From 45498d0255abe5da8d3ff95c117ccab594c49b8f Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Thu, 11 Jul 2024 22:10:02 +0200 Subject: [PATCH] Updated builds. --- build/three.webgpu.js | 344 +++++++++++++++++++++++++++++++++++++- build/three.webgpu.min.js | 2 +- 2 files changed, 343 insertions(+), 3 deletions(-) diff --git a/build/three.webgpu.js b/build/three.webgpu.js index f14362d3e04c9a..57f4e61f8a9b6d 100644 --- a/build/three.webgpu.js +++ b/build/three.webgpu.js @@ -53312,6 +53312,321 @@ const lut3D = ( node, lut, size, intensity ) => nodeObject( new Lut3DNode( nodeO addNodeElement( 'lut3D', lut3D ); +const _quadMesh = new QuadMesh(); +const _currentClearColor = new Color(); + +class GTAONode extends TempNode { + + constructor( textureNode, depthNode, normalNode, camera ) { + + super(); + + this.textureNode = textureNode; + this.depthNode = depthNode; + this.normalNode = normalNode; + + this.radius = uniform( 0.25 ); + this.resolution = uniform( new Vector2() ); + this.thickness = uniform( 1 ); + this.distanceExponent = uniform( 1 ); + this.distanceFallOff = uniform( 1 ); + this.scale = uniform( 1 ); + this.blendIntensity = uniform( 1 ); + this.noiseNode = texture( generateMagicSquareNoise() ); + + this.cameraProjectionMatrix = uniform( camera.projectionMatrix ); + this.cameraProjectionMatrixInverse = uniform( camera.projectionMatrixInverse ); + + this.SAMPLES = uniform( 16 ); + + this._aoRenderTarget = new RenderTarget(); + this._aoRenderTarget.texture.name = 'GTAONode.AO'; + + this._material = null; + this._textureNode = passTexture( this, this._aoRenderTarget.texture ); + + this.updateBeforeType = NodeUpdateType.RENDER; + + } + + setSize( width, height ) { + + this.resolution.value.set( width, height ); + this._aoRenderTarget.setSize( width, height ); + + } + + updateBefore( frame ) { + + const { renderer } = frame; + + const textureNode = this.textureNode; + const map = textureNode.value; + + const currentRenderTarget = renderer.getRenderTarget(); + const currentMRT = renderer.getMRT(); + renderer.getClearColor( _currentClearColor ); + const currentClearAlpha = renderer.getClearAlpha(); + + + const currentTexture = textureNode.value; + + _quadMesh.material = this._material; + + this.setSize( map.image.width, map.image.height ); + + + const textureType = map.type; + + this._aoRenderTarget.texture.type = textureType; + + // clear + + renderer.setMRT( null ); + renderer.setClearColor( 0xffffff, 1 ); + + // ao + + renderer.setRenderTarget( this._aoRenderTarget ); + _quadMesh.render( renderer ); + + // restore + + renderer.setRenderTarget( currentRenderTarget ); + renderer.setMRT( currentMRT ); + renderer.setClearColor( _currentClearColor, currentClearAlpha ); + textureNode.value = currentTexture; + + } + + setup( builder ) { + + const { textureNode } = this; + + const uvNode = uv(); + + const sampleTexture = ( uv ) => textureNode.uv( uv ); + const sampleDepth = ( uv ) => this.depthNode.uv( uv ).x; + const sampleNoise = ( uv ) => this.noiseNode.uv( uv ); + + const getSceneUvAndDepth = tslFn( ( [ sampleViewPos ] )=> { + + const sampleClipPos = this.cameraProjectionMatrix.mul( vec4( sampleViewPos, 1.0 ) ); + let sampleUv = sampleClipPos.xy.div( sampleClipPos.w ).mul( 0.5 ).add( 0.5 ).toVar(); + sampleUv = vec2( sampleUv.x, sampleUv.y.oneMinus() ); + const sampleSceneDepth = sampleDepth( sampleUv ); + return vec3( sampleUv, sampleSceneDepth ); + + } ); + + const getViewPosition = tslFn( ( [ screenPosition, depth ] ) => { + + screenPosition = vec2( screenPosition.x, screenPosition.y.oneMinus() ).mul( 2.0 ).sub( 1.0 ); + + const clipSpacePosition = vec4( vec3( screenPosition, depth ), 1.0 ); + const viewSpacePosition = vec4( this.cameraProjectionMatrixInverse.mul( clipSpacePosition ) ); + + return viewSpacePosition.xyz.div( viewSpacePosition.w ); + + } ); + + const ao = tslFn( () => { + + const depth = sampleDepth( uvNode ); + + depth.greaterThanEqual( 1.0 ).discard(); + + const viewPosition = getViewPosition( uvNode, depth ); + const viewNormal = this.normalNode.rgb.normalize(); + + const radiusToUse = this.radius; + + const noiseResolution = textureSize( this.noiseNode, 0 ); + let noiseUv = vec2( uvNode.x, uvNode.y.oneMinus() ); + noiseUv = noiseUv.mul( this.resolution.div( noiseResolution ) ); + const noiseTexel = sampleNoise( noiseUv ); + const randomVec = noiseTexel.xyz.mul( 2.0 ).sub( 1.0 ); + const tangent = vec3( randomVec.xy, 0.0 ).normalize(); + const bitangent = vec3( tangent.y.mul( - 1.0 ), tangent.x, 0.0 ); + const kernelMatrix = mat3( tangent, bitangent, vec3( 0.0, 0.0, 1.0 ) ); + + const DIRECTIONS = this.SAMPLES.lessThan( 30 ).cond( 3, 5 ); + const STEPS = add( this.SAMPLES, DIRECTIONS.sub( 1 ) ).div( DIRECTIONS ); + + const ao = float( 0 ).toVar(); + + loop( { start: int( 0 ), end: DIRECTIONS, type: 'int', condition: '<' }, ( { i } ) => { + + const angle = float( i ).div( float( DIRECTIONS ) ).mul( PI ); + const sampleDir = vec4( cos( angle ), sin( angle ), 0., add( 0.5, mul( 0.5, noiseTexel.w ) ) ); + sampleDir.xyz = normalize( kernelMatrix.mul( sampleDir.xyz ) ); + + const viewDir = normalize( viewPosition.xyz.negate() ); + const sliceBitangent = normalize( cross( sampleDir.xyz, viewDir ) ); + const sliceTangent = cross( sliceBitangent, viewDir ); + const normalInSlice = normalize( viewNormal.sub( sliceBitangent.mul( dot( viewNormal, sliceBitangent ) ) ) ); + + const tangentToNormalInSlice = cross( normalInSlice, sliceBitangent ); + const cosHorizons = vec2( dot( viewDir, tangentToNormalInSlice ), dot( viewDir, tangentToNormalInSlice.negate() ) ).toVar(); + + loop( { end: STEPS, type: 'int', name: 'j', condition: '<' }, ( { j } ) => { + + const sampleViewOffset = sampleDir.xyz.mul( radiusToUse ).mul( sampleDir.w ).mul( pow( div( float( j ).add( 1.0 ), float( STEPS ) ), this.distanceExponent ) ); + + // x + + const sampleSceneUvDepthX = getSceneUvAndDepth( viewPosition.add( sampleViewOffset ) ); + const sampleSceneViewPositionX = getViewPosition( sampleSceneUvDepthX.xy, sampleSceneUvDepthX.z ); + const viewDeltaX = sampleSceneViewPositionX.sub( viewPosition ); + + If( abs( viewDeltaX.z ).lessThan( this.thickness ), () => { + + const sampleCosHorizon = dot( viewDir, normalize( viewDeltaX ) ); + cosHorizons.x.addAssign( max$1( 0, mul( sampleCosHorizon.sub( cosHorizons.x ), mix( 1.0, float( 2.0 ).div( float( j ).add( 2 ) ), this.distanceFallOff ) ) ) ); + + } ); + + // y + + const sampleSceneUvDepthY = getSceneUvAndDepth( viewPosition.sub( sampleViewOffset ) ); + const sampleSceneViewPositionY = getViewPosition( sampleSceneUvDepthY.xy, sampleSceneUvDepthY.z ); + const viewDeltaY = sampleSceneViewPositionY.sub( viewPosition ); + + If( abs( viewDeltaY.z ).lessThan( this.thickness ), () => { + + const sampleCosHorizon = dot( viewDir, normalize( viewDeltaY ) ); + cosHorizons.y.addAssign( max$1( 0, mul( sampleCosHorizon.sub( cosHorizons.y ), mix( 1.0, float( 2.0 ).div( float( j ).add( 2 ) ), this.distanceFallOff ) ) ) ); + + } ); + + } ); + + const sinHorizons = sqrt( sub( 1.0, cosHorizons.mul( cosHorizons ) ) ); + const nx = dot( normalInSlice, sliceTangent ); + const ny = dot( normalInSlice, viewDir ); + const nxb = mul( 0.5, acos( cosHorizons.y ).sub( acos( cosHorizons.x ) ).add( sinHorizons.x.mul( cosHorizons.x ).sub( sinHorizons.y.mul( cosHorizons.y ) ) ) ); + const nyb = mul( 0.5, sub( 2.0, cosHorizons.x.mul( cosHorizons.x ) ).sub( cosHorizons.y.mul( cosHorizons.y ) ) ); + const occlusion = nx.mul( nxb ).add( ny.mul( nyb ) ); + ao.addAssign( occlusion ); + + } ); + + ao.assign( clamp( ao.div( DIRECTIONS ), 0, 1 ) ); + ao.assign( pow( ao, this.scale ) ); + + return vec4( vec3( ao ), 1.0 ); + + } ); + + const composite = tslFn( () => { + + const beauty = sampleTexture( uvNode ); + const ao = this._textureNode.uv( uvNode ); + + return beauty.mul( mix( vec3( 1.0 ), ao, this.blendIntensity ) ); + + } ); + + const material = this._material || ( this._material = builder.createNodeMaterial() ); + material.fragmentNode = ao().context( builder.getSharedContext() ); + material.needsUpdate = true; + + // + + return composite(); + + } + +} + +function generateMagicSquareNoise( size = 5 ) { + + const noiseSize = Math.floor( size ) % 2 === 0 ? Math.floor( size ) + 1 : Math.floor( size ); + const magicSquare = generateMagicSquare( noiseSize ); + const noiseSquareSize = magicSquare.length; + const data = new Uint8Array( noiseSquareSize * 4 ); + + for ( let inx = 0; inx < noiseSquareSize; ++ inx ) { + + const iAng = magicSquare[ inx ]; + const angle = ( 2 * Math.PI * iAng ) / noiseSquareSize; + const randomVec = new Vector3( + Math.cos( angle ), + Math.sin( angle ), + 0 + ).normalize(); + data[ inx * 4 ] = ( randomVec.x * 0.5 + 0.5 ) * 255; + data[ inx * 4 + 1 ] = ( randomVec.y * 0.5 + 0.5 ) * 255; + data[ inx * 4 + 2 ] = 127; + data[ inx * 4 + 3 ] = 255; + + } + + const noiseTexture = new DataTexture( data, noiseSize, noiseSize ); + noiseTexture.wrapS = RepeatWrapping; + noiseTexture.wrapT = RepeatWrapping; + noiseTexture.needsUpdate = true; + + return noiseTexture; + +} + +function generateMagicSquare( size ) { + + const noiseSize = Math.floor( size ) % 2 === 0 ? Math.floor( size ) + 1 : Math.floor( size ); + const noiseSquareSize = noiseSize * noiseSize; + const magicSquare = Array( noiseSquareSize ).fill( 0 ); + let i = Math.floor( noiseSize / 2 ); + let j = noiseSize - 1; + + for ( let num = 1; num <= noiseSquareSize; ) { + + if ( i === - 1 && j === noiseSize ) { + + j = noiseSize - 2; + i = 0; + + } else { + + if ( j === noiseSize ) { + + j = 0; + + } + + if ( i < 0 ) { + + i = noiseSize - 1; + + } + + } + + if ( magicSquare[ i * noiseSize + j ] !== 0 ) { + + j -= 2; + i ++; + continue; + + } else { + + magicSquare[ i * noiseSize + j ] = num ++; + + } + + j ++; + i --; + + } + + return magicSquare; + +} + +const ao = ( node, depthNode, normalNode, camera ) => nodeObject( new GTAONode( nodeObject( node ).toTexture(), nodeObject( depthNode ), nodeObject( normalNode ), camera ) ); + +addNodeElement( 'ao', ao ); + class RenderOutputNode extends TempNode { constructor( colorNode, toneMapping, outputColorSpace ) { @@ -71287,6 +71602,8 @@ fn main( ${shaderData.attributes} ) -> VaryingsStruct { return `${ this.getSignature() } +diagnostic( off, derivative_uniformity ); + // uniforms ${shaderData.uniforms} @@ -73432,7 +73749,30 @@ class WebGPUBackend extends Backend { } - passEncoderGPU.dispatchWorkgroups( computeNode.dispatchCount ); + const maxComputeWorkgroupsPerDimension = this.device.limits.maxComputeWorkgroupsPerDimension; + + const computeNodeData = this.get( computeNode ); + + if ( computeNodeData.dispatchSize === undefined ) computeNodeData.dispatchSize = { x: 0, y: 1, z: 1 }; + + const { dispatchSize } = computeNodeData; + + if ( computeNode.dispatchCount > maxComputeWorkgroupsPerDimension ) { + + dispatchSize.x = Math.min( computeNode.dispatchCount, maxComputeWorkgroupsPerDimension ); + dispatchSize.y = Math.ceil( computeNode.dispatchCount / maxComputeWorkgroupsPerDimension ); + + } else { + + dispatchSize.x = computeNode.dispatchCount; + + } + + passEncoderGPU.dispatchWorkgroups( + dispatchSize.x, + dispatchSize.y, + dispatchSize.z + ); } @@ -74298,4 +74638,4 @@ if ( typeof window !== 'undefined' ) { } -export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveAnimationBlendMode, AdditiveBlending, AfterImageNode, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, AnamorphicNode, AnimationAction, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrayCamera, ArrayElementNode, ArrowHelper, AssignNode, AttachedBindMode, AttributeNode, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, BRDF_GGX, BRDF_Lambert, BackSide, BasicDepthPacking, BasicEnvironmentNode, BasicShadowMap, BatchNode, BatchedMesh, BlendModeNode, Bone, BooleanKeyframeTrack, Box2, Box3, Box3Helper, BoxGeometry, BoxHelper, Break, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferGeometryLoader, BufferNode, BumpMapNode, BypassNode, ByteType, Cache, CacheNode, Camera, CameraHelper, CanvasTexture, CapsuleGeometry, CatmullRomCurve3, CheckerNode, CineonToneMapping, CircleGeometry, ClampToEdgeWrapping, Clock, CodeNode, Color, ColorAdjustmentNode, ColorKeyframeTrack, ColorManagement, ColorSpaceNode, CompressedArrayTexture, CompressedCubeTexture, CompressedTexture, CompressedTextureLoader, ComputeNode, CondNode, ConeGeometry, ConstNode, ConstantAlphaFactor, ConstantColorFactor, ContextNode, Continue, ConvertNode, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureLoader, CubeTextureNode, CubeUVReflectionMapping, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceBack, CullFaceFront, CullFaceFrontBack, CullFaceNone, Curve, CurvePath, CustomBlending, CustomToneMapping, CylinderGeometry, Cylindrical, DFGApprox, D_GGX, Data3DTexture, DataArrayTexture, DataTexture, DataTextureLoader, DataUtils, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DepthFormat, DepthOfFieldNode, DepthStencilFormat, DepthTexture, DetachedBindMode, DirectionalLight, DirectionalLightHelper, DirectionalLightNode, DiscardNode, DiscreteInterpolant, DisplayP3ColorSpace, DodecahedronGeometry, DotScreenNode, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicCopyUsage, DynamicDrawUsage, DynamicReadUsage, EPSILON, EdgesGeometry, EllipseCurve, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectUVNode, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExpressionNode, ExtrudeGeometry, F_Schlick, FileLoader, FilmNode, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fog, FogExp2, FogExp2Node, FogNode, FogRangeNode, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLBufferAttribute, GLSL1, GLSL3, GLSLNodeParser, GaussianBlurNode, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HalfFloatType, HashNode, HemisphereLight, HemisphereLightHelper, HemisphereLightNode, IESSpotLight, IESSpotLightNode, INFINITY, IcosahedronGeometry, If, ImageBitmapLoader, ImageLoader, ImageUtils, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, InstanceNode, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, InstancedMesh, InstancedPointsNodeMaterial, Int16BufferAttribute, Int32BufferAttribute, Int8BufferAttribute, IntType, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InvertStencilOp, IrradianceNode, JoinNode, KeepStencilOp, KeyframeTrack, LOD, LatheGeometry, Layers, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, Light, LightNode, LightProbe, LightingContextNode, LightingModel, LightingNode, LightsNode, Line, Line2NodeMaterial, Line3, LineBasicMaterial, LineBasicNodeMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineDashedNodeMaterial, LineLoop, LineSegments, LinearDisplayP3ColorSpace, LinearFilter, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Loader, LoaderUtils, LoadingManager, LoopNode, LoopOnce, LoopPingPong, LoopRepeat, LuminanceAlphaFormat, LuminanceFormat, Lut3DNode, MOUSE, MRTNode, MatcapUVNode, Material, MaterialLoader, MaterialNode, MaterialReferenceNode, MathNode, MathUtils, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, ModelViewProjectionNode, MorphNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, Node, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeFrame, NodeFunctionInput, NodeKeywords, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalAnimationBlendMode, NormalBlending, NormalMapNode, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OctahedronGeometry, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OperatorNode, OrthographicCamera, OscNode, OutputStructNode, P3Primaries, PCFShadowMap, PCFSoftShadowMap, PI, PI2, PMREMGenerator, PMREMNode, PackingNode, ParameterNode, PassNode, Path, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PlaneGeometry, PlaneHelper, PointLight, PointLightHelper, PointLightNode, PointUVNode, Points, PointsMaterial, PointsNodeMaterial, PolarGridHelper, PolyhedronGeometry, PositionalAudio, PostProcessing, PosterizeNode, PropertyBinding, PropertyMixer, PropertyNode, QuadMesh, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RGBADepthPacking, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBDepthPacking, RGBFormat, RGBIntegerFormat, RGBShiftNode, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGDepthPacking, RGFormat, RGIntegerFormat, RTTNode, RangeNode, RawShaderMaterial, Ray, Raycaster, Rec709Primaries, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceNode, ReflectorNode, ReinhardToneMapping, RemapNode, RenderOutputNode, RenderTarget, RendererReferenceNode, RepeatWrapping, ReplaceStencilOp, Return, ReverseSubtractEquation, RingGeometry, RotateNode, RotateUVNode, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, SceneNode, Schlick_to_F0, ScriptableNode, ScriptableValueNode, SetNode, ShaderMaterial, ShaderNode, ShadowMaterial, ShadowNodeMaterial, Shape, ShapeGeometry, ShapePath, ShapeUtils, ShortType, Skeleton, SkeletonHelper, SkinnedMesh, SkinningNode, SobelOperatorNode, Source, Sphere, SphereGeometry, Spherical, SphericalHarmonics3, SplineCurve, SplitNode, SpotLight, SpotLightHelper, SpotLightNode, Sprite, SpriteMaterial, SpriteNodeMaterial, SpriteSheetUVNode, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StaticCopyUsage, StaticDrawUsage, StaticReadUsage, StereoCamera, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTextureNode, StreamCopyUsage, StreamDrawUsage, StreamReadUsage, StringKeyframeTrack, SubtractEquation, SubtractiveBlending, TBNViewMatrix, TOUCH, TangentSpaceNormalMap, TempNode, TetrahedronGeometry, Texture, Texture3DNode, TextureBicubicNode, TextureLoader, TextureNode, TextureSizeNode, TimerNode, ToneMappingNode, TorusGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TriplanarTexturesNode, TubeGeometry, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Uniform$1 as Uniform, UniformGroupNode, UniformNode, UniformsGroup$1 as UniformsGroup, UniformsNode, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, V_GGX_SmithCorrelated, VarNode, VaryingNode, Vector2, Vector3, Vector4, VectorKeyframeTrack, VertexColorNode, VideoTexture, ViewportDepthNode, ViewportDepthTextureNode, ViewportNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGL3DRenderTarget, WebGLArrayRenderTarget, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGLMultipleRenderTargets, WebGLRenderTarget, WebGPUCoordinateSystem, WebGPURenderer, WireframeGeometry, WrapAroundEnding, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, abs, acos, add, addLightNode, addNodeClass, addNodeElement, addNodeMaterial, afterImage, all, alphaT, anamorphic, and, anisotropy, anisotropyB, anisotropyT, any, append, arrayBuffer, asin, assign, atan, atan2, attribute, backgroundBlurriness, backgroundIntensity, batch, bitAnd, bitNot, bitOr, bitXor, bitangentGeometry, bitangentLocal, bitangentView, bitangentWorld, bitcast, blur, bmat2, bmat3, bmat4, bool, buffer, bufferAttribute, bumpMap, burn, bvec2, bvec3, bvec4, bypass, cache, call, cameraFar, cameraLogDepth, cameraNear, cameraNormalMatrix, cameraPosition, cameraProjectionMatrix, cameraProjectionMatrixInverse, cameraViewMatrix, cameraWorldMatrix, cbrt, ceil, checker, clamp, clearcoat, clearcoatRoughness, code, color, colorSpaceToLinear, colorToDirection, compute, cond, context, convert, cos, createCanvasElement, createNodeFromType, createNodeMaterialFromType, cross, cubeTexture, dFdx, dFdy, dashSize, defaultBuildStages, defaultShaderStages, defined, degrees, densityFog, depth, depthPass, difference, diffuseColor, directionToColor, discard, distance, div, dodge, dof, dot, dotScreen, drawIndex, dynamicBufferAttribute, element, emissive, equal, equals, equirectUV, exp, exp2, expression, faceDirection, faceForward, film, float, floor, fog, fract, frameGroup, frameId, frontFacing, fwidth, gain, gapSize, gaussianBlur, getConstNodeType, getCurrentStack, getDirection, getDistanceAttenuation, getGeometryRoughness, getRoughness, global, glsl, glslFn, greaterThan, greaterThanEqual, hash, hue, imat2, imat3, imat4, instance, instanceIndex, instancedBufferAttribute, instancedDynamicBufferAttribute, int, inverseSqrt, iridescence, iridescenceIOR, iridescenceThickness, ivec2, ivec3, ivec4, js, label, length, lengthSq, lessThan, lessThanEqual, lightTargetDirection, lightingContext, lights, lightsNode, linearDepth, linearToColorSpace, linearTosRGB, log, log2, loop, lumaCoeffs, luminance, lut3D, mat2, mat3, mat4, matcapUV, materialAOMap, materialAlphaTest, materialAnisotropy, materialAnisotropyVector, materialClearcoat, materialClearcoatNormal, materialClearcoatRoughness, materialColor, materialDispersion, materialEmissive, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLightMap, materialLineDashOffset, materialLineDashSize, materialLineGapSize, materialLineScale, materialLineWidth, materialMetalness, materialNormal, materialOpacity, materialPointWidth, materialReference, materialReflectivity, materialRotation, materialRoughness, materialSheen, materialSheenRoughness, materialShininess, materialSpecular, materialSpecularStrength, max$1 as max, maxMipLevel, metalness, min$1 as min, mix, mod, modelDirection, modelNormalMatrix, modelPosition, modelScale, modelViewMatrix, modelViewPosition, modelViewProjection, modelWorldMatrix, modelWorldMatrixInverse, morphReference, mrt, mul, mx_aastep, mx_cell_noise_float, mx_contrast, mx_fractal_noise_float, mx_fractal_noise_vec2, mx_fractal_noise_vec3, mx_fractal_noise_vec4, mx_hsvtorgb, mx_noise_float, mx_noise_vec3, mx_noise_vec4, mx_ramplr, mx_ramptb, mx_rgbtohsv, mx_safepower, mx_splitlr, mx_splittb, mx_srgb_texture_to_lin_rec709, mx_transform_uv, mx_worley_noise_float, mx_worley_noise_vec2, mx_worley_noise_vec3, negate, nodeArray, nodeImmutable, nodeObject, nodeObjects, nodeProxy, normalGeometry, normalLocal, normalMap, normalView, normalWorld, normalize, not, objectDirection, objectGroup, objectNormalMatrix, objectPosition, objectScale, objectViewMatrix, objectViewPosition, objectWorldMatrix, oneMinus, or, orthographicDepthToViewZ, oscSawtooth, oscSine, oscSquare, oscTriangle, output, outputStruct, overlay, overloadingFn, parabola, parallaxDirection, parallaxUV, parameter, pass, passTexture, pcurve, perspectiveDepthToViewZ, pmremTexture, pointUV, pointWidth, positionGeometry, positionLocal, positionView, positionViewDirection, positionWorld, positionWorldDirection, posterize, pow, pow2, pow3, pow4, property, radians, rand, range, rangeFog, reciprocal, reference, referenceBuffer, reflect, reflectVector, reflectView, reflector, refract, refractVector, refractView, remainder, remap, remapClamp, renderGroup, renderOutput, rendererReference, rgbShift, rotate, rotateUV, roughness, round, rtt, sRGBToLinear, sampler, saturate, saturation, screen, scriptable, scriptableValue, setCurrentStack, shaderStages, sheen, sheenRoughness, shiftLeft, shiftRight, shininess, sign, sin, sinc, skinning, skinningReference, smoothstep, sobel, specularColor, split, spritesheetUV, sqrt, stack, step, storage, storageObject, storageTexture, string, sub, tan, tangentGeometry, tangentLocal, tangentView, tangentWorld, temp, texture, texture3D, textureBicubic, textureCubeUV, textureLoad, textureSize, textureStore, threshold, timerDelta, timerGlobal, timerLocal, toneMapping, transformDirection, transformedBentNormalView, transformedBitangentView, transformedBitangentWorld, transformedClearcoatNormalView, transformedNormalView, transformedNormalWorld, transformedTangentView, transformedTangentWorld, transpose, triNoise3D, triplanarTexture, triplanarTextures, trunc, tslFn, uint, umat2, umat3, umat4, uniform, uniformGroup, uniforms, userData, uv, uvec2, uvec3, uvec4, varying, varyingProperty, vec2, vec3, vec4, vectorComponents, vertexColor, vertexIndex, vibrance, viewZToOrthographicDepth, viewZToPerspectiveDepth, viewport, viewportBottomLeft, viewportBottomRight, viewportCoordinate, viewportDepthTexture, viewportLinearDepth, viewportMipTexture, viewportResolution, viewportSharedTexture, viewportTexture, viewportTopLeft, viewportTopRight, wgsl, wgslFn, xor }; +export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveAnimationBlendMode, AdditiveBlending, AfterImageNode, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, AnamorphicNode, AnimationAction, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrayCamera, ArrayElementNode, ArrowHelper, AssignNode, AttachedBindMode, AttributeNode, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, BRDF_GGX, BRDF_Lambert, BackSide, BasicDepthPacking, BasicEnvironmentNode, BasicShadowMap, BatchNode, BatchedMesh, BlendModeNode, Bone, BooleanKeyframeTrack, Box2, Box3, Box3Helper, BoxGeometry, BoxHelper, Break, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferGeometryLoader, BufferNode, BumpMapNode, BypassNode, ByteType, Cache, CacheNode, Camera, CameraHelper, CanvasTexture, CapsuleGeometry, CatmullRomCurve3, CheckerNode, CineonToneMapping, CircleGeometry, ClampToEdgeWrapping, Clock, CodeNode, Color, ColorAdjustmentNode, ColorKeyframeTrack, ColorManagement, ColorSpaceNode, CompressedArrayTexture, CompressedCubeTexture, CompressedTexture, CompressedTextureLoader, ComputeNode, CondNode, ConeGeometry, ConstNode, ConstantAlphaFactor, ConstantColorFactor, ContextNode, Continue, ConvertNode, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureLoader, CubeTextureNode, CubeUVReflectionMapping, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceBack, CullFaceFront, CullFaceFrontBack, CullFaceNone, Curve, CurvePath, CustomBlending, CustomToneMapping, CylinderGeometry, Cylindrical, DFGApprox, D_GGX, Data3DTexture, DataArrayTexture, DataTexture, DataTextureLoader, DataUtils, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DepthFormat, DepthOfFieldNode, DepthStencilFormat, DepthTexture, DetachedBindMode, DirectionalLight, DirectionalLightHelper, DirectionalLightNode, DiscardNode, DiscreteInterpolant, DisplayP3ColorSpace, DodecahedronGeometry, DotScreenNode, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicCopyUsage, DynamicDrawUsage, DynamicReadUsage, EPSILON, EdgesGeometry, EllipseCurve, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectUVNode, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExpressionNode, ExtrudeGeometry, F_Schlick, FileLoader, FilmNode, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fog, FogExp2, FogExp2Node, FogNode, FogRangeNode, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLBufferAttribute, GLSL1, GLSL3, GLSLNodeParser, GTAONode, GaussianBlurNode, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HalfFloatType, HashNode, HemisphereLight, HemisphereLightHelper, HemisphereLightNode, IESSpotLight, IESSpotLightNode, INFINITY, IcosahedronGeometry, If, ImageBitmapLoader, ImageLoader, ImageUtils, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, InstanceNode, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, InstancedMesh, InstancedPointsNodeMaterial, Int16BufferAttribute, Int32BufferAttribute, Int8BufferAttribute, IntType, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InvertStencilOp, IrradianceNode, JoinNode, KeepStencilOp, KeyframeTrack, LOD, LatheGeometry, Layers, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, Light, LightNode, LightProbe, LightingContextNode, LightingModel, LightingNode, LightsNode, Line, Line2NodeMaterial, Line3, LineBasicMaterial, LineBasicNodeMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineDashedNodeMaterial, LineLoop, LineSegments, LinearDisplayP3ColorSpace, LinearFilter, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Loader, LoaderUtils, LoadingManager, LoopNode, LoopOnce, LoopPingPong, LoopRepeat, LuminanceAlphaFormat, LuminanceFormat, Lut3DNode, MOUSE, MRTNode, MatcapUVNode, Material, MaterialLoader, MaterialNode, MaterialReferenceNode, MathNode, MathUtils, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, ModelViewProjectionNode, MorphNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, Node, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeFrame, NodeFunctionInput, NodeKeywords, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalAnimationBlendMode, NormalBlending, NormalMapNode, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OctahedronGeometry, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OperatorNode, OrthographicCamera, OscNode, OutputStructNode, P3Primaries, PCFShadowMap, PCFSoftShadowMap, PI, PI2, PMREMGenerator, PMREMNode, PackingNode, ParameterNode, PassNode, Path, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PlaneGeometry, PlaneHelper, PointLight, PointLightHelper, PointLightNode, PointUVNode, Points, PointsMaterial, PointsNodeMaterial, PolarGridHelper, PolyhedronGeometry, PositionalAudio, PostProcessing, PosterizeNode, PropertyBinding, PropertyMixer, PropertyNode, QuadMesh, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RGBADepthPacking, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBDepthPacking, RGBFormat, RGBIntegerFormat, RGBShiftNode, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGDepthPacking, RGFormat, RGIntegerFormat, RTTNode, RangeNode, RawShaderMaterial, Ray, Raycaster, Rec709Primaries, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceNode, ReflectorNode, ReinhardToneMapping, RemapNode, RenderOutputNode, RenderTarget, RendererReferenceNode, RepeatWrapping, ReplaceStencilOp, Return, ReverseSubtractEquation, RingGeometry, RotateNode, RotateUVNode, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, SceneNode, Schlick_to_F0, ScriptableNode, ScriptableValueNode, SetNode, ShaderMaterial, ShaderNode, ShadowMaterial, ShadowNodeMaterial, Shape, ShapeGeometry, ShapePath, ShapeUtils, ShortType, Skeleton, SkeletonHelper, SkinnedMesh, SkinningNode, SobelOperatorNode, Source, Sphere, SphereGeometry, Spherical, SphericalHarmonics3, SplineCurve, SplitNode, SpotLight, SpotLightHelper, SpotLightNode, Sprite, SpriteMaterial, SpriteNodeMaterial, SpriteSheetUVNode, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StaticCopyUsage, StaticDrawUsage, StaticReadUsage, StereoCamera, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTextureNode, StreamCopyUsage, StreamDrawUsage, StreamReadUsage, StringKeyframeTrack, SubtractEquation, SubtractiveBlending, TBNViewMatrix, TOUCH, TangentSpaceNormalMap, TempNode, TetrahedronGeometry, Texture, Texture3DNode, TextureBicubicNode, TextureLoader, TextureNode, TextureSizeNode, TimerNode, ToneMappingNode, TorusGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TriplanarTexturesNode, TubeGeometry, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Uniform$1 as Uniform, UniformGroupNode, UniformNode, UniformsGroup$1 as UniformsGroup, UniformsNode, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, V_GGX_SmithCorrelated, VarNode, VaryingNode, Vector2, Vector3, Vector4, VectorKeyframeTrack, VertexColorNode, VideoTexture, ViewportDepthNode, ViewportDepthTextureNode, ViewportNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGL3DRenderTarget, WebGLArrayRenderTarget, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGLMultipleRenderTargets, WebGLRenderTarget, WebGPUCoordinateSystem, WebGPURenderer, WireframeGeometry, WrapAroundEnding, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, abs, acos, add, addLightNode, addNodeClass, addNodeElement, addNodeMaterial, afterImage, all, alphaT, anamorphic, and, anisotropy, anisotropyB, anisotropyT, any, ao, append, arrayBuffer, asin, assign, atan, atan2, attribute, backgroundBlurriness, backgroundIntensity, batch, bitAnd, bitNot, bitOr, bitXor, bitangentGeometry, bitangentLocal, bitangentView, bitangentWorld, bitcast, blur, bmat2, bmat3, bmat4, bool, buffer, bufferAttribute, bumpMap, burn, bvec2, bvec3, bvec4, bypass, cache, call, cameraFar, cameraLogDepth, cameraNear, cameraNormalMatrix, cameraPosition, cameraProjectionMatrix, cameraProjectionMatrixInverse, cameraViewMatrix, cameraWorldMatrix, cbrt, ceil, checker, clamp, clearcoat, clearcoatRoughness, code, color, colorSpaceToLinear, colorToDirection, compute, cond, context, convert, cos, createCanvasElement, createNodeFromType, createNodeMaterialFromType, cross, cubeTexture, dFdx, dFdy, dashSize, defaultBuildStages, defaultShaderStages, defined, degrees, densityFog, depth, depthPass, difference, diffuseColor, directionToColor, discard, distance, div, dodge, dof, dot, dotScreen, drawIndex, dynamicBufferAttribute, element, emissive, equal, equals, equirectUV, exp, exp2, expression, faceDirection, faceForward, film, float, floor, fog, fract, frameGroup, frameId, frontFacing, fwidth, gain, gapSize, gaussianBlur, getConstNodeType, getCurrentStack, getDirection, getDistanceAttenuation, getGeometryRoughness, getRoughness, global, glsl, glslFn, greaterThan, greaterThanEqual, hash, hue, imat2, imat3, imat4, instance, instanceIndex, instancedBufferAttribute, instancedDynamicBufferAttribute, int, inverseSqrt, iridescence, iridescenceIOR, iridescenceThickness, ivec2, ivec3, ivec4, js, label, length, lengthSq, lessThan, lessThanEqual, lightTargetDirection, lightingContext, lights, lightsNode, linearDepth, linearToColorSpace, linearTosRGB, log, log2, loop, lumaCoeffs, luminance, lut3D, mat2, mat3, mat4, matcapUV, materialAOMap, materialAlphaTest, materialAnisotropy, materialAnisotropyVector, materialClearcoat, materialClearcoatNormal, materialClearcoatRoughness, materialColor, materialDispersion, materialEmissive, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLightMap, materialLineDashOffset, materialLineDashSize, materialLineGapSize, materialLineScale, materialLineWidth, materialMetalness, materialNormal, materialOpacity, materialPointWidth, materialReference, materialReflectivity, materialRotation, materialRoughness, materialSheen, materialSheenRoughness, materialShininess, materialSpecular, materialSpecularStrength, max$1 as max, maxMipLevel, metalness, min$1 as min, mix, mod, modelDirection, modelNormalMatrix, modelPosition, modelScale, modelViewMatrix, modelViewPosition, modelViewProjection, modelWorldMatrix, modelWorldMatrixInverse, morphReference, mrt, mul, mx_aastep, mx_cell_noise_float, mx_contrast, mx_fractal_noise_float, mx_fractal_noise_vec2, mx_fractal_noise_vec3, mx_fractal_noise_vec4, mx_hsvtorgb, mx_noise_float, mx_noise_vec3, mx_noise_vec4, mx_ramplr, mx_ramptb, mx_rgbtohsv, mx_safepower, mx_splitlr, mx_splittb, mx_srgb_texture_to_lin_rec709, mx_transform_uv, mx_worley_noise_float, mx_worley_noise_vec2, mx_worley_noise_vec3, negate, nodeArray, nodeImmutable, nodeObject, nodeObjects, nodeProxy, normalGeometry, normalLocal, normalMap, normalView, normalWorld, normalize, not, objectDirection, objectGroup, objectNormalMatrix, objectPosition, objectScale, objectViewMatrix, objectViewPosition, objectWorldMatrix, oneMinus, or, orthographicDepthToViewZ, oscSawtooth, oscSine, oscSquare, oscTriangle, output, outputStruct, overlay, overloadingFn, parabola, parallaxDirection, parallaxUV, parameter, pass, passTexture, pcurve, perspectiveDepthToViewZ, pmremTexture, pointUV, pointWidth, positionGeometry, positionLocal, positionView, positionViewDirection, positionWorld, positionWorldDirection, posterize, pow, pow2, pow3, pow4, property, radians, rand, range, rangeFog, reciprocal, reference, referenceBuffer, reflect, reflectVector, reflectView, reflector, refract, refractVector, refractView, remainder, remap, remapClamp, renderGroup, renderOutput, rendererReference, rgbShift, rotate, rotateUV, roughness, round, rtt, sRGBToLinear, sampler, saturate, saturation, screen, scriptable, scriptableValue, setCurrentStack, shaderStages, sheen, sheenRoughness, shiftLeft, shiftRight, shininess, sign, sin, sinc, skinning, skinningReference, smoothstep, sobel, specularColor, split, spritesheetUV, sqrt, stack, step, storage, storageObject, storageTexture, string, sub, tan, tangentGeometry, tangentLocal, tangentView, tangentWorld, temp, texture, texture3D, textureBicubic, textureCubeUV, textureLoad, textureSize, textureStore, threshold, timerDelta, timerGlobal, timerLocal, toneMapping, transformDirection, transformedBentNormalView, transformedBitangentView, transformedBitangentWorld, transformedClearcoatNormalView, transformedNormalView, transformedNormalWorld, transformedTangentView, transformedTangentWorld, transpose, triNoise3D, triplanarTexture, triplanarTextures, trunc, tslFn, uint, umat2, umat3, umat4, uniform, uniformGroup, uniforms, userData, uv, uvec2, uvec3, uvec4, varying, varyingProperty, vec2, vec3, vec4, vectorComponents, vertexColor, vertexIndex, vibrance, viewZToOrthographicDepth, viewZToPerspectiveDepth, viewport, viewportBottomLeft, viewportBottomRight, viewportCoordinate, viewportDepthTexture, viewportLinearDepth, viewportMipTexture, viewportResolution, viewportSharedTexture, viewportTexture, viewportTopLeft, viewportTopRight, wgsl, wgslFn, xor }; diff --git a/build/three.webgpu.min.js b/build/three.webgpu.min.js index 22dc459ceba8d7..78076f7c502580 100644 --- a/build/three.webgpu.min.js +++ b/build/three.webgpu.min.js @@ -3,4 +3,4 @@ * Copyright 2010-2024 Three.js Authors * SPDX-License-Identifier: MIT */ -const t="167dev",e={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},s={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},i=0,r=1,n=2,o=3,a=0,h=1,u=2,l=3,c=0,d=1,p=2,m=0,g=1,f=2,y=3,x=4,b=5,v=100,T=101,_=102,w=103,S=104,M=200,A=201,N=202,R=203,C=204,E=205,B=206,I=207,P=208,F=209,U=210,O=211,L=212,z=213,V=214,D=0,k=1,G=2,W=3,j=4,H=5,q=6,$=7,X=0,Y=1,J=2,Z=0,Q=1,K=2,tt=3,et=4,st=5,it=6,rt=7,nt="attached",ot="detached",at=300,ht=301,ut=302,lt=303,ct=304,dt=306,pt=1e3,mt=1001,gt=1002,ft=1003,yt=1004,xt=1004,bt=1005,vt=1005,Tt=1006,_t=1007,wt=1007,St=1008,Mt=1008,At=1009,Nt=1010,Rt=1011,Ct=1012,Et=1013,Bt=1014,It=1015,Pt=1016,Ft=1017,Ut=1018,Ot=1020,Lt=35902,zt=1021,Vt=1022,Dt=1023,kt=1024,Gt=1025,Wt=1026,jt=1027,Ht=1028,qt=1029,$t=1030,Xt=1031,Yt=1032,Jt=1033,Zt=33776,Qt=33777,Kt=33778,te=33779,ee=35840,se=35841,ie=35842,re=35843,ne=36196,oe=37492,ae=37496,he=37808,ue=37809,le=37810,ce=37811,de=37812,pe=37813,me=37814,ge=37815,fe=37816,ye=37817,xe=37818,be=37819,ve=37820,Te=37821,_e=36492,we=36494,Se=36495,Me=36283,Ae=36284,Ne=36285,Re=36286,Ce=2200,Ee=2201,Be=2202,Ie=2300,Pe=2301,Fe=2302,Ue=2400,Oe=2401,Le=2402,ze=2500,Ve=2501,De=0,ke=1,Ge=2,We=3200,je=3201,He=3202,qe=3203,$e=0,Xe=1,Ye="",Je="srgb",Ze="srgb-linear",Qe="display-p3",Ke="display-p3-linear",ts="linear",es="srgb",ss="rec709",is="p3",rs=0,ns=7680,os=7681,as=7682,hs=7683,us=34055,ls=34056,cs=5386,ds=512,ps=513,ms=514,gs=515,fs=516,ys=517,xs=518,bs=519,vs=512,Ts=513,_s=514,ws=515,Ss=516,Ms=517,As=518,Ns=519,Rs=35044,Cs=35048,Es=35040,Bs=35045,Is=35049,Ps=35041,Fs=35046,Us=35050,Os=35042,Ls="100",zs="300 es",Vs=2e3,Ds=2001;class ks{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const s=this._listeners;void 0===s[t]&&(s[t]=[]),-1===s[t].indexOf(e)&&s[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const s=this._listeners;return void 0!==s[t]&&-1!==s[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const s=this._listeners[t];if(void 0!==s){const t=s.indexOf(e);-1!==t&&s.splice(t,1)}}dispatchEvent(t){if(void 0===this._listeners)return;const e=this._listeners[t.type];if(void 0!==e){t.target=this;const s=e.slice(0);for(let e=0,i=s.length;e>8&255]+Gs[t>>16&255]+Gs[t>>24&255]+"-"+Gs[255&e]+Gs[e>>8&255]+"-"+Gs[e>>16&15|64]+Gs[e>>24&255]+"-"+Gs[63&s|128]+Gs[s>>8&255]+"-"+Gs[s>>16&255]+Gs[s>>24&255]+Gs[255&i]+Gs[i>>8&255]+Gs[i>>16&255]+Gs[i>>24&255]).toLowerCase()}function $s(t,e,s){return Math.max(e,Math.min(s,t))}function Xs(t,e){return(t%e+e)%e}function Ys(t,e,s){return(1-s)*t+s*e}function Js(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function Zs(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(4294967295*t);case Uint16Array:return Math.round(65535*t);case Uint8Array:return Math.round(255*t);case Int32Array:return Math.round(2147483647*t);case Int16Array:return Math.round(32767*t);case Int8Array:return Math.round(127*t);default:throw new Error("Invalid component type.")}}const Qs={DEG2RAD:js,RAD2DEG:Hs,generateUUID:qs,clamp:$s,euclideanModulo:Xs,mapLinear:function(t,e,s,i,r){return i+(t-e)*(r-i)/(s-e)},inverseLerp:function(t,e,s){return t!==e?(s-t)/(e-t):0},lerp:Ys,damp:function(t,e,s,i){return Ys(t,e,1-Math.exp(-s*i))},pingpong:function(t,e=1){return e-Math.abs(Xs(t,2*e)-e)},smoothstep:function(t,e,s){return t<=e?0:t>=s?1:(t=(t-e)/(s-e))*t*(3-2*t)},smootherstep:function(t,e,s){return t<=e?0:t>=s?1:(t=(t-e)/(s-e))*t*t*(t*(6*t-15)+10)},randInt:function(t,e){return t+Math.floor(Math.random()*(e-t+1))},randFloat:function(t,e){return t+Math.random()*(e-t)},randFloatSpread:function(t){return t*(.5-Math.random())},seededRandom:function(t){void 0!==t&&(Ws=t);let e=Ws+=1831565813;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296},degToRad:function(t){return t*js},radToDeg:function(t){return t*Hs},isPowerOfTwo:function(t){return 0==(t&t-1)&&0!==t},ceilPowerOfTwo:function(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))},floorPowerOfTwo:function(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))},setQuaternionFromProperEuler:function(t,e,s,i,r){const n=Math.cos,o=Math.sin,a=n(s/2),h=o(s/2),u=n((e+i)/2),l=o((e+i)/2),c=n((e-i)/2),d=o((e-i)/2),p=n((i-e)/2),m=o((i-e)/2);switch(r){case"XYX":t.set(a*l,h*c,h*d,a*u);break;case"YZY":t.set(h*d,a*l,h*c,a*u);break;case"ZXZ":t.set(h*c,h*d,a*l,a*u);break;case"XZX":t.set(a*l,h*m,h*p,a*u);break;case"YXY":t.set(h*p,a*l,h*m,a*u);break;case"ZYZ":t.set(h*m,h*p,a*l,a*u);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:Zs,denormalize:Js};class Ks{constructor(t=0,e=0){Ks.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,s=this.y,i=t.elements;return this.x=i[0]*e+i[3]*s+i[6],this.y=i[1]*e+i[4]*s+i[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos($s(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y;return e*e+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const s=Math.cos(e),i=Math.sin(e),r=this.x-t.x,n=this.y-t.y;return this.x=r*s-n*i+t.x,this.y=r*i+n*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class ti{constructor(t,e,s,i,r,n,o,a,h){ti.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h)}set(t,e,s,i,r,n,o,a,h){const u=this.elements;return u[0]=t,u[1]=i,u[2]=o,u[3]=e,u[4]=r,u[5]=a,u[6]=s,u[7]=n,u[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],this}extractBasis(t,e,s){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),s.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[3],a=s[6],h=s[1],u=s[4],l=s[7],c=s[2],d=s[5],p=s[8],m=i[0],g=i[3],f=i[6],y=i[1],x=i[4],b=i[7],v=i[2],T=i[5],_=i[8];return r[0]=n*m+o*y+a*v,r[3]=n*g+o*x+a*T,r[6]=n*f+o*b+a*_,r[1]=h*m+u*y+l*v,r[4]=h*g+u*x+l*T,r[7]=h*f+u*b+l*_,r[2]=c*m+d*y+p*v,r[5]=c*g+d*x+p*T,r[8]=c*f+d*b+p*_,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8];return e*n*u-e*o*h-s*r*u+s*o*a+i*r*h-i*n*a}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8],l=u*n-o*h,c=o*a-u*r,d=h*r-n*a,p=e*l+s*c+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const m=1/p;return t[0]=l*m,t[1]=(i*h-u*s)*m,t[2]=(o*s-i*n)*m,t[3]=c*m,t[4]=(u*e-i*a)*m,t[5]=(i*r-o*e)*m,t[6]=d*m,t[7]=(s*a-h*e)*m,t[8]=(n*e-s*r)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,s,i,r,n,o){const a=Math.cos(r),h=Math.sin(r);return this.set(s*a,s*h,-s*(a*n+h*o)+n+t,-i*h,i*a,-i*(-h*n+a*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(ei.makeScale(t,e)),this}rotate(t){return this.premultiply(ei.makeRotation(-t)),this}translate(t,e){return this.premultiply(ei.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,s,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<9;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<9;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const ei=new ti;const si={Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array};function ii(t,e){return new si[t](e)}function ri(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function ni(){const t=ri("canvas");return t.style.display="block",t}const oi={};function ai(t){t in oi||(oi[t]=!0,console.warn(t))}const hi=(new ti).set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),ui=(new ti).set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),li={[Ze]:{transfer:ts,primaries:ss,toReference:t=>t,fromReference:t=>t},[Je]:{transfer:es,primaries:ss,toReference:t=>t.convertSRGBToLinear(),fromReference:t=>t.convertLinearToSRGB()},[Ke]:{transfer:ts,primaries:is,toReference:t=>t.applyMatrix3(ui),fromReference:t=>t.applyMatrix3(hi)},[Qe]:{transfer:es,primaries:is,toReference:t=>t.convertSRGBToLinear().applyMatrix3(ui),fromReference:t=>t.applyMatrix3(hi).convertLinearToSRGB()}},ci=new Set([Ze,Ke]),di={enabled:!0,_workingColorSpace:Ze,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(t){if(!ci.has(t))throw new Error(`Unsupported working color space, "${t}".`);this._workingColorSpace=t},convert:function(t,e,s){if(!1===this.enabled||e===s||!e||!s)return t;const i=li[e].toReference;return(0,li[s].fromReference)(i(t))},fromWorkingColorSpace:function(t,e){return this.convert(t,this._workingColorSpace,e)},toWorkingColorSpace:function(t,e){return this.convert(t,e,this._workingColorSpace)},getPrimaries:function(t){return li[t].primaries},getTransfer:function(t){return t===Ye?ts:li[t].transfer}};function pi(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function mi(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let gi;class fi{static getDataURL(t){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{void 0===gi&&(gi=ri("canvas")),gi.width=t.width,gi.height=t.height;const s=gi.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),e=gi}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const e=ri("canvas");e.width=t.width,e.height=t.height;const s=e.getContext("2d");s.drawImage(t,0,0,t.width,t.height);const i=s.getImageData(0,0,t.width,t.height),r=i.data;for(let t=0;t0&&(s.userData=this.userData),e||(t.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==at)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case pt:t.x=t.x-Math.floor(t.x);break;case mt:t.x=t.x<0?0:1;break;case gt:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case pt:t.y=t.y-Math.floor(t.y);break;case mt:t.y=t.y<0?0:1;break;case gt:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){!0===t&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){!0===t&&this.pmremVersion++}}Ti.DEFAULT_IMAGE=null,Ti.DEFAULT_MAPPING=at,Ti.DEFAULT_ANISOTROPY=1;class _i{constructor(t=0,e=0,s=0,i=1){_i.prototype.isVector4=!0,this.x=t,this.y=e,this.z=s,this.w=i}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,s,i){return this.x=t,this.y=e,this.z=s,this.w=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=void 0!==t.w?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=this.w,n=t.elements;return this.x=n[0]*e+n[4]*s+n[8]*i+n[12]*r,this.y=n[1]*e+n[5]*s+n[9]*i+n[13]*r,this.z=n[2]*e+n[6]*s+n[10]*i+n[14]*r,this.w=n[3]*e+n[7]*s+n[11]*i+n[15]*r,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,s,i,r;const n=.01,o=.1,a=t.elements,h=a[0],u=a[4],l=a[8],c=a[1],d=a[5],p=a[9],m=a[2],g=a[6],f=a[10];if(Math.abs(u-c)a&&t>y?ty?a=0?1:-1,i=1-e*e;if(i>Number.EPSILON){const r=Math.sqrt(i),n=Math.atan2(r,e*s);t=Math.sin(t*n)/r,o=Math.sin(o*n)/r}const r=o*s;if(a=a*t+c*r,h=h*t+d*r,u=u*t+p*r,l=l*t+m*r,t===1-o){const t=1/Math.sqrt(a*a+h*h+u*u+l*l);a*=t,h*=t,u*=t,l*=t}}t[e]=a,t[e+1]=h,t[e+2]=u,t[e+3]=l}static multiplyQuaternionsFlat(t,e,s,i,r,n){const o=s[i],a=s[i+1],h=s[i+2],u=s[i+3],l=r[n],c=r[n+1],d=r[n+2],p=r[n+3];return t[e]=o*p+u*l+a*d-h*c,t[e+1]=a*p+u*c+h*l-o*d,t[e+2]=h*p+u*d+o*c-a*l,t[e+3]=u*p-o*l-a*c-h*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,s,i){return this._x=t,this._y=e,this._z=s,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const s=t._x,i=t._y,r=t._z,n=t._order,o=Math.cos,a=Math.sin,h=o(s/2),u=o(i/2),l=o(r/2),c=a(s/2),d=a(i/2),p=a(r/2);switch(n){case"XYZ":this._x=c*u*l+h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l-c*d*p;break;case"YXZ":this._x=c*u*l+h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l+c*d*p;break;case"ZXY":this._x=c*u*l-h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l-c*d*p;break;case"ZYX":this._x=c*u*l-h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l+c*d*p;break;case"YZX":this._x=c*u*l+h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l-c*d*p;break;case"XZY":this._x=c*u*l-h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l+c*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,i=Math.sin(s);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],i=e[4],r=e[8],n=e[1],o=e[5],a=e[9],h=e[2],u=e[6],l=e[10],c=s+o+l;if(c>0){const t=.5/Math.sqrt(c+1);this._w=.25/t,this._x=(u-a)*t,this._y=(r-h)*t,this._z=(n-i)*t}else if(s>o&&s>l){const t=2*Math.sqrt(1+s-o-l);this._w=(u-a)/t,this._x=.25*t,this._y=(i+n)/t,this._z=(r+h)/t}else if(o>l){const t=2*Math.sqrt(1+o-s-l);this._w=(r-h)/t,this._x=(i+n)/t,this._y=.25*t,this._z=(a+u)/t}else{const t=2*Math.sqrt(1+l-s-o);this._w=(n-i)/t,this._x=(r+h)/t,this._y=(a+u)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return sMath.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs($s(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(0===s)return this;const i=Math.min(1,e/s);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const s=t._x,i=t._y,r=t._z,n=t._w,o=e._x,a=e._y,h=e._z,u=e._w;return this._x=s*u+n*o+i*h-r*a,this._y=i*u+n*a+r*o-s*h,this._z=r*u+n*h+s*a-i*o,this._w=n*u-s*o-i*a-r*h,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const s=this._x,i=this._y,r=this._z,n=this._w;let o=n*t._w+s*t._x+i*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=n,this._x=s,this._y=i,this._z=r,this;const a=1-o*o;if(a<=Number.EPSILON){const t=1-e;return this._w=t*n+e*this._w,this._x=t*s+e*this._x,this._y=t*i+e*this._y,this._z=t*r+e*this._z,this.normalize(),this}const h=Math.sqrt(a),u=Math.atan2(h,o),l=Math.sin((1-e)*u)/h,c=Math.sin(e*u)/h;return this._w=n*l+this._w*c,this._x=s*l+this._x*c,this._y=i*l+this._y*c,this._z=r*l+this._z*c,this._onChangeCallback(),this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class Ei{constructor(t=0,e=0,s=0){Ei.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return void 0===s&&(s=this.z),this.x=t,this.y=e,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(Ii.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Ii.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*i,this.y=r[1]*e+r[4]*s+r[7]*i,this.z=r[2]*e+r[5]*s+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=t.elements,n=1/(r[3]*e+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*e+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*e+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,r=t.x,n=t.y,o=t.z,a=t.w,h=2*(n*i-o*s),u=2*(o*e-r*i),l=2*(r*s-n*e);return this.x=e+a*h+n*l-o*u,this.y=s+a*u+o*h-r*l,this.z=i+a*l+r*u-n*h,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*i,this.y=r[1]*e+r[5]*s+r[9]*i,this.z=r[2]*e+r[6]*s+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,i=t.y,r=t.z,n=e.x,o=e.y,a=e.z;return this.x=i*a-r*o,this.y=r*n-s*a,this.z=s*o-i*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return Bi.copy(this).projectOnVector(t),this.sub(Bi)}reflect(t){return this.sub(Bi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos($s(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,i=this.z-t.z;return e*e+s*s+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,s){const i=Math.sin(e)*t;return this.x=i*Math.sin(s),this.y=Math.cos(e)*t,this.z=i*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Bi=new Ei,Ii=new Ci;class Pi{constructor(t=new Ei(1/0,1/0,1/0),e=new Ei(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,s=t.length;ethis.max.x||t.ythis.max.y||t.zthis.max.z)}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return!(t.max.xthis.max.x||t.max.ythis.max.y||t.max.zthis.max.z)}intersectsSphere(t){return this.clampPoint(t.center,Ui),Ui.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,s;return t.normal.x>0?(e=t.normal.x*this.min.x,s=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,s=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,s+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,s+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,s+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,s+=t.normal.z*this.min.z),e<=-t.constant&&s>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Wi),ji.subVectors(this.max,Wi),Li.subVectors(t.a,Wi),zi.subVectors(t.b,Wi),Vi.subVectors(t.c,Wi),Di.subVectors(zi,Li),ki.subVectors(Vi,zi),Gi.subVectors(Li,Vi);let e=[0,-Di.z,Di.y,0,-ki.z,ki.y,0,-Gi.z,Gi.y,Di.z,0,-Di.x,ki.z,0,-ki.x,Gi.z,0,-Gi.x,-Di.y,Di.x,0,-ki.y,ki.x,0,-Gi.y,Gi.x,0];return!!$i(e,Li,zi,Vi,ji)&&(e=[1,0,0,0,1,0,0,0,1],!!$i(e,Li,zi,Vi,ji)&&(Hi.crossVectors(Di,ki),e=[Hi.x,Hi.y,Hi.z],$i(e,Li,zi,Vi,ji)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Ui).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(Ui).length()),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()||(Fi[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Fi[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Fi[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Fi[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Fi[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Fi[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Fi[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Fi[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Fi)),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const Fi=[new Ei,new Ei,new Ei,new Ei,new Ei,new Ei,new Ei,new Ei],Ui=new Ei,Oi=new Pi,Li=new Ei,zi=new Ei,Vi=new Ei,Di=new Ei,ki=new Ei,Gi=new Ei,Wi=new Ei,ji=new Ei,Hi=new Ei,qi=new Ei;function $i(t,e,s,i,r){for(let n=0,o=t.length-3;n<=o;n+=3){qi.fromArray(t,n);const o=r.x*Math.abs(qi.x)+r.y*Math.abs(qi.y)+r.z*Math.abs(qi.z),a=e.dot(qi),h=s.dot(qi),u=i.dot(qi);if(Math.max(-Math.max(a,h,u),Math.min(a,h,u))>o)return!1}return!0}const Xi=new Pi,Yi=new Ei,Ji=new Ei;class Zi{constructor(t=new Ei,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const s=this.center;void 0!==e?s.copy(e):Xi.setFromPoints(t).getCenter(s);let i=0;for(let e=0,r=t.length;ethis.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;Yi.subVectors(t,this.center);const e=Yi.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),s=.5*(t-this.radius);this.center.addScaledVector(Yi,s/t),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(!0===this.center.equals(t.center)?this.radius=Math.max(this.radius,t.radius):(Ji.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(Yi.copy(t.center).add(Ji)),this.expandByPoint(Yi.copy(t.center).sub(Ji))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const Qi=new Ei,Ki=new Ei,tr=new Ei,er=new Ei,sr=new Ei,ir=new Ei,rr=new Ei;class nr{constructor(t=new Ei,e=new Ei(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,Qi)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const s=e.dot(this.direction);return s<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,s)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=Qi.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(Qi.copy(this.origin).addScaledVector(this.direction,e),Qi.distanceToSquared(t))}distanceSqToSegment(t,e,s,i){Ki.copy(t).add(e).multiplyScalar(.5),tr.copy(e).sub(t).normalize(),er.copy(this.origin).sub(Ki);const r=.5*t.distanceTo(e),n=-this.direction.dot(tr),o=er.dot(this.direction),a=-er.dot(tr),h=er.lengthSq(),u=Math.abs(1-n*n);let l,c,d,p;if(u>0)if(l=n*a-o,c=n*o-a,p=r*u,l>=0)if(c>=-p)if(c<=p){const t=1/u;l*=t,c*=t,d=l*(l+n*c+2*o)+c*(n*l+c+2*a)+h}else c=r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;else c=-r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;else c<=-p?(l=Math.max(0,-(-n*r+o)),c=l>0?-r:Math.min(Math.max(-r,-a),r),d=-l*l+c*(c+2*a)+h):c<=p?(l=0,c=Math.min(Math.max(-r,-a),r),d=c*(c+2*a)+h):(l=Math.max(0,-(n*r+o)),c=l>0?r:Math.min(Math.max(-r,-a),r),d=-l*l+c*(c+2*a)+h);else c=n>0?-r:r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;return s&&s.copy(this.origin).addScaledVector(this.direction,l),i&&i.copy(Ki).addScaledVector(tr,c),d}intersectSphere(t,e){Qi.subVectors(t.center,this.origin);const s=Qi.dot(this.direction),i=Qi.dot(Qi)-s*s,r=t.radius*t.radius;if(i>r)return null;const n=Math.sqrt(r-i),o=s-n,a=s+n;return a<0?null:o<0?this.at(a,e):this.at(o,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const s=-(this.origin.dot(t.normal)+t.constant)/e;return s>=0?s:null}intersectPlane(t,e){const s=this.distanceToPlane(t);return null===s?null:this.at(s,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);if(0===e)return!0;return t.normal.dot(this.direction)*e<0}intersectBox(t,e){let s,i,r,n,o,a;const h=1/this.direction.x,u=1/this.direction.y,l=1/this.direction.z,c=this.origin;return h>=0?(s=(t.min.x-c.x)*h,i=(t.max.x-c.x)*h):(s=(t.max.x-c.x)*h,i=(t.min.x-c.x)*h),u>=0?(r=(t.min.y-c.y)*u,n=(t.max.y-c.y)*u):(r=(t.max.y-c.y)*u,n=(t.min.y-c.y)*u),s>n||r>i?null:((r>s||isNaN(s))&&(s=r),(n=0?(o=(t.min.z-c.z)*l,a=(t.max.z-c.z)*l):(o=(t.max.z-c.z)*l,a=(t.min.z-c.z)*l),s>a||o>i?null:((o>s||s!=s)&&(s=o),(a=0?s:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,Qi)}intersectTriangle(t,e,s,i,r){sr.subVectors(e,t),ir.subVectors(s,t),rr.crossVectors(sr,ir);let n,o=this.direction.dot(rr);if(o>0){if(i)return null;n=1}else{if(!(o<0))return null;n=-1,o=-o}er.subVectors(this.origin,t);const a=n*this.direction.dot(ir.crossVectors(er,ir));if(a<0)return null;const h=n*this.direction.dot(sr.cross(er));if(h<0)return null;if(a+h>o)return null;const u=-n*er.dot(rr);return u<0?null:this.at(u/o,r)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class or{constructor(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g){or.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g)}set(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g){const f=this.elements;return f[0]=t,f[4]=e,f[8]=s,f[12]=i,f[1]=r,f[5]=n,f[9]=o,f[13]=a,f[2]=h,f[6]=u,f[10]=l,f[14]=c,f[3]=d,f[7]=p,f[11]=m,f[15]=g,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new or).fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,s){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,s=t.elements,i=1/ar.setFromMatrixColumn(t,0).length(),r=1/ar.setFromMatrixColumn(t,1).length(),n=1/ar.setFromMatrixColumn(t,2).length();return e[0]=s[0]*i,e[1]=s[1]*i,e[2]=s[2]*i,e[3]=0,e[4]=s[4]*r,e[5]=s[5]*r,e[6]=s[6]*r,e[7]=0,e[8]=s[8]*n,e[9]=s[9]*n,e[10]=s[10]*n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,i=t.y,r=t.z,n=Math.cos(s),o=Math.sin(s),a=Math.cos(i),h=Math.sin(i),u=Math.cos(r),l=Math.sin(r);if("XYZ"===t.order){const t=n*u,s=n*l,i=o*u,r=o*l;e[0]=a*u,e[4]=-a*l,e[8]=h,e[1]=s+i*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=i+s*h,e[10]=n*a}else if("YXZ"===t.order){const t=a*u,s=a*l,i=h*u,r=h*l;e[0]=t+r*o,e[4]=i*o-s,e[8]=n*h,e[1]=n*l,e[5]=n*u,e[9]=-o,e[2]=s*o-i,e[6]=r+t*o,e[10]=n*a}else if("ZXY"===t.order){const t=a*u,s=a*l,i=h*u,r=h*l;e[0]=t-r*o,e[4]=-n*l,e[8]=i+s*o,e[1]=s+i*o,e[5]=n*u,e[9]=r-t*o,e[2]=-n*h,e[6]=o,e[10]=n*a}else if("ZYX"===t.order){const t=n*u,s=n*l,i=o*u,r=o*l;e[0]=a*u,e[4]=i*h-s,e[8]=t*h+r,e[1]=a*l,e[5]=r*h+t,e[9]=s*h-i,e[2]=-h,e[6]=o*a,e[10]=n*a}else if("YZX"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*u,e[4]=r-t*l,e[8]=i*l+s,e[1]=l,e[5]=n*u,e[9]=-o*u,e[2]=-h*u,e[6]=s*l+i,e[10]=t-r*l}else if("XZY"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*u,e[4]=-l,e[8]=h*u,e[1]=t*l+r,e[5]=n*u,e[9]=s*l-i,e[2]=i*l-s,e[6]=o*u,e[10]=r*l+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(ur,t,lr)}lookAt(t,e,s){const i=this.elements;return pr.subVectors(t,e),0===pr.lengthSq()&&(pr.z=1),pr.normalize(),cr.crossVectors(s,pr),0===cr.lengthSq()&&(1===Math.abs(s.z)?pr.x+=1e-4:pr.z+=1e-4,pr.normalize(),cr.crossVectors(s,pr)),cr.normalize(),dr.crossVectors(pr,cr),i[0]=cr.x,i[4]=dr.x,i[8]=pr.x,i[1]=cr.y,i[5]=dr.y,i[9]=pr.y,i[2]=cr.z,i[6]=dr.z,i[10]=pr.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[4],a=s[8],h=s[12],u=s[1],l=s[5],c=s[9],d=s[13],p=s[2],m=s[6],g=s[10],f=s[14],y=s[3],x=s[7],b=s[11],v=s[15],T=i[0],_=i[4],w=i[8],S=i[12],M=i[1],A=i[5],N=i[9],R=i[13],C=i[2],E=i[6],B=i[10],I=i[14],P=i[3],F=i[7],U=i[11],O=i[15];return r[0]=n*T+o*M+a*C+h*P,r[4]=n*_+o*A+a*E+h*F,r[8]=n*w+o*N+a*B+h*U,r[12]=n*S+o*R+a*I+h*O,r[1]=u*T+l*M+c*C+d*P,r[5]=u*_+l*A+c*E+d*F,r[9]=u*w+l*N+c*B+d*U,r[13]=u*S+l*R+c*I+d*O,r[2]=p*T+m*M+g*C+f*P,r[6]=p*_+m*A+g*E+f*F,r[10]=p*w+m*N+g*B+f*U,r[14]=p*S+m*R+g*I+f*O,r[3]=y*T+x*M+b*C+v*P,r[7]=y*_+x*A+b*E+v*F,r[11]=y*w+x*N+b*B+v*U,r[15]=y*S+x*R+b*I+v*O,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[4],i=t[8],r=t[12],n=t[1],o=t[5],a=t[9],h=t[13],u=t[2],l=t[6],c=t[10],d=t[14];return t[3]*(+r*a*l-i*h*l-r*o*c+s*h*c+i*o*d-s*a*d)+t[7]*(+e*a*d-e*h*c+r*n*c-i*n*d+i*h*u-r*a*u)+t[11]*(+e*h*l-e*o*d-r*n*l+s*n*d+r*o*u-s*h*u)+t[15]*(-i*o*u-e*a*l+e*o*c+i*n*l-s*n*c+s*a*u)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,s){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8],l=t[9],c=t[10],d=t[11],p=t[12],m=t[13],g=t[14],f=t[15],y=l*g*h-m*c*h+m*a*d-o*g*d-l*a*f+o*c*f,x=p*c*h-u*g*h-p*a*d+n*g*d+u*a*f-n*c*f,b=u*m*h-p*l*h+p*o*d-n*m*d-u*o*f+n*l*f,v=p*l*a-u*m*a-p*o*c+n*m*c+u*o*g-n*l*g,T=e*y+s*x+i*b+r*v;if(0===T)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const _=1/T;return t[0]=y*_,t[1]=(m*c*r-l*g*r-m*i*d+s*g*d+l*i*f-s*c*f)*_,t[2]=(o*g*r-m*a*r+m*i*h-s*g*h-o*i*f+s*a*f)*_,t[3]=(l*a*r-o*c*r-l*i*h+s*c*h+o*i*d-s*a*d)*_,t[4]=x*_,t[5]=(u*g*r-p*c*r+p*i*d-e*g*d-u*i*f+e*c*f)*_,t[6]=(p*a*r-n*g*r-p*i*h+e*g*h+n*i*f-e*a*f)*_,t[7]=(n*c*r-u*a*r+u*i*h-e*c*h-n*i*d+e*a*d)*_,t[8]=b*_,t[9]=(p*l*r-u*m*r-p*s*d+e*m*d+u*s*f-e*l*f)*_,t[10]=(n*m*r-p*o*r+p*s*h-e*m*h-n*s*f+e*o*f)*_,t[11]=(u*o*r-n*l*r-u*s*h+e*l*h+n*s*d-e*o*d)*_,t[12]=v*_,t[13]=(u*m*i-p*l*i+p*s*c-e*m*c-u*s*g+e*l*g)*_,t[14]=(p*o*i-n*m*i-p*s*a+e*m*a+n*s*g-e*o*g)*_,t[15]=(n*l*i-u*o*i+u*s*a-e*l*a-n*s*c+e*o*c)*_,this}scale(t){const e=this.elements,s=t.x,i=t.y,r=t.z;return e[0]*=s,e[4]*=i,e[8]*=r,e[1]*=s,e[5]*=i,e[9]*=r,e[2]*=s,e[6]*=i,e[10]*=r,e[3]*=s,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,s,i))}makeTranslation(t,e,s){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),i=Math.sin(e),r=1-s,n=t.x,o=t.y,a=t.z,h=r*n,u=r*o;return this.set(h*n+s,h*o-i*a,h*a+i*o,0,h*o+i*a,u*o+s,u*a-i*n,0,h*a-i*o,u*a+i*n,r*a*a+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,i,r,n){return this.set(1,s,r,0,t,1,n,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,r=e._x,n=e._y,o=e._z,a=e._w,h=r+r,u=n+n,l=o+o,c=r*h,d=r*u,p=r*l,m=n*u,g=n*l,f=o*l,y=a*h,x=a*u,b=a*l,v=s.x,T=s.y,_=s.z;return i[0]=(1-(m+f))*v,i[1]=(d+b)*v,i[2]=(p-x)*v,i[3]=0,i[4]=(d-b)*T,i[5]=(1-(c+f))*T,i[6]=(g+y)*T,i[7]=0,i[8]=(p+x)*_,i[9]=(g-y)*_,i[10]=(1-(c+m))*_,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,s){const i=this.elements;let r=ar.set(i[0],i[1],i[2]).length();const n=ar.set(i[4],i[5],i[6]).length(),o=ar.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),t.x=i[12],t.y=i[13],t.z=i[14],hr.copy(this);const a=1/r,h=1/n,u=1/o;return hr.elements[0]*=a,hr.elements[1]*=a,hr.elements[2]*=a,hr.elements[4]*=h,hr.elements[5]*=h,hr.elements[6]*=h,hr.elements[8]*=u,hr.elements[9]*=u,hr.elements[10]*=u,e.setFromRotationMatrix(hr),s.x=r,s.y=n,s.z=o,this}makePerspective(t,e,s,i,r,n,o=2e3){const a=this.elements,h=2*r/(e-t),u=2*r/(s-i),l=(e+t)/(e-t),c=(s+i)/(s-i);let d,p;if(o===Vs)d=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(o!==Ds)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);d=-n/(n-r),p=-n*r/(n-r)}return a[0]=h,a[4]=0,a[8]=l,a[12]=0,a[1]=0,a[5]=u,a[9]=c,a[13]=0,a[2]=0,a[6]=0,a[10]=d,a[14]=p,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,s,i,r,n,o=2e3){const a=this.elements,h=1/(e-t),u=1/(s-i),l=1/(n-r),c=(e+t)*h,d=(s+i)*u;let p,m;if(o===Vs)p=(n+r)*l,m=-2*l;else{if(o!==Ds)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=r*l,m=-1*l}return a[0]=2*h,a[4]=0,a[8]=0,a[12]=-c,a[1]=0,a[5]=2*u,a[9]=0,a[13]=-d,a[2]=0,a[6]=0,a[10]=m,a[14]=-p,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<16;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const ar=new Ei,hr=new or,ur=new Ei(0,0,0),lr=new Ei(1,1,1),cr=new Ei,dr=new Ei,pr=new Ei,mr=new or,gr=new Ci;class fr{constructor(t=0,e=0,s=0,i=fr.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,s,i=this._order){return this._x=t,this._y=e,this._z=s,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,s=!0){const i=t.elements,r=i[0],n=i[4],o=i[8],a=i[1],h=i[5],u=i[9],l=i[2],c=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin($s(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-u,d),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(c,h),this._z=0);break;case"YXZ":this._x=Math.asin(-$s(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-l,r),this._z=0);break;case"ZXY":this._x=Math.asin($s(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(-l,d),this._z=Math.atan2(-n,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-$s(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(c,d),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-n,h));break;case"YZX":this._z=Math.asin($s(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-u,h),this._y=Math.atan2(-l,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-$s(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(c,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-u,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===s&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return mr.makeRotationFromQuaternion(t),this.setFromRotationMatrix(mr,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return gr.setFromEuler(this),this.setFromQuaternion(gr,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}fr.DEFAULT_ORDER="XYZ";class yr{constructor(){this.mask=1}set(t){this.mask=(1<>>0}enable(t){this.mask|=1<1){for(let t=0;t1){for(let t=0;t0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.visibility=this._visibility,i.active=this._active,i.bounds=this._bounds.map((t=>({boxInitialized:t.boxInitialized,boxMin:t.box.min.toArray(),boxMax:t.box.max.toArray(),sphereInitialized:t.sphereInitialized,sphereRadius:t.sphere.radius,sphereCenter:t.sphere.center.toArray()}))),i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.geometryCount=this._geometryCount,i.matricesTexture=this._matricesTexture.toJSON(t),null!==this._colorsTexture&&(i.colorsTexture=this._colorsTexture.toJSON(t)),null!==this.boundingSphere&&(i.boundingSphere={center:i.boundingSphere.center.toArray(),radius:i.boundingSphere.radius}),null!==this.boundingBox&&(i.boundingBox={min:i.boundingBox.min.toArray(),max:i.boundingBox.max.toArray()})),this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=r(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const s=e.shapes;if(Array.isArray(s))for(let e=0,i=s.length;e0){i.children=[];for(let e=0;e0){i.animations=[];for(let e=0;e0&&(s.geometries=e),i.length>0&&(s.materials=i),r.length>0&&(s.textures=r),o.length>0&&(s.images=o),a.length>0&&(s.shapes=a),h.length>0&&(s.skeletons=h),u.length>0&&(s.animations=u),l.length>0&&(s.nodes=l)}return s.object=i,s;function n(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}}clone(t){return(new this.constructor).copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(let e=0;e0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,s,i,r){Fr.subVectors(i,e),Ur.subVectors(s,e),Or.subVectors(t,e);const n=Fr.dot(Fr),o=Fr.dot(Ur),a=Fr.dot(Or),h=Ur.dot(Ur),u=Ur.dot(Or),l=n*h-o*o;if(0===l)return r.set(0,0,0),null;const c=1/l,d=(h*a-o*u)*c,p=(n*u-o*a)*c;return r.set(1-d-p,p,d)}static containsPoint(t,e,s,i){return null!==this.getBarycoord(t,e,s,i,Lr)&&(Lr.x>=0&&Lr.y>=0&&Lr.x+Lr.y<=1)}static getInterpolation(t,e,s,i,r,n,o,a){return null===this.getBarycoord(t,e,s,i,Lr)?(a.x=0,a.y=0,"z"in a&&(a.z=0),"w"in a&&(a.w=0),null):(a.setScalar(0),a.addScaledVector(r,Lr.x),a.addScaledVector(n,Lr.y),a.addScaledVector(o,Lr.z),a)}static isFrontFacing(t,e,s,i){return Fr.subVectors(s,e),Ur.subVectors(t,e),Fr.cross(Ur).dot(i)<0}set(t,e,s){return this.a.copy(t),this.b.copy(e),this.c.copy(s),this}setFromPointsAndIndices(t,e,s,i){return this.a.copy(t[e]),this.b.copy(t[s]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,s,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,s),this.c.fromBufferAttribute(t,i),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return Fr.subVectors(this.c,this.b),Ur.subVectors(this.a,this.b),.5*Fr.cross(Ur).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return jr.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return jr.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,s,i,r){return jr.getInterpolation(t,this.a,this.b,this.c,e,s,i,r)}containsPoint(t){return jr.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return jr.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const s=this.a,i=this.b,r=this.c;let n,o;zr.subVectors(i,s),Vr.subVectors(r,s),kr.subVectors(t,s);const a=zr.dot(kr),h=Vr.dot(kr);if(a<=0&&h<=0)return e.copy(s);Gr.subVectors(t,i);const u=zr.dot(Gr),l=Vr.dot(Gr);if(u>=0&&l<=u)return e.copy(i);const c=a*l-u*h;if(c<=0&&a>=0&&u<=0)return n=a/(a-u),e.copy(s).addScaledVector(zr,n);Wr.subVectors(t,r);const d=zr.dot(Wr),p=Vr.dot(Wr);if(p>=0&&d<=p)return e.copy(r);const m=d*h-a*p;if(m<=0&&h>=0&&p<=0)return o=h/(h-p),e.copy(s).addScaledVector(Vr,o);const g=u*p-d*l;if(g<=0&&l-u>=0&&d-p>=0)return Dr.subVectors(r,i),o=(l-u)/(l-u+(d-p)),e.copy(i).addScaledVector(Dr,o);const f=1/(g+m+c);return n=m*f,o=c*f,e.copy(s).addScaledVector(zr,n).addScaledVector(Vr,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const Hr={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},qr={h:0,s:0,l:0},$r={h:0,s:0,l:0};function Xr(t,e,s){return s<0&&(s+=1),s>1&&(s-=1),s<1/6?t+6*(e-t)*s:s<.5?e:s<2/3?t+6*(e-t)*(2/3-s):t}class Yr{constructor(t,e,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,s)}set(t,e,s){if(void 0===e&&void 0===s){const e=t;e&&e.isColor?this.copy(e):"number"==typeof e?this.setHex(e):"string"==typeof e&&this.setStyle(e)}else this.setRGB(t,e,s);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Je){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,di.toWorkingColorSpace(this,e),this}setRGB(t,e,s,i=di.workingColorSpace){return this.r=t,this.g=e,this.b=s,di.toWorkingColorSpace(this,i),this}setHSL(t,e,s,i=di.workingColorSpace){if(t=Xs(t,1),e=$s(e,0,1),s=$s(s,0,1),0===e)this.r=this.g=this.b=s;else{const i=s<=.5?s*(1+e):s+e-s*e,r=2*s-i;this.r=Xr(r,i,t+1/3),this.g=Xr(r,i,t),this.b=Xr(r,i,t-1/3)}return di.toWorkingColorSpace(this,i),this}setStyle(t,e=Je){function s(e){void 0!==e&&parseFloat(e)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let r;const n=i[1],o=i[2];switch(n){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){const s=i[1],r=s.length;if(3===r)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,e);if(6===r)return this.setHex(parseInt(s,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=Je){const s=Hr[t.toLowerCase()];return void 0!==s?this.setHex(s,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=pi(t.r),this.g=pi(t.g),this.b=pi(t.b),this}copyLinearToSRGB(t){return this.r=mi(t.r),this.g=mi(t.g),this.b=mi(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Je){return di.fromWorkingColorSpace(Jr.copy(this),t),65536*Math.round($s(255*Jr.r,0,255))+256*Math.round($s(255*Jr.g,0,255))+Math.round($s(255*Jr.b,0,255))}getHexString(t=Je){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=di.workingColorSpace){di.fromWorkingColorSpace(Jr.copy(this),e);const s=Jr.r,i=Jr.g,r=Jr.b,n=Math.max(s,i,r),o=Math.min(s,i,r);let a,h;const u=(o+n)/2;if(o===n)a=0,h=0;else{const t=n-o;switch(h=u<=.5?t/(n+o):t/(2-n-o),n){case s:a=(i-r)/t+(i0!=t>0&&this.version++,this._alphaTest=t}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const s=t[e];if(void 0===s){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(s):i&&i.isVector3&&s&&s.isVector3?i.copy(s):this[e]=s:console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const s={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(s.uuid=this.uuid,s.type=this.type,""!==this.name&&(s.name=this.name),this.color&&this.color.isColor&&(s.color=this.color.getHex()),void 0!==this.roughness&&(s.roughness=this.roughness),void 0!==this.metalness&&(s.metalness=this.metalness),void 0!==this.sheen&&(s.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(s.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(s.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(s.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(s.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(s.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(s.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(s.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(s.shininess=this.shininess),void 0!==this.clearcoat&&(s.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(s.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(s.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(s.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(s.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,s.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.dispersion&&(s.dispersion=this.dispersion),void 0!==this.iridescence&&(s.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(s.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(s.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(s.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(s.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(s.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(s.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(s.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(s.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(s.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(s.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(s.lightMap=this.lightMap.toJSON(t).uuid,s.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(s.aoMap=this.aoMap.toJSON(t).uuid,s.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(s.bumpMap=this.bumpMap.toJSON(t).uuid,s.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(s.normalMap=this.normalMap.toJSON(t).uuid,s.normalMapType=this.normalMapType,s.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(s.displacementMap=this.displacementMap.toJSON(t).uuid,s.displacementScale=this.displacementScale,s.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(s.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(s.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(s.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(s.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(s.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(s.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(s.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(s.combine=this.combine)),void 0!==this.envMapRotation&&(s.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(s.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(s.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(s.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(s.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(s.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(s.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(s.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(s.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(s.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(s.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(s.size=this.size),null!==this.shadowSide&&(s.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(s.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(s.blending=this.blending),this.side!==c&&(s.side=this.side),!0===this.vertexColors&&(s.vertexColors=!0),this.opacity<1&&(s.opacity=this.opacity),!0===this.transparent&&(s.transparent=!0),this.blendSrc!==C&&(s.blendSrc=this.blendSrc),this.blendDst!==E&&(s.blendDst=this.blendDst),this.blendEquation!==v&&(s.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(s.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(s.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(s.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(s.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(s.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(s.depthFunc=this.depthFunc),!1===this.depthTest&&(s.depthTest=this.depthTest),!1===this.depthWrite&&(s.depthWrite=this.depthWrite),!1===this.colorWrite&&(s.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(s.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==bs&&(s.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(s.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(s.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==ns&&(s.stencilFail=this.stencilFail),this.stencilZFail!==ns&&(s.stencilZFail=this.stencilZFail),this.stencilZPass!==ns&&(s.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(s.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(s.rotation=this.rotation),!0===this.polygonOffset&&(s.polygonOffset=!0),0!==this.polygonOffsetFactor&&(s.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(s.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(s.linewidth=this.linewidth),void 0!==this.dashSize&&(s.dashSize=this.dashSize),void 0!==this.gapSize&&(s.gapSize=this.gapSize),void 0!==this.scale&&(s.scale=this.scale),!0===this.dithering&&(s.dithering=!0),this.alphaTest>0&&(s.alphaTest=this.alphaTest),!0===this.alphaHash&&(s.alphaHash=!0),!0===this.alphaToCoverage&&(s.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(s.premultipliedAlpha=!0),!0===this.forceSinglePass&&(s.forceSinglePass=!0),!0===this.wireframe&&(s.wireframe=!0),this.wireframeLinewidth>1&&(s.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(s.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(s.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(s.flatShading=!0),!1===this.visible&&(s.visible=!1),!1===this.toneMapped&&(s.toneMapped=!1),!1===this.fog&&(s.fog=!1),Object.keys(this.userData).length>0&&(s.userData=this.userData),e){const e=i(t.textures),r=i(t.images);e.length>0&&(s.textures=e),r.length>0&&(s.images=r)}return s}clone(){return(new this.constructor).copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let s=null;if(null!==e){const t=e.length;s=new Array(t);for(let i=0;i!==t;++i)s[i]=e[i].clone()}return this.clippingPlanes=s,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}onBuild(){console.warn("Material: onBuild() has been removed.")}onBeforeRender(){console.warn("Material: onBeforeRender() has been removed.")}}class Kr extends Qr{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Yr(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fr,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const tn=en();function en(){const t=new ArrayBuffer(4),e=new Float32Array(t),s=new Uint32Array(t),i=new Uint32Array(512),r=new Uint32Array(512);for(let t=0;t<256;++t){const e=t-127;e<-27?(i[t]=0,i[256|t]=32768,r[t]=24,r[256|t]=24):e<-14?(i[t]=1024>>-e-14,i[256|t]=1024>>-e-14|32768,r[t]=-e-1,r[256|t]=-e-1):e<=15?(i[t]=e+15<<10,i[256|t]=e+15<<10|32768,r[t]=13,r[256|t]=13):e<128?(i[t]=31744,i[256|t]=64512,r[t]=24,r[256|t]=24):(i[t]=31744,i[256|t]=64512,r[t]=13,r[256|t]=13)}const n=new Uint32Array(2048),o=new Uint32Array(64),a=new Uint32Array(64);for(let t=1;t<1024;++t){let e=t<<13,s=0;for(;0==(8388608&e);)e<<=1,s-=8388608;e&=-8388609,s+=947912704,n[t]=e|s}for(let t=1024;t<2048;++t)n[t]=939524096+(t-1024<<13);for(let t=1;t<31;++t)o[t]=t<<23;o[31]=1199570944,o[32]=2147483648;for(let t=33;t<63;++t)o[t]=2147483648+(t-32<<23);o[63]=3347054592;for(let t=1;t<64;++t)32!==t&&(a[t]=1024);return{floatView:e,uint32View:s,baseTable:i,shiftTable:r,mantissaTable:n,exponentTable:o,offsetTable:a}}function sn(t){Math.abs(t)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),t=$s(t,-65504,65504),tn.floatView[0]=t;const e=tn.uint32View[0],s=e>>23&511;return tn.baseTable[s]+((8388607&e)>>tn.shiftTable[s])}function rn(t){const e=t>>10;return tn.uint32View[0]=tn.mantissaTable[tn.offsetTable[e]+(1023&t)]+tn.exponentTable[e],tn.floatView[0]}const nn={toHalfFloat:sn,fromHalfFloat:rn},on=new Ei,an=new Ks;class hn{constructor(t,e,s=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=s,this.usage=Rs,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.gpuType=It,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}get updateRange(){return ai("THREE.BufferAttribute: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead."),this._updateRange}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,s){t*=this.itemSize,s*=e.itemSize;for(let i=0,r=this.itemSize;i=0;--e)if(t[e]>=65535)return!0;return!1}(t)?gn:pn)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return void 0!==this.attributes[t]}addGroup(t,e,s=0){this.groups.push({start:t,count:e,materialIndex:s})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;void 0!==e&&(e.applyMatrix4(t),e.needsUpdate=!0);const s=this.attributes.normal;if(void 0!==s){const e=(new ti).getNormalMatrix(t);s.applyNormalMatrix(e),s.needsUpdate=!0}const i=this.attributes.tangent;return void 0!==i&&(i.transformDirection(t),i.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}applyQuaternion(t){return bn.makeRotationFromQuaternion(t),this.applyMatrix4(bn),this}rotateX(t){return bn.makeRotationX(t),this.applyMatrix4(bn),this}rotateY(t){return bn.makeRotationY(t),this.applyMatrix4(bn),this}rotateZ(t){return bn.makeRotationZ(t),this.applyMatrix4(bn),this}translate(t,e,s){return bn.makeTranslation(t,e,s),this.applyMatrix4(bn),this}scale(t,e,s){return bn.makeScale(t,e,s),this.applyMatrix4(bn),this}lookAt(t){return vn.lookAt(t),vn.updateMatrix(),this.applyMatrix4(vn.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Tn).negate(),this.translate(Tn.x,Tn.y,Tn.z),this}setFromPoints(t){const e=[];for(let s=0,i=t.length;s0&&(t.userData=this.userData),void 0!==this.parameters){const e=this.parameters;for(const s in e)void 0!==e[s]&&(t[s]=e[s]);return t}t.data={attributes:{}};const e=this.index;null!==e&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const s=this.attributes;for(const e in s){const i=s[e];t.data.attributes[e]=i.toJSON(t.data)}const i={};let r=!1;for(const e in this.morphAttributes){const s=this.morphAttributes[e],n=[];for(let e=0,i=s.length;e0&&(i[e]=n,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const n=this.groups;n.length>0&&(t.data.groups=JSON.parse(JSON.stringify(n)));const o=this.boundingSphere;return null!==o&&(t.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),t}clone(){return(new this.constructor).copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const s=t.index;null!==s&&this.setIndex(s.clone(e));const i=t.attributes;for(const t in i){const s=i[t];this.setAttribute(t,s.clone(e))}const r=t.morphAttributes;for(const t in r){const s=[],i=r[t];for(let t=0,r=i.length;t0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;t(t.far-t.near)**2)return}An.copy(r).invert(),Nn.copy(t.ray).applyMatrix4(An),null!==s.boundingBox&&!1===Nn.intersectsBox(s.boundingBox)||this._computeIntersections(t,e,Nn)}}_computeIntersections(t,e,s){let i;const r=this.geometry,n=this.material,o=r.index,a=r.attributes.position,h=r.attributes.uv,u=r.attributes.uv1,l=r.attributes.normal,c=r.groups,d=r.drawRange;if(null!==o)if(Array.isArray(n))for(let r=0,a=c.length;rs.far?null:{distance:u,point:Gn.clone(),object:t}}(t,e,s,i,En,Bn,In,kn);if(l){r&&(Un.fromBufferAttribute(r,a),On.fromBufferAttribute(r,h),Ln.fromBufferAttribute(r,u),l.uv=jr.getInterpolation(kn,En,Bn,In,Un,On,Ln,new Ks)),n&&(Un.fromBufferAttribute(n,a),On.fromBufferAttribute(n,h),Ln.fromBufferAttribute(n,u),l.uv1=jr.getInterpolation(kn,En,Bn,In,Un,On,Ln,new Ks)),o&&(zn.fromBufferAttribute(o,a),Vn.fromBufferAttribute(o,h),Dn.fromBufferAttribute(o,u),l.normal=jr.getInterpolation(kn,En,Bn,In,zn,Vn,Dn,new Ei),l.normal.dot(i.direction)>0&&l.normal.multiplyScalar(-1));const t={a:a,b:h,c:u,normal:new Ei,materialIndex:0};jr.getNormal(En,Bn,In,t.normal),l.face=t}return l}class Hn extends Mn{constructor(t=1,e=1,s=1,i=1,r=1,n=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:s,widthSegments:i,heightSegments:r,depthSegments:n};const o=this;i=Math.floor(i),r=Math.floor(r),n=Math.floor(n);const a=[],h=[],u=[],l=[];let c=0,d=0;function p(t,e,s,i,r,n,p,m,g,f,y){const x=n/g,b=p/f,v=n/2,T=p/2,_=m/2,w=g+1,S=f+1;let M=0,A=0;const N=new Ei;for(let n=0;n0?1:-1,u.push(N.x,N.y,N.z),l.push(a/g),l.push(1-n/f),M+=1}}for(let t=0;t0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const s={};for(const t in this.extensions)!0===this.extensions[t]&&(s[t]=!0);return Object.keys(s).length>0&&(e.extensions=s),e}}class Xn extends Pr{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new or,this.projectionMatrix=new or,this.projectionMatrixInverse=new or,this.coordinateSystem=Vs}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return(new this.constructor).copy(this)}}const Yn=new Ei,Jn=new Ks,Zn=new Ks;class Qn extends Xn{constructor(t=50,e=1,s=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=s,this.far=i,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=null===t.view?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=2*Hs*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*js*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*Hs*Math.atan(Math.tan(.5*js*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,s){Yn.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(Yn.x,Yn.y).multiplyScalar(-t/Yn.z),Yn.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),s.set(Yn.x,Yn.y).multiplyScalar(-t/Yn.z)}getViewSize(t,e){return this.getViewBounds(t,Jn,Zn),e.subVectors(Zn,Jn)}setViewOffset(t,e,s,i,r,n){this.aspect=t/e,null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=s,this.view.offsetY=i,this.view.width=r,this.view.height=n,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*js*this.fov)/this.zoom,s=2*e,i=this.aspect*s,r=-.5*i;const n=this.view;if(null!==this.view&&this.view.enabled){const t=n.fullWidth,o=n.fullHeight;r+=n.offsetX*i/t,e-=n.offsetY*s/o,i*=n.width/t,s*=n.height/o}const o=this.filmOffset;0!==o&&(r+=t*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+i,e,e-s,t,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,null!==this.view&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const Kn=-90;class to extends Pr{constructor(t,e,s){super(),this.type="CubeCamera",this.renderTarget=s,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Qn(Kn,1,t,e);i.layers=this.layers,this.add(i);const r=new Qn(Kn,1,t,e);r.layers=this.layers,this.add(r);const n=new Qn(Kn,1,t,e);n.layers=this.layers,this.add(n);const o=new Qn(Kn,1,t,e);o.layers=this.layers,this.add(o);const a=new Qn(Kn,1,t,e);a.layers=this.layers,this.add(a);const h=new Qn(Kn,1,t,e);h.layers=this.layers,this.add(h)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[s,i,r,n,o,a]=e;for(const t of e)this.remove(t);if(t===Vs)s.up.set(0,1,0),s.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),n.up.set(0,0,1),n.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),a.up.set(0,1,0),a.lookAt(0,0,-1);else{if(t!==Ds)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);s.up.set(0,-1,0),s.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),n.up.set(0,0,-1),n.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),a.up.set(0,-1,0),a.lookAt(0,0,-1)}for(const t of e)this.add(t),t.updateMatrixWorld()}update(t,e){null===this.parent&&this.updateMatrixWorld();const{renderTarget:s,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,n,o,a,h,u]=this.children,l=t.getRenderTarget(),c=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const m=s.texture.generateMipmaps;s.texture.generateMipmaps=!1,t.setRenderTarget(s,0,i),t.render(e,r),t.setRenderTarget(s,1,i),t.render(e,n),t.setRenderTarget(s,2,i),t.render(e,o),t.setRenderTarget(s,3,i),t.render(e,a),t.setRenderTarget(s,4,i),t.render(e,h),s.texture.generateMipmaps=m,t.setRenderTarget(s,5,i),t.render(e,u),t.setRenderTarget(l,c,d),t.xr.enabled=p,s.texture.needsPMREMUpdate=!0}}class eo extends Ti{constructor(t,e,s,i,r,n,o,a,h,u){super(t=void 0!==t?t:[],e=void 0!==e?e:ht,s,i,r,n,o,a,h,u),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class so extends Si{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const s={width:t,height:t,depth:1},i=[s,s,s,s,s,s];this.texture=new eo(i,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=void 0!==e.generateMipmaps&&e.generateMipmaps,this.texture.minFilter=void 0!==e.minFilter?e.minFilter:Tt}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const s={uniforms:{tEquirect:{value:null}},vertexShader:"\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include \n\t\t\t\t\t#include \n\n\t\t\t\t}\n\t\t\t",fragmentShader:"\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include \n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t"},i=new Hn(5,5,5),r=new $n({name:"CubemapFromEquirect",uniforms:qn(s.uniforms),vertexShader:s.vertexShader,fragmentShader:s.fragmentShader,side:d,blending:m});r.uniforms.tEquirect.value=e;const n=new Wn(i,r),o=e.minFilter;e.minFilter===St&&(e.minFilter=Tt);return new to(1,10,this).update(t,n),e.minFilter=o,n.geometry.dispose(),n.material.dispose(),this}clear(t,e,s,i){const r=t.getRenderTarget();for(let r=0;r<6;r++)t.setRenderTarget(this,r),t.clear(e,s,i);t.setRenderTarget(r)}}class io{constructor(t,e=25e-5){this.isFogExp2=!0,this.name="",this.color=new Yr(t),this.density=e}clone(){return new io(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}}class ro{constructor(t,e=1,s=1e3){this.isFog=!0,this.name="",this.color=new Yr(t),this.near=e,this.far=s}clone(){return new ro(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class no extends Pr{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new fr,this.environmentIntensity=1,this.environmentRotation=new fr,this.overrideMaterial=null,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),null!==t.background&&(this.background=t.background.clone()),null!==t.environment&&(this.environment=t.environment.clone()),null!==t.fog&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,this.backgroundRotation.copy(t.backgroundRotation),this.environmentIntensity=t.environmentIntensity,this.environmentRotation.copy(t.environmentRotation),null!==t.overrideMaterial&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return null!==this.fog&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),1!==this.backgroundIntensity&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),1!==this.environmentIntensity&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}class oo{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=Rs,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.version=0,this.uuid=qs()}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}get updateRange(){return ai("THREE.InterleavedBuffer: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead."),this._updateRange}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,s){t*=this.stride,s*=e.stride;for(let i=0,r=this.stride;it.far||e.push({distance:a,point:co.clone(),uv:jr.getInterpolation(co,xo,bo,vo,To,_o,wo,new Ks),face:null,object:this})}copy(t,e){return super.copy(t,e),void 0!==t.center&&this.center.copy(t.center),this.material=t.material,this}}function Mo(t,e,s,i,r,n){go.subVectors(t,s).addScalar(.5).multiply(i),void 0!==r?(fo.x=n*go.x-r*go.y,fo.y=r*go.x+n*go.y):fo.copy(go),t.copy(e),t.x+=fo.x,t.y+=fo.y,t.applyMatrix4(yo)}const Ao=new Ei,No=new Ei;class Ro extends Pr{constructor(){super(),this._currentLevel=0,this.type="LOD",Object.defineProperties(this,{levels:{enumerable:!0,value:[]},isLOD:{value:!0}}),this.autoUpdate=!0}copy(t){super.copy(t,!1);const e=t.levels;for(let t=0,s=e.length;t0){let s,i;for(s=1,i=e.length;s0){Ao.setFromMatrixPosition(this.matrixWorld);const s=t.ray.origin.distanceTo(Ao);this.getObjectForDistance(s).raycast(t,e)}}update(t){const e=this.levels;if(e.length>1){Ao.setFromMatrixPosition(t.matrixWorld),No.setFromMatrixPosition(this.matrixWorld);const s=Ao.distanceTo(No)/t.zoom;let i,r;for(e[0].object.visible=!0,i=1,r=e.length;i=t))break;e[i-1].object.visible=!1,e[i].object.visible=!0}for(this._currentLevel=i-1;i1?null:e.copy(t.start).addScaledVector(s,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),s=this.distanceToPoint(t.end);return e<0&&s>0||s<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const s=e||ea.getNormalMatrix(t),i=this.coplanarPoint(Ko).applyMatrix4(t),r=this.normal.applyMatrix3(s).normalize();return this.constant=-i.dot(r),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return(new this.constructor).copy(this)}}const ia=new Zi,ra=new Ei;class na{constructor(t=new sa,e=new sa,s=new sa,i=new sa,r=new sa,n=new sa){this.planes=[t,e,s,i,r,n]}set(t,e,s,i,r,n){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(s),o[3].copy(i),o[4].copy(r),o[5].copy(n),this}copy(t){const e=this.planes;for(let s=0;s<6;s++)e[s].copy(t.planes[s]);return this}setFromProjectionMatrix(t,e=2e3){const s=this.planes,i=t.elements,r=i[0],n=i[1],o=i[2],a=i[3],h=i[4],u=i[5],l=i[6],c=i[7],d=i[8],p=i[9],m=i[10],g=i[11],f=i[12],y=i[13],x=i[14],b=i[15];if(s[0].setComponents(a-r,c-h,g-d,b-f).normalize(),s[1].setComponents(a+r,c+h,g+d,b+f).normalize(),s[2].setComponents(a+n,c+u,g+p,b+y).normalize(),s[3].setComponents(a-n,c-u,g-p,b-y).normalize(),s[4].setComponents(a-o,c-l,g-m,b-x).normalize(),e===Vs)s[5].setComponents(a+o,c+l,g+m,b+x).normalize();else{if(e!==Ds)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);s[5].setComponents(o,l,m,x).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),ia.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),ia.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(ia)}intersectsSprite(t){return ia.center.set(0,0,0),ia.radius=.7071067811865476,ia.applyMatrix4(t.matrixWorld),this.intersectsSphere(ia)}intersectsSphere(t){const e=this.planes,s=t.center,i=-t.radius;for(let t=0;t<6;t++){if(e[t].distanceToPoint(s)0?t.max.x:t.min.x,ra.y=i.normal.y>0?t.max.y:t.min.y,ra.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(ra)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let s=0;s<6;s++)if(e[s].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function oa(t,e){return t.z-e.z}function aa(t,e){return e.z-t.z}class ha{constructor(){this.index=0,this.pool=[],this.list=[]}push(t,e,s){const i=this.pool,r=this.list;this.index>=i.length&&i.push({start:-1,count:-1,z:-1,index:-1});const n=i[this.index];r.push(n),this.index++,n.start=t.start,n.count=t.count,n.z=e,n.index=s}reset(){this.list.length=0,this.index=0}}const ua=new or,la=new or,ca=new or,da=new Yr(1,1,1),pa=new or,ma=new na,ga=new Pi,fa=new Zi,ya=new Ei,xa=new Ei,ba=new Ei,va=new ha,Ta=new Wn,_a=[];function wa(t,e,s=0){const i=e.itemSize;if(t.isInterleavedBufferAttribute||t.array.constructor!==e.array.constructor){const r=t.count;for(let n=0;n65535?new Uint32Array(i):new Uint16Array(i);e.setIndex(new hn(t,1))}this._geometryInitialized=!0}}_validateGeometry(t){const e=this.geometry;if(Boolean(t.getIndex())!==Boolean(e.getIndex()))throw new Error('BatchedMesh: All geometries must consistently have "index".');for(const s in e.attributes){if(!t.hasAttribute(s))throw new Error(`BatchedMesh: Added geometry missing "${s}". All geometries must have consistent attributes.`);const i=t.getAttribute(s),r=e.getAttribute(s);if(i.itemSize!==r.itemSize||i.normalized!==r.normalized)throw new Error("BatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}setCustomSort(t){return this.customSort=t,this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Pi);const t=this._geometryCount,e=this.boundingBox,s=this._drawInfo;e.makeEmpty();for(let i=0;i=this._maxInstanceCount)throw new Error("BatchedMesh: Maximum item count reached.");this._drawInfo.push({visible:!0,active:!0,geometryIndex:t});const e=this._drawInfo.length-1,s=this._matricesTexture,i=s.image.data;ca.toArray(i,16*e),s.needsUpdate=!0;const r=this._colorsTexture;return r&&(da.toArray(r.image.data,4*e),r.needsUpdate=!0),e}addGeometry(t,e=-1,s=-1){if(this._initializeGeometry(t),this._validateGeometry(t),this._drawInfo.length>=this._maxInstanceCount)throw new Error("BatchedMesh: Maximum item count reached.");const i={vertexStart:-1,vertexCount:-1,indexStart:-1,indexCount:-1};let r=null;const n=this._reservedRanges,o=this._drawRanges,a=this._bounds;0!==this._geometryCount&&(r=n[n.length-1]),i.vertexCount=-1===e?t.getAttribute("position").count:e,i.vertexStart=null===r?0:r.vertexStart+r.vertexCount;const h=t.getIndex(),u=null!==h;if(u&&(i.indexCount=-1===s?h.count:s,i.indexStart=null===r?0:r.indexStart+r.indexCount),-1!==i.indexStart&&i.indexStart+i.indexCount>this._maxIndexCount||i.vertexStart+i.vertexCount>this._maxVertexCount)throw new Error("BatchedMesh: Reserved space request exceeds the maximum buffer size.");const l=this._geometryCount;return this._geometryCount++,n.push(i),o.push({start:u?i.indexStart:i.vertexStart,count:-1}),a.push({boxInitialized:!1,box:new Pi,sphereInitialized:!1,sphere:new Zi}),this.setGeometryAt(l,t),l}setGeometryAt(t,e){if(t>=this._geometryCount)throw new Error("BatchedMesh: Maximum geometry count reached.");this._validateGeometry(e);const s=this.geometry,i=null!==s.getIndex(),r=s.getIndex(),n=e.getIndex(),o=this._reservedRanges[t];if(i&&n.count>o.indexCount||e.attributes.position.count>o.vertexCount)throw new Error("BatchedMesh: Reserved space not large enough for provided geometry.");const a=o.vertexStart,h=o.vertexCount;for(const t in s.attributes){const i=e.getAttribute(t),r=s.getAttribute(t);wa(i,r,a);const n=i.itemSize;for(let t=i.count,e=h;t=this._geometryCount)return null;const s=this._bounds[t],i=s.box,r=this.geometry;if(!1===s.boxInitialized){i.makeEmpty();const e=r.index,n=r.attributes.position,o=this._drawRanges[t];for(let t=o.start,s=o.start+o.count;t=this._geometryCount)return null;const s=this._bounds[t],i=s.sphere,r=this.geometry;if(!1===s.sphereInitialized){i.makeEmpty(),this.getBoundingBoxAt(t,ga),ga.getCenter(i.center);const e=r.index,n=r.attributes.position,o=this._drawRanges[t];let a=0;for(let t=o.start,s=o.start+o.count;t=s.length||!1===s[t].active||(e.toArray(r,16*t),i.needsUpdate=!0),this}getMatrixAt(t,e){const s=this._drawInfo,i=this._matricesTexture.image.data;return t>=s.length||!1===s[t].active?null:e.fromArray(i,16*t)}setColorAt(t,e){null===this._colorsTexture&&this._initColorsTexture();const s=this._colorsTexture,i=this._colorsTexture.image.data,r=this._drawInfo;return t>=r.length||!1===r[t].active||(e.toArray(i,4*t),s.needsUpdate=!0),this}getColorAt(t,e){const s=this._colorsTexture.image.data,i=this._drawInfo;return t>=i.length||!1===i[t].active?null:e.fromArray(s,4*t)}setVisibleAt(t,e){const s=this._drawInfo;return t>=s.length||!1===s[t].active||s[t].visible===e||(s[t].visible=e,this._visibilityChanged=!0),this}getVisibleAt(t){const e=this._drawInfo;return!(t>=e.length||!1===e[t].active)&&e[t].visible}raycast(t,e){const s=this._drawInfo,i=this._drawRanges,r=this.matrixWorld,n=this.geometry;Ta.material=this.material,Ta.geometry.index=n.index,Ta.geometry.attributes=n.attributes,null===Ta.geometry.boundingBox&&(Ta.geometry.boundingBox=new Pi),null===Ta.geometry.boundingSphere&&(Ta.geometry.boundingSphere=new Zi);for(let n=0,o=s.length;n({...t}))),this._reservedRanges=t._reservedRanges.map((t=>({...t}))),this._drawInfo=t._drawInfo.map((t=>({...t}))),this._bounds=t._bounds.map((t=>({boxInitialized:t.boxInitialized,box:t.box.clone(),sphereInitialized:t.sphereInitialized,sphere:t.sphere.clone()}))),this._maxInstanceCount=t._maxInstanceCount,this._maxVertexCount=t._maxVertexCount,this._maxIndexCount=t._maxIndexCount,this._geometryInitialized=t._geometryInitialized,this._geometryCount=t._geometryCount,this._multiDrawCounts=t._multiDrawCounts.slice(),this._multiDrawStarts=t._multiDrawStarts.slice(),this._matricesTexture=t._matricesTexture.clone(),this._matricesTexture.image.data=this._matricesTexture.image.data.slice(),null!==this._colorsTexture&&(this._colorsTexture=t._colorsTexture.clone(),this._colorsTexture.image.data=this._colorsTexture.image.data.slice()),this}dispose(){return this.geometry.dispose(),this._matricesTexture.dispose(),this._matricesTexture=null,this._indirectTexture.dispose(),this._indirectTexture=null,null!==this._colorsTexture&&(this._colorsTexture.dispose(),this._colorsTexture=null),this}onBeforeRender(t,e,s,i,r){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;const n=i.getIndex(),o=null===n?1:n.array.BYTES_PER_ELEMENT,a=this._drawInfo,h=this._multiDrawStarts,u=this._multiDrawCounts,l=this._drawRanges,c=this.perObjectFrustumCulled,d=this._indirectTexture,p=d.image.data;c&&(pa.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse).multiply(this.matrixWorld),ma.setFromProjectionMatrix(pa,t.coordinateSystem));let m=0;if(this.sortObjects){la.copy(this.matrixWorld).invert(),ya.setFromMatrixPosition(s.matrixWorld).applyMatrix4(la),xa.set(0,0,-1).transformDirection(s.matrixWorld).transformDirection(la);for(let t=0,e=a.length;t0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;ti)return;Ba.applyMatrix4(t.matrixWorld);const a=e.ray.origin.distanceTo(Ba);return ae.far?void 0:{distance:a,point:Ia.clone().applyMatrix4(t.matrixWorld),index:r,face:null,faceIndex:null,object:t}}const Ua=new Ei,Oa=new Ei;class La extends Pa{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(null===t.index){const e=t.attributes.position,s=[];for(let t=0,i=e.count;t0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;tr.far)return;n.push({distance:h,distanceToRay:Math.sqrt(a),point:s,index:e,face:null,object:o})}}class qa extends Pr{constructor(){super(),this.isGroup=!0,this.type="Group"}}class $a extends Ti{constructor(t,e,s,i,r,n,o,a,h){super(t,e,s,i,r,n,o,a,h),this.isVideoTexture=!0,this.minFilter=void 0!==n?n:Tt,this.magFilter=void 0!==r?r:Tt,this.generateMipmaps=!1;const u=this;"requestVideoFrameCallback"in t&&t.requestVideoFrameCallback((function e(){u.needsUpdate=!0,t.requestVideoFrameCallback(e)}))}clone(){return new this.constructor(this.image).copy(this)}update(){const t=this.image;!1==="requestVideoFrameCallback"in t&&t.readyState>=t.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}}class Xa extends Ti{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=ft,this.minFilter=ft,this.generateMipmaps=!1,this.needsUpdate=!0}}class Ya extends Ti{constructor(t,e,s,i,r,n,o,a,h,u,l,c){super(null,n,o,a,h,u,i,r,l,c),this.isCompressedTexture=!0,this.image={width:e,height:s},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}}class Ja extends Ya{constructor(t,e,s,i,r,n){super(t,e,s,r,n),this.isCompressedArrayTexture=!0,this.image.depth=i,this.wrapR=mt,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class Za extends Ya{constructor(t,e,s){super(void 0,t[0].width,t[0].height,e,s,ht),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=t}}class Qa extends Ti{constructor(t,e,s,i,r,n,o,a,h){super(t,e,s,i,r,n,o,a,h),this.isCanvasTexture=!0,this.needsUpdate=!0}}class Ka extends Ti{constructor(t,e,s,i,r,n,o,a,h,u=1026){if(u!==Wt&&u!==jt)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===s&&u===Wt&&(s=Bt),void 0===s&&u===jt&&(s=Ot),super(null,i,r,n,o,a,u,s,h),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=void 0!==o?o:ft,this.minFilter=void 0!==a?a:ft,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return null!==this.compareFunction&&(e.compareFunction=this.compareFunction),e}}class th{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(t,e){const s=this.getUtoTmapping(t);return this.getPoint(s,e)}getPoints(t=5){const e=[];for(let s=0;s<=t;s++)e.push(this.getPoint(s/t));return e}getSpacedPoints(t=5){const e=[];for(let s=0;s<=t;s++)e.push(this.getPointAt(s/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const e=[];let s,i=this.getPoint(0),r=0;e.push(0);for(let n=1;n<=t;n++)s=this.getPoint(n/t),r+=s.distanceTo(i),e.push(r),i=s;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const s=this.getLengths();let i=0;const r=s.length;let n;n=e||t*s[r-1];let o,a=0,h=r-1;for(;a<=h;)if(i=Math.floor(a+(h-a)/2),o=s[i]-n,o<0)a=i+1;else{if(!(o>0)){h=i;break}h=i-1}if(i=h,s[i]===n)return i/(r-1);const u=s[i];return(i+(n-u)/(s[i+1]-u))/(r-1)}getTangent(t,e){const s=1e-4;let i=t-s,r=t+s;i<0&&(i=0),r>1&&(r=1);const n=this.getPoint(i),o=this.getPoint(r),a=e||(n.isVector2?new Ks:new Ei);return a.copy(o).sub(n).normalize(),a}getTangentAt(t,e){const s=this.getUtoTmapping(t);return this.getTangent(s,e)}computeFrenetFrames(t,e){const s=new Ei,i=[],r=[],n=[],o=new Ei,a=new or;for(let e=0;e<=t;e++){const s=e/t;i[e]=this.getTangentAt(s,new Ei)}r[0]=new Ei,n[0]=new Ei;let h=Number.MAX_VALUE;const u=Math.abs(i[0].x),l=Math.abs(i[0].y),c=Math.abs(i[0].z);u<=h&&(h=u,s.set(1,0,0)),l<=h&&(h=l,s.set(0,1,0)),c<=h&&s.set(0,0,1),o.crossVectors(i[0],s).normalize(),r[0].crossVectors(i[0],o),n[0].crossVectors(i[0],r[0]);for(let e=1;e<=t;e++){if(r[e]=r[e-1].clone(),n[e]=n[e-1].clone(),o.crossVectors(i[e-1],i[e]),o.length()>Number.EPSILON){o.normalize();const t=Math.acos($s(i[e-1].dot(i[e]),-1,1));r[e].applyMatrix4(a.makeRotationAxis(o,t))}n[e].crossVectors(i[e],r[e])}if(!0===e){let e=Math.acos($s(r[0].dot(r[t]),-1,1));e/=t,i[0].dot(o.crossVectors(r[0],r[t]))>0&&(e=-e);for(let s=1;s<=t;s++)r[s].applyMatrix4(a.makeRotationAxis(i[s],e*s)),n[s].crossVectors(i[s],r[s])}return{tangents:i,normals:r,binormals:n}}clone(){return(new this.constructor).copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){const t={metadata:{version:4.6,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}class eh extends th{constructor(t=0,e=0,s=1,i=1,r=0,n=2*Math.PI,o=!1,a=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=s,this.yRadius=i,this.aStartAngle=r,this.aEndAngle=n,this.aClockwise=o,this.aRotation=a}getPoint(t,e=new Ks){const s=e,i=2*Math.PI;let r=this.aEndAngle-this.aStartAngle;const n=Math.abs(r)i;)r-=i;r0?0:(Math.floor(Math.abs(h)/r)+1)*r:0===u&&h===r-1&&(h=r-2,u=1),this.closed||h>0?o=i[(h-1)%r]:(rh.subVectors(i[0],i[1]).add(i[0]),o=rh);const l=i[h%r],c=i[(h+1)%r];if(this.closed||h+2i.length-2?i.length-1:n+1],l=i[n>i.length-3?i.length-1:n+2];return s.set(uh(o,a.x,h.x,u.x,l.x),uh(o,a.y,h.y,u.y,l.y)),s}copy(t){super.copy(t),this.points=[];for(let e=0,s=t.points.length;e=s){const t=i[r]-s,n=this.curves[r],o=n.getLength(),a=0===o?0:1-t/o;return n.getPointAt(a,e)}r++}return null}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const t=[];let e=0;for(let s=0,i=this.curves.length;s1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,s=t.curves.length;e0){const t=h.getPoint(0);t.equals(this.currentPoint)||this.lineTo(t.x,t.y)}this.curves.push(h);const u=h.getPoint(1);return this.currentPoint.copy(u),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){const t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}}class _h extends Mn{constructor(t=[new Ks(0,-.5),new Ks(.5,0),new Ks(0,.5)],e=12,s=0,i=2*Math.PI){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:s,phiLength:i},e=Math.floor(e),i=$s(i,0,2*Math.PI);const r=[],n=[],o=[],a=[],h=[],u=1/e,l=new Ei,c=new Ks,d=new Ei,p=new Ei,m=new Ei;let g=0,f=0;for(let e=0;e<=t.length-1;e++)switch(e){case 0:g=t[e+1].x-t[e].x,f=t[e+1].y-t[e].y,d.x=1*f,d.y=-g,d.z=0*f,m.copy(d),d.normalize(),a.push(d.x,d.y,d.z);break;case t.length-1:a.push(m.x,m.y,m.z);break;default:g=t[e+1].x-t[e].x,f=t[e+1].y-t[e].y,d.x=1*f,d.y=-g,d.z=0*f,p.copy(d),d.x+=m.x,d.y+=m.y,d.z+=m.z,d.normalize(),a.push(d.x,d.y,d.z),m.copy(p)}for(let r=0;r<=e;r++){const d=s+r*u*i,p=Math.sin(d),m=Math.cos(d);for(let s=0;s<=t.length-1;s++){l.x=t[s].x*p,l.y=t[s].y,l.z=t[s].x*m,n.push(l.x,l.y,l.z),c.x=r/e,c.y=s/(t.length-1),o.push(c.x,c.y);const i=a[3*s+0]*p,u=a[3*s+1],d=a[3*s+0]*m;h.push(i,u,d)}}for(let s=0;s0&&y(!0),e>0&&y(!1)),this.setIndex(u),this.setAttribute("position",new yn(l,3)),this.setAttribute("normal",new yn(c,3)),this.setAttribute("uv",new yn(d,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Mh(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class Ah extends Mh{constructor(t=1,e=1,s=32,i=1,r=!1,n=0,o=2*Math.PI){super(0,t,e,s,i,r,n,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:s,heightSegments:i,openEnded:r,thetaStart:n,thetaLength:o}}static fromJSON(t){return new Ah(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class Nh extends Mn{constructor(t=[],e=[],s=1,i=0){super(),this.type="PolyhedronGeometry",this.parameters={vertices:t,indices:e,radius:s,detail:i};const r=[],n=[];function o(t,e,s,i){const r=i+1,n=[];for(let i=0;i<=r;i++){n[i]=[];const o=t.clone().lerp(s,i/r),a=e.clone().lerp(s,i/r),h=r-i;for(let t=0;t<=h;t++)n[i][t]=0===t&&i===r?o:o.clone().lerp(a,t/h)}for(let t=0;t.9&&o<.1&&(e<.2&&(n[t+0]+=1),s<.2&&(n[t+2]+=1),i<.2&&(n[t+4]+=1))}}()}(),this.setAttribute("position",new yn(r,3)),this.setAttribute("normal",new yn(r.slice(),3)),this.setAttribute("uv",new yn(n,2)),0===i?this.computeVertexNormals():this.normalizeNormals()}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Nh(t.vertices,t.indices,t.radius,t.details)}}class Rh extends Nh{constructor(t=1,e=0){const s=(1+Math.sqrt(5))/2,i=1/s;super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-i,-s,0,-i,s,0,i,-s,0,i,s,-i,-s,0,-i,s,0,i,-s,0,i,s,0,-s,0,-i,s,0,-i,-s,0,i,s,0,i],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],t,e),this.type="DodecahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new Rh(t.radius,t.detail)}}const Ch=new Ei,Eh=new Ei,Bh=new Ei,Ih=new jr;class Ph extends Mn{constructor(t=null,e=1){if(super(),this.type="EdgesGeometry",this.parameters={geometry:t,thresholdAngle:e},null!==t){const s=4,i=Math.pow(10,s),r=Math.cos(js*e),n=t.getIndex(),o=t.getAttribute("position"),a=n?n.count:o.count,h=[0,0,0],u=["a","b","c"],l=new Array(3),c={},d=[];for(let t=0;t80*s){a=u=t[0],h=l=t[1];for(let e=s;eu&&(u=c),d>l&&(l=d);p=Math.max(u-a,l-h),p=0!==p?32767/p:0}return zh(n,o,s,a,h,p,0),o};function Oh(t,e,s,i,r){let n,o;if(r===function(t,e,s,i){let r=0;for(let n=e,o=s-i;n0)for(n=e;n=e;n-=i)o=iu(n,t[n],t[n+1],o);return o&&Zh(o,o.next)&&(ru(o),o=o.next),o}function Lh(t,e){if(!t)return t;e||(e=t);let s,i=t;do{if(s=!1,i.steiner||!Zh(i,i.next)&&0!==Jh(i.prev,i,i.next))i=i.next;else{if(ru(i),i=e=i.prev,i===i.next)break;s=!0}}while(s||i!==e);return e}function zh(t,e,s,i,r,n,o){if(!t)return;!o&&n&&function(t,e,s,i){let r=t;do{0===r.z&&(r.z=qh(r.x,r.y,e,s,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){let e,s,i,r,n,o,a,h,u=1;do{for(s=t,t=null,n=null,o=0;s;){for(o++,i=s,a=0,e=0;e0||h>0&&i;)0!==a&&(0===h||!i||s.z<=i.z)?(r=s,s=s.nextZ,a--):(r=i,i=i.nextZ,h--),n?n.nextZ=r:t=r,r.prevZ=n,n=r;s=i}n.nextZ=null,u*=2}while(o>1)}(r)}(t,i,r,n);let a,h,u=t;for(;t.prev!==t.next;)if(a=t.prev,h=t.next,n?Dh(t,i,r,n):Vh(t))e.push(a.i/s|0),e.push(t.i/s|0),e.push(h.i/s|0),ru(t),t=h.next,u=h.next;else if((t=h)===u){o?1===o?zh(t=kh(Lh(t),e,s),e,s,i,r,n,2):2===o&&Gh(t,e,s,i,r,n):zh(Lh(t),e,s,i,r,n,1);break}}function Vh(t){const e=t.prev,s=t,i=t.next;if(Jh(e,s,i)>=0)return!1;const r=e.x,n=s.x,o=i.x,a=e.y,h=s.y,u=i.y,l=rn?r>o?r:o:n>o?n:o,p=a>h?a>u?a:u:h>u?h:u;let m=i.next;for(;m!==e;){if(m.x>=l&&m.x<=d&&m.y>=c&&m.y<=p&&Xh(r,a,n,h,o,u,m.x,m.y)&&Jh(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function Dh(t,e,s,i){const r=t.prev,n=t,o=t.next;if(Jh(r,n,o)>=0)return!1;const a=r.x,h=n.x,u=o.x,l=r.y,c=n.y,d=o.y,p=ah?a>u?a:u:h>u?h:u,f=l>c?l>d?l:d:c>d?c:d,y=qh(p,m,e,s,i),x=qh(g,f,e,s,i);let b=t.prevZ,v=t.nextZ;for(;b&&b.z>=y&&v&&v.z<=x;){if(b.x>=p&&b.x<=g&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&Xh(a,l,h,c,u,d,b.x,b.y)&&Jh(b.prev,b,b.next)>=0)return!1;if(b=b.prevZ,v.x>=p&&v.x<=g&&v.y>=m&&v.y<=f&&v!==r&&v!==o&&Xh(a,l,h,c,u,d,v.x,v.y)&&Jh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}for(;b&&b.z>=y;){if(b.x>=p&&b.x<=g&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&Xh(a,l,h,c,u,d,b.x,b.y)&&Jh(b.prev,b,b.next)>=0)return!1;b=b.prevZ}for(;v&&v.z<=x;){if(v.x>=p&&v.x<=g&&v.y>=m&&v.y<=f&&v!==r&&v!==o&&Xh(a,l,h,c,u,d,v.x,v.y)&&Jh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function kh(t,e,s){let i=t;do{const r=i.prev,n=i.next.next;!Zh(r,n)&&Qh(r,i,i.next,n)&&eu(r,n)&&eu(n,r)&&(e.push(r.i/s|0),e.push(i.i/s|0),e.push(n.i/s|0),ru(i),ru(i.next),i=t=n),i=i.next}while(i!==t);return Lh(i)}function Gh(t,e,s,i,r,n){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Yh(o,t)){let a=su(o,t);return o=Lh(o,o.next),a=Lh(a,a.next),zh(o,e,s,i,r,n,0),void zh(a,e,s,i,r,n,0)}t=t.next}o=o.next}while(o!==t)}function Wh(t,e){return t.x-e.x}function jh(t,e){const s=function(t,e){let s,i=e,r=-1/0;const n=t.x,o=t.y;do{if(o<=i.y&&o>=i.next.y&&i.next.y!==i.y){const t=i.x+(o-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(t<=n&&t>r&&(r=t,s=i.x=i.x&&i.x>=h&&n!==i.x&&Xh(os.x||i.x===s.x&&Hh(s,i)))&&(s=i,c=l)),i=i.next}while(i!==a);return s}(t,e);if(!s)return e;const i=su(s,t);return Lh(i,i.next),Lh(s,s.next)}function Hh(t,e){return Jh(t.prev,t,e.prev)<0&&Jh(e.next,t,t.next)<0}function qh(t,e,s,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-s)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function $h(t){let e=t,s=t;do{(e.x=(t-o)*(n-a)&&(t-o)*(i-a)>=(s-o)*(e-a)&&(s-o)*(n-a)>=(r-o)*(i-a)}function Yh(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let s=t;do{if(s.i!==t.i&&s.next.i!==t.i&&s.i!==e.i&&s.next.i!==e.i&&Qh(s,s.next,t,e))return!0;s=s.next}while(s!==t);return!1}(t,e)&&(eu(t,e)&&eu(e,t)&&function(t,e){let s=t,i=!1;const r=(t.x+e.x)/2,n=(t.y+e.y)/2;do{s.y>n!=s.next.y>n&&s.next.y!==s.y&&r<(s.next.x-s.x)*(n-s.y)/(s.next.y-s.y)+s.x&&(i=!i),s=s.next}while(s!==t);return i}(t,e)&&(Jh(t.prev,t,e.prev)||Jh(t,e.prev,e))||Zh(t,e)&&Jh(t.prev,t,t.next)>0&&Jh(e.prev,e,e.next)>0)}function Jh(t,e,s){return(e.y-t.y)*(s.x-e.x)-(e.x-t.x)*(s.y-e.y)}function Zh(t,e){return t.x===e.x&&t.y===e.y}function Qh(t,e,s,i){const r=tu(Jh(t,e,s)),n=tu(Jh(t,e,i)),o=tu(Jh(s,i,t)),a=tu(Jh(s,i,e));return r!==n&&o!==a||(!(0!==r||!Kh(t,s,e))||(!(0!==n||!Kh(t,i,e))||(!(0!==o||!Kh(s,t,i))||!(0!==a||!Kh(s,e,i)))))}function Kh(t,e,s){return e.x<=Math.max(t.x,s.x)&&e.x>=Math.min(t.x,s.x)&&e.y<=Math.max(t.y,s.y)&&e.y>=Math.min(t.y,s.y)}function tu(t){return t>0?1:t<0?-1:0}function eu(t,e){return Jh(t.prev,t,t.next)<0?Jh(t,e,t.next)>=0&&Jh(t,t.prev,e)>=0:Jh(t,e,t.prev)<0||Jh(t,t.next,e)<0}function su(t,e){const s=new nu(t.i,t.x,t.y),i=new nu(e.i,e.x,e.y),r=t.next,n=e.prev;return t.next=e,e.prev=t,s.next=r,r.prev=s,i.next=s,s.prev=i,n.next=i,i.prev=n,i}function iu(t,e,s,i){const r=new nu(t,e,s);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function ru(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function nu(t,e,s){this.i=t,this.x=e,this.y=s,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}class ou{static area(t){const e=t.length;let s=0;for(let i=e-1,r=0;r2&&t[e-1].equals(t[0])&&t.pop()}function hu(t,e){for(let s=0;sNumber.EPSILON){const c=Math.sqrt(l),d=Math.sqrt(h*h+u*u),p=e.x-a/c,m=e.y+o/c,g=((s.x-u/d-p)*u-(s.y+h/d-m)*h)/(o*u-a*h);i=p+o*g-t.x,r=m+a*g-t.y;const f=i*i+r*r;if(f<=2)return new Ks(i,r);n=Math.sqrt(f/2)}else{let t=!1;o>Number.EPSILON?h>Number.EPSILON&&(t=!0):o<-Number.EPSILON?h<-Number.EPSILON&&(t=!0):Math.sign(a)===Math.sign(u)&&(t=!0),t?(i=-a,r=o,n=Math.sqrt(l)):(i=o,r=a,n=Math.sqrt(l/2))}return new Ks(i/n,r/n)}const B=[];for(let t=0,e=A.length,s=e-1,i=t+1;t=0;t--){const e=t/p,s=l*Math.cos(e*Math.PI/2),i=c*Math.sin(e*Math.PI/2)+d;for(let t=0,e=A.length;t=0;){const i=s;let r=s-1;r<0&&(r=t.length-1);for(let t=0,s=a+2*p;t0)&&d.push(e,r,h),(t!==s-1||a0!=t>0&&this.version++,this._anisotropy=t}get clearcoat(){return this._clearcoat}set clearcoat(t){this._clearcoat>0!=t>0&&this.version++,this._clearcoat=t}get iridescence(){return this._iridescence}set iridescence(t){this._iridescence>0!=t>0&&this.version++,this._iridescence=t}get dispersion(){return this._dispersion}set dispersion(t){this._dispersion>0!=t>0&&this.version++,this._dispersion=t}get sheen(){return this._sheen}set sheen(t){this._sheen>0!=t>0&&this.version++,this._sheen=t}get transmission(){return this._transmission}set transmission(t){this._transmission>0!=t>0&&this.version++,this._transmission=t}copy(t){return super.copy(t),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=t.anisotropy,this.anisotropyRotation=t.anisotropyRotation,this.anisotropyMap=t.anisotropyMap,this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.dispersion=t.dispersion,this.ior=t.ior,this.iridescence=t.iridescence,this.iridescenceMap=t.iridescenceMap,this.iridescenceIOR=t.iridescenceIOR,this.iridescenceThicknessRange=[...t.iridescenceThicknessRange],this.iridescenceThicknessMap=t.iridescenceThicknessMap,this.sheen=t.sheen,this.sheenColor.copy(t.sheenColor),this.sheenColorMap=t.sheenColorMap,this.sheenRoughness=t.sheenRoughness,this.sheenRoughnessMap=t.sheenRoughnessMap,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this.thickness=t.thickness,this.thicknessMap=t.thicknessMap,this.attenuationDistance=t.attenuationDistance,this.attenuationColor.copy(t.attenuationColor),this.specularIntensity=t.specularIntensity,this.specularIntensityMap=t.specularIntensityMap,this.specularColor.copy(t.specularColor),this.specularColorMap=t.specularColorMap,this}}class Ru extends Qr{constructor(t){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new Yr(16777215),this.specular=new Yr(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Yr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fr,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.specular.copy(t.specular),this.shininess=t.shininess,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Cu extends Qr{constructor(t){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new Yr(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Yr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.gradientMap=t.gradientMap,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}class Eu extends Qr{constructor(t){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.flatShading=t.flatShading,this}}class Bu extends Qr{constructor(t){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new Yr(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Yr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fr,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Iu extends Qr{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=3200,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class Pu extends Qr{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}class Fu extends Qr{constructor(t){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new Yr(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={MATCAP:""},this.color.copy(t.color),this.matcap=t.matcap,this.map=t.map,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Uu extends Ma{constructor(t){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(t)}copy(t){return super.copy(t),this.scale=t.scale,this.dashSize=t.dashSize,this.gapSize=t.gapSize,this}}function Ou(t,e,s){return!t||!s&&t.constructor===e?t:"number"==typeof e.BYTES_PER_ELEMENT?new e(t):Array.prototype.slice.call(t)}function Lu(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function zu(t){const e=t.length,s=new Array(e);for(let t=0;t!==e;++t)s[t]=t;return s.sort((function(e,s){return t[e]-t[s]})),s}function Vu(t,e,s){const i=t.length,r=new t.constructor(i);for(let n=0,o=0;o!==i;++n){const i=s[n]*e;for(let s=0;s!==e;++s)r[o++]=t[i+s]}return r}function Du(t,e,s,i){let r=1,n=t[0];for(;void 0!==n&&void 0===n[i];)n=t[r++];if(void 0===n)return;let o=n[i];if(void 0!==o)if(Array.isArray(o))do{o=n[i],void 0!==o&&(e.push(n.time),s.push.apply(s,o)),n=t[r++]}while(void 0!==n);else if(void 0!==o.toArray)do{o=n[i],void 0!==o&&(e.push(n.time),o.toArray(s,s.length)),n=t[r++]}while(void 0!==n);else do{o=n[i],void 0!==o&&(e.push(n.time),s.push(o)),n=t[r++]}while(void 0!==n)}const ku={convertArray:Ou,isTypedArray:Lu,getKeyframeOrder:zu,sortedArray:Vu,flattenJSON:Du,subclip:function(t,e,s,i,r=30){const n=t.clone();n.name=e;const o=[];for(let t=0;t=i)){h.push(e.times[t]);for(let s=0;sn.tracks[t].times[0]&&(a=n.tracks[t].times[0]);for(let t=0;t=i.times[c]){const t=c*h+a,e=t+h-a;d=i.values.slice(t,e)}else{const t=i.createInterpolant(),e=a,s=h-a;t.evaluate(n),d=t.resultBuffer.slice(e,s)}if("quaternion"===r){(new Ci).fromArray(d).normalize().conjugate().toArray(d)}const p=o.times.length;for(let t=0;t=r)break t;{const o=e[1];t=r)break e}n=s,s=0}}for(;s>>1;te;)--n;if(++n,0!==r||n!==i){r>=n&&(n=Math.max(n,1),r=n-1);const t=this.getValueSize();this.times=s.slice(r,n),this.values=this.values.slice(r*t,n*t)}return this}validate(){let t=!0;const e=this.getValueSize();e-Math.floor(e)!=0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),t=!1);const s=this.times,i=this.values,r=s.length;0===r&&(console.error("THREE.KeyframeTrack: Track is empty.",this),t=!1);let n=null;for(let e=0;e!==r;e++){const i=s[e];if("number"==typeof i&&isNaN(i)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,e,i),t=!1;break}if(null!==n&&n>i){console.error("THREE.KeyframeTrack: Out of order keys.",this,e,i,n),t=!1;break}n=i}if(void 0!==i&&Lu(i))for(let e=0,s=i.length;e!==s;++e){const s=i[e];if(isNaN(s)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,e,s),t=!1;break}}return t}optimize(){const t=this.times.slice(),e=this.values.slice(),s=this.getValueSize(),i=this.getInterpolation()===Fe,r=t.length-1;let n=1;for(let o=1;o0){t[n]=t[r];for(let t=r*s,i=n*s,o=0;o!==s;++o)e[i+o]=e[t+o];++n}return n!==t.length?(this.times=t.slice(0,n),this.values=e.slice(0,n*s)):(this.times=t,this.values=e),this}clone(){const t=this.times.slice(),e=this.values.slice(),s=new(0,this.constructor)(this.name,t,e);return s.createInterpolant=this.createInterpolant,s}}qu.prototype.TimeBufferType=Float32Array,qu.prototype.ValueBufferType=Float32Array,qu.prototype.DefaultInterpolation=Pe;class $u extends qu{constructor(t,e,s){super(t,e,s)}}$u.prototype.ValueTypeName="bool",$u.prototype.ValueBufferType=Array,$u.prototype.DefaultInterpolation=Ie,$u.prototype.InterpolantFactoryMethodLinear=void 0,$u.prototype.InterpolantFactoryMethodSmooth=void 0;class Xu extends qu{}Xu.prototype.ValueTypeName="color";class Yu extends qu{}Yu.prototype.ValueTypeName="number";class Ju extends Gu{constructor(t,e,s,i){super(t,e,s,i)}interpolate_(t,e,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=(s-e)/(i-e);let h=t*o;for(let t=h+o;h!==t;h+=4)Ci.slerpFlat(r,0,n,h-o,n,h,a);return r}}class Zu extends qu{InterpolantFactoryMethodLinear(t){return new Ju(this.times,this.values,this.getValueSize(),t)}}Zu.prototype.ValueTypeName="quaternion",Zu.prototype.InterpolantFactoryMethodSmooth=void 0;class Qu extends qu{constructor(t,e,s){super(t,e,s)}}Qu.prototype.ValueTypeName="string",Qu.prototype.ValueBufferType=Array,Qu.prototype.DefaultInterpolation=Ie,Qu.prototype.InterpolantFactoryMethodLinear=void 0,Qu.prototype.InterpolantFactoryMethodSmooth=void 0;class Ku extends qu{}Ku.prototype.ValueTypeName="vector";class tl{constructor(t="",e=-1,s=[],i=2500){this.name=t,this.tracks=s,this.duration=e,this.blendMode=i,this.uuid=qs(),this.duration<0&&this.resetDuration()}static parse(t){const e=[],s=t.tracks,i=1/(t.fps||1);for(let t=0,r=s.length;t!==r;++t)e.push(el(s[t]).scale(i));const r=new this(t.name,t.duration,e,t.blendMode);return r.uuid=t.uuid,r}static toJSON(t){const e=[],s=t.tracks,i={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode};for(let t=0,i=s.length;t!==i;++t)e.push(qu.toJSON(s[t]));return i}static CreateFromMorphTargetSequence(t,e,s,i){const r=e.length,n=[];for(let t=0;t1){const t=n[1];let e=i[t];e||(i[t]=e=[]),e.push(s)}}const n=[];for(const t in i)n.push(this.CreateFromMorphTargetSequence(t,i[t],e,s));return n}static parseAnimation(t,e){if(!t)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;const s=function(t,e,s,i,r){if(0!==s.length){const n=[],o=[];Du(s,n,o,i),0!==n.length&&r.push(new t(e,n,o))}},i=[],r=t.name||"default",n=t.fps||30,o=t.blendMode;let a=t.length||-1;const h=t.hierarchy||[];for(let t=0;t{e&&e(r),this.manager.itemEnd(t)}),0),r;if(void 0!==ol[t])return void ol[t].push({onLoad:e,onProgress:s,onError:i});ol[t]=[],ol[t].push({onLoad:e,onProgress:s,onError:i});const n=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),o=this.mimeType,a=this.responseType;fetch(n).then((e=>{if(200===e.status||0===e.status){if(0===e.status&&console.warn("THREE.FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===e.body||void 0===e.body.getReader)return e;const s=ol[t],i=e.body.getReader(),r=e.headers.get("X-File-Size")||e.headers.get("Content-Length"),n=r?parseInt(r):0,o=0!==n;let a=0;const h=new ReadableStream({start(t){!function e(){i.read().then((({done:i,value:r})=>{if(i)t.close();else{a+=r.byteLength;const i=new ProgressEvent("progress",{lengthComputable:o,loaded:a,total:n});for(let t=0,e=s.length;t{t.error(e)}))}()}});return new Response(h)}throw new al(`fetch for "${e.url}" responded with ${e.status}: ${e.statusText}`,e)})).then((t=>{switch(a){case"arraybuffer":return t.arrayBuffer();case"blob":return t.blob();case"document":return t.text().then((t=>(new DOMParser).parseFromString(t,o)));case"json":return t.json();default:if(void 0===o)return t.text();{const e=/charset="?([^;"\s]*)"?/i.exec(o),s=e&&e[1]?e[1].toLowerCase():void 0,i=new TextDecoder(s);return t.arrayBuffer().then((t=>i.decode(t)))}}})).then((e=>{sl.add(t,e);const s=ol[t];delete ol[t];for(let t=0,i=s.length;t{const s=ol[t];if(void 0===s)throw this.manager.itemError(t),e;delete ol[t];for(let t=0,i=s.length;t{this.manager.itemEnd(t)})),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}}class ul extends nl{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new hl(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(s){try{e(r.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),r.manager.itemError(t)}}),s,i)}parse(t){const e=[];for(let s=0;s0:i.vertexColors=t.vertexColors),void 0!==t.uniforms)for(const e in t.uniforms){const r=t.uniforms[e];switch(i.uniforms[e]={},r.type){case"t":i.uniforms[e].value=s(r.value);break;case"c":i.uniforms[e].value=(new Yr).setHex(r.value);break;case"v2":i.uniforms[e].value=(new Ks).fromArray(r.value);break;case"v3":i.uniforms[e].value=(new Ei).fromArray(r.value);break;case"v4":i.uniforms[e].value=(new _i).fromArray(r.value);break;case"m3":i.uniforms[e].value=(new ti).fromArray(r.value);break;case"m4":i.uniforms[e].value=(new or).fromArray(r.value);break;default:i.uniforms[e].value=r.value}}if(void 0!==t.defines&&(i.defines=t.defines),void 0!==t.vertexShader&&(i.vertexShader=t.vertexShader),void 0!==t.fragmentShader&&(i.fragmentShader=t.fragmentShader),void 0!==t.glslVersion&&(i.glslVersion=t.glslVersion),void 0!==t.extensions)for(const e in t.extensions)i.extensions[e]=t.extensions[e];if(void 0!==t.lights&&(i.lights=t.lights),void 0!==t.clipping&&(i.clipping=t.clipping),void 0!==t.size&&(i.size=t.size),void 0!==t.sizeAttenuation&&(i.sizeAttenuation=t.sizeAttenuation),void 0!==t.map&&(i.map=s(t.map)),void 0!==t.matcap&&(i.matcap=s(t.matcap)),void 0!==t.alphaMap&&(i.alphaMap=s(t.alphaMap)),void 0!==t.bumpMap&&(i.bumpMap=s(t.bumpMap)),void 0!==t.bumpScale&&(i.bumpScale=t.bumpScale),void 0!==t.normalMap&&(i.normalMap=s(t.normalMap)),void 0!==t.normalMapType&&(i.normalMapType=t.normalMapType),void 0!==t.normalScale){let e=t.normalScale;!1===Array.isArray(e)&&(e=[e,e]),i.normalScale=(new Ks).fromArray(e)}return void 0!==t.displacementMap&&(i.displacementMap=s(t.displacementMap)),void 0!==t.displacementScale&&(i.displacementScale=t.displacementScale),void 0!==t.displacementBias&&(i.displacementBias=t.displacementBias),void 0!==t.roughnessMap&&(i.roughnessMap=s(t.roughnessMap)),void 0!==t.metalnessMap&&(i.metalnessMap=s(t.metalnessMap)),void 0!==t.emissiveMap&&(i.emissiveMap=s(t.emissiveMap)),void 0!==t.emissiveIntensity&&(i.emissiveIntensity=t.emissiveIntensity),void 0!==t.specularMap&&(i.specularMap=s(t.specularMap)),void 0!==t.specularIntensityMap&&(i.specularIntensityMap=s(t.specularIntensityMap)),void 0!==t.specularColorMap&&(i.specularColorMap=s(t.specularColorMap)),void 0!==t.envMap&&(i.envMap=s(t.envMap)),void 0!==t.envMapRotation&&i.envMapRotation.fromArray(t.envMapRotation),void 0!==t.envMapIntensity&&(i.envMapIntensity=t.envMapIntensity),void 0!==t.reflectivity&&(i.reflectivity=t.reflectivity),void 0!==t.refractionRatio&&(i.refractionRatio=t.refractionRatio),void 0!==t.lightMap&&(i.lightMap=s(t.lightMap)),void 0!==t.lightMapIntensity&&(i.lightMapIntensity=t.lightMapIntensity),void 0!==t.aoMap&&(i.aoMap=s(t.aoMap)),void 0!==t.aoMapIntensity&&(i.aoMapIntensity=t.aoMapIntensity),void 0!==t.gradientMap&&(i.gradientMap=s(t.gradientMap)),void 0!==t.clearcoatMap&&(i.clearcoatMap=s(t.clearcoatMap)),void 0!==t.clearcoatRoughnessMap&&(i.clearcoatRoughnessMap=s(t.clearcoatRoughnessMap)),void 0!==t.clearcoatNormalMap&&(i.clearcoatNormalMap=s(t.clearcoatNormalMap)),void 0!==t.clearcoatNormalScale&&(i.clearcoatNormalScale=(new Ks).fromArray(t.clearcoatNormalScale)),void 0!==t.iridescenceMap&&(i.iridescenceMap=s(t.iridescenceMap)),void 0!==t.iridescenceThicknessMap&&(i.iridescenceThicknessMap=s(t.iridescenceThicknessMap)),void 0!==t.transmissionMap&&(i.transmissionMap=s(t.transmissionMap)),void 0!==t.thicknessMap&&(i.thicknessMap=s(t.thicknessMap)),void 0!==t.anisotropyMap&&(i.anisotropyMap=s(t.anisotropyMap)),void 0!==t.sheenColorMap&&(i.sheenColorMap=s(t.sheenColorMap)),void 0!==t.sheenRoughnessMap&&(i.sheenRoughnessMap=s(t.sheenRoughnessMap)),i}setTextures(t){return this.textures=t,this}static createMaterialFromType(t){return new{ShadowMaterial:Su,SpriteMaterial:uo,RawShaderMaterial:Mu,ShaderMaterial:$n,PointsMaterial:Va,MeshPhysicalMaterial:Nu,MeshStandardMaterial:Au,MeshPhongMaterial:Ru,MeshToonMaterial:Cu,MeshNormalMaterial:Eu,MeshLambertMaterial:Bu,MeshDepthMaterial:Iu,MeshDistanceMaterial:Pu,MeshBasicMaterial:Kr,MeshMatcapMaterial:Fu,LineDashedMaterial:Uu,LineBasicMaterial:Ma,Material:Qr}[t]}}class Ol{static decodeText(t){if(console.warn("THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead."),"undefined"!=typeof TextDecoder)return(new TextDecoder).decode(t);let e="";for(let s=0,i=t.length;s0){const s=new il(e);r=new cl(s),r.setCrossOrigin(this.crossOrigin);for(let e=0,s=t.length;e0){i=new cl(this.manager),i.setCrossOrigin(this.crossOrigin);for(let e=0,i=t.length;e{const e=new Pi;e.min.fromArray(t.boxMin),e.max.fromArray(t.boxMax);const s=new Zi;return s.radius=t.sphereRadius,s.center.fromArray(t.sphereCenter),{boxInitialized:t.boxInitialized,box:e,sphereInitialized:t.sphereInitialized,sphere:s}})),n._maxInstanceCount=t.maxInstanceCount,n._maxVertexCount=t.maxVertexCount,n._maxIndexCount=t.maxIndexCount,n._geometryInitialized=t.geometryInitialized,n._geometryCount=t.geometryCount,n._matricesTexture=l(t.matricesTexture.uuid),void 0!==t.colorsTexture&&(n._colorsTexture=l(t.colorsTexture.uuid));break;case"LOD":n=new Ro;break;case"Line":n=new Pa(h(t.geometry),u(t.material));break;case"LineLoop":n=new za(h(t.geometry),u(t.material));break;case"LineSegments":n=new La(h(t.geometry),u(t.material));break;case"PointCloud":case"Points":n=new ja(h(t.geometry),u(t.material));break;case"Sprite":n=new So(u(t.material));break;case"Group":n=new qa;break;case"Bone":n=new Vo;break;default:n=new Pr}if(n.uuid=t.uuid,void 0!==t.name&&(n.name=t.name),void 0!==t.matrix?(n.matrix.fromArray(t.matrix),void 0!==t.matrixAutoUpdate&&(n.matrixAutoUpdate=t.matrixAutoUpdate),n.matrixAutoUpdate&&n.matrix.decompose(n.position,n.quaternion,n.scale)):(void 0!==t.position&&n.position.fromArray(t.position),void 0!==t.rotation&&n.rotation.fromArray(t.rotation),void 0!==t.quaternion&&n.quaternion.fromArray(t.quaternion),void 0!==t.scale&&n.scale.fromArray(t.scale)),void 0!==t.up&&n.up.fromArray(t.up),void 0!==t.castShadow&&(n.castShadow=t.castShadow),void 0!==t.receiveShadow&&(n.receiveShadow=t.receiveShadow),t.shadow&&(void 0!==t.shadow.intensity&&(n.shadow.intensity=t.shadow.intensity),void 0!==t.shadow.bias&&(n.shadow.bias=t.shadow.bias),void 0!==t.shadow.normalBias&&(n.shadow.normalBias=t.shadow.normalBias),void 0!==t.shadow.radius&&(n.shadow.radius=t.shadow.radius),void 0!==t.shadow.mapSize&&n.shadow.mapSize.fromArray(t.shadow.mapSize),void 0!==t.shadow.camera&&(n.shadow.camera=this.parseObject(t.shadow.camera))),void 0!==t.visible&&(n.visible=t.visible),void 0!==t.frustumCulled&&(n.frustumCulled=t.frustumCulled),void 0!==t.renderOrder&&(n.renderOrder=t.renderOrder),void 0!==t.userData&&(n.userData=t.userData),void 0!==t.layers&&(n.layers.mask=t.layers),void 0!==t.children){const o=t.children;for(let t=0;t{e&&e(s),r.manager.itemEnd(t)})).catch((t=>{i&&i(t)})):(setTimeout((function(){e&&e(n),r.manager.itemEnd(t)}),0),n);const o={};o.credentials="anonymous"===this.crossOrigin?"same-origin":"include",o.headers=this.requestHeader;const a=fetch(t,o).then((function(t){return t.blob()})).then((function(t){return createImageBitmap(t,Object.assign(r.options,{colorSpaceConversion:"none"}))})).then((function(s){return sl.add(t,s),e&&e(s),r.manager.itemEnd(t),s})).catch((function(e){i&&i(e),sl.remove(t),r.manager.itemError(t),r.manager.itemEnd(t)}));sl.add(t,a),r.manager.itemStart(t)}}let jl;class Hl{static getContext(){return void 0===jl&&(jl=new(window.AudioContext||window.webkitAudioContext)),jl}static setContext(t){jl=t}}class ql extends nl{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new hl(this.manager);function o(e){i?i(e):console.error(e),r.manager.itemError(t)}n.setResponseType("arraybuffer"),n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(t){try{const s=t.slice(0);Hl.getContext().decodeAudioData(s,(function(t){e(t)})).catch(o)}catch(t){o(t)}}),s,i)}}const $l=new or,Xl=new or,Yl=new or;class Jl{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Qn,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Qn,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(t){const e=this._cache;if(e.focus!==t.focus||e.fov!==t.fov||e.aspect!==t.aspect*this.aspect||e.near!==t.near||e.far!==t.far||e.zoom!==t.zoom||e.eyeSep!==this.eyeSep){e.focus=t.focus,e.fov=t.fov,e.aspect=t.aspect*this.aspect,e.near=t.near,e.far=t.far,e.zoom=t.zoom,e.eyeSep=this.eyeSep,Yl.copy(t.projectionMatrix);const s=e.eyeSep/2,i=s*e.near/e.focus,r=e.near*Math.tan(js*e.fov*.5)/e.zoom;let n,o;Xl.elements[12]=-s,$l.elements[12]=s,n=-r*e.aspect+i,o=r*e.aspect+i,Yl.elements[0]=2*e.near/(o-n),Yl.elements[8]=(o+n)/(o-n),this.cameraL.projectionMatrix.copy(Yl),n=-r*e.aspect-i,o=r*e.aspect-i,Yl.elements[0]=2*e.near/(o-n),Yl.elements[8]=(o+n)/(o-n),this.cameraR.projectionMatrix.copy(Yl)}this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(Xl),this.cameraR.matrixWorld.copy(t.matrixWorld).multiply($l)}}class Zl extends Qn{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class Ql{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=Kl(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){const e=Kl();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function Kl(){return("undefined"==typeof performance?Date:performance).now()}const tc=new Ei,ec=new Ci,sc=new Ei,ic=new Ei;class rc extends Pr{constructor(){super(),this.type="AudioListener",this.context=Hl.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new Ql}getInput(){return this.gain}removeFilter(){return null!==this.filter&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this}getFilter(){return this.filter}setFilter(t){return null!==this.filter?(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)):this.gain.disconnect(this.context.destination),this.filter=t,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}updateMatrixWorld(t){super.updateMatrixWorld(t);const e=this.context.listener,s=this.up;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(tc,ec,sc),ic.set(0,0,-1).applyQuaternion(ec),e.positionX){const t=this.context.currentTime+this.timeDelta;e.positionX.linearRampToValueAtTime(tc.x,t),e.positionY.linearRampToValueAtTime(tc.y,t),e.positionZ.linearRampToValueAtTime(tc.z,t),e.forwardX.linearRampToValueAtTime(ic.x,t),e.forwardY.linearRampToValueAtTime(ic.y,t),e.forwardZ.linearRampToValueAtTime(ic.z,t),e.upX.linearRampToValueAtTime(s.x,t),e.upY.linearRampToValueAtTime(s.y,t),e.upZ.linearRampToValueAtTime(s.z,t)}else e.setPosition(tc.x,tc.y,tc.z),e.setOrientation(ic.x,ic.y,ic.z,s.x,s.y,s.z)}}class nc extends Pr{constructor(t){super(),this.type="Audio",this.listener=t,this.context=t.context,this.gain=this.context.createGain(),this.gain.connect(t.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.offset=0,this.duration=void 0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.source=null,this.sourceType="empty",this._startedAt=0,this._progress=0,this._connected=!1,this.filters=[]}getOutput(){return this.gain}setNodeSource(t){return this.hasPlaybackControl=!1,this.sourceType="audioNode",this.source=t,this.connect(),this}setMediaElementSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaNode",this.source=this.context.createMediaElementSource(t),this.connect(),this}setMediaStreamSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaStreamNode",this.source=this.context.createMediaStreamSource(t),this.connect(),this}setBuffer(t){return this.buffer=t,this.sourceType="buffer",this.autoplay&&this.play(),this}play(t=0){if(!0===this.isPlaying)return void console.warn("THREE.Audio: Audio is already playing.");if(!1===this.hasPlaybackControl)return void console.warn("THREE.Audio: this Audio has no playback control.");this._startedAt=this.context.currentTime+t;const e=this.context.createBufferSource();return e.buffer=this.buffer,e.loop=this.loop,e.loopStart=this.loopStart,e.loopEnd=this.loopEnd,e.onended=this.onEnded.bind(this),e.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=e,this.setDetune(this.detune),this.setPlaybackRate(this.playbackRate),this.connect()}pause(){if(!1!==this.hasPlaybackControl)return!0===this.isPlaying&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,!0===this.loop&&(this._progress=this._progress%(this.duration||this.buffer.duration)),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this;console.warn("THREE.Audio: this Audio has no playback control.")}stop(){if(!1!==this.hasPlaybackControl)return this._progress=0,null!==this.source&&(this.source.stop(),this.source.onended=null),this.isPlaying=!1,this;console.warn("THREE.Audio: this Audio has no playback control.")}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(let t=1,e=this.filters.length;t0){this.source.disconnect(this.filters[0]);for(let t=1,e=this.filters.length;t0&&this._mixBufferRegionAdditive(s,i,this._addIndex*e,1,e);for(let t=e,r=e+e;t!==r;++t)if(s[t]!==s[t+e]){o.setValue(s,i);break}}saveOriginalState(){const t=this.binding,e=this.buffer,s=this.valueSize,i=s*this._origIndex;t.getValue(e,i);for(let t=s,r=i;t!==r;++t)e[t]=e[i+t%s];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const t=3*this.valueSize;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){const t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let s=t;s=.5)for(let i=0;i!==r;++i)t[e+i]=t[s+i]}_slerp(t,e,s,i){Ci.slerpFlat(t,e,t,e,t,s,i)}_slerpAdditive(t,e,s,i,r){const n=this._workIndex*r;Ci.multiplyQuaternionsFlat(t,n,t,e,t,s),Ci.slerpFlat(t,e,t,e,t,n,i)}_lerp(t,e,s,i,r){const n=1-i;for(let o=0;o!==r;++o){const r=e+o;t[r]=t[r]*n+t[s+o]*i}}_lerpAdditive(t,e,s,i,r){for(let n=0;n!==r;++n){const r=e+n;t[r]=t[r]+t[s+n]*i}}}const pc="\\[\\]\\.:\\/",mc=new RegExp("["+pc+"]","g"),gc="[^"+pc+"]",fc="[^"+pc.replace("\\.","")+"]",yc=new RegExp("^"+/((?:WC+[\/:])*)/.source.replace("WC",gc)+/(WCOD+)?/.source.replace("WCOD",fc)+/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",gc)+/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",gc)+"$"),xc=["material","materials","bones","map"];class bc{constructor(t,e,s){this.path=e,this.parsedPath=s||bc.parseTrackName(e),this.node=bc.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,s){return t&&t.isAnimationObjectGroup?new bc.Composite(t,e,s):new bc(t,e,s)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(mc,"")}static parseTrackName(t){const e=yc.exec(t);if(null===e)throw new Error("PropertyBinding: Cannot parse trackName: "+t);const s={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},i=s.nodeName&&s.nodeName.lastIndexOf(".");if(void 0!==i&&-1!==i){const t=s.nodeName.substring(i+1);-1!==xc.indexOf(t)&&(s.nodeName=s.nodeName.substring(0,i),s.objectName=t)}if(null===s.propertyName||0===s.propertyName.length)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return s}static findNode(t,e){if(void 0===e||""===e||"."===e||-1===e||e===t.name||e===t.uuid)return t;if(t.skeleton){const s=t.skeleton.getBoneByName(e);if(void 0!==s)return s}if(t.children){const s=function(t){for(let i=0;i=r){const n=r++,u=t[n];e[u.uuid]=h,t[h]=u,e[a]=n,t[n]=o;for(let t=0,e=i;t!==e;++t){const e=s[t],i=e[n],r=e[h];e[h]=i,e[n]=r}}}this.nCachedObjects_=r}uncache(){const t=this._objects,e=this._indicesByUUID,s=this._bindings,i=s.length;let r=this.nCachedObjects_,n=t.length;for(let o=0,a=arguments.length;o!==a;++o){const a=arguments[o].uuid,h=e[a];if(void 0!==h)if(delete e[a],h0&&(e[o.uuid]=h),t[h]=o,t.pop();for(let t=0,e=i;t!==e;++t){const e=s[t];e[h]=e[r],e.pop()}}}this.nCachedObjects_=r}subscribe_(t,e){const s=this._bindingsIndicesByPath;let i=s[t];const r=this._bindings;if(void 0!==i)return r[i];const n=this._paths,o=this._parsedPaths,a=this._objects,h=a.length,u=this.nCachedObjects_,l=new Array(h);i=r.length,s[t]=i,n.push(t),o.push(e),r.push(l);for(let s=u,i=a.length;s!==i;++s){const i=a[s];l[s]=new bc(i,t,e)}return l}unsubscribe_(t){const e=this._bindingsIndicesByPath,s=e[t];if(void 0!==s){const i=this._paths,r=this._parsedPaths,n=this._bindings,o=n.length-1,a=n[o];e[t[o]]=s,n[s]=a,n.pop(),r[s]=r[o],r.pop(),i[s]=i[o],i.pop()}}}class Tc{constructor(t,e,s=null,i=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=s,this.blendMode=i;const r=e.tracks,n=r.length,o=new Array(n),a={endingStart:Ue,endingEnd:Ue};for(let t=0;t!==n;++t){const e=r[t].createInterpolant(null);o[t]=e,e.settings=a}this._interpolantSettings=a,this._interpolants=o,this._propertyBindings=new Array(n),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=2201,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&0!==this.timeScale&&null===this._startTime&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(t){return this._startTime=t,this}setLoop(t,e){return this.loop=t,this.repetitions=e,this}setEffectiveWeight(t){return this.weight=t,this._effectiveWeight=this.enabled?t:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(t){return this._scheduleFading(t,0,1)}fadeOut(t){return this._scheduleFading(t,1,0)}crossFadeFrom(t,e,s){if(t.fadeOut(e),this.fadeIn(e),s){const s=this._clip.duration,i=t._clip.duration,r=i/s,n=s/i;t.warp(1,r,e),this.warp(n,1,e)}return this}crossFadeTo(t,e,s){return t.crossFadeFrom(this,e,s)}stopFading(){const t=this._weightInterpolant;return null!==t&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}setEffectiveTimeScale(t){return this.timeScale=t,this._effectiveTimeScale=this.paused?0:t,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(t){return this.timeScale=this._clip.duration/t,this.stopWarping()}syncWith(t){return this.time=t.time,this.timeScale=t.timeScale,this.stopWarping()}halt(t){return this.warp(this._effectiveTimeScale,0,t)}warp(t,e,s){const i=this._mixer,r=i.time,n=this.timeScale;let o=this._timeScaleInterpolant;null===o&&(o=i._lendControlInterpolant(),this._timeScaleInterpolant=o);const a=o.parameterPositions,h=o.sampleValues;return a[0]=r,a[1]=r+s,h[0]=t/n,h[1]=e/n,this}stopWarping(){const t=this._timeScaleInterpolant;return null!==t&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(t,e,s,i){if(!this.enabled)return void this._updateWeight(t);const r=this._startTime;if(null!==r){const i=(t-r)*s;i<0||0===s?e=0:(this._startTime=null,e=s*i)}e*=this._updateTimeScale(t);const n=this._updateTime(e),o=this._updateWeight(t);if(o>0){const t=this._interpolants,e=this._propertyBindings;if(this.blendMode===Ve)for(let s=0,i=t.length;s!==i;++s)t[s].evaluate(n),e[s].accumulateAdditive(o);else for(let s=0,r=t.length;s!==r;++s)t[s].evaluate(n),e[s].accumulate(i,o)}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const s=this._weightInterpolant;if(null!==s){const i=s.evaluate(t)[0];e*=i,t>s.parameterPositions[1]&&(this.stopFading(),0===i&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;const s=this._timeScaleInterpolant;if(null!==s){e*=s.evaluate(t)[0],t>s.parameterPositions[1]&&(this.stopWarping(),0===e?this.paused=!0:this.timeScale=e)}}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,s=this.loop;let i=this.time+t,r=this._loopCount;const n=2202===s;if(0===t)return-1===r?i:n&&1==(1&r)?e-i:i;if(2200===s){-1===r&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(i>=e)i=e;else{if(!(i<0)){this.time=i;break t}i=0}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(-1===r&&(t>=0?(r=0,this._setEndings(!0,0===this.repetitions,n)):this._setEndings(0===this.repetitions,!0,n)),i>=e||i<0){const s=Math.floor(i/e);i-=e*s,r+=Math.abs(s);const o=this.repetitions-r;if(o<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,i=t>0?e:0,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(1===o){const e=t<0;this._setEndings(e,!e,n)}else this._setEndings(!1,!1,n);this._loopCount=r,this.time=i,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:s})}}else this.time=i;if(n&&1==(1&r))return e-i}return i}_setEndings(t,e,s){const i=this._interpolantSettings;s?(i.endingStart=Oe,i.endingEnd=Oe):(i.endingStart=t?this.zeroSlopeAtStart?Oe:Ue:Le,i.endingEnd=e?this.zeroSlopeAtEnd?Oe:Ue:Le)}_scheduleFading(t,e,s){const i=this._mixer,r=i.time;let n=this._weightInterpolant;null===n&&(n=i._lendControlInterpolant(),this._weightInterpolant=n);const o=n.parameterPositions,a=n.sampleValues;return o[0]=r,a[0]=e,o[1]=r+t,a[1]=s,this}}const _c=new Float32Array(1);class wc extends ks{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(t,e){const s=t._localRoot||this._root,i=t._clip.tracks,r=i.length,n=t._propertyBindings,o=t._interpolants,a=s.uuid,h=this._bindingsByRootAndName;let u=h[a];void 0===u&&(u={},h[a]=u);for(let t=0;t!==r;++t){const r=i[t],h=r.name;let l=u[h];if(void 0!==l)++l.referenceCount,n[t]=l;else{if(l=n[t],void 0!==l){null===l._cacheIndex&&(++l.referenceCount,this._addInactiveBinding(l,a,h));continue}const i=e&&e._propertyBindings[t].binding.parsedPath;l=new dc(bc.create(s,h,i),r.ValueTypeName,r.getValueSize()),++l.referenceCount,this._addInactiveBinding(l,a,h),n[t]=l}o[t].resultBuffer=l.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(null===t._cacheIndex){const e=(t._localRoot||this._root).uuid,s=t._clip.uuid,i=this._actionsByClip[s];this._bindAction(t,i&&i.knownActions[0]),this._addInactiveAction(t,s,e)}const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==s.useCount++&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==--s.useCount&&(s.restoreOriginalState(),this._takeBackBinding(s))}this._takeBackAction(t)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}}_isActiveAction(t){const e=t._cacheIndex;return null!==e&&e=0;--e)t[e].stop();return this}update(t){t*=this.timeScale;const e=this._actions,s=this._nActiveActions,i=this.time+=t,r=Math.sign(t),n=this._accuIndex^=1;for(let o=0;o!==s;++o){e[o]._update(i,t,r,n)}const o=this._bindings,a=this._nActiveBindings;for(let t=0;t!==a;++t)o[t].apply(n);return this}setTime(t){this.time=0;for(let t=0;tthis.max.x||t.ythis.max.y)}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(t){return!(t.max.xthis.max.x||t.max.ythis.max.y)}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Uc).distanceTo(t)}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const Lc=new Ei,zc=new Ei;class Vc{constructor(t=new Ei,e=new Ei){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){Lc.subVectors(t,this.start),zc.subVectors(this.end,this.start);const s=zc.dot(zc);let i=zc.dot(Lc)/s;return e&&(i=$s(i,0,1)),i}closestPointToPoint(t,e,s){const i=this.closestPointToPointParameter(t,e);return this.delta(s).multiplyScalar(i).add(this.start)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return(new this.constructor).copy(this)}}const Dc=new Ei;class kc extends Pr{constructor(t,e){super(),this.light=t,this.matrixAutoUpdate=!1,this.color=e,this.type="SpotLightHelper";const s=new Mn,i=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(let t=0,e=1,s=32;t1)for(let s=0;s.99999)this.quaternion.set(0,0,0,1);else if(t.y<-.99999)this.quaternion.set(1,0,0,0);else{dd.set(t.z,0,-t.x).normalize();const e=Math.acos(t.y);this.quaternion.setFromAxisAngle(dd,e)}}setLength(t,e=.2*t,s=.2*e){this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(s,e,s),this.cone.position.y=t,this.cone.updateMatrix()}setColor(t){this.line.material.color.set(t),this.cone.material.color.set(t)}copy(t){return super.copy(t,!1),this.line.copy(t.line),this.cone.copy(t.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}}class fd extends La{constructor(t=1){const e=[0,0,0,t,0,0,0,0,0,0,t,0,0,0,0,0,0,t],s=new Mn;s.setAttribute("position",new yn(e,3)),s.setAttribute("color",new yn([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],3));super(s,new Ma({vertexColors:!0,toneMapped:!1})),this.type="AxesHelper"}setColors(t,e,s){const i=new Yr,r=this.geometry.attributes.color.array;return i.set(t),i.toArray(r,0),i.toArray(r,3),i.set(e),i.toArray(r,6),i.toArray(r,9),i.set(s),i.toArray(r,12),i.toArray(r,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class yd{constructor(){this.type="ShapePath",this.color=new Yr,this.subPaths=[],this.currentPath=null}moveTo(t,e){return this.currentPath=new Th,this.subPaths.push(this.currentPath),this.currentPath.moveTo(t,e),this}lineTo(t,e){return this.currentPath.lineTo(t,e),this}quadraticCurveTo(t,e,s,i){return this.currentPath.quadraticCurveTo(t,e,s,i),this}bezierCurveTo(t,e,s,i,r,n){return this.currentPath.bezierCurveTo(t,e,s,i,r,n),this}splineThru(t){return this.currentPath.splineThru(t),this}toShapes(t){function e(t,e){const s=e.length;let i=!1;for(let r=s-1,n=0;nNumber.EPSILON){if(h<0&&(s=e[n],a=-a,o=e[r],h=-h),t.yo.y)continue;if(t.y===s.y){if(t.x===s.x)return!0}else{const e=h*(t.x-s.x)-a*(t.y-s.y);if(0===e)return!0;if(e<0)continue;i=!i}}else{if(t.y!==s.y)continue;if(o.x<=t.x&&t.x<=s.x||s.x<=t.x&&t.x<=o.x)return!0}}return i}const s=ou.isClockWise,i=this.subPaths;if(0===i.length)return[];let r,n,o;const a=[];if(1===i.length)return n=i[0],o=new Fh,o.curves=n.curves,a.push(o),a;let h=!s(i[0].getPoints());h=t?!h:h;const u=[],l=[];let c,d,p=[],m=0;l[m]=void 0,p[m]=[];for(let e=0,o=i.length;e1){let t=!1,s=0;for(let t=0,e=l.length;t0&&!1===t&&(p=u)}for(let t=0,e=l.length;t{this.requestId=self.requestAnimationFrame(t),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this.animationLoop&&this.animationLoop(e,s)};t()}dispose(){self.cancelAnimationFrame(this.requestId),this.requestId=null}setAnimationLoop(t){this.animationLoop=t}}class _d{constructor(){this.weakMap=new WeakMap}get(t){let e=this.weakMap;for(let s=0;s{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(t){const e=this.material;let s=this.clippingContext;Array.isArray(e.clippingPlanes)?(s!==t&&s||(s=new Md,this.clippingContext=s),s.update(t,e)):this.clippingContext!==t&&(this.clippingContext=t)}get clippingNeedsUpdate(){return this.clippingContext.version!==this.clippingContextVersion&&(this.clippingContextVersion=this.clippingContext.version,!0)}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}getAttributes(){if(null!==this.attributes)return this.attributes;const t=this.getNodeBuilderState().nodeAttributes,e=this.geometry,s=[],i=new Set;for(const r of t){const t=r.node&&r.node.attribute?r.node.attribute:e.getAttribute(r.name);if(void 0===t)continue;s.push(t);const n=t.isInterleavedBufferAttribute?t.data:t;i.add(n)}return this.attributes=s,this.vertexBuffers=Array.from(i.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getMaterialCacheKey(){const{object:t,material:e}=this;let s=e.customProgramCacheKey();for(const t of function(t){const e=Object.keys(t);let s=Object.getPrototypeOf(t);for(;s;){const t=Object.getOwnPropertyDescriptors(s);for(const s in t)if(void 0!==t[s]){const i=t[s];i&&"function"==typeof i.get&&e.push(s)}s=Object.getPrototypeOf(s)}return e}(e)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(t))continue;const i=e[t];let r;if(null!==i){const t=typeof i;"number"===t?r=0!==i?"1":"0":"object"===t&&(r="{",i.isTexture&&(r+=i.mapping),r+="}")}else r=String(i);s+=r+","}return s+=this.clippingContextVersion+",",t.skeleton&&(s+=t.skeleton.bones.length+","),t.morphTargetInfluences&&(s+=t.morphTargetInfluences.length+","),t.isBatchedMesh&&(s+=t._matricesTexture.uuid+",",null!==t._colorsTexture&&(s+=t._colorsTexture.uuid+",")),t.count>1&&(s+=t.count+","),s}get needsUpdate(){return this.initialNodesCacheKey!==this.getNodesCacheKey()||this.clippingNeedsUpdate}getNodesCacheKey(){return this._nodes.getCacheKey(this.scene,this.lightsNode)}getCacheKey(){return this.getMaterialCacheKey()+","+this.getNodesCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}class Rd{constructor(t,e,s,i,r,n){this.renderer=t,this.nodes=e,this.geometries=s,this.pipelines=i,this.bindings=r,this.info=n,this.chainMaps={}}get(t,e,s,i,r,n,o){const a=this.getChainMap(o),h=[t,e,n,r];let u=a.get(h);return void 0===u?(u=this.createRenderObject(this.nodes,this.geometries,this.renderer,t,e,s,i,r,n,o),a.set(h,u)):(u.updateClipping(n.clippingContext),(u.version!==e.version||u.needsUpdate)&&(u.initialCacheKey!==u.getCacheKey()?(u.dispose(),u=this.get(t,e,s,i,r,n,o)):u.version=e.version)),u}getChainMap(t="default"){return this.chainMaps[t]||(this.chainMaps[t]=new _d)}dispose(){this.chainMaps={}}createRenderObject(t,e,s,i,r,n,o,a,h,u){const l=this.getChainMap(u),c=new Nd(t,e,s,i,r,n,o,a,h);return c.onDispose=()=>{this.pipelines.delete(c),this.bindings.delete(c),this.nodes.delete(c),l.delete(c.getChainArray())},c}}class Cd{constructor(){this.data=new WeakMap}get(t){let e=this.data.get(t);return void 0===e&&(e={},this.data.set(t,e)),e}delete(t){let e;return this.data.has(t)&&(e=this.data.get(t),this.data.delete(t)),e}has(t){return this.data.has(t)}dispose(){this.data=new WeakMap}}const Ed=1,Bd=2,Id=4,Pd=16;class Fd extends Cd{constructor(t){super(),this.backend=t}delete(t){const e=super.delete(t);return void 0!==e&&this.backend.destroyAttribute(t),e}update(t,e){const s=this.get(t);if(void 0===s.version)e===Ed?this.backend.createAttribute(t):e===Bd?this.backend.createIndexAttribute(t):e===Id&&this.backend.createStorageAttribute(t),s.version=this._getBufferAttribute(t).version;else{const e=this._getBufferAttribute(t);(s.version=0;--e)if(t[e]>=65535)return!0;return!1}(e)?gn:pn)(e,1);return r.version=Ud(t),r}class Ld extends Cd{constructor(t,e){super(),this.attributes=t,this.info=e,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(t){const e=t.geometry;return super.has(e)&&!0===this.get(e).initialized}updateForRender(t){!1===this.has(t)&&this.initGeometry(t),this.updateAttributes(t)}initGeometry(t){const e=t.geometry;this.get(e).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const i=e.index,r=t.getAttributes();null!==i&&this.attributes.delete(i);for(const t of r)this.attributes.delete(t);const n=this.wireframes.get(e);void 0!==n&&this.attributes.delete(n),e.removeEventListener("dispose",s)};e.addEventListener("dispose",s)}updateAttributes(t){const e=t.getAttributes();for(const t of e)t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute?this.updateAttribute(t,Id):this.updateAttribute(t,Ed);const s=this.getIndex(t);null!==s&&this.updateAttribute(s,Bd)}updateAttribute(t,e){const s=this.info.render.calls;t.isInterleavedBufferAttribute?void 0===this.attributeCall.get(t)?(this.attributes.update(t,e),this.attributeCall.set(t,s)):this.attributeCall.get(t.data)!==s&&(this.attributes.update(t,e),this.attributeCall.set(t.data,s),this.attributeCall.set(t,s)):this.attributeCall.get(t)!==s&&(this.attributes.update(t,e),this.attributeCall.set(t,s))}getIndex(t){const{geometry:e,material:s}=t;let i=e.index;if(!0===s.wireframe){const t=this.wireframes;let s=t.get(e);void 0===s?(s=Od(e),t.set(e,s)):s.version!==Ud(e)&&(this.attributes.delete(s),s=Od(e),t.set(e,s)),i=s}return i}}class zd{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(t,e,s){this.render.drawCalls++,t.isMesh||t.isSprite?this.render.triangles+=s*(e/3):t.isPoints?this.render.points+=s*e:t.isLineSegments?this.render.lines+=s*(e/2):t.isLine?this.render.lines+=s*(e-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(t,e){0===this[t].timestampCalls&&(this[t].timestamp=0),this[t].timestamp+=e,this[t].timestampCalls++,this[t].timestampCalls>=this[t].previousFrameCalls&&(this[t].timestampCalls=0)}reset(){const t=this.render.frameCalls;this.render.previousFrameCalls=t;const e=this.compute.frameCalls;this.compute.previousFrameCalls=e,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class Vd{constructor(t){this.cacheKey=t,this.usedTimes=0}}class Dd extends Vd{constructor(t,e,s){super(t),this.vertexProgram=e,this.fragmentProgram=s}}class kd extends Vd{constructor(t,e){super(t),this.computeProgram=e,this.isComputePipeline=!0}}let Gd=0;class Wd{constructor(t,e,s=null,i=null){this.id=Gd++,this.code=t,this.stage=e,this.transforms=s,this.attributes=i,this.usedTimes=0}}class jd extends Cd{constructor(t,e){super(),this.backend=t,this.nodes=e,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(t,e){const{backend:s}=this,i=this.get(t);if(this._needsComputeUpdate(t)){const r=i.pipeline;r&&(r.usedTimes--,r.computeProgram.usedTimes--);const n=this.nodes.getForCompute(t);let o=this.programs.compute.get(n.computeShader);void 0===o&&(r&&0===r.computeProgram.usedTimes&&this._releaseProgram(r.computeProgram),o=new Wd(n.computeShader,"compute",n.transforms,n.nodeAttributes),this.programs.compute.set(n.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(t,o);let h=this.caches.get(a);void 0===h&&(r&&0===r.usedTimes&&this._releasePipeline(r),h=this._getComputePipeline(t,o,a,e)),h.usedTimes++,o.usedTimes++,i.version=t.version,i.pipeline=h}return i.pipeline}getForRender(t,e=null){const{backend:s}=this,i=this.get(t);if(this._needsRenderUpdate(t)){const r=i.pipeline;r&&(r.usedTimes--,r.vertexProgram.usedTimes--,r.fragmentProgram.usedTimes--);const n=t.getNodeBuilderState();let o=this.programs.vertex.get(n.vertexShader);void 0===o&&(r&&0===r.vertexProgram.usedTimes&&this._releaseProgram(r.vertexProgram),o=new Wd(n.vertexShader,"vertex"),this.programs.vertex.set(n.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(n.fragmentShader);void 0===a&&(r&&0===r.fragmentProgram.usedTimes&&this._releaseProgram(r.fragmentProgram),a=new Wd(n.fragmentShader,"fragment"),this.programs.fragment.set(n.fragmentShader,a),s.createProgram(a));const h=this._getRenderCacheKey(t,o,a);let u=this.caches.get(h);void 0===u?(r&&0===r.usedTimes&&this._releasePipeline(r),u=this._getRenderPipeline(t,o,a,h,e)):t.pipeline=u,u.usedTimes++,o.usedTimes++,a.usedTimes++,i.pipeline=u}return i.pipeline}delete(t){const e=this.get(t).pipeline;return e&&(e.usedTimes--,0===e.usedTimes&&this._releasePipeline(e),e.isComputePipeline?(e.computeProgram.usedTimes--,0===e.computeProgram.usedTimes&&this._releaseProgram(e.computeProgram)):(e.fragmentProgram.usedTimes--,e.vertexProgram.usedTimes--,0===e.vertexProgram.usedTimes&&this._releaseProgram(e.vertexProgram),0===e.fragmentProgram.usedTimes&&this._releaseProgram(e.fragmentProgram))),super.delete(t)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(t){this.getForRender(t)}_getComputePipeline(t,e,s,i){s=s||this._getComputeCacheKey(t,e);let r=this.caches.get(s);return void 0===r&&(r=new kd(s,e),this.caches.set(s,r),this.backend.createComputePipeline(r,i)),r}_getRenderPipeline(t,e,s,i,r){i=i||this._getRenderCacheKey(t,e,s);let n=this.caches.get(i);return void 0===n&&(n=new Dd(i,e,s),this.caches.set(i,n),t.pipeline=n,this.backend.createRenderPipeline(t,r)),n}_getComputeCacheKey(t,e){return t.id+","+e.id}_getRenderCacheKey(t,e,s){return e.id+","+s.id+","+this.backend.getRenderCacheKey(t)}_releasePipeline(t){this.caches.delete(t.cacheKey)}_releaseProgram(t){const e=t.code,s=t.stage;this.programs[s].delete(e)}_needsComputeUpdate(t){const e=this.get(t);return void 0===e.pipeline||e.version!==t.version}_needsRenderUpdate(t){return void 0===this.get(t).pipeline||this.backend.needsRenderUpdate(t)}}class Hd extends Cd{constructor(t,e,s,i,r,n){super(),this.backend=t,this.textures=s,this.pipelines=r,this.attributes=i,this.nodes=e,this.info=n,this.pipelines.bindings=this}getForRender(t){const e=t.getBindings();for(const t of e){const s=this.get(t);void 0===s.bindGroup&&(this._init(t),this.backend.createBindings(t,e),s.bindGroup=t)}return e}getForCompute(t){const e=this.nodes.getForCompute(t).bindings;for(const t of e){const s=this.get(t);void 0===s.bindGroup&&(this._init(t),this.backend.createBindings(t,e),s.bindGroup=t)}return e}updateForCompute(t){this._updateBindings(t,this.getForCompute(t))}updateForRender(t){this._updateBindings(t,this.getForRender(t))}_updateBindings(t,e){for(const s of e)this._update(t,s,e)}_init(t){for(const e of t.bindings)if(e.isSampledTexture)this.textures.updateTexture(e.texture);else if(e.isStorageBuffer){const t=e.attribute;this.attributes.update(t,Id)}}_update(t,e,s){const{backend:i}=this;let r=!1;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&i.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=t.texture;t.needsBindingsUpdate&&(r=!0);const s=t.update();s&&this.textures.updateTexture(t.texture);const n=i.get(t.texture);if(!0===i.isWebGPUBackend&&void 0===n.texture&&void 0===n.externalTexture&&(console.error("Bindings._update: binding should be available:",t,s,t.texture,t.textureNode.value),this.textures.updateTexture(t.texture),r=!0),!0===e.isStorageTexture){const s=this.get(e);!0===t.store?s.needsMipmap=!0:!0===e.generateMipmaps&&this.textures.needsMipmaps(e)&&!0===s.needsMipmap&&(this.backend.generateMipmaps(e),s.needsMipmap=!1)}}}if(!0===r){const i=this.pipelines.getForRender(t);this.backend.updateBindings(e,s,i)}}}const qd={VERTEX:"vertex",FRAGMENT:"fragment"},$d={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Xd={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Yd=["fragment","vertex"],Jd=["setup","analyze","generate"],Zd=[...Yd,"compute"],Qd=["x","y","z","w"];function Kd(t,e=!1){let s="{";!0===t.isNode&&(s+=t.id);for(const{property:i,childNode:r}of tp(t))s+=","+i.slice(0,-4)+":"+r.getCacheKey(e);return s+="}",s}function*tp(t,e=!1){for(const s in t){if(!0===s.startsWith("_"))continue;const i=t[s];if(!0===Array.isArray(i))for(let t=0;tt.charCodeAt(0))).buffer}var np=Object.freeze({__proto__:null,arrayBufferToBase64:ip,base64ToArrayBuffer:rp,getCacheKey:Kd,getNodeChildren:tp,getValueFromType:sp,getValueType:ep});const op=new Map;let ap=0;class hp extends ks{constructor(t=null){super(),this.nodeType=t,this.updateType=$d.NONE,this.updateBeforeType=$d.NONE,this.updateAfterType=$d.NONE,this.uuid=Qs.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:ap++})}set needsUpdate(t){!0===t&&this.version++}get type(){return this.constructor.type}onUpdate(t,e){return this.updateType=e,this.update=t.bind(this.getSelf()),this}onFrameUpdate(t){return this.onUpdate(t,$d.FRAME)}onRenderUpdate(t){return this.onUpdate(t,$d.RENDER)}onObjectUpdate(t){return this.onUpdate(t,$d.OBJECT)}onReference(t){return this.updateReference=t.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:t}of tp(this))yield t}dispose(){this.dispatchEvent({type:"dispose"})}traverse(t){t(this);for(const e of this.getChildren())e.traverse(t)}getCacheKey(t=!1){return!0!==(t=t||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=Kd(this,t),this._cacheKeyVersion=this.version),this._cacheKey}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(t){const e=this.getNodeType(t);return t.getElementType(e)}getNodeType(t){const e=t.getNodeProperties(this);return e.outputNode?e.outputNode.getNodeType(t):this.nodeType}getShared(t){const e=this.getHash(t);return t.getNodeFromHash(e)||this}setup(t){const e=t.getNodeProperties(this);let s=0;for(const t of this.getChildren())e["node"+s++]=t;return null}construct(t){return console.warn("THREE.Node: construct() is deprecated. Use setup() instead."),this.setup(t)}increaseUsage(t){const e=t.getDataFromNode(this);return e.usageCount=void 0===e.usageCount?1:e.usageCount+1,e.usageCount}analyze(t){if(1===this.increaseUsage(t)){const e=t.getNodeProperties(this);for(const s of Object.values(e))s&&!0===s.isNode&&s.build(t)}}generate(t,e){const{outputNode:s}=t.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(t,e)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(t,e=null){const s=this.getShared(t);if(this!==s)return s.build(t,e);t.addNode(this),t.addChain(this);let i=null;const r=t.getBuildStage();if("setup"===r){this.updateReference(t);const e=t.getNodeProperties(this);if(!0!==e.initialized){const s=t.stack.nodes.length;e.initialized=!0,e.outputNode=this.setup(t),null!==e.outputNode&&t.stack.nodes.length!==s&&(e.outputNode=t.stack);for(const s of Object.values(e))s&&!0===s.isNode&&s.build(t)}}else if("analyze"===r)this.analyze(t);else if("generate"===r){if(1===this.generate.length){const s=this.getNodeType(t),r=t.getDataFromNode(this);i=r.snippet,void 0===i&&(i=this.generate(t)||"",r.snippet=i),i=t.format(i,s,e)}else i=this.generate(t,e)||""}return t.removeChain(this),i}getSerializeChildren(){return tp(this)}serialize(t){const e=this.getSerializeChildren(),s={};for(const{property:i,index:r,childNode:n}of e)void 0!==r?(void 0===s[i]&&(s[i]=Number.isInteger(r)?[]:{}),s[i][r]=n.toJSON(t.meta).uuid):s[i]=n.toJSON(t.meta).uuid;Object.keys(s).length>0&&(t.inputNodes=s)}deserialize(t){if(void 0!==t.inputNodes){const e=t.meta.nodes;for(const s in t.inputNodes)if(Array.isArray(t.inputNodes[s])){const i=[];for(const r of t.inputNodes[s])i.push(e[r]);this[s]=i}else if("object"==typeof t.inputNodes[s]){const i={};for(const r in t.inputNodes[s]){const n=t.inputNodes[s][r];i[r]=e[n]}this[s]=i}else{const i=t.inputNodes[s];this[s]=e[i]}}}toJSON(t){const{uuid:e,type:s}=this,i=void 0===t||"string"==typeof t;i&&(t={textures:{},images:{},nodes:{}});let r=t.nodes[e];function n(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(void 0===r&&(r={uuid:e,type:s,meta:t,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==i&&(t.nodes[r.uuid]=r),this.serialize(r),delete r.meta),i){const e=n(t.textures),s=n(t.images),i=n(t.nodes);e.length>0&&(r.textures=e),s.length>0&&(r.images=s),i.length>0&&(r.nodes=i)}return r}}function up(t,e){if("function"!=typeof e||!t)throw new Error(`Node class ${t} is not a class`);op.has(t)?console.warn(`Redefinition of node class ${t}`):(op.set(t,e),e.type=t)}function lp(t){const e=op.get(t);if(void 0!==e)return new e}class cp extends hp{constructor(t){super(t),this.isTempNode=!0}hasDependencies(t){return t.getDataFromNode(this).usageCount>1}build(t,e){if("generate"===t.getBuildStage()){const s=t.getVectorType(this.getNodeType(t,e)),i=t.getDataFromNode(this);if(void 0!==i.propertyName)return t.format(i.propertyName,s,e);if("void"!==s&&"void"!==e&&this.hasDependencies(t)){const r=super.build(t,s),n=t.getVarFromNode(this,null,s),o=t.getPropertyName(n);return t.addLineFlowCode(`${o} = ${r}`),i.snippet=r,i.propertyName=o,t.format(i.propertyName,s,e)}}return super.build(t,e)}}up("TempNode",cp);class dp extends hp{constructor(t,e){super(),this.node=t,this.indexNode=e,this.isArrayElementNode=!0}getNodeType(t){return this.node.getElementType(t)}generate(t){return`${this.node.build(t)}[ ${this.indexNode.build(t,"uint")} ]`}}up("ArrayElementNode",dp);class pp extends hp{constructor(t,e){super(),this.node=t,this.convertTo=e}getNodeType(t){const e=this.node.getNodeType(t);let s=null;for(const i of this.convertTo.split("|"))null!==s&&t.getTypeLength(e)!==t.getTypeLength(i)||(s=i);return s}serialize(t){super.serialize(t),t.convertTo=this.convertTo}deserialize(t){super.deserialize(t),this.convertTo=t.convertTo}generate(t,e){const s=this.node,i=this.getNodeType(t),r=s.build(t,i);return t.format(r,i,e)}}up("ConvertNode",pp);class mp extends cp{constructor(t=[],e=null){super(e),this.nodes=t}getNodeType(t){return null!==this.nodeType?t.getVectorType(this.nodeType):t.getTypeFromLength(this.nodes.reduce(((e,s)=>e+t.getTypeLength(s.getNodeType(t))),0))}generate(t,e){const s=this.getNodeType(t),i=this.nodes,r=t.getComponentType(s),n=[];for(const e of i){let s=e.build(t);const i=t.getComponentType(e.getNodeType(t));i!==r&&(s=t.format(s,i,r)),n.push(s)}const o=`${t.getType(s)}( ${n.join(", ")} )`;return t.format(o,s,e)}}up("JoinNode",mp);const gp=Qd.join("");class fp extends hp{constructor(t,e="x"){super(),this.node=t,this.components=e,this.isSplitNode=!0}getVectorLength(){let t=this.components.length;for(const e of this.components)t=Math.max(Qd.indexOf(e)+1,t);return t}getComponentType(t){return t.getComponentType(this.node.getNodeType(t))}getNodeType(t){return t.getTypeFromLength(this.components.length,this.getComponentType(t))}generate(t,e){const s=this.node,i=t.getTypeLength(s.getNodeType(t));let r=null;if(i>1){let n=null;this.getVectorLength()>=i&&(n=t.getTypeFromLength(this.getVectorLength(),this.getComponentType(t)));const o=s.build(t,n);r=this.components.length===i&&this.components===gp.slice(0,this.components.length)?t.format(o,n,e):t.format(`${o}.${this.components}`,this.getNodeType(t),e)}else r=s.build(t,e);return r}serialize(t){super.serialize(t),t.components=this.components}deserialize(t){super.deserialize(t),this.components=t.components}}up("SplitNode",fp);class yp extends cp{constructor(t,e,s){super(),this.sourceNode=t,this.components=e,this.targetNode=s}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{sourceNode:e,components:s,targetNode:i}=this,r=this.getNodeType(t),n=t.getTypeFromLength(s.length),o=i.build(t,n),a=e.build(t,r),h=t.getTypeLength(r),u=[];for(let t=0;tt.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Sp={setup(t,e){const s=e.shift();return t(Yp(s),...e)},get(t,e,s){if("string"==typeof e&&void 0===t[e]){if(!0!==t.isStackNode&&"assign"===e)return(...t)=>(vp.assign(s,...t),s);if(Tp.has(e)){const i=Tp.get(e);return t.isStackNode?(...t)=>s.add(i(...t)):(...t)=>i(s,...t)}if("self"===e)return t;if(e.endsWith("Assign")&&Tp.has(e.slice(0,e.length-6))){const i=Tp.get(e.slice(0,e.length-6));return t.isStackNode?(...t)=>s.assign(t[0],i(...t)):(...t)=>s.assign(i(s,...t))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(e))return e=wp(e),Xp(new fp(s,e));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(e))return e=(e=wp(e.slice(3).toLowerCase())).split("").sort().join(""),s=>Xp(new yp(t,e,s));if("width"===e||"height"===e||"depth"===e)return"width"===e?e="x":"height"===e?e="y":"depth"===e&&(e="z"),Xp(new fp(t,e));if(!0===/^\d+$/.test(e))return Xp(new dp(s,new bp(Number(e),"uint")))}return Reflect.get(t,e,s)},set:(t,e,s,i)=>"string"!=typeof e||void 0!==t[e]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(e)&&"width"!==e&&"height"!==e&&"depth"!==e&&!0!==/^\d+$/.test(e)?Reflect.set(t,e,s,i):(i[e].assign(s),!0)},Mp=new WeakMap,Ap=new WeakMap,Np=function(t,e=null){for(const s in t)t[s]=Xp(t[s],e);return t},Rp=function(t,e=null){const s=t.length;for(let i=0;iXp(null!==i?Object.assign(t,i):t);return null===e?(...e)=>r(new t(...Jp(e))):null!==s?(s=Xp(s),(...i)=>r(new t(e,...Jp(i),s))):(...s)=>r(new t(e,...Jp(s)))},Ep=function(t,...e){return Xp(new t(...Jp(e)))};class Bp extends hp{constructor(t,e){super(),this.shaderNode=t,this.inputNodes=e}getNodeType(t){const e=t.getNodeProperties(this);return null===e.outputNode&&(e.outputNode=this.setupOutput(t)),e.outputNode.getNodeType(t)}call(t){const{shaderNode:e,inputNodes:s}=this;if(e.layout){let i=Ap.get(t.constructor);void 0===i&&(i=new WeakMap,Ap.set(t.constructor,i));let r=i.get(e);return void 0===r&&(r=Xp(t.buildFunctionNode(e)),i.set(e,r)),null!==t.currentFunctionNode&&t.currentFunctionNode.includes.push(r),Xp(r.call(s))}const i=e.jsFunc,r=null!==s?i(s,t.stack,t):i(t.stack,t);return Xp(r)}setup(t){const{outputNode:e}=t.getNodeProperties(this);return e||this.setupOutput(t)}setupOutput(t){return t.addStack(),t.stack.outputNode=this.call(t),t.removeStack()}generate(t,e){const{outputNode:s}=t.getNodeProperties(this);return null===s?this.call(t).build(t,e):super.generate(t,e)}}class Ip extends hp{constructor(t){super(),this.jsFunc=t,this.layout=null,this.global=!0}get isArrayInput(){return/^\((\s+)?\[/.test(this.jsFunc.toString())}setLayout(t){return this.layout=t,this}call(t=null){return Yp(t),Xp(new Bp(this,t))}setup(){return this.call()}}const Pp=[!1,!0],Fp=[0,1,2,3],Up=[-1,-2],Op=[.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],Lp=new Map;for(const t of Pp)Lp.set(t,new bp(t));const zp=new Map;for(const t of Fp)zp.set(t,new bp(t,"uint"));const Vp=new Map([...zp].map((t=>new bp(t.value,"int"))));for(const t of Up)Vp.set(t,new bp(t,"int"));const Dp=new Map([...Vp].map((t=>new bp(t.value))));for(const t of Op)Dp.set(t,new bp(t));for(const t of Op)Dp.set(-t,new bp(-t));const kp={bool:Lp,uint:zp,ints:Vp,float:Dp},Gp=new Map([...Lp,...Dp]),Wp=(t,e)=>Gp.has(t)?Gp.get(t):!0===t.isNode?t:new bp(t,e),jp=function(t,e=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(t)&&s.every((t=>"object"!=typeof t)))&&(s=[sp(t,...s)]),1===s.length&&null!==e&&e.has(s[0]))return Xp(e.get(s[0]));if(1===s.length){const e=Wp(s[0],t);return(t=>{try{return t.getNodeType()}catch(t){return}})(e)===t?Xp(e):Xp(new pp(e,t))}const i=s.map((t=>Wp(t)));return Xp(new mp(i,t))}},Hp=t=>t&&t.value,qp=t=>null!=t?t.nodeType||t.convertTo||("string"==typeof t?t:null):null;function $p(t){return new Proxy(new Ip(t),Sp)}const Xp=(t,e=null)=>function(t,e=null){const s=ep(t);if("node"===s){let e=Mp.get(t);return void 0===e&&(e=new Proxy(t,Sp),Mp.set(t,e),Mp.set(e,e)),e}return null===e&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?Xp(Wp(t,e)):"shader"===s?Kp(t):t}(t,e),Yp=(t,e=null)=>new Np(t,e),Jp=(t,e=null)=>new Rp(t,e),Zp=(...t)=>new Cp(...t),Qp=(...t)=>new Ep(...t),Kp=t=>{const e=new $p(t),s=(...t)=>{let s;return Yp(t),s=t[0]&&t[0].isNode?[...t]:t[0],e.call(s)};return s.shaderNode=e,s.setLayout=t=>(e.setLayout(t),s),s};up("ShaderNode",$p),_p("toGlobal",(t=>(t.global=!0,t)));const tm=t=>{vp=t},em=()=>vp,sm=(...t)=>vp.if(...t);function im(t){return vp&&vp.add(t),t}_p("append",im);const rm=new jp("color"),nm=new jp("float",kp.float),om=new jp("int",kp.ints),am=new jp("uint",kp.uint),hm=new jp("bool",kp.bool),um=new jp("vec2"),lm=new jp("ivec2"),cm=new jp("uvec2"),dm=new jp("bvec2"),pm=new jp("vec3"),mm=new jp("ivec3"),gm=new jp("uvec3"),fm=new jp("bvec3"),ym=new jp("vec4"),xm=new jp("ivec4"),bm=new jp("uvec4"),vm=new jp("bvec4"),Tm=new jp("mat2"),_m=new jp("imat2"),wm=new jp("umat2"),Sm=new jp("bmat2"),Mm=new jp("mat3"),Am=new jp("imat3"),Nm=new jp("umat3"),Rm=new jp("bmat3"),Cm=new jp("mat4"),Em=new jp("imat4"),Bm=new jp("umat4"),Im=new jp("bmat4"),Pm=(t="")=>Xp(new bp(t,"string")),Fm=t=>Xp(new bp(t,"ArrayBuffer"));_p("toColor",rm),_p("toFloat",nm),_p("toInt",om),_p("toUint",am),_p("toBool",hm),_p("toVec2",um),_p("toIvec2",lm),_p("toUvec2",cm),_p("toBvec2",dm),_p("toVec3",pm),_p("toIvec3",mm),_p("toUvec3",gm),_p("toBvec3",fm),_p("toVec4",ym),_p("toIvec4",xm),_p("toUvec4",bm),_p("toBvec4",vm),_p("toMat2",Tm),_p("toImat2",_m),_p("toUmat2",wm),_p("toBmat2",Sm),_p("toMat3",Mm),_p("toImat3",Am),_p("toUmat3",Nm),_p("toBmat3",Rm),_p("toMat4",Cm),_p("toImat4",Em),_p("toUmat4",Bm),_p("toBmat4",Im);const Um=Zp(dp),Om=(t,e)=>Xp(new pp(Xp(t),e)),Lm=(t,e)=>Xp(new fp(Xp(t),e));_p("element",Um),_p("convert",Om);class zm extends cp{constructor(t,e){super(),this.targetNode=t,this.sourceNode=e}hasDependencies(){return!1}getNodeType(t,e){return"void"!==e?this.targetNode.getNodeType(t):"void"}needsSplitAssign(t){const{targetNode:e}=this;if(!1===t.isAvailable("swizzleAssign")&&e.isSplitNode&&e.components.length>1){const s=t.getTypeLength(e.node.getNodeType(t));return Qd.join("").slice(0,s)!==e.components}return!1}generate(t,e){const{targetNode:s,sourceNode:i}=this,r=this.needsSplitAssign(t),n=s.getNodeType(t),o=s.context({assign:!0}).build(t),a=i.build(t,n),h=i.getNodeType(t),u=t.getDataFromNode(this);let l;if(!0===u.initialized)"void"!==e&&(l=o);else if(r){const i=t.getVarFromNode(this,null,n),r=t.getPropertyName(i);t.addLineFlowCode(`${r} = ${a}`);const h=s.node.context({assign:!0}).build(t);for(let e=0;eXp(new Gm(t,e,Xp(s)));up("AttributeNode",Gm);class jm extends hp{constructor(t,e){super(),this.isBypassNode=!0,this.outputNode=t,this.callNode=e}getNodeType(t){return this.outputNode.getNodeType(t)}generate(t){const e=this.callNode.build(t,"void");return""!==e&&t.addLineFlowCode(e),this.outputNode.build(t)}}const Hm=Zp(jm);_p("bypass",Hm),up("BypassNode",jm);class qm extends hp{constructor(t,e=!0){super(),this.node=t,this.parent=e,this.isCacheNode=!0}getNodeType(t){return this.node.getNodeType(t)}build(t,...e){const s=t.getCache(),i=t.getCacheFromNode(this,parent);t.setCache(i);const r=this.node.build(t,...e);return t.setCache(s),r}}const $m=(t,...e)=>Xp(new qm(Xp(t),...e));_p("cache",$m),up("CacheNode",qm);class Xm extends hp{constructor(t,e={}){super(),this.isContextNode=!0,this.node=t,this.context=e}getNodeType(t){return this.node.getNodeType(t)}analyze(t){this.node.build(t)}setup(t){const e=t.getContext();t.setContext({...t.context,...this.context});const s=this.node.build(t);return t.setContext(e),s}generate(t,e){const s=t.getContext();t.setContext({...t.context,...this.context});const i=this.node.build(t,e);return t.setContext(s),i}}const Ym=Zp(Xm),Jm=(t,e)=>Ym(t,{label:e});_p("context",Ym),_p("label",Jm),up("ContextNode",Xm);class Zm extends hp{constructor(t){super("uint"),this.scope=t,this.isInstanceIndexNode=!0}generate(t){const e=this.getNodeType(t),s=this.scope;let i,r;if(s===Zm.VERTEX)i=t.getVertexIndex();else if(s===Zm.INSTANCE)i=t.getInstanceIndex();else{if(s!==Zm.DRAW)throw new Error("THREE.IndexNode: Unknown scope: "+s);i=t.getDrawIndex()}if("vertex"===t.shaderStage||"compute"===t.shaderStage)r=i;else{r=km(this).build(t,e)}return r}}Zm.VERTEX="vertex",Zm.INSTANCE="instance",Zm.DRAW="draw";const Qm=Qp(Zm,Zm.VERTEX),Km=Qp(Zm,Zm.INSTANCE),tg=Qp(Zm,Zm.DRAW);up("IndexNode",Zm);class eg{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class sg extends hp{constructor(t,e=null){super(),this.node=t,this.name=e,this.global=!0,this.isVarNode=!0}getHash(t){return this.name||super.getHash(t)}getNodeType(t){return this.node.getNodeType(t)}generate(t){const{node:e,name:s}=this,i=t.getVarFromNode(this,s,t.getVectorType(this.getNodeType(t))),r=t.getPropertyName(i),n=e.build(t,i.type);return t.addLineFlowCode(`${r} = ${n}`),r}}const ig=Zp(sg);_p("temp",ig),_p("toVar",((...t)=>ig(...t).append())),up("VarNode",sg);class rg{constructor(t,e,s=null){this.isNodeAttribute=!0,this.name=t,this.type=e,this.node=s}}class ng{constructor(t,e,s){this.isNodeUniform=!0,this.name=t,this.type=e,this.node=s.getSelf()}get value(){return this.node.value}set value(t){this.node.value=t}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class og{constructor(t,e){this.isNodeVar=!0,this.name=t,this.type=e}}class ag extends og{constructor(t,e){super(t,e),this.needsInterpolation=!1,this.isNodeVarying=!0}}class hg{constructor(t,e,s=""){this.name=t,this.type=e,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}class ug{constructor(){this.keywords=[],this.nodes={},this.keywordsCallback={}}getNode(t){let e=this.nodes[t];return void 0===e&&void 0!==this.keywordsCallback[t]&&(e=this.keywordsCallback[t](t),this.nodes[t]=e),e}addKeyword(t,e){return this.keywords.push(t),this.keywordsCallback[t]=e,this}parse(t){const e=this.keywords,s=new RegExp(`\\b${e.join("\\b|\\b")}\\b`,"g"),i=t.match(s),r=[];if(null!==i)for(const t of i){const e=this.getNode(t);void 0!==e&&-1===r.indexOf(e)&&r.push(e)}return r}include(t,e){const s=this.parse(e);for(const e of s)e.build(t)}}let lg=0;class cg{constructor(t=null){this.id=lg++,this.nodesData=new WeakMap,this.parent=t}getData(t){let e=this.nodesData.get(t);return void 0===e&&null!==this.parent&&(e=this.parent.getData(t)),e}setData(t,e){this.nodesData.set(t,e)}}class dg extends hp{constructor(t,e=null,s=!1){super(t),this.name=e,this.varying=s,this.isPropertyNode=!0}getHash(t){return this.name||super.getHash(t)}isGlobal(){return!0}generate(t){let e;return!0===this.varying?(e=t.getVaryingFromNode(this,this.name),e.needsInterpolation=!0):e=t.getVarFromNode(this,this.name),t.getPropertyName(e)}}const pg=(t,e)=>Xp(new dg(t,e)),mg=(t,e)=>Xp(new dg(t,e,!0)),gg=Qp(dg,"vec4","DiffuseColor"),fg=Qp(dg,"vec3","EmissiveColor"),yg=Qp(dg,"float","Roughness"),xg=Qp(dg,"float","Metalness"),bg=Qp(dg,"float","Clearcoat"),vg=Qp(dg,"float","ClearcoatRoughness"),Tg=Qp(dg,"vec3","Sheen"),_g=Qp(dg,"float","SheenRoughness"),wg=Qp(dg,"float","Iridescence"),Sg=Qp(dg,"float","IridescenceIOR"),Mg=Qp(dg,"float","IridescenceThickness"),Ag=Qp(dg,"float","AlphaT"),Ng=Qp(dg,"float","Anisotropy"),Rg=Qp(dg,"vec3","AnisotropyT"),Cg=Qp(dg,"vec3","AnisotropyB"),Eg=Qp(dg,"color","SpecularColor"),Bg=Qp(dg,"float","SpecularF90"),Ig=Qp(dg,"float","Shininess"),Pg=Qp(dg,"vec4","Output"),Fg=Qp(dg,"float","dashSize"),Ug=Qp(dg,"float","gapSize"),Og=Qp(dg,"float","pointWidth"),Lg=Qp(dg,"float","IOR"),zg=Qp(dg,"float","Transmission"),Vg=Qp(dg,"float","Thickness"),Dg=Qp(dg,"float","AttenuationDistance"),kg=Qp(dg,"color","AttenuationColor"),Gg=Qp(dg,"float","Dispersion");up("PropertyNode",dg);class Wg extends dg{constructor(t,e=null){super(t,e),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const jg=(t,e)=>Xp(new Wg(t,e));up("ParameterNode",Wg);class Hg extends hp{constructor(t="",e=[],s=""){super("code"),this.isCodeNode=!0,this.code=t,this.language=s,this.includes=e}isGlobal(){return!0}setIncludes(t){return this.includes=t,this}getIncludes(){return this.includes}generate(t){const e=this.getIncludes(t);for(const s of e)s.build(t);const s=t.getCodeFromNode(this,this.getNodeType(t));return s.code=this.code,s.code}serialize(t){super.serialize(t),t.code=this.code,t.language=this.language}deserialize(t){super.deserialize(t),this.code=t.code,this.language=t.language}}const qg=Zp(Hg),$g=(t,e)=>qg(t,e,"js"),Xg=(t,e)=>qg(t,e,"wgsl"),Yg=(t,e)=>qg(t,e,"glsl");up("CodeNode",Hg);class Jg extends Hg{constructor(t="",e=[],s=""){super(t,e,s),this.keywords={}}getNodeType(t){return this.getNodeFunction(t).type}getInputs(t){return this.getNodeFunction(t).inputs}getNodeFunction(t){const e=t.getDataFromNode(this);let s=e.nodeFunction;return void 0===s&&(s=t.parser.parseFunction(this.code),e.nodeFunction=s),s}generate(t,e){super.generate(t);const s=this.getNodeFunction(t),i=s.name,r=s.type,n=t.getCodeFromNode(this,r);""!==i&&(n.name=i);const o=t.getPropertyName(n);let a=this.getNodeFunction(t).getCode(o);const h=this.keywords,u=Object.keys(h);if(u.length>0)for(const e of u){const s=new RegExp(`\\b${e}\\b`,"g"),i=h[e].build(t,"property");a=a.replace(s,i)}return n.code=a+"\n","property"===e?o:t.format(`${o}()`,r,e)}}const Zg=(t,e=[],s="")=>{for(let t=0;ti.call(...t);return r.functionNode=i,r},Qg=(t,e)=>Zg(t,e,"glsl"),Kg=(t,e)=>Zg(t,e,"wgsl");up("FunctionNode",Jg);class tf extends hp{constructor(t,e=!1){super("string"),this.name=t,this.version=0,this.shared=e,this.isUniformGroup=!0}set needsUpdate(t){!0===t&&this.version++}}const ef=t=>new tf(t),sf=t=>new tf(t,!0),rf=sf("frame"),nf=sf("render"),of=ef("object");up("UniformGroupNode",tf);class af extends xp{constructor(t,e=null){super(t,e),this.isUniformNode=!0,this.name="",this.groupNode=of}label(t){return this.name=t,this}setGroup(t){return this.groupNode=t,this}getGroup(){return this.groupNode}getUniformHash(t){return this.getHash(t)}onUpdate(t,e){const s=this.getSelf();return t=t.bind(s),super.onUpdate((e=>{const i=t(e,s);void 0!==i&&(this.value=i)}),e)}generate(t,e){const s=this.getNodeType(t),i=this.getUniformHash(t);let r=t.getNodeFromHash(i);void 0===r&&(t.setHashNode(this,i),r=this);const n=r.getInputType(t),o=t.getUniformFromNode(r,n,t.shaderStage,this.name||t.context.label),a=t.getPropertyName(o);return void 0!==t.context.label&&delete t.context.label,t.format(a,s,e)}}const hf=(t,e)=>{const s=qp(e||t),i=t&&!0===t.isNode?t.node&&t.node.value||t.value:t;return Xp(new af(i,s))};up("UniformNode",af);const uf=t=>Wm("uv"+(t>0?t:""),"vec2");class lf extends hp{constructor(t,e=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=t,this.levelNode=e}generate(t,e){const s=this.textureNode.build(t,"property"),i=this.levelNode.build(t,"int");return t.format(`${t.getMethod("textureDimensions")}( ${s}, ${i} )`,this.getNodeType(t),e)}}const cf=Zp(lf);_p("textureSize",cf),up("TextureSizeNode",lf);class df extends cp{constructor(t,e,s,...i){if(super(),i.length>0){let r=new df(t,e,s);for(let e=0;e>"===s||"<<"===s)return t.getIntegerType(n);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=e?t.getTypeLength(e):Math.max(t.getTypeLength(n),t.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===n&&t.isMatrix(o)?o:t.isMatrix(n)&&t.isVector(o)?t.getVectorFromMatrix(n):t.isVector(n)&&t.isMatrix(o)?t.getVectorFromMatrix(o):t.getTypeLength(o)>t.getTypeLength(n)?o:n}generate(t,e){const s=this.op,i=this.aNode,r=this.bNode,n=this.getNodeType(t,e);let o=null,a=null;"void"!==n?(o=i.getNodeType(t),a=void 0!==r?r.getNodeType(t):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?t.isVector(o)?a=o:o=a="float":">>"===s||"<<"===s?(o=n,a=t.changeComponentType(a,"uint")):t.isMatrix(o)&&t.isVector(a)?a=t.getVectorFromMatrix(o):o=t.isVector(o)&&t.isMatrix(a)?t.getVectorFromMatrix(a):a=n):o=a=n;const h=i.build(t,o),u=void 0!==r?r.build(t,a):null,l=t.getTypeLength(e),c=t.getFunctionOperator(s);return"void"!==e?"<"===s&&l>1?t.format(`${t.getMethod("lessThan")}( ${h}, ${u} )`,n,e):"<="===s&&l>1?t.format(`${t.getMethod("lessThanEqual")}( ${h}, ${u} )`,n,e):">"===s&&l>1?t.format(`${t.getMethod("greaterThan")}( ${h}, ${u} )`,n,e):">="===s&&l>1?t.format(`${t.getMethod("greaterThanEqual")}( ${h}, ${u} )`,n,e):"!"===s||"~"===s?t.format(`(${s}${h})`,o,e):c?t.format(`${c}( ${h}, ${u} )`,n,e):t.format(`( ${h} ${s} ${u} )`,n,e):"void"!==o?c?t.format(`${c}( ${h}, ${u} )`,n,e):t.format(`${h} ${s} ${u}`,n,e):void 0}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}}const pf=Zp(df,"+"),mf=Zp(df,"-"),gf=Zp(df,"*"),ff=Zp(df,"/"),yf=Zp(df,"%"),xf=Zp(df,"=="),bf=Zp(df,"!="),vf=Zp(df,"<"),Tf=Zp(df,">"),_f=Zp(df,"<="),wf=Zp(df,">="),Sf=Zp(df,"&&"),Mf=Zp(df,"||"),Af=Zp(df,"!"),Nf=Zp(df,"^^"),Rf=Zp(df,"&"),Cf=Zp(df,"~"),Ef=Zp(df,"|"),Bf=Zp(df,"^"),If=Zp(df,"<<"),Pf=Zp(df,">>");_p("add",pf),_p("sub",mf),_p("mul",gf),_p("div",ff),_p("remainder",yf),_p("equal",xf),_p("notEqual",bf),_p("lessThan",vf),_p("greaterThan",Tf),_p("lessThanEqual",_f),_p("greaterThanEqual",wf),_p("and",Sf),_p("or",Mf),_p("not",Af),_p("xor",Nf),_p("bitAnd",Rf),_p("bitNot",Cf),_p("bitOr",Ef),_p("bitXor",Bf),_p("shiftLeft",If),_p("shiftRight",Pf),up("OperatorNode",df);class Ff extends cp{constructor(t,e,s=null,i=null){super(),this.method=t,this.aNode=e,this.bNode=s,this.cNode=i}getInputType(t){const e=this.aNode.getNodeType(t),s=this.bNode?this.bNode.getNodeType(t):null,i=this.cNode?this.cNode.getNodeType(t):null,r=t.isMatrix(e)?0:t.getTypeLength(e),n=t.isMatrix(s)?0:t.getTypeLength(s),o=t.isMatrix(i)?0:t.getTypeLength(i);return r>n&&r>o?e:n>o?s:o>r?i:e}getNodeType(t){const e=this.method;return e===Ff.LENGTH||e===Ff.DISTANCE||e===Ff.DOT?"float":e===Ff.CROSS?"vec3":e===Ff.ALL?"bool":e===Ff.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):e===Ff.MOD?this.aNode.getNodeType(t):this.getInputType(t)}generate(t,e){const s=this.method,i=this.getNodeType(t),r=this.getInputType(t),n=this.aNode,o=this.bNode,a=this.cNode,h=!0===t.renderer.isWebGLRenderer;if(s===Ff.TRANSFORM_DIRECTION){let s=n,i=o;t.isMatrix(s.getNodeType(t))?i=ym(pm(i),0):s=ym(pm(s),0);const r=gf(s,i).xyz;return Qf(r).build(t,e)}if(s===Ff.NEGATE)return t.format("( - "+n.build(t,r)+" )",i,e);if(s===Ff.ONE_MINUS)return mf(1,n).build(t,e);if(s===Ff.RECIPROCAL)return ff(1,n).build(t,e);if(s===Ff.DIFFERENCE)return oy(mf(n,o)).build(t,e);{const u=[];return s===Ff.CROSS||s===Ff.MOD?u.push(n.build(t,i),o.build(t,i)):s===Ff.STEP?u.push(n.build(t,1===t.getTypeLength(n.getNodeType(t))?"float":r),o.build(t,r)):h&&(s===Ff.MIN||s===Ff.MAX)||s===Ff.MOD?u.push(n.build(t,r),o.build(t,1===t.getTypeLength(o.getNodeType(t))?"float":r)):s===Ff.REFRACT?u.push(n.build(t,r),o.build(t,r),a.build(t,"float")):s===Ff.MIX?u.push(n.build(t,r),o.build(t,r),a.build(t,1===t.getTypeLength(a.getNodeType(t))?"float":r)):(u.push(n.build(t,r)),null!==o&&u.push(o.build(t,r)),null!==a&&u.push(a.build(t,r))),t.format(`${t.getMethod(s,i)}( ${u.join(", ")} )`,i,e)}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}Ff.ALL="all",Ff.ANY="any",Ff.EQUALS="equals",Ff.RADIANS="radians",Ff.DEGREES="degrees",Ff.EXP="exp",Ff.EXP2="exp2",Ff.LOG="log",Ff.LOG2="log2",Ff.SQRT="sqrt",Ff.INVERSE_SQRT="inversesqrt",Ff.FLOOR="floor",Ff.CEIL="ceil",Ff.NORMALIZE="normalize",Ff.FRACT="fract",Ff.SIN="sin",Ff.COS="cos",Ff.TAN="tan",Ff.ASIN="asin",Ff.ACOS="acos",Ff.ATAN="atan",Ff.ABS="abs",Ff.SIGN="sign",Ff.LENGTH="length",Ff.NEGATE="negate",Ff.ONE_MINUS="oneMinus",Ff.DFDX="dFdx",Ff.DFDY="dFdy",Ff.ROUND="round",Ff.RECIPROCAL="reciprocal",Ff.TRUNC="trunc",Ff.FWIDTH="fwidth",Ff.BITCAST="bitcast",Ff.TRANSPOSE="transpose",Ff.ATAN2="atan2",Ff.MIN="min",Ff.MAX="max",Ff.MOD="mod",Ff.STEP="step",Ff.REFLECT="reflect",Ff.DISTANCE="distance",Ff.DIFFERENCE="difference",Ff.DOT="dot",Ff.CROSS="cross",Ff.POW="pow",Ff.TRANSFORM_DIRECTION="transformDirection",Ff.MIX="mix",Ff.CLAMP="clamp",Ff.REFRACT="refract",Ff.SMOOTHSTEP="smoothstep",Ff.FACEFORWARD="faceforward";const Uf=nm(1e-6),Of=nm(1e6),Lf=nm(Math.PI),zf=nm(2*Math.PI),Vf=Zp(Ff,Ff.ALL),Df=Zp(Ff,Ff.ANY),kf=Zp(Ff,Ff.EQUALS),Gf=Zp(Ff,Ff.RADIANS),Wf=Zp(Ff,Ff.DEGREES),jf=Zp(Ff,Ff.EXP),Hf=Zp(Ff,Ff.EXP2),qf=Zp(Ff,Ff.LOG),$f=Zp(Ff,Ff.LOG2),Xf=Zp(Ff,Ff.SQRT),Yf=Zp(Ff,Ff.INVERSE_SQRT),Jf=Zp(Ff,Ff.FLOOR),Zf=Zp(Ff,Ff.CEIL),Qf=Zp(Ff,Ff.NORMALIZE),Kf=Zp(Ff,Ff.FRACT),ty=Zp(Ff,Ff.SIN),ey=Zp(Ff,Ff.COS),sy=Zp(Ff,Ff.TAN),iy=Zp(Ff,Ff.ASIN),ry=Zp(Ff,Ff.ACOS),ny=Zp(Ff,Ff.ATAN),oy=Zp(Ff,Ff.ABS),ay=Zp(Ff,Ff.SIGN),hy=Zp(Ff,Ff.LENGTH),uy=Zp(Ff,Ff.NEGATE),ly=Zp(Ff,Ff.ONE_MINUS),cy=Zp(Ff,Ff.DFDX),dy=Zp(Ff,Ff.DFDY),py=Zp(Ff,Ff.ROUND),my=Zp(Ff,Ff.RECIPROCAL),gy=Zp(Ff,Ff.TRUNC),fy=Zp(Ff,Ff.FWIDTH),yy=Zp(Ff,Ff.BITCAST),xy=Zp(Ff,Ff.TRANSPOSE),by=Zp(Ff,Ff.ATAN2),vy=Zp(Ff,Ff.MIN),Ty=Zp(Ff,Ff.MAX),_y=Zp(Ff,Ff.MOD),wy=Zp(Ff,Ff.STEP),Sy=Zp(Ff,Ff.REFLECT),My=Zp(Ff,Ff.DISTANCE),Ay=Zp(Ff,Ff.DIFFERENCE),Ny=Zp(Ff,Ff.DOT),Ry=Zp(Ff,Ff.CROSS),Cy=Zp(Ff,Ff.POW),Ey=Zp(Ff,Ff.POW,2),By=Zp(Ff,Ff.POW,3),Iy=Zp(Ff,Ff.POW,4),Py=Zp(Ff,Ff.TRANSFORM_DIRECTION),Fy=t=>gf(ay(t),Cy(oy(t),1/3)),Uy=t=>Ny(t,t),Oy=Zp(Ff,Ff.MIX),Ly=(t,e=0,s=1)=>Xp(new Ff(Ff.CLAMP,Xp(t),Xp(e),Xp(s))),zy=t=>Ly(t),Vy=Zp(Ff,Ff.REFRACT),Dy=Zp(Ff,Ff.SMOOTHSTEP),ky=Zp(Ff,Ff.FACEFORWARD),Gy=Kp((([t])=>{const e=Ny(t.xy,um(12.9898,78.233)),s=_y(e,Lf);return Kf(ty(s).mul(43758.5453))}));_p("all",Vf),_p("any",Df),_p("equals",kf),_p("radians",Gf),_p("degrees",Wf),_p("exp",jf),_p("exp2",Hf),_p("log",qf),_p("log2",$f),_p("sqrt",Xf),_p("inverseSqrt",Yf),_p("floor",Jf),_p("ceil",Zf),_p("normalize",Qf),_p("fract",Kf),_p("sin",ty),_p("cos",ey),_p("tan",sy),_p("asin",iy),_p("acos",ry),_p("atan",ny),_p("abs",oy),_p("sign",ay),_p("length",hy),_p("lengthSq",Uy),_p("negate",uy),_p("oneMinus",ly),_p("dFdx",cy),_p("dFdy",dy),_p("round",py),_p("reciprocal",my),_p("trunc",gy),_p("fwidth",fy),_p("atan2",by),_p("min",vy),_p("max",Ty),_p("mod",_y),_p("step",wy),_p("reflect",Sy),_p("distance",My),_p("dot",Ny),_p("cross",Ry),_p("pow",Cy),_p("pow2",Ey),_p("pow3",By),_p("pow4",Iy),_p("transformDirection",Py),_p("mix",((t,e,s)=>Oy(e,s,t))),_p("clamp",Ly),_p("refract",Vy),_p("smoothstep",((t,e,s)=>Dy(e,s,t))),_p("faceForward",ky),_p("difference",Ay),_p("saturate",zy),_p("cbrt",Fy),_p("transpose",xy),_p("rand",Gy),up("MathNode",Ff);const Wy=Kp((t=>{const{value:e}=t,{rgb:s}=e,i=s.mul(.9478672986).add(.0521327014).pow(2.4),r=s.mul(.0773993808),n=s.lessThanEqual(.04045),o=Oy(i,r,n);return ym(o,e.a)})),jy=Kp((t=>{const{value:e}=t,{rgb:s}=e,i=s.pow(.41666).mul(1.055).sub(.055),r=s.mul(12.92),n=s.lessThanEqual(.0031308),o=Oy(i,r,n);return ym(o,e.a)})),Hy=t=>{let e=null;return t===Ze?e="Linear":t===Je&&(e="sRGB"),e},qy=(t,e)=>Hy(t)+"To"+Hy(e);class $y extends cp{constructor(t,e){super("vec4"),this.method=t,this.node=e}setup(){const{method:t,node:e}=this;return t===$y.LINEAR_TO_LINEAR?e:Xy[t]({value:e})}}$y.LINEAR_TO_LINEAR="LinearToLinear",$y.LINEAR_TO_sRGB="LinearTosRGB",$y.sRGB_TO_LINEAR="sRGBToLinear";const Xy={[$y.LINEAR_TO_sRGB]:jy,[$y.sRGB_TO_LINEAR]:Wy},Yy=(t,e)=>Xp(new $y(qy(Ze,e),Xp(t))),Jy=(t,e)=>Xp(new $y(qy(e,Ze),Xp(t))),Zy=Zp($y,$y.LINEAR_TO_sRGB),Qy=Zp($y,$y.sRGB_TO_LINEAR);_p("linearTosRGB",Zy),_p("sRGBToLinear",Qy),_p("linearToColorSpace",Yy),_p("colorSpaceToLinear",Jy),up("ColorSpaceNode",$y);class Ky extends hp{constructor(t="",e="void"){super(e),this.snippet=t}generate(t,e){const s=this.getNodeType(t),i=this.snippet;if("void"!==s)return t.format(`( ${i} )`,s,e);t.addLineFlowCode(i)}}const tx=Zp(Ky);up("ExpressionNode",Ky);class ex extends af{constructor(t){super(0),this._textureNode=t,this.updateType=$d.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const t=this.texture,e=t.images,s=e&&e.length>0?e[0]&&e[0].image||e[0]:t.image;if(s&&void 0!==s.width){const{width:t,height:e}=s;this.value=Math.log2(Math.max(t,e))}}}const sx=Zp(ex);up("MaxMipLevelNode",ex);class ix extends af{constructor(t,e=null,s=null,i=null){super(t),this.isTextureNode=!0,this.uvNode=e,this.levelNode=s,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=$d.NONE,this.referenceNode=null,this._value=t,this._matrixUniform=null,this.setUpdateMatrix(null===e)}set value(t){this.referenceNode?this.referenceNode.value=t:this._value=t}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===Bt?"uvec4":this.value.type===Et?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return uf(this.value.channel)}updateReference(){return this.value}getTransformedUV(t){return null===this._matrixUniform&&(this._matrixUniform=hf(this.value.matrix)),this._matrixUniform.mul(pm(t,1)).xy}setUpdateMatrix(t){return this.updateMatrix=t,this.updateType=t?$d.FRAME:$d.NONE,this}setupUV(t,e){const s=this.value;return!t.isFlipY()||!0!==s.isRenderTargetTexture&&!0!==s.isFramebufferTexture&&!0!==s.isDepthTexture||(e=e.setY(e.y.oneMinus())),e}setup(t){const e=t.getNodeProperties(this);e.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==t.context.forceUVContext||!t.context.getUV||(s=t.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(t,s);let i=this.levelNode;null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),e.uvNode=s,e.levelNode=i,e.biasNode=this.biasNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.depthNode=this.depthNode}generateUV(t,e){return e.build(t,!0===this.sampler?"vec2":"ivec2")}generateSnippet(t,e,s,i,r,n,o,a){const h=this.value;let u;return u=i?t.generateTextureLevel(h,e,s,i,n):r?t.generateTextureBias(h,e,s,r,n):a?t.generateTextureGrad(h,e,s,a,n):o?t.generateTextureCompare(h,e,s,o,n):!1===this.sampler?t.generateTextureLoad(h,e,s,n):t.generateTexture(h,e,s,n),u}generate(t,e){const s=t.getNodeProperties(this),i=this.value;if(!i||!0!==i.isTexture)throw new Error("TextureNode: Need a three.js texture.");const r=super.generate(t,"property");if("sampler"===e)return r+"_sampler";if(t.isReference(e))return r;{const n=t.getDataFromNode(this);let o=n.propertyName;if(void 0===o){const{uvNode:e,levelNode:i,biasNode:a,compareNode:h,depthNode:u,gradNode:l}=s,c=this.generateUV(t,e),d=i?i.build(t,"float"):null,p=a?a.build(t,"float"):null,m=u?u.build(t,"int"):null,g=h?h.build(t,"float"):null,f=l?[l[0].build(t,"vec2"),l[1].build(t,"vec2")]:null,y=t.getVarFromNode(this);o=t.getPropertyName(y);const x=this.generateSnippet(t,r,c,d,p,m,g,f);t.addLineFlowCode(`${o} = ${x}`),n.snippet=x,n.propertyName=o}let a=o;const h=this.getNodeType(t);return t.needsColorSpaceToLinear(i)&&(a=Jy(tx(a,h),i.colorSpace).setup(t).build(t,h)),t.format(a,h,e)}}setSampler(t){return this.sampler=t,this}getSampler(){return this.sampler}uv(t){const e=this.clone();return e.uvNode=Xp(t),e.referenceNode=this,Xp(e)}blur(t){const e=this.clone();return e.biasNode=Xp(t).mul(sx(e)),e.referenceNode=this,Xp(e)}level(t){const e=this.clone();return e.levelNode=Xp(t),e.referenceNode=this,Xp(e)}size(t){return cf(this,t)}bias(t){const e=this.clone();return e.biasNode=Xp(t),e.referenceNode=this,Xp(e)}compare(t){const e=this.clone();return e.compareNode=Xp(t),e.referenceNode=this,Xp(e)}grad(t,e){const s=this.clone();return s.gradNode=[Xp(t),Xp(e)],s.referenceNode=this,Xp(s)}depth(t){const e=this.clone();return e.depthNode=Xp(t),e.referenceNode=this,Xp(e)}serialize(t){super.serialize(t),t.value=this.value.toJSON(t.meta).uuid}deserialize(t){super.deserialize(t),this.value=t.meta.textures[t.value]}update(){const t=this.value,e=this._matrixUniform;null!==e&&(e.value=t.matrix),!0===t.matrixAutoUpdate&&t.updateMatrix()}clone(){const t=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return t.sampler=this.sampler,t}}const rx=Zp(ix),nx=(...t)=>rx(...t).setSampler(!1),ox=t=>(!0===t.isNode?t:rx(t)).convert("sampler");_p("texture",rx),up("TextureNode",ix);class ax extends af{constructor(t,e,s=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferCount=s}getElementType(t){return this.getNodeType(t)}getInputType(){return"buffer"}}const hx=(t,e,s)=>Xp(new ax(t,e,s));up("BufferNode",ax);class ux extends dp{constructor(t,e){super(t,e),this.isArrayBufferElementNode=!0}getNodeType(t){return this.node.getElementType(t)}generate(t){const e=super.generate(t),s=this.getNodeType();return t.format(e,"vec4",s)}}class lx extends ax{constructor(t,e=null){super(null,"vec4"),this.array=t,this.elementType=e,this._elementType=null,this._elementLength=0,this.updateType=$d.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:t,value:e}=this,s=this.getElementLength(),i=this.getElementType();if(1===s)for(let s=0;sXp(new lx(t,e));up("UniformsNode",lx);class dx extends dp{constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),s=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,s,i)}}class px extends hp{constructor(t,e,s=null,i=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=i,this.properties=t.split("."),this.reference=null,this.node=null,this.updateType=$d.OBJECT}element(t){return Xp(new dx(this,Xp(t)))}setNodeType(t){let e=null;e=null!==this.count?hx(null,t,this.count):Array.isArray(this.getValueFromReference())?cx(null,t):"texture"===t?rx(null):hf(null,t),this.node=e}getNodeType(t){return null===this.node&&this.updateValue(),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let s=t[e[0]];for(let t=1;tXp(new px(t,e,s)),gx=(t,e,s,i)=>Xp(new px(t,e,i,s));up("ReferenceNode",px);class fx extends px{constructor(t,e,s=null){super(t,e,s),this.material=s}updateReference(t){return this.reference=null!==this.material?this.material:t.material,this.reference}}const yx=(t,e,s)=>Xp(new fx(t,e,s));up("MaterialReferenceNode",fx);const xx=sf("camera").onRenderUpdate((()=>{xx.needsUpdate=!0})),bx=hf("float").label("cameraNear").setGroup(xx).onRenderUpdate((({camera:t})=>t.near)),vx=hf("float").label("cameraFar").setGroup(xx).onRenderUpdate((({camera:t})=>t.far)),Tx=hf("float").label("cameraLogDepth").setGroup(xx).onRenderUpdate((({camera:t})=>2/(Math.log(t.far+1)/Math.LN2))),_x=hf("mat4").label("cameraProjectionMatrix").setGroup(xx).onRenderUpdate((({camera:t})=>t.projectionMatrix)),wx=hf("mat4").label("cameraProjectionMatrixInverse").setGroup(xx).onRenderUpdate((({camera:t})=>t.projectionMatrixInverse)),Sx=hf("mat4").label("cameraViewMatrix").setGroup(xx).onRenderUpdate((({camera:t})=>t.matrixWorldInverse)),Mx=hf("mat4").label("cameraWorldMatrix").setGroup(xx).onRenderUpdate((({camera:t})=>t.matrixWorld)),Ax=hf("mat3").label("cameraNormalMatrix").setGroup(xx).onRenderUpdate((({camera:t})=>t.normalMatrix)),Nx=hf(new Ei).label("cameraPosition").setGroup(xx).onRenderUpdate((({camera:t},e)=>e.value.setFromMatrixPosition(t.matrixWorld)));class Rx extends hp{constructor(t=Rx.VIEW_MATRIX,e=null){super(),this.scope=t,this.object3d=e,this.updateType=$d.OBJECT,this._uniformNode=new af(null)}getNodeType(){const t=this.scope;return t===Rx.WORLD_MATRIX||t===Rx.VIEW_MATRIX?"mat4":t===Rx.NORMAL_MATRIX?"mat3":t===Rx.POSITION||t===Rx.VIEW_POSITION||t===Rx.DIRECTION||t===Rx.SCALE?"vec3":void 0}update(t){const e=this.object3d,s=this._uniformNode,i=this.scope;if(i===Rx.VIEW_MATRIX)s.value=e.modelViewMatrix;else if(i===Rx.NORMAL_MATRIX)s.value=e.normalMatrix;else if(i===Rx.WORLD_MATRIX)s.value=e.matrixWorld;else if(i===Rx.POSITION)s.value=s.value||new Ei,s.value.setFromMatrixPosition(e.matrixWorld);else if(i===Rx.SCALE)s.value=s.value||new Ei,s.value.setFromMatrixScale(e.matrixWorld);else if(i===Rx.DIRECTION)s.value=s.value||new Ei,e.getWorldDirection(s.value);else if(i===Rx.VIEW_POSITION){const i=t.camera;s.value=s.value||new Ei,s.value.setFromMatrixPosition(e.matrixWorld),s.value.applyMatrix4(i.matrixWorldInverse)}}generate(t){const e=this.scope;return e===Rx.WORLD_MATRIX||e===Rx.VIEW_MATRIX?this._uniformNode.nodeType="mat4":e===Rx.NORMAL_MATRIX?this._uniformNode.nodeType="mat3":e!==Rx.POSITION&&e!==Rx.VIEW_POSITION&&e!==Rx.DIRECTION&&e!==Rx.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(t)}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}}Rx.VIEW_MATRIX="viewMatrix",Rx.NORMAL_MATRIX="normalMatrix",Rx.WORLD_MATRIX="worldMatrix",Rx.POSITION="position",Rx.SCALE="scale",Rx.VIEW_POSITION="viewPosition",Rx.DIRECTION="direction";const Cx=Zp(Rx,Rx.DIRECTION),Ex=Zp(Rx,Rx.VIEW_MATRIX),Bx=Zp(Rx,Rx.NORMAL_MATRIX),Ix=Zp(Rx,Rx.WORLD_MATRIX),Px=Zp(Rx,Rx.POSITION),Fx=Zp(Rx,Rx.SCALE),Ux=Zp(Rx,Rx.VIEW_POSITION);up("Object3DNode",Rx);class Ox extends Rx{constructor(t=Ox.VIEW_MATRIX){super(t)}update(t){this.object3d=t.object,super.update(t)}}const Lx=Qp(Ox,Ox.DIRECTION),zx=Qp(Ox,Ox.VIEW_MATRIX).label("modelViewMatrix").temp("ModelViewMatrix"),Vx=Qp(Ox,Ox.NORMAL_MATRIX),Dx=Qp(Ox,Ox.WORLD_MATRIX),kx=Qp(Ox,Ox.POSITION),Gx=Qp(Ox,Ox.SCALE),Wx=Qp(Ox,Ox.VIEW_POSITION),jx=hf(new or).onObjectUpdate((({object:t},e)=>e.value.copy(t.matrixWorld).invert()));up("ModelNode",Ox);const Hx=Wm("normal","vec3",pm(0,1,0)),qx=Hx.toVar("normalLocal"),$x=km(Vx.mul(qx),"v_normalView").normalize().toVar("normalView"),Xx=km($x.transformDirection(Sx),"v_normalWorld").normalize().toVar("normalWorld"),Yx=pg("vec3","transformedNormalView"),Jx=Yx.transformDirection(Sx).normalize().toVar("transformedNormalWorld"),Zx=pg("vec3","transformedClearcoatNormalView"),Qx=new Map;class Kx extends hp{constructor(t){super(),this.scope=t}getCache(t,e){let s=Qx.get(t);return void 0===s&&(s=yx(t,e),Qx.set(t,s)),s}getFloat(t){return this.getCache(t,"float")}getColor(t){return this.getCache(t,"color")}getTexture(t){return this.getCache("map"===t?"map":t+"Map","texture")}setup(t){const e=t.context.material,s=this.scope;let i=null;if(s===Kx.COLOR){const t=this.getColor(s);i=e.map&&!0===e.map.isTexture?t.mul(this.getTexture("map")):t}else if(s===Kx.OPACITY){const t=this.getFloat(s);i=e.alphaMap&&!0===e.alphaMap.isTexture?t.mul(this.getTexture("alpha")):t}else if(s===Kx.SPECULAR_STRENGTH)i=e.specularMap&&!0===e.specularMap.isTexture?this.getTexture("specular").r:nm(1);else if(s===Kx.SPECULAR_INTENSITY){const t=this.getFloat(s);i=e.specularMap?t.mul(this.getTexture(s).a):t}else if(s===Kx.SPECULAR_COLOR){const t=this.getColor(s);i=e.specularColorMap&&!0===e.specularColorMap.isTexture?t.mul(this.getTexture(s).rgb):t}else if(s===Kx.ROUGHNESS){const t=this.getFloat(s);i=e.roughnessMap&&!0===e.roughnessMap.isTexture?t.mul(this.getTexture(s).g):t}else if(s===Kx.METALNESS){const t=this.getFloat(s);i=e.metalnessMap&&!0===e.metalnessMap.isTexture?t.mul(this.getTexture(s).b):t}else if(s===Kx.EMISSIVE){const t=this.getColor(s);i=e.emissiveMap&&!0===e.emissiveMap.isTexture?t.mul(this.getTexture(s)):t}else if(s===Kx.NORMAL)i=e.normalMap?this.getTexture("normal").normalMap(this.getCache("normalScale","vec2")):e.bumpMap?this.getTexture("bump").r.bumpMap(this.getFloat("bumpScale")):$x;else if(s===Kx.CLEARCOAT){const t=this.getFloat(s);i=e.clearcoatMap&&!0===e.clearcoatMap.isTexture?t.mul(this.getTexture(s).r):t}else if(s===Kx.CLEARCOAT_ROUGHNESS){const t=this.getFloat(s);i=e.clearcoatRoughnessMap&&!0===e.clearcoatRoughnessMap.isTexture?t.mul(this.getTexture(s).r):t}else if(s===Kx.CLEARCOAT_NORMAL)i=e.clearcoatNormalMap?this.getTexture(s).normalMap(this.getCache(s+"Scale","vec2")):$x;else if(s===Kx.SHEEN){const t=this.getColor("sheenColor").mul(this.getFloat("sheen"));i=e.sheenColorMap&&!0===e.sheenColorMap.isTexture?t.mul(this.getTexture("sheenColor").rgb):t}else if(s===Kx.SHEEN_ROUGHNESS){const t=this.getFloat(s);i=e.sheenRoughnessMap&&!0===e.sheenRoughnessMap.isTexture?t.mul(this.getTexture(s).a):t,i=i.clamp(.07,1)}else if(s===Kx.ANISOTROPY)if(e.anisotropyMap&&!0===e.anisotropyMap.isTexture){const t=this.getTexture(s);i=Tm(zb.x,zb.y,zb.y.negate(),zb.x).mul(t.rg.mul(2).sub(um(1)).normalize().mul(t.b))}else i=zb;else if(s===Kx.IRIDESCENCE_THICKNESS){const t=mx("1","float",e.iridescenceThicknessRange);if(e.iridescenceThicknessMap){const r=mx("0","float",e.iridescenceThicknessRange);i=t.sub(r).mul(this.getTexture(s).g).add(r)}else i=t}else if(s===Kx.TRANSMISSION){const t=this.getFloat(s);i=e.transmissionMap?t.mul(this.getTexture(s).r):t}else if(s===Kx.THICKNESS){const t=this.getFloat(s);i=e.thicknessMap?t.mul(this.getTexture(s).g):t}else if(s===Kx.IOR)i=this.getFloat(s);else if(s===Kx.REFRACTION_RATIO)i=this.getFloat(s);else if(s===Kx.LIGHT_MAP)i=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===Kx.AO_MAP)i=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const e=this.getNodeType(t);i=this.getCache(s,e)}return i}}Kx.ALPHA_TEST="alphaTest",Kx.COLOR="color",Kx.OPACITY="opacity",Kx.SHININESS="shininess",Kx.SPECULAR="specular",Kx.SPECULAR_STRENGTH="specularStrength",Kx.SPECULAR_INTENSITY="specularIntensity",Kx.SPECULAR_COLOR="specularColor",Kx.REFLECTIVITY="reflectivity",Kx.ROUGHNESS="roughness",Kx.METALNESS="metalness",Kx.NORMAL="normal",Kx.CLEARCOAT="clearcoat",Kx.CLEARCOAT_ROUGHNESS="clearcoatRoughness",Kx.CLEARCOAT_NORMAL="clearcoatNormal",Kx.EMISSIVE="emissive",Kx.ROTATION="rotation",Kx.SHEEN="sheen",Kx.SHEEN_ROUGHNESS="sheenRoughness",Kx.ANISOTROPY="anisotropy",Kx.IRIDESCENCE="iridescence",Kx.IRIDESCENCE_IOR="iridescenceIOR",Kx.IRIDESCENCE_THICKNESS="iridescenceThickness",Kx.IOR="ior",Kx.TRANSMISSION="transmission",Kx.THICKNESS="thickness",Kx.ATTENUATION_DISTANCE="attenuationDistance",Kx.ATTENUATION_COLOR="attenuationColor",Kx.LINE_SCALE="scale",Kx.LINE_DASH_SIZE="dashSize",Kx.LINE_GAP_SIZE="gapSize",Kx.LINE_WIDTH="linewidth",Kx.LINE_DASH_OFFSET="dashOffset",Kx.POINT_WIDTH="pointWidth",Kx.DISPERSION="dispersion",Kx.LIGHT_MAP="light",Kx.AO_MAP="ao",Kx.REFRACTION_RATIO="refractionRatio";const tb=Qp(Kx,Kx.ALPHA_TEST),eb=Qp(Kx,Kx.COLOR),sb=Qp(Kx,Kx.SHININESS),ib=Qp(Kx,Kx.EMISSIVE),rb=Qp(Kx,Kx.OPACITY),nb=Qp(Kx,Kx.SPECULAR),ob=Qp(Kx,Kx.SPECULAR_INTENSITY),ab=Qp(Kx,Kx.SPECULAR_COLOR),hb=Qp(Kx,Kx.SPECULAR_STRENGTH),ub=Qp(Kx,Kx.REFLECTIVITY),lb=Qp(Kx,Kx.ROUGHNESS),cb=Qp(Kx,Kx.METALNESS),db=Qp(Kx,Kx.NORMAL),pb=Qp(Kx,Kx.CLEARCOAT),mb=Qp(Kx,Kx.CLEARCOAT_ROUGHNESS),gb=Qp(Kx,Kx.CLEARCOAT_NORMAL),fb=Qp(Kx,Kx.ROTATION),yb=Qp(Kx,Kx.SHEEN),xb=Qp(Kx,Kx.SHEEN_ROUGHNESS),bb=Qp(Kx,Kx.ANISOTROPY),vb=Qp(Kx,Kx.IRIDESCENCE),Tb=Qp(Kx,Kx.IRIDESCENCE_IOR),_b=Qp(Kx,Kx.IRIDESCENCE_THICKNESS),wb=Qp(Kx,Kx.TRANSMISSION),Sb=Qp(Kx,Kx.THICKNESS),Mb=Qp(Kx,Kx.IOR),Ab=Qp(Kx,Kx.ATTENUATION_DISTANCE),Nb=Qp(Kx,Kx.ATTENUATION_COLOR),Rb=Qp(Kx,Kx.LINE_SCALE),Cb=Qp(Kx,Kx.LINE_DASH_SIZE),Eb=Qp(Kx,Kx.LINE_GAP_SIZE),Bb=Qp(Kx,Kx.LINE_WIDTH),Ib=Qp(Kx,Kx.LINE_DASH_OFFSET),Pb=Qp(Kx,Kx.POINT_WIDTH),Fb=Qp(Kx,Kx.DISPERSION),Ub=Qp(Kx,Kx.LIGHT_MAP),Ob=Qp(Kx,Kx.AO_MAP),Lb=Qp(Kx,Kx.REFRACTION_RATIO),zb=hf(new Ks).onReference((function(t){return t.material})).onRenderUpdate((function({material:t}){this.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation))}));up("MaterialNode",Kx);const Vb=Wm("position","vec3"),Db=Vb.toVar("positionLocal"),kb=km(Dx.mul(Db).xyz,"v_positionWorld"),Gb=km(Db.transformDirection(Dx),"v_positionWorldDirection").normalize().toVar("positionWorldDirection"),Wb=km(zx.mul(Db).xyz,"v_positionView"),jb=km(Wb.negate(),"v_positionViewDirection").normalize().toVar("positionViewDirection");class Hb extends cp{constructor(t=null){super("vec4"),this.positionNode=t}setup(t){if("fragment"===t.shaderStage)return km(t.context.mvp);const e=this.positionNode||Db;return _x.mul(zx).mul(e)}}const qb=Zp(Hb);up("ModelViewProjectionNode",Hb);class $b extends xp{constructor(t,e=null,s=0,i=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferStride=s,this.bufferOffset=i,this.usage=Rs,this.instanced=!1,this.attribute=null,this.global=!0,t&&!0===t.isBufferAttribute&&(this.attribute=t,this.usage=t.usage,this.instanced=t.isInstancedBufferAttribute)}getHash(t){if(0===this.bufferStride&&0===this.bufferOffset){let e=t.globalCache.getData(this.value);return void 0===e&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getNodeType(t){return null===this.bufferType&&(this.bufferType=t.getTypeFromAttribute(this.attribute)),this.bufferType}setup(t){if(null!==this.attribute)return;const e=this.getNodeType(t),s=this.value,i=t.getTypeLength(e),r=this.bufferStride||i,n=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new oo(s,r),a=new ho(o,i,n);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(t){const e=this.getNodeType(t),s=t.getBufferAttributeFromNode(this,e),i=t.getPropertyName(s);let r=null;if("vertex"===t.shaderStage||"compute"===t.shaderStage)this.name=i,r=i;else{r=km(this).build(t,e)}return r}getInputType(){return"bufferAttribute"}setUsage(t){return this.usage=t,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=t),this}setInstanced(t){return this.instanced=t,this}}const Xb=(t,e,s,i)=>Xp(new $b(t,e,s,i)),Yb=(t,e,s,i)=>Xb(t,e,s,i).setUsage(Cs),Jb=(t,e,s,i)=>Xb(t,e,s,i).setInstanced(!0),Zb=(t,e,s,i)=>Yb(t,e,s,i).setInstanced(!0);_p("toAttribute",(t=>Xb(t.value))),up("BufferAttributeNode",$b);class Qb extends hp{constructor(t){super("void"),this.instanceMesh=t,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=$d.FRAME,this.buffer=null,this.bufferColor=null}setup(){let t=this.instanceMatrixNode;const e=this.instanceMesh;if(null===t){const s=e.instanceMatrix,i=new Nc(s.array,16,1);this.buffer=i;const r=s.usage===Cs?Zb:Jb,n=[r(i,"vec4",16,0),r(i,"vec4",16,4),r(i,"vec4",16,8),r(i,"vec4",16,12)];t=Cm(...n),this.instanceMatrixNode=t}const s=e.instanceColor;if(s&&null===this.instanceColorNode){const t=new jo(s.array,3),e=s.usage===Cs?Zb:Jb;this.bufferColor=t,this.instanceColorNode=pm(e(t,"vec3",3,0))}const i=t.mul(Db).xyz,r=Mm(t[0].xyz,t[1].xyz,t[2].xyz),n=qx.div(pm(r[0].dot(r[0]),r[1].dot(r[1]),r[2].dot(r[2]))),o=r.mul(n).xyz;Db.assign(i),qx.assign(o),null!==this.instanceColorNode&&mg("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==Cs&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==Cs&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const Kb=Zp(Qb);up("InstanceNode",Qb);const tv=Kp(((t,e)=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),Wm("tangent","vec4"))))(),ev=tv.xyz.toVar("tangentLocal"),sv=km(zx.mul(ym(ev,0)).xyz,"v_tangentView").normalize().toVar("tangentView"),iv=km(sv.transformDirection(Sx),"v_tangentWorld").normalize().toVar("tangentWorld"),rv=sv.toVar("transformedTangentView"),nv=rv.transformDirection(Sx).normalize().toVar("transformedTangentWorld");class ov extends hp{constructor(t){super("void"),this.batchMesh=t,this.instanceColorNode=null,this.batchingIdNode=null}setup(t){null===this.batchingIdNode&&(null===t.getDrawIndex()?this.batchingIdNode=Km:this.batchingIdNode=tg);const e=Kp((([t])=>{const e=cf(nx(this.batchMesh._indirectTexture),0),s=om(t).remainder(om(e)),i=om(t).div(om(e));return nx(this.batchMesh._indirectTexture,lm(s,i)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=this.batchMesh._matricesTexture,i=cf(nx(s),0),r=nm(e(om(this.batchingIdNode))).mul(4).toVar(),n=om(r.mod(i)),o=om(r).div(om(i)),a=Cm(nx(s,lm(n,o)),nx(s,lm(n.add(1),o)),nx(s,lm(n.add(2),o)),nx(s,lm(n.add(3),o))),h=Mm(a[0].xyz,a[1].xyz,a[2].xyz);Db.assign(a.mul(Db));const u=qx.div(pm(h[0].dot(h[0]),h[1].dot(h[1]),h[2].dot(h[2]))),l=h.mul(u).xyz;qx.assign(l),t.hasGeometryAttribute("tangent")&&ev.mulAssign(h)}}const av=Zp(ov);up("batch",ov);class hv extends hp{constructor(t,e=!1){let s,i,r;super("void"),this.skinnedMesh=t,this.useReference=e,this.updateType=$d.OBJECT,this.skinIndexNode=Wm("skinIndex","uvec4"),this.skinWeightNode=Wm("skinWeight","vec4"),e?(s=mx("bindMatrix","mat4"),i=mx("bindMatrixInverse","mat4"),r=gx("skeleton.boneMatrices","mat4",t.skeleton.bones.length)):(s=hf(t.bindMatrix,"mat4"),i=hf(t.bindMatrixInverse,"mat4"),r=hx(t.skeleton.boneMatrices,"mat4",t.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=i,this.boneMatricesNode=r}setup(t){const{skinIndexNode:e,skinWeightNode:s,bindMatrixNode:i,bindMatrixInverseNode:r,boneMatricesNode:n}=this,o=n.element(e.x),a=n.element(e.y),h=n.element(e.z),u=n.element(e.w),l=i.mul(Db),c=pf(o.mul(s.x).mul(l),a.mul(s.y).mul(l),h.mul(s.z).mul(l),u.mul(s.w).mul(l)),d=r.mul(c).xyz;let p=pf(s.x.mul(o),s.y.mul(a),s.z.mul(h),s.w.mul(u));p=r.mul(p).mul(i);const m=p.transformDirection(qx).xyz;Db.assign(d),qx.assign(m),t.hasGeometryAttribute("tangent")&&ev.assign(m)}generate(t,e){if("void"!==e)return Db.build(t,e)}update(t){(this.useReference?t.object:this.skinnedMesh).skeleton.update()}}const uv=t=>Xp(new hv(t)),lv=t=>Xp(new hv(t,!0));up("SkinningNode",hv);class cv extends hp{constructor(t=[]){super(),this.params=t}getVarName(t){return String.fromCharCode("i".charCodeAt()+t)}getProperties(t){const e=t.getNodeProperties(this);if(void 0!==e.stackNode)return e;const s={};for(let t=0,e=this.params.length-1;tNumber(n)?">=":"<"));const l={start:r,end:n,condition:h},c=l.start,d=l.end;let p="",m="",g="";u||(u="int"===a||"uint"===a?h.includes("<")?"++":"--":h.includes("<")?"+= 1.":"-= 1."),p+=t.getVar(a,o)+" = "+c,m+=o+" "+h+" "+d,g+=o+" "+u;const f=`for ( ${p}; ${m}; ${g} )`;t.addFlowCode((0===e?"\n":"")+t.tab+f+" {\n\n").addFlowTab()}const r=i.build(t,"void"),n=e.returnsNode?e.returnsNode.build(t):"";t.removeFlowTab().addFlowCode("\n"+t.tab+r);for(let e=0,s=this.params.length-1;eXp(new cv(Jp(t,"int"))).append(),pv=()=>tx("continue").append(),mv=()=>tx("break").append();_p("loop",((t,...e)=>Hm(t,dv(...e)))),up("LoopNode",cv);const gv=new WeakMap,fv=new _i,yv=Kp((({bufferMap:t,influence:e,stride:s,width:i,depth:r,offset:n})=>{const o=om(Qm).mul(s).add(n),a=o.div(i),h=o.sub(a.mul(i));return nx(t,lm(h,a)).depth(r).mul(e)}));class xv extends hp{constructor(t){super("void"),this.mesh=t,this.morphBaseInfluence=hf(1),this.updateType=$d.OBJECT}setup(t){const{geometry:e}=t,s=void 0!==e.morphAttributes.position,i=void 0!==e.morphAttributes.normal,r=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,n=void 0!==r?r.length:0,{texture:o,stride:a,size:h}=function(t){const e=void 0!==t.morphAttributes.position,s=void 0!==t.morphAttributes.normal,i=void 0!==t.morphAttributes.color,r=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,n=void 0!==r?r.length:0;let o=gv.get(t);if(void 0===o||o.count!==n){void 0!==o&&o.texture.dispose();const a=t.morphAttributes.position||[],h=t.morphAttributes.normal||[],u=t.morphAttributes.color||[];let l=0;!0===e&&(l=1),!0===s&&(l=2),!0===i&&(l=3);let c=t.attributes.position.count*l,d=1;const p=4096;c>p&&(d=Math.ceil(c/p),c=p);const m=new Float32Array(c*d*4*n),g=new Mi(m,c,d,n);g.type=It,g.needsUpdate=!0;const f=4*l;for(let x=0;x{const e=nm(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?e.assign(nx(this.mesh.morphTexture,lm(om(t).add(1),om(Km))).r):e.assign(mx("morphTargetInfluences","float").element(t).toVar()),!0===s&&Db.addAssign(yv({bufferMap:o,influence:e,stride:a,width:u,depth:t,offset:om(0)})),!0===i&&qx.addAssign(yv({bufferMap:o,influence:e,stride:a,width:u,depth:t,offset:om(1)}))}))}update(){const t=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?t.value=1:t.value=1-this.mesh.morphTargetInfluences.reduce(((t,e)=>t+e),0)}}const bv=Zp(xv);up("MorphNode",xv);const vv=jb.negate().reflect(Yx),Tv=jb.negate().refract(Yx,Lb),_v=vv.transformDirection(Sx).toVar("reflectVector"),wv=Tv.transformDirection(Sx).toVar("reflectVector");class Sv extends ix{constructor(t,e=null,s=null,i=null){super(t,e,s,i),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const t=this.value;return t.mapping===ht?_v:t.mapping===ut?wv:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',t.mapping),pm(0,0,0))}setUpdateMatrix(){}setupUV(t,e){const s=this.value;return t.renderer.coordinateSystem!==Ds&&s.isRenderTargetTexture?e:pm(e.x.negate(),e.yz)}generateUV(t,e){return e.build(t,"vec3")}}const Mv=Zp(Sv);_p("cubeTexture",Mv),up("CubeTextureNode",Sv);class Av extends hp{constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}up("LightingNode",Av);let Nv=null;class Rv extends Av{constructor(t=null){super(),this.updateType=$d.FRAME,this.light=t,this.rtt=null,this.shadowNode=null,this.shadowMaskNode=null,this.color=new Yr,this._defaultColorNode=hf(this.color),this.colorNode=this._defaultColorNode,this.isAnalyticLightNode=!0}getCacheKey(){return super.getCacheKey()+"-"+this.light.id+"-"+(this.light.castShadow?"1":"0")}getHash(){return this.light.uuid}setupShadow(t){const{object:e}=t;if(!1===e.receiveShadow)return;let s=this.shadowNode;if(null===s){null===Nv&&(Nv=t.createNodeMaterial(),Nv.fragmentNode=ym(0,0,0,1),Nv.isShadowNodeMaterial=!0);const i=this.light.shadow,r=t.createRenderTarget(i.mapSize.width,i.mapSize.height),n=new Ka;n.minFilter=ft,n.magFilter=ft,n.image.width=i.mapSize.width,n.image.height=i.mapSize.height,n.compareFunction=Ts,r.depthTexture=n,i.camera.updateProjectionMatrix();const o=mx("intensity","float",i),a=mx("bias","float",i),h=mx("normalBias","float",i),u=e.material.shadowPositionNode||kb;let l=hf(i.matrix).mul(u.add(Xx.mul(h)));l=l.xyz.div(l.w);const c=l.x.greaterThanEqual(0).and(l.x.lessThanEqual(1)).and(l.y.greaterThanEqual(0)).and(l.y.lessThanEqual(1)).and(l.z.lessThanEqual(1));let d=l.z.add(a);t.renderer.coordinateSystem===Ds&&(d=d.mul(2).sub(1)),l=pm(l.x,l.y.oneMinus(),d);const p=(t,e,s)=>rx(t,e).compare(s);s=p(n,l.xy,l.z);const m=rx(r.texture,l),g=c.mix(1,s.mix(m.a.mix(1,m),1));this.rtt=r,this.colorNode=this.colorNode.mul(Oy(1,g,o)),this.shadowNode=s,this.shadowMaskNode=g,this.updateBeforeType=$d.RENDER}}setup(t){this.light.castShadow?this.setupShadow(t):null!==this.shadowNode&&this.disposeShadow()}updateShadow(t){const{rtt:e,light:s}=this,{renderer:i,scene:r,camera:n}=t,o=r.overrideMaterial;r.overrideMaterial=Nv,e.setSize(s.shadow.mapSize.width,s.shadow.mapSize.height),s.shadow.updateMatrices(s),s.shadow.camera.layers.mask=n.layers.mask;const a=i.toneMapping,h=i.getRenderTarget(),u=i.getRenderObjectFunction();i.setRenderObjectFunction(((t,...e)=>{!0===t.castShadow&&i.renderObject(t,...e)})),i.setRenderTarget(e),i.toneMapping=0,i.render(r,s.shadow.camera),i.setRenderTarget(h),i.setRenderObjectFunction(u),i.toneMapping=a,r.overrideMaterial=o}disposeShadow(){this.rtt.dispose(),this.shadowNode=null,this.shadowMaskNode=null,this.rtt=null,this.colorNode=this._defaultColorNode}updateBefore(t){const{light:e}=this;e.castShadow&&this.updateShadow(t)}update(){const{light:t}=this;this.color.copy(t.color).multiplyScalar(t.intensity)}}up("AnalyticLightNode",Rv);const Cv=new WeakMap;class Ev extends hp{constructor(t=[]){super("vec3"),this.totalDiffuseNode=pm().temp("totalDiffuse"),this.totalSpecularNode=pm().temp("totalSpecular"),this.outgoingLightNode=pm().temp("outgoingLight"),this.lightNodes=t,this._hash=null}get hasLight(){return this.lightNodes.length>0}getHash(){if(null===this._hash){const t=[];for(const e of this.lightNodes)t.push(e.getHash());this._hash="lights-"+t.join(",")}return this._hash}analyze(t){const e=t.getDataFromNode(this);for(const s of e.nodes)s.build(t)}setup(t){const e=t.context,s=e.lightingModel;let i=this.outgoingLightNode;if(s){const{lightNodes:r,totalDiffuseNode:n,totalSpecularNode:o}=this;e.outgoingLight=i;const a=t.addStack();t.getDataFromNode(this).nodes=a.nodes,s.start(e,a,t);for(const e of r)e.build(t);s.indirect(e,a,t);const{backdrop:h,backdropAlpha:u}=e,{directDiffuse:l,directSpecular:c,indirectDiffuse:d,indirectSpecular:p}=e.reflectedLight;let m=l.add(d);null!==h&&(m=pm(null!==u?u.mix(m,h):h),e.material.transparent=!0),n.assign(m),o.assign(c.add(p)),i.assign(n.add(o)),s.finish(e,a,t),i=i.bypass(t.removeStack())}return i}_getLightNodeById(t){for(const e of this.lightNodes)if(e.isAnalyticLightNode&&e.light.id===t)return e;return null}fromLights(t=[]){const e=[];t=(t=>t.sort(((t,e)=>t.id-e.id)))(t);for(const s of t){let t=this._getLightNodeById(s.id);if(null===t){const e=s.constructor,i=Cv.has(e)?Cv.get(e):Rv;t=Xp(new i(s))}e.push(t)}return this.lightNodes=e,this._hash=null,this}}const Bv=t=>Xp((new Ev).fromLights(t)),Iv=Zp(Ev);function Pv(t,e){if(Cv.has(t))console.warn(`Redefinition of light node ${e.type}`);else{if("function"!=typeof t)throw new Error(`Light ${t.name} is not a class`);if("function"!=typeof e||!e.type)throw new Error(`Light node ${e.type} is not a class`);Cv.set(t,e)}}class Fv extends Av{constructor(t=null){super(),this.aoNode=t}setup(t){t.context.ambientOcclusion.mulAssign(this.aoNode)}}up("AONode",Fv);class Uv extends Xm{constructor(t,e=null,s=null,i=null){super(t),this.lightingModel=e,this.backdropNode=s,this.backdropAlphaNode=i,this._context=null}getContext(){const{backdropNode:t,backdropAlphaNode:e}=this,s={directDiffuse:pm().temp("directDiffuse"),directSpecular:pm().temp("directSpecular"),indirectDiffuse:pm().temp("indirectDiffuse"),indirectSpecular:pm().temp("indirectSpecular")};return{radiance:pm().temp("radiance"),irradiance:pm().temp("irradiance"),iblIrradiance:pm().temp("iblIrradiance"),ambientOcclusion:nm(1).temp("ambientOcclusion"),reflectedLight:s,backdrop:t,backdropAlpha:e}}setup(t){return this.context=this._context||(this._context=this.getContext()),this.context.lightingModel=this.lightingModel||t.context.lightingModel,super.setup(t)}}const Ov=Zp(Uv);_p("lightingContext",Ov),up("LightingContextNode",Uv);class Lv extends Av{constructor(t){super(),this.node=t}setup(t){t.context.irradiance.addAssign(this.node)}}let zv,Vv;up("IrradianceNode",Lv);class Dv extends hp{constructor(t){super(),this.scope=t,this.isViewportNode=!0}getNodeType(){return this.scope===Dv.VIEWPORT?"vec4":this.scope===Dv.COORDINATE?"vec3":"vec2"}getUpdateType(){let t=$d.NONE;return this.scope!==Dv.RESOLUTION&&this.scope!==Dv.VIEWPORT||(t=$d.RENDER),this.updateType=t,t}update({renderer:t}){this.scope===Dv.VIEWPORT?t.getViewport(Vv):t.getDrawingBufferSize(zv)}setup(){const t=this.scope;let e=null;if(t===Dv.RESOLUTION)e=hf(zv||(zv=new Ks));else if(t===Dv.VIEWPORT)e=hf(Vv||(Vv=new _i));else{e=kv.div(Gv);let s=e.x,i=e.y;/bottom/i.test(t)&&(i=i.oneMinus()),/right/i.test(t)&&(s=s.oneMinus()),e=um(s,i)}return e}generate(t){if(this.scope===Dv.COORDINATE){let e=t.getFragCoord();if(t.isFlipY()){const s=t.getNodeProperties(Gv).outputNode.build(t);e=`${t.getType("vec3")}( ${e}.x, ${s}.y - ${e}.y, ${e}.z )`}return e}return super.generate(t)}}Dv.COORDINATE="coordinate",Dv.RESOLUTION="resolution",Dv.VIEWPORT="viewport",Dv.TOP_LEFT="topLeft",Dv.BOTTOM_LEFT="bottomLeft",Dv.TOP_RIGHT="topRight",Dv.BOTTOM_RIGHT="bottomRight";const kv=Qp(Dv,Dv.COORDINATE),Gv=Qp(Dv,Dv.RESOLUTION),Wv=Qp(Dv,Dv.VIEWPORT),jv=Qp(Dv,Dv.TOP_LEFT),Hv=Qp(Dv,Dv.BOTTOM_LEFT),qv=Qp(Dv,Dv.TOP_RIGHT),$v=Qp(Dv,Dv.BOTTOM_RIGHT);up("ViewportNode",Dv);const Xv=new Ks;class Yv extends ix{constructor(t=jv,e=null,s=null){null===s&&((s=new Xa).minFilter=St),super(s,t,e),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=$d.FRAME}updateBefore(t){const e=t.renderer;e.getDrawingBufferSize(Xv);const s=this.value;s.image.width===Xv.width&&s.image.height===Xv.height||(s.image.width=Xv.width,s.image.height=Xv.height,s.needsUpdate=!0);const i=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,e.copyFramebufferToTexture(s),s.generateMipmaps=i}clone(){const t=new this.constructor(this.uvNode,this.levelNode,this.value);return t.generateMipmaps=this.generateMipmaps,t}}const Jv=Zp(Yv),Zv=Zp(Yv,null,null,{generateMipmaps:!0});_p("viewportTexture",Jv),_p("viewportMipTexture",Zv),up("ViewportTextureNode",Yv);let Qv=null;class Kv extends Yv{constructor(t=jv,e=null){null===Qv&&(Qv=new Ka),super(t,e,Qv)}}const tT=Zp(Kv);_p("viewportDepthTexture",tT),up("ViewportDepthTextureNode",Kv);class eT extends hp{constructor(t,e=null){super("float"),this.scope=t,this.valueNode=e,this.isViewportDepthNode=!0}generate(t){const{scope:e}=this;return e===eT.DEPTH?t.getFragDepth():super.generate(t)}setup({camera:t}){const{scope:e}=this,s=this.valueNode;let i=null;if(e===eT.DEPTH)i=null!==s?oT().assign(s):t.isPerspectiveCamera?rT(Wb.z,bx,vx):sT(Wb.z,bx,vx);else if(e===eT.LINEAR_DEPTH)if(null!==s)if(t.isPerspectiveCamera){const t=nT(s,bx,vx);i=sT(t,bx,vx)}else i=s;else i=sT(Wb.z,bx,vx);return i}}const sT=(t,e,s)=>t.add(e).div(e.sub(s)),iT=(t,e,s)=>e.sub(s).mul(t).sub(e),rT=(t,e,s)=>e.add(t).mul(s).div(s.sub(e).mul(t)),nT=(t,e,s)=>e.mul(s).div(s.sub(e).mul(t).sub(s));eT.DEPTH="depth",eT.LINEAR_DEPTH="linearDepth";const oT=Zp(eT,eT.DEPTH),aT=Qp(eT,eT.DEPTH),hT=Zp(eT,eT.LINEAR_DEPTH),uT=hT(tT());aT.assign=t=>oT(t),up("ViewportDepthNode",eT);class lT extends hp{constructor(t=lT.DEFAULT){super(),this.scope=t}setup(t){super.setup(t);const e=t.clippingContext,{localClipIntersection:s,localClippingCount:i,globalClippingCount:r}=e,n=r+i,o=s?n-i:n;return this.scope===lT.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(e.planes,n,o):this.setupDefault(e.planes,n,o)}setupAlphaToCoverage(t,e,s){return Kp((()=>{const i=cx(t),r=pg("float","distanceToPlane"),n=pg("float","distanceToGradient"),o=pg("float","clipOpacity");let a;if(o.assign(1),dv(s,(({i:t})=>{a=i.element(t),r.assign(Wb.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),o.mulAssign(Dy(n.negate(),n,r)),o.equal(0).discard()})),s{a=i.element(e),r.assign(Wb.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),t.mulAssign(Dy(n.negate(),n,r).oneMinus())})),o.mulAssign(t.oneMinus())}gg.a.mulAssign(o),gg.a.equal(0).discard()}))()}setupDefault(t,e,s){return Kp((()=>{const i=cx(t);let r;if(dv(s,(({i:t})=>{r=i.element(t),Wb.dot(r.xyz).greaterThan(r.w).discard()})),s{r=i.element(e),t.assign(Wb.dot(r.xyz).greaterThan(r.w).and(t))})),t.discard()}}))()}}lT.ALPHA_TO_COVERAGE="alphaToCoverage",lT.DEFAULT="default";class cT extends hp{constructor(){super("bool"),this.isFrontFacingNode=!0}generate(t){const{renderer:e,material:s}=t;return e.coordinateSystem===Vs&&s.side===d?"false":t.getFrontFacing()}}const dT=Qp(cT),pT=nm(dT).mul(2).sub(1);up("FrontFacingNode",cT);const mT=new Map;class gT extends Qr{constructor(){super(),this.isNodeMaterial=!0,this.type=this.constructor.type,this.forceSinglePass=!1,this.fog=!0,this.lights=!0,this.normals=!0,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.depthNode=null,this.shadowNode=null,this.shadowPositionNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+Kd(this)}build(t){this.setup(t)}setup(t){let e;t.addStack(),t.stack.outputNode=this.vertexNode||this.setupPosition(t),t.addFlow("vertex",t.removeStack()),t.addStack();const s=this.setupClipping(t);if(!0===this.depthWrite&&this.setupDepth(t),null===this.fragmentNode){!0===this.normals&&this.setupNormal(t),this.setupDiffuseColor(t),this.setupVariants(t);const i=this.setupLighting(t);null!==s&&t.stack.add(s);const r=ym(i,gg.a).max(0);e=this.setupOutput(t,r),Pg.assign(e),null!==this.outputNode&&(e=this.outputNode);if(null!==t.renderer.getRenderTarget()){const s=t.renderer.getMRT(),i=this.mrtNode;null!==s?(e=s,null!==i&&(e=s.merge(i))):null!==i&&(e=i)}}else{let s=this.fragmentNode;!0!==s.isOutputStructNode&&(s=ym(s)),e=this.setupOutput(t,s)}t.stack.outputNode=e,t.addFlow("fragment",t.removeStack())}setupClipping(t){if(null===t.clippingContext)return null;const{globalClippingCount:e,localClippingCount:s}=t.clippingContext;let i=null;return(e||s)&&(this.alphaToCoverage?i=Xp(new lT(lT.ALPHA_TO_COVERAGE)):t.stack.add(Xp(new lT))),i}setupDepth(t){const{renderer:e}=t;let s=this.depthNode;if(null===s&&!0===e.logarithmicDepthBuffer){s=qb().w.add(1).log2().mul(Tx).mul(.5)}null!==s&&aT.assign(s).append()}setupPosition(t){const{object:e}=t,s=e.geometry;if(t.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&bv(e).append(),!0===e.isSkinnedMesh&&lv(e).append(),this.displacementMap){const t=yx("displacementMap","texture"),e=yx("displacementScale","float"),s=yx("displacementBias","float");Db.addAssign(qx.normalize().mul(t.x.mul(e).add(s)))}e.isBatchedMesh&&av(e).append(),e.instanceMatrix&&!0===e.instanceMatrix.isInstancedBufferAttribute&&Kb(e).append(),null!==this.positionNode&&Db.assign(this.positionNode);const i=qb();return t.context.vertex=t.removeStack(),t.context.mvp=i,i}setupDiffuseColor({object:t,geometry:e}){let s=this.colorNode?ym(this.colorNode):eb;if(!0===this.vertexColors&&e.hasAttribute("color")&&(s=ym(s.xyz.mul(Wm("color","vec3")),s.a)),t.instanceColor){s=mg("vec3","vInstanceColor").mul(s)}gg.assign(s);const i=this.opacityNode?nm(this.opacityNode):rb;if(gg.a.assign(gg.a.mul(i)),null!==this.alphaTestNode||this.alphaTest>0){const t=null!==this.alphaTestNode?nm(this.alphaTestNode):tb;gg.a.lessThanEqual(t).discard()}!1===this.transparent&&1===this.blending&&!1===this.alphaToCoverage&&gg.a.assign(1)}setupVariants(){}setupNormal(){if(!0===this.flatShading){const t=Wb.dFdx().cross(Wb.dFdy()).normalize();Yx.assign(t.mul(pT))}else{const t=this.normalNode?pm(this.normalNode):db;Yx.assign(t.mul(pT))}}setupEnvironment(t){let e=null;return this.envNode?e=this.envNode:this.envMap?e=this.envMap.isCubeTexture?Mv(this.envMap):rx(this.envMap):t.environmentNode&&(e=t.environmentNode),e}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new Lv(Ub)),e}setupLights(t){const e=[],s=this.setupEnvironment(t);s&&s.isLightingNode&&e.push(s);const i=this.setupLightMap(t);if(i&&i.isLightingNode&&e.push(i),null!==this.aoNode||t.material.aoMap){const t=null!==this.aoNode?this.aoNode:Ob;e.push(new Fv(t))}let r=this.lightsNode||t.lightsNode;return e.length>0&&(r=Iv([...r.lightNodes,...e])),r}setupLightingModel(){}setupLighting(t){const{material:e}=t,{backdropNode:s,backdropAlphaNode:i,emissiveNode:r}=this,n=!0===this.lights||null!==this.lightsNode?this.setupLights(t):null;let o=gg.rgb;if(n&&!1!==n.hasLight){const e=this.setupLightingModel(t);o=Ov(n,e,s,i)}else null!==s&&(o=pm(null!==i?Oy(o,s,i):s));return(r&&!0===r.isNode||e.emissive&&!0===e.emissive.isColor)&&(fg.assign(pm(r||ib)),o=o.add(fg)),o}setupOutput(t,e){if(!0===this.fog){const s=t.fogNode;s&&(e=ym(s.mix(e.rgb,s.colorNode),e.a))}return e}setDefaultValues(t){for(const e in t){const s=t[e];void 0===this[e]&&(this[e]=s,s&&s.clone&&(this[e]=s.clone()))}const e=Object.getOwnPropertyDescriptors(t.constructor.prototype);for(const t in e)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,t)&&void 0!==e[t].get&&Object.defineProperty(this.constructor.prototype,t,e[t])}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{},nodes:{}});const s=Qr.prototype.toJSON.call(this,t),i=tp(this);s.inputNodes={};for(const{property:e,childNode:r}of i)s.inputNodes[e]=r.toJSON(t).uuid;function r(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(e){const e=r(t.textures),i=r(t.images),n=r(t.nodes);e.length>0&&(s.textures=e),i.length>0&&(s.images=i),n.length>0&&(s.nodes=n)}return s}copy(t){return this.lightsNode=t.lightsNode,this.envNode=t.envNode,this.colorNode=t.colorNode,this.normalNode=t.normalNode,this.opacityNode=t.opacityNode,this.backdropNode=t.backdropNode,this.backdropAlphaNode=t.backdropAlphaNode,this.alphaTestNode=t.alphaTestNode,this.positionNode=t.positionNode,this.depthNode=t.depthNode,this.shadowNode=t.shadowNode,this.shadowPositionNode=t.shadowPositionNode,this.outputNode=t.outputNode,this.mrtNode=t.mrtNode,this.fragmentNode=t.fragmentNode,this.vertexNode=t.vertexNode,super.copy(t)}static fromMaterial(t){if(!0===t.isNodeMaterial)return t;const e=yT(t.type.replace("Material","NodeMaterial"));if(void 0===e)throw new Error(`NodeMaterial: Material "${t.type}" is not compatible.`);for(const s in t)e[s]=t[s];return e}}function fT(t,e){if("function"!=typeof e||!t)throw new Error(`Node material ${t} is not a class`);mT.has(t)?console.warn(`Redefinition of node material ${t}`):(mT.set(t,e),e.type=t)}function yT(t){const e=mT.get(t);if(void 0!==e)return new e}fT("NodeMaterial",gT);class xT{constructor(t,e){this.name=t,this.value=e,this.boundary=0,this.itemSize=0,this.offset=0}setValue(t){this.value=t}getValue(){return this.value}}class bT extends xT{constructor(t,e=0){super(t,e),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class vT extends xT{constructor(t,e=new Ks){super(t,e),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class TT extends xT{constructor(t,e=new Ei){super(t,e),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class _T extends xT{constructor(t,e=new _i){super(t,e),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class wT extends xT{constructor(t,e=new Yr){super(t,e),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class ST extends xT{constructor(t,e=new ti){super(t,e),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class MT extends xT{constructor(t,e=new or){super(t,e),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class AT extends bT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class NT extends vT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class RT extends TT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class CT extends _T{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class ET extends wT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class BT extends ST{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class IT extends MT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class PT extends hp{constructor(t,e,s=null){super(),this.condNode=t,this.ifNode=e,this.elseNode=s}getNodeType(t){const e=this.ifNode.getNodeType(t);if(null!==this.elseNode){const s=this.elseNode.getNodeType(t);if(t.getTypeLength(s)>t.getTypeLength(e))return s}return e}setup(t){const e=t.getNodeProperties(this);e.condNode=this.condNode.cache(),e.ifNode=this.ifNode.cache(),e.elseNode=this.elseNode?this.elseNode.cache():null}generate(t,e){const s=this.getNodeType(t),i=t.getDataFromNode(this);if(void 0!==i.nodeProperty)return i.nodeProperty;const{condNode:r,ifNode:n,elseNode:o}=t.getNodeProperties(this),a="void"!==e,h=a?pg(s).build(t):"";i.nodeProperty=h;const u=r.build(t,"bool");t.addFlowCode(`\n${t.tab}if ( ${u} ) {\n\n`).addFlowTab();let l=n.build(t,s);if(l&&(l=a?h+" = "+l+";":"return "+l+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+l+"\n\n"+t.tab+"}"),null!==o){t.addFlowCode(" else {\n\n").addFlowTab();let e=o.build(t,s);e&&(e=a?h+" = "+e+";":"return "+e+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+e+"\n\n"+t.tab+"}\n\n")}else t.addFlowCode("\n\n");return t.format(h,s,e)}}const FT=Zp(PT);_p("cond",FT),up("CondNode",PT);class UT extends hp{constructor(t=null){super(),this.nodes=[],this.outputNode=null,this.parent=t,this._currentCond=null,this.isStackNode=!0}getNodeType(t){return this.outputNode?this.outputNode.getNodeType(t):"void"}add(t){return this.nodes.push(t),this}if(t,e){const s=new $p(e);return this._currentCond=FT(t,s),this.add(this._currentCond)}elseif(t,e){const s=new $p(e),i=FT(t,s);return this._currentCond.elseNode=i,this._currentCond=i,this}else(t){return this._currentCond.elseNode=new $p(t),this}build(t,...e){const s=em();tm(this);for(const e of this.nodes)e.build(t,"void");return tm(s),this.outputNode?this.outputNode.build(t,...e):super.build(t,...e)}}const OT=Zp(UT);up("StackNode",UT);class LT extends cp{constructor(t=Gb){super("vec2"),this.dirNode=t}setup(){const t=this.dirNode,e=t.z.atan2(t.x).mul(1/(2*Math.PI)).add(.5),s=t.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return um(e,s)}}const zT=Zp(LT);up("EquirectUVNode",LT);class VT extends so{constructor(t=1,e={}){super(t,e),this.isCubeRenderTarget=!0}fromEquirectangularTexture(t,e){const s=e.minFilter,i=e.generateMipmaps;e.generateMipmaps=!0,this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const r=new Hn(5,5,5),n=zT(Gb),o=yT("MeshBasicNodeMaterial");o.colorNode=rx(e,n,0),o.side=d,o.blending=m;const a=new Wn(r,o),h=new no;h.add(a),e.minFilter===St&&(e.minFilter=Tt);return new to(1,10,this).update(t,h),e.minFilter=s,e.currentGenerateMipmaps=i,a.geometry.dispose(),a.material.dispose(),this}}const DT=nm(1),kT=nm(-2),GT=nm(.8),WT=nm(-1),jT=nm(.4),HT=nm(2),qT=nm(.305),$T=nm(3),XT=nm(.21),YT=nm(4),JT=nm(4),ZT=nm(16),QT=Kp((([t])=>{const e=pm(oy(t)).toVar(),s=nm(-1).toVar();return sm(e.x.greaterThan(e.z),(()=>{sm(e.x.greaterThan(e.y),(()=>{s.assign(FT(t.x.greaterThan(0),0,3))})).else((()=>{s.assign(FT(t.y.greaterThan(0),1,4))}))})).else((()=>{sm(e.z.greaterThan(e.y),(()=>{s.assign(FT(t.z.greaterThan(0),2,5))})).else((()=>{s.assign(FT(t.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),KT=Kp((([t,e])=>{const s=um().toVar();return sm(e.equal(0),(()=>{s.assign(um(t.z,t.y).div(oy(t.x)))})).elseif(e.equal(1),(()=>{s.assign(um(t.x.negate(),t.z.negate()).div(oy(t.y)))})).elseif(e.equal(2),(()=>{s.assign(um(t.x.negate(),t.y).div(oy(t.z)))})).elseif(e.equal(3),(()=>{s.assign(um(t.z.negate(),t.y).div(oy(t.x)))})).elseif(e.equal(4),(()=>{s.assign(um(t.x.negate(),t.z).div(oy(t.y)))})).else((()=>{s.assign(um(t.x,t.y).div(oy(t.z)))})),gf(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),t_=Kp((([t])=>{const e=nm(0).toVar();return sm(t.greaterThanEqual(GT),(()=>{e.assign(DT.sub(t).mul(WT.sub(kT)).div(DT.sub(GT)).add(kT))})).elseif(t.greaterThanEqual(jT),(()=>{e.assign(GT.sub(t).mul(HT.sub(WT)).div(GT.sub(jT)).add(WT))})).elseif(t.greaterThanEqual(qT),(()=>{e.assign(jT.sub(t).mul($T.sub(HT)).div(jT.sub(qT)).add(HT))})).elseif(t.greaterThanEqual(XT),(()=>{e.assign(qT.sub(t).mul(YT.sub($T)).div(qT.sub(XT)).add($T))})).else((()=>{e.assign(nm(-2).mul($f(gf(1.16,t))))})),e})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),e_=Kp((([t,e])=>{const s=t.toVar();s.assign(gf(2,s).sub(1));const i=pm(s,1).toVar();return sm(e.equal(0),(()=>{i.assign(i.zyx)})).elseif(e.equal(1),(()=>{i.assign(i.xzy),i.xz.mulAssign(-1)})).elseif(e.equal(2),(()=>{i.x.mulAssign(-1)})).elseif(e.equal(3),(()=>{i.assign(i.zyx),i.xz.mulAssign(-1)})).elseif(e.equal(4),(()=>{i.assign(i.xzy),i.xy.mulAssign(-1)})).elseif(e.equal(5),(()=>{i.z.mulAssign(-1)})),i})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),s_=Kp((([t,e,s,i,r,n])=>{const o=nm(s),a=pm(e),h=Ly(t_(o),kT,n),u=Kf(h),l=Jf(h),c=pm(i_(t,a,l,i,r,n)).toVar();return sm(u.notEqual(0),(()=>{const e=pm(i_(t,a,l.add(1),i,r,n)).toVar();c.assign(Oy(c,e,u))})),c})),i_=Kp((([t,e,s,i,r,n])=>{const o=nm(s).toVar(),a=pm(e),h=nm(QT(a)).toVar(),u=nm(Ty(JT.sub(o),0)).toVar();o.assign(Ty(o,JT));const l=nm(Hf(o)).toVar(),c=um(KT(a,h).mul(l.sub(2)).add(1)).toVar();return sm(h.greaterThan(2),(()=>{c.y.addAssign(l),h.subAssign(3)})),c.x.addAssign(h.mul(l)),c.x.addAssign(u.mul(gf(3,ZT))),c.y.addAssign(gf(4,Hf(n).sub(l))),c.x.mulAssign(i),c.y.mulAssign(r),t.uv(c).grad(um(),um())})),r_=Kp((({envMap:t,mipInt:e,outputDirection:s,theta:i,axis:r,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const h=ey(i),u=s.mul(h).add(r.cross(s).mul(ty(i))).add(r.mul(r.dot(s).mul(h.oneMinus())));return i_(t,u,e,n,o,a)})),n_=Kp((({n:t,latitudinal:e,poleAxis:s,outputDirection:i,weights:r,samples:n,dTheta:o,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c})=>{const d=pm(FT(e,s,Ry(s,i))).toVar();sm(Vf(d.equals(pm(0))),(()=>{d.assign(pm(i.z,0,i.x.negate()))})),d.assign(Qf(d));const p=pm().toVar();return p.addAssign(r.element(om(0)).mul(r_({theta:0,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c}))),dv({start:om(1),end:t},(({i:t})=>{sm(t.greaterThanEqual(n),(()=>{mv()}));const e=nm(o.mul(nm(t))).toVar();p.addAssign(r.element(t).mul(r_({theta:e.mul(-1),axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c}))),p.addAssign(r.element(t).mul(r_({theta:e,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c})))})),ym(p,1)})),o_=[.125,.215,.35,.446,.526,.582],a_=20,h_=new Rl(-1,1,1,-1,0,1),u_=new Qn(90,1),l_=new Yr;let c_=null,d_=0,p_=0;const m_=(1+Math.sqrt(5))/2,g_=1/m_,f_=[new Ei(-m_,g_,0),new Ei(m_,g_,0),new Ei(-g_,0,m_),new Ei(g_,0,m_),new Ei(0,m_,-g_),new Ei(0,m_,g_),new Ei(-1,1,-1),new Ei(1,1,-1),new Ei(-1,1,1),new Ei(1,1,1)],y_=[3,1,5,0,4,2],x_=e_(uf(),Wm("faceIndex")).normalize(),b_=pm(x_.x,x_.y.negate(),x_.z);class v_{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(t,e=0,s=.1,i=100){c_=this._renderer.getRenderTarget(),d_=this._renderer.getActiveCubeFace(),p_=this._renderer.getActiveMipmapLevel(),this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(t,s,i,r),e>0&&this._blur(r,0,0,e),this._applyPMREM(r),this._cleanup(r),r}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=S_(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=M_(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let t=0;tt-4?h=o_[a-t+4-1]:0===a&&(h=0),i.push(h);const u=1/(o-2),l=-u,c=1+u,d=[l,l,c,l,c,c,l,l,c,c,l,c],p=6,m=6,g=3,f=2,y=1,x=new Float32Array(g*m*p),b=new Float32Array(f*m*p),v=new Float32Array(y*m*p);for(let t=0;t2?0:-1,i=[e,s,0,e+2/3,s,0,e+2/3,s+1,0,e,s,0,e+2/3,s+1,0,e,s+1,0],r=y_[t];x.set(i,g*m*r),b.set(d,f*m*r);const n=[r,r,r,r,r,r];v.set(n,y*m*r)}const T=new Mn;T.setAttribute("position",new hn(x,g)),T.setAttribute("uv",new hn(b,f)),T.setAttribute("faceIndex",new hn(v,y)),e.push(T),r.push(new Wn(T,null)),n>4&&n--}return{lodPlanes:e,sizeLods:s,sigmas:i,lodMeshes:r}}(i)),this._blurMaterial=function(t,e,s){const i=cx(new Array(a_).fill(0)),r=hf(new Ei(0,1,0)),n=hf(0),o=nm(a_),a=hf(0),h=hf(1),u=rx(null),l=hf(0),c=nm(1/e),d=nm(1/s),p=nm(t),m={n:o,latitudinal:a,weights:i,poleAxis:r,outputDirection:b_,dTheta:n,samples:h,envMap:u,mipInt:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:p},g=w_();return g.uniforms=m,g.fragmentNode=n_({...m,latitudinal:a.equal(1)}),g}(i,t,e)}return i}_compileMaterial(t){const e=this._lodMeshes[0];e.material=t,this._renderer.compile(e,h_)}_sceneToCubeUV(t,e,s,i){const r=u_;r.near=e,r.far=s;const n=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,h=a.autoClear;a.getClearColor(l_),a.autoClear=!1;let u=this._backgroundBox;if(null===u){const t=new Kr({name:"PMREM.Background",side:d,depthWrite:!1,depthTest:!1});u=new Wn(new Hn,t)}let l=!1;const c=t.background;c?c.isColor&&(u.material.color.copy(c),t.background=null,l=!0):(u.material.color.copy(l_),l=!0),a.setRenderTarget(i),a.clear(),l&&a.render(u,r);for(let e=0;e<6;e++){const s=e%3;0===s?(r.up.set(0,n[e],0),r.lookAt(o[e],0,0)):1===s?(r.up.set(0,0,n[e]),r.lookAt(0,o[e],0)):(r.up.set(0,n[e],0),r.lookAt(0,0,o[e]));const h=this._cubeSize;__(i,s*h,e>2?h:0,h,h),a.render(t,r)}a.autoClear=h,t.background=c}_textureToCubeUV(t,e){const s=this._renderer,i=t.mapping===ht||t.mapping===ut;i?null===this._cubemapMaterial&&(this._cubemapMaterial=S_(t)):null===this._equirectMaterial&&(this._equirectMaterial=M_(t));const r=i?this._cubemapMaterial:this._equirectMaterial;r.fragmentNode.value=t;const n=this._lodMeshes[0];n.material=r;const o=this._cubeSize;__(e,0,0,3*o,2*o),s.setRenderTarget(e),s.render(n,h_)}_applyPMREM(t){const e=this._renderer,s=e.autoClear;e.autoClear=!1;const i=this._lodPlanes.length;for(let e=1;ea_&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${m} samples when the maximum is set to 20`);const g=[];let f=0;for(let t=0;ty-4?i-y+4:0),4*(this._cubeSize-x),3*x,2*x),a.setRenderTarget(e),a.render(u,h_)}}function T_(t,e,s){const i=new wi(t,e,s);return i.texture.mapping=306,i.texture.name="PMREM.cubeUv",i.texture.isPMREMTexture=!0,i.scissorTest=!0,i}function __(t,e,s,i,r){const n=t.height-r-s;t.viewport.set(e,n,i,r),t.scissor.set(e,n,i,r)}function w_(){const t=new gT;return t.depthTest=!1,t.depthWrite=!1,t.blending=m,t}function S_(t){const e=w_();return e.fragmentNode=Mv(t,b_),e}function M_(t){const e=w_();return e.fragmentNode=rx(t,zT(b_),0),e}let A_=0;class N_{constructor(t="",e=[]){this.name=t,this.bindings=e,this.id=A_++}}const R_=new WeakMap,C_=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),E_=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),B_=t=>(t=Number(t))+(t%1?"":".0");class I_{constructor(t,e,s){this.object=t,this.material=t&&t.material||null,this.geometry=t&&t.geometry||null,this.renderer=e,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=OT(),this.stacks=[],this.tab="\t",this.instanceBindGroups=!0,this.currentFunctionNode=null,this.context={keywords:new ug,material:this.material},this.cache=new cg,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null}getBingGroupsCache(){let t=R_.get(this.renderer);return void 0===t&&(t=new _d,R_.set(this.renderer,t)),t}createRenderTarget(t,e,s){return new wi(t,e,s)}createCubeRenderTarget(t,e){return new VT(t,e)}createPMREMGenerator(){return new v_(this.renderer)}includes(t){return this.nodes.includes(t)}_getBindGroup(t,e){const s=this.getBingGroupsCache(),i=[];let r,n=!0;for(const t of e)i.push(t),n=n&&!0!==t.groupNode.shared;return n?(r=s.get(i),void 0===r&&(r=new N_(t,i),s.set(i,r))):r=new N_(t,i),r}getBindGroupArray(t,e){const s=this.bindings[e];let i=s[t];return void 0===i&&(void 0===this.bindingsIndexes[t]&&(this.bindingsIndexes[t]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[t]=i=[]),i}getBindings(){let t=this.bindGroups;if(null===t){const e={},s=this.bindings;for(const t of Zd)for(const i in s[t]){const r=s[t][i];(e[i]||(e[i]=[])).push(...r)}t=[];for(const s in e){const i=e[s],r=this._getBindGroup(s,i);t.push(r)}this.bindGroups=t}return t}setHashNode(t,e){this.hashNodes[e]=t}addNode(t){!1===this.nodes.includes(t)&&(this.nodes.push(t),this.setHashNode(t,t.getHash(this)))}buildUpdateNodes(){for(const t of this.nodes){const e=t.getUpdateType(),s=t.getUpdateBeforeType(),i=t.getUpdateAfterType();e!==$d.NONE&&this.updateNodes.push(t.getSelf()),s!==$d.NONE&&this.updateBeforeNodes.push(t),i!==$d.NONE&&this.updateAfterNodes.push(t)}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(t){return t.magFilter===Tt||t.magFilter===_t||t.magFilter===bt||t.magFilter===St||t.minFilter===Tt||t.minFilter===_t||t.minFilter===bt||t.minFilter===St}addChain(t){this.chaining.push(t)}removeChain(t){if(this.chaining.pop()!==t)throw new Error("NodeBuilder: Invalid node chaining!")}getMethod(t){return t}getNodeFromHash(t){return this.hashNodes[t]}addFlow(t,e){return this.flowNodes[t].push(e),e}setContext(t){this.context=t}getContext(){return this.context}getSharedContext(){return this.context,this.context}setCache(t){this.cache=t}getCache(){return this.cache}getCacheFromNode(t,e=!0){const s=this.getDataFromNode(t);return void 0===s.cache&&(s.cache=new cg(e?this.getCache():null)),s.cache}isAvailable(){return!1}getVertexIndex(){console.warn("Abstract function.")}getInstanceIndex(){console.warn("Abstract function.")}getDrawIndex(){console.warn("Abstract function.")}getFrontFacing(){console.warn("Abstract function.")}getFragCoord(){console.warn("Abstract function.")}isFlipY(){return!1}generateTexture(){console.warn("Abstract function.")}generateTextureLod(){console.warn("Abstract function.")}generateConst(t,e=null){if(null===e&&("float"===t||"int"===t||"uint"===t?e=0:"bool"===t?e=!1:"color"===t?e=new Yr:"vec2"===t?e=new Ks:"vec3"===t?e=new Ei:"vec4"===t&&(e=new _i)),"float"===t)return B_(e);if("int"===t)return`${Math.round(e)}`;if("uint"===t)return e>=0?`${Math.round(e)}u`:"0u";if("bool"===t)return e?"true":"false";if("color"===t)return`${this.getType("vec3")}( ${B_(e.r)}, ${B_(e.g)}, ${B_(e.b)} )`;const s=this.getTypeLength(t),i=this.getComponentType(t),r=t=>this.generateConst(i,t);if(2===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)} )`;if(3===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)}, ${r(e.z)} )`;if(4===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)}, ${r(e.z)}, ${r(e.w)} )`;if(s>4&&e&&(e.isMatrix3||e.isMatrix4))return`${this.getType(t)}( ${e.elements.map(r).join(", ")} )`;if(s>4)return`${this.getType(t)}()`;throw new Error(`NodeBuilder: Type '${t}' not found in generate constant attempt.`)}getType(t){return"color"===t?"vec3":t}hasGeometryAttribute(t){return this.geometry&&void 0!==this.geometry.getAttribute(t)}getAttribute(t,e){const s=this.attributes;for(const e of s)if(e.name===t)return e;const i=new rg(t,e);return s.push(i),i}getPropertyName(t){return t.name}isVector(t){return/vec\d/.test(t)}isMatrix(t){return/mat\d/.test(t)}isReference(t){return"void"===t||"property"===t||"sampler"===t||"texture"===t||"cubeTexture"===t||"storageTexture"===t||"depthTexture"===t||"texture3D"===t}needsColorSpaceToLinear(){return!1}getComponentTypeFromTexture(t){const e=t.type;if(t.isDataTexture){if(e===Et)return"int";if(e===Bt)return"uint"}return"float"}getElementType(t){return"mat2"===t?"vec2":"mat3"===t?"vec3":"mat4"===t?"vec4":this.getComponentType(t)}getComponentType(t){if("float"===(t=this.getVectorType(t))||"bool"===t||"int"===t||"uint"===t)return t;const e=/(b|i|u|)(vec|mat)([2-4])/.exec(t);return null===e?null:"b"===e[1]?"bool":"i"===e[1]?"int":"u"===e[1]?"uint":"float"}getVectorType(t){return"color"===t?"vec3":"texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t?"vec4":t}getTypeFromLength(t,e="float"){if(1===t)return e;const s=C_.get(t);return("float"===e?"":e[0])+s}getTypeFromArray(t){return E_.get(t.constructor)}getTypeFromAttribute(t){let e=t;t.isInterleavedBufferAttribute&&(e=t.data);const s=e.array,i=t.itemSize,r=t.normalized;let n;return t instanceof fn||!0===r||(n=this.getTypeFromArray(s)),this.getTypeFromLength(i,n)}getTypeLength(t){const e=this.getVectorType(t),s=/vec([2-4])/.exec(e);return null!==s?Number(s[1]):"float"===e||"bool"===e||"int"===e||"uint"===e?1:!0===/mat2/.test(t)?4:!0===/mat3/.test(t)?9:!0===/mat4/.test(t)?16:0}getVectorFromMatrix(t){return t.replace("mat","vec")}changeComponentType(t,e){return this.getTypeFromLength(this.getTypeLength(t),e)}getIntegerType(t){const e=this.getComponentType(t);return"int"===e||"uint"===e?t:this.changeComponentType(t,"int")}addStack(){return this.stack=OT(this.stack),this.stacks.push(em()||this.stack),tm(this.stack),this.stack}removeStack(){const t=this.stack;return this.stack=t.parent,tm(this.stacks.pop()),t}getDataFromNode(t,e=this.shaderStage,s=null){let i=(s=null===s?t.isGlobal(this)?this.globalCache:this.cache:s).getData(t);return void 0===i&&(i={},s.setData(t,i)),void 0===i[e]&&(i[e]={}),i[e]}getNodeProperties(t,e="any"){const s=this.getDataFromNode(t,e);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(t,e){const s=this.getDataFromNode(t);let i=s.bufferAttribute;if(void 0===i){const r=this.uniforms.index++;i=new rg("nodeAttribute"+r,e,t),this.bufferAttributes.push(i),s.bufferAttribute=i}return i}getStructTypeFromNode(t,e=this.shaderStage){const s=this.getDataFromNode(t,e);if(void 0===s.structType){const i=this.structs.index++;t.name=`StructType${i}`,this.structs[e].push(t),s.structType=t}return t}getUniformFromNode(t,e,s=this.shaderStage,i=null){const r=this.getDataFromNode(t,s,this.globalCache);let n=r.uniform;if(void 0===n){const o=this.uniforms.index++;n=new ng(i||"nodeUniform"+o,e,t),this.uniforms[s].push(n),r.uniform=n}return n}getVarFromNode(t,e=null,s=t.getNodeType(this),i=this.shaderStage){const r=this.getDataFromNode(t,i);let n=r.variable;if(void 0===n){const t=this.vars[i]||(this.vars[i]=[]);null===e&&(e="nodeVar"+t.length),n=new og(e,s),t.push(n),r.variable=n}return n}getVaryingFromNode(t,e=null,s=t.getNodeType(this)){const i=this.getDataFromNode(t,"any");let r=i.varying;if(void 0===r){const t=this.varyings,n=t.length;null===e&&(e="nodeVarying"+n),r=new ag(e,s),t.push(r),i.varying=r}return r}getCodeFromNode(t,e,s=this.shaderStage){const i=this.getDataFromNode(t);let r=i.code;if(void 0===r){const t=this.codes[s]||(this.codes[s]=[]),n=t.length;r=new hg("nodeCode"+n,e),t.push(r),i.code=r}return r}addLineFlowCode(t){return""===t||(t=this.tab+t,/;\s*$/.test(t)||(t+=";\n"),this.flow.code+=t),this}addFlowCode(t){return this.flow.code+=t,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(t){return this.flowsData.get(t)}flowNode(t){const e=t.getNodeType(this),s=this.flowChildNode(t,e);return this.flowsData.set(t,s),s}buildFunctionNode(t){const e=new Jg,s=this.currentFunctionNode;return this.currentFunctionNode=e,e.code=this.buildFunctionCode(t),this.currentFunctionNode=s,e}flowShaderNode(t){const e=t.layout;let s;if(t.isArrayInput){s=[];for(const t of e.inputs)s.push(new Wg(t.type,t.name))}else{s={};for(const t of e.inputs)s[t.name]=new Wg(t.type,t.name)}t.layout=null;const i=t.call(s),r=this.flowStagesNode(i,e.type);return t.layout=e,r}flowStagesNode(t,e=null){const s=this.flow,i=this.vars,r=this.cache,n=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new cg,this.stack=OT();for(const s of Jd)this.setBuildStage(s),a.result=t.build(this,e);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=i,this.cache=r,this.stack=o,this.setBuildStage(n),a}getFunctionOperator(){return null}flowChildNode(t,e=null){const s=this.flow,i={code:""};return this.flow=i,i.result=t.build(this,e),this.flow=s,i}flowNodeFromShaderStage(t,e,s=null,i=null){const r=this.shaderStage;this.setShaderStage(t);const n=this.flowChildNode(e,s);return null!==i&&(n.code+=`${this.tab+i} = ${n.result};\n`),this.flowCode[t]=this.flowCode[t]+n.code,this.setShaderStage(r),n}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(t,e){return`${this.getType(t)} ${e}`}getVars(t){let e="";const s=this.vars[t];if(void 0!==s)for(const t of s)e+=`${this.getVar(t.type,t.name)}; `;return e}getUniforms(){console.warn("Abstract function.")}getCodes(t){const e=this.codes[t];let s="";if(void 0!==e)for(const t of e)s+=t.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(t){this.shaderStage=t}getShaderStage(){return this.shaderStage}setBuildStage(t){this.buildStage=t}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:t,material:e}=this;null!==e?gT.fromMaterial(e).build(this):this.addFlow("compute",t);for(const t of Jd){this.setBuildStage(t),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const e of Zd){this.setShaderStage(e);const s=this.flowNodes[e];for(const e of s)"generate"===t?this.flowNode(e):e.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(t,e){if("float"===e||"int"===e||"uint"===e)return new AT(t);if("vec2"===e||"ivec2"===e||"uvec2"===e)return new NT(t);if("vec3"===e||"ivec3"===e||"uvec3"===e)return new RT(t);if("vec4"===e||"ivec4"===e||"uvec4"===e)return new CT(t);if("color"===e)return new ET(t);if("mat3"===e)return new BT(t);if("mat4"===e)return new IT(t);throw new Error(`Uniform "${e}" not declared.`)}createNodeMaterial(t="NodeMaterial"){return yT(t)}format(t,e,s){if((e=this.getVectorType(e))===(s=this.getVectorType(s))||null===s||this.isReference(s))return t;const i=this.getTypeLength(e),r=this.getTypeLength(s);return i>4||r>4||0===r?t:i===r?`${this.getType(s)}( ${t} )`:i>r?this.format(`${t}.${"xyz".slice(0,r)}`,this.getTypeFromLength(r,this.getComponentType(e)),s):4===r&&i>1?`${this.getType(s)}( ${this.format(t,e,"vec3")}, 1.0 )`:2===i?`${this.getType(s)}( ${this.format(t,e,"vec2")}, 0.0 )`:(1===i&&r>1&&e!==this.getComponentType(s)&&(t=`${this.getType(this.getComponentType(s))}( ${t} )`),`${this.getType(s)}( ${t} )`)}getSignature(){return`// Three.js r${t} - Node System\n`}}class P_{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(t,e){let s=t.get(e);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},t.set(e,s)),s}updateBeforeNode(t){const e=t.getUpdateBeforeType(),s=t.updateReference(this);if(e===$d.FRAME){const{frameMap:e}=this._getMaps(this.updateBeforeMap,s);e.get(s)!==this.frameId&&!1!==t.updateBefore(this)&&e.set(s,this.frameId)}else if(e===$d.RENDER){const{renderMap:e}=this._getMaps(this.updateBeforeMap,s);e.get(s)!==this.renderId&&!1!==t.updateBefore(this)&&e.set(s,this.renderId)}else e===$d.OBJECT&&t.updateBefore(this)}updateAfterNode(t){const e=t.getUpdateAfterType(),s=t.updateReference(this);if(e===$d.FRAME){const{frameMap:e}=this._getMaps(this.updateAfterMap,s);e.get(s)!==this.frameId&&!1!==t.updateAfter(this)&&e.set(s,this.frameId)}else if(e===$d.RENDER){const{renderMap:e}=this._getMaps(this.updateAfterMap,s);e.get(s)!==this.renderId&&!1!==t.updateAfter(this)&&e.set(s,this.renderId)}else e===$d.OBJECT&&t.updateAfter(this)}updateNode(t){const e=t.getUpdateType(),s=t.updateReference(this);if(e===$d.FRAME){const{frameMap:e}=this._getMaps(this.updateMap,s);e.get(s)!==this.frameId&&!1!==t.update(this)&&e.set(s,this.frameId)}else if(e===$d.RENDER){const{renderMap:e}=this._getMaps(this.updateMap,s);e.get(s)!==this.renderId&&!1!==t.update(this)&&e.set(s,this.renderId)}else e===$d.OBJECT&&t.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class F_{constructor(t,e,s=null,i="",r=!1){this.type=t,this.name=e,this.count=s,this.qualifier=i,this.isConst=r}}F_.isNodeFunctionInput=!0;class U_ extends hp{constructor(t){super(),this.types=t,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}up("StructTypeNode",U_);class O_ extends hp{constructor(...t){super(),this.members=t,this.isOutputStructNode=!0}setup(t){super.setup(t);const e=this.members,s=[];for(let i=0;iCy(gf(4,t.mul(mf(1,t))),e),j_=(t,e)=>t.lessThan(.5)?W_(t.mul(2),e).div(2):mf(1,W_(gf(mf(1,t),2),e).div(2)),H_=(t,e,s)=>Cy(ff(Cy(t,e),pf(Cy(t,e),Cy(mf(1,t),s))),1/e),q_=(t,e)=>ty(Lf.mul(e.mul(t).sub(1))).div(Lf.mul(e.mul(t).sub(1)));_p("parabola",W_),_p("gain",j_),_p("pcurve",H_),_p("sinc",q_);const $_=Kp((([t])=>t.fract().sub(.5).abs())),X_=Kp((([t])=>pm($_(t.z.add($_(t.y.mul(1)))),$_(t.z.add($_(t.x.mul(1)))),$_(t.y.add($_(t.x.mul(1))))))),Y_=Kp((([t,e,s])=>{const i=pm(t).toVar(),r=nm(1.4).toVar(),n=nm(0).toVar(),o=pm(i).toVar();return dv({start:nm(0),end:nm(3),type:"float",condition:"<="},(()=>{const t=pm(X_(o.mul(2))).toVar();i.addAssign(t.add(s.mul(nm(.1).mul(e)))),o.mulAssign(1.8),r.mulAssign(1.5),i.mulAssign(1.2);const a=nm($_(i.z.add($_(i.x.add($_(i.y)))))).toVar();n.addAssign(a.div(r)),o.addAssign(.14)})),n}));let J_;$_.setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),X_.setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Y_.setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class Z_ extends PT{constructor(t){J_=J_||tx("discard"),super(t,J_)}}const Q_=Zp(Z_),K_=t=>Q_(t).append(),tw=()=>tx("return").append();_p("discard",K_),up("DiscardNode",Z_);class ew extends hp{constructor(t=[],...e){super(),this.functionNodes=t,this.parametersNodes=e,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(t){const e=this.parametersNodes;let s=this._candidateFnCall;if(null===s){let i=null,r=-1;for(const s of this.functionNodes){const n=s.shaderNode.layout;if(null===n)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=n.inputs;if(e.length===o.length){let n=0;for(let s=0;sr&&(i=s,r=n)}}this._candidateFnCall=s=i(...e)}return s}}const sw=Zp(ew),iw=t=>(...e)=>sw(t,...e);up("FunctionOverloadingNode",ew);class rw extends cp{constructor(){super("vec2")}setup(){const t=pm(jb.z,0,jb.x.negate()).normalize(),e=jb.cross(t);return um(t.dot(Yx),e.dot(Yx)).mul(.495).add(.5)}}const nw=Qp(rw);up("MatcapUVNode",rw);class ow extends af{constructor(t=ow.LOCAL,e=1,s=0){super(s),this.scope=t,this.scale=e,this.updateType=$d.FRAME}update(t){const e=this.scope,s=this.scale;e===ow.LOCAL?this.value+=t.deltaTime*s:e===ow.DELTA?this.value=t.deltaTime*s:e===ow.FRAME?this.value=t.frameId:this.value=t.time*s}serialize(t){super.serialize(t),t.scope=this.scope,t.scale=this.scale}deserialize(t){super.deserialize(t),this.scope=t.scope,this.scale=t.scale}}ow.LOCAL="local",ow.GLOBAL="global",ow.DELTA="delta",ow.FRAME="frame";const aw=(t,e=0)=>Xp(new ow(ow.LOCAL,t,e)),hw=(t,e=0)=>Xp(new ow(ow.GLOBAL,t,e)),uw=(t,e=0)=>Xp(new ow(ow.DELTA,t,e)),lw=Qp(ow,ow.FRAME).toUint();up("TimerNode",ow);class cw extends hp{constructor(t=cw.SINE,e=aw()){super(),this.method=t,this.timeNode=e}getNodeType(t){return this.timeNode.getNodeType(t)}setup(){const t=this.method,e=Xp(this.timeNode);let s=null;return t===cw.SINE?s=e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5):t===cw.SQUARE?s=e.fract().round():t===cw.TRIANGLE?s=e.add(.5).fract().mul(2).sub(1).abs():t===cw.SAWTOOTH&&(s=e.fract()),s}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}cw.SINE="sine",cw.SQUARE="square",cw.TRIANGLE="triangle",cw.SAWTOOTH="sawtooth";const dw=Zp(cw,cw.SINE),pw=Zp(cw,cw.SQUARE),mw=Zp(cw,cw.TRIANGLE),gw=Zp(cw,cw.SAWTOOTH);up("OscNode",cw);class fw extends cp{constructor(t,e){super(),this.scope=t,this.node=e}getNodeType(t){return this.node.getNodeType(t)}setup(){const{scope:t,node:e}=this;let s=null;return t===fw.DIRECTION_TO_COLOR?s=e.mul(.5).add(.5):t===fw.COLOR_TO_DIRECTION&&(s=e.mul(2).sub(1)),s}}fw.DIRECTION_TO_COLOR="directionToColor",fw.COLOR_TO_DIRECTION="colorToDirection";const yw=Zp(fw,fw.DIRECTION_TO_COLOR),xw=Zp(fw,fw.COLOR_TO_DIRECTION);_p("directionToColor",yw),_p("colorToDirection",xw),up("PackingNode",fw);class bw extends hp{constructor(t,e,s,i=nm(0),r=nm(1)){super(),this.node=t,this.inLowNode=e,this.inHighNode=s,this.outLowNode=i,this.outHighNode=r,this.doClamp=!0}setup(){const{node:t,inLowNode:e,inHighNode:s,outLowNode:i,outHighNode:r,doClamp:n}=this;let o=t.sub(e).div(s.sub(e));return!0===n&&(o=o.clamp()),o.mul(r.sub(i)).add(i)}}const vw=Zp(bw,null,null,{doClamp:!1}),Tw=Zp(bw);_p("remap",vw),_p("remapClamp",Tw),up("RemapNode",bw);class _w extends cp{constructor(t,e,s=um(.5)){super("vec2"),this.uvNode=t,this.rotationNode=e,this.centerNode=s}setup(){const{uvNode:t,rotationNode:e,centerNode:s}=this;return t.sub(s).rotate(e).add(s)}}const ww=Zp(_w);_p("rotateUV",ww),up("RotateUVNode",_w);class Sw extends cp{constructor(t,e){super(),this.positionNode=t,this.rotationNode=e}getNodeType(t){return this.positionNode.getNodeType(t)}setup(t){const{rotationNode:e,positionNode:s}=this;if("vec2"===this.getNodeType(t)){const t=e.cos(),i=e.sin();return Tm(t,i,i.negate(),t).mul(s)}{const t=e,i=Cm(ym(1,0,0,0),ym(0,ey(t.x),ty(t.x).negate(),0),ym(0,ty(t.x),ey(t.x),0),ym(0,0,0,1)),r=Cm(ym(ey(t.y),0,ty(t.y),0),ym(0,1,0,0),ym(ty(t.y).negate(),0,ey(t.y),0),ym(0,0,0,1)),n=Cm(ym(ey(t.z),ty(t.z).negate(),0,0),ym(ty(t.z),ey(t.z),0,0),ym(0,0,1,0),ym(0,0,0,1));return i.mul(r).mul(n).mul(ym(s,1)).xyz}}}const Mw=Zp(Sw);_p("rotate",Mw),up("RotateNode",Sw);class Aw extends hp{constructor(t,e=uf(),s=nm(0)){super("vec2"),this.countNode=t,this.uvNode=e,this.frameNode=s}setup(){const{frameNode:t,uvNode:e,countNode:s}=this,{width:i,height:r}=s,n=t.mod(i.mul(r)).floor(),o=n.mod(i),a=r.sub(n.add(1).div(i).ceil()),h=s.reciprocal(),u=um(o,a);return e.add(u).mul(h)}}const Nw=Zp(Aw);up("SpriteSheetUVNode",Aw);class Rw extends dp{constructor(t,e){super(t,e),this.isStorageArrayElementNode=!0}set storageBufferNode(t){this.node=t}get storageBufferNode(){return this.node}setup(t){return!1===t.isAvailable("storageBuffer")&&(this.node.instanceIndex||!0!==this.node.bufferObject||t.setupPBO(this.node)),super.setup(t)}generate(t,e){let s;const i=t.context.assign;if(!1===t.isAvailable("storageBuffer")){const{node:e}=this;s=e.instanceIndex||!0!==this.node.bufferObject||!0===i?e.build(t):t.generatePBO(this)}else s=super.generate(t);if(!0!==i){const i=this.getNodeType(t);s=t.format(s,i,e)}return s}}const Cw=Zp(Rw);_p("storageElement",Cw),up("StorageArrayElementNode",Rw);class Ew extends hp{constructor(t,e=null,s=null,i=nm(1),r=Db,n=qx){super("vec4"),this.textureXNode=t,this.textureYNode=e,this.textureZNode=s,this.scaleNode=i,this.positionNode=r,this.normalNode=n}setup(){const{textureXNode:t,textureYNode:e,textureZNode:s,scaleNode:i,positionNode:r,normalNode:n}=this;let o=n.abs().normalize();o=o.div(o.dot(pm(1)));const a=r.yz.mul(i),h=r.zx.mul(i),u=r.xy.mul(i),l=t.value,c=null!==e?e.value:l,d=null!==s?s.value:l,p=rx(l,a).mul(o.x),m=rx(c,h).mul(o.y),g=rx(d,u).mul(o.z);return pf(p,m,g)}}const Bw=Zp(Ew),Iw=(...t)=>Bw(...t);_p("triplanarTexture",Iw),up("TriplanarTexturesNode",Ew);const Pw=new sa,Fw=new Ei,Uw=new Ei,Ow=new Ei,Lw=new or,zw=new Ei(0,0,-1),Vw=new _i,Dw=new Ei,kw=new Ei,Gw=new _i,Ww=new Ks,jw=new wi,Hw=um(jv.x.oneMinus(),jv.y);let qw=!1;class $w extends ix{constructor(t={}){super(jw.texture,Hw);const{target:e=new Pr,resolution:s=1,generateMipmaps:i=!1,bounces:r=!0}=t;this.target=e,this.resolution=s,this.generateMipmaps=i,this.bounces=r,this.updateBeforeType=r?$d.RENDER:$d.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(t,e){const s=this.resolution;e.getDrawingBufferSize(Ww),t.setSize(Math.round(Ww.width*s),Math.round(Ww.height*s))}setup(t){return this._updateResolution(jw,t.renderer),super.setup(t)}getTextureNode(){return this.textureNode}getVirtualCamera(t){let e=this.virtualCameras.get(t);return void 0===e&&(e=t.clone(),this.virtualCameras.set(t,e)),e}getRenderTarget(t){let e=this.renderTargets.get(t);return void 0===e&&(e=new wi(0,0,{type:Pt}),!0===this.generateMipmaps&&(e.texture.minFilter=1008,e.texture.generateMipmaps=!0),this.renderTargets.set(t,e)),e}updateBefore(t){if(!1===this.bounces&&qw)return!1;qw=!0;const{scene:e,camera:s,renderer:i,material:r}=t,{target:n}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(i.getDrawingBufferSize(Ww),this._updateResolution(a,i),Uw.setFromMatrixPosition(n.matrixWorld),Ow.setFromMatrixPosition(s.matrixWorld),Lw.extractRotation(n.matrixWorld),Fw.set(0,0,1),Fw.applyMatrix4(Lw),Dw.subVectors(Uw,Ow),Dw.dot(Fw)>0)return;Dw.reflect(Fw).negate(),Dw.add(Uw),Lw.extractRotation(s.matrixWorld),zw.set(0,0,-1),zw.applyMatrix4(Lw),zw.add(Ow),kw.subVectors(Uw,zw),kw.reflect(Fw).negate(),kw.add(Uw),o.coordinateSystem=s.coordinateSystem,o.position.copy(Dw),o.up.set(0,1,0),o.up.applyMatrix4(Lw),o.up.reflect(Fw),o.lookAt(kw),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),Pw.setFromNormalAndCoplanarPoint(Fw,Uw),Pw.applyMatrix4(o.matrixWorldInverse),Vw.set(Pw.normal.x,Pw.normal.y,Pw.normal.z,Pw.constant);const h=o.projectionMatrix;Gw.x=(Math.sign(Vw.x)+h.elements[8])/h.elements[0],Gw.y=(Math.sign(Vw.y)+h.elements[9])/h.elements[5],Gw.z=-1,Gw.w=(1+h.elements[10])/h.elements[14],Vw.multiplyScalar(1/Vw.dot(Gw));h.elements[2]=Vw.x,h.elements[6]=Vw.y,h.elements[10]=Vw.z-0,h.elements[14]=Vw.w,this.value=a.texture,r.visible=!1;const u=i.getRenderTarget();i.setRenderTarget(a),i.render(e,o),i.setRenderTarget(u),r.visible=!0,qw=!1}}const Xw=t=>Xp(new $w(t)),Yw=new Rl(-1,1,1,-1,0,1);const Jw=new class extends Mn{constructor(t=!1){super();const e=!1===t?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new yn([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new yn(e,2))}};class Zw extends Wn{constructor(t=null){super(Jw,t),this.camera=Yw}renderAsync(t){return t.renderAsync(this,Yw)}render(t){t.render(this,Yw)}}const Qw=new Ks;class Kw extends ix{constructor(t,e=null,s=null,i={type:Pt}){const r=new wi(e,s,i);super(r.texture,uf()),this.node=t,this.width=e,this.height=s,this.renderTarget=r,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new Zw(new gT),this.updateBeforeType=$d.RENDER}get autoSize(){return null===this.width}setup(t){return this._rttNode=this.node.context(t.getSharedContext()),this._quadMesh.material.needsUpdate=!0,super.setup(t)}setSize(t,e){this.width=t,this.height=e;const s=t*this.pixelRatio,i=e*this.pixelRatio;this.renderTarget.setSize(s,i),this.textureNeedsUpdate=!0}setPixelRatio(t){this.pixelRatio=t,this.setSize(this.width,this.height)}updateBefore({renderer:t}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=t.getPixelRatio();const e=t.getSize(Qw);this.setSize(e.width,e.height)}this._quadMesh.material.fragmentNode=this._rttNode;const e=t.getRenderTarget();t.setRenderTarget(this.renderTarget),this._quadMesh.render(t),t.setRenderTarget(e)}clone(){const t=new ix(this.value,this.uvNode,this.levelNode);return t.sampler=this.sampler,t.referenceNode=this,t}}const tS=(t,...e)=>Xp(new Kw(Xp(t),...e));_p("toTexture",((t,...e)=>t.isTextureNode?t:tS(t,...e))),up("RTTNode",Kw);const eS=t=>t.mul(tv.w).xyz,sS=km(eS(Hx.cross(tv)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),iS=km(eS(qx.cross(ev)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),rS=km(eS($x.cross(sv)),"v_bitangentView").normalize().toVar("bitangentView"),nS=km(eS(Xx.cross(iv)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),oS=eS(Yx.cross(rv)).normalize().toVar("transformedBitangentView"),aS=oS.transformDirection(Sx).normalize().toVar("transformedBitangentWorld"),hS=Mm(sv,rS,$x),uS=jb.mul(hS),lS=(t,e)=>t.sub(uS.mul(e)),cS=(()=>{let t=Cg.cross(jb);return t=t.cross(Cg).normalize(),t=Oy(t,Yx,Ng.mul(yg.oneMinus()).oneMinus().pow2().pow2()).normalize(),t})();class dS extends Gm{constructor(t=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=t}getAttributeName(){const t=this.index;return"color"+(t>0?t:"")}generate(t){const e=this.getAttributeName(t);let s;return s=!0===t.hasGeometryAttribute(e)?super.generate(t):t.generateConst(this.nodeType,new _i(1,1,1,1)),s}serialize(t){super.serialize(t),t.index=this.index}deserialize(t){super.deserialize(t),this.index=t.index}}const pS=(...t)=>Xp(new dS(...t));up("VertexColorNode",dS);class mS extends px{constructor(t,e,s=null){super(t,e,s),this.renderer=s}updateReference(t){return this.reference=null!==this.renderer?this.renderer:t.renderer,this.reference}}const gS=(t,e,s)=>Xp(new mS(t,e,s));up("RendererReferenceNode",mS);const fS=1/6,yS=t=>gf(fS,gf(t,gf(t,t.negate().add(3)).sub(3)).add(1)),xS=t=>gf(fS,gf(t,gf(t,gf(3,t).sub(6))).add(4)),bS=t=>gf(fS,gf(t,gf(t,gf(-3,t).add(3)).add(3)).add(1)),vS=t=>gf(fS,Cy(t,3)),TS=t=>yS(t).add(xS(t)),_S=t=>bS(t).add(vS(t)),wS=t=>pf(-1,xS(t).div(yS(t).add(xS(t)))),SS=t=>pf(1,vS(t).div(bS(t).add(vS(t)))),MS=(t,e,s)=>{const i=t.uvNode,r=gf(i,e.zw).add(.5),n=Jf(r),o=Kf(r),a=TS(o.x),h=_S(o.x),u=wS(o.x),l=SS(o.x),c=wS(o.y),d=SS(o.y),p=um(n.x.add(u),n.y.add(c)).sub(.5).mul(e.xy),m=um(n.x.add(l),n.y.add(c)).sub(.5).mul(e.xy),g=um(n.x.add(u),n.y.add(d)).sub(.5).mul(e.xy),f=um(n.x.add(l),n.y.add(d)).sub(.5).mul(e.xy),y=TS(o.y).mul(pf(a.mul(t.uv(p).level(s)),h.mul(t.uv(m).level(s)))),x=_S(o.y).mul(pf(a.mul(t.uv(g).level(s)),h.mul(t.uv(f).level(s))));return y.add(x)};class AS extends cp{constructor(t,e=nm(3)){super("vec4"),this.textureNode=t,this.blurNode=e}setup(){return((t,e)=>{const s=um(t.size(om(e))),i=um(t.size(om(e.add(1)))),r=ff(1,s),n=ff(1,i),o=MS(t,ym(r,s),Jf(e)),a=MS(t,ym(n,i),Zf(e));return Kf(e).mix(o,a)})(this.textureNode,this.blurNode)}}const NS=Zp(AS);_p("bicubic",NS),up("TextureBicubicNode",AS);class RS extends hp{constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const CS=Qp(RS);up("PointUVNode",RS);class ES extends hp{constructor(t=ES.BACKGROUND_BLURRINESS,e=null){super(),this.scope=t,this.scene=e}setup(t){const e=this.scope,s=null!==this.scene?this.scene:t.scene;let i;return e===ES.BACKGROUND_BLURRINESS?i=mx("backgroundBlurriness","float",s):e===ES.BACKGROUND_INTENSITY?i=mx("backgroundIntensity","float",s):console.error("THREE.SceneNode: Unknown scope:",e),i}}ES.BACKGROUND_BLURRINESS="backgroundBlurriness",ES.BACKGROUND_INTENSITY="backgroundIntensity";const BS=Qp(ES,ES.BACKGROUND_BLURRINESS),IS=Qp(ES,ES.BACKGROUND_INTENSITY);up("SceneNode",ES);const PS="point-list",FS="line-list",US="line-strip",OS="triangle-list",LS="triangle-strip",zS="never",VS="less",DS="equal",kS="less-equal",GS="greater",WS="not-equal",jS="greater-equal",HS="always",qS="store",$S="load",XS="clear",YS="ccw",JS="none",ZS="front",QS="back",KS="uint16",tM="uint32",eM={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},sM="clamp-to-edge",iM="repeat",rM="mirror-repeat",nM="linear",oM="nearest",aM="zero",hM="one",uM="src",lM="one-minus-src",cM="src-alpha",dM="one-minus-src-alpha",pM="dst",mM="one-minus-dst",gM="dst-alpha",fM="one-minus-dst-alpha",yM="src-alpha-saturated",xM="constant",bM="one-minus-constant",vM="add",TM="subtract",_M="reverse-subtract",wM="min",SM="max",MM=0,AM=15,NM="keep",RM="zero",CM="replace",EM="invert",BM="increment-clamp",IM="decrement-clamp",PM="increment-wrap",FM="decrement-wrap",UM="storage",OM="read-only-storage",LM="write-only",zM="read-only",VM="unfilterable-float",DM="depth",kM="sint",GM="uint",WM="2d",jM="3d",HM="2d",qM="2d-array",$M="cube",XM="3d",YM="all",JM="vertex",ZM="instance",QM={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable"};class KM extends ax{constructor(t,e,s=0){super(t,e,s),this.isStorageBufferNode=!0,this.access=UM,this.bufferObject=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==t.isStorageBufferAttribute&&!0!==t.isStorageInstancedBufferAttribute&&(t.isInstancedBufferAttribute?t.isStorageInstancedBufferAttribute=!0:t.isStorageBufferAttribute=!0)}getHash(t){if(0===this.bufferCount){let e=t.globalCache.getData(this.value);return void 0===e&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getInputType(){return"storageBuffer"}element(t){return Cw(this,t)}setBufferObject(t){return this.bufferObject=t,this}setAccess(t){return this.access=t,this}toReadOnly(){return this.setAccess(OM)}generate(t){if(t.isAvailable("storageBuffer"))return super.generate(t);const e=this.getNodeType(t);null===this._attribute&&(this._attribute=Xb(this.value),this._varying=km(this._attribute));const s=this._varying.build(t,e);return t.registerTransform(s,this._attribute),s}}const tA=(t,e,s)=>Xp(new KM(t,e,s)),eA=(t,e,s)=>Xp(new KM(t,e,s).setBufferObject(!0));up("StorageBufferNode",KM);class sA extends ix{constructor(t,e,s=null){super(t,e),this.storeNode=s,this.isStorageTextureNode=!0,this.access=LM}getInputType(){return"storageTexture"}setup(t){super.setup(t);t.getNodeProperties(this).storeNode=this.storeNode}setAccess(t){return this.access=t,this}generate(t,e){let s;return s=null!==this.storeNode?this.generateStore(t):super.generate(t,e),s}toReadOnly(){return this.setAccess(zM)}toWriteOnly(){return this.setAccess(LM)}generateStore(t){const e=t.getNodeProperties(this),{uvNode:s,storeNode:i}=e,r=super.generate(t,"property"),n=s.build(t,"uvec2"),o=i.build(t,"vec4"),a=t.generateTextureStore(t,r,n,o);t.addLineFlowCode(a)}}const iA=Zp(sA),rA=(t,e,s)=>{const i=iA(t,e,s);return null!==s&&i.append(),i};up("StorageTextureNode",sA);const nA=Kp((({texture:t,uv:e})=>{const s=1e-4,i=pm().temp();return sm(e.x.lessThan(s),(()=>{i.assign(pm(1,0,0))})).elseif(e.y.lessThan(s),(()=>{i.assign(pm(0,1,0))})).elseif(e.z.lessThan(s),(()=>{i.assign(pm(0,0,1))})).elseif(e.x.greaterThan(.9999),(()=>{i.assign(pm(-1,0,0))})).elseif(e.y.greaterThan(.9999),(()=>{i.assign(pm(0,-1,0))})).elseif(e.z.greaterThan(.9999),(()=>{i.assign(pm(0,0,-1))})).else((()=>{const s=.01,r=t.uv(e.add(pm(-.01,0,0))).r.sub(t.uv(e.add(pm(s,0,0))).r),n=t.uv(e.add(pm(0,-.01,0))).r.sub(t.uv(e.add(pm(0,s,0))).r),o=t.uv(e.add(pm(0,0,-.01))).r.sub(t.uv(e.add(pm(0,0,s))).r);i.assign(pm(r,n,o))})),i.normalize()}));class oA extends ix{constructor(t,e=null,s=null){super(t,e,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return pm(.5,.5,.5)}setUpdateMatrix(){}setupUV(t,e){return e}generateUV(t,e){return e.build(t,"vec3")}normal(t){return nA({texture:this,uv:t})}}const aA=Zp(oA);up("Texture3DNode",oA);class hA extends px{constructor(t,e,s=null){super(t,e,s),this.userData=s}update(t){this.reference=null!==this.userData?this.userData:t.object.userData,super.update(t)}}const uA=(t,e,s)=>Xp(new hA(t,e,s));up("UserDataNode",hA);const lA=Kp((({base:t,blend:e})=>{const s=s=>e[s].lessThan(Uf).cond(e[s],t[s].oneMinus().div(e[s]).oneMinus().max(0));return pm(s("x"),s("y"),s("z"))})).setLayout({name:"burnColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),cA=Kp((({base:t,blend:e})=>{const s=s=>e[s].equal(1).cond(e[s],t[s].div(e[s].oneMinus()).max(0));return pm(s("x"),s("y"),s("z"))})).setLayout({name:"dodgeColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),dA=Kp((({base:t,blend:e})=>{const s=s=>t[s].oneMinus().mul(e[s].oneMinus()).oneMinus();return pm(s("x"),s("y"),s("z"))})).setLayout({name:"screenColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),pA=Kp((({base:t,blend:e})=>{const s=s=>t[s].lessThan(.5).cond(t[s].mul(e[s],2),t[s].oneMinus().mul(e[s].oneMinus()).oneMinus());return pm(s("x"),s("y"),s("z"))})).setLayout({name:"overlayColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]});class mA extends cp{constructor(t,e,s){super(),this.blendMode=t,this.baseNode=e,this.blendNode=s}setup(){const{blendMode:t,baseNode:e,blendNode:s}=this,i={base:e,blend:s};let r=null;return t===mA.BURN?r=lA(i):t===mA.DODGE?r=cA(i):t===mA.SCREEN?r=dA(i):t===mA.OVERLAY&&(r=pA(i)),r}}mA.BURN="burn",mA.DODGE="dodge",mA.SCREEN="screen",mA.OVERLAY="overlay";const gA=Zp(mA,mA.BURN),fA=Zp(mA,mA.DODGE),yA=Zp(mA,mA.OVERLAY),xA=Zp(mA,mA.SCREEN);_p("burn",gA),_p("dodge",fA),_p("overlay",yA),_p("screen",xA),up("BlendModeNode",mA);const bA=Kp((({textureNode:t,bumpScale:e})=>{const s=e=>t.cache().context({getUV:t=>e(t.uvNode||uf()),forceUVContext:!0}),i=nm(s((t=>t)));return um(nm(s((t=>t.add(t.dFdx())))).sub(i),nm(s((t=>t.add(t.dFdy())))).sub(i)).mul(e)})),vA=Kp((t=>{const{surf_pos:e,surf_norm:s,dHdxy:i}=t,r=e.dFdx().normalize(),n=s,o=e.dFdy().normalize().cross(n),a=n.cross(r),h=r.dot(o).mul(pT),u=h.sign().mul(i.x.mul(o).add(i.y.mul(a)));return h.abs().mul(s).sub(u).normalize()}));class TA extends cp{constructor(t,e=null){super("vec3"),this.textureNode=t,this.scaleNode=e}setup(){const t=null!==this.scaleNode?this.scaleNode:1,e=bA({textureNode:this.textureNode,bumpScale:t});return vA({surf_pos:Wb,surf_norm:$x,dHdxy:e})}}const _A=Zp(TA);_p("bumpMap",_A),up("BumpMapNode",TA);const wA=Kp((({color:t,adjustment:e})=>e.mix(BA(t.rgb),t.rgb))),SA=Kp((({color:t,adjustment:e})=>{const s=pf(t.r,t.g,t.b).div(3),i=t.r.max(t.g.max(t.b)),r=i.sub(s).mul(e).mul(-3);return Oy(t.rgb,i,r)})),MA=Kp((({color:t,adjustment:e})=>{const s=pm(.57735,.57735,.57735),i=e.cos();return pm(t.rgb.mul(i).add(s.cross(t.rgb).mul(e.sin()).add(s.mul(Ny(s,t.rgb).mul(i.oneMinus())))))}));class AA extends cp{constructor(t,e,s=nm(1)){super("vec3"),this.method=t,this.colorNode=e,this.adjustmentNode=s}setup(){const{method:t,colorNode:e,adjustmentNode:s}=this,i={color:e,adjustment:s};let r=null;return t===AA.SATURATION?r=wA(i):t===AA.VIBRANCE?r=SA(i):t===AA.HUE?r=MA(i):console.error(`${this.type}: Method "${this.method}" not supported!`),r}}AA.SATURATION="saturation",AA.VIBRANCE="vibrance",AA.HUE="hue";const NA=Zp(AA,AA.SATURATION),RA=Zp(AA,AA.VIBRANCE),CA=Zp(AA,AA.HUE),EA=pm(.2125,.7154,.0721),BA=(t,e=EA)=>Ny(t,e),IA=(t,e)=>Oy(pm(0),t,BA(t).sub(e).max(0));_p("saturation",NA),_p("vibrance",RA),_p("hue",CA),_p("threshold",IA),up("ColorAdjustmentNode",AA);const PA=Kp((t=>{const{eye_pos:e,surf_norm:s,mapN:i,uv:r}=t,n=e.dFdx(),o=e.dFdy(),a=r.dFdx(),h=r.dFdy(),u=s,l=o.cross(u),c=u.cross(n),d=l.mul(a.x).add(c.mul(h.x)),p=l.mul(a.y).add(c.mul(h.y)),m=d.dot(d).max(p.dot(p)),g=pT.mul(m.inverseSqrt());return pf(d.mul(i.x,g),p.mul(i.y,g),u.mul(i.z)).normalize()}));class FA extends cp{constructor(t,e=null){super("vec3"),this.node=t,this.scaleNode=e,this.normalMapType=0}setup(t){const{normalMapType:e,scaleNode:s}=this;let i=this.node.mul(2).sub(1);null!==s&&(i=pm(i.xy.mul(s),i.z));let r=null;if(1===e)r=Vx.mul(i).normalize();else if(0===e){r=!0===t.hasGeometryAttribute("tangent")?hS.mul(i).normalize():PA({eye_pos:Wb,surf_norm:$x,mapN:i,uv:uf()})}return r}}const UA=Zp(FA);_p("normalMap",UA),up("NormalMapNode",FA);class OA extends cp{constructor(t,e){super(),this.sourceNode=t,this.stepsNode=e}setup(){const{sourceNode:t,stepsNode:e}=this;return t.mul(e).floor().div(e)}}const LA=Zp(OA);_p("posterize",LA),up("PosterizeNode",OA);const zA=Kp((({color:t,exposure:e})=>t.mul(e).clamp())),VA=Kp((({color:t,exposure:e})=>(t=t.mul(e)).div(t.add(1)).clamp())),DA=Kp((({color:t,exposure:e})=>{const s=(t=(t=t.mul(e)).sub(.004).max(0)).mul(t.mul(6.2).add(.5)),i=t.mul(t.mul(6.2).add(1.7)).add(.06);return s.div(i).pow(2.2)})),kA=Kp((({color:t})=>{const e=t.mul(t.add(.0245786)).sub(90537e-9),s=t.mul(t.add(.432951).mul(.983729)).add(.238081);return e.div(s)})),GA=Kp((({color:t,exposure:e})=>{const s=Mm(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),i=Mm(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return t=t.mul(e).div(.6),t=s.mul(t),t=kA({color:t}),(t=i.mul(t)).clamp()})),WA=Mm(pm(1.6605,-.1246,-.0182),pm(-.5876,1.1329,-.1006),pm(-.0728,-.0083,1.1187)),jA=Mm(pm(.6274,.0691,.0164),pm(.3293,.9195,.088),pm(.0433,.0113,.8956)),HA=Kp((([t])=>{const e=pm(t).toVar(),s=pm(e.mul(e)).toVar(),i=pm(s.mul(s)).toVar();return nm(15.5).mul(i.mul(s)).sub(gf(40.14,i.mul(e))).add(gf(31.96,i).sub(gf(6.868,s.mul(e))).add(gf(.4298,s).add(gf(.1191,e).sub(.00232))))})),qA=Kp((({color:t,exposure:e})=>{const s=pm(t).toVar(),i=Mm(pm(.856627153315983,.137318972929847,.11189821299995),pm(.0951212405381588,.761241990602591,.0767994186031903),pm(.0482516061458583,.101439036467562,.811302368396859)),r=Mm(pm(1.1271005818144368,-.1413297634984383,-.14132976349843826),pm(-.11060664309660323,1.157823702216272,-.11060664309660294),pm(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=nm(-12.47393),o=nm(4.026069);return s.mulAssign(e),s.assign(jA.mul(s)),s.assign(i.mul(s)),s.assign(Ty(s,1e-10)),s.assign($f(s)),s.assign(s.sub(n).div(o.sub(n))),s.assign(Ly(s,0,1)),s.assign(HA(s)),s.assign(r.mul(s)),s.assign(Cy(Ty(pm(0),s),pm(2.2))),s.assign(WA.mul(s)),s.assign(Ly(s,0,1)),s})),$A=Kp((({color:t,exposure:e})=>{const s=nm(.76),i=nm(.15);t=t.mul(e);const r=vy(t.r,vy(t.g,t.b)),n=FT(r.lessThan(.08),r.sub(gf(6.25,r.mul(r))),.04);t.subAssign(n);const o=Ty(t.r,Ty(t.g,t.b));sm(o.lessThan(s),(()=>t));const a=mf(1,s),h=mf(1,a.mul(a).div(o.add(a.sub(s))));t.mulAssign(h.div(o));const u=mf(1,ff(1,i.mul(o.sub(h)).add(1)));return Oy(t,pm(h),u)})).setLayout({name:"NeutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),XA={1:zA,2:VA,3:DA,4:GA,6:qA,7:$A};class YA extends cp{constructor(t=0,e=ZA,s=null){super("vec3"),this.toneMapping=t,this.exposureNode=e,this.colorNode=s}getCacheKey(){let t=super.getCacheKey();return t="{toneMapping:"+this.toneMapping+",nodes:"+t+"}",t}setup(t){const e=this.colorNode||t.context.color,s=this.toneMapping;if(0===s)return e;const i={exposure:this.exposureNode,color:e},r=XA[s];let n=null;return r?n=r(i):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),n=e),n}}const JA=(t,e,s)=>Xp(new YA(t,Xp(e),Xp(s))),ZA=gS("toneMappingExposure","float");_p("toneMapping",((t,e,s)=>JA(e,s,t))),up("ToneMappingNode",YA);let QA=null;class KA extends Yv{constructor(t=jv,e=null){null===QA&&(QA=new Xa),super(t,e,QA)}updateReference(){return this}}const tN=Zp(KA);_p("viewportSharedTexture",tN),up("ViewportSharedTextureNode",KA);const eN=new Ks;class sN extends ix{constructor(t,e){super(e),this.passNode=t,this.setUpdateMatrix(!1)}setup(t){return this.passNode.build(t),super.setup(t)}clone(){return new this.constructor(this.passNode,this.value)}}class iN extends sN{constructor(t,e){super(t,null),this.textureName=e}setup(t){return this.value=this.passNode.getTexture(this.textureName),super.setup(t)}clone(){return new this.constructor(this.passNode,this.textureName)}}class rN extends cp{constructor(t,e,s,i={}){super("vec4"),this.scope=t,this.scene=e,this.camera=s,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;const r=new Ka;r.isRenderTargetTexture=!0,r.name="depth";const n=new wi(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:Pt,...i});n.texture.name="output",n.depthTexture=r,this.renderTarget=n,this.updateBeforeType=$d.FRAME,this._textures={output:n.texture,depth:r},this._nodes={},this._linearDepthNode=null,this._viewZNode=null,this._cameraNear=hf(0),this._cameraFar=hf(0),this._mrt=null,this.isPassNode=!0}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(t){let e=this._textures[t];if(void 0===e){e=this.renderTarget.texture.clone(),e.isRenderTargetTexture=!0,e.name=t,this._textures[t]=e,this.renderTarget.textures.push(e)}return e}getTextureNode(t="output"){let e=this._nodes[t];return void 0===e&&(this._nodes[t]=e=Xp(new iN(this,t))),e}getViewZNode(){if(null===this._viewZNode){const t=this._cameraNear,e=this._cameraFar;this._viewZNode=nT(this.getTextureNode("depth"),t,e)}return this._viewZNode}getLinearDepthNode(){if(null===this._linearDepthNode){const t=this._cameraNear,e=this._cameraFar;this._linearDepthNode=sT(this.getViewZNode(),t,e)}return this._linearDepthNode}setup({renderer:t}){return this.renderTarget.samples=void 0===this.options.samples?t.samples:this.options.samples,!0===t.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===rN.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){const{renderer:e}=t,{scene:s,camera:i}=this;this._pixelRatio=e.getPixelRatio();const r=e.getSize(eN);this.setSize(r.width,r.height);const n=e.getRenderTarget(),o=e.getMRT();this._cameraNear.value=i.near,this._cameraFar.value=i.far,e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),e.render(s,i),e.setRenderTarget(n),e.setMRT(o)}setSize(t,e){this._width=t,this._height=e;const s=this._width*this._pixelRatio,i=this._height*this._pixelRatio;this.renderTarget.setSize(s,i)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}rN.COLOR="color",rN.DEPTH="depth";const nN=(t,e,s)=>Xp(new rN(rN.COLOR,t,e,s)),oN=(t,e)=>Xp(new sN(t,e)),aN=(t,e)=>Xp(new rN(rN.DEPTH,t,e));up("PassNode",rN);const hN=new Zw,uN=new Zw;class lN extends cp{constructor(t,e=null,s=2){super("vec4"),this.textureNode=t,this.directionNode=e,this.sigma=s,this._invSize=hf(new Ks),this._passDirection=hf(new Ks),this._horizontalRT=new wi,this._horizontalRT.texture.name="GaussianBlurNode.horizontal",this._verticalRT=new wi,this._verticalRT.texture.name="GaussianBlurNode.vertical",this._textureNode=oN(this,this._verticalRT.texture),this.updateBeforeType=$d.RENDER,this.resolution=new Ks(1,1)}setSize(t,e){t=Math.max(Math.round(t*this.resolution.x),1),e=Math.max(Math.round(e*this.resolution.y),1),this._invSize.value.set(1/t,1/e),this._horizontalRT.setSize(t,e),this._verticalRT.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=this.textureNode,i=s.value,r=e.getRenderTarget(),n=e.getMRT(),o=s.value;hN.material=this._material,uN.material=this._material,this.setSize(i.image.width,i.image.height);const a=i.type;this._horizontalRT.texture.type=a,this._verticalRT.texture.type=a,e.setMRT(null),e.setRenderTarget(this._horizontalRT),this._passDirection.value.set(1,0),hN.render(e),s.value=this._horizontalRT.texture,e.setRenderTarget(this._verticalRT),this._passDirection.value.set(0,1),uN.render(e),e.setRenderTarget(r),e.setMRT(n),s.value=o}getTextureNode(){return this._textureNode}setup(t){const e=this.textureNode;if(!0!==e.isTextureNode)return console.error("GaussianBlurNode requires a TextureNode."),ym();const s=e.uvNode||uf(),i=um(this.directionNode||1),r=t=>e.uv(t),n=Kp((()=>{const t=3+2*this.sigma,e=this._getCoefficients(t),n=this._invSize,o=i.mul(this._passDirection),a=nm(e[0]).toVar(),h=ym(r(s).mul(a)).toVar();for(let i=1;iXp(new lN(Xp(t).toTexture(),e,s));_p("gaussianBlur",cN);const dN=new Ks,pN=new Zw;class mN extends cp{constructor(t,e=.96){super(t),this.textureNode=t,this.textureNodeOld=rx(),this.damp=hf(e),this._compRT=new wi,this._compRT.texture.name="AfterImageNode.comp",this._oldRT=new wi,this._oldRT.texture.name="AfterImageNode.old",this._textureNode=oN(this,this._compRT.texture),this.updateBeforeType=$d.RENDER}getTextureNode(){return this._textureNode}setSize(t,e){this._compRT.setSize(t,e),this._oldRT.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=this.textureNode,i=s.value.type;this._compRT.texture.type=i,this._oldRT.texture.type=i,e.getDrawingBufferSize(dN),this.setSize(dN.x,dN.y);const r=e.getRenderTarget(),n=s.value;this.textureNodeOld.value=this._oldRT.texture,e.setRenderTarget(this._compRT),pN.render(e);const o=this._oldRT;this._oldRT=this._compRT,this._compRT=o,e.setRenderTarget(r),s.value=n}setup(t){const e=this.textureNode,s=this.textureNodeOld,i=e.uvNode||uf();s.uvNode=i;const r=Kp((([t,e])=>{const s=nm(e).toVar(),i=ym(t).toVar();return Ty(ay(i.sub(s)),0)})),n=Kp((()=>{const t=ym(s),n=ym((t=>e.uv(t))(i));return t.mulAssign(this.damp.mul(r(t,.1))),Ty(n,t)})),o=this._materialComposed||(this._materialComposed=t.createNodeMaterial());o.fragmentNode=n(),pN.material=o;return t.getNodeProperties(this).textureNode=e,this._textureNode}}const gN=(t,e)=>Xp(new mN(Xp(t).toTexture(),e));_p("afterImage",gN);const fN=new Zw;class yN extends cp{constructor(t,e,s,i){super("vec4"),this.textureNode=t,this.tresholdNode=e,this.scaleNode=s,this.colorNode=pm(.1,0,1),this.samples=i,this.resolution=new Ks(1,1),this._renderTarget=new wi,this._renderTarget.texture.name="anamorphic",this._invSize=hf(new Ks),this._textureNode=oN(this,this._renderTarget.texture),this.updateBeforeType=$d.RENDER}getTextureNode(){return this._textureNode}setSize(t,e){this._invSize.value.set(1/t,1/e),t=Math.max(Math.round(t*this.resolution.x),1),e=Math.max(Math.round(e*this.resolution.y),1),this._renderTarget.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=this.textureNode,i=s.value;this._renderTarget.texture.type=i.type;const r=e.getRenderTarget(),n=s.value;fN.material=this._material,this.setSize(i.image.width,i.image.height),e.setRenderTarget(this._renderTarget),fN.render(e),e.setRenderTarget(r),s.value=n}setup(t){const e=this.textureNode,s=e.uvNode||uf(),i=Kp((()=>{const t=this.samples,i=Math.floor(t/2),r=pm(0).toVar();return dv({start:-i,end:i},(({i:t})=>{const n=nm(t).abs().div(i).oneMinus(),o=(t=>e.uv(t))(um(s.x.add(this._invSize.x.mul(t).mul(this.scaleNode)),s.y)),a=IA(o,this.tresholdNode).mul(n);r.addAssign(a)})),r.mul(this.colorNode)}));(this._material||(this._material=t.createNodeMaterial())).fragmentNode=i();return t.getNodeProperties(this).textureNode=e,this._textureNode}}const xN=(t,e=.9,s=3,i=32)=>Xp(new yN(Xp(t).toTexture(),Xp(e),Xp(s),i));_p("anamorphic",xN);class bN extends cp{constructor(t){super(),this.textureNode=t,this.updateBeforeType=$d.RENDER,this._invSize=hf(new Ks)}updateBefore(){const t=this.textureNode.value;this._invSize.value.set(1/t.image.width,1/t.image.height)}setup(){const{textureNode:t}=this,e=t.uvNode||uf(),s=e=>t.uv(e);return Kp((()=>{const t=this._invSize,i=Mm(-1,-2,-1,0,0,0,1,2,1),r=Mm(-1,0,1,-2,0,2,-1,0,1),n=BA(s(e.add(t.mul(um(-1,-1)))).xyz),o=BA(s(e.add(t.mul(um(-1,0)))).xyz),a=BA(s(e.add(t.mul(um(-1,1)))).xyz),h=BA(s(e.add(t.mul(um(0,-1)))).xyz),u=BA(s(e.add(t.mul(um(0,0)))).xyz),l=BA(s(e.add(t.mul(um(0,1)))).xyz),c=BA(s(e.add(t.mul(um(1,-1)))).xyz),d=BA(s(e.add(t.mul(um(1,0)))).xyz),p=BA(s(e.add(t.mul(um(1,1)))).xyz),m=pf(i[0][0].mul(n),i[1][0].mul(h),i[2][0].mul(c),i[0][1].mul(o),i[1][1].mul(u),i[2][1].mul(d),i[0][2].mul(a),i[1][2].mul(l),i[2][2].mul(p)),g=pf(r[0][0].mul(n),r[1][0].mul(h),r[2][0].mul(c),r[0][1].mul(o),r[1][1].mul(u),r[2][1].mul(d),r[0][2].mul(a),r[1][2].mul(l),r[2][2].mul(p)),f=m.mul(m).add(g.mul(g)).sqrt();return ym(pm(f),1)}))()}}const vN=t=>Xp(new bN(Xp(t).toTexture()));_p("sobel",vN);class TN extends cp{constructor(t,e,s,i,r){super(),this.textureNode=t,this.viewZNode=e,this.focusNode=s,this.apertureNode=i,this.maxblurNode=r,this._aspect=hf(0),this.updateBeforeType=$d.RENDER}updateBefore(){const t=this.textureNode.value;this._aspect.value=t.image.width/t.image.height}setup(){const t=this.textureNode,e=t.uvNode||uf(),s=e=>t.uv(e);return Kp((()=>{const t=um(1,this._aspect),i=this.focusNode.add(this.viewZNode),r=um(Ly(i.mul(this.apertureNode),this.maxblurNode.negate(),this.maxblurNode)),n=r.mul(.9),o=r.mul(.7),a=r.mul(.4);let h=ym(0);return h=h.add(s(e)),h=h.add(s(e.add(um(0,.4).mul(t).mul(r)))),h=h.add(s(e.add(um(.15,.37).mul(t).mul(r)))),h=h.add(s(e.add(um(.29,.29).mul(t).mul(r)))),h=h.add(s(e.add(um(-.37,.15).mul(t).mul(r)))),h=h.add(s(e.add(um(.4,0).mul(t).mul(r)))),h=h.add(s(e.add(um(.37,-.15).mul(t).mul(r)))),h=h.add(s(e.add(um(.29,-.29).mul(t).mul(r)))),h=h.add(s(e.add(um(-.15,-.37).mul(t).mul(r)))),h=h.add(s(e.add(um(0,-.4).mul(t).mul(r)))),h=h.add(s(e.add(um(-.15,.37).mul(t).mul(r)))),h=h.add(s(e.add(um(-.29,.29).mul(t).mul(r)))),h=h.add(s(e.add(um(.37,.15).mul(t).mul(r)))),h=h.add(s(e.add(um(-.4,0).mul(t).mul(r)))),h=h.add(s(e.add(um(-.37,-.15).mul(t).mul(r)))),h=h.add(s(e.add(um(-.29,-.29).mul(t).mul(r)))),h=h.add(s(e.add(um(.15,-.37).mul(t).mul(r)))),h=h.add(s(e.add(um(.15,.37).mul(t).mul(n)))),h=h.add(s(e.add(um(-.37,.15).mul(t).mul(n)))),h=h.add(s(e.add(um(.37,-.15).mul(t).mul(n)))),h=h.add(s(e.add(um(-.15,-.37).mul(t).mul(n)))),h=h.add(s(e.add(um(-.15,.37).mul(t).mul(n)))),h=h.add(s(e.add(um(.37,.15).mul(t).mul(n)))),h=h.add(s(e.add(um(-.37,-.15).mul(t).mul(n)))),h=h.add(s(e.add(um(.15,-.37).mul(t).mul(n)))),h=h.add(s(e.add(um(.29,.29).mul(t).mul(o)))),h=h.add(s(e.add(um(.4,0).mul(t).mul(o)))),h=h.add(s(e.add(um(.29,-.29).mul(t).mul(o)))),h=h.add(s(e.add(um(0,-.4).mul(t).mul(o)))),h=h.add(s(e.add(um(-.29,.29).mul(t).mul(o)))),h=h.add(s(e.add(um(-.4,0).mul(t).mul(o)))),h=h.add(s(e.add(um(-.29,-.29).mul(t).mul(o)))),h=h.add(s(e.add(um(0,.4).mul(t).mul(o)))),h=h.add(s(e.add(um(.29,.29).mul(t).mul(a)))),h=h.add(s(e.add(um(.4,0).mul(t).mul(a)))),h=h.add(s(e.add(um(.29,-.29).mul(t).mul(a)))),h=h.add(s(e.add(um(0,-.4).mul(t).mul(a)))),h=h.add(s(e.add(um(-.29,.29).mul(t).mul(a)))),h=h.add(s(e.add(um(-.4,0).mul(t).mul(a)))),h=h.add(s(e.add(um(-.29,-.29).mul(t).mul(a)))),h=h.add(s(e.add(um(0,.4).mul(t).mul(a)))),h=h.div(41),h.a=1,ym(h)}))()}}const _N=(t,e,s=1,i=.025,r=1)=>Xp(new TN(Xp(t).toTexture(),Xp(e),Xp(s),Xp(i),Xp(r)));_p("dof",_N);class wN extends cp{constructor(t,e=new Ks(.5,.5),s=1.57,i=1){super("vec4"),this.inputNode=t,this.center=hf(e),this.angle=hf(s),this.scale=hf(i),this._size=hf(new Ks),this.updateBeforeType=$d.RENDER}updateBefore(){const t=this.inputNode.value;this._size.value.set(t.image.width,t.image.height)}setup(){const t=this.inputNode,e=Kp((()=>{const t=ty(this.angle),e=ey(this.angle),s=uf().mul(this._size).sub(this.center),i=um(e.mul(s.x).sub(t.mul(s.y)),t.mul(s.x).add(e.mul(s.y))).mul(this.scale);return ty(i.x).mul(ty(i.y)).mul(4)})),s=Kp((()=>{const s=t,i=pf(s.r,s.g,s.b).div(3);return ym(pm(i.mul(10).sub(5).add(e())),s.a)}));return s()}}const SN=(t,e,s,i)=>Xp(new wN(Xp(t),e,s,i));_p("dotScreen",SN);class MN extends cp{constructor(t,e=.005,s=0){super("vec4"),this.textureNode=t,this.amount=hf(e),this.angle=hf(s)}setup(){const{textureNode:t}=this,e=t.uvNode||uf(),s=e=>t.uv(e);return Kp((()=>{const t=um(ey(this.angle),ty(this.angle)).mul(this.amount),i=s(e.add(t)),r=s(e),n=s(e.sub(t));return ym(i.r,r.g,n.b,r.a)}))()}}const AN=(t,e,s)=>Xp(new MN(Xp(t).toTexture(),e,s));_p("rgbShift",AN);class NN extends cp{constructor(t,e=null,s=null){super(),this.inputNode=t,this.intensityNode=e,this.uvNode=s}setup(){const t=this.uvNode||uf(),e=Kp((()=>{const e=this.inputNode.rgb,s=Gy(Kf(t.add(aw())));let i=e.add(e.mul(Ly(s.add(.1),0,1)));return null!==this.intensityNode&&(i=Oy(e,i,this.intensityNode)),ym(i,this.inputNode.a)}));return e()}}const RN=Zp(NN);_p("film",RN);class CN extends cp{constructor(t,e,s,i){super(),this.inputNode=t,this.lutNode=e,this.size=hf(s),this.intensityNode=i}setup(){const{inputNode:t,lutNode:e}=this,s=Kp((()=>{const s=t,i=nm(1).div(this.size),r=nm(.5).div(this.size),n=pm(r).add(s.rgb.mul(nm(1).sub(i))),o=ym((t=>e.uv(t))(n).rgb,s.a);return ym(Oy(s,o,this.intensityNode))}));return s()}}const EN=(t,e,s,i)=>Xp(new CN(Xp(t),Xp(e),s,Xp(i)));_p("lut3D",EN);class BN extends cp{constructor(t,e,s){super("vec4"),this.colorNode=t,this.toneMapping=e,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:t}){let e=this.colorNode||t.color;const s=null!==this.toneMapping?this.toneMapping:t.toneMapping,i=null!==this.outputColorSpace?this.outputColorSpace:t.outputColorSpace;return 0!==s&&(e=e.toneMapping(s)),i===Je&&(e=e.linearToColorSpace(i)),e}}const IN=(t,e=null,s=null)=>Xp(new BN(Xp(t),e,s));_p("renderOutput",IN),up("RenderOutputNode",BN);class PN extends cp{constructor(t=null,e={}){super(),this.functionNode=t,this.parameters=e}setParameters(t){return this.parameters=t,this}getParameters(){return this.parameters}getNodeType(t){return this.functionNode.getNodeType(t)}generate(t){const e=[],s=this.functionNode,i=s.getInputs(t),r=this.parameters;if(Array.isArray(r))for(let s=0;s(e=e.length>1||e[0]&&!0===e[0].isNode?Jp(e):Yp(e[0]),Xp(new PN(Xp(t),e)));_p("call",FN),up("FunctionCallNode",PN);class UN extends hp{constructor(t=null){super(),this._value=t,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new ks,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(t){this._value!==t&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=t,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const t=this.value;if(t&&null===this._cache&&"URL"===this.inputType&&t.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([t.value]));else if(t&&null!==t.value&&void 0!==t.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof t.value||"Number"===this.inputType&&"number"==typeof t.value||"Vector2"===this.inputType&&t.value.isVector2||"Vector3"===this.inputType&&t.value.isVector3||"Vector4"===this.inputType&&t.value.isVector4||"Color"===this.inputType&&t.value.isColor||"Matrix3"===this.inputType&&t.value.isMatrix3||"Matrix4"===this.inputType&&t.value.isMatrix4))return t.value;return this._cache||t}getNodeType(t){return this.value&&this.value.isNode?this.value.getNodeType(t):"float"}setup(){return this.value&&this.value.isNode?this.value:nm()}serialize(t){super.serialize(t),null!==this.value?"ArrayBuffer"===this.inputType?t.value=ip(this.value):t.value=this.value?this.value.toJSON(t.meta).uuid:null:t.value=null,t.inputType=this.inputType,t.outputType=this.outputType}deserialize(t){super.deserialize(t);let e=null;null!==t.value&&(e="ArrayBuffer"===t.inputType?rp(t.value):"Texture"===t.inputType?t.meta.textures[t.value]:t.meta.nodes[t.value]||null),this.value=e,this.inputType=t.inputType,this.outputType=t.outputType}}const ON=Zp(UN);_p("scriptableValue",ON),up("ScriptableValueNode",UN);class LN extends Map{get(t,e=null,...s){if(this.has(t))return super.get(t);if(null!==e){const i=e(...s);return this.set(t,i),i}}}class zN{constructor(t){this.scriptableNode=t}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(t){return this.scriptableNode.getInputLayout(t)}get(t){const e=this.parameters[t];return e?e.getValue():null}}const VN=new LN;class DN extends hp{constructor(t=null,e={}){super(),this.codeNode=t,this.parameters=e,this._local=new LN,this._output=ON(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(t,e){return this._local.set(t,e)}getLocal(t){return this._local.get(t)}onRefresh(){this._refresh()}getInputLayout(t){for(const e of this.getLayout())if(e.inputType&&(e.id===t||e.name===t))return e}getOutputLayout(t){for(const e of this.getLayout())if(e.outputType&&(e.id===t||e.name===t))return e}setOutput(t,e){const s=this._outputs;return void 0===s[t]?s[t]=ON(e):s[t].value=e,this}getOutput(t){return this._outputs[t]}getParameter(t){return this.parameters[t]}setParameter(t,e){const s=this.parameters;return e&&e.isScriptableNode?(this.deleteParameter(t),s[t]=e,s[t].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):e&&e.isScriptableValueNode?(this.deleteParameter(t),s[t]=e,s[t].events.addEventListener("refresh",this.onRefresh)):void 0===s[t]?(s[t]=ON(e),s[t].events.addEventListener("refresh",this.onRefresh)):s[t].value=e,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(t){let e=this.parameters[t];return e&&(e.isScriptableNode&&(e=e.getDefaultOutput()),e.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const t of Object.keys(this.parameters))this.deleteParameter(t);return this.needsUpdate=!0,this}call(t,...e){const s=this.getObject()[t];if("function"==typeof s)return s(...e)}async callAsync(t,...e){const s=this.getObject()[t];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...e):s(...e)}getNodeType(t){return this.getDefaultOutputNode().getNodeType(t)}refresh(t=null){null!==t?this.getOutput(t).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const t=new zN(this),e=VN.get("THREE"),s=VN.get("TSL"),i=this.getMethod(this.codeNode),r=[t,this._local,VN,()=>this.refresh(),(t,e)=>this.setOutput(t,e),e,s];this._object=i(...r);const n=this._object.layout;if(n&&(!1===n.cache&&this._local.clear(),this._output.outputType=n.outputType||null,Array.isArray(n.elements)))for(const t of n.elements){const e=t.id||t.name;t.inputType&&(void 0===this.getParameter(e)&&this.setParameter(e,null),this.getParameter(e).inputType=t.inputType),t.outputType&&(void 0===this.getOutput(e)&&this.setOutput(e,null),this.getOutput(e).outputType=t.outputType)}return this._object}deserialize(t){super.deserialize(t);for(const t in this.parameters){let e=this.parameters[t];e.isScriptableNode&&(e=e.getDefaultOutput()),e.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const t=this.getDefaultOutput().value;return t&&t.isNode?t:nm()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const t=["layout","init","main","dispose"].join(", "),e="\nreturn { ...output, "+t+" };",s="var "+t+"; var output = {};\n"+this.codeNode.code+e;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}set needsUpdate(t){!0===t&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const kN=Zp(DN);_p("scriptable",kN),up("ScriptableNode",DN);class GN extends hp{constructor(t,e){super("float"),this.isFogNode=!0,this.colorNode=t,this.factorNode=e}getViewZNode(t){let e;const s=t.context.getViewZ;return void 0!==s&&(e=s(this)),(e||Wb.z).negate()}setup(){return this.factorNode}}const WN=Zp(GN);_p("fog",WN),up("FogNode",GN);class jN extends GN{constructor(t,e,s){super(t),this.isFogRangeNode=!0,this.nearNode=e,this.farNode=s}setup(t){const e=this.getViewZNode(t);return Dy(this.nearNode,this.farNode,e)}}const HN=Zp(jN);_p("rangeFog",HN),up("FogRangeNode",jN);class qN extends GN{constructor(t,e){super(t),this.isFogExp2Node=!0,this.densityNode=e}setup(t){const e=this.getViewZNode(t),s=this.densityNode;return s.mul(s,e,e).negate().exp().oneMinus()}}const $N=Zp(qN);_p("densityFog",$N),up("FogExp2Node",qN);let XN=null,YN=null;class JN extends hp{constructor(t=nm(),e=nm()){super(),this.minNode=t,this.maxNode=e}getVectorLength(t){const e=t.getTypeLength(ep(this.minNode.value)),s=t.getTypeLength(ep(this.maxNode.value));return e>s?e:s}getNodeType(t){return t.object.count>1?t.getTypeFromLength(this.getVectorLength(t)):"float"}setup(t){const e=t.object;let s=null;if(e.count>1){const i=this.minNode.value,r=this.maxNode.value,n=t.getTypeLength(ep(i)),o=t.getTypeLength(ep(r));XN=XN||new _i,YN=YN||new _i,XN.setScalar(0),YN.setScalar(0),1===n?XN.setScalar(i):i.isColor?XN.set(i.r,i.g,i.b):XN.set(i.x,i.y,i.z||0,i.w||0),1===o?YN.setScalar(r):r.isColor?YN.set(r.r,r.g,r.b):YN.set(r.x,r.y,r.z||0,r.w||0);const a=4,h=a*e.count,u=new Float32Array(h);for(let t=0;tXp(new QN(Xp(t),e,s));_p("compute",KN),up("ComputeNode",QN);class tR extends hp{constructor(t=tR.TARGET_DIRECTION,e=null){super(),this.scope=t,this.light=e}setup(){const{scope:t,light:e}=this;let s=null;return t===tR.TARGET_DIRECTION&&(s=Sx.transformDirection(Px(e).sub(Px(e.target)))),s}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}}tR.TARGET_DIRECTION="targetDirection";const eR=Zp(tR,tR.TARGET_DIRECTION);up("LightNode",tR);const sR=Kp((t=>{const{lightDistance:e,cutoffDistance:s,decayExponent:i}=t,r=e.pow(i).max(.01).reciprocal();return s.greaterThan(0).cond(r.mul(e.div(s).pow4().oneMinus().clamp().pow2()),r)}));class iR extends Rv{constructor(t=null){super(t),this.cutoffDistanceNode=hf(0),this.decayExponentNode=hf(0)}update(t){const{light:e}=this;super.update(t),this.cutoffDistanceNode.value=e.distance,this.decayExponentNode.value=e.decay}setup(t){const{colorNode:e,cutoffDistanceNode:s,decayExponentNode:i,light:r}=this,n=t.context.lightingModel,o=Ux(r).sub(Wb),a=o.normalize(),h=o.length(),u=sR({lightDistance:h,cutoffDistance:s,decayExponent:i}),l=e.mul(u),c=t.context.reflectedLight;n.direct({lightDirection:a,lightColor:l,reflectedLight:c,shadowMask:this.shadowMaskNode},t.stack,t)}}up("PointLightNode",iR),Pv(Nl,iR);class rR extends Rv{constructor(t=null){super(t)}setup(t){super.setup(t);const e=t.context.lightingModel,s=this.colorNode,i=eR(this.light),r=t.context.reflectedLight;e.direct({lightDirection:i,lightColor:s,reflectedLight:r,shadowMask:this.shadowMaskNode},t.stack,t)}}up("DirectionalLightNode",rR),Pv(El,rR);const nR=new or,oR=new or;let aR=null;class hR extends Rv{constructor(t=null){super(t),this.halfHeight=hf(new Ei),this.halfWidth=hf(new Ei)}update(t){super.update(t);const{light:e}=this,s=t.camera.matrixWorldInverse;oR.identity(),nR.copy(e.matrixWorld),nR.premultiply(s),oR.extractRotation(nR),this.halfWidth.value.set(.5*e.width,0,0),this.halfHeight.value.set(0,.5*e.height,0),this.halfWidth.value.applyMatrix4(oR),this.halfHeight.value.applyMatrix4(oR)}setup(t){let e,s;super.setup(t),t.isAvailable("float32Filterable")?(e=rx(aR.LTC_FLOAT_1),s=rx(aR.LTC_FLOAT_2)):(e=rx(aR.LTC_HALF_1),s=rx(aR.LTC_HALF_2));const{colorNode:i,light:r}=this,n=t.context.lightingModel,o=Ux(r),a=t.context.reflectedLight;n.directRectArea({lightColor:i,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:e,ltc_2:s},t.stack,t)}static setLTC(t){aR=t}}up("RectAreaLightNode",hR),Pv(Il,hR);class uR extends Rv{constructor(t=null){super(t),this.coneCosNode=hf(0),this.penumbraCosNode=hf(0),this.cutoffDistanceNode=hf(0),this.decayExponentNode=hf(0)}update(t){super.update(t);const{light:e}=this;this.coneCosNode.value=Math.cos(e.angle),this.penumbraCosNode.value=Math.cos(e.angle*(1-e.penumbra)),this.cutoffDistanceNode.value=e.distance,this.decayExponentNode.value=e.decay}getSpotAttenuation(t){const{coneCosNode:e,penumbraCosNode:s}=this;return Dy(e,s,t)}setup(t){super.setup(t);const e=t.context.lightingModel,{colorNode:s,cutoffDistanceNode:i,decayExponentNode:r,light:n}=this,o=Ux(n).sub(Wb),a=o.normalize(),h=a.dot(eR(n)),u=this.getSpotAttenuation(h),l=o.length(),c=sR({lightDistance:l,cutoffDistance:i,decayExponent:r}),d=s.mul(u).mul(c),p=t.context.reflectedLight;e.direct({lightDirection:a,lightColor:d,reflectedLight:p,shadowMask:this.shadowMaskNode},t.stack,t)}}up("SpotLightNode",uR),Pv(_l,uR);class lR extends _l{constructor(t,e,s,i,r,n){super(t,e,s,i,r,n),this.iesMap=null}copy(t,e){return super.copy(t,e),this.iesMap=t.iesMap,this}}class cR extends uR{getSpotAttenuation(t){const e=this.light.iesMap;let s=null;if(e&&!0===e.isTexture){const i=t.acos().mul(1/Math.PI);s=rx(e,um(i,0),0).r}else s=super.getSpotAttenuation(t);return s}}up("IESSpotLightNode",cR),Pv(lR,cR);class dR extends Rv{constructor(t=null){super(t)}setup({context:t}){t.irradiance.addAssign(this.colorNode)}}up("AmbientLightNode",dR),Pv(Bl,dR);class pR extends Rv{constructor(t=null){super(t),this.lightPositionNode=Px(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=hf(new Yr)}update(t){const{light:e}=this;super.update(t),this.lightPositionNode.object3d=e,this.groundColorNode.value.copy(e.groundColor).multiplyScalar(e.intensity)}setup(t){const{colorNode:e,groundColorNode:s,lightDirectionNode:i}=this,r=$x.dot(i).mul(.5).add(.5),n=Oy(s,e,r);t.context.irradiance.addAssign(n)}}up("HemisphereLightNode",pR),Pv(fl,pR);let mR=null;const gR=new WeakMap;class fR extends cp{constructor(t,e=null,s=null){super("vec3"),this._value=t,this._pmrem=null,this.uvNode=e,this.levelNode=s,this._generator=null,this._texture=rx(null),this._width=hf(0),this._height=hf(0),this._maxMip=hf(0),this.updateBeforeType=$d.RENDER}set value(t){this._value=t,this._pmrem=null}get value(){return this._value}updateFromTexture(t){const e=function(t){const e=Math.log2(t)-2,s=1/t;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:s,maxMip:e}}(t.image.height);this._texture.value=t,this._width.value=e.texelWidth,this._height.value=e.texelHeight,this._maxMip.value=e.maxMip}updateBefore(){let t=this._pmrem;const e=t?t.pmremVersion:-1,s=this._value;e!==s.pmremVersion&&(t=!0===s.isPMREMTexture?s:function(t){let e=gR.get(t);if((void 0!==e?e.pmremVersion:-1)!==t.pmremVersion){if(t.isCubeTexture){if(t.source.data.some((t=>void 0===t)))throw new Error("PMREMNode: Undefined texture in CubeTexture. Use onLoad callback or async loader");e=mR.fromCubemap(t,e)}else{if(void 0===t.image)throw new Error("PMREMNode: Undefined image in Texture. Use onLoad callback or async loader");e=mR.fromEquirectangular(t,e)}e.pmremVersion=t.pmremVersion,gR.set(t,e)}return e.texture}(s),this._pmrem=t,this.updateFromTexture(t))}setup(t){null===mR&&(mR=t.createPMREMGenerator()),this.updateBefore(t);let e=this.uvNode;null===e&&t.context.getUV&&(e=t.context.getUV(this));const s=this.value;t.renderer.coordinateSystem===Vs&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(e=pm(e.x.negate(),e.yz));let i=this.levelNode;return null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),s_(this._texture,e,i,this._width,this._height,this._maxMip)}}const yR=Zp(fR);up("PMREMNode",fR);const xR=new WeakMap;class bR extends Av{constructor(t=null){super(),this.envNode=t}setup(t){let e=this.envNode;if(e.isTextureNode){let t=xR.get(e.value);void 0===t&&(t=yR(e.value),xR.set(e.value,t)),e=t}const{material:s}=t,i=s.envMap?mx("envMapIntensity","float",t.material):mx("environmentIntensity","float",t.scene),r=!0===s.useAnisotropy||s.anisotropy>0,n=Ym(e,vR(yg,r?cS:Yx)).mul(i),o=Ym(e,TR(Jx)).mul(Math.PI).mul(i),a=$m(n),h=$m(o);t.context.radiance.addAssign(a),t.context.iblIrradiance.addAssign(h);const u=t.context.lightingModel.clearcoatRadiance;if(u){const t=Ym(e,vR(vg,Zx)).mul(i),s=$m(t);u.addAssign(s)}}}const vR=(t,e)=>{let s=null;return{getUV:()=>(null===s&&(s=jb.negate().reflect(e),s=t.mul(t).mix(s,e).normalize(),s=s.transformDirection(Sx)),s),getTextureLevel:()=>t}},TR=t=>({getUV:()=>t,getTextureLevel:()=>nm(1)});up("EnvironmentNode",bR);class _R extends Av{constructor(t=null){super(),this.envNode=t}setup(t){t.context.environment=this.envNode}}up("BasicEnvironmentNode",_R);const wR=Kp((t=>{const e=t.uv.mul(2),s=e.x.floor(),i=e.y.floor();return s.add(i).mod(2).sign()}));class SR extends cp{constructor(t=uf()){super("float"),this.uvNode=t}setup(){return wR({uv:this.uvNode})}}const MR=Zp(SR);_p("checker",MR),up("CheckerNode",SR);class AR extends nl{constructor(t){super(t),this.textures={}}load(t,e,s,i){const r=new hl(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,(s=>{try{e(this.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),this.manager.itemError(t)}}),s,i)}parseNodes(t){const e={};if(void 0!==t){for(const s of t){const{uuid:t,type:i}=s;e[t]=Xp(lp(i)),e[t].uuid=t}const s={nodes:e,textures:this.textures};for(const i of t){i.meta=s;e[i.uuid].deserialize(i),delete i.meta}}return e}parse(t){const e=Xp(lp(t.type));e.uuid=t.uuid;const s={nodes:this.parseNodes(t.nodes),textures:this.textures};return t.meta=s,e.deserialize(t),delete t.meta,e}setTextures(t){return this.textures=t,this}}const NR=new Va;class RR extends gT{constructor(t={}){super(),this.normals=!1,this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=t.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.setDefaultValues(NR),this.setupShaders(),this.setValues(t)}setupShaders(){const t=this.alphaToCoverage,e=this.useColor;this.vertexNode=Kp((()=>{km(um(),"vUv").assign(uf());const t=Wm("instancePosition"),e=pg("vec4","mvPos");e.assign(zx.mul(ym(t,1)));const s=Wv.z.div(Wv.w),i=_x.mul(e),r=pg("vec2","offset");return r.assign(Vb.xy),r.assign(r.mul(Pb)),r.assign(r.div(Wv.z)),r.y.assign(r.y.mul(s)),r.assign(r.mul(i.w)),i.assign(i.add(ym(r,0,0))),i}))(),this.fragmentNode=Kp((()=>{const s=km(um(),"vUv"),i=pg("float","alpha");i.assign(1);const r=s.x,n=s.y,o=r.mul(r).add(n.mul(n));if(t){const t=pg("float","dlen");t.assign(o.fwidth()),i.assign(Dy(t.oneMinus(),t.add(1),o).oneMinus())}else o.greaterThan(1).discard();let a;if(this.pointColorNode)a=this.pointColorNode;else if(e){a=Wm("instanceColor").mul(eb)}else a=eb;return ym(a,i)}))(),this.needsUpdate=!0}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.setupShaders())}}fT("InstancedPointsNodeMaterial",RR);const CR=new Ma;class ER extends gT{constructor(t){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.normals=!1,this.setDefaultValues(CR),this.setValues(t)}}fT("LineBasicNodeMaterial",ER);const BR=new Uu;class IR extends gT{constructor(t){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.normals=!1,this.setDefaultValues(BR),this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setupVariants(){const t=this.offsetNode,e=this.dashScaleNode?nm(this.dashScaleNode):Rb,s=this.dashSizeNode?nm(this.dashSizeNode):Cb,i=this.dashSizeNode?nm(this.dashGapNode):Eb;Fg.assign(s),Ug.assign(i);const r=km(Wm("lineDistance").mul(e));(t?r.add(t):r).mod(Fg.add(Ug)).greaterThan(Fg).discard()}}fT("LineDashedNodeMaterial",IR);const PR=new Uu;class FR extends gT{constructor(t={}){super(),this.normals=!1,this.lights=!1,this.setDefaultValues(PR),this.useAlphaToCoverage=!0,this.useColor=t.vertexColors,this.useDash=t.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setup(t){this.setupShaders(),super.setup(t)}setupShaders(){const t=this.alphaToCoverage,e=this.useColor,s=this.dashed,i=this.worldUnits,r=Kp((({start:t,end:e})=>{const s=_x.element(2).element(2),i=_x.element(3).element(2).mul(-.5).div(s).sub(t.z).div(e.z.sub(t.z));return ym(Oy(t.xyz,e.xyz,i),e.w)}));this.vertexNode=Kp((()=>{mg("vec2","vUv").assign(uf());const t=Wm("instanceStart"),e=Wm("instanceEnd"),n=pg("vec4","start"),o=pg("vec4","end");n.assign(zx.mul(ym(t,1))),o.assign(zx.mul(ym(e,1))),i&&(mg("vec3","worldStart").assign(n.xyz),mg("vec3","worldEnd").assign(o.xyz));const a=Wv.z.div(Wv.w),h=_x.element(2).element(3).equal(-1);sm(h,(()=>{sm(n.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(r({start:n,end:o}))})).elseif(o.z.lessThan(0).and(n.z.greaterThanEqual(0)),(()=>{n.assign(r({start:o,end:n}))}))}));const u=_x.mul(n),l=_x.mul(o),c=u.xyz.div(u.w),d=l.xyz.div(l.w),p=d.xy.sub(c.xy).temp();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const m=ig(ym());if(i){const t=o.xyz.sub(n.xyz).normalize(),e=Oy(n.xyz,o.xyz,.5).normalize(),i=t.cross(e).normalize(),r=t.cross(i),a=mg("vec4","worldPos");a.assign(Vb.y.lessThan(.5).cond(n,o));const h=Bb.mul(.5);a.addAssign(ym(Vb.x.lessThan(0).cond(i.mul(h),i.mul(h).negate()),0)),s||(a.addAssign(ym(Vb.y.lessThan(.5).cond(t.mul(h).negate(),t.mul(h)),0)),a.addAssign(ym(r.mul(h),0)),sm(Vb.y.greaterThan(1).or(Vb.y.lessThan(0)),(()=>{a.subAssign(ym(r.mul(2).mul(h),0))}))),m.assign(_x.mul(a));const u=ig(pm());u.assign(Vb.y.lessThan(.5).cond(c,d)),m.z.assign(u.z.mul(m.w))}else{const t=pg("vec2","offset");t.assign(um(p.y,p.x.negate())),p.x.assign(p.x.div(a)),t.x.assign(t.x.div(a)),t.assign(Vb.x.lessThan(0).cond(t.negate(),t)),sm(Vb.y.lessThan(0),(()=>{t.assign(t.sub(p))})).elseif(Vb.y.greaterThan(1),(()=>{t.assign(t.add(p))})),t.assign(t.mul(Bb)),t.assign(t.div(Wv.w)),m.assign(Vb.y.lessThan(.5).cond(u,l)),t.assign(t.mul(m.w)),m.assign(m.add(ym(t,0,0)))}return m}))();const n=Kp((({p1:t,p2:e,p3:s,p4:i})=>{const r=t.sub(s),n=i.sub(s),o=e.sub(t),a=r.dot(n),h=n.dot(o),u=r.dot(o),l=n.dot(n),c=o.dot(o).mul(l).sub(h.mul(h)),d=a.mul(h).sub(u.mul(l)).div(c).clamp(),p=a.add(h.mul(d)).div(l).clamp();return um(d,p)}));this.fragmentNode=Kp((()=>{const r=mg("vec2","vUv");if(s){const t=this.offsetNode?nm(this.offsetNodeNode):Ib,e=this.dashScaleNode?nm(this.dashScaleNode):Rb,s=this.dashSizeNode?nm(this.dashSizeNode):Cb,i=this.dashSizeNode?nm(this.dashGapNode):Eb;Fg.assign(s),Ug.assign(i);const n=Wm("instanceDistanceStart"),o=Wm("instanceDistanceEnd"),a=Vb.y.lessThan(.5).cond(e.mul(n),Rb.mul(o)),h=km(a.add(Ib)),u=t?h.add(t):h;r.y.lessThan(-1).or(r.y.greaterThan(1)).discard(),u.mod(Fg.add(Ug)).greaterThan(Fg).discard()}const o=pg("float","alpha");if(o.assign(1),i){const e=mg("vec3","worldStart"),i=mg("vec3","worldEnd"),r=mg("vec4","worldPos").xyz.normalize().mul(1e5),a=i.sub(e),h=n({p1:e,p2:i,p3:pm(0,0,0),p4:r}),u=e.add(a.mul(h.x)),l=r.mul(h.y),c=u.sub(l).length().div(Bb);if(!s)if(t){const t=c.fwidth();o.assign(Dy(t.negate().add(.5),t.add(.5),c).oneMinus())}else c.greaterThan(.5).discard()}else if(t){const t=r.x,e=r.y.greaterThan(0).cond(r.y.sub(1),r.y.add(1)),s=t.mul(t).add(e.mul(e)),i=pg("float","dlen");i.assign(s.fwidth()),sm(r.y.abs().greaterThan(1),(()=>{o.assign(Dy(i.oneMinus(),i.add(1),s).oneMinus())}))}else sm(r.y.abs().greaterThan(1),(()=>{const t=r.x,e=r.y.greaterThan(0).cond(r.y.sub(1),r.y.add(1));t.mul(t).add(e.mul(e)).greaterThan(1).discard()}));let a;if(this.lineColorNode)a=this.lineColorNode;else if(e){const t=Wm("instanceColorStart"),e=Wm("instanceColorEnd");a=Vb.y.lessThan(.5).cond(t,e).mul(eb)}else a=eb;return ym(a,o)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(t){this.useWorldUnits!==t&&(this.useWorldUnits=t,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(t){this.useDash!==t&&(this.useDash=t,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.needsUpdate=!0)}}fT("Line2NodeMaterial",FR);const UR=new Eu;class OR extends gT{constructor(t){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(UR),this.setValues(t)}setupDiffuseColor(){const t=this.opacityNode?nm(this.opacityNode):rb;gg.assign(ym(yw(Yx),t))}}fT("MeshNormalNodeMaterial",OR);class LR extends Av{constructor(t=null){super(),this.lightMapNode=t}setup(t){const e=nm(1/Math.PI);t.context.irradianceLightMap=this.lightMapNode.mul(e)}}up("BasicLightMapNode",LR);class zR extends eg{constructor(){super()}indirect(t,e,s){const i=t.ambientOcclusion,r=t.reflectedLight,n=s.context.irradianceLightMap;r.indirectDiffuse.assign(ym(0)),n?r.indirectDiffuse.addAssign(n):r.indirectDiffuse.addAssign(ym(1,1,1,0)),r.indirectDiffuse.mulAssign(i),r.indirectDiffuse.mulAssign(gg.rgb)}finish(t,e,s){const i=s.material,r=t.outgoingLight,n=s.context.environment;if(n)switch(i.combine){case 0:r.rgb.assign(Oy(r.rgb,r.rgb.mul(n.rgb),hb.mul(ub)));break;case 1:r.rgb.assign(Oy(r.rgb,n.rgb,hb.mul(ub)));break;case 2:r.rgb.addAssign(n.rgb.mul(hb.mul(ub)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",i.combine)}}}const VR=new Kr;class DR extends gT{constructor(t){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(VR),this.setValues(t)}setupNormal(){Yx.assign($x)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new _R(e):null}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new LR(Ub)),e}setupLightingModel(){return new zR}}fT("MeshBasicNodeMaterial",DR);const kR=Kp((({f0:t,f90:e,dotVH:s})=>{const i=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return t.mul(i.oneMinus()).add(e.mul(i))})),GR=Kp((t=>t.diffuseColor.mul(1/Math.PI))),WR=Kp((({dotNH:t})=>Ig.mul(nm(.5)).add(1).mul(nm(1/Math.PI)).mul(t.pow(Ig)))),jR=Kp((({lightDirection:t})=>{const e=t.add(jb).normalize(),s=Yx.dot(e).clamp(),i=jb.dot(e).clamp(),r=kR({f0:Eg,f90:1,dotVH:i}),n=nm(.25),o=WR({dotNH:s});return r.mul(n).mul(o)}));class HR extends zR{constructor(t=!0){super(),this.specular=t}direct({lightDirection:t,lightColor:e,reflectedLight:s}){const i=Yx.dot(t).clamp().mul(e);s.directDiffuse.addAssign(i.mul(GR({diffuseColor:gg.rgb}))),!0===this.specular&&s.directSpecular.addAssign(i.mul(jR({lightDirection:t})).mul(hb))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:s}){s.indirectDiffuse.addAssign(e.mul(GR({diffuseColor:gg}))),s.indirectDiffuse.mulAssign(t)}}const qR=new Bu;class $R extends gT{constructor(t){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(qR),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new _R(e):null}setupLightingModel(){return new HR(!1)}}fT("MeshLambertNodeMaterial",$R);const XR=new Ru;class YR extends gT{constructor(t){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(XR),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new _R(e):null}setupLightingModel(){return new HR}setupVariants(){const t=(this.shininessNode?nm(this.shininessNode):sb).max(1e-4);Ig.assign(t);const e=this.specularNode||nb;Eg.assign(e)}copy(t){return this.shininessNode=t.shininessNode,this.specularNode=t.specularNode,super.copy(t)}}fT("MeshPhongNodeMaterial",YR);const JR=Kp((()=>{const t=Hx.dFdx().abs().max(Hx.dFdy().abs());return t.x.max(t.y).max(t.z)})),ZR=Kp((t=>{const{roughness:e}=t,s=JR();let i=e.max(.0525);return i=i.add(s),i=i.min(1),i})),QR=Kp((({alpha:t,dotNL:e,dotNV:s})=>{const i=t.pow2(),r=e.mul(i.add(i.oneMinus().mul(s.pow2())).sqrt()),n=s.mul(i.add(i.oneMinus().mul(e.pow2())).sqrt());return ff(.5,r.add(n).max(Uf))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),KR=Kp((({alphaT:t,alphaB:e,dotTV:s,dotBV:i,dotTL:r,dotBL:n,dotNV:o,dotNL:a})=>{const h=a.mul(pm(t.mul(s),e.mul(i),o).length()),u=o.mul(pm(t.mul(r),e.mul(n),a).length());return ff(.5,h.add(u)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),tC=Kp((({alpha:t,dotNH:e})=>{const s=t.pow2(),i=e.pow2().mul(s.oneMinus()).oneMinus();return s.div(i.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),eC=nm(1/Math.PI),sC=Kp((({alphaT:t,alphaB:e,dotNH:s,dotTH:i,dotBH:r})=>{const n=t.mul(e),o=pm(e.mul(i),t.mul(r),n.mul(s)),a=o.dot(o),h=n.div(a);return eC.mul(n.mul(h.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),iC=Kp((t=>{const{lightDirection:e,f0:s,f90:i,roughness:r,f:n,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=t,h=t.normalView||Yx,u=r.pow2(),l=e.add(jb).normalize(),c=h.dot(e).clamp(),d=h.dot(jb).clamp(),p=h.dot(l).clamp(),m=jb.dot(l).clamp();let g,f,y=kR({f0:s,f90:i,dotVH:m});if(Hp(o)&&(y=wg.mix(y,n)),Hp(a)){const t=Rg.dot(e),s=Rg.dot(jb),i=Rg.dot(l),r=Cg.dot(e),n=Cg.dot(jb),o=Cg.dot(l);g=KR({alphaT:Ag,alphaB:u,dotTV:s,dotBV:n,dotTL:t,dotBL:r,dotNV:d,dotNL:c}),f=sC({alphaT:Ag,alphaB:u,dotNH:p,dotTH:i,dotBH:o})}else g=QR({alpha:u,dotNL:c,dotNV:d}),f=tC({alpha:u,dotNH:p});return y.mul(g).mul(f)})),rC=Kp((({roughness:t,dotNV:e})=>{const s=ym(-1,-.0275,-.572,.022),i=ym(1,.0425,1.04,-.04),r=t.mul(s).add(i),n=r.x.mul(r.x).min(e.mul(-9.28).exp2()).mul(r.x).add(r.y);return um(-1.04,1.04).mul(n).add(r.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),nC=Kp((t=>{const{dotNV:e,specularColor:s,specularF90:i,roughness:r}=t,n=rC({dotNV:e,roughness:r});return s.mul(n.x).add(i.mul(n.y))})),oC=Kp((({f:t,f90:e,dotVH:s})=>{const i=s.oneMinus().saturate(),r=i.mul(i),n=i.mul(r,r).clamp(0,.9999);return t.sub(pm(e).mul(n)).div(n.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),aC=Kp((({roughness:t,dotNH:e})=>{const s=t.pow2(),i=nm(1).div(s),r=e.pow2().oneMinus().max(.0078125);return nm(2).add(i).mul(r.pow(i.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),hC=Kp((({dotNV:t,dotNL:e})=>nm(1).div(nm(4).mul(e.add(t).sub(e.mul(t)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),uC=Kp((({lightDirection:t})=>{const e=t.add(jb).normalize(),s=Yx.dot(t).clamp(),i=Yx.dot(jb).clamp(),r=Yx.dot(e).clamp(),n=aC({roughness:_g,dotNH:r}),o=hC({dotNV:i,dotNL:s});return Tg.mul(n).mul(o)})),lC=Kp((({N:t,V:e,roughness:s})=>{const i=t.dot(e).saturate(),r=um(s,i.oneMinus().sqrt());return r.assign(r.mul(.984375).add(.0078125)),r})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),cC=Kp((({f:t})=>{const e=t.length();return Ty(e.mul(e).add(t.z).div(e.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),dC=Kp((({v1:t,v2:e})=>{const s=t.dot(e),i=s.abs().toVar(),r=i.mul(.0145206).add(.4965155).mul(i).add(.8543985).toVar(),n=i.add(4.1616724).mul(i).add(3.417594).toVar(),o=r.div(n),a=s.greaterThan(0).cond(o,Ty(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return t.cross(e).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),pC=Kp((({N:t,V:e,P:s,mInv:i,p0:r,p1:n,p2:o,p3:a})=>{const h=n.sub(r).toVar(),u=a.sub(r).toVar(),l=h.cross(u),c=pm().toVar();return sm(l.dot(s.sub(r)).greaterThanEqual(0),(()=>{const h=e.sub(t.mul(e.dot(t))).normalize(),u=t.cross(h).negate(),l=i.mul(Mm(h,u,t).transpose()).toVar(),d=l.mul(r.sub(s)).normalize().toVar(),p=l.mul(n.sub(s)).normalize().toVar(),m=l.mul(o.sub(s)).normalize().toVar(),g=l.mul(a.sub(s)).normalize().toVar(),f=pm(0).toVar();f.addAssign(dC({v1:d,v2:p})),f.addAssign(dC({v1:p,v2:m})),f.addAssign(dC({v1:m,v2:g})),f.addAssign(dC({v1:g,v2:d})),c.assign(pm(cC({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),mC=Kp((([t,e,s,i,r])=>{const n=pm(Vy(e.negate(),Qf(t),ff(1,i))),o=pm(hy(r[0].xyz),hy(r[1].xyz),hy(r[2].xyz));return Qf(n).mul(s.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),gC=Kp((([t,e])=>t.mul(Ly(e.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),fC=Zv(),yC=Kp((([t,e,s])=>{const i=fC.uv(t),r=$f(nm(Gv.x)).mul(gC(e,s));return i.bicubic(r)})),xC=Kp((([t,e,s])=>(sm(s.notEqual(0),(()=>{const i=qf(e).negate().div(s);return jf(i.negate().mul(t))})),pm(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),bC=Kp((([t,e,s,i,r,n,o,a,h,u,l,c,d,p,m])=>{let g,f;if(m){g=ym().toVar(),f=pm().toVar();const r=l.sub(1).mul(m.mul(.025)),n=pm(l.sub(r),l,l.add(r));dv({start:0,end:3},(({i:r})=>{const l=n.element(r),m=mC(t,e,c,l,a),y=o.add(m),x=u.mul(h.mul(ym(y,1))),b=um(x.xy.div(x.w)).toVar();b.addAssign(1),b.divAssign(2),b.assign(um(b.x,b.y.oneMinus()));const v=yC(b,s,l);g.element(r).assign(v.element(r)),g.a.addAssign(v.a),f.element(r).assign(i.element(r).mul(xC(hy(m),d,p).element(r)))})),g.a.divAssign(3)}else{const r=mC(t,e,c,l,a),n=o.add(r),m=u.mul(h.mul(ym(n,1))),y=um(m.xy.div(m.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(um(y.x,y.y.oneMinus())),g=yC(y,s,l),f=i.mul(xC(hy(r),d,p))}const y=f.rgb.mul(g.rgb),x=t.dot(e).clamp(),b=pm(nC({dotNV:x,specularColor:r,specularF90:n,roughness:s})),v=f.r.add(f.g,f.b).div(3);return ym(b.oneMinus().mul(y),g.a.oneMinus().mul(v).oneMinus())})),vC=Mm(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),TC=(t,e)=>t.sub(e).div(t.add(e)).pow2(),_C=(t,e)=>{const s=t.mul(2*Math.PI*1e-9),i=pm(54856e-17,44201e-17,52481e-17),r=pm(1681e3,1795300,2208400),n=pm(43278e5,93046e5,66121e5),o=nm(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(e.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=i.mul(n.mul(2*Math.PI).sqrt()).mul(r.mul(s).add(e).cos()).mul(s.pow2().negate().mul(n).exp());a=pm(a.x.add(o),a.y,a.z).div(1.0685e-7);return vC.mul(a)},wC=Kp((({outsideIOR:t,eta2:e,cosTheta1:s,thinFilmThickness:i,baseF0:r})=>{const n=Oy(t,e,Dy(0,.03,i)),o=t.div(n).pow2().mul(nm(1).sub(s.pow2())),a=nm(1).sub(o).sqrt(),h=TC(n,t),u=kR({f0:h,f90:1,dotVH:s}),l=u.oneMinus(),c=n.lessThan(t).cond(Math.PI,0),d=nm(Math.PI).sub(c),p=(t=>{const e=t.sqrt();return pm(1).add(e).div(pm(1).sub(e))})(r.clamp(0,.9999)),m=TC(p,n.toVec3()),g=kR({f0:m,f90:1,dotVH:a}),f=pm(p.x.lessThan(n).cond(Math.PI,0),p.y.lessThan(n).cond(Math.PI,0),p.z.lessThan(n).cond(Math.PI,0)),y=n.mul(i,a,2),x=pm(d).add(f),b=u.mul(g).clamp(1e-5,.9999),v=b.sqrt(),T=l.pow2().mul(g).div(pm(1).sub(b));let _=u.add(T),w=T.sub(l);for(let t=1;t<=2;++t){w=w.mul(v);const e=_C(nm(t).mul(y),nm(t).mul(x)).mul(2);_=_.add(w.mul(e))}return _.max(pm(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),SC=Kp((({normal:t,viewDir:e,roughness:s})=>{const i=t.dot(e).saturate(),r=s.pow2(),n=FT(s.lessThan(.25),nm(-339.2).mul(r).add(nm(161.4).mul(s)).sub(25.9),nm(-8.48).mul(r).add(nm(14.3).mul(s)).sub(9.95)),o=FT(s.lessThan(.25),nm(44).mul(r).sub(nm(23.7).mul(s)).add(3.26),nm(1.97).mul(r).sub(nm(3.27).mul(s)).add(.72));return FT(s.lessThan(.25),0,nm(.1).mul(s).sub(.025)).add(n.mul(i).add(o).exp()).mul(1/Math.PI).saturate()})),MC=pm(.04),AC=nm(1);class NC extends eg{constructor(t=!1,e=!1,s=!1,i=!1,r=!1,n=!1){super(),this.clearcoat=t,this.sheen=e,this.iridescence=s,this.anisotropy=i,this.transmission=r,this.dispersion=n,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(t){if(!0===this.clearcoat&&(this.clearcoatRadiance=pm().temp("clearcoatRadiance"),this.clearcoatSpecularDirect=pm().temp("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=pm().temp("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=pm().temp("sheenSpecularDirect"),this.sheenSpecularIndirect=pm().temp("sheenSpecularIndirect")),!0===this.iridescence){const t=Yx.dot(jb).clamp();this.iridescenceFresnel=wC({outsideIOR:nm(1),eta2:Sg,cosTheta1:t,thinFilmThickness:Mg,baseF0:Eg}),this.iridescenceF0=oC({f:this.iridescenceFresnel,f90:1,dotVH:t})}if(!0===this.transmission){const e=kb,s=Nx.sub(kb).normalize(),i=Jx;t.backdrop=bC(i,s,yg,gg,Eg,Bg,e,Dx,Sx,_x,Lg,Vg,kg,Dg,this.dispersion?Gg:null),t.backdropAlpha=zg,gg.a.mulAssign(Oy(1,t.backdrop.a,zg))}}computeMultiscattering(t,e,s){const i=Yx.dot(jb).clamp(),r=rC({roughness:yg,dotNV:i}),n=(this.iridescenceF0?wg.mix(Eg,this.iridescenceF0):Eg).mul(r.x).add(s.mul(r.y)),o=r.x.add(r.y).oneMinus(),a=Eg.add(Eg.oneMinus().mul(.047619)),h=n.mul(a).div(o.mul(a).oneMinus());t.addAssign(n),e.addAssign(h.mul(o))}direct({lightDirection:t,lightColor:e,reflectedLight:s}){const i=Yx.dot(t).clamp().mul(e);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(i.mul(uC({lightDirection:t}))),!0===this.clearcoat){const s=Zx.dot(t).clamp().mul(e);this.clearcoatSpecularDirect.addAssign(s.mul(iC({lightDirection:t,f0:MC,f90:AC,roughness:vg,normalView:Zx})))}s.directDiffuse.addAssign(i.mul(GR({diffuseColor:gg.rgb}))),s.directSpecular.addAssign(i.mul(iC({lightDirection:t,f0:Eg,f90:1,roughness:yg,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:t,lightPosition:e,halfWidth:s,halfHeight:i,reflectedLight:r,ltc_1:n,ltc_2:o}){const a=e.add(s).sub(i),h=e.sub(s).sub(i),u=e.sub(s).add(i),l=e.add(s).add(i),c=Yx,d=jb,p=Wb.toVar(),m=lC({N:c,V:d,roughness:yg}),g=n.uv(m).toVar(),f=o.uv(m).toVar(),y=Mm(pm(g.x,0,g.y),pm(0,1,0),pm(g.z,0,g.w)).toVar(),x=Eg.mul(f.x).add(Eg.oneMinus().mul(f.y)).toVar();r.directSpecular.addAssign(t.mul(x).mul(pC({N:c,V:d,P:p,mInv:y,p0:a,p1:h,p2:u,p3:l}))),r.directDiffuse.addAssign(t.mul(gg).mul(pC({N:c,V:d,P:p,mInv:Mm(1,0,0,0,1,0,0,0,1),p0:a,p1:h,p2:u,p3:l})))}indirect(t,e,s){this.indirectDiffuse(t,e,s),this.indirectSpecular(t,e,s),this.ambientOcclusion(t,e,s)}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.addAssign(t.mul(GR({diffuseColor:gg})))}indirectSpecular({radiance:t,iblIrradiance:e,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(e.mul(Tg,SC({normal:Yx,viewDir:jb,roughness:_g}))),!0===this.clearcoat){const t=Zx.dot(jb).clamp(),e=nC({dotNV:t,specularColor:MC,specularF90:AC,roughness:vg});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(e))}const i=pm().temp("singleScattering"),r=pm().temp("multiScattering"),n=e.mul(1/Math.PI);this.computeMultiscattering(i,r,Bg);const o=i.add(r),a=gg.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(t.mul(i)),s.indirectSpecular.addAssign(r.mul(n)),s.indirectDiffuse.addAssign(a.mul(n))}ambientOcclusion({ambientOcclusion:t,reflectedLight:e}){const s=Yx.dot(jb).clamp().add(t),i=yg.mul(-16).oneMinus().negate().exp2(),r=t.sub(s.pow(i).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(t),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(t),e.indirectDiffuse.mulAssign(t),e.indirectSpecular.mulAssign(r)}finish(t){const{outgoingLight:e}=t;if(!0===this.clearcoat){const t=Zx.dot(jb).clamp(),s=kR({dotVH:t,f0:MC,f90:AC}),i=e.mul(bg.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(bg));e.assign(i)}if(!0===this.sheen){const t=Tg.r.max(Tg.g).max(Tg.b).mul(.157).oneMinus(),s=e.mul(t).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);e.assign(s)}}}const RC=new Au;class CC extends gT{constructor(t){super(),this.isMeshStandardNodeMaterial=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(RC),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new bR(e):null}setupLightingModel(){return new NC}setupSpecular(){const t=Oy(pm(.04),gg.rgb,xg);Eg.assign(t),Bg.assign(1)}setupVariants(){const t=this.metalnessNode?nm(this.metalnessNode):cb;xg.assign(t);let e=this.roughnessNode?nm(this.roughnessNode):lb;e=ZR({roughness:e}),yg.assign(e),this.setupSpecular(),gg.assign(ym(gg.rgb.mul(t.oneMinus()),gg.a))}copy(t){return this.emissiveNode=t.emissiveNode,this.metalnessNode=t.metalnessNode,this.roughnessNode=t.roughnessNode,super.copy(t)}}fT("MeshStandardNodeMaterial",CC);const EC=new Nu;class BC extends CC{constructor(t){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(EC),this.setValues(t)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const t=this.iorNode?nm(this.iorNode):Mb;Lg.assign(t),Eg.assign(Oy(vy(Ey(Lg.sub(1).div(Lg.add(1))).mul(ab),pm(1)).mul(ob),gg.rgb,xg)),Bg.assign(Oy(ob,1,xg))}setupLightingModel(){return new NC(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(t){if(super.setupVariants(t),this.useClearcoat){const t=this.clearcoatNode?nm(this.clearcoatNode):pb,e=this.clearcoatRoughnessNode?nm(this.clearcoatRoughnessNode):mb;bg.assign(t),vg.assign(ZR({roughness:e}))}if(this.useSheen){const t=this.sheenNode?pm(this.sheenNode):yb,e=this.sheenRoughnessNode?nm(this.sheenRoughnessNode):xb;Tg.assign(t),_g.assign(e)}if(this.useIridescence){const t=this.iridescenceNode?nm(this.iridescenceNode):vb,e=this.iridescenceIORNode?nm(this.iridescenceIORNode):Tb,s=this.iridescenceThicknessNode?nm(this.iridescenceThicknessNode):_b;wg.assign(t),Sg.assign(e),Mg.assign(s)}if(this.useAnisotropy){const t=(this.anisotropyNode?um(this.anisotropyNode):bb).toVar();Ng.assign(t.length()),sm(Ng.equal(0),(()=>{t.assign(um(1,0))})).else((()=>{t.divAssign(um(Ng)),Ng.assign(Ng.saturate())})),Ag.assign(Ng.pow2().mix(yg.pow2(),1)),Rg.assign(hS[0].mul(t.x).add(hS[1].mul(t.y))),Cg.assign(hS[1].mul(t.x).sub(hS[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?nm(this.transmissionNode):wb,e=this.thicknessNode?nm(this.thicknessNode):Sb,s=this.attenuationDistanceNode?nm(this.attenuationDistanceNode):Ab,i=this.attenuationColorNode?pm(this.attenuationColorNode):Nb;if(zg.assign(t),Vg.assign(e),Dg.assign(s),kg.assign(i),this.useDispersion){const t=this.dispersionNode?nm(this.dispersionNode):Fb;Gg.assign(t)}}}setupNormal(t){super.setupNormal(t);const e=this.clearcoatNormalNode?pm(this.clearcoatNormalNode):gb;Zx.assign(e)}copy(t){return this.clearcoatNode=t.clearcoatNode,this.clearcoatRoughnessNode=t.clearcoatRoughnessNode,this.clearcoatNormalNode=t.clearcoatNormalNode,this.sheenNode=t.sheenNode,this.sheenRoughnessNode=t.sheenRoughnessNode,this.iridescenceNode=t.iridescenceNode,this.iridescenceIORNode=t.iridescenceIORNode,this.iridescenceThicknessNode=t.iridescenceThicknessNode,this.specularIntensityNode=t.specularIntensityNode,this.specularColorNode=t.specularColorNode,this.transmissionNode=t.transmissionNode,this.thicknessNode=t.thicknessNode,this.attenuationDistanceNode=t.attenuationDistanceNode,this.attenuationColorNode=t.attenuationColorNode,this.dispersionNode=t.dispersionNode,this.anisotropyNode=t.anisotropyNode,super.copy(t)}}fT("MeshPhysicalNodeMaterial",BC);class IC extends NC{constructor(t,e,s,i){super(t,e,s),this.useSSS=i}direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r){if(!0===this.useSSS){const i=r.material,{thicknessColorNode:n,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:h,thicknessPowerNode:u,thicknessScaleNode:l}=i,c=t.add(Yx.mul(o)).normalize(),d=nm(jb.dot(c.negate()).saturate().pow(u).mul(l)),p=pm(d.add(a).mul(n));s.directDiffuse.addAssign(p.mul(h.mul(e)))}super.direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r)}}class PC extends BC{constructor(t){super(t),this.thicknessColorNode=null,this.thicknessDistortionNode=nm(.1),this.thicknessAmbientNode=nm(0),this.thicknessAttenuationNode=nm(.1),this.thicknessPowerNode=nm(2),this.thicknessScaleNode=nm(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new IC(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(t){return this.thicknessColorNode=t.thicknessColorNode,this.thicknessDistortionNode=t.thicknessDistortionNode,this.thicknessAmbientNode=t.thicknessAmbientNode,this.thicknessAttenuationNode=t.thicknessAttenuationNode,this.thicknessPowerNode=t.thicknessPowerNode,this.thicknessScaleNode=t.thicknessScaleNode,super.copy(t)}}fT("MeshSSSNodeMaterial",PC);const FC=Kp((({normal:t,lightDirection:e,builder:s})=>{const i=t.dot(e),r=um(i.mul(.5).add(.5),0);if(s.material.gradientMap){const t=yx("gradientMap","texture").context({getUV:()=>r});return pm(t.r)}{const t=r.fwidth().mul(.5);return Oy(pm(.7),pm(1),Dy(nm(.7).sub(t.x),nm(.7).add(t.x),r.x))}}));class UC extends eg{direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r){const n=FC({normal:Hx,lightDirection:t,builder:r}).mul(e);s.directDiffuse.addAssign(n.mul(GR({diffuseColor:gg.rgb})))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:s}){s.indirectDiffuse.addAssign(e.mul(GR({diffuseColor:gg}))),s.indirectDiffuse.mulAssign(t)}}const OC=new Cu;class LC extends gT{constructor(t){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(OC),this.setValues(t)}setupLightingModel(){return new UC}}fT("MeshToonNodeMaterial",LC);const zC=new Fu;class VC extends gT{constructor(t){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(zC),this.setValues(t)}setupVariants(t){const e=nw;let s;s=t.material.matcap?yx("matcap","texture").context({getUV:()=>e}):pm(Oy(.2,.8,e.y)),gg.rgb.mulAssign(s.rgb)}}fT("MeshMatcapNodeMaterial",VC);const DC=new Va;class kC extends gT{constructor(t){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.normals=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(DC),this.setValues(t)}copy(t){return this.sizeNode=t.sizeNode,super.copy(t)}}fT("PointsNodeMaterial",kC);const GC=new uo;class WC extends gT{constructor(t){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this.normals=!1,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(GC),this.setValues(t)}setupPosition({object:t,context:e}){const{positionNode:s,rotationNode:i,scaleNode:r}=this,n=Db;let o=zx.mul(pm(s||0)),a=um(Dx[0].xyz.length(),Dx[1].xyz.length());null!==r&&(a=a.mul(r));let h=n.xy;t.center&&!0===t.center.isVector2&&(h=h.sub(hf(t.center).sub(.5))),h=h.mul(a);const u=nm(i||fb),l=h.rotate(u);o=ym(o.xy.add(l),o.zw);const c=_x.mul(o);return e.vertex=n,c}copy(t){return this.positionNode=t.positionNode,this.rotationNode=t.rotationNode,this.scaleNode=t.scaleNode,super.copy(t)}}fT("SpriteNodeMaterial",WC);class jC extends eg{constructor(){super(),this.shadowNode=nm(1).toVar("shadowMask")}direct({shadowMask:t}){this.shadowNode.mulAssign(t)}finish(t){gg.a.mulAssign(this.shadowNode.oneMinus()),t.outgoingLight.rgb.assign(gg.rgb)}}const HC=new Su;class qC extends gT{constructor(t){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(HC),this.setValues(t)}setupLightingModel(){return new jC}}fT("ShadowNodeMaterial",qC);class $C extends gT{constructor(t={}){super(),this.normals=!1,this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(t)}setup(t){const e=aA(this.map,null,0),s=Kp((({orig:t,dir:e})=>{const s=pm(-.5),i=pm(.5),r=e.reciprocal(),n=s.sub(t).mul(r),o=i.sub(t).mul(r),a=vy(n,o),h=Ty(n,o),u=Ty(a.x,Ty(a.y,a.z)),l=vy(h.x,vy(h.y,h.z));return um(u,l)}));this.fragmentNode=Kp((()=>{const t=km(pm(jx.mul(ym(Nx,1)))),i=km(Vb.sub(t)).normalize(),r=pg("vec2","bounds").assign(s({orig:t,dir:i}));r.x.greaterThan(r.y).discard(),r.assign(um(Ty(r.x,0),r.y));const n=pg("vec3","p").assign(t.add(r.x.mul(i))),o=pg("vec3","inc").assign(pm(i.abs().reciprocal())),a=pg("float","delta").assign(vy(o.x,vy(o.y,o.z)));a.divAssign(yx("steps","float"));const h=pg("vec4","ac").assign(ym(yx("base","color"),0));return dv({type:"float",start:r.x,end:r.y,update:"+= delta"},(()=>{const t=pg("float","d").assign(e.uv(n.add(.5)).r);null!==this.testNode?this.testNode({map:e,mapValue:t,probe:n,finalColor:h}).append():(h.a.assign(1),mv()),n.addAssign(i.mul(a))})),h.a.equal(0).discard(),ym(h)}))(),super.setup(t)}}fT("VolumeNodeMaterial",$C);const XC=Ul.createMaterialFromType;Ul.createMaterialFromType=function(t){const e=yT(t);return void 0!==e?e:XC.call(this,t)};class YC extends Ul{constructor(t){super(t),this.nodes={}}parse(t){const e=super.parse(t),s=this.nodes,i=t.inputNodes;for(const t in i){const r=i[t];e[t]=s[r]}return e}setNodes(t){return this.nodes=t,this}}class JC extends Vl{constructor(t){super(t),this._nodesJSON=null}parse(t,e){this._nodesJSON=t.nodes;const s=super.parse(t,e);return this._nodesJSON=null,s}parseNodes(t,e){if(void 0!==t){const s=new AR;return s.setTextures(e),s.parseNodes(t)}return{}}parseMaterials(t,e){const s={};if(void 0!==t){const i=this.parseNodes(this._nodesJSON,e),r=new YC;r.setTextures(e),r.setNodes(i);for(let e=0,i=t.length;e{const e=(t=t.trim()).indexOf(eE),s=-1!==e?t.slice(e+12):t,i=s.match(KC);if(null!==i&&5===i.length){const r=i[4],n=[];let o=null;for(;null!==(o=tE.exec(r));)n.push(o);const a=[];let h=0;for(;h{const i=nm(s).toVar(),r=nm(e).toVar(),n=hm(t).toVar();return FT(n,r,i)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),nE=Kp((([t,e])=>{const s=hm(e).toVar(),i=nm(t).toVar();return FT(s,i.negate(),i)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),oE=Kp((([t])=>{const e=nm(t).toVar();return om(Jf(e))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),aE=Kp((([t,e])=>{const s=nm(t).toVar();return e.assign(oE(s)),s.sub(nm(e))})),hE=iw([Kp((([t,e,s,i,r,n])=>{const o=nm(n).toVar(),a=nm(r).toVar(),h=nm(i).toVar(),u=nm(s).toVar(),l=nm(e).toVar(),c=nm(t).toVar(),d=nm(mf(1,a)).toVar();return mf(1,o).mul(c.mul(d).add(l.mul(a))).add(o.mul(u.mul(d).add(h.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),Kp((([t,e,s,i,r,n])=>{const o=nm(n).toVar(),a=nm(r).toVar(),h=pm(i).toVar(),u=pm(s).toVar(),l=pm(e).toVar(),c=pm(t).toVar(),d=nm(mf(1,a)).toVar();return mf(1,o).mul(c.mul(d).add(l.mul(a))).add(o.mul(u.mul(d).add(h.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),uE=iw([Kp((([t,e,s,i,r,n,o,a,h,u,l])=>{const c=nm(l).toVar(),d=nm(u).toVar(),p=nm(h).toVar(),m=nm(a).toVar(),g=nm(o).toVar(),f=nm(n).toVar(),y=nm(r).toVar(),x=nm(i).toVar(),b=nm(s).toVar(),v=nm(e).toVar(),T=nm(t).toVar(),_=nm(mf(1,p)).toVar(),w=nm(mf(1,d)).toVar();return nm(mf(1,c)).toVar().mul(w.mul(T.mul(_).add(v.mul(p))).add(d.mul(b.mul(_).add(x.mul(p))))).add(c.mul(w.mul(y.mul(_).add(f.mul(p))).add(d.mul(g.mul(_).add(m.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),Kp((([t,e,s,i,r,n,o,a,h,u,l])=>{const c=nm(l).toVar(),d=nm(u).toVar(),p=nm(h).toVar(),m=pm(a).toVar(),g=pm(o).toVar(),f=pm(n).toVar(),y=pm(r).toVar(),x=pm(i).toVar(),b=pm(s).toVar(),v=pm(e).toVar(),T=pm(t).toVar(),_=nm(mf(1,p)).toVar(),w=nm(mf(1,d)).toVar();return nm(mf(1,c)).toVar().mul(w.mul(T.mul(_).add(v.mul(p))).add(d.mul(b.mul(_).add(x.mul(p))))).add(c.mul(w.mul(y.mul(_).add(f.mul(p))).add(d.mul(g.mul(_).add(m.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),lE=Kp((([t,e,s])=>{const i=nm(s).toVar(),r=nm(e).toVar(),n=am(t).toVar(),o=am(n.bitAnd(am(7))).toVar(),a=nm(rE(o.lessThan(am(4)),r,i)).toVar(),h=nm(gf(2,rE(o.lessThan(am(4)),i,r))).toVar();return nE(a,hm(o.bitAnd(am(1)))).add(nE(h,hm(o.bitAnd(am(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),cE=Kp((([t,e,s,i])=>{const r=nm(i).toVar(),n=nm(s).toVar(),o=nm(e).toVar(),a=am(t).toVar(),h=am(a.bitAnd(am(15))).toVar(),u=nm(rE(h.lessThan(am(8)),o,n)).toVar(),l=nm(rE(h.lessThan(am(4)),n,rE(h.equal(am(12)).or(h.equal(am(14))),o,r))).toVar();return nE(u,hm(h.bitAnd(am(1)))).add(nE(l,hm(h.bitAnd(am(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),dE=iw([lE,cE]),pE=Kp((([t,e,s])=>{const i=nm(s).toVar(),r=nm(e).toVar(),n=gm(t).toVar();return pm(dE(n.x,r,i),dE(n.y,r,i),dE(n.z,r,i))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),mE=Kp((([t,e,s,i])=>{const r=nm(i).toVar(),n=nm(s).toVar(),o=nm(e).toVar(),a=gm(t).toVar();return pm(dE(a.x,o,n,r),dE(a.y,o,n,r),dE(a.z,o,n,r))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),gE=iw([pE,mE]),fE=Kp((([t])=>{const e=nm(t).toVar();return gf(.6616,e)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),yE=Kp((([t])=>{const e=nm(t).toVar();return gf(.982,e)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),xE=iw([fE,Kp((([t])=>{const e=pm(t).toVar();return gf(.6616,e)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),bE=iw([yE,Kp((([t])=>{const e=pm(t).toVar();return gf(.982,e)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),vE=Kp((([t,e])=>{const s=om(e).toVar(),i=am(t).toVar();return i.shiftLeft(s).bitOr(i.shiftRight(om(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),TE=Kp((([t,e,s])=>{t.subAssign(s),t.bitXorAssign(vE(s,om(4))),s.addAssign(e),e.subAssign(t),e.bitXorAssign(vE(t,om(6))),t.addAssign(s),s.subAssign(e),s.bitXorAssign(vE(e,om(8))),e.addAssign(t),t.subAssign(s),t.bitXorAssign(vE(s,om(16))),s.addAssign(e),e.subAssign(t),e.bitXorAssign(vE(t,om(19))),t.addAssign(s),s.subAssign(e),s.bitXorAssign(vE(e,om(4))),e.addAssign(t)})),_E=Kp((([t,e,s])=>{const i=am(s).toVar(),r=am(e).toVar(),n=am(t).toVar();return i.bitXorAssign(r),i.subAssign(vE(r,om(14))),n.bitXorAssign(i),n.subAssign(vE(i,om(11))),r.bitXorAssign(n),r.subAssign(vE(n,om(25))),i.bitXorAssign(r),i.subAssign(vE(r,om(16))),n.bitXorAssign(i),n.subAssign(vE(i,om(4))),r.bitXorAssign(n),r.subAssign(vE(n,om(14))),i.bitXorAssign(r),i.subAssign(vE(r,om(24))),i})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),wE=Kp((([t])=>{const e=am(t).toVar();return nm(e).div(nm(am(om(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),SE=Kp((([t])=>{const e=nm(t).toVar();return e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),ME=iw([Kp((([t])=>{const e=om(t).toVar(),s=am(am(1)).toVar(),i=am(am(om(3735928559)).add(s.shiftLeft(am(2))).add(am(13))).toVar();return _E(i.add(am(e)),i,i)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),Kp((([t,e])=>{const s=om(e).toVar(),i=om(t).toVar(),r=am(am(2)).toVar(),n=am().toVar(),o=am().toVar(),a=am().toVar();return n.assign(o.assign(a.assign(am(om(3735928559)).add(r.shiftLeft(am(2))).add(am(13))))),n.addAssign(am(i)),o.addAssign(am(s)),_E(n,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Kp((([t,e,s])=>{const i=om(s).toVar(),r=om(e).toVar(),n=om(t).toVar(),o=am(am(3)).toVar(),a=am().toVar(),h=am().toVar(),u=am().toVar();return a.assign(h.assign(u.assign(am(om(3735928559)).add(o.shiftLeft(am(2))).add(am(13))))),a.addAssign(am(n)),h.addAssign(am(r)),u.addAssign(am(i)),_E(a,h,u)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),Kp((([t,e,s,i])=>{const r=om(i).toVar(),n=om(s).toVar(),o=om(e).toVar(),a=om(t).toVar(),h=am(am(4)).toVar(),u=am().toVar(),l=am().toVar(),c=am().toVar();return u.assign(l.assign(c.assign(am(om(3735928559)).add(h.shiftLeft(am(2))).add(am(13))))),u.addAssign(am(a)),l.addAssign(am(o)),c.addAssign(am(n)),TE(u,l,c),u.addAssign(am(r)),_E(u,l,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),Kp((([t,e,s,i,r])=>{const n=om(r).toVar(),o=om(i).toVar(),a=om(s).toVar(),h=om(e).toVar(),u=om(t).toVar(),l=am(am(5)).toVar(),c=am().toVar(),d=am().toVar(),p=am().toVar();return c.assign(d.assign(p.assign(am(om(3735928559)).add(l.shiftLeft(am(2))).add(am(13))))),c.addAssign(am(u)),d.addAssign(am(h)),p.addAssign(am(a)),TE(c,d,p),c.addAssign(am(o)),d.addAssign(am(n)),_E(c,d,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),AE=iw([Kp((([t,e])=>{const s=om(e).toVar(),i=om(t).toVar(),r=am(ME(i,s)).toVar(),n=gm().toVar();return n.x.assign(r.bitAnd(om(255))),n.y.assign(r.shiftRight(om(8)).bitAnd(om(255))),n.z.assign(r.shiftRight(om(16)).bitAnd(om(255))),n})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Kp((([t,e,s])=>{const i=om(s).toVar(),r=om(e).toVar(),n=om(t).toVar(),o=am(ME(n,r,i)).toVar(),a=gm().toVar();return a.x.assign(o.bitAnd(om(255))),a.y.assign(o.shiftRight(om(8)).bitAnd(om(255))),a.z.assign(o.shiftRight(om(16)).bitAnd(om(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),NE=iw([Kp((([t])=>{const e=um(t).toVar(),s=om().toVar(),i=om().toVar(),r=nm(aE(e.x,s)).toVar(),n=nm(aE(e.y,i)).toVar(),o=nm(SE(r)).toVar(),a=nm(SE(n)).toVar(),h=nm(hE(dE(ME(s,i),r,n),dE(ME(s.add(om(1)),i),r.sub(1),n),dE(ME(s,i.add(om(1))),r,n.sub(1)),dE(ME(s.add(om(1)),i.add(om(1))),r.sub(1),n.sub(1)),o,a)).toVar();return xE(h)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),Kp((([t])=>{const e=pm(t).toVar(),s=om().toVar(),i=om().toVar(),r=om().toVar(),n=nm(aE(e.x,s)).toVar(),o=nm(aE(e.y,i)).toVar(),a=nm(aE(e.z,r)).toVar(),h=nm(SE(n)).toVar(),u=nm(SE(o)).toVar(),l=nm(SE(a)).toVar(),c=nm(uE(dE(ME(s,i,r),n,o,a),dE(ME(s.add(om(1)),i,r),n.sub(1),o,a),dE(ME(s,i.add(om(1)),r),n,o.sub(1),a),dE(ME(s.add(om(1)),i.add(om(1)),r),n.sub(1),o.sub(1),a),dE(ME(s,i,r.add(om(1))),n,o,a.sub(1)),dE(ME(s.add(om(1)),i,r.add(om(1))),n.sub(1),o,a.sub(1)),dE(ME(s,i.add(om(1)),r.add(om(1))),n,o.sub(1),a.sub(1)),dE(ME(s.add(om(1)),i.add(om(1)),r.add(om(1))),n.sub(1),o.sub(1),a.sub(1)),h,u,l)).toVar();return bE(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),RE=iw([Kp((([t])=>{const e=um(t).toVar(),s=om().toVar(),i=om().toVar(),r=nm(aE(e.x,s)).toVar(),n=nm(aE(e.y,i)).toVar(),o=nm(SE(r)).toVar(),a=nm(SE(n)).toVar(),h=pm(hE(gE(AE(s,i),r,n),gE(AE(s.add(om(1)),i),r.sub(1),n),gE(AE(s,i.add(om(1))),r,n.sub(1)),gE(AE(s.add(om(1)),i.add(om(1))),r.sub(1),n.sub(1)),o,a)).toVar();return xE(h)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Kp((([t])=>{const e=pm(t).toVar(),s=om().toVar(),i=om().toVar(),r=om().toVar(),n=nm(aE(e.x,s)).toVar(),o=nm(aE(e.y,i)).toVar(),a=nm(aE(e.z,r)).toVar(),h=nm(SE(n)).toVar(),u=nm(SE(o)).toVar(),l=nm(SE(a)).toVar(),c=pm(uE(gE(AE(s,i,r),n,o,a),gE(AE(s.add(om(1)),i,r),n.sub(1),o,a),gE(AE(s,i.add(om(1)),r),n,o.sub(1),a),gE(AE(s.add(om(1)),i.add(om(1)),r),n.sub(1),o.sub(1),a),gE(AE(s,i,r.add(om(1))),n,o,a.sub(1)),gE(AE(s.add(om(1)),i,r.add(om(1))),n.sub(1),o,a.sub(1)),gE(AE(s,i.add(om(1)),r.add(om(1))),n,o.sub(1),a.sub(1)),gE(AE(s.add(om(1)),i.add(om(1)),r.add(om(1))),n.sub(1),o.sub(1),a.sub(1)),h,u,l)).toVar();return bE(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),CE=iw([Kp((([t])=>{const e=nm(t).toVar(),s=om(oE(e)).toVar();return wE(ME(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),Kp((([t])=>{const e=um(t).toVar(),s=om(oE(e.x)).toVar(),i=om(oE(e.y)).toVar();return wE(ME(s,i))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),Kp((([t])=>{const e=pm(t).toVar(),s=om(oE(e.x)).toVar(),i=om(oE(e.y)).toVar(),r=om(oE(e.z)).toVar();return wE(ME(s,i,r))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),Kp((([t])=>{const e=ym(t).toVar(),s=om(oE(e.x)).toVar(),i=om(oE(e.y)).toVar(),r=om(oE(e.z)).toVar(),n=om(oE(e.w)).toVar();return wE(ME(s,i,r,n))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),EE=iw([Kp((([t])=>{const e=nm(t).toVar(),s=om(oE(e)).toVar();return pm(wE(ME(s,om(0))),wE(ME(s,om(1))),wE(ME(s,om(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),Kp((([t])=>{const e=um(t).toVar(),s=om(oE(e.x)).toVar(),i=om(oE(e.y)).toVar();return pm(wE(ME(s,i,om(0))),wE(ME(s,i,om(1))),wE(ME(s,i,om(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Kp((([t])=>{const e=pm(t).toVar(),s=om(oE(e.x)).toVar(),i=om(oE(e.y)).toVar(),r=om(oE(e.z)).toVar();return pm(wE(ME(s,i,r,om(0))),wE(ME(s,i,r,om(1))),wE(ME(s,i,r,om(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Kp((([t])=>{const e=ym(t).toVar(),s=om(oE(e.x)).toVar(),i=om(oE(e.y)).toVar(),r=om(oE(e.z)).toVar(),n=om(oE(e.w)).toVar();return pm(wE(ME(s,i,r,n,om(0))),wE(ME(s,i,r,n,om(1))),wE(ME(s,i,r,n,om(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),BE=Kp((([t,e,s,i])=>{const r=nm(i).toVar(),n=nm(s).toVar(),o=om(e).toVar(),a=pm(t).toVar(),h=nm(0).toVar(),u=nm(1).toVar();return dv(o,(()=>{h.addAssign(u.mul(NE(a))),u.mulAssign(r),a.mulAssign(n)})),h})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),IE=Kp((([t,e,s,i])=>{const r=nm(i).toVar(),n=nm(s).toVar(),o=om(e).toVar(),a=pm(t).toVar(),h=pm(0).toVar(),u=nm(1).toVar();return dv(o,(()=>{h.addAssign(u.mul(RE(a))),u.mulAssign(r),a.mulAssign(n)})),h})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),PE=Kp((([t,e,s,i])=>{const r=nm(i).toVar(),n=nm(s).toVar(),o=om(e).toVar(),a=pm(t).toVar();return um(BE(a,o,n,r),BE(a.add(pm(om(19),om(193),om(17))),o,n,r))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),FE=Kp((([t,e,s,i])=>{const r=nm(i).toVar(),n=nm(s).toVar(),o=om(e).toVar(),a=pm(t).toVar(),h=pm(IE(a,o,n,r)).toVar(),u=nm(BE(a.add(pm(om(19),om(193),om(17))),o,n,r)).toVar();return ym(h,u)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),UE=Kp((([t,e,s,i,r,n,o])=>{const a=om(o).toVar(),h=nm(n).toVar(),u=om(r).toVar(),l=om(i).toVar(),c=om(s).toVar(),d=om(e).toVar(),p=um(t).toVar(),m=pm(EE(um(d.add(l),c.add(u)))).toVar(),g=um(m.x,m.y).toVar();g.subAssign(.5),g.mulAssign(h),g.addAssign(.5);const f=um(um(nm(d),nm(c)).add(g)).toVar(),y=um(f.sub(p)).toVar();return sm(a.equal(om(2)),(()=>oy(y.x).add(oy(y.y)))),sm(a.equal(om(3)),(()=>Ty(oy(y.x),oy(y.y)))),Ny(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),OE=iw([UE,Kp((([t,e,s,i,r,n,o,a,h])=>{const u=om(h).toVar(),l=nm(a).toVar(),c=om(o).toVar(),d=om(n).toVar(),p=om(r).toVar(),m=om(i).toVar(),g=om(s).toVar(),f=om(e).toVar(),y=pm(t).toVar(),x=pm(EE(pm(f.add(p),g.add(d),m.add(c)))).toVar();x.subAssign(.5),x.mulAssign(l),x.addAssign(.5);const b=pm(pm(nm(f),nm(g),nm(m)).add(x)).toVar(),v=pm(b.sub(y)).toVar();return sm(u.equal(om(2)),(()=>oy(v.x).add(oy(v.y)).add(oy(v.z)))),sm(u.equal(om(3)),(()=>Ty(Ty(oy(v.x),oy(v.y)),oy(v.z)))),Ny(v,v)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),LE=Kp((([t,e,s])=>{const i=om(s).toVar(),r=nm(e).toVar(),n=um(t).toVar(),o=om().toVar(),a=om().toVar(),h=um(aE(n.x,o),aE(n.y,a)).toVar(),u=nm(1e6).toVar();return dv({start:-1,end:om(1),name:"x",condition:"<="},(({x:t})=>{dv({start:-1,end:om(1),name:"y",condition:"<="},(({y:e})=>{const s=nm(OE(h,t,e,o,a,r,i)).toVar();u.assign(vy(u,s))}))})),sm(i.equal(om(0)),(()=>{u.assign(Xf(u))})),u})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),zE=Kp((([t,e,s])=>{const i=om(s).toVar(),r=nm(e).toVar(),n=um(t).toVar(),o=om().toVar(),a=om().toVar(),h=um(aE(n.x,o),aE(n.y,a)).toVar(),u=um(1e6,1e6).toVar();return dv({start:-1,end:om(1),name:"x",condition:"<="},(({x:t})=>{dv({start:-1,end:om(1),name:"y",condition:"<="},(({y:e})=>{const s=nm(OE(h,t,e,o,a,r,i)).toVar();sm(s.lessThan(u.x),(()=>{u.y.assign(u.x),u.x.assign(s)})).elseif(s.lessThan(u.y),(()=>{u.y.assign(s)}))}))})),sm(i.equal(om(0)),(()=>{u.assign(Xf(u))})),u})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),VE=Kp((([t,e,s])=>{const i=om(s).toVar(),r=nm(e).toVar(),n=um(t).toVar(),o=om().toVar(),a=om().toVar(),h=um(aE(n.x,o),aE(n.y,a)).toVar(),u=pm(1e6,1e6,1e6).toVar();return dv({start:-1,end:om(1),name:"x",condition:"<="},(({x:t})=>{dv({start:-1,end:om(1),name:"y",condition:"<="},(({y:e})=>{const s=nm(OE(h,t,e,o,a,r,i)).toVar();sm(s.lessThan(u.x),(()=>{u.z.assign(u.y),u.y.assign(u.x),u.x.assign(s)})).elseif(s.lessThan(u.y),(()=>{u.z.assign(u.y),u.y.assign(s)})).elseif(s.lessThan(u.z),(()=>{u.z.assign(s)}))}))})),sm(i.equal(om(0)),(()=>{u.assign(Xf(u))})),u})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),DE=iw([LE,Kp((([t,e,s])=>{const i=om(s).toVar(),r=nm(e).toVar(),n=pm(t).toVar(),o=om().toVar(),a=om().toVar(),h=om().toVar(),u=pm(aE(n.x,o),aE(n.y,a),aE(n.z,h)).toVar(),l=nm(1e6).toVar();return dv({start:-1,end:om(1),name:"x",condition:"<="},(({x:t})=>{dv({start:-1,end:om(1),name:"y",condition:"<="},(({y:e})=>{dv({start:-1,end:om(1),name:"z",condition:"<="},(({z:s})=>{const n=nm(OE(u,t,e,s,o,a,h,r,i)).toVar();l.assign(vy(l,n))}))}))})),sm(i.equal(om(0)),(()=>{l.assign(Xf(l))})),l})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),kE=iw([zE,Kp((([t,e,s])=>{const i=om(s).toVar(),r=nm(e).toVar(),n=pm(t).toVar(),o=om().toVar(),a=om().toVar(),h=om().toVar(),u=pm(aE(n.x,o),aE(n.y,a),aE(n.z,h)).toVar(),l=um(1e6,1e6).toVar();return dv({start:-1,end:om(1),name:"x",condition:"<="},(({x:t})=>{dv({start:-1,end:om(1),name:"y",condition:"<="},(({y:e})=>{dv({start:-1,end:om(1),name:"z",condition:"<="},(({z:s})=>{const n=nm(OE(u,t,e,s,o,a,h,r,i)).toVar();sm(n.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(n)})).elseif(n.lessThan(l.y),(()=>{l.y.assign(n)}))}))}))})),sm(i.equal(om(0)),(()=>{l.assign(Xf(l))})),l})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),GE=iw([VE,Kp((([t,e,s])=>{const i=om(s).toVar(),r=nm(e).toVar(),n=pm(t).toVar(),o=om().toVar(),a=om().toVar(),h=om().toVar(),u=pm(aE(n.x,o),aE(n.y,a),aE(n.z,h)).toVar(),l=pm(1e6,1e6,1e6).toVar();return dv({start:-1,end:om(1),name:"x",condition:"<="},(({x:t})=>{dv({start:-1,end:om(1),name:"y",condition:"<="},(({y:e})=>{dv({start:-1,end:om(1),name:"z",condition:"<="},(({z:s})=>{const n=nm(OE(u,t,e,s,o,a,h,r,i)).toVar();sm(n.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(n)})).elseif(n.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(n)})).elseif(n.lessThan(l.z),(()=>{l.z.assign(n)}))}))}))})),sm(i.equal(om(0)),(()=>{l.assign(Xf(l))})),l})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),WE=Kp((([t])=>{const e=pm(t).toVar(),s=nm(e.x).toVar(),i=nm(e.y).toVar(),r=nm(e.z).toVar();sm(i.lessThan(1e-4),(()=>pm(r,r,r))).else((()=>{s.assign(gf(6,s.sub(Jf(s))));const t=om(gy(s)).toVar(),e=nm(s.sub(nm(t))).toVar(),n=nm(r.mul(mf(1,i))).toVar(),o=nm(r.mul(mf(1,i.mul(e)))).toVar(),a=nm(r.mul(mf(1,i.mul(mf(1,e))))).toVar();return sm(t.equal(om(0)),(()=>pm(r,a,n))).elseif(t.equal(om(1)),(()=>pm(o,r,n))).elseif(t.equal(om(2)),(()=>pm(n,r,a))).elseif(t.equal(om(3)),(()=>pm(n,o,r))).elseif(t.equal(om(4)),(()=>pm(a,n,r))),pm(r,n,o)}))})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),jE=Kp((([t])=>{const e=pm(t).toVar(),s=nm(e.x).toVar(),i=nm(e.y).toVar(),r=nm(e.z).toVar(),n=nm(vy(s,vy(i,r))).toVar(),o=nm(Ty(s,Ty(i,r))).toVar(),a=nm(o.sub(n)).toVar(),h=nm().toVar(),u=nm().toVar(),l=nm().toVar();return l.assign(o),sm(o.greaterThan(0),(()=>{u.assign(a.div(o))})).else((()=>{u.assign(0)})),sm(u.lessThanEqual(0),(()=>{h.assign(0)})).else((()=>{sm(s.greaterThanEqual(o),(()=>{h.assign(i.sub(r).div(a))})).elseif(i.greaterThanEqual(o),(()=>{h.assign(pf(2,r.sub(s).div(a)))})).else((()=>{h.assign(pf(4,s.sub(i).div(a)))})),h.mulAssign(1/6),sm(h.lessThan(0),(()=>{h.addAssign(1)}))})),pm(h,u,l)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),HE=Kp((([t])=>{const e=pm(t).toVar(),s=fm(Tf(e,pm(.04045))).toVar(),i=pm(e.div(12.92)).toVar(),r=pm(Cy(Ty(e.add(pm(.055)),pm(0)).div(1.055),pm(2.4))).toVar();return Oy(i,r,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),qE=(t,e)=>{t=nm(t),e=nm(e);const s=um(e.dFdx(),e.dFdy()).length().mul(.7071067811865476);return Dy(t.sub(s),t.add(s),e)},$E=(t,e,s,i)=>Oy(t,e,s[i].clamp()),XE=(t,e,s=uf())=>$E(t,e,s,"x"),YE=(t,e,s=uf())=>$E(t,e,s,"y"),JE=(t,e,s,i,r)=>Oy(t,e,qE(s,i[r])),ZE=(t,e,s,i=uf())=>JE(t,e,s,i,"x"),QE=(t,e,s,i=uf())=>JE(t,e,s,i,"y"),KE=(t=1,e=0,s=uf())=>s.mul(t).add(e),tB=(t,e=1)=>(t=nm(t)).abs().pow(e).mul(t.sign()),eB=(t,e=1,s=.5)=>nm(t).sub(s).mul(e).add(s),sB=(t=uf(),e=1,s=0)=>NE(t.convert("vec2|vec3")).mul(e).add(s),iB=(t=uf(),e=1,s=0)=>RE(t.convert("vec2|vec3")).mul(e).add(s),rB=(t=uf(),e=1,s=0)=>{t=t.convert("vec2|vec3");return ym(RE(t),NE(t.add(um(19,73)))).mul(e).add(s)},nB=(t=uf(),e=1)=>DE(t.convert("vec2|vec3"),e,om(1)),oB=(t=uf(),e=1)=>kE(t.convert("vec2|vec3"),e,om(1)),aB=(t=uf(),e=1)=>GE(t.convert("vec2|vec3"),e,om(1)),hB=(t=uf())=>CE(t.convert("vec2|vec3")),uB=(t=uf(),e=3,s=2,i=.5,r=1)=>BE(t,om(e),s,i).mul(r),lB=(t=uf(),e=3,s=2,i=.5,r=1)=>PE(t,om(e),s,i).mul(r),cB=(t=uf(),e=3,s=2,i=.5,r=1)=>IE(t,om(e),s,i).mul(r),dB=(t=uf(),e=3,s=2,i=.5,r=1)=>FE(t,om(e),s,i).mul(r);function pB(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.material.id!==e.material.id?t.material.id-e.material.id:t.z!==e.z?t.z-e.z:t.id-e.id}function mB(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.z!==e.z?e.z-t.z:t.id-e.id}class gB{constructor(){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparent=[],this.bundles=[],this.lightsNode=new Ev([]),this.lightsArray=[],this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(t,e,s,i,r,n){let o=this.renderItems[this.renderItemsIndex];return void 0===o?(o={id:t.id,object:t,geometry:e,material:s,groupOrder:i,renderOrder:t.renderOrder,z:r,group:n},this.renderItems[this.renderItemsIndex]=o):(o.id=t.id,o.object=t,o.geometry=e,o.material=s,o.groupOrder=i,o.renderOrder=t.renderOrder,o.z=r,o.group=n),this.renderItemsIndex++,o}push(t,e,s,i,r,n){const o=this.getNextRenderItem(t,e,s,i,r,n);!0===t.occlusionTest&&this.occlusionQueryCount++,(!0===s.transparent||s.transmission>0?this.transparent:this.opaque).push(o)}unshift(t,e,s,i,r,n){const o=this.getNextRenderItem(t,e,s,i,r,n);(!0===s.transparent?this.transparent:this.opaque).unshift(o)}pushBundle(t){this.bundles.push(t)}pushLight(t){this.lightsArray.push(t)}getLightsNode(){return this.lightsNode.fromLights(this.lightsArray)}sort(t,e){this.opaque.length>1&&this.opaque.sort(t||pB),this.transparent.length>1&&this.transparent.sort(e||mB)}finish(){this.lightsNode.fromLights(this.lightsArray);for(let t=this.renderItemsIndex,e=this.renderItems.length;t>e,u=a.height>>e;let l=t.depthTexture||r[e],c=!1;void 0===l&&(l=new Ka,l.format=t.stencilBuffer?jt:Wt,l.type=t.stencilBuffer?Ot:Bt,l.image.width=h,l.image.height=u,r[e]=l),s.width===a.width&&a.height===s.height||(c=!0,l.needsUpdate=!0,l.image.width=h,l.image.height=u),s.width=a.width,s.height=a.height,s.textures=o,s.depthTexture=l,s.depth=t.depthBuffer,s.stencil=t.stencilBuffer,s.renderTarget=t,s.sampleCount!==i&&(c=!0,l.needsUpdate=!0,s.sampleCount=i);const d={sampleCount:i};for(let t=0;t{if(t.removeEventListener("dispose",e),void 0!==o)for(let t=0;t0){const i=t.image;if(void 0===i)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===i.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(t.images){const s=[];for(const e of t.images)s.push(e);e.images=s}else e.image=i;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(r.createTexture(t,e),s.isDefaultTexture=!1),!0===t.source.dataReady&&r.updateTexture(t,e),e.needsMipmaps&&0===t.mipmaps.length&&r.generateMipmaps(t)}}else r.createDefaultTexture(t),s.isDefaultTexture=!0}if(!0!==s.initialized){s.initialized=!0,this.info.memory.textures++;const e=()=>{t.removeEventListener("dispose",e),this._destroyTexture(t),this.info.memory.textures--};t.addEventListener("dispose",e)}s.version=t.version}getSize(t,e=vB){let s=t.images?t.images[0]:t.image;return s?(void 0!==s.image&&(s=s.image),e.width=s.width,e.height=s.height,e.depth=t.isCubeTexture?6:s.depth||1):e.width=e.height=e.depth=1,e}getMipLevels(t,e,s){let i;return i=t.isCompressedTexture?t.mipmaps.length:Math.floor(Math.log2(Math.max(e,s)))+1,i}needsMipmaps(t){return!!this.isEnvironmentTexture(t)||(!0===t.isCompressedTexture||t.minFilter!==ft&&t.minFilter!==Tt)}isEnvironmentTexture(t){const e=t.mapping;return e===lt||e===ct||e===ht||e===ut}_destroyTexture(t){this.backend.destroySampler(t),this.backend.destroyTexture(t),this.delete(t)}}class _B extends Yr{constructor(t,e,s,i=1){super(t,e,s),this.a=i}set(t,e,s,i=1){return this.a=i,super.set(t,e,s)}copy(t){return void 0!==t.a&&(this.a=t.a),super.copy(t)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}const wB=new _B;class SB extends Cd{constructor(t,e){super(),this.renderer=t,this.nodes=e}update(t,e,s){const i=this.renderer,r=this.nodes.getBackgroundNode(t)||t.background;let n=!1;if(null===r)i._clearColor.getRGB(wB,Ze),wB.a=i._clearColor.a;else if(!0===r.isColor)r.getRGB(wB,Ze),wB.a=1,n=!0;else if(!0===r.isNode){const s=this.get(t),n=r;wB.copy(i._clearColor);let o=s.backgroundMesh;if(void 0===o){const t=Ym(ym(n).mul(IS),{getUV:()=>Xx,getTextureLevel:()=>BS});let e=qb();e=e.setZ(e.w);const i=new gT;i.side=d,i.depthTest=!1,i.depthWrite=!1,i.fog=!1,i.lights=!1,i.vertexNode=e,i.colorNode=t,s.backgroundMeshNode=t,s.backgroundMesh=o=new Wn(new fu(1,32,32),i),o.frustumCulled=!1,o.onBeforeRender=function(t,e,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=n.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=ym(n).mul(IS),o.material.needsUpdate=!0,s.backgroundCacheKey=a),e.unshift(o,o.geometry,o.material,0,0,null)}else console.error("THREE.Renderer: Unsupported background configuration.",r);if(!0===i.autoClear||!0===n){wB.multiplyScalar(wB.a);const t=s.clearColorValue;t.r=wB.r,t.g=wB.g,t.b=wB.b,t.a=wB.a,s.depthClearValue=i._clearDepth,s.stencilClearValue=i._clearStencil,s.clearColor=!0===i.autoClearColor,s.clearDepth=!0===i.autoClearDepth,s.clearStencil=!0===i.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}class MB{constructor(t,e,s,i,r,n,o,a,h=!0,u=[]){this.vertexShader=t,this.fragmentShader=e,this.computeShader=s,this.transforms=u,this.nodeAttributes=i,this.bindings=r,this.updateNodes=n,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.instanceBindGroups=h,this.usedTimes=0}createBindings(){const t=[];for(const e of this.bindings){if(!0!==(this.instanceBindGroups&&e.bindings[0].groupNode.shared)){const s=new N_(e.name);t.push(s);for(const t of e.bindings)s.bindings.push(t.clone())}else t.push(e)}return t}}const AB=new WeakMap;class NB extends Cd{constructor(t,e){super(),this.renderer=t,this.backend=e,this.nodeFrame=new P_,this.nodeBuilderCache=new Map,this.callHashCache=new _d,this.groupsData=new _d}updateGroup(t){const e=t.groupNode,s=e.name;if(s===of.name)return!0;if(s===nf.name){const e=this.get(t),s=this.nodeFrame.renderId;return e.renderId!==s&&(e.renderId=s,!0)}if(s===rf.name){const e=this.get(t),s=this.nodeFrame.frameId;return e.frameId!==s&&(e.frameId=s,!0)}const i=[e,t];let r=this.groupsData.get(i);return void 0===r&&this.groupsData.set(i,r={}),r.version!==e.version&&(r.version=e.version,!0)}getForRenderCacheKey(t){return t.initialCacheKey}getForRender(t){const e=this.get(t);let s=e.nodeBuilderState;if(void 0===s){const{nodeBuilderCache:i}=this,r=this.getForRenderCacheKey(t);if(s=i.get(r),void 0===s){const e=this.backend.createNodeBuilder(t.object,this.renderer);e.scene=t.scene,e.material=t.material,e.camera=t.camera,e.context.material=t.material,e.lightsNode=t.lightsNode,e.environmentNode=this.getEnvironmentNode(t.scene),e.fogNode=this.getFogNode(t.scene),e.clippingContext=t.clippingContext,e.build(),s=this._createNodeBuilderState(e),i.set(r,s)}s.usedTimes++,e.nodeBuilderState=s}return s}delete(t){if(t.isRenderObject){const e=this.get(t).nodeBuilderState;e.usedTimes--,0===e.usedTimes&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(t))}return super.delete(t)}getForCompute(t){const e=this.get(t);let s=e.nodeBuilderState;if(void 0===s){const i=this.backend.createNodeBuilder(t,this.renderer);i.build(),s=this._createNodeBuilderState(i),e.nodeBuilderState=s}return s}_createNodeBuilderState(t){return new MB(t.vertexShader,t.fragmentShader,t.computeShader,t.getAttributesArray(),t.getBindings(),t.updateNodes,t.updateBeforeNodes,t.updateAfterNodes,t.instanceBindGroups,t.transforms)}getEnvironmentNode(t){return t.environmentNode||this.get(t).environmentNode||null}getBackgroundNode(t){return t.backgroundNode||this.get(t).backgroundNode||null}getFogNode(t){return t.fogNode||this.get(t).fogNode||null}getCacheKey(t,e){const s=[t,e],i=this.renderer.info.calls;let r=this.callHashCache.get(s);if(void 0===r||r.callId!==i){const n=this.getEnvironmentNode(t),o=this.getFogNode(t),a=[];e&&a.push(e.getCacheKey()),n&&a.push(n.getCacheKey()),o&&a.push(o.getCacheKey()),r={callId:i,cacheKey:a.join(",")},this.callHashCache.set(s,r)}return r.cacheKey}updateScene(t){this.updateEnvironment(t),this.updateFog(t),this.updateBackground(t)}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(t){const e=this.get(t),s=t.background;if(s){if(e.background!==s){let t=null;!0===s.isCubeTexture||s.mapping===lt||s.mapping===ct?t=yR(s,Xx):!0===s.isTexture?t=rx(s,Hv).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s),e.backgroundNode=t,e.background=s}}else e.backgroundNode&&(delete e.backgroundNode,delete e.background)}updateFog(t){const e=this.get(t),s=t.fog;if(s){if(e.fog!==s){let t=null;s.isFogExp2?t=$N(mx("color","color",s),mx("density","float",s)):s.isFog?t=HN(mx("color","color",s),mx("near","float",s),mx("far","float",s)):console.error("WebGPUNodes: Unsupported fog configuration.",s),e.fogNode=t,e.fog=s}}else delete e.fogNode,delete e.fog}updateEnvironment(t){const e=this.get(t),s=t.environment;if(s){if(e.environment!==s){let t=null;!0===s.isCubeTexture?t=Mv(s):!0===s.isTexture?t=rx(s):console.error("Nodes: Unsupported environment configuration.",s),e.environmentNode=t,e.environment=s}}else e.environmentNode&&(delete e.environmentNode,delete e.environment)}getNodeFrame(t=this.renderer,e=null,s=null,i=null,r=null){const n=this.nodeFrame;return n.renderer=t,n.scene=e,n.object=s,n.camera=i,n.material=r,n}getNodeFrameForRender(t){return this.getNodeFrame(t.renderer,t.scene,t.object,t.camera,t.material)}getOutputCacheKey(){const t=this.renderer;return t.toneMapping+","+t.currentColorSpace}hasOutputChange(t){return AB.get(t)!==this.getOutputCacheKey()}getOutputNode(t){const e=this.renderer,s=this.getOutputCacheKey(),i=rx(t,jv).renderOutput(e.toneMapping,e.currentColorSpace);return AB.set(t,s),i}updateBefore(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateBeforeNodes)e.updateBeforeNode(t)}updateAfter(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateAfterNodes)e.updateAfterNode(t)}updateForCompute(t){const e=this.getNodeFrame(),s=this.getForCompute(t);for(const t of s.updateNodes)e.updateNode(t)}updateForRender(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateNodes)e.updateNode(t)}dispose(){super.dispose(),this.nodeFrame=new P_,this.nodeBuilderCache=new Map}}class RB{constructor(t,e){this.scene=t,this.camera=e}clone(){return Object.assign(new this.constructor,this)}}class CB{constructor(){this.lists=new _d}get(t,e){const s=this.lists,i=[t,e];let r=s.get(i);return void 0===r&&(r=new RB(t,e),s.set(i,r)),r}dispose(){this.lists=new _d}}const EB=new no,BB=new Ks,IB=new _i,PB=new na,FB=new or,UB=new Ei;class OB{constructor(t,e={}){this.isRenderer=!0;const{logarithmicDepthBuffer:s=!1,alpha:i=!0,antialias:r=!1,samples:n=0}=e;this.domElement=t.getDomElement(),this.backend=t,this.samples=n||!0===r?4:0,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=i,this.logarithmicDepthBuffer=s,this.outputColorSpace=Je,this.toneMapping=0,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=!0,this.stencil=!1,this.clippingPlanes=[],this.info=new zd,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new _i(0,0,this._width,this._height),this._scissor=new _i(0,0,this._width,this._height),this._scissorTest=!1,this._attributes=null,this._geometries=null,this._nodes=null,this._animation=null,this._bindings=null,this._objects=null,this._pipelines=null,this._bundles=null,this._renderLists=null,this._renderContexts=null,this._textures=null,this._background=null,this._quad=new Zw(new gT),this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;const o=!0===this.alpha?0:1;this._clearColor=new _B(0,0,0,o),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._mrt=null,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._initialized=!1,this._initPromise=null,this._compilationPromises=null,this.shadowMap={enabled:!1,type:null},this.xr={enabled:!1},this.debug={checkShaderErrors:!0,onShaderError:null}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(t,e)=>{const s=this.backend;try{await s.init(this)}catch(t){return void e(t)}this._nodes=new NB(this,s),this._animation=new Td(this._nodes,this.info),this._attributes=new Fd(s),this._background=new SB(this,this._nodes),this._geometries=new Ld(this._attributes,this.info),this._textures=new TB(this,s,this.info),this._pipelines=new jd(s,this._nodes),this._bindings=new Hd(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Rd(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new fB,this._bundles=new CB,this._renderContexts=new bB,this._initialized=!0,t()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(t,e,s=null){!1===this._initialized&&await this.init();const i=this._nodes.nodeFrame,r=i.renderId,n=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,h=!0===t.isScene?t:EB;null===s&&(s=t);const u=this._renderTarget,l=this._renderContexts.get(s,e,u),c=this._activeMipmapLevel,d=[];this._currentRenderContext=l,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=d,i.renderId++,i.update(),l.depth=this.depth,l.stencil=this.stencil,l.clippingContext||(l.clippingContext=new Md),l.clippingContext.updateGlobal(this,e),h.onBeforeRender(this,t,e,u);const p=this._renderLists.get(t,e);if(p.begin(),this._projectObject(t,e,0,p),s!==t&&s.traverseVisible((function(t){t.isLight&&t.layers.test(e.layers)&&p.pushLight(t)})),p.finish(),null!==u){this._textures.updateRenderTarget(u,c);const t=this._textures.get(u);l.textures=t.textures,l.depthTexture=t.depthTexture}else l.textures=null,l.depthTexture=null;this._nodes.updateScene(h),this._background.update(h,p,l);const m=p.opaque,g=p.transparent,f=p.lightsNode;m.length>0&&this._renderObjects(m,e,h,f),g.length>0&&this._renderObjects(g,e,h,f),i.renderId=r,this._currentRenderContext=n,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(d)}async renderAsync(t,e){!1===this._initialized&&await this.init();const s=this._renderScene(t,e);await this.backend.resolveTimestampAsync(s,"render")}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}_renderBundle(t,e,s){const{object:i,camera:r,renderList:n}=t,o=this._currentRenderContext,a=this.backend.get(o),h=this._bundles.get(i,r),u=this.backend.get(h);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=!1===u.renderContexts.has(o)||!0===i.needsUpdate;if(u.renderContexts.add(o),l){if(void 0===a.renderObjects||!0===i.needsUpdate){const t=this._nodes.nodeFrame;a.renderObjects=[],a.renderBundles=[],a.scene=e,a.camera=r,a.renderId=t.renderId,a.registerBundlesPhase=!0}this._currentRenderBundle=h;const t=n.opaque;t.length>0&&this._renderObjects(t,r,e,s),this._currentRenderBundle=null,i.needsUpdate=!1}else{const t=this._currentRenderContext,e=this.backend.get(t);for(let t=0,s=e.renderObjects.length;t>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=x,p.viewportValue.maxDepth=b,p.viewport=!1===p.viewportValue.equals(IB),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(IB),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new Md),p.clippingContext.updateGlobal(this,e),h.onBeforeRender(this,t,e,d),FB.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),PB.setFromProjectionMatrix(FB,m);const v=this._renderLists.get(t,e);if(v.begin(),this._projectObject(t,e,0,v),v.finish(),!0===this.sortObjects&&v.sort(this._opaqueSort,this._transparentSort),null!==d){this._textures.updateRenderTarget(d,c);const t=this._textures.get(d);p.textures=t.textures,p.depthTexture=t.depthTexture,p.width=t.width,p.height=t.height,p.renderTarget=d,p.depth=d.depthBuffer,p.stencil=d.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=l,p.activeMipmapLevel=c,p.occlusionQueryCount=v.occlusionQueryCount,this._nodes.updateScene(h),this._background.update(h,v,p),this.backend.beginRender(p);const T=v.opaque,_=v.transparent,w=v.bundles,S=v.lightsNode;if(w.length>0&&this._renderBundles(w,h,S),T.length>0&&this._renderObjects(T,e,h,S),_.length>0&&this._renderObjects(_,e,h,S),this.backend.finishRender(p),r.renderId=n,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==i){this.setRenderTarget(u,l,c);const t=this._quad;this._nodes.hasOutputChange(d.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(d.texture),t.material.needsUpdate=!0),this._renderScene(t,t.camera,!1)}return h.onAfterRender(this,t,e,d),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(t){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(t)}async getArrayBufferAsync(t){return await this.backend.getArrayBufferAsync(t)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(t){return t.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(t){return t.set(this._width,this._height)}setPixelRatio(t=1){this._pixelRatio=t,this.setSize(this._width,this._height,!1)}setDrawingBufferSize(t,e,s){this._width=t,this._height=e,this._pixelRatio=s,this.domElement.width=Math.floor(t*s),this.domElement.height=Math.floor(e*s),this.setViewport(0,0,t,e),this._initialized&&this.backend.updateSize()}setSize(t,e,s=!0){this._width=t,this._height=e,this.domElement.width=Math.floor(t*this._pixelRatio),this.domElement.height=Math.floor(e*this._pixelRatio),!0===s&&(this.domElement.style.width=t+"px",this.domElement.style.height=e+"px"),this.setViewport(0,0,t,e),this._initialized&&this.backend.updateSize()}setOpaqueSort(t){this._opaqueSort=t}setTransparentSort(t){this._transparentSort=t}getScissor(t){const e=this._scissor;return t.x=e.x,t.y=e.y,t.width=e.width,t.height=e.height,t}setScissor(t,e,s,i){const r=this._scissor;t.isVector4?r.copy(t):r.set(t,e,s,i)}getScissorTest(){return this._scissorTest}setScissorTest(t){this._scissorTest=t,this.backend.setScissorTest(t)}getViewport(t){return t.copy(this._viewport)}setViewport(t,e,s,i,r=0,n=1){const o=this._viewport;t.isVector4?o.copy(t):o.set(t,e,s,i),o.minDepth=r,o.maxDepth=n}getClearColor(t){return t.copy(this._clearColor)}setClearColor(t,e=1){this._clearColor.set(t),this._clearColor.a=e}getClearAlpha(){return this._clearColor.a}setClearAlpha(t){this._clearColor.a=t}getClearDepth(){return this._clearDepth}setClearDepth(t){this._clearDepth=t}getClearStencil(){return this._clearStencil}setClearStencil(t){this._clearStencil=t}isOccluded(t){const e=this._currentRenderContext;return e&&this.backend.isOccluded(e,t)}clear(t=!0,e=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(t,e,s);const i=this._renderTarget||this._getFrameBufferTarget();let r=null;if(null!==i&&(this._textures.updateRenderTarget(i),r=this._textures.get(i)),this.backend.clear(t,e,s,r),null!==i&&null===this._renderTarget){const t=this._quad;this._nodes.hasOutputChange(i.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(i.texture),t.material.needsUpdate=!0),this._renderScene(t,t.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(t=!0,e=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(t,e,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentColorSpace(){const t=this._renderTarget;if(null!==t){const e=t.texture;return(Array.isArray(e)?e[0]:e).colorSpace}return this.outputColorSpace}dispose(){this.info.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(t,e=0,s=0){this._renderTarget=t,this._activeCubeFace=e,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(t){this._renderObjectFunction=t}getRenderObjectFunction(){return this._renderObjectFunction}async computeAsync(t){!1===this._initialized&&await this.init();const e=this._nodes.nodeFrame,s=e.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,e.renderId=this.info.calls;const i=this.backend,r=this._pipelines,n=this._bindings,o=this._nodes,a=Array.isArray(t)?t:[t];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");i.beginCompute(t);for(const e of a){if(!1===r.has(e)){const t=()=>{e.removeEventListener("dispose",t),r.delete(e),n.delete(e),o.delete(e)};e.addEventListener("dispose",t),e.onInit({renderer:this})}o.updateForCompute(e),n.updateForCompute(e);const s=n.getForCompute(e),a=r.getForCompute(e,s);i.compute(t,e,s,a)}i.finishCompute(t),await this.backend.resolveTimestampAsync(t,"compute"),e.renderId=s}async hasFeatureAsync(t){return!1===this._initialized&&await this.init(),this.backend.hasFeature(t)}hasFeature(t){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(t)}copyFramebufferToTexture(t){const e=this._currentRenderContext;this._textures.updateTexture(t),this.backend.copyFramebufferToTexture(t,e)}copyTextureToTexture(t,e,s=null,i=null,r=0){this._textures.updateTexture(t),this._textures.updateTexture(e),this.backend.copyTextureToTexture(t,e,s,i,r)}readRenderTargetPixelsAsync(t,e,s,i,r,n=0){return this.backend.copyTextureToBuffer(t.textures[n],e,s,i,r)}_projectObject(t,e,s,i){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)s=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)i.pushLight(t);else if(t.isSprite){if(!t.frustumCulled||PB.intersectsSprite(t)){!0===this.sortObjects&&UB.setFromMatrixPosition(t.matrixWorld).applyMatrix4(FB);const e=t.geometry,r=t.material;r.visible&&i.push(t,e,r,s,UB.z,null)}}else if(t.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((t.isMesh||t.isLine||t.isPoints)&&(!t.frustumCulled||PB.intersectsObject(t))){const e=t.geometry,r=t.material;if(!0===this.sortObjects&&(null===e.boundingSphere&&e.computeBoundingSphere(),UB.copy(e.boundingSphere.center).applyMatrix4(t.matrixWorld).applyMatrix4(FB)),Array.isArray(r)){const n=e.groups;for(let o=0,a=n.length;o0?i:"";e=`${t.name} {\n\t${s} ${r.name}[${n}];\n};\n`}else{e=`${this.getVectorType(r.type)} ${this.getPropertyName(r,t)};`,n=!0}const o=r.node.precision;if(null!==o&&(e=ZB[o]+" "+e),n){e="\t"+e;const t=r.groupNode.name;(i[t]||(i[t]=[])).push(e)}else e="uniform "+e,s.push(e)}let r="";for(const e in i){const s=i[e];r+=this._getGLSLUniformStruct(t+"_"+e,s.join("\n"))+"\n"}return r+=s.join("\n"),r}getTypeFromAttribute(t){let e=super.getTypeFromAttribute(t);if(/^[iu]/.test(e)&&t.gpuType!==Et){let s=t;t.isInterleavedBufferAttribute&&(s=t.data);const i=s.array;!1==(i instanceof Uint32Array||i instanceof Int32Array||i instanceof Uint16Array||i instanceof Int16Array)&&(e=e.slice(1))}return e}getAttributes(t){let e="";if("vertex"===t||"compute"===t){const t=this.getAttributesArray();let s=0;for(const i of t)e+=`layout( location = ${s++} ) in ${i.type} ${i.name};\n`}return e}getStructMembers(t){const e=[],s=t.getMemberTypes();for(let t=0;t0&&(s+="\n"),s+=`\t// flow -> ${n}\n\t`),s+=`${i.code}\n\t`,t===r&&"compute"!==e&&(s+="// result\n\t","vertex"===e?(s+="gl_Position = ",s+=`${i.result};`):"fragment"===e&&(t.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${i.result};`)))}const n=t[e];n.extensions=this.getExtensions(e),n.uniforms=this.getUniforms(e),n.attributes=this.getAttributes(e),n.varyings=this.getVaryings(e),n.vars=this.getVars(e),n.structs=this.getStructs(e),n.codes=this.getCodes(e),n.transforms=this.getTransforms(e),n.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(t.vertex),this.fragmentShader=this._getGLSLFragmentCode(t.fragment)):this.computeShader=this._getGLSLVertexCode(t.compute)}getUniformFromNode(t,e,s,i=null){const r=super.getUniformFromNode(t,e,s,i),n=this.getDataFromNode(t,s,this.globalCache);let o=n.uniformGPU;if(void 0===o){const i=t.groupNode,a=i.name,h=this.getBindGroupArray(a,s);if("texture"===e)o=new $B(r.name,r.node,i),h.push(o);else if("cubeTexture"===e)o=new XB(r.name,r.node,i),h.push(o);else if("texture3D"===e)o=new YB(r.name,r.node,i),h.push(o);else if("buffer"===e){t.name=`NodeBuffer_${t.id}`,r.name=`buffer${t.id}`;const e=new kB(t,i);e.name=t.name,h.push(e),o=e}else{const t=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=t[a];void 0===n&&(n=new jB(s+"_"+a,i),t[a]=n,h.push(n)),o=this.getNodeUniform(r,e),n.addUniform(o)}n.uniformGPU=o}return r}}let eI=null,sI=null,iI=null;class rI{constructor(t={}){this.parameters=Object.assign({},t),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(t){this.renderer=t}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(t){const{object:e,geometry:s}=t;return s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1}getDrawingBufferSize(){return eI=eI||new Ks,this.renderer.getDrawingBufferSize(eI)}getScissor(){return sI=sI||new _i,this.renderer.getScissor(sI)}setScissorTest(){}getClearColor(){const t=this.renderer;return iI=iI||new _B,t.getClearColor(iI),iI.getRGB(iI,this.renderer.currentColorSpace),iI}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:ni(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${t} webgpu`),this.domElement=e),e}set(t,e){this.data.set(t,e)}get(t){let e=this.data.get(t);return void 0===e&&(e={},this.data.set(t,e)),e}has(t){return this.data.has(t)}delete(t){this.data.delete(t)}}let nI=0;class oI{constructor(t,e){this.buffers=[t.bufferGPU,e],this.type=t.type,this.bufferType=t.bufferType,this.pbo=t.pbo,this.byteLength=t.byteLength,this.bytesPerElement=t.BYTES_PER_ELEMENT,this.version=t.version,this.isInteger=t.isInteger,this.activeBufferIndex=0,this.baseId=t.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class aI{constructor(t){this.backend=t}createAttribute(t,e){const s=this.backend,{gl:i}=s,r=t.array,n=t.usage||i.STATIC_DRAW,o=t.isInterleavedBufferAttribute?t.data:t,a=s.get(o);let h,u=a.bufferGPU;if(void 0===u&&(u=this._createBuffer(i,e,r,n),a.bufferGPU=u,a.bufferType=e,a.version=o.version),r instanceof Float32Array)h=i.FLOAT;else if(r instanceof Uint16Array)h=t.isFloat16BufferAttribute?i.HALF_FLOAT:i.UNSIGNED_SHORT;else if(r instanceof Int16Array)h=i.SHORT;else if(r instanceof Uint32Array)h=i.UNSIGNED_INT;else if(r instanceof Int32Array)h=i.INT;else if(r instanceof Int8Array)h=i.BYTE;else if(r instanceof Uint8Array)h=i.UNSIGNED_BYTE;else{if(!(r instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+r);h=i.UNSIGNED_BYTE}let l={bufferGPU:u,bufferType:e,type:h,byteLength:r.byteLength,bytesPerElement:r.BYTES_PER_ELEMENT,version:t.version,pbo:t.pbo,isInteger:h===i.INT||h===i.UNSIGNED_INT||h===i.UNSIGNED_SHORT||t.gpuType===Et,id:nI++};if(t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute){const t=this._createBuffer(i,e,r,n);l=new oI(l,t)}s.set(t,l)}updateAttribute(t){const e=this.backend,{gl:s}=e,i=t.array,r=t.isInterleavedBufferAttribute?t.data:t,n=e.get(r),o=n.bufferType,a=t.isInterleavedBufferAttribute?t.data.updateRanges:t.updateRanges;if(s.bindBuffer(o,n.bufferGPU),0===a.length)s.bufferSubData(o,0,i);else{for(let t=0,e=a.length;t{!function r(){const n=t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0);if(n===t.WAIT_FAILED)return t.deleteSync(e),void i();n!==t.TIMEOUT_EXPIRED?(t.deleteSync(e),s()):requestAnimationFrame(r)}()}))}}let pI,mI,gI,fI=!1;class yI{constructor(t){this.backend=t,this.gl=t.gl,this.extensions=t.extensions,this.defaultTextures={},!1===fI&&(this._init(this.gl),fI=!0)}_init(t){pI={[pt]:t.REPEAT,[mt]:t.CLAMP_TO_EDGE,[gt]:t.MIRRORED_REPEAT},mI={[ft]:t.NEAREST,[yt]:t.NEAREST_MIPMAP_NEAREST,[bt]:t.NEAREST_MIPMAP_LINEAR,[Tt]:t.LINEAR,[_t]:t.LINEAR_MIPMAP_NEAREST,[St]:t.LINEAR_MIPMAP_LINEAR},gI={512:t.NEVER,519:t.ALWAYS,[Ts]:t.LESS,515:t.LEQUAL,514:t.EQUAL,518:t.GEQUAL,516:t.GREATER,517:t.NOTEQUAL}}filterFallback(t){const{gl:e}=this;return t===ft||t===yt||t===bt?e.NEAREST:e.LINEAR}getGLTextureType(t){const{gl:e}=this;let s;return s=!0===t.isCubeTexture?e.TEXTURE_CUBE_MAP:!0===t.isDataArrayTexture?e.TEXTURE_2D_ARRAY:!0===t.isData3DTexture?e.TEXTURE_3D:e.TEXTURE_2D,s}getInternalFormat(t,e,s,i,r=!1){const{gl:n,extensions:o}=this;if(null!==t){if(void 0!==n[t])return n[t];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+t+"'")}let a=e;return e===n.RED&&(s===n.FLOAT&&(a=n.R32F),s===n.HALF_FLOAT&&(a=n.R16F),s===n.UNSIGNED_BYTE&&(a=n.R8),s===n.UNSIGNED_SHORT&&(a=n.R16),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),e===n.RED_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.R8UI),s===n.UNSIGNED_SHORT&&(a=n.R16UI),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),e===n.RG&&(s===n.FLOAT&&(a=n.RG32F),s===n.HALF_FLOAT&&(a=n.RG16F),s===n.UNSIGNED_BYTE&&(a=n.RG8),s===n.UNSIGNED_SHORT&&(a=n.RG16),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),e===n.RG_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RG8UI),s===n.UNSIGNED_SHORT&&(a=n.RG16UI),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),e===n.RGB&&(s===n.FLOAT&&(a=n.RGB32F),s===n.HALF_FLOAT&&(a=n.RGB16F),s===n.UNSIGNED_BYTE&&(a=n.RGB8),s===n.UNSIGNED_SHORT&&(a=n.RGB16),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I),s===n.UNSIGNED_BYTE&&(a=i===Je&&!1===r?n.SRGB8:n.RGB8),s===n.UNSIGNED_SHORT_5_6_5&&(a=n.RGB565),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGB4),s===n.UNSIGNED_INT_5_9_9_9_REV&&(a=n.RGB9_E5)),e===n.RGB_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGB8UI),s===n.UNSIGNED_SHORT&&(a=n.RGB16UI),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I)),e===n.RGBA&&(s===n.FLOAT&&(a=n.RGBA32F),s===n.HALF_FLOAT&&(a=n.RGBA16F),s===n.UNSIGNED_BYTE&&(a=n.RGBA8),s===n.UNSIGNED_SHORT&&(a=n.RGBA16),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I),s===n.UNSIGNED_BYTE&&(a=i===Je&&!1===r?n.SRGB8_ALPHA8:n.RGBA8),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGBA4),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1)),e===n.RGBA_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGBA8UI),s===n.UNSIGNED_SHORT&&(a=n.RGBA16UI),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I)),e===n.DEPTH_COMPONENT&&(s===n.UNSIGNED_INT&&(a=n.DEPTH24_STENCIL8),s===n.FLOAT&&(a=n.DEPTH_COMPONENT32F)),e===n.DEPTH_STENCIL&&s===n.UNSIGNED_INT_24_8&&(a=n.DEPTH24_STENCIL8),a!==n.R16F&&a!==n.R32F&&a!==n.RG16F&&a!==n.RG32F&&a!==n.RGBA16F&&a!==n.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(t,e){const{gl:s,extensions:i,backend:r}=this,{currentAnisotropy:n}=r.get(e);s.texParameteri(t,s.TEXTURE_WRAP_S,pI[e.wrapS]),s.texParameteri(t,s.TEXTURE_WRAP_T,pI[e.wrapT]),t!==s.TEXTURE_3D&&t!==s.TEXTURE_2D_ARRAY||s.texParameteri(t,s.TEXTURE_WRAP_R,pI[e.wrapR]),s.texParameteri(t,s.TEXTURE_MAG_FILTER,mI[e.magFilter]);const o=e.isVideoTexture||e.minFilter!==Tt?e.minFilter:St;if(s.texParameteri(t,s.TEXTURE_MIN_FILTER,mI[o]),e.compareFunction&&(s.texParameteri(t,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(t,s.TEXTURE_COMPARE_FUNC,gI[e.compareFunction])),!0===i.has("EXT_texture_filter_anisotropic")){if(e.magFilter===ft)return;if(e.minFilter!==bt&&e.minFilter!==St)return;if(e.type===It&&!1===i.has("OES_texture_float_linear"))return;if(e.anisotropy>1||n!==e.anisotropy){const n=i.get("EXT_texture_filter_anisotropic");s.texParameterf(t,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(e.anisotropy,r.getMaxAnisotropy())),r.get(e).currentAnisotropy=e.anisotropy}}}createDefaultTexture(t){const{gl:e,backend:s,defaultTextures:i}=this,r=this.getGLTextureType(t);let n=i[r];void 0===n&&(n=e.createTexture(),s.state.bindTexture(r,n),e.texParameteri(r,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(r,e.TEXTURE_MAG_FILTER,e.NEAREST),i[r]=n),s.set(t,{textureGPU:n,glTextureType:r,isDefault:!0})}createTexture(t,e){const{gl:s,backend:i}=this,{levels:r,width:n,height:o,depth:a}=e,h=i.utils.convert(t.format,t.colorSpace),u=i.utils.convert(t.type),l=this.getInternalFormat(t.internalFormat,h,u,t.colorSpace,t.isVideoTexture),c=s.createTexture(),d=this.getGLTextureType(t);i.state.bindTexture(d,c),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),this.setTextureParameters(d,t),t.isDataArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,r,l,n,o,a):t.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,r,l,n,o,a):t.isVideoTexture||s.texStorage2D(d,r,l,n,o),i.set(t,{textureGPU:c,glTextureType:d,glFormat:h,glType:u,glInternalFormat:l})}copyBufferToTexture(t,e){const{gl:s,backend:i}=this,{textureGPU:r,glTextureType:n,glFormat:o,glType:a}=i.get(e),{width:h,height:u}=e.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,t),i.state.bindTexture(n,r),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(n,0,0,0,h,u,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(t,e){const{gl:s}=this,{width:i,height:r}=e,{textureGPU:n,glTextureType:o,glFormat:a,glType:h,glInternalFormat:u}=this.backend.get(t);if(t.isRenderTargetTexture||void 0===n)return;const l=t=>t.isDataTexture?t.image.data:t instanceof ImageBitmap||t instanceof OffscreenCanvas||t instanceof HTMLImageElement||t instanceof HTMLCanvasElement?t:t.data;if(this.backend.state.bindTexture(o,n),t.isCompressedTexture){const i=t.mipmaps;for(let r=0;r0){let a,h;!0===t.isDepthTexture?(a=s.DEPTH_BUFFER_BIT,h=s.DEPTH_ATTACHMENT,e.stencil&&(a|=s.STENCIL_BUFFER_BIT)):(a=s.COLOR_BUFFER_BIT,h=s.COLOR_ATTACHMENT0);const u=s.createFramebuffer();i.bindFramebuffer(s.DRAW_FRAMEBUFFER,u),s.framebufferTexture2D(s.DRAW_FRAMEBUFFER,h,s.TEXTURE_2D,r,0),s.blitFramebuffer(0,0,n,o,0,0,n,o,a,s.NEAREST),s.deleteFramebuffer(u)}else i.bindTexture(s.TEXTURE_2D,r),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,0,0,n,o),i.unbindTexture();t.generateMipmaps&&this.generateMipmaps(t),this.backend._setFramebuffer(e)}setupRenderBufferStorage(t,e){const{gl:s}=this,i=e.renderTarget,{samples:r,depthTexture:n,depthBuffer:o,stencilBuffer:a,width:h,height:u}=i;if(s.bindRenderbuffer(s.RENDERBUFFER,t),o&&!a){let e=s.DEPTH_COMPONENT24;r>0?(n&&n.isDepthTexture&&n.type===s.FLOAT&&(e=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,r,e,h,u)):s.renderbufferStorage(s.RENDERBUFFER,e,h,u),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,t)}else o&&a&&(r>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,r,s.DEPTH24_STENCIL8,h,u):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,h,u),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,t))}async copyTextureToBuffer(t,e,s,i,r){const{backend:n,gl:o}=this,{textureGPU:a,glFormat:h,glType:u}=this.backend.get(t),l=o.createFramebuffer();o.bindFramebuffer(o.READ_FRAMEBUFFER,l),o.framebufferTexture2D(o.READ_FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,a,0);const c=this._getTypedArrayType(u),d=i*r*this._getBytesPerTexel(h),p=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,p),o.bufferData(o.PIXEL_PACK_BUFFER,d,o.STREAM_READ),o.readPixels(e,s,i,r,h,u,0),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),await n.utils._clientWaitAsync();const m=new c(d/c.BYTES_PER_ELEMENT);return o.bindBuffer(o.PIXEL_PACK_BUFFER,p),o.getBufferSubData(o.PIXEL_PACK_BUFFER,0,m),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),o.deleteFramebuffer(l),m}_getTypedArrayType(t){const{gl:e}=this;if(t===e.UNSIGNED_BYTE)return Uint8Array;if(t===e.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(t===e.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(t===e.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(t===e.UNSIGNED_SHORT)return Uint16Array;if(t===e.UNSIGNED_INT)return Uint32Array;if(t===e.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${t}`)}_getBytesPerTexel(t){const{gl:e}=this;return t===e.RGBA?4:t===e.RGB?3:t===e.ALPHA?1:void 0}}class xI{constructor(t){this.backend=t,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(t){let e=this.extensions[t];return void 0===e&&(e=this.gl.getExtension(t),this.extensions[t]=e),e}has(t){return this.availableExtensions.includes(t)}}class bI{constructor(t){this.backend=t,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const t=this.backend.gl,e=this.backend.extensions;if(!0===e.has("EXT_texture_filter_anisotropic")){const s=e.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=t.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const vI={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class TI{constructor(t){this.gl=t.gl,this.extensions=t.extensions,this.info=t.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(t,e){const{gl:s,mode:i,object:r,type:n,info:o,index:a}=this;0!==a?s.drawElements(i,e,n,t):s.drawArrays(i,t,e),o.update(r,e,i,1)}renderInstances(t,e,s){const{gl:i,mode:r,type:n,index:o,object:a,info:h}=this;0!==s&&(0!==o?i.drawElementsInstanced(r,e,n,t,s):i.drawArraysInstanced(r,t,e,s),h.update(a,e,r,s))}renderMultiDraw(t,e,s){const{extensions:i,mode:r,object:n,info:o}=this;if(0===s)return;const a=i.get("WEBGL_multi_draw");if(null===a)for(let i=0;i0)){const t=e.queryQueue.shift();this.initTimestampQuery(t)}}async resolveTimestampAsync(t,e="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(t);s.gpuQueries||(s.gpuQueries=[]);for(let t=0;t0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(i),s.occlusionQueryObjects=new Array(i),s.occlusionQueryIndex=0)}finishRender(t){const{gl:e,state:s}=this,i=this.get(t).previousContext,r=t.textures;if(null!==r)for(let t=0;t0){const r=i.msaaFrameBuffer,a=t.textures;s.bindFramebuffer(e.READ_FRAMEBUFFER,r),s.bindFramebuffer(e.DRAW_FRAMEBUFFER,n);for(let s=0;s0){if(n>this.get(t).occlusionQueryIndex){const{gl:t}=this;t.endQuery(t.ANY_SAMPLES_PASSED)}this.resolveOccludedAsync(t)}this.prepareTimestampBuffer(t)}resolveOccludedAsync(t){const e=this.get(t),{currentOcclusionQueries:s,currentOcclusionQueryObjects:i}=e;if(s&&i){const t=new WeakSet,{gl:r}=this;e.currentOcclusionQueryObjects=null,e.currentOcclusionQueries=null;const n=()=>{let o=0;for(let e=0;e0&&t.add(i[e]),s[e]=null,r.deleteQuery(n),o++))}o1?f.renderInstances(m,y,x):f.render(m,y),o.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(t){return t.id}createDefaultTexture(t){this.textureUtils.createDefaultTexture(t)}createTexture(t,e){this.textureUtils.createTexture(t,e)}updateTexture(t,e){this.textureUtils.updateTexture(t,e)}generateMipmaps(t){this.textureUtils.generateMipmaps(t)}destroyTexture(t){this.textureUtils.destroyTexture(t)}copyTextureToBuffer(t,e,s,i,r){return this.textureUtils.copyTextureToBuffer(t,e,s,i,r)}createSampler(){}destroySampler(){}createNodeBuilder(t,e){return new tI(t,e)}createProgram(t){const e=this.gl,{stage:s,code:i}=t,r="fragment"===s?e.createShader(e.FRAGMENT_SHADER):e.createShader(e.VERTEX_SHADER);e.shaderSource(r,i),e.compileShader(r),this.set(t,{shaderGPU:r})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(t,e){const s=this.gl,i=t.pipeline,{fragmentProgram:r,vertexProgram:n}=i,o=s.createProgram(),a=this.get(r).shaderGPU,h=this.get(n).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,h),s.linkProgram(o),this.set(i,{programGPU:o,fragmentShader:a,vertexShader:h}),null!==e&&this.parallel){const r=new Promise((e=>{const r=this.parallel,n=()=>{s.getProgramParameter(o,r.COMPLETION_STATUS_KHR)?(this._completeCompile(t,i),e()):requestAnimationFrame(n)};n()}));e.push(r)}else this._completeCompile(t,i)}_handleSource(t,e){const s=t.split("\n"),i=[],r=Math.max(e-6,0),n=Math.min(e+6,s.length);for(let t=r;t":" "} ${r}: ${s[t]}`)}return i.join("\n")}_getShaderErrors(t,e,s){const i=t.getShaderParameter(e,t.COMPILE_STATUS),r=t.getShaderInfoLog(e).trim();if(i&&""===r)return"";const n=/ERROR: 0:(\d+)/.exec(r);if(n){const i=parseInt(n[1]);return s.toUpperCase()+"\n\n"+r+"\n\n"+this._handleSource(t.getShaderSource(e),i)}return r}_logProgramError(t,e,s){if(this.renderer.debug.checkShaderErrors){const i=this.gl,r=i.getProgramInfoLog(t).trim();if(!1===i.getProgramParameter(t,i.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(i,t,s,e);else{const n=this._getShaderErrors(i,s,"vertex"),o=this._getShaderErrors(i,e,"fragment");console.error("THREE.WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(t,i.VALIDATE_STATUS)+"\n\nProgram Info Log: "+r+"\n"+n+"\n"+o)}else""!==r&&console.warn("THREE.WebGLProgram: Program Info Log:",r)}}_completeCompile(t,e){const s=this.gl,i=this.get(e),{programGPU:r,fragmentShader:n,vertexShader:o}=i;!1===s.getProgramParameter(r,s.LINK_STATUS)&&this._logProgramError(r,n,o),s.useProgram(r);const a=t.getBindings();this._setupBindings(a,r),this.set(e,{programGPU:r})}createComputePipeline(t,e){const s=this.gl,i={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(i);const{computeProgram:r}=t,n=s.createProgram(),o=this.get(i).shaderGPU,a=this.get(r).shaderGPU,h=r.transforms,u=[],l=[];for(let t=0;tvI[e]===t)),s=this.extensions;for(let t=0;t0){if(void 0===d){const i=[];d=e.createFramebuffer(),s.bindFramebuffer(e.FRAMEBUFFER,d);const r=[],u=t.textures;for(let s=0;s,\n\t@location( 0 ) vTex : vec2\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2, 4 >(\n\t\tvec2( -1.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 ),\n\t\tvec2( -1.0, -1.0 ),\n\t\tvec2( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2, 4 >(\n\t\tvec2( 0.0, 0.0 ),\n\t\tvec2( 1.0, 0.0 ),\n\t\tvec2( 0.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=t.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=t.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(t){let e=this.transferPipelines[t];return void 0===e&&(e=this.device.createRenderPipeline({vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:LS,stripIndexFormat:tM},layout:"auto"}),this.transferPipelines[t]=e),e}getFlipYPipeline(t){let e=this.flipYPipelines[t];return void 0===e&&(e=this.device.createRenderPipeline({vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:LS,stripIndexFormat:tM},layout:"auto"}),this.flipYPipelines[t]=e),e}flipY(t,e,s=0){const i=e.format,{width:r,height:n}=e.size,o=this.getTransferPipeline(i),a=this.getFlipYPipeline(i),h=this.device.createTexture({size:{width:r,height:n,depthOrArrayLayers:1},format:i,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),u=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:HM,baseArrayLayer:s}),l=h.createView({baseMipLevel:0,mipLevelCount:1,dimension:HM,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),d=(t,e,s)=>{const i=t.getBindGroupLayout(0),r=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:e}]}),n=c.beginRenderPass({colorAttachments:[{view:s,loadOp:XS,storeOp:qS,clearValue:[0,0,0,0]}]});n.setPipeline(t),n.setBindGroup(0,r),n.draw(4,1,0,0),n.end()};d(o,u,l),d(a,l,u),this.device.queue.submit([c.finish()]),h.destroy()}generateMipmaps(t,e,s=0){const i=this.getTransferPipeline(e.format),r=this.device.createCommandEncoder({}),n=i.getBindGroupLayout(0);let o=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:HM,baseArrayLayer:s});for(let a=1;a1&&!t.isMultisampleRenderTargetTexture){const t=Object.assign({},p);t.label=t.label+"-msaa",t.sampleCount=l,i.msaaTexture=s.device.createTexture(t)}i.initialized=!0,i.textureDescriptorGPU=p}destroyTexture(t){const e=this.backend,s=e.get(t);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),e.delete(t)}destroySampler(t){delete this.backend.get(t).sampler}generateMipmaps(t){const e=this.backend.get(t);if(t.isCubeTexture)for(let t=0;t<6;t++)this._generateMipmaps(e.texture,e.textureDescriptorGPU,t);else this._generateMipmaps(e.texture,e.textureDescriptorGPU)}getColorBuffer(){this.colorBuffer&&this.colorBuffer.destroy();const t=this.backend,{width:e,height:s}=t.getDrawingBufferSize();return this.colorBuffer=t.device.createTexture({label:"colorBuffer",size:{width:e,height:s,depthOrArrayLayers:1},sampleCount:t.utils.getSampleCount(t.renderer.samples),format:eM.BGRA8Unorm,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),this.colorBuffer}getDepthBuffer(t=!0,e=!1){const s=this.backend,{width:i,height:r}=s.getDrawingBufferSize(),n=this.depthTexture,o=s.get(n).texture;let a,h;if(e?(a=jt,h=Ot):t&&(a=Wt,h=Bt),void 0!==o){if(n.image.width===i&&n.image.height===r&&n.format===a&&n.type===h)return o;this.destroyTexture(n)}return n.name="depthBuffer",n.format=a,n.type=h,n.image.width=i,n.image.height=r,this.createTexture(n,{sampleCount:s.utils.getSampleCount(s.renderer.samples),width:i,height:r}),s.get(n).texture}updateTexture(t,e){const s=this.backend.get(t),{textureDescriptorGPU:i}=s;if(!t.isRenderTargetTexture&&void 0!==i){if(t.isDataTexture)this._copyBufferToTexture(e.image,s.texture,i,0,t.flipY);else if(t.isDataArrayTexture||t.isData3DTexture)for(let r=0;r]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,FI=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,UI={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_2d:"texture",texture_cube:"cubeTexture",texture_depth_2d:"depthTexture",texture_storage_2d:"storageTexture",texture_3d:"texture3D"};class OI extends QC{constructor(t){const{type:e,inputs:s,name:i,inputsCode:r,blockCode:n,outputType:o}=(t=>{const e=(t=t.trim()).match(PI);if(null!==e&&4===e.length){const s=e[2],i=[];let r=null;for(;null!==(r=FI.exec(s));)i.push({name:r[1],type:r[2]});const n=[];for(let t=0;t "+this.outputType:"";return`fn ${t} ( ${this.inputsCode.trim()} ) ${e}`+this.blockCode}}class LI extends ZC{parseFunction(t){return new OI(t)}}const zI=self.GPUShaderStage,VI={vertex:zI?zI.VERTEX:1,fragment:zI?zI.FRAGMENT:2,compute:zI?zI.COMPUTE:4},DI={instance:!0,swizzleAssign:!1,storageBuffer:!0},kI={"^^":"threejs_xor"},GI={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",imat2:"mat2x2",umat2:"mat2x2",bmat2:"mat2x2",mat3:"mat3x3",imat3:"mat3x3",umat3:"mat3x3",bmat3:"mat3x3",mat4:"mat4x4",imat4:"mat4x4",umat4:"mat4x4",bmat4:"mat4x4"},WI={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"threejs_mod_float",mod_vec2:"threejs_mod_vec2",mod_vec3:"threejs_mod_vec3",mod_vec4:"threejs_mod_vec4",equals_bool:"threejs_equals_bool",equals_bvec2:"threejs_equals_bvec2",equals_bvec3:"threejs_equals_bvec3",equals_bvec4:"threejs_equals_bvec4",lessThanEqual:"threejs_lessThanEqual",greaterThan:"threejs_greaterThan",inversesqrt:"inverseSqrt",bitcast:"bitcast"},jI={threejs_xor:new Hg("\nfn threejs_xor( a : bool, b : bool ) -> bool {\n\n\treturn ( a || b ) && !( a && b );\n\n}\n"),lessThanEqual:new Hg("\nfn threejs_lessThanEqual( a : vec3, b : vec3 ) -> vec3 {\n\n\treturn vec3( a.x <= b.x, a.y <= b.y, a.z <= b.z );\n\n}\n"),greaterThan:new Hg("\nfn threejs_greaterThan( a : vec3, b : vec3 ) -> vec3 {\n\n\treturn vec3( a.x > b.x, a.y > b.y, a.z > b.z );\n\n}\n"),mod_float:new Hg("fn threejs_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new Hg("fn threejs_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new Hg("fn threejs_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new Hg("fn threejs_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new Hg("fn threejs_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new Hg("fn threejs_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new Hg("fn threejs_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new Hg("fn threejs_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping:new Hg("\nfn threejs_repeatWrapping( uv : vec2, dimension : vec2 ) -> vec2 {\n\n\tlet uvScaled = vec2( uv * vec2( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new Hg("\nfn threejs_biquadraticTexture( map : texture_2d, coord : vec2f, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( textureDimensions( map, level ) );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2i( iuv + vec2( 0.5, 0.5 ) ), level );\n\tlet rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ), level );\n\tlet rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ), level );\n\tlet rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ), level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")};class HI extends I_{constructor(t,e){super(t,e,new LI),this.uniformGroups={},this.builtins={}}needsColorSpaceToLinear(t){return!0===t.isVideoTexture&&t.colorSpace!==Ye}_generateTextureSample(t,e,s,i,r=this.shaderStage){return"fragment"===r?i?`textureSample( ${e}, ${e}_sampler, ${s}, ${i} )`:`textureSample( ${e}, ${e}_sampler, ${s} )`:this.isFilteredTexture(t)?this.generateFilteredTexture(t,e,s):this.generateTextureLod(t,e,s,"0")}_generateVideoSample(t,e,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${t}, ${t}_sampler, vec2( ${e}.x, 1.0 - ${e}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(t,e,s,i,r,n=this.shaderStage){return"fragment"===n&&!1===this.isUnfilterable(t)?`textureSampleLevel( ${e}, ${e}_sampler, ${s}, ${i} )`:this.isFilteredTexture(t)?this.generateFilteredTexture(t,e,s,i):this.generateTextureLod(t,e,s,i)}generateFilteredTexture(t,e,s,i="0"){return this._include("biquadraticTexture"),`threejs_biquadraticTexture( ${e}, ${s}, i32( ${i} ) )`}generateTextureLod(t,e,s,i="0"){this._include("repeatWrapping");return`textureLoad( ${e}, threejs_repeatWrapping( ${s}, ${!0===t.isMultisampleRenderTargetTexture?`textureDimensions( ${e} )`:`textureDimensions( ${e}, 0 )`} ), i32( ${i} ) )`}generateTextureLoad(t,e,s,i,r="0u"){return i?`textureLoad( ${e}, ${s}, ${i}, ${r} )`:`textureLoad( ${e}, ${s}, ${r} )`}generateTextureStore(t,e,s,i){return`textureStore( ${e}, ${s}, ${i} )`}isUnfilterable(t){return"float"!==this.getComponentTypeFromTexture(t)||!0===t.isDataTexture&&t.type===It||!0===t.isMultisampleRenderTargetTexture}generateTexture(t,e,s,i,r=this.shaderStage){let n=null;return n=!0===t.isVideoTexture?this._generateVideoSample(e,s,r):this.isUnfilterable(t)?this.generateTextureLod(t,e,s,"0",i,r):this._generateTextureSample(t,e,s,i,r),n}generateTextureGrad(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleGrad( ${e}, ${e}_sampler, ${s}, ${i[0]}, ${i[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${n} shader.`)}generateTextureCompare(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleCompare( ${e}, ${e}_sampler, ${s}, ${i} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}generateTextureLevel(t,e,s,i,r,n=this.shaderStage){let o=null;return o=!0===t.isVideoTexture?this._generateVideoSample(e,s,n):this._generateTextureSampleLevel(t,e,s,i,r,n),o}generateTextureBias(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleBias( ${e}, ${e}_sampler, ${s}, ${i} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${n} shader.`)}getPropertyName(t,e=this.shaderStage){if(!0===t.isNodeVarying&&!0===t.needsInterpolation){if("vertex"===e)return`varyings.${t.name}`}else if(!0===t.isNodeUniform){const e=t.name,s=t.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?e:"buffer"===s||"storageBuffer"===s?`NodeBuffer_${t.id}.${e}`:t.groupNode.name+"."+e}return super.getPropertyName(t)}getOutputStructName(){return"output"}_getUniformGroupCount(t){return Object.keys(this.uniforms[t]).length}getFunctionOperator(t){const e=kI[t];return void 0!==e?(this._include(e),e):null}getStorageAccess(t){if(t.isStorageTextureNode)switch(t.access){case zM:return"read";case LM:return"write";default:return"read_write"}else switch(t.access){case UM:return"read_write";case OM:return"read";default:return"write"}}getUniformFromNode(t,e,s,i=null){const r=super.getUniformFromNode(t,e,s,i),n=this.getDataFromNode(t,s,this.globalCache);if(void 0===n.uniformGPU){let i;const o=t.groupNode,a=o.name,h=this.getBindGroupArray(a,s);if("texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e){let n=null;if("texture"===e||"storageTexture"===e?n=new $B(r.name,r.node,o,t.access?t.access:null):"cubeTexture"===e?n=new XB(r.name,r.node,o,t.access?t.access:null):"texture3D"===e&&(n=new YB(r.name,r.node,o,t.access?t.access:null)),n.store=!0===t.isStorageTextureNode,n.setVisibility(VI[s]),"fragment"===s&&!1===this.isUnfilterable(t.value)&&!1===n.store){const t=new SI(`${r.name}_sampler`,r.node,o);t.setVisibility(VI[s]),h.push(t,n),i=[t,n]}else h.push(n),i=[n]}else if("buffer"===e||"storageBuffer"===e){const r=new("storageBuffer"===e?NI:kB)(t,o);r.setVisibility(VI[s]),h.push(r),i=r}else{const t=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=t[a];void 0===n&&(n=new jB(a,o),n.setVisibility(VI[s]),t[a]=n,h.push(n)),i=this.getNodeUniform(r,e),n.addUniform(i)}n.uniformGPU=i}return r}getBuiltin(t,e,s,i=this.shaderStage){const r=this.builtins[i]||(this.builtins[i]=new Map);return!1===r.has(t)&&r.set(t,{name:t,property:e,type:s}),e}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(t){const e=t.layout,s=this.flowShaderNode(t),i=[];for(const t of e.inputs)i.push(t.name+" : "+this.getType(t.type));return`fn ${e.name}( ${i.join(", ")} ) -> ${this.getType(e.type)} {\n${s.vars}\n${s.code}\n\treturn ${s.result};\n\n}`}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xyz"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}isFlipY(){return!1}getBuiltins(t){const e=[],s=this.builtins[t];if(void 0!==s)for(const{name:t,property:i,type:r}of s.values())e.push(`@builtin( ${t} ) ${i} : ${r}`);return e.join(",\n\t")}getAttributes(t){const e=[];if("compute"===t&&this.getBuiltin("global_invocation_id","id","vec3","attribute"),"vertex"===t||"compute"===t){const t=this.getBuiltins("attribute");t&&e.push(t);const s=this.getAttributesArray();for(let t=0,i=s.length;t`)}const i=this.getBuiltins("output");return i&&e.push(i),e.join(",\n")}getStructs(t){const e=[],s=this.structs[t];for(let t=0,i=s.length;t output : ${r};\n\n`)}return e.join("\n\n")}getVar(t,e){return`var ${e} : ${this.getType(t)}`}getVars(t){const e=[],s=this.vars[t];if(void 0!==s)for(const t of s)e.push(`\t${this.getVar(t.type,t.name)};`);return`\n${e.join("\n")}\n`}getVaryings(t){const e=[];if("vertex"===t&&this.getBuiltin("position","Vertex","vec4","vertex"),"vertex"===t||"fragment"===t){const s=this.varyings,i=this.vars[t];for(let r=0;r";else if(!0===e.isDataArrayTexture)i="texture_2d_array";else if(!0===e.isDepthTexture)i=`texture_depth${n}_2d`;else if(!0===e.isVideoTexture)i="texture_external";else if(!0===e.isData3DTexture)i="texture_3d";else if(!0===r.node.isStorageTextureNode){i=`texture_storage_2d<${II(e)}, ${this.getStorageAccess(r.node)}>`}else{i=`texture${n}_2d<${this.getComponentTypeFromTexture(e).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${r.name} : ${i};`)}else if("buffer"===r.type||"storageBuffer"===r.type){const t=r.node,e=this.getType(t.bufferType),s=t.bufferCount,n=s>0?", "+s:"",a=`\t${r.name} : array< ${e}${n} >\n`,h=t.isStorageBufferNode?`storage, ${this.getStorageAccess(t)}`:"uniform";i.push(this._getWGSLStructBinding("NodeBuffer_"+t.id,a,h,o.binding++,o.group))}else{const t=this.getType(this.getVectorType(r.type)),e=r.groupNode.name;(n[e]||(n[e]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${r.name} : ${t}`)}}for(const t in n){const e=n[t];r.push(this._getWGSLStructBinding(t,e.snippets.join(",\n"),"uniform",e.index,e.id))}let o=s.join("\n");return o+=i.join("\n"),o+=r.join("\n"),o}buildCode(){const t=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};for(const e in t){const s=t[e];s.uniforms=this.getUniforms(e),s.attributes=this.getAttributes(e),s.varyings=this.getVaryings(e),s.structs=this.getStructs(e),s.vars=this.getVars(e),s.codes=this.getCodes(e);let i="// code\n\n";i+=this.flowCode[e];const r=this.flowNodes[e],n=r[r.length-1],o=n.outputNode,a=void 0!==o&&!0===o.isOutputStructNode;for(const t of r){const r=this.getFlowData(t),h=t.name;if(h&&(i.length>0&&(i+="\n"),i+=`\t// flow -> ${h}\n\t`),i+=`${r.code}\n\t`,t===n&&"compute"!==e)if(i+="// result\n\n\t","vertex"===e)i+=`varyings.Vertex = ${r.result};`;else if("fragment"===e)if(a)s.returnType=o.nodeType,i+=`return ${r.result};`;else{let t="\t@location(0) color: vec4";const e=this.getBuiltins("output");e&&(t+=",\n\t"+e),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",t),s.structs+="\nvar output : OutputStruct;\n\n",i+=`output.color = ${r.result};\n\n\treturn output;`}}s.flow=i}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(t.vertex),this.fragmentShader=this._getWGSLFragmentCode(t.fragment)):this.computeShader=this._getWGSLComputeCode(t.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(t,e=null){let s;return null!==e&&(s=this._getWGSLMethod(t+"_"+e)),void 0===s&&(s=this._getWGSLMethod(t)),s||t}getType(t){return GI[t]||t}isAvailable(t){let e=DI[t];return void 0===e&&("float32Filterable"===t&&(e=this.renderer.hasFeature("float32-filterable")),DI[t]=e),e}_getWGSLMethod(t){return void 0!==jI[t]&&this._include(t),WI[t]}_include(t){const e=jI[t];return e.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(e),e}_getWGSLVertexCode(t){return`${this.getSignature()}\n\n// uniforms\n${t.uniforms}\n\n// varyings\n${t.varyings}\nvar varyings : VaryingsStruct;\n\n// codes\n${t.codes}\n\n@vertex\nfn main( ${t.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(t){return`${this.getSignature()}\n\n// uniforms\n${t.uniforms}\n\n// structs\n${t.structs}\n\n// codes\n${t.codes}\n\n@fragment\nfn main( ${t.varyings} ) -> ${t.returnType} {\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n}\n`}_getWGSLComputeCode(t,e){return`${this.getSignature()}\n// system\nvar instanceIndex : u32;\n\n// uniforms\n${t.uniforms}\n\n// codes\n${t.codes}\n\n@compute @workgroup_size( ${e} )\nfn main( ${t.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x;\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n}\n`}_getWGSLStruct(t,e){return`\nstruct ${t} {\n${e}\n};`}_getWGSLStructBinding(t,e,s,i=0,r=0){const n=t+"Struct";return`${this._getWGSLStruct(n,e)}\n@binding( ${i} ) @group( ${r} )\nvar<${s}> ${t} : ${n};`}}class qI{constructor(t){this.backend=t}getCurrentDepthStencilFormat(t){let e;return null!==t.depthTexture?e=this.getTextureFormatGPU(t.depthTexture):t.depth&&t.stencil?e=eM.Depth24PlusStencil8:t.depth&&(e=eM.Depth24Plus),e}getTextureFormatGPU(t){return this.backend.get(t).texture.format}getCurrentColorFormat(t){let e;return e=null!==t.textures?this.getTextureFormatGPU(t.textures[0]):eM.BGRA8Unorm,e}getCurrentColorSpace(t){return null!==t.textures?t.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(t,e){return t.isPoints?PS:t.isLineSegments||t.isMesh&&!0===e.wireframe?FS:t.isLine?US:t.isMesh?OS:void 0}getSampleCount(t){let e=1;return t>1&&(e=Math.pow(2,Math.floor(Math.log2(t))),2===e&&(e=4)),e}getSampleCountRenderContext(t){return null!==t.textures?this.getSampleCount(t.sampleCount):this.getSampleCount(this.backend.renderer.samples)}}const $I=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),XI=new Map([[fn,["float16"]]]),YI=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class JI{constructor(t){this.backend=t}createAttribute(t,e){const s=this._getBufferAttribute(t),i=this.backend,r=i.get(s);let n=r.buffer;if(void 0===n){const o=i.device;let a=s.array;if(!1===t.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const t=new Uint32Array(a.length);for(let e=0;e{u.createRenderPipelineAsync(M).then((e=>{c.pipeline=e,t()}))}));e.push(t)}}createBundleEncoder(t,e){const s=this.backend,{utils:i,device:r}=s,n=s.get(t),o=s.get(e),a=i.getCurrentDepthStencilFormat(t),h={label:"renderBundleEncoder",colorFormats:[i.getCurrentColorFormat(t)],depthStencilFormat:a,sampleCount:this._getSampleCount(e.context)},u=r.createRenderBundleEncoder(h);return o.bundleEncoder=u,n.currentSets={attributes:{}},n._renderBundleViewport=t.width+"_"+t.height,u}createComputePipeline(t,e){const s=this.backend,i=s.device,r=s.get(t.computeProgram).module,n=s.get(t),o=[];for(const t of e){const e=s.get(t);o.push(e.layout)}n.pipeline=i.createComputePipeline({compute:r,layout:i.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(t){let e,s;const i=t.blending,r=t.blendSrc,n=t.blendDst,o=t.blendEquation;if(5===i){const i=null!==t.blendSrcAlpha?t.blendSrcAlpha:r,a=null!==t.blendDstAlpha?t.blendDstAlpha:n,h=null!==t.blendEquationAlpha?t.blendEquationAlpha:o;e={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(n),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(h)}}else{const r=(t,i,r,n)=>{e={srcFactor:t,dstFactor:i,operation:vM},s={srcFactor:r,dstFactor:n,operation:vM}};if(t.premultipliedAlpha)switch(i){case 1:r(cM,dM,hM,dM);break;case 2:r(cM,hM,hM,hM);break;case 3:r(aM,lM,aM,hM);break;case 4:r(aM,uM,aM,cM)}else switch(i){case 1:r(cM,dM,hM,dM);break;case 2:r(cM,hM,cM,hM);break;case 3:r(aM,lM,aM,hM);break;case 4:r(aM,uM,aM,uM)}}if(void 0!==e&&void 0!==s)return{color:e,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(t){let e;switch(t){case 200:e=aM;break;case 201:e=hM;break;case 202:e=uM;break;case 203:e=lM;break;case C:e=cM;break;case E:e=dM;break;case 208:e=pM;break;case 209:e=mM;break;case 206:e=gM;break;case 207:e=fM;break;case 210:e=yM;break;case 211:e=xM;break;case 212:e=bM;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",t)}return e}_getStencilCompare(t){let e;const s=t.stencilFunc;switch(s){case 512:e=zS;break;case bs:e=HS;break;case 513:e=VS;break;case 515:e=kS;break;case 514:e=DS;break;case 518:e=jS;break;case 516:e=GS;break;case 517:e=WS;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return e}_getStencilOperation(t){let e;switch(t){case ns:e=NM;break;case 0:e=RM;break;case 7681:e=CM;break;case 5386:e=EM;break;case 7682:e=BM;break;case 7683:e=IM;break;case 34055:e=PM;break;case 34056:e=FM;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",e)}return e}_getBlendOperation(t){let e;switch(t){case v:e=vM;break;case 101:e=TM;break;case 102:e=_M;break;case 103:e=wM;break;case 104:e=SM;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",t)}return e}_getPrimitiveState(t,e,s){const i={},r=this.backend.utils;switch(i.topology=r.getPrimitiveTopology(t,s),null!==e.index&&!0===t.isLine&&!0!==t.isLineSegments&&(i.stripIndexFormat=e.index.array instanceof Uint16Array?KS:tM),s.side){case c:i.frontFace=YS,i.cullMode=QS;break;case d:i.frontFace=YS,i.cullMode=ZS;break;case 2:i.frontFace=YS,i.cullMode=JS;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return i}_getColorWriteMask(t){return!0===t.colorWrite?AM:MM}_getDepthCompare(t){let e;if(!1===t.depthTest)e=HS;else{const s=t.depthFunc;switch(s){case 0:e=zS;break;case 1:e=HS;break;case 2:e=VS;break;case 3:e=kS;break;case 4:e=DS;break;case 5:e=jS;break;case 6:e=GS;break;case 7:e=WS;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return e}}class KI extends rI{constructor(t={}){super(t),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===t.alpha||t.alpha,this.parameters.requiredLimits=void 0===t.requiredLimits?{}:t.requiredLimits,this.trackTimestamp=!0===t.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new qI(this),this.attributeUtils=new JI(this),this.bindingUtils=new ZI(this),this.pipelineUtils=new QI(this),this.textureUtils=new BI(this),this.occludedResolveCache=new Map}async init(t){await super.init(t);const e=this.parameters;let s;if(void 0===e.device){const t={powerPreference:e.powerPreference},i=await navigator.gpu.requestAdapter(t);if(null===i)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const r=Object.values(QM),n=[];for(const t of r)i.features.has(t)&&n.push(t);const o={requiredFeatures:n,requiredLimits:e.requiredLimits};s=await i.requestDevice(o)}else s=e.device;const i=void 0!==e.context?e.context:t.domElement.getContext("webgpu");this.device=s,this.context=i;const r=e.alpha?"premultiplied":"opaque";this.context.configure({device:this.device,format:eM.BGRA8Unorm,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:r}),this.updateSize()}get coordinateSystem(){return Ds}async getArrayBufferAsync(t){return await this.attributeUtils.getArrayBufferAsync(t)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let t=this.defaultRenderPassdescriptor;if(null===t){const e=this.renderer;t={colorAttachments:[{view:null}],depthStencilAttachment:{view:this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView()}};const s=t.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=t}const e=t.colorAttachments[0];return this.renderer.samples>0?e.resolveTarget=this.context.getCurrentTexture().createView():e.view=this.context.getCurrentTexture().createView(),t}_getRenderPassDescriptor(t){const e=t.renderTarget,s=this.get(e);let i=s.descriptors;void 0===i&&(i=[],s.descriptors=i),s.width===e.width&&s.height===e.height&&s.activeMipmapLevel===e.activeMipmapLevel&&s.samples===e.samples||(i.length=0);let r=i[t.activeCubeFace];if(void 0===r){const n=t.textures,o=[];for(let e=0;e0&&(e.currentOcclusionQuerySet&&e.currentOcclusionQuerySet.destroy(),e.currentOcclusionQueryBuffer&&e.currentOcclusionQueryBuffer.destroy(),e.currentOcclusionQuerySet=e.occlusionQuerySet,e.currentOcclusionQueryBuffer=e.occlusionQueryBuffer,e.currentOcclusionQueryObjects=e.occlusionQueryObjects,r=s.createQuerySet({type:"occlusion",count:i}),e.occlusionQuerySet=r,e.occlusionQueryIndex=0,e.occlusionQueryObjects=new Array(i),e.lastOcclusionObject=null),n=null===t.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(t),this.initTimestampQuery(t,n),n.occlusionQuerySet=r;const o=n.depthStencilAttachment;if(null!==t.textures){const e=n.colorAttachments;for(let s=0;s0&&(e.registerBundlesPhase=!1,e.currentPass.executeBundles(e.renderBundles)),s>e.occlusionQueryIndex&&e.currentPass.endOcclusionQuery(),e.currentPass.end(),s>0){const i=8*s;let r=this.occludedResolveCache.get(i);void 0===r&&(r=this.device.createBuffer({size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(i,r));const n=this.device.createBuffer({size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});e.encoder.resolveQuerySet(e.occlusionQuerySet,0,s,r,0),e.encoder.copyBufferToBuffer(r,0,n,0,i),e.occlusionQueryBuffer=n,this.resolveOccludedAsync(t)}if(this.prepareTimestampBuffer(t,e.encoder),this.device.queue.submit([e.encoder.finish()]),null!==t.textures){const e=t.textures;for(let t=0;t1?0:s;g.drawIndexed(e[s]/n,i,t[s]/4,0,o)}}else if(!0===y){const t=b.count!==1/0?b.count:f.count;g.drawIndexed(t,T,v,0,0),e.update(s,t,T)}else{const t=i.attributes.position,r=b.count!==1/0?b.count:t.count;g.draw(r,T,v,0),e.update(s,r,T)}if(this.renderer._currentRenderBundle){const t=g.finish();l.lastPipelineGPU=h,l.renderBundle=t,l.bundleEncoder=g}}}needsRenderUpdate(t){const e=this.get(t),{object:s,material:i}=t,r=this.utils,n=r.getSampleCountRenderContext(t.context),o=r.getCurrentColorSpace(t.context),a=r.getCurrentColorFormat(t.context),h=r.getCurrentDepthStencilFormat(t.context),u=r.getPrimitiveTopology(s,i);let l=!1;return e.material===i&&e.materialVersion===i.version&&e.transparent===i.transparent&&e.blending===i.blending&&e.premultipliedAlpha===i.premultipliedAlpha&&e.blendSrc===i.blendSrc&&e.blendDst===i.blendDst&&e.blendEquation===i.blendEquation&&e.blendSrcAlpha===i.blendSrcAlpha&&e.blendDstAlpha===i.blendDstAlpha&&e.blendEquationAlpha===i.blendEquationAlpha&&e.colorWrite===i.colorWrite&&e.depthWrite===i.depthWrite&&e.depthTest===i.depthTest&&e.depthFunc===i.depthFunc&&e.stencilWrite===i.stencilWrite&&e.stencilFunc===i.stencilFunc&&e.stencilFail===i.stencilFail&&e.stencilZFail===i.stencilZFail&&e.stencilZPass===i.stencilZPass&&e.stencilFuncMask===i.stencilFuncMask&&e.stencilWriteMask===i.stencilWriteMask&&e.side===i.side&&e.alphaToCoverage===i.alphaToCoverage&&e.sampleCount===n&&e.colorSpace===o&&e.colorFormat===a&&e.depthStencilFormat===h&&e.primitiveTopology===u&&e.clippingContextVersion===t.clippingContextVersion||(e.material=i,e.materialVersion=i.version,e.transparent=i.transparent,e.blending=i.blending,e.premultipliedAlpha=i.premultipliedAlpha,e.blendSrc=i.blendSrc,e.blendDst=i.blendDst,e.blendEquation=i.blendEquation,e.blendSrcAlpha=i.blendSrcAlpha,e.blendDstAlpha=i.blendDstAlpha,e.blendEquationAlpha=i.blendEquationAlpha,e.colorWrite=i.colorWrite,e.depthWrite=i.depthWrite,e.depthTest=i.depthTest,e.depthFunc=i.depthFunc,e.stencilWrite=i.stencilWrite,e.stencilFunc=i.stencilFunc,e.stencilFail=i.stencilFail,e.stencilZFail=i.stencilZFail,e.stencilZPass=i.stencilZPass,e.stencilFuncMask=i.stencilFuncMask,e.stencilWriteMask=i.stencilWriteMask,e.side=i.side,e.alphaToCoverage=i.alphaToCoverage,e.sampleCount=n,e.colorSpace=o,e.colorFormat=a,e.depthStencilFormat=h,e.primitiveTopology=u,e.clippingContextVersion=t.clippingContextVersion,l=!0),l}getRenderCacheKey(t){const{object:e,material:s}=t,i=this.utils,r=t.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,i.getSampleCountRenderContext(r),i.getCurrentColorSpace(r),i.getCurrentColorFormat(r),i.getCurrentDepthStencilFormat(r),i.getPrimitiveTopology(e,s),t.clippingContextVersion].join()}createSampler(t){this.textureUtils.createSampler(t)}destroySampler(t){this.textureUtils.destroySampler(t)}createDefaultTexture(t){this.textureUtils.createDefaultTexture(t)}createTexture(t,e){this.textureUtils.createTexture(t,e)}updateTexture(t,e){this.textureUtils.updateTexture(t,e)}generateMipmaps(t){this.textureUtils.generateMipmaps(t)}destroyTexture(t){this.textureUtils.destroyTexture(t)}copyTextureToBuffer(t,e,s,i,r){return this.textureUtils.copyTextureToBuffer(t,e,s,i,r)}initTimestampQuery(t,e){if(!this.hasFeature(QM.TimestampQuery)||!this.trackTimestamp)return;const s=this.get(t);if(!s.timeStampQuerySet){const t=this.device.createQuerySet({type:"timestamp",count:2}),i={querySet:t,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(e,{timestampWrites:i}),s.timeStampQuerySet=t}}prepareTimestampBuffer(t,e){if(!this.hasFeature(QM.TimestampQuery)||!this.trackTimestamp)return;const s=this.get(t),i=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:r,resultBuffer:n,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(e.resolveQuerySet(s.timeStampQuerySet,0,2,r,0),e.copyBufferToBuffer(r,0,n,0,i))}async resolveTimestampAsync(t,e="render"){if(!this.hasFeature(QM.TimestampQuery)||!this.trackTimestamp)return;const s=this.get(t);if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:i,isMappingPending:r}=s.currentTimestampQueryBuffers;!0!==r&&(s.currentTimestampQueryBuffers.isMappingPending=!0,i.mapAsync(GPUMapMode.READ).then((()=>{const t=new BigUint64Array(i.getMappedRange()),r=Number(t[1]-t[0])/1e6;this.renderer.info.updateTimestamp(e,r),i.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(t,e){return new HI(t,e)}createProgram(t){this.get(t).module={module:this.device.createShaderModule({code:t.code,label:t.stage}),entryPoint:"main"}}destroyProgram(t){this.delete(t)}createRenderPipeline(t,e){this.pipelineUtils.createRenderPipeline(t,e)}createComputePipeline(t,e){this.pipelineUtils.createComputePipeline(t,e)}createBundleEncoder(t,e){return this.pipelineUtils.createBundleEncoder(t,e)}createBindings(t){this.bindingUtils.createBindings(t)}updateBindings(t){this.bindingUtils.createBindings(t)}updateBinding(t){this.bindingUtils.updateBinding(t)}createIndexAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(t){this.attributeUtils.updateAttribute(t)}destroyAttribute(t){this.attributeUtils.destroyAttribute(t)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(t){return this.device.features.has(t)}copyTextureToTexture(t,e,s=null,i=null,r=0){let n=0,o=0,a=0,h=0,u=t.image.width,l=t.image.height;null!==s&&(a=s.x,h=s.y,u=s.width,l=s.height),null!==i&&(n=i.x,o=i.y);const c=this.device.createCommandEncoder({label:"copyTextureToTexture_"+t.id+"_"+e.id}),d=this.get(t).texture,p=this.get(e).texture;c.copyTextureToTexture({texture:d,mipLevel:r,origin:{x:a,y:h,z:0}},{texture:p,mipLevel:r,origin:{x:n,y:o,z:0}},[u,l]),this.device.queue.submit([c.finish()])}copyFramebufferToTexture(t,e){const s=this.get(e),{encoder:i,descriptor:r}=s;let n=null;n=e.renderTarget?t.isDepthTexture?this.get(e.depthTexture).texture:this.get(e.textures[0]).texture:t.isDepthTexture?this.textureUtils.getDepthBuffer(e.depth,e.stencil):this.context.getCurrentTexture();const o=this.get(t).texture;if(n.format===o.format){s.currentPass.end(),i.copyTextureToTexture({texture:n,origin:{x:0,y:0,z:0}},{texture:o},[t.image.width,t.image.height]),t.generateMipmaps&&this.textureUtils.generateMipmaps(t);for(let t=0;t>8&255]+Gs[t>>16&255]+Gs[t>>24&255]+"-"+Gs[255&e]+Gs[e>>8&255]+"-"+Gs[e>>16&15|64]+Gs[e>>24&255]+"-"+Gs[63&s|128]+Gs[s>>8&255]+"-"+Gs[s>>16&255]+Gs[s>>24&255]+Gs[255&i]+Gs[i>>8&255]+Gs[i>>16&255]+Gs[i>>24&255]).toLowerCase()}function $s(t,e,s){return Math.max(e,Math.min(s,t))}function Xs(t,e){return(t%e+e)%e}function Ys(t,e,s){return(1-s)*t+s*e}function Js(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function Zs(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(4294967295*t);case Uint16Array:return Math.round(65535*t);case Uint8Array:return Math.round(255*t);case Int32Array:return Math.round(2147483647*t);case Int16Array:return Math.round(32767*t);case Int8Array:return Math.round(127*t);default:throw new Error("Invalid component type.")}}const Qs={DEG2RAD:js,RAD2DEG:Hs,generateUUID:qs,clamp:$s,euclideanModulo:Xs,mapLinear:function(t,e,s,i,r){return i+(t-e)*(r-i)/(s-e)},inverseLerp:function(t,e,s){return t!==e?(s-t)/(e-t):0},lerp:Ys,damp:function(t,e,s,i){return Ys(t,e,1-Math.exp(-s*i))},pingpong:function(t,e=1){return e-Math.abs(Xs(t,2*e)-e)},smoothstep:function(t,e,s){return t<=e?0:t>=s?1:(t=(t-e)/(s-e))*t*(3-2*t)},smootherstep:function(t,e,s){return t<=e?0:t>=s?1:(t=(t-e)/(s-e))*t*t*(t*(6*t-15)+10)},randInt:function(t,e){return t+Math.floor(Math.random()*(e-t+1))},randFloat:function(t,e){return t+Math.random()*(e-t)},randFloatSpread:function(t){return t*(.5-Math.random())},seededRandom:function(t){void 0!==t&&(Ws=t);let e=Ws+=1831565813;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296},degToRad:function(t){return t*js},radToDeg:function(t){return t*Hs},isPowerOfTwo:function(t){return 0==(t&t-1)&&0!==t},ceilPowerOfTwo:function(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))},floorPowerOfTwo:function(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))},setQuaternionFromProperEuler:function(t,e,s,i,r){const n=Math.cos,o=Math.sin,a=n(s/2),h=o(s/2),u=n((e+i)/2),l=o((e+i)/2),c=n((e-i)/2),d=o((e-i)/2),p=n((i-e)/2),m=o((i-e)/2);switch(r){case"XYX":t.set(a*l,h*c,h*d,a*u);break;case"YZY":t.set(h*d,a*l,h*c,a*u);break;case"ZXZ":t.set(h*c,h*d,a*l,a*u);break;case"XZX":t.set(a*l,h*m,h*p,a*u);break;case"YXY":t.set(h*p,a*l,h*m,a*u);break;case"ZYZ":t.set(h*m,h*p,a*l,a*u);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:Zs,denormalize:Js};class Ks{constructor(t=0,e=0){Ks.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,s=this.y,i=t.elements;return this.x=i[0]*e+i[3]*s+i[6],this.y=i[1]*e+i[4]*s+i[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos($s(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y;return e*e+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const s=Math.cos(e),i=Math.sin(e),r=this.x-t.x,n=this.y-t.y;return this.x=r*s-n*i+t.x,this.y=r*i+n*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class ti{constructor(t,e,s,i,r,n,o,a,h){ti.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h)}set(t,e,s,i,r,n,o,a,h){const u=this.elements;return u[0]=t,u[1]=i,u[2]=o,u[3]=e,u[4]=r,u[5]=a,u[6]=s,u[7]=n,u[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],this}extractBasis(t,e,s){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),s.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[3],a=s[6],h=s[1],u=s[4],l=s[7],c=s[2],d=s[5],p=s[8],m=i[0],g=i[3],f=i[6],y=i[1],x=i[4],b=i[7],v=i[2],T=i[5],_=i[8];return r[0]=n*m+o*y+a*v,r[3]=n*g+o*x+a*T,r[6]=n*f+o*b+a*_,r[1]=h*m+u*y+l*v,r[4]=h*g+u*x+l*T,r[7]=h*f+u*b+l*_,r[2]=c*m+d*y+p*v,r[5]=c*g+d*x+p*T,r[8]=c*f+d*b+p*_,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8];return e*n*u-e*o*h-s*r*u+s*o*a+i*r*h-i*n*a}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8],l=u*n-o*h,c=o*a-u*r,d=h*r-n*a,p=e*l+s*c+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const m=1/p;return t[0]=l*m,t[1]=(i*h-u*s)*m,t[2]=(o*s-i*n)*m,t[3]=c*m,t[4]=(u*e-i*a)*m,t[5]=(i*r-o*e)*m,t[6]=d*m,t[7]=(s*a-h*e)*m,t[8]=(n*e-s*r)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,s,i,r,n,o){const a=Math.cos(r),h=Math.sin(r);return this.set(s*a,s*h,-s*(a*n+h*o)+n+t,-i*h,i*a,-i*(-h*n+a*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(ei.makeScale(t,e)),this}rotate(t){return this.premultiply(ei.makeRotation(-t)),this}translate(t,e){return this.premultiply(ei.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,s,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<9;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<9;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const ei=new ti;const si={Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array};function ii(t,e){return new si[t](e)}function ri(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function ni(){const t=ri("canvas");return t.style.display="block",t}const oi={};function ai(t){t in oi||(oi[t]=!0,console.warn(t))}const hi=(new ti).set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),ui=(new ti).set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),li={[Ze]:{transfer:ts,primaries:ss,toReference:t=>t,fromReference:t=>t},[Je]:{transfer:es,primaries:ss,toReference:t=>t.convertSRGBToLinear(),fromReference:t=>t.convertLinearToSRGB()},[Ke]:{transfer:ts,primaries:is,toReference:t=>t.applyMatrix3(ui),fromReference:t=>t.applyMatrix3(hi)},[Qe]:{transfer:es,primaries:is,toReference:t=>t.convertSRGBToLinear().applyMatrix3(ui),fromReference:t=>t.applyMatrix3(hi).convertLinearToSRGB()}},ci=new Set([Ze,Ke]),di={enabled:!0,_workingColorSpace:Ze,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(t){if(!ci.has(t))throw new Error(`Unsupported working color space, "${t}".`);this._workingColorSpace=t},convert:function(t,e,s){if(!1===this.enabled||e===s||!e||!s)return t;const i=li[e].toReference;return(0,li[s].fromReference)(i(t))},fromWorkingColorSpace:function(t,e){return this.convert(t,this._workingColorSpace,e)},toWorkingColorSpace:function(t,e){return this.convert(t,e,this._workingColorSpace)},getPrimaries:function(t){return li[t].primaries},getTransfer:function(t){return t===Ye?ts:li[t].transfer}};function pi(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function mi(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let gi;class fi{static getDataURL(t){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{void 0===gi&&(gi=ri("canvas")),gi.width=t.width,gi.height=t.height;const s=gi.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),e=gi}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const e=ri("canvas");e.width=t.width,e.height=t.height;const s=e.getContext("2d");s.drawImage(t,0,0,t.width,t.height);const i=s.getImageData(0,0,t.width,t.height),r=i.data;for(let t=0;t0&&(s.userData=this.userData),e||(t.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==at)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case pt:t.x=t.x-Math.floor(t.x);break;case mt:t.x=t.x<0?0:1;break;case gt:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case pt:t.y=t.y-Math.floor(t.y);break;case mt:t.y=t.y<0?0:1;break;case gt:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){!0===t&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){!0===t&&this.pmremVersion++}}Ti.DEFAULT_IMAGE=null,Ti.DEFAULT_MAPPING=at,Ti.DEFAULT_ANISOTROPY=1;class _i{constructor(t=0,e=0,s=0,i=1){_i.prototype.isVector4=!0,this.x=t,this.y=e,this.z=s,this.w=i}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,s,i){return this.x=t,this.y=e,this.z=s,this.w=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=void 0!==t.w?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=this.w,n=t.elements;return this.x=n[0]*e+n[4]*s+n[8]*i+n[12]*r,this.y=n[1]*e+n[5]*s+n[9]*i+n[13]*r,this.z=n[2]*e+n[6]*s+n[10]*i+n[14]*r,this.w=n[3]*e+n[7]*s+n[11]*i+n[15]*r,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,s,i,r;const n=.01,o=.1,a=t.elements,h=a[0],u=a[4],l=a[8],c=a[1],d=a[5],p=a[9],m=a[2],g=a[6],f=a[10];if(Math.abs(u-c)a&&t>y?ty?a=0?1:-1,i=1-e*e;if(i>Number.EPSILON){const r=Math.sqrt(i),n=Math.atan2(r,e*s);t=Math.sin(t*n)/r,o=Math.sin(o*n)/r}const r=o*s;if(a=a*t+c*r,h=h*t+d*r,u=u*t+p*r,l=l*t+m*r,t===1-o){const t=1/Math.sqrt(a*a+h*h+u*u+l*l);a*=t,h*=t,u*=t,l*=t}}t[e]=a,t[e+1]=h,t[e+2]=u,t[e+3]=l}static multiplyQuaternionsFlat(t,e,s,i,r,n){const o=s[i],a=s[i+1],h=s[i+2],u=s[i+3],l=r[n],c=r[n+1],d=r[n+2],p=r[n+3];return t[e]=o*p+u*l+a*d-h*c,t[e+1]=a*p+u*c+h*l-o*d,t[e+2]=h*p+u*d+o*c-a*l,t[e+3]=u*p-o*l-a*c-h*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,s,i){return this._x=t,this._y=e,this._z=s,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const s=t._x,i=t._y,r=t._z,n=t._order,o=Math.cos,a=Math.sin,h=o(s/2),u=o(i/2),l=o(r/2),c=a(s/2),d=a(i/2),p=a(r/2);switch(n){case"XYZ":this._x=c*u*l+h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l-c*d*p;break;case"YXZ":this._x=c*u*l+h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l+c*d*p;break;case"ZXY":this._x=c*u*l-h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l-c*d*p;break;case"ZYX":this._x=c*u*l-h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l+c*d*p;break;case"YZX":this._x=c*u*l+h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l-c*d*p;break;case"XZY":this._x=c*u*l-h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l+c*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,i=Math.sin(s);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],i=e[4],r=e[8],n=e[1],o=e[5],a=e[9],h=e[2],u=e[6],l=e[10],c=s+o+l;if(c>0){const t=.5/Math.sqrt(c+1);this._w=.25/t,this._x=(u-a)*t,this._y=(r-h)*t,this._z=(n-i)*t}else if(s>o&&s>l){const t=2*Math.sqrt(1+s-o-l);this._w=(u-a)/t,this._x=.25*t,this._y=(i+n)/t,this._z=(r+h)/t}else if(o>l){const t=2*Math.sqrt(1+o-s-l);this._w=(r-h)/t,this._x=(i+n)/t,this._y=.25*t,this._z=(a+u)/t}else{const t=2*Math.sqrt(1+l-s-o);this._w=(n-i)/t,this._x=(r+h)/t,this._y=(a+u)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return sMath.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs($s(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(0===s)return this;const i=Math.min(1,e/s);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const s=t._x,i=t._y,r=t._z,n=t._w,o=e._x,a=e._y,h=e._z,u=e._w;return this._x=s*u+n*o+i*h-r*a,this._y=i*u+n*a+r*o-s*h,this._z=r*u+n*h+s*a-i*o,this._w=n*u-s*o-i*a-r*h,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const s=this._x,i=this._y,r=this._z,n=this._w;let o=n*t._w+s*t._x+i*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=n,this._x=s,this._y=i,this._z=r,this;const a=1-o*o;if(a<=Number.EPSILON){const t=1-e;return this._w=t*n+e*this._w,this._x=t*s+e*this._x,this._y=t*i+e*this._y,this._z=t*r+e*this._z,this.normalize(),this}const h=Math.sqrt(a),u=Math.atan2(h,o),l=Math.sin((1-e)*u)/h,c=Math.sin(e*u)/h;return this._w=n*l+this._w*c,this._x=s*l+this._x*c,this._y=i*l+this._y*c,this._z=r*l+this._z*c,this._onChangeCallback(),this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class Ei{constructor(t=0,e=0,s=0){Ei.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return void 0===s&&(s=this.z),this.x=t,this.y=e,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(Ii.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Ii.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*i,this.y=r[1]*e+r[4]*s+r[7]*i,this.z=r[2]*e+r[5]*s+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=t.elements,n=1/(r[3]*e+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*e+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*e+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,r=t.x,n=t.y,o=t.z,a=t.w,h=2*(n*i-o*s),u=2*(o*e-r*i),l=2*(r*s-n*e);return this.x=e+a*h+n*l-o*u,this.y=s+a*u+o*h-r*l,this.z=i+a*l+r*u-n*h,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*i,this.y=r[1]*e+r[5]*s+r[9]*i,this.z=r[2]*e+r[6]*s+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,i=t.y,r=t.z,n=e.x,o=e.y,a=e.z;return this.x=i*a-r*o,this.y=r*n-s*a,this.z=s*o-i*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return Bi.copy(this).projectOnVector(t),this.sub(Bi)}reflect(t){return this.sub(Bi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos($s(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,i=this.z-t.z;return e*e+s*s+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,s){const i=Math.sin(e)*t;return this.x=i*Math.sin(s),this.y=Math.cos(e)*t,this.z=i*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Bi=new Ei,Ii=new Ci;class Pi{constructor(t=new Ei(1/0,1/0,1/0),e=new Ei(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,s=t.length;ethis.max.x||t.ythis.max.y||t.zthis.max.z)}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return!(t.max.xthis.max.x||t.max.ythis.max.y||t.max.zthis.max.z)}intersectsSphere(t){return this.clampPoint(t.center,Ui),Ui.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,s;return t.normal.x>0?(e=t.normal.x*this.min.x,s=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,s=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,s+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,s+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,s+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,s+=t.normal.z*this.min.z),e<=-t.constant&&s>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Wi),ji.subVectors(this.max,Wi),zi.subVectors(t.a,Wi),Li.subVectors(t.b,Wi),Vi.subVectors(t.c,Wi),Di.subVectors(Li,zi),ki.subVectors(Vi,Li),Gi.subVectors(zi,Vi);let e=[0,-Di.z,Di.y,0,-ki.z,ki.y,0,-Gi.z,Gi.y,Di.z,0,-Di.x,ki.z,0,-ki.x,Gi.z,0,-Gi.x,-Di.y,Di.x,0,-ki.y,ki.x,0,-Gi.y,Gi.x,0];return!!$i(e,zi,Li,Vi,ji)&&(e=[1,0,0,0,1,0,0,0,1],!!$i(e,zi,Li,Vi,ji)&&(Hi.crossVectors(Di,ki),e=[Hi.x,Hi.y,Hi.z],$i(e,zi,Li,Vi,ji)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Ui).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(Ui).length()),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()||(Fi[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Fi[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Fi[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Fi[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Fi[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Fi[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Fi[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Fi[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Fi)),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const Fi=[new Ei,new Ei,new Ei,new Ei,new Ei,new Ei,new Ei,new Ei],Ui=new Ei,Oi=new Pi,zi=new Ei,Li=new Ei,Vi=new Ei,Di=new Ei,ki=new Ei,Gi=new Ei,Wi=new Ei,ji=new Ei,Hi=new Ei,qi=new Ei;function $i(t,e,s,i,r){for(let n=0,o=t.length-3;n<=o;n+=3){qi.fromArray(t,n);const o=r.x*Math.abs(qi.x)+r.y*Math.abs(qi.y)+r.z*Math.abs(qi.z),a=e.dot(qi),h=s.dot(qi),u=i.dot(qi);if(Math.max(-Math.max(a,h,u),Math.min(a,h,u))>o)return!1}return!0}const Xi=new Pi,Yi=new Ei,Ji=new Ei;class Zi{constructor(t=new Ei,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const s=this.center;void 0!==e?s.copy(e):Xi.setFromPoints(t).getCenter(s);let i=0;for(let e=0,r=t.length;ethis.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;Yi.subVectors(t,this.center);const e=Yi.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),s=.5*(t-this.radius);this.center.addScaledVector(Yi,s/t),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(!0===this.center.equals(t.center)?this.radius=Math.max(this.radius,t.radius):(Ji.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(Yi.copy(t.center).add(Ji)),this.expandByPoint(Yi.copy(t.center).sub(Ji))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const Qi=new Ei,Ki=new Ei,tr=new Ei,er=new Ei,sr=new Ei,ir=new Ei,rr=new Ei;class nr{constructor(t=new Ei,e=new Ei(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,Qi)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const s=e.dot(this.direction);return s<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,s)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=Qi.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(Qi.copy(this.origin).addScaledVector(this.direction,e),Qi.distanceToSquared(t))}distanceSqToSegment(t,e,s,i){Ki.copy(t).add(e).multiplyScalar(.5),tr.copy(e).sub(t).normalize(),er.copy(this.origin).sub(Ki);const r=.5*t.distanceTo(e),n=-this.direction.dot(tr),o=er.dot(this.direction),a=-er.dot(tr),h=er.lengthSq(),u=Math.abs(1-n*n);let l,c,d,p;if(u>0)if(l=n*a-o,c=n*o-a,p=r*u,l>=0)if(c>=-p)if(c<=p){const t=1/u;l*=t,c*=t,d=l*(l+n*c+2*o)+c*(n*l+c+2*a)+h}else c=r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;else c=-r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;else c<=-p?(l=Math.max(0,-(-n*r+o)),c=l>0?-r:Math.min(Math.max(-r,-a),r),d=-l*l+c*(c+2*a)+h):c<=p?(l=0,c=Math.min(Math.max(-r,-a),r),d=c*(c+2*a)+h):(l=Math.max(0,-(n*r+o)),c=l>0?r:Math.min(Math.max(-r,-a),r),d=-l*l+c*(c+2*a)+h);else c=n>0?-r:r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;return s&&s.copy(this.origin).addScaledVector(this.direction,l),i&&i.copy(Ki).addScaledVector(tr,c),d}intersectSphere(t,e){Qi.subVectors(t.center,this.origin);const s=Qi.dot(this.direction),i=Qi.dot(Qi)-s*s,r=t.radius*t.radius;if(i>r)return null;const n=Math.sqrt(r-i),o=s-n,a=s+n;return a<0?null:o<0?this.at(a,e):this.at(o,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const s=-(this.origin.dot(t.normal)+t.constant)/e;return s>=0?s:null}intersectPlane(t,e){const s=this.distanceToPlane(t);return null===s?null:this.at(s,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);if(0===e)return!0;return t.normal.dot(this.direction)*e<0}intersectBox(t,e){let s,i,r,n,o,a;const h=1/this.direction.x,u=1/this.direction.y,l=1/this.direction.z,c=this.origin;return h>=0?(s=(t.min.x-c.x)*h,i=(t.max.x-c.x)*h):(s=(t.max.x-c.x)*h,i=(t.min.x-c.x)*h),u>=0?(r=(t.min.y-c.y)*u,n=(t.max.y-c.y)*u):(r=(t.max.y-c.y)*u,n=(t.min.y-c.y)*u),s>n||r>i?null:((r>s||isNaN(s))&&(s=r),(n=0?(o=(t.min.z-c.z)*l,a=(t.max.z-c.z)*l):(o=(t.max.z-c.z)*l,a=(t.min.z-c.z)*l),s>a||o>i?null:((o>s||s!=s)&&(s=o),(a=0?s:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,Qi)}intersectTriangle(t,e,s,i,r){sr.subVectors(e,t),ir.subVectors(s,t),rr.crossVectors(sr,ir);let n,o=this.direction.dot(rr);if(o>0){if(i)return null;n=1}else{if(!(o<0))return null;n=-1,o=-o}er.subVectors(this.origin,t);const a=n*this.direction.dot(ir.crossVectors(er,ir));if(a<0)return null;const h=n*this.direction.dot(sr.cross(er));if(h<0)return null;if(a+h>o)return null;const u=-n*er.dot(rr);return u<0?null:this.at(u/o,r)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class or{constructor(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g){or.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g)}set(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g){const f=this.elements;return f[0]=t,f[4]=e,f[8]=s,f[12]=i,f[1]=r,f[5]=n,f[9]=o,f[13]=a,f[2]=h,f[6]=u,f[10]=l,f[14]=c,f[3]=d,f[7]=p,f[11]=m,f[15]=g,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new or).fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,s){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,s=t.elements,i=1/ar.setFromMatrixColumn(t,0).length(),r=1/ar.setFromMatrixColumn(t,1).length(),n=1/ar.setFromMatrixColumn(t,2).length();return e[0]=s[0]*i,e[1]=s[1]*i,e[2]=s[2]*i,e[3]=0,e[4]=s[4]*r,e[5]=s[5]*r,e[6]=s[6]*r,e[7]=0,e[8]=s[8]*n,e[9]=s[9]*n,e[10]=s[10]*n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,i=t.y,r=t.z,n=Math.cos(s),o=Math.sin(s),a=Math.cos(i),h=Math.sin(i),u=Math.cos(r),l=Math.sin(r);if("XYZ"===t.order){const t=n*u,s=n*l,i=o*u,r=o*l;e[0]=a*u,e[4]=-a*l,e[8]=h,e[1]=s+i*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=i+s*h,e[10]=n*a}else if("YXZ"===t.order){const t=a*u,s=a*l,i=h*u,r=h*l;e[0]=t+r*o,e[4]=i*o-s,e[8]=n*h,e[1]=n*l,e[5]=n*u,e[9]=-o,e[2]=s*o-i,e[6]=r+t*o,e[10]=n*a}else if("ZXY"===t.order){const t=a*u,s=a*l,i=h*u,r=h*l;e[0]=t-r*o,e[4]=-n*l,e[8]=i+s*o,e[1]=s+i*o,e[5]=n*u,e[9]=r-t*o,e[2]=-n*h,e[6]=o,e[10]=n*a}else if("ZYX"===t.order){const t=n*u,s=n*l,i=o*u,r=o*l;e[0]=a*u,e[4]=i*h-s,e[8]=t*h+r,e[1]=a*l,e[5]=r*h+t,e[9]=s*h-i,e[2]=-h,e[6]=o*a,e[10]=n*a}else if("YZX"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*u,e[4]=r-t*l,e[8]=i*l+s,e[1]=l,e[5]=n*u,e[9]=-o*u,e[2]=-h*u,e[6]=s*l+i,e[10]=t-r*l}else if("XZY"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*u,e[4]=-l,e[8]=h*u,e[1]=t*l+r,e[5]=n*u,e[9]=s*l-i,e[2]=i*l-s,e[6]=o*u,e[10]=r*l+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(ur,t,lr)}lookAt(t,e,s){const i=this.elements;return pr.subVectors(t,e),0===pr.lengthSq()&&(pr.z=1),pr.normalize(),cr.crossVectors(s,pr),0===cr.lengthSq()&&(1===Math.abs(s.z)?pr.x+=1e-4:pr.z+=1e-4,pr.normalize(),cr.crossVectors(s,pr)),cr.normalize(),dr.crossVectors(pr,cr),i[0]=cr.x,i[4]=dr.x,i[8]=pr.x,i[1]=cr.y,i[5]=dr.y,i[9]=pr.y,i[2]=cr.z,i[6]=dr.z,i[10]=pr.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[4],a=s[8],h=s[12],u=s[1],l=s[5],c=s[9],d=s[13],p=s[2],m=s[6],g=s[10],f=s[14],y=s[3],x=s[7],b=s[11],v=s[15],T=i[0],_=i[4],w=i[8],S=i[12],M=i[1],A=i[5],N=i[9],R=i[13],C=i[2],E=i[6],B=i[10],I=i[14],P=i[3],F=i[7],U=i[11],O=i[15];return r[0]=n*T+o*M+a*C+h*P,r[4]=n*_+o*A+a*E+h*F,r[8]=n*w+o*N+a*B+h*U,r[12]=n*S+o*R+a*I+h*O,r[1]=u*T+l*M+c*C+d*P,r[5]=u*_+l*A+c*E+d*F,r[9]=u*w+l*N+c*B+d*U,r[13]=u*S+l*R+c*I+d*O,r[2]=p*T+m*M+g*C+f*P,r[6]=p*_+m*A+g*E+f*F,r[10]=p*w+m*N+g*B+f*U,r[14]=p*S+m*R+g*I+f*O,r[3]=y*T+x*M+b*C+v*P,r[7]=y*_+x*A+b*E+v*F,r[11]=y*w+x*N+b*B+v*U,r[15]=y*S+x*R+b*I+v*O,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[4],i=t[8],r=t[12],n=t[1],o=t[5],a=t[9],h=t[13],u=t[2],l=t[6],c=t[10],d=t[14];return t[3]*(+r*a*l-i*h*l-r*o*c+s*h*c+i*o*d-s*a*d)+t[7]*(+e*a*d-e*h*c+r*n*c-i*n*d+i*h*u-r*a*u)+t[11]*(+e*h*l-e*o*d-r*n*l+s*n*d+r*o*u-s*h*u)+t[15]*(-i*o*u-e*a*l+e*o*c+i*n*l-s*n*c+s*a*u)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,s){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8],l=t[9],c=t[10],d=t[11],p=t[12],m=t[13],g=t[14],f=t[15],y=l*g*h-m*c*h+m*a*d-o*g*d-l*a*f+o*c*f,x=p*c*h-u*g*h-p*a*d+n*g*d+u*a*f-n*c*f,b=u*m*h-p*l*h+p*o*d-n*m*d-u*o*f+n*l*f,v=p*l*a-u*m*a-p*o*c+n*m*c+u*o*g-n*l*g,T=e*y+s*x+i*b+r*v;if(0===T)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const _=1/T;return t[0]=y*_,t[1]=(m*c*r-l*g*r-m*i*d+s*g*d+l*i*f-s*c*f)*_,t[2]=(o*g*r-m*a*r+m*i*h-s*g*h-o*i*f+s*a*f)*_,t[3]=(l*a*r-o*c*r-l*i*h+s*c*h+o*i*d-s*a*d)*_,t[4]=x*_,t[5]=(u*g*r-p*c*r+p*i*d-e*g*d-u*i*f+e*c*f)*_,t[6]=(p*a*r-n*g*r-p*i*h+e*g*h+n*i*f-e*a*f)*_,t[7]=(n*c*r-u*a*r+u*i*h-e*c*h-n*i*d+e*a*d)*_,t[8]=b*_,t[9]=(p*l*r-u*m*r-p*s*d+e*m*d+u*s*f-e*l*f)*_,t[10]=(n*m*r-p*o*r+p*s*h-e*m*h-n*s*f+e*o*f)*_,t[11]=(u*o*r-n*l*r-u*s*h+e*l*h+n*s*d-e*o*d)*_,t[12]=v*_,t[13]=(u*m*i-p*l*i+p*s*c-e*m*c-u*s*g+e*l*g)*_,t[14]=(p*o*i-n*m*i-p*s*a+e*m*a+n*s*g-e*o*g)*_,t[15]=(n*l*i-u*o*i+u*s*a-e*l*a-n*s*c+e*o*c)*_,this}scale(t){const e=this.elements,s=t.x,i=t.y,r=t.z;return e[0]*=s,e[4]*=i,e[8]*=r,e[1]*=s,e[5]*=i,e[9]*=r,e[2]*=s,e[6]*=i,e[10]*=r,e[3]*=s,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,s,i))}makeTranslation(t,e,s){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),i=Math.sin(e),r=1-s,n=t.x,o=t.y,a=t.z,h=r*n,u=r*o;return this.set(h*n+s,h*o-i*a,h*a+i*o,0,h*o+i*a,u*o+s,u*a-i*n,0,h*a-i*o,u*a+i*n,r*a*a+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,i,r,n){return this.set(1,s,r,0,t,1,n,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,r=e._x,n=e._y,o=e._z,a=e._w,h=r+r,u=n+n,l=o+o,c=r*h,d=r*u,p=r*l,m=n*u,g=n*l,f=o*l,y=a*h,x=a*u,b=a*l,v=s.x,T=s.y,_=s.z;return i[0]=(1-(m+f))*v,i[1]=(d+b)*v,i[2]=(p-x)*v,i[3]=0,i[4]=(d-b)*T,i[5]=(1-(c+f))*T,i[6]=(g+y)*T,i[7]=0,i[8]=(p+x)*_,i[9]=(g-y)*_,i[10]=(1-(c+m))*_,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,s){const i=this.elements;let r=ar.set(i[0],i[1],i[2]).length();const n=ar.set(i[4],i[5],i[6]).length(),o=ar.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),t.x=i[12],t.y=i[13],t.z=i[14],hr.copy(this);const a=1/r,h=1/n,u=1/o;return hr.elements[0]*=a,hr.elements[1]*=a,hr.elements[2]*=a,hr.elements[4]*=h,hr.elements[5]*=h,hr.elements[6]*=h,hr.elements[8]*=u,hr.elements[9]*=u,hr.elements[10]*=u,e.setFromRotationMatrix(hr),s.x=r,s.y=n,s.z=o,this}makePerspective(t,e,s,i,r,n,o=2e3){const a=this.elements,h=2*r/(e-t),u=2*r/(s-i),l=(e+t)/(e-t),c=(s+i)/(s-i);let d,p;if(o===Vs)d=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(o!==Ds)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);d=-n/(n-r),p=-n*r/(n-r)}return a[0]=h,a[4]=0,a[8]=l,a[12]=0,a[1]=0,a[5]=u,a[9]=c,a[13]=0,a[2]=0,a[6]=0,a[10]=d,a[14]=p,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,s,i,r,n,o=2e3){const a=this.elements,h=1/(e-t),u=1/(s-i),l=1/(n-r),c=(e+t)*h,d=(s+i)*u;let p,m;if(o===Vs)p=(n+r)*l,m=-2*l;else{if(o!==Ds)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=r*l,m=-1*l}return a[0]=2*h,a[4]=0,a[8]=0,a[12]=-c,a[1]=0,a[5]=2*u,a[9]=0,a[13]=-d,a[2]=0,a[6]=0,a[10]=m,a[14]=-p,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<16;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const ar=new Ei,hr=new or,ur=new Ei(0,0,0),lr=new Ei(1,1,1),cr=new Ei,dr=new Ei,pr=new Ei,mr=new or,gr=new Ci;class fr{constructor(t=0,e=0,s=0,i=fr.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,s,i=this._order){return this._x=t,this._y=e,this._z=s,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,s=!0){const i=t.elements,r=i[0],n=i[4],o=i[8],a=i[1],h=i[5],u=i[9],l=i[2],c=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin($s(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-u,d),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(c,h),this._z=0);break;case"YXZ":this._x=Math.asin(-$s(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-l,r),this._z=0);break;case"ZXY":this._x=Math.asin($s(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(-l,d),this._z=Math.atan2(-n,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-$s(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(c,d),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-n,h));break;case"YZX":this._z=Math.asin($s(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-u,h),this._y=Math.atan2(-l,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-$s(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(c,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-u,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===s&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return mr.makeRotationFromQuaternion(t),this.setFromRotationMatrix(mr,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return gr.setFromEuler(this),this.setFromQuaternion(gr,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}fr.DEFAULT_ORDER="XYZ";class yr{constructor(){this.mask=1}set(t){this.mask=(1<>>0}enable(t){this.mask|=1<1){for(let t=0;t1){for(let t=0;t0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.visibility=this._visibility,i.active=this._active,i.bounds=this._bounds.map((t=>({boxInitialized:t.boxInitialized,boxMin:t.box.min.toArray(),boxMax:t.box.max.toArray(),sphereInitialized:t.sphereInitialized,sphereRadius:t.sphere.radius,sphereCenter:t.sphere.center.toArray()}))),i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.geometryCount=this._geometryCount,i.matricesTexture=this._matricesTexture.toJSON(t),null!==this._colorsTexture&&(i.colorsTexture=this._colorsTexture.toJSON(t)),null!==this.boundingSphere&&(i.boundingSphere={center:i.boundingSphere.center.toArray(),radius:i.boundingSphere.radius}),null!==this.boundingBox&&(i.boundingBox={min:i.boundingBox.min.toArray(),max:i.boundingBox.max.toArray()})),this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=r(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const s=e.shapes;if(Array.isArray(s))for(let e=0,i=s.length;e0){i.children=[];for(let e=0;e0){i.animations=[];for(let e=0;e0&&(s.geometries=e),i.length>0&&(s.materials=i),r.length>0&&(s.textures=r),o.length>0&&(s.images=o),a.length>0&&(s.shapes=a),h.length>0&&(s.skeletons=h),u.length>0&&(s.animations=u),l.length>0&&(s.nodes=l)}return s.object=i,s;function n(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}}clone(t){return(new this.constructor).copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(let e=0;e0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,s,i,r){Fr.subVectors(i,e),Ur.subVectors(s,e),Or.subVectors(t,e);const n=Fr.dot(Fr),o=Fr.dot(Ur),a=Fr.dot(Or),h=Ur.dot(Ur),u=Ur.dot(Or),l=n*h-o*o;if(0===l)return r.set(0,0,0),null;const c=1/l,d=(h*a-o*u)*c,p=(n*u-o*a)*c;return r.set(1-d-p,p,d)}static containsPoint(t,e,s,i){return null!==this.getBarycoord(t,e,s,i,zr)&&(zr.x>=0&&zr.y>=0&&zr.x+zr.y<=1)}static getInterpolation(t,e,s,i,r,n,o,a){return null===this.getBarycoord(t,e,s,i,zr)?(a.x=0,a.y=0,"z"in a&&(a.z=0),"w"in a&&(a.w=0),null):(a.setScalar(0),a.addScaledVector(r,zr.x),a.addScaledVector(n,zr.y),a.addScaledVector(o,zr.z),a)}static isFrontFacing(t,e,s,i){return Fr.subVectors(s,e),Ur.subVectors(t,e),Fr.cross(Ur).dot(i)<0}set(t,e,s){return this.a.copy(t),this.b.copy(e),this.c.copy(s),this}setFromPointsAndIndices(t,e,s,i){return this.a.copy(t[e]),this.b.copy(t[s]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,s,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,s),this.c.fromBufferAttribute(t,i),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return Fr.subVectors(this.c,this.b),Ur.subVectors(this.a,this.b),.5*Fr.cross(Ur).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return jr.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return jr.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,s,i,r){return jr.getInterpolation(t,this.a,this.b,this.c,e,s,i,r)}containsPoint(t){return jr.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return jr.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const s=this.a,i=this.b,r=this.c;let n,o;Lr.subVectors(i,s),Vr.subVectors(r,s),kr.subVectors(t,s);const a=Lr.dot(kr),h=Vr.dot(kr);if(a<=0&&h<=0)return e.copy(s);Gr.subVectors(t,i);const u=Lr.dot(Gr),l=Vr.dot(Gr);if(u>=0&&l<=u)return e.copy(i);const c=a*l-u*h;if(c<=0&&a>=0&&u<=0)return n=a/(a-u),e.copy(s).addScaledVector(Lr,n);Wr.subVectors(t,r);const d=Lr.dot(Wr),p=Vr.dot(Wr);if(p>=0&&d<=p)return e.copy(r);const m=d*h-a*p;if(m<=0&&h>=0&&p<=0)return o=h/(h-p),e.copy(s).addScaledVector(Vr,o);const g=u*p-d*l;if(g<=0&&l-u>=0&&d-p>=0)return Dr.subVectors(r,i),o=(l-u)/(l-u+(d-p)),e.copy(i).addScaledVector(Dr,o);const f=1/(g+m+c);return n=m*f,o=c*f,e.copy(s).addScaledVector(Lr,n).addScaledVector(Vr,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const Hr={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},qr={h:0,s:0,l:0},$r={h:0,s:0,l:0};function Xr(t,e,s){return s<0&&(s+=1),s>1&&(s-=1),s<1/6?t+6*(e-t)*s:s<.5?e:s<2/3?t+6*(e-t)*(2/3-s):t}class Yr{constructor(t,e,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,s)}set(t,e,s){if(void 0===e&&void 0===s){const e=t;e&&e.isColor?this.copy(e):"number"==typeof e?this.setHex(e):"string"==typeof e&&this.setStyle(e)}else this.setRGB(t,e,s);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Je){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,di.toWorkingColorSpace(this,e),this}setRGB(t,e,s,i=di.workingColorSpace){return this.r=t,this.g=e,this.b=s,di.toWorkingColorSpace(this,i),this}setHSL(t,e,s,i=di.workingColorSpace){if(t=Xs(t,1),e=$s(e,0,1),s=$s(s,0,1),0===e)this.r=this.g=this.b=s;else{const i=s<=.5?s*(1+e):s+e-s*e,r=2*s-i;this.r=Xr(r,i,t+1/3),this.g=Xr(r,i,t),this.b=Xr(r,i,t-1/3)}return di.toWorkingColorSpace(this,i),this}setStyle(t,e=Je){function s(e){void 0!==e&&parseFloat(e)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let r;const n=i[1],o=i[2];switch(n){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){const s=i[1],r=s.length;if(3===r)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,e);if(6===r)return this.setHex(parseInt(s,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=Je){const s=Hr[t.toLowerCase()];return void 0!==s?this.setHex(s,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=pi(t.r),this.g=pi(t.g),this.b=pi(t.b),this}copyLinearToSRGB(t){return this.r=mi(t.r),this.g=mi(t.g),this.b=mi(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Je){return di.fromWorkingColorSpace(Jr.copy(this),t),65536*Math.round($s(255*Jr.r,0,255))+256*Math.round($s(255*Jr.g,0,255))+Math.round($s(255*Jr.b,0,255))}getHexString(t=Je){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=di.workingColorSpace){di.fromWorkingColorSpace(Jr.copy(this),e);const s=Jr.r,i=Jr.g,r=Jr.b,n=Math.max(s,i,r),o=Math.min(s,i,r);let a,h;const u=(o+n)/2;if(o===n)a=0,h=0;else{const t=n-o;switch(h=u<=.5?t/(n+o):t/(2-n-o),n){case s:a=(i-r)/t+(i0!=t>0&&this.version++,this._alphaTest=t}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const s=t[e];if(void 0===s){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(s):i&&i.isVector3&&s&&s.isVector3?i.copy(s):this[e]=s:console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const s={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(s.uuid=this.uuid,s.type=this.type,""!==this.name&&(s.name=this.name),this.color&&this.color.isColor&&(s.color=this.color.getHex()),void 0!==this.roughness&&(s.roughness=this.roughness),void 0!==this.metalness&&(s.metalness=this.metalness),void 0!==this.sheen&&(s.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(s.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(s.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(s.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(s.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(s.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(s.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(s.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(s.shininess=this.shininess),void 0!==this.clearcoat&&(s.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(s.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(s.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(s.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(s.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,s.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.dispersion&&(s.dispersion=this.dispersion),void 0!==this.iridescence&&(s.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(s.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(s.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(s.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(s.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(s.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(s.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(s.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(s.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(s.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(s.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(s.lightMap=this.lightMap.toJSON(t).uuid,s.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(s.aoMap=this.aoMap.toJSON(t).uuid,s.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(s.bumpMap=this.bumpMap.toJSON(t).uuid,s.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(s.normalMap=this.normalMap.toJSON(t).uuid,s.normalMapType=this.normalMapType,s.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(s.displacementMap=this.displacementMap.toJSON(t).uuid,s.displacementScale=this.displacementScale,s.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(s.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(s.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(s.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(s.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(s.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(s.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(s.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(s.combine=this.combine)),void 0!==this.envMapRotation&&(s.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(s.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(s.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(s.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(s.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(s.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(s.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(s.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(s.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(s.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(s.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(s.size=this.size),null!==this.shadowSide&&(s.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(s.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(s.blending=this.blending),this.side!==c&&(s.side=this.side),!0===this.vertexColors&&(s.vertexColors=!0),this.opacity<1&&(s.opacity=this.opacity),!0===this.transparent&&(s.transparent=!0),this.blendSrc!==C&&(s.blendSrc=this.blendSrc),this.blendDst!==E&&(s.blendDst=this.blendDst),this.blendEquation!==v&&(s.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(s.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(s.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(s.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(s.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(s.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(s.depthFunc=this.depthFunc),!1===this.depthTest&&(s.depthTest=this.depthTest),!1===this.depthWrite&&(s.depthWrite=this.depthWrite),!1===this.colorWrite&&(s.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(s.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==bs&&(s.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(s.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(s.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==ns&&(s.stencilFail=this.stencilFail),this.stencilZFail!==ns&&(s.stencilZFail=this.stencilZFail),this.stencilZPass!==ns&&(s.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(s.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(s.rotation=this.rotation),!0===this.polygonOffset&&(s.polygonOffset=!0),0!==this.polygonOffsetFactor&&(s.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(s.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(s.linewidth=this.linewidth),void 0!==this.dashSize&&(s.dashSize=this.dashSize),void 0!==this.gapSize&&(s.gapSize=this.gapSize),void 0!==this.scale&&(s.scale=this.scale),!0===this.dithering&&(s.dithering=!0),this.alphaTest>0&&(s.alphaTest=this.alphaTest),!0===this.alphaHash&&(s.alphaHash=!0),!0===this.alphaToCoverage&&(s.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(s.premultipliedAlpha=!0),!0===this.forceSinglePass&&(s.forceSinglePass=!0),!0===this.wireframe&&(s.wireframe=!0),this.wireframeLinewidth>1&&(s.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(s.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(s.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(s.flatShading=!0),!1===this.visible&&(s.visible=!1),!1===this.toneMapped&&(s.toneMapped=!1),!1===this.fog&&(s.fog=!1),Object.keys(this.userData).length>0&&(s.userData=this.userData),e){const e=i(t.textures),r=i(t.images);e.length>0&&(s.textures=e),r.length>0&&(s.images=r)}return s}clone(){return(new this.constructor).copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let s=null;if(null!==e){const t=e.length;s=new Array(t);for(let i=0;i!==t;++i)s[i]=e[i].clone()}return this.clippingPlanes=s,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}onBuild(){console.warn("Material: onBuild() has been removed.")}onBeforeRender(){console.warn("Material: onBeforeRender() has been removed.")}}class Kr extends Qr{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Yr(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fr,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const tn=en();function en(){const t=new ArrayBuffer(4),e=new Float32Array(t),s=new Uint32Array(t),i=new Uint32Array(512),r=new Uint32Array(512);for(let t=0;t<256;++t){const e=t-127;e<-27?(i[t]=0,i[256|t]=32768,r[t]=24,r[256|t]=24):e<-14?(i[t]=1024>>-e-14,i[256|t]=1024>>-e-14|32768,r[t]=-e-1,r[256|t]=-e-1):e<=15?(i[t]=e+15<<10,i[256|t]=e+15<<10|32768,r[t]=13,r[256|t]=13):e<128?(i[t]=31744,i[256|t]=64512,r[t]=24,r[256|t]=24):(i[t]=31744,i[256|t]=64512,r[t]=13,r[256|t]=13)}const n=new Uint32Array(2048),o=new Uint32Array(64),a=new Uint32Array(64);for(let t=1;t<1024;++t){let e=t<<13,s=0;for(;0==(8388608&e);)e<<=1,s-=8388608;e&=-8388609,s+=947912704,n[t]=e|s}for(let t=1024;t<2048;++t)n[t]=939524096+(t-1024<<13);for(let t=1;t<31;++t)o[t]=t<<23;o[31]=1199570944,o[32]=2147483648;for(let t=33;t<63;++t)o[t]=2147483648+(t-32<<23);o[63]=3347054592;for(let t=1;t<64;++t)32!==t&&(a[t]=1024);return{floatView:e,uint32View:s,baseTable:i,shiftTable:r,mantissaTable:n,exponentTable:o,offsetTable:a}}function sn(t){Math.abs(t)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),t=$s(t,-65504,65504),tn.floatView[0]=t;const e=tn.uint32View[0],s=e>>23&511;return tn.baseTable[s]+((8388607&e)>>tn.shiftTable[s])}function rn(t){const e=t>>10;return tn.uint32View[0]=tn.mantissaTable[tn.offsetTable[e]+(1023&t)]+tn.exponentTable[e],tn.floatView[0]}const nn={toHalfFloat:sn,fromHalfFloat:rn},on=new Ei,an=new Ks;class hn{constructor(t,e,s=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=s,this.usage=Rs,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.gpuType=It,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}get updateRange(){return ai("THREE.BufferAttribute: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead."),this._updateRange}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,s){t*=this.itemSize,s*=e.itemSize;for(let i=0,r=this.itemSize;i=0;--e)if(t[e]>=65535)return!0;return!1}(t)?gn:pn)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return void 0!==this.attributes[t]}addGroup(t,e,s=0){this.groups.push({start:t,count:e,materialIndex:s})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;void 0!==e&&(e.applyMatrix4(t),e.needsUpdate=!0);const s=this.attributes.normal;if(void 0!==s){const e=(new ti).getNormalMatrix(t);s.applyNormalMatrix(e),s.needsUpdate=!0}const i=this.attributes.tangent;return void 0!==i&&(i.transformDirection(t),i.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}applyQuaternion(t){return bn.makeRotationFromQuaternion(t),this.applyMatrix4(bn),this}rotateX(t){return bn.makeRotationX(t),this.applyMatrix4(bn),this}rotateY(t){return bn.makeRotationY(t),this.applyMatrix4(bn),this}rotateZ(t){return bn.makeRotationZ(t),this.applyMatrix4(bn),this}translate(t,e,s){return bn.makeTranslation(t,e,s),this.applyMatrix4(bn),this}scale(t,e,s){return bn.makeScale(t,e,s),this.applyMatrix4(bn),this}lookAt(t){return vn.lookAt(t),vn.updateMatrix(),this.applyMatrix4(vn.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Tn).negate(),this.translate(Tn.x,Tn.y,Tn.z),this}setFromPoints(t){const e=[];for(let s=0,i=t.length;s0&&(t.userData=this.userData),void 0!==this.parameters){const e=this.parameters;for(const s in e)void 0!==e[s]&&(t[s]=e[s]);return t}t.data={attributes:{}};const e=this.index;null!==e&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const s=this.attributes;for(const e in s){const i=s[e];t.data.attributes[e]=i.toJSON(t.data)}const i={};let r=!1;for(const e in this.morphAttributes){const s=this.morphAttributes[e],n=[];for(let e=0,i=s.length;e0&&(i[e]=n,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const n=this.groups;n.length>0&&(t.data.groups=JSON.parse(JSON.stringify(n)));const o=this.boundingSphere;return null!==o&&(t.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),t}clone(){return(new this.constructor).copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const s=t.index;null!==s&&this.setIndex(s.clone(e));const i=t.attributes;for(const t in i){const s=i[t];this.setAttribute(t,s.clone(e))}const r=t.morphAttributes;for(const t in r){const s=[],i=r[t];for(let t=0,r=i.length;t0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;t(t.far-t.near)**2)return}An.copy(r).invert(),Nn.copy(t.ray).applyMatrix4(An),null!==s.boundingBox&&!1===Nn.intersectsBox(s.boundingBox)||this._computeIntersections(t,e,Nn)}}_computeIntersections(t,e,s){let i;const r=this.geometry,n=this.material,o=r.index,a=r.attributes.position,h=r.attributes.uv,u=r.attributes.uv1,l=r.attributes.normal,c=r.groups,d=r.drawRange;if(null!==o)if(Array.isArray(n))for(let r=0,a=c.length;rs.far?null:{distance:u,point:Gn.clone(),object:t}}(t,e,s,i,En,Bn,In,kn);if(l){r&&(Un.fromBufferAttribute(r,a),On.fromBufferAttribute(r,h),zn.fromBufferAttribute(r,u),l.uv=jr.getInterpolation(kn,En,Bn,In,Un,On,zn,new Ks)),n&&(Un.fromBufferAttribute(n,a),On.fromBufferAttribute(n,h),zn.fromBufferAttribute(n,u),l.uv1=jr.getInterpolation(kn,En,Bn,In,Un,On,zn,new Ks)),o&&(Ln.fromBufferAttribute(o,a),Vn.fromBufferAttribute(o,h),Dn.fromBufferAttribute(o,u),l.normal=jr.getInterpolation(kn,En,Bn,In,Ln,Vn,Dn,new Ei),l.normal.dot(i.direction)>0&&l.normal.multiplyScalar(-1));const t={a:a,b:h,c:u,normal:new Ei,materialIndex:0};jr.getNormal(En,Bn,In,t.normal),l.face=t}return l}class Hn extends Mn{constructor(t=1,e=1,s=1,i=1,r=1,n=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:s,widthSegments:i,heightSegments:r,depthSegments:n};const o=this;i=Math.floor(i),r=Math.floor(r),n=Math.floor(n);const a=[],h=[],u=[],l=[];let c=0,d=0;function p(t,e,s,i,r,n,p,m,g,f,y){const x=n/g,b=p/f,v=n/2,T=p/2,_=m/2,w=g+1,S=f+1;let M=0,A=0;const N=new Ei;for(let n=0;n0?1:-1,u.push(N.x,N.y,N.z),l.push(a/g),l.push(1-n/f),M+=1}}for(let t=0;t0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const s={};for(const t in this.extensions)!0===this.extensions[t]&&(s[t]=!0);return Object.keys(s).length>0&&(e.extensions=s),e}}class Xn extends Pr{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new or,this.projectionMatrix=new or,this.projectionMatrixInverse=new or,this.coordinateSystem=Vs}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return(new this.constructor).copy(this)}}const Yn=new Ei,Jn=new Ks,Zn=new Ks;class Qn extends Xn{constructor(t=50,e=1,s=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=s,this.far=i,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=null===t.view?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=2*Hs*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*js*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*Hs*Math.atan(Math.tan(.5*js*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,s){Yn.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(Yn.x,Yn.y).multiplyScalar(-t/Yn.z),Yn.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),s.set(Yn.x,Yn.y).multiplyScalar(-t/Yn.z)}getViewSize(t,e){return this.getViewBounds(t,Jn,Zn),e.subVectors(Zn,Jn)}setViewOffset(t,e,s,i,r,n){this.aspect=t/e,null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=s,this.view.offsetY=i,this.view.width=r,this.view.height=n,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*js*this.fov)/this.zoom,s=2*e,i=this.aspect*s,r=-.5*i;const n=this.view;if(null!==this.view&&this.view.enabled){const t=n.fullWidth,o=n.fullHeight;r+=n.offsetX*i/t,e-=n.offsetY*s/o,i*=n.width/t,s*=n.height/o}const o=this.filmOffset;0!==o&&(r+=t*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+i,e,e-s,t,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,null!==this.view&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const Kn=-90;class to extends Pr{constructor(t,e,s){super(),this.type="CubeCamera",this.renderTarget=s,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Qn(Kn,1,t,e);i.layers=this.layers,this.add(i);const r=new Qn(Kn,1,t,e);r.layers=this.layers,this.add(r);const n=new Qn(Kn,1,t,e);n.layers=this.layers,this.add(n);const o=new Qn(Kn,1,t,e);o.layers=this.layers,this.add(o);const a=new Qn(Kn,1,t,e);a.layers=this.layers,this.add(a);const h=new Qn(Kn,1,t,e);h.layers=this.layers,this.add(h)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[s,i,r,n,o,a]=e;for(const t of e)this.remove(t);if(t===Vs)s.up.set(0,1,0),s.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),n.up.set(0,0,1),n.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),a.up.set(0,1,0),a.lookAt(0,0,-1);else{if(t!==Ds)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);s.up.set(0,-1,0),s.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),n.up.set(0,0,-1),n.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),a.up.set(0,-1,0),a.lookAt(0,0,-1)}for(const t of e)this.add(t),t.updateMatrixWorld()}update(t,e){null===this.parent&&this.updateMatrixWorld();const{renderTarget:s,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,n,o,a,h,u]=this.children,l=t.getRenderTarget(),c=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const m=s.texture.generateMipmaps;s.texture.generateMipmaps=!1,t.setRenderTarget(s,0,i),t.render(e,r),t.setRenderTarget(s,1,i),t.render(e,n),t.setRenderTarget(s,2,i),t.render(e,o),t.setRenderTarget(s,3,i),t.render(e,a),t.setRenderTarget(s,4,i),t.render(e,h),s.texture.generateMipmaps=m,t.setRenderTarget(s,5,i),t.render(e,u),t.setRenderTarget(l,c,d),t.xr.enabled=p,s.texture.needsPMREMUpdate=!0}}class eo extends Ti{constructor(t,e,s,i,r,n,o,a,h,u){super(t=void 0!==t?t:[],e=void 0!==e?e:ht,s,i,r,n,o,a,h,u),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class so extends Si{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const s={width:t,height:t,depth:1},i=[s,s,s,s,s,s];this.texture=new eo(i,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=void 0!==e.generateMipmaps&&e.generateMipmaps,this.texture.minFilter=void 0!==e.minFilter?e.minFilter:Tt}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const s={uniforms:{tEquirect:{value:null}},vertexShader:"\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include \n\t\t\t\t\t#include \n\n\t\t\t\t}\n\t\t\t",fragmentShader:"\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include \n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t"},i=new Hn(5,5,5),r=new $n({name:"CubemapFromEquirect",uniforms:qn(s.uniforms),vertexShader:s.vertexShader,fragmentShader:s.fragmentShader,side:d,blending:m});r.uniforms.tEquirect.value=e;const n=new Wn(i,r),o=e.minFilter;e.minFilter===St&&(e.minFilter=Tt);return new to(1,10,this).update(t,n),e.minFilter=o,n.geometry.dispose(),n.material.dispose(),this}clear(t,e,s,i){const r=t.getRenderTarget();for(let r=0;r<6;r++)t.setRenderTarget(this,r),t.clear(e,s,i);t.setRenderTarget(r)}}class io{constructor(t,e=25e-5){this.isFogExp2=!0,this.name="",this.color=new Yr(t),this.density=e}clone(){return new io(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}}class ro{constructor(t,e=1,s=1e3){this.isFog=!0,this.name="",this.color=new Yr(t),this.near=e,this.far=s}clone(){return new ro(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class no extends Pr{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new fr,this.environmentIntensity=1,this.environmentRotation=new fr,this.overrideMaterial=null,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),null!==t.background&&(this.background=t.background.clone()),null!==t.environment&&(this.environment=t.environment.clone()),null!==t.fog&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,this.backgroundRotation.copy(t.backgroundRotation),this.environmentIntensity=t.environmentIntensity,this.environmentRotation.copy(t.environmentRotation),null!==t.overrideMaterial&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return null!==this.fog&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),1!==this.backgroundIntensity&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),1!==this.environmentIntensity&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}class oo{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=Rs,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.version=0,this.uuid=qs()}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}get updateRange(){return ai("THREE.InterleavedBuffer: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead."),this._updateRange}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,s){t*=this.stride,s*=e.stride;for(let i=0,r=this.stride;it.far||e.push({distance:a,point:co.clone(),uv:jr.getInterpolation(co,xo,bo,vo,To,_o,wo,new Ks),face:null,object:this})}copy(t,e){return super.copy(t,e),void 0!==t.center&&this.center.copy(t.center),this.material=t.material,this}}function Mo(t,e,s,i,r,n){go.subVectors(t,s).addScalar(.5).multiply(i),void 0!==r?(fo.x=n*go.x-r*go.y,fo.y=r*go.x+n*go.y):fo.copy(go),t.copy(e),t.x+=fo.x,t.y+=fo.y,t.applyMatrix4(yo)}const Ao=new Ei,No=new Ei;class Ro extends Pr{constructor(){super(),this._currentLevel=0,this.type="LOD",Object.defineProperties(this,{levels:{enumerable:!0,value:[]},isLOD:{value:!0}}),this.autoUpdate=!0}copy(t){super.copy(t,!1);const e=t.levels;for(let t=0,s=e.length;t0){let s,i;for(s=1,i=e.length;s0){Ao.setFromMatrixPosition(this.matrixWorld);const s=t.ray.origin.distanceTo(Ao);this.getObjectForDistance(s).raycast(t,e)}}update(t){const e=this.levels;if(e.length>1){Ao.setFromMatrixPosition(t.matrixWorld),No.setFromMatrixPosition(this.matrixWorld);const s=Ao.distanceTo(No)/t.zoom;let i,r;for(e[0].object.visible=!0,i=1,r=e.length;i=t))break;e[i-1].object.visible=!1,e[i].object.visible=!0}for(this._currentLevel=i-1;i1?null:e.copy(t.start).addScaledVector(s,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),s=this.distanceToPoint(t.end);return e<0&&s>0||s<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const s=e||ea.getNormalMatrix(t),i=this.coplanarPoint(Ko).applyMatrix4(t),r=this.normal.applyMatrix3(s).normalize();return this.constant=-i.dot(r),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return(new this.constructor).copy(this)}}const ia=new Zi,ra=new Ei;class na{constructor(t=new sa,e=new sa,s=new sa,i=new sa,r=new sa,n=new sa){this.planes=[t,e,s,i,r,n]}set(t,e,s,i,r,n){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(s),o[3].copy(i),o[4].copy(r),o[5].copy(n),this}copy(t){const e=this.planes;for(let s=0;s<6;s++)e[s].copy(t.planes[s]);return this}setFromProjectionMatrix(t,e=2e3){const s=this.planes,i=t.elements,r=i[0],n=i[1],o=i[2],a=i[3],h=i[4],u=i[5],l=i[6],c=i[7],d=i[8],p=i[9],m=i[10],g=i[11],f=i[12],y=i[13],x=i[14],b=i[15];if(s[0].setComponents(a-r,c-h,g-d,b-f).normalize(),s[1].setComponents(a+r,c+h,g+d,b+f).normalize(),s[2].setComponents(a+n,c+u,g+p,b+y).normalize(),s[3].setComponents(a-n,c-u,g-p,b-y).normalize(),s[4].setComponents(a-o,c-l,g-m,b-x).normalize(),e===Vs)s[5].setComponents(a+o,c+l,g+m,b+x).normalize();else{if(e!==Ds)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);s[5].setComponents(o,l,m,x).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),ia.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),ia.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(ia)}intersectsSprite(t){return ia.center.set(0,0,0),ia.radius=.7071067811865476,ia.applyMatrix4(t.matrixWorld),this.intersectsSphere(ia)}intersectsSphere(t){const e=this.planes,s=t.center,i=-t.radius;for(let t=0;t<6;t++){if(e[t].distanceToPoint(s)0?t.max.x:t.min.x,ra.y=i.normal.y>0?t.max.y:t.min.y,ra.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(ra)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let s=0;s<6;s++)if(e[s].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function oa(t,e){return t.z-e.z}function aa(t,e){return e.z-t.z}class ha{constructor(){this.index=0,this.pool=[],this.list=[]}push(t,e,s){const i=this.pool,r=this.list;this.index>=i.length&&i.push({start:-1,count:-1,z:-1,index:-1});const n=i[this.index];r.push(n),this.index++,n.start=t.start,n.count=t.count,n.z=e,n.index=s}reset(){this.list.length=0,this.index=0}}const ua=new or,la=new or,ca=new or,da=new Yr(1,1,1),pa=new or,ma=new na,ga=new Pi,fa=new Zi,ya=new Ei,xa=new Ei,ba=new Ei,va=new ha,Ta=new Wn,_a=[];function wa(t,e,s=0){const i=e.itemSize;if(t.isInterleavedBufferAttribute||t.array.constructor!==e.array.constructor){const r=t.count;for(let n=0;n65535?new Uint32Array(i):new Uint16Array(i);e.setIndex(new hn(t,1))}this._geometryInitialized=!0}}_validateGeometry(t){const e=this.geometry;if(Boolean(t.getIndex())!==Boolean(e.getIndex()))throw new Error('BatchedMesh: All geometries must consistently have "index".');for(const s in e.attributes){if(!t.hasAttribute(s))throw new Error(`BatchedMesh: Added geometry missing "${s}". All geometries must have consistent attributes.`);const i=t.getAttribute(s),r=e.getAttribute(s);if(i.itemSize!==r.itemSize||i.normalized!==r.normalized)throw new Error("BatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}setCustomSort(t){return this.customSort=t,this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Pi);const t=this._geometryCount,e=this.boundingBox,s=this._drawInfo;e.makeEmpty();for(let i=0;i=this._maxInstanceCount)throw new Error("BatchedMesh: Maximum item count reached.");this._drawInfo.push({visible:!0,active:!0,geometryIndex:t});const e=this._drawInfo.length-1,s=this._matricesTexture,i=s.image.data;ca.toArray(i,16*e),s.needsUpdate=!0;const r=this._colorsTexture;return r&&(da.toArray(r.image.data,4*e),r.needsUpdate=!0),e}addGeometry(t,e=-1,s=-1){if(this._initializeGeometry(t),this._validateGeometry(t),this._drawInfo.length>=this._maxInstanceCount)throw new Error("BatchedMesh: Maximum item count reached.");const i={vertexStart:-1,vertexCount:-1,indexStart:-1,indexCount:-1};let r=null;const n=this._reservedRanges,o=this._drawRanges,a=this._bounds;0!==this._geometryCount&&(r=n[n.length-1]),i.vertexCount=-1===e?t.getAttribute("position").count:e,i.vertexStart=null===r?0:r.vertexStart+r.vertexCount;const h=t.getIndex(),u=null!==h;if(u&&(i.indexCount=-1===s?h.count:s,i.indexStart=null===r?0:r.indexStart+r.indexCount),-1!==i.indexStart&&i.indexStart+i.indexCount>this._maxIndexCount||i.vertexStart+i.vertexCount>this._maxVertexCount)throw new Error("BatchedMesh: Reserved space request exceeds the maximum buffer size.");const l=this._geometryCount;return this._geometryCount++,n.push(i),o.push({start:u?i.indexStart:i.vertexStart,count:-1}),a.push({boxInitialized:!1,box:new Pi,sphereInitialized:!1,sphere:new Zi}),this.setGeometryAt(l,t),l}setGeometryAt(t,e){if(t>=this._geometryCount)throw new Error("BatchedMesh: Maximum geometry count reached.");this._validateGeometry(e);const s=this.geometry,i=null!==s.getIndex(),r=s.getIndex(),n=e.getIndex(),o=this._reservedRanges[t];if(i&&n.count>o.indexCount||e.attributes.position.count>o.vertexCount)throw new Error("BatchedMesh: Reserved space not large enough for provided geometry.");const a=o.vertexStart,h=o.vertexCount;for(const t in s.attributes){const i=e.getAttribute(t),r=s.getAttribute(t);wa(i,r,a);const n=i.itemSize;for(let t=i.count,e=h;t=this._geometryCount)return null;const s=this._bounds[t],i=s.box,r=this.geometry;if(!1===s.boxInitialized){i.makeEmpty();const e=r.index,n=r.attributes.position,o=this._drawRanges[t];for(let t=o.start,s=o.start+o.count;t=this._geometryCount)return null;const s=this._bounds[t],i=s.sphere,r=this.geometry;if(!1===s.sphereInitialized){i.makeEmpty(),this.getBoundingBoxAt(t,ga),ga.getCenter(i.center);const e=r.index,n=r.attributes.position,o=this._drawRanges[t];let a=0;for(let t=o.start,s=o.start+o.count;t=s.length||!1===s[t].active||(e.toArray(r,16*t),i.needsUpdate=!0),this}getMatrixAt(t,e){const s=this._drawInfo,i=this._matricesTexture.image.data;return t>=s.length||!1===s[t].active?null:e.fromArray(i,16*t)}setColorAt(t,e){null===this._colorsTexture&&this._initColorsTexture();const s=this._colorsTexture,i=this._colorsTexture.image.data,r=this._drawInfo;return t>=r.length||!1===r[t].active||(e.toArray(i,4*t),s.needsUpdate=!0),this}getColorAt(t,e){const s=this._colorsTexture.image.data,i=this._drawInfo;return t>=i.length||!1===i[t].active?null:e.fromArray(s,4*t)}setVisibleAt(t,e){const s=this._drawInfo;return t>=s.length||!1===s[t].active||s[t].visible===e||(s[t].visible=e,this._visibilityChanged=!0),this}getVisibleAt(t){const e=this._drawInfo;return!(t>=e.length||!1===e[t].active)&&e[t].visible}raycast(t,e){const s=this._drawInfo,i=this._drawRanges,r=this.matrixWorld,n=this.geometry;Ta.material=this.material,Ta.geometry.index=n.index,Ta.geometry.attributes=n.attributes,null===Ta.geometry.boundingBox&&(Ta.geometry.boundingBox=new Pi),null===Ta.geometry.boundingSphere&&(Ta.geometry.boundingSphere=new Zi);for(let n=0,o=s.length;n({...t}))),this._reservedRanges=t._reservedRanges.map((t=>({...t}))),this._drawInfo=t._drawInfo.map((t=>({...t}))),this._bounds=t._bounds.map((t=>({boxInitialized:t.boxInitialized,box:t.box.clone(),sphereInitialized:t.sphereInitialized,sphere:t.sphere.clone()}))),this._maxInstanceCount=t._maxInstanceCount,this._maxVertexCount=t._maxVertexCount,this._maxIndexCount=t._maxIndexCount,this._geometryInitialized=t._geometryInitialized,this._geometryCount=t._geometryCount,this._multiDrawCounts=t._multiDrawCounts.slice(),this._multiDrawStarts=t._multiDrawStarts.slice(),this._matricesTexture=t._matricesTexture.clone(),this._matricesTexture.image.data=this._matricesTexture.image.data.slice(),null!==this._colorsTexture&&(this._colorsTexture=t._colorsTexture.clone(),this._colorsTexture.image.data=this._colorsTexture.image.data.slice()),this}dispose(){return this.geometry.dispose(),this._matricesTexture.dispose(),this._matricesTexture=null,this._indirectTexture.dispose(),this._indirectTexture=null,null!==this._colorsTexture&&(this._colorsTexture.dispose(),this._colorsTexture=null),this}onBeforeRender(t,e,s,i,r){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;const n=i.getIndex(),o=null===n?1:n.array.BYTES_PER_ELEMENT,a=this._drawInfo,h=this._multiDrawStarts,u=this._multiDrawCounts,l=this._drawRanges,c=this.perObjectFrustumCulled,d=this._indirectTexture,p=d.image.data;c&&(pa.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse).multiply(this.matrixWorld),ma.setFromProjectionMatrix(pa,t.coordinateSystem));let m=0;if(this.sortObjects){la.copy(this.matrixWorld).invert(),ya.setFromMatrixPosition(s.matrixWorld).applyMatrix4(la),xa.set(0,0,-1).transformDirection(s.matrixWorld).transformDirection(la);for(let t=0,e=a.length;t0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;ti)return;Ba.applyMatrix4(t.matrixWorld);const a=e.ray.origin.distanceTo(Ba);return ae.far?void 0:{distance:a,point:Ia.clone().applyMatrix4(t.matrixWorld),index:r,face:null,faceIndex:null,object:t}}const Ua=new Ei,Oa=new Ei;class za extends Pa{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(null===t.index){const e=t.attributes.position,s=[];for(let t=0,i=e.count;t0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;tr.far)return;n.push({distance:h,distanceToRay:Math.sqrt(a),point:s,index:e,face:null,object:o})}}class qa extends Pr{constructor(){super(),this.isGroup=!0,this.type="Group"}}class $a extends Ti{constructor(t,e,s,i,r,n,o,a,h){super(t,e,s,i,r,n,o,a,h),this.isVideoTexture=!0,this.minFilter=void 0!==n?n:Tt,this.magFilter=void 0!==r?r:Tt,this.generateMipmaps=!1;const u=this;"requestVideoFrameCallback"in t&&t.requestVideoFrameCallback((function e(){u.needsUpdate=!0,t.requestVideoFrameCallback(e)}))}clone(){return new this.constructor(this.image).copy(this)}update(){const t=this.image;!1==="requestVideoFrameCallback"in t&&t.readyState>=t.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}}class Xa extends Ti{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=ft,this.minFilter=ft,this.generateMipmaps=!1,this.needsUpdate=!0}}class Ya extends Ti{constructor(t,e,s,i,r,n,o,a,h,u,l,c){super(null,n,o,a,h,u,i,r,l,c),this.isCompressedTexture=!0,this.image={width:e,height:s},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}}class Ja extends Ya{constructor(t,e,s,i,r,n){super(t,e,s,r,n),this.isCompressedArrayTexture=!0,this.image.depth=i,this.wrapR=mt,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class Za extends Ya{constructor(t,e,s){super(void 0,t[0].width,t[0].height,e,s,ht),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=t}}class Qa extends Ti{constructor(t,e,s,i,r,n,o,a,h){super(t,e,s,i,r,n,o,a,h),this.isCanvasTexture=!0,this.needsUpdate=!0}}class Ka extends Ti{constructor(t,e,s,i,r,n,o,a,h,u=1026){if(u!==Wt&&u!==jt)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===s&&u===Wt&&(s=Bt),void 0===s&&u===jt&&(s=Ot),super(null,i,r,n,o,a,u,s,h),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=void 0!==o?o:ft,this.minFilter=void 0!==a?a:ft,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return null!==this.compareFunction&&(e.compareFunction=this.compareFunction),e}}class th{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(t,e){const s=this.getUtoTmapping(t);return this.getPoint(s,e)}getPoints(t=5){const e=[];for(let s=0;s<=t;s++)e.push(this.getPoint(s/t));return e}getSpacedPoints(t=5){const e=[];for(let s=0;s<=t;s++)e.push(this.getPointAt(s/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const e=[];let s,i=this.getPoint(0),r=0;e.push(0);for(let n=1;n<=t;n++)s=this.getPoint(n/t),r+=s.distanceTo(i),e.push(r),i=s;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const s=this.getLengths();let i=0;const r=s.length;let n;n=e||t*s[r-1];let o,a=0,h=r-1;for(;a<=h;)if(i=Math.floor(a+(h-a)/2),o=s[i]-n,o<0)a=i+1;else{if(!(o>0)){h=i;break}h=i-1}if(i=h,s[i]===n)return i/(r-1);const u=s[i];return(i+(n-u)/(s[i+1]-u))/(r-1)}getTangent(t,e){const s=1e-4;let i=t-s,r=t+s;i<0&&(i=0),r>1&&(r=1);const n=this.getPoint(i),o=this.getPoint(r),a=e||(n.isVector2?new Ks:new Ei);return a.copy(o).sub(n).normalize(),a}getTangentAt(t,e){const s=this.getUtoTmapping(t);return this.getTangent(s,e)}computeFrenetFrames(t,e){const s=new Ei,i=[],r=[],n=[],o=new Ei,a=new or;for(let e=0;e<=t;e++){const s=e/t;i[e]=this.getTangentAt(s,new Ei)}r[0]=new Ei,n[0]=new Ei;let h=Number.MAX_VALUE;const u=Math.abs(i[0].x),l=Math.abs(i[0].y),c=Math.abs(i[0].z);u<=h&&(h=u,s.set(1,0,0)),l<=h&&(h=l,s.set(0,1,0)),c<=h&&s.set(0,0,1),o.crossVectors(i[0],s).normalize(),r[0].crossVectors(i[0],o),n[0].crossVectors(i[0],r[0]);for(let e=1;e<=t;e++){if(r[e]=r[e-1].clone(),n[e]=n[e-1].clone(),o.crossVectors(i[e-1],i[e]),o.length()>Number.EPSILON){o.normalize();const t=Math.acos($s(i[e-1].dot(i[e]),-1,1));r[e].applyMatrix4(a.makeRotationAxis(o,t))}n[e].crossVectors(i[e],r[e])}if(!0===e){let e=Math.acos($s(r[0].dot(r[t]),-1,1));e/=t,i[0].dot(o.crossVectors(r[0],r[t]))>0&&(e=-e);for(let s=1;s<=t;s++)r[s].applyMatrix4(a.makeRotationAxis(i[s],e*s)),n[s].crossVectors(i[s],r[s])}return{tangents:i,normals:r,binormals:n}}clone(){return(new this.constructor).copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){const t={metadata:{version:4.6,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}class eh extends th{constructor(t=0,e=0,s=1,i=1,r=0,n=2*Math.PI,o=!1,a=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=s,this.yRadius=i,this.aStartAngle=r,this.aEndAngle=n,this.aClockwise=o,this.aRotation=a}getPoint(t,e=new Ks){const s=e,i=2*Math.PI;let r=this.aEndAngle-this.aStartAngle;const n=Math.abs(r)i;)r-=i;r0?0:(Math.floor(Math.abs(h)/r)+1)*r:0===u&&h===r-1&&(h=r-2,u=1),this.closed||h>0?o=i[(h-1)%r]:(rh.subVectors(i[0],i[1]).add(i[0]),o=rh);const l=i[h%r],c=i[(h+1)%r];if(this.closed||h+2i.length-2?i.length-1:n+1],l=i[n>i.length-3?i.length-1:n+2];return s.set(uh(o,a.x,h.x,u.x,l.x),uh(o,a.y,h.y,u.y,l.y)),s}copy(t){super.copy(t),this.points=[];for(let e=0,s=t.points.length;e=s){const t=i[r]-s,n=this.curves[r],o=n.getLength(),a=0===o?0:1-t/o;return n.getPointAt(a,e)}r++}return null}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const t=[];let e=0;for(let s=0,i=this.curves.length;s1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,s=t.curves.length;e0){const t=h.getPoint(0);t.equals(this.currentPoint)||this.lineTo(t.x,t.y)}this.curves.push(h);const u=h.getPoint(1);return this.currentPoint.copy(u),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){const t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}}class _h extends Mn{constructor(t=[new Ks(0,-.5),new Ks(.5,0),new Ks(0,.5)],e=12,s=0,i=2*Math.PI){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:s,phiLength:i},e=Math.floor(e),i=$s(i,0,2*Math.PI);const r=[],n=[],o=[],a=[],h=[],u=1/e,l=new Ei,c=new Ks,d=new Ei,p=new Ei,m=new Ei;let g=0,f=0;for(let e=0;e<=t.length-1;e++)switch(e){case 0:g=t[e+1].x-t[e].x,f=t[e+1].y-t[e].y,d.x=1*f,d.y=-g,d.z=0*f,m.copy(d),d.normalize(),a.push(d.x,d.y,d.z);break;case t.length-1:a.push(m.x,m.y,m.z);break;default:g=t[e+1].x-t[e].x,f=t[e+1].y-t[e].y,d.x=1*f,d.y=-g,d.z=0*f,p.copy(d),d.x+=m.x,d.y+=m.y,d.z+=m.z,d.normalize(),a.push(d.x,d.y,d.z),m.copy(p)}for(let r=0;r<=e;r++){const d=s+r*u*i,p=Math.sin(d),m=Math.cos(d);for(let s=0;s<=t.length-1;s++){l.x=t[s].x*p,l.y=t[s].y,l.z=t[s].x*m,n.push(l.x,l.y,l.z),c.x=r/e,c.y=s/(t.length-1),o.push(c.x,c.y);const i=a[3*s+0]*p,u=a[3*s+1],d=a[3*s+0]*m;h.push(i,u,d)}}for(let s=0;s0&&y(!0),e>0&&y(!1)),this.setIndex(u),this.setAttribute("position",new yn(l,3)),this.setAttribute("normal",new yn(c,3)),this.setAttribute("uv",new yn(d,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Mh(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class Ah extends Mh{constructor(t=1,e=1,s=32,i=1,r=!1,n=0,o=2*Math.PI){super(0,t,e,s,i,r,n,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:s,heightSegments:i,openEnded:r,thetaStart:n,thetaLength:o}}static fromJSON(t){return new Ah(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class Nh extends Mn{constructor(t=[],e=[],s=1,i=0){super(),this.type="PolyhedronGeometry",this.parameters={vertices:t,indices:e,radius:s,detail:i};const r=[],n=[];function o(t,e,s,i){const r=i+1,n=[];for(let i=0;i<=r;i++){n[i]=[];const o=t.clone().lerp(s,i/r),a=e.clone().lerp(s,i/r),h=r-i;for(let t=0;t<=h;t++)n[i][t]=0===t&&i===r?o:o.clone().lerp(a,t/h)}for(let t=0;t.9&&o<.1&&(e<.2&&(n[t+0]+=1),s<.2&&(n[t+2]+=1),i<.2&&(n[t+4]+=1))}}()}(),this.setAttribute("position",new yn(r,3)),this.setAttribute("normal",new yn(r.slice(),3)),this.setAttribute("uv",new yn(n,2)),0===i?this.computeVertexNormals():this.normalizeNormals()}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Nh(t.vertices,t.indices,t.radius,t.details)}}class Rh extends Nh{constructor(t=1,e=0){const s=(1+Math.sqrt(5))/2,i=1/s;super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-i,-s,0,-i,s,0,i,-s,0,i,s,-i,-s,0,-i,s,0,i,-s,0,i,s,0,-s,0,-i,s,0,-i,-s,0,i,s,0,i],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],t,e),this.type="DodecahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new Rh(t.radius,t.detail)}}const Ch=new Ei,Eh=new Ei,Bh=new Ei,Ih=new jr;class Ph extends Mn{constructor(t=null,e=1){if(super(),this.type="EdgesGeometry",this.parameters={geometry:t,thresholdAngle:e},null!==t){const s=4,i=Math.pow(10,s),r=Math.cos(js*e),n=t.getIndex(),o=t.getAttribute("position"),a=n?n.count:o.count,h=[0,0,0],u=["a","b","c"],l=new Array(3),c={},d=[];for(let t=0;t80*s){a=u=t[0],h=l=t[1];for(let e=s;eu&&(u=c),d>l&&(l=d);p=Math.max(u-a,l-h),p=0!==p?32767/p:0}return Lh(n,o,s,a,h,p,0),o};function Oh(t,e,s,i,r){let n,o;if(r===function(t,e,s,i){let r=0;for(let n=e,o=s-i;n0)for(n=e;n=e;n-=i)o=iu(n,t[n],t[n+1],o);return o&&Zh(o,o.next)&&(ru(o),o=o.next),o}function zh(t,e){if(!t)return t;e||(e=t);let s,i=t;do{if(s=!1,i.steiner||!Zh(i,i.next)&&0!==Jh(i.prev,i,i.next))i=i.next;else{if(ru(i),i=e=i.prev,i===i.next)break;s=!0}}while(s||i!==e);return e}function Lh(t,e,s,i,r,n,o){if(!t)return;!o&&n&&function(t,e,s,i){let r=t;do{0===r.z&&(r.z=qh(r.x,r.y,e,s,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){let e,s,i,r,n,o,a,h,u=1;do{for(s=t,t=null,n=null,o=0;s;){for(o++,i=s,a=0,e=0;e0||h>0&&i;)0!==a&&(0===h||!i||s.z<=i.z)?(r=s,s=s.nextZ,a--):(r=i,i=i.nextZ,h--),n?n.nextZ=r:t=r,r.prevZ=n,n=r;s=i}n.nextZ=null,u*=2}while(o>1)}(r)}(t,i,r,n);let a,h,u=t;for(;t.prev!==t.next;)if(a=t.prev,h=t.next,n?Dh(t,i,r,n):Vh(t))e.push(a.i/s|0),e.push(t.i/s|0),e.push(h.i/s|0),ru(t),t=h.next,u=h.next;else if((t=h)===u){o?1===o?Lh(t=kh(zh(t),e,s),e,s,i,r,n,2):2===o&&Gh(t,e,s,i,r,n):Lh(zh(t),e,s,i,r,n,1);break}}function Vh(t){const e=t.prev,s=t,i=t.next;if(Jh(e,s,i)>=0)return!1;const r=e.x,n=s.x,o=i.x,a=e.y,h=s.y,u=i.y,l=rn?r>o?r:o:n>o?n:o,p=a>h?a>u?a:u:h>u?h:u;let m=i.next;for(;m!==e;){if(m.x>=l&&m.x<=d&&m.y>=c&&m.y<=p&&Xh(r,a,n,h,o,u,m.x,m.y)&&Jh(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function Dh(t,e,s,i){const r=t.prev,n=t,o=t.next;if(Jh(r,n,o)>=0)return!1;const a=r.x,h=n.x,u=o.x,l=r.y,c=n.y,d=o.y,p=ah?a>u?a:u:h>u?h:u,f=l>c?l>d?l:d:c>d?c:d,y=qh(p,m,e,s,i),x=qh(g,f,e,s,i);let b=t.prevZ,v=t.nextZ;for(;b&&b.z>=y&&v&&v.z<=x;){if(b.x>=p&&b.x<=g&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&Xh(a,l,h,c,u,d,b.x,b.y)&&Jh(b.prev,b,b.next)>=0)return!1;if(b=b.prevZ,v.x>=p&&v.x<=g&&v.y>=m&&v.y<=f&&v!==r&&v!==o&&Xh(a,l,h,c,u,d,v.x,v.y)&&Jh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}for(;b&&b.z>=y;){if(b.x>=p&&b.x<=g&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&Xh(a,l,h,c,u,d,b.x,b.y)&&Jh(b.prev,b,b.next)>=0)return!1;b=b.prevZ}for(;v&&v.z<=x;){if(v.x>=p&&v.x<=g&&v.y>=m&&v.y<=f&&v!==r&&v!==o&&Xh(a,l,h,c,u,d,v.x,v.y)&&Jh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function kh(t,e,s){let i=t;do{const r=i.prev,n=i.next.next;!Zh(r,n)&&Qh(r,i,i.next,n)&&eu(r,n)&&eu(n,r)&&(e.push(r.i/s|0),e.push(i.i/s|0),e.push(n.i/s|0),ru(i),ru(i.next),i=t=n),i=i.next}while(i!==t);return zh(i)}function Gh(t,e,s,i,r,n){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Yh(o,t)){let a=su(o,t);return o=zh(o,o.next),a=zh(a,a.next),Lh(o,e,s,i,r,n,0),void Lh(a,e,s,i,r,n,0)}t=t.next}o=o.next}while(o!==t)}function Wh(t,e){return t.x-e.x}function jh(t,e){const s=function(t,e){let s,i=e,r=-1/0;const n=t.x,o=t.y;do{if(o<=i.y&&o>=i.next.y&&i.next.y!==i.y){const t=i.x+(o-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(t<=n&&t>r&&(r=t,s=i.x=i.x&&i.x>=h&&n!==i.x&&Xh(os.x||i.x===s.x&&Hh(s,i)))&&(s=i,c=l)),i=i.next}while(i!==a);return s}(t,e);if(!s)return e;const i=su(s,t);return zh(i,i.next),zh(s,s.next)}function Hh(t,e){return Jh(t.prev,t,e.prev)<0&&Jh(e.next,t,t.next)<0}function qh(t,e,s,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-s)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function $h(t){let e=t,s=t;do{(e.x=(t-o)*(n-a)&&(t-o)*(i-a)>=(s-o)*(e-a)&&(s-o)*(n-a)>=(r-o)*(i-a)}function Yh(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let s=t;do{if(s.i!==t.i&&s.next.i!==t.i&&s.i!==e.i&&s.next.i!==e.i&&Qh(s,s.next,t,e))return!0;s=s.next}while(s!==t);return!1}(t,e)&&(eu(t,e)&&eu(e,t)&&function(t,e){let s=t,i=!1;const r=(t.x+e.x)/2,n=(t.y+e.y)/2;do{s.y>n!=s.next.y>n&&s.next.y!==s.y&&r<(s.next.x-s.x)*(n-s.y)/(s.next.y-s.y)+s.x&&(i=!i),s=s.next}while(s!==t);return i}(t,e)&&(Jh(t.prev,t,e.prev)||Jh(t,e.prev,e))||Zh(t,e)&&Jh(t.prev,t,t.next)>0&&Jh(e.prev,e,e.next)>0)}function Jh(t,e,s){return(e.y-t.y)*(s.x-e.x)-(e.x-t.x)*(s.y-e.y)}function Zh(t,e){return t.x===e.x&&t.y===e.y}function Qh(t,e,s,i){const r=tu(Jh(t,e,s)),n=tu(Jh(t,e,i)),o=tu(Jh(s,i,t)),a=tu(Jh(s,i,e));return r!==n&&o!==a||(!(0!==r||!Kh(t,s,e))||(!(0!==n||!Kh(t,i,e))||(!(0!==o||!Kh(s,t,i))||!(0!==a||!Kh(s,e,i)))))}function Kh(t,e,s){return e.x<=Math.max(t.x,s.x)&&e.x>=Math.min(t.x,s.x)&&e.y<=Math.max(t.y,s.y)&&e.y>=Math.min(t.y,s.y)}function tu(t){return t>0?1:t<0?-1:0}function eu(t,e){return Jh(t.prev,t,t.next)<0?Jh(t,e,t.next)>=0&&Jh(t,t.prev,e)>=0:Jh(t,e,t.prev)<0||Jh(t,t.next,e)<0}function su(t,e){const s=new nu(t.i,t.x,t.y),i=new nu(e.i,e.x,e.y),r=t.next,n=e.prev;return t.next=e,e.prev=t,s.next=r,r.prev=s,i.next=s,s.prev=i,n.next=i,i.prev=n,i}function iu(t,e,s,i){const r=new nu(t,e,s);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function ru(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function nu(t,e,s){this.i=t,this.x=e,this.y=s,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}class ou{static area(t){const e=t.length;let s=0;for(let i=e-1,r=0;r2&&t[e-1].equals(t[0])&&t.pop()}function hu(t,e){for(let s=0;sNumber.EPSILON){const c=Math.sqrt(l),d=Math.sqrt(h*h+u*u),p=e.x-a/c,m=e.y+o/c,g=((s.x-u/d-p)*u-(s.y+h/d-m)*h)/(o*u-a*h);i=p+o*g-t.x,r=m+a*g-t.y;const f=i*i+r*r;if(f<=2)return new Ks(i,r);n=Math.sqrt(f/2)}else{let t=!1;o>Number.EPSILON?h>Number.EPSILON&&(t=!0):o<-Number.EPSILON?h<-Number.EPSILON&&(t=!0):Math.sign(a)===Math.sign(u)&&(t=!0),t?(i=-a,r=o,n=Math.sqrt(l)):(i=o,r=a,n=Math.sqrt(l/2))}return new Ks(i/n,r/n)}const B=[];for(let t=0,e=A.length,s=e-1,i=t+1;t=0;t--){const e=t/p,s=l*Math.cos(e*Math.PI/2),i=c*Math.sin(e*Math.PI/2)+d;for(let t=0,e=A.length;t=0;){const i=s;let r=s-1;r<0&&(r=t.length-1);for(let t=0,s=a+2*p;t0)&&d.push(e,r,h),(t!==s-1||a0!=t>0&&this.version++,this._anisotropy=t}get clearcoat(){return this._clearcoat}set clearcoat(t){this._clearcoat>0!=t>0&&this.version++,this._clearcoat=t}get iridescence(){return this._iridescence}set iridescence(t){this._iridescence>0!=t>0&&this.version++,this._iridescence=t}get dispersion(){return this._dispersion}set dispersion(t){this._dispersion>0!=t>0&&this.version++,this._dispersion=t}get sheen(){return this._sheen}set sheen(t){this._sheen>0!=t>0&&this.version++,this._sheen=t}get transmission(){return this._transmission}set transmission(t){this._transmission>0!=t>0&&this.version++,this._transmission=t}copy(t){return super.copy(t),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=t.anisotropy,this.anisotropyRotation=t.anisotropyRotation,this.anisotropyMap=t.anisotropyMap,this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.dispersion=t.dispersion,this.ior=t.ior,this.iridescence=t.iridescence,this.iridescenceMap=t.iridescenceMap,this.iridescenceIOR=t.iridescenceIOR,this.iridescenceThicknessRange=[...t.iridescenceThicknessRange],this.iridescenceThicknessMap=t.iridescenceThicknessMap,this.sheen=t.sheen,this.sheenColor.copy(t.sheenColor),this.sheenColorMap=t.sheenColorMap,this.sheenRoughness=t.sheenRoughness,this.sheenRoughnessMap=t.sheenRoughnessMap,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this.thickness=t.thickness,this.thicknessMap=t.thicknessMap,this.attenuationDistance=t.attenuationDistance,this.attenuationColor.copy(t.attenuationColor),this.specularIntensity=t.specularIntensity,this.specularIntensityMap=t.specularIntensityMap,this.specularColor.copy(t.specularColor),this.specularColorMap=t.specularColorMap,this}}class Ru extends Qr{constructor(t){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new Yr(16777215),this.specular=new Yr(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Yr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fr,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.specular.copy(t.specular),this.shininess=t.shininess,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Cu extends Qr{constructor(t){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new Yr(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Yr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.gradientMap=t.gradientMap,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}class Eu extends Qr{constructor(t){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.flatShading=t.flatShading,this}}class Bu extends Qr{constructor(t){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new Yr(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Yr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fr,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Iu extends Qr{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=3200,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class Pu extends Qr{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}class Fu extends Qr{constructor(t){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new Yr(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={MATCAP:""},this.color.copy(t.color),this.matcap=t.matcap,this.map=t.map,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Uu extends Ma{constructor(t){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(t)}copy(t){return super.copy(t),this.scale=t.scale,this.dashSize=t.dashSize,this.gapSize=t.gapSize,this}}function Ou(t,e,s){return!t||!s&&t.constructor===e?t:"number"==typeof e.BYTES_PER_ELEMENT?new e(t):Array.prototype.slice.call(t)}function zu(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function Lu(t){const e=t.length,s=new Array(e);for(let t=0;t!==e;++t)s[t]=t;return s.sort((function(e,s){return t[e]-t[s]})),s}function Vu(t,e,s){const i=t.length,r=new t.constructor(i);for(let n=0,o=0;o!==i;++n){const i=s[n]*e;for(let s=0;s!==e;++s)r[o++]=t[i+s]}return r}function Du(t,e,s,i){let r=1,n=t[0];for(;void 0!==n&&void 0===n[i];)n=t[r++];if(void 0===n)return;let o=n[i];if(void 0!==o)if(Array.isArray(o))do{o=n[i],void 0!==o&&(e.push(n.time),s.push.apply(s,o)),n=t[r++]}while(void 0!==n);else if(void 0!==o.toArray)do{o=n[i],void 0!==o&&(e.push(n.time),o.toArray(s,s.length)),n=t[r++]}while(void 0!==n);else do{o=n[i],void 0!==o&&(e.push(n.time),s.push(o)),n=t[r++]}while(void 0!==n)}const ku={convertArray:Ou,isTypedArray:zu,getKeyframeOrder:Lu,sortedArray:Vu,flattenJSON:Du,subclip:function(t,e,s,i,r=30){const n=t.clone();n.name=e;const o=[];for(let t=0;t=i)){h.push(e.times[t]);for(let s=0;sn.tracks[t].times[0]&&(a=n.tracks[t].times[0]);for(let t=0;t=i.times[c]){const t=c*h+a,e=t+h-a;d=i.values.slice(t,e)}else{const t=i.createInterpolant(),e=a,s=h-a;t.evaluate(n),d=t.resultBuffer.slice(e,s)}if("quaternion"===r){(new Ci).fromArray(d).normalize().conjugate().toArray(d)}const p=o.times.length;for(let t=0;t=r)break t;{const o=e[1];t=r)break e}n=s,s=0}}for(;s>>1;te;)--n;if(++n,0!==r||n!==i){r>=n&&(n=Math.max(n,1),r=n-1);const t=this.getValueSize();this.times=s.slice(r,n),this.values=this.values.slice(r*t,n*t)}return this}validate(){let t=!0;const e=this.getValueSize();e-Math.floor(e)!=0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),t=!1);const s=this.times,i=this.values,r=s.length;0===r&&(console.error("THREE.KeyframeTrack: Track is empty.",this),t=!1);let n=null;for(let e=0;e!==r;e++){const i=s[e];if("number"==typeof i&&isNaN(i)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,e,i),t=!1;break}if(null!==n&&n>i){console.error("THREE.KeyframeTrack: Out of order keys.",this,e,i,n),t=!1;break}n=i}if(void 0!==i&&zu(i))for(let e=0,s=i.length;e!==s;++e){const s=i[e];if(isNaN(s)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,e,s),t=!1;break}}return t}optimize(){const t=this.times.slice(),e=this.values.slice(),s=this.getValueSize(),i=this.getInterpolation()===Fe,r=t.length-1;let n=1;for(let o=1;o0){t[n]=t[r];for(let t=r*s,i=n*s,o=0;o!==s;++o)e[i+o]=e[t+o];++n}return n!==t.length?(this.times=t.slice(0,n),this.values=e.slice(0,n*s)):(this.times=t,this.values=e),this}clone(){const t=this.times.slice(),e=this.values.slice(),s=new(0,this.constructor)(this.name,t,e);return s.createInterpolant=this.createInterpolant,s}}qu.prototype.TimeBufferType=Float32Array,qu.prototype.ValueBufferType=Float32Array,qu.prototype.DefaultInterpolation=Pe;class $u extends qu{constructor(t,e,s){super(t,e,s)}}$u.prototype.ValueTypeName="bool",$u.prototype.ValueBufferType=Array,$u.prototype.DefaultInterpolation=Ie,$u.prototype.InterpolantFactoryMethodLinear=void 0,$u.prototype.InterpolantFactoryMethodSmooth=void 0;class Xu extends qu{}Xu.prototype.ValueTypeName="color";class Yu extends qu{}Yu.prototype.ValueTypeName="number";class Ju extends Gu{constructor(t,e,s,i){super(t,e,s,i)}interpolate_(t,e,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=(s-e)/(i-e);let h=t*o;for(let t=h+o;h!==t;h+=4)Ci.slerpFlat(r,0,n,h-o,n,h,a);return r}}class Zu extends qu{InterpolantFactoryMethodLinear(t){return new Ju(this.times,this.values,this.getValueSize(),t)}}Zu.prototype.ValueTypeName="quaternion",Zu.prototype.InterpolantFactoryMethodSmooth=void 0;class Qu extends qu{constructor(t,e,s){super(t,e,s)}}Qu.prototype.ValueTypeName="string",Qu.prototype.ValueBufferType=Array,Qu.prototype.DefaultInterpolation=Ie,Qu.prototype.InterpolantFactoryMethodLinear=void 0,Qu.prototype.InterpolantFactoryMethodSmooth=void 0;class Ku extends qu{}Ku.prototype.ValueTypeName="vector";class tl{constructor(t="",e=-1,s=[],i=2500){this.name=t,this.tracks=s,this.duration=e,this.blendMode=i,this.uuid=qs(),this.duration<0&&this.resetDuration()}static parse(t){const e=[],s=t.tracks,i=1/(t.fps||1);for(let t=0,r=s.length;t!==r;++t)e.push(el(s[t]).scale(i));const r=new this(t.name,t.duration,e,t.blendMode);return r.uuid=t.uuid,r}static toJSON(t){const e=[],s=t.tracks,i={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode};for(let t=0,i=s.length;t!==i;++t)e.push(qu.toJSON(s[t]));return i}static CreateFromMorphTargetSequence(t,e,s,i){const r=e.length,n=[];for(let t=0;t1){const t=n[1];let e=i[t];e||(i[t]=e=[]),e.push(s)}}const n=[];for(const t in i)n.push(this.CreateFromMorphTargetSequence(t,i[t],e,s));return n}static parseAnimation(t,e){if(!t)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;const s=function(t,e,s,i,r){if(0!==s.length){const n=[],o=[];Du(s,n,o,i),0!==n.length&&r.push(new t(e,n,o))}},i=[],r=t.name||"default",n=t.fps||30,o=t.blendMode;let a=t.length||-1;const h=t.hierarchy||[];for(let t=0;t{e&&e(r),this.manager.itemEnd(t)}),0),r;if(void 0!==ol[t])return void ol[t].push({onLoad:e,onProgress:s,onError:i});ol[t]=[],ol[t].push({onLoad:e,onProgress:s,onError:i});const n=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),o=this.mimeType,a=this.responseType;fetch(n).then((e=>{if(200===e.status||0===e.status){if(0===e.status&&console.warn("THREE.FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===e.body||void 0===e.body.getReader)return e;const s=ol[t],i=e.body.getReader(),r=e.headers.get("X-File-Size")||e.headers.get("Content-Length"),n=r?parseInt(r):0,o=0!==n;let a=0;const h=new ReadableStream({start(t){!function e(){i.read().then((({done:i,value:r})=>{if(i)t.close();else{a+=r.byteLength;const i=new ProgressEvent("progress",{lengthComputable:o,loaded:a,total:n});for(let t=0,e=s.length;t{t.error(e)}))}()}});return new Response(h)}throw new al(`fetch for "${e.url}" responded with ${e.status}: ${e.statusText}`,e)})).then((t=>{switch(a){case"arraybuffer":return t.arrayBuffer();case"blob":return t.blob();case"document":return t.text().then((t=>(new DOMParser).parseFromString(t,o)));case"json":return t.json();default:if(void 0===o)return t.text();{const e=/charset="?([^;"\s]*)"?/i.exec(o),s=e&&e[1]?e[1].toLowerCase():void 0,i=new TextDecoder(s);return t.arrayBuffer().then((t=>i.decode(t)))}}})).then((e=>{sl.add(t,e);const s=ol[t];delete ol[t];for(let t=0,i=s.length;t{const s=ol[t];if(void 0===s)throw this.manager.itemError(t),e;delete ol[t];for(let t=0,i=s.length;t{this.manager.itemEnd(t)})),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}}class ul extends nl{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new hl(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(s){try{e(r.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),r.manager.itemError(t)}}),s,i)}parse(t){const e=[];for(let s=0;s0:i.vertexColors=t.vertexColors),void 0!==t.uniforms)for(const e in t.uniforms){const r=t.uniforms[e];switch(i.uniforms[e]={},r.type){case"t":i.uniforms[e].value=s(r.value);break;case"c":i.uniforms[e].value=(new Yr).setHex(r.value);break;case"v2":i.uniforms[e].value=(new Ks).fromArray(r.value);break;case"v3":i.uniforms[e].value=(new Ei).fromArray(r.value);break;case"v4":i.uniforms[e].value=(new _i).fromArray(r.value);break;case"m3":i.uniforms[e].value=(new ti).fromArray(r.value);break;case"m4":i.uniforms[e].value=(new or).fromArray(r.value);break;default:i.uniforms[e].value=r.value}}if(void 0!==t.defines&&(i.defines=t.defines),void 0!==t.vertexShader&&(i.vertexShader=t.vertexShader),void 0!==t.fragmentShader&&(i.fragmentShader=t.fragmentShader),void 0!==t.glslVersion&&(i.glslVersion=t.glslVersion),void 0!==t.extensions)for(const e in t.extensions)i.extensions[e]=t.extensions[e];if(void 0!==t.lights&&(i.lights=t.lights),void 0!==t.clipping&&(i.clipping=t.clipping),void 0!==t.size&&(i.size=t.size),void 0!==t.sizeAttenuation&&(i.sizeAttenuation=t.sizeAttenuation),void 0!==t.map&&(i.map=s(t.map)),void 0!==t.matcap&&(i.matcap=s(t.matcap)),void 0!==t.alphaMap&&(i.alphaMap=s(t.alphaMap)),void 0!==t.bumpMap&&(i.bumpMap=s(t.bumpMap)),void 0!==t.bumpScale&&(i.bumpScale=t.bumpScale),void 0!==t.normalMap&&(i.normalMap=s(t.normalMap)),void 0!==t.normalMapType&&(i.normalMapType=t.normalMapType),void 0!==t.normalScale){let e=t.normalScale;!1===Array.isArray(e)&&(e=[e,e]),i.normalScale=(new Ks).fromArray(e)}return void 0!==t.displacementMap&&(i.displacementMap=s(t.displacementMap)),void 0!==t.displacementScale&&(i.displacementScale=t.displacementScale),void 0!==t.displacementBias&&(i.displacementBias=t.displacementBias),void 0!==t.roughnessMap&&(i.roughnessMap=s(t.roughnessMap)),void 0!==t.metalnessMap&&(i.metalnessMap=s(t.metalnessMap)),void 0!==t.emissiveMap&&(i.emissiveMap=s(t.emissiveMap)),void 0!==t.emissiveIntensity&&(i.emissiveIntensity=t.emissiveIntensity),void 0!==t.specularMap&&(i.specularMap=s(t.specularMap)),void 0!==t.specularIntensityMap&&(i.specularIntensityMap=s(t.specularIntensityMap)),void 0!==t.specularColorMap&&(i.specularColorMap=s(t.specularColorMap)),void 0!==t.envMap&&(i.envMap=s(t.envMap)),void 0!==t.envMapRotation&&i.envMapRotation.fromArray(t.envMapRotation),void 0!==t.envMapIntensity&&(i.envMapIntensity=t.envMapIntensity),void 0!==t.reflectivity&&(i.reflectivity=t.reflectivity),void 0!==t.refractionRatio&&(i.refractionRatio=t.refractionRatio),void 0!==t.lightMap&&(i.lightMap=s(t.lightMap)),void 0!==t.lightMapIntensity&&(i.lightMapIntensity=t.lightMapIntensity),void 0!==t.aoMap&&(i.aoMap=s(t.aoMap)),void 0!==t.aoMapIntensity&&(i.aoMapIntensity=t.aoMapIntensity),void 0!==t.gradientMap&&(i.gradientMap=s(t.gradientMap)),void 0!==t.clearcoatMap&&(i.clearcoatMap=s(t.clearcoatMap)),void 0!==t.clearcoatRoughnessMap&&(i.clearcoatRoughnessMap=s(t.clearcoatRoughnessMap)),void 0!==t.clearcoatNormalMap&&(i.clearcoatNormalMap=s(t.clearcoatNormalMap)),void 0!==t.clearcoatNormalScale&&(i.clearcoatNormalScale=(new Ks).fromArray(t.clearcoatNormalScale)),void 0!==t.iridescenceMap&&(i.iridescenceMap=s(t.iridescenceMap)),void 0!==t.iridescenceThicknessMap&&(i.iridescenceThicknessMap=s(t.iridescenceThicknessMap)),void 0!==t.transmissionMap&&(i.transmissionMap=s(t.transmissionMap)),void 0!==t.thicknessMap&&(i.thicknessMap=s(t.thicknessMap)),void 0!==t.anisotropyMap&&(i.anisotropyMap=s(t.anisotropyMap)),void 0!==t.sheenColorMap&&(i.sheenColorMap=s(t.sheenColorMap)),void 0!==t.sheenRoughnessMap&&(i.sheenRoughnessMap=s(t.sheenRoughnessMap)),i}setTextures(t){return this.textures=t,this}static createMaterialFromType(t){return new{ShadowMaterial:Su,SpriteMaterial:uo,RawShaderMaterial:Mu,ShaderMaterial:$n,PointsMaterial:Va,MeshPhysicalMaterial:Nu,MeshStandardMaterial:Au,MeshPhongMaterial:Ru,MeshToonMaterial:Cu,MeshNormalMaterial:Eu,MeshLambertMaterial:Bu,MeshDepthMaterial:Iu,MeshDistanceMaterial:Pu,MeshBasicMaterial:Kr,MeshMatcapMaterial:Fu,LineDashedMaterial:Uu,LineBasicMaterial:Ma,Material:Qr}[t]}}class Ol{static decodeText(t){if(console.warn("THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead."),"undefined"!=typeof TextDecoder)return(new TextDecoder).decode(t);let e="";for(let s=0,i=t.length;s0){const s=new il(e);r=new cl(s),r.setCrossOrigin(this.crossOrigin);for(let e=0,s=t.length;e0){i=new cl(this.manager),i.setCrossOrigin(this.crossOrigin);for(let e=0,i=t.length;e{const e=new Pi;e.min.fromArray(t.boxMin),e.max.fromArray(t.boxMax);const s=new Zi;return s.radius=t.sphereRadius,s.center.fromArray(t.sphereCenter),{boxInitialized:t.boxInitialized,box:e,sphereInitialized:t.sphereInitialized,sphere:s}})),n._maxInstanceCount=t.maxInstanceCount,n._maxVertexCount=t.maxVertexCount,n._maxIndexCount=t.maxIndexCount,n._geometryInitialized=t.geometryInitialized,n._geometryCount=t.geometryCount,n._matricesTexture=l(t.matricesTexture.uuid),void 0!==t.colorsTexture&&(n._colorsTexture=l(t.colorsTexture.uuid));break;case"LOD":n=new Ro;break;case"Line":n=new Pa(h(t.geometry),u(t.material));break;case"LineLoop":n=new La(h(t.geometry),u(t.material));break;case"LineSegments":n=new za(h(t.geometry),u(t.material));break;case"PointCloud":case"Points":n=new ja(h(t.geometry),u(t.material));break;case"Sprite":n=new So(u(t.material));break;case"Group":n=new qa;break;case"Bone":n=new Vo;break;default:n=new Pr}if(n.uuid=t.uuid,void 0!==t.name&&(n.name=t.name),void 0!==t.matrix?(n.matrix.fromArray(t.matrix),void 0!==t.matrixAutoUpdate&&(n.matrixAutoUpdate=t.matrixAutoUpdate),n.matrixAutoUpdate&&n.matrix.decompose(n.position,n.quaternion,n.scale)):(void 0!==t.position&&n.position.fromArray(t.position),void 0!==t.rotation&&n.rotation.fromArray(t.rotation),void 0!==t.quaternion&&n.quaternion.fromArray(t.quaternion),void 0!==t.scale&&n.scale.fromArray(t.scale)),void 0!==t.up&&n.up.fromArray(t.up),void 0!==t.castShadow&&(n.castShadow=t.castShadow),void 0!==t.receiveShadow&&(n.receiveShadow=t.receiveShadow),t.shadow&&(void 0!==t.shadow.intensity&&(n.shadow.intensity=t.shadow.intensity),void 0!==t.shadow.bias&&(n.shadow.bias=t.shadow.bias),void 0!==t.shadow.normalBias&&(n.shadow.normalBias=t.shadow.normalBias),void 0!==t.shadow.radius&&(n.shadow.radius=t.shadow.radius),void 0!==t.shadow.mapSize&&n.shadow.mapSize.fromArray(t.shadow.mapSize),void 0!==t.shadow.camera&&(n.shadow.camera=this.parseObject(t.shadow.camera))),void 0!==t.visible&&(n.visible=t.visible),void 0!==t.frustumCulled&&(n.frustumCulled=t.frustumCulled),void 0!==t.renderOrder&&(n.renderOrder=t.renderOrder),void 0!==t.userData&&(n.userData=t.userData),void 0!==t.layers&&(n.layers.mask=t.layers),void 0!==t.children){const o=t.children;for(let t=0;t{e&&e(s),r.manager.itemEnd(t)})).catch((t=>{i&&i(t)})):(setTimeout((function(){e&&e(n),r.manager.itemEnd(t)}),0),n);const o={};o.credentials="anonymous"===this.crossOrigin?"same-origin":"include",o.headers=this.requestHeader;const a=fetch(t,o).then((function(t){return t.blob()})).then((function(t){return createImageBitmap(t,Object.assign(r.options,{colorSpaceConversion:"none"}))})).then((function(s){return sl.add(t,s),e&&e(s),r.manager.itemEnd(t),s})).catch((function(e){i&&i(e),sl.remove(t),r.manager.itemError(t),r.manager.itemEnd(t)}));sl.add(t,a),r.manager.itemStart(t)}}let jl;class Hl{static getContext(){return void 0===jl&&(jl=new(window.AudioContext||window.webkitAudioContext)),jl}static setContext(t){jl=t}}class ql extends nl{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new hl(this.manager);function o(e){i?i(e):console.error(e),r.manager.itemError(t)}n.setResponseType("arraybuffer"),n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(t){try{const s=t.slice(0);Hl.getContext().decodeAudioData(s,(function(t){e(t)})).catch(o)}catch(t){o(t)}}),s,i)}}const $l=new or,Xl=new or,Yl=new or;class Jl{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Qn,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Qn,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(t){const e=this._cache;if(e.focus!==t.focus||e.fov!==t.fov||e.aspect!==t.aspect*this.aspect||e.near!==t.near||e.far!==t.far||e.zoom!==t.zoom||e.eyeSep!==this.eyeSep){e.focus=t.focus,e.fov=t.fov,e.aspect=t.aspect*this.aspect,e.near=t.near,e.far=t.far,e.zoom=t.zoom,e.eyeSep=this.eyeSep,Yl.copy(t.projectionMatrix);const s=e.eyeSep/2,i=s*e.near/e.focus,r=e.near*Math.tan(js*e.fov*.5)/e.zoom;let n,o;Xl.elements[12]=-s,$l.elements[12]=s,n=-r*e.aspect+i,o=r*e.aspect+i,Yl.elements[0]=2*e.near/(o-n),Yl.elements[8]=(o+n)/(o-n),this.cameraL.projectionMatrix.copy(Yl),n=-r*e.aspect-i,o=r*e.aspect-i,Yl.elements[0]=2*e.near/(o-n),Yl.elements[8]=(o+n)/(o-n),this.cameraR.projectionMatrix.copy(Yl)}this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(Xl),this.cameraR.matrixWorld.copy(t.matrixWorld).multiply($l)}}class Zl extends Qn{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class Ql{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=Kl(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){const e=Kl();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function Kl(){return("undefined"==typeof performance?Date:performance).now()}const tc=new Ei,ec=new Ci,sc=new Ei,ic=new Ei;class rc extends Pr{constructor(){super(),this.type="AudioListener",this.context=Hl.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new Ql}getInput(){return this.gain}removeFilter(){return null!==this.filter&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this}getFilter(){return this.filter}setFilter(t){return null!==this.filter?(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)):this.gain.disconnect(this.context.destination),this.filter=t,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}updateMatrixWorld(t){super.updateMatrixWorld(t);const e=this.context.listener,s=this.up;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(tc,ec,sc),ic.set(0,0,-1).applyQuaternion(ec),e.positionX){const t=this.context.currentTime+this.timeDelta;e.positionX.linearRampToValueAtTime(tc.x,t),e.positionY.linearRampToValueAtTime(tc.y,t),e.positionZ.linearRampToValueAtTime(tc.z,t),e.forwardX.linearRampToValueAtTime(ic.x,t),e.forwardY.linearRampToValueAtTime(ic.y,t),e.forwardZ.linearRampToValueAtTime(ic.z,t),e.upX.linearRampToValueAtTime(s.x,t),e.upY.linearRampToValueAtTime(s.y,t),e.upZ.linearRampToValueAtTime(s.z,t)}else e.setPosition(tc.x,tc.y,tc.z),e.setOrientation(ic.x,ic.y,ic.z,s.x,s.y,s.z)}}class nc extends Pr{constructor(t){super(),this.type="Audio",this.listener=t,this.context=t.context,this.gain=this.context.createGain(),this.gain.connect(t.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.offset=0,this.duration=void 0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.source=null,this.sourceType="empty",this._startedAt=0,this._progress=0,this._connected=!1,this.filters=[]}getOutput(){return this.gain}setNodeSource(t){return this.hasPlaybackControl=!1,this.sourceType="audioNode",this.source=t,this.connect(),this}setMediaElementSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaNode",this.source=this.context.createMediaElementSource(t),this.connect(),this}setMediaStreamSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaStreamNode",this.source=this.context.createMediaStreamSource(t),this.connect(),this}setBuffer(t){return this.buffer=t,this.sourceType="buffer",this.autoplay&&this.play(),this}play(t=0){if(!0===this.isPlaying)return void console.warn("THREE.Audio: Audio is already playing.");if(!1===this.hasPlaybackControl)return void console.warn("THREE.Audio: this Audio has no playback control.");this._startedAt=this.context.currentTime+t;const e=this.context.createBufferSource();return e.buffer=this.buffer,e.loop=this.loop,e.loopStart=this.loopStart,e.loopEnd=this.loopEnd,e.onended=this.onEnded.bind(this),e.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=e,this.setDetune(this.detune),this.setPlaybackRate(this.playbackRate),this.connect()}pause(){if(!1!==this.hasPlaybackControl)return!0===this.isPlaying&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,!0===this.loop&&(this._progress=this._progress%(this.duration||this.buffer.duration)),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this;console.warn("THREE.Audio: this Audio has no playback control.")}stop(){if(!1!==this.hasPlaybackControl)return this._progress=0,null!==this.source&&(this.source.stop(),this.source.onended=null),this.isPlaying=!1,this;console.warn("THREE.Audio: this Audio has no playback control.")}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(let t=1,e=this.filters.length;t0){this.source.disconnect(this.filters[0]);for(let t=1,e=this.filters.length;t0&&this._mixBufferRegionAdditive(s,i,this._addIndex*e,1,e);for(let t=e,r=e+e;t!==r;++t)if(s[t]!==s[t+e]){o.setValue(s,i);break}}saveOriginalState(){const t=this.binding,e=this.buffer,s=this.valueSize,i=s*this._origIndex;t.getValue(e,i);for(let t=s,r=i;t!==r;++t)e[t]=e[i+t%s];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const t=3*this.valueSize;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){const t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let s=t;s=.5)for(let i=0;i!==r;++i)t[e+i]=t[s+i]}_slerp(t,e,s,i){Ci.slerpFlat(t,e,t,e,t,s,i)}_slerpAdditive(t,e,s,i,r){const n=this._workIndex*r;Ci.multiplyQuaternionsFlat(t,n,t,e,t,s),Ci.slerpFlat(t,e,t,e,t,n,i)}_lerp(t,e,s,i,r){const n=1-i;for(let o=0;o!==r;++o){const r=e+o;t[r]=t[r]*n+t[s+o]*i}}_lerpAdditive(t,e,s,i,r){for(let n=0;n!==r;++n){const r=e+n;t[r]=t[r]+t[s+n]*i}}}const pc="\\[\\]\\.:\\/",mc=new RegExp("["+pc+"]","g"),gc="[^"+pc+"]",fc="[^"+pc.replace("\\.","")+"]",yc=new RegExp("^"+/((?:WC+[\/:])*)/.source.replace("WC",gc)+/(WCOD+)?/.source.replace("WCOD",fc)+/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",gc)+/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",gc)+"$"),xc=["material","materials","bones","map"];class bc{constructor(t,e,s){this.path=e,this.parsedPath=s||bc.parseTrackName(e),this.node=bc.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,s){return t&&t.isAnimationObjectGroup?new bc.Composite(t,e,s):new bc(t,e,s)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(mc,"")}static parseTrackName(t){const e=yc.exec(t);if(null===e)throw new Error("PropertyBinding: Cannot parse trackName: "+t);const s={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},i=s.nodeName&&s.nodeName.lastIndexOf(".");if(void 0!==i&&-1!==i){const t=s.nodeName.substring(i+1);-1!==xc.indexOf(t)&&(s.nodeName=s.nodeName.substring(0,i),s.objectName=t)}if(null===s.propertyName||0===s.propertyName.length)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return s}static findNode(t,e){if(void 0===e||""===e||"."===e||-1===e||e===t.name||e===t.uuid)return t;if(t.skeleton){const s=t.skeleton.getBoneByName(e);if(void 0!==s)return s}if(t.children){const s=function(t){for(let i=0;i=r){const n=r++,u=t[n];e[u.uuid]=h,t[h]=u,e[a]=n,t[n]=o;for(let t=0,e=i;t!==e;++t){const e=s[t],i=e[n],r=e[h];e[h]=i,e[n]=r}}}this.nCachedObjects_=r}uncache(){const t=this._objects,e=this._indicesByUUID,s=this._bindings,i=s.length;let r=this.nCachedObjects_,n=t.length;for(let o=0,a=arguments.length;o!==a;++o){const a=arguments[o].uuid,h=e[a];if(void 0!==h)if(delete e[a],h0&&(e[o.uuid]=h),t[h]=o,t.pop();for(let t=0,e=i;t!==e;++t){const e=s[t];e[h]=e[r],e.pop()}}}this.nCachedObjects_=r}subscribe_(t,e){const s=this._bindingsIndicesByPath;let i=s[t];const r=this._bindings;if(void 0!==i)return r[i];const n=this._paths,o=this._parsedPaths,a=this._objects,h=a.length,u=this.nCachedObjects_,l=new Array(h);i=r.length,s[t]=i,n.push(t),o.push(e),r.push(l);for(let s=u,i=a.length;s!==i;++s){const i=a[s];l[s]=new bc(i,t,e)}return l}unsubscribe_(t){const e=this._bindingsIndicesByPath,s=e[t];if(void 0!==s){const i=this._paths,r=this._parsedPaths,n=this._bindings,o=n.length-1,a=n[o];e[t[o]]=s,n[s]=a,n.pop(),r[s]=r[o],r.pop(),i[s]=i[o],i.pop()}}}class Tc{constructor(t,e,s=null,i=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=s,this.blendMode=i;const r=e.tracks,n=r.length,o=new Array(n),a={endingStart:Ue,endingEnd:Ue};for(let t=0;t!==n;++t){const e=r[t].createInterpolant(null);o[t]=e,e.settings=a}this._interpolantSettings=a,this._interpolants=o,this._propertyBindings=new Array(n),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=2201,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&0!==this.timeScale&&null===this._startTime&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(t){return this._startTime=t,this}setLoop(t,e){return this.loop=t,this.repetitions=e,this}setEffectiveWeight(t){return this.weight=t,this._effectiveWeight=this.enabled?t:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(t){return this._scheduleFading(t,0,1)}fadeOut(t){return this._scheduleFading(t,1,0)}crossFadeFrom(t,e,s){if(t.fadeOut(e),this.fadeIn(e),s){const s=this._clip.duration,i=t._clip.duration,r=i/s,n=s/i;t.warp(1,r,e),this.warp(n,1,e)}return this}crossFadeTo(t,e,s){return t.crossFadeFrom(this,e,s)}stopFading(){const t=this._weightInterpolant;return null!==t&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}setEffectiveTimeScale(t){return this.timeScale=t,this._effectiveTimeScale=this.paused?0:t,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(t){return this.timeScale=this._clip.duration/t,this.stopWarping()}syncWith(t){return this.time=t.time,this.timeScale=t.timeScale,this.stopWarping()}halt(t){return this.warp(this._effectiveTimeScale,0,t)}warp(t,e,s){const i=this._mixer,r=i.time,n=this.timeScale;let o=this._timeScaleInterpolant;null===o&&(o=i._lendControlInterpolant(),this._timeScaleInterpolant=o);const a=o.parameterPositions,h=o.sampleValues;return a[0]=r,a[1]=r+s,h[0]=t/n,h[1]=e/n,this}stopWarping(){const t=this._timeScaleInterpolant;return null!==t&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(t,e,s,i){if(!this.enabled)return void this._updateWeight(t);const r=this._startTime;if(null!==r){const i=(t-r)*s;i<0||0===s?e=0:(this._startTime=null,e=s*i)}e*=this._updateTimeScale(t);const n=this._updateTime(e),o=this._updateWeight(t);if(o>0){const t=this._interpolants,e=this._propertyBindings;if(this.blendMode===Ve)for(let s=0,i=t.length;s!==i;++s)t[s].evaluate(n),e[s].accumulateAdditive(o);else for(let s=0,r=t.length;s!==r;++s)t[s].evaluate(n),e[s].accumulate(i,o)}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const s=this._weightInterpolant;if(null!==s){const i=s.evaluate(t)[0];e*=i,t>s.parameterPositions[1]&&(this.stopFading(),0===i&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;const s=this._timeScaleInterpolant;if(null!==s){e*=s.evaluate(t)[0],t>s.parameterPositions[1]&&(this.stopWarping(),0===e?this.paused=!0:this.timeScale=e)}}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,s=this.loop;let i=this.time+t,r=this._loopCount;const n=2202===s;if(0===t)return-1===r?i:n&&1==(1&r)?e-i:i;if(2200===s){-1===r&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(i>=e)i=e;else{if(!(i<0)){this.time=i;break t}i=0}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(-1===r&&(t>=0?(r=0,this._setEndings(!0,0===this.repetitions,n)):this._setEndings(0===this.repetitions,!0,n)),i>=e||i<0){const s=Math.floor(i/e);i-=e*s,r+=Math.abs(s);const o=this.repetitions-r;if(o<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,i=t>0?e:0,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(1===o){const e=t<0;this._setEndings(e,!e,n)}else this._setEndings(!1,!1,n);this._loopCount=r,this.time=i,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:s})}}else this.time=i;if(n&&1==(1&r))return e-i}return i}_setEndings(t,e,s){const i=this._interpolantSettings;s?(i.endingStart=Oe,i.endingEnd=Oe):(i.endingStart=t?this.zeroSlopeAtStart?Oe:Ue:ze,i.endingEnd=e?this.zeroSlopeAtEnd?Oe:Ue:ze)}_scheduleFading(t,e,s){const i=this._mixer,r=i.time;let n=this._weightInterpolant;null===n&&(n=i._lendControlInterpolant(),this._weightInterpolant=n);const o=n.parameterPositions,a=n.sampleValues;return o[0]=r,a[0]=e,o[1]=r+t,a[1]=s,this}}const _c=new Float32Array(1);class wc extends ks{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(t,e){const s=t._localRoot||this._root,i=t._clip.tracks,r=i.length,n=t._propertyBindings,o=t._interpolants,a=s.uuid,h=this._bindingsByRootAndName;let u=h[a];void 0===u&&(u={},h[a]=u);for(let t=0;t!==r;++t){const r=i[t],h=r.name;let l=u[h];if(void 0!==l)++l.referenceCount,n[t]=l;else{if(l=n[t],void 0!==l){null===l._cacheIndex&&(++l.referenceCount,this._addInactiveBinding(l,a,h));continue}const i=e&&e._propertyBindings[t].binding.parsedPath;l=new dc(bc.create(s,h,i),r.ValueTypeName,r.getValueSize()),++l.referenceCount,this._addInactiveBinding(l,a,h),n[t]=l}o[t].resultBuffer=l.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(null===t._cacheIndex){const e=(t._localRoot||this._root).uuid,s=t._clip.uuid,i=this._actionsByClip[s];this._bindAction(t,i&&i.knownActions[0]),this._addInactiveAction(t,s,e)}const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==s.useCount++&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==--s.useCount&&(s.restoreOriginalState(),this._takeBackBinding(s))}this._takeBackAction(t)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}}_isActiveAction(t){const e=t._cacheIndex;return null!==e&&e=0;--e)t[e].stop();return this}update(t){t*=this.timeScale;const e=this._actions,s=this._nActiveActions,i=this.time+=t,r=Math.sign(t),n=this._accuIndex^=1;for(let o=0;o!==s;++o){e[o]._update(i,t,r,n)}const o=this._bindings,a=this._nActiveBindings;for(let t=0;t!==a;++t)o[t].apply(n);return this}setTime(t){this.time=0;for(let t=0;tthis.max.x||t.ythis.max.y)}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(t){return!(t.max.xthis.max.x||t.max.ythis.max.y)}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Uc).distanceTo(t)}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const zc=new Ei,Lc=new Ei;class Vc{constructor(t=new Ei,e=new Ei){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){zc.subVectors(t,this.start),Lc.subVectors(this.end,this.start);const s=Lc.dot(Lc);let i=Lc.dot(zc)/s;return e&&(i=$s(i,0,1)),i}closestPointToPoint(t,e,s){const i=this.closestPointToPointParameter(t,e);return this.delta(s).multiplyScalar(i).add(this.start)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return(new this.constructor).copy(this)}}const Dc=new Ei;class kc extends Pr{constructor(t,e){super(),this.light=t,this.matrixAutoUpdate=!1,this.color=e,this.type="SpotLightHelper";const s=new Mn,i=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(let t=0,e=1,s=32;t1)for(let s=0;s.99999)this.quaternion.set(0,0,0,1);else if(t.y<-.99999)this.quaternion.set(1,0,0,0);else{dd.set(t.z,0,-t.x).normalize();const e=Math.acos(t.y);this.quaternion.setFromAxisAngle(dd,e)}}setLength(t,e=.2*t,s=.2*e){this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(s,e,s),this.cone.position.y=t,this.cone.updateMatrix()}setColor(t){this.line.material.color.set(t),this.cone.material.color.set(t)}copy(t){return super.copy(t,!1),this.line.copy(t.line),this.cone.copy(t.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}}class fd extends za{constructor(t=1){const e=[0,0,0,t,0,0,0,0,0,0,t,0,0,0,0,0,0,t],s=new Mn;s.setAttribute("position",new yn(e,3)),s.setAttribute("color",new yn([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],3));super(s,new Ma({vertexColors:!0,toneMapped:!1})),this.type="AxesHelper"}setColors(t,e,s){const i=new Yr,r=this.geometry.attributes.color.array;return i.set(t),i.toArray(r,0),i.toArray(r,3),i.set(e),i.toArray(r,6),i.toArray(r,9),i.set(s),i.toArray(r,12),i.toArray(r,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class yd{constructor(){this.type="ShapePath",this.color=new Yr,this.subPaths=[],this.currentPath=null}moveTo(t,e){return this.currentPath=new Th,this.subPaths.push(this.currentPath),this.currentPath.moveTo(t,e),this}lineTo(t,e){return this.currentPath.lineTo(t,e),this}quadraticCurveTo(t,e,s,i){return this.currentPath.quadraticCurveTo(t,e,s,i),this}bezierCurveTo(t,e,s,i,r,n){return this.currentPath.bezierCurveTo(t,e,s,i,r,n),this}splineThru(t){return this.currentPath.splineThru(t),this}toShapes(t){function e(t,e){const s=e.length;let i=!1;for(let r=s-1,n=0;nNumber.EPSILON){if(h<0&&(s=e[n],a=-a,o=e[r],h=-h),t.yo.y)continue;if(t.y===s.y){if(t.x===s.x)return!0}else{const e=h*(t.x-s.x)-a*(t.y-s.y);if(0===e)return!0;if(e<0)continue;i=!i}}else{if(t.y!==s.y)continue;if(o.x<=t.x&&t.x<=s.x||s.x<=t.x&&t.x<=o.x)return!0}}return i}const s=ou.isClockWise,i=this.subPaths;if(0===i.length)return[];let r,n,o;const a=[];if(1===i.length)return n=i[0],o=new Fh,o.curves=n.curves,a.push(o),a;let h=!s(i[0].getPoints());h=t?!h:h;const u=[],l=[];let c,d,p=[],m=0;l[m]=void 0,p[m]=[];for(let e=0,o=i.length;e1){let t=!1,s=0;for(let t=0,e=l.length;t0&&!1===t&&(p=u)}for(let t=0,e=l.length;t{this.requestId=self.requestAnimationFrame(t),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this.animationLoop&&this.animationLoop(e,s)};t()}dispose(){self.cancelAnimationFrame(this.requestId),this.requestId=null}setAnimationLoop(t){this.animationLoop=t}}class _d{constructor(){this.weakMap=new WeakMap}get(t){let e=this.weakMap;for(let s=0;s{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(t){const e=this.material;let s=this.clippingContext;Array.isArray(e.clippingPlanes)?(s!==t&&s||(s=new Md,this.clippingContext=s),s.update(t,e)):this.clippingContext!==t&&(this.clippingContext=t)}get clippingNeedsUpdate(){return this.clippingContext.version!==this.clippingContextVersion&&(this.clippingContextVersion=this.clippingContext.version,!0)}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}getAttributes(){if(null!==this.attributes)return this.attributes;const t=this.getNodeBuilderState().nodeAttributes,e=this.geometry,s=[],i=new Set;for(const r of t){const t=r.node&&r.node.attribute?r.node.attribute:e.getAttribute(r.name);if(void 0===t)continue;s.push(t);const n=t.isInterleavedBufferAttribute?t.data:t;i.add(n)}return this.attributes=s,this.vertexBuffers=Array.from(i.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getMaterialCacheKey(){const{object:t,material:e}=this;let s=e.customProgramCacheKey();for(const t of function(t){const e=Object.keys(t);let s=Object.getPrototypeOf(t);for(;s;){const t=Object.getOwnPropertyDescriptors(s);for(const s in t)if(void 0!==t[s]){const i=t[s];i&&"function"==typeof i.get&&e.push(s)}s=Object.getPrototypeOf(s)}return e}(e)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(t))continue;const i=e[t];let r;if(null!==i){const t=typeof i;"number"===t?r=0!==i?"1":"0":"object"===t&&(r="{",i.isTexture&&(r+=i.mapping),r+="}")}else r=String(i);s+=r+","}return s+=this.clippingContextVersion+",",t.skeleton&&(s+=t.skeleton.bones.length+","),t.morphTargetInfluences&&(s+=t.morphTargetInfluences.length+","),t.isBatchedMesh&&(s+=t._matricesTexture.uuid+",",null!==t._colorsTexture&&(s+=t._colorsTexture.uuid+",")),t.count>1&&(s+=t.count+","),s}get needsUpdate(){return this.initialNodesCacheKey!==this.getNodesCacheKey()||this.clippingNeedsUpdate}getNodesCacheKey(){return this._nodes.getCacheKey(this.scene,this.lightsNode)}getCacheKey(){return this.getMaterialCacheKey()+","+this.getNodesCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}class Rd{constructor(t,e,s,i,r,n){this.renderer=t,this.nodes=e,this.geometries=s,this.pipelines=i,this.bindings=r,this.info=n,this.chainMaps={}}get(t,e,s,i,r,n,o){const a=this.getChainMap(o),h=[t,e,n,r];let u=a.get(h);return void 0===u?(u=this.createRenderObject(this.nodes,this.geometries,this.renderer,t,e,s,i,r,n,o),a.set(h,u)):(u.updateClipping(n.clippingContext),(u.version!==e.version||u.needsUpdate)&&(u.initialCacheKey!==u.getCacheKey()?(u.dispose(),u=this.get(t,e,s,i,r,n,o)):u.version=e.version)),u}getChainMap(t="default"){return this.chainMaps[t]||(this.chainMaps[t]=new _d)}dispose(){this.chainMaps={}}createRenderObject(t,e,s,i,r,n,o,a,h,u){const l=this.getChainMap(u),c=new Nd(t,e,s,i,r,n,o,a,h);return c.onDispose=()=>{this.pipelines.delete(c),this.bindings.delete(c),this.nodes.delete(c),l.delete(c.getChainArray())},c}}class Cd{constructor(){this.data=new WeakMap}get(t){let e=this.data.get(t);return void 0===e&&(e={},this.data.set(t,e)),e}delete(t){let e;return this.data.has(t)&&(e=this.data.get(t),this.data.delete(t)),e}has(t){return this.data.has(t)}dispose(){this.data=new WeakMap}}const Ed=1,Bd=2,Id=4,Pd=16;class Fd extends Cd{constructor(t){super(),this.backend=t}delete(t){const e=super.delete(t);return void 0!==e&&this.backend.destroyAttribute(t),e}update(t,e){const s=this.get(t);if(void 0===s.version)e===Ed?this.backend.createAttribute(t):e===Bd?this.backend.createIndexAttribute(t):e===Id&&this.backend.createStorageAttribute(t),s.version=this._getBufferAttribute(t).version;else{const e=this._getBufferAttribute(t);(s.version=0;--e)if(t[e]>=65535)return!0;return!1}(e)?gn:pn)(e,1);return r.version=Ud(t),r}class zd extends Cd{constructor(t,e){super(),this.attributes=t,this.info=e,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(t){const e=t.geometry;return super.has(e)&&!0===this.get(e).initialized}updateForRender(t){!1===this.has(t)&&this.initGeometry(t),this.updateAttributes(t)}initGeometry(t){const e=t.geometry;this.get(e).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const i=e.index,r=t.getAttributes();null!==i&&this.attributes.delete(i);for(const t of r)this.attributes.delete(t);const n=this.wireframes.get(e);void 0!==n&&this.attributes.delete(n),e.removeEventListener("dispose",s)};e.addEventListener("dispose",s)}updateAttributes(t){const e=t.getAttributes();for(const t of e)t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute?this.updateAttribute(t,Id):this.updateAttribute(t,Ed);const s=this.getIndex(t);null!==s&&this.updateAttribute(s,Bd)}updateAttribute(t,e){const s=this.info.render.calls;t.isInterleavedBufferAttribute?void 0===this.attributeCall.get(t)?(this.attributes.update(t,e),this.attributeCall.set(t,s)):this.attributeCall.get(t.data)!==s&&(this.attributes.update(t,e),this.attributeCall.set(t.data,s),this.attributeCall.set(t,s)):this.attributeCall.get(t)!==s&&(this.attributes.update(t,e),this.attributeCall.set(t,s))}getIndex(t){const{geometry:e,material:s}=t;let i=e.index;if(!0===s.wireframe){const t=this.wireframes;let s=t.get(e);void 0===s?(s=Od(e),t.set(e,s)):s.version!==Ud(e)&&(this.attributes.delete(s),s=Od(e),t.set(e,s)),i=s}return i}}class Ld{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(t,e,s){this.render.drawCalls++,t.isMesh||t.isSprite?this.render.triangles+=s*(e/3):t.isPoints?this.render.points+=s*e:t.isLineSegments?this.render.lines+=s*(e/2):t.isLine?this.render.lines+=s*(e-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(t,e){0===this[t].timestampCalls&&(this[t].timestamp=0),this[t].timestamp+=e,this[t].timestampCalls++,this[t].timestampCalls>=this[t].previousFrameCalls&&(this[t].timestampCalls=0)}reset(){const t=this.render.frameCalls;this.render.previousFrameCalls=t;const e=this.compute.frameCalls;this.compute.previousFrameCalls=e,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class Vd{constructor(t){this.cacheKey=t,this.usedTimes=0}}class Dd extends Vd{constructor(t,e,s){super(t),this.vertexProgram=e,this.fragmentProgram=s}}class kd extends Vd{constructor(t,e){super(t),this.computeProgram=e,this.isComputePipeline=!0}}let Gd=0;class Wd{constructor(t,e,s=null,i=null){this.id=Gd++,this.code=t,this.stage=e,this.transforms=s,this.attributes=i,this.usedTimes=0}}class jd extends Cd{constructor(t,e){super(),this.backend=t,this.nodes=e,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(t,e){const{backend:s}=this,i=this.get(t);if(this._needsComputeUpdate(t)){const r=i.pipeline;r&&(r.usedTimes--,r.computeProgram.usedTimes--);const n=this.nodes.getForCompute(t);let o=this.programs.compute.get(n.computeShader);void 0===o&&(r&&0===r.computeProgram.usedTimes&&this._releaseProgram(r.computeProgram),o=new Wd(n.computeShader,"compute",n.transforms,n.nodeAttributes),this.programs.compute.set(n.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(t,o);let h=this.caches.get(a);void 0===h&&(r&&0===r.usedTimes&&this._releasePipeline(r),h=this._getComputePipeline(t,o,a,e)),h.usedTimes++,o.usedTimes++,i.version=t.version,i.pipeline=h}return i.pipeline}getForRender(t,e=null){const{backend:s}=this,i=this.get(t);if(this._needsRenderUpdate(t)){const r=i.pipeline;r&&(r.usedTimes--,r.vertexProgram.usedTimes--,r.fragmentProgram.usedTimes--);const n=t.getNodeBuilderState();let o=this.programs.vertex.get(n.vertexShader);void 0===o&&(r&&0===r.vertexProgram.usedTimes&&this._releaseProgram(r.vertexProgram),o=new Wd(n.vertexShader,"vertex"),this.programs.vertex.set(n.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(n.fragmentShader);void 0===a&&(r&&0===r.fragmentProgram.usedTimes&&this._releaseProgram(r.fragmentProgram),a=new Wd(n.fragmentShader,"fragment"),this.programs.fragment.set(n.fragmentShader,a),s.createProgram(a));const h=this._getRenderCacheKey(t,o,a);let u=this.caches.get(h);void 0===u?(r&&0===r.usedTimes&&this._releasePipeline(r),u=this._getRenderPipeline(t,o,a,h,e)):t.pipeline=u,u.usedTimes++,o.usedTimes++,a.usedTimes++,i.pipeline=u}return i.pipeline}delete(t){const e=this.get(t).pipeline;return e&&(e.usedTimes--,0===e.usedTimes&&this._releasePipeline(e),e.isComputePipeline?(e.computeProgram.usedTimes--,0===e.computeProgram.usedTimes&&this._releaseProgram(e.computeProgram)):(e.fragmentProgram.usedTimes--,e.vertexProgram.usedTimes--,0===e.vertexProgram.usedTimes&&this._releaseProgram(e.vertexProgram),0===e.fragmentProgram.usedTimes&&this._releaseProgram(e.fragmentProgram))),super.delete(t)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(t){this.getForRender(t)}_getComputePipeline(t,e,s,i){s=s||this._getComputeCacheKey(t,e);let r=this.caches.get(s);return void 0===r&&(r=new kd(s,e),this.caches.set(s,r),this.backend.createComputePipeline(r,i)),r}_getRenderPipeline(t,e,s,i,r){i=i||this._getRenderCacheKey(t,e,s);let n=this.caches.get(i);return void 0===n&&(n=new Dd(i,e,s),this.caches.set(i,n),t.pipeline=n,this.backend.createRenderPipeline(t,r)),n}_getComputeCacheKey(t,e){return t.id+","+e.id}_getRenderCacheKey(t,e,s){return e.id+","+s.id+","+this.backend.getRenderCacheKey(t)}_releasePipeline(t){this.caches.delete(t.cacheKey)}_releaseProgram(t){const e=t.code,s=t.stage;this.programs[s].delete(e)}_needsComputeUpdate(t){const e=this.get(t);return void 0===e.pipeline||e.version!==t.version}_needsRenderUpdate(t){return void 0===this.get(t).pipeline||this.backend.needsRenderUpdate(t)}}class Hd extends Cd{constructor(t,e,s,i,r,n){super(),this.backend=t,this.textures=s,this.pipelines=r,this.attributes=i,this.nodes=e,this.info=n,this.pipelines.bindings=this}getForRender(t){const e=t.getBindings();for(const t of e){const s=this.get(t);void 0===s.bindGroup&&(this._init(t),this.backend.createBindings(t,e),s.bindGroup=t)}return e}getForCompute(t){const e=this.nodes.getForCompute(t).bindings;for(const t of e){const s=this.get(t);void 0===s.bindGroup&&(this._init(t),this.backend.createBindings(t,e),s.bindGroup=t)}return e}updateForCompute(t){this._updateBindings(t,this.getForCompute(t))}updateForRender(t){this._updateBindings(t,this.getForRender(t))}_updateBindings(t,e){for(const s of e)this._update(t,s,e)}_init(t){for(const e of t.bindings)if(e.isSampledTexture)this.textures.updateTexture(e.texture);else if(e.isStorageBuffer){const t=e.attribute;this.attributes.update(t,Id)}}_update(t,e,s){const{backend:i}=this;let r=!1;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&i.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=t.texture;t.needsBindingsUpdate&&(r=!0);const s=t.update();s&&this.textures.updateTexture(t.texture);const n=i.get(t.texture);if(!0===i.isWebGPUBackend&&void 0===n.texture&&void 0===n.externalTexture&&(console.error("Bindings._update: binding should be available:",t,s,t.texture,t.textureNode.value),this.textures.updateTexture(t.texture),r=!0),!0===e.isStorageTexture){const s=this.get(e);!0===t.store?s.needsMipmap=!0:!0===e.generateMipmaps&&this.textures.needsMipmaps(e)&&!0===s.needsMipmap&&(this.backend.generateMipmaps(e),s.needsMipmap=!1)}}}if(!0===r){const i=this.pipelines.getForRender(t);this.backend.updateBindings(e,s,i)}}}const qd={VERTEX:"vertex",FRAGMENT:"fragment"},$d={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Xd={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Yd=["fragment","vertex"],Jd=["setup","analyze","generate"],Zd=[...Yd,"compute"],Qd=["x","y","z","w"];function Kd(t,e=!1){let s="{";!0===t.isNode&&(s+=t.id);for(const{property:i,childNode:r}of tp(t))s+=","+i.slice(0,-4)+":"+r.getCacheKey(e);return s+="}",s}function*tp(t,e=!1){for(const s in t){if(!0===s.startsWith("_"))continue;const i=t[s];if(!0===Array.isArray(i))for(let t=0;tt.charCodeAt(0))).buffer}var np=Object.freeze({__proto__:null,arrayBufferToBase64:ip,base64ToArrayBuffer:rp,getCacheKey:Kd,getNodeChildren:tp,getValueFromType:sp,getValueType:ep});const op=new Map;let ap=0;class hp extends ks{constructor(t=null){super(),this.nodeType=t,this.updateType=$d.NONE,this.updateBeforeType=$d.NONE,this.updateAfterType=$d.NONE,this.uuid=Qs.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:ap++})}set needsUpdate(t){!0===t&&this.version++}get type(){return this.constructor.type}onUpdate(t,e){return this.updateType=e,this.update=t.bind(this.getSelf()),this}onFrameUpdate(t){return this.onUpdate(t,$d.FRAME)}onRenderUpdate(t){return this.onUpdate(t,$d.RENDER)}onObjectUpdate(t){return this.onUpdate(t,$d.OBJECT)}onReference(t){return this.updateReference=t.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:t}of tp(this))yield t}dispose(){this.dispatchEvent({type:"dispose"})}traverse(t){t(this);for(const e of this.getChildren())e.traverse(t)}getCacheKey(t=!1){return!0!==(t=t||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=Kd(this,t),this._cacheKeyVersion=this.version),this._cacheKey}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(t){const e=this.getNodeType(t);return t.getElementType(e)}getNodeType(t){const e=t.getNodeProperties(this);return e.outputNode?e.outputNode.getNodeType(t):this.nodeType}getShared(t){const e=this.getHash(t);return t.getNodeFromHash(e)||this}setup(t){const e=t.getNodeProperties(this);let s=0;for(const t of this.getChildren())e["node"+s++]=t;return null}construct(t){return console.warn("THREE.Node: construct() is deprecated. Use setup() instead."),this.setup(t)}increaseUsage(t){const e=t.getDataFromNode(this);return e.usageCount=void 0===e.usageCount?1:e.usageCount+1,e.usageCount}analyze(t){if(1===this.increaseUsage(t)){const e=t.getNodeProperties(this);for(const s of Object.values(e))s&&!0===s.isNode&&s.build(t)}}generate(t,e){const{outputNode:s}=t.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(t,e)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(t,e=null){const s=this.getShared(t);if(this!==s)return s.build(t,e);t.addNode(this),t.addChain(this);let i=null;const r=t.getBuildStage();if("setup"===r){this.updateReference(t);const e=t.getNodeProperties(this);if(!0!==e.initialized){const s=t.stack.nodes.length;e.initialized=!0,e.outputNode=this.setup(t),null!==e.outputNode&&t.stack.nodes.length!==s&&(e.outputNode=t.stack);for(const s of Object.values(e))s&&!0===s.isNode&&s.build(t)}}else if("analyze"===r)this.analyze(t);else if("generate"===r){if(1===this.generate.length){const s=this.getNodeType(t),r=t.getDataFromNode(this);i=r.snippet,void 0===i&&(i=this.generate(t)||"",r.snippet=i),i=t.format(i,s,e)}else i=this.generate(t,e)||""}return t.removeChain(this),i}getSerializeChildren(){return tp(this)}serialize(t){const e=this.getSerializeChildren(),s={};for(const{property:i,index:r,childNode:n}of e)void 0!==r?(void 0===s[i]&&(s[i]=Number.isInteger(r)?[]:{}),s[i][r]=n.toJSON(t.meta).uuid):s[i]=n.toJSON(t.meta).uuid;Object.keys(s).length>0&&(t.inputNodes=s)}deserialize(t){if(void 0!==t.inputNodes){const e=t.meta.nodes;for(const s in t.inputNodes)if(Array.isArray(t.inputNodes[s])){const i=[];for(const r of t.inputNodes[s])i.push(e[r]);this[s]=i}else if("object"==typeof t.inputNodes[s]){const i={};for(const r in t.inputNodes[s]){const n=t.inputNodes[s][r];i[r]=e[n]}this[s]=i}else{const i=t.inputNodes[s];this[s]=e[i]}}}toJSON(t){const{uuid:e,type:s}=this,i=void 0===t||"string"==typeof t;i&&(t={textures:{},images:{},nodes:{}});let r=t.nodes[e];function n(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(void 0===r&&(r={uuid:e,type:s,meta:t,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==i&&(t.nodes[r.uuid]=r),this.serialize(r),delete r.meta),i){const e=n(t.textures),s=n(t.images),i=n(t.nodes);e.length>0&&(r.textures=e),s.length>0&&(r.images=s),i.length>0&&(r.nodes=i)}return r}}function up(t,e){if("function"!=typeof e||!t)throw new Error(`Node class ${t} is not a class`);op.has(t)?console.warn(`Redefinition of node class ${t}`):(op.set(t,e),e.type=t)}function lp(t){const e=op.get(t);if(void 0!==e)return new e}class cp extends hp{constructor(t){super(t),this.isTempNode=!0}hasDependencies(t){return t.getDataFromNode(this).usageCount>1}build(t,e){if("generate"===t.getBuildStage()){const s=t.getVectorType(this.getNodeType(t,e)),i=t.getDataFromNode(this);if(void 0!==i.propertyName)return t.format(i.propertyName,s,e);if("void"!==s&&"void"!==e&&this.hasDependencies(t)){const r=super.build(t,s),n=t.getVarFromNode(this,null,s),o=t.getPropertyName(n);return t.addLineFlowCode(`${o} = ${r}`),i.snippet=r,i.propertyName=o,t.format(i.propertyName,s,e)}}return super.build(t,e)}}up("TempNode",cp);class dp extends hp{constructor(t,e){super(),this.node=t,this.indexNode=e,this.isArrayElementNode=!0}getNodeType(t){return this.node.getElementType(t)}generate(t){return`${this.node.build(t)}[ ${this.indexNode.build(t,"uint")} ]`}}up("ArrayElementNode",dp);class pp extends hp{constructor(t,e){super(),this.node=t,this.convertTo=e}getNodeType(t){const e=this.node.getNodeType(t);let s=null;for(const i of this.convertTo.split("|"))null!==s&&t.getTypeLength(e)!==t.getTypeLength(i)||(s=i);return s}serialize(t){super.serialize(t),t.convertTo=this.convertTo}deserialize(t){super.deserialize(t),this.convertTo=t.convertTo}generate(t,e){const s=this.node,i=this.getNodeType(t),r=s.build(t,i);return t.format(r,i,e)}}up("ConvertNode",pp);class mp extends cp{constructor(t=[],e=null){super(e),this.nodes=t}getNodeType(t){return null!==this.nodeType?t.getVectorType(this.nodeType):t.getTypeFromLength(this.nodes.reduce(((e,s)=>e+t.getTypeLength(s.getNodeType(t))),0))}generate(t,e){const s=this.getNodeType(t),i=this.nodes,r=t.getComponentType(s),n=[];for(const e of i){let s=e.build(t);const i=t.getComponentType(e.getNodeType(t));i!==r&&(s=t.format(s,i,r)),n.push(s)}const o=`${t.getType(s)}( ${n.join(", ")} )`;return t.format(o,s,e)}}up("JoinNode",mp);const gp=Qd.join("");class fp extends hp{constructor(t,e="x"){super(),this.node=t,this.components=e,this.isSplitNode=!0}getVectorLength(){let t=this.components.length;for(const e of this.components)t=Math.max(Qd.indexOf(e)+1,t);return t}getComponentType(t){return t.getComponentType(this.node.getNodeType(t))}getNodeType(t){return t.getTypeFromLength(this.components.length,this.getComponentType(t))}generate(t,e){const s=this.node,i=t.getTypeLength(s.getNodeType(t));let r=null;if(i>1){let n=null;this.getVectorLength()>=i&&(n=t.getTypeFromLength(this.getVectorLength(),this.getComponentType(t)));const o=s.build(t,n);r=this.components.length===i&&this.components===gp.slice(0,this.components.length)?t.format(o,n,e):t.format(`${o}.${this.components}`,this.getNodeType(t),e)}else r=s.build(t,e);return r}serialize(t){super.serialize(t),t.components=this.components}deserialize(t){super.deserialize(t),this.components=t.components}}up("SplitNode",fp);class yp extends cp{constructor(t,e,s){super(),this.sourceNode=t,this.components=e,this.targetNode=s}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{sourceNode:e,components:s,targetNode:i}=this,r=this.getNodeType(t),n=t.getTypeFromLength(s.length),o=i.build(t,n),a=e.build(t,r),h=t.getTypeLength(r),u=[];for(let t=0;tt.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Sp={setup(t,e){const s=e.shift();return t(Yp(s),...e)},get(t,e,s){if("string"==typeof e&&void 0===t[e]){if(!0!==t.isStackNode&&"assign"===e)return(...t)=>(vp.assign(s,...t),s);if(Tp.has(e)){const i=Tp.get(e);return t.isStackNode?(...t)=>s.add(i(...t)):(...t)=>i(s,...t)}if("self"===e)return t;if(e.endsWith("Assign")&&Tp.has(e.slice(0,e.length-6))){const i=Tp.get(e.slice(0,e.length-6));return t.isStackNode?(...t)=>s.assign(t[0],i(...t)):(...t)=>s.assign(i(s,...t))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(e))return e=wp(e),Xp(new fp(s,e));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(e))return e=(e=wp(e.slice(3).toLowerCase())).split("").sort().join(""),s=>Xp(new yp(t,e,s));if("width"===e||"height"===e||"depth"===e)return"width"===e?e="x":"height"===e?e="y":"depth"===e&&(e="z"),Xp(new fp(t,e));if(!0===/^\d+$/.test(e))return Xp(new dp(s,new bp(Number(e),"uint")))}return Reflect.get(t,e,s)},set:(t,e,s,i)=>"string"!=typeof e||void 0!==t[e]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(e)&&"width"!==e&&"height"!==e&&"depth"!==e&&!0!==/^\d+$/.test(e)?Reflect.set(t,e,s,i):(i[e].assign(s),!0)},Mp=new WeakMap,Ap=new WeakMap,Np=function(t,e=null){for(const s in t)t[s]=Xp(t[s],e);return t},Rp=function(t,e=null){const s=t.length;for(let i=0;iXp(null!==i?Object.assign(t,i):t);return null===e?(...e)=>r(new t(...Jp(e))):null!==s?(s=Xp(s),(...i)=>r(new t(e,...Jp(i),s))):(...s)=>r(new t(e,...Jp(s)))},Ep=function(t,...e){return Xp(new t(...Jp(e)))};class Bp extends hp{constructor(t,e){super(),this.shaderNode=t,this.inputNodes=e}getNodeType(t){const e=t.getNodeProperties(this);return null===e.outputNode&&(e.outputNode=this.setupOutput(t)),e.outputNode.getNodeType(t)}call(t){const{shaderNode:e,inputNodes:s}=this;if(e.layout){let i=Ap.get(t.constructor);void 0===i&&(i=new WeakMap,Ap.set(t.constructor,i));let r=i.get(e);return void 0===r&&(r=Xp(t.buildFunctionNode(e)),i.set(e,r)),null!==t.currentFunctionNode&&t.currentFunctionNode.includes.push(r),Xp(r.call(s))}const i=e.jsFunc,r=null!==s?i(s,t.stack,t):i(t.stack,t);return Xp(r)}setup(t){const{outputNode:e}=t.getNodeProperties(this);return e||this.setupOutput(t)}setupOutput(t){return t.addStack(),t.stack.outputNode=this.call(t),t.removeStack()}generate(t,e){const{outputNode:s}=t.getNodeProperties(this);return null===s?this.call(t).build(t,e):super.generate(t,e)}}class Ip extends hp{constructor(t){super(),this.jsFunc=t,this.layout=null,this.global=!0}get isArrayInput(){return/^\((\s+)?\[/.test(this.jsFunc.toString())}setLayout(t){return this.layout=t,this}call(t=null){return Yp(t),Xp(new Bp(this,t))}setup(){return this.call()}}const Pp=[!1,!0],Fp=[0,1,2,3],Up=[-1,-2],Op=[.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],zp=new Map;for(const t of Pp)zp.set(t,new bp(t));const Lp=new Map;for(const t of Fp)Lp.set(t,new bp(t,"uint"));const Vp=new Map([...Lp].map((t=>new bp(t.value,"int"))));for(const t of Up)Vp.set(t,new bp(t,"int"));const Dp=new Map([...Vp].map((t=>new bp(t.value))));for(const t of Op)Dp.set(t,new bp(t));for(const t of Op)Dp.set(-t,new bp(-t));const kp={bool:zp,uint:Lp,ints:Vp,float:Dp},Gp=new Map([...zp,...Dp]),Wp=(t,e)=>Gp.has(t)?Gp.get(t):!0===t.isNode?t:new bp(t,e),jp=function(t,e=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(t)&&s.every((t=>"object"!=typeof t)))&&(s=[sp(t,...s)]),1===s.length&&null!==e&&e.has(s[0]))return Xp(e.get(s[0]));if(1===s.length){const e=Wp(s[0],t);return(t=>{try{return t.getNodeType()}catch(t){return}})(e)===t?Xp(e):Xp(new pp(e,t))}const i=s.map((t=>Wp(t)));return Xp(new mp(i,t))}},Hp=t=>t&&t.value,qp=t=>null!=t?t.nodeType||t.convertTo||("string"==typeof t?t:null):null;function $p(t){return new Proxy(new Ip(t),Sp)}const Xp=(t,e=null)=>function(t,e=null){const s=ep(t);if("node"===s){let e=Mp.get(t);return void 0===e&&(e=new Proxy(t,Sp),Mp.set(t,e),Mp.set(e,e)),e}return null===e&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?Xp(Wp(t,e)):"shader"===s?Kp(t):t}(t,e),Yp=(t,e=null)=>new Np(t,e),Jp=(t,e=null)=>new Rp(t,e),Zp=(...t)=>new Cp(...t),Qp=(...t)=>new Ep(...t),Kp=t=>{const e=new $p(t),s=(...t)=>{let s;return Yp(t),s=t[0]&&t[0].isNode?[...t]:t[0],e.call(s)};return s.shaderNode=e,s.setLayout=t=>(e.setLayout(t),s),s};up("ShaderNode",$p),_p("toGlobal",(t=>(t.global=!0,t)));const tm=t=>{vp=t},em=()=>vp,sm=(...t)=>vp.if(...t);function im(t){return vp&&vp.add(t),t}_p("append",im);const rm=new jp("color"),nm=new jp("float",kp.float),om=new jp("int",kp.ints),am=new jp("uint",kp.uint),hm=new jp("bool",kp.bool),um=new jp("vec2"),lm=new jp("ivec2"),cm=new jp("uvec2"),dm=new jp("bvec2"),pm=new jp("vec3"),mm=new jp("ivec3"),gm=new jp("uvec3"),fm=new jp("bvec3"),ym=new jp("vec4"),xm=new jp("ivec4"),bm=new jp("uvec4"),vm=new jp("bvec4"),Tm=new jp("mat2"),_m=new jp("imat2"),wm=new jp("umat2"),Sm=new jp("bmat2"),Mm=new jp("mat3"),Am=new jp("imat3"),Nm=new jp("umat3"),Rm=new jp("bmat3"),Cm=new jp("mat4"),Em=new jp("imat4"),Bm=new jp("umat4"),Im=new jp("bmat4"),Pm=(t="")=>Xp(new bp(t,"string")),Fm=t=>Xp(new bp(t,"ArrayBuffer"));_p("toColor",rm),_p("toFloat",nm),_p("toInt",om),_p("toUint",am),_p("toBool",hm),_p("toVec2",um),_p("toIvec2",lm),_p("toUvec2",cm),_p("toBvec2",dm),_p("toVec3",pm),_p("toIvec3",mm),_p("toUvec3",gm),_p("toBvec3",fm),_p("toVec4",ym),_p("toIvec4",xm),_p("toUvec4",bm),_p("toBvec4",vm),_p("toMat2",Tm),_p("toImat2",_m),_p("toUmat2",wm),_p("toBmat2",Sm),_p("toMat3",Mm),_p("toImat3",Am),_p("toUmat3",Nm),_p("toBmat3",Rm),_p("toMat4",Cm),_p("toImat4",Em),_p("toUmat4",Bm),_p("toBmat4",Im);const Um=Zp(dp),Om=(t,e)=>Xp(new pp(Xp(t),e)),zm=(t,e)=>Xp(new fp(Xp(t),e));_p("element",Um),_p("convert",Om);class Lm extends cp{constructor(t,e){super(),this.targetNode=t,this.sourceNode=e}hasDependencies(){return!1}getNodeType(t,e){return"void"!==e?this.targetNode.getNodeType(t):"void"}needsSplitAssign(t){const{targetNode:e}=this;if(!1===t.isAvailable("swizzleAssign")&&e.isSplitNode&&e.components.length>1){const s=t.getTypeLength(e.node.getNodeType(t));return Qd.join("").slice(0,s)!==e.components}return!1}generate(t,e){const{targetNode:s,sourceNode:i}=this,r=this.needsSplitAssign(t),n=s.getNodeType(t),o=s.context({assign:!0}).build(t),a=i.build(t,n),h=i.getNodeType(t),u=t.getDataFromNode(this);let l;if(!0===u.initialized)"void"!==e&&(l=o);else if(r){const i=t.getVarFromNode(this,null,n),r=t.getPropertyName(i);t.addLineFlowCode(`${r} = ${a}`);const h=s.node.context({assign:!0}).build(t);for(let e=0;eXp(new Gm(t,e,Xp(s)));up("AttributeNode",Gm);class jm extends hp{constructor(t,e){super(),this.isBypassNode=!0,this.outputNode=t,this.callNode=e}getNodeType(t){return this.outputNode.getNodeType(t)}generate(t){const e=this.callNode.build(t,"void");return""!==e&&t.addLineFlowCode(e),this.outputNode.build(t)}}const Hm=Zp(jm);_p("bypass",Hm),up("BypassNode",jm);class qm extends hp{constructor(t,e=!0){super(),this.node=t,this.parent=e,this.isCacheNode=!0}getNodeType(t){return this.node.getNodeType(t)}build(t,...e){const s=t.getCache(),i=t.getCacheFromNode(this,parent);t.setCache(i);const r=this.node.build(t,...e);return t.setCache(s),r}}const $m=(t,...e)=>Xp(new qm(Xp(t),...e));_p("cache",$m),up("CacheNode",qm);class Xm extends hp{constructor(t,e={}){super(),this.isContextNode=!0,this.node=t,this.context=e}getNodeType(t){return this.node.getNodeType(t)}analyze(t){this.node.build(t)}setup(t){const e=t.getContext();t.setContext({...t.context,...this.context});const s=this.node.build(t);return t.setContext(e),s}generate(t,e){const s=t.getContext();t.setContext({...t.context,...this.context});const i=this.node.build(t,e);return t.setContext(s),i}}const Ym=Zp(Xm),Jm=(t,e)=>Ym(t,{label:e});_p("context",Ym),_p("label",Jm),up("ContextNode",Xm);class Zm extends hp{constructor(t){super("uint"),this.scope=t,this.isInstanceIndexNode=!0}generate(t){const e=this.getNodeType(t),s=this.scope;let i,r;if(s===Zm.VERTEX)i=t.getVertexIndex();else if(s===Zm.INSTANCE)i=t.getInstanceIndex();else{if(s!==Zm.DRAW)throw new Error("THREE.IndexNode: Unknown scope: "+s);i=t.getDrawIndex()}if("vertex"===t.shaderStage||"compute"===t.shaderStage)r=i;else{r=km(this).build(t,e)}return r}}Zm.VERTEX="vertex",Zm.INSTANCE="instance",Zm.DRAW="draw";const Qm=Qp(Zm,Zm.VERTEX),Km=Qp(Zm,Zm.INSTANCE),tg=Qp(Zm,Zm.DRAW);up("IndexNode",Zm);class eg{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class sg extends hp{constructor(t,e=null){super(),this.node=t,this.name=e,this.global=!0,this.isVarNode=!0}getHash(t){return this.name||super.getHash(t)}getNodeType(t){return this.node.getNodeType(t)}generate(t){const{node:e,name:s}=this,i=t.getVarFromNode(this,s,t.getVectorType(this.getNodeType(t))),r=t.getPropertyName(i),n=e.build(t,i.type);return t.addLineFlowCode(`${r} = ${n}`),r}}const ig=Zp(sg);_p("temp",ig),_p("toVar",((...t)=>ig(...t).append())),up("VarNode",sg);class rg{constructor(t,e,s=null){this.isNodeAttribute=!0,this.name=t,this.type=e,this.node=s}}class ng{constructor(t,e,s){this.isNodeUniform=!0,this.name=t,this.type=e,this.node=s.getSelf()}get value(){return this.node.value}set value(t){this.node.value=t}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class og{constructor(t,e){this.isNodeVar=!0,this.name=t,this.type=e}}class ag extends og{constructor(t,e){super(t,e),this.needsInterpolation=!1,this.isNodeVarying=!0}}class hg{constructor(t,e,s=""){this.name=t,this.type=e,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}class ug{constructor(){this.keywords=[],this.nodes={},this.keywordsCallback={}}getNode(t){let e=this.nodes[t];return void 0===e&&void 0!==this.keywordsCallback[t]&&(e=this.keywordsCallback[t](t),this.nodes[t]=e),e}addKeyword(t,e){return this.keywords.push(t),this.keywordsCallback[t]=e,this}parse(t){const e=this.keywords,s=new RegExp(`\\b${e.join("\\b|\\b")}\\b`,"g"),i=t.match(s),r=[];if(null!==i)for(const t of i){const e=this.getNode(t);void 0!==e&&-1===r.indexOf(e)&&r.push(e)}return r}include(t,e){const s=this.parse(e);for(const e of s)e.build(t)}}let lg=0;class cg{constructor(t=null){this.id=lg++,this.nodesData=new WeakMap,this.parent=t}getData(t){let e=this.nodesData.get(t);return void 0===e&&null!==this.parent&&(e=this.parent.getData(t)),e}setData(t,e){this.nodesData.set(t,e)}}class dg extends hp{constructor(t,e=null,s=!1){super(t),this.name=e,this.varying=s,this.isPropertyNode=!0}getHash(t){return this.name||super.getHash(t)}isGlobal(){return!0}generate(t){let e;return!0===this.varying?(e=t.getVaryingFromNode(this,this.name),e.needsInterpolation=!0):e=t.getVarFromNode(this,this.name),t.getPropertyName(e)}}const pg=(t,e)=>Xp(new dg(t,e)),mg=(t,e)=>Xp(new dg(t,e,!0)),gg=Qp(dg,"vec4","DiffuseColor"),fg=Qp(dg,"vec3","EmissiveColor"),yg=Qp(dg,"float","Roughness"),xg=Qp(dg,"float","Metalness"),bg=Qp(dg,"float","Clearcoat"),vg=Qp(dg,"float","ClearcoatRoughness"),Tg=Qp(dg,"vec3","Sheen"),_g=Qp(dg,"float","SheenRoughness"),wg=Qp(dg,"float","Iridescence"),Sg=Qp(dg,"float","IridescenceIOR"),Mg=Qp(dg,"float","IridescenceThickness"),Ag=Qp(dg,"float","AlphaT"),Ng=Qp(dg,"float","Anisotropy"),Rg=Qp(dg,"vec3","AnisotropyT"),Cg=Qp(dg,"vec3","AnisotropyB"),Eg=Qp(dg,"color","SpecularColor"),Bg=Qp(dg,"float","SpecularF90"),Ig=Qp(dg,"float","Shininess"),Pg=Qp(dg,"vec4","Output"),Fg=Qp(dg,"float","dashSize"),Ug=Qp(dg,"float","gapSize"),Og=Qp(dg,"float","pointWidth"),zg=Qp(dg,"float","IOR"),Lg=Qp(dg,"float","Transmission"),Vg=Qp(dg,"float","Thickness"),Dg=Qp(dg,"float","AttenuationDistance"),kg=Qp(dg,"color","AttenuationColor"),Gg=Qp(dg,"float","Dispersion");up("PropertyNode",dg);class Wg extends dg{constructor(t,e=null){super(t,e),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const jg=(t,e)=>Xp(new Wg(t,e));up("ParameterNode",Wg);class Hg extends hp{constructor(t="",e=[],s=""){super("code"),this.isCodeNode=!0,this.code=t,this.language=s,this.includes=e}isGlobal(){return!0}setIncludes(t){return this.includes=t,this}getIncludes(){return this.includes}generate(t){const e=this.getIncludes(t);for(const s of e)s.build(t);const s=t.getCodeFromNode(this,this.getNodeType(t));return s.code=this.code,s.code}serialize(t){super.serialize(t),t.code=this.code,t.language=this.language}deserialize(t){super.deserialize(t),this.code=t.code,this.language=t.language}}const qg=Zp(Hg),$g=(t,e)=>qg(t,e,"js"),Xg=(t,e)=>qg(t,e,"wgsl"),Yg=(t,e)=>qg(t,e,"glsl");up("CodeNode",Hg);class Jg extends Hg{constructor(t="",e=[],s=""){super(t,e,s),this.keywords={}}getNodeType(t){return this.getNodeFunction(t).type}getInputs(t){return this.getNodeFunction(t).inputs}getNodeFunction(t){const e=t.getDataFromNode(this);let s=e.nodeFunction;return void 0===s&&(s=t.parser.parseFunction(this.code),e.nodeFunction=s),s}generate(t,e){super.generate(t);const s=this.getNodeFunction(t),i=s.name,r=s.type,n=t.getCodeFromNode(this,r);""!==i&&(n.name=i);const o=t.getPropertyName(n);let a=this.getNodeFunction(t).getCode(o);const h=this.keywords,u=Object.keys(h);if(u.length>0)for(const e of u){const s=new RegExp(`\\b${e}\\b`,"g"),i=h[e].build(t,"property");a=a.replace(s,i)}return n.code=a+"\n","property"===e?o:t.format(`${o}()`,r,e)}}const Zg=(t,e=[],s="")=>{for(let t=0;ti.call(...t);return r.functionNode=i,r},Qg=(t,e)=>Zg(t,e,"glsl"),Kg=(t,e)=>Zg(t,e,"wgsl");up("FunctionNode",Jg);class tf extends hp{constructor(t,e=!1){super("string"),this.name=t,this.version=0,this.shared=e,this.isUniformGroup=!0}set needsUpdate(t){!0===t&&this.version++}}const ef=t=>new tf(t),sf=t=>new tf(t,!0),rf=sf("frame"),nf=sf("render"),of=ef("object");up("UniformGroupNode",tf);class af extends xp{constructor(t,e=null){super(t,e),this.isUniformNode=!0,this.name="",this.groupNode=of}label(t){return this.name=t,this}setGroup(t){return this.groupNode=t,this}getGroup(){return this.groupNode}getUniformHash(t){return this.getHash(t)}onUpdate(t,e){const s=this.getSelf();return t=t.bind(s),super.onUpdate((e=>{const i=t(e,s);void 0!==i&&(this.value=i)}),e)}generate(t,e){const s=this.getNodeType(t),i=this.getUniformHash(t);let r=t.getNodeFromHash(i);void 0===r&&(t.setHashNode(this,i),r=this);const n=r.getInputType(t),o=t.getUniformFromNode(r,n,t.shaderStage,this.name||t.context.label),a=t.getPropertyName(o);return void 0!==t.context.label&&delete t.context.label,t.format(a,s,e)}}const hf=(t,e)=>{const s=qp(e||t),i=t&&!0===t.isNode?t.node&&t.node.value||t.value:t;return Xp(new af(i,s))};up("UniformNode",af);const uf=t=>Wm("uv"+(t>0?t:""),"vec2");class lf extends hp{constructor(t,e=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=t,this.levelNode=e}generate(t,e){const s=this.textureNode.build(t,"property"),i=this.levelNode.build(t,"int");return t.format(`${t.getMethod("textureDimensions")}( ${s}, ${i} )`,this.getNodeType(t),e)}}const cf=Zp(lf);_p("textureSize",cf),up("TextureSizeNode",lf);class df extends cp{constructor(t,e,s,...i){if(super(),i.length>0){let r=new df(t,e,s);for(let e=0;e>"===s||"<<"===s)return t.getIntegerType(n);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=e?t.getTypeLength(e):Math.max(t.getTypeLength(n),t.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===n&&t.isMatrix(o)?o:t.isMatrix(n)&&t.isVector(o)?t.getVectorFromMatrix(n):t.isVector(n)&&t.isMatrix(o)?t.getVectorFromMatrix(o):t.getTypeLength(o)>t.getTypeLength(n)?o:n}generate(t,e){const s=this.op,i=this.aNode,r=this.bNode,n=this.getNodeType(t,e);let o=null,a=null;"void"!==n?(o=i.getNodeType(t),a=void 0!==r?r.getNodeType(t):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?t.isVector(o)?a=o:o=a="float":">>"===s||"<<"===s?(o=n,a=t.changeComponentType(a,"uint")):t.isMatrix(o)&&t.isVector(a)?a=t.getVectorFromMatrix(o):o=t.isVector(o)&&t.isMatrix(a)?t.getVectorFromMatrix(a):a=n):o=a=n;const h=i.build(t,o),u=void 0!==r?r.build(t,a):null,l=t.getTypeLength(e),c=t.getFunctionOperator(s);return"void"!==e?"<"===s&&l>1?t.format(`${t.getMethod("lessThan")}( ${h}, ${u} )`,n,e):"<="===s&&l>1?t.format(`${t.getMethod("lessThanEqual")}( ${h}, ${u} )`,n,e):">"===s&&l>1?t.format(`${t.getMethod("greaterThan")}( ${h}, ${u} )`,n,e):">="===s&&l>1?t.format(`${t.getMethod("greaterThanEqual")}( ${h}, ${u} )`,n,e):"!"===s||"~"===s?t.format(`(${s}${h})`,o,e):c?t.format(`${c}( ${h}, ${u} )`,n,e):t.format(`( ${h} ${s} ${u} )`,n,e):"void"!==o?c?t.format(`${c}( ${h}, ${u} )`,n,e):t.format(`${h} ${s} ${u}`,n,e):void 0}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}}const pf=Zp(df,"+"),mf=Zp(df,"-"),gf=Zp(df,"*"),ff=Zp(df,"/"),yf=Zp(df,"%"),xf=Zp(df,"=="),bf=Zp(df,"!="),vf=Zp(df,"<"),Tf=Zp(df,">"),_f=Zp(df,"<="),wf=Zp(df,">="),Sf=Zp(df,"&&"),Mf=Zp(df,"||"),Af=Zp(df,"!"),Nf=Zp(df,"^^"),Rf=Zp(df,"&"),Cf=Zp(df,"~"),Ef=Zp(df,"|"),Bf=Zp(df,"^"),If=Zp(df,"<<"),Pf=Zp(df,">>");_p("add",pf),_p("sub",mf),_p("mul",gf),_p("div",ff),_p("remainder",yf),_p("equal",xf),_p("notEqual",bf),_p("lessThan",vf),_p("greaterThan",Tf),_p("lessThanEqual",_f),_p("greaterThanEqual",wf),_p("and",Sf),_p("or",Mf),_p("not",Af),_p("xor",Nf),_p("bitAnd",Rf),_p("bitNot",Cf),_p("bitOr",Ef),_p("bitXor",Bf),_p("shiftLeft",If),_p("shiftRight",Pf),up("OperatorNode",df);class Ff extends cp{constructor(t,e,s=null,i=null){super(),this.method=t,this.aNode=e,this.bNode=s,this.cNode=i}getInputType(t){const e=this.aNode.getNodeType(t),s=this.bNode?this.bNode.getNodeType(t):null,i=this.cNode?this.cNode.getNodeType(t):null,r=t.isMatrix(e)?0:t.getTypeLength(e),n=t.isMatrix(s)?0:t.getTypeLength(s),o=t.isMatrix(i)?0:t.getTypeLength(i);return r>n&&r>o?e:n>o?s:o>r?i:e}getNodeType(t){const e=this.method;return e===Ff.LENGTH||e===Ff.DISTANCE||e===Ff.DOT?"float":e===Ff.CROSS?"vec3":e===Ff.ALL?"bool":e===Ff.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):e===Ff.MOD?this.aNode.getNodeType(t):this.getInputType(t)}generate(t,e){const s=this.method,i=this.getNodeType(t),r=this.getInputType(t),n=this.aNode,o=this.bNode,a=this.cNode,h=!0===t.renderer.isWebGLRenderer;if(s===Ff.TRANSFORM_DIRECTION){let s=n,i=o;t.isMatrix(s.getNodeType(t))?i=ym(pm(i),0):s=ym(pm(s),0);const r=gf(s,i).xyz;return Qf(r).build(t,e)}if(s===Ff.NEGATE)return t.format("( - "+n.build(t,r)+" )",i,e);if(s===Ff.ONE_MINUS)return mf(1,n).build(t,e);if(s===Ff.RECIPROCAL)return ff(1,n).build(t,e);if(s===Ff.DIFFERENCE)return oy(mf(n,o)).build(t,e);{const u=[];return s===Ff.CROSS||s===Ff.MOD?u.push(n.build(t,i),o.build(t,i)):s===Ff.STEP?u.push(n.build(t,1===t.getTypeLength(n.getNodeType(t))?"float":r),o.build(t,r)):h&&(s===Ff.MIN||s===Ff.MAX)||s===Ff.MOD?u.push(n.build(t,r),o.build(t,1===t.getTypeLength(o.getNodeType(t))?"float":r)):s===Ff.REFRACT?u.push(n.build(t,r),o.build(t,r),a.build(t,"float")):s===Ff.MIX?u.push(n.build(t,r),o.build(t,r),a.build(t,1===t.getTypeLength(a.getNodeType(t))?"float":r)):(u.push(n.build(t,r)),null!==o&&u.push(o.build(t,r)),null!==a&&u.push(a.build(t,r))),t.format(`${t.getMethod(s,i)}( ${u.join(", ")} )`,i,e)}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}Ff.ALL="all",Ff.ANY="any",Ff.EQUALS="equals",Ff.RADIANS="radians",Ff.DEGREES="degrees",Ff.EXP="exp",Ff.EXP2="exp2",Ff.LOG="log",Ff.LOG2="log2",Ff.SQRT="sqrt",Ff.INVERSE_SQRT="inversesqrt",Ff.FLOOR="floor",Ff.CEIL="ceil",Ff.NORMALIZE="normalize",Ff.FRACT="fract",Ff.SIN="sin",Ff.COS="cos",Ff.TAN="tan",Ff.ASIN="asin",Ff.ACOS="acos",Ff.ATAN="atan",Ff.ABS="abs",Ff.SIGN="sign",Ff.LENGTH="length",Ff.NEGATE="negate",Ff.ONE_MINUS="oneMinus",Ff.DFDX="dFdx",Ff.DFDY="dFdy",Ff.ROUND="round",Ff.RECIPROCAL="reciprocal",Ff.TRUNC="trunc",Ff.FWIDTH="fwidth",Ff.BITCAST="bitcast",Ff.TRANSPOSE="transpose",Ff.ATAN2="atan2",Ff.MIN="min",Ff.MAX="max",Ff.MOD="mod",Ff.STEP="step",Ff.REFLECT="reflect",Ff.DISTANCE="distance",Ff.DIFFERENCE="difference",Ff.DOT="dot",Ff.CROSS="cross",Ff.POW="pow",Ff.TRANSFORM_DIRECTION="transformDirection",Ff.MIX="mix",Ff.CLAMP="clamp",Ff.REFRACT="refract",Ff.SMOOTHSTEP="smoothstep",Ff.FACEFORWARD="faceforward";const Uf=nm(1e-6),Of=nm(1e6),zf=nm(Math.PI),Lf=nm(2*Math.PI),Vf=Zp(Ff,Ff.ALL),Df=Zp(Ff,Ff.ANY),kf=Zp(Ff,Ff.EQUALS),Gf=Zp(Ff,Ff.RADIANS),Wf=Zp(Ff,Ff.DEGREES),jf=Zp(Ff,Ff.EXP),Hf=Zp(Ff,Ff.EXP2),qf=Zp(Ff,Ff.LOG),$f=Zp(Ff,Ff.LOG2),Xf=Zp(Ff,Ff.SQRT),Yf=Zp(Ff,Ff.INVERSE_SQRT),Jf=Zp(Ff,Ff.FLOOR),Zf=Zp(Ff,Ff.CEIL),Qf=Zp(Ff,Ff.NORMALIZE),Kf=Zp(Ff,Ff.FRACT),ty=Zp(Ff,Ff.SIN),ey=Zp(Ff,Ff.COS),sy=Zp(Ff,Ff.TAN),iy=Zp(Ff,Ff.ASIN),ry=Zp(Ff,Ff.ACOS),ny=Zp(Ff,Ff.ATAN),oy=Zp(Ff,Ff.ABS),ay=Zp(Ff,Ff.SIGN),hy=Zp(Ff,Ff.LENGTH),uy=Zp(Ff,Ff.NEGATE),ly=Zp(Ff,Ff.ONE_MINUS),cy=Zp(Ff,Ff.DFDX),dy=Zp(Ff,Ff.DFDY),py=Zp(Ff,Ff.ROUND),my=Zp(Ff,Ff.RECIPROCAL),gy=Zp(Ff,Ff.TRUNC),fy=Zp(Ff,Ff.FWIDTH),yy=Zp(Ff,Ff.BITCAST),xy=Zp(Ff,Ff.TRANSPOSE),by=Zp(Ff,Ff.ATAN2),vy=Zp(Ff,Ff.MIN),Ty=Zp(Ff,Ff.MAX),_y=Zp(Ff,Ff.MOD),wy=Zp(Ff,Ff.STEP),Sy=Zp(Ff,Ff.REFLECT),My=Zp(Ff,Ff.DISTANCE),Ay=Zp(Ff,Ff.DIFFERENCE),Ny=Zp(Ff,Ff.DOT),Ry=Zp(Ff,Ff.CROSS),Cy=Zp(Ff,Ff.POW),Ey=Zp(Ff,Ff.POW,2),By=Zp(Ff,Ff.POW,3),Iy=Zp(Ff,Ff.POW,4),Py=Zp(Ff,Ff.TRANSFORM_DIRECTION),Fy=t=>gf(ay(t),Cy(oy(t),1/3)),Uy=t=>Ny(t,t),Oy=Zp(Ff,Ff.MIX),zy=(t,e=0,s=1)=>Xp(new Ff(Ff.CLAMP,Xp(t),Xp(e),Xp(s))),Ly=t=>zy(t),Vy=Zp(Ff,Ff.REFRACT),Dy=Zp(Ff,Ff.SMOOTHSTEP),ky=Zp(Ff,Ff.FACEFORWARD),Gy=Kp((([t])=>{const e=Ny(t.xy,um(12.9898,78.233)),s=_y(e,zf);return Kf(ty(s).mul(43758.5453))}));_p("all",Vf),_p("any",Df),_p("equals",kf),_p("radians",Gf),_p("degrees",Wf),_p("exp",jf),_p("exp2",Hf),_p("log",qf),_p("log2",$f),_p("sqrt",Xf),_p("inverseSqrt",Yf),_p("floor",Jf),_p("ceil",Zf),_p("normalize",Qf),_p("fract",Kf),_p("sin",ty),_p("cos",ey),_p("tan",sy),_p("asin",iy),_p("acos",ry),_p("atan",ny),_p("abs",oy),_p("sign",ay),_p("length",hy),_p("lengthSq",Uy),_p("negate",uy),_p("oneMinus",ly),_p("dFdx",cy),_p("dFdy",dy),_p("round",py),_p("reciprocal",my),_p("trunc",gy),_p("fwidth",fy),_p("atan2",by),_p("min",vy),_p("max",Ty),_p("mod",_y),_p("step",wy),_p("reflect",Sy),_p("distance",My),_p("dot",Ny),_p("cross",Ry),_p("pow",Cy),_p("pow2",Ey),_p("pow3",By),_p("pow4",Iy),_p("transformDirection",Py),_p("mix",((t,e,s)=>Oy(e,s,t))),_p("clamp",zy),_p("refract",Vy),_p("smoothstep",((t,e,s)=>Dy(e,s,t))),_p("faceForward",ky),_p("difference",Ay),_p("saturate",Ly),_p("cbrt",Fy),_p("transpose",xy),_p("rand",Gy),up("MathNode",Ff);const Wy=Kp((t=>{const{value:e}=t,{rgb:s}=e,i=s.mul(.9478672986).add(.0521327014).pow(2.4),r=s.mul(.0773993808),n=s.lessThanEqual(.04045),o=Oy(i,r,n);return ym(o,e.a)})),jy=Kp((t=>{const{value:e}=t,{rgb:s}=e,i=s.pow(.41666).mul(1.055).sub(.055),r=s.mul(12.92),n=s.lessThanEqual(.0031308),o=Oy(i,r,n);return ym(o,e.a)})),Hy=t=>{let e=null;return t===Ze?e="Linear":t===Je&&(e="sRGB"),e},qy=(t,e)=>Hy(t)+"To"+Hy(e);class $y extends cp{constructor(t,e){super("vec4"),this.method=t,this.node=e}setup(){const{method:t,node:e}=this;return t===$y.LINEAR_TO_LINEAR?e:Xy[t]({value:e})}}$y.LINEAR_TO_LINEAR="LinearToLinear",$y.LINEAR_TO_sRGB="LinearTosRGB",$y.sRGB_TO_LINEAR="sRGBToLinear";const Xy={[$y.LINEAR_TO_sRGB]:jy,[$y.sRGB_TO_LINEAR]:Wy},Yy=(t,e)=>Xp(new $y(qy(Ze,e),Xp(t))),Jy=(t,e)=>Xp(new $y(qy(e,Ze),Xp(t))),Zy=Zp($y,$y.LINEAR_TO_sRGB),Qy=Zp($y,$y.sRGB_TO_LINEAR);_p("linearTosRGB",Zy),_p("sRGBToLinear",Qy),_p("linearToColorSpace",Yy),_p("colorSpaceToLinear",Jy),up("ColorSpaceNode",$y);class Ky extends hp{constructor(t="",e="void"){super(e),this.snippet=t}generate(t,e){const s=this.getNodeType(t),i=this.snippet;if("void"!==s)return t.format(`( ${i} )`,s,e);t.addLineFlowCode(i)}}const tx=Zp(Ky);up("ExpressionNode",Ky);class ex extends af{constructor(t){super(0),this._textureNode=t,this.updateType=$d.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const t=this.texture,e=t.images,s=e&&e.length>0?e[0]&&e[0].image||e[0]:t.image;if(s&&void 0!==s.width){const{width:t,height:e}=s;this.value=Math.log2(Math.max(t,e))}}}const sx=Zp(ex);up("MaxMipLevelNode",ex);class ix extends af{constructor(t,e=null,s=null,i=null){super(t),this.isTextureNode=!0,this.uvNode=e,this.levelNode=s,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=$d.NONE,this.referenceNode=null,this._value=t,this._matrixUniform=null,this.setUpdateMatrix(null===e)}set value(t){this.referenceNode?this.referenceNode.value=t:this._value=t}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===Bt?"uvec4":this.value.type===Et?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return uf(this.value.channel)}updateReference(){return this.value}getTransformedUV(t){return null===this._matrixUniform&&(this._matrixUniform=hf(this.value.matrix)),this._matrixUniform.mul(pm(t,1)).xy}setUpdateMatrix(t){return this.updateMatrix=t,this.updateType=t?$d.FRAME:$d.NONE,this}setupUV(t,e){const s=this.value;return!t.isFlipY()||!0!==s.isRenderTargetTexture&&!0!==s.isFramebufferTexture&&!0!==s.isDepthTexture||(e=e.setY(e.y.oneMinus())),e}setup(t){const e=t.getNodeProperties(this);e.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==t.context.forceUVContext||!t.context.getUV||(s=t.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(t,s);let i=this.levelNode;null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),e.uvNode=s,e.levelNode=i,e.biasNode=this.biasNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.depthNode=this.depthNode}generateUV(t,e){return e.build(t,!0===this.sampler?"vec2":"ivec2")}generateSnippet(t,e,s,i,r,n,o,a){const h=this.value;let u;return u=i?t.generateTextureLevel(h,e,s,i,n):r?t.generateTextureBias(h,e,s,r,n):a?t.generateTextureGrad(h,e,s,a,n):o?t.generateTextureCompare(h,e,s,o,n):!1===this.sampler?t.generateTextureLoad(h,e,s,n):t.generateTexture(h,e,s,n),u}generate(t,e){const s=t.getNodeProperties(this),i=this.value;if(!i||!0!==i.isTexture)throw new Error("TextureNode: Need a three.js texture.");const r=super.generate(t,"property");if("sampler"===e)return r+"_sampler";if(t.isReference(e))return r;{const n=t.getDataFromNode(this);let o=n.propertyName;if(void 0===o){const{uvNode:e,levelNode:i,biasNode:a,compareNode:h,depthNode:u,gradNode:l}=s,c=this.generateUV(t,e),d=i?i.build(t,"float"):null,p=a?a.build(t,"float"):null,m=u?u.build(t,"int"):null,g=h?h.build(t,"float"):null,f=l?[l[0].build(t,"vec2"),l[1].build(t,"vec2")]:null,y=t.getVarFromNode(this);o=t.getPropertyName(y);const x=this.generateSnippet(t,r,c,d,p,m,g,f);t.addLineFlowCode(`${o} = ${x}`),n.snippet=x,n.propertyName=o}let a=o;const h=this.getNodeType(t);return t.needsColorSpaceToLinear(i)&&(a=Jy(tx(a,h),i.colorSpace).setup(t).build(t,h)),t.format(a,h,e)}}setSampler(t){return this.sampler=t,this}getSampler(){return this.sampler}uv(t){const e=this.clone();return e.uvNode=Xp(t),e.referenceNode=this,Xp(e)}blur(t){const e=this.clone();return e.biasNode=Xp(t).mul(sx(e)),e.referenceNode=this,Xp(e)}level(t){const e=this.clone();return e.levelNode=Xp(t),e.referenceNode=this,Xp(e)}size(t){return cf(this,t)}bias(t){const e=this.clone();return e.biasNode=Xp(t),e.referenceNode=this,Xp(e)}compare(t){const e=this.clone();return e.compareNode=Xp(t),e.referenceNode=this,Xp(e)}grad(t,e){const s=this.clone();return s.gradNode=[Xp(t),Xp(e)],s.referenceNode=this,Xp(s)}depth(t){const e=this.clone();return e.depthNode=Xp(t),e.referenceNode=this,Xp(e)}serialize(t){super.serialize(t),t.value=this.value.toJSON(t.meta).uuid}deserialize(t){super.deserialize(t),this.value=t.meta.textures[t.value]}update(){const t=this.value,e=this._matrixUniform;null!==e&&(e.value=t.matrix),!0===t.matrixAutoUpdate&&t.updateMatrix()}clone(){const t=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return t.sampler=this.sampler,t}}const rx=Zp(ix),nx=(...t)=>rx(...t).setSampler(!1),ox=t=>(!0===t.isNode?t:rx(t)).convert("sampler");_p("texture",rx),up("TextureNode",ix);class ax extends af{constructor(t,e,s=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferCount=s}getElementType(t){return this.getNodeType(t)}getInputType(){return"buffer"}}const hx=(t,e,s)=>Xp(new ax(t,e,s));up("BufferNode",ax);class ux extends dp{constructor(t,e){super(t,e),this.isArrayBufferElementNode=!0}getNodeType(t){return this.node.getElementType(t)}generate(t){const e=super.generate(t),s=this.getNodeType();return t.format(e,"vec4",s)}}class lx extends ax{constructor(t,e=null){super(null,"vec4"),this.array=t,this.elementType=e,this._elementType=null,this._elementLength=0,this.updateType=$d.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:t,value:e}=this,s=this.getElementLength(),i=this.getElementType();if(1===s)for(let s=0;sXp(new lx(t,e));up("UniformsNode",lx);class dx extends dp{constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),s=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,s,i)}}class px extends hp{constructor(t,e,s=null,i=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=i,this.properties=t.split("."),this.reference=null,this.node=null,this.updateType=$d.OBJECT}element(t){return Xp(new dx(this,Xp(t)))}setNodeType(t){let e=null;e=null!==this.count?hx(null,t,this.count):Array.isArray(this.getValueFromReference())?cx(null,t):"texture"===t?rx(null):hf(null,t),this.node=e}getNodeType(t){return null===this.node&&this.updateValue(),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let s=t[e[0]];for(let t=1;tXp(new px(t,e,s)),gx=(t,e,s,i)=>Xp(new px(t,e,i,s));up("ReferenceNode",px);class fx extends px{constructor(t,e,s=null){super(t,e,s),this.material=s}updateReference(t){return this.reference=null!==this.material?this.material:t.material,this.reference}}const yx=(t,e,s)=>Xp(new fx(t,e,s));up("MaterialReferenceNode",fx);const xx=sf("camera").onRenderUpdate((()=>{xx.needsUpdate=!0})),bx=hf("float").label("cameraNear").setGroup(xx).onRenderUpdate((({camera:t})=>t.near)),vx=hf("float").label("cameraFar").setGroup(xx).onRenderUpdate((({camera:t})=>t.far)),Tx=hf("float").label("cameraLogDepth").setGroup(xx).onRenderUpdate((({camera:t})=>2/(Math.log(t.far+1)/Math.LN2))),_x=hf("mat4").label("cameraProjectionMatrix").setGroup(xx).onRenderUpdate((({camera:t})=>t.projectionMatrix)),wx=hf("mat4").label("cameraProjectionMatrixInverse").setGroup(xx).onRenderUpdate((({camera:t})=>t.projectionMatrixInverse)),Sx=hf("mat4").label("cameraViewMatrix").setGroup(xx).onRenderUpdate((({camera:t})=>t.matrixWorldInverse)),Mx=hf("mat4").label("cameraWorldMatrix").setGroup(xx).onRenderUpdate((({camera:t})=>t.matrixWorld)),Ax=hf("mat3").label("cameraNormalMatrix").setGroup(xx).onRenderUpdate((({camera:t})=>t.normalMatrix)),Nx=hf(new Ei).label("cameraPosition").setGroup(xx).onRenderUpdate((({camera:t},e)=>e.value.setFromMatrixPosition(t.matrixWorld)));class Rx extends hp{constructor(t=Rx.VIEW_MATRIX,e=null){super(),this.scope=t,this.object3d=e,this.updateType=$d.OBJECT,this._uniformNode=new af(null)}getNodeType(){const t=this.scope;return t===Rx.WORLD_MATRIX||t===Rx.VIEW_MATRIX?"mat4":t===Rx.NORMAL_MATRIX?"mat3":t===Rx.POSITION||t===Rx.VIEW_POSITION||t===Rx.DIRECTION||t===Rx.SCALE?"vec3":void 0}update(t){const e=this.object3d,s=this._uniformNode,i=this.scope;if(i===Rx.VIEW_MATRIX)s.value=e.modelViewMatrix;else if(i===Rx.NORMAL_MATRIX)s.value=e.normalMatrix;else if(i===Rx.WORLD_MATRIX)s.value=e.matrixWorld;else if(i===Rx.POSITION)s.value=s.value||new Ei,s.value.setFromMatrixPosition(e.matrixWorld);else if(i===Rx.SCALE)s.value=s.value||new Ei,s.value.setFromMatrixScale(e.matrixWorld);else if(i===Rx.DIRECTION)s.value=s.value||new Ei,e.getWorldDirection(s.value);else if(i===Rx.VIEW_POSITION){const i=t.camera;s.value=s.value||new Ei,s.value.setFromMatrixPosition(e.matrixWorld),s.value.applyMatrix4(i.matrixWorldInverse)}}generate(t){const e=this.scope;return e===Rx.WORLD_MATRIX||e===Rx.VIEW_MATRIX?this._uniformNode.nodeType="mat4":e===Rx.NORMAL_MATRIX?this._uniformNode.nodeType="mat3":e!==Rx.POSITION&&e!==Rx.VIEW_POSITION&&e!==Rx.DIRECTION&&e!==Rx.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(t)}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}}Rx.VIEW_MATRIX="viewMatrix",Rx.NORMAL_MATRIX="normalMatrix",Rx.WORLD_MATRIX="worldMatrix",Rx.POSITION="position",Rx.SCALE="scale",Rx.VIEW_POSITION="viewPosition",Rx.DIRECTION="direction";const Cx=Zp(Rx,Rx.DIRECTION),Ex=Zp(Rx,Rx.VIEW_MATRIX),Bx=Zp(Rx,Rx.NORMAL_MATRIX),Ix=Zp(Rx,Rx.WORLD_MATRIX),Px=Zp(Rx,Rx.POSITION),Fx=Zp(Rx,Rx.SCALE),Ux=Zp(Rx,Rx.VIEW_POSITION);up("Object3DNode",Rx);class Ox extends Rx{constructor(t=Ox.VIEW_MATRIX){super(t)}update(t){this.object3d=t.object,super.update(t)}}const zx=Qp(Ox,Ox.DIRECTION),Lx=Qp(Ox,Ox.VIEW_MATRIX).label("modelViewMatrix").temp("ModelViewMatrix"),Vx=Qp(Ox,Ox.NORMAL_MATRIX),Dx=Qp(Ox,Ox.WORLD_MATRIX),kx=Qp(Ox,Ox.POSITION),Gx=Qp(Ox,Ox.SCALE),Wx=Qp(Ox,Ox.VIEW_POSITION),jx=hf(new or).onObjectUpdate((({object:t},e)=>e.value.copy(t.matrixWorld).invert()));up("ModelNode",Ox);const Hx=Wm("normal","vec3",pm(0,1,0)),qx=Hx.toVar("normalLocal"),$x=km(Vx.mul(qx),"v_normalView").normalize().toVar("normalView"),Xx=km($x.transformDirection(Sx),"v_normalWorld").normalize().toVar("normalWorld"),Yx=pg("vec3","transformedNormalView"),Jx=Yx.transformDirection(Sx).normalize().toVar("transformedNormalWorld"),Zx=pg("vec3","transformedClearcoatNormalView"),Qx=new Map;class Kx extends hp{constructor(t){super(),this.scope=t}getCache(t,e){let s=Qx.get(t);return void 0===s&&(s=yx(t,e),Qx.set(t,s)),s}getFloat(t){return this.getCache(t,"float")}getColor(t){return this.getCache(t,"color")}getTexture(t){return this.getCache("map"===t?"map":t+"Map","texture")}setup(t){const e=t.context.material,s=this.scope;let i=null;if(s===Kx.COLOR){const t=this.getColor(s);i=e.map&&!0===e.map.isTexture?t.mul(this.getTexture("map")):t}else if(s===Kx.OPACITY){const t=this.getFloat(s);i=e.alphaMap&&!0===e.alphaMap.isTexture?t.mul(this.getTexture("alpha")):t}else if(s===Kx.SPECULAR_STRENGTH)i=e.specularMap&&!0===e.specularMap.isTexture?this.getTexture("specular").r:nm(1);else if(s===Kx.SPECULAR_INTENSITY){const t=this.getFloat(s);i=e.specularMap?t.mul(this.getTexture(s).a):t}else if(s===Kx.SPECULAR_COLOR){const t=this.getColor(s);i=e.specularColorMap&&!0===e.specularColorMap.isTexture?t.mul(this.getTexture(s).rgb):t}else if(s===Kx.ROUGHNESS){const t=this.getFloat(s);i=e.roughnessMap&&!0===e.roughnessMap.isTexture?t.mul(this.getTexture(s).g):t}else if(s===Kx.METALNESS){const t=this.getFloat(s);i=e.metalnessMap&&!0===e.metalnessMap.isTexture?t.mul(this.getTexture(s).b):t}else if(s===Kx.EMISSIVE){const t=this.getColor(s);i=e.emissiveMap&&!0===e.emissiveMap.isTexture?t.mul(this.getTexture(s)):t}else if(s===Kx.NORMAL)i=e.normalMap?this.getTexture("normal").normalMap(this.getCache("normalScale","vec2")):e.bumpMap?this.getTexture("bump").r.bumpMap(this.getFloat("bumpScale")):$x;else if(s===Kx.CLEARCOAT){const t=this.getFloat(s);i=e.clearcoatMap&&!0===e.clearcoatMap.isTexture?t.mul(this.getTexture(s).r):t}else if(s===Kx.CLEARCOAT_ROUGHNESS){const t=this.getFloat(s);i=e.clearcoatRoughnessMap&&!0===e.clearcoatRoughnessMap.isTexture?t.mul(this.getTexture(s).r):t}else if(s===Kx.CLEARCOAT_NORMAL)i=e.clearcoatNormalMap?this.getTexture(s).normalMap(this.getCache(s+"Scale","vec2")):$x;else if(s===Kx.SHEEN){const t=this.getColor("sheenColor").mul(this.getFloat("sheen"));i=e.sheenColorMap&&!0===e.sheenColorMap.isTexture?t.mul(this.getTexture("sheenColor").rgb):t}else if(s===Kx.SHEEN_ROUGHNESS){const t=this.getFloat(s);i=e.sheenRoughnessMap&&!0===e.sheenRoughnessMap.isTexture?t.mul(this.getTexture(s).a):t,i=i.clamp(.07,1)}else if(s===Kx.ANISOTROPY)if(e.anisotropyMap&&!0===e.anisotropyMap.isTexture){const t=this.getTexture(s);i=Tm(Lb.x,Lb.y,Lb.y.negate(),Lb.x).mul(t.rg.mul(2).sub(um(1)).normalize().mul(t.b))}else i=Lb;else if(s===Kx.IRIDESCENCE_THICKNESS){const t=mx("1","float",e.iridescenceThicknessRange);if(e.iridescenceThicknessMap){const r=mx("0","float",e.iridescenceThicknessRange);i=t.sub(r).mul(this.getTexture(s).g).add(r)}else i=t}else if(s===Kx.TRANSMISSION){const t=this.getFloat(s);i=e.transmissionMap?t.mul(this.getTexture(s).r):t}else if(s===Kx.THICKNESS){const t=this.getFloat(s);i=e.thicknessMap?t.mul(this.getTexture(s).g):t}else if(s===Kx.IOR)i=this.getFloat(s);else if(s===Kx.REFRACTION_RATIO)i=this.getFloat(s);else if(s===Kx.LIGHT_MAP)i=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===Kx.AO_MAP)i=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const e=this.getNodeType(t);i=this.getCache(s,e)}return i}}Kx.ALPHA_TEST="alphaTest",Kx.COLOR="color",Kx.OPACITY="opacity",Kx.SHININESS="shininess",Kx.SPECULAR="specular",Kx.SPECULAR_STRENGTH="specularStrength",Kx.SPECULAR_INTENSITY="specularIntensity",Kx.SPECULAR_COLOR="specularColor",Kx.REFLECTIVITY="reflectivity",Kx.ROUGHNESS="roughness",Kx.METALNESS="metalness",Kx.NORMAL="normal",Kx.CLEARCOAT="clearcoat",Kx.CLEARCOAT_ROUGHNESS="clearcoatRoughness",Kx.CLEARCOAT_NORMAL="clearcoatNormal",Kx.EMISSIVE="emissive",Kx.ROTATION="rotation",Kx.SHEEN="sheen",Kx.SHEEN_ROUGHNESS="sheenRoughness",Kx.ANISOTROPY="anisotropy",Kx.IRIDESCENCE="iridescence",Kx.IRIDESCENCE_IOR="iridescenceIOR",Kx.IRIDESCENCE_THICKNESS="iridescenceThickness",Kx.IOR="ior",Kx.TRANSMISSION="transmission",Kx.THICKNESS="thickness",Kx.ATTENUATION_DISTANCE="attenuationDistance",Kx.ATTENUATION_COLOR="attenuationColor",Kx.LINE_SCALE="scale",Kx.LINE_DASH_SIZE="dashSize",Kx.LINE_GAP_SIZE="gapSize",Kx.LINE_WIDTH="linewidth",Kx.LINE_DASH_OFFSET="dashOffset",Kx.POINT_WIDTH="pointWidth",Kx.DISPERSION="dispersion",Kx.LIGHT_MAP="light",Kx.AO_MAP="ao",Kx.REFRACTION_RATIO="refractionRatio";const tb=Qp(Kx,Kx.ALPHA_TEST),eb=Qp(Kx,Kx.COLOR),sb=Qp(Kx,Kx.SHININESS),ib=Qp(Kx,Kx.EMISSIVE),rb=Qp(Kx,Kx.OPACITY),nb=Qp(Kx,Kx.SPECULAR),ob=Qp(Kx,Kx.SPECULAR_INTENSITY),ab=Qp(Kx,Kx.SPECULAR_COLOR),hb=Qp(Kx,Kx.SPECULAR_STRENGTH),ub=Qp(Kx,Kx.REFLECTIVITY),lb=Qp(Kx,Kx.ROUGHNESS),cb=Qp(Kx,Kx.METALNESS),db=Qp(Kx,Kx.NORMAL),pb=Qp(Kx,Kx.CLEARCOAT),mb=Qp(Kx,Kx.CLEARCOAT_ROUGHNESS),gb=Qp(Kx,Kx.CLEARCOAT_NORMAL),fb=Qp(Kx,Kx.ROTATION),yb=Qp(Kx,Kx.SHEEN),xb=Qp(Kx,Kx.SHEEN_ROUGHNESS),bb=Qp(Kx,Kx.ANISOTROPY),vb=Qp(Kx,Kx.IRIDESCENCE),Tb=Qp(Kx,Kx.IRIDESCENCE_IOR),_b=Qp(Kx,Kx.IRIDESCENCE_THICKNESS),wb=Qp(Kx,Kx.TRANSMISSION),Sb=Qp(Kx,Kx.THICKNESS),Mb=Qp(Kx,Kx.IOR),Ab=Qp(Kx,Kx.ATTENUATION_DISTANCE),Nb=Qp(Kx,Kx.ATTENUATION_COLOR),Rb=Qp(Kx,Kx.LINE_SCALE),Cb=Qp(Kx,Kx.LINE_DASH_SIZE),Eb=Qp(Kx,Kx.LINE_GAP_SIZE),Bb=Qp(Kx,Kx.LINE_WIDTH),Ib=Qp(Kx,Kx.LINE_DASH_OFFSET),Pb=Qp(Kx,Kx.POINT_WIDTH),Fb=Qp(Kx,Kx.DISPERSION),Ub=Qp(Kx,Kx.LIGHT_MAP),Ob=Qp(Kx,Kx.AO_MAP),zb=Qp(Kx,Kx.REFRACTION_RATIO),Lb=hf(new Ks).onReference((function(t){return t.material})).onRenderUpdate((function({material:t}){this.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation))}));up("MaterialNode",Kx);const Vb=Wm("position","vec3"),Db=Vb.toVar("positionLocal"),kb=km(Dx.mul(Db).xyz,"v_positionWorld"),Gb=km(Db.transformDirection(Dx),"v_positionWorldDirection").normalize().toVar("positionWorldDirection"),Wb=km(Lx.mul(Db).xyz,"v_positionView"),jb=km(Wb.negate(),"v_positionViewDirection").normalize().toVar("positionViewDirection");class Hb extends cp{constructor(t=null){super("vec4"),this.positionNode=t}setup(t){if("fragment"===t.shaderStage)return km(t.context.mvp);const e=this.positionNode||Db;return _x.mul(Lx).mul(e)}}const qb=Zp(Hb);up("ModelViewProjectionNode",Hb);class $b extends xp{constructor(t,e=null,s=0,i=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferStride=s,this.bufferOffset=i,this.usage=Rs,this.instanced=!1,this.attribute=null,this.global=!0,t&&!0===t.isBufferAttribute&&(this.attribute=t,this.usage=t.usage,this.instanced=t.isInstancedBufferAttribute)}getHash(t){if(0===this.bufferStride&&0===this.bufferOffset){let e=t.globalCache.getData(this.value);return void 0===e&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getNodeType(t){return null===this.bufferType&&(this.bufferType=t.getTypeFromAttribute(this.attribute)),this.bufferType}setup(t){if(null!==this.attribute)return;const e=this.getNodeType(t),s=this.value,i=t.getTypeLength(e),r=this.bufferStride||i,n=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new oo(s,r),a=new ho(o,i,n);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(t){const e=this.getNodeType(t),s=t.getBufferAttributeFromNode(this,e),i=t.getPropertyName(s);let r=null;if("vertex"===t.shaderStage||"compute"===t.shaderStage)this.name=i,r=i;else{r=km(this).build(t,e)}return r}getInputType(){return"bufferAttribute"}setUsage(t){return this.usage=t,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=t),this}setInstanced(t){return this.instanced=t,this}}const Xb=(t,e,s,i)=>Xp(new $b(t,e,s,i)),Yb=(t,e,s,i)=>Xb(t,e,s,i).setUsage(Cs),Jb=(t,e,s,i)=>Xb(t,e,s,i).setInstanced(!0),Zb=(t,e,s,i)=>Yb(t,e,s,i).setInstanced(!0);_p("toAttribute",(t=>Xb(t.value))),up("BufferAttributeNode",$b);class Qb extends hp{constructor(t){super("void"),this.instanceMesh=t,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=$d.FRAME,this.buffer=null,this.bufferColor=null}setup(){let t=this.instanceMatrixNode;const e=this.instanceMesh;if(null===t){const s=e.instanceMatrix,i=new Nc(s.array,16,1);this.buffer=i;const r=s.usage===Cs?Zb:Jb,n=[r(i,"vec4",16,0),r(i,"vec4",16,4),r(i,"vec4",16,8),r(i,"vec4",16,12)];t=Cm(...n),this.instanceMatrixNode=t}const s=e.instanceColor;if(s&&null===this.instanceColorNode){const t=new jo(s.array,3),e=s.usage===Cs?Zb:Jb;this.bufferColor=t,this.instanceColorNode=pm(e(t,"vec3",3,0))}const i=t.mul(Db).xyz,r=Mm(t[0].xyz,t[1].xyz,t[2].xyz),n=qx.div(pm(r[0].dot(r[0]),r[1].dot(r[1]),r[2].dot(r[2]))),o=r.mul(n).xyz;Db.assign(i),qx.assign(o),null!==this.instanceColorNode&&mg("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==Cs&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==Cs&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const Kb=Zp(Qb);up("InstanceNode",Qb);const tv=Kp(((t,e)=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),Wm("tangent","vec4"))))(),ev=tv.xyz.toVar("tangentLocal"),sv=km(Lx.mul(ym(ev,0)).xyz,"v_tangentView").normalize().toVar("tangentView"),iv=km(sv.transformDirection(Sx),"v_tangentWorld").normalize().toVar("tangentWorld"),rv=sv.toVar("transformedTangentView"),nv=rv.transformDirection(Sx).normalize().toVar("transformedTangentWorld");class ov extends hp{constructor(t){super("void"),this.batchMesh=t,this.instanceColorNode=null,this.batchingIdNode=null}setup(t){null===this.batchingIdNode&&(null===t.getDrawIndex()?this.batchingIdNode=Km:this.batchingIdNode=tg);const e=Kp((([t])=>{const e=cf(nx(this.batchMesh._indirectTexture),0),s=om(t).remainder(om(e)),i=om(t).div(om(e));return nx(this.batchMesh._indirectTexture,lm(s,i)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=this.batchMesh._matricesTexture,i=cf(nx(s),0),r=nm(e(om(this.batchingIdNode))).mul(4).toVar(),n=om(r.mod(i)),o=om(r).div(om(i)),a=Cm(nx(s,lm(n,o)),nx(s,lm(n.add(1),o)),nx(s,lm(n.add(2),o)),nx(s,lm(n.add(3),o))),h=Mm(a[0].xyz,a[1].xyz,a[2].xyz);Db.assign(a.mul(Db));const u=qx.div(pm(h[0].dot(h[0]),h[1].dot(h[1]),h[2].dot(h[2]))),l=h.mul(u).xyz;qx.assign(l),t.hasGeometryAttribute("tangent")&&ev.mulAssign(h)}}const av=Zp(ov);up("batch",ov);class hv extends hp{constructor(t,e=!1){let s,i,r;super("void"),this.skinnedMesh=t,this.useReference=e,this.updateType=$d.OBJECT,this.skinIndexNode=Wm("skinIndex","uvec4"),this.skinWeightNode=Wm("skinWeight","vec4"),e?(s=mx("bindMatrix","mat4"),i=mx("bindMatrixInverse","mat4"),r=gx("skeleton.boneMatrices","mat4",t.skeleton.bones.length)):(s=hf(t.bindMatrix,"mat4"),i=hf(t.bindMatrixInverse,"mat4"),r=hx(t.skeleton.boneMatrices,"mat4",t.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=i,this.boneMatricesNode=r}setup(t){const{skinIndexNode:e,skinWeightNode:s,bindMatrixNode:i,bindMatrixInverseNode:r,boneMatricesNode:n}=this,o=n.element(e.x),a=n.element(e.y),h=n.element(e.z),u=n.element(e.w),l=i.mul(Db),c=pf(o.mul(s.x).mul(l),a.mul(s.y).mul(l),h.mul(s.z).mul(l),u.mul(s.w).mul(l)),d=r.mul(c).xyz;let p=pf(s.x.mul(o),s.y.mul(a),s.z.mul(h),s.w.mul(u));p=r.mul(p).mul(i);const m=p.transformDirection(qx).xyz;Db.assign(d),qx.assign(m),t.hasGeometryAttribute("tangent")&&ev.assign(m)}generate(t,e){if("void"!==e)return Db.build(t,e)}update(t){(this.useReference?t.object:this.skinnedMesh).skeleton.update()}}const uv=t=>Xp(new hv(t)),lv=t=>Xp(new hv(t,!0));up("SkinningNode",hv);class cv extends hp{constructor(t=[]){super(),this.params=t}getVarName(t){return String.fromCharCode("i".charCodeAt()+t)}getProperties(t){const e=t.getNodeProperties(this);if(void 0!==e.stackNode)return e;const s={};for(let t=0,e=this.params.length-1;tNumber(n)?">=":"<"));const l={start:r,end:n,condition:h},c=l.start,d=l.end;let p="",m="",g="";u||(u="int"===a||"uint"===a?h.includes("<")?"++":"--":h.includes("<")?"+= 1.":"-= 1."),p+=t.getVar(a,o)+" = "+c,m+=o+" "+h+" "+d,g+=o+" "+u;const f=`for ( ${p}; ${m}; ${g} )`;t.addFlowCode((0===e?"\n":"")+t.tab+f+" {\n\n").addFlowTab()}const r=i.build(t,"void"),n=e.returnsNode?e.returnsNode.build(t):"";t.removeFlowTab().addFlowCode("\n"+t.tab+r);for(let e=0,s=this.params.length-1;eXp(new cv(Jp(t,"int"))).append(),pv=()=>tx("continue").append(),mv=()=>tx("break").append();_p("loop",((t,...e)=>Hm(t,dv(...e)))),up("LoopNode",cv);const gv=new WeakMap,fv=new _i,yv=Kp((({bufferMap:t,influence:e,stride:s,width:i,depth:r,offset:n})=>{const o=om(Qm).mul(s).add(n),a=o.div(i),h=o.sub(a.mul(i));return nx(t,lm(h,a)).depth(r).mul(e)}));class xv extends hp{constructor(t){super("void"),this.mesh=t,this.morphBaseInfluence=hf(1),this.updateType=$d.OBJECT}setup(t){const{geometry:e}=t,s=void 0!==e.morphAttributes.position,i=void 0!==e.morphAttributes.normal,r=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,n=void 0!==r?r.length:0,{texture:o,stride:a,size:h}=function(t){const e=void 0!==t.morphAttributes.position,s=void 0!==t.morphAttributes.normal,i=void 0!==t.morphAttributes.color,r=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,n=void 0!==r?r.length:0;let o=gv.get(t);if(void 0===o||o.count!==n){void 0!==o&&o.texture.dispose();const a=t.morphAttributes.position||[],h=t.morphAttributes.normal||[],u=t.morphAttributes.color||[];let l=0;!0===e&&(l=1),!0===s&&(l=2),!0===i&&(l=3);let c=t.attributes.position.count*l,d=1;const p=4096;c>p&&(d=Math.ceil(c/p),c=p);const m=new Float32Array(c*d*4*n),g=new Mi(m,c,d,n);g.type=It,g.needsUpdate=!0;const f=4*l;for(let x=0;x{const e=nm(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?e.assign(nx(this.mesh.morphTexture,lm(om(t).add(1),om(Km))).r):e.assign(mx("morphTargetInfluences","float").element(t).toVar()),!0===s&&Db.addAssign(yv({bufferMap:o,influence:e,stride:a,width:u,depth:t,offset:om(0)})),!0===i&&qx.addAssign(yv({bufferMap:o,influence:e,stride:a,width:u,depth:t,offset:om(1)}))}))}update(){const t=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?t.value=1:t.value=1-this.mesh.morphTargetInfluences.reduce(((t,e)=>t+e),0)}}const bv=Zp(xv);up("MorphNode",xv);const vv=jb.negate().reflect(Yx),Tv=jb.negate().refract(Yx,zb),_v=vv.transformDirection(Sx).toVar("reflectVector"),wv=Tv.transformDirection(Sx).toVar("reflectVector");class Sv extends ix{constructor(t,e=null,s=null,i=null){super(t,e,s,i),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const t=this.value;return t.mapping===ht?_v:t.mapping===ut?wv:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',t.mapping),pm(0,0,0))}setUpdateMatrix(){}setupUV(t,e){const s=this.value;return t.renderer.coordinateSystem!==Ds&&s.isRenderTargetTexture?e:pm(e.x.negate(),e.yz)}generateUV(t,e){return e.build(t,"vec3")}}const Mv=Zp(Sv);_p("cubeTexture",Mv),up("CubeTextureNode",Sv);class Av extends hp{constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}up("LightingNode",Av);let Nv=null;class Rv extends Av{constructor(t=null){super(),this.updateType=$d.FRAME,this.light=t,this.rtt=null,this.shadowNode=null,this.shadowMaskNode=null,this.color=new Yr,this._defaultColorNode=hf(this.color),this.colorNode=this._defaultColorNode,this.isAnalyticLightNode=!0}getCacheKey(){return super.getCacheKey()+"-"+this.light.id+"-"+(this.light.castShadow?"1":"0")}getHash(){return this.light.uuid}setupShadow(t){const{object:e}=t;if(!1===e.receiveShadow)return;let s=this.shadowNode;if(null===s){null===Nv&&(Nv=t.createNodeMaterial(),Nv.fragmentNode=ym(0,0,0,1),Nv.isShadowNodeMaterial=!0);const i=this.light.shadow,r=t.createRenderTarget(i.mapSize.width,i.mapSize.height),n=new Ka;n.minFilter=ft,n.magFilter=ft,n.image.width=i.mapSize.width,n.image.height=i.mapSize.height,n.compareFunction=Ts,r.depthTexture=n,i.camera.updateProjectionMatrix();const o=mx("intensity","float",i),a=mx("bias","float",i),h=mx("normalBias","float",i),u=e.material.shadowPositionNode||kb;let l=hf(i.matrix).mul(u.add(Xx.mul(h)));l=l.xyz.div(l.w);const c=l.x.greaterThanEqual(0).and(l.x.lessThanEqual(1)).and(l.y.greaterThanEqual(0)).and(l.y.lessThanEqual(1)).and(l.z.lessThanEqual(1));let d=l.z.add(a);t.renderer.coordinateSystem===Ds&&(d=d.mul(2).sub(1)),l=pm(l.x,l.y.oneMinus(),d);const p=(t,e,s)=>rx(t,e).compare(s);s=p(n,l.xy,l.z);const m=rx(r.texture,l),g=c.mix(1,s.mix(m.a.mix(1,m),1));this.rtt=r,this.colorNode=this.colorNode.mul(Oy(1,g,o)),this.shadowNode=s,this.shadowMaskNode=g,this.updateBeforeType=$d.RENDER}}setup(t){this.light.castShadow?this.setupShadow(t):null!==this.shadowNode&&this.disposeShadow()}updateShadow(t){const{rtt:e,light:s}=this,{renderer:i,scene:r,camera:n}=t,o=r.overrideMaterial;r.overrideMaterial=Nv,e.setSize(s.shadow.mapSize.width,s.shadow.mapSize.height),s.shadow.updateMatrices(s),s.shadow.camera.layers.mask=n.layers.mask;const a=i.toneMapping,h=i.getRenderTarget(),u=i.getRenderObjectFunction();i.setRenderObjectFunction(((t,...e)=>{!0===t.castShadow&&i.renderObject(t,...e)})),i.setRenderTarget(e),i.toneMapping=0,i.render(r,s.shadow.camera),i.setRenderTarget(h),i.setRenderObjectFunction(u),i.toneMapping=a,r.overrideMaterial=o}disposeShadow(){this.rtt.dispose(),this.shadowNode=null,this.shadowMaskNode=null,this.rtt=null,this.colorNode=this._defaultColorNode}updateBefore(t){const{light:e}=this;e.castShadow&&this.updateShadow(t)}update(){const{light:t}=this;this.color.copy(t.color).multiplyScalar(t.intensity)}}up("AnalyticLightNode",Rv);const Cv=new WeakMap;class Ev extends hp{constructor(t=[]){super("vec3"),this.totalDiffuseNode=pm().temp("totalDiffuse"),this.totalSpecularNode=pm().temp("totalSpecular"),this.outgoingLightNode=pm().temp("outgoingLight"),this.lightNodes=t,this._hash=null}get hasLight(){return this.lightNodes.length>0}getHash(){if(null===this._hash){const t=[];for(const e of this.lightNodes)t.push(e.getHash());this._hash="lights-"+t.join(",")}return this._hash}analyze(t){const e=t.getDataFromNode(this);for(const s of e.nodes)s.build(t)}setup(t){const e=t.context,s=e.lightingModel;let i=this.outgoingLightNode;if(s){const{lightNodes:r,totalDiffuseNode:n,totalSpecularNode:o}=this;e.outgoingLight=i;const a=t.addStack();t.getDataFromNode(this).nodes=a.nodes,s.start(e,a,t);for(const e of r)e.build(t);s.indirect(e,a,t);const{backdrop:h,backdropAlpha:u}=e,{directDiffuse:l,directSpecular:c,indirectDiffuse:d,indirectSpecular:p}=e.reflectedLight;let m=l.add(d);null!==h&&(m=pm(null!==u?u.mix(m,h):h),e.material.transparent=!0),n.assign(m),o.assign(c.add(p)),i.assign(n.add(o)),s.finish(e,a,t),i=i.bypass(t.removeStack())}return i}_getLightNodeById(t){for(const e of this.lightNodes)if(e.isAnalyticLightNode&&e.light.id===t)return e;return null}fromLights(t=[]){const e=[];t=(t=>t.sort(((t,e)=>t.id-e.id)))(t);for(const s of t){let t=this._getLightNodeById(s.id);if(null===t){const e=s.constructor,i=Cv.has(e)?Cv.get(e):Rv;t=Xp(new i(s))}e.push(t)}return this.lightNodes=e,this._hash=null,this}}const Bv=t=>Xp((new Ev).fromLights(t)),Iv=Zp(Ev);function Pv(t,e){if(Cv.has(t))console.warn(`Redefinition of light node ${e.type}`);else{if("function"!=typeof t)throw new Error(`Light ${t.name} is not a class`);if("function"!=typeof e||!e.type)throw new Error(`Light node ${e.type} is not a class`);Cv.set(t,e)}}class Fv extends Av{constructor(t=null){super(),this.aoNode=t}setup(t){t.context.ambientOcclusion.mulAssign(this.aoNode)}}up("AONode",Fv);class Uv extends Xm{constructor(t,e=null,s=null,i=null){super(t),this.lightingModel=e,this.backdropNode=s,this.backdropAlphaNode=i,this._context=null}getContext(){const{backdropNode:t,backdropAlphaNode:e}=this,s={directDiffuse:pm().temp("directDiffuse"),directSpecular:pm().temp("directSpecular"),indirectDiffuse:pm().temp("indirectDiffuse"),indirectSpecular:pm().temp("indirectSpecular")};return{radiance:pm().temp("radiance"),irradiance:pm().temp("irradiance"),iblIrradiance:pm().temp("iblIrradiance"),ambientOcclusion:nm(1).temp("ambientOcclusion"),reflectedLight:s,backdrop:t,backdropAlpha:e}}setup(t){return this.context=this._context||(this._context=this.getContext()),this.context.lightingModel=this.lightingModel||t.context.lightingModel,super.setup(t)}}const Ov=Zp(Uv);_p("lightingContext",Ov),up("LightingContextNode",Uv);class zv extends Av{constructor(t){super(),this.node=t}setup(t){t.context.irradiance.addAssign(this.node)}}let Lv,Vv;up("IrradianceNode",zv);class Dv extends hp{constructor(t){super(),this.scope=t,this.isViewportNode=!0}getNodeType(){return this.scope===Dv.VIEWPORT?"vec4":this.scope===Dv.COORDINATE?"vec3":"vec2"}getUpdateType(){let t=$d.NONE;return this.scope!==Dv.RESOLUTION&&this.scope!==Dv.VIEWPORT||(t=$d.RENDER),this.updateType=t,t}update({renderer:t}){this.scope===Dv.VIEWPORT?t.getViewport(Vv):t.getDrawingBufferSize(Lv)}setup(){const t=this.scope;let e=null;if(t===Dv.RESOLUTION)e=hf(Lv||(Lv=new Ks));else if(t===Dv.VIEWPORT)e=hf(Vv||(Vv=new _i));else{e=kv.div(Gv);let s=e.x,i=e.y;/bottom/i.test(t)&&(i=i.oneMinus()),/right/i.test(t)&&(s=s.oneMinus()),e=um(s,i)}return e}generate(t){if(this.scope===Dv.COORDINATE){let e=t.getFragCoord();if(t.isFlipY()){const s=t.getNodeProperties(Gv).outputNode.build(t);e=`${t.getType("vec3")}( ${e}.x, ${s}.y - ${e}.y, ${e}.z )`}return e}return super.generate(t)}}Dv.COORDINATE="coordinate",Dv.RESOLUTION="resolution",Dv.VIEWPORT="viewport",Dv.TOP_LEFT="topLeft",Dv.BOTTOM_LEFT="bottomLeft",Dv.TOP_RIGHT="topRight",Dv.BOTTOM_RIGHT="bottomRight";const kv=Qp(Dv,Dv.COORDINATE),Gv=Qp(Dv,Dv.RESOLUTION),Wv=Qp(Dv,Dv.VIEWPORT),jv=Qp(Dv,Dv.TOP_LEFT),Hv=Qp(Dv,Dv.BOTTOM_LEFT),qv=Qp(Dv,Dv.TOP_RIGHT),$v=Qp(Dv,Dv.BOTTOM_RIGHT);up("ViewportNode",Dv);const Xv=new Ks;class Yv extends ix{constructor(t=jv,e=null,s=null){null===s&&((s=new Xa).minFilter=St),super(s,t,e),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=$d.FRAME}updateBefore(t){const e=t.renderer;e.getDrawingBufferSize(Xv);const s=this.value;s.image.width===Xv.width&&s.image.height===Xv.height||(s.image.width=Xv.width,s.image.height=Xv.height,s.needsUpdate=!0);const i=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,e.copyFramebufferToTexture(s),s.generateMipmaps=i}clone(){const t=new this.constructor(this.uvNode,this.levelNode,this.value);return t.generateMipmaps=this.generateMipmaps,t}}const Jv=Zp(Yv),Zv=Zp(Yv,null,null,{generateMipmaps:!0});_p("viewportTexture",Jv),_p("viewportMipTexture",Zv),up("ViewportTextureNode",Yv);let Qv=null;class Kv extends Yv{constructor(t=jv,e=null){null===Qv&&(Qv=new Ka),super(t,e,Qv)}}const tT=Zp(Kv);_p("viewportDepthTexture",tT),up("ViewportDepthTextureNode",Kv);class eT extends hp{constructor(t,e=null){super("float"),this.scope=t,this.valueNode=e,this.isViewportDepthNode=!0}generate(t){const{scope:e}=this;return e===eT.DEPTH?t.getFragDepth():super.generate(t)}setup({camera:t}){const{scope:e}=this,s=this.valueNode;let i=null;if(e===eT.DEPTH)i=null!==s?oT().assign(s):t.isPerspectiveCamera?rT(Wb.z,bx,vx):sT(Wb.z,bx,vx);else if(e===eT.LINEAR_DEPTH)if(null!==s)if(t.isPerspectiveCamera){const t=nT(s,bx,vx);i=sT(t,bx,vx)}else i=s;else i=sT(Wb.z,bx,vx);return i}}const sT=(t,e,s)=>t.add(e).div(e.sub(s)),iT=(t,e,s)=>e.sub(s).mul(t).sub(e),rT=(t,e,s)=>e.add(t).mul(s).div(s.sub(e).mul(t)),nT=(t,e,s)=>e.mul(s).div(s.sub(e).mul(t).sub(s));eT.DEPTH="depth",eT.LINEAR_DEPTH="linearDepth";const oT=Zp(eT,eT.DEPTH),aT=Qp(eT,eT.DEPTH),hT=Zp(eT,eT.LINEAR_DEPTH),uT=hT(tT());aT.assign=t=>oT(t),up("ViewportDepthNode",eT);class lT extends hp{constructor(t=lT.DEFAULT){super(),this.scope=t}setup(t){super.setup(t);const e=t.clippingContext,{localClipIntersection:s,localClippingCount:i,globalClippingCount:r}=e,n=r+i,o=s?n-i:n;return this.scope===lT.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(e.planes,n,o):this.setupDefault(e.planes,n,o)}setupAlphaToCoverage(t,e,s){return Kp((()=>{const i=cx(t),r=pg("float","distanceToPlane"),n=pg("float","distanceToGradient"),o=pg("float","clipOpacity");let a;if(o.assign(1),dv(s,(({i:t})=>{a=i.element(t),r.assign(Wb.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),o.mulAssign(Dy(n.negate(),n,r)),o.equal(0).discard()})),s{a=i.element(e),r.assign(Wb.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),t.mulAssign(Dy(n.negate(),n,r).oneMinus())})),o.mulAssign(t.oneMinus())}gg.a.mulAssign(o),gg.a.equal(0).discard()}))()}setupDefault(t,e,s){return Kp((()=>{const i=cx(t);let r;if(dv(s,(({i:t})=>{r=i.element(t),Wb.dot(r.xyz).greaterThan(r.w).discard()})),s{r=i.element(e),t.assign(Wb.dot(r.xyz).greaterThan(r.w).and(t))})),t.discard()}}))()}}lT.ALPHA_TO_COVERAGE="alphaToCoverage",lT.DEFAULT="default";class cT extends hp{constructor(){super("bool"),this.isFrontFacingNode=!0}generate(t){const{renderer:e,material:s}=t;return e.coordinateSystem===Vs&&s.side===d?"false":t.getFrontFacing()}}const dT=Qp(cT),pT=nm(dT).mul(2).sub(1);up("FrontFacingNode",cT);const mT=new Map;class gT extends Qr{constructor(){super(),this.isNodeMaterial=!0,this.type=this.constructor.type,this.forceSinglePass=!1,this.fog=!0,this.lights=!0,this.normals=!0,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.depthNode=null,this.shadowNode=null,this.shadowPositionNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+Kd(this)}build(t){this.setup(t)}setup(t){let e;t.addStack(),t.stack.outputNode=this.vertexNode||this.setupPosition(t),t.addFlow("vertex",t.removeStack()),t.addStack();const s=this.setupClipping(t);if(!0===this.depthWrite&&this.setupDepth(t),null===this.fragmentNode){!0===this.normals&&this.setupNormal(t),this.setupDiffuseColor(t),this.setupVariants(t);const i=this.setupLighting(t);null!==s&&t.stack.add(s);const r=ym(i,gg.a).max(0);e=this.setupOutput(t,r),Pg.assign(e),null!==this.outputNode&&(e=this.outputNode);if(null!==t.renderer.getRenderTarget()){const s=t.renderer.getMRT(),i=this.mrtNode;null!==s?(e=s,null!==i&&(e=s.merge(i))):null!==i&&(e=i)}}else{let s=this.fragmentNode;!0!==s.isOutputStructNode&&(s=ym(s)),e=this.setupOutput(t,s)}t.stack.outputNode=e,t.addFlow("fragment",t.removeStack())}setupClipping(t){if(null===t.clippingContext)return null;const{globalClippingCount:e,localClippingCount:s}=t.clippingContext;let i=null;return(e||s)&&(this.alphaToCoverage?i=Xp(new lT(lT.ALPHA_TO_COVERAGE)):t.stack.add(Xp(new lT))),i}setupDepth(t){const{renderer:e}=t;let s=this.depthNode;if(null===s&&!0===e.logarithmicDepthBuffer){s=qb().w.add(1).log2().mul(Tx).mul(.5)}null!==s&&aT.assign(s).append()}setupPosition(t){const{object:e}=t,s=e.geometry;if(t.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&bv(e).append(),!0===e.isSkinnedMesh&&lv(e).append(),this.displacementMap){const t=yx("displacementMap","texture"),e=yx("displacementScale","float"),s=yx("displacementBias","float");Db.addAssign(qx.normalize().mul(t.x.mul(e).add(s)))}e.isBatchedMesh&&av(e).append(),e.instanceMatrix&&!0===e.instanceMatrix.isInstancedBufferAttribute&&Kb(e).append(),null!==this.positionNode&&Db.assign(this.positionNode);const i=qb();return t.context.vertex=t.removeStack(),t.context.mvp=i,i}setupDiffuseColor({object:t,geometry:e}){let s=this.colorNode?ym(this.colorNode):eb;if(!0===this.vertexColors&&e.hasAttribute("color")&&(s=ym(s.xyz.mul(Wm("color","vec3")),s.a)),t.instanceColor){s=mg("vec3","vInstanceColor").mul(s)}gg.assign(s);const i=this.opacityNode?nm(this.opacityNode):rb;if(gg.a.assign(gg.a.mul(i)),null!==this.alphaTestNode||this.alphaTest>0){const t=null!==this.alphaTestNode?nm(this.alphaTestNode):tb;gg.a.lessThanEqual(t).discard()}!1===this.transparent&&1===this.blending&&!1===this.alphaToCoverage&&gg.a.assign(1)}setupVariants(){}setupNormal(){if(!0===this.flatShading){const t=Wb.dFdx().cross(Wb.dFdy()).normalize();Yx.assign(t.mul(pT))}else{const t=this.normalNode?pm(this.normalNode):db;Yx.assign(t.mul(pT))}}setupEnvironment(t){let e=null;return this.envNode?e=this.envNode:this.envMap?e=this.envMap.isCubeTexture?Mv(this.envMap):rx(this.envMap):t.environmentNode&&(e=t.environmentNode),e}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new zv(Ub)),e}setupLights(t){const e=[],s=this.setupEnvironment(t);s&&s.isLightingNode&&e.push(s);const i=this.setupLightMap(t);if(i&&i.isLightingNode&&e.push(i),null!==this.aoNode||t.material.aoMap){const t=null!==this.aoNode?this.aoNode:Ob;e.push(new Fv(t))}let r=this.lightsNode||t.lightsNode;return e.length>0&&(r=Iv([...r.lightNodes,...e])),r}setupLightingModel(){}setupLighting(t){const{material:e}=t,{backdropNode:s,backdropAlphaNode:i,emissiveNode:r}=this,n=!0===this.lights||null!==this.lightsNode?this.setupLights(t):null;let o=gg.rgb;if(n&&!1!==n.hasLight){const e=this.setupLightingModel(t);o=Ov(n,e,s,i)}else null!==s&&(o=pm(null!==i?Oy(o,s,i):s));return(r&&!0===r.isNode||e.emissive&&!0===e.emissive.isColor)&&(fg.assign(pm(r||ib)),o=o.add(fg)),o}setupOutput(t,e){if(!0===this.fog){const s=t.fogNode;s&&(e=ym(s.mix(e.rgb,s.colorNode),e.a))}return e}setDefaultValues(t){for(const e in t){const s=t[e];void 0===this[e]&&(this[e]=s,s&&s.clone&&(this[e]=s.clone()))}const e=Object.getOwnPropertyDescriptors(t.constructor.prototype);for(const t in e)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,t)&&void 0!==e[t].get&&Object.defineProperty(this.constructor.prototype,t,e[t])}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{},nodes:{}});const s=Qr.prototype.toJSON.call(this,t),i=tp(this);s.inputNodes={};for(const{property:e,childNode:r}of i)s.inputNodes[e]=r.toJSON(t).uuid;function r(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(e){const e=r(t.textures),i=r(t.images),n=r(t.nodes);e.length>0&&(s.textures=e),i.length>0&&(s.images=i),n.length>0&&(s.nodes=n)}return s}copy(t){return this.lightsNode=t.lightsNode,this.envNode=t.envNode,this.colorNode=t.colorNode,this.normalNode=t.normalNode,this.opacityNode=t.opacityNode,this.backdropNode=t.backdropNode,this.backdropAlphaNode=t.backdropAlphaNode,this.alphaTestNode=t.alphaTestNode,this.positionNode=t.positionNode,this.depthNode=t.depthNode,this.shadowNode=t.shadowNode,this.shadowPositionNode=t.shadowPositionNode,this.outputNode=t.outputNode,this.mrtNode=t.mrtNode,this.fragmentNode=t.fragmentNode,this.vertexNode=t.vertexNode,super.copy(t)}static fromMaterial(t){if(!0===t.isNodeMaterial)return t;const e=yT(t.type.replace("Material","NodeMaterial"));if(void 0===e)throw new Error(`NodeMaterial: Material "${t.type}" is not compatible.`);for(const s in t)e[s]=t[s];return e}}function fT(t,e){if("function"!=typeof e||!t)throw new Error(`Node material ${t} is not a class`);mT.has(t)?console.warn(`Redefinition of node material ${t}`):(mT.set(t,e),e.type=t)}function yT(t){const e=mT.get(t);if(void 0!==e)return new e}fT("NodeMaterial",gT);class xT{constructor(t,e){this.name=t,this.value=e,this.boundary=0,this.itemSize=0,this.offset=0}setValue(t){this.value=t}getValue(){return this.value}}class bT extends xT{constructor(t,e=0){super(t,e),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class vT extends xT{constructor(t,e=new Ks){super(t,e),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class TT extends xT{constructor(t,e=new Ei){super(t,e),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class _T extends xT{constructor(t,e=new _i){super(t,e),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class wT extends xT{constructor(t,e=new Yr){super(t,e),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class ST extends xT{constructor(t,e=new ti){super(t,e),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class MT extends xT{constructor(t,e=new or){super(t,e),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class AT extends bT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class NT extends vT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class RT extends TT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class CT extends _T{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class ET extends wT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class BT extends ST{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class IT extends MT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class PT extends hp{constructor(t,e,s=null){super(),this.condNode=t,this.ifNode=e,this.elseNode=s}getNodeType(t){const e=this.ifNode.getNodeType(t);if(null!==this.elseNode){const s=this.elseNode.getNodeType(t);if(t.getTypeLength(s)>t.getTypeLength(e))return s}return e}setup(t){const e=t.getNodeProperties(this);e.condNode=this.condNode.cache(),e.ifNode=this.ifNode.cache(),e.elseNode=this.elseNode?this.elseNode.cache():null}generate(t,e){const s=this.getNodeType(t),i=t.getDataFromNode(this);if(void 0!==i.nodeProperty)return i.nodeProperty;const{condNode:r,ifNode:n,elseNode:o}=t.getNodeProperties(this),a="void"!==e,h=a?pg(s).build(t):"";i.nodeProperty=h;const u=r.build(t,"bool");t.addFlowCode(`\n${t.tab}if ( ${u} ) {\n\n`).addFlowTab();let l=n.build(t,s);if(l&&(l=a?h+" = "+l+";":"return "+l+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+l+"\n\n"+t.tab+"}"),null!==o){t.addFlowCode(" else {\n\n").addFlowTab();let e=o.build(t,s);e&&(e=a?h+" = "+e+";":"return "+e+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+e+"\n\n"+t.tab+"}\n\n")}else t.addFlowCode("\n\n");return t.format(h,s,e)}}const FT=Zp(PT);_p("cond",FT),up("CondNode",PT);class UT extends hp{constructor(t=null){super(),this.nodes=[],this.outputNode=null,this.parent=t,this._currentCond=null,this.isStackNode=!0}getNodeType(t){return this.outputNode?this.outputNode.getNodeType(t):"void"}add(t){return this.nodes.push(t),this}if(t,e){const s=new $p(e);return this._currentCond=FT(t,s),this.add(this._currentCond)}elseif(t,e){const s=new $p(e),i=FT(t,s);return this._currentCond.elseNode=i,this._currentCond=i,this}else(t){return this._currentCond.elseNode=new $p(t),this}build(t,...e){const s=em();tm(this);for(const e of this.nodes)e.build(t,"void");return tm(s),this.outputNode?this.outputNode.build(t,...e):super.build(t,...e)}}const OT=Zp(UT);up("StackNode",UT);class zT extends cp{constructor(t=Gb){super("vec2"),this.dirNode=t}setup(){const t=this.dirNode,e=t.z.atan2(t.x).mul(1/(2*Math.PI)).add(.5),s=t.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return um(e,s)}}const LT=Zp(zT);up("EquirectUVNode",zT);class VT extends so{constructor(t=1,e={}){super(t,e),this.isCubeRenderTarget=!0}fromEquirectangularTexture(t,e){const s=e.minFilter,i=e.generateMipmaps;e.generateMipmaps=!0,this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const r=new Hn(5,5,5),n=LT(Gb),o=yT("MeshBasicNodeMaterial");o.colorNode=rx(e,n,0),o.side=d,o.blending=m;const a=new Wn(r,o),h=new no;h.add(a),e.minFilter===St&&(e.minFilter=Tt);return new to(1,10,this).update(t,h),e.minFilter=s,e.currentGenerateMipmaps=i,a.geometry.dispose(),a.material.dispose(),this}}const DT=nm(1),kT=nm(-2),GT=nm(.8),WT=nm(-1),jT=nm(.4),HT=nm(2),qT=nm(.305),$T=nm(3),XT=nm(.21),YT=nm(4),JT=nm(4),ZT=nm(16),QT=Kp((([t])=>{const e=pm(oy(t)).toVar(),s=nm(-1).toVar();return sm(e.x.greaterThan(e.z),(()=>{sm(e.x.greaterThan(e.y),(()=>{s.assign(FT(t.x.greaterThan(0),0,3))})).else((()=>{s.assign(FT(t.y.greaterThan(0),1,4))}))})).else((()=>{sm(e.z.greaterThan(e.y),(()=>{s.assign(FT(t.z.greaterThan(0),2,5))})).else((()=>{s.assign(FT(t.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),KT=Kp((([t,e])=>{const s=um().toVar();return sm(e.equal(0),(()=>{s.assign(um(t.z,t.y).div(oy(t.x)))})).elseif(e.equal(1),(()=>{s.assign(um(t.x.negate(),t.z.negate()).div(oy(t.y)))})).elseif(e.equal(2),(()=>{s.assign(um(t.x.negate(),t.y).div(oy(t.z)))})).elseif(e.equal(3),(()=>{s.assign(um(t.z.negate(),t.y).div(oy(t.x)))})).elseif(e.equal(4),(()=>{s.assign(um(t.x.negate(),t.z).div(oy(t.y)))})).else((()=>{s.assign(um(t.x,t.y).div(oy(t.z)))})),gf(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),t_=Kp((([t])=>{const e=nm(0).toVar();return sm(t.greaterThanEqual(GT),(()=>{e.assign(DT.sub(t).mul(WT.sub(kT)).div(DT.sub(GT)).add(kT))})).elseif(t.greaterThanEqual(jT),(()=>{e.assign(GT.sub(t).mul(HT.sub(WT)).div(GT.sub(jT)).add(WT))})).elseif(t.greaterThanEqual(qT),(()=>{e.assign(jT.sub(t).mul($T.sub(HT)).div(jT.sub(qT)).add(HT))})).elseif(t.greaterThanEqual(XT),(()=>{e.assign(qT.sub(t).mul(YT.sub($T)).div(qT.sub(XT)).add($T))})).else((()=>{e.assign(nm(-2).mul($f(gf(1.16,t))))})),e})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),e_=Kp((([t,e])=>{const s=t.toVar();s.assign(gf(2,s).sub(1));const i=pm(s,1).toVar();return sm(e.equal(0),(()=>{i.assign(i.zyx)})).elseif(e.equal(1),(()=>{i.assign(i.xzy),i.xz.mulAssign(-1)})).elseif(e.equal(2),(()=>{i.x.mulAssign(-1)})).elseif(e.equal(3),(()=>{i.assign(i.zyx),i.xz.mulAssign(-1)})).elseif(e.equal(4),(()=>{i.assign(i.xzy),i.xy.mulAssign(-1)})).elseif(e.equal(5),(()=>{i.z.mulAssign(-1)})),i})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),s_=Kp((([t,e,s,i,r,n])=>{const o=nm(s),a=pm(e),h=zy(t_(o),kT,n),u=Kf(h),l=Jf(h),c=pm(i_(t,a,l,i,r,n)).toVar();return sm(u.notEqual(0),(()=>{const e=pm(i_(t,a,l.add(1),i,r,n)).toVar();c.assign(Oy(c,e,u))})),c})),i_=Kp((([t,e,s,i,r,n])=>{const o=nm(s).toVar(),a=pm(e),h=nm(QT(a)).toVar(),u=nm(Ty(JT.sub(o),0)).toVar();o.assign(Ty(o,JT));const l=nm(Hf(o)).toVar(),c=um(KT(a,h).mul(l.sub(2)).add(1)).toVar();return sm(h.greaterThan(2),(()=>{c.y.addAssign(l),h.subAssign(3)})),c.x.addAssign(h.mul(l)),c.x.addAssign(u.mul(gf(3,ZT))),c.y.addAssign(gf(4,Hf(n).sub(l))),c.x.mulAssign(i),c.y.mulAssign(r),t.uv(c).grad(um(),um())})),r_=Kp((({envMap:t,mipInt:e,outputDirection:s,theta:i,axis:r,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const h=ey(i),u=s.mul(h).add(r.cross(s).mul(ty(i))).add(r.mul(r.dot(s).mul(h.oneMinus())));return i_(t,u,e,n,o,a)})),n_=Kp((({n:t,latitudinal:e,poleAxis:s,outputDirection:i,weights:r,samples:n,dTheta:o,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c})=>{const d=pm(FT(e,s,Ry(s,i))).toVar();sm(Vf(d.equals(pm(0))),(()=>{d.assign(pm(i.z,0,i.x.negate()))})),d.assign(Qf(d));const p=pm().toVar();return p.addAssign(r.element(om(0)).mul(r_({theta:0,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c}))),dv({start:om(1),end:t},(({i:t})=>{sm(t.greaterThanEqual(n),(()=>{mv()}));const e=nm(o.mul(nm(t))).toVar();p.addAssign(r.element(t).mul(r_({theta:e.mul(-1),axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c}))),p.addAssign(r.element(t).mul(r_({theta:e,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c})))})),ym(p,1)})),o_=[.125,.215,.35,.446,.526,.582],a_=20,h_=new Rl(-1,1,1,-1,0,1),u_=new Qn(90,1),l_=new Yr;let c_=null,d_=0,p_=0;const m_=(1+Math.sqrt(5))/2,g_=1/m_,f_=[new Ei(-m_,g_,0),new Ei(m_,g_,0),new Ei(-g_,0,m_),new Ei(g_,0,m_),new Ei(0,m_,-g_),new Ei(0,m_,g_),new Ei(-1,1,-1),new Ei(1,1,-1),new Ei(-1,1,1),new Ei(1,1,1)],y_=[3,1,5,0,4,2],x_=e_(uf(),Wm("faceIndex")).normalize(),b_=pm(x_.x,x_.y.negate(),x_.z);class v_{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(t,e=0,s=.1,i=100){c_=this._renderer.getRenderTarget(),d_=this._renderer.getActiveCubeFace(),p_=this._renderer.getActiveMipmapLevel(),this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(t,s,i,r),e>0&&this._blur(r,0,0,e),this._applyPMREM(r),this._cleanup(r),r}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=S_(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=M_(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let t=0;tt-4?h=o_[a-t+4-1]:0===a&&(h=0),i.push(h);const u=1/(o-2),l=-u,c=1+u,d=[l,l,c,l,c,c,l,l,c,c,l,c],p=6,m=6,g=3,f=2,y=1,x=new Float32Array(g*m*p),b=new Float32Array(f*m*p),v=new Float32Array(y*m*p);for(let t=0;t2?0:-1,i=[e,s,0,e+2/3,s,0,e+2/3,s+1,0,e,s,0,e+2/3,s+1,0,e,s+1,0],r=y_[t];x.set(i,g*m*r),b.set(d,f*m*r);const n=[r,r,r,r,r,r];v.set(n,y*m*r)}const T=new Mn;T.setAttribute("position",new hn(x,g)),T.setAttribute("uv",new hn(b,f)),T.setAttribute("faceIndex",new hn(v,y)),e.push(T),r.push(new Wn(T,null)),n>4&&n--}return{lodPlanes:e,sizeLods:s,sigmas:i,lodMeshes:r}}(i)),this._blurMaterial=function(t,e,s){const i=cx(new Array(a_).fill(0)),r=hf(new Ei(0,1,0)),n=hf(0),o=nm(a_),a=hf(0),h=hf(1),u=rx(null),l=hf(0),c=nm(1/e),d=nm(1/s),p=nm(t),m={n:o,latitudinal:a,weights:i,poleAxis:r,outputDirection:b_,dTheta:n,samples:h,envMap:u,mipInt:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:p},g=w_();return g.uniforms=m,g.fragmentNode=n_({...m,latitudinal:a.equal(1)}),g}(i,t,e)}return i}_compileMaterial(t){const e=this._lodMeshes[0];e.material=t,this._renderer.compile(e,h_)}_sceneToCubeUV(t,e,s,i){const r=u_;r.near=e,r.far=s;const n=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,h=a.autoClear;a.getClearColor(l_),a.autoClear=!1;let u=this._backgroundBox;if(null===u){const t=new Kr({name:"PMREM.Background",side:d,depthWrite:!1,depthTest:!1});u=new Wn(new Hn,t)}let l=!1;const c=t.background;c?c.isColor&&(u.material.color.copy(c),t.background=null,l=!0):(u.material.color.copy(l_),l=!0),a.setRenderTarget(i),a.clear(),l&&a.render(u,r);for(let e=0;e<6;e++){const s=e%3;0===s?(r.up.set(0,n[e],0),r.lookAt(o[e],0,0)):1===s?(r.up.set(0,0,n[e]),r.lookAt(0,o[e],0)):(r.up.set(0,n[e],0),r.lookAt(0,0,o[e]));const h=this._cubeSize;__(i,s*h,e>2?h:0,h,h),a.render(t,r)}a.autoClear=h,t.background=c}_textureToCubeUV(t,e){const s=this._renderer,i=t.mapping===ht||t.mapping===ut;i?null===this._cubemapMaterial&&(this._cubemapMaterial=S_(t)):null===this._equirectMaterial&&(this._equirectMaterial=M_(t));const r=i?this._cubemapMaterial:this._equirectMaterial;r.fragmentNode.value=t;const n=this._lodMeshes[0];n.material=r;const o=this._cubeSize;__(e,0,0,3*o,2*o),s.setRenderTarget(e),s.render(n,h_)}_applyPMREM(t){const e=this._renderer,s=e.autoClear;e.autoClear=!1;const i=this._lodPlanes.length;for(let e=1;ea_&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${m} samples when the maximum is set to 20`);const g=[];let f=0;for(let t=0;ty-4?i-y+4:0),4*(this._cubeSize-x),3*x,2*x),a.setRenderTarget(e),a.render(u,h_)}}function T_(t,e,s){const i=new wi(t,e,s);return i.texture.mapping=306,i.texture.name="PMREM.cubeUv",i.texture.isPMREMTexture=!0,i.scissorTest=!0,i}function __(t,e,s,i,r){const n=t.height-r-s;t.viewport.set(e,n,i,r),t.scissor.set(e,n,i,r)}function w_(){const t=new gT;return t.depthTest=!1,t.depthWrite=!1,t.blending=m,t}function S_(t){const e=w_();return e.fragmentNode=Mv(t,b_),e}function M_(t){const e=w_();return e.fragmentNode=rx(t,LT(b_),0),e}let A_=0;class N_{constructor(t="",e=[]){this.name=t,this.bindings=e,this.id=A_++}}const R_=new WeakMap,C_=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),E_=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),B_=t=>(t=Number(t))+(t%1?"":".0");class I_{constructor(t,e,s){this.object=t,this.material=t&&t.material||null,this.geometry=t&&t.geometry||null,this.renderer=e,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=OT(),this.stacks=[],this.tab="\t",this.instanceBindGroups=!0,this.currentFunctionNode=null,this.context={keywords:new ug,material:this.material},this.cache=new cg,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null}getBingGroupsCache(){let t=R_.get(this.renderer);return void 0===t&&(t=new _d,R_.set(this.renderer,t)),t}createRenderTarget(t,e,s){return new wi(t,e,s)}createCubeRenderTarget(t,e){return new VT(t,e)}createPMREMGenerator(){return new v_(this.renderer)}includes(t){return this.nodes.includes(t)}_getBindGroup(t,e){const s=this.getBingGroupsCache(),i=[];let r,n=!0;for(const t of e)i.push(t),n=n&&!0!==t.groupNode.shared;return n?(r=s.get(i),void 0===r&&(r=new N_(t,i),s.set(i,r))):r=new N_(t,i),r}getBindGroupArray(t,e){const s=this.bindings[e];let i=s[t];return void 0===i&&(void 0===this.bindingsIndexes[t]&&(this.bindingsIndexes[t]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[t]=i=[]),i}getBindings(){let t=this.bindGroups;if(null===t){const e={},s=this.bindings;for(const t of Zd)for(const i in s[t]){const r=s[t][i];(e[i]||(e[i]=[])).push(...r)}t=[];for(const s in e){const i=e[s],r=this._getBindGroup(s,i);t.push(r)}this.bindGroups=t}return t}setHashNode(t,e){this.hashNodes[e]=t}addNode(t){!1===this.nodes.includes(t)&&(this.nodes.push(t),this.setHashNode(t,t.getHash(this)))}buildUpdateNodes(){for(const t of this.nodes){const e=t.getUpdateType(),s=t.getUpdateBeforeType(),i=t.getUpdateAfterType();e!==$d.NONE&&this.updateNodes.push(t.getSelf()),s!==$d.NONE&&this.updateBeforeNodes.push(t),i!==$d.NONE&&this.updateAfterNodes.push(t)}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(t){return t.magFilter===Tt||t.magFilter===_t||t.magFilter===bt||t.magFilter===St||t.minFilter===Tt||t.minFilter===_t||t.minFilter===bt||t.minFilter===St}addChain(t){this.chaining.push(t)}removeChain(t){if(this.chaining.pop()!==t)throw new Error("NodeBuilder: Invalid node chaining!")}getMethod(t){return t}getNodeFromHash(t){return this.hashNodes[t]}addFlow(t,e){return this.flowNodes[t].push(e),e}setContext(t){this.context=t}getContext(){return this.context}getSharedContext(){return this.context,this.context}setCache(t){this.cache=t}getCache(){return this.cache}getCacheFromNode(t,e=!0){const s=this.getDataFromNode(t);return void 0===s.cache&&(s.cache=new cg(e?this.getCache():null)),s.cache}isAvailable(){return!1}getVertexIndex(){console.warn("Abstract function.")}getInstanceIndex(){console.warn("Abstract function.")}getDrawIndex(){console.warn("Abstract function.")}getFrontFacing(){console.warn("Abstract function.")}getFragCoord(){console.warn("Abstract function.")}isFlipY(){return!1}generateTexture(){console.warn("Abstract function.")}generateTextureLod(){console.warn("Abstract function.")}generateConst(t,e=null){if(null===e&&("float"===t||"int"===t||"uint"===t?e=0:"bool"===t?e=!1:"color"===t?e=new Yr:"vec2"===t?e=new Ks:"vec3"===t?e=new Ei:"vec4"===t&&(e=new _i)),"float"===t)return B_(e);if("int"===t)return`${Math.round(e)}`;if("uint"===t)return e>=0?`${Math.round(e)}u`:"0u";if("bool"===t)return e?"true":"false";if("color"===t)return`${this.getType("vec3")}( ${B_(e.r)}, ${B_(e.g)}, ${B_(e.b)} )`;const s=this.getTypeLength(t),i=this.getComponentType(t),r=t=>this.generateConst(i,t);if(2===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)} )`;if(3===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)}, ${r(e.z)} )`;if(4===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)}, ${r(e.z)}, ${r(e.w)} )`;if(s>4&&e&&(e.isMatrix3||e.isMatrix4))return`${this.getType(t)}( ${e.elements.map(r).join(", ")} )`;if(s>4)return`${this.getType(t)}()`;throw new Error(`NodeBuilder: Type '${t}' not found in generate constant attempt.`)}getType(t){return"color"===t?"vec3":t}hasGeometryAttribute(t){return this.geometry&&void 0!==this.geometry.getAttribute(t)}getAttribute(t,e){const s=this.attributes;for(const e of s)if(e.name===t)return e;const i=new rg(t,e);return s.push(i),i}getPropertyName(t){return t.name}isVector(t){return/vec\d/.test(t)}isMatrix(t){return/mat\d/.test(t)}isReference(t){return"void"===t||"property"===t||"sampler"===t||"texture"===t||"cubeTexture"===t||"storageTexture"===t||"depthTexture"===t||"texture3D"===t}needsColorSpaceToLinear(){return!1}getComponentTypeFromTexture(t){const e=t.type;if(t.isDataTexture){if(e===Et)return"int";if(e===Bt)return"uint"}return"float"}getElementType(t){return"mat2"===t?"vec2":"mat3"===t?"vec3":"mat4"===t?"vec4":this.getComponentType(t)}getComponentType(t){if("float"===(t=this.getVectorType(t))||"bool"===t||"int"===t||"uint"===t)return t;const e=/(b|i|u|)(vec|mat)([2-4])/.exec(t);return null===e?null:"b"===e[1]?"bool":"i"===e[1]?"int":"u"===e[1]?"uint":"float"}getVectorType(t){return"color"===t?"vec3":"texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t?"vec4":t}getTypeFromLength(t,e="float"){if(1===t)return e;const s=C_.get(t);return("float"===e?"":e[0])+s}getTypeFromArray(t){return E_.get(t.constructor)}getTypeFromAttribute(t){let e=t;t.isInterleavedBufferAttribute&&(e=t.data);const s=e.array,i=t.itemSize,r=t.normalized;let n;return t instanceof fn||!0===r||(n=this.getTypeFromArray(s)),this.getTypeFromLength(i,n)}getTypeLength(t){const e=this.getVectorType(t),s=/vec([2-4])/.exec(e);return null!==s?Number(s[1]):"float"===e||"bool"===e||"int"===e||"uint"===e?1:!0===/mat2/.test(t)?4:!0===/mat3/.test(t)?9:!0===/mat4/.test(t)?16:0}getVectorFromMatrix(t){return t.replace("mat","vec")}changeComponentType(t,e){return this.getTypeFromLength(this.getTypeLength(t),e)}getIntegerType(t){const e=this.getComponentType(t);return"int"===e||"uint"===e?t:this.changeComponentType(t,"int")}addStack(){return this.stack=OT(this.stack),this.stacks.push(em()||this.stack),tm(this.stack),this.stack}removeStack(){const t=this.stack;return this.stack=t.parent,tm(this.stacks.pop()),t}getDataFromNode(t,e=this.shaderStage,s=null){let i=(s=null===s?t.isGlobal(this)?this.globalCache:this.cache:s).getData(t);return void 0===i&&(i={},s.setData(t,i)),void 0===i[e]&&(i[e]={}),i[e]}getNodeProperties(t,e="any"){const s=this.getDataFromNode(t,e);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(t,e){const s=this.getDataFromNode(t);let i=s.bufferAttribute;if(void 0===i){const r=this.uniforms.index++;i=new rg("nodeAttribute"+r,e,t),this.bufferAttributes.push(i),s.bufferAttribute=i}return i}getStructTypeFromNode(t,e=this.shaderStage){const s=this.getDataFromNode(t,e);if(void 0===s.structType){const i=this.structs.index++;t.name=`StructType${i}`,this.structs[e].push(t),s.structType=t}return t}getUniformFromNode(t,e,s=this.shaderStage,i=null){const r=this.getDataFromNode(t,s,this.globalCache);let n=r.uniform;if(void 0===n){const o=this.uniforms.index++;n=new ng(i||"nodeUniform"+o,e,t),this.uniforms[s].push(n),r.uniform=n}return n}getVarFromNode(t,e=null,s=t.getNodeType(this),i=this.shaderStage){const r=this.getDataFromNode(t,i);let n=r.variable;if(void 0===n){const t=this.vars[i]||(this.vars[i]=[]);null===e&&(e="nodeVar"+t.length),n=new og(e,s),t.push(n),r.variable=n}return n}getVaryingFromNode(t,e=null,s=t.getNodeType(this)){const i=this.getDataFromNode(t,"any");let r=i.varying;if(void 0===r){const t=this.varyings,n=t.length;null===e&&(e="nodeVarying"+n),r=new ag(e,s),t.push(r),i.varying=r}return r}getCodeFromNode(t,e,s=this.shaderStage){const i=this.getDataFromNode(t);let r=i.code;if(void 0===r){const t=this.codes[s]||(this.codes[s]=[]),n=t.length;r=new hg("nodeCode"+n,e),t.push(r),i.code=r}return r}addLineFlowCode(t){return""===t||(t=this.tab+t,/;\s*$/.test(t)||(t+=";\n"),this.flow.code+=t),this}addFlowCode(t){return this.flow.code+=t,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(t){return this.flowsData.get(t)}flowNode(t){const e=t.getNodeType(this),s=this.flowChildNode(t,e);return this.flowsData.set(t,s),s}buildFunctionNode(t){const e=new Jg,s=this.currentFunctionNode;return this.currentFunctionNode=e,e.code=this.buildFunctionCode(t),this.currentFunctionNode=s,e}flowShaderNode(t){const e=t.layout;let s;if(t.isArrayInput){s=[];for(const t of e.inputs)s.push(new Wg(t.type,t.name))}else{s={};for(const t of e.inputs)s[t.name]=new Wg(t.type,t.name)}t.layout=null;const i=t.call(s),r=this.flowStagesNode(i,e.type);return t.layout=e,r}flowStagesNode(t,e=null){const s=this.flow,i=this.vars,r=this.cache,n=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new cg,this.stack=OT();for(const s of Jd)this.setBuildStage(s),a.result=t.build(this,e);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=i,this.cache=r,this.stack=o,this.setBuildStage(n),a}getFunctionOperator(){return null}flowChildNode(t,e=null){const s=this.flow,i={code:""};return this.flow=i,i.result=t.build(this,e),this.flow=s,i}flowNodeFromShaderStage(t,e,s=null,i=null){const r=this.shaderStage;this.setShaderStage(t);const n=this.flowChildNode(e,s);return null!==i&&(n.code+=`${this.tab+i} = ${n.result};\n`),this.flowCode[t]=this.flowCode[t]+n.code,this.setShaderStage(r),n}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(t,e){return`${this.getType(t)} ${e}`}getVars(t){let e="";const s=this.vars[t];if(void 0!==s)for(const t of s)e+=`${this.getVar(t.type,t.name)}; `;return e}getUniforms(){console.warn("Abstract function.")}getCodes(t){const e=this.codes[t];let s="";if(void 0!==e)for(const t of e)s+=t.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(t){this.shaderStage=t}getShaderStage(){return this.shaderStage}setBuildStage(t){this.buildStage=t}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:t,material:e}=this;null!==e?gT.fromMaterial(e).build(this):this.addFlow("compute",t);for(const t of Jd){this.setBuildStage(t),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const e of Zd){this.setShaderStage(e);const s=this.flowNodes[e];for(const e of s)"generate"===t?this.flowNode(e):e.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(t,e){if("float"===e||"int"===e||"uint"===e)return new AT(t);if("vec2"===e||"ivec2"===e||"uvec2"===e)return new NT(t);if("vec3"===e||"ivec3"===e||"uvec3"===e)return new RT(t);if("vec4"===e||"ivec4"===e||"uvec4"===e)return new CT(t);if("color"===e)return new ET(t);if("mat3"===e)return new BT(t);if("mat4"===e)return new IT(t);throw new Error(`Uniform "${e}" not declared.`)}createNodeMaterial(t="NodeMaterial"){return yT(t)}format(t,e,s){if((e=this.getVectorType(e))===(s=this.getVectorType(s))||null===s||this.isReference(s))return t;const i=this.getTypeLength(e),r=this.getTypeLength(s);return i>4||r>4||0===r?t:i===r?`${this.getType(s)}( ${t} )`:i>r?this.format(`${t}.${"xyz".slice(0,r)}`,this.getTypeFromLength(r,this.getComponentType(e)),s):4===r&&i>1?`${this.getType(s)}( ${this.format(t,e,"vec3")}, 1.0 )`:2===i?`${this.getType(s)}( ${this.format(t,e,"vec2")}, 0.0 )`:(1===i&&r>1&&e!==this.getComponentType(s)&&(t=`${this.getType(this.getComponentType(s))}( ${t} )`),`${this.getType(s)}( ${t} )`)}getSignature(){return`// Three.js r${t} - Node System\n`}}class P_{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(t,e){let s=t.get(e);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},t.set(e,s)),s}updateBeforeNode(t){const e=t.getUpdateBeforeType(),s=t.updateReference(this);if(e===$d.FRAME){const{frameMap:e}=this._getMaps(this.updateBeforeMap,s);e.get(s)!==this.frameId&&!1!==t.updateBefore(this)&&e.set(s,this.frameId)}else if(e===$d.RENDER){const{renderMap:e}=this._getMaps(this.updateBeforeMap,s);e.get(s)!==this.renderId&&!1!==t.updateBefore(this)&&e.set(s,this.renderId)}else e===$d.OBJECT&&t.updateBefore(this)}updateAfterNode(t){const e=t.getUpdateAfterType(),s=t.updateReference(this);if(e===$d.FRAME){const{frameMap:e}=this._getMaps(this.updateAfterMap,s);e.get(s)!==this.frameId&&!1!==t.updateAfter(this)&&e.set(s,this.frameId)}else if(e===$d.RENDER){const{renderMap:e}=this._getMaps(this.updateAfterMap,s);e.get(s)!==this.renderId&&!1!==t.updateAfter(this)&&e.set(s,this.renderId)}else e===$d.OBJECT&&t.updateAfter(this)}updateNode(t){const e=t.getUpdateType(),s=t.updateReference(this);if(e===$d.FRAME){const{frameMap:e}=this._getMaps(this.updateMap,s);e.get(s)!==this.frameId&&!1!==t.update(this)&&e.set(s,this.frameId)}else if(e===$d.RENDER){const{renderMap:e}=this._getMaps(this.updateMap,s);e.get(s)!==this.renderId&&!1!==t.update(this)&&e.set(s,this.renderId)}else e===$d.OBJECT&&t.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class F_{constructor(t,e,s=null,i="",r=!1){this.type=t,this.name=e,this.count=s,this.qualifier=i,this.isConst=r}}F_.isNodeFunctionInput=!0;class U_ extends hp{constructor(t){super(),this.types=t,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}up("StructTypeNode",U_);class O_ extends hp{constructor(...t){super(),this.members=t,this.isOutputStructNode=!0}setup(t){super.setup(t);const e=this.members,s=[];for(let i=0;iCy(gf(4,t.mul(mf(1,t))),e),j_=(t,e)=>t.lessThan(.5)?W_(t.mul(2),e).div(2):mf(1,W_(gf(mf(1,t),2),e).div(2)),H_=(t,e,s)=>Cy(ff(Cy(t,e),pf(Cy(t,e),Cy(mf(1,t),s))),1/e),q_=(t,e)=>ty(zf.mul(e.mul(t).sub(1))).div(zf.mul(e.mul(t).sub(1)));_p("parabola",W_),_p("gain",j_),_p("pcurve",H_),_p("sinc",q_);const $_=Kp((([t])=>t.fract().sub(.5).abs())),X_=Kp((([t])=>pm($_(t.z.add($_(t.y.mul(1)))),$_(t.z.add($_(t.x.mul(1)))),$_(t.y.add($_(t.x.mul(1))))))),Y_=Kp((([t,e,s])=>{const i=pm(t).toVar(),r=nm(1.4).toVar(),n=nm(0).toVar(),o=pm(i).toVar();return dv({start:nm(0),end:nm(3),type:"float",condition:"<="},(()=>{const t=pm(X_(o.mul(2))).toVar();i.addAssign(t.add(s.mul(nm(.1).mul(e)))),o.mulAssign(1.8),r.mulAssign(1.5),i.mulAssign(1.2);const a=nm($_(i.z.add($_(i.x.add($_(i.y)))))).toVar();n.addAssign(a.div(r)),o.addAssign(.14)})),n}));let J_;$_.setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),X_.setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Y_.setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class Z_ extends PT{constructor(t){J_=J_||tx("discard"),super(t,J_)}}const Q_=Zp(Z_),K_=t=>Q_(t).append(),tw=()=>tx("return").append();_p("discard",K_),up("DiscardNode",Z_);class ew extends hp{constructor(t=[],...e){super(),this.functionNodes=t,this.parametersNodes=e,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(t){const e=this.parametersNodes;let s=this._candidateFnCall;if(null===s){let i=null,r=-1;for(const s of this.functionNodes){const n=s.shaderNode.layout;if(null===n)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=n.inputs;if(e.length===o.length){let n=0;for(let s=0;sr&&(i=s,r=n)}}this._candidateFnCall=s=i(...e)}return s}}const sw=Zp(ew),iw=t=>(...e)=>sw(t,...e);up("FunctionOverloadingNode",ew);class rw extends cp{constructor(){super("vec2")}setup(){const t=pm(jb.z,0,jb.x.negate()).normalize(),e=jb.cross(t);return um(t.dot(Yx),e.dot(Yx)).mul(.495).add(.5)}}const nw=Qp(rw);up("MatcapUVNode",rw);class ow extends af{constructor(t=ow.LOCAL,e=1,s=0){super(s),this.scope=t,this.scale=e,this.updateType=$d.FRAME}update(t){const e=this.scope,s=this.scale;e===ow.LOCAL?this.value+=t.deltaTime*s:e===ow.DELTA?this.value=t.deltaTime*s:e===ow.FRAME?this.value=t.frameId:this.value=t.time*s}serialize(t){super.serialize(t),t.scope=this.scope,t.scale=this.scale}deserialize(t){super.deserialize(t),this.scope=t.scope,this.scale=t.scale}}ow.LOCAL="local",ow.GLOBAL="global",ow.DELTA="delta",ow.FRAME="frame";const aw=(t,e=0)=>Xp(new ow(ow.LOCAL,t,e)),hw=(t,e=0)=>Xp(new ow(ow.GLOBAL,t,e)),uw=(t,e=0)=>Xp(new ow(ow.DELTA,t,e)),lw=Qp(ow,ow.FRAME).toUint();up("TimerNode",ow);class cw extends hp{constructor(t=cw.SINE,e=aw()){super(),this.method=t,this.timeNode=e}getNodeType(t){return this.timeNode.getNodeType(t)}setup(){const t=this.method,e=Xp(this.timeNode);let s=null;return t===cw.SINE?s=e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5):t===cw.SQUARE?s=e.fract().round():t===cw.TRIANGLE?s=e.add(.5).fract().mul(2).sub(1).abs():t===cw.SAWTOOTH&&(s=e.fract()),s}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}cw.SINE="sine",cw.SQUARE="square",cw.TRIANGLE="triangle",cw.SAWTOOTH="sawtooth";const dw=Zp(cw,cw.SINE),pw=Zp(cw,cw.SQUARE),mw=Zp(cw,cw.TRIANGLE),gw=Zp(cw,cw.SAWTOOTH);up("OscNode",cw);class fw extends cp{constructor(t,e){super(),this.scope=t,this.node=e}getNodeType(t){return this.node.getNodeType(t)}setup(){const{scope:t,node:e}=this;let s=null;return t===fw.DIRECTION_TO_COLOR?s=e.mul(.5).add(.5):t===fw.COLOR_TO_DIRECTION&&(s=e.mul(2).sub(1)),s}}fw.DIRECTION_TO_COLOR="directionToColor",fw.COLOR_TO_DIRECTION="colorToDirection";const yw=Zp(fw,fw.DIRECTION_TO_COLOR),xw=Zp(fw,fw.COLOR_TO_DIRECTION);_p("directionToColor",yw),_p("colorToDirection",xw),up("PackingNode",fw);class bw extends hp{constructor(t,e,s,i=nm(0),r=nm(1)){super(),this.node=t,this.inLowNode=e,this.inHighNode=s,this.outLowNode=i,this.outHighNode=r,this.doClamp=!0}setup(){const{node:t,inLowNode:e,inHighNode:s,outLowNode:i,outHighNode:r,doClamp:n}=this;let o=t.sub(e).div(s.sub(e));return!0===n&&(o=o.clamp()),o.mul(r.sub(i)).add(i)}}const vw=Zp(bw,null,null,{doClamp:!1}),Tw=Zp(bw);_p("remap",vw),_p("remapClamp",Tw),up("RemapNode",bw);class _w extends cp{constructor(t,e,s=um(.5)){super("vec2"),this.uvNode=t,this.rotationNode=e,this.centerNode=s}setup(){const{uvNode:t,rotationNode:e,centerNode:s}=this;return t.sub(s).rotate(e).add(s)}}const ww=Zp(_w);_p("rotateUV",ww),up("RotateUVNode",_w);class Sw extends cp{constructor(t,e){super(),this.positionNode=t,this.rotationNode=e}getNodeType(t){return this.positionNode.getNodeType(t)}setup(t){const{rotationNode:e,positionNode:s}=this;if("vec2"===this.getNodeType(t)){const t=e.cos(),i=e.sin();return Tm(t,i,i.negate(),t).mul(s)}{const t=e,i=Cm(ym(1,0,0,0),ym(0,ey(t.x),ty(t.x).negate(),0),ym(0,ty(t.x),ey(t.x),0),ym(0,0,0,1)),r=Cm(ym(ey(t.y),0,ty(t.y),0),ym(0,1,0,0),ym(ty(t.y).negate(),0,ey(t.y),0),ym(0,0,0,1)),n=Cm(ym(ey(t.z),ty(t.z).negate(),0,0),ym(ty(t.z),ey(t.z),0,0),ym(0,0,1,0),ym(0,0,0,1));return i.mul(r).mul(n).mul(ym(s,1)).xyz}}}const Mw=Zp(Sw);_p("rotate",Mw),up("RotateNode",Sw);class Aw extends hp{constructor(t,e=uf(),s=nm(0)){super("vec2"),this.countNode=t,this.uvNode=e,this.frameNode=s}setup(){const{frameNode:t,uvNode:e,countNode:s}=this,{width:i,height:r}=s,n=t.mod(i.mul(r)).floor(),o=n.mod(i),a=r.sub(n.add(1).div(i).ceil()),h=s.reciprocal(),u=um(o,a);return e.add(u).mul(h)}}const Nw=Zp(Aw);up("SpriteSheetUVNode",Aw);class Rw extends dp{constructor(t,e){super(t,e),this.isStorageArrayElementNode=!0}set storageBufferNode(t){this.node=t}get storageBufferNode(){return this.node}setup(t){return!1===t.isAvailable("storageBuffer")&&(this.node.instanceIndex||!0!==this.node.bufferObject||t.setupPBO(this.node)),super.setup(t)}generate(t,e){let s;const i=t.context.assign;if(!1===t.isAvailable("storageBuffer")){const{node:e}=this;s=e.instanceIndex||!0!==this.node.bufferObject||!0===i?e.build(t):t.generatePBO(this)}else s=super.generate(t);if(!0!==i){const i=this.getNodeType(t);s=t.format(s,i,e)}return s}}const Cw=Zp(Rw);_p("storageElement",Cw),up("StorageArrayElementNode",Rw);class Ew extends hp{constructor(t,e=null,s=null,i=nm(1),r=Db,n=qx){super("vec4"),this.textureXNode=t,this.textureYNode=e,this.textureZNode=s,this.scaleNode=i,this.positionNode=r,this.normalNode=n}setup(){const{textureXNode:t,textureYNode:e,textureZNode:s,scaleNode:i,positionNode:r,normalNode:n}=this;let o=n.abs().normalize();o=o.div(o.dot(pm(1)));const a=r.yz.mul(i),h=r.zx.mul(i),u=r.xy.mul(i),l=t.value,c=null!==e?e.value:l,d=null!==s?s.value:l,p=rx(l,a).mul(o.x),m=rx(c,h).mul(o.y),g=rx(d,u).mul(o.z);return pf(p,m,g)}}const Bw=Zp(Ew),Iw=(...t)=>Bw(...t);_p("triplanarTexture",Iw),up("TriplanarTexturesNode",Ew);const Pw=new sa,Fw=new Ei,Uw=new Ei,Ow=new Ei,zw=new or,Lw=new Ei(0,0,-1),Vw=new _i,Dw=new Ei,kw=new Ei,Gw=new _i,Ww=new Ks,jw=new wi,Hw=um(jv.x.oneMinus(),jv.y);let qw=!1;class $w extends ix{constructor(t={}){super(jw.texture,Hw);const{target:e=new Pr,resolution:s=1,generateMipmaps:i=!1,bounces:r=!0}=t;this.target=e,this.resolution=s,this.generateMipmaps=i,this.bounces=r,this.updateBeforeType=r?$d.RENDER:$d.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(t,e){const s=this.resolution;e.getDrawingBufferSize(Ww),t.setSize(Math.round(Ww.width*s),Math.round(Ww.height*s))}setup(t){return this._updateResolution(jw,t.renderer),super.setup(t)}getTextureNode(){return this.textureNode}getVirtualCamera(t){let e=this.virtualCameras.get(t);return void 0===e&&(e=t.clone(),this.virtualCameras.set(t,e)),e}getRenderTarget(t){let e=this.renderTargets.get(t);return void 0===e&&(e=new wi(0,0,{type:Pt}),!0===this.generateMipmaps&&(e.texture.minFilter=1008,e.texture.generateMipmaps=!0),this.renderTargets.set(t,e)),e}updateBefore(t){if(!1===this.bounces&&qw)return!1;qw=!0;const{scene:e,camera:s,renderer:i,material:r}=t,{target:n}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(i.getDrawingBufferSize(Ww),this._updateResolution(a,i),Uw.setFromMatrixPosition(n.matrixWorld),Ow.setFromMatrixPosition(s.matrixWorld),zw.extractRotation(n.matrixWorld),Fw.set(0,0,1),Fw.applyMatrix4(zw),Dw.subVectors(Uw,Ow),Dw.dot(Fw)>0)return;Dw.reflect(Fw).negate(),Dw.add(Uw),zw.extractRotation(s.matrixWorld),Lw.set(0,0,-1),Lw.applyMatrix4(zw),Lw.add(Ow),kw.subVectors(Uw,Lw),kw.reflect(Fw).negate(),kw.add(Uw),o.coordinateSystem=s.coordinateSystem,o.position.copy(Dw),o.up.set(0,1,0),o.up.applyMatrix4(zw),o.up.reflect(Fw),o.lookAt(kw),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),Pw.setFromNormalAndCoplanarPoint(Fw,Uw),Pw.applyMatrix4(o.matrixWorldInverse),Vw.set(Pw.normal.x,Pw.normal.y,Pw.normal.z,Pw.constant);const h=o.projectionMatrix;Gw.x=(Math.sign(Vw.x)+h.elements[8])/h.elements[0],Gw.y=(Math.sign(Vw.y)+h.elements[9])/h.elements[5],Gw.z=-1,Gw.w=(1+h.elements[10])/h.elements[14],Vw.multiplyScalar(1/Vw.dot(Gw));h.elements[2]=Vw.x,h.elements[6]=Vw.y,h.elements[10]=Vw.z-0,h.elements[14]=Vw.w,this.value=a.texture,r.visible=!1;const u=i.getRenderTarget();i.setRenderTarget(a),i.render(e,o),i.setRenderTarget(u),r.visible=!0,qw=!1}}const Xw=t=>Xp(new $w(t)),Yw=new Rl(-1,1,1,-1,0,1);const Jw=new class extends Mn{constructor(t=!1){super();const e=!1===t?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new yn([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new yn(e,2))}};class Zw extends Wn{constructor(t=null){super(Jw,t),this.camera=Yw}renderAsync(t){return t.renderAsync(this,Yw)}render(t){t.render(this,Yw)}}const Qw=new Ks;class Kw extends ix{constructor(t,e=null,s=null,i={type:Pt}){const r=new wi(e,s,i);super(r.texture,uf()),this.node=t,this.width=e,this.height=s,this.renderTarget=r,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new Zw(new gT),this.updateBeforeType=$d.RENDER}get autoSize(){return null===this.width}setup(t){return this._rttNode=this.node.context(t.getSharedContext()),this._quadMesh.material.needsUpdate=!0,super.setup(t)}setSize(t,e){this.width=t,this.height=e;const s=t*this.pixelRatio,i=e*this.pixelRatio;this.renderTarget.setSize(s,i),this.textureNeedsUpdate=!0}setPixelRatio(t){this.pixelRatio=t,this.setSize(this.width,this.height)}updateBefore({renderer:t}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=t.getPixelRatio();const e=t.getSize(Qw);this.setSize(e.width,e.height)}this._quadMesh.material.fragmentNode=this._rttNode;const e=t.getRenderTarget();t.setRenderTarget(this.renderTarget),this._quadMesh.render(t),t.setRenderTarget(e)}clone(){const t=new ix(this.value,this.uvNode,this.levelNode);return t.sampler=this.sampler,t.referenceNode=this,t}}const tS=(t,...e)=>Xp(new Kw(Xp(t),...e));_p("toTexture",((t,...e)=>t.isTextureNode?t:tS(t,...e))),up("RTTNode",Kw);const eS=t=>t.mul(tv.w).xyz,sS=km(eS(Hx.cross(tv)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),iS=km(eS(qx.cross(ev)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),rS=km(eS($x.cross(sv)),"v_bitangentView").normalize().toVar("bitangentView"),nS=km(eS(Xx.cross(iv)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),oS=eS(Yx.cross(rv)).normalize().toVar("transformedBitangentView"),aS=oS.transformDirection(Sx).normalize().toVar("transformedBitangentWorld"),hS=Mm(sv,rS,$x),uS=jb.mul(hS),lS=(t,e)=>t.sub(uS.mul(e)),cS=(()=>{let t=Cg.cross(jb);return t=t.cross(Cg).normalize(),t=Oy(t,Yx,Ng.mul(yg.oneMinus()).oneMinus().pow2().pow2()).normalize(),t})();class dS extends Gm{constructor(t=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=t}getAttributeName(){const t=this.index;return"color"+(t>0?t:"")}generate(t){const e=this.getAttributeName(t);let s;return s=!0===t.hasGeometryAttribute(e)?super.generate(t):t.generateConst(this.nodeType,new _i(1,1,1,1)),s}serialize(t){super.serialize(t),t.index=this.index}deserialize(t){super.deserialize(t),this.index=t.index}}const pS=(...t)=>Xp(new dS(...t));up("VertexColorNode",dS);class mS extends px{constructor(t,e,s=null){super(t,e,s),this.renderer=s}updateReference(t){return this.reference=null!==this.renderer?this.renderer:t.renderer,this.reference}}const gS=(t,e,s)=>Xp(new mS(t,e,s));up("RendererReferenceNode",mS);const fS=1/6,yS=t=>gf(fS,gf(t,gf(t,t.negate().add(3)).sub(3)).add(1)),xS=t=>gf(fS,gf(t,gf(t,gf(3,t).sub(6))).add(4)),bS=t=>gf(fS,gf(t,gf(t,gf(-3,t).add(3)).add(3)).add(1)),vS=t=>gf(fS,Cy(t,3)),TS=t=>yS(t).add(xS(t)),_S=t=>bS(t).add(vS(t)),wS=t=>pf(-1,xS(t).div(yS(t).add(xS(t)))),SS=t=>pf(1,vS(t).div(bS(t).add(vS(t)))),MS=(t,e,s)=>{const i=t.uvNode,r=gf(i,e.zw).add(.5),n=Jf(r),o=Kf(r),a=TS(o.x),h=_S(o.x),u=wS(o.x),l=SS(o.x),c=wS(o.y),d=SS(o.y),p=um(n.x.add(u),n.y.add(c)).sub(.5).mul(e.xy),m=um(n.x.add(l),n.y.add(c)).sub(.5).mul(e.xy),g=um(n.x.add(u),n.y.add(d)).sub(.5).mul(e.xy),f=um(n.x.add(l),n.y.add(d)).sub(.5).mul(e.xy),y=TS(o.y).mul(pf(a.mul(t.uv(p).level(s)),h.mul(t.uv(m).level(s)))),x=_S(o.y).mul(pf(a.mul(t.uv(g).level(s)),h.mul(t.uv(f).level(s))));return y.add(x)};class AS extends cp{constructor(t,e=nm(3)){super("vec4"),this.textureNode=t,this.blurNode=e}setup(){return((t,e)=>{const s=um(t.size(om(e))),i=um(t.size(om(e.add(1)))),r=ff(1,s),n=ff(1,i),o=MS(t,ym(r,s),Jf(e)),a=MS(t,ym(n,i),Zf(e));return Kf(e).mix(o,a)})(this.textureNode,this.blurNode)}}const NS=Zp(AS);_p("bicubic",NS),up("TextureBicubicNode",AS);class RS extends hp{constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const CS=Qp(RS);up("PointUVNode",RS);class ES extends hp{constructor(t=ES.BACKGROUND_BLURRINESS,e=null){super(),this.scope=t,this.scene=e}setup(t){const e=this.scope,s=null!==this.scene?this.scene:t.scene;let i;return e===ES.BACKGROUND_BLURRINESS?i=mx("backgroundBlurriness","float",s):e===ES.BACKGROUND_INTENSITY?i=mx("backgroundIntensity","float",s):console.error("THREE.SceneNode: Unknown scope:",e),i}}ES.BACKGROUND_BLURRINESS="backgroundBlurriness",ES.BACKGROUND_INTENSITY="backgroundIntensity";const BS=Qp(ES,ES.BACKGROUND_BLURRINESS),IS=Qp(ES,ES.BACKGROUND_INTENSITY);up("SceneNode",ES);const PS="point-list",FS="line-list",US="line-strip",OS="triangle-list",zS="triangle-strip",LS="never",VS="less",DS="equal",kS="less-equal",GS="greater",WS="not-equal",jS="greater-equal",HS="always",qS="store",$S="load",XS="clear",YS="ccw",JS="none",ZS="front",QS="back",KS="uint16",tM="uint32",eM={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},sM="clamp-to-edge",iM="repeat",rM="mirror-repeat",nM="linear",oM="nearest",aM="zero",hM="one",uM="src",lM="one-minus-src",cM="src-alpha",dM="one-minus-src-alpha",pM="dst",mM="one-minus-dst",gM="dst-alpha",fM="one-minus-dst-alpha",yM="src-alpha-saturated",xM="constant",bM="one-minus-constant",vM="add",TM="subtract",_M="reverse-subtract",wM="min",SM="max",MM=0,AM=15,NM="keep",RM="zero",CM="replace",EM="invert",BM="increment-clamp",IM="decrement-clamp",PM="increment-wrap",FM="decrement-wrap",UM="storage",OM="read-only-storage",zM="write-only",LM="read-only",VM="unfilterable-float",DM="depth",kM="sint",GM="uint",WM="2d",jM="3d",HM="2d",qM="2d-array",$M="cube",XM="3d",YM="all",JM="vertex",ZM="instance",QM={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable"};class KM extends ax{constructor(t,e,s=0){super(t,e,s),this.isStorageBufferNode=!0,this.access=UM,this.bufferObject=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==t.isStorageBufferAttribute&&!0!==t.isStorageInstancedBufferAttribute&&(t.isInstancedBufferAttribute?t.isStorageInstancedBufferAttribute=!0:t.isStorageBufferAttribute=!0)}getHash(t){if(0===this.bufferCount){let e=t.globalCache.getData(this.value);return void 0===e&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getInputType(){return"storageBuffer"}element(t){return Cw(this,t)}setBufferObject(t){return this.bufferObject=t,this}setAccess(t){return this.access=t,this}toReadOnly(){return this.setAccess(OM)}generate(t){if(t.isAvailable("storageBuffer"))return super.generate(t);const e=this.getNodeType(t);null===this._attribute&&(this._attribute=Xb(this.value),this._varying=km(this._attribute));const s=this._varying.build(t,e);return t.registerTransform(s,this._attribute),s}}const tA=(t,e,s)=>Xp(new KM(t,e,s)),eA=(t,e,s)=>Xp(new KM(t,e,s).setBufferObject(!0));up("StorageBufferNode",KM);class sA extends ix{constructor(t,e,s=null){super(t,e),this.storeNode=s,this.isStorageTextureNode=!0,this.access=zM}getInputType(){return"storageTexture"}setup(t){super.setup(t);t.getNodeProperties(this).storeNode=this.storeNode}setAccess(t){return this.access=t,this}generate(t,e){let s;return s=null!==this.storeNode?this.generateStore(t):super.generate(t,e),s}toReadOnly(){return this.setAccess(LM)}toWriteOnly(){return this.setAccess(zM)}generateStore(t){const e=t.getNodeProperties(this),{uvNode:s,storeNode:i}=e,r=super.generate(t,"property"),n=s.build(t,"uvec2"),o=i.build(t,"vec4"),a=t.generateTextureStore(t,r,n,o);t.addLineFlowCode(a)}}const iA=Zp(sA),rA=(t,e,s)=>{const i=iA(t,e,s);return null!==s&&i.append(),i};up("StorageTextureNode",sA);const nA=Kp((({texture:t,uv:e})=>{const s=1e-4,i=pm().temp();return sm(e.x.lessThan(s),(()=>{i.assign(pm(1,0,0))})).elseif(e.y.lessThan(s),(()=>{i.assign(pm(0,1,0))})).elseif(e.z.lessThan(s),(()=>{i.assign(pm(0,0,1))})).elseif(e.x.greaterThan(.9999),(()=>{i.assign(pm(-1,0,0))})).elseif(e.y.greaterThan(.9999),(()=>{i.assign(pm(0,-1,0))})).elseif(e.z.greaterThan(.9999),(()=>{i.assign(pm(0,0,-1))})).else((()=>{const s=.01,r=t.uv(e.add(pm(-.01,0,0))).r.sub(t.uv(e.add(pm(s,0,0))).r),n=t.uv(e.add(pm(0,-.01,0))).r.sub(t.uv(e.add(pm(0,s,0))).r),o=t.uv(e.add(pm(0,0,-.01))).r.sub(t.uv(e.add(pm(0,0,s))).r);i.assign(pm(r,n,o))})),i.normalize()}));class oA extends ix{constructor(t,e=null,s=null){super(t,e,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return pm(.5,.5,.5)}setUpdateMatrix(){}setupUV(t,e){return e}generateUV(t,e){return e.build(t,"vec3")}normal(t){return nA({texture:this,uv:t})}}const aA=Zp(oA);up("Texture3DNode",oA);class hA extends px{constructor(t,e,s=null){super(t,e,s),this.userData=s}update(t){this.reference=null!==this.userData?this.userData:t.object.userData,super.update(t)}}const uA=(t,e,s)=>Xp(new hA(t,e,s));up("UserDataNode",hA);const lA=Kp((({base:t,blend:e})=>{const s=s=>e[s].lessThan(Uf).cond(e[s],t[s].oneMinus().div(e[s]).oneMinus().max(0));return pm(s("x"),s("y"),s("z"))})).setLayout({name:"burnColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),cA=Kp((({base:t,blend:e})=>{const s=s=>e[s].equal(1).cond(e[s],t[s].div(e[s].oneMinus()).max(0));return pm(s("x"),s("y"),s("z"))})).setLayout({name:"dodgeColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),dA=Kp((({base:t,blend:e})=>{const s=s=>t[s].oneMinus().mul(e[s].oneMinus()).oneMinus();return pm(s("x"),s("y"),s("z"))})).setLayout({name:"screenColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),pA=Kp((({base:t,blend:e})=>{const s=s=>t[s].lessThan(.5).cond(t[s].mul(e[s],2),t[s].oneMinus().mul(e[s].oneMinus()).oneMinus());return pm(s("x"),s("y"),s("z"))})).setLayout({name:"overlayColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]});class mA extends cp{constructor(t,e,s){super(),this.blendMode=t,this.baseNode=e,this.blendNode=s}setup(){const{blendMode:t,baseNode:e,blendNode:s}=this,i={base:e,blend:s};let r=null;return t===mA.BURN?r=lA(i):t===mA.DODGE?r=cA(i):t===mA.SCREEN?r=dA(i):t===mA.OVERLAY&&(r=pA(i)),r}}mA.BURN="burn",mA.DODGE="dodge",mA.SCREEN="screen",mA.OVERLAY="overlay";const gA=Zp(mA,mA.BURN),fA=Zp(mA,mA.DODGE),yA=Zp(mA,mA.OVERLAY),xA=Zp(mA,mA.SCREEN);_p("burn",gA),_p("dodge",fA),_p("overlay",yA),_p("screen",xA),up("BlendModeNode",mA);const bA=Kp((({textureNode:t,bumpScale:e})=>{const s=e=>t.cache().context({getUV:t=>e(t.uvNode||uf()),forceUVContext:!0}),i=nm(s((t=>t)));return um(nm(s((t=>t.add(t.dFdx())))).sub(i),nm(s((t=>t.add(t.dFdy())))).sub(i)).mul(e)})),vA=Kp((t=>{const{surf_pos:e,surf_norm:s,dHdxy:i}=t,r=e.dFdx().normalize(),n=s,o=e.dFdy().normalize().cross(n),a=n.cross(r),h=r.dot(o).mul(pT),u=h.sign().mul(i.x.mul(o).add(i.y.mul(a)));return h.abs().mul(s).sub(u).normalize()}));class TA extends cp{constructor(t,e=null){super("vec3"),this.textureNode=t,this.scaleNode=e}setup(){const t=null!==this.scaleNode?this.scaleNode:1,e=bA({textureNode:this.textureNode,bumpScale:t});return vA({surf_pos:Wb,surf_norm:$x,dHdxy:e})}}const _A=Zp(TA);_p("bumpMap",_A),up("BumpMapNode",TA);const wA=Kp((({color:t,adjustment:e})=>e.mix(BA(t.rgb),t.rgb))),SA=Kp((({color:t,adjustment:e})=>{const s=pf(t.r,t.g,t.b).div(3),i=t.r.max(t.g.max(t.b)),r=i.sub(s).mul(e).mul(-3);return Oy(t.rgb,i,r)})),MA=Kp((({color:t,adjustment:e})=>{const s=pm(.57735,.57735,.57735),i=e.cos();return pm(t.rgb.mul(i).add(s.cross(t.rgb).mul(e.sin()).add(s.mul(Ny(s,t.rgb).mul(i.oneMinus())))))}));class AA extends cp{constructor(t,e,s=nm(1)){super("vec3"),this.method=t,this.colorNode=e,this.adjustmentNode=s}setup(){const{method:t,colorNode:e,adjustmentNode:s}=this,i={color:e,adjustment:s};let r=null;return t===AA.SATURATION?r=wA(i):t===AA.VIBRANCE?r=SA(i):t===AA.HUE?r=MA(i):console.error(`${this.type}: Method "${this.method}" not supported!`),r}}AA.SATURATION="saturation",AA.VIBRANCE="vibrance",AA.HUE="hue";const NA=Zp(AA,AA.SATURATION),RA=Zp(AA,AA.VIBRANCE),CA=Zp(AA,AA.HUE),EA=pm(.2125,.7154,.0721),BA=(t,e=EA)=>Ny(t,e),IA=(t,e)=>Oy(pm(0),t,BA(t).sub(e).max(0));_p("saturation",NA),_p("vibrance",RA),_p("hue",CA),_p("threshold",IA),up("ColorAdjustmentNode",AA);const PA=Kp((t=>{const{eye_pos:e,surf_norm:s,mapN:i,uv:r}=t,n=e.dFdx(),o=e.dFdy(),a=r.dFdx(),h=r.dFdy(),u=s,l=o.cross(u),c=u.cross(n),d=l.mul(a.x).add(c.mul(h.x)),p=l.mul(a.y).add(c.mul(h.y)),m=d.dot(d).max(p.dot(p)),g=pT.mul(m.inverseSqrt());return pf(d.mul(i.x,g),p.mul(i.y,g),u.mul(i.z)).normalize()}));class FA extends cp{constructor(t,e=null){super("vec3"),this.node=t,this.scaleNode=e,this.normalMapType=0}setup(t){const{normalMapType:e,scaleNode:s}=this;let i=this.node.mul(2).sub(1);null!==s&&(i=pm(i.xy.mul(s),i.z));let r=null;if(1===e)r=Vx.mul(i).normalize();else if(0===e){r=!0===t.hasGeometryAttribute("tangent")?hS.mul(i).normalize():PA({eye_pos:Wb,surf_norm:$x,mapN:i,uv:uf()})}return r}}const UA=Zp(FA);_p("normalMap",UA),up("NormalMapNode",FA);class OA extends cp{constructor(t,e){super(),this.sourceNode=t,this.stepsNode=e}setup(){const{sourceNode:t,stepsNode:e}=this;return t.mul(e).floor().div(e)}}const zA=Zp(OA);_p("posterize",zA),up("PosterizeNode",OA);const LA=Kp((({color:t,exposure:e})=>t.mul(e).clamp())),VA=Kp((({color:t,exposure:e})=>(t=t.mul(e)).div(t.add(1)).clamp())),DA=Kp((({color:t,exposure:e})=>{const s=(t=(t=t.mul(e)).sub(.004).max(0)).mul(t.mul(6.2).add(.5)),i=t.mul(t.mul(6.2).add(1.7)).add(.06);return s.div(i).pow(2.2)})),kA=Kp((({color:t})=>{const e=t.mul(t.add(.0245786)).sub(90537e-9),s=t.mul(t.add(.432951).mul(.983729)).add(.238081);return e.div(s)})),GA=Kp((({color:t,exposure:e})=>{const s=Mm(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),i=Mm(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return t=t.mul(e).div(.6),t=s.mul(t),t=kA({color:t}),(t=i.mul(t)).clamp()})),WA=Mm(pm(1.6605,-.1246,-.0182),pm(-.5876,1.1329,-.1006),pm(-.0728,-.0083,1.1187)),jA=Mm(pm(.6274,.0691,.0164),pm(.3293,.9195,.088),pm(.0433,.0113,.8956)),HA=Kp((([t])=>{const e=pm(t).toVar(),s=pm(e.mul(e)).toVar(),i=pm(s.mul(s)).toVar();return nm(15.5).mul(i.mul(s)).sub(gf(40.14,i.mul(e))).add(gf(31.96,i).sub(gf(6.868,s.mul(e))).add(gf(.4298,s).add(gf(.1191,e).sub(.00232))))})),qA=Kp((({color:t,exposure:e})=>{const s=pm(t).toVar(),i=Mm(pm(.856627153315983,.137318972929847,.11189821299995),pm(.0951212405381588,.761241990602591,.0767994186031903),pm(.0482516061458583,.101439036467562,.811302368396859)),r=Mm(pm(1.1271005818144368,-.1413297634984383,-.14132976349843826),pm(-.11060664309660323,1.157823702216272,-.11060664309660294),pm(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=nm(-12.47393),o=nm(4.026069);return s.mulAssign(e),s.assign(jA.mul(s)),s.assign(i.mul(s)),s.assign(Ty(s,1e-10)),s.assign($f(s)),s.assign(s.sub(n).div(o.sub(n))),s.assign(zy(s,0,1)),s.assign(HA(s)),s.assign(r.mul(s)),s.assign(Cy(Ty(pm(0),s),pm(2.2))),s.assign(WA.mul(s)),s.assign(zy(s,0,1)),s})),$A=Kp((({color:t,exposure:e})=>{const s=nm(.76),i=nm(.15);t=t.mul(e);const r=vy(t.r,vy(t.g,t.b)),n=FT(r.lessThan(.08),r.sub(gf(6.25,r.mul(r))),.04);t.subAssign(n);const o=Ty(t.r,Ty(t.g,t.b));sm(o.lessThan(s),(()=>t));const a=mf(1,s),h=mf(1,a.mul(a).div(o.add(a.sub(s))));t.mulAssign(h.div(o));const u=mf(1,ff(1,i.mul(o.sub(h)).add(1)));return Oy(t,pm(h),u)})).setLayout({name:"NeutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),XA={1:LA,2:VA,3:DA,4:GA,6:qA,7:$A};class YA extends cp{constructor(t=0,e=ZA,s=null){super("vec3"),this.toneMapping=t,this.exposureNode=e,this.colorNode=s}getCacheKey(){let t=super.getCacheKey();return t="{toneMapping:"+this.toneMapping+",nodes:"+t+"}",t}setup(t){const e=this.colorNode||t.context.color,s=this.toneMapping;if(0===s)return e;const i={exposure:this.exposureNode,color:e},r=XA[s];let n=null;return r?n=r(i):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),n=e),n}}const JA=(t,e,s)=>Xp(new YA(t,Xp(e),Xp(s))),ZA=gS("toneMappingExposure","float");_p("toneMapping",((t,e,s)=>JA(e,s,t))),up("ToneMappingNode",YA);let QA=null;class KA extends Yv{constructor(t=jv,e=null){null===QA&&(QA=new Xa),super(t,e,QA)}updateReference(){return this}}const tN=Zp(KA);_p("viewportSharedTexture",tN),up("ViewportSharedTextureNode",KA);const eN=new Ks;class sN extends ix{constructor(t,e){super(e),this.passNode=t,this.setUpdateMatrix(!1)}setup(t){return this.passNode.build(t),super.setup(t)}clone(){return new this.constructor(this.passNode,this.value)}}class iN extends sN{constructor(t,e){super(t,null),this.textureName=e}setup(t){return this.value=this.passNode.getTexture(this.textureName),super.setup(t)}clone(){return new this.constructor(this.passNode,this.textureName)}}class rN extends cp{constructor(t,e,s,i={}){super("vec4"),this.scope=t,this.scene=e,this.camera=s,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;const r=new Ka;r.isRenderTargetTexture=!0,r.name="depth";const n=new wi(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:Pt,...i});n.texture.name="output",n.depthTexture=r,this.renderTarget=n,this.updateBeforeType=$d.FRAME,this._textures={output:n.texture,depth:r},this._nodes={},this._linearDepthNode=null,this._viewZNode=null,this._cameraNear=hf(0),this._cameraFar=hf(0),this._mrt=null,this.isPassNode=!0}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(t){let e=this._textures[t];if(void 0===e){e=this.renderTarget.texture.clone(),e.isRenderTargetTexture=!0,e.name=t,this._textures[t]=e,this.renderTarget.textures.push(e)}return e}getTextureNode(t="output"){let e=this._nodes[t];return void 0===e&&(this._nodes[t]=e=Xp(new iN(this,t))),e}getViewZNode(){if(null===this._viewZNode){const t=this._cameraNear,e=this._cameraFar;this._viewZNode=nT(this.getTextureNode("depth"),t,e)}return this._viewZNode}getLinearDepthNode(){if(null===this._linearDepthNode){const t=this._cameraNear,e=this._cameraFar;this._linearDepthNode=sT(this.getViewZNode(),t,e)}return this._linearDepthNode}setup({renderer:t}){return this.renderTarget.samples=void 0===this.options.samples?t.samples:this.options.samples,!0===t.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===rN.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){const{renderer:e}=t,{scene:s,camera:i}=this;this._pixelRatio=e.getPixelRatio();const r=e.getSize(eN);this.setSize(r.width,r.height);const n=e.getRenderTarget(),o=e.getMRT();this._cameraNear.value=i.near,this._cameraFar.value=i.far,e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),e.render(s,i),e.setRenderTarget(n),e.setMRT(o)}setSize(t,e){this._width=t,this._height=e;const s=this._width*this._pixelRatio,i=this._height*this._pixelRatio;this.renderTarget.setSize(s,i)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}rN.COLOR="color",rN.DEPTH="depth";const nN=(t,e,s)=>Xp(new rN(rN.COLOR,t,e,s)),oN=(t,e)=>Xp(new sN(t,e)),aN=(t,e)=>Xp(new rN(rN.DEPTH,t,e));up("PassNode",rN);const hN=new Zw,uN=new Zw;class lN extends cp{constructor(t,e=null,s=2){super("vec4"),this.textureNode=t,this.directionNode=e,this.sigma=s,this._invSize=hf(new Ks),this._passDirection=hf(new Ks),this._horizontalRT=new wi,this._horizontalRT.texture.name="GaussianBlurNode.horizontal",this._verticalRT=new wi,this._verticalRT.texture.name="GaussianBlurNode.vertical",this._textureNode=oN(this,this._verticalRT.texture),this.updateBeforeType=$d.RENDER,this.resolution=new Ks(1,1)}setSize(t,e){t=Math.max(Math.round(t*this.resolution.x),1),e=Math.max(Math.round(e*this.resolution.y),1),this._invSize.value.set(1/t,1/e),this._horizontalRT.setSize(t,e),this._verticalRT.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=this.textureNode,i=s.value,r=e.getRenderTarget(),n=e.getMRT(),o=s.value;hN.material=this._material,uN.material=this._material,this.setSize(i.image.width,i.image.height);const a=i.type;this._horizontalRT.texture.type=a,this._verticalRT.texture.type=a,e.setMRT(null),e.setRenderTarget(this._horizontalRT),this._passDirection.value.set(1,0),hN.render(e),s.value=this._horizontalRT.texture,e.setRenderTarget(this._verticalRT),this._passDirection.value.set(0,1),uN.render(e),e.setRenderTarget(r),e.setMRT(n),s.value=o}getTextureNode(){return this._textureNode}setup(t){const e=this.textureNode;if(!0!==e.isTextureNode)return console.error("GaussianBlurNode requires a TextureNode."),ym();const s=e.uvNode||uf(),i=um(this.directionNode||1),r=t=>e.uv(t),n=Kp((()=>{const t=3+2*this.sigma,e=this._getCoefficients(t),n=this._invSize,o=i.mul(this._passDirection),a=nm(e[0]).toVar(),h=ym(r(s).mul(a)).toVar();for(let i=1;iXp(new lN(Xp(t).toTexture(),e,s));_p("gaussianBlur",cN);const dN=new Ks,pN=new Zw;class mN extends cp{constructor(t,e=.96){super(t),this.textureNode=t,this.textureNodeOld=rx(),this.damp=hf(e),this._compRT=new wi,this._compRT.texture.name="AfterImageNode.comp",this._oldRT=new wi,this._oldRT.texture.name="AfterImageNode.old",this._textureNode=oN(this,this._compRT.texture),this.updateBeforeType=$d.RENDER}getTextureNode(){return this._textureNode}setSize(t,e){this._compRT.setSize(t,e),this._oldRT.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=this.textureNode,i=s.value.type;this._compRT.texture.type=i,this._oldRT.texture.type=i,e.getDrawingBufferSize(dN),this.setSize(dN.x,dN.y);const r=e.getRenderTarget(),n=s.value;this.textureNodeOld.value=this._oldRT.texture,e.setRenderTarget(this._compRT),pN.render(e);const o=this._oldRT;this._oldRT=this._compRT,this._compRT=o,e.setRenderTarget(r),s.value=n}setup(t){const e=this.textureNode,s=this.textureNodeOld,i=e.uvNode||uf();s.uvNode=i;const r=Kp((([t,e])=>{const s=nm(e).toVar(),i=ym(t).toVar();return Ty(ay(i.sub(s)),0)})),n=Kp((()=>{const t=ym(s),n=ym((t=>e.uv(t))(i));return t.mulAssign(this.damp.mul(r(t,.1))),Ty(n,t)})),o=this._materialComposed||(this._materialComposed=t.createNodeMaterial());o.fragmentNode=n(),pN.material=o;return t.getNodeProperties(this).textureNode=e,this._textureNode}}const gN=(t,e)=>Xp(new mN(Xp(t).toTexture(),e));_p("afterImage",gN);const fN=new Zw;class yN extends cp{constructor(t,e,s,i){super("vec4"),this.textureNode=t,this.tresholdNode=e,this.scaleNode=s,this.colorNode=pm(.1,0,1),this.samples=i,this.resolution=new Ks(1,1),this._renderTarget=new wi,this._renderTarget.texture.name="anamorphic",this._invSize=hf(new Ks),this._textureNode=oN(this,this._renderTarget.texture),this.updateBeforeType=$d.RENDER}getTextureNode(){return this._textureNode}setSize(t,e){this._invSize.value.set(1/t,1/e),t=Math.max(Math.round(t*this.resolution.x),1),e=Math.max(Math.round(e*this.resolution.y),1),this._renderTarget.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=this.textureNode,i=s.value;this._renderTarget.texture.type=i.type;const r=e.getRenderTarget(),n=s.value;fN.material=this._material,this.setSize(i.image.width,i.image.height),e.setRenderTarget(this._renderTarget),fN.render(e),e.setRenderTarget(r),s.value=n}setup(t){const e=this.textureNode,s=e.uvNode||uf(),i=Kp((()=>{const t=this.samples,i=Math.floor(t/2),r=pm(0).toVar();return dv({start:-i,end:i},(({i:t})=>{const n=nm(t).abs().div(i).oneMinus(),o=(t=>e.uv(t))(um(s.x.add(this._invSize.x.mul(t).mul(this.scaleNode)),s.y)),a=IA(o,this.tresholdNode).mul(n);r.addAssign(a)})),r.mul(this.colorNode)}));(this._material||(this._material=t.createNodeMaterial())).fragmentNode=i();return t.getNodeProperties(this).textureNode=e,this._textureNode}}const xN=(t,e=.9,s=3,i=32)=>Xp(new yN(Xp(t).toTexture(),Xp(e),Xp(s),i));_p("anamorphic",xN);class bN extends cp{constructor(t){super(),this.textureNode=t,this.updateBeforeType=$d.RENDER,this._invSize=hf(new Ks)}updateBefore(){const t=this.textureNode.value;this._invSize.value.set(1/t.image.width,1/t.image.height)}setup(){const{textureNode:t}=this,e=t.uvNode||uf(),s=e=>t.uv(e);return Kp((()=>{const t=this._invSize,i=Mm(-1,-2,-1,0,0,0,1,2,1),r=Mm(-1,0,1,-2,0,2,-1,0,1),n=BA(s(e.add(t.mul(um(-1,-1)))).xyz),o=BA(s(e.add(t.mul(um(-1,0)))).xyz),a=BA(s(e.add(t.mul(um(-1,1)))).xyz),h=BA(s(e.add(t.mul(um(0,-1)))).xyz),u=BA(s(e.add(t.mul(um(0,0)))).xyz),l=BA(s(e.add(t.mul(um(0,1)))).xyz),c=BA(s(e.add(t.mul(um(1,-1)))).xyz),d=BA(s(e.add(t.mul(um(1,0)))).xyz),p=BA(s(e.add(t.mul(um(1,1)))).xyz),m=pf(i[0][0].mul(n),i[1][0].mul(h),i[2][0].mul(c),i[0][1].mul(o),i[1][1].mul(u),i[2][1].mul(d),i[0][2].mul(a),i[1][2].mul(l),i[2][2].mul(p)),g=pf(r[0][0].mul(n),r[1][0].mul(h),r[2][0].mul(c),r[0][1].mul(o),r[1][1].mul(u),r[2][1].mul(d),r[0][2].mul(a),r[1][2].mul(l),r[2][2].mul(p)),f=m.mul(m).add(g.mul(g)).sqrt();return ym(pm(f),1)}))()}}const vN=t=>Xp(new bN(Xp(t).toTexture()));_p("sobel",vN);class TN extends cp{constructor(t,e,s,i,r){super(),this.textureNode=t,this.viewZNode=e,this.focusNode=s,this.apertureNode=i,this.maxblurNode=r,this._aspect=hf(0),this.updateBeforeType=$d.RENDER}updateBefore(){const t=this.textureNode.value;this._aspect.value=t.image.width/t.image.height}setup(){const t=this.textureNode,e=t.uvNode||uf(),s=e=>t.uv(e);return Kp((()=>{const t=um(1,this._aspect),i=this.focusNode.add(this.viewZNode),r=um(zy(i.mul(this.apertureNode),this.maxblurNode.negate(),this.maxblurNode)),n=r.mul(.9),o=r.mul(.7),a=r.mul(.4);let h=ym(0);return h=h.add(s(e)),h=h.add(s(e.add(um(0,.4).mul(t).mul(r)))),h=h.add(s(e.add(um(.15,.37).mul(t).mul(r)))),h=h.add(s(e.add(um(.29,.29).mul(t).mul(r)))),h=h.add(s(e.add(um(-.37,.15).mul(t).mul(r)))),h=h.add(s(e.add(um(.4,0).mul(t).mul(r)))),h=h.add(s(e.add(um(.37,-.15).mul(t).mul(r)))),h=h.add(s(e.add(um(.29,-.29).mul(t).mul(r)))),h=h.add(s(e.add(um(-.15,-.37).mul(t).mul(r)))),h=h.add(s(e.add(um(0,-.4).mul(t).mul(r)))),h=h.add(s(e.add(um(-.15,.37).mul(t).mul(r)))),h=h.add(s(e.add(um(-.29,.29).mul(t).mul(r)))),h=h.add(s(e.add(um(.37,.15).mul(t).mul(r)))),h=h.add(s(e.add(um(-.4,0).mul(t).mul(r)))),h=h.add(s(e.add(um(-.37,-.15).mul(t).mul(r)))),h=h.add(s(e.add(um(-.29,-.29).mul(t).mul(r)))),h=h.add(s(e.add(um(.15,-.37).mul(t).mul(r)))),h=h.add(s(e.add(um(.15,.37).mul(t).mul(n)))),h=h.add(s(e.add(um(-.37,.15).mul(t).mul(n)))),h=h.add(s(e.add(um(.37,-.15).mul(t).mul(n)))),h=h.add(s(e.add(um(-.15,-.37).mul(t).mul(n)))),h=h.add(s(e.add(um(-.15,.37).mul(t).mul(n)))),h=h.add(s(e.add(um(.37,.15).mul(t).mul(n)))),h=h.add(s(e.add(um(-.37,-.15).mul(t).mul(n)))),h=h.add(s(e.add(um(.15,-.37).mul(t).mul(n)))),h=h.add(s(e.add(um(.29,.29).mul(t).mul(o)))),h=h.add(s(e.add(um(.4,0).mul(t).mul(o)))),h=h.add(s(e.add(um(.29,-.29).mul(t).mul(o)))),h=h.add(s(e.add(um(0,-.4).mul(t).mul(o)))),h=h.add(s(e.add(um(-.29,.29).mul(t).mul(o)))),h=h.add(s(e.add(um(-.4,0).mul(t).mul(o)))),h=h.add(s(e.add(um(-.29,-.29).mul(t).mul(o)))),h=h.add(s(e.add(um(0,.4).mul(t).mul(o)))),h=h.add(s(e.add(um(.29,.29).mul(t).mul(a)))),h=h.add(s(e.add(um(.4,0).mul(t).mul(a)))),h=h.add(s(e.add(um(.29,-.29).mul(t).mul(a)))),h=h.add(s(e.add(um(0,-.4).mul(t).mul(a)))),h=h.add(s(e.add(um(-.29,.29).mul(t).mul(a)))),h=h.add(s(e.add(um(-.4,0).mul(t).mul(a)))),h=h.add(s(e.add(um(-.29,-.29).mul(t).mul(a)))),h=h.add(s(e.add(um(0,.4).mul(t).mul(a)))),h=h.div(41),h.a=1,ym(h)}))()}}const _N=(t,e,s=1,i=.025,r=1)=>Xp(new TN(Xp(t).toTexture(),Xp(e),Xp(s),Xp(i),Xp(r)));_p("dof",_N);class wN extends cp{constructor(t,e=new Ks(.5,.5),s=1.57,i=1){super("vec4"),this.inputNode=t,this.center=hf(e),this.angle=hf(s),this.scale=hf(i),this._size=hf(new Ks),this.updateBeforeType=$d.RENDER}updateBefore(){const t=this.inputNode.value;this._size.value.set(t.image.width,t.image.height)}setup(){const t=this.inputNode,e=Kp((()=>{const t=ty(this.angle),e=ey(this.angle),s=uf().mul(this._size).sub(this.center),i=um(e.mul(s.x).sub(t.mul(s.y)),t.mul(s.x).add(e.mul(s.y))).mul(this.scale);return ty(i.x).mul(ty(i.y)).mul(4)})),s=Kp((()=>{const s=t,i=pf(s.r,s.g,s.b).div(3);return ym(pm(i.mul(10).sub(5).add(e())),s.a)}));return s()}}const SN=(t,e,s,i)=>Xp(new wN(Xp(t),e,s,i));_p("dotScreen",SN);class MN extends cp{constructor(t,e=.005,s=0){super("vec4"),this.textureNode=t,this.amount=hf(e),this.angle=hf(s)}setup(){const{textureNode:t}=this,e=t.uvNode||uf(),s=e=>t.uv(e);return Kp((()=>{const t=um(ey(this.angle),ty(this.angle)).mul(this.amount),i=s(e.add(t)),r=s(e),n=s(e.sub(t));return ym(i.r,r.g,n.b,r.a)}))()}}const AN=(t,e,s)=>Xp(new MN(Xp(t).toTexture(),e,s));_p("rgbShift",AN);class NN extends cp{constructor(t,e=null,s=null){super(),this.inputNode=t,this.intensityNode=e,this.uvNode=s}setup(){const t=this.uvNode||uf(),e=Kp((()=>{const e=this.inputNode.rgb,s=Gy(Kf(t.add(aw())));let i=e.add(e.mul(zy(s.add(.1),0,1)));return null!==this.intensityNode&&(i=Oy(e,i,this.intensityNode)),ym(i,this.inputNode.a)}));return e()}}const RN=Zp(NN);_p("film",RN);class CN extends cp{constructor(t,e,s,i){super(),this.inputNode=t,this.lutNode=e,this.size=hf(s),this.intensityNode=i}setup(){const{inputNode:t,lutNode:e}=this,s=Kp((()=>{const s=t,i=nm(1).div(this.size),r=nm(.5).div(this.size),n=pm(r).add(s.rgb.mul(nm(1).sub(i))),o=ym((t=>e.uv(t))(n).rgb,s.a);return ym(Oy(s,o,this.intensityNode))}));return s()}}const EN=(t,e,s,i)=>Xp(new CN(Xp(t),Xp(e),s,Xp(i)));_p("lut3D",EN);const BN=new Zw,IN=new Yr;class PN extends cp{constructor(t,e,s,i){super(),this.textureNode=t,this.depthNode=e,this.normalNode=s,this.radius=hf(.25),this.resolution=hf(new Ks),this.thickness=hf(1),this.distanceExponent=hf(1),this.distanceFallOff=hf(1),this.scale=hf(1),this.blendIntensity=hf(1),this.noiseNode=rx(function(t=5){const e=Math.floor(t)%2==0?Math.floor(t)+1:Math.floor(t),s=function(t){const e=Math.floor(t)%2==0?Math.floor(t)+1:Math.floor(t),s=e*e,i=Array(s).fill(0);let r=Math.floor(e/2),n=e-1;for(let t=1;t<=s;)-1===r&&n===e?(n=e-2,r=0):(n===e&&(n=0),r<0&&(r=e-1)),0===i[r*e+n]?(i[r*e+n]=t++,n++,r--):(n-=2,r++);return i}(e),i=s.length,r=new Uint8Array(4*i);for(let t=0;tthis.depthNode.uv(t).x,r=t=>this.noiseNode.uv(t),n=Kp((([t])=>{const e=this.cameraProjectionMatrix.mul(ym(t,1));let s=e.xy.div(e.w).mul(.5).add(.5).toVar();s=um(s.x,s.y.oneMinus());const r=i(s);return pm(s,r)})),o=Kp((([t,e])=>{t=um(t.x,t.y.oneMinus()).mul(2).sub(1);const s=ym(pm(t,e),1),i=ym(this.cameraProjectionMatrixInverse.mul(s));return i.xyz.div(i.w)})),a=Kp((()=>{const t=i(s);t.greaterThanEqual(1).discard();const e=o(s,t),a=this.normalNode.rgb.normalize(),h=this.radius,u=cf(this.noiseNode,0);let l=um(s.x,s.y.oneMinus());l=l.mul(this.resolution.div(u));const c=r(l),d=c.xyz.mul(2).sub(1),p=pm(d.xy,0).normalize(),m=pm(p.y.mul(-1),p.x,0),g=Mm(p,m,pm(0,0,1)),f=this.SAMPLES.lessThan(30).cond(3,5),y=pf(this.SAMPLES,f.sub(1)).div(f),x=nm(0).toVar();return dv({start:om(0),end:f,type:"int",condition:"<"},(({i:t})=>{const s=nm(t).div(nm(f)).mul(zf),i=ym(ey(s),ty(s),0,pf(.5,gf(.5,c.w)));i.xyz=Qf(g.mul(i.xyz));const r=Qf(e.xyz.negate()),u=Qf(Ry(i.xyz,r)),l=Ry(u,r),d=Qf(a.sub(u.mul(Ny(a,u)))),p=Ry(d,u),m=um(Ny(r,p),Ny(r,p.negate())).toVar();dv({end:y,type:"int",name:"j",condition:"<"},(({j:t})=>{const s=i.xyz.mul(h).mul(i.w).mul(Cy(ff(nm(t).add(1),nm(y)),this.distanceExponent)),a=n(e.add(s)),u=o(a.xy,a.z).sub(e);sm(oy(u.z).lessThan(this.thickness),(()=>{const e=Ny(r,Qf(u));m.x.addAssign(Ty(0,gf(e.sub(m.x),Oy(1,nm(2).div(nm(t).add(2)),this.distanceFallOff))))}));const l=n(e.sub(s)),c=o(l.xy,l.z).sub(e);sm(oy(c.z).lessThan(this.thickness),(()=>{const e=Ny(r,Qf(c));m.y.addAssign(Ty(0,gf(e.sub(m.y),Oy(1,nm(2).div(nm(t).add(2)),this.distanceFallOff))))}))}));const b=Xf(mf(1,m.mul(m))),v=Ny(d,l),T=Ny(d,r),_=gf(.5,ry(m.y).sub(ry(m.x)).add(b.x.mul(m.x).sub(b.y.mul(m.y)))),w=gf(.5,mf(2,m.x.mul(m.x)).sub(m.y.mul(m.y))),S=v.mul(_).add(T.mul(w));x.addAssign(S)})),x.assign(zy(x.div(f),0,1)),x.assign(Cy(x,this.scale)),ym(pm(x),1)})),h=Kp((()=>{const t=(t=>e.uv(t))(s),i=this._textureNode.uv(s);return t.mul(Oy(pm(1),i,this.blendIntensity))})),u=this._material||(this._material=t.createNodeMaterial());return u.fragmentNode=a().context(t.getSharedContext()),u.needsUpdate=!0,h()}}const FN=(t,e,s,i)=>Xp(new PN(Xp(t).toTexture(),Xp(e),Xp(s),i));_p("ao",FN);class UN extends cp{constructor(t,e,s){super("vec4"),this.colorNode=t,this.toneMapping=e,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:t}){let e=this.colorNode||t.color;const s=null!==this.toneMapping?this.toneMapping:t.toneMapping,i=null!==this.outputColorSpace?this.outputColorSpace:t.outputColorSpace;return 0!==s&&(e=e.toneMapping(s)),i===Je&&(e=e.linearToColorSpace(i)),e}}const ON=(t,e=null,s=null)=>Xp(new UN(Xp(t),e,s));_p("renderOutput",ON),up("RenderOutputNode",UN);class zN extends cp{constructor(t=null,e={}){super(),this.functionNode=t,this.parameters=e}setParameters(t){return this.parameters=t,this}getParameters(){return this.parameters}getNodeType(t){return this.functionNode.getNodeType(t)}generate(t){const e=[],s=this.functionNode,i=s.getInputs(t),r=this.parameters;if(Array.isArray(r))for(let s=0;s(e=e.length>1||e[0]&&!0===e[0].isNode?Jp(e):Yp(e[0]),Xp(new zN(Xp(t),e)));_p("call",LN),up("FunctionCallNode",zN);class VN extends hp{constructor(t=null){super(),this._value=t,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new ks,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(t){this._value!==t&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=t,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const t=this.value;if(t&&null===this._cache&&"URL"===this.inputType&&t.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([t.value]));else if(t&&null!==t.value&&void 0!==t.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof t.value||"Number"===this.inputType&&"number"==typeof t.value||"Vector2"===this.inputType&&t.value.isVector2||"Vector3"===this.inputType&&t.value.isVector3||"Vector4"===this.inputType&&t.value.isVector4||"Color"===this.inputType&&t.value.isColor||"Matrix3"===this.inputType&&t.value.isMatrix3||"Matrix4"===this.inputType&&t.value.isMatrix4))return t.value;return this._cache||t}getNodeType(t){return this.value&&this.value.isNode?this.value.getNodeType(t):"float"}setup(){return this.value&&this.value.isNode?this.value:nm()}serialize(t){super.serialize(t),null!==this.value?"ArrayBuffer"===this.inputType?t.value=ip(this.value):t.value=this.value?this.value.toJSON(t.meta).uuid:null:t.value=null,t.inputType=this.inputType,t.outputType=this.outputType}deserialize(t){super.deserialize(t);let e=null;null!==t.value&&(e="ArrayBuffer"===t.inputType?rp(t.value):"Texture"===t.inputType?t.meta.textures[t.value]:t.meta.nodes[t.value]||null),this.value=e,this.inputType=t.inputType,this.outputType=t.outputType}}const DN=Zp(VN);_p("scriptableValue",DN),up("ScriptableValueNode",VN);class kN extends Map{get(t,e=null,...s){if(this.has(t))return super.get(t);if(null!==e){const i=e(...s);return this.set(t,i),i}}}class GN{constructor(t){this.scriptableNode=t}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(t){return this.scriptableNode.getInputLayout(t)}get(t){const e=this.parameters[t];return e?e.getValue():null}}const WN=new kN;class jN extends hp{constructor(t=null,e={}){super(),this.codeNode=t,this.parameters=e,this._local=new kN,this._output=DN(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(t,e){return this._local.set(t,e)}getLocal(t){return this._local.get(t)}onRefresh(){this._refresh()}getInputLayout(t){for(const e of this.getLayout())if(e.inputType&&(e.id===t||e.name===t))return e}getOutputLayout(t){for(const e of this.getLayout())if(e.outputType&&(e.id===t||e.name===t))return e}setOutput(t,e){const s=this._outputs;return void 0===s[t]?s[t]=DN(e):s[t].value=e,this}getOutput(t){return this._outputs[t]}getParameter(t){return this.parameters[t]}setParameter(t,e){const s=this.parameters;return e&&e.isScriptableNode?(this.deleteParameter(t),s[t]=e,s[t].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):e&&e.isScriptableValueNode?(this.deleteParameter(t),s[t]=e,s[t].events.addEventListener("refresh",this.onRefresh)):void 0===s[t]?(s[t]=DN(e),s[t].events.addEventListener("refresh",this.onRefresh)):s[t].value=e,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(t){let e=this.parameters[t];return e&&(e.isScriptableNode&&(e=e.getDefaultOutput()),e.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const t of Object.keys(this.parameters))this.deleteParameter(t);return this.needsUpdate=!0,this}call(t,...e){const s=this.getObject()[t];if("function"==typeof s)return s(...e)}async callAsync(t,...e){const s=this.getObject()[t];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...e):s(...e)}getNodeType(t){return this.getDefaultOutputNode().getNodeType(t)}refresh(t=null){null!==t?this.getOutput(t).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const t=new GN(this),e=WN.get("THREE"),s=WN.get("TSL"),i=this.getMethod(this.codeNode),r=[t,this._local,WN,()=>this.refresh(),(t,e)=>this.setOutput(t,e),e,s];this._object=i(...r);const n=this._object.layout;if(n&&(!1===n.cache&&this._local.clear(),this._output.outputType=n.outputType||null,Array.isArray(n.elements)))for(const t of n.elements){const e=t.id||t.name;t.inputType&&(void 0===this.getParameter(e)&&this.setParameter(e,null),this.getParameter(e).inputType=t.inputType),t.outputType&&(void 0===this.getOutput(e)&&this.setOutput(e,null),this.getOutput(e).outputType=t.outputType)}return this._object}deserialize(t){super.deserialize(t);for(const t in this.parameters){let e=this.parameters[t];e.isScriptableNode&&(e=e.getDefaultOutput()),e.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const t=this.getDefaultOutput().value;return t&&t.isNode?t:nm()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const t=["layout","init","main","dispose"].join(", "),e="\nreturn { ...output, "+t+" };",s="var "+t+"; var output = {};\n"+this.codeNode.code+e;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}set needsUpdate(t){!0===t&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const HN=Zp(jN);_p("scriptable",HN),up("ScriptableNode",jN);class qN extends hp{constructor(t,e){super("float"),this.isFogNode=!0,this.colorNode=t,this.factorNode=e}getViewZNode(t){let e;const s=t.context.getViewZ;return void 0!==s&&(e=s(this)),(e||Wb.z).negate()}setup(){return this.factorNode}}const $N=Zp(qN);_p("fog",$N),up("FogNode",qN);class XN extends qN{constructor(t,e,s){super(t),this.isFogRangeNode=!0,this.nearNode=e,this.farNode=s}setup(t){const e=this.getViewZNode(t);return Dy(this.nearNode,this.farNode,e)}}const YN=Zp(XN);_p("rangeFog",YN),up("FogRangeNode",XN);class JN extends qN{constructor(t,e){super(t),this.isFogExp2Node=!0,this.densityNode=e}setup(t){const e=this.getViewZNode(t),s=this.densityNode;return s.mul(s,e,e).negate().exp().oneMinus()}}const ZN=Zp(JN);_p("densityFog",ZN),up("FogExp2Node",JN);let QN=null,KN=null;class tR extends hp{constructor(t=nm(),e=nm()){super(),this.minNode=t,this.maxNode=e}getVectorLength(t){const e=t.getTypeLength(ep(this.minNode.value)),s=t.getTypeLength(ep(this.maxNode.value));return e>s?e:s}getNodeType(t){return t.object.count>1?t.getTypeFromLength(this.getVectorLength(t)):"float"}setup(t){const e=t.object;let s=null;if(e.count>1){const i=this.minNode.value,r=this.maxNode.value,n=t.getTypeLength(ep(i)),o=t.getTypeLength(ep(r));QN=QN||new _i,KN=KN||new _i,QN.setScalar(0),KN.setScalar(0),1===n?QN.setScalar(i):i.isColor?QN.set(i.r,i.g,i.b):QN.set(i.x,i.y,i.z||0,i.w||0),1===o?KN.setScalar(r):r.isColor?KN.set(r.r,r.g,r.b):KN.set(r.x,r.y,r.z||0,r.w||0);const a=4,h=a*e.count,u=new Float32Array(h);for(let t=0;tXp(new sR(Xp(t),e,s));_p("compute",iR),up("ComputeNode",sR);class rR extends hp{constructor(t=rR.TARGET_DIRECTION,e=null){super(),this.scope=t,this.light=e}setup(){const{scope:t,light:e}=this;let s=null;return t===rR.TARGET_DIRECTION&&(s=Sx.transformDirection(Px(e).sub(Px(e.target)))),s}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}}rR.TARGET_DIRECTION="targetDirection";const nR=Zp(rR,rR.TARGET_DIRECTION);up("LightNode",rR);const oR=Kp((t=>{const{lightDistance:e,cutoffDistance:s,decayExponent:i}=t,r=e.pow(i).max(.01).reciprocal();return s.greaterThan(0).cond(r.mul(e.div(s).pow4().oneMinus().clamp().pow2()),r)}));class aR extends Rv{constructor(t=null){super(t),this.cutoffDistanceNode=hf(0),this.decayExponentNode=hf(0)}update(t){const{light:e}=this;super.update(t),this.cutoffDistanceNode.value=e.distance,this.decayExponentNode.value=e.decay}setup(t){const{colorNode:e,cutoffDistanceNode:s,decayExponentNode:i,light:r}=this,n=t.context.lightingModel,o=Ux(r).sub(Wb),a=o.normalize(),h=o.length(),u=oR({lightDistance:h,cutoffDistance:s,decayExponent:i}),l=e.mul(u),c=t.context.reflectedLight;n.direct({lightDirection:a,lightColor:l,reflectedLight:c,shadowMask:this.shadowMaskNode},t.stack,t)}}up("PointLightNode",aR),Pv(Nl,aR);class hR extends Rv{constructor(t=null){super(t)}setup(t){super.setup(t);const e=t.context.lightingModel,s=this.colorNode,i=nR(this.light),r=t.context.reflectedLight;e.direct({lightDirection:i,lightColor:s,reflectedLight:r,shadowMask:this.shadowMaskNode},t.stack,t)}}up("DirectionalLightNode",hR),Pv(El,hR);const uR=new or,lR=new or;let cR=null;class dR extends Rv{constructor(t=null){super(t),this.halfHeight=hf(new Ei),this.halfWidth=hf(new Ei)}update(t){super.update(t);const{light:e}=this,s=t.camera.matrixWorldInverse;lR.identity(),uR.copy(e.matrixWorld),uR.premultiply(s),lR.extractRotation(uR),this.halfWidth.value.set(.5*e.width,0,0),this.halfHeight.value.set(0,.5*e.height,0),this.halfWidth.value.applyMatrix4(lR),this.halfHeight.value.applyMatrix4(lR)}setup(t){let e,s;super.setup(t),t.isAvailable("float32Filterable")?(e=rx(cR.LTC_FLOAT_1),s=rx(cR.LTC_FLOAT_2)):(e=rx(cR.LTC_HALF_1),s=rx(cR.LTC_HALF_2));const{colorNode:i,light:r}=this,n=t.context.lightingModel,o=Ux(r),a=t.context.reflectedLight;n.directRectArea({lightColor:i,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:e,ltc_2:s},t.stack,t)}static setLTC(t){cR=t}}up("RectAreaLightNode",dR),Pv(Il,dR);class pR extends Rv{constructor(t=null){super(t),this.coneCosNode=hf(0),this.penumbraCosNode=hf(0),this.cutoffDistanceNode=hf(0),this.decayExponentNode=hf(0)}update(t){super.update(t);const{light:e}=this;this.coneCosNode.value=Math.cos(e.angle),this.penumbraCosNode.value=Math.cos(e.angle*(1-e.penumbra)),this.cutoffDistanceNode.value=e.distance,this.decayExponentNode.value=e.decay}getSpotAttenuation(t){const{coneCosNode:e,penumbraCosNode:s}=this;return Dy(e,s,t)}setup(t){super.setup(t);const e=t.context.lightingModel,{colorNode:s,cutoffDistanceNode:i,decayExponentNode:r,light:n}=this,o=Ux(n).sub(Wb),a=o.normalize(),h=a.dot(nR(n)),u=this.getSpotAttenuation(h),l=o.length(),c=oR({lightDistance:l,cutoffDistance:i,decayExponent:r}),d=s.mul(u).mul(c),p=t.context.reflectedLight;e.direct({lightDirection:a,lightColor:d,reflectedLight:p,shadowMask:this.shadowMaskNode},t.stack,t)}}up("SpotLightNode",pR),Pv(_l,pR);class mR extends _l{constructor(t,e,s,i,r,n){super(t,e,s,i,r,n),this.iesMap=null}copy(t,e){return super.copy(t,e),this.iesMap=t.iesMap,this}}class gR extends pR{getSpotAttenuation(t){const e=this.light.iesMap;let s=null;if(e&&!0===e.isTexture){const i=t.acos().mul(1/Math.PI);s=rx(e,um(i,0),0).r}else s=super.getSpotAttenuation(t);return s}}up("IESSpotLightNode",gR),Pv(mR,gR);class fR extends Rv{constructor(t=null){super(t)}setup({context:t}){t.irradiance.addAssign(this.colorNode)}}up("AmbientLightNode",fR),Pv(Bl,fR);class yR extends Rv{constructor(t=null){super(t),this.lightPositionNode=Px(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=hf(new Yr)}update(t){const{light:e}=this;super.update(t),this.lightPositionNode.object3d=e,this.groundColorNode.value.copy(e.groundColor).multiplyScalar(e.intensity)}setup(t){const{colorNode:e,groundColorNode:s,lightDirectionNode:i}=this,r=$x.dot(i).mul(.5).add(.5),n=Oy(s,e,r);t.context.irradiance.addAssign(n)}}up("HemisphereLightNode",yR),Pv(fl,yR);let xR=null;const bR=new WeakMap;class vR extends cp{constructor(t,e=null,s=null){super("vec3"),this._value=t,this._pmrem=null,this.uvNode=e,this.levelNode=s,this._generator=null,this._texture=rx(null),this._width=hf(0),this._height=hf(0),this._maxMip=hf(0),this.updateBeforeType=$d.RENDER}set value(t){this._value=t,this._pmrem=null}get value(){return this._value}updateFromTexture(t){const e=function(t){const e=Math.log2(t)-2,s=1/t;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:s,maxMip:e}}(t.image.height);this._texture.value=t,this._width.value=e.texelWidth,this._height.value=e.texelHeight,this._maxMip.value=e.maxMip}updateBefore(){let t=this._pmrem;const e=t?t.pmremVersion:-1,s=this._value;e!==s.pmremVersion&&(t=!0===s.isPMREMTexture?s:function(t){let e=bR.get(t);if((void 0!==e?e.pmremVersion:-1)!==t.pmremVersion){if(t.isCubeTexture){if(t.source.data.some((t=>void 0===t)))throw new Error("PMREMNode: Undefined texture in CubeTexture. Use onLoad callback or async loader");e=xR.fromCubemap(t,e)}else{if(void 0===t.image)throw new Error("PMREMNode: Undefined image in Texture. Use onLoad callback or async loader");e=xR.fromEquirectangular(t,e)}e.pmremVersion=t.pmremVersion,bR.set(t,e)}return e.texture}(s),this._pmrem=t,this.updateFromTexture(t))}setup(t){null===xR&&(xR=t.createPMREMGenerator()),this.updateBefore(t);let e=this.uvNode;null===e&&t.context.getUV&&(e=t.context.getUV(this));const s=this.value;t.renderer.coordinateSystem===Vs&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(e=pm(e.x.negate(),e.yz));let i=this.levelNode;return null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),s_(this._texture,e,i,this._width,this._height,this._maxMip)}}const TR=Zp(vR);up("PMREMNode",vR);const _R=new WeakMap;class wR extends Av{constructor(t=null){super(),this.envNode=t}setup(t){let e=this.envNode;if(e.isTextureNode){let t=_R.get(e.value);void 0===t&&(t=TR(e.value),_R.set(e.value,t)),e=t}const{material:s}=t,i=s.envMap?mx("envMapIntensity","float",t.material):mx("environmentIntensity","float",t.scene),r=!0===s.useAnisotropy||s.anisotropy>0,n=Ym(e,SR(yg,r?cS:Yx)).mul(i),o=Ym(e,MR(Jx)).mul(Math.PI).mul(i),a=$m(n),h=$m(o);t.context.radiance.addAssign(a),t.context.iblIrradiance.addAssign(h);const u=t.context.lightingModel.clearcoatRadiance;if(u){const t=Ym(e,SR(vg,Zx)).mul(i),s=$m(t);u.addAssign(s)}}}const SR=(t,e)=>{let s=null;return{getUV:()=>(null===s&&(s=jb.negate().reflect(e),s=t.mul(t).mix(s,e).normalize(),s=s.transformDirection(Sx)),s),getTextureLevel:()=>t}},MR=t=>({getUV:()=>t,getTextureLevel:()=>nm(1)});up("EnvironmentNode",wR);class AR extends Av{constructor(t=null){super(),this.envNode=t}setup(t){t.context.environment=this.envNode}}up("BasicEnvironmentNode",AR);const NR=Kp((t=>{const e=t.uv.mul(2),s=e.x.floor(),i=e.y.floor();return s.add(i).mod(2).sign()}));class RR extends cp{constructor(t=uf()){super("float"),this.uvNode=t}setup(){return NR({uv:this.uvNode})}}const CR=Zp(RR);_p("checker",CR),up("CheckerNode",RR);class ER extends nl{constructor(t){super(t),this.textures={}}load(t,e,s,i){const r=new hl(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,(s=>{try{e(this.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),this.manager.itemError(t)}}),s,i)}parseNodes(t){const e={};if(void 0!==t){for(const s of t){const{uuid:t,type:i}=s;e[t]=Xp(lp(i)),e[t].uuid=t}const s={nodes:e,textures:this.textures};for(const i of t){i.meta=s;e[i.uuid].deserialize(i),delete i.meta}}return e}parse(t){const e=Xp(lp(t.type));e.uuid=t.uuid;const s={nodes:this.parseNodes(t.nodes),textures:this.textures};return t.meta=s,e.deserialize(t),delete t.meta,e}setTextures(t){return this.textures=t,this}}const BR=new Va;class IR extends gT{constructor(t={}){super(),this.normals=!1,this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=t.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.setDefaultValues(BR),this.setupShaders(),this.setValues(t)}setupShaders(){const t=this.alphaToCoverage,e=this.useColor;this.vertexNode=Kp((()=>{km(um(),"vUv").assign(uf());const t=Wm("instancePosition"),e=pg("vec4","mvPos");e.assign(Lx.mul(ym(t,1)));const s=Wv.z.div(Wv.w),i=_x.mul(e),r=pg("vec2","offset");return r.assign(Vb.xy),r.assign(r.mul(Pb)),r.assign(r.div(Wv.z)),r.y.assign(r.y.mul(s)),r.assign(r.mul(i.w)),i.assign(i.add(ym(r,0,0))),i}))(),this.fragmentNode=Kp((()=>{const s=km(um(),"vUv"),i=pg("float","alpha");i.assign(1);const r=s.x,n=s.y,o=r.mul(r).add(n.mul(n));if(t){const t=pg("float","dlen");t.assign(o.fwidth()),i.assign(Dy(t.oneMinus(),t.add(1),o).oneMinus())}else o.greaterThan(1).discard();let a;if(this.pointColorNode)a=this.pointColorNode;else if(e){a=Wm("instanceColor").mul(eb)}else a=eb;return ym(a,i)}))(),this.needsUpdate=!0}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.setupShaders())}}fT("InstancedPointsNodeMaterial",IR);const PR=new Ma;class FR extends gT{constructor(t){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.normals=!1,this.setDefaultValues(PR),this.setValues(t)}}fT("LineBasicNodeMaterial",FR);const UR=new Uu;class OR extends gT{constructor(t){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.normals=!1,this.setDefaultValues(UR),this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setupVariants(){const t=this.offsetNode,e=this.dashScaleNode?nm(this.dashScaleNode):Rb,s=this.dashSizeNode?nm(this.dashSizeNode):Cb,i=this.dashSizeNode?nm(this.dashGapNode):Eb;Fg.assign(s),Ug.assign(i);const r=km(Wm("lineDistance").mul(e));(t?r.add(t):r).mod(Fg.add(Ug)).greaterThan(Fg).discard()}}fT("LineDashedNodeMaterial",OR);const zR=new Uu;class LR extends gT{constructor(t={}){super(),this.normals=!1,this.lights=!1,this.setDefaultValues(zR),this.useAlphaToCoverage=!0,this.useColor=t.vertexColors,this.useDash=t.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setup(t){this.setupShaders(),super.setup(t)}setupShaders(){const t=this.alphaToCoverage,e=this.useColor,s=this.dashed,i=this.worldUnits,r=Kp((({start:t,end:e})=>{const s=_x.element(2).element(2),i=_x.element(3).element(2).mul(-.5).div(s).sub(t.z).div(e.z.sub(t.z));return ym(Oy(t.xyz,e.xyz,i),e.w)}));this.vertexNode=Kp((()=>{mg("vec2","vUv").assign(uf());const t=Wm("instanceStart"),e=Wm("instanceEnd"),n=pg("vec4","start"),o=pg("vec4","end");n.assign(Lx.mul(ym(t,1))),o.assign(Lx.mul(ym(e,1))),i&&(mg("vec3","worldStart").assign(n.xyz),mg("vec3","worldEnd").assign(o.xyz));const a=Wv.z.div(Wv.w),h=_x.element(2).element(3).equal(-1);sm(h,(()=>{sm(n.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(r({start:n,end:o}))})).elseif(o.z.lessThan(0).and(n.z.greaterThanEqual(0)),(()=>{n.assign(r({start:o,end:n}))}))}));const u=_x.mul(n),l=_x.mul(o),c=u.xyz.div(u.w),d=l.xyz.div(l.w),p=d.xy.sub(c.xy).temp();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const m=ig(ym());if(i){const t=o.xyz.sub(n.xyz).normalize(),e=Oy(n.xyz,o.xyz,.5).normalize(),i=t.cross(e).normalize(),r=t.cross(i),a=mg("vec4","worldPos");a.assign(Vb.y.lessThan(.5).cond(n,o));const h=Bb.mul(.5);a.addAssign(ym(Vb.x.lessThan(0).cond(i.mul(h),i.mul(h).negate()),0)),s||(a.addAssign(ym(Vb.y.lessThan(.5).cond(t.mul(h).negate(),t.mul(h)),0)),a.addAssign(ym(r.mul(h),0)),sm(Vb.y.greaterThan(1).or(Vb.y.lessThan(0)),(()=>{a.subAssign(ym(r.mul(2).mul(h),0))}))),m.assign(_x.mul(a));const u=ig(pm());u.assign(Vb.y.lessThan(.5).cond(c,d)),m.z.assign(u.z.mul(m.w))}else{const t=pg("vec2","offset");t.assign(um(p.y,p.x.negate())),p.x.assign(p.x.div(a)),t.x.assign(t.x.div(a)),t.assign(Vb.x.lessThan(0).cond(t.negate(),t)),sm(Vb.y.lessThan(0),(()=>{t.assign(t.sub(p))})).elseif(Vb.y.greaterThan(1),(()=>{t.assign(t.add(p))})),t.assign(t.mul(Bb)),t.assign(t.div(Wv.w)),m.assign(Vb.y.lessThan(.5).cond(u,l)),t.assign(t.mul(m.w)),m.assign(m.add(ym(t,0,0)))}return m}))();const n=Kp((({p1:t,p2:e,p3:s,p4:i})=>{const r=t.sub(s),n=i.sub(s),o=e.sub(t),a=r.dot(n),h=n.dot(o),u=r.dot(o),l=n.dot(n),c=o.dot(o).mul(l).sub(h.mul(h)),d=a.mul(h).sub(u.mul(l)).div(c).clamp(),p=a.add(h.mul(d)).div(l).clamp();return um(d,p)}));this.fragmentNode=Kp((()=>{const r=mg("vec2","vUv");if(s){const t=this.offsetNode?nm(this.offsetNodeNode):Ib,e=this.dashScaleNode?nm(this.dashScaleNode):Rb,s=this.dashSizeNode?nm(this.dashSizeNode):Cb,i=this.dashSizeNode?nm(this.dashGapNode):Eb;Fg.assign(s),Ug.assign(i);const n=Wm("instanceDistanceStart"),o=Wm("instanceDistanceEnd"),a=Vb.y.lessThan(.5).cond(e.mul(n),Rb.mul(o)),h=km(a.add(Ib)),u=t?h.add(t):h;r.y.lessThan(-1).or(r.y.greaterThan(1)).discard(),u.mod(Fg.add(Ug)).greaterThan(Fg).discard()}const o=pg("float","alpha");if(o.assign(1),i){const e=mg("vec3","worldStart"),i=mg("vec3","worldEnd"),r=mg("vec4","worldPos").xyz.normalize().mul(1e5),a=i.sub(e),h=n({p1:e,p2:i,p3:pm(0,0,0),p4:r}),u=e.add(a.mul(h.x)),l=r.mul(h.y),c=u.sub(l).length().div(Bb);if(!s)if(t){const t=c.fwidth();o.assign(Dy(t.negate().add(.5),t.add(.5),c).oneMinus())}else c.greaterThan(.5).discard()}else if(t){const t=r.x,e=r.y.greaterThan(0).cond(r.y.sub(1),r.y.add(1)),s=t.mul(t).add(e.mul(e)),i=pg("float","dlen");i.assign(s.fwidth()),sm(r.y.abs().greaterThan(1),(()=>{o.assign(Dy(i.oneMinus(),i.add(1),s).oneMinus())}))}else sm(r.y.abs().greaterThan(1),(()=>{const t=r.x,e=r.y.greaterThan(0).cond(r.y.sub(1),r.y.add(1));t.mul(t).add(e.mul(e)).greaterThan(1).discard()}));let a;if(this.lineColorNode)a=this.lineColorNode;else if(e){const t=Wm("instanceColorStart"),e=Wm("instanceColorEnd");a=Vb.y.lessThan(.5).cond(t,e).mul(eb)}else a=eb;return ym(a,o)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(t){this.useWorldUnits!==t&&(this.useWorldUnits=t,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(t){this.useDash!==t&&(this.useDash=t,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.needsUpdate=!0)}}fT("Line2NodeMaterial",LR);const VR=new Eu;class DR extends gT{constructor(t){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(VR),this.setValues(t)}setupDiffuseColor(){const t=this.opacityNode?nm(this.opacityNode):rb;gg.assign(ym(yw(Yx),t))}}fT("MeshNormalNodeMaterial",DR);class kR extends Av{constructor(t=null){super(),this.lightMapNode=t}setup(t){const e=nm(1/Math.PI);t.context.irradianceLightMap=this.lightMapNode.mul(e)}}up("BasicLightMapNode",kR);class GR extends eg{constructor(){super()}indirect(t,e,s){const i=t.ambientOcclusion,r=t.reflectedLight,n=s.context.irradianceLightMap;r.indirectDiffuse.assign(ym(0)),n?r.indirectDiffuse.addAssign(n):r.indirectDiffuse.addAssign(ym(1,1,1,0)),r.indirectDiffuse.mulAssign(i),r.indirectDiffuse.mulAssign(gg.rgb)}finish(t,e,s){const i=s.material,r=t.outgoingLight,n=s.context.environment;if(n)switch(i.combine){case 0:r.rgb.assign(Oy(r.rgb,r.rgb.mul(n.rgb),hb.mul(ub)));break;case 1:r.rgb.assign(Oy(r.rgb,n.rgb,hb.mul(ub)));break;case 2:r.rgb.addAssign(n.rgb.mul(hb.mul(ub)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",i.combine)}}}const WR=new Kr;class jR extends gT{constructor(t){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(WR),this.setValues(t)}setupNormal(){Yx.assign($x)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new AR(e):null}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new kR(Ub)),e}setupLightingModel(){return new GR}}fT("MeshBasicNodeMaterial",jR);const HR=Kp((({f0:t,f90:e,dotVH:s})=>{const i=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return t.mul(i.oneMinus()).add(e.mul(i))})),qR=Kp((t=>t.diffuseColor.mul(1/Math.PI))),$R=Kp((({dotNH:t})=>Ig.mul(nm(.5)).add(1).mul(nm(1/Math.PI)).mul(t.pow(Ig)))),XR=Kp((({lightDirection:t})=>{const e=t.add(jb).normalize(),s=Yx.dot(e).clamp(),i=jb.dot(e).clamp(),r=HR({f0:Eg,f90:1,dotVH:i}),n=nm(.25),o=$R({dotNH:s});return r.mul(n).mul(o)}));class YR extends GR{constructor(t=!0){super(),this.specular=t}direct({lightDirection:t,lightColor:e,reflectedLight:s}){const i=Yx.dot(t).clamp().mul(e);s.directDiffuse.addAssign(i.mul(qR({diffuseColor:gg.rgb}))),!0===this.specular&&s.directSpecular.addAssign(i.mul(XR({lightDirection:t})).mul(hb))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:s}){s.indirectDiffuse.addAssign(e.mul(qR({diffuseColor:gg}))),s.indirectDiffuse.mulAssign(t)}}const JR=new Bu;class ZR extends gT{constructor(t){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(JR),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new AR(e):null}setupLightingModel(){return new YR(!1)}}fT("MeshLambertNodeMaterial",ZR);const QR=new Ru;class KR extends gT{constructor(t){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(QR),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new AR(e):null}setupLightingModel(){return new YR}setupVariants(){const t=(this.shininessNode?nm(this.shininessNode):sb).max(1e-4);Ig.assign(t);const e=this.specularNode||nb;Eg.assign(e)}copy(t){return this.shininessNode=t.shininessNode,this.specularNode=t.specularNode,super.copy(t)}}fT("MeshPhongNodeMaterial",KR);const tC=Kp((()=>{const t=Hx.dFdx().abs().max(Hx.dFdy().abs());return t.x.max(t.y).max(t.z)})),eC=Kp((t=>{const{roughness:e}=t,s=tC();let i=e.max(.0525);return i=i.add(s),i=i.min(1),i})),sC=Kp((({alpha:t,dotNL:e,dotNV:s})=>{const i=t.pow2(),r=e.mul(i.add(i.oneMinus().mul(s.pow2())).sqrt()),n=s.mul(i.add(i.oneMinus().mul(e.pow2())).sqrt());return ff(.5,r.add(n).max(Uf))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),iC=Kp((({alphaT:t,alphaB:e,dotTV:s,dotBV:i,dotTL:r,dotBL:n,dotNV:o,dotNL:a})=>{const h=a.mul(pm(t.mul(s),e.mul(i),o).length()),u=o.mul(pm(t.mul(r),e.mul(n),a).length());return ff(.5,h.add(u)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),rC=Kp((({alpha:t,dotNH:e})=>{const s=t.pow2(),i=e.pow2().mul(s.oneMinus()).oneMinus();return s.div(i.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),nC=nm(1/Math.PI),oC=Kp((({alphaT:t,alphaB:e,dotNH:s,dotTH:i,dotBH:r})=>{const n=t.mul(e),o=pm(e.mul(i),t.mul(r),n.mul(s)),a=o.dot(o),h=n.div(a);return nC.mul(n.mul(h.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),aC=Kp((t=>{const{lightDirection:e,f0:s,f90:i,roughness:r,f:n,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=t,h=t.normalView||Yx,u=r.pow2(),l=e.add(jb).normalize(),c=h.dot(e).clamp(),d=h.dot(jb).clamp(),p=h.dot(l).clamp(),m=jb.dot(l).clamp();let g,f,y=HR({f0:s,f90:i,dotVH:m});if(Hp(o)&&(y=wg.mix(y,n)),Hp(a)){const t=Rg.dot(e),s=Rg.dot(jb),i=Rg.dot(l),r=Cg.dot(e),n=Cg.dot(jb),o=Cg.dot(l);g=iC({alphaT:Ag,alphaB:u,dotTV:s,dotBV:n,dotTL:t,dotBL:r,dotNV:d,dotNL:c}),f=oC({alphaT:Ag,alphaB:u,dotNH:p,dotTH:i,dotBH:o})}else g=sC({alpha:u,dotNL:c,dotNV:d}),f=rC({alpha:u,dotNH:p});return y.mul(g).mul(f)})),hC=Kp((({roughness:t,dotNV:e})=>{const s=ym(-1,-.0275,-.572,.022),i=ym(1,.0425,1.04,-.04),r=t.mul(s).add(i),n=r.x.mul(r.x).min(e.mul(-9.28).exp2()).mul(r.x).add(r.y);return um(-1.04,1.04).mul(n).add(r.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),uC=Kp((t=>{const{dotNV:e,specularColor:s,specularF90:i,roughness:r}=t,n=hC({dotNV:e,roughness:r});return s.mul(n.x).add(i.mul(n.y))})),lC=Kp((({f:t,f90:e,dotVH:s})=>{const i=s.oneMinus().saturate(),r=i.mul(i),n=i.mul(r,r).clamp(0,.9999);return t.sub(pm(e).mul(n)).div(n.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),cC=Kp((({roughness:t,dotNH:e})=>{const s=t.pow2(),i=nm(1).div(s),r=e.pow2().oneMinus().max(.0078125);return nm(2).add(i).mul(r.pow(i.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),dC=Kp((({dotNV:t,dotNL:e})=>nm(1).div(nm(4).mul(e.add(t).sub(e.mul(t)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),pC=Kp((({lightDirection:t})=>{const e=t.add(jb).normalize(),s=Yx.dot(t).clamp(),i=Yx.dot(jb).clamp(),r=Yx.dot(e).clamp(),n=cC({roughness:_g,dotNH:r}),o=dC({dotNV:i,dotNL:s});return Tg.mul(n).mul(o)})),mC=Kp((({N:t,V:e,roughness:s})=>{const i=t.dot(e).saturate(),r=um(s,i.oneMinus().sqrt());return r.assign(r.mul(.984375).add(.0078125)),r})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),gC=Kp((({f:t})=>{const e=t.length();return Ty(e.mul(e).add(t.z).div(e.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),fC=Kp((({v1:t,v2:e})=>{const s=t.dot(e),i=s.abs().toVar(),r=i.mul(.0145206).add(.4965155).mul(i).add(.8543985).toVar(),n=i.add(4.1616724).mul(i).add(3.417594).toVar(),o=r.div(n),a=s.greaterThan(0).cond(o,Ty(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return t.cross(e).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),yC=Kp((({N:t,V:e,P:s,mInv:i,p0:r,p1:n,p2:o,p3:a})=>{const h=n.sub(r).toVar(),u=a.sub(r).toVar(),l=h.cross(u),c=pm().toVar();return sm(l.dot(s.sub(r)).greaterThanEqual(0),(()=>{const h=e.sub(t.mul(e.dot(t))).normalize(),u=t.cross(h).negate(),l=i.mul(Mm(h,u,t).transpose()).toVar(),d=l.mul(r.sub(s)).normalize().toVar(),p=l.mul(n.sub(s)).normalize().toVar(),m=l.mul(o.sub(s)).normalize().toVar(),g=l.mul(a.sub(s)).normalize().toVar(),f=pm(0).toVar();f.addAssign(fC({v1:d,v2:p})),f.addAssign(fC({v1:p,v2:m})),f.addAssign(fC({v1:m,v2:g})),f.addAssign(fC({v1:g,v2:d})),c.assign(pm(gC({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),xC=Kp((([t,e,s,i,r])=>{const n=pm(Vy(e.negate(),Qf(t),ff(1,i))),o=pm(hy(r[0].xyz),hy(r[1].xyz),hy(r[2].xyz));return Qf(n).mul(s.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),bC=Kp((([t,e])=>t.mul(zy(e.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),vC=Zv(),TC=Kp((([t,e,s])=>{const i=vC.uv(t),r=$f(nm(Gv.x)).mul(bC(e,s));return i.bicubic(r)})),_C=Kp((([t,e,s])=>(sm(s.notEqual(0),(()=>{const i=qf(e).negate().div(s);return jf(i.negate().mul(t))})),pm(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),wC=Kp((([t,e,s,i,r,n,o,a,h,u,l,c,d,p,m])=>{let g,f;if(m){g=ym().toVar(),f=pm().toVar();const r=l.sub(1).mul(m.mul(.025)),n=pm(l.sub(r),l,l.add(r));dv({start:0,end:3},(({i:r})=>{const l=n.element(r),m=xC(t,e,c,l,a),y=o.add(m),x=u.mul(h.mul(ym(y,1))),b=um(x.xy.div(x.w)).toVar();b.addAssign(1),b.divAssign(2),b.assign(um(b.x,b.y.oneMinus()));const v=TC(b,s,l);g.element(r).assign(v.element(r)),g.a.addAssign(v.a),f.element(r).assign(i.element(r).mul(_C(hy(m),d,p).element(r)))})),g.a.divAssign(3)}else{const r=xC(t,e,c,l,a),n=o.add(r),m=u.mul(h.mul(ym(n,1))),y=um(m.xy.div(m.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(um(y.x,y.y.oneMinus())),g=TC(y,s,l),f=i.mul(_C(hy(r),d,p))}const y=f.rgb.mul(g.rgb),x=t.dot(e).clamp(),b=pm(uC({dotNV:x,specularColor:r,specularF90:n,roughness:s})),v=f.r.add(f.g,f.b).div(3);return ym(b.oneMinus().mul(y),g.a.oneMinus().mul(v).oneMinus())})),SC=Mm(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),MC=(t,e)=>t.sub(e).div(t.add(e)).pow2(),AC=(t,e)=>{const s=t.mul(2*Math.PI*1e-9),i=pm(54856e-17,44201e-17,52481e-17),r=pm(1681e3,1795300,2208400),n=pm(43278e5,93046e5,66121e5),o=nm(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(e.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=i.mul(n.mul(2*Math.PI).sqrt()).mul(r.mul(s).add(e).cos()).mul(s.pow2().negate().mul(n).exp());a=pm(a.x.add(o),a.y,a.z).div(1.0685e-7);return SC.mul(a)},NC=Kp((({outsideIOR:t,eta2:e,cosTheta1:s,thinFilmThickness:i,baseF0:r})=>{const n=Oy(t,e,Dy(0,.03,i)),o=t.div(n).pow2().mul(nm(1).sub(s.pow2())),a=nm(1).sub(o).sqrt(),h=MC(n,t),u=HR({f0:h,f90:1,dotVH:s}),l=u.oneMinus(),c=n.lessThan(t).cond(Math.PI,0),d=nm(Math.PI).sub(c),p=(t=>{const e=t.sqrt();return pm(1).add(e).div(pm(1).sub(e))})(r.clamp(0,.9999)),m=MC(p,n.toVec3()),g=HR({f0:m,f90:1,dotVH:a}),f=pm(p.x.lessThan(n).cond(Math.PI,0),p.y.lessThan(n).cond(Math.PI,0),p.z.lessThan(n).cond(Math.PI,0)),y=n.mul(i,a,2),x=pm(d).add(f),b=u.mul(g).clamp(1e-5,.9999),v=b.sqrt(),T=l.pow2().mul(g).div(pm(1).sub(b));let _=u.add(T),w=T.sub(l);for(let t=1;t<=2;++t){w=w.mul(v);const e=AC(nm(t).mul(y),nm(t).mul(x)).mul(2);_=_.add(w.mul(e))}return _.max(pm(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),RC=Kp((({normal:t,viewDir:e,roughness:s})=>{const i=t.dot(e).saturate(),r=s.pow2(),n=FT(s.lessThan(.25),nm(-339.2).mul(r).add(nm(161.4).mul(s)).sub(25.9),nm(-8.48).mul(r).add(nm(14.3).mul(s)).sub(9.95)),o=FT(s.lessThan(.25),nm(44).mul(r).sub(nm(23.7).mul(s)).add(3.26),nm(1.97).mul(r).sub(nm(3.27).mul(s)).add(.72));return FT(s.lessThan(.25),0,nm(.1).mul(s).sub(.025)).add(n.mul(i).add(o).exp()).mul(1/Math.PI).saturate()})),CC=pm(.04),EC=nm(1);class BC extends eg{constructor(t=!1,e=!1,s=!1,i=!1,r=!1,n=!1){super(),this.clearcoat=t,this.sheen=e,this.iridescence=s,this.anisotropy=i,this.transmission=r,this.dispersion=n,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(t){if(!0===this.clearcoat&&(this.clearcoatRadiance=pm().temp("clearcoatRadiance"),this.clearcoatSpecularDirect=pm().temp("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=pm().temp("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=pm().temp("sheenSpecularDirect"),this.sheenSpecularIndirect=pm().temp("sheenSpecularIndirect")),!0===this.iridescence){const t=Yx.dot(jb).clamp();this.iridescenceFresnel=NC({outsideIOR:nm(1),eta2:Sg,cosTheta1:t,thinFilmThickness:Mg,baseF0:Eg}),this.iridescenceF0=lC({f:this.iridescenceFresnel,f90:1,dotVH:t})}if(!0===this.transmission){const e=kb,s=Nx.sub(kb).normalize(),i=Jx;t.backdrop=wC(i,s,yg,gg,Eg,Bg,e,Dx,Sx,_x,zg,Vg,kg,Dg,this.dispersion?Gg:null),t.backdropAlpha=Lg,gg.a.mulAssign(Oy(1,t.backdrop.a,Lg))}}computeMultiscattering(t,e,s){const i=Yx.dot(jb).clamp(),r=hC({roughness:yg,dotNV:i}),n=(this.iridescenceF0?wg.mix(Eg,this.iridescenceF0):Eg).mul(r.x).add(s.mul(r.y)),o=r.x.add(r.y).oneMinus(),a=Eg.add(Eg.oneMinus().mul(.047619)),h=n.mul(a).div(o.mul(a).oneMinus());t.addAssign(n),e.addAssign(h.mul(o))}direct({lightDirection:t,lightColor:e,reflectedLight:s}){const i=Yx.dot(t).clamp().mul(e);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(i.mul(pC({lightDirection:t}))),!0===this.clearcoat){const s=Zx.dot(t).clamp().mul(e);this.clearcoatSpecularDirect.addAssign(s.mul(aC({lightDirection:t,f0:CC,f90:EC,roughness:vg,normalView:Zx})))}s.directDiffuse.addAssign(i.mul(qR({diffuseColor:gg.rgb}))),s.directSpecular.addAssign(i.mul(aC({lightDirection:t,f0:Eg,f90:1,roughness:yg,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:t,lightPosition:e,halfWidth:s,halfHeight:i,reflectedLight:r,ltc_1:n,ltc_2:o}){const a=e.add(s).sub(i),h=e.sub(s).sub(i),u=e.sub(s).add(i),l=e.add(s).add(i),c=Yx,d=jb,p=Wb.toVar(),m=mC({N:c,V:d,roughness:yg}),g=n.uv(m).toVar(),f=o.uv(m).toVar(),y=Mm(pm(g.x,0,g.y),pm(0,1,0),pm(g.z,0,g.w)).toVar(),x=Eg.mul(f.x).add(Eg.oneMinus().mul(f.y)).toVar();r.directSpecular.addAssign(t.mul(x).mul(yC({N:c,V:d,P:p,mInv:y,p0:a,p1:h,p2:u,p3:l}))),r.directDiffuse.addAssign(t.mul(gg).mul(yC({N:c,V:d,P:p,mInv:Mm(1,0,0,0,1,0,0,0,1),p0:a,p1:h,p2:u,p3:l})))}indirect(t,e,s){this.indirectDiffuse(t,e,s),this.indirectSpecular(t,e,s),this.ambientOcclusion(t,e,s)}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.addAssign(t.mul(qR({diffuseColor:gg})))}indirectSpecular({radiance:t,iblIrradiance:e,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(e.mul(Tg,RC({normal:Yx,viewDir:jb,roughness:_g}))),!0===this.clearcoat){const t=Zx.dot(jb).clamp(),e=uC({dotNV:t,specularColor:CC,specularF90:EC,roughness:vg});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(e))}const i=pm().temp("singleScattering"),r=pm().temp("multiScattering"),n=e.mul(1/Math.PI);this.computeMultiscattering(i,r,Bg);const o=i.add(r),a=gg.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(t.mul(i)),s.indirectSpecular.addAssign(r.mul(n)),s.indirectDiffuse.addAssign(a.mul(n))}ambientOcclusion({ambientOcclusion:t,reflectedLight:e}){const s=Yx.dot(jb).clamp().add(t),i=yg.mul(-16).oneMinus().negate().exp2(),r=t.sub(s.pow(i).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(t),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(t),e.indirectDiffuse.mulAssign(t),e.indirectSpecular.mulAssign(r)}finish(t){const{outgoingLight:e}=t;if(!0===this.clearcoat){const t=Zx.dot(jb).clamp(),s=HR({dotVH:t,f0:CC,f90:EC}),i=e.mul(bg.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(bg));e.assign(i)}if(!0===this.sheen){const t=Tg.r.max(Tg.g).max(Tg.b).mul(.157).oneMinus(),s=e.mul(t).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);e.assign(s)}}}const IC=new Au;class PC extends gT{constructor(t){super(),this.isMeshStandardNodeMaterial=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(IC),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new wR(e):null}setupLightingModel(){return new BC}setupSpecular(){const t=Oy(pm(.04),gg.rgb,xg);Eg.assign(t),Bg.assign(1)}setupVariants(){const t=this.metalnessNode?nm(this.metalnessNode):cb;xg.assign(t);let e=this.roughnessNode?nm(this.roughnessNode):lb;e=eC({roughness:e}),yg.assign(e),this.setupSpecular(),gg.assign(ym(gg.rgb.mul(t.oneMinus()),gg.a))}copy(t){return this.emissiveNode=t.emissiveNode,this.metalnessNode=t.metalnessNode,this.roughnessNode=t.roughnessNode,super.copy(t)}}fT("MeshStandardNodeMaterial",PC);const FC=new Nu;class UC extends PC{constructor(t){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(FC),this.setValues(t)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const t=this.iorNode?nm(this.iorNode):Mb;zg.assign(t),Eg.assign(Oy(vy(Ey(zg.sub(1).div(zg.add(1))).mul(ab),pm(1)).mul(ob),gg.rgb,xg)),Bg.assign(Oy(ob,1,xg))}setupLightingModel(){return new BC(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(t){if(super.setupVariants(t),this.useClearcoat){const t=this.clearcoatNode?nm(this.clearcoatNode):pb,e=this.clearcoatRoughnessNode?nm(this.clearcoatRoughnessNode):mb;bg.assign(t),vg.assign(eC({roughness:e}))}if(this.useSheen){const t=this.sheenNode?pm(this.sheenNode):yb,e=this.sheenRoughnessNode?nm(this.sheenRoughnessNode):xb;Tg.assign(t),_g.assign(e)}if(this.useIridescence){const t=this.iridescenceNode?nm(this.iridescenceNode):vb,e=this.iridescenceIORNode?nm(this.iridescenceIORNode):Tb,s=this.iridescenceThicknessNode?nm(this.iridescenceThicknessNode):_b;wg.assign(t),Sg.assign(e),Mg.assign(s)}if(this.useAnisotropy){const t=(this.anisotropyNode?um(this.anisotropyNode):bb).toVar();Ng.assign(t.length()),sm(Ng.equal(0),(()=>{t.assign(um(1,0))})).else((()=>{t.divAssign(um(Ng)),Ng.assign(Ng.saturate())})),Ag.assign(Ng.pow2().mix(yg.pow2(),1)),Rg.assign(hS[0].mul(t.x).add(hS[1].mul(t.y))),Cg.assign(hS[1].mul(t.x).sub(hS[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?nm(this.transmissionNode):wb,e=this.thicknessNode?nm(this.thicknessNode):Sb,s=this.attenuationDistanceNode?nm(this.attenuationDistanceNode):Ab,i=this.attenuationColorNode?pm(this.attenuationColorNode):Nb;if(Lg.assign(t),Vg.assign(e),Dg.assign(s),kg.assign(i),this.useDispersion){const t=this.dispersionNode?nm(this.dispersionNode):Fb;Gg.assign(t)}}}setupNormal(t){super.setupNormal(t);const e=this.clearcoatNormalNode?pm(this.clearcoatNormalNode):gb;Zx.assign(e)}copy(t){return this.clearcoatNode=t.clearcoatNode,this.clearcoatRoughnessNode=t.clearcoatRoughnessNode,this.clearcoatNormalNode=t.clearcoatNormalNode,this.sheenNode=t.sheenNode,this.sheenRoughnessNode=t.sheenRoughnessNode,this.iridescenceNode=t.iridescenceNode,this.iridescenceIORNode=t.iridescenceIORNode,this.iridescenceThicknessNode=t.iridescenceThicknessNode,this.specularIntensityNode=t.specularIntensityNode,this.specularColorNode=t.specularColorNode,this.transmissionNode=t.transmissionNode,this.thicknessNode=t.thicknessNode,this.attenuationDistanceNode=t.attenuationDistanceNode,this.attenuationColorNode=t.attenuationColorNode,this.dispersionNode=t.dispersionNode,this.anisotropyNode=t.anisotropyNode,super.copy(t)}}fT("MeshPhysicalNodeMaterial",UC);class OC extends BC{constructor(t,e,s,i){super(t,e,s),this.useSSS=i}direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r){if(!0===this.useSSS){const i=r.material,{thicknessColorNode:n,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:h,thicknessPowerNode:u,thicknessScaleNode:l}=i,c=t.add(Yx.mul(o)).normalize(),d=nm(jb.dot(c.negate()).saturate().pow(u).mul(l)),p=pm(d.add(a).mul(n));s.directDiffuse.addAssign(p.mul(h.mul(e)))}super.direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r)}}class zC extends UC{constructor(t){super(t),this.thicknessColorNode=null,this.thicknessDistortionNode=nm(.1),this.thicknessAmbientNode=nm(0),this.thicknessAttenuationNode=nm(.1),this.thicknessPowerNode=nm(2),this.thicknessScaleNode=nm(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new OC(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(t){return this.thicknessColorNode=t.thicknessColorNode,this.thicknessDistortionNode=t.thicknessDistortionNode,this.thicknessAmbientNode=t.thicknessAmbientNode,this.thicknessAttenuationNode=t.thicknessAttenuationNode,this.thicknessPowerNode=t.thicknessPowerNode,this.thicknessScaleNode=t.thicknessScaleNode,super.copy(t)}}fT("MeshSSSNodeMaterial",zC);const LC=Kp((({normal:t,lightDirection:e,builder:s})=>{const i=t.dot(e),r=um(i.mul(.5).add(.5),0);if(s.material.gradientMap){const t=yx("gradientMap","texture").context({getUV:()=>r});return pm(t.r)}{const t=r.fwidth().mul(.5);return Oy(pm(.7),pm(1),Dy(nm(.7).sub(t.x),nm(.7).add(t.x),r.x))}}));class VC extends eg{direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r){const n=LC({normal:Hx,lightDirection:t,builder:r}).mul(e);s.directDiffuse.addAssign(n.mul(qR({diffuseColor:gg.rgb})))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:s}){s.indirectDiffuse.addAssign(e.mul(qR({diffuseColor:gg}))),s.indirectDiffuse.mulAssign(t)}}const DC=new Cu;class kC extends gT{constructor(t){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(DC),this.setValues(t)}setupLightingModel(){return new VC}}fT("MeshToonNodeMaterial",kC);const GC=new Fu;class WC extends gT{constructor(t){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(GC),this.setValues(t)}setupVariants(t){const e=nw;let s;s=t.material.matcap?yx("matcap","texture").context({getUV:()=>e}):pm(Oy(.2,.8,e.y)),gg.rgb.mulAssign(s.rgb)}}fT("MeshMatcapNodeMaterial",WC);const jC=new Va;class HC extends gT{constructor(t){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.normals=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(jC),this.setValues(t)}copy(t){return this.sizeNode=t.sizeNode,super.copy(t)}}fT("PointsNodeMaterial",HC);const qC=new uo;class $C extends gT{constructor(t){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this.normals=!1,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(qC),this.setValues(t)}setupPosition({object:t,context:e}){const{positionNode:s,rotationNode:i,scaleNode:r}=this,n=Db;let o=Lx.mul(pm(s||0)),a=um(Dx[0].xyz.length(),Dx[1].xyz.length());null!==r&&(a=a.mul(r));let h=n.xy;t.center&&!0===t.center.isVector2&&(h=h.sub(hf(t.center).sub(.5))),h=h.mul(a);const u=nm(i||fb),l=h.rotate(u);o=ym(o.xy.add(l),o.zw);const c=_x.mul(o);return e.vertex=n,c}copy(t){return this.positionNode=t.positionNode,this.rotationNode=t.rotationNode,this.scaleNode=t.scaleNode,super.copy(t)}}fT("SpriteNodeMaterial",$C);class XC extends eg{constructor(){super(),this.shadowNode=nm(1).toVar("shadowMask")}direct({shadowMask:t}){this.shadowNode.mulAssign(t)}finish(t){gg.a.mulAssign(this.shadowNode.oneMinus()),t.outgoingLight.rgb.assign(gg.rgb)}}const YC=new Su;class JC extends gT{constructor(t){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(YC),this.setValues(t)}setupLightingModel(){return new XC}}fT("ShadowNodeMaterial",JC);class ZC extends gT{constructor(t={}){super(),this.normals=!1,this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(t)}setup(t){const e=aA(this.map,null,0),s=Kp((({orig:t,dir:e})=>{const s=pm(-.5),i=pm(.5),r=e.reciprocal(),n=s.sub(t).mul(r),o=i.sub(t).mul(r),a=vy(n,o),h=Ty(n,o),u=Ty(a.x,Ty(a.y,a.z)),l=vy(h.x,vy(h.y,h.z));return um(u,l)}));this.fragmentNode=Kp((()=>{const t=km(pm(jx.mul(ym(Nx,1)))),i=km(Vb.sub(t)).normalize(),r=pg("vec2","bounds").assign(s({orig:t,dir:i}));r.x.greaterThan(r.y).discard(),r.assign(um(Ty(r.x,0),r.y));const n=pg("vec3","p").assign(t.add(r.x.mul(i))),o=pg("vec3","inc").assign(pm(i.abs().reciprocal())),a=pg("float","delta").assign(vy(o.x,vy(o.y,o.z)));a.divAssign(yx("steps","float"));const h=pg("vec4","ac").assign(ym(yx("base","color"),0));return dv({type:"float",start:r.x,end:r.y,update:"+= delta"},(()=>{const t=pg("float","d").assign(e.uv(n.add(.5)).r);null!==this.testNode?this.testNode({map:e,mapValue:t,probe:n,finalColor:h}).append():(h.a.assign(1),mv()),n.addAssign(i.mul(a))})),h.a.equal(0).discard(),ym(h)}))(),super.setup(t)}}fT("VolumeNodeMaterial",ZC);const QC=Ul.createMaterialFromType;Ul.createMaterialFromType=function(t){const e=yT(t);return void 0!==e?e:QC.call(this,t)};class KC extends Ul{constructor(t){super(t),this.nodes={}}parse(t){const e=super.parse(t),s=this.nodes,i=t.inputNodes;for(const t in i){const r=i[t];e[t]=s[r]}return e}setNodes(t){return this.nodes=t,this}}class tE extends Vl{constructor(t){super(t),this._nodesJSON=null}parse(t,e){this._nodesJSON=t.nodes;const s=super.parse(t,e);return this._nodesJSON=null,s}parseNodes(t,e){if(void 0!==t){const s=new ER;return s.setTextures(e),s.parseNodes(t)}return{}}parseMaterials(t,e){const s={};if(void 0!==t){const i=this.parseNodes(this._nodesJSON,e),r=new KC;r.setTextures(e),r.setNodes(i);for(let e=0,i=t.length;e{const e=(t=t.trim()).indexOf(nE),s=-1!==e?t.slice(e+12):t,i=s.match(iE);if(null!==i&&5===i.length){const r=i[4],n=[];let o=null;for(;null!==(o=rE.exec(r));)n.push(o);const a=[];let h=0;for(;h{const i=nm(s).toVar(),r=nm(e).toVar(),n=hm(t).toVar();return FT(n,r,i)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),uE=Kp((([t,e])=>{const s=hm(e).toVar(),i=nm(t).toVar();return FT(s,i.negate(),i)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),lE=Kp((([t])=>{const e=nm(t).toVar();return om(Jf(e))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),cE=Kp((([t,e])=>{const s=nm(t).toVar();return e.assign(lE(s)),s.sub(nm(e))})),dE=iw([Kp((([t,e,s,i,r,n])=>{const o=nm(n).toVar(),a=nm(r).toVar(),h=nm(i).toVar(),u=nm(s).toVar(),l=nm(e).toVar(),c=nm(t).toVar(),d=nm(mf(1,a)).toVar();return mf(1,o).mul(c.mul(d).add(l.mul(a))).add(o.mul(u.mul(d).add(h.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),Kp((([t,e,s,i,r,n])=>{const o=nm(n).toVar(),a=nm(r).toVar(),h=pm(i).toVar(),u=pm(s).toVar(),l=pm(e).toVar(),c=pm(t).toVar(),d=nm(mf(1,a)).toVar();return mf(1,o).mul(c.mul(d).add(l.mul(a))).add(o.mul(u.mul(d).add(h.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),pE=iw([Kp((([t,e,s,i,r,n,o,a,h,u,l])=>{const c=nm(l).toVar(),d=nm(u).toVar(),p=nm(h).toVar(),m=nm(a).toVar(),g=nm(o).toVar(),f=nm(n).toVar(),y=nm(r).toVar(),x=nm(i).toVar(),b=nm(s).toVar(),v=nm(e).toVar(),T=nm(t).toVar(),_=nm(mf(1,p)).toVar(),w=nm(mf(1,d)).toVar();return nm(mf(1,c)).toVar().mul(w.mul(T.mul(_).add(v.mul(p))).add(d.mul(b.mul(_).add(x.mul(p))))).add(c.mul(w.mul(y.mul(_).add(f.mul(p))).add(d.mul(g.mul(_).add(m.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),Kp((([t,e,s,i,r,n,o,a,h,u,l])=>{const c=nm(l).toVar(),d=nm(u).toVar(),p=nm(h).toVar(),m=pm(a).toVar(),g=pm(o).toVar(),f=pm(n).toVar(),y=pm(r).toVar(),x=pm(i).toVar(),b=pm(s).toVar(),v=pm(e).toVar(),T=pm(t).toVar(),_=nm(mf(1,p)).toVar(),w=nm(mf(1,d)).toVar();return nm(mf(1,c)).toVar().mul(w.mul(T.mul(_).add(v.mul(p))).add(d.mul(b.mul(_).add(x.mul(p))))).add(c.mul(w.mul(y.mul(_).add(f.mul(p))).add(d.mul(g.mul(_).add(m.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),mE=Kp((([t,e,s])=>{const i=nm(s).toVar(),r=nm(e).toVar(),n=am(t).toVar(),o=am(n.bitAnd(am(7))).toVar(),a=nm(hE(o.lessThan(am(4)),r,i)).toVar(),h=nm(gf(2,hE(o.lessThan(am(4)),i,r))).toVar();return uE(a,hm(o.bitAnd(am(1)))).add(uE(h,hm(o.bitAnd(am(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),gE=Kp((([t,e,s,i])=>{const r=nm(i).toVar(),n=nm(s).toVar(),o=nm(e).toVar(),a=am(t).toVar(),h=am(a.bitAnd(am(15))).toVar(),u=nm(hE(h.lessThan(am(8)),o,n)).toVar(),l=nm(hE(h.lessThan(am(4)),n,hE(h.equal(am(12)).or(h.equal(am(14))),o,r))).toVar();return uE(u,hm(h.bitAnd(am(1)))).add(uE(l,hm(h.bitAnd(am(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),fE=iw([mE,gE]),yE=Kp((([t,e,s])=>{const i=nm(s).toVar(),r=nm(e).toVar(),n=gm(t).toVar();return pm(fE(n.x,r,i),fE(n.y,r,i),fE(n.z,r,i))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),xE=Kp((([t,e,s,i])=>{const r=nm(i).toVar(),n=nm(s).toVar(),o=nm(e).toVar(),a=gm(t).toVar();return pm(fE(a.x,o,n,r),fE(a.y,o,n,r),fE(a.z,o,n,r))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),bE=iw([yE,xE]),vE=Kp((([t])=>{const e=nm(t).toVar();return gf(.6616,e)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),TE=Kp((([t])=>{const e=nm(t).toVar();return gf(.982,e)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),_E=iw([vE,Kp((([t])=>{const e=pm(t).toVar();return gf(.6616,e)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),wE=iw([TE,Kp((([t])=>{const e=pm(t).toVar();return gf(.982,e)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),SE=Kp((([t,e])=>{const s=om(e).toVar(),i=am(t).toVar();return i.shiftLeft(s).bitOr(i.shiftRight(om(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),ME=Kp((([t,e,s])=>{t.subAssign(s),t.bitXorAssign(SE(s,om(4))),s.addAssign(e),e.subAssign(t),e.bitXorAssign(SE(t,om(6))),t.addAssign(s),s.subAssign(e),s.bitXorAssign(SE(e,om(8))),e.addAssign(t),t.subAssign(s),t.bitXorAssign(SE(s,om(16))),s.addAssign(e),e.subAssign(t),e.bitXorAssign(SE(t,om(19))),t.addAssign(s),s.subAssign(e),s.bitXorAssign(SE(e,om(4))),e.addAssign(t)})),AE=Kp((([t,e,s])=>{const i=am(s).toVar(),r=am(e).toVar(),n=am(t).toVar();return i.bitXorAssign(r),i.subAssign(SE(r,om(14))),n.bitXorAssign(i),n.subAssign(SE(i,om(11))),r.bitXorAssign(n),r.subAssign(SE(n,om(25))),i.bitXorAssign(r),i.subAssign(SE(r,om(16))),n.bitXorAssign(i),n.subAssign(SE(i,om(4))),r.bitXorAssign(n),r.subAssign(SE(n,om(14))),i.bitXorAssign(r),i.subAssign(SE(r,om(24))),i})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),NE=Kp((([t])=>{const e=am(t).toVar();return nm(e).div(nm(am(om(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),RE=Kp((([t])=>{const e=nm(t).toVar();return e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),CE=iw([Kp((([t])=>{const e=om(t).toVar(),s=am(am(1)).toVar(),i=am(am(om(3735928559)).add(s.shiftLeft(am(2))).add(am(13))).toVar();return AE(i.add(am(e)),i,i)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),Kp((([t,e])=>{const s=om(e).toVar(),i=om(t).toVar(),r=am(am(2)).toVar(),n=am().toVar(),o=am().toVar(),a=am().toVar();return n.assign(o.assign(a.assign(am(om(3735928559)).add(r.shiftLeft(am(2))).add(am(13))))),n.addAssign(am(i)),o.addAssign(am(s)),AE(n,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Kp((([t,e,s])=>{const i=om(s).toVar(),r=om(e).toVar(),n=om(t).toVar(),o=am(am(3)).toVar(),a=am().toVar(),h=am().toVar(),u=am().toVar();return a.assign(h.assign(u.assign(am(om(3735928559)).add(o.shiftLeft(am(2))).add(am(13))))),a.addAssign(am(n)),h.addAssign(am(r)),u.addAssign(am(i)),AE(a,h,u)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),Kp((([t,e,s,i])=>{const r=om(i).toVar(),n=om(s).toVar(),o=om(e).toVar(),a=om(t).toVar(),h=am(am(4)).toVar(),u=am().toVar(),l=am().toVar(),c=am().toVar();return u.assign(l.assign(c.assign(am(om(3735928559)).add(h.shiftLeft(am(2))).add(am(13))))),u.addAssign(am(a)),l.addAssign(am(o)),c.addAssign(am(n)),ME(u,l,c),u.addAssign(am(r)),AE(u,l,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),Kp((([t,e,s,i,r])=>{const n=om(r).toVar(),o=om(i).toVar(),a=om(s).toVar(),h=om(e).toVar(),u=om(t).toVar(),l=am(am(5)).toVar(),c=am().toVar(),d=am().toVar(),p=am().toVar();return c.assign(d.assign(p.assign(am(om(3735928559)).add(l.shiftLeft(am(2))).add(am(13))))),c.addAssign(am(u)),d.addAssign(am(h)),p.addAssign(am(a)),ME(c,d,p),c.addAssign(am(o)),d.addAssign(am(n)),AE(c,d,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),EE=iw([Kp((([t,e])=>{const s=om(e).toVar(),i=om(t).toVar(),r=am(CE(i,s)).toVar(),n=gm().toVar();return n.x.assign(r.bitAnd(om(255))),n.y.assign(r.shiftRight(om(8)).bitAnd(om(255))),n.z.assign(r.shiftRight(om(16)).bitAnd(om(255))),n})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Kp((([t,e,s])=>{const i=om(s).toVar(),r=om(e).toVar(),n=om(t).toVar(),o=am(CE(n,r,i)).toVar(),a=gm().toVar();return a.x.assign(o.bitAnd(om(255))),a.y.assign(o.shiftRight(om(8)).bitAnd(om(255))),a.z.assign(o.shiftRight(om(16)).bitAnd(om(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),BE=iw([Kp((([t])=>{const e=um(t).toVar(),s=om().toVar(),i=om().toVar(),r=nm(cE(e.x,s)).toVar(),n=nm(cE(e.y,i)).toVar(),o=nm(RE(r)).toVar(),a=nm(RE(n)).toVar(),h=nm(dE(fE(CE(s,i),r,n),fE(CE(s.add(om(1)),i),r.sub(1),n),fE(CE(s,i.add(om(1))),r,n.sub(1)),fE(CE(s.add(om(1)),i.add(om(1))),r.sub(1),n.sub(1)),o,a)).toVar();return _E(h)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),Kp((([t])=>{const e=pm(t).toVar(),s=om().toVar(),i=om().toVar(),r=om().toVar(),n=nm(cE(e.x,s)).toVar(),o=nm(cE(e.y,i)).toVar(),a=nm(cE(e.z,r)).toVar(),h=nm(RE(n)).toVar(),u=nm(RE(o)).toVar(),l=nm(RE(a)).toVar(),c=nm(pE(fE(CE(s,i,r),n,o,a),fE(CE(s.add(om(1)),i,r),n.sub(1),o,a),fE(CE(s,i.add(om(1)),r),n,o.sub(1),a),fE(CE(s.add(om(1)),i.add(om(1)),r),n.sub(1),o.sub(1),a),fE(CE(s,i,r.add(om(1))),n,o,a.sub(1)),fE(CE(s.add(om(1)),i,r.add(om(1))),n.sub(1),o,a.sub(1)),fE(CE(s,i.add(om(1)),r.add(om(1))),n,o.sub(1),a.sub(1)),fE(CE(s.add(om(1)),i.add(om(1)),r.add(om(1))),n.sub(1),o.sub(1),a.sub(1)),h,u,l)).toVar();return wE(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),IE=iw([Kp((([t])=>{const e=um(t).toVar(),s=om().toVar(),i=om().toVar(),r=nm(cE(e.x,s)).toVar(),n=nm(cE(e.y,i)).toVar(),o=nm(RE(r)).toVar(),a=nm(RE(n)).toVar(),h=pm(dE(bE(EE(s,i),r,n),bE(EE(s.add(om(1)),i),r.sub(1),n),bE(EE(s,i.add(om(1))),r,n.sub(1)),bE(EE(s.add(om(1)),i.add(om(1))),r.sub(1),n.sub(1)),o,a)).toVar();return _E(h)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Kp((([t])=>{const e=pm(t).toVar(),s=om().toVar(),i=om().toVar(),r=om().toVar(),n=nm(cE(e.x,s)).toVar(),o=nm(cE(e.y,i)).toVar(),a=nm(cE(e.z,r)).toVar(),h=nm(RE(n)).toVar(),u=nm(RE(o)).toVar(),l=nm(RE(a)).toVar(),c=pm(pE(bE(EE(s,i,r),n,o,a),bE(EE(s.add(om(1)),i,r),n.sub(1),o,a),bE(EE(s,i.add(om(1)),r),n,o.sub(1),a),bE(EE(s.add(om(1)),i.add(om(1)),r),n.sub(1),o.sub(1),a),bE(EE(s,i,r.add(om(1))),n,o,a.sub(1)),bE(EE(s.add(om(1)),i,r.add(om(1))),n.sub(1),o,a.sub(1)),bE(EE(s,i.add(om(1)),r.add(om(1))),n,o.sub(1),a.sub(1)),bE(EE(s.add(om(1)),i.add(om(1)),r.add(om(1))),n.sub(1),o.sub(1),a.sub(1)),h,u,l)).toVar();return wE(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),PE=iw([Kp((([t])=>{const e=nm(t).toVar(),s=om(lE(e)).toVar();return NE(CE(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),Kp((([t])=>{const e=um(t).toVar(),s=om(lE(e.x)).toVar(),i=om(lE(e.y)).toVar();return NE(CE(s,i))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),Kp((([t])=>{const e=pm(t).toVar(),s=om(lE(e.x)).toVar(),i=om(lE(e.y)).toVar(),r=om(lE(e.z)).toVar();return NE(CE(s,i,r))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),Kp((([t])=>{const e=ym(t).toVar(),s=om(lE(e.x)).toVar(),i=om(lE(e.y)).toVar(),r=om(lE(e.z)).toVar(),n=om(lE(e.w)).toVar();return NE(CE(s,i,r,n))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),FE=iw([Kp((([t])=>{const e=nm(t).toVar(),s=om(lE(e)).toVar();return pm(NE(CE(s,om(0))),NE(CE(s,om(1))),NE(CE(s,om(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),Kp((([t])=>{const e=um(t).toVar(),s=om(lE(e.x)).toVar(),i=om(lE(e.y)).toVar();return pm(NE(CE(s,i,om(0))),NE(CE(s,i,om(1))),NE(CE(s,i,om(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Kp((([t])=>{const e=pm(t).toVar(),s=om(lE(e.x)).toVar(),i=om(lE(e.y)).toVar(),r=om(lE(e.z)).toVar();return pm(NE(CE(s,i,r,om(0))),NE(CE(s,i,r,om(1))),NE(CE(s,i,r,om(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Kp((([t])=>{const e=ym(t).toVar(),s=om(lE(e.x)).toVar(),i=om(lE(e.y)).toVar(),r=om(lE(e.z)).toVar(),n=om(lE(e.w)).toVar();return pm(NE(CE(s,i,r,n,om(0))),NE(CE(s,i,r,n,om(1))),NE(CE(s,i,r,n,om(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),UE=Kp((([t,e,s,i])=>{const r=nm(i).toVar(),n=nm(s).toVar(),o=om(e).toVar(),a=pm(t).toVar(),h=nm(0).toVar(),u=nm(1).toVar();return dv(o,(()=>{h.addAssign(u.mul(BE(a))),u.mulAssign(r),a.mulAssign(n)})),h})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),OE=Kp((([t,e,s,i])=>{const r=nm(i).toVar(),n=nm(s).toVar(),o=om(e).toVar(),a=pm(t).toVar(),h=pm(0).toVar(),u=nm(1).toVar();return dv(o,(()=>{h.addAssign(u.mul(IE(a))),u.mulAssign(r),a.mulAssign(n)})),h})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),zE=Kp((([t,e,s,i])=>{const r=nm(i).toVar(),n=nm(s).toVar(),o=om(e).toVar(),a=pm(t).toVar();return um(UE(a,o,n,r),UE(a.add(pm(om(19),om(193),om(17))),o,n,r))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),LE=Kp((([t,e,s,i])=>{const r=nm(i).toVar(),n=nm(s).toVar(),o=om(e).toVar(),a=pm(t).toVar(),h=pm(OE(a,o,n,r)).toVar(),u=nm(UE(a.add(pm(om(19),om(193),om(17))),o,n,r)).toVar();return ym(h,u)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),VE=Kp((([t,e,s,i,r,n,o])=>{const a=om(o).toVar(),h=nm(n).toVar(),u=om(r).toVar(),l=om(i).toVar(),c=om(s).toVar(),d=om(e).toVar(),p=um(t).toVar(),m=pm(FE(um(d.add(l),c.add(u)))).toVar(),g=um(m.x,m.y).toVar();g.subAssign(.5),g.mulAssign(h),g.addAssign(.5);const f=um(um(nm(d),nm(c)).add(g)).toVar(),y=um(f.sub(p)).toVar();return sm(a.equal(om(2)),(()=>oy(y.x).add(oy(y.y)))),sm(a.equal(om(3)),(()=>Ty(oy(y.x),oy(y.y)))),Ny(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),DE=iw([VE,Kp((([t,e,s,i,r,n,o,a,h])=>{const u=om(h).toVar(),l=nm(a).toVar(),c=om(o).toVar(),d=om(n).toVar(),p=om(r).toVar(),m=om(i).toVar(),g=om(s).toVar(),f=om(e).toVar(),y=pm(t).toVar(),x=pm(FE(pm(f.add(p),g.add(d),m.add(c)))).toVar();x.subAssign(.5),x.mulAssign(l),x.addAssign(.5);const b=pm(pm(nm(f),nm(g),nm(m)).add(x)).toVar(),v=pm(b.sub(y)).toVar();return sm(u.equal(om(2)),(()=>oy(v.x).add(oy(v.y)).add(oy(v.z)))),sm(u.equal(om(3)),(()=>Ty(Ty(oy(v.x),oy(v.y)),oy(v.z)))),Ny(v,v)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),kE=Kp((([t,e,s])=>{const i=om(s).toVar(),r=nm(e).toVar(),n=um(t).toVar(),o=om().toVar(),a=om().toVar(),h=um(cE(n.x,o),cE(n.y,a)).toVar(),u=nm(1e6).toVar();return dv({start:-1,end:om(1),name:"x",condition:"<="},(({x:t})=>{dv({start:-1,end:om(1),name:"y",condition:"<="},(({y:e})=>{const s=nm(DE(h,t,e,o,a,r,i)).toVar();u.assign(vy(u,s))}))})),sm(i.equal(om(0)),(()=>{u.assign(Xf(u))})),u})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),GE=Kp((([t,e,s])=>{const i=om(s).toVar(),r=nm(e).toVar(),n=um(t).toVar(),o=om().toVar(),a=om().toVar(),h=um(cE(n.x,o),cE(n.y,a)).toVar(),u=um(1e6,1e6).toVar();return dv({start:-1,end:om(1),name:"x",condition:"<="},(({x:t})=>{dv({start:-1,end:om(1),name:"y",condition:"<="},(({y:e})=>{const s=nm(DE(h,t,e,o,a,r,i)).toVar();sm(s.lessThan(u.x),(()=>{u.y.assign(u.x),u.x.assign(s)})).elseif(s.lessThan(u.y),(()=>{u.y.assign(s)}))}))})),sm(i.equal(om(0)),(()=>{u.assign(Xf(u))})),u})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),WE=Kp((([t,e,s])=>{const i=om(s).toVar(),r=nm(e).toVar(),n=um(t).toVar(),o=om().toVar(),a=om().toVar(),h=um(cE(n.x,o),cE(n.y,a)).toVar(),u=pm(1e6,1e6,1e6).toVar();return dv({start:-1,end:om(1),name:"x",condition:"<="},(({x:t})=>{dv({start:-1,end:om(1),name:"y",condition:"<="},(({y:e})=>{const s=nm(DE(h,t,e,o,a,r,i)).toVar();sm(s.lessThan(u.x),(()=>{u.z.assign(u.y),u.y.assign(u.x),u.x.assign(s)})).elseif(s.lessThan(u.y),(()=>{u.z.assign(u.y),u.y.assign(s)})).elseif(s.lessThan(u.z),(()=>{u.z.assign(s)}))}))})),sm(i.equal(om(0)),(()=>{u.assign(Xf(u))})),u})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),jE=iw([kE,Kp((([t,e,s])=>{const i=om(s).toVar(),r=nm(e).toVar(),n=pm(t).toVar(),o=om().toVar(),a=om().toVar(),h=om().toVar(),u=pm(cE(n.x,o),cE(n.y,a),cE(n.z,h)).toVar(),l=nm(1e6).toVar();return dv({start:-1,end:om(1),name:"x",condition:"<="},(({x:t})=>{dv({start:-1,end:om(1),name:"y",condition:"<="},(({y:e})=>{dv({start:-1,end:om(1),name:"z",condition:"<="},(({z:s})=>{const n=nm(DE(u,t,e,s,o,a,h,r,i)).toVar();l.assign(vy(l,n))}))}))})),sm(i.equal(om(0)),(()=>{l.assign(Xf(l))})),l})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),HE=iw([GE,Kp((([t,e,s])=>{const i=om(s).toVar(),r=nm(e).toVar(),n=pm(t).toVar(),o=om().toVar(),a=om().toVar(),h=om().toVar(),u=pm(cE(n.x,o),cE(n.y,a),cE(n.z,h)).toVar(),l=um(1e6,1e6).toVar();return dv({start:-1,end:om(1),name:"x",condition:"<="},(({x:t})=>{dv({start:-1,end:om(1),name:"y",condition:"<="},(({y:e})=>{dv({start:-1,end:om(1),name:"z",condition:"<="},(({z:s})=>{const n=nm(DE(u,t,e,s,o,a,h,r,i)).toVar();sm(n.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(n)})).elseif(n.lessThan(l.y),(()=>{l.y.assign(n)}))}))}))})),sm(i.equal(om(0)),(()=>{l.assign(Xf(l))})),l})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),qE=iw([WE,Kp((([t,e,s])=>{const i=om(s).toVar(),r=nm(e).toVar(),n=pm(t).toVar(),o=om().toVar(),a=om().toVar(),h=om().toVar(),u=pm(cE(n.x,o),cE(n.y,a),cE(n.z,h)).toVar(),l=pm(1e6,1e6,1e6).toVar();return dv({start:-1,end:om(1),name:"x",condition:"<="},(({x:t})=>{dv({start:-1,end:om(1),name:"y",condition:"<="},(({y:e})=>{dv({start:-1,end:om(1),name:"z",condition:"<="},(({z:s})=>{const n=nm(DE(u,t,e,s,o,a,h,r,i)).toVar();sm(n.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(n)})).elseif(n.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(n)})).elseif(n.lessThan(l.z),(()=>{l.z.assign(n)}))}))}))})),sm(i.equal(om(0)),(()=>{l.assign(Xf(l))})),l})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),$E=Kp((([t])=>{const e=pm(t).toVar(),s=nm(e.x).toVar(),i=nm(e.y).toVar(),r=nm(e.z).toVar();sm(i.lessThan(1e-4),(()=>pm(r,r,r))).else((()=>{s.assign(gf(6,s.sub(Jf(s))));const t=om(gy(s)).toVar(),e=nm(s.sub(nm(t))).toVar(),n=nm(r.mul(mf(1,i))).toVar(),o=nm(r.mul(mf(1,i.mul(e)))).toVar(),a=nm(r.mul(mf(1,i.mul(mf(1,e))))).toVar();return sm(t.equal(om(0)),(()=>pm(r,a,n))).elseif(t.equal(om(1)),(()=>pm(o,r,n))).elseif(t.equal(om(2)),(()=>pm(n,r,a))).elseif(t.equal(om(3)),(()=>pm(n,o,r))).elseif(t.equal(om(4)),(()=>pm(a,n,r))),pm(r,n,o)}))})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),XE=Kp((([t])=>{const e=pm(t).toVar(),s=nm(e.x).toVar(),i=nm(e.y).toVar(),r=nm(e.z).toVar(),n=nm(vy(s,vy(i,r))).toVar(),o=nm(Ty(s,Ty(i,r))).toVar(),a=nm(o.sub(n)).toVar(),h=nm().toVar(),u=nm().toVar(),l=nm().toVar();return l.assign(o),sm(o.greaterThan(0),(()=>{u.assign(a.div(o))})).else((()=>{u.assign(0)})),sm(u.lessThanEqual(0),(()=>{h.assign(0)})).else((()=>{sm(s.greaterThanEqual(o),(()=>{h.assign(i.sub(r).div(a))})).elseif(i.greaterThanEqual(o),(()=>{h.assign(pf(2,r.sub(s).div(a)))})).else((()=>{h.assign(pf(4,s.sub(i).div(a)))})),h.mulAssign(1/6),sm(h.lessThan(0),(()=>{h.addAssign(1)}))})),pm(h,u,l)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),YE=Kp((([t])=>{const e=pm(t).toVar(),s=fm(Tf(e,pm(.04045))).toVar(),i=pm(e.div(12.92)).toVar(),r=pm(Cy(Ty(e.add(pm(.055)),pm(0)).div(1.055),pm(2.4))).toVar();return Oy(i,r,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),JE=(t,e)=>{t=nm(t),e=nm(e);const s=um(e.dFdx(),e.dFdy()).length().mul(.7071067811865476);return Dy(t.sub(s),t.add(s),e)},ZE=(t,e,s,i)=>Oy(t,e,s[i].clamp()),QE=(t,e,s=uf())=>ZE(t,e,s,"x"),KE=(t,e,s=uf())=>ZE(t,e,s,"y"),tB=(t,e,s,i,r)=>Oy(t,e,JE(s,i[r])),eB=(t,e,s,i=uf())=>tB(t,e,s,i,"x"),sB=(t,e,s,i=uf())=>tB(t,e,s,i,"y"),iB=(t=1,e=0,s=uf())=>s.mul(t).add(e),rB=(t,e=1)=>(t=nm(t)).abs().pow(e).mul(t.sign()),nB=(t,e=1,s=.5)=>nm(t).sub(s).mul(e).add(s),oB=(t=uf(),e=1,s=0)=>BE(t.convert("vec2|vec3")).mul(e).add(s),aB=(t=uf(),e=1,s=0)=>IE(t.convert("vec2|vec3")).mul(e).add(s),hB=(t=uf(),e=1,s=0)=>{t=t.convert("vec2|vec3");return ym(IE(t),BE(t.add(um(19,73)))).mul(e).add(s)},uB=(t=uf(),e=1)=>jE(t.convert("vec2|vec3"),e,om(1)),lB=(t=uf(),e=1)=>HE(t.convert("vec2|vec3"),e,om(1)),cB=(t=uf(),e=1)=>qE(t.convert("vec2|vec3"),e,om(1)),dB=(t=uf())=>PE(t.convert("vec2|vec3")),pB=(t=uf(),e=3,s=2,i=.5,r=1)=>UE(t,om(e),s,i).mul(r),mB=(t=uf(),e=3,s=2,i=.5,r=1)=>zE(t,om(e),s,i).mul(r),gB=(t=uf(),e=3,s=2,i=.5,r=1)=>OE(t,om(e),s,i).mul(r),fB=(t=uf(),e=3,s=2,i=.5,r=1)=>LE(t,om(e),s,i).mul(r);function yB(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.material.id!==e.material.id?t.material.id-e.material.id:t.z!==e.z?t.z-e.z:t.id-e.id}function xB(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.z!==e.z?e.z-t.z:t.id-e.id}class bB{constructor(){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparent=[],this.bundles=[],this.lightsNode=new Ev([]),this.lightsArray=[],this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(t,e,s,i,r,n){let o=this.renderItems[this.renderItemsIndex];return void 0===o?(o={id:t.id,object:t,geometry:e,material:s,groupOrder:i,renderOrder:t.renderOrder,z:r,group:n},this.renderItems[this.renderItemsIndex]=o):(o.id=t.id,o.object=t,o.geometry=e,o.material=s,o.groupOrder=i,o.renderOrder=t.renderOrder,o.z=r,o.group=n),this.renderItemsIndex++,o}push(t,e,s,i,r,n){const o=this.getNextRenderItem(t,e,s,i,r,n);!0===t.occlusionTest&&this.occlusionQueryCount++,(!0===s.transparent||s.transmission>0?this.transparent:this.opaque).push(o)}unshift(t,e,s,i,r,n){const o=this.getNextRenderItem(t,e,s,i,r,n);(!0===s.transparent?this.transparent:this.opaque).unshift(o)}pushBundle(t){this.bundles.push(t)}pushLight(t){this.lightsArray.push(t)}getLightsNode(){return this.lightsNode.fromLights(this.lightsArray)}sort(t,e){this.opaque.length>1&&this.opaque.sort(t||yB),this.transparent.length>1&&this.transparent.sort(e||xB)}finish(){this.lightsNode.fromLights(this.lightsArray);for(let t=this.renderItemsIndex,e=this.renderItems.length;t>e,u=a.height>>e;let l=t.depthTexture||r[e],c=!1;void 0===l&&(l=new Ka,l.format=t.stencilBuffer?jt:Wt,l.type=t.stencilBuffer?Ot:Bt,l.image.width=h,l.image.height=u,r[e]=l),s.width===a.width&&a.height===s.height||(c=!0,l.needsUpdate=!0,l.image.width=h,l.image.height=u),s.width=a.width,s.height=a.height,s.textures=o,s.depthTexture=l,s.depth=t.depthBuffer,s.stencil=t.stencilBuffer,s.renderTarget=t,s.sampleCount!==i&&(c=!0,l.needsUpdate=!0,s.sampleCount=i);const d={sampleCount:i};for(let t=0;t{if(t.removeEventListener("dispose",e),void 0!==o)for(let t=0;t0){const i=t.image;if(void 0===i)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===i.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(t.images){const s=[];for(const e of t.images)s.push(e);e.images=s}else e.image=i;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(r.createTexture(t,e),s.isDefaultTexture=!1),!0===t.source.dataReady&&r.updateTexture(t,e),e.needsMipmaps&&0===t.mipmaps.length&&r.generateMipmaps(t)}}else r.createDefaultTexture(t),s.isDefaultTexture=!0}if(!0!==s.initialized){s.initialized=!0,this.info.memory.textures++;const e=()=>{t.removeEventListener("dispose",e),this._destroyTexture(t),this.info.memory.textures--};t.addEventListener("dispose",e)}s.version=t.version}getSize(t,e=SB){let s=t.images?t.images[0]:t.image;return s?(void 0!==s.image&&(s=s.image),e.width=s.width,e.height=s.height,e.depth=t.isCubeTexture?6:s.depth||1):e.width=e.height=e.depth=1,e}getMipLevels(t,e,s){let i;return i=t.isCompressedTexture?t.mipmaps.length:Math.floor(Math.log2(Math.max(e,s)))+1,i}needsMipmaps(t){return!!this.isEnvironmentTexture(t)||(!0===t.isCompressedTexture||t.minFilter!==ft&&t.minFilter!==Tt)}isEnvironmentTexture(t){const e=t.mapping;return e===lt||e===ct||e===ht||e===ut}_destroyTexture(t){this.backend.destroySampler(t),this.backend.destroyTexture(t),this.delete(t)}}class AB extends Yr{constructor(t,e,s,i=1){super(t,e,s),this.a=i}set(t,e,s,i=1){return this.a=i,super.set(t,e,s)}copy(t){return void 0!==t.a&&(this.a=t.a),super.copy(t)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}const NB=new AB;class RB extends Cd{constructor(t,e){super(),this.renderer=t,this.nodes=e}update(t,e,s){const i=this.renderer,r=this.nodes.getBackgroundNode(t)||t.background;let n=!1;if(null===r)i._clearColor.getRGB(NB,Ze),NB.a=i._clearColor.a;else if(!0===r.isColor)r.getRGB(NB,Ze),NB.a=1,n=!0;else if(!0===r.isNode){const s=this.get(t),n=r;NB.copy(i._clearColor);let o=s.backgroundMesh;if(void 0===o){const t=Ym(ym(n).mul(IS),{getUV:()=>Xx,getTextureLevel:()=>BS});let e=qb();e=e.setZ(e.w);const i=new gT;i.side=d,i.depthTest=!1,i.depthWrite=!1,i.fog=!1,i.lights=!1,i.vertexNode=e,i.colorNode=t,s.backgroundMeshNode=t,s.backgroundMesh=o=new Wn(new fu(1,32,32),i),o.frustumCulled=!1,o.onBeforeRender=function(t,e,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=n.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=ym(n).mul(IS),o.material.needsUpdate=!0,s.backgroundCacheKey=a),e.unshift(o,o.geometry,o.material,0,0,null)}else console.error("THREE.Renderer: Unsupported background configuration.",r);if(!0===i.autoClear||!0===n){NB.multiplyScalar(NB.a);const t=s.clearColorValue;t.r=NB.r,t.g=NB.g,t.b=NB.b,t.a=NB.a,s.depthClearValue=i._clearDepth,s.stencilClearValue=i._clearStencil,s.clearColor=!0===i.autoClearColor,s.clearDepth=!0===i.autoClearDepth,s.clearStencil=!0===i.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}class CB{constructor(t,e,s,i,r,n,o,a,h=!0,u=[]){this.vertexShader=t,this.fragmentShader=e,this.computeShader=s,this.transforms=u,this.nodeAttributes=i,this.bindings=r,this.updateNodes=n,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.instanceBindGroups=h,this.usedTimes=0}createBindings(){const t=[];for(const e of this.bindings){if(!0!==(this.instanceBindGroups&&e.bindings[0].groupNode.shared)){const s=new N_(e.name);t.push(s);for(const t of e.bindings)s.bindings.push(t.clone())}else t.push(e)}return t}}const EB=new WeakMap;class BB extends Cd{constructor(t,e){super(),this.renderer=t,this.backend=e,this.nodeFrame=new P_,this.nodeBuilderCache=new Map,this.callHashCache=new _d,this.groupsData=new _d}updateGroup(t){const e=t.groupNode,s=e.name;if(s===of.name)return!0;if(s===nf.name){const e=this.get(t),s=this.nodeFrame.renderId;return e.renderId!==s&&(e.renderId=s,!0)}if(s===rf.name){const e=this.get(t),s=this.nodeFrame.frameId;return e.frameId!==s&&(e.frameId=s,!0)}const i=[e,t];let r=this.groupsData.get(i);return void 0===r&&this.groupsData.set(i,r={}),r.version!==e.version&&(r.version=e.version,!0)}getForRenderCacheKey(t){return t.initialCacheKey}getForRender(t){const e=this.get(t);let s=e.nodeBuilderState;if(void 0===s){const{nodeBuilderCache:i}=this,r=this.getForRenderCacheKey(t);if(s=i.get(r),void 0===s){const e=this.backend.createNodeBuilder(t.object,this.renderer);e.scene=t.scene,e.material=t.material,e.camera=t.camera,e.context.material=t.material,e.lightsNode=t.lightsNode,e.environmentNode=this.getEnvironmentNode(t.scene),e.fogNode=this.getFogNode(t.scene),e.clippingContext=t.clippingContext,e.build(),s=this._createNodeBuilderState(e),i.set(r,s)}s.usedTimes++,e.nodeBuilderState=s}return s}delete(t){if(t.isRenderObject){const e=this.get(t).nodeBuilderState;e.usedTimes--,0===e.usedTimes&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(t))}return super.delete(t)}getForCompute(t){const e=this.get(t);let s=e.nodeBuilderState;if(void 0===s){const i=this.backend.createNodeBuilder(t,this.renderer);i.build(),s=this._createNodeBuilderState(i),e.nodeBuilderState=s}return s}_createNodeBuilderState(t){return new CB(t.vertexShader,t.fragmentShader,t.computeShader,t.getAttributesArray(),t.getBindings(),t.updateNodes,t.updateBeforeNodes,t.updateAfterNodes,t.instanceBindGroups,t.transforms)}getEnvironmentNode(t){return t.environmentNode||this.get(t).environmentNode||null}getBackgroundNode(t){return t.backgroundNode||this.get(t).backgroundNode||null}getFogNode(t){return t.fogNode||this.get(t).fogNode||null}getCacheKey(t,e){const s=[t,e],i=this.renderer.info.calls;let r=this.callHashCache.get(s);if(void 0===r||r.callId!==i){const n=this.getEnvironmentNode(t),o=this.getFogNode(t),a=[];e&&a.push(e.getCacheKey()),n&&a.push(n.getCacheKey()),o&&a.push(o.getCacheKey()),r={callId:i,cacheKey:a.join(",")},this.callHashCache.set(s,r)}return r.cacheKey}updateScene(t){this.updateEnvironment(t),this.updateFog(t),this.updateBackground(t)}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(t){const e=this.get(t),s=t.background;if(s){if(e.background!==s){let t=null;!0===s.isCubeTexture||s.mapping===lt||s.mapping===ct?t=TR(s,Xx):!0===s.isTexture?t=rx(s,Hv).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s),e.backgroundNode=t,e.background=s}}else e.backgroundNode&&(delete e.backgroundNode,delete e.background)}updateFog(t){const e=this.get(t),s=t.fog;if(s){if(e.fog!==s){let t=null;s.isFogExp2?t=ZN(mx("color","color",s),mx("density","float",s)):s.isFog?t=YN(mx("color","color",s),mx("near","float",s),mx("far","float",s)):console.error("WebGPUNodes: Unsupported fog configuration.",s),e.fogNode=t,e.fog=s}}else delete e.fogNode,delete e.fog}updateEnvironment(t){const e=this.get(t),s=t.environment;if(s){if(e.environment!==s){let t=null;!0===s.isCubeTexture?t=Mv(s):!0===s.isTexture?t=rx(s):console.error("Nodes: Unsupported environment configuration.",s),e.environmentNode=t,e.environment=s}}else e.environmentNode&&(delete e.environmentNode,delete e.environment)}getNodeFrame(t=this.renderer,e=null,s=null,i=null,r=null){const n=this.nodeFrame;return n.renderer=t,n.scene=e,n.object=s,n.camera=i,n.material=r,n}getNodeFrameForRender(t){return this.getNodeFrame(t.renderer,t.scene,t.object,t.camera,t.material)}getOutputCacheKey(){const t=this.renderer;return t.toneMapping+","+t.currentColorSpace}hasOutputChange(t){return EB.get(t)!==this.getOutputCacheKey()}getOutputNode(t){const e=this.renderer,s=this.getOutputCacheKey(),i=rx(t,jv).renderOutput(e.toneMapping,e.currentColorSpace);return EB.set(t,s),i}updateBefore(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateBeforeNodes)e.updateBeforeNode(t)}updateAfter(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateAfterNodes)e.updateAfterNode(t)}updateForCompute(t){const e=this.getNodeFrame(),s=this.getForCompute(t);for(const t of s.updateNodes)e.updateNode(t)}updateForRender(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateNodes)e.updateNode(t)}dispose(){super.dispose(),this.nodeFrame=new P_,this.nodeBuilderCache=new Map}}class IB{constructor(t,e){this.scene=t,this.camera=e}clone(){return Object.assign(new this.constructor,this)}}class PB{constructor(){this.lists=new _d}get(t,e){const s=this.lists,i=[t,e];let r=s.get(i);return void 0===r&&(r=new IB(t,e),s.set(i,r)),r}dispose(){this.lists=new _d}}const FB=new no,UB=new Ks,OB=new _i,zB=new na,LB=new or,VB=new Ei;class DB{constructor(t,e={}){this.isRenderer=!0;const{logarithmicDepthBuffer:s=!1,alpha:i=!0,antialias:r=!1,samples:n=0}=e;this.domElement=t.getDomElement(),this.backend=t,this.samples=n||!0===r?4:0,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=i,this.logarithmicDepthBuffer=s,this.outputColorSpace=Je,this.toneMapping=0,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=!0,this.stencil=!1,this.clippingPlanes=[],this.info=new Ld,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new _i(0,0,this._width,this._height),this._scissor=new _i(0,0,this._width,this._height),this._scissorTest=!1,this._attributes=null,this._geometries=null,this._nodes=null,this._animation=null,this._bindings=null,this._objects=null,this._pipelines=null,this._bundles=null,this._renderLists=null,this._renderContexts=null,this._textures=null,this._background=null,this._quad=new Zw(new gT),this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;const o=!0===this.alpha?0:1;this._clearColor=new AB(0,0,0,o),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._mrt=null,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._initialized=!1,this._initPromise=null,this._compilationPromises=null,this.shadowMap={enabled:!1,type:null},this.xr={enabled:!1},this.debug={checkShaderErrors:!0,onShaderError:null}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(t,e)=>{const s=this.backend;try{await s.init(this)}catch(t){return void e(t)}this._nodes=new BB(this,s),this._animation=new Td(this._nodes,this.info),this._attributes=new Fd(s),this._background=new RB(this,this._nodes),this._geometries=new zd(this._attributes,this.info),this._textures=new MB(this,s,this.info),this._pipelines=new jd(s,this._nodes),this._bindings=new Hd(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Rd(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new vB,this._bundles=new PB,this._renderContexts=new wB,this._initialized=!0,t()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(t,e,s=null){!1===this._initialized&&await this.init();const i=this._nodes.nodeFrame,r=i.renderId,n=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,h=!0===t.isScene?t:FB;null===s&&(s=t);const u=this._renderTarget,l=this._renderContexts.get(s,e,u),c=this._activeMipmapLevel,d=[];this._currentRenderContext=l,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=d,i.renderId++,i.update(),l.depth=this.depth,l.stencil=this.stencil,l.clippingContext||(l.clippingContext=new Md),l.clippingContext.updateGlobal(this,e),h.onBeforeRender(this,t,e,u);const p=this._renderLists.get(t,e);if(p.begin(),this._projectObject(t,e,0,p),s!==t&&s.traverseVisible((function(t){t.isLight&&t.layers.test(e.layers)&&p.pushLight(t)})),p.finish(),null!==u){this._textures.updateRenderTarget(u,c);const t=this._textures.get(u);l.textures=t.textures,l.depthTexture=t.depthTexture}else l.textures=null,l.depthTexture=null;this._nodes.updateScene(h),this._background.update(h,p,l);const m=p.opaque,g=p.transparent,f=p.lightsNode;m.length>0&&this._renderObjects(m,e,h,f),g.length>0&&this._renderObjects(g,e,h,f),i.renderId=r,this._currentRenderContext=n,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(d)}async renderAsync(t,e){!1===this._initialized&&await this.init();const s=this._renderScene(t,e);await this.backend.resolveTimestampAsync(s,"render")}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}_renderBundle(t,e,s){const{object:i,camera:r,renderList:n}=t,o=this._currentRenderContext,a=this.backend.get(o),h=this._bundles.get(i,r),u=this.backend.get(h);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=!1===u.renderContexts.has(o)||!0===i.needsUpdate;if(u.renderContexts.add(o),l){if(void 0===a.renderObjects||!0===i.needsUpdate){const t=this._nodes.nodeFrame;a.renderObjects=[],a.renderBundles=[],a.scene=e,a.camera=r,a.renderId=t.renderId,a.registerBundlesPhase=!0}this._currentRenderBundle=h;const t=n.opaque;t.length>0&&this._renderObjects(t,r,e,s),this._currentRenderBundle=null,i.needsUpdate=!1}else{const t=this._currentRenderContext,e=this.backend.get(t);for(let t=0,s=e.renderObjects.length;t>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=x,p.viewportValue.maxDepth=b,p.viewport=!1===p.viewportValue.equals(OB),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(OB),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new Md),p.clippingContext.updateGlobal(this,e),h.onBeforeRender(this,t,e,d),LB.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),zB.setFromProjectionMatrix(LB,m);const v=this._renderLists.get(t,e);if(v.begin(),this._projectObject(t,e,0,v),v.finish(),!0===this.sortObjects&&v.sort(this._opaqueSort,this._transparentSort),null!==d){this._textures.updateRenderTarget(d,c);const t=this._textures.get(d);p.textures=t.textures,p.depthTexture=t.depthTexture,p.width=t.width,p.height=t.height,p.renderTarget=d,p.depth=d.depthBuffer,p.stencil=d.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=l,p.activeMipmapLevel=c,p.occlusionQueryCount=v.occlusionQueryCount,this._nodes.updateScene(h),this._background.update(h,v,p),this.backend.beginRender(p);const T=v.opaque,_=v.transparent,w=v.bundles,S=v.lightsNode;if(w.length>0&&this._renderBundles(w,h,S),T.length>0&&this._renderObjects(T,e,h,S),_.length>0&&this._renderObjects(_,e,h,S),this.backend.finishRender(p),r.renderId=n,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==i){this.setRenderTarget(u,l,c);const t=this._quad;this._nodes.hasOutputChange(d.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(d.texture),t.material.needsUpdate=!0),this._renderScene(t,t.camera,!1)}return h.onAfterRender(this,t,e,d),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(t){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(t)}async getArrayBufferAsync(t){return await this.backend.getArrayBufferAsync(t)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(t){return t.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(t){return t.set(this._width,this._height)}setPixelRatio(t=1){this._pixelRatio=t,this.setSize(this._width,this._height,!1)}setDrawingBufferSize(t,e,s){this._width=t,this._height=e,this._pixelRatio=s,this.domElement.width=Math.floor(t*s),this.domElement.height=Math.floor(e*s),this.setViewport(0,0,t,e),this._initialized&&this.backend.updateSize()}setSize(t,e,s=!0){this._width=t,this._height=e,this.domElement.width=Math.floor(t*this._pixelRatio),this.domElement.height=Math.floor(e*this._pixelRatio),!0===s&&(this.domElement.style.width=t+"px",this.domElement.style.height=e+"px"),this.setViewport(0,0,t,e),this._initialized&&this.backend.updateSize()}setOpaqueSort(t){this._opaqueSort=t}setTransparentSort(t){this._transparentSort=t}getScissor(t){const e=this._scissor;return t.x=e.x,t.y=e.y,t.width=e.width,t.height=e.height,t}setScissor(t,e,s,i){const r=this._scissor;t.isVector4?r.copy(t):r.set(t,e,s,i)}getScissorTest(){return this._scissorTest}setScissorTest(t){this._scissorTest=t,this.backend.setScissorTest(t)}getViewport(t){return t.copy(this._viewport)}setViewport(t,e,s,i,r=0,n=1){const o=this._viewport;t.isVector4?o.copy(t):o.set(t,e,s,i),o.minDepth=r,o.maxDepth=n}getClearColor(t){return t.copy(this._clearColor)}setClearColor(t,e=1){this._clearColor.set(t),this._clearColor.a=e}getClearAlpha(){return this._clearColor.a}setClearAlpha(t){this._clearColor.a=t}getClearDepth(){return this._clearDepth}setClearDepth(t){this._clearDepth=t}getClearStencil(){return this._clearStencil}setClearStencil(t){this._clearStencil=t}isOccluded(t){const e=this._currentRenderContext;return e&&this.backend.isOccluded(e,t)}clear(t=!0,e=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(t,e,s);const i=this._renderTarget||this._getFrameBufferTarget();let r=null;if(null!==i&&(this._textures.updateRenderTarget(i),r=this._textures.get(i)),this.backend.clear(t,e,s,r),null!==i&&null===this._renderTarget){const t=this._quad;this._nodes.hasOutputChange(i.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(i.texture),t.material.needsUpdate=!0),this._renderScene(t,t.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(t=!0,e=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(t,e,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentColorSpace(){const t=this._renderTarget;if(null!==t){const e=t.texture;return(Array.isArray(e)?e[0]:e).colorSpace}return this.outputColorSpace}dispose(){this.info.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(t,e=0,s=0){this._renderTarget=t,this._activeCubeFace=e,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(t){this._renderObjectFunction=t}getRenderObjectFunction(){return this._renderObjectFunction}async computeAsync(t){!1===this._initialized&&await this.init();const e=this._nodes.nodeFrame,s=e.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,e.renderId=this.info.calls;const i=this.backend,r=this._pipelines,n=this._bindings,o=this._nodes,a=Array.isArray(t)?t:[t];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");i.beginCompute(t);for(const e of a){if(!1===r.has(e)){const t=()=>{e.removeEventListener("dispose",t),r.delete(e),n.delete(e),o.delete(e)};e.addEventListener("dispose",t),e.onInit({renderer:this})}o.updateForCompute(e),n.updateForCompute(e);const s=n.getForCompute(e),a=r.getForCompute(e,s);i.compute(t,e,s,a)}i.finishCompute(t),await this.backend.resolveTimestampAsync(t,"compute"),e.renderId=s}async hasFeatureAsync(t){return!1===this._initialized&&await this.init(),this.backend.hasFeature(t)}hasFeature(t){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(t)}copyFramebufferToTexture(t){const e=this._currentRenderContext;this._textures.updateTexture(t),this.backend.copyFramebufferToTexture(t,e)}copyTextureToTexture(t,e,s=null,i=null,r=0){this._textures.updateTexture(t),this._textures.updateTexture(e),this.backend.copyTextureToTexture(t,e,s,i,r)}readRenderTargetPixelsAsync(t,e,s,i,r,n=0){return this.backend.copyTextureToBuffer(t.textures[n],e,s,i,r)}_projectObject(t,e,s,i){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)s=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)i.pushLight(t);else if(t.isSprite){if(!t.frustumCulled||zB.intersectsSprite(t)){!0===this.sortObjects&&VB.setFromMatrixPosition(t.matrixWorld).applyMatrix4(LB);const e=t.geometry,r=t.material;r.visible&&i.push(t,e,r,s,VB.z,null)}}else if(t.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((t.isMesh||t.isLine||t.isPoints)&&(!t.frustumCulled||zB.intersectsObject(t))){const e=t.geometry,r=t.material;if(!0===this.sortObjects&&(null===e.boundingSphere&&e.computeBoundingSphere(),VB.copy(e.boundingSphere.center).applyMatrix4(t.matrixWorld).applyMatrix4(LB)),Array.isArray(r)){const n=e.groups;for(let o=0,a=n.length;o0?i:"";e=`${t.name} {\n\t${s} ${r.name}[${n}];\n};\n`}else{e=`${this.getVectorType(r.type)} ${this.getPropertyName(r,t)};`,n=!0}const o=r.node.precision;if(null!==o&&(e=eI[o]+" "+e),n){e="\t"+e;const t=r.groupNode.name;(i[t]||(i[t]=[])).push(e)}else e="uniform "+e,s.push(e)}let r="";for(const e in i){const s=i[e];r+=this._getGLSLUniformStruct(t+"_"+e,s.join("\n"))+"\n"}return r+=s.join("\n"),r}getTypeFromAttribute(t){let e=super.getTypeFromAttribute(t);if(/^[iu]/.test(e)&&t.gpuType!==Et){let s=t;t.isInterleavedBufferAttribute&&(s=t.data);const i=s.array;!1==(i instanceof Uint32Array||i instanceof Int32Array||i instanceof Uint16Array||i instanceof Int16Array)&&(e=e.slice(1))}return e}getAttributes(t){let e="";if("vertex"===t||"compute"===t){const t=this.getAttributesArray();let s=0;for(const i of t)e+=`layout( location = ${s++} ) in ${i.type} ${i.name};\n`}return e}getStructMembers(t){const e=[],s=t.getMemberTypes();for(let t=0;t0&&(s+="\n"),s+=`\t// flow -> ${n}\n\t`),s+=`${i.code}\n\t`,t===r&&"compute"!==e&&(s+="// result\n\t","vertex"===e?(s+="gl_Position = ",s+=`${i.result};`):"fragment"===e&&(t.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${i.result};`)))}const n=t[e];n.extensions=this.getExtensions(e),n.uniforms=this.getUniforms(e),n.attributes=this.getAttributes(e),n.varyings=this.getVaryings(e),n.vars=this.getVars(e),n.structs=this.getStructs(e),n.codes=this.getCodes(e),n.transforms=this.getTransforms(e),n.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(t.vertex),this.fragmentShader=this._getGLSLFragmentCode(t.fragment)):this.computeShader=this._getGLSLVertexCode(t.compute)}getUniformFromNode(t,e,s,i=null){const r=super.getUniformFromNode(t,e,s,i),n=this.getDataFromNode(t,s,this.globalCache);let o=n.uniformGPU;if(void 0===o){const i=t.groupNode,a=i.name,h=this.getBindGroupArray(a,s);if("texture"===e)o=new ZB(r.name,r.node,i),h.push(o);else if("cubeTexture"===e)o=new QB(r.name,r.node,i),h.push(o);else if("texture3D"===e)o=new KB(r.name,r.node,i),h.push(o);else if("buffer"===e){t.name=`NodeBuffer_${t.id}`,r.name=`buffer${t.id}`;const e=new HB(t,i);e.name=t.name,h.push(e),o=e}else{const t=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=t[a];void 0===n&&(n=new XB(s+"_"+a,i),t[a]=n,h.push(n)),o=this.getNodeUniform(r,e),n.addUniform(o)}n.uniformGPU=o}return r}}let nI=null,oI=null,aI=null;class hI{constructor(t={}){this.parameters=Object.assign({},t),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(t){this.renderer=t}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(t){const{object:e,geometry:s}=t;return s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1}getDrawingBufferSize(){return nI=nI||new Ks,this.renderer.getDrawingBufferSize(nI)}getScissor(){return oI=oI||new _i,this.renderer.getScissor(oI)}setScissorTest(){}getClearColor(){const t=this.renderer;return aI=aI||new AB,t.getClearColor(aI),aI.getRGB(aI,this.renderer.currentColorSpace),aI}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:ni(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${t} webgpu`),this.domElement=e),e}set(t,e){this.data.set(t,e)}get(t){let e=this.data.get(t);return void 0===e&&(e={},this.data.set(t,e)),e}has(t){return this.data.has(t)}delete(t){this.data.delete(t)}}let uI=0;class lI{constructor(t,e){this.buffers=[t.bufferGPU,e],this.type=t.type,this.bufferType=t.bufferType,this.pbo=t.pbo,this.byteLength=t.byteLength,this.bytesPerElement=t.BYTES_PER_ELEMENT,this.version=t.version,this.isInteger=t.isInteger,this.activeBufferIndex=0,this.baseId=t.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class cI{constructor(t){this.backend=t}createAttribute(t,e){const s=this.backend,{gl:i}=s,r=t.array,n=t.usage||i.STATIC_DRAW,o=t.isInterleavedBufferAttribute?t.data:t,a=s.get(o);let h,u=a.bufferGPU;if(void 0===u&&(u=this._createBuffer(i,e,r,n),a.bufferGPU=u,a.bufferType=e,a.version=o.version),r instanceof Float32Array)h=i.FLOAT;else if(r instanceof Uint16Array)h=t.isFloat16BufferAttribute?i.HALF_FLOAT:i.UNSIGNED_SHORT;else if(r instanceof Int16Array)h=i.SHORT;else if(r instanceof Uint32Array)h=i.UNSIGNED_INT;else if(r instanceof Int32Array)h=i.INT;else if(r instanceof Int8Array)h=i.BYTE;else if(r instanceof Uint8Array)h=i.UNSIGNED_BYTE;else{if(!(r instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+r);h=i.UNSIGNED_BYTE}let l={bufferGPU:u,bufferType:e,type:h,byteLength:r.byteLength,bytesPerElement:r.BYTES_PER_ELEMENT,version:t.version,pbo:t.pbo,isInteger:h===i.INT||h===i.UNSIGNED_INT||h===i.UNSIGNED_SHORT||t.gpuType===Et,id:uI++};if(t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute){const t=this._createBuffer(i,e,r,n);l=new lI(l,t)}s.set(t,l)}updateAttribute(t){const e=this.backend,{gl:s}=e,i=t.array,r=t.isInterleavedBufferAttribute?t.data:t,n=e.get(r),o=n.bufferType,a=t.isInterleavedBufferAttribute?t.data.updateRanges:t.updateRanges;if(s.bindBuffer(o,n.bufferGPU),0===a.length)s.bufferSubData(o,0,i);else{for(let t=0,e=a.length;t{!function r(){const n=t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0);if(n===t.WAIT_FAILED)return t.deleteSync(e),void i();n!==t.TIMEOUT_EXPIRED?(t.deleteSync(e),s()):requestAnimationFrame(r)}()}))}}let yI,xI,bI,vI=!1;class TI{constructor(t){this.backend=t,this.gl=t.gl,this.extensions=t.extensions,this.defaultTextures={},!1===vI&&(this._init(this.gl),vI=!0)}_init(t){yI={[pt]:t.REPEAT,[mt]:t.CLAMP_TO_EDGE,[gt]:t.MIRRORED_REPEAT},xI={[ft]:t.NEAREST,[yt]:t.NEAREST_MIPMAP_NEAREST,[bt]:t.NEAREST_MIPMAP_LINEAR,[Tt]:t.LINEAR,[_t]:t.LINEAR_MIPMAP_NEAREST,[St]:t.LINEAR_MIPMAP_LINEAR},bI={512:t.NEVER,519:t.ALWAYS,[Ts]:t.LESS,515:t.LEQUAL,514:t.EQUAL,518:t.GEQUAL,516:t.GREATER,517:t.NOTEQUAL}}filterFallback(t){const{gl:e}=this;return t===ft||t===yt||t===bt?e.NEAREST:e.LINEAR}getGLTextureType(t){const{gl:e}=this;let s;return s=!0===t.isCubeTexture?e.TEXTURE_CUBE_MAP:!0===t.isDataArrayTexture?e.TEXTURE_2D_ARRAY:!0===t.isData3DTexture?e.TEXTURE_3D:e.TEXTURE_2D,s}getInternalFormat(t,e,s,i,r=!1){const{gl:n,extensions:o}=this;if(null!==t){if(void 0!==n[t])return n[t];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+t+"'")}let a=e;return e===n.RED&&(s===n.FLOAT&&(a=n.R32F),s===n.HALF_FLOAT&&(a=n.R16F),s===n.UNSIGNED_BYTE&&(a=n.R8),s===n.UNSIGNED_SHORT&&(a=n.R16),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),e===n.RED_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.R8UI),s===n.UNSIGNED_SHORT&&(a=n.R16UI),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),e===n.RG&&(s===n.FLOAT&&(a=n.RG32F),s===n.HALF_FLOAT&&(a=n.RG16F),s===n.UNSIGNED_BYTE&&(a=n.RG8),s===n.UNSIGNED_SHORT&&(a=n.RG16),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),e===n.RG_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RG8UI),s===n.UNSIGNED_SHORT&&(a=n.RG16UI),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),e===n.RGB&&(s===n.FLOAT&&(a=n.RGB32F),s===n.HALF_FLOAT&&(a=n.RGB16F),s===n.UNSIGNED_BYTE&&(a=n.RGB8),s===n.UNSIGNED_SHORT&&(a=n.RGB16),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I),s===n.UNSIGNED_BYTE&&(a=i===Je&&!1===r?n.SRGB8:n.RGB8),s===n.UNSIGNED_SHORT_5_6_5&&(a=n.RGB565),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGB4),s===n.UNSIGNED_INT_5_9_9_9_REV&&(a=n.RGB9_E5)),e===n.RGB_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGB8UI),s===n.UNSIGNED_SHORT&&(a=n.RGB16UI),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I)),e===n.RGBA&&(s===n.FLOAT&&(a=n.RGBA32F),s===n.HALF_FLOAT&&(a=n.RGBA16F),s===n.UNSIGNED_BYTE&&(a=n.RGBA8),s===n.UNSIGNED_SHORT&&(a=n.RGBA16),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I),s===n.UNSIGNED_BYTE&&(a=i===Je&&!1===r?n.SRGB8_ALPHA8:n.RGBA8),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGBA4),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1)),e===n.RGBA_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGBA8UI),s===n.UNSIGNED_SHORT&&(a=n.RGBA16UI),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I)),e===n.DEPTH_COMPONENT&&(s===n.UNSIGNED_INT&&(a=n.DEPTH24_STENCIL8),s===n.FLOAT&&(a=n.DEPTH_COMPONENT32F)),e===n.DEPTH_STENCIL&&s===n.UNSIGNED_INT_24_8&&(a=n.DEPTH24_STENCIL8),a!==n.R16F&&a!==n.R32F&&a!==n.RG16F&&a!==n.RG32F&&a!==n.RGBA16F&&a!==n.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(t,e){const{gl:s,extensions:i,backend:r}=this,{currentAnisotropy:n}=r.get(e);s.texParameteri(t,s.TEXTURE_WRAP_S,yI[e.wrapS]),s.texParameteri(t,s.TEXTURE_WRAP_T,yI[e.wrapT]),t!==s.TEXTURE_3D&&t!==s.TEXTURE_2D_ARRAY||s.texParameteri(t,s.TEXTURE_WRAP_R,yI[e.wrapR]),s.texParameteri(t,s.TEXTURE_MAG_FILTER,xI[e.magFilter]);const o=e.isVideoTexture||e.minFilter!==Tt?e.minFilter:St;if(s.texParameteri(t,s.TEXTURE_MIN_FILTER,xI[o]),e.compareFunction&&(s.texParameteri(t,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(t,s.TEXTURE_COMPARE_FUNC,bI[e.compareFunction])),!0===i.has("EXT_texture_filter_anisotropic")){if(e.magFilter===ft)return;if(e.minFilter!==bt&&e.minFilter!==St)return;if(e.type===It&&!1===i.has("OES_texture_float_linear"))return;if(e.anisotropy>1||n!==e.anisotropy){const n=i.get("EXT_texture_filter_anisotropic");s.texParameterf(t,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(e.anisotropy,r.getMaxAnisotropy())),r.get(e).currentAnisotropy=e.anisotropy}}}createDefaultTexture(t){const{gl:e,backend:s,defaultTextures:i}=this,r=this.getGLTextureType(t);let n=i[r];void 0===n&&(n=e.createTexture(),s.state.bindTexture(r,n),e.texParameteri(r,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(r,e.TEXTURE_MAG_FILTER,e.NEAREST),i[r]=n),s.set(t,{textureGPU:n,glTextureType:r,isDefault:!0})}createTexture(t,e){const{gl:s,backend:i}=this,{levels:r,width:n,height:o,depth:a}=e,h=i.utils.convert(t.format,t.colorSpace),u=i.utils.convert(t.type),l=this.getInternalFormat(t.internalFormat,h,u,t.colorSpace,t.isVideoTexture),c=s.createTexture(),d=this.getGLTextureType(t);i.state.bindTexture(d,c),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),this.setTextureParameters(d,t),t.isDataArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,r,l,n,o,a):t.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,r,l,n,o,a):t.isVideoTexture||s.texStorage2D(d,r,l,n,o),i.set(t,{textureGPU:c,glTextureType:d,glFormat:h,glType:u,glInternalFormat:l})}copyBufferToTexture(t,e){const{gl:s,backend:i}=this,{textureGPU:r,glTextureType:n,glFormat:o,glType:a}=i.get(e),{width:h,height:u}=e.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,t),i.state.bindTexture(n,r),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(n,0,0,0,h,u,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(t,e){const{gl:s}=this,{width:i,height:r}=e,{textureGPU:n,glTextureType:o,glFormat:a,glType:h,glInternalFormat:u}=this.backend.get(t);if(t.isRenderTargetTexture||void 0===n)return;const l=t=>t.isDataTexture?t.image.data:t instanceof ImageBitmap||t instanceof OffscreenCanvas||t instanceof HTMLImageElement||t instanceof HTMLCanvasElement?t:t.data;if(this.backend.state.bindTexture(o,n),t.isCompressedTexture){const i=t.mipmaps;for(let r=0;r0){let a,h;!0===t.isDepthTexture?(a=s.DEPTH_BUFFER_BIT,h=s.DEPTH_ATTACHMENT,e.stencil&&(a|=s.STENCIL_BUFFER_BIT)):(a=s.COLOR_BUFFER_BIT,h=s.COLOR_ATTACHMENT0);const u=s.createFramebuffer();i.bindFramebuffer(s.DRAW_FRAMEBUFFER,u),s.framebufferTexture2D(s.DRAW_FRAMEBUFFER,h,s.TEXTURE_2D,r,0),s.blitFramebuffer(0,0,n,o,0,0,n,o,a,s.NEAREST),s.deleteFramebuffer(u)}else i.bindTexture(s.TEXTURE_2D,r),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,0,0,n,o),i.unbindTexture();t.generateMipmaps&&this.generateMipmaps(t),this.backend._setFramebuffer(e)}setupRenderBufferStorage(t,e){const{gl:s}=this,i=e.renderTarget,{samples:r,depthTexture:n,depthBuffer:o,stencilBuffer:a,width:h,height:u}=i;if(s.bindRenderbuffer(s.RENDERBUFFER,t),o&&!a){let e=s.DEPTH_COMPONENT24;r>0?(n&&n.isDepthTexture&&n.type===s.FLOAT&&(e=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,r,e,h,u)):s.renderbufferStorage(s.RENDERBUFFER,e,h,u),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,t)}else o&&a&&(r>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,r,s.DEPTH24_STENCIL8,h,u):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,h,u),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,t))}async copyTextureToBuffer(t,e,s,i,r){const{backend:n,gl:o}=this,{textureGPU:a,glFormat:h,glType:u}=this.backend.get(t),l=o.createFramebuffer();o.bindFramebuffer(o.READ_FRAMEBUFFER,l),o.framebufferTexture2D(o.READ_FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,a,0);const c=this._getTypedArrayType(u),d=i*r*this._getBytesPerTexel(h),p=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,p),o.bufferData(o.PIXEL_PACK_BUFFER,d,o.STREAM_READ),o.readPixels(e,s,i,r,h,u,0),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),await n.utils._clientWaitAsync();const m=new c(d/c.BYTES_PER_ELEMENT);return o.bindBuffer(o.PIXEL_PACK_BUFFER,p),o.getBufferSubData(o.PIXEL_PACK_BUFFER,0,m),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),o.deleteFramebuffer(l),m}_getTypedArrayType(t){const{gl:e}=this;if(t===e.UNSIGNED_BYTE)return Uint8Array;if(t===e.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(t===e.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(t===e.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(t===e.UNSIGNED_SHORT)return Uint16Array;if(t===e.UNSIGNED_INT)return Uint32Array;if(t===e.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${t}`)}_getBytesPerTexel(t){const{gl:e}=this;return t===e.RGBA?4:t===e.RGB?3:t===e.ALPHA?1:void 0}}class _I{constructor(t){this.backend=t,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(t){let e=this.extensions[t];return void 0===e&&(e=this.gl.getExtension(t),this.extensions[t]=e),e}has(t){return this.availableExtensions.includes(t)}}class wI{constructor(t){this.backend=t,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const t=this.backend.gl,e=this.backend.extensions;if(!0===e.has("EXT_texture_filter_anisotropic")){const s=e.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=t.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const SI={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class MI{constructor(t){this.gl=t.gl,this.extensions=t.extensions,this.info=t.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(t,e){const{gl:s,mode:i,object:r,type:n,info:o,index:a}=this;0!==a?s.drawElements(i,e,n,t):s.drawArrays(i,t,e),o.update(r,e,i,1)}renderInstances(t,e,s){const{gl:i,mode:r,type:n,index:o,object:a,info:h}=this;0!==s&&(0!==o?i.drawElementsInstanced(r,e,n,t,s):i.drawArraysInstanced(r,t,e,s),h.update(a,e,r,s))}renderMultiDraw(t,e,s){const{extensions:i,mode:r,object:n,info:o}=this;if(0===s)return;const a=i.get("WEBGL_multi_draw");if(null===a)for(let i=0;i0)){const t=e.queryQueue.shift();this.initTimestampQuery(t)}}async resolveTimestampAsync(t,e="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(t);s.gpuQueries||(s.gpuQueries=[]);for(let t=0;t0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(i),s.occlusionQueryObjects=new Array(i),s.occlusionQueryIndex=0)}finishRender(t){const{gl:e,state:s}=this,i=this.get(t).previousContext,r=t.textures;if(null!==r)for(let t=0;t0){const r=i.msaaFrameBuffer,a=t.textures;s.bindFramebuffer(e.READ_FRAMEBUFFER,r),s.bindFramebuffer(e.DRAW_FRAMEBUFFER,n);for(let s=0;s0){if(n>this.get(t).occlusionQueryIndex){const{gl:t}=this;t.endQuery(t.ANY_SAMPLES_PASSED)}this.resolveOccludedAsync(t)}this.prepareTimestampBuffer(t)}resolveOccludedAsync(t){const e=this.get(t),{currentOcclusionQueries:s,currentOcclusionQueryObjects:i}=e;if(s&&i){const t=new WeakSet,{gl:r}=this;e.currentOcclusionQueryObjects=null,e.currentOcclusionQueries=null;const n=()=>{let o=0;for(let e=0;e0&&t.add(i[e]),s[e]=null,r.deleteQuery(n),o++))}o1?f.renderInstances(m,y,x):f.render(m,y),o.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(t){return t.id}createDefaultTexture(t){this.textureUtils.createDefaultTexture(t)}createTexture(t,e){this.textureUtils.createTexture(t,e)}updateTexture(t,e){this.textureUtils.updateTexture(t,e)}generateMipmaps(t){this.textureUtils.generateMipmaps(t)}destroyTexture(t){this.textureUtils.destroyTexture(t)}copyTextureToBuffer(t,e,s,i,r){return this.textureUtils.copyTextureToBuffer(t,e,s,i,r)}createSampler(){}destroySampler(){}createNodeBuilder(t,e){return new rI(t,e)}createProgram(t){const e=this.gl,{stage:s,code:i}=t,r="fragment"===s?e.createShader(e.FRAGMENT_SHADER):e.createShader(e.VERTEX_SHADER);e.shaderSource(r,i),e.compileShader(r),this.set(t,{shaderGPU:r})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(t,e){const s=this.gl,i=t.pipeline,{fragmentProgram:r,vertexProgram:n}=i,o=s.createProgram(),a=this.get(r).shaderGPU,h=this.get(n).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,h),s.linkProgram(o),this.set(i,{programGPU:o,fragmentShader:a,vertexShader:h}),null!==e&&this.parallel){const r=new Promise((e=>{const r=this.parallel,n=()=>{s.getProgramParameter(o,r.COMPLETION_STATUS_KHR)?(this._completeCompile(t,i),e()):requestAnimationFrame(n)};n()}));e.push(r)}else this._completeCompile(t,i)}_handleSource(t,e){const s=t.split("\n"),i=[],r=Math.max(e-6,0),n=Math.min(e+6,s.length);for(let t=r;t":" "} ${r}: ${s[t]}`)}return i.join("\n")}_getShaderErrors(t,e,s){const i=t.getShaderParameter(e,t.COMPILE_STATUS),r=t.getShaderInfoLog(e).trim();if(i&&""===r)return"";const n=/ERROR: 0:(\d+)/.exec(r);if(n){const i=parseInt(n[1]);return s.toUpperCase()+"\n\n"+r+"\n\n"+this._handleSource(t.getShaderSource(e),i)}return r}_logProgramError(t,e,s){if(this.renderer.debug.checkShaderErrors){const i=this.gl,r=i.getProgramInfoLog(t).trim();if(!1===i.getProgramParameter(t,i.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(i,t,s,e);else{const n=this._getShaderErrors(i,s,"vertex"),o=this._getShaderErrors(i,e,"fragment");console.error("THREE.WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(t,i.VALIDATE_STATUS)+"\n\nProgram Info Log: "+r+"\n"+n+"\n"+o)}else""!==r&&console.warn("THREE.WebGLProgram: Program Info Log:",r)}}_completeCompile(t,e){const s=this.gl,i=this.get(e),{programGPU:r,fragmentShader:n,vertexShader:o}=i;!1===s.getProgramParameter(r,s.LINK_STATUS)&&this._logProgramError(r,n,o),s.useProgram(r);const a=t.getBindings();this._setupBindings(a,r),this.set(e,{programGPU:r})}createComputePipeline(t,e){const s=this.gl,i={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(i);const{computeProgram:r}=t,n=s.createProgram(),o=this.get(i).shaderGPU,a=this.get(r).shaderGPU,h=r.transforms,u=[],l=[];for(let t=0;tSI[e]===t)),s=this.extensions;for(let t=0;t0){if(void 0===d){const i=[];d=e.createFramebuffer(),s.bindFramebuffer(e.FRAMEBUFFER,d);const r=[],u=t.textures;for(let s=0;s,\n\t@location( 0 ) vTex : vec2\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2, 4 >(\n\t\tvec2( -1.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 ),\n\t\tvec2( -1.0, -1.0 ),\n\t\tvec2( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2, 4 >(\n\t\tvec2( 0.0, 0.0 ),\n\t\tvec2( 1.0, 0.0 ),\n\t\tvec2( 0.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=t.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=t.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(t){let e=this.transferPipelines[t];return void 0===e&&(e=this.device.createRenderPipeline({vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:zS,stripIndexFormat:tM},layout:"auto"}),this.transferPipelines[t]=e),e}getFlipYPipeline(t){let e=this.flipYPipelines[t];return void 0===e&&(e=this.device.createRenderPipeline({vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:zS,stripIndexFormat:tM},layout:"auto"}),this.flipYPipelines[t]=e),e}flipY(t,e,s=0){const i=e.format,{width:r,height:n}=e.size,o=this.getTransferPipeline(i),a=this.getFlipYPipeline(i),h=this.device.createTexture({size:{width:r,height:n,depthOrArrayLayers:1},format:i,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),u=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:HM,baseArrayLayer:s}),l=h.createView({baseMipLevel:0,mipLevelCount:1,dimension:HM,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),d=(t,e,s)=>{const i=t.getBindGroupLayout(0),r=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:e}]}),n=c.beginRenderPass({colorAttachments:[{view:s,loadOp:XS,storeOp:qS,clearValue:[0,0,0,0]}]});n.setPipeline(t),n.setBindGroup(0,r),n.draw(4,1,0,0),n.end()};d(o,u,l),d(a,l,u),this.device.queue.submit([c.finish()]),h.destroy()}generateMipmaps(t,e,s=0){const i=this.getTransferPipeline(e.format),r=this.device.createCommandEncoder({}),n=i.getBindGroupLayout(0);let o=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:HM,baseArrayLayer:s});for(let a=1;a1&&!t.isMultisampleRenderTargetTexture){const t=Object.assign({},p);t.label=t.label+"-msaa",t.sampleCount=l,i.msaaTexture=s.device.createTexture(t)}i.initialized=!0,i.textureDescriptorGPU=p}destroyTexture(t){const e=this.backend,s=e.get(t);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),e.delete(t)}destroySampler(t){delete this.backend.get(t).sampler}generateMipmaps(t){const e=this.backend.get(t);if(t.isCubeTexture)for(let t=0;t<6;t++)this._generateMipmaps(e.texture,e.textureDescriptorGPU,t);else this._generateMipmaps(e.texture,e.textureDescriptorGPU)}getColorBuffer(){this.colorBuffer&&this.colorBuffer.destroy();const t=this.backend,{width:e,height:s}=t.getDrawingBufferSize();return this.colorBuffer=t.device.createTexture({label:"colorBuffer",size:{width:e,height:s,depthOrArrayLayers:1},sampleCount:t.utils.getSampleCount(t.renderer.samples),format:eM.BGRA8Unorm,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),this.colorBuffer}getDepthBuffer(t=!0,e=!1){const s=this.backend,{width:i,height:r}=s.getDrawingBufferSize(),n=this.depthTexture,o=s.get(n).texture;let a,h;if(e?(a=jt,h=Ot):t&&(a=Wt,h=Bt),void 0!==o){if(n.image.width===i&&n.image.height===r&&n.format===a&&n.type===h)return o;this.destroyTexture(n)}return n.name="depthBuffer",n.format=a,n.type=h,n.image.width=i,n.image.height=r,this.createTexture(n,{sampleCount:s.utils.getSampleCount(s.renderer.samples),width:i,height:r}),s.get(n).texture}updateTexture(t,e){const s=this.backend.get(t),{textureDescriptorGPU:i}=s;if(!t.isRenderTargetTexture&&void 0!==i){if(t.isDataTexture)this._copyBufferToTexture(e.image,s.texture,i,0,t.flipY);else if(t.isDataArrayTexture||t.isData3DTexture)for(let r=0;r]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,LI=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,VI={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_2d:"texture",texture_cube:"cubeTexture",texture_depth_2d:"depthTexture",texture_storage_2d:"storageTexture",texture_3d:"texture3D"};class DI extends sE{constructor(t){const{type:e,inputs:s,name:i,inputsCode:r,blockCode:n,outputType:o}=(t=>{const e=(t=t.trim()).match(zI);if(null!==e&&4===e.length){const s=e[2],i=[];let r=null;for(;null!==(r=LI.exec(s));)i.push({name:r[1],type:r[2]});const n=[];for(let t=0;t "+this.outputType:"";return`fn ${t} ( ${this.inputsCode.trim()} ) ${e}`+this.blockCode}}class kI extends eE{parseFunction(t){return new DI(t)}}const GI=self.GPUShaderStage,WI={vertex:GI?GI.VERTEX:1,fragment:GI?GI.FRAGMENT:2,compute:GI?GI.COMPUTE:4},jI={instance:!0,swizzleAssign:!1,storageBuffer:!0},HI={"^^":"threejs_xor"},qI={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",imat2:"mat2x2",umat2:"mat2x2",bmat2:"mat2x2",mat3:"mat3x3",imat3:"mat3x3",umat3:"mat3x3",bmat3:"mat3x3",mat4:"mat4x4",imat4:"mat4x4",umat4:"mat4x4",bmat4:"mat4x4"},$I={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"threejs_mod_float",mod_vec2:"threejs_mod_vec2",mod_vec3:"threejs_mod_vec3",mod_vec4:"threejs_mod_vec4",equals_bool:"threejs_equals_bool",equals_bvec2:"threejs_equals_bvec2",equals_bvec3:"threejs_equals_bvec3",equals_bvec4:"threejs_equals_bvec4",lessThanEqual:"threejs_lessThanEqual",greaterThan:"threejs_greaterThan",inversesqrt:"inverseSqrt",bitcast:"bitcast"},XI={threejs_xor:new Hg("\nfn threejs_xor( a : bool, b : bool ) -> bool {\n\n\treturn ( a || b ) && !( a && b );\n\n}\n"),lessThanEqual:new Hg("\nfn threejs_lessThanEqual( a : vec3, b : vec3 ) -> vec3 {\n\n\treturn vec3( a.x <= b.x, a.y <= b.y, a.z <= b.z );\n\n}\n"),greaterThan:new Hg("\nfn threejs_greaterThan( a : vec3, b : vec3 ) -> vec3 {\n\n\treturn vec3( a.x > b.x, a.y > b.y, a.z > b.z );\n\n}\n"),mod_float:new Hg("fn threejs_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new Hg("fn threejs_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new Hg("fn threejs_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new Hg("fn threejs_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new Hg("fn threejs_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new Hg("fn threejs_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new Hg("fn threejs_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new Hg("fn threejs_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping:new Hg("\nfn threejs_repeatWrapping( uv : vec2, dimension : vec2 ) -> vec2 {\n\n\tlet uvScaled = vec2( uv * vec2( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new Hg("\nfn threejs_biquadraticTexture( map : texture_2d, coord : vec2f, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( textureDimensions( map, level ) );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2i( iuv + vec2( 0.5, 0.5 ) ), level );\n\tlet rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ), level );\n\tlet rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ), level );\n\tlet rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ), level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")};class YI extends I_{constructor(t,e){super(t,e,new kI),this.uniformGroups={},this.builtins={}}needsColorSpaceToLinear(t){return!0===t.isVideoTexture&&t.colorSpace!==Ye}_generateTextureSample(t,e,s,i,r=this.shaderStage){return"fragment"===r?i?`textureSample( ${e}, ${e}_sampler, ${s}, ${i} )`:`textureSample( ${e}, ${e}_sampler, ${s} )`:this.isFilteredTexture(t)?this.generateFilteredTexture(t,e,s):this.generateTextureLod(t,e,s,"0")}_generateVideoSample(t,e,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${t}, ${t}_sampler, vec2( ${e}.x, 1.0 - ${e}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(t,e,s,i,r,n=this.shaderStage){return"fragment"===n&&!1===this.isUnfilterable(t)?`textureSampleLevel( ${e}, ${e}_sampler, ${s}, ${i} )`:this.isFilteredTexture(t)?this.generateFilteredTexture(t,e,s,i):this.generateTextureLod(t,e,s,i)}generateFilteredTexture(t,e,s,i="0"){return this._include("biquadraticTexture"),`threejs_biquadraticTexture( ${e}, ${s}, i32( ${i} ) )`}generateTextureLod(t,e,s,i="0"){this._include("repeatWrapping");return`textureLoad( ${e}, threejs_repeatWrapping( ${s}, ${!0===t.isMultisampleRenderTargetTexture?`textureDimensions( ${e} )`:`textureDimensions( ${e}, 0 )`} ), i32( ${i} ) )`}generateTextureLoad(t,e,s,i,r="0u"){return i?`textureLoad( ${e}, ${s}, ${i}, ${r} )`:`textureLoad( ${e}, ${s}, ${r} )`}generateTextureStore(t,e,s,i){return`textureStore( ${e}, ${s}, ${i} )`}isUnfilterable(t){return"float"!==this.getComponentTypeFromTexture(t)||!0===t.isDataTexture&&t.type===It||!0===t.isMultisampleRenderTargetTexture}generateTexture(t,e,s,i,r=this.shaderStage){let n=null;return n=!0===t.isVideoTexture?this._generateVideoSample(e,s,r):this.isUnfilterable(t)?this.generateTextureLod(t,e,s,"0",i,r):this._generateTextureSample(t,e,s,i,r),n}generateTextureGrad(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleGrad( ${e}, ${e}_sampler, ${s}, ${i[0]}, ${i[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${n} shader.`)}generateTextureCompare(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleCompare( ${e}, ${e}_sampler, ${s}, ${i} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}generateTextureLevel(t,e,s,i,r,n=this.shaderStage){let o=null;return o=!0===t.isVideoTexture?this._generateVideoSample(e,s,n):this._generateTextureSampleLevel(t,e,s,i,r,n),o}generateTextureBias(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleBias( ${e}, ${e}_sampler, ${s}, ${i} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${n} shader.`)}getPropertyName(t,e=this.shaderStage){if(!0===t.isNodeVarying&&!0===t.needsInterpolation){if("vertex"===e)return`varyings.${t.name}`}else if(!0===t.isNodeUniform){const e=t.name,s=t.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?e:"buffer"===s||"storageBuffer"===s?`NodeBuffer_${t.id}.${e}`:t.groupNode.name+"."+e}return super.getPropertyName(t)}getOutputStructName(){return"output"}_getUniformGroupCount(t){return Object.keys(this.uniforms[t]).length}getFunctionOperator(t){const e=HI[t];return void 0!==e?(this._include(e),e):null}getStorageAccess(t){if(t.isStorageTextureNode)switch(t.access){case LM:return"read";case zM:return"write";default:return"read_write"}else switch(t.access){case UM:return"read_write";case OM:return"read";default:return"write"}}getUniformFromNode(t,e,s,i=null){const r=super.getUniformFromNode(t,e,s,i),n=this.getDataFromNode(t,s,this.globalCache);if(void 0===n.uniformGPU){let i;const o=t.groupNode,a=o.name,h=this.getBindGroupArray(a,s);if("texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e){let n=null;if("texture"===e||"storageTexture"===e?n=new ZB(r.name,r.node,o,t.access?t.access:null):"cubeTexture"===e?n=new QB(r.name,r.node,o,t.access?t.access:null):"texture3D"===e&&(n=new KB(r.name,r.node,o,t.access?t.access:null)),n.store=!0===t.isStorageTextureNode,n.setVisibility(WI[s]),"fragment"===s&&!1===this.isUnfilterable(t.value)&&!1===n.store){const t=new RI(`${r.name}_sampler`,r.node,o);t.setVisibility(WI[s]),h.push(t,n),i=[t,n]}else h.push(n),i=[n]}else if("buffer"===e||"storageBuffer"===e){const r=new("storageBuffer"===e?BI:HB)(t,o);r.setVisibility(WI[s]),h.push(r),i=r}else{const t=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=t[a];void 0===n&&(n=new XB(a,o),n.setVisibility(WI[s]),t[a]=n,h.push(n)),i=this.getNodeUniform(r,e),n.addUniform(i)}n.uniformGPU=i}return r}getBuiltin(t,e,s,i=this.shaderStage){const r=this.builtins[i]||(this.builtins[i]=new Map);return!1===r.has(t)&&r.set(t,{name:t,property:e,type:s}),e}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(t){const e=t.layout,s=this.flowShaderNode(t),i=[];for(const t of e.inputs)i.push(t.name+" : "+this.getType(t.type));return`fn ${e.name}( ${i.join(", ")} ) -> ${this.getType(e.type)} {\n${s.vars}\n${s.code}\n\treturn ${s.result};\n\n}`}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xyz"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}isFlipY(){return!1}getBuiltins(t){const e=[],s=this.builtins[t];if(void 0!==s)for(const{name:t,property:i,type:r}of s.values())e.push(`@builtin( ${t} ) ${i} : ${r}`);return e.join(",\n\t")}getAttributes(t){const e=[];if("compute"===t&&this.getBuiltin("global_invocation_id","id","vec3","attribute"),"vertex"===t||"compute"===t){const t=this.getBuiltins("attribute");t&&e.push(t);const s=this.getAttributesArray();for(let t=0,i=s.length;t`)}const i=this.getBuiltins("output");return i&&e.push(i),e.join(",\n")}getStructs(t){const e=[],s=this.structs[t];for(let t=0,i=s.length;t output : ${r};\n\n`)}return e.join("\n\n")}getVar(t,e){return`var ${e} : ${this.getType(t)}`}getVars(t){const e=[],s=this.vars[t];if(void 0!==s)for(const t of s)e.push(`\t${this.getVar(t.type,t.name)};`);return`\n${e.join("\n")}\n`}getVaryings(t){const e=[];if("vertex"===t&&this.getBuiltin("position","Vertex","vec4","vertex"),"vertex"===t||"fragment"===t){const s=this.varyings,i=this.vars[t];for(let r=0;r";else if(!0===e.isDataArrayTexture)i="texture_2d_array";else if(!0===e.isDepthTexture)i=`texture_depth${n}_2d`;else if(!0===e.isVideoTexture)i="texture_external";else if(!0===e.isData3DTexture)i="texture_3d";else if(!0===r.node.isStorageTextureNode){i=`texture_storage_2d<${OI(e)}, ${this.getStorageAccess(r.node)}>`}else{i=`texture${n}_2d<${this.getComponentTypeFromTexture(e).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${r.name} : ${i};`)}else if("buffer"===r.type||"storageBuffer"===r.type){const t=r.node,e=this.getType(t.bufferType),s=t.bufferCount,n=s>0?", "+s:"",a=`\t${r.name} : array< ${e}${n} >\n`,h=t.isStorageBufferNode?`storage, ${this.getStorageAccess(t)}`:"uniform";i.push(this._getWGSLStructBinding("NodeBuffer_"+t.id,a,h,o.binding++,o.group))}else{const t=this.getType(this.getVectorType(r.type)),e=r.groupNode.name;(n[e]||(n[e]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${r.name} : ${t}`)}}for(const t in n){const e=n[t];r.push(this._getWGSLStructBinding(t,e.snippets.join(",\n"),"uniform",e.index,e.id))}let o=s.join("\n");return o+=i.join("\n"),o+=r.join("\n"),o}buildCode(){const t=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};for(const e in t){const s=t[e];s.uniforms=this.getUniforms(e),s.attributes=this.getAttributes(e),s.varyings=this.getVaryings(e),s.structs=this.getStructs(e),s.vars=this.getVars(e),s.codes=this.getCodes(e);let i="// code\n\n";i+=this.flowCode[e];const r=this.flowNodes[e],n=r[r.length-1],o=n.outputNode,a=void 0!==o&&!0===o.isOutputStructNode;for(const t of r){const r=this.getFlowData(t),h=t.name;if(h&&(i.length>0&&(i+="\n"),i+=`\t// flow -> ${h}\n\t`),i+=`${r.code}\n\t`,t===n&&"compute"!==e)if(i+="// result\n\n\t","vertex"===e)i+=`varyings.Vertex = ${r.result};`;else if("fragment"===e)if(a)s.returnType=o.nodeType,i+=`return ${r.result};`;else{let t="\t@location(0) color: vec4";const e=this.getBuiltins("output");e&&(t+=",\n\t"+e),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",t),s.structs+="\nvar output : OutputStruct;\n\n",i+=`output.color = ${r.result};\n\n\treturn output;`}}s.flow=i}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(t.vertex),this.fragmentShader=this._getWGSLFragmentCode(t.fragment)):this.computeShader=this._getWGSLComputeCode(t.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(t,e=null){let s;return null!==e&&(s=this._getWGSLMethod(t+"_"+e)),void 0===s&&(s=this._getWGSLMethod(t)),s||t}getType(t){return qI[t]||t}isAvailable(t){let e=jI[t];return void 0===e&&("float32Filterable"===t&&(e=this.renderer.hasFeature("float32-filterable")),jI[t]=e),e}_getWGSLMethod(t){return void 0!==XI[t]&&this._include(t),$I[t]}_include(t){const e=XI[t];return e.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(e),e}_getWGSLVertexCode(t){return`${this.getSignature()}\n\n// uniforms\n${t.uniforms}\n\n// varyings\n${t.varyings}\nvar varyings : VaryingsStruct;\n\n// codes\n${t.codes}\n\n@vertex\nfn main( ${t.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(t){return`${this.getSignature()}\n\ndiagnostic( off, derivative_uniformity );\n\n// uniforms\n${t.uniforms}\n\n// structs\n${t.structs}\n\n// codes\n${t.codes}\n\n@fragment\nfn main( ${t.varyings} ) -> ${t.returnType} {\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n}\n`}_getWGSLComputeCode(t,e){return`${this.getSignature()}\n// system\nvar instanceIndex : u32;\n\n// uniforms\n${t.uniforms}\n\n// codes\n${t.codes}\n\n@compute @workgroup_size( ${e} )\nfn main( ${t.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x;\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n}\n`}_getWGSLStruct(t,e){return`\nstruct ${t} {\n${e}\n};`}_getWGSLStructBinding(t,e,s,i=0,r=0){const n=t+"Struct";return`${this._getWGSLStruct(n,e)}\n@binding( ${i} ) @group( ${r} )\nvar<${s}> ${t} : ${n};`}}class JI{constructor(t){this.backend=t}getCurrentDepthStencilFormat(t){let e;return null!==t.depthTexture?e=this.getTextureFormatGPU(t.depthTexture):t.depth&&t.stencil?e=eM.Depth24PlusStencil8:t.depth&&(e=eM.Depth24Plus),e}getTextureFormatGPU(t){return this.backend.get(t).texture.format}getCurrentColorFormat(t){let e;return e=null!==t.textures?this.getTextureFormatGPU(t.textures[0]):eM.BGRA8Unorm,e}getCurrentColorSpace(t){return null!==t.textures?t.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(t,e){return t.isPoints?PS:t.isLineSegments||t.isMesh&&!0===e.wireframe?FS:t.isLine?US:t.isMesh?OS:void 0}getSampleCount(t){let e=1;return t>1&&(e=Math.pow(2,Math.floor(Math.log2(t))),2===e&&(e=4)),e}getSampleCountRenderContext(t){return null!==t.textures?this.getSampleCount(t.sampleCount):this.getSampleCount(this.backend.renderer.samples)}}const ZI=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),QI=new Map([[fn,["float16"]]]),KI=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class tP{constructor(t){this.backend=t}createAttribute(t,e){const s=this._getBufferAttribute(t),i=this.backend,r=i.get(s);let n=r.buffer;if(void 0===n){const o=i.device;let a=s.array;if(!1===t.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const t=new Uint32Array(a.length);for(let e=0;e{u.createRenderPipelineAsync(M).then((e=>{c.pipeline=e,t()}))}));e.push(t)}}createBundleEncoder(t,e){const s=this.backend,{utils:i,device:r}=s,n=s.get(t),o=s.get(e),a=i.getCurrentDepthStencilFormat(t),h={label:"renderBundleEncoder",colorFormats:[i.getCurrentColorFormat(t)],depthStencilFormat:a,sampleCount:this._getSampleCount(e.context)},u=r.createRenderBundleEncoder(h);return o.bundleEncoder=u,n.currentSets={attributes:{}},n._renderBundleViewport=t.width+"_"+t.height,u}createComputePipeline(t,e){const s=this.backend,i=s.device,r=s.get(t.computeProgram).module,n=s.get(t),o=[];for(const t of e){const e=s.get(t);o.push(e.layout)}n.pipeline=i.createComputePipeline({compute:r,layout:i.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(t){let e,s;const i=t.blending,r=t.blendSrc,n=t.blendDst,o=t.blendEquation;if(5===i){const i=null!==t.blendSrcAlpha?t.blendSrcAlpha:r,a=null!==t.blendDstAlpha?t.blendDstAlpha:n,h=null!==t.blendEquationAlpha?t.blendEquationAlpha:o;e={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(n),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(h)}}else{const r=(t,i,r,n)=>{e={srcFactor:t,dstFactor:i,operation:vM},s={srcFactor:r,dstFactor:n,operation:vM}};if(t.premultipliedAlpha)switch(i){case 1:r(cM,dM,hM,dM);break;case 2:r(cM,hM,hM,hM);break;case 3:r(aM,lM,aM,hM);break;case 4:r(aM,uM,aM,cM)}else switch(i){case 1:r(cM,dM,hM,dM);break;case 2:r(cM,hM,cM,hM);break;case 3:r(aM,lM,aM,hM);break;case 4:r(aM,uM,aM,uM)}}if(void 0!==e&&void 0!==s)return{color:e,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(t){let e;switch(t){case 200:e=aM;break;case 201:e=hM;break;case 202:e=uM;break;case 203:e=lM;break;case C:e=cM;break;case E:e=dM;break;case 208:e=pM;break;case 209:e=mM;break;case 206:e=gM;break;case 207:e=fM;break;case 210:e=yM;break;case 211:e=xM;break;case 212:e=bM;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",t)}return e}_getStencilCompare(t){let e;const s=t.stencilFunc;switch(s){case 512:e=LS;break;case bs:e=HS;break;case 513:e=VS;break;case 515:e=kS;break;case 514:e=DS;break;case 518:e=jS;break;case 516:e=GS;break;case 517:e=WS;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return e}_getStencilOperation(t){let e;switch(t){case ns:e=NM;break;case 0:e=RM;break;case 7681:e=CM;break;case 5386:e=EM;break;case 7682:e=BM;break;case 7683:e=IM;break;case 34055:e=PM;break;case 34056:e=FM;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",e)}return e}_getBlendOperation(t){let e;switch(t){case v:e=vM;break;case 101:e=TM;break;case 102:e=_M;break;case 103:e=wM;break;case 104:e=SM;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",t)}return e}_getPrimitiveState(t,e,s){const i={},r=this.backend.utils;switch(i.topology=r.getPrimitiveTopology(t,s),null!==e.index&&!0===t.isLine&&!0!==t.isLineSegments&&(i.stripIndexFormat=e.index.array instanceof Uint16Array?KS:tM),s.side){case c:i.frontFace=YS,i.cullMode=QS;break;case d:i.frontFace=YS,i.cullMode=ZS;break;case 2:i.frontFace=YS,i.cullMode=JS;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return i}_getColorWriteMask(t){return!0===t.colorWrite?AM:MM}_getDepthCompare(t){let e;if(!1===t.depthTest)e=HS;else{const s=t.depthFunc;switch(s){case 0:e=LS;break;case 1:e=HS;break;case 2:e=VS;break;case 3:e=kS;break;case 4:e=DS;break;case 5:e=jS;break;case 6:e=GS;break;case 7:e=WS;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return e}}class iP extends hI{constructor(t={}){super(t),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===t.alpha||t.alpha,this.parameters.requiredLimits=void 0===t.requiredLimits?{}:t.requiredLimits,this.trackTimestamp=!0===t.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new JI(this),this.attributeUtils=new tP(this),this.bindingUtils=new eP(this),this.pipelineUtils=new sP(this),this.textureUtils=new UI(this),this.occludedResolveCache=new Map}async init(t){await super.init(t);const e=this.parameters;let s;if(void 0===e.device){const t={powerPreference:e.powerPreference},i=await navigator.gpu.requestAdapter(t);if(null===i)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const r=Object.values(QM),n=[];for(const t of r)i.features.has(t)&&n.push(t);const o={requiredFeatures:n,requiredLimits:e.requiredLimits};s=await i.requestDevice(o)}else s=e.device;const i=void 0!==e.context?e.context:t.domElement.getContext("webgpu");this.device=s,this.context=i;const r=e.alpha?"premultiplied":"opaque";this.context.configure({device:this.device,format:eM.BGRA8Unorm,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:r}),this.updateSize()}get coordinateSystem(){return Ds}async getArrayBufferAsync(t){return await this.attributeUtils.getArrayBufferAsync(t)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let t=this.defaultRenderPassdescriptor;if(null===t){const e=this.renderer;t={colorAttachments:[{view:null}],depthStencilAttachment:{view:this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView()}};const s=t.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=t}const e=t.colorAttachments[0];return this.renderer.samples>0?e.resolveTarget=this.context.getCurrentTexture().createView():e.view=this.context.getCurrentTexture().createView(),t}_getRenderPassDescriptor(t){const e=t.renderTarget,s=this.get(e);let i=s.descriptors;void 0===i&&(i=[],s.descriptors=i),s.width===e.width&&s.height===e.height&&s.activeMipmapLevel===e.activeMipmapLevel&&s.samples===e.samples||(i.length=0);let r=i[t.activeCubeFace];if(void 0===r){const n=t.textures,o=[];for(let e=0;e0&&(e.currentOcclusionQuerySet&&e.currentOcclusionQuerySet.destroy(),e.currentOcclusionQueryBuffer&&e.currentOcclusionQueryBuffer.destroy(),e.currentOcclusionQuerySet=e.occlusionQuerySet,e.currentOcclusionQueryBuffer=e.occlusionQueryBuffer,e.currentOcclusionQueryObjects=e.occlusionQueryObjects,r=s.createQuerySet({type:"occlusion",count:i}),e.occlusionQuerySet=r,e.occlusionQueryIndex=0,e.occlusionQueryObjects=new Array(i),e.lastOcclusionObject=null),n=null===t.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(t),this.initTimestampQuery(t,n),n.occlusionQuerySet=r;const o=n.depthStencilAttachment;if(null!==t.textures){const e=n.colorAttachments;for(let s=0;s0&&(e.registerBundlesPhase=!1,e.currentPass.executeBundles(e.renderBundles)),s>e.occlusionQueryIndex&&e.currentPass.endOcclusionQuery(),e.currentPass.end(),s>0){const i=8*s;let r=this.occludedResolveCache.get(i);void 0===r&&(r=this.device.createBuffer({size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(i,r));const n=this.device.createBuffer({size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});e.encoder.resolveQuerySet(e.occlusionQuerySet,0,s,r,0),e.encoder.copyBufferToBuffer(r,0,n,0,i),e.occlusionQueryBuffer=n,this.resolveOccludedAsync(t)}if(this.prepareTimestampBuffer(t,e.encoder),this.device.queue.submit([e.encoder.finish()]),null!==t.textures){const e=t.textures;for(let t=0;to?(h.x=Math.min(e.dispatchCount,o),h.y=Math.ceil(e.dispatchCount/o)):h.x=e.dispatchCount,r.dispatchWorkgroups(h.x,h.y,h.z)}finishCompute(t){const e=this.get(t);e.passEncoderGPU.end(),this.prepareTimestampBuffer(t,e.cmdEncoderGPU),this.device.queue.submit([e.cmdEncoderGPU.finish()])}draw(t,e){const{object:s,geometry:i,context:r,pipeline:n}=t,o=t.getBindings(),a=this.get(r),h=this.get(n).pipeline,u=a.currentSets,l=this.get(t),{bundleEncoder:c,renderBundle:d,lastPipelineGPU:p}=l,m=this.get(r);if(!0===m.registerBundlesPhase&&void 0!==c&&p===h)return void m.renderBundles.push(d);const g=this.renderer._currentRenderBundle?this.createBundleEncoder(r,t):a.currentPass;u.pipeline!==h&&(g.setPipeline(h),u.pipeline=h);for(let t=0,e=o.length;t1?0:s;g.drawIndexed(e[s]/n,i,t[s]/4,0,o)}}else if(!0===y){const t=b.count!==1/0?b.count:f.count;g.drawIndexed(t,T,v,0,0),e.update(s,t,T)}else{const t=i.attributes.position,r=b.count!==1/0?b.count:t.count;g.draw(r,T,v,0),e.update(s,r,T)}if(this.renderer._currentRenderBundle){const t=g.finish();l.lastPipelineGPU=h,l.renderBundle=t,l.bundleEncoder=g}}}needsRenderUpdate(t){const e=this.get(t),{object:s,material:i}=t,r=this.utils,n=r.getSampleCountRenderContext(t.context),o=r.getCurrentColorSpace(t.context),a=r.getCurrentColorFormat(t.context),h=r.getCurrentDepthStencilFormat(t.context),u=r.getPrimitiveTopology(s,i);let l=!1;return e.material===i&&e.materialVersion===i.version&&e.transparent===i.transparent&&e.blending===i.blending&&e.premultipliedAlpha===i.premultipliedAlpha&&e.blendSrc===i.blendSrc&&e.blendDst===i.blendDst&&e.blendEquation===i.blendEquation&&e.blendSrcAlpha===i.blendSrcAlpha&&e.blendDstAlpha===i.blendDstAlpha&&e.blendEquationAlpha===i.blendEquationAlpha&&e.colorWrite===i.colorWrite&&e.depthWrite===i.depthWrite&&e.depthTest===i.depthTest&&e.depthFunc===i.depthFunc&&e.stencilWrite===i.stencilWrite&&e.stencilFunc===i.stencilFunc&&e.stencilFail===i.stencilFail&&e.stencilZFail===i.stencilZFail&&e.stencilZPass===i.stencilZPass&&e.stencilFuncMask===i.stencilFuncMask&&e.stencilWriteMask===i.stencilWriteMask&&e.side===i.side&&e.alphaToCoverage===i.alphaToCoverage&&e.sampleCount===n&&e.colorSpace===o&&e.colorFormat===a&&e.depthStencilFormat===h&&e.primitiveTopology===u&&e.clippingContextVersion===t.clippingContextVersion||(e.material=i,e.materialVersion=i.version,e.transparent=i.transparent,e.blending=i.blending,e.premultipliedAlpha=i.premultipliedAlpha,e.blendSrc=i.blendSrc,e.blendDst=i.blendDst,e.blendEquation=i.blendEquation,e.blendSrcAlpha=i.blendSrcAlpha,e.blendDstAlpha=i.blendDstAlpha,e.blendEquationAlpha=i.blendEquationAlpha,e.colorWrite=i.colorWrite,e.depthWrite=i.depthWrite,e.depthTest=i.depthTest,e.depthFunc=i.depthFunc,e.stencilWrite=i.stencilWrite,e.stencilFunc=i.stencilFunc,e.stencilFail=i.stencilFail,e.stencilZFail=i.stencilZFail,e.stencilZPass=i.stencilZPass,e.stencilFuncMask=i.stencilFuncMask,e.stencilWriteMask=i.stencilWriteMask,e.side=i.side,e.alphaToCoverage=i.alphaToCoverage,e.sampleCount=n,e.colorSpace=o,e.colorFormat=a,e.depthStencilFormat=h,e.primitiveTopology=u,e.clippingContextVersion=t.clippingContextVersion,l=!0),l}getRenderCacheKey(t){const{object:e,material:s}=t,i=this.utils,r=t.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,i.getSampleCountRenderContext(r),i.getCurrentColorSpace(r),i.getCurrentColorFormat(r),i.getCurrentDepthStencilFormat(r),i.getPrimitiveTopology(e,s),t.clippingContextVersion].join()}createSampler(t){this.textureUtils.createSampler(t)}destroySampler(t){this.textureUtils.destroySampler(t)}createDefaultTexture(t){this.textureUtils.createDefaultTexture(t)}createTexture(t,e){this.textureUtils.createTexture(t,e)}updateTexture(t,e){this.textureUtils.updateTexture(t,e)}generateMipmaps(t){this.textureUtils.generateMipmaps(t)}destroyTexture(t){this.textureUtils.destroyTexture(t)}copyTextureToBuffer(t,e,s,i,r){return this.textureUtils.copyTextureToBuffer(t,e,s,i,r)}initTimestampQuery(t,e){if(!this.hasFeature(QM.TimestampQuery)||!this.trackTimestamp)return;const s=this.get(t);if(!s.timeStampQuerySet){const t=this.device.createQuerySet({type:"timestamp",count:2}),i={querySet:t,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(e,{timestampWrites:i}),s.timeStampQuerySet=t}}prepareTimestampBuffer(t,e){if(!this.hasFeature(QM.TimestampQuery)||!this.trackTimestamp)return;const s=this.get(t),i=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:r,resultBuffer:n,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(e.resolveQuerySet(s.timeStampQuerySet,0,2,r,0),e.copyBufferToBuffer(r,0,n,0,i))}async resolveTimestampAsync(t,e="render"){if(!this.hasFeature(QM.TimestampQuery)||!this.trackTimestamp)return;const s=this.get(t);if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:i,isMappingPending:r}=s.currentTimestampQueryBuffers;!0!==r&&(s.currentTimestampQueryBuffers.isMappingPending=!0,i.mapAsync(GPUMapMode.READ).then((()=>{const t=new BigUint64Array(i.getMappedRange()),r=Number(t[1]-t[0])/1e6;this.renderer.info.updateTimestamp(e,r),i.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(t,e){return new YI(t,e)}createProgram(t){this.get(t).module={module:this.device.createShaderModule({code:t.code,label:t.stage}),entryPoint:"main"}}destroyProgram(t){this.delete(t)}createRenderPipeline(t,e){this.pipelineUtils.createRenderPipeline(t,e)}createComputePipeline(t,e){this.pipelineUtils.createComputePipeline(t,e)}createBundleEncoder(t,e){return this.pipelineUtils.createBundleEncoder(t,e)}createBindings(t){this.bindingUtils.createBindings(t)}updateBindings(t){this.bindingUtils.createBindings(t)}updateBinding(t){this.bindingUtils.updateBinding(t)}createIndexAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(t){this.attributeUtils.updateAttribute(t)}destroyAttribute(t){this.attributeUtils.destroyAttribute(t)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(t){return this.device.features.has(t)}copyTextureToTexture(t,e,s=null,i=null,r=0){let n=0,o=0,a=0,h=0,u=t.image.width,l=t.image.height;null!==s&&(a=s.x,h=s.y,u=s.width,l=s.height),null!==i&&(n=i.x,o=i.y);const c=this.device.createCommandEncoder({label:"copyTextureToTexture_"+t.id+"_"+e.id}),d=this.get(t).texture,p=this.get(e).texture;c.copyTextureToTexture({texture:d,mipLevel:r,origin:{x:a,y:h,z:0}},{texture:p,mipLevel:r,origin:{x:n,y:o,z:0}},[u,l]),this.device.queue.submit([c.finish()])}copyFramebufferToTexture(t,e){const s=this.get(e),{encoder:i,descriptor:r}=s;let n=null;n=e.renderTarget?t.isDepthTexture?this.get(e.depthTexture).texture:this.get(e.textures[0]).texture:t.isDepthTexture?this.textureUtils.getDepthBuffer(e.depth,e.stencil):this.context.getCurrentTexture();const o=this.get(t).texture;if(n.format===o.format){s.currentPass.end(),i.copyTextureToTexture({texture:n,origin:{x:0,y:0,z:0}},{texture:o},[t.image.width,t.image.height]),t.generateMipmaps&&this.textureUtils.generateMipmaps(t);for(let t=0;t