@needle-tools/three 0.169.20 → 0.183.2-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +5 -6
- package/build/three.cjs +54178 -56709
- package/build/three.core.js +59506 -0
- package/build/three.core.min.js +6 -0
- package/build/three.module.js +11645 -73012
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +648 -0
- package/build/three.tsl.min.js +6 -0
- package/build/three.webgpu.js +53905 -51657
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +53884 -51814
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
- package/examples/fonts/MPLUSRounded1c/OFL.txt +91 -0
- package/examples/jsm/Addons.js +5 -15
- package/examples/jsm/animation/AnimationClipCreator.js +58 -6
- package/examples/jsm/animation/CCDIKSolver.js +152 -45
- package/examples/jsm/capabilities/WebGL.js +28 -29
- package/examples/jsm/capabilities/WebGPU.js +19 -17
- package/examples/jsm/controls/ArcballControls.js +474 -178
- package/examples/jsm/controls/DragControls.js +100 -58
- package/examples/jsm/controls/FirstPersonControls.js +116 -6
- package/examples/jsm/controls/FlyControls.js +50 -2
- package/examples/jsm/controls/MapControls.js +96 -8
- package/examples/jsm/controls/OrbitControls.js +496 -57
- package/examples/jsm/controls/PointerLockControls.js +115 -22
- package/examples/jsm/controls/TrackballControls.js +166 -14
- package/examples/jsm/controls/TransformControls.js +336 -26
- package/examples/jsm/csm/CSM.js +232 -18
- package/examples/jsm/csm/CSMFrustum.js +61 -4
- package/examples/jsm/csm/CSMHelper.js +50 -0
- package/examples/jsm/csm/CSMShader.js +13 -1
- package/examples/jsm/csm/CSMShadowNode.js +599 -0
- package/examples/jsm/curves/CurveExtras.js +303 -31
- package/examples/jsm/curves/NURBSCurve.js +91 -16
- package/examples/jsm/curves/NURBSSurface.js +52 -6
- package/examples/jsm/curves/NURBSUtils.js +102 -112
- package/examples/jsm/curves/NURBSVolume.js +24 -4
- package/examples/jsm/effects/AnaglyphEffect.js +134 -7
- package/examples/jsm/effects/AsciiEffect.js +69 -22
- package/examples/jsm/effects/OutlineEffect.js +61 -111
- package/examples/jsm/effects/ParallaxBarrierEffect.js +30 -0
- package/examples/jsm/effects/StereoEffect.js +31 -0
- package/examples/jsm/environments/ColorEnvironment.js +59 -0
- package/examples/jsm/environments/DebugEnvironment.js +50 -0
- package/examples/jsm/environments/RoomEnvironment.js +83 -42
- package/examples/jsm/exporters/DRACOExporter.js +56 -14
- package/examples/jsm/exporters/EXRExporter.js +40 -9
- package/examples/jsm/exporters/GLTFExporter.js +502 -169
- package/examples/jsm/exporters/OBJExporter.js +21 -1
- package/examples/jsm/exporters/PLYExporter.js +44 -12
- package/examples/jsm/exporters/STLExporter.js +27 -5
- package/examples/jsm/exporters/USDZExporter.js +781 -291
- package/examples/jsm/geometries/BoxLineGeometry.js +23 -0
- package/examples/jsm/geometries/ConvexGeometry.js +19 -0
- package/examples/jsm/geometries/DecalGeometry.js +91 -30
- package/examples/jsm/geometries/ParametricFunctions.js +100 -0
- package/examples/jsm/geometries/ParametricGeometry.js +38 -5
- package/examples/jsm/geometries/RoundedBoxGeometry.js +68 -7
- package/examples/jsm/geometries/TeapotGeometry.js +23 -38
- package/examples/jsm/geometries/TextGeometry.js +48 -29
- package/examples/jsm/gpgpu/BitonicSort.js +715 -0
- package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
- package/examples/jsm/helpers/LightProbeHelper.js +36 -0
- package/examples/jsm/helpers/LightProbeHelperGPU.js +38 -1
- package/examples/jsm/helpers/OctreeHelper.js +36 -0
- package/examples/jsm/helpers/PositionalAudioHelper.js +60 -0
- package/examples/jsm/helpers/RapierHelper.js +59 -0
- package/examples/jsm/helpers/RectAreaLightHelper.js +36 -3
- package/examples/jsm/helpers/TextureHelper.js +28 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +214 -0
- package/examples/jsm/helpers/VertexNormalsHelper.js +61 -2
- package/examples/jsm/helpers/VertexTangentsHelper.js +47 -2
- package/examples/jsm/helpers/ViewHelper.js +181 -9
- package/examples/jsm/inspector/Inspector.js +487 -0
- package/examples/jsm/inspector/RendererInspector.js +425 -0
- package/examples/jsm/inspector/tabs/Console.js +238 -0
- package/examples/jsm/inspector/tabs/Parameters.js +348 -0
- package/examples/jsm/inspector/tabs/Performance.js +268 -0
- package/examples/jsm/inspector/tabs/Viewer.js +166 -0
- package/examples/jsm/inspector/ui/Graph.js +95 -0
- package/examples/jsm/inspector/ui/Item.js +170 -0
- package/examples/jsm/inspector/ui/List.js +75 -0
- package/examples/jsm/inspector/ui/Profiler.js +1975 -0
- package/examples/jsm/inspector/ui/Style.js +1613 -0
- package/examples/jsm/inspector/ui/Tab.js +233 -0
- package/examples/jsm/inspector/ui/Values.js +439 -0
- package/examples/jsm/inspector/ui/utils.js +56 -0
- package/examples/jsm/interactive/HTMLMesh.js +43 -12
- package/examples/jsm/interactive/InteractiveGroup.js +170 -52
- package/examples/jsm/interactive/SelectionBox.js +106 -9
- package/examples/jsm/interactive/SelectionHelper.js +76 -30
- package/examples/jsm/libs/demuxer_mp4.js +109 -0
- package/examples/jsm/libs/meshopt_decoder.module.js +76 -58
- package/examples/jsm/libs/motion-controllers.module.js +1 -1
- package/examples/jsm/lighting/TiledLighting.js +42 -0
- package/examples/jsm/lights/LightProbeGenerator.js +44 -7
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +50 -14
- package/examples/jsm/lights/RectAreaLightUniformsLib.js +16 -0
- package/examples/jsm/lines/Line2.js +41 -4
- package/examples/jsm/lines/LineGeometry.js +80 -2
- package/examples/jsm/lines/LineMaterial.js +105 -5
- package/examples/jsm/lines/LineSegments2.js +54 -4
- package/examples/jsm/lines/LineSegmentsGeometry.js +65 -8
- package/examples/jsm/lines/Wireframe.js +41 -4
- package/examples/jsm/lines/WireframeGeometry2.js +27 -2
- package/examples/jsm/lines/webgpu/Line2.js +28 -2
- package/examples/jsm/lines/webgpu/LineSegments2.js +59 -24
- package/examples/jsm/lines/webgpu/Wireframe.js +86 -0
- package/examples/jsm/loaders/3DMLoader.js +78 -6
- package/examples/jsm/loaders/3MFLoader.js +148 -7
- package/examples/jsm/loaders/AMFLoader.js +34 -14
- package/examples/jsm/loaders/BVHLoader.js +59 -12
- package/examples/jsm/loaders/ColladaLoader.js +61 -4027
- package/examples/jsm/loaders/DDSLoader.js +68 -1
- package/examples/jsm/loaders/DRACOLoader.js +146 -22
- package/examples/jsm/loaders/EXRLoader.js +255 -34
- package/examples/jsm/loaders/FBXLoader.js +80 -42
- package/examples/jsm/loaders/FontLoader.js +83 -6
- package/examples/jsm/loaders/GCodeLoader.js +71 -14
- package/examples/jsm/loaders/GLTFLoader.js +381 -263
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +52 -3
- package/examples/jsm/loaders/HDRLoader.js +485 -0
- package/examples/jsm/loaders/IESLoader.js +42 -0
- package/examples/jsm/loaders/KMZLoader.js +39 -6
- package/examples/jsm/loaders/KTX2Loader.js +124 -48
- package/examples/jsm/loaders/KTXLoader.js +31 -10
- package/examples/jsm/loaders/LDrawLoader.js +192 -145
- package/examples/jsm/loaders/LUT3dlLoader.js +47 -10
- package/examples/jsm/loaders/LUTCubeLoader.js +46 -9
- package/examples/jsm/loaders/LUTImageLoader.js +79 -38
- package/examples/jsm/loaders/LWOLoader.js +54 -59
- package/examples/jsm/loaders/LottieLoader.js +54 -1
- package/examples/jsm/loaders/MD2Loader.js +37 -1
- package/examples/jsm/loaders/MDDLoader.js +57 -12
- package/examples/jsm/loaders/MTLLoader.js +60 -35
- package/examples/jsm/loaders/MaterialXLoader.js +268 -34
- package/examples/jsm/loaders/NRRDLoader.js +40 -8
- package/examples/jsm/loaders/OBJLoader.js +51 -2
- package/examples/jsm/loaders/PCDLoader.js +173 -21
- package/examples/jsm/loaders/PDBLoader.js +41 -2
- package/examples/jsm/loaders/PLYLoader.js +70 -39
- package/examples/jsm/loaders/PVRLoader.js +25 -6
- package/examples/jsm/loaders/RGBELoader.js +6 -438
- package/examples/jsm/loaders/STLLoader.js +48 -38
- package/examples/jsm/loaders/SVGLoader.js +119 -25
- package/examples/jsm/loaders/TDSLoader.js +92 -74
- package/examples/jsm/loaders/TGALoader.js +23 -2
- package/examples/jsm/loaders/TIFFLoader.js +23 -0
- package/examples/jsm/loaders/TTFLoader.js +50 -3
- package/examples/jsm/loaders/USDLoader.js +279 -0
- package/examples/jsm/loaders/USDZLoader.js +4 -858
- package/examples/jsm/loaders/UltraHDRLoader.js +338 -166
- package/examples/jsm/loaders/VOXLoader.js +688 -87
- package/examples/jsm/loaders/VRMLLoader.js +121 -12
- package/examples/jsm/loaders/VTKLoader.js +77 -25
- package/examples/jsm/loaders/XYZLoader.js +36 -0
- package/examples/jsm/loaders/collada/ColladaComposer.js +2950 -0
- package/examples/jsm/loaders/collada/ColladaParser.js +1962 -0
- package/examples/jsm/loaders/lwo/IFFParser.js +77 -77
- package/examples/jsm/loaders/usd/USDAParser.js +822 -0
- package/examples/jsm/loaders/usd/USDCParser.js +1852 -0
- package/examples/jsm/loaders/usd/USDComposer.js +4041 -0
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +183 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +154 -0
- package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
- package/examples/jsm/math/Capsule.js +91 -14
- package/examples/jsm/math/ColorConverter.js +22 -0
- package/examples/jsm/math/ColorSpaces.js +74 -2
- package/examples/jsm/math/ConvexHull.js +517 -93
- package/examples/jsm/math/ImprovedNoise.js +32 -15
- package/examples/jsm/math/Lut.js +113 -0
- package/examples/jsm/math/MeshSurfaceSampler.js +78 -13
- package/examples/jsm/math/OBB.js +141 -29
- package/examples/jsm/math/Octree.js +283 -7
- package/examples/jsm/math/SimplexNoise.js +68 -42
- package/examples/jsm/misc/ConvexObjectBreaker.js +45 -25
- package/examples/jsm/misc/GPUComputationRenderer.js +96 -20
- package/examples/jsm/misc/Gyroscope.js +12 -0
- package/examples/jsm/misc/MD2Character.js +117 -2
- package/examples/jsm/misc/MD2CharacterComplex.js +175 -11
- package/examples/jsm/misc/MorphAnimMesh.js +44 -0
- package/examples/jsm/misc/MorphBlendMesh.js +103 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +100 -54
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +322 -0
- package/examples/jsm/misc/RollerCoaster.js +57 -0
- package/examples/jsm/misc/TubePainter.js +437 -40
- package/examples/jsm/misc/Volume.js +123 -76
- package/examples/jsm/misc/VolumeSlice.js +95 -49
- package/examples/jsm/modifiers/CurveModifier.js +66 -38
- package/examples/jsm/modifiers/CurveModifierGPU.js +42 -19
- package/examples/jsm/modifiers/EdgeSplitModifier.js +20 -0
- package/examples/jsm/modifiers/SimplifyModifier.js +24 -10
- package/examples/jsm/modifiers/TessellateModifier.js +35 -2
- package/examples/jsm/objects/GroundedSkybox.js +25 -6
- package/examples/jsm/objects/Lensflare.js +94 -2
- package/examples/jsm/objects/LensflareMesh.js +64 -10
- package/examples/jsm/objects/MarchingCubes.js +90 -5
- package/examples/jsm/objects/Reflector.js +76 -2
- package/examples/jsm/objects/ReflectorForSSRPass.js +41 -0
- package/examples/jsm/objects/Refractor.js +62 -0
- package/examples/jsm/objects/ShadowMesh.js +54 -4
- package/examples/jsm/objects/Sky.js +106 -16
- package/examples/jsm/objects/SkyMesh.js +211 -38
- package/examples/jsm/objects/Water.js +49 -8
- package/examples/jsm/objects/Water2.js +49 -7
- package/examples/jsm/objects/Water2Mesh.js +50 -9
- package/examples/jsm/objects/WaterMesh.js +136 -43
- package/examples/jsm/physics/AmmoPhysics.js +60 -7
- package/examples/jsm/physics/JoltPhysics.js +65 -12
- package/examples/jsm/physics/RapierPhysics.js +217 -21
- package/examples/jsm/postprocessing/AfterimagePass.js +110 -29
- package/examples/jsm/postprocessing/BloomPass.js +128 -26
- package/examples/jsm/postprocessing/BokehPass.js +99 -22
- package/examples/jsm/postprocessing/ClearPass.js +54 -3
- package/examples/jsm/postprocessing/CubeTexturePass.js +82 -21
- package/examples/jsm/postprocessing/DotScreenPass.js +59 -10
- package/examples/jsm/postprocessing/EffectComposer.js +140 -6
- package/examples/jsm/postprocessing/FXAAPass.js +40 -0
- package/examples/jsm/postprocessing/FilmPass.js +54 -5
- package/examples/jsm/postprocessing/GTAOPass.js +202 -57
- package/examples/jsm/postprocessing/GlitchPass.js +86 -34
- package/examples/jsm/postprocessing/HalftonePass.js +65 -10
- package/examples/jsm/postprocessing/LUTPass.js +38 -8
- package/examples/jsm/postprocessing/MaskPass.js +91 -0
- package/examples/jsm/postprocessing/OutlinePass.js +272 -135
- package/examples/jsm/postprocessing/OutputPass.js +65 -14
- package/examples/jsm/postprocessing/Pass.js +100 -4
- package/examples/jsm/postprocessing/RenderPass.js +94 -0
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +124 -45
- package/examples/jsm/postprocessing/RenderTransitionPass.js +120 -21
- package/examples/jsm/postprocessing/SAOPass.js +128 -55
- package/examples/jsm/postprocessing/SMAAPass.js +106 -75
- package/examples/jsm/postprocessing/SSAARenderPass.js +118 -35
- package/examples/jsm/postprocessing/SSAOPass.js +173 -60
- package/examples/jsm/postprocessing/SSRPass.js +268 -53
- package/examples/jsm/postprocessing/SavePass.js +69 -16
- package/examples/jsm/postprocessing/ShaderPass.js +65 -7
- package/examples/jsm/postprocessing/TAARenderPass.js +79 -24
- package/examples/jsm/postprocessing/TexturePass.js +72 -8
- package/examples/jsm/postprocessing/UnrealBloomPass.js +168 -59
- package/examples/jsm/renderers/CSS2DRenderer.js +98 -5
- package/examples/jsm/renderers/CSS3DRenderer.js +111 -7
- package/examples/jsm/renderers/Projector.js +288 -32
- package/examples/jsm/renderers/SVGRenderer.js +323 -61
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +3 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +5 -1
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +12 -5
- package/examples/jsm/shaders/AfterimageShader.js +8 -3
- package/examples/jsm/shaders/BasicShader.js +8 -1
- package/examples/jsm/shaders/BleachBypassShader.js +10 -3
- package/examples/jsm/shaders/BlendShader.js +8 -1
- package/examples/jsm/shaders/BokehShader.js +9 -3
- package/examples/jsm/shaders/BokehShader2.js +11 -4
- package/examples/jsm/shaders/BrightnessContrastShader.js +10 -4
- package/examples/jsm/shaders/ColorCorrectionShader.js +8 -1
- package/examples/jsm/shaders/ColorifyShader.js +8 -1
- package/examples/jsm/shaders/ConvolutionShader.js +9 -38
- package/examples/jsm/shaders/CopyShader.js +8 -1
- package/examples/jsm/shaders/DOFMipMapShader.js +10 -3
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +10 -1
- package/examples/jsm/shaders/DigitalGlitch.js +10 -7
- package/examples/jsm/shaders/DotScreenShader.js +8 -3
- package/examples/jsm/shaders/ExposureShader.js +8 -1
- package/examples/jsm/shaders/FXAAShader.js +233 -221
- package/examples/jsm/shaders/FilmShader.js +13 -0
- package/examples/jsm/shaders/FocusShader.js +8 -3
- package/examples/jsm/shaders/FreiChenShader.js +10 -3
- package/examples/jsm/shaders/GTAOShader.js +55 -45
- package/examples/jsm/shaders/GammaCorrectionShader.js +11 -2
- package/examples/jsm/shaders/HalftoneShader.js +24 -4
- package/examples/jsm/shaders/HorizontalBlurShader.js +12 -3
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +9 -2
- package/examples/jsm/shaders/HueSaturationShader.js +10 -3
- package/examples/jsm/shaders/KaleidoShader.js +11 -4
- package/examples/jsm/shaders/LuminosityHighPassShader.js +8 -4
- package/examples/jsm/shaders/LuminosityShader.js +8 -2
- package/examples/jsm/shaders/MirrorShader.js +10 -4
- package/examples/jsm/shaders/NormalMapShader.js +7 -2
- package/examples/jsm/shaders/OutputShader.js +19 -1
- package/examples/jsm/shaders/PoissonDenoiseShader.js +30 -17
- package/examples/jsm/shaders/RGBShiftShader.js +8 -1
- package/examples/jsm/shaders/SAOShader.js +27 -5
- package/examples/jsm/shaders/SMAAShader.js +24 -1
- package/examples/jsm/shaders/SSAOShader.js +37 -6
- package/examples/jsm/shaders/SSRShader.js +32 -6
- package/examples/jsm/shaders/SepiaShader.js +8 -3
- package/examples/jsm/shaders/SobelOperatorShader.js +9 -3
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +13 -8
- package/examples/jsm/shaders/TechnicolorShader.js +10 -4
- package/examples/jsm/shaders/ToonShader.js +29 -6
- package/examples/jsm/shaders/TriangleBlurShader.js +9 -4
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +19 -6
- package/examples/jsm/shaders/VelocityShader.js +8 -1
- package/examples/jsm/shaders/VerticalBlurShader.js +9 -2
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +8 -1
- package/examples/jsm/shaders/VignetteShader.js +8 -3
- package/examples/jsm/shaders/VolumeShader.js +11 -2
- package/examples/jsm/shaders/WaterRefractionShader.js +11 -0
- package/examples/jsm/textures/FlakesTexture.js +14 -0
- package/examples/jsm/transpiler/AST.js +436 -31
- package/examples/jsm/transpiler/GLSLDecoder.js +380 -135
- package/examples/jsm/transpiler/Linker.js +327 -0
- package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -1
- package/examples/jsm/transpiler/TSLEncoder.js +363 -97
- package/examples/jsm/transpiler/Transpiler.js +50 -1
- package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
- package/examples/jsm/transpiler/WGSLEncoder.js +839 -0
- package/examples/jsm/tsl/display/AfterImageNode.js +244 -0
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +549 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +282 -0
- package/examples/jsm/tsl/display/BilateralBlurNode.js +364 -0
- package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +11 -4
- package/examples/jsm/tsl/display/BloomNode.js +534 -0
- package/examples/jsm/tsl/display/CRT.js +150 -0
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +207 -0
- package/examples/jsm/tsl/display/DenoiseNode.js +334 -0
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +554 -0
- package/examples/jsm/tsl/display/DotScreenNode.js +104 -0
- package/examples/jsm/tsl/display/FXAANode.js +365 -0
- package/examples/jsm/tsl/display/FilmNode.js +101 -0
- package/examples/jsm/tsl/display/GTAONode.js +571 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +389 -0
- package/examples/jsm/tsl/display/GodraysNode.js +624 -0
- package/examples/jsm/tsl/display/LensflareNode.js +279 -0
- package/examples/jsm/tsl/display/Lut3DNode.js +109 -0
- package/examples/jsm/tsl/display/MotionBlur.js +33 -0
- package/examples/jsm/tsl/display/OutlineNode.js +762 -0
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +89 -0
- package/examples/jsm/tsl/display/PixelationPassNode.js +335 -0
- package/examples/jsm/tsl/display/RGBShiftNode.js +96 -0
- package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
- package/examples/jsm/tsl/display/SMAANode.js +768 -0
- package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +120 -49
- package/examples/jsm/tsl/display/SSGINode.js +642 -0
- package/examples/jsm/tsl/display/SSRNode.js +656 -0
- package/examples/jsm/tsl/display/SSSNode.js +490 -0
- package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +9 -2
- package/examples/jsm/tsl/display/Shape.js +29 -0
- package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +61 -19
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +192 -0
- package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +48 -12
- package/examples/jsm/tsl/display/TRAANode.js +726 -0
- package/examples/jsm/tsl/display/TransitionNode.js +141 -0
- package/examples/jsm/tsl/display/boxBlur.js +65 -0
- package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
- package/examples/jsm/tsl/display/hashBlur.js +54 -0
- package/examples/jsm/tsl/display/radialBlur.js +68 -0
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +442 -0
- package/examples/jsm/tsl/math/Bayer.js +73 -0
- package/examples/jsm/tsl/shadows/TileShadowNode.js +456 -0
- package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +212 -0
- package/examples/jsm/tsl/utils/Raymarching.js +70 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +91 -29
- package/examples/jsm/utils/CameraUtils.js +15 -6
- package/examples/jsm/utils/GeometryCompressionUtils.js +23 -30
- package/examples/jsm/utils/GeometryUtils.js +32 -27
- package/examples/jsm/utils/LDrawUtils.js +14 -5
- package/examples/jsm/utils/SceneOptimizer.js +458 -0
- package/examples/jsm/utils/SceneUtils.js +53 -3
- package/examples/jsm/utils/ShadowMapViewer.js +72 -33
- package/examples/jsm/utils/ShadowMapViewerGPU.js +61 -29
- package/examples/jsm/utils/SkeletonUtils.js +48 -0
- package/examples/jsm/utils/SortUtils.js +17 -5
- package/examples/jsm/utils/UVsDebug.js +12 -4
- package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +16 -0
- package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +20 -2
- package/examples/jsm/utils/WorkerPool.js +67 -2
- package/examples/jsm/webxr/ARButton.js +19 -0
- package/examples/jsm/webxr/OculusHandModel.js +84 -0
- package/examples/jsm/webxr/OculusHandPointerModel.js +148 -22
- package/examples/jsm/webxr/Text2D.js +20 -6
- package/examples/jsm/webxr/VRButton.js +31 -0
- package/examples/jsm/webxr/XRButton.js +23 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +94 -3
- package/examples/jsm/webxr/XREstimatedLight.js +35 -4
- package/examples/jsm/webxr/XRHandMeshModel.js +37 -0
- package/examples/jsm/webxr/XRHandModelFactory.js +96 -6
- package/examples/jsm/webxr/XRHandPrimitiveModel.js +44 -0
- package/examples/jsm/webxr/XRPlanes.js +18 -0
- package/package.json +29 -34
- package/src/Three.Core.js +198 -0
- package/src/Three.Legacy.js +0 -21
- package/src/Three.TSL.js +641 -0
- package/src/Three.WebGPU.Nodes.js +14 -186
- package/src/Three.WebGPU.js +16 -186
- package/src/Three.js +2 -197
- package/src/animation/AnimationAction.js +263 -31
- package/src/animation/AnimationClip.js +162 -7
- package/src/animation/AnimationMixer.js +99 -15
- package/src/animation/AnimationObjectGroup.js +45 -21
- package/src/animation/AnimationUtils.js +163 -24
- package/src/animation/KeyframeTrack.js +191 -17
- package/src/animation/PropertyBinding.js +91 -16
- package/src/animation/PropertyMixer.js +72 -5
- package/src/animation/tracks/BooleanKeyframeTrack.js +33 -6
- package/src/animation/tracks/ColorKeyframeTrack.js +26 -5
- package/src/animation/tracks/NumberKeyframeTrack.js +26 -2
- package/src/animation/tracks/QuaternionKeyframeTrack.js +30 -1
- package/src/animation/tracks/StringKeyframeTrack.js +33 -2
- package/src/animation/tracks/VectorKeyframeTrack.js +26 -2
- package/src/audio/Audio.js +386 -8
- package/src/audio/AudioAnalyser.js +58 -1
- package/src/audio/AudioContext.js +15 -0
- package/src/audio/AudioListener.js +94 -13
- package/src/audio/PositionalAudio.js +107 -0
- package/src/cameras/ArrayCamera.js +37 -0
- package/src/cameras/Camera.js +61 -0
- package/src/cameras/CubeCamera.js +86 -0
- package/src/cameras/OrthographicCamera.js +110 -1
- package/src/cameras/PerspectiveCamera.js +174 -35
- package/src/cameras/StereoCamera.js +48 -2
- package/src/constants.js +1546 -11
- package/src/core/BufferAttribute.js +417 -3
- package/src/core/BufferGeometry.js +407 -22
- package/src/core/Clock.js +69 -8
- package/src/core/EventDispatcher.js +52 -8
- package/src/core/GLBufferAttribute.js +113 -2
- package/src/core/InstancedBufferAttribute.js +29 -0
- package/src/core/InstancedBufferGeometry.js +20 -0
- package/src/core/InstancedInterleavedBuffer.js +26 -0
- package/src/core/InterleavedBuffer.js +141 -7
- package/src/core/InterleavedBufferAttribute.js +200 -2
- package/src/core/Layers.js +71 -10
- package/src/core/Object3D.js +673 -26
- package/src/core/Raycaster.js +136 -2
- package/src/core/RenderTarget.js +256 -27
- package/src/core/RenderTarget3D.js +48 -0
- package/src/core/Timer.js +184 -0
- package/src/core/Uniform.js +29 -0
- package/src/core/UniformsGroup.js +84 -2
- package/src/extras/Controls.js +89 -1
- package/src/extras/DataUtils.js +50 -9
- package/src/extras/Earcut.js +18 -779
- package/src/extras/ImageUtils.js +22 -14
- package/src/extras/PMREMGenerator.js +316 -67
- package/src/extras/ShapeUtils.js +24 -2
- package/src/extras/TextureUtils.js +101 -15
- package/src/extras/core/Curve.js +156 -55
- package/src/extras/core/CurvePath.js +63 -22
- package/src/extras/core/Interpolations.js +34 -2
- package/src/extras/core/Path.js +134 -1
- package/src/extras/core/Shape.js +66 -3
- package/src/extras/core/ShapePath.js +80 -4
- package/src/extras/curves/ArcCurve.js +22 -0
- package/src/extras/curves/CatmullRomCurve3.js +89 -18
- package/src/extras/curves/CubicBezierCurve.js +67 -0
- package/src/extras/curves/CubicBezierCurve3.js +50 -0
- package/src/extras/curves/EllipseCurve.js +102 -0
- package/src/extras/curves/LineCurve.js +36 -0
- package/src/extras/curves/LineCurve3.js +36 -0
- package/src/extras/curves/QuadraticBezierCurve.js +59 -0
- package/src/extras/curves/QuadraticBezierCurve3.js +43 -0
- package/src/extras/curves/SplineCurve.js +48 -0
- package/src/extras/lib/earcut.js +685 -0
- package/src/geometries/BoxGeometry.js +39 -0
- package/src/geometries/CapsuleGeometry.js +196 -11
- package/src/geometries/CircleGeometry.js +41 -0
- package/src/geometries/ConeGeometry.js +39 -0
- package/src/geometries/CylinderGeometry.js +42 -2
- package/src/geometries/DodecahedronGeometry.js +33 -0
- package/src/geometries/EdgesGeometry.js +30 -2
- package/src/geometries/ExtrudeGeometry.js +148 -52
- package/src/geometries/IcosahedronGeometry.js +33 -0
- package/src/geometries/LatheGeometry.js +44 -3
- package/src/geometries/OctahedronGeometry.js +33 -0
- package/src/geometries/PlaneGeometry.js +35 -0
- package/src/geometries/PolyhedronGeometry.js +30 -1
- package/src/geometries/RingGeometry.js +37 -0
- package/src/geometries/ShapeGeometry.js +38 -0
- package/src/geometries/SphereGeometry.js +38 -0
- package/src/geometries/TetrahedronGeometry.js +33 -0
- package/src/geometries/TorusGeometry.js +44 -3
- package/src/geometries/TorusKnotGeometry.js +39 -0
- package/src/geometries/TubeGeometry.js +50 -0
- package/src/geometries/WireframeGeometry.js +32 -0
- package/src/helpers/ArrowHelper.js +62 -5
- package/src/helpers/AxesHelper.js +28 -0
- package/src/helpers/Box3Helper.js +28 -0
- package/src/helpers/BoxHelper.js +43 -7
- package/src/helpers/CameraHelper.js +103 -27
- package/src/helpers/DirectionalLightHelper.js +55 -0
- package/src/helpers/GridHelper.js +26 -0
- package/src/helpers/HemisphereLightHelper.js +42 -0
- package/src/helpers/PlaneHelper.js +33 -0
- package/src/helpers/PointLightHelper.js +43 -24
- package/src/helpers/PolarGridHelper.js +30 -0
- package/src/helpers/SkeletonHelper.js +73 -7
- package/src/helpers/SpotLightHelper.js +43 -0
- package/src/lights/AmbientLight.js +25 -0
- package/src/lights/DirectionalLight.js +70 -0
- package/src/lights/DirectionalLightShadow.js +15 -0
- package/src/lights/HemisphereLight.js +42 -0
- package/src/lights/Light.js +37 -11
- package/src/lights/LightProbe.js +37 -9
- package/src/lights/LightShadow.js +202 -7
- package/src/lights/PointLight.js +74 -0
- package/src/lights/PointLightShadow.js +15 -80
- package/src/lights/RectAreaLight.js +59 -0
- package/src/lights/SpotLight.js +124 -1
- package/src/lights/SpotLightShadow.js +33 -3
- package/src/lights/webgpu/IESSpotLight.js +22 -0
- package/src/lights/webgpu/ProjectorLight.js +46 -0
- package/src/loaders/AnimationLoader.js +34 -2
- package/src/loaders/AudioLoader.js +34 -2
- package/src/loaders/BufferGeometryLoader.js +38 -13
- package/src/loaders/Cache.js +75 -2
- package/src/loaders/CompressedTextureLoader.js +36 -3
- package/src/loaders/CubeTextureLoader.js +45 -0
- package/src/loaders/DataTextureLoader.js +45 -4
- package/src/loaders/FileLoader.js +85 -5
- package/src/loaders/ImageBitmapLoader.js +113 -11
- package/src/loaders/ImageLoader.js +85 -8
- package/src/loaders/Loader.js +144 -0
- package/src/loaders/LoaderUtils.js +18 -36
- package/src/loaders/LoadingManager.js +187 -0
- package/src/loaders/MaterialLoader.js +62 -3
- package/src/loaders/ObjectLoader.js +131 -31
- package/src/loaders/TextureLoader.js +33 -0
- package/src/loaders/nodes/NodeLoader.js +68 -4
- package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
- package/src/loaders/nodes/NodeObjectLoader.js +61 -0
- package/src/materials/LineBasicMaterial.js +74 -1
- package/src/materials/LineDashedMaterial.js +52 -1
- package/src/materials/Material.js +502 -8
- package/src/materials/MeshBasicMaterial.js +168 -2
- package/src/materials/MeshDepthMaterial.js +94 -0
- package/src/materials/MeshDistanceMaterial.js +76 -0
- package/src/materials/MeshLambertMaterial.js +283 -0
- package/src/materials/MeshMatcapMaterial.js +164 -0
- package/src/materials/MeshNormalMaterial.js +114 -0
- package/src/materials/MeshPhongMaterial.js +298 -0
- package/src/materials/MeshPhysicalMaterial.js +296 -4
- package/src/materials/MeshStandardMaterial.js +300 -2
- package/src/materials/MeshToonMaterial.js +219 -0
- package/src/materials/PointsMaterial.js +89 -0
- package/src/materials/RawShaderMaterial.js +25 -0
- package/src/materials/ShaderMaterial.js +234 -6
- package/src/materials/ShadowMaterial.js +54 -0
- package/src/materials/SpriteMaterial.js +82 -0
- package/src/materials/nodes/Line2NodeMaterial.js +158 -53
- package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
- package/src/materials/nodes/LineDashedNodeMaterial.js +81 -6
- package/src/materials/nodes/MeshBasicNodeMaterial.js +59 -2
- package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +23 -3
- package/src/materials/nodes/MeshNormalNodeMaterial.js +27 -4
- package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +276 -3
- package/src/materials/nodes/MeshSSSNodeMaterial.js +98 -10
- package/src/materials/nodes/MeshStandardNodeMaterial.js +83 -4
- package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
- package/src/materials/nodes/NodeMaterial.js +789 -74
- package/src/materials/nodes/NodeMaterials.js +0 -1
- package/src/materials/nodes/PointsNodeMaterial.js +180 -11
- package/src/materials/nodes/ShadowNodeMaterial.js +38 -0
- package/src/materials/nodes/SpriteNodeMaterial.js +86 -23
- package/src/materials/nodes/VolumeNodeMaterial.js +57 -84
- package/src/materials/nodes/manager/NodeMaterialObserver.js +329 -12
- package/src/math/Box2.js +177 -0
- package/src/math/Box3.js +271 -0
- package/src/math/Color.js +355 -11
- package/src/math/ColorManagement.js +158 -92
- package/src/math/Cylindrical.js +65 -6
- package/src/math/Euler.js +139 -5
- package/src/math/Frustum.js +108 -9
- package/src/math/FrustumArray.js +258 -0
- package/src/math/Interpolant.js +87 -8
- package/src/math/Line3.js +221 -2
- package/src/math/MathUtils.js +408 -20
- package/src/math/Matrix2.js +70 -0
- package/src/math/Matrix3.js +229 -4
- package/src/math/Matrix4.js +489 -94
- package/src/math/Plane.js +164 -2
- package/src/math/Quaternion.js +322 -90
- package/src/math/Ray.js +162 -0
- package/src/math/Sphere.js +175 -0
- package/src/math/Spherical.js +73 -11
- package/src/math/SphericalHarmonics3.js +112 -14
- package/src/math/Triangle.js +206 -2
- package/src/math/Vector2.js +396 -10
- package/src/math/Vector3.js +550 -15
- package/src/math/Vector4.js +415 -9
- package/src/math/interpolants/BezierInterpolant.js +108 -0
- package/src/math/interpolants/CubicInterpolant.js +10 -1
- package/src/math/interpolants/DiscreteInterpolant.js +10 -2
- package/src/math/interpolants/LinearInterpolant.js +13 -0
- package/src/math/interpolants/QuaternionLinearInterpolant.js +10 -1
- package/src/nodes/Nodes.js +91 -88
- package/src/nodes/TSL.js +32 -38
- package/src/nodes/accessors/AccessorsUtils.js +37 -9
- package/src/nodes/accessors/Arrays.js +68 -0
- package/src/nodes/accessors/BatchNode.js +49 -14
- package/src/nodes/accessors/Bitangent.js +82 -13
- package/src/nodes/accessors/BufferAttributeNode.js +269 -8
- package/src/nodes/accessors/BufferNode.js +91 -2
- package/src/nodes/accessors/BuiltinNode.js +63 -0
- package/src/nodes/accessors/Camera.js +400 -10
- package/src/nodes/accessors/ClippingNode.js +149 -45
- package/src/nodes/accessors/CubeTextureNode.js +137 -7
- package/src/nodes/accessors/InstanceNode.js +245 -40
- package/src/nodes/accessors/InstancedMeshNode.js +50 -0
- package/src/nodes/accessors/Lights.js +88 -0
- package/src/nodes/accessors/MaterialNode.js +355 -13
- package/src/nodes/accessors/MaterialProperties.js +57 -1
- package/src/nodes/accessors/MaterialReferenceNode.js +52 -14
- package/src/nodes/accessors/ModelNode.js +117 -5
- package/src/nodes/accessors/ModelViewProjectionNode.js +10 -39
- package/src/nodes/accessors/MorphNode.js +73 -26
- package/src/nodes/accessors/Normal.js +174 -19
- package/src/nodes/accessors/Object3DNode.js +146 -12
- package/src/nodes/accessors/PointUVNode.js +25 -0
- package/src/nodes/accessors/Position.js +119 -7
- package/src/nodes/accessors/ReferenceBaseNode.js +190 -4
- package/src/nodes/accessors/ReferenceNode.js +223 -8
- package/src/nodes/accessors/ReflectVector.js +29 -3
- package/src/nodes/accessors/RendererReferenceNode.js +45 -2
- package/src/nodes/accessors/SceneProperties.js +53 -0
- package/src/nodes/accessors/SkinningNode.js +180 -43
- package/src/nodes/accessors/StorageBufferNode.js +278 -26
- package/src/nodes/accessors/StorageTextureNode.js +205 -12
- package/src/nodes/accessors/Tangent.js +48 -10
- package/src/nodes/accessors/TangentUtils.js +46 -0
- package/src/nodes/accessors/Texture3DNode.js +104 -11
- package/src/nodes/accessors/TextureBicubic.js +31 -4
- package/src/nodes/accessors/TextureNode.js +564 -52
- package/src/nodes/accessors/TextureSizeNode.js +42 -1
- package/src/nodes/accessors/UV.js +9 -1
- package/src/nodes/accessors/UniformArrayNode.js +226 -34
- package/src/nodes/accessors/UserDataNode.js +46 -2
- package/src/nodes/accessors/VelocityNode.js +93 -3
- package/src/nodes/accessors/VertexColorNode.js +39 -4
- package/src/nodes/code/CodeNode.js +101 -8
- package/src/nodes/code/ExpressionNode.js +29 -2
- package/src/nodes/code/FunctionCallNode.js +98 -10
- package/src/nodes/code/FunctionNode.js +69 -2
- package/src/nodes/core/ArrayNode.js +174 -0
- package/src/nodes/core/AssignNode.js +80 -9
- package/src/nodes/core/AttributeNode.js +47 -4
- package/src/nodes/core/BypassNode.js +47 -3
- package/src/nodes/core/ConstNode.js +32 -0
- package/src/nodes/core/ContextNode.js +220 -14
- package/src/nodes/core/IndexNode.js +72 -7
- package/src/nodes/core/InputNode.js +50 -1
- package/src/nodes/core/InspectorNode.js +128 -0
- package/src/nodes/core/IsolateNode.js +133 -0
- package/src/nodes/core/LightingModel.js +65 -5
- package/src/nodes/core/MRTNode.js +113 -2
- package/src/nodes/core/Node.js +595 -36
- package/src/nodes/core/NodeAttribute.js +38 -0
- package/src/nodes/core/NodeBuilder.js +1840 -121
- package/src/nodes/core/NodeCache.js +41 -2
- package/src/nodes/core/NodeCode.js +31 -0
- package/src/nodes/core/NodeError.js +28 -0
- package/src/nodes/core/NodeFrame.js +153 -24
- package/src/nodes/core/NodeFunction.js +48 -1
- package/src/nodes/core/NodeFunctionInput.js +44 -0
- package/src/nodes/core/NodeParser.js +13 -1
- package/src/nodes/core/NodeUniform.js +53 -1
- package/src/nodes/core/NodeUtils.js +201 -51
- package/src/nodes/core/NodeVar.js +47 -1
- package/src/nodes/core/NodeVarying.js +47 -1
- package/src/nodes/core/OutputStructNode.js +54 -12
- package/src/nodes/core/ParameterNode.js +60 -2
- package/src/nodes/core/PropertyNode.js +286 -7
- package/src/nodes/core/StackNode.js +337 -20
- package/src/nodes/core/StackTrace.js +139 -0
- package/src/nodes/core/StructNode.js +134 -0
- package/src/nodes/core/StructType.js +13 -0
- package/src/nodes/core/StructTypeNode.js +126 -6
- package/src/nodes/core/SubBuildNode.js +89 -0
- package/src/nodes/core/TempNode.js +31 -5
- package/src/nodes/core/UniformGroupNode.js +85 -7
- package/src/nodes/core/UniformNode.js +163 -16
- package/src/nodes/core/VarNode.js +317 -10
- package/src/nodes/core/VaryingNode.js +115 -13
- package/src/nodes/core/constants.js +40 -0
- package/src/nodes/display/BlendModes.js +171 -0
- package/src/nodes/display/BumpMapNode.js +38 -2
- package/src/nodes/display/ColorAdjustment.js +118 -6
- package/src/nodes/display/ColorSpaceFunctions.js +22 -6
- package/src/nodes/display/ColorSpaceNode.js +97 -47
- package/src/nodes/display/FrontFacingNode.js +64 -7
- package/src/nodes/display/NormalMapNode.js +101 -54
- package/src/nodes/display/PassNode.js +690 -33
- package/src/nodes/display/RenderOutputNode.js +94 -4
- package/src/nodes/display/ScreenNode.js +138 -27
- package/src/nodes/display/ToneMappingFunctions.js +62 -10
- package/src/nodes/display/ToneMappingNode.js +88 -8
- package/src/nodes/display/ToonOutlinePassNode.js +84 -4
- package/src/nodes/display/ViewportDepthNode.js +227 -10
- package/src/nodes/display/ViewportDepthTextureNode.js +39 -5
- package/src/nodes/display/ViewportSharedTextureNode.js +35 -1
- package/src/nodes/display/ViewportTextureNode.js +171 -7
- package/src/nodes/fog/Fog.js +97 -0
- package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
- package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +52 -0
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
- package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/LTC.js +45 -1
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
- package/src/nodes/functions/BasicLightingModel.js +28 -6
- package/src/nodes/functions/PhongLightingModel.js +36 -6
- package/src/nodes/functions/PhysicalLightingModel.js +336 -91
- package/src/nodes/functions/ShadowMaskModel.js +30 -3
- package/src/nodes/functions/ToonLightingModel.js +21 -2
- package/src/nodes/functions/VolumetricLightingModel.js +183 -0
- package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
- package/src/nodes/functions/material/getGeometryRoughness.js +10 -4
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
- package/src/nodes/geometry/RangeNode.js +97 -8
- package/src/nodes/gpgpu/AtomicFunctionNode.js +198 -23
- package/src/nodes/gpgpu/BarrierNode.js +52 -3
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +135 -6
- package/src/nodes/gpgpu/ComputeNode.js +212 -16
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +455 -0
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +143 -9
- package/src/nodes/lighting/AONode.js +18 -0
- package/src/nodes/lighting/AmbientLightNode.js +10 -0
- package/src/nodes/lighting/AnalyticLightNode.js +186 -399
- package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
- package/src/nodes/lighting/BasicLightMapNode.js +17 -0
- package/src/nodes/lighting/DirectionalLightNode.js +12 -11
- package/src/nodes/lighting/EnvironmentNode.js +59 -19
- package/src/nodes/lighting/HemisphereLightNode.js +33 -2
- package/src/nodes/lighting/IESSpotLightNode.js +13 -1
- package/src/nodes/lighting/IrradianceNode.js +17 -0
- package/src/nodes/lighting/LightProbeNode.js +20 -0
- package/src/nodes/lighting/LightUtils.js +11 -3
- package/src/nodes/lighting/LightingContextNode.js +52 -4
- package/src/nodes/lighting/LightingNode.js +15 -6
- package/src/nodes/lighting/LightsNode.js +238 -35
- package/src/nodes/lighting/PointLightNode.js +60 -25
- package/src/nodes/lighting/PointShadowNode.js +325 -0
- package/src/nodes/lighting/ProjectorLightNode.js +91 -0
- package/src/nodes/lighting/RectAreaLightNode.js +50 -14
- package/src/nodes/lighting/ShadowBaseNode.js +81 -0
- package/src/nodes/lighting/ShadowFilterNode.js +264 -0
- package/src/nodes/lighting/ShadowNode.js +867 -0
- package/src/nodes/lighting/SpotLightNode.js +99 -18
- package/src/nodes/materialx/MaterialXNodes.js +131 -2
- package/src/nodes/materialx/lib/mx_noise.js +166 -2
- package/src/nodes/math/BitcastNode.js +156 -0
- package/src/nodes/math/BitcountNode.js +433 -0
- package/src/nodes/math/ConditionalNode.js +110 -21
- package/src/nodes/math/Hash.js +8 -0
- package/src/nodes/math/MathNode.js +820 -97
- package/src/nodes/math/MathUtils.js +47 -1
- package/src/nodes/math/OperatorNode.js +517 -84
- package/src/nodes/math/PackFloatNode.js +98 -0
- package/src/nodes/math/TriNoise3D.js +17 -7
- package/src/nodes/math/UnpackFloatNode.js +96 -0
- package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
- package/src/nodes/parsers/GLSLNodeParser.js +11 -0
- package/src/nodes/pmrem/PMREMNode.js +180 -23
- package/src/nodes/pmrem/PMREMUtils.js +114 -5
- package/src/nodes/procedural/Checker.js +8 -0
- package/src/nodes/shapes/Shapes.js +33 -0
- package/src/nodes/tsl/TSLBase.js +10 -4
- package/src/nodes/tsl/TSLCore.js +732 -160
- package/src/nodes/utils/ArrayElementNode.js +55 -4
- package/src/nodes/utils/ConvertNode.js +31 -0
- package/src/nodes/utils/CubeMapNode.js +79 -2
- package/src/nodes/utils/DebugNode.js +83 -0
- package/src/nodes/utils/Discard.js +18 -2
- package/src/nodes/utils/EquirectUV.js +27 -0
- package/src/nodes/utils/EventNode.js +118 -0
- package/src/nodes/utils/FlipNode.js +38 -0
- package/src/nodes/utils/FunctionOverloadingNode.js +91 -22
- package/src/nodes/utils/JoinNode.js +57 -4
- package/src/nodes/utils/LoopNode.js +193 -55
- package/src/nodes/utils/MatcapUV.js +22 -0
- package/src/nodes/utils/MaxMipLevelNode.js +49 -1
- package/src/nodes/utils/MemberNode.js +120 -0
- package/src/nodes/utils/Oscillators.js +41 -0
- package/src/nodes/utils/Packing.js +30 -1
- package/src/nodes/utils/PostProcessingUtils.js +154 -0
- package/src/nodes/utils/RTTNode.js +165 -9
- package/src/nodes/utils/ReflectorNode.js +407 -21
- package/src/nodes/utils/RemapNode.js +81 -2
- package/src/nodes/utils/RotateNode.js +41 -1
- package/src/nodes/utils/SampleNode.js +91 -0
- package/src/nodes/utils/SetNode.js +44 -1
- package/src/nodes/utils/SplitNode.js +66 -3
- package/src/nodes/utils/SpriteSheetUV.js +35 -0
- package/src/nodes/utils/SpriteUtils.js +16 -0
- package/src/nodes/utils/StorageArrayElementNode.js +56 -3
- package/src/nodes/utils/Timer.js +26 -0
- package/src/nodes/utils/TriplanarTextures.js +65 -0
- package/src/nodes/utils/UVUtils.js +48 -0
- package/src/nodes/utils/ViewportUtils.js +12 -0
- package/src/objects/BatchedMesh.js +798 -309
- package/src/objects/Bone.js +24 -0
- package/src/objects/ClippingGroup.js +68 -0
- package/src/objects/Group.js +24 -0
- package/src/objects/InstancedMesh.js +131 -2
- package/src/objects/LOD.js +99 -5
- package/src/objects/Line.js +90 -7
- package/src/objects/LineLoop.js +20 -0
- package/src/objects/LineSegments.js +20 -1
- package/src/objects/Mesh.js +84 -0
- package/src/objects/Points.js +60 -0
- package/src/objects/Skeleton.js +120 -5
- package/src/objects/SkinnedMesh.js +102 -6
- package/src/objects/Sprite.js +65 -1
- package/src/renderers/WebGL3DRenderTarget.js +26 -0
- package/src/renderers/WebGLArrayRenderTarget.js +26 -0
- package/src/renderers/WebGLCubeRenderTarget.js +41 -5
- package/src/renderers/WebGLRenderTarget.js +19 -0
- package/src/renderers/WebGLRenderer.js +1016 -278
- package/src/renderers/common/Animation.js +123 -14
- package/src/renderers/common/Attributes.js +41 -1
- package/src/renderers/common/Backend.js +623 -44
- package/src/renderers/common/Background.js +99 -16
- package/src/renderers/common/BindGroup.js +37 -2
- package/src/renderers/common/Binding.js +46 -0
- package/src/renderers/common/Bindings.js +211 -20
- package/src/renderers/common/BlendMode.js +143 -0
- package/src/renderers/common/Buffer.js +89 -0
- package/src/renderers/common/BufferUtils.js +25 -0
- package/src/renderers/common/BundleGroup.js +57 -0
- package/src/renderers/common/CanvasTarget.js +341 -0
- package/src/renderers/common/ChainMap.js +73 -10
- package/src/renderers/common/ClippingContext.js +172 -87
- package/src/renderers/common/Color4.js +40 -0
- package/src/renderers/common/ComputePipeline.js +24 -0
- package/src/renderers/common/Constants.js +2 -1
- package/src/renderers/common/CubeRenderTarget.js +77 -7
- package/src/renderers/common/DataMap.js +37 -1
- package/src/renderers/common/Geometries.js +163 -14
- package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
- package/src/renderers/common/Info.js +81 -36
- package/src/renderers/common/InspectorBase.js +146 -0
- package/src/renderers/common/Lighting.js +57 -0
- package/src/renderers/common/Pipeline.js +22 -0
- package/src/renderers/common/Pipelines.js +150 -7
- package/src/renderers/common/PostProcessing.js +22 -84
- package/src/renderers/common/ProgrammableStage.js +60 -2
- package/src/renderers/common/QuadMesh.js +63 -6
- package/src/renderers/common/RenderBundle.js +14 -8
- package/src/renderers/common/RenderBundles.js +40 -10
- package/src/renderers/common/RenderContext.js +219 -4
- package/src/renderers/common/RenderContexts.js +54 -17
- package/src/renderers/common/RenderList.js +233 -24
- package/src/renderers/common/RenderLists.js +46 -6
- package/src/renderers/common/RenderObject.js +548 -46
- package/src/renderers/common/RenderObjectPipeline.js +40 -0
- package/src/renderers/common/RenderObjects.js +133 -15
- package/src/renderers/common/RenderPipeline.js +216 -6
- package/src/renderers/common/Renderer.js +2155 -332
- package/src/renderers/common/RendererUtils.js +200 -0
- package/src/renderers/common/SampledTexture.js +99 -39
- package/src/renderers/common/Sampler.js +148 -1
- package/src/renderers/common/Storage3DTexture.js +100 -0
- package/src/renderers/common/StorageArrayTexture.js +84 -0
- package/src/renderers/common/StorageBuffer.js +38 -2
- package/src/renderers/common/StorageBufferAttribute.js +31 -2
- package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
- package/src/renderers/common/StorageTexture.js +65 -0
- package/src/renderers/common/Textures.js +273 -57
- package/src/renderers/common/TimestampQueryPool.js +163 -0
- package/src/renderers/common/Uniform.js +233 -3
- package/src/renderers/common/UniformBuffer.js +19 -0
- package/src/renderers/common/UniformsGroup.js +235 -26
- package/src/renderers/common/XRManager.js +1677 -0
- package/src/renderers/common/XRRenderTarget.js +91 -0
- package/src/renderers/common/extras/PMREMGenerator.js +371 -108
- package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
- package/src/renderers/common/nodes/NodeLibrary.js +95 -17
- package/src/renderers/common/nodes/NodeManager.js +852 -0
- package/src/renderers/common/nodes/NodeSampledTexture.js +84 -8
- package/src/renderers/common/nodes/NodeSampler.js +41 -1
- package/src/renderers/common/nodes/NodeStorageBuffer.js +48 -3
- package/src/renderers/common/nodes/NodeUniform.js +285 -2
- package/src/renderers/common/nodes/NodeUniformBuffer.js +81 -0
- package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
- package/src/renderers/shaders/DFGLUTData.js +49 -0
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +0 -12
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +7 -11
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
- package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +154 -59
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
- package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +230 -181
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk.js +3 -3
- package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +14 -2
- package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib.js +7 -5
- package/src/renderers/shaders/UniformsLib.js +2 -7
- package/src/renderers/shaders/UniformsUtils.js +21 -2
- package/src/renderers/webgl/WebGLAttributes.js +4 -0
- package/src/renderers/webgl/WebGLBackground.js +30 -5
- package/src/renderers/webgl/WebGLBindingStates.js +99 -27
- package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLCapabilities.js +7 -14
- package/src/renderers/webgl/WebGLEnvironments.js +228 -0
- package/src/renderers/webgl/WebGLExtensions.js +2 -25
- package/src/renderers/webgl/WebGLGeometries.js +10 -35
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLInfo.js +3 -1
- package/src/renderers/webgl/WebGLLights.js +18 -1
- package/src/renderers/webgl/WebGLMaterials.js +12 -0
- package/src/renderers/webgl/WebGLObjects.js +3 -1
- package/src/renderers/webgl/WebGLOutput.js +267 -0
- package/src/renderers/webgl/WebGLProgram.js +87 -148
- package/src/renderers/webgl/WebGLPrograms.js +53 -51
- package/src/renderers/webgl/WebGLRenderLists.js +15 -0
- package/src/renderers/webgl/WebGLShadowMap.js +204 -28
- package/src/renderers/webgl/WebGLState.js +88 -56
- package/src/renderers/webgl/WebGLTextures.js +293 -59
- package/src/renderers/webgl/WebGLUniforms.js +40 -3
- package/src/renderers/webgl/WebGLUniformsGroups.js +5 -3
- package/src/renderers/webgl/WebGLUtils.js +7 -5
- package/src/renderers/webgl-fallback/WebGLBackend.js +1416 -293
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +785 -92
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +62 -1
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
- package/src/renderers/webgl-fallback/utils/WebGLConstants.js +3 -3
- package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +584 -20
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +468 -80
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +396 -0
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +72 -24
- package/src/renderers/webgpu/WebGPUBackend.js +1517 -428
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +31 -4
- package/src/renderers/webgpu/WebGPURenderer.js +55 -4
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +23 -16
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +37 -42
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +1335 -241
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +32 -4
- package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +144 -20
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +460 -116
- package/src/renderers/webgpu/utils/WebGPUConstants.js +17 -4
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +283 -69
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +225 -178
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +583 -191
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +310 -0
- package/src/renderers/webgpu/utils/WebGPUUtils.js +150 -28
- package/src/renderers/webxr/WebXRController.js +87 -2
- package/src/renderers/webxr/WebXRDepthSensing.js +52 -7
- package/src/renderers/webxr/WebXRManager.js +275 -15
- package/src/scenes/Fog.js +60 -0
- package/src/scenes/FogExp2.js +51 -0
- package/src/scenes/Scene.js +88 -0
- package/src/textures/CanvasTexture.js +28 -0
- package/src/textures/CompressedArrayTexture.js +57 -0
- package/src/textures/CompressedCubeTexture.js +29 -0
- package/src/textures/CompressedTexture.js +64 -6
- package/src/textures/CubeDepthTexture.js +76 -0
- package/src/textures/CubeTexture.js +52 -4
- package/src/textures/Data3DTexture.js +79 -2
- package/src/textures/DataArrayTexture.js +93 -0
- package/src/textures/DataTexture.js +65 -0
- package/src/textures/DepthTexture.js +59 -11
- package/src/textures/ExternalTexture.js +56 -0
- package/src/textures/FramebufferTexture.js +62 -0
- package/src/textures/Source.js +106 -4
- package/src/textures/Texture.js +488 -6
- package/src/textures/VideoFrameTexture.js +72 -0
- package/src/textures/VideoTexture.js +78 -6
- package/src/utils.js +322 -3
- package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
- package/examples/jsm/animation/MMDPhysics.js +0 -1406
- package/examples/jsm/cameras/CinematicCamera.js +0 -208
- package/examples/jsm/effects/PeppersGhostEffect.js +0 -153
- package/examples/jsm/exporters/MMDExporter.js +0 -217
- package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
- package/examples/jsm/geometries/ParametricGeometries.js +0 -254
- package/examples/jsm/libs/mmdparser.module.js +0 -11530
- package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +0 -729
- package/examples/jsm/loaders/MMDLoader.js +0 -2295
- package/examples/jsm/loaders/RGBMLoader.js +0 -1081
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -432
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -144
- package/examples/jsm/misc/Timer.js +0 -128
- package/examples/jsm/objects/InstancedPoints.js +0 -21
- package/examples/jsm/shaders/GodRaysShader.js +0 -321
- package/examples/jsm/shaders/MMDToonShader.js +0 -134
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -156
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -24
- package/src/nodes/accessors/SceneNode.js +0 -55
- package/src/nodes/code/ScriptableNode.js +0 -505
- package/src/nodes/code/ScriptableValueNode.js +0 -170
- package/src/nodes/core/CacheNode.js +0 -50
- package/src/nodes/core/UniformGroup.js +0 -13
- package/src/nodes/display/AfterImageNode.js +0 -158
- package/src/nodes/display/AnaglyphPassNode.js +0 -67
- package/src/nodes/display/AnamorphicNode.js +0 -151
- package/src/nodes/display/BlendMode.js +0 -54
- package/src/nodes/display/BloomNode.js +0 -341
- package/src/nodes/display/DenoiseNode.js +0 -204
- package/src/nodes/display/DepthOfFieldNode.js +0 -124
- package/src/nodes/display/DotScreenNode.js +0 -66
- package/src/nodes/display/FXAANode.js +0 -332
- package/src/nodes/display/FilmNode.js +0 -56
- package/src/nodes/display/GTAONode.js +0 -331
- package/src/nodes/display/GaussianBlurNode.js +0 -213
- package/src/nodes/display/Lut3DNode.js +0 -57
- package/src/nodes/display/MotionBlur.js +0 -25
- package/src/nodes/display/ParallaxBarrierPassNode.js +0 -58
- package/src/nodes/display/PixelationPassNode.js +0 -213
- package/src/nodes/display/PosterizeNode.js +0 -33
- package/src/nodes/display/RGBShiftNode.js +0 -53
- package/src/nodes/display/StereoCompositePassNode.js +0 -110
- package/src/nodes/display/TransitionNode.js +0 -80
- package/src/nodes/fog/FogExp2Node.js +0 -35
- package/src/nodes/fog/FogNode.js +0 -50
- package/src/nodes/fog/FogRangeNode.js +0 -36
- package/src/nodes/functions/BSDF/DFGApprox.js +0 -30
- package/src/nodes/utils/EquirectUVNode.js +0 -36
- package/src/nodes/utils/MatcapUVNode.js +0 -33
- package/src/nodes/utils/OscNode.js +0 -85
- package/src/nodes/utils/SpriteSheetUVNode.js +0 -45
- package/src/nodes/utils/TimerNode.js +0 -97
- package/src/nodes/utils/TriplanarTexturesNode.js +0 -64
- package/src/renderers/common/nodes/Nodes.js +0 -534
- package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
- package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -136
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright 2010-
|
|
3
|
+
* Copyright 2010-2026 Three.js Authors
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
*/
|
|
6
|
-
const e="169.20",t={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,N=201,A=202,C=203,R=204,E=205,B=206,I=207,P=208,F=209,z=210,U=211,O=212,L=213,V=214,D=0,k=1,G=2,W=3,H=4,j=5,q=6,$=7,X=0,Y=1,Z=2,J=0,K=1,Q=2,ee=3,te=4,se=5,ie=6,re=7,ne="attached",oe="detached",ae=300,he=301,ue=302,le=303,ce=304,de=306,pe=1e3,me=1001,ge=1002,fe=1003,ye=1004,xe=1004,be=1005,ve=1005,Te=1006,_e=1007,we=1007,Se=1008,Me=1008,Ne=1009,Ae=1010,Ce=1011,Re=1012,Ee=1013,Be=1014,Ie=1015,Pe=1016,Fe=1017,ze=1018,Ue=1020,Oe=35902,Le=35899,Ve=1021,De=1022,ke=1023,Ge=1024,We=1025,He=1026,je=1027,qe=1028,$e=1029,Xe=1030,Ye=1031,Ze=1032,Je=1033,Ke=33776,Qe=33777,et=33778,tt=33779,st=35840,it=35841,rt=35842,nt=35843,ot=36196,at=37492,ht=37496,ut=37808,lt=37809,ct=37810,dt=37811,pt=37812,mt=37813,gt=37814,ft=37815,yt=37816,xt=37817,bt=37818,vt=37819,Tt=37820,_t=37821,wt=36492,St=36494,Mt=36495,Nt=36283,At=36284,Ct=36285,Rt=36286,Et=2200,Bt=2201,It=2202,Pt=2300,Ft=2301,zt=2302,Ut=2400,Ot=2401,Lt=2402,Vt=2500,Dt=2501,kt=0,Gt=1,Wt=2,Ht=3200,jt=3201,qt=3202,$t=3203,Xt=0,Yt=1,Zt="",Jt="srgb",Kt="srgb-linear",Qt="display-p3",es="display-p3-linear",ts="linear",ss="srgb",is="rec709",rs="p3",ns=0,os=7680,as=7681,hs=7682,us=7683,ls=34055,cs=34056,ds=5386,ps=512,ms=513,gs=514,fs=515,ys=516,xs=517,bs=518,vs=519,Ts=512,_s=513,ws=514,Ss=515,Ms=516,Ns=517,As=518,Cs=519,Rs=35044,Es=35048,Bs=35040,Is=35045,Ps=35049,Fs=35041,zs=35046,Us=35050,Os=35042,Ls="100",Vs="300 es",Ds=2e3,ks=2001;class Gs{addEventListener(e,t){void 0===this._listeners&&(this._listeners={});const s=this._listeners;void 0===s[e]&&(s[e]=[]),-1===s[e].indexOf(t)&&s[e].push(t)}hasEventListener(e,t){if(void 0===this._listeners)return!1;const s=this._listeners;return void 0!==s[e]&&-1!==s[e].indexOf(t)}removeEventListener(e,t){if(void 0===this._listeners)return;const s=this._listeners[e];if(void 0!==s){const e=s.indexOf(t);-1!==e&&s.splice(e,1)}}dispatchEvent(e){if(void 0===this._listeners)return;const t=this._listeners[e.type];if(void 0!==t){e.target=this;const s=t.slice(0);for(let t=0,i=s.length;t<i;t++)s[t].call(this,e);e.target=null}}}const Ws=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let Hs=1234567;const js=Math.PI/180,qs=180/Math.PI;function $s(){const e=4294967295*Math.random()|0,t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(Ws[255&e]+Ws[e>>8&255]+Ws[e>>16&255]+Ws[e>>24&255]+"-"+Ws[255&t]+Ws[t>>8&255]+"-"+Ws[t>>16&15|64]+Ws[t>>24&255]+"-"+Ws[63&s|128]+Ws[s>>8&255]+"-"+Ws[s>>16&255]+Ws[s>>24&255]+Ws[255&i]+Ws[i>>8&255]+Ws[i>>16&255]+Ws[i>>24&255]).toLowerCase()}function Xs(e,t,s){return Math.max(t,Math.min(s,e))}function Ys(e,t){return(e%t+t)%t}function Zs(e,t,s){return(1-s)*e+s*t}function Js(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return e/4294967295;case Uint16Array:return e/65535;case Uint8Array:return e/255;case Int32Array:return Math.max(e/2147483647,-1);case Int16Array:return Math.max(e/32767,-1);case Int8Array:return Math.max(e/127,-1);default:throw new Error("Invalid component type.")}}function Ks(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return Math.round(4294967295*e);case Uint16Array:return Math.round(65535*e);case Uint8Array:return Math.round(255*e);case Int32Array:return Math.round(2147483647*e);case Int16Array:return Math.round(32767*e);case Int8Array:return Math.round(127*e);default:throw new Error("Invalid component type.")}}const Qs={DEG2RAD:js,RAD2DEG:qs,generateUUID:$s,clamp:Xs,euclideanModulo:Ys,mapLinear:function(e,t,s,i,r){return i+(e-t)*(r-i)/(s-t)},inverseLerp:function(e,t,s){return e!==t?(s-e)/(t-e):0},lerp:Zs,damp:function(e,t,s,i){return Zs(e,t,1-Math.exp(-s*i))},pingpong:function(e,t=1){return t-Math.abs(Ys(e,2*t)-t)},smoothstep:function(e,t,s){return e<=t?0:e>=s?1:(e=(e-t)/(s-t))*e*(3-2*e)},smootherstep:function(e,t,s){return e<=t?0:e>=s?1:(e=(e-t)/(s-t))*e*e*(e*(6*e-15)+10)},randInt:function(e,t){return e+Math.floor(Math.random()*(t-e+1))},randFloat:function(e,t){return e+Math.random()*(t-e)},randFloatSpread:function(e){return e*(.5-Math.random())},seededRandom:function(e){void 0!==e&&(Hs=e);let t=Hs+=1831565813;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296},degToRad:function(e){return e*js},radToDeg:function(e){return e*qs},isPowerOfTwo:function(e){return!(e&e-1)&&0!==e},ceilPowerOfTwo:function(e){return Math.pow(2,Math.ceil(Math.log(e)/Math.LN2))},floorPowerOfTwo:function(e){return Math.pow(2,Math.floor(Math.log(e)/Math.LN2))},setQuaternionFromProperEuler:function(e,t,s,i,r){const n=Math.cos,o=Math.sin,a=n(s/2),h=o(s/2),u=n((t+i)/2),l=o((t+i)/2),c=n((t-i)/2),d=o((t-i)/2),p=n((i-t)/2),m=o((i-t)/2);switch(r){case"XYX":e.set(a*l,h*c,h*d,a*u);break;case"YZY":e.set(h*d,a*l,h*c,a*u);break;case"ZXZ":e.set(h*c,h*d,a*l,a*u);break;case"XZX":e.set(a*l,h*m,h*p,a*u);break;case"YXY":e.set(h*p,a*l,h*m,a*u);break;case"ZYZ":e.set(h*m,h*p,a*l,a*u);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:Ks,denormalize:Js};class ei{constructor(e=0,t=0){ei.prototype.isVector2=!0,this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,s=this.y,i=e.elements;return this.x=i[0]*t+i[3]*s+i[6],this.y=i[1]*t+i[4]*s+i[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this}clampLength(e,t){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(e,Math.min(t,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(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.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(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(0===t)return Math.PI/2;const s=this.dot(e)/t;return Math.acos(Xs(s,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,s=this.y-e.y;return t*t+s*s}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,s){return this.x=e.x+(t.x-e.x)*s,this.y=e.y+(t.y-e.y)*s,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const s=Math.cos(t),i=Math.sin(t),r=this.x-e.x,n=this.y-e.y;return this.x=r*s-n*i+e.x,this.y=r*i+n*s+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class ti{constructor(e,t,s,i,r,n,o,a,h){ti.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==e&&this.set(e,t,s,i,r,n,o,a,h)}set(e,t,s,i,r,n,o,a,h){const u=this.elements;return u[0]=e,u[1]=i,u[2]=o,u[3]=t,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(e){const t=this.elements,s=e.elements;return t[0]=s[0],t[1]=s[1],t[2]=s[2],t[3]=s[3],t[4]=s[4],t[5]=s[5],t[6]=s[6],t[7]=s[7],t[8]=s[8],this}extractBasis(e,t,s){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),s.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const s=e.elements,i=t.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(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],s=e[1],i=e[2],r=e[3],n=e[4],o=e[5],a=e[6],h=e[7],u=e[8];return t*n*u-t*o*h-s*r*u+s*o*a+i*r*h-i*n*a}invert(){const e=this.elements,t=e[0],s=e[1],i=e[2],r=e[3],n=e[4],o=e[5],a=e[6],h=e[7],u=e[8],l=u*n-o*h,c=o*a-u*r,d=h*r-n*a,p=t*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 e[0]=l*m,e[1]=(i*h-u*s)*m,e[2]=(o*s-i*n)*m,e[3]=c*m,e[4]=(u*t-i*a)*m,e[5]=(i*r-o*t)*m,e[6]=d*m,e[7]=(s*a-h*t)*m,e[8]=(n*t-s*r)*m,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,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+e,-i*h,i*a,-i*(-h*n+a*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(si.makeScale(e,t)),this}rotate(e){return this.premultiply(si.makeRotation(-e)),this}translate(e,t){return this.premultiply(si.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),s=Math.sin(e);return this.set(t,-s,0,s,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,s=e.elements;for(let e=0;e<9;e++)if(t[e]!==s[e])return!1;return!0}fromArray(e,t=0){for(let s=0;s<9;s++)this.elements[s]=e[s+t];return this}toArray(e=[],t=0){const s=this.elements;return e[t]=s[0],e[t+1]=s[1],e[t+2]=s[2],e[t+3]=s[3],e[t+4]=s[4],e[t+5]=s[5],e[t+6]=s[6],e[t+7]=s[7],e[t+8]=s[8],e}clone(){return(new this.constructor).fromArray(this.elements)}}const si=new ti;const ii={Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array};function ri(e,t){return new ii[e](t)}function ni(e){return document.createElementNS("http://www.w3.org/1999/xhtml",e)}function oi(){const e=ni("canvas");return e.style.display="block",e}const ai={};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={[Kt]:{transfer:ts,primaries:is,luminanceCoefficients:[.2126,.7152,.0722],toReference:e=>e,fromReference:e=>e},[Jt]:{transfer:ss,primaries:is,luminanceCoefficients:[.2126,.7152,.0722],toReference:e=>e.convertSRGBToLinear(),fromReference:e=>e.convertLinearToSRGB()},[es]:{transfer:ts,primaries:rs,luminanceCoefficients:[.2289,.6917,.0793],toReference:e=>e.applyMatrix3(ui),fromReference:e=>e.applyMatrix3(hi)},[Qt]:{transfer:ss,primaries:rs,luminanceCoefficients:[.2289,.6917,.0793],toReference:e=>e.convertSRGBToLinear().applyMatrix3(ui),fromReference:e=>e.applyMatrix3(hi).convertLinearToSRGB()}},ci=new Set([Kt,es]),di={enabled:!0,_workingColorSpace:Kt,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(e){if(!ci.has(e))throw new Error(`Unsupported working color space, "${e}".`);this._workingColorSpace=e},convert:function(e,t,s){if(!1===this.enabled||t===s||!t||!s)return e;const i=li[t].toReference;return(0,li[s].fromReference)(i(e))},fromWorkingColorSpace:function(e,t){return this.convert(e,this._workingColorSpace,t)},toWorkingColorSpace:function(e,t){return this.convert(e,t,this._workingColorSpace)},getPrimaries:function(e){return li[e].primaries},getTransfer:function(e){return e===Zt?ts:li[e].transfer},getLuminanceCoefficients:function(e,t=this._workingColorSpace){return e.fromArray(li[t].luminanceCoefficients)}};function pi(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}function mi(e){return e<.0031308?12.92*e:1.055*Math.pow(e,.41666)-.055}let gi;class fi{static getDataURL(e){if(/^data:/i.test(e.src))return e.src;if("undefined"==typeof HTMLCanvasElement)return e.src;let t;if(e instanceof HTMLCanvasElement)t=e;else{void 0===gi&&(gi=ni("canvas")),gi.width=e.width,gi.height=e.height;const s=gi.getContext("2d");e instanceof ImageData?s.putImageData(e,0,0):s.drawImage(e,0,0,e.width,e.height),t=gi}return t.width>2048||t.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",e),t.toDataURL("image/jpeg",.6)):t.toDataURL("image/png")}static sRGBToLinear(e){if("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap){const t=ni("canvas");t.width=e.width,t.height=e.height;const s=t.getContext("2d");s.drawImage(e,0,0,e.width,e.height);const i=s.getImageData(0,0,e.width,e.height),r=i.data;for(let e=0;e<r.length;e++)r[e]=255*pi(r[e]/255);return s.putImageData(i,0,0),t}if(e.data){const t=e.data.slice(0);for(let e=0;e<t.length;e++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[e]=Math.floor(255*pi(t[e]/255)):t[e]=pi(t[e]);return{data:t,width:e.width,height:e.height}}return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}}let yi=0;class xi{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:yi++}),this.uuid=$s(),this.data=e,this.dataReady=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}toJSON(e){const t=void 0===e||"string"==typeof e;if(!t&&void 0!==e.images[this.uuid])return e.images[this.uuid];const s={uuid:this.uuid,url:""},i=this.data;if(null!==i){let e;if(Array.isArray(i)){e=[];for(let t=0,s=i.length;t<s;t++)i[t].isDataTexture?e.push(bi(i[t].image)):e.push(bi(i[t]))}else e=bi(i);s.url=e}return t||(e.images[this.uuid]=s),s}}function bi(e){return"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap?fi.getDataURL(e):e.data?{data:Array.from(e.data),width:e.width,height:e.height,type:e.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}let vi=0;class Ti extends Gs{constructor(e=Ti.DEFAULT_IMAGE,t=Ti.DEFAULT_MAPPING,s=1001,i=1001,r=1006,n=1008,o=1023,a=1009,h=Ti.DEFAULT_ANISOTROPY,u=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:vi++}),this.uuid=$s(),this.name="",this.source=new xi(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=s,this.wrapT=i,this.magFilter=r,this.minFilter=n,this.anisotropy=h,this.format=o,this.internalFormat=null,this.type=a,this.offset=new ei(0,0),this.repeat=new ei(1,1),this.center=new ei(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new ti,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=u,this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1,this.pmremVersion=0}get image(){return this.source.data}set image(e=null){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}clone(){return(new this.constructor).copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}toJSON(e){const t=void 0===e||"string"==typeof e;if(!t&&void 0!==e.textures[this.uuid])return e.textures[this.uuid];const s={metadata:{version:4.6,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(s.userData=this.userData),t||(e.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==ae)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case pe:e.x=e.x-Math.floor(e.x);break;case me:e.x=e.x<0?0:1;break;case ge:1===Math.abs(Math.floor(e.x)%2)?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x)}if(e.y<0||e.y>1)switch(this.wrapT){case pe:e.y=e.y-Math.floor(e.y);break;case me:e.y=e.y<0?0:1;break;case ge:1===Math.abs(Math.floor(e.y)%2)?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y)}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){!0===e&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){!0===e&&this.pmremVersion++}}Ti.DEFAULT_IMAGE=null,Ti.DEFAULT_MAPPING=ae,Ti.DEFAULT_ANISOTROPY=4;class _i{constructor(e=0,t=0,s=0,i=1){_i.prototype.isVector4=!0,this.x=e,this.y=t,this.z=s,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,s,i){return this.x=e,this.y=t,this.z=s,this.w=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){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: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=void 0!==e.w?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,s=this.y,i=this.z,r=this.w,n=e.elements;return this.x=n[0]*t+n[4]*s+n[8]*i+n[12]*r,this.y=n[1]*t+n[5]*s+n[9]*i+n[13]*r,this.z=n[2]*t+n[6]*s+n[10]*i+n[14]*r,this.w=n[3]*t+n[7]*s+n[11]*i+n[15]*r,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,s,i,r;const n=.01,o=.1,a=e.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)<n&&Math.abs(l-m)<n&&Math.abs(p-g)<n){if(Math.abs(u+c)<o&&Math.abs(l+m)<o&&Math.abs(p+g)<o&&Math.abs(h+d+f-3)<o)return this.set(1,0,0,0),this;t=Math.PI;const e=(h+1)/2,a=(d+1)/2,y=(f+1)/2,x=(u+c)/4,b=(l+m)/4,v=(p+g)/4;return e>a&&e>y?e<n?(s=0,i=.707106781,r=.707106781):(s=Math.sqrt(e),i=x/s,r=b/s):a>y?a<n?(s=.707106781,i=0,r=.707106781):(i=Math.sqrt(a),s=x/i,r=v/i):y<n?(s=.707106781,i=.707106781,r=0):(r=Math.sqrt(y),s=b/r,i=v/r),this.set(s,i,r,t),this}let y=Math.sqrt((g-p)*(g-p)+(l-m)*(l-m)+(c-u)*(c-u));return Math.abs(y)<.001&&(y=1),this.x=(g-p)/y,this.y=(l-m)/y,this.z=(c-u)/y,this.w=Math.acos((h+d+f-1)/2),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this.w=Math.max(e.w,Math.min(t.w,this.w)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this.w=Math.max(e,Math.min(t,this.w)),this}clampLength(e,t){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(e,Math.min(t,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.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)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,s){return this.x=e.x+(t.x-e.x)*s,this.y=e.y+(t.y-e.y)*s,this.z=e.z+(t.z-e.z)*s,this.w=e.w+(t.w-e.w)*s,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class wi extends Gs{constructor(e=1,t=1,s={}){super(),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=1,this.scissor=new _i(0,0,e,t),this.scissorTest=!1,this.viewport=new _i(0,0,e,t);const i={width:e,height:t,depth:1};s=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Te,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},s);const r=new Ti(i,s.mapping,s.wrapS,s.wrapT,s.magFilter,s.minFilter,s.format,s.type,s.anisotropy,s.colorSpace);r.flipY=!1,r.generateMipmaps=s.generateMipmaps,r.internalFormat=s.internalFormat,this.textures=[];const n=s.count;for(let e=0;e<n;e++)this.textures[e]=r.clone(),this.textures[e].isRenderTargetTexture=!0;this.depthBuffer=s.depthBuffer,this.stencilBuffer=s.stencilBuffer,this.resolveDepthBuffer=s.resolveDepthBuffer,this.resolveStencilBuffer=s.resolveStencilBuffer,this.depthTexture=s.depthTexture,this.samples=s.samples}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}setSize(e,t,s=1){if(this.width!==e||this.height!==t||this.depth!==s){this.width=e,this.height=t,this.depth=s;for(let i=0,r=this.textures.length;i<r;i++)this.textures[i].image.width=e,this.textures[i].image.height=t,this.textures[i].image.depth=s;this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return(new this.constructor).copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,s=e.textures.length;t<s;t++)this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0;const t=Object.assign({},e.texture.image);return this.texture.source=new xi(t),this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,null!==e.depthTexture&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Si extends wi{constructor(e=1,t=1,s={}){super(e,t,s),this.isWebGLRenderTarget=!0}}class Mi extends Ti{constructor(e=null,t=1,s=1,i=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:s,depth:i},this.magFilter=fe,this.minFilter=fe,this.wrapR=me,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}}class Ni extends Si{constructor(e=1,t=1,s=1,i={}){super(e,t,i),this.isWebGLArrayRenderTarget=!0,this.depth=s,this.texture=new Mi(null,e,t,s),this.texture.isRenderTargetTexture=!0}}class Ai extends Ti{constructor(e=null,t=1,s=1,i=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:s,depth:i},this.magFilter=fe,this.minFilter=fe,this.wrapR=me,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Ci extends Si{constructor(e=1,t=1,s=1,i={}){super(e,t,i),this.isWebGL3DRenderTarget=!0,this.depth=s,this.texture=new Ai(null,e,t,s),this.texture.isRenderTargetTexture=!0}}class Ri{constructor(e=0,t=0,s=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=s,this._w=i}static slerpFlat(e,t,s,i,r,n,o){let a=s[i+0],h=s[i+1],u=s[i+2],l=s[i+3];const c=r[n+0],d=r[n+1],p=r[n+2],m=r[n+3];if(0===o)return e[t+0]=a,e[t+1]=h,e[t+2]=u,void(e[t+3]=l);if(1===o)return e[t+0]=c,e[t+1]=d,e[t+2]=p,void(e[t+3]=m);if(l!==m||a!==c||h!==d||u!==p){let e=1-o;const t=a*c+h*d+u*p+l*m,s=t>=0?1:-1,i=1-t*t;if(i>Number.EPSILON){const r=Math.sqrt(i),n=Math.atan2(r,t*s);e=Math.sin(e*n)/r,o=Math.sin(o*n)/r}const r=o*s;if(a=a*e+c*r,h=h*e+d*r,u=u*e+p*r,l=l*e+m*r,e===1-o){const e=1/Math.sqrt(a*a+h*h+u*u+l*l);a*=e,h*=e,u*=e,l*=e}}e[t]=a,e[t+1]=h,e[t+2]=u,e[t+3]=l}static multiplyQuaternionsFlat(e,t,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 e[t]=o*p+u*l+a*d-h*c,e[t+1]=a*p+u*c+h*l-o*d,e[t+2]=h*p+u*d+o*c-a*l,e[t+3]=u*p-o*l-a*c-h*d,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,s,i){return this._x=e,this._y=t,this._z=s,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const s=e._x,i=e._y,r=e._z,n=e._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===t&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const s=t/2,i=Math.sin(s);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,s=t[0],i=t[4],r=t[8],n=t[1],o=t[5],a=t[9],h=t[2],u=t[6],l=t[10],c=s+o+l;if(c>0){const e=.5/Math.sqrt(c+1);this._w=.25/e,this._x=(u-a)*e,this._y=(r-h)*e,this._z=(n-i)*e}else if(s>o&&s>l){const e=2*Math.sqrt(1+s-o-l);this._w=(u-a)/e,this._x=.25*e,this._y=(i+n)/e,this._z=(r+h)/e}else if(o>l){const e=2*Math.sqrt(1+o-s-l);this._w=(r-h)/e,this._x=(i+n)/e,this._y=.25*e,this._z=(a+u)/e}else{const e=2*Math.sqrt(1+l-s-o);this._w=(n-i)/e,this._x=(r+h)/e,this._y=(a+u)/e,this._z=.25*e}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let s=e.dot(t)+1;return s<Number.EPSILON?(s=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=s):(this._x=0,this._y=-e.z,this._z=e.y,this._w=s)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=s),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(Xs(this.dot(e),-1,1)))}rotateTowards(e,t){const s=this.angleTo(e);if(0===s)return this;const i=Math.min(1,t/s);return this.slerp(e,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(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._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 e=this.length();return 0===e?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const s=e._x,i=e._y,r=e._z,n=e._w,o=t._x,a=t._y,h=t._z,u=t._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(e,t){if(0===t)return this;if(1===t)return this.copy(e);const s=this._x,i=this._y,r=this._z,n=this._w;let o=n*e._w+s*e._x+i*e._y+r*e._z;if(o<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,o=-o):this.copy(e),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 e=1-t;return this._w=e*n+t*this._w,this._x=e*s+t*this._x,this._y=e*i+t*this._y,this._z=e*r+t*this._z,this.normalize(),this}const h=Math.sqrt(a),u=Math.atan2(h,o),l=Math.sin((1-t)*u)/h,c=Math.sin(t*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(e,t,s){return this.copy(e).slerp(t,s)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);return this.set(i*Math.sin(e),i*Math.cos(e),r*Math.sin(t),r*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class Ei{constructor(e=0,t=0,s=0){Ei.prototype.isVector3=!0,this.x=e,this.y=t,this.z=s}set(e,t,s){return void 0===s&&(s=this.z),this.x=e,this.y=t,this.z=s,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Ii.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Ii.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,s=this.y,i=this.z,r=e.elements;return this.x=r[0]*t+r[3]*s+r[6]*i,this.y=r[1]*t+r[4]*s+r[7]*i,this.z=r[2]*t+r[5]*s+r[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,s=this.y,i=this.z,r=e.elements,n=1/(r[3]*t+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*t+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*t+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*t+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(e){const t=this.x,s=this.y,i=this.z,r=e.x,n=e.y,o=e.z,a=e.w,h=2*(n*i-o*s),u=2*(o*t-r*i),l=2*(r*s-n*t);return this.x=t+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(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,s=this.y,i=this.z,r=e.elements;return this.x=r[0]*t+r[4]*s+r[8]*i,this.y=r[1]*t+r[5]*s+r[9]*i,this.z=r[2]*t+r[6]*s+r[10]*i,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this}clampLength(e,t){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(e,Math.min(t,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(e){return this.x*e.x+this.y*e.y+this.z*e.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(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,s){return this.x=e.x+(t.x-e.x)*s,this.y=e.y+(t.y-e.y)*s,this.z=e.z+(t.z-e.z)*s,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const s=e.x,i=e.y,r=e.z,n=t.x,o=t.y,a=t.z;return this.x=i*a-r*o,this.y=r*n-s*a,this.z=s*o-i*n,this}projectOnVector(e){const t=e.lengthSq();if(0===t)return this.set(0,0,0);const s=e.dot(this)/t;return this.copy(e).multiplyScalar(s)}projectOnPlane(e){return Bi.copy(this).projectOnVector(e),this.sub(Bi)}reflect(e){return this.sub(Bi.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(0===t)return Math.PI/2;const s=this.dot(e)/t;return Math.acos(Xs(s,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,s=this.y-e.y,i=this.z-e.z;return t*t+s*s+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,s){const i=Math.sin(t)*e;return this.x=i*Math.sin(s),this.y=Math.cos(t)*e,this.z=i*Math.cos(s),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,s){return this.x=e*Math.sin(t),this.y=s,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),s=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=s,this.z=i,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,4*t)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,3*t)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=2*Math.random()-1,s=Math.sqrt(1-t*t);return this.x=s*Math.cos(e),this.y=t,this.z=s*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Bi=new Ei,Ii=new Ri;class Pi{constructor(e=new Ei(1/0,1/0,1/0),t=new Ei(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,s=e.length;t<s;t+=3)this.expandByPoint(zi.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,s=e.count;t<s;t++)this.expandByPoint(zi.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,s=e.length;t<s;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){const s=zi.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(s),this.max.copy(e).add(s),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return(new this.constructor).copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);const s=e.geometry;if(void 0!==s){const i=s.getAttribute("position");if(!0===t&&void 0!==i&&!0!==e.isInstancedMesh)for(let t=0,s=i.count;t<s;t++)!0===e.isMesh?e.getVertexPosition(t,zi):zi.fromBufferAttribute(i,t),zi.applyMatrix4(e.matrixWorld),this.expandByPoint(zi);else void 0!==e.boundingBox?(null===e.boundingBox&&e.computeBoundingBox(),Ui.copy(e.boundingBox)):(null===s.boundingBox&&s.computeBoundingBox(),Ui.copy(s.boundingBox)),Ui.applyMatrix4(e.matrixWorld),this.union(Ui)}const i=e.children;for(let e=0,s=i.length;e<s;e++)this.expandByObject(i[e],t);return this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,zi),zi.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,s;return e.normal.x>0?(t=e.normal.x*this.min.x,s=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,s=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,s+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,s+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,s+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,s+=e.normal.z*this.min.z),t<=-e.constant&&s>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(Wi),Hi.subVectors(this.max,Wi),Oi.subVectors(e.a,Wi),Li.subVectors(e.b,Wi),Vi.subVectors(e.c,Wi),Di.subVectors(Li,Oi),ki.subVectors(Vi,Li),Gi.subVectors(Oi,Vi);let t=[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(t,Oi,Li,Vi,Hi)&&(t=[1,0,0,0,1,0,0,0,1],!!$i(t,Oi,Li,Vi,Hi)&&(ji.crossVectors(Di,ki),t=[ji.x,ji.y,ji.z],$i(t,Oi,Li,Vi,Hi)))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,zi).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=.5*this.getSize(zi).length()),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()||(Fi[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Fi[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Fi[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Fi[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Fi[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Fi[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Fi[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Fi[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Fi)),this}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}}const Fi=[new Ei,new Ei,new Ei,new Ei,new Ei,new Ei,new Ei,new Ei],zi=new Ei,Ui=new Pi,Oi=new Ei,Li=new Ei,Vi=new Ei,Di=new Ei,ki=new Ei,Gi=new Ei,Wi=new Ei,Hi=new Ei,ji=new Ei,qi=new Ei;function $i(e,t,s,i,r){for(let n=0,o=e.length-3;n<=o;n+=3){qi.fromArray(e,n);const o=r.x*Math.abs(qi.x)+r.y*Math.abs(qi.y)+r.z*Math.abs(qi.z),a=t.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,Zi=new Ei;class Ji{constructor(e=new Ei,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){const s=this.center;void 0!==t?s.copy(t):Xi.setFromPoints(e).getCenter(s);let i=0;for(let t=0,r=e.length;t<r;t++)i=Math.max(i,s.distanceToSquared(e[t]));return this.radius=Math.sqrt(i),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){const t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){const s=this.center.distanceToSquared(e);return t.copy(e),s>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;Yi.subVectors(e,this.center);const t=Yi.lengthSq();if(t>this.radius*this.radius){const e=Math.sqrt(t),s=.5*(e-this.radius);this.center.addScaledVector(Yi,s/e),this.radius+=s}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(!0===this.center.equals(e.center)?this.radius=Math.max(this.radius,e.radius):(Zi.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(Yi.copy(e.center).add(Zi)),this.expandByPoint(Yi.copy(e.center).sub(Zi))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const Ki=new Ei,Qi=new Ei,er=new Ei,tr=new Ei,sr=new Ei,ir=new Ei,rr=new Ei;class nr{constructor(e=new Ei,t=new Ei(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,Ki)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);const s=t.dot(this.direction);return s<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,s)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const t=Ki.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(Ki.copy(this.origin).addScaledVector(this.direction,t),Ki.distanceToSquared(e))}distanceSqToSegment(e,t,s,i){Qi.copy(e).add(t).multiplyScalar(.5),er.copy(t).sub(e).normalize(),tr.copy(this.origin).sub(Qi);const r=.5*e.distanceTo(t),n=-this.direction.dot(er),o=tr.dot(this.direction),a=-tr.dot(er),h=tr.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 e=1/u;l*=e,c*=e,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(Qi).addScaledVector(er,c),d}intersectSphere(e,t){Ki.subVectors(e.center,this.origin);const s=Ki.dot(this.direction),i=Ki.dot(Ki)-s*s,r=e.radius*e.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,t):this.at(o,t)}intersectsSphere(e){return this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const t=e.normal.dot(this.direction);if(0===t)return 0===e.distanceToPoint(this.origin)?0:null;const s=-(this.origin.dot(e.normal)+e.constant)/t;return s>=0?s:null}intersectPlane(e,t){const s=this.distanceToPlane(e);return null===s?null:this.at(s,t)}intersectsPlane(e){const t=e.distanceToPoint(this.origin);if(0===t)return!0;return e.normal.dot(this.direction)*t<0}intersectBox(e,t){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=(e.min.x-c.x)*h,i=(e.max.x-c.x)*h):(s=(e.max.x-c.x)*h,i=(e.min.x-c.x)*h),u>=0?(r=(e.min.y-c.y)*u,n=(e.max.y-c.y)*u):(r=(e.max.y-c.y)*u,n=(e.min.y-c.y)*u),s>n||r>i?null:((r>s||isNaN(s))&&(s=r),(n<i||isNaN(i))&&(i=n),l>=0?(o=(e.min.z-c.z)*l,a=(e.max.z-c.z)*l):(o=(e.max.z-c.z)*l,a=(e.min.z-c.z)*l),s>a||o>i?null:((o>s||s!=s)&&(s=o),(a<i||i!=i)&&(i=a),i<0?null:this.at(s>=0?s:i,t)))}intersectsBox(e){return null!==this.intersectBox(e,Ki)}intersectTriangle(e,t,s,i,r){sr.subVectors(t,e),ir.subVectors(s,e),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}tr.subVectors(this.origin,e);const a=n*this.direction.dot(ir.crossVectors(tr,ir));if(a<0)return null;const h=n*this.direction.dot(sr.cross(tr));if(h<0)return null;if(a+h>o)return null;const u=-n*tr.dot(rr);return u<0?null:this.at(u/o,r)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class or{constructor(e,t,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!==e&&this.set(e,t,s,i,r,n,o,a,h,u,l,c,d,p,m,g)}set(e,t,s,i,r,n,o,a,h,u,l,c,d,p,m,g){const f=this.elements;return f[0]=e,f[4]=t,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(e){const t=this.elements,s=e.elements;return t[0]=s[0],t[1]=s[1],t[2]=s[2],t[3]=s[3],t[4]=s[4],t[5]=s[5],t[6]=s[6],t[7]=s[7],t[8]=s[8],t[9]=s[9],t[10]=s[10],t[11]=s[11],t[12]=s[12],t[13]=s[13],t[14]=s[14],t[15]=s[15],this}copyPosition(e){const t=this.elements,s=e.elements;return t[12]=s[12],t[13]=s[13],t[14]=s[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,s){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this}makeBasis(e,t,s){return this.set(e.x,t.x,s.x,0,e.y,t.y,s.y,0,e.z,t.z,s.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,s=e.elements,i=1/ar.setFromMatrixColumn(e,0).length(),r=1/ar.setFromMatrixColumn(e,1).length(),n=1/ar.setFromMatrixColumn(e,2).length();return t[0]=s[0]*i,t[1]=s[1]*i,t[2]=s[2]*i,t[3]=0,t[4]=s[4]*r,t[5]=s[5]*r,t[6]=s[6]*r,t[7]=0,t[8]=s[8]*n,t[9]=s[9]*n,t[10]=s[10]*n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,s=e.x,i=e.y,r=e.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"===e.order){const e=n*u,s=n*l,i=o*u,r=o*l;t[0]=a*u,t[4]=-a*l,t[8]=h,t[1]=s+i*h,t[5]=e-r*h,t[9]=-o*a,t[2]=r-e*h,t[6]=i+s*h,t[10]=n*a}else if("YXZ"===e.order){const e=a*u,s=a*l,i=h*u,r=h*l;t[0]=e+r*o,t[4]=i*o-s,t[8]=n*h,t[1]=n*l,t[5]=n*u,t[9]=-o,t[2]=s*o-i,t[6]=r+e*o,t[10]=n*a}else if("ZXY"===e.order){const e=a*u,s=a*l,i=h*u,r=h*l;t[0]=e-r*o,t[4]=-n*l,t[8]=i+s*o,t[1]=s+i*o,t[5]=n*u,t[9]=r-e*o,t[2]=-n*h,t[6]=o,t[10]=n*a}else if("ZYX"===e.order){const e=n*u,s=n*l,i=o*u,r=o*l;t[0]=a*u,t[4]=i*h-s,t[8]=e*h+r,t[1]=a*l,t[5]=r*h+e,t[9]=s*h-i,t[2]=-h,t[6]=o*a,t[10]=n*a}else if("YZX"===e.order){const e=n*a,s=n*h,i=o*a,r=o*h;t[0]=a*u,t[4]=r-e*l,t[8]=i*l+s,t[1]=l,t[5]=n*u,t[9]=-o*u,t[2]=-h*u,t[6]=s*l+i,t[10]=e-r*l}else if("XZY"===e.order){const e=n*a,s=n*h,i=o*a,r=o*h;t[0]=a*u,t[4]=-l,t[8]=h*u,t[1]=e*l+r,t[5]=n*u,t[9]=s*l-i,t[2]=i*l-s,t[6]=o*u,t[10]=r*l+e}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(ur,e,lr)}lookAt(e,t,s){const i=this.elements;return pr.subVectors(e,t),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(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const s=e.elements,i=t.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],N=i[5],A=i[9],C=i[13],R=i[2],E=i[6],B=i[10],I=i[14],P=i[3],F=i[7],z=i[11],U=i[15];return r[0]=n*T+o*M+a*R+h*P,r[4]=n*_+o*N+a*E+h*F,r[8]=n*w+o*A+a*B+h*z,r[12]=n*S+o*C+a*I+h*U,r[1]=u*T+l*M+c*R+d*P,r[5]=u*_+l*N+c*E+d*F,r[9]=u*w+l*A+c*B+d*z,r[13]=u*S+l*C+c*I+d*U,r[2]=p*T+m*M+g*R+f*P,r[6]=p*_+m*N+g*E+f*F,r[10]=p*w+m*A+g*B+f*z,r[14]=p*S+m*C+g*I+f*U,r[3]=y*T+x*M+b*R+v*P,r[7]=y*_+x*N+b*E+v*F,r[11]=y*w+x*A+b*B+v*z,r[15]=y*S+x*C+b*I+v*U,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],s=e[4],i=e[8],r=e[12],n=e[1],o=e[5],a=e[9],h=e[13],u=e[2],l=e[6],c=e[10],d=e[14];return e[3]*(+r*a*l-i*h*l-r*o*c+s*h*c+i*o*d-s*a*d)+e[7]*(+t*a*d-t*h*c+r*n*c-i*n*d+i*h*u-r*a*u)+e[11]*(+t*h*l-t*o*d-r*n*l+s*n*d+r*o*u-s*h*u)+e[15]*(-i*o*u-t*a*l+t*o*c+i*n*l-s*n*c+s*a*u)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,s){const i=this.elements;return e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=t,i[14]=s),this}invert(){const e=this.elements,t=e[0],s=e[1],i=e[2],r=e[3],n=e[4],o=e[5],a=e[6],h=e[7],u=e[8],l=e[9],c=e[10],d=e[11],p=e[12],m=e[13],g=e[14],f=e[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=t*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 e[0]=y*_,e[1]=(m*c*r-l*g*r-m*i*d+s*g*d+l*i*f-s*c*f)*_,e[2]=(o*g*r-m*a*r+m*i*h-s*g*h-o*i*f+s*a*f)*_,e[3]=(l*a*r-o*c*r-l*i*h+s*c*h+o*i*d-s*a*d)*_,e[4]=x*_,e[5]=(u*g*r-p*c*r+p*i*d-t*g*d-u*i*f+t*c*f)*_,e[6]=(p*a*r-n*g*r-p*i*h+t*g*h+n*i*f-t*a*f)*_,e[7]=(n*c*r-u*a*r+u*i*h-t*c*h-n*i*d+t*a*d)*_,e[8]=b*_,e[9]=(p*l*r-u*m*r-p*s*d+t*m*d+u*s*f-t*l*f)*_,e[10]=(n*m*r-p*o*r+p*s*h-t*m*h-n*s*f+t*o*f)*_,e[11]=(u*o*r-n*l*r-u*s*h+t*l*h+n*s*d-t*o*d)*_,e[12]=v*_,e[13]=(u*m*i-p*l*i+p*s*c-t*m*c-u*s*g+t*l*g)*_,e[14]=(p*o*i-n*m*i-p*s*a+t*m*a+n*s*g-t*o*g)*_,e[15]=(n*l*i-u*o*i+u*s*a-t*l*a-n*s*c+t*o*c)*_,this}scale(e){const t=this.elements,s=e.x,i=e.y,r=e.z;return t[0]*=s,t[4]*=i,t[8]*=r,t[1]*=s,t[5]*=i,t[9]*=r,t[2]*=s,t[6]*=i,t[10]*=r,t[3]*=s,t[7]*=i,t[11]*=r,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],s=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,s,i))}makeTranslation(e,t,s){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,s,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),s=Math.sin(e);return this.set(1,0,0,0,0,t,-s,0,0,s,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),s=Math.sin(e);return this.set(t,0,s,0,0,1,0,0,-s,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),s=Math.sin(e);return this.set(t,-s,0,0,s,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const s=Math.cos(t),i=Math.sin(t),r=1-s,n=e.x,o=e.y,a=e.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(e,t,s){return this.set(e,0,0,0,0,t,0,0,0,0,s,0,0,0,0,1),this}makeShear(e,t,s,i,r,n){return this.set(1,s,r,0,e,1,n,0,t,i,1,0,0,0,0,1),this}compose(e,t,s){const i=this.elements,r=t._x,n=t._y,o=t._z,a=t._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]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,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),e.x=i[12],e.y=i[13],e.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,t.setFromRotationMatrix(hr),s.x=r,s.y=n,s.z=o,this}makePerspective(e,t,s,i,r,n,o=2e3){const a=this.elements,h=2*r/(t-e),u=2*r/(s-i),l=(t+e)/(t-e),c=(s+i)/(s-i);let d,p;if(o===Ds)d=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(o!==ks)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(e,t,s,i,r,n,o=2e3){const a=this.elements,h=1/(t-e),u=1/(s-i),l=1/(n-r),c=(t+e)*h,d=(s+i)*u;let p,m;if(o===Ds)p=(n+r)*l,m=-2*l;else{if(o!==ks)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(e){const t=this.elements,s=e.elements;for(let e=0;e<16;e++)if(t[e]!==s[e])return!1;return!0}fromArray(e,t=0){for(let s=0;s<16;s++)this.elements[s]=e[s+t];return this}toArray(e=[],t=0){const s=this.elements;return e[t]=s[0],e[t+1]=s[1],e[t+2]=s[2],e[t+3]=s[3],e[t+4]=s[4],e[t+5]=s[5],e[t+6]=s[6],e[t+7]=s[7],e[t+8]=s[8],e[t+9]=s[9],e[t+10]=s[10],e[t+11]=s[11],e[t+12]=s[12],e[t+13]=s[13],e[t+14]=s[14],e[t+15]=s[15],e}}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 Ri;class fr{constructor(e=0,t=0,s=0,i=fr.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=s,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,s,i=this._order){return this._x=e,this._y=t,this._z=s,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,s=!0){const i=e.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(t){case"XYZ":this._y=Math.asin(Xs(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(-Xs(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(Xs(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(-Xs(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(Xs(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(-Xs(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: "+t)}return this._order=t,!0===s&&this._onChangeCallback(),this}setFromQuaternion(e,t,s){return mr.makeRotationFromQuaternion(e),this.setFromRotationMatrix(mr,t,s)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return gr.setFromEuler(this),this.setFromQuaternion(gr,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],void 0!==e[3]&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,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(e){this.mask=1<<e>>>0}enable(e){this.mask|=1<<e}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e}disable(e){this.mask&=~(1<<e)}disableAll(){this.mask=0}test(e){return 0!==(this.mask&e.mask)}isEnabled(e){return!!(this.mask&1<<e)}}let xr=0;const br=new Ei,vr=new Ri,Tr=new or,_r=new Ei,wr=new Ei,Sr=new Ei,Mr=new Ri,Nr=new Ei(1,0,0),Ar=new Ei(0,1,0),Cr=new Ei(0,0,1),Rr={type:"added"},Er={type:"removed"},Br={type:"childadded",child:null},Ir={type:"childremoved",child:null};class Pr extends Gs{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:xr++}),this.uuid=$s(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Pr.DEFAULT_UP.clone();const e=new Ei,t=new fr,s=new Ri,i=new Ei(1,1,1);t._onChange(function(){s.setFromEuler(t,!1)}),s._onChange(function(){t.setFromQuaternion(s,void 0,!1)}),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:s},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new or},normalMatrix:{value:new ti}}),this.matrix=new or,this.matrixWorld=new or,this.matrixAutoUpdate=Pr.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Pr.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new yr,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return vr.setFromAxisAngle(e,t),this.quaternion.multiply(vr),this}rotateOnWorldAxis(e,t){return vr.setFromAxisAngle(e,t),this.quaternion.premultiply(vr),this}rotateX(e){return this.rotateOnAxis(Nr,e)}rotateY(e){return this.rotateOnAxis(Ar,e)}rotateZ(e){return this.rotateOnAxis(Cr,e)}translateOnAxis(e,t){return br.copy(e).applyQuaternion(this.quaternion),this.position.add(br.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(Nr,e)}translateY(e){return this.translateOnAxis(Ar,e)}translateZ(e){return this.translateOnAxis(Cr,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(Tr.copy(this.matrixWorld).invert())}lookAt(e,t,s){e.isVector3?_r.copy(e):_r.set(e,t,s);const i=this.parent;this.updateWorldMatrix(!0,!1),wr.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Tr.lookAt(wr,_r,this.up):Tr.lookAt(_r,wr,this.up),this.quaternion.setFromRotationMatrix(Tr),i&&(Tr.extractRotation(i.matrixWorld),vr.setFromRotationMatrix(Tr),this.quaternion.premultiply(vr.invert()))}add(e){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return e===this?(console.error("THREE.Object3D.add: object can't be added as a child of itself.",e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(Rr),Br.child=e,this.dispatchEvent(Br),Br.child=null):console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.remove(arguments[e]);return this}const t=this.children.indexOf(e);return-1!==t&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(Er),Ir.child=e,this.dispatchEvent(Ir),Ir.child=null),this}removeFromParent(){const e=this.parent;return null!==e&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),Tr.copy(this.matrixWorld).invert(),null!==e.parent&&(e.parent.updateWorldMatrix(!0,!1),Tr.multiply(e.parent.matrixWorld)),e.applyMatrix4(Tr),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(Rr),Br.child=e,this.dispatchEvent(Br),Br.child=null,this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let s=0,i=this.children.length;s<i;s++){const i=this.children[s].getObjectByProperty(e,t);if(void 0!==i)return i}}getObjectsByProperty(e,t,s=[]){this[e]===t&&s.push(this);const i=this.children;for(let r=0,n=i.length;r<n;r++)i[r].getObjectsByProperty(e,t,s);return s}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(wr,e,Sr),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(wr,Mr,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);const t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);const t=this.children;for(let s=0,i=t.length;s<i;s++)t[s].traverse(e)}traverseVisible(e){if(!1===this.visible)return;e(this);const t=this.children;for(let s=0,i=t.length;s<i;s++)t[s].traverseVisible(e)}traverseAncestors(e){const t=this.parent;null!==t&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(!0===this.matrixWorldAutoUpdate&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);const t=this.children;for(let s=0,i=t.length;s<i;s++){t[s].updateMatrixWorld(e)}}updateWorldMatrix(e,t){const s=this.parent;if(!0===e&&null!==s&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),!0===this.matrixWorldAutoUpdate&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),!0===t){const e=this.children;for(let t=0,s=e.length;t<s;t++){e[t].updateWorldMatrix(!1,!0)}}}toJSON(e){const t=void 0===e||"string"==typeof e,s={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},s.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const i={};function r(t,s){return void 0===t[s.uuid]&&(t[s.uuid]=s.toJSON(e)),s.uuid}if(i.uuid=this.uuid,i.type=this.type,""!==this.name&&(i.name=this.name),!0===this.castShadow&&(i.castShadow=!0),!0===this.receiveShadow&&(i.receiveShadow=!0),!1===this.visible&&(i.visible=!1),!1===this.frustumCulled&&(i.frustumCulled=!1),0!==this.renderOrder&&(i.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(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(e=>({boxInitialized:e.boxInitialized,boxMin:e.box.min.toArray(),boxMax:e.box.max.toArray(),sphereInitialized:e.sphereInitialized,sphereRadius:e.sphere.radius,sphereCenter:e.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(e),null!==this._colorsTexture&&(i.colorsTexture=this._colorsTexture.toJSON(e)),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(e).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(i.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=r(e.geometries,this.geometry);const t=this.geometry.parameters;if(void 0!==t&&void 0!==t.shapes){const s=t.shapes;if(Array.isArray(s))for(let t=0,i=s.length;t<i;t++){const i=s[t];r(e.shapes,i)}else r(e.shapes,s)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),void 0!==this.skeleton&&(r(e.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),void 0!==this.material)if(Array.isArray(this.material)){const t=[];for(let s=0,i=this.material.length;s<i;s++)t.push(r(e.materials,this.material[s]));i.material=t}else i.material=r(e.materials,this.material);if(this.children.length>0){i.children=[];for(let t=0;t<this.children.length;t++)i.children.push(this.children[t].toJSON(e).object)}if(this.animations.length>0){i.animations=[];for(let t=0;t<this.animations.length;t++){const s=this.animations[t];i.animations.push(r(e.animations,s))}}if(t){const t=n(e.geometries),i=n(e.materials),r=n(e.textures),o=n(e.images),a=n(e.shapes),h=n(e.skeletons),u=n(e.animations),l=n(e.nodes);t.length>0&&(s.geometries=t),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(e){const t=[];for(const s in e){const i=e[s];delete i.metadata,t.push(i)}return t}}clone(e){return(new this.constructor).copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),!0===t)for(let t=0;t<e.children.length;t++){const s=e.children[t];this.add(s.clone())}return this}}Pr.DEFAULT_UP=new Ei(0,1,0),Pr.DEFAULT_MATRIX_AUTO_UPDATE=!0,Pr.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const Fr=new Ei,zr=new Ei,Ur=new Ei,Or=new Ei,Lr=new Ei,Vr=new Ei,Dr=new Ei,kr=new Ei,Gr=new Ei,Wr=new Ei,Hr=new _i,jr=new _i,qr=new _i;class $r{constructor(e=new Ei,t=new Ei,s=new Ei){this.a=e,this.b=t,this.c=s}static getNormal(e,t,s,i){i.subVectors(s,t),Fr.subVectors(e,t),i.cross(Fr);const r=i.lengthSq();return r>0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(e,t,s,i,r){Fr.subVectors(i,t),zr.subVectors(s,t),Ur.subVectors(e,t);const n=Fr.dot(Fr),o=Fr.dot(zr),a=Fr.dot(Ur),h=zr.dot(zr),u=zr.dot(Ur),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(e,t,s,i){return null!==this.getBarycoord(e,t,s,i,Or)&&(Or.x>=0&&Or.y>=0&&Or.x+Or.y<=1)}static getInterpolation(e,t,s,i,r,n,o,a){return null===this.getBarycoord(e,t,s,i,Or)?(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,Or.x),a.addScaledVector(n,Or.y),a.addScaledVector(o,Or.z),a)}static getInterpolatedAttribute(e,t,s,i,r,n){return Hr.setScalar(0),jr.setScalar(0),qr.setScalar(0),Hr.fromBufferAttribute(e,t),jr.fromBufferAttribute(e,s),qr.fromBufferAttribute(e,i),n.setScalar(0),n.addScaledVector(Hr,r.x),n.addScaledVector(jr,r.y),n.addScaledVector(qr,r.z),n}static isFrontFacing(e,t,s,i){return Fr.subVectors(s,t),zr.subVectors(e,t),Fr.cross(zr).dot(i)<0}set(e,t,s){return this.a.copy(e),this.b.copy(t),this.c.copy(s),this}setFromPointsAndIndices(e,t,s,i){return this.a.copy(e[t]),this.b.copy(e[s]),this.c.copy(e[i]),this}setFromAttributeAndIndices(e,t,s,i){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,s),this.c.fromBufferAttribute(e,i),this}clone(){return(new this.constructor).copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return Fr.subVectors(this.c,this.b),zr.subVectors(this.a,this.b),.5*Fr.cross(zr).length()}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return $r.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return $r.getBarycoord(e,this.a,this.b,this.c,t)}getInterpolation(e,t,s,i,r){return $r.getInterpolation(e,this.a,this.b,this.c,t,s,i,r)}containsPoint(e){return $r.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return $r.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){const s=this.a,i=this.b,r=this.c;let n,o;Lr.subVectors(i,s),Vr.subVectors(r,s),kr.subVectors(e,s);const a=Lr.dot(kr),h=Vr.dot(kr);if(a<=0&&h<=0)return t.copy(s);Gr.subVectors(e,i);const u=Lr.dot(Gr),l=Vr.dot(Gr);if(u>=0&&l<=u)return t.copy(i);const c=a*l-u*h;if(c<=0&&a>=0&&u<=0)return n=a/(a-u),t.copy(s).addScaledVector(Lr,n);Wr.subVectors(e,r);const d=Lr.dot(Wr),p=Vr.dot(Wr);if(p>=0&&d<=p)return t.copy(r);const m=d*h-a*p;if(m<=0&&h>=0&&p<=0)return o=h/(h-p),t.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)),t.copy(i).addScaledVector(Dr,o);const f=1/(g+m+c);return n=m*f,o=c*f,t.copy(s).addScaledVector(Lr,n).addScaledVector(Vr,o)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}}const Xr={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},Yr={h:0,s:0,l:0},Zr={h:0,s:0,l:0};function Jr(e,t,s){return s<0&&(s+=1),s>1&&(s-=1),s<1/6?e+6*(t-e)*s:s<.5?t:s<2/3?e+6*(t-e)*(2/3-s):e}class Kr{constructor(e,t,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,s)}set(e,t,s){if(void 0===t&&void 0===s){const t=e;t&&t.isColor?this.copy(t):"number"==typeof t?this.setHex(t):"string"==typeof t&&this.setStyle(t)}else this.setRGB(e,t,s);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=Jt){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(255&e)/255,di.toWorkingColorSpace(this,t),this}setRGB(e,t,s,i=di.workingColorSpace){return this.r=e,this.g=t,this.b=s,di.toWorkingColorSpace(this,i),this}setHSL(e,t,s,i=di.workingColorSpace){if(e=Ys(e,1),t=Xs(t,0,1),s=Xs(s,0,1),0===t)this.r=this.g=this.b=s;else{const i=s<=.5?s*(1+t):s+t-s*t,r=2*s-i;this.r=Jr(r,i,e+1/3),this.g=Jr(r,i,e),this.b=Jr(r,i,e-1/3)}return di.toWorkingColorSpace(this,i),this}setStyle(e,t=Jt){function s(t){void 0!==t&&parseFloat(t)<1&&console.warn("THREE.Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(e)){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,t);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,t);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,t);break;default:console.warn("THREE.Color: Unknown color model "+e)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(e)){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,t);if(6===r)return this.setHex(parseInt(s,16),t);console.warn("THREE.Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=Jt){const s=Xr[e.toLowerCase()];return void 0!==s?this.setHex(s,t):console.warn("THREE.Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=pi(e.r),this.g=pi(e.g),this.b=pi(e.b),this}copyLinearToSRGB(e){return this.r=mi(e.r),this.g=mi(e.g),this.b=mi(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=Jt){return di.fromWorkingColorSpace(Qr.copy(this),e),65536*Math.round(Xs(255*Qr.r,0,255))+256*Math.round(Xs(255*Qr.g,0,255))+Math.round(Xs(255*Qr.b,0,255))}getHexString(e=Jt){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=di.workingColorSpace){di.fromWorkingColorSpace(Qr.copy(this),t);const s=Qr.r,i=Qr.g,r=Qr.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 e=n-o;switch(h=u<=.5?e/(n+o):e/(2-n-o),n){case s:a=(i-r)/e+(i<r?6:0);break;case i:a=(r-s)/e+2;break;case r:a=(s-i)/e+4}a/=6}return e.h=a,e.s=h,e.l=u,e}getRGB(e,t=di.workingColorSpace){return di.fromWorkingColorSpace(Qr.copy(this),t),e.r=Qr.r,e.g=Qr.g,e.b=Qr.b,e}getStyle(e=Jt){di.fromWorkingColorSpace(Qr.copy(this),e);const t=Qr.r,s=Qr.g,i=Qr.b;return e!==Jt?`color(${e} ${t.toFixed(3)} ${s.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(255*t)},${Math.round(255*s)},${Math.round(255*i)})`}offsetHSL(e,t,s){return this.getHSL(Yr),this.setHSL(Yr.h+e,Yr.s+t,Yr.l+s)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,s){return this.r=e.r+(t.r-e.r)*s,this.g=e.g+(t.g-e.g)*s,this.b=e.b+(t.b-e.b)*s,this}lerpHSL(e,t){this.getHSL(Yr),e.getHSL(Zr);const s=Zs(Yr.h,Zr.h,t),i=Zs(Yr.s,Zr.s,t),r=Zs(Yr.l,Zr.l,t);return this.setHSL(s,i,r),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){const t=this.r,s=this.g,i=this.b,r=e.elements;return this.r=r[0]*t+r[3]*s+r[6]*i,this.g=r[1]*t+r[4]*s+r[7]*i,this.b=r[2]*t+r[5]*s+r[8]*i,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const Qr=new Kr;Kr.NAMES=Xr;let en=0;class tn extends Gs{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:en++}),this.uuid=$s(),this.name="",this.type="Material",this.blending=1,this.side=0,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=R,this.blendDst=E,this.blendEquation=v,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new Kr(0,0,0),this.blendAlpha=0,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=vs,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=os,this.stencilZFail=os,this.stencilZPass=os,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBuild(){}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(void 0!==e)for(const t in e){const s=e[t];if(void 0===s){console.warn(`THREE.Material: parameter '${t}' has value of undefined.`);continue}const i=this[t];void 0!==i?i&&i.isColor?i.set(s):i&&i.isVector3&&s&&s.isVector3?i.copy(s):this[t]=s:console.warn(`THREE.Material: '${t}' is not a property of THREE.${this.type}.`)}}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{}});const s={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function i(e){const t=[];for(const s in e){const i=e[s];delete i.metadata,t.push(i)}return t}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(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(s.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(s.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).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(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(s.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).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(e).uuid),this.map&&this.map.isTexture&&(s.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(s.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(s.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(s.lightMap=this.lightMap.toJSON(e).uuid,s.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(s.aoMap=this.aoMap.toJSON(e).uuid,s.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(s.bumpMap=this.bumpMap.toJSON(e).uuid,s.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(s.normalMap=this.normalMap.toJSON(e).uuid,s.normalMapType=this.normalMapType,s.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(s.displacementMap=this.displacementMap.toJSON(e).uuid,s.displacementScale=this.displacementScale,s.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(s.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(s.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(s.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(s.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(s.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(s.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(s.envMap=this.envMap.toJSON(e).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(e).uuid),void 0!==this.transmission&&(s.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(s.transmissionMap=this.transmissionMap.toJSON(e).uuid),void 0!==this.thickness&&(s.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(s.thicknessMap=this.thicknessMap.toJSON(e).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),0!==this.side&&(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!==R&&(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!==vs&&(s.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(s.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(s.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==os&&(s.stencilFail=this.stencilFail),this.stencilZFail!==os&&(s.stencilZFail=this.stencilZFail),this.stencilZPass!==os&&(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),t){const t=i(e.textures),r=i(e.images);t.length>0&&(s.textures=t),r.length>0&&(s.images=r)}return s}clone(){return(new this.constructor).copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const t=e.clippingPlanes;let s=null;if(null!==t){const e=t.length;s=new Array(e);for(let i=0;i!==e;++i)s[i]=t[i].clone()}return this.clippingPlanes=s,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}}class sn extends tn{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Kr(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(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}const rn=nn();function nn(){const e=new ArrayBuffer(4),t=new Float32Array(e),s=new Uint32Array(e),i=new Uint32Array(512),r=new Uint32Array(512);for(let e=0;e<256;++e){const t=e-127;t<-27?(i[e]=0,i[256|e]=32768,r[e]=24,r[256|e]=24):t<-14?(i[e]=1024>>-t-14,i[256|e]=1024>>-t-14|32768,r[e]=-t-1,r[256|e]=-t-1):t<=15?(i[e]=t+15<<10,i[256|e]=t+15<<10|32768,r[e]=13,r[256|e]=13):t<128?(i[e]=31744,i[256|e]=64512,r[e]=24,r[256|e]=24):(i[e]=31744,i[256|e]=64512,r[e]=13,r[256|e]=13)}const n=new Uint32Array(2048),o=new Uint32Array(64),a=new Uint32Array(64);for(let e=1;e<1024;++e){let t=e<<13,s=0;for(;!(8388608&t);)t<<=1,s-=8388608;t&=-8388609,s+=947912704,n[e]=t|s}for(let e=1024;e<2048;++e)n[e]=939524096+(e-1024<<13);for(let e=1;e<31;++e)o[e]=e<<23;o[31]=1199570944,o[32]=2147483648;for(let e=33;e<63;++e)o[e]=2147483648+(e-32<<23);o[63]=3347054592;for(let e=1;e<64;++e)32!==e&&(a[e]=1024);return{floatView:t,uint32View:s,baseTable:i,shiftTable:r,mantissaTable:n,exponentTable:o,offsetTable:a}}function on(e){Math.abs(e)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),e=Xs(e,-65504,65504),rn.floatView[0]=e;const t=rn.uint32View[0],s=t>>23&511;return rn.baseTable[s]+((8388607&t)>>rn.shiftTable[s])}function an(e){const t=e>>10;return rn.uint32View[0]=rn.mantissaTable[rn.offsetTable[t]+(1023&e)]+rn.exponentTable[t],rn.floatView[0]}const hn={toHalfFloat:on,fromHalfFloat:an},un=new Ei,ln=new ei;class cn{constructor(e,t,s=!1){if(Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=e,this.itemSize=t,this.count=void 0!==e?e.length/t:0,this.normalized=s,this.usage=Rs,this.updateRanges=[],this.gpuType=Ie,this.version=0}onUploadCallback(){}set needsUpdate(e){!0===e&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,s){e*=this.itemSize,s*=t.itemSize;for(let i=0,r=this.itemSize;i<r;i++)this.array[e+i]=t.array[s+i];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(2===this.itemSize)for(let t=0,s=this.count;t<s;t++)ln.fromBufferAttribute(this,t),ln.applyMatrix3(e),this.setXY(t,ln.x,ln.y);else if(3===this.itemSize)for(let t=0,s=this.count;t<s;t++)un.fromBufferAttribute(this,t),un.applyMatrix3(e),this.setXYZ(t,un.x,un.y,un.z);return this}applyMatrix4(e){for(let t=0,s=this.count;t<s;t++)un.fromBufferAttribute(this,t),un.applyMatrix4(e),this.setXYZ(t,un.x,un.y,un.z);return this}applyNormalMatrix(e){for(let t=0,s=this.count;t<s;t++)un.fromBufferAttribute(this,t),un.applyNormalMatrix(e),this.setXYZ(t,un.x,un.y,un.z);return this}transformDirection(e){for(let t=0,s=this.count;t<s;t++)un.fromBufferAttribute(this,t),un.transformDirection(e),this.setXYZ(t,un.x,un.y,un.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let s=this.array[e*this.itemSize+t];return this.normalized&&(s=Js(s,this.array)),s}setComponent(e,t,s){return this.normalized&&(s=Ks(s,this.array)),this.array[e*this.itemSize+t]=s,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=Js(t,this.array)),t}setX(e,t){return this.normalized&&(t=Ks(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=Js(t,this.array)),t}setY(e,t){return this.normalized&&(t=Ks(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=Js(t,this.array)),t}setZ(e,t){return this.normalized&&(t=Ks(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=Js(t,this.array)),t}setW(e,t){return this.normalized&&(t=Ks(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,s){return e*=this.itemSize,this.normalized&&(t=Ks(t,this.array),s=Ks(s,this.array)),this.array[e+0]=t,this.array[e+1]=s,this}setXYZ(e,t,s,i){return e*=this.itemSize,this.normalized&&(t=Ks(t,this.array),s=Ks(s,this.array),i=Ks(i,this.array)),this.array[e+0]=t,this.array[e+1]=s,this.array[e+2]=i,this}setXYZW(e,t,s,i,r){return e*=this.itemSize,this.normalized&&(t=Ks(t,this.array),s=Ks(s,this.array),i=Ks(i,this.array),r=Ks(r,this.array)),this.array[e+0]=t,this.array[e+1]=s,this.array[e+2]=i,this.array[e+3]=r,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return""!==this.name&&(e.name=this.name),this.usage!==Rs&&(e.usage=this.usage),e}}class dn extends cn{constructor(e,t,s){super(new Int8Array(e),t,s)}}class pn extends cn{constructor(e,t,s){super(new Uint8Array(e),t,s)}}class mn extends cn{constructor(e,t,s){super(new Uint8ClampedArray(e),t,s)}}class gn extends cn{constructor(e,t,s){super(new Int16Array(e),t,s)}}class fn extends cn{constructor(e,t,s){super(new Uint16Array(e),t,s)}}class yn extends cn{constructor(e,t,s){super(new Int32Array(e),t,s)}}class xn extends cn{constructor(e,t,s){super(new Uint32Array(e),t,s)}}class bn extends cn{constructor(e,t,s){super(new Uint16Array(e),t,s),this.isFloat16BufferAttribute=!0}getX(e){let t=an(this.array[e*this.itemSize]);return this.normalized&&(t=Js(t,this.array)),t}setX(e,t){return this.normalized&&(t=Ks(t,this.array)),this.array[e*this.itemSize]=on(t),this}getY(e){let t=an(this.array[e*this.itemSize+1]);return this.normalized&&(t=Js(t,this.array)),t}setY(e,t){return this.normalized&&(t=Ks(t,this.array)),this.array[e*this.itemSize+1]=on(t),this}getZ(e){let t=an(this.array[e*this.itemSize+2]);return this.normalized&&(t=Js(t,this.array)),t}setZ(e,t){return this.normalized&&(t=Ks(t,this.array)),this.array[e*this.itemSize+2]=on(t),this}getW(e){let t=an(this.array[e*this.itemSize+3]);return this.normalized&&(t=Js(t,this.array)),t}setW(e,t){return this.normalized&&(t=Ks(t,this.array)),this.array[e*this.itemSize+3]=on(t),this}setXY(e,t,s){return e*=this.itemSize,this.normalized&&(t=Ks(t,this.array),s=Ks(s,this.array)),this.array[e+0]=on(t),this.array[e+1]=on(s),this}setXYZ(e,t,s,i){return e*=this.itemSize,this.normalized&&(t=Ks(t,this.array),s=Ks(s,this.array),i=Ks(i,this.array)),this.array[e+0]=on(t),this.array[e+1]=on(s),this.array[e+2]=on(i),this}setXYZW(e,t,s,i,r){return e*=this.itemSize,this.normalized&&(t=Ks(t,this.array),s=Ks(s,this.array),i=Ks(i,this.array),r=Ks(r,this.array)),this.array[e+0]=on(t),this.array[e+1]=on(s),this.array[e+2]=on(i),this.array[e+3]=on(r),this}}class vn extends cn{constructor(e,t,s){super(new Float32Array(e),t,s)}}let Tn=0;const _n=new or,wn=new Pr,Sn=new Ei,Mn=new Pi,Nn=new Pi,An=new Ei;class Cn extends Gs{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:Tn++}),this.uuid=$s(),this.name="",this.type="BufferGeometry",this.index=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(function(e){for(let t=e.length-1;t>=0;--t)if(e[t]>=65535)return!0;return!1}(e)?xn:fn)(e,1):this.index=e,this}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return void 0!==this.attributes[e]}addGroup(e,t,s=0){this.groups.push({start:e,count:t,materialIndex:s})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){const t=this.attributes.position;void 0!==t&&(t.applyMatrix4(e),t.needsUpdate=!0);const s=this.attributes.normal;if(void 0!==s){const t=(new ti).getNormalMatrix(e);s.applyNormalMatrix(t),s.needsUpdate=!0}const i=this.attributes.tangent;return void 0!==i&&(i.transformDirection(e),i.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}applyQuaternion(e){return _n.makeRotationFromQuaternion(e),this.applyMatrix4(_n),this}rotateX(e){return _n.makeRotationX(e),this.applyMatrix4(_n),this}rotateY(e){return _n.makeRotationY(e),this.applyMatrix4(_n),this}rotateZ(e){return _n.makeRotationZ(e),this.applyMatrix4(_n),this}translate(e,t,s){return _n.makeTranslation(e,t,s),this.applyMatrix4(_n),this}scale(e,t,s){return _n.makeScale(e,t,s),this.applyMatrix4(_n),this}lookAt(e){return wn.lookAt(e),wn.updateMatrix(),this.applyMatrix4(wn.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Sn).negate(),this.translate(Sn.x,Sn.y,Sn.z),this}setFromPoints(e){const t=[];for(let s=0,i=e.length;s<i;s++){const i=e[s];t.push(i.x,i.y,i.z||0)}return this.setAttribute("position",new vn(t,3)),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Pi);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute)return console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),void this.boundingBox.set(new Ei(-1/0,-1/0,-1/0),new Ei(1/0,1/0,1/0));if(void 0!==e){if(this.boundingBox.setFromBufferAttribute(e),t)for(let e=0,s=t.length;e<s;e++){const s=t[e];Mn.setFromBufferAttribute(s),this.morphTargetsRelative?(An.addVectors(this.boundingBox.min,Mn.min),this.boundingBox.expandByPoint(An),An.addVectors(this.boundingBox.max,Mn.max),this.boundingBox.expandByPoint(An)):(this.boundingBox.expandByPoint(Mn.min),this.boundingBox.expandByPoint(Mn.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new Ji);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute)return console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),void this.boundingSphere.set(new Ei,1/0);if(e){const s=this.boundingSphere.center;if(Mn.setFromBufferAttribute(e),t)for(let e=0,s=t.length;e<s;e++){const s=t[e];Nn.setFromBufferAttribute(s),this.morphTargetsRelative?(An.addVectors(Mn.min,Nn.min),Mn.expandByPoint(An),An.addVectors(Mn.max,Nn.max),Mn.expandByPoint(An)):(Mn.expandByPoint(Nn.min),Mn.expandByPoint(Nn.max))}Mn.getCenter(s);let i=0;for(let t=0,r=e.count;t<r;t++)An.fromBufferAttribute(e,t),i=Math.max(i,s.distanceToSquared(An));if(t)for(let r=0,n=t.length;r<n;r++){const n=t[r],o=this.morphTargetsRelative;for(let t=0,r=n.count;t<r;t++)An.fromBufferAttribute(n,t),o&&(Sn.fromBufferAttribute(e,t),An.add(Sn)),i=Math.max(i,s.distanceToSquared(An))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const e=this.index,t=this.attributes;if(null===e||void 0===t.position||void 0===t.normal||void 0===t.uv)return void console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");const s=t.position,i=t.normal,r=t.uv;!1===this.hasAttribute("tangent")&&this.setAttribute("tangent",new cn(new Float32Array(4*s.count),4));const n=this.getAttribute("tangent"),o=[],a=[];for(let e=0;e<s.count;e++)o[e]=new Ei,a[e]=new Ei;const h=new Ei,u=new Ei,l=new Ei,c=new ei,d=new ei,p=new ei,m=new Ei,g=new Ei;function f(e,t,i){h.fromBufferAttribute(s,e),u.fromBufferAttribute(s,t),l.fromBufferAttribute(s,i),c.fromBufferAttribute(r,e),d.fromBufferAttribute(r,t),p.fromBufferAttribute(r,i),u.sub(h),l.sub(h),d.sub(c),p.sub(c);const n=1/(d.x*p.y-p.x*d.y);isFinite(n)&&(m.copy(u).multiplyScalar(p.y).addScaledVector(l,-d.y).multiplyScalar(n),g.copy(l).multiplyScalar(d.x).addScaledVector(u,-p.x).multiplyScalar(n),o[e].add(m),o[t].add(m),o[i].add(m),a[e].add(g),a[t].add(g),a[i].add(g))}let y=this.groups;0===y.length&&(y=[{start:0,count:e.count}]);for(let t=0,s=y.length;t<s;++t){const s=y[t],i=s.start;for(let t=i,r=i+s.count;t<r;t+=3)f(e.getX(t+0),e.getX(t+1),e.getX(t+2))}const x=new Ei,b=new Ei,v=new Ei,T=new Ei;function _(e){v.fromBufferAttribute(i,e),T.copy(v);const t=o[e];x.copy(t),x.sub(v.multiplyScalar(v.dot(t))).normalize(),b.crossVectors(T,t);const s=b.dot(a[e])<0?-1:1;n.setXYZW(e,x.x,x.y,x.z,s)}for(let t=0,s=y.length;t<s;++t){const s=y[t],i=s.start;for(let t=i,r=i+s.count;t<r;t+=3)_(e.getX(t+0)),_(e.getX(t+1)),_(e.getX(t+2))}}computeVertexNormals(){const e=this.index,t=this.getAttribute("position");if(void 0!==t){let s=this.getAttribute("normal");if(void 0===s)s=new cn(new Float32Array(3*t.count),3),this.setAttribute("normal",s);else for(let e=0,t=s.count;e<t;e++)s.setXYZ(e,0,0,0);const i=new Ei,r=new Ei,n=new Ei,o=new Ei,a=new Ei,h=new Ei,u=new Ei,l=new Ei;if(e)for(let c=0,d=e.count;c<d;c+=3){const d=e.getX(c+0),p=e.getX(c+1),m=e.getX(c+2);i.fromBufferAttribute(t,d),r.fromBufferAttribute(t,p),n.fromBufferAttribute(t,m),u.subVectors(n,r),l.subVectors(i,r),u.cross(l),o.fromBufferAttribute(s,d),a.fromBufferAttribute(s,p),h.fromBufferAttribute(s,m),o.add(u),a.add(u),h.add(u),s.setXYZ(d,o.x,o.y,o.z),s.setXYZ(p,a.x,a.y,a.z),s.setXYZ(m,h.x,h.y,h.z)}else for(let e=0,o=t.count;e<o;e+=3)i.fromBufferAttribute(t,e+0),r.fromBufferAttribute(t,e+1),n.fromBufferAttribute(t,e+2),u.subVectors(n,r),l.subVectors(i,r),u.cross(l),s.setXYZ(e+0,u.x,u.y,u.z),s.setXYZ(e+1,u.x,u.y,u.z),s.setXYZ(e+2,u.x,u.y,u.z);this.normalizeNormals(),s.needsUpdate=!0}}normalizeNormals(){const e=this.attributes.normal;for(let t=0,s=e.count;t<s;t++)An.fromBufferAttribute(e,t),An.normalize(),e.setXYZ(t,An.x,An.y,An.z)}toNonIndexed(){function e(e,t){const s=e.array,i=e.itemSize,r=e.normalized,n=new s.constructor(t.length*i);let o=0,a=0;for(let r=0,h=t.length;r<h;r++){o=e.isInterleavedBufferAttribute?t[r]*e.data.stride+e.offset:t[r]*i;for(let e=0;e<i;e++)n[a++]=s[o++]}return new cn(n,i,r)}if(null===this.index)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const t=new Cn,s=this.index.array,i=this.attributes;for(const r in i){const n=e(i[r],s);t.setAttribute(r,n)}const r=this.morphAttributes;for(const i in r){const n=[],o=r[i];for(let t=0,i=o.length;t<i;t++){const i=e(o[t],s);n.push(i)}t.morphAttributes[i]=n}t.morphTargetsRelative=this.morphTargetsRelative;const n=this.groups;for(let e=0,s=n.length;e<s;e++){const s=n[e];t.addGroup(s.start,s.count,s.materialIndex)}return t}toJSON(){const e={metadata:{version:4.6,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(e.uuid=this.uuid,e.type=this.type,""!==this.name&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),void 0!==this.parameters){const t=this.parameters;for(const s in t)void 0!==t[s]&&(e[s]=t[s]);return e}e.data={attributes:{}};const t=this.index;null!==t&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});const s=this.attributes;for(const t in s){const i=s[t];e.data.attributes[t]=i.toJSON(e.data)}const i={};let r=!1;for(const t in this.morphAttributes){const s=this.morphAttributes[t],n=[];for(let t=0,i=s.length;t<i;t++){const i=s[t];n.push(i.toJSON(e.data))}n.length>0&&(i[t]=n,r=!0)}r&&(e.data.morphAttributes=i,e.data.morphTargetsRelative=this.morphTargetsRelative);const n=this.groups;n.length>0&&(e.data.groups=JSON.parse(JSON.stringify(n)));const o=this.boundingSphere;return null!==o&&(e.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),e}clone(){return(new this.constructor).copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const t={};this.name=e.name;const s=e.index;null!==s&&this.setIndex(s.clone(t));const i=e.attributes;for(const e in i){const s=i[e];this.setAttribute(e,s.clone(t))}const r=e.morphAttributes;for(const e in r){const s=[],i=r[e];for(let e=0,r=i.length;e<r;e++)s.push(i[e].clone(t));this.morphAttributes[e]=s}this.morphTargetsRelative=e.morphTargetsRelative;const n=e.groups;for(let e=0,t=n.length;e<t;e++){const t=n[e];this.addGroup(t.start,t.count,t.materialIndex)}const o=e.boundingBox;null!==o&&(this.boundingBox=o.clone());const a=e.boundingSphere;return null!==a&&(this.boundingSphere=a.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Rn=new or,En=new nr,Bn=new Ji,In=new Ei,Pn=new Ei,Fn=new Ei,zn=new Ei,Un=new Ei,On=new Ei,Ln=new Ei,Vn=new Ei;class Dn extends Pr{constructor(e=new Cn,t=new sn){super(),this.isMesh=!0,this.type="Mesh",this.geometry=e,this.material=t,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),void 0!==e.morphTargetInfluences&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),void 0!==e.morphTargetDictionary&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){const e=this.geometry.morphAttributes,t=Object.keys(e);if(t.length>0){const s=e[t[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=s.length;e<t;e++){const t=s[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[t]=e}}}}getVertexPosition(e,t){const s=this.geometry,i=s.attributes.position,r=s.morphAttributes.position,n=s.morphTargetsRelative;t.fromBufferAttribute(i,e);const o=this.morphTargetInfluences;if(r&&o){On.set(0,0,0);for(let s=0,i=r.length;s<i;s++){const i=o[s],a=r[s];0!==i&&(Un.fromBufferAttribute(a,e),n?On.addScaledVector(Un,i):On.addScaledVector(Un.sub(t),i))}t.add(On)}return t}raycast(e,t){const s=this.geometry,i=this.material,r=this.matrixWorld;if(void 0!==i){if(null===s.boundingSphere&&s.computeBoundingSphere(),Bn.copy(s.boundingSphere),Bn.applyMatrix4(r),En.copy(e.ray).recast(e.near),!1===Bn.containsPoint(En.origin)){if(null===En.intersectSphere(Bn,In))return;if(En.origin.distanceToSquared(In)>(e.far-e.near)**2)return}Rn.copy(r).invert(),En.copy(e.ray).applyMatrix4(Rn),null!==s.boundingBox&&!1===En.intersectsBox(s.boundingBox)||this._computeIntersections(e,t,En)}}_computeIntersections(e,t,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;r<a;r++){const a=c[r],p=n[a.materialIndex];for(let r=Math.max(a.start,d.start),n=Math.min(o.count,Math.min(a.start+a.count,d.start+d.count));r<n;r+=3){i=kn(this,p,e,s,h,u,l,o.getX(r),o.getX(r+1),o.getX(r+2)),i&&(i.faceIndex=Math.floor(r/3),i.face.materialIndex=a.materialIndex,t.push(i))}}else{for(let r=Math.max(0,d.start),a=Math.min(o.count,d.start+d.count);r<a;r+=3){i=kn(this,n,e,s,h,u,l,o.getX(r),o.getX(r+1),o.getX(r+2)),i&&(i.faceIndex=Math.floor(r/3),t.push(i))}}else if(void 0!==a)if(Array.isArray(n))for(let r=0,o=c.length;r<o;r++){const o=c[r],p=n[o.materialIndex];for(let r=Math.max(o.start,d.start),n=Math.min(a.count,Math.min(o.start+o.count,d.start+d.count));r<n;r+=3){i=kn(this,p,e,s,h,u,l,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),i.face.materialIndex=o.materialIndex,t.push(i))}}else{for(let r=Math.max(0,d.start),o=Math.min(a.count,d.start+d.count);r<o;r+=3){i=kn(this,n,e,s,h,u,l,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),t.push(i))}}}}function kn(e,t,s,i,r,n,o,a,h,u){e.getVertexPosition(a,Pn),e.getVertexPosition(h,Fn),e.getVertexPosition(u,zn);const l=function(e,t,s,i,r,n,o,a){let h;if(h=1===t.side?i.intersectTriangle(o,n,r,!0,a):i.intersectTriangle(r,n,o,0===t.side,a),null===h)return null;Vn.copy(a),Vn.applyMatrix4(e.matrixWorld);const u=s.ray.origin.distanceTo(Vn);return u<s.near||u>s.far?null:{distance:u,point:Vn.clone(),object:e}}(e,t,s,i,Pn,Fn,zn,Ln);if(l){const e=new Ei;$r.getBarycoord(Ln,Pn,Fn,zn,e),r&&(l.uv=$r.getInterpolatedAttribute(r,a,h,u,e,new ei)),n&&(l.uv1=$r.getInterpolatedAttribute(n,a,h,u,e,new ei)),o&&(l.normal=$r.getInterpolatedAttribute(o,a,h,u,e,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};$r.getNormal(Pn,Fn,zn,t.normal),l.face=t,l.barycoord=e}return l}class Gn extends Cn{constructor(e=1,t=1,s=1,i=1,r=1,n=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,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(e,t,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,N=0;const A=new Ei;for(let n=0;n<S;n++){const o=n*b-T;for(let a=0;a<w;a++){const c=a*x-v;A[e]=c*i,A[t]=o*r,A[s]=_,h.push(A.x,A.y,A.z),A[e]=0,A[t]=0,A[s]=m>0?1:-1,u.push(A.x,A.y,A.z),l.push(a/g),l.push(1-n/f),M+=1}}for(let e=0;e<f;e++)for(let t=0;t<g;t++){const s=c+t+w*e,i=c+t+w*(e+1),r=c+(t+1)+w*(e+1),n=c+(t+1)+w*e;a.push(s,i,n),a.push(i,r,n),N+=6}o.addGroup(d,N,y),d+=N,c+=M}p("z","y","x",-1,-1,s,t,e,n,r,0),p("z","y","x",1,-1,s,t,-e,n,r,1),p("x","z","y",1,1,e,s,t,i,n,2),p("x","z","y",1,-1,e,s,-t,i,n,3),p("x","y","z",1,-1,e,t,s,i,r,4),p("x","y","z",-1,-1,e,t,-s,i,r,5),this.setIndex(a),this.setAttribute("position",new vn(h,3)),this.setAttribute("normal",new vn(u,3)),this.setAttribute("uv",new vn(l,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Gn(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}}function Wn(e){const t={};for(const s in e){t[s]={};for(const i in e[s]){const r=e[s][i];r&&(r.isColor||r.isMatrix3||r.isMatrix4||r.isVector2||r.isVector3||r.isVector4||r.isTexture||r.isQuaternion)?r.isRenderTargetTexture?(console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),t[s][i]=null):t[s][i]=r.clone():Array.isArray(r)?t[s][i]=r.slice():t[s][i]=r}}return t}class Hn extends tn{constructor(e){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader="\nvoid main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n",this.fragmentShader="\nvoid main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}\n",this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,void 0!==e&&this.setValues(e)}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=Wn(e.uniforms),this.uniformsGroups=function(e){const t=[];for(let s=0;s<e.length;s++)t.push(e[s].clone());return t}(e.uniformsGroups),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.fog=e.fog,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this}toJSON(e){const t=super.toJSON(e);t.glslVersion=this.glslVersion,t.uniforms={};for(const s in this.uniforms){const i=this.uniforms[s].value;i&&i.isTexture?t.uniforms[s]={type:"t",value:i.toJSON(e).uuid}:i&&i.isColor?t.uniforms[s]={type:"c",value:i.getHex()}:i&&i.isVector2?t.uniforms[s]={type:"v2",value:i.toArray()}:i&&i.isVector3?t.uniforms[s]={type:"v3",value:i.toArray()}:i&&i.isVector4?t.uniforms[s]={type:"v4",value:i.toArray()}:i&&i.isMatrix3?t.uniforms[s]={type:"m3",value:i.toArray()}:i&&i.isMatrix4?t.uniforms[s]={type:"m4",value:i.toArray()}:t.uniforms[s]={value:i}}Object.keys(this.defines).length>0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;const s={};for(const e in this.extensions)!0===this.extensions[e]&&(s[e]=!0);return Object.keys(s).length>0&&(t.extensions=s),t}}const jn=new Ei,qn=new Ri,$n=new Ei;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=Ds}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorld.decompose(jn,qn,$n),1===$n.x&&1===$n.y&&1===$n.z?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(jn,qn,$n.set(1,1,1)).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorld.decompose(jn,qn,$n),1===$n.x&&1===$n.y&&1===$n.z?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(jn,qn,$n.set(1,1,1)).invert()}clone(){return(new this.constructor).copy(this)}}const Yn=new Ei,Zn=new ei,Jn=new ei;class Kn extends Xn{constructor(e=50,t=1,s=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=s,this.far=i,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=null===e.view?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){const t=.5*this.getFilmHeight()/e;this.fov=2*qs*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){const e=Math.tan(.5*js*this.fov);return.5*this.getFilmHeight()/e}getEffectiveFOV(){return 2*qs*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(e,t,s){Yn.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(Yn.x,Yn.y).multiplyScalar(-e/Yn.z),Yn.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),s.set(Yn.x,Yn.y).multiplyScalar(-e/Yn.z)}getViewSize(e,t){return this.getViewBounds(e,Zn,Jn),t.subVectors(Jn,Zn)}setViewOffset(e,t,s,i,r,n){this.aspect=e/t,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=e,this.view.fullHeight=t,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 e=this.near;let t=e*Math.tan(.5*js*this.fov)/this.zoom,s=2*t,i=this.aspect*s,r=-.5*i;const n=this.view;if(null!==this.view&&this.view.enabled){const e=n.fullWidth,o=n.fullHeight;r+=n.offsetX*i/e,t-=n.offsetY*s/o,i*=n.width/e,s*=n.height/o}const o=this.filmOffset;0!==o&&(r+=e*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+i,t,t-s,e,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,null!==this.view&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}}const Qn=-90;class eo extends Pr{constructor(e,t,s){super(),this.type="CubeCamera",this.renderTarget=s,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Kn(Qn,1,e,t);i.layers=this.layers,this.add(i);const r=new Kn(Qn,1,e,t);r.layers=this.layers,this.add(r);const n=new Kn(Qn,1,e,t);n.layers=this.layers,this.add(n);const o=new Kn(Qn,1,e,t);o.layers=this.layers,this.add(o);const a=new Kn(Qn,1,e,t);a.layers=this.layers,this.add(a);const h=new Kn(Qn,1,e,t);h.layers=this.layers,this.add(h)}updateCoordinateSystem(){const e=this.coordinateSystem,t=this.children.concat(),[s,i,r,n,o,a]=t;for(const e of t)this.remove(e);if(e===Ds)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(e!==ks)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+e);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 e of t)this.add(e),e.updateMatrixWorld()}update(e,t){null===this.parent&&this.updateMatrixWorld();const{renderTarget:s,activeMipmapLevel:i}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());const[r,n,o,a,h,u]=this.children,l=e.getRenderTarget(),c=e.getActiveCubeFace(),d=e.getActiveMipmapLevel(),p=e.xr.enabled;e.xr.enabled=!1;const m=s.texture.generateMipmaps;s.texture.generateMipmaps=!1,e.setRenderTarget(s,0,i),e.render(t,r),e.setRenderTarget(s,1,i),e.render(t,n),e.setRenderTarget(s,2,i),e.render(t,o),e.setRenderTarget(s,3,i),e.render(t,a),e.setRenderTarget(s,4,i),e.render(t,h),s.texture.generateMipmaps=m,e.setRenderTarget(s,5,i),e.render(t,u),e.setRenderTarget(l,c,d),e.xr.enabled=p,s.texture.needsPMREMUpdate=!0}}class to extends Ti{constructor(e,t,s,i,r,n,o,a,h,u){super(e=void 0!==e?e:[],t=void 0!==t?t:he,s,i,r,n,o,a,h,u),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}}class so extends Si{constructor(e=1,t={}){super(e,e,t),this.isWebGLCubeRenderTarget=!0;const s={width:e,height:e,depth:1},i=[s,s,s,s,s,s];this.texture=new to(i,t.mapping,t.wrapS,t.wrapT,t.magFilter,t.minFilter,t.format,t.type,t.anisotropy,t.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=void 0!==t.generateMipmaps&&t.generateMipmaps,this.texture.minFilter=void 0!==t.minFilter?t.minFilter:Te}fromEquirectangularTexture(e,t){this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.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 <begin_vertex>\n\t\t\t\t\t#include <project_vertex>\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 <common>\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 Gn(5,5,5),r=new Hn({name:"CubemapFromEquirect",uniforms:Wn(s.uniforms),vertexShader:s.vertexShader,fragmentShader:s.fragmentShader,side:1,blending:0});r.uniforms.tEquirect.value=t;const n=new Dn(i,r),o=t.minFilter;t.minFilter===Se&&(t.minFilter=Te);return new eo(1,10,this).update(e,n),t.minFilter=o,n.geometry.dispose(),n.material.dispose(),this}clear(e,t,s,i){const r=e.getRenderTarget();for(let r=0;r<6;r++)e.setRenderTarget(this,r),e.clear(t,s,i);e.setRenderTarget(r)}}class io{constructor(e,t=25e-5){this.isFogExp2=!0,this.name="",this.color=new Kr(e),this.density=t}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(e,t=1,s=1e3){this.isFog=!0,this.name="",this.color=new Kr(e),this.near=t,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(e,t){return super.copy(e,t),null!==e.background&&(this.background=e.background.clone()),null!==e.environment&&(this.environment=e.environment.clone()),null!==e.fog&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),null!==e.overrideMaterial&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return null!==this.fog&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),1!==this.backgroundIntensity&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),1!==this.environmentIntensity&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}}class oo{constructor(e,t){this.isInterleavedBuffer=!0,this.array=e,this.stride=t,this.count=void 0!==e?e.length/t:0,this.usage=Rs,this.updateRanges=[],this.version=0,this.uuid=$s()}onUploadCallback(){}set needsUpdate(e){!0===e&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.array=new e.array.constructor(e.array),this.count=e.count,this.stride=e.stride,this.usage=e.usage,this}copyAt(e,t,s){e*=this.stride,s*=t.stride;for(let i=0,r=this.stride;i<r;i++)this.array[e+i]=t.array[s+i];return this}set(e,t=0){return this.array.set(e,t),this}clone(e){void 0===e.arrayBuffers&&(e.arrayBuffers={}),void 0===this.array.buffer._uuid&&(this.array.buffer._uuid=$s()),void 0===e.arrayBuffers[this.array.buffer._uuid]&&(e.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const t=new this.array.constructor(e.arrayBuffers[this.array.buffer._uuid]),s=new this.constructor(t,this.stride);return s.setUsage(this.usage),s}onUpload(e){return this.onUploadCallback=e,this}toJSON(e){return void 0===e.arrayBuffers&&(e.arrayBuffers={}),void 0===this.array.buffer._uuid&&(this.array.buffer._uuid=$s()),void 0===e.arrayBuffers[this.array.buffer._uuid]&&(e.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}const ao=new Ei;class ho{constructor(e,t,s,i=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=e,this.itemSize=t,this.offset=s,this.normalized=i}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(e){this.data.needsUpdate=e}applyMatrix4(e){for(let t=0,s=this.data.count;t<s;t++)ao.fromBufferAttribute(this,t),ao.applyMatrix4(e),this.setXYZ(t,ao.x,ao.y,ao.z);return this}applyNormalMatrix(e){for(let t=0,s=this.count;t<s;t++)ao.fromBufferAttribute(this,t),ao.applyNormalMatrix(e),this.setXYZ(t,ao.x,ao.y,ao.z);return this}transformDirection(e){for(let t=0,s=this.count;t<s;t++)ao.fromBufferAttribute(this,t),ao.transformDirection(e),this.setXYZ(t,ao.x,ao.y,ao.z);return this}getComponent(e,t){let s=this.array[e*this.data.stride+this.offset+t];return this.normalized&&(s=Js(s,this.array)),s}setComponent(e,t,s){return this.normalized&&(s=Ks(s,this.array)),this.data.array[e*this.data.stride+this.offset+t]=s,this}setX(e,t){return this.normalized&&(t=Ks(t,this.array)),this.data.array[e*this.data.stride+this.offset]=t,this}setY(e,t){return this.normalized&&(t=Ks(t,this.array)),this.data.array[e*this.data.stride+this.offset+1]=t,this}setZ(e,t){return this.normalized&&(t=Ks(t,this.array)),this.data.array[e*this.data.stride+this.offset+2]=t,this}setW(e,t){return this.normalized&&(t=Ks(t,this.array)),this.data.array[e*this.data.stride+this.offset+3]=t,this}getX(e){let t=this.data.array[e*this.data.stride+this.offset];return this.normalized&&(t=Js(t,this.array)),t}getY(e){let t=this.data.array[e*this.data.stride+this.offset+1];return this.normalized&&(t=Js(t,this.array)),t}getZ(e){let t=this.data.array[e*this.data.stride+this.offset+2];return this.normalized&&(t=Js(t,this.array)),t}getW(e){let t=this.data.array[e*this.data.stride+this.offset+3];return this.normalized&&(t=Js(t,this.array)),t}setXY(e,t,s){return e=e*this.data.stride+this.offset,this.normalized&&(t=Ks(t,this.array),s=Ks(s,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=s,this}setXYZ(e,t,s,i){return e=e*this.data.stride+this.offset,this.normalized&&(t=Ks(t,this.array),s=Ks(s,this.array),i=Ks(i,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=s,this.data.array[e+2]=i,this}setXYZW(e,t,s,i,r){return e=e*this.data.stride+this.offset,this.normalized&&(t=Ks(t,this.array),s=Ks(s,this.array),i=Ks(i,this.array),r=Ks(r,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=s,this.data.array[e+2]=i,this.data.array[e+3]=r,this}clone(e){if(void 0===e){console.log("THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let t=0;t<this.count;t++){const s=t*this.data.stride+this.offset;for(let t=0;t<this.itemSize;t++)e.push(this.data.array[s+t])}return new cn(new this.array.constructor(e),this.itemSize,this.normalized)}return void 0===e.interleavedBuffers&&(e.interleavedBuffers={}),void 0===e.interleavedBuffers[this.data.uuid]&&(e.interleavedBuffers[this.data.uuid]=this.data.clone(e)),new ho(e.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(e){if(void 0===e){console.log("THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let t=0;t<this.count;t++){const s=t*this.data.stride+this.offset;for(let t=0;t<this.itemSize;t++)e.push(this.data.array[s+t])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:e,normalized:this.normalized}}return void 0===e.interleavedBuffers&&(e.interleavedBuffers={}),void 0===e.interleavedBuffers[this.data.uuid]&&(e.interleavedBuffers[this.data.uuid]=this.data.toJSON(e)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}class uo extends tn{constructor(e){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new Kr(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}let lo;const co=new Ei,po=new Ei,mo=new Ei,go=new ei,fo=new ei,yo=new or,xo=new Ei,bo=new Ei,vo=new Ei,To=new ei,_o=new ei,wo=new ei;class So extends Pr{constructor(e=new uo){if(super(),this.isSprite=!0,this.type="Sprite",void 0===lo){lo=new Cn;const e=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),t=new oo(e,5);lo.setIndex([0,1,2,0,2,3]),lo.setAttribute("position",new ho(t,3,0,!1)),lo.setAttribute("uv",new ho(t,2,3,!1))}this.geometry=lo,this.material=e,this.center=new ei(.5,.5)}raycast(e,t){null===e.camera&&console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),po.setFromMatrixScale(this.matrixWorld),yo.copy(e.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(e.camera.matrixWorldInverse,this.matrixWorld),mo.setFromMatrixPosition(this.modelViewMatrix),e.camera.isPerspectiveCamera&&!1===this.material.sizeAttenuation&&po.multiplyScalar(-mo.z);const s=this.material.rotation;let i,r;0!==s&&(r=Math.cos(s),i=Math.sin(s));const n=this.center;Mo(xo.set(-.5,-.5,0),mo,n,po,i,r),Mo(bo.set(.5,-.5,0),mo,n,po,i,r),Mo(vo.set(.5,.5,0),mo,n,po,i,r),To.set(0,0),_o.set(1,0),wo.set(1,1);let o=e.ray.intersectTriangle(xo,bo,vo,!1,co);if(null===o&&(Mo(bo.set(-.5,.5,0),mo,n,po,i,r),_o.set(0,1),o=e.ray.intersectTriangle(xo,vo,bo,!1,co),null===o))return;const a=e.ray.origin.distanceTo(co);a<e.near||a>e.far||t.push({distance:a,point:co.clone(),uv:$r.getInterpolation(co,xo,bo,vo,To,_o,wo,new ei),face:null,object:this})}copy(e,t){return super.copy(e,t),void 0!==e.center&&this.center.copy(e.center),this.material=e.material,this}}function Mo(e,t,s,i,r,n){go.subVectors(e,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),e.copy(t),e.x+=fo.x,e.y+=fo.y,e.applyMatrix4(yo)}const No=new Ei,Ao=new Ei;class Co extends Pr{constructor(){super(),this._currentLevel=0,this.type="LOD",Object.defineProperties(this,{levels:{enumerable:!0,value:[]},isLOD:{value:!0}}),this.autoUpdate=!0}copy(e){super.copy(e,!1);const t=e.levels;for(let e=0,s=t.length;e<s;e++){const s=t[e];this.addLevel(s.object.clone(),s.distance,s.hysteresis)}return this.autoUpdate=e.autoUpdate,this}addLevel(e,t=0,s=0){t=Math.abs(t);const i=this.levels;let r;for(r=0;r<i.length&&!(t<i[r].distance);r++);return i.splice(r,0,{distance:t,hysteresis:s,object:e}),this.add(e),this}removeLevel(e){const t=this.levels;for(let s=0;s<t.length;s++)if(t[s].distance===e){const e=t.splice(s,1);return this.remove(e[0].object),!0}return!1}getCurrentLevel(){return this._currentLevel}getObjectForDistance(e){const t=this.levels;if(t.length>0){let s,i;for(s=1,i=t.length;s<i;s++){let i=t[s].distance;if(t[s].object.visible&&(i-=i*t[s].hysteresis),e<i)break}return t[s-1].object}return null}raycast(e,t){if(this.levels.length>0){No.setFromMatrixPosition(this.matrixWorld);const s=e.ray.origin.distanceTo(No);this.getObjectForDistance(s).raycast(e,t)}}update(e){const t=this.levels;if(t.length>1){No.setFromMatrixPosition(e.matrixWorld),Ao.setFromMatrixPosition(this.matrixWorld);const s=No.distanceTo(Ao)/e.zoom;let i,r;for(t[0].object.visible=!0,i=1,r=t.length;i<r;i++){let e=t[i].distance;if(t[i].object.visible&&(e-=e*t[i].hysteresis),!(s>=e))break;t[i-1].object.visible=!1,t[i].object.visible=!0}for(this._currentLevel=i-1;i<r;i++)t[i].object.visible=!1}}toJSON(e){const t=super.toJSON(e);!1===this.autoUpdate&&(t.object.autoUpdate=!1),t.object.levels=[];const s=this.levels;for(let e=0,i=s.length;e<i;e++){const i=s[e];t.object.levels.push({object:i.object.uuid,distance:i.distance,hysteresis:i.hysteresis})}return t}}const Ro=new Ei,Eo=new _i,Bo=new _i,Io=new Ei,Po=new or,Fo=new Ei,zo=new Ji,Uo=new or,Oo=new nr;class Lo extends Dn{constructor(e,t){super(e,t),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=ne,this.bindMatrix=new or,this.bindMatrixInverse=new or,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const e=this.geometry;null===this.boundingBox&&(this.boundingBox=new Pi),this.boundingBox.makeEmpty();const t=e.getAttribute("position");for(let e=0;e<t.count;e++)this.getVertexPosition(e,Fo),this.boundingBox.expandByPoint(Fo)}computeBoundingSphere(){const e=this.geometry;null===this.boundingSphere&&(this.boundingSphere=new Ji),this.boundingSphere.makeEmpty();const t=e.getAttribute("position");for(let e=0;e<t.count;e++)this.getVertexPosition(e,Fo),this.boundingSphere.expandByPoint(Fo)}copy(e,t){return super.copy(e,t),this.bindMode=e.bindMode,this.bindMatrix.copy(e.bindMatrix),this.bindMatrixInverse.copy(e.bindMatrixInverse),this.skeleton=e.skeleton,null!==e.boundingBox&&(this.boundingBox=e.boundingBox.clone()),null!==e.boundingSphere&&(this.boundingSphere=e.boundingSphere.clone()),this}raycast(e,t){const s=this.material,i=this.matrixWorld;void 0!==s&&(null===this.boundingSphere&&this.computeBoundingSphere(),zo.copy(this.boundingSphere),zo.applyMatrix4(i),!1!==e.ray.intersectsSphere(zo)&&(Uo.copy(i).invert(),Oo.copy(e.ray).applyMatrix4(Uo),null!==this.boundingBox&&!1===Oo.intersectsBox(this.boundingBox)||this._computeIntersections(e,t,Oo)))}getVertexPosition(e,t){return super.getVertexPosition(e,t),this.applyBoneTransform(e,t),t}bind(e,t){this.skeleton=e,void 0===t&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),t=this.matrixWorld),this.bindMatrix.copy(t),this.bindMatrixInverse.copy(t).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const e=new _i,t=this.geometry.attributes.skinWeight;for(let s=0,i=t.count;s<i;s++){e.fromBufferAttribute(t,s);const i=1/e.manhattanLength();i!==1/0?e.multiplyScalar(i):e.set(1,0,0,0),t.setXYZW(s,e.x,e.y,e.z,e.w)}}updateMatrixWorld(e){super.updateMatrixWorld(e),this.bindMode===ne?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===oe?this.bindMatrixInverse.copy(this.bindMatrix).invert():console.warn("THREE.SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(e,t){const s=this.skeleton,i=this.geometry;Eo.fromBufferAttribute(i.attributes.skinIndex,e),Bo.fromBufferAttribute(i.attributes.skinWeight,e),Ro.copy(t).applyMatrix4(this.bindMatrix),t.set(0,0,0);for(let e=0;e<4;e++){const i=Bo.getComponent(e);if(0!==i){const r=Eo.getComponent(e);Po.multiplyMatrices(s.bones[r].matrixWorld,s.boneInverses[r]),t.addScaledVector(Io.copy(Ro).applyMatrix4(Po),i)}}return t.applyMatrix4(this.bindMatrixInverse)}}class Vo extends Pr{constructor(){super(),this.isBone=!0,this.type="Bone"}}class Do extends Ti{constructor(e=null,t=1,s=1,i,r,n,o,a,h=1003,u=1003,l,c){super(null,n,o,a,h,u,i,r,l,c),this.isDataTexture=!0,this.image={data:e,width:t,height:s},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const ko=new or,Go=new or;class Wo{constructor(e=[],t=[]){this.uuid=$s(),this.bones=e.slice(0),this.boneInverses=t,this.boneMatrices=null,this.boneTexture=null,this.init()}init(){const e=this.bones,t=this.boneInverses;if(this.boneMatrices=new Float32Array(16*e.length),0===t.length)this.calculateInverses();else if(e.length!==t.length){console.warn("THREE.Skeleton: Number of inverse bone matrices does not match amount of bones."),this.boneInverses=[];for(let e=0,t=this.bones.length;e<t;e++)this.boneInverses.push(new or)}}calculateInverses(){this.boneInverses.length=0;for(let e=0,t=this.bones.length;e<t;e++){const t=new or;this.bones[e]&&t.copy(this.bones[e].matrixWorld).invert(),this.boneInverses.push(t)}}pose(){for(let e=0,t=this.bones.length;e<t;e++){const t=this.bones[e];t&&t.matrixWorld.copy(this.boneInverses[e]).invert()}for(let e=0,t=this.bones.length;e<t;e++){const t=this.bones[e];t&&(t.parent&&t.parent.isBone?(t.matrix.copy(t.parent.matrixWorld).invert(),t.matrix.multiply(t.matrixWorld)):t.matrix.copy(t.matrixWorld),t.matrix.decompose(t.position,t.quaternion,t.scale))}}update(){const e=this.bones,t=this.boneInverses,s=this.boneMatrices,i=this.boneTexture;for(let i=0,r=e.length;i<r;i++){const r=e[i]?e[i].matrixWorld:Go;ko.multiplyMatrices(r,t[i]),ko.toArray(s,16*i)}null!==i&&(i.needsUpdate=!0)}clone(){return new Wo(this.bones,this.boneInverses)}computeBoneTexture(){let e=Math.sqrt(4*this.bones.length);e=4*Math.ceil(e/4),e=Math.max(e,4);const t=new Float32Array(e*e*4);t.set(this.boneMatrices);const s=new Do(t,e,e,ke,Ie);return s.needsUpdate=!0,this.boneMatrices=t,this.boneTexture=s,this}getBoneByName(e){for(let t=0,s=this.bones.length;t<s;t++){const s=this.bones[t];if(s.name===e)return s}}dispose(){null!==this.boneTexture&&(this.boneTexture.dispose(),this.boneTexture=null)}fromJSON(e,t){this.uuid=e.uuid;for(let s=0,i=e.bones.length;s<i;s++){const i=e.bones[s];let r=t[i];void 0===r&&(console.warn("THREE.Skeleton: No bone found with UUID:",i),r=new Vo),this.bones.push(r),this.boneInverses.push((new or).fromArray(e.boneInverses[s]))}return this.init(),this}toJSON(){const e={metadata:{version:4.6,type:"Skeleton",generator:"Skeleton.toJSON"},bones:[],boneInverses:[]};e.uuid=this.uuid;const t=this.bones,s=this.boneInverses;for(let i=0,r=t.length;i<r;i++){const r=t[i];e.bones.push(r.uuid);const n=s[i];e.boneInverses.push(n.toArray())}return e}}class Ho extends cn{constructor(e,t,s,i=1){super(e,t,s),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=i}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}toJSON(){const e=super.toJSON();return e.meshPerAttribute=this.meshPerAttribute,e.isInstancedBufferAttribute=!0,e}}const jo=new or,qo=new or,$o=[],Xo=new Pi,Yo=new or,Zo=new Dn,Jo=new Ji;class Ko extends Dn{constructor(e,t,s){super(e,t),this.isInstancedMesh=!0,this.instanceMatrix=new Ho(new Float32Array(16*s),16),this.instanceColor=null,this.morphTexture=null,this.count=s,this.boundingBox=null,this.boundingSphere=null;for(let e=0;e<s;e++)this.setMatrixAt(e,Yo)}computeBoundingBox(){const e=this.geometry,t=this.count;null===this.boundingBox&&(this.boundingBox=new Pi),null===e.boundingBox&&e.computeBoundingBox(),this.boundingBox.makeEmpty();for(let s=0;s<t;s++)this.getMatrixAt(s,jo),Xo.copy(e.boundingBox).applyMatrix4(jo),this.boundingBox.union(Xo)}computeBoundingSphere(){const e=this.geometry,t=this.count;null===this.boundingSphere&&(this.boundingSphere=new Ji),null===e.boundingSphere&&e.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let s=0;s<t;s++)this.getMatrixAt(s,jo),Jo.copy(e.boundingSphere).applyMatrix4(jo),this.boundingSphere.union(Jo)}copy(e,t){return super.copy(e,t),this.instanceMatrix.copy(e.instanceMatrix),null!==e.morphTexture&&(this.morphTexture=e.morphTexture.clone()),null!==e.instanceColor&&(this.instanceColor=e.instanceColor.clone()),this.count=e.count,null!==e.boundingBox&&(this.boundingBox=e.boundingBox.clone()),null!==e.boundingSphere&&(this.boundingSphere=e.boundingSphere.clone()),this}getColorAt(e,t){t.fromArray(this.instanceColor.array,3*e)}getMatrixAt(e,t){t.fromArray(this.instanceMatrix.array,16*e)}getMorphAt(e,t){const s=t.morphTargetInfluences,i=this.morphTexture.source.data.data,r=e*(s.length+1)+1;for(let e=0;e<s.length;e++)s[e]=i[r+e]}raycast(e,t){const s=this.matrixWorld,i=this.count;if(Zo.geometry=this.geometry,Zo.material=this.material,void 0!==Zo.material&&(null===this.boundingSphere&&this.computeBoundingSphere(),Jo.copy(this.boundingSphere),Jo.applyMatrix4(s),!1!==e.ray.intersectsSphere(Jo)))for(let r=0;r<i;r++){this.getMatrixAt(r,jo),qo.multiplyMatrices(s,jo),Zo.matrixWorld=qo,Zo.raycast(e,$o);for(let e=0,s=$o.length;e<s;e++){const s=$o[e];s.instanceId=r,s.object=this,t.push(s)}$o.length=0}}setColorAt(e,t){null===this.instanceColor&&(this.instanceColor=new Ho(new Float32Array(3*this.instanceMatrix.count).fill(1),3)),t.toArray(this.instanceColor.array,3*e)}setMatrixAt(e,t){t.toArray(this.instanceMatrix.array,16*e)}setMorphAt(e,t){const s=t.morphTargetInfluences,i=s.length+1;null===this.morphTexture&&(this.morphTexture=new Do(new Float32Array(i*this.count),i,this.count,qe,Ie));const r=this.morphTexture.source.data.data;let n=0;for(let e=0;e<s.length;e++)n+=s[e];const o=this.geometry.morphTargetsRelative?1:1-n,a=i*e;r[a]=o,r.set(s,a+1)}updateMorphTargets(){}dispose(){return this.dispatchEvent({type:"dispose"}),null!==this.morphTexture&&(this.morphTexture.dispose(),this.morphTexture=null),this}}const Qo=new Ei,ea=new Ei,ta=new ti;class sa{constructor(e=new Ei(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,s,i){return this.normal.set(e,t,s),this.constant=i,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,s){const i=Qo.subVectors(s,t).cross(ea.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(i,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){const e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t){const s=e.delta(Qo),i=this.normal.dot(s);if(0===i)return 0===this.distanceToPoint(e.start)?t.copy(e.start):null;const r=-(e.start.dot(this.normal)+this.constant)/i;return r<0||r>1?null:t.copy(e.start).addScaledVector(s,r)}intersectsLine(e){const t=this.distanceToPoint(e.start),s=this.distanceToPoint(e.end);return t<0&&s>0||s<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){const s=t||ta.getNormalMatrix(e),i=this.coplanarPoint(Qo).applyMatrix4(e),r=this.normal.applyMatrix3(s).normalize();return this.constant=-i.dot(r),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return(new this.constructor).copy(this)}}const ia=new Ji,ra=new Ei;class na{constructor(e=new sa,t=new sa,s=new sa,i=new sa,r=new sa,n=new sa){this.planes=[e,t,s,i,r,n]}set(e,t,s,i,r,n){const o=this.planes;return o[0].copy(e),o[1].copy(t),o[2].copy(s),o[3].copy(i),o[4].copy(r),o[5].copy(n),this}copy(e){const t=this.planes;for(let s=0;s<6;s++)t[s].copy(e.planes[s]);return this}setFromProjectionMatrix(e,t=2e3){const s=this.planes,i=e.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(),t===Ds)s[5].setComponents(a+o,c+l,g+m,b+x).normalize();else{if(t!==ks)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);s[5].setComponents(o,l,m,x).normalize()}return this}intersectsObject(e){if(void 0!==e.boundingSphere)null===e.boundingSphere&&e.computeBoundingSphere(),ia.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{const t=e.geometry;null===t.boundingSphere&&t.computeBoundingSphere(),ia.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(ia)}intersectsSprite(e){return ia.center.set(0,0,0),ia.radius=.7071067811865476,ia.applyMatrix4(e.matrixWorld),this.intersectsSphere(ia)}intersectsSphere(e){const t=this.planes,s=e.center,i=-e.radius;for(let e=0;e<6;e++){if(t[e].distanceToPoint(s)<i)return!1}return!0}intersectsBox(e){const t=this.planes;for(let s=0;s<6;s++){const i=t[s];if(ra.x=i.normal.x>0?e.max.x:e.min.x,ra.y=i.normal.y>0?e.max.y:e.min.y,ra.z=i.normal.z>0?e.max.z:e.min.z,i.distanceToPoint(ra)<0)return!1}return!0}containsPoint(e){const t=this.planes;for(let s=0;s<6;s++)if(t[s].distanceToPoint(e)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function oa(e,t){return e.z-t.z}function aa(e,t){return t.z-e.z}class ha{constructor(){this.index=0,this.pool=[],this.list=[]}push(e,t,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=e.start,n.count=e.count,n.z=t,n.index=s}reset(){this.list.length=0,this.index=0}}const ua=new or,la=new or,ca=new or,da=new Kr(1,1,1),pa=new or,ma=new na,ga=new Pi,fa=new Ji,ya=new Ei,xa=new Ei,ba=new Ei,va=new ha,Ta=new Dn,_a=[];function wa(e,t,s=0){const i=t.itemSize;if(e.isInterleavedBufferAttribute||e.array.constructor!==t.array.constructor){const r=e.count;for(let n=0;n<r;n++)for(let r=0;r<i;r++)t.setComponent(n+s,r,e.getComponent(n,r))}else t.array.set(e.array,s*i);t.needsUpdate=!0}class Sa extends Dn{get maxInstanceCount(){return this._maxInstanceCount}constructor(e,t,s=2*t,i){super(new Cn,i),this.isBatchedMesh=!0,this.perObjectFrustumCulled=!0,this.sortObjects=!0,this.boundingBox=null,this.boundingSphere=null,this.customSort=null,this._drawInfo=[],this._availableInstanceIds=[],this._drawRanges=[],this._reservedRanges=[],this._bounds=[],this._maxInstanceCount=e,this._maxVertexCount=t,this._maxIndexCount=s,this._geometryInitialized=!1,this._geometryCount=0,this._multiDrawCounts=new Int32Array(e),this._multiDrawStarts=new Int32Array(e),this._multiDrawCount=0,this._multiDrawInstances=null,this._visibilityChanged=!0,this._matricesTexture=null,this._indirectTexture=null,this._colorsTexture=null,this._initMatricesTexture(),this._initIndirectTexture()}_initMatricesTexture(){let e=Math.sqrt(4*this._maxInstanceCount);e=4*Math.ceil(e/4),e=Math.max(e,4);const t=new Float32Array(e*e*4),s=new Do(t,e,e,ke,Ie);this._matricesTexture=s}_initIndirectTexture(){let e=Math.sqrt(this._maxInstanceCount);e=Math.ceil(e);const t=new Uint32Array(e*e),s=new Do(t,e,e,$e,Be);this._indirectTexture=s}_initColorsTexture(){let e=Math.sqrt(this._maxInstanceCount);e=Math.ceil(e);const t=new Float32Array(e*e*4).fill(1),s=new Do(t,e,e,ke,Ie);s.colorSpace=di.workingColorSpace,this._colorsTexture=s}_initializeGeometry(e){const t=this.geometry,s=this._maxVertexCount,i=this._maxIndexCount;if(!1===this._geometryInitialized){for(const i in e.attributes){const r=e.getAttribute(i),{array:n,itemSize:o,normalized:a}=r,h=new n.constructor(s*o),u=new cn(h,o,a);t.setAttribute(i,u)}if(null!==e.getIndex()){const e=s>65535?new Uint32Array(i):new Uint16Array(i);t.setIndex(new cn(e,1))}this._geometryInitialized=!0}}_validateGeometry(e){const t=this.geometry;if(Boolean(e.getIndex())!==Boolean(t.getIndex()))throw new Error('BatchedMesh: All geometries must consistently have "index".');for(const s in t.attributes){if(!e.hasAttribute(s))throw new Error(`BatchedMesh: Added geometry missing "${s}". All geometries must have consistent attributes.`);const i=e.getAttribute(s),r=t.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(e){return this.customSort=e,this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Pi);const e=this.boundingBox,t=this._drawInfo;e.makeEmpty();for(let s=0,i=t.length;s<i;s++){if(!1===t[s].active)continue;const i=t[s].geometryIndex;this.getMatrixAt(s,ua),this.getBoundingBoxAt(i,ga).applyMatrix4(ua),e.union(ga)}}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new Ji);const e=this.boundingSphere,t=this._drawInfo;e.makeEmpty();for(let s=0,i=t.length;s<i;s++){if(!1===t[s].active)continue;const i=t[s].geometryIndex;this.getMatrixAt(s,ua),this.getBoundingSphereAt(i,fa).applyMatrix4(ua),e.union(fa)}}addInstance(e){if(this._drawInfo.length>=this.maxInstanceCount&&0===this._availableInstanceIds.length)throw new Error("BatchedMesh: Maximum item count reached.");const t={visible:!0,active:!0,geometryIndex:e};let s=null;this._availableInstanceIds.length>0?(s=this._availableInstanceIds.pop(),this._drawInfo[s]=t):(s=this._drawInfo.length,this._drawInfo.push(t));const i=this._matricesTexture,r=i.image.data;ca.toArray(r,16*s),i.needsUpdate=!0;const n=this._colorsTexture;return n&&(da.toArray(n.image.data,4*s),n.needsUpdate=!0),s}addGeometry(e,t=-1,s=-1){if(this._initializeGeometry(e),this._validateGeometry(e),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===t?e.getAttribute("position").count:t,i.vertexStart=null===r?0:r.vertexStart+r.vertexCount;const h=e.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 Ji}),this.setGeometryAt(l,e),l}setGeometryAt(e,t){if(e>=this._geometryCount)throw new Error("BatchedMesh: Maximum geometry count reached.");this._validateGeometry(t);const s=this.geometry,i=null!==s.getIndex(),r=s.getIndex(),n=t.getIndex(),o=this._reservedRanges[e];if(i&&n.count>o.indexCount||t.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 e in s.attributes){const i=t.getAttribute(e),r=s.getAttribute(e);wa(i,r,a);const n=i.itemSize;for(let e=i.count,t=h;e<t;e++){const t=a+e;for(let e=0;e<n;e++)r.setComponent(t,e,0)}r.needsUpdate=!0,r.addUpdateRange(a*n,h*n)}if(i){const e=o.indexStart;for(let t=0;t<n.count;t++)r.setX(e+t,a+n.getX(t));for(let t=n.count,s=o.indexCount;t<s;t++)r.setX(e+t,a);r.needsUpdate=!0,r.addUpdateRange(e,o.indexCount)}const u=this._bounds[e];null!==t.boundingBox?(u.box.copy(t.boundingBox),u.boxInitialized=!0):u.boxInitialized=!1,null!==t.boundingSphere?(u.sphere.copy(t.boundingSphere),u.sphereInitialized=!0):u.sphereInitialized=!1;const l=this._drawRanges[e],c=t.getAttribute("position");return l.count=i?n.count:c.count,this._visibilityChanged=!0,e}deleteInstance(e){const t=this._drawInfo;return e>=t.length||!1===t[e].active||(t[e].active=!1,this._availableInstanceIds.push(e),this._visibilityChanged=!0),this}getBoundingBoxAt(e,t){if(e>=this._geometryCount)return null;const s=this._bounds[e],i=s.box,r=this.geometry;if(!1===s.boxInitialized){i.makeEmpty();const t=r.index,n=r.attributes.position,o=this._drawRanges[e];for(let e=o.start,s=o.start+o.count;e<s;e++){let s=e;t&&(s=t.getX(s)),i.expandByPoint(ya.fromBufferAttribute(n,s))}s.boxInitialized=!0}return t.copy(i),t}getBoundingSphereAt(e,t){if(e>=this._geometryCount)return null;const s=this._bounds[e],i=s.sphere,r=this.geometry;if(!1===s.sphereInitialized){i.makeEmpty(),this.getBoundingBoxAt(e,ga),ga.getCenter(i.center);const t=r.index,n=r.attributes.position,o=this._drawRanges[e];let a=0;for(let e=o.start,s=o.start+o.count;e<s;e++){let s=e;t&&(s=t.getX(s)),ya.fromBufferAttribute(n,s),a=Math.max(a,i.center.distanceToSquared(ya))}i.radius=Math.sqrt(a),s.sphereInitialized=!0}return t.copy(i),t}setMatrixAt(e,t){const s=this._drawInfo,i=this._matricesTexture,r=this._matricesTexture.image.data;return e>=s.length||!1===s[e].active||(t.toArray(r,16*e),i.needsUpdate=!0),this}getMatrixAt(e,t){const s=this._drawInfo,i=this._matricesTexture.image.data;return e>=s.length||!1===s[e].active?null:t.fromArray(i,16*e)}setColorAt(e,t){null===this._colorsTexture&&this._initColorsTexture();const s=this._colorsTexture,i=this._colorsTexture.image.data,r=this._drawInfo;return e>=r.length||!1===r[e].active||(t.toArray(i,4*e),s.needsUpdate=!0),this}getColorAt(e,t){const s=this._colorsTexture.image.data,i=this._drawInfo;return e>=i.length||!1===i[e].active?null:t.fromArray(s,4*e)}setVisibleAt(e,t){const s=this._drawInfo;return e>=s.length||!1===s[e].active||s[e].visible===t||(s[e].visible=t,this._visibilityChanged=!0),this}getVisibleAt(e){const t=this._drawInfo;return!(e>=t.length||!1===t[e].active)&&t[e].visible}setGeometryIdAt(e,t){const s=this._drawInfo;return e>=s.length||!1===s[e].active||t<0||t>=this._geometryCount?null:(s[e].geometryIndex=t,this)}getGeometryIdAt(e){const t=this._drawInfo;return e>=t.length||!1===t[e].active?-1:t[e].geometryIndex}getGeometryRangeAt(e,t={}){if(e<0||e>=this._geometryCount)return null;const s=this._drawRanges[e];return t.start=s.start,t.count=s.count,t}raycast(e,t){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 Ji);for(let n=0,o=s.length;n<o;n++){if(!s[n].visible||!s[n].active)continue;const o=s[n].geometryIndex,a=i[o];Ta.geometry.setDrawRange(a.start,a.count),this.getMatrixAt(n,Ta.matrixWorld).premultiply(r),this.getBoundingBoxAt(o,Ta.geometry.boundingBox),this.getBoundingSphereAt(o,Ta.geometry.boundingSphere),Ta.raycast(e,_a);for(let e=0,s=_a.length;e<s;e++){const s=_a[e];s.object=this,s.batchId=n,t.push(s)}_a.length=0}Ta.material=null,Ta.geometry.index=null,Ta.geometry.attributes={},Ta.geometry.setDrawRange(0,1/0)}copy(e){return super.copy(e),this.geometry=e.geometry.clone(),this.perObjectFrustumCulled=e.perObjectFrustumCulled,this.sortObjects=e.sortObjects,this.boundingBox=null!==e.boundingBox?e.boundingBox.clone():null,this.boundingSphere=null!==e.boundingSphere?e.boundingSphere.clone():null,this._drawRanges=e._drawRanges.map(e=>({...e})),this._reservedRanges=e._reservedRanges.map(e=>({...e})),this._drawInfo=e._drawInfo.map(e=>({...e})),this._bounds=e._bounds.map(e=>({boxInitialized:e.boxInitialized,box:e.box.clone(),sphereInitialized:e.sphereInitialized,sphere:e.sphere.clone()})),this._maxInstanceCount=e._maxInstanceCount,this._maxVertexCount=e._maxVertexCount,this._maxIndexCount=e._maxIndexCount,this._geometryInitialized=e._geometryInitialized,this._geometryCount=e._geometryCount,this._multiDrawCounts=e._multiDrawCounts.slice(),this._multiDrawStarts=e._multiDrawStarts.slice(),this._matricesTexture=e._matricesTexture.clone(),this._matricesTexture.image.data=this._matricesTexture.image.data.slice(),null!==this._colorsTexture&&(this._colorsTexture=e._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(e,t,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,e.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 e=0,t=a.length;e<t;e++)if(a[e].visible&&a[e].active){const t=a[e].geometryIndex;this.getMatrixAt(e,ua),this.getBoundingSphereAt(t,fa).applyMatrix4(ua);let s=!1;if(c&&(s=!ma.intersectsSphere(fa)),!s){const s=ba.subVectors(fa.center,ya).dot(xa);va.push(l[t],s,e)}}const e=va.list,t=this.customSort;null===t?e.sort(r.transparent?aa:oa):t.call(this,e,s);for(let t=0,s=e.length;t<s;t++){const s=e[t];h[m]=s.start*o,u[m]=s.count,p[m]=s.index,m++}va.reset()}else for(let e=0,t=a.length;e<t;e++)if(a[e].visible&&a[e].active){const t=a[e].geometryIndex;let s=!1;if(c&&(this.getMatrixAt(e,ua),this.getBoundingSphereAt(t,fa).applyMatrix4(ua),s=!ma.intersectsSphere(fa)),!s){const s=l[t];h[m]=s.start*o,u[m]=s.count,p[m]=e,m++}}d.needsUpdate=!0,this._multiDrawCount=m,this._visibilityChanged=!1}onBeforeShadow(e,t,s,i,r,n){this.onBeforeRender(e,null,i,r,n)}}class Ma extends tn{constructor(e){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new Kr(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.fog=e.fog,this}}const Na=new Ei,Aa=new Ei,Ca=new or,Ra=new nr,Ea=new Ji,Ba=new Ei,Ia=new Ei;class Pa extends Pr{constructor(e=new Cn,t=new Ma){super(),this.isLine=!0,this.type="Line",this.geometry=e,this.material=t,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}computeLineDistances(){const e=this.geometry;if(null===e.index){const t=e.attributes.position,s=[0];for(let e=1,i=t.count;e<i;e++)Na.fromBufferAttribute(t,e-1),Aa.fromBufferAttribute(t,e),s[e]=s[e-1],s[e]+=Na.distanceTo(Aa);e.setAttribute("lineDistance",new vn(s,1))}else console.warn("THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(e,t){const s=this.geometry,i=this.matrixWorld,r=e.params.Line.threshold,n=s.drawRange;if(null===s.boundingSphere&&s.computeBoundingSphere(),Ea.copy(s.boundingSphere),Ea.applyMatrix4(i),Ea.radius+=r,!1===e.ray.intersectsSphere(Ea))return;Ca.copy(i).invert(),Ra.copy(e.ray).applyMatrix4(Ca);const o=r/((this.scale.x+this.scale.y+this.scale.z)/3),a=o*o,h=this.isLineSegments?2:1,u=s.index,l=s.attributes.position;if(null!==u){const s=Math.max(0,n.start),i=Math.min(u.count,n.start+n.count);for(let r=s,n=i-1;r<n;r+=h){const s=u.getX(r),i=u.getX(r+1),n=Fa(this,e,Ra,a,s,i);n&&t.push(n)}if(this.isLineLoop){const r=u.getX(i-1),n=u.getX(s),o=Fa(this,e,Ra,a,r,n);o&&t.push(o)}}else{const s=Math.max(0,n.start),i=Math.min(l.count,n.start+n.count);for(let r=s,n=i-1;r<n;r+=h){const s=Fa(this,e,Ra,a,r,r+1);s&&t.push(s)}if(this.isLineLoop){const r=Fa(this,e,Ra,a,i-1,s);r&&t.push(r)}}}updateMorphTargets(){const e=this.geometry.morphAttributes,t=Object.keys(e);if(t.length>0){const s=e[t[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=s.length;e<t;e++){const t=s[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[t]=e}}}}}function Fa(e,t,s,i,r,n){const o=e.geometry.attributes.position;Na.fromBufferAttribute(o,r),Aa.fromBufferAttribute(o,n);if(s.distanceSqToSegment(Na,Aa,Ba,Ia)>i)return;Ba.applyMatrix4(e.matrixWorld);const a=t.ray.origin.distanceTo(Ba);return a<t.near||a>t.far?void 0:{distance:a,point:Ia.clone().applyMatrix4(e.matrixWorld),index:r,face:null,faceIndex:null,barycoord:null,object:e}}const za=new Ei,Ua=new Ei;class Oa extends Pa{constructor(e,t){super(e,t),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const e=this.geometry;if(null===e.index){const t=e.attributes.position,s=[];for(let e=0,i=t.count;e<i;e+=2)za.fromBufferAttribute(t,e),Ua.fromBufferAttribute(t,e+1),s[e]=0===e?0:s[e-1],s[e+1]=s[e]+za.distanceTo(Ua);e.setAttribute("lineDistance",new vn(s,1))}else console.warn("THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class La extends Pa{constructor(e,t){super(e,t),this.isLineLoop=!0,this.type="LineLoop"}}class Va extends tn{constructor(e){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new Kr(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.size=e.size,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}const Da=new or,ka=new nr,Ga=new Ji,Wa=new Ei;class Ha extends Pr{constructor(e=new Cn,t=new Va){super(),this.isPoints=!0,this.type="Points",this.geometry=e,this.material=t,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}raycast(e,t){const s=this.geometry,i=this.matrixWorld,r=e.params.Points.threshold,n=s.drawRange;if(null===s.boundingSphere&&s.computeBoundingSphere(),Ga.copy(s.boundingSphere),Ga.applyMatrix4(i),Ga.radius+=r,!1===e.ray.intersectsSphere(Ga))return;Da.copy(i).invert(),ka.copy(e.ray).applyMatrix4(Da);const o=r/((this.scale.x+this.scale.y+this.scale.z)/3),a=o*o,h=s.index,u=s.attributes.position;if(null!==h){for(let s=Math.max(0,n.start),r=Math.min(h.count,n.start+n.count);s<r;s++){const r=h.getX(s);Wa.fromBufferAttribute(u,r),ja(Wa,r,a,i,e,t,this)}}else{for(let s=Math.max(0,n.start),r=Math.min(u.count,n.start+n.count);s<r;s++)Wa.fromBufferAttribute(u,s),ja(Wa,s,a,i,e,t,this)}}updateMorphTargets(){const e=this.geometry.morphAttributes,t=Object.keys(e);if(t.length>0){const s=e[t[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=s.length;e<t;e++){const t=s[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[t]=e}}}}}function ja(e,t,s,i,r,n,o){const a=ka.distanceSqToPoint(e);if(a<s){const s=new Ei;ka.closestPointToPoint(e,s),s.applyMatrix4(i);const h=r.ray.origin.distanceTo(s);if(h<r.near||h>r.far)return;n.push({distance:h,distanceToRay:Math.sqrt(a),point:s,index:t,face:null,faceIndex:null,barycoord:null,object:o})}}class qa extends Pr{constructor(){super(),this.isGroup=!0,this.type="Group"}}class $a extends Ti{constructor(e,t,s,i,r,n,o,a,h){super(e,t,s,i,r,n,o,a,h),this.isVideoTexture=!0,this.minFilter=void 0!==n?n:Te,this.magFilter=void 0!==r?r:Te,this.generateMipmaps=!1;const u=this;"requestVideoFrameCallback"in e&&e.requestVideoFrameCallback(function t(){u.needsUpdate=!0,e.requestVideoFrameCallback(t)})}clone(){return new this.constructor(this.image).copy(this)}update(){const e=this.image;!1==="requestVideoFrameCallback"in e&&e.readyState>=e.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}}class Xa extends Ti{constructor(e,t){super({width:e,height:t}),this.isFramebufferTexture=!0,this.magFilter=fe,this.minFilter=fe,this.generateMipmaps=!1,this.needsUpdate=!0}}class Ya extends Ti{constructor(e,t,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:t,height:s},this.mipmaps=e,this.flipY=!1,this.generateMipmaps=!1}}class Za extends Ya{constructor(e,t,s,i,r,n){super(e,t,s,r,n),this.isCompressedArrayTexture=!0,this.image.depth=i,this.wrapR=me,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}}class Ja extends Ya{constructor(e,t,s){super(void 0,e[0].width,e[0].height,t,s,he),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=e}}class Ka extends Ti{constructor(e,t,s,i,r,n,o,a,h){super(e,t,s,i,r,n,o,a,h),this.isCanvasTexture=!0,this.needsUpdate=!0}}class Qa extends Ti{constructor(e,t,s,i,r,n,o,a,h,u=1026){if(u!==He&&u!==je)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===s&&u===He&&(s=Be),void 0===s&&u===je&&(s=Ue),super(null,i,r,n,o,a,u,s,h),this.isDepthTexture=!0,this.image={width:e,height:t},this.magFilter=void 0!==o?o:fe,this.minFilter=void 0!==a?a:fe,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.compareFunction=e.compareFunction,this}toJSON(e){const t=super.toJSON(e);return null!==this.compareFunction&&(t.compareFunction=this.compareFunction),t}}class eh{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(e,t){const s=this.getUtoTmapping(e);return this.getPoint(s,t)}getPoints(e=5){const t=[];for(let s=0;s<=e;s++)t.push(this.getPoint(s/e));return t}getSpacedPoints(e=5){const t=[];for(let s=0;s<=e;s++)t.push(this.getPointAt(s/e));return t}getLength(){const e=this.getLengths();return e[e.length-1]}getLengths(e=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const t=[];let s,i=this.getPoint(0),r=0;t.push(0);for(let n=1;n<=e;n++)s=this.getPoint(n/e),r+=s.distanceTo(i),t.push(r),i=s;return this.cacheArcLengths=t,t}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(e,t){const s=this.getLengths();let i=0;const r=s.length;let n;n=t||e*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(e,t){const s=1e-4;let i=e-s,r=e+s;i<0&&(i=0),r>1&&(r=1);const n=this.getPoint(i),o=this.getPoint(r),a=t||(n.isVector2?new ei:new Ei);return a.copy(o).sub(n).normalize(),a}getTangentAt(e,t){const s=this.getUtoTmapping(e);return this.getTangent(s,t)}computeFrenetFrames(e,t){const s=new Ei,i=[],r=[],n=[],o=new Ei,a=new or;for(let t=0;t<=e;t++){const s=t/e;i[t]=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 t=1;t<=e;t++){if(r[t]=r[t-1].clone(),n[t]=n[t-1].clone(),o.crossVectors(i[t-1],i[t]),o.length()>Number.EPSILON){o.normalize();const e=Math.acos(Xs(i[t-1].dot(i[t]),-1,1));r[t].applyMatrix4(a.makeRotationAxis(o,e))}n[t].crossVectors(i[t],r[t])}if(!0===t){let t=Math.acos(Xs(r[0].dot(r[e]),-1,1));t/=e,i[0].dot(o.crossVectors(r[0],r[e]))>0&&(t=-t);for(let s=1;s<=e;s++)r[s].applyMatrix4(a.makeRotationAxis(i[s],t*s)),n[s].crossVectors(i[s],r[s])}return{tangents:i,normals:r,binormals:n}}clone(){return(new this.constructor).copy(this)}copy(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}toJSON(){const e={metadata:{version:4.6,type:"Curve",generator:"Curve.toJSON"}};return e.arcLengthDivisions=this.arcLengthDivisions,e.type=this.type,e}fromJSON(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}}class th extends eh{constructor(e=0,t=0,s=1,i=1,r=0,n=2*Math.PI,o=!1,a=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=e,this.aY=t,this.xRadius=s,this.yRadius=i,this.aStartAngle=r,this.aEndAngle=n,this.aClockwise=o,this.aRotation=a}getPoint(e,t=new ei){const s=t,i=2*Math.PI;let r=this.aEndAngle-this.aStartAngle;const n=Math.abs(r)<Number.EPSILON;for(;r<0;)r+=i;for(;r>i;)r-=i;r<Number.EPSILON&&(r=n?0:i),!0!==this.aClockwise||n||(r===i?r=-i:r-=i);const o=this.aStartAngle+e*r;let a=this.aX+this.xRadius*Math.cos(o),h=this.aY+this.yRadius*Math.sin(o);if(0!==this.aRotation){const e=Math.cos(this.aRotation),t=Math.sin(this.aRotation),s=a-this.aX,i=h-this.aY;a=s*e-i*t+this.aX,h=s*t+i*e+this.aY}return s.set(a,h)}copy(e){return super.copy(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}toJSON(){const e=super.toJSON();return e.aX=this.aX,e.aY=this.aY,e.xRadius=this.xRadius,e.yRadius=this.yRadius,e.aStartAngle=this.aStartAngle,e.aEndAngle=this.aEndAngle,e.aClockwise=this.aClockwise,e.aRotation=this.aRotation,e}fromJSON(e){return super.fromJSON(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}}class sh extends th{constructor(e,t,s,i,r,n){super(e,t,s,s,i,r,n),this.isArcCurve=!0,this.type="ArcCurve"}}function ih(){let e=0,t=0,s=0,i=0;function r(r,n,o,a){e=r,t=o,s=-3*r+3*n-2*o-a,i=2*r-2*n+o+a}return{initCatmullRom:function(e,t,s,i,n){r(t,s,n*(s-e),n*(i-t))},initNonuniformCatmullRom:function(e,t,s,i,n,o,a){let h=(t-e)/n-(s-e)/(n+o)+(s-t)/o,u=(s-t)/o-(i-t)/(o+a)+(i-s)/a;h*=o,u*=o,r(t,s,h,u)},calc:function(r){const n=r*r;return e+t*r+s*n+i*(n*r)}}}const rh=new Ei,nh=new ih,oh=new ih,ah=new ih;class hh extends eh{constructor(e=[],t=!1,s="centripetal",i=.5){super(),this.isCatmullRomCurve3=!0,this.type="CatmullRomCurve3",this.points=e,this.closed=t,this.curveType=s,this.tension=i}getPoint(e,t=new Ei){const s=t,i=this.points,r=i.length,n=(r-(this.closed?0:1))*e;let o,a,h=Math.floor(n),u=n-h;this.closed?h+=h>0?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+2<r?a=i[(h+2)%r]:(rh.subVectors(i[r-1],i[r-2]).add(i[r-1]),a=rh),"centripetal"===this.curveType||"chordal"===this.curveType){const e="chordal"===this.curveType?.5:.25;let t=Math.pow(o.distanceToSquared(l),e),s=Math.pow(l.distanceToSquared(c),e),i=Math.pow(c.distanceToSquared(a),e);s<1e-4&&(s=1),t<1e-4&&(t=s),i<1e-4&&(i=s),nh.initNonuniformCatmullRom(o.x,l.x,c.x,a.x,t,s,i),oh.initNonuniformCatmullRom(o.y,l.y,c.y,a.y,t,s,i),ah.initNonuniformCatmullRom(o.z,l.z,c.z,a.z,t,s,i)}else"catmullrom"===this.curveType&&(nh.initCatmullRom(o.x,l.x,c.x,a.x,this.tension),oh.initCatmullRom(o.y,l.y,c.y,a.y,this.tension),ah.initCatmullRom(o.z,l.z,c.z,a.z,this.tension));return s.set(nh.calc(u),oh.calc(u),ah.calc(u)),s}copy(e){super.copy(e),this.points=[];for(let t=0,s=e.points.length;t<s;t++){const s=e.points[t];this.points.push(s.clone())}return this.closed=e.closed,this.curveType=e.curveType,this.tension=e.tension,this}toJSON(){const e=super.toJSON();e.points=[];for(let t=0,s=this.points.length;t<s;t++){const s=this.points[t];e.points.push(s.toArray())}return e.closed=this.closed,e.curveType=this.curveType,e.tension=this.tension,e}fromJSON(e){super.fromJSON(e),this.points=[];for(let t=0,s=e.points.length;t<s;t++){const s=e.points[t];this.points.push((new Ei).fromArray(s))}return this.closed=e.closed,this.curveType=e.curveType,this.tension=e.tension,this}}function uh(e,t,s,i,r){const n=.5*(i-t),o=.5*(r-s),a=e*e;return(2*s-2*i+n+o)*(e*a)+(-3*s+3*i-2*n-o)*a+n*e+s}function lh(e,t,s,i){return function(e,t){const s=1-e;return s*s*t}(e,t)+function(e,t){return 2*(1-e)*e*t}(e,s)+function(e,t){return e*e*t}(e,i)}function ch(e,t,s,i,r){return function(e,t){const s=1-e;return s*s*s*t}(e,t)+function(e,t){const s=1-e;return 3*s*s*e*t}(e,s)+function(e,t){return 3*(1-e)*e*e*t}(e,i)+function(e,t){return e*e*e*t}(e,r)}class dh extends eh{constructor(e=new ei,t=new ei,s=new ei,i=new ei){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=e,this.v1=t,this.v2=s,this.v3=i}getPoint(e,t=new ei){const s=t,i=this.v0,r=this.v1,n=this.v2,o=this.v3;return s.set(ch(e,i.x,r.x,n.x,o.x),ch(e,i.y,r.y,n.y,o.y)),s}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e.v3=this.v3.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this.v3.fromArray(e.v3),this}}class ph extends eh{constructor(e=new Ei,t=new Ei,s=new Ei,i=new Ei){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=e,this.v1=t,this.v2=s,this.v3=i}getPoint(e,t=new Ei){const s=t,i=this.v0,r=this.v1,n=this.v2,o=this.v3;return s.set(ch(e,i.x,r.x,n.x,o.x),ch(e,i.y,r.y,n.y,o.y),ch(e,i.z,r.z,n.z,o.z)),s}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e.v3=this.v3.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this.v3.fromArray(e.v3),this}}class mh extends eh{constructor(e=new ei,t=new ei){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=e,this.v2=t}getPoint(e,t=new ei){const s=t;return 1===e?s.copy(this.v2):(s.copy(this.v2).sub(this.v1),s.multiplyScalar(e).add(this.v1)),s}getPointAt(e,t){return this.getPoint(e,t)}getTangent(e,t=new ei){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t){return this.getTangent(e,t)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class gh extends eh{constructor(e=new Ei,t=new Ei){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=e,this.v2=t}getPoint(e,t=new Ei){const s=t;return 1===e?s.copy(this.v2):(s.copy(this.v2).sub(this.v1),s.multiplyScalar(e).add(this.v1)),s}getPointAt(e,t){return this.getPoint(e,t)}getTangent(e,t=new Ei){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t){return this.getTangent(e,t)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class fh extends eh{constructor(e=new ei,t=new ei,s=new ei){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=e,this.v1=t,this.v2=s}getPoint(e,t=new ei){const s=t,i=this.v0,r=this.v1,n=this.v2;return s.set(lh(e,i.x,r.x,n.x),lh(e,i.y,r.y,n.y)),s}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class yh extends eh{constructor(e=new Ei,t=new Ei,s=new Ei){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=e,this.v1=t,this.v2=s}getPoint(e,t=new Ei){const s=t,i=this.v0,r=this.v1,n=this.v2;return s.set(lh(e,i.x,r.x,n.x),lh(e,i.y,r.y,n.y),lh(e,i.z,r.z,n.z)),s}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class xh extends eh{constructor(e=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=e}getPoint(e,t=new ei){const s=t,i=this.points,r=(i.length-1)*e,n=Math.floor(r),o=r-n,a=i[0===n?n:n-1],h=i[n],u=i[n>i.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(e){super.copy(e),this.points=[];for(let t=0,s=e.points.length;t<s;t++){const s=e.points[t];this.points.push(s.clone())}return this}toJSON(){const e=super.toJSON();e.points=[];for(let t=0,s=this.points.length;t<s;t++){const s=this.points[t];e.points.push(s.toArray())}return e}fromJSON(e){super.fromJSON(e),this.points=[];for(let t=0,s=e.points.length;t<s;t++){const s=e.points[t];this.points.push((new ei).fromArray(s))}return this}}var bh=Object.freeze({__proto__:null,ArcCurve:sh,CatmullRomCurve3:hh,CubicBezierCurve:dh,CubicBezierCurve3:ph,EllipseCurve:th,LineCurve:mh,LineCurve3:gh,QuadraticBezierCurve:fh,QuadraticBezierCurve3:yh,SplineCurve:xh});class vh extends eh{constructor(){super(),this.type="CurvePath",this.curves=[],this.autoClose=!1}add(e){this.curves.push(e)}closePath(){const e=this.curves[0].getPoint(0),t=this.curves[this.curves.length-1].getPoint(1);if(!e.equals(t)){const s=!0===e.isVector2?"LineCurve":"LineCurve3";this.curves.push(new bh[s](t,e))}return this}getPoint(e,t){const s=e*this.getLength(),i=this.getCurveLengths();let r=0;for(;r<i.length;){if(i[r]>=s){const e=i[r]-s,n=this.curves[r],o=n.getLength(),a=0===o?0:1-e/o;return n.getPointAt(a,t)}r++}return null}getLength(){const e=this.getCurveLengths();return e[e.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 e=[];let t=0;for(let s=0,i=this.curves.length;s<i;s++)t+=this.curves[s].getLength(),e.push(t);return this.cacheLengths=e,e}getSpacedPoints(e=40){const t=[];for(let s=0;s<=e;s++)t.push(this.getPoint(s/e));return this.autoClose&&t.push(t[0]),t}getPoints(e=12){const t=[];let s;for(let i=0,r=this.curves;i<r.length;i++){const n=r[i],o=n.isEllipseCurve?2*e:n.isLineCurve||n.isLineCurve3?1:n.isSplineCurve?e*n.points.length:e,a=n.getPoints(o);for(let e=0;e<a.length;e++){const i=a[e];s&&s.equals(i)||(t.push(i),s=i)}}return this.autoClose&&t.length>1&&!t[t.length-1].equals(t[0])&&t.push(t[0]),t}copy(e){super.copy(e),this.curves=[];for(let t=0,s=e.curves.length;t<s;t++){const s=e.curves[t];this.curves.push(s.clone())}return this.autoClose=e.autoClose,this}toJSON(){const e=super.toJSON();e.autoClose=this.autoClose,e.curves=[];for(let t=0,s=this.curves.length;t<s;t++){const s=this.curves[t];e.curves.push(s.toJSON())}return e}fromJSON(e){super.fromJSON(e),this.autoClose=e.autoClose,this.curves=[];for(let t=0,s=e.curves.length;t<s;t++){const s=e.curves[t];this.curves.push((new bh[s.type]).fromJSON(s))}return this}}class Th extends vh{constructor(e){super(),this.type="Path",this.currentPoint=new ei,e&&this.setFromPoints(e)}setFromPoints(e){this.moveTo(e[0].x,e[0].y);for(let t=1,s=e.length;t<s;t++)this.lineTo(e[t].x,e[t].y);return this}moveTo(e,t){return this.currentPoint.set(e,t),this}lineTo(e,t){const s=new mh(this.currentPoint.clone(),new ei(e,t));return this.curves.push(s),this.currentPoint.set(e,t),this}quadraticCurveTo(e,t,s,i){const r=new fh(this.currentPoint.clone(),new ei(e,t),new ei(s,i));return this.curves.push(r),this.currentPoint.set(s,i),this}bezierCurveTo(e,t,s,i,r,n){const o=new dh(this.currentPoint.clone(),new ei(e,t),new ei(s,i),new ei(r,n));return this.curves.push(o),this.currentPoint.set(r,n),this}splineThru(e){const t=[this.currentPoint.clone()].concat(e),s=new xh(t);return this.curves.push(s),this.currentPoint.copy(e[e.length-1]),this}arc(e,t,s,i,r,n){const o=this.currentPoint.x,a=this.currentPoint.y;return this.absarc(e+o,t+a,s,i,r,n),this}absarc(e,t,s,i,r,n){return this.absellipse(e,t,s,s,i,r,n),this}ellipse(e,t,s,i,r,n,o,a){const h=this.currentPoint.x,u=this.currentPoint.y;return this.absellipse(e+h,t+u,s,i,r,n,o,a),this}absellipse(e,t,s,i,r,n,o,a){const h=new th(e,t,s,i,r,n,o,a);if(this.curves.length>0){const e=h.getPoint(0);e.equals(this.currentPoint)||this.lineTo(e.x,e.y)}this.curves.push(h);const u=h.getPoint(1);return this.currentPoint.copy(u),this}copy(e){return super.copy(e),this.currentPoint.copy(e.currentPoint),this}toJSON(){const e=super.toJSON();return e.currentPoint=this.currentPoint.toArray(),e}fromJSON(e){return super.fromJSON(e),this.currentPoint.fromArray(e.currentPoint),this}}class _h extends Cn{constructor(e=[new ei(0,-.5),new ei(.5,0),new ei(0,.5)],t=12,s=0,i=2*Math.PI){super(),this.type="LatheGeometry",this.parameters={points:e,segments:t,phiStart:s,phiLength:i},t=Math.floor(t),i=Xs(i,0,2*Math.PI);const r=[],n=[],o=[],a=[],h=[],u=1/t,l=new Ei,c=new ei,d=new Ei,p=new Ei,m=new Ei;let g=0,f=0;for(let t=0;t<=e.length-1;t++)switch(t){case 0:g=e[t+1].x-e[t].x,f=e[t+1].y-e[t].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 e.length-1:a.push(m.x,m.y,m.z);break;default:g=e[t+1].x-e[t].x,f=e[t+1].y-e[t].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<=t;r++){const d=s+r*u*i,p=Math.sin(d),m=Math.cos(d);for(let s=0;s<=e.length-1;s++){l.x=e[s].x*p,l.y=e[s].y,l.z=e[s].x*m,n.push(l.x,l.y,l.z),c.x=r/t,c.y=s/(e.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;s<t;s++)for(let t=0;t<e.length-1;t++){const i=t+s*e.length,n=i,o=i+e.length,a=i+e.length+1,h=i+1;r.push(n,o,h),r.push(a,h,o)}this.setIndex(r),this.setAttribute("position",new vn(n,3)),this.setAttribute("uv",new vn(o,2)),this.setAttribute("normal",new vn(h,3))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new _h(e.points,e.segments,e.phiStart,e.phiLength)}}class wh extends _h{constructor(e=1,t=1,s=4,i=8){const r=new Th;r.absarc(0,-t/2,e,1.5*Math.PI,0),r.absarc(0,t/2,e,0,.5*Math.PI),super(r.getPoints(s),i),this.type="CapsuleGeometry",this.parameters={radius:e,length:t,capSegments:s,radialSegments:i}}static fromJSON(e){return new wh(e.radius,e.length,e.capSegments,e.radialSegments)}}class Sh extends Cn{constructor(e=1,t=32,s=0,i=2*Math.PI){super(),this.type="CircleGeometry",this.parameters={radius:e,segments:t,thetaStart:s,thetaLength:i},t=Math.max(3,t);const r=[],n=[],o=[],a=[],h=new Ei,u=new ei;n.push(0,0,0),o.push(0,0,1),a.push(.5,.5);for(let r=0,l=3;r<=t;r++,l+=3){const c=s+r/t*i;h.x=e*Math.cos(c),h.y=e*Math.sin(c),n.push(h.x,h.y,h.z),o.push(0,0,1),u.x=(n[l]/e+1)/2,u.y=(n[l+1]/e+1)/2,a.push(u.x,u.y)}for(let e=1;e<=t;e++)r.push(e,e+1,0);this.setIndex(r),this.setAttribute("position",new vn(n,3)),this.setAttribute("normal",new vn(o,3)),this.setAttribute("uv",new vn(a,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Sh(e.radius,e.segments,e.thetaStart,e.thetaLength)}}class Mh extends Cn{constructor(e=1,t=1,s=1,i=32,r=1,n=!1,o=0,a=2*Math.PI){super(),this.type="CylinderGeometry",this.parameters={radiusTop:e,radiusBottom:t,height:s,radialSegments:i,heightSegments:r,openEnded:n,thetaStart:o,thetaLength:a};const h=this;i=Math.floor(i),r=Math.floor(r);const u=[],l=[],c=[],d=[];let p=0;const m=[],g=s/2;let f=0;function y(s){const r=p,n=new ei,m=new Ei;let y=0;const x=!0===s?e:t,b=!0===s?1:-1;for(let e=1;e<=i;e++)l.push(0,g*b,0),c.push(0,b,0),d.push(.5,.5),p++;const v=p;for(let e=0;e<=i;e++){const t=e/i*a+o,s=Math.cos(t),r=Math.sin(t);m.x=x*r,m.y=g*b,m.z=x*s,l.push(m.x,m.y,m.z),c.push(0,b,0),n.x=.5*s+.5,n.y=.5*r*b+.5,d.push(n.x,n.y),p++}for(let e=0;e<i;e++){const t=r+e,i=v+e;!0===s?u.push(i,i+1,t):u.push(i+1,i,t),y+=3}h.addGroup(f,y,!0===s?1:2),f+=y}!function(){const n=new Ei,y=new Ei;let x=0;const b=(t-e)/s;for(let h=0;h<=r;h++){const u=[],f=h/r,x=f*(t-e)+e;for(let e=0;e<=i;e++){const t=e/i,r=t*a+o,h=Math.sin(r),m=Math.cos(r);y.x=x*h,y.y=-f*s+g,y.z=x*m,l.push(y.x,y.y,y.z),n.set(h,b,m).normalize(),c.push(n.x,n.y,n.z),d.push(t,1-f),u.push(p++)}m.push(u)}for(let s=0;s<i;s++)for(let i=0;i<r;i++){const r=m[i][s],n=m[i+1][s],o=m[i+1][s+1],a=m[i][s+1];e>0&&(u.push(r,n,a),x+=3),t>0&&(u.push(n,o,a),x+=3)}h.addGroup(f,x,0),f+=x}(),!1===n&&(e>0&&y(!0),t>0&&y(!1)),this.setIndex(u),this.setAttribute("position",new vn(l,3)),this.setAttribute("normal",new vn(c,3)),this.setAttribute("uv",new vn(d,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Mh(e.radiusTop,e.radiusBottom,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class Nh extends Mh{constructor(e=1,t=1,s=32,i=1,r=!1,n=0,o=2*Math.PI){super(0,e,t,s,i,r,n,o),this.type="ConeGeometry",this.parameters={radius:e,height:t,radialSegments:s,heightSegments:i,openEnded:r,thetaStart:n,thetaLength:o}}static fromJSON(e){return new Nh(e.radius,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class Ah extends Cn{constructor(e=[],t=[],s=1,i=0){super(),this.type="PolyhedronGeometry",this.parameters={vertices:e,indices:t,radius:s,detail:i};const r=[],n=[];function o(e,t,s,i){const r=i+1,n=[];for(let i=0;i<=r;i++){n[i]=[];const o=e.clone().lerp(s,i/r),a=t.clone().lerp(s,i/r),h=r-i;for(let e=0;e<=h;e++)n[i][e]=0===e&&i===r?o:o.clone().lerp(a,e/h)}for(let e=0;e<r;e++)for(let t=0;t<2*(r-e)-1;t++){const s=Math.floor(t/2);t%2==0?(a(n[e][s+1]),a(n[e+1][s]),a(n[e][s])):(a(n[e][s+1]),a(n[e+1][s+1]),a(n[e+1][s]))}}function a(e){r.push(e.x,e.y,e.z)}function h(t,s){const i=3*t;s.x=e[i+0],s.y=e[i+1],s.z=e[i+2]}function u(e,t,s,i){i<0&&1===e.x&&(n[t]=e.x-1),0===s.x&&0===s.z&&(n[t]=i/2/Math.PI+.5)}function l(e){return Math.atan2(e.z,-e.x)}function c(e){return Math.atan2(-e.y,Math.sqrt(e.x*e.x+e.z*e.z))}!function(e){const s=new Ei,i=new Ei,r=new Ei;for(let n=0;n<t.length;n+=3)h(t[n+0],s),h(t[n+1],i),h(t[n+2],r),o(s,i,r,e)}(i),function(e){const t=new Ei;for(let s=0;s<r.length;s+=3)t.x=r[s+0],t.y=r[s+1],t.z=r[s+2],t.normalize().multiplyScalar(e),r[s+0]=t.x,r[s+1]=t.y,r[s+2]=t.z}(s),function(){const e=new Ei;for(let t=0;t<r.length;t+=3){e.x=r[t+0],e.y=r[t+1],e.z=r[t+2];const s=l(e)/2/Math.PI+.5,i=c(e)/Math.PI+.5;n.push(s,1-i)}(function(){const e=new Ei,t=new Ei,s=new Ei,i=new Ei,o=new ei,a=new ei,h=new ei;for(let c=0,d=0;c<r.length;c+=9,d+=6){e.set(r[c+0],r[c+1],r[c+2]),t.set(r[c+3],r[c+4],r[c+5]),s.set(r[c+6],r[c+7],r[c+8]),o.set(n[d+0],n[d+1]),a.set(n[d+2],n[d+3]),h.set(n[d+4],n[d+5]),i.copy(e).add(t).add(s).divideScalar(3);const p=l(i);u(o,d+0,e,p),u(a,d+2,t,p),u(h,d+4,s,p)}})(),function(){for(let e=0;e<n.length;e+=6){const t=n[e+0],s=n[e+2],i=n[e+4],r=Math.max(t,s,i),o=Math.min(t,s,i);r>.9&&o<.1&&(t<.2&&(n[e+0]+=1),s<.2&&(n[e+2]+=1),i<.2&&(n[e+4]+=1))}}()}(),this.setAttribute("position",new vn(r,3)),this.setAttribute("normal",new vn(r.slice(),3)),this.setAttribute("uv",new vn(n,2)),0===i?this.computeVertexNormals():this.normalizeNormals()}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Ah(e.vertices,e.indices,e.radius,e.details)}}class Ch extends Ah{constructor(e=1,t=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],e,t),this.type="DodecahedronGeometry",this.parameters={radius:e,detail:t}}static fromJSON(e){return new Ch(e.radius,e.detail)}}const Rh=new Ei,Eh=new Ei,Bh=new Ei,Ih=new $r;class Ph extends Cn{constructor(e=null,t=1){if(super(),this.type="EdgesGeometry",this.parameters={geometry:e,thresholdAngle:t},null!==e){const s=4,i=Math.pow(10,s),r=Math.cos(js*t),n=e.getIndex(),o=e.getAttribute("position"),a=n?n.count:o.count,h=[0,0,0],u=["a","b","c"],l=new Array(3),c={},d=[];for(let e=0;e<a;e+=3){n?(h[0]=n.getX(e),h[1]=n.getX(e+1),h[2]=n.getX(e+2)):(h[0]=e,h[1]=e+1,h[2]=e+2);const{a:t,b:s,c:a}=Ih;if(t.fromBufferAttribute(o,h[0]),s.fromBufferAttribute(o,h[1]),a.fromBufferAttribute(o,h[2]),Ih.getNormal(Bh),l[0]=`${Math.round(t.x*i)},${Math.round(t.y*i)},${Math.round(t.z*i)}`,l[1]=`${Math.round(s.x*i)},${Math.round(s.y*i)},${Math.round(s.z*i)}`,l[2]=`${Math.round(a.x*i)},${Math.round(a.y*i)},${Math.round(a.z*i)}`,l[0]!==l[1]&&l[1]!==l[2]&&l[2]!==l[0])for(let e=0;e<3;e++){const t=(e+1)%3,s=l[e],i=l[t],n=Ih[u[e]],o=Ih[u[t]],a=`${s}_${i}`,p=`${i}_${s}`;p in c&&c[p]?(Bh.dot(c[p].normal)<=r&&(d.push(n.x,n.y,n.z),d.push(o.x,o.y,o.z)),c[p]=null):a in c||(c[a]={index0:h[e],index1:h[t],normal:Bh.clone()})}}for(const e in c)if(c[e]){const{index0:t,index1:s}=c[e];Rh.fromBufferAttribute(o,t),Eh.fromBufferAttribute(o,s),d.push(Rh.x,Rh.y,Rh.z),d.push(Eh.x,Eh.y,Eh.z)}this.setAttribute("position",new vn(d,3))}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}}class Fh extends Th{constructor(e){super(e),this.uuid=$s(),this.type="Shape",this.holes=[]}getPointsHoles(e){const t=[];for(let s=0,i=this.holes.length;s<i;s++)t[s]=this.holes[s].getPoints(e);return t}extractPoints(e){return{shape:this.getPoints(e),holes:this.getPointsHoles(e)}}copy(e){super.copy(e),this.holes=[];for(let t=0,s=e.holes.length;t<s;t++){const s=e.holes[t];this.holes.push(s.clone())}return this}toJSON(){const e=super.toJSON();e.uuid=this.uuid,e.holes=[];for(let t=0,s=this.holes.length;t<s;t++){const s=this.holes[t];e.holes.push(s.toJSON())}return e}fromJSON(e){super.fromJSON(e),this.uuid=e.uuid,this.holes=[];for(let t=0,s=e.holes.length;t<s;t++){const s=e.holes[t];this.holes.push((new Th).fromJSON(s))}return this}}const zh=function(e,t,s=2){const i=t&&t.length,r=i?t[0]*s:e.length;let n=Uh(e,0,r,s,!0);const o=[];if(!n||n.next===n.prev)return o;let a,h,u,l,c,d,p;if(i&&(n=function(e,t,s,i){const r=[];let n,o,a,h,u;for(n=0,o=t.length;n<o;n++)a=t[n]*i,h=n<o-1?t[n+1]*i:e.length,u=Uh(e,a,h,i,!1),u===u.next&&(u.steiner=!0),r.push($h(u));for(r.sort(Wh),n=0;n<r.length;n++)s=Hh(r[n],s);return s}(e,t,n,s)),e.length>80*s){a=u=e[0],h=l=e[1];for(let t=s;t<r;t+=s)c=e[t],d=e[t+1],c<a&&(a=c),d<h&&(h=d),c>u&&(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 Uh(e,t,s,i,r){let n,o;if(r===function(e,t,s,i){let r=0;for(let n=t,o=s-i;n<s;n+=i)r+=(e[o]-e[n])*(e[n+1]+e[o+1]),o=n;return r}(e,t,s,i)>0)for(n=t;n<s;n+=i)o=iu(n,e[n],e[n+1],o);else for(n=s-i;n>=t;n-=i)o=iu(n,e[n],e[n+1],o);return o&&Jh(o,o.next)&&(ru(o),o=o.next),o}function Oh(e,t){if(!e)return e;t||(t=e);let s,i=e;do{if(s=!1,i.steiner||!Jh(i,i.next)&&0!==Zh(i.prev,i,i.next))i=i.next;else{if(ru(i),i=t=i.prev,i===i.next)break;s=!0}}while(s||i!==t);return t}function Lh(e,t,s,i,r,n,o){if(!e)return;!o&&n&&function(e,t,s,i){let r=e;do{0===r.z&&(r.z=qh(r.x,r.y,t,s,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==e);r.prevZ.nextZ=null,r.prevZ=null,function(e){let t,s,i,r,n,o,a,h,u=1;do{for(s=e,e=null,n=null,o=0;s;){for(o++,i=s,a=0,t=0;t<u&&(a++,i=i.nextZ,i);t++);for(h=u;a>0||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:e=r,r.prevZ=n,n=r;s=i}n.nextZ=null,u*=2}while(o>1)}(r)}(e,i,r,n);let a,h,u=e;for(;e.prev!==e.next;)if(a=e.prev,h=e.next,n?Dh(e,i,r,n):Vh(e))t.push(a.i/s|0),t.push(e.i/s|0),t.push(h.i/s|0),ru(e),e=h.next,u=h.next;else if((e=h)===u){o?1===o?Lh(e=kh(Oh(e),t,s),t,s,i,r,n,2):2===o&&Gh(e,t,s,i,r,n):Lh(Oh(e),t,s,i,r,n,1);break}}function Vh(e){const t=e.prev,s=e,i=e.next;if(Zh(t,s,i)>=0)return!1;const r=t.x,n=s.x,o=i.x,a=t.y,h=s.y,u=i.y,l=r<n?r<o?r:o:n<o?n:o,c=a<h?a<u?a:u:h<u?h:u,d=r>n?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!==t;){if(m.x>=l&&m.x<=d&&m.y>=c&&m.y<=p&&Xh(r,a,n,h,o,u,m.x,m.y)&&Zh(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function Dh(e,t,s,i){const r=e.prev,n=e,o=e.next;if(Zh(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=a<h?a<u?a:u:h<u?h:u,m=l<c?l<d?l:d:c<d?c:d,g=a>h?a>u?a:u:h>u?h:u,f=l>c?l>d?l:d:c>d?c:d,y=qh(p,m,t,s,i),x=qh(g,f,t,s,i);let b=e.prevZ,v=e.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)&&Zh(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)&&Zh(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)&&Zh(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)&&Zh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function kh(e,t,s){let i=e;do{const r=i.prev,n=i.next.next;!Jh(r,n)&&Kh(r,i,i.next,n)&&tu(r,n)&&tu(n,r)&&(t.push(r.i/s|0),t.push(i.i/s|0),t.push(n.i/s|0),ru(i),ru(i.next),i=e=n),i=i.next}while(i!==e);return Oh(i)}function Gh(e,t,s,i,r,n){let o=e;do{let e=o.next.next;for(;e!==o.prev;){if(o.i!==e.i&&Yh(o,e)){let a=su(o,e);return o=Oh(o,o.next),a=Oh(a,a.next),Lh(o,t,s,i,r,n,0),void Lh(a,t,s,i,r,n,0)}e=e.next}o=o.next}while(o!==e)}function Wh(e,t){return e.x-t.x}function Hh(e,t){const s=function(e,t){let s,i=t,r=-1/0;const n=e.x,o=e.y;do{if(o<=i.y&&o>=i.next.y&&i.next.y!==i.y){const e=i.x+(o-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(e<=n&&e>r&&(r=e,s=i.x<i.next.x?i:i.next,e===n))return s}i=i.next}while(i!==t);if(!s)return null;const a=s,h=s.x,u=s.y;let l,c=1/0;i=s;do{n>=i.x&&i.x>=h&&n!==i.x&&Xh(o<u?n:r,o,h,u,o<u?r:n,o,i.x,i.y)&&(l=Math.abs(o-i.y)/(n-i.x),tu(i,e)&&(l<c||l===c&&(i.x>s.x||i.x===s.x&&jh(s,i)))&&(s=i,c=l)),i=i.next}while(i!==a);return s}(e,t);if(!s)return t;const i=su(s,e);return Oh(i,i.next),Oh(s,s.next)}function jh(e,t){return Zh(e.prev,e,t.prev)<0&&Zh(t.next,e,e.next)<0}function qh(e,t,s,i,r){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-s)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-i)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function $h(e){let t=e,s=e;do{(t.x<s.x||t.x===s.x&&t.y<s.y)&&(s=t),t=t.next}while(t!==e);return s}function Xh(e,t,s,i,r,n,o,a){return(r-o)*(t-a)>=(e-o)*(n-a)&&(e-o)*(i-a)>=(s-o)*(t-a)&&(s-o)*(n-a)>=(r-o)*(i-a)}function Yh(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){let s=e;do{if(s.i!==e.i&&s.next.i!==e.i&&s.i!==t.i&&s.next.i!==t.i&&Kh(s,s.next,e,t))return!0;s=s.next}while(s!==e);return!1}(e,t)&&(tu(e,t)&&tu(t,e)&&function(e,t){let s=e,i=!1;const r=(e.x+t.x)/2,n=(e.y+t.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!==e);return i}(e,t)&&(Zh(e.prev,e,t.prev)||Zh(e,t.prev,t))||Jh(e,t)&&Zh(e.prev,e,e.next)>0&&Zh(t.prev,t,t.next)>0)}function Zh(e,t,s){return(t.y-e.y)*(s.x-t.x)-(t.x-e.x)*(s.y-t.y)}function Jh(e,t){return e.x===t.x&&e.y===t.y}function Kh(e,t,s,i){const r=eu(Zh(e,t,s)),n=eu(Zh(e,t,i)),o=eu(Zh(s,i,e)),a=eu(Zh(s,i,t));return r!==n&&o!==a||(!(0!==r||!Qh(e,s,t))||(!(0!==n||!Qh(e,i,t))||(!(0!==o||!Qh(s,e,i))||!(0!==a||!Qh(s,t,i)))))}function Qh(e,t,s){return t.x<=Math.max(e.x,s.x)&&t.x>=Math.min(e.x,s.x)&&t.y<=Math.max(e.y,s.y)&&t.y>=Math.min(e.y,s.y)}function eu(e){return e>0?1:e<0?-1:0}function tu(e,t){return Zh(e.prev,e,e.next)<0?Zh(e,t,e.next)>=0&&Zh(e,e.prev,t)>=0:Zh(e,t,e.prev)<0||Zh(e,e.next,t)<0}function su(e,t){const s=new nu(e.i,e.x,e.y),i=new nu(t.i,t.x,t.y),r=e.next,n=t.prev;return e.next=t,t.prev=e,s.next=r,r.prev=s,i.next=s,s.prev=i,n.next=i,i.prev=n,i}function iu(e,t,s,i){const r=new nu(e,t,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(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function nu(e,t,s){this.i=e,this.x=t,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(e){const t=e.length;let s=0;for(let i=t-1,r=0;r<t;i=r++)s+=e[i].x*e[r].y-e[r].x*e[i].y;return.5*s}static isClockWise(e){return ou.area(e)<0}static triangulateShape(e,t){const s=[],i=[],r=[];au(e),hu(s,e);let n=e.length;t.forEach(au);for(let e=0;e<t.length;e++)i.push(n),n+=t[e].length,hu(s,t[e]);const o=zh(s,i);for(let e=0;e<o.length;e+=3)r.push(o.slice(e,e+3));return r}}function au(e){const t=e.length;t>2&&e[t-1].equals(e[0])&&e.pop()}function hu(e,t){for(let s=0;s<t.length;s++)e.push(t[s].x),e.push(t[s].y)}class uu extends Cn{constructor(e=new Fh([new ei(.5,.5),new ei(-.5,.5),new ei(-.5,-.5),new ei(.5,-.5)]),t={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:e,options:t},e=Array.isArray(e)?e:[e];const s=this,i=[],r=[];for(let t=0,s=e.length;t<s;t++){n(e[t])}function n(e){const n=[],o=void 0!==t.curveSegments?t.curveSegments:12,a=void 0!==t.steps?t.steps:1,h=void 0!==t.depth?t.depth:1;let u=void 0===t.bevelEnabled||t.bevelEnabled,l=void 0!==t.bevelThickness?t.bevelThickness:.2,c=void 0!==t.bevelSize?t.bevelSize:l-.1,d=void 0!==t.bevelOffset?t.bevelOffset:0,p=void 0!==t.bevelSegments?t.bevelSegments:3;const m=t.extrudePath,g=void 0!==t.UVGenerator?t.UVGenerator:lu;let f,y,x,b,v,T=!1;m&&(f=m.getSpacedPoints(a),T=!0,u=!1,y=m.computeFrenetFrames(a,!1),x=new Ei,b=new Ei,v=new Ei),u||(p=0,l=0,c=0,d=0);const _=e.extractPoints(o);let w=_.shape;const S=_.holes;if(!ou.isClockWise(w)){w=w.reverse();for(let e=0,t=S.length;e<t;e++){const t=S[e];ou.isClockWise(t)&&(S[e]=t.reverse())}}const M=ou.triangulateShape(w,S),N=w;for(let e=0,t=S.length;e<t;e++){const t=S[e];w=w.concat(t)}function A(e,t,s){return t||console.error("THREE.ExtrudeGeometry: vec does not exist"),e.clone().addScaledVector(t,s)}const C=w.length,R=M.length;function E(e,t,s){let i,r,n;const o=e.x-t.x,a=e.y-t.y,h=s.x-e.x,u=s.y-e.y,l=o*o+a*a,c=o*u-a*h;if(Math.abs(c)>Number.EPSILON){const c=Math.sqrt(l),d=Math.sqrt(h*h+u*u),p=t.x-a/c,m=t.y+o/c,g=((s.x-u/d-p)*u-(s.y+h/d-m)*h)/(o*u-a*h);i=p+o*g-e.x,r=m+a*g-e.y;const f=i*i+r*r;if(f<=2)return new ei(i,r);n=Math.sqrt(f/2)}else{let e=!1;o>Number.EPSILON?h>Number.EPSILON&&(e=!0):o<-Number.EPSILON?h<-Number.EPSILON&&(e=!0):Math.sign(a)===Math.sign(u)&&(e=!0),e?(i=-a,r=o,n=Math.sqrt(l)):(i=o,r=a,n=Math.sqrt(l/2))}return new ei(i/n,r/n)}const B=[];for(let e=0,t=N.length,s=t-1,i=e+1;e<t;e++,s++,i++)s===t&&(s=0),i===t&&(i=0),B[e]=E(N[e],N[s],N[i]);const I=[];let P,F=B.concat();for(let e=0,t=S.length;e<t;e++){const t=S[e];P=[];for(let e=0,s=t.length,i=s-1,r=e+1;e<s;e++,i++,r++)i===s&&(i=0),r===s&&(r=0),P[e]=E(t[e],t[i],t[r]);I.push(P),F=F.concat(P)}for(let e=0;e<p;e++){const t=e/p,s=l*Math.cos(t*Math.PI/2),i=c*Math.sin(t*Math.PI/2)+d;for(let e=0,t=N.length;e<t;e++){const t=A(N[e],B[e],i);O(t.x,t.y,-s)}for(let e=0,t=S.length;e<t;e++){const t=S[e];P=I[e];for(let e=0,r=t.length;e<r;e++){const r=A(t[e],P[e],i);O(r.x,r.y,-s)}}}const z=c+d;for(let e=0;e<C;e++){const t=u?A(w[e],F[e],z):w[e];T?(b.copy(y.normals[0]).multiplyScalar(t.x),x.copy(y.binormals[0]).multiplyScalar(t.y),v.copy(f[0]).add(b).add(x),O(v.x,v.y,v.z)):O(t.x,t.y,0)}for(let e=1;e<=a;e++)for(let t=0;t<C;t++){const s=u?A(w[t],F[t],z):w[t];T?(b.copy(y.normals[e]).multiplyScalar(s.x),x.copy(y.binormals[e]).multiplyScalar(s.y),v.copy(f[e]).add(b).add(x),O(v.x,v.y,v.z)):O(s.x,s.y,h/a*e)}for(let e=p-1;e>=0;e--){const t=e/p,s=l*Math.cos(t*Math.PI/2),i=c*Math.sin(t*Math.PI/2)+d;for(let e=0,t=N.length;e<t;e++){const t=A(N[e],B[e],i);O(t.x,t.y,h+s)}for(let e=0,t=S.length;e<t;e++){const t=S[e];P=I[e];for(let e=0,r=t.length;e<r;e++){const r=A(t[e],P[e],i);T?O(r.x,r.y+f[a-1].y,f[a-1].x+s):O(r.x,r.y,h+s)}}}function U(e,t){let s=e.length;for(;--s>=0;){const i=s;let r=s-1;r<0&&(r=e.length-1);for(let e=0,s=a+2*p;e<s;e++){const s=C*e,n=C*(e+1);V(t+i+s,t+r+s,t+r+n,t+i+n)}}}function O(e,t,s){n.push(e),n.push(t),n.push(s)}function L(e,t,r){D(e),D(t),D(r);const n=i.length/3,o=g.generateTopUV(s,i,n-3,n-2,n-1);k(o[0]),k(o[1]),k(o[2])}function V(e,t,r,n){D(e),D(t),D(n),D(t),D(r),D(n);const o=i.length/3,a=g.generateSideWallUV(s,i,o-6,o-3,o-2,o-1);k(a[0]),k(a[1]),k(a[3]),k(a[1]),k(a[2]),k(a[3])}function D(e){i.push(n[3*e+0]),i.push(n[3*e+1]),i.push(n[3*e+2])}function k(e){r.push(e.x),r.push(e.y)}!function(){const e=i.length/3;if(u){let e=0,t=C*e;for(let e=0;e<R;e++){const s=M[e];L(s[2]+t,s[1]+t,s[0]+t)}e=a+2*p,t=C*e;for(let e=0;e<R;e++){const s=M[e];L(s[0]+t,s[1]+t,s[2]+t)}}else{for(let e=0;e<R;e++){const t=M[e];L(t[2],t[1],t[0])}for(let e=0;e<R;e++){const t=M[e];L(t[0]+C*a,t[1]+C*a,t[2]+C*a)}}s.addGroup(e,i.length/3-e,0)}(),function(){const e=i.length/3;let t=0;U(N,t),t+=N.length;for(let e=0,s=S.length;e<s;e++){const s=S[e];U(s,t),t+=s.length}s.addGroup(e,i.length/3-e,1)}()}this.setAttribute("position",new vn(i,3)),this.setAttribute("uv",new vn(r,2)),this.computeVertexNormals()}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){const e=super.toJSON();return function(e,t,s){if(s.shapes=[],Array.isArray(e))for(let t=0,i=e.length;t<i;t++){const i=e[t];s.shapes.push(i.uuid)}else s.shapes.push(e.uuid);s.options=Object.assign({},t),void 0!==t.extrudePath&&(s.options.extrudePath=t.extrudePath.toJSON());return s}(this.parameters.shapes,this.parameters.options,e)}static fromJSON(e,t){const s=[];for(let i=0,r=e.shapes.length;i<r;i++){const r=t[e.shapes[i]];s.push(r)}const i=e.options.extrudePath;return void 0!==i&&(e.options.extrudePath=(new bh[i.type]).fromJSON(i)),new uu(s,e.options)}}const lu={generateTopUV:function(e,t,s,i,r){const n=t[3*s],o=t[3*s+1],a=t[3*i],h=t[3*i+1],u=t[3*r],l=t[3*r+1];return[new ei(n,o),new ei(a,h),new ei(u,l)]},generateSideWallUV:function(e,t,s,i,r,n){const o=t[3*s],a=t[3*s+1],h=t[3*s+2],u=t[3*i],l=t[3*i+1],c=t[3*i+2],d=t[3*r],p=t[3*r+1],m=t[3*r+2],g=t[3*n],f=t[3*n+1],y=t[3*n+2];return Math.abs(a-l)<Math.abs(o-u)?[new ei(o,1-h),new ei(u,1-c),new ei(d,1-m),new ei(g,1-y)]:[new ei(a,1-h),new ei(l,1-c),new ei(p,1-m),new ei(f,1-y)]}};class cu extends Ah{constructor(e=1,t=0){const s=(1+Math.sqrt(5))/2;super([-1,s,0,1,s,0,-1,-s,0,1,-s,0,0,-1,s,0,1,s,0,-1,-s,0,1,-s,s,0,-1,s,0,1,-s,0,-1,-s,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],e,t),this.type="IcosahedronGeometry",this.parameters={radius:e,detail:t}}static fromJSON(e){return new cu(e.radius,e.detail)}}class du extends Ah{constructor(e=1,t=0){super([1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],e,t),this.type="OctahedronGeometry",this.parameters={radius:e,detail:t}}static fromJSON(e){return new du(e.radius,e.detail)}}class pu extends Cn{constructor(e=1,t=1,s=1,i=1){super(),this.type="PlaneGeometry",this.parameters={width:e,height:t,widthSegments:s,heightSegments:i};const r=e/2,n=t/2,o=Math.floor(s),a=Math.floor(i),h=o+1,u=a+1,l=e/o,c=t/a,d=[],p=[],m=[],g=[];for(let e=0;e<u;e++){const t=e*c-n;for(let s=0;s<h;s++){const i=s*l-r;p.push(i,-t,0),m.push(0,0,1),g.push(s/o),g.push(1-e/a)}}for(let e=0;e<a;e++)for(let t=0;t<o;t++){const s=t+h*e,i=t+h*(e+1),r=t+1+h*(e+1),n=t+1+h*e;d.push(s,i,n),d.push(i,r,n)}this.setIndex(d),this.setAttribute("position",new vn(p,3)),this.setAttribute("normal",new vn(m,3)),this.setAttribute("uv",new vn(g,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new pu(e.width,e.height,e.widthSegments,e.heightSegments)}}class mu extends Cn{constructor(e=.5,t=1,s=32,i=1,r=0,n=2*Math.PI){super(),this.type="RingGeometry",this.parameters={innerRadius:e,outerRadius:t,thetaSegments:s,phiSegments:i,thetaStart:r,thetaLength:n},s=Math.max(3,s);const o=[],a=[],h=[],u=[];let l=e;const c=(t-e)/(i=Math.max(1,i)),d=new Ei,p=new ei;for(let e=0;e<=i;e++){for(let e=0;e<=s;e++){const i=r+e/s*n;d.x=l*Math.cos(i),d.y=l*Math.sin(i),a.push(d.x,d.y,d.z),h.push(0,0,1),p.x=(d.x/t+1)/2,p.y=(d.y/t+1)/2,u.push(p.x,p.y)}l+=c}for(let e=0;e<i;e++){const t=e*(s+1);for(let e=0;e<s;e++){const i=e+t,r=i,n=i+s+1,a=i+s+2,h=i+1;o.push(r,n,h),o.push(n,a,h)}}this.setIndex(o),this.setAttribute("position",new vn(a,3)),this.setAttribute("normal",new vn(h,3)),this.setAttribute("uv",new vn(u,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new mu(e.innerRadius,e.outerRadius,e.thetaSegments,e.phiSegments,e.thetaStart,e.thetaLength)}}class gu extends Cn{constructor(e=new Fh([new ei(0,.5),new ei(-.5,-.5),new ei(.5,-.5)]),t=12){super(),this.type="ShapeGeometry",this.parameters={shapes:e,curveSegments:t};const s=[],i=[],r=[],n=[];let o=0,a=0;if(!1===Array.isArray(e))h(e);else for(let t=0;t<e.length;t++)h(e[t]),this.addGroup(o,a,t),o+=a,a=0;function h(e){const o=i.length/3,h=e.extractPoints(t);let u=h.shape;const l=h.holes;!1===ou.isClockWise(u)&&(u=u.reverse());for(let e=0,t=l.length;e<t;e++){const t=l[e];!0===ou.isClockWise(t)&&(l[e]=t.reverse())}const c=ou.triangulateShape(u,l);for(let e=0,t=l.length;e<t;e++){const t=l[e];u=u.concat(t)}for(let e=0,t=u.length;e<t;e++){const t=u[e];i.push(t.x,t.y,0),r.push(0,0,1),n.push(t.x,t.y)}for(let e=0,t=c.length;e<t;e++){const t=c[e],i=t[0]+o,r=t[1]+o,n=t[2]+o;s.push(i,r,n),a+=3}}this.setIndex(s),this.setAttribute("position",new vn(i,3)),this.setAttribute("normal",new vn(r,3)),this.setAttribute("uv",new vn(n,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){const e=super.toJSON();return function(e,t){if(t.shapes=[],Array.isArray(e))for(let s=0,i=e.length;s<i;s++){const i=e[s];t.shapes.push(i.uuid)}else t.shapes.push(e.uuid);return t}(this.parameters.shapes,e)}static fromJSON(e,t){const s=[];for(let i=0,r=e.shapes.length;i<r;i++){const r=t[e.shapes[i]];s.push(r)}return new gu(s,e.curveSegments)}}class fu extends Cn{constructor(e=1,t=32,s=16,i=0,r=2*Math.PI,n=0,o=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:e,widthSegments:t,heightSegments:s,phiStart:i,phiLength:r,thetaStart:n,thetaLength:o},t=Math.max(3,Math.floor(t)),s=Math.max(2,Math.floor(s));const a=Math.min(n+o,Math.PI);let h=0;const u=[],l=new Ei,c=new Ei,d=[],p=[],m=[],g=[];for(let d=0;d<=s;d++){const f=[],y=d/s;let x=0;0===d&&0===n?x=.5/t:d===s&&a===Math.PI&&(x=-.5/t);for(let s=0;s<=t;s++){const a=s/t;l.x=-e*Math.cos(i+a*r)*Math.sin(n+y*o),l.y=e*Math.cos(n+y*o),l.z=e*Math.sin(i+a*r)*Math.sin(n+y*o),p.push(l.x,l.y,l.z),c.copy(l).normalize(),m.push(c.x,c.y,c.z),g.push(a+x,1-y),f.push(h++)}u.push(f)}for(let e=0;e<s;e++)for(let i=0;i<t;i++){const t=u[e][i+1],r=u[e][i],o=u[e+1][i],h=u[e+1][i+1];(0!==e||n>0)&&d.push(t,r,h),(e!==s-1||a<Math.PI)&&d.push(r,o,h)}this.setIndex(d),this.setAttribute("position",new vn(p,3)),this.setAttribute("normal",new vn(m,3)),this.setAttribute("uv",new vn(g,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new fu(e.radius,e.widthSegments,e.heightSegments,e.phiStart,e.phiLength,e.thetaStart,e.thetaLength)}}class yu extends Ah{constructor(e=1,t=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],e,t),this.type="TetrahedronGeometry",this.parameters={radius:e,detail:t}}static fromJSON(e){return new yu(e.radius,e.detail)}}class xu extends Cn{constructor(e=1,t=.4,s=12,i=48,r=2*Math.PI){super(),this.type="TorusGeometry",this.parameters={radius:e,tube:t,radialSegments:s,tubularSegments:i,arc:r},s=Math.floor(s),i=Math.floor(i);const n=[],o=[],a=[],h=[],u=new Ei,l=new Ei,c=new Ei;for(let n=0;n<=s;n++)for(let d=0;d<=i;d++){const p=d/i*r,m=n/s*Math.PI*2;l.x=(e+t*Math.cos(m))*Math.cos(p),l.y=(e+t*Math.cos(m))*Math.sin(p),l.z=t*Math.sin(m),o.push(l.x,l.y,l.z),u.x=e*Math.cos(p),u.y=e*Math.sin(p),c.subVectors(l,u).normalize(),a.push(c.x,c.y,c.z),h.push(d/i),h.push(n/s)}for(let e=1;e<=s;e++)for(let t=1;t<=i;t++){const s=(i+1)*e+t-1,r=(i+1)*(e-1)+t-1,o=(i+1)*(e-1)+t,a=(i+1)*e+t;n.push(s,r,a),n.push(r,o,a)}this.setIndex(n),this.setAttribute("position",new vn(o,3)),this.setAttribute("normal",new vn(a,3)),this.setAttribute("uv",new vn(h,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new xu(e.radius,e.tube,e.radialSegments,e.tubularSegments,e.arc)}}class bu extends Cn{constructor(e=1,t=.4,s=64,i=8,r=2,n=3){super(),this.type="TorusKnotGeometry",this.parameters={radius:e,tube:t,tubularSegments:s,radialSegments:i,p:r,q:n},s=Math.floor(s),i=Math.floor(i);const o=[],a=[],h=[],u=[],l=new Ei,c=new Ei,d=new Ei,p=new Ei,m=new Ei,g=new Ei,f=new Ei;for(let o=0;o<=s;++o){const x=o/s*r*Math.PI*2;y(x,r,n,e,d),y(x+.01,r,n,e,p),g.subVectors(p,d),f.addVectors(p,d),m.crossVectors(g,f),f.crossVectors(m,g),m.normalize(),f.normalize();for(let e=0;e<=i;++e){const r=e/i*Math.PI*2,n=-t*Math.cos(r),p=t*Math.sin(r);l.x=d.x+(n*f.x+p*m.x),l.y=d.y+(n*f.y+p*m.y),l.z=d.z+(n*f.z+p*m.z),a.push(l.x,l.y,l.z),c.subVectors(l,d).normalize(),h.push(c.x,c.y,c.z),u.push(o/s),u.push(e/i)}}for(let e=1;e<=s;e++)for(let t=1;t<=i;t++){const s=(i+1)*(e-1)+(t-1),r=(i+1)*e+(t-1),n=(i+1)*e+t,a=(i+1)*(e-1)+t;o.push(s,r,a),o.push(r,n,a)}function y(e,t,s,i,r){const n=Math.cos(e),o=Math.sin(e),a=s/t*e,h=Math.cos(a);r.x=i*(2+h)*.5*n,r.y=i*(2+h)*o*.5,r.z=i*Math.sin(a)*.5}this.setIndex(o),this.setAttribute("position",new vn(a,3)),this.setAttribute("normal",new vn(h,3)),this.setAttribute("uv",new vn(u,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new bu(e.radius,e.tube,e.tubularSegments,e.radialSegments,e.p,e.q)}}class vu extends Cn{constructor(e=new yh(new Ei(-1,-1,0),new Ei(-1,1,0),new Ei(1,1,0)),t=64,s=1,i=8,r=!1){super(),this.type="TubeGeometry",this.parameters={path:e,tubularSegments:t,radius:s,radialSegments:i,closed:r};const n=e.computeFrenetFrames(t,r);this.tangents=n.tangents,this.normals=n.normals,this.binormals=n.binormals;const o=new Ei,a=new Ei,h=new ei;let u=new Ei;const l=[],c=[],d=[],p=[];function m(r){u=e.getPointAt(r/t,u);const h=n.normals[r],d=n.binormals[r];for(let e=0;e<=i;e++){const t=e/i*Math.PI*2,r=Math.sin(t),n=-Math.cos(t);a.x=n*h.x+r*d.x,a.y=n*h.y+r*d.y,a.z=n*h.z+r*d.z,a.normalize(),c.push(a.x,a.y,a.z),o.x=u.x+s*a.x,o.y=u.y+s*a.y,o.z=u.z+s*a.z,l.push(o.x,o.y,o.z)}}!function(){for(let e=0;e<t;e++)m(e);m(!1===r?t:0),function(){for(let e=0;e<=t;e++)for(let s=0;s<=i;s++)h.x=e/t,h.y=s/i,d.push(h.x,h.y)}(),function(){for(let e=1;e<=t;e++)for(let t=1;t<=i;t++){const s=(i+1)*(e-1)+(t-1),r=(i+1)*e+(t-1),n=(i+1)*e+t,o=(i+1)*(e-1)+t;p.push(s,r,o),p.push(r,n,o)}}()}(),this.setIndex(p),this.setAttribute("position",new vn(l,3)),this.setAttribute("normal",new vn(c,3)),this.setAttribute("uv",new vn(d,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){const e=super.toJSON();return e.path=this.parameters.path.toJSON(),e}static fromJSON(e){return new vu((new bh[e.path.type]).fromJSON(e.path),e.tubularSegments,e.radius,e.radialSegments,e.closed)}}class Tu extends Cn{constructor(e=null){if(super(),this.type="WireframeGeometry",this.parameters={geometry:e},null!==e){const t=[],s=new Set,i=new Ei,r=new Ei;if(null!==e.index){const n=e.attributes.position,o=e.index;let a=e.groups;0===a.length&&(a=[{start:0,count:o.count,materialIndex:0}]);for(let e=0,h=a.length;e<h;++e){const h=a[e],u=h.start;for(let e=u,a=u+h.count;e<a;e+=3)for(let a=0;a<3;a++){const h=o.getX(e+a),u=o.getX(e+(a+1)%3);i.fromBufferAttribute(n,h),r.fromBufferAttribute(n,u),!0===_u(i,r,s)&&(t.push(i.x,i.y,i.z),t.push(r.x,r.y,r.z))}}}else{const n=e.attributes.position;for(let e=0,o=n.count/3;e<o;e++)for(let o=0;o<3;o++){const a=3*e+o,h=3*e+(o+1)%3;i.fromBufferAttribute(n,a),r.fromBufferAttribute(n,h),!0===_u(i,r,s)&&(t.push(i.x,i.y,i.z),t.push(r.x,r.y,r.z))}}this.setAttribute("position",new vn(t,3))}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}}function _u(e,t,s){const i=`${e.x},${e.y},${e.z}-${t.x},${t.y},${t.z}`,r=`${t.x},${t.y},${t.z}-${e.x},${e.y},${e.z}`;return!0!==s.has(i)&&!0!==s.has(r)&&(s.add(i),s.add(r),!0)}var wu=Object.freeze({__proto__:null,BoxGeometry:Gn,CapsuleGeometry:wh,CircleGeometry:Sh,ConeGeometry:Nh,CylinderGeometry:Mh,DodecahedronGeometry:Ch,EdgesGeometry:Ph,ExtrudeGeometry:uu,IcosahedronGeometry:cu,LatheGeometry:_h,OctahedronGeometry:du,PlaneGeometry:pu,PolyhedronGeometry:Ah,RingGeometry:mu,ShapeGeometry:gu,SphereGeometry:fu,TetrahedronGeometry:yu,TorusGeometry:xu,TorusKnotGeometry:bu,TubeGeometry:vu,WireframeGeometry:Tu});class Su extends tn{constructor(e){super(),this.isShadowMaterial=!0,this.type="ShadowMaterial",this.color=new Kr(0),this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.fog=e.fog,this}}class Mu extends Hn{constructor(e){super(e),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class Nu extends tn{constructor(e){super(),this.isMeshStandardMaterial=!0,this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new Kr(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Kr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ei(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fr,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={STANDARD:""},this.color.copy(e.color),this.roughness=e.roughness,this.metalness=e.metalness,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.roughnessMap=e.roughnessMap,this.metalnessMap=e.metalnessMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.envMapIntensity=e.envMapIntensity,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class Au extends Nu{constructor(e){super(),this.isMeshPhysicalMaterial=!0,this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.anisotropyRotation=0,this.anisotropyMap=null,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new ei(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return Xs(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(e){this.ior=(1+.4*e)/(1-.4*e)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessRange=[100,400],this.iridescenceThicknessMap=null,this.sheenColor=new Kr(0),this.sheenColorMap=null,this.sheenRoughness=1,this.sheenRoughnessMap=null,this.transmissionMap=null,this.thickness=0,this.thicknessMap=null,this.attenuationDistance=1/0,this.attenuationColor=new Kr(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new Kr(1,1,1),this.specularColorMap=null,this._anisotropy=0,this._clearcoat=0,this._dispersion=0,this._iridescence=0,this._sheen=0,this._transmission=0,this.setValues(e)}get anisotropy(){return this._anisotropy}set anisotropy(e){this._anisotropy>0!=e>0&&this.version++,this._anisotropy=e}get clearcoat(){return this._clearcoat}set clearcoat(e){this._clearcoat>0!=e>0&&this.version++,this._clearcoat=e}get iridescence(){return this._iridescence}set iridescence(e){this._iridescence>0!=e>0&&this.version++,this._iridescence=e}get dispersion(){return this._dispersion}set dispersion(e){this._dispersion>0!=e>0&&this.version++,this._dispersion=e}get sheen(){return this._sheen}set sheen(e){this._sheen>0!=e>0&&this.version++,this._sheen=e}get transmission(){return this._transmission}set transmission(e){this._transmission>0!=e>0&&this.version++,this._transmission=e}copy(e){return super.copy(e),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=e.anisotropy,this.anisotropyRotation=e.anisotropyRotation,this.anisotropyMap=e.anisotropyMap,this.clearcoat=e.clearcoat,this.clearcoatMap=e.clearcoatMap,this.clearcoatRoughness=e.clearcoatRoughness,this.clearcoatRoughnessMap=e.clearcoatRoughnessMap,this.clearcoatNormalMap=e.clearcoatNormalMap,this.clearcoatNormalScale.copy(e.clearcoatNormalScale),this.dispersion=e.dispersion,this.ior=e.ior,this.iridescence=e.iridescence,this.iridescenceMap=e.iridescenceMap,this.iridescenceIOR=e.iridescenceIOR,this.iridescenceThicknessRange=[...e.iridescenceThicknessRange],this.iridescenceThicknessMap=e.iridescenceThicknessMap,this.sheen=e.sheen,this.sheenColor.copy(e.sheenColor),this.sheenColorMap=e.sheenColorMap,this.sheenRoughness=e.sheenRoughness,this.sheenRoughnessMap=e.sheenRoughnessMap,this.transmission=e.transmission,this.transmissionMap=e.transmissionMap,this.thickness=e.thickness,this.thicknessMap=e.thicknessMap,this.attenuationDistance=e.attenuationDistance,this.attenuationColor.copy(e.attenuationColor),this.specularIntensity=e.specularIntensity,this.specularIntensityMap=e.specularIntensityMap,this.specularColor.copy(e.specularColor),this.specularColorMap=e.specularColorMap,this}}class Cu extends tn{constructor(e){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new Kr(16777215),this.specular=new Kr(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Kr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ei(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(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.specular.copy(e.specular),this.shininess=e.shininess,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class Ru extends tn{constructor(e){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new Kr(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Kr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ei(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(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.gradientMap=e.gradientMap,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}class Eu extends tn{constructor(e){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ei(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(e)}copy(e){return super.copy(e),this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this}}class Bu extends tn{constructor(e){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new Kr(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Kr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ei(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(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class Iu extends tn{constructor(e){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(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}}class Pu extends tn{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}}class Fu extends tn{constructor(e){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new Kr(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ei(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={MATCAP:""},this.color.copy(e.color),this.matcap=e.matcap,this.map=e.map,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.flatShading=e.flatShading,this.fog=e.fog,this}}class zu extends Ma{constructor(e){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(e)}copy(e){return super.copy(e),this.scale=e.scale,this.dashSize=e.dashSize,this.gapSize=e.gapSize,this}}function Uu(e,t,s){return!e||!s&&e.constructor===t?e:"number"==typeof t.BYTES_PER_ELEMENT?new t(e):Array.prototype.slice.call(e)}function Ou(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Lu(e){const t=e.length,s=new Array(t);for(let e=0;e!==t;++e)s[e]=e;return s.sort(function(t,s){return e[t]-e[s]}),s}function Vu(e,t,s){const i=e.length,r=new e.constructor(i);for(let n=0,o=0;o!==i;++n){const i=s[n]*t;for(let s=0;s!==t;++s)r[o++]=e[i+s]}return r}function Du(e,t,s,i){let r=1,n=e[0];for(;void 0!==n&&void 0===n[i];)n=e[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&&(t.push(n.time),s.push.apply(s,o)),n=e[r++]}while(void 0!==n);else if(void 0!==o.toArray)do{o=n[i],void 0!==o&&(t.push(n.time),o.toArray(s,s.length)),n=e[r++]}while(void 0!==n);else do{o=n[i],void 0!==o&&(t.push(n.time),s.push(o)),n=e[r++]}while(void 0!==n)}const ku={convertArray:Uu,isTypedArray:Ou,getKeyframeOrder:Lu,sortedArray:Vu,flattenJSON:Du,subclip:function(e,t,s,i,r=30){const n=e.clone();n.name=t;const o=[];for(let e=0;e<n.tracks.length;++e){const t=n.tracks[e],a=t.getValueSize(),h=[],u=[];for(let e=0;e<t.times.length;++e){const n=t.times[e]*r;if(!(n<s||n>=i)){h.push(t.times[e]);for(let s=0;s<a;++s)u.push(t.values[e*a+s])}}0!==h.length&&(t.times=Uu(h,t.times.constructor),t.values=Uu(u,t.values.constructor),o.push(t))}n.tracks=o;let a=1/0;for(let e=0;e<n.tracks.length;++e)a>n.tracks[e].times[0]&&(a=n.tracks[e].times[0]);for(let e=0;e<n.tracks.length;++e)n.tracks[e].shift(-1*a);return n.resetDuration(),n},makeClipAdditive:function(e,t=0,s=e,i=30){i<=0&&(i=30);const r=s.tracks.length,n=t/i;for(let t=0;t<r;++t){const i=s.tracks[t],r=i.ValueTypeName;if("bool"===r||"string"===r)continue;const o=e.tracks.find(function(e){return e.name===i.name&&e.ValueTypeName===r});if(void 0===o)continue;let a=0;const h=i.getValueSize();i.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(a=h/3);let u=0;const l=o.getValueSize();o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(u=l/3);const c=i.times.length-1;let d;if(n<=i.times[0]){const e=a,t=h-a;d=i.values.slice(e,t)}else if(n>=i.times[c]){const e=c*h+a,t=e+h-a;d=i.values.slice(e,t)}else{const e=i.createInterpolant(),t=a,s=h-a;e.evaluate(n),d=e.resultBuffer.slice(t,s)}if("quaternion"===r){(new Ri).fromArray(d).normalize().conjugate().toArray(d)}const p=o.times.length;for(let e=0;e<p;++e){const t=e*l+u;if("quaternion"===r)Ri.multiplyQuaternionsFlat(o.values,t,d,0,o.values,t);else{const e=l-2*u;for(let s=0;s<e;++s)o.values[t+s]-=d[s]}}}return e.blendMode=Dt,e}};class Gu{constructor(e,t,s,i){this.parameterPositions=e,this._cachedIndex=0,this.resultBuffer=void 0!==i?i:new t.constructor(s),this.sampleValues=t,this.valueSize=s,this.settings=null,this.DefaultSettings_={}}evaluate(e){const t=this.parameterPositions;let s=this._cachedIndex,i=t[s],r=t[s-1];e:{t:{let n;s:{i:if(!(e<i)){for(let n=s+2;;){if(void 0===i){if(e<r)break i;return s=t.length,this._cachedIndex=s,this.copySampleValue_(s-1)}if(s===n)break;if(r=i,i=t[++s],e<i)break t}n=t.length;break s}if(!(e>=r)){const o=t[1];e<o&&(s=2,r=o);for(let n=s-2;;){if(void 0===r)return this._cachedIndex=0,this.copySampleValue_(0);if(s===n)break;if(i=r,r=t[--s-1],e>=r)break t}n=s,s=0;break s}break e}for(;s<n;){const i=s+n>>>1;e<t[i]?n=i:s=i+1}if(i=t[s],r=t[s-1],void 0===r)return this._cachedIndex=0,this.copySampleValue_(0);if(void 0===i)return s=t.length,this._cachedIndex=s,this.copySampleValue_(s-1)}this._cachedIndex=s,this.intervalChanged_(s,r,i)}return this.interpolate_(s,r,e,i)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,i=this.valueSize,r=e*i;for(let e=0;e!==i;++e)t[e]=s[r+e];return t}interpolate_(){throw new Error("call to abstract method")}intervalChanged_(){}}class Wu extends Gu{constructor(e,t,s,i){super(e,t,s,i),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:Ut,endingEnd:Ut}}intervalChanged_(e,t,s){const i=this.parameterPositions;let r=e-2,n=e+1,o=i[r],a=i[n];if(void 0===o)switch(this.getSettings_().endingStart){case Ot:r=e,o=2*t-s;break;case Lt:r=i.length-2,o=t+i[r]-i[r+1];break;default:r=e,o=s}if(void 0===a)switch(this.getSettings_().endingEnd){case Ot:n=e,a=2*s-t;break;case Lt:n=1,a=s+i[1]-i[0];break;default:n=e-1,a=t}const h=.5*(s-t),u=this.valueSize;this._weightPrev=h/(t-o),this._weightNext=h/(a-s),this._offsetPrev=r*u,this._offsetNext=n*u}interpolate_(e,t,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=e*o,h=a-o,u=this._offsetPrev,l=this._offsetNext,c=this._weightPrev,d=this._weightNext,p=(s-t)/(i-t),m=p*p,g=m*p,f=-c*g+2*c*m-c*p,y=(1+c)*g+(-1.5-2*c)*m+(-.5+c)*p+1,x=(-1-d)*g+(1.5+d)*m+.5*p,b=d*g-d*m;for(let e=0;e!==o;++e)r[e]=f*n[u+e]+y*n[h+e]+x*n[a+e]+b*n[l+e];return r}}class Hu extends Gu{constructor(e,t,s,i){super(e,t,s,i)}interpolate_(e,t,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=e*o,h=a-o,u=(s-t)/(i-t),l=1-u;for(let e=0;e!==o;++e)r[e]=n[h+e]*l+n[a+e]*u;return r}}class ju extends Gu{constructor(e,t,s,i){super(e,t,s,i)}interpolate_(e){return this.copySampleValue_(e-1)}}class qu{constructor(e,t,s,i){if(void 0===e)throw new Error("THREE.KeyframeTrack: track name is undefined");if(void 0===t||0===t.length)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+e);this.name=e,this.times=Uu(t,this.TimeBufferType),this.values=Uu(s,this.ValueBufferType),this.setInterpolation(i||this.DefaultInterpolation)}static toJSON(e){const t=e.constructor;let s;if(t.toJSON!==this.toJSON)s=t.toJSON(e);else{s={name:e.name,times:Uu(e.times,Array),values:Uu(e.values,Array)};const t=e.getInterpolation();t!==e.DefaultInterpolation&&(s.interpolation=t)}return s.type=e.ValueTypeName,s}InterpolantFactoryMethodDiscrete(e){return new ju(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodLinear(e){return new Hu(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodSmooth(e){return new Wu(this.times,this.values,this.getValueSize(),e)}setInterpolation(e){let t;switch(e){case Pt:t=this.InterpolantFactoryMethodDiscrete;break;case Ft:t=this.InterpolantFactoryMethodLinear;break;case zt:t=this.InterpolantFactoryMethodSmooth}if(void 0===t){const t="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(void 0===this.createInterpolant){if(e===this.DefaultInterpolation)throw new Error(t);this.setInterpolation(this.DefaultInterpolation)}return console.warn("THREE.KeyframeTrack:",t),this}return this.createInterpolant=t,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return Pt;case this.InterpolantFactoryMethodLinear:return Ft;case this.InterpolantFactoryMethodSmooth:return zt}}getValueSize(){return this.values.length/this.times.length}shift(e){if(0!==e){const t=this.times;for(let s=0,i=t.length;s!==i;++s)t[s]+=e}return this}scale(e){if(1!==e){const t=this.times;for(let s=0,i=t.length;s!==i;++s)t[s]*=e}return this}trim(e,t){const s=this.times,i=s.length;let r=0,n=i-1;for(;r!==i&&s[r]<e;)++r;for(;-1!==n&&s[n]>t;)--n;if(++n,0!==r||n!==i){r>=n&&(n=Math.max(n,1),r=n-1);const e=this.getValueSize();this.times=s.slice(r,n),this.values=this.values.slice(r*e,n*e)}return this}validate(){let e=!0;const t=this.getValueSize();t-Math.floor(t)!==0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),e=!1);const s=this.times,i=this.values,r=s.length;0===r&&(console.error("THREE.KeyframeTrack: Track is empty.",this),e=!1);let n=null;for(let t=0;t!==r;t++){const i=s[t];if("number"==typeof i&&isNaN(i)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,t,i),e=!1;break}if(null!==n&&n>i){console.error("THREE.KeyframeTrack: Out of order keys.",this,t,i,n),e=!1;break}n=i}if(void 0!==i&&Ou(i))for(let t=0,s=i.length;t!==s;++t){const s=i[t];if(isNaN(s)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,t,s),e=!1;break}}return e}optimize(){const e=this.times.slice(),t=this.values.slice(),s=this.getValueSize(),i=this.getInterpolation()===zt,r=e.length-1;let n=1;for(let o=1;o<r;++o){let r=!1;const a=e[o];if(a!==e[o+1]&&(1!==o||a!==e[0]))if(i)r=!0;else{const e=o*s,i=e-s,n=e+s;for(let o=0;o!==s;++o){const s=t[e+o];if(s!==t[i+o]||s!==t[n+o]){r=!0;break}}}if(r){if(o!==n){e[n]=e[o];const i=o*s,r=n*s;for(let e=0;e!==s;++e)t[r+e]=t[i+e]}++n}}if(r>0){e[n]=e[r];for(let e=r*s,i=n*s,o=0;o!==s;++o)t[i+o]=t[e+o];++n}return n!==e.length?(this.times=e.slice(0,n),this.values=t.slice(0,n*s)):(this.times=e,this.values=t),this}clone(){const e=this.times.slice(),t=this.values.slice(),s=new(0,this.constructor)(this.name,e,t);return s.createInterpolant=this.createInterpolant,s}}qu.prototype.TimeBufferType=Float32Array,qu.prototype.ValueBufferType=Float32Array,qu.prototype.DefaultInterpolation=Ft;class $u extends qu{constructor(e,t,s){super(e,t,s)}}$u.prototype.ValueTypeName="bool",$u.prototype.ValueBufferType=Array,$u.prototype.DefaultInterpolation=Pt,$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 Zu extends Gu{constructor(e,t,s,i){super(e,t,s,i)}interpolate_(e,t,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=(s-t)/(i-t);let h=e*o;for(let e=h+o;h!==e;h+=4)Ri.slerpFlat(r,0,n,h-o,n,h,a);return r}}class Ju extends qu{InterpolantFactoryMethodLinear(e){return new Zu(this.times,this.values,this.getValueSize(),e)}}Ju.prototype.ValueTypeName="quaternion",Ju.prototype.InterpolantFactoryMethodSmooth=void 0;class Ku extends qu{constructor(e,t,s){super(e,t,s)}}Ku.prototype.ValueTypeName="string",Ku.prototype.ValueBufferType=Array,Ku.prototype.DefaultInterpolation=Pt,Ku.prototype.InterpolantFactoryMethodLinear=void 0,Ku.prototype.InterpolantFactoryMethodSmooth=void 0;class Qu extends qu{}Qu.prototype.ValueTypeName="vector";class el{constructor(e="",t=-1,s=[],i=2500){this.name=e,this.tracks=s,this.duration=t,this.blendMode=i,this.uuid=$s(),this.duration<0&&this.resetDuration()}static parse(e){const t=[],s=e.tracks,i=1/(e.fps||1);for(let e=0,r=s.length;e!==r;++e)t.push(tl(s[e]).scale(i));const r=new this(e.name,e.duration,t,e.blendMode);return r.uuid=e.uuid,r}static toJSON(e){const t=[],s=e.tracks,i={name:e.name,duration:e.duration,tracks:t,uuid:e.uuid,blendMode:e.blendMode};for(let e=0,i=s.length;e!==i;++e)t.push(qu.toJSON(s[e]));return i}static CreateFromMorphTargetSequence(e,t,s,i){const r=t.length,n=[];for(let e=0;e<r;e++){let o=[],a=[];o.push((e+r-1)%r,e,(e+1)%r),a.push(0,1,0);const h=Lu(o);o=Vu(o,1,h),a=Vu(a,1,h),i||0!==o[0]||(o.push(r),a.push(a[0])),n.push(new Yu(".morphTargetInfluences["+t[e].name+"]",o,a).scale(1/s))}return new this(e,-1,n)}static findByName(e,t){let s=e;if(!Array.isArray(e)){const t=e;s=t.geometry&&t.geometry.animations||t.animations}for(let e=0;e<s.length;e++)if(s[e].name===t)return s[e];return null}static CreateClipsFromMorphTargetSequences(e,t,s){const i={},r=/^([\w-]*?)([\d]+)$/;for(let t=0,s=e.length;t<s;t++){const s=e[t],n=s.name.match(r);if(n&&n.length>1){const e=n[1];let t=i[e];t||(i[e]=t=[]),t.push(s)}}const n=[];for(const e in i)n.push(this.CreateFromMorphTargetSequence(e,i[e],t,s));return n}static parseAnimation(e,t){if(!e)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;const s=function(e,t,s,i,r){if(0!==s.length){const n=[],o=[];Du(s,n,o,i),0!==n.length&&r.push(new e(t,n,o))}},i=[],r=e.name||"default",n=e.fps||30,o=e.blendMode;let a=e.length||-1;const h=e.hierarchy||[];for(let e=0;e<h.length;e++){const r=h[e].keys;if(r&&0!==r.length)if(r[0].morphTargets){const e={};let t;for(t=0;t<r.length;t++)if(r[t].morphTargets)for(let s=0;s<r[t].morphTargets.length;s++)e[r[t].morphTargets[s]]=-1;for(const s in e){const e=[],n=[];for(let i=0;i!==r[t].morphTargets.length;++i){const i=r[t];e.push(i.time),n.push(i.morphTarget===s?1:0)}i.push(new Yu(".morphTargetInfluence["+s+"]",e,n))}a=e.length*n}else{const n=".bones["+t[e].name+"]";s(Qu,n+".position",r,"pos",i),s(Ju,n+".quaternion",r,"rot",i),s(Qu,n+".scale",r,"scl",i)}}if(0===i.length)return null;return new this(r,a,i,o)}resetDuration(){let e=0;for(let t=0,s=this.tracks.length;t!==s;++t){const s=this.tracks[t];e=Math.max(e,s.times[s.times.length-1])}return this.duration=e,this}trim(){for(let e=0;e<this.tracks.length;e++)this.tracks[e].trim(0,this.duration);return this}validate(){let e=!0;for(let t=0;t<this.tracks.length;t++)e=e&&this.tracks[t].validate();return e}optimize(){for(let e=0;e<this.tracks.length;e++)this.tracks[e].optimize();return this}clone(){const e=[];for(let t=0;t<this.tracks.length;t++)e.push(this.tracks[t].clone());return new this.constructor(this.name,this.duration,e,this.blendMode)}toJSON(){return this.constructor.toJSON(this)}}function tl(e){if(void 0===e.type)throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");const t=function(e){switch(e.toLowerCase()){case"scalar":case"double":case"float":case"number":case"integer":return Yu;case"vector":case"vector2":case"vector3":case"vector4":return Qu;case"color":return Xu;case"quaternion":return Ju;case"bool":case"boolean":return $u;case"string":return Ku}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+e)}(e.type);if(void 0===e.times){const t=[],s=[];Du(e.keys,t,s,"value"),e.times=t,e.values=s}return void 0!==t.parse?t.parse(e):new t(e.name,e.times,e.values,e.interpolation)}const sl={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}};class il{constructor(e,t,s){const i=this;let r,n=!1,o=0,a=0;const h=[];this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=s,this.itemStart=function(e){a++,!1===n&&void 0!==i.onStart&&i.onStart(e,o,a),n=!0},this.itemEnd=function(e){o++,void 0!==i.onProgress&&i.onProgress(e,o,a),o===a&&(n=!1,void 0!==i.onLoad&&i.onLoad())},this.itemError=function(e){void 0!==i.onError&&i.onError(e)},this.resolveURL=function(e){return r?r(e):e},this.setURLModifier=function(e){return r=e,this},this.addHandler=function(e,t){return h.push(e,t),this},this.removeHandler=function(e){const t=h.indexOf(e);return-1!==t&&h.splice(t,2),this},this.getHandler=function(e){for(let t=0,s=h.length;t<s;t+=2){const s=h[t],i=h[t+1];if(s.global&&(s.lastIndex=0),s.test(e))return i}return null}}}const rl=new il;class nl{constructor(e){this.manager=void 0!==e?e:rl,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}load(){}loadAsync(e,t){const s=this;return new Promise(function(i,r){s.load(e,i,t,r)})}parse(){}setCrossOrigin(e){return this.crossOrigin=e,this}setWithCredentials(e){return this.withCredentials=e,this}setPath(e){return this.path=e,this}setResourcePath(e){return this.resourcePath=e,this}setRequestHeader(e){return this.requestHeader=e,this}}nl.DEFAULT_MATERIAL_NAME="__DEFAULT";const ol={};class al extends Error{constructor(e,t){super(e),this.response=t}}class hl extends nl{constructor(e){super(e)}load(e,t,s,i){void 0===e&&(e=""),void 0!==this.path&&(e=this.path+e),e=this.manager.resolveURL(e);const r=sl.get(e);if(void 0!==r)return this.manager.itemStart(e),setTimeout(()=>{t&&t(r),this.manager.itemEnd(e)},0),r;if(void 0!==ol[e])return void ol[e].push({onLoad:t,onProgress:s,onError:i});ol[e]=[],ol[e].push({onLoad:t,onProgress:s,onError:i});const n=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),o=this.mimeType,a=this.responseType;fetch(n).then(t=>{if(200===t.status||0===t.status){if(0===t.status&&console.warn("THREE.FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body||void 0===t.body.getReader)return t;const s=ol[e],i=t.body.getReader(),r=t.headers.get("X-File-Size")||t.headers.get("Content-Length"),n=r?parseInt(r):0,o=0!==n;let a=0;const h=new ReadableStream({start(e){!function t(){i.read().then(({done:i,value:r})=>{if(i)e.close();else{a+=r.byteLength;const i=new ProgressEvent("progress",{lengthComputable:o,loaded:a,total:n});for(let e=0,t=s.length;e<t;e++){const t=s[e];t.onProgress&&t.onProgress(i)}e.enqueue(r),t()}},t=>{e.error(t)})}()}});return new Response(h)}throw new al(`fetch for "${t.url}" responded with ${t.status}: ${t.statusText}`,t)}).then(e=>{switch(a){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then(e=>(new DOMParser).parseFromString(e,o));case"json":return e.json();default:if(void 0===o)return e.text();{const t=/charset="?([^;"\s]*)"?/i.exec(o),s=t&&t[1]?t[1].toLowerCase():void 0,i=new TextDecoder(s);return e.arrayBuffer().then(e=>i.decode(e))}}}).then(t=>{sl.add(e,t);const s=ol[e];delete ol[e];for(let e=0,i=s.length;e<i;e++){const i=s[e];i.onLoad&&i.onLoad(t)}}).catch(t=>{const s=ol[e];if(void 0===s)throw this.manager.itemError(e),t;delete ol[e];for(let e=0,i=s.length;e<i;e++){const i=s[e];i.onError&&i.onError(t)}this.manager.itemError(e)}).finally(()=>{this.manager.itemEnd(e)}),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}}class ul extends nl{constructor(e){super(e)}load(e,t,s,i){const r=this,n=new hl(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(e,function(s){try{t(r.parse(JSON.parse(s)))}catch(t){i?i(t):console.error(t),r.manager.itemError(e)}},s,i)}parse(e){const t=[];for(let s=0;s<e.length;s++){const i=el.parse(e[s]);t.push(i)}return t}}class ll extends nl{constructor(e){super(e)}load(e,t,s,i){const r=this,n=[],o=new Ya,a=new hl(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(r.withCredentials);let h=0;function u(u){a.load(e[u],function(e){const s=r.parse(e,!0);n[u]={width:s.width,height:s.height,format:s.format,mipmaps:s.mipmaps},h+=1,6===h&&(1===s.mipmapCount&&(o.minFilter=Te),o.image=n,o.format=s.format,o.needsUpdate=!0,t&&t(o))},s,i)}if(Array.isArray(e))for(let t=0,s=e.length;t<s;++t)u(t);else a.load(e,function(e){const s=r.parse(e,!0);if(s.isCubemap){const e=s.mipmaps.length/s.mipmapCount;for(let t=0;t<e;t++){n[t]={mipmaps:[]};for(let e=0;e<s.mipmapCount;e++)n[t].mipmaps.push(s.mipmaps[t*s.mipmapCount+e]),n[t].format=s.format,n[t].width=s.width,n[t].height=s.height}o.image=n}else o.image.width=s.width,o.image.height=s.height,o.mipmaps=s.mipmaps;1===s.mipmapCount&&(o.minFilter=Te),o.format=s.format,o.needsUpdate=!0,t&&t(o)},s,i);return o}}class cl extends nl{constructor(e){super(e)}load(e,t,s,i){void 0!==this.path&&(e=this.path+e),e=this.manager.resolveURL(e);const r=this,n=sl.get(e);if(void 0!==n)return r.manager.itemStart(e),setTimeout(function(){t&&t(n),r.manager.itemEnd(e)},0),n;const o=ni("img");function a(){u(),sl.add(e,this),t&&t(this),r.manager.itemEnd(e)}function h(t){u(),i&&i(t),r.manager.itemError(e),r.manager.itemEnd(e)}function u(){o.removeEventListener("load",a,!1),o.removeEventListener("error",h,!1)}return o.addEventListener("load",a,!1),o.addEventListener("error",h,!1),"data:"!==e.slice(0,5)&&void 0!==this.crossOrigin&&(o.crossOrigin=this.crossOrigin),r.manager.itemStart(e),o.src=e,o}}class dl extends nl{constructor(e){super(e)}load(e,t,s,i){const r=new to;r.colorSpace=Jt;const n=new cl(this.manager);n.setCrossOrigin(this.crossOrigin),n.setPath(this.path);let o=0;function a(s){n.load(e[s],function(e){r.images[s]=e,o++,6===o&&(r.needsUpdate=!0,t&&t(r))},void 0,i)}for(let t=0;t<e.length;++t)a(t);return r}}class pl extends nl{constructor(e){super(e)}load(e,t,s,i){const r=this,n=new Do,o=new hl(this.manager);return o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setPath(this.path),o.setWithCredentials(r.withCredentials),o.load(e,function(e){let s;try{s=r.parse(e)}catch(e){if(void 0===i)return void console.error(e);i(e)}void 0!==s.image?n.image=s.image:void 0!==s.data&&(n.image.width=s.width,n.image.height=s.height,n.image.data=s.data),n.wrapS=void 0!==s.wrapS?s.wrapS:me,n.wrapT=void 0!==s.wrapT?s.wrapT:me,n.magFilter=void 0!==s.magFilter?s.magFilter:Te,n.minFilter=void 0!==s.minFilter?s.minFilter:Te,n.anisotropy=void 0!==s.anisotropy?s.anisotropy:1,void 0!==s.colorSpace&&(n.colorSpace=s.colorSpace),void 0!==s.flipY&&(n.flipY=s.flipY),void 0!==s.format&&(n.format=s.format),void 0!==s.type&&(n.type=s.type),void 0!==s.mipmaps&&(n.mipmaps=s.mipmaps,n.minFilter=Se),1===s.mipmapCount&&(n.minFilter=Te),void 0!==s.generateMipmaps&&(n.generateMipmaps=s.generateMipmaps),n.needsUpdate=!0,t&&t(n,s)},s,i),n}}class ml extends nl{constructor(e){super(e)}load(e,t,s,i){const r=new Ti,n=new cl(this.manager);return n.setCrossOrigin(this.crossOrigin),n.setPath(this.path),n.load(e,function(e){r.image=e,r.needsUpdate=!0,void 0!==t&&t(r)},s,i),r}}class gl extends Pr{constructor(e,t=1){super(),this.isLight=!0,this.type="Light",this.color=new Kr(e),this.intensity=t}dispose(){}copy(e,t){return super.copy(e,t),this.color.copy(e.color),this.intensity=e.intensity,this}toJSON(e){const t=super.toJSON(e);return t.object.color=this.color.getHex(),t.object.intensity=this.intensity,void 0!==this.groundColor&&(t.object.groundColor=this.groundColor.getHex()),void 0!==this.distance&&(t.object.distance=this.distance),void 0!==this.angle&&(t.object.angle=this.angle),void 0!==this.decay&&(t.object.decay=this.decay),void 0!==this.penumbra&&(t.object.penumbra=this.penumbra),void 0!==this.shadow&&(t.object.shadow=this.shadow.toJSON()),void 0!==this.target&&(t.object.target=this.target.uuid),t}}class fl extends gl{constructor(e,t,s){super(e,s),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(Pr.DEFAULT_UP),this.updateMatrix(),this.groundColor=new Kr(t)}copy(e,t){return super.copy(e,t),this.groundColor.copy(e.groundColor),this}}const yl=new or,xl=new Ei,bl=new Ei;class vl{constructor(e){this.camera=e,this.intensity=1,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new ei(512,512),this.map=null,this.mapPass=null,this.matrix=new or,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new na,this._frameExtents=new ei(1,1),this._viewportCount=1,this._viewports=[new _i(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(e){const t=this.camera,s=this.matrix;xl.setFromMatrixPosition(e.matrixWorld),t.position.copy(xl),bl.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(bl),t.updateMatrixWorld(),yl.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this._frustum.setFromProjectionMatrix(yl),s.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),s.multiply(yl)}getViewport(e){return this._viewports[e]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(e){return this.camera=e.camera.clone(),this.intensity=e.intensity,this.bias=e.bias,this.radius=e.radius,this.mapSize.copy(e.mapSize),this}clone(){return(new this.constructor).copy(this)}toJSON(){const e={};return 1!==this.intensity&&(e.intensity=this.intensity),0!==this.bias&&(e.bias=this.bias),0!==this.normalBias&&(e.normalBias=this.normalBias),1!==this.radius&&(e.radius=this.radius),512===this.mapSize.x&&512===this.mapSize.y||(e.mapSize=this.mapSize.toArray()),e.camera=this.camera.toJSON(!1).object,delete e.camera.matrix,e}}class Tl extends vl{constructor(){super(new Kn(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1}updateMatrices(e){const t=this.camera,s=2*qs*e.angle*this.focus,i=this.mapSize.width/this.mapSize.height,r=e.distance||t.far;s===t.fov&&i===t.aspect&&r===t.far||(t.fov=s,t.aspect=i,t.far=r,t.updateProjectionMatrix()),super.updateMatrices(e)}copy(e){return super.copy(e),this.focus=e.focus,this}}class _l extends gl{constructor(e,t,s=0,i=Math.PI/3,r=0,n=2){super(e,t),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(Pr.DEFAULT_UP),this.updateMatrix(),this.target=new Pr,this.distance=s,this.angle=i,this.penumbra=r,this.decay=n,this.map=null,this.shadow=new Tl}get power(){return this.intensity*Math.PI}set power(e){this.intensity=e/Math.PI}dispose(){this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.angle=e.angle,this.penumbra=e.penumbra,this.decay=e.decay,this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}}const wl=new or,Sl=new Ei,Ml=new Ei;class Nl extends vl{constructor(){super(new Kn(90,1,.5,500)),this.isPointLightShadow=!0,this._frameExtents=new ei(4,2),this._viewportCount=6,this._viewports=[new _i(2,1,1,1),new _i(0,1,1,1),new _i(3,1,1,1),new _i(1,1,1,1),new _i(3,0,1,1),new _i(1,0,1,1)],this._cubeDirections=[new Ei(1,0,0),new Ei(-1,0,0),new Ei(0,0,1),new Ei(0,0,-1),new Ei(0,1,0),new Ei(0,-1,0)],this._cubeUps=[new Ei(0,1,0),new Ei(0,1,0),new Ei(0,1,0),new Ei(0,1,0),new Ei(0,0,1),new Ei(0,0,-1)]}updateMatrices(e,t=0){const s=this.camera,i=this.matrix,r=e.distance||s.far;r!==s.far&&(s.far=r,s.updateProjectionMatrix()),Sl.setFromMatrixPosition(e.matrixWorld),s.position.copy(Sl),Ml.copy(s.position),Ml.add(this._cubeDirections[t]),s.up.copy(this._cubeUps[t]),s.lookAt(Ml),s.updateMatrixWorld(),i.makeTranslation(-Sl.x,-Sl.y,-Sl.z),wl.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse),this._frustum.setFromProjectionMatrix(wl)}}class Al extends gl{constructor(e,t,s=0,i=2){super(e,t),this.isPointLight=!0,this.type="PointLight",this.distance=s,this.decay=i,this.shadow=new Nl}get power(){return 4*this.intensity*Math.PI}set power(e){this.intensity=e/(4*Math.PI)}dispose(){this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.decay=e.decay,this.shadow=e.shadow.clone(),this}}class Cl extends Xn{constructor(e=-1,t=1,s=1,i=-1,r=.1,n=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=s,this.bottom=i,this.near=r,this.far=n,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=null===e.view?null:Object.assign({},e.view),this}setViewOffset(e,t,s,i,r,n){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=e,this.view.fullHeight=t,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 e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),s=(this.right+this.left)/2,i=(this.top+this.bottom)/2;let r=s-e,n=s+e,o=i+t,a=i-t;if(null!==this.view&&this.view.enabled){const e=(this.right-this.left)/this.view.fullWidth/this.zoom,t=(this.top-this.bottom)/this.view.fullHeight/this.zoom;r+=e*this.view.offsetX,n=r+e*this.view.width,o-=t*this.view.offsetY,a=o-t*this.view.height}this.projectionMatrix.makeOrthographic(r,n,o,a,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,null!==this.view&&(t.object.view=Object.assign({},this.view)),t}}class Rl extends vl{constructor(){super(new Cl(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class El extends gl{constructor(e,t){super(e,t),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(Pr.DEFAULT_UP),this.updateMatrix(),this.target=new Pr,this.shadow=new Rl}dispose(){this.shadow.dispose()}copy(e){return super.copy(e),this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}}class Bl extends gl{constructor(e,t){super(e,t),this.isAmbientLight=!0,this.type="AmbientLight"}}class Il extends gl{constructor(e,t,s=10,i=10){super(e,t),this.isRectAreaLight=!0,this.type="RectAreaLight",this.width=s,this.height=i}get power(){return this.intensity*this.width*this.height*Math.PI}set power(e){this.intensity=e/(this.width*this.height*Math.PI)}copy(e){return super.copy(e),this.width=e.width,this.height=e.height,this}toJSON(e){const t=super.toJSON(e);return t.object.width=this.width,t.object.height=this.height,t}}class Pl{constructor(){this.isSphericalHarmonics3=!0,this.coefficients=[];for(let e=0;e<9;e++)this.coefficients.push(new Ei)}set(e){for(let t=0;t<9;t++)this.coefficients[t].copy(e[t]);return this}zero(){for(let e=0;e<9;e++)this.coefficients[e].set(0,0,0);return this}getAt(e,t){const s=e.x,i=e.y,r=e.z,n=this.coefficients;return t.copy(n[0]).multiplyScalar(.282095),t.addScaledVector(n[1],.488603*i),t.addScaledVector(n[2],.488603*r),t.addScaledVector(n[3],.488603*s),t.addScaledVector(n[4],s*i*1.092548),t.addScaledVector(n[5],i*r*1.092548),t.addScaledVector(n[6],.315392*(3*r*r-1)),t.addScaledVector(n[7],s*r*1.092548),t.addScaledVector(n[8],.546274*(s*s-i*i)),t}getIrradianceAt(e,t){const s=e.x,i=e.y,r=e.z,n=this.coefficients;return t.copy(n[0]).multiplyScalar(.886227),t.addScaledVector(n[1],1.023328*i),t.addScaledVector(n[2],1.023328*r),t.addScaledVector(n[3],1.023328*s),t.addScaledVector(n[4],.858086*s*i),t.addScaledVector(n[5],.858086*i*r),t.addScaledVector(n[6],.743125*r*r-.247708),t.addScaledVector(n[7],.858086*s*r),t.addScaledVector(n[8],.429043*(s*s-i*i)),t}add(e){for(let t=0;t<9;t++)this.coefficients[t].add(e.coefficients[t]);return this}addScaledSH(e,t){for(let s=0;s<9;s++)this.coefficients[s].addScaledVector(e.coefficients[s],t);return this}scale(e){for(let t=0;t<9;t++)this.coefficients[t].multiplyScalar(e);return this}lerp(e,t){for(let s=0;s<9;s++)this.coefficients[s].lerp(e.coefficients[s],t);return this}equals(e){for(let t=0;t<9;t++)if(!this.coefficients[t].equals(e.coefficients[t]))return!1;return!0}copy(e){return this.set(e.coefficients)}clone(){return(new this.constructor).copy(this)}fromArray(e,t=0){const s=this.coefficients;for(let i=0;i<9;i++)s[i].fromArray(e,t+3*i);return this}toArray(e=[],t=0){const s=this.coefficients;for(let i=0;i<9;i++)s[i].toArray(e,t+3*i);return e}static getBasisAt(e,t){const s=e.x,i=e.y,r=e.z;t[0]=.282095,t[1]=.488603*i,t[2]=.488603*r,t[3]=.488603*s,t[4]=1.092548*s*i,t[5]=1.092548*i*r,t[6]=.315392*(3*r*r-1),t[7]=1.092548*s*r,t[8]=.546274*(s*s-i*i)}}class Fl extends gl{constructor(e=new Pl,t=1){super(void 0,t),this.isLightProbe=!0,this.sh=e}copy(e){return super.copy(e),this.sh.copy(e.sh),this}fromJSON(e){return this.intensity=e.intensity,this.sh.fromArray(e.sh),this}toJSON(e){const t=super.toJSON(e);return t.object.sh=this.sh.toArray(),t}}class zl extends nl{constructor(e){super(e),this.textures={}}load(e,t,s,i){const r=this,n=new hl(r.manager);n.setPath(r.path),n.setRequestHeader(r.requestHeader),n.setWithCredentials(r.withCredentials),n.load(e,function(s){try{t(r.parse(JSON.parse(s)))}catch(t){i?i(t):console.error(t),r.manager.itemError(e)}},s,i)}parse(e){const t=this.textures;function s(e){return void 0===t[e]&&console.warn("THREE.MaterialLoader: Undefined texture",e),t[e]}const i=this.createMaterialFromType(e.type);if(void 0!==e.uuid&&(i.uuid=e.uuid),void 0!==e.name&&(i.name=e.name),void 0!==e.color&&void 0!==i.color&&i.color.setHex(e.color),void 0!==e.roughness&&(i.roughness=e.roughness),void 0!==e.metalness&&(i.metalness=e.metalness),void 0!==e.sheen&&(i.sheen=e.sheen),void 0!==e.sheenColor&&(i.sheenColor=(new Kr).setHex(e.sheenColor)),void 0!==e.sheenRoughness&&(i.sheenRoughness=e.sheenRoughness),void 0!==e.emissive&&void 0!==i.emissive&&i.emissive.setHex(e.emissive),void 0!==e.specular&&void 0!==i.specular&&i.specular.setHex(e.specular),void 0!==e.specularIntensity&&(i.specularIntensity=e.specularIntensity),void 0!==e.specularColor&&void 0!==i.specularColor&&i.specularColor.setHex(e.specularColor),void 0!==e.shininess&&(i.shininess=e.shininess),void 0!==e.clearcoat&&(i.clearcoat=e.clearcoat),void 0!==e.clearcoatRoughness&&(i.clearcoatRoughness=e.clearcoatRoughness),void 0!==e.dispersion&&(i.dispersion=e.dispersion),void 0!==e.iridescence&&(i.iridescence=e.iridescence),void 0!==e.iridescenceIOR&&(i.iridescenceIOR=e.iridescenceIOR),void 0!==e.iridescenceThicknessRange&&(i.iridescenceThicknessRange=e.iridescenceThicknessRange),void 0!==e.transmission&&(i.transmission=e.transmission),void 0!==e.thickness&&(i.thickness=e.thickness),void 0!==e.attenuationDistance&&(i.attenuationDistance=e.attenuationDistance),void 0!==e.attenuationColor&&void 0!==i.attenuationColor&&i.attenuationColor.setHex(e.attenuationColor),void 0!==e.anisotropy&&(i.anisotropy=e.anisotropy),void 0!==e.anisotropyRotation&&(i.anisotropyRotation=e.anisotropyRotation),void 0!==e.fog&&(i.fog=e.fog),void 0!==e.flatShading&&(i.flatShading=e.flatShading),void 0!==e.blending&&(i.blending=e.blending),void 0!==e.combine&&(i.combine=e.combine),void 0!==e.side&&(i.side=e.side),void 0!==e.shadowSide&&(i.shadowSide=e.shadowSide),void 0!==e.opacity&&(i.opacity=e.opacity),void 0!==e.transparent&&(i.transparent=e.transparent),void 0!==e.alphaTest&&(i.alphaTest=e.alphaTest),void 0!==e.alphaHash&&(i.alphaHash=e.alphaHash),void 0!==e.depthFunc&&(i.depthFunc=e.depthFunc),void 0!==e.depthTest&&(i.depthTest=e.depthTest),void 0!==e.depthWrite&&(i.depthWrite=e.depthWrite),void 0!==e.colorWrite&&(i.colorWrite=e.colorWrite),void 0!==e.blendSrc&&(i.blendSrc=e.blendSrc),void 0!==e.blendDst&&(i.blendDst=e.blendDst),void 0!==e.blendEquation&&(i.blendEquation=e.blendEquation),void 0!==e.blendSrcAlpha&&(i.blendSrcAlpha=e.blendSrcAlpha),void 0!==e.blendDstAlpha&&(i.blendDstAlpha=e.blendDstAlpha),void 0!==e.blendEquationAlpha&&(i.blendEquationAlpha=e.blendEquationAlpha),void 0!==e.blendColor&&void 0!==i.blendColor&&i.blendColor.setHex(e.blendColor),void 0!==e.blendAlpha&&(i.blendAlpha=e.blendAlpha),void 0!==e.stencilWriteMask&&(i.stencilWriteMask=e.stencilWriteMask),void 0!==e.stencilFunc&&(i.stencilFunc=e.stencilFunc),void 0!==e.stencilRef&&(i.stencilRef=e.stencilRef),void 0!==e.stencilFuncMask&&(i.stencilFuncMask=e.stencilFuncMask),void 0!==e.stencilFail&&(i.stencilFail=e.stencilFail),void 0!==e.stencilZFail&&(i.stencilZFail=e.stencilZFail),void 0!==e.stencilZPass&&(i.stencilZPass=e.stencilZPass),void 0!==e.stencilWrite&&(i.stencilWrite=e.stencilWrite),void 0!==e.wireframe&&(i.wireframe=e.wireframe),void 0!==e.wireframeLinewidth&&(i.wireframeLinewidth=e.wireframeLinewidth),void 0!==e.wireframeLinecap&&(i.wireframeLinecap=e.wireframeLinecap),void 0!==e.wireframeLinejoin&&(i.wireframeLinejoin=e.wireframeLinejoin),void 0!==e.rotation&&(i.rotation=e.rotation),void 0!==e.linewidth&&(i.linewidth=e.linewidth),void 0!==e.dashSize&&(i.dashSize=e.dashSize),void 0!==e.gapSize&&(i.gapSize=e.gapSize),void 0!==e.scale&&(i.scale=e.scale),void 0!==e.polygonOffset&&(i.polygonOffset=e.polygonOffset),void 0!==e.polygonOffsetFactor&&(i.polygonOffsetFactor=e.polygonOffsetFactor),void 0!==e.polygonOffsetUnits&&(i.polygonOffsetUnits=e.polygonOffsetUnits),void 0!==e.dithering&&(i.dithering=e.dithering),void 0!==e.alphaToCoverage&&(i.alphaToCoverage=e.alphaToCoverage),void 0!==e.premultipliedAlpha&&(i.premultipliedAlpha=e.premultipliedAlpha),void 0!==e.forceSinglePass&&(i.forceSinglePass=e.forceSinglePass),void 0!==e.visible&&(i.visible=e.visible),void 0!==e.toneMapped&&(i.toneMapped=e.toneMapped),void 0!==e.userData&&(i.userData=e.userData),void 0!==e.vertexColors&&("number"==typeof e.vertexColors?i.vertexColors=e.vertexColors>0:i.vertexColors=e.vertexColors),void 0!==e.uniforms)for(const t in e.uniforms){const r=e.uniforms[t];switch(i.uniforms[t]={},r.type){case"t":i.uniforms[t].value=s(r.value);break;case"c":i.uniforms[t].value=(new Kr).setHex(r.value);break;case"v2":i.uniforms[t].value=(new ei).fromArray(r.value);break;case"v3":i.uniforms[t].value=(new Ei).fromArray(r.value);break;case"v4":i.uniforms[t].value=(new _i).fromArray(r.value);break;case"m3":i.uniforms[t].value=(new ti).fromArray(r.value);break;case"m4":i.uniforms[t].value=(new or).fromArray(r.value);break;default:i.uniforms[t].value=r.value}}if(void 0!==e.defines&&(i.defines=e.defines),void 0!==e.vertexShader&&(i.vertexShader=e.vertexShader),void 0!==e.fragmentShader&&(i.fragmentShader=e.fragmentShader),void 0!==e.glslVersion&&(i.glslVersion=e.glslVersion),void 0!==e.extensions)for(const t in e.extensions)i.extensions[t]=e.extensions[t];if(void 0!==e.lights&&(i.lights=e.lights),void 0!==e.clipping&&(i.clipping=e.clipping),void 0!==e.size&&(i.size=e.size),void 0!==e.sizeAttenuation&&(i.sizeAttenuation=e.sizeAttenuation),void 0!==e.map&&(i.map=s(e.map)),void 0!==e.matcap&&(i.matcap=s(e.matcap)),void 0!==e.alphaMap&&(i.alphaMap=s(e.alphaMap)),void 0!==e.bumpMap&&(i.bumpMap=s(e.bumpMap)),void 0!==e.bumpScale&&(i.bumpScale=e.bumpScale),void 0!==e.normalMap&&(i.normalMap=s(e.normalMap)),void 0!==e.normalMapType&&(i.normalMapType=e.normalMapType),void 0!==e.normalScale){let t=e.normalScale;!1===Array.isArray(t)&&(t=[t,t]),i.normalScale=(new ei).fromArray(t)}return void 0!==e.displacementMap&&(i.displacementMap=s(e.displacementMap)),void 0!==e.displacementScale&&(i.displacementScale=e.displacementScale),void 0!==e.displacementBias&&(i.displacementBias=e.displacementBias),void 0!==e.roughnessMap&&(i.roughnessMap=s(e.roughnessMap)),void 0!==e.metalnessMap&&(i.metalnessMap=s(e.metalnessMap)),void 0!==e.emissiveMap&&(i.emissiveMap=s(e.emissiveMap)),void 0!==e.emissiveIntensity&&(i.emissiveIntensity=e.emissiveIntensity),void 0!==e.specularMap&&(i.specularMap=s(e.specularMap)),void 0!==e.specularIntensityMap&&(i.specularIntensityMap=s(e.specularIntensityMap)),void 0!==e.specularColorMap&&(i.specularColorMap=s(e.specularColorMap)),void 0!==e.envMap&&(i.envMap=s(e.envMap)),void 0!==e.envMapRotation&&i.envMapRotation.fromArray(e.envMapRotation),void 0!==e.envMapIntensity&&(i.envMapIntensity=e.envMapIntensity),void 0!==e.reflectivity&&(i.reflectivity=e.reflectivity),void 0!==e.refractionRatio&&(i.refractionRatio=e.refractionRatio),void 0!==e.lightMap&&(i.lightMap=s(e.lightMap)),void 0!==e.lightMapIntensity&&(i.lightMapIntensity=e.lightMapIntensity),void 0!==e.aoMap&&(i.aoMap=s(e.aoMap)),void 0!==e.aoMapIntensity&&(i.aoMapIntensity=e.aoMapIntensity),void 0!==e.gradientMap&&(i.gradientMap=s(e.gradientMap)),void 0!==e.clearcoatMap&&(i.clearcoatMap=s(e.clearcoatMap)),void 0!==e.clearcoatRoughnessMap&&(i.clearcoatRoughnessMap=s(e.clearcoatRoughnessMap)),void 0!==e.clearcoatNormalMap&&(i.clearcoatNormalMap=s(e.clearcoatNormalMap)),void 0!==e.clearcoatNormalScale&&(i.clearcoatNormalScale=(new ei).fromArray(e.clearcoatNormalScale)),void 0!==e.iridescenceMap&&(i.iridescenceMap=s(e.iridescenceMap)),void 0!==e.iridescenceThicknessMap&&(i.iridescenceThicknessMap=s(e.iridescenceThicknessMap)),void 0!==e.transmissionMap&&(i.transmissionMap=s(e.transmissionMap)),void 0!==e.thicknessMap&&(i.thicknessMap=s(e.thicknessMap)),void 0!==e.anisotropyMap&&(i.anisotropyMap=s(e.anisotropyMap)),void 0!==e.sheenColorMap&&(i.sheenColorMap=s(e.sheenColorMap)),void 0!==e.sheenRoughnessMap&&(i.sheenRoughnessMap=s(e.sheenRoughnessMap)),i}setTextures(e){return this.textures=e,this}createMaterialFromType(e){return zl.createMaterialFromType(e)}static createMaterialFromType(e){return new{ShadowMaterial:Su,SpriteMaterial:uo,RawShaderMaterial:Mu,ShaderMaterial:Hn,PointsMaterial:Va,MeshPhysicalMaterial:Au,MeshStandardMaterial:Nu,MeshPhongMaterial:Cu,MeshToonMaterial:Ru,MeshNormalMaterial:Eu,MeshLambertMaterial:Bu,MeshDepthMaterial:Iu,MeshDistanceMaterial:Pu,MeshBasicMaterial:sn,MeshMatcapMaterial:Fu,LineDashedMaterial:zu,LineBasicMaterial:Ma,Material:tn}[e]}}class Ul{static decodeText(e){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(e);let t="";for(let s=0,i=e.length;s<i;s++)t+=String.fromCharCode(e[s]);try{return decodeURIComponent(escape(t))}catch(e){return t}}static extractUrlBase(e){const t=e.lastIndexOf("/");return-1===t?"./":e.slice(0,t+1)}static resolveURL(e,t){return"string"!=typeof e||""===e?"":(/^https?:\/\//i.test(t)&&/^\//.test(e)&&(t=t.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(e)||/^data:.*,.*$/i.test(e)||/^blob:.*$/i.test(e)?e:t+e)}}class Ol extends Cn{constructor(){super(),this.isInstancedBufferGeometry=!0,this.type="InstancedBufferGeometry",this.instanceCount=1/0}copy(e){return super.copy(e),this.instanceCount=e.instanceCount,this}toJSON(){const e=super.toJSON();return e.instanceCount=this.instanceCount,e.isInstancedBufferGeometry=!0,e}}class Ll extends nl{constructor(e){super(e)}load(e,t,s,i){const r=this,n=new hl(r.manager);n.setPath(r.path),n.setRequestHeader(r.requestHeader),n.setWithCredentials(r.withCredentials),n.load(e,function(s){try{t(r.parse(JSON.parse(s)))}catch(t){i?i(t):console.error(t),r.manager.itemError(e)}},s,i)}parse(e){const t={},s={};function i(e,i){if(void 0!==t[i])return t[i];const r=e.interleavedBuffers[i],n=function(e,t){if(void 0!==s[t])return s[t];const i=e.arrayBuffers,r=i[t],n=new Uint32Array(r).buffer;return s[t]=n,n}(e,r.buffer),o=ri(r.type,n),a=new oo(o,r.stride);return a.uuid=r.uuid,t[i]=a,a}const r=e.isInstancedBufferGeometry?new Ol:new Cn,n=e.data.index;if(void 0!==n){const e=ri(n.type,n.array);r.setIndex(new cn(e,1))}const o=e.data.attributes;for(const t in o){const s=o[t];let n;if(s.isInterleavedBufferAttribute){const t=i(e.data,s.data);n=new ho(t,s.itemSize,s.offset,s.normalized)}else{const e=ri(s.type,s.array);n=new(s.isInstancedBufferAttribute?Ho:cn)(e,s.itemSize,s.normalized)}void 0!==s.name&&(n.name=s.name),void 0!==s.usage&&n.setUsage(s.usage),r.setAttribute(t,n)}const a=e.data.morphAttributes;if(a)for(const t in a){const s=a[t],n=[];for(let t=0,r=s.length;t<r;t++){const r=s[t];let o;if(r.isInterleavedBufferAttribute){const t=i(e.data,r.data);o=new ho(t,r.itemSize,r.offset,r.normalized)}else{const e=ri(r.type,r.array);o=new cn(e,r.itemSize,r.normalized)}void 0!==r.name&&(o.name=r.name),n.push(o)}r.morphAttributes[t]=n}e.data.morphTargetsRelative&&(r.morphTargetsRelative=!0);const h=e.data.groups||e.data.drawcalls||e.data.offsets;if(void 0!==h)for(let e=0,t=h.length;e!==t;++e){const t=h[e];r.addGroup(t.start,t.count,t.materialIndex)}const u=e.data.boundingSphere;if(void 0!==u){const e=new Ei;void 0!==u.center&&e.fromArray(u.center),r.boundingSphere=new Ji(e,u.radius)}return e.name&&(r.name=e.name),e.userData&&(r.userData=e.userData),r}}class Vl extends nl{constructor(e){super(e)}load(e,t,s,i){const r=this,n=""===this.path?Ul.extractUrlBase(e):this.path;this.resourcePath=this.resourcePath||n;const o=new hl(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(s){let n=null;try{n=JSON.parse(s)}catch(t){return void 0!==i&&i(t),void console.error("THREE:ObjectLoader: Can't parse "+e+".",t.message)}const o=n.metadata;if(void 0===o||void 0===o.type||"geometry"===o.type.toLowerCase())return void 0!==i&&i(new Error("THREE.ObjectLoader: Can't load "+e)),void console.error("THREE.ObjectLoader: Can't load "+e);r.parse(n,t)},s,i)}async loadAsync(e,t){const s=""===this.path?Ul.extractUrlBase(e):this.path;this.resourcePath=this.resourcePath||s;const i=new hl(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials);const r=await i.loadAsync(e,t),n=JSON.parse(r),o=n.metadata;if(void 0===o||void 0===o.type||"geometry"===o.type.toLowerCase())throw new Error("THREE.ObjectLoader: Can't load "+e);return await this.parseAsync(n)}parse(e,t){const s=this.parseAnimations(e.animations),i=this.parseShapes(e.shapes),r=this.parseGeometries(e.geometries,i),n=this.parseImages(e.images,function(){void 0!==t&&t(h)}),o=this.parseTextures(e.textures,n),a=this.parseMaterials(e.materials,o),h=this.parseObject(e.object,r,a,o,s),u=this.parseSkeletons(e.skeletons,h);if(this.bindSkeletons(h,u),this.bindLightTargets(h),void 0!==t){let e=!1;for(const t in n)if(n[t].data instanceof HTMLImageElement){e=!0;break}!1===e&&t(h)}return h}async parseAsync(e){const t=this.parseAnimations(e.animations),s=this.parseShapes(e.shapes),i=this.parseGeometries(e.geometries,s),r=await this.parseImagesAsync(e.images),n=this.parseTextures(e.textures,r),o=this.parseMaterials(e.materials,n),a=this.parseObject(e.object,i,o,n,t),h=this.parseSkeletons(e.skeletons,a);return this.bindSkeletons(a,h),this.bindLightTargets(a),a}parseShapes(e){const t={};if(void 0!==e)for(let s=0,i=e.length;s<i;s++){const i=(new Fh).fromJSON(e[s]);t[i.uuid]=i}return t}parseSkeletons(e,t){const s={},i={};if(t.traverse(function(e){e.isBone&&(i[e.uuid]=e)}),void 0!==e)for(let t=0,r=e.length;t<r;t++){const r=(new Wo).fromJSON(e[t],i);s[r.uuid]=r}return s}parseGeometries(e,t){const s={};if(void 0!==e){const i=new Ll;for(let r=0,n=e.length;r<n;r++){let n;const o=e[r];switch(o.type){case"BufferGeometry":case"InstancedBufferGeometry":n=i.parse(o);break;default:o.type in wu?n=wu[o.type].fromJSON(o,t):console.warn(`THREE.ObjectLoader: Unsupported geometry type "${o.type}"`)}n.uuid=o.uuid,void 0!==o.name&&(n.name=o.name),void 0!==o.userData&&(n.userData=o.userData),s[o.uuid]=n}}return s}parseMaterials(e,t){const s={},i={};if(void 0!==e){const r=new zl;r.setTextures(t);for(let t=0,n=e.length;t<n;t++){const n=e[t];void 0===s[n.uuid]&&(s[n.uuid]=r.parse(n)),i[n.uuid]=s[n.uuid]}}return i}parseAnimations(e){const t={};if(void 0!==e)for(let s=0;s<e.length;s++){const i=e[s],r=el.parse(i);t[r.uuid]=r}return t}parseImages(e,t){const s=this,i={};let r;function n(e){if("string"==typeof e){const t=e;return function(e){return s.manager.itemStart(e),r.load(e,function(){s.manager.itemEnd(e)},void 0,function(){s.manager.itemError(e),s.manager.itemEnd(e)})}(/^(\/\/)|([a-z]+:(\/\/)?)/i.test(t)?t:s.resourcePath+t)}return e.data?{data:ri(e.type,e.data),width:e.width,height:e.height}:null}if(void 0!==e&&e.length>0){const s=new il(t);r=new cl(s),r.setCrossOrigin(this.crossOrigin);for(let t=0,s=e.length;t<s;t++){const s=e[t],r=s.url;if(Array.isArray(r)){const e=[];for(let t=0,s=r.length;t<s;t++){const s=n(r[t]);null!==s&&(s instanceof HTMLImageElement?e.push(s):e.push(new Do(s.data,s.width,s.height)))}i[s.uuid]=new xi(e)}else{const e=n(s.url);i[s.uuid]=new xi(e)}}}return i}async parseImagesAsync(e){const t=this,s={};let i;async function r(e){if("string"==typeof e){const s=e,r=/^(\/\/)|([a-z]+:(\/\/)?)/i.test(s)?s:t.resourcePath+s;return await i.loadAsync(r)}return e.data?{data:ri(e.type,e.data),width:e.width,height:e.height}:null}if(void 0!==e&&e.length>0){i=new cl(this.manager),i.setCrossOrigin(this.crossOrigin);for(let t=0,i=e.length;t<i;t++){const i=e[t],n=i.url;if(Array.isArray(n)){const e=[];for(let t=0,s=n.length;t<s;t++){const s=n[t],i=await r(s);null!==i&&(i instanceof HTMLImageElement?e.push(i):e.push(new Do(i.data,i.width,i.height)))}s[i.uuid]=new xi(e)}else{const e=await r(i.url);s[i.uuid]=new xi(e)}}}return s}parseTextures(e,t){function s(e,t){return"number"==typeof e?e:(console.warn("THREE.ObjectLoader.parseTexture: Constant should be in numeric form.",e),t[e])}const i={};if(void 0!==e)for(let r=0,n=e.length;r<n;r++){const n=e[r];void 0===n.image&&console.warn('THREE.ObjectLoader: No "image" specified for',n.uuid),void 0===t[n.image]&&console.warn("THREE.ObjectLoader: Undefined image",n.image);const o=t[n.image],a=o.data;let h;Array.isArray(a)?(h=new to,6===a.length&&(h.needsUpdate=!0)):(h=a&&a.data?new Do:new Ti,a&&(h.needsUpdate=!0)),h.source=o,h.uuid=n.uuid,void 0!==n.name&&(h.name=n.name),void 0!==n.mapping&&(h.mapping=s(n.mapping,Dl)),void 0!==n.channel&&(h.channel=n.channel),void 0!==n.offset&&h.offset.fromArray(n.offset),void 0!==n.repeat&&h.repeat.fromArray(n.repeat),void 0!==n.center&&h.center.fromArray(n.center),void 0!==n.rotation&&(h.rotation=n.rotation),void 0!==n.wrap&&(h.wrapS=s(n.wrap[0],kl),h.wrapT=s(n.wrap[1],kl)),void 0!==n.format&&(h.format=n.format),void 0!==n.internalFormat&&(h.internalFormat=n.internalFormat),void 0!==n.type&&(h.type=n.type),void 0!==n.colorSpace&&(h.colorSpace=n.colorSpace),void 0!==n.minFilter&&(h.minFilter=s(n.minFilter,Gl)),void 0!==n.magFilter&&(h.magFilter=s(n.magFilter,Gl)),void 0!==n.anisotropy&&(h.anisotropy=n.anisotropy),void 0!==n.flipY&&(h.flipY=n.flipY),void 0!==n.generateMipmaps&&(h.generateMipmaps=n.generateMipmaps),void 0!==n.premultiplyAlpha&&(h.premultiplyAlpha=n.premultiplyAlpha),void 0!==n.unpackAlignment&&(h.unpackAlignment=n.unpackAlignment),void 0!==n.compareFunction&&(h.compareFunction=n.compareFunction),void 0!==n.userData&&(h.userData=n.userData),i[n.uuid]=h}return i}parseObject(e,t,s,i,r){let n,o,a;function h(e){return void 0===t[e]&&console.warn("THREE.ObjectLoader: Undefined geometry",e),t[e]}function u(e){if(void 0!==e){if(Array.isArray(e)){const t=[];for(let i=0,r=e.length;i<r;i++){const r=e[i];void 0===s[r]&&console.warn("THREE.ObjectLoader: Undefined material",r),t.push(s[r])}return t}return void 0===s[e]&&console.warn("THREE.ObjectLoader: Undefined material",e),s[e]}}function l(e){return void 0===i[e]&&console.warn("THREE.ObjectLoader: Undefined texture",e),i[e]}switch(e.type){case"Scene":n=new no,void 0!==e.background&&(Number.isInteger(e.background)?n.background=new Kr(e.background):n.background=l(e.background)),void 0!==e.environment&&(n.environment=l(e.environment)),void 0!==e.fog&&("Fog"===e.fog.type?n.fog=new ro(e.fog.color,e.fog.near,e.fog.far):"FogExp2"===e.fog.type&&(n.fog=new io(e.fog.color,e.fog.density)),""!==e.fog.name&&(n.fog.name=e.fog.name)),void 0!==e.backgroundBlurriness&&(n.backgroundBlurriness=e.backgroundBlurriness),void 0!==e.backgroundIntensity&&(n.backgroundIntensity=e.backgroundIntensity),void 0!==e.backgroundRotation&&n.backgroundRotation.fromArray(e.backgroundRotation),void 0!==e.environmentIntensity&&(n.environmentIntensity=e.environmentIntensity),void 0!==e.environmentRotation&&n.environmentRotation.fromArray(e.environmentRotation);break;case"PerspectiveCamera":n=new Kn(e.fov,e.aspect,e.near,e.far),void 0!==e.focus&&(n.focus=e.focus),void 0!==e.zoom&&(n.zoom=e.zoom),void 0!==e.filmGauge&&(n.filmGauge=e.filmGauge),void 0!==e.filmOffset&&(n.filmOffset=e.filmOffset),void 0!==e.view&&(n.view=Object.assign({},e.view));break;case"OrthographicCamera":n=new Cl(e.left,e.right,e.top,e.bottom,e.near,e.far),void 0!==e.zoom&&(n.zoom=e.zoom),void 0!==e.view&&(n.view=Object.assign({},e.view));break;case"AmbientLight":n=new Bl(e.color,e.intensity);break;case"DirectionalLight":n=new El(e.color,e.intensity),n.target=e.target||"";break;case"PointLight":n=new Al(e.color,e.intensity,e.distance,e.decay);break;case"RectAreaLight":n=new Il(e.color,e.intensity,e.width,e.height);break;case"SpotLight":n=new _l(e.color,e.intensity,e.distance,e.angle,e.penumbra,e.decay),n.target=e.target||"";break;case"HemisphereLight":n=new fl(e.color,e.groundColor,e.intensity);break;case"LightProbe":n=(new Fl).fromJSON(e);break;case"SkinnedMesh":o=h(e.geometry),a=u(e.material),n=new Lo(o,a),void 0!==e.bindMode&&(n.bindMode=e.bindMode),void 0!==e.bindMatrix&&n.bindMatrix.fromArray(e.bindMatrix),void 0!==e.skeleton&&(n.skeleton=e.skeleton);break;case"Mesh":o=h(e.geometry),a=u(e.material),n=new Dn(o,a);break;case"InstancedMesh":o=h(e.geometry),a=u(e.material);const t=e.count,s=e.instanceMatrix,i=e.instanceColor;n=new Ko(o,a,t),n.instanceMatrix=new Ho(new Float32Array(s.array),16),void 0!==i&&(n.instanceColor=new Ho(new Float32Array(i.array),i.itemSize));break;case"BatchedMesh":o=h(e.geometry),a=u(e.material),n=new Sa(e.maxInstanceCount,e.maxVertexCount,e.maxIndexCount,a),n.geometry=o,n.perObjectFrustumCulled=e.perObjectFrustumCulled,n.sortObjects=e.sortObjects,n._drawRanges=e.drawRanges,n._reservedRanges=e.reservedRanges,n._visibility=e.visibility,n._active=e.active,n._bounds=e.bounds.map(e=>{const t=new Pi;t.min.fromArray(e.boxMin),t.max.fromArray(e.boxMax);const s=new Ji;return s.radius=e.sphereRadius,s.center.fromArray(e.sphereCenter),{boxInitialized:e.boxInitialized,box:t,sphereInitialized:e.sphereInitialized,sphere:s}}),n._maxInstanceCount=e.maxInstanceCount,n._maxVertexCount=e.maxVertexCount,n._maxIndexCount=e.maxIndexCount,n._geometryInitialized=e.geometryInitialized,n._geometryCount=e.geometryCount,n._matricesTexture=l(e.matricesTexture.uuid),void 0!==e.colorsTexture&&(n._colorsTexture=l(e.colorsTexture.uuid));break;case"LOD":n=new Co;break;case"Line":n=new Pa(h(e.geometry),u(e.material));break;case"LineLoop":n=new La(h(e.geometry),u(e.material));break;case"LineSegments":n=new Oa(h(e.geometry),u(e.material));break;case"PointCloud":case"Points":n=new Ha(h(e.geometry),u(e.material));break;case"Sprite":n=new So(u(e.material));break;case"Group":n=new qa;break;case"Bone":n=new Vo;break;default:n=new Pr}if(n.uuid=e.uuid,void 0!==e.name&&(n.name=e.name),void 0!==e.matrix?(n.matrix.fromArray(e.matrix),void 0!==e.matrixAutoUpdate&&(n.matrixAutoUpdate=e.matrixAutoUpdate),n.matrixAutoUpdate&&n.matrix.decompose(n.position,n.quaternion,n.scale)):(void 0!==e.position&&n.position.fromArray(e.position),void 0!==e.rotation&&n.rotation.fromArray(e.rotation),void 0!==e.quaternion&&n.quaternion.fromArray(e.quaternion),void 0!==e.scale&&n.scale.fromArray(e.scale)),void 0!==e.up&&n.up.fromArray(e.up),void 0!==e.castShadow&&(n.castShadow=e.castShadow),void 0!==e.receiveShadow&&(n.receiveShadow=e.receiveShadow),e.shadow&&(void 0!==e.shadow.intensity&&(n.shadow.intensity=e.shadow.intensity),void 0!==e.shadow.bias&&(n.shadow.bias=e.shadow.bias),void 0!==e.shadow.normalBias&&(n.shadow.normalBias=e.shadow.normalBias),void 0!==e.shadow.radius&&(n.shadow.radius=e.shadow.radius),void 0!==e.shadow.mapSize&&n.shadow.mapSize.fromArray(e.shadow.mapSize),void 0!==e.shadow.camera&&(n.shadow.camera=this.parseObject(e.shadow.camera))),void 0!==e.visible&&(n.visible=e.visible),void 0!==e.frustumCulled&&(n.frustumCulled=e.frustumCulled),void 0!==e.renderOrder&&(n.renderOrder=e.renderOrder),void 0!==e.userData&&(n.userData=e.userData),void 0!==e.layers&&(n.layers.mask=e.layers),void 0!==e.children){const o=e.children;for(let e=0;e<o.length;e++)n.add(this.parseObject(o[e],t,s,i,r))}if(void 0!==e.animations){const t=e.animations;for(let e=0;e<t.length;e++){const s=t[e];n.animations.push(r[s])}}if("LOD"===e.type){void 0!==e.autoUpdate&&(n.autoUpdate=e.autoUpdate);const t=e.levels;for(let e=0;e<t.length;e++){const s=t[e],i=n.getObjectByProperty("uuid",s.object);void 0!==i&&n.addLevel(i,s.distance,s.hysteresis)}}return n}bindSkeletons(e,t){0!==Object.keys(t).length&&e.traverse(function(e){if(!0===e.isSkinnedMesh&&void 0!==e.skeleton){const s=t[e.skeleton];void 0===s?console.warn("THREE.ObjectLoader: No skeleton found with UUID:",e.skeleton):e.bind(s,e.bindMatrix)}})}bindLightTargets(e){e.traverse(function(t){if(t.isDirectionalLight||t.isSpotLight){const s=t.target,i=e.getObjectByProperty("uuid",s);t.target=void 0!==i?i:new Pr}})}}const Dl={UVMapping:ae,CubeReflectionMapping:he,CubeRefractionMapping:ue,EquirectangularReflectionMapping:le,EquirectangularRefractionMapping:ce,CubeUVReflectionMapping:de},kl={RepeatWrapping:pe,ClampToEdgeWrapping:me,MirroredRepeatWrapping:ge},Gl={NearestFilter:fe,NearestMipmapNearestFilter:ye,NearestMipmapLinearFilter:be,LinearFilter:Te,LinearMipmapNearestFilter:_e,LinearMipmapLinearFilter:Se};class Wl extends nl{constructor(e){super(e),this.isImageBitmapLoader=!0,"undefined"==typeof createImageBitmap&&console.warn("THREE.ImageBitmapLoader: createImageBitmap() not supported."),"undefined"==typeof fetch&&console.warn("THREE.ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"}}setOptions(e){return this.options=e,this}load(e,t,s,i){void 0===e&&(e=""),void 0!==this.path&&(e=this.path+e),e=this.manager.resolveURL(e);const r=this,n=sl.get(e);if(void 0!==n)return r.manager.itemStart(e),n.then?void n.then(s=>{t&&t(s),r.manager.itemEnd(e)}).catch(e=>{i&&i(e)}):(setTimeout(function(){t&&t(n),r.manager.itemEnd(e)},0),n);const o={};o.credentials="anonymous"===this.crossOrigin?"same-origin":"include",o.headers=this.requestHeader;const a=fetch(e,o).then(function(e){return e.blob()}).then(function(e){return createImageBitmap(e,Object.assign(r.options,{colorSpaceConversion:"none"}))}).then(function(s){return sl.add(e,s),t&&t(s),r.manager.itemEnd(e),s}).catch(function(t){i&&i(t),sl.remove(e),r.manager.itemError(e),r.manager.itemEnd(e)});sl.add(e,a),r.manager.itemStart(e)}}let Hl;class jl{static getContext(){return void 0===Hl&&(Hl=new(window.AudioContext||window.webkitAudioContext)),Hl}static setContext(e){Hl=e}}class ql extends nl{constructor(e){super(e)}load(e,t,s,i){const r=this,n=new hl(this.manager);function o(t){i?i(t):console.error(t),r.manager.itemError(e)}n.setResponseType("arraybuffer"),n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(e,function(e){try{const s=e.slice(0);jl.getContext().decodeAudioData(s,function(e){t(e)}).catch(o)}catch(e){o(e)}},s,i)}}const $l=new or,Xl=new or,Yl=new or;class Zl{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Kn,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Kn,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(e){const t=this._cache;if(t.focus!==e.focus||t.fov!==e.fov||t.aspect!==e.aspect*this.aspect||t.near!==e.near||t.far!==e.far||t.zoom!==e.zoom||t.eyeSep!==this.eyeSep){t.focus=e.focus,t.fov=e.fov,t.aspect=e.aspect*this.aspect,t.near=e.near,t.far=e.far,t.zoom=e.zoom,t.eyeSep=this.eyeSep,Yl.copy(e.projectionMatrix);const s=t.eyeSep/2,i=s*t.near/t.focus,r=t.near*Math.tan(js*t.fov*.5)/t.zoom;let n,o;Xl.elements[12]=-s,$l.elements[12]=s,n=-r*t.aspect+i,o=r*t.aspect+i,Yl.elements[0]=2*t.near/(o-n),Yl.elements[8]=(o+n)/(o-n),this.cameraL.projectionMatrix.copy(Yl),n=-r*t.aspect-i,o=r*t.aspect-i,Yl.elements[0]=2*t.near/(o-n),Yl.elements[8]=(o+n)/(o-n),this.cameraR.projectionMatrix.copy(Yl)}this.cameraL.matrixWorld.copy(e.matrixWorld).multiply(Xl),this.cameraR.matrixWorld.copy(e.matrixWorld).multiply($l)}}class Jl extends Kn{constructor(e=[]){super(),this.isArrayCamera=!0,this.cameras=e}}class Kl{constructor(e=!0){this.autoStart=e,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=Ql(),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 e=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){const t=Ql();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}}function Ql(){return performance.now()}const ec=new Ei,tc=new Ri,sc=new Ei,ic=new Ei;class rc extends Pr{constructor(){super(),this.type="AudioListener",this.context=jl.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new Kl}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(e){return null!==this.filter?(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)):this.gain.disconnect(this.context.destination),this.filter=e,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(e){return this.gain.gain.setTargetAtTime(e,this.context.currentTime,.01),this}updateMatrixWorld(e){super.updateMatrixWorld(e);const t=this.context.listener,s=this.up;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(ec,tc,sc),Number.isFinite(ec.x)&&Number.isFinite(ec.y)&&Number.isFinite(ec.z))if(ic.set(0,0,-1).applyQuaternion(tc),t.positionX){const e=this.context.currentTime+this.timeDelta;t.positionX.linearRampToValueAtTime(ec.x,e),t.positionY.linearRampToValueAtTime(ec.y,e),t.positionZ.linearRampToValueAtTime(ec.z,e),t.forwardX.linearRampToValueAtTime(ic.x,e),t.forwardY.linearRampToValueAtTime(ic.y,e),t.forwardZ.linearRampToValueAtTime(ic.z,e),t.upX.linearRampToValueAtTime(s.x,e),t.upY.linearRampToValueAtTime(s.y,e),t.upZ.linearRampToValueAtTime(s.z,e)}else t.setPosition(ec.x,ec.y,ec.z),t.setOrientation(ic.x,ic.y,ic.z,s.x,s.y,s.z)}}class nc extends Pr{constructor(e){super(),this.type="Audio",this.listener=e,this.context=e.context,this.gain=this.context.createGain(),this.gain.connect(e.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(e){return this.hasPlaybackControl=!1,this.sourceType="audioNode",this.source=e,this.connect(),this}setMediaElementSource(e){return this.hasPlaybackControl=!1,this.sourceType="mediaNode",this.source=this.context.createMediaElementSource(e),this.connect(),this}setMediaStreamSource(e){return this.hasPlaybackControl=!1,this.sourceType="mediaStreamNode",this.source=this.context.createMediaStreamSource(e),this.connect(),this}setBuffer(e){return this.buffer=e,this.sourceType="buffer",this.autoplay&&this.play(),this}play(e=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+e;const t=this.context.createBufferSource();return t.buffer=this.buffer,t.loop=this.loop,t.loopStart=this.loopStart,t.loopEnd=this.loopEnd,t.onended=this.onEnded.bind(this),t.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=t,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?this.buffer.duration:Number.MAX_VALUE))),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this;console.warn("THREE.Audio: this Audio has no playback control.")}stop(e=0){if(!1!==this.hasPlaybackControl)return this._progress=0,null!==this.source&&(this.source.stop(this.context.currentTime+e),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 e=1,t=this.filters.length;e<t;e++)this.filters[e-1].connect(this.filters[e]);this.filters[this.filters.length-1].connect(this.getOutput())}else this.source.connect(this.getOutput());return this._connected=!0,this}disconnect(){if(!1!==this._connected){if(this.filters.length>0){this.source.disconnect(this.filters[0]);for(let e=1,t=this.filters.length;e<t;e++)this.filters[e-1].disconnect(this.filters[e]);this.filters[this.filters.length-1].disconnect(this.getOutput())}else this.source.disconnect(this.getOutput());return this._connected=!1,this}}getFilters(){return this.filters}setFilters(e){return e||(e=[]),!0===this._connected?(this.disconnect(),this.filters=e.slice(),this.connect()):this.filters=e.slice(),this}setDetune(e){return this.detune=e,!0===this.isPlaying&&void 0!==this.source.detune&&this.source.detune.setTargetAtTime(this.detune,this.context.currentTime,.01),this}getDetune(){return this.detune}getFilter(){return this.getFilters()[0]}setFilter(e){return this.setFilters(e?[e]:[])}setPlaybackRate(e){if(!1!==this.hasPlaybackControl)return this.playbackRate=e,!0===this.isPlaying&&this.source.playbackRate.setTargetAtTime(this.playbackRate,this.context.currentTime,.01),this;console.warn("THREE.Audio: this Audio has no playback control.")}getPlaybackRate(){return this.playbackRate}onEnded(){this.isPlaying=!1}getLoop(){return!1===this.hasPlaybackControl?(console.warn("THREE.Audio: this Audio has no playback control."),!1):this.loop}setLoop(e){if(!1!==this.hasPlaybackControl)return this.loop=e,!0===this.isPlaying&&(this.source.loop=this.loop),this;console.warn("THREE.Audio: this Audio has no playback control.")}setLoopStart(e){return this.loopStart=e,this}setLoopEnd(e){return this.loopEnd=e,this}getVolume(){return this.gain.gain.value}setVolume(e){return this.gain.gain.setTargetAtTime(e,this.context.currentTime,.01),this}}const oc=new Ei,ac=new Ri,hc=new Ei,uc=new Ei;class lc extends nc{constructor(e){super(e),this.panner=this.context.createPanner(),this.panner.panningModel="HRTF",this.panner.connect(this.gain)}connect(){super.connect(),this.panner.connect(this.gain)}disconnect(){super.disconnect(),this.panner.disconnect(this.gain)}getOutput(){return this.panner}getRefDistance(){return this.panner.refDistance}setRefDistance(e){return this.panner.refDistance=e,this}getRolloffFactor(){return this.panner.rolloffFactor}setRolloffFactor(e){return this.panner.rolloffFactor=e,this}getDistanceModel(){return this.panner.distanceModel}setDistanceModel(e){return this.panner.distanceModel=e,this}getMaxDistance(){return this.panner.maxDistance}setMaxDistance(e){return this.panner.maxDistance=e,this}setDirectionalCone(e,t,s){return this.panner.coneInnerAngle=e,this.panner.coneOuterAngle=t,this.panner.coneOuterGain=s,this}updateMatrixWorld(e){if(super.updateMatrixWorld(e),!0===this.hasPlaybackControl&&!1===this.isPlaying)return;this.matrixWorld.decompose(oc,ac,hc),uc.set(0,0,1).applyQuaternion(ac);const t=this.panner;if(t.positionX){const e=this.context.currentTime+this.listener.timeDelta;t.positionX.linearRampToValueAtTime(oc.x,e),t.positionY.linearRampToValueAtTime(oc.y,e),t.positionZ.linearRampToValueAtTime(oc.z,e),t.orientationX.linearRampToValueAtTime(uc.x,e),t.orientationY.linearRampToValueAtTime(uc.y,e),t.orientationZ.linearRampToValueAtTime(uc.z,e)}else t.setPosition(oc.x,oc.y,oc.z),t.setOrientation(uc.x,uc.y,uc.z)}}class cc{constructor(e,t=2048){this.analyser=e.context.createAnalyser(),this.analyser.fftSize=t,this.data=new Uint8Array(this.analyser.frequencyBinCount),e.getOutput().connect(this.analyser)}getFrequencyData(){return this.analyser.getByteFrequencyData(this.data),this.data}getAverageFrequency(){let e=0;const t=this.getFrequencyData();for(let s=0;s<t.length;s++)e+=t[s];return e/t.length}}class dc{constructor(e,t,s){let i,r,n;switch(this.binding=e,this.valueSize=s,t){case"quaternion":i=this._slerp,r=this._slerpAdditive,n=this._setAdditiveIdentityQuaternion,this.buffer=new Float64Array(6*s),this._workIndex=5;break;case"string":case"bool":i=this._select,r=this._select,n=this._setAdditiveIdentityOther,this.buffer=new Array(5*s);break;default:i=this._lerp,r=this._lerpAdditive,n=this._setAdditiveIdentityNumeric,this.buffer=new Float64Array(5*s)}this._mixBufferRegion=i,this._mixBufferRegionAdditive=r,this._setIdentity=n,this._origIndex=3,this._addIndex=4,this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,this.useCount=0,this.referenceCount=0}accumulate(e,t){const s=this.buffer,i=this.valueSize,r=e*i+i;let n=this.cumulativeWeight;if(0===n){for(let e=0;e!==i;++e)s[r+e]=s[e];n=t}else{n+=t;const e=t/n;this._mixBufferRegion(s,r,0,e,i)}this.cumulativeWeight=n}accumulateAdditive(e){const t=this.buffer,s=this.valueSize,i=s*this._addIndex;0===this.cumulativeWeightAdditive&&this._setIdentity(),this._mixBufferRegionAdditive(t,i,0,e,s),this.cumulativeWeightAdditive+=e}apply(e){const t=this.valueSize,s=this.buffer,i=e*t+t,r=this.cumulativeWeight,n=this.cumulativeWeightAdditive,o=this.binding;if(this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,r<1){const e=t*this._origIndex;this._mixBufferRegion(s,i,e,1-r,t)}n>0&&this._mixBufferRegionAdditive(s,i,this._addIndex*t,1,t);for(let e=t,r=t+t;e!==r;++e)if(s[e]!==s[e+t]){o.setValue(s,i);break}}saveOriginalState(){const e=this.binding,t=this.buffer,s=this.valueSize,i=s*this._origIndex;e.getValue(t,i);for(let e=s,r=i;e!==r;++e)t[e]=t[i+e%s];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const e=3*this.valueSize;this.binding.setValue(this.buffer,e)}_setAdditiveIdentityNumeric(){const e=this._addIndex*this.valueSize,t=e+this.valueSize;for(let s=e;s<t;s++)this.buffer[s]=0}_setAdditiveIdentityQuaternion(){this._setAdditiveIdentityNumeric(),this.buffer[this._addIndex*this.valueSize+3]=1}_setAdditiveIdentityOther(){const e=this._origIndex*this.valueSize,t=this._addIndex*this.valueSize;for(let s=0;s<this.valueSize;s++)this.buffer[t+s]=this.buffer[e+s]}_select(e,t,s,i,r){if(i>=.5)for(let i=0;i!==r;++i)e[t+i]=e[s+i]}_slerp(e,t,s,i){Ri.slerpFlat(e,t,e,t,e,s,i)}_slerpAdditive(e,t,s,i,r){const n=this._workIndex*r;Ri.multiplyQuaternionsFlat(e,n,e,t,e,s),Ri.slerpFlat(e,t,e,t,e,n,i)}_lerp(e,t,s,i,r){const n=1-i;for(let o=0;o!==r;++o){const r=t+o;e[r]=e[r]*n+e[s+o]*i}}_lerpAdditive(e,t,s,i,r){for(let n=0;n!==r;++n){const r=t+n;e[r]=e[r]+e[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(e,t,s){this.path=t,this.parsedPath=s||bc.parseTrackName(t),this.node=bc.findNode(e,this.parsedPath.nodeName),this.rootNode=e,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(e,t,s){return e&&e.isAnimationObjectGroup?new bc.Composite(e,t,s):new bc(e,t,s)}static sanitizeNodeName(e){return e.replace(/\s/g,"_").replace(mc,"")}static parseTrackName(e){const t=yc.exec(e);if(null===t)throw new Error("PropertyBinding: Cannot parse trackName: "+e);const s={nodeName:t[2],objectName:t[3],objectIndex:t[4],propertyName:t[5],propertyIndex:t[6]},i=s.nodeName&&s.nodeName.lastIndexOf(".");if(void 0!==i&&-1!==i){const e=s.nodeName.substring(i+1);-1!==xc.indexOf(e)&&(s.nodeName=s.nodeName.substring(0,i),s.objectName=e)}if(null===s.propertyName||0===s.propertyName.length)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+e);return s}static findNode(e,t){if(void 0===t||""===t||"."===t||-1===t||t===e.name||t===e.uuid)return e;if(e.skeleton){const s=e.skeleton.getBoneByName(t);if(void 0!==s)return s}if(e.children){const s=function(e,i){for(let r=0;r<e.length;r++){const n=e[r];if(!(i||n.name!==t&&n.uuid!==t))return n;if(i&&n.userData&&n.userData.name===t)return n;const o=s(n.children,i);if(o)return o}return null},i=s(e.children);if(i)return i;{const t=s(e.children,!0);if(t)return t}}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(e,t){e[t]=this.targetObject[this.propertyName]}_getValue_array(e,t){const s=this.resolvedProperty;for(let i=0,r=s.length;i!==r;++i)e[t++]=s[i]}_getValue_arrayElement(e,t){e[t]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(e,t){this.resolvedProperty.toArray(e,t)}_setValue_direct(e,t){this.targetObject[this.propertyName]=e[t]}_setValue_direct_setNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(e,t){const s=this.resolvedProperty;for(let i=0,r=s.length;i!==r;++i)s[i]=e[t++]}_setValue_array_setNeedsUpdate(e,t){const s=this.resolvedProperty;for(let i=0,r=s.length;i!==r;++i)s[i]=e[t++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(e,t){const s=this.resolvedProperty;for(let i=0,r=s.length;i!==r;++i)s[i]=e[t++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(e,t){this.resolvedProperty[this.propertyIndex]=e[t]}_setValue_arrayElement_setNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(e,t){this.resolvedProperty.fromArray(e,t)}_setValue_fromArray_setNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(e,t){this.bind(),this.getValue(e,t)}_setValue_unbound(e,t){this.bind(),this.setValue(e,t)}bind(){let e=this.node;const t=this.parsedPath,s=t.objectName,i=t.propertyName;let r=t.propertyIndex;if(e||(e=bc.findNode(this.rootNode,t.nodeName),this.node=e),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!e)return void console.warn("THREE.PropertyBinding: No target node found for track: "+this.path+".");if(s){let i=t.objectIndex;switch(s){case"materials":if(!e.material)return void console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.",this);if(!e.material.materials)return void console.error("THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.",this);e=e.material.materials;break;case"bones":if(!e.skeleton)return void console.error("THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.",this);e=e.skeleton.bones;for(let t=0;t<e.length;t++)if(e[t].name===i){i=t;break}break;case"map":if("map"in e){e=e.map;break}if(!e.material)return void console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.",this);if(!e.material.map)return void console.error("THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.",this);e=e.material.map;break;default:if(void 0===e[s])return void console.error("THREE.PropertyBinding: Can not bind to objectName of node undefined.",this);e=e[s]}if(void 0!==i){if(void 0===e[i])return void console.error("THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.",this,e);e=e[i]}}const n=e[i];if(void 0===n){const s=t.nodeName;return void console.error("THREE.PropertyBinding: Trying to update property for track: "+s+"."+i+" but it wasn't found.",e)}let o=this.Versioning.None;this.targetObject=e,void 0!==e.needsUpdate?o=this.Versioning.NeedsUpdate:void 0!==e.matrixWorldNeedsUpdate&&(o=this.Versioning.MatrixWorldNeedsUpdate);let a=this.BindingType.Direct;if(void 0!==r){if("morphTargetInfluences"===i){if(!e.geometry)return void console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.",this);if(!e.geometry.morphAttributes)return void console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.",this);void 0!==e.morphTargetDictionary[r]&&(r=e.morphTargetDictionary[r])}a=this.BindingType.ArrayElement,this.resolvedProperty=n,this.propertyIndex=r}else void 0!==n.fromArray&&void 0!==n.toArray?(a=this.BindingType.HasFromToArray,this.resolvedProperty=n):Array.isArray(n)?(a=this.BindingType.EntireArray,this.resolvedProperty=n):this.propertyName=i;this.getValue=this.GetterByBindingType[a],this.setValue=this.SetterByBindingTypeAndVersioning[a][o]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}}bc.Composite=class{constructor(e,t,s){const i=s||bc.parseTrackName(t);this._targetGroup=e,this._bindings=e.subscribe_(t,i)}getValue(e,t){this.bind();const s=this._targetGroup.nCachedObjects_,i=this._bindings[s];void 0!==i&&i.getValue(e,t)}setValue(e,t){const s=this._bindings;for(let i=this._targetGroup.nCachedObjects_,r=s.length;i!==r;++i)s[i].setValue(e,t)}bind(){const e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,s=e.length;t!==s;++t)e[t].bind()}unbind(){const e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,s=e.length;t!==s;++t)e[t].unbind()}},bc.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3},bc.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2},bc.prototype.GetterByBindingType=[bc.prototype._getValue_direct,bc.prototype._getValue_array,bc.prototype._getValue_arrayElement,bc.prototype._getValue_toArray],bc.prototype.SetterByBindingTypeAndVersioning=[[bc.prototype._setValue_direct,bc.prototype._setValue_direct_setNeedsUpdate,bc.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[bc.prototype._setValue_array,bc.prototype._setValue_array_setNeedsUpdate,bc.prototype._setValue_array_setMatrixWorldNeedsUpdate],[bc.prototype._setValue_arrayElement,bc.prototype._setValue_arrayElement_setNeedsUpdate,bc.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[bc.prototype._setValue_fromArray,bc.prototype._setValue_fromArray_setNeedsUpdate,bc.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];class vc{constructor(){this.isAnimationObjectGroup=!0,this.uuid=$s(),this._objects=Array.prototype.slice.call(arguments),this.nCachedObjects_=0;const e={};this._indicesByUUID=e;for(let t=0,s=arguments.length;t!==s;++t)e[arguments[t].uuid]=t;this._paths=[],this._parsedPaths=[],this._bindings=[],this._bindingsIndicesByPath={};const t=this;this.stats={objects:{get total(){return t._objects.length},get inUse(){return this.total-t.nCachedObjects_}},get bindingsPerObject(){return t._bindings.length}}}add(){const e=this._objects,t=this._indicesByUUID,s=this._paths,i=this._parsedPaths,r=this._bindings,n=r.length;let o,a=e.length,h=this.nCachedObjects_;for(let u=0,l=arguments.length;u!==l;++u){const l=arguments[u],c=l.uuid;let d=t[c];if(void 0===d){d=a++,t[c]=d,e.push(l);for(let e=0,t=n;e!==t;++e)r[e].push(new bc(l,s[e],i[e]))}else if(d<h){o=e[d];const a=--h,u=e[a];t[u.uuid]=d,e[d]=u,t[c]=a,e[a]=l;for(let e=0,t=n;e!==t;++e){const t=r[e],n=t[a];let o=t[d];t[d]=n,void 0===o&&(o=new bc(l,s[e],i[e])),t[a]=o}}else e[d]!==o&&console.error("THREE.AnimationObjectGroup: Different objects with the same UUID detected. Clean the caches or recreate your infrastructure when reloading scenes.")}this.nCachedObjects_=h}remove(){const e=this._objects,t=this._indicesByUUID,s=this._bindings,i=s.length;let r=this.nCachedObjects_;for(let n=0,o=arguments.length;n!==o;++n){const o=arguments[n],a=o.uuid,h=t[a];if(void 0!==h&&h>=r){const n=r++,u=e[n];t[u.uuid]=h,e[h]=u,t[a]=n,e[n]=o;for(let e=0,t=i;e!==t;++e){const t=s[e],i=t[n],r=t[h];t[h]=i,t[n]=r}}}this.nCachedObjects_=r}uncache(){const e=this._objects,t=this._indicesByUUID,s=this._bindings,i=s.length;let r=this.nCachedObjects_,n=e.length;for(let o=0,a=arguments.length;o!==a;++o){const a=arguments[o].uuid,h=t[a];if(void 0!==h)if(delete t[a],h<r){const o=--r,a=e[o],u=--n,l=e[u];t[a.uuid]=h,e[h]=a,t[l.uuid]=o,e[o]=l,e.pop();for(let e=0,t=i;e!==t;++e){const t=s[e],i=t[o],r=t[u];t[h]=i,t[o]=r,t.pop()}}else{const r=--n,o=e[r];r>0&&(t[o.uuid]=h),e[h]=o,e.pop();for(let e=0,t=i;e!==t;++e){const t=s[e];t[h]=t[r],t.pop()}}}this.nCachedObjects_=r}subscribe_(e,t){const s=this._bindingsIndicesByPath;let i=s[e];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[e]=i,n.push(e),o.push(t),r.push(l);for(let s=u,i=a.length;s!==i;++s){const i=a[s];l[s]=new bc(i,e,t)}return l}unsubscribe_(e){const t=this._bindingsIndicesByPath,s=t[e];if(void 0!==s){const i=this._paths,r=this._parsedPaths,n=this._bindings,o=n.length-1,a=n[o];t[e[o]]=s,n[s]=a,n.pop(),r[s]=r[o],r.pop(),i[s]=i[o],i.pop()}}}class Tc{constructor(e,t,s=null,i=t.blendMode){this._mixer=e,this._clip=t,this._localRoot=s,this.blendMode=i;const r=t.tracks,n=r.length,o=new Array(n),a={endingStart:Ut,endingEnd:Ut};for(let e=0;e!==n;++e){const t=r[e].createInterpolant(null);o[e]=t,t.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(e){return this._startTime=e,this}setLoop(e,t){return this.loop=e,this.repetitions=t,this}setEffectiveWeight(e){return this.weight=e,this._effectiveWeight=this.enabled?e:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(e){return this._scheduleFading(e,0,1)}fadeOut(e){return this._scheduleFading(e,1,0)}crossFadeFrom(e,t,s){if(e.fadeOut(t),this.fadeIn(t),s){const s=this._clip.duration,i=e._clip.duration,r=i/s,n=s/i;e.warp(1,r,t),this.warp(n,1,t)}return this}crossFadeTo(e,t,s){return e.crossFadeFrom(this,t,s)}stopFading(){const e=this._weightInterpolant;return null!==e&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(e)),this}setEffectiveTimeScale(e){return this.timeScale=e,this._effectiveTimeScale=this.paused?0:e,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(e){return this.timeScale=this._clip.duration/e,this.stopWarping()}syncWith(e){return this.time=e.time,this.timeScale=e.timeScale,this.stopWarping()}halt(e){return this.warp(this._effectiveTimeScale,0,e)}warp(e,t,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]=e/n,h[1]=t/n,this}stopWarping(){const e=this._timeScaleInterpolant;return null!==e&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(e)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(e,t,s,i){if(!this.enabled)return void this._updateWeight(e);const r=this._startTime;if(null!==r){const i=(e-r)*s;i<0||0===s?t=0:(this._startTime=null,t=s*i)}t*=this._updateTimeScale(e);const n=this._updateTime(t),o=this._updateWeight(e);if(o>0){const e=this._interpolants,t=this._propertyBindings;if(this.blendMode===Dt)for(let s=0,i=e.length;s!==i;++s)e[s].evaluate(n),t[s].accumulateAdditive(o);else for(let s=0,r=e.length;s!==r;++s)e[s].evaluate(n),t[s].accumulate(i,o)}}_updateWeight(e){let t=0;if(this.enabled){t=this.weight;const s=this._weightInterpolant;if(null!==s){const i=s.evaluate(e)[0];t*=i,e>s.parameterPositions[1]&&(this.stopFading(),0===i&&(this.enabled=!1))}}return this._effectiveWeight=t,t}_updateTimeScale(e){let t=0;if(!this.paused){t=this.timeScale;const s=this._timeScaleInterpolant;if(null!==s){t*=s.evaluate(e)[0],e>s.parameterPositions[1]&&(this.stopWarping(),0===t?this.paused=!0:this.timeScale=t)}}return this._effectiveTimeScale=t,t}_updateTime(e){const t=this._clip.duration,s=this.loop;let i=this.time+e,r=this._loopCount;const n=2202===s;if(0===e)return-1===r||!n||1&~r?i:t-i;if(2200===s){-1===r&&(this._loopCount=0,this._setEndings(!0,!0,!1));e:{if(i>=t)i=t;else{if(!(i<0)){this.time=i;break e}i=0}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:e<0?-1:1})}}else{if(-1===r&&(e>=0?(r=0,this._setEndings(!0,0===this.repetitions,n)):this._setEndings(0===this.repetitions,!0,n)),i>=t||i<0){const s=Math.floor(i/t);i-=t*s,r+=Math.abs(s);const o=this.repetitions-r;if(o<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,i=e>0?t:0,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:e>0?1:-1});else{if(1===o){const t=e<0;this._setEndings(t,!t,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&~r))return t-i}return i}_setEndings(e,t,s){const i=this._interpolantSettings;s?(i.endingStart=Ot,i.endingEnd=Ot):(i.endingStart=e?this.zeroSlopeAtStart?Ot:Ut:Lt,i.endingEnd=t?this.zeroSlopeAtEnd?Ot:Ut:Lt)}_scheduleFading(e,t,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]=t,o[1]=r+e,a[1]=s,this}}const _c=new Float32Array(1);class wc extends Gs{constructor(e){super(),this._root=e,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}_bindAction(e,t){const s=e._localRoot||this._root,i=e._clip.tracks,r=i.length,n=e._propertyBindings,o=e._interpolants,a=s.uuid,h=this._bindingsByRootAndName;let u=h[a];void 0===u&&(u={},h[a]=u);for(let e=0;e!==r;++e){const r=i[e],h=r.name;let l=u[h];if(void 0!==l)++l.referenceCount,n[e]=l;else{if(l=n[e],void 0!==l){null===l._cacheIndex&&(++l.referenceCount,this._addInactiveBinding(l,a,h));continue}const i=t&&t._propertyBindings[e].binding.parsedPath;l=new dc(bc.create(s,h,i),r.ValueTypeName,r.getValueSize()),++l.referenceCount,this._addInactiveBinding(l,a,h),n[e]=l}o[e].resultBuffer=l.buffer}}_activateAction(e){if(!this._isActiveAction(e)){if(null===e._cacheIndex){const t=(e._localRoot||this._root).uuid,s=e._clip.uuid,i=this._actionsByClip[s];this._bindAction(e,i&&i.knownActions[0]),this._addInactiveAction(e,s,t)}const t=e._propertyBindings;for(let e=0,s=t.length;e!==s;++e){const s=t[e];0===s.useCount++&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(e)}}_deactivateAction(e){if(this._isActiveAction(e)){const t=e._propertyBindings;for(let e=0,s=t.length;e!==s;++e){const s=t[e];0===--s.useCount&&(s.restoreOriginalState(),this._takeBackBinding(s))}this._takeBackAction(e)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const e=this;this.stats={actions:{get total(){return e._actions.length},get inUse(){return e._nActiveActions}},bindings:{get total(){return e._bindings.length},get inUse(){return e._nActiveBindings}},controlInterpolants:{get total(){return e._controlInterpolants.length},get inUse(){return e._nActiveControlInterpolants}}}}_isActiveAction(e){const t=e._cacheIndex;return null!==t&&t<this._nActiveActions}_addInactiveAction(e,t,s){const i=this._actions,r=this._actionsByClip;let n=r[t];if(void 0===n)n={knownActions:[e],actionByRoot:{}},e._byClipCacheIndex=0,r[t]=n;else{const t=n.knownActions;e._byClipCacheIndex=t.length,t.push(e)}e._cacheIndex=i.length,i.push(e),n.actionByRoot[s]=e}_removeInactiveAction(e){const t=this._actions,s=t[t.length-1],i=e._cacheIndex;s._cacheIndex=i,t[i]=s,t.pop(),e._cacheIndex=null;const r=e._clip.uuid,n=this._actionsByClip,o=n[r],a=o.knownActions,h=a[a.length-1],u=e._byClipCacheIndex;h._byClipCacheIndex=u,a[u]=h,a.pop(),e._byClipCacheIndex=null;delete o.actionByRoot[(e._localRoot||this._root).uuid],0===a.length&&delete n[r],this._removeInactiveBindingsForAction(e)}_removeInactiveBindingsForAction(e){const t=e._propertyBindings;for(let e=0,s=t.length;e!==s;++e){const s=t[e];0===--s.referenceCount&&this._removeInactiveBinding(s)}}_lendAction(e){const t=this._actions,s=e._cacheIndex,i=this._nActiveActions++,r=t[i];e._cacheIndex=i,t[i]=e,r._cacheIndex=s,t[s]=r}_takeBackAction(e){const t=this._actions,s=e._cacheIndex,i=--this._nActiveActions,r=t[i];e._cacheIndex=i,t[i]=e,r._cacheIndex=s,t[s]=r}_addInactiveBinding(e,t,s){const i=this._bindingsByRootAndName,r=this._bindings;let n=i[t];void 0===n&&(n={},i[t]=n),n[s]=e,e._cacheIndex=r.length,r.push(e)}_removeInactiveBinding(e){const t=this._bindings,s=e.binding,i=s.rootNode.uuid,r=s.path,n=this._bindingsByRootAndName,o=n[i],a=t[t.length-1],h=e._cacheIndex;a._cacheIndex=h,t[h]=a,t.pop(),delete o[r],0===Object.keys(o).length&&delete n[i]}_lendBinding(e){const t=this._bindings,s=e._cacheIndex,i=this._nActiveBindings++,r=t[i];e._cacheIndex=i,t[i]=e,r._cacheIndex=s,t[s]=r}_takeBackBinding(e){const t=this._bindings,s=e._cacheIndex,i=--this._nActiveBindings,r=t[i];e._cacheIndex=i,t[i]=e,r._cacheIndex=s,t[s]=r}_lendControlInterpolant(){const e=this._controlInterpolants,t=this._nActiveControlInterpolants++;let s=e[t];return void 0===s&&(s=new Hu(new Float32Array(2),new Float32Array(2),1,_c),s.__cacheIndex=t,e[t]=s),s}_takeBackControlInterpolant(e){const t=this._controlInterpolants,s=e.__cacheIndex,i=--this._nActiveControlInterpolants,r=t[i];e.__cacheIndex=i,t[i]=e,r.__cacheIndex=s,t[s]=r}clipAction(e,t,s){const i=t||this._root,r=i.uuid;let n="string"==typeof e?el.findByName(i,e):e;const o=null!==n?n.uuid:e,a=this._actionsByClip[o];let h=null;if(void 0===s&&(s=null!==n?n.blendMode:Vt),void 0!==a){const e=a.actionByRoot[r];if(void 0!==e&&e.blendMode===s)return e;h=a.knownActions[0],null===n&&(n=h._clip)}if(null===n)return null;const u=new Tc(this,n,t,s);return this._bindAction(u,h),this._addInactiveAction(u,o,r),u}existingAction(e,t){const s=t||this._root,i=s.uuid,r="string"==typeof e?el.findByName(s,e):e,n=r?r.uuid:e,o=this._actionsByClip[n];return void 0!==o&&o.actionByRoot[i]||null}stopAllAction(){const e=this._actions;for(let t=this._nActiveActions-1;t>=0;--t)e[t].stop();return this}update(e){e*=this.timeScale;const t=this._actions,s=this._nActiveActions,i=this.time+=e,r=Math.sign(e),n=this._accuIndex^=1;for(let o=0;o!==s;++o){t[o]._update(i,e,r,n)}const o=this._bindings,a=this._nActiveBindings;for(let e=0;e!==a;++e)o[e].apply(n);return this}setTime(e){this.time=0;for(let e=0;e<this._actions.length;e++)this._actions[e].time=0;return this.update(e)}getRoot(){return this._root}uncacheClip(e){const t=this._actions,s=e.uuid,i=this._actionsByClip,r=i[s];if(void 0!==r){const e=r.knownActions;for(let s=0,i=e.length;s!==i;++s){const i=e[s];this._deactivateAction(i);const r=i._cacheIndex,n=t[t.length-1];i._cacheIndex=null,i._byClipCacheIndex=null,n._cacheIndex=r,t[r]=n,t.pop(),this._removeInactiveBindingsForAction(i)}delete i[s]}}uncacheRoot(e){const t=e.uuid,s=this._actionsByClip;for(const e in s){const i=s[e].actionByRoot[t];void 0!==i&&(this._deactivateAction(i),this._removeInactiveAction(i))}const i=this._bindingsByRootAndName[t];if(void 0!==i)for(const e in i){const t=i[e];t.restoreOriginalState(),this._removeInactiveBinding(t)}}uncacheAction(e,t){const s=this.existingAction(e,t);null!==s&&(this._deactivateAction(s),this._removeInactiveAction(s))}}let Sc=class e{constructor(e){this.value=e}clone(){return new e(void 0===this.value.clone?this.value:this.value.clone())}},Mc=0,Nc=class extends Gs{constructor(){super(),this.isUniformsGroup=!0,Object.defineProperty(this,"id",{value:Mc++}),this.name="",this.usage=Rs,this.uniforms=[]}add(e){return this.uniforms.push(e),this}remove(e){const t=this.uniforms.indexOf(e);return-1!==t&&this.uniforms.splice(t,1),this}setName(e){return this.name=e,this}setUsage(e){return this.usage=e,this}dispose(){return this.dispatchEvent({type:"dispose"}),this}copy(e){this.name=e.name,this.usage=e.usage;const t=e.uniforms;this.uniforms.length=0;for(let e=0,s=t.length;e<s;e++){const s=Array.isArray(t[e])?t[e]:[t[e]];for(let e=0;e<s.length;e++)this.uniforms.push(s[e].clone())}return this}clone(){return(new this.constructor).copy(this)}};class Ac extends oo{constructor(e,t,s=1){super(e,t),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=s}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}clone(e){const t=super.clone(e);return t.meshPerAttribute=this.meshPerAttribute,t}toJSON(e){const t=super.toJSON(e);return t.isInstancedInterleavedBuffer=!0,t.meshPerAttribute=this.meshPerAttribute,t}}class Cc{constructor(e,t,s,i,r){this.isGLBufferAttribute=!0,this.name="",this.buffer=e,this.type=t,this.itemSize=s,this.elementSize=i,this.count=r,this.version=0}set needsUpdate(e){!0===e&&this.version++}setBuffer(e){return this.buffer=e,this}setType(e,t){return this.type=e,this.elementSize=t,this}setItemSize(e){return this.itemSize=e,this}setCount(e){return this.count=e,this}}const Rc=new or;class Ec{constructor(e,t,s=0,i=1/0){this.ray=new nr(e,t),this.near=s,this.far=i,this.camera=null,this.layers=new yr,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(e,t){this.ray.set(e,t)}setFromCamera(e,t){t.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(e.x,e.y,.5).unproject(t).sub(this.ray.origin).normalize(),this.camera=t):t.isOrthographicCamera?(this.ray.origin.set(e.x,e.y,(t.near+t.far)/(t.near-t.far)).unproject(t),this.ray.direction.set(0,0,-1).transformDirection(t.matrixWorld),this.camera=t):console.error("THREE.Raycaster: Unsupported camera type: "+t.type)}setFromXRController(e){return Rc.identity().extractRotation(e.matrixWorld),this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(Rc),this}intersectObject(e,t=!0,s=[]){return Ic(e,this,s,t),s.sort(Bc),s}intersectObjects(e,t=!0,s=[]){for(let i=0,r=e.length;i<r;i++)Ic(e[i],this,s,t);return s.sort(Bc),s}}function Bc(e,t){return e.distance-t.distance}function Ic(e,t,s,i){let r=!0;if(e.layers.test(t.layers)){!1===e.raycast(t,s)&&(r=!1)}if(!0===r&&!0===i){const i=e.children;for(let e=0,r=i.length;e<r;e++)Ic(i[e],t,s,!0)}}class Pc{constructor(e=1,t=0,s=0){return this.radius=e,this.phi=t,this.theta=s,this}set(e,t,s){return this.radius=e,this.phi=t,this.theta=s,this}copy(e){return this.radius=e.radius,this.phi=e.phi,this.theta=e.theta,this}makeSafe(){const e=1e-6;return this.phi=Math.max(e,Math.min(Math.PI-e,this.phi)),this}setFromVector3(e){return this.setFromCartesianCoords(e.x,e.y,e.z)}setFromCartesianCoords(e,t,s){return this.radius=Math.sqrt(e*e+t*t+s*s),0===this.radius?(this.theta=0,this.phi=0):(this.theta=Math.atan2(e,s),this.phi=Math.acos(Xs(t/this.radius,-1,1))),this}clone(){return(new this.constructor).copy(this)}}class Fc{constructor(e=1,t=0,s=0){return this.radius=e,this.theta=t,this.y=s,this}set(e,t,s){return this.radius=e,this.theta=t,this.y=s,this}copy(e){return this.radius=e.radius,this.theta=e.theta,this.y=e.y,this}setFromVector3(e){return this.setFromCartesianCoords(e.x,e.y,e.z)}setFromCartesianCoords(e,t,s){return this.radius=Math.sqrt(e*e+s*s),this.theta=Math.atan2(e,s),this.y=t,this}clone(){return(new this.constructor).copy(this)}}class zc{constructor(e,t,s,i){zc.prototype.isMatrix2=!0,this.elements=[1,0,0,1],void 0!==e&&this.set(e,t,s,i)}identity(){return this.set(1,0,0,1),this}fromArray(e,t=0){for(let s=0;s<4;s++)this.elements[s]=e[s+t];return this}set(e,t,s,i){const r=this.elements;return r[0]=e,r[2]=t,r[1]=s,r[3]=i,this}}const Uc=new ei;class Oc{constructor(e=new ei(1/0,1/0),t=new ei(-1/0,-1/0)){this.isBox2=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromPoints(e){this.makeEmpty();for(let t=0,s=e.length;t<s;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){const s=Uc.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(s),this.max.copy(e).add(s),this}clone(){return(new this.constructor).copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=1/0,this.max.x=this.max.y=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y}getCenter(e){return this.isEmpty()?e.set(0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Uc).distanceTo(e)}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}}const Lc=new Ei,Vc=new Ei;class Dc{constructor(e=new Ei,t=new Ei){this.start=e,this.end=t}set(e,t){return this.start.copy(e),this.end.copy(t),this}copy(e){return this.start.copy(e.start),this.end.copy(e.end),this}getCenter(e){return e.addVectors(this.start,this.end).multiplyScalar(.5)}delta(e){return e.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(e,t){return this.delta(t).multiplyScalar(e).add(this.start)}closestPointToPointParameter(e,t){Lc.subVectors(e,this.start),Vc.subVectors(this.end,this.start);const s=Vc.dot(Vc);let i=Vc.dot(Lc)/s;return t&&(i=Xs(i,0,1)),i}closestPointToPoint(e,t,s){const i=this.closestPointToPointParameter(e,t);return this.delta(s).multiplyScalar(i).add(this.start)}applyMatrix4(e){return this.start.applyMatrix4(e),this.end.applyMatrix4(e),this}equals(e){return e.start.equals(this.start)&&e.end.equals(this.end)}clone(){return(new this.constructor).copy(this)}}const kc=new Ei;class Gc extends Pr{constructor(e,t){super(),this.light=e,this.matrixAutoUpdate=!1,this.color=t,this.type="SpotLightHelper";const s=new Cn,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 e=0,t=1,s=32;e<s;e++,t++){const r=e/s*Math.PI*2,n=t/s*Math.PI*2;i.push(Math.cos(r),Math.sin(r),1,Math.cos(n),Math.sin(n),1)}s.setAttribute("position",new vn(i,3));const r=new Ma({fog:!1,toneMapped:!1});this.cone=new Oa(s,r),this.add(this.cone),this.update()}dispose(){this.cone.geometry.dispose(),this.cone.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),this.light.target.updateWorldMatrix(!0,!1),this.parent?(this.parent.updateWorldMatrix(!0),this.matrix.copy(this.parent.matrixWorld).invert().multiply(this.light.matrixWorld)):this.matrix.copy(this.light.matrixWorld),this.matrixWorld.copy(this.light.matrixWorld);const e=this.light.distance?this.light.distance:1e3,t=e*Math.tan(this.light.angle);this.cone.scale.set(t,t,e),kc.setFromMatrixPosition(this.light.target.matrixWorld),this.cone.lookAt(kc),void 0!==this.color?this.cone.material.color.set(this.color):this.cone.material.color.copy(this.light.color)}}const Wc=new Ei,Hc=new or,jc=new or;class qc extends Oa{constructor(e){const t=$c(e),s=new Cn,i=[],r=[],n=new Kr(0,0,1),o=new Kr(0,1,0);for(let e=0;e<t.length;e++){const s=t[e];s.parent&&s.parent.isBone&&(i.push(0,0,0),i.push(0,0,0),r.push(n.r,n.g,n.b),r.push(o.r,o.g,o.b))}s.setAttribute("position",new vn(i,3)),s.setAttribute("color",new vn(r,3));super(s,new Ma({vertexColors:!0,depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0})),this.isSkeletonHelper=!0,this.type="SkeletonHelper",this.root=e,this.bones=t,this.matrix=e.matrixWorld,this.matrixAutoUpdate=!1}updateMatrixWorld(e){const t=this.bones,s=this.geometry,i=s.getAttribute("position");jc.copy(this.root.matrixWorld).invert();for(let e=0,s=0;e<t.length;e++){const r=t[e];r.parent&&r.parent.isBone&&(Hc.multiplyMatrices(jc,r.matrixWorld),Wc.setFromMatrixPosition(Hc),i.setXYZ(s,Wc.x,Wc.y,Wc.z),Hc.multiplyMatrices(jc,r.parent.matrixWorld),Wc.setFromMatrixPosition(Hc),i.setXYZ(s+1,Wc.x,Wc.y,Wc.z),s+=2)}s.getAttribute("position").needsUpdate=!0,super.updateMatrixWorld(e)}dispose(){this.geometry.dispose(),this.material.dispose()}}function $c(e){const t=[];!0===e.isBone&&t.push(e);for(let s=0;s<e.children.length;s++)t.push.apply(t,$c(e.children[s]));return t}class Xc extends Dn{constructor(e,t,s){super(new fu(t,4,2),new sn({wireframe:!0,fog:!1,toneMapped:!1})),this.light=e,this.color=s,this.type="PointLightHelper",this.matrix=this.light.matrixWorld,this.matrixAutoUpdate=!1,this.update()}dispose(){this.geometry.dispose(),this.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),void 0!==this.color?this.material.color.set(this.color):this.material.color.copy(this.light.color)}}const Yc=new Ei,Zc=new Kr,Jc=new Kr;class Kc extends Pr{constructor(e,t,s){super(),this.light=e,this.matrix=e.matrixWorld,this.matrixAutoUpdate=!1,this.color=s,this.type="HemisphereLightHelper";const i=new du(t);i.rotateY(.5*Math.PI),this.material=new sn({wireframe:!0,fog:!1,toneMapped:!1}),void 0===this.color&&(this.material.vertexColors=!0);const r=i.getAttribute("position"),n=new Float32Array(3*r.count);i.setAttribute("color",new cn(n,3)),this.add(new Dn(i,this.material)),this.update()}dispose(){this.children[0].geometry.dispose(),this.children[0].material.dispose()}update(){const e=this.children[0];if(void 0!==this.color)this.material.color.set(this.color);else{const t=e.geometry.getAttribute("color");Zc.copy(this.light.color),Jc.copy(this.light.groundColor);for(let e=0,s=t.count;e<s;e++){const i=e<s/2?Zc:Jc;t.setXYZ(e,i.r,i.g,i.b)}t.needsUpdate=!0}this.light.updateWorldMatrix(!0,!1),e.lookAt(Yc.setFromMatrixPosition(this.light.matrixWorld).negate())}}class Qc extends Oa{constructor(e=10,t=10,s=4473924,i=8947848){s=new Kr(s),i=new Kr(i);const r=t/2,n=e/t,o=e/2,a=[],h=[];for(let e=0,u=0,l=-o;e<=t;e++,l+=n){a.push(-o,0,l,o,0,l),a.push(l,0,-o,l,0,o);const t=e===r?s:i;t.toArray(h,u),u+=3,t.toArray(h,u),u+=3,t.toArray(h,u),u+=3,t.toArray(h,u),u+=3}const u=new Cn;u.setAttribute("position",new vn(a,3)),u.setAttribute("color",new vn(h,3));super(u,new Ma({vertexColors:!0,toneMapped:!1})),this.type="GridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}}class ed extends Oa{constructor(e=10,t=16,s=8,i=64,r=4473924,n=8947848){r=new Kr(r),n=new Kr(n);const o=[],a=[];if(t>1)for(let s=0;s<t;s++){const i=s/t*(2*Math.PI),h=Math.sin(i)*e,u=Math.cos(i)*e;o.push(0,0,0),o.push(h,0,u);const l=1&s?r:n;a.push(l.r,l.g,l.b),a.push(l.r,l.g,l.b)}for(let t=0;t<s;t++){const h=1&t?r:n,u=e-e/s*t;for(let e=0;e<i;e++){let t=e/i*(2*Math.PI),s=Math.sin(t)*u,r=Math.cos(t)*u;o.push(s,0,r),a.push(h.r,h.g,h.b),t=(e+1)/i*(2*Math.PI),s=Math.sin(t)*u,r=Math.cos(t)*u,o.push(s,0,r),a.push(h.r,h.g,h.b)}}const h=new Cn;h.setAttribute("position",new vn(o,3)),h.setAttribute("color",new vn(a,3));super(h,new Ma({vertexColors:!0,toneMapped:!1})),this.type="PolarGridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}}const td=new Ei,sd=new Ei,id=new Ei;class rd extends Pr{constructor(e,t,s){super(),this.light=e,this.matrix=e.matrixWorld,this.matrixAutoUpdate=!1,this.color=s,this.type="DirectionalLightHelper",void 0===t&&(t=1);let i=new Cn;i.setAttribute("position",new vn([-t,t,0,t,t,0,t,-t,0,-t,-t,0,-t,t,0],3));const r=new Ma({fog:!1,toneMapped:!1});this.lightPlane=new Pa(i,r),this.add(this.lightPlane),i=new Cn,i.setAttribute("position",new vn([0,0,0,0,0,1],3)),this.targetLine=new Pa(i,r),this.add(this.targetLine),this.update()}dispose(){this.lightPlane.geometry.dispose(),this.lightPlane.material.dispose(),this.targetLine.geometry.dispose(),this.targetLine.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),this.light.target.updateWorldMatrix(!0,!1),td.setFromMatrixPosition(this.light.matrixWorld),sd.setFromMatrixPosition(this.light.target.matrixWorld),id.subVectors(sd,td),this.lightPlane.lookAt(sd),void 0!==this.color?(this.lightPlane.material.color.set(this.color),this.targetLine.material.color.set(this.color)):(this.lightPlane.material.color.copy(this.light.color),this.targetLine.material.color.copy(this.light.color)),this.targetLine.lookAt(sd),this.targetLine.scale.z=id.length()}}const nd=new Ei,od=new Xn;class ad extends Oa{constructor(e){const t=new Cn,s=new Ma({color:16777215,vertexColors:!0,toneMapped:!1}),i=[],r=[],n={};function o(e,t){a(e),a(t)}function a(e){i.push(0,0,0),r.push(0,0,0),void 0===n[e]&&(n[e]=[]),n[e].push(i.length/3-1)}o("n1","n2"),o("n2","n4"),o("n4","n3"),o("n3","n1"),o("f1","f2"),o("f2","f4"),o("f4","f3"),o("f3","f1"),o("n1","f1"),o("n2","f2"),o("n3","f3"),o("n4","f4"),o("p","n1"),o("p","n2"),o("p","n3"),o("p","n4"),o("u1","u2"),o("u2","u3"),o("u3","u1"),o("c","t"),o("p","c"),o("cn1","cn2"),o("cn3","cn4"),o("cf1","cf2"),o("cf3","cf4"),t.setAttribute("position",new vn(i,3)),t.setAttribute("color",new vn(r,3)),super(t,s),this.type="CameraHelper",this.camera=e,this.camera.updateProjectionMatrix&&this.camera.updateProjectionMatrix(),this.matrix=e.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=n,this.update();const h=new Kr(16755200),u=new Kr(16711680),l=new Kr(43775),c=new Kr(16777215),d=new Kr(3355443);this.setColors(h,u,l,c,d)}setColors(e,t,s,i,r){const n=this.geometry.getAttribute("color");n.setXYZ(0,e.r,e.g,e.b),n.setXYZ(1,e.r,e.g,e.b),n.setXYZ(2,e.r,e.g,e.b),n.setXYZ(3,e.r,e.g,e.b),n.setXYZ(4,e.r,e.g,e.b),n.setXYZ(5,e.r,e.g,e.b),n.setXYZ(6,e.r,e.g,e.b),n.setXYZ(7,e.r,e.g,e.b),n.setXYZ(8,e.r,e.g,e.b),n.setXYZ(9,e.r,e.g,e.b),n.setXYZ(10,e.r,e.g,e.b),n.setXYZ(11,e.r,e.g,e.b),n.setXYZ(12,e.r,e.g,e.b),n.setXYZ(13,e.r,e.g,e.b),n.setXYZ(14,e.r,e.g,e.b),n.setXYZ(15,e.r,e.g,e.b),n.setXYZ(16,e.r,e.g,e.b),n.setXYZ(17,e.r,e.g,e.b),n.setXYZ(18,e.r,e.g,e.b),n.setXYZ(19,e.r,e.g,e.b),n.setXYZ(20,e.r,e.g,e.b),n.setXYZ(21,e.r,e.g,e.b),n.setXYZ(22,e.r,e.g,e.b),n.setXYZ(23,e.r,e.g,e.b),n.setXYZ(24,t.r,t.g,t.b),n.setXYZ(25,t.r,t.g,t.b),n.setXYZ(26,t.r,t.g,t.b),n.setXYZ(27,t.r,t.g,t.b),n.setXYZ(28,t.r,t.g,t.b),n.setXYZ(29,t.r,t.g,t.b),n.setXYZ(30,t.r,t.g,t.b),n.setXYZ(31,t.r,t.g,t.b),n.setXYZ(32,s.r,s.g,s.b),n.setXYZ(33,s.r,s.g,s.b),n.setXYZ(34,s.r,s.g,s.b),n.setXYZ(35,s.r,s.g,s.b),n.setXYZ(36,s.r,s.g,s.b),n.setXYZ(37,s.r,s.g,s.b),n.setXYZ(38,i.r,i.g,i.b),n.setXYZ(39,i.r,i.g,i.b),n.setXYZ(40,r.r,r.g,r.b),n.setXYZ(41,r.r,r.g,r.b),n.setXYZ(42,r.r,r.g,r.b),n.setXYZ(43,r.r,r.g,r.b),n.setXYZ(44,r.r,r.g,r.b),n.setXYZ(45,r.r,r.g,r.b),n.setXYZ(46,r.r,r.g,r.b),n.setXYZ(47,r.r,r.g,r.b),n.setXYZ(48,r.r,r.g,r.b),n.setXYZ(49,r.r,r.g,r.b),n.needsUpdate=!0}update(){const e=this.geometry,t=this.pointMap;od.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse),hd("c",t,e,od,0,0,-1),hd("t",t,e,od,0,0,1),hd("n1",t,e,od,-1,-1,-1),hd("n2",t,e,od,1,-1,-1),hd("n3",t,e,od,-1,1,-1),hd("n4",t,e,od,1,1,-1),hd("f1",t,e,od,-1,-1,1),hd("f2",t,e,od,1,-1,1),hd("f3",t,e,od,-1,1,1),hd("f4",t,e,od,1,1,1),hd("u1",t,e,od,.7,1.1,-1),hd("u2",t,e,od,-.7,1.1,-1),hd("u3",t,e,od,0,2,-1),hd("cf1",t,e,od,-1,0,1),hd("cf2",t,e,od,1,0,1),hd("cf3",t,e,od,0,-1,1),hd("cf4",t,e,od,0,1,1),hd("cn1",t,e,od,-1,0,-1),hd("cn2",t,e,od,1,0,-1),hd("cn3",t,e,od,0,-1,-1),hd("cn4",t,e,od,0,1,-1),e.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}}function hd(e,t,s,i,r,n,o){nd.set(r,n,o).unproject(i);const a=t[e];if(void 0!==a){const e=s.getAttribute("position");for(let t=0,s=a.length;t<s;t++)e.setXYZ(a[t],nd.x,nd.y,nd.z)}}const ud=new Pi;class ld extends Oa{constructor(e,t=16776960){const s=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),i=new Float32Array(24),r=new Cn;r.setIndex(new cn(s,1)),r.setAttribute("position",new cn(i,3)),super(r,new Ma({color:t,toneMapped:!1})),this.object=e,this.type="BoxHelper",this.matrixAutoUpdate=!1,this.update()}update(e){if(void 0!==e&&console.warn("THREE.BoxHelper: .update() has no longer arguments."),void 0!==this.object&&ud.setFromObject(this.object),ud.isEmpty())return;const t=ud.min,s=ud.max,i=this.geometry.attributes.position,r=i.array;r[0]=s.x,r[1]=s.y,r[2]=s.z,r[3]=t.x,r[4]=s.y,r[5]=s.z,r[6]=t.x,r[7]=t.y,r[8]=s.z,r[9]=s.x,r[10]=t.y,r[11]=s.z,r[12]=s.x,r[13]=s.y,r[14]=t.z,r[15]=t.x,r[16]=s.y,r[17]=t.z,r[18]=t.x,r[19]=t.y,r[20]=t.z,r[21]=s.x,r[22]=t.y,r[23]=t.z,i.needsUpdate=!0,this.geometry.computeBoundingSphere()}setFromObject(e){return this.object=e,this.update(),this}copy(e,t){return super.copy(e,t),this.object=e.object,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class cd extends Oa{constructor(e,t=16776960){const s=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),i=new Cn;i.setIndex(new cn(s,1)),i.setAttribute("position",new vn([1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,-1,1,-1,-1],3)),super(i,new Ma({color:t,toneMapped:!1})),this.box=e,this.type="Box3Helper",this.geometry.computeBoundingSphere()}updateMatrixWorld(e){const t=this.box;t.isEmpty()||(t.getCenter(this.position),t.getSize(this.scale),this.scale.multiplyScalar(.5),super.updateMatrixWorld(e))}dispose(){this.geometry.dispose(),this.material.dispose()}}class dd extends Pa{constructor(e,t=1,s=16776960){const i=s,r=new Cn;r.setAttribute("position",new vn([1,-1,0,-1,1,0,-1,-1,0,1,1,0,-1,1,0,-1,-1,0,1,-1,0,1,1,0],3)),r.computeBoundingSphere(),super(r,new Ma({color:i,toneMapped:!1})),this.type="PlaneHelper",this.plane=e,this.size=t;const n=new Cn;n.setAttribute("position",new vn([1,1,0,-1,1,0,-1,-1,0,1,1,0,-1,-1,0,1,-1,0],3)),n.computeBoundingSphere(),this.add(new Dn(n,new sn({color:i,opacity:.2,transparent:!0,depthWrite:!1,toneMapped:!1})))}updateMatrixWorld(e){this.position.set(0,0,0),this.scale.set(.5*this.size,.5*this.size,1),this.lookAt(this.plane.normal),this.translateZ(-this.plane.constant),super.updateMatrixWorld(e)}dispose(){this.geometry.dispose(),this.material.dispose(),this.children[0].geometry.dispose(),this.children[0].material.dispose()}}const pd=new Ei;let md,gd;class fd extends Pr{constructor(e=new Ei(0,0,1),t=new Ei(0,0,0),s=1,i=16776960,r=.2*s,n=.2*r){super(),this.type="ArrowHelper",void 0===md&&(md=new Cn,md.setAttribute("position",new vn([0,0,0,0,1,0],3)),gd=new Mh(0,.5,1,5,1),gd.translate(0,-.5,0)),this.position.copy(t),this.line=new Pa(md,new Ma({color:i,toneMapped:!1})),this.line.matrixAutoUpdate=!1,this.add(this.line),this.cone=new Dn(gd,new sn({color:i,toneMapped:!1})),this.cone.matrixAutoUpdate=!1,this.add(this.cone),this.setDirection(e),this.setLength(s,r,n)}setDirection(e){if(e.y>.99999)this.quaternion.set(0,0,0,1);else if(e.y<-.99999)this.quaternion.set(1,0,0,0);else{pd.set(e.z,0,-e.x).normalize();const t=Math.acos(e.y);this.quaternion.setFromAxisAngle(pd,t)}}setLength(e,t=.2*e,s=.2*t){this.line.scale.set(1,Math.max(1e-4,e-t),1),this.line.updateMatrix(),this.cone.scale.set(s,t,s),this.cone.position.y=e,this.cone.updateMatrix()}setColor(e){this.line.material.color.set(e),this.cone.material.color.set(e)}copy(e){return super.copy(e,!1),this.line.copy(e.line),this.cone.copy(e.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}}class yd extends Oa{constructor(e=1){const t=[0,0,0,e,0,0,0,0,0,0,e,0,0,0,0,0,0,e],s=new Cn;s.setAttribute("position",new vn(t,3)),s.setAttribute("color",new vn([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(e,t,s){const i=new Kr,r=this.geometry.attributes.color.array;return i.set(e),i.toArray(r,0),i.toArray(r,3),i.set(t),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 xd{constructor(){this.type="ShapePath",this.color=new Kr,this.subPaths=[],this.currentPath=null}moveTo(e,t){return this.currentPath=new Th,this.subPaths.push(this.currentPath),this.currentPath.moveTo(e,t),this}lineTo(e,t){return this.currentPath.lineTo(e,t),this}quadraticCurveTo(e,t,s,i){return this.currentPath.quadraticCurveTo(e,t,s,i),this}bezierCurveTo(e,t,s,i,r,n){return this.currentPath.bezierCurveTo(e,t,s,i,r,n),this}splineThru(e){return this.currentPath.splineThru(e),this}toShapes(e){function t(e,t){const s=t.length;let i=!1;for(let r=s-1,n=0;n<s;r=n++){let s=t[r],o=t[n],a=o.x-s.x,h=o.y-s.y;if(Math.abs(h)>Number.EPSILON){if(h<0&&(s=t[n],a=-a,o=t[r],h=-h),e.y<s.y||e.y>o.y)continue;if(e.y===s.y){if(e.x===s.x)return!0}else{const t=h*(e.x-s.x)-a*(e.y-s.y);if(0===t)return!0;if(t<0)continue;i=!i}}else{if(e.y!==s.y)continue;if(o.x<=e.x&&e.x<=s.x||s.x<=e.x&&e.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=e?!h:h;const u=[],l=[];let c,d,p=[],m=0;l[m]=void 0,p[m]=[];for(let t=0,o=i.length;t<o;t++)n=i[t],c=n.getPoints(),r=s(c),r=e?!r:r,r?(!h&&l[m]&&m++,l[m]={s:new Fh,p:c},l[m].s.curves=n.curves,h&&m++,p[m]=[]):p[m].push({h:n,p:c[0]});if(!l[0])return function(e){const t=[];for(let s=0,i=e.length;s<i;s++){const i=e[s],r=new Fh;r.curves=i.curves,t.push(r)}return t}(i);if(l.length>1){let e=!1,s=0;for(let e=0,t=l.length;e<t;e++)u[e]=[];for(let i=0,r=l.length;i<r;i++){const r=p[i];for(let n=0;n<r.length;n++){const o=r[n];let a=!0;for(let r=0;r<l.length;r++)t(o.p,l[r].p)&&(i!==r&&s++,a?(a=!1,u[r].push(o)):e=!0);a&&u[i].push(o)}}s>0&&!1===e&&(p=u)}for(let e=0,t=l.length;e<t;e++){o=l[e].s,a.push(o),d=p[e];for(let e=0,t=d.length;e<t;e++)o.holes.push(d[e].h)}return a}}class bd extends Gs{constructor(e,t=null){super(),this.object=e,this.domElement=t,this.enabled=!0,this.state=-1,this.keys={},this.mouseButtons={LEFT:null,MIDDLE:null,RIGHT:null},this.touches={ONE:null,TWO:null}}connect(){}disconnect(){}dispose(){}update(){}}class vd extends Si{constructor(e=1,t=1,s=1,i={}){console.warn('THREE.WebGLMultipleRenderTargets has been deprecated and will be removed in r172. Use THREE.WebGLRenderTarget and set the "count" parameter to enable MRT.'),super(e,t,{...i,count:s}),this.isWebGLMultipleRenderTargets=!0}get texture(){return this.textures}}const Td=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveMap","envMap","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"];class _d{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=Td,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}getRenderObjectData(e){let t=this.renderObjects.get(e);return void 0===t&&(t={material:this.getMaterialData(e.material),worldMatrix:e.object.matrixWorld.clone()},e.object.center&&(t.center=e.object.center.clone()),e.object.morphTargetInfluences&&(t.morphTargetInfluences=e.object.morphTargetInfluences.slice()),null!==e.bundle&&(t.version=e.bundle.version),this.renderObjects.set(e,t)),t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return null!==e.renderer.nodes.modelViewMatrix||null!==e.renderer.nodes.modelNormalViewMatrix}getMaterialData(e){const t={};for(const s of this.refreshUniforms){const i=e[s];null!=i&&("object"==typeof i&&void 0!==i.clone?!0===i.isTexture?t[s]={id:i.id,version:i.version}:t[s]=i.clone():t[s]=i)}return t}equals(e){const{object:t,material:s}=e,i=this.getRenderObjectData(e);if(!0!==i.worldMatrix.equals(t.matrixWorld))return i.worldMatrix.copy(t.matrixWorld),!1;const r=i.material;for(const e in r){const t=r[e],i=s[e];if(void 0!==t.equals){if(!1===t.equals(i))return t.copy(i),!1}else if(!0===i.isTexture){if(t.id!==i.id||t.version!==i.version)return t.id=i.id,t.version=i.version,!1}else if(t!==i)return r[e]=i,!1}if(i.morphTargetInfluences){let e=!1;for(let s=0;s<i.morphTargetInfluences.length;s++)i.morphTargetInfluences[s]!==t.morphTargetInfluences[s]&&(e=!0);if(e)return!0}return i.center&&!1===i.center.equals(t.center)?(i.center.copy(t.center),!0):(null!==e.bundle&&(i.version=e.bundle.version),!0)}needsRefresh(e,t){if(this.hasNode||this.hasAnimation||this.firstInitialization(e))return!0;const{renderId:s}=t;if(this.renderId!==s)return this.renderId=s,!0;const i=!0===e.object.static,r=null!==e.bundle&&!0===e.bundle.static&&this.getRenderObjectData(e).version===e.bundle.version;if(i||r)return!1;return!0!==this.equals(e)}}function wd(e,t=0){let s=3735928559^t,i=1103547991^t;if(e instanceof Array)for(let t,r=0;r<e.length;r++)t=e[r],s=Math.imul(s^t,2654435761),i=Math.imul(i^t,1597334677);else for(let t,r=0;r<e.length;r++)t=e.charCodeAt(r),s=Math.imul(s^t,2654435761),i=Math.imul(i^t,1597334677);return s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(i^i>>>13,3266489909),i=Math.imul(i^i>>>16,2246822507),i^=Math.imul(s^s>>>13,3266489909),4294967296*(2097151&i)+(s>>>0)}const Sd=e=>wd(e),Md=e=>wd(e),Nd=(...e)=>wd(e);function Ad(e,t=!1){const s=[];!0===e.isNode&&(s.push(e.id),e=e.getSelf());for(const{property:i,childNode:r}of Cd(e))s.push(s,wd(i.slice(0,-4)),r.getCacheKey(t));return wd(s)}function*Cd(e,t=!1){for(const s in e){if(!0===s.startsWith("_"))continue;const i=e[s];if(!0===Array.isArray(i))for(let e=0;e<i.length;e++){const r=i[e];r&&(!0===r.isNode||t&&"function"==typeof r.toJSON)&&(yield{property:s,index:e,childNode:r})}else if(i&&!0===i.isNode)yield{property:s,childNode:i};else if("object"==typeof i)for(const e in i){const r=i[e];r&&(!0===r.isNode||t&&"function"==typeof r.toJSON)&&(yield{property:s,index:e,childNode:r})}}}function Rd(e){if(null==e)return null;const t=typeof e;return!0===e.isNode?"node":"number"===t?"float":"boolean"===t?"bool":"string"===t?"string":"function"===t?"shader":!0===e.isVector2?"vec2":!0===e.isVector3?"vec3":!0===e.isVector4?"vec4":!0===e.isMatrix3?"mat3":!0===e.isMatrix4?"mat4":!0===e.isColor?"color":e instanceof ArrayBuffer?"ArrayBuffer":null}function Ed(e,...t){const s=e?e.slice(-4):void 0;return 1===t.length&&("vec2"===s?t=[t[0],t[0]]:"vec3"===s?t=[t[0],t[0],t[0]]:"vec4"===s&&(t=[t[0],t[0],t[0],t[0]])),"color"===e?new Kr(...t):"vec2"===s?new ei(...t):"vec3"===s?new Ei(...t):"vec4"===s?new _i(...t):"mat3"===s?new ti(...t):"mat4"===s?new or(...t):"bool"===e?t[0]||!1:"float"===e||"int"===e||"uint"===e?t[0]||0:"string"===e?t[0]||"":"ArrayBuffer"===e?Id(t[0]):null}function Bd(e){let t="";const s=new Uint8Array(e);for(let e=0;e<s.length;e++)t+=String.fromCharCode(s[e]);return btoa(t)}function Id(e){return Uint8Array.from(atob(e),e=>e.charCodeAt(0)).buffer}var Pd=Object.freeze({__proto__:null,arrayBufferToBase64:Bd,base64ToArrayBuffer:Id,getCacheKey:Ad,getNodeChildren:Cd,getValueFromType:Ed,getValueType:Rd,hash:Nd,hashArray:Md,hashString:Sd});const Fd={VERTEX:"vertex",FRAGMENT:"fragment"},zd={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Ud={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Od=["fragment","vertex"],Ld=["setup","analyze","generate"],Vd=[...Od,"compute"],Dd=["x","y","z","w"];let kd=0;class Gd extends Gs{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=zd.NONE,this.updateBeforeType=zd.NONE,this.updateAfterType=zd.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:kd++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,zd.FRAME)}onRenderUpdate(e){return this.onUpdate(e,zd.RENDER)}onObjectUpdate(e){return this.onUpdate(e,zd.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of Cd(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return!0!==(e=e||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=Ad(this,e),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){const t=e.getNodeProperties(this);let s=0;for(const e of this.getChildren())t["node"+s++]=e;return null}analyze(e){if(1===e.increaseUsage(this)){const t=e.getNodeProperties(this);for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}generate(e,t){const{outputNode:s}=e.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const s=this.getShared(e);if(this!==s)return s.build(e,t);e.addNode(this),e.addChain(this);let i=null;const r=e.getBuildStage();if("setup"===r){this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){e.stack.nodes.length;t.initialized=!0,t.outputNode=this.setup(e),null!==t.outputNode&&e.stack.nodes.length;for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}else if("analyze"===r)this.analyze(e);else if("generate"===r){if(1===this.generate.length){const s=this.getNodeType(e),r=e.getDataFromNode(this);i=r.snippet,void 0===i?(i=this.generate(e)||"",r.snippet=i):void 0!==r.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),i=e.format(i,s,t)}else i=this.generate(e,t)||""}return e.removeChain(this),i}getSerializeChildren(){return Cd(this)}serialize(e){const t=this.getSerializeChildren(),s={};for(const{property:i,index:r,childNode:n}of t)void 0!==r?(void 0===s[i]&&(s[i]=Number.isInteger(r)?[]:{}),s[i][r]=n.toJSON(e.meta).uuid):s[i]=n.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){const i=[];for(const r of e.inputNodes[s])i.push(t[r]);this[s]=i}else if("object"==typeof e.inputNodes[s]){const i={};for(const r in e.inputNodes[s]){const n=e.inputNodes[s][r];i[r]=t[n]}this[s]=i}else{const i=e.inputNodes[s];this[s]=t[i]}}}toJSON(e){const{uuid:t,type:s}=this,i=void 0===e||"string"==typeof e;i&&(e={textures:{},images:{},nodes:{}});let r=e.nodes[t];function n(e){const t=[];for(const s in e){const i=e[s];delete i.metadata,t.push(i)}return t}if(void 0===r&&(r={uuid:t,type:s,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==i&&(e.nodes[r.uuid]=r),this.serialize(r),delete r.meta),i){const t=n(e.textures),s=n(e.images),i=n(e.nodes);t.length>0&&(r.textures=t),s.length>0&&(r.images=s),i.length>0&&(r.nodes=i)}return r}}class Wd extends Gd{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){return`${this.node.build(e)}[ ${this.indexNode.build(e,"uint")} ]`}}class Hd extends Gd{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let s=null;for(const i of this.convertTo.split("|"))null!==s&&e.getTypeLength(t)!==e.getTypeLength(i)||(s=i);return s}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const s=this.node,i=this.getNodeType(e),r=s.build(e,i);return e.format(r,i,t)}}class jd extends Gd{static get type(){return"TempNode"}constructor(e){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const s=e.getVectorType(this.getNodeType(e,t)),i=e.getDataFromNode(this);if(void 0!==i.propertyName)return e.format(i.propertyName,s,t);if("void"!==s&&"void"!==t&&this.hasDependencies(e)){const r=super.build(e,s),n=e.getVarFromNode(this,null,s),o=e.getPropertyName(n);return e.addLineFlowCode(`${o} = ${r}`,this),i.snippet=r,i.propertyName=o,e.format(i.propertyName,s,t)}}return super.build(e,t)}}class qd extends jd{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce((t,s)=>t+e.getTypeLength(s.getNodeType(e)),0))}generate(e,t){const s=this.getNodeType(e),i=this.nodes,r=e.getComponentType(s),n=[];for(const t of i){let s=t.build(e);const i=e.getComponentType(t.getNodeType(e));i!==r&&(s=e.format(s,i,r)),n.push(s)}const o=`${e.getType(s)}( ${n.join(", ")} )`;return e.format(o,s,t)}}const $d=Dd.join("");class Xd extends Gd{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(Dd.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){const s=this.node,i=e.getTypeLength(s.getNodeType(e));let r=null;if(i>1){let n=null;this.getVectorLength()>=i&&(n=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const o=s.build(e,n);r=this.components.length===i&&this.components===$d.slice(0,this.components.length)?e.format(o,n,t):e.format(`${o}.${this.components}`,this.getNodeType(e),t)}else r=s.build(e,t);return r}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class Yd extends jd{static get type(){return"SetNode"}constructor(e,t,s){super(),this.sourceNode=e,this.components=t,this.targetNode=s}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:s,targetNode:i}=this,r=this.getNodeType(e),n=e.getTypeFromLength(s.length,i.getNodeType(e)),o=i.build(e,n),a=t.build(e,r),h=e.getTypeLength(r),u=[];for(let e=0;e<h;e++){const t=Dd[e];t===s[0]?(u.push(o),e+=s.length-1):u.push(a+"."+t)}return`${e.getType(r)}( ${u.join(", ")} )`}}class Zd extends jd{static get type(){return"FlipNode"}constructor(e,t){super(),this.sourceNode=e,this.components=t}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{components:t,sourceNode:s}=this,i=this.getNodeType(e),r=s.build(e),n=e.getVarFromNode(this),o=e.getPropertyName(n);e.addLineFlowCode(o+" = "+r,this);const a=e.getTypeLength(i),h=[];let u=0;for(let e=0;e<a;e++){const s=Dd[e];s===t[u]?(h.push("1.0 - "+o+"."+s),u++):h.push(o+"."+s)}return`${e.getType(i)}( ${h.join(", ")} )`}}class Jd extends Gd{static get type(){return"InputNode"}constructor(e,t=null){super(t),this.isInputNode=!0,this.value=e,this.precision=null}getNodeType(){return null===this.nodeType?Rd(this.value):this.nodeType}getInputType(e){return this.getNodeType(e)}setPrecision(e){return this.precision=e,this}serialize(e){super.serialize(e),e.value=this.value,this.value&&this.value.toArray&&(e.value=this.value.toArray()),e.valueType=Rd(this.value),e.nodeType=this.nodeType,"ArrayBuffer"===e.valueType&&(e.value=Bd(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?Ed(e.valueType,...e.value):e.value,this.precision=e.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(e.value))}generate(){console.warn("Abstract function.")}}class Kd extends Jd{static get type(){return"ConstNode"}constructor(e,t=null){super(e,t),this.isConstNode=!0}generateConst(e){return e.generateConst(this.getNodeType(e),this.value)}generate(e,t){const s=this.getNodeType(e);return e.format(this.generateConst(e),s,t)}}let Qd=null;const ep=new Map;function tp(e,t){if(ep.has(e))console.warn(`Redefinition of method chaining ${e}`);else{if("function"!=typeof t)throw new Error(`Node element ${e} is not a function`);ep.set(e,t)}}const sp=e=>e.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),ip=e=>sp(e).split("").sort().join(""),rp={setup(e,t){const s=t.shift();return e(Rp(s),...t)},get(e,t,s){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(Qd.assign(s,...e),s);if(ep.has(t)){const i=ep.get(t);return e.isStackNode?(...e)=>s.add(i(...e)):(...e)=>i(s,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&ep.has(t.slice(0,t.length-6))){const i=ep.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>s.assign(e[0],i(...e)):(...e)=>s.assign(i(s,...e))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return t=sp(t),Cp(new Xd(s,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=ip(t.slice(3).toLowerCase()),s=>Cp(new Yd(e,t,s));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=ip(t.slice(4).toLowerCase()),()=>Cp(new Zd(Cp(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),Cp(new Xd(e,t));if(!0===/^\d+$/.test(t))return Cp(new Wd(s,new Kd(Number(t),"uint")))}return Reflect.get(e,t,s)},set:(e,t,s,i)=>"string"!=typeof t||void 0!==e[t]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(t)&&"width"!==t&&"height"!==t&&"depth"!==t&&!0!==/^\d+$/.test(t)?Reflect.set(e,t,s,i):(i[t].assign(s),!0)},np=new WeakMap,op=new WeakMap,ap=function(e,t=null){for(const s in e)e[s]=Cp(e[s],t);return e},hp=function(e,t=null){const s=e.length;for(let i=0;i<s;i++)e[i]=Cp(e[i],t);return e},up=function(e,t=null,s=null,i=null){const r=e=>Cp(null!==i?Object.assign(e,i):e);return null===t?(...t)=>r(new e(...Ep(t))):null!==s?(s=Cp(s),(...i)=>r(new e(t,...Ep(i),s))):(...s)=>r(new e(t,...Ep(s)))},lp=function(e,...t){return Cp(new e(...Ep(t)))};class cp extends Gd{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}call(e){const{shaderNode:t,inputNodes:s}=this,i=e.getNodeProperties(t);if(i.onceOutput)return i.onceOutput;let r=null;if(t.layout){let i=op.get(e.constructor);void 0===i&&(i=new WeakMap,op.set(e.constructor,i));let n=i.get(t);void 0===n&&(n=Cp(e.buildFunctionNode(t)),i.set(t,n)),null!==e.currentFunctionNode&&e.currentFunctionNode.includes.push(n),r=Cp(n.call(s))}else{const i=t.jsFunc,n=null!==s?i(s,e):i(e);r=Cp(n)}return t.once&&(i.onceOutput=r),r}getOutputNode(e){const t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class dp extends Gd{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}call(e=null){return Rp(e),Cp(new cp(this,e))}setup(){return this.call()}}const pp=[!1,!0],mp=[0,1,2,3],gp=[-1,-2],fp=[.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],yp=new Map;for(const e of pp)yp.set(e,new Kd(e));const xp=new Map;for(const e of mp)xp.set(e,new Kd(e,"uint"));const bp=new Map([...xp].map(e=>new Kd(e.value,"int")));for(const e of gp)bp.set(e,new Kd(e,"int"));const vp=new Map([...bp].map(e=>new Kd(e.value)));for(const e of fp)vp.set(e,new Kd(e));for(const e of fp)vp.set(-e,new Kd(-e));const Tp={bool:yp,uint:xp,ints:bp,float:vp},_p=new Map([...yp,...vp]),wp=(e,t)=>_p.has(e)?_p.get(e):!0===e.isNode?e:new Kd(e,t),Sp=function(e,t=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(e)&&s.every(e=>"object"!=typeof e))&&(s=[Ed(e,...s)]),1===s.length&&null!==t&&t.has(s[0]))return Cp(t.get(s[0]));if(1===s.length){const t=wp(s[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?Cp(t):Cp(new Hd(t,e))}const i=s.map(e=>wp(e));return Cp(new qd(i,e))}},Mp=e=>"object"==typeof e&&null!==e?e.value:e,Np=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function Ap(e,t){return new Proxy(new dp(e,t),rp)}const Cp=(e,t=null)=>function(e,t=null){const s=Rd(e);if("node"===s){let t=np.get(e);return void 0===t&&(t=new Proxy(e,rp),np.set(e,t),np.set(t,t)),t}return null===t&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?Cp(wp(e,t)):"shader"===s?Pp(e):e}(e,t),Rp=(e,t=null)=>new ap(e,t),Ep=(e,t=null)=>new hp(e,t),Bp=(...e)=>new up(...e),Ip=(...e)=>new lp(...e),Pp=(e,t)=>{const s=new Ap(e,t),i=(...e)=>{let t;return Rp(e),t=e[0]&&e[0].isNode?[...e]:e[0],s.call(t)};return i.shaderNode=s,i.setLayout=e=>(s.setLayout(e),i),i.once=()=>(s.once=!0,i),i},Fp=(...e)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),Pp(...e));tp("toGlobal",e=>(e.global=!0,e));const zp=e=>{Qd=e},Up=()=>Qd,Op=(...e)=>Qd.If(...e);function Lp(e){return Qd&&Qd.add(e),e}tp("append",Lp);const Vp=new Sp("color"),Dp=new Sp("float",Tp.float),kp=new Sp("int",Tp.ints),Gp=new Sp("uint",Tp.uint),Wp=new Sp("bool",Tp.bool),Hp=new Sp("vec2"),jp=new Sp("ivec2"),qp=new Sp("uvec2"),$p=new Sp("bvec2"),Xp=new Sp("vec3"),Yp=new Sp("ivec3"),Zp=new Sp("uvec3"),Jp=new Sp("bvec3"),Kp=new Sp("vec4"),Qp=new Sp("ivec4"),em=new Sp("uvec4"),tm=new Sp("bvec4"),sm=new Sp("mat2"),im=new Sp("mat3"),rm=new Sp("mat4"),nm=(e="")=>Cp(new Kd(e,"string")),om=e=>Cp(new Kd(e,"ArrayBuffer"));tp("toColor",Vp),tp("toFloat",Dp),tp("toInt",kp),tp("toUint",Gp),tp("toBool",Wp),tp("toVec2",Hp),tp("toIVec2",jp),tp("toUVec2",qp),tp("toBVec2",$p),tp("toVec3",Xp),tp("toIVec3",Yp),tp("toUVec3",Zp),tp("toBVec3",Jp),tp("toVec4",Kp),tp("toIVec4",Qp),tp("toUVec4",em),tp("toBVec4",tm),tp("toMat2",sm),tp("toMat3",im),tp("toMat4",rm);const am=Bp(Wd),hm=(e,t)=>Cp(new Hd(Cp(e),t)),um=(e,t)=>Cp(new Xd(Cp(e),t));tp("element",am),tp("convert",hm);class lm extends Gd{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.version=0,this.shared=t,this.order=s,this.isUniformGroup=!0}set needsUpdate(e){!0===e&&this.version++}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const cm=e=>new lm(e),dm=(e,t=0)=>new lm(e,!0,t),pm=dm("frame"),mm=dm("render"),gm=cm("object");class fm extends Jd{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=gm}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const s=this.getSelf();return e=e.bind(s),super.onUpdate(t=>{const i=e(t,s);void 0!==i&&(this.value=i)},t)}generate(e,t){const s=this.getNodeType(e),i=this.getUniformHash(e);let r=e.getNodeFromHash(i);void 0===r&&(e.setHashNode(this,i),r=this);const n=r.getInputType(e),o=e.getUniformFromNode(r,n,e.shaderStage,this.name||e.context.label),a=e.getPropertyName(o);return void 0!==e.context.label&&delete e.context.label,e.format(a,s,t)}}const ym=(e,t)=>{const s=Np(t||e),i=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return Cp(new fm(i,s))};class xm extends Gd{static get type(){return"PropertyNode"}constructor(e,t=null,s=!1){super(e),this.name=t,this.varying=s,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const bm=(e,t)=>Cp(new xm(e,t)),vm=(e,t)=>Cp(new xm(e,t,!0)),Tm=Ip(xm,"vec4","DiffuseColor"),_m=Ip(xm,"vec3","EmissiveColor"),wm=Ip(xm,"float","Roughness"),Sm=Ip(xm,"float","Metalness"),Mm=Ip(xm,"float","Clearcoat"),Nm=Ip(xm,"float","ClearcoatRoughness"),Am=Ip(xm,"vec3","Sheen"),Cm=Ip(xm,"float","SheenRoughness"),Rm=Ip(xm,"float","Iridescence"),Em=Ip(xm,"float","IridescenceIOR"),Bm=Ip(xm,"float","IridescenceThickness"),Im=Ip(xm,"float","AlphaT"),Pm=Ip(xm,"float","Anisotropy"),Fm=Ip(xm,"vec3","AnisotropyT"),zm=Ip(xm,"vec3","AnisotropyB"),Um=Ip(xm,"color","SpecularColor"),Om=Ip(xm,"float","SpecularF90"),Lm=Ip(xm,"float","Shininess"),Vm=Ip(xm,"vec4","Output"),Dm=Ip(xm,"float","dashSize"),km=Ip(xm,"float","gapSize"),Gm=Ip(xm,"float","pointWidth"),Wm=Ip(xm,"float","IOR"),Hm=Ip(xm,"float","Transmission"),jm=Ip(xm,"float","Thickness"),qm=Ip(xm,"float","AttenuationDistance"),$m=Ip(xm,"color","AttenuationColor"),Xm=Ip(xm,"float","Dispersion");class Ym extends jd{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const s=e.getTypeLength(t.node.getNodeType(e));return Dd.join("").slice(0,s)!==t.components}return!1}generate(e,t){const{targetNode:s,sourceNode:i}=this,r=this.needsSplitAssign(e),n=s.getNodeType(e),o=s.context({assign:!0}).build(e),a=i.build(e,n),h=i.getNodeType(e),u=e.getDataFromNode(this);let l;if(!0===u.initialized)"void"!==t&&(l=o);else if(r){const i=e.getVarFromNode(this,null,n),r=e.getPropertyName(i);e.addLineFlowCode(`${r} = ${a}`,this);const h=s.node.context({assign:!0}).build(e);for(let t=0;t<s.components.length;t++){const i=s.components[t];e.addLineFlowCode(`${h}.${i} = ${r}[ ${t} ]`,this)}"void"!==t&&(l=o)}else l=`${o} = ${a}`,"void"!==t&&"void"!==h||(e.addLineFlowCode(l,this),"void"!==t&&(l=o));return u.initialized=!0,e.format(l,n,t)}}const Zm=Bp(Ym);tp("assign",Zm);class Jm extends jd{static get type(){return"FunctionCallNode"}constructor(e=null,t={}){super(),this.functionNode=e,this.parameters=t}setParameters(e){return this.parameters=e,this}getParameters(){return this.parameters}getNodeType(e){return this.functionNode.getNodeType(e)}generate(e){const t=[],s=this.functionNode,i=s.getInputs(e),r=this.parameters;if(Array.isArray(r))for(let s=0;s<r.length;s++){const n=i[s],o=r[s];t.push(o.build(e,n.type))}else for(const s of i){const i=r[s.name];if(void 0===i)throw new Error(`FunctionCallNode: Input '${s.name}' not found in FunctionNode.`);t.push(i.build(e,s.type))}return`${s.build(e,"property")}( ${t.join(", ")} )`}}const Km=(e,...t)=>(t=t.length>1||t[0]&&!0===t[0].isNode?Ep(t):Rp(t[0]),Cp(new Jm(Cp(e),t)));tp("call",Km);class Qm extends jd{static get type(){return"OperatorNode"}constructor(e,t,s,...i){if(super(),i.length>0){let r=new Qm(e,t,s);for(let t=0;t<i.length-1;t++)r=new Qm(e,r,i[t]);t=r,s=i[i.length-1]}this.op=e,this.aNode=t,this.bNode=s}getNodeType(e,t){const s=this.op,i=this.aNode,r=this.bNode,n=i.getNodeType(e),o=void 0!==r?r.getNodeType(e):null;if("void"===n||"void"===o)return"void";if("%"===s)return n;if("~"===s||"&"===s||"|"===s||"^"===s||">>"===s||"<<"===s)return e.getIntegerType(n);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=t?e.getTypeLength(t):Math.max(e.getTypeLength(n),e.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===n&&e.isMatrix(o)?o:e.isMatrix(n)&&e.isVector(o)?e.getVectorFromMatrix(n):e.isVector(n)&&e.isMatrix(o)?e.getVectorFromMatrix(o):e.getTypeLength(o)>e.getTypeLength(n)?o:n}generate(e,t){const s=this.op,i=this.aNode,r=this.bNode,n=this.getNodeType(e,t);let o=null,a=null;"void"!==n?(o=i.getNodeType(e),a=void 0!==r?r.getNodeType(e):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?e.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===s||"<<"===s?(o=n,a=e.changeComponentType(a,"uint")):e.isMatrix(o)&&e.isVector(a)?a=e.getVectorFromMatrix(o):o=e.isVector(o)&&e.isMatrix(a)?e.getVectorFromMatrix(a):a=n):o=a=n;const h=i.build(e,o),u=void 0!==r?r.build(e,a):null,l=e.getTypeLength(t),c=e.getFunctionOperator(s);return"void"!==t?"<"===s&&l>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${h}, ${u} )`,n,t):e.format(`( ${h} < ${u} )`,n,t):"<="===s&&l>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${h}, ${u} )`,n,t):e.format(`( ${h} <= ${u} )`,n,t):">"===s&&l>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${h}, ${u} )`,n,t):e.format(`( ${h} > ${u} )`,n,t):">="===s&&l>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${h}, ${u} )`,n,t):e.format(`( ${h} >= ${u} )`,n,t):"!"===s||"~"===s?e.format(`(${s}${h})`,o,t):c?e.format(`${c}( ${h}, ${u} )`,n,t):e.format(`( ${h} ${s} ${u} )`,n,t):"void"!==o?c?e.format(`${c}( ${h}, ${u} )`,n,t):e.format(`${h} ${s} ${u}`,n,t):void 0}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const eg=Bp(Qm,"+"),tg=Bp(Qm,"-"),sg=Bp(Qm,"*"),ig=Bp(Qm,"/"),rg=Bp(Qm,"%"),ng=Bp(Qm,"=="),og=Bp(Qm,"!="),ag=Bp(Qm,"<"),hg=Bp(Qm,">"),ug=Bp(Qm,"<="),lg=Bp(Qm,">="),cg=Bp(Qm,"&&"),dg=Bp(Qm,"||"),pg=Bp(Qm,"!"),mg=Bp(Qm,"^^"),gg=Bp(Qm,"&"),fg=Bp(Qm,"~"),yg=Bp(Qm,"|"),xg=Bp(Qm,"^"),bg=Bp(Qm,"<<"),vg=Bp(Qm,">>");tp("add",eg),tp("sub",tg),tp("mul",sg),tp("div",ig),tp("modInt",rg),tp("equal",ng),tp("notEqual",og),tp("lessThan",ag),tp("greaterThan",hg),tp("lessThanEqual",ug),tp("greaterThanEqual",lg),tp("and",cg),tp("or",dg),tp("not",pg),tp("xor",mg),tp("bitAnd",gg),tp("bitNot",fg),tp("bitOr",yg),tp("bitXor",xg),tp("shiftLeft",bg),tp("shiftRight",vg);const Tg=(...e)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),rg(...e));tp("remainder",Tg);class _g extends jd{static get type(){return"MathNode"}constructor(e,t,s=null,i=null){super(),this.method=e,this.aNode=t,this.bNode=s,this.cNode=i}getInputType(e){const t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,i=this.cNode?this.cNode.getNodeType(e):null,r=e.isMatrix(t)?0:e.getTypeLength(t),n=e.isMatrix(s)?0:e.getTypeLength(s),o=e.isMatrix(i)?0:e.getTypeLength(i);return r>n&&r>o?t:n>o?s:o>r?i:t}getNodeType(e){const t=this.method;return t===_g.LENGTH||t===_g.DISTANCE||t===_g.DOT?"float":t===_g.CROSS?"vec3":t===_g.ALL?"bool":t===_g.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===_g.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){const s=this.method,i=this.getNodeType(e),r=this.getInputType(e),n=this.aNode,o=this.bNode,a=this.cNode,h=!0===e.renderer.isWebGLRenderer;if(s===_g.TRANSFORM_DIRECTION){let s=n,i=o;e.isMatrix(s.getNodeType(e))?i=Kp(Xp(i),0):s=Kp(Xp(s),0);const r=sg(s,i).xyz;return Dg(r).build(e,t)}if(s===_g.NEGATE)return e.format("( - "+n.build(e,r)+" )",i,t);if(s===_g.ONE_MINUS)return tg(1,n).build(e,t);if(s===_g.RECIPROCAL)return ig(1,n).build(e,t);if(s===_g.DIFFERENCE)return Xg(tg(n,o)).build(e,t);{const u=[];return s===_g.CROSS||s===_g.MOD?u.push(n.build(e,i),o.build(e,i)):h&&s===_g.STEP?u.push(n.build(e,1===e.getTypeLength(n.getNodeType(e))?"float":r),o.build(e,r)):h&&(s===_g.MIN||s===_g.MAX)||s===_g.MOD?u.push(n.build(e,r),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":r)):s===_g.REFRACT?u.push(n.build(e,r),o.build(e,r),a.build(e,"float")):s===_g.MIX?u.push(n.build(e,r),o.build(e,r),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":r)):(u.push(n.build(e,r)),null!==o&&u.push(o.build(e,r)),null!==a&&u.push(a.build(e,r))),e.format(`${e.getMethod(s,i)}( ${u.join(", ")} )`,i,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}_g.ALL="all",_g.ANY="any",_g.EQUALS="equals",_g.RADIANS="radians",_g.DEGREES="degrees",_g.EXP="exp",_g.EXP2="exp2",_g.LOG="log",_g.LOG2="log2",_g.SQRT="sqrt",_g.INVERSE_SQRT="inversesqrt",_g.FLOOR="floor",_g.CEIL="ceil",_g.NORMALIZE="normalize",_g.FRACT="fract",_g.SIN="sin",_g.COS="cos",_g.TAN="tan",_g.ASIN="asin",_g.ACOS="acos",_g.ATAN="atan",_g.ABS="abs",_g.SIGN="sign",_g.LENGTH="length",_g.NEGATE="negate",_g.ONE_MINUS="oneMinus",_g.DFDX="dFdx",_g.DFDY="dFdy",_g.ROUND="round",_g.RECIPROCAL="reciprocal",_g.TRUNC="trunc",_g.FWIDTH="fwidth",_g.BITCAST="bitcast",_g.TRANSPOSE="transpose",_g.ATAN2="atan2",_g.MIN="min",_g.MAX="max",_g.MOD="mod",_g.STEP="step",_g.REFLECT="reflect",_g.DISTANCE="distance",_g.DIFFERENCE="difference",_g.DOT="dot",_g.CROSS="cross",_g.POW="pow",_g.TRANSFORM_DIRECTION="transformDirection",_g.MIX="mix",_g.CLAMP="clamp",_g.REFRACT="refract",_g.SMOOTHSTEP="smoothstep",_g.FACEFORWARD="faceforward";const wg=Dp(1e-6),Sg=Dp(1e6),Mg=Dp(Math.PI),Ng=Dp(2*Math.PI),Ag=Bp(_g,_g.ALL),Cg=Bp(_g,_g.ANY),Rg=Bp(_g,_g.EQUALS),Eg=Bp(_g,_g.RADIANS),Bg=Bp(_g,_g.DEGREES),Ig=Bp(_g,_g.EXP),Pg=Bp(_g,_g.EXP2),Fg=Bp(_g,_g.LOG),zg=Bp(_g,_g.LOG2),Ug=Bp(_g,_g.SQRT),Og=Bp(_g,_g.INVERSE_SQRT),Lg=Bp(_g,_g.FLOOR),Vg=Bp(_g,_g.CEIL),Dg=Bp(_g,_g.NORMALIZE),kg=Bp(_g,_g.FRACT),Gg=Bp(_g,_g.SIN),Wg=Bp(_g,_g.COS),Hg=Bp(_g,_g.TAN),jg=Bp(_g,_g.ASIN),qg=Bp(_g,_g.ACOS),$g=Bp(_g,_g.ATAN),Xg=Bp(_g,_g.ABS),Yg=Bp(_g,_g.SIGN),Zg=Bp(_g,_g.LENGTH),Jg=Bp(_g,_g.NEGATE),Kg=Bp(_g,_g.ONE_MINUS),Qg=Bp(_g,_g.DFDX),ef=Bp(_g,_g.DFDY),tf=Bp(_g,_g.ROUND),sf=Bp(_g,_g.RECIPROCAL),rf=Bp(_g,_g.TRUNC),nf=Bp(_g,_g.FWIDTH),of=Bp(_g,_g.BITCAST),af=Bp(_g,_g.TRANSPOSE),hf=Bp(_g,_g.ATAN2),uf=Bp(_g,_g.MIN),lf=Bp(_g,_g.MAX),cf=Bp(_g,_g.MOD),df=Bp(_g,_g.STEP),pf=Bp(_g,_g.REFLECT),mf=Bp(_g,_g.DISTANCE),gf=Bp(_g,_g.DIFFERENCE),ff=Bp(_g,_g.DOT),yf=Bp(_g,_g.CROSS),xf=Bp(_g,_g.POW),bf=Bp(_g,_g.POW,2),vf=Bp(_g,_g.POW,3),Tf=Bp(_g,_g.POW,4),_f=Bp(_g,_g.TRANSFORM_DIRECTION),wf=e=>sg(Yg(e),xf(Xg(e),1/3)),Sf=e=>ff(e,e),Mf=Bp(_g,_g.MIX),Nf=(e,t=0,s=1)=>Cp(new _g(_g.CLAMP,Cp(e),Cp(t),Cp(s))),Af=e=>Nf(e),Cf=Bp(_g,_g.REFRACT),Rf=Bp(_g,_g.SMOOTHSTEP),Ef=Bp(_g,_g.FACEFORWARD),Bf=Pp(([e])=>{const t=ff(e.xy,Hp(12.9898,78.233)),s=cf(t,Mg);return kg(Gg(s).mul(43758.5453))}),If=(e,t,s)=>Mf(t,s,e),Pf=(e,t,s)=>Rf(t,s,e);tp("all",Ag),tp("any",Cg),tp("equals",Rg),tp("radians",Eg),tp("degrees",Bg),tp("exp",Ig),tp("exp2",Pg),tp("log",Fg),tp("log2",zg),tp("sqrt",Ug),tp("inverseSqrt",Og),tp("floor",Lg),tp("ceil",Vg),tp("normalize",Dg),tp("fract",kg),tp("sin",Gg),tp("cos",Wg),tp("tan",Hg),tp("asin",jg),tp("acos",qg),tp("atan",$g),tp("abs",Xg),tp("sign",Yg),tp("length",Zg),tp("lengthSq",Sf),tp("negate",Jg),tp("oneMinus",Kg),tp("dFdx",Qg),tp("dFdy",ef),tp("round",tf),tp("reciprocal",sf),tp("trunc",rf),tp("fwidth",nf),tp("atan2",hf),tp("min",uf),tp("max",lf),tp("mod",cf),tp("step",df),tp("reflect",pf),tp("distance",mf),tp("dot",ff),tp("cross",yf),tp("pow",xf),tp("pow2",bf),tp("pow3",vf),tp("pow4",Tf),tp("transformDirection",_f),tp("mix",If),tp("clamp",Nf),tp("refract",Cf),tp("smoothstep",Pf),tp("faceForward",Ef),tp("difference",gf),tp("saturate",Af),tp("cbrt",wf),tp("transpose",af),tp("rand",Bf);class Ff extends Gd{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){const t=this.ifNode.getNodeType(e);if(null!==this.elseNode){const s=this.elseNode.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(t))return s}return t}setup(e){const t=this.condNode.cache(),s=this.ifNode.cache(),i=this.elseNode?this.elseNode.cache():null,r=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=r,null!==i&&(e.getDataFromNode(i).parentNodeBlock=r);const n=e.getNodeProperties(this);n.condNode=t,n.ifNode=s.context({nodeBlock:s}),n.elseNode=i?i.context({nodeBlock:i}):null}generate(e,t){const s=this.getNodeType(e),i=e.getDataFromNode(this);if(void 0!==i.nodeProperty)return i.nodeProperty;const{condNode:r,ifNode:n,elseNode:o}=e.getNodeProperties(this),a="void"!==t,h=a?bm(s).build(e):"";i.nodeProperty=h;const u=r.build(e,"bool");e.addFlowCode(`\n${e.tab}if ( ${u} ) {\n\n`).addFlowTab();let l=n.build(e,s);if(l&&(l=a?h+" = "+l+";":"return "+l+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+l+"\n\n"+e.tab+"}"),null!==o){e.addFlowCode(" else {\n\n").addFlowTab();let t=o.build(e,s);t&&(t=a?h+" = "+t+";":"return "+t+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(h,s,t)}}const zf=Bp(Ff);tp("select",zf);const Uf=(...e)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),zf(...e));tp("cond",Uf);class Of extends Gd{static get type(){return"ContextNode"}constructor(e,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}analyze(e){this.node.build(e)}setup(e){const t=e.getContext();e.setContext({...e.context,...this.value});const s=this.node.build(e);return e.setContext(t),s}generate(e,t){const s=e.getContext();e.setContext({...e.context,...this.value});const i=this.node.build(e,t);return e.setContext(s),i}}const Lf=Bp(Of),Vf=(e,t)=>Lf(e,{label:t});tp("context",Lf),tp("label",Vf);class Df extends Gd{static get type(){return"VarNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){const{node:t,name:s}=this,i=e.getVarFromNode(this,s,e.getVectorType(this.getNodeType(e))),r=e.getPropertyName(i),n=t.build(e,i.type);return e.addLineFlowCode(`${r} = ${n}`,this),r}}const kf=Bp(Df);tp("temp",kf),tp("toVar",(...e)=>kf(...e).append());class Gf extends Gd{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0}isGlobal(){return!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let s=t.varying;if(void 0===s){const i=this.name,r=this.getNodeType(e);t.varying=s=e.getVaryingFromNode(this,i,r),t.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===e.shaderStage),s}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){const t=e.getNodeProperties(this),s=this.setupVarying(e);if(void 0===t.propertyName){const i=this.getNodeType(e),r=e.getPropertyName(s,Fd.VERTEX);e.flowNodeFromShaderStage(Fd.VERTEX,this.node,i,r),t.propertyName=r}return e.getPropertyName(s)}}const Wf=Bp(Gf);tp("varying",Wf);const Hf="WorkingColorSpace",jf="OutputColorSpace";function qf(e){let t=null;return e===Kt?t="Linear":e===Jt&&(t="sRGB"),t}function $f(e,t){return qf(e)+"To"+qf(t)}class Xf extends jd{static get type(){return"ColorSpaceNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.source=t,this.target=s}getColorSpace(e,t){return t===Hf?di.workingColorSpace:t===jf?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{renderer:t}=e,{colorNode:s}=this,i=this.getColorSpace(e,this.source),r=this.getColorSpace(e,this.target);if(i===r)return s;const n=$f(i,r);let o=null;const a=t.nodes.library.getColorSpaceFunction(n);return null!==a?o=Kp(a(s.rgb),s.a):(console.error("ColorSpaceNode: Unsupported Color Space configuration.",n),o=s),o}}const Yf=e=>Cp(new Xf(Cp(e),Hf,jf)),Zf=e=>Cp(new Xf(Cp(e),jf,Hf)),Jf=(e,t)=>Cp(new Xf(Cp(e),Hf,t)),Kf=(e,t)=>Cp(new Xf(Cp(e),t,Hf));tp("toOutputColorSpace",Yf),tp("toWorkingColorSpace",Zf),tp("workingToColorSpace",Jf),tp("colorSpaceToWorking",Kf);let Qf=class extends Wd{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),i=this.getNodeType();return e.format(t,s,i)}};class ey extends Gd{static get type(){return"ReferenceBaseNode"}constructor(e,t,s=null,i=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=i,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=zd.OBJECT}setGroup(e){return this.group=e,this}element(e){return Cp(new Qf(this,Cp(e)))}setNodeType(e){const t=ym(null,e).getSelf();null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;e<t.length;e++)s=s[t[e]];return s}updateReference(e){return this.reference=null!==this.object?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);const e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}class ty extends ey{static get type(){return"RendererReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.renderer=s,this.setGroup(mm)}updateReference(e){return this.reference=null!==this.renderer?this.renderer:e.renderer,this.reference}}const sy=(e,t,s)=>Cp(new ty(e,t,s));class iy extends jd{static get type(){return"ToneMappingNode"}constructor(e,t=ny,s=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=s}getCacheKey(){return Nd(super.getCacheKey(),this.toneMapping)}setup(e){const t=this.colorNode||e.context.color,s=this.toneMapping;if(0===s)return t;let i=null;const r=e.renderer.nodes.library.getToneMappingFunction(s);return null!==r?i=Kp(r(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),i=t),i}}const ry=(e,t,s)=>Cp(new iy(e,Cp(t),Cp(s))),ny=sy("toneMappingExposure","float");tp("toneMapping",(e,t,s)=>ry(t,s,e));class oy extends Jd{static get type(){return"BufferAttributeNode"}constructor(e,t=null,s=0,i=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=s,this.bufferOffset=i,this.usage=Rs,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;const t=this.getNodeType(e),s=this.value,i=e.getTypeLength(t),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(e){const t=this.getNodeType(e),s=e.getBufferAttributeFromNode(this,t),i=e.getPropertyName(s);let r=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=i,r=i;else{r=Wf(this).build(e,t)}return r}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}const ay=(e,t,s,i)=>Cp(new oy(e,t,s,i)),hy=(e,t,s,i)=>ay(e,t,s,i).setUsage(Es),uy=(e,t,s,i)=>ay(e,t,s,i).setInstanced(!0),ly=(e,t,s,i)=>hy(e,t,s,i).setInstanced(!0);tp("toAttribute",e=>ay(e.value));class cy extends Gd{static get type(){return"ComputeNode"}constructor(e,t,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=e,this.count=t,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=zd.OBJECT,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}updateDispatchCount(){const{count:e,workgroupSize:t}=this;let s=t[0];for(let e=1;e<t.length;e++)s*=t[e];this.dispatchCount=Math.ceil(e/s)}onInit(){}updateBefore({renderer:e}){e.compute(this)}generate(e){const{shaderStage:t}=e;if("compute"===t){const t=this.computeNode.build(e,"void");""!==t&&e.addLineFlowCode(t,this)}}}const dy=(e,t,s)=>Cp(new cy(Cp(e),t,s));tp("compute",dy);class py extends Gd{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){return this.node.getNodeType(e)}build(e,...t){const s=e.getCache(),i=e.getCacheFromNode(this,this.parent);e.setCache(i);const r=this.node.build(e,...t);return e.setCache(s),r}}const my=(e,...t)=>Cp(new py(Cp(e),...t));tp("cache",my);class gy extends Gd{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const fy=Bp(gy);tp("bypass",fy);class yy extends Gd{static get type(){return"RemapNode"}constructor(e,t,s,i=Dp(0),r=Dp(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=s,this.outLowNode=i,this.outHighNode=r,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:s,outLowNode:i,outHighNode:r,doClamp:n}=this;let o=e.sub(t).div(s.sub(t));return!0===n&&(o=o.clamp()),o.mul(r.sub(i)).add(i)}}const xy=Bp(yy,null,null,{doClamp:!1}),by=Bp(yy);tp("remap",xy),tp("remapClamp",by);class vy extends Gd{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const s=this.getNodeType(e),i=this.snippet;if("void"!==s)return e.format(`( ${i} )`,s,t);e.addLineFlowCode(i,this)}}const Ty=Bp(vy),_y=e=>(e?zf(e,Ty("discard")):Ty("discard")).append(),wy=()=>Ty("return").append();tp("discard",_y);class Sy extends jd{static get type(){return"RenderOutputNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:e}){let t=this.colorNode||e.color;const s=(null!==this.toneMapping?this.toneMapping:e.toneMapping)||0,i=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||Zt;return 0!==s&&(t=t.toneMapping(s)),i!==Zt&&i!==di.workingColorSpace&&(t=t.workingToColorSpace(i)),t}}const My=(e,t=null,s=null)=>Cp(new Sy(Cp(e),t,s));function Ny(e){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)}tp("renderOutput",My);class Ay extends Gd{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){const s=this.getAttributeName(e);if(e.hasGeometryAttribute(s)){const i=e.geometry.getAttribute(s);t=e.getTypeFromAttribute(i)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),s=this.getNodeType(e);if(!0===e.hasGeometryAttribute(t)){const i=e.geometry.getAttribute(t),r=e.getTypeFromAttribute(i),n=e.getAttribute(t,r);if("vertex"===e.shaderStage)return e.format(n.name,r,s);return Wf(this).build(e,s)}return console.warn(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(s)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const Cy=(e,t)=>Cp(new Ay(e,t)),Ry=e=>Cy("uv"+(e>0?e:""),"vec2");class Ey extends Gd{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const s=this.textureNode.build(e,"property"),i=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${s}, ${i} )`,this.getNodeType(e),t)}}const By=Bp(Ey);class Iy extends fm{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=zd.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,s=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(s&&void 0!==s.width){const{width:e,height:t}=s;this.value=Math.log2(Math.max(e,t))}}}const Py=Bp(Iy);class Fy extends fm{static get type(){return"TextureNode"}constructor(e,t=null,s=null,i=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=s,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=zd.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}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===Be?"uvec4":this.value.type===Ee?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return Ry(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=ym(this.value.matrix)),this._matrixUniform.mul(Xp(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?zd.FRAME:zd.NONE,this}setupUV(e,t){const s=this.value;return!e.isFlipY()||!0!==s.isRenderTargetTexture&&!0!==s.isFramebufferTexture&&!0!==s.isDepthTexture||(t=this.sampler?t.flipY():t.setY(kp(By(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==e.context.forceUVContext||!e.context.getUV||(s=e.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(e,s);let i=this.levelNode;null===i&&e.context.getTextureLevel&&(i=e.context.getTextureLevel(this)),t.uvNode=s,t.levelNode=i,t.biasNode=this.biasNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.depthNode=this.depthNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateSnippet(e,t,s,i,r,n,o,a){const h=this.value;let u;return u=i?e.generateTextureLevel(h,t,s,i,n):r?e.generateTextureBias(h,t,s,r,n):a?e.generateTextureGrad(h,t,s,a,n):o?e.generateTextureCompare(h,t,s,o,n):!1===this.sampler?e.generateTextureLoad(h,t,s,n):e.generateTexture(h,t,s,n),u}generate(e,t){const s=e.getNodeProperties(this),i=this.value;if(!i||!0!==i.isTexture)throw new Error("TextureNode: Need a three.js texture.");const r=super.generate(e,"property");if("sampler"===t)return r+"_sampler";if(e.isReference(t))return r;{const n=e.getDataFromNode(this);let o=n.propertyName;if(void 0===o){const{uvNode:t,levelNode:i,biasNode:a,compareNode:h,depthNode:u,gradNode:l}=s,c=this.generateUV(e,t),d=i?i.build(e,"float"):null,p=a?a.build(e,"float"):null,m=u?u.build(e,"int"):null,g=h?h.build(e,"float"):null,f=l?[l[0].build(e,"vec2"),l[1].build(e,"vec2")]:null,y=e.getVarFromNode(this);o=e.getPropertyName(y);const x=this.generateSnippet(e,r,c,d,p,m,g,f);e.addLineFlowCode(`${o} = ${x}`,this),n.snippet=x,n.propertyName=o}let a=o;const h=this.getNodeType(e);return e.needsToWorkingColorSpace(i)&&(a=Kf(Ty(a,h),i.colorSpace).setup(e).build(e,h)),e.format(a,h,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}uv(e){const t=this.clone();return t.uvNode=Cp(e),t.referenceNode=this.getSelf(),Cp(t)}blur(e){const t=this.clone();return t.biasNode=Cp(e).mul(Py(t)),t.referenceNode=this.getSelf(),Cp(t)}level(e){const t=this.clone();return t.levelNode=Cp(e),t.referenceNode=this.getSelf(),Cp(t)}size(e){return By(this,e)}bias(e){const t=this.clone();return t.biasNode=Cp(e),t.referenceNode=this.getSelf(),Cp(t)}compare(e){const t=this.clone();return t.compareNode=Cp(e),t.referenceNode=this.getSelf(),Cp(t)}grad(e,t){const s=this.clone();return s.gradNode=[Cp(e),Cp(t)],s.referenceNode=this.getSelf(),Cp(s)}depth(e){const t=this.clone();return t.depthNode=Cp(e),t.referenceNode=this.getSelf(),Cp(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix()}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e}}const zy=Bp(Fy),Uy=(...e)=>zy(...e).setSampler(!1),Oy=e=>(!0===e.isNode?e:zy(e)).convert("sampler"),Ly=ym("float").label("cameraNear").setGroup(mm).onRenderUpdate(({camera:e})=>e.near),Vy=ym("float").label("cameraFar").setGroup(mm).onRenderUpdate(({camera:e})=>e.far),Dy=ym("float").label("cameraLogDepth").setGroup(mm).onRenderUpdate(({camera:e})=>2/(Math.log(e.far+1)/Math.LN2)),ky=ym("mat4").label("cameraProjectionMatrix").setGroup(mm).onRenderUpdate(({camera:e})=>e.projectionMatrix),Gy=ym("mat4").label("cameraProjectionMatrixInverse").setGroup(mm).onRenderUpdate(({camera:e})=>e.projectionMatrixInverse),Wy=ym("mat4").label("cameraViewMatrix").setGroup(mm).onRenderUpdate(({camera:e})=>e.matrixWorldInverse),Hy=ym("mat4").label("cameraWorldMatrix").setGroup(mm).onRenderUpdate(({camera:e})=>e.matrixWorld),jy=ym("mat3").label("cameraNormalMatrix").setGroup(mm).onRenderUpdate(({camera:e})=>e.normalMatrix),qy=ym(new Ei).label("cameraPosition").setGroup(mm).onRenderUpdate(({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld));class $y extends Gd{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=zd.OBJECT,this._uniformNode=new fm(null)}getNodeType(){const e=this.scope;return e===$y.WORLD_MATRIX?"mat4":e===$y.POSITION||e===$y.VIEW_POSITION||e===$y.DIRECTION||e===$y.SCALE?"vec3":void 0}update(e){const t=this.object3d,s=this._uniformNode,i=this.scope;if(i===$y.WORLD_MATRIX)s.value=t.matrixWorld;else if(i===$y.POSITION)s.value=s.value||new Ei,s.value.setFromMatrixPosition(t.matrixWorld);else if(i===$y.SCALE)s.value=s.value||new Ei,s.value.setFromMatrixScale(t.matrixWorld);else if(i===$y.DIRECTION)s.value=s.value||new Ei,t.getWorldDirection(s.value);else if(i===$y.VIEW_POSITION){const i=e.camera;s.value=s.value||new Ei,s.value.setFromMatrixPosition(t.matrixWorld),s.value.applyMatrix4(i.matrixWorldInverse)}}generate(e){const t=this.scope;return t===$y.WORLD_MATRIX?this._uniformNode.nodeType="mat4":t!==$y.POSITION&&t!==$y.VIEW_POSITION&&t!==$y.DIRECTION&&t!==$y.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}$y.WORLD_MATRIX="worldMatrix",$y.POSITION="position",$y.SCALE="scale",$y.VIEW_POSITION="viewPosition",$y.DIRECTION="direction";const Xy=Bp($y,$y.DIRECTION),Yy=Bp($y,$y.WORLD_MATRIX),Zy=Bp($y,$y.POSITION),Jy=Bp($y,$y.SCALE),Ky=Bp($y,$y.VIEW_POSITION);class Qy extends $y{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const ex=Ip(Qy,Qy.DIRECTION),tx=Ip(Qy,Qy.WORLD_MATRIX),sx=Ip(Qy,Qy.POSITION),ix=Ip(Qy,Qy.SCALE),rx=Ip(Qy,Qy.VIEW_POSITION),nx=ym(new ti).onObjectUpdate(({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld)),ox=ym(new or).onObjectUpdate(({object:e},t)=>t.value.copy(e.matrixWorld).invert()),ax=Wy.mul(tx).toVar("modelViewMatrix_2"),hx=Pp(e=>(e.context.isHighPrecisionModelViewMatrix=!0,ym("mat4").onObjectUpdate(({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))).once()().toVar("highPrecisionModelViewMatrix"),ux=Pp(e=>{const t=e.context.isHighPrecisionModelViewMatrix;return ym("mat3").onObjectUpdate(({object:e,camera:s})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix)))}).once()().toVar("highPrecisionModelNormalMatrix"),lx=Cy("position","vec3"),cx=lx.varying("positionLocal"),dx=lx.varying("positionPrevious"),px=tx.mul(cx).xyz.varying("v_positionWorld"),mx=cx.transformDirection(tx).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),gx=ax.mul(cx).xyz.varying("v_positionView"),fx=gx.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class yx extends Gd{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){const{renderer:t,material:s}=e;return t.coordinateSystem===Ds&&1===s.side?"false":e.getFrontFacing()}}const xx=Ip(yx),bx=Dp(xx).mul(2).sub(1),vx=Cy("normal","vec3"),Tx=Pp(e=>!1===e.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),Xp(0,1,0)):vx,"vec3").once()().toVar("normalLocal"),_x=gx.dFdx().cross(gx.dFdy()).normalize().toVar("normalFlat"),wx=Pp(e=>{let t;return t=!0===e.material.flatShading?_x:Wf(Rx(Tx),"v_normalView").normalize(),t},"vec3").once()().toVar("normalView"),Sx=Wf(wx.transformDirection(Wy),"v_normalWorld").normalize().toVar("normalWorld"),Mx=Pp(e=>e.context.setupNormal(),"vec3").once()().mul(bx).toVar("transformedNormalView"),Nx=Mx.transformDirection(Wy).toVar("transformedNormalWorld"),Ax=Pp(e=>e.context.setupClearcoatNormal(),"vec3").once()().mul(bx).toVar("transformedClearcoatNormalView"),Cx=Pp(([e,t=tx])=>{const s=im(t),i=e.div(Xp(s[0].dot(s[0]),s[1].dot(s[1]),s[2].dot(s[2])));return s.mul(i).xyz}),Rx=Pp(([e],t)=>{const s=t.renderer.nodes.modelNormalViewMatrix;if(null!==s)return s.transformDirection(e);const i=nx.mul(e);return Wy.transformDirection(i)}),Ex=ym(0).onReference(({material:e})=>e).onRenderUpdate(({material:e})=>e.refractionRatio),Bx=fx.negate().reflect(Mx),Ix=fx.negate().refract(Mx,Ex),Px=Bx.transformDirection(Wy).toVar("reflectVector"),Fx=Ix.transformDirection(Wy).toVar("reflectVector");class zx extends Fy{static get type(){return"CubeTextureNode"}constructor(e,t=null,s=null,i=null){super(e,t,s,i),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===he?Px:e.mapping===ue?Fx:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),Xp(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.renderer.coordinateSystem!==ks&&s.isRenderTargetTexture?t:Xp(t.x.negate(),t.yz)}generateUV(e,t){return t.build(e,"vec3")}}const Ux=Bp(zx);class Ox extends fm{static get type(){return"BufferNode"}constructor(e,t,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=s}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const Lx=(e,t,s)=>Cp(new Ox(e,t,s));class Vx extends Wd{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),s=this.getNodeType();return e.format(t,"vec4",s)}}class Dx extends Ox{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null,"vec4"),this.array=e,this.elementType=t,this._elementType=null,this._elementLength=0,this.updateType=zd.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:e,value:t}=this,s=this.getElementLength(),i=this.getElementType();if(1===s)for(let s=0;s<e.length;s++){t[4*s]=e[s]}else if("color"===i)for(let s=0;s<e.length;s++){const i=4*s,r=e[s];t[i]=r.r,t[i+1]=r.g,t[i+2]=r.b||0}else for(let s=0;s<e.length;s++){const i=4*s,r=e[s];t[i]=r.x,t[i+1]=r.y,t[i+2]=r.z||0,t[i+3]=r.w||0}}setup(e){const t=this.array.length;this._elementType=null===this.elementType?Rd(this.array[0]):this.elementType,this._elementLength=e.getTypeLength(this._elementType);let s=Float32Array;return"i"===this._elementType.charAt(0)?s=Int32Array:"u"===this._elementType.charAt(0)&&(s=Uint32Array),this.value=new s(4*t),this.bufferCount=t,this.bufferType=e.changeComponentType("vec4",e.getComponentType(this._elementType)),super.setup(e)}element(e){return Cp(new Vx(this,Cp(e)))}}const kx=(e,t)=>Cp(new Dx(e,t)),Gx=(e,t)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),Cp(new Dx(e,t)));class Wx extends Wd{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),i=this.getNodeType();return e.format(t,s,i)}}class Hx extends Gd{static get type(){return"ReferenceNode"}constructor(e,t,s=null,i=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=i,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=zd.OBJECT}element(e){return Cp(new Wx(this,Cp(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;t=null!==this.count?Lx(null,e,this.count):Array.isArray(this.getValueFromReference())?kx(null,e):"texture"===e?zy(null):"cubeTexture"===e?Ux(null):ym(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;e<t.length;e++)s=s[t[e]];return s}updateReference(e){return this.reference=null!==this.object?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);const e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}const jx=(e,t,s)=>Cp(new Hx(e,t,s)),qx=(e,t,s,i)=>Cp(new Hx(e,t,i,s));class $x extends Hx{static get type(){return"MaterialReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}const Xx=(e,t,s)=>Cp(new $x(e,t,s)),Yx=Pp(e=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),Cy("tangent","vec4")))(),Zx=Yx.xyz.toVar("tangentLocal"),Jx=ax.mul(Kp(Zx,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Kx=Jx.transformDirection(Wy).varying("v_tangentWorld").normalize().toVar("tangentWorld"),Qx=Jx.toVar("transformedTangentView"),eb=Qx.transformDirection(Wy).normalize().toVar("transformedTangentWorld"),tb=e=>e.mul(Yx.w).xyz,sb=Wf(tb(vx.cross(Yx)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),ib=Wf(tb(Tx.cross(Zx)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),rb=Wf(tb(wx.cross(Jx)),"v_bitangentView").normalize().toVar("bitangentView"),nb=Wf(tb(Sx.cross(Kx)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),ob=tb(Mx.cross(Qx)).normalize().toVar("transformedBitangentView"),ab=ob.transformDirection(Wy).normalize().toVar("transformedBitangentWorld"),hb=im(Jx,rb,wx),ub=fx.mul(hb),lb=(e,t)=>e.sub(ub.mul(t)),cb=(()=>{let e=zm.cross(fx);return e=e.cross(zm).normalize(),e=Mf(e,Mx,Pm.mul(wm.oneMinus()).oneMinus().pow2().pow2()).normalize(),e})(),db=Pp(e=>{const{eye_pos:t,surf_norm:s,mapN:i,uv:r}=e,n=t.dFdx(),o=t.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=bx.mul(m.inverseSqrt());return eg(d.mul(i.x,g),p.mul(i.y,g),u.mul(i.z)).normalize()});class pb extends jd{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=0}setup(e){const{normalMapType:t,scaleNode:s}=this;let i=this.node.mul(2).sub(1);null!==s&&(i=Xp(i.xy.mul(s),i.z));let r=null;if(1===t)r=Rx(i);else if(0===t){r=!0===e.hasGeometryAttribute("tangent")?hb.mul(i).normalize():db({eye_pos:gx,surf_norm:wx,mapN:i,uv:Ry()})}return r}}const mb=Bp(pb),gb=Pp(({textureNode:e,bumpScale:t})=>{const s=t=>e.cache().context({getUV:e=>t(e.uvNode||Ry()),forceUVContext:!0}),i=Dp(s(e=>e));return Hp(Dp(s(e=>e.add(e.dFdx()))).sub(i),Dp(s(e=>e.add(e.dFdy()))).sub(i)).mul(t)}),fb=Pp(e=>{const{surf_pos:t,surf_norm:s,dHdxy:i}=e,r=t.dFdx().normalize(),n=s,o=t.dFdy().normalize().cross(n),a=n.cross(r),h=r.dot(o).mul(bx),u=h.sign().mul(i.x.mul(o).add(i.y.mul(a)));return h.abs().mul(s).sub(u).normalize()});class yb extends jd{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=null!==this.scaleNode?this.scaleNode:1,t=gb({textureNode:this.textureNode,bumpScale:e});return fb({surf_pos:gx,surf_norm:wx,dHdxy:t})}}const xb=Bp(yb),bb=new Map;class vb extends Gd{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let s=bb.get(e);return void 0===s&&(s=Xx(e,t),bb.set(e,s)),s}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){const t=e.context.material,s=this.scope;let i=null;if(s===vb.COLOR){const e=void 0!==t.color?this.getColor(s):Xp();i=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(s===vb.OPACITY){const e=this.getFloat(s);i=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(s===vb.SPECULAR_STRENGTH)i=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:Dp(1);else if(s===vb.SPECULAR_INTENSITY){const e=this.getFloat(s);i=t.specularMap?e.mul(this.getTexture(s).a):e}else if(s===vb.SPECULAR_COLOR){const e=this.getColor(s);i=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(s).rgb):e}else if(s===vb.ROUGHNESS){const e=this.getFloat(s);i=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(s).g):e}else if(s===vb.METALNESS){const e=this.getFloat(s);i=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(s).b):e}else if(s===vb.EMISSIVE){const e=this.getFloat("emissiveIntensity"),r=this.getColor(s).mul(e);i=t.emissiveMap&&!0===t.emissiveMap.isTexture?r.mul(this.getTexture(s)):r}else if(s===vb.NORMAL)t.normalMap?(i=mb(this.getTexture("normal"),this.getCache("normalScale","vec2")),i.normalMapType=t.normalMapType):i=t.bumpMap?xb(this.getTexture("bump").r,this.getFloat("bumpScale")):wx;else if(s===vb.CLEARCOAT){const e=this.getFloat(s);i=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===vb.CLEARCOAT_ROUGHNESS){const e=this.getFloat(s);i=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===vb.CLEARCOAT_NORMAL)i=t.clearcoatNormalMap?mb(this.getTexture(s),this.getCache(s+"Scale","vec2")):wx;else if(s===vb.SHEEN){const e=this.getColor("sheenColor").mul(this.getFloat("sheen"));i=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(s===vb.SHEEN_ROUGHNESS){const e=this.getFloat(s);i=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(s).a):e,i=i.clamp(.07,1)}else if(s===vb.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){const e=this.getTexture(s);i=sm(rv.x,rv.y,rv.y.negate(),rv.x).mul(e.rg.mul(2).sub(Hp(1)).normalize().mul(e.b))}else i=rv;else if(s===vb.IRIDESCENCE_THICKNESS){const e=jx("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const r=jx("0","float",t.iridescenceThicknessRange);i=e.sub(r).mul(this.getTexture(s).g).add(r)}else i=e}else if(s===vb.TRANSMISSION){const e=this.getFloat(s);i=t.transmissionMap?e.mul(this.getTexture(s).r):e}else if(s===vb.THICKNESS){const e=this.getFloat(s);i=t.thicknessMap?e.mul(this.getTexture(s).g):e}else if(s===vb.IOR)i=this.getFloat(s);else if(s===vb.LIGHT_MAP)i=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===vb.AO_MAP)i=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const t=this.getNodeType(e);i=this.getCache(s,t)}return i}}vb.ALPHA_TEST="alphaTest",vb.COLOR="color",vb.OPACITY="opacity",vb.SHININESS="shininess",vb.SPECULAR="specular",vb.SPECULAR_STRENGTH="specularStrength",vb.SPECULAR_INTENSITY="specularIntensity",vb.SPECULAR_COLOR="specularColor",vb.REFLECTIVITY="reflectivity",vb.ROUGHNESS="roughness",vb.METALNESS="metalness",vb.NORMAL="normal",vb.CLEARCOAT="clearcoat",vb.CLEARCOAT_ROUGHNESS="clearcoatRoughness",vb.CLEARCOAT_NORMAL="clearcoatNormal",vb.EMISSIVE="emissive",vb.ROTATION="rotation",vb.SHEEN="sheen",vb.SHEEN_ROUGHNESS="sheenRoughness",vb.ANISOTROPY="anisotropy",vb.IRIDESCENCE="iridescence",vb.IRIDESCENCE_IOR="iridescenceIOR",vb.IRIDESCENCE_THICKNESS="iridescenceThickness",vb.IOR="ior",vb.TRANSMISSION="transmission",vb.THICKNESS="thickness",vb.ATTENUATION_DISTANCE="attenuationDistance",vb.ATTENUATION_COLOR="attenuationColor",vb.LINE_SCALE="scale",vb.LINE_DASH_SIZE="dashSize",vb.LINE_GAP_SIZE="gapSize",vb.LINE_WIDTH="linewidth",vb.LINE_DASH_OFFSET="dashOffset",vb.POINT_WIDTH="pointWidth",vb.DISPERSION="dispersion",vb.LIGHT_MAP="light",vb.AO_MAP="ao";const Tb=Ip(vb,vb.ALPHA_TEST),_b=Ip(vb,vb.COLOR),wb=Ip(vb,vb.SHININESS),Sb=Ip(vb,vb.EMISSIVE),Mb=Ip(vb,vb.OPACITY),Nb=Ip(vb,vb.SPECULAR),Ab=Ip(vb,vb.SPECULAR_INTENSITY),Cb=Ip(vb,vb.SPECULAR_COLOR),Rb=Ip(vb,vb.SPECULAR_STRENGTH),Eb=Ip(vb,vb.REFLECTIVITY),Bb=Ip(vb,vb.ROUGHNESS),Ib=Ip(vb,vb.METALNESS),Pb=Ip(vb,vb.NORMAL).context({getUV:null}),Fb=Ip(vb,vb.CLEARCOAT),zb=Ip(vb,vb.CLEARCOAT_ROUGHNESS),Ub=Ip(vb,vb.CLEARCOAT_NORMAL).context({getUV:null}),Ob=Ip(vb,vb.ROTATION),Lb=Ip(vb,vb.SHEEN),Vb=Ip(vb,vb.SHEEN_ROUGHNESS),Db=Ip(vb,vb.ANISOTROPY),kb=Ip(vb,vb.IRIDESCENCE),Gb=Ip(vb,vb.IRIDESCENCE_IOR),Wb=Ip(vb,vb.IRIDESCENCE_THICKNESS),Hb=Ip(vb,vb.TRANSMISSION),jb=Ip(vb,vb.THICKNESS),qb=Ip(vb,vb.IOR),$b=Ip(vb,vb.ATTENUATION_DISTANCE),Xb=Ip(vb,vb.ATTENUATION_COLOR),Yb=Ip(vb,vb.LINE_SCALE),Zb=Ip(vb,vb.LINE_DASH_SIZE),Jb=Ip(vb,vb.LINE_GAP_SIZE),Kb=Ip(vb,vb.LINE_WIDTH),Qb=Ip(vb,vb.LINE_DASH_OFFSET),ev=Ip(vb,vb.POINT_WIDTH),tv=Ip(vb,vb.DISPERSION),sv=Ip(vb,vb.LIGHT_MAP),iv=Ip(vb,vb.AO_MAP),rv=ym(new ei).onReference(function(e){return e.material}).onRenderUpdate(function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))});class nv extends jd{static get type(){return"ModelViewProjectionNode"}constructor(e=null){super("vec4"),this.positionNode=e}setup(e){if("fragment"===e.shaderStage)return Wf(e.context.mvp);const t=this.positionNode||cx,s=e.renderer.nodes.modelViewMatrix||ax;return ky.mul(s).mul(t)}}const ov=Bp(nv);class av extends Gd{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isInstanceIndexNode=!0}generate(e){const t=this.getNodeType(e),s=this.scope;let i,r;if(s===av.VERTEX)i=e.getVertexIndex();else if(s===av.INSTANCE)i=e.getInstanceIndex();else if(s===av.DRAW)i=e.getDrawIndex();else if(s===av.INVOCATION_LOCAL)i=e.getInvocationLocalIndex();else if(s===av.INVOCATION_SUBGROUP)i=e.getInvocationSubgroupIndex();else{if(s!==av.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+s);i=e.getSubgroupIndex()}if("vertex"===e.shaderStage||"compute"===e.shaderStage)r=i;else{r=Wf(this).build(e,t)}return r}}av.VERTEX="vertex",av.INSTANCE="instance",av.SUBGROUP="subgroup",av.INVOCATION_LOCAL="invocationLocal",av.INVOCATION_SUBGROUP="invocationSubgroup",av.DRAW="draw";const hv=Ip(av,av.VERTEX),uv=Ip(av,av.INSTANCE),lv=Ip(av,av.SUBGROUP),cv=Ip(av,av.INVOCATION_SUBGROUP),dv=Ip(av,av.INVOCATION_LOCAL),pv=Ip(av,av.DRAW);class mv extends Gd{static get type(){return"InstanceNode"}constructor(e){super("void"),this.instanceMesh=e,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=zd.FRAME,this.buffer=null,this.bufferColor=null}setup(e){let t=this.instanceMatrixNode,s=this.instanceColorNode;const i=this.instanceMesh;if(null===t){const e=i.instanceMatrix;if(i.count<=1e3)t=Lx(e.array,"mat4",Math.max(i.count,1)).element(uv);else{const s=new Ac(e.array,16,1);this.buffer=s;const i=e.usage===Es?ly:uy,r=[i(s,"vec4",16,0),i(s,"vec4",16,4),i(s,"vec4",16,8),i(s,"vec4",16,12)];t=rm(...r)}this.instanceMatrixNode=t}const r=i.instanceColor;if(r&&null===s){const e=new Ho(r.array,3),t=r.usage===Es?ly:uy;this.bufferColor=e,s=Xp(t(e,"vec3",3,0)),this.instanceColorNode=s}const n=t.mul(cx).xyz;if(cx.assign(n),e.hasGeometryAttribute("normal")){const e=Cx(Tx,t);Tx.assign(e)}null!==this.instanceColorNode&&vm("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==Es&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==Es&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const gv=Bp(mv);class fv extends Gd{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=uv:this.batchingIdNode=pv);const t=Pp(([e])=>{const t=By(Uy(this.batchMesh._indirectTexture),0),s=kp(e).modInt(kp(t)),i=kp(e).div(kp(t));return Uy(this.batchMesh._indirectTexture,jp(s,i)).x}).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=t(kp(this.batchingIdNode)),i=this.batchMesh._matricesTexture,r=By(Uy(i),0),n=Dp(s).mul(4).toInt().toVar(),o=n.modInt(r),a=n.div(kp(r)),h=rm(Uy(i,jp(o,a)),Uy(i,jp(o.add(1),a)),Uy(i,jp(o.add(2),a)),Uy(i,jp(o.add(3),a))),u=this.batchMesh._colorsTexture;if(null!==u){const e=Pp(([e])=>{const t=By(Uy(u),0).x,s=e,i=s.modInt(t),r=s.div(t);return Uy(u,jp(i,r)).rgb}).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),t=e(s);vm("vec3","vBatchColor").assign(t)}const l=im(h);cx.assign(h.mul(cx));const c=Tx.div(Xp(l[0].dot(l[0]),l[1].dot(l[1]),l[2].dot(l[2]))),d=l.mul(c).xyz;Tx.assign(d),e.hasGeometryAttribute("tangent")&&Zx.mulAssign(l)}}const yv=Bp(fv),xv=new WeakMap;class bv extends Gd{static get type(){return"SkinningNode"}constructor(e,t=!1){let s,i,r;super("void"),this.skinnedMesh=e,this.useReference=t,this.updateType=zd.OBJECT,this.skinIndexNode=Cy("skinIndex","uvec4"),this.skinWeightNode=Cy("skinWeight","vec4"),t?(s=jx("bindMatrix","mat4"),i=jx("bindMatrixInverse","mat4"),r=qx("skeleton.boneMatrices","mat4",e.skeleton.bones.length)):(s=ym(e.bindMatrix,"mat4"),i=ym(e.bindMatrixInverse,"mat4"),r=Lx(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=i,this.boneMatricesNode=r,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=cx){const{skinIndexNode:s,skinWeightNode:i,bindMatrixNode:r,bindMatrixInverseNode:n}=this,o=e.element(s.x),a=e.element(s.y),h=e.element(s.z),u=e.element(s.w),l=r.mul(t),c=eg(o.mul(i.x).mul(l),a.mul(i.y).mul(l),h.mul(i.z).mul(l),u.mul(i.w).mul(l));return n.mul(c).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=Tx){const{skinIndexNode:s,skinWeightNode:i,bindMatrixNode:r,bindMatrixInverseNode:n}=this,o=e.element(s.x),a=e.element(s.y),h=e.element(s.z),u=e.element(s.w);let l=eg(i.x.mul(o),i.y.mul(a),i.z.mul(h),i.w.mul(u));return l=n.mul(l).mul(r),l.transformDirection(t).xyz}getPreviousSkinnedPosition(e){const t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=qx("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,dx)}needsPreviousBoneMatrices(e){const t=e.renderer.getMRT();return t&&t.has("velocity")}setup(e){this.needsPreviousBoneMatrices(e)&&dx.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(cx.assign(t),e.hasGeometryAttribute("normal")){const t=this.getSkinnedNormal();Tx.assign(t),e.hasGeometryAttribute("tangent")&&Zx.assign(t)}}generate(e,t){if("void"!==t)return cx.build(e,t)}update(e){const t=(this.useReference?e.object:this.skinnedMesh).skeleton;xv.get(t)!==e.frameId&&(xv.set(t,e.frameId),null!==this.previousBoneMatricesNode&&t.previousBoneMatrices.set(t.boneMatrices),t.update())}}const vv=e=>Cp(new bv(e)),Tv=e=>Cp(new bv(e,!0));class _v extends Gd{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode("i".charCodeAt()+e)}getProperties(e){const t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;const s={};for(let e=0,t=this.params.length-1;e<t;e++){const t=this.params[e],i=!0!==t.isNode&&t.name||this.getVarName(e),r=!0!==t.isNode&&t.type||"int";s[i]=Ty(i,r)}const i=e.addStack();return t.returnsNode=this.params[this.params.length-1](s,i,e),t.stackNode=i,e.removeStack(),t}getNodeType(e){const{returnsNode:t}=this.getProperties(e);return t?t.getNodeType(e):"void"}setup(e){this.getProperties(e)}generate(e){const t=this.getProperties(e),s=this.params,i=t.stackNode;for(let t=0,i=s.length-1;t<i;t++){const i=s[t];let r=null,n=null,o=null,a=null,h=null,u=null;i.isNode?(a="int",o=this.getVarName(t),r="0",n=i.build(e,a),h="<"):(a=i.type||"int",o=i.name||this.getVarName(t),r=i.start,n=i.end,h=i.condition,u=i.update,"number"==typeof r?r=r.toString():r&&r.isNode&&(r=r.build(e,a)),"number"==typeof n?n=n.toString():n&&n.isNode&&(n=n.build(e,a)),void 0!==r&&void 0===n?(r+=" - 1",n="0",h=">="):void 0!==n&&void 0===r&&(r="0",h="<"),void 0===h&&(h=Number(r)>Number(n)?">=":"<"));const l={start:r,end:n},c=l.start,d=l.end;let p="",m="",g="";u||(u="int"===a||"uint"===a?h.includes("<")?"++":"--":h.includes("<")?"+= 1.":"-= 1."),p+=e.getVar(a,o)+" = "+c,m+=o+" "+h+" "+d,g+=o+" "+u;const f=`for ( ${p}; ${m}; ${g} )`;e.addFlowCode((0===t?"\n":"")+e.tab+f+" {\n\n").addFlowTab()}const r=i.build(e,"void"),n=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode("\n"+e.tab+r);for(let t=0,s=this.params.length-1;t<s;t++)e.addFlowCode((0===t?"":e.tab)+"}\n\n").removeFlowTab();return e.addFlowTab(),n}}const wv=(...e)=>Cp(new _v(Ep(e,"int"))).append(),Sv=()=>Ty("continue").append(),Mv=()=>Ty("break").append(),Nv=(...e)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),wv(...e)),Av=new WeakMap,Cv=new _i,Rv=Pp(({bufferMap:e,influence:t,stride:s,width:i,depth:r,offset:n})=>{const o=kp(hv).mul(s).add(n),a=o.div(i),h=o.sub(a.mul(i));return Uy(e,jp(h,a)).depth(r).mul(t)});class Ev extends Gd{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=ym(1),this.updateType=zd.OBJECT}setup(e){const{geometry:t}=e,s=void 0!==t.morphAttributes.position,i=t.hasAttribute("normal")&&void 0!==t.morphAttributes.normal,r=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,n=void 0!==r?r.length:0,{texture:o,stride:a,size:h}=function(e){const t=void 0!==e.morphAttributes.position,s=void 0!==e.morphAttributes.normal,i=void 0!==e.morphAttributes.color,r=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,n=void 0!==r?r.length:0;let o=Av.get(e);if(void 0===o||o.count!==n){void 0!==o&&o.texture.dispose();const a=e.morphAttributes.position||[],h=e.morphAttributes.normal||[],u=e.morphAttributes.color||[];let l=0;!0===t&&(l=1),!0===s&&(l=2),!0===i&&(l=3);let c=e.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=Ie,g.needsUpdate=!0;const f=4*l;for(let x=0;x<n;x++){const b=a[x],v=h[x],T=u[x],_=c*d*4*x;for(let w=0;w<b.count;w++){const S=w*f;!0===t&&(Cv.fromBufferAttribute(b,w),m[_+S+0]=Cv.x,m[_+S+1]=Cv.y,m[_+S+2]=Cv.z,m[_+S+3]=0),!0===s&&(Cv.fromBufferAttribute(v,w),m[_+S+4]=Cv.x,m[_+S+5]=Cv.y,m[_+S+6]=Cv.z,m[_+S+7]=0),!0===i&&(Cv.fromBufferAttribute(T,w),m[_+S+8]=Cv.x,m[_+S+9]=Cv.y,m[_+S+10]=Cv.z,m[_+S+11]=4===T.itemSize?Cv.w:1)}}function y(){g.dispose(),Av.delete(e),e.removeEventListener("dispose",y)}o={count:n,texture:g,stride:l,size:new ei(c,d)},Av.set(e,o),e.addEventListener("dispose",y)}return o}(t);!0===s&&cx.mulAssign(this.morphBaseInfluence),!0===i&&Tx.mulAssign(this.morphBaseInfluence);const u=kp(h.width);wv(n,({i:e})=>{const t=Dp(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(Uy(this.mesh.morphTexture,jp(kp(e).add(1),kp(uv))).r):t.assign(jx("morphTargetInfluences","float").element(e).toVar()),!0===s&&cx.addAssign(Rv({bufferMap:o,influence:t,stride:a,width:u,depth:e,offset:kp(0)})),!0===i&&Tx.addAssign(Rv({bufferMap:o,influence:t,stride:a,width:u,depth:e,offset:kp(1)}))})}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce((e,t)=>e+t,0)}}const Bv=Bp(Ev),Iv=(e,t)=>{for(const s of t)if(s.isAnalyticLightNode&&s.light.id===e)return s;return null},Pv=new WeakMap;class Fv extends Gd{static get type(){return"LightsNode"}constructor(e=[]){super("vec3"),this.totalDiffuseNode=Xp().toVar("totalDiffuse"),this.totalSpecularNode=Xp().toVar("totalSpecular"),this.outgoingLightNode=Xp().toVar("outgoingLight"),this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);const t=[];for(const e of this._lightNodes)t.push(e.getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getDataFromNode(this);for(const s of t.nodes)s.build(e)}setupLightsNode(e){const t=[],s=this._lightNodes,i=(e=>e.sort((e,t)=>e.id-t.id))(this._lights),r=e.renderer.nodes.library;for(const e of i)if(e.isNode)t.push(Cp(e));else{let i=null;if(null!==s&&(i=Iv(e.id,s)),null===i){const s=r.getLightNodeClass(e.constructor);if(null===s){console.warn(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let i=null;Pv.has(e)?i=Pv.get(e):(i=new s(e),Pv.set(e,i)),t.push(i)}}this._lightNodes=t}setup(e){null===this._lightNodes&&this.setupLightsNode(e);const t=e.context,s=t.lightingModel;let i=this.outgoingLightNode;if(s){const{_lightNodes:r,totalDiffuseNode:n,totalSpecularNode:o}=this;t.outgoingLight=i;const a=e.addStack();e.getDataFromNode(this).nodes=a.nodes,s.start(t,a,e);for(const t of r)t.build(e);s.indirect(t,a,e);const{backdrop:h,backdropAlpha:u}=t,{directDiffuse:l,directSpecular:c,indirectDiffuse:d,indirectSpecular:p}=t.reflectedLight;let m=l.add(d);null!==h&&(m=Xp(null!==u?u.mix(m,h):h),t.material.transparent=!0),n.assign(m),o.assign(c.add(p)),i.assign(n.add(o)),s.finish(t,a,e),i=i.bypass(e.removeStack())}return i}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}}const zv=Bp(Fv);class Uv extends Gd{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class Ov extends Uv{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class Lv extends Of{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,i=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=i,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s={directDiffuse:Xp().toVar("directDiffuse"),directSpecular:Xp().toVar("directSpecular"),indirectDiffuse:Xp().toVar("indirectDiffuse"),indirectSpecular:Xp().toVar("indirectSpecular")};return{radiance:Xp().toVar("radiance"),irradiance:Xp().toVar("irradiance"),iblIrradiance:Xp().toVar("iblIrradiance"),ambientOcclusion:Dp(1).toVar("ambientOcclusion"),reflectedLight:s,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const Vv=Bp(Lv);class Dv extends Uv{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let kv,Gv;class Wv extends Gd{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===Wv.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=zd.NONE;return this.scope!==Wv.SIZE&&this.scope!==Wv.VIEWPORT||(e=zd.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Wv.VIEWPORT?null!==t?Gv.copy(t.viewport):(e.getViewport(Gv),Gv.multiplyScalar(e.getPixelRatio())):null!==t?(kv.width=t.width,kv.height=t.height):e.getDrawingBufferSize(kv)}setup(){const e=this.scope;let t=null;return t=e===Wv.SIZE?ym(kv||(kv=new ei)):e===Wv.VIEWPORT?ym(Gv||(Gv=new _i)):Hp(qv.div(jv)),t}generate(e){if(this.scope===Wv.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(jv).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}Wv.COORDINATE="coordinate",Wv.VIEWPORT="viewport",Wv.SIZE="size",Wv.UV="uv";const Hv=Ip(Wv,Wv.UV),jv=Ip(Wv,Wv.SIZE),qv=Ip(Wv,Wv.COORDINATE),$v=Ip(Wv,Wv.VIEWPORT),Xv=$v.zw,Yv=qv.sub($v.xy),Zv=Yv.div(Xv),Jv=Pp(()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),jv),"vec2").once()(),Kv=Pp(()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),Hv),"vec2").once()(),Qv=Pp(()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),Hv.flipY()),"vec2").once()(),eT=new ei;class tT extends Fy{static get type(){return"ViewportTextureNode"}constructor(e=Hv,t=null,s=null){null===s&&((s=new Xa).minFilter=Se),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=zd.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(eT);const s=this.value;s.image.width===eT.width&&s.image.height===eT.height||(s.image.width=eT.width,s.image.height=eT.height,s.needsUpdate=!0);const i=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=i}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const sT=Bp(tT),iT=Bp(tT,null,null,{generateMipmaps:!0});let rT=null;class nT extends tT{static get type(){return"ViewportDepthTextureNode"}constructor(e=Hv,t=null){null===rT&&(rT=new Qa),super(e,t,rT)}}const oT=Bp(nT);class aT extends Gd{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===aT.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let i=null;if(t===aT.DEPTH_BASE)null!==s&&(i=dT().assign(s));else if(t===aT.DEPTH)i=e.isPerspectiveCamera?lT(gx.z,Ly,Vy):hT(gx.z,Ly,Vy);else if(t===aT.LINEAR_DEPTH)if(null!==s)if(e.isPerspectiveCamera){const e=cT(s,Ly,Vy);i=hT(e,Ly,Vy)}else i=s;else i=hT(gx.z,Ly,Vy);return i}}aT.DEPTH_BASE="depthBase",aT.DEPTH="depth",aT.LINEAR_DEPTH="linearDepth";const hT=(e,t,s)=>e.add(t).div(t.sub(s)),uT=(e,t,s)=>t.sub(s).mul(e).sub(t),lT=(e,t,s)=>t.add(e).mul(s).div(s.sub(t).mul(e)),cT=(e,t,s)=>t.mul(s).div(s.sub(t).mul(e).sub(s)),dT=Bp(aT,aT.DEPTH_BASE),pT=Ip(aT,aT.DEPTH),mT=Bp(aT,aT.LINEAR_DEPTH),gT=mT(oT());pT.assign=e=>dT(e);class fT extends Gd{static get type(){return"ClippingNode"}constructor(e=fT.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{localClipIntersection:s,localClippingCount:i,globalClippingCount:r}=t,n=r+i,o=s?n-i:n;return this.scope===fT.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(t.planes,n,o):this.setupDefault(t.planes,n,o)}setupAlphaToCoverage(e,t,s){return Pp(()=>{const i=kx(e),r=bm("float","distanceToPlane"),n=bm("float","distanceToGradient"),o=bm("float","clipOpacity");let a;if(o.assign(1),wv(s,({i:e})=>{a=i.element(e),r.assign(gx.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),o.mulAssign(Rf(n.negate(),n,r)),o.equal(0).discard()}),s<t){const e=bm("float","unionclipOpacity");e.assign(1),wv({start:s,end:t},({i:t})=>{a=i.element(t),r.assign(gx.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),e.mulAssign(Rf(n.negate(),n,r).oneMinus())}),o.mulAssign(e.oneMinus())}Tm.a.mulAssign(o),Tm.a.equal(0).discard()})()}setupDefault(e,t,s){return Pp(()=>{const i=kx(e);let r;if(wv(s,({i:e})=>{r=i.element(e),gx.dot(r.xyz).greaterThan(r.w).discard()}),s<t){const e=bm("bool","clipped");e.assign(!0),wv({start:s,end:t},({i:t})=>{r=i.element(t),e.assign(gx.dot(r.xyz).greaterThan(r.w).and(e))}),e.discard()}})()}}fT.ALPHA_TO_COVERAGE="alphaToCoverage",fT.DEFAULT="default";class yT extends tn{static get type(){return"NodeMaterial"}constructor(){super(),this.isNodeMaterial=!0,this.type=this.constructor.type,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,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+Ad(this)}build(e){this.setup(e)}setupObserver(e){return new _d(e)}setup(e){let t;e.context.setupNormal=()=>this.setupNormal(e),e.addStack(),e.stack.outputNode=this.vertexNode||this.setupPosition(e),e.addFlow("vertex",e.removeStack()),e.addStack();const s=this.setupClipping(e);if(!0===this.depthWrite&&this.setupDepth(e),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);const i=this.setupLighting(e);null!==s&&e.stack.add(s);const r=Kp(i,Tm.a).max(0);t=this.setupOutput(e,r),Vm.assign(t),null!==this.outputNode&&(t=this.outputNode);if(null!==e.renderer.getRenderTarget()){const s=e.renderer.getMRT(),i=this.mrtNode;null!==s?(t=s,null!==i&&(t=s.merge(i))):null!==i&&(t=i)}}else{let s=this.fragmentNode;!0!==s.isOutputStructNode&&(s=Kp(s)),t=this.setupOutput(e,s)}e.stack.outputNode=t,e.addFlow("fragment",e.removeStack()),e.monitor=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;const{globalClippingCount:t,localClippingCount:s}=e.clippingContext;let i=null;if(t||s){const t=e.renderer.samples;this.alphaToCoverage&&t>1?i=Cp(new fT(fT.ALPHA_TO_COVERAGE)):e.stack.add(Cp(new fT))}return i}setupDepth(e){const{renderer:t}=e;let s=this.depthNode;if(null===s){const e="getMRT"in t&&t.getMRT();if(e&&e.has("depth"))s=e.get("depth");else if(!0===t.logarithmicDepthBuffer){s=ov().w.add(1).log2().mul(Dy).mul(.5)}}null!==s&&pT.assign(s).append()}setupPosition(e){const{object:t}=e,s=t.geometry;if(e.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&Bv(t).append(),!0===t.isSkinnedMesh&&Tv(t).append(),this.displacementMap){const e=Xx("displacementMap","texture"),t=Xx("displacementScale","float"),s=Xx("displacementBias","float");cx.addAssign(Tx.normalize().mul(e.x.mul(t).add(s)))}t.isBatchedMesh&&yv(t).append(),t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&gv(t).append(),null!==this.positionNode&&cx.assign(this.positionNode);const i=ov();return e.context.vertex=e.removeStack(),e.context.mvp=i,i}setupDiffuseColor({object:e,geometry:t}){let s=this.colorNode?Kp(this.colorNode):_b;if(!0===this.vertexColors&&t.hasAttribute("color")&&(s=Kp(s.xyz.mul(Cy("color","vec3")),s.a)),e.instanceColor){s=vm("vec3","vInstanceColor").mul(s)}if(e.isBatchedMesh&&e._colorsTexture){s=vm("vec3","vBatchColor").mul(s)}Tm.assign(s);const i=this.opacityNode?Dp(this.opacityNode):Mb;if(Tm.a.assign(Tm.a.mul(i)),null!==this.alphaTestNode||this.alphaTest>0){const e=null!==this.alphaTestNode?Dp(this.alphaTestNode):Tb;Tm.a.lessThanEqual(e).discard()}!1===this.transparent&&1===this.blending&&!1===this.alphaToCoverage&&Tm.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Xp(0):Tm.rgb}setupNormal(){return this.normalNode?Xp(this.normalNode):Pb}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?Xx("envMap","cubeTexture"):Xx("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Dv(sv)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const i=this.setupLightMap(e);if(i&&i.isLightingNode&&t.push(i),null!==this.aoNode||e.material.aoMap){const e=null!==this.aoNode?this.aoNode:iv;t.push(new Ov(e))}let r=this.lightsNode||e.lightsNode;return t.length>0&&(r=zv([...r.getLights(),...t])),r}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:i,emissiveNode:r}=this,n=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null;let o=this.setupOutgoingLight(e);if(n&&n.getScope().getLights().length>0){const t=this.setupLightingModel(e);o=Vv(n,t,s,i)}else null!==s&&(o=Xp(null!==i?Mf(o,s,i):s));return(r&&!0===r.isNode||t.emissive&&!0===t.emissive.isColor)&&(_m.assign(Xp(r||Sb)),o=o.add(_m)),o}setupOutput(e,t){if(!0===this.fog){const s=e.fogNode;s&&(t=Kp(s.mix(t.rgb,s.colorNode),t.a))}return t}setDefaultValues(e){for(const t in e){const s=e[t];void 0===this[t]&&(this[t]=s,s&&s.clone&&(this[t]=s.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});const s=tn.prototype.toJSON.call(this,e),i=Cd(this);s.inputNodes={};for(const{property:t,childNode:r}of i)s.inputNodes[t]=r.toJSON(e).uuid;function r(e){const t=[];for(const s in e){const i=e[s];delete i.metadata,t.push(i)}return t}if(t){const t=r(e.textures),i=r(e.images),n=r(e.nodes);t.length>0&&(s.textures=t),i.length>0&&(s.images=i),n.length>0&&(s.nodes=n)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.positionNode=e.positionNode,this.depthNode=e.depthNode,this.shadowNode=e.shadowNode,this.shadowPositionNode=e.shadowPositionNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const xT=new Va;class bT extends yT{static get type(){return"InstancedPointsNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(xT),this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor;this.vertexNode=Pp(()=>{const e=Cy("instancePosition").xyz,t=Kp(ax.mul(Kp(e,1))),s=$v.z.div($v.w),i=ky.mul(t),r=lx.xy.toVar();return r.mulAssign(this.pointWidthNode?this.pointWidthNode:ev),r.assign(r.div($v.z)),r.y.assign(r.y.mul(s)),r.assign(r.mul(i.w)),i.addAssign(Kp(r,0,0)),i})(),this.fragmentNode=Pp(()=>{const i=Dp(1).toVar(),r=Sf(Ry().mul(2).sub(1));if(t&&e.samples>1){const e=Dp(r.fwidth()).toVar();i.assign(Rf(e.oneMinus(),e.add(1),r).oneMinus())}else r.greaterThan(1).discard();let n;if(this.pointColorNode)n=this.pointColorNode;else if(s){n=Cy("instanceColor").mul(_b)}else n=_b;return i.mulAssign(Mb),Kp(n,i)})()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const vT=new Ma;class TT extends yT{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(vT),this.setValues(e)}}const _T=new zu;class wT extends yT{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(_T),this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode,t=this.dashScaleNode?Dp(this.dashScaleNode):Yb,s=this.dashSizeNode?Dp(this.dashSizeNode):Zb,i=this.dashSizeNode?Dp(this.dashGapNode):Jb;Dm.assign(s),km.assign(i);const r=Wf(Cy("lineDistance").mul(t));(e?r.add(e):r).mod(Dm.add(km)).greaterThan(Dm).discard()}}const ST=new zu;class MT extends yT{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.lights=!1,this.setDefaultValues(ST),this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.useDash=e.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(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor,i=this.dashed,r=this.worldUnits,n=Pp(({start:e,end:t})=>{const s=ky.element(2).element(2),i=ky.element(3).element(2).mul(-.5).div(s).sub(e.z).div(t.z.sub(e.z));return Kp(Mf(e.xyz,t.xyz,i),t.w)}).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=Pp(()=>{const e=Cy("instanceStart"),t=Cy("instanceEnd"),s=Kp(ax.mul(Kp(e,1))).toVar("start"),o=Kp(ax.mul(Kp(t,1))).toVar("end");r&&(vm("vec3","worldStart").assign(s.xyz),vm("vec3","worldEnd").assign(o.xyz));const a=$v.z.div($v.w),h=ky.element(2).element(3).equal(-1);Op(h,()=>{Op(s.z.lessThan(0).and(o.z.greaterThan(0)),()=>{o.assign(n({start:s,end:o}))}).ElseIf(o.z.lessThan(0).and(s.z.greaterThanEqual(0)),()=>{s.assign(n({start:o,end:s}))})});const u=ky.mul(s),l=ky.mul(o),c=u.xyz.div(u.w),d=l.xyz.div(l.w),p=d.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const m=Kp().toVar();if(r){const e=o.xyz.sub(s.xyz).normalize(),t=Mf(s.xyz,o.xyz,.5).normalize(),r=e.cross(t).normalize(),n=e.cross(r),a=vm("vec4","worldPos");a.assign(lx.y.lessThan(.5).select(s,o));const h=Kb.mul(.5);a.addAssign(Kp(lx.x.lessThan(0).select(r.mul(h),r.mul(h).negate()),0)),i||(a.addAssign(Kp(lx.y.lessThan(.5).select(e.mul(h).negate(),e.mul(h)),0)),a.addAssign(Kp(n.mul(h),0)),Op(lx.y.greaterThan(1).or(lx.y.lessThan(0)),()=>{a.subAssign(Kp(n.mul(2).mul(h),0))})),m.assign(ky.mul(a));const u=Xp().toVar();u.assign(lx.y.lessThan(.5).select(c,d)),m.z.assign(u.z.mul(m.w))}else{const e=Hp(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),e.x.assign(e.x.div(a)),e.assign(lx.x.lessThan(0).select(e.negate(),e)),Op(lx.y.lessThan(0),()=>{e.assign(e.sub(p))}).ElseIf(lx.y.greaterThan(1),()=>{e.assign(e.add(p))}),e.assign(e.mul(Kb)),e.assign(e.div($v.w)),m.assign(lx.y.lessThan(.5).select(u,l)),e.assign(e.mul(m.w)),m.assign(m.add(Kp(e,0,0)))}return m})();const o=Pp(({p1:e,p2:t,p3:s,p4:i})=>{const r=e.sub(s),n=i.sub(s),o=t.sub(e),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 Hp(d,p)});this.fragmentNode=Pp(()=>{const n=Ry();if(i){const e=this.offsetNode?Dp(this.offsetNodeNode):Qb,t=this.dashScaleNode?Dp(this.dashScaleNode):Yb,s=this.dashSizeNode?Dp(this.dashSizeNode):Zb,i=this.dashSizeNode?Dp(this.dashGapNode):Jb;Dm.assign(s),km.assign(i);const r=Cy("instanceDistanceStart"),o=Cy("instanceDistanceEnd"),a=lx.y.lessThan(.5).select(t.mul(r),Yb.mul(o)),h=Wf(a.add(Qb)),u=e?h.add(e):h;n.y.lessThan(-1).or(n.y.greaterThan(1)).discard(),u.mod(Dm.add(km)).greaterThan(Dm).discard()}const a=Dp(1).toVar("alpha");if(r){const s=vm("vec3","worldStart"),r=vm("vec3","worldEnd"),n=vm("vec4","worldPos").xyz.normalize().mul(1e5),h=r.sub(s),u=o({p1:s,p2:r,p3:Xp(0,0,0),p4:n}),l=s.add(h.mul(u.x)),c=n.mul(u.y),d=l.sub(c).length().div(Kb);if(!i)if(t&&e.samples>1){const e=d.fwidth();a.assign(Rf(e.negate().add(.5),e.add(.5),d).oneMinus())}else d.greaterThan(.5).discard()}else if(t&&e.samples>1){const e=n.x,t=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1)),s=e.mul(e).add(t.mul(t)),i=Dp(s.fwidth()).toVar("dlen");Op(n.y.abs().greaterThan(1),()=>{a.assign(Rf(i.oneMinus(),i.add(1),s).oneMinus())})}else Op(n.y.abs().greaterThan(1),()=>{const e=n.x,t=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1));e.mul(e).add(t.mul(t)).greaterThan(1).discard()});let h;if(this.lineColorNode)h=this.lineColorNode;else if(s){const e=Cy("instanceColorStart"),t=Cy("instanceColorEnd");h=lx.y.lessThan(.5).select(e,t).mul(_b)}else h=_b;return Kp(h,a)})()}get worldUnits(){return this.useWorldUnits}set worldUnits(e){this.useWorldUnits!==e&&(this.useWorldUnits=e,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(e){this.useDash!==e&&(this.useDash=e,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const NT=e=>Cp(e).mul(.5).add(.5),AT=e=>Cp(e).mul(2).sub(1),CT=new Eu;class RT extends yT{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(CT),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?Dp(this.opacityNode):Mb;Tm.assign(Kp(NT(Mx),e))}}class ET extends jd{static get type(){return"EquirectUVNode"}constructor(e=mx){super("vec2"),this.dirNode=e}setup(){const e=this.dirNode,t=e.z.atan2(e.x).mul(1/(2*Math.PI)).add(.5),s=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return Hp(t,s)}}const BT=Bp(ET);class IT extends so{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,i=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const r=new Gn(5,5,5),n=BT(mx),o=new yT;o.colorNode=zy(t,n,0),o.side=1,o.blending=0;const a=new Dn(r,o),h=new no;h.add(a),t.minFilter===Se&&(t.minFilter=Te);const u=new eo(1,10,this),l=e.getMRT();return e.setMRT(null),u.update(e,h),e.setMRT(l),t.minFilter=s,t.currentGenerateMipmaps=i,a.geometry.dispose(),a.material.dispose(),this}}const PT=new WeakMap;class FT extends jd{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=Ux();const t=new to;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=zd.RENDER}updateBefore(e){const{renderer:t,material:s}=e,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){const e=i.isTextureNode?i.value:s[i.property];if(e&&e.isTexture){const s=e.mapping;if(s===le||s===ce){if(PT.has(e)){const t=PT.get(e);UT(t,e.mapping),this._cubeTexture=t}else{const s=e.image;if(function(e){return null!=e&&e.height>0}(s)){const i=new IT(s.height);i.fromEquirectangularTexture(t,e),UT(i.texture,e.mapping),this._cubeTexture=i.texture,PT.set(e,i.texture),e.addEventListener("dispose",zT)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function zT(e){const t=e.target;t.removeEventListener("dispose",zT);const s=PT.get(t);void 0!==s&&(PT.delete(t),s.dispose())}function UT(e,t){t===le?e.mapping=he:t===ce&&(e.mapping=ue)}const OT=Bp(FT);class LT extends Uv{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=OT(this.envNode)}}class VT extends Uv{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=Dp(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class DT{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class kT extends DT{constructor(){super()}indirect(e,t,s){const i=e.ambientOcclusion,r=e.reflectedLight,n=s.context.irradianceLightMap;r.indirectDiffuse.assign(Kp(0)),n?r.indirectDiffuse.addAssign(n):r.indirectDiffuse.addAssign(Kp(1,1,1,0)),r.indirectDiffuse.mulAssign(i),r.indirectDiffuse.mulAssign(Tm.rgb)}finish(e,t,s){const i=s.material,r=e.outgoingLight,n=s.context.environment;if(n)switch(i.combine){case 0:r.rgb.assign(Mf(r.rgb,r.rgb.mul(n.rgb),Rb.mul(Eb)));break;case 1:r.rgb.assign(Mf(r.rgb,n.rgb,Rb.mul(Eb)));break;case 2:r.rgb.addAssign(n.rgb.mul(Rb.mul(Eb)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",i.combine)}}}const GT=new sn;class WT extends yT{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(GT),this.setValues(e)}setupNormal(){return wx}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new LT(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new VT(sv)),t}setupOutgoingLight(){return Tm.rgb}setupLightingModel(){return new kT}}const HT=Pp(({f0:e,f90:t,dotVH:s})=>{const i=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return e.mul(i.oneMinus()).add(t.mul(i))}),jT=Pp(e=>e.diffuseColor.mul(1/Math.PI)),qT=Pp(({dotNH:e})=>Lm.mul(Dp(.5)).add(1).mul(Dp(1/Math.PI)).mul(e.pow(Lm))),$T=Pp(({lightDirection:e})=>{const t=e.add(fx).normalize(),s=Mx.dot(t).clamp(),i=fx.dot(t).clamp(),r=HT({f0:Um,f90:1,dotVH:i}),n=Dp(.25),o=qT({dotNH:s});return r.mul(n).mul(o)});class XT extends kT{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const i=Mx.dot(e).clamp().mul(t);s.directDiffuse.addAssign(i.mul(jT({diffuseColor:Tm.rgb}))),!0===this.specular&&s.directSpecular.addAssign(i.mul($T({lightDirection:e})).mul(Rb))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(jT({diffuseColor:Tm}))),s.indirectDiffuse.mulAssign(e)}}const YT=new Bu;class ZT extends yT{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(YT),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new LT(t):null}setupLightingModel(){return new XT(!1)}}const JT=new Cu;class KT extends yT{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(JT),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new LT(t):null}setupLightingModel(){return new XT}setupVariants(){const e=(this.shininessNode?Dp(this.shininessNode):wb).max(1e-4);Lm.assign(e);const t=this.specularNode||Nb;Um.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const QT=Pp(()=>{const e=wx.dFdx().abs().max(wx.dFdy().abs());return e.x.max(e.y).max(e.z)}),e_=Pp(e=>{const{roughness:t}=e,s=QT();let i=t.max(.0525);return i=i.add(s),i=i.min(1),i}),t_=Pp(({alpha:e,dotNL:t,dotNV:s})=>{const i=e.pow2(),r=t.mul(i.add(i.oneMinus().mul(s.pow2())).sqrt()),n=s.mul(i.add(i.oneMinus().mul(t.pow2())).sqrt());return ig(.5,r.add(n).max(wg))}).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),s_=Pp(({alphaT:e,alphaB:t,dotTV:s,dotBV:i,dotTL:r,dotBL:n,dotNV:o,dotNL:a})=>{const h=a.mul(Xp(e.mul(s),t.mul(i),o).length()),u=o.mul(Xp(e.mul(r),t.mul(n),a).length());return ig(.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"}]}),i_=Pp(({alpha:e,dotNH:t})=>{const s=e.pow2(),i=t.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"}]}),r_=Dp(1/Math.PI),n_=Pp(({alphaT:e,alphaB:t,dotNH:s,dotTH:i,dotBH:r})=>{const n=e.mul(t),o=Xp(t.mul(i),e.mul(r),n.mul(s)),a=o.dot(o),h=n.div(a);return r_.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"}]}),o_=Pp(e=>{const{lightDirection:t,f0:s,f90:i,roughness:r,f:n,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=e,h=e.normalView||Mx,u=r.pow2(),l=t.add(fx).normalize(),c=h.dot(t).clamp(),d=h.dot(fx).clamp(),p=h.dot(l).clamp(),m=fx.dot(l).clamp();let g,f,y=HT({f0:s,f90:i,dotVH:m});if(Mp(o)&&(y=Rm.mix(y,n)),Mp(a)){const e=Fm.dot(t),s=Fm.dot(fx),i=Fm.dot(l),r=zm.dot(t),n=zm.dot(fx),o=zm.dot(l);g=s_({alphaT:Im,alphaB:u,dotTV:s,dotBV:n,dotTL:e,dotBL:r,dotNV:d,dotNL:c}),f=n_({alphaT:Im,alphaB:u,dotNH:p,dotTH:i,dotBH:o})}else g=t_({alpha:u,dotNL:c,dotNV:d}),f=i_({alpha:u,dotNH:p});return y.mul(g).mul(f)}),a_=Pp(({roughness:e,dotNV:t})=>{const s=Kp(-1,-.0275,-.572,.022),i=Kp(1,.0425,1.04,-.04),r=e.mul(s).add(i),n=r.x.mul(r.x).min(t.mul(-9.28).exp2()).mul(r.x).add(r.y);return Hp(-1.04,1.04).mul(n).add(r.zw)}).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),h_=Pp(e=>{const{dotNV:t,specularColor:s,specularF90:i,roughness:r}=e,n=a_({dotNV:t,roughness:r});return s.mul(n.x).add(i.mul(n.y))}),u_=Pp(({f:e,f90:t,dotVH:s})=>{const i=s.oneMinus().saturate(),r=i.mul(i),n=i.mul(r,r).clamp(0,.9999);return e.sub(Xp(t).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"}]}),l_=Pp(({roughness:e,dotNH:t})=>{const s=e.pow2(),i=Dp(1).div(s),r=t.pow2().oneMinus().max(.0078125);return Dp(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"}]}),c_=Pp(({dotNV:e,dotNL:t})=>Dp(1).div(Dp(4).mul(t.add(e).sub(t.mul(e))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),d_=Pp(({lightDirection:e})=>{const t=e.add(fx).normalize(),s=Mx.dot(e).clamp(),i=Mx.dot(fx).clamp(),r=Mx.dot(t).clamp(),n=l_({roughness:Cm,dotNH:r}),o=c_({dotNV:i,dotNL:s});return Am.mul(n).mul(o)}),p_=Pp(({N:e,V:t,roughness:s})=>{const i=e.dot(t).saturate(),r=Hp(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"}]}),m_=Pp(({f:e})=>{const t=e.length();return lf(t.mul(t).add(e.z).div(t.add(1)),0)}).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),g_=Pp(({v1:e,v2:t})=>{const s=e.dot(t),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).select(o,lf(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return e.cross(t).mul(a)}).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),f_=Pp(({N:e,V:t,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=Xp().toVar();return Op(l.dot(s.sub(r)).greaterThanEqual(0),()=>{const h=t.sub(e.mul(t.dot(e))).normalize(),u=e.cross(h).negate(),l=i.mul(im(h,u,e).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=Xp(0).toVar();f.addAssign(g_({v1:d,v2:p})),f.addAssign(g_({v1:p,v2:m})),f.addAssign(g_({v1:m,v2:g})),f.addAssign(g_({v1:g,v2:d})),c.assign(Xp(m_({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"}]}),y_=1/6,x_=e=>sg(y_,sg(e,sg(e,e.negate().add(3)).sub(3)).add(1)),b_=e=>sg(y_,sg(e,sg(e,sg(3,e).sub(6))).add(4)),v_=e=>sg(y_,sg(e,sg(e,sg(-3,e).add(3)).add(3)).add(1)),T_=e=>sg(y_,xf(e,3)),__=e=>x_(e).add(b_(e)),w_=e=>v_(e).add(T_(e)),S_=e=>eg(-1,b_(e).div(x_(e).add(b_(e)))),M_=e=>eg(1,T_(e).div(v_(e).add(T_(e)))),N_=(e,t,s)=>{const i=e.uvNode,r=sg(i,t.zw).add(.5),n=Lg(r),o=kg(r),a=__(o.x),h=w_(o.x),u=S_(o.x),l=M_(o.x),c=S_(o.y),d=M_(o.y),p=Hp(n.x.add(u),n.y.add(c)).sub(.5).mul(t.xy),m=Hp(n.x.add(l),n.y.add(c)).sub(.5).mul(t.xy),g=Hp(n.x.add(u),n.y.add(d)).sub(.5).mul(t.xy),f=Hp(n.x.add(l),n.y.add(d)).sub(.5).mul(t.xy),y=__(o.y).mul(eg(a.mul(e.uv(p).level(s)),h.mul(e.uv(m).level(s)))),x=w_(o.y).mul(eg(a.mul(e.uv(g).level(s)),h.mul(e.uv(f).level(s))));return y.add(x)},A_=Pp(([e,t=Dp(3)])=>{const s=Hp(e.size(kp(t))),i=Hp(e.size(kp(t.add(1)))),r=ig(1,s),n=ig(1,i),o=N_(e,Kp(r,s),Lg(t)),a=N_(e,Kp(n,i),Vg(t));return kg(t).mix(o,a)}),C_=Pp(([e,t,s,i,r])=>{const n=Xp(Cf(t.negate(),Dg(e),ig(1,i))),o=Xp(Zg(r[0].xyz),Zg(r[1].xyz),Zg(r[2].xyz));return Dg(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"}]}),R_=Pp(([e,t])=>e.mul(Nf(t.mul(2).sub(2),0,1))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),E_=iT(),B_=Pp(([e,t,s])=>{const i=E_.uv(e),r=zg(Dp(jv.x)).mul(R_(t,s));return A_(i,r)}),I_=Pp(([e,t,s])=>(Op(s.notEqual(0),()=>{const i=Fg(t).negate().div(s);return Ig(i.negate().mul(e))}),Xp(1))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),P_=Pp(([e,t,s,i,r,n,o,a,h,u,l,c,d,p,m])=>{let g,f;if(m){g=Kp().toVar(),f=Xp().toVar();const r=l.sub(1).mul(m.mul(.025)),n=Xp(l.sub(r),l,l.add(r));wv({start:0,end:3},({i:r})=>{const l=n.element(r),m=C_(e,t,c,l,a),y=o.add(m),x=u.mul(h.mul(Kp(y,1))),b=Hp(x.xy.div(x.w)).toVar();b.addAssign(1),b.divAssign(2),b.assign(Hp(b.x,b.y.oneMinus()));const v=B_(b,s,l);g.element(r).assign(v.element(r)),g.a.addAssign(v.a),f.element(r).assign(i.element(r).mul(I_(Zg(m),d,p).element(r)))}),g.a.divAssign(3)}else{const r=C_(e,t,c,l,a),n=o.add(r),m=u.mul(h.mul(Kp(n,1))),y=Hp(m.xy.div(m.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(Hp(y.x,y.y.oneMinus())),g=B_(y,s,l),f=i.mul(I_(Zg(r),d,p))}const y=f.rgb.mul(g.rgb),x=e.dot(t).clamp(),b=Xp(h_({dotNV:x,specularColor:r,specularF90:n,roughness:s})),v=f.r.add(f.g,f.b).div(3);return Kp(b.oneMinus().mul(y),g.a.oneMinus().mul(v).oneMinus())}),F_=im(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),z_=(e,t)=>e.sub(t).div(e.add(t)).pow2(),U_=(e,t)=>{const s=e.mul(2*Math.PI*1e-9),i=Xp(54856e-17,44201e-17,52481e-17),r=Xp(1681e3,1795300,2208400),n=Xp(43278e5,93046e5,66121e5),o=Dp(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(t.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=i.mul(n.mul(2*Math.PI).sqrt()).mul(r.mul(s).add(t).cos()).mul(s.pow2().negate().mul(n).exp());a=Xp(a.x.add(o),a.y,a.z).div(1.0685e-7);return F_.mul(a)},O_=Pp(({outsideIOR:e,eta2:t,cosTheta1:s,thinFilmThickness:i,baseF0:r})=>{const n=Mf(e,t,Rf(0,.03,i)),o=e.div(n).pow2().mul(Dp(1).sub(s.pow2())),a=Dp(1).sub(o).sqrt(),h=z_(n,e),u=HT({f0:h,f90:1,dotVH:s}),l=u.oneMinus(),c=n.lessThan(e).select(Math.PI,0),d=Dp(Math.PI).sub(c),p=(e=>{const t=e.sqrt();return Xp(1).add(t).div(Xp(1).sub(t))})(r.clamp(0,.9999)),m=z_(p,n.toVec3()),g=HT({f0:m,f90:1,dotVH:a}),f=Xp(p.x.lessThan(n).select(Math.PI,0),p.y.lessThan(n).select(Math.PI,0),p.z.lessThan(n).select(Math.PI,0)),y=n.mul(i,a,2),x=Xp(d).add(f),b=u.mul(g).clamp(1e-5,.9999),v=b.sqrt(),T=l.pow2().mul(g).div(Xp(1).sub(b));let _=u.add(T),w=T.sub(l);for(let e=1;e<=2;++e){w=w.mul(v);const t=U_(Dp(e).mul(y),Dp(e).mul(x)).mul(2);_=_.add(w.mul(t))}return _.max(Xp(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"}]}),L_=Pp(({normal:e,viewDir:t,roughness:s})=>{const i=e.dot(t).saturate(),r=s.pow2(),n=zf(s.lessThan(.25),Dp(-339.2).mul(r).add(Dp(161.4).mul(s)).sub(25.9),Dp(-8.48).mul(r).add(Dp(14.3).mul(s)).sub(9.95)),o=zf(s.lessThan(.25),Dp(44).mul(r).sub(Dp(23.7).mul(s)).add(3.26),Dp(1.97).mul(r).sub(Dp(3.27).mul(s)).add(.72));return zf(s.lessThan(.25),0,Dp(.1).mul(s).sub(.025)).add(n.mul(i).add(o).exp()).mul(1/Math.PI).saturate()}),V_=Xp(.04),D_=Dp(1);class k_ extends DT{constructor(e=!1,t=!1,s=!1,i=!1,r=!1,n=!1){super(),this.clearcoat=e,this.sheen=t,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(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=Xp().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Xp().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Xp().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Xp().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Xp().toVar("sheenSpecularIndirect")),!0===this.iridescence){const e=Mx.dot(fx).clamp();this.iridescenceFresnel=O_({outsideIOR:Dp(1),eta2:Em,cosTheta1:e,thinFilmThickness:Bm,baseF0:Um}),this.iridescenceF0=u_({f:this.iridescenceFresnel,f90:1,dotVH:e})}if(!0===this.transmission){const t=px,s=qy.sub(px).normalize(),i=Nx;e.backdrop=P_(i,s,wm,Tm,Um,Om,t,tx,Wy,ky,Wm,jm,$m,qm,this.dispersion?Xm:null),e.backdropAlpha=Hm,Tm.a.mulAssign(Mf(1,e.backdrop.a,Hm))}}computeMultiscattering(e,t,s){const i=Mx.dot(fx).clamp(),r=a_({roughness:wm,dotNV:i}),n=(this.iridescenceF0?Rm.mix(Um,this.iridescenceF0):Um).mul(r.x).add(s.mul(r.y)),o=r.x.add(r.y).oneMinus(),a=Um.add(Um.oneMinus().mul(.047619)),h=n.mul(a).div(o.mul(a).oneMinus());e.addAssign(n),t.addAssign(h.mul(o))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const i=Mx.dot(e).clamp().mul(t);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(i.mul(d_({lightDirection:e}))),!0===this.clearcoat){const s=Ax.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(s.mul(o_({lightDirection:e,f0:V_,f90:D_,roughness:Nm,normalView:Ax})))}s.directDiffuse.addAssign(i.mul(jT({diffuseColor:Tm.rgb}))),s.directSpecular.addAssign(i.mul(o_({lightDirection:e,f0:Um,f90:1,roughness:wm,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:i,reflectedLight:r,ltc_1:n,ltc_2:o}){const a=t.add(s).sub(i),h=t.sub(s).sub(i),u=t.sub(s).add(i),l=t.add(s).add(i),c=Mx,d=fx,p=gx.toVar(),m=p_({N:c,V:d,roughness:wm}),g=n.uv(m).toVar(),f=o.uv(m).toVar(),y=im(Xp(g.x,0,g.y),Xp(0,1,0),Xp(g.z,0,g.w)).toVar(),x=Um.mul(f.x).add(Um.oneMinus().mul(f.y)).toVar();r.directSpecular.addAssign(e.mul(x).mul(f_({N:c,V:d,P:p,mInv:y,p0:a,p1:h,p2:u,p3:l}))),r.directDiffuse.addAssign(e.mul(Tm).mul(f_({N:c,V:d,P:p,mInv:im(1,0,0,0,1,0,0,0,1),p0:a,p1:h,p2:u,p3:l})))}indirect(e,t,s){this.indirectDiffuse(e,t,s),this.indirectSpecular(e,t,s),this.ambientOcclusion(e,t,s)}indirectDiffuse({irradiance:e,reflectedLight:t}){t.indirectDiffuse.addAssign(e.mul(jT({diffuseColor:Tm})))}indirectSpecular({radiance:e,iblIrradiance:t,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(t.mul(Am,L_({normal:Mx,viewDir:fx,roughness:Cm}))),!0===this.clearcoat){const e=Ax.dot(fx).clamp(),t=h_({dotNV:e,specularColor:V_,specularF90:D_,roughness:Nm});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(t))}const i=Xp().toVar("singleScattering"),r=Xp().toVar("multiScattering"),n=t.mul(1/Math.PI);this.computeMultiscattering(i,r,Om);const o=i.add(r),a=Tm.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(e.mul(i)),s.indirectSpecular.addAssign(r.mul(n)),s.indirectDiffuse.addAssign(a.mul(n))}ambientOcclusion({ambientOcclusion:e,reflectedLight:t}){const s=Mx.dot(fx).clamp().add(e),i=wm.mul(-16).oneMinus().negate().exp2(),r=e.sub(s.pow(i).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(e),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(e),t.indirectDiffuse.mulAssign(e),t.indirectSpecular.mulAssign(r)}finish(e){const{outgoingLight:t}=e;if(!0===this.clearcoat){const e=Ax.dot(fx).clamp(),s=HT({dotVH:e,f0:V_,f90:D_}),i=t.mul(Mm.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(Mm));t.assign(i)}if(!0===this.sheen){const e=Am.r.max(Am.g).max(Am.b).mul(.157).oneMinus(),s=t.mul(e).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(s)}}}const G_=Dp(1),W_=Dp(-2),H_=Dp(.8),j_=Dp(-1),q_=Dp(.4),$_=Dp(2),X_=Dp(.305),Y_=Dp(3),Z_=Dp(.21),J_=Dp(4),K_=Dp(4),Q_=Dp(16),ew=Pp(([e])=>{const t=Xp(Xg(e)).toVar(),s=Dp(-1).toVar();return Op(t.x.greaterThan(t.z),()=>{Op(t.x.greaterThan(t.y),()=>{s.assign(zf(e.x.greaterThan(0),0,3))}).Else(()=>{s.assign(zf(e.y.greaterThan(0),1,4))})}).Else(()=>{Op(t.z.greaterThan(t.y),()=>{s.assign(zf(e.z.greaterThan(0),2,5))}).Else(()=>{s.assign(zf(e.y.greaterThan(0),1,4))})}),s}).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),tw=Pp(([e,t])=>{const s=Hp().toVar();return Op(t.equal(0),()=>{s.assign(Hp(e.z,e.y).div(Xg(e.x)))}).ElseIf(t.equal(1),()=>{s.assign(Hp(e.x.negate(),e.z.negate()).div(Xg(e.y)))}).ElseIf(t.equal(2),()=>{s.assign(Hp(e.x.negate(),e.y).div(Xg(e.z)))}).ElseIf(t.equal(3),()=>{s.assign(Hp(e.z.negate(),e.y).div(Xg(e.x)))}).ElseIf(t.equal(4),()=>{s.assign(Hp(e.x.negate(),e.z).div(Xg(e.y)))}).Else(()=>{s.assign(Hp(e.x,e.y).div(Xg(e.z)))}),sg(.5,s.add(1))}).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),sw=Pp(([e])=>{const t=Dp(0).toVar();return Op(e.greaterThanEqual(H_),()=>{t.assign(G_.sub(e).mul(j_.sub(W_)).div(G_.sub(H_)).add(W_))}).ElseIf(e.greaterThanEqual(q_),()=>{t.assign(H_.sub(e).mul($_.sub(j_)).div(H_.sub(q_)).add(j_))}).ElseIf(e.greaterThanEqual(X_),()=>{t.assign(q_.sub(e).mul(Y_.sub($_)).div(q_.sub(X_)).add($_))}).ElseIf(e.greaterThanEqual(Z_),()=>{t.assign(X_.sub(e).mul(J_.sub(Y_)).div(X_.sub(Z_)).add(Y_))}).Else(()=>{t.assign(Dp(-2).mul(zg(sg(1.16,e))))}),t}).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),iw=Pp(([e,t])=>{const s=e.toVar();s.assign(sg(2,s).sub(1));const i=Xp(s,1).toVar();return Op(t.equal(0),()=>{i.assign(i.zyx)}).ElseIf(t.equal(1),()=>{i.assign(i.xzy),i.xz.mulAssign(-1)}).ElseIf(t.equal(2),()=>{i.x.mulAssign(-1)}).ElseIf(t.equal(3),()=>{i.assign(i.zyx),i.xz.mulAssign(-1)}).ElseIf(t.equal(4),()=>{i.assign(i.xzy),i.xy.mulAssign(-1)}).ElseIf(t.equal(5),()=>{i.z.mulAssign(-1)}),i}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),rw=Pp(([e,t,s,i,r,n])=>{const o=Dp(s),a=Xp(t),h=Nf(sw(o),W_,n),u=kg(h),l=Lg(h),c=Xp(nw(e,a,l,i,r,n)).toVar();return Op(u.notEqual(0),()=>{const t=Xp(nw(e,a,l.add(1),i,r,n)).toVar();c.assign(Mf(c,t,u))}),c}),nw=Pp(([e,t,s,i,r,n])=>{const o=Dp(s).toVar(),a=Xp(t),h=Dp(ew(a)).toVar(),u=Dp(lf(K_.sub(o),0)).toVar();o.assign(lf(o,K_));const l=Dp(Pg(o)).toVar(),c=Hp(tw(a,h).mul(l.sub(2)).add(1)).toVar();return Op(h.greaterThan(2),()=>{c.y.addAssign(l),h.subAssign(3)}),c.x.addAssign(h.mul(l)),c.x.addAssign(u.mul(sg(3,Q_))),c.y.addAssign(sg(4,Pg(n).sub(l))),c.x.mulAssign(i),c.y.mulAssign(r),e.uv(c).grad(Hp(),Hp())}),ow=Pp(({envMap:e,mipInt:t,outputDirection:s,theta:i,axis:r,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const h=Wg(i),u=s.mul(h).add(r.cross(s).mul(Gg(i))).add(r.mul(r.dot(s).mul(h.oneMinus())));return nw(e,u,t,n,o,a)}),aw=Pp(({n:e,latitudinal:t,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=Xp(zf(t,s,yf(s,i))).toVar();Op(Ag(d.equals(Xp(0))),()=>{d.assign(Xp(i.z,0,i.x.negate()))}),d.assign(Dg(d));const p=Xp().toVar();return p.addAssign(r.element(kp(0)).mul(ow({theta:0,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c}))),wv({start:kp(1),end:e},({i:e})=>{Op(e.greaterThanEqual(n),()=>{Mv()});const t=Dp(o.mul(Dp(e))).toVar();p.addAssign(r.element(e).mul(ow({theta:t.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(e).mul(ow({theta:t,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c})))}),Kp(p,1)});let hw=null;const uw=new WeakMap;function lw(e){let t=uw.get(e);if((void 0!==t?t.pmremVersion:-1)!==e.pmremVersion){const s=e.image;if(e.isCubeTexture){if(!function(e){if(null==e)return!1;let t=0;const s=6;for(let i=0;i<s;i++)void 0!==e[i]&&t++;return t===s}(s))return null;t=hw.fromCubemap(e,t)}else{if(!function(e){return null!=e&&e.height>0}(s))return null;t=hw.fromEquirectangular(e,t)}t.pmremVersion=e.pmremVersion,uw.set(e,t)}return t.texture}class cw extends jd{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const i=new Ti;i.isRenderTargetTexture=!0,this._texture=zy(i),this._width=ym(0),this._height=ym(0),this._maxMip=ym(0),this.updateBeforeType=zd.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=function(e){const t=Math.log2(e)-2,s=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:s,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(){let e=this._pmrem;const t=e?e.pmremVersion:-1,s=this._value;t!==s.pmremVersion&&(e=!0===s.isPMREMTexture?s:lw(s),null!==e&&(this._pmrem=e,this.updateFromTexture(e)))}setup(e){null===hw&&(hw=e.createPMREMGenerator()),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this));const s=this.value;e.renderer.coordinateSystem===Ds&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(t=Xp(t.x.negate(),t.yz));let i=this.levelNode;return null===i&&e.context.getTextureLevel&&(i=e.context.getTextureLevel(this)),rw(this._texture,t,i,this._width,this._height,this._maxMip)}}const dw=Bp(cw),pw=new WeakMap;class mw extends Uv{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const e=s.isTextureNode?s.value:t[s.property];let i=pw.get(e);void 0===i&&(i=dw(e),pw.set(e,i)),s=i}const i=t.envMap?jx("envMapIntensity","float",e.material):jx("environmentIntensity","float",e.scene),r=!0===t.useAnisotropy||t.anisotropy>0?cb:Mx,n=s.context(gw(wm,r)).mul(i),o=s.context(fw(Nx)).mul(Math.PI).mul(i),a=my(n),h=my(o);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(h);const u=e.context.lightingModel.clearcoatRadiance;if(u){const e=s.context(gw(Nm,Ax)).mul(i),t=my(e);u.addAssign(t)}}}const gw=(e,t)=>{let s=null;return{getUV:()=>(null===s&&(s=fx.negate().reflect(t),s=e.mul(e).mix(s,t).normalize(),s=s.transformDirection(Wy)),s),getTextureLevel:()=>e}},fw=e=>({getUV:()=>e,getTextureLevel:()=>Dp(1)}),yw=new Nu;class xw extends yT{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(yw),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new mw(t):null}setupLightingModel(){return new k_}setupSpecular(){const e=Mf(Xp(.04),Tm.rgb,Sm);Um.assign(e),Om.assign(1)}setupVariants(){const e=this.metalnessNode?Dp(this.metalnessNode):Ib;Sm.assign(e);let t=this.roughnessNode?Dp(this.roughnessNode):Bb;t=e_({roughness:t}),wm.assign(t),this.setupSpecular(),Tm.assign(Kp(Tm.rgb.mul(e.oneMinus()),Tm.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const bw=new Au;class vw extends xw{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){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(bw),this.setValues(e)}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 e=this.iorNode?Dp(this.iorNode):qb;Wm.assign(e),Um.assign(Mf(uf(bf(Wm.sub(1).div(Wm.add(1))).mul(Cb),Xp(1)).mul(Ab),Tm.rgb,Sm)),Om.assign(Mf(Ab,1,Sm))}setupLightingModel(){return new k_(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const e=this.clearcoatNode?Dp(this.clearcoatNode):Fb,t=this.clearcoatRoughnessNode?Dp(this.clearcoatRoughnessNode):zb;Mm.assign(e),Nm.assign(e_({roughness:t}))}if(this.useSheen){const e=this.sheenNode?Xp(this.sheenNode):Lb,t=this.sheenRoughnessNode?Dp(this.sheenRoughnessNode):Vb;Am.assign(e),Cm.assign(t)}if(this.useIridescence){const e=this.iridescenceNode?Dp(this.iridescenceNode):kb,t=this.iridescenceIORNode?Dp(this.iridescenceIORNode):Gb,s=this.iridescenceThicknessNode?Dp(this.iridescenceThicknessNode):Wb;Rm.assign(e),Em.assign(t),Bm.assign(s)}if(this.useAnisotropy){const e=(this.anisotropyNode?Hp(this.anisotropyNode):Db).toVar();Pm.assign(e.length()),Op(Pm.equal(0),()=>{e.assign(Hp(1,0))}).Else(()=>{e.divAssign(Hp(Pm)),Pm.assign(Pm.saturate())}),Im.assign(Pm.pow2().mix(wm.pow2(),1)),Fm.assign(hb[0].mul(e.x).add(hb[1].mul(e.y))),zm.assign(hb[1].mul(e.x).sub(hb[0].mul(e.y)))}if(this.useTransmission){const e=this.transmissionNode?Dp(this.transmissionNode):Hb,t=this.thicknessNode?Dp(this.thicknessNode):jb,s=this.attenuationDistanceNode?Dp(this.attenuationDistanceNode):$b,i=this.attenuationColorNode?Xp(this.attenuationColorNode):Xb;if(Hm.assign(e),jm.assign(t),qm.assign(s),$m.assign(i),this.useDispersion){const e=this.dispersionNode?Dp(this.dispersionNode):tv;Xm.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Xp(this.clearcoatNormalNode):Ub}setup(e){e.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(e),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}class Tw extends k_{constructor(e,t,s,i){super(e,t,s),this.useSSS=i}direct({lightDirection:e,lightColor:t,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=e.add(Mx.mul(o)).normalize(),d=Dp(fx.dot(c.negate()).saturate().pow(u).mul(l)),p=Xp(d.add(a).mul(n));s.directDiffuse.addAssign(p.mul(h.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:s},i,r)}}class _w extends vw{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=Dp(.1),this.thicknessAmbientNode=Dp(0),this.thicknessAttenuationNode=Dp(.1),this.thicknessPowerNode=Dp(2),this.thicknessScaleNode=Dp(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new Tw(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(e){return this.thicknessColorNode=e.thicknessColorNode,this.thicknessDistortionNode=e.thicknessDistortionNode,this.thicknessAmbientNode=e.thicknessAmbientNode,this.thicknessAttenuationNode=e.thicknessAttenuationNode,this.thicknessPowerNode=e.thicknessPowerNode,this.thicknessScaleNode=e.thicknessScaleNode,super.copy(e)}}const ww=Pp(({normal:e,lightDirection:t,builder:s})=>{const i=e.dot(t),r=Hp(i.mul(.5).add(.5),0);if(s.material.gradientMap){const e=Xx("gradientMap","texture").context({getUV:()=>r});return Xp(e.r)}{const e=r.fwidth().mul(.5);return Mf(Xp(.7),Xp(1),Rf(Dp(.7).sub(e.x),Dp(.7).add(e.x),r.x))}});class Sw extends DT{direct({lightDirection:e,lightColor:t,reflectedLight:s},i,r){const n=ww({normal:vx,lightDirection:e,builder:r}).mul(t);s.directDiffuse.addAssign(n.mul(jT({diffuseColor:Tm.rgb})))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(jT({diffuseColor:Tm}))),s.indirectDiffuse.mulAssign(e)}}const Mw=new Ru;class Nw extends yT{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Mw),this.setValues(e)}setupLightingModel(){return new Sw}}class Aw extends jd{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const e=Xp(fx.z,0,fx.x.negate()).normalize(),t=fx.cross(e);return Hp(e.dot(Mx),t.dot(Mx)).mul(.495).add(.5)}}const Cw=Ip(Aw),Rw=new Fu;class Ew extends yT{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(Rw),this.setValues(e)}setupVariants(e){const t=Cw;let s;s=e.material.matcap?Xx("matcap","texture").context({getUV:()=>t}):Xp(Mf(.2,.8,t.y)),Tm.rgb.mulAssign(s.rgb)}}const Bw=new Va;class Iw extends yT{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(Bw),this.setValues(e)}copy(e){return this.sizeNode=e.sizeNode,super.copy(e)}}class Pw extends jd{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:s}=this;if("vec2"===this.getNodeType(e)){const e=t.cos(),i=t.sin();return sm(e,i,i.negate(),e).mul(s)}{const e=t,i=rm(Kp(1,0,0,0),Kp(0,Wg(e.x),Gg(e.x).negate(),0),Kp(0,Gg(e.x),Wg(e.x),0),Kp(0,0,0,1)),r=rm(Kp(Wg(e.y),0,Gg(e.y),0),Kp(0,1,0,0),Kp(Gg(e.y).negate(),0,Wg(e.y),0),Kp(0,0,0,1)),n=rm(Kp(Wg(e.z),Gg(e.z).negate(),0,0),Kp(Gg(e.z),Wg(e.z),0,0),Kp(0,0,1,0),Kp(0,0,0,1));return i.mul(r).mul(n).mul(Kp(s,1)).xyz}}}const Fw=Bp(Pw),zw=new uo;class Uw extends yT{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(zw),this.setValues(e)}setupPosition({object:e,camera:t,context:s}){const i=this.sizeAttenuation,{positionNode:r,rotationNode:n,scaleNode:o}=this,a=cx;let h=ax.mul(Xp(r||0)),u=Hp(tx[0].xyz.length(),tx[1].xyz.length());null!==o&&(u=u.mul(o)),!i&&t.isPerspectiveCamera&&(u=u.mul(h.z.negate()));let l=a.xy;if(e.center&&!0===e.center.isVector2){const e=((e,t,s)=>Cp(new ey(e,t,s)))("center","vec2");l=l.sub(e.sub(.5))}l=l.mul(u);const c=Dp(n||Ob),d=Fw(l,c);h=Kp(h.xy.add(d),h.zw);const p=ky.mul(h);return s.vertex=a,p}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}class Ow extends DT{constructor(){super(),this.shadowNode=Dp(1).toVar("shadowMask")}direct({shadowMask:e}){this.shadowNode.mulAssign(e)}finish(e){Tm.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(Tm.rgb)}}const Lw=new Su;class Vw extends yT{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Lw),this.setValues(e)}setupLightingModel(){return new Ow}}const Dw=Pp(({texture:e,uv:t})=>{const s=1e-4,i=Xp().toVar();return Op(t.x.lessThan(s),()=>{i.assign(Xp(1,0,0))}).ElseIf(t.y.lessThan(s),()=>{i.assign(Xp(0,1,0))}).ElseIf(t.z.lessThan(s),()=>{i.assign(Xp(0,0,1))}).ElseIf(t.x.greaterThan(.9999),()=>{i.assign(Xp(-1,0,0))}).ElseIf(t.y.greaterThan(.9999),()=>{i.assign(Xp(0,-1,0))}).ElseIf(t.z.greaterThan(.9999),()=>{i.assign(Xp(0,0,-1))}).Else(()=>{const s=.01,r=e.uv(t.add(Xp(-.01,0,0))).r.sub(e.uv(t.add(Xp(s,0,0))).r),n=e.uv(t.add(Xp(0,-.01,0))).r.sub(e.uv(t.add(Xp(0,s,0))).r),o=e.uv(t.add(Xp(0,0,-.01))).r.sub(e.uv(t.add(Xp(0,0,s))).r);i.assign(Xp(r,n,o))}),i.normalize()});class kw extends Fy{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Xp(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){return t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return Dw({texture:this,uv:e})}}const Gw=Bp(kw);class Ww extends yT{static get type(){return"VolumeNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(e)}setup(e){const t=Gw(this.map,null,0),s=Pp(({orig:e,dir:t})=>{const s=Xp(-.5),i=Xp(.5),r=t.reciprocal(),n=s.sub(e).mul(r),o=i.sub(e).mul(r),a=uf(n,o),h=lf(n,o),u=lf(a.x,lf(a.y,a.z)),l=uf(h.x,uf(h.y,h.z));return Hp(u,l)});this.fragmentNode=Pp(()=>{const e=Wf(Xp(ox.mul(Kp(qy,1)))),i=Wf(lx.sub(e)).normalize(),r=Hp(s({orig:e,dir:i})).toVar();r.x.greaterThan(r.y).discard(),r.assign(Hp(lf(r.x,0),r.y));const n=Xp(e.add(r.x.mul(i))).toVar(),o=Xp(i.abs().reciprocal()).toVar(),a=Dp(uf(o.x,uf(o.y,o.z))).toVar("delta");a.divAssign(Xx("steps","float"));const h=Kp(Xx("base","color"),0).toVar();return wv({type:"float",start:r.x,end:r.y,update:"+= delta"},()=>{const e=bm("float","d").assign(t.uv(n.add(.5)).r);null!==this.testNode?this.testNode({map:t,mapValue:e,probe:n,finalColor:h}).append():(h.a.assign(1),Mv()),n.addAssign(i.mul(a))}),h.a.equal(0).discard(),Kp(h)})(),super.setup(e)}}class Hw{constructor(e,t){this.nodes=e,this.info=t,this.animationLoop=null,this.requestId=null,this._init()}_init(){const e=(t,s)=>{this.requestId=self.requestAnimationFrame(e),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this.animationLoop&&this.animationLoop(t,s)};e()}dispose(){self.cancelAnimationFrame(this.requestId),this.requestId=null}setAnimationLoop(e){this.animationLoop=e}}class jw{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s<e.length;s++)if(t=t.get(e[s]),void 0===t)return;return t.get(e[e.length-1])}set(e,t){let s=this.weakMap;for(let t=0;t<e.length;t++){const i=e[t];!1===s.has(i)&&s.set(i,new WeakMap),s=s.get(i)}return s.set(e[e.length-1],t)}delete(e){let t=this.weakMap;for(let s=0;s<e.length;s++)if(t=t.get(e[s]),void 0===t)return!1;return t.delete(e[e.length-1])}}const qw=new sa;class $w{constructor(){this.version=0,this.globalClippingCount=0,this.localClippingCount=0,this.localClippingEnabled=!1,this.localClipIntersection=!1,this.planes=[],this.parentVersion=0,this.viewNormalMatrix=new ti,this.cacheKey=0}projectPlanes(e,t){const s=e.length,i=this.planes;for(let r=0;r<s;r++){qw.copy(e[r]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);const s=i[t+r],n=qw.normal;s.x=-n.x,s.y=-n.y,s.z=-n.z,s.w=qw.constant}}updateGlobal(e,t){const s=e.clippingPlanes;this.viewMatrix=t.matrixWorldInverse,this.viewNormalMatrix.getNormalMatrix(this.viewMatrix);let i=!1;if(Array.isArray(s)&&0!==s.length){const e=s.length;if(e!==this.globalClippingCount){const t=[];for(let s=0;s<e;s++)t.push(new _i);this.globalClippingCount=e,this.planes=t,i=!0}this.projectPlanes(s,0)}else 0!==this.globalClippingCount&&(this.globalClippingCount=0,this.planes=[],i=!0);e.localClippingEnabled!==this.localClippingEnabled&&(this.localClippingEnabled=e.localClippingEnabled,i=!0),i&&(this.version++,this.cacheKey=Nd(this.globalClippingCount,!0===this.localClippingEnabled?1:0))}update(e,t){let s=!1;if(this!==e&&e.version!==this.parentVersion&&(this.globalClippingCount=t.isShadowNodeMaterial?0:e.globalClippingCount,this.localClippingEnabled=e.localClippingEnabled,this.planes=Array.from(e.planes),this.parentVersion=e.version,this.viewMatrix=e.viewMatrix,this.viewNormalMatrix=e.viewNormalMatrix,s=!0),this.localClippingEnabled){const e=t.clippingPlanes;if(Array.isArray(e)&&0!==e.length){const t=e.length,i=this.planes,r=this.globalClippingCount;if(s||t!==this.localClippingCount){i.length=r+t;for(let e=0;e<t;e++)i[r+e]=new _i;this.localClippingCount=t,s=!0}this.projectPlanes(e,r)}else 0!==this.localClippingCount&&(this.localClippingCount=0,s=!0);this.localClipIntersection!==t.clipIntersection&&(this.localClipIntersection=t.clipIntersection,s=!0)}s&&(this.version+=e.version,this.cacheKey=Nd(e.cacheKey,this.localClippingCount,!0===this.localClipIntersection?1:0))}}let Xw=0;class Yw{constructor(e,t,s,i,r,n,o,a,h){this._nodes=e,this._geometries=t,this.id=Xw++,this.renderer=s,this.object=i,this.material=r,this.scene=n,this.camera=o,this.lightsNode=a,this.context=h,this.geometry=i.geometry,this.version=r.version,this.drawRange=null,this.attributes=null,this.pipeline=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.updateClipping(h.clippingContext),this.clippingContextVersion=this.clippingContext.version,this.initialNodesCacheKey=this.getDynamicCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=null,this._monitor=null,this.onDispose=null,this.isRenderObject=!0,this.onMaterialDispose=()=>{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){const t=this.material;let s=this.clippingContext;Array.isArray(t.clippingPlanes)?(s!==e&&s||(s=new $w,this.clippingContext=s),s.update(e,t)):this.clippingContext!==e&&(this.clippingContext=e)}get clippingNeedsUpdate(){return this.clippingContext.version!==this.clippingContextVersion&&(this.clippingContextVersion=this.clippingContext.version,!0)}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}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 e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],i=new Set;for(const r of e){const e=r.node&&r.node.attribute?r.node.attribute:t.getAttribute(r.name);if(void 0===e)continue;s.push(e);const n=e.isInterleavedBufferAttribute?e.data:e;i.add(n)}return this.attributes=s,this.vertexBuffers=Array.from(i.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:i,drawRange:r}=this,n=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,h=s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1;if(0===h)return null;if(n.instanceCount=h,!0===e.isBatchedMesh)return n;let u=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(u=2);let l=r.start*u,c=(r.start+r.count)*u;null!==i&&(l=Math.max(l,i.start*u),c=Math.min(c,(i.start+i.count)*u));const d=!0===a?o.count:s.attributes.position.count;l=Math.max(l,0),c=Math.min(c,d);const p=c-l;return p<0||p===1/0?null:(n.vertexCount=p,n.firstVertex=l,n)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const i=e.attributes[s];t+=s+",",i.data&&(t+=i.data.stride+","),i.offset&&(t+=i.offset+","),i.itemSize&&(t+=i.itemSize+","),i.normalized&&(t+="n,")}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const e of function(e){const t=Object.keys(e);let s=Object.getPrototypeOf(e);for(;s;){const e=Object.getOwnPropertyDescriptors(s);for(const s in e)if(void 0!==e[s]){const i=e[s];i&&"function"==typeof i.get&&t.push(s)}s=Object.getPrototypeOf(s)}return t}(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;const i=t[e];let r;if(null!==i){const e=typeof i;"number"===e?r=0!==i?"1":"0":"object"===e?(r="{",i.isTexture&&(r+=i.mapping),r+="}"):r=String(i)}else r=String(i);s+=r+","}return s+=this.clippingContext.cacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.morphTargetInfluences&&(s+=e.morphTargetInfluences.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),Sd(s)}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(e+=1),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const Zw=[];class Jw{constructor(e,t,s,i,r,n){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=i,this.bindings=r,this.info=n,this.chainMaps={}}get(e,t,s,i,r,n,o){const a=this.getChainMap(o);Zw[0]=e,Zw[1]=t,Zw[2]=n,Zw[3]=r;let h=a.get(Zw);return void 0===h?(h=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,i,r,n,o),a.set(Zw,h)):(h.updateClipping(n.clippingContext),(h.version!==t.version||h.needsUpdate)&&(h.initialCacheKey!==h.getCacheKey()?(h.dispose(),h=this.get(e,t,s,i,r,n,o)):h.version=t.version)),h}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new jw)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,i,r,n,o,a,h,u){const l=this.getChainMap(u),c=new Yw(e,t,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 Kw{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Qw=1,eS=2,tS=4,sS=16;class iS extends Kw{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return void 0!==t&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(void 0===s.version)t===Qw?this.backend.createAttribute(e):t===eS?this.backend.createIndexAttribute(e):t===tS&&this.backend.createStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const t=this._getBufferAttribute(e);(s.version<t.version||t.usage===Es)&&(this.backend.updateAttribute(e),s.version=t.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}function rS(e){return null!==e.index?e.index.version:e.attributes.position.version}function nS(e){const t=[],s=e.index,i=e.attributes.position;if(null!==s){const e=s.array;for(let s=0,i=e.length;s<i;s+=3){const i=e[s+0],r=e[s+1],n=e[s+2];t.push(i,r,r,n,n,i)}}else{for(let e=0,s=i.array.length/3-1;e<s;e+=3){const s=e+0,i=e+1,r=e+2;t.push(s,i,i,r,r,s)}}const r=new(function(e){for(let t=e.length-1;t>=0;--t)if(e[t]>=65535)return!0;return!1}(t)?xn:fn)(t,1);return r.version=rS(e),r}class oS extends Kw{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const i=t.index,r=e.getAttributes();null!==i&&this.attributes.delete(i);for(const e of r)this.attributes.delete(e);const n=this.wireframes.get(t);void 0!==n&&this.attributes.delete(n),t.removeEventListener("dispose",s)};t.addEventListener("dispose",s)}updateAttributes(e){const t=e.getAttributes();for(const e of t)e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute?this.updateAttribute(e,tS):this.updateAttribute(e,Qw);const s=this.getIndex(e);null!==s&&this.updateAttribute(s,eS)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndex(e){const{geometry:t,material:s}=e;let i=t.index;if(!0===s.wireframe){const e=this.wireframes;let s=e.get(t);void 0===s?(s=nS(t),e.set(t,s)):s.version!==rS(t)&&(this.attributes.delete(s),s=nS(t),e.set(t,s)),i=s}return i}}class aS{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(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(e,t){0===this[e].timestampCalls&&(this[e].timestamp=0),this[e].timestamp+=t,this[e].timestampCalls++,this[e].timestampCalls>=this[e].previousFrameCalls&&(this[e].timestampCalls=0)}reset(){const e=this.render.frameCalls;this.render.previousFrameCalls=e;const t=this.compute.frameCalls;this.compute.previousFrameCalls=t,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 hS{constructor(e){this.cacheKey=e,this.usedTimes=0}}class uS extends hS{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class lS extends hS{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let cS=0;class dS{constructor(e,t,s=null,i=null){this.id=cS++,this.code=e,this.stage=t,this.transforms=s,this.attributes=i,this.usedTimes=0}}class pS extends Kw{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,i=this.get(e);if(this._needsComputeUpdate(e)){const r=i.pipeline;r&&(r.usedTimes--,r.computeProgram.usedTimes--);const n=this.nodes.getForCompute(e);let o=this.programs.compute.get(n.computeShader);void 0===o&&(r&&0===r.computeProgram.usedTimes&&this._releaseProgram(r.computeProgram),o=new dS(n.computeShader,"compute",n.transforms,n.nodeAttributes),this.programs.compute.set(n.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(e,o);let h=this.caches.get(a);void 0===h&&(r&&0===r.usedTimes&&this._releasePipeline(r),h=this._getComputePipeline(e,o,a,t)),h.usedTimes++,o.usedTimes++,i.version=e.version,i.pipeline=h}return i.pipeline}getForRender(e,t=null){const{backend:s}=this,i=this.get(e);if(this._needsRenderUpdate(e)){const r=i.pipeline;r&&(r.usedTimes--,r.vertexProgram.usedTimes--,r.fragmentProgram.usedTimes--);const n=e.getNodeBuilderState();let o=this.programs.vertex.get(n.vertexShader);void 0===o&&(r&&0===r.vertexProgram.usedTimes&&this._releaseProgram(r.vertexProgram),o=new dS(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 dS(n.fragmentShader,"fragment"),this.programs.fragment.set(n.fragmentShader,a),s.createProgram(a));const h=this._getRenderCacheKey(e,o,a);let u=this.caches.get(h);void 0===u?(r&&0===r.usedTimes&&this._releasePipeline(r),u=this._getRenderPipeline(e,o,a,h,t)):e.pipeline=u,u.usedTimes++,o.usedTimes++,a.usedTimes++,i.pipeline=u}return i.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,i){s=s||this._getComputeCacheKey(e,t);let r=this.caches.get(s);return void 0===r&&(r=new lS(s,t),this.caches.set(s,r),this.backend.createComputePipeline(r,i)),r}_getRenderPipeline(e,t,s,i,r){i=i||this._getRenderCacheKey(e,t,s);let n=this.caches.get(i);return void 0===n&&(n=new uS(i,t,s),this.caches.set(i,n),e.pipeline=n,this.backend.createRenderPipeline(e,r)),n}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class mS extends Kw{constructor(e,t,s,i,r,n){super(),this.backend=e,this.textures=s,this.pipelines=r,this.attributes=i,this.nodes=t,this.info=n,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t),s.bindGroup=e)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t),s.bindGroup=e)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const e=t.attribute;this.attributes.update(e,tS)}}_update(e,t){const{backend:s}=this;let i=!1;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&s.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){t.needsBindingsUpdate(this.textures.get(t.texture).generation)&&(i=!0);const e=t.update(),r=t.texture;e&&this.textures.updateTexture(r);const n=s.get(r);if(!0===s.isWebGPUBackend&&void 0===n.texture&&void 0===n.externalTexture&&(console.error("Bindings._update: binding should be available:",t,e,r,t.textureNode.value,i),this.textures.updateTexture(r),i=!0),!0===r.isStorageTexture){const e=this.get(r);!0===t.store?e.needsMipmap=!0:!0===r.generateMipmaps&&this.textures.needsMipmaps(r)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(r),e.needsMipmap=!1)}}}!0===i&&this.backend.updateBindings(e,t)}}class gS{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}}class fS{constructor(e,t,s){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=s.getSelf()}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class yS{constructor(e,t){this.isNodeVar=!0,this.name=e,this.type=t}}class xS extends yS{constructor(e,t){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0}}class bS{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let vS=0;class TS{constructor(e=null){this.id=vS++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class _S extends xm{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const wS=(e,t)=>Cp(new _S(e,t));class SS extends Gd{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.code=e,this.language=s,this.includes=t}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const s of t)s.build(e);const s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}const MS=Bp(SS),NS=(e,t)=>MS(e,t,"js"),AS=(e,t)=>MS(e,t,"wgsl"),CS=(e,t)=>MS(e,t,"glsl");class RS extends SS{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let s=t.nodeFunction;return void 0===s&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),i=s.name,r=s.type,n=e.getCodeFromNode(this,r);""!==i&&(n.name=i);const o=e.getPropertyName(n),a=this.getNodeFunction(e).getCode(o);return n.code=a+"\n","property"===t?o:e.format(`${o}()`,r,t)}}const ES=(e,t=[],s="")=>{for(let e=0;e<t.length;e++){const s=t[e];"function"==typeof s&&(t[e]=s.functionNode)}const i=Cp(new RS(e,t,s)),r=(...e)=>i.call(...e);return r.functionNode=i,r},BS=(e,t)=>ES(e,t,"glsl"),IS=(e,t)=>ES(e,t,"wgsl");class PS{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0}setValue(e){this.value=e}getValue(){return this.value}}class FS extends PS{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class zS extends PS{constructor(e,t=new ei){super(e,t),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class US extends PS{constructor(e,t=new Ei){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class OS extends PS{constructor(e,t=new _i){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class LS extends PS{constructor(e,t=new Kr){super(e,t),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class VS extends PS{constructor(e,t=new ti){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class DS extends PS{constructor(e,t=new or){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class kS extends FS{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class GS extends zS{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class WS extends US{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class HS extends OS{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class jS extends LS{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class qS extends VS{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class $S extends DS{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class XS extends Gd{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}add(e){return this.nodes.push(e),this}If(e,t){const s=new Ap(t);return this._currentCond=zf(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new Ap(t),i=zf(e,s);return this._currentCond.elseNode=i,this._currentCond=i,this}Else(e){return this._currentCond.elseNode=new Ap(e),this}build(e,...t){const s=Up();zp(this);for(const t of this.nodes)t.build(e,"void");return zp(s),this.outputNode?this.outputNode.build(e,...t):super.build(e,...t)}else(...e){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...e)}elseif(...e){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...e)}}const YS=Bp(XS),ZS=[.125,.215,.35,.446,.526,.582],JS=20,KS=new Cl(-1,1,1,-1,0,1),QS=new Kn(90,1),eM=new Kr;let tM=null,sM=0,iM=0;const rM=(1+Math.sqrt(5))/2,nM=1/rM,oM=[new Ei(-rM,nM,0),new Ei(rM,nM,0),new Ei(-nM,0,rM),new Ei(nM,0,rM),new Ei(0,rM,-nM),new Ei(0,rM,nM),new Ei(-1,1,-1),new Ei(1,1,-1),new Ei(-1,1,1),new Ei(1,1,1)],aM=[3,1,5,0,4,2],hM=iw(Ry(),Cy("faceIndex")).normalize(),uM=Xp(hM.x,hM.y.negate(),hM.z);class lM{constructor(e){this._renderer=e,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(e,t=0,s=.1,i=100){tM=this._renderer.getRenderTarget(),sM=this._renderer.getActiveCubeFace(),iM=this._renderer.getActiveMipmapLevel(),this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(e,s,i,r),t>0&&this._blur(r,0,0,t),this._applyPMREM(r),this._cleanup(r),r}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=mM(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=gM(),await 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(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodPlanes.length;e++)this._lodPlanes[e].dispose()}_cleanup(e){this._renderer.setRenderTarget(tM,sM,iM),e.scissorTest=!1,dM(e,0,0,e.width,e.height)}_fromTexture(e,t){e.mapping===he||e.mapping===ue?this._setSize(0===e.image.length?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4),tM=this._renderer.getRenderTarget(),sM=this._renderer.getActiveCubeFace(),iM=this._renderer.getActiveMipmapLevel();const s=t||this._allocateTargets();return this._textureToCubeUV(e,s),this._applyPMREM(s),this._cleanup(s),s}_allocateTargets(){const e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize,s={magFilter:Te,minFilter:Te,generateMipmaps:!1,type:Pe,format:ke,colorSpace:Kt},i=cM(e,t,s);if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==e||this._pingPongRenderTarget.height!==t){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=cM(e,t,s);const{_lodMax:i}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas,lodMeshes:this._lodMeshes}=function(e){const t=[],s=[],i=[],r=[];let n=e;const o=e-4+1+ZS.length;for(let a=0;a<o;a++){const o=Math.pow(2,n);s.push(o);let h=1/o;a>e-4?h=ZS[a-e+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 e=0;e<p;e++){const t=e%3*2/3-1,s=e>2?0:-1,i=[t,s,0,t+2/3,s,0,t+2/3,s+1,0,t,s,0,t+2/3,s+1,0,t,s+1,0],r=aM[e];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 Cn;T.setAttribute("position",new cn(x,g)),T.setAttribute("uv",new cn(b,f)),T.setAttribute("faceIndex",new cn(v,y)),t.push(T),r.push(new Dn(T,null)),n>4&&n--}return{lodPlanes:t,sizeLods:s,sigmas:i,lodMeshes:r}}(i)),this._blurMaterial=function(e,t,s){const i=kx(new Array(JS).fill(0)),r=ym(new Ei(0,1,0)),n=ym(0),o=Dp(JS),a=ym(0),h=ym(1),u=zy(null),l=ym(0),c=Dp(1/t),d=Dp(1/s),p=Dp(e),m={n:o,latitudinal:a,weights:i,poleAxis:r,outputDirection:uM,dTheta:n,samples:h,envMap:u,mipInt:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:p},g=pM("blur");return g.uniforms=m,g.fragmentNode=aw({...m,latitudinal:a.equal(1)}),g}(i,e,t)}return i}async _compileMaterial(e){const t=new Dn(this._lodPlanes[0],e);await this._renderer.compile(t,KS)}_sceneToCubeUV(e,t,s,i){const r=QS;r.near=t,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(eM),a.autoClear=!1;let u=this._backgroundBox;if(null===u){const e=new sn({name:"PMREM.Background",side:1,depthWrite:!1,depthTest:!1});u=new Dn(new Gn,e)}let l=!1;const c=e.background;c?c.isColor&&(u.material.color.copy(c),e.background=null,l=!0):(u.material.color.copy(eM),l=!0),a.setRenderTarget(i),a.clear(),l&&a.render(u,r);for(let t=0;t<6;t++){const s=t%3;0===s?(r.up.set(0,n[t],0),r.lookAt(o[t],0,0)):1===s?(r.up.set(0,0,n[t]),r.lookAt(0,o[t],0)):(r.up.set(0,n[t],0),r.lookAt(0,0,o[t]));const h=this._cubeSize;dM(i,s*h,t>2?h:0,h,h),a.render(e,r)}a.autoClear=h,e.background=c}_textureToCubeUV(e,t){const s=this._renderer,i=e.mapping===he||e.mapping===ue;i?null===this._cubemapMaterial&&(this._cubemapMaterial=mM(e)):null===this._equirectMaterial&&(this._equirectMaterial=gM(e));const r=i?this._cubemapMaterial:this._equirectMaterial;r.fragmentNode.value=e;const n=this._lodMeshes[0];n.material=r;const o=this._cubeSize;dM(t,0,0,3*o,2*o),s.setRenderTarget(t),s.render(n,KS)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const i=this._lodPlanes.length;for(let t=1;t<i;t++){const s=Math.sqrt(this._sigmas[t]*this._sigmas[t]-this._sigmas[t-1]*this._sigmas[t-1]),r=oM[(i-t-1)%oM.length];this._blur(e,t-1,t,s,r)}t.autoClear=s}_blur(e,t,s,i,r){const n=this._pingPongRenderTarget;this._halfBlur(e,n,t,s,i,"latitudinal",r),this._halfBlur(n,e,s,s,i,"longitudinal",r)}_halfBlur(e,t,s,i,r,n,o){const a=this._renderer,h=this._blurMaterial;"latitudinal"!==n&&"longitudinal"!==n&&console.error("blur direction must be either latitudinal or longitudinal!");const u=this._lodMeshes[i];u.material=h;const l=h.uniforms,c=this._sizeLods[s]-1,d=isFinite(r)?Math.PI/(2*c):2*Math.PI/39,p=r/d,m=isFinite(r)?1+Math.floor(3*p):JS;m>JS&&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 e=0;e<JS;++e){const t=e/p,s=Math.exp(-t*t/2);g.push(s),0===e?f+=s:e<m&&(f+=2*s)}for(let e=0;e<g.length;e++)g[e]=g[e]/f;e.texture.frame=(e.texture.frame||0)+1,l.envMap.value=e.texture,l.samples.value=m,l.weights.array=g,l.latitudinal.value="latitudinal"===n?1:0,o&&(l.poleAxis.value=o);const{_lodMax:y}=this;l.dTheta.value=d,l.mipInt.value=y-s;const x=this._sizeLods[i];dM(t,3*x*(i>y-4?i-y+4:0),4*(this._cubeSize-x),3*x,2*x),a.setRenderTarget(t),a.render(u,KS)}}function cM(e,t,s){const i=new wi(e,t,s);return i.texture.mapping=de,i.texture.name="PMREM.cubeUv",i.texture.isPMREMTexture=!0,i.scissorTest=!0,i}function dM(e,t,s,i,r){e.viewport.set(t,s,i,r),e.scissor.set(t,s,i,r)}function pM(e){const t=new yT;return t.depthTest=!1,t.depthWrite=!1,t.blending=0,t.name=`PMREM_${e}`,t}function mM(e){const t=pM("cubemap");return t.fragmentNode=Ux(e,uM),t}function gM(e){const t=pM("equirect");return t.fragmentNode=zy(e,BT(uM),0),t}let fM=0;class yM{constructor(e="",t=[],s=0,i=[]){this.name=e,this.bindings=t,this.index=s,this.bindingsReference=i,this.id=fM++}}const xM=new WeakMap,bM=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),vM=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),TM=e=>(e=Number(e))+(e%1?"":".0");class _M{constructor(e,t,s){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,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=YS(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new TS,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let e=xM.get(this.renderer);return void 0===e&&(e=new jw,xM.set(this.renderer,e)),e}createRenderTarget(e,t,s){return new wi(e,t,s)}createCubeRenderTarget(e,t){return new IT(e,t)}createPMREMGenerator(){return new lM(this.renderer)}includes(e){return this.nodes.includes(e)}_getBindGroup(e,t){const s=this.getBindGroupsCache(),i=[];let r,n=!0;for(const e of t)i.push(e),n=n&&!0!==e.groupNode.shared;return n?(r=s.get(i),void 0===r&&(r=new yM(e,i,this.bindingsIndexes[e].group,i),s.set(i,r))):r=new yM(e,i,this.bindingsIndexes[e].group,i),r}getBindGroupArray(e,t){const s=this.bindings[t];let i=s[e];return void 0===i&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=i=[]),i}getBindings(){let e=this.bindGroups;if(null===e){const t={},s=this.bindings;for(const e of Vd)for(const i in s[e]){const r=s[e][i];(t[i]||(t[i]=[])).push(...r)}e=[];for(const s in t){const i=t[s],r=this._getBindGroup(s,i);e.push(r)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort((e,t)=>e.bindings[0].groupNode.order-t.bindings[0].groupNode.order);for(let t=0;t<e.length;t++){const s=e[t];this.bindingsIndexes[s.name].group=t,s.index=t}}setHashNode(e,t){this.hashNodes[t]=e}addNode(e){!1===this.nodes.includes(e)&&(this.nodes.push(e),this.setHashNode(e,e.getHash(this)))}buildUpdateNodes(){for(const e of this.nodes){const t=e.getUpdateType(),s=e.getUpdateBeforeType(),i=e.getUpdateAfterType();t!==zd.NONE&&this.updateNodes.push(e.getSelf()),s!==zd.NONE&&this.updateBeforeNodes.push(e.getSelf()),i!==zd.NONE&&this.updateAfterNodes.push(e.getSelf())}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(e){return e.magFilter===Te||e.magFilter===_e||e.magFilter===be||e.magFilter===Se||e.minFilter===Te||e.minFilter===_e||e.minFilter===be||e.minFilter===Se}addChain(e){this.chaining.push(e)}removeChain(e){if(this.chaining.pop()!==e)throw new Error("NodeBuilder: Invalid node chaining!")}getMethod(e){return e}getNodeFromHash(e){return this.hashNodes[e]}addFlow(e,t){return this.flowNodes[e].push(t),t}setContext(e){this.context=e}getContext(){return this.context}getSharedContext(){return this.context,this.context}setCache(e){this.cache=e}getCache(){return this.cache}getCacheFromNode(e,t=!0){const s=this.getDataFromNode(e);return void 0===s.cache&&(s.cache=new TS(t?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}increaseUsage(e){const t=this.getDataFromNode(e);return t.usageCount=void 0===t.usageCount?1:t.usageCount+1,t.usageCount}generateTexture(){console.warn("Abstract function.")}generateTextureLod(){console.warn("Abstract function.")}generateConst(e,t=null){if(null===t&&("float"===e||"int"===e||"uint"===e?t=0:"bool"===e?t=!1:"color"===e?t=new Kr:"vec2"===e?t=new ei:"vec3"===e?t=new Ei:"vec4"===e&&(t=new _i)),"float"===e)return TM(t);if("int"===e)return`${Math.round(t)}`;if("uint"===e)return t>=0?`${Math.round(t)}u`:"0u";if("bool"===e)return t?"true":"false";if("color"===e)return`${this.getType("vec3")}( ${TM(t.r)}, ${TM(t.g)}, ${TM(t.b)} )`;const s=this.getTypeLength(e),i=this.getComponentType(e),r=e=>this.generateConst(i,e);if(2===s)return`${this.getType(e)}( ${r(t.x)}, ${r(t.y)} )`;if(3===s)return`${this.getType(e)}( ${r(t.x)}, ${r(t.y)}, ${r(t.z)} )`;if(4===s)return`${this.getType(e)}( ${r(t.x)}, ${r(t.y)}, ${r(t.z)}, ${r(t.w)} )`;if(s>4&&t&&(t.isMatrix3||t.isMatrix4))return`${this.getType(e)}( ${t.elements.map(r).join(", ")} )`;if(s>4)return`${this.getType(e)}()`;throw new Error(`NodeBuilder: Type '${e}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){const s=this.attributes;for(const t of s)if(t.name===e)return t;const i=new gS(e,t);return s.push(i),i}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===Ee)return"int";if(t===Be)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;const s=bM.get(e);return("float"===t?"":t[0])+s}getTypeFromArray(e){return vM.get(e.constructor)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const s=t.array,i=e.itemSize,r=e.normalized;let n;return e instanceof bn||!0===r||(n=this.getTypeFromArray(s)),this.getTypeFromLength(i,n)}getTypeLength(e){const t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return null!==s?Number(s[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:!0===/mat4/.test(e)?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}addStack(){return this.stack=YS(this.stack),this.stacks.push(Up()||this.stack),zp(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,zp(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){let i=(s=null===s?e.isGlobal(this)?this.globalCache:this.cache:s).getData(e);return void 0===i&&(i={},s.setData(e,i)),void 0===i[t]&&(i[t]={}),i[t]}getNodeProperties(e,t="any"){const s=this.getDataFromNode(e,t);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const s=this.getDataFromNode(e);let i=s.bufferAttribute;if(void 0===i){const r=this.uniforms.index++;i=new gS("nodeAttribute"+r,t,e),this.bufferAttributes.push(i),s.bufferAttribute=i}return i}getStructTypeFromNode(e,t=this.shaderStage){const s=this.getDataFromNode(e,t);if(void 0===s.structType){const i=this.structs.index++;e.name=`StructType${i}`,this.structs[t].push(e),s.structType=e}return e}getUniformFromNode(e,t,s=this.shaderStage,i=null){"in"===i&&(console.warn('NodeBuilder: "in" is a reserved word, using "inValue" instead.',e,i),e.name="inValue",i=e.name);const r=this.getDataFromNode(e,s,this.globalCache);let n=r.uniform;if(void 0===n){const o=this.uniforms.index++;n=new fS(i||"nodeUniform"+o,t,e),this.uniforms[s].push(n),r.uniform=n}return n}getVarFromNode(e,t=null,s=e.getNodeType(this),i=this.shaderStage){const r=this.getDataFromNode(e,i);let n=r.variable;if(void 0===n){const e=this.vars[i]||(this.vars[i]=[]);null===t&&(t="nodeVar"+e.length),n=new yS(t,s),e.push(n),r.variable=n}return n}getVaryingFromNode(e,t=null,s=e.getNodeType(this)){const i=this.getDataFromNode(e,"any");let r=i.varying;if(void 0===r){const e=this.varyings,n=e.length;null===t&&(t="nodeVarying"+n),r=new xS(t,s),e.push(r),i.varying=r}return r}getCodeFromNode(e,t,s=this.shaderStage){const i=this.getDataFromNode(e);let r=i.code;if(void 0===r){const e=this.codes[s]||(this.codes[s]=[]),n=e.length;r=new bS("nodeCode"+n,t),e.push(r),i.code=r}return r}addFlowCodeHierarchy(e,t){const{flowCodes:s,flowCodeBlock:i}=this.getDataFromNode(e);let r=!0,n=t;for(;n;){if(!0===i.get(n)){r=!1;break}n=this.getDataFromNode(n).parentNodeBlock}if(r)for(const e of s)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,s){const i=this.getDataFromNode(e),r=i.flowCodes||(i.flowCodes=[]),n=i.flowCodeBlock||(i.flowCodeBlock=new WeakMap);r.push(t),n.set(s,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),s=this.flowChildNode(e,t);return this.flowsData.set(e,s),s}buildFunctionNode(e){const t=new RS,s=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=s,t}flowShaderNode(e){const t=e.layout,s={[Symbol.iterator](){let e=0;const t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(const e of t.inputs)s[e.name]=new _S(e.type,e.name);e.layout=null;const i=e.call(s),r=this.flowStagesNode(i,t.type);return e.layout=t,r}flowStagesNode(e,t=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 TS,this.stack=YS();for(const s of Ld)this.setBuildStage(s),a.result=e.build(this,t);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(e,t=null){const s=this.flow,i={code:""};return this.flow=i,i.result=e.build(this,t),this.flow=s,i}flowNodeFromShaderStage(e,t,s=null,i=null){const r=this.shaderStage;this.setShaderStage(e);const n=this.flowChildNode(t,s);return null!==i&&(n.code+=`${this.tab+i} = ${n.result};\n`),this.flowCode[e]=this.flowCode[e]+n.code,this.setShaderStage(r),n}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(e,t){return`${this.getType(e)} ${t}`}getVars(e){let t="";const s=this.vars[e];if(void 0!==s)for(const e of s)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){const t=this.codes[e];let s="";if(void 0!==t)for(const e of t)s+=e.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:e,material:t,renderer:s}=this;if(null!==t){let e=s.nodes.library.fromMaterial(t);null===e&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new yT),e.build(this)}else this.addFlow("compute",e);for(const e of Ld){this.setBuildStage(e),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const t of Vd){this.setShaderStage(t);const s=this.flowNodes[t];for(const t of s)"generate"===e?this.flowNode(t):t.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if("float"===t||"int"===t||"uint"===t)return new kS(e);if("vec2"===t||"ivec2"===t||"uvec2"===t)return new GS(e);if("vec3"===t||"ivec3"===t||"uvec3"===t)return new WS(e);if("vec4"===t||"ivec4"===t||"uvec4"===t)return new HS(e);if("color"===t)return new jS(e);if("mat3"===t)return new qS(e);if("mat4"===t)return new $S(e);throw new Error(`Uniform "${t}" not declared.`)}createNodeMaterial(e="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}format(e,t,s){if((t=this.getVectorType(t))===(s=this.getVectorType(s))||null===s||this.isReference(s))return e;const i=this.getTypeLength(t),r=this.getTypeLength(s);return 16===i&&9===r?`${this.getType(s)}(${e}[0].xyz, ${e}[1].xyz, ${e}[2].xyz)`:9===i&&4===r?`${this.getType(s)}(${e}[0].xy, ${e}[1].xy)`:i>4||r>4||0===r?e:i===r?`${this.getType(s)}( ${e} )`:i>r?this.format(`${e}.${"xyz".slice(0,r)}`,this.getTypeFromLength(r,this.getComponentType(t)),s):4===r&&i>1?`${this.getType(s)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===i?`${this.getType(s)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===i&&r>1&&t!==this.getComponentType(s)&&(e=`${this.getType(this.getComponentType(s))}( ${e} )`),`${this.getType(s)}( ${e} )`)}getSignature(){return`// Three.js r${e} - Node System\n`}}class wM{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(e,t){let s=e.get(t);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,s)),s}updateBeforeNode(e){const t=e.getUpdateBeforeType(),s=e.updateReference(this);if(t===zd.FRAME){const{frameMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.frameId&&!1!==e.updateBefore(this)&&t.set(s,this.frameId)}else if(t===zd.RENDER){const{renderMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.renderId&&!1!==e.updateBefore(this)&&t.set(s,this.renderId)}else t===zd.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),s=e.updateReference(this);if(t===zd.FRAME){const{frameMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.frameId&&!1!==e.updateAfter(this)&&t.set(s,this.frameId)}else if(t===zd.RENDER){const{renderMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.renderId&&!1!==e.updateAfter(this)&&t.set(s,this.renderId)}else t===zd.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),s=e.updateReference(this);if(t===zd.FRAME){const{frameMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.frameId&&!1!==e.update(this)&&t.set(s,this.frameId)}else if(t===zd.RENDER){const{renderMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.renderId&&!1!==e.update(this)&&t.set(s,this.renderId)}else t===zd.OBJECT&&e.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 SM{constructor(e,t,s=null,i="",r=!1){this.type=e,this.name=t,this.count=s,this.qualifier=i,this.isConst=r}}SM.isNodeFunctionInput=!0;class MM extends Gd{static get type(){return"StructTypeNode"}constructor(e){super(),this.types=e,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}class NM extends Gd{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}setup(e){super.setup(e);const t=this.members,s=[];for(let i=0;i<t.length;i++)s.push(t[i].getNodeType(e));this.nodeType=e.getStructTypeFromNode(new MM(s)).name}generate(e,t){const s=e.getOutputStructName(),i=this.members,r=""!==s?s+".":"";for(let s=0;s<i.length;s++){const n=i[s].build(e,t);e.addLineFlowCode(`${r}m${s} = ${n}`,this)}return s}}const AM=Bp(NM);function CM(e,t){for(let s=0;s<e.length;s++)if(e[s].name===t)return s;return-1}class RM extends NM{static get type(){return"MRTNode"}constructor(e){super(),this.outputNodes=e,this.isMRTNode=!0}has(e){return void 0!==this.outputNodes[e]}get(e){return this.outputNodes[e]}merge(e){const t={...this.outputNodes,...e.outputNodes};return EM(t)}setup(e){const t=this.outputNodes,s=[],i=e.renderer.getRenderTarget().textures;for(const e in t){s[CM(i,e)]=Kp(t[e])}return this.members=s,super.setup(e)}}const EM=Bp(RM);class BM extends Gd{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(e){const t=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(t.length===o.length){let n=0;for(let s=0;s<t.length;s++){const i=t[s],r=o[s];i.getNodeType(e)===r.type?n++:n=0}n>r&&(i=s,r=n)}}this._candidateFnCall=s=i(...t)}return s}}const IM=Bp(BM),PM=e=>(...t)=>IM(e,...t);class FM extends fm{static get type(){return"TimerNode"}constructor(e=FM.LOCAL,t=1,s=0){super(s),this.scope=e,this.scale=t,this.updateType=zd.FRAME}update(e){const t=this.scope,s=this.scale;t===FM.LOCAL?this.value+=e.deltaTime*s:t===FM.DELTA?this.value=e.deltaTime*s:t===FM.FRAME?this.value=e.frameId:this.value=e.time*s}serialize(e){super.serialize(e),e.scope=this.scope,e.scale=this.scale}deserialize(e){super.deserialize(e),this.scope=e.scope,this.scale=e.scale}}FM.LOCAL="local",FM.GLOBAL="global",FM.DELTA="delta",FM.FRAME="frame";const zM=(e,t=0)=>Cp(new FM(FM.LOCAL,e,t)),UM=(e,t=0)=>Cp(new FM(FM.GLOBAL,e,t)),OM=(e,t=0)=>Cp(new FM(FM.DELTA,e,t)),LM=Ip(FM,FM.FRAME).toUint();class VM extends Gd{static get type(){return"OscNode"}constructor(e=VM.SINE,t=zM()){super(),this.method=e,this.timeNode=t}getNodeType(e){return this.timeNode.getNodeType(e)}setup(){const e=this.method,t=Cp(this.timeNode);let s=null;return e===VM.SINE?s=t.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5):e===VM.SQUARE?s=t.fract().round():e===VM.TRIANGLE?s=t.add(.5).fract().mul(2).sub(1).abs():e===VM.SAWTOOTH&&(s=t.fract()),s}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}VM.SINE="sine",VM.SQUARE="square",VM.TRIANGLE="triangle",VM.SAWTOOTH="sawtooth";const DM=Bp(VM,VM.SINE),kM=Bp(VM,VM.SQUARE),GM=Bp(VM,VM.TRIANGLE),WM=Bp(VM,VM.SAWTOOTH);class HM extends Gd{static get type(){return"SpriteSheetUVNode"}constructor(e,t=Ry(),s=Dp(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=s}setup(){const{frameNode:e,uvNode:t,countNode:s}=this,{width:i,height:r}=s,n=e.mod(i.mul(r)).floor(),o=n.mod(i),a=r.sub(n.add(1).div(i).ceil()),h=s.reciprocal(),u=Hp(o,a);return t.add(u).mul(h)}}const jM=Bp(HM);class qM extends Wd{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.bufferObject&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let s;const i=e.context.assign;if(s=!1===e.isAvailable("storageBuffer")?!0===this.node.bufferObject&&!0!==i?e.generatePBO(this):this.node.build(e):super.generate(e),!0!==i){const i=this.getNodeType(e);s=e.format(s,i,t)}return s}}const $M=Bp(qM);class XM extends Gd{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,s=null,i=Dp(1),r=cx,n=Tx){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=s,this.scaleNode=i,this.positionNode=r,this.normalNode=n}setup(){const{textureXNode:e,textureYNode:t,textureZNode:s,scaleNode:i,positionNode:r,normalNode:n}=this;let o=n.abs().normalize();o=o.div(o.dot(Xp(1)));const a=r.yz.mul(i),h=r.zx.mul(i),u=r.xy.mul(i),l=e.value,c=null!==t?t.value:l,d=null!==s?s.value:l,p=zy(l,a).mul(o.x),m=zy(c,h).mul(o.y),g=zy(d,u).mul(o.z);return eg(p,m,g)}}const YM=Bp(XM),ZM=(...e)=>YM(...e),JM=new sa,KM=new Ei,QM=new Ei,eN=new Ei,tN=new or,sN=new Ei(0,0,-1),iN=new _i,rN=new Ei,nN=new Ei,oN=new _i,aN=new ei,hN=new wi,uN=Hv.flipX();let lN=!1;class cN extends Fy{static get type(){return"ReflectorNode"}constructor(e={}){super(hN.texture,uN);const{target:t=new Pr,resolution:s=1,generateMipmaps:i=!1,bounces:r=!0}=e;this.target=t,this.resolution=s,this.generateMipmaps=i,this.bounces=r,this.updateBeforeType=r?zd.RENDER:zd.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(e,t){const s=this.resolution;t.getDrawingBufferSize(aN),e.setSize(Math.round(aN.width*s),Math.round(aN.height*s))}setup(e){return this._updateResolution(hN,e.renderer),super.setup(e)}getTextureNode(){return this.textureNode}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new wi(0,0,{type:Pe}),!0===this.generateMipmaps&&(t.texture.minFilter=1008,t.texture.generateMipmaps=!0),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&lN)return!1;lN=!0;const{scene:t,camera:s,renderer:i,material:r}=e,{target:n}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(i.getDrawingBufferSize(aN),this._updateResolution(a,i),QM.setFromMatrixPosition(n.matrixWorld),eN.setFromMatrixPosition(s.matrixWorld),tN.extractRotation(n.matrixWorld),KM.set(0,0,1),KM.applyMatrix4(tN),rN.subVectors(QM,eN),rN.dot(KM)>0)return;rN.reflect(KM).negate(),rN.add(QM),tN.extractRotation(s.matrixWorld),sN.set(0,0,-1),sN.applyMatrix4(tN),sN.add(eN),nN.subVectors(QM,sN),nN.reflect(KM).negate(),nN.add(QM),o.coordinateSystem=s.coordinateSystem,o.position.copy(rN),o.up.set(0,1,0),o.up.applyMatrix4(tN),o.up.reflect(KM),o.lookAt(nN),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),JM.setFromNormalAndCoplanarPoint(KM,QM),JM.applyMatrix4(o.matrixWorldInverse),iN.set(JM.normal.x,JM.normal.y,JM.normal.z,JM.constant);const h=o.projectionMatrix;oN.x=(Math.sign(iN.x)+h.elements[8])/h.elements[0],oN.y=(Math.sign(iN.y)+h.elements[9])/h.elements[5],oN.z=-1,oN.w=(1+h.elements[10])/h.elements[14],iN.multiplyScalar(1/iN.dot(oN));h.elements[2]=iN.x,h.elements[6]=iN.y,h.elements[10]=iN.z-0,h.elements[14]=iN.w,this.value=a.texture,r.visible=!1;const u=i.getRenderTarget(),l=i.getMRT();i.setMRT(null),i.setRenderTarget(a),i.render(t,o),i.setMRT(l),i.setRenderTarget(u),r.visible=!0,lN=!1}}const dN=e=>Cp(new cN(e)),pN=new Cl(-1,1,1,-1,0,1);class mN extends Cn{constructor(e=!1){super();const t=!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new vn([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new vn(t,2))}}const gN=new mN;class fN extends Dn{constructor(e=null){super(gN,e),this.camera=pN,this.isQuadMesh=!0}renderAsync(e){return e.renderAsync(this,pN)}render(e){e.render(this,pN)}}const yN=new ei;class xN extends Fy{static get type(){return"RTTNode"}constructor(e,t=null,s=null,i={type:Pe}){const r=new wi(t,s,i);super(r.texture,Ry()),this.node=e,this.width=t,this.height=s,this.renderTarget=r,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new fN(new yT),this.updateBeforeType=zd.RENDER}get autoSize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;const s=e*this.pixelRatio,i=t*this.pixelRatio;this.renderTarget.setSize(s,i),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=e.getPixelRatio();const t=e.getSize(yN);this.setSize(t.width,t.height)}this._quadMesh.material.fragmentNode=this._rttNode;const t=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){const e=new Fy(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const bN=(e,...t)=>Cp(new xN(Cp(e),...t)),vN=(e,...t)=>e.isTextureNode?e:bN(e,...t);class TN extends Ay{static get type(){return"VertexColorNode"}constructor(e=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e);let s;return s=!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new _i(1,1,1,1)),s}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const _N=(...e)=>Cp(new TN(...e));class wN extends Gd{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const SN=Ip(wN);class MN extends Gd{static get type(){return"SceneNode"}constructor(e=MN.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=null!==this.scene?this.scene:e.scene;let i;return t===MN.BACKGROUND_BLURRINESS?i=jx("backgroundBlurriness","float",s):t===MN.BACKGROUND_INTENSITY?i=jx("backgroundIntensity","float",s):console.error("THREE.SceneNode: Unknown scope:",t),i}}MN.BACKGROUND_BLURRINESS="backgroundBlurriness",MN.BACKGROUND_INTENSITY="backgroundIntensity";const NN=Ip(MN,MN.BACKGROUND_BLURRINESS),AN=Ip(MN,MN.BACKGROUND_INTENSITY),CN="point-list",RN="line-list",EN="line-strip",BN="triangle-list",IN="triangle-strip",PN="never",FN="less",zN="equal",UN="less-equal",ON="greater",LN="not-equal",VN="greater-equal",DN="always",kN="store",GN="load",WN="clear",HN="ccw",jN="none",qN="front",$N="back",XN="uint16",YN="uint32",ZN={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",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",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",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"},JN="clamp-to-edge",KN="repeat",QN="mirror-repeat",eA="linear",tA="nearest",sA="zero",iA="one",rA="src",nA="one-minus-src",oA="src-alpha",aA="one-minus-src-alpha",hA="dst",uA="one-minus-dst",lA="dst-alpha",cA="one-minus-dst-alpha",dA="src-alpha-saturated",pA="constant",mA="one-minus-constant",gA="add",fA="subtract",yA="reverse-subtract",xA="min",bA="max",vA=0,TA=15,_A="keep",wA="zero",SA="replace",MA="invert",NA="increment-clamp",AA="decrement-clamp",CA="increment-wrap",RA="decrement-wrap",EA="storage",BA="read-only-storage",IA="write-only",PA="read-only",FA="float",zA="unfilterable-float",UA="depth",OA="sint",LA="uint",VA="2d",DA="3d",kA="2d",GA="2d-array",WA="cube",HA="3d",jA="all",qA="vertex",$A="instance",XA={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",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups"};class YA extends Ox{static get type(){return"StorageBufferNode"}constructor(e,t,s=0){super(e,t,s),this.isStorageBufferNode=!0,this.access=EA,this.isAtomic=!1,this.bufferObject=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return"storageBuffer"}element(e){return $M(this,e)}setBufferObject(e){return this.bufferObject=e,this}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(BA)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}generate(e){if(e.isAvailable("storageBuffer"))return super.generate(e);const t=this.getNodeType(e);null===this._attribute&&(this._attribute=ay(this.value),this._varying=Wf(this._attribute));const s=this._varying.build(e,t);return e.registerTransform(s,this._attribute),s}}const ZA=(e,t,s)=>Cp(new YA(e,t,s)),JA=(e,t,s)=>Cp(new YA(e,t,s).setBufferObject(!0));class KA extends Fy{static get type(){return"StorageTextureNode"}constructor(e,t,s=null){super(e,t),this.storeNode=s,this.isStorageTextureNode=!0,this.access=IA}getInputType(){return"storageTexture"}setup(e){super.setup(e);e.getNodeProperties(this).storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){let s;return s=null!==this.storeNode?this.generateStore(e):super.generate(e,t),s}toReadOnly(){return this.setAccess(PA)}toWriteOnly(){return this.setAccess(IA)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:s,storeNode:i}=t,r=super.generate(e,"property"),n=s.build(e,"uvec2"),o=i.build(e,"vec4"),a=e.generateTextureStore(e,r,n,o);e.addLineFlowCode(a,this)}}const QA=Bp(KA),eC=(e,t,s)=>{const i=QA(e,t,s);return null!==s&&i.append(),i};class tC extends Hx{static get type(){return"UserDataNode"}constructor(e,t,s=null){super(e,t,s),this.userData=s}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}const sC=(e,t,s)=>Cp(new tC(e,t,s));class iC extends jd{static get type(){return"PosterizeNode"}constructor(e,t){super(),this.sourceNode=e,this.stepsNode=t}setup(){const{sourceNode:e,stepsNode:t}=this;return e.mul(t).floor().div(t)}}const rC=Bp(iC);let nC=null;class oC extends tT{static get type(){return"ViewportSharedTextureNode"}constructor(e=Hv,t=null){null===nC&&(nC=new Xa),super(e,t,nC)}updateReference(){return this}}const aC=Bp(oC),hC=new ei;class uC extends Fy{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.setUpdateMatrix(!1)}setup(e){return e.object.isQuadMesh&&this.passNode.build(e),super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class lC extends uC{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class cC extends jd{static get type(){return"PassNode"}constructor(e,t,s,i={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;const r=new Qa;r.isRenderTargetTexture=!0,r.name="depth";const n=new wi(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:Pe,...i});n.texture.name="output",n.depthTexture=r,this.renderTarget=n,this.updateBeforeType=zd.FRAME,this._textures={output:n.texture,depth:r},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=ym(0),this._cameraFar=ym(0),this._mrt=null,this.isPassNode=!0}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(e){let t=this._textures[e];if(void 0===t){t=this.renderTarget.texture.clone(),t.isRenderTargetTexture=!0,t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)}return t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),t.isRenderTargetTexture=!0,this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(void 0!==t){const s=this._textures[e],i=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[i]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&(this._textureNodes[e]=t=Cp(new lC(this,e)),this._textureNodes[e].updateTexture()),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),this._previousTextureNodes[e]=t=Cp(new lC(this,e,!0)),this._previousTextureNodes[e].updateTexture()),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){const s=this._cameraNear,i=this._cameraFar;this._viewZNodes[e]=t=cT(this.getTextureNode(e),s,i)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){const s=this._cameraNear,i=this._cameraFar,r=this.getViewZNode(e);this._linearDepthNodes[e]=t=hT(r,s,i)}return t}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,!0===e.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===cC.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s,camera:i}=this;this._pixelRatio=t.getPixelRatio();const r=t.getSize(hC);this.setSize(r.width,r.height);const n=t.getRenderTarget(),o=t.getMRT();this._cameraNear.value=i.near,this._cameraFar.value=i.far;for(const e in this._previousTextures)this.toggleTexture(e);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,i),t.setRenderTarget(n),t.setMRT(o)}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio,i=this._height*this._pixelRatio;this.renderTarget.setSize(s,i)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}cC.COLOR="color",cC.DEPTH="depth";const dC=(e,t,s)=>Cp(new cC(cC.COLOR,e,t,s)),pC=(e,t)=>Cp(new uC(e,t)),mC=(e,t)=>Cp(new cC(cC.DEPTH,e,t)),gC=new fN,fC=new fN;class yC extends jd{static get type(){return"GaussianBlurNode"}constructor(e,t=null,s=2){super("vec4"),this.textureNode=e,this.directionNode=t,this.sigma=s,this._invSize=ym(new ei),this._passDirection=ym(new ei),this._horizontalRT=new wi,this._horizontalRT.texture.name="GaussianBlurNode.horizontal",this._verticalRT=new wi,this._verticalRT.texture.name="GaussianBlurNode.vertical",this._textureNode=pC(this,this._verticalRT.texture),this.updateBeforeType=zd.RENDER,this.resolution=new ei(1,1)}setSize(e,t){e=Math.max(Math.round(e*this.resolution.x),1),t=Math.max(Math.round(t*this.resolution.y),1),this._invSize.value.set(1/e,1/t),this._horizontalRT.setSize(e,t),this._verticalRT.setSize(e,t)}updateBefore(e){const{renderer:t}=e,s=this.textureNode,i=s.value,r=t.getRenderTarget(),n=t.getMRT(),o=s.value;gC.material=this._material,fC.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,t.setMRT(null),t.setRenderTarget(this._horizontalRT),this._passDirection.value.set(1,0),gC.render(t),s.value=this._horizontalRT.texture,t.setRenderTarget(this._verticalRT),this._passDirection.value.set(0,1),fC.render(t),t.setRenderTarget(r),t.setMRT(n),s.value=o}getTextureNode(){return this._textureNode}setup(e){const t=this.textureNode;if(!0!==t.isTextureNode)return console.error("GaussianBlurNode requires a TextureNode."),Kp();const s=t.uvNode||Ry(),i=Hp(this.directionNode||1),r=e=>t.uv(e),n=Pp(()=>{const e=3+2*this.sigma,t=this._getCoefficients(e),n=this._invSize,o=i.mul(this._passDirection),a=Dp(t[0]).toVar(),h=Kp(r(s).mul(a)).toVar();for(let i=1;i<e;i++){const e=Dp(i),u=Dp(t[i]),l=Hp(o.mul(n.mul(e))).toVar(),c=Kp(r(s.add(l))),d=Kp(r(s.sub(l)));h.addAssign(c.add(d).mul(u)),a.addAssign(sg(2,u))}return h.div(a)}),o=this._material||(this._material=new yT);o.fragmentNode=n().context(e.getSharedContext()),o.name="Gaussian_blur",o.needsUpdate=!0;return e.getNodeProperties(this).textureNode=t,this._textureNode}dispose(){this._horizontalRT.dispose(),this._verticalRT.dispose()}_getCoefficients(e){const t=[];for(let s=0;s<e;s++)t.push(.39894*Math.exp(-.5*s*s/(e*e))/e);return t}}const xC=(e,t,s)=>Cp(new yC(vN(e),t,s)),bC=new ei,vC=new fN;class TC extends jd{static get type(){return"AfterImageNode"}constructor(e,t=.96){super(e),this.textureNode=e,this.textureNodeOld=zy(),this.damp=ym(t),this._compRT=new wi,this._compRT.texture.name="AfterImageNode.comp",this._oldRT=new wi,this._oldRT.texture.name="AfterImageNode.old",this._textureNode=pC(this,this._compRT.texture),this.updateBeforeType=zd.RENDER}getTextureNode(){return this._textureNode}setSize(e,t){this._compRT.setSize(e,t),this._oldRT.setSize(e,t)}updateBefore(e){const{renderer:t}=e,s=this.textureNode,i=s.value.type;this._compRT.texture.type=i,this._oldRT.texture.type=i,t.getDrawingBufferSize(bC),this.setSize(bC.x,bC.y);const r=t.getRenderTarget(),n=s.value;this.textureNodeOld.value=this._oldRT.texture,t.setRenderTarget(this._compRT),vC.render(t);const o=this._oldRT;this._oldRT=this._compRT,this._compRT=o,t.setRenderTarget(r),s.value=n}setup(e){const t=this.textureNode,s=this.textureNodeOld,i=t.uvNode||Ry();s.uvNode=i;const r=Pp(([e,t])=>{const s=Dp(t).toVar(),i=Kp(e).toVar();return lf(Yg(i.sub(s)),0)}),n=Pp(()=>{const e=Kp(s),n=Kp((e=>t.uv(e))(i));return e.mulAssign(this.damp.mul(r(e,.1))),lf(n,e)}),o=this._materialComposed||(this._materialComposed=new yT);o.name="AfterImage",o.fragmentNode=n(),vC.material=o;return e.getNodeProperties(this).textureNode=t,this._textureNode}dispose(){this._compRT.dispose(),this._oldRT.dispose()}}const _C=(e,t)=>Cp(new TC(vN(e),t)),wC=Pp(([e])=>CC(e.rgb)),SC=Pp(([e,t=Dp(1)])=>t.mix(CC(e.rgb),e.rgb)),MC=Pp(([e,t=Dp(1)])=>{const s=eg(e.r,e.g,e.b).div(3),i=e.r.max(e.g.max(e.b)),r=i.sub(s).mul(t).mul(-3);return Mf(e.rgb,i,r)}),NC=Pp(([e,t=Dp(1)])=>{const s=Xp(.57735,.57735,.57735),i=t.cos();return Xp(e.rgb.mul(i).add(s.cross(e.rgb).mul(t.sin()).add(s.mul(ff(s,e.rgb).mul(i.oneMinus())))))}),AC=new Ei,CC=(e,t=Xp(...di.getLuminanceCoefficients(AC)))=>ff(e,t),RC=(e,t)=>Mf(Xp(0),e,CC(e).sub(t).max(0)),EC=new fN;class BC extends jd{static get type(){return"AnamorphicNode"}constructor(e,t,s,i){super("vec4"),this.textureNode=e,this.tresholdNode=t,this.scaleNode=s,this.colorNode=Xp(.1,0,1),this.samples=i,this.resolution=new ei(1,1),this._renderTarget=new wi,this._renderTarget.texture.name="anamorphic",this._invSize=ym(new ei),this._textureNode=pC(this,this._renderTarget.texture),this.updateBeforeType=zd.RENDER}getTextureNode(){return this._textureNode}setSize(e,t){this._invSize.value.set(1/e,1/t),e=Math.max(Math.round(e*this.resolution.x),1),t=Math.max(Math.round(t*this.resolution.y),1),this._renderTarget.setSize(e,t)}updateBefore(e){const{renderer:t}=e,s=this.textureNode,i=s.value;this._renderTarget.texture.type=i.type;const r=t.getRenderTarget(),n=s.value;EC.material=this._material,this.setSize(i.image.width,i.image.height),t.setRenderTarget(this._renderTarget),EC.render(t),t.setRenderTarget(r),s.value=n}setup(e){const t=this.textureNode,s=t.uvNode||Ry(),i=Pp(()=>{const e=this.samples,i=Math.floor(e/2),r=Xp(0).toVar();return wv({start:-i,end:i},({i:e})=>{const n=Dp(e).abs().div(i).oneMinus(),o=(e=>t.uv(e))(Hp(s.x.add(this._invSize.x.mul(e).mul(this.scaleNode)),s.y)),a=RC(o,this.tresholdNode).mul(n);r.addAssign(a)}),r.mul(this.colorNode)}),r=this._material||(this._material=new yT);r.name="Anamorphic",r.fragmentNode=i();return e.getNodeProperties(this).textureNode=t,this._textureNode}dispose(){this._renderTarget.dispose()}}const IC=(e,t=.9,s=3,i=32)=>Cp(new BC(vN(e),Cp(t),Cp(s),i));class PC extends jd{static get type(){return"SobelOperatorNode"}constructor(e){super(),this.textureNode=e,this.updateBeforeType=zd.RENDER,this._invSize=ym(new ei)}updateBefore(){const e=this.textureNode.value;this._invSize.value.set(1/e.image.width,1/e.image.height)}setup(){const{textureNode:e}=this,t=e.uvNode||Ry(),s=t=>e.uv(t);return Pp(()=>{const e=this._invSize,i=im(-1,-2,-1,0,0,0,1,2,1),r=im(-1,0,1,-2,0,2,-1,0,1),n=CC(s(t.add(e.mul(Hp(-1,-1)))).xyz),o=CC(s(t.add(e.mul(Hp(-1,0)))).xyz),a=CC(s(t.add(e.mul(Hp(-1,1)))).xyz),h=CC(s(t.add(e.mul(Hp(0,-1)))).xyz),u=CC(s(t.add(e.mul(Hp(0,0)))).xyz),l=CC(s(t.add(e.mul(Hp(0,1)))).xyz),c=CC(s(t.add(e.mul(Hp(1,-1)))).xyz),d=CC(s(t.add(e.mul(Hp(1,0)))).xyz),p=CC(s(t.add(e.mul(Hp(1,1)))).xyz),m=eg(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=eg(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 Kp(Xp(f),1)})()}}const FC=e=>Cp(new PC(vN(e)));class zC extends jd{static get type(){return"DepthOfFieldNode"}constructor(e,t,s,i,r){super(),this.textureNode=e,this.viewZNode=t,this.focusNode=s,this.apertureNode=i,this.maxblurNode=r,this._aspect=ym(0),this.updateBeforeType=zd.RENDER}updateBefore(){const e=this.textureNode.value;this._aspect.value=e.image.width/e.image.height}setup(){const e=this.textureNode,t=e.uvNode||Ry(),s=t=>e.uv(t);return Pp(()=>{const e=Hp(1,this._aspect),i=this.focusNode.add(this.viewZNode),r=Hp(Nf(i.mul(this.apertureNode),this.maxblurNode.negate(),this.maxblurNode)),n=r.mul(.9),o=r.mul(.7),a=r.mul(.4);let h=Kp(0);return h=h.add(s(t)),h=h.add(s(t.add(Hp(0,.4).mul(e).mul(r)))),h=h.add(s(t.add(Hp(.15,.37).mul(e).mul(r)))),h=h.add(s(t.add(Hp(.29,.29).mul(e).mul(r)))),h=h.add(s(t.add(Hp(-.37,.15).mul(e).mul(r)))),h=h.add(s(t.add(Hp(.4,0).mul(e).mul(r)))),h=h.add(s(t.add(Hp(.37,-.15).mul(e).mul(r)))),h=h.add(s(t.add(Hp(.29,-.29).mul(e).mul(r)))),h=h.add(s(t.add(Hp(-.15,-.37).mul(e).mul(r)))),h=h.add(s(t.add(Hp(0,-.4).mul(e).mul(r)))),h=h.add(s(t.add(Hp(-.15,.37).mul(e).mul(r)))),h=h.add(s(t.add(Hp(-.29,.29).mul(e).mul(r)))),h=h.add(s(t.add(Hp(.37,.15).mul(e).mul(r)))),h=h.add(s(t.add(Hp(-.4,0).mul(e).mul(r)))),h=h.add(s(t.add(Hp(-.37,-.15).mul(e).mul(r)))),h=h.add(s(t.add(Hp(-.29,-.29).mul(e).mul(r)))),h=h.add(s(t.add(Hp(.15,-.37).mul(e).mul(r)))),h=h.add(s(t.add(Hp(.15,.37).mul(e).mul(n)))),h=h.add(s(t.add(Hp(-.37,.15).mul(e).mul(n)))),h=h.add(s(t.add(Hp(.37,-.15).mul(e).mul(n)))),h=h.add(s(t.add(Hp(-.15,-.37).mul(e).mul(n)))),h=h.add(s(t.add(Hp(-.15,.37).mul(e).mul(n)))),h=h.add(s(t.add(Hp(.37,.15).mul(e).mul(n)))),h=h.add(s(t.add(Hp(-.37,-.15).mul(e).mul(n)))),h=h.add(s(t.add(Hp(.15,-.37).mul(e).mul(n)))),h=h.add(s(t.add(Hp(.29,.29).mul(e).mul(o)))),h=h.add(s(t.add(Hp(.4,0).mul(e).mul(o)))),h=h.add(s(t.add(Hp(.29,-.29).mul(e).mul(o)))),h=h.add(s(t.add(Hp(0,-.4).mul(e).mul(o)))),h=h.add(s(t.add(Hp(-.29,.29).mul(e).mul(o)))),h=h.add(s(t.add(Hp(-.4,0).mul(e).mul(o)))),h=h.add(s(t.add(Hp(-.29,-.29).mul(e).mul(o)))),h=h.add(s(t.add(Hp(0,.4).mul(e).mul(o)))),h=h.add(s(t.add(Hp(.29,.29).mul(e).mul(a)))),h=h.add(s(t.add(Hp(.4,0).mul(e).mul(a)))),h=h.add(s(t.add(Hp(.29,-.29).mul(e).mul(a)))),h=h.add(s(t.add(Hp(0,-.4).mul(e).mul(a)))),h=h.add(s(t.add(Hp(-.29,.29).mul(e).mul(a)))),h=h.add(s(t.add(Hp(-.4,0).mul(e).mul(a)))),h=h.add(s(t.add(Hp(-.29,-.29).mul(e).mul(a)))),h=h.add(s(t.add(Hp(0,.4).mul(e).mul(a)))),h=h.div(41),h.a=1,Kp(h)})()}}const UC=(e,t,s=1,i=.025,r=1)=>Cp(new zC(vN(e),Cp(t),Cp(s),Cp(i),Cp(r)));class OC extends jd{static get type(){return"DotScreenNode"}constructor(e,t=new ei(.5,.5),s=1.57,i=1){super("vec4"),this.inputNode=e,this.center=ym(t),this.angle=ym(s),this.scale=ym(i)}setup(){const e=this.inputNode,t=Pp(()=>{const e=Gg(this.angle),t=Wg(this.angle),s=Ry().mul(jv).sub(this.center),i=Hp(t.mul(s.x).sub(e.mul(s.y)),e.mul(s.x).add(t.mul(s.y))).mul(this.scale);return Gg(i.x).mul(Gg(i.y)).mul(4)}),s=Pp(()=>{const s=e,i=eg(s.r,s.g,s.b).div(3);return Kp(Xp(i.mul(10).sub(5).add(t())),s.a)});return s()}}const LC=(e,t,s,i)=>Cp(new OC(Cp(e),t,s,i));class VC extends jd{static get type(){return"RGBShiftNode"}constructor(e,t=.005,s=0){super("vec4"),this.textureNode=e,this.amount=ym(t),this.angle=ym(s)}setup(){const{textureNode:e}=this,t=e.uvNode||Ry(),s=t=>e.uv(t);return Pp(()=>{const e=Hp(Wg(this.angle),Gg(this.angle)).mul(this.amount),i=s(t.add(e)),r=s(t),n=s(t.sub(e));return Kp(i.r,r.g,n.b,r.a)})()}}const DC=(e,t,s)=>Cp(new VC(vN(e),t,s));class kC extends jd{static get type(){return"FilmNode"}constructor(e,t=null,s=null){super(),this.inputNode=e,this.intensityNode=t,this.uvNode=s}setup(){const e=this.uvNode||Ry(),t=Pp(()=>{const t=this.inputNode.rgb,s=Bf(kg(e.add(zM())));let i=t.add(t.mul(Nf(s.add(.1),0,1)));return null!==this.intensityNode&&(i=Mf(t,i,this.intensityNode)),Kp(i,this.inputNode.a)});return t()}}const GC=Bp(kC);class WC extends jd{static get type(){return"Lut3DNode"}constructor(e,t,s,i){super(),this.inputNode=e,this.lutNode=t,this.size=ym(s),this.intensityNode=i}setup(){const{inputNode:e,lutNode:t}=this,s=Pp(()=>{const s=e,i=Dp(1).div(this.size),r=Dp(.5).div(this.size),n=Xp(r).add(s.rgb.mul(Dp(1).sub(i))),o=Kp((e=>t.uv(e))(n).rgb,s.a);return Kp(Mf(s,o,this.intensityNode))});return s()}}const HC=(e,t,s,i)=>Cp(new WC(Cp(e),Cp(t),s,Cp(i))),jC=new fN,qC=new Kr,$C=new ei;class XC extends jd{static get type(){return"GTAONode"}constructor(e,t,s){super(),this.depthNode=e,this.normalNode=t,this.radius=ym(.25),this.resolution=ym(new ei),this.thickness=ym(1),this.distanceExponent=ym(1),this.distanceFallOff=ym(1),this.scale=ym(1),this.noiseNode=zy(function(e=5){const t=Math.floor(e)%2==0?Math.floor(e)+1:Math.floor(e),s=function(e){const t=Math.floor(e)%2==0?Math.floor(e)+1:Math.floor(e),s=t*t,i=Array(s).fill(0);let r=Math.floor(t/2),n=t-1;for(let e=1;e<=s;)-1===r&&n===t?(n=t-2,r=0):(n===t&&(n=0),r<0&&(r=t-1)),0===i[r*t+n]?(i[r*t+n]=e++,n++,r--):(n-=2,r++);return i}(t),i=s.length,r=new Uint8Array(4*i);for(let e=0;e<i;++e){const t=s[e],n=2*Math.PI*t/i,o=new Ei(Math.cos(n),Math.sin(n),0).normalize();r[4*e]=255*(.5*o.x+.5),r[4*e+1]=255*(.5*o.y+.5),r[4*e+2]=127,r[4*e+3]=255}const n=new Do(r,t,t);return n.wrapS=pe,n.wrapT=pe,n.needsUpdate=!0,n}()),this.cameraProjectionMatrix=ym(s.projectionMatrix),this.cameraProjectionMatrixInverse=ym(s.projectionMatrixInverse),this.SAMPLES=ym(16),this._aoRenderTarget=new wi,this._aoRenderTarget.texture.name="GTAONode.AO",this._material=null,this._textureNode=pC(this,this._aoRenderTarget.texture),this.updateBeforeType=zd.FRAME}getTextureNode(){return this._textureNode}setSize(e,t){this.resolution.value.set(e,t),this._aoRenderTarget.setSize(e,t)}updateBefore(e){const{renderer:t}=e,s=t.getDrawingBufferSize($C),i=t.getRenderTarget(),r=t.getMRT();t.getClearColor(qC);const n=t.getClearAlpha();jC.material=this._material,this.setSize(s.width,s.height),t.setMRT(null),t.setClearColor(16777215,1),t.setRenderTarget(this._aoRenderTarget),jC.render(t),t.setRenderTarget(i),t.setMRT(r),t.setClearColor(qC,n)}setup(e){const t=Ry(),s=e=>this.depthNode.uv(e).x,i=e=>this.noiseNode.uv(e),r=Pp(([e])=>{const t=this.cameraProjectionMatrix.mul(Kp(e,1));let i=t.xy.div(t.w).mul(.5).add(.5).toVar();i=Hp(i.x,i.y.oneMinus());const r=s(i);return Xp(i,r)}),n=Pp(([e,t])=>{e=Hp(e.x,e.y.oneMinus()).mul(2).sub(1);const s=Kp(Xp(e,t),1),i=Kp(this.cameraProjectionMatrixInverse.mul(s));return i.xyz.div(i.w)}),o=Pp(()=>{const e=s(t);e.greaterThanEqual(1).discard();const o=n(t,e),a=this.normalNode.rgb.normalize(),h=this.radius,u=By(this.noiseNode,0);let l=Hp(t.x,t.y.oneMinus());l=l.mul(this.resolution.div(u));const c=i(l),d=c.xyz.mul(2).sub(1),p=Xp(d.xy,0).normalize(),m=Xp(p.y.mul(-1),p.x,0),g=im(p,m,Xp(0,0,1)),f=this.SAMPLES.lessThan(30).select(3,5),y=eg(this.SAMPLES,f.sub(1)).div(f),x=Dp(0).toVar();return wv({start:kp(0),end:f,type:"int",condition:"<"},({i:e})=>{const t=Dp(e).div(Dp(f)).mul(Mg),s=Kp(Wg(t),Gg(t),0,eg(.5,sg(.5,c.w)));s.xyz=Dg(g.mul(s.xyz));const i=Dg(o.xyz.negate()),u=Dg(yf(s.xyz,i)),l=yf(u,i),d=Dg(a.sub(u.mul(ff(a,u)))),p=yf(d,u),m=Hp(ff(i,p),ff(i,p.negate())).toVar();wv({end:y,type:"int",name:"j",condition:"<"},({j:e})=>{const t=s.xyz.mul(h).mul(s.w).mul(xf(ig(Dp(e).add(1),Dp(y)),this.distanceExponent)),a=r(o.add(t)),u=n(a.xy,a.z).sub(o);Op(Xg(u.z).lessThan(this.thickness),()=>{const t=ff(i,Dg(u));m.x.addAssign(lf(0,sg(t.sub(m.x),Mf(1,Dp(2).div(Dp(e).add(2)),this.distanceFallOff))))});const l=r(o.sub(t)),c=n(l.xy,l.z).sub(o);Op(Xg(c.z).lessThan(this.thickness),()=>{const t=ff(i,Dg(c));m.y.addAssign(lf(0,sg(t.sub(m.y),Mf(1,Dp(2).div(Dp(e).add(2)),this.distanceFallOff))))})});const b=Ug(tg(1,m.mul(m))),v=ff(d,l),T=ff(d,i),_=sg(.5,qg(m.y).sub(qg(m.x)).add(b.x.mul(m.x).sub(b.y.mul(m.y)))),w=sg(.5,tg(2,m.x.mul(m.x)).sub(m.y.mul(m.y))),S=v.mul(_).add(T.mul(w));x.addAssign(S)}),x.assign(Nf(x.div(f),0,1)),x.assign(xf(x,this.scale)),Kp(Xp(x),1)}),a=this._material||(this._material=new yT);return a.fragmentNode=o().context(e.getSharedContext()),a.name="GTAO",a.needsUpdate=!0,this._textureNode}dispose(){this._aoRenderTarget.dispose()}}const YC=(e,t,s)=>Cp(new XC(Cp(e),Cp(t),s));class ZC extends jd{static get type(){return"DenoiseNode"}constructor(e,t,s,i,r){super(),this.textureNode=e,this.depthNode=t,this.normalNode=s,this.noiseNode=i,this.cameraProjectionMatrixInverse=ym(r.projectionMatrixInverse),this.lumaPhi=ym(5),this.depthPhi=ym(5),this.normalPhi=ym(5),this.radius=ym(5),this.index=ym(0),this._resolution=ym(new ei),this._sampleVectors=kx(function(e,t,s){const i=function(e,t,s){const i=[];for(let r=0;r<e;r++){const n=2*Math.PI*t*r/e,o=Math.pow(r/(e-1),s);i.push(new Ei(Math.cos(n),Math.sin(n),o))}return i}(e,t,s),r=[];for(let t=0;t<e;t++){const e=i[t];r.push(e)}return r}(16,2,1)),this.updateBeforeType=zd.RENDER}updateBefore(){const e=this.textureNode.value;this._resolution.value.set(e.image.width,e.image.height)}setup(){const e=Ry(),t=e=>this.textureNode.uv(e),s=e=>this.depthNode.uv(e).x,i=e=>this.normalNode.uv(e),r=e=>this.noiseNode.uv(e),n=Pp(([e,t])=>{e=Hp(e.x,e.y.oneMinus()).mul(2).sub(1);const s=Kp(Xp(e,t),1),i=Kp(this.cameraProjectionMatrixInverse.mul(s));return i.xyz.div(i.w)}),o=Pp(([e,r,o,a])=>{const h=t(a),u=s(a),l=i(a).rgb.normalize(),c=h.rgb,d=n(a,u),p=ff(r,l).toVar(),m=xf(lf(p,0),this.normalPhi).toVar(),g=Xg(CC(c).sub(CC(e))).toVar(),f=lf(Dp(1).sub(g.div(this.lumaPhi)),0).toVar(),y=Xg(ff(o.sub(d),r)).toVar(),x=lf(Dp(1).sub(y.div(this.depthPhi)),0),b=f.mul(x).mul(m);return Kp(c.mul(b),b)}),a=Pp(([e])=>{const a=s(e),h=i(e).rgb.normalize(),u=t(e);Op(a.greaterThanEqual(1).or(ff(h,h).equal(0)),()=>u);const l=Xp(u.rgb),c=n(e,a),d=By(this.noiseNode,0);let p=Hp(e.x,e.y.oneMinus());p=p.mul(this._resolution.div(d));const m=r(p),g=Gg(m.element(this.index.mod(4).mul(2).mul(Mg))),f=Wg(m.element(this.index.mod(4).mul(2).mul(Mg))),y=Hp(g,f),x=sm(y.x,y.y.negate(),y.x,y.y),b=Dp(1).toVar(),v=Xp(u.rgb).toVar();return wv({start:kp(0),end:kp(16),type:"int",condition:"<"},({i:t})=>{const s=this._sampleVectors.element(t).toVar(),i=x.mul(s.xy.mul(Dp(1).add(s.z.mul(this.radius.sub(1))))).div(this._resolution).toVar(),r=e.add(i).toVar(),n=o(l,h,c,r);v.addAssign(n.xyz),b.addAssign(n.w)}),Op(b.greaterThan(Dp(0)),()=>{v.divAssign(b)}),Kp(v,u.a)}).setLayout({name:"denoise",type:"vec4",inputs:[{name:"uv",type:"vec2"}]});return Pp(()=>a(e))()}}const JC=(e,t,s,i,r)=>Cp(new ZC(vN(e),Cp(t),Cp(s),Cp(i),r));class KC extends jd{static get type(){return"FXAANode"}constructor(e){super(),this.textureNode=e,this.updateBeforeType=zd.RENDER,this._invSize=ym(new ei)}updateBefore(){const e=this.textureNode.value;this._invSize.value.set(1/e.image.width,1/e.image.height)}setup(){const e=this.textureNode.bias(-100),t=e.uvNode||Ry(),s=t=>e.uv(t),i=(t,s,i)=>e.uv(t.add(s.mul(i))),r=kp(5),n=Pp(([e,t])=>{const s=Kp(t).toVar(),i=Kp(e).toVar(),r=Kp(Xg(i.sub(s))).toVar();return lf(lf(lf(r.r,r.g),r.b),r.a)}),o=Pp(([e,t,o,a])=>{const h=s(e).toVar(),u=i(e,Hp(0,-1),t.xy).toVar(),l=i(e,Hp(1,0),t.xy).toVar(),c=i(e,Hp(0,1),t.xy).toVar(),d=i(e,Hp(-1,0),t.xy).toVar(),p=n(h,c).toVar(),m=n(h,u).toVar(),g=n(h,l).toVar(),f=n(h,d).toVar(),y=lf(p,lf(m,lf(g,f))).toVar();Op(y.lessThan(o),()=>h);const x=tg(p.add(m),g.add(f)).toVar();x.mulAssign(a),Op(Xg(x).lessThan(.3),()=>{const s=g.greaterThan(f).select(1,-1).toVar(),r=m.greaterThan(p).select(1,-1).toVar(),o=Hp(s,r).toVar(),y=i(e,Hp(o.x,o.y),t.xy),b=n(h,y).toVar(),v=i(e,Hp(o.x.negate(),o.y.negate()),t.xy),T=n(h,v).toVar();x.assign(T.sub(b)),x.mulAssign(a),Op(Xg(x).lessThan(.3),()=>{const e=c.add(u).add(l).add(d);return Mf(h,e.mul(.25),.4)})});const b=Hp().toVar();Op(x.lessThanEqual(0),()=>{c.assign(d),u.assign(l),b.x.assign(0),b.y.assign(t.y)}).Else(()=>{b.x.assign(t.x),b.y.assign(0)});const v=n(h,c).toVar(),T=n(h,u).toVar();Op(v.lessThanEqual(T),()=>{c.assign(u)});const _=kp(0).toVar(),w=kp(0).toVar(),S=Dp(0).toVar(),M=Dp(0).toVar(),N=Hp(e).toVar(),A=Hp(e).toVar(),C=kp(0).toVar(),R=kp(0).toVar();wv(r,({i:t})=>{const i=t.add(1).toVar();Op(_.equal(0),()=>{S.addAssign(i),N.assign(e.add(b.mul(S)));const r=s(N.xy),o=n(r,h).toVar(),a=n(r,c).toVar();Op(o.greaterThan(a),()=>{_.assign(1)}),C.assign(t)}),Op(w.equal(0),()=>{M.addAssign(i),A.assign(e.sub(b.mul(M)));const r=s(A.xy),o=n(r,h).toVar(),a=n(r,c).toVar();Op(o.greaterThan(a),()=>{w.assign(1)}),R.assign(t)}),Op(_.equal(1).or(w.equal(1)),()=>{Mv()})}),Op(_.equal(0).and(w.equal(0)),()=>h);const E=Dp(1).toVar(),B=Dp(1).toVar();Op(_.equal(1),()=>{E.assign(Dp(C).div(Dp(r.sub(1))))}),Op(w.equal(1),()=>{B.assign(Dp(R).div(Dp(r.sub(1))))});const I=uf(E,B);return I.assign(xf(I,.5)),I.assign(Dp(1).sub(I)),Mf(h,c,I.mul(.5))}).setLayout({name:"FxaaPixelShader",type:"vec4",inputs:[{name:"uv",type:"vec2"},{name:"fxaaQualityRcpFrame",type:"vec2"},{name:"fxaaQualityEdgeThreshold",type:"float"},{name:"fxaaQualityinvEdgeThreshold",type:"float"}]});return Pp(()=>{const e=Dp(.2),s=Dp(1).div(e);return o(t,this._invSize,e,s)})()}}const QC=e=>Cp(new KC(vN(e))),eR=new fN,tR=new Kr(0,0,0),sR=new Kr,iR=new ei,rR=new ei(1,0),nR=new ei(0,1);class oR extends jd{static get type(){return"BloomNode"}constructor(e,t=1,s=0,i=0){super(),this.inputNode=e,this.strength=ym(t),this.radius=ym(s),this.threshold=ym(i),this.smoothWidth=ym(.01),this._renderTargetsHorizontal=[],this._renderTargetsVertical=[],this._nMips=5,this._renderTargetBright=new wi(1,1,{type:Pe}),this._renderTargetBright.texture.name="UnrealBloomPass.bright",this._renderTargetBright.texture.generateMipmaps=!1;for(let e=0;e<this._nMips;e++){const t=new wi(1,1,{type:Pe});t.texture.name="UnrealBloomPass.h"+e,t.texture.generateMipmaps=!1,this._renderTargetsHorizontal.push(t);const s=new wi(1,1,{type:Pe});s.texture.name="UnrealBloomPass.v"+e,s.texture.generateMipmaps=!1,this._renderTargetsVertical.push(s)}this._compositeMaterial=null,this._highPassFilterMaterial=null,this._separableBlurMaterials=[],this._textureNodeBright=zy(this._renderTargetBright.texture),this._textureNodeBlur0=zy(this._renderTargetsVertical[0].texture),this._textureNodeBlur1=zy(this._renderTargetsVertical[1].texture),this._textureNodeBlur2=zy(this._renderTargetsVertical[2].texture),this._textureNodeBlur3=zy(this._renderTargetsVertical[3].texture),this._textureNodeBlur4=zy(this._renderTargetsVertical[4].texture),this._textureOutput=pC(this,this._renderTargetsHorizontal[0].texture),this.updateBeforeType=zd.FRAME}getTextureNode(){return this._textureOutput}setSize(e,t){let s=Math.round(e/2),i=Math.round(t/2);this._renderTargetBright.setSize(s,i);for(let e=0;e<this._nMips;e++)this._renderTargetsHorizontal[e].setSize(s,i),this._renderTargetsVertical[e].setSize(s,i),this._separableBlurMaterials[e].invSize.value.set(1/s,1/i),s=Math.round(s/2),i=Math.round(i/2)}updateBefore(e){const{renderer:t}=e,s=t.getDrawingBufferSize(iR);this.setSize(s.width,s.height);const i=t.getRenderTarget(),r=t.getMRT();t.getClearColor(sR);const n=t.getClearAlpha();this.setSize(s.width,s.height),t.setMRT(null),t.setClearColor(tR,0),t.setRenderTarget(this._renderTargetBright),eR.material=this._highPassFilterMaterial,eR.render(t);let o=this._renderTargetBright;for(let e=0;e<this._nMips;e++)eR.material=this._separableBlurMaterials[e],this._separableBlurMaterials[e].colorTexture.value=o.texture,this._separableBlurMaterials[e].direction.value=rR,t.setRenderTarget(this._renderTargetsHorizontal[e]),t.clear(),eR.render(t),this._separableBlurMaterials[e].colorTexture.value=this._renderTargetsHorizontal[e].texture,this._separableBlurMaterials[e].direction.value=nR,t.setRenderTarget(this._renderTargetsVertical[e]),t.clear(),eR.render(t),o=this._renderTargetsVertical[e];t.setRenderTarget(this._renderTargetsHorizontal[0]),t.clear(),eR.material=this._compositeMaterial,eR.render(t),t.setRenderTarget(i),t.setMRT(r),t.setClearColor(sR,n)}setup(e){const t=Pp(()=>{const e=this.inputNode,t=CC(e.rgb),s=Rf(this.threshold,this.threshold.add(this.smoothWidth),t);return Mf(Kp(0),e,s)});this._highPassFilterMaterial=this._highPassFilterMaterial||new yT,this._highPassFilterMaterial.fragmentNode=t().context(e.getSharedContext()),this._highPassFilterMaterial.name="Bloom_highPass",this._highPassFilterMaterial.needsUpdate=!0;const s=[3,5,7,9,11];for(let t=0;t<this._nMips;t++)this._separableBlurMaterials.push(this._getSeperableBlurMaterial(e,s[t]));const i=kx([1,.8,.6,.4,.2]),r=kx([new Ei(1,1,1),new Ei(1,1,1),new Ei(1,1,1),new Ei(1,1,1),new Ei(1,1,1)]),n=Pp(([e,t])=>{const s=Dp(1.2).sub(e);return Mf(e,s,t)}).setLayout({name:"lerpBloomFactor",type:"float",inputs:[{name:"factor",type:"float"},{name:"radius",type:"float"}]}),o=Pp(()=>{const e=n(i.element(0),this.radius).mul(Kp(r.element(0),1)).mul(this._textureNodeBlur0),t=n(i.element(1),this.radius).mul(Kp(r.element(1),1)).mul(this._textureNodeBlur1),s=n(i.element(2),this.radius).mul(Kp(r.element(2),1)).mul(this._textureNodeBlur2),o=n(i.element(3),this.radius).mul(Kp(r.element(3),1)).mul(this._textureNodeBlur3),a=n(i.element(4),this.radius).mul(Kp(r.element(4),1)).mul(this._textureNodeBlur4);return e.add(t).add(s).add(o).add(a).mul(this.strength)});return this._compositeMaterial=this._compositeMaterial||new yT,this._compositeMaterial.fragmentNode=o().context(e.getSharedContext()),this._compositeMaterial.name="Bloom_comp",this._compositeMaterial.needsUpdate=!0,this._textureOutput}dispose(){for(let e=0;e<this._renderTargetsHorizontal.length;e++)this._renderTargetsHorizontal[e].dispose();for(let e=0;e<this._renderTargetsVertical.length;e++)this._renderTargetsVertical[e].dispose();this._renderTargetBright.dispose()}_getSeperableBlurMaterial(e,t){const s=[];for(let e=0;e<t;e++)s.push(.39894*Math.exp(-.5*e*e/(t*t))/t);const i=zy(),r=kx(s),n=ym(new ei),o=ym(new ei(.5,.5)),a=Ry(),h=e=>i.uv(e),u=Pp(()=>{const e=r.element(0).toVar(),s=h(a).rgb.mul(e).toVar();return wv({start:kp(1),end:kp(t),type:"int",condition:"<"},({i:t})=>{const i=Dp(t),u=r.element(t),l=o.mul(n).mul(i),c=h(a.add(l)).rgb,d=h(a.sub(l)).rgb;s.addAssign(eg(c,d).mul(u)),e.addAssign(Dp(2).mul(u))}),Kp(s.div(e),1)}),l=new yT;return l.fragmentNode=u().context(e.getSharedContext()),l.name="Bloom_seperable",l.needsUpdate=!0,l.colorTexture=i,l.direction=o,l.invSize=n,l}}const aR=(e,t,s,i)=>Cp(new oR(Cp(e),t,s,i));class hR extends jd{static get type(){return"TransitionNode"}constructor(e,t,s,i,r,n){super(),this.textureNodeA=e,this.textureNodeB=t,this.mixTextureNode=s,this.mixRatioNode=i,this.thresholdNode=r,this.useTextureNode=n}setup(){const{textureNodeA:e,textureNodeB:t,mixTextureNode:s,mixRatioNode:i,thresholdNode:r,useTextureNode:n}=this,o=e=>{const t=e.uvNode||Ry();return e.uv(t)},a=Pp(()=>{const a=o(e),h=o(t),u=Kp().toVar();return Op(n.equal(kp(1)),()=>{const e=o(s),t=i.mul(r.mul(2).add(1)).sub(r),n=Nf(tg(e.r,t).mul(Dp(1).div(r)),0,1);u.assign(Mf(a,h,n))}).Else(()=>{u.assign(Mf(h,a,i))}),u});return a()}}const uR=(e,t,s,i=0,r=.1,n=0)=>Cp(new hR(vN(e),vN(t),vN(s),Cp(i),Cp(r),Cp(n)));class lR extends jd{static get type(){return"PixelationNode"}constructor(e,t,s,i,r,n){super(),this.textureNode=e,this.depthNode=t,this.normalNode=s,this.pixelSize=i,this.normalEdgeStrength=r,this.depthEdgeStrength=n,this._resolution=ym(new _i),this.updateBeforeType=zd.RENDER}updateBefore(){const e=this.textureNode.value,t=e.image.width,s=e.image.height;this._resolution.value.set(t,s,1/t,1/s)}setup(){const{textureNode:e,depthNode:t,normalNode:s}=this,i=e.uvNode||Ry(),r=t.uvNode||Ry(),n=s.uvNode||Ry(),o=(e,s)=>t.uv(r.add(Hp(e,s).mul(this._resolution.zw))).r,a=(e,t)=>s.uv(n.add(Hp(e,t).mul(this._resolution.zw))).rgb.normalize(),h=(e,t,s,i)=>{const r=o(e,t).sub(s),n=a(e,t),h=Xp(1,1,1),u=ff(i.sub(n),h),l=Nf(Rf(-.01,.01,u),0,1),c=Nf(Yg(r.mul(.25).add(.0025)),0,1);return Dp(1).sub(ff(i,n)).mul(c).mul(l)},u=Pp(()=>{const t=e.uv(i),s=bm("float","depth"),r=bm("vec3","normal");Op(this.depthEdgeStrength.greaterThan(0).or(this.normalEdgeStrength.greaterThan(0)),()=>{s.assign(o(0,0)),r.assign(a(0,0))});const n=bm("float","dei");Op(this.depthEdgeStrength.greaterThan(0),()=>{n.assign((e=>{const t=bm("float","diff");return t.addAssign(Nf(o(1,0).sub(e))),t.addAssign(Nf(o(-1,0).sub(e))),t.addAssign(Nf(o(0,1).sub(e))),t.addAssign(Nf(o(0,-1).sub(e))),Lg(Rf(.01,.02,t).mul(2)).div(2)})(s))});const u=bm("float","nei");Op(this.normalEdgeStrength.greaterThan(0),()=>{u.assign(((e,t)=>{const s=bm("float","indicator");return s.addAssign(h(0,-1,e,t)),s.addAssign(h(0,1,e,t)),s.addAssign(h(-1,0,e,t)),s.addAssign(h(1,0,e,t)),df(.1,s)})(s,r))});const l=n.greaterThan(0).select(Dp(1).sub(n.mul(this.depthEdgeStrength)),u.mul(this.normalEdgeStrength).add(1));return t.mul(l)});return u()}}class cR extends cC{static get type(){return"PixelationPassNode"}constructor(e,t,s=6,i=.3,r=.4){super("color",e,t,{minFilter:fe,magFilter:fe}),this.pixelSize=s,this.normalEdgeStrength=i,this.depthEdgeStrength=r,this.isPixelationPassNode=!0,this._mrt=EM({output:Vm,normal:wx})}setSize(e,t){const s=this.pixelSize.value?this.pixelSize.value:this.pixelSize,i=Math.floor(e/s),r=Math.floor(t/s);super.setSize(i,r)}setup(){return((e,t,s,i=6,r=.3,n=.4)=>Cp(new lR(vN(e),vN(t),vN(s),Cp(i),Cp(r),Cp(n))))(super.getTextureNode("output"),super.getTextureNode("depth"),super.getTextureNode("normal"),this.pixelSize,this.normalEdgeStrength,this.depthEdgeStrength)}}const dR=(e,t,s,i,r)=>Cp(new cR(e,t,s,i,r)),pR=new ei;class mR extends cC{static get type(){return"SSAAPassNode"}constructor(e,t){super(cC.COLOR,e,t),this.isSSAAPassNode=!0,this.sampleLevel=4,this.unbiased=!0,this.clearColor=new Kr(0),this.clearAlpha=0,this._currentClearColor=new Kr,this.sampleWeight=ym(1),this.sampleRenderTarget=null,this._quadMesh=new fN}updateBefore(e){const{renderer:t}=e,{scene:s,camera:i}=this;this._pixelRatio=t.getPixelRatio();const r=t.getSize(pR);this.setSize(r.width,r.height),this.sampleRenderTarget.setSize(this.renderTarget.width,this.renderTarget.height),t.getClearColor(this._currentClearColor);const n=t.getClearAlpha(),o=t.getRenderTarget(),a=t.getMRT(),h=t.autoClear;this._cameraNear.value=i.near,this._cameraFar.value=i.far,t.setMRT(this.getMRT()),t.autoClear=!1;const u=gR[Math.max(0,Math.min(this.sampleLevel,5))],l=1/u.length,c={fullWidth:this.renderTarget.width,fullHeight:this.renderTarget.height,offsetX:0,offsetY:0,width:this.renderTarget.width,height:this.renderTarget.height},d=Object.assign({},i.view);d.enabled&&Object.assign(c,d);for(let e=0;e<u.length;e++){const r=u[e];if(i.setViewOffset&&i.setViewOffset(c.fullWidth,c.fullHeight,c.offsetX+.0625*r[0],c.offsetY+.0625*r[1],c.width,c.height),this.sampleWeight.value=l,this.unbiased){const t=(e+.5)/u.length-.5;this.sampleWeight.value+=.03125*t}t.setClearColor(this.clearColor,this.clearAlpha),t.setRenderTarget(this.sampleRenderTarget),t.clear(),t.render(s,i),t.setRenderTarget(this.renderTarget),0===e&&(t.setClearColor(0,0),t.clear()),this._quadMesh.render(t)}t.copyTextureToTexture(this.sampleRenderTarget.depthTexture,this.renderTarget.depthTexture),i.setViewOffset&&d.enabled?i.setViewOffset(d.fullWidth,d.fullHeight,d.offsetX,d.offsetY,d.width,d.height):i.clearViewOffset&&i.clearViewOffset(),t.setRenderTarget(o),t.setMRT(a),t.autoClear=h,t.setClearColor(this._currentClearColor,n)}setup(e){let t;null===this.sampleRenderTarget&&(this.sampleRenderTarget=this.renderTarget.clone());const s=this.getMRT();if(null!==s){const e={};for(const t in s.outputNodes){const s=CM(this.sampleRenderTarget.textures,t);s>=0&&(e[t]=zy(this.sampleRenderTarget.textures[s]).mul(this.sampleWeight))}t=EM(e)}else t=zy(this.sampleRenderTarget.texture).mul(this.sampleWeight);return this._quadMesh.material=new yT,this._quadMesh.material.fragmentNode=t,this._quadMesh.material.transparent=!0,this._quadMesh.material.depthTest=!1,this._quadMesh.material.depthWrite=!1,this._quadMesh.material.premultipliedAlpha=!0,this._quadMesh.material.blending=2,this._quadMesh.material.normals=!1,this._quadMesh.material.name="SSAA",super.setup(e)}dispose(){super.dispose(),null!==this.sampleRenderTarget&&this.sampleRenderTarget.dispose()}}const gR=[[[0,0]],[[4,4],[-4,-4]],[[-2,-6],[6,-2],[-6,2],[2,6]],[[1,-3],[-1,3],[5,1],[-3,-5],[-5,5],[-7,-1],[3,7],[7,-7]],[[1,1],[-1,-3],[-3,2],[4,-1],[-5,-2],[2,5],[5,3],[3,-5],[-2,6],[0,-7],[-4,-6],[-6,4],[-8,0],[7,-4],[6,7],[-7,-8]],[[-4,-7],[-7,-5],[-3,-5],[-5,-4],[-1,-4],[-2,-2],[-6,-1],[-4,0],[-7,1],[-1,2],[-6,3],[-3,3],[-7,6],[-3,6],[-5,7],[-1,7],[5,-7],[1,-6],[6,-5],[4,-4],[2,-3],[7,-2],[1,-1],[4,-1],[2,1],[6,2],[0,4],[4,4],[2,5],[7,5],[5,6],[3,7]]],fR=(e,t)=>Cp(new mR(e,t)),yR=new ei;class xR extends cC{static get type(){return"StereoPassNode"}constructor(e,t){super(cC.COLOR,e,t),this.isStereoPassNode=!0,this.stereo=new Zl,this.stereo.aspect=.5}updateBefore(e){const{renderer:t}=e,{scene:s,camera:i,stereo:r,renderTarget:n}=this;this._pixelRatio=t.getPixelRatio(),r.cameraL.coordinateSystem=t.coordinateSystem,r.cameraR.coordinateSystem=t.coordinateSystem,r.update(i);const o=t.getSize(yR);this.setSize(o.width,o.height);const a=t.autoClear;t.autoClear=!1;const h=t.getRenderTarget(),u=t.getMRT();this._cameraNear.value=i.near,this._cameraFar.value=i.far;for(const e in this._previousTextures)this.toggleTexture(e);t.setRenderTarget(n),t.setMRT(this._mrt),t.clear(),n.scissorTest=!0,n.scissor.set(0,0,n.width/2,n.height),n.viewport.set(0,0,n.width/2,n.height),t.render(s,r.cameraL),n.scissor.set(n.width/2,0,n.width/2,n.height),n.viewport.set(n.width/2,0,n.width/2,n.height),t.render(s,r.cameraR),n.scissorTest=!1,t.setRenderTarget(h),t.setMRT(u),t.autoClear=a}}const bR=(e,t)=>Cp(new xR(e,t)),vR=new ei,TR=new fN;class _R extends cC{static get type(){return"StereoCompositePassNode"}constructor(e,t){super(cC.COLOR,e,t),this.isStereoCompositePassNode=!0,this.stereo=new Zl;const s={minFilter:Te,magFilter:fe,type:Pe};this._renderTargetL=new wi(1,1,s),this._renderTargetR=new wi(1,1,s),this._mapLeft=zy(this._renderTargetL.texture),this._mapRight=zy(this._renderTargetR.texture),this._material=null}updateStereoCamera(e){this.stereo.cameraL.coordinateSystem=e,this.stereo.cameraR.coordinateSystem=e,this.stereo.update(this.camera)}setSize(e,t){super.setSize(e,t),this._renderTargetL.setSize(this.renderTarget.width,this.renderTarget.height),this._renderTargetR.setSize(this.renderTarget.width,this.renderTarget.height)}updateBefore(e){const{renderer:t}=e,{scene:s,stereo:i,renderTarget:r}=this;this._pixelRatio=t.getPixelRatio(),this.updateStereoCamera(t.coordinateSystem);const n=t.getSize(vR);this.setSize(n.width,n.height);const o=t.getRenderTarget();t.setRenderTarget(this._renderTargetL),t.render(s,i.cameraL),t.setRenderTarget(this._renderTargetR),t.render(s,i.cameraR),t.setRenderTarget(r),TR.material=this._material,TR.render(t),t.setRenderTarget(o)}dispose(){super.dispose(),this._renderTargetL.dispose(),this._renderTargetR.dispose(),null!==this._material&&this._material.dispose()}}class wR extends _R{static get type(){return"AnaglyphPassNode"}constructor(e,t){super(e,t),this.isAnaglyphPassNode=!0,this._colorMatrixLeft=ym((new ti).fromArray([.4561,-.0400822,-.0152161,.500484,-.0378246,-.0205971,.176381,-.0157589,-.00546856])),this._colorMatrixRight=ym((new ti).fromArray([-.0434706,.378476,-.0721527,-.0879388,.73364,-.112961,-.00155529,-.0184503,1.2264]))}setup(e){const t=Ry(),s=Pp(()=>{const e=this._mapLeft.uv(t),s=this._mapRight.uv(t),i=Nf(this._colorMatrixLeft.mul(e.rgb).add(this._colorMatrixRight.mul(s.rgb)));return Kp(i.rgb,lf(e.a,s.a))}),i=this._material||(this._material=new yT);return i.fragmentNode=s().context(e.getSharedContext()),i.name="Anaglyph",i.needsUpdate=!0,super.setup(e)}}const SR=(e,t)=>Cp(new wR(e,t));class MR extends _R{static get type(){return"ParallaxBarrierPassNode"}constructor(e,t){super(e,t),this.isParallaxBarrierPassNode=!0}setup(e){const t=Ry(),s=Pp(()=>{const e=Kp().toVar();return Op(cf(qv.y,2).greaterThan(1),()=>{e.assign(this._mapLeft.uv(t))}).Else(()=>{e.assign(this._mapRight.uv(t))}),e}),i=this._material||(this._material=new yT);return i.fragmentNode=s().context(e.getSharedContext()),i.needsUpdate=!0,super.setup(e)}}const NR=(e,t)=>Cp(new MR(e,t));class AR extends cC{static get type(){return"ToonOutlinePassNode"}constructor(e,t,s,i,r){super(cC.COLOR,e,t),this.colorNode=s,this.thicknessNode=i,this.alphaNode=r,this._materialCache=new WeakMap}updateBefore(e){const{renderer:t}=e,s=t.getRenderObjectFunction();t.setRenderObjectFunction((e,s,i,r,n,o,a)=>{if((n.isMeshToonMaterial||n.isMeshToonNodeMaterial)&&!1===n.wireframe){const h=this._getOutlineMaterial(n);t.renderObject(e,s,i,r,h,o,a)}t.renderObject(e,s,i,r,n,o,a)}),super.updateBefore(e),t.setRenderObjectFunction(s)}_createMaterial(){const e=new yT;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=1;const t=Tx.negate(),s=ky.mul(ax),i=Dp(1),r=s.mul(Kp(cx,1)),n=s.mul(Kp(cx.add(t),1)),o=Dg(r.sub(n));return e.vertexNode=r.add(o.mul(this.thicknessNode).mul(r.w).mul(i)),e.colorNode=Kp(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const CR=(e,t,s=new Kr(0,0,0),i=.003,r=1)=>Cp(new AR(e,t,Cp(s),Cp(i),Cp(r)));class RR extends Gd{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new Gs,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(e){this._value!==e&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=e,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const e=this.value;if(e&&null===this._cache&&"URL"===this.inputType&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&null!==e.value&&void 0!==e.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof e.value||"Number"===this.inputType&&"number"==typeof e.value||"Vector2"===this.inputType&&e.value.isVector2||"Vector3"===this.inputType&&e.value.isVector3||"Vector4"===this.inputType&&e.value.isVector4||"Color"===this.inputType&&e.value.isColor||"Matrix3"===this.inputType&&e.value.isMatrix3||"Matrix4"===this.inputType&&e.value.isMatrix4))return e.value;return this._cache||e}getNodeType(e){return this.value&&this.value.isNode?this.value.getNodeType(e):"float"}setup(){return this.value&&this.value.isNode?this.value:Dp()}serialize(e){super.serialize(e),null!==this.value?"ArrayBuffer"===this.inputType?e.value=Bd(this.value):e.value=this.value?this.value.toJSON(e.meta).uuid:null:e.value=null,e.inputType=this.inputType,e.outputType=this.outputType}deserialize(e){super.deserialize(e);let t=null;null!==e.value&&(t="ArrayBuffer"===e.inputType?Id(e.value):"Texture"===e.inputType?e.meta.textures[e.value]:e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}const ER=Bp(RR);class BR extends Map{get(e,t=null,...s){if(this.has(e))return super.get(e);if(null!==t){const i=t(...s);return this.set(e,i),i}}}class IR{constructor(e){this.scriptableNode=e}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(e){return this.scriptableNode.getInputLayout(e)}get(e){const t=this.parameters[e];return t?t.getValue():null}}const PR=new BR;class FR extends Gd{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new BR,this._output=ER(),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(e,t){return this._local.set(e,t)}getLocal(e){return this._local.get(e)}onRefresh(){this._refresh()}getInputLayout(e){for(const t of this.getLayout())if(t.inputType&&(t.id===e||t.name===e))return t}getOutputLayout(e){for(const t of this.getLayout())if(t.outputType&&(t.id===e||t.name===e))return t}setOutput(e,t){const s=this._outputs;return void 0===s[e]?s[e]=ER(t):s[e].value=t,this}getOutput(e){return this._outputs[e]}getParameter(e){return this.parameters[e]}setParameter(e,t){const s=this.parameters;return t&&t.isScriptableNode?(this.deleteParameter(e),s[e]=t,s[e].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):t&&t.isScriptableValueNode?(this.deleteParameter(e),s[e]=t,s[e].events.addEventListener("refresh",this.onRefresh)):void 0===s[e]?(s[e]=ER(t),s[e].events.addEventListener("refresh",this.onRefresh)):s[e].value=t,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(e){let t=this.parameters[e];return t&&(t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const e of Object.keys(this.parameters))this.deleteParameter(e);return this.needsUpdate=!0,this}call(e,...t){const s=this.getObject()[e];if("function"==typeof s)return s(...t)}async callAsync(e,...t){const s=this.getObject()[e];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...t):s(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){null!==e?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const e=new IR(this),t=PR.get("THREE"),s=PR.get("TSL"),i=this.getMethod(this.codeNode),r=[e,this._local,PR,()=>this.refresh(),(e,t)=>this.setOutput(e,t),t,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 e of n.elements){const t=e.id||e.name;e.inputType&&(void 0===this.getParameter(t)&&this.setParameter(t,null),this.getParameter(t).inputType=e.inputType),e.outputType&&(void 0===this.getOutput(t)&&this.setOutput(t,null),this.getOutput(t).outputType=e.outputType)}return this._object}deserialize(e){super.deserialize(e);for(const e in this.parameters){let t=this.parameters[e];t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const e=this.getDefaultOutput().value;return e&&e.isNode?e:Dp()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const e=["layout","init","main","dispose"].join(", "),t="\nreturn { ...output, "+e+" };",s="var "+e+"; var output = {};\n"+this.codeNode.code+t;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()}getCacheKey(e){const t=[Sd(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(const s in this.parameters)t.push(this.parameters[s].getCacheKey(e));return Md(t)}set needsUpdate(e){!0===e&&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 zR=Bp(FR);class UR extends Gd{static get type(){return"FogNode"}constructor(e,t){super("float"),this.isFogNode=!0,this.colorNode=e,this.factorNode=t}getViewZNode(e){let t;const s=e.context.getViewZ;return void 0!==s&&(t=s(this)),(t||gx.z).negate()}setup(){return this.factorNode}}const OR=Bp(UR);class LR extends UR{static get type(){return"FogRangeNode"}constructor(e,t,s){super(e),this.isFogRangeNode=!0,this.nearNode=t,this.farNode=s}setup(e){const t=this.getViewZNode(e);return Rf(this.nearNode,this.farNode,t)}}const VR=Bp(LR);class DR extends UR{static get type(){return"FogExp2Node"}constructor(e,t){super(e),this.isFogExp2Node=!0,this.densityNode=t}setup(e){const t=this.getViewZNode(e),s=this.densityNode;return s.mul(s,t,t).negate().exp().oneMinus()}}const kR=Bp(DR);let GR=null,WR=null;class HR extends Gd{static get type(){return"RangeNode"}constructor(e=Dp(),t=Dp()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=e.getTypeLength(Rd(this.minNode.value)),s=e.getTypeLength(Rd(this.maxNode.value));return t>s?t:s}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}setup(e){const t=e.object;let s=null;if(t.count>1){const i=this.minNode.value,r=this.maxNode.value,n=e.getTypeLength(Rd(i)),o=e.getTypeLength(Rd(r));GR=GR||new _i,WR=WR||new _i,GR.setScalar(0),WR.setScalar(0),1===n?GR.setScalar(i):i.isColor?GR.set(i.r,i.g,i.b):GR.set(i.x,i.y,i.z||0,i.w||0),1===o?WR.setScalar(r):r.isColor?WR.set(r.r,r.g,r.b):WR.set(r.x,r.y,r.z||0,r.w||0);const a=4,h=a*t.count,u=new Float32Array(h);for(let e=0;e<h;e++){const t=e%a,s=GR.getComponent(t),i=WR.getComponent(t);u[e]=Qs.lerp(s,i,Math.random())}const l=this.getNodeType(e);if(t.count<=4096)s=Lx(u,"vec4",t.count).element(uv).convert(l);else{const t=new Ho(u,4);e.geometry.setAttribute("__range"+this.id,t),s=uy(t).convert(l)}}else s=Dp(0);return s}}const jR=Bp(HR),qR=Pp(({depthTexture:e,shadowCoord:t})=>zy(e,t.xy).compare(t.z)),$R=Pp(({depthTexture:e,shadowCoord:t,shadow:s})=>{const i=(t,s)=>zy(e,t).compare(s),r=jx("mapSize","vec2",s).setGroup(mm),n=jx("radius","float",s).setGroup(mm),o=Hp(1).div(r),a=o.x.negate().mul(n),h=o.y.negate().mul(n),u=o.x.mul(n),l=o.y.mul(n),c=a.div(2),d=h.div(2),p=u.div(2),m=l.div(2);return eg(i(t.xy.add(Hp(a,h)),t.z),i(t.xy.add(Hp(0,h)),t.z),i(t.xy.add(Hp(u,h)),t.z),i(t.xy.add(Hp(c,d)),t.z),i(t.xy.add(Hp(0,d)),t.z),i(t.xy.add(Hp(p,d)),t.z),i(t.xy.add(Hp(a,0)),t.z),i(t.xy.add(Hp(c,0)),t.z),i(t.xy,t.z),i(t.xy.add(Hp(p,0)),t.z),i(t.xy.add(Hp(u,0)),t.z),i(t.xy.add(Hp(c,m)),t.z),i(t.xy.add(Hp(0,m)),t.z),i(t.xy.add(Hp(p,m)),t.z),i(t.xy.add(Hp(a,l)),t.z),i(t.xy.add(Hp(0,l)),t.z),i(t.xy.add(Hp(u,l)),t.z)).mul(1/17)}),XR=Pp(({depthTexture:e,shadowCoord:t,shadow:s})=>{const i=(t,s)=>zy(e,t).compare(s),r=jx("mapSize","vec2",s).setGroup(mm),n=Hp(1).div(r),o=n.x,a=n.y,h=t.xy,u=kg(h.mul(r).add(.5));return h.subAssign(u.mul(n)),eg(i(h,t.z),i(h.add(Hp(o,0)),t.z),i(h.add(Hp(0,a)),t.z),i(h.add(n),t.z),Mf(i(h.add(Hp(o.negate(),0)),t.z),i(h.add(Hp(o.mul(2),0)),t.z),u.x),Mf(i(h.add(Hp(o.negate(),a)),t.z),i(h.add(Hp(o.mul(2),a)),t.z),u.x),Mf(i(h.add(Hp(0,a.negate())),t.z),i(h.add(Hp(0,a.mul(2))),t.z),u.y),Mf(i(h.add(Hp(o,a.negate())),t.z),i(h.add(Hp(o,a.mul(2))),t.z),u.y),Mf(Mf(i(h.add(Hp(o.negate(),a.negate())),t.z),i(h.add(Hp(o.mul(2),a.negate())),t.z),u.x),Mf(i(h.add(Hp(o.negate(),a.mul(2))),t.z),i(h.add(Hp(o.mul(2),a.mul(2))),t.z),u.x),u.y)).mul(1/9)}),YR=Pp(({depthTexture:e,shadowCoord:t})=>{const s=Dp(1).toVar(),i=zy(e).uv(t.xy).rg,r=df(t.z,i.x);return Op(r.notEqual(Dp(1)),()=>{const e=t.z.sub(i.x),n=lf(0,i.y.mul(i.y));let o=n.div(n.add(e.mul(e)));o=Nf(tg(o,.3).div(.95-.3)),s.assign(Nf(lf(r,o)))}),s}),ZR=Pp(({samples:e,radius:t,size:s,shadowPass:i})=>{const r=Dp(0).toVar(),n=Dp(0).toVar(),o=e.lessThanEqual(Dp(1)).select(Dp(0),Dp(2).div(e.sub(1))),a=e.lessThanEqual(Dp(1)).select(Dp(0),Dp(-1));wv({start:kp(0),end:kp(e),type:"int",condition:"<"},({i:e})=>{const h=a.add(Dp(e).mul(o)),u=i.uv(eg(qv.xy,Hp(0,h).mul(t)).div(s)).x;r.addAssign(u),n.addAssign(u.mul(u))}),r.divAssign(e),n.divAssign(e);const h=Ug(n.sub(r.mul(r)));return Hp(r,h)}),JR=Pp(({samples:e,radius:t,size:s,shadowPass:i})=>{const r=Dp(0).toVar(),n=Dp(0).toVar(),o=e.lessThanEqual(Dp(1)).select(Dp(0),Dp(2).div(e.sub(1))),a=e.lessThanEqual(Dp(1)).select(Dp(0),Dp(-1));wv({start:kp(0),end:kp(e),type:"int",condition:"<"},({i:e})=>{const h=a.add(Dp(e).mul(o)),u=i.uv(eg(qv.xy,Hp(h,0).mul(t)).div(s));r.addAssign(u.x),n.addAssign(eg(u.y.mul(u.y),u.x.mul(u.x)))}),r.divAssign(e),n.divAssign(e);const h=Ug(n.sub(r.mul(r)));return Hp(r,h)}),KR=[qR,$R,XR,YR];let QR=null;const eE=new fN;class tE extends Uv{static get type(){return"AnalyticLightNode"}constructor(e=null){super(),this.updateType=zd.FRAME,this.light=e,this.color=new Kr,this.colorNode=ym(this.color).setGroup(mm),this.baseColorNode=null,this.shadowMap=null,this.shadowNode=null,this.shadowColorNode=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.isAnalyticLightNode=!0}getCacheKey(){return Nd(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(e){const{object:t,renderer:s}=e;if(!1===s.shadowMap.enabled)return;let i=this.shadowColorNode;if(null===i){null===QR&&(QR=new yT,QR.fragmentNode=Kp(0,0,0,1),QR.isShadowNodeMaterial=!0,QR.name="ShadowMaterial");const r=s.shadowMap.type,n=this.light.shadow,o=new Qa;o.compareFunction=_s;const a=e.createRenderTarget(n.mapSize.width,n.mapSize.height);if(a.depthTexture=o,n.camera.updateProjectionMatrix(),3===r){o.compareFunction=null,this.vsmShadowMapVertical=e.createRenderTarget(n.mapSize.width,n.mapSize.height,{format:Xe,type:Pe}),this.vsmShadowMapHorizontal=e.createRenderTarget(n.mapSize.width,n.mapSize.height,{format:Xe,type:Pe});const t=zy(o),s=zy(this.vsmShadowMapVertical.texture),i=jx("blurSamples","float",n).setGroup(mm),r=jx("radius","float",n).setGroup(mm),a=jx("mapSize","vec2",n).setGroup(mm);let h=this.vsmMaterialVertical||(this.vsmMaterialVertical=new yT);h.fragmentNode=ZR({samples:i,radius:r,size:a,shadowPass:t}).context(e.getSharedContext()),h.name="VSMVertical",h=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new yT),h.fragmentNode=JR({samples:i,radius:r,size:a,shadowPass:s}).context(e.getSharedContext()),h.name="VSMHorizontal"}const h=jx("intensity","float",n).setGroup(mm),u=jx("bias","float",n).setGroup(mm),l=jx("normalBias","float",n).setGroup(mm),c=t.material.shadowPositionNode||px;let d=ym(n.matrix).setGroup(mm).mul(c.add(Sx.mul(l)));d=d.xyz.div(d.w);let p=d.z.add(u);s.coordinateSystem===ks&&(p=p.mul(2).sub(1)),d=Xp(d.x,d.y.oneMinus(),p);const m=d.x.greaterThanEqual(0).and(d.x.lessThanEqual(1)).and(d.y.greaterThanEqual(0)).and(d.y.lessThanEqual(1)).and(d.z.lessThanEqual(1)),g=n.filterNode||KR[s.shadowMap.type]||null;if(null===g)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const f=zy(a.texture,d),y=m.select(g({depthTexture:3===r?this.vsmShadowMapHorizontal.texture:o,shadowCoord:d,shadow:n}),Dp(1));this.shadowMap=a,this.light.shadow.map=a,this.shadowNode=y,this.shadowColorNode=i=this.colorNode.mul(Mf(1,y.rgb.mix(f,1),h.mul(f.a))),this.baseColorNode=this.colorNode}this.colorNode=i,this.updateBeforeType=zd.RENDER}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&this.disposeShadow()}updateShadow(e){const{shadowMap:t,light:s}=this,{renderer:i,scene:r,camera:n}=e,o=i.shadowMap.type,a=t.depthTexture.version;this._depthVersionCached=a;const h=r.overrideMaterial;r.overrideMaterial=QR,t.setSize(s.shadow.mapSize.width,s.shadow.mapSize.height),s.shadow.updateMatrices(s),s.shadow.camera.layers.mask=n.layers.mask;const u=i.getRenderTarget(),l=i.getRenderObjectFunction();i.setRenderObjectFunction((e,...t)=>{(!0===e.castShadow||e.receiveShadow&&3===o)&&i.renderObject(e,...t)}),i.setRenderTarget(t),i.render(r,s.shadow.camera),i.setRenderObjectFunction(l),!0!==s.isPointLight&&3===o&&this.vsmPass(e,s),i.setRenderTarget(u),r.overrideMaterial=h}vsmPass(e,t){const{renderer:s}=e;this.vsmShadowMapVertical.setSize(t.shadow.mapSize.width,t.shadow.mapSize.height),this.vsmShadowMapHorizontal.setSize(t.shadow.mapSize.width,t.shadow.mapSize.height),s.setRenderTarget(this.vsmShadowMapVertical),eE.material=this.vsmMaterialVertical,eE.render(s),s.setRenderTarget(this.vsmShadowMapHorizontal),eE.material=this.vsmMaterialHorizontal,eE.render(s)}disposeShadow(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.shadowNode=null,this.shadowColorNode=null,this.baseColorNode=null,this.updateBeforeType=zd.NONE}updateBefore(e){const t=this.light.shadow;(t.needsUpdate||t.autoUpdate)&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const sE=Pp(e=>{const{lightDistance:t,cutoffDistance:s,decayExponent:i}=e,r=t.pow(i).max(.01).reciprocal();return s.greaterThan(0).select(r.mul(t.div(s).pow4().oneMinus().clamp().pow2()),r)});let iE;function rE(e){iE=iE||new WeakMap;let t=iE.get(e);return void 0===t&&iE.set(e,t={}),t}function nE(e){const t=rE(e);return t.position||(t.position=ym(new Ei).setGroup(mm).onRenderUpdate((t,s)=>s.value.setFromMatrixPosition(e.matrixWorld)))}function oE(e){const t=rE(e);return t.targetPosition||(t.targetPosition=ym(new Ei).setGroup(mm).onRenderUpdate((t,s)=>s.value.setFromMatrixPosition(e.target.matrixWorld)))}function aE(e){const t=rE(e);return t.viewPosition||(t.viewPosition=ym(new Ei).setGroup(mm).onRenderUpdate(({camera:t},s)=>{s.value=s.value||new Ei,s.value.setFromMatrixPosition(e.matrixWorld),s.value.applyMatrix4(t.matrixWorldInverse)}))}const hE=e=>Wy.transformDirection(nE(e).sub(oE(e))),uE=Pp(([e])=>{const t=e.toUint().mul(747796405).add(2891336453),s=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return s.shiftRight(22).bitXor(s).toFloat().mul(1/2**32)}),lE=(e,t)=>xf(sg(4,e.mul(tg(1,e))),t),cE=(e,t)=>e.lessThan(.5)?lE(e.mul(2),t).div(2):tg(1,lE(sg(tg(1,e),2),t).div(2)),dE=(e,t,s)=>xf(ig(xf(e,t),eg(xf(e,t),xf(tg(1,e),s))),1/t),pE=(e,t)=>Gg(Mg.mul(t.mul(e).sub(1))).div(Mg.mul(t.mul(e).sub(1))),mE=Pp(([e])=>e.fract().sub(.5).abs()).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),gE=Pp(([e])=>Xp(mE(e.z.add(mE(e.y.mul(1)))),mE(e.z.add(mE(e.x.mul(1)))),mE(e.y.add(mE(e.x.mul(1)))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),fE=Pp(([e,t,s])=>{const i=Xp(e).toVar(),r=Dp(1.4).toVar(),n=Dp(0).toVar(),o=Xp(i).toVar();return wv({start:Dp(0),end:Dp(3),type:"float",condition:"<="},()=>{const e=Xp(gE(o.mul(2))).toVar();i.addAssign(e.add(s.mul(Dp(.1).mul(t)))),o.mulAssign(1.8),r.mulAssign(1.5),i.mulAssign(1.2);const a=Dp(mE(i.z.add(mE(i.x.add(mE(i.y)))))).toVar();n.addAssign(a.div(r)),o.addAssign(.14)}),n}).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]}),yE=Pp(([e,t,s=Hp(.5)])=>Fw(e.sub(s),t).add(s)),xE=Pp(([e,t,s=Hp(.5)])=>{const i=e.sub(s),r=i.dot(i),n=r.mul(r).mul(t);return e.add(i.mul(n))}),bE=Pp(({position:e=null,horizontal:t=!0,vertical:s=!1})=>{let i;null!==e?(i=tx.toVar(),i[3][0]=e.x,i[3][1]=e.y,i[3][2]=e.z):i=tx;const r=Wy.mul(i);return Mp(t)&&(r[0][0]=tx[0].length(),r[0][1]=0,r[0][2]=0),Mp(s)&&(r[1][0]=0,r[1][1]=tx[1].length(),r[1][2]=0),r[2][0]=0,r[2][1]=0,r[2][2]=1,ky.mul(r).mul(cx)}),vE=Pp(([e=null])=>{const t=mT();return mT(oT(e)).sub(t).lessThan(0).select(Hv,e)}),TE=new WeakMap;class _E extends jd{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.updateType=zd.OBJECT,this.updateAfterType=zd.OBJECT,this.previousModelWorldMatrix=ym(new or),this.previousProjectionMatrix=ym(new or).setGroup(mm),this.previousCameraViewMatrix=ym(new or)}update({frameId:e,camera:t,object:s}){const i=SE(s);this.previousModelWorldMatrix.value.copy(i);const r=wE(t);r.frameId!==e&&(r.frameId=e,void 0===r.previousProjectionMatrix?(r.previousProjectionMatrix=new or,r.previousCameraViewMatrix=new or,r.currentProjectionMatrix=new or,r.currentCameraViewMatrix=new or,r.previousProjectionMatrix.copy(t.projectionMatrix),r.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(r.previousProjectionMatrix.copy(r.currentProjectionMatrix),r.previousCameraViewMatrix.copy(r.currentCameraViewMatrix)),r.currentProjectionMatrix.copy(t.projectionMatrix),r.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(r.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(r.previousCameraViewMatrix))}updateAfter({object:e}){SE(e).copy(e.matrixWorld)}setup(){const e=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),t=ky.mul(ax).mul(cx),s=this.previousProjectionMatrix.mul(e).mul(dx),i=t.xy.div(t.w),r=s.xy.div(s.w);return tg(i,r)}}function wE(e){let t=TE.get(e);return void 0===t&&(t={},TE.set(e,t)),t}function SE(e,t=0){const s=wE(e);let i=s[t];return void 0===i&&(s[t]=i=new or),i}const ME=Ip(_E),NE=Pp(([e,t])=>uf(1,e.oneMinus().div(t)).oneMinus()).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),AE=Pp(([e,t])=>uf(e.div(t.oneMinus()),1)).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),CE=Pp(([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus()).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),RE=Pp(([e,t])=>Mf(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),df(.5,e))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),EE=Pp(([e,t,s=kp(16)])=>{const i=t=>e.uv(t),r=Ry(),n=i(r).toVar(),o=Dp(s);return wv({start:kp(1),end:s,type:"int",condition:"<="},({i:e})=>{const s=t.mul(Dp(e).div(o.sub(1)).sub(.5));n.addAssign(i(r.add(s)))}),n.divAssign(o),n}),BE=Pp(([e,t=1])=>{const s=e,i=CC(s.rgb),r=Xp(i),n=uf(1,lf(0,Dp(10).mul(i.sub(.45)))),o=r.mul(s.rgb).mul(2),a=Dp(2).mul(r.oneMinus()).mul(s.rgb.oneMinus()).oneMinus(),h=Mf(o,a,n),u=s.a.mul(t),l=u.mul(h.rgb);return l.addAssign(s.rgb.mul(u.oneMinus())),Kp(l,s.a)}),IE=Pp(([e])=>{const t=Xp(e);return Kp(ff(t,Xp(.393,.769,.189)),ff(t,Xp(.349,.686,.168)),ff(t,Xp(.272,.534,.131)),e.a)}),PE=Pp(([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),s=e.mul(.0773993808),i=e.lessThanEqual(.04045);return Mf(t,s,i)}).setLayout({name:"sRGBToLinearSRGB",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),FE=Pp(([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),s=e.mul(12.92),i=e.lessThanEqual(.0031308);return Mf(t,s,i)}).setLayout({name:"linearSRGBTosRGB",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),zE=Pp(([e,t])=>e.mul(t).clamp()).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),UE=Pp(([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp()).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),OE=Pp(([e,t])=>{const s=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),i=e.mul(e.mul(6.2).add(1.7)).add(.06);return s.div(i).pow(2.2)}).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),LE=Pp(([e])=>{const t=e.mul(e.add(.0245786)).sub(90537e-9),s=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(s)}),VE=Pp(([e,t])=>{const s=im(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),i=im(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=s.mul(e),e=LE(e),(e=i.mul(e)).clamp()}).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),DE=im(Xp(1.6605,-.1246,-.0182),Xp(-.5876,1.1329,-.1006),Xp(-.0728,-.0083,1.1187)),kE=im(Xp(.6274,.0691,.0164),Xp(.3293,.9195,.088),Xp(.0433,.0113,.8956)),GE=Pp(([e])=>{const t=Xp(e).toVar(),s=Xp(t.mul(t)).toVar(),i=Xp(s.mul(s)).toVar();return Dp(15.5).mul(i.mul(s)).sub(sg(40.14,i.mul(t))).add(sg(31.96,i).sub(sg(6.868,s.mul(t))).add(sg(.4298,s).add(sg(.1191,t).sub(.00232))))}),WE=Pp(([e,t])=>{const s=Xp(e).toVar(),i=im(Xp(.856627153315983,.137318972929847,.11189821299995),Xp(.0951212405381588,.761241990602591,.0767994186031903),Xp(.0482516061458583,.101439036467562,.811302368396859)),r=im(Xp(1.1271005818144368,-.1413297634984383,-.14132976349843826),Xp(-.11060664309660323,1.157823702216272,-.11060664309660294),Xp(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=Dp(-12.47393),o=Dp(4.026069);return s.mulAssign(t),s.assign(kE.mul(s)),s.assign(i.mul(s)),s.assign(lf(s,1e-10)),s.assign(zg(s)),s.assign(s.sub(n).div(o.sub(n))),s.assign(Nf(s,0,1)),s.assign(GE(s)),s.assign(r.mul(s)),s.assign(xf(lf(Xp(0),s),Xp(2.2))),s.assign(DE.mul(s)),s.assign(Nf(s,0,1)),s}).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),HE=Pp(([e,t])=>{const s=Dp(.76),i=Dp(.15);e=e.mul(t);const r=uf(e.r,uf(e.g,e.b)),n=zf(r.lessThan(.08),r.sub(sg(6.25,r.mul(r))),.04);e.subAssign(n);const o=lf(e.r,lf(e.g,e.b));Op(o.lessThan(s),()=>e);const a=tg(1,s),h=tg(1,a.mul(a).div(o.add(a.sub(s))));e.mulAssign(h.div(o));const u=tg(1,ig(1,i.mul(o.sub(h)).add(1)));return Mf(e,Xp(h),u)}).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class jE extends Gd{static get type(){return"ComputeBuiltinNode"}constructor(e,t){super(t),this._builtinName=e}getHash(e){return this.getBuiltinName(e)}getNodeType(){return this.nodeType}setBuiltinName(e){return this._builtinName=e,this}getBuiltinName(){return this._builtinName}hasBuiltin(e){e.hasBuiltin(this._builtinName)}generate(e,t){const s=this.getBuiltinName(e),i=this.getNodeType(e);return"compute"===e.shaderStage?e.format(s,i,t):(console.warn(`ComputeBuiltinNode: Compute built-in value ${s} can not be accessed in the ${e.shaderStage} stage`),e.generateConst(i))}serialize(e){super.serialize(e),e.global=this.global,e._builtinName=this._builtinName}deserialize(e){super.deserialize(e),this.global=e.global,this._builtinName=e._builtinName}}const qE=(e,t)=>Cp(new jE(e,t)),$E=qE("numWorkgroups","uvec3"),XE=qE("workgroupId","uvec3"),YE=qE("localId","uvec3"),ZE=qE("subgroupSize","uint");const JE=Bp(class extends Gd{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:s}=e;!0===s.backend.isWebGLBackend?e.addFlowCode(`\t// ${t}Barrier \n`):e.addLineFlowCode(`${t}Barrier()`,this)}}),KE=()=>JE("workgroup").append(),QE=()=>JE("storage").append(),eB=()=>JE("texture").append();class tB extends Wd{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let s;const i=e.context.assign;if(s=super.generate(e),!0!==i){const i=this.getNodeType(e);s=e.format(s,i,t)}return s}}class sB extends Gd{constructor(e,t,s=0){super(t),this.bufferType=t,this.bufferCount=s,this.isWorkgroupInfoNode=!0,this.scope=e}label(e){return this.name=e,this}getHash(){return this.uuid}setScope(e){return this.scope=e,this}getInputType(){return`${this.scope}Array`}element(e){return Cp(new tB(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const iB=(e,t)=>Cp(new sB("Workgroup",e,t));class rB extends jd{static get type(){return"AtomicFunctionNode"}constructor(e,t,s,i=null){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.storeNode=i}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=this.method,s=this.getNodeType(e),i=this.getInputType(e),r=this.pointerNode,n=this.valueNode,o=[];o.push(`&${r.build(e,i)}`),o.push(n.build(e,i));const a=`${e.getMethod(t,s)}( ${o.join(", ")} )`;if(null!==this.storeNode){const t=this.storeNode.build(e,i);e.addLineFlowCode(`${t} = ${a}`,this)}else e.addLineFlowCode(a,this)}}rB.ATOMIC_LOAD="atomicLoad",rB.ATOMIC_STORE="atomicStore",rB.ATOMIC_ADD="atomicAdd",rB.ATOMIC_SUB="atomicSub",rB.ATOMIC_MAX="atomicMax",rB.ATOMIC_MIN="atomicMin",rB.ATOMIC_AND="atomicAnd",rB.ATOMIC_OR="atomicOr",rB.ATOMIC_XOR="atomicXor";const nB=Bp(rB),oB=(e,t,s,i)=>{const r=nB(e,t,s,i);return r.append(),r},aB=(e,t,s=null)=>oB(rB.ATOMIC_STORE,e,t,s),hB=(e,t,s=null)=>oB(rB.ATOMIC_ADD,e,t,s),uB=(e,t,s=null)=>oB(rB.ATOMIC_SUB,e,t,s),lB=(e,t,s=null)=>oB(rB.ATOMIC_MAX,e,t,s),cB=(e,t,s=null)=>oB(rB.ATOMIC_MIN,e,t,s),dB=(e,t,s=null)=>oB(rB.ATOMIC_AND,e,t,s),pB=(e,t,s=null)=>oB(rB.ATOMIC_OR,e,t,s),mB=(e,t,s=null)=>oB(rB.ATOMIC_XOR,e,t,s),gB=Pp(([e=t()])=>{const t=e.mul(2),s=t.x.floor(),i=t.y.floor();return s.add(i).mod(2).sign()}),fB=Pp(([e,t,s])=>{const i=Dp(s).toVar(),r=Dp(t).toVar(),n=Wp(e).toVar();return zf(n,r,i)}).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),yB=Pp(([e,t])=>{const s=Wp(t).toVar(),i=Dp(e).toVar();return zf(s,i.negate(),i)}).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),xB=Pp(([e])=>{const t=Dp(e).toVar();return kp(Lg(t))}).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),bB=Pp(([e,t])=>{const s=Dp(e).toVar();return t.assign(xB(s)),s.sub(Dp(t))}),vB=PM([Pp(([e,t,s,i,r,n])=>{const o=Dp(n).toVar(),a=Dp(r).toVar(),h=Dp(i).toVar(),u=Dp(s).toVar(),l=Dp(t).toVar(),c=Dp(e).toVar(),d=Dp(tg(1,a)).toVar();return tg(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"}]}),Pp(([e,t,s,i,r,n])=>{const o=Dp(n).toVar(),a=Dp(r).toVar(),h=Xp(i).toVar(),u=Xp(s).toVar(),l=Xp(t).toVar(),c=Xp(e).toVar(),d=Dp(tg(1,a)).toVar();return tg(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"}]})]),TB=PM([Pp(([e,t,s,i,r,n,o,a,h,u,l])=>{const c=Dp(l).toVar(),d=Dp(u).toVar(),p=Dp(h).toVar(),m=Dp(a).toVar(),g=Dp(o).toVar(),f=Dp(n).toVar(),y=Dp(r).toVar(),x=Dp(i).toVar(),b=Dp(s).toVar(),v=Dp(t).toVar(),T=Dp(e).toVar(),_=Dp(tg(1,p)).toVar(),w=Dp(tg(1,d)).toVar();return Dp(tg(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"}]}),Pp(([e,t,s,i,r,n,o,a,h,u,l])=>{const c=Dp(l).toVar(),d=Dp(u).toVar(),p=Dp(h).toVar(),m=Xp(a).toVar(),g=Xp(o).toVar(),f=Xp(n).toVar(),y=Xp(r).toVar(),x=Xp(i).toVar(),b=Xp(s).toVar(),v=Xp(t).toVar(),T=Xp(e).toVar(),_=Dp(tg(1,p)).toVar(),w=Dp(tg(1,d)).toVar();return Dp(tg(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"}]})]),_B=Pp(([e,t,s])=>{const i=Dp(s).toVar(),r=Dp(t).toVar(),n=Gp(e).toVar(),o=Gp(n.bitAnd(Gp(7))).toVar(),a=Dp(fB(o.lessThan(Gp(4)),r,i)).toVar(),h=Dp(sg(2,fB(o.lessThan(Gp(4)),i,r))).toVar();return yB(a,Wp(o.bitAnd(Gp(1)))).add(yB(h,Wp(o.bitAnd(Gp(2)))))}).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),wB=Pp(([e,t,s,i])=>{const r=Dp(i).toVar(),n=Dp(s).toVar(),o=Dp(t).toVar(),a=Gp(e).toVar(),h=Gp(a.bitAnd(Gp(15))).toVar(),u=Dp(fB(h.lessThan(Gp(8)),o,n)).toVar(),l=Dp(fB(h.lessThan(Gp(4)),n,fB(h.equal(Gp(12)).or(h.equal(Gp(14))),o,r))).toVar();return yB(u,Wp(h.bitAnd(Gp(1)))).add(yB(l,Wp(h.bitAnd(Gp(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"}]}),SB=PM([_B,wB]),MB=Pp(([e,t,s])=>{const i=Dp(s).toVar(),r=Dp(t).toVar(),n=Zp(e).toVar();return Xp(SB(n.x,r,i),SB(n.y,r,i),SB(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"}]}),NB=Pp(([e,t,s,i])=>{const r=Dp(i).toVar(),n=Dp(s).toVar(),o=Dp(t).toVar(),a=Zp(e).toVar();return Xp(SB(a.x,o,n,r),SB(a.y,o,n,r),SB(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"}]}),AB=PM([MB,NB]),CB=Pp(([e])=>{const t=Dp(e).toVar();return sg(.6616,t)}).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),RB=Pp(([e])=>{const t=Dp(e).toVar();return sg(.982,t)}).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),EB=PM([CB,Pp(([e])=>{const t=Xp(e).toVar();return sg(.6616,t)}).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),BB=PM([RB,Pp(([e])=>{const t=Xp(e).toVar();return sg(.982,t)}).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),IB=Pp(([e,t])=>{const s=kp(t).toVar(),i=Gp(e).toVar();return i.shiftLeft(s).bitOr(i.shiftRight(kp(32).sub(s)))}).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),PB=Pp(([e,t,s])=>{e.subAssign(s),e.bitXorAssign(IB(s,kp(4))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(IB(e,kp(6))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(IB(t,kp(8))),t.addAssign(e),e.subAssign(s),e.bitXorAssign(IB(s,kp(16))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(IB(e,kp(19))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(IB(t,kp(4))),t.addAssign(e)}),FB=Pp(([e,t,s])=>{const i=Gp(s).toVar(),r=Gp(t).toVar(),n=Gp(e).toVar();return i.bitXorAssign(r),i.subAssign(IB(r,kp(14))),n.bitXorAssign(i),n.subAssign(IB(i,kp(11))),r.bitXorAssign(n),r.subAssign(IB(n,kp(25))),i.bitXorAssign(r),i.subAssign(IB(r,kp(16))),n.bitXorAssign(i),n.subAssign(IB(i,kp(4))),r.bitXorAssign(n),r.subAssign(IB(n,kp(14))),i.bitXorAssign(r),i.subAssign(IB(r,kp(24))),i}).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),zB=Pp(([e])=>{const t=Gp(e).toVar();return Dp(t).div(Dp(Gp(kp(4294967295))))}).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),UB=Pp(([e])=>{const t=Dp(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))}).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),OB=PM([Pp(([e])=>{const t=kp(e).toVar(),s=Gp(Gp(1)).toVar(),i=Gp(Gp(kp(3735928559)).add(s.shiftLeft(Gp(2))).add(Gp(13))).toVar();return FB(i.add(Gp(t)),i,i)}).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),Pp(([e,t])=>{const s=kp(t).toVar(),i=kp(e).toVar(),r=Gp(Gp(2)).toVar(),n=Gp().toVar(),o=Gp().toVar(),a=Gp().toVar();return n.assign(o.assign(a.assign(Gp(kp(3735928559)).add(r.shiftLeft(Gp(2))).add(Gp(13))))),n.addAssign(Gp(i)),o.addAssign(Gp(s)),FB(n,o,a)}).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Pp(([e,t,s])=>{const i=kp(s).toVar(),r=kp(t).toVar(),n=kp(e).toVar(),o=Gp(Gp(3)).toVar(),a=Gp().toVar(),h=Gp().toVar(),u=Gp().toVar();return a.assign(h.assign(u.assign(Gp(kp(3735928559)).add(o.shiftLeft(Gp(2))).add(Gp(13))))),a.addAssign(Gp(n)),h.addAssign(Gp(r)),u.addAssign(Gp(i)),FB(a,h,u)}).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),Pp(([e,t,s,i])=>{const r=kp(i).toVar(),n=kp(s).toVar(),o=kp(t).toVar(),a=kp(e).toVar(),h=Gp(Gp(4)).toVar(),u=Gp().toVar(),l=Gp().toVar(),c=Gp().toVar();return u.assign(l.assign(c.assign(Gp(kp(3735928559)).add(h.shiftLeft(Gp(2))).add(Gp(13))))),u.addAssign(Gp(a)),l.addAssign(Gp(o)),c.addAssign(Gp(n)),PB(u,l,c),u.addAssign(Gp(r)),FB(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"}]}),Pp(([e,t,s,i,r])=>{const n=kp(r).toVar(),o=kp(i).toVar(),a=kp(s).toVar(),h=kp(t).toVar(),u=kp(e).toVar(),l=Gp(Gp(5)).toVar(),c=Gp().toVar(),d=Gp().toVar(),p=Gp().toVar();return c.assign(d.assign(p.assign(Gp(kp(3735928559)).add(l.shiftLeft(Gp(2))).add(Gp(13))))),c.addAssign(Gp(u)),d.addAssign(Gp(h)),p.addAssign(Gp(a)),PB(c,d,p),c.addAssign(Gp(o)),d.addAssign(Gp(n)),FB(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"}]})]),LB=PM([Pp(([e,t])=>{const s=kp(t).toVar(),i=kp(e).toVar(),r=Gp(OB(i,s)).toVar(),n=Zp().toVar();return n.x.assign(r.bitAnd(kp(255))),n.y.assign(r.shiftRight(kp(8)).bitAnd(kp(255))),n.z.assign(r.shiftRight(kp(16)).bitAnd(kp(255))),n}).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Pp(([e,t,s])=>{const i=kp(s).toVar(),r=kp(t).toVar(),n=kp(e).toVar(),o=Gp(OB(n,r,i)).toVar(),a=Zp().toVar();return a.x.assign(o.bitAnd(kp(255))),a.y.assign(o.shiftRight(kp(8)).bitAnd(kp(255))),a.z.assign(o.shiftRight(kp(16)).bitAnd(kp(255))),a}).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),VB=PM([Pp(([e])=>{const t=Hp(e).toVar(),s=kp().toVar(),i=kp().toVar(),r=Dp(bB(t.x,s)).toVar(),n=Dp(bB(t.y,i)).toVar(),o=Dp(UB(r)).toVar(),a=Dp(UB(n)).toVar(),h=Dp(vB(SB(OB(s,i),r,n),SB(OB(s.add(kp(1)),i),r.sub(1),n),SB(OB(s,i.add(kp(1))),r,n.sub(1)),SB(OB(s.add(kp(1)),i.add(kp(1))),r.sub(1),n.sub(1)),o,a)).toVar();return EB(h)}).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),Pp(([e])=>{const t=Xp(e).toVar(),s=kp().toVar(),i=kp().toVar(),r=kp().toVar(),n=Dp(bB(t.x,s)).toVar(),o=Dp(bB(t.y,i)).toVar(),a=Dp(bB(t.z,r)).toVar(),h=Dp(UB(n)).toVar(),u=Dp(UB(o)).toVar(),l=Dp(UB(a)).toVar(),c=Dp(TB(SB(OB(s,i,r),n,o,a),SB(OB(s.add(kp(1)),i,r),n.sub(1),o,a),SB(OB(s,i.add(kp(1)),r),n,o.sub(1),a),SB(OB(s.add(kp(1)),i.add(kp(1)),r),n.sub(1),o.sub(1),a),SB(OB(s,i,r.add(kp(1))),n,o,a.sub(1)),SB(OB(s.add(kp(1)),i,r.add(kp(1))),n.sub(1),o,a.sub(1)),SB(OB(s,i.add(kp(1)),r.add(kp(1))),n,o.sub(1),a.sub(1)),SB(OB(s.add(kp(1)),i.add(kp(1)),r.add(kp(1))),n.sub(1),o.sub(1),a.sub(1)),h,u,l)).toVar();return BB(c)}).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),DB=PM([Pp(([e])=>{const t=Hp(e).toVar(),s=kp().toVar(),i=kp().toVar(),r=Dp(bB(t.x,s)).toVar(),n=Dp(bB(t.y,i)).toVar(),o=Dp(UB(r)).toVar(),a=Dp(UB(n)).toVar(),h=Xp(vB(AB(LB(s,i),r,n),AB(LB(s.add(kp(1)),i),r.sub(1),n),AB(LB(s,i.add(kp(1))),r,n.sub(1)),AB(LB(s.add(kp(1)),i.add(kp(1))),r.sub(1),n.sub(1)),o,a)).toVar();return EB(h)}).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Pp(([e])=>{const t=Xp(e).toVar(),s=kp().toVar(),i=kp().toVar(),r=kp().toVar(),n=Dp(bB(t.x,s)).toVar(),o=Dp(bB(t.y,i)).toVar(),a=Dp(bB(t.z,r)).toVar(),h=Dp(UB(n)).toVar(),u=Dp(UB(o)).toVar(),l=Dp(UB(a)).toVar(),c=Xp(TB(AB(LB(s,i,r),n,o,a),AB(LB(s.add(kp(1)),i,r),n.sub(1),o,a),AB(LB(s,i.add(kp(1)),r),n,o.sub(1),a),AB(LB(s.add(kp(1)),i.add(kp(1)),r),n.sub(1),o.sub(1),a),AB(LB(s,i,r.add(kp(1))),n,o,a.sub(1)),AB(LB(s.add(kp(1)),i,r.add(kp(1))),n.sub(1),o,a.sub(1)),AB(LB(s,i.add(kp(1)),r.add(kp(1))),n,o.sub(1),a.sub(1)),AB(LB(s.add(kp(1)),i.add(kp(1)),r.add(kp(1))),n.sub(1),o.sub(1),a.sub(1)),h,u,l)).toVar();return BB(c)}).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),kB=PM([Pp(([e])=>{const t=Dp(e).toVar(),s=kp(xB(t)).toVar();return zB(OB(s))}).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),Pp(([e])=>{const t=Hp(e).toVar(),s=kp(xB(t.x)).toVar(),i=kp(xB(t.y)).toVar();return zB(OB(s,i))}).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),Pp(([e])=>{const t=Xp(e).toVar(),s=kp(xB(t.x)).toVar(),i=kp(xB(t.y)).toVar(),r=kp(xB(t.z)).toVar();return zB(OB(s,i,r))}).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),Pp(([e])=>{const t=Kp(e).toVar(),s=kp(xB(t.x)).toVar(),i=kp(xB(t.y)).toVar(),r=kp(xB(t.z)).toVar(),n=kp(xB(t.w)).toVar();return zB(OB(s,i,r,n))}).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),GB=PM([Pp(([e])=>{const t=Dp(e).toVar(),s=kp(xB(t)).toVar();return Xp(zB(OB(s,kp(0))),zB(OB(s,kp(1))),zB(OB(s,kp(2))))}).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),Pp(([e])=>{const t=Hp(e).toVar(),s=kp(xB(t.x)).toVar(),i=kp(xB(t.y)).toVar();return Xp(zB(OB(s,i,kp(0))),zB(OB(s,i,kp(1))),zB(OB(s,i,kp(2))))}).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Pp(([e])=>{const t=Xp(e).toVar(),s=kp(xB(t.x)).toVar(),i=kp(xB(t.y)).toVar(),r=kp(xB(t.z)).toVar();return Xp(zB(OB(s,i,r,kp(0))),zB(OB(s,i,r,kp(1))),zB(OB(s,i,r,kp(2))))}).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Pp(([e])=>{const t=Kp(e).toVar(),s=kp(xB(t.x)).toVar(),i=kp(xB(t.y)).toVar(),r=kp(xB(t.z)).toVar(),n=kp(xB(t.w)).toVar();return Xp(zB(OB(s,i,r,n,kp(0))),zB(OB(s,i,r,n,kp(1))),zB(OB(s,i,r,n,kp(2))))}).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),WB=Pp(([e,t,s,i])=>{const r=Dp(i).toVar(),n=Dp(s).toVar(),o=kp(t).toVar(),a=Xp(e).toVar(),h=Dp(0).toVar(),u=Dp(1).toVar();return wv(o,()=>{h.addAssign(u.mul(VB(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"}]}),HB=Pp(([e,t,s,i])=>{const r=Dp(i).toVar(),n=Dp(s).toVar(),o=kp(t).toVar(),a=Xp(e).toVar(),h=Xp(0).toVar(),u=Dp(1).toVar();return wv(o,()=>{h.addAssign(u.mul(DB(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"}]}),jB=Pp(([e,t,s,i])=>{const r=Dp(i).toVar(),n=Dp(s).toVar(),o=kp(t).toVar(),a=Xp(e).toVar();return Hp(WB(a,o,n,r),WB(a.add(Xp(kp(19),kp(193),kp(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"}]}),qB=Pp(([e,t,s,i])=>{const r=Dp(i).toVar(),n=Dp(s).toVar(),o=kp(t).toVar(),a=Xp(e).toVar(),h=Xp(HB(a,o,n,r)).toVar(),u=Dp(WB(a.add(Xp(kp(19),kp(193),kp(17))),o,n,r)).toVar();return Kp(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"}]}),$B=Pp(([e,t,s,i,r,n,o])=>{const a=kp(o).toVar(),h=Dp(n).toVar(),u=kp(r).toVar(),l=kp(i).toVar(),c=kp(s).toVar(),d=kp(t).toVar(),p=Hp(e).toVar(),m=Xp(GB(Hp(d.add(l),c.add(u)))).toVar(),g=Hp(m.x,m.y).toVar();g.subAssign(.5),g.mulAssign(h),g.addAssign(.5);const f=Hp(Hp(Dp(d),Dp(c)).add(g)).toVar(),y=Hp(f.sub(p)).toVar();return Op(a.equal(kp(2)),()=>Xg(y.x).add(Xg(y.y))),Op(a.equal(kp(3)),()=>lf(Xg(y.x),Xg(y.y))),ff(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"}]}),XB=PM([$B,Pp(([e,t,s,i,r,n,o,a,h])=>{const u=kp(h).toVar(),l=Dp(a).toVar(),c=kp(o).toVar(),d=kp(n).toVar(),p=kp(r).toVar(),m=kp(i).toVar(),g=kp(s).toVar(),f=kp(t).toVar(),y=Xp(e).toVar(),x=Xp(GB(Xp(f.add(p),g.add(d),m.add(c)))).toVar();x.subAssign(.5),x.mulAssign(l),x.addAssign(.5);const b=Xp(Xp(Dp(f),Dp(g),Dp(m)).add(x)).toVar(),v=Xp(b.sub(y)).toVar();return Op(u.equal(kp(2)),()=>Xg(v.x).add(Xg(v.y)).add(Xg(v.z))),Op(u.equal(kp(3)),()=>lf(lf(Xg(v.x),Xg(v.y)),Xg(v.z))),ff(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"}]})]),YB=Pp(([e,t,s])=>{const i=kp(s).toVar(),r=Dp(t).toVar(),n=Hp(e).toVar(),o=kp().toVar(),a=kp().toVar(),h=Hp(bB(n.x,o),bB(n.y,a)).toVar(),u=Dp(1e6).toVar();return wv({start:-1,end:kp(1),name:"x",condition:"<="},({x:e})=>{wv({start:-1,end:kp(1),name:"y",condition:"<="},({y:t})=>{const s=Dp(XB(h,e,t,o,a,r,i)).toVar();u.assign(uf(u,s))})}),Op(i.equal(kp(0)),()=>{u.assign(Ug(u))}),u}).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),ZB=Pp(([e,t,s])=>{const i=kp(s).toVar(),r=Dp(t).toVar(),n=Hp(e).toVar(),o=kp().toVar(),a=kp().toVar(),h=Hp(bB(n.x,o),bB(n.y,a)).toVar(),u=Hp(1e6,1e6).toVar();return wv({start:-1,end:kp(1),name:"x",condition:"<="},({x:e})=>{wv({start:-1,end:kp(1),name:"y",condition:"<="},({y:t})=>{const s=Dp(XB(h,e,t,o,a,r,i)).toVar();Op(s.lessThan(u.x),()=>{u.y.assign(u.x),u.x.assign(s)}).ElseIf(s.lessThan(u.y),()=>{u.y.assign(s)})})}),Op(i.equal(kp(0)),()=>{u.assign(Ug(u))}),u}).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),JB=Pp(([e,t,s])=>{const i=kp(s).toVar(),r=Dp(t).toVar(),n=Hp(e).toVar(),o=kp().toVar(),a=kp().toVar(),h=Hp(bB(n.x,o),bB(n.y,a)).toVar(),u=Xp(1e6,1e6,1e6).toVar();return wv({start:-1,end:kp(1),name:"x",condition:"<="},({x:e})=>{wv({start:-1,end:kp(1),name:"y",condition:"<="},({y:t})=>{const s=Dp(XB(h,e,t,o,a,r,i)).toVar();Op(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)})})}),Op(i.equal(kp(0)),()=>{u.assign(Ug(u))}),u}).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),KB=PM([YB,Pp(([e,t,s])=>{const i=kp(s).toVar(),r=Dp(t).toVar(),n=Xp(e).toVar(),o=kp().toVar(),a=kp().toVar(),h=kp().toVar(),u=Xp(bB(n.x,o),bB(n.y,a),bB(n.z,h)).toVar(),l=Dp(1e6).toVar();return wv({start:-1,end:kp(1),name:"x",condition:"<="},({x:e})=>{wv({start:-1,end:kp(1),name:"y",condition:"<="},({y:t})=>{wv({start:-1,end:kp(1),name:"z",condition:"<="},({z:s})=>{const n=Dp(XB(u,e,t,s,o,a,h,r,i)).toVar();l.assign(uf(l,n))})})}),Op(i.equal(kp(0)),()=>{l.assign(Ug(l))}),l}).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),QB=PM([ZB,Pp(([e,t,s])=>{const i=kp(s).toVar(),r=Dp(t).toVar(),n=Xp(e).toVar(),o=kp().toVar(),a=kp().toVar(),h=kp().toVar(),u=Xp(bB(n.x,o),bB(n.y,a),bB(n.z,h)).toVar(),l=Hp(1e6,1e6).toVar();return wv({start:-1,end:kp(1),name:"x",condition:"<="},({x:e})=>{wv({start:-1,end:kp(1),name:"y",condition:"<="},({y:t})=>{wv({start:-1,end:kp(1),name:"z",condition:"<="},({z:s})=>{const n=Dp(XB(u,e,t,s,o,a,h,r,i)).toVar();Op(n.lessThan(l.x),()=>{l.y.assign(l.x),l.x.assign(n)}).ElseIf(n.lessThan(l.y),()=>{l.y.assign(n)})})})}),Op(i.equal(kp(0)),()=>{l.assign(Ug(l))}),l}).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),eI=PM([JB,Pp(([e,t,s])=>{const i=kp(s).toVar(),r=Dp(t).toVar(),n=Xp(e).toVar(),o=kp().toVar(),a=kp().toVar(),h=kp().toVar(),u=Xp(bB(n.x,o),bB(n.y,a),bB(n.z,h)).toVar(),l=Xp(1e6,1e6,1e6).toVar();return wv({start:-1,end:kp(1),name:"x",condition:"<="},({x:e})=>{wv({start:-1,end:kp(1),name:"y",condition:"<="},({y:t})=>{wv({start:-1,end:kp(1),name:"z",condition:"<="},({z:s})=>{const n=Dp(XB(u,e,t,s,o,a,h,r,i)).toVar();Op(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)})})})}),Op(i.equal(kp(0)),()=>{l.assign(Ug(l))}),l}).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),tI=Pp(([e])=>{const t=e.y,s=e.z,i=Xp().toVar();return Op(t.lessThan(1e-4),()=>{i.assign(Xp(s,s,s))}).Else(()=>{let r=e.x;r=r.sub(Lg(r)).mul(6).toVar();const n=kp(rf(r)),o=r.sub(Dp(n)),a=s.mul(t.oneMinus()),h=s.mul(t.mul(o).oneMinus()),u=s.mul(t.mul(o.oneMinus()).oneMinus());Op(n.equal(kp(0)),()=>{i.assign(Xp(s,u,a))}).ElseIf(n.equal(kp(1)),()=>{i.assign(Xp(h,s,a))}).ElseIf(n.equal(kp(2)),()=>{i.assign(Xp(a,s,u))}).ElseIf(n.equal(kp(3)),()=>{i.assign(Xp(a,h,s))}).ElseIf(n.equal(kp(4)),()=>{i.assign(Xp(u,a,s))}).Else(()=>{i.assign(Xp(s,a,h))})}),i}).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),sI=Pp(([e])=>{const t=Xp(e).toVar(),s=Dp(t.x).toVar(),i=Dp(t.y).toVar(),r=Dp(t.z).toVar(),n=Dp(uf(s,uf(i,r))).toVar(),o=Dp(lf(s,lf(i,r))).toVar(),a=Dp(o.sub(n)).toVar(),h=Dp().toVar(),u=Dp().toVar(),l=Dp().toVar();return l.assign(o),Op(o.greaterThan(0),()=>{u.assign(a.div(o))}).Else(()=>{u.assign(0)}),Op(u.lessThanEqual(0),()=>{h.assign(0)}).Else(()=>{Op(s.greaterThanEqual(o),()=>{h.assign(i.sub(r).div(a))}).ElseIf(i.greaterThanEqual(o),()=>{h.assign(eg(2,r.sub(s).div(a)))}).Else(()=>{h.assign(eg(4,s.sub(i).div(a)))}),h.mulAssign(1/6),Op(h.lessThan(0),()=>{h.addAssign(1)})}),Xp(h,u,l)}).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),iI=Pp(([e])=>{const t=Xp(e).toVar(),s=Jp(hg(t,Xp(.04045))).toVar(),i=Xp(t.div(12.92)).toVar(),r=Xp(xf(lf(t.add(Xp(.055)),Xp(0)).div(1.055),Xp(2.4))).toVar();return Mf(i,r,s)}).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),rI=(e,t)=>{e=Dp(e),t=Dp(t);const s=Hp(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return Rf(e.sub(s),e.add(s),t)},nI=(e,t,s,i)=>Mf(e,t,s[i].clamp()),oI=(e,t,s=Ry())=>nI(e,t,s,"x"),aI=(e,t,s=Ry())=>nI(e,t,s,"y"),hI=(e,t,s,i,r)=>Mf(e,t,rI(s,i[r])),uI=(e,t,s,i=Ry())=>hI(e,t,s,i,"x"),lI=(e,t,s,i=Ry())=>hI(e,t,s,i,"y"),cI=(e=1,t=0,s=Ry())=>s.mul(e).add(t),dI=(e,t=1)=>(e=Dp(e)).abs().pow(t).mul(e.sign()),pI=(e,t=1,s=.5)=>Dp(e).sub(s).mul(t).add(s),mI=(e=Ry(),t=1,s=0)=>VB(e.convert("vec2|vec3")).mul(t).add(s),gI=(e=Ry(),t=1,s=0)=>DB(e.convert("vec2|vec3")).mul(t).add(s),fI=(e=Ry(),t=1,s=0)=>{e=e.convert("vec2|vec3");return Kp(DB(e),VB(e.add(Hp(19,73)))).mul(t).add(s)},yI=(e=Ry(),t=1)=>KB(e.convert("vec2|vec3"),t,kp(1)),xI=(e=Ry(),t=1)=>QB(e.convert("vec2|vec3"),t,kp(1)),bI=(e=Ry(),t=1)=>eI(e.convert("vec2|vec3"),t,kp(1)),vI=(e=Ry())=>kB(e.convert("vec2|vec3")),TI=(e=Ry(),t=3,s=2,i=.5,r=1)=>WB(e,kp(t),s,i).mul(r),_I=(e=Ry(),t=3,s=2,i=.5,r=1)=>jB(e,kp(t),s,i).mul(r),wI=(e=Ry(),t=3,s=2,i=.5,r=1)=>HB(e,kp(t),s,i).mul(r),SI=(e=Ry(),t=3,s=2,i=.5,r=1)=>qB(e,kp(t),s,i).mul(r),MI=Pp(([e,t])=>{const s=e.x,i=e.y,r=e.z;let n=t.element(0).mul(.886227);return n=n.add(t.element(1).mul(1.023328).mul(i)),n=n.add(t.element(2).mul(1.023328).mul(r)),n=n.add(t.element(3).mul(1.023328).mul(s)),n=n.add(t.element(4).mul(.858086).mul(s).mul(i)),n=n.add(t.element(5).mul(.858086).mul(i).mul(r)),n=n.add(t.element(6).mul(r.mul(r).mul(.743125).sub(.247708))),n=n.add(t.element(7).mul(.858086).mul(s).mul(r)),n=n.add(t.element(8).mul(.429043).mul(sg(s,s).sub(sg(i,i)))),n});class NI extends tE{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=ym(0).setGroup(mm),this.decayExponentNode=ym(0).setGroup(mm)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setup(e){const{colorNode:t,cutoffDistanceNode:s,decayExponentNode:i,light:r}=this,n=e.context.lightingModel,o=aE(r).sub(gx),a=o.normalize(),h=o.length(),u=sE({lightDistance:h,cutoffDistance:s,decayExponent:i}),l=t.mul(u),c=e.context.reflectedLight;n.direct({lightDirection:a,lightColor:l,reflectedLight:c},e.stack,e)}}class AI extends tE{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setup(e){super.setup(e);const t=e.context.lightingModel,s=this.colorNode,i=hE(this.light),r=e.context.reflectedLight;t.direct({lightDirection:i,lightColor:s,reflectedLight:r},e.stack,e)}}const CI=new or,RI=new or;let EI=null;class BI extends tE{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=ym(new Ei).setGroup(mm),this.halfWidth=ym(new Ei).setGroup(mm)}update(e){super.update(e);const{light:t}=this,s=e.camera.matrixWorldInverse;RI.identity(),CI.copy(t.matrixWorld),CI.premultiply(s),RI.extractRotation(CI),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(RI),this.halfHeight.value.applyMatrix4(RI)}setup(e){let t,s;super.setup(e),e.isAvailable("float32Filterable")?(t=zy(EI.LTC_FLOAT_1),s=zy(EI.LTC_FLOAT_2)):(t=zy(EI.LTC_HALF_1),s=zy(EI.LTC_HALF_2));const{colorNode:i,light:r}=this,n=e.context.lightingModel,o=aE(r),a=e.context.reflectedLight;n.directRectArea({lightColor:i,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:t,ltc_2:s},e.stack,e)}static setLTC(e){EI=e}}class II extends tE{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=ym(0).setGroup(mm),this.penumbraCosNode=ym(0).setGroup(mm),this.cutoffDistanceNode=ym(0).setGroup(mm),this.decayExponentNode=ym(0).setGroup(mm)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e){const{coneCosNode:t,penumbraCosNode:s}=this;return Rf(t,s,e)}setup(e){super.setup(e);const t=e.context.lightingModel,{colorNode:s,cutoffDistanceNode:i,decayExponentNode:r,light:n}=this,o=aE(n).sub(gx),a=o.normalize(),h=a.dot(hE(n)),u=this.getSpotAttenuation(h),l=o.length(),c=sE({lightDistance:l,cutoffDistance:i,decayExponent:r}),d=s.mul(u).mul(c),p=e.context.reflectedLight;t.direct({lightDirection:a,lightColor:d,reflectedLight:p},e.stack,e)}}class PI extends II{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){const t=this.light.iesMap;let s=null;if(t&&!0===t.isTexture){const i=e.acos().mul(1/Math.PI);s=zy(t,Hp(i,0),0).r}else s=super.getSpotAttenuation(e);return s}}class FI extends tE{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class zI extends tE{static get type(){return"HemisphereLightNode"}constructor(e=null){super(e),this.lightPositionNode=nE(e),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=ym(new Kr).setGroup(mm)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:s,lightDirectionNode:i}=this,r=wx.dot(i).mul(.5).add(.5),n=Mf(s,t,r);e.context.irradiance.addAssign(n)}}class UI extends tE{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let e=0;e<9;e++)t.push(new Ei);this.lightProbe=kx(t)}update(e){const{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){const t=MI(Sx,this.lightProbe);e.context.irradiance.addAssign(t)}}class OI{parseFunction(){console.warn("Abstract function.")}}class LI{constructor(e,t,s="",i=""){this.type=e,this.inputs=t,this.name=s,this.precision=i}getCode(){console.warn("Abstract function.")}}LI.isNodeFunction=!0;const VI=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,DI=/[a-z_0-9]+/gi,kI="#pragma main";class GI extends LI{constructor(e){const{type:t,inputs:s,name:i,precision:r,inputsCode:n,blockCode:o,headerCode:a}=(e=>{const t=(e=e.trim()).indexOf(kI),s=-1!==t?e.slice(t+12):e,i=s.match(VI);if(null!==i&&5===i.length){const r=i[4],n=[];let o=null;for(;null!==(o=DI.exec(r));)n.push(o);const a=[];let h=0;for(;h<n.length;){const e="const"===n[h][0];!0===e&&h++;let t=n[h][0];"in"===t||"out"===t||"inout"===t?h++:t="";const s=n[h++][0];let i=Number.parseInt(n[h][0]);!1===Number.isNaN(i)?h++:i=null;const r=n[h++][0];a.push(new SM(s,r,i,t,e))}const u=s.substring(i[0].length),l=void 0!==i[3]?i[3]:"";return{type:i[2],inputs:a,name:l,precision:void 0!==i[1]?i[1]:"",inputsCode:r,blockCode:u,headerCode:-1!==t?e.slice(0,t):""}}throw new Error("FunctionNode: Function is not a GLSL code.")})(e);super(t,s,i,r),this.inputsCode=n,this.blockCode=o,this.headerCode=a}getCode(e=this.name){let t;const s=this.blockCode;if(""!==s){const{type:i,inputsCode:r,headerCode:n,precision:o}=this;let a=`${i} ${e} ( ${r.trim()} )`;""!==o&&(a=`${o} ${a}`),t=n+a+s}else t="";return t}}class WI extends OI{parseFunction(e){return new GI(e)}}function HI(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.material.id!==t.material.id?e.material.id-t.material.id:e.z!==t.z?e.z-t.z:e.id-t.id}function jI(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}class qI{constructor(){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparent=[],this.bundles=[],this.lightsNode=new Fv([]),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(e,t,s,i,r,n){let o=this.renderItems[this.renderItemsIndex];return void 0===o?(o={id:e.id,object:e,geometry:t,material:s,groupOrder:i,renderOrder:e.renderOrder,z:r,group:n},this.renderItems[this.renderItemsIndex]=o):(o.id=e.id,o.object=e,o.geometry=t,o.material=s,o.groupOrder=i,o.renderOrder=e.renderOrder,o.z=r,o.group=n),this.renderItemsIndex++,o}push(e,t,s,i,r,n){const o=this.getNextRenderItem(e,t,s,i,r,n);!0===e.occlusionTest&&this.occlusionQueryCount++,(!0===s.transparent||s.transmission>0?this.transparent:this.opaque).push(o)}unshift(e,t,s,i,r,n){const o=this.getNextRenderItem(e,t,s,i,r,n);(!0===s.transparent?this.transparent:this.opaque).unshift(o)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}getLightsNode(){return this.lightsNode.fromLights(this.lightsArray)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||HI),this.transparent.length>1&&this.transparent.sort(t||jI)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){const t=this.renderItems[e];if(null===t.id)break;t.id=null,t.object=null,t.geometry=null,t.material=null,t.groupOrder=null,t.renderOrder=null,t.z=null,t.group=null}}}class $I{constructor(){this.lists=new jw}get(e,t){const s=this.lists,i=[e,t];let r=s.get(i);return void 0===r&&(r=new qI,s.set(i,r)),r}dispose(){this.lists=new jw}}let XI=0;class YI{constructor(){this.id=XI++,this.color=!0,this.clearColor=!0,this.clearColorValue={r:0,g:0,b:0,a:1},this.depth=!0,this.clearDepth=!0,this.clearDepthValue=1,this.stencil=!1,this.clearStencil=!0,this.clearStencilValue=1,this.viewport=!1,this.viewportValue=new _i,this.scissor=!1,this.scissorValue=new _i,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.sampleCount=1,this.width=0,this.height=0,this.isRenderContext=!0}getCacheKey(){return ZI(this)}}function ZI(e){const{textures:t,activeCubeFace:s}=e,i=[s];for(const e of t)i.push(e.id);return Md(i)}class JI{constructor(){this.chainMaps={}}get(e,t,s=null){const i=[e,t];let r;if(null===s)r="default";else{const e=s.texture.format;r=`${s.textures.length}:${e}:${s.samples}:${s.depthBuffer}:${s.stencilBuffer}`}const n=this.getChainMap(r);let o=n.get(i);return void 0===o&&(o=new YI,n.set(i,o)),null!==s&&(o.sampleCount=0===s.samples?1:s.samples),o}getChainMap(e){return this.chainMaps[e]||(this.chainMaps[e]=new jw)}dispose(){this.chainMaps={}}}const KI=new Ei;class QI extends Kw{constructor(e,t,s){super(),this.renderer=e,this.backend=t,this.info=s}updateRenderTarget(e,t=0){const s=this.get(e),i=0===e.samples?1:e.samples,r=s.depthTextureMips||(s.depthTextureMips={}),n=e.textures,o=this.getSize(n[0]),a=o.width>>t,h=o.height>>t;let u=e.depthTexture||r[t],l=!1;void 0===u&&(u=new Qa,u.format=e.stencilBuffer?je:He,u.type=e.stencilBuffer?Ue:Be,u.image.width=a,u.image.height=h,r[t]=u),s.width===o.width&&o.height===s.height||(l=!0,u.needsUpdate=!0,u.image.width=a,u.image.height=h),s.width=o.width,s.height=o.height,s.textures=n,s.depthTexture=u,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==i&&(l=!0,u.needsUpdate=!0,s.sampleCount=i);const c={sampleCount:i};for(let e=0;e<n.length;e++){const t=n[e];l&&(t.needsUpdate=!0),this.updateTexture(t,c)}if(this.updateTexture(u,c),!0!==s.initialized){s.initialized=!0;const t=()=>{e.removeEventListener("dispose",t);for(let e=0;e<n.length;e++)this._destroyTexture(n[e]);this._destroyTexture(u),this.delete(e)};e.addEventListener("dispose",t)}}updateTexture(e,t={}){const s=this.get(e);if(!0===s.initialized&&s.version===e.version)return;const i=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,r=this.backend;if(i&&!0===s.initialized&&(r.destroySampler(e),r.destroyTexture(e)),e.isFramebufferTexture){const t=this.renderer.getRenderTarget();e.type=t?t.texture.type:Ne}const{width:n,height:o,depth:a}=this.getSize(e);if(t.width=n,t.height=o,t.depth=a,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,n,o):1,i||!0===e.isStorageTexture)r.createSampler(e),r.createTexture(e,t),s.generation=e.version;else{if(!0!==s.initialized&&r.createSampler(e),e.version>0){const i=e.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(e.images){const s=[];for(const t of e.images)s.push(t);t.images=s}else t.image=i;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(r.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),!0===e.source.dataReady&&r.updateTexture(e,t),t.needsMipmaps&&0===e.mipmaps.length&&r.generateMipmaps(e)}}else r.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version}if(!0!==s.initialized){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const t=()=>{e.removeEventListener("dispose",t),this._destroyTexture(e),this.info.memory.textures--};e.addEventListener("dispose",t)}s.version=e.version}getSize(e,t=KI){let s=e.images?e.images[0]:e.image;return s?(void 0!==s.image&&(s=s.image),t.width=s.width,t.height=s.height,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let i;return i=e.isCompressedTexture?e.mipmaps.length:Math.floor(Math.log2(Math.max(t,s)))+1,i}needsMipmaps(e){return!!this.isEnvironmentTexture(e)||(!0===e.isCompressedTexture||e.minFilter!==fe&&e.minFilter!==Te)}isEnvironmentTexture(e){const t=e.mapping;return t===le||t===ce||t===he||t===ue}_destroyTexture(e){this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e)}}class eP extends Kr{constructor(e,t,s,i=1){super(e,t,s),this.a=i}set(e,t,s,i=1){return this.a=i,super.set(e,t,s)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}const tP=new eP;class sP extends Kw{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){const i=this.renderer,r=this.nodes.getBackgroundNode(e)||e.background;let n=!1;if(null===r)i._clearColor.getRGB(tP,Kt),tP.a=i._clearColor.a;else if(!0===r.isColor)r.getRGB(tP,Kt),tP.a=1,n=!0;else if(!0===r.isNode){const s=this.get(e),n=r;tP.copy(i._clearColor);let o=s.backgroundMesh;if(void 0===o){const e=Lf(Kp(n).mul(AN),{getUV:()=>Sx,getTextureLevel:()=>NN});let t=ov();t=t.setZ(t.w);const i=new yT;i.name="Background.material",i.side=1,i.depthTest=!1,i.depthWrite=!1,i.fog=!1,i.lights=!1,i.vertexNode=t,i.colorNode=e,s.backgroundMeshNode=e,s.backgroundMesh=o=new Dn(new fu(1,32,32),i),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(e,t,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=n.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=Kp(n).mul(AN),s.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,s.backgroundCacheKey=a),t.unshift(o,o.geometry,o.material,0,0,null)}else console.error("THREE.Renderer: Unsupported background configuration.",r);if(!0===i.autoClear||!0===n){tP.multiplyScalar(tP.a);const e=s.clearColorValue;e.r=tP.r,e.g=tP.g,e.b=tP.b,e.a=tP.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 iP{constructor(e,t,s,i,r,n,o,a,h,u=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=u,this.nodeAttributes=i,this.bindings=r,this.updateNodes=n,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=h,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings){if(!0!==t.bindings[0].groupNode.shared){const s=new yM(t.name,[],t.index,t);e.push(s);for(const e of t.bindings)s.bindings.push(e.clone())}else e.push(t)}return e}}const rP=new WeakMap;class nP extends Kw{constructor(e,t){super(),this.renderer=e,this.backend=t,this.nodeFrame=new wM,this.nodeBuilderCache=new Map,this.callHashCache=new jw,this.groupsData=new jw}updateGroup(e){const t=e.groupNode,s=t.name;if(s===gm.name)return!0;if(s===mm.name){const t=this.get(e),s=this.nodeFrame.renderId;return t.renderId!==s&&(t.renderId=s,!0)}if(s===pm.name){const t=this.get(e),s=this.nodeFrame.frameId;return t.frameId!==s&&(t.frameId=s,!0)}const i=[t,e];let r=this.groupsData.get(i);return void 0===r&&this.groupsData.set(i,r={}),r.version!==t.version&&(r.version=t.version,!0)}getForRenderCacheKey(e){return e.initialCacheKey}getForRender(e){const t=this.get(e);let s=t.nodeBuilderState;if(void 0===s){const{nodeBuilderCache:i}=this,r=this.getForRenderCacheKey(e);if(s=i.get(r),void 0===s){const t=this.backend.createNodeBuilder(e.object,this.renderer);t.scene=e.scene,t.material=e.material,t.camera=e.camera,t.context.material=e.material,t.lightsNode=e.lightsNode,t.environmentNode=this.getEnvironmentNode(e.scene),t.fogNode=this.getFogNode(e.scene),t.clippingContext=e.clippingContext,t.build(),s=this._createNodeBuilderState(t),i.set(r,s)}s.usedTimes++,t.nodeBuilderState=s}return s}delete(e){if(e.isRenderObject){const t=this.get(e).nodeBuilderState;t.usedTimes--,0===t.usedTimes&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(e))}return super.delete(e)}getForCompute(e){const t=this.get(e);let s=t.nodeBuilderState;if(void 0===s){const i=this.backend.createNodeBuilder(e,this.renderer);i.build(),s=this._createNodeBuilderState(i),t.nodeBuilderState=s}return s}_createNodeBuilderState(e){return new iP(e.vertexShader,e.fragmentShader,e.computeShader,e.getAttributesArray(),e.getBindings(),e.updateNodes,e.updateBeforeNodes,e.updateAfterNodes,e.monitor,e.transforms)}getEnvironmentNode(e){return e.environmentNode||this.get(e).environmentNode||null}getBackgroundNode(e){return e.backgroundNode||this.get(e).backgroundNode||null}getFogNode(e){return e.fogNode||this.get(e).fogNode||null}getCacheKey(e,t){const s=[e,t],i=this.renderer.info.calls;let r=this.callHashCache.get(s);if(void 0===r||r.callId!==i){const n=this.getEnvironmentNode(e),o=this.getFogNode(e),a=[];t&&a.push(t.getCacheKey(!0)),n&&a.push(n.getCacheKey()),o&&a.push(o.getCacheKey()),a.push(this.renderer.shadowMap.enabled?1:0),r={callId:i,cacheKey:Md(a)},this.callHashCache.set(s,r)}return r.cacheKey}updateScene(e){this.updateEnvironment(e),this.updateFog(e),this.updateBackground(e)}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(e){const t=this.get(e),s=e.background;if(s){const i=0===e.backgroundBlurriness&&t.backgroundBlurriness>0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;if(t.background!==s||i){let i=null;if(!0===s.isCubeTexture||s.mapping===le||s.mapping===ce||s.mapping===de)if(e.backgroundBlurriness>0||s.mapping===de)i=dw(s,Sx);else{let e;e=!0===s.isCubeTexture?Ux(s):zy(s),i=OT(e)}else!0===s.isTexture?i=zy(s,Hv.flipY()).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s);t.backgroundNode=i,t.background=s,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}updateFog(e){const t=this.get(e),s=e.fog;if(s){if(t.fog!==s){let e=null;if(s.isFogExp2){const t=jx("color","color",s).setGroup(mm),i=jx("density","float",s).setGroup(mm);e=kR(t,i)}else if(s.isFog){const t=jx("color","color",s).setGroup(mm),i=jx("near","float",s).setGroup(mm),r=jx("far","float",s).setGroup(mm);e=VR(t,i,r)}else console.error("WebGPUNodes: Unsupported fog configuration.",s);t.fogNode=e,t.fog=s}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),s=e.environment;if(s){if(t.environment!==s){let e=null;!0===s.isCubeTexture?e=Ux(s):!0===s.isTexture?e=zy(s):console.error("Nodes: Unsupported environment configuration.",s),t.environmentNode=e,t.environment=s}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,s=null,i=null,r=null){const n=this.nodeFrame;return n.renderer=e,n.scene=t,n.object=s,n.camera=i,n.material=r,n}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace}hasOutputChange(e){return rP.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,s=this.getOutputCacheKey(),i=zy(e,Hv).renderOutput(t.toneMapping,t.currentColorSpace);return rP.set(e,s),i}updateBefore(e){const t=e.getNodeBuilderState();for(const s of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(s)}updateAfter(e){const t=e.getNodeBuilderState();for(const s of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(s)}updateForCompute(e){const t=this.getNodeFrame(),s=this.getForCompute(e);for(const e of s.updateNodes)t.updateNode(e)}updateForRender(e){const t=this.getNodeFrameForRender(e),s=e.getNodeBuilderState();for(const e of s.updateNodes)t.updateNode(e)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new wM,this.nodeBuilderCache=new Map}}class oP{constructor(e,t){this.scene=e,this.camera=t}clone(){return Object.assign(new this.constructor,this)}}class aP{constructor(){this.lists=new jw}get(e,t){const s=this.lists,i=[e,t];let r=s.get(i);return void 0===r&&(r=new oP(e,t),s.set(i,r)),r}dispose(){this.lists=new jw}}class hP{constructor(){this.lightNodes=new WeakMap,this.materialNodes=new Map,this.toneMappingNodes=new Map,this.colorSpaceNodes=new Map}fromMaterial(e){if(e.isNodeMaterial)return e;let t=null;const s=this.getMaterialNodeClass(e.type);if(null!==s){t=new s;for(const s in e)t[s]=e[s]}return t}addColorSpace(e,t){this.addType(e,t,this.colorSpaceNodes)}getColorSpaceFunction(e){return this.colorSpaceNodes.get(e)||null}addToneMapping(e,t){this.addType(e,t,this.toneMappingNodes)}getToneMappingFunction(e){return this.toneMappingNodes.get(e)||null}getMaterialNodeClass(e){return this.materialNodes.get(e)||null}addMaterial(e,t){this.addType(e,t.name,this.materialNodes)}getLightNodeClass(e){return this.lightNodes.get(e)||null}addLight(e,t){this.addClass(e,t,this.lightNodes)}addType(e,t,s){if(s.has(t))console.warn(`Redefinition of node ${t}`);else{if("function"!=typeof e)throw new Error(`Node class ${e.name} is not a class.`);if("function"==typeof t||"object"==typeof t)throw new Error(`Base class ${t} is not a class.`);s.set(t,e)}}addClass(e,t,s){if(s.has(t))console.warn(`Redefinition of node ${t.name}`);else{if("function"!=typeof e)throw new Error(`Node class ${e.name} is not a class.`);if("function"!=typeof t)throw new Error(`Base class ${t.name} is not a class.`);s.set(t,e)}}}const uP=new no,lP=new ei,cP=new _i,dP=new na,pP=new or,mP=new _i;class gP{constructor(e,t={}){this.isRenderer=!0;const{logarithmicDepthBuffer:s=!1,alpha:i=!0,depth:r=!0,stencil:n=!1,antialias:o=!1,samples:a=0,getFallback:h=null}=t;this.domElement=e.getDomElement(),this.backend=e,this.samples=a||!0===o?4:0,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=i,this.logarithmicDepthBuffer=s,this.outputColorSpace=Jt,this.toneMapping=0,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=r,this.stencil=n,this.clippingPlanes=[],this.info=new aS,this.nodes={library:new hP,modelViewMatrix:null,modelNormalViewMatrix:null},this._getFallback=h,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 fN(new yT),this._quad.material.type="Renderer_output",this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;const u=!0===this.alpha?0:1;this._clearColor=new eP(0,0,0,u),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.transparent=!0,this.opaque=!0,this.shadowMap={enabled:!1,type:1},this.xr={enabled:!1},this.debug={checkShaderErrors:!0,onShaderError:null,getShaderAsync:async(e,t,s)=>{await this.compileAsync(e,t);const i=this._renderLists.get(e,t),r=this._renderContexts.get(e,t,this._renderTarget),n=e.overrideMaterial||s.material,o=this._objects.get(s,n,e,t,i.lightsNode,r),{fragmentShader:a,vertexShader:h}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:h}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise(async(e,t)=>{let s=this.backend;try{await s.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=s=this._getFallback(e),await s.init(this)}catch(e){return void t(e)}}this._nodes=new nP(this,s),this._animation=new Hw(this._nodes,this.info),this._attributes=new iS(s),this._background=new sP(this,this._nodes),this._geometries=new oS(this._attributes,this.info),this._textures=new QI(this,s,this.info),this._pipelines=new pS(s,this._nodes),this._bindings=new mS(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Jw(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new $I,this._bundles=new aP,this._renderContexts=new JI,this._initialized=!0,e()})),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,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===e.isScene?e:uP;null===s&&(s=e);const u=this._renderTarget,l=this._renderContexts.get(s,t,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 $w),l.clippingContext.updateGlobal(this,t),h.onBeforeRender(this,e,t,u);const p=this._renderLists.get(e,t);if(p.begin(),this._projectObject(e,t,0,p),s!==e&&s.traverseVisible(function(e){e.isLight&&e.layers.test(t.layers)&&p.pushLight(e)}),p.finish(),null!==u){this._textures.updateRenderTarget(u,c);const e=this._textures.get(u);l.textures=e.textures,l.depthTexture=e.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;!0===this.opaque&&m.length>0&&this._renderObjects(m,t,h,f),!0===this.transparent&&g.length>0&&this._renderObjects(g,t,h,f),i.renderId=r,this._currentRenderContext=n,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(d)}async renderAsync(e,t){!1===this._initialized&&await this.init();const s=this._renderScene(e,t);await this.backend.resolveTimestampAsync(s,"render")}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}_renderBundle(e,t,s){const{bundleGroup:i,camera:r,renderList:n}=e,o=this._currentRenderContext,a=this._bundles.get(i,r),h=this.backend.get(a);void 0===h.renderContexts&&(h.renderContexts=new Set);const u=i.version!==h.version,l=!1===h.renderContexts.has(o)||u;if(h.renderContexts.add(o),l){this.backend.beginBundle(o),(void 0===h.renderObjects||u)&&(h.renderObjects=[]),this._currentRenderBundle=a;const e=n.opaque;e.length>0&&this._renderObjects(e,r,t,s),this._currentRenderBundle=null,this.backend.finishBundle(o,a),h.version=i.version}else{const{renderObjects:e}=h;for(let t=0,s=e.length;t<s;t++){const s=e[t];this._nodes.needsRefresh(s)&&(this._nodes.updateBefore(s),this._nodes.updateForRender(s),this._bindings.updateForRender(s),this._nodes.updateAfter(s))}}this.backend.addBundle(o,a)}render(e,t){if(!1===this._initialized)return console.warn("THREE.Renderer: .render() called before the backend is initialized. Try using .renderAsync() instead."),this.renderAsync(e,t);this._renderScene(e,t)}_getFrameBufferTarget(){const{currentToneMapping:e,currentColorSpace:t}=this;if(!1===(0!==e)&&!1===(t!==Kt))return null;const{width:s,height:i}=this.getDrawingBufferSize(lP),{depth:r,stencil:n}=this;let o=this._frameBufferTarget;return null===o&&(o=new wi(s,i,{depthBuffer:r,stencilBuffer:n,type:Pe,format:ke,colorSpace:Kt,generateMipmaps:!1,minFilter:Te,magFilter:Te,samples:this.samples}),o.isPostProcessingRenderTarget=!0,this._frameBufferTarget=o),o.depthBuffer=r,o.stencilBuffer=n,o.setSize(s,i),o.viewport.copy(this._viewport),o.scissor.copy(this._scissor),o.viewport.multiplyScalar(this._pixelRatio),o.scissor.multiplyScalar(this._pixelRatio),o.scissorTest=this._scissorTest,o}_renderScene(e,t,s=!0){const i=s?this._getFrameBufferTarget():null,r=this._nodes.nodeFrame,n=r.renderId,o=this._currentRenderContext,a=this._currentRenderObjectFunction,h=!0===e.isScene?e:uP,u=this._renderTarget,l=this._activeCubeFace,c=this._activeMipmapLevel;let d;null!==i?(d=i,this.setRenderTarget(d)):d=u;const p=this._renderContexts.get(e,t,d);this._currentRenderContext=p,this._currentRenderObjectFunction=this._renderObjectFunction||this.renderObject,this.info.calls++,this.info.render.calls++,this.info.render.frameCalls++,r.renderId=this.info.calls;const m=this.coordinateSystem;t.coordinateSystem!==m&&(t.coordinateSystem=m,t.updateProjectionMatrix()),!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld(),null===t.parent&&!0===t.matrixWorldAutoUpdate&&t.updateMatrixWorld();let g=this._viewport,f=this._scissor,y=this._pixelRatio;null!==d&&(g=d.viewport,f=d.scissor,y=1),this.getDrawingBufferSize(lP),cP.set(0,0,lP.width,lP.height);const x=void 0===g.minDepth?0:g.minDepth,b=void 0===g.maxDepth?1:g.maxDepth;p.viewportValue.copy(g).multiplyScalar(y).floor(),p.viewportValue.width>>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=x,p.viewportValue.maxDepth=b,p.viewport=!1===p.viewportValue.equals(cP),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(cP),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new $w),p.clippingContext.updateGlobal(this,t),h.onBeforeRender(this,e,t,d),pP.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),dP.setFromProjectionMatrix(pP,m);const v=this._renderLists.get(e,t);if(v.begin(),this._projectObject(e,t,0,v),v.finish(),!0===this.sortObjects&&v.sort(this._opaqueSort,this._transparentSort),null!==d){this._textures.updateRenderTarget(d,c);const e=this._textures.get(d);p.textures=e.textures,p.depthTexture=e.depthTexture,p.width=e.width,p.height=e.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{bundles:T,lightsNode:_,transparent:w,opaque:S}=v;if(T.length>0&&this._renderBundles(T,h,_),!0===this.opaque&&S.length>0&&this._renderObjects(S,t,h,_),!0===this.transparent&&w.length>0&&this._renderObjects(w,t,h,_),this.backend.finishRender(p),r.renderId=n,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==i){this.setRenderTarget(u,l,c);const e=this._quad;this._nodes.hasOutputChange(d.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(d.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}return h.onAfterRender(this,e,t,d),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio=e,this.setSize(this._width,this._height,!1)}setDrawingBufferSize(e,t,s){this._width=e,this._height=t,this._pixelRatio=s,this.domElement.width=Math.floor(e*s),this.domElement.height=Math.floor(t*s),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setSize(e,t,s=!0){this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===s&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,s,i){const r=this._scissor;e.isVector4?r.copy(e):r.set(e,t,s,i)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,s,i,r=0,n=1){const o=this._viewport;e.isVector4?o.copy(e):o.set(e,t,s,i),o.minDepth=r,o.maxDepth=n}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!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(e,t,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(e,t,s,r),null!==i&&null===this._renderTarget){const e=this._quad;this._nodes.hasOutputChange(i.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(i.texture),e.material.needsUpdate=!0),this._renderScene(e,e.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(e=!0,t=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(e,t,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?0:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Kt: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(e,t=0,s=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}async computeAsync(e){!1===this._initialized&&await this.init();const t=this._nodes.nodeFrame,s=t.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,t.renderId=this.info.calls;const i=this.backend,r=this._pipelines,n=this._bindings,o=this._nodes,a=Array.isArray(e)?e:[e];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");i.beginCompute(e);for(const t of a){if(!1===r.has(t)){const e=()=>{t.removeEventListener("dispose",e),r.delete(t),n.delete(t),o.delete(t)};t.addEventListener("dispose",e),t.onInit({renderer:this})}o.updateForCompute(t),n.updateForCompute(t);const s=n.getForCompute(t),a=r.getForCompute(t,s);i.compute(e,t,s,a)}i.finishCompute(e),await this.backend.resolveTimestampAsync(e,"compute"),t.renderId=s}async hasFeatureAsync(e){return!1===this._initialized&&await this.init(),this.backend.hasFeature(e)}hasFeature(e){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(e)}copyFramebufferToTexture(e,t=null){const s=this._currentRenderContext;this._textures.updateTexture(e),t=null===t?mP.set(0,0,e.image.width,e.image.height):t,this.backend.copyFramebufferToTexture(e,s,t)}copyTextureToTexture(e,t,s=null,i=null,r=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,s,i,r)}readRenderTargetPixelsAsync(e,t,s,i,r,n=0,o=0){return this.backend.copyTextureToBuffer(e.textures[n],t,s,i,r,o)}_projectObject(e,t,s,i){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)s=e.renderOrder;else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)i.pushLight(e);else if(e.isSprite){if(!e.frustumCulled||dP.intersectsSprite(e)){!0===this.sortObjects&&mP.setFromMatrixPosition(e.matrixWorld).applyMatrix4(pP);const{geometry:t,material:r}=e;r.visible&&i.push(e,t,r,s,mP.z,null)}}else if(e.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||dP.intersectsObject(e))){const{geometry:t,material:r}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),mP.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(pP)),Array.isArray(r)){const n=t.groups;for(let o=0,a=n.length;o<a;o++){const a=n[o],h=r[a.materialIndex];h&&h.visible&&i.push(e,t,h,s,mP.z,a)}}else r.visible&&i.push(e,t,r,s,mP.z,null)}if(!0===e.isBundleGroup&&void 0!==this.backend.beginBundle){const s=i;(i=this._renderLists.get(e,t)).begin(),s.pushBundle({bundleGroup:e,camera:t,renderList:i}),i.finish()}const r=e.children;for(let e=0,n=r.length;e<n;e++)this._projectObject(r[e],t,s,i)}_renderBundles(e,t,s){for(const i of e)this._renderBundle(i,t,s)}_renderObjects(e,t,s,i){for(let r=0,n=e.length;r<n;r++){const n=e[r],{object:o,geometry:a,material:h,group:u}=n;if(t.isArrayCamera){const e=t.cameras;for(let t=0,r=e.length;t<r;t++){const r=e[t];if(o.layers.test(r.layers)){const e=r.viewport,t=void 0===e.minDepth?0:e.minDepth,n=void 0===e.maxDepth?1:e.maxDepth,l=this._currentRenderContext.viewportValue;l.copy(e).multiplyScalar(this._pixelRatio).floor(),l.minDepth=t,l.maxDepth=n,this.backend.updateViewport(this._currentRenderContext),this._currentRenderObjectFunction(o,s,r,a,h,u,i)}}}else this._currentRenderObjectFunction(o,s,t,a,h,u,i)}}renderObject(e,t,s,i,r,n,o){let a,h,u;if(e.onBeforeRender(this,t,s,i,r,n),r.onBeforeRender(this,t,s,i,r,n),null!==t.overrideMaterial){const e=t.overrideMaterial;r.positionNode&&r.positionNode.isNode&&(a=e.positionNode,e.positionNode=r.positionNode),e.isShadowNodeMaterial&&(e.side=null===r.shadowSide?r.side:r.shadowSide,r.depthNode&&r.depthNode.isNode&&(u=e.depthNode,e.depthNode=r.depthNode),r.shadowNode&&r.shadowNode.isNode&&(h=e.fragmentNode,e.fragmentNode=r.shadowNode),this.localClippingEnabled&&(r.clipShadows?(e.clippingPlanes!==r.clippingPlanes&&(e.clippingPlanes=r.clippingPlanes,e.needsUpdate=!0),e.clipIntersection!==r.clipIntersection&&(e.clipIntersection=r.clipIntersection)):Array.isArray(e.clippingPlanes)&&(e.clippingPlanes=null,e.needsUpdate=!0))),r=e}!0===r.transparent&&2===r.side&&!1===r.forceSinglePass?(r.side=1,this._handleObjectFunction(e,r,t,s,o,n,"backSide"),r.side=0,this._handleObjectFunction(e,r,t,s,o,n),r.side=2):this._handleObjectFunction(e,r,t,s,o,n),void 0!==a&&(t.overrideMaterial.positionNode=a),void 0!==u&&(t.overrideMaterial.depthNode=u),void 0!==h&&(t.overrideMaterial.fragmentNode=h),e.onAfterRender(this,t,s,i,r,n)}_renderObjectDirect(e,t,s,i,r,n,o){const a=this._objects.get(e,t,s,i,r,this._currentRenderContext,o);a.drawRange=e.geometry.drawRange,a.group=n;const h=this._nodes.needsRefresh(a);if(h&&(this._nodes.updateBefore(a),this._geometries.updateForRender(a),this._nodes.updateForRender(a),this._bindings.updateForRender(a)),this._pipelines.updateForRender(a),null!==this._currentRenderBundle){this.backend.get(this._currentRenderBundle).renderObjects.push(a),a.bundle=this._currentRenderBundle.scene}this.backend.draw(a,this.info),h&&this._nodes.updateAfter(a)}_createObjectPipeline(e,t,s,i,r,n){const o=this._objects.get(e,t,s,i,r,this._currentRenderContext,n);this._nodes.updateBefore(o),this._geometries.updateForRender(o),this._nodes.updateForRender(o),this._bindings.updateForRender(o),this._pipelines.getForRender(o,this._compilationPromises),this._nodes.updateAfter(o)}get compute(){return this.computeAsync}get compile(){return this.compileAsync}}class fP{constructor(e=""){this.name=e,this.visibility=0}setVisibility(e){this.visibility|=e}clone(){return Object.assign(new this.constructor,this)}}class yP extends fP{constructor(e,t=null){super(e),this.isBuffer=!0,this.bytesPerElement=Float32Array.BYTES_PER_ELEMENT,this._buffer=t}get byteLength(){return(e=this._buffer.byteLength)+(sS-e%sS)%sS;var e}get buffer(){return this._buffer}update(){return!0}}class xP extends yP{constructor(e,t=null){super(e,t),this.isUniformBuffer=!0}}let bP=0;class vP extends xP{constructor(e,t){super("UniformBuffer_"+bP++,e?e.value:null),this.nodeUniform=e,this.groupNode=t}get buffer(){return this.nodeUniform.value}}class TP extends xP{constructor(e){super(e),this.isUniformsGroup=!0,this._values=null,this.uniforms=[]}addUniform(e){return this.uniforms.push(e),this}removeUniform(e){const t=this.uniforms.indexOf(e);return-1!==t&&this.uniforms.splice(t,1),this}get values(){return null===this._values&&(this._values=Array.from(this.buffer)),this._values}get buffer(){let e=this._buffer;if(null===e){const t=this.byteLength;e=new Float32Array(new ArrayBuffer(t)),this._buffer=e}return e}get byteLength(){let e=0;for(let t=0,s=this.uniforms.length;t<s;t++){const s=this.uniforms[t],{boundary:i,itemSize:r}=s,n=e%sS;0!==n&&sS-n-i<0?e+=sS-n:n%i!==0&&(e+=n%i),s.offset=e/this.bytesPerElement,e+=r*this.bytesPerElement}return Math.ceil(e/sS)*sS}update(){let e=!1;for(const t of this.uniforms)!0===this.updateByType(t)&&(e=!0);return e}updateByType(e){return e.isNumberUniform?this.updateNumber(e):e.isVector2Uniform?this.updateVector2(e):e.isVector3Uniform?this.updateVector3(e):e.isVector4Uniform?this.updateVector4(e):e.isColorUniform?this.updateColor(e):e.isMatrix3Uniform?this.updateMatrix3(e):e.isMatrix4Uniform?this.updateMatrix4(e):void console.error("THREE.WebGPUUniformsGroup: Unsupported uniform type.",e)}updateNumber(e){let t=!1;const s=this.values,i=e.getValue(),r=e.offset;if(s[r]!==i){this.buffer[r]=s[r]=i,t=!0}return t}updateVector2(e){let t=!1;const s=this.values,i=e.getValue(),r=e.offset;if(s[r+0]!==i.x||s[r+1]!==i.y){const e=this.buffer;e[r+0]=s[r+0]=i.x,e[r+1]=s[r+1]=i.y,t=!0}return t}updateVector3(e){let t=!1;const s=this.values,i=e.getValue(),r=e.offset;if(s[r+0]!==i.x||s[r+1]!==i.y||s[r+2]!==i.z){const e=this.buffer;e[r+0]=s[r+0]=i.x,e[r+1]=s[r+1]=i.y,e[r+2]=s[r+2]=i.z,t=!0}return t}updateVector4(e){let t=!1;const s=this.values,i=e.getValue(),r=e.offset;if(s[r+0]!==i.x||s[r+1]!==i.y||s[r+2]!==i.z||s[r+4]!==i.w){const e=this.buffer;e[r+0]=s[r+0]=i.x,e[r+1]=s[r+1]=i.y,e[r+2]=s[r+2]=i.z,e[r+3]=s[r+3]=i.w,t=!0}return t}updateColor(e){let t=!1;const s=this.values,i=e.getValue(),r=e.offset;if(s[r+0]!==i.r||s[r+1]!==i.g||s[r+2]!==i.b){const e=this.buffer;e[r+0]=s[r+0]=i.r,e[r+1]=s[r+1]=i.g,e[r+2]=s[r+2]=i.b,t=!0}return t}updateMatrix3(e){let t=!1;const s=this.values,i=e.getValue().elements,r=e.offset;if(s[r+0]!==i[0]||s[r+1]!==i[1]||s[r+2]!==i[2]||s[r+4]!==i[3]||s[r+5]!==i[4]||s[r+6]!==i[5]||s[r+8]!==i[6]||s[r+9]!==i[7]||s[r+10]!==i[8]){const e=this.buffer;e[r+0]=s[r+0]=i[0],e[r+1]=s[r+1]=i[1],e[r+2]=s[r+2]=i[2],e[r+4]=s[r+4]=i[3],e[r+5]=s[r+5]=i[4],e[r+6]=s[r+6]=i[5],e[r+8]=s[r+8]=i[6],e[r+9]=s[r+9]=i[7],e[r+10]=s[r+10]=i[8],t=!0}return t}updateMatrix4(e){let t=!1;const s=this.values,i=e.getValue().elements,r=e.offset;if(!1===function(e,t,s){for(let i=0,r=t.length;i<r;i++)if(e[s+i]!==t[i])return!1;return!0}(s,i,r)){this.buffer.set(i,r),function(e,t,s){for(let i=0,r=t.length;i<r;i++)e[s+i]=t[i]}(s,i,r),t=!0}return t}}let _P=0;class wP extends TP{constructor(e,t){super(e),this.id=_P++,this.groupNode=t,this.isNodeUniformsGroup=!0}getNodes(){const e=[];for(const t of this.uniforms){const s=t.nodeUniform.node;if(!s)throw new Error("NodeUniformsGroup: Uniform has no node.");e.push(s)}return e}}let SP=0;class MP extends fP{constructor(e,t){super(e),this.id=SP++,this.texture=t,this.version=t?t.version:0,this.store=!1,this.generation=null,this.isSampledTexture=!0}needsBindingsUpdate(e){const{texture:t}=this;return e!==this.generation?(this.generation=e,!0):t.isVideoTexture}update(){const{texture:e,version:t}=this;return t!==e.version&&(this.version=e.version,!0)}}class NP extends MP{constructor(e,t,s,i=null){super(e,t?t.value:null),this.textureNode=t,this.groupNode=s,this.access=i}needsBindingsUpdate(e){return this.textureNode.value!==this.texture||super.needsBindingsUpdate(e)}update(){const{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}}class AP extends NP{constructor(e,t,s,i){super(e,t,s,i),this.isSampledCubeTexture=!0}}class CP extends NP{constructor(e,t,s,i){super(e,t,s,i),this.isSampledTexture3D=!0}}const RP={atan2:"atan",textureDimensions:"textureSize",equals:"equal"},EP={low:"lowp",medium:"mediump",high:"highp"},BP={swizzleAssign:!0,storageBuffer:!1},IP="\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\nprecision highp sampler3D;\nprecision highp samplerCube;\nprecision highp sampler2DArray;\n\nprecision highp usampler2D;\nprecision highp usampler3D;\nprecision highp usamplerCube;\nprecision highp usampler2DArray;\n\nprecision highp isampler2D;\nprecision highp isampler3D;\nprecision highp isamplerCube;\nprecision highp isampler2DArray;\n\nprecision lowp sampler2DShadow;\n";class PP extends _M{constructor(e,t){super(e,t,new WI),this.uniformGroups={},this.transforms=[],this.extensions={},this.useComparisonMethod=!0}needsColorSpaceToLinearSRGB(e){return!0===e.isVideoTexture&&e.colorSpace!==Zt}getMethod(e){return RP[e]||e}getOutputStructName(){return""}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),i=[];for(const e of t.inputs)i.push(this.getType(e.type)+" "+e.name);return`${this.getType(t.type)} ${t.name}( ${i.join(", ")} ) {\n\n\t${s.vars}\n\n${s.code}\n\treturn ${s.result};\n\n}`}setupPBO(e){const t=e.value;if(void 0===t.pbo){const e=t.array,s=t.count*t.itemSize,{itemSize:i}=t,r=t.array.constructor.name.toLowerCase().includes("int");let n=r?$e:qe;2===i?n=r?Ye:Xe:3===i?n=r?1032:De:4===i&&(n=r?Je:ke);const o={Float32Array:Ie,Uint8Array:Ne,Uint16Array:Re,Uint32Array:Be,Int8Array:Ae,Int16Array:Ce,Int32Array:Ee,Uint8ClampedArray:Ne},a=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(s/i))));let h=Math.ceil(s/i/a);a*h*i<s&&h++;const u=a*h*i,l=new e.constructor(u);l.set(e,0),t.array=l;const c=new Do(t.array,a,h,n,o[t.array.constructor.name]||Ie);c.needsUpdate=!0,c.isPBOTexture=!0;const d=new Fy(c,null,null);d.setPrecision("high"),t.pboNode=d,t.pbo=d.value,this.getUniformFromNode(t.pboNode,"texture",this.shaderStage,this.context.label)}}getPropertyName(e,t=this.shaderStage){return e.isNodeUniform&&!0!==e.node.isTextureNode&&!0!==e.node.isBufferNode?t.charAt(0)+"_"+e.name:super.getPropertyName(e,t)}generatePBO(e){const{node:t,indexNode:s}=e,i=t.value;if(this.renderer.backend.has(i)){this.renderer.backend.get(i).pbo=i.pbo}const r=this.getUniformFromNode(i.pboNode,"texture",this.shaderStage,this.context.label),n=this.getPropertyName(r);this.increaseUsage(s);const o=s.build(this,"uint"),a=this.getDataFromNode(e);let h=a.propertyName;if(void 0===h){const s=this.getVarFromNode(e);h=this.getPropertyName(s);const r=this.getDataFromNode(t);let u=r.propertySizeName;void 0===u&&(u=h+"Size",this.getVarFromNode(t,u,"uint"),this.addLineFlowCode(`${u} = uint( textureSize( ${n}, 0 ).x )`,e),r.propertySizeName=u);const{itemSize:l}=i,c="."+Dd.join("").slice(0,l),d=`ivec2(${o} % ${u}, ${o} / ${u})`,p=this.generateTextureLoad(null,n,d,null,"0");let m="vec4";i.pbo.type===Be?m="uvec4":i.pbo.type===Ee&&(m="ivec4"),this.addLineFlowCode(`${h} = ${m}(${p})${c}`,e),a.propertyName=h}return h}generateTextureLoad(e,t,s,i,r="0"){return i?`texelFetch( ${t}, ivec3( ${s}, ${i} ), ${r} )`:`texelFetch( ${t}, ${s}, ${r} )`}generateTexture(e,t,s,i){return e.isDepthTexture?`texture( ${t}, ${s} ).x`:(i&&(s=`vec3( ${s}, ${i} )`),`texture( ${t}, ${s} )`)}generateTextureLevel(e,t,s,i){return`textureLod( ${t}, ${s}, ${i} )`}generateTextureBias(e,t,s,i){return`texture( ${t}, ${s}, ${i} )`}generateTextureGrad(e,t,s,i){return`textureGrad( ${t}, ${s}, ${i[0]}, ${i[1]} )`}generateTextureCompare(e,t,s,i,r,n=this.shaderStage){if("fragment"===n)return`texture( ${t}, vec3( ${s}, ${i} ) )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}getVars(e){const t=[],s=this.vars[e];if(void 0!==s)for(const e of s)t.push(`${this.getVar(e.type,e.name)};`);return t.join("\n\t")}getUniforms(e){const t=this.uniforms[e],s=[],i={};for(const r of t){let t=null,n=!1;if("texture"===r.type){const e=r.node.value;let s="";!0===e.isDataTexture&&(e.type===Be?s="u":e.type===Ee&&(s="i")),t=e.compareFunction?`sampler2DShadow ${r.name};`:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?`${s}sampler2DArray ${r.name};`:`${s}sampler2D ${r.name};`}else if("cubeTexture"===r.type)t=`samplerCube ${r.name};`;else if("texture3D"===r.type)t=`sampler3D ${r.name};`;else if("buffer"===r.type){const e=r.node,s=this.getType(e.bufferType),i=e.bufferCount,n=i>0?i:"";t=`${e.name} {\n\t${s} ${r.name}[${n}];\n};\n`}else{t=`${this.getVectorType(r.type)} ${this.getPropertyName(r,e)};`,n=!0}const o=r.node.precision;if(null!==o&&(t=EP[o]+" "+t),n){t="\t"+t;const e=r.groupNode.name;(i[e]||(i[e]=[])).push(t)}else t="uniform "+t,s.push(t)}let r="";for(const t in i){const s=i[t];r+=this._getGLSLUniformStruct(e+"_"+t,s.join("\n"))+"\n"}return r+=s.join("\n"),r}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==Ee){let s=e;e.isInterleavedBufferAttribute&&(s=e.data);const i=s.array;!1==(i instanceof Uint32Array||i instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){const e=this.getAttributesArray();let s=0;for(const i of e)t+=`layout( location = ${s++} ) in ${i.type} ${i.name};\n`}return t}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;e<s.length;e++){const i=s[e];t.push(`layout( location = ${e} ) out ${i} m${e};`)}return t.join("\n")}getStructs(e){const t=[],s=this.structs[e];if(0===s.length)return"layout( location = 0 ) out vec4 fragColor;\n";for(let e=0,i=s.length;e<i;e++){const i=s[e];let r="\n";r+=this.getStructMembers(i),r+="\n",t.push(r)}return t.join("\n\n")}getVaryings(e){let t="";const s=this.varyings;if("vertex"===e||"compute"===e)for(const i of s){"compute"===e&&(i.needsInterpolation=!0);const s=i.type;t+=`${s.includes("int")||s.includes("uv")||s.includes("iv")?"flat ":""}${i.needsInterpolation?"out":"/*out*/"} ${s} ${i.name};\n`}else if("fragment"===e)for(const e of s)if(e.needsInterpolation){const s=e.type;t+=`${s.includes("int")||s.includes("uv")||s.includes("iv")?"flat ":""}in ${s} ${e.name};\n`}return t}getVertexIndex(){return"uint( gl_VertexID )"}getInstanceIndex(){return"uint( gl_InstanceID )"}getInvocationLocalIndex(){return`uint( gl_InstanceID ) % ${this.object.workgroupSize.reduce((e,t)=>e*t,1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,s=this.shaderStage){const i=this.extensions[s]||(this.extensions[s]=new Map);!1===i.has(e)&&i.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if("vertex"===e){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const s=this.extensions[e];if(void 0!==s)for(const{name:e,behavior:i}of s.values())t.push(`#extension ${e} : ${i}`);return t.join("\n")}isAvailable(e){let t=BP[e];if(void 0===t){if("float32Filterable"===e){const e=this.renderer.backend.extensions;e.has("OES_texture_float_linear")?(e.get("OES_texture_float_linear"),t=!0):t=!1}BP[e]=t}return t}isFlipY(){return!0}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){const e=this.transforms;let t="";for(let s=0;s<e.length;s++){const i=e[s],r=this.getPropertyName(i.attributeNode);t+=`${i.varyingName} = ${r};\n\t`}return t}_getGLSLUniformStruct(e,t){return`\nlayout( std140 ) uniform ${e} {\n${t}\n};`}_getGLSLVertexCode(e){return`#version 300 es\n\n${this.getSignature()}\n\n// extensions \n${e.extensions}\n\n// precision\n${IP}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\n\n// attributes\n${e.attributes}\n\n// codes\n${e.codes}\n\nvoid main() {\n\n\t// vars\n\t${e.vars}\n\n\t// transforms\n\t${e.transforms}\n\n\t// flow\n\t${e.flow}\n\n\tgl_PointSize = 1.0;\n\n}\n`}_getGLSLFragmentCode(e){return`#version 300 es\n\n${this.getSignature()}\n\n// precision\n${IP}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\n\n// codes\n${e.codes}\n\n${e.structs}\n\nvoid main() {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){let s="// code\n\n";s+=this.flowCode[t];const i=this.flowNodes[t],r=i[i.length-1];for(const e of i){const i=this.getFlowData(e),n=e.name;n&&(s.length>0&&(s+="\n"),s+=`\t// flow -> ${n}\n\t`),s+=`${i.code}\n\t`,e===r&&"compute"!==t&&(s+="// result\n\t","vertex"===t?(s+="gl_Position = ",s+=`${i.result};`):"fragment"===t&&(e.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${i.result};`)))}const n=e[t];n.extensions=this.getExtensions(t),n.uniforms=this.getUniforms(t),n.attributes=this.getAttributes(t),n.varyings=this.getVaryings(t),n.vars=this.getVars(t),n.structs=this.getStructs(t),n.codes=this.getCodes(t),n.transforms=this.getTransforms(t),n.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,s,i=null){const r=super.getUniformFromNode(e,t,s,i),n=this.getDataFromNode(e,s,this.globalCache);let o=n.uniformGPU;if(void 0===o){const i=e.groupNode,a=i.name,h=this.getBindGroupArray(a,s);if("texture"===t)o=new NP(r.name,r.node,i),h.push(o);else if("cubeTexture"===t)o=new AP(r.name,r.node,i),h.push(o);else if("texture3D"===t)o=new CP(r.name,r.node,i),h.push(o);else if("buffer"===t){e.name=`NodeBuffer_${e.id}`,r.name=`buffer${e.id}`;const t=new vP(e,i);t.name=e.name,h.push(t),o=t}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=e[a];void 0===n&&(n=new wP(s+"_"+a,i),e[a]=n,h.push(n)),o=this.getNodeUniform(r,t),n.addUniform(o)}n.uniformGPU=o}return r}}let FP=null,zP=null,UP=null;class OP{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(e){this.renderer=e}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(e){const{object:t,geometry:s}=e;return s.isInstancedBufferGeometry?s.instanceCount:t.count>1?t.count:1}getDrawingBufferSize(){return FP=FP||new ei,this.renderer.getDrawingBufferSize(FP)}getScissor(){return zP=zP||new _i,this.renderer.getScissor(zP)}setScissorTest(){}getClearColor(){const e=this.renderer;return UP=UP||new eP,e.getClearColor(UP),UP.getRGB(UP,this.renderer.currentColorSpace),UP}getDomElement(){let t=this.domElement;return null===t&&(t=void 0!==this.parameters.canvas?this.parameters.canvas:oi(),"setAttribute"in t&&t.setAttribute("data-engine",`three.js r${e} webgpu`),this.domElement=t),t}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}}let LP=0;class VP{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.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 DP{constructor(e){this.backend=e}createAttribute(e,t){const s=this.backend,{gl:i}=s,r=e.array,n=e.usage||i.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,a=s.get(o);let h,u=a.bufferGPU;if(void 0===u&&(u=this._createBuffer(i,t,r,n),a.bufferGPU=u,a.bufferType=t,a.version=o.version),r instanceof Float32Array)h=i.FLOAT;else if(r instanceof Uint16Array)h=e.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:t,type:h,byteLength:r.byteLength,bytesPerElement:r.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:h===i.INT||h===i.UNSIGNED_INT||e.gpuType===Ee,id:LP++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const e=this._createBuffer(i,t,r,n);l=new VP(l,e)}s.set(e,l)}updateAttribute(e){const t=this.backend,{gl:s}=t,i=e.array,r=e.isInterleavedBufferAttribute?e.data:e,n=t.get(r),o=n.bufferType,a=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(s.bindBuffer(o,n.bufferGPU),0===a.length)s.bufferSubData(o,0,i);else{for(let e=0,t=a.length;e<t;e++){const t=a[e];s.bufferSubData(o,t.start*i.BYTES_PER_ELEMENT,i,t.start,t.count)}r.clearUpdateRanges()}s.bindBuffer(o,null),n.version=r.version}destroyAttribute(e){const t=this.backend,{gl:s}=t;e.isInterleavedBufferAttribute&&t.delete(e.data);const i=t.get(e);s.deleteBuffer(i.bufferGPU),t.delete(e)}async getArrayBufferAsync(e){const t=this.backend,{gl:s}=t,i=e.isInterleavedBufferAttribute?e.data:e,{bufferGPU:r}=t.get(i),n=e.array,o=n.byteLength;s.bindBuffer(s.COPY_READ_BUFFER,r);const a=s.createBuffer();s.bindBuffer(s.COPY_WRITE_BUFFER,a),s.bufferData(s.COPY_WRITE_BUFFER,o,s.STREAM_READ),s.copyBufferSubData(s.COPY_READ_BUFFER,s.COPY_WRITE_BUFFER,0,0,o),await t.utils._clientWaitAsync();const h=new e.array.constructor(n.length);return s.bindBuffer(s.COPY_WRITE_BUFFER,a),s.getBufferSubData(s.COPY_WRITE_BUFFER,0,h),s.deleteBuffer(a),s.bindBuffer(s.COPY_READ_BUFFER,null),s.bindBuffer(s.COPY_WRITE_BUFFER,null),h.buffer}_createBuffer(e,t,s,i){const r=e.createBuffer();return e.bindBuffer(t,r),e.bufferData(t,s,i),e.bindBuffer(t,null),r}}let kP,GP,WP=!1;class HP{constructor(e){this.backend=e,this.gl=this.backend.gl,this.enabled={},this.currentFlipSided=null,this.currentCullFace=null,this.currentProgram=null,this.currentBlendingEnabled=!1,this.currentBlending=null,this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentPremultipledAlpha=null,this.currentPolygonOffsetFactor=null,this.currentPolygonOffsetUnits=null,this.currentColorMask=null,this.currentDepthFunc=null,this.currentDepthMask=null,this.currentStencilFunc=null,this.currentStencilRef=null,this.currentStencilFuncMask=null,this.currentStencilFail=null,this.currentStencilZFail=null,this.currentStencilZPass=null,this.currentStencilMask=null,this.currentLineWidth=null,this.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.currentTextureSlot=null,this.currentBoundTextures={},this.currentBoundBufferBases={},!1===WP&&(this._init(this.gl),WP=!0)}_init(e){kP={[v]:e.FUNC_ADD,[T]:e.FUNC_SUBTRACT,[_]:e.FUNC_REVERSE_SUBTRACT},GP={[M]:e.ZERO,[N]:e.ONE,[A]:e.SRC_COLOR,[R]:e.SRC_ALPHA,[z]:e.SRC_ALPHA_SATURATE,[P]:e.DST_COLOR,[B]:e.DST_ALPHA,[C]:e.ONE_MINUS_SRC_COLOR,[E]:e.ONE_MINUS_SRC_ALPHA,[F]:e.ONE_MINUS_DST_COLOR,[I]:e.ONE_MINUS_DST_ALPHA}}enable(e){const{enabled:t}=this;!0!==t[e]&&(this.gl.enable(e),t[e]=!0)}disable(e){const{enabled:t}=this;!1!==t[e]&&(this.gl.disable(e),t[e]=!1)}setFlipSided(e){if(this.currentFlipSided!==e){const{gl:t}=this;e?t.frontFace(t.CW):t.frontFace(t.CCW),this.currentFlipSided=e}}setCullFace(e){const{gl:t}=this;0!==e?(this.enable(t.CULL_FACE),e!==this.currentCullFace&&(1===e?t.cullFace(t.BACK):2===e?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):this.disable(t.CULL_FACE),this.currentCullFace=e}setLineWidth(e){const{currentLineWidth:t,gl:s}=this;e!==t&&(s.lineWidth(e),this.currentLineWidth=e)}setBlending(e,t,s,i,r,n,o,a){const{gl:h}=this;if(0!==e){if(!1===this.currentBlendingEnabled&&(this.enable(h.BLEND),this.currentBlendingEnabled=!0),5===e)r=r||t,n=n||s,o=o||i,t===this.currentBlendEquation&&r===this.currentBlendEquationAlpha||(h.blendEquationSeparate(kP[t],kP[r]),this.currentBlendEquation=t,this.currentBlendEquationAlpha=r),s===this.currentBlendSrc&&i===this.currentBlendDst&&n===this.currentBlendSrcAlpha&&o===this.currentBlendDstAlpha||(h.blendFuncSeparate(GP[s],GP[i],GP[n],GP[o]),this.currentBlendSrc=s,this.currentBlendDst=i,this.currentBlendSrcAlpha=n,this.currentBlendDstAlpha=o),this.currentBlending=e,this.currentPremultipledAlpha=!1;else if(e!==this.currentBlending||a!==this.currentPremultipledAlpha){if(this.currentBlendEquation===v&&this.currentBlendEquationAlpha===v||(h.blendEquation(h.FUNC_ADD),this.currentBlendEquation=v,this.currentBlendEquationAlpha=v),a)switch(e){case 1:h.blendFuncSeparate(h.ONE,h.ONE_MINUS_SRC_ALPHA,h.ONE,h.ONE_MINUS_SRC_ALPHA);break;case 2:h.blendFunc(h.ONE,h.ONE);break;case 3:h.blendFuncSeparate(h.ZERO,h.ONE_MINUS_SRC_COLOR,h.ZERO,h.ONE);break;case 4:h.blendFuncSeparate(h.ZERO,h.SRC_COLOR,h.ZERO,h.SRC_ALPHA);break;default:console.error("THREE.WebGLState: Invalid blending: ",e)}else switch(e){case 1:h.blendFuncSeparate(h.SRC_ALPHA,h.ONE_MINUS_SRC_ALPHA,h.ONE,h.ONE_MINUS_SRC_ALPHA);break;case 2:h.blendFunc(h.SRC_ALPHA,h.ONE);break;case 3:h.blendFuncSeparate(h.ZERO,h.ONE_MINUS_SRC_COLOR,h.ZERO,h.ONE);break;case 4:h.blendFunc(h.ZERO,h.SRC_COLOR);break;default:console.error("THREE.WebGLState: Invalid blending: ",e)}this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlending=e,this.currentPremultipledAlpha=a}}else!0===this.currentBlendingEnabled&&(this.disable(h.BLEND),this.currentBlendingEnabled=!1)}setColorMask(e){this.currentColorMask!==e&&(this.gl.colorMask(e,e,e,e),this.currentColorMask=e)}setDepthTest(e){const{gl:t}=this;e?this.enable(t.DEPTH_TEST):this.disable(t.DEPTH_TEST)}setDepthMask(e){this.currentDepthMask!==e&&(this.gl.depthMask(e),this.currentDepthMask=e)}setDepthFunc(e){if(this.currentDepthFunc!==e){const{gl:t}=this;switch(e){case 0:t.depthFunc(t.NEVER);break;case 1:t.depthFunc(t.ALWAYS);break;case 2:t.depthFunc(t.LESS);break;case 3:default:t.depthFunc(t.LEQUAL);break;case 4:t.depthFunc(t.EQUAL);break;case 5:t.depthFunc(t.GEQUAL);break;case 6:t.depthFunc(t.GREATER);break;case 7:t.depthFunc(t.NOTEQUAL)}this.currentDepthFunc=e}}setStencilTest(e){const{gl:t}=this;e?this.enable(t.STENCIL_TEST):this.disable(t.STENCIL_TEST)}setStencilMask(e){this.currentStencilMask!==e&&(this.gl.stencilMask(e),this.currentStencilMask=e)}setStencilFunc(e,t,s){this.currentStencilFunc===e&&this.currentStencilRef===t&&this.currentStencilFuncMask===s||(this.gl.stencilFunc(e,t,s),this.currentStencilFunc=e,this.currentStencilRef=t,this.currentStencilFuncMask=s)}setStencilOp(e,t,s){this.currentStencilFail===e&&this.currentStencilZFail===t&&this.currentStencilZPass===s||(this.gl.stencilOp(e,t,s),this.currentStencilFail=e,this.currentStencilZFail=t,this.currentStencilZPass=s)}setMaterial(e,t){const{gl:s}=this;2===e.side?this.disable(s.CULL_FACE):this.enable(s.CULL_FACE);let i=1===e.side;t&&(i=!i),this.setFlipSided(i),1===e.blending&&!1===e.transparent?this.setBlending(0):this.setBlending(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.premultipliedAlpha),this.setDepthFunc(e.depthFunc),this.setDepthTest(e.depthTest),this.setDepthMask(e.depthWrite),this.setColorMask(e.colorWrite);const r=e.stencilWrite;this.setStencilTest(r),r&&(this.setStencilMask(e.stencilWriteMask),this.setStencilFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),this.setStencilOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),this.setPolygonOffset(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),!0===e.alphaToCoverage&&this.backend.renderer.samples>1?this.enable(s.SAMPLE_ALPHA_TO_COVERAGE):this.disable(s.SAMPLE_ALPHA_TO_COVERAGE)}setPolygonOffset(e,t,s){const{gl:i}=this;e?(this.enable(i.POLYGON_OFFSET_FILL),this.currentPolygonOffsetFactor===t&&this.currentPolygonOffsetUnits===s||(i.polygonOffset(t,s),this.currentPolygonOffsetFactor=t,this.currentPolygonOffsetUnits=s)):this.disable(i.POLYGON_OFFSET_FILL)}useProgram(e){return this.currentProgram!==e&&(this.gl.useProgram(e),this.currentProgram=e,!0)}bindFramebuffer(e,t){const{gl:s,currentBoundFramebuffers:i}=this;return i[e]!==t&&(s.bindFramebuffer(e,t),i[e]=t,e===s.DRAW_FRAMEBUFFER&&(i[s.FRAMEBUFFER]=t),e===s.FRAMEBUFFER&&(i[s.DRAW_FRAMEBUFFER]=t),!0)}drawBuffers(e,t){const{gl:s}=this;let i=[],r=!1;if(null!==e.textures){i=this.currentDrawbuffers.get(t),void 0===i&&(i=[],this.currentDrawbuffers.set(t,i));const n=e.textures;if(i.length!==n.length||i[0]!==s.COLOR_ATTACHMENT0){for(let e=0,t=n.length;e<t;e++)i[e]=s.COLOR_ATTACHMENT0+e;i.length=n.length,r=!0}}else i[0]!==s.BACK&&(i[0]=s.BACK,r=!0);r&&s.drawBuffers(i)}activeTexture(e){const{gl:t,currentTextureSlot:s,maxTextures:i}=this;void 0===e&&(e=t.TEXTURE0+i-1),s!==e&&(t.activeTexture(e),this.currentTextureSlot=e)}bindTexture(e,t,s){const{gl:i,currentTextureSlot:r,currentBoundTextures:n,maxTextures:o}=this;void 0===s&&(s=null===r?i.TEXTURE0+o-1:r);let a=n[s];void 0===a&&(a={type:void 0,texture:void 0},n[s]=a),a.type===e&&a.texture===t||(r!==s&&(i.activeTexture(s),this.currentTextureSlot=s),i.bindTexture(e,t),a.type=e,a.texture=t)}bindBufferBase(e,t,s){const{gl:i}=this,r=`${e}-${t}`;return this.currentBoundBufferBases[r]!==s&&(i.bindBufferBase(e,t,s),this.currentBoundBufferBases[r]=s,!0)}unbindTexture(){const{gl:e,currentTextureSlot:t,currentBoundTextures:s}=this,i=s[t];void 0!==i&&void 0!==i.type&&(e.bindTexture(i.type,null),i.type=void 0,i.texture=void 0)}}class jP{constructor(e){this.backend=e,this.gl=this.backend.gl,this.extensions=e.extensions}convert(e,t=""){const{gl:s,extensions:i}=this;let r;if(e===Ne)return s.UNSIGNED_BYTE;if(1017===e)return s.UNSIGNED_SHORT_4_4_4_4;if(1018===e)return s.UNSIGNED_SHORT_5_5_5_1;if(e===Oe)return s.UNSIGNED_INT_5_9_9_9_REV;if(35899===e)return s.UNSIGNED_INT_10F_11F_11F_REV;if(e===Ae)return s.BYTE;if(e===Ce)return s.SHORT;if(e===Re)return s.UNSIGNED_SHORT;if(e===Ee)return s.INT;if(e===Be)return s.UNSIGNED_INT;if(e===Ie)return s.FLOAT;if(e===Pe)return s.HALF_FLOAT;if(1021===e)return s.ALPHA;if(e===De)return s.RGB;if(e===ke)return s.RGBA;if(1024===e)return s.LUMINANCE;if(1025===e)return s.LUMINANCE_ALPHA;if(e===He)return s.DEPTH_COMPONENT;if(e===je)return s.DEPTH_STENCIL;if(e===qe)return s.RED;if(e===$e)return s.RED_INTEGER;if(e===Xe)return s.RG;if(e===Ye)return s.RG_INTEGER;if(e===Je)return s.RGBA_INTEGER;if(e===Ke||e===Qe||e===et||e===tt)if(t===Jt){if(r=i.get("WEBGL_compressed_texture_s3tc_srgb"),null===r)return null;if(e===Ke)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(e===Qe)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(e===et)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(e===tt)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(r=i.get("WEBGL_compressed_texture_s3tc"),null===r)return null;if(e===Ke)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(e===Qe)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(e===et)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(e===tt)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(e===st||e===it||e===rt||e===nt){if(r=i.get("WEBGL_compressed_texture_pvrtc"),null===r)return null;if(e===st)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(e===it)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(e===rt)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(e===nt)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(e===ot||e===at||e===ht){if(r=i.get("WEBGL_compressed_texture_etc"),null===r)return null;if(e===ot||e===at)return t===Jt?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(e===ht)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}if(e===ut||e===lt||e===ct||e===dt||e===pt||e===mt||e===gt||e===ft||e===yt||e===xt||e===bt||e===vt||e===Tt||e===_t){if(r=i.get("WEBGL_compressed_texture_astc"),null===r)return null;if(e===ut)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(e===lt)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(e===ct)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(e===dt)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(e===pt)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(e===mt)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(e===gt)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(e===ft)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(e===yt)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(e===xt)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(e===bt)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(e===vt)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(e===Tt)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(e===_t)return t===Jt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}if(e===wt){if(r=i.get("EXT_texture_compression_bptc"),null===r)return null;if(e===wt)return t===Jt?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT}if(36283===e||e===At||e===Ct||e===Rt){if(r=i.get("EXT_texture_compression_rgtc"),null===r)return null;if(e===wt)return r.COMPRESSED_RED_RGTC1_EXT;if(e===At)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(e===Ct)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(e===Rt)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return e===Ue?s.UNSIGNED_INT_24_8:void 0!==s[e]?s[e]:null}_clientWaitAsync(){const{gl:e}=this,t=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),new Promise((s,i)=>{!function r(){const n=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(n===e.WAIT_FAILED)return e.deleteSync(t),void i();n!==e.TIMEOUT_EXPIRED?(e.deleteSync(t),s()):requestAnimationFrame(r)}()})}}let qP,$P,XP,YP=!1;class ZP{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},!1===YP&&(this._init(this.gl),YP=!0)}_init(e){qP={[pe]:e.REPEAT,[me]:e.CLAMP_TO_EDGE,[ge]:e.MIRRORED_REPEAT},$P={[fe]:e.NEAREST,[ye]:e.NEAREST_MIPMAP_NEAREST,[be]:e.NEAREST_MIPMAP_LINEAR,[Te]:e.LINEAR,[_e]:e.LINEAR_MIPMAP_NEAREST,[Se]:e.LINEAR_MIPMAP_LINEAR},XP={[Ts]:e.NEVER,[Cs]:e.ALWAYS,[_s]:e.LESS,[Ss]:e.LEQUAL,[ws]:e.EQUAL,[As]:e.GEQUAL,[Ms]:e.GREATER,[Ns]:e.NOTEQUAL}}filterFallback(e){const{gl:t}=this;return e===fe||e===ye||e===be?t.NEAREST:t.LINEAR}getGLTextureType(e){const{gl:t}=this;let s;return s=!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D,s}getInternalFormat(e,t,s,i,r=!1){const{gl:n,extensions:o}=this;if(null!==e){if(void 0!==n[e])return n[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let a=t;return t===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)),t===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)),t===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)),t===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)),t===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===Jt&&!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),s===n.UNSIGNED_INT_10F_11F_11F_REV&&(a=n.R11F_G11F_B10F)),t===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)),t===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===Jt&&!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)),t===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)),t===n.DEPTH_COMPONENT&&(s===n.UNSIGNED_INT&&(a=n.DEPTH24_STENCIL8),s===n.FLOAT&&(a=n.DEPTH_COMPONENT32F)),t===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(e,t){const{gl:s,extensions:i,backend:r}=this;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),s.texParameteri(e,s.TEXTURE_WRAP_S,qP[t.wrapS]),s.texParameteri(e,s.TEXTURE_WRAP_T,qP[t.wrapT]),e!==s.TEXTURE_3D&&e!==s.TEXTURE_2D_ARRAY||s.texParameteri(e,s.TEXTURE_WRAP_R,qP[t.wrapR]),s.texParameteri(e,s.TEXTURE_MAG_FILTER,$P[t.magFilter]);const n=void 0!==t.mipmaps&&t.mipmaps.length>0,o=t.minFilter===Te&&n?Se:t.minFilter;if(s.texParameteri(e,s.TEXTURE_MIN_FILTER,$P[o]),t.compareFunction&&(s.texParameteri(e,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(e,s.TEXTURE_COMPARE_FUNC,XP[t.compareFunction])),!0===i.has("EXT_texture_filter_anisotropic")){if(t.magFilter===fe)return;if(t.minFilter!==be&&t.minFilter!==Se)return;if(t.type===Ie&&!1===i.has("OES_texture_float_linear"))return;if(t.anisotropy>1){const n=i.get("EXT_texture_filter_anisotropic");s.texParameterf(e,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,r.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:s,defaultTextures:i}=this,r=this.getGLTextureType(e);let n=i[r];void 0===n&&(n=t.createTexture(),s.state.bindTexture(r,n),t.texParameteri(r,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(r,t.TEXTURE_MAG_FILTER,t.NEAREST),i[r]=n),s.set(e,{textureGPU:n,glTextureType:r,isDefault:!0})}createTexture(e,t){const{gl:s,backend:i}=this,{levels:r,width:n,height:o,depth:a}=t,h=i.utils.convert(e.format,e.colorSpace),u=i.utils.convert(e.type),l=this.getInternalFormat(e.internalFormat,h,u,e.colorSpace,e.isVideoTexture),c=s.createTexture(),d=this.getGLTextureType(e);i.state.bindTexture(d,c),this.setTextureParameters(d,e),e.isDataArrayTexture||e.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,r,l,n,o,a):e.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,r,l,n,o,a):e.isVideoTexture||s.texStorage2D(d,r,l,n,o),i.set(e,{textureGPU:c,glTextureType:d,glFormat:h,glType:u,glInternalFormat:l})}copyBufferToTexture(e,t){const{gl:s,backend:i}=this,{textureGPU:r,glTextureType:n,glFormat:o,glType:a}=i.get(t),{width:h,height:u}=t.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,e),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(e,t){const{gl:s}=this,{width:i,height:r}=t,{textureGPU:n,glTextureType:o,glFormat:a,glType:h,glInternalFormat:u}=this.backend.get(e);if(e.isRenderTargetTexture||void 0===n)return;const l=e=>e.isDataTexture?e.image.data:e instanceof ImageBitmap||e instanceof OffscreenCanvas||e instanceof HTMLImageElement||e instanceof HTMLCanvasElement?e:e.data;if(this.backend.state.bindTexture(o,n),this.setTextureParameters(o,e),e.isCompressedTexture){const i=e.mipmaps,r=t.image;for(let t=0;t<i.length;t++){const n=i[t];e.isCompressedArrayTexture?e.format!==s.RGBA?null!==a?s.compressedTexSubImage3D(s.TEXTURE_2D_ARRAY,t,0,0,0,n.width,n.height,r.depth,a,n.data,0,0):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):s.texSubImage3D(s.TEXTURE_2D_ARRAY,t,0,0,0,n.width,n.height,r.depth,a,h,n.data):null!==a?s.compressedTexSubImage2D(s.TEXTURE_2D,t,0,0,n.width,n.height,a,n.data):console.warn("Unsupported compressed texture format")}}else if(e.isCubeTexture){const e=t.images;for(let t=0;t<6;t++){const n=l(e[t]);s.texSubImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,0,0,i,r,a,h,n)}}else if(e.isDataArrayTexture){const e=t.image;s.texSubImage3D(s.TEXTURE_2D_ARRAY,0,0,0,0,e.width,e.height,e.depth,a,h,e.data)}else if(e.isData3DTexture){const e=t.image;s.texSubImage3D(s.TEXTURE_3D,0,0,0,0,e.width,e.height,e.depth,a,h,e.data)}else if(e.isVideoTexture)e.update(),s.texImage2D(o,0,u,a,h,t.image);else{const e=l(t.image);s.texSubImage2D(o,0,0,0,i,r,a,h,e)}}generateMipmaps(e){const{gl:t,backend:s}=this,{textureGPU:i,glTextureType:r}=s.get(e);s.state.bindTexture(r,i),t.generateMipmap(r)}deallocateRenderBuffers(e){const{gl:t,backend:s}=this;if(e){const i=s.get(e);if(i.renderBufferStorageSetup=void 0,i.framebuffers){for(const e in i.framebuffers)t.deleteFramebuffer(i.framebuffers[e]);delete i.framebuffers}if(i.depthRenderbuffer&&(t.deleteRenderbuffer(i.depthRenderbuffer),delete i.depthRenderbuffer),i.stencilRenderbuffer&&(t.deleteRenderbuffer(i.stencilRenderbuffer),delete i.stencilRenderbuffer),i.msaaFrameBuffer&&(t.deleteFramebuffer(i.msaaFrameBuffer),delete i.msaaFrameBuffer),i.msaaRenderbuffers){for(let e=0;e<i.msaaRenderbuffers.length;e++)t.deleteRenderbuffer(i.msaaRenderbuffers[e]);delete i.msaaRenderbuffers}}}destroyTexture(e){const{gl:t,backend:s}=this,{textureGPU:i,renderTarget:r}=s.get(e);this.deallocateRenderBuffers(r),t.deleteTexture(i),s.delete(e)}copyTextureToTexture(e,t,s=null,i=null,r=0){const{gl:n,backend:o}=this,{state:a}=this.backend,{textureGPU:h,glTextureType:u,glType:l,glFormat:c}=o.get(t);let d,p,m,g,f,y;null!==s?(d=s.max.x-s.min.x,p=s.max.y-s.min.y,m=s.min.x,g=s.min.y):(d=e.image.width,p=e.image.height,m=0,g=0),null!==i?(f=i.x,y=i.y):(f=0,y=0),a.bindTexture(u,h),n.pixelStorei(n.UNPACK_ALIGNMENT,t.unpackAlignment),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,t.flipY),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),n.pixelStorei(n.UNPACK_ALIGNMENT,t.unpackAlignment);const x=n.getParameter(n.UNPACK_ROW_LENGTH),b=n.getParameter(n.UNPACK_IMAGE_HEIGHT),v=n.getParameter(n.UNPACK_SKIP_PIXELS),T=n.getParameter(n.UNPACK_SKIP_ROWS),_=n.getParameter(n.UNPACK_SKIP_IMAGES),w=e.isCompressedTexture?e.mipmaps[r]:e.image;n.pixelStorei(n.UNPACK_ROW_LENGTH,w.width),n.pixelStorei(n.UNPACK_IMAGE_HEIGHT,w.height),n.pixelStorei(n.UNPACK_SKIP_PIXELS,m),n.pixelStorei(n.UNPACK_SKIP_ROWS,g),e.isDataTexture?n.texSubImage2D(n.TEXTURE_2D,r,f,y,d,p,c,l,w.data):e.isCompressedTexture?n.compressedTexSubImage2D(n.TEXTURE_2D,r,f,y,w.width,w.height,c,w.data):n.texSubImage2D(n.TEXTURE_2D,r,f,y,d,p,c,l,w),n.pixelStorei(n.UNPACK_ROW_LENGTH,x),n.pixelStorei(n.UNPACK_IMAGE_HEIGHT,b),n.pixelStorei(n.UNPACK_SKIP_PIXELS,v),n.pixelStorei(n.UNPACK_SKIP_ROWS,T),n.pixelStorei(n.UNPACK_SKIP_IMAGES,_),0===r&&t.generateMipmaps&&n.generateMipmap(n.TEXTURE_2D),a.unbindTexture()}copyFramebufferToTexture(e,t,s){const{gl:i}=this,{state:r}=this.backend,{textureGPU:n}=this.backend.get(e),{x:o,y:a,z:h,w:u}=s,l=!0===e.isDepthTexture||t.renderTarget&&t.renderTarget.samples>0,c=t.renderTarget?t.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(l){const s=0!==o||0!==a;let l,d;if(!0===e.isDepthTexture?(l=i.DEPTH_BUFFER_BIT,d=i.DEPTH_ATTACHMENT,t.stencil&&(l|=i.STENCIL_BUFFER_BIT)):(l=i.COLOR_BUFFER_BIT,d=i.COLOR_ATTACHMENT0),s){const e=this.backend.get(t.renderTarget),s=e.framebuffers[t.getCacheKey()],d=e.msaaFrameBuffer;r.bindFramebuffer(i.DRAW_FRAMEBUFFER,s),r.bindFramebuffer(i.READ_FRAMEBUFFER,d);const p=c-a-u;i.blitFramebuffer(o,p,o+h,p+u,o,p,o+h,p+u,l,i.NEAREST),r.bindFramebuffer(i.READ_FRAMEBUFFER,s),r.bindTexture(i.TEXTURE_2D,n),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,o,p,h,u),r.unbindTexture()}else{const e=i.createFramebuffer();r.bindFramebuffer(i.DRAW_FRAMEBUFFER,e),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,d,i.TEXTURE_2D,n,0),i.blitFramebuffer(0,0,h,u,0,0,h,u,l,i.NEAREST),i.deleteFramebuffer(e)}}else r.bindTexture(i.TEXTURE_2D,n),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,o,c-u-a,h,u),r.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t){const{gl:s}=this,i=t.renderTarget,{samples:r,depthTexture:n,depthBuffer:o,stencilBuffer:a,width:h,height:u}=i;if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!a){let t=s.DEPTH_COMPONENT24;r>0?(n&&n.isDepthTexture&&n.type===s.FLOAT&&(t=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,r,t,h,u)):s.renderbufferStorage(s.RENDERBUFFER,t,h,u),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}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,e))}async copyTextureToBuffer(e,t,s,i,r,n){const{backend:o,gl:a}=this,{textureGPU:h,glFormat:u,glType:l}=this.backend.get(e),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const d=e.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+n:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,d,h,0);const p=this._getTypedArrayType(l),m=i*r*this._getBytesPerTexel(l,u),g=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,g),a.bufferData(a.PIXEL_PACK_BUFFER,m,a.STREAM_READ),a.readPixels(t,s,i,r,u,l,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(m/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,g),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:s}=this;let i=0;return e===s.UNSIGNED_BYTE&&(i=1),e!==s.UNSIGNED_SHORT_4_4_4_4&&e!==s.UNSIGNED_SHORT_5_5_5_1&&e!==s.UNSIGNED_SHORT_5_6_5&&e!==s.UNSIGNED_SHORT&&e!==s.HALF_FLOAT||(i=2),e!==s.UNSIGNED_INT&&e!==s.FLOAT||(i=4),t===s.RGBA?4*i:t===s.RGB?3*i:t===s.ALPHA?i:void 0}}class JP{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class KP{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){const s=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const QP={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 eF{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:s,mode:i,object:r,type:n,info:o,index:a}=this;0!==a?s.drawElements(i,t,n,e):s.drawArrays(i,e,t),o.update(r,t,i,1)}renderInstances(e,t,s){const{gl:i,mode:r,type:n,index:o,object:a,info:h}=this;0!==s&&(0!==o?i.drawElementsInstanced(r,t,n,e,s):i.drawArraysInstanced(r,e,t,s),h.update(a,t,r,s))}renderMultiDraw(e,t,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;i<s;i++)this.render(e[i],t[i]);else{0!==this.index?a.multiDrawElementsWEBGL(r,t,0,this.type,e,0,s):a.multiDrawArraysWEBGL(r,e,0,t,0,s);let i=0;for(let e=0;e<s;e++)i+=t[e];o.update(n,i,r,1)}}renderMultiDrawInstances(e,t,s,i){const{extensions:r,mode:n,object:o,info:a}=this;if(0===s)return;const h=r.get("WEBGL_multi_draw");if(null===h)for(let r=0;r<s;r++)this.renderInstances(e[r],t[r],i[r]);else{0!==this.index?h.multiDrawElementsInstancedWEBGL(n,t,0,this.type,e,0,i,0,s):h.multiDrawArraysInstancedWEBGL(n,e,0,t,0,i,0,s);let r=0;for(let e=0;e<s;e++)r+=t[e];for(let e=0;e<i.length;e++)a.update(o,r,n,i[e])}}}class tF extends OP{constructor(e={}){super(e),this.isWebGLBackend=!0}init(e){super.init(e);const t=this.parameters,s=void 0!==t.context?t.context:e.domElement.getContext("webgl2");this.gl=s,this.extensions=new JP(this),this.capabilities=new KP(this),this.attributeUtils=new DP(this),this.textureUtils=new ZP(this),this.bufferRenderer=new eF(this),this.state=new HP(this),this.utils=new jP(this),this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.trackTimestamp=!0===t.trackTimestamp,this.extensions.get("EXT_color_buffer_float"),this.extensions.get("WEBGL_clip_cull_distance"),this.extensions.get("OES_texture_float_linear"),this.extensions.get("EXT_color_buffer_half_float"),this.extensions.get("WEBGL_multisampled_render_to_texture"),this.extensions.get("WEBGL_render_shared_exponent"),this.extensions.get("WEBGL_multi_draw"),this.disjoint=this.extensions.get("EXT_disjoint_timer_query_webgl2"),this.parallel=this.extensions.get("KHR_parallel_shader_compile"),this._currentContext=null}get coordinateSystem(){return Ds}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}initTimestampQuery(e){if(!this.disjoint||!this.trackTimestamp)return;const t=this.get(e);if(this.queryRunning)return t.queryQueue||(t.queryQueue=[]),void t.queryQueue.push(e);t.activeQuery&&(this.gl.endQuery(this.disjoint.TIME_ELAPSED_EXT),t.activeQuery=null),t.activeQuery=this.gl.createQuery(),null!==t.activeQuery&&(this.gl.beginQuery(this.disjoint.TIME_ELAPSED_EXT,t.activeQuery),this.queryRunning=!0)}prepareTimestampBuffer(e){if(!this.disjoint||!this.trackTimestamp)return;const t=this.get(e);if(t.activeQuery&&(this.gl.endQuery(this.disjoint.TIME_ELAPSED_EXT),t.gpuQueries||(t.gpuQueries=[]),t.gpuQueries.push({query:t.activeQuery}),t.activeQuery=null,this.queryRunning=!1,t.queryQueue&&t.queryQueue.length>0)){const e=t.queryQueue.shift();this.initTimestampQuery(e)}}async resolveTimestampAsync(e,t="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(e);s.gpuQueries||(s.gpuQueries=[]);for(let e=0;e<s.gpuQueries.length;e++){const i=s.gpuQueries[e],r=this.gl.getQueryParameter(i.query,this.gl.QUERY_RESULT_AVAILABLE),n=this.gl.getParameter(this.disjoint.GPU_DISJOINT_EXT);if(r&&!n){const r=this.gl.getQueryParameter(i.query,this.gl.QUERY_RESULT),n=Number(r)/1e6;this.gl.deleteQuery(i.query),s.gpuQueries.splice(e,1),e--,this.renderer.info.updateTimestamp(t,n)}}}getContext(){return this.gl}beginRender(e){const{gl:t}=this,s=this.get(e);if(this.initTimestampQuery(e),s.previousContext=this._currentContext,this._currentContext=e,this._setFramebuffer(e),this.clear(e.clearColor,e.clearDepth,e.clearStencil,e,!1),e.viewport?this.updateViewport(e):t.viewport(0,0,t.drawingBufferWidth,t.drawingBufferHeight),e.scissor){const{x:s,y:i,width:r,height:n}=e.scissorValue;t.scissor(s,e.height-n-i,r,n)}const i=e.occlusionQueryCount;i>0&&(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(e){const{gl:t,state:s}=this,i=this.get(e),r=i.previousContext,n=e.occlusionQueryCount;n>0&&(n>i.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const o=e.textures;if(null!==o)for(let e=0;e<o.length;e++){const t=o[e];t.generateMipmaps&&this.generateMipmaps(t)}if(this._currentContext=r,null!==e.textures&&e.renderTarget){const i=this.get(e.renderTarget),{samples:r}=e.renderTarget;if(r>0){const r=i.framebuffers[e.getCacheKey()],n=t.COLOR_BUFFER_BIT,o=i.msaaFrameBuffer,a=e.textures;s.bindFramebuffer(t.READ_FRAMEBUFFER,o),s.bindFramebuffer(t.DRAW_FRAMEBUFFER,r);for(let s=0;s<a.length;s++)if(e.scissor){const{x:s,y:r,width:o,height:a}=e.scissorValue,h=e.height-a-r;t.blitFramebuffer(s,h,s+o,h+a,s,h,s+o,h+a,n,t.NEAREST),t.invalidateSubFramebuffer(t.READ_FRAMEBUFFER,i.invalidationArray,s,h,o,a)}else t.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,n,t.NEAREST),t.invalidateFramebuffer(t.READ_FRAMEBUFFER,i.invalidationArray)}}null!==r&&(this._setFramebuffer(r),r.viewport?this.updateViewport(r):t.viewport(0,0,t.drawingBufferWidth,t.drawingBufferHeight)),this.prepareTimestampBuffer(e)}resolveOccludedAsync(e){const t=this.get(e),{currentOcclusionQueries:s,currentOcclusionQueryObjects:i}=t;if(s&&i){const e=new WeakSet,{gl:r}=this;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueries=null;const n=()=>{let o=0;for(let t=0;t<s.length;t++){const n=s[t];null!==n&&(r.getQueryParameter(n,r.QUERY_RESULT_AVAILABLE)&&(r.getQueryParameter(n,r.QUERY_RESULT)>0&&e.add(i[t]),s[t]=null,r.deleteQuery(n),o++))}o<s.length?requestAnimationFrame(n):t.occluded=e};n()}}isOccluded(e,t){const s=this.get(e);return s.occluded&&s.occluded.has(t)}updateViewport(e){const t=this.gl,{x:s,y:i,width:r,height:n}=e.viewportValue;t.viewport(s,e.height-n-i,r,n)}setScissorTest(e){const t=this.gl;e?t.enable(t.SCISSOR_TEST):t.disable(t.SCISSOR_TEST)}clear(e,t,s,i=null,r=!0){const{gl:n}=this;null===i&&(i={textures:null,clearColorValue:this.getClearColor()});let o=0;if(e&&(o|=n.COLOR_BUFFER_BIT),t&&(o|=n.DEPTH_BUFFER_BIT),s&&(o|=n.STENCIL_BUFFER_BIT),0!==o){const a=i.clearColorValue||this.getClearColor();if(a.r*=a.a,a.g*=a.a,a.b*=a.a,t&&this.state.setDepthMask(!0),null===i.textures)n.clearColor(a.r,a.g,a.b,a.a),n.clear(o);else{if(r&&this._setFramebuffer(i),e)for(let e=0;e<i.textures.length;e++)n.clearBufferfv(n.COLOR,e,[a.r,a.g,a.b,a.a]);t&&s?n.clearBufferfi(n.DEPTH_STENCIL,0,1,0):t?n.clearBufferfv(n.DEPTH,0,[1]):s&&n.clearBufferiv(n.STENCIL,0,[0])}}}beginCompute(e){const{state:t,gl:s}=this;t.bindFramebuffer(s.FRAMEBUFFER,null),this.initTimestampQuery(e)}compute(e,t,s,i){const{state:r,gl:n}=this;this.discard||(n.enable(n.RASTERIZER_DISCARD),this.discard=!0);const{programGPU:o,transformBuffers:a,attributes:h}=this.get(i),u=this._getVaoKey(null,h),l=this.vaoCache[u];void 0===l?this._createVao(null,h):n.bindVertexArray(l),r.useProgram(o),this._bindUniforms(s);const c=this._getTransformFeedback(a);n.bindTransformFeedback(n.TRANSFORM_FEEDBACK,c),n.beginTransformFeedback(n.POINTS),h[0].isStorageInstancedBufferAttribute?n.drawArraysInstanced(n.POINTS,0,1,t.count):n.drawArrays(n.POINTS,0,t.count),n.endTransformFeedback(),n.bindTransformFeedback(n.TRANSFORM_FEEDBACK,null);for(let e=0;e<a.length;e++){const t=a[e];t.pbo&&this.textureUtils.copyBufferToTexture(t.transformBuffer,t.pbo),t.switchBuffers()}}finishCompute(e){const t=this.gl;this.discard=!1,t.disable(t.RASTERIZER_DISCARD),this.prepareTimestampBuffer(e)}draw(e){const{object:t,pipeline:s,material:i,context:r}=e,{programGPU:n}=this.get(s),{gl:o,state:a}=this,h=this.get(r),u=e.getDrawParameters();if(null===u)return;this._bindUniforms(e.getBindings());const l=t.isMesh&&t.matrixWorld.determinant()<0;a.setMaterial(i,l),a.useProgram(n);let c=e.staticVao;if(void 0===c){const t=this._getVaoKey(e.getIndex(),e.getAttributes());if(c=this.vaoCache[t],void 0===c){let t;({vaoGPU:c,staticVao:t}=this._createVao(e.getIndex(),e.getAttributes())),t&&(e.staticVao=c)}}o.bindVertexArray(c);const d=e.getIndex(),p=h.lastOcclusionObject;if(p!==t&&void 0!==p){if(null!==p&&!0===p.occlusionTest&&(o.endQuery(o.ANY_SAMPLES_PASSED),h.occlusionQueryIndex++),!0===t.occlusionTest){const e=o.createQuery();o.beginQuery(o.ANY_SAMPLES_PASSED,e),h.occlusionQueries[h.occlusionQueryIndex]=e,h.occlusionQueryObjects[h.occlusionQueryIndex]=t}h.lastOcclusionObject=t}const m=this.bufferRenderer;t.isPoints?m.mode=o.POINTS:t.isLineSegments?m.mode=o.LINES:t.isLine?m.mode=o.LINE_STRIP:t.isLineLoop?m.mode=o.LINE_LOOP:!0===i.wireframe?(a.setLineWidth(i.wireframeLinewidth*this.renderer.getPixelRatio()),m.mode=o.LINES):m.mode=o.TRIANGLES;const{vertexCount:g,instanceCount:f}=u;let{firstVertex:y}=u;if(m.object=t,null!==d){y*=d.array.BYTES_PER_ELEMENT;const e=this.get(d);m.index=d.count,m.type=e.type}else m.index=0;var x;t.isBatchedMesh?null!==t._multiDrawInstances?m.renderMultiDrawInstances(t._multiDrawStarts,t._multiDrawCounts,t._multiDrawCount,t._multiDrawInstances):this.hasFeature("WEBGL_multi_draw")?m.renderMultiDraw(t._multiDrawStarts,t._multiDrawCounts,t._multiDrawCount):(x="THREE.WebGLRenderer: WEBGL_multi_draw not supported.")in ai||(ai[x]=!0,console.warn(x)):f>1?m.renderInstances(y,g,f):m.render(y,g),o.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,i,r,n){return this.textureUtils.copyTextureToBuffer(e,t,s,i,r,n)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new PP(e,t)}createProgram(e){const t=this.gl,{stage:s,code:i}=e,r="fragment"===s?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(r,i),t.compileShader(r),this.set(e,{shaderGPU:r})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(e,t){const s=this.gl,i=e.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!==t&&this.parallel){const r=new Promise(t=>{const r=this.parallel,n=()=>{s.getProgramParameter(o,r.COMPLETION_STATUS_KHR)?(this._completeCompile(e,i),t()):requestAnimationFrame(n)};n()});return void t.push(r)}this._completeCompile(e,i)}_handleSource(e,t){const s=e.split("\n"),i=[],r=Math.max(t-6,0),n=Math.min(t+6,s.length);for(let e=r;e<n;e++){const r=e+1;i.push(`${r===t?">":" "} ${r}: ${s[e]}`)}return i.join("\n")}_getShaderErrors(e,t,s){const i=e.getShaderParameter(t,e.COMPILE_STATUS),r=e.getShaderInfoLog(t).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(e.getShaderSource(t),i)}return r}_logProgramError(e,t,s){if(this.renderer.debug.checkShaderErrors){const i=this.gl,r=i.getProgramInfoLog(e).trim();if(!1===i.getProgramParameter(e,i.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(i,e,s,t);else{const n=this._getShaderErrors(i,s,"vertex"),o=this._getShaderErrors(i,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(e,i.VALIDATE_STATUS)+"\n\nProgram Info Log: "+r+"\n"+n+"\n"+o)}else""!==r&&console.warn("THREE.WebGLProgram: Program Info Log:",r)}}_completeCompile(e,t){const{state:s,gl:i}=this,r=this.get(t),{programGPU:n,fragmentShader:o,vertexShader:a}=r;!1===i.getProgramParameter(n,i.LINK_STATUS)&&this._logProgramError(n,o,a),s.useProgram(n);const h=e.getBindings();this._setupBindings(h,n),this.set(t,{programGPU:n})}createComputePipeline(e,t){const{state:s,gl:i}=this,r={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(r);const{computeProgram:n}=e,o=i.createProgram(),a=this.get(r).shaderGPU,h=this.get(n).shaderGPU,u=n.transforms,l=[],c=[];for(let e=0;e<u.length;e++){const t=u[e];l.push(t.varyingName),c.push(t.attributeNode)}i.attachShader(o,a),i.attachShader(o,h),i.transformFeedbackVaryings(o,l,i.SEPARATE_ATTRIBS),i.linkProgram(o),!1===i.getProgramParameter(o,i.LINK_STATUS)&&this._logProgramError(o,a,h),s.useProgram(o),this.createBindings(null,t),this._setupBindings(t,o);const d=n.attributes,p=[],m=[];for(let e=0;e<d.length;e++){const t=d[e].node.attribute;p.push(t),this.has(t)||this.attributeUtils.createAttribute(t,i.ARRAY_BUFFER)}for(let e=0;e<c.length;e++){const t=c[e].attribute;this.has(t)||this.attributeUtils.createAttribute(t,i.ARRAY_BUFFER);const s=this.get(t);m.push(s)}this.set(e,{programGPU:o,transformBuffers:m,attributes:p})}createBindings(e,t){this.updateBindings(e,t)}updateBindings(e,t){if(!e)return;const{gl:s}=this,i=this.get(t),r=this.get(e);void 0===i.textureIndex&&(i.textureIndex=0),void 0===r.textureIndex?r.textureIndex=i.textureIndex:i.textureIndex=r.textureIndex;let n=0;for(const t of e.bindings)if(t.isUniformsGroup||t.isUniformBuffer){const i=t.buffer,r=s.createBuffer();s.bindBuffer(s.UNIFORM_BUFFER,r),s.bufferData(s.UNIFORM_BUFFER,i,s.DYNAMIC_DRAW),this.set(t,{index:2*e.index+n++,bufferGPU:r})}else if(t.isSampledTexture){const{textureGPU:e,glTextureType:s}=this.get(t.texture);this.set(t,{index:i.textureIndex++,textureGPU:e,glTextureType:s})}}updateBinding(e){const t=this.gl;if(e.isUniformsGroup||e.isUniformBuffer){const s=this.get(e).bufferGPU,i=e.buffer;t.bindBuffer(t.UNIFORM_BUFFER,s),t.bufferData(t.UNIFORM_BUFFER,i,t.DYNAMIC_DRAW)}}createIndexAttribute(e){const t=this.gl;this.attributeUtils.createAttribute(e,t.ELEMENT_ARRAY_BUFFER)}createAttribute(e){if(this.has(e))return;const t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}createStorageAttribute(e){if(this.has(e))return;const t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){}hasFeature(e){const t=Object.keys(QP).filter(t=>QP[t]===e),s=this.extensions;for(let e=0;e<t.length;e++)if(s.has(t[e]))return!0;return!1}getMaxAnisotropy(){return this.capabilities.getMaxAnisotropy()}copyTextureToTexture(e,t,s,i){this.textureUtils.copyTextureToTexture(e,t,s,i)}copyFramebufferToTexture(e,t,s){this.textureUtils.copyFramebufferToTexture(e,t,s)}_setFramebuffer(e){const{gl:t,state:s}=this;let i=null;if(null!==e.textures){const r=e.renderTarget,n=this.get(r),{samples:o,depthBuffer:a,stencilBuffer:h}=r,u=!0===r.isWebGLCubeRenderTarget;let l=n.msaaFrameBuffer,c=n.depthRenderbuffer;const d=ZI(e);let p;if(u?(n.cubeFramebuffers||(n.cubeFramebuffers={}),p=n.cubeFramebuffers[d]):(n.framebuffers||(n.framebuffers={}),p=n.framebuffers[d]),void 0===p){p=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,p);const i=e.textures;if(u){n.cubeFramebuffers[d]=p;const{textureGPU:e}=this.get(i[0]),s=this.renderer._activeCubeFace;t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+s,e,0)}else{n.framebuffers[d]=p;for(let s=0;s<i.length;s++){const r=i[s],n=this.get(r);n.renderTarget=e.renderTarget;const o=t.COLOR_ATTACHMENT0+s;t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,n.textureGPU,0)}s.drawBuffers(e,p)}if(null!==e.depthTexture){const s=this.get(e.depthTexture),i=h?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;t.framebufferTexture2D(t.FRAMEBUFFER,i,t.TEXTURE_2D,s.textureGPU,0)}}if(o>0){if(void 0===l){const i=[];l=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,l);const r=[],u=e.textures;for(let s=0;s<u.length;s++){if(r[s]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,r[s]),i.push(t.COLOR_ATTACHMENT0+s),a){const e=h?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;i.push(e)}const n=e.textures[s],u=this.get(n);t.renderbufferStorageMultisample(t.RENDERBUFFER,o,u.glInternalFormat,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+s,t.RENDERBUFFER,r[s])}if(n.msaaFrameBuffer=l,n.msaaRenderbuffers=r,void 0===c){c=t.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(c,e),n.depthRenderbuffer=c;const s=h?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;i.push(s)}n.invalidationArray=i}i=n.msaaFrameBuffer}else i=p}s.bindFramebuffer(t.FRAMEBUFFER,i)}_getVaoKey(e,t){let s=[];if(null!==e){s+=":"+this.get(e).id}for(let e=0;e<t.length;e++){s+=":"+this.get(t[e]).id}return s}_createVao(e,t){const{gl:s}=this,i=s.createVertexArray();let r="",n=!0;if(s.bindVertexArray(i),null!==e){const t=this.get(e);s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,t.bufferGPU),r+=":"+t.id}for(let e=0;e<t.length;e++){const i=t[e],o=this.get(i);let a,h;r+=":"+o.id,s.bindBuffer(s.ARRAY_BUFFER,o.bufferGPU),s.enableVertexAttribArray(e),(i.isStorageBufferAttribute||i.isStorageInstancedBufferAttribute)&&(n=!1),!0===i.isInterleavedBufferAttribute?(a=i.data.stride*o.bytesPerElement,h=i.offset*o.bytesPerElement):(a=0,h=0),o.isInteger?s.vertexAttribIPointer(e,i.itemSize,o.type,a,h):s.vertexAttribPointer(e,i.itemSize,o.type,i.normalized,a,h),i.isInstancedBufferAttribute&&!i.isInterleavedBufferAttribute?s.vertexAttribDivisor(e,i.meshPerAttribute):i.isInterleavedBufferAttribute&&i.data.isInstancedInterleavedBuffer&&s.vertexAttribDivisor(e,i.data.meshPerAttribute)}return s.bindBuffer(s.ARRAY_BUFFER,null),this.vaoCache[r]=i,{vaoGPU:i,staticVao:n}}_getTransformFeedback(e){let t="";for(let s=0;s<e.length;s++)t+=":"+e[s].id;let s=this.transformFeedbackCache[t];if(void 0!==s)return s;const{gl:i}=this;s=i.createTransformFeedback(),i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,s);for(let t=0;t<e.length;t++){const s=e[t];i.bindBufferBase(i.TRANSFORM_FEEDBACK_BUFFER,t,s.transformBuffer)}return i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[t]=s,s}_setupBindings(e,t){const s=this.gl;for(const i of e)for(const e of i.bindings){const i=this.get(e).index;if(e.isUniformsGroup||e.isUniformBuffer){const r=s.getUniformBlockIndex(t,e.name);s.uniformBlockBinding(t,r,i)}else if(e.isSampledTexture){const r=s.getUniformLocation(t,e.name);s.uniform1i(r,i)}}}_bindUniforms(e){const{gl:t,state:s}=this;for(const i of e)for(const e of i.bindings){const i=this.get(e),r=i.index;e.isUniformsGroup||e.isUniformBuffer?s.bindBufferBase(t.UNIFORM_BUFFER,r,i.bufferGPU):e.isSampledTexture&&s.bindTexture(i.glTextureType,i.textureGPU,t.TEXTURE0+r)}}}class sF extends fP{constructor(e,t){super(e),this.texture=t,this.version=t?t.version:0,this.isSampler=!0}}class iF extends sF{constructor(e,t,s){super(e,t?t.value:null),this.textureNode=t,this.groupNode=s}update(){this.texture=this.textureNode.value}}class rF extends yP{constructor(e,t){super(e,t?t.array:null),this.attribute=t,this.isStorageBuffer=!0}}let nF=0;class oF extends rF{constructor(e,t){super("StorageBuffer_"+nF++,e?e.value:null),this.nodeUniform=e,this.access=e?e.access:EA,this.groupNode=t}get buffer(){return this.nodeUniform.value}}class aF extends Kw{constructor(e){super(),this.device=e;this.mipmapSampler=e.createSampler({minFilter:eA}),this.flipYSampler=e.createSampler({minFilter:tA}),this.transferPipelines={},this.flipYPipelines={},this.mipmapVertexShaderModule=e.createShaderModule({label:"mipmapVertex",code:"\nstruct VarysStruct {\n\t@builtin( position ) Position: vec4<f32>,\n\t@location( 0 ) vTex : vec2<f32>\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2<f32>, 4 >(\n\t\tvec2<f32>( -1.0, 1.0 ),\n\t\tvec2<f32>( 1.0, 1.0 ),\n\t\tvec2<f32>( -1.0, -1.0 ),\n\t\tvec2<f32>( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2<f32>, 4 >(\n\t\tvec2<f32>( 0.0, 0.0 ),\n\t\tvec2<f32>( 1.0, 0.0 ),\n\t\tvec2<f32>( 0.0, 1.0 ),\n\t\tvec2<f32>( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4<f32>( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d<f32>;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d<f32>;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(e){let t=this.transferPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:IN,stripIndexFormat:YN},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:IN,stripIndexFormat:YN},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,s=0){const i=t.format,{width:r,height:n}=t.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=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:kA,baseArrayLayer:s}),l=h.createView({baseMipLevel:0,mipLevelCount:1,dimension:kA,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),d=(e,t,s)=>{const i=e.getBindGroupLayout(0),r=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t}]}),n=c.beginRenderPass({colorAttachments:[{view:s,loadOp:WN,storeOp:kN,clearValue:[0,0,0,0]}]});n.setPipeline(e),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(e,t,s=0){const i=this.get(e);void 0===i.useCount&&(i.useCount=0,i.layers=[]);const r=i.layers[s]||this._mipmapCreateBundles(e,t,s),n=this.device.createCommandEncoder({});this._mipmapRunBundles(n,r),this.device.queue.submit([n.finish()]),0!==i.useCount&&(i.layers[s]=r),i.useCount++}_mipmapCreateBundles(e,t,s){const i=this.getTransferPipeline(t.format),r=i.getBindGroupLayout(0);let n=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:kA,baseArrayLayer:s});const o=[];for(let a=1;a<t.mipLevelCount;a++){const h=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.mipmapSampler},{binding:1,resource:n}]}),u=e.createView({baseMipLevel:a,mipLevelCount:1,dimension:kA,baseArrayLayer:s}),l={colorAttachments:[{view:u,loadOp:WN,storeOp:kN,clearValue:[0,0,0,0]}]},c=this.device.createRenderBundleEncoder({colorFormats:[t.format]});c.setPipeline(i),c.setBindGroup(0,h),c.draw(4,1,0,0),o.push({renderBundles:[c.finish()],passDescriptor:l}),n=u}return o}_mipmapRunBundles(e,t){const s=t.length;for(let i=0;i<s;i++){const s=t[i],r=e.beginRenderPass(s.passDescriptor);r.executeBundles(s.renderBundles),r.end()}}}const hF={[Ts]:"never",[_s]:"less",[ws]:"equal",[Ss]:"less-equal",[Ms]:"greater",[As]:"greater-equal",[Cs]:"always",[Ns]:"not-equal"},uF=[0,1,3,2,4,5];class lF{constructor(e){this.backend=e,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this.colorBuffer=null,this.depthTexture=new Qa,this.depthTexture.name="depthBuffer"}createSampler(e){const t=this.backend,s=t.device,i=t.get(e),r={addressModeU:this._convertAddressMode(e.wrapS),addressModeV:this._convertAddressMode(e.wrapT),addressModeW:this._convertAddressMode(e.wrapR),magFilter:this._convertFilterMode(e.magFilter),minFilter:this._convertFilterMode(e.minFilter),mipmapFilter:this._convertFilterMode(e.minFilter),maxAnisotropy:e.anisotropy};e.isDepthTexture&&null!==e.compareFunction&&(r.compare=hF[e.compareFunction]),i.sampler=s.createSampler(r)}createDefaultTexture(e){let t;const s=cF(e);e.isCubeTexture?t=this._getDefaultCubeTextureGPU(s):e.isVideoTexture?this.backend.get(e).externalTexture=this._getDefaultVideoFrame():t=this._getDefaultTextureGPU(s),this.backend.get(e).texture=t}createTexture(e,t={}){const s=this.backend,i=s.get(e);if(i.initialized)throw new Error("WebGPUTextureUtils: Texture already initialized.");void 0===t.needsMipmaps&&(t.needsMipmaps=!1),void 0===t.levels&&(t.levels=1),void 0===t.depth&&(t.depth=1);const{width:r,height:n,depth:o,levels:a}=t,h=this._getDimension(e),u=e.internalFormat||t.format||cF(e,s.device);i.format=u;let l=void 0!==t.sampleCount?t.sampleCount:1;l=s.utils.getSampleCount(l);const c=e.isRenderTargetTexture&&!e.isMultisampleRenderTargetTexture?1:l;let d=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;!0===e.isStorageTexture&&(d|=GPUTextureUsage.STORAGE_BINDING),!0!==e.isCompressedTexture&&!0!==e.isCompressedArrayTexture&&(d|=GPUTextureUsage.RENDER_ATTACHMENT);const p={label:e.name,size:{width:r,height:n,depthOrArrayLayers:o},mipLevelCount:a,sampleCount:c,dimension:h,format:u,usage:d};if(e.isVideoTexture){const t=e.source.data,s=new VideoFrame(t);p.size.width=s.displayWidth,p.size.height=s.displayHeight,s.close(),i.externalTexture=t}else{if(void 0===u)return console.warn("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(e);i.texture=s.device.createTexture(p)}if(e.isRenderTargetTexture&&l>1&&!e.isMultisampleRenderTargetTexture){const e=Object.assign({},p);e.label=e.label+"-msaa",e.sampleCount=l,i.msaaTexture=s.device.createTexture(e)}i.initialized=!0,i.textureDescriptorGPU=p}destroyTexture(e){const t=this.backend,s=t.get(e);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),t.delete(e)}destroySampler(e){delete this.backend.get(e).sampler}generateMipmaps(e){const t=this.backend.get(e);if(e.isCubeTexture)for(let e=0;e<6;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e);else{const s=e.image.depth||1;for(let e=0;e<s;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e)}}getColorBuffer(){this.colorBuffer&&this.colorBuffer.destroy();const e=this.backend,{width:t,height:s}=e.getDrawingBufferSize();return this.colorBuffer=e.device.createTexture({label:"colorBuffer",size:{width:t,height:s,depthOrArrayLayers:1},sampleCount:e.utils.getSampleCount(e.renderer.samples),format:e.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),this.colorBuffer}getDepthBuffer(e=!0,t=!1){const s=this.backend,{width:i,height:r}=s.getDrawingBufferSize(),n=this.depthTexture,o=s.get(n).texture;let a,h;if(t?(a=je,h=Ue):e&&(a=He,h=Be),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(e,t){const s=this.backend.get(e),{textureDescriptorGPU:i}=s;if(!e.isRenderTargetTexture&&void 0!==i){if(e.isDataTexture)this._copyBufferToTexture(t.image,s.texture,i,0,e.flipY);else if(e.isDataArrayTexture||e.isData3DTexture)for(let r=0;r<t.image.depth;r++)this._copyBufferToTexture(t.image,s.texture,i,r,e.flipY,r);else if(e.isCompressedTexture||e.isCompressedArrayTexture)this._copyCompressedBufferToTexture(e.mipmaps,s.texture,i);else if(e.isCubeTexture)this._copyCubeMapToTexture(t.images,s.texture,i,e.flipY);else if(e.isVideoTexture){const t=e.source.data;s.externalTexture=t}else this._copyImageToTexture(t.image,s.texture,i,0,e.flipY);s.version=e.version,e.onUpdate&&e.onUpdate(e)}}async copyTextureToBuffer(e,t,s,i,r,n){const o=this.backend.device,a=this.backend.get(e),h=a.texture,u=a.textureDescriptorGPU.format,l=this._getBytesPerTexel(u);let c=i*l;c=256*Math.ceil(c/256);const d=o.createBuffer({size:i*r*l,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),p=o.createCommandEncoder();p.copyTextureToBuffer({texture:h,origin:{x:t,y:s,z:n}},{buffer:d,bytesPerRow:c},{width:i,height:r});const m=this._getTypedArrayType(u);o.queue.submit([p.finish()]),await d.mapAsync(GPUMapMode.READ);return new m(d.getMappedRange())}_isEnvironmentTexture(e){const t=e.mapping;return t===le||t===ce||t===he||t===ue}_getDefaultTextureGPU(e){let t=this.defaultTexture[e];if(void 0===t){const s=new Ti;s.minFilter=fe,s.magFilter=fe,this.createTexture(s,{width:1,height:1,format:e}),this.defaultTexture[e]=t=s}return this.backend.get(t).texture}_getDefaultCubeTextureGPU(e){let t=this.defaultTexture[e];if(void 0===t){const s=new to;s.minFilter=fe,s.magFilter=fe,this.createTexture(s,{width:1,height:1,depth:6}),this.defaultCubeTexture[e]=t=s}return this.backend.get(t).texture}_getDefaultVideoFrame(){let e=this.defaultVideoFrame;if(null===e){const t={timestamp:0,codedWidth:1,codedHeight:1,format:"RGBA"};this.defaultVideoFrame=e=new VideoFrame(new Uint8Array([0,0,0,255]),t)}return e}_copyCubeMapToTexture(e,t,s,i){for(let r=0;r<6;r++){const n=e[r],o=!0===i?uF[r]:r;n.isDataTexture?this._copyBufferToTexture(n.image,t,s,o,i):this._copyImageToTexture(n,t,s,o,i)}}_copyImageToTexture(e,t,s,i,r){this.backend.device.queue.copyExternalImageToTexture({source:e},{texture:t,mipLevel:0,origin:{x:0,y:0,z:i}},{width:e.width,height:e.height,depthOrArrayLayers:1}),!0===r&&this._flipY(t,s,i)}_getPassUtils(){let e=this._passUtils;return null===e&&(this._passUtils=e=new aF(this.backend.device)),e}_generateMipmaps(e,t,s=0){this._getPassUtils().generateMipmaps(e,t,s)}_flipY(e,t,s=0){this._getPassUtils().flipY(e,t,s)}_copyBufferToTexture(e,t,s,i,r,n=0){const o=this.backend.device,a=e.data,h=this._getBytesPerTexel(s.format),u=e.width*h;o.queue.writeTexture({texture:t,mipLevel:0,origin:{x:0,y:0,z:i}},a,{offset:e.width*e.height*h*n,bytesPerRow:u},{width:e.width,height:e.height,depthOrArrayLayers:1}),!0===r&&this._flipY(t,s,i)}_copyCompressedBufferToTexture(e,t,s){const i=this.backend.device,r=this._getBlockData(s.format),n=s.size.depthOrArrayLayers>1;for(let o=0;o<e.length;o++){const a=e[o],h=a.width,u=a.height,l=n?s.size.depthOrArrayLayers:1,c=Math.ceil(h/r.width)*r.byteLength,d=c*Math.ceil(u/r.height);for(let e=0;e<l;e++)i.queue.writeTexture({texture:t,mipLevel:o,origin:{x:0,y:0,z:e}},a.data,{offset:e*d,bytesPerRow:c,rowsPerImage:Math.ceil(u/r.height)},{width:Math.ceil(h/r.width)*r.width,height:Math.ceil(u/r.height)*r.height,depthOrArrayLayers:1})}}_getBlockData(e){return e===ZN.BC1RGBAUnorm||e===ZN.BC1RGBAUnormSRGB?{byteLength:8,width:4,height:4}:e===ZN.BC2RGBAUnorm||e===ZN.BC2RGBAUnormSRGB||e===ZN.BC3RGBAUnorm||e===ZN.BC3RGBAUnormSRGB?{byteLength:16,width:4,height:4}:e===ZN.BC4RUnorm||e===ZN.BC4RSNorm?{byteLength:8,width:4,height:4}:e===ZN.BC5RGUnorm||e===ZN.BC5RGSnorm||e===ZN.BC6HRGBUFloat||e===ZN.BC6HRGBFloat||e===ZN.BC7RGBAUnorm||e===ZN.BC7RGBAUnormSRGB?{byteLength:16,width:4,height:4}:e===ZN.ETC2RGB8Unorm||e===ZN.ETC2RGB8UnormSRGB||e===ZN.ETC2RGB8A1Unorm||e===ZN.ETC2RGB8A1UnormSRGB?{byteLength:8,width:4,height:4}:e===ZN.ETC2RGBA8Unorm||e===ZN.ETC2RGBA8UnormSRGB?{byteLength:16,width:4,height:4}:e===ZN.EACR11Unorm||e===ZN.EACR11Snorm?{byteLength:8,width:4,height:4}:e===ZN.EACRG11Unorm||e===ZN.EACRG11Snorm||e===ZN.ASTC4x4Unorm||e===ZN.ASTC4x4UnormSRGB?{byteLength:16,width:4,height:4}:e===ZN.ASTC5x4Unorm||e===ZN.ASTC5x4UnormSRGB?{byteLength:16,width:5,height:4}:e===ZN.ASTC5x5Unorm||e===ZN.ASTC5x5UnormSRGB?{byteLength:16,width:5,height:5}:e===ZN.ASTC6x5Unorm||e===ZN.ASTC6x5UnormSRGB?{byteLength:16,width:6,height:5}:e===ZN.ASTC6x6Unorm||e===ZN.ASTC6x6UnormSRGB?{byteLength:16,width:6,height:6}:e===ZN.ASTC8x5Unorm||e===ZN.ASTC8x5UnormSRGB?{byteLength:16,width:8,height:5}:e===ZN.ASTC8x6Unorm||e===ZN.ASTC8x6UnormSRGB?{byteLength:16,width:8,height:6}:e===ZN.ASTC8x8Unorm||e===ZN.ASTC8x8UnormSRGB?{byteLength:16,width:8,height:8}:e===ZN.ASTC10x5Unorm||e===ZN.ASTC10x5UnormSRGB?{byteLength:16,width:10,height:5}:e===ZN.ASTC10x6Unorm||e===ZN.ASTC10x6UnormSRGB?{byteLength:16,width:10,height:6}:e===ZN.ASTC10x8Unorm||e===ZN.ASTC10x8UnormSRGB?{byteLength:16,width:10,height:8}:e===ZN.ASTC10x10Unorm||e===ZN.ASTC10x10UnormSRGB?{byteLength:16,width:10,height:10}:e===ZN.ASTC12x10Unorm||e===ZN.ASTC12x10UnormSRGB?{byteLength:16,width:12,height:10}:e===ZN.ASTC12x12Unorm||e===ZN.ASTC12x12UnormSRGB?{byteLength:16,width:12,height:12}:void 0}_convertAddressMode(e){let t=JN;return e===pe?t=KN:e===ge&&(t=QN),t}_convertFilterMode(e){let t=eA;return e!==fe&&e!==ye&&e!==be||(t=tA),t}_getBytesPerTexel(e){return e===ZN.R8Unorm||e===ZN.R8Snorm||e===ZN.R8Uint||e===ZN.R8Sint?1:e===ZN.R16Uint||e===ZN.R16Sint||e===ZN.R16Float||e===ZN.RG8Unorm||e===ZN.RG8Snorm||e===ZN.RG8Uint||e===ZN.RG8Sint?2:e===ZN.R32Uint||e===ZN.R32Sint||e===ZN.R32Float||e===ZN.RG16Uint||e===ZN.RG16Sint||e===ZN.RG16Float||e===ZN.RGBA8Unorm||e===ZN.RGBA8UnormSRGB||e===ZN.RGBA8Snorm||e===ZN.RGBA8Uint||e===ZN.RGBA8Sint||e===ZN.BGRA8Unorm||e===ZN.BGRA8UnormSRGB||e===ZN.RGB9E5UFloat||e===ZN.RGB10A2Unorm||e===ZN.RG11B10UFloat||e===ZN.Depth32Float||e===ZN.Depth24Plus||e===ZN.Depth24PlusStencil8||e===ZN.Depth32FloatStencil8?4:e===ZN.RG32Uint||e===ZN.RG32Sint||e===ZN.RG32Float||e===ZN.RGBA16Uint||e===ZN.RGBA16Sint||e===ZN.RGBA16Float?8:e===ZN.RGBA32Uint||e===ZN.RGBA32Sint||e===ZN.RGBA32Float?16:void 0}_getTypedArrayType(e){return e===ZN.R8Uint?Uint8Array:e===ZN.R8Sint?Int8Array:e===ZN.R8Unorm?Uint8Array:e===ZN.R8Snorm?Int8Array:e===ZN.RG8Uint?Uint8Array:e===ZN.RG8Sint?Int8Array:e===ZN.RG8Unorm?Uint8Array:e===ZN.RG8Snorm?Int8Array:e===ZN.RGBA8Uint?Uint8Array:e===ZN.RGBA8Sint?Int8Array:e===ZN.RGBA8Unorm?Uint8Array:e===ZN.RGBA8Snorm?Int8Array:e===ZN.R16Uint?Uint16Array:e===ZN.R16Sint?Int16Array:e===ZN.RG16Uint?Uint16Array:e===ZN.RG16Sint?Int16Array:e===ZN.RGBA16Uint?Uint16Array:e===ZN.RGBA16Sint?Int16Array:e===ZN.R16Float||e===ZN.RG16Float||e===ZN.RGBA16Float?Uint16Array:e===ZN.R32Uint?Uint32Array:e===ZN.R32Sint?Int32Array:e===ZN.R32Float?Float32Array:e===ZN.RG32Uint?Uint32Array:e===ZN.RG32Sint?Int32Array:e===ZN.RG32Float?Float32Array:e===ZN.RGBA32Uint?Uint32Array:e===ZN.RGBA32Sint?Int32Array:e===ZN.RGBA32Float?Float32Array:e===ZN.BGRA8Unorm||e===ZN.BGRA8UnormSRGB?Uint8Array:e===ZN.RGB10A2Unorm||e===ZN.RGB9E5UFloat||e===ZN.RG11B10UFloat?Uint32Array:e===ZN.Depth32Float?Float32Array:e===ZN.Depth24Plus||e===ZN.Depth24PlusStencil8?Uint32Array:e===ZN.Depth32FloatStencil8?Float32Array:void 0}_getDimension(e){let t;return t=e.isData3DTexture?DA:VA,t}}function cF(e,t=null){const s=e.format,i=e.type,r=e.colorSpace;let n;if(!0===e.isFramebufferTexture&&e.type===Ne)n=ZN.BGRA8Unorm;else if(!0===e.isCompressedTexture||!0===e.isCompressedArrayTexture)switch(s){case Qe:n=r===Jt?ZN.BC1RGBAUnormSRGB:ZN.BC1RGBAUnorm;break;case et:n=r===Jt?ZN.BC2RGBAUnormSRGB:ZN.BC2RGBAUnorm;break;case tt:n=r===Jt?ZN.BC3RGBAUnormSRGB:ZN.BC3RGBAUnorm;break;case at:n=r===Jt?ZN.ETC2RGB8UnormSRGB:ZN.ETC2RGB8Unorm;break;case ht:n=r===Jt?ZN.ETC2RGBA8UnormSRGB:ZN.ETC2RGBA8Unorm;break;case ut:n=r===Jt?ZN.ASTC4x4UnormSRGB:ZN.ASTC4x4Unorm;break;case lt:n=r===Jt?ZN.ASTC5x4UnormSRGB:ZN.ASTC5x4Unorm;break;case ct:n=r===Jt?ZN.ASTC5x5UnormSRGB:ZN.ASTC5x5Unorm;break;case dt:n=r===Jt?ZN.ASTC6x5UnormSRGB:ZN.ASTC6x5Unorm;break;case pt:n=r===Jt?ZN.ASTC6x6UnormSRGB:ZN.ASTC6x6Unorm;break;case mt:n=r===Jt?ZN.ASTC8x5UnormSRGB:ZN.ASTC8x5Unorm;break;case gt:n=r===Jt?ZN.ASTC8x6UnormSRGB:ZN.ASTC8x6Unorm;break;case ft:n=r===Jt?ZN.ASTC8x8UnormSRGB:ZN.ASTC8x8Unorm;break;case yt:n=r===Jt?ZN.ASTC10x5UnormSRGB:ZN.ASTC10x5Unorm;break;case xt:n=r===Jt?ZN.ASTC10x6UnormSRGB:ZN.ASTC10x6Unorm;break;case bt:n=r===Jt?ZN.ASTC10x8UnormSRGB:ZN.ASTC10x8Unorm;break;case vt:n=r===Jt?ZN.ASTC10x10UnormSRGB:ZN.ASTC10x10Unorm;break;case Tt:n=r===Jt?ZN.ASTC12x10UnormSRGB:ZN.ASTC12x10Unorm;break;case _t:n=r===Jt?ZN.ASTC12x12UnormSRGB:ZN.ASTC12x12Unorm;break;default:console.error("WebGPURenderer: Unsupported texture format.",s)}else switch(s){case ke:switch(i){case Ae:n=ZN.RGBA8Snorm;break;case Ce:n=ZN.RGBA16Sint;break;case Re:n=ZN.RGBA16Uint;break;case Be:n=ZN.RGBA32Uint;break;case Ee:n=ZN.RGBA32Sint;break;case Ne:n=r===Jt?ZN.RGBA8UnormSRGB:ZN.RGBA8Unorm;break;case Pe:n=ZN.RGBA16Float;break;case Ie:n=ZN.RGBA32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAFormat.",i)}break;case De:if(i===Oe)n=ZN.RGB9E5UFloat;else console.error("WebGPURenderer: Unsupported texture type with RGBFormat.",i);break;case qe:switch(i){case Ae:n=ZN.R8Snorm;break;case Ce:n=ZN.R16Sint;break;case Re:n=ZN.R16Uint;break;case Be:n=ZN.R32Uint;break;case Ee:n=ZN.R32Sint;break;case Ne:n=ZN.R8Unorm;break;case Pe:n=ZN.R16Float;break;case Ie:n=ZN.R32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RedFormat.",i)}break;case Xe:switch(i){case Ae:n=ZN.RG8Snorm;break;case Ce:n=ZN.RG16Sint;break;case Re:n=ZN.RG16Uint;break;case Be:n=ZN.RG32Uint;break;case Ee:n=ZN.RG32Sint;break;case Ne:n=ZN.RG8Unorm;break;case Pe:n=ZN.RG16Float;break;case Ie:n=ZN.RG32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGFormat.",i)}break;case He:switch(i){case Re:n=ZN.Depth16Unorm;break;case Be:n=ZN.Depth24Plus;break;case Ie:n=ZN.Depth32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthFormat.",i)}break;case je:switch(i){case Ue:n=ZN.Depth24PlusStencil8;break;case Ie:t&&!1===t.features.has(XA.Depth32FloatStencil8)&&console.error('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),n=ZN.Depth32FloatStencil8;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",i)}break;case $e:switch(i){case Ee:n=ZN.R32Sint;break;case Be:n=ZN.R32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",i)}break;case Ye:switch(i){case Ee:n=ZN.RG32Sint;break;case Be:n=ZN.RG32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",i)}break;case Je:switch(i){case Ee:n=ZN.RGBA32Sint;break;case Be:n=ZN.RGBA32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",i)}break;default:console.error("WebGPURenderer: Unsupported texture format.",s)}return n}const dF=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,pF=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,mF={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2<f32>":"vec2","vec2<i32>":"ivec2","vec2<u32>":"uvec2","vec2<bool>":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3<f32>":"vec3","vec3<i32>":"ivec3","vec3<u32>":"uvec3","vec3<bool>":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4<f32>":"vec4","vec4<i32>":"ivec4","vec4<u32>":"uvec4","vec4<bool>":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2<f32>":"mat2",mat2x2f:"mat2","mat3x3<f32>":"mat3",mat3x3f:"mat3","mat4x4<f32>":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class gF extends LI{constructor(e){const{type:t,inputs:s,name:i,inputsCode:r,blockCode:n,outputType:o}=(e=>{const t=(e=e.trim()).match(dF);if(null!==t&&4===t.length){const s=t[2],i=[];let r=null;for(;null!==(r=pF.exec(s));)i.push({name:r[1],type:r[2]});const n=[];for(let e=0;e<i.length;e++){const{name:t,type:s}=i[e];let r=s;r.startsWith("texture")&&(r=s.split("<")[0]),r=mF[r]||r,n.push(new SM(r,t))}const o=e.substring(t[0].length),a=t[3]||"void",h=void 0!==t[1]?t[1]:"";return{type:mF[a]||a,inputs:n,name:h,inputsCode:s,blockCode:o,outputType:a}}throw new Error("FunctionNode: Function is not a WGSL code.")})(e);super(t,s,i),this.inputsCode=r,this.blockCode=n,this.outputType=o}getCode(e=this.name){const t="void"!==this.outputType?"-> "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class fF extends OI{parseFunction(e){return new gF(e)}}const yF=self.GPUShaderStage,xF={vertex:yF?yF.VERTEX:1,fragment:yF?yF.FRAGMENT:2,compute:yF?yF.COMPUTE:4},bF={instance:!0,swizzleAssign:!1,storageBuffer:!0},vF={"^^":"tsl_xor"},TF={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3<f32>",vec2:"vec2<f32>",ivec2:"vec2<i32>",uvec2:"vec2<u32>",bvec2:"vec2<bool>",vec3:"vec3<f32>",ivec3:"vec3<i32>",uvec3:"vec3<u32>",bvec3:"vec3<bool>",vec4:"vec4<f32>",ivec4:"vec4<i32>",uvec4:"vec4<u32>",bvec4:"vec4<bool>",mat2:"mat2x2<f32>",imat2:"mat2x2<i32>",umat2:"mat2x2<u32>",bmat2:"mat2x2<bool>",mat3:"mat3x3<f32>",imat3:"mat3x3<i32>",umat3:"mat3x3<u32>",bmat3:"mat3x3<bool>",mat4:"mat4x4<f32>",imat4:"mat4x4<i32>",umat4:"mat4x4<u32>",bmat4:"mat4x4<bool>"},_F={tsl_xor:new SS("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new SS("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new SS("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new SS("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new SS("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new SS("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new SS("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new SS("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new SS("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping:new SS("\nfn tsl_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {\n\n\tlet uvScaled = vec2<u32>( uv * vec2<f32>( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new SS("\nfn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -> vec4f {\n\n\tlet iRes = vec2i( textureDimensions( map, level ) );\n\tlet res = vec2f( iRes );\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 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},wF={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast<f32>"};/Windows/g.test(navigator.userAgent)&&(_F.pow_float=new SS("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),_F.pow_vec2=new SS("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[_F.pow_float]),_F.pow_vec3=new SS("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[_F.pow_float]),_F.pow_vec4=new SS("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[_F.pow_float]),wF.pow_float="tsl_pow_float",wF.pow_vec2="tsl_pow_vec2",wF.pow_vec3="tsl_pow_vec3",wF.pow_vec4="tsl_pow_vec4");let SF="";!0!==/Firefox/g.test(navigator.userAgent)&&(SF+="diagnostic( off, derivative_uniformity );\n");class MF extends _M{constructor(e,t){super(e,t,new fF),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==Zt}_generateTextureSample(e,t,s,i,r=this.shaderStage){return"fragment"===r?i?`textureSample( ${t}, ${t}_sampler, ${s}, ${i} )`:`textureSample( ${t}, ${t}_sampler, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s):this.generateTextureLod(e,t,s,"0")}_generateVideoSample(e,t,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${e}, ${e}_sampler, vec2<f32>( ${t}.x, 1.0 - ${t}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(e,t,s,i,r,n=this.shaderStage){return"fragment"===n&&!1===this.isUnfilterable(e)?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${i} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,i):this.generateTextureLod(e,t,s,i)}generateFilteredTexture(e,t,s,i="0"){return this._include("biquadraticTexture"),`tsl_biquadraticTexture( ${t}, ${s}, i32( ${i} ) )`}generateTextureLod(e,t,s,i="0"){this._include("repeatWrapping");return`textureLoad( ${t}, tsl_repeatWrapping( ${s}, ${!0===e.isMultisampleRenderTargetTexture?`textureDimensions( ${t} )`:`textureDimensions( ${t}, 0 )`} ), i32( ${i} ) )`}generateTextureLoad(e,t,s,i,r="0u"){return i?`textureLoad( ${t}, ${s}, ${i}, ${r} )`:`textureLoad( ${t}, ${s}, ${r} )`}generateTextureStore(e,t,s,i){return`textureStore( ${t}, ${s}, ${i} )`}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===Ie||!0===e.isMultisampleRenderTargetTexture}generateTexture(e,t,s,i,r=this.shaderStage){let n=null;return n=!0===e.isVideoTexture?this._generateVideoSample(t,s,r):this.isUnfilterable(e)?this.generateTextureLod(e,t,s,"0",i,r):this._generateTextureSample(e,t,s,i,r),n}generateTextureGrad(e,t,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${i[0]}, ${i[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${n} shader.`)}generateTextureCompare(e,t,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${i} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}generateTextureLevel(e,t,s,i,r,n=this.shaderStage){let o=null;return o=!0===e.isVideoTexture?this._generateVideoSample(t,s,n):this._generateTextureSampleLevel(e,t,s,i,r,n),o}generateTextureBias(e,t,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${i} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${n} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){const t=e.name,s=e.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?t:"buffer"===s||"storageBuffer"===s?`NodeBuffer_${e.id}.${t}`:e.groupNode.name+"."+t}return super.getPropertyName(e)}getOutputStructName(){return"output"}_getUniformGroupCount(e){return Object.keys(this.uniforms[e]).length}getFunctionOperator(e){const t=vF[e];return void 0!==t?(this._include(t),t):null}getStorageAccess(e){if(e.isStorageTextureNode)switch(e.access){case PA:return"read";case IA:return"write";default:return"read_write"}else switch(e.access){case EA:return"read_write";case BA:return"read";default:return"write"}}getUniformFromNode(e,t,s,i=null){const r=super.getUniformFromNode(e,t,s,i),n=this.getDataFromNode(e,s,this.globalCache);if(void 0===n.uniformGPU){let i;const o=e.groupNode,a=o.name,h=this.getBindGroupArray(a,s);if("texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t){let n=null;if("texture"===t||"storageTexture"===t?n=new NP(r.name,r.node,o,e.access?e.access:null):"cubeTexture"===t?n=new AP(r.name,r.node,o,e.access?e.access:null):"texture3D"===t&&(n=new CP(r.name,r.node,o,e.access?e.access:null)),n.store=!0===e.isStorageTextureNode,n.setVisibility(xF[s]),"fragment"===s&&!1===this.isUnfilterable(e.value)&&!1===n.store){const e=new iF(`${r.name}_sampler`,r.node,o);e.setVisibility(xF[s]),h.push(e,n),i=[e,n]}else h.push(n),i=[n]}else if("buffer"===t||"storageBuffer"===t){const r=new("storageBuffer"===t?oF:vP)(e,o);r.setVisibility(xF[s]),h.push(r),i=r}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=e[a];void 0===n&&(n=new wP(a,o),n.setVisibility(xF[s]),e[a]=n,h.push(n)),i=this.getNodeUniform(r,t),n.addUniform(i)}n.uniformGPU=i}return r}getBuiltin(e,t,s,i=this.shaderStage){const r=this.builtins[i]||(this.builtins[i]=new Map);return!1===r.has(e)&&r.set(e,{name:e,property:t,type:s}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),i=[];for(const e of t.inputs)i.push(e.name+" : "+this.getType(e.type));let r=`fn ${t.name}( ${i.join(", ")} ) -> ${this.getType(t.type)} {\n${s.vars}\n${s.code}\n`;return s.result&&(r+=`\treturn ${s.result};\n`),r+="\n}\n",r}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4<f32>")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){const t=[],s=this.directives[e];if(void 0!==s)for(const e of s)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}getBuiltins(e){const t=[],s=this.builtins[e];if(void 0!==s)for(const{name:e,property:i,type:r}of s.values())t.push(`@builtin( ${e} ) ${i} : ${r}`);return t.join(",\n\t")}getScopedArray(e,t,s,i){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:s,bufferCount:i}),e}getScopedArrays(e){if("compute"!==e)return;const t=[];for(const{name:e,scope:s,bufferType:i,bufferCount:r}of this.scopedArrays.values()){const n=this.getType(i);t.push(`var<${s}> ${e}: array< ${n}, ${r} >;`)}return t.join("\n")}getAttributes(e){const t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","id","vec3<u32>","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3<u32>","attribute"),this.getBuiltin("local_invocation_id","localId","vec3<u32>","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3<u32>","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){const e=this.getBuiltins("attribute");e&&t.push(e);const s=this.getAttributesArray();for(let e=0,i=s.length;e<i;e++){const i=s[e],r=i.name,n=this.getType(i.type);t.push(`@location( ${e} ) ${r} : ${n}`)}}return t.join(",\n\t")}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;e<s.length;e++){const i=s[e];t.push(`\t@location( ${e} ) m${e} : ${i}<f32>`)}const i=this.getBuiltins("output");return i&&t.push("\t"+i),t.join(",\n")}getStructs(e){const t=[],s=this.structs[e];for(let e=0,i=s.length;e<i;e++){const i=s[e],r=i.name;let n=`struct ${r} {\n`;n+=this.getStructMembers(i),n+="\n}",t.push(n),t.push(`\nvar<private> output : ${r};\n\n`)}return t.join("\n\n")}getVar(e,t){return`var ${t} : ${this.getType(e)}`}getVars(e){const t=[],s=this.vars[e];if(void 0!==s)for(const e of s)t.push(`\t${this.getVar(e.type,e.name)};`);return`\n${t.join("\n")}\n`}getVaryings(e){const t=[];if("vertex"===e&&this.getBuiltin("position","Vertex","vec4<f32>","vertex"),"vertex"===e||"fragment"===e){const s=this.varyings,i=this.vars[e];for(let r=0;r<s.length;r++){const n=s[r];if(n.needsInterpolation){let e=`@location( ${r} )`;/^(int|uint|ivec|uvec)/.test(n.type)&&(e+=" @interpolate( flat )"),t.push(`${e} ${n.name} : ${this.getType(n.type)}`)}else"vertex"===e&&!1===i.includes(n)&&i.push(n)}}const s=this.getBuiltins(e);s&&t.push(s);const i=t.join(",\n\t");return"vertex"===e?this._getWGSLStruct("VaryingsStruct","\t"+i):i}getUniforms(e){const t=this.uniforms[e],s=[],i=[],r=[],n={};for(const r of t){const t=r.groupNode.name,o=this.bindingsIndexes[t];if("texture"===r.type||"cubeTexture"===r.type||"storageTexture"===r.type||"texture3D"===r.type){const t=r.node.value;let i;"fragment"===e&&!1===this.isUnfilterable(t)&&!0!==r.node.isStorageTextureNode&&(!0===t.isDepthTexture&&null!==t.compareFunction?s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${r.name}_sampler : sampler_comparison;`):s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${r.name}_sampler : sampler;`));let n="";if(!0===t.isMultisampleRenderTargetTexture&&(n="_multisampled"),!0===t.isCubeTexture)i="texture_cube<f32>";else if(!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture)i="texture_2d_array<f32>";else if(!0===t.isDepthTexture)i=`texture_depth${n}_2d`;else if(!0===t.isVideoTexture)i="texture_external";else if(!0===t.isData3DTexture)i="texture_3d<f32>";else if(!0===r.node.isStorageTextureNode){i=`texture_storage_2d<${cF(t)}, ${this.getStorageAccess(r.node)}>`}else{i=`texture${n}_2d<${this.getComponentTypeFromTexture(t).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${r.name} : ${i};`)}else if("buffer"===r.type||"storageBuffer"===r.type){const e=r.node,t=this.getType(e.bufferType),s=e.bufferCount,n=s>0?", "+s:"",a=e.isAtomic?`atomic<${t}>`:`${t}`,h=`\t${r.name} : array< ${a}${n} >\n`,u=e.isStorageBufferNode?`storage, ${this.getStorageAccess(e)}`:"uniform";i.push(this._getWGSLStructBinding("NodeBuffer_"+e.id,h,u,o.binding++,o.group))}else{const e=this.getType(this.getVectorType(r.type)),t=r.groupNode.name;(n[t]||(n[t]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${r.name} : ${e}`)}}for(const e in n){const t=n[e];r.push(this._getWGSLStructBinding(e,t.snippets.join(",\n"),"uniform",t.index,t.id))}let o=s.join("\n");return o+=i.join("\n"),o+=r.join("\n"),o}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){const s=e[t];s.uniforms=this.getUniforms(t),s.attributes=this.getAttributes(t),s.varyings=this.getVaryings(t),s.structs=this.getStructs(t),s.vars=this.getVars(t),s.codes=this.getCodes(t),s.directives=this.getDirectives(t),s.scopedArrays=this.getScopedArrays(t);let i="// code\n\n";i+=this.flowCode[t];const r=this.flowNodes[t],n=r[r.length-1],o=n.outputNode,a=void 0!==o&&!0===o.isOutputStructNode;for(const e of r){const r=this.getFlowData(e),h=e.name;if(h&&(i.length>0&&(i+="\n"),i+=`\t// flow -> ${h}\n\t`),i+=`${r.code}\n\t`,e===n&&"compute"!==t)if(i+="// result\n\n\t","vertex"===t)i+=`varyings.Vertex = ${r.result};`;else if("fragment"===t)if(a)s.returnType=o.nodeType,i+=`return ${r.result};`;else{let e="\t@location(0) color: vec4<f32>";const t=this.getBuiltins("output");t&&(e+=",\n\t"+t),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",e),s.structs+="\nvar<private> output : OutputStruct;\n\n",i+=`output.color = ${r.result};\n\n\treturn output;`}}s.flow=i}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment)):this.computeShader=this._getWGSLComputeCode(e.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(e,t=null){let s;return null!==t&&(s=this._getWGSLMethod(e+"_"+t)),void 0===s&&(s=this._getWGSLMethod(e)),s||e}getType(e){return TF[e]||e}isAvailable(e){let t=bF[e];return void 0===t&&("float32Filterable"===e&&(t=this.renderer.hasFeature("float32-filterable")),bF[e]=t),t}_getWGSLMethod(e){return void 0!==_F[e]&&this._include(e),wF[e]}_include(e){const t=_F[e];return t.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\nvar<private> varyings : VaryingsStruct;\n\n// codes\n${e.codes}\n\n@vertex\nfn main( ${e.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(e){return`${this.getSignature()}\n// global\n${SF}\n\n// uniforms\n${e.uniforms}\n\n// structs\n${e.structs}\n\n// codes\n${e.codes}\n\n@fragment\nfn main( ${e.varyings} ) -> ${e.returnType} {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLComputeCode(e,t){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// system\nvar<private> instanceIndex : u32;\n\n// locals\n${e.scopedArrays}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@compute @workgroup_size( ${t} )\nfn main( ${e.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${t}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${t});\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLStruct(e,t){return`\nstruct ${e} {\n${t}\n};`}_getWGSLStructBinding(e,t,s,i=0,r=0){const n=e+"Struct";return`${this._getWGSLStruct(n,t)}\n@binding( ${i} ) @group( ${r} )\nvar<${s}> ${e} : ${n};`}}class NF{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return null!==e.depthTexture?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=ZN.Depth24PlusStencil8:e.depth&&(t=ZN.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getCurrentColorFormat(e){let t;return t=null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat(),t}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?CN:e.isLineSegments||e.isMesh&&!0===t.wireframe?RN:e.isLine?EN:e.isMesh?BN:void 0}getSampleCount(e){let t=1;return e>1&&(t=Math.pow(2,Math.floor(Math.log2(e))),2===t&&(t=4)),t}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?ZN.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const AF=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),CF=new Map([[bn,["float16"]]]),RF=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class EF{constructor(e){this.backend=e}createAttribute(e,t){const s=this._getBufferAttribute(e),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===e.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const e=new Uint32Array(a.length);for(let t=0;t<a.length;t++)e[t]=a[t];a=e}if(s.array=a,(s.isStorageBufferAttribute||s.isStorageInstancedBufferAttribute)&&3===s.itemSize){a=new a.constructor(4*s.count);for(let e=0;e<s.count;e++)a.set(s.array.subarray(3*e,3*e+3),4*e);s.itemSize=4,s.array=a}const h=a.byteLength+(4-a.byteLength%4)%4;n=o.createBuffer({label:s.name,size:h,usage:t,mappedAtCreation:!0}),new a.constructor(n.getMappedRange()).set(a),n.unmap(),r.buffer=n}}updateAttribute(e){const t=this._getBufferAttribute(e),s=this.backend,i=s.device,r=s.get(t).buffer,n=t.array,o=t.updateRanges;if(0===o.length)i.queue.writeBuffer(r,0,n,0);else{for(let e=0,t=o.length;e<t;e++){const t=o[e];i.queue.writeBuffer(r,0,n,t.start*n.BYTES_PER_ELEMENT,t.count*n.BYTES_PER_ELEMENT)}t.clearUpdateRanges()}}createShaderVertexBuffers(e){const t=e.getAttributes(),s=new Map;for(let e=0;e<t.length;e++){const i=t[e],r=i.array.BYTES_PER_ELEMENT,n=this._getBufferAttribute(i);let o=s.get(n);if(void 0===o){let e,t;!0===i.isInterleavedBufferAttribute?(e=i.data.stride*r,t=i.data.isInstancedInterleavedBuffer?$A:qA):(e=i.itemSize*r,t=i.isInstancedBufferAttribute?$A:qA),!1!==i.normalized||i.array.constructor!==Int16Array&&i.array.constructor!==Uint16Array||(e=4),o={arrayStride:e,attributes:[],stepMode:t},s.set(n,o)}const a=this._getVertexFormat(i),h=!0===i.isInterleavedBufferAttribute?i.offset*r:0;o.attributes.push({shaderLocation:e,offset:h,format:a})}return Array.from(s.values())}destroyAttribute(e){const t=this.backend;t.get(this._getBufferAttribute(e)).buffer.destroy(),t.delete(e)}async getArrayBufferAsync(e){const t=this.backend,s=t.device,i=t.get(this._getBufferAttribute(e)).buffer,r=i.size,n=s.createBuffer({label:e.name,size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),o=s.createCommandEncoder({});o.copyBufferToBuffer(i,0,n,0,r),n.unmap();const a=o.finish();s.queue.submit([a]),await n.mapAsync(GPUMapMode.READ);return n.getMappedRange()}_getVertexFormat(e){const{itemSize:t,normalized:s}=e,i=e.array.constructor,r=e.constructor;let n;if(1==t)n=RF.get(i);else{const e=(CF.get(r)||AF.get(i))[s?1:0];if(e){const s=i.BYTES_PER_ELEMENT*t,r=4*Math.floor((s+3)/4)/i.BYTES_PER_ELEMENT;if(r%1)throw new Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");n=`${e}x${r}`}}return n||console.error("THREE.WebGPUAttributeUtils: Vertex format not supported yet."),n}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}class BF{constructor(e){this.backend=e,this.bindGroupLayoutCache=new WeakMap}createBindingsLayout(e){const t=this.backend.device,s=[];let i=0;for(const t of e.bindings){const e={binding:i++,visibility:t.visibility};if(t.isUniformBuffer||t.isStorageBuffer){const s={};t.isStorageBuffer&&(s.type=t.access),e.buffer=s}else if(t.isSampler){const s={};t.texture.isDepthTexture&&null!==t.texture.compareFunction&&(s.type="comparison"),e.sampler=s}else if(t.isSampledTexture&&t.texture.isVideoTexture)e.externalTexture={};else if(t.isSampledTexture&&t.store){const s=this.backend.get(t.texture).texture.format,i=t.access;e.storageTexture={format:s,access:i}}else if(t.isSampledTexture){const s={};if(!0===t.texture.isMultisampleRenderTargetTexture&&(s.multisampled=!0),t.texture.isDepthTexture)s.sampleType=UA;else if(t.texture.isDataTexture||t.texture.isDataArrayTexture||t.texture.isData3DTexture){const e=t.texture.type;e===Ee?s.sampleType=OA:e===Be?s.sampleType=LA:e===Ie&&(this.backend.hasFeature("float32-filterable")?s.sampleType=FA:s.sampleType=zA)}t.isSampledCubeTexture?s.viewDimension=WA:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?s.viewDimension=GA:t.isSampledTexture3D&&(s.viewDimension=HA),e.texture=s}else console.error(`WebGPUBindingUtils: Unsupported binding "${t}".`);s.push(e)}return t.createBindGroupLayout({entries:s})}createBindings(e){const{backend:t,bindGroupLayoutCache:s}=this,i=t.get(e);let r=s.get(e.bindingsReference);void 0===r&&(r=this.createBindingsLayout(e),s.set(e.bindingsReference,r));const n=this.createBindGroup(e,r);i.layout=r,i.group=n}updateBinding(e){const t=this.backend,s=t.device,i=e.buffer,r=t.get(e).buffer;s.queue.writeBuffer(r,0,i,0)}createBindGroup(e,t){const s=this.backend,i=s.device;let r=0;const n=[];for(const t of e.bindings){if(t.isUniformBuffer){const e=s.get(t);if(void 0===e.buffer){const s=t.byteLength,r=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,n=i.createBuffer({label:"bindingBuffer_"+t.name,size:s,usage:r});e.buffer=n}n.push({binding:r,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){const e=s.get(t);if(void 0===e.buffer){const i=t.attribute;e.buffer=s.get(i).buffer}n.push({binding:r,resource:{buffer:e.buffer}})}else if(t.isSampler){const e=s.get(t.texture);n.push({binding:r,resource:e.sampler})}else if(t.isSampledTexture){const e=s.get(t.texture);let o;if(void 0!==e.externalTexture)o=i.importExternalTexture({source:e.externalTexture});else{const s=t.store?1:e.texture.mipLevelCount,i=`view-${e.texture.width}-${e.texture.height}-${s}`;if(o=e[i],void 0===o){const r=jA;let n;n=t.isSampledCubeTexture?WA:t.isSampledTexture3D?HA:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?GA:kA,o=e[i]=e.texture.createView({aspect:r,dimension:n,mipLevelCount:s})}}n.push({binding:r,resource:o})}r++}return i.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:n})}}class IF{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:s,material:i,geometry:r,pipeline:n}=e,{vertexProgram:o,fragmentProgram:a}=n,h=this.backend,u=h.device,l=h.utils,c=h.get(n),d=[];for(const t of e.getBindings()){const e=h.get(t);d.push(e.layout)}const p=h.attributeUtils.createShaderVertexBuffers(e);let m;!0===i.transparent&&0!==i.blending&&(m=this._getBlending(i));let g={};!0===i.stencilWrite&&(g={compare:this._getStencilCompare(i),failOp:this._getStencilOperation(i.stencilFail),depthFailOp:this._getStencilOperation(i.stencilZFail),passOp:this._getStencilOperation(i.stencilZPass)});const f=this._getColorWriteMask(i),y=[];if(null!==e.context.textures){const t=e.context.textures;for(let e=0;e<t.length;e++){const s=l.getTextureFormatGPU(t[e]);y.push({format:s,blend:m,writeMask:f})}}else{const t=l.getCurrentColorFormat(e.context);y.push({format:t,blend:m,writeMask:f})}const x=h.get(o).module,b=h.get(a).module,v=this._getPrimitiveState(s,r,i),T=this._getDepthCompare(i),_=l.getCurrentDepthStencilFormat(e.context),w=this._getSampleCount(e.context),S={label:`renderPipeline_${i.name||i.type}_${i.id}`,vertex:Object.assign({},x,{buffers:p}),fragment:Object.assign({},b,{targets:y}),primitive:v,depthStencil:{format:_,depthWriteEnabled:i.depthWrite,depthCompare:T,stencilFront:g,stencilBack:{},stencilReadMask:i.stencilFuncMask,stencilWriteMask:i.stencilWriteMask},multisample:{count:w,alphaToCoverageEnabled:i.alphaToCoverage&&w>1},layout:u.createPipelineLayout({bindGroupLayouts:d})};if(null===t)c.pipeline=u.createRenderPipeline(S);else{const e=new Promise(e=>{u.createRenderPipelineAsync(S).then(t=>{c.pipeline=t,e()})});t.push(e)}}createBundleEncoder(e){const t=this.backend,{utils:s,device:i}=t,r=s.getCurrentDepthStencilFormat(e),n={label:"renderBundleEncoder",colorFormats:[s.getCurrentColorFormat(e)],depthStencilFormat:r,sampleCount:this._getSampleCount(e)};return i.createRenderBundleEncoder(n)}createComputePipeline(e,t){const s=this.backend,i=s.device,r=s.get(e.computeProgram).module,n=s.get(e),o=[];for(const e of t){const t=s.get(e);o.push(t.layout)}n.pipeline=i.createComputePipeline({compute:r,layout:i.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(e){let t,s;const i=e.blending,r=e.blendSrc,n=e.blendDst,o=e.blendEquation;if(5===i){const i=null!==e.blendSrcAlpha?e.blendSrcAlpha:r,a=null!==e.blendDstAlpha?e.blendDstAlpha:n,h=null!==e.blendEquationAlpha?e.blendEquationAlpha:o;t={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=(e,i,r,n)=>{t={srcFactor:e,dstFactor:i,operation:gA},s={srcFactor:r,dstFactor:n,operation:gA}};if(e.premultipliedAlpha)switch(i){case 1:r(iA,aA,iA,aA);break;case 2:r(iA,iA,iA,iA);break;case 3:r(sA,nA,sA,iA);break;case 4:r(sA,rA,sA,oA)}else switch(i){case 1:r(oA,aA,iA,aA);break;case 2:r(oA,iA,oA,iA);break;case 3:r(sA,nA,sA,iA);break;case 4:r(sA,rA,sA,rA)}}if(void 0!==t&&void 0!==s)return{color:t,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(e){let t;switch(e){case 200:t=sA;break;case 201:t=iA;break;case 202:t=rA;break;case 203:t=nA;break;case R:t=oA;break;case E:t=aA;break;case 208:t=hA;break;case 209:t=uA;break;case 206:t=lA;break;case 207:t=cA;break;case 210:t=dA;break;case 211:t=pA;break;case 212:t=mA;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const s=e.stencilFunc;switch(s){case 512:t=PN;break;case vs:t=DN;break;case 513:t=FN;break;case 515:t=UN;break;case 514:t=zN;break;case 518:t=VN;break;case 516:t=ON;break;case 517:t=LN;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return t}_getStencilOperation(e){let t;switch(e){case os:t=_A;break;case 0:t=wA;break;case 7681:t=SA;break;case 5386:t=MA;break;case 7682:t=NA;break;case 7683:t=AA;break;case 34055:t=CA;break;case 34056:t=RA;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case v:t=gA;break;case 101:t=fA;break;case 102:t=yA;break;case 103:t=xA;break;case 104:t=bA;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,s){const i={},r=this.backend.utils;switch(i.topology=r.getPrimitiveTopology(e,s),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(i.stripIndexFormat=t.index.array instanceof Uint16Array?XN:YN),s.side){case 0:i.frontFace=HN,i.cullMode=$N;break;case 1:i.frontFace=HN,i.cullMode=qN;break;case 2:i.frontFace=HN,i.cullMode=jN;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return i}_getColorWriteMask(e){return!0===e.colorWrite?TA:vA}_getDepthCompare(e){let t;if(!1===e.depthTest)t=DN;else{const s=e.depthFunc;switch(s){case 0:t=PN;break;case 1:t=DN;break;case 2:t=FN;break;case 3:t=UN;break;case 4:t=zN;break;case 5:t=VN;break;case 6:t=ON;break;case 7:t=LN;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return t}}class PF extends OP{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.trackTimestamp=!0===e.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new NF(this),this.attributeUtils=new EF(this),this.bindingUtils=new BF(this),this.pipelineUtils=new IF(this),this.textureUtils=new lF(this),this.occludedResolveCache=new Map}async init(e){await super.init(e);const t=this.parameters;let s;if(void 0===t.device){const e={powerPreference:t.powerPreference},i=await navigator.gpu.requestAdapter(e);if(null===i)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const r=Object.values(XA),n=[];for(const e of r)i.features.has(e)&&n.push(e);const o={requiredFeatures:n,requiredLimits:t.requiredLimits};s=await i.requestDevice(o)}else s=t.device;const i=void 0!==t.context?t.context:e.domElement.getContext("webgpu");this.device=s,this.context=i;const r=t.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(XA.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:r}),this.updateSize()}get coordinateSystem(){return ks}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(null===e){const t=this.renderer;e={colorAttachments:[{view:null}],depthStencilAttachment:{view:this.textureUtils.getDepthBuffer(t.depth,t.stencil).createView()}};const s=e.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=e}const t=e.colorAttachments[0];return this.renderer.samples>0?t.resolveTarget=this.context.getCurrentTexture().createView():t.view=this.context.getCurrentTexture().createView(),e}_getRenderPassDescriptor(e){const t=e.renderTarget,s=this.get(t);let i=s.descriptors;if(void 0===i||s.width!==t.width||s.height!==t.height||s.activeMipmapLevel!==t.activeMipmapLevel||s.samples!==t.samples){i={},s.descriptors=i;const e=()=>{t.removeEventListener("dispose",e),this.delete(t)};t.addEventListener("dispose",e)}const r=e.getCacheKey();let n=i[r];if(void 0===n){const o=e.textures,a=[];for(let t=0;t<o.length;t++){const s=this.get(o[t]),i=s.texture.createView({baseMipLevel:e.activeMipmapLevel,mipLevelCount:1,baseArrayLayer:e.activeCubeFace,dimension:kA});let r,n;void 0!==s.msaaTexture?(r=s.msaaTexture.createView(),n=i):(r=i,n=void 0),a.push({view:r,resolveTarget:n,loadOp:GN,storeOp:kN})}n={colorAttachments:a,depthStencilAttachment:{view:this.get(e.depthTexture).texture.createView()}},i[r]=n,s.width=t.width,s.height=t.height,s.samples=t.samples,s.activeMipmapLevel=t.activeMipmapLevel}return n}beginRender(e){const t=this.get(e),s=this.device,i=e.occlusionQueryCount;let r,n;i>0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,r=s.createQuerySet({type:"occlusion",count:i}),t.occlusionQuerySet=r,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(i),t.lastOcclusionObject=null),n=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e),this.initTimestampQuery(e,n),n.occlusionQuerySet=r;const o=n.depthStencilAttachment;if(null!==e.textures){const t=n.colorAttachments;for(let s=0;s<t.length;s++){const i=t[s];e.clearColor?(i.clearValue=0===s?e.clearColorValue:{r:0,g:0,b:0,a:1},i.loadOp=WN,i.storeOp=kN):(i.loadOp=GN,i.storeOp=kN)}}else{const t=n.colorAttachments[0];e.clearColor?(t.clearValue=e.clearColorValue,t.loadOp=WN,t.storeOp=kN):(t.loadOp=GN,t.storeOp=kN)}e.depth&&(e.clearDepth?(o.depthClearValue=e.clearDepthValue,o.depthLoadOp=WN,o.depthStoreOp=kN):(o.depthLoadOp=GN,o.depthStoreOp=kN)),e.stencil&&(e.clearStencil?(o.stencilClearValue=e.clearStencilValue,o.stencilLoadOp=WN,o.stencilStoreOp=kN):(o.stencilLoadOp=GN,o.stencilStoreOp=kN));const a=s.createCommandEncoder({label:"renderContext_"+e.id}),h=a.beginRenderPass(n);if(t.descriptor=n,t.encoder=a,t.currentPass=h,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.renderBundles=[],e.viewport&&this.updateViewport(e),e.scissor){const{x:t,y:s,width:i,height:r}=e.scissorValue;h.setScissorRect(t,s,i,r)}}finishRender(e){const t=this.get(e),s=e.occlusionQueryCount;if(t.renderBundles.length>0&&t.currentPass.executeBundles(t.renderBundles),s>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery(),t.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});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,s,r,0),t.encoder.copyBufferToBuffer(r,0,n,0,i),t.occlusionQueryBuffer=n,this.resolveOccludedAsync(e)}if(this.prepareTimestampBuffer(e,t.encoder),this.device.queue.submit([t.encoder.finish()]),null!==e.textures){const t=e.textures;for(let e=0;e<t.length;e++){const s=t[e];!0===s.generateMipmaps&&this.textureUtils.generateMipmaps(s)}}}isOccluded(e,t){const s=this.get(e);return s.occluded&&s.occluded.has(t)}async resolveOccludedAsync(e){const t=this.get(e),{currentOcclusionQueryBuffer:s,currentOcclusionQueryObjects:i}=t;if(s&&i){const e=new WeakSet;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueryBuffer=null,await s.mapAsync(GPUMapMode.READ);const r=s.getMappedRange(),n=new BigUint64Array(r);for(let t=0;t<i.length;t++)n[t]!==BigInt(0)&&e.add(i[t]);s.destroy(),t.occluded=e}}updateViewport(e){const{currentPass:t}=this.get(e),{x:s,y:i,width:r,height:n,minDepth:o,maxDepth:a}=e.viewportValue;t.setViewport(s,i,r,n,o,a)}clear(e,t,s,i=null){const r=this.device,n=this.renderer;let o,a,h,u,l=[];if(e){const e=this.getClearColor();if(!0===this.renderer.alpha){const t=e.a;a={r:e.r*t,g:e.g*t,b:e.b*t,a:t}}else a={r:e.r,g:e.g,b:e.b,a:e.a}}if(null===i){h=n.depth,u=n.stencil;const t=this._getDefaultRenderPassDescriptor();if(e){l=t.colorAttachments;const e=l[0];e.clearValue=a,e.loadOp=WN,e.storeOp=kN}(h||u)&&(o=t.depthStencilAttachment)}else{if(h=i.depth,u=i.stencil,e)for(const e of i.textures){const t=this.get(e),s=t.texture.createView();let i,r;void 0!==t.msaaTexture?(i=t.msaaTexture.createView(),r=s):(i=s,r=void 0),l.push({view:i,resolveTarget:r,clearValue:a,loadOp:WN,storeOp:kN})}if(h||u){o={view:this.get(i.depthTexture).texture.createView()}}}h&&(t?(o.depthLoadOp=WN,o.depthClearValue=n.getClearDepth(),o.depthStoreOp=kN):(o.depthLoadOp=GN,o.depthStoreOp=kN)),u&&(s?(o.stencilLoadOp=WN,o.stencilClearValue=n.getClearStencil(),o.stencilStoreOp=kN):(o.stencilLoadOp=GN,o.stencilStoreOp=kN));const c=r.createCommandEncoder({});c.beginRenderPass({colorAttachments:l,depthStencilAttachment:o}).end(),r.queue.submit([c.finish()])}beginCompute(e){const t=this.get(e),s={};this.initTimestampQuery(e,s),t.cmdEncoderGPU=this.device.createCommandEncoder(),t.passEncoderGPU=t.cmdEncoderGPU.beginComputePass(s)}compute(e,t,s,i){const{passEncoderGPU:r}=this.get(e),n=this.get(i).pipeline;r.setPipeline(n);for(let e=0,t=s.length;e<t;e++){const t=s[e],i=this.get(t);r.setBindGroup(e,i.group)}const o=this.device.limits.maxComputeWorkgroupsPerDimension,a=this.get(t);void 0===a.dispatchSize&&(a.dispatchSize={x:0,y:1,z:1});const{dispatchSize:h}=a;t.dispatchCount>o?(h.x=Math.min(t.dispatchCount,o),h.y=Math.ceil(t.dispatchCount/o)):h.x=t.dispatchCount,r.dispatchWorkgroups(h.x,h.y,h.z)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.prepareTimestampBuffer(e,t.cmdEncoderGPU),this.device.queue.submit([t.cmdEncoderGPU.finish()])}draw(e,t){const{object:s,context:i,pipeline:r}=e,n=e.getBindings(),o=this.get(i),a=this.get(r).pipeline,h=o.currentSets,u=o.currentPass,l=e.getDrawParameters();if(null===l)return;h.pipeline!==a&&(u.setPipeline(a),h.pipeline=a);const c=h.bindingGroups;for(let e=0,t=n.length;e<t;e++){const t=n[e],s=this.get(t);c[t.index]!==t.id&&(u.setBindGroup(t.index,s.group),c[t.index]=t.id)}const d=e.getIndex(),p=null!==d;if(!0===p&&h.index!==d){const e=this.get(d).buffer,t=d.array instanceof Uint16Array?XN:YN;u.setIndexBuffer(e,t),h.index=d}const m=e.getVertexBuffers();for(let e=0,t=m.length;e<t;e++){const t=m[e];if(h.attributes[e]!==t){const s=this.get(t).buffer;u.setVertexBuffer(e,s),h.attributes[e]=t}}if(void 0!==o.occlusionQuerySet){const e=o.lastOcclusionObject;e!==s&&(null!==e&&!0===e.occlusionTest&&(u.endOcclusionQuery(),o.occlusionQueryIndex++),!0===s.occlusionTest&&(u.beginOcclusionQuery(o.occlusionQueryIndex),o.occlusionQueryObjects[o.occlusionQueryIndex]=s),o.lastOcclusionObject=s)}if(!0===s.isBatchedMesh){const e=s._multiDrawStarts,t=s._multiDrawCounts,i=s._multiDrawCount,r=s._multiDrawInstances,n=p?d.array.BYTES_PER_ELEMENT:1;for(let s=0;s<i;s++){const i=r?r[s]:1,o=i>1?0:s;u.drawIndexed(t[s],i,e[s]/n,0,o)}}else if(!0===p){const{vertexCount:e,instanceCount:i,firstVertex:r}=l;u.drawIndexed(e,i,r,0,0),t.update(s,e,i)}else{const{vertexCount:e,instanceCount:i,firstVertex:r}=l;u.draw(e,i,r,0),t.update(s,e,i)}}needsRenderUpdate(e){const t=this.get(e),{object:s,material:i}=e,r=this.utils,n=r.getSampleCountRenderContext(e.context),o=r.getCurrentColorSpace(e.context),a=r.getCurrentColorFormat(e.context),h=r.getCurrentDepthStencilFormat(e.context),u=r.getPrimitiveTopology(s,i);let l=!1;return t.material===i&&t.materialVersion===i.version&&t.transparent===i.transparent&&t.blending===i.blending&&t.premultipliedAlpha===i.premultipliedAlpha&&t.blendSrc===i.blendSrc&&t.blendDst===i.blendDst&&t.blendEquation===i.blendEquation&&t.blendSrcAlpha===i.blendSrcAlpha&&t.blendDstAlpha===i.blendDstAlpha&&t.blendEquationAlpha===i.blendEquationAlpha&&t.colorWrite===i.colorWrite&&t.depthWrite===i.depthWrite&&t.depthTest===i.depthTest&&t.depthFunc===i.depthFunc&&t.stencilWrite===i.stencilWrite&&t.stencilFunc===i.stencilFunc&&t.stencilFail===i.stencilFail&&t.stencilZFail===i.stencilZFail&&t.stencilZPass===i.stencilZPass&&t.stencilFuncMask===i.stencilFuncMask&&t.stencilWriteMask===i.stencilWriteMask&&t.side===i.side&&t.alphaToCoverage===i.alphaToCoverage&&t.sampleCount===n&&t.colorSpace===o&&t.colorFormat===a&&t.depthStencilFormat===h&&t.primitiveTopology===u&&t.clippingContextCacheKey===e.clippingContext.cacheKey||(t.material=i,t.materialVersion=i.version,t.transparent=i.transparent,t.blending=i.blending,t.premultipliedAlpha=i.premultipliedAlpha,t.blendSrc=i.blendSrc,t.blendDst=i.blendDst,t.blendEquation=i.blendEquation,t.blendSrcAlpha=i.blendSrcAlpha,t.blendDstAlpha=i.blendDstAlpha,t.blendEquationAlpha=i.blendEquationAlpha,t.colorWrite=i.colorWrite,t.depthWrite=i.depthWrite,t.depthTest=i.depthTest,t.depthFunc=i.depthFunc,t.stencilWrite=i.stencilWrite,t.stencilFunc=i.stencilFunc,t.stencilFail=i.stencilFail,t.stencilZFail=i.stencilZFail,t.stencilZPass=i.stencilZPass,t.stencilFuncMask=i.stencilFuncMask,t.stencilWriteMask=i.stencilWriteMask,t.side=i.side,t.alphaToCoverage=i.alphaToCoverage,t.sampleCount=n,t.colorSpace=o,t.colorFormat=a,t.depthStencilFormat=h,t.primitiveTopology=u,t.clippingContextCacheKey=e.clippingContext.cacheKey,l=!0),l}getRenderCacheKey(e){const{object:t,material:s}=e,i=this.utils,r=e.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(t,s),e.clippingContext.cacheKey].join()}createSampler(e){this.textureUtils.createSampler(e)}destroySampler(e){this.textureUtils.destroySampler(e)}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,i,r,n){return this.textureUtils.copyTextureToBuffer(e,t,s,i,r,n)}initTimestampQuery(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet){const e=this.device.createQuerySet({type:"timestamp",count:2}),i={querySet:e,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(t,{timestampWrites:i}),s.timeStampQuerySet=e}}prepareTimestampBuffer(e,t){if(!this.trackTimestamp)return;const s=this.get(e),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&&(t.resolveQuerySet(s.timeStampQuerySet,0,2,r,0),t.copyBufferToBuffer(r,0,n,0,i))}async resolveTimestampAsync(e,t="render"){if(!this.trackTimestamp)return;const s=this.get(e);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 e=new BigUint64Array(i.getMappedRange()),r=Number(e[1]-e[0])/1e6;this.renderer.info.updateTimestamp(t,r),i.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1}))}createNodeBuilder(e,t){return new MF(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const s=this.get(e),i=s.currentPass.finish();this.get(t).bundleGPU=i,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e){this.bindingUtils.createBindings(e)}updateBindings(e){this.bindingUtils.createBindings(e)}updateBinding(e){this.bindingUtils.updateBinding(e)}createIndexAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(e){return this.device.features.has(e)}copyTextureToTexture(e,t,s=null,i=null,r=0){let n=0,o=0,a=0,h=0,u=0,l=0,c=e.image.width,d=e.image.height;null!==s&&(h=s.x,u=s.y,l=s.z||0,c=s.width,d=s.height),null!==i&&(n=i.x,o=i.y,a=i.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),m=this.get(e).texture,g=this.get(t).texture;p.copyTextureToTexture({texture:m,mipLevel:r,origin:{x:h,y:u,z:l}},{texture:g,mipLevel:r,origin:{x:n,y:o,z:a}},[c,d,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(e,t,s){const i=this.get(t),{encoder:r,descriptor:n}=i;let o=null;o=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();const a=this.get(e).texture;if(o.format===a.format){i.currentPass.end(),r.copyTextureToTexture({texture:o,origin:{x:s.x,y:s.y,z:0}},{texture:a},[s.z,s.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e);for(let e=0;e<n.colorAttachments.length;e++)n.colorAttachments[e].loadOp=GN;t.depth&&(n.depthStencilAttachment.depthLoadOp=GN),t.stencil&&(n.depthStencilAttachment.stencilLoadOp=GN),i.currentPass=r.beginRenderPass(n),i.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null}}else console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",o.format,a.format)}}class FF extends _l{constructor(e,t,s,i,r,n){super(e,t,s,i,r,n),this.iesMap=null}copy(e,t){return super.copy(e,t),this.iesMap=e.iesMap,this}}class zF extends hP{constructor(){super(),this.addLight(NI,Al),this.addLight(AI,El),this.addLight(BI,Il),this.addLight(II,_l),this.addLight(FI,Bl),this.addLight(zI,fl),this.addLight(UI,Fl),this.addLight(PI,FF),this.addToneMapping(zE,1),this.addToneMapping(UE,2),this.addToneMapping(OE,3),this.addToneMapping(VE,4),this.addToneMapping(WE,6),this.addToneMapping(HE,7),this.addColorSpace(FE,$f(Kt,Jt)),this.addColorSpace(PE,$f(Jt,Kt))}}class UF extends gP{constructor(e={}){let t;e.forceWebGL?t=tF:(t=PF,e.getFallback=()=>(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new tF(e)));super(new t(e),e),this.nodes.library=new zF,this.isWebGPURenderer=!0}}const OF=new yT,LF=new fN(OF);class VF{constructor(e,t=Kp(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0,OF.name="PostProcessing"}render(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=0,e.outputColorSpace=Kt,LF.render(e),e.toneMapping=t,e.outputColorSpace=s}update(){if(!0===this.needsUpdate){const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;LF.material.fragmentNode=!0===this.outputColorTransform?My(this.outputNode,t,s):this.outputNode.context({toneMapping:t,outputColorSpace:s}),LF.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=0,e.outputColorSpace=Kt,await LF.renderAsync(e),e.toneMapping=t,e.outputColorSpace=s}}class DF extends Ti{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=Te,this.minFilter=Te,this.isStorageTexture=!0}}class kF extends cn{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageBufferAttribute=!0}}class GF extends Ho{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageInstancedBufferAttribute=!0}}class WF extends nl{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,s,i){const r=new hl(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(e,s=>{try{t(this.parse(JSON.parse(s)))}catch(t){i?i(t):console.error(t),this.manager.itemError(e)}},s,i)}parseNodes(e){const t={};if(void 0!==e){for(const s of e){const{uuid:e,type:i}=s;t[e]=this.createNodeFromType(i),t[e].uuid=e}const s={nodes:t,textures:this.textures};for(const i of e){i.meta=s;t[i.uuid].deserialize(i),delete i.meta}}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const s={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=s,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return void 0===this.nodes[e]?(console.error("THREE.NodeLoader: Node type not found:",e),Dp()):Cp(new this.nodes[e])}}class HF extends zl{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),s=this.nodes,i=e.inputNodes;for(const e in i){const r=i[e];t[e]=s[r]}return t}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}createMaterialFromType(e){const t=this.nodeMaterials[e];return void 0!==t?new t:super.createMaterialFromType(e)}}class jF extends Vl{constructor(e){super(e),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}parse(e,t){this._nodesJSON=e.nodes;const s=super.parse(e,t);return this._nodesJSON=null,s}parseNodes(e,t){if(void 0!==e){const s=new WF;return s.setNodes(this.nodes),s.setTextures(t),s.parseNodes(e)}return{}}parseMaterials(e,t){const s={};if(void 0!==e){const i=this.parseNodes(this._nodesJSON,t),r=new HF;r.setTextures(t),r.setNodes(i),r.setNodeMaterials(this.nodeMaterials);for(let t=0,i=e.length;t<i;t++){const i=e[t];s[i.uuid]=r.parse(i)}}return s}}"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:e}})),"undefined"!=typeof window&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=e);export{te as ACESFilmicToneMapping,Ov as AONode,v as AddEquation,Z as AddOperation,Dt as AdditiveAnimationBlendMode,f as AdditiveBlending,TC as AfterImageNode,ie as AgXToneMapping,Ve as AlphaFormat,Cs as AlwaysCompare,k as AlwaysDepth,vs as AlwaysStencilFunc,Bl as AmbientLight,FI as AmbientLightNode,wR as AnaglyphPassNode,tE as AnalyticLightNode,BC as AnamorphicNode,Tc as AnimationAction,el as AnimationClip,ul as AnimationLoader,wc as AnimationMixer,vc as AnimationObjectGroup,ku as AnimationUtils,sh as ArcCurve,Jl as ArrayCamera,Wd as ArrayElementNode,fd as ArrowHelper,Ym as AssignNode,ne as AttachedBindMode,Ay as AttributeNode,nc as Audio,cc as AudioAnalyser,jl as AudioContext,rc as AudioListener,ql as AudioLoader,yd as AxesHelper,o_ as BRDF_GGX,jT as BRDF_Lambert,d as BackSide,Ht as BasicDepthPacking,LT as BasicEnvironmentNode,a as BasicShadowMap,fv as BatchNode,Sa as BatchedMesh,oR as BloomNode,Vo as Bone,$u as BooleanKeyframeTrack,Oc as Box2,Pi as Box3,cd as Box3Helper,Gn as BoxGeometry,ld as BoxHelper,Mv as Break,cn as BufferAttribute,oy as BufferAttributeNode,Cn as BufferGeometry,Ll as BufferGeometryLoader,Ox as BufferNode,yb as BumpMapNode,gy as BypassNode,Ae as ByteType,sl as Cache,py as CacheNode,Xn as Camera,ad as CameraHelper,Ka as CanvasTexture,wh as CapsuleGeometry,hh as CatmullRomCurve3,ee as CineonToneMapping,Sh as CircleGeometry,me as ClampToEdgeWrapping,Kl as Clock,SS as CodeNode,Kr as Color,Xu as ColorKeyframeTrack,di as ColorManagement,Xf as ColorSpaceNode,Za as CompressedArrayTexture,Ja as CompressedCubeTexture,Ya as CompressedTexture,ll as CompressedTextureLoader,cy as ComputeNode,Nh as ConeGeometry,Kd as ConstNode,L as ConstantAlphaFactor,U as ConstantColorFactor,Of as ContextNode,Sv as Continue,bd as Controls,Hd as ConvertNode,eo as CubeCamera,he as CubeReflectionMapping,ue as CubeRefractionMapping,to as CubeTexture,dl as CubeTextureLoader,zx as CubeTextureNode,de as CubeUVReflectionMapping,dh as CubicBezierCurve,ph as CubicBezierCurve3,Wu as CubicInterpolant,r as CullFaceBack,n as CullFaceFront,o as CullFaceFrontBack,i as CullFaceNone,eh as Curve,vh as CurvePath,b as CustomBlending,se as CustomToneMapping,Mh as CylinderGeometry,Fc as Cylindrical,a_ as DFGApprox,i_ as D_GGX,Ai as Data3DTexture,Mi as DataArrayTexture,Do as DataTexture,pl as DataTextureLoader,hn as DataUtils,us as DecrementStencilOp,cs as DecrementWrapStencilOp,rl as DefaultLoadingManager,ZC as DenoiseNode,He as DepthFormat,zC as DepthOfFieldNode,je as DepthStencilFormat,Qa as DepthTexture,oe as DetachedBindMode,El as DirectionalLight,rd as DirectionalLightHelper,AI as DirectionalLightNode,_y as Discard,ju as DiscreteInterpolant,Qt as DisplayP3ColorSpace,Ch as DodecahedronGeometry,OC as DotScreenNode,p as DoubleSide,B as DstAlphaFactor,P as DstColorFactor,Us as DynamicCopyUsage,Es as DynamicDrawUsage,Ps as DynamicReadUsage,wg as EPSILON,Ph as EdgesGeometry,th as EllipseCurve,mw as EnvironmentNode,ws as EqualCompare,H as EqualDepth,gs as EqualStencilFunc,ET as EquirectUVNode,le as EquirectangularReflectionMapping,ce as EquirectangularRefractionMapping,fr as Euler,Gs as EventDispatcher,vy as ExpressionNode,uu as ExtrudeGeometry,KC as FXAANode,HT as F_Schlick,hl as FileLoader,kC as FilmNode,bn as Float16BufferAttribute,vn as Float32BufferAttribute,Ie as FloatType,Pp as Fn,ro as Fog,io as FogExp2,DR as FogExp2Node,UR as FogNode,LR as FogRangeNode,Xa as FramebufferTexture,yx as FrontFacingNode,c as FrontSide,na as Frustum,Jm as FunctionCallNode,RS as FunctionNode,BM as FunctionOverloadingNode,Cc as GLBufferAttribute,Ls as GLSL1,Vs as GLSL3,WI as GLSLNodeParser,XC as GTAONode,yC as GaussianBlurNode,Ms as GreaterCompare,q as GreaterDepth,As as GreaterEqualCompare,j as GreaterEqualDepth,bs as GreaterEqualStencilFunc,ys as GreaterStencilFunc,Qc as GridHelper,qa as Group,Pe as HalfFloatType,fl as HemisphereLight,Kc as HemisphereLightHelper,zI as HemisphereLightNode,FF as IESSpotLight,PI as IESSpotLightNode,Sg as INFINITY,cu as IcosahedronGeometry,Op as If,Wl as ImageBitmapLoader,cl as ImageLoader,fi as ImageUtils,hs as IncrementStencilOp,ls as IncrementWrapStencilOp,av as IndexNode,mv as InstanceNode,Ho as InstancedBufferAttribute,Ol as InstancedBufferGeometry,Ac as InstancedInterleavedBuffer,Ko as InstancedMesh,bT as InstancedPointsNodeMaterial,gn as Int16BufferAttribute,yn as Int32BufferAttribute,dn as Int8BufferAttribute,Ee as IntType,oo as InterleavedBuffer,ho as InterleavedBufferAttribute,Gu as Interpolant,Pt as InterpolateDiscrete,Ft as InterpolateLinear,zt as InterpolateSmooth,ds as InvertStencilOp,Dv as IrradianceNode,qd as JoinNode,os as KeepStencilOp,qu as KeyframeTrack,Co as LOD,_h as LatheGeometry,yr as Layers,_s as LessCompare,G as LessDepth,Ss as LessEqualCompare,W as LessEqualDepth,fs as LessEqualStencilFunc,ms as LessStencilFunc,gl as Light,Fl as LightProbe,UI as LightProbeNode,Lv as LightingContextNode,DT as LightingModel,Uv as LightingNode,Fv as LightsNode,Pa as Line,MT as Line2NodeMaterial,Dc as Line3,Ma as LineBasicMaterial,TT as LineBasicNodeMaterial,mh as LineCurve,gh as LineCurve3,zu as LineDashedMaterial,wT as LineDashedNodeMaterial,La as LineLoop,Oa as LineSegments,es as LinearDisplayP3ColorSpace,Te as LinearFilter,Hu as LinearInterpolant,Me as LinearMipMapLinearFilter,we as LinearMipMapNearestFilter,Se as LinearMipmapLinearFilter,_e as LinearMipmapNearestFilter,Kt as LinearSRGBColorSpace,K as LinearToneMapping,ts as LinearTransfer,nl as Loader,Ul as LoaderUtils,il as LoadingManager,wv as Loop,_v as LoopNode,Et as LoopOnce,It as LoopPingPong,Bt as LoopRepeat,We as LuminanceAlphaFormat,Ge as LuminanceFormat,WC as Lut3DNode,t as MOUSE,RM as MRTNode,Aw as MatcapUVNode,tn as Material,zl as MaterialLoader,vb as MaterialNode,$x as MaterialReferenceNode,Qs as MathUtils,zc as Matrix2,ti as Matrix3,or as Matrix4,S as MaxEquation,Iy as MaxMipLevelNode,Dn as Mesh,sn as MeshBasicMaterial,WT as MeshBasicNodeMaterial,Iu as MeshDepthMaterial,Pu as MeshDistanceMaterial,Bu as MeshLambertMaterial,ZT as MeshLambertNodeMaterial,Fu as MeshMatcapMaterial,Ew as MeshMatcapNodeMaterial,Eu as MeshNormalMaterial,RT as MeshNormalNodeMaterial,Cu as MeshPhongMaterial,KT as MeshPhongNodeMaterial,Au as MeshPhysicalMaterial,vw as MeshPhysicalNodeMaterial,_w as MeshSSSNodeMaterial,Nu as MeshStandardMaterial,xw as MeshStandardNodeMaterial,Ru as MeshToonMaterial,Nw as MeshToonNodeMaterial,w as MinEquation,ge as MirroredRepeatWrapping,Y as MixOperation,Qy as ModelNode,nv as ModelViewProjectionNode,Ev as MorphNode,x as MultiplyBlending,X as MultiplyOperation,fe as NearestFilter,ve as NearestMipMapLinearFilter,xe as NearestMipMapNearestFilter,be as NearestMipmapLinearFilter,ye as NearestMipmapNearestFilter,re as NeutralToneMapping,Ts as NeverCompare,D as NeverDepth,ps as NeverStencilFunc,m as NoBlending,Zt as NoColorSpace,J as NoToneMapping,Gd as Node,gS as NodeAttribute,_M as NodeBuilder,TS as NodeCache,bS as NodeCode,wM as NodeFrame,SM as NodeFunctionInput,WF as NodeLoader,yT as NodeMaterial,HF as NodeMaterialLoader,_d as NodeMaterialObserver,jF as NodeObjectLoader,Fd as NodeShaderStage,Ud as NodeType,fS as NodeUniform,zd as NodeUpdateType,Pd as NodeUtils,yS as NodeVar,xS as NodeVarying,Vt as NormalAnimationBlendMode,g as NormalBlending,pb as NormalMapNode,Ns as NotEqualCompare,$ as NotEqualDepth,xs as NotEqualStencilFunc,Yu as NumberKeyframeTrack,Pr as Object3D,$y as Object3DNode,Vl as ObjectLoader,Yt as ObjectSpaceNormalMap,du as OctahedronGeometry,N as OneFactor,V as OneMinusConstantAlphaFactor,O as OneMinusConstantColorFactor,I as OneMinusDstAlphaFactor,F as OneMinusDstColorFactor,E as OneMinusSrcAlphaFactor,C as OneMinusSrcColorFactor,Cl as OrthographicCamera,VM as OscNode,NM as OutputStructNode,rs as P3Primaries,h as PCFShadowMap,u as PCFSoftShadowMap,Mg as PI,Ng as PI2,lM as PMREMGenerator,cw as PMREMNode,MR as ParallaxBarrierPassNode,_S as ParameterNode,cC as PassNode,Th as Path,Kn as PerspectiveCamera,XT as PhongLightingModel,k_ as PhysicalLightingModel,cR as PixelationPassNode,sa as Plane,pu as PlaneGeometry,dd as PlaneHelper,Al as PointLight,Xc as PointLightHelper,NI as PointLightNode,wN as PointUVNode,Ha as Points,Va as PointsMaterial,Iw as PointsNodeMaterial,ed as PolarGridHelper,Ah as PolyhedronGeometry,lc as PositionalAudio,VF as PostProcessing,iC as PosterizeNode,bc as PropertyBinding,dc as PropertyMixer,xm as PropertyNode,fN as QuadMesh,fh as QuadraticBezierCurve,yh as QuadraticBezierCurve3,Ri as Quaternion,Ju as QuaternionKeyframeTrack,Zu as QuaternionLinearInterpolant,Ct as RED_GREEN_RGTC2_Format,Nt as RED_RGTC1_Format,e as REVISION,jt as RGBADepthPacking,ke as RGBAFormat,Je as RGBAIntegerFormat,vt as RGBA_ASTC_10x10_Format,yt as RGBA_ASTC_10x5_Format,xt as RGBA_ASTC_10x6_Format,bt as RGBA_ASTC_10x8_Format,Tt as RGBA_ASTC_12x10_Format,_t as RGBA_ASTC_12x12_Format,ut as RGBA_ASTC_4x4_Format,lt as RGBA_ASTC_5x4_Format,ct as RGBA_ASTC_5x5_Format,dt as RGBA_ASTC_6x5_Format,pt as RGBA_ASTC_6x6_Format,mt as RGBA_ASTC_8x5_Format,gt as RGBA_ASTC_8x6_Format,ft as RGBA_ASTC_8x8_Format,wt as RGBA_BPTC_Format,ht as RGBA_ETC2_EAC_Format,nt as RGBA_PVRTC_2BPPV1_Format,rt as RGBA_PVRTC_4BPPV1_Format,Qe as RGBA_S3TC_DXT1_Format,et as RGBA_S3TC_DXT3_Format,tt as RGBA_S3TC_DXT5_Format,qt as RGBDepthPacking,De as RGBFormat,Ze as RGBIntegerFormat,VC as RGBShiftNode,St as RGB_BPTC_SIGNED_Format,Mt as RGB_BPTC_UNSIGNED_Format,ot as RGB_ETC1_Format,at as RGB_ETC2_Format,it as RGB_PVRTC_2BPPV1_Format,st as RGB_PVRTC_4BPPV1_Format,Ke as RGB_S3TC_DXT1_Format,$t as RGDepthPacking,Xe as RGFormat,Ye as RGIntegerFormat,xN as RTTNode,HR as RangeNode,Mu as RawShaderMaterial,nr as Ray,Ec as Raycaster,is as Rec709Primaries,Il as RectAreaLight,BI as RectAreaLightNode,qe as RedFormat,$e as RedIntegerFormat,Hx as ReferenceNode,cN as ReflectorNode,Q as ReinhardToneMapping,yy as RemapNode,Sy as RenderOutputNode,wi as RenderTarget,ty as RendererReferenceNode,pe as RepeatWrapping,as as ReplaceStencilOp,wy as Return,_ as ReverseSubtractEquation,mu as RingGeometry,Pw as RotateNode,Rt as SIGNED_RED_GREEN_RGTC2_Format,At as SIGNED_RED_RGTC1_Format,Jt as SRGBColorSpace,ss as SRGBTransfer,mR as SSAAPassNode,no as Scene,MN as SceneNode,u_ as Schlick_to_F0,Wv as ScreenNode,FR as ScriptableNode,RR as ScriptableValueNode,Yd as SetNode,Hn as ShaderMaterial,Ap as ShaderNode,Su as ShadowMaterial,Vw as ShadowNodeMaterial,Fh as Shape,gu as ShapeGeometry,xd as ShapePath,ou as ShapeUtils,Ce as ShortType,Wo as Skeleton,qc as SkeletonHelper,Lo as SkinnedMesh,bv as SkinningNode,PC as SobelOperatorNode,xi as Source,Ji as Sphere,fu as SphereGeometry,Pc as Spherical,Pl as SphericalHarmonics3,xh as SplineCurve,Xd as SplitNode,_l as SpotLight,Gc as SpotLightHelper,II as SpotLightNode,So as Sprite,uo as SpriteMaterial,Uw as SpriteNodeMaterial,HM as SpriteSheetUVNode,R as SrcAlphaFactor,z as SrcAlphaSaturateFactor,A as SrcColorFactor,XS as StackNode,zs as StaticCopyUsage,Rs as StaticDrawUsage,Is as StaticReadUsage,Zl as StereoCamera,xR as StereoPassNode,qM as StorageArrayElementNode,kF as StorageBufferAttribute,YA as StorageBufferNode,GF as StorageInstancedBufferAttribute,DF as StorageTexture,KA as StorageTextureNode,Os as StreamCopyUsage,Bs as StreamDrawUsage,Fs as StreamReadUsage,Ku as StringKeyframeTrack,T as SubtractEquation,y as SubtractiveBlending,hb as TBNViewMatrix,s as TOUCH,Xt as TangentSpaceNormalMap,jd as TempNode,yu as TetrahedronGeometry,Ti as Texture,kw as Texture3DNode,ml as TextureLoader,Fy as TextureNode,Ey as TextureSizeNode,FM as TimerNode,iy as ToneMappingNode,AR as ToonOutlinePassNode,xu as TorusGeometry,bu as TorusKnotGeometry,hR as TransitionNode,$r as Triangle,Wt as TriangleFanDrawMode,Gt as TriangleStripDrawMode,kt as TrianglesDrawMode,XM as TriplanarTexturesNode,vu as TubeGeometry,ae as UVMapping,fn as Uint16BufferAttribute,xn as Uint32BufferAttribute,pn as Uint8BufferAttribute,mn as Uint8ClampedBufferAttribute,Sc as Uniform,Dx as UniformArrayNode,lm as UniformGroupNode,fm as UniformNode,Nc as UniformsGroup,Ne as UnsignedByteType,Le as UnsignedInt101111Type,Ue as UnsignedInt248Type,Oe as UnsignedInt5999Type,Be as UnsignedIntType,Fe as UnsignedShort4444Type,ze as UnsignedShort5551Type,Re as UnsignedShortType,tC as UserDataNode,l as VSMShadowMap,t_ as V_GGX_SmithCorrelated,Df as VarNode,Gf as VaryingNode,ei as Vector2,Ei as Vector3,_i as Vector4,Qu as VectorKeyframeTrack,TN as VertexColorNode,$a as VideoTexture,aT as ViewportDepthNode,nT as ViewportDepthTextureNode,oC as ViewportSharedTextureNode,tT as ViewportTextureNode,Ww as VolumeNodeMaterial,Ci as WebGL3DRenderTarget,Ni as WebGLArrayRenderTarget,Ds as WebGLCoordinateSystem,so as WebGLCubeRenderTarget,vd as WebGLMultipleRenderTargets,Si as WebGLRenderTarget,ks as WebGPUCoordinateSystem,UF as WebGPURenderer,Tu as WireframeGeometry,Lt as WrapAroundEnding,Ut as ZeroCurvatureEnding,M as ZeroFactor,Ot as ZeroSlopeEnding,ns as ZeroStencilOp,Xg as abs,VE as acesFilmicToneMapping,qg as acos,eg as add,tp as addMethodChaining,Ny as addNodeElement,_C as afterImage,WE as agxToneMapping,Ag as all,Im as alphaT,SR as anaglyphPass,IC as anamorphic,cg as and,Pm as anisotropy,zm as anisotropyB,Fm as anisotropyT,Cg as any,YC as ao,Lp as append,om as arrayBuffer,jg as asin,Zm as assign,$g as atan,hf as atan2,hB as atomicAdd,dB as atomicAnd,oB as atomicFunc,lB as atomicMax,cB as atomicMin,pB as atomicOr,aB as atomicStore,uB as atomicSub,mB as atomicXor,$m as attenuationColor,qm as attenuationDistance,Cy as attribute,NN as backgroundBlurriness,AN as backgroundIntensity,yv as batch,bE as billboarding,gg as bitAnd,fg as bitNot,yg as bitOr,xg as bitXor,sb as bitangentGeometry,ib as bitangentLocal,rb as bitangentView,nb as bitangentWorld,of as bitcast,BE as bleach,aR as bloom,aw as blur,Wp as bool,Lx as buffer,ay as bufferAttribute,xb as bumpMap,NE as burn,$p as bvec2,Jp as bvec3,tm as bvec4,fy as bypass,my as cache,Km as call,Vy as cameraFar,Dy as cameraLogDepth,Ly as cameraNear,jy as cameraNormalMatrix,qy as cameraPosition,ky as cameraProjectionMatrix,Gy as cameraProjectionMatrixInverse,Wy as cameraViewMatrix,Hy as cameraWorldMatrix,wf as cbrt,Vg as ceil,gB as checker,OE as cineonToneMapping,Nf as clamp,Mm as clearcoat,Nm as clearcoatRoughness,MS as code,Vp as color,Kf as colorSpaceToWorking,AT as colorToDirection,dy as compute,Uf as cond,Lf as context,hm as convert,vN as convertToTexture,Wg as cos,oi as createCanvasElement,yf as cross,Ux as cubeTexture,Qg as dFdx,ef as dFdy,Dm as dashSize,Ld as defaultBuildStages,Od as defaultShaderStages,Mp as defined,Bg as degrees,JC as denoise,kR as densityFog,pT as depth,mC as depthPass,gf as difference,Tm as diffuseColor,NT as directionToColor,Xm as dispersion,mf as distance,ig as div,AE as dodge,UC as dof,ff as dot,LC as dotScreen,pv as drawIndex,hy as dynamicBufferAttribute,am as element,_m as emissive,ng as equal,Rg as equals,BT as equirectUV,Ig as exp,Pg as exp2,Ty as expression,bx as faceDirection,Ef as faceForward,GC as film,Dp as float,Lg as floor,OR as fog,kg as fract,pm as frameGroup,LM as frameId,xx as frontFacing,nf as fwidth,QC as fxaa,cE as gain,km as gapSize,xC as gaussianBlur,$f as getColorSpaceMethod,Np as getConstNodeType,Up as getCurrentStack,iw as getDirection,sE as getDistanceAttenuation,QT as getGeometryRoughness,e_ as getRoughness,MI as getShIrradianceAt,CM as getTextureIndex,PR as global,CS as glsl,BS as glslFn,wC as grayscale,hg as greaterThan,lg as greaterThanEqual,uE as hash,ux as highPrecisionModelNormalViewMatrix,hx as highPrecisionModelViewMatrix,NC as hue,gv as instance,uv as instanceIndex,uy as instancedBufferAttribute,ly as instancedDynamicBufferAttribute,kp as int,Og as inverseSqrt,dv as invocationLocalIndex,cv as invocationSubgroupIndex,Wm as ior,Rm as iridescence,Em as iridescenceIOR,Bm as iridescenceThickness,jp as ivec2,Yp as ivec3,Qp as ivec4,NS as js,Vf as label,Zg as length,Sf as lengthSq,ag as lessThan,ug as lessThanEqual,nE as lightPosition,hE as lightTargetDirection,oE as lightTargetPosition,aE as lightViewPosition,Vv as lightingContext,zv as lights,mT as linearDepth,FE as linearSRGBTosRGB,zE as linearToneMapping,YE as localId,Fg as log,zg as log2,Nv as loop,CC as luminance,HC as lut3D,sm as mat2,im as mat3,rm as mat4,Cw as matcapUV,iv as materialAOMap,Tb as materialAlphaTest,Db as materialAnisotropy,rv as materialAnisotropyVector,Xb as materialAttenuationColor,$b as materialAttenuationDistance,Fb as materialClearcoat,Ub as materialClearcoatNormal,zb as materialClearcoatRoughness,_b as materialColor,tv as materialDispersion,Sb as materialEmissive,qb as materialIOR,kb as materialIridescence,Gb as materialIridescenceIOR,Wb as materialIridescenceThickness,sv as materialLightMap,Qb as materialLineDashOffset,Zb as materialLineDashSize,Jb as materialLineGapSize,Yb as materialLineScale,Kb as materialLineWidth,Ib as materialMetalness,Pb as materialNormal,Mb as materialOpacity,ev as materialPointWidth,Xx as materialReference,Eb as materialReflectivity,Ex as materialRefractionRatio,Ob as materialRotation,Bb as materialRoughness,Lb as materialSheen,Vb as materialSheenRoughness,wb as materialShininess,Nb as materialSpecular,Cb as materialSpecularColor,Ab as materialSpecularIntensity,Rb as materialSpecularStrength,jb as materialThickness,Hb as materialTransmission,lf as max,Py as maxMipLevel,Sm as metalness,uf as min,Mf as mix,If as mixElement,cf as mod,rg as modInt,ex as modelDirection,nx as modelNormalMatrix,sx as modelPosition,ix as modelScale,ax as modelViewMatrix,rx as modelViewPosition,ov as modelViewProjection,tx as modelWorldMatrix,ox as modelWorldMatrixInverse,Bv as morphReference,EE as motionBlur,EM as mrt,sg as mul,rI as mx_aastep,vI as mx_cell_noise_float,pI as mx_contrast,TI as mx_fractal_noise_float,_I as mx_fractal_noise_vec2,wI as mx_fractal_noise_vec3,SI as mx_fractal_noise_vec4,tI as mx_hsvtorgb,mI as mx_noise_float,gI as mx_noise_vec3,fI as mx_noise_vec4,oI as mx_ramplr,aI as mx_ramptb,sI as mx_rgbtohsv,dI as mx_safepower,uI as mx_splitlr,lI as mx_splittb,iI as mx_srgb_texture_to_lin_rec709,cI as mx_transform_uv,yI as mx_worley_noise_float,xI as mx_worley_noise_vec2,bI as mx_worley_noise_vec3,Jg as negate,HE as neutralToneMapping,Ep as nodeArray,Ip as nodeImmutable,Cp as nodeObject,Rp as nodeObjects,Bp as nodeProxy,_x as normalFlat,vx as normalGeometry,Tx as normalLocal,mb as normalMap,wx as normalView,Sx as normalWorld,Dg as normalize,pg as not,og as notEqual,$E as numWorkgroups,Xy as objectDirection,gm as objectGroup,Zy as objectPosition,Jy as objectScale,Ky as objectViewPosition,Yy as objectWorldMatrix,Kg as oneMinus,dg as or,uT as orthographicDepthToViewZ,WM as oscSawtooth,DM as oscSine,kM as oscSquare,GM as oscTriangle,Vm as output,AM as outputStruct,RE as overlay,PM as overloadingFn,lE as parabola,NR as parallaxBarrierPass,ub as parallaxDirection,lb as parallaxUV,wS as parameter,dC as pass,pC as passTexture,dE as pcurve,cT as perspectiveDepthToViewZ,dR as pixelationPass,dw as pmremTexture,SN as pointUV,Gm as pointWidth,lx as positionGeometry,cx as positionLocal,dx as positionPrevious,gx as positionView,fx as positionViewDirection,px as positionWorld,mx as positionWorldDirection,rC as posterize,xf as pow,bf as pow2,vf as pow3,Tf as pow4,bm as property,Eg as radians,Bf as rand,jR as range,VR as rangeFog,sf as reciprocal,jx as reference,qx as referenceBuffer,pf as reflect,Px as reflectVector,Bx as reflectView,dN as reflector,Cf as refract,Fx as refractVector,Ix as refractView,UE as reinhardToneMapping,Tg as remainder,xy as remap,by as remapClamp,mm as renderGroup,My as renderOutput,sy as rendererReference,DC as rgbShift,Fw as rotate,yE as rotateUV,wm as roughness,tf as round,bN as rtt,PE as sRGBToLinearSRGB,Oy as sampler,Af as saturate,SC as saturation,CE as screen,qv as screenCoordinate,jv as screenSize,Hv as screenUV,zR as scriptable,ER as scriptableValue,zf as select,IE as sepia,zp as setCurrentStack,Vd as shaderStages,dm as sharedUniformGroup,Am as sheen,Cm as sheenRoughness,bg as shiftLeft,vg as shiftRight,Lm as shininess,Yg as sign,Gg as sin,pE as sinc,vv as skinning,Tv as skinningReference,Rf as smoothstep,Pf as smoothstepElement,FC as sobel,Um as specularColor,Om as specularF90,xE as spherizeUV,um as split,jM as spritesheetUV,Ug as sqrt,fR as ssaaPass,YS as stack,df as step,bR as stereoPass,ZA as storage,QE as storageBarrier,JA as storageObject,QA as storageTexture,nm as string,tg as sub,lv as subgroupIndex,ZE as subgroupSize,Hg as tan,Yx as tangentGeometry,Zx as tangentLocal,Jx as tangentView,Kx as tangentWorld,kf as temp,zy as texture,Gw as texture3D,eB as textureBarrier,A_ as textureBicubic,rw as textureCubeUV,Uy as textureLoad,By as textureSize,eC as textureStore,jm as thickness,RC as threshold,OM as timerDelta,UM as timerGlobal,zM as timerLocal,Yf as toOutputColorSpace,Zf as toWorkingColorSpace,ry as toneMapping,ny as toneMappingExposure,CR as toonOutlinePass,_f as transformDirection,Cx as transformNormal,Rx as transformNormalToView,cb as transformedBentNormalView,ob as transformedBitangentView,ab as transformedBitangentWorld,Ax as transformedClearcoatNormalView,Mx as transformedNormalView,Nx as transformedNormalWorld,Qx as transformedTangentView,eb as transformedTangentWorld,uR as transition,Hm as transmission,af as transpose,mE as tri,gE as tri3,fE as triNoise3D,ZM as triplanarTexture,YM as triplanarTextures,rf as trunc,Fp as tslFn,Gp as uint,ym as uniform,kx as uniformArray,cm as uniformGroup,Gx as uniforms,sC as userData,Ry as uv,qp as uvec2,Zp as uvec3,em as uvec4,Wf as varying,vm as varyingProperty,Hp as vec2,Xp as vec3,Kp as vec4,Dd as vectorComponents,ME as velocity,_N as vertexColor,hv as vertexIndex,MC as vibrance,hT as viewZToOrthographicDepth,lT as viewZToPerspectiveDepth,$v as viewport,Qv as viewportBottomLeft,Yv as viewportCoordinate,oT as viewportDepthTexture,gT as viewportLinearDepth,iT as viewportMipTexture,Jv as viewportResolution,vE as viewportSafeUV,aC as viewportSharedTexture,Xv as viewportSize,sT as viewportTexture,Kv as viewportTopLeft,Zv as viewportUV,AS as wgsl,IS as wgslFn,iB as workgroupArray,KE as workgroupBarrier,XE as workgroupId,Jf as workingToColorSpace,mg as xor};
|
|
6
|
+
import{Color as e,Vector2 as t,Vector3 as r,Vector4 as s,Matrix2 as i,Matrix3 as n,Matrix4 as a,error as o,EventDispatcher as u,MathUtils as l,warn as d,WebGLCoordinateSystem as c,WebGPUCoordinateSystem as h,ColorManagement as p,SRGBTransfer as g,NoToneMapping as m,StaticDrawUsage as f,InterleavedBufferAttribute as y,InterleavedBuffer as b,DynamicDrawUsage as x,NoColorSpace as T,log as _,warnOnce as v,Texture as N,UnsignedIntType as S,IntType as R,Compatibility as E,LessCompare as A,LessEqualCompare as w,GreaterCompare as C,GreaterEqualCompare as M,NearestFilter as B,Sphere as F,BackSide as L,DoubleSide as P,Euler as D,CubeTexture as U,CubeReflectionMapping as I,CubeRefractionMapping as O,TangentSpaceNormalMap as V,NoNormalPacking as k,NormalRGPacking as G,NormalGAPacking as $,ObjectSpaceNormalMap as z,RGFormat as W,RED_GREEN_RGTC2_Format as H,RG11_EAC_Format as q,InstancedBufferAttribute as j,InstancedInterleavedBuffer as X,DataArrayTexture as K,FloatType as Y,FramebufferTexture as Q,LinearMipmapLinearFilter as Z,DepthTexture as J,Material as ee,LineBasicMaterial as te,LineDashedMaterial as re,NoBlending as se,MeshNormalMaterial as ie,SRGBColorSpace as ne,RenderTarget as ae,BoxGeometry as oe,Mesh as ue,Scene as le,LinearFilter as de,CubeCamera as ce,EquirectangularReflectionMapping as he,EquirectangularRefractionMapping as pe,AddOperation as ge,MixOperation as me,MultiplyOperation as fe,MeshBasicMaterial as ye,MeshLambertMaterial as be,MeshPhongMaterial as xe,DataTexture as Te,HalfFloatType as _e,ClampToEdgeWrapping as ve,BufferGeometry as Ne,OrthographicCamera as Se,PerspectiveCamera as Re,LinearSRGBColorSpace as Ee,RGBAFormat as Ae,CubeUVReflectionMapping as we,BufferAttribute as Ce,MeshStandardMaterial as Me,MeshPhysicalMaterial as Be,MeshToonMaterial as Fe,MeshMatcapMaterial as Le,SpriteMaterial as Pe,PointsMaterial as De,ShadowMaterial as Ue,Uint32BufferAttribute as Ie,Uint16BufferAttribute as Oe,DepthStencilFormat as Ve,DepthFormat as ke,UnsignedInt248Type as Ge,UnsignedByteType as $e,NormalBlending as ze,SrcAlphaFactor as We,OneMinusSrcAlphaFactor as He,AddEquation as qe,MaterialBlending as je,Plane as Xe,Object3D as Ke,LinearMipMapLinearFilter as Ye,Float32BufferAttribute as Qe,UVMapping as Ze,VSMShadowMap as Je,PCFShadowMap as et,PCFSoftShadowMap as tt,BasicShadowMap as rt,CubeDepthTexture as st,SphereGeometry as it,LinearMipmapNearestFilter as nt,NearestMipmapLinearFilter as at,Float16BufferAttribute as ot,REVISION as ut,ArrayCamera as lt,PlaneGeometry as dt,FrontSide as ct,CustomBlending as ht,ZeroFactor as pt,CylinderGeometry as gt,Quaternion as mt,WebXRController as ft,RAD2DEG as yt,FrustumArray as bt,Frustum as xt,RedIntegerFormat as Tt,RedFormat as _t,ShortType as vt,ByteType as Nt,UnsignedShortType as St,RGIntegerFormat as Rt,RGBIntegerFormat as Et,RGBFormat as At,RGBAIntegerFormat as wt,TimestampQuery as Ct,createCanvasElement as Mt,ReverseSubtractEquation as Bt,SubtractEquation as Ft,OneMinusDstAlphaFactor as Lt,OneMinusDstColorFactor as Pt,OneMinusSrcColorFactor as Dt,DstAlphaFactor as Ut,DstColorFactor as It,SrcAlphaSaturateFactor as Ot,SrcColorFactor as Vt,OneFactor as kt,CullFaceNone as Gt,CullFaceBack as $t,CullFaceFront as zt,MultiplyBlending as Wt,SubtractiveBlending as Ht,AdditiveBlending as qt,NotEqualDepth as jt,GreaterDepth as Xt,GreaterEqualDepth as Kt,EqualDepth as Yt,LessEqualDepth as Qt,LessDepth as Zt,AlwaysDepth as Jt,NeverDepth as er,ReversedDepthFuncs as tr,UnsignedShort4444Type as rr,UnsignedShort5551Type as sr,UnsignedInt5999Type as ir,UnsignedInt101111Type as nr,AlphaFormat as ar,RGB_S3TC_DXT1_Format as or,RGBA_S3TC_DXT1_Format as ur,RGBA_S3TC_DXT3_Format as lr,RGBA_S3TC_DXT5_Format as dr,RGB_PVRTC_4BPPV1_Format as cr,RGB_PVRTC_2BPPV1_Format as hr,RGBA_PVRTC_4BPPV1_Format as pr,RGBA_PVRTC_2BPPV1_Format as gr,RGB_ETC1_Format as mr,RGB_ETC2_Format as fr,RGBA_ETC2_EAC_Format as yr,R11_EAC_Format as br,SIGNED_R11_EAC_Format as xr,SIGNED_RG11_EAC_Format as Tr,RGBA_ASTC_4x4_Format as _r,RGBA_ASTC_5x4_Format as vr,RGBA_ASTC_5x5_Format as Nr,RGBA_ASTC_6x5_Format as Sr,RGBA_ASTC_6x6_Format as Rr,RGBA_ASTC_8x5_Format as Er,RGBA_ASTC_8x6_Format as Ar,RGBA_ASTC_8x8_Format as wr,RGBA_ASTC_10x5_Format as Cr,RGBA_ASTC_10x6_Format as Mr,RGBA_ASTC_10x8_Format as Br,RGBA_ASTC_10x10_Format as Fr,RGBA_ASTC_12x10_Format as Lr,RGBA_ASTC_12x12_Format as Pr,RGBA_BPTC_Format as Dr,RED_RGTC1_Format as Ur,SIGNED_RED_RGTC1_Format as Ir,SIGNED_RED_GREEN_RGTC2_Format as Or,MirroredRepeatWrapping as Vr,RepeatWrapping as kr,NearestMipmapNearestFilter as Gr,NotEqualCompare as $r,EqualCompare as zr,AlwaysCompare as Wr,NeverCompare as Hr,LinearTransfer as qr,getByteLength as jr,isTypedArray as Xr,NotEqualStencilFunc as Kr,GreaterStencilFunc as Yr,GreaterEqualStencilFunc as Qr,EqualStencilFunc as Zr,LessEqualStencilFunc as Jr,LessStencilFunc as es,AlwaysStencilFunc as ts,NeverStencilFunc as rs,DecrementWrapStencilOp as ss,IncrementWrapStencilOp as is,DecrementStencilOp as ns,IncrementStencilOp as as,InvertStencilOp as os,ReplaceStencilOp as us,ZeroStencilOp as ls,KeepStencilOp as ds,MaxEquation as cs,MinEquation as hs,SpotLight as ps,PointLight as gs,DirectionalLight as ms,RectAreaLight as fs,AmbientLight as ys,HemisphereLight as bs,LightProbe as xs,LinearToneMapping as Ts,ReinhardToneMapping as _s,CineonToneMapping as vs,ACESFilmicToneMapping as Ns,AgXToneMapping as Ss,NeutralToneMapping as Rs,Group as Es,Loader as As,FileLoader as ws,MaterialLoader as Cs,ObjectLoader as Ms}from"./three.core.min.js";export{AdditiveAnimationBlendMode,AnimationAction,AnimationClip,AnimationLoader,AnimationMixer,AnimationObjectGroup,AnimationUtils,ArcCurve,ArrowHelper,AttachedBindMode,Audio,AudioAnalyser,AudioContext,AudioListener,AudioLoader,AxesHelper,BasicDepthPacking,BatchedMesh,BezierInterpolant,Bone,BooleanKeyframeTrack,Box2,Box3,Box3Helper,BoxHelper,BufferGeometryLoader,Cache,Camera,CameraHelper,CanvasTexture,CapsuleGeometry,CatmullRomCurve3,CircleGeometry,Clock,ColorKeyframeTrack,CompressedArrayTexture,CompressedCubeTexture,CompressedTexture,CompressedTextureLoader,ConeGeometry,ConstantAlphaFactor,ConstantColorFactor,Controls,CubeTextureLoader,CubicBezierCurve,CubicBezierCurve3,CubicInterpolant,CullFaceFrontBack,Curve,CurvePath,CustomToneMapping,Cylindrical,Data3DTexture,DataTextureLoader,DataUtils,DefaultLoadingManager,DetachedBindMode,DirectionalLightHelper,DiscreteInterpolant,DodecahedronGeometry,DynamicCopyUsage,DynamicReadUsage,EdgesGeometry,EllipseCurve,ExternalTexture,ExtrudeGeometry,Fog,FogExp2,GLBufferAttribute,GLSL1,GLSL3,GridHelper,HemisphereLightHelper,IcosahedronGeometry,ImageBitmapLoader,ImageLoader,ImageUtils,InstancedBufferGeometry,InstancedMesh,Int16BufferAttribute,Int32BufferAttribute,Int8BufferAttribute,Interpolant,InterpolateBezier,InterpolateDiscrete,InterpolateLinear,InterpolateSmooth,InterpolationSamplingMode,InterpolationSamplingType,KeyframeTrack,LOD,LatheGeometry,Layers,Light,Line,Line3,LineCurve,LineCurve3,LineLoop,LineSegments,LinearInterpolant,LinearMipMapNearestFilter,LoaderUtils,LoadingManager,LoopOnce,LoopPingPong,LoopRepeat,MOUSE,MeshDepthMaterial,MeshDistanceMaterial,NearestMipMapLinearFilter,NearestMipMapNearestFilter,NormalAnimationBlendMode,NumberKeyframeTrack,OctahedronGeometry,OneMinusConstantAlphaFactor,OneMinusConstantColorFactor,Path,PlaneHelper,PointLightHelper,Points,PolarGridHelper,PolyhedronGeometry,PositionalAudio,PropertyBinding,PropertyMixer,QuadraticBezierCurve,QuadraticBezierCurve3,QuaternionKeyframeTrack,QuaternionLinearInterpolant,RGBADepthPacking,RGBDepthPacking,RGB_BPTC_SIGNED_Format,RGB_BPTC_UNSIGNED_Format,RGDepthPacking,RawShaderMaterial,Ray,Raycaster,RenderTarget3D,RingGeometry,ShaderMaterial,Shape,ShapeGeometry,ShapePath,ShapeUtils,Skeleton,SkeletonHelper,SkinnedMesh,Source,Spherical,SphericalHarmonics3,SplineCurve,SpotLightHelper,Sprite,StaticCopyUsage,StaticReadUsage,StereoCamera,StreamCopyUsage,StreamDrawUsage,StreamReadUsage,StringKeyframeTrack,TOUCH,TetrahedronGeometry,TextureLoader,TextureUtils,Timer,TorusGeometry,TorusKnotGeometry,Triangle,TriangleFanDrawMode,TriangleStripDrawMode,TrianglesDrawMode,TubeGeometry,Uint8BufferAttribute,Uint8ClampedBufferAttribute,Uniform,UniformsGroup,VectorKeyframeTrack,VideoFrameTexture,VideoTexture,WebGL3DRenderTarget,WebGLArrayRenderTarget,WebGLRenderTarget,WireframeGeometry,WrapAroundEnding,ZeroCurvatureEnding,ZeroSlopeEnding,getConsoleFunction,setConsoleFunction}from"./three.core.min.js";const Bs=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","aoMapIntensity","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveIntensity","emissiveMap","envMap","envMapIntensity","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","lightMapIntensity","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"],Fs=new WeakMap;class Ls{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=Bs,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}needsVelocity(e){const t=e.getMRT();return null!==t&&t.has("velocity")}getRenderObjectData(e){let t=this.renderObjects.get(e);if(void 0===t){const{geometry:r,material:s,object:i}=e;if(t={material:this.getMaterialData(s),geometry:{id:r.id,attributes:this.getAttributesData(r.attributes),indexId:r.index?r.index.id:null,indexVersion:r.index?r.index.version:null,drawRange:{start:r.drawRange.start,count:r.drawRange.count}},worldMatrix:i.matrixWorld.clone()},i.center&&(t.center=i.center.clone()),i.morphTargetInfluences&&(t.morphTargetInfluences=i.morphTargetInfluences.slice()),null!==e.bundle&&(t.version=e.bundle.version),t.material.transmission>0){const{width:r,height:s}=e.context;t.bufferWidth=r,t.bufferHeight=s}t.lights=this.getLightsData(e.lightsNode.getLights()),this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const r in e){const s=e[r];t[r]={id:s.id,version:s.version}}return t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return!!(e.context.modelViewMatrix||e.context.modelNormalViewMatrix||e.context.getAO||e.context.getShadow)}getMaterialData(e){const t={};for(const r of this.refreshUniforms){const s=e[r];null!=s&&("object"==typeof s&&void 0!==s.clone?!0===s.isTexture?t[r]={id:s.id,version:s.version}:t[r]=s.clone():t[r]=s)}return t}equals(e,t){const{object:r,material:s,geometry:i}=e,n=this.getRenderObjectData(e);if(!0!==n.worldMatrix.equals(r.matrixWorld))return n.worldMatrix.copy(r.matrixWorld),!1;const a=n.material;for(const e in a){const t=a[e],r=s[e];if(void 0!==t.equals){if(!1===t.equals(r))return t.copy(r),!1}else if(!0===r.isTexture){if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}else if(t!==r)return a[e]=r,!1}if(a.transmission>0){const{width:t,height:r}=e.context;if(n.bufferWidth!==t||n.bufferHeight!==r)return n.bufferWidth=t,n.bufferHeight=r,!1}const o=n.geometry,u=i.attributes,l=o.attributes,d=Object.keys(l),c=Object.keys(u);if(o.id!==i.id)return o.id=i.id,!1;if(d.length!==c.length)return n.geometry.attributes=this.getAttributesData(u),!1;for(const e of d){const t=l[e],r=u[e];if(void 0===r)return delete l[e],!1;if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}const h=i.index,p=o.indexId,g=o.indexVersion,m=h?h.id:null,f=h?h.version:null;if(p!==m||g!==f)return o.indexId=m,o.indexVersion=f,!1;if(o.drawRange.start!==i.drawRange.start||o.drawRange.count!==i.drawRange.count)return o.drawRange.start=i.drawRange.start,o.drawRange.count=i.drawRange.count,!1;if(n.morphTargetInfluences){let e=!1;for(let t=0;t<n.morphTargetInfluences.length;t++)n.morphTargetInfluences[t]!==r.morphTargetInfluences[t]&&(n.morphTargetInfluences[t]=r.morphTargetInfluences[t],e=!0);if(e)return!1}if(n.lights)for(let e=0;e<t.length;e++)if(n.lights[e].map!==t[e].map)return!1;return n.center&&!1===n.center.equals(r.center)?(n.center.copy(r.center),!0):(null!==e.bundle&&(n.version=e.bundle.version),!0)}getLightsData(e){const t=[];for(const r of e)!0===r.isSpotLight&&null!==r.map&&t.push({map:r.map.version});return t}getLights(e,t){if(Fs.has(e)){const r=Fs.get(e);if(r.renderId===t)return r.lightsData}const r=this.getLightsData(e.getLights());return Fs.set(e,{renderId:t,lightsData:r}),r}needsRefresh(e,t){if(this.hasNode||this.hasAnimation||this.firstInitialization(e)||this.needsVelocity(t.renderer))return!0;const{renderId:r}=t;if(this.renderId!==r)return this.renderId=r,!0;const s=!0===e.object.static,i=null!==e.bundle&&!0===e.bundle.static&&this.getRenderObjectData(e).version===e.bundle.version;if(s||i)return!1;const n=this.getLights(e.lightsNode,r);return!0!==this.equals(e,n)}}const Ps=[/^StackTrace\.js$/,/^TSLCore\.js$/,/^.*Node\.js$/,/^three\.webgpu.*\.js$/];class Ds{constructor(e=null){this.isStackTrace=!0,this.stack=function(e){const t=/(?:at\s+(.+?)\s+\()?(?:(.+?)@)?([^@\s()]+):(\d+):(\d+)/;return e.split("\n").map(e=>{const r=e.match(t);if(!r)return null;const s=r[1]||r[2]||"",i=r[3].split("?")[0],n=parseInt(r[4],10),a=parseInt(r[5],10);return{fn:s,file:i.split("/").pop(),line:n,column:a}}).filter(e=>e&&!Ps.some(t=>t.test(e.file)))}(e||(new Error).stack)}getLocation(){if(0===this.stack.length)return"[Unknown location]";const e=this.stack[0],t=e.fn;return`${t?`"${t}()" at `:""}"${e.file}:${e.line}"`}getError(e){if(0===this.stack.length)return e;return`${e}\n${this.stack.map(e=>{const t=`${e.file}:${e.line}:${e.column}`;return e.fn?` at ${e.fn} (${t})`:` at ${t}`}).join("\n")}`}}function Us(e,t=0){let r=3735928559^t,s=1103547991^t;if(e instanceof Array)for(let t,i=0;i<e.length;i++)t=e[i],r=Math.imul(r^t,2654435761),s=Math.imul(s^t,1597334677);else for(let t,i=0;i<e.length;i++)t=e.charCodeAt(i),r=Math.imul(r^t,2654435761),s=Math.imul(s^t,1597334677);return r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),4294967296*(2097151&s)+(r>>>0)}const Is=e=>Us(e),Os=e=>Us(e),Vs=(...e)=>Us(e),ks=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),Gs=new WeakMap;function $s(e){return ks.get(e)}function zs(e){if(/[iu]?vec\d/.test(e))return e.startsWith("ivec")?Int32Array:e.startsWith("uvec")?Uint32Array:Float32Array;if(/mat\d/.test(e))return Float32Array;if(/float/.test(e))return Float32Array;if(/uint/.test(e))return Uint32Array;if(/int/.test(e))return Int32Array;throw new Error(`THREE.NodeUtils: Unsupported type: ${e}`)}function Ws(e){return/float|int|uint/.test(e)?1:/vec2/.test(e)?2:/vec3/.test(e)?3:/vec4/.test(e)||/mat2/.test(e)?4:/mat3/.test(e)?9:/mat4/.test(e)?16:void o(`TSL: Unsupported type: ${e}`,new Ds)}function Hs(e){return/float|int|uint/.test(e)?1:/vec2/.test(e)?2:/vec3/.test(e)?3:/vec4/.test(e)||/mat2/.test(e)?4:/mat3/.test(e)?12:/mat4/.test(e)?16:void o(`TSL: Unsupported type: ${e}`,new Ds)}function qs(e){return/float|int|uint/.test(e)?4:/vec2/.test(e)?8:/vec3/.test(e)||/vec4/.test(e)?16:/mat2/.test(e)?8:/mat3/.test(e)||/mat4/.test(e)?16:void o(`TSL: Unsupported type: ${e}`,new Ds)}function js(e){if(null==e)return null;const t=typeof e;return!0===e.isNode?"node":"number"===t?"float":"boolean"===t?"bool":"string"===t?"string":"function"===t?"shader":!0===e.isVector2?"vec2":!0===e.isVector3?"vec3":!0===e.isVector4?"vec4":!0===e.isMatrix2?"mat2":!0===e.isMatrix3?"mat3":!0===e.isMatrix4?"mat4":!0===e.isColor?"color":e instanceof ArrayBuffer?"ArrayBuffer":null}function Xs(o,...u){const l=o?o.slice(-4):void 0;return 1===u.length&&("vec2"===l?u=[u[0],u[0]]:"vec3"===l?u=[u[0],u[0],u[0]]:"vec4"===l&&(u=[u[0],u[0],u[0],u[0]])),"color"===o?new e(...u):"vec2"===l?new t(...u):"vec3"===l?new r(...u):"vec4"===l?new s(...u):"mat2"===l?new i(...u):"mat3"===l?new n(...u):"mat4"===l?new a(...u):"bool"===o?u[0]||!1:"float"===o||"int"===o||"uint"===o?u[0]||0:"string"===o?u[0]||"":"ArrayBuffer"===o?Qs(u[0]):null}function Ks(e){let t=Gs.get(e);return void 0===t&&(t={},Gs.set(e,t)),t}function Ys(e){let t="";const r=new Uint8Array(e);for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return btoa(t)}function Qs(e){return Uint8Array.from(atob(e),e=>e.charCodeAt(0)).buffer}var Zs=Object.freeze({__proto__:null,arrayBufferToBase64:Ys,base64ToArrayBuffer:Qs,getAlignmentFromType:qs,getDataFromObject:Ks,getLengthFromType:Ws,getMemoryLengthFromType:Hs,getTypeFromLength:$s,getTypedArrayFromType:zs,getValueFromType:Xs,getValueType:js,hash:Vs,hashArray:Os,hashString:Is});const Js={VERTEX:"vertex",FRAGMENT:"fragment"},ei={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},ti={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},ri={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},si=["fragment","vertex"],ii=["setup","analyze","generate"],ni=[...si,"compute"],ai=["x","y","z","w"],oi={analyze:"setup",generate:"analyze"};let ui=0;class li extends u{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=ei.NONE,this.updateBeforeType=ei.NONE,this.updateAfterType=ei.NONE,this.uuid=l.generateUUID(),this.version=0,this.name="",this.global=!1,this.parents=!1,this.isNode=!0,this._beforeNodes=null,this._cacheKey=null,this._cacheKeyVersion=0,Object.defineProperty(this,"id",{value:ui++}),this.stackTrace=null,!0===li.captureStackTrace&&(this.stackTrace=new Ds)}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this),this}onFrameUpdate(e){return this.onUpdate(e,ei.FRAME)}onRenderUpdate(e){return this.onUpdate(e,ei.RENDER)}onObjectUpdate(e){return this.onUpdate(e,ei.OBJECT)}onReference(e){return this.updateReference=e.bind(this),this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of this._getChildren())yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}_getChildren(e=new Set){const t=[];e.add(this);for(const r of Object.getOwnPropertyNames(this)){const s=this[r];if(!0!==r.startsWith("_")&&!e.has(s))if(!0===Array.isArray(s))for(let e=0;e<s.length;e++){const i=s[e];i&&!0===i.isNode&&t.push({property:r,index:e,childNode:i})}else if(s&&!0===s.isNode)t.push({property:r,childNode:s});else if(s&&Object.getPrototypeOf(s)===Object.prototype)for(const e in s){if(!0===e.startsWith("_"))continue;const i=s[e];i&&!0===i.isNode&&t.push({property:r,index:e,childNode:i})}}return t}getCacheKey(e=!1,t=null){if(!0===(e=e||this.version!==this._cacheKeyVersion)||null===this._cacheKey){null===t&&(t=new Set);const r=[];for(const{property:s,childNode:i}of this._getChildren(t))r.push(Is(s.slice(0,-4)),i.getCacheKey(e,t));this._cacheKey=Vs(Os(r),this.customCacheKey()),this._cacheKeyVersion=this.version}return this._cacheKey}customCacheKey(){return this.id}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getMemberType(){return"void"}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}getArrayCount(){return null}setup(e){const t=e.getNodeProperties(this);let r=0;for(const e of this.getChildren())t["node"+r++]=e;return t.outputNode||null}analyze(e,t=null){const r=e.increaseUsage(this);if(!0===this.parents){const r=e.getDataFromNode(this,"any");r.stages=r.stages||{},r.stages[e.shaderStage]=r.stages[e.shaderStage]||[],r.stages[e.shaderStage].push(t)}if(1===r){const t=e.getNodeProperties(this);for(const r of Object.values(t))r&&!0===r.isNode&&r.build(e,this)}}generate(e,t){const{outputNode:r}=e.getNodeProperties(this);if(r&&!0===r.isNode)return r.build(e,t)}updateBefore(){d("Abstract function.")}updateAfter(){d("Abstract function.")}update(){d("Abstract function.")}before(e){return null===this._beforeNodes&&(this._beforeNodes=[]),this._beforeNodes.push(e),this}build(e,t=null){const r=this.getShared(e);if(this!==r)return r.build(e,t);if(null!==this._beforeNodes){const r=this._beforeNodes;this._beforeNodes=null;for(const s of r)s.build(e,t);this._beforeNodes=r}const s=e.getDataFromNode(this);s.buildStages=s.buildStages||{},s.buildStages[e.buildStage]=!0;const i=oi[e.buildStage];if(i&&!0!==s.buildStages[i]){const t=e.getBuildStage();e.setBuildStage(i),this.build(e),e.setBuildStage(t)}e.addChain(this);let n=null;const a=e.getBuildStage();if("setup"===a){e.addNode(this),this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){t.initialized=!0,t.outputNode=this.setup(e)||t.outputNode||null;for(const r of Object.values(t))if(r&&!0===r.isNode){if(!0===r.parents){const t=e.getNodeProperties(r);t.parents=t.parents||[],t.parents.push(this)}r.build(e)}e.addSequentialNode(this)}n=t.outputNode}else if("analyze"===a)this.analyze(e,t);else if("generate"===a){if(this.generate.length<2){const r=this.getNodeType(e),s=e.getDataFromNode(this);n=s.snippet,void 0===n?void 0===s.generated?(s.generated=!0,n=this.generate(e)||"",s.snippet=n):(d("Node: Recursion detected.",this),n="/* Recursion detected. */"):void 0!==s.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),n=e.format(n,r,t)}else n=this.generate(e,t)||"";""===n&&null!==t&&"void"!==t&&"OutputType"!==t&&(o(`TSL: Invalid generated code, expected a "${t}".`),n=e.generateConst(t))}return e.removeChain(this),n}getSerializeChildren(){return this._getChildren()}serialize(e){const t=this.getSerializeChildren(),r={};for(const{property:s,index:i,childNode:n}of t)void 0!==i?(void 0===r[s]&&(r[s]=Number.isInteger(i)?[]:{}),r[s][i]=n.toJSON(e.meta).uuid):r[s]=n.toJSON(e.meta).uuid;Object.keys(r).length>0&&(e.inputNodes=r)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const r in e.inputNodes)if(Array.isArray(e.inputNodes[r])){const s=[];for(const i of e.inputNodes[r])s.push(t[i]);this[r]=s}else if("object"==typeof e.inputNodes[r]){const s={};for(const i in e.inputNodes[r]){const n=e.inputNodes[r][i];s[i]=t[n]}this[r]=s}else{const s=e.inputNodes[r];this[r]=t[s]}}}toJSON(e){const{uuid:t,type:r}=this,s=void 0===e||"string"==typeof e;s&&(e={textures:{},images:{},nodes:{}});let i=e.nodes[t];function n(e){const t=[];for(const r in e){const s=e[r];delete s.metadata,t.push(s)}return t}if(void 0===i&&(i={uuid:t,type:r,meta:e,metadata:{version:4.7,type:"Node",generator:"Node.toJSON"}},!0!==s&&(e.nodes[i.uuid]=i),this.serialize(i),delete i.meta),s){const t=n(e.textures),r=n(e.images),s=n(e.nodes);t.length>0&&(i.textures=t),r.length>0&&(i.images=r),s.length>0&&(i.nodes=s)}return i}}li.captureStackTrace=!1;class di extends li{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}getMemberType(e,t){return this.node.getMemberType(e,t)}generate(e){const t=this.indexNode.getNodeType(e);return`${this.node.build(e)}[ ${this.indexNode.build(e,!e.isVector(t)&&e.isInteger(t)?t:"uint")} ]`}}class ci extends li{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let r=null;for(const s of this.convertTo.split("|"))null!==r&&e.getTypeLength(t)!==e.getTypeLength(s)||(r=s);return r}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const r=this.node,s=this.getNodeType(e),i=r.build(e,s);return e.format(i,s,t)}}class hi extends li{static get type(){return"TempNode"}constructor(e=null){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const r=e.getVectorType(this.getNodeType(e,t)),s=e.getDataFromNode(this);if(void 0!==s.propertyName)return e.format(s.propertyName,r,t);if("void"!==r&&"void"!==t&&this.hasDependencies(e)){const i=super.build(e,r),n=e.getVarFromNode(this,null,r),a=e.getPropertyName(n);return e.addLineFlowCode(`${a} = ${i}`,this),s.snippet=i,s.propertyName=a,e.format(s.propertyName,r,t)}}return super.build(e,t)}}class pi extends hi{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce((t,r)=>t+e.getTypeLength(r.getNodeType(e)),0))}generate(e,t){const r=this.getNodeType(e),s=e.getTypeLength(r),i=this.nodes,n=e.getComponentType(r),a=[];let u=0;for(const t of i){if(u>=s){o(`TSL: Length of parameters exceeds maximum length of function '${r}()' type.`,this.stackTrace);break}let i,l=t.getNodeType(e),d=e.getTypeLength(l);u+d>s&&(o(`TSL: Length of '${r}()' data exceeds maximum length of output type.`,this.stackTrace),d=s-u,l=e.getTypeFromLength(d)),u+=d,i=t.build(e,l);if(e.getComponentType(l)!==n){const t=e.getTypeFromLength(d,n);i=e.format(i,l,t)}a.push(i)}const l=`${e.getType(r)}( ${a.join(", ")} )`;return e.format(l,r,t)}}const gi=ai.join("");class mi extends li{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(ai.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}getScope(){return this.node.getScope()}generate(e,t){const r=this.node,s=e.getTypeLength(r.getNodeType(e));let i=null;if(s>1){let n=null;this.getVectorLength()>=s&&(n=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const a=r.build(e,n);i=this.components.length===s&&this.components===gi.slice(0,this.components.length)?e.format(a,n,t):e.format(`${a}.${this.components}`,this.getNodeType(e),t)}else i=r.build(e,t);return i}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class fi extends hi{static get type(){return"SetNode"}constructor(e,t,r){super(),this.sourceNode=e,this.components=t,this.targetNode=r}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:r,targetNode:s}=this,i=this.getNodeType(e),n=e.getComponentType(s.getNodeType(e)),a=e.getTypeFromLength(r.length,n),o=s.build(e,a),u=t.build(e,i),l=e.getTypeLength(i),d=[];for(let e=0;e<l;e++){const t=ai[e];t===r[0]?(d.push(o),e+=r.length-1):d.push(u+"."+t)}return`${e.getType(i)}( ${d.join(", ")} )`}}class yi extends hi{static get type(){return"FlipNode"}constructor(e,t){super(),this.sourceNode=e,this.components=t}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{components:t,sourceNode:r}=this,s=this.getNodeType(e),i=r.build(e),n=e.getVarFromNode(this),a=e.getPropertyName(n);e.addLineFlowCode(a+" = "+i,this);const o=e.getTypeLength(s),u=[];let l=0;for(let e=0;e<o;e++){const r=ai[e];r===t[l]?(u.push("1.0 - "+a+"."+r),l++):u.push(a+"."+r)}return`${e.getType(s)}( ${u.join(", ")} )`}}class bi extends li{static get type(){return"InputNode"}constructor(e,t=null){super(t),this.isInputNode=!0,this.value=e,this.precision=null}getNodeType(){return null===this.nodeType?js(this.value):this.nodeType}getInputType(e){return this.getNodeType(e)}setPrecision(e){return this.precision=e,this}serialize(e){super.serialize(e),e.value=this.value,this.value&&this.value.toArray&&(e.value=this.value.toArray()),e.valueType=js(this.value),e.nodeType=this.nodeType,"ArrayBuffer"===e.valueType&&(e.value=Ys(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?Xs(e.valueType,...e.value):e.value,this.precision=e.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(e.value))}generate(){d("Abstract function.")}}const xi=/float|u?int/;class Ti extends bi{static get type(){return"ConstNode"}constructor(e,t=null){super(e,t),this.isConstNode=!0}generateConst(e){return e.generateConst(this.getNodeType(e),this.value)}generate(e,t){const r=this.getNodeType(e);return xi.test(r)&&xi.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),r,t)}}class _i extends li{static get type(){return"MemberNode"}constructor(e,t){super(),this.structNode=e,this.property=t,this.isMemberNode=!0}hasMember(e){return(!this.structNode.isMemberNode||!1!==this.structNode.hasMember(e))&&"void"!==this.structNode.getMemberType(e,this.property)}getNodeType(e){return!1===this.hasMember(e)?"float":this.structNode.getMemberType(e,this.property)}getMemberType(e,t){if(!1===this.hasMember(e))return"float";const r=this.getNodeType(e);return e.getStructTypeNode(r).getMemberType(e,t)}generate(e){if(!1===this.hasMember(e)){d(`TSL: Member "${this.property}" does not exist in struct.`,this.stackTrace);const t=this.getNodeType(e);return e.generateConst(t)}return this.structNode.build(e)+"."+this.property}}let vi=null;const Ni=new Map;function Si(e,t){if(Ni.has(e))d(`TSL: Redefinition of method chaining '${e}'.`);else{if("function"!=typeof t)throw new Error(`THREE.TSL: Node element ${e} is not a function`);Ni.set(e,t),"assign"!==e&&(li.prototype[e]=function(...e){return this.isStackNode?this.addToStack(t(...e)):t(this,...e)},li.prototype[e+"Assign"]=function(...e){return this.isStackNode?this.assign(e[0],t(...e)):this.assign(t(this,...e))})}}const Ri=e=>(e=>e.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"))(e).split("").sort().join("");li.prototype.assign=function(...e){if(!0!==this.isStackNode)return null!==vi?vi.assign(this,...e):o("TSL: No stack defined for assign operation. Make sure the assign is inside a Fn().",new Ds),this;{const t=Ni.get("assign");return this.addToStack(t(...e))}},li.prototype.toVarIntent=function(){return this},li.prototype.get=function(e){return new _i(this,e)};const Ei={};function Ai(e,t,r){Ei[e]=Ei[t]=Ei[r]={get(){this._cache=this._cache||{};let t=this._cache[e];return void 0===t&&(t=new mi(this,e),this._cache[e]=t),t},set(t){this[e].assign(Ji(t))}};const s=e.toUpperCase(),i=t.toUpperCase(),n=r.toUpperCase();li.prototype["set"+s]=li.prototype["set"+i]=li.prototype["set"+n]=function(t){const r=Ri(e);return new fi(this,r,Ji(t))},li.prototype["flip"+s]=li.prototype["flip"+i]=li.prototype["flip"+n]=function(){const t=Ri(e);return new yi(this,t)}}const wi=["x","y","z","w"],Ci=["r","g","b","a"],Mi=["s","t","p","q"];for(let e=0;e<4;e++){let t=wi[e],r=Ci[e],s=Mi[e];Ai(t,r,s);for(let i=0;i<4;i++){t=wi[e]+wi[i],r=Ci[e]+Ci[i],s=Mi[e]+Mi[i],Ai(t,r,s);for(let n=0;n<4;n++){t=wi[e]+wi[i]+wi[n],r=Ci[e]+Ci[i]+Ci[n],s=Mi[e]+Mi[i]+Mi[n],Ai(t,r,s);for(let a=0;a<4;a++)t=wi[e]+wi[i]+wi[n]+wi[a],r=Ci[e]+Ci[i]+Ci[n]+Ci[a],s=Mi[e]+Mi[i]+Mi[n]+Mi[a],Ai(t,r,s)}}}for(let e=0;e<32;e++)Ei[e]={get(){this._cache=this._cache||{};let t=this._cache[e];return void 0===t&&(t=new di(this,new Ti(e,"uint")),this._cache[e]=t),t},set(t){this[e].assign(Ji(t))}};Object.defineProperties(li.prototype,Ei);const Bi=new WeakMap,Fi=function(e,t=null){for(const r in e)e[r]=Ji(e[r],t);return e},Li=function(e,t=null){const r=e.length;for(let s=0;s<r;s++)e[s]=Ji(e[s],t);return e},Pi=function(e,t=null,r=null,s=null){function i(e){return null!==s?(e=Ji(Object.assign(e,s)),!0===s.intent&&(e=e.toVarIntent())):e=Ji(e),e}let n,a,u,l=t;function d(t){let r;return r=l?/[a-z]/i.test(l)?l+"()":l:e.type,void 0!==a&&t.length<a?(o(`TSL: "${r}" parameter length is less than minimum required.`,new Ds),t.concat(new Array(a-t.length).fill(0))):void 0!==u&&t.length>u?(o(`TSL: "${r}" parameter length exceeds limit.`,new Ds),t.slice(0,u)):t}return null===t?n=(...t)=>i(new e(...rn(d(t)))):null!==r?(r=Ji(r),n=(...s)=>i(new e(t,...rn(d(s)),r))):n=(...r)=>i(new e(t,...rn(d(r)))),n.setParameterLength=(...e)=>(1===e.length?a=u=e[0]:2===e.length&&([a,u]=e),n),n.setName=e=>(l=e,n),n},Di=function(e,...t){return new e(...rn(t))};class Ui extends li{constructor(e,t){super(),this.shaderNode=e,this.rawInputs=t,this.isShaderCallNodeInternal=!0}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}getElementType(e){return this.getOutputNode(e).getElementType(e)}getMemberType(e,t){return this.getOutputNode(e).getMemberType(e,t)}call(e){const{shaderNode:t,rawInputs:r}=this,s=e.getNodeProperties(t),i=e.getClosestSubBuild(t.subBuilds)||"",n=i||"default";if(s[n])return s[n];const a=e.subBuildFn,o=e.fnCall;e.subBuildFn=i,e.fnCall=this;let u=null;if(t.layout){let s=Bi.get(e.constructor);void 0===s&&(s=new WeakMap,Bi.set(e.constructor,s));let i=s.get(t);void 0===i&&(i=Ji(e.buildFunctionNode(t)),s.set(t,i)),e.addInclude(i);const n=r?function(e){let t;tn(e);t=e[0]&&(e[0].isNode||Object.getPrototypeOf(e[0])!==Object.prototype)?[...e]:e[0];return t}(r):null;u=Ji(i.call(n))}else{const s=new Proxy(e,{get:(e,t,r)=>{let s;return s=Symbol.iterator===t?function*(){yield}:Reflect.get(e,t,r),s}}),i=r?function(e){let t=0;return tn(e),new Proxy(e,{get:(r,s,i)=>{let n;if("length"===s)return n=e.length,n;if(Symbol.iterator===s)n=function*(){for(const t of e)yield Ji(t)};else{if(e.length>0)if(Object.getPrototypeOf(e[0])===Object.prototype){const r=e[0];n=void 0===r[s]?r[t++]:Reflect.get(r,s,i)}else e[0]instanceof li&&(n=void 0===e[s]?e[t++]:Reflect.get(e,s,i));else n=Reflect.get(r,s,i);n=Ji(n)}return n}})}(r):null,n=Array.isArray(r)?r.length>0:null!==r,a=t.jsFunc,o=n||a.length>1?a(i,s):a(s);u=Ji(o)}return e.subBuildFn=a,e.fnCall=o,t.once&&(s[n]=u),u}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}getOutputNode(e){const t=e.getNodeProperties(this),r=e.getSubBuildOutput(this);return t[r]=t[r]||this.setupOutput(e),t[r].subBuild=e.getClosestSubBuild(this),t[r]}build(e,t=null){let r=null;const s=e.getBuildStage(),i=e.getNodeProperties(this),n=e.getSubBuildOutput(this),a=this.getOutputNode(e),o=e.fnCall;if(e.fnCall=this,"setup"===s){const t=e.getSubBuildProperty("initialized",this);if(!0!==i[t]&&(i[t]=!0,i[n]=this.getOutputNode(e),i[n].build(e),this.shaderNode.subBuilds))for(const t of e.chaining){const r=e.getDataFromNode(t,"any");r.subBuilds=r.subBuilds||new Set;for(const e of this.shaderNode.subBuilds)r.subBuilds.add(e)}r=i[n]}else"analyze"===s?a.build(e,t):"generate"===s&&(r=a.build(e,t)||"");return e.fnCall=o,r}}class Ii extends li{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}getLayout(){return this.layout}call(e=null){return new Ui(this,e)}setup(){return this.call()}}const Oi=[!1,!0],Vi=[0,1,2,3],ki=[-1,-2],Gi=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],$i=new Map;for(const e of Oi)$i.set(e,new Ti(e));const zi=new Map;for(const e of Vi)zi.set(e,new Ti(e,"uint"));const Wi=new Map([...zi].map(e=>new Ti(e.value,"int")));for(const e of ki)Wi.set(e,new Ti(e,"int"));const Hi=new Map([...Wi].map(e=>new Ti(e.value)));for(const e of Gi)Hi.set(e,new Ti(e));for(const e of Gi)Hi.set(-e,new Ti(-e));const qi={bool:$i,uint:zi,ints:Wi,float:Hi},ji=new Map([...$i,...Hi]),Xi=(e,t)=>ji.has(e)?ji.get(e):!0===e.isNode?e:new Ti(e,t),Ki=function(e,t=null){return(...r)=>{for(const t of r)if(void 0===t)return o(`TSL: Invalid parameter for the type "${e}".`,new Ds),new Ti(0,e);if((0===r.length||!["bool","float","int","uint"].includes(e)&&r.every(e=>{const t=typeof e;return"object"!==t&&"function"!==t}))&&(r=[Xs(e,...r)]),1===r.length&&null!==t&&t.has(r[0]))return en(t.get(r[0]));if(1===r.length){const t=Xi(r[0],e);return t.nodeType===e?en(t):en(new ci(t,e))}const s=r.map(e=>Xi(e));return en(new pi(s,e))}},Yi=e=>"object"==typeof e&&null!==e?e.value:e,Qi=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function Zi(e,t){return new Ii(e,t)}const Ji=(e,t=null)=>function(e,t=null){const r=js(e);return"node"===r?e:null===t&&("float"===r||"boolean"===r)||r&&"shader"!==r&&"string"!==r?Ji(Xi(e,t)):"shader"===r?e.isFn?e:ln(e):e}(e,t),en=(e,t=null)=>Ji(e,t).toVarIntent(),tn=(e,t=null)=>new Fi(e,t),rn=(e,t=null)=>new Li(e,t),sn=(e,t=null,r=null,s=null)=>new Pi(e,t,r,s),nn=(e,...t)=>new Di(e,...t),an=(e,t=null,r=null,s={})=>new Pi(e,t,r,{...s,intent:!0});let on=0;class un extends li{constructor(e,t=null){super();let r=null;null!==t&&("object"==typeof t?r=t.return:("string"==typeof t?r=t:o("TSL: Invalid layout type.",new Ds),t=null)),this.shaderNode=new Zi(e,r),null!==t&&this.setLayout(t),this.isFn=!0}setLayout(e){const t=this.shaderNode.nodeType;if("object"!=typeof e.inputs){const r={name:"fn"+on++,type:t,inputs:[]};for(const t in e)"return"!==t&&r.inputs.push({name:t,type:e[t]});e=r}return this.shaderNode.setLayout(e),this}getNodeType(e){return this.shaderNode.getNodeType(e)||"float"}call(...e){const t=this.shaderNode.call(e);return"void"===this.shaderNode.nodeType&&t.toStack(),t.toVarIntent()}once(e=null){return this.shaderNode.once=!0,this.shaderNode.subBuilds=e,this}generate(e){const t=this.getNodeType(e);return o('TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".',this.stackTrace),e.generateConst(t)}}function ln(e,t=null){const r=new un(e,t);return new Proxy(()=>{},{apply:(e,t,s)=>r.call(...s),get:(e,t,s)=>Reflect.get(r,t,s),set:(e,t,s,i)=>Reflect.set(r,t,s,i)})}const dn=e=>{vi=e},cn=()=>vi,hn=(...e)=>vi.If(...e);function pn(e){return vi&&vi.addToStack(e),e}Si("toStack",pn);const gn=new Ki("color"),mn=new Ki("float",qi.float),fn=new Ki("int",qi.ints),yn=new Ki("uint",qi.uint),bn=new Ki("bool",qi.bool),xn=new Ki("vec2"),Tn=new Ki("ivec2"),_n=new Ki("uvec2"),vn=new Ki("bvec2"),Nn=new Ki("vec3"),Sn=new Ki("ivec3"),Rn=new Ki("uvec3"),En=new Ki("bvec3"),An=new Ki("vec4"),wn=new Ki("ivec4"),Cn=new Ki("uvec4"),Mn=new Ki("bvec4"),Bn=new Ki("mat2"),Fn=new Ki("mat3"),Ln=new Ki("mat4");Si("toColor",gn),Si("toFloat",mn),Si("toInt",fn),Si("toUint",yn),Si("toBool",bn),Si("toVec2",xn),Si("toIVec2",Tn),Si("toUVec2",_n),Si("toBVec2",vn),Si("toVec3",Nn),Si("toIVec3",Sn),Si("toUVec3",Rn),Si("toBVec3",En),Si("toVec4",An),Si("toIVec4",wn),Si("toUVec4",Cn),Si("toBVec4",Mn),Si("toMat2",Bn),Si("toMat3",Fn),Si("toMat4",Ln);const Pn=sn(di).setParameterLength(2),Dn=(e,t)=>new ci(Ji(e),t);Si("element",Pn),Si("convert",Dn);Si("append",e=>(d("TSL: .append() has been renamed to .toStack().",new Ds),pn(e)));class Un extends li{static get type(){return"PropertyNode"}constructor(e,t=null,r=!1){super(e),this.name=t,this.varying=r,this.isPropertyNode=!0,this.global=!0}customCacheKey(){return Is(this.type+":"+(this.name||"")+":"+(this.varying?"1":"0"))}getHash(e){return this.name||super.getHash(e)}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const In=(e,t)=>new Un(e,t),On=(e,t)=>new Un(e,t,!0),Vn=nn(Un,"vec4","DiffuseColor"),kn=nn(Un,"vec3","DiffuseContribution"),Gn=nn(Un,"vec3","EmissiveColor"),$n=nn(Un,"float","Roughness"),zn=nn(Un,"float","Metalness"),Wn=nn(Un,"float","Clearcoat"),Hn=nn(Un,"float","ClearcoatRoughness"),qn=nn(Un,"vec3","Sheen"),jn=nn(Un,"float","SheenRoughness"),Xn=nn(Un,"float","Iridescence"),Kn=nn(Un,"float","IridescenceIOR"),Yn=nn(Un,"float","IridescenceThickness"),Qn=nn(Un,"float","AlphaT"),Zn=nn(Un,"float","Anisotropy"),Jn=nn(Un,"vec3","AnisotropyT"),ea=nn(Un,"vec3","AnisotropyB"),ta=nn(Un,"color","SpecularColor"),ra=nn(Un,"color","SpecularColorBlended"),sa=nn(Un,"float","SpecularF90"),ia=nn(Un,"float","Shininess"),na=nn(Un,"vec4","Output"),aa=nn(Un,"float","dashSize"),oa=nn(Un,"float","gapSize"),ua=nn(Un,"float","pointWidth"),la=nn(Un,"float","IOR"),da=nn(Un,"float","Transmission"),ca=nn(Un,"float","Thickness"),ha=nn(Un,"float","AttenuationDistance"),pa=nn(Un,"color","AttenuationColor"),ga=nn(Un,"float","Dispersion");class ma extends li{static get type(){return"UniformGroupNode"}constructor(e,t=!1,r=1){super("string"),this.name=e,this.shared=t,this.order=r,this.isUniformGroup=!0}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const fa=e=>new ma(e),ya=(e,t=0)=>new ma(e,!0,t),ba=ya("frame"),xa=ya("render"),Ta=fa("object");class _a extends bi{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Ta}setName(e){return this.name=e,this}label(e){return d('TSL: "label()" has been deprecated. Use "setName()" instead.',new Ds),this.setName(e)}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){return e=e.bind(this),super.onUpdate(t=>{const r=e(t,this);void 0!==r&&(this.value=r)},t)}getInputType(e){let t=super.getInputType(e);return"bool"===t&&(t="uint"),t}generate(e,t){const r=this.getNodeType(e),s=this.getUniformHash(e);let i=e.getNodeFromHash(s);void 0===i&&(e.setHashNode(this,s),i=this);const n=i.getInputType(e),a=e.getUniformFromNode(i,n,e.shaderStage,this.name||e.context.nodeName),o=e.getPropertyName(a);void 0!==e.context.nodeName&&delete e.context.nodeName;let u=o;if("bool"===r){const t=e.getDataFromNode(this);let s=t.propertyName;if(void 0===s){const i=e.getVarFromNode(this,null,"bool");s=e.getPropertyName(i),t.propertyName=s,u=e.format(o,n,r),e.addLineFlowCode(`${s} = ${u}`,this)}u=s}return e.format(u,r,t)}}const va=(e,t)=>{const r=Qi(t||e);if(r===e&&(e=Xs(r)),e&&!0===e.isNode){let t=e.value;e.traverse(e=>{!0===e.isConstNode&&(t=e.value)}),e=t}return new _a(e,r)};class Na extends hi{static get type(){return"ArrayNode"}constructor(e,t,r=null){super(e),this.count=t,this.values=r,this.isArrayNode=!0}getArrayCount(){return this.count}getNodeType(e){return null===this.nodeType?this.values[0].getNodeType(e):this.nodeType}getElementType(e){return this.getNodeType(e)}getMemberType(e,t){return null===this.nodeType?this.values[0].getMemberType(e,t):super.getMemberType(e,t)}generate(e){const t=this.getNodeType(e);return e.generateArray(t,this.count,this.values)}}const Sa=(...e)=>{let t;if(1===e.length){const r=e[0];t=new Na(null,r.length,r)}else{const r=e[0],s=e[1];t=new Na(r,s)}return Ji(t)};Si("toArray",(e,t)=>Sa(Array(t).fill(e)));class Ra extends hi{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t,this.isAssignNode=!0}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const r=e.getTypeLength(t.node.getNodeType(e));return ai.join("").slice(0,r)!==t.components}return!1}setup(e){const{targetNode:t,sourceNode:r}=this,s=t.getScope();e.getDataFromNode(s).assign=!0;const i=e.getNodeProperties(this);i.sourceNode=r,i.targetNode=t.context({assign:!0})}generate(e,t){const{targetNode:r,sourceNode:s}=e.getNodeProperties(this),i=this.needsSplitAssign(e),n=r.build(e),a=r.getNodeType(e),o=s.build(e,a),u=s.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=n);else if(i){const s=e.getVarFromNode(this,null,a),i=e.getPropertyName(s);e.addLineFlowCode(`${i} = ${o}`,this);const u=r.node,l=u.node.context({assign:!0}).build(e);for(let t=0;t<u.components.length;t++){const r=u.components[t];e.addLineFlowCode(`${l}.${r} = ${i}[ ${t} ]`,this)}"void"!==t&&(d=n)}else d=`${n} = ${o}`,"void"!==t&&"void"!==u||(e.addLineFlowCode(d,this),"void"!==t&&(d=n));return l.initialized=!0,e.format(d,a,t)}}const Ea=sn(Ra).setParameterLength(2);Si("assign",Ea);class Aa extends hi{static get type(){return"FunctionCallNode"}constructor(e=null,t={}){super(),this.functionNode=e,this.parameters=t}setParameters(e){return this.parameters=e,this}getParameters(){return this.parameters}getNodeType(e){return this.functionNode.getNodeType(e)}getMemberType(e,t){return this.functionNode.getMemberType(e,t)}generate(e){const t=[],r=this.functionNode,s=r.getInputs(e),i=this.parameters,n=(t,r)=>{const s=r.type;let i;return i="pointer"===s?"&"+t.build(e):t.build(e,s),i};if(Array.isArray(i)){if(i.length>s.length)o("TSL: The number of provided parameters exceeds the expected number of inputs in 'Fn()'."),i.length=s.length;else if(i.length<s.length)for(o("TSL: The number of provided parameters is less than the expected number of inputs in 'Fn()'.");i.length<s.length;)i.push(mn(0));for(let e=0;e<i.length;e++)t.push(n(i[e],s[e]))}else for(const e of s){const r=i[e.name];void 0!==r?t.push(n(r,e)):(o(`TSL: Input '${e.name}' not found in 'Fn()'.`),t.push(n(mn(0),e)))}return`${r.build(e,"property")}( ${t.join(", ")} )`}}const wa=(e,...t)=>(t=t.length>1||t[0]&&!0===t[0].isNode?rn(t):tn(t[0]),new Aa(Ji(e),t));Si("call",wa);const Ca={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"};class Ma extends hi{static get type(){return"OperatorNode"}constructor(e,t,r,...s){if(super(),s.length>0){let i=new Ma(e,t,r);for(let t=0;t<s.length-1;t++)i=new Ma(e,i,s[t]);t=i,r=s[s.length-1]}this.op=e,this.aNode=t,this.bNode=r,this.isOperatorNode=!0}getOperatorMethod(e,t){return e.getMethod(Ca[this.op],t)}getNodeType(e,t=null){const r=this.op,s=this.aNode,i=this.bNode,n=s.getNodeType(e),a=i?i.getNodeType(e):null;if("void"===n||"void"===a)return t||"void";if("%"===r)return n;if("~"===r||"&"===r||"|"===r||"^"===r||">>"===r||"<<"===r)return e.getIntegerType(n);if("!"===r||"&&"===r||"||"===r||"^^"===r)return"bool";if("=="===r||"!="===r||"<"===r||">"===r||"<="===r||">="===r){const t=Math.max(e.getTypeLength(n),e.getTypeLength(a));return t>1?`bvec${t}`:"bool"}if(e.isMatrix(n)){if("float"===a)return n;if(e.isVector(a))return e.getVectorFromMatrix(n);if(e.isMatrix(a))return n}else if(e.isMatrix(a)){if("float"===n)return a;if(e.isVector(n))return e.getVectorFromMatrix(a)}return e.getTypeLength(a)>e.getTypeLength(n)?a:n}generate(e,t){const r=this.op,{aNode:s,bNode:i}=this,n=this.getNodeType(e,t);let a=null,o=null;"void"!==n?(a=s.getNodeType(e),o=i?i.getNodeType(e):null,"<"===r||">"===r||"<="===r||">="===r||"=="===r||"!="===r?e.isVector(a)?o=a:e.isVector(o)?a=o:a!==o&&(a=o="float"):">>"===r||"<<"===r?(a=n,o=e.changeComponentType(o,"uint")):"%"===r?(a=n,o=e.isInteger(a)&&e.isInteger(o)?o:a):e.isMatrix(a)?"float"===o?o="float":e.isVector(o)?o=e.getVectorFromMatrix(a):e.isMatrix(o)||(a=o=n):a=e.isMatrix(o)?"float"===a?"float":e.isVector(a)?e.getVectorFromMatrix(o):o=n:o=n):a=o=n;const u=s.build(e,a),l=i?i.build(e,o):null,d=e.getFunctionOperator(r);if("void"!==t){const s=e.renderer.coordinateSystem===c;if("=="===r||"!="===r||"<"===r||">"===r||"<="===r||">="===r)return s&&e.isVector(a)?e.format(`${this.getOperatorMethod(e,t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} ${r} ${l} )`,n,t);if("%"===r)return e.isInteger(o)?e.format(`( ${u} % ${l} )`,n,t):e.format(`${this.getOperatorMethod(e,n)}( ${u}, ${l} )`,n,t);if("!"===r||"~"===r)return e.format(`(${r}${u})`,a,t);if(d)return e.format(`${d}( ${u}, ${l} )`,n,t);if(e.isMatrix(a)&&"float"===o)return e.format(`( ${l} ${r} ${u} )`,n,t);if("float"===a&&e.isMatrix(o))return e.format(`${u} ${r} ${l}`,n,t);{let i=`( ${u} ${r} ${l} )`;return!s&&"bool"===n&&e.isVector(a)&&e.isVector(o)&&(i=`all${i}`),e.format(i,n,t)}}if("void"!==a)return d?e.format(`${d}( ${u}, ${l} )`,n,t):e.isMatrix(a)&&"float"===o?e.format(`${l} ${r} ${u}`,n,t):e.format(`${u} ${r} ${l}`,n,t)}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Ba=an(Ma,"+").setParameterLength(2,1/0).setName("add"),Fa=an(Ma,"-").setParameterLength(2,1/0).setName("sub"),La=an(Ma,"*").setParameterLength(2,1/0).setName("mul"),Pa=an(Ma,"/").setParameterLength(2,1/0).setName("div"),Da=an(Ma,"%").setParameterLength(2).setName("mod"),Ua=an(Ma,"==").setParameterLength(2).setName("equal"),Ia=an(Ma,"!=").setParameterLength(2).setName("notEqual"),Oa=an(Ma,"<").setParameterLength(2).setName("lessThan"),Va=an(Ma,">").setParameterLength(2).setName("greaterThan"),ka=an(Ma,"<=").setParameterLength(2).setName("lessThanEqual"),Ga=an(Ma,">=").setParameterLength(2).setName("greaterThanEqual"),$a=an(Ma,"&&").setParameterLength(2,1/0).setName("and"),za=an(Ma,"||").setParameterLength(2,1/0).setName("or"),Wa=an(Ma,"!").setParameterLength(1).setName("not"),Ha=an(Ma,"^^").setParameterLength(2).setName("xor"),qa=an(Ma,"&").setParameterLength(2).setName("bitAnd"),ja=an(Ma,"~").setParameterLength(1).setName("bitNot"),Xa=an(Ma,"|").setParameterLength(2).setName("bitOr"),Ka=an(Ma,"^").setParameterLength(2).setName("bitXor"),Ya=an(Ma,"<<").setParameterLength(2).setName("shiftLeft"),Qa=an(Ma,">>").setParameterLength(2).setName("shiftRight"),Za=ln(([e])=>(e.addAssign(1),e)),Ja=ln(([e])=>(e.subAssign(1),e)),eo=ln(([e])=>{const t=fn(e).toConst();return e.addAssign(1),t}),to=ln(([e])=>{const t=fn(e).toConst();return e.subAssign(1),t});Si("add",Ba),Si("sub",Fa),Si("mul",La),Si("div",Pa),Si("mod",Da),Si("equal",Ua),Si("notEqual",Ia),Si("lessThan",Oa),Si("greaterThan",Va),Si("lessThanEqual",ka),Si("greaterThanEqual",Ga),Si("and",$a),Si("or",za),Si("not",Wa),Si("xor",Ha),Si("bitAnd",qa),Si("bitNot",ja),Si("bitOr",Xa),Si("bitXor",Ka),Si("shiftLeft",Ya),Si("shiftRight",Qa),Si("incrementBefore",Za),Si("decrementBefore",Ja),Si("increment",eo),Si("decrement",to);const ro=(e,t)=>(d('TSL: "modInt()" is deprecated. Use "mod( int( ... ) )" instead.',new Ds),Da(fn(e),fn(t)));Si("modInt",ro);class so extends hi{static get type(){return"MathNode"}constructor(e,t,r=null,s=null){if(super(),(e===so.MAX||e===so.MIN)&&arguments.length>3){let i=new so(e,t,r);for(let t=2;t<arguments.length-1;t++)i=new so(e,i,arguments[t]);t=i,r=arguments[arguments.length-1],s=null}this.method=e,this.aNode=t,this.bNode=r,this.cNode=s,this.isMathNode=!0}getInputType(e){const t=this.aNode.getNodeType(e),r=this.bNode?this.bNode.getNodeType(e):null,s=this.cNode?this.cNode.getNodeType(e):null,i=e.isMatrix(t)?0:e.getTypeLength(t),n=e.isMatrix(r)?0:e.getTypeLength(r),a=e.isMatrix(s)?0:e.getTypeLength(s);return i>n&&i>a?t:n>a?r:a>i?s:t}getNodeType(e){const t=this.method;return t===so.LENGTH||t===so.DISTANCE||t===so.DOT?"float":t===so.CROSS?"vec3":t===so.ALL||t===so.ANY?"bool":t===so.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):this.getInputType(e)}setup(e){const{aNode:t,bNode:r,method:s}=this;let i=null;if(s===so.ONE_MINUS)i=Fa(1,t);else if(s===so.RECIPROCAL)i=Pa(1,t);else if(s===so.DIFFERENCE)i=Bo(Fa(t,r));else if(s===so.TRANSFORM_DIRECTION){let s=t,n=r;e.isMatrix(s.getNodeType(e))?n=An(Nn(n),0):s=An(Nn(s),0);const a=La(s,n).xyz;i=No(a)}return null!==i?i:super.setup(e)}generate(e,t){if(e.getNodeProperties(this).outputNode)return super.generate(e,t);let r=this.method;const s=this.getNodeType(e),i=this.getInputType(e),n=this.aNode,a=this.bNode,o=this.cNode,u=e.renderer.coordinateSystem;if(r===so.NEGATE)return e.format("( - "+n.build(e,i)+" )",s,t);{const l=[];return r===so.CROSS?l.push(n.build(e,s),a.build(e,s)):u===c&&r===so.STEP?l.push(n.build(e,1===e.getTypeLength(n.getNodeType(e))?"float":i),a.build(e,i)):u!==c||r!==so.MIN&&r!==so.MAX?r===so.REFRACT?l.push(n.build(e,i),a.build(e,i),o.build(e,"float")):r===so.MIX?l.push(n.build(e,i),a.build(e,i),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":i)):(u===h&&r===so.ATAN&&null!==a&&(r="atan2"),"fragment"===e.shaderStage||r!==so.DFDX&&r!==so.DFDY||(d(`TSL: '${r}' is not supported in the ${e.shaderStage} stage.`,this.stackTrace),r="/*"+r+"*/"),l.push(n.build(e,i)),null!==a&&l.push(a.build(e,i)),null!==o&&l.push(o.build(e,i))):l.push(n.build(e,i),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":i)),e.format(`${e.getMethod(r,s)}( ${l.join(", ")} )`,s,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}so.ALL="all",so.ANY="any",so.RADIANS="radians",so.DEGREES="degrees",so.EXP="exp",so.EXP2="exp2",so.LOG="log",so.LOG2="log2",so.SQRT="sqrt",so.INVERSE_SQRT="inversesqrt",so.FLOOR="floor",so.CEIL="ceil",so.NORMALIZE="normalize",so.FRACT="fract",so.SIN="sin",so.COS="cos",so.TAN="tan",so.ASIN="asin",so.ACOS="acos",so.ATAN="atan",so.ABS="abs",so.SIGN="sign",so.LENGTH="length",so.NEGATE="negate",so.ONE_MINUS="oneMinus",so.DFDX="dFdx",so.DFDY="dFdy",so.ROUND="round",so.RECIPROCAL="reciprocal",so.TRUNC="trunc",so.FWIDTH="fwidth",so.TRANSPOSE="transpose",so.DETERMINANT="determinant",so.INVERSE="inverse",so.EQUALS="equals",so.MIN="min",so.MAX="max",so.STEP="step",so.REFLECT="reflect",so.DISTANCE="distance",so.DIFFERENCE="difference",so.DOT="dot",so.CROSS="cross",so.POW="pow",so.TRANSFORM_DIRECTION="transformDirection",so.MIX="mix",so.CLAMP="clamp",so.REFRACT="refract",so.SMOOTHSTEP="smoothstep",so.FACEFORWARD="faceforward";const io=mn(1e-6),no=mn(1e6),ao=mn(Math.PI),oo=mn(2*Math.PI),uo=mn(2*Math.PI),lo=mn(.5*Math.PI),co=an(so,so.ALL).setParameterLength(1),ho=an(so,so.ANY).setParameterLength(1),po=an(so,so.RADIANS).setParameterLength(1),go=an(so,so.DEGREES).setParameterLength(1),mo=an(so,so.EXP).setParameterLength(1),fo=an(so,so.EXP2).setParameterLength(1),yo=an(so,so.LOG).setParameterLength(1),bo=an(so,so.LOG2).setParameterLength(1),xo=an(so,so.SQRT).setParameterLength(1),To=an(so,so.INVERSE_SQRT).setParameterLength(1),_o=an(so,so.FLOOR).setParameterLength(1),vo=an(so,so.CEIL).setParameterLength(1),No=an(so,so.NORMALIZE).setParameterLength(1),So=an(so,so.FRACT).setParameterLength(1),Ro=an(so,so.SIN).setParameterLength(1),Eo=an(so,so.COS).setParameterLength(1),Ao=an(so,so.TAN).setParameterLength(1),wo=an(so,so.ASIN).setParameterLength(1),Co=an(so,so.ACOS).setParameterLength(1),Mo=an(so,so.ATAN).setParameterLength(1,2),Bo=an(so,so.ABS).setParameterLength(1),Fo=an(so,so.SIGN).setParameterLength(1),Lo=an(so,so.LENGTH).setParameterLength(1),Po=an(so,so.NEGATE).setParameterLength(1),Do=an(so,so.ONE_MINUS).setParameterLength(1),Uo=an(so,so.DFDX).setParameterLength(1),Io=an(so,so.DFDY).setParameterLength(1),Oo=an(so,so.ROUND).setParameterLength(1),Vo=an(so,so.RECIPROCAL).setParameterLength(1),ko=an(so,so.TRUNC).setParameterLength(1),Go=an(so,so.FWIDTH).setParameterLength(1),$o=an(so,so.TRANSPOSE).setParameterLength(1),zo=an(so,so.DETERMINANT).setParameterLength(1),Wo=an(so,so.INVERSE).setParameterLength(1),Ho=an(so,so.MIN).setParameterLength(2,1/0),qo=an(so,so.MAX).setParameterLength(2,1/0),jo=an(so,so.STEP).setParameterLength(2),Xo=an(so,so.REFLECT).setParameterLength(2),Ko=an(so,so.DISTANCE).setParameterLength(2),Yo=an(so,so.DIFFERENCE).setParameterLength(2),Qo=an(so,so.DOT).setParameterLength(2),Zo=an(so,so.CROSS).setParameterLength(2),Jo=an(so,so.POW).setParameterLength(2),eu=e=>La(e,e),tu=e=>La(e,e,e),ru=e=>La(e,e,e,e),su=an(so,so.TRANSFORM_DIRECTION).setParameterLength(2),iu=e=>La(Fo(e),Jo(Bo(e),1/3)),nu=e=>Qo(e,e),au=an(so,so.MIX).setParameterLength(3),ou=(e,t=0,r=1)=>new so(so.CLAMP,Ji(e),Ji(t),Ji(r)),uu=e=>ou(e),lu=an(so,so.REFRACT).setParameterLength(3),du=an(so,so.SMOOTHSTEP).setParameterLength(3),cu=an(so,so.FACEFORWARD).setParameterLength(3),hu=ln(([e])=>{const t=Qo(e.xy,xn(12.9898,78.233)),r=Da(t,ao);return So(Ro(r).mul(43758.5453))}),pu=(e,t,r)=>au(t,r,e),gu=(e,t,r)=>du(t,r,e),mu=(e,t)=>jo(t,e),fu=cu,yu=To;Si("all",co),Si("any",ho),Si("radians",po),Si("degrees",go),Si("exp",mo),Si("exp2",fo),Si("log",yo),Si("log2",bo),Si("sqrt",xo),Si("inverseSqrt",To),Si("floor",_o),Si("ceil",vo),Si("normalize",No),Si("fract",So),Si("sin",Ro),Si("cos",Eo),Si("tan",Ao),Si("asin",wo),Si("acos",Co),Si("atan",Mo),Si("abs",Bo),Si("sign",Fo),Si("length",Lo),Si("lengthSq",nu),Si("negate",Po),Si("oneMinus",Do),Si("dFdx",Uo),Si("dFdy",Io),Si("round",Oo),Si("reciprocal",Vo),Si("trunc",ko),Si("fwidth",Go),Si("min",Ho),Si("max",qo),Si("step",mu),Si("reflect",Xo),Si("distance",Ko),Si("dot",Qo),Si("cross",Zo),Si("pow",Jo),Si("pow2",eu),Si("pow3",tu),Si("pow4",ru),Si("transformDirection",su),Si("mix",pu),Si("clamp",ou),Si("refract",lu),Si("smoothstep",gu),Si("faceForward",cu),Si("difference",Yo),Si("saturate",uu),Si("cbrt",iu),Si("transpose",$o),Si("determinant",zo),Si("inverse",Wo),Si("rand",hu);class bu extends li{static get type(){return"ConditionalNode"}constructor(e,t,r=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=r}getNodeType(e){const{ifNode:t,elseNode:r}=e.getNodeProperties(this);if(void 0===t)return e.flowBuildStage(this,"setup"),this.getNodeType(e);const s=t.getNodeType(e);if(null!==r){const t=r.getNodeType(e);if(e.getTypeLength(t)>e.getTypeLength(s))return t}return s}setup(e){const t=this.condNode,r=this.ifNode.isolate(),s=this.elseNode?this.elseNode.isolate():null,i=e.context.nodeBlock;e.getDataFromNode(r).parentNodeBlock=i,null!==s&&(e.getDataFromNode(s).parentNodeBlock=i);const n=e.context.uniformFlow,a=e.getNodeProperties(this);a.condNode=t,a.ifNode=n?r:r.context({nodeBlock:r}),a.elseNode=s?n?s:s.context({nodeBlock:s}):null}generate(e,t){const r=this.getNodeType(e),s=e.getDataFromNode(this);if(void 0!==s.nodeProperty)return s.nodeProperty;const{condNode:i,ifNode:n,elseNode:a}=e.getNodeProperties(this),o=e.currentFunctionNode,u="void"!==t,l=u?In(r).build(e):"";s.nodeProperty=l;const c=i.build(e,"bool");if(e.context.uniformFlow&&null!==a){const s=n.build(e,r),i=a.build(e,r),o=e.getTernary(c,s,i);return e.format(o,r,t)}e.addFlowCode(`\n${e.tab}if ( ${c} ) {\n\n`).addFlowTab();let h=n.build(e,r);if(h&&(u?h=l+" = "+h+";":(h="return "+h+";",null===o&&(d("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),h="// "+h))),e.removeFlowTab().addFlowCode(e.tab+"\t"+h+"\n\n"+e.tab+"}"),null!==a){e.addFlowCode(" else {\n\n").addFlowTab();let t=a.build(e,r);t&&(u?t=l+" = "+t+";":(t="return "+t+";",null===o&&(d("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),t="// "+t))),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(l,r,t)}}const xu=sn(bu).setParameterLength(2,3);Si("select",xu);class Tu extends li{static get type(){return"ContextNode"}constructor(e=null,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}getFlowContextData(){const e=[];return this.traverse(t=>{!0===t.isContextNode&&e.push(t.value)}),Object.assign({},...e)}getMemberType(e,t){return this.node.getMemberType(e,t)}analyze(e){const t=e.addContext(this.value);this.node.build(e),e.setContext(t)}setup(e){const t=e.addContext(this.value);this.node.build(e),e.setContext(t)}generate(e,t){const r=e.addContext(this.value),s=this.node.build(e,t);return e.setContext(r),s}}const _u=(e=null,t={})=>{let r=e;return null!==r&&!0===r.isNode||(t=r||t,r=null),new Tu(r,t)},vu=e=>_u(e,{uniformFlow:!0}),Nu=(e,t)=>_u(e,{nodeName:t});function Su(e,t,r=null){return _u(r,{getShadow:({light:r,shadowColorNode:s})=>t===r?s.mul(e):s})}function Ru(e,t=null){return _u(t,{getAO:(t,{material:r})=>!0===r.transparent?t:null!==t?t.mul(e):e})}function Eu(e,t){return d('TSL: "label()" has been deprecated. Use "setName()" instead.'),Nu(e,t)}Si("context",_u),Si("label",Eu),Si("uniformFlow",vu),Si("setName",Nu),Si("builtinShadowContext",(e,t,r)=>Su(t,r,e)),Si("builtinAOContext",(e,t)=>Ru(t,e));class Au extends li{static get type(){return"VarNode"}constructor(e,t=null,r=!1){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0,this.readOnly=r,this.parents=!0,this.intent=!1}setIntent(e){return this.intent=e,this}isIntent(e){return!0!==e.getDataFromNode(this).forceDeclaration&&this.intent}getIntent(){return this.intent}getMemberType(e,t){return this.node.getMemberType(e,t)}getElementType(e){return this.node.getElementType(e)}getNodeType(e){return this.node.getNodeType(e)}getArrayCount(e){return this.node.getArrayCount(e)}isAssign(e){return e.getDataFromNode(this).assign}build(...e){const t=e[0];if(!1===this._hasStack(t)&&"setup"===t.buildStage&&(t.context.nodeLoop||t.context.nodeBlock)){let e=!1;if(this.node.isShaderCallNodeInternal&&null===this.node.shaderNode.getLayout()&&t.fnCall&&t.fnCall.shaderNode){if(t.getDataFromNode(this.node.shaderNode).hasLoop){t.getDataFromNode(this).forceDeclaration=!0,e=!0}}const r=t.getBaseStack();e?r.addToStackBefore(this):r.addToStack(this)}return this.isIntent(t)&&!0!==this.isAssign(t)?this.node.build(...e):super.build(...e)}generate(e){const{node:t,name:r,readOnly:s}=this,{renderer:i}=e,n=!0===i.backend.isWebGPUBackend;let a=!1,u=!1;s&&(a=e.isDeterministic(t),u=n?s:a);const l=this.getNodeType(e);if("void"==l){!0!==this.isIntent(e)&&o('TSL: ".toVar()" can not be used with void type.',this.stackTrace);return t.build(e)}const d=e.getVectorType(l),c=t.build(e,d),h=e.getVarFromNode(this,r,d,void 0,u),p=e.getPropertyName(h);let g=p;if(u)if(n)g=a?`const ${p}`:`let ${p}`;else{const r=t.getArrayCount(e);g=`const ${e.getVar(h.type,p,r)}`}return e.addLineFlowCode(`${g} = ${c}`,this),p}_hasStack(e){return void 0!==e.getDataFromNode(this).stack}}const wu=sn(Au),Cu=(e,t=null)=>wu(e,t).toStack(),Mu=(e,t=null)=>wu(e,t,!0).toStack(),Bu=e=>wu(e).setIntent(!0).toStack();Si("toVar",Cu),Si("toConst",Mu),Si("toVarIntent",Bu);class Fu extends li{static get type(){return"SubBuild"}constructor(e,t,r=null){super(r),this.node=e,this.name=t,this.isSubBuildNode=!0}getNodeType(e){if(null!==this.nodeType)return this.nodeType;e.addSubBuild(this.name);const t=this.node.getNodeType(e);return e.removeSubBuild(),t}build(e,...t){e.addSubBuild(this.name);const r=this.node.build(e,...t);return e.removeSubBuild(),r}}const Lu=(e,t,r=null)=>new Fu(Ji(e),t,r);class Pu extends li{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=Lu(e,"VERTEX"),this.name=t,this.isVaryingNode=!0,this.interpolationType=null,this.interpolationSampling=null,this.global=!0}setInterpolation(e,t=null){return this.interpolationType=e,this.interpolationSampling=t,this}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let r=t.varying;if(void 0===r){const s=this.name,i=this.getNodeType(e),n=this.interpolationType,a=this.interpolationSampling;t.varying=r=e.getVaryingFromNode(this,s,i,n,a),t.node=Lu(this.node,"VERTEX")}return r.needsInterpolation||(r.needsInterpolation="fragment"===e.shaderStage),r}setup(e){this.setupVarying(e),e.flowNodeFromShaderStage(Js.VERTEX,this.node)}analyze(e){this.setupVarying(e),e.flowNodeFromShaderStage(Js.VERTEX,this.node)}generate(e){const t=e.getSubBuildProperty("property",e.currentStack),r=e.getNodeProperties(this),s=this.setupVarying(e);if(void 0===r[t]){const i=this.getNodeType(e),n=e.getPropertyName(s,Js.VERTEX);e.flowNodeFromShaderStage(Js.VERTEX,r.node,i,n),r[t]=n}return e.getPropertyName(s)}}const Du=sn(Pu).setParameterLength(1,2),Uu=e=>Du(e);Si("toVarying",Du),Si("toVertexStage",Uu);const Iu=ln(([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),r=e.mul(.0773993808),s=e.lessThanEqual(.04045);return au(t,r,s)}).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ou=ln(([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),r=e.mul(12.92),s=e.lessThanEqual(.0031308);return au(t,r,s)}).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Vu="WorkingColorSpace";class ku extends hi{static get type(){return"ColorSpaceNode"}constructor(e,t,r){super("vec4"),this.colorNode=e,this.source=t,this.target=r}resolveColorSpace(e,t){return t===Vu?p.workingColorSpace:"OutputColorSpace"===t?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,r=this.resolveColorSpace(e,this.source),s=this.resolveColorSpace(e,this.target);let i=t;return!1!==p.enabled&&r!==s&&r&&s?(p.getTransfer(r)===g&&(i=An(Iu(i.rgb),i.a)),p.getPrimaries(r)!==p.getPrimaries(s)&&(i=An(Fn(p._getMatrix(new n,r,s)).mul(i.rgb),i.a)),p.getTransfer(s)===g&&(i=An(Ou(i.rgb),i.a)),i):i}}const Gu=(e,t)=>new ku(Ji(e),Vu,t),$u=(e,t)=>new ku(Ji(e),t,Vu);Si("workingToColorSpace",Gu),Si("colorSpaceToWorking",$u);let zu=class extends di{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),r=this.referenceNode.getNodeType(),s=this.getNodeType();return e.format(t,r,s)}};class Wu extends li{static get type(){return"ReferenceBaseNode"}constructor(e,t,r=null,s=null){super(),this.property=e,this.uniformType=t,this.object=r,this.count=s,this.properties=e.split("."),this.reference=r,this.node=null,this.group=null,this.updateType=ei.OBJECT}setGroup(e){return this.group=e,this}element(e){return new zu(this,Ji(e))}setNodeType(e){const t=va(null,e);null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let r=e[t[0]];for(let e=1;e<t.length;e++)r=r[t[e]];return r}updateReference(e){return this.reference=null!==this.object?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);const e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}class Hu extends Wu{static get type(){return"RendererReferenceNode"}constructor(e,t,r=null){super(e,t,r),this.renderer=r,this.setGroup(xa)}updateReference(e){return this.reference=null!==this.renderer?this.renderer:e.renderer,this.reference}}const qu=(e,t,r=null)=>new Hu(e,t,r);class ju extends hi{static get type(){return"ToneMappingNode"}constructor(e,t=Ku,r=null){super("vec3"),this._toneMapping=e,this.exposureNode=t,this.colorNode=r}customCacheKey(){return Vs(this._toneMapping)}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup(e){const t=this.colorNode||e.context.color,r=this._toneMapping;if(r===m)return t;let s=null;const i=e.renderer.library.getToneMappingFunction(r);return null!==i?s=An(i(t.rgb,this.exposureNode),t.a):(o("ToneMappingNode: Unsupported Tone Mapping configuration.",r),s=t),s}}const Xu=(e,t,r)=>new ju(e,Ji(t),Ji(r)),Ku=qu("toneMappingExposure","float");Si("toneMapping",(e,t,r)=>Xu(t,r,e));const Yu=new WeakMap;function Qu(e,t){let r=Yu.get(e);return void 0===r&&(r=new b(e,t),Yu.set(e,r)),r}class Zu extends bi{static get type(){return"BufferAttributeNode"}constructor(e,t=null,r=0,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=r,this.bufferOffset=s,this.usage=f,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&e.itemSize<=4&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;const t=this.getNodeType(e),r=e.getTypeLength(t),s=this.value,i=this.bufferStride||r,n=this.bufferOffset;let a;a=!0===s.isInterleavedBuffer?s:!0===s.isBufferAttribute?Qu(s.array,i):Qu(s,i);const o=new y(a,r,n);a.setUsage(this.usage),this.attribute=o,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),r=e.getBufferAttributeFromNode(this,t),s=e.getPropertyName(r);let i=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=s,i=s;else{i=Du(this).build(e,t)}return i}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}function Ju(e,t=null,r=0,s=0,i=f,n=!1){return"mat3"===t||null===t&&9===e.itemSize?Fn(new Zu(e,"vec3",9,0).setUsage(i).setInstanced(n),new Zu(e,"vec3",9,3).setUsage(i).setInstanced(n),new Zu(e,"vec3",9,6).setUsage(i).setInstanced(n)):"mat4"===t||null===t&&16===e.itemSize?Ln(new Zu(e,"vec4",16,0).setUsage(i).setInstanced(n),new Zu(e,"vec4",16,4).setUsage(i).setInstanced(n),new Zu(e,"vec4",16,8).setUsage(i).setInstanced(n),new Zu(e,"vec4",16,12).setUsage(i).setInstanced(n)):new Zu(e,t,r,s).setUsage(i)}const el=(e,t=null,r=0,s=0)=>Ju(e,t,r,s),tl=(e,t=null,r=0,s=0)=>Ju(e,t,r,s,f,!0),rl=(e,t=null,r=0,s=0)=>Ju(e,t,r,s,x,!0);Si("toAttribute",e=>el(e.value));class sl extends li{static get type(){return"ComputeNode"}constructor(e,t){super("void"),this.isComputeNode=!0,this.computeNode=e,this.workgroupSize=t,this.count=null,this.version=1,this.name="",this.updateBeforeType=ei.OBJECT,this.onInitFunction=null}setCount(e){return this.count=e,this}getCount(){return this.count}dispose(){this.dispatchEvent({type:"dispose"})}setName(e){return this.name=e,this}label(e){return d('TSL: "label()" has been deprecated. Use "setName()" instead.',new Ds),this.setName(e)}onInit(e){return this.onInitFunction=e,this}updateBefore({renderer:e}){e.compute(this)}setup(e){const t=this.computeNode.build(e);if(t){e.getNodeProperties(this).outputComputeNode=t.outputNode,t.outputNode=null}return t}generate(e,t){const{shaderStage:r}=e;if("compute"===r){const t=this.computeNode.build(e,"void");""!==t&&e.addLineFlowCode(t,this)}else{const r=e.getNodeProperties(this).outputComputeNode;if(r)return r.build(e,t)}}}const il=(e,t=[64])=>{(0===t.length||t.length>3)&&o("TSL: compute() workgroupSize must have 1, 2, or 3 elements",new Ds);for(let e=0;e<t.length;e++){const r=t[e];("number"!=typeof r||r<=0||!Number.isInteger(r))&&o(`TSL: compute() workgroupSize element at index [ ${e} ] must be a positive integer`,new Ds)}for(;t.length<3;)t.push(1);return new sl(Ji(e),t)},nl=(e,t,r)=>il(e,r).setCount(t);Si("compute",nl),Si("computeKernel",il);class al extends li{static get type(){return"IsolateNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isIsolateNode=!0}getNodeType(e){const t=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);const s=this.node.getNodeType(e);return e.setCache(t),s}build(e,...t){const r=e.getCache(),s=e.getCacheFromNode(this,this.parent);e.setCache(s);const i=this.node.build(e,...t);return e.setCache(r),i}setParent(e){return this.parent=e,this}getParent(){return this.parent}}const ol=e=>new al(Ji(e));function ul(e,t=!0){return d('TSL: "cache()" has been deprecated. Use "isolate()" instead.'),ol(e).setParent(t)}Si("cache",ul),Si("isolate",ol);class ll extends li{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const dl=sn(ll).setParameterLength(2);Si("bypass",dl);class cl extends li{static get type(){return"RemapNode"}constructor(e,t,r,s=mn(0),i=mn(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=r,this.outLowNode=s,this.outHighNode=i,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:r,outLowNode:s,outHighNode:i,doClamp:n}=this;let a=e.sub(t).div(r.sub(t));return!0===n&&(a=a.clamp()),a.mul(i.sub(s)).add(s)}}const hl=sn(cl,null,null,{doClamp:!1}).setParameterLength(3,5),pl=sn(cl).setParameterLength(3,5);Si("remap",hl),Si("remapClamp",pl);class gl extends li{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const r=this.getNodeType(e),s=this.snippet;if("void"!==r)return e.format(s,r,t);e.addLineFlowCode(s,this)}}const ml=sn(gl).setParameterLength(1,2),fl=e=>(e?xu(e,ml("discard")):ml("discard")).toStack();Si("discard",fl);class yl extends hi{static get type(){return"RenderOutputNode"}constructor(e,t,r){super("vec4"),this.colorNode=e,this._toneMapping=t,this.outputColorSpace=r,this.isRenderOutputNode=!0}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup({context:e}){let t=this.colorNode||e.color;const r=(null!==this._toneMapping?this._toneMapping:e.toneMapping)||m,s=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||T;return r!==m&&(t=t.toneMapping(r)),s!==T&&s!==p.workingColorSpace&&(t=t.workingToColorSpace(s)),t}}const bl=(e,t=null,r=null)=>new yl(Ji(e),t,r);Si("renderOutput",bl);class xl extends hi{static get type(){return"DebugNode"}constructor(e,t=null){super(),this.node=e,this.callback=t}getNodeType(e){return this.node.getNodeType(e)}setup(e){return this.node.build(e)}analyze(e){return this.node.build(e)}generate(e){const t=this.callback,r=this.node.build(e);if(null!==t)t(e,r);else{const t="--- TSL debug - "+e.shaderStage+" shader ---",s="-".repeat(t.length);let i="";i+="// #"+t+"#\n",i+=e.flow.code.replace(/^\t/gm,"")+"\n",i+="/* ... */ "+r+" /* ... */\n",i+="// #"+s+"#\n",_(i)}return r}}const Tl=(e,t=null)=>new xl(Ji(e),t).toStack();Si("debug",Tl);class _l{constructor(){this._renderer=null,this.currentFrame=null}get nodeFrame(){return this._renderer._nodes.nodeFrame}setRenderer(e){return this._renderer=e,this}getRenderer(){return this._renderer}init(){}begin(){}finish(){}inspect(){}computeAsync(){}beginCompute(){}finishCompute(){}beginRender(){}finishRender(){}copyTextureToTexture(){}copyFramebufferToTexture(){}}class vl extends li{static get type(){return"InspectorNode"}constructor(e,t="",r=null){super(),this.node=e,this.name=t,this.callback=r,this.updateType=ei.FRAME,this.isInspectorNode=!0}getName(){return this.name||this.node.name}update(e){e.renderer.inspector.inspect(this)}getNodeType(e){return this.node.getNodeType(e)}setup(e){let t=this.node;return!0===e.context.inspector&&null!==this.callback&&(t=this.callback(t)),!0!==e.renderer.backend.isWebGPUBackend&&e.renderer.inspector.constructor!==_l&&v('TSL: ".toInspector()" is only available with WebGPU.'),t}}function Nl(e,t="",r=null){return(e=Ji(e)).before(new vl(e,t,r))}Si("toInspector",Nl);class Sl extends li{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){const r=this.getAttributeName(e);if(e.hasGeometryAttribute(r)){const s=e.geometry.getAttribute(r);t=e.getTypeFromAttribute(s)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),r=this.getNodeType(e);if(!0===e.hasGeometryAttribute(t)){const s=e.geometry.getAttribute(t),i=e.getTypeFromAttribute(s),n=e.getAttribute(t,i);if("vertex"===e.shaderStage)return e.format(n.name,i,r);return Du(this).build(e,r)}return d(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(r)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const Rl=(e,t=null)=>new Sl(e,t),El=(e=0)=>Rl("uv"+(e>0?e:""),"vec2");class Al extends li{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const r=this.textureNode.build(e,"property"),s=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${r}, ${s} )`,this.getNodeType(e),t)}}const wl=sn(Al).setParameterLength(1,2);class Cl extends _a{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=ei.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,r=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(r&&void 0!==r.width){const{width:e,height:t}=r;this.value=Math.log2(Math.max(e,t))}}}const Ml=sn(Cl).setParameterLength(1);class Bl extends Error{constructor(e,t=null){super(e),this.name="NodeError",this.stackTrace=t}}const Fl=new N;class Ll extends _a{static get type(){return"TextureNode"}constructor(e=Fl,t=null,r=null,s=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=r,this.biasNode=s,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.offsetNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=ei.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this._flipYUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}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===S?"uvec4":this.value.type===R?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return El(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=va(this.value.matrix)),this._matrixUniform.mul(Nn(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this}setupUV(e,t){return e.isFlipY()&&(null===this._flipYUniform&&(this._flipYUniform=va(!1)),t=t.toVar(),t=this.sampler?this._flipYUniform.select(t.flipY(),t):this._flipYUniform.select(t.setY(fn(wl(this,this.levelNode).y).sub(t.y).sub(1)),t)),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;const r=this.value;if(!r||!0!==r.isTexture)throw new Bl("THREE.TSL: `texture( value )` function expects a valid instance of THREE.Texture().",this.stackTrace);const s=ln(()=>{let t=this.uvNode;return null!==t&&!0!==e.context.forceUVContext||!e.context.getUV||(t=e.context.getUV(this,e)),t||(t=this.getDefaultUV()),!0===this.updateMatrix&&(t=this.getTransformedUV(t)),t=this.setupUV(e,t),this.updateType=null!==this._matrixUniform||null!==this._flipYUniform?ei.OBJECT:ei.NONE,t})();let i=this.levelNode;null===i&&e.context.getTextureLevel&&(i=e.context.getTextureLevel(this));let n=null,a=null;if(null!==this.compareNode)if(e.renderer.hasCompatibility(E.TEXTURE_COMPARE))n=this.compareNode;else{const e=r.compareFunction;null===e||e===A||e===w||e===C||e===M?a=this.compareNode:(n=this.compareNode,v('TSL: Only "LessCompare", "LessEqualCompare", "GreaterCompare" and "GreaterEqualCompare" are supported for depth texture comparison fallback.'))}t.uvNode=s,t.levelNode=i,t.biasNode=this.biasNode,t.compareNode=n,t.compareStepNode=a,t.gradNode=this.gradNode,t.depthNode=this.depthNode,t.offsetNode=this.offsetNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateOffset(e,t){return t.build(e,"ivec2")}generateSnippet(e,t,r,s,i,n,a,o,u){const l=this.value;let d;return d=i?e.generateTextureBias(l,t,r,i,n,u):o?e.generateTextureGrad(l,t,r,o,n,u):a?e.generateTextureCompare(l,t,r,a,n,u):!1===this.sampler?e.generateTextureLoad(l,t,r,s,n,u):s?e.generateTextureLevel(l,t,r,s,n,u):e.generateTexture(l,t,r,n,u),d}generate(e,t){const r=this.value,s=e.getNodeProperties(this),i=super.generate(e,"property");if(/^sampler/.test(t))return i+"_sampler";if(e.isReference(t))return i;{const n=e.getDataFromNode(this),a=this.getNodeType(e);let o=n.propertyName;if(void 0===o){const{uvNode:t,levelNode:u,biasNode:l,compareNode:d,compareStepNode:c,depthNode:h,gradNode:p,offsetNode:g}=s,m=this.generateUV(e,t),f=u?u.build(e,"float"):null,y=l?l.build(e,"float"):null,b=h?h.build(e,"int"):null,x=d?d.build(e,"float"):null,T=c?c.build(e,"float"):null,_=p?[p[0].build(e,"vec2"),p[1].build(e,"vec2")]:null,v=g?this.generateOffset(e,g):null,N=e.getVarFromNode(this);o=e.getPropertyName(N);let S=this.generateSnippet(e,i,m,f,y,b,x,_,v);if(null!==T){const t=r.compareFunction;S=t===C||t===M?jo(ml(S,a),ml(T,"float")).build(e,a):jo(ml(T,"float"),ml(S,a)).build(e,a)}e.addLineFlowCode(`${o} = ${S}`,this),n.snippet=S,n.propertyName=o}let u=o;return e.needsToWorkingColorSpace(r)&&(u=$u(ml(u,a),r.colorSpace).setup(e).build(e,a)),e.format(u,a,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}sample(e){const t=this.clone();return t.uvNode=Ji(e),t.referenceNode=this.getBase(),Ji(t)}load(e){return this.sample(e).setSampler(!1)}blur(e){const t=this.clone();t.biasNode=Ji(e).mul(Ml(t)),t.referenceNode=this.getBase();const r=t.value;return!1===t.generateMipmaps&&(r&&!1===r.generateMipmaps||r.minFilter===B||r.magFilter===B)&&(d("TSL: texture().blur() requires mipmaps and sampling. Use .generateMipmaps=true and .minFilter/.magFilter=THREE.LinearFilter in the Texture."),t.biasNode=null),Ji(t)}level(e){const t=this.clone();return t.levelNode=Ji(e),t.referenceNode=this.getBase(),Ji(t)}size(e){return wl(this,e)}bias(e){const t=this.clone();return t.biasNode=Ji(e),t.referenceNode=this.getBase(),Ji(t)}getBase(){return this.referenceNode?this.referenceNode.getBase():this}compare(e){const t=this.clone();return t.compareNode=Ji(e),t.referenceNode=this.getBase(),Ji(t)}grad(e,t){const r=this.clone();return r.gradNode=[Ji(e),Ji(t)],r.referenceNode=this.getBase(),Ji(r)}depth(e){const t=this.clone();return t.depthNode=Ji(e),t.referenceNode=this.getBase(),Ji(t)}offset(e){const t=this.clone();return t.offsetNode=Ji(e),t.referenceNode=this.getBase(),Ji(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix();const r=this._flipYUniform;null!==r&&(r.value=e.image instanceof ImageBitmap&&!0===e.flipY||!0===e.isRenderTargetTexture||!0===e.isFramebufferTexture||!0===e.isDepthTexture)}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.offsetNode=this.offsetNode,e}}const Pl=sn(Ll).setParameterLength(1,4).setName("texture"),Dl=(e=Fl,t=null,r=null,s=null)=>{let i;return e&&!0===e.isTextureNode?(i=Ji(e.clone()),i.referenceNode=e.getBase(),null!==t&&(i.uvNode=Ji(t)),null!==r&&(i.levelNode=Ji(r)),null!==s&&(i.biasNode=Ji(s))):i=Pl(e,t,r,s),i},Ul=(...e)=>Dl(...e).setSampler(!1);class Il extends _a{static get type(){return"BufferNode"}constructor(e,t,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=r,this.updateRanges=[]}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const Ol=(e,t,r)=>new Il(e,t,r);class Vl extends di{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),r=this.getNodeType(),s=this.node.getPaddedType();return e.format(t,s,r)}}class kl extends Il{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null),this.array=e,this.elementType=null===t?js(e[0]):t,this.paddedType=this.getPaddedType(),this.updateType=ei.RENDER,this.isArrayBufferNode=!0}getNodeType(){return this.paddedType}getElementType(){return this.elementType}getPaddedType(){const e=this.elementType;let t="vec4";return"mat2"===e?t="mat2":!0===/mat/.test(e)?t="mat4":"i"===e.charAt(0)?t="ivec4":"u"===e.charAt(0)&&(t="uvec4"),t}update(){const{array:e,value:t}=this,r=this.elementType;if("float"===r||"int"===r||"uint"===r)for(let r=0;r<e.length;r++){t[4*r]=e[r]}else if("color"===r)for(let r=0;r<e.length;r++){const s=4*r,i=e[r];t[s]=i.r,t[s+1]=i.g,t[s+2]=i.b||0}else if("mat2"===r)for(let r=0;r<e.length;r++){const s=4*r,i=e[r];t[s]=i.elements[0],t[s+1]=i.elements[1],t[s+2]=i.elements[2],t[s+3]=i.elements[3]}else if("mat3"===r)for(let r=0;r<e.length;r++){const s=16*r,i=e[r];t[s]=i.elements[0],t[s+1]=i.elements[1],t[s+2]=i.elements[2],t[s+4]=i.elements[3],t[s+5]=i.elements[4],t[s+6]=i.elements[5],t[s+8]=i.elements[6],t[s+9]=i.elements[7],t[s+10]=i.elements[8],t[s+15]=1}else if("mat4"===r)for(let r=0;r<e.length;r++){const s=16*r,i=e[r];for(let e=0;e<i.elements.length;e++)t[s+e]=i.elements[e]}else for(let r=0;r<e.length;r++){const s=4*r,i=e[r];t[s]=i.x,t[s+1]=i.y,t[s+2]=i.z||0,t[s+3]=i.w||0}}setup(e){const t=this.array.length,r=this.elementType;let s=Float32Array;const i=this.paddedType,n=e.getTypeLength(i);return"i"===r.charAt(0)&&(s=Int32Array),"u"===r.charAt(0)&&(s=Uint32Array),this.value=new s(t*n),this.bufferCount=t,this.bufferType=i,this.update(),super.setup(e)}element(e){return new Vl(this,Ji(e))}}const Gl=(e,t)=>new kl(e,t);class $l extends li{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}}const zl=sn($l).setParameterLength(1);let Wl,Hl;class ql extends li{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this._output=null,this.isViewportNode=!0}getNodeType(){return this.scope===ql.DPR?"float":this.scope===ql.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=ei.NONE;return this.scope!==ql.SIZE&&this.scope!==ql.VIEWPORT&&this.scope!==ql.DPR||(e=ei.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===ql.VIEWPORT?null!==t?Hl.copy(t.viewport):(e.getViewport(Hl),Hl.multiplyScalar(e.getPixelRatio())):this.scope===ql.DPR?this._output.value=e.getPixelRatio():null!==t?(Wl.width=t.width,Wl.height=t.height):e.getDrawingBufferSize(Wl)}setup(){const e=this.scope;let r=null;return r=e===ql.SIZE?va(Wl||(Wl=new t)):e===ql.VIEWPORT?va(Hl||(Hl=new s)):e===ql.DPR?va(1):xn(Yl.div(Kl)),this._output=r,r}generate(e){if(this.scope===ql.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const r=e.getNodeProperties(Kl).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${r}.y - ${t}.y )`}return t}return super.generate(e)}}ql.COORDINATE="coordinate",ql.VIEWPORT="viewport",ql.SIZE="size",ql.UV="uv",ql.DPR="dpr";const jl=nn(ql,ql.DPR),Xl=nn(ql,ql.UV),Kl=nn(ql,ql.SIZE),Yl=nn(ql,ql.COORDINATE),Ql=nn(ql,ql.VIEWPORT),Zl=Ql.zw,Jl=Yl.sub(Ql.xy),ed=Jl.div(Zl),td=ln(()=>(d('TSL: "viewportResolution" is deprecated. Use "screenSize" instead.',new Ds),Kl),"vec2").once()();let rd=null,sd=null,id=null,nd=null,ad=null,od=null,ud=null,ld=null,dd=null,cd=null,hd=null,pd=null,gd=null,md=null;const fd=va(0,"uint").setName("u_cameraIndex").setGroup(ya("cameraIndex")).toVarying("v_cameraIndex"),yd=va("float").setName("cameraNear").setGroup(xa).onRenderUpdate(({camera:e})=>e.near),bd=va("float").setName("cameraFar").setGroup(xa).onRenderUpdate(({camera:e})=>e.far),xd=ln(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){const r=[];for(const t of e.cameras)r.push(t.projectionMatrix);null===sd?sd=Gl(r).setGroup(xa).setName("cameraProjectionMatrices"):sd.array=r,t=sd.element(e.isMultiViewCamera?zl("gl_ViewID_OVR"):fd).toConst("cameraProjectionMatrix")}else null===rd&&(rd=va(e.projectionMatrix).setName("cameraProjectionMatrix").setGroup(xa).onRenderUpdate(({camera:e})=>e.projectionMatrix)),t=rd;return t}).once()(),Td=ln(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){const r=[];for(const t of e.cameras)r.push(t.projectionMatrixInverse);null===nd?nd=Gl(r).setGroup(xa).setName("cameraProjectionMatricesInverse"):nd.array=r,t=nd.element(e.isMultiViewCamera?zl("gl_ViewID_OVR"):fd).toConst("cameraProjectionMatrixInverse")}else null===id&&(id=va(e.projectionMatrixInverse).setName("cameraProjectionMatrixInverse").setGroup(xa).onRenderUpdate(({camera:e})=>e.projectionMatrixInverse)),t=id;return t}).once()(),_d=ln(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){const r=[];for(const t of e.cameras)r.push(t.matrixWorldInverse);null===od?od=Gl(r).setGroup(xa).setName("cameraViewMatrices"):od.array=r,t=od.element(e.isMultiViewCamera?zl("gl_ViewID_OVR"):fd).toConst("cameraViewMatrix")}else null===ad&&(ad=va(e.matrixWorldInverse).setName("cameraViewMatrix").setGroup(xa).onRenderUpdate(({camera:e})=>e.matrixWorldInverse)),t=ad;return t}).once()(),vd=ln(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){const r=[];for(const t of e.cameras)r.push(t.matrixWorld);null===ld?ld=Gl(r).setGroup(xa).setName("cameraWorldMatrices"):ld.array=r,t=ld.element(e.isMultiViewCamera?zl("gl_ViewID_OVR"):fd).toConst("cameraWorldMatrix")}else null===ud&&(ud=va(e.matrixWorld).setName("cameraWorldMatrix").setGroup(xa).onRenderUpdate(({camera:e})=>e.matrixWorld)),t=ud;return t}).once()(),Nd=ln(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){const r=[];for(const t of e.cameras)r.push(t.normalMatrix);null===cd?cd=Gl(r).setGroup(xa).setName("cameraNormalMatrices"):cd.array=r,t=cd.element(e.isMultiViewCamera?zl("gl_ViewID_OVR"):fd).toConst("cameraNormalMatrix")}else null===dd&&(dd=va(e.normalMatrix).setName("cameraNormalMatrix").setGroup(xa).onRenderUpdate(({camera:e})=>e.normalMatrix)),t=dd;return t}).once()(),Sd=ln(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){const s=[];for(let t=0,i=e.cameras.length;t<i;t++)s.push(new r);null===pd?pd=Gl(s).setGroup(xa).setName("cameraPositions").onRenderUpdate(({camera:e},t)=>{const r=e.cameras,s=t.array;for(let e=0,t=r.length;e<t;e++)s[e].setFromMatrixPosition(r[e].matrixWorld)}):pd.array=s,t=pd.element(e.isMultiViewCamera?zl("gl_ViewID_OVR"):fd).toConst("cameraPosition")}else null===hd&&(hd=va(new r).setName("cameraPosition").setGroup(xa).onRenderUpdate(({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld))),t=hd;return t}).once()(),Rd=ln(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){const r=[];for(const t of e.cameras)r.push(t.viewport);null===md?md=Gl(r,"vec4").setGroup(xa).setName("cameraViewports"):md.array=r,t=md.element(fd).toConst("cameraViewport")}else null===gd&&(gd=An(0,0,Kl.x,Kl.y).toConst("cameraViewport")),t=gd;return t}).once()(),Ed=new F;class Ad extends li{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=ei.OBJECT,this.uniformNode=new _a(null)}getNodeType(){const e=this.scope;return e===Ad.WORLD_MATRIX?"mat4":e===Ad.POSITION||e===Ad.VIEW_POSITION||e===Ad.DIRECTION||e===Ad.SCALE?"vec3":e===Ad.RADIUS?"float":void 0}update(e){const t=this.object3d,s=this.uniformNode,i=this.scope;if(i===Ad.WORLD_MATRIX)s.value=t.matrixWorld;else if(i===Ad.POSITION)s.value=s.value||new r,s.value.setFromMatrixPosition(t.matrixWorld);else if(i===Ad.SCALE)s.value=s.value||new r,s.value.setFromMatrixScale(t.matrixWorld);else if(i===Ad.DIRECTION)s.value=s.value||new r,t.getWorldDirection(s.value);else if(i===Ad.VIEW_POSITION){const i=e.camera;s.value=s.value||new r,s.value.setFromMatrixPosition(t.matrixWorld),s.value.applyMatrix4(i.matrixWorldInverse)}else if(i===Ad.RADIUS){const r=e.object.geometry;null===r.boundingSphere&&r.computeBoundingSphere(),Ed.copy(r.boundingSphere).applyMatrix4(t.matrixWorld),s.value=Ed.radius}}generate(e){const t=this.scope;return t===Ad.WORLD_MATRIX?this.uniformNode.nodeType="mat4":t===Ad.POSITION||t===Ad.VIEW_POSITION||t===Ad.DIRECTION||t===Ad.SCALE?this.uniformNode.nodeType="vec3":t===Ad.RADIUS&&(this.uniformNode.nodeType="float"),this.uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}Ad.WORLD_MATRIX="worldMatrix",Ad.POSITION="position",Ad.SCALE="scale",Ad.VIEW_POSITION="viewPosition",Ad.DIRECTION="direction",Ad.RADIUS="radius";const wd=sn(Ad,Ad.DIRECTION).setParameterLength(1),Cd=sn(Ad,Ad.WORLD_MATRIX).setParameterLength(1),Md=sn(Ad,Ad.POSITION).setParameterLength(1),Bd=sn(Ad,Ad.SCALE).setParameterLength(1),Fd=sn(Ad,Ad.VIEW_POSITION).setParameterLength(1),Ld=sn(Ad,Ad.RADIUS).setParameterLength(1);class Pd extends Ad{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const Dd=nn(Pd,Pd.DIRECTION),Ud=nn(Pd,Pd.WORLD_MATRIX),Id=nn(Pd,Pd.POSITION),Od=nn(Pd,Pd.SCALE),Vd=nn(Pd,Pd.VIEW_POSITION),kd=nn(Pd,Pd.RADIUS),Gd=va(new n).onObjectUpdate(({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld)),$d=va(new a).onObjectUpdate(({object:e},t)=>t.value.copy(e.matrixWorld).invert()),zd=ln(e=>e.context.modelViewMatrix||Wd).once()().toVar("modelViewMatrix_2"),Wd=_d.mul(Ud),Hd=ln(e=>(e.context.isHighPrecisionModelViewMatrix=!0,va("mat4").onObjectUpdate(({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))).once()().toVar("highpModelViewMatrix"),qd=ln(e=>{const t=e.context.isHighPrecisionModelViewMatrix;return va("mat3").onObjectUpdate(({object:e,camera:r})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix)))}).once()().toVar("highpModelNormalViewMatrix"),jd=ln(e=>"fragment"!==e.shaderStage?(v("TSL: `clipSpace` is only available in fragment stage."),An()):e.context.clipSpace.toVarying("v_clipSpace")).once()(),Xd=Rl("position","vec3"),Kd=Xd.toVarying("positionLocal"),Yd=Xd.toVarying("positionPrevious"),Qd=ln(e=>Ud.mul(Kd).xyz.toVarying(e.getSubBuildProperty("v_positionWorld")),"vec3").once(["POSITION"])(),Zd=ln(()=>Kd.transformDirection(Ud).toVarying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),"vec3").once(["POSITION"])(),Jd=ln(e=>{if("fragment"===e.shaderStage&&e.material.vertexNode){const e=Td.mul(jd);return e.xyz.div(e.w).toVar("positionView")}return e.context.setupPositionView().toVarying("v_positionView")},"vec3").once(["POSITION","VERTEX"])(),ec=ln(e=>{let t;return t=e.camera.isOrthographicCamera?Nn(0,0,1):Jd.negate().toVarying("v_positionViewDirection").normalize(),t.toVar("positionViewDirection")},"vec3").once(["POSITION"])();class tc extends li{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){if("fragment"!==e.shaderStage)return"true";const{material:t}=e;return t.side===L?"false":e.getFrontFacing()}}const rc=nn(tc),sc=mn(rc).mul(2).sub(1),ic=ln(([e],{material:t})=>{const r=t.side;return r===L?e=e.mul(-1):r===P&&(e=e.mul(sc)),e}),nc=Rl("normal","vec3"),ac=ln(e=>!1===e.geometry.hasAttribute("normal")?(d('TSL: Vertex attribute "normal" not found on geometry.'),Nn(0,1,0)):nc,"vec3").once()().toVar("normalLocal"),oc=Jd.dFdx().cross(Jd.dFdy()).normalize().toVar("normalFlat"),uc=ln(e=>{let t;return t=e.isFlatShading()?oc:gc(ac).toVarying("v_normalViewGeometry").normalize(),t},"vec3").once()().toVar("normalViewGeometry"),lc=ln(e=>{let t=uc.transformDirection(_d);return!0!==e.isFlatShading()&&(t=t.toVarying("v_normalWorldGeometry")),t.normalize().toVar("normalWorldGeometry")},"vec3").once()(),dc=ln(e=>{let t;return"NORMAL"===e.subBuildFn||"VERTEX"===e.subBuildFn?(t=uc,!0!==e.isFlatShading()&&(t=ic(t))):t=e.context.setupNormal().context({getUV:null,getTextureLevel:null}),t},"vec3").once(["NORMAL","VERTEX"])().toVar("normalView"),cc=dc.transformDirection(_d).toVar("normalWorld"),hc=ln(({subBuildFn:e,context:t})=>{let r;return r="NORMAL"===e||"VERTEX"===e?dc:t.setupClearcoatNormal().context({getUV:null,getTextureLevel:null}),r},"vec3").once(["NORMAL","VERTEX"])().toVar("clearcoatNormalView"),pc=ln(([e,t=Ud])=>{const r=Fn(t),s=e.div(Nn(r[0].dot(r[0]),r[1].dot(r[1]),r[2].dot(r[2])));return r.mul(s).xyz}),gc=ln(([e],t)=>{const r=t.context.modelNormalViewMatrix;if(r)return r.transformDirection(e);const s=Gd.mul(e);return _d.transformDirection(s)}),mc=ln(()=>(d('TSL: "transformedNormalView" is deprecated. Use "normalView" instead.'),dc)).once(["NORMAL","VERTEX"])(),fc=ln(()=>(d('TSL: "transformedNormalWorld" is deprecated. Use "normalWorld" instead.'),cc)).once(["NORMAL","VERTEX"])(),yc=ln(()=>(d('TSL: "transformedClearcoatNormalView" is deprecated. Use "clearcoatNormalView" instead.'),hc)).once(["NORMAL","VERTEX"])(),bc=new D,xc=new a,Tc=va(0).onReference(({material:e})=>e).onObjectUpdate(({material:e})=>e.refractionRatio),_c=va(1).onReference(({material:e})=>e).onObjectUpdate(function({material:e,scene:t}){return e.envMap?e.envMapIntensity:t.environmentIntensity}),vc=va(new a).onReference(function(e){return e.material}).onObjectUpdate(function({material:e,scene:t}){const r=null!==t.environment&&null===e.envMap?t.environmentRotation:e.envMapRotation;return r?(bc.copy(r),xc.makeRotationFromEuler(bc)):xc.identity(),xc}),Nc=ec.negate().reflect(dc),Sc=ec.negate().refract(dc,Tc),Rc=Nc.transformDirection(_d).toVar("reflectVector"),Ec=Sc.transformDirection(_d).toVar("reflectVector"),Ac=new U;class wc extends Ll{static get type(){return"CubeTextureNode"}constructor(e,t=null,r=null,s=null){super(e,t,r,s),this.isCubeTextureNode=!0}getInputType(){return!0===this.value.isDepthTexture?"cubeDepthTexture":"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===I?Rc:e.mapping===O?Ec:(o('CubeTextureNode: Mapping "%s" not supported.',e.mapping),Nn(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const r=this.value;return!0===r.isDepthTexture?e.renderer.coordinateSystem===h?Nn(t.x,t.y.negate(),t.z):t:(e.renderer.coordinateSystem!==h&&r.isRenderTargetTexture||(t=Nn(t.x.negate(),t.yz)),vc.mul(t))}generateUV(e,t){return t.build(e,!0===this.sampler?"vec3":"ivec3")}}const Cc=sn(wc).setParameterLength(1,4).setName("cubeTexture"),Mc=(e=Ac,t=null,r=null,s=null)=>{let i;return e&&!0===e.isCubeTextureNode?(i=Ji(e.clone()),i.referenceNode=e,null!==t&&(i.uvNode=Ji(t)),null!==r&&(i.levelNode=Ji(r)),null!==s&&(i.biasNode=Ji(s))):i=Cc(e,t,r,s),i};class Bc extends di{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),r=this.referenceNode.getNodeType(),s=this.getNodeType();return e.format(t,r,s)}}class Fc extends li{static get type(){return"ReferenceNode"}constructor(e,t,r=null,s=null){super(),this.property=e,this.uniformType=t,this.object=r,this.count=s,this.properties=e.split("."),this.reference=r,this.node=null,this.group=null,this.name=null,this.updateType=ei.OBJECT}element(e){return new Bc(this,Ji(e))}setGroup(e){return this.group=e,this}setName(e){return this.name=e,this}label(e){return d('TSL: "label()" has been deprecated. Use "setName()" instead.'),this.setName(e)}setNodeType(e){let t=null;t=null!==this.count?Ol(null,e,this.count):Array.isArray(this.getValueFromReference())?Gl(null,e):"texture"===e?Dl(null):"cubeTexture"===e?Mc(null):va(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.setName(this.name),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let r=e[t[0]];for(let e=1;e<t.length;e++)r=r[t[e]];return r}updateReference(e){return this.reference=null!==this.object?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);const e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}const Lc=(e,t,r)=>new Fc(e,t,r),Pc=(e,t,r,s)=>new Fc(e,t,s,r);class Dc extends Fc{static get type(){return"MaterialReferenceNode"}constructor(e,t,r=null){super(e,t,r),this.material=r,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}const Uc=(e,t,r=null)=>new Dc(e,t,r),Ic=El(),Oc=Jd.dFdx(),Vc=Jd.dFdy(),kc=Ic.dFdx(),Gc=Ic.dFdy(),$c=dc,zc=Vc.cross($c),Wc=$c.cross(Oc),Hc=zc.mul(kc.x).add(Wc.mul(Gc.x)),qc=zc.mul(kc.y).add(Wc.mul(Gc.y)),jc=Hc.dot(Hc).max(qc.dot(qc)),Xc=jc.equal(0).select(0,jc.inverseSqrt()),Kc=Hc.mul(Xc).toVar("tangentViewFrame"),Yc=qc.mul(Xc).toVar("bitangentViewFrame"),Qc=Rl("tangent","vec4"),Zc=Qc.xyz.toVar("tangentLocal"),Jc=ln(e=>{let t;return t="VERTEX"===e.subBuildFn||e.geometry.hasAttribute("tangent")?zd.mul(An(Zc,0)).xyz.toVarying("v_tangentView").normalize():Kc,!0!==e.isFlatShading()&&(t=ic(t)),t},"vec3").once(["NORMAL","VERTEX"])().toVar("tangentView"),eh=Jc.transformDirection(_d).toVarying("v_tangentWorld").normalize().toVar("tangentWorld"),th=ln(([e,t],r)=>{let s=e.mul(Qc.w).xyz;return"NORMAL"===r.subBuildFn&&!0!==r.isFlatShading()&&(s=s.toVarying(t)),s}).once(["NORMAL"]),rh=th(nc.cross(Qc),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),sh=th(ac.cross(Zc),"v_bitangentLocal").normalize().toVar("bitangentLocal"),ih=ln(e=>{let t;return t="VERTEX"===e.subBuildFn||e.geometry.hasAttribute("tangent")?th(dc.cross(Jc),"v_bitangentView").normalize():Yc,!0!==e.isFlatShading()&&(t=ic(t)),t},"vec3").once(["NORMAL","VERTEX"])().toVar("bitangentView"),nh=th(cc.cross(eh),"v_bitangentWorld").normalize().toVar("bitangentWorld"),ah=Fn(Jc,ih,dc).toVar("TBNViewMatrix"),oh=ec.mul(ah),uh=ln(()=>{let e=ea.cross(ec);return e=e.cross(ea).normalize(),e=au(e,dc,Zn.mul($n.oneMinus()).oneMinus().pow2().pow2()).normalize(),e}).once()(),lh=e=>Ji(e).mul(.5).add(.5),dh=e=>Nn(e,xo(uu(mn(1).sub(Qo(e,e)))));class ch extends hi{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=V,this.unpackNormalMode=k}setup(e){const{normalMapType:t,scaleNode:r,unpackNormalMode:s}=this;let i=this.node.mul(2).sub(1);if(t===V?s===G?i=dh(i.xy):s===$?i=dh(i.yw):s!==k&&console.error(`THREE.NodeMaterial: Unexpected unpack normal mode: ${s}`):s!==k&&console.error(`THREE.NodeMaterial: Normal map type '${t}' is not compatible with unpack normal mode '${s}'`),null!==r){let t=r;!0===e.isFlatShading()&&(t=ic(t)),i=Nn(i.xy.mul(t),i.z)}let n=null;return t===z?n=gc(i):t===V?n=ah.mul(i).normalize():(o(`NodeMaterial: Unsupported normal map type: ${t}`),n=dc),n}}const hh=sn(ch).setParameterLength(1,2),ph=ln(({textureNode:e,bumpScale:t})=>{const r=t=>e.isolate().context({getUV:e=>t(e.uvNode||El()),forceUVContext:!0}),s=mn(r(e=>e));return xn(mn(r(e=>e.add(e.dFdx()))).sub(s),mn(r(e=>e.add(e.dFdy()))).sub(s)).mul(t)}),gh=ln(e=>{const{surf_pos:t,surf_norm:r,dHdxy:s}=e,i=t.dFdx().normalize(),n=r,a=t.dFdy().normalize().cross(n),o=n.cross(i),u=i.dot(a).mul(sc),l=u.sign().mul(s.x.mul(a).add(s.y.mul(o)));return u.abs().mul(r).sub(l).normalize()});class mh extends hi{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=null!==this.scaleNode?this.scaleNode:1,t=ph({textureNode:this.textureNode,bumpScale:e});return gh({surf_pos:Jd,surf_norm:dc,dHdxy:t})}}const fh=sn(mh).setParameterLength(1,2),yh=new Map;class bh extends li{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let r=yh.get(e);return void 0===r&&(r=Uc(e,t),yh.set(e,r)),r}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){const t=e.context.material,r=this.scope;let s=null;if(r===bh.COLOR){const e=void 0!==t.color?this.getColor(r):Nn();s=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(r===bh.OPACITY){const e=this.getFloat(r);s=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(r===bh.SPECULAR_STRENGTH)s=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:mn(1);else if(r===bh.SPECULAR_INTENSITY){const e=this.getFloat(r);s=t.specularIntensityMap&&!0===t.specularIntensityMap.isTexture?e.mul(this.getTexture(r).a):e}else if(r===bh.SPECULAR_COLOR){const e=this.getColor(r);s=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(r).rgb):e}else if(r===bh.ROUGHNESS){const e=this.getFloat(r);s=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(r).g):e}else if(r===bh.METALNESS){const e=this.getFloat(r);s=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(r).b):e}else if(r===bh.EMISSIVE){const e=this.getFloat("emissiveIntensity"),i=this.getColor(r).mul(e);s=t.emissiveMap&&!0===t.emissiveMap.isTexture?i.mul(this.getTexture(r)):i}else if(r===bh.NORMAL)t.normalMap?(s=hh(this.getTexture("normal"),this.getCache("normalScale","vec2")),s.normalMapType=t.normalMapType,t.normalMap.format!=W&&t.normalMap.format!=H&&t.normalMap.format!=q||(s.unpackNormalMode=G)):s=t.bumpMap?fh(this.getTexture("bump").r,this.getFloat("bumpScale")):dc;else if(r===bh.CLEARCOAT){const e=this.getFloat(r);s=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(r).r):e}else if(r===bh.CLEARCOAT_ROUGHNESS){const e=this.getFloat(r);s=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(r).r):e}else if(r===bh.CLEARCOAT_NORMAL)s=t.clearcoatNormalMap?hh(this.getTexture(r),this.getCache(r+"Scale","vec2")):dc;else if(r===bh.SHEEN){const e=this.getColor("sheenColor").mul(this.getFloat("sheen"));s=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(r===bh.SHEEN_ROUGHNESS){const e=this.getFloat(r);s=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(r).a):e,s=s.clamp(1e-4,1)}else if(r===bh.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){const e=this.getTexture(r);s=Bn(rp.x,rp.y,rp.y.negate(),rp.x).mul(e.rg.mul(2).sub(xn(1)).normalize().mul(e.b))}else s=rp;else if(r===bh.IRIDESCENCE_THICKNESS){const e=Lc("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const i=Lc("0","float",t.iridescenceThicknessRange);s=e.sub(i).mul(this.getTexture(r).g).add(i)}else s=e}else if(r===bh.TRANSMISSION){const e=this.getFloat(r);s=t.transmissionMap?e.mul(this.getTexture(r).r):e}else if(r===bh.THICKNESS){const e=this.getFloat(r);s=t.thicknessMap?e.mul(this.getTexture(r).g):e}else if(r===bh.IOR)s=this.getFloat(r);else if(r===bh.LIGHT_MAP)s=this.getTexture(r).rgb.mul(this.getFloat("lightMapIntensity"));else if(r===bh.AO)s=this.getTexture(r).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else if(r===bh.LINE_DASH_OFFSET)s=t.dashOffset?this.getFloat(r):mn(0);else{const t=this.getNodeType(e);s=this.getCache(r,t)}return s}}bh.ALPHA_TEST="alphaTest",bh.COLOR="color",bh.OPACITY="opacity",bh.SHININESS="shininess",bh.SPECULAR="specular",bh.SPECULAR_STRENGTH="specularStrength",bh.SPECULAR_INTENSITY="specularIntensity",bh.SPECULAR_COLOR="specularColor",bh.REFLECTIVITY="reflectivity",bh.ROUGHNESS="roughness",bh.METALNESS="metalness",bh.NORMAL="normal",bh.CLEARCOAT="clearcoat",bh.CLEARCOAT_ROUGHNESS="clearcoatRoughness",bh.CLEARCOAT_NORMAL="clearcoatNormal",bh.EMISSIVE="emissive",bh.ROTATION="rotation",bh.SHEEN="sheen",bh.SHEEN_ROUGHNESS="sheenRoughness",bh.ANISOTROPY="anisotropy",bh.IRIDESCENCE="iridescence",bh.IRIDESCENCE_IOR="iridescenceIOR",bh.IRIDESCENCE_THICKNESS="iridescenceThickness",bh.IOR="ior",bh.TRANSMISSION="transmission",bh.THICKNESS="thickness",bh.ATTENUATION_DISTANCE="attenuationDistance",bh.ATTENUATION_COLOR="attenuationColor",bh.LINE_SCALE="scale",bh.LINE_DASH_SIZE="dashSize",bh.LINE_GAP_SIZE="gapSize",bh.LINE_WIDTH="linewidth",bh.LINE_DASH_OFFSET="dashOffset",bh.POINT_SIZE="size",bh.DISPERSION="dispersion",bh.LIGHT_MAP="light",bh.AO="ao";const xh=nn(bh,bh.ALPHA_TEST),Th=nn(bh,bh.COLOR),_h=nn(bh,bh.SHININESS),vh=nn(bh,bh.EMISSIVE),Nh=nn(bh,bh.OPACITY),Sh=nn(bh,bh.SPECULAR),Rh=nn(bh,bh.SPECULAR_INTENSITY),Eh=nn(bh,bh.SPECULAR_COLOR),Ah=nn(bh,bh.SPECULAR_STRENGTH),wh=nn(bh,bh.REFLECTIVITY),Ch=nn(bh,bh.ROUGHNESS),Mh=nn(bh,bh.METALNESS),Bh=nn(bh,bh.NORMAL),Fh=nn(bh,bh.CLEARCOAT),Lh=nn(bh,bh.CLEARCOAT_ROUGHNESS),Ph=nn(bh,bh.CLEARCOAT_NORMAL),Dh=nn(bh,bh.ROTATION),Uh=nn(bh,bh.SHEEN),Ih=nn(bh,bh.SHEEN_ROUGHNESS),Oh=nn(bh,bh.ANISOTROPY),Vh=nn(bh,bh.IRIDESCENCE),kh=nn(bh,bh.IRIDESCENCE_IOR),Gh=nn(bh,bh.IRIDESCENCE_THICKNESS),$h=nn(bh,bh.TRANSMISSION),zh=nn(bh,bh.THICKNESS),Wh=nn(bh,bh.IOR),Hh=nn(bh,bh.ATTENUATION_DISTANCE),qh=nn(bh,bh.ATTENUATION_COLOR),jh=nn(bh,bh.LINE_SCALE),Xh=nn(bh,bh.LINE_DASH_SIZE),Kh=nn(bh,bh.LINE_GAP_SIZE),Yh=nn(bh,bh.LINE_WIDTH),Qh=nn(bh,bh.LINE_DASH_OFFSET),Zh=nn(bh,bh.POINT_SIZE),Jh=nn(bh,bh.DISPERSION),ep=nn(bh,bh.LIGHT_MAP),tp=nn(bh,bh.AO),rp=va(new t).onReference(function(e){return e.material}).onRenderUpdate(function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}),sp=ln(e=>e.context.setupModelViewProjection(),"vec4").once()().toVarying("v_modelViewProjection");class ip extends di{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}getMemberType(e,t){const r=this.storageBufferNode.structTypeNode;return r?r.getMemberType(e,t):"void"}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.isPBO&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let r;const s=e.context.assign;if(r=!1===e.isAvailable("storageBuffer")?!0!==this.node.isPBO||!0===s||!this.node.value.isInstancedBufferAttribute&&"compute"===e.shaderStage?this.node.build(e):e.generatePBO(this):super.generate(e),!0!==s){const s=this.getNodeType(e);r=e.format(r,s,t)}return r}}const np=sn(ip).setParameterLength(2);class ap extends Il{static get type(){return"StorageBufferNode"}constructor(e,t=null,r=0){let s,i=null;t&&t.isStruct?(s="struct",i=t.layout,(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(r=e.count)):null===t&&(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)?(s=$s(e.itemSize),r=e.count):s=t,super(e,s,r),this.isStorageBufferNode=!0,this.structTypeNode=i,this.access=ri.READ_WRITE,this.isAtomic=!1,this.isPBO=!1,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return np(this,e)}setPBO(e){return this.isPBO=e,this}getPBO(){return this.isPBO}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(ri.READ_ONLY)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=el(this.value),this._varying=Du(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(null!==this.structTypeNode)return this.structTypeNode.getNodeType(e);if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}getMemberType(e,t){return null!==this.structTypeNode?this.structTypeNode.getMemberType(e,t):"void"}generate(e){if(null!==this.structTypeNode&&this.structTypeNode.build(e),e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:r}=this.getAttributeData(),s=r.build(e);return e.registerTransform(s,t),s}}const op=(e,t=null,r=0)=>new ap(e,t,r);class up extends li{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isIndexNode=!0}generate(e){const t=this.getNodeType(e),r=this.scope;let s,i;if(r===up.VERTEX)s=e.getVertexIndex();else if(r===up.INSTANCE)s=e.getInstanceIndex();else if(r===up.DRAW)s=e.getDrawIndex();else if(r===up.INVOCATION_LOCAL)s=e.getInvocationLocalIndex();else if(r===up.INVOCATION_SUBGROUP)s=e.getInvocationSubgroupIndex();else{if(r!==up.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+r);s=e.getSubgroupIndex()}if("vertex"===e.shaderStage||"compute"===e.shaderStage)i=s;else{i=Du(this).build(e,t)}return i}}up.VERTEX="vertex",up.INSTANCE="instance",up.SUBGROUP="subgroup",up.INVOCATION_LOCAL="invocationLocal",up.INVOCATION_SUBGROUP="invocationSubgroup",up.DRAW="draw";const lp=nn(up,up.VERTEX),dp=nn(up,up.INSTANCE),cp=nn(up,up.SUBGROUP),hp=nn(up,up.INVOCATION_SUBGROUP),pp=nn(up,up.INVOCATION_LOCAL),gp=nn(up,up.DRAW);class mp extends li{static get type(){return"InstanceNode"}constructor(e,t,r=null){super("void"),this.count=e,this.instanceMatrix=t,this.instanceColor=r,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=ei.FRAME,this.buffer=null,this.bufferColor=null,this.previousInstanceMatrixNode=null}get isStorageMatrix(){const{instanceMatrix:e}=this;return e&&!0===e.isStorageInstancedBufferAttribute}get isStorageColor(){const{instanceColor:e}=this;return e&&!0===e.isStorageInstancedBufferAttribute}setup(e){let{instanceMatrixNode:t,instanceColorNode:r}=this;null===t&&(t=this._createInstanceMatrixNode(!0,e),this.instanceMatrixNode=t);const{instanceColor:s,isStorageColor:i}=this;if(s&&null===r){if(i)r=op(s,"vec3",Math.max(s.count,1)).element(dp);else{const e=new j(s.array,3),t=s.usage===x?rl:tl;this.bufferColor=e,r=Nn(t(e,"vec3",3,0))}this.instanceColorNode=r}const n=t.mul(Kd).xyz;if(Kd.assign(n),e.needsPreviousData()&&Yd.assign(this.getPreviousInstancedPosition(e)),e.hasGeometryAttribute("normal")){const e=pc(ac,t);ac.assign(e)}null!==this.instanceColorNode&&On("vec3","vInstanceColor").assign(this.instanceColorNode)}update(e){null!==this.buffer&&!0!==this.isStorageMatrix&&(this.buffer.clearUpdateRanges(),this.buffer.updateRanges.push(...this.instanceMatrix.updateRanges),this.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMatrix.version)),this.instanceColor&&null!==this.bufferColor&&!0!==this.isStorageColor&&(this.bufferColor.clearUpdateRanges(),this.bufferColor.updateRanges.push(...this.instanceColor.updateRanges),this.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceColor.version)),null!==this.previousInstanceMatrixNode&&e.object.previousInstanceMatrix.array.set(this.instanceMatrix.array)}getPreviousInstancedPosition(e){const t=e.object;return null===this.previousInstanceMatrixNode&&(t.previousInstanceMatrix=this.instanceMatrix.clone(),this.previousInstanceMatrixNode=this._createInstanceMatrixNode(!1,e)),this.previousInstanceMatrixNode.mul(Yd).xyz}_createInstanceMatrixNode(e,t){let r;const{instanceMatrix:s}=this,{count:i}=s;if(this.isStorageMatrix)r=op(s,"mat4",Math.max(i,1)).element(dp);else{if(16*i*4<=t.getUniformBufferLimit())r=Ol(s.array,"mat4",Math.max(i,1)).element(dp);else{const t=new X(s.array,16,1);!0===e&&(this.buffer=t);const i=s.usage===x?rl:tl,n=[i(t,"vec4",16,0),i(t,"vec4",16,4),i(t,"vec4",16,8),i(t,"vec4",16,12)];r=Ln(...n)}}return r}}const fp=sn(mp).setParameterLength(2,3);class yp extends mp{static get type(){return"InstancedMeshNode"}constructor(e){const{count:t,instanceMatrix:r,instanceColor:s}=e;super(t,r,s),this.instancedMesh=e}}const bp=sn(yp).setParameterLength(1);class xp extends li{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=dp:this.batchingIdNode=gp);const t=ln(([e])=>{const t=fn(wl(Ul(this.batchMesh._indirectTexture),0).x).toConst(),r=fn(e).mod(t).toConst(),s=fn(e).div(t).toConst();return Ul(this.batchMesh._indirectTexture,Tn(r,s)).x}).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),r=t(fn(this.batchingIdNode)),s=this.batchMesh._matricesTexture,i=fn(wl(Ul(s),0).x).toConst(),n=mn(r).mul(4).toInt().toConst(),a=n.mod(i).toConst(),o=n.div(i).toConst(),u=Ln(Ul(s,Tn(a,o)),Ul(s,Tn(a.add(1),o)),Ul(s,Tn(a.add(2),o)),Ul(s,Tn(a.add(3),o))),l=this.batchMesh._colorsTexture;if(null!==l){const e=ln(([e])=>{const t=fn(wl(Ul(l),0).x).toConst(),r=e,s=r.mod(t).toConst(),i=r.div(t).toConst();return Ul(l,Tn(s,i)).rgb}).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),t=e(r);On("vec3","vBatchColor").assign(t)}const d=Fn(u);Kd.assign(u.mul(Kd));const c=ac.div(Nn(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),h=d.mul(c).xyz;ac.assign(h),e.hasGeometryAttribute("tangent")&&Zc.mulAssign(d)}}const Tp=sn(xp).setParameterLength(1),_p=new WeakMap;class vp extends li{static get type(){return"SkinningNode"}constructor(e){super("void"),this.skinnedMesh=e,this.updateType=ei.OBJECT,this.skinIndexNode=Rl("skinIndex","uvec4"),this.skinWeightNode=Rl("skinWeight","vec4"),this.bindMatrixNode=Lc("bindMatrix","mat4"),this.bindMatrixInverseNode=Lc("bindMatrixInverse","mat4"),this.boneMatricesNode=Pc("skeleton.boneMatrices","mat4",e.skeleton.bones.length),this.positionNode=Kd,this.toPositionNode=Kd,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=this.positionNode){const{skinIndexNode:r,skinWeightNode:s,bindMatrixNode:i,bindMatrixInverseNode:n}=this,a=e.element(r.x),o=e.element(r.y),u=e.element(r.z),l=e.element(r.w),d=i.mul(t),c=Ba(a.mul(s.x).mul(d),o.mul(s.y).mul(d),u.mul(s.z).mul(d),l.mul(s.w).mul(d));return n.mul(c).xyz}getSkinnedNormalAndTangent(e=this.boneMatricesNode,t=ac,r=Zc){const{skinIndexNode:s,skinWeightNode:i,bindMatrixNode:n,bindMatrixInverseNode:a}=this,o=e.element(s.x),u=e.element(s.y),l=e.element(s.z),d=e.element(s.w);let c=Ba(i.x.mul(o),i.y.mul(u),i.z.mul(l),i.w.mul(d));c=a.mul(c).mul(n);return{skinNormal:c.transformDirection(t).xyz,skinTangent:c.transformDirection(r).xyz}}getPreviousSkinnedPosition(e){const t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Pc("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Yd)}setup(e){e.needsPreviousData()&&Yd.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(this.toPositionNode&&this.toPositionNode.assign(t),e.hasGeometryAttribute("normal")){const{skinNormal:t,skinTangent:r}=this.getSkinnedNormalAndTangent();ac.assign(t),e.hasGeometryAttribute("tangent")&&Zc.assign(r)}return t}generate(e,t){if("void"!==t)return super.generate(e,t)}update(e){const t=e.object&&e.object.skeleton?e.object.skeleton:this.skinnedMesh.skeleton;_p.get(t)!==e.frameId&&(_p.set(t,e.frameId),null!==this.previousBoneMatricesNode&&(null===t.previousBoneMatrices&&(t.previousBoneMatrices=new Float32Array(t.boneMatrices)),t.previousBoneMatrices.set(t.boneMatrices)),t.update())}}const Np=e=>new vp(e);class Sp extends li{static get type(){return"LoopNode"}constructor(e=[]){super("void"),this.params=e}getVarName(e){return String.fromCharCode("i".charCodeAt(0)+e)}getProperties(e){const t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;const r={};for(let e=0,t=this.params.length-1;e<t;e++){const t=this.params[e],s=!0!==t.isNode&&t.name||this.getVarName(e),i=!0!==t.isNode&&t.type||"int";r[s]=ml(s,i)}const s=e.addStack(),i=this.params[this.params.length-1](r);t.returnsNode=i.context({nodeLoop:i}),t.stackNode=s;const n=this.params[0];if(!0!==n.isNode&&"function"==typeof n.update){const e=ln(this.params[0].update)(r);t.updateNode=e.context({nodeLoop:e})}return e.removeStack(),t}setup(e){if(this.getProperties(e),e.fnCall){e.getDataFromNode(e.fnCall.shaderNode).hasLoop=!0}}generate(e){const t=this.getProperties(e),r=this.params,s=t.stackNode;for(let s=0,i=r.length-1;s<i;s++){const i=r[s];let n,a=!1,u=null,l=null,d=null,c=null,h=null,p=null;if(i.isNode?"bool"===i.getNodeType(e)?(a=!0,c="bool",l=i.build(e,c)):(c="int",d=this.getVarName(s),u="0",l=i.build(e,c),h="<"):(c=i.type||"int",d=i.name||this.getVarName(s),u=i.start,l=i.end,h=i.condition,p=i.update,"number"==typeof u?u=e.generateConst(c,u):u&&u.isNode&&(u=u.build(e,c)),"number"==typeof l?l=e.generateConst(c,l):l&&l.isNode&&(l=l.build(e,c)),void 0!==u&&void 0===l?(u+=" - 1",l="0",h=">="):void 0!==l&&void 0===u&&(u="0",h="<"),void 0===h&&(h=Number(u)>Number(l)?">=":"<")),a)n=`while ( ${l} )`;else{const r={start:u,end:l},s=r.start,i=r.end;let a;const g=()=>h.includes("<")?"+=":"-=";if(null!=p)switch(typeof p){case"function":a=e.flowStagesNode(t.updateNode,"void").code.replace(/\t|;/g,"");break;case"number":a=d+" "+g()+" "+e.generateConst(c,p);break;case"string":a=d+" "+p;break;default:p.isNode?a=d+" "+g()+" "+p.build(e):(o("TSL: 'Loop( { update: ... } )' is not a function, string or number.",this.stackTrace),a="break /* invalid update */")}else p="int"===c||"uint"===c?h.includes("<")?"++":"--":g()+" 1.",a=d+" "+p;n=`for ( ${e.getVar(c,d)+" = "+s}; ${d+" "+h+" "+i}; ${a} )`}e.addFlowCode((0===s?"\n":"")+e.tab+n+" {\n\n").addFlowTab()}const i=s.build(e,"void");t.returnsNode.build(e,"void"),e.removeFlowTab().addFlowCode("\n"+e.tab+i);for(let t=0,r=this.params.length-1;t<r;t++)e.addFlowCode((0===t?"":e.tab)+"}\n\n").removeFlowTab();e.addFlowTab()}}const Rp=(...e)=>new Sp(rn(e,"int")).toStack(),Ep=()=>ml("break").toStack(),Ap=new WeakMap,wp=new s,Cp=ln(({bufferMap:e,influence:t,stride:r,width:s,depth:i,offset:n})=>{const a=fn(lp).mul(r).add(n),o=a.div(s),u=a.sub(o.mul(s));return Ul(e,Tn(u,o)).depth(i).xyz.mul(t)});class Mp extends li{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=va(1),this.updateType=ei.OBJECT}setup(e){const{geometry:r}=e,s=void 0!==r.morphAttributes.position,i=r.hasAttribute("normal")&&void 0!==r.morphAttributes.normal,n=r.morphAttributes.position||r.morphAttributes.normal||r.morphAttributes.color,a=void 0!==n?n.length:0,{texture:o,stride:u,size:l}=function(e){const r=void 0!==e.morphAttributes.position,s=void 0!==e.morphAttributes.normal,i=void 0!==e.morphAttributes.color,n=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,a=void 0!==n?n.length:0;let o=Ap.get(e);if(void 0===o||o.count!==a){void 0!==o&&o.texture.dispose();const u=e.morphAttributes.position||[],l=e.morphAttributes.normal||[],d=e.morphAttributes.color||[];let c=0;!0===r&&(c=1),!0===s&&(c=2),!0===i&&(c=3);let h=e.attributes.position.count*c,p=1;const g=4096;h>g&&(p=Math.ceil(h/g),h=g);const m=new Float32Array(h*p*4*a),f=new K(m,h,p,a);f.type=Y,f.needsUpdate=!0;const y=4*c;for(let x=0;x<a;x++){const T=u[x],_=l[x],v=d[x],N=h*p*4*x;for(let S=0;S<T.count;S++){const R=S*y;!0===r&&(wp.fromBufferAttribute(T,S),m[N+R+0]=wp.x,m[N+R+1]=wp.y,m[N+R+2]=wp.z,m[N+R+3]=0),!0===s&&(wp.fromBufferAttribute(_,S),m[N+R+4]=wp.x,m[N+R+5]=wp.y,m[N+R+6]=wp.z,m[N+R+7]=0),!0===i&&(wp.fromBufferAttribute(v,S),m[N+R+8]=wp.x,m[N+R+9]=wp.y,m[N+R+10]=wp.z,m[N+R+11]=4===v.itemSize?wp.w:1)}}function b(){f.dispose(),Ap.delete(e),e.removeEventListener("dispose",b)}o={count:a,texture:f,stride:c,size:new t(h,p)},Ap.set(e,o),e.addEventListener("dispose",b)}return o}(r);!0===s&&Kd.mulAssign(this.morphBaseInfluence),!0===i&&ac.mulAssign(this.morphBaseInfluence);const d=fn(l.width);Rp(a,({i:e})=>{const t=mn(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(Ul(this.mesh.morphTexture,Tn(fn(e).add(1),fn(dp))).r):t.assign(Lc("morphTargetInfluences","float").element(e).toVar()),hn(t.notEqual(0),()=>{!0===s&&Kd.addAssign(Cp({bufferMap:o,influence:t,stride:u,width:d,depth:e,offset:fn(0)})),!0===i&&ac.addAssign(Cp({bufferMap:o,influence:t,stride:u,width:d,depth:e,offset:fn(1)}))})})}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce((e,t)=>e+t,0)}}const Bp=sn(Mp).setParameterLength(1);class Fp extends li{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}}class Lp extends Fp{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class Pp extends Tu{static get type(){return"LightingContextNode"}constructor(e,t=null,r=null,s=null){super(e),this.lightingModel=t,this.backdropNode=r,this.backdropAlphaNode=s,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,r={directDiffuse:Nn().toVar("directDiffuse"),directSpecular:Nn().toVar("directSpecular"),indirectDiffuse:Nn().toVar("indirectDiffuse"),indirectSpecular:Nn().toVar("indirectSpecular")};return{radiance:Nn().toVar("radiance"),irradiance:Nn().toVar("irradiance"),iblIrradiance:Nn().toVar("iblIrradiance"),ambientOcclusion:mn(1).toVar("ambientOcclusion"),reflectedLight:r,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const Dp=sn(Pp);class Up extends Fp{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}const Ip=new t;class Op extends Ll{static get type(){return"ViewportTextureNode"}constructor(e=Xl,t=null,r=null){let s=null;null===r?(s=new Q,s.minFilter=Z,r=s):s=r,super(r,e,t),this.generateMipmaps=!1,this.defaultFramebuffer=s,this.isOutputTextureNode=!0,this.updateBeforeType=ei.RENDER,this._cacheTextures=new WeakMap}getTextureForReference(e=null){let t,r;if(this.referenceNode?(t=this.referenceNode.defaultFramebuffer,r=this.referenceNode._cacheTextures):(t=this.defaultFramebuffer,r=this._cacheTextures),null===e)return t;if(!1===r.has(e)){const s=t.clone();r.set(e,s)}return r.get(e)}updateReference(e){const t=e.renderer.getRenderTarget();return this.value=this.getTextureForReference(t),this.value}updateBefore(e){const t=e.renderer,r=t.getRenderTarget();null===r?t.getDrawingBufferSize(Ip):Ip.set(r.width,r.height);const s=this.getTextureForReference(r);s.image.width===Ip.width&&s.image.height===Ip.height||(s.image.width=Ip.width,s.image.height=Ip.height,s.needsUpdate=!0);const i=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=i}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Vp=sn(Op).setParameterLength(0,3),kp=sn(Op,null,null,{generateMipmaps:!0}).setParameterLength(0,3),Gp=kp(),$p=(e=Xl,t=null)=>Gp.sample(e,t);let zp=null;class Wp extends Op{static get type(){return"ViewportDepthTextureNode"}constructor(e=Xl,t=null){null===zp&&(zp=new J),super(e,t,zp)}getTextureForReference(){return zp}}const Hp=sn(Wp).setParameterLength(0,2);class qp extends li{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===qp.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,r=this.valueNode;let s=null;if(t===qp.DEPTH_BASE)null!==r&&(s=Jp().assign(r));else if(t===qp.DEPTH)s=e.isPerspectiveCamera?Kp(Jd.z,yd,bd):jp(Jd.z,yd,bd);else if(t===qp.LINEAR_DEPTH)if(null!==r)if(e.isPerspectiveCamera){const e=Qp(r,yd,bd);s=jp(e,yd,bd)}else s=r;else s=jp(Jd.z,yd,bd);return s}}qp.DEPTH_BASE="depthBase",qp.DEPTH="depth",qp.LINEAR_DEPTH="linearDepth";const jp=(e,t,r)=>e.add(t).div(t.sub(r)),Xp=ln(([e,t,r],s)=>!0===s.renderer.reversedDepthBuffer?r.sub(t).mul(e).sub(r):t.sub(r).mul(e).sub(t)),Kp=(e,t,r)=>t.add(e).mul(r).div(r.sub(t).mul(e)),Yp=(e,t,r)=>t.mul(e.add(r)).div(e.mul(t.sub(r))),Qp=ln(([e,t,r],s)=>!0===s.renderer.reversedDepthBuffer?t.mul(r).div(t.sub(r).mul(e).sub(t)):t.mul(r).div(r.sub(t).mul(e).sub(r))),Zp=(e,t,r)=>{t=t.max(1e-6).toVar();const s=bo(e.negate().div(t)),i=bo(r.div(t));return s.div(i)},Jp=sn(qp,qp.DEPTH_BASE),eg=nn(qp,qp.DEPTH),tg=sn(qp,qp.LINEAR_DEPTH).setParameterLength(0,1),rg=tg(Hp());eg.assign=e=>Jp(e);class sg extends li{static get type(){return"ClippingNode"}constructor(e=sg.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:r,unionPlanes:s}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===sg.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(r,s):this.scope===sg.HARDWARE?this.setupHardwareClipping(s,e):this.setupDefault(r,s)}setupAlphaToCoverage(e,t){return ln(()=>{const r=mn().toVar("distanceToPlane"),s=mn().toVar("distanceToGradient"),i=mn(1).toVar("clipOpacity"),n=t.length;if(!1===this.hardwareClipping&&n>0){const e=Gl(t).setGroup(xa);Rp(n,({i:t})=>{const n=e.element(t);r.assign(Jd.dot(n.xyz).negate().add(n.w)),s.assign(r.fwidth().div(2)),i.mulAssign(du(s.negate(),s,r))})}const a=e.length;if(a>0){const t=Gl(e).setGroup(xa),n=mn(1).toVar("intersectionClipOpacity");Rp(a,({i:e})=>{const i=t.element(e);r.assign(Jd.dot(i.xyz).negate().add(i.w)),s.assign(r.fwidth().div(2)),n.mulAssign(du(s.negate(),s,r).oneMinus())}),i.mulAssign(n.oneMinus())}Vn.a.mulAssign(i),Vn.a.equal(0).discard()})()}setupDefault(e,t){return ln(()=>{const r=t.length;if(!1===this.hardwareClipping&&r>0){const e=Gl(t).setGroup(xa);Rp(r,({i:t})=>{const r=e.element(t);Jd.dot(r.xyz).greaterThan(r.w).discard()})}const s=e.length;if(s>0){const t=Gl(e).setGroup(xa),r=bn(!0).toVar("clipped");Rp(s,({i:e})=>{const s=t.element(e);r.assign(Jd.dot(s.xyz).greaterThan(s.w).and(r))}),r.discard()}})()}setupHardwareClipping(e,t){const r=e.length;return t.enableHardwareClipping(r),ln(()=>{const s=Gl(e).setGroup(xa),i=zl(t.getClipDistance());Rp(r,({i:e})=>{const t=s.element(e),r=Jd.dot(t.xyz).sub(t.w).negate();i.element(e).assign(r)})})()}}sg.ALPHA_TO_COVERAGE="alphaToCoverage",sg.DEFAULT="default",sg.HARDWARE="hardware";const ig=ln(([e])=>So(La(1e4,Ro(La(17,e.x).add(La(.1,e.y)))).mul(Ba(.1,Bo(Ro(La(13,e.y).add(e.x))))))),ng=ln(([e])=>ig(xn(ig(e.xy),e.z))),ag=ln(([e])=>{const t=qo(Lo(Uo(e.xyz)),Lo(Io(e.xyz))),r=mn(1).div(mn(.05).mul(t)).toVar("pixScale"),s=xn(fo(_o(bo(r))),fo(vo(bo(r)))),i=xn(ng(_o(s.x.mul(e.xyz))),ng(_o(s.y.mul(e.xyz)))),n=So(bo(r)),a=Ba(La(n.oneMinus(),i.x),La(n,i.y)),o=Ho(n,n.oneMinus()),u=Nn(a.mul(a).div(La(2,o).mul(Fa(1,o))),a.sub(La(.5,o)).div(Fa(1,o)),Fa(1,Fa(1,a).mul(Fa(1,a)).div(La(2,o).mul(Fa(1,o))))),l=a.lessThan(o.oneMinus()).select(a.lessThan(o).select(u.x,u.y),u.z);return ou(l,1e-6,1)}).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]});class og extends Sl{static get type(){return"VertexColorNode"}constructor(e){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e);let r;return r=!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new s(1,1,1,1)),r}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const ug=(e=0)=>new og(e),lg=ln(([e,t])=>Ho(1,e.oneMinus().div(t)).oneMinus()).setLayout({name:"blendBurn",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),dg=ln(([e,t])=>Ho(e.div(t.oneMinus()),1)).setLayout({name:"blendDodge",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),cg=ln(([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus()).setLayout({name:"blendScreen",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),hg=ln(([e,t])=>au(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),jo(.5,e))).setLayout({name:"blendOverlay",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),pg=ln(([e,t])=>{const r=t.a.add(e.a.mul(t.a.oneMinus()));return An(t.rgb.mul(t.a).add(e.rgb.mul(e.a).mul(t.a.oneMinus())).div(r),r)}).setLayout({name:"blendColor",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),gg=ln(([e])=>An(e.rgb.mul(e.a),e.a),{color:"vec4",return:"vec4"}),mg=ln(([e])=>(hn(e.a.equal(0),()=>An(0)),An(e.rgb.div(e.a),e.a)),{color:"vec4",return:"vec4"});class fg extends ee{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,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.maskNode=null,this.maskShadowNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.receivedShadowPositionNode=null,this.castShadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null,this.contextNode=null}_getNodeChildren(){const e=[];for(const t of Object.getOwnPropertyNames(this)){if(!0===t.startsWith("_"))continue;const r=this[t];r&&!0===r.isNode&&e.push({property:t,childNode:r})}return e}customProgramCacheKey(){const e=[];for(const{property:t,childNode:r}of this._getNodeChildren())e.push(Is(t.slice(0,-4)),r.getCacheKey());return this.type+Os(e)}build(e){this.setup(e)}setupObserver(e){return new Ls(e)}setup(e){e.context.setupNormal=()=>Lu(this.setupNormal(e),"NORMAL","vec3"),e.context.setupPositionView=()=>this.setupPositionView(e),e.context.setupModelViewProjection=()=>this.setupModelViewProjection(e);const t=e.renderer,r=t.getRenderTarget();!0===t.contextNode.isContextNode?e.context={...e.context,...t.contextNode.getFlowContextData()}:o('NodeMaterial: "renderer.contextNode" must be an instance of `context()`.'),null!==this.contextNode&&(!0===this.contextNode.isContextNode?e.context={...e.context,...this.contextNode.getFlowContextData()}:o('NodeMaterial: "material.contextNode" must be an instance of `context()`.')),e.addStack();const s=this.setupVertex(e),i=Lu(this.vertexNode||s,"VERTEX");let n;e.context.clipSpace=i,e.stack.outputNode=i,this.setupHardwareClipping(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();const a=this.setupClipping(e);if(!0!==this.depthWrite&&!0!==this.depthTest||(null!==r?!0===r.depthBuffer&&this.setupDepth(e):!0===t.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);const s=this.setupLighting(e);null!==a&&e.stack.addToStack(a);const i=An(s,Vn.a).max(0);n=this.setupOutput(e,i),na.assign(n);const o=null!==this.outputNode;if(o&&(n=this.outputNode),e.context.getOutput&&(n=e.context.getOutput(n,e)),null!==r){const e=t.getMRT(),r=this.mrtNode;null!==e?(o&&na.assign(n),n=e,null!==r&&(n=e.merge(r))):null!==r&&(n=r)}}else{let t=this.fragmentNode;!0!==t.isOutputStructNode&&(t=An(t)),n=this.setupOutput(e,t)}e.stack.outputNode=n,e.addFlow("fragment",e.removeStack()),e.observer=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;const{unionPlanes:t,intersectionPlanes:r}=e.clippingContext;let s=null;if(t.length>0||r.length>0){const t=e.renderer.currentSamples;this.alphaToCoverage&&t>1?s=new sg(sg.ALPHA_TO_COVERAGE):e.stack.addToStack(new sg)}return s}setupHardwareClipping(e){if(this.hardwareClipping=!1,null===e.clippingContext)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.addToStack(new sg(sg.HARDWARE)),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:r}=e;let s=this.depthNode;if(null===s){const e="getMRT"in t&&t.getMRT();e&&e.has("depth")?s=e.get("depth"):!0===t.logarithmicDepthBuffer&&(s=r.isPerspectiveCamera?Zp(Jd.z,yd,bd):jp(Jd.z,yd,bd))}null!==s&&eg.assign(s).toStack()}setupPositionView(){return zd.mul(Kd).xyz}setupModelViewProjection(){return xd.mul(Jd)}setupVertex(e){return e.addStack(),this.setupPosition(e),e.context.position=e.removeStack(),sp}setupPosition(e){const{object:t,geometry:r}=e;if((r.morphAttributes.position||r.morphAttributes.normal||r.morphAttributes.color)&&Bp(t).toStack(),!0===t.isSkinnedMesh&&Np(t).toStack(),this.displacementMap){const e=Uc("displacementMap","texture"),t=Uc("displacementScale","float"),r=Uc("displacementBias","float");Kd.addAssign(ac.normalize().mul(e.x.mul(t).add(r)))}return t.isBatchedMesh&&Tp(t).toStack(),t.isInstancedMesh&&t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&bp(t).toStack(),null!==this.positionNode&&Kd.assign(Lu(this.positionNode,"POSITION","vec3")),Kd}setupDiffuseColor(e){const{object:t,geometry:r}=e;null!==this.maskNode&&bn(this.maskNode).not().discard();let s=this.colorNode?An(this.colorNode):Th;if(!0===this.vertexColors&&r.hasAttribute("color")&&(s=s.mul(ug())),t.instanceColor){s=On("vec3","vInstanceColor").mul(s)}if(t.isBatchedMesh&&t._colorsTexture){s=On("vec3","vBatchColor").mul(s)}Vn.assign(s);const i=this.opacityNode?mn(this.opacityNode):Nh;Vn.a.assign(Vn.a.mul(i));let n=null;(null!==this.alphaTestNode||this.alphaTest>0)&&(n=null!==this.alphaTestNode?mn(this.alphaTestNode):xh,!0===this.alphaToCoverage?(Vn.a=du(n,n.add(Go(Vn.a)),Vn.a),Vn.a.lessThanEqual(0).discard()):Vn.a.lessThanEqual(n).discard()),!0===this.alphaHash&&Vn.a.lessThan(ag(Kd)).discard(),e.isOpaque()&&Vn.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Nn(0):Vn.rgb}setupNormal(){return this.normalNode?Nn(this.normalNode):Bh}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?Uc("envMap","cubeTexture"):Uc("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Up(ep)),t}setupLights(e){const t=[],r=this.setupEnvironment(e);r&&r.isLightingNode&&t.push(r);const s=this.setupLightMap(e);s&&s.isLightingNode&&t.push(s);let i=this.aoNode;null===i&&e.material.aoMap&&(i=tp),e.context.getAO&&(i=e.context.getAO(i,e)),i&&t.push(new Lp(i));let n=this.lightsNode||e.lightsNode;return t.length>0&&(n=e.renderer.lighting.createNode([...n.getLights(),...t])),n}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:r,backdropAlphaNode:s,emissiveNode:i}=this,n=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null;let a=this.setupOutgoingLight(e);if(n&&n.getScope().hasLights){const t=this.setupLightingModel(e)||null;a=Dp(n,t,r,s)}else null!==r&&(a=Nn(null!==s?au(a,r,s):r));return(i&&!0===i.isNode||t.emissive&&!0===t.emissive.isColor)&&(Gn.assign(Nn(i||vh)),a=a.add(Gn)),a}setupFog(e,t){const r=e.fogNode;return r&&(na.assign(t),t=An(r.toVar())),t}setupPremultipliedAlpha(e,t){return gg(t)}setupOutput(e,t){return!0===this.fog&&(t=this.setupFog(e,t)),!0===this.premultipliedAlpha&&(t=this.setupPremultipliedAlpha(e,t)),t}setDefaultValues(e){for(const t in e){const r=e[t];void 0===this[t]&&(this[t]=r,r&&r.clone&&(this[t]=r.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});const r=ee.prototype.toJSON.call(this,e);r.inputNodes={};for(const{property:t,childNode:s}of this._getNodeChildren())r.inputNodes[t]=s.toJSON(e).uuid;function s(e){const t=[];for(const r in e){const s=e[r];delete s.metadata,t.push(s)}return t}if(t){const t=s(e.textures),i=s(e.images),n=s(e.nodes);t.length>0&&(r.textures=t),i.length>0&&(r.images=i),n.length>0&&(r.nodes=n)}return r}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.aoNode=e.aoNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.maskNode=e.maskNode,this.maskShadowNode=e.maskShadowNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.receivedShadowPositionNode=e.receivedShadowPositionNode,this.castShadowPositionNode=e.castShadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,this.contextNode=e.contextNode,super.copy(e)}}const yg=new te;class bg extends fg{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.setDefaultValues(yg),this.setValues(e)}}const xg=new re;class Tg extends fg{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.setDefaultValues(xg),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?mn(this.offsetNode):Qh,t=this.dashScaleNode?mn(this.dashScaleNode):jh,r=this.dashSizeNode?mn(this.dashSizeNode):Xh,s=this.gapSizeNode?mn(this.gapSizeNode):Kh;aa.assign(r),oa.assign(s);const i=Du(Rl("lineDistance").mul(t));(e?i.add(e):i).mod(aa.add(oa)).greaterThan(aa).discard()}}const _g=new re;class vg extends fg{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.isLine2NodeMaterial=!0,this.setDefaultValues(_g),this.vertexColors=e.vertexColors,this.dashOffset=0,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.blending=se,this._useDash=e.dashed,this._useAlphaToCoverage=!0,this._useWorldUnits=!1,this.setValues(e)}setup(e){const{renderer:t}=e,r=this._useAlphaToCoverage,s=this.vertexColors,i=this._useDash,n=this._useWorldUnits,a=ln(({start:e,end:t})=>{const r=xd.element(2).element(2),s=xd.element(3).element(2).mul(-.5).div(r).sub(e.z).div(t.z.sub(e.z));return An(au(e.xyz,t.xyz,s),t.w)}).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=ln(()=>{const e=Rl("instanceStart"),t=Rl("instanceEnd"),r=An(zd.mul(An(e,1))).toVar("start"),s=An(zd.mul(An(t,1))).toVar("end");if(i){const e=this.dashScaleNode?mn(this.dashScaleNode):jh,t=this.offsetNode?mn(this.offsetNode):Qh,r=Rl("instanceDistanceStart"),s=Rl("instanceDistanceEnd");let i=Xd.y.lessThan(.5).select(e.mul(r),e.mul(s));i=i.add(t),On("float","lineDistance").assign(i)}n&&(On("vec3","worldStart").assign(r.xyz),On("vec3","worldEnd").assign(s.xyz));const o=Ql.z.div(Ql.w),u=xd.element(2).element(3).equal(-1);hn(u,()=>{hn(r.z.lessThan(0).and(s.z.greaterThan(0)),()=>{s.assign(a({start:r,end:s}))}).ElseIf(s.z.lessThan(0).and(r.z.greaterThanEqual(0)),()=>{r.assign(a({start:s,end:r}))})});const l=xd.mul(r),d=xd.mul(s),c=l.xyz.div(l.w),h=d.xyz.div(d.w),p=h.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(o)),p.assign(p.normalize());const g=An().toVar();if(n){const e=s.xyz.sub(r.xyz).normalize(),t=au(r.xyz,s.xyz,.5).normalize(),n=e.cross(t).normalize(),a=e.cross(n),o=On("vec4","worldPos");o.assign(Xd.y.lessThan(.5).select(r,s));const u=Yh.mul(.5);o.addAssign(An(Xd.x.lessThan(0).select(n.mul(u),n.mul(u).negate()),0)),i||(o.addAssign(An(Xd.y.lessThan(.5).select(e.mul(u).negate(),e.mul(u)),0)),o.addAssign(An(a.mul(u),0)),hn(Xd.y.greaterThan(1).or(Xd.y.lessThan(0)),()=>{o.subAssign(An(a.mul(2).mul(u),0))})),g.assign(xd.mul(o));const l=Nn().toVar();l.assign(Xd.y.lessThan(.5).select(c,h)),g.z.assign(l.z.mul(g.w))}else{const e=xn(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(o)),e.x.assign(e.x.div(o)),e.assign(Xd.x.lessThan(0).select(e.negate(),e)),hn(Xd.y.lessThan(0),()=>{e.assign(e.sub(p))}).ElseIf(Xd.y.greaterThan(1),()=>{e.assign(e.add(p))}),e.assign(e.mul(Yh)),e.assign(e.div(Ql.w.div(jl))),g.assign(Xd.y.lessThan(.5).select(l,d)),e.assign(e.mul(g.w)),g.assign(g.add(An(e,0,0)))}return g})();const o=ln(({p1:e,p2:t,p3:r,p4:s})=>{const i=e.sub(r),n=s.sub(r),a=t.sub(e),o=i.dot(n),u=n.dot(a),l=i.dot(a),d=n.dot(n),c=a.dot(a).mul(d).sub(u.mul(u)),h=o.mul(u).sub(l.mul(d)).div(c).clamp(),p=o.add(u.mul(h)).div(d).clamp();return xn(h,p)});if(this.colorNode=ln(()=>{const e=El();if(i){const t=this.dashSizeNode?mn(this.dashSizeNode):Xh,r=this.gapSizeNode?mn(this.gapSizeNode):Kh;aa.assign(t),oa.assign(r);const s=On("float","lineDistance");e.y.lessThan(-1).or(e.y.greaterThan(1)).discard(),s.mod(aa.add(oa)).greaterThan(aa).discard()}const a=mn(1).toVar("alpha");if(n){const e=On("vec3","worldStart"),s=On("vec3","worldEnd"),n=On("vec4","worldPos").xyz.normalize().mul(1e5),u=s.sub(e),l=o({p1:e,p2:s,p3:Nn(0,0,0),p4:n}),d=e.add(u.mul(l.x)),c=n.mul(l.y),h=d.sub(c).length().div(Yh);if(!i)if(r&&t.currentSamples>0){const e=h.fwidth();a.assign(du(e.negate().add(.5),e.add(.5),h).oneMinus())}else h.greaterThan(.5).discard()}else if(r&&t.currentSamples>0){const t=e.x,r=e.y.greaterThan(0).select(e.y.sub(1),e.y.add(1)),s=t.mul(t).add(r.mul(r)),i=mn(s.fwidth()).toVar("dlen");hn(e.y.abs().greaterThan(1),()=>{a.assign(du(i.oneMinus(),i.add(1),s).oneMinus())})}else hn(e.y.abs().greaterThan(1),()=>{const t=e.x,r=e.y.greaterThan(0).select(e.y.sub(1),e.y.add(1));t.mul(t).add(r.mul(r)).greaterThan(1).discard()});let u;if(this.lineColorNode)u=this.lineColorNode;else if(s){const e=Rl("instanceColorStart"),t=Rl("instanceColorEnd");u=Xd.y.lessThan(.5).select(e,t).mul(Th)}else u=Th;return An(u,a)})(),this.transparent){const e=this.opacityNode?mn(this.opacityNode):Nh;this.outputNode=An(this.colorNode.rgb.mul(e).add($p().rgb.mul(e.oneMinus())),this.colorNode.a)}super.setup(e)}get worldUnits(){return this._useWorldUnits}set worldUnits(e){this._useWorldUnits!==e&&(this._useWorldUnits=e,this.needsUpdate=!0)}get dashed(){return this._useDash}set dashed(e){this._useDash!==e&&(this._useDash=e,this.needsUpdate=!0)}get alphaToCoverage(){return this._useAlphaToCoverage}set alphaToCoverage(e){this._useAlphaToCoverage!==e&&(this._useAlphaToCoverage=e,this.needsUpdate=!0)}}const Ng=new ie;class Sg extends fg{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(Ng),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?mn(this.opacityNode):Nh;Vn.assign($u(An(lh(dc),e),ne))}}const Rg=ln(([e=Zd])=>{const t=e.z.atan(e.x).mul(1/(2*Math.PI)).add(.5),r=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return xn(t,r)});class Eg extends ae{constructor(e=1,t={}){super(e,e,t),this.isCubeRenderTarget=!0;const r={width:e,height:e,depth:1},s=[r,r,r,r,r,r];this.texture=new U(s),this._setTextureOptions(t),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(e,t){const r=t.minFilter,s=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const i=new oe(5,5,5),n=Rg(Zd),a=new fg;a.colorNode=Dl(t,n,0),a.side=L,a.blending=se;const o=new ue(i,a),u=new le;u.add(o),t.minFilter===Z&&(t.minFilter=de);const l=new ce(1,10,this),d=e.getMRT();return e.setMRT(null),l.update(e,u),e.setMRT(d),t.minFilter=r,t.currentGenerateMipmaps=s,o.geometry.dispose(),o.material.dispose(),this}clear(e,t=!0,r=!0,s=!0){const i=e.getRenderTarget();for(let i=0;i<6;i++)e.setRenderTarget(this,i),e.clear(t,r,s);e.setRenderTarget(i)}}const Ag=new WeakMap;class wg extends hi{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=Mc(null);const t=new U;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=ei.RENDER}updateBefore(e){const{renderer:t,material:r}=e,s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const e=s.isTextureNode?s.value:r[s.property];if(e&&e.isTexture){const r=e.mapping;if(r===he||r===pe){if(Ag.has(e)){const t=Ag.get(e);Mg(t,e.mapping),this._cubeTexture=t}else{const r=e.image;if(function(e){return null!=e&&e.height>0}(r)){const s=new Eg(r.height);s.fromEquirectangularTexture(t,e),Mg(s.texture,e.mapping),this._cubeTexture=s.texture,Ag.set(e,s.texture),e.addEventListener("dispose",Cg)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function Cg(e){const t=e.target;t.removeEventListener("dispose",Cg);const r=Ag.get(t);void 0!==r&&(Ag.delete(t),r.dispose())}function Mg(e,t){t===he?e.mapping=I:t===pe&&(e.mapping=O)}const Bg=sn(wg).setParameterLength(1);class Fg extends Fp{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Bg(this.envNode)}}class Lg extends Fp{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=mn(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Pg{start(e){e.lightsNode.setupLights(e,e.lightsNode.getLightNodes(e)),this.indirect(e)}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class Dg extends Pg{constructor(){super()}indirect({context:e}){const t=e.ambientOcclusion,r=e.reflectedLight,s=e.irradianceLightMap;r.indirectDiffuse.assign(An(0)),s?r.indirectDiffuse.addAssign(s):r.indirectDiffuse.addAssign(An(1,1,1,0)),r.indirectDiffuse.mulAssign(t),r.indirectDiffuse.mulAssign(Vn.rgb)}finish(e){const{material:t,context:r}=e,s=r.outgoingLight,i=e.context.environment;if(i)switch(t.combine){case fe:s.rgb.assign(au(s.rgb,s.rgb.mul(i.rgb),Ah.mul(wh)));break;case me:s.rgb.assign(au(s.rgb,i.rgb,Ah.mul(wh)));break;case ge:s.rgb.addAssign(i.rgb.mul(Ah.mul(wh)));break;default:d("BasicLightingModel: Unsupported .combine value:",t.combine)}}}const Ug=new ye;class Ig extends fg{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Ug),this.setValues(e)}setupNormal(){return ic(uc)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Fg(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Lg(ep)),t}setupOutgoingLight(){return Vn.rgb}setupLightingModel(){return new Dg}}const Og=ln(({f0:e,f90:t,dotVH:r})=>{const s=r.mul(-5.55473).sub(6.98316).mul(r).exp2();return e.mul(s.oneMinus()).add(t.mul(s))}),Vg=ln(e=>e.diffuseColor.mul(1/Math.PI)),kg=ln(({dotNH:e})=>ia.mul(mn(.5)).add(1).mul(mn(1/Math.PI)).mul(e.pow(ia))),Gg=ln(({lightDirection:e})=>{const t=e.add(ec).normalize(),r=dc.dot(t).clamp(),s=ec.dot(t).clamp(),i=Og({f0:ta,f90:1,dotVH:s}),n=mn(.25),a=kg({dotNH:r});return i.mul(n).mul(a)});class $g extends Dg{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:r}){const s=dc.dot(e).clamp().mul(t);r.directDiffuse.addAssign(s.mul(Vg({diffuseColor:Vn.rgb}))),!0===this.specular&&r.directSpecular.addAssign(s.mul(Gg({lightDirection:e})).mul(Ah))}indirect(e){const{ambientOcclusion:t,irradiance:r,reflectedLight:s}=e.context;s.indirectDiffuse.addAssign(r.mul(Vg({diffuseColor:Vn}))),s.indirectDiffuse.mulAssign(t)}}const zg=new be;class Wg extends fg{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(zg),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Fg(t):null}setupLightingModel(){return new $g(!1)}}const Hg=new xe;class qg extends fg{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(Hg),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Fg(t):null}setupLightingModel(){return new $g}setupVariants(){const e=(this.shininessNode?mn(this.shininessNode):_h).max(1e-4);ia.assign(e);const t=this.specularNode||Sh;ta.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const jg=ln(e=>{if(!1===e.geometry.hasAttribute("normal"))return mn(0);const t=uc.dFdx().abs().max(uc.dFdy().abs());return t.x.max(t.y).max(t.z)}),Xg=ln(e=>{const{roughness:t}=e,r=jg();let s=t.max(.0525);return s=s.add(r),s=s.min(1),s}),Kg=ln(({alpha:e,dotNL:t,dotNV:r})=>{const s=e.pow2(),i=t.mul(s.add(s.oneMinus().mul(r.pow2())).sqrt()),n=r.mul(s.add(s.oneMinus().mul(t.pow2())).sqrt());return Pa(.5,i.add(n).max(io))}).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),Yg=ln(({alphaT:e,alphaB:t,dotTV:r,dotBV:s,dotTL:i,dotBL:n,dotNV:a,dotNL:o})=>{const u=o.mul(Nn(e.mul(r),t.mul(s),a).length()),l=a.mul(Nn(e.mul(i),t.mul(n),o).length());return Pa(.5,u.add(l))}).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"}]}),Qg=ln(({alpha:e,dotNH:t})=>{const r=e.pow2(),s=t.pow2().mul(r.oneMinus()).oneMinus();return r.div(s.pow2()).mul(1/Math.PI)}).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),Zg=mn(1/Math.PI),Jg=ln(({alphaT:e,alphaB:t,dotNH:r,dotTH:s,dotBH:i})=>{const n=e.mul(t),a=Nn(t.mul(s),e.mul(i),n.mul(r)),o=a.dot(a),u=n.div(o);return Zg.mul(n.mul(u.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"}]}),em=ln(({lightDirection:e,f0:t,f90:r,roughness:s,f:i,normalView:n=dc,USE_IRIDESCENCE:a,USE_ANISOTROPY:o})=>{const u=s.pow2(),l=e.add(ec).normalize(),d=n.dot(e).clamp(),c=n.dot(ec).clamp(),h=n.dot(l).clamp(),p=ec.dot(l).clamp();let g,m,f=Og({f0:t,f90:r,dotVH:p});if(Yi(a)&&(f=Xn.mix(f,i)),Yi(o)){const t=Jn.dot(e),r=Jn.dot(ec),s=Jn.dot(l),i=ea.dot(e),n=ea.dot(ec),a=ea.dot(l);g=Yg({alphaT:Qn,alphaB:u,dotTV:r,dotBV:n,dotTL:t,dotBL:i,dotNV:c,dotNL:d}),m=Jg({alphaT:Qn,alphaB:u,dotNH:h,dotTH:s,dotBH:a})}else g=Kg({alpha:u,dotNL:d,dotNV:c}),m=Qg({alpha:u,dotNH:h});return f.mul(g).mul(m)}),tm=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]);let rm=null;const sm=ln(({roughness:e,dotNV:t})=>{null===rm&&(rm=new Te(tm,16,16,W,_e),rm.name="DFG_LUT",rm.minFilter=de,rm.magFilter=de,rm.wrapS=ve,rm.wrapT=ve,rm.generateMipmaps=!1,rm.needsUpdate=!0);const r=xn(e,t);return Dl(rm,r).rg}),im=ln(({lightDirection:e,f0:t,f90:r,roughness:s,f:i,USE_IRIDESCENCE:n,USE_ANISOTROPY:a})=>{const o=em({lightDirection:e,f0:t,f90:r,roughness:s,f:i,USE_IRIDESCENCE:n,USE_ANISOTROPY:a}),u=dc.dot(e).clamp(),l=dc.dot(ec).clamp(),d=sm({roughness:s,dotNV:l}),c=sm({roughness:s,dotNV:u}),h=t.mul(d.x).add(r.mul(d.y)),p=t.mul(c.x).add(r.mul(c.y)),g=d.x.add(d.y),m=c.x.add(c.y),f=mn(1).sub(g),y=mn(1).sub(m),b=t.add(t.oneMinus().mul(.047619)),x=h.mul(p).mul(b).div(mn(1).sub(f.mul(y).mul(b).mul(b)).add(io)),T=f.mul(y),_=x.mul(T);return o.add(_)}),nm=ln(e=>{const{dotNV:t,specularColor:r,specularF90:s,roughness:i}=e,n=sm({dotNV:t,roughness:i});return r.mul(n.x).add(s.mul(n.y))}),am=ln(({f:e,f90:t,dotVH:r})=>{const s=r.oneMinus().saturate(),i=s.mul(s),n=s.mul(i,i).clamp(0,.9999);return e.sub(Nn(t).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"}]}),om=ln(({roughness:e,dotNH:t})=>{const r=e.pow2(),s=mn(1).div(r),i=t.pow2().oneMinus().max(.0078125);return mn(2).add(s).mul(i.pow(s.mul(.5))).div(2*Math.PI)}).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),um=ln(({dotNV:e,dotNL:t})=>mn(1).div(mn(4).mul(t.add(e).sub(t.mul(e))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),lm=ln(({lightDirection:e})=>{const t=e.add(ec).normalize(),r=dc.dot(e).clamp(),s=dc.dot(ec).clamp(),i=dc.dot(t).clamp(),n=om({roughness:jn,dotNH:i}),a=um({dotNV:s,dotNL:r});return qn.mul(n).mul(a)}),dm=ln(({N:e,V:t,roughness:r})=>{const s=e.dot(t).saturate(),i=xn(r,s.oneMinus().sqrt());return i.assign(i.mul(.984375).add(.0078125)),i}).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),cm=ln(({f:e})=>{const t=e.length();return qo(t.mul(t).add(e.z).div(t.add(1)),0)}).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),hm=ln(({v1:e,v2:t})=>{const r=e.dot(t),s=r.abs().toVar(),i=s.mul(.0145206).add(.4965155).mul(s).add(.8543985).toVar(),n=s.add(4.1616724).mul(s).add(3.417594).toVar(),a=i.div(n),o=r.greaterThan(0).select(a,qo(r.mul(r).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(a));return e.cross(t).mul(o)}).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),pm=ln(({N:e,V:t,P:r,mInv:s,p0:i,p1:n,p2:a,p3:o})=>{const u=n.sub(i).toVar(),l=o.sub(i).toVar(),d=u.cross(l),c=Nn().toVar();return hn(d.dot(r.sub(i)).greaterThanEqual(0),()=>{const u=t.sub(e.mul(t.dot(e))).normalize(),l=e.cross(u).negate(),d=s.mul(Fn(u,l,e).transpose()).toVar(),h=d.mul(i.sub(r)).normalize().toVar(),p=d.mul(n.sub(r)).normalize().toVar(),g=d.mul(a.sub(r)).normalize().toVar(),m=d.mul(o.sub(r)).normalize().toVar(),f=Nn(0).toVar();f.addAssign(hm({v1:h,v2:p})),f.addAssign(hm({v1:p,v2:g})),f.addAssign(hm({v1:g,v2:m})),f.addAssign(hm({v1:m,v2:h})),c.assign(Nn(cm({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"}]}),gm=ln(({P:e,p0:t,p1:r,p2:s,p3:i})=>{const n=r.sub(t).toVar(),a=i.sub(t).toVar(),o=n.cross(a),u=Nn().toVar();return hn(o.dot(e.sub(t)).greaterThanEqual(0),()=>{const n=t.sub(e).normalize().toVar(),a=r.sub(e).normalize().toVar(),o=s.sub(e).normalize().toVar(),l=i.sub(e).normalize().toVar(),d=Nn(0).toVar();d.addAssign(hm({v1:n,v2:a})),d.addAssign(hm({v1:a,v2:o})),d.addAssign(hm({v1:o,v2:l})),d.addAssign(hm({v1:l,v2:n})),u.assign(Nn(cm({f:d.abs()})))}),u}).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"P",type:"vec3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),mm=1/6,fm=e=>La(mm,La(e,La(e,e.negate().add(3)).sub(3)).add(1)),ym=e=>La(mm,La(e,La(e,La(3,e).sub(6))).add(4)),bm=e=>La(mm,La(e,La(e,La(-3,e).add(3)).add(3)).add(1)),xm=e=>La(mm,Jo(e,3)),Tm=e=>fm(e).add(ym(e)),_m=e=>bm(e).add(xm(e)),vm=e=>Ba(-1,ym(e).div(fm(e).add(ym(e)))),Nm=e=>Ba(1,xm(e).div(bm(e).add(xm(e)))),Sm=(e,t,r)=>{const s=e.uvNode,i=La(s,t.zw).add(.5),n=_o(i),a=So(i),o=Tm(a.x),u=_m(a.x),l=vm(a.x),d=Nm(a.x),c=vm(a.y),h=Nm(a.y),p=xn(n.x.add(l),n.y.add(c)).sub(.5).mul(t.xy),g=xn(n.x.add(d),n.y.add(c)).sub(.5).mul(t.xy),m=xn(n.x.add(l),n.y.add(h)).sub(.5).mul(t.xy),f=xn(n.x.add(d),n.y.add(h)).sub(.5).mul(t.xy),y=Tm(a.y).mul(Ba(o.mul(e.sample(p).level(r)),u.mul(e.sample(g).level(r)))),b=_m(a.y).mul(Ba(o.mul(e.sample(m).level(r)),u.mul(e.sample(f).level(r))));return y.add(b)},Rm=ln(([e,t])=>{const r=xn(e.size(fn(t))),s=xn(e.size(fn(t.add(1)))),i=Pa(1,r),n=Pa(1,s),a=Sm(e,An(i,r),_o(t)),o=Sm(e,An(n,s),vo(t));return So(t).mix(a,o)}),Em=ln(([e,t])=>{const r=t.mul(Ml(e));return Rm(e,r)}),Am=ln(([e,t,r,s,i])=>{const n=Nn(lu(t.negate(),No(e),Pa(1,s))),a=Nn(Lo(i[0].xyz),Lo(i[1].xyz),Lo(i[2].xyz));return No(n).mul(r.mul(a))}).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"}]}),wm=ln(([e,t])=>e.mul(ou(t.mul(2).sub(2),0,1))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),Cm=kp(),Mm=$p(),Bm=ln(([e,t,r],{material:s})=>{const i=(s.side===L?Cm:Mm).sample(e),n=bo(Kl.x).mul(wm(t,r));return Rm(i,n)}),Fm=ln(([e,t,r])=>(hn(r.notEqual(0),()=>{const s=yo(t).negate().div(r);return mo(s.negate().mul(e))}),Nn(1))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),Lm=ln(([e,t,r,s,i,n,a,o,u,l,d,c,h,p,g])=>{let m,f;if(g){m=An().toVar(),f=Nn().toVar();const i=d.sub(1).mul(g.mul(.025)),n=Nn(d.sub(i),d,d.add(i));Rp({start:0,end:3},({i:i})=>{const d=n.element(i),g=Am(e,t,c,d,o),y=a.add(g),b=l.mul(u.mul(An(y,1))),x=xn(b.xy.div(b.w)).toVar();x.addAssign(1),x.divAssign(2),x.assign(xn(x.x,x.y.oneMinus()));const T=Bm(x,r,d);m.element(i).assign(T.element(i)),m.a.addAssign(T.a),f.element(i).assign(s.element(i).mul(Fm(Lo(g),h,p).element(i)))}),m.a.divAssign(3)}else{const i=Am(e,t,c,d,o),n=a.add(i),g=l.mul(u.mul(An(n,1))),y=xn(g.xy.div(g.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(xn(y.x,y.y.oneMinus())),m=Bm(y,r,d),f=s.mul(Fm(Lo(i),h,p))}const y=f.rgb.mul(m.rgb),b=e.dot(t).clamp(),x=Nn(nm({dotNV:b,specularColor:i,specularF90:n,roughness:r})),T=f.r.add(f.g,f.b).div(3);return An(x.oneMinus().mul(y),m.a.oneMinus().mul(T).oneMinus())}),Pm=Fn(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),Dm=(e,t)=>e.sub(t).div(e.add(t)).pow2(),Um=ln(({outsideIOR:e,eta2:t,cosTheta1:r,thinFilmThickness:s,baseF0:i})=>{const n=au(e,t,du(0,.03,s)),a=e.div(n).pow2().mul(r.pow2().oneMinus()).oneMinus();hn(a.lessThan(0),()=>Nn(1));const o=a.sqrt(),u=Dm(n,e),l=Og({f0:u,f90:1,dotVH:r}),d=l.oneMinus(),c=n.lessThan(e).select(Math.PI,0),h=mn(Math.PI).sub(c),p=(e=>{const t=e.sqrt();return Nn(1).add(t).div(Nn(1).sub(t))})(i.clamp(0,.9999)),g=Dm(p,n.toVec3()),m=Og({f0:g,f90:1,dotVH:o}),f=Nn(p.x.lessThan(n).select(Math.PI,0),p.y.lessThan(n).select(Math.PI,0),p.z.lessThan(n).select(Math.PI,0)),y=n.mul(s,o,2),b=Nn(h).add(f),x=l.mul(m).clamp(1e-5,.9999),T=x.sqrt(),_=d.pow2().mul(m).div(Nn(1).sub(x)),v=l.add(_).toVar(),N=_.sub(d).toVar();return Rp({start:1,end:2,condition:"<=",name:"m"},({m:e})=>{N.mulAssign(T);const t=((e,t)=>{const r=e.mul(2*Math.PI*1e-9),s=Nn(54856e-17,44201e-17,52481e-17),i=Nn(1681e3,1795300,2208400),n=Nn(43278e5,93046e5,66121e5),a=mn(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(r.mul(2239900).add(t.x).cos()).mul(r.pow2().mul(-45282e5).exp());let o=s.mul(n.mul(2*Math.PI).sqrt()).mul(i.mul(r).add(t).cos()).mul(r.pow2().negate().mul(n).exp());return o=Nn(o.x.add(a),o.y,o.z).div(1.0685e-7),Pm.mul(o)})(mn(e).mul(y),mn(e).mul(b)).mul(2);v.addAssign(N.mul(t))}),v.max(Nn(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"}]}),Im=ln(({normal:e,viewDir:t,roughness:r})=>{const s=e.dot(t).saturate(),i=r.mul(r),n=r.add(.1).reciprocal(),a=mn(-1.9362).add(r.mul(1.0678)).add(i.mul(.4573)).sub(n.mul(.8469)),o=mn(-.6014).add(r.mul(.5538)).sub(i.mul(.467)).sub(n.mul(.1255));return a.mul(s).add(o).exp().saturate()}),Om=Nn(.04),Vm=mn(1);class km extends Pg{constructor(e=!1,t=!1,r=!1,s=!1,i=!1,n=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=r,this.anisotropy=s,this.transmission=i,this.dispersion=n,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null,this.iridescenceF0Dielectric=null,this.iridescenceF0Metallic=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=Nn().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Nn().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Nn().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Nn().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Nn().toVar("sheenSpecularIndirect")),!0===this.iridescence){const e=dc.dot(ec).clamp(),t=Um({outsideIOR:mn(1),eta2:Kn,cosTheta1:e,thinFilmThickness:Yn,baseF0:ta}),r=Um({outsideIOR:mn(1),eta2:Kn,cosTheta1:e,thinFilmThickness:Yn,baseF0:Vn.rgb});this.iridescenceFresnel=au(t,r,zn),this.iridescenceF0Dielectric=am({f:t,f90:1,dotVH:e}),this.iridescenceF0Metallic=am({f:r,f90:1,dotVH:e}),this.iridescenceF0=au(this.iridescenceF0Dielectric,this.iridescenceF0Metallic,zn)}if(!0===this.transmission){const t=Qd,r=Sd.sub(Qd).normalize(),s=cc,i=e.context;i.backdrop=Lm(s,r,$n,kn,ra,sa,t,Ud,_d,xd,la,ca,pa,ha,this.dispersion?ga:null),i.backdropAlpha=da,Vn.a.mulAssign(au(1,i.backdrop.a,da))}super.start(e)}computeMultiscattering(e,t,r,s,i=null){const n=dc.dot(ec).clamp(),a=sm({roughness:$n,dotNV:n}),o=i?Xn.mix(s,i):s,u=o.mul(a.x).add(r.mul(a.y)),l=a.x.add(a.y).oneMinus(),d=o.add(o.oneMinus().mul(.047619)),c=u.mul(d).div(l.mul(d).oneMinus());e.addAssign(u),t.addAssign(c.mul(l))}direct({lightDirection:e,lightColor:t,reflectedLight:r}){const s=dc.dot(e).clamp().mul(t).toVar();if(!0===this.sheen){this.sheenSpecularDirect.addAssign(s.mul(lm({lightDirection:e})));const t=Im({normal:dc,viewDir:ec,roughness:jn}),r=Im({normal:dc,viewDir:e,roughness:jn}),i=qn.r.max(qn.g).max(qn.b).mul(t.max(r)).oneMinus();s.mulAssign(i)}if(!0===this.clearcoat){const r=hc.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(r.mul(em({lightDirection:e,f0:Om,f90:Vm,roughness:Hn,normalView:hc})))}r.directDiffuse.addAssign(s.mul(Vg({diffuseColor:kn}))),r.directSpecular.addAssign(s.mul(im({lightDirection:e,f0:ra,f90:1,roughness:$n,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:r,halfHeight:s,reflectedLight:i,ltc_1:n,ltc_2:a}){const o=t.add(r).sub(s),u=t.sub(r).sub(s),l=t.sub(r).add(s),d=t.add(r).add(s),c=dc,h=ec,p=Jd.toVar(),g=dm({N:c,V:h,roughness:$n}),m=n.sample(g).toVar(),f=a.sample(g).toVar(),y=Fn(Nn(m.x,0,m.y),Nn(0,1,0),Nn(m.z,0,m.w)).toVar(),b=ra.mul(f.x).add(sa.sub(ra).mul(f.y)).toVar();if(i.directSpecular.addAssign(e.mul(b).mul(pm({N:c,V:h,P:p,mInv:y,p0:o,p1:u,p2:l,p3:d}))),i.directDiffuse.addAssign(e.mul(kn).mul(pm({N:c,V:h,P:p,mInv:Fn(1,0,0,0,1,0,0,0,1),p0:o,p1:u,p2:l,p3:d}))),!0===this.clearcoat){const t=hc,r=dm({N:t,V:h,roughness:Hn}),s=n.sample(r),i=a.sample(r),c=Fn(Nn(s.x,0,s.y),Nn(0,1,0),Nn(s.z,0,s.w)),g=Om.mul(i.x).add(Vm.sub(Om).mul(i.y));this.clearcoatSpecularDirect.addAssign(e.mul(g).mul(pm({N:t,V:h,P:p,mInv:c,p0:o,p1:u,p2:l,p3:d})))}}indirect(e){this.indirectDiffuse(e),this.indirectSpecular(e),this.ambientOcclusion(e)}indirectDiffuse(e){const{irradiance:t,reflectedLight:r}=e.context,s=t.mul(Vg({diffuseColor:kn})).toVar();if(!0===this.sheen){const e=Im({normal:dc,viewDir:ec,roughness:jn}),t=qn.r.max(qn.g).max(qn.b).mul(e).oneMinus();s.mulAssign(t)}r.indirectDiffuse.addAssign(s)}indirectSpecular(e){const{radiance:t,iblIrradiance:r,reflectedLight:s}=e.context;if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(r.mul(qn,Im({normal:dc,viewDir:ec,roughness:jn}))),!0===this.clearcoat){const e=hc.dot(ec).clamp(),t=nm({dotNV:e,specularColor:Om,specularF90:Vm,roughness:Hn});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(t))}const i=Nn().toVar("singleScatteringDielectric"),n=Nn().toVar("multiScatteringDielectric"),a=Nn().toVar("singleScatteringMetallic"),o=Nn().toVar("multiScatteringMetallic");this.computeMultiscattering(i,n,sa,ta,this.iridescenceF0Dielectric),this.computeMultiscattering(a,o,sa,Vn.rgb,this.iridescenceF0Metallic);const u=au(i,a,zn),l=au(n,o,zn),d=i.add(n),c=kn.mul(d.oneMinus()),h=r.mul(1/Math.PI),p=t.mul(u).add(l.mul(h)).toVar(),g=c.mul(h).toVar();if(!0===this.sheen){const e=Im({normal:dc,viewDir:ec,roughness:jn}),t=qn.r.max(qn.g).max(qn.b).mul(e).oneMinus();p.mulAssign(t),g.mulAssign(t)}s.indirectSpecular.addAssign(p),s.indirectDiffuse.addAssign(g)}ambientOcclusion(e){const{ambientOcclusion:t,reflectedLight:r}=e.context,s=dc.dot(ec).clamp().add(t),i=$n.mul(-16).oneMinus().negate().exp2(),n=t.sub(s.pow(i).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(t),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(t),r.indirectDiffuse.mulAssign(t),r.indirectSpecular.mulAssign(n)}finish({context:e}){const{outgoingLight:t}=e;if(!0===this.clearcoat){const e=hc.dot(ec).clamp(),r=Og({dotVH:e,f0:Om,f90:Vm}),s=t.mul(Wn.mul(r).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(Wn));t.assign(s)}if(!0===this.sheen){const e=t.add(this.sheenSpecularDirect,this.sheenSpecularIndirect.mul(1/Math.PI));t.assign(e)}}}const Gm=mn(1),$m=mn(-2),zm=mn(.8),Wm=mn(-1),Hm=mn(.4),qm=mn(2),jm=mn(.305),Xm=mn(3),Km=mn(.21),Ym=mn(4),Qm=mn(4),Zm=mn(16),Jm=ln(([e])=>{const t=Nn(Bo(e)).toVar(),r=mn(-1).toVar();return hn(t.x.greaterThan(t.z),()=>{hn(t.x.greaterThan(t.y),()=>{r.assign(xu(e.x.greaterThan(0),0,3))}).Else(()=>{r.assign(xu(e.y.greaterThan(0),1,4))})}).Else(()=>{hn(t.z.greaterThan(t.y),()=>{r.assign(xu(e.z.greaterThan(0),2,5))}).Else(()=>{r.assign(xu(e.y.greaterThan(0),1,4))})}),r}).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),ef=ln(([e,t])=>{const r=xn().toVar();return hn(t.equal(0),()=>{r.assign(xn(e.z,e.y).div(Bo(e.x)))}).ElseIf(t.equal(1),()=>{r.assign(xn(e.x.negate(),e.z.negate()).div(Bo(e.y)))}).ElseIf(t.equal(2),()=>{r.assign(xn(e.x.negate(),e.y).div(Bo(e.z)))}).ElseIf(t.equal(3),()=>{r.assign(xn(e.z.negate(),e.y).div(Bo(e.x)))}).ElseIf(t.equal(4),()=>{r.assign(xn(e.x.negate(),e.z).div(Bo(e.y)))}).Else(()=>{r.assign(xn(e.x,e.y).div(Bo(e.z)))}),La(.5,r.add(1))}).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),tf=ln(([e])=>{const t=mn(0).toVar();return hn(e.greaterThanEqual(zm),()=>{t.assign(Gm.sub(e).mul(Wm.sub($m)).div(Gm.sub(zm)).add($m))}).ElseIf(e.greaterThanEqual(Hm),()=>{t.assign(zm.sub(e).mul(qm.sub(Wm)).div(zm.sub(Hm)).add(Wm))}).ElseIf(e.greaterThanEqual(jm),()=>{t.assign(Hm.sub(e).mul(Xm.sub(qm)).div(Hm.sub(jm)).add(qm))}).ElseIf(e.greaterThanEqual(Km),()=>{t.assign(jm.sub(e).mul(Ym.sub(Xm)).div(jm.sub(Km)).add(Xm))}).Else(()=>{t.assign(mn(-2).mul(bo(La(1.16,e))))}),t}).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),rf=ln(([e,t])=>{const r=e.toVar();r.assign(La(2,r).sub(1));const s=Nn(r,1).toVar();return hn(t.equal(0),()=>{s.assign(s.zyx)}).ElseIf(t.equal(1),()=>{s.assign(s.xzy),s.xz.mulAssign(-1)}).ElseIf(t.equal(2),()=>{s.x.mulAssign(-1)}).ElseIf(t.equal(3),()=>{s.assign(s.zyx),s.xz.mulAssign(-1)}).ElseIf(t.equal(4),()=>{s.assign(s.xzy),s.xy.mulAssign(-1)}).ElseIf(t.equal(5),()=>{s.z.mulAssign(-1)}),s}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),sf=ln(([e,t,r,s,i,n])=>{const a=mn(r),o=Nn(t),u=ou(tf(a),$m,n),l=So(u),d=_o(u),c=Nn(nf(e,o,d,s,i,n)).toVar();return hn(l.notEqual(0),()=>{const t=Nn(nf(e,o,d.add(1),s,i,n)).toVar();c.assign(au(c,t,l))}),c}),nf=ln(([e,t,r,s,i,n])=>{const a=mn(r).toVar(),o=Nn(t),u=mn(Jm(o)).toVar(),l=mn(qo(Qm.sub(a),0)).toVar();a.assign(qo(a,Qm));const d=mn(fo(a)).toVar(),c=xn(ef(o,u).mul(d.sub(2)).add(1)).toVar();return hn(u.greaterThan(2),()=>{c.y.addAssign(d),u.subAssign(3)}),c.x.addAssign(u.mul(d)),c.x.addAssign(l.mul(La(3,Zm))),c.y.addAssign(La(4,fo(n).sub(d))),c.x.mulAssign(s),c.y.mulAssign(i),e.sample(c).grad(xn(),xn())}),af=ln(({envMap:e,mipInt:t,outputDirection:r,theta:s,axis:i,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:a,CUBEUV_MAX_MIP:o})=>{const u=Eo(s),l=r.mul(u).add(i.cross(r).mul(Ro(s))).add(i.mul(i.dot(r).mul(u.oneMinus())));return nf(e,l,t,n,a,o)}),of=ln(({n:e,latitudinal:t,poleAxis:r,outputDirection:s,weights:i,samples:n,dTheta:a,mipInt:o,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})=>{const h=Nn(xu(t,r,Zo(r,s))).toVar();hn(h.equal(Nn(0)),()=>{h.assign(Nn(s.z,0,s.x.negate()))}),h.assign(No(h));const p=Nn().toVar();return p.addAssign(i.element(0).mul(af({theta:0,axis:h,outputDirection:s,mipInt:o,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),Rp({start:fn(1),end:e},({i:e})=>{hn(e.greaterThanEqual(n),()=>{Ep()});const t=mn(a.mul(mn(e))).toVar();p.addAssign(i.element(e).mul(af({theta:t.mul(-1),axis:h,outputDirection:s,mipInt:o,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),p.addAssign(i.element(e).mul(af({theta:t,axis:h,outputDirection:s,mipInt:o,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})))}),An(p,1)}),uf=ln(([e])=>{const t=yn(e).toVar();return t.assign(t.shiftLeft(yn(16)).bitOr(t.shiftRight(yn(16)))),t.assign(t.bitAnd(yn(1431655765)).shiftLeft(yn(1)).bitOr(t.bitAnd(yn(2863311530)).shiftRight(yn(1)))),t.assign(t.bitAnd(yn(858993459)).shiftLeft(yn(2)).bitOr(t.bitAnd(yn(3435973836)).shiftRight(yn(2)))),t.assign(t.bitAnd(yn(252645135)).shiftLeft(yn(4)).bitOr(t.bitAnd(yn(4042322160)).shiftRight(yn(4)))),t.assign(t.bitAnd(yn(16711935)).shiftLeft(yn(8)).bitOr(t.bitAnd(yn(4278255360)).shiftRight(yn(8)))),mn(t).mul(2.3283064365386963e-10)}),lf=ln(([e,t])=>xn(mn(e).div(mn(t)),uf(e))),df=ln(([e,t,r])=>{const s=r.mul(r).toConst(),i=Nn(1,0,0).toConst(),n=Zo(t,i).toConst(),a=xo(e.x).toConst(),o=La(2,3.14159265359).mul(e.y).toConst(),u=a.mul(Eo(o)).toConst(),l=a.mul(Ro(o)).toVar(),d=La(.5,t.z.add(1)).toConst();l.assign(d.oneMinus().mul(xo(u.mul(u).oneMinus())).add(d.mul(l)));const c=i.mul(u).add(n.mul(l)).add(t.mul(xo(qo(0,u.mul(u).add(l.mul(l)).oneMinus()))));return No(Nn(s.mul(c.x),s.mul(c.y),qo(0,c.z)))}),cf=ln(({roughness:e,mipInt:t,envMap:r,N_immutable:s,GGX_SAMPLES:i,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:a,CUBEUV_MAX_MIP:o})=>{const u=Nn(s).toVar(),l=Nn(0).toVar(),d=mn(0).toVar();return hn(e.lessThan(.001),()=>{l.assign(nf(r,u,t,n,a,o))}).Else(()=>{const s=xu(Bo(u.z).lessThan(.999),Nn(0,0,1),Nn(1,0,0)),c=No(Zo(s,u)).toVar(),h=Zo(u,c).toVar();Rp({start:yn(0),end:i},({i:s})=>{const p=lf(s,i),g=df(p,Nn(0,0,1),e),m=No(c.mul(g.x).add(h.mul(g.y)).add(u.mul(g.z))),f=No(m.mul(Qo(u,m).mul(2)).sub(u)),y=qo(Qo(u,f),0);hn(y.greaterThan(0),()=>{const e=nf(r,f,t,n,a,o);l.addAssign(e.mul(y)),d.addAssign(y)})}),hn(d.greaterThan(0),()=>{l.assign(l.div(d))})}),An(l,1)}),hf=[.125,.215,.35,.446,.526,.582],pf=20,gf=new Se(-1,1,1,-1,0,1),mf=new Re(90,1),ff=new e;let yf=null,bf=0,xf=0;const Tf=new r,_f=new WeakMap,vf=[3,1,5,0,4,2],Nf=rf(El(),Rl("faceIndex")).normalize(),Sf=Nn(Nf.x,Nf.y,Nf.z);class Rf{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._ggxMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}get _hasInitialized(){return this._renderer.hasInitialized()}fromScene(e,t=0,r=.1,s=100,i={}){const{size:n=256,position:a=Tf,renderTarget:o=null}=i;if(this._setSize(n),!1===this._hasInitialized){d('PMREMGenerator: ".fromScene()" called before the backend is initialized. Try using "await renderer.init()" instead.');const n=o||this._allocateTarget();return i.renderTarget=n,this.fromSceneAsync(e,t,r,s,i),n}yf=this._renderer.getRenderTarget(),bf=this._renderer.getActiveCubeFace(),xf=this._renderer.getActiveMipmapLevel();const u=o||this._allocateTarget();return u.depthBuffer=!0,this._init(u),this._sceneToCubeUV(e,r,s,u,a),t>0&&this._blur(u,0,0,t),this._applyPMREM(u),this._cleanup(u),u}async fromSceneAsync(e,t=0,r=.1,s=100,i={}){return v('PMREMGenerator: ".fromSceneAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this.fromScene(e,t,r,s,i)}fromEquirectangular(e,t=null){if(!1===this._hasInitialized){d('PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Try using "await renderer.init()" instead.'),this._setSizeFromTexture(e);const r=t||this._allocateTarget();return this.fromEquirectangularAsync(e,r),r}return this._fromTexture(e,t)}async fromEquirectangularAsync(e,t=null){return v('PMREMGenerator: ".fromEquirectangularAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}fromCubemap(e,t=null){if(!1===this._hasInitialized){d("PMREMGenerator: .fromCubemap() called before the backend is initialized. Try using .fromCubemapAsync() instead."),this._setSizeFromTexture(e);const r=t||this._allocateTarget();return this.fromCubemapAsync(e,t),r}return this._fromTexture(e,t)}async fromCubemapAsync(e,t=null){return v('PMREMGenerator: ".fromCubemapAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=Cf(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=Mf(),await 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())}_setSizeFromTexture(e){e.mapping===I||e.mapping===O?this._setSize(0===e.image.length?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4)}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._ggxMaterial&&this._ggxMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodMeshes.length;e++)this._lodMeshes[e].geometry.dispose()}_cleanup(e){this._renderer.setRenderTarget(yf,bf,xf),e.scissorTest=!1,Af(e,0,0,e.width,e.height)}_fromTexture(e,t){this._setSizeFromTexture(e),yf=this._renderer.getRenderTarget(),bf=this._renderer.getActiveCubeFace(),xf=this._renderer.getActiveMipmapLevel();const r=t||this._allocateTarget();return this._init(r),this._textureToCubeUV(e,r),this._applyPMREM(r),this._cleanup(r),r}_allocateTarget(){return Ef(3*Math.max(this._cubeSize,112),4*this._cubeSize)}_init(e){if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==e.width||this._pingPongRenderTarget.height!==e.height){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=Ef(e.width,e.height);const{_lodMax:t}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=function(e){const t=[],r=[],s=[];let i=e;const n=e-4+1+hf.length;for(let a=0;a<n;a++){const n=Math.pow(2,i);t.push(n);let o=1/n;a>e-4?o=hf[a-e+4-1]:0===a&&(o=0),r.push(o);const u=1/(n-2),l=-u,d=1+u,c=[l,l,d,l,d,d,l,l,d,d,l,d],h=6,p=6,g=3,m=2,f=1,y=new Float32Array(g*p*h),b=new Float32Array(m*p*h),x=new Float32Array(f*p*h);for(let e=0;e<h;e++){const t=e%3*2/3-1,r=e>2?0:-1,s=[t,r,0,t+2/3,r,0,t+2/3,r+1,0,t,r,0,t+2/3,r+1,0,t,r+1,0],i=vf[e];y.set(s,g*p*i),b.set(c,m*p*i);const n=[i,i,i,i,i,i];x.set(n,f*p*i)}const T=new Ne;T.setAttribute("position",new Ce(y,g)),T.setAttribute("uv",new Ce(b,m)),T.setAttribute("faceIndex",new Ce(x,f)),s.push(new ue(T,null)),i>4&&i--}return{lodMeshes:s,sizeLods:t,sigmas:r}}(t)),this._blurMaterial=function(e,t,s){const i=Gl(new Array(pf).fill(0)),n=va(new r(0,1,0)),a=va(0),o=mn(pf),u=va(0),l=va(1),d=Dl(),c=va(0),h=mn(1/t),p=mn(1/s),g=mn(e),m={n:o,latitudinal:u,weights:i,poleAxis:n,outputDirection:Sf,dTheta:a,samples:l,envMap:d,mipInt:c,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:g},f=wf("blur");return f.fragmentNode=of({...m,latitudinal:u.equal(1)}),_f.set(f,m),f}(t,e.width,e.height),this._ggxMaterial=function(e,t,r){const s=Dl(),i=va(0),n=va(0),a=mn(1/t),o=mn(1/r),u=mn(e),l={envMap:s,roughness:i,mipInt:n,CUBEUV_TEXEL_WIDTH:a,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:u},d=wf("ggx");return d.fragmentNode=cf({...l,N_immutable:Sf,GGX_SAMPLES:yn(512)}),_f.set(d,l),d}(t,e.width,e.height)}}async _compileMaterial(e){const t=new ue(new Ne,e);await this._renderer.compile(t,gf)}_sceneToCubeUV(e,t,r,s,i){const n=mf;n.near=t,n.far=r;const a=[1,1,1,1,-1,1],o=[1,-1,1,-1,1,-1],u=this._renderer,l=u.autoClear;u.getClearColor(ff),u.autoClear=!1,null===this._backgroundBox&&(this._backgroundBox=new ue(new oe,new ye({name:"PMREM.Background",side:L,depthWrite:!1,depthTest:!1})));const d=this._backgroundBox,c=d.material;let h=!1;const p=e.background;p?p.isColor&&(c.color.copy(p),e.background=null,h=!0):(c.color.copy(ff),h=!0),u.setRenderTarget(s),u.clear(),h&&u.render(d,n);for(let t=0;t<6;t++){const r=t%3;0===r?(n.up.set(0,a[t],0),n.position.set(i.x,i.y,i.z),n.lookAt(i.x+o[t],i.y,i.z)):1===r?(n.up.set(0,0,a[t]),n.position.set(i.x,i.y,i.z),n.lookAt(i.x,i.y+o[t],i.z)):(n.up.set(0,a[t],0),n.position.set(i.x,i.y,i.z),n.lookAt(i.x,i.y,i.z+o[t]));const l=this._cubeSize;Af(s,r*l,t>2?l:0,l,l),u.render(e,n)}u.autoClear=l,e.background=p}_textureToCubeUV(e,t){const r=this._renderer,s=e.mapping===I||e.mapping===O;s?null===this._cubemapMaterial&&(this._cubemapMaterial=Cf(e)):null===this._equirectMaterial&&(this._equirectMaterial=Mf(e));const i=s?this._cubemapMaterial:this._equirectMaterial;i.fragmentNode.value=e;const n=this._lodMeshes[0];n.material=i;const a=this._cubeSize;Af(t,0,0,3*a,2*a),r.setRenderTarget(t),r.render(n,gf)}_applyPMREM(e){const t=this._renderer,r=t.autoClear;t.autoClear=!1;const s=this._lodMeshes.length;for(let t=1;t<s;t++)this._applyGGXFilter(e,t-1,t);t.autoClear=r}_applyGGXFilter(e,t,r){const s=this._renderer,i=this._pingPongRenderTarget,n=this._ggxMaterial,a=this._lodMeshes[r];a.material=n;const o=_f.get(n),u=r/(this._lodMeshes.length-1),l=t/(this._lodMeshes.length-1),d=Math.sqrt(u*u-l*l)*(0+1.25*u),{_lodMax:c}=this,h=this._sizeLods[r],p=3*h*(r>c-4?r-c+4:0),g=4*(this._cubeSize-h);e.texture.frame=(e.texture.frame||0)+1,o.envMap.value=e.texture,o.roughness.value=d,o.mipInt.value=c-t,Af(i,p,g,3*h,2*h),s.setRenderTarget(i),s.render(a,gf),i.texture.frame=(i.texture.frame||0)+1,o.envMap.value=i.texture,o.roughness.value=0,o.mipInt.value=c-r,Af(e,p,g,3*h,2*h),s.setRenderTarget(e),s.render(a,gf)}_blur(e,t,r,s,i){const n=this._pingPongRenderTarget;this._halfBlur(e,n,t,r,s,"latitudinal",i),this._halfBlur(n,e,r,r,s,"longitudinal",i)}_halfBlur(e,t,r,s,i,n,a){const u=this._renderer,l=this._blurMaterial;"latitudinal"!==n&&"longitudinal"!==n&&o("blur direction must be either latitudinal or longitudinal!");const c=this._lodMeshes[s];c.material=l;const h=_f.get(l),p=this._sizeLods[r]-1,g=isFinite(i)?Math.PI/(2*p):2*Math.PI/39,m=i/g,f=isFinite(i)?1+Math.floor(3*m):pf;f>pf&&d(`sigmaRadians, ${i}, is too large and will clip, as it requested ${f} samples when the maximum is set to 20`);const y=[];let b=0;for(let e=0;e<pf;++e){const t=e/m,r=Math.exp(-t*t/2);y.push(r),0===e?b+=r:e<f&&(b+=2*r)}for(let e=0;e<y.length;e++)y[e]=y[e]/b;e.texture.frame=(e.texture.frame||0)+1,h.envMap.value=e.texture,h.samples.value=f,h.weights.array=y,h.latitudinal.value="latitudinal"===n?1:0,a&&(h.poleAxis.value=a);const{_lodMax:x}=this;h.dTheta.value=g,h.mipInt.value=x-r;const T=this._sizeLods[s];Af(t,3*T*(s>x-4?s-x+4:0),4*(this._cubeSize-T),3*T,2*T),u.setRenderTarget(t),u.render(c,gf)}}function Ef(e,t){const r=new ae(e,t,{magFilter:de,minFilter:de,generateMipmaps:!1,type:_e,format:Ae,colorSpace:Ee});return r.texture.mapping=we,r.texture.name="PMREM.cubeUv",r.texture.isPMREMTexture=!0,r.scissorTest=!0,r}function Af(e,t,r,s,i){e.viewport.set(t,r,s,i),e.scissor.set(t,r,s,i)}function wf(e){const t=new fg;return t.depthTest=!1,t.depthWrite=!1,t.blending=se,t.name=`PMREM_${e}`,t}function Cf(e){const t=wf("cubemap");return t.fragmentNode=Mc(e,Sf),t}function Mf(e){const t=wf("equirect");return t.fragmentNode=Dl(e,Rg(Sf),0),t}const Bf=new WeakMap;function Ff(e,t,r){const s=function(e){let t=Bf.get(e);void 0===t&&(t=new WeakMap,Bf.set(e,t));return t}(t);let i=s.get(e);if((void 0!==i?i.pmremVersion:-1)!==e.pmremVersion){const t=e.image;if(e.isCubeTexture){if(!function(e){if(null==e)return!1;let t=0;const r=6;for(let s=0;s<r;s++)void 0!==e[s]&&t++;return t===r}(t))return null;i=r.fromCubemap(e,i)}else{if(!function(e){return null!=e&&e.height>0}(t))return null;i=r.fromEquirectangular(e,i)}i.pmremVersion=e.pmremVersion,s.set(e,i)}return i.texture}class Lf extends hi{static get type(){return"PMREMNode"}constructor(e,t=null,r=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=r,this._generator=null;const s=new N;s.isRenderTargetTexture=!0,this._texture=Dl(s),this._width=va(0),this._height=va(0),this._maxMip=va(0),this.updateBeforeType=ei.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=function(e){const t=Math.log2(e)-2,r=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:r,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(e){let t=this._pmrem;const r=t?t.pmremVersion:-1,s=this._value;r!==s.pmremVersion&&(t=!0===s.isPMREMTexture?s:Ff(s,e.renderer,this._generator),null!==t&&(this._pmrem=t,this.updateFromTexture(t)))}setup(e){null===this._generator&&(this._generator=new Rf(e.renderer)),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this,e)),t=vc.mul(Nn(t.x,t.y.negate(),t.z));let r=this.levelNode;return null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),sf(this._texture,t,r,this._width,this._height,this._maxMip)}dispose(){super.dispose(),null!==this._generator&&this._generator.dispose()}}const Pf=sn(Lf).setParameterLength(1,3),Df=new WeakMap;class Uf extends Fp{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const s=r.isTextureNode?r.value:t[r.property],i=this._getPMREMNodeCache(e.renderer);let n=i.get(s);void 0===n&&(n=Pf(s),i.set(s,n)),r=n}const s=!0===t.useAnisotropy||t.anisotropy>0?uh:dc,i=r.context(If($n,s)).mul(_c),n=r.context(Of(cc)).mul(Math.PI).mul(_c),a=ol(i),o=ol(n);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(o);const u=e.context.lightingModel.clearcoatRadiance;if(u){const e=r.context(If(Hn,hc)).mul(_c),t=ol(e);u.addAssign(t)}}_getPMREMNodeCache(e){let t=Df.get(e);return void 0===t&&(t=new WeakMap,Df.set(e,t)),t}}const If=(e,t)=>{let r=null;return{getUV:()=>(null===r&&(r=ec.negate().reflect(t),r=ru(e).mix(r,t).normalize(),r=r.transformDirection(_d)),r),getTextureLevel:()=>e}},Of=e=>({getUV:()=>e,getTextureLevel:()=>mn(1)}),Vf=new Me;class kf extends fg{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(Vf),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new Uf(t):null}setupLightingModel(){return new km}setupSpecular(){const e=au(Nn(.04),Vn.rgb,zn);ta.assign(Nn(.04)),ra.assign(e),sa.assign(1)}setupVariants(){const e=this.metalnessNode?mn(this.metalnessNode):Mh;zn.assign(e);let t=this.roughnessNode?mn(this.roughnessNode):Ch;t=Xg({roughness:t}),$n.assign(t),this.setupSpecular(),kn.assign(Vn.rgb.mul(e.oneMinus()))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const Gf=new Be;class $f extends kf{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){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(Gf),this.setValues(e)}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 e=this.iorNode?mn(this.iorNode):Wh;la.assign(e),ta.assign(Ho(eu(la.sub(1).div(la.add(1))).mul(Eh),Nn(1)).mul(Rh)),ra.assign(au(ta,Vn.rgb,zn)),sa.assign(au(Rh,1,zn))}setupLightingModel(){return new km(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const e=this.clearcoatNode?mn(this.clearcoatNode):Fh,t=this.clearcoatRoughnessNode?mn(this.clearcoatRoughnessNode):Lh;Wn.assign(e),Hn.assign(Xg({roughness:t}))}if(this.useSheen){const e=this.sheenNode?Nn(this.sheenNode):Uh,t=this.sheenRoughnessNode?mn(this.sheenRoughnessNode):Ih;qn.assign(e),jn.assign(t)}if(this.useIridescence){const e=this.iridescenceNode?mn(this.iridescenceNode):Vh,t=this.iridescenceIORNode?mn(this.iridescenceIORNode):kh,r=this.iridescenceThicknessNode?mn(this.iridescenceThicknessNode):Gh;Xn.assign(e),Kn.assign(t),Yn.assign(r)}if(this.useAnisotropy){const e=(this.anisotropyNode?xn(this.anisotropyNode):Oh).toVar();Zn.assign(e.length()),hn(Zn.equal(0),()=>{e.assign(xn(1,0))}).Else(()=>{e.divAssign(xn(Zn)),Zn.assign(Zn.saturate())}),Qn.assign(Zn.pow2().mix($n.pow2(),1)),Jn.assign(ah[0].mul(e.x).add(ah[1].mul(e.y))),ea.assign(ah[1].mul(e.x).sub(ah[0].mul(e.y)))}if(this.useTransmission){const e=this.transmissionNode?mn(this.transmissionNode):$h,t=this.thicknessNode?mn(this.thicknessNode):zh,r=this.attenuationDistanceNode?mn(this.attenuationDistanceNode):Hh,s=this.attenuationColorNode?Nn(this.attenuationColorNode):qh;if(da.assign(e),ca.assign(t),ha.assign(r),pa.assign(s),this.useDispersion){const e=this.dispersionNode?mn(this.dispersionNode):Jh;ga.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Nn(this.clearcoatNormalNode):Ph}setup(e){e.context.setupClearcoatNormal=()=>Lu(this.setupClearcoatNormal(e),"NORMAL","vec3"),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.iorNode=e.iorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}class zf extends km{constructor(e=!1,t=!1,r=!1,s=!1,i=!1,n=!1,a=!1){super(e,t,r,s,i,n),this.useSSS=a}direct({lightDirection:e,lightColor:t,reflectedLight:r},s){if(!0===this.useSSS){const i=s.material,{thicknessColorNode:n,thicknessDistortionNode:a,thicknessAmbientNode:o,thicknessAttenuationNode:u,thicknessPowerNode:l,thicknessScaleNode:d}=i,c=e.add(dc.mul(a)).normalize(),h=mn(ec.dot(c.negate()).saturate().pow(l).mul(d)),p=Nn(h.add(o).mul(n));r.directDiffuse.addAssign(p.mul(u.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:r},s)}}class Wf extends $f{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=mn(.1),this.thicknessAmbientNode=mn(0),this.thicknessAttenuationNode=mn(.1),this.thicknessPowerNode=mn(2),this.thicknessScaleNode=mn(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new zf(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion,this.useSSS)}copy(e){return this.thicknessColorNode=e.thicknessColorNode,this.thicknessDistortionNode=e.thicknessDistortionNode,this.thicknessAmbientNode=e.thicknessAmbientNode,this.thicknessAttenuationNode=e.thicknessAttenuationNode,this.thicknessPowerNode=e.thicknessPowerNode,this.thicknessScaleNode=e.thicknessScaleNode,super.copy(e)}}const Hf=ln(({normal:e,lightDirection:t,builder:r})=>{const s=e.dot(t),i=xn(s.mul(.5).add(.5),0);if(r.material.gradientMap){const e=Uc("gradientMap","texture").context({getUV:()=>i});return Nn(e.r)}{const e=i.fwidth().mul(.5);return au(Nn(.7),Nn(1),du(mn(.7).sub(e.x),mn(.7).add(e.x),i.x))}});class qf extends Pg{direct({lightDirection:e,lightColor:t,reflectedLight:r},s){const i=Hf({normal:nc,lightDirection:e,builder:s}).mul(t);r.directDiffuse.addAssign(i.mul(Vg({diffuseColor:Vn.rgb})))}indirect(e){const{ambientOcclusion:t,irradiance:r,reflectedLight:s}=e.context;s.indirectDiffuse.addAssign(r.mul(Vg({diffuseColor:Vn}))),s.indirectDiffuse.mulAssign(t)}}const jf=new Fe;class Xf extends fg{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(jf),this.setValues(e)}setupLightingModel(){return new qf}}const Kf=ln(()=>{const e=Nn(ec.z,0,ec.x.negate()).normalize(),t=ec.cross(e);return xn(e.dot(dc),t.dot(dc)).mul(.495).add(.5)}).once(["NORMAL","VERTEX"])().toVar("matcapUV"),Yf=new Le;class Qf extends fg{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(Yf),this.setValues(e)}setupVariants(e){const t=Kf;let r;r=e.material.matcap?Uc("matcap","texture").context({getUV:()=>t}):Nn(au(.2,.8,t.y)),Vn.rgb.mulAssign(r.rgb)}}class Zf extends hi{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:r}=this;if("vec2"===this.getNodeType(e)){const e=t.cos(),s=t.sin();return Bn(e,s,s.negate(),e).mul(r)}{const e=t,s=Ln(An(1,0,0,0),An(0,Eo(e.x),Ro(e.x).negate(),0),An(0,Ro(e.x),Eo(e.x),0),An(0,0,0,1)),i=Ln(An(Eo(e.y),0,Ro(e.y),0),An(0,1,0,0),An(Ro(e.y).negate(),0,Eo(e.y),0),An(0,0,0,1)),n=Ln(An(Eo(e.z),Ro(e.z).negate(),0,0),An(Ro(e.z),Eo(e.z),0,0),An(0,0,1,0),An(0,0,0,1));return s.mul(i).mul(n).mul(An(r,1)).xyz}}}const Jf=sn(Zf).setParameterLength(2),ey=new Pe;class ty extends fg{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.transparent=!0,this.setDefaultValues(ey),this.setValues(e)}setupPositionView(e){const{object:t,camera:r}=e,{positionNode:s,rotationNode:i,scaleNode:n,sizeAttenuation:a}=this,o=zd.mul(Nn(s||0));let u=xn(Ud[0].xyz.length(),Ud[1].xyz.length());null!==n&&(u=u.mul(xn(n))),r.isPerspectiveCamera&&!1===a&&(u=u.mul(o.z.negate()));let l=Xd.xy;if(t.center&&!0===t.center.isVector2){const e=((e,t,r)=>new Wu(e,t,r))("center","vec2",t);l=l.sub(e.sub(.5))}l=l.mul(u);const d=mn(i||Dh),c=Jf(l,d);return An(o.xy.add(c),o.zw)}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}const ry=new De,sy=new t;class iy extends ty{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.sizeNode=null,this.isPointsNodeMaterial=!0,this.setDefaultValues(ry),this.setValues(e)}setupPositionView(){const{positionNode:e}=this;return zd.mul(Nn(e||Kd)).xyz}setupVertexSprite(e){const{material:t,camera:r}=e,{rotationNode:s,scaleNode:i,sizeNode:n,sizeAttenuation:a}=this;let o=super.setupVertex(e);if(!0!==t.isNodeMaterial)return o;let u=null!==n?xn(n):Zh;u=u.mul(jl),r.isPerspectiveCamera&&!0===a&&(u=u.mul(ny.div(Jd.z.negate()))),i&&i.isNode&&(u=u.mul(xn(i)));let l=Xd.xy;if(s&&s.isNode){const e=mn(s);l=Jf(l,e)}return l=l.mul(u),l=l.div(Zl.div(2)),l=l.mul(o.w),o=o.add(An(l,0,0)),o}setupVertex(e){return e.object.isPoints?super.setupVertex(e):this.setupVertexSprite(e)}get alphaToCoverage(){return this._useAlphaToCoverage}set alphaToCoverage(e){this._useAlphaToCoverage!==e&&(this._useAlphaToCoverage=e,this.needsUpdate=!0)}}const ny=va(1).onFrameUpdate(function({renderer:e}){const t=e.getSize(sy);this.value=.5*t.y});class ay extends Pg{constructor(){super(),this.shadowNode=mn(1).toVar("shadowMask")}direct({lightNode:e}){null!==e.shadowNode&&this.shadowNode.mulAssign(e.shadowNode)}finish({context:e}){Vn.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(Vn.rgb)}}const oy=new Ue;class uy extends fg{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.transparent=!0,this.setDefaultValues(oy),this.setValues(e)}setupLightingModel(){return new ay}}const ly=In("vec3"),dy=In("vec3"),cy=In("vec3");class hy extends Pg{constructor(){super()}start(e){const{material:t}=e,r=In("vec3"),s=In("vec3");hn(Sd.sub(Qd).length().greaterThan(kd.mul(2)),()=>{r.assign(Sd),s.assign(Qd)}).Else(()=>{r.assign(Qd),s.assign(Sd)});const i=s.sub(r),n=va("int").onRenderUpdate(({material:e})=>e.steps),a=i.length().div(n).toVar(),o=i.normalize().toVar(),u=mn(0).toVar(),l=Nn(1).toVar();t.offsetNode&&u.addAssign(t.offsetNode.mul(a)),Rp(n,()=>{const s=r.add(o.mul(u)),i=_d.mul(An(s,1)).xyz;let n;null!==t.depthNode&&(dy.assign(tg(Kp(i.z,yd,bd))),e.context.sceneDepthNode=tg(t.depthNode).toVar()),e.context.positionWorld=s,e.context.shadowPositionWorld=s,e.context.positionView=i,ly.assign(0),t.scatteringNode&&(n=t.scatteringNode({positionRay:s})),super.start(e),n&&ly.mulAssign(n);const d=ly.mul(.01).negate().mul(a).exp();l.mulAssign(d),u.addAssign(a)}),cy.addAssign(l.saturate().oneMinus())}scatteringLight(e,t){const r=t.context.sceneDepthNode;r?hn(r.greaterThanEqual(dy),()=>{ly.addAssign(e)}):ly.addAssign(e)}direct({lightNode:e,lightColor:t},r){if(void 0===e.light.distance)return;const s=t.xyz.toVar();s.mulAssign(e.shadowNode),this.scatteringLight(s,r)}directRectArea({lightColor:e,lightPosition:t,halfWidth:r,halfHeight:s},i){const n=t.add(r).sub(s),a=t.sub(r).sub(s),o=t.sub(r).add(s),u=t.add(r).add(s),l=i.context.positionView,d=e.xyz.mul(gm({P:l,p0:n,p1:a,p2:o,p3:u})).pow(1.5);this.scatteringLight(d,i)}finish(e){e.context.outgoingLight.assign(cy)}}class py extends fg{static get type(){return"VolumeNodeMaterial"}constructor(e){super(),this.isVolumeNodeMaterial=!0,this.steps=25,this.offsetNode=null,this.scatteringNode=null,this.lights=!0,this.transparent=!0,this.side=L,this.depthTest=!1,this.depthWrite=!1,this.setValues(e)}setupLightingModel(){return new hy}}class gy{constructor(e,t,r){this.renderer=e,this.nodes=t,this.info=r,this._context="undefined"!=typeof self?self:null,this._animationLoop=null,this._requestId=null}start(){const e=(t,r)=>{this._requestId=this._context.requestAnimationFrame(e),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,this.renderer._inspector.begin(),null!==this._animationLoop&&this._animationLoop(t,r),this.renderer._inspector.finish()};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}getAnimationLoop(){return this._animationLoop}setAnimationLoop(e){this._animationLoop=e}getContext(){return this._context}setContext(e){this._context=e}dispose(){this.stop()}}class my{constructor(){this.weakMaps={}}_getWeakMap(e){const t=e.length;let r=this.weakMaps[t];return void 0===r&&(r=new WeakMap,this.weakMaps[t]=r),r}get(e){let t=this._getWeakMap(e);for(let r=0;r<e.length-1;r++)if(t=t.get(e[r]),void 0===t)return;return t.get(e[e.length-1])}set(e,t){let r=this._getWeakMap(e);for(let t=0;t<e.length-1;t++){const s=e[t];!1===r.has(s)&&r.set(s,new WeakMap),r=r.get(s)}return r.set(e[e.length-1],t),this}delete(e){let t=this._getWeakMap(e);for(let r=0;r<e.length-1;r++)if(t=t.get(e[r]),void 0===t)return!1;return t.delete(e[e.length-1])}}let fy=0;class yy{constructor(e,t,r,s,i,n,a,o,u,l){this.id=fy++,this._nodes=e,this._geometries=t,this.renderer=r,this.object=s,this.material=i,this.scene=n,this.camera=a,this.lightsNode=o,this.context=u,this.geometry=s.geometry,this.version=i.version,this.drawRange=null,this.attributes=null,this.attributesId=null,this.pipeline=null,this.group=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.clippingContext=l,this.clippingContextCacheKey=null!==l?l.cacheKey:"",this.initialNodesCacheKey=this.getDynamicCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=null,this._monitor=null,this.onDispose=null,this.isRenderObject=!0,this.onMaterialDispose=()=>{this.dispose()},this.onGeometryDispose=()=>{this.attributes=null,this.attributesId=null},this.material.addEventListener("dispose",this.onMaterialDispose),this.geometry.addEventListener("dispose",this.onGeometryDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.material.hardwareClipping?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().observer)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getBindingGroup(e){for(const t of this.getBindings())if(t.name===e)return t}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getIndirectOffset(){return this._geometries.getIndirectOffset(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null,this.attributesId=null}getAttributes(){if(null!==this.attributes)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,r=[],s=new Set,i={};for(const n of e){let e;if(n.node&&n.node.attribute?e=n.node.attribute:(e=t.getAttribute(n.name),i[n.name]=e.id),void 0===e)continue;r.push(e);const a=e.isInterleavedBufferAttribute?e.data:e;s.add(a)}return this.attributes=r,this.attributesId=i,this.vertexBuffers=Array.from(s.values()),r}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:r,group:s,drawRange:i}=this,n=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),a=this.getIndex(),o=null!==a;let u=1;if(!0===r.isInstancedBufferGeometry?u=r.instanceCount:void 0!==e.count&&(u=Math.max(0,e.count)),0===u)return null;if(n.instanceCount=u,!0===e.isBatchedMesh)return n;let l=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(l=2);let d=i.start*l,c=(i.start+i.count)*l;null!==s&&(d=Math.max(d,s.start*l),c=Math.min(c,(s.start+s.count)*l));const h=r.attributes.position;let p=1/0;o?p=a.count:null!=h&&(p=h.count),d=Math.max(d,0),c=Math.min(c,p);const g=c-d;return g<0||g===1/0?null:(n.vertexCount=g,n.firstVertex=d,n)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const r of Object.keys(e.attributes).sort()){const s=e.attributes[r];t+=r+",",s.data&&(t+=s.data.stride+","),s.offset&&(t+=s.offset+","),s.itemSize&&(t+=s.itemSize+","),s.normalized&&(t+="n,")}for(const r of Object.keys(e.morphAttributes).sort()){const s=e.morphAttributes[r];t+="morph-"+r+",";for(let e=0,r=s.length;e<r;e++){t+=s[e].id+","}}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t,renderer:r}=this;let s=t.customProgramCacheKey();for(const e of function(e){const t=Object.keys(e);let r=Object.getPrototypeOf(e);for(;r;){const e=Object.getOwnPropertyDescriptors(r);for(const r in e)if(void 0!==e[r]){const s=e[r];s&&"function"==typeof s.get&&t.push(r)}r=Object.getPrototypeOf(r)}return t}(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;const i=t[e];let n;if(null!==i){const e=typeof i;"number"===e?n=0!==i?"1":"0":"object"===e?(n="{",i.isTexture&&(n+=i.mapping,!0===r.backend.isWebGPUBackend&&(n+=i.magFilter,n+=i.minFilter,n+=i.wrapS,n+=i.wrapT,n+=i.wrapR)),n+="}"):n=String(i)}else n=String(i);s+=n+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(s+=e._colorsTexture.uuid+",")),(e.isInstancedMesh||e.count>1||Array.isArray(e.morphTargetInfluences))&&(s+=e.uuid+","),s+=this.context.id+",",s+=e.receiveShadow+",",Is(s)}get needsGeometryUpdate(){if(this.geometry.id!==this.object.geometry.id)return!0;if(null!==this.attributes){const e=this.attributesId;for(const t in e){const r=this.geometry.getAttribute(t);if(void 0===r||e[t]!==r.id)return!0}}return!1}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=0;return!0!==this.material.isShadowPassMaterial&&(e=this._nodes.getCacheKey(this.scene,this.lightsNode)),this.camera.isArrayCamera&&(e=Vs(e,this.camera.cameras.length)),this.object.receiveShadow&&(e=Vs(e,1)),e=Vs(e,this.renderer.contextNode.id,this.renderer.contextNode.version),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.geometry.removeEventListener("dispose",this.onGeometryDispose),this.onDispose()}}const by=[];class xy{constructor(e,t,r,s,i,n){this.renderer=e,this.nodes=t,this.geometries=r,this.pipelines=s,this.bindings=i,this.info=n,this.chainMaps={}}get(e,t,r,s,i,n,a,o){const u=this.getChainMap(o);by[0]=e,by[1]=t,by[2]=n,by[3]=i;let l=u.get(by);return void 0===l?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,r,s,i,n,a,o),u.set(by,l)):(l.camera=s,l.updateClipping(a),l.needsGeometryUpdate&&l.setGeometry(e.geometry),(l.version!==t.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(e,t,r,s,i,n,a,o)):l.version=t.version)),by[0]=null,by[1]=null,by[2]=null,by[3]=null,l}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new my)}dispose(){this.chainMaps={}}createRenderObject(e,t,r,s,i,n,a,o,u,l,d){const c=this.getChainMap(d),h=new yy(e,t,r,s,i,n,a,o,u,l);return h.onDispose=()=>{this.pipelines.delete(h),this.bindings.deleteForRender(h),this.nodes.delete(h),c.delete(h.getChainArray())},h}}class Ty{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t=null;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const _y=1,vy=2,Ny=3,Sy=4,Ry=16;class Ey extends Ty{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return null!==t&&this.backend.destroyAttribute(e),t}update(e,t){const r=this.get(e);if(void 0===r.version)t===_y?this.backend.createAttribute(e):t===vy?this.backend.createIndexAttribute(e):t===Ny?this.backend.createStorageAttribute(e):t===Sy&&this.backend.createIndirectStorageAttribute(e),r.version=this._getBufferAttribute(e).version;else{const t=this._getBufferAttribute(e);(r.version<t.version||t.usage===x)&&(this.backend.updateAttribute(e),r.version=t.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}function Ay(e){return null!==e.index?e.index.version:e.attributes.position.version}function wy(e){return null!==e.index?e.index.id:e.attributes.position.id}function Cy(e){const t=[],r=e.index,s=e.attributes.position;if(null!==r){const e=r.array;for(let r=0,s=e.length;r<s;r+=3){const s=e[r+0],i=e[r+1],n=e[r+2];t.push(s,i,i,n,n,s)}}else{for(let e=0,r=s.array.length/3-1;e<r;e+=3){const r=e+0,s=e+1,i=e+2;t.push(r,s,s,i,i,r)}}const i=new(s.count>=65535?Ie:Oe)(t,1);return i.version=Ay(e),i.__id=wy(e),i}class My extends Ty{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap,this._geometryDisposeListeners=new Map}has(e){const t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;const r=()=>{this.info.memory.geometries--;const s=t.index,i=e.getAttributes();null!==s&&this.attributes.delete(s);for(const e of i)this.attributes.delete(e);const n=this.wireframes.get(t);void 0!==n&&this.attributes.delete(n),t.removeEventListener("dispose",r),this._geometryDisposeListeners.delete(t)};t.addEventListener("dispose",r),this._geometryDisposeListeners.set(t,r)}updateAttributes(e){const t=e.getAttributes();for(const e of t)e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute?this.updateAttribute(e,Ny):this.updateAttribute(e,_y);const r=this.getIndex(e);null!==r&&this.updateAttribute(r,vy);const s=e.geometry.indirect;null!==s&&this.updateAttribute(s,Sy)}updateAttribute(e,t){const r=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,r)):this.attributeCall.get(e.data)!==r&&(this.attributes.update(e,t),this.attributeCall.set(e.data,r),this.attributeCall.set(e,r)):this.attributeCall.get(e)!==r&&(this.attributes.update(e,t),this.attributeCall.set(e,r))}getIndirect(e){return e.geometry.indirect}getIndirectOffset(e){return e.geometry.indirectOffset}getIndex(e){const{geometry:t,material:r}=e;let s=t.index;if(!0===r.wireframe){const e=this.wireframes;let r=e.get(t);void 0===r?(r=Cy(t),e.set(t,r)):r.version===Ay(t)&&r.__id===wy(t)||(this.attributes.delete(r),r=Cy(t),e.set(t,r)),s=r}return s}dispose(){for(const[e,t]of this._geometryDisposeListeners.entries())e.removeEventListener("dispose",t);this._geometryDisposeListeners.clear()}}class By{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},this.compute={calls:0,frameCalls:0,timestamp:0},this.memory={geometries:0,textures:0}}update(e,t,r){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=r*(t/3):e.isPoints?this.render.points+=r*t:e.isLineSegments?this.render.lines+=r*(t/2):e.isLine?this.render.lines+=r*(t-1):o("WebGPUInfo: Unknown object type.")}reset(){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 Fy{constructor(e){this.cacheKey=e,this.usedTimes=0}}class Ly extends Fy{constructor(e,t,r){super(e),this.vertexProgram=t,this.fragmentProgram=r}}class Py extends Fy{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Dy=0;class Uy{constructor(e,t,r,s=null,i=null){this.id=Dy++,this.code=e,this.stage=t,this.name=r,this.transforms=s,this.attributes=i,this.usedTimes=0}}class Iy extends Ty{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:r}=this,s=this.get(e);if(this._needsComputeUpdate(e)){const i=s.pipeline;i&&(i.usedTimes--,i.computeProgram.usedTimes--);const n=this.nodes.getForCompute(e);let a=this.programs.compute.get(n.computeShader);void 0===a&&(i&&0===i.computeProgram.usedTimes&&this._releaseProgram(i.computeProgram),a=new Uy(n.computeShader,"compute",e.name,n.transforms,n.nodeAttributes),this.programs.compute.set(n.computeShader,a),r.createProgram(a));const o=this._getComputeCacheKey(e,a);let u=this.caches.get(o);void 0===u&&(i&&0===i.usedTimes&&this._releasePipeline(i),u=this._getComputePipeline(e,a,o,t)),u.usedTimes++,a.usedTimes++,s.version=e.version,s.pipeline=u}return s.pipeline}getForRender(e,t=null){const{backend:r}=this,s=this.get(e);if(this._needsRenderUpdate(e)){const i=s.pipeline;i&&(i.usedTimes--,i.vertexProgram.usedTimes--,i.fragmentProgram.usedTimes--);const n=e.getNodeBuilderState(),a=e.material?e.material.name:"";let o=this.programs.vertex.get(n.vertexShader);void 0===o&&(i&&0===i.vertexProgram.usedTimes&&this._releaseProgram(i.vertexProgram),o=new Uy(n.vertexShader,"vertex",a),this.programs.vertex.set(n.vertexShader,o),r.createProgram(o));let u=this.programs.fragment.get(n.fragmentShader);void 0===u&&(i&&0===i.fragmentProgram.usedTimes&&this._releaseProgram(i.fragmentProgram),u=new Uy(n.fragmentShader,"fragment",a),this.programs.fragment.set(n.fragmentShader,u),r.createProgram(u));const l=this._getRenderCacheKey(e,o,u);let d=this.caches.get(l);void 0===d?(i&&0===i.usedTimes&&this._releasePipeline(i),d=this._getRenderPipeline(e,o,u,l,t)):e.pipeline=d,d.usedTimes++,o.usedTimes++,u.usedTimes++,s.pipeline=d}return s.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,r,s){r=r||this._getComputeCacheKey(e,t);let i=this.caches.get(r);return void 0===i&&(i=new Py(r,t),this.caches.set(r,i),this.backend.createComputePipeline(i,s)),i}_getRenderPipeline(e,t,r,s,i){s=s||this._getRenderCacheKey(e,t,r);let n=this.caches.get(s);return void 0===n&&(n=new Ly(s,t,r),this.caches.set(s,n),e.pipeline=n,this.backend.createRenderPipeline(e,i)),n}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,r){return t.id+","+r.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,r=e.stage;this.programs[r].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class Oy extends Ty{constructor(e,t,r,s,i,n){super(),this.backend=e,this.textures=r,this.pipelines=i,this.attributes=s,this.nodes=t,this.info=n,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const e of t){const r=this.get(e);void 0===r.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),r.bindGroup=e)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t){const r=this.get(e);void 0===r.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),r.bindGroup=e)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}deleteForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t)this.backend.deleteBindGroupData(e),this.delete(e)}deleteForRender(e){const t=e.getBindings();for(const e of t)this.backend.deleteBindGroupData(e),this.delete(e)}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isSampler)this.textures.updateSampler(t.texture);else if(t.isStorageBuffer){const e=t.attribute,r=e.isIndirectStorageBufferAttribute?Sy:Ny;this.attributes.update(e,r)}}_update(e,t){const{backend:r}=this;let s=!1,i=!0,n=0,a=0;for(const t of e.bindings){if(!1!==this.nodes.updateGroup(t)){if(t.isStorageBuffer){const e=t.attribute,i=e.isIndirectStorageBufferAttribute?Sy:Ny,n=r.get(t);this.attributes.update(e,i),n.attribute!==e&&(n.attribute=e,s=!0)}if(t.isUniformBuffer){t.update()&&r.updateBinding(t)}else if(t.isSampledTexture){const o=t.update(),u=t.texture,l=this.textures.get(u);o&&(this.textures.updateTexture(u),t.generation!==l.generation&&(t.generation=l.generation,s=!0),l.bindGroups.add(e));if(void 0!==r.get(u).externalTexture||l.isDefaultTexture?i=!1:(n=10*n+u.id,a+=u.version),!0===u.isStorageTexture&&!0===u.mipmapsAutoUpdate){const e=this.get(u);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(u)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(u),e.needsMipmap=!1)}}else if(t.isSampler){if(t.update()){const e=this.textures.updateSampler(t.texture);t.samplerKey!==e&&(t.samplerKey=e,s=!0)}}t.isBuffer&&t.updateRanges.length>0&&t.clearUpdateRanges()}}!0===s&&this.backend.updateBindings(e,t,i?n:0,a)}}function Vy(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?e.z-t.z:e.id-t.id}function ky(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function Gy(e){return(e.transmission>0||e.transmissionNode&&e.transmissionNode.isNode)&&e.side===P&&!1===e.forceSinglePass}class $y{constructor(e,t,r){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,r),this.lightsArray=[],this.scene=t,this.camera=r,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,r,s,i,n,a){let o=this.renderItems[this.renderItemsIndex];return void 0===o?(o={id:e.id,object:e,geometry:t,material:r,groupOrder:s,renderOrder:e.renderOrder,z:i,group:n,clippingContext:a},this.renderItems[this.renderItemsIndex]=o):(o.id=e.id,o.object=e,o.geometry=t,o.material=r,o.groupOrder=s,o.renderOrder=e.renderOrder,o.z=i,o.group=n,o.clippingContext=a),this.renderItemsIndex++,o}push(e,t,r,s,i,n,a){const o=this.getNextRenderItem(e,t,r,s,i,n,a);!0===e.occlusionTest&&this.occlusionQueryCount++,!0===r.transparent||r.transmission>0||r.transmissionNode&&r.transmissionNode.isNode||r.backdropNode&&r.backdropNode.isNode?(Gy(r)&&this.transparentDoublePass.push(o),this.transparent.push(o)):this.opaque.push(o)}unshift(e,t,r,s,i,n,a){const o=this.getNextRenderItem(e,t,r,s,i,n,a);!0===r.transparent||r.transmission>0||r.transmissionNode&&r.transmissionNode.isNode||r.backdropNode&&r.backdropNode.isNode?(Gy(r)&&this.transparentDoublePass.unshift(o),this.transparent.unshift(o)):this.opaque.unshift(o)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||Vy),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||ky),this.transparent.length>1&&this.transparent.sort(t||ky)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){const t=this.renderItems[e];if(null===t.id)break;t.id=null,t.object=null,t.geometry=null,t.material=null,t.groupOrder=null,t.renderOrder=null,t.z=null,t.group=null,t.clippingContext=null}}}const zy=[];class Wy{constructor(e){this.lighting=e,this.lists=new my}get(e,t){const r=this.lists;zy[0]=e,zy[1]=t;let s=r.get(zy);return void 0===s&&(s=new $y(this.lighting,e,t),r.set(zy,s)),zy[0]=null,zy[1]=null,s}dispose(){this.lists=new my}}let Hy=0;class qy{constructor(){this.id=Hy++,this.mrt=null,this.color=!0,this.clearColor=!0,this.clearColorValue={r:0,g:0,b:0,a:1},this.depth=!0,this.clearDepth=!0,this.clearDepthValue=1,this.stencil=!1,this.clearStencil=!0,this.clearStencilValue=1,this.viewport=!1,this.viewportValue=new s,this.scissor=!1,this.scissorValue=new s,this.renderTarget=null,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.activeMipmapLevel=0,this.sampleCount=1,this.width=0,this.height=0,this.occlusionQueryCount=0,this.clippingContext=null,this.camera=null,this.isRenderContext=!0}getCacheKey(){return jy(this)}}function jy(e){const{textures:t,activeCubeFace:r,activeMipmapLevel:s}=e,i=[r,s];for(const e of t)i.push(e.id);return Os(i)}class Xy{constructor(e){this.renderer=e,this._renderContexts={}}get(e=null,t=null,r=0){let s;if(null===e)s="default";else{const t=e.texture.format,r=e.texture.type;s=`${e.textures.length}:${t}:${r}:${e.samples}:${e.depthBuffer}:${e.stencilBuffer}`}const i=s+"-"+(null!==t?t.id:"default")+"-"+r;let n=this._renderContexts[i];return void 0===n&&(n=new qy,n.mrt=t,this._renderContexts[i]=n),null!==e&&(n.sampleCount=0===e.samples?1:e.samples),n.clearDepthValue=this.renderer.getClearDepth(),n.clearStencilValue=this.renderer.getClearStencil(),n}dispose(){this._renderContexts={}}}const Ky=new r;class Yy extends Ty{constructor(e,t,r){super(),this.renderer=e,this.backend=t,this.info=r}updateRenderTarget(e,t=0){const r=this.get(e),s=0===e.samples?1:e.samples,i=r.depthTextureMips||(r.depthTextureMips={}),n=e.textures,a=this.getSize(n[0]),o=a.width>>t,u=a.height>>t;let l=e.depthTexture||i[t];const d=!0===e.depthBuffer||!0===e.stencilBuffer;let c=!1;void 0===l&&d&&(l=new J,l.format=e.stencilBuffer?Ve:ke,l.type=e.stencilBuffer?Ge:S,l.image.width=o,l.image.height=u,l.image.depth=a.depth,l.renderTarget=e,l.isArrayTexture=!0===e.multiview&&a.depth>1,i[t]=l),r.width===a.width&&a.height===r.height||(c=!0,l&&(l.needsUpdate=!0,l.image.width=o,l.image.height=u,l.image.depth=l.isArrayTexture?l.image.depth:1)),r.width=a.width,r.height=a.height,r.textures=n,r.depthTexture=l||null,r.depth=e.depthBuffer,r.stencil=e.stencilBuffer,r.renderTarget=e,r.sampleCount!==s&&(c=!0,l&&(l.needsUpdate=!0),r.sampleCount=s);const h={sampleCount:s};if(!0!==e.isXRRenderTarget){for(let e=0;e<n.length;e++){const t=n[e];c&&(t.needsUpdate=!0),this.updateTexture(t,h)}l&&this.updateTexture(l,h)}!0!==r.initialized&&(r.initialized=!0,r.onDispose=()=>{this._destroyRenderTarget(e)},e.addEventListener("dispose",r.onDispose))}updateTexture(e,t={}){const r=this.get(e);if(!0===r.initialized&&r.version===e.version)return;const s=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,i=this.backend;if(s&&!0===r.initialized&&i.destroyTexture(e),e.isFramebufferTexture){const t=this.renderer.getRenderTarget();e.type=t?t.texture.type:$e}const{width:n,height:a,depth:o}=this.getSize(e);if(t.width=n,t.height=a,t.depth=o,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,n,a):1,e.isCubeTexture&&e.mipmaps.length>0&&t.levels++,s||!0===e.isStorageTexture||!0===e.isExternalTexture)i.createTexture(e,t),r.generation=e.version;else if(e.version>0){const s=e.image;if(void 0===s)d("Renderer: Texture marked for update but image is undefined.");else if(!1===s.complete)d("Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const r=[];for(const t of e.images)r.push(t);t.images=r}else t.image=s;void 0!==r.isDefaultTexture&&!0!==r.isDefaultTexture||(i.createTexture(e,t),r.isDefaultTexture=!1,r.generation=e.version),!0===e.source.dataReady&&i.updateTexture(e,t);const n=!0===e.isStorageTexture&&!1===e.mipmapsAutoUpdate;t.needsMipmaps&&0===e.mipmaps.length&&!n&&i.generateMipmaps(e),e.onUpdate&&e.onUpdate(e)}}else i.createDefaultTexture(e),r.isDefaultTexture=!0,r.generation=e.version;!0!==r.initialized&&(r.initialized=!0,r.generation=e.version,r.bindGroups=new Set,this.info.memory.textures++,e.isVideoTexture&&!0===p.enabled&&p.getTransfer(e.colorSpace)!==g&&d("WebGPURenderer: Video textures must use a color space with a sRGB transfer function, e.g. SRGBColorSpace."),r.onDispose=()=>{this._destroyTexture(e)},e.addEventListener("dispose",r.onDispose)),r.version=e.version}updateSampler(e){return this.backend.updateSampler(e)}getSize(e,t=Ky){let r=e.images?e.images[0]:e.image;return r?(void 0!==r.image&&(r=r.image),"undefined"!=typeof HTMLVideoElement&&r instanceof HTMLVideoElement?(t.width=r.videoWidth||1,t.height=r.videoHeight||1,t.depth=1):"undefined"!=typeof VideoFrame&&r instanceof VideoFrame?(t.width=r.displayWidth||1,t.height=r.displayHeight||1,t.depth=1):(t.width=r.width||1,t.height=r.height||1,t.depth=e.isCubeTexture?6:r.depth||1)):t.width=t.height=t.depth=1,t}getMipLevels(e,t,r){let s;return s=e.mipmaps.length>0?e.mipmaps.length:!0===e.isCompressedTexture?1:Math.floor(Math.log2(Math.max(t,r)))+1,s}needsMipmaps(e){return!0===e.generateMipmaps||e.mipmaps.length>0}_destroyRenderTarget(e){if(!0===this.has(e)){const t=this.get(e),r=t.textures,s=t.depthTexture;e.removeEventListener("dispose",t.onDispose);for(let e=0;e<r.length;e++)this._destroyTexture(r[e]);s&&this._destroyTexture(s),this.delete(e),this.backend.delete(e)}}_destroyTexture(e){if(!0===this.has(e)){const t=this.get(e);e.removeEventListener("dispose",t.onDispose);const r=t.isDefaultTexture;if(this.backend.destroyTexture(e,r),t.bindGroups)for(const e of t.bindGroups){const t=this.backend.get(e);t.groups=void 0,t.versions=void 0}this.delete(e),this.info.memory.textures--}}}class Qy extends e{constructor(e,t,r,s=1){super(e,t,r),this.a=s}set(e,t,r,s=1){return this.a=s,super.set(e,t,r)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class Zy extends Un{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getMemberType(e,t){const r=this.getNodeType(e),s=e.getStructTypeNode(r);let i;return null!==s?i=s.getMemberType(e,t):(o(`TSL: Member "${t}" not found in struct "${r}".`,new Ds),i="float"),i}getHash(){return this.uuid}generate(){return this.name}}class Jy extends li{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this._expressionNode=null,this._currentNode=null,this.isStackNode=!0}getElementType(e){return this.hasOutput(e)?this.outputNode.getElementType(e):"void"}getNodeType(e){return this.hasOutput(e)?this.outputNode.getNodeType(e):"void"}getMemberType(e,t){return this.hasOutput(e)?this.outputNode.getMemberType(e,t):"void"}addToStack(e,t=this.nodes.length){return!0!==e.isNode?(o("TSL: Invalid node added to stack.",new Ds),this):(this.nodes.splice(t,0,e),this)}addToStackBefore(e){const t=this._currentNode?this.nodes.indexOf(this._currentNode):0;return this.addToStack(e,t)}If(e,t){const r=new Zi(t);return this._currentCond=xu(e,r),this.addToStack(this._currentCond)}ElseIf(e,t){const r=new Zi(t),s=xu(e,r);return this._currentCond.elseNode=s,this._currentCond=s,this}Else(e){return this._currentCond.elseNode=new Zi(e),this}Switch(e){return this._expressionNode=Ji(e),this}Case(...e){const t=[];if(e.length>=2)for(let r=0;r<e.length-1;r++)t.push(this._expressionNode.equal(Ji(e[r])));else o("TSL: Invalid parameter length. Case() requires at least two parameters.",new Ds);const r=new Zi(e[e.length-1]);let s=t[0];for(let e=1;e<t.length;e++)s=s.or(t[e]);const i=xu(s,r);return null===this._currentCond?(this._currentCond=i,this.addToStack(this._currentCond)):(this._currentCond.elseNode=i,this._currentCond=i,this)}Default(e){return this.Else(e),this}setup(e){const t=e.getNodeProperties(this);let r=0;for(const s of this.getChildren())s.isVarNode&&s.isIntent(e)&&!0!==s.isAssign(e)||(t["node"+r++]=s);return t.outputNode||null}hasOutput(e){return this.outputNode&&this.outputNode.isNode&&"void"!==this.outputNode.getNodeType(e)}build(e,...t){const r=cn(),s=e.buildStage;dn(this),e.setActiveStack(this);const i=t=>{if(this._currentNode=t,!t.isVarNode||!t.isIntent(e)||!0===t.isAssign(e))if("setup"===s)t.build(e);else if("analyze"===s)t.build(e,this);else if("generate"===s){const r=e.getDataFromNode(t,"any").stages,s=r&&r[e.shaderStage];if(t.isVarNode&&s&&1===s.length&&s[0]&&s[0].isStackNode)return;t.build(e,"void")}},n=[...this.nodes];for(const e of n)i(e);this._currentNode=null;const a=this.nodes.filter(e=>-1===n.indexOf(e));for(const e of a)i(e);let o;return o=this.hasOutput(e)?this.outputNode.build(e,...t):super.build(e,...t),dn(r),e.removeActiveStack(this),o}}const eb=sn(Jy).setParameterLength(0,1);class tb extends li{static get type(){return"StructTypeNode"}constructor(e,t=null){var r;super("struct"),this.membersLayout=(r=e,Object.entries(r).map(([e,t])=>"string"==typeof t?{name:e,type:t,atomic:!1}:{name:e,type:t.type,atomic:t.atomic||!1})),this.name=t,this.isStructLayoutNode=!0}getLength(){const e=Float32Array.BYTES_PER_ELEMENT;let t=1,r=0;for(const s of this.membersLayout){const i=s.type,n=Hs(i),a=qs(i)/e;t=Math.max(t,a);const o=r%t%a;0!==o&&(r+=a-o),r+=n}return Math.ceil(r/t)*t}getMemberType(e,t){const r=this.membersLayout.find(e=>e.name===t);return r?r.type:"void"}getNodeType(e){return e.getStructTypeFromNode(this,this.membersLayout,this.name).name}setup(e){e.getStructTypeFromNode(this,this.membersLayout,this.name),e.addInclude(this)}generate(e){return this.getNodeType(e)}}class rb extends li{static get type(){return"StructNode"}constructor(e,t){super("vec3"),this.structTypeNode=e,this.values=t,this.isStructNode=!0}getNodeType(e){return this.structTypeNode.getNodeType(e)}getMemberType(e,t){return this.structTypeNode.getMemberType(e,t)}_getChildren(){const e=super._getChildren(),t=e.find(e=>e.childNode===this.structTypeNode);return e.splice(e.indexOf(t),1),e.push(t),e}generate(e){const t=e.getVarFromNode(this),r=t.type,s=e.getPropertyName(t);return e.addLineFlowCode(`${s} = ${e.generateStruct(r,this.structTypeNode.membersLayout,this.values)}`,this),t.name}}class sb extends li{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}getNodeType(){return"OutputType"}generate(e){const t=e.getDataFromNode(this);if(void 0===t.membersLayout){const r=this.members,s=[];for(let t=0;t<r.length;t++){const i="m"+t,n=r[t].getNodeType(e);s.push({name:i,type:n,index:t})}t.membersLayout=s,t.structType=e.getOutputStructTypeFromNode(this,t.membersLayout)}const r=e.getOutputStructName(),s=this.members,i=""!==r?r+".":"";for(let t=0;t<s.length;t++){const r=s[t].build(e);e.addLineFlowCode(`${i}m${t} = ${r}`,this)}return r}}const ib=sn(sb);class nb{constructor(e=ze){this.blending=e,this.blendSrc=We,this.blendDst=He,this.blendEquation=qe,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.premultiplyAlpha=!1}copy(e){return this.blending=e.blending,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.premultiplyAlpha=e.premultiplyAlpha,this}clone(){return(new this.constructor).copy(this)}}const ab=new nb(se),ob=new nb(je);function ub(e,t){for(let r=0;r<e.length;r++)if(e[r].name===t)return r;return-1}class lb extends sb{static get type(){return"MRTNode"}constructor(e){super(),this.outputNodes=e,this.blendModes={output:ob},this.isMRTNode=!0}setBlendMode(e,t){return this.blendModes[e]=t,this}getBlendMode(e){return this.blendModes[e]||ab}has(e){return void 0!==this.outputNodes[e]}get(e){return this.outputNodes[e]}merge(e){const t={...this.outputNodes,...e.outputNodes},r={...this.blendModes,...e.blendModes},s=db(t);return s.blendings=r,s}setup(e){const t=this.outputNodes,r=[],s=e.renderer.getRenderTarget().textures;for(const e in t){r[ub(s,e)]=An(t[e])}return this.members=r,super.setup(e)}}const db=sn(lb);class cb extends hi{static get type(){return"BitcastNode"}constructor(e,t,r=null){super(),this.valueNode=e,this.conversionType=t,this.inputType=r,this.isBitcastNode=!0}getNodeType(e){if(null!==this.inputType){const t=this.valueNode.getNodeType(e),r=e.getTypeLength(t);return e.getTypeFromLength(r,this.conversionType)}return this.conversionType}generate(e){const t=this.getNodeType(e);let r="";if(null!==this.inputType){const t=this.valueNode.getNodeType(e);r=1===e.getTypeLength(t)?this.inputType:e.changeComponentType(t,this.inputType)}else r=this.valueNode.getNodeType(e);return`${e.getBitcastMethod(t,r)}( ${this.valueNode.build(e,r)} )`}}const hb=an(cb).setParameterLength(2),pb=e=>new cb(e,"uint","float"),gb={};class mb extends so{static get type(){return"BitcountNode"}constructor(e,t){super(e,t),this.isBitcountNode=!0}_resolveElementType(e,t,r){"int"===r?t.assign(hb(e,"uint")):t.assign(e)}_returnDataNode(e){switch(e){case"uint":return yn;case"int":return fn;case"uvec2":return _n;case"uvec3":return Rn;case"uvec4":return Cn;case"ivec2":return Tn;case"ivec3":return Sn;case"ivec4":return wn}}_createTrailingZerosBaseLayout(e,t){const r=this._returnDataNode(t);return ln(([e])=>{const s=yn(0);this._resolveElementType(e,s,t);const i=mn(s.bitAnd(Po(s))),n=pb(i).shiftRight(23).sub(127);return r(n)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createLeadingZerosBaseLayout(e,t){const r=this._returnDataNode(t);return ln(([e])=>{hn(e.equal(yn(0)),()=>yn(32));const s=yn(0),i=yn(0);return this._resolveElementType(e,s,t),hn(s.shiftRight(16).equal(0),()=>{i.addAssign(16),s.shiftLeftAssign(16)}),hn(s.shiftRight(24).equal(0),()=>{i.addAssign(8),s.shiftLeftAssign(8)}),hn(s.shiftRight(28).equal(0),()=>{i.addAssign(4),s.shiftLeftAssign(4)}),hn(s.shiftRight(30).equal(0),()=>{i.addAssign(2),s.shiftLeftAssign(2)}),hn(s.shiftRight(31).equal(0),()=>{i.addAssign(1)}),r(i)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createOneBitsBaseLayout(e,t){const r=this._returnDataNode(t);return ln(([e])=>{const s=yn(0);this._resolveElementType(e,s,t),s.assign(s.sub(s.shiftRight(yn(1)).bitAnd(yn(1431655765)))),s.assign(s.bitAnd(yn(858993459)).add(s.shiftRight(yn(2)).bitAnd(yn(858993459))));const i=s.add(s.shiftRight(yn(4))).bitAnd(yn(252645135)).mul(yn(16843009)).shiftRight(yn(24));return r(i)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createMainLayout(e,t,r,s){const i=this._returnDataNode(t);return ln(([e])=>{if(1===r)return i(s(e));{const t=i(0),n=["x","y","z","w"];for(let i=0;i<r;i++){const r=n[i];t[r].assign(s(e[r]))}return t}}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}setup(e){const{method:t,aNode:r}=this,{renderer:s}=e;if(s.backend.isWebGPUBackend)return super.setup(e);const i=this.getInputType(e),n=e.getElementType(i),a=e.getTypeLength(i),o=`${t}_base_${n}`,u=`${t}_${i}`;let l=gb[o];if(void 0===l){switch(t){case mb.COUNT_LEADING_ZEROS:l=this._createLeadingZerosBaseLayout(o,n);break;case mb.COUNT_TRAILING_ZEROS:l=this._createTrailingZerosBaseLayout(o,n);break;case mb.COUNT_ONE_BITS:l=this._createOneBitsBaseLayout(o,n)}gb[o]=l}let d=gb[u];void 0===d&&(d=this._createMainLayout(u,i,a,l),gb[u]=d);return ln(()=>d(r))()}}mb.COUNT_TRAILING_ZEROS="countTrailingZeros",mb.COUNT_LEADING_ZEROS="countLeadingZeros",mb.COUNT_ONE_BITS="countOneBits";const fb=an(mb,mb.COUNT_TRAILING_ZEROS).setParameterLength(1),yb=an(mb,mb.COUNT_LEADING_ZEROS).setParameterLength(1),bb=an(mb,mb.COUNT_ONE_BITS).setParameterLength(1),xb=ln(([e])=>{const t=e.toUint().mul(747796405).add(2891336453),r=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return r.shiftRight(22).bitXor(r).toFloat().mul(1/2**32)}),Tb=(e,t)=>Jo(La(4,e.mul(Fa(1,e))),t);class _b extends hi{static get type(){return"PackFloatNode"}constructor(e,t){super(),this.vectorNode=t,this.encoding=e,this.isPackFloatNode=!0}getNodeType(){return"uint"}generate(e){const t=this.vectorNode.getNodeType(e);return`${e.getFloatPackingMethod(this.encoding)}(${this.vectorNode.build(e,t)})`}}const vb=an(_b,"snorm").setParameterLength(1),Nb=an(_b,"unorm").setParameterLength(1),Sb=an(_b,"float16").setParameterLength(1);class Rb extends hi{static get type(){return"UnpackFloatNode"}constructor(e,t){super(),this.uintNode=t,this.encoding=e,this.isUnpackFloatNode=!0}getNodeType(){return"vec2"}generate(e){const t=this.uintNode.getNodeType(e);return`${e.getFloatUnpackingMethod(this.encoding)}(${this.uintNode.build(e,t)})`}}const Eb=an(Rb,"snorm").setParameterLength(1),Ab=an(Rb,"unorm").setParameterLength(1),wb=an(Rb,"float16").setParameterLength(1),Cb=ln(([e])=>e.fract().sub(.5).abs()).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),Mb=ln(([e])=>Nn(Cb(e.z.add(Cb(e.y.mul(1)))),Cb(e.z.add(Cb(e.x.mul(1)))),Cb(e.y.add(Cb(e.x.mul(1)))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Bb=ln(([e,t,r])=>{const s=Nn(e).toVar(),i=mn(1.4).toVar(),n=mn(0).toVar(),a=Nn(s).toVar();return Rp({start:mn(0),end:mn(3),type:"float",condition:"<="},()=>{const e=Nn(Mb(a.mul(2))).toVar();s.addAssign(e.add(r.mul(mn(.1).mul(t)))),a.mulAssign(1.8),i.mulAssign(1.5),s.mulAssign(1.2);const o=mn(Cb(s.z.add(Cb(s.x.add(Cb(s.y)))))).toVar();n.addAssign(o.div(i)),a.addAssign(.14)}),n}).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"position",type:"vec3"},{name:"speed",type:"float"},{name:"time",type:"float"}]});class Fb extends li{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFn=null,this.global=!0}getNodeType(e){return this.getCandidateFn(e).shaderNode.layout.type}getCandidateFn(e){const t=this.parametersNodes;let r=this._candidateFn;if(null===r){let s=null,i=-1;for(const r of this.functionNodes){const n=r.shaderNode.layout;if(null===n)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const a=n.inputs;if(t.length===a.length){let n=0;for(let r=0;r<t.length;r++){const s=t[r],i=a[r];s.getNodeType(e)===i.type&&n++}n>i&&(s=r,i=n)}}this._candidateFn=r=s}return r}setup(e){return this.getCandidateFn(e)(...this.parametersNodes)}}const Lb=sn(Fb),Pb=e=>(...t)=>Lb(e,...t),Db=va(0).setGroup(xa).onRenderUpdate(e=>e.time),Ub=va(0).setGroup(xa).onRenderUpdate(e=>e.deltaTime),Ib=va(0,"uint").setGroup(xa).onRenderUpdate(e=>e.frameId);const Ob=ln(([e,t,r=xn(.5)])=>Jf(e.sub(r),t).add(r)),Vb=ln(([e,t,r=xn(.5)])=>{const s=e.sub(r),i=s.dot(s),n=i.mul(i).mul(t);return e.add(s.mul(n))}),kb=ln(({position:e=null,horizontal:t=!0,vertical:r=!1})=>{let s;null!==e?(s=Ud.toVar(),s[3][0]=e.x,s[3][1]=e.y,s[3][2]=e.z):s=Ud;const i=_d.mul(s);return Yi(t)&&(i[0][0]=Ud[0].length(),i[0][1]=0,i[0][2]=0),Yi(r)&&(i[1][0]=0,i[1][1]=Ud[1].length(),i[1][2]=0),i[2][0]=0,i[2][1]=0,i[2][2]=1,xd.mul(i).mul(Kd)}),Gb=ln(([e=null])=>{const t=tg();return tg(Hp(e)).sub(t).lessThan(0).select(Xl,e)}),$b=ln(([e,t=El(),r=mn(0)])=>{const s=e.x,i=e.y,n=r.mod(s.mul(i)).floor(),a=n.mod(s),o=i.sub(n.add(1).div(s).ceil()),u=e.reciprocal(),l=xn(a,o);return t.add(l).mul(u)}),zb=ln(([e,t=null,r=null,s=mn(1),i=Kd,n=ac])=>{let a=n.abs().normalize();a=a.div(a.dot(Nn(1)));const o=i.yz.mul(s),u=i.zx.mul(s),l=i.xy.mul(s),d=e.value,c=null!==t?t.value:d,h=null!==r?r.value:d,p=Dl(d,o).mul(a.x),g=Dl(c,u).mul(a.y),m=Dl(h,l).mul(a.z);return Ba(p,g,m)}),Wb=new Xe,Hb=new r,qb=new r,jb=new r,Xb=new a,Kb=new r(0,0,-1),Yb=new s,Qb=new r,Zb=new r,Jb=new s,ex=new t,tx=new ae,rx=Xl.flipX();tx.depthTexture=new J(1,1);let sx=!1;class ix extends Ll{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||tx.texture,rx),this._reflectorBaseNode=e.reflector||new nx(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(null===this._depthNode){if(!0!==this._reflectorBaseNode.depth)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=new ix({defaultTexture:tx.depthTexture,reflector:this._reflectorBaseNode})}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){const e=new this.constructor(this.reflectorNode);return e.uvNode=this.uvNode,e.levelNode=this.levelNode,e.biasNode=this.biasNode,e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.offsetNode=this.offsetNode,e._reflectorBaseNode=this._reflectorBaseNode,e}dispose(){super.dispose(),this._reflectorBaseNode.dispose()}}class nx extends li{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();const{target:r=new Ke,resolutionScale:s=1,generateMipmaps:i=!1,bounces:n=!0,depth:a=!1,samples:o=0}=t;this.textureNode=e,this.target=r,this.resolutionScale=s,void 0!==t.resolution&&(v('ReflectorNode: The "resolution" parameter has been renamed to "resolutionScale".'),this.resolutionScale=t.resolution),this.generateMipmaps=i,this.bounces=n,this.depth=a,this.samples=o,this.updateBeforeType=n?ei.RENDER:ei.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new Map,this.forceUpdate=!1,this.hasOutput=!1}_updateResolution(e,t){const r=this.resolutionScale;t.getDrawingBufferSize(ex),e.setSize(Math.round(ex.width*r),Math.round(ex.height*r))}setup(e){return this._updateResolution(tx,e.renderer),super.setup(e)}dispose(){super.dispose();for(const e of this.renderTargets.values())e.dispose()}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new ae(0,0,{type:_e,samples:this.samples}),!0===this.generateMipmaps&&(t.texture.minFilter=Ye,t.texture.generateMipmaps=!0),!0===this.depth&&(t.depthTexture=new J),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&sx)return!1;sx=!0;const{scene:t,camera:r,renderer:s,material:i}=e,{target:n}=this,a=this.getVirtualCamera(r),o=this.getRenderTarget(a);s.getDrawingBufferSize(ex),this._updateResolution(o,s),qb.setFromMatrixPosition(n.matrixWorld),jb.setFromMatrixPosition(r.matrixWorld),Xb.extractRotation(n.matrixWorld),Hb.set(0,0,1),Hb.applyMatrix4(Xb),Qb.subVectors(qb,jb);let u=!1;if(!0===Qb.dot(Hb)>0&&!1===this.forceUpdate){if(!1===this.hasOutput)return void(sx=!1);u=!0}Qb.reflect(Hb).negate(),Qb.add(qb),Xb.extractRotation(r.matrixWorld),Kb.set(0,0,-1),Kb.applyMatrix4(Xb),Kb.add(jb),Zb.subVectors(qb,Kb),Zb.reflect(Hb).negate(),Zb.add(qb),a.coordinateSystem=r.coordinateSystem,a.position.copy(Qb),a.up.set(0,1,0),a.up.applyMatrix4(Xb),a.up.reflect(Hb),a.lookAt(Zb),a.near=r.near,a.far=r.far,a.updateMatrixWorld(),a.projectionMatrix.copy(r.projectionMatrix),Wb.setFromNormalAndCoplanarPoint(Hb,qb),Wb.applyMatrix4(a.matrixWorldInverse),Yb.set(Wb.normal.x,Wb.normal.y,Wb.normal.z,Wb.constant);const l=a.projectionMatrix;Jb.x=(Math.sign(Yb.x)+l.elements[8])/l.elements[0],Jb.y=(Math.sign(Yb.y)+l.elements[9])/l.elements[5],Jb.z=-1,Jb.w=(1+l.elements[10])/l.elements[14],Yb.multiplyScalar(1/Yb.dot(Jb));l.elements[2]=Yb.x,l.elements[6]=Yb.y,l.elements[10]=s.coordinateSystem===h?Yb.z-0:Yb.z+1-0,l.elements[14]=Yb.w,this.textureNode.value=o.texture,!0===this.depth&&(this.textureNode.getDepthNode().value=o.depthTexture),i.visible=!1;const d=s.getRenderTarget(),c=s.getMRT(),p=s.autoClear;s.setMRT(null),s.setRenderTarget(o),s.autoClear=!0;const g=t.name;t.name=(t.name||"Scene")+" [ Reflector ]",u?(s.clear(),this.hasOutput=!1):(s.render(t,a),this.hasOutput=!0),t.name=g,s.setMRT(c),s.setRenderTarget(d),s.autoClear=p,i.visible=!0,sx=!1,this.forceUpdate=!1}get resolution(){return v('ReflectorNode: The "resolution" property has been renamed to "resolutionScale".'),this.resolutionScale}set resolution(e){v('ReflectorNode: The "resolution" property has been renamed to "resolutionScale".'),this.resolutionScale=e}}const ax=new Se(-1,1,1,-1,0,1);class ox extends Ne{constructor(e=!1){super();const t=!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new Qe([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new Qe(t,2))}}const ux=new ox;class lx extends ue{constructor(e=null){super(ux,e),this.camera=ax,this.isQuadMesh=!0}async renderAsync(e){v('QuadMesh: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await e.init(),e.render(this,ax)}render(e){e.render(this,ax)}}const dx=new t;class cx extends Ll{static get type(){return"RTTNode"}constructor(e,t=null,r=null,s={type:_e}){const i=new ae(t,r,s);super(i.texture,El()),this.isRTTNode=!0,this.node=e,this.width=t,this.height=r,this.pixelRatio=1,this.renderTarget=i,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this._rttNode=null,this._quadMesh=new lx(new fg),this.updateBeforeType=ei.RENDER}get autoResize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;const r=e*this.pixelRatio,s=t*this.pixelRatio;this.renderTarget.setSize(r,s),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoResize){const t=e.getPixelRatio(),r=e.getSize(dx),s=Math.floor(r.width*t),i=Math.floor(r.height*t);s===this.renderTarget.width&&i===this.renderTarget.height||(this.renderTarget.setSize(s,i),this.textureNeedsUpdate=!0)}let t="RTT";this.node.name&&(t=this.node.name+" [ "+t+" ]"),this._quadMesh.material.fragmentNode=this._rttNode,this._quadMesh.name=t;const r=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(r)}clone(){const e=new Ll(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const hx=(e,...t)=>new cx(Ji(e),...t),px=ln(([e,t,r],s)=>{let i;s.renderer.coordinateSystem===h?(e=xn(e.x,e.y.oneMinus()).mul(2).sub(1),i=An(Nn(e,t),1)):i=An(Nn(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);const n=An(r.mul(i));return n.xyz.div(n.w)}),gx=ln(([e,t])=>{const r=t.mul(An(e,1)),s=r.xy.div(r.w).mul(.5).add(.5).toVar();return xn(s.x,s.y.oneMinus())}),mx=ln(([e,t,r])=>{const s=wl(Ul(t)),i=Tn(e.mul(s)).toVar(),n=Ul(t,i).toVar(),a=Ul(t,i.sub(Tn(2,0))).toVar(),o=Ul(t,i.sub(Tn(1,0))).toVar(),u=Ul(t,i.add(Tn(1,0))).toVar(),l=Ul(t,i.add(Tn(2,0))).toVar(),d=Ul(t,i.add(Tn(0,2))).toVar(),c=Ul(t,i.add(Tn(0,1))).toVar(),h=Ul(t,i.sub(Tn(0,1))).toVar(),p=Ul(t,i.sub(Tn(0,2))).toVar(),g=Bo(Fa(mn(2).mul(o).sub(a),n)).toVar(),m=Bo(Fa(mn(2).mul(u).sub(l),n)).toVar(),f=Bo(Fa(mn(2).mul(c).sub(d),n)).toVar(),y=Bo(Fa(mn(2).mul(h).sub(p),n)).toVar(),b=px(e,n,r).toVar(),x=g.lessThan(m).select(b.sub(px(e.sub(xn(mn(1).div(s.x),0)),o,r)),b.negate().add(px(e.add(xn(mn(1).div(s.x),0)),u,r))),T=f.lessThan(y).select(b.sub(px(e.add(xn(0,mn(1).div(s.y))),c,r)),b.negate().add(px(e.sub(xn(0,mn(1).div(s.y))),h,r)));return No(Zo(x,T))}),fx=ln(([e])=>So(mn(52.9829189).mul(So(Qo(e,xn(.06711056,.00583715)))))).setLayout({name:"interleavedGradientNoise",type:"float",inputs:[{name:"position",type:"vec2"}]}),yx=ln(([e,t,r])=>{const s=mn(2.399963229728653),i=xo(mn(e).add(.5).div(mn(t))),n=mn(e).mul(s).add(r);return xn(Eo(n),Ro(n)).mul(i)}).setLayout({name:"vogelDiskSample",type:"vec2",inputs:[{name:"sampleIndex",type:"int"},{name:"samplesCount",type:"int"},{name:"phi",type:"float"}]});class bx extends li{static get type(){return"SampleNode"}constructor(e,t=null){super(),this.callback=e,this.uvNode=t,this.isSampleNode=!0}setup(){return this.sample(El())}sample(e){return this.callback(e)}}class xx extends li{static get type(){return"EventNode"}constructor(e,t){super("void"),this.eventType=e,this.callback=t,e===xx.OBJECT?this.updateType=ei.OBJECT:e===xx.MATERIAL?this.updateType=ei.RENDER:e===xx.BEFORE_OBJECT?this.updateBeforeType=ei.OBJECT:e===xx.BEFORE_MATERIAL&&(this.updateBeforeType=ei.RENDER)}update(e){this.callback(e)}updateBefore(e){this.callback(e)}}xx.OBJECT="object",xx.MATERIAL="material",xx.BEFORE_OBJECT="beforeObject",xx.BEFORE_MATERIAL="beforeMaterial";const Tx=(e,t)=>new xx(e,t).toStack();class _x extends j{constructor(e,t,r=Float32Array){super(ArrayBuffer.isView(e)?e:new r(e*t),t),this.isStorageInstancedBufferAttribute=!0}}class vx extends Ce{constructor(e,t,r=Float32Array){super(ArrayBuffer.isView(e)?e:new r(e*t),t),this.isStorageBufferAttribute=!0}}class Nx extends li{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const Sx=nn(Nx),Rx=new D,Ex=new a,Ax=va(0).setGroup(xa).onRenderUpdate(({scene:e})=>e.backgroundBlurriness),wx=va(1).setGroup(xa).onRenderUpdate(({scene:e})=>e.backgroundIntensity),Cx=va(new a).setGroup(xa).onRenderUpdate(({scene:e})=>{const t=e.background;return null!==t&&t.isTexture&&t.mapping!==Ze?(Rx.copy(e.backgroundRotation),Rx.x*=-1,Rx.y*=-1,Rx.z*=-1,Ex.makeRotationFromEuler(Rx)):Ex.identity(),Ex});class Mx extends Ll{static get type(){return"StorageTextureNode"}constructor(e,t,r=null){super(e,t),this.storeNode=r,this.mipLevel=0,this.isStorageTextureNode=!0,this.access=ri.WRITE_ONLY}getInputType(){return"storageTexture"}setup(e){super.setup(e);const t=e.getNodeProperties(this);return t.storeNode=this.storeNode,t}setAccess(e){return this.access=e,this}setMipLevel(e){return this.mipLevel=e,this}generate(e,t){let r;return r=null!==this.storeNode?this.generateStore(e):super.generate(e,t),r}generateSnippet(e,t,r,s,i,n,a,o,u){const l=this.value;return e.generateStorageTextureLoad(l,t,r,s,n,u)}toReadWrite(){return this.setAccess(ri.READ_WRITE)}toReadOnly(){return this.setAccess(ri.READ_ONLY)}toWriteOnly(){return this.setAccess(ri.WRITE_ONLY)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:r,storeNode:s,depthNode:i}=t,n=super.generate(e,"property"),a=r.build(e,!0===this.value.is3DTexture?"uvec3":"uvec2"),o=s.build(e,"vec4"),u=i?i.build(e,"int"):null,l=e.generateTextureStore(e,n,a,u,o);e.addLineFlowCode(l,this)}clone(){const e=super.clone();return e.storeNode=this.storeNode,e.mipLevel=this.mipLevel,e.access=this.access,e}}const Bx=sn(Mx).setParameterLength(1,3),Fx=ln(({texture:e,uv:t})=>{const r=1e-4,s=Nn().toVar();return hn(t.x.lessThan(r),()=>{s.assign(Nn(1,0,0))}).ElseIf(t.y.lessThan(r),()=>{s.assign(Nn(0,1,0))}).ElseIf(t.z.lessThan(r),()=>{s.assign(Nn(0,0,1))}).ElseIf(t.x.greaterThan(.9999),()=>{s.assign(Nn(-1,0,0))}).ElseIf(t.y.greaterThan(.9999),()=>{s.assign(Nn(0,-1,0))}).ElseIf(t.z.greaterThan(.9999),()=>{s.assign(Nn(0,0,-1))}).Else(()=>{const r=.01,i=e.sample(t.add(Nn(-.01,0,0))).r.sub(e.sample(t.add(Nn(r,0,0))).r),n=e.sample(t.add(Nn(0,-.01,0))).r.sub(e.sample(t.add(Nn(0,r,0))).r),a=e.sample(t.add(Nn(0,0,-.01))).r.sub(e.sample(t.add(Nn(0,0,r))).r);s.assign(Nn(i,n,a))}),s.normalize()});class Lx extends Ll{static get type(){return"Texture3DNode"}constructor(e,t=null,r=null){super(e,t,r),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Nn(.5,.5,.5)}setUpdateMatrix(){}generateUV(e,t){return t.build(e,!0===this.sampler?"vec3":"ivec3")}generateOffset(e,t){return t.build(e,"ivec3")}normal(e){return Fx({texture:this,uv:e})}}const Px=sn(Lx).setParameterLength(1,3);class Dx extends Fc{static get type(){return"UserDataNode"}constructor(e,t,r=null){super(e,t,r),this.userData=r}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}const Ux=new WeakMap;class Ix extends hi{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=ei.OBJECT,this.updateAfterType=ei.OBJECT,this.previousModelWorldMatrix=va(new a),this.previousProjectionMatrix=va(new a).setGroup(xa),this.previousCameraViewMatrix=va(new a)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:r}){const s=Vx(r);this.previousModelWorldMatrix.value.copy(s);const i=Ox(t);i.frameId!==e&&(i.frameId=e,void 0===i.previousProjectionMatrix?(i.previousProjectionMatrix=new a,i.previousCameraViewMatrix=new a,i.currentProjectionMatrix=new a,i.currentCameraViewMatrix=new a,i.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),i.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(i.previousProjectionMatrix.copy(i.currentProjectionMatrix),i.previousCameraViewMatrix.copy(i.currentCameraViewMatrix)),i.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),i.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(i.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(i.previousCameraViewMatrix))}updateAfter({object:e}){Vx(e).copy(e.matrixWorld)}setup(){const e=null===this.projectionMatrix?xd:va(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),r=e.mul(zd).mul(Kd),s=this.previousProjectionMatrix.mul(t).mul(Yd),i=r.xy.div(r.w),n=s.xy.div(s.w);return Fa(i,n)}}function Ox(e){let t=Ux.get(e);return void 0===t&&(t={},Ux.set(e,t)),t}function Vx(e,t=0){const r=Ox(e);let s=r[t];return void 0===s&&(r[t]=s=new a,r[t].copy(e.matrixWorld)),s}const kx=nn(Ix),Gx=ln(([e])=>Hx(e.rgb)),$x=ln(([e,t=mn(1)])=>t.mix(Hx(e.rgb),e.rgb)),zx=ln(([e,t=mn(1)])=>{const r=Ba(e.r,e.g,e.b).div(3),s=e.r.max(e.g.max(e.b)),i=s.sub(r).mul(t).mul(-3);return au(e.rgb,s,i)}),Wx=ln(([e,t=mn(1)])=>{const r=Nn(.57735,.57735,.57735),s=t.cos();return Nn(e.rgb.mul(s).add(r.cross(e.rgb).mul(t.sin()).add(r.mul(Qo(r,e.rgb).mul(s.oneMinus())))))}),Hx=(e,t=Nn(p.getLuminanceCoefficients(new r)))=>Qo(e,t),qx=ln(([e,t=Nn(1),s=Nn(0),i=Nn(1),n=mn(1),a=Nn(p.getLuminanceCoefficients(new r,Ee))])=>{const o=e.rgb.dot(Nn(a)),u=qo(e.rgb.mul(t).add(s),0).toVar(),l=u.pow(i).toVar();return hn(u.r.greaterThan(0),()=>{u.r.assign(l.r)}),hn(u.g.greaterThan(0),()=>{u.g.assign(l.g)}),hn(u.b.greaterThan(0),()=>{u.b.assign(l.b)}),u.assign(o.add(u.sub(o).mul(n))),An(u.rgb,e.a)}),jx=ln(([e,t])=>e.mul(t).floor().div(t));let Xx=null;class Kx extends Op{static get type(){return"ViewportSharedTextureNode"}constructor(e=Xl,t=null){null===Xx&&(Xx=new Q),super(e,t,Xx)}getTextureForReference(){return Xx}updateReference(){return this}}const Yx=sn(Kx).setParameterLength(0,2),Qx=new t;class Zx extends Ll{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.isPassTextureNode=!0,this.setUpdateMatrix(!1)}setup(e){return e.getNodeProperties(this).passNode=this.passNode,super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class Jx extends Zx{static get type(){return"PassMultipleTextureNode"}constructor(e,t,r=!1){super(e,null),this.textureName=t,this.previousTexture=r,this.isPassMultipleTextureNode=!0}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){const e=new this.constructor(this.passNode,this.textureName,this.previousTexture);return e.uvNode=this.uvNode,e.levelNode=this.levelNode,e.biasNode=this.biasNode,e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.offsetNode=this.offsetNode,e}}class eT extends hi{static get type(){return"PassNode"}constructor(e,t,r,s={}){super("vec4"),this.scope=e,this.scene=t,this.camera=r,this.options=s,this._pixelRatio=1,this._width=1,this._height=1;const i=new J;i.isRenderTargetTexture=!0,i.name="depth";const n=new ae(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:_e,...s});n.texture.name="output",n.depthTexture=i,this.renderTarget=n,this.overrideMaterial=null,this.transparent=!0,this.opaque=!0,this.contextNode=null,this._contextNodeCache=null,this._textures={output:n.texture,depth:i},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=va(0),this._cameraFar=va(0),this._mrt=null,this._layers=null,this._resolutionScale=1,this._viewport=null,this._scissor=null,this.isPassNode=!0,this.updateBeforeType=ei.FRAME,this.global=!0}setResolutionScale(e){return this._resolutionScale=e,this}getResolutionScale(){return this._resolutionScale}setResolution(e){return d("PassNode: .setResolution() is deprecated. Use .setResolutionScale() instead."),this.setResolutionScale(e)}getResolution(){return d("PassNode: .getResolution() is deprecated. Use .getResolutionScale() instead."),this.getResolutionScale()}setLayers(e){return this._layers=e,this}getLayers(){return this._layers}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getTexture(e){let t=this._textures[e];if(void 0===t){t=this.renderTarget.texture.clone(),t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)}return t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(void 0!==t){const r=this._textures[e],s=this.renderTarget.textures.indexOf(r);this.renderTarget.textures[s]=t,this._textures[e]=t,this._previousTextures[e]=r,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&(t=new Jx(this,e),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),t=new Jx(this,e,!0),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){const r=this._cameraNear,s=this._cameraFar;this._viewZNodes[e]=t=Qp(this.getTextureNode(e),r,s)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){const r=this._cameraNear,s=this._cameraFar,i=this.getViewZNode(e);this._linearDepthNodes[e]=t=jp(i,r,s)}return t}async compileAsync(e){const t=e.getRenderTarget(),r=e.getMRT();e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),await e.compileAsync(this.scene,this.camera),e.setRenderTarget(t),e.setMRT(r)}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,this.renderTarget.texture.type=e.getOutputBufferType(),this.scope===eT.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:r}=this;let s,i;const n=t.getOutputRenderTarget();n&&!0===n.isXRRenderTarget?(i=1,s=t.xr.getCamera(),t.xr.updateCamera(s),Qx.set(n.width,n.height)):(s=this.camera,i=t.getPixelRatio(),t.getSize(Qx)),this._pixelRatio=i,this.setSize(Qx.width,Qx.height);const a=t.getRenderTarget(),o=t.getMRT(),u=t.autoClear,l=t.transparent,d=t.opaque,c=s.layers.mask,h=t.contextNode,p=r.overrideMaterial;this._cameraNear.value=s.near,this._cameraFar.value=s.far,null!==this._layers&&(s.layers.mask=this._layers.mask);for(const e in this._previousTextures)this.toggleTexture(e);null!==this.overrideMaterial&&(r.overrideMaterial=this.overrideMaterial),t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.autoClear=!0,t.transparent=this.transparent,t.opaque=this.opaque,null!==this.contextNode&&(null!==this._contextNodeCache&&this._contextNodeCache.version===this.version||(this._contextNodeCache={version:this.version,context:_u({...t.contextNode.getFlowContextData(),...this.contextNode.getFlowContextData()})}),t.contextNode=this._contextNodeCache.context);const g=r.name;r.name=this.name?this.name:r.name,t.render(r,s),r.name=g,r.overrideMaterial=p,t.setRenderTarget(a),t.setMRT(o),t.autoClear=u,t.transparent=l,t.opaque=d,t.contextNode=h,s.layers.mask=c}setSize(e,t){this._width=e,this._height=t;const r=Math.floor(this._width*this._pixelRatio*this._resolutionScale),s=Math.floor(this._height*this._pixelRatio*this._resolutionScale);this.renderTarget.setSize(r,s),null!==this._scissor&&this.renderTarget.scissor.copy(this._scissor),null!==this._viewport&&this.renderTarget.viewport.copy(this._viewport)}setScissor(e,t,r,i){null===e?this._scissor=null:(null===this._scissor&&(this._scissor=new s),e.isVector4?this._scissor.copy(e):this._scissor.set(e,t,r,i),this._scissor.multiplyScalar(this._pixelRatio*this._resolutionScale).floor())}setViewport(e,t,r,i){null===e?this._viewport=null:(null===this._viewport&&(this._viewport=new s),e.isVector4?this._viewport.copy(e):this._viewport.set(e,t,r,i),this._viewport.multiplyScalar(this._pixelRatio*this._resolutionScale).floor())}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}eT.COLOR="color",eT.DEPTH="depth";class tT extends eT{static get type(){return"ToonOutlinePassNode"}constructor(e,t,r,s,i){super(eT.COLOR,e,t),this.colorNode=r,this.thicknessNode=s,this.alphaNode=i,this._materialCache=new WeakMap,this.name="Outline Pass"}updateBefore(e){const{renderer:t}=e,r=t.getRenderObjectFunction();t.setRenderObjectFunction((e,r,s,i,n,a,o,u)=>{if((n.isMeshToonMaterial||n.isMeshToonNodeMaterial)&&!1===n.wireframe){const l=this._getOutlineMaterial(n);t.renderObject(e,r,s,i,l,a,o,u)}t.renderObject(e,r,s,i,n,a,o,u)}),super.updateBefore(e),t.setRenderObjectFunction(r)}_createMaterial(){const e=new fg;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=L;const t=ac.negate(),r=xd.mul(zd),s=mn(1),i=r.mul(An(Kd,1)),n=r.mul(An(Kd.add(t),1)),a=No(i.sub(n));return e.vertexNode=i.add(a.mul(this.thicknessNode).mul(i.w).mul(s)),e.colorNode=An(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const rT=ln(([e,t])=>e.mul(t).clamp()).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),sT=ln(([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp()).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),iT=ln(([e,t])=>{const r=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),s=e.mul(e.mul(6.2).add(1.7)).add(.06);return r.div(s).pow(2.2)}).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),nT=ln(([e])=>{const t=e.mul(e.add(.0245786)).sub(90537e-9),r=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(r)}),aT=ln(([e,t])=>{const r=Fn(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),s=Fn(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=r.mul(e),e=nT(e),(e=s.mul(e)).clamp()}).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),oT=Fn(Nn(1.6605,-.1246,-.0182),Nn(-.5876,1.1329,-.1006),Nn(-.0728,-.0083,1.1187)),uT=Fn(Nn(.6274,.0691,.0164),Nn(.3293,.9195,.088),Nn(.0433,.0113,.8956)),lT=ln(([e])=>{const t=Nn(e).toVar(),r=Nn(t.mul(t)).toVar(),s=Nn(r.mul(r)).toVar();return mn(15.5).mul(s.mul(r)).sub(La(40.14,s.mul(t))).add(La(31.96,s).sub(La(6.868,r.mul(t))).add(La(.4298,r).add(La(.1191,t).sub(.00232))))}),dT=ln(([e,t])=>{const r=Nn(e).toVar(),s=Fn(Nn(.856627153315983,.137318972929847,.11189821299995),Nn(.0951212405381588,.761241990602591,.0767994186031903),Nn(.0482516061458583,.101439036467562,.811302368396859)),i=Fn(Nn(1.1271005818144368,-.1413297634984383,-.14132976349843826),Nn(-.11060664309660323,1.157823702216272,-.11060664309660294),Nn(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=mn(-12.47393),a=mn(4.026069);return r.mulAssign(t),r.assign(uT.mul(r)),r.assign(s.mul(r)),r.assign(qo(r,1e-10)),r.assign(bo(r)),r.assign(r.sub(n).div(a.sub(n))),r.assign(ou(r,0,1)),r.assign(lT(r)),r.assign(i.mul(r)),r.assign(Jo(qo(Nn(0),r),Nn(2.2))),r.assign(oT.mul(r)),r.assign(ou(r,0,1)),r}).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),cT=ln(([e,t])=>{const r=mn(.76),s=mn(.15);e=e.mul(t);const i=Ho(e.r,Ho(e.g,e.b)),n=xu(i.lessThan(.08),i.sub(La(6.25,i.mul(i))),.04);e.subAssign(n);const a=qo(e.r,qo(e.g,e.b));hn(a.lessThan(r),()=>e);const o=Fa(1,r),u=Fa(1,o.mul(o).div(a.add(o.sub(r))));e.mulAssign(u.div(a));const l=Fa(1,Pa(1,s.mul(a.sub(u)).add(1)));return au(e,Nn(u),l)}).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class hT extends li{static get type(){return"CodeNode"}constructor(e="",t=[],r=""){super("code"),this.isCodeNode=!0,this.global=!0,this.code=e,this.includes=t,this.language=r}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const r of t)r.build(e);const r=e.getCodeFromNode(this,this.getNodeType(e));return r.code=this.code,r.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}const pT=sn(hT).setParameterLength(1,3);class gT extends hT{static get type(){return"FunctionNode"}constructor(e="",t=[],r=""){super(e,t,r)}getNodeType(e){return this.getNodeFunction(e).type}getMemberType(e,t){const r=this.getNodeType(e);return e.getStructTypeNode(r).getMemberType(e,t)}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let r=t.nodeFunction;return void 0===r&&(r=e.parser.parseFunction(this.code),t.nodeFunction=r),r}generate(e,t){super.generate(e);const r=this.getNodeFunction(e),s=r.name,i=r.type,n=e.getCodeFromNode(this,i);""!==s&&(n.name=s);const a=e.getPropertyName(n),o=this.getNodeFunction(e).getCode(a);return n.code=o+"\n","property"===t?a:e.format(`${a}()`,i,t)}}const mT=(e,t=[],r="")=>{for(let e=0;e<t.length;e++){const r=t[e];"function"==typeof r&&(t[e]=r.functionNode)}const s=new gT(e,t,r),i=(...e)=>s.call(...e);return i.functionNode=s,i};function fT(e){let t;const r=e.context.getViewZ;return void 0!==r&&(t=r(this)),(t||Jd.z).negate()}const yT=ln(([e,t],r)=>{const s=fT(r);return du(e,t,s)}),bT=ln(([e],t)=>{const r=fT(t);return e.mul(e,r,r).negate().exp().oneMinus()}),xT=ln(([e,t],r)=>{const s=fT(r),i=t.sub(Qd.y).max(0).toConst().mul(s).toConst();return e.mul(e,i,i).negate().exp().oneMinus()}),TT=ln(([e,t])=>An(t.toFloat().mix(na.rgb,e.toVec3()),na.a));let _T=null,vT=null;class NT extends li{static get type(){return"RangeNode"}constructor(e=mn(),t=mn()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=this.getConstNode(this.minNode),r=this.getConstNode(this.maxNode),s=e.getTypeLength(js(t.value)),i=e.getTypeLength(js(r.value));return s>i?s:i}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}getConstNode(e){let t=null;if(e.traverse(e=>{!0===e.isConstNode&&(t=e)}),null===t)throw new Bl('THREE.TSL: No "ConstNode" found in node graph.',this.stackTrace);return t}setup(e){const t=e.object;let r=null;if(t.count>1){const i=this.getConstNode(this.minNode),n=this.getConstNode(this.maxNode),a=i.value,o=n.value,u=e.getTypeLength(js(a)),d=e.getTypeLength(js(o));_T=_T||new s,vT=vT||new s,_T.setScalar(0),vT.setScalar(0),1===u?_T.setScalar(a):a.isColor?_T.set(a.r,a.g,a.b,1):_T.set(a.x,a.y,a.z||0,a.w||0),1===d?vT.setScalar(o):o.isColor?vT.set(o.r,o.g,o.b,1):vT.set(o.x,o.y,o.z||0,o.w||0);const c=4,h=c*t.count,p=new Float32Array(h);for(let e=0;e<h;e++){const t=e%c,r=_T.getComponent(t),s=vT.getComponent(t);p[e]=l.lerp(r,s,Math.random())}const g=this.getNodeType(e);if(4*t.count*4<=e.getUniformBufferLimit())r=Ol(p,"vec4",t.count).element(dp).convert(g);else{const t=new j(p,4);e.geometry.setAttribute("__range"+this.id,t),r=tl(t).convert(g)}}else r=mn(0);return r}}const ST=sn(NT).setParameterLength(2);class RT extends li{static get type(){return"ComputeBuiltinNode"}constructor(e,t){super(t),this._builtinName=e}getHash(e){return this.getBuiltinName(e)}getNodeType(){return this.nodeType}setBuiltinName(e){return this._builtinName=e,this}getBuiltinName(){return this._builtinName}hasBuiltin(e){return e.hasBuiltin(this._builtinName)}generate(e,t){const r=this.getBuiltinName(e),s=this.getNodeType(e);return"compute"===e.shaderStage?e.format(r,s,t):(d(`ComputeBuiltinNode: Compute built-in value ${r} can not be accessed in the ${e.shaderStage} stage`),e.generateConst(s))}serialize(e){super.serialize(e),e.global=this.global,e._builtinName=this._builtinName}deserialize(e){super.deserialize(e),this.global=e.global,this._builtinName=e._builtinName}}const ET=(e,t)=>new RT(e,t),AT=ET("numWorkgroups","uvec3"),wT=ET("workgroupId","uvec3"),CT=ET("globalId","uvec3"),MT=ET("localId","uvec3"),BT=ET("subgroupSize","uint");class FT extends li{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:r}=e;!0===r.backend.isWebGLBackend?e.addFlowCode(`\t// ${t}Barrier \n`):e.addLineFlowCode(`${t}Barrier()`,this)}}const LT=sn(FT);class PT extends di{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let r;const s=e.context.assign;if(r=super.generate(e),!0!==s){const s=this.getNodeType(e);r=e.format(r,s,t)}return r}}class DT extends li{constructor(e,t,r=0){super(t),this.bufferType=t,this.bufferCount=r,this.isWorkgroupInfoNode=!0,this.elementType=t,this.scope=e,this.name=""}setName(e){return this.name=e,this}label(e){return d('TSL: "label()" has been deprecated. Use "setName()" instead.',new Ds),this.setName(e)}setScope(e){return this.scope=e,this}getElementType(){return this.elementType}getInputType(){return`${this.scope}Array`}element(e){return new PT(this,e)}generate(e){const t=""!==this.name?this.name:`${this.scope}Array_${this.id}`;return e.getScopedArray(t,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}class UT extends li{static get type(){return"AtomicFunctionNode"}constructor(e,t,r){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=r,this.parents=!0}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=e.getNodeProperties(this),r=t.parents,s=this.method,i=this.getNodeType(e),n=this.getInputType(e),a=this.pointerNode,o=this.valueNode,u=[];u.push(`&${a.build(e,n)}`),null!==o&&u.push(o.build(e,n));const l=`${e.getMethod(s,i)}( ${u.join(", ")} )`;if(!(!!r&&(1===r.length&&!0===r[0].isStackNode)))return void 0===t.constNode&&(t.constNode=ml(l,i).toConst()),t.constNode.build(e);e.addLineFlowCode(l,this)}}UT.ATOMIC_LOAD="atomicLoad",UT.ATOMIC_STORE="atomicStore",UT.ATOMIC_ADD="atomicAdd",UT.ATOMIC_SUB="atomicSub",UT.ATOMIC_MAX="atomicMax",UT.ATOMIC_MIN="atomicMin",UT.ATOMIC_AND="atomicAnd",UT.ATOMIC_OR="atomicOr",UT.ATOMIC_XOR="atomicXor";const IT=sn(UT),OT=(e,t,r)=>IT(e,t,r).toStack();class VT extends hi{static get type(){return"SubgroupFunctionNode"}constructor(e,t=null,r=null){super(),this.method=e,this.aNode=t,this.bNode=r}getInputType(e){const t=this.aNode?this.aNode.getNodeType(e):null,r=this.bNode?this.bNode.getNodeType(e):null;return(e.isMatrix(t)?0:e.getTypeLength(t))>(e.isMatrix(r)?0:e.getTypeLength(r))?t:r}getNodeType(e){const t=this.method;return t===VT.SUBGROUP_ELECT?"bool":t===VT.SUBGROUP_BALLOT?"uvec4":this.getInputType(e)}generate(e,t){const r=this.method,s=this.getNodeType(e),i=this.getInputType(e),n=this.aNode,a=this.bNode,o=[];if(r===VT.SUBGROUP_BROADCAST||r===VT.SUBGROUP_SHUFFLE||r===VT.QUAD_BROADCAST){const t=a.getNodeType(e);o.push(n.build(e,s),a.build(e,"float"===t?"int":s))}else r===VT.SUBGROUP_SHUFFLE_XOR||r===VT.SUBGROUP_SHUFFLE_DOWN||r===VT.SUBGROUP_SHUFFLE_UP?o.push(n.build(e,s),a.build(e,"uint")):(null!==n&&o.push(n.build(e,i)),null!==a&&o.push(a.build(e,i)));const u=0===o.length?"()":`( ${o.join(", ")} )`;return e.format(`${e.getMethod(r,s)}${u}`,s,t)}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}VT.SUBGROUP_ELECT="subgroupElect",VT.SUBGROUP_BALLOT="subgroupBallot",VT.SUBGROUP_ADD="subgroupAdd",VT.SUBGROUP_INCLUSIVE_ADD="subgroupInclusiveAdd",VT.SUBGROUP_EXCLUSIVE_AND="subgroupExclusiveAdd",VT.SUBGROUP_MUL="subgroupMul",VT.SUBGROUP_INCLUSIVE_MUL="subgroupInclusiveMul",VT.SUBGROUP_EXCLUSIVE_MUL="subgroupExclusiveMul",VT.SUBGROUP_AND="subgroupAnd",VT.SUBGROUP_OR="subgroupOr",VT.SUBGROUP_XOR="subgroupXor",VT.SUBGROUP_MIN="subgroupMin",VT.SUBGROUP_MAX="subgroupMax",VT.SUBGROUP_ALL="subgroupAll",VT.SUBGROUP_ANY="subgroupAny",VT.SUBGROUP_BROADCAST_FIRST="subgroupBroadcastFirst",VT.QUAD_SWAP_X="quadSwapX",VT.QUAD_SWAP_Y="quadSwapY",VT.QUAD_SWAP_DIAGONAL="quadSwapDiagonal",VT.SUBGROUP_BROADCAST="subgroupBroadcast",VT.SUBGROUP_SHUFFLE="subgroupShuffle",VT.SUBGROUP_SHUFFLE_XOR="subgroupShuffleXor",VT.SUBGROUP_SHUFFLE_UP="subgroupShuffleUp",VT.SUBGROUP_SHUFFLE_DOWN="subgroupShuffleDown",VT.QUAD_BROADCAST="quadBroadcast";const kT=an(VT,VT.SUBGROUP_ELECT).setParameterLength(0),GT=an(VT,VT.SUBGROUP_BALLOT).setParameterLength(1),$T=an(VT,VT.SUBGROUP_ADD).setParameterLength(1),zT=an(VT,VT.SUBGROUP_INCLUSIVE_ADD).setParameterLength(1),WT=an(VT,VT.SUBGROUP_EXCLUSIVE_AND).setParameterLength(1),HT=an(VT,VT.SUBGROUP_MUL).setParameterLength(1),qT=an(VT,VT.SUBGROUP_INCLUSIVE_MUL).setParameterLength(1),jT=an(VT,VT.SUBGROUP_EXCLUSIVE_MUL).setParameterLength(1),XT=an(VT,VT.SUBGROUP_AND).setParameterLength(1),KT=an(VT,VT.SUBGROUP_OR).setParameterLength(1),YT=an(VT,VT.SUBGROUP_XOR).setParameterLength(1),QT=an(VT,VT.SUBGROUP_MIN).setParameterLength(1),ZT=an(VT,VT.SUBGROUP_MAX).setParameterLength(1),JT=an(VT,VT.SUBGROUP_ALL).setParameterLength(0),e_=an(VT,VT.SUBGROUP_ANY).setParameterLength(0),t_=an(VT,VT.SUBGROUP_BROADCAST_FIRST).setParameterLength(2),r_=an(VT,VT.QUAD_SWAP_X).setParameterLength(1),s_=an(VT,VT.QUAD_SWAP_Y).setParameterLength(1),i_=an(VT,VT.QUAD_SWAP_DIAGONAL).setParameterLength(1),n_=an(VT,VT.SUBGROUP_BROADCAST).setParameterLength(2),a_=an(VT,VT.SUBGROUP_SHUFFLE).setParameterLength(2),o_=an(VT,VT.SUBGROUP_SHUFFLE_XOR).setParameterLength(2),u_=an(VT,VT.SUBGROUP_SHUFFLE_UP).setParameterLength(2),l_=an(VT,VT.SUBGROUP_SHUFFLE_DOWN).setParameterLength(2),d_=an(VT,VT.QUAD_BROADCAST).setParameterLength(1);let c_;function h_(e){c_=c_||new WeakMap;let t=c_.get(e);return void 0===t&&c_.set(e,t={}),t}function p_(e){const t=h_(e);return t.shadowMatrix||(t.shadowMatrix=va("mat4").setGroup(xa).onRenderUpdate(t=>(!0===e.castShadow&&!1!==t.renderer.shadowMap.enabled||(e.shadow.camera.coordinateSystem!==t.camera.coordinateSystem&&(e.shadow.camera.coordinateSystem=t.camera.coordinateSystem,e.shadow.camera.updateProjectionMatrix()),e.shadow.updateMatrices(e)),e.shadow.matrix)))}function g_(e,t=Qd){const r=p_(e).mul(t);return r.xyz.div(r.w)}function m_(e){const t=h_(e);return t.position||(t.position=va(new r).setGroup(xa).onRenderUpdate((t,r)=>r.value.setFromMatrixPosition(e.matrixWorld)))}function f_(e){const t=h_(e);return t.targetPosition||(t.targetPosition=va(new r).setGroup(xa).onRenderUpdate((t,r)=>r.value.setFromMatrixPosition(e.target.matrixWorld)))}function y_(e){const t=h_(e);return t.viewPosition||(t.viewPosition=va(new r).setGroup(xa).onRenderUpdate(({camera:t},s)=>{s.value=s.value||new r,s.value.setFromMatrixPosition(e.matrixWorld),s.value.applyMatrix4(t.matrixWorldInverse)}))}const b_=e=>_d.transformDirection(m_(e).sub(f_(e))),x_=(e,t)=>{for(const r of t)if(r.isAnalyticLightNode&&r.light.id===e)return r;return null},T_=new WeakMap,__=[];class v_ extends li{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=In("vec3","totalDiffuse"),this.totalSpecularNode=In("vec3","totalSpecular"),this.outgoingLightNode=In("vec3","outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}customCacheKey(){const e=this._lights;for(let t=0;t<e.length;t++){const r=e[t];if(__.push(r.id),__.push(r.castShadow?1:0),!0===r.isSpotLight){const e=null!==r.map?r.map.id:-1,t=r.colorNode?r.colorNode.getCacheKey():-1;__.push(e,t)}}const t=Os(__);return __.length=0,t}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);const t=[];for(const e of this._lightNodes)t.push(e.getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getNodeProperties(this);for(const r of t.nodes)r.build(e);t.outputNode.build(e)}setupLightsNode(e){const t=[],r=this._lightNodes,s=(e=>e.sort((e,t)=>e.id-t.id))(this._lights),i=e.renderer.library;for(const e of s)if(e.isNode)t.push(Ji(e));else{let s=null;if(null!==r&&(s=x_(e.id,r)),null===s){const r=i.getLightNodeClass(e.constructor);if(null===r){d(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let s=null;T_.has(e)?s=T_.get(e):(s=new r(e),T_.set(e,s)),t.push(s)}}this._lightNodes=t}setupDirectLight(e,t,r){const{lightingModel:s,reflectedLight:i}=e.context;s.direct({...r,lightNode:t,reflectedLight:i},e)}setupDirectRectAreaLight(e,t,r){const{lightingModel:s,reflectedLight:i}=e.context;s.directRectArea({...r,lightNode:t,reflectedLight:i},e)}setupLights(e,t){for(const r of t)r.build(e)}getLightNodes(e){return null===this._lightNodes&&this.setupLightsNode(e),this._lightNodes}setup(e){const t=e.lightsNode;e.lightsNode=this;let r=this.outgoingLightNode;const s=e.context,i=s.lightingModel,n=e.getNodeProperties(this);if(i){const{totalDiffuseNode:t,totalSpecularNode:a}=this;s.outgoingLight=r;const o=e.addStack();n.nodes=o.nodes,i.start(e);const{backdrop:u,backdropAlpha:l}=s,{directDiffuse:d,directSpecular:c,indirectDiffuse:h,indirectSpecular:p}=s.reflectedLight;let g=d.add(h);null!==u&&(g=Nn(null!==l?l.mix(g,u):u)),t.assign(g),a.assign(c.add(p)),r.assign(t.add(a)),i.finish(e),r=r.bypass(e.removeStack())}else n.nodes=[];return e.lightsNode=t,r}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}class N_ extends li{static get type(){return"ShadowBaseNode"}constructor(e){super(),this.light=e,this.updateBeforeType=ei.RENDER,this.isShadowBaseNode=!0}setupShadowPosition({context:e,material:t}){S_.assign(t.receivedShadowPositionNode||e.shadowPositionWorld||Qd)}}const S_=In("vec3","shadowPositionWorld");function R_(t,r={}){return r.toneMapping=t.toneMapping,r.toneMappingExposure=t.toneMappingExposure,r.outputColorSpace=t.outputColorSpace,r.renderTarget=t.getRenderTarget(),r.activeCubeFace=t.getActiveCubeFace(),r.activeMipmapLevel=t.getActiveMipmapLevel(),r.renderObjectFunction=t.getRenderObjectFunction(),r.pixelRatio=t.getPixelRatio(),r.mrt=t.getMRT(),r.clearColor=t.getClearColor(r.clearColor||new e),r.clearAlpha=t.getClearAlpha(),r.autoClear=t.autoClear,r.scissorTest=t.getScissorTest(),r}function E_(e,t){return t=R_(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t}function A_(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}function w_(e,t={}){return t.background=e.background,t.backgroundNode=e.backgroundNode,t.overrideMaterial=e.overrideMaterial,t}function C_(e,t){return t=w_(e,t),e.background=null,e.backgroundNode=null,e.overrideMaterial=null,t}function M_(e,t){e.background=t.background,e.backgroundNode=t.backgroundNode,e.overrideMaterial=t.overrideMaterial}function B_(e,t,r){return r=C_(t,r=E_(e,r))}function F_(e,t,r){A_(e,r),M_(t,r)}var L_=Object.freeze({__proto__:null,resetRendererAndSceneState:B_,resetRendererState:E_,resetSceneState:C_,restoreRendererAndSceneState:F_,restoreRendererState:A_,restoreSceneState:M_,saveRendererAndSceneState:function(e,t,r={}){return r=w_(t,r=R_(e,r))},saveRendererState:R_,saveSceneState:w_});const P_=new WeakMap,D_=ln(({depthTexture:e,shadowCoord:t,depthLayer:r})=>{let s=Dl(e,t.xy).setName("t_basic");return e.isArrayTexture&&(s=s.depth(r)),s.compare(t.z)}),U_=ln(({depthTexture:e,shadowCoord:t,shadow:r,depthLayer:s})=>{const i=(t,r)=>{let i=Dl(e,t);return e.isArrayTexture&&(i=i.depth(s)),i.compare(r)},n=Lc("mapSize","vec2",r).setGroup(xa),a=Lc("radius","float",r).setGroup(xa),o=xn(1).div(n),u=a.mul(o.x),l=fx(Yl.xy).mul(6.28318530718);return Ba(i(t.xy.add(yx(0,5,l).mul(u)),t.z),i(t.xy.add(yx(1,5,l).mul(u)),t.z),i(t.xy.add(yx(2,5,l).mul(u)),t.z),i(t.xy.add(yx(3,5,l).mul(u)),t.z),i(t.xy.add(yx(4,5,l).mul(u)),t.z)).mul(.2)}),I_=ln(({depthTexture:e,shadowCoord:t,shadow:r,depthLayer:s})=>{const i=(t,r)=>{let i=Dl(e,t);return e.isArrayTexture&&(i=i.depth(s)),i.compare(r)},n=Lc("mapSize","vec2",r).setGroup(xa),a=xn(1).div(n),o=a.x,u=a.y,l=t.xy,d=So(l.mul(n).add(.5));return l.subAssign(d.mul(a)),Ba(i(l,t.z),i(l.add(xn(o,0)),t.z),i(l.add(xn(0,u)),t.z),i(l.add(a),t.z),au(i(l.add(xn(o.negate(),0)),t.z),i(l.add(xn(o.mul(2),0)),t.z),d.x),au(i(l.add(xn(o.negate(),u)),t.z),i(l.add(xn(o.mul(2),u)),t.z),d.x),au(i(l.add(xn(0,u.negate())),t.z),i(l.add(xn(0,u.mul(2))),t.z),d.y),au(i(l.add(xn(o,u.negate())),t.z),i(l.add(xn(o,u.mul(2))),t.z),d.y),au(au(i(l.add(xn(o.negate(),u.negate())),t.z),i(l.add(xn(o.mul(2),u.negate())),t.z),d.x),au(i(l.add(xn(o.negate(),u.mul(2))),t.z),i(l.add(xn(o.mul(2),u.mul(2))),t.z),d.x),d.y)).mul(1/9)}),O_=ln(({depthTexture:e,shadowCoord:t,depthLayer:r},s)=>{let i=Dl(e).sample(t.xy);e.isArrayTexture&&(i=i.depth(r)),i=i.rg;const n=i.x,a=qo(1e-7,i.y.mul(i.y)),o=s.renderer.reversedDepthBuffer?jo(n,t.z):jo(t.z,n),u=mn(1).toVar();return hn(o.notEqual(1),()=>{const e=t.z.sub(n);let r=a.div(a.add(e.mul(e)));r=ou(Fa(r,.3).div(.65)),u.assign(qo(o,r))}),u}),V_=e=>{let t=P_.get(e);return void 0===t&&(t=new fg,t.colorNode=An(0,0,0,1),t.isShadowPassMaterial=!0,t.name="ShadowMaterial",t.blending=se,t.fog=!1,P_.set(e,t)),t},k_=e=>{const t=P_.get(e);void 0!==t&&(t.dispose(),P_.delete(e))},G_=new my,$_=[],z_=(e,t,r,s)=>{$_[0]=e,$_[1]=t;let i=G_.get($_);return void 0!==i&&i.shadowType===r&&i.useVelocity===s||(i=(i,n,a,o,u,l,...d)=>{(!0===i.castShadow||i.receiveShadow&&r===Je)&&(s&&(Ks(i).useVelocity=!0),i.onBeforeShadow(e,i,a,t.camera,o,n.overrideMaterial,l),e.renderObject(i,n,a,o,u,l,...d),i.onAfterShadow(e,i,a,t.camera,o,n.overrideMaterial,l))},i.shadowType=r,i.useVelocity=s,G_.set($_,i)),$_[0]=null,$_[1]=null,i},W_=ln(({samples:e,radius:t,size:r,shadowPass:s,depthLayer:i})=>{const n=mn(0).toVar("meanVertical"),a=mn(0).toVar("squareMeanVertical"),o=e.lessThanEqual(mn(1)).select(mn(0),mn(2).div(e.sub(1))),u=e.lessThanEqual(mn(1)).select(mn(0),mn(-1));Rp({start:fn(0),end:fn(e),type:"int",condition:"<"},({i:e})=>{const l=u.add(mn(e).mul(o));let d=s.sample(Ba(Yl.xy,xn(0,l).mul(t)).div(r));s.value.isArrayTexture&&(d=d.depth(i)),d=d.x,n.addAssign(d),a.addAssign(d.mul(d))}),n.divAssign(e),a.divAssign(e);const l=xo(a.sub(n.mul(n)).max(0));return xn(n,l)}),H_=ln(({samples:e,radius:t,size:r,shadowPass:s,depthLayer:i})=>{const n=mn(0).toVar("meanHorizontal"),a=mn(0).toVar("squareMeanHorizontal"),o=e.lessThanEqual(mn(1)).select(mn(0),mn(2).div(e.sub(1))),u=e.lessThanEqual(mn(1)).select(mn(0),mn(-1));Rp({start:fn(0),end:fn(e),type:"int",condition:"<"},({i:e})=>{const l=u.add(mn(e).mul(o));let d=s.sample(Ba(Yl.xy,xn(l,0).mul(t)).div(r));s.value.isArrayTexture&&(d=d.depth(i)),n.addAssign(d.x),a.addAssign(Ba(d.y.mul(d.y),d.x.mul(d.x)))}),n.divAssign(e),a.divAssign(e);const l=xo(a.sub(n.mul(n)).max(0));return xn(n,l)}),q_=[D_,U_,I_,O_];let j_;const X_=new lx;class K_ extends N_{static get type(){return"ShadowNode"}constructor(e,t=null){super(e),this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this._node=null,this._currentShadowType=null,this._cameraFrameId=new WeakMap,this.isShadowNode=!0,this.depthLayer=0}setupShadowFilter(e,{filterFn:t,depthTexture:r,shadowCoord:s,shadow:i,depthLayer:n}){const a=s.x.greaterThanEqual(0).and(s.x.lessThanEqual(1)).and(s.y.greaterThanEqual(0)).and(s.y.lessThanEqual(1)).and(s.z.lessThanEqual(1)),o=t({depthTexture:r,shadowCoord:s,shadow:i,depthLayer:n});return a.select(o,mn(1))}setupShadowCoord(e,t){const{shadow:r}=this,{renderer:s}=e,i=r.biasNode||Lc("bias","float",r).setGroup(xa);let n,a=t;if(r.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)a=a.xyz.div(a.w),n=a.z;else{const e=a.w;a=a.xy.div(e);const t=Lc("near","float",r.camera).setGroup(xa),s=Lc("far","float",r.camera).setGroup(xa);n=Zp(e.negate(),t,s)}return a=Nn(a.x,a.y.oneMinus(),s.reversedDepthBuffer?n.sub(i):n.add(i)),a}getShadowFilterFn(e){return q_[e]}setupRenderTarget(e,t){const r=new J(e.mapSize.width,e.mapSize.height);r.name="ShadowDepthTexture",r.compareFunction=t.renderer.reversedDepthBuffer?M:w;const s=t.createRenderTarget(e.mapSize.width,e.mapSize.height);return s.texture.name="ShadowMap",s.texture.type=e.mapType,s.depthTexture=r,{shadowMap:s,depthTexture:r}}setupShadow(e){const{renderer:t,camera:r}=e,{light:s,shadow:i}=this,{depthTexture:n,shadowMap:a}=this.setupRenderTarget(i,e),o=t.shadowMap.type,u=t.hasCompatibility(E.TEXTURE_COMPARE);if(o!==et&&o!==tt||!u?(n.minFilter=B,n.magFilter=B):(n.minFilter=de,n.magFilter=de),i.camera.coordinateSystem=r.coordinateSystem,i.camera.updateProjectionMatrix(),o===Je&&!0!==i.isPointLightShadow){n.compareFunction=null,a.depth>1?(a._vsmShadowMapVertical||(a._vsmShadowMapVertical=e.createRenderTarget(i.mapSize.width,i.mapSize.height,{format:W,type:_e,depth:a.depth,depthBuffer:!1}),a._vsmShadowMapVertical.texture.name="VSMVertical"),this.vsmShadowMapVertical=a._vsmShadowMapVertical,a._vsmShadowMapHorizontal||(a._vsmShadowMapHorizontal=e.createRenderTarget(i.mapSize.width,i.mapSize.height,{format:W,type:_e,depth:a.depth,depthBuffer:!1}),a._vsmShadowMapHorizontal.texture.name="VSMHorizontal"),this.vsmShadowMapHorizontal=a._vsmShadowMapHorizontal):(this.vsmShadowMapVertical=e.createRenderTarget(i.mapSize.width,i.mapSize.height,{format:W,type:_e,depthBuffer:!1}),this.vsmShadowMapHorizontal=e.createRenderTarget(i.mapSize.width,i.mapSize.height,{format:W,type:_e,depthBuffer:!1}));let t=Dl(n);n.isArrayTexture&&(t=t.depth(this.depthLayer));let r=Dl(this.vsmShadowMapVertical.texture);n.isArrayTexture&&(r=r.depth(this.depthLayer));const s=Lc("blurSamples","float",i).setGroup(xa),o=Lc("radius","float",i).setGroup(xa),u=Lc("mapSize","vec2",i).setGroup(xa);let l=this.vsmMaterialVertical||(this.vsmMaterialVertical=new fg);l.fragmentNode=W_({samples:s,radius:o,size:u,shadowPass:t,depthLayer:this.depthLayer}).context(e.getSharedContext()),l.name="VSMVertical",l=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new fg),l.fragmentNode=H_({samples:s,radius:o,size:u,shadowPass:r,depthLayer:this.depthLayer}).context(e.getSharedContext()),l.name="VSMHorizontal"}const l=Lc("intensity","float",i).setGroup(xa),d=Lc("normalBias","float",i).setGroup(xa),c=p_(s).mul(S_.add(cc.mul(d))),h=this.setupShadowCoord(e,c),p=i.filterNode||this.getShadowFilterFn(t.shadowMap.type)||null;if(null===p)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const g=o===Je&&!0!==i.isPointLightShadow?this.vsmShadowMapHorizontal.texture:n,m=this.setupShadowFilter(e,{filterFn:p,shadowTexture:a.texture,depthTexture:g,shadowCoord:h,shadow:i,depthLayer:this.depthLayer});let f,y;!0===t.shadowMap.transmitted&&(a.texture.isCubeTexture?f=Mc(a.texture,h.xyz):(f=Dl(a.texture,h),n.isArrayTexture&&(f=f.depth(this.depthLayer)))),y=f?au(1,m.rgb.mix(f,1),l.mul(f.a)).toVar():au(1,m,l).toVar(),this.shadowMap=a,this.shadow.map=a;const b=`${this.light.type} Shadow [ ${this.light.name||"ID: "+this.light.id} ]`;return f&&y.toInspector(`${b} / Color`,()=>this.shadowMap.texture.isCubeTexture?Mc(this.shadowMap.texture):Dl(this.shadowMap.texture)),y.toInspector(`${b} / Depth`,()=>this.shadowMap.texture.isCubeTexture?Mc(this.shadowMap.texture).r.oneMinus():Ul(this.shadowMap.depthTexture,El().mul(wl(Dl(this.shadowMap.depthTexture)))).r.oneMinus())}setup(e){if(!1!==e.renderer.shadowMap.enabled)return ln(()=>{const t=e.renderer.shadowMap.type;this._currentShadowType!==t&&(this._reset(),this._node=null);let r=this._node;return this.setupShadowPosition(e),null===r&&(this._node=r=this.setupShadow(e),this._currentShadowType=t),e.material.receivedShadowNode&&(r=e.material.receivedShadowNode(r)),r})()}renderShadow(e){const{shadow:t,shadowMap:r,light:s}=this,{renderer:i,scene:n}=e;t.updateMatrices(s),r.setSize(t.mapSize.width,t.mapSize.height,r.depth);const a=n.name;n.name=`Shadow Map [ ${s.name||"ID: "+s.id} ]`,i.render(n,t.camera),n.name=a}updateShadow(e){const{shadowMap:t,light:r,shadow:s}=this,{renderer:i,scene:n,camera:a}=e,o=i.shadowMap.type,u=t.depthTexture.version;this._depthVersionCached=u;const l=s.camera.layers.mask;4294967294&s.camera.layers.mask||(s.camera.layers.mask=a.layers.mask);const d=i.getRenderObjectFunction(),c=i.getMRT(),h=!!c&&c.has("velocity");j_=B_(i,n,j_),n.overrideMaterial=V_(r),i.setRenderObjectFunction(z_(i,s,o,h)),i.setClearColor(0,0),i.setRenderTarget(t),this.renderShadow(e),i.setRenderObjectFunction(d),o===Je&&!0!==s.isPointLightShadow&&this.vsmPass(i),s.camera.layers.mask=l,F_(i,n,j_)}vsmPass(e){const{shadow:t}=this,r=this.shadowMap.depth;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height,r),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height,r),e.setRenderTarget(this.vsmShadowMapVertical),X_.material=this.vsmMaterialVertical,X_.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),X_.material=this.vsmMaterialHorizontal,X_.render(e)}dispose(){this._reset(),super.dispose()}_reset(){this._currentShadowType=null,k_(this.light),this.shadowMap&&(this.shadowMap.dispose(),this.shadowMap=null),null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null)}updateBefore(e){const{shadow:t}=this;let r=t.needsUpdate||t.autoUpdate;r&&(this._cameraFrameId[e.camera]===e.frameId&&(r=!1),this._cameraFrameId[e.camera]=e.frameId),r&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const Y_=(e,t)=>new K_(e,t),Q_=new e,Z_=new a,J_=new r,ev=new r,tv=[new r(1,0,0),new r(-1,0,0),new r(0,-1,0),new r(0,1,0),new r(0,0,1),new r(0,0,-1)],rv=[new r(0,-1,0),new r(0,-1,0),new r(0,0,-1),new r(0,0,1),new r(0,-1,0),new r(0,-1,0)],sv=[new r(1,0,0),new r(-1,0,0),new r(0,1,0),new r(0,-1,0),new r(0,0,1),new r(0,0,-1)],iv=[new r(0,-1,0),new r(0,-1,0),new r(0,0,1),new r(0,0,-1),new r(0,-1,0),new r(0,-1,0)],nv=ln(({depthTexture:e,bd3D:t,dp:r})=>Mc(e,t).compare(r)),av=ln(({depthTexture:e,bd3D:t,dp:r,shadow:s})=>{const i=Lc("radius","float",s).setGroup(xa),n=Lc("mapSize","vec2",s).setGroup(xa),a=i.div(n.x),o=Bo(t),u=No(Zo(t,o.x.greaterThan(o.z).select(Nn(0,1,0),Nn(1,0,0)))),l=Zo(t,u),d=fx(Yl.xy).mul(6.28318530718),c=yx(0,5,d),h=yx(1,5,d),p=yx(2,5,d),g=yx(3,5,d),m=yx(4,5,d);return Mc(e,t.add(u.mul(c.x).add(l.mul(c.y)).mul(a))).compare(r).add(Mc(e,t.add(u.mul(h.x).add(l.mul(h.y)).mul(a))).compare(r)).add(Mc(e,t.add(u.mul(p.x).add(l.mul(p.y)).mul(a))).compare(r)).add(Mc(e,t.add(u.mul(g.x).add(l.mul(g.y)).mul(a))).compare(r)).add(Mc(e,t.add(u.mul(m.x).add(l.mul(m.y)).mul(a))).compare(r)).mul(.2)}),ov=ln(({filterFn:e,depthTexture:t,shadowCoord:r,shadow:s},i)=>{const n=r.xyz.toConst(),a=n.abs().toConst(),o=a.x.max(a.y).max(a.z),u=va("float").setGroup(xa).onRenderUpdate(()=>s.camera.near),l=va("float").setGroup(xa).onRenderUpdate(()=>s.camera.far),d=Lc("bias","float",s).setGroup(xa),c=mn(1).toVar();return hn(o.sub(l).lessThanEqual(0).and(o.sub(u).greaterThanEqual(0)),()=>{let r;i.renderer.reversedDepthBuffer?(r=Yp(o.negate(),u,l),r.subAssign(d)):(r=Kp(o.negate(),u,l),r.addAssign(d));const a=n.normalize();c.assign(e({depthTexture:t,bd3D:a,dp:r,shadow:s}))}),c});class uv extends K_{static get type(){return"PointShadowNode"}constructor(e,t=null){super(e,t)}getShadowFilterFn(e){return e===rt?nv:av}setupShadowCoord(e,t){return t}setupShadowFilter(e,{filterFn:t,depthTexture:r,shadowCoord:s,shadow:i}){return ov({filterFn:t,depthTexture:r,shadowCoord:s,shadow:i})}setupRenderTarget(e,t){const r=new st(e.mapSize.width);r.name="PointShadowDepthTexture",r.compareFunction=t.renderer.reversedDepthBuffer?M:w;const s=t.createCubeRenderTarget(e.mapSize.width);return s.texture.name="PointShadowMap",s.depthTexture=r,{shadowMap:s,depthTexture:r}}renderShadow(e){const{shadow:t,shadowMap:r,light:s}=this,{renderer:i,scene:n}=e,a=t.camera,o=t.matrix,u=i.coordinateSystem===h,l=u?tv:sv,d=u?rv:iv;r.setSize(t.mapSize.width,t.mapSize.width);const c=i.autoClear,p=i.getClearColor(Q_),g=i.getClearAlpha();i.autoClear=!1,i.setClearColor(t.clearColor,t.clearAlpha);for(let e=0;e<6;e++){i.setRenderTarget(r,e),i.clear();const u=s.distance||a.far;u!==a.far&&(a.far=u,a.updateProjectionMatrix()),J_.setFromMatrixPosition(s.matrixWorld),a.position.copy(J_),ev.copy(a.position),ev.add(l[e]),a.up.copy(d[e]),a.lookAt(ev),a.updateMatrixWorld(),o.makeTranslation(-J_.x,-J_.y,-J_.z),Z_.multiplyMatrices(a.projectionMatrix,a.matrixWorldInverse),t._frustum.setFromProjectionMatrix(Z_,a.coordinateSystem,a.reversedDepth);const c=n.name;n.name=`Point Light Shadow [ ${s.name||"ID: "+s.id} ] - Face ${e+1}`,i.render(n,a),n.name=c}i.autoClear=c,i.setClearColor(p,g)}}const lv=(e,t)=>new uv(e,t);class dv extends Fp{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.light=t,this.color=new e,this.colorNode=t&&t.colorNode||va(this.color).setGroup(xa),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0,this.updateType=ei.FRAME,t&&t.shadow&&(this._shadowDisposeListener=()=>{this.disposeShadow()},t.addEventListener("dispose",this._shadowDisposeListener))}dispose(){this._shadowDisposeListener&&this.light.removeEventListener("dispose",this._shadowDisposeListener),super.dispose()}disposeShadow(){null!==this.shadowNode&&(this.shadowNode.dispose(),this.shadowNode=null),this.shadowColorNode=null,null!==this.baseColorNode&&(this.colorNode=this.baseColorNode,this.baseColorNode=null)}getHash(){return this.light.uuid}getLightVector(e){return y_(this.light).sub(e.context.positionView||Jd)}setupDirect(){}setupDirectRectArea(){}setupShadowNode(){return Y_(this.light)}setupShadow(e){const{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let r=this.shadowColorNode;if(null===r){const e=this.light.shadow.shadowNode;let t;t=void 0!==e?Ji(e):this.setupShadowNode(),this.shadowNode=t,this.shadowColorNode=r=this.colorNode.mul(t),this.baseColorNode=this.colorNode}e.context.getShadow&&(r=e.context.getShadow(this,e)),this.colorNode=r}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&(this.shadowNode.dispose(),this.shadowNode=null,this.shadowColorNode=null);const t=this.setupDirect(e),r=this.setupDirectRectArea(e);t&&e.lightsNode.setupDirectLight(e,this,t),r&&e.lightsNode.setupDirectRectAreaLight(e,this,r)}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const cv=ln(({lightDistance:e,cutoffDistance:t,decayExponent:r})=>{const s=e.pow(r).max(.01).reciprocal();return t.greaterThan(0).select(s.mul(e.div(t).pow4().oneMinus().clamp().pow2()),s)}),hv=({color:e,lightVector:t,cutoffDistance:r,decayExponent:s})=>{const i=t.normalize(),n=t.length(),a=cv({lightDistance:n,cutoffDistance:r,decayExponent:s});return{lightDirection:i,lightColor:e.mul(a)}};class pv extends dv{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=va(0).setGroup(xa),this.decayExponentNode=va(2).setGroup(xa)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setupShadowNode(){return lv(this.light)}setupDirect(e){return hv({color:this.colorNode,lightVector:this.getLightVector(e),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode})}}const gv=ln(([e=El()])=>{const t=e.mul(2),r=t.x.floor(),s=t.y.floor();return r.add(s).mod(2).sign()}),mv=ln(([e=El()],{renderer:t,material:r})=>{const s=nu(e.mul(2).sub(1));let i;if(r.alphaToCoverage&&t.currentSamples>0){const e=mn(s.fwidth()).toVar();i=du(e.oneMinus(),e.add(1),s).oneMinus()}else i=xu(s.greaterThan(1),0,1);return i}),fv=ln(([e,t,r])=>{const s=mn(r).toVar(),i=mn(t).toVar(),n=bn(e).toVar();return xu(n,i,s)}).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),yv=ln(([e,t])=>{const r=bn(t).toVar(),s=mn(e).toVar();return xu(r,s.negate(),s)}).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),bv=ln(([e])=>{const t=mn(e).toVar();return fn(_o(t))}).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),xv=ln(([e,t])=>{const r=mn(e).toVar();return t.assign(bv(r)),r.sub(mn(t))}),Tv=Pb([ln(([e,t,r,s,i,n])=>{const a=mn(n).toVar(),o=mn(i).toVar(),u=mn(s).toVar(),l=mn(r).toVar(),d=mn(t).toVar(),c=mn(e).toVar(),h=mn(Fa(1,o)).toVar();return Fa(1,a).mul(c.mul(h).add(d.mul(o))).add(a.mul(l.mul(h).add(u.mul(o))))}).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"}]}),ln(([e,t,r,s,i,n])=>{const a=mn(n).toVar(),o=mn(i).toVar(),u=Nn(s).toVar(),l=Nn(r).toVar(),d=Nn(t).toVar(),c=Nn(e).toVar(),h=mn(Fa(1,o)).toVar();return Fa(1,a).mul(c.mul(h).add(d.mul(o))).add(a.mul(l.mul(h).add(u.mul(o))))}).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"}]})]),_v=Pb([ln(([e,t,r,s,i,n,a,o,u,l,d])=>{const c=mn(d).toVar(),h=mn(l).toVar(),p=mn(u).toVar(),g=mn(o).toVar(),m=mn(a).toVar(),f=mn(n).toVar(),y=mn(i).toVar(),b=mn(s).toVar(),x=mn(r).toVar(),T=mn(t).toVar(),_=mn(e).toVar(),v=mn(Fa(1,p)).toVar(),N=mn(Fa(1,h)).toVar();return mn(Fa(1,c)).toVar().mul(N.mul(_.mul(v).add(T.mul(p))).add(h.mul(x.mul(v).add(b.mul(p))))).add(c.mul(N.mul(y.mul(v).add(f.mul(p))).add(h.mul(m.mul(v).add(g.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"}]}),ln(([e,t,r,s,i,n,a,o,u,l,d])=>{const c=mn(d).toVar(),h=mn(l).toVar(),p=mn(u).toVar(),g=Nn(o).toVar(),m=Nn(a).toVar(),f=Nn(n).toVar(),y=Nn(i).toVar(),b=Nn(s).toVar(),x=Nn(r).toVar(),T=Nn(t).toVar(),_=Nn(e).toVar(),v=mn(Fa(1,p)).toVar(),N=mn(Fa(1,h)).toVar();return mn(Fa(1,c)).toVar().mul(N.mul(_.mul(v).add(T.mul(p))).add(h.mul(x.mul(v).add(b.mul(p))))).add(c.mul(N.mul(y.mul(v).add(f.mul(p))).add(h.mul(m.mul(v).add(g.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"}]})]),vv=ln(([e,t,r])=>{const s=mn(r).toVar(),i=mn(t).toVar(),n=yn(e).toVar(),a=yn(n.bitAnd(yn(7))).toVar(),o=mn(fv(a.lessThan(yn(4)),i,s)).toVar(),u=mn(La(2,fv(a.lessThan(yn(4)),s,i))).toVar();return yv(o,bn(a.bitAnd(yn(1)))).add(yv(u,bn(a.bitAnd(yn(2)))))}).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),Nv=ln(([e,t,r,s])=>{const i=mn(s).toVar(),n=mn(r).toVar(),a=mn(t).toVar(),o=yn(e).toVar(),u=yn(o.bitAnd(yn(15))).toVar(),l=mn(fv(u.lessThan(yn(8)),a,n)).toVar(),d=mn(fv(u.lessThan(yn(4)),n,fv(u.equal(yn(12)).or(u.equal(yn(14))),a,i))).toVar();return yv(l,bn(u.bitAnd(yn(1)))).add(yv(d,bn(u.bitAnd(yn(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"}]}),Sv=Pb([vv,Nv]),Rv=ln(([e,t,r])=>{const s=mn(r).toVar(),i=mn(t).toVar(),n=Rn(e).toVar();return Nn(Sv(n.x,i,s),Sv(n.y,i,s),Sv(n.z,i,s))}).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),Ev=ln(([e,t,r,s])=>{const i=mn(s).toVar(),n=mn(r).toVar(),a=mn(t).toVar(),o=Rn(e).toVar();return Nn(Sv(o.x,a,n,i),Sv(o.y,a,n,i),Sv(o.z,a,n,i))}).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"}]}),Av=Pb([Rv,Ev]),wv=ln(([e])=>{const t=mn(e).toVar();return La(.6616,t)}).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),Cv=ln(([e])=>{const t=mn(e).toVar();return La(.982,t)}).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),Mv=Pb([wv,ln(([e])=>{const t=Nn(e).toVar();return La(.6616,t)}).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),Bv=Pb([Cv,ln(([e])=>{const t=Nn(e).toVar();return La(.982,t)}).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),Fv=ln(([e,t])=>{const r=fn(t).toVar(),s=yn(e).toVar();return s.shiftLeft(r).bitOr(s.shiftRight(fn(32).sub(r)))}).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),Lv=ln(([e,t,r])=>{e.subAssign(r),e.bitXorAssign(Fv(r,fn(4))),r.addAssign(t),t.subAssign(e),t.bitXorAssign(Fv(e,fn(6))),e.addAssign(r),r.subAssign(t),r.bitXorAssign(Fv(t,fn(8))),t.addAssign(e),e.subAssign(r),e.bitXorAssign(Fv(r,fn(16))),r.addAssign(t),t.subAssign(e),t.bitXorAssign(Fv(e,fn(19))),e.addAssign(r),r.subAssign(t),r.bitXorAssign(Fv(t,fn(4))),t.addAssign(e)}),Pv=ln(([e,t,r])=>{const s=yn(r).toVar(),i=yn(t).toVar(),n=yn(e).toVar();return s.bitXorAssign(i),s.subAssign(Fv(i,fn(14))),n.bitXorAssign(s),n.subAssign(Fv(s,fn(11))),i.bitXorAssign(n),i.subAssign(Fv(n,fn(25))),s.bitXorAssign(i),s.subAssign(Fv(i,fn(16))),n.bitXorAssign(s),n.subAssign(Fv(s,fn(4))),i.bitXorAssign(n),i.subAssign(Fv(n,fn(14))),s.bitXorAssign(i),s.subAssign(Fv(i,fn(24))),s}).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),Dv=ln(([e])=>{const t=yn(e).toVar();return mn(t).div(mn(yn(fn(4294967295))))}).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),Uv=ln(([e])=>{const t=mn(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))}).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),Iv=Pb([ln(([e])=>{const t=fn(e).toVar(),r=yn(yn(1)).toVar(),s=yn(yn(fn(3735928559)).add(r.shiftLeft(yn(2))).add(yn(13))).toVar();return Pv(s.add(yn(t)),s,s)}).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),ln(([e,t])=>{const r=fn(t).toVar(),s=fn(e).toVar(),i=yn(yn(2)).toVar(),n=yn().toVar(),a=yn().toVar(),o=yn().toVar();return n.assign(a.assign(o.assign(yn(fn(3735928559)).add(i.shiftLeft(yn(2))).add(yn(13))))),n.addAssign(yn(s)),a.addAssign(yn(r)),Pv(n,a,o)}).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),ln(([e,t,r])=>{const s=fn(r).toVar(),i=fn(t).toVar(),n=fn(e).toVar(),a=yn(yn(3)).toVar(),o=yn().toVar(),u=yn().toVar(),l=yn().toVar();return o.assign(u.assign(l.assign(yn(fn(3735928559)).add(a.shiftLeft(yn(2))).add(yn(13))))),o.addAssign(yn(n)),u.addAssign(yn(i)),l.addAssign(yn(s)),Pv(o,u,l)}).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),ln(([e,t,r,s])=>{const i=fn(s).toVar(),n=fn(r).toVar(),a=fn(t).toVar(),o=fn(e).toVar(),u=yn(yn(4)).toVar(),l=yn().toVar(),d=yn().toVar(),c=yn().toVar();return l.assign(d.assign(c.assign(yn(fn(3735928559)).add(u.shiftLeft(yn(2))).add(yn(13))))),l.addAssign(yn(o)),d.addAssign(yn(a)),c.addAssign(yn(n)),Lv(l,d,c),l.addAssign(yn(i)),Pv(l,d,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"}]}),ln(([e,t,r,s,i])=>{const n=fn(i).toVar(),a=fn(s).toVar(),o=fn(r).toVar(),u=fn(t).toVar(),l=fn(e).toVar(),d=yn(yn(5)).toVar(),c=yn().toVar(),h=yn().toVar(),p=yn().toVar();return c.assign(h.assign(p.assign(yn(fn(3735928559)).add(d.shiftLeft(yn(2))).add(yn(13))))),c.addAssign(yn(l)),h.addAssign(yn(u)),p.addAssign(yn(o)),Lv(c,h,p),c.addAssign(yn(a)),h.addAssign(yn(n)),Pv(c,h,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"}]})]),Ov=Pb([ln(([e,t])=>{const r=fn(t).toVar(),s=fn(e).toVar(),i=yn(Iv(s,r)).toVar(),n=Rn().toVar();return n.x.assign(i.bitAnd(fn(255))),n.y.assign(i.shiftRight(fn(8)).bitAnd(fn(255))),n.z.assign(i.shiftRight(fn(16)).bitAnd(fn(255))),n}).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),ln(([e,t,r])=>{const s=fn(r).toVar(),i=fn(t).toVar(),n=fn(e).toVar(),a=yn(Iv(n,i,s)).toVar(),o=Rn().toVar();return o.x.assign(a.bitAnd(fn(255))),o.y.assign(a.shiftRight(fn(8)).bitAnd(fn(255))),o.z.assign(a.shiftRight(fn(16)).bitAnd(fn(255))),o}).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),Vv=Pb([ln(([e])=>{const t=xn(e).toVar(),r=fn().toVar(),s=fn().toVar(),i=mn(xv(t.x,r)).toVar(),n=mn(xv(t.y,s)).toVar(),a=mn(Uv(i)).toVar(),o=mn(Uv(n)).toVar(),u=mn(Tv(Sv(Iv(r,s),i,n),Sv(Iv(r.add(fn(1)),s),i.sub(1),n),Sv(Iv(r,s.add(fn(1))),i,n.sub(1)),Sv(Iv(r.add(fn(1)),s.add(fn(1))),i.sub(1),n.sub(1)),a,o)).toVar();return Mv(u)}).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),ln(([e])=>{const t=Nn(e).toVar(),r=fn().toVar(),s=fn().toVar(),i=fn().toVar(),n=mn(xv(t.x,r)).toVar(),a=mn(xv(t.y,s)).toVar(),o=mn(xv(t.z,i)).toVar(),u=mn(Uv(n)).toVar(),l=mn(Uv(a)).toVar(),d=mn(Uv(o)).toVar(),c=mn(_v(Sv(Iv(r,s,i),n,a,o),Sv(Iv(r.add(fn(1)),s,i),n.sub(1),a,o),Sv(Iv(r,s.add(fn(1)),i),n,a.sub(1),o),Sv(Iv(r.add(fn(1)),s.add(fn(1)),i),n.sub(1),a.sub(1),o),Sv(Iv(r,s,i.add(fn(1))),n,a,o.sub(1)),Sv(Iv(r.add(fn(1)),s,i.add(fn(1))),n.sub(1),a,o.sub(1)),Sv(Iv(r,s.add(fn(1)),i.add(fn(1))),n,a.sub(1),o.sub(1)),Sv(Iv(r.add(fn(1)),s.add(fn(1)),i.add(fn(1))),n.sub(1),a.sub(1),o.sub(1)),u,l,d)).toVar();return Bv(c)}).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),kv=Pb([ln(([e])=>{const t=xn(e).toVar(),r=fn().toVar(),s=fn().toVar(),i=mn(xv(t.x,r)).toVar(),n=mn(xv(t.y,s)).toVar(),a=mn(Uv(i)).toVar(),o=mn(Uv(n)).toVar(),u=Nn(Tv(Av(Ov(r,s),i,n),Av(Ov(r.add(fn(1)),s),i.sub(1),n),Av(Ov(r,s.add(fn(1))),i,n.sub(1)),Av(Ov(r.add(fn(1)),s.add(fn(1))),i.sub(1),n.sub(1)),a,o)).toVar();return Mv(u)}).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),ln(([e])=>{const t=Nn(e).toVar(),r=fn().toVar(),s=fn().toVar(),i=fn().toVar(),n=mn(xv(t.x,r)).toVar(),a=mn(xv(t.y,s)).toVar(),o=mn(xv(t.z,i)).toVar(),u=mn(Uv(n)).toVar(),l=mn(Uv(a)).toVar(),d=mn(Uv(o)).toVar(),c=Nn(_v(Av(Ov(r,s,i),n,a,o),Av(Ov(r.add(fn(1)),s,i),n.sub(1),a,o),Av(Ov(r,s.add(fn(1)),i),n,a.sub(1),o),Av(Ov(r.add(fn(1)),s.add(fn(1)),i),n.sub(1),a.sub(1),o),Av(Ov(r,s,i.add(fn(1))),n,a,o.sub(1)),Av(Ov(r.add(fn(1)),s,i.add(fn(1))),n.sub(1),a,o.sub(1)),Av(Ov(r,s.add(fn(1)),i.add(fn(1))),n,a.sub(1),o.sub(1)),Av(Ov(r.add(fn(1)),s.add(fn(1)),i.add(fn(1))),n.sub(1),a.sub(1),o.sub(1)),u,l,d)).toVar();return Bv(c)}).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),Gv=Pb([ln(([e])=>{const t=mn(e).toVar(),r=fn(bv(t)).toVar();return Dv(Iv(r))}).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),ln(([e])=>{const t=xn(e).toVar(),r=fn(bv(t.x)).toVar(),s=fn(bv(t.y)).toVar();return Dv(Iv(r,s))}).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),ln(([e])=>{const t=Nn(e).toVar(),r=fn(bv(t.x)).toVar(),s=fn(bv(t.y)).toVar(),i=fn(bv(t.z)).toVar();return Dv(Iv(r,s,i))}).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),ln(([e])=>{const t=An(e).toVar(),r=fn(bv(t.x)).toVar(),s=fn(bv(t.y)).toVar(),i=fn(bv(t.z)).toVar(),n=fn(bv(t.w)).toVar();return Dv(Iv(r,s,i,n))}).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),$v=Pb([ln(([e])=>{const t=mn(e).toVar(),r=fn(bv(t)).toVar();return Nn(Dv(Iv(r,fn(0))),Dv(Iv(r,fn(1))),Dv(Iv(r,fn(2))))}).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),ln(([e])=>{const t=xn(e).toVar(),r=fn(bv(t.x)).toVar(),s=fn(bv(t.y)).toVar();return Nn(Dv(Iv(r,s,fn(0))),Dv(Iv(r,s,fn(1))),Dv(Iv(r,s,fn(2))))}).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),ln(([e])=>{const t=Nn(e).toVar(),r=fn(bv(t.x)).toVar(),s=fn(bv(t.y)).toVar(),i=fn(bv(t.z)).toVar();return Nn(Dv(Iv(r,s,i,fn(0))),Dv(Iv(r,s,i,fn(1))),Dv(Iv(r,s,i,fn(2))))}).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),ln(([e])=>{const t=An(e).toVar(),r=fn(bv(t.x)).toVar(),s=fn(bv(t.y)).toVar(),i=fn(bv(t.z)).toVar(),n=fn(bv(t.w)).toVar();return Nn(Dv(Iv(r,s,i,n,fn(0))),Dv(Iv(r,s,i,n,fn(1))),Dv(Iv(r,s,i,n,fn(2))))}).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),zv=ln(([e,t,r,s])=>{const i=mn(s).toVar(),n=mn(r).toVar(),a=fn(t).toVar(),o=Nn(e).toVar(),u=mn(0).toVar(),l=mn(1).toVar();return Rp(a,()=>{u.addAssign(l.mul(Vv(o))),l.mulAssign(i),o.mulAssign(n)}),u}).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"}]}),Wv=ln(([e,t,r,s])=>{const i=mn(s).toVar(),n=mn(r).toVar(),a=fn(t).toVar(),o=Nn(e).toVar(),u=Nn(0).toVar(),l=mn(1).toVar();return Rp(a,()=>{u.addAssign(l.mul(kv(o))),l.mulAssign(i),o.mulAssign(n)}),u}).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"}]}),Hv=ln(([e,t,r,s])=>{const i=mn(s).toVar(),n=mn(r).toVar(),a=fn(t).toVar(),o=Nn(e).toVar();return xn(zv(o,a,n,i),zv(o.add(Nn(fn(19),fn(193),fn(17))),a,n,i))}).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"}]}),qv=ln(([e,t,r,s])=>{const i=mn(s).toVar(),n=mn(r).toVar(),a=fn(t).toVar(),o=Nn(e).toVar(),u=Nn(Wv(o,a,n,i)).toVar(),l=mn(zv(o.add(Nn(fn(19),fn(193),fn(17))),a,n,i)).toVar();return An(u,l)}).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"}]}),jv=Pb([ln(([e,t,r,s,i,n,a])=>{const o=fn(a).toVar(),u=mn(n).toVar(),l=fn(i).toVar(),d=fn(s).toVar(),c=fn(r).toVar(),h=fn(t).toVar(),p=xn(e).toVar(),g=Nn($v(xn(h.add(d),c.add(l)))).toVar(),m=xn(g.x,g.y).toVar();m.subAssign(.5),m.mulAssign(u),m.addAssign(.5);const f=xn(xn(mn(h),mn(c)).add(m)).toVar(),y=xn(f.sub(p)).toVar();return hn(o.equal(fn(2)),()=>Bo(y.x).add(Bo(y.y))),hn(o.equal(fn(3)),()=>qo(Bo(y.x),Bo(y.y))),Qo(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"}]}),ln(([e,t,r,s,i,n,a,o,u])=>{const l=fn(u).toVar(),d=mn(o).toVar(),c=fn(a).toVar(),h=fn(n).toVar(),p=fn(i).toVar(),g=fn(s).toVar(),m=fn(r).toVar(),f=fn(t).toVar(),y=Nn(e).toVar(),b=Nn($v(Nn(f.add(p),m.add(h),g.add(c)))).toVar();b.subAssign(.5),b.mulAssign(d),b.addAssign(.5);const x=Nn(Nn(mn(f),mn(m),mn(g)).add(b)).toVar(),T=Nn(x.sub(y)).toVar();return hn(l.equal(fn(2)),()=>Bo(T.x).add(Bo(T.y)).add(Bo(T.z))),hn(l.equal(fn(3)),()=>qo(Bo(T.x),Bo(T.y),Bo(T.z))),Qo(T,T)}).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"}]})]),Xv=ln(([e,t,r])=>{const s=fn(r).toVar(),i=mn(t).toVar(),n=xn(e).toVar(),a=fn().toVar(),o=fn().toVar(),u=xn(xv(n.x,a),xv(n.y,o)).toVar(),l=mn(1e6).toVar();return Rp({start:-1,end:fn(1),name:"x",condition:"<="},({x:e})=>{Rp({start:-1,end:fn(1),name:"y",condition:"<="},({y:t})=>{const r=mn(jv(u,e,t,a,o,i,s)).toVar();l.assign(Ho(l,r))})}),hn(s.equal(fn(0)),()=>{l.assign(xo(l))}),l}).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),Kv=ln(([e,t,r])=>{const s=fn(r).toVar(),i=mn(t).toVar(),n=xn(e).toVar(),a=fn().toVar(),o=fn().toVar(),u=xn(xv(n.x,a),xv(n.y,o)).toVar(),l=xn(1e6,1e6).toVar();return Rp({start:-1,end:fn(1),name:"x",condition:"<="},({x:e})=>{Rp({start:-1,end:fn(1),name:"y",condition:"<="},({y:t})=>{const r=mn(jv(u,e,t,a,o,i,s)).toVar();hn(r.lessThan(l.x),()=>{l.y.assign(l.x),l.x.assign(r)}).ElseIf(r.lessThan(l.y),()=>{l.y.assign(r)})})}),hn(s.equal(fn(0)),()=>{l.assign(xo(l))}),l}).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),Yv=ln(([e,t,r])=>{const s=fn(r).toVar(),i=mn(t).toVar(),n=xn(e).toVar(),a=fn().toVar(),o=fn().toVar(),u=xn(xv(n.x,a),xv(n.y,o)).toVar(),l=Nn(1e6,1e6,1e6).toVar();return Rp({start:-1,end:fn(1),name:"x",condition:"<="},({x:e})=>{Rp({start:-1,end:fn(1),name:"y",condition:"<="},({y:t})=>{const r=mn(jv(u,e,t,a,o,i,s)).toVar();hn(r.lessThan(l.x),()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(r)}).ElseIf(r.lessThan(l.y),()=>{l.z.assign(l.y),l.y.assign(r)}).ElseIf(r.lessThan(l.z),()=>{l.z.assign(r)})})}),hn(s.equal(fn(0)),()=>{l.assign(xo(l))}),l}).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),Qv=Pb([Xv,ln(([e,t,r])=>{const s=fn(r).toVar(),i=mn(t).toVar(),n=Nn(e).toVar(),a=fn().toVar(),o=fn().toVar(),u=fn().toVar(),l=Nn(xv(n.x,a),xv(n.y,o),xv(n.z,u)).toVar(),d=mn(1e6).toVar();return Rp({start:-1,end:fn(1),name:"x",condition:"<="},({x:e})=>{Rp({start:-1,end:fn(1),name:"y",condition:"<="},({y:t})=>{Rp({start:-1,end:fn(1),name:"z",condition:"<="},({z:r})=>{const n=mn(jv(l,e,t,r,a,o,u,i,s)).toVar();d.assign(Ho(d,n))})})}),hn(s.equal(fn(0)),()=>{d.assign(xo(d))}),d}).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),Zv=Pb([Kv,ln(([e,t,r])=>{const s=fn(r).toVar(),i=mn(t).toVar(),n=Nn(e).toVar(),a=fn().toVar(),o=fn().toVar(),u=fn().toVar(),l=Nn(xv(n.x,a),xv(n.y,o),xv(n.z,u)).toVar(),d=xn(1e6,1e6).toVar();return Rp({start:-1,end:fn(1),name:"x",condition:"<="},({x:e})=>{Rp({start:-1,end:fn(1),name:"y",condition:"<="},({y:t})=>{Rp({start:-1,end:fn(1),name:"z",condition:"<="},({z:r})=>{const n=mn(jv(l,e,t,r,a,o,u,i,s)).toVar();hn(n.lessThan(d.x),()=>{d.y.assign(d.x),d.x.assign(n)}).ElseIf(n.lessThan(d.y),()=>{d.y.assign(n)})})})}),hn(s.equal(fn(0)),()=>{d.assign(xo(d))}),d}).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),Jv=Pb([Yv,ln(([e,t,r])=>{const s=fn(r).toVar(),i=mn(t).toVar(),n=Nn(e).toVar(),a=fn().toVar(),o=fn().toVar(),u=fn().toVar(),l=Nn(xv(n.x,a),xv(n.y,o),xv(n.z,u)).toVar(),d=Nn(1e6,1e6,1e6).toVar();return Rp({start:-1,end:fn(1),name:"x",condition:"<="},({x:e})=>{Rp({start:-1,end:fn(1),name:"y",condition:"<="},({y:t})=>{Rp({start:-1,end:fn(1),name:"z",condition:"<="},({z:r})=>{const n=mn(jv(l,e,t,r,a,o,u,i,s)).toVar();hn(n.lessThan(d.x),()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(n)}).ElseIf(n.lessThan(d.y),()=>{d.z.assign(d.y),d.y.assign(n)}).ElseIf(n.lessThan(d.z),()=>{d.z.assign(n)})})})}),hn(s.equal(fn(0)),()=>{d.assign(xo(d))}),d}).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),eN=ln(([e,t,r,s,i,n,a,o,u,l,d])=>{const c=fn(e).toVar(),h=xn(t).toVar(),p=xn(r).toVar(),g=xn(s).toVar(),m=mn(i).toVar(),f=mn(n).toVar(),y=mn(a).toVar(),b=bn(o).toVar(),x=fn(u).toVar(),T=mn(l).toVar(),_=mn(d).toVar(),v=h.mul(p).add(g),N=mn(0).toVar();return hn(c.equal(fn(0)),()=>{N.assign(kv(v))}),hn(c.equal(fn(1)),()=>{N.assign($v(v))}),hn(c.equal(fn(2)),()=>{N.assign(Jv(v,m,fn(0)))}),hn(c.equal(fn(3)),()=>{N.assign(Wv(Nn(v,0),x,T,_))}),N.assign(N.mul(y.sub(f)).add(f)),hn(b,()=>{N.assign(ou(N,f,y))}),N}).setLayout({name:"mx_unifiednoise2d",type:"float",inputs:[{name:"noiseType",type:"int"},{name:"texcoord",type:"vec2"},{name:"freq",type:"vec2"},{name:"offset",type:"vec2"},{name:"jitter",type:"float"},{name:"outmin",type:"float"},{name:"outmax",type:"float"},{name:"clampoutput",type:"bool"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),tN=ln(([e,t,r,s,i,n,a,o,u,l,d])=>{const c=fn(e).toVar(),h=Nn(t).toVar(),p=Nn(r).toVar(),g=Nn(s).toVar(),m=mn(i).toVar(),f=mn(n).toVar(),y=mn(a).toVar(),b=bn(o).toVar(),x=fn(u).toVar(),T=mn(l).toVar(),_=mn(d).toVar(),v=h.mul(p).add(g),N=mn(0).toVar();return hn(c.equal(fn(0)),()=>{N.assign(kv(v))}),hn(c.equal(fn(1)),()=>{N.assign($v(v))}),hn(c.equal(fn(2)),()=>{N.assign(Jv(v,m,fn(0)))}),hn(c.equal(fn(3)),()=>{N.assign(Wv(v,x,T,_))}),N.assign(N.mul(y.sub(f)).add(f)),hn(b,()=>{N.assign(ou(N,f,y))}),N}).setLayout({name:"mx_unifiednoise3d",type:"float",inputs:[{name:"noiseType",type:"int"},{name:"position",type:"vec3"},{name:"freq",type:"vec3"},{name:"offset",type:"vec3"},{name:"jitter",type:"float"},{name:"outmin",type:"float"},{name:"outmax",type:"float"},{name:"clampoutput",type:"bool"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),rN=ln(([e])=>{const t=e.y,r=e.z,s=Nn().toVar();return hn(t.lessThan(1e-4),()=>{s.assign(Nn(r,r,r))}).Else(()=>{let i=e.x;i=i.sub(_o(i)).mul(6).toVar();const n=fn(ko(i)),a=i.sub(mn(n)),o=r.mul(t.oneMinus()),u=r.mul(t.mul(a).oneMinus()),l=r.mul(t.mul(a.oneMinus()).oneMinus());hn(n.equal(fn(0)),()=>{s.assign(Nn(r,l,o))}).ElseIf(n.equal(fn(1)),()=>{s.assign(Nn(u,r,o))}).ElseIf(n.equal(fn(2)),()=>{s.assign(Nn(o,r,l))}).ElseIf(n.equal(fn(3)),()=>{s.assign(Nn(o,u,r))}).ElseIf(n.equal(fn(4)),()=>{s.assign(Nn(l,o,r))}).Else(()=>{s.assign(Nn(r,o,u))})}),s}).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),sN=ln(([e])=>{const t=Nn(e).toVar(),r=mn(t.x).toVar(),s=mn(t.y).toVar(),i=mn(t.z).toVar(),n=mn(Ho(r,Ho(s,i))).toVar(),a=mn(qo(r,qo(s,i))).toVar(),o=mn(a.sub(n)).toVar(),u=mn().toVar(),l=mn().toVar(),d=mn().toVar();return d.assign(a),hn(a.greaterThan(0),()=>{l.assign(o.div(a))}).Else(()=>{l.assign(0)}),hn(l.lessThanEqual(0),()=>{u.assign(0)}).Else(()=>{hn(r.greaterThanEqual(a),()=>{u.assign(s.sub(i).div(o))}).ElseIf(s.greaterThanEqual(a),()=>{u.assign(Ba(2,i.sub(r).div(o)))}).Else(()=>{u.assign(Ba(4,r.sub(s).div(o)))}),u.mulAssign(1/6),hn(u.lessThan(0),()=>{u.addAssign(1)})}),Nn(u,l,d)}).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),iN=ln(([e])=>{const t=Nn(e).toVar(),r=En(Va(t,Nn(.04045))).toVar(),s=Nn(t.div(12.92)).toVar(),i=Nn(Jo(qo(t.add(Nn(.055)),Nn(0)).div(1.055),Nn(2.4))).toVar();return au(s,i,r)}).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),nN=(e,t)=>{e=mn(e),t=mn(t);const r=xn(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return du(e.sub(r),e.add(r),t)},aN=(e,t,r,s)=>au(e,t,r[s].clamp()),oN=(e,t,r,s,i)=>au(e,t,nN(r,s[i])),uN=ln(([e,t,r])=>{const s=No(e).toVar(),i=Fa(mn(.5).mul(t.sub(r)),Qd).div(s).toVar(),n=Fa(mn(-.5).mul(t.sub(r)),Qd).div(s).toVar(),a=Nn().toVar();a.x=s.x.greaterThan(mn(0)).select(i.x,n.x),a.y=s.y.greaterThan(mn(0)).select(i.y,n.y),a.z=s.z.greaterThan(mn(0)).select(i.z,n.z);const o=Ho(a.x,a.y,a.z).toVar();return Qd.add(s.mul(o)).toVar().sub(r)}),lN=ln(([e,t])=>{const r=e.x,s=e.y,i=e.z;let n=t.element(0).mul(.886227);return n=n.add(t.element(1).mul(1.023328).mul(s)),n=n.add(t.element(2).mul(1.023328).mul(i)),n=n.add(t.element(3).mul(1.023328).mul(r)),n=n.add(t.element(4).mul(.858086).mul(r).mul(s)),n=n.add(t.element(5).mul(.858086).mul(s).mul(i)),n=n.add(t.element(6).mul(i.mul(i).mul(.743125).sub(.247708))),n=n.add(t.element(7).mul(.858086).mul(r).mul(i)),n=n.add(t.element(8).mul(.429043).mul(La(r,r).sub(La(s,s)))),n});var dN=Object.freeze({__proto__:null,BRDF_GGX:em,BRDF_Lambert:Vg,BasicPointShadowFilter:nv,BasicShadowFilter:D_,Break:Ep,Const:Mu,Continue:()=>ml("continue").toStack(),DFGLUT:sm,D_GGX:Qg,Discard:fl,EPSILON:io,F_Schlick:Og,Fn:ln,HALF_PI:lo,INFINITY:no,If:hn,Loop:Rp,NodeAccess:ri,NodeShaderStage:Js,NodeType:ti,NodeUpdateType:ei,OnBeforeMaterialUpdate:e=>Tx(xx.BEFORE_MATERIAL,e),OnBeforeObjectUpdate:e=>Tx(xx.BEFORE_OBJECT,e),OnMaterialUpdate:e=>Tx(xx.MATERIAL,e),OnObjectUpdate:e=>Tx(xx.OBJECT,e),PCFShadowFilter:U_,PCFSoftShadowFilter:I_,PI:ao,PI2:oo,PointShadowFilter:av,Return:()=>ml("return").toStack(),Schlick_to_F0:am,ShaderNode:Zi,Stack:pn,Switch:(...e)=>vi.Switch(...e),TBNViewMatrix:ah,TWO_PI:uo,VSMShadowFilter:O_,V_GGX_SmithCorrelated:Kg,Var:Cu,VarIntent:Bu,abs:Bo,acesFilmicToneMapping:aT,acos:Co,add:Ba,addMethodChaining:Si,addNodeElement:function(e){d("TSL: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)},agxToneMapping:dT,all:co,alphaT:Qn,and:$a,anisotropy:Zn,anisotropyB:ea,anisotropyT:Jn,any:ho,append:e=>(d("TSL: append() has been renamed to Stack().",new Ds),pn(e)),array:Sa,arrayBuffer:e=>new Ti(e,"ArrayBuffer"),asin:wo,assign:Ea,atan:Mo,atomicAdd:(e,t)=>OT(UT.ATOMIC_ADD,e,t),atomicAnd:(e,t)=>OT(UT.ATOMIC_AND,e,t),atomicFunc:OT,atomicLoad:e=>OT(UT.ATOMIC_LOAD,e,null),atomicMax:(e,t)=>OT(UT.ATOMIC_MAX,e,t),atomicMin:(e,t)=>OT(UT.ATOMIC_MIN,e,t),atomicOr:(e,t)=>OT(UT.ATOMIC_OR,e,t),atomicStore:(e,t)=>OT(UT.ATOMIC_STORE,e,t),atomicSub:(e,t)=>OT(UT.ATOMIC_SUB,e,t),atomicXor:(e,t)=>OT(UT.ATOMIC_XOR,e,t),attenuationColor:pa,attenuationDistance:ha,attribute:Rl,attributeArray:(e,t="float")=>{let r,s;!0===t.isStruct?(r=t.layout.getLength(),s=zs("float")):(r=Ws(t),s=zs(t));const i=new vx(e,r,s);return op(i,t,e)},backgroundBlurriness:Ax,backgroundIntensity:wx,backgroundRotation:Cx,batch:Tp,bentNormalView:uh,billboarding:kb,bitAnd:qa,bitNot:ja,bitOr:Xa,bitXor:Ka,bitangentGeometry:rh,bitangentLocal:sh,bitangentView:ih,bitangentWorld:nh,bitcast:hb,blendBurn:lg,blendColor:pg,blendDodge:dg,blendOverlay:hg,blendScreen:cg,blur:of,bool:bn,buffer:Ol,bufferAttribute:el,builtin:zl,builtinAOContext:Ru,builtinShadowContext:Su,bumpMap:fh,bvec2:vn,bvec3:En,bvec4:Mn,bypass:dl,cache:ul,call:wa,cameraFar:bd,cameraIndex:fd,cameraNear:yd,cameraNormalMatrix:Nd,cameraPosition:Sd,cameraProjectionMatrix:xd,cameraProjectionMatrixInverse:Td,cameraViewMatrix:_d,cameraViewport:Rd,cameraWorldMatrix:vd,cbrt:iu,cdl:qx,ceil:vo,checker:gv,cineonToneMapping:iT,clamp:ou,clearcoat:Wn,clearcoatNormalView:hc,clearcoatRoughness:Hn,clipSpace:jd,code:pT,color:gn,colorSpaceToWorking:$u,colorToDirection:e=>Ji(e).mul(2).sub(1),compute:nl,computeKernel:il,computeSkinning:(e,t=null)=>{const r=new vp(e);return r.positionNode=op(new j(e.geometry.getAttribute("position").array,3),"vec3").setPBO(!0).toReadOnly().element(dp).toVar(),r.skinIndexNode=op(new j(new Uint32Array(e.geometry.getAttribute("skinIndex").array),4),"uvec4").setPBO(!0).toReadOnly().element(dp).toVar(),r.skinWeightNode=op(new j(e.geometry.getAttribute("skinWeight").array,4),"vec4").setPBO(!0).toReadOnly().element(dp).toVar(),r.bindMatrixNode=va(e.bindMatrix,"mat4"),r.bindMatrixInverseNode=va(e.bindMatrixInverse,"mat4"),r.boneMatricesNode=Ol(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length),r.toPositionNode=t,Ji(r)},context:_u,convert:Dn,convertColorSpace:(e,t,r)=>new ku(Ji(e),t,r),convertToTexture:(e,...t)=>e.isSampleNode||e.isTextureNode?e:e.isPassNode?e.getTextureNode():hx(e,...t),cos:Eo,countLeadingZeros:yb,countOneBits:bb,countTrailingZeros:fb,cross:Zo,cubeTexture:Mc,cubeTextureBase:Cc,dFdx:Uo,dFdy:Io,dashSize:aa,debug:Tl,decrement:to,decrementBefore:Ja,defaultBuildStages:ii,defaultShaderStages:si,defined:Yi,degrees:go,deltaTime:Ub,densityFogFactor:bT,depth:eg,depthPass:(e,t,r)=>new eT(eT.DEPTH,e,t,r),determinant:zo,difference:Yo,diffuseColor:Vn,diffuseContribution:kn,directPointLight:hv,directionToColor:lh,directionToFaceDirection:ic,dispersion:ga,disposeShadowMaterial:k_,distance:Ko,div:Pa,dot:Qo,drawIndex:gp,dynamicBufferAttribute:(e,t=null,r=0,s=0)=>Ju(e,t,r,s,x),element:Pn,emissive:Gn,equal:Ua,equirectUV:Rg,exp:mo,exp2:fo,exponentialHeightFogFactor:xT,expression:ml,faceDirection:sc,faceForward:cu,faceforward:fu,float:mn,floatBitsToInt:e=>new cb(e,"int","float"),floatBitsToUint:pb,floor:_o,fog:TT,fract:So,frameGroup:ba,frameId:Ib,frontFacing:rc,fwidth:Go,gain:(e,t)=>e.lessThan(.5)?Tb(e.mul(2),t).div(2):Fa(1,Tb(La(Fa(1,e),2),t).div(2)),gapSize:oa,getConstNodeType:Qi,getCurrentStack:cn,getDirection:rf,getDistanceAttenuation:cv,getGeometryRoughness:jg,getNormalFromDepth:mx,getParallaxCorrectNormal:uN,getRoughness:Xg,getScreenPosition:gx,getShIrradianceAt:lN,getShadowMaterial:V_,getShadowRenderObjectFunction:z_,getTextureIndex:ub,getViewPosition:px,ggxConvolution:cf,globalId:CT,glsl:(e,t)=>pT(e,t,"glsl"),glslFn:(e,t)=>mT(e,t,"glsl"),grayscale:Gx,greaterThan:Va,greaterThanEqual:Ga,hash:xb,highpModelNormalViewMatrix:qd,highpModelViewMatrix:Hd,hue:Wx,increment:eo,incrementBefore:Za,inspector:Nl,instance:fp,instanceIndex:dp,instancedArray:(e,t="float")=>{let r,s;!0===t.isStruct?(r=t.layout.getLength(),s=zs("float")):(r=Ws(t),s=zs(t));const i=new _x(e,r,s);return op(i,t,i.count)},instancedBufferAttribute:tl,instancedDynamicBufferAttribute:rl,instancedMesh:bp,int:fn,intBitsToFloat:e=>new cb(e,"float","int"),interleavedGradientNoise:fx,inverse:Wo,inverseSqrt:To,inversesqrt:yu,invocationLocalIndex:pp,invocationSubgroupIndex:hp,ior:la,iridescence:Xn,iridescenceIOR:Kn,iridescenceThickness:Yn,isolate:ol,ivec2:Tn,ivec3:Sn,ivec4:wn,js:(e,t)=>pT(e,t,"js"),label:Eu,length:Lo,lengthSq:nu,lessThan:Oa,lessThanEqual:ka,lightPosition:m_,lightProjectionUV:g_,lightShadowMatrix:p_,lightTargetDirection:b_,lightTargetPosition:f_,lightViewPosition:y_,lightingContext:Dp,lights:(e=[])=>(new v_).setLights(e),linearDepth:tg,linearToneMapping:rT,localId:MT,log:yo,log2:bo,logarithmicDepthToViewZ:(e,t,r)=>{const s=e.mul(yo(r.div(t)));return mn(Math.E).pow(s).mul(t).negate()},luminance:Hx,mat2:Bn,mat3:Fn,mat4:Ln,matcapUV:Kf,materialAO:tp,materialAlphaTest:xh,materialAnisotropy:Oh,materialAnisotropyVector:rp,materialAttenuationColor:qh,materialAttenuationDistance:Hh,materialClearcoat:Fh,materialClearcoatNormal:Ph,materialClearcoatRoughness:Lh,materialColor:Th,materialDispersion:Jh,materialEmissive:vh,materialEnvIntensity:_c,materialEnvRotation:vc,materialIOR:Wh,materialIridescence:Vh,materialIridescenceIOR:kh,materialIridescenceThickness:Gh,materialLightMap:ep,materialLineDashOffset:Qh,materialLineDashSize:Xh,materialLineGapSize:Kh,materialLineScale:jh,materialLineWidth:Yh,materialMetalness:Mh,materialNormal:Bh,materialOpacity:Nh,materialPointSize:Zh,materialReference:Uc,materialReflectivity:wh,materialRefractionRatio:Tc,materialRotation:Dh,materialRoughness:Ch,materialSheen:Uh,materialSheenRoughness:Ih,materialShininess:_h,materialSpecular:Sh,materialSpecularColor:Eh,materialSpecularIntensity:Rh,materialSpecularStrength:Ah,materialThickness:zh,materialTransmission:$h,max:qo,maxMipLevel:Ml,mediumpModelViewMatrix:Wd,metalness:zn,min:Ho,mix:au,mixElement:pu,mod:Da,modInt:ro,modelDirection:Dd,modelNormalMatrix:Gd,modelPosition:Id,modelRadius:kd,modelScale:Od,modelViewMatrix:zd,modelViewPosition:Vd,modelViewProjection:sp,modelWorldMatrix:Ud,modelWorldMatrixInverse:$d,morphReference:Bp,mrt:db,mul:La,mx_aastep:nN,mx_add:(e,t=mn(0))=>Ba(e,t),mx_atan2:(e=mn(0),t=mn(1))=>Mo(e,t),mx_cell_noise_float:(e=El())=>Gv(e.convert("vec2|vec3")),mx_contrast:(e,t=1,r=.5)=>mn(e).sub(r).mul(t).add(r),mx_divide:(e,t=mn(1))=>Pa(e,t),mx_fractal_noise_float:(e=El(),t=3,r=2,s=.5,i=1)=>zv(e,fn(t),r,s).mul(i),mx_fractal_noise_vec2:(e=El(),t=3,r=2,s=.5,i=1)=>Hv(e,fn(t),r,s).mul(i),mx_fractal_noise_vec3:(e=El(),t=3,r=2,s=.5,i=1)=>Wv(e,fn(t),r,s).mul(i),mx_fractal_noise_vec4:(e=El(),t=3,r=2,s=.5,i=1)=>qv(e,fn(t),r,s).mul(i),mx_frame:()=>Ib,mx_heighttonormal:(e,t)=>(e=Nn(e),t=mn(t),fh(e,t)),mx_hsvtorgb:rN,mx_ifequal:(e,t,r,s)=>e.equal(t).mix(r,s),mx_ifgreater:(e,t,r,s)=>e.greaterThan(t).mix(r,s),mx_ifgreatereq:(e,t,r,s)=>e.greaterThanEqual(t).mix(r,s),mx_invert:(e,t=mn(1))=>Fa(t,e),mx_modulo:(e,t=mn(1))=>Da(e,t),mx_multiply:(e,t=mn(1))=>La(e,t),mx_noise_float:(e=El(),t=1,r=0)=>Vv(e.convert("vec2|vec3")).mul(t).add(r),mx_noise_vec3:(e=El(),t=1,r=0)=>kv(e.convert("vec2|vec3")).mul(t).add(r),mx_noise_vec4:(e=El(),t=1,r=0)=>{e=e.convert("vec2|vec3");return An(kv(e),Vv(e.add(xn(19,73)))).mul(t).add(r)},mx_place2d:(e,t=xn(.5,.5),r=xn(1,1),s=mn(0),i=xn(0,0))=>{let n=e;if(t&&(n=n.sub(t)),r&&(n=n.mul(r)),s){const e=s.mul(Math.PI/180),t=e.cos(),r=e.sin();n=xn(n.x.mul(t).sub(n.y.mul(r)),n.x.mul(r).add(n.y.mul(t)))}return t&&(n=n.add(t)),i&&(n=n.add(i)),n},mx_power:(e,t=mn(1))=>Jo(e,t),mx_ramp4:(e,t,r,s,i=El())=>{const n=i.x.clamp(),a=i.y.clamp(),o=au(e,t,n),u=au(r,s,n);return au(o,u,a)},mx_ramplr:(e,t,r=El())=>aN(e,t,r,"x"),mx_ramptb:(e,t,r=El())=>aN(e,t,r,"y"),mx_rgbtohsv:sN,mx_rotate2d:(e,t)=>{e=xn(e);const r=(t=mn(t)).mul(Math.PI/180);return Jf(e,r)},mx_rotate3d:(e,t,r)=>{e=Nn(e),t=mn(t),r=Nn(r);const s=t.mul(Math.PI/180),i=r.normalize(),n=s.cos(),a=s.sin(),o=mn(1).sub(n);return e.mul(n).add(i.cross(e).mul(a)).add(i.mul(i.dot(e)).mul(o))},mx_safepower:(e,t=1)=>(e=mn(e)).abs().pow(t).mul(e.sign()),mx_separate:(e,t=null)=>{if("string"==typeof t){const r={x:0,r:0,y:1,g:1,z:2,b:2,w:3,a:3},s=t.replace(/^out/,"").toLowerCase();if(void 0!==r[s])return e.element(r[s])}if("number"==typeof t)return e.element(t);if("string"==typeof t&&1===t.length){const r={x:0,r:0,y:1,g:1,z:2,b:2,w:3,a:3};if(void 0!==r[t])return e.element(r[t])}return e},mx_splitlr:(e,t,r,s=El())=>oN(e,t,r,s,"x"),mx_splittb:(e,t,r,s=El())=>oN(e,t,r,s,"y"),mx_srgb_texture_to_lin_rec709:iN,mx_subtract:(e,t=mn(0))=>Fa(e,t),mx_timer:()=>Db,mx_transform_uv:(e=1,t=0,r=El())=>r.mul(e).add(t),mx_unifiednoise2d:(e,t=El(),r=xn(1,1),s=xn(0,0),i=1,n=0,a=1,o=!1,u=1,l=2,d=.5)=>eN(e,t.convert("vec2|vec3"),r,s,i,n,a,o,u,l,d),mx_unifiednoise3d:(e,t=El(),r=xn(1,1),s=xn(0,0),i=1,n=0,a=1,o=!1,u=1,l=2,d=.5)=>tN(e,t.convert("vec2|vec3"),r,s,i,n,a,o,u,l,d),mx_worley_noise_float:(e=El(),t=1)=>Qv(e.convert("vec2|vec3"),t,fn(1)),mx_worley_noise_vec2:(e=El(),t=1)=>Zv(e.convert("vec2|vec3"),t,fn(1)),mx_worley_noise_vec3:(e=El(),t=1)=>Jv(e.convert("vec2|vec3"),t,fn(1)),negate:Po,neutralToneMapping:cT,nodeArray:rn,nodeImmutable:nn,nodeObject:Ji,nodeObjectIntent:en,nodeObjects:tn,nodeProxy:sn,nodeProxyIntent:an,normalFlat:oc,normalGeometry:nc,normalLocal:ac,normalMap:hh,normalView:dc,normalViewGeometry:uc,normalWorld:cc,normalWorldGeometry:lc,normalize:No,not:Wa,notEqual:Ia,numWorkgroups:AT,objectDirection:wd,objectGroup:Ta,objectPosition:Md,objectRadius:Ld,objectScale:Bd,objectViewPosition:Fd,objectWorldMatrix:Cd,oneMinus:Do,or:za,orthographicDepthToViewZ:Xp,oscSawtooth:(e=Db)=>e.fract(),oscSine:(e=Db)=>e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),oscSquare:(e=Db)=>e.fract().round(),oscTriangle:(e=Db)=>e.add(.5).fract().mul(2).sub(1).abs(),output:na,outputStruct:ib,overloadingFn:Pb,packHalf2x16:Sb,packSnorm2x16:vb,packUnorm2x16:Nb,parabola:Tb,parallaxDirection:oh,parallaxUV:(e,t)=>e.sub(oh.mul(t)),parameter:(e,t)=>new Zy(e,t),pass:(e,t,r)=>new eT(eT.COLOR,e,t,r),passTexture:(e,t)=>new Zx(e,t),pcurve:(e,t,r)=>Jo(Pa(Jo(e,t),Ba(Jo(e,t),Jo(Fa(1,e),r))),1/t),perspectiveDepthToViewZ:Qp,pmremTexture:Pf,pointShadow:lv,pointUV:Sx,pointWidth:ua,positionGeometry:Xd,positionLocal:Kd,positionPrevious:Yd,positionView:Jd,positionViewDirection:ec,positionWorld:Qd,positionWorldDirection:Zd,posterize:jx,pow:Jo,pow2:eu,pow3:tu,pow4:ru,premultiplyAlpha:gg,property:In,quadBroadcast:d_,quadSwapDiagonal:i_,quadSwapX:r_,quadSwapY:s_,radians:po,rand:hu,range:ST,rangeFogFactor:yT,reciprocal:Vo,reference:Lc,referenceBuffer:Pc,reflect:Xo,reflectVector:Rc,reflectView:Nc,reflector:e=>new ix(e),refract:lu,refractVector:Ec,refractView:Sc,reinhardToneMapping:sT,remap:hl,remapClamp:pl,renderGroup:xa,renderOutput:bl,rendererReference:qu,replaceDefaultUV:function(e,t=null){return _u(t,{getUV:"function"==typeof e?e:()=>e})},rotate:Jf,rotateUV:Ob,roughness:$n,round:Oo,rtt:hx,sRGBTransferEOTF:Iu,sRGBTransferOETF:Ou,sample:(e,t=null)=>new bx(e,Ji(t)),sampler:e=>(!0===e.isNode?e:Dl(e)).convert("sampler"),samplerComparison:e=>(!0===e.isNode?e:Dl(e)).convert("samplerComparison"),saturate:uu,saturation:$x,screenCoordinate:Yl,screenDPR:jl,screenSize:Kl,screenUV:Xl,select:xu,setCurrentStack:dn,setName:Nu,shaderStages:ni,shadow:Y_,shadowPositionWorld:S_,shapeCircle:mv,sharedUniformGroup:ya,sheen:qn,sheenRoughness:jn,shiftLeft:Ya,shiftRight:Qa,shininess:ia,sign:Fo,sin:Ro,sinc:(e,t)=>Ro(ao.mul(t.mul(e).sub(1))).div(ao.mul(t.mul(e).sub(1))),skinning:Np,smoothstep:du,smoothstepElement:gu,specularColor:ta,specularColorBlended:ra,specularF90:sa,spherizeUV:Vb,split:(e,t)=>new mi(Ji(e),t),spritesheetUV:$b,sqrt:xo,stack:eb,step:jo,stepElement:mu,storage:op,storageBarrier:()=>LT("storage").toStack(),storageTexture:Bx,string:(e="")=>new Ti(e,"string"),struct:(e,t=null)=>{const r=new tb(e,t),s=(...t)=>{let s=null;if(t.length>0)if(t[0].isNode){s={};const r=Object.keys(e);for(let e=0;e<t.length;e++)s[r[e]]=t[e]}else s=t[0];return new rb(r,s)};return s.layout=r,s.isStruct=!0,s},sub:Fa,subBuild:Lu,subgroupAdd:$T,subgroupAll:JT,subgroupAnd:XT,subgroupAny:e_,subgroupBallot:GT,subgroupBroadcast:n_,subgroupBroadcastFirst:t_,subgroupElect:kT,subgroupExclusiveAdd:WT,subgroupExclusiveMul:jT,subgroupInclusiveAdd:zT,subgroupInclusiveMul:qT,subgroupIndex:cp,subgroupMax:ZT,subgroupMin:QT,subgroupMul:HT,subgroupOr:KT,subgroupShuffle:a_,subgroupShuffleDown:l_,subgroupShuffleUp:u_,subgroupShuffleXor:o_,subgroupSize:BT,subgroupXor:YT,tan:Ao,tangentGeometry:Qc,tangentLocal:Zc,tangentView:Jc,tangentWorld:eh,texture:Dl,texture3D:Px,texture3DLevel:(e,t,r)=>Px(e,t).level(r),texture3DLoad:(...e)=>Px(...e).setSampler(!1),textureBarrier:()=>LT("texture").toStack(),textureBicubic:Em,textureBicubicLevel:Rm,textureCubeUV:sf,textureLevel:(e,t,r)=>Dl(e,t).level(r),textureLoad:Ul,textureSize:wl,textureStore:(e,t,r)=>{let s;return!0===e.isStorageTextureNode?(s=e.clone(),s.uvNode=t,s.storeNode=r):s=Bx(e,t,r),null!==r&&s.toStack(),s},thickness:ca,time:Db,toneMapping:Xu,toneMappingExposure:Ku,toonOutlinePass:(t,r,s=new e(0,0,0),i=.003,n=1)=>new tT(t,r,Ji(s),Ji(i),Ji(n)),transformDirection:su,transformNormal:pc,transformNormalToView:gc,transformedClearcoatNormalView:yc,transformedNormalView:mc,transformedNormalWorld:fc,transmission:da,transpose:$o,triNoise3D:Bb,triplanarTexture:(...e)=>zb(...e),triplanarTextures:zb,trunc:ko,uint:yn,uintBitsToFloat:e=>new cb(e,"float","uint"),uniform:va,uniformArray:Gl,uniformCubeTexture:(e=Ac)=>Cc(e),uniformFlow:vu,uniformGroup:fa,uniformTexture:(e=Fl)=>Dl(e),unpackHalf2x16:wb,unpackNormal:dh,unpackSnorm2x16:Eb,unpackUnorm2x16:Ab,unpremultiplyAlpha:mg,userData:(e,t,r)=>new Dx(e,t,r),uv:El,uvec2:_n,uvec3:Rn,uvec4:Cn,varying:Du,varyingProperty:On,vec2:xn,vec3:Nn,vec4:An,vectorComponents:ai,velocity:kx,vertexColor:ug,vertexIndex:lp,vertexStage:Uu,vibrance:zx,viewZToLogarithmicDepth:Zp,viewZToOrthographicDepth:jp,viewZToPerspectiveDepth:Kp,viewZToReversedOrthographicDepth:(e,t,r)=>e.add(r).div(r.sub(t)),viewZToReversedPerspectiveDepth:Yp,viewport:Ql,viewportCoordinate:Jl,viewportDepthTexture:Hp,viewportLinearDepth:rg,viewportMipTexture:kp,viewportOpaqueMipTexture:$p,viewportResolution:td,viewportSafeUV:Gb,viewportSharedTexture:Yx,viewportSize:Zl,viewportTexture:Vp,viewportUV:ed,vogelDiskSample:yx,wgsl:(e,t)=>pT(e,t,"wgsl"),wgslFn:(e,t)=>mT(e,t,"wgsl"),workgroupArray:(e,t)=>new DT("Workgroup",e,t),workgroupBarrier:()=>LT("workgroup").toStack(),workgroupId:wT,workingToColorSpace:Gu,xor:Ha});const cN=new Qy;class hN extends Ty{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,r){const s=this.renderer,i=this.nodes.getBackgroundNode(e)||e.background;let n=!1;if(null===i)s._clearColor.getRGB(cN),cN.a=s._clearColor.a;else if(!0===i.isColor)i.getRGB(cN),cN.a=1,n=!0;else if(!0===i.isNode){const u=this.get(e),l=i;cN.copy(s._clearColor);let d=u.backgroundMesh;if(void 0===d){const h=An(l).mul(wx).context({getUV:()=>Cx.mul(lc),getTextureLevel:()=>Ax}),p=xd.element(3).element(3).equal(1),g=Pa(1,xd.element(1).element(1)).mul(3),m=p.select(Kd.mul(g),Kd),f=zd.mul(An(m,0));let y=xd.mul(An(f.xyz,1));y=y.setZ(y.w);const b=new fg;function x(){i.removeEventListener("dispose",x),d.material.dispose(),d.geometry.dispose()}b.name="Background.material",b.side=L,b.depthTest=!1,b.depthWrite=!1,b.allowOverride=!1,b.fog=!1,b.lights=!1,b.vertexNode=y,b.colorNode=h,u.backgroundMeshNode=h,u.backgroundMesh=d=new ue(new it(1,32,32),b),d.frustumCulled=!1,d.name="Background.mesh",i.addEventListener("dispose",x)}const c=l.getCacheKey();u.backgroundCacheKey!==c&&(u.backgroundMeshNode.node=An(l).mul(wx),u.backgroundMeshNode.needsUpdate=!0,d.material.needsUpdate=!0,u.backgroundCacheKey=c),t.unshift(d,d.geometry,d.material,0,0,null,null)}else o("Renderer: Unsupported background configuration.",i);const a=s.xr.getEnvironmentBlendMode();if("additive"===a?cN.set(0,0,0,1):"alpha-blend"===a&&cN.set(0,0,0,0),!0===s.autoClear||!0===n){const T=r.clearColorValue;T.r=cN.r,T.g=cN.g,T.b=cN.b,T.a=cN.a,!0!==s.backend.isWebGLBackend&&!0!==s.alpha||(T.r*=T.a,T.g*=T.a,T.b*=T.a),r.depthClearValue=s.getClearDepth(),r.stencilClearValue=s.getClearStencil(),r.clearColor=!0===s.autoClearColor,r.clearDepth=!0===s.autoClearDepth,r.clearStencil=!0===s.autoClearStencil}else r.clearColor=!1,r.clearDepth=!1,r.clearStencil=!1}}let pN=0;class gN{constructor(e="",t=[],r=0){this.name=e,this.bindings=t,this.index=r,this.id=pN++}}class mN{constructor(e,t,r,s,i,n,a,o,u,l=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=r,this.transforms=l,this.nodeAttributes=s,this.bindings=i,this.updateNodes=n,this.updateBeforeNodes=a,this.updateAfterNodes=o,this.observer=u,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings){if(!0!==t.bindings[0].groupNode.shared){const r=new gN(t.name,[],t.index);e.push(r);for(const e of t.bindings)r.bindings.push(e.clone())}else e.push(t)}return e}}class fN{constructor(e,t,r=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=r}}class yN{constructor(e,t,r){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=r}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class bN{constructor(e,t,r=!1,s=null){this.isNodeVar=!0,this.name=e,this.type=t,this.readOnly=r,this.count=s}}class xN extends bN{constructor(e,t,r=null,s=null){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0,this.interpolationType=r,this.interpolationSampling=s}}class TN{constructor(e,t,r=""){this.name=e,this.type=t,this.code=r,Object.defineProperty(this,"isNodeCode",{value:!0})}}let _N=0;class vN{constructor(e=null){this.id=_N++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class NN{constructor(e,t){this.name=e,this.members=t,this.output=!1}}class SN{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0,this.index=-1}setValue(e){this.value=e}getValue(){return this.value}}class RN extends SN{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class EN extends SN{constructor(e,r=new t){super(e,r),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class AN extends SN{constructor(e,t=new r){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class wN extends SN{constructor(e,t=new s){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class CN extends SN{constructor(t,r=new e){super(t,r),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class MN extends SN{constructor(e,t=new i){super(e,t),this.isMatrix2Uniform=!0,this.boundary=8,this.itemSize=4}}class BN extends SN{constructor(e,t=new n){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class FN extends SN{constructor(e,t=new a){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class LN extends RN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class PN extends EN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class DN extends AN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class UN extends wN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class IN extends CN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class ON extends MN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class VN extends BN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class kN extends FN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}let GN=0;const $N=new WeakMap,zN=new WeakMap,WN=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),HN=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0");class qN{constructor(e,t,r){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=r,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.observer=null,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.types={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.declarations={},this.flow={code:""},this.chaining=[],this.stack=eb(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new vN,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.subBuildLayers=[],this.activeStacks=[],this.subBuildFn=null,this.fnCall=null,Object.defineProperty(this,"id",{value:GN++})}isFlatShading(){return!0===this.material.flatShading||!1===this.geometry.hasAttribute("normal")}isOpaque(){const e=this.material;return!1===e.transparent&&e.blending===ze&&!1===e.alphaToCoverage}createRenderTarget(e,t,r){return new ae(e,t,r)}createCubeRenderTarget(e,t){return new Eg(e,t)}includes(e){return this.nodes.includes(e)}getOutputStructName(){}_getBindGroup(e,t){const r=t[0].groupNode;let s,i=r.shared;if(i)for(let e=1;e<t.length;e++)r!==t[e].groupNode&&(i=!1);if(i){let r="";for(const e of t)if(e.isNodeUniformsGroup){e.uniforms.sort((e,t)=>e.nodeUniform.node.id-t.nodeUniform.node.id);for(const t of e.uniforms)r+=t.nodeUniform.node.id}else r+=e.nodeUniform.id;const i=this.renderer._currentRenderContext||this.renderer;let n=$N.get(i);void 0===n&&(n=new Map,$N.set(i,n));const a=Is(r);s=n.get(a),void 0===s&&(s=new gN(e,t,this.bindingsIndexes[e].group),n.set(a,s))}else s=new gN(e,t,this.bindingsIndexes[e].group);return s}getBindGroupArray(e,t){const r=this.bindings[t];let s=r[e];return void 0===s&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),r[e]=s=[]),s}getBindings(){let e=this.bindGroups;if(null===e){const t={},r=this.bindings;for(const e of ni)for(const s in r[e]){const i=r[e][s],n=t[s]||(t[s]=[]);for(const e of i)!1===n.includes(e)&&n.push(e)}e=[];for(const r in t){const s=t[r],i=this._getBindGroup(r,s);e.push(i)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort((e,t)=>e.bindings[0].groupNode.order-t.bindings[0].groupNode.order);for(let t=0;t<e.length;t++){const r=e[t];this.bindingsIndexes[r.name].group=t,r.index=t}}setHashNode(e,t){this.hashNodes[t]=e}addNode(e){!1===this.nodes.includes(e)&&(this.nodes.push(e),this.setHashNode(e,e.getHash(this)))}addSequentialNode(e){const t=e.getUpdateBeforeType(),r=e.getUpdateAfterType();t===ei.NONE&&r===ei.NONE||!1===this.sequentialNodes.includes(e)&&this.sequentialNodes.push(e)}buildUpdateNodes(){for(const e of this.nodes){e.getUpdateType()!==ei.NONE&&this.updateNodes.push(e)}for(const e of this.sequentialNodes){const t=e.getUpdateBeforeType(),r=e.getUpdateAfterType();t!==ei.NONE&&this.updateBeforeNodes.push(e),r!==ei.NONE&&this.updateAfterNodes.push(e)}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(e){return e.magFilter===de||e.magFilter===nt||e.magFilter===at||e.magFilter===Z||e.minFilter===de||e.minFilter===nt||e.minFilter===at||e.minFilter===Z}getUniformBufferLimit(){return 16384}addChain(e){this.chaining.push(e)}removeChain(e){if(this.chaining.pop()!==e)throw new Error("NodeBuilder: Invalid node chaining!")}getMethod(e){return e}getTernary(){return null}getNodeFromHash(e){return this.hashNodes[e]}addFlow(e,t){return this.flowNodes[e].push(t),t}setContext(e){this.context=e}getContext(){return this.context}addContext(e){const t=this.getContext();return this.setContext({...this.context,...e}),t}getSharedContext(){const e={...this.context};return delete e.material,delete e.getUV,delete e.getOutput,delete e.getTextureLevel,delete e.getAO,delete e.getShadow,e}setCache(e){this.cache=e}getCache(){return this.cache}getCacheFromNode(e,t=!0){const r=this.getDataFromNode(e);return void 0===r.cache&&(r.cache=new vN(t?this.getCache():null)),r.cache}isAvailable(){return!1}getVertexIndex(){d("Abstract function.")}getInstanceIndex(){d("Abstract function.")}getDrawIndex(){d("Abstract function.")}getFrontFacing(){d("Abstract function.")}getFragCoord(){d("Abstract function.")}isFlipY(){return!1}increaseUsage(e){const t=this.getDataFromNode(e);return t.usageCount=void 0===t.usageCount?1:t.usageCount+1,t.usageCount}generateTexture(){d("Abstract function.")}generateTextureLod(){d("Abstract function.")}generateArrayDeclaration(e,t){return this.getType(e)+"[ "+t+" ]"}generateArray(e,t,r=null){let s=this.generateArrayDeclaration(e,t)+"( ";for(let i=0;i<t;i++){const n=r?r[i]:null;s+=null!==n?n.build(this,e):this.generateConst(e),i<t-1&&(s+=", ")}return s+=" )",s}generateStruct(e,t,r=null){const s=[];for(const e of t){const{name:t,type:i}=e;r&&r[t]&&r[t].isNode?s.push(r[t].build(this,i)):s.push(this.generateConst(i))}return e+"( "+s.join(", ")+" )"}generateConst(i,n=null){if(null===n&&("float"===i||"int"===i||"uint"===i?n=0:"bool"===i?n=!1:"color"===i?n=new e:"vec2"===i||"uvec2"===i||"ivec2"===i?n=new t:"vec3"===i||"uvec3"===i||"ivec3"===i?n=new r:"vec4"!==i&&"uvec4"!==i&&"ivec4"!==i||(n=new s)),"float"===i)return HN(n);if("int"===i)return`${Math.round(n)}`;if("uint"===i)return n>=0?`${Math.round(n)}u`:"0u";if("bool"===i)return n?"true":"false";if("color"===i)return`${this.getType("vec3")}( ${HN(n.r)}, ${HN(n.g)}, ${HN(n.b)} )`;const a=this.getTypeLength(i),o=this.getComponentType(i),u=e=>this.generateConst(o,e);if(2===a)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)} )`;if(3===a)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)}, ${u(n.z)} )`;if(4===a&&"mat2"!==i)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)}, ${u(n.z)}, ${u(n.w)} )`;if(a>=4&&n&&(n.isMatrix2||n.isMatrix3||n.isMatrix4))return`${this.getType(i)}( ${n.elements.map(u).join(", ")} )`;if(a>4)return`${this.getType(i)}()`;throw new Error(`NodeBuilder: Type '${i}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){const r=this.attributes;for(const t of r)if(t.name===e)return t;const s=new fN(e,t);return this.registerDeclaration(s),r.push(s),s}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"samplerComparison"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===R)return"int";if(t===S)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;let r=$s(e);const s="float"===t?"":t[0];return!0===/mat2/.test(t)&&(r=r.replace("vec","mat")),s+r}getTypeFromArray(e){return WN.get(e.constructor)}isInteger(e){return/int|uint|(i|u)vec/.test(e)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const r=t.array,s=e.itemSize,i=e.normalized;let n;return e instanceof ot||!0===i||(n=this.getTypeFromArray(r)),this.getTypeFromLength(s,n)}getTypeLength(e){const t=this.getVectorType(e),r=/vec([2-4])/.exec(t);return null!==r?Number(r[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:!0===/mat4/.test(e)?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}setActiveStack(e){this.activeStacks.push(e)}removeActiveStack(e){if(this.activeStacks[this.activeStacks.length-1]!==e)throw new Error("NodeBuilder: Invalid active stack removal.");this.activeStacks.pop()}getActiveStack(){return this.activeStacks[this.activeStacks.length-1]}getBaseStack(){return this.activeStacks[0]}addStack(){this.stack=eb(this.stack);const e=cn();return this.stacks.push(e),dn(this.stack),this.stack}removeStack(){const e=this.stack;for(const t of e.nodes){this.getDataFromNode(t).stack=e}return this.stack=e.parent,dn(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,r=null){let s=(r=null===r?e.isGlobal(this)?this.globalCache:this.cache:r).getData(e);void 0===s&&(s={},r.setData(e,s)),void 0===s[t]&&(s[t]={});let i=s[t];const n=s.any?s.any.subBuilds:null,a=this.getClosestSubBuild(n);return a&&(void 0===i.subBuildsCache&&(i.subBuildsCache={}),i=i.subBuildsCache[a]||(i.subBuildsCache[a]={}),i.subBuilds=n),i}getNodeProperties(e,t="any"){const r=this.getDataFromNode(e,t);return r.properties||(r.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const r=this.getDataFromNode(e,"vertex");let s=r.bufferAttribute;if(void 0===s){const i=this.uniforms.index++;s=new fN("nodeAttribute"+i,t,e),this.bufferAttributes.push(s),r.bufferAttribute=s}return s}getStructTypeNode(e,t=this.shaderStage){return this.types[t][e]||null}getStructTypeFromNode(e,t,r=null,s=this.shaderStage){const i=this.getDataFromNode(e,s,this.globalCache);let n=i.structType;if(void 0===n){const a=this.structs.index++;null===r&&(r="StructType"+a),n=new NN(r,t),this.structs[s].push(n),this.types[s][r]=e,i.structType=n}return n}getOutputStructTypeFromNode(e,t){const r=this.getStructTypeFromNode(e,t,"OutputType","fragment");return r.output=!0,r}getUniformFromNode(e,t,r=this.shaderStage,s=null){"in"===s&&(console.warn('NodeBuilder: "in" is a reserved word, using "inValue" instead.',e,s),e.name="inValue",s=e.name);const i=this.getDataFromNode(e,r,this.globalCache);let n=i.uniform;if(void 0===n){const a=this.uniforms.index++;n=new yN(s||"nodeUniform"+a,t,e),this.uniforms[r].push(n),this.registerDeclaration(n),i.uniform=n}return n}getVarFromNode(e,t=null,r=e.getNodeType(this),s=this.shaderStage,i=!1){const n=this.getDataFromNode(e,s),a=this.getSubBuildProperty("variable",n.subBuilds);let o=n[a];if(void 0===o){const u=i?"_const":"_var",l=this.vars[s]||(this.vars[s]=[]),d=this.vars[u]||(this.vars[u]=0);null===t&&(t=(i?"nodeConst":"nodeVar")+d,this.vars[u]++),"variable"!==a&&(t=this.getSubBuildProperty(t,n.subBuilds));const c=e.getArrayCount(this);o=new bN(t,r,i,c),i||l.push(o),this.registerDeclaration(o),n[a]=o}return o}isDeterministic(e){if(e.isMathNode)return this.isDeterministic(e.aNode)&&(!e.bNode||this.isDeterministic(e.bNode))&&(!e.cNode||this.isDeterministic(e.cNode));if(e.isOperatorNode)return this.isDeterministic(e.aNode)&&(!e.bNode||this.isDeterministic(e.bNode));if(e.isArrayNode){if(null!==e.values)for(const t of e.values)if(!this.isDeterministic(t))return!1;return!0}return!!e.isConstNode}getVaryingFromNode(e,t=null,r=e.getNodeType(this),s=null,i=null){const n=this.getDataFromNode(e,"any"),a=this.getSubBuildProperty("varying",n.subBuilds);let o=n[a];if(void 0===o){const e=this.varyings,u=e.length;null===t&&(t="nodeVarying"+u),"varying"!==a&&(t=this.getSubBuildProperty(t,n.subBuilds)),o=new xN(t,r,s,i),e.push(o),this.registerDeclaration(o),n[a]=o}return o}registerDeclaration(e){const t=this.shaderStage,r=this.declarations[t]||(this.declarations[t]={}),s=this.getPropertyName(e);let i=1,n=s;for(;void 0!==r[n];)n=s+"_"+i++;i>1&&(e.name=n,d(`TSL: Declaration name '${s}' of '${e.type}' already in use. Renamed to '${n}'.`)),r[n]=e}getCodeFromNode(e,t,r=this.shaderStage){const s=this.getDataFromNode(e);let i=s.code;if(void 0===i){const e=this.codes[r]||(this.codes[r]=[]),n=e.length;i=new TN("nodeCode"+n,t),e.push(i),s.code=i}return i}addFlowCodeHierarchy(e,t){const{flowCodes:r,flowCodeBlock:s}=this.getDataFromNode(e);let i=!0,n=t;for(;n;){if(!0===s.get(n)){i=!1;break}n=this.getDataFromNode(n).parentNodeBlock}if(i)for(const e of r)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,r){const s=this.getDataFromNode(e),i=s.flowCodes||(s.flowCodes=[]),n=s.flowCodeBlock||(s.flowCodeBlock=new WeakMap);i.push(t),n.set(r,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),r=this.flowChildNode(e,t);return this.flowsData.set(e,r),r}addInclude(e){null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(e)}buildFunctionNode(e){const t=new gT,r=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=r,t}flowShaderNode(e){const t=e.layout,r={[Symbol.iterator](){let e=0;const t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(const e of t.inputs)r[e.name]=new Zy(e.type,e.name);e.layout=null;const s=e.call(r),i=this.flowStagesNode(s,t.type);return e.layout=t,i}flowBuildStage(e,t,r=null){const s=this.getBuildStage();this.setBuildStage(t);const i=e.build(this,r);return this.setBuildStage(s),i}flowStagesNode(e,t=null){const r=this.flow,s=this.vars,i=this.declarations,n=this.cache,a=this.buildStage,o=this.stack,u={code:""};this.flow=u,this.vars={},this.declarations={},this.cache=new vN,this.stack=eb();for(const r of ii)this.setBuildStage(r),u.result=e.build(this,t);return u.vars=this.getVars(this.shaderStage),this.flow=r,this.vars=s,this.declarations=i,this.cache=n,this.stack=o,this.setBuildStage(a),u}getFunctionOperator(){return null}buildFunctionCode(){d("Abstract function.")}flowChildNode(e,t=null){const r=this.flow,s={code:""};return this.flow=s,s.result=e.build(this,t),this.flow=r,s}flowNodeFromShaderStage(e,t,r=null,s=null){const i=this.tab,n=this.cache,a=this.shaderStage,o=this.context;this.setShaderStage(e);const u={...this.context};delete u.nodeBlock,this.cache=this.globalCache,this.tab="\t",this.context=u;let l=null;if("generate"===this.buildStage){const i=this.flowChildNode(t,r);null!==s&&(i.code+=`${this.tab+s} = ${i.result};\n`),this.flowCode[e]=this.flowCode[e]+i.code,l=i}else l=t.build(this);return this.setShaderStage(a),this.cache=n,this.tab=i,this.context=o,l}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){d("Abstract function.")}getVaryings(){d("Abstract function.")}getVar(e,t,r=null){return`${null!==r?this.generateArrayDeclaration(e,r):this.getType(e)} ${t}`}getVars(e){let t="";const r=this.vars[e];if(void 0!==r)for(const e of r)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){d("Abstract function.")}getCodes(e){const t=this.codes[e];let r="";if(void 0!==t)for(const e of t)r+=e.code+"\n";return r}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){d("Abstract function.")}get subBuild(){return this.subBuildLayers[this.subBuildLayers.length-1]||null}addSubBuild(e){this.subBuildLayers.push(e)}removeSubBuild(){return this.subBuildLayers.pop()}getClosestSubBuild(e){let t;if(t=e&&e.isNode?e.isShaderCallNodeInternal?e.shaderNode.subBuilds:e.isStackNode?[e.subBuild]:this.getDataFromNode(e,"any").subBuilds:e instanceof Set?[...e]:e,!t)return null;const r=this.subBuildLayers;for(let e=t.length-1;e>=0;e--){const s=t[e];if(r.includes(s))return s}return null}getSubBuildOutput(e){return this.getSubBuildProperty("outputNode",e)}getSubBuildProperty(e="",t=null){let r,s;return r=null!==t?this.getClosestSubBuild(t):this.subBuildFn,s=r?e?r+"_"+e:r:e,s}build(){const{object:e,material:t,renderer:r}=this;if(null!==t){let e=r.library.fromMaterial(t);null===e&&(o(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new fg),e.build(this)}else this.addFlow("compute",e);for(const e of ii){this.setBuildStage(e),this.context.position&&this.context.position.isNode&&this.flowNodeFromShaderStage("vertex",this.context.position);for(const t of ni){this.setShaderStage(t);const r=this.flowNodes[t];for(const t of r)"generate"===e?this.flowNode(t):t.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getSharedDataFromNode(e){let t=zN.get(e);return void 0===t&&(t={}),t}getNodeUniform(e,t){const r=this.getSharedDataFromNode(e);let s=r.cache;if(void 0===s){if("float"===t||"int"===t||"uint"===t)s=new LN(e);else if("vec2"===t||"ivec2"===t||"uvec2"===t)s=new PN(e);else if("vec3"===t||"ivec3"===t||"uvec3"===t)s=new DN(e);else if("vec4"===t||"ivec4"===t||"uvec4"===t)s=new UN(e);else if("color"===t)s=new IN(e);else if("mat2"===t)s=new ON(e);else if("mat3"===t)s=new VN(e);else{if("mat4"!==t)throw new Error(`Uniform "${t}" not implemented.`);s=new kN(e)}r.cache=s}return s}format(e,t,r){if((t=this.getVectorType(t))===(r=this.getVectorType(r))||null===r||this.isReference(r))return e;const s=this.getTypeLength(t),i=this.getTypeLength(r);return 16===s&&9===i?`${this.getType(r)}( ${e}[ 0 ].xyz, ${e}[ 1 ].xyz, ${e}[ 2 ].xyz )`:9===s&&4===i?`${this.getType(r)}( ${e}[ 0 ].xy, ${e}[ 1 ].xy )`:s>4||i>4||0===i?e:s===i?`${this.getType(r)}( ${e} )`:s>i?(e="bool"===r?`all( ${e} )`:`${e}.${"xyz".slice(0,i)}`,this.format(e,this.getTypeFromLength(i,this.getComponentType(t)),r)):4===i&&s>1?`${this.getType(r)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===s?`${this.getType(r)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===s&&i>1&&t!==this.getComponentType(r)&&(e=`${this.getType(this.getComponentType(r))}( ${e} )`),`${this.getType(r)}( ${e} )`)}getSignature(){return`// Three.js r${ut} - Node System\n`}needsPreviousData(){const e=this.renderer.getMRT();return e&&e.has("velocity")||!0===Ks(this.object).useVelocity}}class jN{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,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(e,t){let r=e.get(t);return void 0===r&&(r={renderId:0,frameId:0},e.set(t,r)),r}updateBeforeNode(e){const t=e.getUpdateBeforeType(),r=e.updateReference(this);if(t===ei.FRAME){const t=this._getMaps(this.updateBeforeMap,r);if(t.frameId!==this.frameId){const r=t.frameId;t.frameId=this.frameId,!1===e.updateBefore(this)&&(t.frameId=r)}}else if(t===ei.RENDER){const t=this._getMaps(this.updateBeforeMap,r);if(t.renderId!==this.renderId){const r=t.renderId;t.renderId=this.renderId,!1===e.updateBefore(this)&&(t.renderId=r)}}else t===ei.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),r=e.updateReference(this);if(t===ei.FRAME){const t=this._getMaps(this.updateAfterMap,r);t.frameId!==this.frameId&&!1!==e.updateAfter(this)&&(t.frameId=this.frameId)}else if(t===ei.RENDER){const t=this._getMaps(this.updateAfterMap,r);t.renderId!==this.renderId&&!1!==e.updateAfter(this)&&(t.renderId=this.renderId)}else t===ei.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),r=e.updateReference(this);if(t===ei.FRAME){const t=this._getMaps(this.updateMap,r);t.frameId!==this.frameId&&!1!==e.update(this)&&(t.frameId=this.frameId)}else if(t===ei.RENDER){const t=this._getMaps(this.updateMap,r);t.renderId!==this.renderId&&!1!==e.update(this)&&(t.renderId=this.renderId)}else t===ei.OBJECT&&e.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 XN{constructor(e,t,r=null,s="",i=!1){this.type=e,this.name=t,this.count=r,this.qualifier=s,this.isConst=i}}XN.isNodeFunctionInput=!0;class KN extends dv{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class YN extends dv{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setupDirect(){const e=this.colorNode;return{lightDirection:b_(this.light),lightColor:e}}}class QN extends dv{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=m_(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=va(new e).setGroup(xa)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:r,lightDirectionNode:s}=this,i=cc.dot(s).mul(.5).add(.5),n=au(r,t,i);e.context.irradiance.addAssign(n)}}class ZN extends dv{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=va(0).setGroup(xa),this.penumbraCosNode=va(0).setGroup(xa),this.cutoffDistanceNode=va(0).setGroup(xa),this.decayExponentNode=va(0).setGroup(xa),this.colorNode=va(this.color).setGroup(xa)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e,t){const{coneCosNode:r,penumbraCosNode:s}=this;return du(r,s,t)}getLightCoord(e){const t=e.getNodeProperties(this);let r=t.projectionUV;return void 0===r&&(r=g_(this.light,e.context.positionWorld),t.projectionUV=r),r}setupDirect(e){const{colorNode:t,cutoffDistanceNode:r,decayExponentNode:s,light:i}=this,n=this.getLightVector(e),a=n.normalize(),o=a.dot(b_(i)),u=this.getSpotAttenuation(e,o),l=n.length(),d=cv({lightDistance:l,cutoffDistance:r,decayExponent:s});let c,h,p=t.mul(u).mul(d);if(i.colorNode?(h=this.getLightCoord(e),c=i.colorNode(h)):i.map&&(h=this.getLightCoord(e),c=Dl(i.map,h.xy).onRenderUpdate(()=>i.map)),c){p=h.mul(2).sub(1).abs().lessThan(1).all().select(p.mul(c),p)}return{lightColor:p,lightDirection:a}}}class JN extends ZN{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e,t){const r=this.light.iesMap;let s=null;if(r&&!0===r.isTexture){const e=t.acos().mul(1/Math.PI);s=Dl(r,xn(e,0),0).r}else s=super.getSpotAttenuation(t);return s}}class eS extends dv{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let e=0;e<9;e++)t.push(new r);this.lightProbe=Gl(t)}update(e){const{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){const t=lN(cc,this.lightProbe);e.context.irradiance.addAssign(t)}}const tS=ln(([e,t])=>{const r=e.abs().sub(t);return Lo(qo(r,0)).add(Ho(qo(r.x,r.y),0))});class rS extends ZN{static get type(){return"ProjectorLightNode"}update(e){super.update(e);const t=this.light;if(this.penumbraCosNode.value=Math.min(Math.cos(t.angle*(1-t.penumbra)),.99999),null===t.aspect){let e=1;null!==t.map&&(e=t.map.width/t.map.height),t.shadow.aspect=e}else t.shadow.aspect=t.aspect}getSpotAttenuation(e){const t=mn(0),r=this.penumbraCosNode,s=p_(this.light).mul(e.context.positionWorld||Qd);return hn(s.w.greaterThan(0),()=>{const e=s.xyz.div(s.w),i=tS(e.xy.sub(xn(.5)),xn(.5)),n=Pa(-1,Fa(1,Co(r)).sub(1));t.assign(uu(i.mul(-2).mul(n)))}),t}}const sS=new a,iS=new a;let nS=null;class aS extends dv{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=va(new r).setGroup(xa),this.halfWidth=va(new r).setGroup(xa),this.updateType=ei.RENDER}update(e){super.update(e);const{light:t}=this,r=e.camera.matrixWorldInverse;iS.identity(),sS.copy(t.matrixWorld),sS.premultiply(r),iS.extractRotation(sS),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(iS),this.halfHeight.value.applyMatrix4(iS)}setupDirectRectArea(e){let t,r;e.isAvailable("float32Filterable")?(t=Dl(nS.LTC_FLOAT_1),r=Dl(nS.LTC_FLOAT_2)):(t=Dl(nS.LTC_HALF_1),r=Dl(nS.LTC_HALF_2));const{colorNode:s,light:i}=this;return{lightColor:s,lightPosition:y_(i),halfWidth:this.halfWidth,halfHeight:this.halfHeight,ltc_1:t,ltc_2:r}}static setLTC(e){nS=e}}class oS{parseFunction(){d("Abstract function.")}}class uS{constructor(e,t,r="",s=""){this.type=e,this.inputs=t,this.name=r,this.precision=s}getCode(){d("Abstract function.")}}uS.isNodeFunction=!0;const lS=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,dS=/[a-z_0-9]+/gi,cS="#pragma main";class hS extends uS{constructor(e){const{type:t,inputs:r,name:s,precision:i,inputsCode:n,blockCode:a,headerCode:o}=(e=>{const t=(e=e.trim()).indexOf(cS),r=-1!==t?e.slice(t+12):e,s=r.match(lS);if(null!==s&&5===s.length){const i=s[4],n=[];let a=null;for(;null!==(a=dS.exec(i));)n.push(a);const o=[];let u=0;for(;u<n.length;){const e="const"===n[u][0];!0===e&&u++;let t=n[u][0];"in"===t||"out"===t||"inout"===t?u++:t="";const r=n[u++][0];let s=Number.parseInt(n[u][0]);!1===Number.isNaN(s)?u++:s=null;const i=n[u++][0];o.push(new XN(r,i,s,t,e))}const l=r.substring(s[0].length),d=void 0!==s[3]?s[3]:"";return{type:s[2],inputs:o,name:d,precision:void 0!==s[1]?s[1]:"",inputsCode:i,blockCode:l,headerCode:-1!==t?e.slice(0,t):""}}throw new Error("FunctionNode: Function is not a GLSL code.")})(e);super(t,r,s,i),this.inputsCode=n,this.blockCode=a,this.headerCode=o}getCode(e=this.name){let t;const r=this.blockCode;if(""!==r){const{type:s,inputsCode:i,headerCode:n,precision:a}=this;let o=`${s} ${e} ( ${i.trim()} )`;""!==a&&(o=`${a} ${o}`),t=n+o+r}else t="";return t}}class pS extends oS{parseFunction(e){return new hS(e)}}const gS=new WeakMap,mS=[],fS=[];class yS extends Ty{constructor(e,t){super(),this.renderer=e,this.backend=t,this.nodeFrame=new jN,this.nodeBuilderCache=new Map,this.callHashCache=new my,this.groupsData=new my,this.cacheLib={}}updateGroup(e){const t=e.groupNode,r=t.name;if(r===Ta.name)return!0;if(r===xa.name){const t=this.get(e),r=this.nodeFrame.renderId;return t.renderId!==r&&(t.renderId=r,!0)}if(r===ba.name){const t=this.get(e),r=this.nodeFrame.frameId;return t.frameId!==r&&(t.frameId=r,!0)}mS[0]=t,mS[1]=e;let s=this.groupsData.get(mS);return void 0===s&&this.groupsData.set(mS,s={}),mS[0]=null,mS[1]=null,s.version!==t.version&&(s.version=t.version,!0)}getForRenderCacheKey(e){return e.initialCacheKey}getForRender(e){const t=this.get(e);let r=t.nodeBuilderState;if(void 0===r){const{nodeBuilderCache:s}=this,i=this.getForRenderCacheKey(e);if(r=s.get(i),void 0===r){const t=t=>{const r=this.backend.createNodeBuilder(e.object,this.renderer);return r.scene=e.scene,r.material=t,r.camera=e.camera,r.context.material=t,r.lightsNode=e.lightsNode,r.environmentNode=this.getEnvironmentNode(e.scene),r.fogNode=this.getFogNode(e.scene),r.clippingContext=e.clippingContext,this.renderer.getOutputRenderTarget()&&this.renderer.getOutputRenderTarget().multiview&&r.enableMultiview(),r};let n=t(e.material);try{n.build()}catch(e){n=t(new fg),n.build();let r=e.stackTrace;!r&&e.stack&&(r=new Ds(e.stack)),o("TSL: "+e,r)}r=this._createNodeBuilderState(n),s.set(i,r)}r.usedTimes++,t.nodeBuilderState=r}return r}delete(e){if(e.isRenderObject){const t=this.get(e).nodeBuilderState;t.usedTimes--,0===t.usedTimes&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(e))}return super.delete(e)}getForCompute(e){const t=this.get(e);let r=t.nodeBuilderState;if(void 0===r){const s=this.backend.createNodeBuilder(e,this.renderer);s.build(),r=this._createNodeBuilderState(s),t.nodeBuilderState=r}return r}_createNodeBuilderState(e){return new mN(e.vertexShader,e.fragmentShader,e.computeShader,e.getAttributesArray(),e.getBindings(),e.updateNodes,e.updateBeforeNodes,e.updateAfterNodes,e.observer,e.transforms)}getEnvironmentNode(e){this.updateEnvironment(e);let t=null;if(e.environmentNode&&e.environmentNode.isNode)t=e.environmentNode;else{const r=this.get(e);r.environmentNode&&(t=r.environmentNode)}return t}getBackgroundNode(e){this.updateBackground(e);let t=null;if(e.backgroundNode&&e.backgroundNode.isNode)t=e.backgroundNode;else{const r=this.get(e);r.backgroundNode&&(t=r.backgroundNode)}return t}getFogNode(e){return this.updateFog(e),e.fogNode||this.get(e).fogNode||null}getCacheKey(e,t){mS[0]=e,mS[1]=t;const r=this.renderer.info.calls,s=this.callHashCache.get(mS)||{};if(s.callId!==r){const i=this.getEnvironmentNode(e),n=this.getFogNode(e);t&&fS.push(t.getCacheKey(!0)),i&&fS.push(i.getCacheKey()),n&&fS.push(n.getCacheKey()),fS.push(this.renderer.getOutputRenderTarget()&&this.renderer.getOutputRenderTarget().multiview?1:0),fS.push(this.renderer.shadowMap.enabled?1:0),fS.push(this.renderer.shadowMap.type),s.callId=r,s.cacheKey=Os(fS),this.callHashCache.set(mS,s),fS.length=0}return mS[0]=null,mS[1]=null,s.cacheKey}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(e){const t=this.get(e),r=e.background;if(r){const s=0===e.backgroundBlurriness&&t.backgroundBlurriness>0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;if(t.background!==r||s){const i=this.getCacheNode("background",r,()=>{if(!0===r.isCubeTexture||r.mapping===he||r.mapping===pe||r.mapping===we){if(e.backgroundBlurriness>0||r.mapping===we)return Pf(r);{let e;return e=!0===r.isCubeTexture?Mc(r):Dl(r),Bg(e)}}if(!0===r.isTexture)return Dl(r,Xl.flipY()).setUpdateMatrix(!0);!0!==r.isColor&&o("WebGPUNodes: Unsupported background configuration.",r)},s);t.backgroundNode=i,t.background=r,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}getCacheNode(e,t,r,s=!1){const i=this.cacheLib[e]||(this.cacheLib[e]=new WeakMap);let n=i.get(t);return(void 0===n||s)&&(n=r(),i.set(t,n)),n}updateFog(e){const t=this.get(e),r=e.fog;if(r){if(t.fog!==r){const e=this.getCacheNode("fog",r,()=>{if(r.isFogExp2){const e=Lc("color","color",r).setGroup(xa),t=Lc("density","float",r).setGroup(xa);return TT(e,bT(t))}if(r.isFog){const e=Lc("color","color",r).setGroup(xa),t=Lc("near","float",r).setGroup(xa),s=Lc("far","float",r).setGroup(xa);return TT(e,yT(t,s))}o("Renderer: Unsupported fog configuration.",r)});t.fogNode=e,t.fog=r}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),r=e.environment;if(r){if(t.environment!==r){const e=this.getCacheNode("environment",r,()=>!0===r.isCubeTexture?Mc(r):!0===r.isTexture?Dl(r):void o("Nodes: Unsupported environment configuration.",r));t.environmentNode=e,t.environment=r}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,r=null,s=null,i=null){const n=this.nodeFrame;return n.renderer=e,n.scene=t,n.object=r,n.camera=s,n.material=i,n}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace+","+e.xr.isPresenting}hasOutputChange(e){return gS.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,r=this.getOutputCacheKey(),s=e.isArrayTexture?Px(e,Nn(Xl,zl("gl_ViewID_OVR"))).renderOutput(t.toneMapping,t.currentColorSpace):Dl(e,Xl).renderOutput(t.toneMapping,t.currentColorSpace);return gS.set(e,r),s}updateBefore(e){const t=e.getNodeBuilderState();for(const r of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(r)}updateAfter(e){const t=e.getNodeBuilderState();for(const r of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(r)}updateForCompute(e){const t=this.getNodeFrame(),r=this.getForCompute(e);for(const e of r.updateNodes)t.updateNode(e)}updateForRender(e){const t=this.getNodeFrameForRender(e),r=e.getNodeBuilderState();for(const e of r.updateNodes)t.updateNode(e)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new jN,this.nodeBuilderCache=new Map,this.cacheLib={}}}const bS=new Xe;class xS{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",this.shadowPass=!1,this.viewNormalMatrix=new n,this.clippingGroupContexts=new WeakMap,this.intersectionPlanes=[],this.unionPlanes=[],this.parentVersion=null,null!==e&&(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix)}projectPlanes(e,t,r){const s=e.length;for(let i=0;i<s;i++){bS.copy(e[i]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);const s=t[r+i],n=bS.normal;s.x=-n.x,s.y=-n.y,s.z=-n.z,s.w=bS.constant}}updateGlobal(e,t){this.shadowPass=null!==e.overrideMaterial&&e.overrideMaterial.isShadowPassMaterial,this.viewMatrix=t.matrixWorldInverse,this.viewNormalMatrix.getNormalMatrix(this.viewMatrix)}update(e,t){let r=!1;e.version!==this.parentVersion&&(this.intersectionPlanes=Array.from(e.intersectionPlanes),this.unionPlanes=Array.from(e.unionPlanes),this.parentVersion=e.version),this.clipIntersection!==t.clipIntersection&&(this.clipIntersection=t.clipIntersection,this.clipIntersection?this.unionPlanes.length=e.unionPlanes.length:this.intersectionPlanes.length=e.intersectionPlanes.length);const i=t.clippingPlanes,n=i.length;let a,o;if(this.clipIntersection?(a=this.intersectionPlanes,o=e.intersectionPlanes.length):(a=this.unionPlanes,o=e.unionPlanes.length),a.length!==o+n){a.length=o+n;for(let e=0;e<n;e++)a[o+e]=new s;r=!0}this.projectPlanes(i,a,o),r&&(this.version++,this.cacheKey=`${this.intersectionPlanes.length}:${this.unionPlanes.length}`)}getGroupContext(e){if(this.shadowPass&&!e.clipShadows)return this;let t=this.clippingGroupContexts.get(e);return void 0===t&&(t=new xS(this),this.clippingGroupContexts.set(e,t)),t.update(this,e),t}get unionClippingCount(){return this.unionPlanes.length}}class TS{constructor(e,t){this.bundleGroup=e,this.camera=t}}const _S=[];class vS{constructor(){this.bundles=new my}get(e,t){const r=this.bundles;_S[0]=e,_S[1]=t;let s=r.get(_S);return void 0===s&&(s=new TS(e,t),r.set(_S,s)),_S[0]=null,_S[1]=null,s}dispose(){this.bundles=new my}}class NS{constructor(){this.lightNodes=new WeakMap,this.materialNodes=new Map,this.toneMappingNodes=new Map}fromMaterial(e){if(e.isNodeMaterial)return e;let t=null;const r=this.getMaterialNodeClass(e.type);if(null!==r){t=new r;for(const r in e)t[r]=e[r]}return t}addToneMapping(e,t){this.addType(e,t,this.toneMappingNodes)}getToneMappingFunction(e){return this.toneMappingNodes.get(e)||null}getMaterialNodeClass(e){return this.materialNodes.get(e)||null}addMaterial(e,t){this.addType(e,t,this.materialNodes)}getLightNodeClass(e){return this.lightNodes.get(e)||null}addLight(e,t){this.addClass(e,t,this.lightNodes)}addType(e,t,r){if(r.has(t))d(`Redefinition of node ${t}`);else{if("function"!=typeof e)throw new Error(`Node class ${e.name} is not a class.`);if("function"==typeof t||"object"==typeof t)throw new Error(`Base class ${t} is not a class.`);r.set(t,e)}}addClass(e,t,r){if(r.has(t))d(`Redefinition of node ${t.name}`);else{if("function"!=typeof e)throw new Error(`Node class ${e.name} is not a class.`);if("function"!=typeof t)throw new Error(`Base class ${t.name} is not a class.`);r.set(t,e)}}}const SS=new v_,RS=new WeakMap;class ES{createNode(e=[]){return(new v_).setLights(e)}getNode(e){if(e.isQuadMesh)return SS;let t=RS.get(e);return void 0===t&&(t=this.createNode(),RS.set(e,t)),t}}class AS extends ae{constructor(e=1,t=1,r={}){super(e,t,r),this.isXRRenderTarget=!0,this._hasExternalTextures=!1,this._autoAllocateDepthBuffer=!0,this._isOpaqueFramebuffer=!1}copy(e){return super.copy(e),this._hasExternalTextures=e._hasExternalTextures,this._autoAllocateDepthBuffer=e._autoAllocateDepthBuffer,this._isOpaqueFramebuffer=e._isOpaqueFramebuffer,this}}const wS=new r,CS=new r;class MS extends u{constructor(e,r=!1){super(),this.enabled=!1,this.isPresenting=!1,this.cameraAutoUpdate=!0,this._renderer=e,this._cameraL=new Re,this._cameraL.viewport=new s,this._cameraR=new Re,this._cameraR.viewport=new s,this._cameras=[this._cameraL,this._cameraR],this._cameraXR=new lt,this._currentDepthNear=null,this._currentDepthFar=null,this._controllers=[],this._controllerInputSources=[],this._xrRenderTarget=null,this._layers=[],this._sessionUsesLayers=!1,this._supportsGlBinding="undefined"!=typeof XRWebGLBinding,this._frameBufferTargets=null,this._createXRLayer=DS.bind(this),this._gl=null,this._currentAnimationContext=null,this._currentAnimationLoop=null,this._currentPixelRatio=null,this._currentSize=new t,this._onSessionEvent=FS.bind(this),this._onSessionEnd=LS.bind(this),this._onInputSourcesChange=PS.bind(this),this._onAnimationFrame=US.bind(this),this._referenceSpace=null,this._referenceSpaceType="local-floor",this._customReferenceSpace=null,this._framebufferScaleFactor=1,this._foveation=1,this._session=null,this._glBaseLayer=null,this._glBinding=null,this._glProjLayer=null,this._xrFrame=null,this._supportsLayers=this._supportsGlBinding&&"createProjectionLayer"in XRWebGLBinding.prototype,this._useMultiviewIfPossible=r,this._useMultiview=!1}getController(e){return this._getController(e).getTargetRaySpace()}getControllerGrip(e){return this._getController(e).getGripSpace()}getHand(e){return this._getController(e).getHandSpace()}getFoveation(){if(null!==this._glProjLayer||null!==this._glBaseLayer)return this._foveation}setFoveation(e){this._foveation=e,null!==this._glProjLayer&&(this._glProjLayer.fixedFoveation=e),null!==this._glBaseLayer&&void 0!==this._glBaseLayer.fixedFoveation&&(this._glBaseLayer.fixedFoveation=e)}getFramebufferScaleFactor(){return this._framebufferScaleFactor}setFramebufferScaleFactor(e){this._framebufferScaleFactor=e,!0===this.isPresenting&&d("XRManager: Cannot change framebuffer scale while presenting.")}getReferenceSpaceType(){return this._referenceSpaceType}setReferenceSpaceType(e){this._referenceSpaceType=e,!0===this.isPresenting&&d("XRManager: Cannot change reference space type while presenting.")}getReferenceSpace(){return this._customReferenceSpace||this._referenceSpace}setReferenceSpace(e){this._customReferenceSpace=e}getCamera(){return this._cameraXR}getEnvironmentBlendMode(){if(null!==this._session)return this._session.environmentBlendMode}getBinding(){return null===this._glBinding&&this._supportsGlBinding&&(this._glBinding=new XRWebGLBinding(this._session,this._gl)),this._glBinding}getFrame(){return this._xrFrame}useMultiview(){return this._useMultiview}createQuadLayer(e,t,r,s,i,n,a,o={}){const u=new dt(e,t),l=new AS(i,n,{format:Ae,type:$e,depthTexture:new J(i,n,o.stencil?Ge:S,void 0,void 0,void 0,void 0,void 0,void 0,o.stencil?Ve:ke),stencilBuffer:o.stencil,resolveDepthBuffer:!1,resolveStencilBuffer:!1});l._autoAllocateDepthBuffer=!0;const d=new ye({color:16777215,side:ct});d.map=l.texture,d.map.offset.y=1,d.map.repeat.y=-1;const c=new ue(u,d);c.position.copy(r),c.quaternion.copy(s);const h={type:"quad",width:e,height:t,translation:r,quaternion:s,pixelwidth:i,pixelheight:n,plane:c,material:d,rendercall:a,renderTarget:l};if(this._layers.push(h),null!==this._session){h.plane.material=new ye({color:16777215,side:ct}),h.plane.material.blending=ht,h.plane.material.blendEquation=qe,h.plane.material.blendSrc=pt,h.plane.material.blendDst=pt,h.xrlayer=this._createXRLayer(h);const e=this._session.renderState.layers;e.unshift(h.xrlayer),this._session.updateRenderState({layers:e})}else l.isXRRenderTarget=!1;return c}createCylinderLayer(e,t,r,s,i,n,a,o,u={}){const l=new gt(e,e,e*t/r,64,64,!0,Math.PI-t/2,t),d=new AS(n,a,{format:Ae,type:$e,depthTexture:new J(n,a,u.stencil?Ge:S,void 0,void 0,void 0,void 0,void 0,void 0,u.stencil?Ve:ke),stencilBuffer:u.stencil,resolveDepthBuffer:!1,resolveStencilBuffer:!1});d._autoAllocateDepthBuffer=!0;const c=new ye({color:16777215,side:L});c.map=d.texture,c.map.offset.y=1,c.map.repeat.y=-1;const h=new ue(l,c);h.position.copy(s),h.quaternion.copy(i);const p={type:"cylinder",radius:e,centralAngle:t,aspectratio:r,translation:s,quaternion:i,pixelwidth:n,pixelheight:a,plane:h,material:c,rendercall:o,renderTarget:d};if(this._layers.push(p),null!==this._session){p.plane.material=new ye({color:16777215,side:L}),p.plane.material.blending=ht,p.plane.material.blendEquation=qe,p.plane.material.blendSrc=pt,p.plane.material.blendDst=pt,p.xrlayer=this._createXRLayer(p);const e=this._session.renderState.layers;e.unshift(p.xrlayer),this._session.updateRenderState({layers:e})}else d.isXRRenderTarget=!1;return h}renderLayers(){const e=new r,s=new mt,i=this._renderer,n=this.isPresenting,a=i.getOutputRenderTarget(),o=i._frameBufferTarget;this.isPresenting=!1;const u=new t;i.getSize(u);const l=i._quad;for(const t of this._layers)if(t.renderTarget.isXRRenderTarget=null!==this._session,t.renderTarget._hasExternalTextures=t.renderTarget.isXRRenderTarget,t.renderTarget.isXRRenderTarget&&this._sessionUsesLayers){t.xrlayer.transform=new XRRigidTransform(t.plane.getWorldPosition(e),t.plane.getWorldQuaternion(s));const r=this._glBinding.getSubImage(t.xrlayer,this._xrFrame);i.backend.setXRRenderTargetTextures(t.renderTarget,r.colorTexture,void 0),i._setXRLayerSize(t.renderTarget.width,t.renderTarget.height),i.setOutputRenderTarget(t.renderTarget),i.setRenderTarget(null),i._frameBufferTarget=null,this._frameBufferTargets||(this._frameBufferTargets=new WeakMap);const{frameBufferTarget:n,quad:a}=this._frameBufferTargets.get(t.renderTarget)||{frameBufferTarget:null,quad:null};n?(i._frameBufferTarget=n,i._quad=a):(i._quad=new lx(new fg),this._frameBufferTargets.set(t.renderTarget,{frameBufferTarget:i._getFrameBufferTarget(),quad:i._quad})),t.rendercall(),i._frameBufferTarget=null}else i.setRenderTarget(t.renderTarget),t.rendercall();i.setRenderTarget(null),i.setOutputRenderTarget(a),i._frameBufferTarget=o,i._setXRLayerSize(u.x,u.y),i._quad=l,this.isPresenting=n}getSession(){return this._session}async setSession(e){const t=this._renderer,r=t.backend;this._gl=t.getContext();const s=this._gl,i=s.getContextAttributes();if(this._session=e,null!==e){if(!0===r.isWebGPUBackend)throw new Error('THREE.XRManager: XR is currently not supported with a WebGPU backend. Use WebGL by passing "{ forceWebGL: true }" to the constructor of the renderer.');if(e.addEventListener("select",this._onSessionEvent),e.addEventListener("selectstart",this._onSessionEvent),e.addEventListener("selectend",this._onSessionEvent),e.addEventListener("squeeze",this._onSessionEvent),e.addEventListener("squeezestart",this._onSessionEvent),e.addEventListener("squeezeend",this._onSessionEvent),e.addEventListener("end",this._onSessionEnd),e.addEventListener("inputsourceschange",this._onInputSourcesChange),await r.makeXRCompatible(),this._currentPixelRatio=t.getPixelRatio(),t.getSize(this._currentSize),this._currentAnimationContext=t._animation.getContext(),this._currentAnimationLoop=t._animation.getAnimationLoop(),t._animation.stop(),!0===this._supportsLayers){let r=null,n=null,a=null;t.depth&&(a=t.stencil?s.DEPTH24_STENCIL8:s.DEPTH_COMPONENT24,r=t.stencil?Ve:ke,n=t.stencil?Ge:S);const o={colorFormat:s.RGBA8,depthFormat:a,scaleFactor:this._framebufferScaleFactor,clearOnAccess:!1};this._useMultiviewIfPossible&&t.hasFeature("OVR_multiview2")&&(o.textureType="texture-array",this._useMultiview=!0),this._glBinding=this.getBinding();const u=this._glBinding.createProjectionLayer(o),l=[u];this._glProjLayer=u,t.setPixelRatio(1),t._setXRLayerSize(u.textureWidth,u.textureHeight);const d=this._useMultiview?2:1,c=new J(u.textureWidth,u.textureHeight,n,void 0,void 0,void 0,void 0,void 0,void 0,r,d);if(this._xrRenderTarget=new AS(u.textureWidth,u.textureHeight,{format:Ae,type:$e,colorSpace:t.outputColorSpace,depthTexture:c,stencilBuffer:t.stencil,samples:i.antialias?4:0,resolveDepthBuffer:!1===u.ignoreDepthValues,resolveStencilBuffer:!1===u.ignoreDepthValues,depth:this._useMultiview?2:1,multiview:this._useMultiview}),this._xrRenderTarget._hasExternalTextures=!0,this._xrRenderTarget.depth=this._useMultiview?2:1,this._sessionUsesLayers=e.enabledFeatures.includes("layers"),this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType()),this._sessionUsesLayers)for(const e of this._layers)e.plane.material=new ye({color:16777215,side:"cylinder"===e.type?L:ct}),e.plane.material.blending=ht,e.plane.material.blendEquation=qe,e.plane.material.blendSrc=pt,e.plane.material.blendDst=pt,e.xrlayer=this._createXRLayer(e),l.unshift(e.xrlayer);e.updateRenderState({layers:l})}else{const r={antialias:t.currentSamples>0,alpha:!0,depth:t.depth,stencil:t.stencil,framebufferScaleFactor:this.getFramebufferScaleFactor()},i=new XRWebGLLayer(e,s,r);this._glBaseLayer=i,e.updateRenderState({baseLayer:i}),t.setPixelRatio(1),t._setXRLayerSize(i.framebufferWidth,i.framebufferHeight),this._xrRenderTarget=new AS(i.framebufferWidth,i.framebufferHeight,{format:Ae,type:$e,colorSpace:t.outputColorSpace,stencilBuffer:t.stencil,resolveDepthBuffer:!1===i.ignoreDepthValues,resolveStencilBuffer:!1===i.ignoreDepthValues}),this._xrRenderTarget._isOpaqueFramebuffer=!0,this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType())}this.setFoveation(this.getFoveation()),t._animation.setAnimationLoop(this._onAnimationFrame),t._animation.setContext(e),t._animation.start(),this.isPresenting=!0,this.dispatchEvent({type:"sessionstart"})}}updateCamera(e){const t=this._session;if(null===t)return;const r=e.near,s=e.far,i=this._cameraXR,n=this._cameraL,a=this._cameraR;i.near=a.near=n.near=r,i.far=a.far=n.far=s,i.isMultiViewCamera=this._useMultiview,this._currentDepthNear===i.near&&this._currentDepthFar===i.far||(t.updateRenderState({depthNear:i.near,depthFar:i.far}),this._currentDepthNear=i.near,this._currentDepthFar=i.far),i.layers.mask=6|e.layers.mask,n.layers.mask=-5&i.layers.mask,a.layers.mask=-3&i.layers.mask;const o=e.parent,u=i.cameras;BS(i,o);for(let e=0;e<u.length;e++)BS(u[e],o);2===u.length?function(e,t,r){wS.setFromMatrixPosition(t.matrixWorld),CS.setFromMatrixPosition(r.matrixWorld);const s=wS.distanceTo(CS),i=t.projectionMatrix.elements,n=r.projectionMatrix.elements,a=i[14]/(i[10]-1),o=i[14]/(i[10]+1),u=(i[9]+1)/i[5],l=(i[9]-1)/i[5],d=(i[8]-1)/i[0],c=(n[8]+1)/n[0],h=a*d,p=a*c,g=s/(-d+c),m=g*-d;if(t.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.translateX(m),e.translateZ(g),e.matrixWorld.compose(e.position,e.quaternion,e.scale),e.matrixWorldInverse.copy(e.matrixWorld).invert(),-1===i[10])e.projectionMatrix.copy(t.projectionMatrix),e.projectionMatrixInverse.copy(t.projectionMatrixInverse);else{const t=a+g,r=o+g,i=h-m,n=p+(s-m),d=u*o/r*t,c=l*o/r*t;e.projectionMatrix.makePerspective(i,n,d,c,t,r),e.projectionMatrixInverse.copy(e.projectionMatrix).invert()}}(i,n,a):i.projectionMatrix.copy(n.projectionMatrix),function(e,t,r){null===r?e.matrix.copy(t.matrixWorld):(e.matrix.copy(r.matrixWorld),e.matrix.invert(),e.matrix.multiply(t.matrixWorld));e.matrix.decompose(e.position,e.quaternion,e.scale),e.updateMatrixWorld(!0),e.projectionMatrix.copy(t.projectionMatrix),e.projectionMatrixInverse.copy(t.projectionMatrixInverse),e.isPerspectiveCamera&&(e.fov=2*yt*Math.atan(1/e.projectionMatrix.elements[5]),e.zoom=1)}(e,i,o)}_getController(e){let t=this._controllers[e];return void 0===t&&(t=new ft,this._controllers[e]=t),t}}function BS(e,t){null===t?e.matrixWorld.copy(e.matrix):e.matrixWorld.multiplyMatrices(t.matrixWorld,e.matrix),e.matrixWorldInverse.copy(e.matrixWorld).invert()}function FS(e){const t=this._controllerInputSources.indexOf(e.inputSource);if(-1===t)return;const r=this._controllers[t];if(void 0!==r){const t=this.getReferenceSpace();r.update(e.inputSource,e.frame,t),r.dispatchEvent({type:e.type,data:e.inputSource})}}function LS(){const e=this._session,t=this._renderer;e.removeEventListener("select",this._onSessionEvent),e.removeEventListener("selectstart",this._onSessionEvent),e.removeEventListener("selectend",this._onSessionEvent),e.removeEventListener("squeeze",this._onSessionEvent),e.removeEventListener("squeezestart",this._onSessionEvent),e.removeEventListener("squeezeend",this._onSessionEvent),e.removeEventListener("end",this._onSessionEnd),e.removeEventListener("inputsourceschange",this._onInputSourcesChange);for(let e=0;e<this._controllers.length;e++){const t=this._controllerInputSources[e];null!==t&&(this._controllerInputSources[e]=null,this._controllers[e].disconnect(t))}if(this._currentDepthNear=null,this._currentDepthFar=null,t._resetXRState(),this._session=null,this._xrRenderTarget=null,this._glBinding=null,this._glBaseLayer=null,this._glProjLayer=null,!0===this._sessionUsesLayers)for(const e of this._layers)e.renderTarget=new AS(e.pixelwidth,e.pixelheight,{format:Ae,type:$e,depthTexture:new J(e.pixelwidth,e.pixelheight,e.stencilBuffer?Ge:S,void 0,void 0,void 0,void 0,void 0,void 0,e.stencilBuffer?Ve:ke),stencilBuffer:e.stencilBuffer,resolveDepthBuffer:!1,resolveStencilBuffer:!1}),e.renderTarget.isXRRenderTarget=!1,e.plane.material=e.material,e.material.map=e.renderTarget.texture,e.material.map.offset.y=1,e.material.map.repeat.y=-1,delete e.xrlayer;this.isPresenting=!1,this._useMultiview=!1,t._animation.stop(),t._animation.setAnimationLoop(this._currentAnimationLoop),t._animation.setContext(this._currentAnimationContext),t._animation.start(),t.setPixelRatio(this._currentPixelRatio),t.setSize(this._currentSize.width,this._currentSize.height,!1),this.dispatchEvent({type:"sessionend"})}function PS(e){const t=this._controllers,r=this._controllerInputSources;for(let s=0;s<e.removed.length;s++){const i=e.removed[s],n=r.indexOf(i);n>=0&&(r[n]=null,t[n].disconnect(i))}for(let s=0;s<e.added.length;s++){const i=e.added[s];let n=r.indexOf(i);if(-1===n){for(let e=0;e<t.length;e++){if(e>=r.length){r.push(i),n=e;break}if(null===r[e]){r[e]=i,n=e;break}}if(-1===n)break}const a=t[n];a&&a.connect(i)}}function DS(e){return"quad"===e.type?this._glBinding.createQuadLayer({transform:new XRRigidTransform(e.translation,e.quaternion),width:e.width/2,height:e.height/2,space:this._referenceSpace,viewPixelWidth:e.pixelwidth,viewPixelHeight:e.pixelheight,clearOnAccess:!1}):this._glBinding.createCylinderLayer({transform:new XRRigidTransform(e.translation,e.quaternion),radius:e.radius,centralAngle:e.centralAngle,aspectRatio:e.aspectRatio,space:this._referenceSpace,viewPixelWidth:e.pixelwidth,viewPixelHeight:e.pixelheight,clearOnAccess:!1})}function US(e,t){if(void 0===t)return;const r=this._cameraXR,i=this._renderer,n=i.backend,a=this._glBaseLayer,o=this.getReferenceSpace(),u=t.getViewerPose(o);if(this._xrFrame=t,null!==u){const e=u.views;null!==this._glBaseLayer&&n.setXRTarget(a.framebuffer);let t=!1;e.length!==r.cameras.length&&(r.cameras.length=0,t=!0);for(let i=0;i<e.length;i++){const o=e[i];let u;if(!0===this._supportsLayers){const e=this._glBinding.getViewSubImage(this._glProjLayer,o);u=e.viewport,0===i&&n.setXRRenderTargetTextures(this._xrRenderTarget,e.colorTexture,this._glProjLayer.ignoreDepthValues&&!this._useMultiview?void 0:e.depthStencilTexture)}else u=a.getViewport(o);let l=this._cameras[i];void 0===l&&(l=new Re,l.layers.enable(i),l.viewport=new s,this._cameras[i]=l),l.matrix.fromArray(o.transform.matrix),l.matrix.decompose(l.position,l.quaternion,l.scale),l.projectionMatrix.fromArray(o.projectionMatrix),l.projectionMatrixInverse.copy(l.projectionMatrix).invert(),l.viewport.set(u.x,u.y,u.width,u.height),0===i&&(r.matrix.copy(l.matrix),r.matrix.decompose(r.position,r.quaternion,r.scale)),!0===t&&r.cameras.push(l)}i.setOutputRenderTarget(this._xrRenderTarget)}for(let e=0;e<this._controllers.length;e++){const r=this._controllerInputSources[e],s=this._controllers[e];null!==r&&void 0!==s&&s.update(r,t,o)}this._currentAnimationLoop&&this._currentAnimationLoop(e,t),t.detectedPlanes&&this.dispatchEvent({type:"planesdetected",data:t}),this._xrFrame=null}class IS extends u{constructor(e){super(),this.domElement=e,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new s(0,0,this._width,this._height),this._scissor=new s(0,0,this._width,this._height),this._scissorTest=!1,this.colorTexture=new Q,this.depthTexture=new J}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,r){this.xr&&this.xr.isPresenting||(this._width=e,this._height=t,this._pixelRatio=r,this.domElement.width=Math.floor(e*r),this.domElement.height=Math.floor(t*r),this.setViewport(0,0,e,t),this._dispatchResize())}setSize(e,t,r=!0){this.xr&&this.xr.isPresenting||(this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===r&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._dispatchResize())}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,r,s){const i=this._scissor;e.isVector4?i.copy(e):i.set(e,t,r,s)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,r,s,i=0,n=1){const a=this._viewport;e.isVector4?a.copy(e):a.set(e,t,r,s),a.minDepth=i,a.maxDepth=n}_dispatchResize(){this.dispatchEvent({type:"resize"})}dispose(){this.dispatchEvent({type:"dispose"})}}const OS=new le,VS=new t,kS=new s,GS=new xt,$S=new bt,zS=new a,WS=new s,HS={[ct]:L,[L]:ct,[P]:P};class qS{constructor(e,t={}){this.isRenderer=!0;const{logarithmicDepthBuffer:r=!1,reversedDepthBuffer:s=!1,alpha:i=!0,depth:n=!0,stencil:a=!1,antialias:o=!1,samples:u=0,getFallback:l=null,outputBufferType:d=_e,multiview:c=!1}=t;this.backend=e,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=i,this.logarithmicDepthBuffer=r,this.reversedDepthBuffer=s,this.outputColorSpace=ne,this.toneMapping=m,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=n,this.stencil=a,this.info=new By,this.contextNode=_u(),this.library=new NS,this.lighting=new ES,this._samples=u||!0===o?4:0,this._onCanvasTargetResize=this._onCanvasTargetResize.bind(this),this._canvasTarget=new IS(e.getDomElement()),this._canvasTarget.addEventListener("resize",this._onCanvasTargetResize),this._canvasTarget.isDefaultCanvasTarget=!0,this._inspector=new _l,this._inspector.setRenderer(this),this._getFallback=l,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 lx(new fg),this._quad.name="Output Color Transform",this._quad.material.name="outputColorTransform",this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;const h=!0===this.alpha?0:1;this._clearColor=new Qy(0,0,0,h),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._outputRenderTarget=null,this._mrt=null,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._isDeviceLost=!1,this.onDeviceLost=this._onDeviceLost,this._outputBufferType=d,this._cacheShadowNodes=new WeakMap,this._initialized=!1,this._callDepth=-1,this._initPromise=null,this._compilationPromises=null,this.transparent=!0,this.opaque=!0,this.shadowMap={enabled:!1,transmitted:!1,type:et},this.xr=new MS(this,c),this.debug={checkShaderErrors:!0,onShaderError:null,getShaderAsync:async(e,t,r)=>{await this.compileAsync(e,t);const s=this._renderLists.get(e,t),i=this._renderContexts.get(this._renderTarget,this._mrt),n=e.overrideMaterial||r.material,a=this._objects.get(r,n,e,t,s.lightsNode,i,i.clippingContext),{fragmentShader:o,vertexShader:u}=a.getNodeBuilderState();return{fragmentShader:o,vertexShader:u}}}}async init(){return null!==this._initPromise||(this._initPromise=new Promise(async(e,t)=>{let r=this.backend;try{await r.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=r=this._getFallback(e),await r.init(this)}catch(e){return void t(e)}}this._nodes=new yS(this,r),this._animation=new gy(this,this._nodes,this.info),this._attributes=new Ey(r),this._background=new hN(this,this._nodes),this._geometries=new My(this._attributes,this.info),this._textures=new Yy(this,r,this.info),this._pipelines=new Iy(r,this._nodes),this._bindings=new Oy(r,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new xy(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new Wy(this.lighting),this._bundles=new vS,this._renderContexts=new Xy(this),this._animation.start(),this._initialized=!0,this._inspector.init(),e(this)})),this._initPromise}get domElement(){return this._canvasTarget.domElement}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,r=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();const s=this._nodes.nodeFrame,i=s.renderId,n=this._currentRenderContext,a=this._currentRenderObjectFunction,o=this._handleObjectFunction,u=this._compilationPromises,l=!0===e.isScene?e:OS;null===r&&(r=e);const d=this._renderTarget,c=this._renderContexts.get(d,this._mrt),h=this._activeMipmapLevel,p=[];this._currentRenderContext=c,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=p,s.renderId++,s.update(),c.depth=this.depth,c.stencil=this.stencil,c.clippingContext||(c.clippingContext=new xS),c.clippingContext.updateGlobal(l,t),l.onBeforeRender(this,e,t,d);const g=this._renderLists.get(e,t);if(g.begin(),this._projectObject(e,t,0,g,c.clippingContext),r!==e&&r.traverseVisible(function(e){e.isLight&&e.layers.test(t.layers)&&g.pushLight(e)}),g.finish(),null!==d){this._textures.updateRenderTarget(d,h);const e=this._textures.get(d);c.textures=e.textures,c.depthTexture=e.depthTexture}else c.textures=null,c.depthTexture=null;r!==e?this._background.update(r,g,c):this._background.update(l,g,c);const m=g.opaque,f=g.transparent,y=g.transparentDoublePass,b=g.lightsNode;!0===this.opaque&&m.length>0&&this._renderObjects(m,t,l,b),!0===this.transparent&&f.length>0&&this._renderTransparents(f,y,t,l,b),s.renderId=i,this._currentRenderContext=n,this._currentRenderObjectFunction=a,this._handleObjectFunction=o,this._compilationPromises=u,await Promise.all(p)}async renderAsync(e,t){v('Renderer: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.render(e,t)}async waitForGPU(){o("Renderer: waitForGPU() has been removed. Read https://github.com/mrdoob/three.js/issues/32012 for more information.")}set inspector(e){null!==this._inspector&&this._inspector.setRenderer(null),this._inspector=e,this._inspector.setRenderer(this)}get inspector(){return this._inspector}set highPrecision(e){const t=this.contextNode.value;!0===e?(t.modelViewMatrix=Hd,t.modelNormalViewMatrix=qd):this.highPrecision&&(delete t.modelViewMatrix,delete t.modelNormalViewMatrix)}get highPrecision(){const e=this.contextNode.value;return e.modelViewMatrix===Hd&&e.modelNormalViewMatrix===qd}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getOutputBufferType(){return this._outputBufferType}getColorBufferType(){return v('Renderer: ".getColorBufferType()" has been renamed to ".getOutputBufferType()".'),this.getOutputBufferType()}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:\n\nMessage: ${e.message}`;e.reason&&(t+=`\nReason: ${e.reason}`),o(t),this._isDeviceLost=!0}_renderBundle(e,t,r){const{bundleGroup:s,camera:i,renderList:n}=e,a=this._currentRenderContext,o=this._bundles.get(s,i),u=this.backend.get(o);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=s.version!==u.version,d=!1===u.renderContexts.has(a)||l;if(u.renderContexts.add(a),d){this.backend.beginBundle(a),(void 0===u.renderObjects||l)&&(u.renderObjects=[]),this._currentRenderBundle=o;const{transparentDoublePass:e,transparent:d,opaque:c}=n;!0===this.opaque&&c.length>0&&this._renderObjects(c,i,t,r),!0===this.transparent&&d.length>0&&this._renderTransparents(d,e,i,t,r),this._currentRenderBundle=null,this.backend.finishBundle(a,o),u.version=s.version}else{const{renderObjects:e}=u;for(let t=0,r=e.length;t<r;t++){const r=e[t];this._nodes.needsRefresh(r)&&(this._nodes.updateBefore(r),this._nodes.updateForRender(r),this._bindings.updateForRender(r),this._nodes.updateAfter(r))}}this.backend.addBundle(a,o)}render(e,t){if(!1===this._initialized)throw new Error('Renderer: .render() called before the backend is initialized. Use "await renderer.init();" before rendering.');this._renderScene(e,t)}get initialized(){return this._initialized}_getFrameBufferTarget(){const{currentToneMapping:e,currentColorSpace:t}=this,r=e!==m,s=t!==p.workingColorSpace;if(!1===r&&!1===s)return null;const{width:i,height:n}=this.getDrawingBufferSize(VS),{depth:a,stencil:o}=this;let u=this._frameBufferTarget;null===u&&(u=new ae(i,n,{depthBuffer:a,stencilBuffer:o,type:this._outputBufferType,format:Ae,colorSpace:p.workingColorSpace,generateMipmaps:!1,minFilter:de,magFilter:de,samples:this.samples}),u.isPostProcessingRenderTarget=!0,this._frameBufferTarget=u);const l=this.getOutputRenderTarget();u.depthBuffer=a,u.stencilBuffer=o,null!==l?u.setSize(l.width,l.height,l.depth):u.setSize(i,n,1);const d=this._canvasTarget;return u.viewport.copy(d._viewport),u.scissor.copy(d._scissor),u.viewport.multiplyScalar(d._pixelRatio),u.scissor.multiplyScalar(d._pixelRatio),u.scissorTest=d._scissorTest,u.multiview=null!==l&&l.multiview,u.resolveDepthBuffer=null===l||l.resolveDepthBuffer,u._autoAllocateDepthBuffer=null!==l&&l._autoAllocateDepthBuffer,u}_renderScene(e,t,r=!0){if(!0===this._isDeviceLost)return;const s=r?this._getFrameBufferTarget():null,i=this._nodes.nodeFrame,n=i.renderId,a=this._currentRenderContext,o=this._currentRenderObjectFunction,u=this._handleObjectFunction;this._callDepth++;const l=!0===e.isScene?e:OS,d=this._renderTarget||this._outputRenderTarget,c=this._activeCubeFace,h=this._activeMipmapLevel;let p;null!==s?(p=s,this.setRenderTarget(p)):p=d;const g=this._renderContexts.get(p,this._mrt,this._callDepth);this._currentRenderContext=g,this._currentRenderObjectFunction=this._renderObjectFunction||this.renderObject,this._handleObjectFunction=this._renderObjectDirect,this.info.calls++,this.info.render.calls++,this.info.render.frameCalls++,i.renderId=this.info.calls,this.backend.updateTimeStampUID(g),this.inspector.beginRender(this.backend.getTimestampUID(g),e,t,p);const m=this.xr;if(!1===m.isPresenting){let e=!1;if(!0===this.reversedDepthBuffer&&!0!==t.reversedDepth){if(t._reversedDepth=!0,t.isArrayCamera)for(const e of t.cameras)e._reversedDepth=!0;e=!0}const r=this.coordinateSystem;if(t.coordinateSystem!==r){if(t.coordinateSystem=r,t.isArrayCamera)for(const e of t.cameras)e.coordinateSystem=r;e=!0}if(!0===e&&(t.updateProjectionMatrix(),t.isArrayCamera))for(const e of t.cameras)e.updateProjectionMatrix()}!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld(),null===t.parent&&!0===t.matrixWorldAutoUpdate&&t.updateMatrixWorld(),!0===m.enabled&&!0===m.isPresenting&&(!0===m.cameraAutoUpdate&&m.updateCamera(t),t=m.getCamera());const f=this._canvasTarget;let y=f._viewport,b=f._scissor,x=f._pixelRatio;null!==p&&(y=p.viewport,b=p.scissor,x=1),this.getDrawingBufferSize(VS),kS.set(0,0,VS.width,VS.height);const T=void 0===y.minDepth?0:y.minDepth,_=void 0===y.maxDepth?1:y.maxDepth;g.viewportValue.copy(y).multiplyScalar(x).floor(),g.viewportValue.width>>=h,g.viewportValue.height>>=h,g.viewportValue.minDepth=T,g.viewportValue.maxDepth=_,g.viewport=!1===g.viewportValue.equals(kS),g.scissorValue.copy(b).multiplyScalar(x).floor(),g.scissor=f._scissorTest&&!1===g.scissorValue.equals(kS),g.scissorValue.width>>=h,g.scissorValue.height>>=h,g.clippingContext||(g.clippingContext=new xS),g.clippingContext.updateGlobal(l,t),l.onBeforeRender(this,e,t,p);const v=t.isArrayCamera?$S:GS;t.isArrayCamera||(zS.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),v.setFromProjectionMatrix(zS,t.coordinateSystem,t.reversedDepth));const N=this._renderLists.get(e,t);if(N.begin(),this._projectObject(e,t,0,N,g.clippingContext),N.finish(),!0===this.sortObjects&&N.sort(this._opaqueSort,this._transparentSort),null!==p){this._textures.updateRenderTarget(p,h);const e=this._textures.get(p);g.textures=e.textures,g.depthTexture=e.depthTexture,g.width=e.width,g.height=e.height,g.renderTarget=p,g.depth=p.depthBuffer,g.stencil=p.stencilBuffer}else g.textures=null,g.depthTexture=null,g.width=VS.width,g.height=VS.height,g.depth=this.depth,g.stencil=this.stencil;g.width>>=h,g.height>>=h,g.activeCubeFace=c,g.activeMipmapLevel=h,g.occlusionQueryCount=N.occlusionQueryCount,g.scissorValue.max(WS.set(0,0,0,0)),g.scissorValue.x+g.scissorValue.width>g.width&&(g.scissorValue.width=Math.max(g.width-g.scissorValue.x,0)),g.scissorValue.y+g.scissorValue.height>g.height&&(g.scissorValue.height=Math.max(g.height-g.scissorValue.y,0)),this._background.update(l,N,g),g.camera=t,this.backend.beginRender(g);const{bundles:S,lightsNode:R,transparentDoublePass:E,transparent:A,opaque:w}=N;return S.length>0&&this._renderBundles(S,l,R),!0===this.opaque&&w.length>0&&this._renderObjects(w,t,l,R),!0===this.transparent&&A.length>0&&this._renderTransparents(A,E,t,l,R),this.backend.finishRender(g),i.renderId=n,this._currentRenderContext=a,this._currentRenderObjectFunction=o,this._handleObjectFunction=u,this._callDepth--,null!==s&&(this.setRenderTarget(d,c,h),this._renderOutput(p)),l.onAfterRender(this,e,t,p),this.inspector.finishRender(this.backend.getTimestampUID(g)),g}_setXRLayerSize(e,t){this._canvasTarget._width=e,this._canvasTarget._height=t,this.setViewport(0,0,e,t)}_renderOutput(e){const t=this._quad;this._nodes.hasOutputChange(e.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(e.texture),t.material.needsUpdate=!0);const r=this.autoClear,s=this.xr.enabled;this.autoClear=!1,this.xr.enabled=!1,this._renderScene(t,t.camera,!1),this.autoClear=r,this.xr.enabled=s}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}getAnimationLoop(){return this._animation.getAnimationLoop()}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._canvasTarget.getPixelRatio()}getDrawingBufferSize(e){return this._canvasTarget.getDrawingBufferSize(e)}getSize(e){return this._canvasTarget.getSize(e)}setPixelRatio(e=1){this._canvasTarget.setPixelRatio(e)}setDrawingBufferSize(e,t,r){this.xr&&this.xr.isPresenting||this._canvasTarget.setDrawingBufferSize(e,t,r)}setSize(e,t,r=!0){this.xr&&this.xr.isPresenting||this._canvasTarget.setSize(e,t,r)}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){return this._canvasTarget.getScissor(e)}setScissor(e,t,r,s){this._canvasTarget.setScissor(e,t,r,s)}getScissorTest(){return this._canvasTarget.getScissorTest()}setScissorTest(e){this._canvasTarget.setScissorTest(e),this.backend.setScissorTest(e)}getViewport(e){return this._canvasTarget.getViewport(e)}setViewport(e,t,r,s,i=0,n=1){this._canvasTarget.setViewport(e,t,r,s,i,n)}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return!0===this.reversedDepthBuffer?1-this._clearDepth:this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,r=!0){if(!1===this._initialized)throw new Error('Renderer: .clear() called before the backend is initialized. Use "await renderer.init();" before before using this method.');const s=this._renderTarget||this._getFrameBufferTarget();let i=null;if(null!==s){this._textures.updateRenderTarget(s);const e=this._textures.get(s);i=this._renderContexts.get(s),i.textures=e.textures,i.depthTexture=e.depthTexture,i.width=e.width,i.height=e.height,i.renderTarget=s,i.depth=s.depthBuffer,i.stencil=s.stencilBuffer;const t=this.backend.getClearColor();i.clearColorValue.r=t.r,i.clearColorValue.g=t.g,i.clearColorValue.b=t.b,i.clearColorValue.a=t.a,i.clearDepthValue=this.getClearDepth(),i.clearStencilValue=this.getClearStencil(),i.activeCubeFace=this.getActiveCubeFace(),i.activeMipmapLevel=this.getActiveMipmapLevel()}this.backend.clear(e,t,r,i),null!==s&&null===this._renderTarget&&this._renderOutput(s)}clearColor(){this.clear(!0,!1,!1)}clearDepth(){this.clear(!1,!0,!1)}clearStencil(){this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,r=!0){v('Renderer: "clearAsync()" has been deprecated. Use "clear()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.clear(e,t,r)}async clearColorAsync(){v('Renderer: "clearColorAsync()" has been deprecated. Use "clearColor()" and "await renderer.init();" when creating the renderer.'),this.clear(!0,!1,!1)}async clearDepthAsync(){v('Renderer: "clearDepthAsync()" has been deprecated. Use "clearDepth()" and "await renderer.init();" when creating the renderer.'),this.clear(!1,!0,!1)}async clearStencilAsync(){v('Renderer: "clearStencilAsync()" has been deprecated. Use "clearStencil()" and "await renderer.init();" when creating the renderer.'),this.clear(!1,!1,!0)}get needsFrameBufferTarget(){const e=this.currentToneMapping!==m,t=this.currentColorSpace!==p.workingColorSpace;return e||t}get samples(){return this._samples}get currentSamples(){let e=this._samples;return null!==this._renderTarget?e=this._renderTarget.samples:this.needsFrameBufferTarget&&(e=0),e}get currentToneMapping(){return this.isOutputTarget?this.toneMapping:m}get currentColorSpace(){return this.isOutputTarget?this.outputColorSpace:p.workingColorSpace}get isOutputTarget(){return this._renderTarget===this._outputRenderTarget||null===this._renderTarget}dispose(){!0===this._initialized&&(this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._geometries.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),null!==this._frameBufferTarget&&this._frameBufferTarget.dispose(),Object.values(this.backend.timestampQueryPool).forEach(e=>{null!==e&&e.dispose()})),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,r=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=r}getRenderTarget(){return this._renderTarget}setOutputRenderTarget(e){this._outputRenderTarget=e}getOutputRenderTarget(){return this._outputRenderTarget}setCanvasTarget(e){this._canvasTarget.removeEventListener("resize",this._onCanvasTargetResize),this._canvasTarget=e,this._canvasTarget.addEventListener("resize",this._onCanvasTargetResize)}getCanvasTarget(){return this._canvasTarget}_resetXRState(){this.backend.setXRTarget(null),this.setOutputRenderTarget(null),this.setRenderTarget(null),this._frameBufferTarget.dispose(),this._frameBufferTarget=null}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e,t=null){if(!0===this._isDeviceLost)return;if(!1===this._initialized)return d("Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e,t);const r=this._nodes.nodeFrame,s=r.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,r.renderId=this.info.calls,this.backend.updateTimeStampUID(e),this.inspector.beginCompute(this.backend.getTimestampUID(e),e);const i=this.backend,n=this._pipelines,a=this._bindings,o=this._nodes,u=Array.isArray(e)?e:[e];if(void 0===u[0]||!0!==u[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");i.beginCompute(e);for(const r of u){if(!1===n.has(r)){const e=()=>{r.removeEventListener("dispose",e),n.delete(r),a.deleteForCompute(r),o.delete(r)};r.addEventListener("dispose",e);const t=r.onInitFunction;null!==t&&t.call(r,{renderer:this})}o.updateForCompute(r),a.updateForCompute(r);const s=a.getForCompute(r),u=n.getForCompute(r,s);i.compute(e,r,s,u,t)}i.finishCompute(e),r.renderId=s,this.inspector.finishCompute(this.backend.getTimestampUID(e))}async computeAsync(e,t=null){!1===this._initialized&&await this.init(),this.compute(e,t)}async hasFeatureAsync(e){return v('Renderer: "hasFeatureAsync()" has been deprecated. Use "hasFeature()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.hasFeature(e)}async resolveTimestampsAsync(e="render"){return!1===this._initialized&&await this.init(),this.backend.resolveTimestampsAsync(e)}hasFeature(e){if(!1===this._initialized)throw new Error('Renderer: .hasFeature() called before the backend is initialized. Use "await renderer.init();" before before using this method.');return this.backend.hasFeature(e)}hasInitialized(){return this._initialized}async initTextureAsync(e){v('Renderer: "initTextureAsync()" has been deprecated. Use "initTexture()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.initTexture(e)}initTexture(e){if(!1===this._initialized)throw new Error('Renderer: .initTexture() called before the backend is initialized. Use "await renderer.init();" before before using this method.');this._textures.updateTexture(e)}initRenderTarget(e){if(!1===this._initialized)throw new Error('Renderer: .initRenderTarget() called before the backend is initialized. Use "await renderer.init();" before before using this method.');this._textures.updateRenderTarget(e);const t=this._textures.get(e),r=this._renderContexts.get(e);r.textures=t.textures,r.depthTexture=t.depthTexture,r.width=t.width,r.height=t.height,r.renderTarget=e,r.depth=e.depthBuffer,r.stencil=e.stencilBuffer,this.backend.initRenderTarget(r)}copyFramebufferToTexture(e,t=null){if(null!==t)if(t.isVector2)t=WS.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void o("Renderer.copyFramebufferToTexture: Invalid rectangle.");t=WS.copy(t).floor()}else t=WS.set(0,0,e.image.width,e.image.height);let r,s=this._currentRenderContext;null!==s?r=s.renderTarget:(r=this._renderTarget||this._getFrameBufferTarget(),null!==r&&(this._textures.updateRenderTarget(r),s=this._textures.get(r))),this._textures.updateTexture(e,{renderTarget:r}),this.backend.copyFramebufferToTexture(e,s,t),this._inspector.copyFramebufferToTexture(e)}copyTextureToTexture(e,t,r=null,s=null,i=0,n=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,r,s,i,n),this._inspector.copyTextureToTexture(e,t)}async readRenderTargetPixelsAsync(e,t,r,s,i,n=0,a=0){return this.backend.copyTextureToBuffer(e.textures[n],t,r,s,i,a)}_projectObject(e,t,r,s,i){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)r=e.renderOrder,e.isClippingGroup&&e.enabled&&(i=i.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)s.pushLight(e);else if(e.isSprite){const n=t.isArrayCamera?$S:GS;if(!e.frustumCulled||n.intersectsSprite(e,t)){!0===this.sortObjects&&WS.setFromMatrixPosition(e.matrixWorld).applyMatrix4(zS);const{geometry:t,material:n}=e;n.visible&&s.push(e,t,n,r,WS.z,null,i)}}else if(e.isLineLoop)o("Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if(e.isMesh||e.isLine||e.isPoints){const n=t.isArrayCamera?$S:GS;if(!e.frustumCulled||n.intersectsObject(e,t)){const{geometry:t,material:n}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),WS.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(zS)),Array.isArray(n)){const a=t.groups;for(let o=0,u=a.length;o<u;o++){const u=a[o],l=n[u.materialIndex];l&&l.visible&&s.push(e,t,l,r,WS.z,u,i)}}else n.visible&&s.push(e,t,n,r,WS.z,null,i)}}if(!0===e.isBundleGroup&&void 0!==this.backend.beginBundle){const r=s;(s=this._renderLists.get(e,t)).begin(),r.pushBundle({bundleGroup:e,camera:t,renderList:s}),s.finish()}const n=e.children;for(let e=0,a=n.length;e<a;e++)this._projectObject(n[e],t,r,s,i)}_renderBundles(e,t,r){for(const s of e)this._renderBundle(s,t,r)}_renderTransparents(e,t,r,s,i){if(t.length>0){for(const{material:e}of t)e.side=L;this._renderObjects(t,r,s,i,"backSide");for(const{material:e}of t)e.side=ct;this._renderObjects(e,r,s,i);for(const{material:e}of t)e.side=P}else this._renderObjects(e,r,s,i)}_renderObjects(e,t,r,s,i=null){for(let n=0,a=e.length;n<a;n++){const{object:a,geometry:o,material:u,group:l,clippingContext:d}=e[n];this._currentRenderObjectFunction(a,r,t,o,u,l,s,d,i)}}_getShadowNodes(e){const t=e.version;let r=this._cacheShadowNodes.get(e);if(void 0===r||r.version!==t){const s=null!==e.map,i=e.colorNode&&e.colorNode.isNode,n=e.castShadowNode&&e.castShadowNode.isNode,a=e.maskShadowNode&&e.maskShadowNode.isNode||e.maskNode&&e.maskNode.isNode;let o=null,u=null,l=null;if(s||i||n||a){let t,r;if(n?(t=e.castShadowNode.rgb,r=e.castShadowNode.a,!0!==this.shadowMap.transmitted&&v("Renderer: `shadowMap.transmitted` needs to be set to `true` when using `material.castShadowNode`.")):(t=Nn(0),r=mn(1)),s&&(r=r.mul(Lc("map","texture",e).a)),i&&(r=r.mul(e.colorNode.a)),u=An(t,r),a){const t=e.maskShadowNode||e.maskNode;u=ln(([e])=>(t.not().discard(),e))(u)}}e.depthNode&&e.depthNode.isNode&&(l=e.depthNode),e.castShadowPositionNode&&e.castShadowPositionNode.isNode?o=e.castShadowPositionNode:e.positionNode&&e.positionNode.isNode&&(o=e.positionNode),r={version:t,colorNode:u,depthNode:l,positionNode:o},this._cacheShadowNodes.set(e,r)}return r}renderObject(e,t,r,s,i,n,a,o=null,u=null){let l,d,c,h,p=!1;if(e.onBeforeRender(this,t,r,s,i,n),i.onBeforeRender(this,t,r,s,i,n),!0===i.allowOverride&&null!==t.overrideMaterial){const e=t.overrideMaterial;if(p=!0,l=e.isNodeMaterial?e.colorNode:null,d=e.isNodeMaterial?e.depthNode:null,c=e.isNodeMaterial?e.positionNode:null,h=t.overrideMaterial.side,i.positionNode&&i.positionNode.isNode&&(e.positionNode=i.positionNode),e.alphaTest=i.alphaTest,e.alphaMap=i.alphaMap,e.transparent=i.transparent||i.transmission>0||i.transmissionNode&&i.transmissionNode.isNode||i.backdropNode&&i.backdropNode.isNode,e.isShadowPassMaterial){const{colorNode:t,depthNode:r,positionNode:s}=this._getShadowNodes(i);this.shadowMap.type===Je?e.side=null!==i.shadowSide?i.shadowSide:i.side:e.side=null!==i.shadowSide?i.shadowSide:HS[i.side],null!==t&&(e.colorNode=t),null!==r&&(e.depthNode=r),null!==s&&(e.positionNode=s)}i=e}!0===i.transparent&&i.side===P&&!1===i.forceSinglePass?(i.side=L,this._handleObjectFunction(e,i,t,r,a,n,o,"backSide"),i.side=ct,this._handleObjectFunction(e,i,t,r,a,n,o,u),i.side=P):this._handleObjectFunction(e,i,t,r,a,n,o,u),p&&(t.overrideMaterial.colorNode=l,t.overrideMaterial.depthNode=d,t.overrideMaterial.positionNode=c,t.overrideMaterial.side=h),e.onAfterRender(this,t,r,s,i,n)}hasCompatibility(e){return this.backend.hasCompatibility(e)}_renderObjectDirect(e,t,r,s,i,n,a,o){const u=this._objects.get(e,t,r,s,i,this._currentRenderContext,a,o);if(u.drawRange=e.geometry.drawRange,u.group=n,null!==this._currentRenderBundle){this.backend.get(this._currentRenderBundle).renderObjects.push(u),u.bundle=this._currentRenderBundle.bundleGroup}const l=this._nodes.needsRefresh(u);l&&(this._nodes.updateBefore(u),this._geometries.updateForRender(u),this._nodes.updateForRender(u),this._bindings.updateForRender(u)),this._pipelines.updateForRender(u),this.backend.draw(u,this.info),l&&this._nodes.updateAfter(u)}_createObjectPipeline(e,t,r,s,i,n,a,o){const u=this._objects.get(e,t,r,s,i,this._currentRenderContext,a,o);u.drawRange=e.geometry.drawRange,u.group=n,this._nodes.updateBefore(u),this._geometries.updateForRender(u),this._nodes.updateForRender(u),this._bindings.updateForRender(u),this._pipelines.getForRender(u,this._compilationPromises),this._nodes.updateAfter(u)}_onCanvasTargetResize(){this._initialized&&this.backend.updateSize()}get compile(){return this.compileAsync}}class jS{constructor(e=""){this.name=e,this.visibility=0}setVisibility(e){this.visibility|=e}getVisibility(){return this.visibility}clone(){return Object.assign(new this.constructor,this)}}class XS extends jS{constructor(e,t=null){super(e),this.isBuffer=!0,this.bytesPerElement=Float32Array.BYTES_PER_ELEMENT,this._buffer=t,this._updateRanges=[]}get updateRanges(){return this._updateRanges}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}get byteLength(){return(e=this._buffer.byteLength)+(Ry-e%Ry)%Ry;var e}get buffer(){return this._buffer}update(){return!0}}class KS extends XS{constructor(e,t=null){super(e,t),this.isUniformBuffer=!0}}let YS=0;class QS extends KS{constructor(e,t){super("UniformBuffer_"+YS++,e?e.value:null),this.nodeUniform=e,this.groupNode=t,this.isNodeUniformBuffer=!0}set updateRanges(e){this.nodeUniform.updateRanges=e}get updateRanges(){return this.nodeUniform.updateRanges}addUpdateRange(e,t){this.nodeUniform.addUpdateRange(e,t)}clearUpdateRanges(){this.nodeUniform.clearUpdateRanges()}get buffer(){return this.nodeUniform.value}}class ZS extends KS{constructor(e){super(e),this.isUniformsGroup=!0,this._values=null,this.uniforms=[],this._updateRangeCache=new Map}addUniformUpdateRange(e){const t=e.index;if(!0!==this._updateRangeCache.has(t)){const r=this.updateRanges,s={start:e.offset,count:e.itemSize};r.push(s),this._updateRangeCache.set(t,s)}}clearUpdateRanges(){this._updateRangeCache.clear(),super.clearUpdateRanges()}addUniform(e){return this.uniforms.push(e),this}removeUniform(e){const t=this.uniforms.indexOf(e);return-1!==t&&this.uniforms.splice(t,1),this}get values(){return null===this._values&&(this._values=Array.from(this.buffer)),this._values}get buffer(){let e=this._buffer;if(null===e){const t=this.byteLength;e=new Float32Array(new ArrayBuffer(t)),this._buffer=e}return e}get byteLength(){const e=this.bytesPerElement;let t=0;for(let r=0,s=this.uniforms.length;r<s;r++){const s=this.uniforms[r],i=s.boundary,n=s.itemSize*e,a=t%Ry,o=a%i,u=a+o;t+=o,0!==u&&Ry-u<n&&(t+=Ry-u),s.offset=t/e,s.index=r,t+=n}return Math.ceil(t/Ry)*Ry}update(){let e=!1;for(const t of this.uniforms)!0===this.updateByType(t)&&(e=!0);return e}updateByType(e){return e.isNumberUniform?this.updateNumber(e):e.isVector2Uniform?this.updateVector2(e):e.isVector3Uniform?this.updateVector3(e):e.isVector4Uniform?this.updateVector4(e):e.isColorUniform?this.updateColor(e):e.isMatrix3Uniform?this.updateMatrix3(e):e.isMatrix4Uniform?this.updateMatrix4(e):void o("WebGPUUniformsGroup: Unsupported uniform type.",e)}updateNumber(e){let t=!1;const r=this.values,s=e.getValue(),i=e.offset,n=e.getType();if(r[i]!==s){this._getBufferForType(n)[i]=r[i]=s,t=!0,this.addUniformUpdateRange(e)}return t}updateVector2(e){let t=!1;const r=this.values,s=e.getValue(),i=e.offset,n=e.getType();if(r[i+0]!==s.x||r[i+1]!==s.y){const a=this._getBufferForType(n);a[i+0]=r[i+0]=s.x,a[i+1]=r[i+1]=s.y,t=!0,this.addUniformUpdateRange(e)}return t}updateVector3(e){let t=!1;const r=this.values,s=e.getValue(),i=e.offset,n=e.getType();if(r[i+0]!==s.x||r[i+1]!==s.y||r[i+2]!==s.z){const a=this._getBufferForType(n);a[i+0]=r[i+0]=s.x,a[i+1]=r[i+1]=s.y,a[i+2]=r[i+2]=s.z,t=!0,this.addUniformUpdateRange(e)}return t}updateVector4(e){let t=!1;const r=this.values,s=e.getValue(),i=e.offset,n=e.getType();if(r[i+0]!==s.x||r[i+1]!==s.y||r[i+2]!==s.z||r[i+4]!==s.w){const a=this._getBufferForType(n);a[i+0]=r[i+0]=s.x,a[i+1]=r[i+1]=s.y,a[i+2]=r[i+2]=s.z,a[i+3]=r[i+3]=s.w,t=!0,this.addUniformUpdateRange(e)}return t}updateColor(e){let t=!1;const r=this.values,s=e.getValue(),i=e.offset;if(r[i+0]!==s.r||r[i+1]!==s.g||r[i+2]!==s.b){const n=this.buffer;n[i+0]=r[i+0]=s.r,n[i+1]=r[i+1]=s.g,n[i+2]=r[i+2]=s.b,t=!0,this.addUniformUpdateRange(e)}return t}updateMatrix3(e){let t=!1;const r=this.values,s=e.getValue().elements,i=e.offset;if(r[i+0]!==s[0]||r[i+1]!==s[1]||r[i+2]!==s[2]||r[i+4]!==s[3]||r[i+5]!==s[4]||r[i+6]!==s[5]||r[i+8]!==s[6]||r[i+9]!==s[7]||r[i+10]!==s[8]){const n=this.buffer;n[i+0]=r[i+0]=s[0],n[i+1]=r[i+1]=s[1],n[i+2]=r[i+2]=s[2],n[i+4]=r[i+4]=s[3],n[i+5]=r[i+5]=s[4],n[i+6]=r[i+6]=s[5],n[i+8]=r[i+8]=s[6],n[i+9]=r[i+9]=s[7],n[i+10]=r[i+10]=s[8],t=!0,this.addUniformUpdateRange(e)}return t}updateMatrix4(e){let t=!1;const r=this.values,s=e.getValue().elements,i=e.offset;if(!1===function(e,t,r){for(let s=0,i=t.length;s<i;s++)if(e[r+s]!==t[s])return!1;return!0}(r,s,i)){this.buffer.set(s,i),function(e,t,r){for(let s=0,i=t.length;s<i;s++)e[r+s]=t[s]}(r,s,i),t=!0,this.addUniformUpdateRange(e)}return t}_getBufferForType(e){return"int"===e||"ivec2"===e||"ivec3"===e||"ivec4"===e?new Int32Array(this.buffer.buffer):"uint"===e||"uvec2"===e||"uvec3"===e||"uvec4"===e?new Uint32Array(this.buffer.buffer):this.buffer}}let JS=0;class eR extends ZS{constructor(e,t){super(e),this.id=JS++,this.groupNode=t,this.isNodeUniformsGroup=!0}}class tR extends jS{constructor(e,t){super(e),this._texture=null,this._onTextureDispose=()=>{this.generation=null,this.version=-1},this.texture=t,this.version=t?t.version:-1,this.generation=null,this.samplerKey="",this.isSampler=!0}set texture(e){this._texture!==e&&(this._texture&&this._texture.removeEventListener("dispose",this._onTextureDispose),this._texture=e,this.generation=null,this.version=-1,this._texture&&this._texture.addEventListener("dispose",this._onTextureDispose))}get texture(){return this._texture}update(){const{texture:e,version:t}=this;return t!==e.version&&(this.version=e.version,!0)}clone(){const e=super.clone();return e._texture=null,e._onTextureDispose=()=>{e.generation=null,e.version=-1},e.texture=this.texture,e}}let rR=0;class sR extends tR{constructor(e,t){super(e,t),this.id=rR++,this.store=!1,this.mipLevel=0,this.isSampledTexture=!0}}class iR extends sR{constructor(e,t,r,s=null){super(e,t?t.value:null),this.textureNode=t,this.groupNode=r,this.access=s}update(){const{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}}class nR extends iR{constructor(e,t,r,s=null){super(e,t,r,s),this.isSampledCubeTexture=!0}}class aR extends iR{constructor(e,t,r,s=null){super(e,t,r,s),this.isSampledTexture3D=!0}}const oR={bitcast_int_uint:new hT("uint tsl_bitcast_int_to_uint ( int x ) { return floatBitsToUint( intBitsToFloat ( x ) ); }"),bitcast_uint_int:new hT("uint tsl_bitcast_uint_to_int ( uint x ) { return floatBitsToInt( uintBitsToFloat ( x ) ); }")},uR={textureDimensions:"textureSize",equals:"equal",bitcast_float_int:"floatBitsToInt",bitcast_int_float:"intBitsToFloat",bitcast_uint_float:"uintBitsToFloat",bitcast_float_uint:"floatBitsToUint",bitcast_uint_int:"tsl_bitcast_uint_to_int",bitcast_int_uint:"tsl_bitcast_int_to_uint",floatpack_snorm_2x16:"packSnorm2x16",floatpack_unorm_2x16:"packUnorm2x16",floatpack_float16_2x16:"packHalf2x16",floatunpack_snorm_2x16:"unpackSnorm2x16",floatunpack_unorm_2x16:"unpackUnorm2x16",floatunpack_float16_2x16:"unpackHalf2x16"},lR={low:"lowp",medium:"mediump",high:"highp"},dR={swizzleAssign:!0,storageBuffer:!1},cR={perspective:"smooth",linear:"noperspective"},hR={centroid:"centroid"},pR="\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\nprecision highp sampler3D;\nprecision highp samplerCube;\nprecision highp sampler2DArray;\n\nprecision highp usampler2D;\nprecision highp usampler3D;\nprecision highp usamplerCube;\nprecision highp usampler2DArray;\n\nprecision highp isampler2D;\nprecision highp isampler3D;\nprecision highp isamplerCube;\nprecision highp isampler2DArray;\n\nprecision highp sampler2DShadow;\nprecision highp sampler2DArrayShadow;\nprecision highp samplerCubeShadow;\n";class gR extends qN{constructor(e,t){super(e,t,new pS),this.uniformGroups={},this.transforms=[],this.extensions={},this.builtins={vertex:[],fragment:[],compute:[]}}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==T}_include(e){const t=oR[e];return t.build(this),this.addInclude(t),t}getMethod(e){return void 0!==oR[e]&&this._include(e),uR[e]||e}getBitcastMethod(e,t){return this.getMethod(`bitcast_${t}_${e}`)}getFloatPackingMethod(e){return this.getMethod(`floatpack_${e}_2x16`)}getFloatUnpackingMethod(e){return this.getMethod(`floatunpack_${e}_2x16`)}getTernary(e,t,r){return`${e} ? ${t} : ${r}`}getOutputStructName(){return""}buildFunctionCode(e){const t=e.layout,r=this.flowShaderNode(e),s=[];for(const e of t.inputs)s.push(this.getType(e.type)+" "+e.name);return`${this.getType(t.type)} ${t.name}( ${s.join(", ")} ) {\n\n\t${r.vars}\n\n${r.code}\n\treturn ${r.result};\n\n}`}setupPBO(e){const t=e.value;if(void 0===t.pbo){const e=t.array,r=t.count*t.itemSize,{itemSize:s}=t,i=t.array.constructor.name.toLowerCase().includes("int");let n=i?Tt:_t;2===s?n=i?Rt:W:3===s?n=i?Et:At:4===s&&(n=i?wt:Ae);const a={Float32Array:Y,Uint8Array:$e,Uint16Array:St,Uint32Array:S,Int8Array:Nt,Int16Array:vt,Int32Array:R,Uint8ClampedArray:$e},o=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(r/s))));let u=Math.ceil(r/s/o);o*u*s<r&&u++;const l=o*u*s,d=new e.constructor(l);d.set(e,0),t.array=d;const c=new Te(t.array,o,u,n,a[t.array.constructor.name]||Y);c.needsUpdate=!0,c.isPBOTexture=!0;const h=new Ll(c,null,null);h.setPrecision("high"),t.pboNode=h,t.pbo=h.value,this.getUniformFromNode(t.pboNode,"texture",this.shaderStage,this.context.nodeName)}}getPropertyName(e,t=this.shaderStage){return e.isNodeUniform&&!0!==e.node.isTextureNode&&!0!==e.node.isBufferNode?e.name:super.getPropertyName(e,t)}generatePBO(e){const{node:t,indexNode:r}=e,s=t.value;if(this.renderer.backend.has(s)){this.renderer.backend.get(s).pbo=s.pbo}const i=this.getUniformFromNode(s.pboNode,"texture",this.shaderStage,this.context.nodeName),n=this.getPropertyName(i);this.increaseUsage(r);const a=r.build(this,"uint"),o=this.getDataFromNode(e);let u=o.propertyName;if(void 0===u){const r=this.getVarFromNode(e);u=this.getPropertyName(r);const i=this.getDataFromNode(t);let l=i.propertySizeName;void 0===l&&(l=u+"Size",this.getVarFromNode(t,l,"uint"),this.addLineFlowCode(`${l} = uint( textureSize( ${n}, 0 ).x )`,e),i.propertySizeName=l);const{itemSize:d}=s,c="."+ai.join("").slice(0,d),h=`ivec2(${a} % ${l}, ${a} / ${l})`,p=this.generateTextureLoad(null,n,h,"0",null,null);let g="vec4";s.pbo.type===S?g="uvec4":s.pbo.type===R&&(g="ivec4"),this.addLineFlowCode(`${u} = ${g}(${p})${c}`,e),o.propertyName=u}return u}generateTextureLoad(e,t,r,s,i,n){let a;return null===s&&(s="0"),a=i?n?`texelFetchOffset( ${t}, ivec3( ${r}, ${i} ), ${s}, ${n} )`:`texelFetch( ${t}, ivec3( ${r}, ${i} ), ${s} )`:n?`texelFetchOffset( ${t}, ${r}, ${s}, ${n} )`:`texelFetch( ${t}, ${r}, ${s} )`,null!==e&&e.isDepthTexture&&(a+=".x"),a}generateTexture(e,t,r,s,i){return s&&(r=`vec3( ${r}, ${s} )`),e.isDepthTexture?i?`textureOffset( ${t}, ${r}, ${i} ).x`:`texture( ${t}, ${r} ).x`:i?`textureOffset( ${t}, ${r}, ${i} )`:`texture( ${t}, ${r} )`}generateTextureLevel(e,t,r,s,i,n){return i&&(r=`vec3( ${r}, ${i} )`),n?`textureLodOffset( ${t}, ${r}, ${s}, ${n} )`:`textureLod( ${t}, ${r}, ${s} )`}generateTextureBias(e,t,r,s,i,n){return i&&(r=`vec3( ${r}, ${i} )`),n?`textureOffset( ${t}, ${r}, ${n}, ${s} )`:`texture( ${t}, ${r}, ${s} )`}generateTextureGrad(e,t,r,s,i,n){return i&&(r=`vec3( ${r}, ${i} )`),n?`textureGradOffset( ${t}, ${r}, ${s[0]}, ${s[1]}, ${n} )`:`textureGrad( ${t}, ${r}, ${s[0]}, ${s[1]} )`}generateTextureCompare(e,t,r,s,i,n,a=this.shaderStage){if("fragment"===a)return e.isCubeTexture?`texture( ${t}, vec4( ${r}, ${s} ) )`:i?n?`textureOffset( ${t}, vec4( ${r}, ${i}, ${s} ), ${n} )`:`texture( ${t}, vec4( ${r}, ${i}, ${s} ) )`:n?`textureOffset( ${t}, vec3( ${r}, ${s} ), ${n} )`:`texture( ${t}, vec3( ${r}, ${s} ) )`;o(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${a} shader.`)}getVars(e){const t=[],r=this.vars[e];if(void 0!==r)for(const e of r)t.push(`${this.getVar(e.type,e.name,e.count)};`);return t.join("\n\t")}getUniforms(e){const t=this.uniforms[e],r=[],s={};for(const e of t){let t=null,i=!1;if("texture"===e.type||"texture3D"===e.type){const r=e.node.value;let s="";!0!==r.isDataTexture&&!0!==r.isData3DTexture||(r.type===S?s="u":r.type===R&&(s="i")),t="texture3D"===e.type&&!1===r.isArrayTexture?`${s}sampler3D ${e.name};`:r.compareFunction?!0===r.isArrayTexture?`sampler2DArrayShadow ${e.name};`:`sampler2DShadow ${e.name};`:!0===r.isArrayTexture||!0===r.isDataArrayTexture||!0===r.isCompressedArrayTexture?`${s}sampler2DArray ${e.name};`:`${s}sampler2D ${e.name};`}else if("cubeTexture"===e.type)t=`samplerCube ${e.name};`;else if("cubeDepthTexture"===e.type){t=e.node.value.compareFunction?`samplerCubeShadow ${e.name};`:`samplerCube ${e.name};`}else if("buffer"===e.type){const r=e.node,s=this.getType(r.bufferType),i=r.bufferCount,n=i>0?i:"";t=`${r.name} {\n\t${s} ${e.name}[${n}];\n};\n`}else{const t=e.groupNode.name;if(void 0===s[t]){const e=this.uniformGroups[t];if(void 0!==e){const r=[];for(const t of e.uniforms){const e=t.getType(),s=this.getVectorType(e),i=t.nodeUniform.node.precision;let n=`${s} ${t.name};`;null!==i&&(n=lR[i]+" "+n),r.push("\t"+n)}s[t]=r}}i=!0}if(!i){const s=e.node.precision;null!==s&&(t=lR[s]+" "+t),t="uniform "+t,r.push(t)}}let i="";for(const e in s){const t=s[e];i+=this._getGLSLUniformStruct(e,t.join("\n"))+"\n"}return i+=r.join("\n"),i}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==R){let r=e;e.isInterleavedBufferAttribute&&(r=e.data);const s=r.array;!1==(s instanceof Uint32Array||s instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){const e=this.getAttributesArray();let r=0;for(const s of e)t+=`layout( location = ${r++} ) in ${s.type} ${s.name};\n`}return t}getStructMembers(e){const t=[];for(const r of e.members)t.push(`\t${r.type} ${r.name};`);return t.join("\n")}getStructs(e){const t=[],r=this.structs[e],s=[];for(const e of r)if(e.output)for(const t of e.members)s.push(`layout( location = ${t.index} ) out ${t.type} ${t.name};`);else{let r="struct "+e.name+" {\n";r+=this.getStructMembers(e),r+="\n};\n",t.push(r)}return 0===s.length&&s.push("layout( location = 0 ) out vec4 fragColor;"),"\n"+s.join("\n")+"\n\n"+t.join("\n")}getVaryings(e){let t="";const r=this.varyings;if("vertex"===e||"compute"===e)for(const s of r){"compute"===e&&(s.needsInterpolation=!0);const r=this.getType(s.type);if(s.needsInterpolation)if(s.interpolationType){t+=`${cR[s.interpolationType]||s.interpolationType} ${hR[s.interpolationSampling]||""} out ${r} ${s.name};\n`}else{t+=`${r.includes("int")||r.includes("uv")||r.includes("iv")?"flat ":""}out ${r} ${s.name};\n`}else t+=`${r} ${s.name};\n`}else if("fragment"===e)for(const e of r)if(e.needsInterpolation){const r=this.getType(e.type);if(e.interpolationType){t+=`${cR[e.interpolationType]||e.interpolationType} ${hR[e.interpolationSampling]||""} in ${r} ${e.name};\n`}else{t+=`${r.includes("int")||r.includes("uv")||r.includes("iv")?"flat ":""}in ${r} ${e.name};\n`}}for(const r of this.builtins[e])t+=`${r};\n`;return t}getVertexIndex(){return"uint( gl_VertexID )"}getInstanceIndex(){return"uint( gl_InstanceID )"}getInvocationLocalIndex(){return`uint( gl_InstanceID ) % ${this.object.workgroupSize.reduce((e,t)=>e*t,1)}u`}getSubgroupSize(){o("GLSLNodeBuilder: WebGLBackend does not support the subgroupSize node")}getInvocationSubgroupIndex(){o("GLSLNodeBuilder: WebGLBackend does not support the invocationSubgroupIndex node")}getSubgroupIndex(){o("GLSLNodeBuilder: WebGLBackend does not support the subgroupIndex node")}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,r=this.shaderStage){const s=this.extensions[r]||(this.extensions[r]=new Map);!1===s.has(e)&&s.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if("vertex"===e){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const r=this.extensions[e];if(void 0!==r)for(const{name:e,behavior:s}of r.values())t.push(`#extension ${e} : ${s}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=dR[e];if(void 0===t){let r;switch(t=!1,e){case"float32Filterable":r="OES_texture_float_linear";break;case"clipDistance":r="WEBGL_clip_cull_distance"}if(void 0!==r){const e=this.renderer.backend.extensions;e.has(r)&&(e.get(r),t=!0)}dR[e]=t}return t}isFlipY(){return!0}getUniformBufferLimit(){const e=this.renderer.backend.gl;return e.getParameter(e.MAX_UNIFORM_BLOCK_SIZE)}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}enableMultiview(){this.enableExtension("GL_OVR_multiview2","require","fragment"),this.enableExtension("GL_OVR_multiview2","require","vertex"),this.builtins.vertex.push("layout(num_views = 2) in")}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){const e=this.transforms;let t="";for(let r=0;r<e.length;r++){const s=e[r],i=this.getPropertyName(s.attributeNode);i&&(t+=`${s.varyingName} = ${i};\n\t`)}return t}_getGLSLUniformStruct(e,t){return`\nlayout( std140 ) uniform ${e} {\n${t}\n};`}_getGLSLVertexCode(e){return`#version 300 es\n\n${this.getSignature()}\n\n// extensions\n${e.extensions}\n\n// precision\n${pR}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\n\n// attributes\n${e.attributes}\n\n// codes\n${e.codes}\n\nvoid main() {\n\n\t// vars\n\t${e.vars}\n\n\t// transforms\n\t${e.transforms}\n\n\t// flow\n\t${e.flow}\n\n\tgl_PointSize = 1.0;\n\n}\n`}_getGLSLFragmentCode(e){return`#version 300 es\n\n${this.getSignature()}\n\n// extensions\n${e.extensions}\n\n// precision\n${pR}\n\n// structs\n${e.structs}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\n\n// codes\n${e.codes}\n\nvoid main() {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){let r="// code\n\n";r+=this.flowCode[t];const s=this.flowNodes[t],i=s[s.length-1];for(const e of s){const s=this.getFlowData(e),n=e.name;n&&(r.length>0&&(r+="\n"),r+=`\t// flow -> ${n}\n\t`),r+=`${s.code}\n\t`,e===i&&"compute"!==t&&(r+="// result\n\t","vertex"===t?(r+="gl_Position = ",r+=`${s.result};`):"fragment"===t&&(e.outputNode.isOutputStructNode||(r+="fragColor = ",r+=`${s.result};`)))}const n=e[t];n.extensions=this.getExtensions(t),n.uniforms=this.getUniforms(t),n.attributes=this.getAttributes(t),n.varyings=this.getVaryings(t),n.vars=this.getVars(t),n.structs=this.getStructs(t),n.codes=this.getCodes(t),n.transforms=this.getTransforms(t),n.flow=r}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,r,s=null){const i=super.getUniformFromNode(e,t,r,s),n=this.getDataFromNode(e,r,this.globalCache);let a=n.uniformGPU;if(void 0===a){const s=e.groupNode,o=s.name,u=this.getBindGroupArray(o,r);if("texture"===t)a=new iR(i.name,i.node,s),u.push(a);else if("cubeTexture"===t||"cubeDepthTexture"===t)a=new nR(i.name,i.node,s),u.push(a);else if("texture3D"===t)a=new aR(i.name,i.node,s),u.push(a);else if("buffer"===t){i.name=`buffer${e.id}`;const t=this.getSharedDataFromNode(e);let r=t.buffer;void 0===r&&(e.name=`NodeBuffer_${e.id}`,r=new QS(e,s),r.name=e.name,t.buffer=r),u.push(r),a=r}else{let e=this.uniformGroups[o];void 0===e?(e=new eR(o,s),this.uniformGroups[o]=e,u.push(e)):-1===u.indexOf(e)&&u.push(e),a=this.getNodeUniform(i,t);const r=a.name;e.uniforms.some(e=>e.name===r)||e.addUniform(a)}n.uniformGPU=a}return i}}let mR=null,fR=null;class yR{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null,this.timestampQueryPool={[Ct.RENDER]:null,[Ct.COMPUTE]:null},this.trackTimestamp=!0===e.trackTimestamp}async init(e){this.renderer=e}get coordinateSystem(){}beginRender(){}finishRender(){}beginCompute(){}finishCompute(){}draw(){}compute(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}updateBinding(){}createRenderPipeline(){}createComputePipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}updateSampler(){}createDefaultTexture(){}createTexture(){}updateTexture(){}generateMipmaps(){}destroyTexture(){}async copyTextureToBuffer(){}copyTextureToTexture(){}copyFramebufferToTexture(){}createAttribute(){}createIndexAttribute(){}createStorageAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}updateViewport(){}updateTimeStampUID(e){const t=this.get(e),r=this.renderer.info.frame;let s;s=!0===e.isComputeNode?"c:"+this.renderer.info.compute.frameCalls:"r:"+this.renderer.info.render.frameCalls,t.timestampUID=s+":"+e.id+":f"+r}getTimestampUID(e){return this.get(e).timestampUID}getTimestampFrames(e){const t=this.timestampQueryPool[e];return t?t.getTimestampFrames():[]}_getQueryPool(e){const t=e.startsWith("c:")?Ct.COMPUTE:Ct.RENDER;return this.timestampQueryPool[t]}getTimestamp(e){return this._getQueryPool(e).getTimestamp(e)}hasTimestamp(e){return this._getQueryPool(e).hasTimestamp(e)}isOccluded(){}async resolveTimestampsAsync(e="render"){if(!this.trackTimestamp)return void v("WebGPURenderer: Timestamp tracking is disabled.");const t=this.timestampQueryPool[e];if(!t)return;const r=await t.resolveQueriesAsync();return this.renderer.info[e].timestamp=r,r}async getArrayBufferAsync(){}async hasFeatureAsync(){}hasFeature(){}getMaxAnisotropy(){}getDrawingBufferSize(){return mR=mR||new t,this.renderer.getDrawingBufferSize(mR)}setScissorTest(){}getClearColor(){const e=this.renderer;return fR=fR||new Qy,e.getClearColor(fR),fR.getRGB(fR),fR}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:Mt(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${ut} webgpu`),this.domElement=e),e}hasCompatibility(){return!1}initRenderTarget(){}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}deleteBindGroupData(){}dispose(){}}let bR,xR,TR=0;class _R{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.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 vR{constructor(e){this.backend=e}createAttribute(e,t){const r=this.backend,{gl:s}=r,i=e.array,n=e.usage||s.STATIC_DRAW,a=e.isInterleavedBufferAttribute?e.data:e,o=r.get(a);let u,l=o.bufferGPU;if(void 0===l&&(l=this._createBuffer(s,t,i,n),o.bufferGPU=l,o.bufferType=t,o.version=a.version),i instanceof Float32Array)u=s.FLOAT;else if("undefined"!=typeof Float16Array&&i instanceof Float16Array)u=s.HALF_FLOAT;else if(i instanceof Uint16Array)u=e.isFloat16BufferAttribute?s.HALF_FLOAT:s.UNSIGNED_SHORT;else if(i instanceof Int16Array)u=s.SHORT;else if(i instanceof Uint32Array)u=s.UNSIGNED_INT;else if(i instanceof Int32Array)u=s.INT;else if(i instanceof Int8Array)u=s.BYTE;else if(i instanceof Uint8Array)u=s.UNSIGNED_BYTE;else{if(!(i instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+i);u=s.UNSIGNED_BYTE}let d={bufferGPU:l,bufferType:t,type:u,byteLength:i.byteLength,bytesPerElement:i.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===s.INT||u===s.UNSIGNED_INT||e.gpuType===R,id:TR++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const e=this._createBuffer(s,t,i,n);d=new _R(d,e)}r.set(e,d)}updateAttribute(e){const t=this.backend,{gl:r}=t,s=e.array,i=e.isInterleavedBufferAttribute?e.data:e,n=t.get(i),a=n.bufferType,o=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(r.bindBuffer(a,n.bufferGPU),0===o.length)r.bufferSubData(a,0,s);else{for(let e=0,t=o.length;e<t;e++){const t=o[e];r.bufferSubData(a,t.start*s.BYTES_PER_ELEMENT,s,t.start,t.count)}i.clearUpdateRanges()}r.bindBuffer(a,null),n.version=i.version}destroyAttribute(e){const t=this.backend,{gl:r}=t;e.isInterleavedBufferAttribute&&t.delete(e.data);const s=t.get(e);r.deleteBuffer(s.bufferGPU),t.delete(e)}async getArrayBufferAsync(e){const t=this.backend,{gl:r}=t,s=e.isInterleavedBufferAttribute?e.data:e,{bufferGPU:i}=t.get(s),n=e.array,a=n.byteLength;r.bindBuffer(r.COPY_READ_BUFFER,i);const o=r.createBuffer();r.bindBuffer(r.COPY_WRITE_BUFFER,o),r.bufferData(r.COPY_WRITE_BUFFER,a,r.STREAM_READ),r.copyBufferSubData(r.COPY_READ_BUFFER,r.COPY_WRITE_BUFFER,0,0,a),await t.utils._clientWaitAsync();const u=new e.array.constructor(n.length);return r.bindBuffer(r.COPY_WRITE_BUFFER,o),r.getBufferSubData(r.COPY_WRITE_BUFFER,0,u),r.deleteBuffer(o),r.bindBuffer(r.COPY_READ_BUFFER,null),r.bindBuffer(r.COPY_WRITE_BUFFER,null),u.buffer}_createBuffer(e,t,r,s){const i=e.createBuffer();return e.bindBuffer(t,i),e.bufferData(t,r,s),e.bindBuffer(t,null),i}}class NR{constructor(e){this.backend=e,this.gl=this.backend.gl,this.enabled={},this.currentFlipSided=null,this.currentCullFace=null,this.currentProgram=null,this.currentBlendingEnabled=!1,this.currentBlending=null,this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentPremultipledAlpha=null,this.currentPolygonOffsetFactor=null,this.currentPolygonOffsetUnits=null,this.currentColorMask=null,this.currentDepthReversed=!1,this.currentDepthFunc=null,this.currentDepthMask=null,this.currentStencilFunc=null,this.currentStencilRef=null,this.currentStencilFuncMask=null,this.currentStencilFail=null,this.currentStencilZFail=null,this.currentStencilZPass=null,this.currentStencilMask=null,this.currentLineWidth=null,this.currentClippingPlanes=0,this.currentVAO=null,this.currentIndex=null,this.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.currentTextureSlot=null,this.currentBoundTextures={},this.currentBoundBufferBases={},this._init()}_init(){const e=this.gl;bR={[qe]:e.FUNC_ADD,[Ft]:e.FUNC_SUBTRACT,[Bt]:e.FUNC_REVERSE_SUBTRACT},xR={[pt]:e.ZERO,[kt]:e.ONE,[Vt]:e.SRC_COLOR,[We]:e.SRC_ALPHA,[Ot]:e.SRC_ALPHA_SATURATE,[It]:e.DST_COLOR,[Ut]:e.DST_ALPHA,[Dt]:e.ONE_MINUS_SRC_COLOR,[He]:e.ONE_MINUS_SRC_ALPHA,[Pt]:e.ONE_MINUS_DST_COLOR,[Lt]:e.ONE_MINUS_DST_ALPHA};const t=e.getParameter(e.SCISSOR_BOX),r=e.getParameter(e.VIEWPORT);this.currentScissor=(new s).fromArray(t),this.currentViewport=(new s).fromArray(r),this._tempVec4=new s}enable(e){const{enabled:t}=this;!0!==t[e]&&(this.gl.enable(e),t[e]=!0)}disable(e){const{enabled:t}=this;!1!==t[e]&&(this.gl.disable(e),t[e]=!1)}setFlipSided(e){if(this.currentFlipSided!==e){const{gl:t}=this;e?t.frontFace(t.CW):t.frontFace(t.CCW),this.currentFlipSided=e}}setCullFace(e){const{gl:t}=this;e!==Gt?(this.enable(t.CULL_FACE),e!==this.currentCullFace&&(e===$t?t.cullFace(t.BACK):e===zt?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):this.disable(t.CULL_FACE),this.currentCullFace=e}setLineWidth(e){const{currentLineWidth:t,gl:r}=this;e!==t&&(r.lineWidth(e),this.currentLineWidth=e)}setMRTBlending(e,t,r){const s=this.gl,i=this.backend.drawBuffersIndexedExt;if(i)for(let n=0;n<e.length;n++){const a=e[n];let o=null;if(null!==t){const e=t.getBlendMode(a.name);e.blending===je?o=r:e.blending!==se&&(o=e)}else o=r;null!==o?this._setMRTBlendingIndex(n,o):i.blendFuncSeparateiOES(n,s.ONE,s.ZERO,s.ONE,s.ZERO)}else v("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets.")}_setMRTBlendingIndex(e,t){const{gl:r}=this,s=this.backend.drawBuffersIndexedExt,i=t.blending,n=t.blendSrc,a=t.blendDst,o=t.blendEquation,u=t.premultipliedAlpha;if(i===ht){const r=null!==t.blendSrcAlpha?t.blendSrcAlpha:n,i=null!==t.blendDstAlpha?t.blendDstAlpha:a,u=null!==t.blendEquationAlpha?t.blendEquationAlpha:o;s.blendEquationSeparateiOES(e,bR[o],bR[u]),s.blendFuncSeparateiOES(e,xR[n],xR[a],xR[r],xR[i])}else if(s.blendEquationSeparateiOES(e,r.FUNC_ADD,r.FUNC_ADD),u)switch(i){case ze:s.blendFuncSeparateiOES(e,r.ONE,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case qt:s.blendFuncSeparateiOES(e,r.ONE,r.ONE,r.ONE,r.ONE);break;case Ht:s.blendFuncSeparateiOES(e,r.ZERO,r.ONE_MINUS_SRC_COLOR,r.ZERO,r.ONE);break;case Wt:s.blendFuncSeparateiOES(e,r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ZERO,r.ONE);break;default:s.blendFuncSeparateiOES(e,r.ONE,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA)}else switch(i){case ze:s.blendFuncSeparateiOES(e,r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case qt:s.blendFuncSeparateiOES(e,r.SRC_ALPHA,r.ONE,r.ONE,r.ONE);break;case Ht:s.blendFuncSeparateiOES(e,r.ZERO,r.ONE_MINUS_SRC_COLOR,r.ZERO,r.ONE);break;case Wt:s.blendFuncSeparateiOES(e,r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ZERO,r.ONE);break;default:s.blendFuncSeparateiOES(e,r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA)}}setBlending(e,t,r,s,i,n,a,u){const{gl:l}=this;if(e!==se){if(!1===this.currentBlendingEnabled&&(this.enable(l.BLEND),this.currentBlendingEnabled=!0),e===ht)i=i||t,n=n||r,a=a||s,t===this.currentBlendEquation&&i===this.currentBlendEquationAlpha||(l.blendEquationSeparate(bR[t],bR[i]),this.currentBlendEquation=t,this.currentBlendEquationAlpha=i),r===this.currentBlendSrc&&s===this.currentBlendDst&&n===this.currentBlendSrcAlpha&&a===this.currentBlendDstAlpha||(l.blendFuncSeparate(xR[r],xR[s],xR[n],xR[a]),this.currentBlendSrc=r,this.currentBlendDst=s,this.currentBlendSrcAlpha=n,this.currentBlendDstAlpha=a),this.currentBlending=e,this.currentPremultipledAlpha=!1;else if(e!==this.currentBlending||u!==this.currentPremultipledAlpha){if(this.currentBlendEquation===qe&&this.currentBlendEquationAlpha===qe||(l.blendEquation(l.FUNC_ADD),this.currentBlendEquation=qe,this.currentBlendEquationAlpha=qe),u)switch(e){case ze:l.blendFuncSeparate(l.ONE,l.ONE_MINUS_SRC_ALPHA,l.ONE,l.ONE_MINUS_SRC_ALPHA);break;case qt:l.blendFunc(l.ONE,l.ONE);break;case Ht:l.blendFuncSeparate(l.ZERO,l.ONE_MINUS_SRC_COLOR,l.ZERO,l.ONE);break;case Wt:l.blendFuncSeparate(l.DST_COLOR,l.ONE_MINUS_SRC_ALPHA,l.ZERO,l.ONE);break;default:o("WebGLState: Invalid blending: ",e)}else switch(e){case ze:l.blendFuncSeparate(l.SRC_ALPHA,l.ONE_MINUS_SRC_ALPHA,l.ONE,l.ONE_MINUS_SRC_ALPHA);break;case qt:l.blendFuncSeparate(l.SRC_ALPHA,l.ONE,l.ONE,l.ONE);break;case Ht:o("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case Wt:o("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:o("WebGLState: Invalid blending: ",e)}this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlending=e,this.currentPremultipledAlpha=u}}else!0===this.currentBlendingEnabled&&(this.disable(l.BLEND),this.currentBlendingEnabled=!1)}setColorMask(e){this.currentColorMask!==e&&(this.gl.colorMask(e,e,e,e),this.currentColorMask=e)}setDepthTest(e){const{gl:t}=this;e?this.enable(t.DEPTH_TEST):this.disable(t.DEPTH_TEST)}setReversedDepth(e){if(this.currentDepthReversed!==e){const t=this.backend.extensions.get("EXT_clip_control");e?t.clipControlEXT(t.LOWER_LEFT_EXT,t.ZERO_TO_ONE_EXT):t.clipControlEXT(t.LOWER_LEFT_EXT,t.NEGATIVE_ONE_TO_ONE_EXT),this.currentDepthReversed=e}}setDepthMask(e){this.currentDepthMask!==e&&(this.gl.depthMask(e),this.currentDepthMask=e)}setDepthFunc(e){if(this.currentDepthReversed&&(e=tr[e]),this.currentDepthFunc!==e){const{gl:t}=this;switch(e){case er:t.depthFunc(t.NEVER);break;case Jt:t.depthFunc(t.ALWAYS);break;case Zt:t.depthFunc(t.LESS);break;case Qt:t.depthFunc(t.LEQUAL);break;case Yt:t.depthFunc(t.EQUAL);break;case Kt:t.depthFunc(t.GEQUAL);break;case Xt:t.depthFunc(t.GREATER);break;case jt:t.depthFunc(t.NOTEQUAL);break;default:t.depthFunc(t.LEQUAL)}this.currentDepthFunc=e}}scissor(e,t,r,s){const i=this._tempVec4.set(e,t,r,s);if(!1===this.currentScissor.equals(i)){const{gl:e}=this;e.scissor(i.x,i.y,i.z,i.w),this.currentScissor.copy(i)}}viewport(e,t,r,s){const i=this._tempVec4.set(e,t,r,s);if(!1===this.currentViewport.equals(i)){const{gl:e}=this;e.viewport(i.x,i.y,i.z,i.w),this.currentViewport.copy(i)}}setScissorTest(e){const t=this.gl;e?this.enable(t.SCISSOR_TEST):this.disable(t.SCISSOR_TEST)}setStencilTest(e){const{gl:t}=this;e?this.enable(t.STENCIL_TEST):this.disable(t.STENCIL_TEST)}setStencilMask(e){this.currentStencilMask!==e&&(this.gl.stencilMask(e),this.currentStencilMask=e)}setStencilFunc(e,t,r){this.currentStencilFunc===e&&this.currentStencilRef===t&&this.currentStencilFuncMask===r||(this.gl.stencilFunc(e,t,r),this.currentStencilFunc=e,this.currentStencilRef=t,this.currentStencilFuncMask=r)}setStencilOp(e,t,r){this.currentStencilFail===e&&this.currentStencilZFail===t&&this.currentStencilZPass===r||(this.gl.stencilOp(e,t,r),this.currentStencilFail=e,this.currentStencilZFail=t,this.currentStencilZPass=r)}setMaterial(e,t,r){const{gl:s}=this;e.side===P?this.disable(s.CULL_FACE):this.enable(s.CULL_FACE);let i=e.side===L;t&&(i=!i),this.setFlipSided(i),e.blending===ze&&!1===e.transparent?this.setBlending(se):this.setBlending(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.premultipliedAlpha),this.setDepthFunc(e.depthFunc),this.setDepthTest(e.depthTest),this.setDepthMask(e.depthWrite),this.setColorMask(e.colorWrite);const n=e.stencilWrite;if(this.setStencilTest(n),n&&(this.setStencilMask(e.stencilWriteMask),this.setStencilFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),this.setStencilOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),this.setPolygonOffset(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),!0===e.alphaToCoverage&&this.backend.renderer.currentSamples>0?this.enable(s.SAMPLE_ALPHA_TO_COVERAGE):this.disable(s.SAMPLE_ALPHA_TO_COVERAGE),r>0&&this.currentClippingPlanes!==r){const e=12288;for(let t=0;t<8;t++)t<r?this.enable(e+t):this.disable(e+t)}}setPolygonOffset(e,t,r){const{gl:s}=this;e?(this.enable(s.POLYGON_OFFSET_FILL),this.currentPolygonOffsetFactor===t&&this.currentPolygonOffsetUnits===r||(s.polygonOffset(t,r),this.currentPolygonOffsetFactor=t,this.currentPolygonOffsetUnits=r)):this.disable(s.POLYGON_OFFSET_FILL)}useProgram(e){return this.currentProgram!==e&&(this.gl.useProgram(e),this.currentProgram=e,!0)}setVertexState(e,t=null){const r=this.gl;return(this.currentVAO!==e||this.currentIndex!==t)&&(r.bindVertexArray(e),null!==t&&r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,t),this.currentVAO=e,this.currentIndex=t,!0)}resetVertexState(){const e=this.gl;e.bindVertexArray(null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),this.currentVAO=null,this.currentIndex=null}bindFramebuffer(e,t){const{gl:r,currentBoundFramebuffers:s}=this;return s[e]!==t&&(r.bindFramebuffer(e,t),s[e]=t,e===r.DRAW_FRAMEBUFFER&&(s[r.FRAMEBUFFER]=t),e===r.FRAMEBUFFER&&(s[r.DRAW_FRAMEBUFFER]=t),!0)}drawBuffers(e,t){const{gl:r}=this;let s=[],i=!1;if(null!==e.textures){s=this.currentDrawbuffers.get(t),void 0===s&&(s=[],this.currentDrawbuffers.set(t,s));const n=e.textures;if(s.length!==n.length||s[0]!==r.COLOR_ATTACHMENT0){for(let e=0,t=n.length;e<t;e++)s[e]=r.COLOR_ATTACHMENT0+e;s.length=n.length,i=!0}}else s[0]!==r.BACK&&(s[0]=r.BACK,i=!0);i&&r.drawBuffers(s)}activeTexture(e){const{gl:t,currentTextureSlot:r,maxTextures:s}=this;void 0===e&&(e=t.TEXTURE0+s-1),r!==e&&(t.activeTexture(e),this.currentTextureSlot=e)}bindTexture(e,t,r){const{gl:s,currentTextureSlot:i,currentBoundTextures:n,maxTextures:a}=this;void 0===r&&(r=null===i?s.TEXTURE0+a-1:i);let o=n[r];void 0===o&&(o={type:void 0,texture:void 0},n[r]=o),o.type===e&&o.texture===t||(i!==r&&(s.activeTexture(r),this.currentTextureSlot=r),s.bindTexture(e,t),o.type=e,o.texture=t)}bindBufferBase(e,t,r){const{gl:s}=this,i=`${e}-${t}`;return this.currentBoundBufferBases[i]!==r&&(s.bindBufferBase(e,t,r),this.currentBoundBufferBases[i]=r,!0)}unbindTexture(){const{gl:e,currentTextureSlot:t,currentBoundTextures:r}=this,s=r[t];void 0!==s&&void 0!==s.type&&(e.bindTexture(s.type,null),s.type=void 0,s.texture=void 0)}}class SR{constructor(e){this.backend=e,this.gl=this.backend.gl,this.extensions=e.extensions}convert(e,t=T){const{gl:r,extensions:s}=this;let i;const n=p.getTransfer(t);if(e===$e)return r.UNSIGNED_BYTE;if(e===rr)return r.UNSIGNED_SHORT_4_4_4_4;if(e===sr)return r.UNSIGNED_SHORT_5_5_5_1;if(e===ir)return r.UNSIGNED_INT_5_9_9_9_REV;if(e===nr)return r.UNSIGNED_INT_10F_11F_11F_REV;if(e===Nt)return r.BYTE;if(e===vt)return r.SHORT;if(e===St)return r.UNSIGNED_SHORT;if(e===R)return r.INT;if(e===S)return r.UNSIGNED_INT;if(e===Y)return r.FLOAT;if(e===_e)return r.HALF_FLOAT;if(e===ar)return r.ALPHA;if(e===At)return r.RGB;if(e===Ae)return r.RGBA;if(e===ke)return r.DEPTH_COMPONENT;if(e===Ve)return r.DEPTH_STENCIL;if(e===_t)return r.RED;if(e===Tt)return r.RED_INTEGER;if(e===W)return r.RG;if(e===Rt)return r.RG_INTEGER;if(e===wt)return r.RGBA_INTEGER;if(e===or||e===ur||e===lr||e===dr)if(n===g){if(i=s.get("WEBGL_compressed_texture_s3tc_srgb"),null===i)return null;if(e===or)return i.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(e===ur)return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(e===lr)return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(e===dr)return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(i=s.get("WEBGL_compressed_texture_s3tc"),null===i)return null;if(e===or)return i.COMPRESSED_RGB_S3TC_DXT1_EXT;if(e===ur)return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(e===lr)return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(e===dr)return i.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(e===cr||e===hr||e===pr||e===gr){if(i=s.get("WEBGL_compressed_texture_pvrtc"),null===i)return null;if(e===cr)return i.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(e===hr)return i.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(e===pr)return i.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(e===gr)return i.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(e===mr||e===fr||e===yr||e===br||e===xr||e===q||e===Tr){if(i=s.get("WEBGL_compressed_texture_etc"),null===i)return null;if(e===mr||e===fr)return n===g?i.COMPRESSED_SRGB8_ETC2:i.COMPRESSED_RGB8_ETC2;if(e===yr)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:i.COMPRESSED_RGBA8_ETC2_EAC;if(e===br)return i.COMPRESSED_R11_EAC;if(e===xr)return i.COMPRESSED_SIGNED_R11_EAC;if(e===q)return i.COMPRESSED_RG11_EAC;if(e===Tr)return i.COMPRESSED_SIGNED_RG11_EAC}if(e===_r||e===vr||e===Nr||e===Sr||e===Rr||e===Er||e===Ar||e===wr||e===Cr||e===Mr||e===Br||e===Fr||e===Lr||e===Pr){if(i=s.get("WEBGL_compressed_texture_astc"),null===i)return null;if(e===_r)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:i.COMPRESSED_RGBA_ASTC_4x4_KHR;if(e===vr)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:i.COMPRESSED_RGBA_ASTC_5x4_KHR;if(e===Nr)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:i.COMPRESSED_RGBA_ASTC_5x5_KHR;if(e===Sr)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:i.COMPRESSED_RGBA_ASTC_6x5_KHR;if(e===Rr)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:i.COMPRESSED_RGBA_ASTC_6x6_KHR;if(e===Er)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:i.COMPRESSED_RGBA_ASTC_8x5_KHR;if(e===Ar)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:i.COMPRESSED_RGBA_ASTC_8x6_KHR;if(e===wr)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:i.COMPRESSED_RGBA_ASTC_8x8_KHR;if(e===Cr)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:i.COMPRESSED_RGBA_ASTC_10x5_KHR;if(e===Mr)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:i.COMPRESSED_RGBA_ASTC_10x6_KHR;if(e===Br)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:i.COMPRESSED_RGBA_ASTC_10x8_KHR;if(e===Fr)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:i.COMPRESSED_RGBA_ASTC_10x10_KHR;if(e===Lr)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:i.COMPRESSED_RGBA_ASTC_12x10_KHR;if(e===Pr)return n===g?i.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:i.COMPRESSED_RGBA_ASTC_12x12_KHR}if(e===Dr){if(i=s.get("EXT_texture_compression_bptc"),null===i)return null;if(e===Dr)return n===g?i.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:i.COMPRESSED_RGBA_BPTC_UNORM_EXT}if(e===Ur||e===Ir||e===H||e===Or){if(i=s.get("EXT_texture_compression_rgtc"),null===i)return null;if(e===Ur)return i.COMPRESSED_RED_RGTC1_EXT;if(e===Ir)return i.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(e===H)return i.COMPRESSED_RED_GREEN_RGTC2_EXT;if(e===Or)return i.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return e===Ge?r.UNSIGNED_INT_24_8:void 0!==r[e]?r[e]:null}_clientWaitAsync(){const{gl:e}=this,t=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),new Promise((r,s)=>{!function i(){const n=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(n===e.WAIT_FAILED)return e.deleteSync(t),void s();n!==e.TIMEOUT_EXPIRED?(e.deleteSync(t),r()):requestAnimationFrame(i)}()})}}let RR,ER,AR,wR=!1;class CR{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},this._srcFramebuffer=null,this._dstFramebuffer=null,!1===wR&&(this._init(),wR=!0)}_init(){const e=this.gl;RR={[kr]:e.REPEAT,[ve]:e.CLAMP_TO_EDGE,[Vr]:e.MIRRORED_REPEAT},ER={[B]:e.NEAREST,[Gr]:e.NEAREST_MIPMAP_NEAREST,[at]:e.NEAREST_MIPMAP_LINEAR,[de]:e.LINEAR,[nt]:e.LINEAR_MIPMAP_NEAREST,[Z]:e.LINEAR_MIPMAP_LINEAR},AR={[Hr]:e.NEVER,[Wr]:e.ALWAYS,[A]:e.LESS,[w]:e.LEQUAL,[zr]:e.EQUAL,[M]:e.GEQUAL,[C]:e.GREATER,[$r]:e.NOTEQUAL}}getGLTextureType(e){const{gl:t}=this;let r;return r=!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isArrayTexture||!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D,r}getInternalFormat(e,t,r,s,i=!1){const{gl:n,extensions:a}=this;if(null!==e){if(void 0!==n[e])return n[e];d("WebGLBackend: Attempt to use non-existing WebGL internal format '"+e+"'")}let o=t;if(t===n.RED&&(r===n.FLOAT&&(o=n.R32F),r===n.HALF_FLOAT&&(o=n.R16F),r===n.UNSIGNED_BYTE&&(o=n.R8),r===n.UNSIGNED_SHORT&&(o=n.R16),r===n.UNSIGNED_INT&&(o=n.R32UI),r===n.BYTE&&(o=n.R8I),r===n.SHORT&&(o=n.R16I),r===n.INT&&(o=n.R32I)),t===n.RED_INTEGER&&(r===n.UNSIGNED_BYTE&&(o=n.R8UI),r===n.UNSIGNED_SHORT&&(o=n.R16UI),r===n.UNSIGNED_INT&&(o=n.R32UI),r===n.BYTE&&(o=n.R8I),r===n.SHORT&&(o=n.R16I),r===n.INT&&(o=n.R32I)),t===n.RG&&(r===n.FLOAT&&(o=n.RG32F),r===n.HALF_FLOAT&&(o=n.RG16F),r===n.UNSIGNED_BYTE&&(o=n.RG8),r===n.UNSIGNED_SHORT&&(o=n.RG16),r===n.UNSIGNED_INT&&(o=n.RG32UI),r===n.BYTE&&(o=n.RG8I),r===n.SHORT&&(o=n.RG16I),r===n.INT&&(o=n.RG32I)),t===n.RG_INTEGER&&(r===n.UNSIGNED_BYTE&&(o=n.RG8UI),r===n.UNSIGNED_SHORT&&(o=n.RG16UI),r===n.UNSIGNED_INT&&(o=n.RG32UI),r===n.BYTE&&(o=n.RG8I),r===n.SHORT&&(o=n.RG16I),r===n.INT&&(o=n.RG32I)),t===n.RGB){const e=i?qr:p.getTransfer(s);r===n.FLOAT&&(o=n.RGB32F),r===n.HALF_FLOAT&&(o=n.RGB16F),r===n.UNSIGNED_BYTE&&(o=n.RGB8),r===n.UNSIGNED_SHORT&&(o=n.RGB16),r===n.UNSIGNED_INT&&(o=n.RGB32UI),r===n.BYTE&&(o=n.RGB8I),r===n.SHORT&&(o=n.RGB16I),r===n.INT&&(o=n.RGB32I),r===n.UNSIGNED_BYTE&&(o=e===g?n.SRGB8:n.RGB8),r===n.UNSIGNED_SHORT_5_6_5&&(o=n.RGB565),r===n.UNSIGNED_SHORT_5_5_5_1&&(o=n.RGB5_A1),r===n.UNSIGNED_SHORT_4_4_4_4&&(o=n.RGB4),r===n.UNSIGNED_INT_5_9_9_9_REV&&(o=n.RGB9_E5),r===n.UNSIGNED_INT_10F_11F_11F_REV&&(o=n.R11F_G11F_B10F)}if(t===n.RGB_INTEGER&&(r===n.UNSIGNED_BYTE&&(o=n.RGB8UI),r===n.UNSIGNED_SHORT&&(o=n.RGB16UI),r===n.UNSIGNED_INT&&(o=n.RGB32UI),r===n.BYTE&&(o=n.RGB8I),r===n.SHORT&&(o=n.RGB16I),r===n.INT&&(o=n.RGB32I)),t===n.RGBA){const e=i?qr:p.getTransfer(s);r===n.FLOAT&&(o=n.RGBA32F),r===n.HALF_FLOAT&&(o=n.RGBA16F),r===n.UNSIGNED_BYTE&&(o=n.RGBA8),r===n.UNSIGNED_SHORT&&(o=n.RGBA16),r===n.UNSIGNED_INT&&(o=n.RGBA32UI),r===n.BYTE&&(o=n.RGBA8I),r===n.SHORT&&(o=n.RGBA16I),r===n.INT&&(o=n.RGBA32I),r===n.UNSIGNED_BYTE&&(o=e===g?n.SRGB8_ALPHA8:n.RGBA8),r===n.UNSIGNED_SHORT_4_4_4_4&&(o=n.RGBA4),r===n.UNSIGNED_SHORT_5_5_5_1&&(o=n.RGB5_A1)}return t===n.RGBA_INTEGER&&(r===n.UNSIGNED_BYTE&&(o=n.RGBA8UI),r===n.UNSIGNED_SHORT&&(o=n.RGBA16UI),r===n.UNSIGNED_INT&&(o=n.RGBA32UI),r===n.BYTE&&(o=n.RGBA8I),r===n.SHORT&&(o=n.RGBA16I),r===n.INT&&(o=n.RGBA32I)),t===n.DEPTH_COMPONENT&&(r===n.UNSIGNED_SHORT&&(o=n.DEPTH_COMPONENT16),r===n.UNSIGNED_INT&&(o=n.DEPTH_COMPONENT24),r===n.FLOAT&&(o=n.DEPTH_COMPONENT32F)),t===n.DEPTH_STENCIL&&r===n.UNSIGNED_INT_24_8&&(o=n.DEPTH24_STENCIL8),o!==n.R16F&&o!==n.R32F&&o!==n.RG16F&&o!==n.RG32F&&o!==n.RGBA16F&&o!==n.RGBA32F||a.get("EXT_color_buffer_float"),o}setTextureParameters(e,t){const{gl:r,extensions:s,backend:i}=this,n=p.getPrimaries(p.workingColorSpace),a=t.colorSpace===T?null:p.getPrimaries(t.colorSpace),o=t.colorSpace===T||n===a?r.NONE:r.BROWSER_DEFAULT_WEBGL;r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,t.flipY),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),r.pixelStorei(r.UNPACK_ALIGNMENT,t.unpackAlignment),r.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,o),r.texParameteri(e,r.TEXTURE_WRAP_S,RR[t.wrapS]),r.texParameteri(e,r.TEXTURE_WRAP_T,RR[t.wrapT]),e!==r.TEXTURE_3D&&e!==r.TEXTURE_2D_ARRAY||t.isArrayTexture||r.texParameteri(e,r.TEXTURE_WRAP_R,RR[t.wrapR]),r.texParameteri(e,r.TEXTURE_MAG_FILTER,ER[t.magFilter]);const u=void 0!==t.mipmaps&&t.mipmaps.length>0,l=t.minFilter===de&&u?Z:t.minFilter;if(r.texParameteri(e,r.TEXTURE_MIN_FILTER,ER[l]),t.compareFunction&&(r.texParameteri(e,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(e,r.TEXTURE_COMPARE_FUNC,AR[t.compareFunction])),!0===s.has("EXT_texture_filter_anisotropic")){if(t.magFilter===B)return;if(t.minFilter!==at&&t.minFilter!==Z)return;if(t.type===Y&&!1===s.has("OES_texture_float_linear"))return;if(t.anisotropy>1){const n=s.get("EXT_texture_filter_anisotropic");r.texParameterf(e,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,i.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:r,defaultTextures:s}=this,i=this.getGLTextureType(e);let n=s[i];void 0===n&&(n=t.createTexture(),r.state.bindTexture(i,n),t.texParameteri(i,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(i,t.TEXTURE_MAG_FILTER,t.NEAREST),s[i]=n),r.set(e,{textureGPU:n,glTextureType:i})}createTexture(e,t){const{gl:r,backend:s}=this,{levels:i,width:n,height:a,depth:o}=t,u=s.utils.convert(e.format,e.colorSpace),l=s.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,u,l,e.colorSpace,e.isVideoTexture),c=r.createTexture(),h=this.getGLTextureType(e);s.state.bindTexture(h,c),this.setTextureParameters(h,e),e.isArrayTexture||e.isDataArrayTexture||e.isCompressedArrayTexture?r.texStorage3D(r.TEXTURE_2D_ARRAY,i,d,n,a,o):e.isData3DTexture?r.texStorage3D(r.TEXTURE_3D,i,d,n,a,o):e.isVideoTexture||r.texStorage2D(h,i,d,n,a),s.set(e,{textureGPU:c,glTextureType:h,glFormat:u,glType:l,glInternalFormat:d})}copyBufferToTexture(e,t){const{gl:r,backend:s}=this,{textureGPU:i,glTextureType:n,glFormat:a,glType:o}=s.get(t),{width:u,height:l}=t.source.data;r.bindBuffer(r.PIXEL_UNPACK_BUFFER,e),s.state.bindTexture(n,i),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.texSubImage2D(n,0,0,0,u,l,a,o,0),r.bindBuffer(r.PIXEL_UNPACK_BUFFER,null),s.state.unbindTexture()}updateTexture(e,t){const{gl:r}=this,{width:s,height:i}=t,{textureGPU:n,glTextureType:a,glFormat:o,glType:u,glInternalFormat:l}=this.backend.get(e);if(!e.isRenderTargetTexture&&void 0!==n)if(this.backend.state.bindTexture(a,n),this.setTextureParameters(a,e),e.isCompressedTexture){const s=e.mipmaps,i=t.image;for(let t=0;t<s.length;t++){const n=s[t];e.isCompressedArrayTexture?e.format!==r.RGBA?null!==o?r.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,t,0,0,0,n.width,n.height,i.depth,o,n.data):d("WebGLBackend: Attempt to load unsupported compressed texture format in .uploadTexture()"):r.texSubImage3D(r.TEXTURE_2D_ARRAY,t,0,0,0,n.width,n.height,i.depth,o,u,n.data):null!==o?r.compressedTexSubImage2D(r.TEXTURE_2D,t,0,0,n.width,n.height,o,n.data):d("WebGLBackend: Unsupported compressed texture format")}}else if(e.isCubeTexture){const n=t.images,a=e.mipmaps;for(let e=0;e<6;e++){const t=MR(n[e]);r.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,s,i,o,u,t);for(let t=0;t<a.length;t++){const s=MR(a[t].images[e]);r.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+e,t+1,0,0,s.width,s.height,o,u,s)}}}else if(e.isDataArrayTexture||e.isArrayTexture){const s=t.image;if(e.layerUpdates.size>0){const t=jr(s.width,s.height,e.format,e.type);for(const i of e.layerUpdates){const e=s.data.subarray(i*t/s.data.BYTES_PER_ELEMENT,(i+1)*t/s.data.BYTES_PER_ELEMENT);r.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,i,s.width,s.height,1,o,u,e)}e.clearLayerUpdates()}else r.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,0,s.width,s.height,s.depth,o,u,s.data)}else if(e.isData3DTexture){const e=t.image;r.texSubImage3D(r.TEXTURE_3D,0,0,0,0,e.width,e.height,e.depth,o,u,e.data)}else if(e.isVideoTexture)e.update(),r.texImage2D(a,0,l,o,u,t.image);else{const n=e.mipmaps;if(n.length>0)for(let e=0,t=n.length;e<t;e++){const t=n[e],s=MR(t);r.texSubImage2D(a,e,0,0,t.width,t.height,o,u,s)}else{const e=MR(t.image);r.texSubImage2D(a,0,0,0,s,i,o,u,e)}}}generateMipmaps(e){const{gl:t,backend:r}=this,{textureGPU:s,glTextureType:i}=r.get(e);r.state.bindTexture(i,s),t.generateMipmap(i)}deallocateRenderBuffers(e){const{gl:t,backend:r}=this;if(e){const s=r.get(e);if(s.renderBufferStorageSetup=void 0,s.framebuffers){for(const e in s.framebuffers)t.deleteFramebuffer(s.framebuffers[e]);delete s.framebuffers}if(s.depthRenderbuffer&&(t.deleteRenderbuffer(s.depthRenderbuffer),delete s.depthRenderbuffer),s.stencilRenderbuffer&&(t.deleteRenderbuffer(s.stencilRenderbuffer),delete s.stencilRenderbuffer),s.msaaFrameBuffer&&(t.deleteFramebuffer(s.msaaFrameBuffer),delete s.msaaFrameBuffer),s.msaaRenderbuffers){for(let e=0;e<s.msaaRenderbuffers.length;e++)t.deleteRenderbuffer(s.msaaRenderbuffers[e]);delete s.msaaRenderbuffers}}}destroyTexture(e,t=!1){const{gl:r,backend:s}=this,{textureGPU:i,renderTarget:n}=s.get(e);this.deallocateRenderBuffers(n),!1===t&&r.deleteTexture(i),s.delete(e)}copyTextureToTexture(e,t,r=null,s=null,i=0,n=0){const{gl:a,backend:o}=this,{state:u}=this.backend,{textureGPU:l,glTextureType:d,glType:c,glFormat:h}=o.get(t);let p,g,m,f,y,b,x,T,_;u.bindTexture(d,l);const v=e.isCompressedTexture?e.mipmaps[n]:e.image;if(null!==r)p=r.max.x-r.min.x,g=r.max.y-r.min.y,m=r.isBox3?r.max.z-r.min.z:1,f=r.min.x,y=r.min.y,b=r.isBox3?r.min.z:0;else{const t=Math.pow(2,-i);p=Math.floor(v.width*t),g=Math.floor(v.height*t),m=e.isDataArrayTexture||e.isArrayTexture?v.depth:e.isData3DTexture?Math.floor(v.depth*t):1,f=0,y=0,b=0}null!==s?(x=s.x,T=s.y,_=s.z):(x=0,T=0,_=0),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,t.flipY),a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),a.pixelStorei(a.UNPACK_ALIGNMENT,t.unpackAlignment);const N=a.getParameter(a.UNPACK_ROW_LENGTH),S=a.getParameter(a.UNPACK_IMAGE_HEIGHT),R=a.getParameter(a.UNPACK_SKIP_PIXELS),E=a.getParameter(a.UNPACK_SKIP_ROWS),A=a.getParameter(a.UNPACK_SKIP_IMAGES);a.pixelStorei(a.UNPACK_ROW_LENGTH,v.width),a.pixelStorei(a.UNPACK_IMAGE_HEIGHT,v.height),a.pixelStorei(a.UNPACK_SKIP_PIXELS,f),a.pixelStorei(a.UNPACK_SKIP_ROWS,y),a.pixelStorei(a.UNPACK_SKIP_IMAGES,b);const w=e.isDataArrayTexture||e.isData3DTexture||t.isArrayTexture,C=t.isDataArrayTexture||t.isData3DTexture||t.isArrayTexture;if(e.isDepthTexture){const r=o.get(e),s=o.get(t),d=o.get(r.renderTarget),c=o.get(s.renderTarget),h=d.framebuffers[r.cacheKey],v=c.framebuffers[s.cacheKey];u.bindFramebuffer(a.READ_FRAMEBUFFER,h),u.bindFramebuffer(a.DRAW_FRAMEBUFFER,v);for(let e=0;e<m;e++)w&&(a.framebufferTextureLayer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,r.textureGPU,i,b+e),a.framebufferTextureLayer(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,l,n,_+e)),a.blitFramebuffer(f,y,p,g,x,T,p,g,a.DEPTH_BUFFER_BIT,a.NEAREST);u.bindFramebuffer(a.READ_FRAMEBUFFER,null),u.bindFramebuffer(a.DRAW_FRAMEBUFFER,null)}else if(0!==i||e.isRenderTargetTexture||o.has(e)){const t=o.get(e);null===this._srcFramebuffer&&(this._srcFramebuffer=a.createFramebuffer()),null===this._dstFramebuffer&&(this._dstFramebuffer=a.createFramebuffer()),u.bindFramebuffer(a.READ_FRAMEBUFFER,this._srcFramebuffer),u.bindFramebuffer(a.DRAW_FRAMEBUFFER,this._dstFramebuffer);for(let e=0;e<m;e++)w?a.framebufferTextureLayer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,t.textureGPU,i,b+e):a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,t.textureGPU,i),C?a.framebufferTextureLayer(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,l,n,_+e):a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,l,n),0!==i?a.blitFramebuffer(f,y,p,g,x,T,p,g,a.COLOR_BUFFER_BIT,a.NEAREST):C?a.copyTexSubImage3D(d,n,x,T,_+e,f,y,p,g):a.copyTexSubImage2D(d,n,x,T,f,y,p,g);u.bindFramebuffer(a.READ_FRAMEBUFFER,null),u.bindFramebuffer(a.DRAW_FRAMEBUFFER,null)}else C?e.isDataTexture||e.isData3DTexture?a.texSubImage3D(d,n,x,T,_,p,g,m,h,c,v.data):t.isCompressedArrayTexture?a.compressedTexSubImage3D(d,n,x,T,_,p,g,m,h,v.data):a.texSubImage3D(d,n,x,T,_,p,g,m,h,c,v):e.isDataTexture?a.texSubImage2D(a.TEXTURE_2D,n,x,T,p,g,h,c,v.data):e.isCompressedTexture?a.compressedTexSubImage2D(a.TEXTURE_2D,n,x,T,v.width,v.height,h,v.data):a.texSubImage2D(a.TEXTURE_2D,n,x,T,p,g,h,c,v);a.pixelStorei(a.UNPACK_ROW_LENGTH,N),a.pixelStorei(a.UNPACK_IMAGE_HEIGHT,S),a.pixelStorei(a.UNPACK_SKIP_PIXELS,R),a.pixelStorei(a.UNPACK_SKIP_ROWS,E),a.pixelStorei(a.UNPACK_SKIP_IMAGES,A),0===n&&t.generateMipmaps&&a.generateMipmap(d),u.unbindTexture()}copyFramebufferToTexture(e,t,r){const{gl:s}=this,{state:i}=this.backend,{textureGPU:n}=this.backend.get(e),{x:a,y:o,z:u,w:l}=r,d=!0===e.isDepthTexture||t.renderTarget&&t.renderTarget.samples>0,c=t.renderTarget?t.renderTarget.height:this.backend.getDrawingBufferSize().y;if(d){const r=0!==a||0!==o;let d,h;if(!0===e.isDepthTexture?(d=s.DEPTH_BUFFER_BIT,h=s.DEPTH_ATTACHMENT,t.stencil&&(d|=s.STENCIL_BUFFER_BIT)):(d=s.COLOR_BUFFER_BIT,h=s.COLOR_ATTACHMENT0),r){const e=this.backend.get(t.renderTarget),r=e.framebuffers[t.getCacheKey()],h=e.msaaFrameBuffer;i.bindFramebuffer(s.DRAW_FRAMEBUFFER,r),i.bindFramebuffer(s.READ_FRAMEBUFFER,h);const p=c-o-l;s.blitFramebuffer(a,p,a+u,p+l,a,p,a+u,p+l,d,s.NEAREST),i.bindFramebuffer(s.READ_FRAMEBUFFER,r),i.bindTexture(s.TEXTURE_2D,n),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,a,p,u,l),i.unbindTexture()}else{const e=s.createFramebuffer();i.bindFramebuffer(s.DRAW_FRAMEBUFFER,e),s.framebufferTexture2D(s.DRAW_FRAMEBUFFER,h,s.TEXTURE_2D,n,0),s.blitFramebuffer(0,0,u,l,0,0,u,l,d,s.NEAREST),s.deleteFramebuffer(e)}}else i.bindTexture(s.TEXTURE_2D,n),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,a,c-l-o,u,l),i.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t,r,s=!1){const{gl:i}=this,n=t.renderTarget,{depthTexture:a,depthBuffer:o,stencilBuffer:u,width:l,height:d}=n;if(i.bindRenderbuffer(i.RENDERBUFFER,e),o&&!u){let t=i.DEPTH_COMPONENT24;if(!0===s){this.extensions.get("WEBGL_multisampled_render_to_texture").renderbufferStorageMultisampleEXT(i.RENDERBUFFER,n.samples,t,l,d)}else r>0?(a&&a.isDepthTexture&&a.type===i.FLOAT&&(t=i.DEPTH_COMPONENT32F),i.renderbufferStorageMultisample(i.RENDERBUFFER,r,t,l,d)):i.renderbufferStorage(i.RENDERBUFFER,t,l,d);i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,e)}else o&&u&&(r>0?i.renderbufferStorageMultisample(i.RENDERBUFFER,r,i.DEPTH24_STENCIL8,l,d):i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_STENCIL,l,d),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.RENDERBUFFER,e));i.bindRenderbuffer(i.RENDERBUFFER,null)}async copyTextureToBuffer(e,t,r,s,i,n){const{backend:a,gl:o}=this,{textureGPU:u,glFormat:l,glType:d}=this.backend.get(e),c=o.createFramebuffer();a.state.bindFramebuffer(o.READ_FRAMEBUFFER,c);const h=e.isCubeTexture?o.TEXTURE_CUBE_MAP_POSITIVE_X+n:o.TEXTURE_2D;o.framebufferTexture2D(o.READ_FRAMEBUFFER,o.COLOR_ATTACHMENT0,h,u,0);const p=this._getTypedArrayType(d),g=s*i*this._getBytesPerTexel(d,l),m=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,m),o.bufferData(o.PIXEL_PACK_BUFFER,g,o.STREAM_READ),o.readPixels(t,r,s,i,l,d,0),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),await a.utils._clientWaitAsync();const f=new p(g/p.BYTES_PER_ELEMENT);return o.bindBuffer(o.PIXEL_PACK_BUFFER,m),o.getBufferSubData(o.PIXEL_PACK_BUFFER,0,f),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),a.state.bindFramebuffer(o.READ_FRAMEBUFFER,null),o.deleteFramebuffer(c),f}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:r}=this;let s=0;return e===r.UNSIGNED_BYTE&&(s=1),e!==r.UNSIGNED_SHORT_4_4_4_4&&e!==r.UNSIGNED_SHORT_5_5_5_1&&e!==r.UNSIGNED_SHORT_5_6_5&&e!==r.UNSIGNED_SHORT&&e!==r.HALF_FLOAT||(s=2),e!==r.UNSIGNED_INT&&e!==r.FLOAT||(s=4),t===r.RGBA?4*s:t===r.RGB?3*s:t===r.ALPHA?s:void 0}dispose(){const{gl:e}=this;null!==this._srcFramebuffer&&e.deleteFramebuffer(this._srcFramebuffer),null!==this._dstFramebuffer&&e.deleteFramebuffer(this._dstFramebuffer)}}function MR(e){return e.isDataTexture?e.image.data:"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas?e:e.data}class BR{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class FR{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){const r=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(r.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const LR={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",WEBGL_compressed_texture_s3tc:"texture-compression-s3tc",EXT_texture_compression_bptc:"texture-compression-bc",EXT_disjoint_timer_query_webgl2:"timestamp-query",OVR_multiview2:"OVR_multiview2"};class PR{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:r,mode:s,object:i,type:n,info:a,index:o}=this;0!==o?r.drawElements(s,t,n,e):r.drawArrays(s,e,t),a.update(i,t,1)}renderInstances(e,t,r){const{gl:s,mode:i,type:n,index:a,object:o,info:u}=this;0!==r&&(0!==a?s.drawElementsInstanced(i,t,n,e,r):s.drawArraysInstanced(i,e,t,r),u.update(o,t,r))}renderMultiDraw(e,t,r){const{extensions:s,mode:i,object:n,info:a}=this;if(0===r)return;const o=s.get("WEBGL_multi_draw");if(null===o)for(let s=0;s<r;s++)this.render(e[s],t[s]);else{0!==this.index?o.multiDrawElementsWEBGL(i,t,0,this.type,e,0,r):o.multiDrawArraysWEBGL(i,e,0,t,0,r);let s=0;for(let e=0;e<r;e++)s+=t[e];a.update(n,s,1)}}renderMultiDrawInstances(e,t,r,s){const{extensions:i,mode:n,object:a,info:o}=this;if(0===r)return;const u=i.get("WEBGL_multi_draw");if(null===u)for(let i=0;i<r;i++)this.renderInstances(e[i],t[i],s[i]);else{0!==this.index?u.multiDrawElementsInstancedWEBGL(n,t,0,this.type,e,0,s,0,r):u.multiDrawArraysInstancedWEBGL(n,e,0,t,0,s,0,r);let i=0;for(let e=0;e<r;e++)i+=t[e]*s[e];o.update(a,i,1)}}}class DR{constructor(e=256){this.trackTimestamp=!0,this.maxQueries=e,this.currentQueryIndex=0,this.queryOffsets=new Map,this.isDisposed=!1,this.lastValue=0,this.frames=[],this.pendingResolve=!1,this.timestamps=new Map}getTimestampFrames(){return this.frames}getTimestamp(e){let t=this.timestamps.get(e);return void 0===t&&(d(`TimestampQueryPool: No timestamp available for uid ${e}.`),t=0),t}hasTimestamp(e){return this.timestamps.has(e)}allocateQueriesForContext(){}async resolveQueriesAsync(){}dispose(){}}class UR extends DR{constructor(e,t,r=2048){if(super(r),this.gl=e,this.type=t,this.ext=e.getExtension("EXT_disjoint_timer_query_webgl2")||e.getExtension("EXT_disjoint_timer_query"),!this.ext)return d("EXT_disjoint_timer_query not supported; timestamps will be disabled."),void(this.trackTimestamp=!1);this.queries=[];for(let t=0;t<this.maxQueries;t++)this.queries.push(e.createQuery());this.activeQuery=null,this.queryStates=new Map}allocateQueriesForContext(e){if(!this.trackTimestamp)return null;if(this.currentQueryIndex+2>this.maxQueries)return v(`WebGPUTimestampQueryPool [${this.type}]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${this.type.toUpperCase()} ).`),null;const t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryStates.set(t,"inactive"),this.queryOffsets.set(e,t),t}beginQuery(e){if(!this.trackTimestamp||this.isDisposed)return;const t=this.queryOffsets.get(e);if(null==t)return;if(null!==this.activeQuery)return;const r=this.queries[t];if(r)try{"inactive"===this.queryStates.get(t)&&(this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT,r),this.activeQuery=t,this.queryStates.set(t,"started"))}catch(e){o("Error in beginQuery:",e),this.activeQuery=null,this.queryStates.set(t,"inactive")}}endQuery(e){if(!this.trackTimestamp||this.isDisposed)return;const t=this.queryOffsets.get(e);if(null!=t&&this.activeQuery===t)try{this.gl.endQuery(this.ext.TIME_ELAPSED_EXT),this.queryStates.set(t,"ended"),this.activeQuery=null}catch(e){o("Error in endQuery:",e),this.queryStates.set(t,"inactive"),this.activeQuery=null}}async resolveQueriesAsync(){if(!this.trackTimestamp||this.pendingResolve)return this.lastValue;this.pendingResolve=!0;try{const e=new Map;for(const[t,r]of this.queryOffsets){if("ended"===this.queryStates.get(r)){const s=this.queries[r];e.set(t,this.resolveQuery(s))}}if(0===e.size)return this.lastValue;const t={},r=[];for(const[s,i]of e){const e=s.match(/^(.*):f(\d+)$/),n=parseInt(e[2]);!1===r.includes(n)&&r.push(n),void 0===t[n]&&(t[n]=0);const a=await i;this.timestamps.set(s,a),t[n]+=a}const s=t[r[r.length-1]];return this.lastValue=s,this.frames=r,this.currentQueryIndex=0,this.queryOffsets.clear(),this.queryStates.clear(),this.activeQuery=null,s}catch(e){return o("Error resolving queries:",e),this.lastValue}finally{this.pendingResolve=!1}}async resolveQuery(e){return new Promise(t=>{if(this.isDisposed)return void t(this.lastValue);let r,s=!1;const i=e=>{s||(s=!0,r&&(clearTimeout(r),r=null),t(e))},n=()=>{if(this.isDisposed)i(this.lastValue);else try{if(this.gl.getParameter(this.ext.GPU_DISJOINT_EXT))return void i(this.lastValue);if(!this.gl.getQueryParameter(e,this.gl.QUERY_RESULT_AVAILABLE))return void(r=setTimeout(n,1));const s=this.gl.getQueryParameter(e,this.gl.QUERY_RESULT);t(Number(s)/1e6)}catch(e){o("Error checking query:",e),t(this.lastValue)}};n()})}dispose(){if(!this.isDisposed&&(this.isDisposed=!0,this.trackTimestamp)){for(const e of this.queries)this.gl.deleteQuery(e);this.queries=[],this.queryStates.clear(),this.queryOffsets.clear(),this.lastValue=0,this.activeQuery=null}}}class IR extends yR{constructor(e={}){super(e),this.isWebGLBackend=!0,this.attributeUtils=null,this.extensions=null,this.capabilities=null,this.textureUtils=null,this.bufferRenderer=null,this.gl=null,this.state=null,this.utils=null,this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.disjoint=null,this.parallel=null,this._currentContext=null,this._knownBindings=new WeakSet,this._supportsInvalidateFramebuffer="undefined"!=typeof navigator&&/OculusBrowser/g.test(navigator.userAgent),this._xrFramebuffer=null}init(e){super.init(e);const t=this.parameters,r={antialias:e.currentSamples>0,alpha:!0,depth:e.depth,stencil:e.stencil},s=void 0!==t.context?t.context:e.domElement.getContext("webgl2",r);function i(t){t.preventDefault();const r={api:"WebGL",message:t.statusMessage||"Unknown reason",reason:null,originalEvent:t};e.onDeviceLost(r)}this._onContextLost=i,e.domElement.addEventListener("webglcontextlost",i,!1),this.gl=s,this.extensions=new BR(this),this.capabilities=new FR(this),this.attributeUtils=new vR(this),this.textureUtils=new CR(this),this.bufferRenderer=new PR(this),this.state=new NR(this),this.utils=new SR(this),this.extensions.get("EXT_color_buffer_float"),this.extensions.get("WEBGL_clip_cull_distance"),this.extensions.get("OES_texture_float_linear"),this.extensions.get("EXT_color_buffer_half_float"),this.extensions.get("WEBGL_multisampled_render_to_texture"),this.extensions.get("WEBGL_render_shared_exponent"),this.extensions.get("WEBGL_multi_draw"),this.extensions.get("OVR_multiview2"),this.extensions.get("EXT_clip_control"),this.disjoint=this.extensions.get("EXT_disjoint_timer_query_webgl2"),this.parallel=this.extensions.get("KHR_parallel_shader_compile"),this.drawBuffersIndexedExt=this.extensions.get("OES_draw_buffers_indexed"),!0===t.reversedDepthBuffer&&this.extensions.has("EXT_clip_control")&&this.state.setReversedDepth(!0)}get coordinateSystem(){return c}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}async makeXRCompatible(){!0!==this.gl.getContextAttributes().xrCompatible&&await this.gl.makeXRCompatible()}setXRTarget(e){this._xrFramebuffer=e}setXRRenderTargetTextures(e,t,r=null){const s=this.gl;if(this.set(e.texture,{textureGPU:t,glInternalFormat:s.RGBA8}),null!==r){const t=e.stencilBuffer?s.DEPTH24_STENCIL8:s.DEPTH_COMPONENT24;this.set(e.depthTexture,{textureGPU:r,glInternalFormat:t}),!0===this.extensions.has("WEBGL_multisampled_render_to_texture")&&!0===e._autoAllocateDepthBuffer&&!1===e.multiview&&d("WebGLBackend: Render-to-texture extension was disabled because an external texture was provided"),e._autoAllocateDepthBuffer=!1}}initTimestampQuery(e,t){if(!this.disjoint||!this.trackTimestamp)return;this.timestampQueryPool[e]||(this.timestampQueryPool[e]=new UR(this.gl,e,2048));const r=this.timestampQueryPool[e];null!==r.allocateQueriesForContext(t)&&r.beginQuery(t)}prepareTimestampBuffer(e,t){if(!this.disjoint||!this.trackTimestamp)return;this.timestampQueryPool[e].endQuery(t)}getContext(){return this.gl}beginRender(e){const{state:t}=this,r=this.get(e);if(e.viewport)this.updateViewport(e);else{const{width:e,height:r}=this.getDrawingBufferSize();t.viewport(0,0,e,r)}if(e.scissor)this.updateScissor(e);else{const{width:e,height:r}=this.getDrawingBufferSize();t.scissor(0,0,e,r)}this.initTimestampQuery(Ct.RENDER,this.getTimestampUID(e)),r.previousContext=this._currentContext,this._currentContext=e,this._setFramebuffer(e),this.clear(e.clearColor,e.clearDepth,e.clearStencil,e,!1);const s=e.occlusionQueryCount;s>0&&(r.currentOcclusionQueries=r.occlusionQueries,r.currentOcclusionQueryObjects=r.occlusionQueryObjects,r.lastOcclusionObject=null,r.occlusionQueries=new Array(s),r.occlusionQueryObjects=new Array(s),r.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:r}=this,s=this.get(e),i=s.previousContext;r.resetVertexState();const n=e.occlusionQueryCount;n>0&&(n>s.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const a=e.textures;if(null!==a)for(let e=0;e<a.length;e++){const t=a[e];t.generateMipmaps&&this.generateMipmaps(t)}if(this._currentContext=i,this._resolveRenderTarget(e),null!==i){if(this._setFramebuffer(i),i.viewport)this.updateViewport(i);else{const{width:e,height:t}=this.getDrawingBufferSize();r.viewport(0,0,e,t)}if(i.scissor)this.updateScissor(i);else{const{width:e,height:t}=this.getDrawingBufferSize();r.scissor(0,0,e,t)}}this.prepareTimestampBuffer(Ct.RENDER,this.getTimestampUID(e))}resolveOccludedAsync(e){const t=this.get(e),{currentOcclusionQueries:r,currentOcclusionQueryObjects:s}=t;if(r&&s){const e=new WeakSet,{gl:i}=this;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueries=null;const n=()=>{let a=0;for(let t=0;t<r.length;t++){const n=r[t];null!==n&&(i.getQueryParameter(n,i.QUERY_RESULT_AVAILABLE)&&(0===i.getQueryParameter(n,i.QUERY_RESULT)&&e.add(s[t]),r[t]=null,i.deleteQuery(n),a++))}a<r.length?requestAnimationFrame(n):t.occluded=e};n()}}isOccluded(e,t){const r=this.get(e);return r.occluded&&r.occluded.has(t)}updateViewport(e){const{state:t}=this,{x:r,y:s,width:i,height:n}=e.viewportValue;t.viewport(r,e.height-n-s,i,n)}updateScissor(e){const{state:t}=this,{x:r,y:s,width:i,height:n}=e.scissorValue;t.scissor(r,e.height-n-s,i,n)}setScissorTest(e){this.state.setScissorTest(e)}getClearColor(){const e=super.getClearColor();return e.r*=e.a,e.g*=e.a,e.b*=e.a,e}clear(e,t,r,s=null,i=!0,n=!0){const{gl:a,renderer:o}=this;if(null===s){s={textures:null,clearColorValue:this.getClearColor()}}let u=0;if(e&&(u|=a.COLOR_BUFFER_BIT),t&&(u|=a.DEPTH_BUFFER_BIT),r&&(u|=a.STENCIL_BUFFER_BIT),0!==u){let l;l=s.clearColorValue?s.clearColorValue:this.getClearColor();const d=o.getClearDepth(),c=o.getClearStencil();if(t&&this.state.setDepthMask(!0),null===s.textures)a.clearColor(l.r,l.g,l.b,l.a),a.clear(u);else{if(i&&this._setFramebuffer(s),e)for(let e=0;e<s.textures.length;e++)0===e?a.clearBufferfv(a.COLOR,e,[l.r,l.g,l.b,l.a]):a.clearBufferfv(a.COLOR,e,[0,0,0,1]);t&&r?a.clearBufferfi(a.DEPTH_STENCIL,0,d,c):t?a.clearBufferfv(a.DEPTH,0,[d]):r&&a.clearBufferiv(a.STENCIL,0,[c]),i&&n&&this._resolveRenderTarget(s)}}}beginCompute(e){const{state:t,gl:r}=this;t.bindFramebuffer(r.FRAMEBUFFER,null),this.initTimestampQuery(Ct.COMPUTE,this.getTimestampUID(e))}compute(e,t,r,s,i=null){const{state:n,gl:a}=this;!1===this.discard&&(n.enable(a.RASTERIZER_DISCARD),this.discard=!0);const{programGPU:o,transformBuffers:u,attributes:l}=this.get(s),d=this._getVaoKey(l),c=this.vaoCache[d];void 0===c?this.vaoCache[d]=this._createVao(l):n.setVertexState(c),n.useProgram(o),this._bindUniforms(r);const h=this._getTransformFeedback(u);a.bindTransformFeedback(a.TRANSFORM_FEEDBACK,h),a.beginTransformFeedback(a.POINTS),i=null!==i?i:t.count,Array.isArray(i)?(v("WebGLBackend.compute(): The count parameter must be a single number, not an array."),i=i[0]):i&&"object"==typeof i&&i.isIndirectStorageBufferAttribute&&(v("WebGLBackend.compute(): The count parameter must be a single number, not IndirectStorageBufferAttribute"),i=t.count),l[0].isStorageInstancedBufferAttribute?a.drawArraysInstanced(a.POINTS,0,1,i):a.drawArrays(a.POINTS,0,i),a.endTransformFeedback(),a.bindTransformFeedback(a.TRANSFORM_FEEDBACK,null);for(let e=0;e<u.length;e++){const t=u[e];t.pbo&&this.has(t.pbo)&&this.textureUtils.copyBufferToTexture(t.transformBuffer,t.pbo),t.switchBuffers()}}finishCompute(e){const{state:t,gl:r}=this;this.discard=!1,t.disable(r.RASTERIZER_DISCARD),this.prepareTimestampBuffer(Ct.COMPUTE,this.getTimestampUID(e)),this._currentContext&&this._setFramebuffer(this._currentContext)}_isRenderCameraDepthArray(e){return e.depthTexture&&e.depthTexture.isArrayTexture&&e.camera.isArrayCamera}draw(e){const{object:t,pipeline:r,material:s,context:i,hardwareClippingPlanes:n}=e,{programGPU:a}=this.get(r),{gl:o,state:u}=this,l=this.get(i),d=e.getDrawParameters();if(null===d)return;this._bindUniforms(e.getBindings());const c=t.isMesh&&t.matrixWorld.determinant()<0;u.setMaterial(s,c,n),null!==i.mrt&&null!==i.textures&&u.setMRTBlending(i.textures,i.mrt,s),u.useProgram(a);const h=e.getAttributes(),p=this.get(h);let g=p.vaoGPU;if(void 0===g){const e=this._getVaoKey(h);g=this.vaoCache[e],void 0===g&&(g=this._createVao(h),this.vaoCache[e]=g,p.vaoGPU=g)}const m=e.getIndex(),f=null!==m?this.get(m).bufferGPU:null;u.setVertexState(g,f);const y=l.lastOcclusionObject;if(y!==t&&void 0!==y){if(null!==y&&!0===y.occlusionTest&&(o.endQuery(o.ANY_SAMPLES_PASSED),l.occlusionQueryIndex++),!0===t.occlusionTest){const e=o.createQuery();o.beginQuery(o.ANY_SAMPLES_PASSED,e),l.occlusionQueries[l.occlusionQueryIndex]=e,l.occlusionQueryObjects[l.occlusionQueryIndex]=t}l.lastOcclusionObject=t}const b=this.bufferRenderer;t.isPoints?b.mode=o.POINTS:t.isLineSegments?b.mode=o.LINES:t.isLine?b.mode=o.LINE_STRIP:t.isLineLoop?b.mode=o.LINE_LOOP:!0===s.wireframe?(u.setLineWidth(s.wireframeLinewidth*this.renderer.getPixelRatio()),b.mode=o.LINES):b.mode=o.TRIANGLES;const{vertexCount:x,instanceCount:T}=d;let{firstVertex:_}=d;if(b.object=t,null!==m){_*=m.array.BYTES_PER_ELEMENT;const e=this.get(m);b.index=m.count,b.type=e.type}else b.index=0;const N=()=>{t.isBatchedMesh?null!==t._multiDrawInstances?(v("WebGLBackend: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection."),b.renderMultiDrawInstances(t._multiDrawStarts,t._multiDrawCounts,t._multiDrawCount,t._multiDrawInstances)):this.hasFeature("WEBGL_multi_draw")?b.renderMultiDraw(t._multiDrawStarts,t._multiDrawCounts,t._multiDrawCount):v("WebGLBackend: WEBGL_multi_draw not supported."):T>1?b.renderInstances(_,x,T):b.render(_,x)};if(!0===e.camera.isArrayCamera&&e.camera.cameras.length>0&&!1===e.camera.isMultiViewCamera){const r=this.get(e.camera),s=e.camera.cameras,i=e.getBindingGroup("cameraIndex").bindings[0];if(void 0===r.indexesGPU||r.indexesGPU.length!==s.length){const e=new Uint32Array([0,0,0,0]),t=[];for(let r=0,i=s.length;r<i;r++){const s=o.createBuffer();e[0]=r,o.bindBuffer(o.UNIFORM_BUFFER,s),o.bufferData(o.UNIFORM_BUFFER,e,o.STATIC_DRAW),t.push(s)}r.indexesGPU=t}const n=this.get(i),a=this.renderer.getPixelRatio(),l=this._currentContext.renderTarget,d=this._isRenderCameraDepthArray(this._currentContext),c=this._currentContext.activeCubeFace;if(d){const e=this.get(l.depthTexture);if(e.clearedRenderId!==this.renderer._nodes.nodeFrame.renderId){e.clearedRenderId=this.renderer._nodes.nodeFrame.renderId;const{stencilBuffer:t}=l;for(let e=0,r=s.length;e<r;e++)this.renderer._activeCubeFace=e,this._currentContext.activeCubeFace=e,this._setFramebuffer(this._currentContext),this.clear(!1,!0,t,this._currentContext,!1,!1);this.renderer._activeCubeFace=c,this._currentContext.activeCubeFace=c}}for(let i=0,l=s.length;i<l;i++){const l=s[i];if(t.layers.test(l.layers)){d&&(this.renderer._activeCubeFace=i,this._currentContext.activeCubeFace=i,this._setFramebuffer(this._currentContext));const t=l.viewport;if(void 0!==t){const r=t.x*a,s=t.y*a,i=t.width*a,n=t.height*a;u.viewport(Math.floor(r),Math.floor(e.context.height-n-s),Math.floor(i),Math.floor(n))}u.bindBufferBase(o.UNIFORM_BUFFER,n.index,r.indexesGPU[i]),N()}this._currentContext.activeCubeFace=c,this.renderer._activeCubeFace=c}}else N()}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e,t=!1){this.textureUtils.destroyTexture(e,t)}async copyTextureToBuffer(e,t,r,s,i,n){return this.textureUtils.copyTextureToBuffer(e,t,r,s,i,n)}updateSampler(){return""}createNodeBuilder(e,t){return new gR(e,t)}createProgram(e){const t=this.gl,{stage:r,code:s}=e,i="fragment"===r?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(i,s),t.compileShader(i),this.set(e,{shaderGPU:i})}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){const r=this.gl,s=e.pipeline,{fragmentProgram:i,vertexProgram:n}=s,a=r.createProgram(),o=this.get(i).shaderGPU,u=this.get(n).shaderGPU;if(r.attachShader(a,o),r.attachShader(a,u),r.linkProgram(a),this.set(s,{programGPU:a,fragmentShader:o,vertexShader:u}),null!==t&&this.parallel){const i=new Promise(t=>{const i=this.parallel,n=()=>{r.getProgramParameter(a,i.COMPLETION_STATUS_KHR)?(this._completeCompile(e,s),t()):requestAnimationFrame(n)};n()});return void t.push(i)}this._completeCompile(e,s)}_handleSource(e,t){const r=e.split("\n"),s=[],i=Math.max(t-6,0),n=Math.min(t+6,r.length);for(let e=i;e<n;e++){const i=e+1;s.push(`${i===t?">":" "} ${i}: ${r[e]}`)}return s.join("\n")}_getShaderErrors(e,t,r){const s=e.getShaderParameter(t,e.COMPILE_STATUS),i=(e.getShaderInfoLog(t)||"").trim();if(s&&""===i)return"";const n=/ERROR: 0:(\d+)/.exec(i);if(n){const s=parseInt(n[1]);return r.toUpperCase()+"\n\n"+i+"\n\n"+this._handleSource(e.getShaderSource(t),s)}return i}_logProgramError(e,t,r){if(this.renderer.debug.checkShaderErrors){const s=this.gl,i=(s.getProgramInfoLog(e)||"").trim();if(!1===s.getProgramParameter(e,s.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(s,e,r,t);else{const n=this._getShaderErrors(s,r,"vertex"),a=this._getShaderErrors(s,t,"fragment");o("THREE.WebGLProgram: Shader Error "+s.getError()+" - VALIDATE_STATUS "+s.getProgramParameter(e,s.VALIDATE_STATUS)+"\n\nProgram Info Log: "+i+"\n"+n+"\n"+a)}else""!==i&&d("WebGLProgram: Program Info Log:",i)}}_completeCompile(e,t){const{state:r,gl:s}=this,i=this.get(t),{programGPU:n,fragmentShader:a,vertexShader:o}=i;!1===s.getProgramParameter(n,s.LINK_STATUS)&&this._logProgramError(n,a,o),r.useProgram(n);const u=e.getBindings();this._setupBindings(u,n),this.set(t,{programGPU:n})}createComputePipeline(e,t){const{state:r,gl:s}=this,i={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(i);const{computeProgram:n}=e,a=s.createProgram(),o=this.get(i).shaderGPU,u=this.get(n).shaderGPU,l=n.transforms,d=[],c=[];for(let e=0;e<l.length;e++){const t=l[e];d.push(t.varyingName),c.push(t.attributeNode)}s.attachShader(a,o),s.attachShader(a,u),s.transformFeedbackVaryings(a,d,s.SEPARATE_ATTRIBS),s.linkProgram(a),!1===s.getProgramParameter(a,s.LINK_STATUS)&&this._logProgramError(a,o,u),r.useProgram(a),this._setupBindings(t,a);const h=n.attributes,p=[],g=[];for(let e=0;e<h.length;e++){const t=h[e].node.attribute;p.push(t),this.has(t)||this.attributeUtils.createAttribute(t,s.ARRAY_BUFFER)}for(let e=0;e<c.length;e++){const t=c[e].attribute;this.has(t)||this.attributeUtils.createAttribute(t,s.ARRAY_BUFFER);const r=this.get(t);g.push(r)}this.set(e,{programGPU:a,transformBuffers:g,attributes:p})}createBindings(e,t){if(!1===this._knownBindings.has(t)){this._knownBindings.add(t);let e=0,r=0;for(const s of t){this.set(s,{textures:r,uniformBuffers:e});for(const t of s.bindings)t.isUniformBuffer&&e++,t.isSampledTexture&&r++}}this.updateBindings(e,t)}updateBindings(e){const{gl:t}=this,r=this.get(e);let s=r.uniformBuffers,i=r.textures;for(const r of e.bindings){const e=this.get(r);if(r.isUniformsGroup||r.isUniformBuffer){const i=r.buffer;let{bufferGPU:n}=this.get(i);void 0===n?(n=t.createBuffer(),t.bindBuffer(t.UNIFORM_BUFFER,n),t.bufferData(t.UNIFORM_BUFFER,i.byteLength,t.DYNAMIC_DRAW),this.set(i,{bufferGPU:n})):t.bindBuffer(t.UNIFORM_BUFFER,n);const a=r.updateRanges;if(t.bindBuffer(t.UNIFORM_BUFFER,n),0===a.length)t.bufferData(t.UNIFORM_BUFFER,i,t.DYNAMIC_DRAW);else{const e=Xr(i),r=e?1:i.BYTES_PER_ELEMENT;for(let s=0,n=a.length;s<n;s++){const n=a[s],o=n.start*r,u=n.count*r,l=o*(e?i.BYTES_PER_ELEMENT:1);t.bufferSubData(t.UNIFORM_BUFFER,l,i,o,u)}}e.index=s++,e.bufferGPU=n,this.set(r,e)}else if(r.isSampledTexture){const{textureGPU:t,glTextureType:s}=this.get(r.texture);e.index=i++,e.textureGPU=t,e.glTextureType=s,this.set(r,e)}}}updateBinding(e){const t=this.gl;if(e.isUniformsGroup||e.isUniformBuffer){const r=this.get(e).bufferGPU,s=e.buffer,i=e.updateRanges;if(t.bindBuffer(t.UNIFORM_BUFFER,r),0===i.length)t.bufferData(t.UNIFORM_BUFFER,s,t.DYNAMIC_DRAW);else{const e=Xr(s),r=e?1:s.BYTES_PER_ELEMENT;for(let n=0,a=i.length;n<a;n++){const a=i[n],o=a.start*r,u=a.count*r,l=o*(e?s.BYTES_PER_ELEMENT:1);t.bufferSubData(t.UNIFORM_BUFFER,l,s,o,u)}}}}createIndexAttribute(e){const t=this.gl;this.attributeUtils.createAttribute(e,t.ELEMENT_ARRAY_BUFFER)}createAttribute(e){if(this.has(e))return;const t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}createStorageAttribute(e){if(this.has(e))return;const t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}hasFeature(e){const t=Object.keys(LR).filter(t=>LR[t]===e),r=this.extensions;for(let e=0;e<t.length;e++)if(r.has(t[e]))return!0;return!1}getMaxAnisotropy(){return this.capabilities.getMaxAnisotropy()}copyTextureToTexture(e,t,r=null,s=null,i=0,n=0){this.textureUtils.copyTextureToTexture(e,t,r,s,i,n)}copyFramebufferToTexture(e,t,r){this.textureUtils.copyFramebufferToTexture(e,t,r)}hasCompatibility(e){return e===E.TEXTURE_COMPARE||super.hasCompatibility(e)}initRenderTarget(e){const{gl:t,state:r}=this;this._setFramebuffer(e),r.bindFramebuffer(t.FRAMEBUFFER,null)}_setFramebuffer(e){const{gl:t,state:r}=this;let s=null;if(null!==e.textures){const i=e.renderTarget,n=this.get(i),{samples:a,depthBuffer:o,stencilBuffer:u}=i,l=!0===i.isCubeRenderTarget,d=!0===i.isRenderTarget3D,c=i.depth>1,h=!0===i.isXRRenderTarget,p=!0===h&&!0===i._hasExternalTextures;let g=n.msaaFrameBuffer,m=n.depthRenderbuffer;const f=this.extensions.get("WEBGL_multisampled_render_to_texture"),y=this.extensions.get("OVR_multiview2"),b=this._useMultisampledExtension(i),x=jy(e);let T;if(l?(n.cubeFramebuffers||(n.cubeFramebuffers={}),T=n.cubeFramebuffers[x]):h&&!1===p?T=this._xrFramebuffer:(n.framebuffers||(n.framebuffers={}),T=n.framebuffers[x]),void 0===T){T=t.createFramebuffer(),r.bindFramebuffer(t.FRAMEBUFFER,T);const s=e.textures,o=[];if(l){n.cubeFramebuffers[x]=T;const{textureGPU:e}=this.get(s[0]),r=this.renderer._activeCubeFace,i=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+r,e,i)}else{n.framebuffers[x]=T;for(let r=0;r<s.length;r++){const n=s[r],o=this.get(n);o.renderTarget=e.renderTarget,o.cacheKey=x;const u=t.COLOR_ATTACHMENT0+r;if(i.multiview)y.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,u,o.textureGPU,0,a,0,2);else if(d||c){const e=this.renderer._activeCubeFace,r=this.renderer._activeMipmapLevel;t.framebufferTextureLayer(t.FRAMEBUFFER,u,o.textureGPU,r,e)}else if(b)f.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,u,t.TEXTURE_2D,o.textureGPU,0,a);else{const e=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,u,t.TEXTURE_2D,o.textureGPU,e)}}}const h=u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(!0===i._autoAllocateDepthBuffer){const r=t.createRenderbuffer();this.textureUtils.setupRenderBufferStorage(r,e,0,b),n.xrDepthRenderbuffer=r,o.push(u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT),t.bindRenderbuffer(t.RENDERBUFFER,r),t.framebufferRenderbuffer(t.FRAMEBUFFER,h,t.RENDERBUFFER,r)}else if(null!==e.depthTexture){o.push(u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT);const r=this.get(e.depthTexture);if(r.renderTarget=e.renderTarget,r.cacheKey=x,i.multiview)y.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,h,r.textureGPU,0,a,0,2);else if(p&&b)f.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,h,t.TEXTURE_2D,r.textureGPU,0,a);else if(e.depthTexture.isArrayTexture){const e=this.renderer._activeCubeFace;t.framebufferTextureLayer(t.FRAMEBUFFER,h,r.textureGPU,0,e)}else if(e.depthTexture.isCubeTexture){const e=this.renderer._activeCubeFace;t.framebufferTexture2D(t.FRAMEBUFFER,h,t.TEXTURE_CUBE_MAP_POSITIVE_X+e,r.textureGPU,0)}else t.framebufferTexture2D(t.FRAMEBUFFER,h,t.TEXTURE_2D,r.textureGPU,0)}n.depthInvalidationArray=o}else{if(this._isRenderCameraDepthArray(e)){r.bindFramebuffer(t.FRAMEBUFFER,T);const s=this.renderer._activeCubeFace,i=this.get(e.depthTexture),n=u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;t.framebufferTextureLayer(t.FRAMEBUFFER,n,i.textureGPU,0,s)}if((h||b||i.multiview)&&!0!==i._isOpaqueFramebuffer){r.bindFramebuffer(t.FRAMEBUFFER,T);const s=this.get(e.textures[0]);i.multiview?y.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,s.textureGPU,0,a,0,2):b?f.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,s.textureGPU,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,s.textureGPU,0);const o=u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(!0===i._autoAllocateDepthBuffer){const e=n.xrDepthRenderbuffer;t.bindRenderbuffer(t.RENDERBUFFER,e),t.framebufferRenderbuffer(t.FRAMEBUFFER,o,t.RENDERBUFFER,e)}else{const r=this.get(e.depthTexture);i.multiview?y.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,o,r.textureGPU,0,a,0,2):b?f.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,o,t.TEXTURE_2D,r.textureGPU,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,r.textureGPU,0)}}}if(a>0&&!1===b&&!i.multiview){if(void 0===g){const s=[];g=t.createFramebuffer(),r.bindFramebuffer(t.FRAMEBUFFER,g);const i=[],l=e.textures;for(let r=0;r<l.length;r++){i[r]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,i[r]),s.push(t.COLOR_ATTACHMENT0+r);const n=e.textures[r],o=this.get(n);t.renderbufferStorageMultisample(t.RENDERBUFFER,a,o.glInternalFormat,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+r,t.RENDERBUFFER,i[r])}if(t.bindRenderbuffer(t.RENDERBUFFER,null),n.msaaFrameBuffer=g,n.msaaRenderbuffers=i,o&&void 0===m){m=t.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(m,e,a),n.depthRenderbuffer=m;const r=u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;s.push(r)}n.invalidationArray=s}s=n.msaaFrameBuffer}else s=T;r.drawBuffers(e,T)}r.bindFramebuffer(t.FRAMEBUFFER,s)}_getVaoKey(e){let t="";for(let r=0;r<e.length;r++){t+=":"+this.get(e[r]).id}return t}_createVao(e){const{gl:t}=this,r=t.createVertexArray();t.bindVertexArray(r);for(let r=0;r<e.length;r++){const s=e[r],i=this.get(s);let n,a;t.bindBuffer(t.ARRAY_BUFFER,i.bufferGPU),t.enableVertexAttribArray(r),!0===s.isInterleavedBufferAttribute?(n=s.data.stride*i.bytesPerElement,a=s.offset*i.bytesPerElement):(n=0,a=0),i.isInteger?t.vertexAttribIPointer(r,s.itemSize,i.type,n,a):t.vertexAttribPointer(r,s.itemSize,i.type,s.normalized,n,a),s.isInstancedBufferAttribute&&!s.isInterleavedBufferAttribute?t.vertexAttribDivisor(r,s.meshPerAttribute):s.isInterleavedBufferAttribute&&s.data.isInstancedInterleavedBuffer&&t.vertexAttribDivisor(r,s.data.meshPerAttribute)}return t.bindBuffer(t.ARRAY_BUFFER,null),r}_getTransformFeedback(e){let t="";for(let r=0;r<e.length;r++)t+=":"+e[r].id;let r=this.transformFeedbackCache[t];if(void 0!==r)return r;const{gl:s}=this;r=s.createTransformFeedback(),s.bindTransformFeedback(s.TRANSFORM_FEEDBACK,r);for(let t=0;t<e.length;t++){const r=e[t];s.bindBufferBase(s.TRANSFORM_FEEDBACK_BUFFER,t,r.transformBuffer)}return s.bindTransformFeedback(s.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[t]=r,r}_setupBindings(e,t){const r=this.gl;for(const s of e)for(const e of s.bindings){const s=this.get(e).index;if(e.isUniformsGroup||e.isUniformBuffer){const i=r.getUniformBlockIndex(t,e.name);r.uniformBlockBinding(t,i,s)}else if(e.isSampledTexture){const i=r.getUniformLocation(t,e.name);r.uniform1i(i,s)}}}_bindUniforms(e){const{gl:t,state:r}=this;for(const s of e)for(const e of s.bindings){const s=this.get(e),i=s.index;e.isUniformsGroup||e.isUniformBuffer?r.bindBufferBase(t.UNIFORM_BUFFER,i,s.bufferGPU):e.isSampledTexture&&r.bindTexture(s.glTextureType,s.textureGPU,t.TEXTURE0+i)}}_resolveRenderTarget(e){const{gl:t,state:r}=this,s=e.renderTarget;if(null!==e.textures&&s){const i=this.get(s);if(s.samples>0&&!1===this._useMultisampledExtension(s)){const n=i.framebuffers[e.getCacheKey()];let a=t.COLOR_BUFFER_BIT;s.resolveDepthBuffer&&(s.depthBuffer&&(a|=t.DEPTH_BUFFER_BIT),s.stencilBuffer&&s.resolveStencilBuffer&&(a|=t.STENCIL_BUFFER_BIT));const o=i.msaaFrameBuffer,u=i.msaaRenderbuffers,l=e.textures,d=l.length>1;if(r.bindFramebuffer(t.READ_FRAMEBUFFER,o),r.bindFramebuffer(t.DRAW_FRAMEBUFFER,n),d)for(let e=0;e<l.length;e++)t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,null),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,null,0);for(let r=0;r<l.length;r++){if(d){const{textureGPU:e}=this.get(l[r]);t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,u[r]),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e,0)}if(e.scissor){const{x:r,y:s,width:i,height:n}=e.scissorValue,o=e.height-n-s;t.blitFramebuffer(r,o,r+i,o+n,r,o,r+i,o+n,a,t.NEAREST)}else t.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,a,t.NEAREST)}if(d)for(let e=0;e<l.length;e++){const{textureGPU:r}=this.get(l[e]);t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,u[e]),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,r,0)}!0===this._supportsInvalidateFramebuffer&&t.invalidateFramebuffer(t.READ_FRAMEBUFFER,i.invalidationArray)}else if(!1===s.resolveDepthBuffer&&i.framebuffers){const s=i.framebuffers[e.getCacheKey()];r.bindFramebuffer(t.DRAW_FRAMEBUFFER,s),t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,i.depthInvalidationArray)}}}_useMultisampledExtension(e){return!0===e.multiview||e.samples>0&&!0===this.extensions.has("WEBGL_multisampled_render_to_texture")&&!1!==e._autoAllocateDepthBuffer}dispose(){null!==this.textureUtils&&this.textureUtils.dispose();const e=this.extensions.get("WEBGL_lose_context");e&&e.loseContext(),this.renderer.domElement.removeEventListener("webglcontextlost",this._onContextLost)}}const OR="point-list",VR="line-list",kR="line-strip",GR="triangle-list",$R="undefined"!=typeof self&&self.GPUShaderStage?self.GPUShaderStage:{VERTEX:1,FRAGMENT:2,COMPUTE:4},zR="never",WR="less",HR="equal",qR="less-equal",jR="greater",XR="not-equal",KR="greater-equal",YR="always",QR="store",ZR="load",JR="clear",eE="ccw",tE="cw",rE="none",sE="back",iE="uint16",nE="uint32",aE="r8unorm",oE="r8snorm",uE="r8uint",lE="r8sint",dE="r16uint",cE="r16sint",hE="r16float",pE="rg8unorm",gE="rg8snorm",mE="rg8uint",fE="rg8sint",yE="r32uint",bE="r32sint",xE="r32float",TE="rg16uint",_E="rg16sint",vE="rg16float",NE="rgba8unorm",SE="rgba8unorm-srgb",RE="rgba8snorm",EE="rgba8uint",AE="rgba8sint",wE="bgra8unorm",CE="bgra8unorm-srgb",ME="rgb9e5ufloat",BE="rgb10a2unorm",FE="rg11b10ufloat",LE="rg32uint",PE="rg32sint",DE="rg32float",UE="rgba16uint",IE="rgba16sint",OE="rgba16float",VE="rgba32uint",kE="rgba32sint",GE="rgba32float",$E="depth16unorm",zE="depth24plus",WE="depth24plus-stencil8",HE="depth32float",qE="depth32float-stencil8",jE="bc1-rgba-unorm",XE="bc1-rgba-unorm-srgb",KE="bc2-rgba-unorm",YE="bc2-rgba-unorm-srgb",QE="bc3-rgba-unorm",ZE="bc3-rgba-unorm-srgb",JE="bc4-r-unorm",eA="bc4-r-snorm",tA="bc5-rg-unorm",rA="bc5-rg-snorm",sA="bc6h-rgb-ufloat",iA="bc6h-rgb-float",nA="bc7-rgba-unorm",aA="bc7-rgba-unorm-srgb",oA="etc2-rgb8unorm",uA="etc2-rgb8unorm-srgb",lA="etc2-rgb8a1unorm",dA="etc2-rgb8a1unorm-srgb",cA="etc2-rgba8unorm",hA="etc2-rgba8unorm-srgb",pA="eac-r11unorm",gA="eac-r11snorm",mA="eac-rg11unorm",fA="eac-rg11snorm",yA="astc-4x4-unorm",bA="astc-4x4-unorm-srgb",xA="astc-5x4-unorm",TA="astc-5x4-unorm-srgb",_A="astc-5x5-unorm",vA="astc-5x5-unorm-srgb",NA="astc-6x5-unorm",SA="astc-6x5-unorm-srgb",RA="astc-6x6-unorm",EA="astc-6x6-unorm-srgb",AA="astc-8x5-unorm",wA="astc-8x5-unorm-srgb",CA="astc-8x6-unorm",MA="astc-8x6-unorm-srgb",BA="astc-8x8-unorm",FA="astc-8x8-unorm-srgb",LA="astc-10x5-unorm",PA="astc-10x5-unorm-srgb",DA="astc-10x6-unorm",UA="astc-10x6-unorm-srgb",IA="astc-10x8-unorm",OA="astc-10x8-unorm-srgb",VA="astc-10x10-unorm",kA="astc-10x10-unorm-srgb",GA="astc-12x10-unorm",$A="astc-12x10-unorm-srgb",zA="astc-12x12-unorm",WA="astc-12x12-unorm-srgb",HA="clamp-to-edge",qA="repeat",jA="mirror-repeat",XA="linear",KA="nearest",YA="zero",QA="one",ZA="src",JA="one-minus-src",ew="src-alpha",tw="one-minus-src-alpha",rw="dst",sw="one-minus-dst",iw="dst-alpha",nw="one-minus-dst-alpha",aw="src-alpha-saturated",ow="constant",uw="one-minus-constant",lw="add",dw="subtract",cw="reverse-subtract",hw="min",pw="max",gw=0,mw=15,fw="keep",yw="zero",bw="replace",xw="invert",Tw="increment-clamp",_w="decrement-clamp",vw="increment-wrap",Nw="decrement-wrap",Sw="storage",Rw="read-only-storage",Ew="write-only",Aw="read-only",ww="read-write",Cw="non-filtering",Mw="comparison",Bw="float",Fw="unfilterable-float",Lw="depth",Pw="sint",Dw="uint",Uw="2d",Iw="3d",Ow="2d",Vw="2d-array",kw="cube",Gw="3d",$w="all",zw="vertex",Ww="instance",Hw={CoreFeaturesAndLimits:"core-features-and-limits",DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionBCSliced3D:"texture-compression-bc-sliced-3d",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TextureCompressionASTCSliced3D:"texture-compression-astc-sliced-3d",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",Float32Blendable:"float32-blendable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups",TextureFormatsTier1:"texture-formats-tier1",TextureFormatsTier2:"texture-formats-tier2"},qw={"texture-compression-s3tc":"texture-compression-bc","texture-compression-etc1":"texture-compression-etc2"};class jw extends tR{constructor(e,t,r){super(e,t?t.value:null),this.textureNode=t,this.groupNode=r}update(){const{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}}class Xw extends XS{constructor(e,t){super(e,t?t.array:null),this._attribute=t,this.isStorageBuffer=!0}get attribute(){return this._attribute}}let Kw=0;class Yw extends Xw{constructor(e,t){super("StorageBuffer_"+Kw++,e?e.value:null),this.nodeUniform=e,this.access=e?e.access:ri.READ_WRITE,this.groupNode=t}get attribute(){return this.nodeUniform.value}get buffer(){return this.nodeUniform.value.array}}class Qw extends Ty{constructor(e){super(),this.device=e;this.mipmapSampler=e.createSampler({minFilter:XA}),this.flipYSampler=e.createSampler({minFilter:KA}),this.flipUniformBuffer=e.createBuffer({size:4,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),e.queue.writeBuffer(this.flipUniformBuffer,0,new Uint32Array([1])),this.noFlipUniformBuffer=e.createBuffer({size:4,usage:GPUBufferUsage.UNIFORM}),this.transferPipelines={},this.mipmapShaderModule=e.createShaderModule({label:"mipmap",code:"\nstruct VarysStruct {\n\t@builtin( position ) Position: vec4f,\n\t@location( 0 ) vTex : vec2f,\n\t@location( 1 ) @interpolate(flat, either) vBaseArrayLayer: u32,\n};\n\n@group( 0 ) @binding ( 2 )\nvar<uniform> flipY: u32;\n\n@vertex\nfn mainVS(\n\t\t@builtin( vertex_index ) vertexIndex : u32,\n\t\t@builtin( instance_index ) instanceIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array(\n\t\tvec2f( -1, -1 ),\n\t\tvec2f( -1, 3 ),\n\t\tvec2f( 3, -1 ),\n\t);\n\n\tlet p = pos[ vertexIndex ];\n\tlet mult = select( vec2f( 0.5, -0.5 ), vec2f( 0.5, 0.5 ), flipY != 0 );\n\tVarys.vTex = p * mult + vec2f( 0.5 );\n\tVarys.Position = vec4f( p, 0, 1 );\n\tVarys.vBaseArrayLayer = instanceIndex;\n\n\treturn Varys;\n\n}\n\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img2d : texture_2d<f32>;\n\n@fragment\nfn main_2d( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> {\n\n\treturn textureSample( img2d, imgSampler, Varys.vTex );\n\n}\n\n@group( 0 ) @binding( 1 )\nvar img2dArray : texture_2d_array<f32>;\n\n@fragment\nfn main_2d_array( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> {\n\n\treturn textureSample( img2dArray, imgSampler, Varys.vTex, Varys.vBaseArrayLayer );\n\n}\n\nconst faceMat = array(\n mat3x3f( 0, 0, -2, 0, -2, 0, 1, 1, 1 ), // pos-x\n mat3x3f( 0, 0, 2, 0, -2, 0, -1, 1, -1 ), // neg-x\n mat3x3f( 2, 0, 0, 0, 0, 2, -1, 1, -1 ), // pos-y\n mat3x3f( 2, 0, 0, 0, 0, -2, -1, -1, 1 ), // neg-y\n mat3x3f( 2, 0, 0, 0, -2, 0, -1, 1, 1 ), // pos-z\n mat3x3f( -2, 0, 0, 0, -2, 0, 1, 1, -1 ), // neg-z\n);\n\n@group( 0 ) @binding( 1 )\nvar imgCube : texture_cube<f32>;\n\n@fragment\nfn main_cube( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> {\n\n\treturn textureSample( imgCube, imgSampler, faceMat[ Varys.vBaseArrayLayer ] * vec3f( fract( Varys.vTex ), 1 ) );\n\n}\n"})}getTransferPipeline(e,t){const r=`${e}-${t=t||"2d-array"}`;let s=this.transferPipelines[r];return void 0===s&&(s=this.device.createRenderPipeline({label:`mipmap-${e}-${t}`,vertex:{module:this.mipmapShaderModule},fragment:{module:this.mipmapShaderModule,entryPoint:`main_${t.replace("-","_")}`,targets:[{format:e}]},layout:"auto"}),this.transferPipelines[r]=s),s}flipY(e,t,r=0){const s=t.format,{width:i,height:n}=t.size,a=this.device.createTexture({size:{width:i,height:n},format:s,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),o=this.getTransferPipeline(s,e.textureBindingViewDimension),u=this.getTransferPipeline(s,a.textureBindingViewDimension),l=this.device.createCommandEncoder({}),d=(e,t,r,s,i,n)=>{const a=e.getBindGroupLayout(0),o=this.device.createBindGroup({layout:a,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t.createView({dimension:t.textureBindingViewDimension||"2d-array",baseMipLevel:0,mipLevelCount:1})},{binding:2,resource:{buffer:n?this.flipUniformBuffer:this.noFlipUniformBuffer}}]}),u=l.beginRenderPass({colorAttachments:[{view:s.createView({dimension:"2d",baseMipLevel:0,mipLevelCount:1,baseArrayLayer:i,arrayLayerCount:1}),loadOp:JR,storeOp:QR}]});u.setPipeline(e),u.setBindGroup(0,o),u.draw(3,1,0,r),u.end()};d(o,e,r,a,0,!1),d(u,a,0,e,r,!0),this.device.queue.submit([l.finish()]),a.destroy()}generateMipmaps(e,t=null){const r=this.get(e),s=r.layers||this._mipmapCreateBundles(e),i=t||this.device.createCommandEncoder({label:"mipmapEncoder"});this._mipmapRunBundles(i,s),null===t&&this.device.queue.submit([i.finish()]),r.layers=s}_mipmapCreateBundles(e){const t=e.textureBindingViewDimension||"2d-array",r=this.getTransferPipeline(e.format,t),s=r.getBindGroupLayout(0),i=[];for(let n=1;n<e.mipLevelCount;n++)for(let a=0;a<e.depthOrArrayLayers;a++){const o=this.device.createBindGroup({layout:s,entries:[{binding:0,resource:this.mipmapSampler},{binding:1,resource:e.createView({dimension:t,baseMipLevel:n-1,mipLevelCount:1})},{binding:2,resource:{buffer:this.noFlipUniformBuffer}}]}),u={colorAttachments:[{view:e.createView({dimension:"2d",baseMipLevel:n,mipLevelCount:1,baseArrayLayer:a,arrayLayerCount:1}),loadOp:JR,storeOp:QR}]},l=this.device.createRenderBundleEncoder({colorFormats:[e.format]});l.setPipeline(r),l.setBindGroup(0,o),l.draw(3,1,0,a),i.push({renderBundles:[l.finish()],passDescriptor:u})}return i}_mipmapRunBundles(e,t){const r=t.length;for(let s=0;s<r;s++){const r=t[s],i=e.beginRenderPass(r.passDescriptor);i.executeBundles(r.renderBundles),i.end()}}}const Zw={[Hr]:"never",[A]:"less",[zr]:"equal",[w]:"less-equal",[C]:"greater",[M]:"greater-equal",[Wr]:"always",[$r]:"not-equal"},Jw=[0,1,3,2,4,5];class eC{constructor(e){this.backend=e,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this._samplerCache=new Map}updateSampler(e){const t=this.backend,r=e.minFilter+"-"+e.magFilter+"-"+e.wrapS+"-"+e.wrapT+"-"+(e.wrapR||"0")+"-"+e.anisotropy+"-"+(e.compareFunction||0);let s=this._samplerCache.get(r);if(void 0===s){const i={addressModeU:this._convertAddressMode(e.wrapS),addressModeV:this._convertAddressMode(e.wrapT),addressModeW:this._convertAddressMode(e.wrapR),magFilter:this._convertFilterMode(e.magFilter),minFilter:this._convertFilterMode(e.minFilter),mipmapFilter:this._convertFilterMode(e.minFilter),maxAnisotropy:1};e.isDepthTexture&&null===e.compareFunction&&(i.magFilter=KA,i.minFilter=KA,i.mipmapFilter=KA),i.magFilter===XA&&i.minFilter===XA&&i.mipmapFilter===XA&&(i.maxAnisotropy=e.anisotropy),e.isDepthTexture&&null!==e.compareFunction&&t.hasCompatibility(E.TEXTURE_COMPARE)&&(i.compare=Zw[e.compareFunction]);s={sampler:t.device.createSampler(i),usedTimes:0},this._samplerCache.set(r,s)}const i=t.get(e);if(i.sampler!==s.sampler){if(void 0!==i.sampler){const e=this._samplerCache.get(i.samplerKey);e.usedTimes--,0===e.usedTimes&&this._samplerCache.delete(i.samplerKey)}i.samplerKey=r,i.sampler=s.sampler,s.usedTimes++}return r}createDefaultTexture(e){let t;const r=tC(e);t=e.isCubeTexture?this._getDefaultCubeTextureGPU(r):this._getDefaultTextureGPU(r),this.backend.get(e).texture=t}createTexture(e,t={}){const r=this.backend,s=r.get(e);if(s.initialized)throw new Error("WebGPUTextureUtils: Texture already initialized.");if(e.isExternalTexture)return s.texture=e.sourceTexture,void(s.initialized=!0);void 0===t.needsMipmaps&&(t.needsMipmaps=!1),void 0===t.levels&&(t.levels=1),void 0===t.depth&&(t.depth=1);const{width:i,height:n,depth:a,levels:o}=t;e.isFramebufferTexture&&(t.renderTarget?t.format=this.backend.utils.getCurrentColorFormat(t.renderTarget):t.format=this.backend.utils.getPreferredCanvasFormat());const u=this._getDimension(e),l=e.internalFormat||t.format||tC(e,r.device);s.format=l;const{samples:c,primarySamples:h,isMSAA:p}=r.utils.getTextureSampleData(e);let g=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;!0===e.isStorageTexture&&(g|=GPUTextureUsage.STORAGE_BINDING),!0!==e.isCompressedTexture&&!0!==e.isCompressedArrayTexture&&l!==ME&&(g|=GPUTextureUsage.RENDER_ATTACHMENT);const m={label:e.name,size:{width:i,height:n,depthOrArrayLayers:a},mipLevelCount:o,sampleCount:h,dimension:u,format:l,usage:g};if(void 0===l)return d("WebGPURenderer: Texture format not supported."),void this.createDefaultTexture(e);e.isCubeTexture&&(m.textureBindingViewDimension=kw);try{s.texture=r.device.createTexture(m)}catch(t){return d("WebGPURenderer: Failed to create texture with descriptor:",m),void this.createDefaultTexture(e)}if(p){const e=Object.assign({},m);e.label=e.label+"-msaa",e.sampleCount=c,e.mipLevelCount=1,s.msaaTexture=r.device.createTexture(e)}s.initialized=!0,s.textureDescriptorGPU=m}destroyTexture(e,t=!1){const r=this.backend,s=r.get(e);void 0!==s.texture&&!1===t&&s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),r.delete(e)}generateMipmaps(e,t=null){const r=this.backend.get(e);this._generateMipmaps(r.texture,t)}getColorBuffer(){const e=this.backend,t=e.renderer.getCanvasTarget(),{width:r,height:s}=e.getDrawingBufferSize(),i=e.renderer.currentSamples,n=t.colorTexture,a=e.get(n);if(n.width===r&&n.height===s&&n.samples===i)return a.texture;let o=a.texture;return o&&o.destroy(),o=e.device.createTexture({label:"colorBuffer",size:{width:r,height:s,depthOrArrayLayers:1},sampleCount:e.utils.getSampleCount(e.renderer.currentSamples),format:e.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),n.source.width=r,n.source.height=s,n.samples=i,a.texture=o,o}getDepthBuffer(e=!0,t=!1){const r=this.backend,s=r.renderer.getCanvasTarget(),{width:i,height:n}=r.getDrawingBufferSize(),a=r.renderer.currentSamples,o=s.depthTexture;if(o.width===i&&o.height===n&&o.samples===a&&o.depth===e&&o.stencil===t)return r.get(o).texture;const u=r.get(o).texture;let l,d;if(t?(l=Ve,d=Ge):e&&(l=ke,d=S),void 0!==u){if(o.image.width===i&&o.image.height===n&&o.format===l&&o.type===d&&o.samples===a)return u;this.destroyTexture(o)}return o.name="depthBuffer",o.format=l,o.type=d,o.image.width=i,o.image.height=n,o.samples=a,this.createTexture(o,{width:i,height:n}),r.get(o).texture}updateTexture(e,t){const r=this.backend.get(e),s=e.mipmaps,{textureDescriptorGPU:i}=r;if(!e.isRenderTargetTexture&&void 0!==i){if(e.isDataTexture)if(s.length>0)for(let t=0,n=s.length;t<n;t++){const n=s[t];this._copyBufferToTexture(n,r.texture,i,0,e.flipY,0,t)}else this._copyBufferToTexture(t.image,r.texture,i,0,e.flipY);else if(e.isArrayTexture||e.isDataArrayTexture||e.isData3DTexture)for(let s=0;s<t.image.depth;s++)this._copyBufferToTexture(t.image,r.texture,i,s,e.flipY,s);else if(e.isCompressedTexture||e.isCompressedArrayTexture)this._copyCompressedBufferToTexture(e.mipmaps,r.texture,i);else if(e.isCubeTexture)this._copyCubeMapToTexture(e,r.texture,i);else if(s.length>0)for(let t=0,n=s.length;t<n;t++){const n=s[t];this._copyImageToTexture(n,r.texture,i,0,e.flipY,e.premultiplyAlpha,t)}else this._copyImageToTexture(t.image,r.texture,i,0,e.flipY,e.premultiplyAlpha);r.version=e.version}}async copyTextureToBuffer(e,t,r,s,i,n){const a=this.backend.device,o=this.backend.get(e),u=o.texture,l=o.textureDescriptorGPU.format,d=this._getBytesPerTexel(l);let c=s*d;c=256*Math.ceil(c/256);const h=a.createBuffer({size:(i-1)*c+s*d,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),p=a.createCommandEncoder();p.copyTextureToBuffer({texture:u,origin:{x:t,y:r,z:n}},{buffer:h,bytesPerRow:c},{width:s,height:i});const g=this._getTypedArrayType(l);a.queue.submit([p.finish()]),await h.mapAsync(GPUMapMode.READ);return new g(h.getMappedRange())}dispose(){this._samplerCache.clear()}_getDefaultTextureGPU(e){let t=this.defaultTexture[e];if(void 0===t){const r=new N;r.minFilter=B,r.magFilter=B,this.createTexture(r,{width:1,height:1,format:e}),this.defaultTexture[e]=t=r}return this.backend.get(t).texture}_getDefaultCubeTextureGPU(e){let t=this.defaultCubeTexture[e];if(void 0===t){const r=new U;r.minFilter=B,r.magFilter=B,this.createTexture(r,{width:1,height:1,depth:6}),this.defaultCubeTexture[e]=t=r}return this.backend.get(t).texture}_copyCubeMapToTexture(e,t,r){const s=e.images,i=e.mipmaps;for(let n=0;n<6;n++){const a=s[n],o=!0===e.flipY?Jw[n]:n;a.isDataTexture?this._copyBufferToTexture(a.image,t,r,o,e.flipY):this._copyImageToTexture(a,t,r,o,e.flipY,e.premultiplyAlpha);for(let s=0;s<i.length;s++){const a=i[s].images[n];a.isDataTexture?this._copyBufferToTexture(a.image,t,r,o,e.flipY,0,s+1):this._copyImageToTexture(a,t,r,o,e.flipY,e.premultiplyAlpha,s+1)}}}_copyImageToTexture(e,t,r,s,i,n,a=0){const o=this.backend.device,u=a>0?e.width:r.size.width,l=a>0?e.height:r.size.height;try{o.queue.copyExternalImageToTexture({source:e,flipY:i},{texture:t,mipLevel:a,origin:{x:0,y:0,z:s},premultipliedAlpha:n},{width:u,height:l,depthOrArrayLayers:1})}catch(e){}}_getPassUtils(){let e=this._passUtils;return null===e&&(this._passUtils=e=new Qw(this.backend.device)),e}_generateMipmaps(e,t=null){this._getPassUtils().generateMipmaps(e,t)}_flipY(e,t,r=0){this._getPassUtils().flipY(e,t,r)}_copyBufferToTexture(e,t,r,s,i,n=0,a=0){const o=this.backend.device,u=e.data,l=this._getBytesPerTexel(r.format),d=e.width*l;o.queue.writeTexture({texture:t,mipLevel:a,origin:{x:0,y:0,z:s}},u,{offset:e.width*e.height*l*n,bytesPerRow:d},{width:e.width,height:e.height,depthOrArrayLayers:1}),!0===i&&this._flipY(t,r,s)}_copyCompressedBufferToTexture(e,t,r){const s=this.backend.device,i=this._getBlockData(r.format),n=r.size.depthOrArrayLayers>1;for(let a=0;a<e.length;a++){const o=e[a],u=o.width,l=o.height,d=n?r.size.depthOrArrayLayers:1,c=Math.ceil(u/i.width)*i.byteLength,h=c*Math.ceil(l/i.height);for(let e=0;e<d;e++)s.queue.writeTexture({texture:t,mipLevel:a,origin:{x:0,y:0,z:e}},o.data,{offset:e*h,bytesPerRow:c,rowsPerImage:Math.ceil(l/i.height)},{width:Math.ceil(u/i.width)*i.width,height:Math.ceil(l/i.height)*i.height,depthOrArrayLayers:1})}}_getBlockData(e){return e===jE||e===XE?{byteLength:8,width:4,height:4}:e===KE||e===YE||e===QE||e===ZE?{byteLength:16,width:4,height:4}:e===JE||e===eA?{byteLength:8,width:4,height:4}:e===tA||e===rA||e===sA||e===iA||e===nA||e===aA?{byteLength:16,width:4,height:4}:e===oA||e===uA||e===lA||e===dA?{byteLength:8,width:4,height:4}:e===cA||e===hA?{byteLength:16,width:4,height:4}:e===pA||e===gA?{byteLength:8,width:4,height:4}:e===mA||e===fA||e===yA||e===bA?{byteLength:16,width:4,height:4}:e===xA||e===TA?{byteLength:16,width:5,height:4}:e===_A||e===vA?{byteLength:16,width:5,height:5}:e===NA||e===SA?{byteLength:16,width:6,height:5}:e===RA||e===EA?{byteLength:16,width:6,height:6}:e===AA||e===wA?{byteLength:16,width:8,height:5}:e===CA||e===MA?{byteLength:16,width:8,height:6}:e===BA||e===FA?{byteLength:16,width:8,height:8}:e===LA||e===PA?{byteLength:16,width:10,height:5}:e===DA||e===UA?{byteLength:16,width:10,height:6}:e===IA||e===OA?{byteLength:16,width:10,height:8}:e===VA||e===kA?{byteLength:16,width:10,height:10}:e===GA||e===$A?{byteLength:16,width:12,height:10}:e===zA||e===WA?{byteLength:16,width:12,height:12}:void 0}_convertAddressMode(e){let t=HA;return e===kr?t=qA:e===Vr&&(t=jA),t}_convertFilterMode(e){let t=XA;return e!==B&&e!==Gr&&e!==at||(t=KA),t}_getBytesPerTexel(e){return e===aE||e===oE||e===uE||e===lE?1:e===dE||e===cE||e===hE||e===pE||e===gE||e===mE||e===fE?2:e===yE||e===bE||e===xE||e===TE||e===_E||e===vE||e===NE||e===SE||e===RE||e===EE||e===AE||e===wE||e===CE||e===ME||e===BE||e===FE||e===HE||e===zE||e===WE||e===qE?4:e===LE||e===PE||e===DE||e===UE||e===IE||e===OE?8:e===VE||e===kE||e===GE?16:void 0}_getTypedArrayType(e){return e===uE?Uint8Array:e===lE?Int8Array:e===aE?Uint8Array:e===oE?Int8Array:e===mE?Uint8Array:e===fE?Int8Array:e===pE?Uint8Array:e===gE?Int8Array:e===EE?Uint8Array:e===AE?Int8Array:e===NE||e===SE?Uint8Array:e===RE?Int8Array:e===dE?Uint16Array:e===cE?Int16Array:e===TE?Uint16Array:e===_E?Int16Array:e===UE?Uint16Array:e===IE?Int16Array:e===hE||e===vE||e===OE?Uint16Array:e===yE?Uint32Array:e===bE?Int32Array:e===xE?Float32Array:e===LE?Uint32Array:e===PE?Int32Array:e===DE?Float32Array:e===VE?Uint32Array:e===kE?Int32Array:e===GE?Float32Array:e===wE||e===CE?Uint8Array:e===BE||e===ME||e===FE?Uint32Array:e===HE?Float32Array:e===zE||e===WE?Uint32Array:e===qE?Float32Array:void 0}_getDimension(e){let t;return t=e.is3DTexture||e.isData3DTexture?Iw:Uw,t}}function tC(e,t=null){const r=e.format,s=e.type,i=e.colorSpace,n=p.getTransfer(i);let a;if(!0===e.isCompressedTexture||!0===e.isCompressedArrayTexture)switch(r){case or:case ur:a=n===g?XE:jE;break;case lr:a=n===g?YE:KE;break;case dr:a=n===g?ZE:QE;break;case Ur:a=JE;break;case Ir:a=eA;break;case H:a=tA;break;case Or:a=rA;break;case Dr:a=n===g?aA:nA;break;case fr:case mr:a=n===g?uA:oA;break;case yr:a=n===g?hA:cA;break;case br:a=pA;break;case xr:a=gA;break;case q:a=mA;break;case Tr:a=fA;break;case _r:a=n===g?bA:yA;break;case vr:a=n===g?TA:xA;break;case Nr:a=n===g?vA:_A;break;case Sr:a=n===g?SA:NA;break;case Rr:a=n===g?EA:RA;break;case Er:a=n===g?wA:AA;break;case Ar:a=n===g?MA:CA;break;case wr:a=n===g?FA:BA;break;case Cr:a=n===g?PA:LA;break;case Mr:a=n===g?UA:DA;break;case Br:a=n===g?OA:IA;break;case Fr:a=n===g?kA:VA;break;case Lr:a=n===g?$A:GA;break;case Pr:a=n===g?WA:zA;break;case Ae:a=n===g?SE:NE;break;default:o("WebGPURenderer: Unsupported texture format.",r)}else switch(r){case Ae:switch(s){case Nt:a=RE;break;case vt:a=IE;break;case St:a=UE;break;case S:a=VE;break;case R:a=kE;break;case $e:a=n===g?SE:NE;break;case _e:a=OE;break;case Y:a=GE;break;default:o("WebGPURenderer: Unsupported texture type with RGBAFormat.",s)}break;case At:switch(s){case ir:a=ME;break;case nr:a=FE;break;default:o("WebGPURenderer: Unsupported texture type with RGBFormat.",s)}break;case _t:switch(s){case Nt:a=oE;break;case vt:a=cE;break;case St:a=dE;break;case S:a=yE;break;case R:a=bE;break;case $e:a=aE;break;case _e:a=hE;break;case Y:a=xE;break;default:o("WebGPURenderer: Unsupported texture type with RedFormat.",s)}break;case W:switch(s){case Nt:a=gE;break;case vt:a=_E;break;case St:a=TE;break;case S:a=LE;break;case R:a=PE;break;case $e:a=pE;break;case _e:a=vE;break;case Y:a=DE;break;default:o("WebGPURenderer: Unsupported texture type with RGFormat.",s)}break;case ke:switch(s){case St:a=$E;break;case S:a=zE;break;case Y:a=HE;break;default:o("WebGPURenderer: Unsupported texture type with DepthFormat.",s)}break;case Ve:switch(s){case Ge:a=WE;break;case Y:t&&!1===t.features.has(Hw.Depth32FloatStencil8)&&o('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),a=qE;break;default:o("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",s)}break;case Tt:switch(s){case R:a=bE;break;case S:a=yE;break;default:o("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",s)}break;case Rt:switch(s){case R:a=PE;break;case S:a=LE;break;default:o("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",s)}break;case wt:switch(s){case R:a=kE;break;case S:a=VE;break;default:o("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",s)}break;default:o("WebGPURenderer: Unsupported texture format.",r)}return a}const rC=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,sC=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,iC={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2<f32>":"vec2","vec2<i32>":"ivec2","vec2<u32>":"uvec2","vec2<bool>":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3<f32>":"vec3","vec3<i32>":"ivec3","vec3<u32>":"uvec3","vec3<bool>":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4<f32>":"vec4","vec4<i32>":"ivec4","vec4<u32>":"uvec4","vec4<bool>":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2<f32>":"mat2",mat2x2f:"mat2","mat3x3<f32>":"mat3",mat3x3f:"mat3","mat4x4<f32>":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_depth_2d_array:"depthTexture",texture_depth_multisampled_2d:"depthTexture",texture_depth_cube:"depthTexture",texture_depth_cube_array:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class nC extends uS{constructor(e){const{type:t,inputs:r,name:s,inputsCode:i,blockCode:n,outputType:a}=(e=>{const t=(e=e.trim()).match(rC);if(null!==t&&4===t.length){const r=t[2],s=[];let i=null;for(;null!==(i=sC.exec(r));)s.push({name:i[1],type:i[2]});const n=[];for(let e=0;e<s.length;e++){const{name:t,type:r}=s[e];let i=r;i.startsWith("ptr")?i="pointer":(i.startsWith("texture")&&(i=r.split("<")[0]),i=iC[i]),n.push(new XN(i,t))}const a=e.substring(t[0].length),o=t[3]||"void",u=void 0!==t[1]?t[1]:"";return{type:iC[o]||o,inputs:n,name:u,inputsCode:r,blockCode:a,outputType:o}}throw new Error("FunctionNode: Function is not a WGSL code.")})(e);super(t,r,s),this.inputsCode=i,this.blockCode=n,this.outputType=a}getCode(e=this.name){const t="void"!==this.outputType?"-> "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class aC extends oS{parseFunction(e){return new nC(e)}}const oC={[ri.READ_ONLY]:"read",[ri.WRITE_ONLY]:"write",[ri.READ_WRITE]:"read_write"},uC={[kr]:"repeat",[ve]:"clamp",[Vr]:"mirror"},lC={vertex:$R.VERTEX,fragment:$R.FRAGMENT,compute:$R.COMPUTE},dC={instance:!0,swizzleAssign:!1,storageBuffer:!0},cC={"^^":"tsl_xor"},hC={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3<f32>",vec2:"vec2<f32>",ivec2:"vec2<i32>",uvec2:"vec2<u32>",bvec2:"vec2<bool>",vec3:"vec3<f32>",ivec3:"vec3<i32>",uvec3:"vec3<u32>",bvec3:"vec3<bool>",vec4:"vec4<f32>",ivec4:"vec4<i32>",uvec4:"vec4<u32>",bvec4:"vec4<bool>",mat2:"mat2x2<f32>",mat3:"mat3x3<f32>",mat4:"mat4x4<f32>"},pC={},gC={tsl_xor:new hT("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new hT("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new hT("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new hT("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new hT("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new hT("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new hT("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new hT("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new hT("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new hT("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new hT("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new hT("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),biquadraticTexture:new hT("\nfn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f {\n\n\tlet res = vec2f( iRes );\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, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n"),biquadraticTextureArray:new hT("\nfn tsl_biquadraticTexture_array( map : texture_2d_array<f32>, coord : vec2f, iRes : vec2u, layer : u32, level : u32 ) -> vec4f {\n\n\tlet res = vec2f( iRes );\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, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, layer, level );\n\tlet rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, layer, level );\n\tlet rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, layer, level );\n\tlet rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, layer, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},mC={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast<f32>",floatpack_snorm_2x16:"pack2x16snorm",floatpack_unorm_2x16:"pack2x16unorm",floatpack_float16_2x16:"pack2x16float",floatunpack_snorm_2x16:"unpack2x16snorm",floatunpack_unorm_2x16:"unpack2x16unorm",floatunpack_float16_2x16:"unpack2x16float"};let fC="";!0!==("undefined"!=typeof navigator&&/Firefox|Deno/g.test(navigator.userAgent))&&(fC+="diagnostic( off, derivative_uniformity );\n");class yC extends qN{constructor(e,t){super(e,t,new aC),this.uniformGroups={},this.uniformGroupsBindings={},this.builtins={},this.directives={},this.scopedArrays=new Map}_generateTextureSample(e,t,r,s,i,n=this.shaderStage){return"fragment"===n?s?i?`textureSample( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`:`textureSample( ${t}, ${t}_sampler, ${r}, ${s} )`:i?`textureSample( ${t}, ${t}_sampler, ${r}, ${i} )`:`textureSample( ${t}, ${t}_sampler, ${r} )`:this.generateTextureSampleLevel(e,t,r,"0",s)}generateTextureSampleLevel(e,t,r,s,i,n){return!1===this.isUnfilterable(e)?i?n?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i}, ${s}, ${n} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i}, ${s} )`:n?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${n} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,r,n,s,i):this.generateTextureLod(e,t,r,i,n,s)}generateWrapFunction(e){const t=`tsl_coord_${uC[e.wrapS]}S_${uC[e.wrapT]}_${e.is3DTexture||e.isData3DTexture?"3d":"2d"}T`;let r=pC[t];if(void 0===r){const s=[],i=e.is3DTexture||e.isData3DTexture?"vec3f":"vec2f";let n=`fn ${t}( coord : ${i} ) -> ${i} {\n\n\treturn ${i}(\n`;const a=(e,t)=>{e===kr?(s.push(gC.repeatWrapping_float),n+=`\t\ttsl_repeatWrapping_float( coord.${t} )`):e===ve?(s.push(gC.clampWrapping_float),n+=`\t\ttsl_clampWrapping_float( coord.${t} )`):e===Vr?(s.push(gC.mirrorWrapping_float),n+=`\t\ttsl_mirrorWrapping_float( coord.${t} )`):(n+=`\t\tcoord.${t}`,d(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};a(e.wrapS,"x"),n+=",\n",a(e.wrapT,"y"),(e.is3DTexture||e.isData3DTexture)&&(n+=",\n",a(e.wrapR,"z")),n+="\n\t);\n\n}\n",pC[t]=r=new hT(n,s)}return r.build(this),t}generateArrayDeclaration(e,t){return`array< ${this.getType(e)}, ${t} >`}generateTextureDimension(e,t,r){const s=this.getDataFromNode(e,this.shaderStage,this.globalCache);void 0===s.dimensionsSnippet&&(s.dimensionsSnippet={});let i=s.dimensionsSnippet[r];if(void 0===s.dimensionsSnippet[r]){let n,a;const{primarySamples:o}=this.renderer.backend.utils.getTextureSampleData(e),u=o>1;a=e.is3DTexture||e.isData3DTexture?"vec3<u32>":"vec2<u32>",n=u||e.isStorageTexture?t:`${t}${r?`, u32( ${r} )`:""}`,i=new Au(new gl(`textureDimensions( ${n} )`,a)),s.dimensionsSnippet[r]=i,(e.isArrayTexture||e.isDataArrayTexture||e.is3DTexture||e.isData3DTexture)&&(s.arrayLayerCount=new Au(new gl(`textureNumLayers(${t})`,"u32"))),e.isTextureCube&&(s.cubeFaceCount=new Au(new gl("6u","u32")))}return i.build(this)}generateFilteredTexture(e,t,r,s,i="0u",n){const a=this.generateWrapFunction(e),o=this.generateTextureDimension(e,t,i);return s&&(r=`${r} + vec2<f32>(${s}) / ${o}`),n?(this._include("biquadraticTextureArray"),`tsl_biquadraticTexture_array( ${t}, ${a}( ${r} ), ${o}, u32( ${n} ), u32( ${i} ) )`):(this._include("biquadraticTexture"),`tsl_biquadraticTexture( ${t}, ${a}( ${r} ), ${o}, u32( ${i} ) )`)}generateTextureLod(e,t,r,s,i,n="0u"){if(!0===e.isCubeTexture){i&&(r=`${r} + vec3<f32>(${i})`);return`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${e.isDepthTexture?"u32":"f32"}( ${n} ) )`}const a=this.generateWrapFunction(e),o=this.generateTextureDimension(e,t,n),u=e.is3DTexture||e.isData3DTexture?"vec3":"vec2";i&&(r=`${r} + ${u}<f32>(${i}) / ${u}<f32>( ${o} )`);return r=`${u}<u32>( clamp( floor( ${a}( ${r} ) * ${u}<f32>( ${o} ) ), ${`${u}<f32>( 0 )`}, ${`${u}<f32>( ${o} - ${"vec3"===u?"vec3<u32>( 1, 1, 1 )":"vec2<u32>( 1, 1 )"} )`} ) )`,this.generateTextureLoad(e,t,r,n,s,null)}generateStorageTextureLoad(e,t,r,s,i,n){let a;return n&&(r=`${r} + ${n}`),a=i?`textureLoad( ${t}, ${r}, ${i} )`:`textureLoad( ${t}, ${r} )`,a}generateTextureLoad(e,t,r,s,i,n){let a;return null===s&&(s="0u"),n&&(r=`${r} + ${n}`),i?a=`textureLoad( ${t}, ${r}, ${i}, u32( ${s} ) )`:(a=`textureLoad( ${t}, ${r}, u32( ${s} ) )`,this.renderer.backend.compatibilityMode&&e.isDepthTexture&&(a+=".x")),a}generateTextureStore(e,t,r,s,i){let n;return n=s?`textureStore( ${t}, ${r}, ${s}, ${i} )`:`textureStore( ${t}, ${r}, ${i} )`,n}isSampleCompare(e){return!0===e.isDepthTexture&&null!==e.compareFunction&&this.renderer.hasCompatibility(E.TEXTURE_COMPARE)}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===Y||!1===this.isSampleCompare(e)&&e.minFilter===B&&e.magFilter===B||this.renderer.backend.utils.getTextureSampleData(e).primarySamples>1}generateTexture(e,t,r,s,i,n=this.shaderStage){let a=null;return a=this.isUnfilterable(e)?this.generateTextureLod(e,t,r,s,i,"0",n):this._generateTextureSample(e,t,r,s,i,n),a}generateTextureGrad(e,t,r,s,i,n,a=this.shaderStage){if("fragment"===a)return i?n?`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${i}, ${s[0]}, ${s[1]}, ${n} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${i}, ${s[0]}, ${s[1]} )`:n?`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${s[0]}, ${s[1]}, ${n} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${s[0]}, ${s[1]} )`;o(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${a} shader.`)}generateTextureCompare(e,t,r,s,i,n,a=this.shaderStage){if("fragment"===a)return!0===e.isDepthTexture&&!0===e.isArrayTexture?n?`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${i}, ${s}, ${n} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${i}, ${s} )`:n?`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${n} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${s} )`;o(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${a} shader.`)}generateTextureLevel(e,t,r,s,i,n){return!1===this.isUnfilterable(e)?i?n?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i}, ${s}, ${n} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i}, ${s} )`:n?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${n} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,r,n,s,i):this.generateTextureLod(e,t,r,i,n,s)}generateTextureBias(e,t,r,s,i,n,a=this.shaderStage){if("fragment"===a)return i?n?`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${i}, ${s}, ${n} )`:`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${i}, ${s} )`:n?`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${s}, ${n} )`:`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${s} )`;o(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${a} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){const t=e.name,r=e.type;return"texture"===r||"cubeTexture"===r||"cubeDepthTexture"===r||"storageTexture"===r||"texture3D"===r?t:"buffer"===r||"storageBuffer"===r||"indirectStorageBuffer"===r?this.isCustomStruct(e)?t:t+".value":e.groupNode.name+"."+t}return super.getPropertyName(e)}getOutputStructName(){return"output"}getFunctionOperator(e){const t=cC[e];return void 0!==t?(this._include(t),t):null}getNodeAccess(e,t){return"compute"!==t?!0===e.isAtomic?(d("WebGPURenderer: Atomic operations are only supported in compute shaders."),ri.READ_WRITE):ri.READ_ONLY:e.access}getStorageAccess(e,t){return oC[this.getNodeAccess(e,t)]}getUniformFromNode(e,t,r,s=null){const i=super.getUniformFromNode(e,t,r,s),n=this.getDataFromNode(e,r,this.globalCache);if(void 0===n.uniformGPU){let a;const o=e.groupNode,u=o.name,l=this.getBindGroupArray(u,r);if("texture"===t||"cubeTexture"===t||"cubeDepthTexture"===t||"storageTexture"===t||"texture3D"===t){let s=null;const n=this.getNodeAccess(e,r);"texture"===t||"storageTexture"===t?s=!0===e.value.is3DTexture?new aR(i.name,i.node,o,n):new iR(i.name,i.node,o,n):"cubeTexture"===t||"cubeDepthTexture"===t?s=new nR(i.name,i.node,o,n):"texture3D"===t&&(s=new aR(i.name,i.node,o,n)),s.store=!0===e.isStorageTextureNode,s.mipLevel=s.store?e.mipLevel:0,s.setVisibility(lC[r]);if(!0===e.value.isCubeTexture||!1===this.isUnfilterable(e.value)&&!1===s.store){const e=new jw(`${i.name}_sampler`,i.node,o);e.setVisibility(lC[r]),l.push(e,s),a=[e,s]}else l.push(s),a=[s]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){const n=this.getSharedDataFromNode(e);let u=n.buffer;if(void 0===u){u=new("buffer"===t?QS:Yw)(e,o),n.buffer=u}u.setVisibility(u.getVisibility()|lC[r]),l.push(u),a=u,i.name=s||"NodeBuffer_"+i.id}else{let e=this.uniformGroups[u];void 0===e&&(e=new eR(u,o),e.setVisibility($R.VERTEX|$R.FRAGMENT|$R.COMPUTE),this.uniformGroups[u]=e),-1===l.indexOf(e)&&l.push(e),a=this.getNodeUniform(i,t);const r=a.name;e.uniforms.some(e=>e.name===r)||e.addUniform(a)}n.uniformGPU=a}return i}getBuiltin(e,t,r,s=this.shaderStage){const i=this.builtins[s]||(this.builtins[s]=new Map);return!1===i.has(e)&&i.set(e,{name:e,property:t,type:r}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,r=this.flowShaderNode(e),s=[];for(const e of t.inputs)s.push(e.name+" : "+this.getType(e.type));let i=`fn ${t.name}( ${s.join(", ")} ) -> ${this.getType(t.type)} {\n${r.vars}\n${r.code}\n`;return r.result&&(i+=`\treturn ${r.result};\n`),i+="\n}\n",i}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4<f32>")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){const t=[],r=this.directives[e];if(void 0!==r)for(const e of r)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array<f32, ${e} >`,"vertex")}getBuiltins(e){const t=[],r=this.builtins[e];if(void 0!==r)for(const{name:e,property:s,type:i}of r.values())t.push(`@builtin( ${e} ) ${s} : ${i}`);return t.join(",\n\t")}getScopedArray(e,t,r,s){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:r,bufferCount:s}),e}getScopedArrays(e){if("compute"!==e)return;const t=[];for(const{name:e,scope:r,bufferType:s,bufferCount:i}of this.scopedArrays.values()){const n=this.getType(s);t.push(`var<${r}> ${e}: array< ${n}, ${i} >;`)}return t.join("\n")}getAttributes(e){const t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","globalId","vec3<u32>","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3<u32>","attribute"),this.getBuiltin("local_invocation_id","localId","vec3<u32>","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3<u32>","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){const e=this.getBuiltins("attribute");e&&t.push(e);const r=this.getAttributesArray();for(let e=0,s=r.length;e<s;e++){const s=r[e],i=s.name,n=this.getType(s.type);t.push(`@location( ${e} ) ${i} : ${n}`)}}return t.join(",\n\t")}getStructMembers(e){const t=[];for(const r of e.members){const s=e.output?"@location( "+r.index+" ) ":"";let i=this.getType(r.type);r.atomic&&(i="atomic< "+i+" >"),t.push(`\t${s+r.name} : ${i}`)}return e.output&&t.push(`\t${this.getBuiltins("output")}`),t.join(",\n")}getStructs(e){let t="";const r=this.structs[e];if(r.length>0){const e=[];for(const t of r){let r=`struct ${t.name} {\n`;r+=this.getStructMembers(t),r+="\n};",e.push(r)}t="\n"+e.join("\n\n")+"\n"}return t}getVar(e,t,r=null){let s=`var ${t} : `;return s+=null!==r?this.generateArrayDeclaration(e,r):this.getType(e),s}getVars(e){const t=[],r=this.vars[e];if(void 0!==r)for(const e of r)t.push(`\t${this.getVar(e.type,e.name,e.count)};`);return`\n${t.join("\n")}\n`}getVaryings(e){const t=[];if("vertex"===e&&this.getBuiltin("position","builtinClipSpace","vec4<f32>","vertex"),"vertex"===e||"fragment"===e){const r=this.varyings,s=this.vars[e];for(let i=0;i<r.length;i++){const n=r[i];if(n.needsInterpolation){let e=`@location( ${i} )`;if(n.interpolationType){const t=null!==n.interpolationSampling?`, ${n.interpolationSampling} )`:" )";e+=` @interpolate( ${n.interpolationType}${t}`}else/^(int|uint|ivec|uvec)/.test(n.type)&&(e+=" @interpolate(flat, either)");t.push(`${e} ${n.name} : ${this.getType(n.type)}`)}else"vertex"===e&&!1===s.includes(n)&&s.push(n)}}const r=this.getBuiltins(e);r&&t.push(r);const s=t.join(",\n\t");return"vertex"===e?this._getWGSLStruct("VaryingsStruct","\t"+s):s}isCustomStruct(e){const t=e.value,r=e.node,s=(t.isBufferAttribute||t.isInstancedBufferAttribute)&&null!==r.structTypeNode,i=r.value&&r.value.array&&"number"==typeof r.value.itemSize&&r.value.array.length>r.value.itemSize;return s&&!i}getUniforms(e){const t=this.uniforms[e],r=[],s=[],i=[],n={};for(const i of t){const t=i.groupNode.name,a=this.bindingsIndexes[t];if("texture"===i.type||"cubeTexture"===i.type||"cubeDepthTexture"===i.type||"storageTexture"===i.type||"texture3D"===i.type){const t=i.node.value;let s;(!0===t.isCubeTexture||!1===this.isUnfilterable(t)&&!0!==i.node.isStorageTextureNode)&&(this.isSampleCompare(t)?r.push(`@binding( ${a.binding++} ) @group( ${a.group} ) var ${i.name}_sampler : sampler_comparison;`):r.push(`@binding( ${a.binding++} ) @group( ${a.group} ) var ${i.name}_sampler : sampler;`));let n="";const{primarySamples:o}=this.renderer.backend.utils.getTextureSampleData(t);if(o>1&&(n="_multisampled"),!0===t.isCubeTexture&&!0===t.isDepthTexture)s="texture_depth_cube";else if(!0===t.isCubeTexture)s="texture_cube<f32>";else if(!0===t.isDepthTexture)s=this.renderer.backend.compatibilityMode&&null===t.compareFunction?`texture${n}_2d<f32>`:`texture_depth${n}_2d${!0===t.isArrayTexture?"_array":""}`;else if(!0===i.node.isStorageTextureNode){const r=tC(t),n=this.getStorageAccess(i.node,e),a=i.node.value.is3DTexture,o=i.node.value.isArrayTexture;s=`texture_storage_${a?"3d":"2d"+(o?"_array":"")}<${r}, ${n}>`}else if(!0===t.isArrayTexture||!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture)s="texture_2d_array<f32>";else if(!0===t.is3DTexture||!0===t.isData3DTexture)s="texture_3d<f32>";else{s=`texture${n}_2d<${this.getComponentTypeFromTexture(t).charAt(0)}32>`}r.push(`@binding( ${a.binding++} ) @group( ${a.group} ) var ${i.name} : ${s};`)}else if("buffer"===i.type||"storageBuffer"===i.type||"indirectStorageBuffer"===i.type){const t=i.node,r=this.getType(t.getNodeType(this)),n=t.bufferCount,o=n>0&&"buffer"===i.type?", "+n:"",u=t.isStorageBufferNode?`storage, ${this.getStorageAccess(t,e)}`:"uniform";if(this.isCustomStruct(i))s.push(`@binding( ${a.binding++} ) @group( ${a.group} ) var<${u}> ${i.name} : ${r};`);else{const e=`\tvalue : array< ${t.isAtomic?`atomic<${r}>`:`${r}`}${o} >`;s.push(this._getWGSLStructBinding(i.name,e,u,a.binding++,a.group))}}else{const e=i.groupNode.name;if(void 0===n[e]){const t=this.uniformGroups[e];if(void 0!==t){const r=[];for(const e of t.uniforms){const t=e.getType(),s=this.getType(this.getVectorType(t));r.push(`\t${e.name} : ${s}`)}let s=this.uniformGroupsBindings[e];void 0===s&&(s={index:a.binding++,id:a.group},this.uniformGroupsBindings[e]=s),n[e]={index:s.index,id:s.id,snippets:r}}}}}for(const e in n){const t=n[e];i.push(this._getWGSLStructBinding(e,t.snippets.join(",\n"),"uniform",t.index,t.id))}return[...r,...s,...i].join("\n")}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){this.shaderStage=t;const r=e[t];r.uniforms=this.getUniforms(t),r.attributes=this.getAttributes(t),r.varyings=this.getVaryings(t),r.structs=this.getStructs(t),r.vars=this.getVars(t),r.codes=this.getCodes(t),r.directives=this.getDirectives(t),r.scopedArrays=this.getScopedArrays(t);let s="// code\n\n";s+=this.flowCode[t];const i=this.flowNodes[t],n=i[i.length-1],a=n.outputNode,o=void 0!==a&&!0===a.isOutputStructNode;for(const e of i){const i=this.getFlowData(e),u=e.name;if(u&&(s.length>0&&(s+="\n"),s+=`\t// flow -> ${u}\n`),s+=`${i.code}\n\t`,e===n&&"compute"!==t)if(s+="// result\n\n\t","vertex"===t)s+=`varyings.builtinClipSpace = ${i.result};`;else if("fragment"===t)if(o)r.returnType=a.getNodeType(this),r.structs+="var<private> output : "+r.returnType+";",s+=`return ${i.result};`;else{let e="\t@location(0) color: vec4<f32>";const t=this.getBuiltins("output");t&&(e+=",\n\t"+t),r.returnType="OutputStruct",r.structs+=this._getWGSLStruct("OutputStruct",e),r.structs+="\nvar<private> output : OutputStruct;",s+=`output.color = ${i.result};\n\n\treturn output;`}}r.flow=s}if(this.shaderStage=null,null!==this.material)this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment);else{const t=this.object.workgroupSize;this.computeShader=this._getWGSLComputeCode(e.compute,t)}}getMethod(e,t=null){let r;return null!==t&&(r=this._getWGSLMethod(e+"_"+t)),void 0===r&&(r=this._getWGSLMethod(e)),r||e}getBitcastMethod(e){return`bitcast<${this.getType(e)}>`}getFloatPackingMethod(e){return this.getMethod(`floatpack_${e}_2x16`)}getFloatUnpackingMethod(e){return this.getMethod(`floatunpack_${e}_2x16`)}getTernary(e,t,r){return`select( ${r}, ${t}, ${e} )`}getType(e){return hC[e]||e}isAvailable(e){let t=dC[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),dC[e]=t),t}getUniformBufferLimit(){return this.renderer.backend.device.limits.maxUniformBufferBindingSize}_getWGSLMethod(e){return void 0!==gC[e]&&this._include(e),mC[e]}_include(e){const t=gC[e];return t.build(this),this.addInclude(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// structs\n${e.structs}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\nvar<private> varyings : VaryingsStruct;\n\n// codes\n${e.codes}\n\n@vertex\nfn main( ${e.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(e){return`${this.getSignature()}\n// global\n${fC}\n\n// structs\n${e.structs}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@fragment\nfn main( ${e.varyings} ) -> ${e.returnType} {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLComputeCode(e,t){const[r,s,i]=t;return`${this.getSignature()}\n// directives\n${e.directives}\n\n// system\nvar<private> instanceIndex : u32;\n\n// locals\n${e.scopedArrays}\n\n// structs\n${e.structs}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@compute @workgroup_size( ${r}, ${s}, ${i} )\nfn main( ${e.attributes} ) {\n\n\t// system\n\tinstanceIndex = globalId.x\n\t\t+ globalId.y * ( ${r} * numWorkgroups.x )\n\t\t+ globalId.z * ( ${r} * numWorkgroups.x ) * ( ${s} * numWorkgroups.y );\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLStruct(e,t){return`\nstruct ${e} {\n${t}\n};`}_getWGSLStructBinding(e,t,r,s=0,i=0){const n=e+"Struct";return`${this._getWGSLStruct(n,t)}\n@binding( ${s} ) @group( ${i} )\nvar<${r}> ${e} : ${n};`}}class bC{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return e.depth&&(t=null!==e.depthTexture?this.getTextureFormatGPU(e.depthTexture):e.stencil?WE:zE),t}getTextureFormatGPU(e){return this.backend.get(e).format}getTextureSampleData(e){let t;if(e.isFramebufferTexture)t=1;else if(e.isDepthTexture&&!e.renderTarget){const e=this.backend.renderer,r=e.getRenderTarget();t=r?r.samples:e.currentSamples}else e.renderTarget&&(t=e.renderTarget.samples);t=t||1;const r=t>1&&null!==e.renderTarget&&!0!==e.isDepthTexture&&!0!==e.isFramebufferTexture;return{samples:t,primarySamples:r?1:t,isMSAA:r}}getCurrentColorFormat(e){let t;return t=null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat(),t}getCurrentColorFormats(e){return null!==e.textures?e.textures.map(e=>this.getTextureFormatGPU(e)):[this.getPreferredCanvasFormat()]}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?OR:e.isLineSegments||e.isMesh&&!0===t.wireframe?VR:e.isLine?kR:e.isMesh?GR:void 0}getSampleCount(e){return e>=4?4:1}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.currentSamples)}getPreferredCanvasFormat(){const e=this.backend.parameters.outputType;if(void 0===e)return navigator.gpu.getPreferredCanvasFormat();if(e===$e)return wE;if(e===_e)return OE;throw new Error("Unsupported output buffer type.")}}const xC=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]);"undefined"!=typeof Float16Array&&xC.set(Float16Array,["float16"]);const TC=new Map([[ot,["float16"]]]),_C=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class vC{constructor(e){this.backend=e}createAttribute(e,t){const r=this._getBufferAttribute(e),s=this.backend,i=s.get(r);let n=i.buffer;if(void 0===n){const a=s.device;let o=r.array;if(!1===e.normalized)if(o.constructor===Int16Array||o.constructor===Int8Array)o=new Int32Array(o);else if((o.constructor===Uint16Array||o.constructor===Uint8Array)&&(o=new Uint32Array(o),t&GPUBufferUsage.INDEX))for(let e=0;e<o.length;e++)65535===o[e]&&(o[e]=4294967295);if(r.array=o,(r.isStorageBufferAttribute||r.isStorageInstancedBufferAttribute)&&3===r.itemSize){o=new o.constructor(4*r.count);for(let e=0;e<r.count;e++)o.set(r.array.subarray(3*e,3*e+3),4*e);r.itemSize=4,r.array=o,i._force3to4BytesAlignment=!0}const u=o.byteLength,l=u+(4-u%4)%4;n=a.createBuffer({label:r.name,size:l,usage:t,mappedAtCreation:!0}),new o.constructor(n.getMappedRange()).set(o),n.unmap(),i.buffer=n}}updateAttribute(e){const t=this._getBufferAttribute(e),r=this.backend,s=r.device,i=r.get(t),n=r.get(t).buffer;let a=t.array;if(!0===i._force3to4BytesAlignment){a=new a.constructor(4*t.count);for(let e=0;e<t.count;e++)a.set(t.array.subarray(3*e,3*e+3),4*e);t.array=a}const o=t.updateRanges;if(0===o.length)s.queue.writeBuffer(n,0,a,0);else{const e=Xr(a),r=e?1:a.BYTES_PER_ELEMENT;for(let t=0,u=o.length;t<u;t++){const u=o[t];let l,d;if(!0===i._force3to4BytesAlignment){l=4*Math.floor(u.start/3)*r,d=4*Math.ceil(u.count/3)*r}else l=u.start*r,d=u.count*r;const c=l*(e?a.BYTES_PER_ELEMENT:1);s.queue.writeBuffer(n,c,a,l,d)}t.clearUpdateRanges()}}createShaderVertexBuffers(e){const t=e.getAttributes(),r=new Map;for(let e=0;e<t.length;e++){const s=t[e],i=s.array.BYTES_PER_ELEMENT,n=this._getBufferAttribute(s);let a=r.get(n);if(void 0===a){let e,t;!0===s.isInterleavedBufferAttribute?(e=s.data.stride*i,t=s.data.isInstancedInterleavedBuffer?Ww:zw):(e=s.itemSize*i,t=s.isInstancedBufferAttribute?Ww:zw),!1!==s.normalized||s.array.constructor!==Int16Array&&s.array.constructor!==Uint16Array||(e=4),a={arrayStride:e,attributes:[],stepMode:t},r.set(n,a)}const o=this._getVertexFormat(s),u=!0===s.isInterleavedBufferAttribute?s.offset*i:0;a.attributes.push({shaderLocation:e,offset:u,format:o})}return Array.from(r.values())}destroyAttribute(e){const t=this.backend;t.get(this._getBufferAttribute(e)).buffer.destroy(),t.delete(e)}async getArrayBufferAsync(e){const t=this.backend,r=t.device,s=t.get(this._getBufferAttribute(e)).buffer,i=s.size,n=r.createBuffer({label:`${e.name}_readback`,size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=r.createCommandEncoder({label:`readback_encoder_${e.name}`});a.copyBufferToBuffer(s,0,n,0,i);const o=a.finish();r.queue.submit([o]),await n.mapAsync(GPUMapMode.READ);const u=n.getMappedRange(),l=new e.array.constructor(u.slice(0));return n.unmap(),l.buffer}_getVertexFormat(e){const{itemSize:t,normalized:r}=e,s=e.array.constructor,i=e.constructor;let n;if(1===t)n=_C.get(s);else{const e=(TC.get(i)||xC.get(s))[r?1:0];if(e){const r=s.BYTES_PER_ELEMENT*t,i=4*Math.floor((r+3)/4)/s.BYTES_PER_ELEMENT;if(i%1)throw new Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");n=`${e}x${i}`}}return n||o("WebGPUAttributeUtils: Vertex format not supported yet."),n}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}class NC{constructor(e){this.layoutGPU=e,this.usedTimes=0}}class SC{constructor(e){this.backend=e,this._bindGroupLayoutCache=new Map}createBindingsLayout(e){const t=this.backend,r=t.device,s=t.get(e);if(s.layout)return s.layout.layoutGPU;const i=this._createLayoutEntries(e),n=Is(JSON.stringify(i));let a=this._bindGroupLayoutCache.get(n);return void 0===a&&(a=new NC(r.createBindGroupLayout({entries:i})),this._bindGroupLayoutCache.set(n,a)),a.usedTimes++,s.layout=a,s.layoutKey=n,a.layoutGPU}createBindings(e,t,r,s=0){const{backend:i}=this,n=i.get(e),a=this.createBindingsLayout(e);let o;r>0&&(void 0===n.groups&&(n.groups=[],n.versions=[]),n.versions[r]===s&&(o=n.groups[r])),void 0===o&&(o=this.createBindGroup(e,a),r>0&&(n.groups[r]=o,n.versions[r]=s)),n.group=o}updateBinding(e){const t=this.backend,r=t.device,s=e.buffer,i=t.get(e).buffer,n=e.updateRanges;if(0===n.length)r.queue.writeBuffer(i,0,s,0);else{const e=Xr(s),t=e?1:s.BYTES_PER_ELEMENT;for(let a=0,o=n.length;a<o;a++){const o=n[a],u=o.start*t,l=o.count*t,d=u*(e?s.BYTES_PER_ELEMENT:1);r.queue.writeBuffer(i,d,s,u,l)}}}createBindGroupIndex(e,t){const r=this.backend.device,s=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,i=e[0],n=r.createBuffer({label:"bindingCameraIndex_"+i,size:16,usage:s});r.queue.writeBuffer(n,0,e,0);const a=[{binding:0,resource:{buffer:n}}];return r.createBindGroup({label:"bindGroupCameraIndex_"+i,layout:t,entries:a})}createBindGroup(e,t){const r=this.backend,s=r.device;let i=0;const n=[];for(const t of e.bindings){if(t.isUniformBuffer){const e=r.get(t);if(void 0===e.buffer){const r=t.byteLength,i=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,n=[];t.visibility&$R.VERTEX&&n.push("vertex"),t.visibility&$R.FRAGMENT&&n.push("fragment"),t.visibility&$R.COMPUTE&&n.push("compute");const a=`(${n.join(",")})`,o=s.createBuffer({label:`bindingBuffer${t.id}_${t.name}_${a}`,size:r,usage:i});e.buffer=o}n.push({binding:i,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){const e=r.get(t.attribute).buffer;n.push({binding:i,resource:{buffer:e}})}else if(t.isSampledTexture){const e=r.get(t.texture);let a;if(void 0!==e.externalTexture)a=s.importExternalTexture({source:e.externalTexture});else{const r=t.store?1:e.texture.mipLevelCount,s=t.store?t.mipLevel:0;let i=`view-${e.texture.width}-${e.texture.height}`;if(e.texture.depthOrArrayLayers>1&&(i+=`-${e.texture.depthOrArrayLayers}`),i+=`-${r}-${s}`,a=e[i],void 0===a){const n=$w;let o;o=t.isSampledCubeTexture?kw:t.isSampledTexture3D?Gw:t.texture.isArrayTexture||t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?Vw:Ow,a=e[i]=e.texture.createView({aspect:n,dimension:o,mipLevelCount:r,baseMipLevel:s})}}n.push({binding:i,resource:a})}else if(t.isSampler){const e=r.get(t.texture);n.push({binding:i,resource:e.sampler})}i++}return s.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:n})}_createLayoutEntries(e){const t=[];let r=0;for(const s of e.bindings){const e=this.backend,i={binding:r,visibility:s.visibility};if(s.isUniformBuffer||s.isStorageBuffer){const e={};s.isStorageBuffer&&(s.visibility&$R.COMPUTE&&(s.access===ri.READ_WRITE||s.access===ri.WRITE_ONLY)?e.type=Sw:e.type=Rw),i.buffer=e}else if(s.isSampledTexture&&s.store){const e={};e.format=this.backend.get(s.texture).texture.format;const t=s.access;e.access=t===ri.READ_WRITE?ww:t===ri.WRITE_ONLY?Ew:Aw,s.texture.isArrayTexture?e.viewDimension=Vw:s.texture.is3DTexture&&(e.viewDimension=Gw),i.storageTexture=e}else if(s.isSampledTexture){const t={},{primarySamples:r}=e.utils.getTextureSampleData(s.texture);if(r>1&&(t.multisampled=!0,s.texture.isDepthTexture||(t.sampleType=Fw)),s.texture.isDepthTexture)e.compatibilityMode&&null===s.texture.compareFunction?t.sampleType=Fw:t.sampleType=Lw;else if(s.texture.isDataTexture||s.texture.isDataArrayTexture||s.texture.isData3DTexture){const e=s.texture.type;e===R?t.sampleType=Pw:e===S?t.sampleType=Dw:e===Y&&(this.backend.hasFeature("float32-filterable")?t.sampleType=Bw:t.sampleType=Fw)}s.isSampledCubeTexture?t.viewDimension=kw:s.texture.isArrayTexture||s.texture.isDataArrayTexture||s.texture.isCompressedArrayTexture?t.viewDimension=Vw:s.isSampledTexture3D&&(t.viewDimension=Gw),i.texture=t}else if(s.isSampler){const t={};s.texture.isDepthTexture&&(null!==s.texture.compareFunction&&e.hasCompatibility(E.TEXTURE_COMPARE)?t.type=Mw:t.type=Cw),i.sampler=t}else o(`WebGPUBindingUtils: Unsupported binding "${s}".`);t.push(i),r++}return t}deleteBindGroupData(e){const{backend:t}=this,r=t.get(e);r.layout&&(r.layout.usedTimes--,0===r.layout.usedTimes&&this._bindGroupLayoutCache.delete(r.layoutKey),r.layout=void 0,r.layoutKey=void 0)}dispose(){this._bindGroupLayoutCache.clear()}}class RC{constructor(e){this.backend=e,this._activePipelines=new WeakMap}setPipeline(e,t){this._activePipelines.get(e)!==t&&(e.setPipeline(t),this._activePipelines.set(e,t))}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:r,material:s,geometry:i,pipeline:n}=e,{vertexProgram:a,fragmentProgram:u}=n,l=this.backend,d=l.device,c=l.utils,h=l.get(n),p=[];for(const t of e.getBindings()){const e=l.get(t),{layoutGPU:r}=e.layout;p.push(r)}const g=l.attributeUtils.createShaderVertexBuffers(e);let m;s.blending===se||s.blending===ze&&!1===s.transparent||(m=this._getBlending(s));let f={};!0===s.stencilWrite&&(f={compare:this._getStencilCompare(s),failOp:this._getStencilOperation(s.stencilFail),depthFailOp:this._getStencilOperation(s.stencilZFail),passOp:this._getStencilOperation(s.stencilZPass)});const y=this._getColorWriteMask(s),b=[];if(null!==e.context.textures){const t=e.context.textures,r=e.context.mrt;for(let e=0;e<t.length;e++){const s=t[e],i=c.getTextureFormatGPU(s);let n;if(null!==r)if(!0!==this.backend.compatibilityMode){const e=r.getBlendMode(s.name);e.blending===je?n=m:e.blending!==se&&(n=this._getBlending(e))}else v("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets."),n=m;else n=m;b.push({format:i,blend:n,writeMask:y})}}else{const t=c.getCurrentColorFormat(e.context);b.push({format:t,blend:m,writeMask:y})}const x=l.get(a).module,T=l.get(u).module,_=this._getPrimitiveState(r,i,s),N=this._getDepthCompare(s),S=c.getCurrentDepthStencilFormat(e.context),R=this._getSampleCount(e.context),E={label:`renderPipeline_${s.name||s.type}_${s.id}`,vertex:Object.assign({},x,{buffers:g}),fragment:Object.assign({},T,{targets:b}),primitive:_,multisample:{count:R,alphaToCoverageEnabled:s.alphaToCoverage&&R>1},layout:d.createPipelineLayout({bindGroupLayouts:p})},A={},w=e.context.depth,C=e.context.stencil;if(!0!==w&&!0!==C||(!0===w&&(A.format=S,A.depthWriteEnabled=s.depthWrite,A.depthCompare=N),!0===C&&(A.stencilFront=f,A.stencilBack=f,A.stencilReadMask=s.stencilFuncMask,A.stencilWriteMask=s.stencilWriteMask),!0===s.polygonOffset&&(A.depthBias=s.polygonOffsetUnits,A.depthBiasSlopeScale=s.polygonOffsetFactor,A.depthBiasClamp=0),E.depthStencil=A),d.pushErrorScope("validation"),null===t)h.pipeline=d.createRenderPipeline(E),d.popErrorScope().then(e=>{null!==e&&(h.error=!0,o(e.message))});else{const e=new Promise(async e=>{try{h.pipeline=await d.createRenderPipelineAsync(E)}catch(e){}const t=await d.popErrorScope();null!==t&&(h.error=!0,o(t.message)),e()});t.push(e)}}createBundleEncoder(e,t="renderBundleEncoder"){const r=this.backend,{utils:s,device:i}=r,n=s.getCurrentDepthStencilFormat(e),a={label:t,colorFormats:s.getCurrentColorFormats(e),depthStencilFormat:n,sampleCount:this._getSampleCount(e)};return i.createRenderBundleEncoder(a)}createComputePipeline(e,t){const r=this.backend,s=r.device,i=r.get(e.computeProgram).module,n=r.get(e),a=[];for(const e of t){const t=r.get(e),{layoutGPU:s}=t.layout;a.push(s)}n.pipeline=s.createComputePipeline({compute:i,layout:s.createPipelineLayout({bindGroupLayouts:a})})}_getBlending(e){let t,r;const s=e.blending,i=e.blendSrc,n=e.blendDst,a=e.blendEquation;if(s===ht){const s=null!==e.blendSrcAlpha?e.blendSrcAlpha:i,o=null!==e.blendDstAlpha?e.blendDstAlpha:n,u=null!==e.blendEquationAlpha?e.blendEquationAlpha:a;t={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(n),operation:this._getBlendOperation(a)},r={srcFactor:this._getBlendFactor(s),dstFactor:this._getBlendFactor(o),operation:this._getBlendOperation(u)}}else{const i=(e,s,i,n)=>{t={srcFactor:e,dstFactor:s,operation:lw},r={srcFactor:i,dstFactor:n,operation:lw}};if(e.premultipliedAlpha)switch(s){case ze:i(QA,tw,QA,tw);break;case qt:i(QA,QA,QA,QA);break;case Ht:i(YA,JA,YA,QA);break;case Wt:i(rw,tw,YA,QA)}else switch(s){case ze:i(ew,tw,QA,tw);break;case qt:i(ew,QA,QA,QA);break;case Ht:o(`WebGPURenderer: "SubtractiveBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`);break;case Wt:o(`WebGPURenderer: "MultiplyBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`)}}if(void 0!==t&&void 0!==r)return{color:t,alpha:r};o("WebGPURenderer: Invalid blending: ",s)}_getBlendFactor(e){let t;switch(e){case pt:t=YA;break;case kt:t=QA;break;case Vt:t=ZA;break;case Dt:t=JA;break;case We:t=ew;break;case He:t=tw;break;case It:t=rw;break;case Pt:t=sw;break;case Ut:t=iw;break;case Lt:t=nw;break;case Ot:t=aw;break;case 211:t=ow;break;case 212:t=uw;break;default:o("WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const r=e.stencilFunc;switch(r){case rs:t=zR;break;case ts:t=YR;break;case es:t=WR;break;case Jr:t=qR;break;case Zr:t=HR;break;case Qr:t=KR;break;case Yr:t=jR;break;case Kr:t=XR;break;default:o("WebGPURenderer: Invalid stencil function.",r)}return t}_getStencilOperation(e){let t;switch(e){case ds:t=fw;break;case ls:t=yw;break;case us:t=bw;break;case os:t=xw;break;case as:t=Tw;break;case ns:t=_w;break;case is:t=vw;break;case ss:t=Nw;break;default:o("WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case qe:t=lw;break;case Ft:t=dw;break;case Bt:t=cw;break;case hs:t=hw;break;case cs:t=pw;break;default:o("WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,r){const s={},i=this.backend.utils;s.topology=i.getPrimitiveTopology(e,r),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(s.stripIndexFormat=t.index.array instanceof Uint16Array?iE:nE);let n=r.side===L;return e.isMesh&&e.matrixWorld.determinant()<0&&(n=!n),s.frontFace=!0===n?tE:eE,s.cullMode=r.side===P?rE:sE,s}_getColorWriteMask(e){return!0===e.colorWrite?mw:gw}_getDepthCompare(e){let t;if(!1===e.depthTest)t=YR;else{const r=this.backend.parameters.reversedDepthBuffer?tr[e.depthFunc]:e.depthFunc;switch(r){case er:t=zR;break;case Jt:t=YR;break;case Zt:t=WR;break;case Qt:t=qR;break;case Yt:t=HR;break;case Kt:t=KR;break;case Xt:t=jR;break;case jt:t=XR;break;default:o("WebGPUPipelineUtils: Invalid depth function.",r)}}return t}}class EC extends DR{constructor(e,t,r=2048){super(r),this.device=e,this.type=t,this.querySet=this.device.createQuerySet({type:"timestamp",count:this.maxQueries,label:`queryset_global_timestamp_${t}`});const s=8*this.maxQueries;this.resolveBuffer=this.device.createBuffer({label:`buffer_timestamp_resolve_${t}`,size:s,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.resultBuffer=this.device.createBuffer({label:`buffer_timestamp_result_${t}`,size:s,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ})}allocateQueriesForContext(e){if(!this.trackTimestamp||this.isDisposed)return null;if(this.currentQueryIndex+2>this.maxQueries)return v(`WebGPUTimestampQueryPool [${this.type}]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${this.type.toUpperCase()} ).`),null;const t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryOffsets.set(e,t),t}async resolveQueriesAsync(){if(!this.trackTimestamp||0===this.currentQueryIndex||this.isDisposed)return this.lastValue;if(this.pendingResolve)return this.pendingResolve;this.pendingResolve=this._resolveQueries();try{return await this.pendingResolve}finally{this.pendingResolve=null}}async _resolveQueries(){if(this.isDisposed)return this.lastValue;try{if("unmapped"!==this.resultBuffer.mapState)return this.lastValue;const e=new Map(this.queryOffsets),t=this.currentQueryIndex,r=8*t;this.currentQueryIndex=0,this.queryOffsets.clear();const s=this.device.createCommandEncoder();s.resolveQuerySet(this.querySet,0,t,this.resolveBuffer,0),s.copyBufferToBuffer(this.resolveBuffer,0,this.resultBuffer,0,r);const i=s.finish();if(this.device.queue.submit([i]),"unmapped"!==this.resultBuffer.mapState)return this.lastValue;if(await this.resultBuffer.mapAsync(GPUMapMode.READ,0,r),this.isDisposed)return"mapped"===this.resultBuffer.mapState&&this.resultBuffer.unmap(),this.lastValue;const n=new BigUint64Array(this.resultBuffer.getMappedRange(0,r)),a={},o=[];for(const[t,r]of e){const e=t.match(/^(.*):f(\d+)$/),s=parseInt(e[2]);!1===o.includes(s)&&o.push(s),void 0===a[s]&&(a[s]=0);const i=n[r],u=n[r+1],l=Number(u-i)/1e6;this.timestamps.set(t,l),a[s]+=l}const u=a[o[o.length-1]];return this.resultBuffer.unmap(),this.lastValue=u,this.frames=o,u}catch(e){return o("Error resolving queries:",e),"mapped"===this.resultBuffer.mapState&&this.resultBuffer.unmap(),this.lastValue}}async dispose(){if(!this.isDisposed){if(this.isDisposed=!0,this.pendingResolve)try{await this.pendingResolve}catch(e){o("Error waiting for pending resolve:",e)}if(this.resultBuffer&&"mapped"===this.resultBuffer.mapState)try{this.resultBuffer.unmap()}catch(e){o("Error unmapping buffer:",e)}this.querySet&&(this.querySet.destroy(),this.querySet=null),this.resolveBuffer&&(this.resolveBuffer.destroy(),this.resolveBuffer=null),this.resultBuffer&&(this.resultBuffer.destroy(),this.resultBuffer=null),this.queryOffsets.clear(),this.pendingResolve=null}}}class AC extends yR{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.compatibilityMode=null,this.device=null,this.defaultRenderPassdescriptor=null,this.utils=new bC(this),this.attributeUtils=new vC(this),this.bindingUtils=new SC(this),this.pipelineUtils=new RC(this),this.textureUtils=new eC(this),this.occludedResolveCache=new Map;const t="undefined"==typeof navigator||!1===/Android/.test(navigator.userAgent);this._compatibility={[E.TEXTURE_COMPARE]:t}}async init(e){await super.init(e);const t=this.parameters;let r;if(void 0===t.device){const e={powerPreference:t.powerPreference,featureLevel:"compatibility"},s="undefined"!=typeof navigator?await navigator.gpu.requestAdapter(e):null;if(null===s)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const i=Object.values(Hw),n=[];for(const e of i)s.features.has(e)&&n.push(e);const a={requiredFeatures:n,requiredLimits:t.requiredLimits};r=await s.requestDevice(a)}else r=t.device;this.compatibilityMode=!r.features.has("core-features-and-limits"),this.compatibilityMode&&(e._samples=0),r.lost.then(t=>{if("destroyed"===t.reason)return;const r={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(r)}),this.device=r,this.trackTimestamp=this.trackTimestamp&&this.hasFeature(Hw.TimestampQuery),this.updateSize()}get context(){const e=this.renderer.getCanvasTarget(),t=this.get(e);let r=t.context;if(void 0===r){const s=this.parameters;r=!0===e.isDefaultCanvasTarget&&void 0!==s.context?s.context:e.domElement.getContext("webgpu"),"setAttribute"in e.domElement&&e.domElement.setAttribute("data-engine",`three.js r${ut} webgpu`);const i=s.alpha?"premultiplied":"opaque",n=s.outputType===_e?"extended":"standard";r.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:i,toneMapping:{mode:n}}),t.context=r}return r}get coordinateSystem(){return h}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){const e=this.renderer,t=e.getCanvasTarget(),r=this.get(t),s=e.currentSamples;let i=r.descriptor;if(void 0===i||r.samples!==s){i={colorAttachments:[{view:null}]},!0!==e.depth&&!0!==e.stencil||(i.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView()});const t=i.colorAttachments[0];s>0?t.view=this.textureUtils.getColorBuffer().createView():t.resolveTarget=void 0,r.descriptor=i,r.samples=s}const n=i.colorAttachments[0];return s>0?n.resolveTarget=this.context.getCurrentTexture().createView():n.view=this.context.getCurrentTexture().createView(),i}_isRenderCameraDepthArray(e){return e.depthTexture&&e.depthTexture.image.depth>1&&e.camera.isArrayCamera}_getRenderPassDescriptor(e,t={}){const r=e.renderTarget,s=this.get(r);let i=s.descriptors;void 0!==i&&s.width===r.width&&s.height===r.height&&s.samples===r.samples||(i={},s.descriptors=i);const n=e.getCacheKey();let a=i[n];if(void 0===a){const t=e.textures,o=[];let u;const l=this._isRenderCameraDepthArray(e);for(let s=0;s<t.length;s++){const i=this.get(t[s]),n={label:`colorAttachment_${s}`,baseMipLevel:e.activeMipmapLevel,mipLevelCount:1,baseArrayLayer:e.activeCubeFace,arrayLayerCount:1,dimension:Ow};if(r.isRenderTarget3D)u=e.activeCubeFace,n.baseArrayLayer=0,n.dimension=Gw,n.depthOrArrayLayers=t[s].image.depth;else if(r.isRenderTarget&&t[s].image.depth>1)if(!0===l){const t=e.camera.cameras;for(let e=0;e<t.length;e++){const t={...n,baseArrayLayer:e,arrayLayerCount:1,dimension:Ow},r=i.texture.createView(t);o.push({view:r,resolveTarget:void 0,depthSlice:void 0})}}else n.dimension=Vw,n.depthOrArrayLayers=t[s].image.depth;if(!0!==l){const e=i.texture.createView(n);let t,r;void 0!==i.msaaTexture?(t=i.msaaTexture.createView(),r=e):(t=e,r=void 0),o.push({view:t,resolveTarget:r,depthSlice:u})}}if(a={textureViews:o},e.depth){const t=this.get(e.depthTexture),r={};(e.depthTexture.isArrayTexture||e.depthTexture.isCubeTexture)&&(r.dimension=Ow,r.arrayLayerCount=1,r.baseArrayLayer=e.activeCubeFace),a.depthStencilView=t.texture.createView(r)}i[n]=a,s.width=r.width,s.height=r.height,s.samples=r.samples,s.activeMipmapLevel=e.activeMipmapLevel,s.activeCubeFace=e.activeCubeFace}const o={colorAttachments:[]};for(let e=0;e<a.textureViews.length;e++){const r=a.textureViews[e];let s={r:0,g:0,b:0,a:1};0===e&&t.clearValue&&(s=t.clearValue),o.colorAttachments.push({view:r.view,depthSlice:r.depthSlice,resolveTarget:r.resolveTarget,loadOp:t.loadOp||ZR,storeOp:t.storeOp||QR,clearValue:s})}return a.depthStencilView&&(o.depthStencilAttachment={view:a.depthStencilView}),o}beginRender(e){const t=this.get(e),r=this.device,s=e.occlusionQueryCount;let i,n;s>0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,i=r.createQuerySet({type:"occlusion",count:s,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=i,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(s),t.lastOcclusionObject=null),n=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e,{loadOp:ZR}),this.initTimestampQuery(Ct.RENDER,this.getTimestampUID(e),n),n.occlusionQuerySet=i;const a=n.depthStencilAttachment;if(null!==e.textures){const t=n.colorAttachments;for(let r=0;r<t.length;r++){const s=t[r];e.clearColor?(s.clearValue=0===r?e.clearColorValue:{r:0,g:0,b:0,a:1},s.loadOp=JR):s.loadOp=ZR,s.storeOp=QR}}else{const t=n.colorAttachments[0];e.clearColor?(t.clearValue=e.clearColorValue,t.loadOp=JR):t.loadOp=ZR,t.storeOp=QR}e.depth&&(e.clearDepth?(a.depthClearValue=e.clearDepthValue,a.depthLoadOp=JR):a.depthLoadOp=ZR,a.depthStoreOp=QR),e.stencil&&(e.clearStencil?(a.stencilClearValue=e.clearStencilValue,a.stencilLoadOp=JR):a.stencilLoadOp=ZR,a.stencilStoreOp=QR);const o=r.createCommandEncoder({label:"renderContext_"+e.id});if(!0===this._isRenderCameraDepthArray(e)){const r=e.camera.cameras;t.layerDescriptors&&t.layerDescriptors.length===r.length?this._updateDepthLayerDescriptors(e,t,r):this._createDepthLayerDescriptors(e,t,n,r),t.bundleEncoders=[],t.bundleSets=[];for(let s=0;s<r.length;s++){const r=this.pipelineUtils.createBundleEncoder(e,"renderBundleArrayCamera_"+s),i={attributes:{},bindingGroups:[],pipeline:null,index:null};t.bundleEncoders.push(r),t.bundleSets.push(i)}t.currentPass=null}else{const r=o.beginRenderPass(n);t.currentPass=r,e.viewport&&this.updateViewport(e),e.scissor&&this.updateScissor(e)}t.descriptor=n,t.encoder=o,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.renderBundles=[]}_createDepthLayerDescriptors(e,t,r,s){const i=r.depthStencilAttachment;t.layerDescriptors=[];const n=this.get(e.depthTexture);n.viewCache||(n.viewCache=[]);for(let a=0;a<s.length;a++){const s={...r,colorAttachments:[{...r.colorAttachments[0],view:r.colorAttachments[a].view}]};if(r.depthStencilAttachment){const t=a;n.viewCache[t]||(n.viewCache[t]=n.texture.createView({dimension:Ow,baseArrayLayer:a,arrayLayerCount:1})),s.depthStencilAttachment={view:n.viewCache[t],depthLoadOp:i.depthLoadOp||JR,depthStoreOp:i.depthStoreOp||QR,depthClearValue:i.depthClearValue||1},e.stencil&&(s.depthStencilAttachment.stencilLoadOp=i.stencilLoadOp,s.depthStencilAttachment.stencilStoreOp=i.stencilStoreOp,s.depthStencilAttachment.stencilClearValue=i.stencilClearValue)}else s.depthStencilAttachment={...i};t.layerDescriptors.push(s)}}_updateDepthLayerDescriptors(e,t,r){for(let s=0;s<r.length;s++){const r=t.layerDescriptors[s];if(r.depthStencilAttachment){const t=r.depthStencilAttachment;e.depth&&(e.clearDepth?(t.depthClearValue=e.clearDepthValue,t.depthLoadOp=JR):t.depthLoadOp=ZR),e.stencil&&(e.clearStencil?(t.stencilClearValue=e.clearStencilValue,t.stencilLoadOp=JR):t.stencilLoadOp=ZR)}}}finishRender(e){const t=this.get(e),r=e.occlusionQueryCount;t.renderBundles.length>0&&t.currentPass.executeBundles(t.renderBundles),r>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery();const s=t.encoder;if(!0===this._isRenderCameraDepthArray(e)){const r=[];for(let e=0;e<t.bundleEncoders.length;e++){const s=t.bundleEncoders[e];r.push(s.finish())}for(let i=0;i<t.layerDescriptors.length;i++)if(i<r.length){const n=t.layerDescriptors[i],a=s.beginRenderPass(n);if(e.viewport){const{x:t,y:r,width:s,height:i,minDepth:n,maxDepth:o}=e.viewportValue;a.setViewport(t,r,s,i,n,o)}if(e.scissor){const{x:t,y:r,width:s,height:i}=e.scissorValue;a.setScissorRect(t,r,s,i)}a.executeBundles([r[i]]),a.end()}}else t.currentPass&&t.currentPass.end();if(r>0){const s=8*r;let i=this.occludedResolveCache.get(s);void 0===i&&(i=this.device.createBuffer({size:s,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(s,i));const n=this.device.createBuffer({size:s,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,r,i,0),t.encoder.copyBufferToBuffer(i,0,n,0,s),t.occlusionQueryBuffer=n,this.resolveOccludedAsync(e)}if(this.device.queue.submit([t.encoder.finish()]),null!==e.textures){const t=e.textures;for(let e=0;e<t.length;e++){const r=t[e];!0===r.generateMipmaps&&this.textureUtils.generateMipmaps(r)}}}isOccluded(e,t){const r=this.get(e);return r.occluded&&r.occluded.has(t)}async resolveOccludedAsync(e){const t=this.get(e),{currentOcclusionQueryBuffer:r,currentOcclusionQueryObjects:s}=t;if(r&&s){const e=new WeakSet;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueryBuffer=null,await r.mapAsync(GPUMapMode.READ);const i=r.getMappedRange(),n=new BigUint64Array(i);for(let t=0;t<s.length;t++)n[t]===BigInt(0)&&e.add(s[t]);r.destroy(),t.occluded=e}}updateViewport(e){const{currentPass:t}=this.get(e),{x:r,y:s,width:i,height:n,minDepth:a,maxDepth:o}=e.viewportValue;t.setViewport(r,s,i,n,a,o)}updateScissor(e){const{currentPass:t}=this.get(e),{x:r,y:s,width:i,height:n}=e.scissorValue;t.setScissorRect(r,s,i,n)}getClearColor(){const e=super.getClearColor();return!0===this.renderer.alpha&&(e.r*=e.a,e.g*=e.a,e.b*=e.a),e}clear(e,t,r,s=null){const i=this.device,n=this.renderer;let a,o,u,l,d=[];if(e){const e=this.getClearColor();o={r:e.r,g:e.g,b:e.b,a:e.a}}if(null===s){u=n.depth,l=n.stencil;const t=this._getDefaultRenderPassDescriptor();if(e){d=t.colorAttachments;const e=d[0];e.clearValue=o,e.loadOp=JR,e.storeOp=QR}(u||l)&&(a=t.depthStencilAttachment)}else{u=s.depth,l=s.stencil;const i={loadOp:e?JR:ZR,clearValue:e?o:void 0};u&&(i.depthLoadOp=t?JR:ZR,i.depthClearValue=t?n.getClearDepth():void 0,i.depthStoreOp=QR),l&&(i.stencilLoadOp=r?JR:ZR,i.stencilClearValue=r?n.getClearStencil():void 0,i.stencilStoreOp=QR);const c=this._getRenderPassDescriptor(s,i);d=c.colorAttachments,a=c.depthStencilAttachment}u&&a&&(t?(a.depthLoadOp=JR,a.depthClearValue=n.getClearDepth(),a.depthStoreOp=QR):(a.depthLoadOp=ZR,a.depthStoreOp=QR)),l&&a&&(r?(a.stencilLoadOp=JR,a.stencilClearValue=n.getClearStencil(),a.stencilStoreOp=QR):(a.stencilLoadOp=ZR,a.stencilStoreOp=QR));const c=i.createCommandEncoder({label:"clear"});c.beginRenderPass({colorAttachments:d,depthStencilAttachment:a}).end(),i.queue.submit([c.finish()])}beginCompute(e){const t=this.get(e),r={label:"computeGroup_"+e.id};this.initTimestampQuery(Ct.COMPUTE,this.getTimestampUID(e),r),t.cmdEncoderGPU=this.device.createCommandEncoder({label:"computeGroup_"+e.id}),t.passEncoderGPU=t.cmdEncoderGPU.beginComputePass(r)}compute(e,t,r,s,i=null){const n=this.get(t),{passEncoderGPU:a}=this.get(e),o=this.get(s).pipeline;this.pipelineUtils.setPipeline(a,o);for(let e=0,t=r.length;e<t;e++){const t=r[e],s=this.get(t);a.setBindGroup(e,s.group)}if(null===i&&(i=t.count),i&&"object"==typeof i&&i.isIndirectStorageBufferAttribute){const e=this.get(i).buffer;return void a.dispatchWorkgroupsIndirect(e,0)}if("number"==typeof i){const e=i;if(void 0===n.dispatchSize||n.count!==e){n.dispatchSize=[0,1,1],n.count=e;const r=t.workgroupSize;let s=r[0];for(let e=1;e<r.length;e++)s*=r[e];const a=Math.ceil(e/s),o=this.device.limits.maxComputeWorkgroupsPerDimension;i=[a,1,1],a>o&&(i[0]=Math.min(a,o),i[1]=Math.ceil(a/o)),n.dispatchSize=i}i=n.dispatchSize}a.dispatchWorkgroups(i[0],i[1]||1,i[2]||1)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.device.queue.submit([t.cmdEncoderGPU.finish()])}draw(e,t){const{object:r,material:s,context:i,pipeline:n}=e,a=e.getBindings(),o=this.get(i),u=this.get(n),l=u.pipeline;if(!0===u.error)return;const d=e.getIndex(),c=null!==d,h=e.getDrawParameters();if(null===h)return;const p=(t,r)=>{this.pipelineUtils.setPipeline(t,l),r.pipeline=l;const n=r.bindingGroups;for(let e=0,r=a.length;e<r;e++){const r=a[e],s=this.get(r);n[r.index]!==r.id&&(t.setBindGroup(r.index,s.group),n[r.index]=r.id)}if(!0===c&&r.index!==d){const e=this.get(d).buffer,s=d.array instanceof Uint16Array?iE:nE;t.setIndexBuffer(e,s),r.index=d}const u=e.getVertexBuffers();for(let e=0,s=u.length;e<s;e++){const s=u[e];if(r.attributes[e]!==s){const i=this.get(s).buffer;t.setVertexBuffer(e,i),r.attributes[e]=s}}!0===i.stencil&&!0===s.stencilWrite&&o.currentStencilRef!==s.stencilRef&&(t.setStencilReference(s.stencilRef),o.currentStencilRef=s.stencilRef)},g=(i,n)=>{if(p(i,n),!0===r.isBatchedMesh){const e=r._multiDrawStarts,n=r._multiDrawCounts,a=r._multiDrawCount,o=r._multiDrawInstances;null!==o&&v("WebGPUBackend: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.");let u=!0===c?d.array.BYTES_PER_ELEMENT:1;s.wireframe&&(u=r.geometry.attributes.position.count>65535?4:2);for(let s=0;s<a;s++){const a=o?o[s]:1,l=a>1?0:s;!0===c?i.drawIndexed(n[s],a,e[s]/u,0,l):i.draw(n[s],a,e[s],l),t.update(r,n[s],a)}}else if(!0===c){const{vertexCount:s,instanceCount:n,firstVertex:a}=h,o=e.getIndirect();if(null!==o){const t=this.get(o).buffer,r=e.getIndirectOffset(),s=Array.isArray(r)?r:[r];for(let e=0;e<s.length;e++)i.drawIndexedIndirect(t,s[e])}else i.drawIndexed(s,n,a,0,0);t.update(r,s,n)}else{const{vertexCount:s,instanceCount:n,firstVertex:a}=h,o=e.getIndirect();if(null!==o){const t=this.get(o).buffer,r=e.getIndirectOffset(),s=Array.isArray(r)?r:[r];for(let e=0;e<s.length;e++)i.drawIndirect(t,s[e])}else i.draw(s,n,a,0);t.update(r,s,n)}};if(e.camera.isArrayCamera&&e.camera.cameras.length>0){const t=this.get(e.camera),s=e.camera.cameras,n=e.getBindingGroup("cameraIndex");if(void 0===t.indexesGPU||t.indexesGPU.length!==s.length){const e=this.get(n),r=[],i=new Uint32Array([0,0,0,0]);for(let t=0,n=s.length;t<n;t++){i[0]=t;const{layoutGPU:s}=e.layout,n=this.bindingUtils.createBindGroupIndex(i,s);r.push(n)}t.indexesGPU=r}const a=this.renderer.getPixelRatio();for(let e=0,u=s.length;e<u;e++){const u=s[e];if(r.layers.test(u.layers)){const r=u.viewport;let s=o.currentPass,l=o.currentSets;if(o.bundleEncoders){s=o.bundleEncoders[e],l=o.bundleSets[e]}r&&s.setViewport(Math.floor(r.x*a),Math.floor(r.y*a),Math.floor(r.width*a),Math.floor(r.height*a),i.viewportValue.minDepth,i.viewportValue.maxDepth),n&&t.indexesGPU&&(s.setBindGroup(n.index,t.indexesGPU[e]),l.bindingGroups[n.index]=n.id),g(s,l)}}}else if(o.currentPass){if(void 0!==o.occlusionQuerySet){const e=o.lastOcclusionObject;e!==r&&(null!==e&&!0===e.occlusionTest&&(o.currentPass.endOcclusionQuery(),o.occlusionQueryIndex++),!0===r.occlusionTest&&(o.currentPass.beginOcclusionQuery(o.occlusionQueryIndex),o.occlusionQueryObjects[o.occlusionQueryIndex]=r),o.lastOcclusionObject=r)}g(o.currentPass,o.currentSets)}}needsRenderUpdate(e){const t=this.get(e),{object:r,material:s}=e,i=this.utils,n=i.getSampleCountRenderContext(e.context),a=i.getCurrentColorSpace(e.context),o=i.getCurrentColorFormat(e.context),u=i.getCurrentDepthStencilFormat(e.context),l=i.getPrimitiveTopology(r,s);let d=!1;return t.material===s&&t.materialVersion===s.version&&t.transparent===s.transparent&&t.blending===s.blending&&t.premultipliedAlpha===s.premultipliedAlpha&&t.blendSrc===s.blendSrc&&t.blendDst===s.blendDst&&t.blendEquation===s.blendEquation&&t.blendSrcAlpha===s.blendSrcAlpha&&t.blendDstAlpha===s.blendDstAlpha&&t.blendEquationAlpha===s.blendEquationAlpha&&t.colorWrite===s.colorWrite&&t.depthWrite===s.depthWrite&&t.depthTest===s.depthTest&&t.depthFunc===s.depthFunc&&t.stencilWrite===s.stencilWrite&&t.stencilFunc===s.stencilFunc&&t.stencilFail===s.stencilFail&&t.stencilZFail===s.stencilZFail&&t.stencilZPass===s.stencilZPass&&t.stencilFuncMask===s.stencilFuncMask&&t.stencilWriteMask===s.stencilWriteMask&&t.side===s.side&&t.alphaToCoverage===s.alphaToCoverage&&t.sampleCount===n&&t.colorSpace===a&&t.colorFormat===o&&t.depthStencilFormat===u&&t.primitiveTopology===l&&t.clippingContextCacheKey===e.clippingContextCacheKey||(t.material=s,t.materialVersion=s.version,t.transparent=s.transparent,t.blending=s.blending,t.premultipliedAlpha=s.premultipliedAlpha,t.blendSrc=s.blendSrc,t.blendDst=s.blendDst,t.blendEquation=s.blendEquation,t.blendSrcAlpha=s.blendSrcAlpha,t.blendDstAlpha=s.blendDstAlpha,t.blendEquationAlpha=s.blendEquationAlpha,t.colorWrite=s.colorWrite,t.depthWrite=s.depthWrite,t.depthTest=s.depthTest,t.depthFunc=s.depthFunc,t.stencilWrite=s.stencilWrite,t.stencilFunc=s.stencilFunc,t.stencilFail=s.stencilFail,t.stencilZFail=s.stencilZFail,t.stencilZPass=s.stencilZPass,t.stencilFuncMask=s.stencilFuncMask,t.stencilWriteMask=s.stencilWriteMask,t.side=s.side,t.alphaToCoverage=s.alphaToCoverage,t.sampleCount=n,t.colorSpace=a,t.colorFormat=o,t.depthStencilFormat=u,t.primitiveTopology=l,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){const{object:t,material:r}=e,s=this.utils,i=e.context,n=t.isMesh&&t.matrixWorld.determinant()<0;return[r.transparent,r.blending,r.premultipliedAlpha,r.blendSrc,r.blendDst,r.blendEquation,r.blendSrcAlpha,r.blendDstAlpha,r.blendEquationAlpha,r.colorWrite,r.depthWrite,r.depthTest,r.depthFunc,r.stencilWrite,r.stencilFunc,r.stencilFail,r.stencilZFail,r.stencilZPass,r.stencilFuncMask,r.stencilWriteMask,r.side,n,s.getSampleCountRenderContext(i),s.getCurrentColorSpace(i),s.getCurrentColorFormat(i),s.getCurrentDepthStencilFormat(i),s.getPrimitiveTopology(t,r),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}updateSampler(e){return this.textureUtils.updateSampler(e)}createDefaultTexture(e){return this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e,t=!1){this.textureUtils.destroyTexture(e,t)}async copyTextureToBuffer(e,t,r,s,i,n){return this.textureUtils.copyTextureToBuffer(e,t,r,s,i,n)}initTimestampQuery(e,t,r){if(!this.trackTimestamp)return;this.timestampQueryPool[e]||(this.timestampQueryPool[e]=new EC(this.device,e,2048));const s=this.timestampQueryPool[e],i=s.allocateQueriesForContext(t);r.timestampWrites={querySet:s.querySet,beginningOfPassWriteIndex:i,endOfPassWriteIndex:i+1}}createNodeBuilder(e,t){return new yC(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage+(""!==e.name?`_${e.name}`:"")}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const r=this.get(e),s=r.currentPass.finish();this.get(t).bundleGPU=s,r.currentSets=r._currentSets,r.currentPass=r._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,r,s){this.bindingUtils.createBindings(e,t,r,s)}updateBindings(e,t,r,s){this.bindingUtils.createBindings(e,t,r,s)}updateBinding(e){this.bindingUtils.updateBinding(e)}deleteBindGroupData(e){this.bindingUtils.deleteBindGroupData(e)}createIndexAttribute(e){let t=GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST;(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(t|=GPUBufferUsage.STORAGE),this.attributeUtils.createAttribute(e,t)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.delete(this.renderer.getCanvasTarget())}getMaxAnisotropy(){return 16}hasFeature(e){return void 0!==qw[e]&&(e=qw[e]),this.device.features.has(e)}copyTextureToTexture(e,t,r=null,s=null,i=0,n=0){let a=0,o=0,u=0,l=0,d=0,c=0,h=e.image.width,p=e.image.height,g=1;null!==r&&(!0===r.isBox3?(l=r.min.x,d=r.min.y,c=r.min.z,h=r.max.x-r.min.x,p=r.max.y-r.min.y,g=r.max.z-r.min.z):(l=r.min.x,d=r.min.y,h=r.max.x-r.min.x,p=r.max.y-r.min.y,g=1)),null!==s&&(a=s.x,o=s.y,u=s.z||0);const m=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),f=this.get(e).texture,y=this.get(t).texture;m.copyTextureToTexture({texture:f,mipLevel:i,origin:{x:l,y:d,z:c}},{texture:y,mipLevel:n,origin:{x:a,y:o,z:u}},[h,p,g]),this.device.queue.submit([m.finish()]),0===n&&t.generateMipmaps&&this.textureUtils.generateMipmaps(t)}copyFramebufferToTexture(e,t,r){const s=this.get(t);let i=null;i=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();const n=this.get(e).texture;if(i.format!==n.format)return void o("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",i.format,n.format);let a;if(s.currentPass?(s.currentPass.end(),a=s.encoder):a=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),a.copyTextureToTexture({texture:i,origin:[r.x,r.y,0]},{texture:n},[r.z,r.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e,a),s.currentPass){const{descriptor:e}=s;for(let t=0;t<e.colorAttachments.length;t++)e.colorAttachments[t].loadOp=ZR;t.depth&&(e.depthStencilAttachment.depthLoadOp=ZR),t.stencil&&(e.depthStencilAttachment.stencilLoadOp=ZR),s.currentPass=a.beginRenderPass(e),s.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.viewport&&this.updateViewport(t),t.scissor&&this.updateScissor(t)}else this.device.queue.submit([a.finish()])}hasCompatibility(e){return void 0!==this._compatibility[E.TEXTURE_COMPARE]?this._compatibility[E.TEXTURE_COMPARE]:super.hasCompatibility(e)}dispose(){if(this.bindingUtils.dispose(),this.textureUtils.dispose(),this.occludedResolveCache){for(const e of this.occludedResolveCache.values())e.destroy();this.occludedResolveCache.clear()}if(this.timestampQueryPool)for(const e of Object.values(this.timestampQueryPool))null!==e&&e.dispose();void 0===this.parameters.device&&null!==this.device&&this.device.destroy()}}class wC extends ps{constructor(e,t,r,s,i,n){super(e,t,r,s,i,n),this.iesMap=null}copy(e,t){return super.copy(e,t),this.iesMap=e.iesMap,this}}class CC extends ps{constructor(e,t,r,s,i,n){super(e,t,r,s,i,n),this.aspect=null}copy(e,t){return super.copy(e,t),this.aspect=e.aspect,this}}class MC extends NS{constructor(){super(),this.addLight(pv,gs),this.addLight(YN,ms),this.addLight(aS,fs),this.addLight(ZN,ps),this.addLight(KN,ys),this.addLight(QN,bs),this.addLight(eS,xs),this.addLight(JN,wC),this.addLight(rS,CC),this.addToneMapping(rT,Ts),this.addToneMapping(sT,_s),this.addToneMapping(iT,vs),this.addToneMapping(aT,Ns),this.addToneMapping(dT,Ss),this.addToneMapping(cT,Rs)}}class BC extends qS{constructor(e={}){let t;e.forceWebGL?t=IR:(t=AC,e.getFallback=()=>(d("WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new IR(e)));super(new t(e),e),this.library=new MC,this.isWebGPURenderer=!0}}class FC extends Es{constructor(){super(),this.isBundleGroup=!0,this.type="BundleGroup",this.static=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}}class LC{constructor(e,t=An(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0;const r=new fg;r.name="RenderPipeline",this._quadMesh=new lx(r),this._quadMesh.name="Render Pipeline",this._context=null}render(){const e=this.renderer;this._update(),null!==this._context.onBeforeRenderPipeline&&this._context.onBeforeRenderPipeline();const t=e.toneMapping,r=e.outputColorSpace;e.toneMapping=m,e.outputColorSpace=p.workingColorSpace;const s=e.xr.enabled;e.xr.enabled=!1,this._quadMesh.render(e),e.xr.enabled=s,e.toneMapping=t,e.outputColorSpace=r,null!==this._context.onAfterRenderPipeline&&this._context.onAfterRenderPipeline()}get context(){return this._context}dispose(){this._quadMesh.material.dispose()}_update(){if(!0===this.needsUpdate){const e=this.renderer,t=e.toneMapping,r=e.outputColorSpace,s={renderPipeline:this,onBeforeRenderPipeline:null,onAfterRenderPipeline:null};let i=this.outputNode;!0===this.outputColorTransform?(i=i.context(s),i=bl(i,t,r)):(s.toneMapping=t,s.outputColorSpace=r,i=i.context(s)),this._context=s,this._quadMesh.material.fragmentNode=i,this._quadMesh.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){v('RenderPipeline: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await this.renderer.init(),this.render()}}class PC extends LC{constructor(e,t){v('PostProcessing: "PostProcessing" has been renamed to "RenderPipeline". Please update your code to use "THREE.RenderPipeline" instead.'),super(e,t)}}class DC extends N{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=de,this.minFilter=de,this.isStorageTexture=!0,this.mipmapsAutoUpdate=!0}setSize(e,t){this.image.width===e&&this.image.height===t||(this.image.width=e,this.image.height=t,this.dispose())}}class UC extends vx{constructor(e,t){super(e,t,Uint32Array),this.isIndirectStorageBufferAttribute=!0}}class IC extends As{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,r,s){const i=new ws(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,r=>{try{t(this.parse(JSON.parse(r)))}catch(t){s?s(t):o(t),this.manager.itemError(e)}},r,s)}parseNodes(e){const t={};if(void 0!==e){for(const r of e){const{uuid:e,type:s}=r;t[e]=this.createNodeFromType(s),t[e].uuid=e}const r={nodes:t,textures:this.textures};for(const s of e){s.meta=r;t[s.uuid].deserialize(s),delete s.meta}}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const r={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=r,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return void 0===this.nodes[e]?(o("NodeLoader: Node type not found:",e),mn()):new this.nodes[e]}}class OC extends Cs{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),r=this.nodes,s=e.inputNodes;for(const e in s){const i=s[e];t[e]=r[i]}return t}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}createMaterialFromType(e){const t=this.nodeMaterials[e];return void 0!==t?new t:super.createMaterialFromType(e)}}class VC extends Ms{constructor(e){super(e),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}parse(e,t){this._nodesJSON=e.nodes;const r=super.parse(e,t);return this._nodesJSON=null,r}parseNodes(e,t){if(void 0!==e){const r=new IC;return r.setNodes(this.nodes),r.setTextures(t),r.parseNodes(e)}return{}}parseMaterials(e,t){const r={};if(void 0!==e){const s=this.parseNodes(this._nodesJSON,t),i=new OC;i.setTextures(t),i.setNodes(s),i.setNodeMaterials(this.nodeMaterials);for(let t=0,s=e.length;t<s;t++){const s=e[t];r[s.uuid]=i.parse(s)}}return r}}class kC extends Es{constructor(){super(),this.isClippingGroup=!0,this.clippingPlanes=[],this.enabled=!0,this.clipIntersection=!1,this.clipShadows=!1}}export{Ns as ACESFilmicToneMapping,Lp as AONode,qe as AddEquation,ge as AddOperation,qt as AdditiveBlending,Ss as AgXToneMapping,ar as AlphaFormat,Wr as AlwaysCompare,Jt as AlwaysDepth,ts as AlwaysStencilFunc,ys as AmbientLight,KN as AmbientLightNode,dv as AnalyticLightNode,lt as ArrayCamera,di as ArrayElementNode,Na as ArrayNode,Ra as AssignNode,UT as AtomicFunctionNode,Sl as AttributeNode,L as BackSide,FT as BarrierNode,Fg as BasicEnvironmentNode,Lg as BasicLightMapNode,rt as BasicShadowMap,xp as BatchNode,cb as BitcastNode,mb as BitcountNode,nb as BlendMode,oe as BoxGeometry,Ce as BufferAttribute,Zu as BufferAttributeNode,Ne as BufferGeometry,Il as BufferNode,$l as BuiltinNode,mh as BumpMapNode,FC as BundleGroup,ll as BypassNode,Nt as ByteType,IS as CanvasTarget,vs as CineonToneMapping,ve as ClampToEdgeWrapping,kC as ClippingGroup,sg as ClippingNode,hT as CodeNode,e as Color,p as ColorManagement,ku as ColorSpaceNode,E as Compatibility,RT as ComputeBuiltinNode,sl as ComputeNode,bu as ConditionalNode,Ti as ConstNode,Tu as ContextNode,ci as ConvertNode,ce as CubeCamera,st as CubeDepthTexture,wg as CubeMapNode,I as CubeReflectionMapping,O as CubeRefractionMapping,U as CubeTexture,wc as CubeTextureNode,we as CubeUVReflectionMapping,$t as CullFaceBack,zt as CullFaceFront,Gt as CullFaceNone,ht as CustomBlending,gt as CylinderGeometry,K as DataArrayTexture,Te as DataTexture,xl as DebugNode,ns as DecrementStencilOp,ss as DecrementWrapStencilOp,ke as DepthFormat,Ve as DepthStencilFormat,J as DepthTexture,ms as DirectionalLight,YN as DirectionalLightNode,P as DoubleSide,Ut as DstAlphaFactor,It as DstColorFactor,x as DynamicDrawUsage,Uf as EnvironmentNode,zr as EqualCompare,Yt as EqualDepth,Zr as EqualStencilFunc,he as EquirectangularReflectionMapping,pe as EquirectangularRefractionMapping,D as Euler,u as EventDispatcher,xx as EventNode,gl as ExpressionNode,ws as FileLoader,yi as FlipNode,ot as Float16BufferAttribute,Qe as Float32BufferAttribute,Y as FloatType,Q as FramebufferTexture,tc as FrontFacingNode,ct as FrontSide,xt as Frustum,bt as FrustumArray,Aa as FunctionCallNode,gT as FunctionNode,Fb as FunctionOverloadingNode,pS as GLSLNodeParser,C as GreaterCompare,Xt as GreaterDepth,M as GreaterEqualCompare,Kt as GreaterEqualDepth,Qr as GreaterEqualStencilFunc,Yr as GreaterStencilFunc,Es as Group,_e as HalfFloatType,bs as HemisphereLight,QN as HemisphereLightNode,wC as IESSpotLight,JN as IESSpotLightNode,as as IncrementStencilOp,is as IncrementWrapStencilOp,up as IndexNode,UC as IndirectStorageBufferAttribute,bi as InputNode,_l as InspectorBase,vl as InspectorNode,mp as InstanceNode,j as InstancedBufferAttribute,X as InstancedInterleavedBuffer,yp as InstancedMeshNode,R as IntType,b as InterleavedBuffer,y as InterleavedBufferAttribute,os as InvertStencilOp,Up as IrradianceNode,al as IsolateNode,pi as JoinNode,ds as KeepStencilOp,A as LessCompare,Zt as LessDepth,w as LessEqualCompare,Qt as LessEqualDepth,Jr as LessEqualStencilFunc,es as LessStencilFunc,xs as LightProbe,eS as LightProbeNode,ES as Lighting,Pp as LightingContextNode,Pg as LightingModel,Fp as LightingNode,v_ as LightsNode,vg as Line2NodeMaterial,te as LineBasicMaterial,bg as LineBasicNodeMaterial,re as LineDashedMaterial,Tg as LineDashedNodeMaterial,de as LinearFilter,Ye as LinearMipMapLinearFilter,Z as LinearMipmapLinearFilter,nt as LinearMipmapNearestFilter,Ee as LinearSRGBColorSpace,Ts as LinearToneMapping,qr as LinearTransfer,As as Loader,Sp as LoopNode,lb as MRTNode,ee as Material,je as MaterialBlending,Cs as MaterialLoader,bh as MaterialNode,Dc as MaterialReferenceNode,so as MathNode,l as MathUtils,i as Matrix2,n as Matrix3,a as Matrix4,cs as MaxEquation,Cl as MaxMipLevelNode,_i as MemberNode,ue as Mesh,ye as MeshBasicMaterial,Ig as MeshBasicNodeMaterial,be as MeshLambertMaterial,Wg as MeshLambertNodeMaterial,Le as MeshMatcapMaterial,Qf as MeshMatcapNodeMaterial,ie as MeshNormalMaterial,Sg as MeshNormalNodeMaterial,xe as MeshPhongMaterial,qg as MeshPhongNodeMaterial,Be as MeshPhysicalMaterial,$f as MeshPhysicalNodeMaterial,Wf as MeshSSSNodeMaterial,Me as MeshStandardMaterial,kf as MeshStandardNodeMaterial,Fe as MeshToonMaterial,Xf as MeshToonNodeMaterial,hs as MinEquation,Vr as MirroredRepeatWrapping,me as MixOperation,Pd as ModelNode,Mp as MorphNode,Wt as MultiplyBlending,fe as MultiplyOperation,B as NearestFilter,at as NearestMipmapLinearFilter,Gr as NearestMipmapNearestFilter,Rs as NeutralToneMapping,Hr as NeverCompare,er as NeverDepth,rs as NeverStencilFunc,se as NoBlending,T as NoColorSpace,k as NoNormalPacking,m as NoToneMapping,li as Node,ri as NodeAccess,fN as NodeAttribute,qN as NodeBuilder,vN as NodeCache,TN as NodeCode,Bl as NodeError,jN as NodeFrame,XN as NodeFunctionInput,IC as NodeLoader,fg as NodeMaterial,OC as NodeMaterialLoader,Ls as NodeMaterialObserver,VC as NodeObjectLoader,Js as NodeShaderStage,ti as NodeType,yN as NodeUniform,ei as NodeUpdateType,Zs as NodeUtils,bN as NodeVar,xN as NodeVarying,ze as NormalBlending,$ as NormalGAPacking,ch as NormalMapNode,G as NormalRGPacking,$r as NotEqualCompare,jt as NotEqualDepth,Kr as NotEqualStencilFunc,Ke as Object3D,Ad as Object3DNode,Ms as ObjectLoader,z as ObjectSpaceNormalMap,kt as OneFactor,Lt as OneMinusDstAlphaFactor,Pt as OneMinusDstColorFactor,He as OneMinusSrcAlphaFactor,Dt as OneMinusSrcColorFactor,Ma as OperatorNode,Se as OrthographicCamera,sb as OutputStructNode,et as PCFShadowMap,tt as PCFSoftShadowMap,Rf as PMREMGenerator,Lf as PMREMNode,_b as PackFloatNode,Zy as ParameterNode,eT as PassNode,Re as PerspectiveCamera,$g as PhongLightingModel,km as PhysicalLightingModel,Xe as Plane,dt as PlaneGeometry,gs as PointLight,pv as PointLightNode,uv as PointShadowNode,Nx as PointUVNode,De as PointsMaterial,iy as PointsNodeMaterial,PC as PostProcessing,CC as ProjectorLight,rS as ProjectorLightNode,Un as PropertyNode,lx as QuadMesh,mt as Quaternion,br as R11_EAC_Format,H as RED_GREEN_RGTC2_Format,Ur as RED_RGTC1_Format,ut as REVISION,q as RG11_EAC_Format,Ae as RGBAFormat,wt as RGBAIntegerFormat,Fr as RGBA_ASTC_10x10_Format,Cr as RGBA_ASTC_10x5_Format,Mr as RGBA_ASTC_10x6_Format,Br as RGBA_ASTC_10x8_Format,Lr as RGBA_ASTC_12x10_Format,Pr as RGBA_ASTC_12x12_Format,_r as RGBA_ASTC_4x4_Format,vr as RGBA_ASTC_5x4_Format,Nr as RGBA_ASTC_5x5_Format,Sr as RGBA_ASTC_6x5_Format,Rr as RGBA_ASTC_6x6_Format,Er as RGBA_ASTC_8x5_Format,Ar as RGBA_ASTC_8x6_Format,wr as RGBA_ASTC_8x8_Format,Dr as RGBA_BPTC_Format,yr as RGBA_ETC2_EAC_Format,gr as RGBA_PVRTC_2BPPV1_Format,pr as RGBA_PVRTC_4BPPV1_Format,ur as RGBA_S3TC_DXT1_Format,lr as RGBA_S3TC_DXT3_Format,dr as RGBA_S3TC_DXT5_Format,At as RGBFormat,Et as RGBIntegerFormat,mr as RGB_ETC1_Format,fr as RGB_ETC2_Format,hr as RGB_PVRTC_2BPPV1_Format,cr as RGB_PVRTC_4BPPV1_Format,or as RGB_S3TC_DXT1_Format,W as RGFormat,Rt as RGIntegerFormat,cx as RTTNode,NT as RangeNode,fs as RectAreaLight,aS as RectAreaLightNode,_t as RedFormat,Tt as RedIntegerFormat,Wu as ReferenceBaseNode,Fc as ReferenceNode,ix as ReflectorNode,_s as ReinhardToneMapping,cl as RemapNode,yl as RenderOutputNode,LC as RenderPipeline,ae as RenderTarget,Hu as RendererReferenceNode,L_ as RendererUtils,kr as RepeatWrapping,us as ReplaceStencilOp,Bt as ReverseSubtractEquation,Zf as RotateNode,xr as SIGNED_R11_EAC_Format,Or as SIGNED_RED_GREEN_RGTC2_Format,Ir as SIGNED_RED_RGTC1_Format,Tr as SIGNED_RG11_EAC_Format,ne as SRGBColorSpace,g as SRGBTransfer,bx as SampleNode,le as Scene,ql as ScreenNode,fi as SetNode,N_ as ShadowBaseNode,Ue as ShadowMaterial,K_ as ShadowNode,uy as ShadowNodeMaterial,vt as ShortType,vp as SkinningNode,F as Sphere,it as SphereGeometry,mi as SplitNode,ps as SpotLight,ZN as SpotLightNode,Pe as SpriteMaterial,ty as SpriteNodeMaterial,We as SrcAlphaFactor,Ot as SrcAlphaSaturateFactor,Vt as SrcColorFactor,Jy as StackNode,Ds as StackTrace,f as StaticDrawUsage,ip as StorageArrayElementNode,vx as StorageBufferAttribute,ap as StorageBufferNode,_x as StorageInstancedBufferAttribute,DC as StorageTexture,Mx as StorageTextureNode,rb as StructNode,tb as StructTypeNode,Fu as SubBuildNode,VT as SubgroupFunctionNode,Ft as SubtractEquation,Ht as SubtractiveBlending,dN as TSL,V as TangentSpaceNormalMap,hi as TempNode,N as Texture,Lx as Texture3DNode,Ll as TextureNode,Al as TextureSizeNode,Ct as TimestampQuery,ju as ToneMappingNode,tT as ToonOutlinePassNode,Ze as UVMapping,Oe as Uint16BufferAttribute,Ie as Uint32BufferAttribute,kl as UniformArrayNode,ma as UniformGroupNode,_a as UniformNode,Rb as UnpackFloatNode,$e as UnsignedByteType,nr as UnsignedInt101111Type,Ge as UnsignedInt248Type,ir as UnsignedInt5999Type,S as UnsignedIntType,rr as UnsignedShort4444Type,sr as UnsignedShort5551Type,St as UnsignedShortType,Dx as UserDataNode,Je as VSMShadowMap,Au as VarNode,Pu as VaryingNode,t as Vector2,r as Vector3,s as Vector4,Ix as VelocityNode,og as VertexColorNode,qp as ViewportDepthNode,Wp as ViewportDepthTextureNode,Kx as ViewportSharedTextureNode,Op as ViewportTextureNode,py as VolumeNodeMaterial,c as WebGLCoordinateSystem,h as WebGPUCoordinateSystem,BC as WebGPURenderer,ft as WebXRController,DT as WorkgroupInfoNode,pt as ZeroFactor,ls as ZeroStencilOp,Mt as createCanvasElement,ii as defaultBuildStages,si as defaultShaderStages,o as error,_ as log,ni as shaderStages,ai as vectorComponents,d as warn,v as warnOnce};
|