Last active
July 19, 2026 13:03
-
-
Save RenaudRohlinger/629551efb48078e2e9792d620af073fa to your computer and use it in GitHub Desktop.
JSFiddle demo: hydrate a fresh Three.js NodeBuilderState from CLI-captured WGSL after refresh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| * { box-sizing: border-box; } | |
| html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #070b12; color: #e6edf3; font: 13px/1.35 system-ui, sans-serif; } | |
| canvas { display: block; width: 100%; height: 100%; } | |
| aside { position: fixed; top: 12px; left: 12px; width: min(296px, calc(100vw - 24px)); padding: 12px; border: 1px solid #ffffff1f; border-radius: 12px; background: #0d1117e8; box-shadow: 0 12px 36px #0008; backdrop-filter: blur(12px); } | |
| .eyebrow { color: #8b949e; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; } | |
| h1 { margin: 2px 0 10px; font-size: 18px; line-height: 1.1; } | |
| .toggle { display: grid; grid-template-columns: 1fr 1.35fr; gap: 3px; margin-bottom: 9px; padding: 3px; border-radius: 9px; background: #010409; } | |
| button { min-width: 0; padding: 7px 6px; border: 0; border-radius: 7px; background: transparent; color: #8b949e; font: 700 11px/1 system-ui, sans-serif; cursor: pointer; } | |
| button:hover { color: #e6edf3; } | |
| button.active { background: #30363d; color: white; box-shadow: 0 1px 4px #0008; } | |
| .verdict { display: flex; align-items: center; gap: 10px; padding: 9px; border: 1px solid #ffffff14; border-radius: 9px; background: #01040999; } | |
| .verdict > span { display: grid; flex: 0 0 34px; height: 34px; place-items: center; border-radius: 50%; background: #30363d; font-size: 20px; font-weight: 800; } | |
| .verdict strong, .verdict small { display: block; } | |
| .verdict small { margin-top: 2px; color: #8b949e; font-size: 10px; } | |
| .verdict.live { border-color: #f0883e66; background: #3d241799; } | |
| .verdict.live > span { background: #9e4c19; color: white; } | |
| .verdict.passed { border-color: #3fb95066; background: #16351f99; } | |
| .verdict.passed > span { background: #238636; color: white; box-shadow: 0 0 18px #3fb95066; } | |
| .verdict.failed { border-color: #f8514966; } | |
| .metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 9px; } | |
| .metrics > div { min-width: 0; padding: 8px; border: 1px solid #ffffff14; border-radius: 8px; background: #01040999; } | |
| .metrics span { display: block; color: #8b949e; font-size: 10px; } | |
| .metrics strong { display: block; margin-top: 2px; color: #c9d1d9; font: 700 17px/1 ui-monospace, monospace; } | |
| p { margin: 9px 2px 0; color: #8b949e; font-size: 10px; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <canvas id="canvas"></canvas> | |
| <aside> | |
| <div class="eyebrow">CLI capture · 17 KB JSON</div> | |
| <h1>TSL shader after refresh</h1> | |
| <div class="toggle" role="group" aria-label="Shader build mode"> | |
| <button type="button" data-mode="live">Live TSL</button> | |
| <button type="button" data-mode="precompiled">Precompiled JSON</button> | |
| </div> | |
| <div id="verdict" class="verdict"> | |
| <span id="check">…</span> | |
| <div> | |
| <strong id="result">Initializing WebGPU</strong> | |
| <small id="summary">Loading the renderer…</small> | |
| </div> | |
| </div> | |
| <div class="metrics"> | |
| <div> | |
| <span>Live TSL builds</span> | |
| <strong id="builds">…</strong> | |
| </div> | |
| <div> | |
| <span>Setup</span> | |
| <strong id="time">…</strong> | |
| </div> | |
| </div> | |
| <p>Captured WGSL and binding recipes are stored independently of this page.</p> | |
| </aside> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ( async () => { | |
| const STORAGE_KEY = 'three-node-builder-state-provider-mode'; | |
| let mode = localStorage.getItem( STORAGE_KEY ) === 'precompiled' ? 'precompiled' : 'live'; | |
| let canvas = document.getElementById( 'canvas' ); | |
| const verdict = document.getElementById( 'verdict' ); | |
| const result = document.getElementById( 'result' ); | |
| const summary = document.getElementById( 'summary' ); | |
| const buttons = document.querySelectorAll( '[data-mode]' ); | |
| let disposeActive = () => {}; | |
| let switching = false; | |
| function fail( title, message ) { | |
| document.getElementById( 'check' ).textContent = '!'; | |
| result.textContent = title; | |
| summary.textContent = message; | |
| verdict.className = 'verdict failed'; | |
| } | |
| function selectMode( selectedMode ) { | |
| for ( const button of buttons ) { | |
| button.classList.toggle( 'active', button.dataset.mode === selectedMode ); | |
| button.disabled = switching; | |
| } | |
| } | |
| selectMode( mode ); | |
| if ( navigator.gpu === undefined ) { | |
| fail( 'WebGPU required', 'Open this fiddle in a WebGPU-capable browser.' ); | |
| return; | |
| } | |
| try { | |
| const { | |
| Color, | |
| createShaderCache, | |
| createThreeWebGPUShaderCompatibility, | |
| float, | |
| Mesh, | |
| MeshBasicNodeMaterial, | |
| mx_fractal_noise_vec3, | |
| mx_worley_noise_vec3, | |
| OrthographicCamera, | |
| PlaneGeometry, | |
| Scene, | |
| ShaderCacheProvider, | |
| uv, | |
| WebGPURenderer, | |
| } = await import( 'https://cdn.jsdelivr.net/gh/RenaudRohlinger/three.js@7fe11cadf2db16e874f3c0fae5b6e843c3a29e27/provider-demo-runtime.mjs' ); | |
| for ( const button of buttons ) { | |
| button.addEventListener( 'click', async () => { | |
| const nextMode = button.dataset.mode; | |
| if ( nextMode === mode || switching ) return; | |
| switching = true; | |
| selectMode( nextMode ); | |
| localStorage.setItem( STORAGE_KEY, nextMode ); | |
| try { | |
| await renderMode( nextMode ); | |
| mode = nextMode; | |
| } catch ( error ) { | |
| fail( 'Demo failed', error instanceof Error ? error.message : String( error ) ); | |
| } finally { | |
| switching = false; | |
| selectMode( mode ); | |
| } | |
| } ); | |
| } | |
| await renderMode( mode ); | |
| async function renderMode( selectedMode ) { | |
| disposeActive(); | |
| const replacement = canvas.cloneNode( false ); | |
| canvas.replaceWith( replacement ); | |
| canvas = replacement; | |
| verdict.className = 'verdict'; | |
| document.getElementById( 'check' ).textContent = '…'; | |
| document.getElementById( 'builds' ).textContent = '…'; | |
| document.getElementById( 'time' ).textContent = '…'; | |
| result.textContent = 'Initializing WebGPU'; | |
| summary.textContent = selectedMode === 'live' | |
| ? 'Building the TSL graph…' | |
| : 'Loading the captured JSON…'; | |
| let manifest = null; | |
| if ( selectedMode === 'precompiled' ) { | |
| const response = await fetch( 'https://cdn.jsdelivr.net/gh/RenaudRohlinger/three.js@7fe11cadf2db16e874f3c0fae5b6e843c3a29e27/main.json' ); | |
| if ( response.ok === false ) throw new Error( `Shader artifact returned HTTP ${ response.status }.` ); | |
| manifest = await response.json(); | |
| } | |
| const renderer = new WebGPURenderer( { canvas, antialias: false } ); | |
| renderer.setPixelRatio( Math.min( devicePixelRatio, 2 ) ); | |
| const scene = new Scene(); | |
| scene.background = new Color( 0x070b12 ); | |
| const camera = new OrthographicCamera( - 1.6, 1.6, 1, - 1, 0.1, 10 ); | |
| camera.position.z = 2; | |
| const material = new MeshBasicNodeMaterial(); | |
| const point = uv().mul( 6 ); | |
| const clouds = mx_fractal_noise_vec3( point, float( 5 ), float( 2 ), float( 0.55 ) ).mul( 0.5 ).add( 0.5 ); | |
| const cells = mx_worley_noise_vec3( point.mul( 0.7 ) ); | |
| material.colorNode = clouds.mul( 0.75 ).add( cells.mul( 0.25 ) ); | |
| const geometry = new PlaneGeometry( 3.2, 2 ); | |
| const mesh = new Mesh( geometry, material ); | |
| scene.add( mesh ); | |
| const cache = createShaderCache( 'main' ); | |
| const registration = cache.material( 'main/procedural-card', material ); | |
| let resize = () => {}; | |
| disposeActive = () => { | |
| removeEventListener( 'resize', resize ); | |
| renderer.setAnimationLoop( null ); | |
| registration.dispose(); | |
| geometry.dispose(); | |
| material.dispose(); | |
| renderer.dispose(); | |
| }; | |
| await renderer.init(); | |
| let hydrated = 0; | |
| if ( manifest !== null ) { | |
| const storedProvider = new ShaderCacheProvider( { | |
| manifest, | |
| renderer, | |
| cache, | |
| compatibility: createThreeWebGPUShaderCompatibility( { | |
| threeVersion: manifest.three, | |
| } ), | |
| strict: true, | |
| } ); | |
| renderer.nodeBuilderStateProvider = { | |
| getForRender( renderObject, NodeBuilderState ) { | |
| const parameters = storedProvider.getForRender( renderObject ); | |
| if ( parameters === null || parameters === undefined ) return null; | |
| hydrated ++; | |
| return new NodeBuilderState( ...parameters ); | |
| }, | |
| getForCompute( computeNode, NodeBuilderState ) { | |
| const parameters = storedProvider.getForCompute( computeNode ); | |
| return parameters === null || parameters === undefined | |
| ? null | |
| : new NodeBuilderState( ...parameters ); | |
| }, | |
| }; | |
| } | |
| let liveBuilds = 0; | |
| const createState = renderer._nodes._createNodeBuilderState; | |
| renderer._nodes._createNodeBuilderState = function ( builder ) { | |
| if ( builder.material === material ) liveBuilds ++; | |
| return createState.call( this, builder ); | |
| }; | |
| resize = () => { | |
| const width = Math.max( innerWidth, 1 ); | |
| const height = Math.max( innerHeight, 1 ); | |
| renderer.setSize( width, height, false ); | |
| const aspect = width / height; | |
| camera.left = - aspect; | |
| camera.right = aspect; | |
| camera.updateProjectionMatrix(); | |
| }; | |
| resize(); | |
| addEventListener( 'resize', resize ); | |
| const start = performance.now(); | |
| await renderer.compileAsync( scene, camera ); | |
| const elapsed = performance.now() - start; | |
| renderer.setAnimationLoop( () => renderer.render( scene, camera ) ); | |
| document.getElementById( 'builds' ).textContent = String( liveBuilds ); | |
| document.getElementById( 'time' ).textContent = `${ elapsed.toFixed( 1 ) } ms`; | |
| if ( selectedMode === 'live' ) { | |
| document.getElementById( 'check' ).textContent = String( liveBuilds ); | |
| result.textContent = 'Built from the TSL graph'; | |
| summary.textContent = 'Switch modes to load the captured JSON.'; | |
| verdict.classList.add( 'live' ); | |
| } else if ( liveBuilds === 0 && hydrated === 1 ) { | |
| document.getElementById( 'check' ).textContent = '✓'; | |
| result.textContent = 'Rendered from stored WGSL'; | |
| summary.textContent = '1 fresh state hydrated · 0 TSL graph builds'; | |
| verdict.classList.add( 'passed' ); | |
| } else { | |
| throw new Error( `${ hydrated } states hydrated · ${ liveBuilds } live builds` ); | |
| } | |
| } | |
| } catch ( error ) { | |
| fail( 'Demo failed', error instanceof Error ? error.message : String( error ) ); | |
| throw error; | |
| } | |
| } )(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Persist a TSL shader and replay its WGSL after refresh | |
| description: Toggle between one live TSL build and a fresh NodeBuilderState hydrated from a Three Blocks CLI capture. | |
| authors: | |
| - Renaud Rohlinger | |
| normalize_css: no | |
| wrap: b | |
| panel_html: 0 | |
| panel_css: 0 | |
| panel_js: 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "entries": { | |
| "main/procedural-card": { | |
| "attributes": [ | |
| { | |
| "name": "uv", | |
| "node": null, | |
| "type": "vec2" | |
| }, | |
| { | |
| "name": "position", | |
| "node": null, | |
| "type": "vec3" | |
| } | |
| ], | |
| "bindGroups": [ | |
| { | |
| "bindings": [ | |
| { | |
| "kind": "NodeUniformsGroup", | |
| "name": "render", | |
| "uniforms": [ | |
| { | |
| "name": "cameraProjectionMatrix", | |
| "type": "mat4" | |
| }, | |
| { | |
| "name": "cameraViewMatrix", | |
| "type": "mat4" | |
| } | |
| ] | |
| } | |
| ], | |
| "index": 0, | |
| "name": "render" | |
| }, | |
| { | |
| "bindings": [ | |
| { | |
| "kind": "NodeUniformsGroup", | |
| "name": "object", | |
| "uniforms": [ | |
| { | |
| "name": "nodeUniform0", | |
| "type": "float" | |
| }, | |
| { | |
| "name": "nodeUniform3", | |
| "type": "mat4" | |
| } | |
| ] | |
| } | |
| ], | |
| "index": 1, | |
| "name": "object" | |
| } | |
| ], | |
| "computeShader": null, | |
| "fragmentShader": "// Three.js r185 - Node System\n\n// global\ndiagnostic( off, derivative_uniformity );\n\n\n// structs\n\nstruct OutputStruct {\n\t@location( 0 ) color: vec4<f32>\n};\nvar<private> output : OutputStruct;\n\n// uniforms\n\nstruct objectStruct {\n\tnodeUniform0 : f32,\n\tnodeUniform3 : mat4x4<f32>\n};\n@binding( 0 ) @group( 1 )\nvar<uniform> object : objectStruct;\n\n// vars\nvar<private> DiffuseColor : vec4<f32>;\nvar<private> nodeVar0 : vec2<f32>;\nvar<private> Output : vec4<f32>;\nvar<private> nodeVar1 : vec4<f32>;\n\n// codes\nfn mx_rotl32 ( x : u32, k : i32 ) -> u32 {\n\n\tvar nodeVar0 : i32;\n\tvar nodeVar1 : u32;\n\n\tnodeVar0 = k;\n\tnodeVar1 = x;\n\n\treturn ( ( nodeVar1 << u32( nodeVar0 ) ) | ( nodeVar1 >> u32( ( 32 - nodeVar0 ) ) ) );\n\n}\n\nfn mx_bjfinal ( a : u32, b : u32, c : u32 ) -> u32 {\n\n\tvar nodeVar0 : u32;\n\tvar nodeVar1 : u32;\n\tvar nodeVar2 : u32;\n\n\tnodeVar0 = c;\n\tnodeVar1 = b;\n\tnodeVar2 = a;\n\tnodeVar0 = ( nodeVar0 ^ nodeVar1 );\n\tnodeVar0 = ( nodeVar0 - mx_rotl32( nodeVar1, 14 ) );\n\tnodeVar2 = ( nodeVar2 ^ nodeVar0 );\n\tnodeVar2 = ( nodeVar2 - mx_rotl32( nodeVar0, 11 ) );\n\tnodeVar1 = ( nodeVar1 ^ nodeVar2 );\n\tnodeVar1 = ( nodeVar1 - mx_rotl32( nodeVar2, 25 ) );\n\tnodeVar0 = ( nodeVar0 ^ nodeVar1 );\n\tnodeVar0 = ( nodeVar0 - mx_rotl32( nodeVar1, 16 ) );\n\tnodeVar2 = ( nodeVar2 ^ nodeVar0 );\n\tnodeVar2 = ( nodeVar2 - mx_rotl32( nodeVar0, 4 ) );\n\tnodeVar1 = ( nodeVar1 ^ nodeVar2 );\n\tnodeVar1 = ( nodeVar1 - mx_rotl32( nodeVar2, 14 ) );\n\tnodeVar0 = ( nodeVar0 ^ nodeVar1 );\n\tnodeVar0 = ( nodeVar0 - mx_rotl32( nodeVar1, 24 ) );\n\n\treturn nodeVar0;\n\n}\n\nfn mx_hash_int_2 ( x : i32, y : i32, z : i32 ) -> u32 {\n\n\tvar nodeVar0 : i32;\n\tvar nodeVar1 : i32;\n\tvar nodeVar2 : i32;\n\tvar nodeVar3 : u32;\n\tvar nodeVar4 : u32;\n\tvar nodeVar5 : u32;\n\tvar nodeVar6 : u32;\n\n\tnodeVar0 = z;\n\tnodeVar1 = y;\n\tnodeVar2 = x;\n\tnodeVar3 = 3u;\n\tnodeVar4 = 0u;\n\tnodeVar5 = 0u;\n\tnodeVar6 = 0u;\n\tnodeVar6 = ( ( 3735928559u + ( nodeVar3 << 2u ) ) + 13u );\n\tnodeVar5 = nodeVar6;\n\tnodeVar4 = nodeVar5;\n\tnodeVar4 = ( nodeVar4 + u32( nodeVar2 ) );\n\tnodeVar5 = ( nodeVar5 + u32( nodeVar1 ) );\n\tnodeVar6 = ( nodeVar6 + u32( nodeVar0 ) );\n\n\treturn mx_bjfinal( nodeVar4, nodeVar5, nodeVar6 );\n\n}\n\nfn mx_select ( b : bool, t : f32, f : f32 ) -> f32 {\n\n\tvar nodeVar0 : f32;\n\tvar nodeVar1 : f32;\n\tvar nodeVar2 : bool;\n\tvar nodeVar3 : f32;\n\n\tnodeVar0 = f;\n\tnodeVar1 = t;\n\tnodeVar2 = b;\n\n\treturn select( nodeVar0, nodeVar1, nodeVar2 );\n\n}\n\nfn mx_negate_if ( val : f32, b : bool ) -> f32 {\n\n\tvar nodeVar0 : bool;\n\tvar nodeVar1 : f32;\n\tvar nodeVar2 : f32;\n\n\tnodeVar0 = b;\n\tnodeVar1 = val;\n\n\treturn select( nodeVar1, ( - nodeVar1 ), nodeVar0 );\n\n}\n\nfn mx_gradient_float_1 ( hash : u32, x : f32, y : f32, z : f32 ) -> f32 {\n\n\tvar nodeVar0 : f32;\n\tvar nodeVar1 : f32;\n\tvar nodeVar2 : f32;\n\tvar nodeVar3 : u32;\n\tvar nodeVar4 : u32;\n\tvar nodeVar5 : f32;\n\tvar nodeVar6 : f32;\n\n\tnodeVar0 = z;\n\tnodeVar1 = y;\n\tnodeVar2 = x;\n\tnodeVar3 = hash;\n\tnodeVar4 = ( nodeVar3 & 15u );\n\tnodeVar5 = mx_select( ( nodeVar4 < 8u ), nodeVar2, nodeVar1 );\n\tnodeVar6 = mx_select( ( nodeVar4 < 4u ), nodeVar1, mx_select( ( ( nodeVar4 == 12u ) || ( nodeVar4 == 14u ) ), nodeVar2, nodeVar0 ) );\n\n\treturn ( mx_negate_if( nodeVar5, bool( ( nodeVar4 & 1u ) ) ) + mx_negate_if( nodeVar6, bool( ( nodeVar4 & 2u ) ) ) );\n\n}\n\nfn mx_floor ( x : f32 ) -> i32 {\n\n\tvar nodeVar0 : f32;\n\n\tnodeVar0 = x;\n\n\treturn i32( floor( nodeVar0 ) );\n\n}\n\nfn mx_fade ( t : f32 ) -> f32 {\n\n\tvar nodeVar0 : f32;\n\n\tnodeVar0 = t;\n\n\treturn ( ( ( nodeVar0 * nodeVar0 ) * nodeVar0 ) * ( ( nodeVar0 * ( ( nodeVar0 * 6.0 ) - 15.0 ) ) + 10.0 ) );\n\n}\n\nfn mx_hash_vec3_1 ( x : i32, y : i32, z : i32 ) -> vec3<u32> {\n\n\tvar nodeVar0 : i32;\n\tvar nodeVar1 : i32;\n\tvar nodeVar2 : i32;\n\tvar nodeVar3 : u32;\n\tvar nodeVar4 : vec3<u32>;\n\n\tnodeVar0 = z;\n\tnodeVar1 = y;\n\tnodeVar2 = x;\n\tnodeVar3 = mx_hash_int_2( nodeVar2, nodeVar1, nodeVar0 );\n\tnodeVar4 = vec3<u32>( 0u, 0u, 0u );\n\tnodeVar4.x = ( nodeVar3 & 255u );\n\tnodeVar4.y = ( ( nodeVar3 >> 8u ) & 255u );\n\tnodeVar4.z = ( ( nodeVar3 >> 16u ) & 255u );\n\n\treturn nodeVar4;\n\n}\n\nfn mx_gradient_vec3_1 ( hash : vec3<u32>, x : f32, y : f32, z : f32 ) -> vec3<f32> {\n\n\tvar nodeVar0 : f32;\n\tvar nodeVar1 : f32;\n\tvar nodeVar2 : f32;\n\tvar nodeVar3 : vec3<u32>;\n\n\tnodeVar0 = z;\n\tnodeVar1 = y;\n\tnodeVar2 = x;\n\tnodeVar3 = hash;\n\n\treturn vec3<f32>( mx_gradient_float_1( nodeVar3.x, nodeVar2, nodeVar1, nodeVar0 ), mx_gradient_float_1( nodeVar3.y, nodeVar2, nodeVar1, nodeVar0 ), mx_gradient_float_1( nodeVar3.z, nodeVar2, nodeVar1, nodeVar0 ) );\n\n}\n\nfn mx_trilerp_1 ( v0 : vec3<f32>, v1 : vec3<f32>, v2 : vec3<f32>, v3 : vec3<f32>, v4 : vec3<f32>, v5 : vec3<f32>, v6 : vec3<f32>, v7 : vec3<f32>, s : f32, t : f32, r : f32 ) -> vec3<f32> {\n\n\tvar nodeVar0 : f32;\n\tvar nodeVar1 : f32;\n\tvar nodeVar2 : f32;\n\tvar nodeVar3 : vec3<f32>;\n\tvar nodeVar4 : vec3<f32>;\n\tvar nodeVar5 : vec3<f32>;\n\tvar nodeVar6 : vec3<f32>;\n\tvar nodeVar7 : vec3<f32>;\n\tvar nodeVar8 : vec3<f32>;\n\tvar nodeVar9 : vec3<f32>;\n\tvar nodeVar10 : vec3<f32>;\n\tvar nodeVar11 : f32;\n\tvar nodeVar12 : f32;\n\tvar nodeVar13 : f32;\n\n\tnodeVar0 = r;\n\tnodeVar1 = t;\n\tnodeVar2 = s;\n\tnodeVar3 = v7;\n\tnodeVar4 = v6;\n\tnodeVar5 = v5;\n\tnodeVar6 = v4;\n\tnodeVar7 = v3;\n\tnodeVar8 = v2;\n\tnodeVar9 = v1;\n\tnodeVar10 = v0;\n\tnodeVar11 = ( 1.0 - nodeVar2 );\n\tnodeVar12 = ( 1.0 - nodeVar1 );\n\tnodeVar13 = ( 1.0 - nodeVar0 );\n\n\treturn ( ( vec3<f32>( nodeVar13 ) * ( ( vec3<f32>( nodeVar12 ) * ( ( nodeVar10 * vec3<f32>( nodeVar11 ) ) + ( nodeVar9 * vec3<f32>( nodeVar2 ) ) ) ) + ( vec3<f32>( nodeVar1 ) * ( ( nodeVar8 * vec3<f32>( nodeVar11 ) ) + ( nodeVar7 * vec3<f32>( nodeVar2 ) ) ) ) ) ) + ( vec3<f32>( nodeVar0 ) * ( ( vec3<f32>( nodeVar12 ) * ( ( nodeVar6 * vec3<f32>( nodeVar11 ) ) + ( nodeVar5 * vec3<f32>( nodeVar2 ) ) ) ) + ( vec3<f32>( nodeVar1 ) * ( ( nodeVar4 * vec3<f32>( nodeVar11 ) ) + ( nodeVar3 * vec3<f32>( nodeVar2 ) ) ) ) ) ) );\n\n}\n\nfn mx_gradient_scale3d_1 ( v : vec3<f32> ) -> vec3<f32> {\n\n\tvar nodeVar0 : vec3<f32>;\n\n\tnodeVar0 = v;\n\n\treturn ( vec3<f32>( 0.982 ) * nodeVar0 );\n\n}\n\nfn mx_perlin_noise_vec3_1 ( p : vec3<f32> ) -> vec3<f32> {\n\n\tvar nodeVar0 : vec3<f32>;\n\tvar nodeVar1 : i32;\n\tvar nodeVar2 : i32;\n\tvar nodeVar3 : i32;\n\tvar nodeVar4 : f32;\n\tvar nodeVar5 : f32;\n\tvar nodeVar6 : f32;\n\tvar nodeVar7 : f32;\n\tvar nodeVar8 : f32;\n\tvar nodeVar9 : f32;\n\tvar nodeVar10 : f32;\n\tvar nodeVar11 : f32;\n\tvar nodeVar12 : f32;\n\tvar nodeVar13 : vec3<f32>;\n\n\tnodeVar0 = p;\n\tnodeVar1 = 0;\n\tnodeVar2 = 0;\n\tnodeVar3 = 0;\n\tnodeVar4 = nodeVar0.x;\n\tnodeVar1 = mx_floor( nodeVar4 );\n\tnodeVar5 = ( nodeVar4 - f32( nodeVar1 ) );\n\tnodeVar6 = nodeVar0.y;\n\tnodeVar2 = mx_floor( nodeVar6 );\n\tnodeVar7 = ( nodeVar6 - f32( nodeVar2 ) );\n\tnodeVar8 = nodeVar0.z;\n\tnodeVar3 = mx_floor( nodeVar8 );\n\tnodeVar9 = ( nodeVar8 - f32( nodeVar3 ) );\n\tnodeVar10 = mx_fade( nodeVar5 );\n\tnodeVar11 = mx_fade( nodeVar7 );\n\tnodeVar12 = mx_fade( nodeVar9 );\n\tnodeVar13 = mx_trilerp_1( mx_gradient_vec3_1( mx_hash_vec3_1( nodeVar1, nodeVar2, nodeVar3 ), nodeVar5, nodeVar7, nodeVar9 ), mx_gradient_vec3_1( mx_hash_vec3_1( ( nodeVar1 + 1 ), nodeVar2, nodeVar3 ), ( nodeVar5 - 1.0 ), nodeVar7, nodeVar9 ), mx_gradient_vec3_1( mx_hash_vec3_1( nodeVar1, ( nodeVar2 + 1 ), nodeVar3 ), nodeVar5, ( nodeVar7 - 1.0 ), nodeVar9 ), mx_gradient_vec3_1( mx_hash_vec3_1( ( nodeVar1 + 1 ), ( nodeVar2 + 1 ), nodeVar3 ), ( nodeVar5 - 1.0 ), ( nodeVar7 - 1.0 ), nodeVar9 ), mx_gradient_vec3_1( mx_hash_vec3_1( nodeVar1, nodeVar2, ( nodeVar3 + 1 ) ), nodeVar5, nodeVar7, ( nodeVar9 - 1.0 ) ), mx_gradient_vec3_1( mx_hash_vec3_1( ( nodeVar1 + 1 ), nodeVar2, ( nodeVar3 + 1 ) ), ( nodeVar5 - 1.0 ), nodeVar7, ( nodeVar9 - 1.0 ) ), mx_gradient_vec3_1( mx_hash_vec3_1( nodeVar1, ( nodeVar2 + 1 ), ( nodeVar3 + 1 ) ), nodeVar5, ( nodeVar7 - 1.0 ), ( nodeVar9 - 1.0 ) ), mx_gradient_vec3_1( mx_hash_vec3_1( ( nodeVar1 + 1 ), ( nodeVar2 + 1 ), ( nodeVar3 + 1 ) ), ( nodeVar5 - 1.0 ), ( nodeVar7 - 1.0 ), ( nodeVar9 - 1.0 ) ), nodeVar10, nodeVar11, nodeVar12 );\n\n\treturn mx_gradient_scale3d_1( nodeVar13 );\n\n}\n\nfn mx_bits_to_01 ( bits : u32 ) -> f32 {\n\n\tvar nodeVar0 : u32;\n\n\tnodeVar0 = bits;\n\n\treturn ( f32( nodeVar0 ) / f32( 4294967295u ) );\n\n}\n\nfn mx_cell_noise_vec3_1 ( p : vec2<f32> ) -> vec3<f32> {\n\n\tvar nodeVar0 : vec2<f32>;\n\tvar nodeVar1 : i32;\n\tvar nodeVar2 : i32;\n\n\tnodeVar0 = p;\n\tnodeVar1 = mx_floor( nodeVar0.x );\n\tnodeVar2 = mx_floor( nodeVar0.y );\n\n\treturn vec3<f32>( mx_bits_to_01( mx_hash_int_2( nodeVar1, nodeVar2, 0 ) ), mx_bits_to_01( mx_hash_int_2( nodeVar1, nodeVar2, 1 ) ), mx_bits_to_01( mx_hash_int_2( nodeVar1, nodeVar2, 2 ) ) );\n\n}\n\nfn mx_worley_distance_0 ( p : vec2<f32>, x : i32, y : i32, xoff : i32, yoff : i32, jitter : f32, metric : i32 ) -> f32 {\n\n\tvar nodeVar0 : i32;\n\tvar nodeVar1 : f32;\n\tvar nodeVar2 : i32;\n\tvar nodeVar3 : i32;\n\tvar nodeVar4 : i32;\n\tvar nodeVar5 : i32;\n\tvar nodeVar6 : vec2<f32>;\n\tvar nodeVar7 : vec3<f32>;\n\tvar nodeVar8 : vec2<f32>;\n\tvar nodeVar9 : vec2<f32>;\n\tvar nodeVar10 : vec2<f32>;\n\n\tnodeVar0 = metric;\n\tnodeVar1 = jitter;\n\tnodeVar2 = yoff;\n\tnodeVar3 = xoff;\n\tnodeVar4 = y;\n\tnodeVar5 = x;\n\tnodeVar6 = p;\n\tnodeVar7 = mx_cell_noise_vec3_1( vec2<f32>( f32( ( nodeVar5 + nodeVar3 ) ), f32( ( nodeVar4 + nodeVar2 ) ) ) );\n\tnodeVar8 = vec2<f32>( nodeVar7.x, nodeVar7.y );\n\tnodeVar8 = ( nodeVar8 - vec2<f32>( 0.5 ) );\n\tnodeVar8 = ( nodeVar8 * vec2<f32>( nodeVar1 ) );\n\tnodeVar8 = ( nodeVar8 + vec2<f32>( 0.5 ) );\n\tnodeVar9 = ( vec2<f32>( f32( nodeVar5 ), f32( nodeVar4 ) ) + nodeVar8 );\n\tnodeVar10 = ( nodeVar9 - nodeVar6 );\n\n\tif ( ( nodeVar0 == 2 ) ) {\n\n\t\treturn ( abs( nodeVar10.x ) + abs( nodeVar10.y ) );\n\n\t}\n\n\n\tif ( ( nodeVar0 == 3 ) ) {\n\n\t\treturn max( abs( nodeVar10.x ), abs( nodeVar10.y ) );\n\n\t}\n\n\n\treturn dot( nodeVar10, nodeVar10 );\n\n}\n\nfn mx_fractal_noise_vec3 ( p : vec3<f32>, octaves : i32, lacunarity : f32, diminish : f32 ) -> vec3<f32> {\n\n\tvar nodeVar0 : f32;\n\tvar nodeVar1 : f32;\n\tvar nodeVar2 : vec3<f32>;\n\tvar nodeVar3 : vec3<f32>;\n\tvar nodeVar4 : f32;\n\tvar nodeVar5 : i32;\n\n\tnodeVar0 = diminish;\n\tnodeVar1 = lacunarity;\n\tnodeVar2 = p;\n\tnodeVar3 = vec3<f32>( 0.0, 0.0, 0.0 );\n\tnodeVar4 = 1.0;\n\tnodeVar5 = octaves;\n\n\tfor ( var i : i32 = 0; i < nodeVar5; i ++ ) {\n\n\t\tnodeVar3 = ( nodeVar3 + ( vec3<f32>( nodeVar4 ) * mx_perlin_noise_vec3_1( nodeVar2 ) ) );\n\t\tnodeVar4 = ( nodeVar4 * nodeVar0 );\n\t\tnodeVar2 = ( nodeVar2 * vec3<f32>( nodeVar1 ) );\n\n\t}\n\n\n\treturn nodeVar3;\n\n}\n\nfn mx_worley_noise_vec3_0 ( p : vec2<f32>, jitter : f32, metric : i32 ) -> vec3<f32> {\n\n\tvar nodeVar0 : i32;\n\tvar nodeVar1 : f32;\n\tvar nodeVar2 : vec2<f32>;\n\tvar nodeVar3 : i32;\n\tvar nodeVar4 : i32;\n\tvar nodeVar5 : f32;\n\tvar nodeVar6 : f32;\n\tvar nodeVar7 : vec2<f32>;\n\tvar nodeVar8 : vec3<f32>;\n\tvar nodeVar9 : f32;\n\n\tnodeVar0 = metric;\n\tnodeVar1 = jitter;\n\tnodeVar2 = p;\n\tnodeVar3 = 0;\n\tnodeVar4 = 0;\n\tnodeVar5 = nodeVar2.x;\n\tnodeVar3 = mx_floor( nodeVar5 );\n\tnodeVar6 = nodeVar2.y;\n\tnodeVar4 = mx_floor( nodeVar6 );\n\tnodeVar7 = vec2<f32>( ( nodeVar5 - f32( nodeVar3 ) ), ( nodeVar6 - f32( nodeVar4 ) ) );\n\tnodeVar8 = vec3<f32>( 1000000.0, 1000000.0, 1000000.0 );\n\n\tfor ( var x : i32 = -1; x <= 1; x ++ ) {\n\n\n\t\tfor ( var y : i32 = -1; y <= 1; y ++ ) {\n\n\t\t\tnodeVar9 = mx_worley_distance_0( nodeVar7, x, y, nodeVar3, nodeVar4, nodeVar1, nodeVar0 );\n\n\t\t\tif ( ( nodeVar9 < nodeVar8.x ) ) {\n\n\t\t\t\tnodeVar8.z = nodeVar8.y;\n\t\t\t\tnodeVar8.y = nodeVar8.x;\n\t\t\t\tnodeVar8.x = nodeVar9;\n\t\t\t\t\n\n\t\t\t} else {\n\n\n\t\t\t\tif ( ( nodeVar9 < nodeVar8.y ) ) {\n\n\t\t\t\t\tnodeVar8.z = nodeVar8.y;\n\t\t\t\t\tnodeVar8.y = nodeVar9;\n\t\t\t\t\t\n\n\t\t\t\t} else {\n\n\n\t\t\t\t\tif ( ( nodeVar9 < nodeVar8.z ) ) {\n\n\t\t\t\t\t\tnodeVar8.z = nodeVar9;\n\t\t\t\t\t\t\n\n\t\t\t\t\t}\n\n\t\t\t\t\t\n\n\t\t\t\t}\n\n\t\t\t\t\n\n\t\t\t}\n\n\n\t\t}\n\n\n\t}\n\n\n\tif ( ( nodeVar0 == 0 ) ) {\n\n\t\tnodeVar8 = sqrt( nodeVar8 );\n\t\t\n\n\t}\n\n\n\treturn nodeVar8;\n\n}\n\n\n\n@fragment\nfn main( @location( 0 ) nodeVarying4 : vec2<f32> ) -> OutputStruct {\n\n\t// flow\n\t// code\n\n\tnodeVar0 = ( nodeVarying4 * vec2<f32>( 6.0 ) );\n\tDiffuseColor = vec4<f32>( ( ( ( ( ( mx_fractal_noise_vec3( vec3<f32>( nodeVar0, 0.0 ), 5, 2.0, 0.55 ) * vec3<f32>( 1.0 ) ) * vec3<f32>( 0.5 ) ) + vec3<f32>( 0.5 ) ) * vec3<f32>( 0.75 ) ) + ( mx_worley_noise_vec3_0( ( nodeVar0 * vec2<f32>( 0.7 ) ), 1.0, 1 ) * vec3<f32>( 0.25 ) ) ), 1.0 );\n\tDiffuseColor.w = ( DiffuseColor.w * object.nodeUniform0 );\n\tDiffuseColor.w = 1.0;\n\tnodeVar1 = max( vec4<f32>( DiffuseColor.xyz, DiffuseColor.w ), vec4<f32>( 0.0 ) );\n\tOutput = nodeVar1;\n\n\t// result\n\n\toutput.color = nodeVar1;\n\n\treturn output;\n\n}\n", | |
| "hardwareClipping": false, | |
| "key": "main/procedural-card", | |
| "observer": { | |
| "hasAnimation": false, | |
| "hasNode": true | |
| }, | |
| "uniformCalls": [ | |
| { | |
| "name": "nodeUniform0", | |
| "nid": 2244, | |
| "node": { | |
| "k": "owned", | |
| "owner": { | |
| "k": "materialCache", | |
| "property": "opacity", | |
| "type": "float" | |
| }, | |
| "path": [ | |
| "node" | |
| ], | |
| "prime": "reference" | |
| }, | |
| "stage": "fragment", | |
| "type": "float" | |
| }, | |
| { | |
| "name": "cameraProjectionMatrix", | |
| "nid": 1030, | |
| "node": { | |
| "k": "namedRenderUniform", | |
| "name": "cameraProjectionMatrix" | |
| }, | |
| "stage": "vertex", | |
| "type": "mat4" | |
| }, | |
| { | |
| "name": "cameraViewMatrix", | |
| "nid": 1039, | |
| "node": { | |
| "k": "namedRenderUniform", | |
| "name": "cameraViewMatrix" | |
| }, | |
| "stage": "vertex", | |
| "type": "mat4" | |
| }, | |
| { | |
| "name": "nodeUniform3", | |
| "nid": 194, | |
| "node": { | |
| "k": "owned", | |
| "owner": { | |
| "k": "tsl", | |
| "name": "mediumpModelViewMatrix" | |
| }, | |
| "path": [ | |
| 0, | |
| 1, | |
| 0 | |
| ] | |
| }, | |
| "stage": "vertex", | |
| "type": "mat4" | |
| } | |
| ], | |
| "updateAfterNodes": [], | |
| "updateBeforeNodes": [], | |
| "updateNodes": [ | |
| { | |
| "k": "namedRenderUniform", | |
| "name": "cameraProjectionMatrix" | |
| }, | |
| { | |
| "k": "tsl", | |
| "name": "renderGroup" | |
| }, | |
| { | |
| "k": "namedRenderUniform", | |
| "name": "cameraViewMatrix" | |
| }, | |
| { | |
| "k": "tsl", | |
| "name": "modelWorldMatrix" | |
| }, | |
| { | |
| "k": "tsl", | |
| "name": "objectGroup" | |
| }, | |
| { | |
| "k": "materialCache", | |
| "property": "opacity", | |
| "type": "float" | |
| } | |
| ], | |
| "vertexShader": "// Three.js r185 - Node System\n\n// directives\n\n\n// structs\n\n\n// uniforms\n\nstruct renderStruct {\n\tcameraProjectionMatrix : mat4x4<f32>,\n\tcameraViewMatrix : mat4x4<f32>\n};\n@binding( 0 ) @group( 0 )\nvar<uniform> render : renderStruct;\n\nstruct objectStruct {\n\tnodeUniform0 : f32,\n\tnodeUniform3 : mat4x4<f32>\n};\n@binding( 0 ) @group( 1 )\nvar<uniform> object : objectStruct;\n\n// varyings\n\nstruct VaryingsStruct {\n\t@location( 0 ) nodeVarying4 : vec2<f32>,\n\t@builtin( position ) builtinClipSpace : vec4<f32>\n};\nvar<private> varyings : VaryingsStruct;\n\n// vars\nvar<private> modelViewMatrix : mat4x4<f32>;\nvar<private> VERTEX_nodeVar2 : vec4<f32>;\nvar<private> v_modelViewProjection : vec4<f32>;\nvar<private> v_positionView : vec3<f32>;\nvar<private> positionLocal : vec3<f32>;\nvar<private> VERTEX_v_modelViewProjection : vec4<f32>;\n\n// codes\n\n\n@vertex\nfn main( @location( 0 ) uv : vec2<f32>,\n\t@location( 1 ) position : vec3<f32> ) -> VaryingsStruct {\n\n\t// flow\n\t// code\n\n\tvaryings.nodeVarying4 = uv;\n\tmodelViewMatrix = ( render.cameraViewMatrix * object.nodeUniform3 );\n\tpositionLocal = position;\n\tv_positionView = ( modelViewMatrix * vec4<f32>( positionLocal, 1.0 ) ).xyz;\n\tVERTEX_nodeVar2 = ( render.cameraProjectionMatrix * vec4<f32>( v_positionView, 1.0 ) );\n\tVERTEX_v_modelViewProjection = VERTEX_nodeVar2;\n\n\t// result\n\n\tvaryings.builtinClipSpace = VERTEX_v_modelViewProjection;\n\n\treturn varyings;\n\n}\n" | |
| } | |
| }, | |
| "runtime": { | |
| "address": 1, | |
| "hydration": 1, | |
| "id": "three-webgpu-r185-v1", | |
| "recipe": 1 | |
| }, | |
| "scene": "main", | |
| "three": "0.185.1", | |
| "threeBlocks": "0.1.0", | |
| "version": 2 | |
| } |
This file has been truncated, but you can view the full file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var eE=Object.defineProperty;var tE=(n,e)=>{for(var t in e)eE(n,t,{get:e[t],enumerable:!0})};var tn="186dev";var qN=0,jN=1,XN=2;var YN=0,Gn=1,Ru=2,Do=3,Yr=0,Ze=1,Kr=2,Pr=0,Zt=1,zn=2,$n=3,Wn=4,rn=5,tl=6,Jt=100,Fd=101,Ld=102,KN=103,QN=104,Zi=200,Pd=201,Dd=202,Ud=203,sn=204,nn=205,Id=206,Od=207,kd=208,Vd=209,Gd=210;var Uo=0,Io=1,Oo=2,fs=3,ko=4,Vo=5,Go=6,zo=7,Hn=0,ZN=1,JN=2,ms=0,ew=1,tw=2,rw=3,iw=4;var sw=6,nw=7;var Cu=300,Ji=301,$o=302,Eu=303,Bu=304,Wo=306,gs=1e3,Dr=1001,xs=1002,Pe=1003,zd=1004;var on=1005;var je=1006,Fu=1007;var Ur=1008,ow=1008,it=1009,Ci=1010,mr=1011,er=1012,Je=1013,Ce=1014,ze=1015,qe=1016,rl=1017,il=1018,Qr=1020,qn=35902,jn=35899,Xn=1021,Ei=1022,wt=1023,Mt=1026,Ht=1027,Bi=1028,Fi=1029,vt=1030,Li=1031,sl=1032,Yn=1033,Kn=33776,Qn=33777,Zn=33778,Jn=33779,Lu=35840,Pu=35841,Du=35842,Uu=35843,Ho=36196,qo=37492,jo=37496,Xo=37488,Yo=37489,an=37490,Ko=37491,Qo=37808,Zo=37809,Jo=37810,ea=37811,ta=37812,ra=37813,ia=37814,sa=37815,na=37816,oa=37817,aa=37818,la=37819,ua=37820,ca=37821,da=36492,ha=36494,pa=36495,fa=36283,ma=36284,ln=36285,ga=36286;var gr=0,aw=1,Zr="",tr="srgb",xa="srgb-linear",nl="linear",fe="srgb",$d="",Wd="rg",lw="ga",uw=0,un=7680,cw=7681,dw=7682,hw=7683,pw=34055,fw=34056,mw=5386,gw=512,xw=513,yw=514,bw=515,_w=516,Tw=517,Sw=518,Iu=519,Hd=512,ol=513,qd=514,Pi=515,ya=516,jd=517,ui=518,Xd=519,ys=35044,eo=35048;var At=2e3,yt=2001,ci={COMPUTE:"compute",RENDER:"render"};var xr={TEXTURE_COMPARE:"depthTextureCompare"};function ww(n){for(let e=n.length-1;e>=0;--e)if(n[e]>=65535)return!0;return!1}function ba(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function Yd(n){return document.createElementNS("http://www.w3.org/1999/xhtml",n)}function Mw(){let n=Yd("canvas");return n.style.display="block",n}var Nw={},al=null;function Ou(...n){let e="THREE."+n.shift();al?al("log",e,...n):console.log(e,...n)}function vw(n){let e=n[0];if(typeof e=="string"&&e.startsWith("TSL:")){let t=n[1];t&&t.isStackTrace?n[0]+=" "+t.getLocation():n[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return n}function U(...n){n=vw(n);let e="THREE."+n.shift();if(al)al("warn",e,...n);else{let t=n[0];t&&t.isStackTrace?console.warn(t.getError(e)):console.warn(e,...n)}}function I(...n){n=vw(n);let e="THREE."+n.shift();if(al)al("error",e,...n);else{let t=n[0];t&&t.isStackTrace?console.error(t.getError(e)):console.error(e,...n)}}function he(...n){let e=n.join(" ");e in Nw||(Nw[e]=!0,U(...n))}function Kd(){return typeof self<"u"&&typeof self.scheduler<"u"&&typeof self.scheduler.yield<"u"?self.scheduler.yield():new Promise(n=>{requestAnimationFrame(n)})}var Qd={[Uo]:Io,[Oo]:Go,[ko]:zo,[fs]:Vo,[Io]:Uo,[Go]:Oo,[zo]:ko,[Vo]:fs};var bt=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});let r=this._listeners;r[e]===void 0&&(r[e]=[]),r[e].indexOf(t)===-1&&r[e].push(t)}hasEventListener(e,t){let r=this._listeners;return r===void 0?!1:r[e]!==void 0&&r[e].indexOf(t)!==-1}removeEventListener(e,t){let r=this._listeners;if(r===void 0)return;let i=r[e];if(i!==void 0){let s=i.indexOf(t);s!==-1&&i.splice(s,1)}}dispatchEvent(e){let t=this._listeners;if(t===void 0)return;let r=t[e.type];if(r!==void 0){e.target=this;let i=r.slice(0);for(let s=0,o=i.length;s<o;s++)i[s].call(this,e);e.target=null}}};var yr=["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"],Aw=1234567,ll=Math.PI/180,cn=180/Math.PI;function Ir(){let n=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(yr[n&255]+yr[n>>8&255]+yr[n>>16&255]+yr[n>>24&255]+"-"+yr[e&255]+yr[e>>8&255]+"-"+yr[e>>16&15|64]+yr[e>>24&255]+"-"+yr[t&63|128]+yr[t>>8&255]+"-"+yr[t>>16&255]+yr[t>>24&255]+yr[r&255]+yr[r>>8&255]+yr[r>>16&255]+yr[r>>24&255]).toLowerCase()}function Te(n,e,t){return Math.max(e,Math.min(t,n))}function Zd(n,e){return(n%e+e)%e}function rE(n,e,t,r,i){return r+(n-e)*(i-r)/(t-e)}function iE(n,e,t){return n!==e?(t-n)/(e-n):0}function ul(n,e,t){return(1-t)*n+t*e}function sE(n,e,t,r){return ul(n,e,1-Math.exp(-t*r))}function nE(n,e=1){return e-Math.abs(Zd(n,e*2)-e)}function oE(n,e,t){return n<=e?0:n>=t?1:(n=(n-e)/(t-e),n*n*(3-2*n))}function aE(n,e,t){return n<=e?0:n>=t?1:(n=(n-e)/(t-e),n*n*n*(n*(n*6-15)+10))}function lE(n,e){return n+Math.floor(Math.random()*(e-n+1))}function uE(n,e){return n+Math.random()*(e-n)}function cE(n){return n*(.5-Math.random())}function dE(n){n!==void 0&&(Aw=n);let e=Aw+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function hE(n){return n*ll}function pE(n){return n*cn}function fE(n){return(n&n-1)===0&&n!==0}function mE(n){return Math.pow(2,Math.ceil(Math.log(n)/Math.LN2))}function gE(n){return Math.pow(2,Math.floor(Math.log(n)/Math.LN2))}function xE(n,e,t,r,i){let s=Math.cos,o=Math.sin,a=s(t/2),l=o(t/2),u=s((e+r)/2),c=o((e+r)/2),d=s((e-r)/2),h=o((e-r)/2),p=s((r-e)/2),f=o((r-e)/2);switch(i){case"XYX":n.set(a*c,l*d,l*h,a*u);break;case"YZY":n.set(l*h,a*c,l*d,a*u);break;case"ZXZ":n.set(l*d,l*h,a*c,a*u);break;case"XZX":n.set(a*c,l*f,l*p,a*u);break;case"YXY":n.set(l*p,a*c,l*f,a*u);break;case"ZYZ":n.set(l*f,l*p,a*c,a*u);break;default:U("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function rr(n,e){switch(e.constructor){case Float32Array:return n;case Uint32Array:return n/4294967295;case Uint16Array:return n/65535;case Uint8Array:return n/255;case Int32Array:return Math.max(n/2147483647,-1);case Int16Array:return Math.max(n/32767,-1);case Int8Array:return Math.max(n/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function Ne(n,e){switch(e.constructor){case Float32Array:return n;case Uint32Array:return Math.round(n*4294967295);case Uint16Array:return Math.round(n*65535);case Uint8Array:return Math.round(n*255);case Int32Array:return Math.round(n*2147483647);case Int16Array:return Math.round(n*32767);case Int8Array:return Math.round(n*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}var Jd={DEG2RAD:ll,RAD2DEG:cn,generateUUID:Ir,clamp:Te,euclideanModulo:Zd,mapLinear:rE,inverseLerp:iE,lerp:ul,damp:sE,pingpong:nE,smoothstep:oE,smootherstep:aE,randInt:lE,randFloat:uE,randFloatSpread:cE,seededRandom:dE,degToRad:hE,radToDeg:pE,isPowerOfTwo:fE,ceilPowerOfTwo:mE,floorPowerOfTwo:gE,setQuaternionFromProperEuler:xE,normalize:Ne,denormalize:rr};var se=class n{static{n.prototype.isVector2=!0}constructor(e=0,t=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("THREE.Vector2: 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("THREE.Vector2: 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){let t=this.x,r=this.y,i=e.elements;return this.x=i[0]*t+i[3]*r+i[6],this.y=i[1]*t+i[4]*r+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=Te(this.x,e.x,t.x),this.y=Te(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=Te(this.x,e,t),this.y=Te(this.y,e,t),this}clampLength(e,t){let r=this.length();return this.divideScalar(r||1).multiplyScalar(Te(r,e,t))}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){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let r=this.dot(e)/t;return Math.acos(Te(r,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,r=this.y-e.y;return t*t+r*r}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,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,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){let r=Math.cos(t),i=Math.sin(t),s=this.x-e.x,o=this.y-e.y;return this.x=s*r-o*i+e.x,this.y=s*i+o*r+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}};var Jr=class{constructor(e=0,t=0,r=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=r,this._w=i}static slerpFlat(e,t,r,i,s,o,a){let l=r[i+0],u=r[i+1],c=r[i+2],d=r[i+3],h=s[o+0],p=s[o+1],f=s[o+2],m=s[o+3];if(d!==m||l!==h||u!==p||c!==f){let g=l*h+u*p+c*f+d*m;g<0&&(h=-h,p=-p,f=-f,m=-m,g=-g);let x=1-a;if(g<.9995){let w=Math.acos(g),v=Math.sin(w);x=Math.sin(x*w)/v,a=Math.sin(a*w)/v,l=l*x+h*a,u=u*x+p*a,c=c*x+f*a,d=d*x+m*a}else{l=l*x+h*a,u=u*x+p*a,c=c*x+f*a,d=d*x+m*a;let w=1/Math.sqrt(l*l+u*u+c*c+d*d);l*=w,u*=w,c*=w,d*=w}}e[t]=l,e[t+1]=u,e[t+2]=c,e[t+3]=d}static multiplyQuaternionsFlat(e,t,r,i,s,o){let a=r[i],l=r[i+1],u=r[i+2],c=r[i+3],d=s[o],h=s[o+1],p=s[o+2],f=s[o+3];return e[t]=a*f+c*d+l*p-u*h,e[t+1]=l*f+c*h+u*d-a*p,e[t+2]=u*f+c*p+a*h-l*d,e[t+3]=c*f-a*d-l*h-u*p,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,r,i){return this._x=e,this._y=t,this._z=r,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){let r=e._x,i=e._y,s=e._z,o=e._order,a=Math.cos,l=Math.sin,u=a(r/2),c=a(i/2),d=a(s/2),h=l(r/2),p=l(i/2),f=l(s/2);switch(o){case"XYZ":this._x=h*c*d+u*p*f,this._y=u*p*d-h*c*f,this._z=u*c*f+h*p*d,this._w=u*c*d-h*p*f;break;case"YXZ":this._x=h*c*d+u*p*f,this._y=u*p*d-h*c*f,this._z=u*c*f-h*p*d,this._w=u*c*d+h*p*f;break;case"ZXY":this._x=h*c*d-u*p*f,this._y=u*p*d+h*c*f,this._z=u*c*f+h*p*d,this._w=u*c*d-h*p*f;break;case"ZYX":this._x=h*c*d-u*p*f,this._y=u*p*d+h*c*f,this._z=u*c*f-h*p*d,this._w=u*c*d+h*p*f;break;case"YZX":this._x=h*c*d+u*p*f,this._y=u*p*d+h*c*f,this._z=u*c*f-h*p*d,this._w=u*c*d-h*p*f;break;case"XZY":this._x=h*c*d-u*p*f,this._y=u*p*d-h*c*f,this._z=u*c*f+h*p*d,this._w=u*c*d+h*p*f;break;default:U("Quaternion: .setFromEuler() encountered an unknown order: "+o)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){let r=t/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback(),this}setFromRotationMatrix(e){let t=e.elements,r=t[0],i=t[4],s=t[8],o=t[1],a=t[5],l=t[9],u=t[2],c=t[6],d=t[10],h=r+a+d;if(h>0){let p=.5/Math.sqrt(h+1);this._w=.25/p,this._x=(c-l)*p,this._y=(s-u)*p,this._z=(o-i)*p}else if(r>a&&r>d){let p=2*Math.sqrt(1+r-a-d);this._w=(c-l)/p,this._x=.25*p,this._y=(i+o)/p,this._z=(s+u)/p}else if(a>d){let p=2*Math.sqrt(1+a-r-d);this._w=(s-u)/p,this._x=(i+o)/p,this._y=.25*p,this._z=(l+c)/p}else{let p=2*Math.sqrt(1+d-r-a);this._w=(o-i)/p,this._x=(s+u)/p,this._y=(l+c)/p,this._z=.25*p}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let r=e.dot(t)+1;return r<1e-8?(r=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=r):(this._x=0,this._y=-e.z,this._z=e.y,this._w=r)):(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=r),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(Te(this.dot(e),-1,1)))}rotateTowards(e,t){let r=this.angleTo(e);if(r===0)return this;let i=Math.min(1,t/r);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 e===0?(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){let r=e._x,i=e._y,s=e._z,o=e._w,a=t._x,l=t._y,u=t._z,c=t._w;return this._x=r*c+o*a+i*u-s*l,this._y=i*c+o*l+s*a-r*u,this._z=s*c+o*u+r*l-i*a,this._w=o*c-r*a-i*l-s*u,this._onChangeCallback(),this}slerp(e,t){let r=e._x,i=e._y,s=e._z,o=e._w,a=this.dot(e);a<0&&(r=-r,i=-i,s=-s,o=-o,a=-a);let l=1-t;if(a<.9995){let u=Math.acos(a),c=Math.sin(u);l=Math.sin(l*u)/c,t=Math.sin(t*u)/c,this._x=this._x*l+r*t,this._y=this._y*l+i*t,this._z=this._z*l+s*t,this._w=this._w*l+o*t,this._onChangeCallback()}else this._x=this._x*l+r*t,this._y=this._y*l+i*t,this._z=this._z*l+s*t,this._w=this._w*l+o*t,this.normalize();return this}slerpQuaternions(e,t,r){return this.copy(e).slerp(t,r)}random(){let e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),r=Math.random(),i=Math.sqrt(1-r),s=Math.sqrt(r);return this.set(i*Math.sin(e),i*Math.cos(e),s*Math.sin(t),s*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}};var C=class n{static{n.prototype.isVector3=!0}constructor(e=0,t=0,r=0){this.x=e,this.y=t,this.z=r}set(e,t,r){return r===void 0&&(r=this.z),this.x=e,this.y=t,this.z=r,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("THREE.Vector3: 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("THREE.Vector3: 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(Rw.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Rw.setFromAxisAngle(e,t))}applyMatrix3(e){let t=this.x,r=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[3]*r+s[6]*i,this.y=s[1]*t+s[4]*r+s[7]*i,this.z=s[2]*t+s[5]*r+s[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){let t=this.x,r=this.y,i=this.z,s=e.elements,o=1/(s[3]*t+s[7]*r+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*r+s[8]*i+s[12])*o,this.y=(s[1]*t+s[5]*r+s[9]*i+s[13])*o,this.z=(s[2]*t+s[6]*r+s[10]*i+s[14])*o,this}applyQuaternion(e){let t=this.x,r=this.y,i=this.z,s=e.x,o=e.y,a=e.z,l=e.w,u=2*(o*i-a*r),c=2*(a*t-s*i),d=2*(s*r-o*t);return this.x=t+l*u+o*d-a*c,this.y=r+l*c+a*u-s*d,this.z=i+l*d+s*c-o*u,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){let t=this.x,r=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[4]*r+s[8]*i,this.y=s[1]*t+s[5]*r+s[9]*i,this.z=s[2]*t+s[6]*r+s[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=Te(this.x,e.x,t.x),this.y=Te(this.y,e.y,t.y),this.z=Te(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=Te(this.x,e,t),this.y=Te(this.y,e,t),this.z=Te(this.z,e,t),this}clampLength(e,t){let r=this.length();return this.divideScalar(r||1).multiplyScalar(Te(r,e,t))}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,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this.z=e.z+(t.z-e.z)*r,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){let r=e.x,i=e.y,s=e.z,o=t.x,a=t.y,l=t.z;return this.x=i*l-s*a,this.y=s*o-r*l,this.z=r*a-i*o,this}projectOnVector(e){let t=e.lengthSq();if(t===0)return this.set(0,0,0);let r=e.dot(this)/t;return this.copy(e).multiplyScalar(r)}projectOnPlane(e){return Fg.copy(this).projectOnVector(e),this.sub(Fg)}reflect(e){return this.sub(Fg.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let r=this.dot(e)/t;return Math.acos(Te(r,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,r=this.y-e.y,i=this.z-e.z;return t*t+r*r+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,r){let i=Math.sin(t)*e;return this.x=i*Math.sin(r),this.y=Math.cos(t)*e,this.z=i*Math.cos(r),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,r){return this.x=e*Math.sin(t),this.y=r,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){let t=this.setFromMatrixColumn(e,0).length(),r=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=r,this.z=i,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}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(){let e=Math.random()*Math.PI*2,t=Math.random()*2-1,r=Math.sqrt(1-t*t);return this.x=r*Math.cos(e),this.y=t,this.z=r*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},Fg=new C,Rw=new Jr;var et=class n{static{n.prototype.isMatrix3=!0}constructor(e,t,r,i,s,o,a,l,u){this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,r,i,s,o,a,l,u)}set(e,t,r,i,s,o,a,l,u){let c=this.elements;return c[0]=e,c[1]=i,c[2]=a,c[3]=t,c[4]=s,c[5]=l,c[6]=r,c[7]=o,c[8]=u,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){let t=this.elements,r=e.elements;return t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3],t[4]=r[4],t[5]=r[5],t[6]=r[6],t[7]=r[7],t[8]=r[8],this}extractBasis(e,t,r){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),r.setFromMatrix3Column(this,2),this}setFromMatrix4(e){let 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){let r=e.elements,i=t.elements,s=this.elements,o=r[0],a=r[3],l=r[6],u=r[1],c=r[4],d=r[7],h=r[2],p=r[5],f=r[8],m=i[0],g=i[3],x=i[6],w=i[1],v=i[4],E=i[7],b=i[2],S=i[5],T=i[8];return s[0]=o*m+a*w+l*b,s[3]=o*g+a*v+l*S,s[6]=o*x+a*E+l*T,s[1]=u*m+c*w+d*b,s[4]=u*g+c*v+d*S,s[7]=u*x+c*E+d*T,s[2]=h*m+p*w+f*b,s[5]=h*g+p*v+f*S,s[8]=h*x+p*E+f*T,this}multiplyScalar(e){let 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(){let e=this.elements,t=e[0],r=e[1],i=e[2],s=e[3],o=e[4],a=e[5],l=e[6],u=e[7],c=e[8];return t*o*c-t*a*u-r*s*c+r*a*l+i*s*u-i*o*l}invert(){let e=this.elements,t=e[0],r=e[1],i=e[2],s=e[3],o=e[4],a=e[5],l=e[6],u=e[7],c=e[8],d=c*o-a*u,h=a*l-c*s,p=u*s-o*l,f=t*d+r*h+i*p;if(f===0)return this.set(0,0,0,0,0,0,0,0,0);let m=1/f;return e[0]=d*m,e[1]=(i*u-c*r)*m,e[2]=(a*r-i*o)*m,e[3]=h*m,e[4]=(c*t-i*l)*m,e[5]=(i*s-a*t)*m,e[6]=p*m,e[7]=(r*l-u*t)*m,e[8]=(o*t-r*s)*m,this}transpose(){let e,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){let 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,r,i,s,o,a){let l=Math.cos(s),u=Math.sin(s);return this.set(r*l,r*u,-r*(l*o+u*a)+o+e,-i*u,i*l,-i*(-u*o+l*a)+a+t,0,0,1),this}scale(e,t){return he("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(Lg.makeScale(e,t)),this}rotate(e){return he("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(Lg.makeRotation(-e)),this}translate(e,t){return he("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(Lg.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){let t=Math.cos(e),r=Math.sin(e);return this.set(t,-r,0,r,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){let t=this.elements,r=e.elements;for(let i=0;i<9;i++)if(t[i]!==r[i])return!1;return!0}fromArray(e,t=0){for(let r=0;r<9;r++)this.elements[r]=e[r+t];return this}toArray(e=[],t=0){let r=this.elements;return e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+3]=r[3],e[t+4]=r[4],e[t+5]=r[5],e[t+6]=r[6],e[t+7]=r[7],e[t+8]=r[8],e}clone(){return new this.constructor().fromArray(this.elements)}},Lg=new et;var Cw=new et().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Ew=new et().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function yE(){let n={enabled:!0,workingColorSpace:xa,spaces:{},convert:function(i,s,o){return this.enabled===!1||s===o||!s||!o||(this.spaces[s].transfer===fe&&(i.r=es(i.r),i.g=es(i.g),i.b=es(i.b)),this.spaces[s].primaries!==this.spaces[o].primaries&&(i.applyMatrix3(this.spaces[s].toXYZ),i.applyMatrix3(this.spaces[o].fromXYZ)),this.spaces[o].transfer===fe&&(i.r=_a(i.r),i.g=_a(i.g),i.b=_a(i.b))),i},workingToColorSpace:function(i,s){return this.convert(i,this.workingColorSpace,s)},colorSpaceToWorking:function(i,s){return this.convert(i,s,this.workingColorSpace)},getPrimaries:function(i){return this.spaces[i].primaries},getTransfer:function(i){return i===Zr?nl:this.spaces[i].transfer},getToneMappingMode:function(i){return this.spaces[i].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(i,s=this.workingColorSpace){return i.fromArray(this.spaces[s].luminanceCoefficients)},define:function(i){Object.assign(this.spaces,i)},_getMatrix:function(i,s,o){return i.copy(this.spaces[s].toXYZ).multiply(this.spaces[o].fromXYZ)},_getDrawingBufferColorSpace:function(i){return this.spaces[i].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(i=this.workingColorSpace){return this.spaces[i].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(i,s){return he("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),n.workingToColorSpace(i,s)},toWorkingColorSpace:function(i,s){return he("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),n.colorSpaceToWorking(i,s)}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],r=[.3127,.329];return n.define({[xa]:{primaries:e,whitePoint:r,transfer:nl,toXYZ:Cw,fromXYZ:Ew,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:tr},outputColorSpaceConfig:{drawingBufferColorSpace:tr}},[tr]:{primaries:e,whitePoint:r,transfer:fe,toXYZ:Cw,fromXYZ:Ew,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:tr}}}),n}var Me=yE();function es(n){return n<.04045?n*.0773993808:Math.pow(n*.9478672986+.0521327014,2.4)}function _a(n){return n<.0031308?n*12.92:1.055*Math.pow(n,.41666)-.055}var cl,eh=class{static getDataURL(e,t="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let r;if(e instanceof HTMLCanvasElement)r=e;else{cl===void 0&&(cl=Yd("canvas")),cl.width=e.width,cl.height=e.height;let i=cl.getContext("2d");e instanceof ImageData?i.putImageData(e,0,0):i.drawImage(e,0,0,e.width,e.height),r=cl}return r.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){let t=Yd("canvas");t.width=e.width,t.height=e.height;let r=t.getContext("2d");r.drawImage(e,0,0,e.width,e.height);let i=r.getImageData(0,0,e.width,e.height),s=i.data;for(let o=0;o<s.length;o++)s[o]=es(s[o]/255)*255;return r.putImageData(i,0,0),t}else if(e.data){let t=e.data.slice(0);for(let r=0;r<t.length;r++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[r]=Math.floor(es(t[r]/255)*255):t[r]=es(t[r]);return{data:t,width:e.width,height:e.height}}else return U("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}};var bE=0,to=class{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:bE++}),this.uuid=Ir(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){let t=this.data;return typeof HTMLVideoElement<"u"&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):typeof VideoFrame<"u"&&t instanceof VideoFrame?e.set(t.displayWidth,t.displayHeight,0):t!==null?e.set(t.width,t.height,t.depth||0):e.set(0,0,0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){let t=e===void 0||typeof e=="string";if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];let r={uuid:this.uuid,url:""},i=this.data;if(i!==null){let s;if(Array.isArray(i)){s=[];for(let o=0,a=i.length;o<a;o++)i[o].isDataTexture?s.push(Pg(i[o].image)):s.push(Pg(i[o]))}else s=Pg(i);r.url=s}return t||(e.images[this.uuid]=r),r}};function Pg(n){return typeof HTMLImageElement<"u"&&n instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&n instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&n instanceof ImageBitmap?eh.getDataURL(n):n.data?{data:Array.from(n.data),width:n.width,height:n.height,type:n.data.constructor.name}:(U("Texture: Unable to serialize Texture."),{})}var _E=0,Dg=new C,nt=class n extends bt{constructor(e=n.DEFAULT_IMAGE,t=n.DEFAULT_MAPPING,r=Dr,i=Dr,s=je,o=Ur,a=wt,l=it,u=n.DEFAULT_ANISOTROPY,c=Zr){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:_E++}),this.uuid=Ir(),this.name="",this.source=new to(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=r,this.wrapT=i,this.magFilter=s,this.minFilter=o,this.anisotropy=u,this.format=a,this.internalFormat=null,this.type=l,this.offset=new se(0,0),this.repeat=new se(1,1),this.center=new se(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new et,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=c,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(e&&e.depth&&e.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(Dg).x}get height(){return this.source.getSize(Dg).y}get depth(){return this.source.getSize(Dg).z}get image(){return this.source.data}set image(e){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)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}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.normalized=e.normalized,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.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(let t in e){let r=e[t];if(r===void 0){U(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}let i=this[t];if(i===void 0){U(`Texture.setValues(): property '${t}' does not exist.`);continue}i&&r&&i.isVector2&&r.isVector2||i&&r&&i.isVector3&&r.isVector3||i&&r&&i.isMatrix3&&r.isMatrix3?i.copy(r):this[t]=r}}toJSON(e){let t=e===void 0||typeof e=="string";if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];let r={metadata:{version:4.7,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,normalized:this.normalized,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&&(r.userData=this.userData),t||(e.textures[this.uuid]=r),r}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==Cu)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case gs:e.x=e.x-Math.floor(e.x);break;case Dr:e.x=e.x<0?0:1;break;case xs:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case gs:e.y=e.y-Math.floor(e.y);break;case Dr:e.y=e.y<0?0:1;break;case xs:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}};nt.DEFAULT_IMAGE=null;nt.DEFAULT_MAPPING=Cu;nt.DEFAULT_ANISOTROPY=1;var pe=class n{static{n.prototype.isVector4=!0}constructor(e=0,t=0,r=0,i=1){this.x=e,this.y=t,this.z=r,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,r,i){return this.x=e,this.y=t,this.z=r,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("THREE.Vector4: 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("THREE.Vector4: 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=e.w!==void 0?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){let t=this.x,r=this.y,i=this.z,s=this.w,o=e.elements;return this.x=o[0]*t+o[4]*r+o[8]*i+o[12]*s,this.y=o[1]*t+o[5]*r+o[9]*i+o[13]*s,this.z=o[2]*t+o[6]*r+o[10]*i+o[14]*s,this.w=o[3]*t+o[7]*r+o[11]*i+o[15]*s,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);let 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,r,i,s,l=e.elements,u=l[0],c=l[4],d=l[8],h=l[1],p=l[5],f=l[9],m=l[2],g=l[6],x=l[10];if(Math.abs(c-h)<.01&&Math.abs(d-m)<.01&&Math.abs(f-g)<.01){if(Math.abs(c+h)<.1&&Math.abs(d+m)<.1&&Math.abs(f+g)<.1&&Math.abs(u+p+x-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;let v=(u+1)/2,E=(p+1)/2,b=(x+1)/2,S=(c+h)/4,T=(d+m)/4,M=(f+g)/4;return v>E&&v>b?v<.01?(r=0,i=.707106781,s=.707106781):(r=Math.sqrt(v),i=S/r,s=T/r):E>b?E<.01?(r=.707106781,i=0,s=.707106781):(i=Math.sqrt(E),r=S/i,s=M/i):b<.01?(r=.707106781,i=.707106781,s=0):(s=Math.sqrt(b),r=T/s,i=M/s),this.set(r,i,s,t),this}let w=Math.sqrt((g-f)*(g-f)+(d-m)*(d-m)+(h-c)*(h-c));return Math.abs(w)<.001&&(w=1),this.x=(g-f)/w,this.y=(d-m)/w,this.z=(h-c)/w,this.w=Math.acos((u+p+x-1)/2),this}setFromMatrixPosition(e){let 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=Te(this.x,e.x,t.x),this.y=Te(this.y,e.y,t.y),this.z=Te(this.z,e.z,t.z),this.w=Te(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=Te(this.x,e,t),this.y=Te(this.y,e,t),this.z=Te(this.z,e,t),this.w=Te(this.w,e,t),this}clampLength(e,t){let r=this.length();return this.divideScalar(r||1).multiplyScalar(Te(r,e,t))}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,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this.z=e.z+(t.z-e.z)*r,this.w=e.w+(t.w-e.w)*r,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}};var ct=class extends bt{constructor(e=1,t=1,r={}){super(),r=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:je,depthBuffer:!0,stencilBuffer:!1,resolveColorBuffer:!0,resolveDepthBuffer:!0,resolveStencilBuffer:!0,storeMultisampledColorBuffer:!0,storeMultisampledDepthBuffer:!0,storeMultisampledStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1,useArrayDepthTexture:!1},r),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=r.depth,this.scissor=new pe(0,0,e,t),this.scissorTest=!1,this.viewport=new pe(0,0,e,t),this.textures=[];let i={width:e,height:t,depth:r.depth},s=new nt(i),o=r.count;for(let a=0;a<o;a++)this.textures[a]=s.clone(),this.textures[a].isRenderTargetTexture=!0,this.textures[a].renderTarget=this;this._setTextureOptions(r),this.depthBuffer=r.depthBuffer,this.stencilBuffer=r.stencilBuffer,this.resolveColorBuffer=r.resolveColorBuffer,this.resolveDepthBuffer=r.resolveDepthBuffer,this.resolveStencilBuffer=r.resolveStencilBuffer,this.storeMultisampledColorBuffer=r.storeMultisampledColorBuffer,this.storeMultisampledDepthBuffer=r.storeMultisampledDepthBuffer,this.storeMultisampledStencilBuffer=r.storeMultisampledStencilBuffer,this._depthTexture=null,this.depthTexture=r.depthTexture,this.samples=r.samples,this.multiview=r.multiview,this.useArrayDepthTexture=r.useArrayDepthTexture}_setTextureOptions(e={}){let t={minFilter:je,generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let r=0;r<this.textures.length;r++)this.textures[r].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&this._depthTexture.renderTarget===this&&(this._depthTexture.renderTarget=null),e!==null&&e.renderTarget===null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,r=1){if(this.width!==e||this.height!==t||this.depth!==r){this.width=e,this.height=t,this.depth=r;for(let i=0,s=this.textures.length;i<s;i++)this.textures[i].image.width=e,this.textures[i].image.height=t,this.textures[i].image.depth=r,this.textures[i].isData3DTexture!==!0&&(this.textures[i].isArrayTexture=this.textures[i].image.depth>1);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,r=e.textures.length;t<r;t++){this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0,this.textures[t].renderTarget=this;let i=Object.assign({},e.textures[t].image);this.textures[t].source=new to(i)}if(this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveColorBuffer=e.resolveColorBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,this.storeMultisampledColorBuffer=e.storeMultisampledColorBuffer,this.storeMultisampledDepthBuffer=e.storeMultisampledDepthBuffer,this.storeMultisampledStencilBuffer=e.storeMultisampledStencilBuffer,e.depthTexture!==null)if(e.depthTexture.renderTarget===e){let t=e.depthTexture.clone();t.renderTarget=null,this.depthTexture=t}else this.depthTexture=e.depthTexture;return this.samples=e.samples,this.multiview=e.multiview,this.useArrayDepthTexture=e.useArrayDepthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}};var Ta=class extends nt{constructor(e=null,t=1,r=1,i=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:r,depth:i},this.magFilter=Pe,this.minFilter=Pe,this.wrapR=Dr,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}};var ue=class n{static{n.prototype.isMatrix4=!0}constructor(e,t,r,i,s,o,a,l,u,c,d,h,p,f,m,g){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,r,i,s,o,a,l,u,c,d,h,p,f,m,g)}set(e,t,r,i,s,o,a,l,u,c,d,h,p,f,m,g){let x=this.elements;return x[0]=e,x[4]=t,x[8]=r,x[12]=i,x[1]=s,x[5]=o,x[9]=a,x[13]=l,x[2]=u,x[6]=c,x[10]=d,x[14]=h,x[3]=p,x[7]=f,x[11]=m,x[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 n().fromArray(this.elements)}copy(e){let t=this.elements,r=e.elements;return t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3],t[4]=r[4],t[5]=r[5],t[6]=r[6],t[7]=r[7],t[8]=r[8],t[9]=r[9],t[10]=r[10],t[11]=r[11],t[12]=r[12],t[13]=r[13],t[14]=r[14],t[15]=r[15],this}copyPosition(e){let t=this.elements,r=e.elements;return t[12]=r[12],t[13]=r[13],t[14]=r[14],this}setFromMatrix3(e){let 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,r){return this.determinantAffine()===0?(e.set(1,0,0),t.set(0,1,0),r.set(0,0,1),this):(e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),r.setFromMatrixColumn(this,2),this)}makeBasis(e,t,r){return this.set(e.x,t.x,r.x,0,e.y,t.y,r.y,0,e.z,t.z,r.z,0,0,0,0,1),this}extractRotation(e){if(e.determinantAffine()===0)return this.identity();let t=this.elements,r=e.elements,i=1/dl.setFromMatrixColumn(e,0).length(),s=1/dl.setFromMatrixColumn(e,1).length(),o=1/dl.setFromMatrixColumn(e,2).length();return t[0]=r[0]*i,t[1]=r[1]*i,t[2]=r[2]*i,t[3]=0,t[4]=r[4]*s,t[5]=r[5]*s,t[6]=r[6]*s,t[7]=0,t[8]=r[8]*o,t[9]=r[9]*o,t[10]=r[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){let t=this.elements,r=e.x,i=e.y,s=e.z,o=Math.cos(r),a=Math.sin(r),l=Math.cos(i),u=Math.sin(i),c=Math.cos(s),d=Math.sin(s);if(e.order==="XYZ"){let h=o*c,p=o*d,f=a*c,m=a*d;t[0]=l*c,t[4]=-l*d,t[8]=u,t[1]=p+f*u,t[5]=h-m*u,t[9]=-a*l,t[2]=m-h*u,t[6]=f+p*u,t[10]=o*l}else if(e.order==="YXZ"){let h=l*c,p=l*d,f=u*c,m=u*d;t[0]=h+m*a,t[4]=f*a-p,t[8]=o*u,t[1]=o*d,t[5]=o*c,t[9]=-a,t[2]=p*a-f,t[6]=m+h*a,t[10]=o*l}else if(e.order==="ZXY"){let h=l*c,p=l*d,f=u*c,m=u*d;t[0]=h-m*a,t[4]=-o*d,t[8]=f+p*a,t[1]=p+f*a,t[5]=o*c,t[9]=m-h*a,t[2]=-o*u,t[6]=a,t[10]=o*l}else if(e.order==="ZYX"){let h=o*c,p=o*d,f=a*c,m=a*d;t[0]=l*c,t[4]=f*u-p,t[8]=h*u+m,t[1]=l*d,t[5]=m*u+h,t[9]=p*u-f,t[2]=-u,t[6]=a*l,t[10]=o*l}else if(e.order==="YZX"){let h=o*l,p=o*u,f=a*l,m=a*u;t[0]=l*c,t[4]=m-h*d,t[8]=f*d+p,t[1]=d,t[5]=o*c,t[9]=-a*c,t[2]=-u*c,t[6]=p*d+f,t[10]=h-m*d}else if(e.order==="XZY"){let h=o*l,p=o*u,f=a*l,m=a*u;t[0]=l*c,t[4]=-d,t[8]=u*c,t[1]=h*d+m,t[5]=o*c,t[9]=p*d-f,t[2]=f*d-p,t[6]=a*c,t[10]=m*d+h}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(TE,e,SE)}lookAt(e,t,r){let i=this.elements;return di.subVectors(e,t),di.lengthSq()===0&&(di.z=1),di.normalize(),ro.crossVectors(r,di),ro.lengthSq()===0&&(Math.abs(r.z)===1?di.x+=1e-4:di.z+=1e-4,di.normalize(),ro.crossVectors(r,di)),ro.normalize(),th.crossVectors(di,ro),i[0]=ro.x,i[4]=th.x,i[8]=di.x,i[1]=ro.y,i[5]=th.y,i[9]=di.y,i[2]=ro.z,i[6]=th.z,i[10]=di.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let r=e.elements,i=t.elements,s=this.elements,o=r[0],a=r[4],l=r[8],u=r[12],c=r[1],d=r[5],h=r[9],p=r[13],f=r[2],m=r[6],g=r[10],x=r[14],w=r[3],v=r[7],E=r[11],b=r[15],S=i[0],T=i[4],M=i[8],B=i[12],D=i[1],O=i[5],z=i[9],Q=i[13],oe=i[2],H=i[6],ae=i[10],de=i[14],me=i[3],Ae=i[7],ge=i[11],Oe=i[15];return s[0]=o*S+a*D+l*oe+u*me,s[4]=o*T+a*O+l*H+u*Ae,s[8]=o*M+a*z+l*ae+u*ge,s[12]=o*B+a*Q+l*de+u*Oe,s[1]=c*S+d*D+h*oe+p*me,s[5]=c*T+d*O+h*H+p*Ae,s[9]=c*M+d*z+h*ae+p*ge,s[13]=c*B+d*Q+h*de+p*Oe,s[2]=f*S+m*D+g*oe+x*me,s[6]=f*T+m*O+g*H+x*Ae,s[10]=f*M+m*z+g*ae+x*ge,s[14]=f*B+m*Q+g*de+x*Oe,s[3]=w*S+v*D+E*oe+b*me,s[7]=w*T+v*O+E*H+b*Ae,s[11]=w*M+v*z+E*ae+b*ge,s[15]=w*B+v*Q+E*de+b*Oe,this}multiplyScalar(e){let 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(){let e=this.elements,t=e[0],r=e[4],i=e[8],s=e[12],o=e[1],a=e[5],l=e[9],u=e[13],c=e[2],d=e[6],h=e[10],p=e[14],f=e[3],m=e[7],g=e[11],x=e[15],w=l*p-u*h,v=a*p-u*d,E=a*h-l*d,b=o*p-u*c,S=o*h-l*c,T=o*d-a*c;return t*(m*w-g*v+x*E)-r*(f*w-g*b+x*S)+i*(f*v-m*b+x*T)-s*(f*E-m*S+g*T)}determinantAffine(){let e=this.elements,t=e[0],r=e[4],i=e[8],s=e[1],o=e[5],a=e[9],l=e[2],u=e[6],c=e[10];return t*(o*c-a*u)-r*(s*c-a*l)+i*(s*u-o*l)}transpose(){let e=this.elements,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,r){let 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]=r),this}invert(){let e=this.elements,t=e[0],r=e[1],i=e[2],s=e[3],o=e[4],a=e[5],l=e[6],u=e[7],c=e[8],d=e[9],h=e[10],p=e[11],f=e[12],m=e[13],g=e[14],x=e[15],w=t*a-r*o,v=t*l-i*o,E=t*u-s*o,b=r*l-i*a,S=r*u-s*a,T=i*u-s*l,M=c*m-d*f,B=c*g-h*f,D=c*x-p*f,O=d*g-h*m,z=d*x-p*m,Q=h*x-p*g,oe=w*Q-v*z+E*O+b*D-S*B+T*M;if(oe===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);let H=1/oe;return e[0]=(a*Q-l*z+u*O)*H,e[1]=(i*z-r*Q-s*O)*H,e[2]=(m*T-g*S+x*b)*H,e[3]=(h*S-d*T-p*b)*H,e[4]=(l*D-o*Q-u*B)*H,e[5]=(t*Q-i*D+s*B)*H,e[6]=(g*E-f*T-x*v)*H,e[7]=(c*T-h*E+p*v)*H,e[8]=(o*z-a*D+u*M)*H,e[9]=(r*D-t*z-s*M)*H,e[10]=(f*S-m*E+x*w)*H,e[11]=(d*E-c*S-p*w)*H,e[12]=(a*B-o*O-l*M)*H,e[13]=(t*O-r*B+i*M)*H,e[14]=(m*v-f*b-g*w)*H,e[15]=(c*b-d*v+h*w)*H,this}scale(e){let t=this.elements,r=e.x,i=e.y,s=e.z;return t[0]*=r,t[4]*=i,t[8]*=s,t[1]*=r,t[5]*=i,t[9]*=s,t[2]*=r,t[6]*=i,t[10]*=s,t[3]*=r,t[7]*=i,t[11]*=s,this}getMaxScaleOnAxis(){let e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],r=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,r,i))}makeTranslation(e,t,r){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,r,0,0,0,1),this}makeRotationX(e){let t=Math.cos(e),r=Math.sin(e);return this.set(1,0,0,0,0,t,-r,0,0,r,t,0,0,0,0,1),this}makeRotationY(e){let t=Math.cos(e),r=Math.sin(e);return this.set(t,0,r,0,0,1,0,0,-r,0,t,0,0,0,0,1),this}makeRotationZ(e){let t=Math.cos(e),r=Math.sin(e);return this.set(t,-r,0,0,r,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){let r=Math.cos(t),i=Math.sin(t),s=1-r,o=e.x,a=e.y,l=e.z,u=s*o,c=s*a;return this.set(u*o+r,u*a-i*l,u*l+i*a,0,u*a+i*l,c*a+r,c*l-i*o,0,u*l-i*a,c*l+i*o,s*l*l+r,0,0,0,0,1),this}makeScale(e,t,r){return this.set(e,0,0,0,0,t,0,0,0,0,r,0,0,0,0,1),this}makeShear(e,t,r,i,s,o){return this.set(1,r,s,0,e,1,o,0,t,i,1,0,0,0,0,1),this}compose(e,t,r){let i=this.elements,s=t._x,o=t._y,a=t._z,l=t._w,u=s+s,c=o+o,d=a+a,h=s*u,p=s*c,f=s*d,m=o*c,g=o*d,x=a*d,w=l*u,v=l*c,E=l*d,b=r.x,S=r.y,T=r.z;return i[0]=(1-(m+x))*b,i[1]=(p+E)*b,i[2]=(f-v)*b,i[3]=0,i[4]=(p-E)*S,i[5]=(1-(h+x))*S,i[6]=(g+w)*S,i[7]=0,i[8]=(f+v)*T,i[9]=(g-w)*T,i[10]=(1-(h+m))*T,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,r){let i=this.elements;e.x=i[12],e.y=i[13],e.z=i[14];let s=this.determinantAffine();if(s===0)return r.set(1,1,1),t.identity(),this;let o=dl.set(i[0],i[1],i[2]).length(),a=dl.set(i[4],i[5],i[6]).length(),l=dl.set(i[8],i[9],i[10]).length();s<0&&(o=-o),ts.copy(this);let u=1/o,c=1/a,d=1/l;return ts.elements[0]*=u,ts.elements[1]*=u,ts.elements[2]*=u,ts.elements[4]*=c,ts.elements[5]*=c,ts.elements[6]*=c,ts.elements[8]*=d,ts.elements[9]*=d,ts.elements[10]*=d,t.setFromRotationMatrix(ts),r.x=o,r.y=a,r.z=l,this}makePerspective(e,t,r,i,s,o,a=At,l=!1){let u=this.elements,c=2*s/(t-e),d=2*s/(r-i),h=(t+e)/(t-e),p=(r+i)/(r-i),f,m;if(l)f=s/(o-s),m=o*s/(o-s);else if(a===At)f=-(o+s)/(o-s),m=-2*o*s/(o-s);else if(a===yt)f=-o/(o-s),m=-o*s/(o-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return u[0]=c,u[4]=0,u[8]=h,u[12]=0,u[1]=0,u[5]=d,u[9]=p,u[13]=0,u[2]=0,u[6]=0,u[10]=f,u[14]=m,u[3]=0,u[7]=0,u[11]=-1,u[15]=0,this}makeOrthographic(e,t,r,i,s,o,a=At,l=!1){let u=this.elements,c=2/(t-e),d=2/(r-i),h=-(t+e)/(t-e),p=-(r+i)/(r-i),f,m;if(l)f=1/(o-s),m=o/(o-s);else if(a===At)f=-2/(o-s),m=-(o+s)/(o-s);else if(a===yt)f=-1/(o-s),m=-s/(o-s);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return u[0]=c,u[4]=0,u[8]=0,u[12]=h,u[1]=0,u[5]=d,u[9]=0,u[13]=p,u[2]=0,u[6]=0,u[10]=f,u[14]=m,u[3]=0,u[7]=0,u[11]=0,u[15]=1,this}equals(e){let t=this.elements,r=e.elements;for(let i=0;i<16;i++)if(t[i]!==r[i])return!1;return!0}fromArray(e,t=0){for(let r=0;r<16;r++)this.elements[r]=e[r+t];return this}toArray(e=[],t=0){let r=this.elements;return e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+3]=r[3],e[t+4]=r[4],e[t+5]=r[5],e[t+6]=r[6],e[t+7]=r[7],e[t+8]=r[8],e[t+9]=r[9],e[t+10]=r[10],e[t+11]=r[11],e[t+12]=r[12],e[t+13]=r[13],e[t+14]=r[14],e[t+15]=r[15],e}},dl=new C,ts=new ue,TE=new C(0,0,0),SE=new C(1,1,1),ro=new C,th=new C,di=new C;var Bw=new ue,Fw=new Jr,br=class n{constructor(e=0,t=0,r=0,i=n.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=r,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,r,i=this._order){return this._x=e,this._y=t,this._z=r,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,r=!0){let i=e.elements,s=i[0],o=i[4],a=i[8],l=i[1],u=i[5],c=i[9],d=i[2],h=i[6],p=i[10];switch(t){case"XYZ":this._y=Math.asin(Te(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-c,p),this._z=Math.atan2(-o,s)):(this._x=Math.atan2(h,u),this._z=0);break;case"YXZ":this._x=Math.asin(-Te(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(a,p),this._z=Math.atan2(l,u)):(this._y=Math.atan2(-d,s),this._z=0);break;case"ZXY":this._x=Math.asin(Te(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(-d,p),this._z=Math.atan2(-o,u)):(this._y=0,this._z=Math.atan2(l,s));break;case"ZYX":this._y=Math.asin(-Te(d,-1,1)),Math.abs(d)<.9999999?(this._x=Math.atan2(h,p),this._z=Math.atan2(l,s)):(this._x=0,this._z=Math.atan2(-o,u));break;case"YZX":this._z=Math.asin(Te(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-c,u),this._y=Math.atan2(-d,s)):(this._x=0,this._y=Math.atan2(a,p));break;case"XZY":this._z=Math.asin(-Te(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(h,u),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-c,p),this._y=0);break;default:U("Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,r===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,r){return Bw.makeRotationFromQuaternion(e),this.setFromRotationMatrix(Bw,t,r)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return Fw.setFromEuler(this),this.setFromQuaternion(Fw,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],e[3]!==void 0&&(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}};br.DEFAULT_ORDER="XYZ";var rh=class{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!==0}};var NE=0,Lw=new C,hl=new Jr,dn=new ue,ih=new C,ku=new C,wE=new C,ME=new Jr,Pw=new C(1,0,0),Dw=new C(0,1,0),Uw=new C(0,0,1),Iw={type:"added"},vE={type:"removed"},pl={type:"childadded",child:null},Ug={type:"childremoved",child:null},Ke=class n extends bt{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:NE++}),this.uuid=Ir(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=n.DEFAULT_UP.clone();let e=new C,t=new br,r=new Jr,i=new C(1,1,1);function s(){r.setFromEuler(t,!1)}function o(){t.setFromQuaternion(r,void 0,!1)}t._onChange(s),r._onChange(o),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:r},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new ue},normalMatrix:{value:new et}}),this.matrix=new ue,this.matrixWorld=new ue,this.matrixAutoUpdate=n.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=n.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new rh,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}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 hl.setFromAxisAngle(e,t),this.quaternion.multiply(hl),this}rotateOnWorldAxis(e,t){return hl.setFromAxisAngle(e,t),this.quaternion.premultiply(hl),this}rotateX(e){return this.rotateOnAxis(Pw,e)}rotateY(e){return this.rotateOnAxis(Dw,e)}rotateZ(e){return this.rotateOnAxis(Uw,e)}translateOnAxis(e,t){return Lw.copy(e).applyQuaternion(this.quaternion),this.position.add(Lw.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(Pw,e)}translateY(e){return this.translateOnAxis(Dw,e)}translateZ(e){return this.translateOnAxis(Uw,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(dn.copy(this.matrixWorld).invert())}lookAt(e,t,r){e.isVector3?ih.copy(e):ih.set(e,t,r);let i=this.parent;this.updateWorldMatrix(!0,!1),ku.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?dn.lookAt(ku,ih,this.up):dn.lookAt(ih,ku,this.up),this.quaternion.setFromRotationMatrix(dn),i&&(dn.extractRotation(i.matrixWorld),hl.setFromRotationMatrix(dn),this.quaternion.premultiply(hl.invert()))}add(e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return e===this?(I("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(Iw),pl.child=e,this.dispatchEvent(pl),pl.child=null):I("Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let r=0;r<arguments.length;r++)this.remove(arguments[r]);return this}let t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(vE),Ug.child=e,this.dispatchEvent(Ug),Ug.child=null),this}removeFromParent(){let e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),dn.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),dn.multiply(e.parent.matrixWorld)),e.applyMatrix4(dn),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(Iw),pl.child=e,this.dispatchEvent(pl),pl.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 r=0,i=this.children.length;r<i;r++){let o=this.children[r].getObjectByProperty(e,t);if(o!==void 0)return o}}getObjectsByProperty(e,t,r=[]){this[e]===t&&r.push(this);let i=this.children;for(let s=0,o=i.length;s<o;s++)i[s].getObjectsByProperty(e,t,r);return r}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ku,e,wE),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ku,ME,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);let t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);let t=this.children;for(let r=0,i=t.length;r<i;r++)t[r].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);let t=this.children;for(let r=0,i=t.length;r<i;r++)t[r].traverseVisible(e)}traverseAncestors(e){let t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);let e=this.pivot;if(e!==null){let t=e.x,r=e.y,i=e.z,s=this.matrix.elements;s[12]+=t-s[0]*t-s[4]*r-s[8]*i,s[13]+=r-s[1]*t-s[5]*r-s[9]*i,s[14]+=i-s[2]*t-s[6]*r-s[10]*i}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);let t=this.children;for(let r=0,i=t.length;r<i;r++)t[r].updateMatrixWorld(e)}updateWorldMatrix(e,t,r=!1){let i=this.parent;if(e===!0&&i!==null&&i.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||r)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,r=!0),t===!0){let s=this.children;for(let o=0,a=s.length;o<a;o++)s[o].updateWorldMatrix(!1,!0,r)}}toJSON(e){let t=e===void 0||typeof e=="string",r={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},r.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});let i={};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.castShadow===!0&&(i.castShadow=!0),this.receiveShadow===!0&&(i.receiveShadow=!0),this.visible===!1&&(i.visible=!1),this.frustumCulled===!1&&(i.frustumCulled=!1),this.renderOrder!==0&&(i.renderOrder=this.renderOrder),this.static!==!1&&(i.static=this.static),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(),this.pivot!==null&&(i.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(i.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(i.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(i.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(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.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(a=>({...a})),i.availableInstanceIds=this._availableInstanceIds.slice(),i.availableGeometryIds=this._availableGeometryIds.slice(),i.nextIndexStart=this._nextIndexStart,i.nextVertexStart=this._nextVertexStart,i.geometryCount=this._geometryCount,i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.matricesTexture=this._matricesTexture.toJSON(e),i.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(i.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(i.boundingBox=this.boundingBox.toJSON()));function s(a,l){return a[l.uuid]===void 0&&(a[l.uuid]=l.toJSON(e)),l.uuid}if(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&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=s(e.geometries,this.geometry);let a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){let l=a.shapes;if(Array.isArray(l))for(let u=0,c=l.length;u<c;u++){let d=l[u];s(e.shapes,d)}else s(e.shapes,l)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(e.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){let a=[];for(let l=0,u=this.material.length;l<u;l++)a.push(s(e.materials,this.material[l]));i.material=a}else i.material=s(e.materials,this.material);if(this.children.length>0){i.children=[];for(let a=0;a<this.children.length;a++)i.children.push(this.children[a].toJSON(e).object)}if(this.animations.length>0){i.animations=[];for(let a=0;a<this.animations.length;a++){let l=this.animations[a];i.animations.push(s(e.animations,l))}}if(t){let a=o(e.geometries),l=o(e.materials),u=o(e.textures),c=o(e.images),d=o(e.shapes),h=o(e.skeletons),p=o(e.animations),f=o(e.nodes);a.length>0&&(r.geometries=a),l.length>0&&(r.materials=l),u.length>0&&(r.textures=u),c.length>0&&(r.images=c),d.length>0&&(r.shapes=d),h.length>0&&(r.skeletons=h),p.length>0&&(r.animations=p),f.length>0&&(r.nodes=f)}return r.object=i,r;function o(a){let l=[];for(let u in a){let c=a[u];delete c.metadata,l.push(c)}return l}}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.pivot=e.pivot!==null?e.pivot.clone():null,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.static=e.static,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let r=0;r<e.children.length;r++){let i=e.children[r];this.add(i.clone())}return this}};Ke.DEFAULT_UP=new C(0,1,0);Ke.DEFAULT_MATRIX_AUTO_UPDATE=!0;Ke.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;var Sa=class extends Ke{constructor(){super(),this.isGroup=!0,this.type="Group"}};var AE={type:"move"},sh=class{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Sa,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new Sa,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new C,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new C),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new Sa,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new C,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new C,this._grip.eventsEnabled=!1),this._grip}dispatchEvent(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){let t=this._hand;if(t)for(let r of e.hand.values())this._getHandJoint(t,r)}return this.dispatchEvent({type:"connected",data:e}),this}disconnect(e){return this.dispatchEvent({type:"disconnected",data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,r){let i=null,s=null,o=null,a=this._targetRay,l=this._grip,u=this._hand;if(e&&t.session.visibilityState!=="visible-blurred"){if(u&&e.hand){o=!0;for(let m of e.hand.values()){let g=t.getJointPose(m,r),x=this._getHandJoint(u,m);g!==null&&(x.matrix.fromArray(g.transform.matrix),x.matrix.decompose(x.position,x.rotation,x.scale),x.matrixWorldNeedsUpdate=!0,x.jointRadius=g.radius),x.visible=g!==null}let c=u.joints["index-finger-tip"],d=u.joints["thumb-tip"],h=c.position.distanceTo(d.position),p=.02,f=.005;u.inputState.pinching&&h>p+f?(u.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!u.inputState.pinching&&h<=p-f&&(u.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else l!==null&&e.gripSpace&&(s=t.getPose(e.gripSpace,r),s!==null&&(l.matrix.fromArray(s.transform.matrix),l.matrix.decompose(l.position,l.rotation,l.scale),l.matrixWorldNeedsUpdate=!0,s.linearVelocity?(l.hasLinearVelocity=!0,l.linearVelocity.copy(s.linearVelocity)):l.hasLinearVelocity=!1,s.angularVelocity?(l.hasAngularVelocity=!0,l.angularVelocity.copy(s.angularVelocity)):l.hasAngularVelocity=!1,l.eventsEnabled&&l.dispatchEvent({type:"gripUpdated",data:e,target:this})));a!==null&&(i=t.getPose(e.targetRaySpace,r),i===null&&s!==null&&(i=s),i!==null&&(a.matrix.fromArray(i.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,i.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(i.linearVelocity)):a.hasLinearVelocity=!1,i.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(i.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(AE)))}return a!==null&&(a.visible=i!==null),l!==null&&(l.visible=s!==null),u!==null&&(u.visible=o!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){let r=new Sa;r.matrixAutoUpdate=!1,r.visible=!1,e.joints[t.jointName]=r,e.add(r)}return e.joints[t.jointName]}};var Ow={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},io={h:0,s:0,l:0},nh={h:0,s:0,l:0};function Ig(n,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?n+(e-n)*6*t:t<1/2?e:t<2/3?n+(e-n)*6*(2/3-t):n}var le=class{constructor(e,t,r){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,r)}set(e,t,r){if(t===void 0&&r===void 0){let i=e;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(e,t,r);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=tr){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Me.colorSpaceToWorking(this,t),this}setRGB(e,t,r,i=Me.workingColorSpace){return this.r=e,this.g=t,this.b=r,Me.colorSpaceToWorking(this,i),this}setHSL(e,t,r,i=Me.workingColorSpace){if(e=Zd(e,1),t=Te(t,0,1),r=Te(r,0,1),t===0)this.r=this.g=this.b=r;else{let s=r<=.5?r*(1+t):r+t-r*t,o=2*r-s;this.r=Ig(o,s,e+1/3),this.g=Ig(o,s,e),this.b=Ig(o,s,e-1/3)}return Me.colorSpaceToWorking(this,i),this}setStyle(e,t=tr){function r(s){s!==void 0&&parseFloat(s)<1&&U("Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(e)){let s,o=i[1],a=i[2];switch(o){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return r(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,t);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return r(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,t);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return r(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,t);break;default:U("Color: Unknown color model "+e)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(e)){let s=i[1],o=s.length;if(o===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,t);if(o===6)return this.setHex(parseInt(s,16),t);U("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=tr){let r=Ow[e.toLowerCase()];return r!==void 0?this.setHex(r,t):U("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=es(e.r),this.g=es(e.g),this.b=es(e.b),this}copyLinearToSRGB(e){return this.r=_a(e.r),this.g=_a(e.g),this.b=_a(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=tr){return Me.workingToColorSpace(_r.copy(this),e),Math.round(Te(_r.r*255,0,255))*65536+Math.round(Te(_r.g*255,0,255))*256+Math.round(Te(_r.b*255,0,255))}getHexString(e=tr){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=Me.workingColorSpace){Me.workingToColorSpace(_r.copy(this),t);let r=_r.r,i=_r.g,s=_r.b,o=Math.max(r,i,s),a=Math.min(r,i,s),l,u,c=(a+o)/2;if(a===o)l=0,u=0;else{let d=o-a;switch(u=c<=.5?d/(o+a):d/(2-o-a),o){case r:l=(i-s)/d+(i<s?6:0);break;case i:l=(s-r)/d+2;break;case s:l=(r-i)/d+4;break}l/=6}return e.h=l,e.s=u,e.l=c,e}getRGB(e,t=Me.workingColorSpace){return Me.workingToColorSpace(_r.copy(this),t),e.r=_r.r,e.g=_r.g,e.b=_r.b,e}getStyle(e=tr){Me.workingToColorSpace(_r.copy(this),e);let t=_r.r,r=_r.g,i=_r.b;return e!==tr?`color(${e} ${t.toFixed(3)} ${r.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(t*255)},${Math.round(r*255)},${Math.round(i*255)})`}offsetHSL(e,t,r){return this.getHSL(io),this.setHSL(io.h+e,io.s+t,io.l+r)}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,r){return this.r=e.r+(t.r-e.r)*r,this.g=e.g+(t.g-e.g)*r,this.b=e.b+(t.b-e.b)*r,this}lerpHSL(e,t){this.getHSL(io),e.getHSL(nh);let r=ul(io.h,nh.h,t),i=ul(io.s,nh.s,t),s=ul(io.l,nh.l,t);return this.setHSL(r,i,s),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){let t=this.r,r=this.g,i=this.b,s=e.elements;return this.r=s[0]*t+s[3]*r+s[6]*i,this.g=s[1]*t+s[4]*r+s[7]*i,this.b=s[2]*t+s[5]*r+s[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}},_r=new le;le.NAMES=Ow;var so=class extends Ke{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 br,this.environmentIntensity=1,this.environmentRotation=new br,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(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),e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){let t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}};var rs=new C,hn=new C,Og=new C,pn=new C,fl=new C,ml=new C,kw=new C,kg=new C,Vg=new C,Gg=new C,zg=new pe,$g=new pe,Wg=new pe,no=class n{constructor(e=new C,t=new C,r=new C){this.a=e,this.b=t,this.c=r}static getNormal(e,t,r,i){i.subVectors(r,t),rs.subVectors(e,t),i.cross(rs);let s=i.lengthSq();return s>0?i.multiplyScalar(1/Math.sqrt(s)):i.set(0,0,0)}static getBarycoord(e,t,r,i,s){rs.subVectors(i,t),hn.subVectors(r,t),Og.subVectors(e,t);let o=rs.dot(rs),a=rs.dot(hn),l=rs.dot(Og),u=hn.dot(hn),c=hn.dot(Og),d=o*u-a*a;if(d===0)return s.set(0,0,0),null;let h=1/d,p=(u*l-a*c)*h,f=(o*c-a*l)*h;return s.set(1-p-f,f,p)}static containsPoint(e,t,r,i){return this.getBarycoord(e,t,r,i,pn)===null?!1:pn.x>=0&&pn.y>=0&&pn.x+pn.y<=1}static getInterpolation(e,t,r,i,s,o,a,l){return this.getBarycoord(e,t,r,i,pn)===null?(l.x=0,l.y=0,"z"in l&&(l.z=0),"w"in l&&(l.w=0),null):(l.setScalar(0),l.addScaledVector(s,pn.x),l.addScaledVector(o,pn.y),l.addScaledVector(a,pn.z),l)}static getInterpolatedAttribute(e,t,r,i,s,o){return zg.setScalar(0),$g.setScalar(0),Wg.setScalar(0),zg.fromBufferAttribute(e,t),$g.fromBufferAttribute(e,r),Wg.fromBufferAttribute(e,i),o.setScalar(0),o.addScaledVector(zg,s.x),o.addScaledVector($g,s.y),o.addScaledVector(Wg,s.z),o}static isFrontFacing(e,t,r,i){return rs.subVectors(r,t),hn.subVectors(e,t),rs.cross(hn).dot(i)<0}set(e,t,r){return this.a.copy(e),this.b.copy(t),this.c.copy(r),this}setFromPointsAndIndices(e,t,r,i){return this.a.copy(e[t]),this.b.copy(e[r]),this.c.copy(e[i]),this}setFromAttributeAndIndices(e,t,r,i){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,r),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 rs.subVectors(this.c,this.b),hn.subVectors(this.a,this.b),rs.cross(hn).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return n.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return n.getBarycoord(e,this.a,this.b,this.c,t)}getInterpolation(e,t,r,i,s){return n.getInterpolation(e,this.a,this.b,this.c,t,r,i,s)}containsPoint(e){return n.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return n.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){let r=this.a,i=this.b,s=this.c,o,a;fl.subVectors(i,r),ml.subVectors(s,r),kg.subVectors(e,r);let l=fl.dot(kg),u=ml.dot(kg);if(l<=0&&u<=0)return t.copy(r);Vg.subVectors(e,i);let c=fl.dot(Vg),d=ml.dot(Vg);if(c>=0&&d<=c)return t.copy(i);let h=l*d-c*u;if(h<=0&&l>=0&&c<=0)return o=l/(l-c),t.copy(r).addScaledVector(fl,o);Gg.subVectors(e,s);let p=fl.dot(Gg),f=ml.dot(Gg);if(f>=0&&p<=f)return t.copy(s);let m=p*u-l*f;if(m<=0&&u>=0&&f<=0)return a=u/(u-f),t.copy(r).addScaledVector(ml,a);let g=c*f-p*d;if(g<=0&&d-c>=0&&p-f>=0)return kw.subVectors(s,i),a=(d-c)/(d-c+(p-f)),t.copy(i).addScaledVector(kw,a);let x=1/(g+m+h);return o=m*x,a=h*x,t.copy(r).addScaledVector(fl,o).addScaledVector(ml,a)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}};var mn=class{constructor(e=new C(1/0,1/0,1/0),t=new C(-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,r=e.length;t<r;t+=3)this.expandByPoint(is.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,r=e.count;t<r;t++)this.expandByPoint(is.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,r=e.length;t<r;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){let r=is.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(r),this.max.copy(e).add(r),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);let r=e.geometry;if(r!==void 0){let s=r.getAttribute("position");if(t===!0&&s!==void 0&&e.isInstancedMesh!==!0)for(let o=0,a=s.count;o<a;o++)e.isMesh===!0?e.getVertexPosition(o,is):is.fromBufferAttribute(s,o),is.applyMatrix4(e.matrixWorld),this.expandByPoint(is);else e.boundingBox!==void 0?(e.boundingBox===null&&e.computeBoundingBox(),oh.copy(e.boundingBox)):(r.boundingBox===null&&r.computeBoundingBox(),oh.copy(r.boundingBox)),oh.applyMatrix4(e.matrixWorld),this.union(oh)}let i=e.children;for(let s=0,o=i.length;s<o;s++)this.expandByObject(i[s],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,is),is.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,r;return e.normal.x>0?(t=e.normal.x*this.min.x,r=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,r=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,r+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,r+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,r+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,r+=e.normal.z*this.min.z),t<=-e.constant&&r>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(Vu),ah.subVectors(this.max,Vu),gl.subVectors(e.a,Vu),xl.subVectors(e.b,Vu),yl.subVectors(e.c,Vu),oo.subVectors(xl,gl),ao.subVectors(yl,xl),Na.subVectors(gl,yl);let t=[0,-oo.z,oo.y,0,-ao.z,ao.y,0,-Na.z,Na.y,oo.z,0,-oo.x,ao.z,0,-ao.x,Na.z,0,-Na.x,-oo.y,oo.x,0,-ao.y,ao.x,0,-Na.y,Na.x,0];return!Hg(t,gl,xl,yl,ah)||(t=[1,0,0,0,1,0,0,0,1],!Hg(t,gl,xl,yl,ah))?!1:(lh.crossVectors(oo,ao),t=[lh.x,lh.y,lh.z],Hg(t,gl,xl,yl,ah))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,is).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(is).length()*.5),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()?this:(fn[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),fn[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),fn[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),fn[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),fn[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),fn[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),fn[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),fn[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(fn),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)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}},fn=[new C,new C,new C,new C,new C,new C,new C,new C],is=new C,oh=new mn,gl=new C,xl=new C,yl=new C,oo=new C,ao=new C,Na=new C,Vu=new C,ah=new C,lh=new C,wa=new C;function Hg(n,e,t,r,i){for(let s=0,o=n.length-3;s<=o;s+=3){wa.fromArray(n,s);let a=i.x*Math.abs(wa.x)+i.y*Math.abs(wa.y)+i.z*Math.abs(wa.z),l=e.dot(wa),u=t.dot(wa),c=r.dot(wa);if(Math.max(-Math.max(l,u,c),Math.min(l,u,c))>a)return!1}return!0}var gn=RE();function RE(){let n=new ArrayBuffer(4),e=new Float32Array(n),t=new Uint32Array(n),r=new Uint32Array(512),i=new Uint32Array(512);for(let l=0;l<256;++l){let u=l-127;u<-27?(r[l]=0,r[l|256]=32768,i[l]=24,i[l|256]=24):u<-14?(r[l]=1024>>-u-14,r[l|256]=1024>>-u-14|32768,i[l]=-u-1,i[l|256]=-u-1):u<=15?(r[l]=u+15<<10,r[l|256]=u+15<<10|32768,i[l]=13,i[l|256]=13):u<128?(r[l]=31744,r[l|256]=64512,i[l]=24,i[l|256]=24):(r[l]=31744,r[l|256]=64512,i[l]=13,i[l|256]=13)}let s=new Uint32Array(2048),o=new Uint32Array(64),a=new Uint32Array(64);for(let l=1;l<1024;++l){let u=l<<13,c=0;for(;(u&8388608)===0;)u<<=1,c-=8388608;u&=-8388609,c+=947912704,s[l]=u|c}for(let l=1024;l<2048;++l)s[l]=939524096+(l-1024<<13);for(let l=1;l<31;++l)o[l]=l<<23;o[31]=1199570944,o[32]=2147483648;for(let l=33;l<63;++l)o[l]=2147483648+(l-32<<23);o[63]=3347054592;for(let l=1;l<64;++l)l!==32&&(a[l]=1024);return{floatView:e,uint32View:t,baseTable:r,shiftTable:i,mantissaTable:s,exponentTable:o,offsetTable:a}}function ei(n){Math.abs(n)>65504&&U("DataUtils.toHalfFloat(): Value out of range."),n=Te(n,-65504,65504),gn.floatView[0]=n;let e=gn.uint32View[0],t=e>>23&511;return gn.baseTable[t]+((e&8388607)>>gn.shiftTable[t])}function Gu(n){let e=n>>10;return gn.uint32View[0]=gn.mantissaTable[gn.offsetTable[e]+(n&1023)]+gn.exponentTable[e],gn.floatView[0]}var Ut=new C,uh=new se,CE=0,$t=class extends bt{constructor(e,t,r=!1){if(super(),Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:CE++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=r,this.usage=ys,this.updateRanges=[],this.gpuType=ze,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&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,r){e*=this.itemSize,r*=t.itemSize;for(let i=0,s=this.itemSize;i<s;i++)this.array[e+i]=t.array[r+i];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,r=this.count;t<r;t++)uh.fromBufferAttribute(this,t),uh.applyMatrix3(e),this.setXY(t,uh.x,uh.y);else if(this.itemSize===3)for(let t=0,r=this.count;t<r;t++)Ut.fromBufferAttribute(this,t),Ut.applyMatrix3(e),this.setXYZ(t,Ut.x,Ut.y,Ut.z);return this}applyMatrix4(e){for(let t=0,r=this.count;t<r;t++)Ut.fromBufferAttribute(this,t),Ut.applyMatrix4(e),this.setXYZ(t,Ut.x,Ut.y,Ut.z);return this}applyNormalMatrix(e){for(let t=0,r=this.count;t<r;t++)Ut.fromBufferAttribute(this,t),Ut.applyNormalMatrix(e),this.setXYZ(t,Ut.x,Ut.y,Ut.z);return this}transformDirection(e){for(let t=0,r=this.count;t<r;t++)Ut.fromBufferAttribute(this,t),Ut.transformDirection(e),this.setXYZ(t,Ut.x,Ut.y,Ut.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let r=this.array[e*this.itemSize+t];return this.normalized&&(r=rr(r,this.array)),r}setComponent(e,t,r){return this.normalized&&(r=Ne(r,this.array)),this.array[e*this.itemSize+t]=r,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=rr(t,this.array)),t}setX(e,t){return this.normalized&&(t=Ne(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=rr(t,this.array)),t}setY(e,t){return this.normalized&&(t=Ne(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=rr(t,this.array)),t}setZ(e,t){return this.normalized&&(t=Ne(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=rr(t,this.array)),t}setW(e,t){return this.normalized&&(t=Ne(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,r){return e*=this.itemSize,this.normalized&&(t=Ne(t,this.array),r=Ne(r,this.array)),this.array[e+0]=t,this.array[e+1]=r,this}setXYZ(e,t,r,i){return e*=this.itemSize,this.normalized&&(t=Ne(t,this.array),r=Ne(r,this.array),i=Ne(i,this.array)),this.array[e+0]=t,this.array[e+1]=r,this.array[e+2]=i,this}setXYZW(e,t,r,i,s){return e*=this.itemSize,this.normalized&&(t=Ne(t,this.array),r=Ne(r,this.array),i=Ne(i,this.array),s=Ne(s,this.array)),this.array[e+0]=t,this.array[e+1]=r,this.array[e+2]=i,this.array[e+3]=s,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){let 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!==ys&&(e.usage=this.usage),this.gpuType!==ze&&(e.gpuType=this.gpuType),e}dispose(){this.dispatchEvent({type:"dispose"})}};var bl=class extends $t{constructor(e,t,r){super(new Uint16Array(e),t,r)}};var _l=class extends $t{constructor(e,t,r){super(new Uint32Array(e),t,r)}},Tl=class extends $t{constructor(e,t,r){super(new Uint16Array(e),t,r),this.isFloat16BufferAttribute=!0}getX(e){let t=Gu(this.array[e*this.itemSize]);return this.normalized&&(t=rr(t,this.array)),t}setX(e,t){return this.normalized&&(t=Ne(t,this.array)),this.array[e*this.itemSize]=ei(t),this}getY(e){let t=Gu(this.array[e*this.itemSize+1]);return this.normalized&&(t=rr(t,this.array)),t}setY(e,t){return this.normalized&&(t=Ne(t,this.array)),this.array[e*this.itemSize+1]=ei(t),this}getZ(e){let t=Gu(this.array[e*this.itemSize+2]);return this.normalized&&(t=rr(t,this.array)),t}setZ(e,t){return this.normalized&&(t=Ne(t,this.array)),this.array[e*this.itemSize+2]=ei(t),this}getW(e){let t=Gu(this.array[e*this.itemSize+3]);return this.normalized&&(t=rr(t,this.array)),t}setW(e,t){return this.normalized&&(t=Ne(t,this.array)),this.array[e*this.itemSize+3]=ei(t),this}setXY(e,t,r){return e*=this.itemSize,this.normalized&&(t=Ne(t,this.array),r=Ne(r,this.array)),this.array[e+0]=ei(t),this.array[e+1]=ei(r),this}setXYZ(e,t,r,i){return e*=this.itemSize,this.normalized&&(t=Ne(t,this.array),r=Ne(r,this.array),i=Ne(i,this.array)),this.array[e+0]=ei(t),this.array[e+1]=ei(r),this.array[e+2]=ei(i),this}setXYZW(e,t,r,i,s){return e*=this.itemSize,this.normalized&&(t=Ne(t,this.array),r=Ne(r,this.array),i=Ne(i,this.array),s=Ne(s,this.array)),this.array[e+0]=ei(t),this.array[e+1]=ei(r),this.array[e+2]=ei(i),this.array[e+3]=ei(s),this}},ft=class extends $t{constructor(e,t,r){super(new Float32Array(e),t,r)}};var EE=new mn,zu=new C,qg=new C,bs=class{constructor(e=new C,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){let r=this.center;t!==void 0?r.copy(t):EE.setFromPoints(e).getCenter(r);let i=0;for(let s=0,o=e.length;s<o;s++)i=Math.max(i,r.distanceToSquared(e[s]));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){let 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){let r=this.center.distanceToSquared(e);return t.copy(e),r>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;zu.subVectors(e,this.center);let t=zu.lengthSq();if(t>this.radius*this.radius){let r=Math.sqrt(t),i=(r-this.radius)*.5;this.center.addScaledVector(zu,i/r),this.radius+=i}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(qg.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(zu.copy(e.center).add(qg)),this.expandByPoint(zu.copy(e.center).sub(qg))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}};var BE=0,Di=new ue,jg=new Ke,Sl=new C,hi=new mn,$u=new mn,qt=new C,ir=class n extends bt{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:BE++}),this.uuid=Ir(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(ww(e)?_l:bl)(e,1):this.index=e,this}setIndirect(e,t=0){return this.indirect=e,this.indirectOffset=t,this}getIndirect(){return this.indirect}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 this.attributes[e]!==void 0}addGroup(e,t,r=0){this.groups.push({start:e,count:t,materialIndex:r})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){let t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);let r=this.attributes.normal;if(r!==void 0){let s=new et().getNormalMatrix(e);r.applyNormalMatrix(s),r.needsUpdate=!0}let i=this.attributes.tangent;return i!==void 0&&(i.transformDirection(e),i.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(e){return Di.makeRotationFromQuaternion(e),this.applyMatrix4(Di),this}rotateX(e){return Di.makeRotationX(e),this.applyMatrix4(Di),this}rotateY(e){return Di.makeRotationY(e),this.applyMatrix4(Di),this}rotateZ(e){return Di.makeRotationZ(e),this.applyMatrix4(Di),this}translate(e,t,r){return Di.makeTranslation(e,t,r),this.applyMatrix4(Di),this}scale(e,t,r){return Di.makeScale(e,t,r),this.applyMatrix4(Di),this}lookAt(e){return jg.lookAt(e),jg.updateMatrix(),this.applyMatrix4(jg.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Sl).negate(),this.translate(Sl.x,Sl.y,Sl.z),this}setFromPoints(e){let t=this.getAttribute("position");if(t===void 0){let r=[];for(let i=0,s=e.length;i<s;i++){let o=e[i];r.push(o.x,o.y,o.z||0)}this.setAttribute("position",new ft(r,3))}else{let r=Math.min(e.length,t.count);for(let i=0;i<r;i++){let s=e[i];t.setXYZ(i,s.x,s.y,s.z||0)}e.length>t.count&&U("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new mn);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){I("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new C(-1/0,-1/0,-1/0),new C(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let r=0,i=t.length;r<i;r++){let s=t[r];hi.setFromBufferAttribute(s),this.morphTargetsRelative?(qt.addVectors(this.boundingBox.min,hi.min),this.boundingBox.expandByPoint(qt),qt.addVectors(this.boundingBox.max,hi.max),this.boundingBox.expandByPoint(qt)):(this.boundingBox.expandByPoint(hi.min),this.boundingBox.expandByPoint(hi.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&I('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new bs);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){I("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new C,1/0);return}if(e){let r=this.boundingSphere.center;if(hi.setFromBufferAttribute(e),t)for(let s=0,o=t.length;s<o;s++){let a=t[s];$u.setFromBufferAttribute(a),this.morphTargetsRelative?(qt.addVectors(hi.min,$u.min),hi.expandByPoint(qt),qt.addVectors(hi.max,$u.max),hi.expandByPoint(qt)):(hi.expandByPoint($u.min),hi.expandByPoint($u.max))}hi.getCenter(r);let i=0;for(let s=0,o=e.count;s<o;s++)qt.fromBufferAttribute(e,s),i=Math.max(i,r.distanceToSquared(qt));if(t)for(let s=0,o=t.length;s<o;s++){let a=t[s],l=this.morphTargetsRelative;for(let u=0,c=a.count;u<c;u++)qt.fromBufferAttribute(a,u),l&&(Sl.fromBufferAttribute(e,u),qt.add(Sl)),i=Math.max(i,r.distanceToSquared(qt))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&I('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){let e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){I("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}let r=t.position,i=t.normal,s=t.uv,o=this.getAttribute("tangent");(o===void 0||o.count!==r.count)&&(o=new $t(new Float32Array(4*r.count),4),this.setAttribute("tangent",o));let a=[],l=[];for(let M=0;M<r.count;M++)a[M]=new C,l[M]=new C;let u=new C,c=new C,d=new C,h=new se,p=new se,f=new se,m=new C,g=new C;function x(M,B,D){u.fromBufferAttribute(r,M),c.fromBufferAttribute(r,B),d.fromBufferAttribute(r,D),h.fromBufferAttribute(s,M),p.fromBufferAttribute(s,B),f.fromBufferAttribute(s,D),c.sub(u),d.sub(u),p.sub(h),f.sub(h);let O=1/(p.x*f.y-f.x*p.y);isFinite(O)&&(m.copy(c).multiplyScalar(f.y).addScaledVector(d,-p.y).multiplyScalar(O),g.copy(d).multiplyScalar(p.x).addScaledVector(c,-f.x).multiplyScalar(O),a[M].add(m),a[B].add(m),a[D].add(m),l[M].add(g),l[B].add(g),l[D].add(g))}let w=this.groups;w.length===0&&(w=[{start:0,count:e.count}]);for(let M=0,B=w.length;M<B;++M){let D=w[M],O=D.start,z=D.count;for(let Q=O,oe=O+z;Q<oe;Q+=3)x(e.getX(Q+0),e.getX(Q+1),e.getX(Q+2))}let v=new C,E=new C,b=new C,S=new C;function T(M){b.fromBufferAttribute(i,M),S.copy(b);let B=a[M];v.copy(B),v.sub(b.multiplyScalar(b.dot(B))).normalize(),E.crossVectors(S,B);let O=E.dot(l[M])<0?-1:1;o.setXYZW(M,v.x,v.y,v.z,O)}for(let M=0,B=w.length;M<B;++M){let D=w[M],O=D.start,z=D.count;for(let Q=O,oe=O+z;Q<oe;Q+=3)T(e.getX(Q+0)),T(e.getX(Q+1)),T(e.getX(Q+2))}this._transformed=!0}computeVertexNormals(){let e=this.index,t=this.getAttribute("position");if(t!==void 0){let r=this.getAttribute("normal");if(r===void 0||r.count!==t.count)r=new $t(new Float32Array(t.count*3),3),this.setAttribute("normal",r);else for(let h=0,p=r.count;h<p;h++)r.setXYZ(h,0,0,0);let i=new C,s=new C,o=new C,a=new C,l=new C,u=new C,c=new C,d=new C;if(e)for(let h=0,p=e.count;h<p;h+=3){let f=e.getX(h+0),m=e.getX(h+1),g=e.getX(h+2);i.fromBufferAttribute(t,f),s.fromBufferAttribute(t,m),o.fromBufferAttribute(t,g),c.subVectors(o,s),d.subVectors(i,s),c.cross(d),a.fromBufferAttribute(r,f),l.fromBufferAttribute(r,m),u.fromBufferAttribute(r,g),a.add(c),l.add(c),u.add(c),r.setXYZ(f,a.x,a.y,a.z),r.setXYZ(m,l.x,l.y,l.z),r.setXYZ(g,u.x,u.y,u.z)}else for(let h=0,p=t.count;h<p;h+=3)i.fromBufferAttribute(t,h+0),s.fromBufferAttribute(t,h+1),o.fromBufferAttribute(t,h+2),c.subVectors(o,s),d.subVectors(i,s),c.cross(d),r.setXYZ(h+0,c.x,c.y,c.z),r.setXYZ(h+1,c.x,c.y,c.z),r.setXYZ(h+2,c.x,c.y,c.z);this.normalizeNormals(),r.needsUpdate=!0}}normalizeNormals(){let e=this.attributes.normal;for(let t=0,r=e.count;t<r;t++)qt.fromBufferAttribute(e,t),qt.normalize(),e.setXYZ(t,qt.x,qt.y,qt.z)}toNonIndexed(){function e(a,l){let u=a.array,c=a.itemSize,d=a.normalized,h=new u.constructor(l.length*c),p=0,f=0;for(let m=0,g=l.length;m<g;m++){a.isInterleavedBufferAttribute?p=l[m]*a.data.stride+a.offset:p=l[m]*c;for(let x=0;x<c;x++)h[f++]=u[p++]}return new $t(h,c,d)}if(this.index===null)return U("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;let t=new n,r=this.index.array,i=this.attributes;for(let a in i){let l=i[a],u=e(l,r);t.setAttribute(a,u)}let s=this.morphAttributes;for(let a in s){let l=[],u=s[a];for(let c=0,d=u.length;c<d;c++){let h=u[c],p=e(h,r);l.push(p)}t.morphAttributes[a]=l}t.morphTargetsRelative=this.morphTargetsRelative;let o=this.groups;for(let a=0,l=o.length;a<l;a++){let u=o[a];t.addGroup(u.start,u.count,u.materialIndex)}return t}toJSON(){let e={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(e.uuid=this.uuid,e.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,this.name!==""&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){let l=this.parameters;for(let u in l)l[u]!==void 0&&(e[u]=l[u]);return e}e.data={attributes:{}};let t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});let r=this.attributes;for(let l in r){let u=r[l];e.data.attributes[l]=u.toJSON(e.data)}let i={},s=!1;for(let l in this.morphAttributes){let u=this.morphAttributes[l],c=[];for(let d=0,h=u.length;d<h;d++){let p=u[d];c.push(p.toJSON(e.data))}c.length>0&&(i[l]=c,s=!0)}s&&(e.data.morphAttributes=i,e.data.morphTargetsRelative=this.morphTargetsRelative);let o=this.groups;o.length>0&&(e.data.groups=JSON.parse(JSON.stringify(o)));let a=this.boundingSphere;return a!==null&&(e.data.boundingSphere=a.toJSON()),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;let t={};this.name=e.name;let r=e.index;r!==null&&this.setIndex(r.clone());let i=e.attributes;for(let u in i){let c=i[u];this.setAttribute(u,c.clone(t))}let s=e.morphAttributes;for(let u in s){let c=[],d=s[u];for(let h=0,p=d.length;h<p;h++)c.push(d[h].clone(t));this.morphAttributes[u]=c}this.morphTargetsRelative=e.morphTargetsRelative;let o=e.groups;for(let u=0,c=o.length;u<c;u++){let d=o[u];this.addGroup(d.start,d.count,d.materialIndex)}let a=e.boundingBox;a!==null&&(this.boundingBox=a.clone());let l=e.boundingSphere;return l!==null&&(this.boundingSphere=l.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this._transformed=e._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}};var Nl=class{constructor(e,t){this.isInterleavedBuffer=!0,this.array=e,this.stride=t,this.count=e!==void 0?e.length/t:0,this.usage=ys,this.updateRanges=[],this.version=0,this.uuid=Ir()}onUploadCallback(){}set needsUpdate(e){e===!0&&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,r){e*=this.stride,r*=t.stride;for(let i=0,s=this.stride;i<s;i++)this.array[e+i]=t.array[r+i];return this}set(e,t=0){return this.array.set(e,t),this}clone(e){e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Ir()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);let t=new this.array.constructor(e.arrayBuffers[this.array.buffer._uuid]),r=new this.constructor(t,this.stride);return r.setUsage(this.usage),r}onUpload(e){return this.onUploadCallback=e,this}toJSON(e){e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Ir()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer)));let t={uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride};return this.usage!==ys&&(t.usage=this.usage),t}};var Or=new C,ch=class n{constructor(e,t,r,i=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=e,this.itemSize=t,this.offset=r,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,r=this.data.count;t<r;t++)Or.fromBufferAttribute(this,t),Or.applyMatrix4(e),this.setXYZ(t,Or.x,Or.y,Or.z);return this}applyNormalMatrix(e){for(let t=0,r=this.count;t<r;t++)Or.fromBufferAttribute(this,t),Or.applyNormalMatrix(e),this.setXYZ(t,Or.x,Or.y,Or.z);return this}transformDirection(e){for(let t=0,r=this.count;t<r;t++)Or.fromBufferAttribute(this,t),Or.transformDirection(e),this.setXYZ(t,Or.x,Or.y,Or.z);return this}getComponent(e,t){let r=this.array[e*this.data.stride+this.offset+t];return this.normalized&&(r=rr(r,this.array)),r}setComponent(e,t,r){return this.normalized&&(r=Ne(r,this.array)),this.data.array[e*this.data.stride+this.offset+t]=r,this}setX(e,t){return this.normalized&&(t=Ne(t,this.array)),this.data.array[e*this.data.stride+this.offset]=t,this}setY(e,t){return this.normalized&&(t=Ne(t,this.array)),this.data.array[e*this.data.stride+this.offset+1]=t,this}setZ(e,t){return this.normalized&&(t=Ne(t,this.array)),this.data.array[e*this.data.stride+this.offset+2]=t,this}setW(e,t){return this.normalized&&(t=Ne(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=rr(t,this.array)),t}getY(e){let t=this.data.array[e*this.data.stride+this.offset+1];return this.normalized&&(t=rr(t,this.array)),t}getZ(e){let t=this.data.array[e*this.data.stride+this.offset+2];return this.normalized&&(t=rr(t,this.array)),t}getW(e){let t=this.data.array[e*this.data.stride+this.offset+3];return this.normalized&&(t=rr(t,this.array)),t}setXY(e,t,r){return e=e*this.data.stride+this.offset,this.normalized&&(t=Ne(t,this.array),r=Ne(r,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=r,this}setXYZ(e,t,r,i){return e=e*this.data.stride+this.offset,this.normalized&&(t=Ne(t,this.array),r=Ne(r,this.array),i=Ne(i,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=r,this.data.array[e+2]=i,this}setXYZW(e,t,r,i,s){return e=e*this.data.stride+this.offset,this.normalized&&(t=Ne(t,this.array),r=Ne(r,this.array),i=Ne(i,this.array),s=Ne(s,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=r,this.data.array[e+2]=i,this.data.array[e+3]=s,this}clone(e){if(e===void 0){Ou("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");let t=[];for(let r=0;r<this.count;r++){let i=r*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[i+s])}return new $t(new this.array.constructor(t),this.itemSize,this.normalized)}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.clone(e)),new n(e.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(e){if(e===void 0){Ou("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");let t=[];for(let r=0;r<this.count;r++){let i=r*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[i+s])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.toJSON(e)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}};var FE=0,st=class extends bt{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:FE++}),this.uuid=Ir(),this.name="",this.type="Material",this.blending=Zt,this.side=Yr,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=sn,this.blendDst=nn,this.blendEquation=Jt,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new le(0,0,0),this.blendAlpha=0,this.depthFunc=fs,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=Iu,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=un,this.stencilZFail=un,this.stencilZPass=un,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.allowOverride=!0,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}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(let t in e){let r=e[t];if(r===void 0){U(`Material: parameter '${t}' has value of undefined.`);continue}let i=this[t];if(i===void 0){U(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}i&&i.isColor?i.set(r):i&&i.isVector2&&r&&r.isVector2||i&&i.isEuler&&r&&r.isEuler||i&&i.isVector3&&r&&r.isVector3?i.copy(r):this[t]=r}}toJSON(e){let t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});let r={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};r.uuid=this.uuid,r.type=this.type,this.name!==""&&(r.name=this.name),this.color&&this.color.isColor&&(r.color=this.color.getHex()),this.roughness!==void 0&&(r.roughness=this.roughness),this.metalness!==void 0&&(r.metalness=this.metalness),this.sheen!==void 0&&(r.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(r.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(r.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(r.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(r.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(r.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(r.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(r.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(r.shininess=this.shininess),this.clearcoat!==void 0&&(r.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(r.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(r.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(r.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(r.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,r.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(r.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(r.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(r.dispersion=this.dispersion),this.retroreflective!==void 0&&(r.retroreflective=this.retroreflective),this.iridescence!==void 0&&(r.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(r.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(r.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(r.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(r.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(r.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(r.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(r.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(r.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(r.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(r.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(r.lightMap=this.lightMap.toJSON(e).uuid,r.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(r.aoMap=this.aoMap.toJSON(e).uuid,r.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(r.bumpMap=this.bumpMap.toJSON(e).uuid,r.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(r.normalMap=this.normalMap.toJSON(e).uuid,r.normalMapType=this.normalMapType,r.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(r.displacementMap=this.displacementMap.toJSON(e).uuid,r.displacementScale=this.displacementScale,r.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(r.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(r.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(r.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(r.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(r.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(r.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(r.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(r.combine=this.combine)),this.envMapRotation!==void 0&&(r.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(r.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(r.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(r.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(r.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(r.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(r.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(r.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(r.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(r.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(r.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(r.size=this.size),this.shadowSide!==null&&(r.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(r.sizeAttenuation=this.sizeAttenuation),this.blending!==Zt&&(r.blending=this.blending),this.side!==Yr&&(r.side=this.side),this.vertexColors===!0&&(r.vertexColors=!0),this.opacity<1&&(r.opacity=this.opacity),this.transparent===!0&&(r.transparent=!0),this.blendSrc!==sn&&(r.blendSrc=this.blendSrc),this.blendDst!==nn&&(r.blendDst=this.blendDst),this.blendEquation!==Jt&&(r.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(r.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(r.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(r.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(r.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(r.blendAlpha=this.blendAlpha),this.depthFunc!==fs&&(r.depthFunc=this.depthFunc),this.depthTest===!1&&(r.depthTest=this.depthTest),this.depthWrite===!1&&(r.depthWrite=this.depthWrite),this.colorWrite===!1&&(r.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(r.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==Iu&&(r.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(r.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(r.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==un&&(r.stencilFail=this.stencilFail),this.stencilZFail!==un&&(r.stencilZFail=this.stencilZFail),this.stencilZPass!==un&&(r.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(r.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(r.rotation=this.rotation),this.polygonOffset===!0&&(r.polygonOffset=!0),this.polygonOffsetFactor!==0&&(r.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(r.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(r.linewidth=this.linewidth),this.dashSize!==void 0&&(r.dashSize=this.dashSize),this.gapSize!==void 0&&(r.gapSize=this.gapSize),this.scale!==void 0&&(r.scale=this.scale),this.dithering===!0&&(r.dithering=!0),this.alphaTest>0&&(r.alphaTest=this.alphaTest),this.alphaHash===!0&&(r.alphaHash=!0),this.alphaToCoverage===!0&&(r.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(r.premultipliedAlpha=!0),this.forceSinglePass===!0&&(r.forceSinglePass=!0),this.allowOverride===!1&&(r.allowOverride=!1),this.wireframe===!0&&(r.wireframe=!0),this.wireframeLinewidth>1&&(r.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(r.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(r.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(r.flatShading=!0),this.visible===!1&&(r.visible=!1),this.toneMapped===!1&&(r.toneMapped=!1),this.fog===!1&&(r.fog=!1),Object.keys(this.userData).length>0&&(r.userData=this.userData);function i(s){let o=[];for(let a in s){let l=s[a];delete l.metadata,o.push(l)}return o}if(t){let s=i(e.textures),o=i(e.images);s.length>0&&(r.textures=s),o.length>0&&(r.images=o)}return r}fromJSON(e,t){if(e.uuid!==void 0&&(this.uuid=e.uuid),e.name!==void 0&&(this.name=e.name),e.color!==void 0&&this.color!==void 0&&this.color.setHex(e.color),e.roughness!==void 0&&(this.roughness=e.roughness),e.metalness!==void 0&&(this.metalness=e.metalness),e.sheen!==void 0&&(this.sheen=e.sheen),e.sheenColor!==void 0&&(this.sheenColor=new le().setHex(e.sheenColor)),e.sheenRoughness!==void 0&&(this.sheenRoughness=e.sheenRoughness),e.emissive!==void 0&&this.emissive!==void 0&&this.emissive.setHex(e.emissive),e.specular!==void 0&&this.specular!==void 0&&this.specular.setHex(e.specular),e.specularIntensity!==void 0&&(this.specularIntensity=e.specularIntensity),e.specularColor!==void 0&&this.specularColor!==void 0&&this.specularColor.setHex(e.specularColor),e.shininess!==void 0&&(this.shininess=e.shininess),e.clearcoat!==void 0&&(this.clearcoat=e.clearcoat),e.clearcoatRoughness!==void 0&&(this.clearcoatRoughness=e.clearcoatRoughness),e.dispersion!==void 0&&(this.dispersion=e.dispersion),e.retroreflective!==void 0&&(this.retroreflective=e.retroreflective),e.iridescence!==void 0&&(this.iridescence=e.iridescence),e.iridescenceIOR!==void 0&&(this.iridescenceIOR=e.iridescenceIOR),e.iridescenceThicknessRange!==void 0&&(this.iridescenceThicknessRange=e.iridescenceThicknessRange),e.transmission!==void 0&&(this.transmission=e.transmission),e.thickness!==void 0&&(this.thickness=e.thickness),e.attenuationDistance!==void 0&&(this.attenuationDistance=e.attenuationDistance),e.attenuationColor!==void 0&&this.attenuationColor!==void 0&&this.attenuationColor.setHex(e.attenuationColor),e.anisotropy!==void 0&&(this.anisotropy=e.anisotropy),e.anisotropyRotation!==void 0&&(this.anisotropyRotation=e.anisotropyRotation),e.fog!==void 0&&(this.fog=e.fog),e.flatShading!==void 0&&(this.flatShading=e.flatShading),e.blending!==void 0&&(this.blending=e.blending),e.combine!==void 0&&(this.combine=e.combine),e.side!==void 0&&(this.side=e.side),e.shadowSide!==void 0&&(this.shadowSide=e.shadowSide),e.opacity!==void 0&&(this.opacity=e.opacity),e.transparent!==void 0&&(this.transparent=e.transparent),e.alphaTest!==void 0&&(this.alphaTest=e.alphaTest),e.alphaHash!==void 0&&(this.alphaHash=e.alphaHash),e.depthFunc!==void 0&&(this.depthFunc=e.depthFunc),e.depthTest!==void 0&&(this.depthTest=e.depthTest),e.depthWrite!==void 0&&(this.depthWrite=e.depthWrite),e.colorWrite!==void 0&&(this.colorWrite=e.colorWrite),e.blendSrc!==void 0&&(this.blendSrc=e.blendSrc),e.blendDst!==void 0&&(this.blendDst=e.blendDst),e.blendEquation!==void 0&&(this.blendEquation=e.blendEquation),e.blendSrcAlpha!==void 0&&(this.blendSrcAlpha=e.blendSrcAlpha),e.blendDstAlpha!==void 0&&(this.blendDstAlpha=e.blendDstAlpha),e.blendEquationAlpha!==void 0&&(this.blendEquationAlpha=e.blendEquationAlpha),e.blendColor!==void 0&&this.blendColor!==void 0&&this.blendColor.setHex(e.blendColor),e.blendAlpha!==void 0&&(this.blendAlpha=e.blendAlpha),e.stencilWriteMask!==void 0&&(this.stencilWriteMask=e.stencilWriteMask),e.stencilFunc!==void 0&&(this.stencilFunc=e.stencilFunc),e.stencilRef!==void 0&&(this.stencilRef=e.stencilRef),e.stencilFuncMask!==void 0&&(this.stencilFuncMask=e.stencilFuncMask),e.stencilFail!==void 0&&(this.stencilFail=e.stencilFail),e.stencilZFail!==void 0&&(this.stencilZFail=e.stencilZFail),e.stencilZPass!==void 0&&(this.stencilZPass=e.stencilZPass),e.stencilWrite!==void 0&&(this.stencilWrite=e.stencilWrite),e.wireframe!==void 0&&(this.wireframe=e.wireframe),e.wireframeLinewidth!==void 0&&(this.wireframeLinewidth=e.wireframeLinewidth),e.wireframeLinecap!==void 0&&(this.wireframeLinecap=e.wireframeLinecap),e.wireframeLinejoin!==void 0&&(this.wireframeLinejoin=e.wireframeLinejoin),e.rotation!==void 0&&(this.rotation=e.rotation),e.linewidth!==void 0&&(this.linewidth=e.linewidth),e.dashSize!==void 0&&(this.dashSize=e.dashSize),e.gapSize!==void 0&&(this.gapSize=e.gapSize),e.scale!==void 0&&(this.scale=e.scale),e.polygonOffset!==void 0&&(this.polygonOffset=e.polygonOffset),e.polygonOffsetFactor!==void 0&&(this.polygonOffsetFactor=e.polygonOffsetFactor),e.polygonOffsetUnits!==void 0&&(this.polygonOffsetUnits=e.polygonOffsetUnits),e.dithering!==void 0&&(this.dithering=e.dithering),e.alphaToCoverage!==void 0&&(this.alphaToCoverage=e.alphaToCoverage),e.premultipliedAlpha!==void 0&&(this.premultipliedAlpha=e.premultipliedAlpha),e.forceSinglePass!==void 0&&(this.forceSinglePass=e.forceSinglePass),e.allowOverride!==void 0&&(this.allowOverride=e.allowOverride),e.visible!==void 0&&(this.visible=e.visible),e.toneMapped!==void 0&&(this.toneMapped=e.toneMapped),e.userData!==void 0&&(this.userData=e.userData),e.vertexColors!==void 0&&(typeof e.vertexColors=="number"?this.vertexColors=e.vertexColors>0:this.vertexColors=e.vertexColors),e.size!==void 0&&(this.size=e.size),e.sizeAttenuation!==void 0&&(this.sizeAttenuation=e.sizeAttenuation),e.map!==void 0&&(this.map=t[e.map]||null),e.matcap!==void 0&&(this.matcap=t[e.matcap]||null),e.alphaMap!==void 0&&(this.alphaMap=t[e.alphaMap]||null),e.bumpMap!==void 0&&(this.bumpMap=t[e.bumpMap]||null),e.bumpScale!==void 0&&(this.bumpScale=e.bumpScale),e.normalMap!==void 0&&(this.normalMap=t[e.normalMap]||null),e.normalMapType!==void 0&&(this.normalMapType=e.normalMapType),e.normalScale!==void 0){let r=e.normalScale;Array.isArray(r)===!1&&(r=[r,r]),this.normalScale=new se().fromArray(r)}return e.displacementMap!==void 0&&(this.displacementMap=t[e.displacementMap]||null),e.displacementScale!==void 0&&(this.displacementScale=e.displacementScale),e.displacementBias!==void 0&&(this.displacementBias=e.displacementBias),e.roughnessMap!==void 0&&(this.roughnessMap=t[e.roughnessMap]||null),e.metalnessMap!==void 0&&(this.metalnessMap=t[e.metalnessMap]||null),e.emissiveMap!==void 0&&(this.emissiveMap=t[e.emissiveMap]||null),e.emissiveIntensity!==void 0&&(this.emissiveIntensity=e.emissiveIntensity),e.specularMap!==void 0&&(this.specularMap=t[e.specularMap]||null),e.specularIntensityMap!==void 0&&(this.specularIntensityMap=t[e.specularIntensityMap]||null),e.specularColorMap!==void 0&&(this.specularColorMap=t[e.specularColorMap]||null),e.envMap!==void 0&&(this.envMap=t[e.envMap]||null),e.envMapRotation!==void 0&&this.envMapRotation.fromArray(e.envMapRotation),e.envMapIntensity!==void 0&&(this.envMapIntensity=e.envMapIntensity),e.reflectivity!==void 0&&(this.reflectivity=e.reflectivity),e.refractionRatio!==void 0&&(this.refractionRatio=e.refractionRatio),e.lightMap!==void 0&&(this.lightMap=t[e.lightMap]||null),e.lightMapIntensity!==void 0&&(this.lightMapIntensity=e.lightMapIntensity),e.aoMap!==void 0&&(this.aoMap=t[e.aoMap]||null),e.aoMapIntensity!==void 0&&(this.aoMapIntensity=e.aoMapIntensity),e.gradientMap!==void 0&&(this.gradientMap=t[e.gradientMap]||null),e.clearcoatMap!==void 0&&(this.clearcoatMap=t[e.clearcoatMap]||null),e.clearcoatRoughnessMap!==void 0&&(this.clearcoatRoughnessMap=t[e.clearcoatRoughnessMap]||null),e.clearcoatNormalMap!==void 0&&(this.clearcoatNormalMap=t[e.clearcoatNormalMap]||null),e.clearcoatNormalScale!==void 0&&(this.clearcoatNormalScale=new se().fromArray(e.clearcoatNormalScale)),e.iridescenceMap!==void 0&&(this.iridescenceMap=t[e.iridescenceMap]||null),e.iridescenceThicknessMap!==void 0&&(this.iridescenceThicknessMap=t[e.iridescenceThicknessMap]||null),e.transmissionMap!==void 0&&(this.transmissionMap=t[e.transmissionMap]||null),e.thicknessMap!==void 0&&(this.thicknessMap=t[e.thicknessMap]||null),e.anisotropyMap!==void 0&&(this.anisotropyMap=t[e.anisotropyMap]||null),e.sheenColorMap!==void 0&&(this.sheenColorMap=t[e.sheenColorMap]||null),e.sheenRoughnessMap!==void 0&&(this.sheenRoughnessMap=t[e.sheenRoughnessMap]||null),this}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;let t=e.clippingPlanes,r=null;if(t!==null){let i=t.length;r=new Array(i);for(let s=0;s!==i;++s)r[s]=t[s].clone()}return this.clippingPlanes=r,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.allowOverride=e.allowOverride,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){e===!0&&this.version++}};var dh=class extends st{constructor(e){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new le(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}};var xn=new C,Xg=new C,hh=new C,ph=new C,fh=class{constructor(e=new C,t=new C(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,xn)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);let r=t.dot(this.direction);return r<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,r)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){let t=xn.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(xn.copy(this.origin).addScaledVector(this.direction,t),xn.distanceToSquared(e))}distanceSqToSegment(e,t,r,i){Xg.copy(e).add(t).multiplyScalar(.5),hh.copy(t).sub(e).normalize(),ph.copy(this.origin).sub(Xg);let s=e.distanceTo(t)*.5,o=-this.direction.dot(hh),a=ph.dot(this.direction),l=-ph.dot(hh),u=ph.lengthSq(),c=Math.abs(1-o*o),d,h,p,f;if(c>0)if(d=o*l-a,h=o*a-l,f=s*c,d>=0)if(h>=-f)if(h<=f){let m=1/c;d*=m,h*=m,p=d*(d+o*h+2*a)+h*(o*d+h+2*l)+u}else h=s,d=Math.max(0,-(o*h+a)),p=-d*d+h*(h+2*l)+u;else h=-s,d=Math.max(0,-(o*h+a)),p=-d*d+h*(h+2*l)+u;else h<=-f?(d=Math.max(0,-(-o*s+a)),h=d>0?-s:Math.min(Math.max(-s,-l),s),p=-d*d+h*(h+2*l)+u):h<=f?(d=0,h=Math.min(Math.max(-s,-l),s),p=h*(h+2*l)+u):(d=Math.max(0,-(o*s+a)),h=d>0?s:Math.min(Math.max(-s,-l),s),p=-d*d+h*(h+2*l)+u);else h=o>0?-s:s,d=Math.max(0,-(o*h+a)),p=-d*d+h*(h+2*l)+u;return r&&r.copy(this.origin).addScaledVector(this.direction,d),i&&i.copy(Xg).addScaledVector(hh,h),p}intersectSphere(e,t){if(e.radius<0)return null;xn.subVectors(e.center,this.origin);let r=xn.dot(this.direction),i=xn.dot(xn)-r*r,s=e.radius*e.radius;if(i>s)return null;let o=Math.sqrt(s-i),a=r-o,l=r+o;return l<0?null:a<0?this.at(l,t):this.at(a,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){let t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;let r=-(this.origin.dot(e.normal)+e.constant)/t;return r>=0?r:null}intersectPlane(e,t){let r=this.distanceToPlane(e);return r===null?null:this.at(r,t)}intersectsPlane(e){let t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let r,i,s,o,a,l,u=1/this.direction.x,c=1/this.direction.y,d=1/this.direction.z,h=this.origin;return u>=0?(r=(e.min.x-h.x)*u,i=(e.max.x-h.x)*u):(r=(e.max.x-h.x)*u,i=(e.min.x-h.x)*u),c>=0?(s=(e.min.y-h.y)*c,o=(e.max.y-h.y)*c):(s=(e.max.y-h.y)*c,o=(e.min.y-h.y)*c),r>o||s>i||((s>r||isNaN(r))&&(r=s),(o<i||isNaN(i))&&(i=o),d>=0?(a=(e.min.z-h.z)*d,l=(e.max.z-h.z)*d):(a=(e.max.z-h.z)*d,l=(e.min.z-h.z)*d),r>l||a>i)||((a>r||r!==r)&&(r=a),(l<i||i!==i)&&(i=l),i<0)?null:this.at(r>=0?r:i,t)}intersectsBox(e){return this.intersectBox(e,xn)!==null}intersectTriangle(e,t,r,i,s){let o=this.origin,a=this.direction,l=a.x,u=a.y,c=a.z,d=e.x-o.x,h=e.y-o.y,p=e.z-o.z,f=t.x-o.x,m=t.y-o.y,g=t.z-o.z,x=r.x-o.x,w=r.y-o.y,v=r.z-o.z,E=Math.abs(l),b=Math.abs(u),S=Math.abs(c),T,M,B,D,O,z,Q,oe,H,ae,de,me;if(E>=b&&E>=S?(B=l,z=d,H=f,me=x,l>=0?(T=u,M=c,D=h,O=p,Q=m,oe=g,ae=w,de=v):(T=c,M=u,D=p,O=h,Q=g,oe=m,ae=v,de=w)):b>=S?(B=u,z=h,H=m,me=w,u>=0?(T=c,M=l,D=p,O=d,Q=g,oe=f,ae=v,de=x):(T=l,M=c,D=d,O=p,Q=f,oe=g,ae=x,de=v)):(B=c,z=p,H=g,me=v,c>=0?(T=l,M=u,D=d,O=h,Q=f,oe=m,ae=x,de=w):(T=u,M=l,D=h,O=d,Q=m,oe=f,ae=w,de=x)),B===0)return null;let Ae=T/B,ge=M/B,Oe=1/B,Ge=D-Ae*z,He=O-ge*z,Lr=Q-Ae*H,li=oe-ge*H,vu=ae-Ae*me,Ja=de-ge*me,Js=vu*li-Ja*Lr,zt=Ge*Ja-He*vu,Qi=Lr*He-li*Ge;if(i){if(Js<0||zt<0||Qi<0)return null}else if((Js<0||zt<0||Qi<0)&&(Js>0||zt>0||Qi>0))return null;let en=Js+zt+Qi;if(en===0)return null;let ps=Oe*(Js*z+zt*H+Qi*me);return(en>0?ps<0:ps>0)?null:this.at(ps/en,s)}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)}};var ti=class extends st{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new le(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 br,this.combine=Hn,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}};var Vw=new ue,Ma=new fh,mh=new bs,Gw=new C,gh=new C,xh=new C,yh=new C,Yg=new C,bh=new C,zw=new C,_h=new C,sr=class extends Ke{constructor(e=new ir,t=new ti){super(),this.isMesh=!0,this.type="Mesh",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){let t=this.geometry.morphAttributes,r=Object.keys(t);if(r.length>0){let i=t[r[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=i.length;s<o;s++){let a=i[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}getVertexPosition(e,t){let r=this.geometry,i=r.attributes.position,s=r.morphAttributes.position,o=r.morphTargetsRelative;t.fromBufferAttribute(i,e);let a=this.morphTargetInfluences;if(s&&a){bh.set(0,0,0);for(let l=0,u=s.length;l<u;l++){let c=a[l],d=s[l];c!==0&&(Yg.fromBufferAttribute(d,e),o?bh.addScaledVector(Yg,c):bh.addScaledVector(Yg.sub(t),c))}t.add(bh)}return t}raycast(e,t){let r=this.geometry,i=this.material,s=this.matrixWorld;i!==void 0&&(r.boundingSphere===null&&r.computeBoundingSphere(),mh.copy(r.boundingSphere),mh.applyMatrix4(s),Ma.copy(e.ray).recast(e.near),!(mh.containsPoint(Ma.origin)===!1&&(Ma.intersectSphere(mh,Gw)===null||Ma.origin.distanceToSquared(Gw)>(e.far-e.near)**2))&&(Vw.copy(s).invert(),Ma.copy(e.ray).applyMatrix4(Vw),!(r.boundingBox!==null&&Ma.intersectsBox(r.boundingBox)===!1)&&this._computeIntersections(e,t,Ma)))}_computeIntersections(e,t,r){let i,s=this.geometry,o=this.material,a=s.index,l=s.attributes.position,u=s.attributes.uv,c=s.attributes.uv1,d=s.attributes.normal,h=s.groups,p=s.drawRange;if(a!==null)if(Array.isArray(o))for(let f=0,m=h.length;f<m;f++){let g=h[f],x=o[g.materialIndex],w=Math.max(g.start,p.start),v=Math.min(a.count,Math.min(g.start+g.count,p.start+p.count));for(let E=w,b=v;E<b;E+=3){let S=a.getX(E),T=a.getX(E+1),M=a.getX(E+2);i=Th(this,x,e,r,u,c,d,S,T,M),i&&(i.faceIndex=Math.floor(E/3),i.face.materialIndex=g.materialIndex,t.push(i))}}else{let f=Math.max(0,p.start),m=Math.min(a.count,p.start+p.count);for(let g=f,x=m;g<x;g+=3){let w=a.getX(g),v=a.getX(g+1),E=a.getX(g+2);i=Th(this,o,e,r,u,c,d,w,v,E),i&&(i.faceIndex=Math.floor(g/3),t.push(i))}}else if(l!==void 0)if(Array.isArray(o))for(let f=0,m=h.length;f<m;f++){let g=h[f],x=o[g.materialIndex],w=Math.max(g.start,p.start),v=Math.min(l.count,Math.min(g.start+g.count,p.start+p.count));for(let E=w,b=v;E<b;E+=3){let S=E,T=E+1,M=E+2;i=Th(this,x,e,r,u,c,d,S,T,M),i&&(i.faceIndex=Math.floor(E/3),i.face.materialIndex=g.materialIndex,t.push(i))}}else{let f=Math.max(0,p.start),m=Math.min(l.count,p.start+p.count);for(let g=f,x=m;g<x;g+=3){let w=g,v=g+1,E=g+2;i=Th(this,o,e,r,u,c,d,w,v,E),i&&(i.faceIndex=Math.floor(g/3),t.push(i))}}}};function LE(n,e,t,r,i,s,o,a){let l;if(e.side===Ze?l=r.intersectTriangle(o,s,i,!0,a):l=r.intersectTriangle(i,s,o,e.side===Yr,a),l===null)return null;_h.copy(a),_h.applyMatrix4(n.matrixWorld);let u=t.ray.origin.distanceTo(_h);return u<t.near||u>t.far?null:{distance:u,point:_h.clone(),object:n}}function Th(n,e,t,r,i,s,o,a,l,u){n.getVertexPosition(a,gh),n.getVertexPosition(l,xh),n.getVertexPosition(u,yh);let c=LE(n,e,t,r,gh,xh,yh,zw);if(c){let d=new C;no.getBarycoord(zw,gh,xh,yh,d),i&&(c.uv=no.getInterpolatedAttribute(i,a,l,u,d,new se)),s&&(c.uv1=no.getInterpolatedAttribute(s,a,l,u,d,new se)),o&&(c.normal=no.getInterpolatedAttribute(o,a,l,u,d,new C),c.normal.dot(r.direction)>0&&c.normal.multiplyScalar(-1));let h={a,b:l,c:u,normal:new C,materialIndex:0};no.getNormal(gh,xh,yh,h.normal),c.face=h,c.barycoord=d}return c}var yn=class extends nt{constructor(e=null,t=1,r=1,i,s,o,a,l,u=Pe,c=Pe,d,h){super(null,o,a,l,u,c,i,s,d,h),this.isDataTexture=!0,this.image={data:e,width:t,height:r},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}};var Ui=class extends $t{constructor(e,t,r,i=1){super(e,t,r),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=i}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}toJSON(){let e=super.toJSON();return e.meshPerAttribute=this.meshPerAttribute,e.isInstancedBufferAttribute=!0,e}};var Kg=new C,PE=new C,DE=new et,pi=class{constructor(e=new C(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,r,i){return this.normal.set(e,t,r),this.constant=i,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,r){let i=Kg.subVectors(r,t).cross(PE.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(i,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){let 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,r=!0){let i=e.delta(Kg),s=this.normal.dot(i);if(s===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;let o=-(e.start.dot(this.normal)+this.constant)/s;return r===!0&&(o<0||o>1)?null:t.copy(e.start).addScaledVector(i,o)}intersectsLine(e){let t=this.distanceToPoint(e.start),r=this.distanceToPoint(e.end);return t<0&&r>0||r<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){let r=t||DE.getNormalMatrix(e),i=this.coplanarPoint(Kg).applyMatrix4(e),s=this.normal.applyMatrix3(r).normalize();return this.constant=-i.dot(s),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)}};var va=new bs,UE=new se(.5,.5),Sh=new C,bn=class{constructor(e=new pi,t=new pi,r=new pi,i=new pi,s=new pi,o=new pi){this.planes=[e,t,r,i,s,o]}set(e,t,r,i,s,o){let a=this.planes;return a[0].copy(e),a[1].copy(t),a[2].copy(r),a[3].copy(i),a[4].copy(s),a[5].copy(o),this}copy(e){let t=this.planes;for(let r=0;r<6;r++)t[r].copy(e.planes[r]);return this}setFromProjectionMatrix(e,t=At,r=!1){let i=this.planes,s=e.elements,o=s[0],a=s[1],l=s[2],u=s[3],c=s[4],d=s[5],h=s[6],p=s[7],f=s[8],m=s[9],g=s[10],x=s[11],w=s[12],v=s[13],E=s[14],b=s[15];if(i[0].setComponents(u-o,p-c,x-f,b-w).normalize(),i[1].setComponents(u+o,p+c,x+f,b+w).normalize(),i[2].setComponents(u+a,p+d,x+m,b+v).normalize(),i[3].setComponents(u-a,p-d,x-m,b-v).normalize(),r)i[4].setComponents(l,h,g,E).normalize(),i[5].setComponents(u-l,p-h,x-g,b-E).normalize();else if(i[4].setComponents(u-l,p-h,x-g,b-E).normalize(),t===At)i[5].setComponents(u+l,p+h,x+g,b+E).normalize();else if(t===yt)i[5].setComponents(l,h,g,E).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),va.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{let t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),va.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(va)}intersectsSprite(e){va.center.set(0,0,0);let t=UE.distanceTo(e.center);return va.radius=.7071067811865476+t,va.applyMatrix4(e.matrixWorld),this.intersectsSphere(va)}intersectsSphere(e){let t=this.planes,r=e.center,i=-e.radius;for(let s=0;s<6;s++)if(t[s].distanceToPoint(r)<i)return!1;return!0}intersectsBox(e){let t=this.planes;for(let r=0;r<6;r++){let i=t[r];if(Sh.x=i.normal.x>0?e.max.x:e.min.x,Sh.y=i.normal.y>0?e.max.y:e.min.y,Sh.z=i.normal.z>0?e.max.z:e.min.z,i.distanceToPoint(Sh)<0)return!1}return!0}containsPoint(e){let t=this.planes;for(let r=0;r<6;r++)if(t[r].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}};var $w=new ue,Nh=class n{constructor(){this.coordinateSystem=At,this._frustums=[],this._count=0}setFromArrayCamera(e){let t=e.cameras,r=this._frustums;for(let i=0;i<t.length;i++){let s=t[i];$w.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse),r[i]===void 0&&(r[i]=new bn),r[i].setFromProjectionMatrix($w,s.coordinateSystem,s.reversedDepth)}return this._count=t.length,this}intersectsObject(e){let t=this._frustums;for(let r=0;r<this._count;r++)if(t[r].intersectsObject(e))return!0;return!1}intersectsSprite(e){let t=this._frustums;for(let r=0;r<this._count;r++)if(t[r].intersectsSprite(e))return!0;return!1}intersectsSphere(e){let t=this._frustums;for(let r=0;r<this._count;r++)if(t[r].intersectsSphere(e))return!0;return!1}intersectsBox(e){let t=this._frustums;for(let r=0;r<this._count;r++)if(t[r].intersectsBox(e))return!0;return!1}containsPoint(e){let t=this._frustums;for(let r=0;r<this._count;r++)if(t[r].containsPoint(e))return!0;return!1}copy(e){this.coordinateSystem=e.coordinateSystem;let t=this._frustums,r=e._frustums;for(let i=0;i<e._count;i++)t[i]===void 0&&(t[i]=new bn),t[i].copy(r[i]);return this._count=e._count,this}clone(){return new n().copy(this)}};var wl=class extends st{constructor(e){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new le(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}};var wh=class extends st{constructor(e){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new le(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}};var lo=class extends nt{constructor(e,t){super({width:e,height:t}),this.isFramebufferTexture=!0,this.magFilter=Pe,this.minFilter=Pe,this.generateMipmaps=!1,this.needsUpdate=!0}};var _s=class extends nt{constructor(e=[],t=Ji,r,i,s,o,a,l,u,c){super(e,t,r,i,s,o,a,l,u,c),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}};var ot=class extends nt{constructor(e,t,r=Ce,i,s,o,a=Pe,l=Pe,u,c=Mt,d=1){if(c!==Mt&&c!==Ht)throw new Error("THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat");let h={width:e,height:t,depth:d};super(h,i,s,o,a,l,c,r,u),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new to(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){let t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}};var Mh=class extends ot{constructor(e,t=Ce,r=Ji,i,s,o=Pe,a=Pe,l,u=Mt){let c={width:e,height:e,depth:1},d=[c,c,c,c,c,c];super(e,e,t,r,i,s,o,a,l,u),this.image=d,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(e){this.image=e}};var Ml=class n extends ir{constructor(e=1,t=1,r=1,i=1,s=1,o=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:r,widthSegments:i,heightSegments:s,depthSegments:o};let a=this;i=Math.floor(i),s=Math.floor(s),o=Math.floor(o);let l=[],u=[],c=[],d=[],h=0,p=0;f("z","y","x",-1,-1,r,t,e,o,s,0),f("z","y","x",1,-1,r,t,-e,o,s,1),f("x","z","y",1,1,e,r,t,i,o,2),f("x","z","y",1,-1,e,r,-t,i,o,3),f("x","y","z",1,-1,e,t,r,i,s,4),f("x","y","z",-1,-1,e,t,-r,i,s,5),this.setIndex(l),this.setAttribute("position",new ft(u,3)),this.setAttribute("normal",new ft(c,3)),this.setAttribute("uv",new ft(d,2));function f(m,g,x,w,v,E,b,S,T,M,B){let D=E/T,O=b/M,z=E/2,Q=b/2,oe=S/2,H=T+1,ae=M+1,de=0,me=0,Ae=new C;for(let ge=0;ge<ae;ge++){let Oe=ge*O-Q;for(let Ge=0;Ge<H;Ge++){let He=Ge*D-z;Ae[m]=He*w,Ae[g]=Oe*v,Ae[x]=oe,u.push(Ae.x,Ae.y,Ae.z),Ae[m]=0,Ae[g]=0,Ae[x]=S>0?1:-1,c.push(Ae.x,Ae.y,Ae.z),d.push(Ge/T),d.push(1-ge/M),de+=1}}for(let ge=0;ge<M;ge++)for(let Oe=0;Oe<T;Oe++){let Ge=h+Oe+H*ge,He=h+Oe+H*(ge+1),Lr=h+(Oe+1)+H*(ge+1),li=h+(Oe+1)+H*ge;l.push(Ge,He,li),l.push(He,Lr,li),me+=6}a.addGroup(p,me,B),p+=me,h+=de}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new n(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}};var vh=class n extends ir{constructor(e=1,t=1,r=1,i=32,s=1,o=!1,a=0,l=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:e,radiusBottom:t,height:r,radialSegments:i,heightSegments:s,openEnded:o,thetaStart:a,thetaLength:l};let u=this;i=Math.floor(i),s=Math.floor(s);let c=[],d=[],h=[],p=[],f=0,m=[],g=r/2,x=0;w(),o===!1&&(e>0&&v(!0),t>0&&v(!1)),this.setIndex(c),this.setAttribute("position",new ft(d,3)),this.setAttribute("normal",new ft(h,3)),this.setAttribute("uv",new ft(p,2));function w(){let E=new C,b=new C,S=0,T=(t-e)/r;for(let M=0;M<=s;M++){let B=[],D=M/s,O=D*(t-e)+e;for(let z=0;z<=i;z++){let Q=z/i,oe=Q*l+a,H=Math.sin(oe),ae=Math.cos(oe);b.x=O*H,b.y=-D*r+g,b.z=O*ae,d.push(b.x,b.y,b.z),E.set(H,T,ae).normalize(),h.push(E.x,E.y,E.z),p.push(Q,1-D),B.push(f++)}m.push(B)}for(let M=0;M<i;M++)for(let B=0;B<s;B++){let D=m[B][M],O=m[B+1][M],z=m[B+1][M+1],Q=m[B][M+1];(e>0||B!==0)&&(c.push(D,O,Q),S+=3),(t>0||B!==s-1)&&(c.push(O,z,Q),S+=3)}u.addGroup(x,S,0),x+=S}function v(E){let b=f,S=new se,T=new C,M=0,B=E===!0?e:t,D=E===!0?1:-1;for(let z=1;z<=i;z++)d.push(0,g*D,0),h.push(0,D,0),p.push(.5,.5),f++;let O=f;for(let z=0;z<=i;z++){let oe=z/i*l+a,H=Math.cos(oe),ae=Math.sin(oe);T.x=B*ae,T.y=g*D,T.z=B*H,d.push(T.x,T.y,T.z),h.push(0,D,0),S.x=H*.5+.5,S.y=ae*.5*D+.5,p.push(S.x,S.y),f++}for(let z=0;z<i;z++){let Q=b+z,oe=O+z;E===!0?c.push(oe,oe+1,Q):c.push(oe+1,oe,Q),M+=3}u.addGroup(x,M,E===!0?1:2),x+=M}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new n(e.radiusTop,e.radiusBottom,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}};var Wu=class n extends ir{constructor(e=1,t=1,r=1,i=1){super(),this.type="PlaneGeometry",this.parameters={width:e,height:t,widthSegments:r,heightSegments:i};let s=e/2,o=t/2,a=Math.floor(r),l=Math.floor(i),u=a+1,c=l+1,d=e/a,h=t/l,p=[],f=[],m=[],g=[];for(let x=0;x<c;x++){let w=x*h-o;for(let v=0;v<u;v++){let E=v*d-s;f.push(E,-w,0),m.push(0,0,1),g.push(v/a),g.push(1-x/l)}}for(let x=0;x<l;x++)for(let w=0;w<a;w++){let v=w+u*x,E=w+u*(x+1),b=w+1+u*(x+1),S=w+1+u*x;p.push(v,E,S),p.push(E,b,S)}this.setIndex(p),this.setAttribute("position",new ft(f,3)),this.setAttribute("normal",new ft(m,3)),this.setAttribute("uv",new ft(g,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new n(e.width,e.height,e.widthSegments,e.heightSegments)}};var Ah=class n extends ir{constructor(e=1,t=32,r=16,i=0,s=Math.PI*2,o=0,a=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:e,widthSegments:t,heightSegments:r,phiStart:i,phiLength:s,thetaStart:o,thetaLength:a},t=Math.max(3,Math.floor(t)),r=Math.max(2,Math.floor(r));let l=Math.min(o+a,Math.PI),u=0,c=[],d=new C,h=new C,p=[],f=[],m=[],g=[];for(let x=0;x<=r;x++){let w=[],v=x/r,E=o+v*a,b=e*Math.cos(E),S=Math.sqrt(e*e-b*b),T=0;x===0&&o===0?T=.5/t:x===r&&l===Math.PI&&(T=-.5/t);for(let M=0;M<=t;M++){let B=M/t,D=i+B*s;d.x=-S*Math.cos(D),d.y=b,d.z=S*Math.sin(D),f.push(d.x,d.y,d.z),h.copy(d).normalize(),m.push(h.x,h.y,h.z),g.push(B+T,1-v),w.push(u++)}c.push(w)}for(let x=0;x<r;x++)for(let w=0;w<t;w++){let v=c[x][w+1],E=c[x][w],b=c[x+1][w],S=c[x+1][w+1];(x!==0||o>0)&&p.push(v,E,S),(x!==r-1||l<Math.PI)&&p.push(E,b,S)}this.setIndex(p),this.setAttribute("position",new ft(f,3)),this.setAttribute("normal",new ft(m,3)),this.setAttribute("uv",new ft(g,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new n(e.radius,e.widthSegments,e.heightSegments,e.phiStart,e.phiLength,e.thetaStart,e.thetaLength)}};var Rh=class extends st{constructor(e){super(),this.isShadowMaterial=!0,this.type="ShadowMaterial",this.color=new le(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}};var vl=class extends st{constructor(e){super(),this.isMeshStandardMaterial=!0,this.type="MeshStandardMaterial",this.defines={STANDARD:""},this.color=new le(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 le(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=gr,this.normalScale=new se(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 br,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}};var Ch=class extends vl{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 se(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return Te(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(t){this.ior=(1+.4*t)/(1-.4*t)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessRange=[100,400],this.iridescenceThicknessMap=null,this.sheenColor=new le(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 le(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new le(1,1,1),this.specularColorMap=null,this._anisotropy=0,this._clearcoat=0,this._dispersion=0,this._iridescence=0,this._retroreflective=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 retroreflective(){return this._retroreflective}set retroreflective(e){this._retroreflective>0!=e>0&&this.version++,this._retroreflective=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.retroreflective=e.retroreflective,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}};var Eh=class extends st{constructor(e){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new le(16777215),this.specular=new le(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new le(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=gr,this.normalScale=new se(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new br,this.combine=Hn,this.reflectivity=1,this.envMapIntensity=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.envMapIntensity=e.envMapIntensity,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}};var Bh=class extends st{constructor(e){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new le(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new le(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=gr,this.normalScale=new se(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}};var Fh=class extends st{constructor(e){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=gr,this.normalScale=new se(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}};var Lh=class extends st{constructor(e){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new le(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new le(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=gr,this.normalScale=new se(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new br,this.combine=Hn,this.reflectivity=1,this.envMapIntensity=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.envMapIntensity=e.envMapIntensity,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}};var Ph=class extends st{constructor(e){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new le(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=gr,this.normalScale=new se(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,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.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this.fog=e.fog,this}};var Dh=class extends wl{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}};var Tr=class extends Ke{constructor(e,t=1){super(),this.isLight=!0,this.type="Light",this.color=new le(e),this.intensity=t}dispose(){this.dispatchEvent({type:"dispose"})}copy(e,t){return super.copy(e,t),this.color.copy(e.color),this.intensity=e.intensity,this}toJSON(e){let t=super.toJSON(e);return t.object.color=this.color.getHex(),t.object.intensity=this.intensity,t}};var Uh=class extends Tr{constructor(e,t,r){super(e,r),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(Ke.DEFAULT_UP),this.updateMatrix(),this.groundColor=new le(t)}copy(e,t){return super.copy(e,t),this.groundColor.copy(e.groundColor),this}toJSON(e){let t=super.toJSON(e);return t.object.groundColor=this.groundColor.getHex(),t}};var Qg=new ue,Ww=new C,Hw=new C,uo=class{constructor(e){this.camera=e,this.intensity=1,this.bias=0,this.biasNode=null,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new se(512,512),this.mapType=it,this.map=null,this.mapPass=null,this.matrix=new ue,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new bn,this._frameExtents=new se(1,1),this._viewportCount=1,this._viewports=[new pe(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(e){let t=this.camera,r=this.matrix;Ww.setFromMatrixPosition(e.matrixWorld),t.position.copy(Ww),Hw.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(Hw),t.updateMatrixWorld(),Qg.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Qg,t.coordinateSystem,t.reversedDepth),t.coordinateSystem===yt||t.reversedDepth?r.set(.5,0,0,.5,0,.5,0,.5,0,0,1,0,0,0,0,1):r.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),r.multiply(Qg)}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.autoUpdate=e.autoUpdate,this.needsUpdate=e.needsUpdate,this.normalBias=e.normalBias,this.blurSamples=e.blurSamples,this.mapSize.copy(e.mapSize),this.biasNode=e.biasNode,this}clone(){return new this.constructor().copy(this)}toJSON(){let e={};return this.intensity!==1&&(e.intensity=this.intensity),this.bias!==0&&(e.bias=this.bias),this.normalBias!==0&&(e.normalBias=this.normalBias),this.radius!==1&&(e.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(e.mapSize=this.mapSize.toArray()),e.camera=this.camera.toJSON(!1).object,delete e.camera.matrix,e}};var Ih=new C,Oh=new Jr,Ts=new C,Al=class extends Ke{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new ue,this.projectionMatrix=new ue,this.projectionMatrixInverse=new ue,this.coordinateSystem=At,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}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(Ih,Oh,Ts),Ts.x===1&&Ts.y===1&&Ts.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(Ih,Oh,Ts.set(1,1,1)).invert()}updateWorldMatrix(e,t,r=!1){super.updateWorldMatrix(e,t,r),this.matrixWorld.decompose(Ih,Oh,Ts),Ts.x===1&&Ts.y===1&&Ts.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(Ih,Oh,Ts.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}};var co=new C,qw=new se,jw=new se,Rt=class extends Al{constructor(e=50,t=1,r=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=r,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=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){let t=.5*this.getFilmHeight()/e;this.fov=cn*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){let e=Math.tan(ll*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return cn*2*Math.atan(Math.tan(ll*.5*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,r){co.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(co.x,co.y).multiplyScalar(-e/co.z),co.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),r.set(co.x,co.y).multiplyScalar(-e/co.z)}getViewSize(e,t){return this.getViewBounds(e,qw,jw),t.subVectors(jw,qw)}setViewOffset(e,t,r,i,s,o){this.aspect=e/t,this.view===null&&(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=r,this.view.offsetY=i,this.view.width=s,this.view.height=o,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=this.near,t=e*Math.tan(ll*.5*this.fov)/this.zoom,r=2*t,i=this.aspect*r,s=-.5*i,o=this.view;if(this.view!==null&&this.view.enabled){let l=o.fullWidth,u=o.fullHeight;s+=o.offsetX*i/l,t-=o.offsetY*r/u,i*=o.width/l,r*=o.height/u}let a=this.filmOffset;a!==0&&(s+=e*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+i,t,t-r,e,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let 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,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}};var kh=class extends uo{constructor(){super(new Rt(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1,this.aspect=1}updateMatrices(e){let t=this.camera,r=cn*2*e.angle*this.focus,i=this.mapSize.width/this.mapSize.height*this.aspect,s=e.distance||t.far;(r!==t.fov||i!==t.aspect||s!==t.far)&&(t.fov=r,t.aspect=i,t.far=s,t.updateProjectionMatrix()),super.updateMatrices(e)}copy(e){return super.copy(e),this.focus=e.focus,this}};var ho=class extends Tr{constructor(e,t,r=0,i=Math.PI/3,s=0,o=2){super(e,t),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(Ke.DEFAULT_UP),this.updateMatrix(),this.target=new Ke,this.distance=r,this.angle=i,this.penumbra=s,this.decay=o,this.map=null,this.shadow=new kh}get power(){return this.intensity*Math.PI}set power(e){this.intensity=e/Math.PI}dispose(){super.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.map=e.map,this.shadow=e.shadow.clone(),this}toJSON(e){let t=super.toJSON(e);return t.object.distance=this.distance,t.object.angle=this.angle,t.object.decay=this.decay,t.object.penumbra=this.penumbra,t.object.target=this.target.uuid,this.map&&this.map.isTexture&&(t.object.map=this.map.toJSON(e).uuid),t.object.shadow=this.shadow.toJSON(),t}};var Vh=class extends uo{constructor(){super(new Rt(90,1,.5,500)),this.isPointLightShadow=!0}};var Gh=class extends Tr{constructor(e,t,r=0,i=2){super(e,t),this.isPointLight=!0,this.type="PointLight",this.distance=r,this.decay=i,this.shadow=new Vh}get power(){return this.intensity*4*Math.PI}set power(e){this.intensity=e/(4*Math.PI)}dispose(){super.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}toJSON(e){let t=super.toJSON(e);return t.object.distance=this.distance,t.object.decay=this.decay,t.object.shadow=this.shadow.toJSON(),t}};var Ss=class extends Al{constructor(e=-1,t=1,r=1,i=-1,s=.1,o=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=r,this.bottom=i,this.near=s,this.far=o,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=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,r,i,s,o){this.view===null&&(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=r,this.view.offsetY=i,this.view.width=s,this.view.height=o,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),r=(this.right+this.left)/2,i=(this.top+this.bottom)/2,s=r-e,o=r+e,a=i+t,l=i-t;if(this.view!==null&&this.view.enabled){let u=(this.right-this.left)/this.view.fullWidth/this.zoom,c=(this.top-this.bottom)/this.view.fullHeight/this.zoom;s+=u*this.view.offsetX,o=s+u*this.view.width,a-=c*this.view.offsetY,l=a-c*this.view.height}this.projectionMatrix.makeOrthographic(s,o,a,l,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let 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,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}};var zh=class extends uo{constructor(){super(new Ss(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}};var $h=class extends Tr{constructor(e,t){super(e,t),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(Ke.DEFAULT_UP),this.updateMatrix(),this.target=new Ke,this.shadow=new zh}dispose(){super.dispose(),this.shadow.dispose()}copy(e){return super.copy(e),this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}toJSON(e){let t=super.toJSON(e);return t.object.shadow=this.shadow.toJSON(),t.object.target=this.target.uuid,t}};var Wh=class extends Tr{constructor(e,t){super(e,t),this.isAmbientLight=!0,this.type="AmbientLight"}};var Hh=class extends Tr{constructor(e,t,r=10,i=10){super(e,t),this.isRectAreaLight=!0,this.type="RectAreaLight",this.width=r,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){let t=super.toJSON(e);return t.object.width=this.width,t.object.height=this.height,t}};var qh=class{constructor(){this.isSphericalHarmonics3=!0,this.coefficients=[];for(let e=0;e<9;e++)this.coefficients.push(new C)}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){let r=e.x,i=e.y,s=e.z,o=this.coefficients;return t.copy(o[0]).multiplyScalar(.282095),t.addScaledVector(o[1],.488603*i),t.addScaledVector(o[2],.488603*s),t.addScaledVector(o[3],.488603*r),t.addScaledVector(o[4],1.092548*(r*i)),t.addScaledVector(o[5],1.092548*(i*s)),t.addScaledVector(o[6],.315392*(3*s*s-1)),t.addScaledVector(o[7],1.092548*(r*s)),t.addScaledVector(o[8],.546274*(r*r-i*i)),t}getIrradianceAt(e,t){let r=e.x,i=e.y,s=e.z,o=this.coefficients;return t.copy(o[0]).multiplyScalar(.886227),t.addScaledVector(o[1],2*.511664*i),t.addScaledVector(o[2],2*.511664*s),t.addScaledVector(o[3],2*.511664*r),t.addScaledVector(o[4],2*.429043*r*i),t.addScaledVector(o[5],2*.429043*i*s),t.addScaledVector(o[6],.743125*s*s-.247708),t.addScaledVector(o[7],2*.429043*r*s),t.addScaledVector(o[8],.429043*(r*r-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 r=0;r<9;r++)this.coefficients[r].addScaledVector(e.coefficients[r],t);return this}scale(e){for(let t=0;t<9;t++)this.coefficients[t].multiplyScalar(e);return this}lerp(e,t){for(let r=0;r<9;r++)this.coefficients[r].lerp(e.coefficients[r],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){let r=this.coefficients;for(let i=0;i<9;i++)r[i].fromArray(e,t+i*3);return this}toArray(e=[],t=0){let r=this.coefficients;for(let i=0;i<9;i++)r[i].toArray(e,t+i*3);return e}static getBasisAt(e,t){let r=e.x,i=e.y,s=e.z;t[0]=.282095,t[1]=.488603*i,t[2]=.488603*s,t[3]=.488603*r,t[4]=1.092548*r*i,t[5]=1.092548*i*s,t[6]=.315392*(3*s*s-1),t[7]=1.092548*r*s,t[8]=.546274*(r*r-i*i)}};var jh=class extends Tr{constructor(e=new qh,t=1){super(void 0,t),this.isLightProbe=!0,this.sh=e}copy(e){return super.copy(e),this.sh.copy(e.sh),this}toJSON(e){let t=super.toJSON(e);return t.object.sh=this.sh.toArray(),t}};var Rl=-90,Cl=1,Xh=class extends Ke{constructor(e,t,r){super(),this.type="CubeCamera",this.renderTarget=r,this.coordinateSystem=null,this.activeMipmapLevel=0;let i=new Rt(Rl,Cl,e,t);i.layers=this.layers,this.add(i);let s=new Rt(Rl,Cl,e,t);s.layers=this.layers,this.add(s);let o=new Rt(Rl,Cl,e,t);o.layers=this.layers,this.add(o);let a=new Rt(Rl,Cl,e,t);a.layers=this.layers,this.add(a);let l=new Rt(Rl,Cl,e,t);l.layers=this.layers,this.add(l);let u=new Rt(Rl,Cl,e,t);u.layers=this.layers,this.add(u)}updateCoordinateSystem(){let e=this.coordinateSystem,t=this.children.concat(),[r,i,s,o,a,l]=t;for(let u of t)this.remove(u);if(e===At)r.up.set(0,1,0),r.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),s.up.set(0,0,-1),s.lookAt(0,1,0),o.up.set(0,0,1),o.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),l.up.set(0,1,0),l.lookAt(0,0,-1);else if(e===yt)r.up.set(0,-1,0),r.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),s.up.set(0,0,1),s.lookAt(0,1,0),o.up.set(0,0,-1),o.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),l.up.set(0,-1,0),l.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+e);for(let u of t)this.add(u),u.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();let{renderTarget:r,activeMipmapLevel:i}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());let[s,o,a,l,u,c]=this.children,d=e.getRenderTarget(),h=e.getActiveCubeFace(),p=e.getActiveMipmapLevel(),f=e.xr.enabled;e.xr.enabled=!1;let m=r.texture.generateMipmaps;r.texture.generateMipmaps=!1;let g=!1;e.isWebGLRenderer===!0?g=e.state.buffers.depth.getReversed():g=e.reversedDepthBuffer,e.setRenderTarget(r,0,i),g&&e.autoClear===!1&&e.clearDepth(),e.render(t,s),e.setRenderTarget(r,1,i),g&&e.autoClear===!1&&e.clearDepth(),e.render(t,o),e.setRenderTarget(r,2,i),g&&e.autoClear===!1&&e.clearDepth(),e.render(t,a),e.setRenderTarget(r,3,i),g&&e.autoClear===!1&&e.clearDepth(),e.render(t,l),e.setRenderTarget(r,4,i),g&&e.autoClear===!1&&e.clearDepth(),e.render(t,u),r.texture.generateMipmaps=m,e.setRenderTarget(r,5,i),g&&e.autoClear===!1&&e.clearDepth(),e.render(t,c),e.setRenderTarget(d,h,p),e.xr.enabled=f,r.texture.needsPMREMUpdate=!0}};var Yh=class extends Rt{constructor(e=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=e}};var Aa=class extends Nl{constructor(e,t,r=1){super(e,t),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=r}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}clone(e){let t=super.clone(e);return t.meshPerAttribute=this.meshPerAttribute,t}toJSON(e){let t=super.toJSON(e);return t.isInstancedInterleavedBuffer=!0,t.meshPerAttribute=this.meshPerAttribute,t}};var El=class n{static{n.prototype.isMatrix2=!0}constructor(e,t,r,i){this.elements=[1,0,0,1],e!==void 0&&this.set(e,t,r,i)}identity(){return this.set(1,0,0,1),this}fromArray(e,t=0){for(let r=0;r<4;r++)this.elements[r]=e[r+t];return this}set(e,t,r,i){let s=this.elements;return s[0]=e,s[2]=t,s[1]=r,s[3]=i,this}};function Zg(n,e,t,r){let i=IE(r);switch(t){case Xn:return n*e;case Bi:return n*e/i.components*i.byteLength;case Fi:return n*e/i.components*i.byteLength;case vt:return n*e*2/i.components*i.byteLength;case Li:return n*e*2/i.components*i.byteLength;case Ei:return n*e*3/i.components*i.byteLength;case wt:return n*e*4/i.components*i.byteLength;case Yn:return n*e*4/i.components*i.byteLength;case Kn:case Qn:return Math.floor((n+3)/4)*Math.floor((e+3)/4)*8;case Zn:case Jn:return Math.floor((n+3)/4)*Math.floor((e+3)/4)*16;case Pu:case Uu:return Math.max(n,16)*Math.max(e,8)/4;case Lu:case Du:return Math.max(n,8)*Math.max(e,8)/2;case Ho:case qo:case Xo:case Yo:return Math.floor((n+3)/4)*Math.floor((e+3)/4)*8;case jo:case an:case Ko:return Math.floor((n+3)/4)*Math.floor((e+3)/4)*16;case Qo:return Math.floor((n+3)/4)*Math.floor((e+3)/4)*16;case Zo:return Math.floor((n+4)/5)*Math.floor((e+3)/4)*16;case Jo:return Math.floor((n+4)/5)*Math.floor((e+4)/5)*16;case ea:return Math.floor((n+5)/6)*Math.floor((e+4)/5)*16;case ta:return Math.floor((n+5)/6)*Math.floor((e+5)/6)*16;case ra:return Math.floor((n+7)/8)*Math.floor((e+4)/5)*16;case ia:return Math.floor((n+7)/8)*Math.floor((e+5)/6)*16;case sa:return Math.floor((n+7)/8)*Math.floor((e+7)/8)*16;case na:return Math.floor((n+9)/10)*Math.floor((e+4)/5)*16;case oa:return Math.floor((n+9)/10)*Math.floor((e+5)/6)*16;case aa:return Math.floor((n+9)/10)*Math.floor((e+7)/8)*16;case la:return Math.floor((n+9)/10)*Math.floor((e+9)/10)*16;case ua:return Math.floor((n+11)/12)*Math.floor((e+9)/10)*16;case ca:return Math.floor((n+11)/12)*Math.floor((e+11)/12)*16;case da:case ha:case pa:return Math.ceil(n/4)*Math.ceil(e/4)*16;case fa:case ma:return Math.ceil(n/4)*Math.ceil(e/4)*8;case ln:case ga:return Math.ceil(n/4)*Math.ceil(e/4)*16}throw new Error(`Unable to determine texture byte length for ${t} format.`)}function IE(n){switch(n){case it:case Ci:return{byteLength:1,components:1};case er:case mr:case qe:return{byteLength:2,components:1};case rl:case il:return{byteLength:2,components:4};case Ce:case Je:case ze:return{byteLength:4,components:1};case qn:case jn:return{byteLength:4,components:3}}throw new Error(`THREE.TextureUtils: Unknown texture type ${n}.`)}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:tn}}));typeof window<"u"&&(window.__THREE__?U("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=tn);var OE=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","aoMapIntensity","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveIntensity","emissiveMap","envMap","envMapIntensity","envMapRotation","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","lightMapIntensity","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","retroreflective","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"],Xw=new WeakMap,Yw=new WeakMap,Kw=new WeakMap,Jg=class{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=e.object.isSkinnedMesh===!0,this.refreshUniforms=OE,this.renderId=0}firstInitialization(e){return this.renderObjects.has(e)===!1?(this.getRenderObjectData(e),!0):!1}needsVelocity(e){let t=e.getMRT();return t!==null&&t.has("velocity")}getRenderObjectData(e){let t=this.renderObjects.get(e);if(t===void 0){let{geometry:r,object:i}=e;if(t={geometryId:r.id,geometryVersion:this.getGeometryData(r)._version,materialVersion:this.getMaterialData(e.material)._version,worldMatrix:i.matrixWorld.clone()},i.center&&(t.center=i.center.clone()),i.morphTargetInfluences&&(t.morphTargetInfluences=i.morphTargetInfluences.slice()),e.bundle!==null&&(t.version=e.bundle.version),e.material.transmission>0){let{width:a,height:l}=e.context;t.bufferWidth=a,t.bufferHeight=l}let{environmentIntensity:s,environmentRotation:o}=e.scene;t.environmentIntensity=s,t.environmentRotation=o.clone(),t.lights=this.getLightsData(e.lightsNode.getBuiltinLights(),[]),this.renderObjects.set(e,t)}return t}getAttributesData(e){let t={};for(let r in e){let i=e[r];t[r]={id:i.isInterleavedBufferAttribute?i.data.uuid:i.id,version:i.isInterleavedBufferAttribute?i.data.version:i.version}}return t}containsNode(e){let t=e.material;for(let r in t)if(t[r]&&t[r].isNode)return!0;return!!(e.context.modelViewMatrix||e.context.modelNormalViewMatrix||e.context.getAO||e.context.getShadow)}getGeometryData(e){let t=Kw.get(e);return t===void 0&&(t={_renderId:-1,_version:0,attributes:this.getAttributesData(e.attributes),indexId:e.index?e.index.id:null,indexVersion:e.index?e.index.version:null,drawRange:{start:e.drawRange.start,count:e.drawRange.count}},Kw.set(e,t)),t}getMaterialData(e){let t=Yw.get(e);if(t===void 0){t={_renderId:-1,_version:0};for(let r of this.refreshUniforms){let i=e[r];i!=null&&(typeof i=="object"&&i.clone!==void 0?i.isTexture===!0?t[r]={id:i.id,version:0}:t[r]=i.clone():t[r]=i)}Yw.set(e,t)}return t}equals(e,t,r){let{object:i,material:s,geometry:o}=e,a=this.getRenderObjectData(e);if(a.worldMatrix.equals(i.matrixWorld)!==!0)return a.worldMatrix.copy(i.matrixWorld),!1;let l=this.getMaterialData(e.material);if(l._renderId!==r){l._renderId=r;let d=!1;for(let h in l){let p=l[h],f=s[h];h!=="_renderId"&&h!=="_version"&&(p.equals!==void 0?p.equals(f)===!1&&(p.copy(f),d=!0):f.isTexture===!0?(p.id!==f.id||p.version!==f.version)&&(p.id=f.id,p.version=f.version,d=!0):p!==f&&(l[h]=f,d=!0))}d===!0&&l._version++}if(a.materialVersion!==l._version)return a.materialVersion=l._version,!1;if(l.transmission>0){let{width:d,height:h}=e.context;if(a.bufferWidth!==d||a.bufferHeight!==h)return a.bufferWidth=d,a.bufferHeight=h,!1}if(a.geometryId!==o.id)return a.geometryId=o.id,!1;let u=this.getGeometryData(e.geometry);if(u._renderId!==r){u._renderId=r;let d=!1,h=o.attributes,p=u.attributes,f=0,m=0;for(let v in h)f++;for(let v in p){m++;let E=p[v],b=h[v];if(b===void 0){delete p[v],d=!0;continue}let S=b.isInterleavedBufferAttribute?b.data.uuid:b.id,T=b.isInterleavedBufferAttribute?b.data.version:b.version;(E.id!==S||E.version!==T)&&(E.id=S,E.version=T,d=!0)}m!==f&&(u.attributes=this.getAttributesData(h),d=!0);let g=o.index,x=g?g.id:null,w=g?g.version:null;(u.indexId!==x||u.indexVersion!==w)&&(u.indexId=x,u.indexVersion=w,d=!0),(u.drawRange.start!==o.drawRange.start||u.drawRange.count!==o.drawRange.count)&&(u.drawRange.start=o.drawRange.start,u.drawRange.count=o.drawRange.count,d=!0),d===!0&&u._version++}if(a.geometryVersion!==u._version)return a.geometryVersion=u._version,!1;if(a.morphTargetInfluences){let d=!1;for(let h=0;h<a.morphTargetInfluences.length;h++)a.morphTargetInfluences[h]!==i.morphTargetInfluences[h]&&(a.morphTargetInfluences[h]=i.morphTargetInfluences[h],d=!0);if(d)return!1}if(a.lights){for(let d=0;d<t.length;d++)if(a.lights[d].map!==t[d].map)return!1}let c=e.scene;return c.environment!==null&&s.envMap===null&&(a.environmentIntensity!==c.environmentIntensity||a.environmentRotation.equals(c.environmentRotation)===!1)?(a.environmentIntensity=c.environmentIntensity,a.environmentRotation.copy(c.environmentRotation),!1):a.center&&a.center.equals(i.center)===!1?(a.center.copy(i.center),!1):(e.bundle!==null&&(a.version=e.bundle.version),!0)}getLightsData(e,t){t.length=0;for(let r of e)r.isSpotLight===!0&&r.map!==null&&t.push({map:r.map.version});return t}getLights(e,t){let r=Xw.get(e);return r===void 0&&(r={renderId:-1,lightsData:[]},Xw.set(e,r)),r.renderId===t||(r.renderId=t,this.getLightsData(e.getBuiltinLights(),r.lightsData)),r.lightsData}needsRefresh(e,t){if(this.hasNode||this.hasAnimation||this.firstInitialization(e)||this.needsVelocity(t.renderer))return!0;let{renderId:r}=t;if(this.renderId!==r)return this.renderId=r,!0;let i=e.object.static===!0,s=e.bundle!==null&&e.bundle.static===!0&&this.getRenderObjectData(e).version===e.bundle.version;if(i||s)return!1;let o=this.getLights(e.lightsNode,r);return this.equals(e,o,r)!==!0}},Hu=Jg;var kE=[/^StackTrace\.js$/,/^TSLCore\.js$/,/^.*Node\.js$/,/^three\.webgpu.*\.js$/];function VE(n){let e=/(?:at\s+(.+?)\s+\()?(?:(.+?)@)?([^@\s()]+):(\d+):(\d+)/;return n.split(` | |
| `).map(t=>{let r=t.match(e);if(!r)return null;let i=r[1]||r[2]||"",s=r[3].split("?")[0],o=parseInt(r[4],10),a=parseInt(r[5],10),l=s.split("/").pop();return{fn:i,file:l,line:o,column:a}}).filter(t=>t&&!kE.some(r=>r.test(t.file)))}var ex=class{constructor(e=null){this.isStackTrace=!0,this.stack=VE(e||new Error().stack)}getLocation(){if(this.stack.length===0)return"[Unknown location]";let e=this.stack[0],t=e.fn;return`${t?`"${t}()" at `:""}"${e.file}:${e.line}"`}getError(e){if(this.stack.length===0)return e;let t=this.stack.map(r=>{let i=`${r.file}:${r.line}:${r.column}`;return r.fn?` at ${r.fn} (${i})`:` at ${i}`}).join(` | |
| `);return`${e} | |
| ${t}`}},tt=ex;function tx(n,e=0){let t=3735928559^e,r=1103547991^e;if(Array.isArray(n))for(let i=0,s;i<n.length;i++)s=n[i],t=Math.imul(t^s,2654435761),r=Math.imul(r^s,1597334677);else for(let i=0,s;i<n.length;i++)s=n.charCodeAt(i),t=Math.imul(t^s,2654435761),r=Math.imul(r^s,1597334677);return t=Math.imul(t^t>>>16,2246822507),t^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(t^t>>>13,3266489909),4294967296*(2097151&r)+(t>>>0)}var Ii=n=>tx(n),Ns=n=>tx(n),po=(...n)=>tx(n),GE=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),Qw=new WeakMap;function qu(n){return GE.get(n)}function ju(n){if(/[iu]?vec\d/.test(n))return n.startsWith("ivec")?Int32Array:n.startsWith("uvec")?Uint32Array:Float32Array;if(/mat\d/.test(n)||/float/.test(n))return Float32Array;if(/uint/.test(n))return Uint32Array;if(/int/.test(n))return Int32Array;throw new Error(`THREE.NodeUtils: Unsupported type: ${n}`)}function rx(n){if(/float|int|uint|bool/.test(n))return 1;if(/vec2/.test(n))return 2;if(/vec3/.test(n))return 3;if(/vec4/.test(n)||/mat2/.test(n))return 4;if(/mat3/.test(n))return 9;if(/mat4/.test(n))return 16;I(`TSL: Unsupported type: ${n}`,new tt)}function Zw(n){if(/float|int|uint|bool/.test(n))return 1;if(/vec2/.test(n))return 2;if(/vec3/.test(n))return 3;if(/vec4/.test(n)||/mat2/.test(n))return 4;if(/mat3/.test(n))return 12;if(/mat4/.test(n))return 16;I(`TSL: Unsupported type: ${n}`,new tt)}function Jw(n){if(/float|int|uint|bool/.test(n))return 1;if(/vec2/.test(n))return 2;if(/vec3/.test(n)||/vec4/.test(n))return 4;if(/mat2/.test(n))return 2;if(/mat3/.test(n)||/mat4/.test(n))return 4;I(`TSL: Unsupported type: ${n}`,new tt)}function Oi(n){if(n==null)return null;let e=typeof n;return n.isNode===!0?"node":e==="number"?"float":e==="boolean"?"bool":e==="string"?"string":e==="function"?"shader":n.isVector2===!0?"vec2":n.isVector3===!0?"vec3":n.isVector4===!0?"vec4":n.isMatrix2===!0?"mat2":n.isMatrix3===!0?"mat3":n.isMatrix4===!0?"mat4":n.isColor===!0?"color":n instanceof ArrayBuffer?"ArrayBuffer":null}function Kh(n){if(n.isDepthTexture===!0)return"float";let e=n.format,t;e===Bi||e===Fi||e===Mt||e===Ht||e===Xn?t=1:e===vt||e===Li?t=2:e===Ei||e===sl?t=3:t=4;let r;if(n.type===Ce?r="uint":n.type===Je?r="int":r="float",t===1)return r;let i=qu(t);return r!=="float"&&(i=r[0]+i),i}function Bl(n,...e){let t=n?n.slice(-4):void 0;return e.length===1&&(t==="vec2"?e=[e[0],e[0]]:t==="vec3"?e=[e[0],e[0],e[0]]:t==="vec4"&&(e=[e[0],e[0],e[0],e[0]])),n==="color"?new le(...e):t==="vec2"?new se(...e):t==="vec3"?new C(...e):t==="vec4"?new pe(...e):t==="mat2"?new El(...e):t==="mat3"?new et(...e):t==="mat4"?new ue(...e):n==="bool"?e[0]||!1:n==="float"||n==="int"||n==="uint"?e[0]||0:n==="string"?e[0]||"":n==="ArrayBuffer"?zE(e[0]):null}function Qh(n){let e=Qw.get(n);return e===void 0&&(e={},Qw.set(n,e)),e}function eM(n){let e="",t=new Uint8Array(n);for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return btoa(e)}function zE(n){return Uint8Array.from(atob(n),e=>e.charCodeAt(0)).buffer}var Ra={VERTEX:"vertex",FRAGMENT:"fragment"},J={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},WE={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},mt={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},tM=["fragment","vertex"],Xu=["setup","analyze","generate"],Yu=[...tM,"compute"],ki=["x","y","z","w"];var HE={analyze:"setup",generate:"analyze"},qE=0,Zh=class n extends bt{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=J.NONE,this.updateBeforeType=J.NONE,this.updateAfterType=J.NONE,this.version=0,this.name="",this.global=!1,this.parents=!1,this.isNode=!0,this._beforeNodes=null,this._cacheKey=null,this._uuid=null,this._cacheKeyVersion=0,this.id=qE++,this.stackTrace=null,n.captureStackTrace===!0&&(this.stackTrace=new tt)}set needsUpdate(e){e===!0&&this.version++}get uuid(){return this._uuid===null&&(this._uuid=Jd.generateUUID()),this._uuid}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,J.FRAME)}onRenderUpdate(e){return this.onUpdate(e,J.RENDER)}onObjectUpdate(e){return this.onUpdate(e,J.OBJECT)}onReference(e){return this.updateReference=e.bind(this),this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(let{childNode:e}of this._getChildren())yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(let t of this.getChildren())t.traverse(e)}_getChildren(e=new Set){let t=[];e.add(this);for(let r of Object.getOwnPropertyNames(this)){let i=this[r];if(!(r.startsWith("_")===!0||e.has(i))){if(Array.isArray(i)===!0)for(let s=0;s<i.length;s++){let o=i[s];o&&o.isNode===!0&&t.push({property:r,index:s,childNode:o})}else if(i&&i.isNode===!0)t.push({property:r,childNode:i});else if(i&&Object.getPrototypeOf(i)===Object.prototype)for(let s in i){if(s.startsWith("_")===!0)continue;let o=i[s];o&&o.isNode===!0&&t.push({property:r,index:s,childNode:o})}}}return t}getCacheKey(e=!1,t=null){if(e=e||this.version!==this._cacheKeyVersion,e===!0||this._cacheKey===null){t===null&&(t=new Set);let r=[];for(let{property:i,childNode:s}of this._getChildren(t))r.push(Ii(i.slice(0,-4)),s.getCacheKey(e,t));this._cacheKey=po(Ns(r),this.customCacheKey()),this._cacheKeyVersion=this.version}return this._cacheKey}customCacheKey(){return this.id}getScope(){return this}getHash(){return String(this.id)}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){let t=this.getNodeType(e);return e.getElementType(t)}getMemberType(){return"void"}getNodeType(e,t=null){let r=e.getDataFromNode(this),i;return t!==null?(r.typeFromOutput=r.typeFromOutput||{},i=r.typeFromOutput[t],i===void 0&&(i=this.generateNodeType(e,t),r.typeFromOutput[t]=i)):(i=r.type,i===void 0&&(i=this.generateNodeType(e),r.type=i)),i}generateNodeType(e,t=null){let r=e.getNodeProperties(this);return r.outputNode?r.outputNode.getNodeType(e,t):this.nodeType}getShared(e){let t=this.getHash(e),r=e.getNodeFromHash(t),i=null;if(r&&r!==this)i=r;else if(e.context.overrideNodes){let s=e.context.overrideNodes.get(this);if(s){let o=e.getDataFromNode(this);o.isOverwritten!==!0?(o.isOverwritten=!0,i=s(e).overrideNode(this,null),o.sharedNode=i):i=o.sharedNode}}return i||this}getArrayCount(){return null}setup(e){let t=e.getNodeProperties(this),r=0;for(let i of this.getChildren())t["node"+r++]=i;return t.outputNode||null}analyze(e,t=null){let r=e.increaseUsage(this);if(this.parents===!0){let i=e.getDataFromNode(this,"any");i.stages=i.stages||{},i.stages[e.shaderStage]=i.stages[e.shaderStage]||[],i.stages[e.shaderStage].push(t)}if(r===1){let i=e.getNodeProperties(this);for(let s of Object.values(i))s&&s.isNode===!0&&s.build(e,this)}}generate(e,t){let{outputNode:r}=e.getNodeProperties(this);if(r&&r.isNode===!0)return r.build(e,t)}updateBefore(){U("Abstract function.")}updateAfter(){U("Abstract function.")}update(){U("Abstract function.")}before(e){return this._beforeNodes===null&&(this._beforeNodes=[]),this._beforeNodes.push(e),this}build(e,t=null){let r=this.getShared(e);if(this!==r)return r.build(e,t);if(this._beforeNodes!==null){let l=this._beforeNodes;this._beforeNodes=null;for(let u of l)u.build(e,t);this._beforeNodes=l}let i=e.getDataFromNode(this);i.buildStages=i.buildStages||{},i.buildStages[e.buildStage]=!0;let s=HE[e.buildStage];if(s&&i.buildStages[s]!==!0){let l=e.getBuildStage();e.setBuildStage(s),this.build(e),e.setBuildStage(l)}e.addChain(this);let o=null,a=e.getBuildStage();if(a==="setup"){e.addNode(this),this.updateReference(e);let l=e.getNodeProperties(this);if(l.initialized!==!0){l.initialized=!0,l.outputNode=this.setup(e)||l.outputNode||null;for(let u of Object.values(l))if(u&&u.isNode===!0){if(u.parents===!0){let c=e.getNodeProperties(u);c.parents=c.parents||[],c.parents.push(this)}u.build(e)}e.addSequentialNode(this)}o=l.outputNode}else if(a==="analyze")this.analyze(e,t);else if(a==="generate"){if(this.generate.length<2){let u=this.getNodeType(e),c=e.getDataFromNode(this);o=c.snippet,o===void 0?c.generated===void 0?(c.generated=!0,o=this.generate(e)||"",c.snippet=o):(U("Node: Recursion detected.",this),o="/* Recursion detected. */"):c.flowCodes!==void 0&&e.context.nodeBlock!==void 0&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),o=e.format(o,u,t)}else o=this.generate(e,t)||"";o===""&&t!==null&&t!=="void"&&t!=="OutputType"&&(I(`TSL: Invalid generated code, expected a "${t}".`),o=e.generateConst(t))}return e.removeChain(this),o}getSerializeChildren(){return this._getChildren()}serialize(e){let t=this.getSerializeChildren(),r={};for(let{property:i,index:s,childNode:o}of t)s!==void 0?(r[i]===void 0&&(r[i]=Number.isInteger(s)?[]:{}),r[i][s]=o.toJSON(e.meta).uuid):r[i]=o.toJSON(e.meta).uuid;Object.keys(r).length>0&&(e.inputNodes=r)}deserialize(e){if(e.inputNodes!==void 0){let t=e.meta.nodes;for(let r in e.inputNodes)if(Array.isArray(e.inputNodes[r])){let i=[];for(let s of e.inputNodes[r])i.push(t[s]);this[r]=i}else if(typeof e.inputNodes[r]=="object"){let i={};for(let s in e.inputNodes[r]){let o=e.inputNodes[r][s];i[s]=t[o]}this[r]=i}else{let i=e.inputNodes[r];this[r]=t[i]}}}toJSON(e){let{uuid:t,type:r}=this,i=e===void 0||typeof e=="string";i&&(e={textures:{},images:{},nodes:{}});let s=e.nodes[t];s===void 0&&(s={uuid:t,type:r,meta:e,metadata:{version:4.7,type:"Node",generator:"Node.toJSON"}},i!==!0&&(e.nodes[s.uuid]=s),this.serialize(s),delete s.meta);function o(a){let l=[];for(let u in a){let c=a[u];delete c.metadata,l.push(c)}return l}if(i){let a=o(e.textures),l=o(e.images),u=o(e.nodes);a.length>0&&(s.textures=a),l.length>0&&(s.images=l),u.length>0&&(s.nodes=u)}return s}};Zh.captureStackTrace=!1;var W=Zh;var ix=class extends W{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}generateNodeType(e){return this.node.getElementType(e)}getMemberType(e,t){return this.node.getMemberType(e,t)}generate(e){let t=this.indexNode.getNodeType(e),r=this.node.build(e),i=this.indexNode.build(e,!e.isVector(t)&&e.isInteger(t)?t:"uint");return`${r}[ ${i} ]`}},ri=ix;var sx=class extends W{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}generateNodeType(e){let t=this.node.getNodeType(e),r=null;for(let i of this.convertTo.split("|"))(r===null||e.getTypeLength(t)===e.getTypeLength(i))&&(r=i);return r}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){let r=this.node,i=this.getNodeType(e),s=r.build(e,i);return e.format(s,i,t)}},Jh=sx;var nx=class extends W{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(e.getBuildStage()==="generate"){let i=e.getVectorType(this.getNodeType(e,t)),s=e.getDataFromNode(this);if(s.propertyName!==void 0)return e.format(s.propertyName,i,t);if(i!=="void"&&t!=="void"&&this.hasDependencies(e)){let o=super.build(e,i),a=e.getVarFromNode(this,null,i),l=e.getPropertyName(a);return e.addLineFlowCode(`${l} = ${o}`,this),s.snippet=o,s.propertyName=l,e.format(s.propertyName,i,t)}}return super.build(e,t)}},_e=nx;var ox=class extends _e{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}generateNodeType(e){return this.nodeType!==null?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce((t,r)=>t+e.getTypeLength(r.getNodeType(e)),0))}generate(e,t){let r=this.getNodeType(e),i=e.getTypeLength(r),s=this.nodes,o=e.getComponentType(r),a=[],l=0;for(let c of s){if(l>=i){I(`TSL: Length of parameters exceeds maximum length of function '${r}()' type.`,this.stackTrace);break}let d=c.getNodeType(e),h=e.getTypeLength(d),p;if(l+h>i&&(I(`TSL: Length of '${r}()' data exceeds maximum length of output type.`,this.stackTrace),h=i-l,d=e.getTypeFromLength(h)),l+=h,p=c.build(e,d),e.getComponentType(d)!==o){let m=e.getTypeFromLength(h,o);p=e.format(p,d,m)}a.push(p)}let u=`${e.getType(r)}( ${a.join(", ")} )`;return e.format(u,r,t)}},ax=ox;var jE=ki.join(""),lx=class extends W{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(let t of this.components)e=Math.max(ki.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}generateNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}getScope(){return this.node.getScope()}generate(e,t){let r=this.node,i=e.getTypeLength(r.getNodeType(e)),s=null;if(i>1){let o=null;this.getVectorLength()>=i&&(o=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));let l=r.build(e,o);this.components.length===i&&this.components===jE.slice(0,this.components.length)?s=e.format(l,o,t):s=e.format(`${l}.${this.components}`,this.getNodeType(e),t)}else s=r.build(e,t);return s}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}},ep=lx;var ux=class extends _e{static get type(){return"SetNode"}constructor(e,t,r){super(),this.sourceNode=e,this.components=t,this.targetNode=r}generateNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){let{sourceNode:t,components:r,targetNode:i}=this,s=this.getNodeType(e),o=e.getComponentType(i.getNodeType(e)),a=e.getTypeFromLength(r.length,o),l=i.build(e,a),u=t.build(e,s),c=e.getTypeLength(s),d=[];for(let h=0;h<c;h++){let p=ki[h];p===r[0]?(d.push(l),h+=r.length-1):d.push(u+"."+p)}return`${e.getType(s)}( ${d.join(", ")} )`}},cx=ux;var dx=class extends _e{static get type(){return"FlipNode"}constructor(e,t){super(),this.sourceNode=e,this.components=t}generateNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){let{components:t,sourceNode:r}=this,i=this.getNodeType(e),s=r.build(e),o=e.getVarFromNode(this),a=e.getPropertyName(o);e.addLineFlowCode(a+" = "+s,this);let l=e.getTypeLength(i),u=[],c=0;for(let d=0;d<l;d++){let h=ki[d];h===t[c]?(u.push("1.0 - "+(a+"."+h)),c++):u.push(a+"."+h)}return`${e.getType(i)}( ${u.join(", ")} )`}},hx=dx;var px=class extends W{static get type(){return"InputNode"}constructor(e,t=null){super(t),this.isInputNode=!0,this.value=e,this.precision=null}generateNodeType(){return this.nodeType===null?Oi(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=Oi(this.value),e.nodeType=this.nodeType,e.valueType==="ArrayBuffer"&&(e.value=eM(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?Bl(e.valueType,...e.value):e.value,this.precision=e.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(e.value))}generate(){U("Abstract function.")}},Ca=px;var rM=/float|u?int/,fx=class extends Ca{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){let r=this.getNodeType(e);return rM.test(r)&&rM.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),r,t)}},Vi=fx;var mx=class extends W{static get type(){return"MemberNode"}constructor(e,t){super(),this.structNode=e,this.property=t,this.isMemberNode=!0}hasMember(e){return this.structNode.isMemberNode&&this.structNode.hasMember(e)===!1?!1:this.structNode.getMemberType(e,this.property)!=="void"}generateNodeType(e){return this.hasMember(e)===!1?"float":this.structNode.getMemberType(e,this.property)}getMemberType(e,t){if(this.hasMember(e)===!1)return"float";let r=this.getNodeType(e);return e.getStructTypeNode(r).getMemberType(e,t)}generate(e){if(this.hasMember(e)===!1){U(`TSL: Member "${this.property}" does not exist in struct.`,this.stackTrace);let r=this.getNodeType(e);return e.generateConst(r)}return this.structNode.build(e)+"."+this.property}},gx=mx;var Tn=null,xx=new Map;function P(n,e){if(xx.has(n)){U(`TSL: Redefinition of method chaining '${n}'.`);return}if(typeof e!="function")throw new Error(`THREE.TSL: Node element ${n} is not a function`);xx.set(n,e),n!=="assign"&&(W.prototype[n]=function(...t){return this.isStackNode?this.addToStack(e(...t)):e(this,...t)},W.prototype[n+"Assign"]=function(...t){return this.isStackNode?this.assign(t[0],e(...t)):this.assign(e(this,...t))})}var XE=n=>n.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),iM=n=>XE(n).split("").sort().join("");W.prototype.assign=function(...n){if(this.isStackNode!==!0)return Tn!==null?Tn.assign(this,...n):I("TSL: No stack defined for assign operation. Make sure the assign is inside a Fn().",new tt),this;{let e=xx.get("assign");return this.addToStack(e(...n))}};W.prototype.toVarIntent=function(){return this};W.prototype.get=function(n){return new gx(this,n)};var Qu={};function tp(n,e,t){Qu[n]=Qu[e]=Qu[t]={get(){this._cache=this._cache||{};let o=this._cache[n];return o===void 0&&(o=new ep(this,n),this._cache[n]=o),o},set(o){this[n].assign(j(o))}};let r=n.toUpperCase(),i=e.toUpperCase(),s=t.toUpperCase();W.prototype["set"+r]=W.prototype["set"+i]=W.prototype["set"+s]=function(o){let a=iM(n);return new cx(this,a,j(o))},W.prototype["flip"+r]=W.prototype["flip"+i]=W.prototype["flip"+s]=function(){let o=iM(n);return new hx(this,o)}}var ws=["x","y","z","w"],Ms=["r","g","b","a"],vs=["s","t","p","q"];for(let n=0;n<4;n++){let e=ws[n],t=Ms[n],r=vs[n];tp(e,t,r);for(let i=0;i<4;i++){e=ws[n]+ws[i],t=Ms[n]+Ms[i],r=vs[n]+vs[i],tp(e,t,r);for(let s=0;s<4;s++){e=ws[n]+ws[i]+ws[s],t=Ms[n]+Ms[i]+Ms[s],r=vs[n]+vs[i]+vs[s],tp(e,t,r);for(let o=0;o<4;o++)e=ws[n]+ws[i]+ws[s]+ws[o],t=Ms[n]+Ms[i]+Ms[s]+Ms[o],r=vs[n]+vs[i]+vs[s]+vs[o],tp(e,t,r)}}}for(let n=0;n<32;n++)Qu[n]={get(){this._cache=this._cache||{};let e=this._cache[n];return e===void 0&&(e=new ri(this,new Vi(n,"uint")),this._cache[n]=e),e},set(e){this[n].assign(j(e))}};Object.defineProperties(W.prototype,Qu);var YE=function(n,e=null){let t=Oi(n);return t==="node"?n:e===null&&(t==="float"||t==="boolean")||t&&t!=="shader"&&t!=="string"?j(_x(n,e)):t==="shader"?n.isFn?n:_(n):n},KE=function(n,e=null){for(let t in n)n[t]=j(n[t],e);return n},QE=function(n,e=null){let t=n.length;for(let r=0;r<t;r++)n[r]=j(n[r],e);return n},nM=function(n,e=null,t=null,r=null){function i(c){return r!==null?(c=j(Object.assign(c,r)),r.intent===!0&&(c=c.toVarIntent())):c=j(c),c}let s,o=e,a,l;function u(c){let d;return o?d=/[a-z]/i.test(o)?o+"()":o:d=n.type,a!==void 0&&c.length<a?(I(`TSL: "${d}" parameter length is less than minimum required.`,new tt),c.concat(new Array(a-c.length).fill(0))):l!==void 0&&c.length>l?(I(`TSL: "${d}" parameter length exceeds limit.`,new tt),c.slice(0,l)):c}return e===null?s=(...c)=>i(new n(..._n(u(c)))):t!==null?(t=j(t),s=(...c)=>i(new n(e,..._n(u(c)),t))):s=(...c)=>i(new n(e,..._n(u(c)))),s.setParameterLength=(...c)=>(c.length===1?a=l=c[0]:c.length===2&&([a,l]=c),s),s.setName=c=>(o=c,s),s},ZE=function(n,...e){return new n(..._n(e))},yx=class extends W{constructor(e,t){super(),this.shaderNode=e,this.rawInputs=t,this.isShaderCallNodeInternal=!0}generateNodeType(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){let{shaderNode:t,rawInputs:r}=this,i=e.getNodeProperties(t),s=e.getClosestSubBuild(t.subBuilds)||"",o=s||"default";if(i[o])return i[o];let a=e.subBuildFn,l=e.fnCall;e.subBuildFn=s,e.fnCall=this;let u=null;if(t.layout){if(r){let h=t.layout.inputs;if(oM(r)){let p=r;for(let f=0;f<h.length;f++){let m=p[f];m&&m.isNode&&m.build(e)}}else{let p=r[0];for(let f of h){let m=p[f.name];m&&m.isNode&&m.build(e)}}}let c=e.buildFunctionNode(t);e.addInclude(c);let d=r?JE(r):null;u=c.call(d)}else{let c=new Proxy(e,{get:(m,g,x)=>{let w;return Symbol.iterator===g?w=function*(){yield void 0}:w=Reflect.get(m,g,x),w}}),d=r?eB(r):null,h=Array.isArray(r)?r.length>0:r!==null,p=t.jsFunc,f=h||p.length>1?p(d,c):p(c);u=j(f)}return e.subBuildFn=a,e.fnCall=l,t.once&&(i[o]=u),u}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}getOutputNode(e){let 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,i=e.getBuildStage(),s=e.getNodeProperties(this),o=e.getSubBuildOutput(this),a=this.getOutputNode(e),l=e.fnCall;if(e.fnCall=this,i==="setup"){let u=e.getSubBuildProperty("initialized",this);if(s[u]!==!0&&(s[u]=!0,s[o]=this.getOutputNode(e),s[o].build(e),this.shaderNode.subBuilds))for(let c of e.chaining){let d=e.getDataFromNode(c,"any");d.subBuilds=d.subBuilds||new Set;for(let h of this.shaderNode.subBuilds)d.subBuilds.add(h)}r=s[o]}else i==="analyze"?a.build(e,t):i==="generate"&&(r=a.build(e,t)||"");return e.fnCall=l,r}};function oM(n){return n[0]&&(n[0].isNode||Object.getPrototypeOf(n[0])!==Object.prototype)}function JE(n){let e;return Zu(n),oM(n)?e=[...n]:e=n[0],e}function eB(n){let e=0;return Zu(n),new Proxy(n,{get:(t,r,i)=>{let s;if(r==="length")return s=n.length,s;if(Symbol.iterator===r)s=function*(){for(let o of n)yield j(o)};else{if(n.length>0)if(Object.getPrototypeOf(n[0])===Object.prototype){let o=n[0];o[r]===void 0?s=o[e++]:s=Reflect.get(o,r,i)}else n[0]instanceof W&&(n[r]===void 0?s=n[e++]:s=Reflect.get(n,r,i));else s=Reflect.get(t,r,i);s=j(s)}return s}})}var bx=class extends W{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 yx(this,e)}setup(){return this.call()}},tB=[!1,!0],rB=[0,1,2,3],iB=[-1,-2],aM=[.5,1.5,1/3,1e-6,1e6,Math.PI,Math.PI*2,1/Math.PI,2/Math.PI,1/(Math.PI*2),Math.PI/2],Sx=new Map;for(let n of tB)Sx.set(n,new Vi(n));var Nx=new Map;for(let n of rB)Nx.set(n,new Vi(n,"uint"));var wx=new Map([...Nx].map(n=>new Vi(n.value,"int")));for(let n of iB)wx.set(n,new Vi(n,"int"));var rp=new Map([...wx].map(n=>new Vi(n.value)));for(let n of aM)rp.set(n,new Vi(n));for(let n of aM)rp.set(-n,new Vi(-n));var ip={bool:Sx,uint:Nx,ints:wx,float:rp},sM=new Map([...Sx,...rp]),_x=(n,e)=>sM.has(n)?sM.get(n):n.isNode===!0?n:new Vi(n,e),It=function(n,e=null){return(...t)=>{for(let i of t)if(i===void 0)return I(`TSL: Invalid parameter for the type "${n}".`,new tt),new Vi(0,n);if((t.length===0||!["bool","float","int","uint"].includes(n)&&t.every(i=>{let s=typeof i;return s!=="object"&&s!=="function"}))&&(t=[Bl(n,...t)]),t.length===1&&e!==null&&e.has(t[0]))return Ku(e.get(t[0]));if(t.length===1){let i=_x(t[0],n);return i.nodeType===n?Ku(i):Ku(new Jh(i,n))}let r=t.map(i=>_x(i));return Ku(new ax(r,n))}};function Sn(n){return n&&n.isNode&&n.traverse(e=>{e.isConstNode&&(n=e.value)}),!!n}var Mx=n=>n!=null?n.nodeType||n.convertTo||(typeof n=="string"?n:null):null;function Ea(n,e){return new bx(n,e)}var j=(n,e=null)=>YE(n,e),Ku=(n,e=null)=>j(n,e).toVarIntent(),Zu=(n,e=null)=>new KE(n,e),_n=(n,e=null)=>new QE(n,e),te=(n,e=null,t=null,r=null)=>new nM(n,e,t,r),q=(n,...e)=>new ZE(n,...e),G=(n,e=null,t=null,r={})=>new nM(n,e,t,{...r,intent:!0}),Ju=(n,e)=>new Proxy(n,{get(t,r,i){return Reflect.get(e,r,i)},set(t,r,i){return Reflect.set(e,r,i)}}),sB=0,Tx=class extends W{constructor(e,t=null){super();let r=null;t!==null&&(typeof t=="object"?r=t.return:(typeof t=="string"?r=t:I("TSL: Invalid layout type.",new tt),t=null)),this.shaderNode=new Ea(e,r),t!==null&&this.setLayout(t),this.isFn=!0}setLayout(e){let t=this.shaderNode.nodeType;if(typeof e.inputs!="object"){let r={name:"fn"+sB++,type:t,inputs:[]};for(let i in e)i!=="return"&&r.inputs.push({name:i,type:e[i]});e=r}return this.shaderNode.setLayout(e),this}generateNodeType(e){return this.shaderNode.getNodeType(e)||"float"}call(...e){let t=this.shaderNode.call(e);return this.shaderNode.nodeType==="void"&&t.toStack(),t.toVarIntent()}once(e=null){return this.shaderNode.once=!0,this.shaderNode.subBuilds=e,this}generate(e){let t=this.getNodeType(e);return I('TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".',this.stackTrace),e.generateConst(t)}};function _(n,e=null){let t=new Tx(n,e);return new Proxy(()=>{},{apply(r,i,s){return t.call(...s)},get(r,i,s){return Reflect.get(t,i,s)},set(r,i,s,o){return Reflect.set(t,i,s,o)}})}var Ba=n=>{Tn=n},ec=()=>Tn,ie=(...n)=>Tn.If(...n),nB=(...n)=>Tn.Switch(...n);function lM(n){return Tn&&Tn.addToStack(n),n}P("toStack",lM);var uM=new It("color"),y=new It("float",ip.float),A=new It("int",ip.ints),k=new It("uint",ip.uint),nr=new It("bool",ip.bool),V=new It("vec2"),dt=new It("ivec2"),sp=new It("uvec2"),cM=new It("bvec2"),N=new It("vec3"),np=new It("ivec3"),Nn=new It("uvec3"),op=new It("bvec3"),X=new It("vec4"),ap=new It("ivec4"),lp=new It("uvec4"),dM=new It("bvec4"),Fl=new It("mat2"),rt=new It("mat3"),Gi=new It("mat4");P("toColor",uM);P("toFloat",y);P("toInt",A);P("toUint",k);P("toBool",nr);P("toVec2",V);P("toIVec2",dt);P("toUVec2",sp);P("toBVec2",cM);P("toVec3",N);P("toIVec3",np);P("toUVec3",Nn);P("toBVec3",op);P("toVec4",X);P("toIVec4",ap);P("toUVec4",lp);P("toBVec4",dM);P("toMat2",Fl);P("toMat3",rt);P("toMat4",Gi);var hM=te(ri).setParameterLength(2),pM=(n,e)=>new Jh(j(n),e),oB=(n,e)=>new ep(j(n),e);P("element",hM);P("convert",pM);var Fe=class extends W{static get type(){return"PropertyNode"}constructor(e,t=null,r=!1,i=null){super(e),this.name=t,this.varying=r,this.placeholderNode=j(i),this.isPropertyNode=!0,this.global=!0}getNodeType(e){let t=super.getNodeType(e);return t==="output"?e.getOutputType():t}customCacheKey(){return Ii(this.type+":"+(this.name||"")+":"+(this.varying?"1":"0"))}getHash(e){return this.name||super.getHash(e)}generate(e){let t;if(this.varying===!0)t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0;else if(t=e.getVarFromNode(this,this.name),this.placeholderNode!==null&&e.hasWriteUsage(this)===!1){let r=this.placeholderNode.build(e,this.getNodeType(e));e.addLineFlowCode(`${e.getPropertyName(t)} = ${r}`,this)}return e.getPropertyName(t)}},vx=Fe,wn=(n,e,t=null)=>new Fe(n,e,!1,t),tc=(n,e,t=null)=>new Fe(n,e,!0,t),ve=q(Fe,"vec4","DiffuseColor"),Mn=q(Fe,"vec3","DiffuseContribution"),up=q(Fe,"vec3","EmissiveColor"),Sr=q(Fe,"float","Roughness"),ss=q(Fe,"float","Metalness"),Ll=q(Fe,"float","Clearcoat"),vn=q(Fe,"float","ClearcoatRoughness"),or=q(Fe,"vec3","Sheen"),ns=q(Fe,"float","SheenRoughness"),Fa=q(Fe,"float","Iridescence"),Pl=q(Fe,"float","IridescenceIOR"),Dl=q(Fe,"float","IridescenceThickness"),Ul=q(Fe,"float","AlphaT"),As=q(Fe,"float","Anisotropy"),La=q(Fe,"vec3","AnisotropyT"),Rs=q(Fe,"vec3","AnisotropyB"),Nr=q(Fe,"color","SpecularColor"),zi=q(Fe,"color","SpecularColorBlended"),fi=q(Fe,"float","SpecularF90"),Il=q(Fe,"float","Shininess"),fo=q(Fe,"output","Output"),rc=q(Fe,"float","dashSize"),cp=q(Fe,"float","gapSize"),aB=q(Fe,"float","pointWidth"),Pa=q(Fe,"float","IOR"),Ol=q(Fe,"float","Transmission"),ic=q(Fe,"float","Thickness"),sc=q(Fe,"float","AttenuationDistance"),nc=q(Fe,"color","AttenuationColor"),oc=q(Fe,"float","Dispersion"),kl=q(Fe,"float","Retroreflective"),dp=q(Fe,"float","AmbientOcclusion",!1,1);var hp=class extends W{static get type(){return"UniformGroupNode"}constructor(e,t=!1,r=1,i=null){super("string"),this.name=e,this.shared=t,this.order=r,this.updateType=i,this.isUniformGroup=!0}update(){this.needsUpdate=!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}};var fM=(n,e=1,t=null)=>new hp(n,!1,e,t),ac=(n,e=0,t=null)=>new hp(n,!0,e,t),lB=ac("frame",0,J.FRAME),ee=ac("render",0,J.RENDER),Ax=fM("object",1,J.OBJECT);var pp=class extends Ca{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Ax}setName(e){return this.name=e,this}label(e){return U('TSL: "label()" has been deprecated. Use "setName()" instead.',new tt),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(r=>{let i=e(r,this);i!==void 0&&(this.value=i)},t)}getInputType(e){let t=super.getInputType(e);return t==="bool"&&(t="uint"),t}generate(e,t){let r=this.getNodeType(e),i=this.getUniformHash(e),s=e.getNodeFromHash(i);s===void 0&&(e.setHashNode(this,i),s=this);let o=s.getInputType(e),a=e.getUniformFromNode(s,o,e.shaderStage,this.name||e.context.nodeName),l=e.getPropertyName(a);e.context.nodeName!==void 0&&delete e.context.nodeName;let u=l;if(r==="bool"){let c=e.getDataFromNode(this),d=c.propertyName;if(d===void 0){let h=e.getVarFromNode(this,null,"bool");d=e.getPropertyName(h),c.propertyName=d,u=e.format(l,o,r),e.addLineFlowCode(`${d} = ${u}`,this)}u=d}return e.format(u,r,t)}},An=pp,Y=(n,e)=>{let t=Mx(e||n);if(t===n&&(n=Bl(t)),n&&n.isNode===!0){let r=n.value;n.traverse(i=>{i.isConstNode===!0&&(r=i.value)}),n=r}return new pp(n,t)};var fp=class extends _e{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}generateNodeType(e){return this.nodeType===null?this.values[0].getNodeType(e):this.nodeType}getElementType(e){return this.getNodeType(e)}getMemberType(e,t){return this.nodeType===null?this.values[0].getMemberType(e,t):super.getMemberType(e,t)}generate(e){let t=this.getNodeType(e);return e.generateArray(t,this.count,this.values)}};var lc=(...n)=>{let e;if(n.length===1){let t=n[0].map(r=>j(r));e=new fp(null,t.length,t)}else{let t=n[0],r=n[1];e=new fp(t,r)}return e};P("toArray",(n,e)=>lc(Array(e).fill(n)));var Rx=class extends _e{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t,this.isAssignNode=!0}hasDependencies(){return!1}generateNodeType(e,t){return t!=="void"?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){let{targetNode:t}=this;if(e.isAvailable("swizzleAssign")===!1&&t.isSplitNode&&t.components.length>1){let r=e.getTypeLength(t.node.getNodeType(e));return ki.join("").slice(0,r)!==t.components}return!1}setup(e){let{targetNode:t,sourceNode:r}=this,i=t.getScope(),s=e.getDataFromNode(i);s.assign=!0;let o=e.getNodeProperties(this);o.sourceNode=r,o.targetNode=t.context({assign:!0})}generate(e,t){let{targetNode:r,sourceNode:i}=e.getNodeProperties(this),s=this.needsSplitAssign(e),o=r.build(e),a=r.getNodeType(e),l=i.build(e,a),u=i.getNodeType(e),c=e.getDataFromNode(this),d;if(c.initialized===!0)t!=="void"&&(d=o);else if(s){let h=e.getVarFromNode(this,null,a),p=e.getPropertyName(h);e.addLineFlowCode(`${p} = ${l}`,this);let f=r.node,g=f.node.context({assign:!0}).build(e);for(let x=0;x<f.components.length;x++){let w=f.components[x];e.addLineFlowCode(`${g}.${w} = ${p}[ ${x} ]`,this)}t!=="void"&&(d=o)}else d=`${o} = ${l}`,(t==="void"||u==="void")&&(e.addLineFlowCode(d,this),t!=="void"&&(d=o));return c.initialized=!0,e.format(d,a,t)}};var mM=te(Rx).setParameterLength(2);P("assign",mM);var Cx=class extends _e{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}generateNodeType(e){return this.functionNode.getNodeType(e)}getMemberType(e,t){return this.functionNode.getMemberType(e,t)}generate(e){let t=[],r=this.functionNode,i=r.getInputs(e),s=this.parameters,o=(l,u)=>{let c=u.type,d=c==="pointer",h;return d?h="&"+l.build(e):h=l.build(e,c),h};if(Array.isArray(s)){if(s.length>i.length)I("TSL: The number of provided parameters exceeds the expected number of inputs in 'Fn()'."),s.length=i.length;else if(s.length<i.length)for(I("TSL: The number of provided parameters is less than the expected number of inputs in 'Fn()'.");s.length<i.length;)s.push(y(0));for(let l=0;l<s.length;l++)t.push(o(s[l],i[l]))}else for(let l of i){let u=s[l.name];u!==void 0?t.push(o(u,l)):(I(`TSL: Input '${l.name}' not found in 'Fn()'.`),t.push(o(y(0),l)))}return`${r.build(e,"property")}( ${t.join(", ")} )`}};var gM=(n,...e)=>(e=e.length>1||e[0]&&e[0].isNode===!0?_n(e):Zu(e[0]),new Cx(j(n),e));P("call",gM);var uB={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"},gt=class n extends _e{static get type(){return"OperatorNode"}constructor(e,t,r,...i){if(super(),i.length>0){let s=new n(e,t,r);for(let o=0;o<i.length-1;o++)s=new n(e,s,i[o]);t=s,r=i[i.length-1]}this.op=e,this.aNode=t,this.bNode=r,this.isOperatorNode=!0}getOperatorMethod(e,t){return e.getMethod(uB[this.op],t)}generateNodeType(e,t=null){let r=this.op,i=this.aNode,s=this.bNode,o=i.getNodeType(e),a=s?s.getNodeType(e):null;if(o==="void"||a==="void")return t||"void";if(r==="%")return o;if(r==="~"||r==="&"||r==="|"||r==="^"||r===">>"||r==="<<")return e.getIntegerType(o);if(r==="&&"||r==="||"||r==="^^")return"bool";if(r==="!"){let l=e.getTypeLength(o);return l>1?`bvec${l}`:"bool"}else if(r==="=="||r==="!="||r==="<"||r===">"||r==="<="||r===">="){let l=Math.max(e.getTypeLength(o),e.getTypeLength(a));return l>1?`bvec${l}`:"bool"}else{if(e.isMatrix(o)){if(a==="float")return o;if(e.isVector(a))return e.getVectorFromMatrix(o);if(e.isMatrix(a))return o}else if(e.isMatrix(a)){if(o==="float")return a;if(e.isVector(o))return e.getVectorFromMatrix(a)}return e.getTypeLength(a)>e.getTypeLength(o)?a:o}}generate(e,t){let r=this.op,{aNode:i,bNode:s}=this,o=this.getNodeType(e,t),a=null,l=null;o!=="void"?(a=i.getNodeType(e),l=s?s.getNodeType(e):null,r==="<"||r===">"||r==="<="||r===">="||r==="=="||r==="!="?e.isVector(a)?l=a:e.isVector(l)?a=l:a!==l&&(a=l="float"):r===">>"||r==="<<"?(a=o,l=e.changeComponentType(l,"uint")):r==="%"?(a=o,l=e.isInteger(a)&&e.isInteger(l)?l:a):e.isMatrix(a)?l==="float"?l="float":e.isVector(l)?l=e.getVectorFromMatrix(a):e.isMatrix(l)||(a=l=o):e.isMatrix(l)?a==="float"?a="float":e.isVector(a)?a=e.getVectorFromMatrix(l):a=l=o:a=l=o):a=l=o;let u=i.build(e,a),c=s?s.build(e,l):null,d=e.getFunctionOperator(r);if(t!=="void"){let h=e.renderer.coordinateSystem===At;if(r==="=="||r==="!="||r==="<"||r===">"||r==="<="||r===">=")return h?e.isVector(a)?e.format(`${this.getOperatorMethod(e,t)}( ${u}, ${c} )`,o,t):e.format(`( ${u} ${r} ${c} )`,o,t):e.format(`( ${u} ${r} ${c} )`,o,t);if(r==="%")return e.isInteger(l)?e.format(`( ${u} % ${c} )`,o,t):e.format(`${this.getOperatorMethod(e,o)}( ${u}, ${c} )`,o,t);if(r==="!")return h&&e.isVector(a)?e.format(`not( ${u} )`,t):e.format(`( ${r} ${u} )`,a,t);if(r==="~")return e.format(`( ${r} ${u} )`,a,t);if(d)return e.format(`${d}( ${u}, ${c} )`,o,t);if(e.isMatrix(a)&&l==="float")return e.format(`( ${c} ${r} ${u} )`,o,t);if(a==="float"&&e.isMatrix(l))return e.format(`${u} ${r} ${c}`,o,t);{let p=`( ${u} ${r} ${c} )`;return!h&&o==="bool"&&e.isVector(a)&&e.isVector(l)&&(p=`all${p}`),e.format(p,o,t)}}else if(a!=="void")return d?e.format(`${d}( ${u}, ${c} )`,o,t):e.isMatrix(a)&&l==="float"?e.format(`${c} ${r} ${u}`,o,t):e.format(`${u} ${r} ${c}`,o,t)}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}};var Xe=G(gt,"+").setParameterLength(2,1/0).setName("add"),Se=G(gt,"-").setParameterLength(2,1/0).setName("sub"),ce=G(gt,"*").setParameterLength(2,1/0).setName("mul"),xt=G(gt,"/").setParameterLength(2,1/0).setName("div"),Vl=G(gt,"%").setParameterLength(2).setName("mod"),xM=G(gt,"==").setParameterLength(2).setName("equal"),yM=G(gt,"!=").setParameterLength(2).setName("notEqual"),bM=G(gt,"<").setParameterLength(2).setName("lessThan"),mp=G(gt,">").setParameterLength(2).setName("greaterThan"),_M=G(gt,"<=").setParameterLength(2).setName("lessThanEqual"),TM=G(gt,">=").setParameterLength(2).setName("greaterThanEqual"),SM=G(gt,"&&").setParameterLength(2,1/0).setName("and"),NM=G(gt,"||").setParameterLength(2,1/0).setName("or"),wM=G(gt,"!").setParameterLength(1).setName("not"),MM=G(gt,"^^").setParameterLength(2).setName("xor"),vM=G(gt,"&").setParameterLength(2).setName("bitAnd"),AM=G(gt,"~").setParameterLength(1).setName("bitNot"),RM=G(gt,"|").setParameterLength(2).setName("bitOr"),CM=G(gt,"^").setParameterLength(2).setName("bitXor"),EM=G(gt,"<<").setParameterLength(2).setName("shiftLeft"),BM=G(gt,">>").setParameterLength(2).setName("shiftRight"),FM=_(([n])=>(n.addAssign(1),n)),LM=_(([n])=>(n.subAssign(1),n)),PM=_(([n])=>{let e=A(n).toConst();return n.addAssign(1),e}),DM=_(([n])=>{let e=A(n).toConst();return n.subAssign(1),e});P("add",Xe);P("sub",Se);P("mul",ce);P("div",xt);P("mod",Vl);P("equal",xM);P("notEqual",yM);P("lessThan",bM);P("greaterThan",mp);P("lessThanEqual",_M);P("greaterThanEqual",TM);P("and",SM);P("or",NM);P("not",wM);P("xor",MM);P("bitAnd",vM);P("bitNot",AM);P("bitOr",RM);P("bitXor",CM);P("shiftLeft",EM);P("shiftRight",BM);P("incrementBefore",FM);P("decrementBefore",LM);P("increment",PM);P("decrement",DM);var L=class n extends _e{static get type(){return"MathNode"}constructor(e,t,r=null,i=null){if(super(),(e===n.MAX||e===n.MIN)&&arguments.length>3){let s=new n(e,t,r);for(let o=3;o<arguments.length-1;o++)s=new n(e,s,arguments[o]);t=s,r=arguments[arguments.length-1],i=null}this.method=e,this.aNode=t,this.bNode=r,this.cNode=i,this.isMathNode=!0}getInputType(e){let t=this.aNode.getNodeType(e),r=this.bNode?this.bNode.getNodeType(e):null,i=this.cNode?this.cNode.getNodeType(e):null,s=e.isMatrix(t)?0:e.getTypeLength(t),o=e.isMatrix(r)?0:e.getTypeLength(r),a=e.isMatrix(i)?0:e.getTypeLength(i);return s>o&&s>a?t:o>a?r:a>s?i:t}generateNodeType(e){let t=this.method;return t===n.LENGTH||t===n.DISTANCE||t===n.DOT?"float":t===n.CROSS?"vec3":t===n.ALL||t===n.ANY?"bool":t===n.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):this.getInputType(e)}setup(e){let{aNode:t,bNode:r,method:i}=this,s=null;if(i===n.ONE_MINUS)s=Se(1,t);else if(i===n.RECIPROCAL)s=xt(1,t);else if(i===n.DIFFERENCE)s=Ue(Se(t,r));else if(i===n.TRANSFORM_DIRECTION){let o,a;e.isMatrix(t.getNodeType(e))?(o=t,a=r):(o=r,a=t),s=_t(ce(o,X(N(a),0)).xyz)}return s!==null?s:super.setup(e)}generate(e,t){if(e.getNodeProperties(this).outputNode)return super.generate(e,t);let i=this.method,s=this.getNodeType(e),o=this.getInputType(e),a=this.aNode,l=this.bNode,u=this.cNode,c=e.renderer.coordinateSystem;if(i===n.NEGATE)return e.format("( - "+a.build(e,o)+" )",s,t);{let d=[];return i===n.CROSS?d.push(a.build(e,s),l.build(e,s)):c===At&&i===n.STEP?d.push(a.build(e,e.getTypeLength(a.getNodeType(e))===1?"float":o),l.build(e,o)):c===At&&(i===n.MIN||i===n.MAX)?d.push(a.build(e,o),l.build(e,e.getTypeLength(l.getNodeType(e))===1?e.getComponentType(o):o)):i===n.REFRACT?d.push(a.build(e,o),l.build(e,o),u.build(e,"float")):i===n.MIX?d.push(a.build(e,o),l.build(e,o),u.build(e,e.getTypeLength(u.getNodeType(e))===1?"float":o)):(c===yt&&i===n.ATAN&&l!==null&&(i="atan2"),e.shaderStage!=="fragment"&&(i===n.DFDX||i===n.DFDY)&&(U(`TSL: '${i}' is not supported in the ${e.shaderStage} stage.`,this.stackTrace),i="/*"+i+"*/"),d.push(a.build(e,o)),l!==null&&d.push(l.build(e,o)),u!==null&&d.push(u.build(e,o))),e.format(`${e.getMethod(i,s)}( ${d.join(", ")} )`,s,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}};L.ALL="all";L.ANY="any";L.RADIANS="radians";L.DEGREES="degrees";L.EXP="exp";L.EXP2="exp2";L.LOG="log";L.LOG2="log2";L.SQRT="sqrt";L.INVERSE_SQRT="inversesqrt";L.FLOOR="floor";L.CEIL="ceil";L.NORMALIZE="normalize";L.FRACT="fract";L.SIN="sin";L.SINH="sinh";L.COS="cos";L.COSH="cosh";L.TAN="tan";L.TANH="tanh";L.ASIN="asin";L.ASINH="asinh";L.ACOS="acos";L.ACOSH="acosh";L.ATAN="atan";L.ATANH="atanh";L.ABS="abs";L.SIGN="sign";L.LENGTH="length";L.NEGATE="negate";L.ONE_MINUS="oneMinus";L.DFDX="dFdx";L.DFDY="dFdy";L.ROUND="round";L.RECIPROCAL="reciprocal";L.TRUNC="trunc";L.FWIDTH="fwidth";L.TRANSPOSE="transpose";L.DETERMINANT="determinant";L.INVERSE="inverse";L.EQUALS="equals";L.MIN="min";L.MAX="max";L.STEP="step";L.REFLECT="reflect";L.DISTANCE="distance";L.DIFFERENCE="difference";L.DOT="dot";L.CROSS="cross";L.POW="pow";L.TRANSFORM_DIRECTION="transformDirection";L.MIX="mix";L.CLAMP="clamp";L.REFRACT="refract";L.SMOOTHSTEP="smoothstep";L.FACEFORWARD="faceforward";var Ex=L,uc=y(1e-6),cB=y(1e6),cc=y(Math.PI),dB=y(Math.PI*2),hB=y(Math.PI*2),pB=y(Math.PI*.5),UM=G(L,L.ALL).setParameterLength(1),IM=G(L,L.ANY).setParameterLength(1),OM=G(L,L.RADIANS).setParameterLength(1),kM=G(L,L.DEGREES).setParameterLength(1),Gl=G(L,L.EXP).setParameterLength(1),mo=G(L,L.EXP2).setParameterLength(1),go=G(L,L.LOG).setParameterLength(1),kr=G(L,L.LOG2).setParameterLength(1),Ct=G(L,L.SQRT).setParameterLength(1),Bx=G(L,L.INVERSE_SQRT).setParameterLength(1),Vr=G(L,L.FLOOR).setParameterLength(1),zl=G(L,L.CEIL).setParameterLength(1),_t=G(L,L.NORMALIZE).setParameterLength(1),ii=G(L,L.FRACT).setParameterLength(1),Tt=G(L,L.SIN).setParameterLength(1),VM=G(L,L.SINH).setParameterLength(1),Gr=G(L,L.COS).setParameterLength(1),GM=G(L,L.COSH).setParameterLength(1),zM=G(L,L.TAN).setParameterLength(1),$M=G(L,L.TANH).setParameterLength(1),WM=G(L,L.ASIN).setParameterLength(1),HM=G(L,L.ASINH).setParameterLength(1),gp=G(L,L.ACOS).setParameterLength(1),qM=G(L,L.ACOSH).setParameterLength(1),xp=G(L,L.ATAN).setParameterLength(1,2),jM=G(L,L.ATANH).setParameterLength(1),Ue=G(L,L.ABS).setParameterLength(1),Fx=G(L,L.SIGN).setParameterLength(1),mi=G(L,L.LENGTH).setParameterLength(1),yp=G(L,L.NEGATE).setParameterLength(1),XM=G(L,L.ONE_MINUS).setParameterLength(1),bp=G(L,L.DFDX).setParameterLength(1),_p=G(L,L.DFDY).setParameterLength(1),YM=G(L,L.ROUND).setParameterLength(1),KM=G(L,L.RECIPROCAL).setParameterLength(1),Tp=G(L,L.TRUNC).setParameterLength(1),Sp=G(L,L.FWIDTH).setParameterLength(1),QM=G(L,L.TRANSPOSE).setParameterLength(1),ZM=G(L,L.DETERMINANT).setParameterLength(1),JM=G(L,L.INVERSE).setParameterLength(1),ht=G(L,L.MIN).setParameterLength(2,1/0),Ie=G(L,L.MAX).setParameterLength(2,1/0),Cs=G(L,L.STEP).setParameterLength(2),ev=G(L,L.REFLECT).setParameterLength(2),tv=G(L,L.DISTANCE).setParameterLength(2),rv=G(L,L.DIFFERENCE).setParameterLength(2),ar=G(L,L.DOT).setParameterLength(2),gi=G(L,L.CROSS).setParameterLength(2),lr=G(L,L.POW).setParameterLength(2),Np=n=>ce(n,n),iv=n=>ce(n,n,n),wp=n=>ce(n,n,n,n),sv=G(L,L.TRANSFORM_DIRECTION).setParameterLength(2),nv=(n,e)=>_t(ce(e,X(N(n),0)).xyz),ov=(n,e)=>_t(X(N(n),0).mul(e).xyz),av=n=>ce(Fx(n),lr(Ue(n),1/3)),Mp=n=>ar(n,n),xe=G(L,L.MIX).setParameterLength(3),ur=(n,e=0,t=1)=>new L(L.CLAMP,j(n),j(e),j(t)),$l=n=>ur(n),vp=G(L,L.REFRACT).setParameterLength(3),Wt=G(L,L.SMOOTHSTEP).setParameterLength(3),Lx=G(L,L.FACEFORWARD).setParameterLength(3),lv=_(([n])=>{let r=43758.5453,i=ar(n.xy,V(12.9898,78.233)),s=Vl(i,cc);return ii(Tt(s).mul(r))}),uv=(n,e,t)=>xe(e,t,n),cv=(n,e,t)=>Wt(e,t,n),dv=(n,e)=>Cs(e,n),fB=Lx,mB=Bx;P("all",UM);P("any",IM);P("radians",OM);P("degrees",kM);P("exp",Gl);P("exp2",mo);P("log",go);P("log2",kr);P("sqrt",Ct);P("inverseSqrt",Bx);P("floor",Vr);P("ceil",zl);P("normalize",_t);P("fract",ii);P("sin",Tt);P("sinh",VM);P("cos",Gr);P("cosh",GM);P("tan",zM);P("tanh",$M);P("asin",WM);P("asinh",HM);P("acos",gp);P("acosh",qM);P("atan",xp);P("atanh",jM);P("abs",Ue);P("sign",Fx);P("length",mi);P("lengthSq",Mp);P("negate",yp);P("oneMinus",XM);P("dFdx",bp);P("dFdy",_p);P("round",YM);P("reciprocal",KM);P("trunc",Tp);P("fwidth",Sp);P("min",ht);P("max",Ie);P("step",dv);P("reflect",ev);P("distance",tv);P("dot",ar);P("cross",gi);P("pow",lr);P("pow2",Np);P("pow3",iv);P("pow4",wp);P("transformDirection",sv);P("transformNormalByViewMatrix",nv);P("transformNormalByInverseViewMatrix",ov);P("mix",uv);P("clamp",ur);P("refract",vp);P("smoothstep",cv);P("faceForward",Lx);P("difference",rv);P("saturate",$l);P("cbrt",av);P("transpose",QM);P("determinant",ZM);P("inverse",JM);P("rand",lv);var Px=class extends W{static get type(){return"ConditionalNode"}constructor(e,t,r=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=r}generateNodeType(e){let{ifNode:t,elseNode:r}=e.getNodeProperties(this);if(t===void 0)return e.flowBuildStage(this,"setup"),this.getNodeType(e);let i=t.getNodeType(e);if(r!==null){let s=r.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(i))return s}return i}setup(e){let t=this.condNode,r=this.ifNode.isolate(),i=this.elseNode?this.elseNode.isolate():null,s=e.context.nodeBlock;e.getDataFromNode(r).parentNodeBlock=s,i!==null&&(e.getDataFromNode(i).parentNodeBlock=s);let o=e.context.uniformFlow,a=e.getNodeProperties(this);a.condNode=t,a.ifNode=o?r:r.context({nodeBlock:r}),a.elseNode=i?o?i:i.context({nodeBlock:i}):null}generate(e,t){let r=this.getNodeType(e),i=e.getDataFromNode(this);if(i.nodeProperty!==void 0)return i.nodeProperty;let{condNode:s,ifNode:o,elseNode:a}=e.getNodeProperties(this),l=e.currentFunctionNode,u=t!=="void",c=u?wn(r).build(e):"";i.nodeProperty=c;let d=s.build(e,"bool");if(e.context.uniformFlow&&a!==null){let f=o.build(e,r),m=a.build(e,r),g=e.getTernary(d,f,m);return e.format(g,r,t)}e.addFlowCode(` | |
| ${e.tab}if ( ${d} ) { | |
| `).addFlowTab();let p=o.build(e,r);if(p&&(u?p=c+" = "+p+";":(p="return "+p+";",l===null&&(U("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),p="// "+p))),e.removeFlowTab().addFlowCode(e.tab+" "+p+` | |
| `+e.tab+"}"),a!==null){e.addFlowCode(` else { | |
| `).addFlowTab();let f=a.build(e,r);f&&(u?f=c+" = "+f+";":(f="return "+f+";",l===null&&(U("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),f="// "+f))),e.removeFlowTab().addFlowCode(e.tab+" "+f+` | |
| `+e.tab+`} | |
| `)}else e.addFlowCode(` | |
| `);return e.format(c,r,t)}};var St=te(Px).setParameterLength(2,3);P("select",St);var Ap=class extends W{static get type(){return"ContextNode"}constructor(e=null,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}generateNodeType(e){return this.node.getNodeType(e)}getFlowContextData(){let e=[];return this.traverse(t=>{t.isContextNode===!0&&e.push(t.value)}),Object.assign({},...e)}getMemberType(e,t){return this.node.getMemberType(e,t)}analyze(e){let t=e.addContext(this.value);this.node.build(e),e.setContext(t)}setup(e){let t=e.addContext(this.value);this.node.build(e),e.setContext(t)}generate(e,t){let r=e.addContext(this.value),i=this.node.build(e,t);return e.setContext(r),i}},dc=Ap,wr=(n=null,e={})=>{let t=n;return(t===null||t.isNode!==!0)&&(e=t||e,t=null),new Ap(t,e)},hv=n=>wr(n,{uniformFlow:!0}),Dx=(n,e)=>wr(n,{nodeName:e});function pv(n,e,t=null){return wr(t,{getShadow:({light:r,shadowColorNode:i})=>e===r?i.mul(n):i})}function fv(n,e=null){return wr(e,{getAO:(t,{material:r})=>r.transparent===!0?t:t!==null?t.mul(n):n})}function mv(n,e){return U('TSL: "label()" has been deprecated. Use "setName()" instead.'),Dx(n,e)}P("context",wr);P("label",mv);P("uniformFlow",hv);P("setName",Dx);P("builtinShadowContext",(n,e,t)=>pv(e,t,n));P("builtinAOContext",(n,e)=>fv(e,n));var Rp=class extends W{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 e.getDataFromNode(this).forceDeclaration===!0?!1:this.intent}getIntent(){return this.intent}getMemberType(e,t){return this.node.getMemberType(e,t)}getElementType(e){return this.node.getElementType(e)}generateNodeType(e){return this.node.getNodeType(e)}getArrayCount(e){return this.node.getArrayCount(e)}isAssign(e){return e.getDataFromNode(this).assign}build(...e){let t=e[0],r=this.getShared(t);if(this!==r)return r.build(...e);if(this._hasStack(t)===!1&&t.buildStage==="setup"&&(t.context.nodeLoop||t.context.nodeBlock)){let i=!1;if(this.node.isShaderCallNodeInternal&&this.node.shaderNode.getLayout()===null&&t.fnCall&&t.fnCall.shaderNode&&t.getDataFromNode(this.node.shaderNode).hasLoop){let a=t.getDataFromNode(this);a.forceDeclaration=!0,i=!0}let s=t.getBaseStack();i?s.addToStackBefore(this):s.addToStack(this)}return this.isIntent(t)&&this.isAssign(t)!==!0?this.node.build(...e):super.build(...e)}generate(e){let{node:t,name:r,readOnly:i}=this,{renderer:s}=e,o=s.backend.isWebGPUBackend===!0,a=!1,l=!1;i&&(a=e.isDeterministic(t),l=o?i:a);let u=this.getNodeType(e);if(u=="void")return this.isIntent(e)!==!0&&I('TSL: ".toVar()" can not be used with void type.',this.stackTrace),t.build(e);let c=e.getVectorType(u),d=t.build(e,c),h=e.getVarFromNode(this,r,c,void 0,l),p=e.getPropertyName(h),f=p;if(l)if(o)f=a?`const ${p}`:`let ${p}`;else{let m=t.getArrayCount(e);f=`const ${e.getVar(h.type,p,m)}`}return e.addLineFlowCode(`${f} = ${d}`,this),p}_hasStack(e){return e.getDataFromNode(this).stack!==void 0}},hc=Rp,Ux=te(Rp),gv=(n,e=null)=>Ux(n,e).toStack(),xv=(n,e=null)=>Ux(n,e,!0).toStack(),yv=n=>Ux(n).setIntent(!0).toStack();P("toVar",gv);P("toConst",xv);P("toVarIntent",yv);var Ix=class extends W{static get type(){return"SubBuild"}constructor(e,t,r=null){super(r),this.node=e,this.name=t,this.isSubBuildNode=!0}generateNodeType(e){if(this.nodeType!==null)return this.nodeType;e.addSubBuild(this.name);let t=this.node.getNodeType(e);return e.removeSubBuild(),t}build(e,...t){e.addSubBuild(this.name);let r=this.node.build(e,...t);return e.removeSubBuild(),r}};var Es=(n,e,t=null)=>new Ix(j(n),e,t);var Ox=class extends W{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=Es(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)}generateNodeType(e){return this.node.getNodeType(e)}setupVarying(e){let t=e.getNodeProperties(this),r=t.varying;if(r===void 0){let i=this.name,s=this.getNodeType(e),o=this.interpolationType,a=this.interpolationSampling;t.varying=r=e.getVaryingFromNode(this,i,s,o,a),t.node=Es(this.node,"VERTEX")}return r.needsInterpolation||(r.needsInterpolation=e.shaderStage==="fragment"),r}setup(e){this.setupVarying(e),e.flowNodeFromShaderStage(Ra.VERTEX,this.node)}analyze(e){this.setupVarying(e),e.flowNodeFromShaderStage(Ra.VERTEX,this.node)}generate(e){let t=e.getSubBuildProperty("property",e.currentStack),r=e.getNodeProperties(this),i=this.setupVarying(e);if(r[t]===void 0){let s=this.getNodeType(e),o=e.getPropertyName(i,Ra.VERTEX);if(e.shaderStage===Ra.VERTEX){let a=r.node.build(e,s);e.addLineFlowCode(`${o} = ${a}`,this)}else e.flowNodeFromShaderStage(Ra.VERTEX,r.node,s,o);r[t]=o}return e.getPropertyName(i)}};var xi=te(Ox).setParameterLength(1,2),bv=n=>xi(n);P("toVarying",xi);P("toVertexStage",bv);var kx=_(([n])=>{let e=n.mul(.9478672986).add(.0521327014).pow(2.4),t=n.mul(.0773993808),r=n.lessThanEqual(.04045);return xe(e,t,r)}).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Vx=_(([n])=>{let e=n.pow(.41666).mul(1.055).sub(.055),t=n.mul(12.92),r=n.lessThanEqual(.0031308);return xe(e,t,r)}).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]});var Gx="WorkingColorSpace",gB="OutputColorSpace",pc=class extends _e{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===Gx?Me.workingColorSpace:t===gB?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){let{colorNode:t}=this,r=this.resolveColorSpace(e,this.source),i=this.resolveColorSpace(e,this.target),s=t;return Me.enabled===!1||r===i||!r||!i||(Me.getTransfer(r)===fe&&(s=X(kx(s.rgb),s.a)),Me.getPrimaries(r)!==Me.getPrimaries(i)&&(s=X(rt(Me._getMatrix(new et,r,i)).mul(s.rgb),s.a)),Me.getTransfer(i)===fe&&(s=X(Vx(s.rgb),s.a))),s}};var _v=(n,e)=>new pc(j(n),Gx,e),Wl=(n,e)=>new pc(j(n),e,Gx),xB=(n,e,t)=>new pc(j(n),e,t);P("workingToColorSpace",_v);P("colorSpaceToWorking",Wl);var zx=class extends ri{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}generateNodeType(){return this.referenceNode.uniformType}generate(e){let t=super.generate(e),r=this.referenceNode.getNodeType(),i=this.getNodeType();return e.format(t,r,i)}},Cp=class extends W{static get type(){return"ReferenceBaseNode"}constructor(e,t,r=null,i=null){super(),this.property=e,this.uniformType=t,this.object=r,this.count=i,this.properties=e.split("."),this.reference=r,this.node=null,this.group=null,this.updateType=J.OBJECT}setGroup(e){return this.group=e,this}element(e){return new zx(this,j(e))}setNodeType(e){let t=Y(null,e);this.group!==null&&t.setGroup(this.group),this.node=t}generateNodeType(e){return this.node===null&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){let{properties:t}=this,r=e[t[0]];for(let i=1;i<t.length;i++)r=r[t[i]];return r}updateReference(e){return this.reference=this.object!==null?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);let e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}},$x=Cp,Tv=(n,e,t)=>new Cp(n,e,t);var Wx=class extends $x{static get type(){return"RendererReferenceNode"}constructor(e,t,r=null){super(e,t,r),this.renderer=r,this.setGroup(ee)}updateReference(e){return this.reference=this.renderer!==null?this.renderer:e.renderer,this.reference}};var Hx=(n,e,t=null)=>new Wx(n,e,t);var qx=class extends _e{static get type(){return"ToneMappingNode"}constructor(e,t=Nv,r=null){super("vec3"),this._toneMapping=e,this.exposureNode=t,this.colorNode=r}customCacheKey(){return po(this._toneMapping)}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup(e){let t=this.colorNode||e.context.color,r=this._toneMapping;if(r===ms)return t;let i=null,s=e.renderer.library.getToneMappingFunction(r);return s!==null?i=X(s(t.rgb,this.exposureNode),t.a):(I("ToneMappingNode: Unsupported Tone Mapping configuration.",r),i=t),i}};var Sv=(n,e,t)=>new qx(n,j(e),j(t)),Nv=Hx("toneMappingExposure","float");P("toneMapping",(n,e,t)=>Sv(e,t,n));var wv=new WeakMap;function Mv(n,e){let t=wv.get(n);return t===void 0&&(t=new Nl(n,e),wv.set(n,t)),t}var Bs=class extends Ca{static get type(){return"BufferAttributeNode"}constructor(e,t=null,r=0,i=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=r,this.bufferOffset=i,this.usage=ys,this.instanced=!1,this.attribute=null,this.global=!0,e&&e.isBufferAttribute===!0&&e.itemSize<=4&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){let t;if(this.bufferStride===0&&this.bufferOffset===0){let r=e.globalCache.getData(this.value);r===void 0&&(r={node:this},e.globalCache.setData(this.value,r)),t=r.node.id}else t=this.id;return String(t)}generateNodeType(e){return this.bufferType===null&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(this.attribute!==null)return;let t=this.getNodeType(e),r=e.getTypeLength(t),i=this.value,s=this.bufferStride||r,o=this.bufferOffset,a;i.isInterleavedBuffer===!0?a=i:i.isBufferAttribute===!0?a=Mv(i.array,s):a=Mv(i,s);let l=new ch(a,r,o);a.setUsage(this.usage),this.attribute=l,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){let t=this.getNodeType(e),r=e.context.nodeName;r!==void 0&&delete e.context.nodeName;let i=e.getBufferAttributeFromNode(this,t,r),s=e.getPropertyName(i),o=null;if(e.shaderStage==="vertex"||e.shaderStage==="compute")this.name=s,o=s;else{let a;r&&(a=r+"Varying"),o=xi(this,a).build(e,t)}return o}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&this.attribute.isBufferAttribute===!0&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}};function Ep(n,e=null,t=0,r=0,i=ys,s=!1){return e==="mat3"||e===null&&n.itemSize===9?rt(new Bs(n,"vec3",9,0).setUsage(i).setInstanced(s),new Bs(n,"vec3",9,3).setUsage(i).setInstanced(s),new Bs(n,"vec3",9,6).setUsage(i).setInstanced(s)):e==="mat4"||e===null&&n.itemSize===16?Gi(new Bs(n,"vec4",16,0).setUsage(i).setInstanced(s),new Bs(n,"vec4",16,4).setUsage(i).setInstanced(s),new Bs(n,"vec4",16,8).setUsage(i).setInstanced(s),new Bs(n,"vec4",16,12).setUsage(i).setInstanced(s)):new Bs(n,e,t,r).setUsage(i)}var Bp=(n,e=null,t=0,r=0)=>Ep(n,e,t,r),yB=(n,e=null,t=0,r=0)=>Ep(n,e,t,r,eo),Hl=(n,e=null,t=0,r=0)=>Ep(n,e,t,r,ys,!0),Fp=(n,e=null,t=0,r=0)=>Ep(n,e,t,r,eo,!0);P("toAttribute",n=>Bp(n.value));var Ot=class n extends W{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isIndexNode=!0}generate(e){let t=this.getNodeType(e),r=this.scope,i;if(r===n.VERTEX)i=e.getVertexIndex();else if(r===n.INSTANCE)i=e.getInstanceIndex();else if(r===n.DRAW)i=e.getDrawIndex();else if(r===n.INVOCATION_LOCAL)i=e.getInvocationLocalIndex();else if(r===n.INVOCATION_SUBGROUP)i=e.getInvocationSubgroupIndex();else if(r===n.SUBGROUP)i=e.getSubgroupIndex();else throw new Error("THREE.IndexNode: Unknown scope: "+r);let s;return e.shaderStage==="vertex"||e.shaderStage==="compute"?s=i:s=xi(this).build(e,t),s}};Ot.VERTEX="vertex";Ot.INSTANCE="instance";Ot.SUBGROUP="subgroup";Ot.INVOCATION_LOCAL="invocationLocal";Ot.INVOCATION_SUBGROUP="invocationSubgroup";Ot.DRAW="draw";var ql=q(Ot,Ot.VERTEX),cr=q(Ot,Ot.INSTANCE),bB=q(Ot,Ot.SUBGROUP),_B=q(Ot,Ot.INVOCATION_SUBGROUP),TB=q(Ot,Ot.INVOCATION_LOCAL),jx=q(Ot,Ot.DRAW);var Xx=class extends W{static get type(){return"ComputeNode"}constructor(e,t){super("void"),this.isComputeNode=!0,this.computeNode=e,this.workgroupSize=t,this.count=null,this.dispatchSize=null,this.version=1,this.name="",this.updateBeforeType=J.OBJECT,this.onInitFunction=null,this.countNode=null}dispose(){this.dispatchEvent({type:"dispose"})}setName(e){return this.name=e,this}label(e){return U('TSL: "label()" has been deprecated. Use "setName()" instead.',new tt),this.setName(e)}onInit(e){return this.onInitFunction=e,this}updateBefore({renderer:e}){e.compute(this)}setup(e){this.count!==null&&this.countNode===null&&(this.countNode=Y(this.count,"uint").onObjectUpdate(()=>this.count));let t=this.computeNode.build(e);if(t){let r=e.getNodeProperties(this);r.outputComputeNode=t.outputNode,t.outputNode=null}return t}generate(e,t){let{shaderStage:r}=e;if(r==="compute"){let i=this.computeNode.build(e,"void");if(i!==""&&e.addLineFlowCode(i,this),this.count!==null&&e.allowEarlyReturns===!0){let s=this.countNode.build(e,"uint"),o=cr.build(e,"uint");e.flow.code=`${e.tab}if ( ${o} >= ${s} ) { return; } | |
| ${e.flow.code}`}}else{let s=e.getNodeProperties(this).outputComputeNode;if(s)return s.build(e,t)}}};var Yx=(n,e=[64])=>{(e.length===0||e.length>3)&&I("TSL: compute() workgroupSize must have 1, 2, or 3 elements",new tt);for(let t=0;t<e.length;t++){let r=e[t];(typeof r!="number"||r<=0||!Number.isInteger(r))&&I(`TSL: compute() workgroupSize element at index [ ${t} ] must be a positive integer`,new tt)}for(;e.length<3;)e.push(1);return new Xx(j(n),e)},vv=(n,e,t)=>{let r=Yx(n,t);return typeof e=="number"?r.count=e:r.dispatchSize=e,r};P("compute",vv);P("computeKernel",Yx);var Kx=class extends W{static get type(){return"IsolateNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isIsolateNode=!0}generateNodeType(e){let t=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);let i=this.node.getNodeType(e);return e.setCache(t),i}build(e,...t){let r=e.getCache(),i=e.getCacheFromNode(this,this.parent);e.setCache(i);let s=this.node.build(e,...t);return e.setCache(r),s}setParent(e){return this.parent=e,this}getParent(){return this.parent}};var Da=n=>new Kx(j(n));function Av(n,e=!0){return U('TSL: "cache()" has been deprecated. Use "isolate()" instead.'),Da(n).setParent(e)}P("cache",Av);P("isolate",Da);var Qx=class extends W{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}generateNodeType(e){return this.outputNode.getNodeType(e)}generate(e){let t=this.callNode.build(e,"void");return t!==""&&e.addLineFlowCode(t,this),this.outputNode.build(e)}};var Rv=te(Qx).setParameterLength(2);P("bypass",Rv);var Zx=_(([n,e,t,r=y(0),i=y(1),s=nr(!1)])=>{let o=n.sub(e).div(t.sub(e));return Sn(s)&&(o=o.clamp()),o.mul(i.sub(r)).add(r)});function Cv(n,e,t,r=y(0),i=y(1)){return Zx(n,e,t,r,i,!0)}P("remap",Zx);P("remapClamp",Cv);var Lp=class extends W{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){let r=this.getNodeType(e),i=this.snippet;if(r==="void")e.addLineFlowCode(i,this);else return e.format(i,r,t)}},fc=Lp,dr=te(Lp).setParameterLength(1,2);var Ev=n=>(n?St(n,dr("discard")):dr("discard")).toStack(),SB=()=>dr("return").toStack();P("discard",Ev);var mc=_(([n])=>X(n.rgb.mul(n.a),n.a),{color:"vec4",return:"vec4"}),Jx=_(([n])=>n.a.equal(0).select(X(0),X(n.rgb.div(n.a),n.a)),{color:"vec4",return:"vec4"});var ey=class extends _e{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;t=X(t.rgb,t.a.clamp(0,1)),t=Jx(t);let r=(this._toneMapping!==null?this._toneMapping:e.toneMapping)||ms,i=(this.outputColorSpace!==null?this.outputColorSpace:e.outputColorSpace)||Zr;return r!==ms&&(t=t.toneMapping(r)),i!==Zr&&i!==Me.workingColorSpace&&(t=t.workingToColorSpace(i)),t=mc(t),t}};var Pp=(n,e=null,t=null)=>new ey(j(n),e,t);P("renderOutput",Pp);var ty=class extends _e{static get type(){return"DebugNode"}constructor(e,t=null){super(),this.node=e,this.callback=t}generateNodeType(e){return this.node.getNodeType(e)}setup(e){return this.node.build(e)}analyze(e){return this.node.build(e)}generate(e){let t=this.callback,r=this.node.build(e);if(t!==null)t(e,r);else{let i="--- TSL debug - "+e.shaderStage+" shader ---",s="-".repeat(i.length),o="";o+="// #"+i+`# | |
| `,o+=e.flow.code.replace(/^\t/mg,"")+` | |
| `,o+="/* ... */ "+r+` /* ... */ | |
| `,o+="// #"+s+`# | |
| `,Ou(o)}return r}};var Bv=(n,e=null)=>new ty(j(n),e).toStack();P("debug",Bv);var ry=class extends bt{constructor(){super(),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(){}},Dp=ry;var iy=class extends W{static get type(){return"InspectorNode"}constructor(e,t="",r=null){super(),this.node=e,this.name=t,this.callback=r,this.updateType=J.FRAME,this.isInspectorNode=!0}getName(){return this.name||this.node.name}update(e){e.renderer.inspector.inspect(this)}generateNodeType(e){return this.node.getNodeType(e)}setup(e){let t=this.node;return e.context.inspector===!0&&this.callback!==null&&(t=this.callback(t)),e.renderer.backend.isWebGPUBackend!==!0&&e.renderer.inspector.constructor!==Dp&&he('TSL: ".toInspector()" is only available with WebGPU.'),t}};function Fv(n,e="",t=null){return n=j(n),n.before(new iy(n,e,t))}P("toInspector",Fv);function NB(n){U("TSL: AddNodeElement has been removed in favor of tree-shaking. Trying add",n)}var Up=class extends W{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}generateNodeType(e){let t=this.nodeType;if(t===null){let r=this.getAttributeName(e);if(e.hasGeometryAttribute(r)){let i=e.geometry.getAttribute(r);t=e.getTypeFromAttribute(i)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){let t=this.getAttributeName(e),r=this.getNodeType(e);if(e.hasGeometryAttribute(t)===!0){let s=e.geometry.getAttribute(t),o=e.getTypeFromAttribute(s),a=e.getAttribute(t,o);return e.shaderStage==="vertex"?e.format(a.name,o,r):xi(this).build(e,r)}else return U(`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}},sy=Up,Mr=(n,e=null)=>new Up(n,e);var Re=(n=0)=>Mr("uv"+(n>0?n:""),"vec2");var ny=class extends W{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e){let t=this.textureNode.build(e,"property"),r=this.levelNode===null?"0":this.levelNode.build(e,"int"),i=e.generateTextureSize(this.textureNode.value,t,r);return e.format(i,this.getNodeType(e))}};var Fs=te(ny).setParameterLength(1,2);var oy=class extends An{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=J.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){let e=this.texture,t=e.images,r=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(r&&r.width!==void 0){let{width:i,height:s}=r;this.value=Math.log2(Math.max(i,s))}}};var gc=te(oy).setParameterLength(1);var ay=class extends Error{constructor(e,t=null){super(e),this.name="NodeError",this.stackTrace=t}},xc=ay;var ly=new nt,Ip=class extends An{static get type(){return"TextureNode"}constructor(e=ly,t=null,r=null,i=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=r,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.gatherNode=null,this.offsetNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=J.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this._flipYUniform=null,this.setUpdateMatrix(t===null)}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}generateNodeType(){return this.gatherNode!==null?"vec4":Kh(this.value)}getInputType(){return"texture"}getDefaultUV(){return Re(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return this._matrixUniform===null&&(this._matrixUniform=Y(this.value.matrix)),this._matrixUniform.mul(N(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this}setupUV(e,t){return e.isFlipY()&&(this._flipYUniform===null&&(this._flipYUniform=Y(!1)),t=t.toVar(),this.sampler?t=this._flipYUniform.select(t.flipY(),t):t=this._flipYUniform.select(t.setY(A(Fs(this,this.levelNode).y).sub(t.y).sub(1)),t)),t}setup(e){let t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let r=this.value;if(!r||r.isTexture!==!0)throw new xc("THREE.TSL: `texture( value )` function expects a valid instance of THREE.Texture().",this.stackTrace);let i=_(()=>{let l=this.uvNode;return(l===null||e.context.forceUVContext===!0)&&e.context.getUV&&(l=e.context.getUV(this,e)),l||(l=this.getDefaultUV()),this.updateMatrix===!0&&(l=this.getTransformedUV(l)),l=this.setupUV(e,l),this.updateType=this._matrixUniform!==null||this._flipYUniform!==null?J.OBJECT:J.NONE,l})(),s=this.levelNode;s===null&&e.context.getTextureLevel&&(s=e.context.getTextureLevel(this));let o=null,a=null;if(this.compareNode!==null)if(e.renderer.hasCompatibility(xr.TEXTURE_COMPARE))o=this.compareNode;else{let l=r.compareFunction;l===null||l===ol||l===Pi||l===ya||l===ui?a=this.compareNode:(o=this.compareNode,he('TSL: Only "LessCompare", "LessEqualCompare", "GreaterCompare" and "GreaterEqualCompare" are supported for depth texture comparison fallback.'))}t.uvNode=i,t.levelNode=s,t.biasNode=this.biasNode,t.compareNode=o,t.compareStepNode=a,t.gradNode=this.gradNode,t.gatherNode=this.gatherNode,t.depthNode=this.depthNode,t.offsetNode=this.offsetNode}generateUV(e,t){return t.build(e,this.sampler===!0?"vec2":"ivec2")}generateOffset(e,t){return t.build(e,"ivec2")}generateSnippet(e,t,r,i,s,o,a,l,u,c,d){let h=this.value,p;return s?p=e.generateTextureBias(h,t,r,s,o,c):l?p=e.generateTextureGrad(h,t,r,l,o,c):u?a?p=e.generateTextureGatherCompare(h,t,r,a,o,c,d):p=e.generateTextureGather(h,t,r,u,o,c,d):a?p=e.generateTextureCompare(h,t,r,a,o,c):this.sampler===!1?p=e.generateTextureLoad(h,t,r,i,o,c):i?p=e.generateTextureLevel(h,t,r,i,o,c):p=e.generateTexture(h,t,r,o,c),p}generate(e,t){let r=this.value,i=e.getNodeProperties(this),s=super.generate(e,"property");if(/^sampler/.test(t))return s+"_sampler";if(e.isReference(t))return s;{let o=e.getDataFromNode(this),a=this.getNodeType(e),l=o.propertyName;if(l===void 0){let{uvNode:c,levelNode:d,biasNode:h,compareNode:p,compareStepNode:f,depthNode:m,gradNode:g,gatherNode:x,offsetNode:w}=i,v=this.generateUV(e,c),E=d?d.build(e,"float"):null,b=h?h.build(e,"float"):null,S=m?m.build(e,"int"):null,T=p?p.build(e,"float"):null,M=f?f.build(e,"float"):null,B=g?[g[0].build(e,"vec2"),g[1].build(e,"vec2")]:null,D=x?x.build(e,"int"):null,O=w?this.generateOffset(e,w):null,z=this._flipYUniform?this._flipYUniform.build(e,"bool"):null,Q=S;Q===null&&r.isArrayTexture&&this.isTexture3DNode!==!0&&(Q="0");let oe=e.getVarFromNode(this);l=e.getPropertyName(oe);let H=this.generateSnippet(e,s,v,E,b,Q,T,B,D,O,z),ae;if(r.isDepthTexture===!0&&D===null?ae="float":ae=r.type===Ce?"uvec4":r.type===Je?"ivec4":"vec4",H=e.format(H,ae,a),M!==null){let de=r.compareFunction;de===ya||de===ui?H=Cs(dr(H,a),dr(M,"float")).build(e,a):H=Cs(dr(M,"float"),dr(H,a)).build(e,a)}e.addLineFlowCode(`${l} = ${H}`,this),o.snippet=H,o.propertyName=l}let u=l;return e.needsToWorkingColorSpace(r)&&(u=Wl(dr(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){let t=this.clone();return t.uvNode=j(e),t.referenceNode=this.getBase(),j(t)}load(e){return this.sample(e).setSampler(!1)}blur(e){let t=this.clone();t.biasNode=j(e).mul(gc(t)),t.referenceNode=this.getBase();let r=t.value;return t.generateMipmaps===!1&&(r&&r.generateMipmaps===!1||r.minFilter===Pe||r.magFilter===Pe)&&(U("TSL: texture().blur() requires mipmaps and sampling. Use .generateMipmaps=true and .minFilter/.magFilter=THREE.LinearFilter in the Texture."),t.biasNode=null),j(t)}level(e){let t=this.clone();return t.levelNode=j(e),t.referenceNode=this.getBase(),j(t)}size(e){return Fs(this,e)}bias(e){let t=this.clone();return t.biasNode=j(e),t.referenceNode=this.getBase(),j(t)}getBase(){return this.referenceNode?this.referenceNode.getBase():this}compare(e){let t=this.clone();return t.compareNode=j(e),t.referenceNode=this.getBase(),j(t)}grad(e,t){let r=this.clone();return r.gradNode=[j(e),j(t)],r.referenceNode=this.getBase(),j(r)}gather(e=0){let t=this.clone();return t.gatherNode=j(e),t.referenceNode=this.getBase(),j(t)}depth(e){let t=this.clone();return t.depthNode=j(e),t.referenceNode=this.getBase(),j(t)}offset(e){let t=this.clone();return t.offsetNode=j(e),t.referenceNode=this.getBase(),j(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(){let e=this.value,t=this._matrixUniform;t!==null&&(t.value=e.matrix),e.matrixAutoUpdate===!0&&e.updateMatrix();let r=this._flipYUniform;r!==null&&(r.value=e.image instanceof ImageBitmap&&e.flipY===!0||e.isRenderTargetTexture===!0||e.isFramebufferTexture===!0||e.isDepthTexture===!0)}clone(){let 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.gatherNode=this.gatherNode,e.offsetNode=this.offsetNode,e}},jt=Ip,wB=te(Ip).setParameterLength(1,4).setName("texture"),be=(n=ly,e=null,t=null,r=null)=>{let i;return n&&n.isTextureNode===!0?(i=j(n.clone()),i.referenceNode=n.getBase(),e!==null&&(i.uvNode=j(e)),t!==null&&(i.levelNode=j(t)),r!==null&&(i.biasNode=j(r))):i=wB(n,e,t,r),i},MB=(n=ly)=>be(n),at=(...n)=>be(...n).setSampler(!1),vB=(n,e,t)=>be(n,e).level(t),AB=n=>(n.isNode===!0?n:be(n)).convert("sampler"),RB=n=>(n.isNode===!0?n:be(n)).convert("samplerComparison");var Op=class extends An{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"}},yc=Op,Ls=(n,e,t)=>new Op(n,e,t);var uy=class extends ri{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){let t=super.generate(e),r=this.getNodeType(e),i=this.node.getPaddedType();return e.format(t,i,r)}},cy=class extends yc{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null),this.array=e,this.elementType=t===null?Oi(e[0]):t,this.paddedType=this.getPaddedType(),this.updateType=J.RENDER,this.isArrayBufferNode=!0}generateNodeType(){return this.paddedType}getElementType(){return this.elementType}getPaddedType(){let e=this.elementType,t="vec4";return e==="mat2"?t="mat2":/mat/.test(e)===!0?t="mat4":e.charAt(0)==="i"?t="ivec4":e.charAt(0)==="u"&&(t="uvec4"),t}update(){this.updateBuffer()}onUpdate(e,t){return e=e.bind(this),super.onUpdate((r,i)=>{e(r,i),this.updateBuffer()},t)}updateBuffer(){let{array:e,value:t}=this,r=this.elementType;if(r==="float"||r==="int"||r==="uint")for(let i=0;i<e.length;i++){let s=i*4;t[s]=e[i]}else if(r==="color")for(let i=0;i<e.length;i++){let s=i*4,o=e[i];t[s]=o.r,t[s+1]=o.g,t[s+2]=o.b||0}else if(r==="mat2")for(let i=0;i<e.length;i++){let s=i*4,o=e[i];t[s]=o.elements[0],t[s+1]=o.elements[1],t[s+2]=o.elements[2],t[s+3]=o.elements[3]}else if(r==="mat3")for(let i=0;i<e.length;i++){let s=i*16,o=e[i];t[s]=o.elements[0],t[s+1]=o.elements[1],t[s+2]=o.elements[2],t[s+4]=o.elements[3],t[s+5]=o.elements[4],t[s+6]=o.elements[5],t[s+8]=o.elements[6],t[s+9]=o.elements[7],t[s+10]=o.elements[8],t[s+15]=1}else if(r==="mat4")for(let i=0;i<e.length;i++){let s=i*16,o=e[i];for(let a=0;a<o.elements.length;a++)t[s+a]=o.elements[a]}else for(let i=0;i<e.length;i++){let s=i*4,o=e[i];t[s]=o.x,t[s+1]=o.y,t[s+2]=o.z||0,t[s+3]=o.w||0}}setup(e){let t=this.array.length,r=this.elementType,i=Float32Array,s=this.paddedType,o=e.getTypeLength(s);return r.charAt(0)==="i"&&(i=Int32Array),r.charAt(0)==="u"&&(i=Uint32Array),this.value=new i(t*o),this.bufferCount=t,this.bufferType=s,this.updateBuffer(),super.setup(e)}element(e){return new uy(this,j(e))}};var Et=(n,e)=>new cy(n,e);var dy=class extends W{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}};var $i=te(dy).setParameterLength(1);var bc,_c,hr=class n extends W{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this._output=null,this.isViewportNode=!0}generateNodeType(){return this.scope===n.DPR?"float":this.scope===n.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=J.NONE;return(this.scope===n.SIZE||this.scope===n.VIEWPORT||this.scope===n.DPR)&&(e=J.RENDER),this.updateType=e,e}update({renderer:e}){let t=e.getRenderTarget();this.scope===n.VIEWPORT?t!==null?_c.copy(t.viewport):(e.getViewport(_c),_c.multiplyScalar(e.getPixelRatio())):this.scope===n.DPR?this._output.value=e.getPixelRatio():t!==null?(bc.width=t.width,bc.height=t.height):e.getDrawingBufferSize(bc)}setup(){let e=this.scope,t=null;return e===n.SIZE?t=Y(bc||(bc=new se)):e===n.VIEWPORT?t=Y(_c||(_c=new pe)):e===n.DPR?t=Y(1):t=V(Ps.div(xo)),this._output=t,t}generate(e){if(this.scope===n.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){let r=e.getNodeProperties(xo).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${r}.y - ${t}.y )`}return t}return super.generate(e)}};hr.COORDINATE="coordinate";hr.VIEWPORT="viewport";hr.SIZE="size";hr.UV="uv";hr.DPR="dpr";var hy=q(hr,hr.DPR),pr=q(hr,hr.UV),xo=q(hr,hr.SIZE),Ps=q(hr,hr.COORDINATE),py=q(hr,hr.VIEWPORT),kp=py.zw,Lv=Ps.sub(py.xy),CB=Lv.div(kp);var fy=null,Vp=null,my=null,Gp=null,gy=null,zp=null,xy=null,$p=null,yy=null,Wp=null,by=null,Hp=null,_y=null,qp=null,yo=Y(0,"uint").setName("u_cameraIndex").setGroup(ac("cameraIndex")).toVarying("v_cameraIndex"),Ds=Y("float").setName("cameraNear").setGroup(ee).onRenderUpdate(({camera:n})=>n.near),Us=Y("float").setName("cameraFar").setGroup(ee).onRenderUpdate(({camera:n})=>n.far),zr=_(({camera:n})=>{let e;if(n.isArrayCamera&&n.cameras.length>0){let t=[];for(let r of n.cameras)t.push(r.projectionMatrix);Vp===null?Vp=Et(t).setGroup(ee).setName("cameraProjectionMatrices"):Vp.array=t,e=Vp.element(n.isMultiViewCamera?$i("gl_ViewID_OVR"):yo)}else fy===null&&(fy=Y(n.projectionMatrix).setName("cameraProjectionMatrix").setGroup(ee).onRenderUpdate(({camera:t})=>t.projectionMatrix)),e=fy;return e}).once()(),Ty=_(({camera:n})=>{let e;if(n.isArrayCamera&&n.cameras.length>0){let t=[];for(let r of n.cameras)t.push(r.projectionMatrixInverse);Gp===null?Gp=Et(t).setGroup(ee).setName("cameraProjectionMatricesInverse"):Gp.array=t,e=Gp.element(n.isMultiViewCamera?$i("gl_ViewID_OVR"):yo)}else my===null&&(my=Y(n.projectionMatrixInverse).setName("cameraProjectionMatrixInverse").setGroup(ee).onRenderUpdate(({camera:t})=>t.projectionMatrixInverse)),e=my;return e}).once()(),yi=_(({camera:n})=>{let e;if(n.isArrayCamera&&n.cameras.length>0){let t=[];for(let r of n.cameras)t.push(r.matrixWorldInverse);zp===null?zp=Et(t).setGroup(ee).setName("cameraViewMatrices"):zp.array=t,e=zp.element(n.isMultiViewCamera?$i("gl_ViewID_OVR"):yo)}else gy===null&&(gy=Y(n.matrixWorldInverse).setName("cameraViewMatrix").setGroup(ee).onRenderUpdate(({camera:t})=>t.matrixWorldInverse)),e=gy;return e}).once()(),bo=_(({camera:n})=>{let e;if(n.isArrayCamera&&n.cameras.length>0){let t=[];for(let r of n.cameras)t.push(r.matrixWorld);$p===null?$p=Et(t).setGroup(ee).setName("cameraWorldMatrices"):$p.array=t,e=$p.element(n.isMultiViewCamera?$i("gl_ViewID_OVR"):yo)}else xy===null&&(xy=Y(n.matrixWorld).setName("cameraWorldMatrix").setGroup(ee).onRenderUpdate(({camera:t})=>t.matrixWorld)),e=xy;return e}).once()(),EB=_(({camera:n})=>{let e;if(n.isArrayCamera&&n.cameras.length>0){let t=[];for(let r of n.cameras)t.push(r.normalMatrix);Wp===null?Wp=Et(t).setGroup(ee).setName("cameraNormalMatrices"):Wp.array=t,e=Wp.element(n.isMultiViewCamera?$i("gl_ViewID_OVR"):yo)}else yy===null&&(yy=Y(n.normalMatrix).setName("cameraNormalMatrix").setGroup(ee).onRenderUpdate(({camera:t})=>t.normalMatrix)),e=yy;return e}).once()(),Sy=_(({camera:n})=>{let e;if(n.isArrayCamera&&n.cameras.length>0){let t=[];for(let r=0,i=n.cameras.length;r<i;r++)t.push(new C);Hp===null?Hp=Et(t).setGroup(ee).setName("cameraPositions").onRenderUpdate(({camera:r},i)=>{let s=r.cameras,o=i.array;for(let a=0,l=s.length;a<l;a++)o[a].setFromMatrixPosition(s[a].matrixWorld)}):Hp.array=t,e=Hp.element(n.isMultiViewCamera?$i("gl_ViewID_OVR"):yo)}else by===null&&(by=Y(new C).setName("cameraPosition").setGroup(ee).onRenderUpdate(({camera:t},r)=>r.value.setFromMatrixPosition(t.matrixWorld))),e=by;return e}).once()(),BB=_(({camera:n})=>{let e;if(n.isArrayCamera&&n.cameras.length>0){let t=[];for(let r of n.cameras)t.push(r.viewport);qp===null?qp=Et(t,"vec4").setGroup(ee).setName("cameraViewports"):qp.array=t,e=qp.element(yo)}else _y===null&&(_y=X(0,0,xo.x,xo.y).toConst("cameraViewport")),e=_y;return e}).once()();var Pv=new bs,Bt=class n extends W{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=J.OBJECT,this.uniformNode=new An(null)}generateNodeType(){let e=this.scope;if(e===n.WORLD_MATRIX)return"mat4";if(e===n.POSITION||e===n.VIEW_POSITION||e===n.DIRECTION||e===n.SCALE)return"vec3";if(e===n.RADIUS)return"float"}update(e){let t=this.object3d,r=this.uniformNode,i=this.scope;if(i===n.WORLD_MATRIX)r.value=t.matrixWorld;else if(i===n.POSITION)r.value=r.value||new C,r.value.setFromMatrixPosition(t.matrixWorld);else if(i===n.SCALE)r.value=r.value||new C,r.value.setFromMatrixScale(t.matrixWorld);else if(i===n.DIRECTION)r.value=r.value||new C,t.getWorldDirection(r.value);else if(i===n.VIEW_POSITION){let s=e.camera;r.value=r.value||new C,r.value.setFromMatrixPosition(t.matrixWorld),r.value.applyMatrix4(s.matrixWorldInverse)}else if(i===n.RADIUS){let s=e.object.geometry;s.boundingSphere===null&&s.computeBoundingSphere(),Pv.copy(s.boundingSphere).applyMatrix4(t.matrixWorld),r.value=Pv.radius}}generate(e){let t=this.scope;return t===n.WORLD_MATRIX?this.uniformNode.nodeType="mat4":t===n.POSITION||t===n.VIEW_POSITION||t===n.DIRECTION||t===n.SCALE?this.uniformNode.nodeType="vec3":t===n.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}};Bt.WORLD_MATRIX="worldMatrix";Bt.POSITION="position";Bt.SCALE="scale";Bt.VIEW_POSITION="viewPosition";Bt.DIRECTION="direction";Bt.RADIUS="radius";var Ny=Bt,FB=te(Bt,Bt.DIRECTION).setParameterLength(1),LB=te(Bt,Bt.WORLD_MATRIX).setParameterLength(1),PB=te(Bt,Bt.POSITION).setParameterLength(1),DB=te(Bt,Bt.SCALE).setParameterLength(1),UB=te(Bt,Bt.VIEW_POSITION).setParameterLength(1),IB=te(Bt,Bt.RADIUS).setParameterLength(1);var si=class extends Ny{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}};var OB=q(si,si.DIRECTION),fr=q(si,si.WORLD_MATRIX),kB=q(si,si.POSITION),VB=q(si,si.SCALE),GB=q(si,si.VIEW_POSITION),zB=q(si,si.RADIUS),wy=Y(new et).onObjectUpdate(({object:n},e)=>e.value.getNormalMatrix(n.matrixWorld)),$B=Y(new ue).onObjectUpdate(({object:n},e)=>e.value.copy(n.matrixWorld).invert()),$r=_(n=>n.context.modelViewMatrix||Dv).once()().toVar("modelViewMatrix"),Dv=yi.mul(fr),jp=_(n=>(n.context.isHighPrecisionModelViewMatrix=!0,Y("mat4").onObjectUpdate(({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))).once()().toVar("highpModelViewMatrix"),Xp=_(n=>{let e=n.context.isHighPrecisionModelViewMatrix;return Y("mat3").onObjectUpdate(({object:t,camera:r})=>(e!==!0&&t.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix)))}).once()().toVar("highpModelNormalViewMatrix");var Uv=_(n=>n.shaderStage!=="fragment"?(he("TSL: `clipSpace` is only available in fragment stage."),X()):n.context.clipSpace.toVarying("v_clipSpace")).once()(),Ua=Mr("position","vec3"),Le=Ua.toVarying("positionLocal"),Is=Ua.toVarying("positionPrevious"),vr=_(n=>fr.mul(Le).xyz.toVarying(n.getSubBuildProperty("v_positionWorld")),"vec3").once(["POSITION"])(),Tc=_(()=>Le.transformDirection(fr).toVarying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),"vec3").once(["POSITION"])(),$e=_(n=>{if(n.shaderStage==="fragment"&&n.material.vertexNode){let e=Ty.mul(Uv);return e.xyz.div(e.w).toVar("positionView")}return n.context.setupPositionView().toVarying("v_positionView")},"vec3").once(["POSITION","VERTEX"])(),De=_(n=>{let e;return n.camera.isOrthographicCamera?e=N(0,0,1):e=$e.negate().toVarying("v_positionViewDirection").normalize(),e.toVar("positionViewDirection")},"vec3").once(["POSITION"])();var My=class extends W{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){if(e.shaderStage!=="fragment")return"true";let{material:t}=e;return t.side===Ze?"false":e.getFrontFacing()}};var Iv=q(My),Yp=y(Iv).mul(2).sub(1),Wi=_(([n],{material:e})=>{let t=e.side;return t===Ze?n=n.mul(-1):t===Kr&&(n=n.mul(Yp)),n}),WB=n=>(he('TSL: "directionToFaceDirection()" has been renamed to "negateOnBackSide()".'),Wi(n));var jl=Mr("normal","vec3"),pt=_(n=>n.geometry.hasAttribute("normal")===!1?(U('TSL: Vertex attribute "normal" not found on geometry.'),N(0,1,0)):jl,"vec3").once()().toVar("normalLocal"),Ov=$e.dFdx().cross($e.dFdy()).normalize().toVar("normalFlat"),_o=_(n=>{let e;return n.isFlatShading()?e=Ov:e=Qp(pt).toVarying("v_normalViewGeometry").normalize(),e},"vec3").once()().toVar("normalViewGeometry"),vy=_(n=>{let e=_o.transformNormalByInverseViewMatrix(yi);return n.isFlatShading()!==!0&&(e=e.toVarying("v_normalWorldGeometry")),e.normalize().toVar("normalWorldGeometry")},"vec3").once()(),ye=_(n=>{let e;return n.subBuildFn==="NORMAL"||n.subBuildFn==="VERTEX"?(e=_o,n.isFlatShading()!==!0&&(e=Wi(e))):e=n.context.setupNormal().context({getUV:null,getTextureLevel:null}),e},"vec3").once(["NORMAL","VERTEX"])().toVar("normalView"),ni=ye.transformNormalByInverseViewMatrix(yi).toVar("normalWorld"),Os=_(({subBuildFn:n,context:e})=>{let t;return n==="NORMAL"||n==="VERTEX"?t=ye:t=e.setupClearcoatNormal().context({getUV:null,getTextureLevel:null}),t},"vec3").once(["NORMAL","VERTEX"])().toVar("clearcoatNormalView"),Kp=_(([n,e=fr])=>rt(e).inverse().transpose().mul(n).normalize());P("transformNormal",Kp);var Qp=_(([n],e)=>{let t=e.context.modelNormalViewMatrix;return t?n.transformNormalByViewMatrix(t):wy.mul(n).transformNormalByViewMatrix(yi)}),HB=_(()=>(U('TSL: "transformedNormalView" is deprecated. Use "normalView" instead.'),ye)).once(["NORMAL","VERTEX"])(),qB=_(()=>(U('TSL: "transformedNormalWorld" is deprecated. Use "normalWorld" instead.'),ni)).once(["NORMAL","VERTEX"])(),jB=_(()=>(U('TSL: "transformedClearcoatNormalView" is deprecated. Use "clearcoatNormalView" instead.'),Os)).once(["NORMAL","VERTEX"])();var Ay=new ue,Ry=Y(0).onReference(({material:n})=>n).onObjectUpdate(({material:n})=>n.refractionRatio),Sc=Y(1).onReference(({material:n})=>n).onObjectUpdate(function({material:n,scene:e}){return n.envMap?n.envMapIntensity:e.environmentIntensity}),Xl=Y(new ue).onReference(function(n){return n.material}).onObjectUpdate(function({material:n,scene:e}){let r=(e.environment!==null||e.environmentNode&&e.environmentNode.isNode)&&n.envMap===null?e.environmentRotation:n.envMapRotation;return r?Ay.makeRotationFromEuler(r).transpose():Ay.identity(),Ay});var kv=De.negate().reflect(ye),Vv=De.negate().refract(ye,Ry),Cy=kv.transformDirection(bo).toVar("reflectVector"),Ey=Vv.transformDirection(bo).toVar("refractVector");var Gv=new _s,By=class extends jt{static get type(){return"CubeTextureNode"}constructor(e,t=null,r=null,i=null){super(e,t,r,i),this.isCubeTextureNode=!0}getInputType(){return this.value.isDepthTexture===!0?"cubeDepthTexture":"cubeTexture"}getDefaultUV(){let e=this.value;return e.mapping===Ji?Cy:e.mapping===$o?Ey:(I('CubeTextureNode: Mapping "%s" not supported.',e.mapping),N(0,0,0))}setUpdateMatrix(){}setupUV(e,t){let r=this.value;return r.isDepthTexture===!0?e.renderer.coordinateSystem===yt?N(t.x,t.y.negate(),t.z):t:(t=Xl.mul(t),(e.renderer.coordinateSystem===yt||!r.isRenderTargetTexture)&&(t=N(t.x.negate(),t.yz)),t)}generateUV(e,t){return t.build(e,this.sampler===!0?"vec3":"ivec3")}};var Fy=te(By).setParameterLength(1,4).setName("cubeTexture"),Ft=(n=Gv,e=null,t=null,r=null)=>{let i;return n&&n.isCubeTextureNode===!0?(i=j(n.clone()),i.referenceNode=n,e!==null&&(i.uvNode=j(e)),t!==null&&(i.levelNode=j(t)),r!==null&&(i.biasNode=j(r))):i=Fy(n,e,t,r),i},XB=(n=Gv)=>Fy(n);var Ly=class extends ri{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}generateNodeType(){return this.referenceNode.uniformType}generate(e){let t=super.generate(e),r=this.referenceNode.getNodeType(e),i=this.getNodeType(e);return e.format(t,r,i)}},Nc=class extends W{static get type(){return"ReferenceNode"}constructor(e,t,r=null,i=null){super(),this.property=e,this.uniformType=t,this.object=r,this.count=i,this.properties=e.split("."),this.reference=r,this.node=null,this.group=null,this.name=null,this.updateType=J.OBJECT}element(e){return new Ly(this,j(e))}setGroup(e){return this.group=e,this}setName(e){return this.name=e,this}label(e){return U('TSL: "label()" has been deprecated. Use "setName()" instead.'),this.setName(e)}setNodeType(e){let t=null;this.count!==null?t=Ls(null,e,this.count):Array.isArray(this.getValueFromReference())?(t=Et(null,e),t.updateType=J.OBJECT):e==="texture"?t=be(null):e==="cubeTexture"?t=Ft(null):t=Y(null,e),this.group!==null&&t.setGroup(this.group),this.name!==null&&t.setName(this.name),this.node=t}generateNodeType(e){return this.node===null&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){let{properties:t}=this,r=e[t[0]];for(let i=1;i<t.length;i++)r=r[t[i]];return r}updateReference(e){return this.reference=this.object!==null?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);let e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}},wc=Nc,ke=(n,e,t)=>new Nc(n,e,t),Py=(n,e,t,r)=>new Nc(n,e,r,t);var Dy=class extends wc{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=this.material!==null?this.material:e.material,this.reference}};var bi=(n,e,t=null)=>new Dy(n,e,t);var $v=Re(),YB=$e.dFdx(),KB=$e.dFdy(),Wv=$v.dFdx(),Hv=$v.dFdy(),qv=ye,jv=KB.cross(qv),Xv=qv.cross(YB),Uy=jv.mul(Wv.x).add(Xv.mul(Hv.x)),Iy=jv.mul(Wv.y).add(Xv.mul(Hv.y)),zv=Uy.dot(Uy).max(Iy.dot(Iy)),Yv=zv.equal(0).select(0,zv.inverseSqrt()),Kv=Uy.mul(Yv).toVar("tangentViewFrame"),Qv=Iy.mul(Yv).toVar("bitangentViewFrame");var Mc=Mr("tangent","vec4"),os=Mc.xyz.toVar("tangentLocal"),Yl=_(n=>{let e;return n.subBuildFn==="VERTEX"||n.geometry.hasAttribute("tangent")?e=$r.mul(X(os,0)).xyz.toVarying("v_tangentView").normalize():e=Kv,n.isFlatShading()!==!0&&(e=Wi(e)),e},"vec3").once(["NORMAL","VERTEX"])().toVar("tangentView"),Oy=Yl.transformDirection(bo).toVarying("v_tangentWorld").normalize().toVar("tangentWorld");var Zp=_(([n,e],t)=>{let r=n.mul(Mc.w).xyz;return t.subBuildFn==="NORMAL"&&t.isFlatShading()!==!0&&(r=r.toVarying(e)),r}).once(["NORMAL"]),QB=Zp(jl.cross(Mc),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),ZB=Zp(pt.cross(os),"v_bitangentLocal").normalize().toVar("bitangentLocal"),ky=_(n=>{let e;return n.subBuildFn==="VERTEX"||n.geometry.hasAttribute("tangent")?e=Zp(ye.cross(Yl),"v_bitangentView").normalize():e=Qv,n.isFlatShading()!==!0&&(e=Wi(e)),e},"vec3").once(["NORMAL","VERTEX"])().toVar("bitangentView"),JB=Zp(ni.cross(Oy),"v_bitangentWorld").normalize().toVar("bitangentWorld");var Rn=rt(Yl,ky,ye).toVar("TBNViewMatrix"),Zv=De.mul(Rn),eF=(n,e)=>n.sub(Zv.mul(e)),Vy=_(()=>{let n=Rs.cross(De);return n=n.cross(Rs).normalize(),n=xe(n,ye,As.mul(Sr.oneMinus()).oneMinus().pow2().pow2()).normalize(),n}).once()();var Jp=n=>j(n).mul(.5).add(.5),Jv=n=>j(n).mul(2).sub(1),ef=n=>N(n,Ct($l(y(1).sub(ar(n,n))))),tF=n=>(he('TSL: "directionToColor()" has been renamed to "packNormalToRGB()".'),Jp(n)),rF=n=>(he('TSL: "colorToDirection()" has been renamed to "unpackRGBToNormal()".'),Jv(n));var Gy=class extends _e{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=gr,this.unpackNormalMode=$d}setup(e){let{normalMapType:t,scaleNode:r,unpackNormalMode:i}=this,s=this.node.mul(2).sub(1);if(t===gr?i===Wd?s=ef(s.xy):i===lw?s=ef(s.yw):i!==$d&&I(`THREE.NodeMaterial: Unexpected unpack normal mode: ${i}`):i!==$d&&I(`THREE.NodeMaterial: Normal map type '${t}' is not compatible with unpack normal mode '${i}'`),r!==null){let a=r;e.isFlatShading()===!0&&(a=Wi(a)),s=N(s.xy.mul(a),s.z)}let o=null;return t===aw?o=Qp(s):t===gr?o=Rn.mul(s).normalize():(I(`NodeMaterial: Unsupported normal map type: ${t}`),o=ye),o}};var tf=te(Gy).setParameterLength(1,2);var iF=_(({textureNode:n,bumpScale:e})=>{let t=i=>n.isolate().context({getUV:s=>i(s.uvNode||Re()),forceUVContext:!0}),r=y(t(i=>i));return V(y(t(i=>i.add(i.dFdx()))).sub(r),y(t(i=>i.add(i.dFdy()))).sub(r)).mul(e)}),sF=_(n=>{let{surf_pos:e,surf_norm:t,dHdxy:r}=n,i=e.dFdx().normalize(),s=e.dFdy().normalize(),o=t,a=s.cross(o),l=o.cross(i),u=i.dot(a).mul(Yp),c=u.sign().mul(r.x.mul(a).add(r.y.mul(l)));return u.abs().mul(t).sub(c).normalize()}),zy=class extends _e{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(e){if(e.material.wireframe===!0)return ye;let t=this.scaleNode!==null?this.scaleNode:1,r=iF({textureNode:this.textureNode,bumpScale:t});return sF({surf_pos:$e,surf_norm:ye,dHdxy:r})}};var vc=te(zy).setParameterLength(1,2);var eA=new Map,$=class n extends W{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let r=eA.get(e);return r===void 0&&(r=bi(e,t),eA.set(e,r)),r}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache(e==="map"?"map":e+"Map","texture")}setup(e){let t=e.context.material,r=this.scope,i=null;if(r===n.COLOR){let s=t.color!==void 0?this.getColor(r):N();t.map&&t.map.isTexture===!0?i=s.mul(this.getTexture("map")):i=s}else if(r===n.OPACITY){let s=this.getFloat(r);t.alphaMap&&t.alphaMap.isTexture===!0?i=s.mul(this.getTexture("alpha")):i=s}else if(r===n.SPECULAR_STRENGTH)t.specularMap&&t.specularMap.isTexture===!0?i=this.getTexture("specular").r:i=y(1);else if(r===n.SPECULAR_INTENSITY){let s=this.getFloat(r);t.specularIntensityMap&&t.specularIntensityMap.isTexture===!0?i=s.mul(this.getTexture(r).a):i=s}else if(r===n.SPECULAR_COLOR){let s=this.getColor(r);t.specularColorMap&&t.specularColorMap.isTexture===!0?i=s.mul(this.getTexture(r).rgb):i=s}else if(r===n.ROUGHNESS){let s=this.getFloat(r);t.roughnessMap&&t.roughnessMap.isTexture===!0?i=s.mul(this.getTexture(r).g):i=s}else if(r===n.METALNESS){let s=this.getFloat(r);t.metalnessMap&&t.metalnessMap.isTexture===!0?i=s.mul(this.getTexture(r).b):i=s}else if(r===n.EMISSIVE){let s=this.getFloat("emissiveIntensity"),o=this.getColor(r).mul(s);t.emissiveMap&&t.emissiveMap.isTexture===!0?i=o.mul(this.getTexture(r)):i=o}else if(r===n.NORMAL)t.normalMap?(i=tf(this.getTexture("normal"),this.getCache("normalScale","vec2")),i.normalMapType=t.normalMapType,(t.normalMap.format==vt||t.normalMap.format==ln||t.normalMap.format==an)&&(i.unpackNormalMode=Wd)):t.bumpMap?i=vc(this.getTexture("bump").r,this.getFloat("bumpScale")):i=ye;else if(r===n.CLEARCOAT){let s=this.getFloat(r);t.clearcoatMap&&t.clearcoatMap.isTexture===!0?i=s.mul(this.getTexture(r).r):i=s}else if(r===n.CLEARCOAT_ROUGHNESS){let s=this.getFloat(r);t.clearcoatRoughnessMap&&t.clearcoatRoughnessMap.isTexture===!0?i=s.mul(this.getTexture(r).r):i=s}else if(r===n.CLEARCOAT_NORMAL)t.clearcoatNormalMap?i=tf(this.getTexture(r),this.getCache(r+"Scale","vec2")):i=ye;else if(r===n.SHEEN){let s=this.getColor("sheenColor").mul(this.getFloat("sheen"));t.sheenColorMap&&t.sheenColorMap.isTexture===!0?i=s.mul(this.getTexture("sheenColor").rgb):i=s}else if(r===n.SHEEN_ROUGHNESS){let s=this.getFloat(r);t.sheenRoughnessMap&&t.sheenRoughnessMap.isTexture===!0?i=s.mul(this.getTexture(r).a):i=s,i=i.clamp(1e-4,1)}else if(r===n.ANISOTROPY)if(t.anisotropyMap&&t.anisotropyMap.isTexture===!0){let s=this.getTexture(r);i=Fl(Kl.x,Kl.y,Kl.y.negate(),Kl.x).mul(s.rg.mul(2).sub(V(1)).normalize().mul(s.b))}else i=Kl;else if(r===n.IRIDESCENCE_THICKNESS){let s=ke("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){let o=ke("0","float",t.iridescenceThicknessRange);i=s.sub(o).mul(this.getTexture(r).g).add(o)}else i=s}else if(r===n.TRANSMISSION){let s=this.getFloat(r);t.transmissionMap?i=s.mul(this.getTexture(r).r):i=s}else if(r===n.THICKNESS){let s=this.getFloat(r);t.thicknessMap?i=s.mul(this.getTexture(r).g):i=s}else if(r===n.IOR)i=this.getFloat(r);else if(r===n.LIGHT_MAP)t.lightMap?i=this.getTexture(r).rgb.mul(this.getFloat("lightMapIntensity")):i=N(0);else if(r===n.AO)t.aoMap?i=this.getTexture(r).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1):i=y(1);else if(r===n.LINE_DASH_OFFSET)i=t.dashOffset?this.getFloat(r):y(0);else{let s=this.getNodeType(e);i=this.getCache(r,s)}return i}};$.ALPHA_TEST="alphaTest";$.COLOR="color";$.OPACITY="opacity";$.SHININESS="shininess";$.SPECULAR="specular";$.SPECULAR_STRENGTH="specularStrength";$.SPECULAR_INTENSITY="specularIntensity";$.SPECULAR_COLOR="specularColor";$.REFLECTIVITY="reflectivity";$.ROUGHNESS="roughness";$.METALNESS="metalness";$.NORMAL="normal";$.CLEARCOAT="clearcoat";$.CLEARCOAT_ROUGHNESS="clearcoatRoughness";$.CLEARCOAT_NORMAL="clearcoatNormal";$.EMISSIVE="emissive";$.ROTATION="rotation";$.SHEEN="sheen";$.SHEEN_ROUGHNESS="sheenRoughness";$.ANISOTROPY="anisotropy";$.IRIDESCENCE="iridescence";$.IRIDESCENCE_IOR="iridescenceIOR";$.IRIDESCENCE_THICKNESS="iridescenceThickness";$.IOR="ior";$.TRANSMISSION="transmission";$.THICKNESS="thickness";$.ATTENUATION_DISTANCE="attenuationDistance";$.ATTENUATION_COLOR="attenuationColor";$.LINE_SCALE="scale";$.LINE_DASH_SIZE="dashSize";$.LINE_GAP_SIZE="gapSize";$.LINE_WIDTH="linewidth";$.LINE_DASH_OFFSET="dashOffset";$.POINT_SIZE="size";$.DISPERSION="dispersion";$.RETROREFLECTIVE="retroreflective";$.LIGHT_MAP="light";$.AO="ao";var $y=$,Wy=q($,$.ALPHA_TEST),Hy=q($,$.COLOR),qy=q($,$.SHININESS),jy=q($,$.EMISSIVE),Ac=q($,$.OPACITY),Xy=q($,$.SPECULAR),rf=q($,$.SPECULAR_INTENSITY),Yy=q($,$.SPECULAR_COLOR),Ia=q($,$.SPECULAR_STRENGTH),Rc=q($,$.REFLECTIVITY),Ky=q($,$.ROUGHNESS),Qy=q($,$.METALNESS),Zy=q($,$.NORMAL),Jy=q($,$.CLEARCOAT),eb=q($,$.CLEARCOAT_ROUGHNESS),tb=q($,$.CLEARCOAT_NORMAL),rb=q($,$.ROTATION),ib=q($,$.SHEEN),sb=q($,$.SHEEN_ROUGHNESS),nb=q($,$.ANISOTROPY),ob=q($,$.IRIDESCENCE),ab=q($,$.IRIDESCENCE_IOR),lb=q($,$.IRIDESCENCE_THICKNESS),ub=q($,$.TRANSMISSION),cb=q($,$.THICKNESS),db=q($,$.IOR),hb=q($,$.ATTENUATION_DISTANCE),pb=q($,$.ATTENUATION_COLOR),fb=q($,$.LINE_SCALE),mb=q($,$.LINE_DASH_SIZE),gb=q($,$.LINE_GAP_SIZE),nF=q($,$.LINE_WIDTH),xb=q($,$.LINE_DASH_OFFSET),yb=q($,$.POINT_SIZE),bb=q($,$.DISPERSION),_b=q($,$.RETROREFLECTIVE),Cc=q($,$.LIGHT_MAP),Tb=q($,$.AO),Kl=Y(new se).onReference(function(n){return n.material}).onRenderUpdate(function({material:n}){this.value.set(n.anisotropy*Math.cos(n.anisotropyRotation),n.anisotropy*Math.sin(n.anisotropyRotation))});var Sb=_(n=>n.context.setupModelViewProjection(),"vec4").once()().toVarying("v_modelViewProjection");var kt=class n extends W{static get type(){return"EventNode"}constructor(e,t){super("void"),this.eventType=e,this.callback=t,e===n.OBJECT?this.updateType=J.OBJECT:e===n.MATERIAL?this.updateType=J.RENDER:e===n.FRAME?this.updateType=J.FRAME:e===n.BEFORE_OBJECT?this.updateBeforeType=J.OBJECT:e===n.BEFORE_MATERIAL?this.updateBeforeType=J.RENDER:e===n.BEFORE_FRAME&&(this.updateBeforeType=J.FRAME)}setup(e){let{eventType:t,callback:r}=this;if(t===n.BEFORE_RENDER_PIPELINE){let i=e.context.onBeforePipelineCallbacks;i&&i.push(r)}else if(t===n.AFTER_RENDER_PIPELINE){let i=e.context.onAfterPipelineCallbacks;i&&i.push(r)}return super.setup(e)}update(e){this.callback(e)}updateBefore(e){this.callback(e)}};kt.OBJECT="object";kt.MATERIAL="material";kt.FRAME="frame";kt.BEFORE_OBJECT="beforeObject";kt.BEFORE_MATERIAL="beforeMaterial";kt.BEFORE_FRAME="beforeFrame";kt.BEFORE_RENDER_PIPELINE="beforeRenderPipeline";kt.AFTER_RENDER_PIPELINE="afterRenderPipeline";var sf=kt,To=(n,e)=>new kt(n,e).toStack(),So=n=>To(kt.OBJECT,n),oF=n=>To(kt.MATERIAL,n),Nb=n=>To(kt.FRAME,n),aF=n=>To(kt.BEFORE_OBJECT,n),lF=n=>To(kt.BEFORE_MATERIAL,n),uF=n=>To(kt.BEFORE_FRAME,n),cF=n=>To(kt.BEFORE_RENDER_PIPELINE,n),dF=n=>To(kt.AFTER_RENDER_PIPELINE,n);var wb=class extends ri{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){let r=this.storageBufferNode.structTypeNode;return r?r.getMemberType(e,t):"void"}setup(e){return e.isAvailable("storageBuffer")===!1&&this.node.isPBO===!0&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let r,i=e.isContextAssign();if(e.isAvailable("storageBuffer")===!1?this.node.isPBO===!0&&i!==!0&&(this.node.value.isInstancedBufferAttribute||e.shaderStage!=="compute")?r=e.generatePBO(this):r=this.node.build(e):r=super.generate(e),i!==!0){let s=this.getNodeType(e);r=e.format(r,s,t)}return r}};var tA=te(wb).setParameterLength(2);var Mb=class extends yc{static get type(){return"StorageBufferNode"}constructor(e,t=null,r=0){let i,s=null;t&&t.isStructTypeNode?(i="struct",s=t,(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(r=e.count)):t===null&&(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)?(i=qu(e.itemSize),r=e.count):i=t,super(e,i,r),this.isStorageBufferNode=!0,this.structTypeNode=s,this.access=mt.READ_WRITE,this.isAtomic=!1,this.isPBO=!1,this._attribute=null,this._varying=null,this.global=!0,e.isStorageBufferAttribute!==!0&&e.isStorageInstancedBufferAttribute!==!0&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){let t;if(this.bufferCount===0){let r=e.globalCache.getData(this.value);r===void 0&&(r={node:this},e.globalCache.setData(this.value,r)),t=r.node.id}else t=this.id;return String(t)}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return tA(this,e)}setPBO(e){return this.isPBO=e,this}getPBO(){return this.isPBO}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(mt.READ_ONLY)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return this._attribute===null&&(this._attribute=Bp(this.value),this._varying=xi(this._attribute)),{attribute:this._attribute,varying:this._varying}}generateNodeType(e){if(this.structTypeNode!==null)return this.structTypeNode.getNodeType(e);if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generateNodeType(e);let{attribute:t}=this.getAttributeData();return t.getNodeType(e)}getMemberType(e,t){return this.structTypeNode!==null?this.structTypeNode.getMemberType(e,t):"void"}generate(e){if(this.structTypeNode!==null&&this.structTypeNode.build(e),e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);let{attribute:t,varying:r}=this.getAttributeData(),i=r.build(e);return e.registerTransform(i,t),i}};var as=(n,e=null,t=0)=>new Mb(n,e,t);var vb=new WeakMap,rA=new WeakMap,Ab=new WeakMap;function iA(n,e){let t,r=Math.max(e.count,1);if(e.isStorageInstancedBufferAttribute===!0)t=as(e,"mat4",r).element(cr);else if(r*16*4<=n.getUniformBufferLimit())t=Ls(e.array,"mat4",r).element(cr);else{let o=vb.get(e);o||(o=new Aa(e.array,16,1),vb.set(e,o));let a=e.usage===eo?Fp:Hl,l=[a(o,"vec4",16,0),a(o,"vec4",16,4),a(o,"vec4",16,8),a(o,"vec4",16,12)];t=Gi(...l)}return t}function hF(n,e,t){let r=Ab.get(n);if(r===void 0){let i=e.clone();r={previousInstanceMatrix:i,node:iA(t,i)},Ab.set(n,r)}return r.node}var nf=tc("vec3","vInstanceColor"),sA=_(([n,e=null],t)=>{let r=n.isStorageInstancedBufferAttribute===!0,i=e&&e.isStorageInstancedBufferAttribute===!0,s=iA(t,n),o=null;r||Math.max(n.count,1)*16*4>t.getUniformBufferLimit()&&(o=vb.get(n));let a=null,l=null;if(e)if(i)a=as(e,"vec3",Math.max(e.count,1)).element(cr);else{let c=rA.get(e);c||(c=new Ui(e.array,3),rA.set(e,c)),l=c;let d=e.usage===eo?Fp:Hl;a=N(d(c,"vec3",3,0))}(o!==null||l!==null)&&Nb(()=>{o!==null&&o.version!==n.version&&(o.clearUpdateRanges(),o.updateRanges.push(...n.updateRanges),n.clearUpdateRanges(),o.version=n.version),e&&l!==null&&l.version!==e.version&&(l.clearUpdateRanges(),l.updateRanges.push(...e.updateRanges),e.clearUpdateRanges(),l.version=e.version)});let u=s.mul(Le).xyz;if(Le.assign(u),t.needsPreviousData()){let c=t.object;So(({object:h})=>{Ab.get(h).previousInstanceMatrix.array.set(n.array)});let d=hF(c,n,t);Is.assign(d.mul(Is).xyz)}if(t.hasGeometryAttribute("normal")){let c=Kp(pt,s);pt.assign(c)}a!==null&&nf.assign(a)},"void"),Rb=_(([n])=>{let{instanceMatrix:e,instanceColor:t}=n;sA(e,t)},"void");var pF=_(([n,e])=>{let t=A(Fs(at(n),0).x).toConst(),r=A(e),i=r.mod(t).toConst(),s=r.div(t).toConst();return at(n,dt(i,s))}),fF=_(([n,e])=>{let t=A(Fs(at(n),0).x).toConst(),r=A(e).mod(t).toConst(),i=A(e).div(t).toConst();return at(n,dt(r,i)).x}),of=tc("vec4","vBatchColor"),Cb=_(([n],e)=>{let t=e.getDrawIndex()===null?cr:jx,r=fF(n._indirectTexture,A(t)),i=n._matricesTexture,s=A(Fs(at(i),0).x).toConst(),o=y(r).mul(4).toInt().toConst(),a=o.mod(s).toConst(),l=o.div(s).toConst(),u=Gi(at(i,dt(a,l)),at(i,dt(a.add(1),l)),at(i,dt(a.add(2),l)),at(i,dt(a.add(3),l))),c=n._colorsTexture;if(c!==null){let f=pF(c,r);of.assign(f)}let d=rt(u);Le.assign(u.mul(Le));let h=pt.div(N(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),p=d.mul(h).xyz;pt.assign(p),e.hasGeometryAttribute("tangent")&&os.mulAssign(d)},"void");var af=new WeakMap,lf=new WeakMap;function Eb(n,e,t,r,i,s){let o=n.element(i.x),a=n.element(i.y),l=n.element(i.z),u=n.element(i.w),c=t.mul(e),d=Xe(o.mul(s.x).mul(c),a.mul(s.y).mul(c),l.mul(s.z).mul(c),u.mul(s.w).mul(c));return r.mul(d).xyz}function nA(n,e,t,r,i,s,o){let a=n.element(s.x),l=n.element(s.y),u=n.element(s.z),c=n.element(s.w),d=Xe(o.x.mul(a),o.y.mul(l),o.z.mul(u),o.w.mul(c));d=i.mul(d).mul(r);let h=rt(d),p=h.mul(e),f=h.mul(t);return{skinNormal:p,skinTangent:f}}function oA(n,e,t,r,i){let s=n.skeleton,o=lf.get(s);if(o===void 0){s.update();let a=new Float32Array(s.boneMatrices);o={previousBoneMatrices:a,node:Ls(a,"mat4",s.bones.length)},lf.set(s,o)}return Eb(o.node,Is,e,t,r,i)}var Bb=_(([n],e)=>{let t=Mr("skinIndex","uvec4"),r=Mr("skinWeight","vec4"),i=ke("bindMatrix","mat4"),s=ke("bindMatrixInverse","mat4"),o=Py("skeleton.boneMatrices","mat4",n.skeleton.bones.length);if(So(({object:l,frameId:u})=>{let c=l.skeleton;if(af.get(c)!==u){af.set(c,u);let d=lf.get(c);d!==void 0&&d.previousBoneMatrices.set(c.boneMatrices),c.update()}}),e.needsPreviousData()){let l=oA(n,i,s,t,r);Is.assign(l)}let a=Eb(o,Le,i,s,t,r);if(Le.assign(a),e.hasGeometryAttribute("normal")){let{skinNormal:l,skinTangent:u}=nA(o,pt,os,i,s,t,r);pt.assign(l),e.hasGeometryAttribute("tangent")&&os.assign(u)}},"void"),mF=_(([n,e=null],t)=>{let r=as(new Ui(n.geometry.getAttribute("position").array,3),"vec3").setPBO(!0).toReadOnly().element(cr).toVar(),i=as(new Ui(new Uint32Array(n.geometry.getAttribute("skinIndex").array),4),"uvec4").setPBO(!0).toReadOnly().element(cr).toVar(),s=as(new Ui(n.geometry.getAttribute("skinWeight").array,4),"vec4").setPBO(!0).toReadOnly().element(cr).toVar(),o=Y(n.bindMatrix,"mat4"),a=Y(n.bindMatrixInverse,"mat4"),l=Ls(n.skeleton.boneMatrices,"mat4",n.skeleton.bones.length),u=n.skeleton;if(So(({frameId:d})=>{if(af.get(u)!==d){af.set(u,d);let h=lf.get(u);h!==void 0&&h.previousBoneMatrices.set(u.boneMatrices),u.update()}}),t.needsPreviousData()){let d=oA(n,o,a,i,s);Is.assign(d)}let c=Eb(l,r,o,a,i,s);if(e!==null&&e.assign(c),t.hasGeometryAttribute("normal")){let{skinNormal:d,skinTangent:h}=nA(l,pt,os,o,a,i,s);pt.assign(d),t.hasGeometryAttribute("tangent")&&os.assign(h)}return c});var Fb=class extends W{static get type(){return"LoopNode"}constructor(e=[]){super("void"),this.params=e}getVarName(e){return String.fromCharCode(105+e)}getProperties(e){let t=e.getNodeProperties(this);if(t.stackNode!==void 0)return t;let r={};for(let a=0,l=this.params.length-1;a<l;a++){let u=this.params[a],c=u.isNode!==!0&&u.name||this.getVarName(a),d=u.isNode!==!0&&u.type||"int";r[c]=dr(c,d)}let i=e.addStack(),s=this.params[this.params.length-1](r);t.returnsNode=s.context({nodeLoop:s}),t.stackNode=i;let o=this.params[0];if(o.isNode!==!0&&typeof o.update=="function"){let a=_(this.params[0].update)(r);t.updateNode=a.context({nodeLoop:a})}return e.removeStack(),t}setup(e){if(this.getProperties(e),e.fnCall){let t=e.getDataFromNode(e.fnCall.shaderNode);t.hasLoop=!0}}generate(e){let t=this.getProperties(e),r=this.params,i=t.stackNode;for(let o=0,a=r.length-1;o<a;o++){let l=r[o],u=!1,c=null,d=null,h=null,p=null,f=null,m=null;l.isNode?l.getNodeType(e)==="bool"?(u=!0,p="bool",d=l.build(e,p)):(p="int",h=this.getVarName(o),c="0",d=l.build(e,p),f="<"):(p=l.type||"int",h=l.name||this.getVarName(o),c=l.start,d=l.end,f=l.condition,m=l.update,typeof c=="number"?c=e.generateConst(p,c):c&&c.isNode&&(c=c.build(e,p)),typeof d=="number"?d=e.generateConst(p,d):d&&d.isNode&&(d=d.build(e,p)),c!==void 0&&d===void 0?(c=c+" - 1",d="0",f=">="):d!==void 0&&c===void 0&&(c="0",f="<"),f===void 0&&(Number(c)>Number(d)?f=">=":f="<"));let g;if(u)g=`while ( ${d} )`;else{let x={start:c,end:d,condition:f},w=x.start,v=x.end,E,b=()=>f.includes("<")?"+=":"-=";if(m!=null)switch(typeof m){case"function":E=e.flowStagesNode(t.updateNode,"void").code.replace(/\t|;/g,"");break;case"number":E=h+" "+b()+" "+e.generateConst(p,m);break;case"string":E=h+" "+m;break;default:m.isNode?E=h+" "+b()+" "+m.build(e):(I("TSL: 'Loop( { update: ... } )' is not a function, string or number.",this.stackTrace),E="break /* invalid update */")}else p==="int"||p==="uint"?m=f.includes("<")?"++":"--":m=b()+" 1.",E=h+" "+m;let S=e.getVar(p,h)+" = "+w,T=h+" "+f+" "+v;g=`for ( ${S}; ${T}; ${E} )`}e.addFlowCode((o===0?` | |
| `:"")+e.tab+g+` { | |
| `).addFlowTab()}let s=i.build(e,"void");t.returnsNode.build(e,"void"),e.removeFlowTab().addFlowCode(` | |
| `+e.tab+s);for(let o=0,a=this.params.length-1;o<a;o++)e.addFlowCode((o===0?"":e.tab)+`} | |
| `).removeFlowTab();e.addFlowTab()}};var Ee=(...n)=>new Fb(_n(n,"int")).toStack(),gF=()=>dr("continue").toStack(),xF=()=>dr("break").toStack();var Lb=new WeakMap,_i=new pe,aA=new WeakMap,lA=_(({bufferMap:n,influence:e,stride:t,width:r,depth:i,offset:s})=>{let o=A(ql).mul(t).add(s),a=o.div(r),l=o.sub(a.mul(r));return at(n,dt(l,a)).depth(i).xyz.mul(e)});function yF(n){let e=n.morphAttributes.position!==void 0,t=n.morphAttributes.normal!==void 0,r=n.morphAttributes.color!==void 0,i=n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color,s=i!==void 0?i.length:0,o=Lb.get(n);if(o===void 0||o.count!==s){let x=function(){m.dispose(),Lb.delete(n),n.removeEventListener("dispose",x)};o!==void 0&&o.texture.dispose();let a=n.morphAttributes.position||[],l=n.morphAttributes.normal||[],u=n.morphAttributes.color||[],c=0;e===!0&&(c=1),t===!0&&(c=2),r===!0&&(c=3);let d=n.attributes.position.count*c,h=1,p=4096;d>p&&(h=Math.ceil(d/p),d=p);let f=new Float32Array(d*h*4*s),m=new Ta(f,d,h,s);m.type=ze,m.needsUpdate=!0;let g=c*4;for(let w=0;w<s;w++){let v=a[w],E=l[w],b=u[w],S=d*h*4*w;for(let T=0;T<v.count;T++){let M=T*g;e===!0&&(_i.fromBufferAttribute(v,T),f[S+M+0]=_i.x,f[S+M+1]=_i.y,f[S+M+2]=_i.z,f[S+M+3]=0),t===!0&&(_i.fromBufferAttribute(E,T),f[S+M+4]=_i.x,f[S+M+5]=_i.y,f[S+M+6]=_i.z,f[S+M+7]=0),r===!0&&(_i.fromBufferAttribute(b,T),f[S+M+8]=_i.x,f[S+M+9]=_i.y,f[S+M+10]=_i.z,f[S+M+11]=b.itemSize===4?_i.w:1)}}o={count:s,texture:m,stride:c,size:new se(d,h)},Lb.set(n,o),n.addEventListener("dispose",x)}return o}var Pb=_(([n])=>{let{geometry:e}=n,t=e.morphAttributes.position!==void 0,r=e.hasAttribute("normal")&&e.morphAttributes.normal!==void 0,i=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,s=i!==void 0?i.length:0;if(s===0)return;let o=aA.get(n);(o===void 0||o.count!==s)&&(o={base:Y(1),influences:n.morphTargetInfluences?Et(n.morphTargetInfluences,"float"):null,count:s},aA.set(n,o));let{base:a,influences:l}=o,{texture:u,stride:c,size:d}=yF(e);t===!0&&Le.mulAssign(a),r===!0&&pt.mulAssign(a);let h=A(d.width);Ee(s,({i:p})=>{let f=y(0).toVar();n.count>1&&n.morphTexture!==null&&n.morphTexture!==void 0?f.assign(at(n.morphTexture,dt(A(p).add(1),A(cr))).r):f.assign(l.element(p).toVar()),ie(f.notEqual(0),()=>{t===!0&&Le.addAssign(lA({bufferMap:u,influence:f,stride:c,width:h,depth:p,offset:A(0)})),r===!0&&pt.addAssign(lA({bufferMap:u,influence:f,stride:c,width:h,depth:p,offset:A(1)}))})}),So(({object:p})=>{let{base:f,influences:m}=o;p.geometry.morphTargetsRelative?f.value=1:f.value=1-p.morphTargetInfluences.reduce((g,x)=>g+x,0),m&&(m.array=p.morphTargetInfluences,m.update())})},"void");var Db=class extends W{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}},Ti=Db;var Ub=class extends Ti{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}},Ib=Ub;var Ob=class extends dc{static get type(){return"LightingContextNode"}constructor(e,t=null,r=[],i=null,s=null){super(e),this.lightingModel=t,this.materialLightings=r,this.backdropNode=i,this.backdropAlphaNode=s,this._value=null}getContext(){let{materialLightings:e,backdropNode:t,backdropAlphaNode:r}=this,i=N().toVar("directDiffuse"),s=N().toVar("directSpecular"),o=N().toVar("indirectDiffuse"),a=N().toVar("indirectSpecular"),l={directDiffuse:i,directSpecular:s,indirectDiffuse:o,indirectSpecular:a};return{radiance:N().toVar("radiance"),irradiance:N().toVar("irradiance"),iblIrradiance:N().toVar("iblIrradiance"),ambientOcclusion:y(1).toVar("ambientOcclusion"),reflectedLight:l,materialLightings:e,backdrop:t,backdropAlpha:r}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}};var kb=te(Ob);var Vb=class extends Ti{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}},Gb=Vb;var Oa=new se,Ec=class extends jt{static get type(){return"ViewportTextureNode"}constructor(e=pr,t=null,r=null){let i=null;r===null?(i=new lo,i.minFilter=Ur,r=i):i=r,super(r,e,t),this.generateMipmaps=!1,this.defaultFramebuffer=i,this.isOutputTextureNode=!0,this.updateBeforeType=J.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),e===null)return t;if(r.has(e)===!1){let i=t.clone();r.set(e,i)}return r.get(e)}updateReference(e){let t=e.renderer,r=t.getRenderTarget(),i=t.getCanvasTarget(),s=r||i;return this.value=this.getTextureForReference(s),this.value}updateBefore(e){let t=e.renderer,r=t.getRenderTarget(),i=t.getCanvasTarget(),s=r||i;s===null?t.getDrawingBufferSize(Oa):s.getDrawingBufferSize?s.getDrawingBufferSize(Oa):Oa.set(s.width,s.height);let o=this.getTextureForReference(s);(o.image.width!==Oa.width||o.image.height!==Oa.height)&&(o.image.width=Oa.width,o.image.height=Oa.height,o.needsUpdate=!0);let a=o.generateMipmaps;o.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(o),o.generateMipmaps=a}clone(){let e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}},Bc=Ec,bF=te(Ec).setParameterLength(0,3),uf=te(Ec,null,null,{generateMipmaps:!0}).setParameterLength(0,3),_F=uf(),zb=(n=pr,e=null)=>_F.sample(n,e);var $b=null,Wb=class extends Bc{static get type(){return"ViewportDepthTextureNode"}constructor(e=pr,t=null,r=null){r===null&&($b===null&&($b=new ot),r=$b),super(e,t,r)}};var Fc=te(Wb).setParameterLength(0,3);var ls=class n extends W{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){let{scope:t}=this;return t===n.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){let{scope:t}=this,r=this.valueNode,i=null;if(t===n.DEPTH_BASE)r!==null&&(i=uA().assign(r));else if(t===n.DEPTH)e.isPerspectiveCamera?i=cf($e.z,Ds,Us):i=ks($e.z,Ds,Us);else if(t===n.LINEAR_DEPTH)if(r!==null)if(e.isPerspectiveCamera){let s=Ql(r,Ds,Us);i=ks(s,Ds,Us)}else i=r;else i=ks($e.z,Ds,Us);return i}};ls.DEPTH_BASE="depthBase";ls.DEPTH="depth";ls.LINEAR_DEPTH="linearDepth";var ks=(n,e,t)=>n.add(e).div(e.sub(t)),TF=(n,e,t)=>n.add(t).div(t.sub(e)),Hb=_(([n,e,t],r)=>r.renderer.reversedDepthBuffer===!0?t.sub(e).mul(n).sub(t):e.sub(t).mul(n).sub(e)),cf=(n,e,t)=>e.add(n).mul(t).div(t.sub(e).mul(n)),qb=(n,e,t)=>e.mul(n.add(t)).div(n.mul(e.sub(t))),Ql=_(([n,e,t],r)=>r.renderer.reversedDepthBuffer===!0?e.mul(t).div(e.sub(t).mul(n).sub(e)):e.mul(t).div(t.sub(e).mul(n).sub(t))),ka=(n,e,t)=>{e=e.max(1e-6).toVar();let r=kr(n.negate().div(e)),i=kr(t.div(e));return r.div(i)},SF=(n,e,t)=>{let r=n.mul(go(t.div(e)));return y(Math.E).pow(r).mul(e).negate()},uA=te(ls,ls.DEPTH_BASE),df=q(ls,ls.DEPTH),Lc=te(ls,ls.LINEAR_DEPTH).setParameterLength(0,1),NF=Lc(Fc());df.assign=n=>uA(n);var Vs=class n extends W{static get type(){return"ClippingNode"}constructor(e=n.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);let t=e.clippingContext,{intersectionPlanes:r,unionPlanes:i}=t;return this.hardwareClipping=e.hardwareClipping,this.scope===n.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(r,i):this.scope===n.HARDWARE?this.setupHardwareClipping(i,e):this.setupDefault(r,i)}setupAlphaToCoverage(e,t){return _(()=>{let r=y().toVar("distanceToPlane"),i=y().toVar("distanceToGradient"),s=y(1).toVar("clipOpacity"),o=t.length;if(this.hardwareClipping===!1&&o>0){let l=Et(t).setGroup(ee);Ee(o,({i:u})=>{let c=l.element(u);r.assign($e.dot(c.xyz).negate().add(c.w)),i.assign(r.fwidth().div(2)),s.mulAssign(Wt(i.negate(),i,r))})}let a=e.length;if(a>0){let l=Et(e).setGroup(ee),u=y(1).toVar("intersectionClipOpacity");Ee(a,({i:c})=>{let d=l.element(c);r.assign($e.dot(d.xyz).negate().add(d.w)),i.assign(r.fwidth().div(2)),u.mulAssign(Wt(i.negate(),i,r).oneMinus())}),s.mulAssign(u.oneMinus())}ve.a.mulAssign(s),ve.a.equal(0).discard()})()}setupDefault(e,t){return _(()=>{let r=t.length;if(this.hardwareClipping===!1&&r>0){let s=Et(t).setGroup(ee);Ee(r,({i:o})=>{let a=s.element(o);$e.dot(a.xyz).greaterThan(a.w).discard()})}let i=e.length;if(i>0){let s=Et(e).setGroup(ee),o=nr(!0).toVar("clipped");Ee(i,({i:a})=>{let l=s.element(a);o.assign($e.dot(l.xyz).greaterThan(l.w).and(o))}),o.discard()}})()}setupHardwareClipping(e,t){let r=e.length;return t.enableHardwareClipping(r),_(()=>{let i=Et(e).setGroup(ee),s=$i(t.getClipDistance());Ee(r,({i:o})=>{let a=i.element(o),l=$e.dot(a.xyz).sub(a.w).negate();s.element(o).assign(l)})})()}};Vs.ALPHA_TO_COVERAGE="alphaToCoverage";Vs.DEFAULT="default";Vs.HARDWARE="hardware";var cA=()=>new Vs,dA=()=>new Vs(Vs.ALPHA_TO_COVERAGE),hA=()=>new Vs(Vs.HARDWARE);var wF=.05,pA=_(([n])=>ii(ce(1e4,Tt(ce(17,n.x).add(ce(.1,n.y)))).mul(Xe(.1,Ue(Tt(ce(13,n.y).add(n.x))))))),fA=_(([n])=>pA(V(pA(n.xy),n.z))),MF=_(([n])=>{let e=Ie(mi(bp(n.xyz)),mi(_p(n.xyz))),t=y(1).div(y(wF).mul(e)).toVar("pixScale"),r=V(mo(Vr(kr(t))),mo(zl(kr(t)))),i=V(fA(Vr(r.x.mul(n.xyz))),fA(Vr(r.y.mul(n.xyz)))),s=ii(kr(t)),o=Xe(ce(s.oneMinus(),i.x),ce(s,i.y)),a=ht(s,s.oneMinus()),l=N(o.mul(o).div(ce(2,a).mul(Se(1,a))),o.sub(ce(.5,a)).div(Se(1,a)),Se(1,Se(1,o).mul(Se(1,o)).div(ce(2,a).mul(Se(1,a))))),u=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(l.x,l.y),l.z);return ur(u,1e-6,1)}).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]}),mA=MF;var jb=class extends sy{static get type(){return"VertexColorNode"}constructor(e){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){let e=this.index;return"color"+(e>0?e:"")}generate(e){let t=this.getAttributeName(e),r=e.hasGeometryAttribute(t),i;return r===!0?i=super.generate(e):i=e.generateConst(this.nodeType,new pe(1,1,1,1)),i}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}};var Xb=(n=0)=>new jb(n);var Yb=class extends st{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.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(){let e=[];for(let t of Object.getOwnPropertyNames(this)){if(t.startsWith("_")===!0)continue;let r=this[t];r&&r.isNode===!0&&e.push({property:t,childNode:r})}return e}customProgramCacheKey(){let e=[];for(let{property:t,childNode:r}of this._getNodeChildren())e.push(Ii(t.slice(0,-4)),r.getCacheKey());return this.type+Ns(e)}build(e){this.setup(e)}setupObserver(e){return new Hu(e)}setup(e){e.context.setupNormal=()=>Es(this.setupNormal(e),"NORMAL","vec3"),e.context.setupPositionView=()=>this.setupPositionView(e),e.context.setupModelViewProjection=()=>this.setupModelViewProjection(e);let t=e.renderer,r=t.getRenderTarget();e.addStack();let i=this.setupVertex(e),s=Es(this.vertexNode||i,"VERTEX");e.context.clipSpace=s,e.stack.outputNode=s,this.setupHardwareClipping(e),this.geometryNode!==null&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();let o,a=this.setupClipping(e);if((this.depthWrite===!0||this.depthTest===!0)&&(r!==null?r.depthBuffer===!0&&this.setupDepth(e):t.depth===!0&&this.setupDepth(e)),this.fragmentNode===null){this.setupDiffuseColor(e),this.setupAmbientOcclusion(e),this.setupVariants(e);let l=this.setupLighting(e);a!==null&&e.stack.addToStack(a);let u=X(l,ve.a).max(0);o=this.setupOutput(e,u),fo.assign(o);let c=this.outputNode!==null;if(c&&(o=this.outputNode),e.context.getOutput&&(o=e.context.getOutput(o,e)),r!==null){let d=t.getMRT(),h=this.mrtNode;d!==null?(c&&fo.assign(o),o=d,h!==null&&(o=d.merge(h))):h!==null&&(o=h)}}else{let l=this.fragmentNode;l.isOutputStructNode!==!0&&(l=l.convert(e.getOutputType())),o=this.setupOutput(e,l)}e.stack.outputNode=o,e.addFlow("fragment",e.removeStack()),e.observer=this.setupObserver(e)}setupClipping(e){if(e.clippingContext===null)return null;let{unionPlanes:t,intersectionPlanes:r}=e.clippingContext,i=null;if(t.length>0||r.length>0){let s=e.renderer.currentSamples;this.alphaToCoverage&&s>1?i=dA():e.stack.addToStack(cA())}return i}setupHardwareClipping(e){if(e.hardwareClipping=!1,e.clippingContext===null)return;let t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.addToStack(hA()),e.hardwareClipping=!0)}setupDepth(e){let{renderer:t,camera:r}=e,i=this.depthNode;if(i===null){let s=t.getMRT();s&&s.has("depth")?i=s.get("depth"):t.logarithmicDepthBuffer===!0&&(r.isPerspectiveCamera?i=ka($e.z,Ds,Us):i=ks($e.z,Ds,Us))}i!==null&&df.assign(i).toStack()}setupPositionView(){return $r.mul(Le).xyz}setupModelViewProjection(){return zr.mul($e)}setupVertex(e){return e.addStack(),this.setupPosition(e),e.context.position=e.removeStack(),Sb}setupPosition(e){let{object:t,geometry:r}=e;if((r.morphAttributes.position||r.morphAttributes.normal||r.morphAttributes.color)&&Pb(t),t.isSkinnedMesh===!0&&Bb(t),this.displacementMap){let i=bi("displacementMap","texture"),s=bi("displacementScale","float"),o=bi("displacementBias","float");Le.addAssign(pt.normalize().mul(i.x.mul(s).add(o)))}return t.isBatchedMesh&&Cb(t),t.isInstancedMesh&&t.instanceMatrix&&t.instanceMatrix.isInstancedBufferAttribute===!0&&Rb(t),this.positionNode!==null&&Le.assign(Es(this.positionNode,"POSITION","vec3")),Le}setupDiffuseColor(e){let{object:t,geometry:r}=e;this.maskNode!==null&&nr(this.maskNode).not().discard();let i=this.colorNode?X(this.colorNode):Hy;this.vertexColors===!0&&r.hasAttribute("color")&&(i=i.mul(Xb())),t.instanceColor&&(i=nf.mul(i)),t.isBatchedMesh&&t._colorsTexture&&(i=of.mul(i)),ve.assign(i);let s=this.opacityNode?y(this.opacityNode):Ac;ve.a.assign(ve.a.mul(s));let o=null;(this.alphaTestNode!==null||this.alphaTest>0)&&(o=this.alphaTestNode!==null?y(this.alphaTestNode):Wy,this.alphaToCoverage===!0?(ve.a=Wt(o,o.add(Sp(ve.a)),ve.a),ve.a.lessThanEqual(0).discard()):ve.a.lessThanEqual(o).discard()),this.alphaHash===!0&&ve.a.lessThan(mA(Le)).discard(),e.isOpaque()&&ve.a.assign(1)}setupVariants(){}setupOutgoingLight(){return this.lights===!0?N(0):ve.rgb}setupNormal(){return this.normalNode?N(this.normalNode):Zy}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?bi("envMap","cubeTexture"):bi("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Gb(Cc)),t}setupMaterialLightings(e){let t=[],r=this.setupEnvironment(e);r&&r.isLightingNode&&t.push(r);let i=this.setupLightMap(e);return i&&i.isLightingNode&&t.push(i),e.context.ambientOcclusion&&t.push(new Ib(e.context.ambientOcclusion)),t}setupAmbientOcclusion(e){let t=this.aoNode;t===null&&e.material.aoMap&&(t=Tb),e.context.getAO&&(t=e.context.getAO(t,e)),t!==null&&(dp.assign(t),e.context.ambientOcclusion=dp)}setupLightingModel(){}setupLighting(e){let{material:t}=e,{backdropNode:r,backdropAlphaNode:i,emissiveNode:s}=this,o=this.lights===!0&&e.renderer.lighting.enabled,a=o||this.lightsNode!==null,l=o?this.setupMaterialLightings(e):[],u=a?this.lightsNode||e.lightsNode:null,c=this.setupOutgoingLight(e);if(u&&(l.length>0||u.getScope().hasLights)){let d=this.setupLightingModel(e)||null;c=kb(u,d,l,r,i)}else r!==null&&(c=N(i!==null?xe(c,r,i):r));return(s&&s.isNode===!0||t.emissive&&t.emissive.isColor===!0)&&(up.assign(N(s||jy)),c=c.add(up)),c}setupFog(e,t){let r=e.fogNode;return r&&(fo.assign(t),t=X(r.toVar())),t}setupPremultipliedAlpha(e,t){return mc(t)}setupOutput(e,t){return this.fog===!0&&(t=this.setupFog(e,t)),this.premultipliedAlpha===!0&&(t=this.setupPremultipliedAlpha(e,t)),t}setDefaultValues(e){for(let r in e){let i=e[r];this[r]===void 0&&(this[r]=i,i&&i.clone&&(this[r]=i.clone()))}let t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(let r in t)Object.getOwnPropertyDescriptor(this.constructor.prototype,r)===void 0&&t[r].get!==void 0&&Object.defineProperty(this.constructor.prototype,r,t[r])}toJSON(e){let t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{},nodes:{}});let r=st.prototype.toJSON.call(this,e);r.inputNodes={};for(let{property:s,childNode:o}of this._getNodeChildren())r.inputNodes[s]=o.toJSON(e).uuid;function i(s){let o=[];for(let a in s){let l=s[a];delete l.metadata,o.push(l)}return o}if(t){let s=i(e.textures),o=i(e.images),a=i(e.nodes);s.length>0&&(r.textures=s),o.length>0&&(r.images=o),a.length>0&&(r.nodes=a)}return r}copy(e){let t=Object.getOwnPropertyDescriptors(this.constructor.prototype);for(let r in t)if(t[r].set!==void 0&&e[r]!==void 0){let i=e[r];this[r]&&this[r].copy!==void 0?this[r].copy(i):this[r]=i}for(let r in this)if(!/^(?:is[A-Z]|_)|^(?:id|uuid|version|type|userData|clippingPlanes)$/.test(r)&&this[r]!==void 0&&e[r]!==void 0){let i=e[r];this[r]&&this[r].copy!==void 0?this[r].copy(i):this[r]=i}return this.clippingPlanes=e.clippingPlanes?e.clippingPlanes.map(r=>r.clone()):null,this.userData=JSON.parse(JSON.stringify(e.userData)),this}},we=Yb;var vF=new wl,Kb=class extends we{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.setDefaultValues(vF),this.setValues(e)}},gA=Kb;var AF=new Dh,Qb=class extends we{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.setDefaultValues(AF),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){let e=this.offsetNode?y(this.offsetNode):xb,t=this.dashScaleNode?y(this.dashScaleNode):fb,r=this.dashSizeNode?y(this.dashSizeNode):mb,i=this.gapSizeNode?y(this.gapSizeNode):gb;rc.assign(r),cp.assign(i);let s=xi(Mr("lineDistance").mul(t));(e?s.add(e):s).mod(rc.add(cp)).greaterThan(rc).discard()}},xA=Qb;var RF=new Fh,Zb=class extends we{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(RF),this.setValues(e)}setupDiffuseColor(){let e=this.opacityNode?y(this.opacityNode):Ac;ve.assign(Wl(X(Jp(ye),e),tr))}},yA=Zb;var Pc=_(([n=Tc])=>{let e=n.z.atan(n.x).mul(1/(Math.PI*2)).add(.5),t=n.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return V(e,t)}),hf=_(([n=Re()])=>{let e=n.x.sub(.5).mul(Math.PI*2),t=n.y.sub(.5).mul(Math.PI),r=t.cos(),i=r.mul(e.cos()),s=t.sin(),o=r.mul(e.sin());return N(i,s,o)});var Jb=class extends ct{constructor(e=1,t={}){super(e,e,t),this.isCubeRenderTarget=!0;let r={width:e,height:e,depth:1},i=[r,r,r,r,r,r];this.texture=new _s(i),this._setTextureOptions(t),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(e,t){let r=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;let s=new Ml(5,5,5),o=Pc(Tc),a=new we;a.colorNode=be(t,o,0),a.side=Ze,a.blending=Pr;let l=new sr(s,a),u=new so;u.add(l),t.minFilter===Ur&&(t.minFilter=je);let c=new Xh(1,10,this),d=e.getMRT();return e.setMRT(null),c.update(e,u),e.setMRT(d),t.minFilter=r,t.generateMipmaps=i,l.geometry.dispose(),l.material.dispose(),this}clear(e,t=!0,r=!0,i=!0){let s=e.getRenderTarget();for(let o=0;o<6;o++)e.setRenderTarget(this,o),e.clear(t,r,i);e.setRenderTarget(s)}},pf=Jb;var Dc=new WeakMap,e0=class extends _e{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=Ft(null);let t=new _s;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=J.RENDER}updateBefore(e){let{renderer:t,material:r}=e,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){let s=i.isTextureNode?i.value:r[i.property];if(s&&s.isTexture){let o=s.mapping;if(o===Eu||o===Bu){if(Dc.has(s)){let a=Dc.get(s);bA(a,s.mapping),this._cubeTexture=a}else{let a=s.image;if(CF(a)){let l=new pf(a.height);l.fromEquirectangularTexture(t,s),bA(l.texture,s.mapping),this._cubeTexture=l.texture,Dc.set(s,l.texture),s.addEventListener("dispose",_A)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}};function CF(n){return n==null?!1:n.height>0}function _A(n){let e=n.target;e.removeEventListener("dispose",_A);let t=Dc.get(e);t!==void 0&&(Dc.delete(e),t.dispose())}function bA(n,e){e===Eu?n.mapping=Ji:e===Bu&&(n.mapping=$o)}var ff=te(e0).setParameterLength(1);var t0=class extends Ti{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=ff(this.envNode)}},Va=t0;var r0=class extends Ti{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){let t=y(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}},i0=r0;var s0=class{start(e){e.lightsNode.setupLights(e,e.lightsNode.getLightNodes(e)),this.indirect(e)}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}},Cn=s0;var n0=class extends Cn{constructor(){super()}indirect({context:e}){let t=e.ambientOcclusion,r=e.reflectedLight,i=e.irradianceLightMap;r.indirectDiffuse.assign(X(0)),i?r.indirectDiffuse.addAssign(i):r.indirectDiffuse.addAssign(X(1,1,1,0)),r.indirectDiffuse.mulAssign(t),r.indirectDiffuse.mulAssign(ve.rgb)}finish(e){let{material:t,context:r}=e,i=r.outgoingLight,s=e.context.environment;if(s)switch(t.combine){case Hn:i.rgb.assign(xe(i.rgb,i.rgb.mul(s.rgb),Ia.mul(Rc)));break;case ZN:i.rgb.assign(xe(i.rgb,s.rgb,Ia.mul(Rc)));break;case JN:i.rgb.addAssign(s.rgb.mul(Ia.mul(Rc)));break;default:U("BasicLightingModel: Unsupported .combine value:",t.combine);break}}},mf=n0;var EF=new ti,o0=class extends we{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(EF),this.setValues(e)}setupNormal(){return Wi(_o)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new Va(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new i0(Cc)),t}setupOutgoingLight(){return ve.rgb}setupLightingModel(){return new mf}},gf=o0;var BF=_(({f0:n,f90:e,dotVH:t})=>{let r=t.mul(-5.55473).sub(6.98316).mul(t).exp2();return n.mul(r.oneMinus()).add(e.mul(r))}),Hi=BF;var FF=_(n=>n.diffuseColor.mul(1/Math.PI)),us=FF;var LF=()=>y(.25),PF=_(({dotNH:n})=>Il.mul(y(.5)).add(1).mul(y(1/Math.PI)).mul(n.pow(Il))),DF=_(({lightDirection:n})=>{let e=n.add(De).normalize(),t=ye.dot(e).clamp(),r=De.dot(e).clamp(),i=Hi({f0:Nr,f90:1,dotVH:r}),s=LF(),o=PF({dotNH:t});return i.mul(s).mul(o)}),a0=class extends mf{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:r}){let s=ye.dot(e).clamp().mul(t);r.directDiffuse.addAssign(s.mul(us({diffuseColor:ve.rgb}))),this.specular===!0&&r.directSpecular.addAssign(s.mul(DF({lightDirection:e})).mul(Ia))}indirect(e){let{ambientOcclusion:t,irradiance:r,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(r.mul(us({diffuseColor:ve}))),i.indirectDiffuse.mulAssign(t)}},Uc=a0;var UF=new Lh,l0=class extends we{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(UF),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new Va(t):null}setupLightingModel(){return new Uc(!1)}},TA=l0;var IF=new Eh,u0=class extends we{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(IF),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new Va(t):null}setupLightingModel(){return new Uc}setupVariants(){let e=(this.shininessNode?y(this.shininessNode):qy).max(1e-4);Il.assign(e);let t=this.specularNode||Xy;Nr.assign(t)}},SA=u0;var OF=_(n=>{if(n.geometry.hasAttribute("normal")===!1)return y(0);let e=_o.dFdx().abs().max(_o.dFdy().abs());return e.x.max(e.y).max(e.z)}),xf=OF;var kF=_(n=>{let{roughness:e}=n,t=xf(),r=e.max(.0525);return r=r.add(t),r=r.min(1),r}),Zl=kF;var VF=_(({alpha:n,dotNL:e,dotNV:t})=>{let r=n.pow2(),i=e.mul(r.add(r.oneMinus().mul(t.pow2())).sqrt()),s=t.mul(r.add(r.oneMinus().mul(e.pow2())).sqrt());return xt(.5,i.add(s).max(uc))}).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),yf=VF;var GF=_(({alphaT:n,alphaB:e,dotTV:t,dotBV:r,dotTL:i,dotBL:s,dotNV:o,dotNL:a})=>{let l=a.mul(N(n.mul(t),e.mul(r),o).length()),u=o.mul(N(n.mul(i),e.mul(s),a).length());return xt(.5,l.add(u).max(uc))}).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"}]}),NA=GF;var zF=_(({alpha:n,dotNH:e})=>{let t=n.pow2(),r=e.pow2().mul(t.oneMinus()).oneMinus();return t.div(r.pow2()).mul(1/Math.PI)}).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),bf=zF;var $F=y(1/Math.PI),WF=_(({alphaT:n,alphaB:e,dotNH:t,dotTH:r,dotBH:i})=>{let s=n.mul(e),o=N(e.mul(r),n.mul(i),s.mul(t)),a=o.dot(o),l=s.div(a);return $F.mul(s.mul(l.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"}]}),wA=WF;var HF=_(({lightDirection:n,f0:e,f90:t,roughness:r,f:i,normalView:s=ye,viewDirection:o=De,USE_IRIDESCENCE:a,USE_ANISOTROPY:l})=>{let u=r.pow2(),c=n.add(o).normalize(),d=s.dot(n).clamp(),h=s.dot(o).clamp(),p=s.dot(c).clamp(),f=o.dot(c).clamp(),m=Hi({f0:e,f90:t,dotVH:f}),g,x;if(Sn(a)&&(m=Fa.mix(m,i)),Sn(l)){let w=La.dot(n),v=La.dot(o),E=La.dot(c),b=Rs.dot(n),S=Rs.dot(o),T=Rs.dot(c);g=NA({alphaT:Ul,alphaB:u,dotTV:v,dotBV:S,dotTL:w,dotBL:b,dotNV:h,dotNL:d}),x=wA({alphaT:Ul,alphaB:u,dotNH:p,dotTH:E,dotBH:T})}else g=yf({alpha:u,dotNL:d,dotNV:h}),x=bf({alpha:u,dotNH:p});return m.mul(g).mul(x)}),Jl=HF;var qF=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]),Gs=null,jF=_(({roughness:n,dotNV:e})=>{Gs===null&&(Gs=new yn(qF,16,16,vt,qe),Gs.name="DFG_LUT",Gs.minFilter=je,Gs.magFilter=je,Gs.wrapS=Dr,Gs.wrapT=Dr,Gs.generateMipmaps=!1,Gs.needsUpdate=!0);let t=V(n,e);return be(Gs,t).rg}),eu=jF;var XF=_(n=>{let{dotNV:e,specularColor:t,specularF90:r,roughness:i}=n,s=eu({dotNV:e,roughness:i});return t.mul(s.x).add(r.mul(s.y))}),c0=XF;var YF=_(({f:n,f90:e,dotVH:t})=>{let r=t.oneMinus().saturate(),i=r.mul(r),s=r.mul(i,i).clamp(0,.9999);return n.sub(N(e).mul(s)).div(s.oneMinus())}).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Ic=YF;var KF=_(({roughness:n,dotNH:e})=>{let t=n.pow2(),r=y(1).div(t),s=e.pow2().oneMinus().max(.0078125);return y(2).add(r).mul(s.pow(r.mul(.5))).div(2*Math.PI)}).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),QF=_(({dotNV:n,dotNL:e})=>y(1).div(y(4).mul(e.add(n).sub(e.mul(n))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),ZF=_(({lightDirection:n})=>{let e=n.add(De).normalize(),t=ye.dot(n).clamp(),r=ye.dot(De).clamp(),i=ye.dot(e).clamp(),s=KF({roughness:ns,dotNH:i}),o=QF({dotNV:r,dotNL:t});return or.mul(s).mul(o)}),MA=ZF;var d0=_(({N:n,V:e,roughness:t})=>{let s=.0078125,o=n.dot(e).saturate(),a=V(t,o.oneMinus().sqrt());return a.assign(a.mul(.984375).add(s)),a}).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),JF=_(({f:n})=>{let e=n.length();return Ie(e.mul(e).add(n.z).div(e.add(1)),0)}).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),_f=_(({v1:n,v2:e})=>{let t=n.dot(e),r=t.abs().toVar(),i=r.mul(.0145206).add(.4965155).mul(r).add(.8543985).toVar(),s=r.add(4.1616724).mul(r).add(3.417594).toVar(),o=i.div(s),a=t.greaterThan(0).select(o,Ie(t.mul(t).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return n.cross(e).mul(a)}).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),Tf=_(({N:n,V:e,P:t,mInv:r,p0:i,p1:s,p2:o,p3:a})=>{let l=s.sub(i).toVar(),u=a.sub(i).toVar(),c=l.cross(u),d=N().toVar();return ie(c.dot(t.sub(i)).greaterThanEqual(0),()=>{let h=e.sub(n.mul(e.dot(n))).normalize(),p=n.cross(h).negate(),f=r.mul(rt(h,p,n).transpose()).toVar(),m=f.mul(i.sub(t)).normalize().toVar(),g=f.mul(s.sub(t)).normalize().toVar(),x=f.mul(o.sub(t)).normalize().toVar(),w=f.mul(a.sub(t)).normalize().toVar(),v=N(0).toVar();v.addAssign(_f({v1:m,v2:g})),v.addAssign(_f({v1:g,v2:x})),v.addAssign(_f({v1:x,v2:w})),v.addAssign(_f({v1:w,v2:m})),d.assign(N(JF({f:v})))}),d}).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"}]});var Sf=1/6,BA=n=>ce(Sf,ce(n,ce(n,n.negate().add(3)).sub(3)).add(1)),h0=n=>ce(Sf,ce(n,ce(n,ce(3,n).sub(6))).add(4)),FA=n=>ce(Sf,ce(n,ce(n,ce(-3,n).add(3)).add(3)).add(1)),p0=n=>ce(Sf,lr(n,3)),vA=n=>BA(n).add(h0(n)),AA=n=>FA(n).add(p0(n)),RA=n=>Xe(-1,h0(n).div(BA(n).add(h0(n)))),CA=n=>Xe(1,p0(n).div(FA(n).add(p0(n)))),EA=(n,e,t)=>{let r=n.uvNode,i=ce(r,e.zw).add(.5),s=Vr(i),o=ii(i),a=vA(o.x),l=AA(o.x),u=RA(o.x),c=CA(o.x),d=RA(o.y),h=CA(o.y),p=V(s.x.add(u),s.y.add(d)).sub(.5).mul(e.xy),f=V(s.x.add(c),s.y.add(d)).sub(.5).mul(e.xy),m=V(s.x.add(u),s.y.add(h)).sub(.5).mul(e.xy),g=V(s.x.add(c),s.y.add(h)).sub(.5).mul(e.xy),x=vA(o.y).mul(Xe(a.mul(n.sample(p).level(t)),l.mul(n.sample(f).level(t)))),w=AA(o.y).mul(Xe(a.mul(n.sample(m).level(t)),l.mul(n.sample(g).level(t))));return x.add(w)},Nf=_(([n,e])=>{let t=V(n.size(A(e))),r=V(n.size(A(e.add(1)))),i=xt(1,t),s=xt(1,r),o=EA(n,X(i,t),Vr(e)),a=EA(n,X(s,r),zl(e));return ii(e).mix(o,a)}),eL=_(([n,e])=>{let t=e.mul(gc(n));return Nf(n,t)});var LA=_(([n,e,t,r,i])=>{let s=N(vp(e.negate(),_t(n),xt(1,r))),o=N(mi(i[0].xyz),mi(i[1].xyz),mi(i[2].xyz));return _t(s).mul(t.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"}]}),tL=_(([n,e])=>n.mul(ur(e.mul(2).sub(2),0,1))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),rL=uf(),iL=zb(),PA=_(([n,e,t],{material:r})=>{let s=(r.side===Ze?rL:iL).sample(n),o=kr(xo.x).mul(tL(e,t));return Nf(s,o)}),DA=_(([n,e,t])=>(ie(t.notEqual(0),()=>{let r=go(e).negate().div(t);return Gl(r.negate().mul(n))}),N(1))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),sL=_(([n,e,t,r,i,s,o,a,l,u,c,d,h,p,f])=>{let m,g;if(f){m=X().toVar(),g=N().toVar();let b=c.sub(1).mul(f.mul(.025)),S=N(c.sub(b),c,c.add(b));Ee({start:0,end:3},({i:T})=>{let M=S.element(T),B=LA(n,e,d,M,a),D=o.add(B),O=u.mul(l.mul(X(D,1))),z=V(O.xy.div(O.w)).toVar();z.addAssign(1),z.divAssign(2),z.assign(V(z.x,z.y.oneMinus()));let Q=PA(z,t,M);m.element(T).assign(Q.element(T)),m.a.addAssign(Q.a),g.element(T).assign(r.element(T).mul(DA(mi(B),h,p).element(T)))}),m.a.divAssign(3)}else{let b=LA(n,e,d,c,a),S=o.add(b),T=u.mul(l.mul(X(S,1))),M=V(T.xy.div(T.w)).toVar();M.addAssign(1),M.divAssign(2),M.assign(V(M.x,M.y.oneMinus())),m=PA(M,t,c),g=r.mul(DA(mi(b),h,p))}let x=g.rgb.mul(m.rgb),w=n.dot(e).clamp(),v=N(c0({dotNV:w,specularColor:i,specularF90:s,roughness:t})),E=g.r.add(g.g,g.b).div(3);return X(v.oneMinus().mul(x),m.a.oneMinus().mul(E).oneMinus())}),nL=rt(3.2404542,-1.5371385,-.4985314,-.969266,1.8760108,.041556,.0556434,-.2040259,1.0572252),oL=n=>{let e=n.sqrt();return N(1).add(e).div(N(1).sub(e))},UA=(n,e)=>n.sub(e).div(n.add(e)).pow2(),aL=(n,e)=>{let t=n.mul(2*Math.PI*1e-9),r=N(54856e-17,44201e-17,52481e-17),i=N(1681e3,1795300,2208400),s=N(43278e5,93046e5,66121e5),o=y(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(t.mul(2239900).add(e.x).cos()).mul(t.pow2().mul(-45282e5).exp()),a=r.mul(s.mul(2*Math.PI).sqrt()).mul(i.mul(t).add(e).cos()).mul(t.pow2().negate().mul(s).exp());return a=N(a.x.add(o),a.y,a.z).div(10685e-11),nL.mul(a)},IA=_(({outsideIOR:n,eta2:e,cosTheta1:t,thinFilmThickness:r,baseF0:i})=>{let s=xe(n,e,Wt(0,.03,r)),a=n.div(s).pow2().mul(t.pow2().oneMinus()).oneMinus();ie(a.lessThan(0),()=>N(1));let l=a.sqrt(),u=UA(s,n),c=Hi({f0:u,f90:1,dotVH:t}),d=c.oneMinus(),h=s.lessThan(n).select(Math.PI,0),p=y(Math.PI).sub(h),f=oL(i.clamp(0,.9999)),m=UA(f,s.toVec3()),g=Hi({f0:m,f90:1,dotVH:l}),x=N(f.x.lessThan(s).select(Math.PI,0),f.y.lessThan(s).select(Math.PI,0),f.z.lessThan(s).select(Math.PI,0)),w=s.mul(r,l,2),v=N(p).add(x),E=c.mul(g).clamp(1e-5,.9999),b=E.sqrt(),S=d.pow2().mul(g).div(N(1).sub(E)),M=c.add(S).toVar(),B=S.sub(d).toVar();return Ee({start:1,end:2,condition:"<=",name:"m"},({m:D})=>{B.mulAssign(b);let O=aL(y(D).mul(w),y(D).mul(v)).mul(2);M.addAssign(B.mul(O))}),M.max(N(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"}]}),Oc=_(({normal:n,viewDir:e,roughness:t})=>{let r=n.dot(e).saturate(),i=t.mul(t),s=t.add(.1).reciprocal(),o=y(-1.9362).add(t.mul(1.0678)).add(i.mul(.4573)).sub(s.mul(.8469)),a=y(-.6014).add(t.mul(.5538)).sub(i.mul(.467)).sub(s.mul(.1255));return o.mul(r).add(a).exp().saturate()}),kc=N(.04),wf=y(1),f0=class extends Cn{constructor(e=!1,t=!1,r=!1,i=!1,s=!1,o=!1,a=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=r,this.anisotropy=i,this.transmission=s,this.dispersion=o,this.retroreflective=a,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0Dielectric=null,this.iridescenceF0Metallic=null,this.dfg=null,this.multiScatteringCompensation=null}start(e){if(this.clearcoat===!0&&(this.clearcoatRadiance=N().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=N().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=N().toVar("clearcoatSpecularIndirect")),this.sheen===!0&&(this.sheenSpecularDirect=N().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=N().toVar("sheenSpecularIndirect")),this.iridescence===!0){let i=ye.dot(De).clamp(),s=IA({outsideIOR:y(1),eta2:Pl,cosTheta1:i,thinFilmThickness:Dl,baseF0:Nr}),o=IA({outsideIOR:y(1),eta2:Pl,cosTheta1:i,thinFilmThickness:Dl,baseF0:ve.rgb});this.iridescenceFresnel=xe(s,o,ss),this.iridescenceF0Dielectric=Ic({f:s,f90:1,dotVH:i}),this.iridescenceF0Metallic=Ic({f:o,f90:1,dotVH:i})}if(this.transmission===!0){let i=vr,s=Sy.sub(vr).normalize(),o=ni,a=e.context;a.backdrop=sL(o,s,Sr,Mn,zi,fi,i,fr,yi,zr,Pa,ic,nc,sc,this.dispersion?oc:null),a.backdropAlpha=Ol,ve.a.mulAssign(xe(1,a.backdrop.a,Ol))}let t=ye.dot(De).clamp();this.dfg=eu({roughness:Sr,dotNV:t}).toConst("dfg");let r=this.dfg.x.add(this.dfg.y);this.multiScatteringCompensation=zi.mul(r.reciprocal().sub(1)).add(1).toConst("multiScatteringCompensation"),super.start(e)}computeMultiscattering(e,t,r,i,s=null){let o=this.dfg,a=s?Fa.mix(i,s):i,l=a.mul(o.x).add(r.mul(o.y)),c=o.x.add(o.y).oneMinus(),d=a.add(a.oneMinus().mul(.047619)),h=l.mul(d).div(c.mul(d).oneMinus());e.addAssign(l),t.addAssign(h.mul(c))}direct({lightDirection:e,lightColor:t,reflectedLight:r}){let s=ye.dot(e).clamp().mul(t).toVar();if(this.sheen===!0){this.sheenSpecularDirect.addAssign(s.mul(MA({lightDirection:e})));let c=Oc({normal:ye,viewDir:De,roughness:ns}),d=Oc({normal:ye,viewDir:e,roughness:ns}),h=or.r.max(or.g).max(or.b).mul(c.max(d)).oneMinus();s.mulAssign(h)}if(this.clearcoat===!0){let d=Os.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(d.mul(Jl({lightDirection:e,f0:kc,f90:wf,roughness:vn,normalView:Os})))}let o=e.add(De).normalize(),a=De.dot(o).clamp(),l=Hi({f0:Nr,f90:fi,dotVH:a}),u=Jl({lightDirection:e,f0:zi,f90:1,roughness:Sr,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy});if(this.retroreflective===!0){let c=De.negate().reflect(ye),d=e.add(c).normalize(),h=c.dot(d).clamp(),p=Hi({f0:Nr,f90:fi,dotVH:h}),f=Jl({lightDirection:e,viewDirection:c,f0:zi,f90:1,roughness:Sr,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy});l=xe(l,p,kl.clamp()),u=xe(u,f,kl.clamp())}r.directDiffuse.addAssign(s.mul(us({diffuseColor:Mn})).mul(l.oneMinus())),r.directSpecular.addAssign(s.mul(u).mul(this.multiScatteringCompensation))}directRectArea({lightColor:e,lightPosition:t,halfWidth:r,halfHeight:i,reflectedLight:s,ltc_1:o,ltc_2:a}){let l=t.add(r).sub(i),u=t.sub(r).sub(i),c=t.sub(r).add(i),d=t.add(r).add(i),h=ye,p=De,f=$e.toVar(),m=d0({N:h,V:p,roughness:Sr}),g=o.sample(m).toVar(),x=a.sample(m).toVar(),w=rt(N(g.x,0,g.y),N(0,1,0),N(g.z,0,g.w)).toVar(),v=zi.mul(x.x).add(fi.sub(zi).mul(x.y)).toVar();if(s.directSpecular.addAssign(e.mul(v).mul(Tf({N:h,V:p,P:f,mInv:w,p0:l,p1:u,p2:c,p3:d}))),s.directDiffuse.addAssign(e.mul(Mn).mul(Tf({N:h,V:p,P:f,mInv:rt(1,0,0,0,1,0,0,0,1),p0:l,p1:u,p2:c,p3:d}))),this.clearcoat===!0){let E=Os,b=d0({N:E,V:p,roughness:vn}),S=o.sample(b),T=a.sample(b),M=rt(N(S.x,0,S.y),N(0,1,0),N(S.z,0,S.w)),B=kc.mul(T.x).add(wf.sub(kc).mul(T.y));this.clearcoatSpecularDirect.addAssign(e.mul(B).mul(Tf({N:E,V:p,P:f,mInv:M,p0:l,p1:u,p2:c,p3:d})))}}indirect(e){this.indirectDiffuse(e),this.indirectSpecular(e),this.ambientOcclusion(e)}indirectDiffuse(e){let{irradiance:t,reflectedLight:r}=e.context,i=N().toVar(),s=N().toVar();this.computeMultiscattering(i,s,fi,Nr,this.iridescenceF0Dielectric);let o=t.mul(us({diffuseColor:Mn})).mul(i.add(s).oneMinus()).toVar();if(this.sheen===!0){let a=Oc({normal:ye,viewDir:De,roughness:ns});this.sheenSpecularIndirect.addAssign(t.mul(or,a,1/Math.PI));let l=or.r.max(or.g).max(or.b).mul(a).oneMinus();o.mulAssign(l)}r.indirectDiffuse.addAssign(o)}indirectSpecular(e){let{radiance:t,iblIrradiance:r,reflectedLight:i}=e.context;if(this.sheen===!0&&this.sheenSpecularIndirect.addAssign(r.mul(or,Oc({normal:ye,viewDir:De,roughness:ns}),1/Math.PI)),this.clearcoat===!0){let g=Os.dot(De).clamp(),x=c0({dotNV:g,specularColor:kc,specularF90:wf,roughness:vn});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(x))}let s=N().toVar("singleScatteringDielectric"),o=N().toVar("multiScatteringDielectric"),a=N().toVar("singleScatteringMetallic"),l=N().toVar("multiScatteringMetallic");this.computeMultiscattering(s,o,fi,Nr,this.iridescenceF0Dielectric),this.computeMultiscattering(a,l,fi,ve.rgb,this.iridescenceF0Metallic);let u=xe(s,a,ss),c=xe(o,l,ss),d=s.add(o),h=Mn.mul(d.oneMinus()),p=r.mul(1/Math.PI),f=t.mul(u).add(c.mul(p)).toVar(),m=h.mul(p).toVar();if(this.sheen===!0){let g=Oc({normal:ye,viewDir:De,roughness:ns}),x=or.r.max(or.g).max(or.b).mul(g).oneMinus();f.mulAssign(x),m.mulAssign(x)}i.indirectSpecular.addAssign(f),i.indirectDiffuse.addAssign(m)}ambientOcclusion(e){let{ambientOcclusion:t,reflectedLight:r}=e.context,s=ye.dot(De).clamp().add(t),o=Sr.mul(-16).oneMinus().negate().exp2(),a=t.sub(s.pow(o).oneMinus()).clamp();this.clearcoat===!0&&this.clearcoatSpecularIndirect.mulAssign(t),this.sheen===!0&&this.sheenSpecularIndirect.mulAssign(t),r.indirectDiffuse.mulAssign(t),r.indirectSpecular.mulAssign(a)}finish({context:e}){let{outgoingLight:t}=e;if(this.clearcoat===!0){let r=Os.dot(De).clamp(),i=Hi({dotVH:r,f0:kc,f90:wf}),s=t.mul(Ll.mul(i).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(Ll));t.assign(s)}if(this.sheen===!0){let r=t.add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(r)}}},Vc=f0;var lL=2.399963229728653,OA=y(1),y0=y(-2),Mf=y(.8),m0=y(-1),vf=y(.4),g0=y(2),Af=y(.305),x0=y(3),kA=y(.21),uL=y(4),VA=y(4),cL=y(16),dL=_(([n])=>{let e=N(Ue(n)).toVar(),t=y(-1).toVar();return ie(e.x.greaterThan(e.z),()=>{ie(e.x.greaterThan(e.y),()=>{t.assign(St(n.x.greaterThan(0),0,3))}).Else(()=>{t.assign(St(n.y.greaterThan(0),1,4))})}).Else(()=>{ie(e.z.greaterThan(e.y),()=>{t.assign(St(n.z.greaterThan(0),2,5))}).Else(()=>{t.assign(St(n.y.greaterThan(0),1,4))})}),t}).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),hL=_(([n,e])=>{let t=V().toVar();return ie(e.equal(0),()=>{t.assign(V(n.z,n.y).div(Ue(n.x)))}).ElseIf(e.equal(1),()=>{t.assign(V(n.x.negate(),n.z.negate()).div(Ue(n.y)))}).ElseIf(e.equal(2),()=>{t.assign(V(n.x.negate(),n.y).div(Ue(n.z)))}).ElseIf(e.equal(3),()=>{t.assign(V(n.z.negate(),n.y).div(Ue(n.x)))}).ElseIf(e.equal(4),()=>{t.assign(V(n.x.negate(),n.z).div(Ue(n.y)))}).Else(()=>{t.assign(V(n.x,n.y).div(Ue(n.z)))}),ce(.5,t.add(1))}).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),pL=_(([n])=>{let e=y(0).toVar();return ie(n.greaterThanEqual(Mf),()=>{e.assign(OA.sub(n).mul(m0.sub(y0)).div(OA.sub(Mf)).add(y0))}).ElseIf(n.greaterThanEqual(vf),()=>{e.assign(Mf.sub(n).mul(g0.sub(m0)).div(Mf.sub(vf)).add(m0))}).ElseIf(n.greaterThanEqual(Af),()=>{e.assign(vf.sub(n).mul(x0.sub(g0)).div(vf.sub(Af)).add(g0))}).ElseIf(n.greaterThanEqual(kA),()=>{e.assign(Af.sub(n).mul(uL.sub(x0)).div(Af.sub(kA)).add(x0))}).Else(()=>{e.assign(y(-2).mul(kr(ce(1.16,n))))}),e}).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),GA=_(([n,e,t,r,i,s])=>{let o=y(t),a=N(e),l=ur(pL(o),y0,s),u=ii(l),c=Vr(l),d=N(tu(n,a,c,r,i,s)).toVar();return ie(u.notEqual(0),()=>{let h=N(tu(n,a,c.add(1),r,i,s)).toVar();d.assign(xe(d,h,u))}),d}),tu=_(([n,e,t,r,i,s])=>{let o=y(t).toVar(),a=N(e),l=y(dL(a)).toVar(),u=y(Ie(VA.sub(o),0)).toVar();o.assign(Ie(o,VA));let c=y(mo(o)).toVar(),d=V(hL(a,l).mul(c.sub(2)).add(1)).toVar();return ie(l.greaterThan(2),()=>{d.y.addAssign(c),l.subAssign(3)}),d.x.addAssign(l.mul(c)),d.x.addAssign(u.mul(ce(3,cL))),d.y.addAssign(ce(4,mo(s).sub(c))),d.x.mulAssign(r),d.y.mulAssign(i),n.sample(d).grad(V(),V())}),zA=_(({SAMPLES:n,sigma:e,outputDirection:t,mipInt:r,envMap:i,CUBEUV_TEXEL_WIDTH:s,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{let l=N(0).toVar();return ie(e.equal(0),()=>{l.assign(tu(i,t,r,s,o,a))}).Else(()=>{let u=St(Ue(t.z).lessThan(.999),N(0,0,1),N(1,0,0)),c=_t(gi(u,t)).toVar(),d=gi(t,c).toVar(),h=ht(e.mul(3),Math.PI),p=Gl(h.mul(h).mul(-.5).div(e.mul(e))).oneMinus().toVar(),f=y(0).toVar();Ee({start:A(0),end:n},({i:m})=>{let g=y(m).add(.5).div(y(n)),x=e.mul(Ct(go(g.mul(p).oneMinus()).mul(-2))).toVar(),w=y(m).mul(lL).toVar(),v=c.mul(Gr(w)).add(d.mul(Tt(w))),E=t.mul(Gr(x)).add(v.mul(Tt(x))),b=Tt(x).div(x).toVar();l.addAssign(tu(i,E,r,s,o,a).mul(b)),f.addAssign(b)}),l.divAssign(f)}),X(l,1)}),fL=_(([n])=>{let e=k(n).toVar();return e.assign(e.shiftLeft(k(16)).bitOr(e.shiftRight(k(16)))),e.assign(e.bitAnd(k(1431655765)).shiftLeft(k(1)).bitOr(e.bitAnd(k(2863311530)).shiftRight(k(1)))),e.assign(e.bitAnd(k(858993459)).shiftLeft(k(2)).bitOr(e.bitAnd(k(3435973836)).shiftRight(k(2)))),e.assign(e.bitAnd(k(252645135)).shiftLeft(k(4)).bitOr(e.bitAnd(k(4042322160)).shiftRight(k(4)))),e.assign(e.bitAnd(k(16711935)).shiftLeft(k(8)).bitOr(e.bitAnd(k(4278255360)).shiftRight(k(8)))),y(e).mul(23283064365386963e-26)}),mL=_(([n,e])=>V(y(n).div(y(e)),fL(n))),gL=_(([n,e,t])=>{let r=t.mul(t).toConst(),i=N(1,0,0).toConst(),s=gi(e,i).toConst(),o=Ct(n.x).toConst(),a=ce(2,3.14159265359).mul(n.y).toConst(),l=o.mul(Gr(a)).toConst(),u=o.mul(Tt(a)).toVar(),c=ce(.5,e.z.add(1)).toConst();u.assign(c.oneMinus().mul(Ct(l.mul(l).oneMinus())).add(c.mul(u)));let d=i.mul(l).add(s.mul(u)).add(e.mul(Ct(Ie(0,l.mul(l).add(u.mul(u)).oneMinus()))));return _t(N(r.mul(d.x),r.mul(d.y),Ie(0,d.z)))}),$A=_(({roughness:n,mipInt:e,envMap:t,N_immutable:r,GGX_SAMPLES:i,CUBEUV_TEXEL_WIDTH:s,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{let l=N(r).toVar(),u=N(0).toVar(),c=y(0).toVar();return ie(n.lessThan(.001),()=>{u.assign(tu(t,l,e,s,o,a))}).Else(()=>{let d=St(Ue(l.z).lessThan(.999),N(0,0,1),N(1,0,0)),h=_t(gi(d,l)).toVar(),p=gi(l,h).toVar();Ee({start:k(0),end:i},({i:f})=>{let m=mL(f,i),g=gL(m,N(0,0,1),n),x=_t(h.mul(g.x).add(p.mul(g.y)).add(l.mul(g.z))),w=_t(x.mul(ar(l,x).mul(2)).sub(l)),v=Ie(ar(l,w),0);ie(v.greaterThan(0),()=>{let E=tu(t,w,e,s,o,a);u.addAssign(E.mul(v)),c.addAssign(v)})}),ie(c.greaterThan(0),()=>{u.assign(u.div(c))})}),X(u,1)});var ru=4,xL=6,yL=20,bL=256,Gc=new Ss(-1,1,1,-1,0,1),_L=new Rt(90,1),WA=new le,b0=null,_0=0,T0=0,TL=new C,Ga=new C,Rf=new WeakMap,SL=[3,1,5,0,4,2],Cf=Mr("outputDirection").normalize(),S0=class{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],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,i=100,s={}){let{size:o=256,position:a=TL,renderTarget:l=null}=s;if(this._setSize(o),this._hasInitialized===!1)throw new Error('THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Use "await renderer.init();" before using this method.');b0=this._renderer.getRenderTarget(),_0=this._renderer.getActiveCubeFace(),T0=this._renderer.getActiveMipmapLevel();let u=l||this._allocateTarget(!0);return this._init(u),this._sceneToCubeUV(e,r,i,u,a),t>0&&this._blur(u,0,0,t),this._applyPMREM(u),this._cleanup(u),u}async fromSceneAsync(e,t=0,r=.1,i=100,s={}){return he('PMREMGenerator: ".fromSceneAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this.fromScene(e,t,r,i,s)}fromEquirectangular(e,t=null){if(this._hasInitialized===!1)throw new Error('THREE.PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this._fromTexture(e,t)}async fromEquirectangularAsync(e,t=null){return he('PMREMGenerator: ".fromEquirectangularAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}fromCubemap(e,t=null){if(this._hasInitialized===!1)throw new Error('THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this._fromTexture(e,t)}async fromCubemapAsync(e,t=null){return he('PMREMGenerator: ".fromCubemapAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}async compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=qA(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=jA(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSizeFromTexture(e){e.mapping===Ji||e.mapping===$o?this._setSize(e.image.length===0?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(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodMeshes.length;e++)this._lodMeshes[e].geometry.dispose()}_cleanup(e){this._renderer.setRenderTarget(b0,_0,T0),e.scissorTest=!1,this._setViewport(e,0,0,e.width,e.height)}_fromTexture(e,t){this._setSizeFromTexture(e),b0=this._renderer.getRenderTarget(),_0=this._renderer.getActiveCubeFace(),T0=this._renderer.getActiveMipmapLevel();let r=t||this._allocateTarget(!1);return this._init(r),this._textureToCubeUV(e,r),this._applyPMREM(r),this._cleanup(r),r}_allocateTarget(e){let t=3*Math.max(this._cubeSize,112),r=4*this._cubeSize;return HA(t,r,e)}_init(e){if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e.width||this._pingPongRenderTarget.height!==e.height){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=HA(e.width,e.height);let{_lodMax:t}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods}=NL(t)),this._blurMaterial=wL(t,e.width,e.height),this._ggxMaterial=ML(t,e.width,e.height)}}async _compileMaterial(e){let t=new sr(new ir,e);await this._renderer.compile(t,Gc)}_sceneToCubeUV(e,t,r,i,s){let o=_L;o.near=t,o.far=r;let a=[1,1,1,1,-1,1],l=[1,-1,1,-1,1,-1],u=this._renderer,c=u.autoClear;u.getClearColor(WA),u.autoClear=!1,this._backgroundBox===null&&(this._backgroundBox=new sr(new Ml,new ti({name:"PMREM.Background",side:Ze,depthWrite:!1,depthTest:!1})));let d=this._backgroundBox,h=d.material,p=!1,f=e.background;f?f.isColor&&(h.color.copy(f),e.background=null,p=!0):(h.color.copy(WA),p=!0),u.setRenderTarget(i),u.clear(),p&&u.render(d,o);for(let m=0;m<6;m++){let g=m%3;g===0?(o.up.set(0,a[m],0),o.position.set(s.x,s.y,s.z),o.lookAt(s.x+l[m],s.y,s.z)):g===1?(o.up.set(0,0,a[m]),o.position.set(s.x,s.y,s.z),o.lookAt(s.x,s.y+l[m],s.z)):(o.up.set(0,a[m],0),o.position.set(s.x,s.y,s.z),o.lookAt(s.x,s.y,s.z+l[m]));let x=this._cubeSize;this._setViewport(i,g*x,m>2?x:0,x,x),u.render(e,o)}u.autoClear=c,e.background=f}_textureToCubeUV(e,t){let r=this._renderer,i=e.mapping===Ji||e.mapping===$o;i?this._cubemapMaterial===null&&(this._cubemapMaterial=qA(e)):this._equirectMaterial===null&&(this._equirectMaterial=jA(e));let s=i?this._cubemapMaterial:this._equirectMaterial;s.fragmentNode.value=e;let o=this._lodMeshes[0];o.material=s;let a=this._cubeSize;this._setViewport(t,0,0,3*a,2*a),r.setRenderTarget(t),r.render(o,Gc)}_applyPMREM(e){let t=this._renderer,r=t.autoClear;t.autoClear=!1;let i=this._lodMeshes.length;for(let s=1;s<i;s++)this._applyGGXFilter(e,s-1,s);t.autoClear=r}_applyGGXFilter(e,t,r){let i=this._renderer,s=this._pingPongRenderTarget,o=this._ggxMaterial,a=this._lodMeshes[r];a.material=o;let l=Rf.get(o),u=r/(this._lodMeshes.length-1),c=t/(this._lodMeshes.length-1),d=Math.sqrt(u*u-c*c),h=u*1.25,p=d*h,{_lodMax:f}=this,m=this._sizeLods[r],g=3*m*(r>f-ru?r-f+ru:0),x=4*(this._cubeSize-m);e.texture.frame=(e.texture.frame||0)+1,l.envMap.value=e.texture,l.roughness.value=p,l.mipInt.value=f-t,this._setViewport(s,g,x,3*m,2*m),i.setRenderTarget(s),i.render(a,Gc),s.texture.frame=(s.texture.frame||0)+1,l.envMap.value=s.texture,l.roughness.value=0,l.mipInt.value=f-r,this._setViewport(e,g,x,3*m,2*m),i.setRenderTarget(e),i.render(a,Gc)}_blur(e,t,r,i){let s=this._pingPongRenderTarget,o=Math.min(i,Math.PI)/Math.SQRT2;this._blurPass(e,s,t,r,o),this._blurPass(s,e,r,r,o)}_blurPass(e,t,r,i,s){let o=this._renderer,a=this._blurMaterial,l=this._lodMeshes[i];l.material=a;let u=Rf.get(a);e.texture.frame=(e.texture.frame||0)+1,u.envMap.value=e.texture,u.sigma.value=s,u.mipInt.value=this._lodMax-r;let c=this._sizeLods[i],d=3*c*(i>this._lodMax-ru?i-this._lodMax+ru:0),h=4*(this._cubeSize-c);this._setViewport(t,d,h,3*c,2*c),o.setRenderTarget(t),o.render(l,Gc)}_setViewport(e,t,r,i,s){this._renderer.isWebGLRenderer?(e.viewport.set(t,e.height-s-r,i,s),e.scissor.set(t,e.height-s-r,i,s)):(e.viewport.set(t,r,i,s),e.scissor.set(t,r,i,s))}};function NL(n){let e=[],t=[],r=n,i=n-ru+1+xL;for(let s=0;s<i;s++){let o=Math.pow(2,r);e.push(o);let a=1/(o-2),l=-a,u=1+a,c=[l,l,u,l,u,u,l,l,u,u,l,u],d=6,h=6,p=3,f=new Float32Array(p*h*d),m=new Float32Array(p*h*d);for(let x=0;x<d;x++){let w=x%3*2/3-1,v=x>2?0:-1,E=[w,v,0,w+2/3,v,0,w+2/3,v+1,0,w,v,0,w+2/3,v+1,0,w,v+1,0],b=SL[x];f.set(E,p*h*b);for(let S=0;S<h;S++){let T=c[S*2]*2-1,M=c[S*2+1]*2-1;b===0?Ga.set(1,M,T):b===1?Ga.set(-T,1,-M):b===2?Ga.set(-T,M,1):b===3?Ga.set(-1,M,-T):b===4?Ga.set(-T,-1,M):Ga.set(T,M,-1),Ga.toArray(m,(b*h+S)*p)}}let g=new ir;g.setAttribute("position",new $t(f,p)),g.setAttribute("outputDirection",new $t(m,p)),t.push(new sr(g,null)),r>ru&&r--}return{lodMeshes:t,sizeLods:e}}function HA(n,e,t){let r={magFilter:je,minFilter:je,generateMipmaps:!1,type:qe,format:wt,colorSpace:xa,depthBuffer:t},i=new ct(n,e,r);return i.texture.mapping=Wo,i.texture.name="PMREM.cubeUv",i.texture.isPMREMTexture=!0,i.scissorTest=!0,i}function Ef(n){let e=new we;return e.depthTest=!1,e.depthWrite=!1,e.blending=Pr,e.name=`PMREM_${n}`,e}function wL(n,e,t){let r=be(),i=Y(0),s=Y(0),o=y(1/e),a=y(1/t),l=y(n),u={envMap:r,sigma:i,mipInt:s,CUBEUV_TEXEL_WIDTH:o,CUBEUV_TEXEL_HEIGHT:a,CUBEUV_MAX_MIP:l},c=Ef("blur");return c.fragmentNode=zA({...u,outputDirection:Cf,SAMPLES:A(yL)}),Rf.set(c,u),c}function ML(n,e,t){let r=be(),i=Y(0),s=Y(0),o=y(1/e),a=y(1/t),l=y(n),u={envMap:r,roughness:i,mipInt:s,CUBEUV_TEXEL_WIDTH:o,CUBEUV_TEXEL_HEIGHT:a,CUBEUV_MAX_MIP:l},c=Ef("ggx");return c.fragmentNode=$A({...u,N_immutable:Cf,GGX_SAMPLES:k(bL)}),Rf.set(c,u),c}function qA(n){let e=Ef("cubemap");return e.fragmentNode=Ft(n,Cf),e}function jA(n){let e=Ef("equirect");return e.fragmentNode=be(n,Pc(Cf),0),e}var zc=S0;var XA=new WeakMap;function vL(n){let e=Math.log2(n)-2,t=1/n;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:t,maxMip:e}}function AL(n,e,t){let r=RL(e),i=r.get(n);if((i!==void 0?i.pmremVersion:-1)!==n.pmremVersion){let o=n.image;if(n.isCubeTexture)if(CL(o))i=t.fromCubemap(n,i);else return null;else if(EL(o))i=t.fromEquirectangular(n,i);else return null;if(i.pmremVersion=n.pmremVersion,r.has(n)===!1){let a=()=>{n.removeEventListener("dispose",a);let l=r.get(n);l!==void 0&&(l.dispose(),r.delete(n))};n.addEventListener("dispose",a)}r.set(n,i)}return i.texture}function RL(n){let e=XA.get(n);return e===void 0&&(e=new WeakMap,XA.set(n,e)),e}var N0=class extends _e{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;let i=new nt;i.isRenderTargetTexture=!0,this._texture=be(i),this._width=Y(0),this._height=Y(0),this._maxMip=Y(0),this.updateBeforeType=J.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){let t=vL(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,r=t?t.pmremVersion:-1,i=this._value;r!==i.pmremVersion&&(i.isPMREMTexture===!0||i.mapping===Wo?t=i:t=AL(i,e.renderer,this._generator),t!==null&&(this._pmrem=t,this.updateFromTexture(t)))}setup(e){this._generator===null&&(this._generator=new zc(e.renderer)),this.updateBefore(e);let t=this.uvNode;t===null&&e.context.getUV&&(t=e.context.getUV(this,e)),t=this._pmrem===null||this._pmrem.isRenderTargetTexture?Xl.mul(N(t.x,t.y.negate(),t.z)):Xl.mul(t);let r=this.levelNode;return r===null&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),GA(this._texture,t,r,this._width,this._height,this._maxMip)}dispose(){super.dispose(),this._generator!==null&&this._generator.dispose()}};function CL(n){if(n==null)return!1;let e=0,t=6;for(let r=0;r<t;r++)n[r]!==void 0&&e++;return e===t}function EL(n){return n==null?!1:n.height>0}var $c=te(N0).setParameterLength(1,3);var YA=new WeakMap,w0=class extends Ti{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){let{material:t}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){let d=r.isTextureNode?r.value:t[r.property],h=this._getPMREMNodeCache(e.renderer),p=h.get(d);p===void 0&&(p=$c(d),h.set(d,p)),r=p}let s=t.useAnisotropy===!0||t.anisotropy>0?Vy:ye,o=r.context(KA(Sr,s)).mul(Sc),a=r.context(BL(ni)).mul(Math.PI).mul(Sc),l=Da(o),u=Da(a);e.context.radiance.addAssign(l),e.context.iblIrradiance.addAssign(u);let c=e.context.lightingModel.clearcoatRadiance;if(c){let d=r.context(KA(vn,Os)).mul(Sc),h=Da(d);c.addAssign(h)}}_getPMREMNodeCache(e){let t=YA.get(e);return t===void 0&&(t=new WeakMap,YA.set(e,t)),t}},M0=w0,KA=(n,e)=>{let t=null;return{getUV:()=>(t===null&&(t=De.negate().reflect(e),t=wp(n).mix(t,e).normalize(),t=t.transformDirection(bo)),t),getTextureLevel:()=>n}},BL=n=>({getUV:()=>n,getTextureLevel:()=>y(1)});var FL=new vl,v0=class extends we{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(FL),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t===null&&e.environmentNode&&(t=e.environmentNode),t?new M0(t):null}setupLightingModel(){return new Vc}setupSpecular(){let e=xe(N(.04),ve.rgb,ss);Nr.assign(N(.04)),zi.assign(e),fi.assign(1)}setupVariants(){let e=this.metalnessNode?y(this.metalnessNode):Qy;ss.assign(e);let t=this.roughnessNode?y(this.roughnessNode):Ky;t=Zl({roughness:t}),Sr.assign(t),this.setupSpecular(),Mn.assign(ve.rgb.mul(e.oneMinus()))}},Bf=v0;var LL=new Ch,A0=class extends Bf{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.retroreflectiveNode=null,this.anisotropyNode=null,this.setDefaultValues(LL),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||this.clearcoatNode!==null}get useIridescence(){return this.iridescence>0||this.iridescenceNode!==null}get useSheen(){return this.sheen>0||this.sheenNode!==null}get useAnisotropy(){return this.anisotropy>0||this.anisotropyNode!==null}get useTransmission(){return this.transmission>0||this.transmissionNode!==null}get useDispersion(){return this.dispersion>0||this.dispersionNode!==null}get useRetroreflective(){return this.retroreflective>0||this.retroreflectiveNode!==null}setupSpecular(){let e=this.iorNode?y(this.iorNode):db;Pa.assign(e),Nr.assign(ht(Np(Pa.sub(1).div(Pa.add(1))).mul(Yy),N(1)).mul(rf)),zi.assign(xe(Nr,ve.rgb,ss)),fi.assign(xe(rf,1,ss))}setupLightingModel(){return new Vc(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion,this.useRetroreflective)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){let t=this.clearcoatNode?y(this.clearcoatNode):Jy,r=this.clearcoatRoughnessNode?y(this.clearcoatRoughnessNode):eb;Ll.assign(t),vn.assign(Zl({roughness:r}))}if(this.useSheen){let t=this.sheenNode?N(this.sheenNode):ib,r=this.sheenRoughnessNode?y(this.sheenRoughnessNode):sb;or.assign(t),ns.assign(r)}if(this.useRetroreflective){let t=this.retroreflectiveNode?y(this.retroreflectiveNode):_b;kl.assign(t)}if(this.useIridescence){let t=this.iridescenceNode?y(this.iridescenceNode):ob,r=this.iridescenceIORNode?y(this.iridescenceIORNode):ab,i=this.iridescenceThicknessNode?y(this.iridescenceThicknessNode):lb;Fa.assign(t),Pl.assign(r),Dl.assign(i)}if(this.useAnisotropy){let t=(this.anisotropyNode?V(this.anisotropyNode):nb).toVar();As.assign(t.length()),ie(As.equal(0),()=>{t.assign(V(1,0))}).Else(()=>{t.divAssign(V(As)),As.assign(As.saturate())}),Ul.assign(As.pow2().mix(Sr.pow2(),1)),La.assign(Rn[0].mul(t.x).add(Rn[1].mul(t.y))),Rs.assign(Rn[1].mul(t.x).sub(Rn[0].mul(t.y)))}if(this.useTransmission){let t=this.transmissionNode?y(this.transmissionNode):ub,r=this.thicknessNode?y(this.thicknessNode):cb,i=this.attenuationDistanceNode?y(this.attenuationDistanceNode):hb,s=this.attenuationColorNode?N(this.attenuationColorNode):pb;if(Ol.assign(t),ic.assign(r),sc.assign(i),nc.assign(s),this.useDispersion){let o=this.dispersionNode?y(this.dispersionNode):bb;oc.assign(o)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?N(this.clearcoatNormalNode):tb}setup(e){e.context.setupClearcoatNormal=()=>Es(this.setupClearcoatNormal(e),"NORMAL","vec3"),super.setup(e)}},QA=A0;var PL=_(({normal:n,lightDirection:e,builder:t})=>{let r=n.dot(e),i=V(r.mul(.5).add(.5),0);if(t.material.gradientMap){let s=bi("gradientMap","texture").context({getUV:()=>i});return N(s.r)}else{let s=i.fwidth().mul(.5);return xe(N(.7),N(1),Wt(y(.7).sub(s.x),y(.7).add(s.x),i.x))}}),R0=class extends Cn{direct({lightDirection:e,lightColor:t,reflectedLight:r},i){let s=PL({normal:jl,lightDirection:e,builder:i}).mul(t);r.directDiffuse.addAssign(s.mul(us({diffuseColor:ve.rgb})))}indirect(e){let{ambientOcclusion:t,irradiance:r,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(r.mul(us({diffuseColor:ve}))),i.indirectDiffuse.mulAssign(t)}},ZA=R0;var DL=new Bh,C0=class extends we{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(DL),this.setValues(e)}setupLightingModel(){return new ZA}},JA=C0;var E0=_(()=>{let n=N(De.z,0,De.x.negate()).normalize(),e=De.cross(n);return V(n.dot(ye),e.dot(ye)).mul(.495).add(.5)}).once(["NORMAL","VERTEX"])().toVar("matcapUV");var UL=new Ph,B0=class extends we{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(UL),this.setValues(e)}setupVariants(e){let t=E0,r;e.material.matcap?r=bi("matcap","texture").context({getUV:()=>t}):r=N(xe(.2,.8,t.y)),ve.rgb.mulAssign(r.rgb)}},eR=B0;var F0=class extends _e{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}generateNodeType(e){return this.positionNode.getNodeType(e)}setup(e){let{rotationNode:t,positionNode:r}=this;if(this.getNodeType(e)==="vec2"){let s=t.cos(),o=t.sin();return Fl(s,o,o.negate(),s).mul(r)}else{let s=t,o=Gi(X(1,0,0,0),X(0,Gr(s.x),Tt(s.x).negate(),0),X(0,Tt(s.x),Gr(s.x),0),X(0,0,0,1)),a=Gi(X(Gr(s.y),0,Tt(s.y),0),X(0,1,0,0),X(Tt(s.y).negate(),0,Gr(s.y),0),X(0,0,0,1)),l=Gi(X(Gr(s.z),Tt(s.z).negate(),0,0),X(Tt(s.z),Gr(s.z),0,0),X(0,0,1,0),X(0,0,0,1));return o.mul(a).mul(l).mul(X(r,1)).xyz}}};var En=te(F0).setParameterLength(2);var IL=new dh,L0=class extends we{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(IL),this.setValues(e)}setupPositionView(e){let{object:t,camera:r}=e,{positionNode:i,rotationNode:s,scaleNode:o,sizeAttenuation:a}=this,l=$r.mul(N(i||0)),u=V(fr[0].xyz.length(),fr[1].xyz.length());o!==null&&(u=u.mul(V(o))),r.isPerspectiveCamera&&a===!1&&(u=u.mul(l.z.negate()));let c=Ua.xy;if(t.center&&t.center.isVector2===!0){let p=Tv("center","vec2",t);c=c.sub(p.sub(.5))}c=c.mul(u);let d=y(s||rb),h=En(c,d);return X(l.xy.add(h),l.zw)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}},Ff=L0;var OL=new wh,kL=new se,P0=class extends Ff{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.sizeNode=null,this.isPointsNodeMaterial=!0,this.setDefaultValues(OL),this.setValues(e)}setupPositionView(){let{positionNode:e}=this;return $r.mul(N(e||Le)).xyz}setupVertexSprite(e){let{material:t,camera:r}=e,{rotationNode:i,scaleNode:s,sizeNode:o,sizeAttenuation:a}=this,l=super.setupVertex(e);if(t.isNodeMaterial!==!0)return l;let u=o!==null?V(o):yb;u=u.mul(hy),r.isPerspectiveCamera&&a===!0&&(u=u.mul(VL.div($e.z.negate()))),s&&s.isNode&&(u=u.mul(V(s)));let c=Ua.xy;if(i&&i.isNode){let d=y(i);c=En(c,d)}return c=c.mul(u),c=c.div(kp.div(2)),c=c.mul(l.w),l=l.add(X(c,0,0)),l}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)}},VL=Y(1).onFrameUpdate(function({renderer:n}){let e=n.getSize(kL);this.value=.5*e.y}),tR=P0;var D0=class extends Cn{constructor(){super(),this.shadowNode=y(1).toVar("shadowMask")}direct({lightNode:e}){e.shadowNode!==null&&this.shadowNode.mulAssign(e.shadowNode)}finish({context:e}){ve.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(ve.rgb)}},rR=D0;var GL=new Rh,U0=class extends we{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.transparent=!0,this.setDefaultValues(GL),this.setValues(e)}setupLightingModel(){return new rR}},iR=U0;var I0=class{constructor(e,t,r){this.renderer=e,this.nodes=t,this.info=r,this._context=typeof self<"u"?self:null,this._animationLoop=null,this._requestId=null}start(){let e=(t,r)=>{this._requestId=this._context.requestAnimationFrame(e),this.info.autoReset===!0&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,this.renderer._inspector.begin(),this._animationLoop!==null&&this._animationLoop(t,r),this.renderer._inspector.finish()};e()}stop(){this._context!==null&&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()}},sR=I0;var O0=class{constructor(){this.weakMaps={}}_getWeakMap(e){let t=e.length,r=this.weakMaps[t];return r===void 0&&(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]),t===void 0)return;return t.get(e[e.length-1])}set(e,t){let r=this._getWeakMap(e);for(let i=0;i<e.length-1;i++){let s=e[i];r.has(s)===!1&&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]),t===void 0)return!1;return t.delete(e[e.length-1])}},Si=O0;var zL=0,nR=new WeakMap;function $L(n){let e=Object.keys(n),t=nR.get(n.constructor);if(t===void 0){t=[];let r=Object.getPrototypeOf(n);for(;r;){let i=Object.getOwnPropertyDescriptors(r);for(let s in i){let o=i[s];o&&typeof o.get=="function"&&t.push(s)}r=Object.getPrototypeOf(r)}nR.set(n.constructor,t)}for(let r=0;r<t.length;r++)e.push(t[r]);return e}var k0=class{constructor(e,t,r,i,s,o,a,l,u,c){this.id=zL++,this._nodes=e,this._geometries=t,this.renderer=r,this.object=i,this.material=s,this.scene=o,this.camera=a,this.lightsNode=l,this.context=u,this.geometry=i.geometry,this.version=s.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=c,this.clippingContextCacheKey=c!==null?c.cacheKey:"",this.initialNodesCacheKey=this.getDynamicCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=null,this._monitor=null,this._sourceMaterial=r._currentSourceMaterial,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),this._sourceMaterial!==null&&this._sourceMaterial.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return this.clippingContext===null||this.clippingContext.cacheKey===this.clippingContextCacheKey?!1:(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return this.getNodeBuilderState().hardwareClipping===!0?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(let 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(this.attributes!==null)return this.attributes;let e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,r=[],i=new Set,s={};for(let o of e){let a;if(o.node&&o.node.attribute?a=o.node.attribute:(a=t.getAttribute(o.name),a!==void 0&&(a.isInterleavedBufferAttribute?s[o.name]=a.data.uuid:s[o.name]=a.id)),a===void 0)continue;r.push(a);let l=a.isInterleavedBufferAttribute?a.data:a;i.add(l)}return this.attributes=r,this.attributesId=s,this.vertexBuffers=Array.from(i.values()),r}getVertexBuffers(){return this.vertexBuffers===null&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){let{object:e,material:t,geometry:r,group:i,drawRange:s}=this,o=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),a=this.getIndex(),l=a!==null,u=1;if(r.isInstancedBufferGeometry===!0?u=r.instanceCount:e.count!==void 0&&(u=Math.max(0,e.count)),u===0)return null;if(o.instanceCount=u,e.isBatchedMesh===!0)return o;let c=1;t.wireframe===!0&&!e.isPoints&&!e.isLineSegments&&!e.isLine&&!e.isLineLoop&&(c=2);let d=s.start*c,h=(s.start+s.count)*c;i!==null&&(d=Math.max(d,i.start*c),h=Math.min(h,(i.start+i.count)*c));let p=r.attributes.position,f=1/0;l?f=a.count:p!=null&&(f=p.count),d=Math.max(d,0),h=Math.min(h,f);let m=h-d;return m<0||m===1/0?null:(o.vertexCount=m,o.firstVertex=d,o)}getGeometryCacheKey(){let{geometry:e}=this,t="";for(let r of Object.keys(e.attributes).sort()){let i=e.attributes[r];t+=r+",",i.data&&(t+=i.data.stride+","),i.offset&&(t+=i.offset+","),i.itemSize&&(t+=i.itemSize+","),i.normalized&&(t+="n,")}for(let r of Object.keys(e.morphAttributes).sort()){let i=e.morphAttributes[r];t+="morph-"+r+",";for(let s=0,o=i.length;s<o;s++){let a=i[s];t+=a.id+","}}return e.index&&(t+="index,"),t}getMaterialCacheKey(){let{object:e,material:t,renderer:r}=this,i=t.customProgramCacheKey();for(let s of $L(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(s))continue;let o=t[s],a;if(o!==null){let l=typeof o;l==="number"?s==="side"?a=String(o):a=o!==0?"1":"0":l==="object"?(a="{",o.isTexture&&(a+=o.mapping,r.backend.isWebGPUBackend===!0&&(a+=o.magFilter,a+=o.minFilter,a+=o.wrapS,a+=o.wrapT,a+=o.wrapR)),a+="}"):a=String(o)}else a=String(o);i+=a+","}return i+=this.clippingContextCacheKey+",",e.geometry&&(i+=this.getGeometryCacheKey()),e.skeleton&&(i+=e.skeleton.bones.length+","),e.isBatchedMesh&&(i+=e._matricesTexture.uuid+",",e._colorsTexture!==null&&(i+=e._colorsTexture.uuid+",")),(e.isInstancedMesh||e.count>1)&&(i+=e.uuid+","),i+=this.context.id+",",i+=e.receiveShadow+",",Ii(i)}get needsGeometryUpdate(){if(this.geometry.id!==this.object.geometry.id)return!0;if(this.attributes!==null){let e=this.attributesId;for(let t in e){let r=this.geometry.getAttribute(t);if(r===void 0)return!0;let i=r.isInterleavedBufferAttribute?r.data.uuid:r.id;if(e[t]!==i)return!0}}return!1}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=0;return this.material.isShadowPassMaterial!==!0&&(e=this._nodes.getCacheKey(this.scene,this.lightsNode)),this.camera.isArrayCamera&&(e=po(e,this.camera.cameras.length)),this.object.receiveShadow&&(e=po(e,1)),e=po(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._sourceMaterial!==null&&this._sourceMaterial.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}},oR=k0;var zs=[],V0=class{constructor(e,t,r,i,s,o){this.renderer=e,this.nodes=t,this.geometries=r,this.pipelines=i,this.bindings=s,this.info=o,this.chainMaps={}}get(e,t,r,i,s,o,a,l){let u=this.getChainMap(l);zs[0]=e,zs[1]=t,zs[2]=o,zs[3]=s;let c=u.get(zs);return c===void 0?(c=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,r,i,s,o,a,l),u.set(zs,c)):(c.camera=i,c.updateClipping(a),c.needsGeometryUpdate&&c.setGeometry(e.geometry),(c.version!==t.version||c.needsUpdate)&&(c.initialCacheKey!==c.getCacheKey()?(c.dispose(),c=this.get(e,t,r,i,s,o,a,l)):c.version=t.version)),zs[0]=null,zs[1]=null,zs[2]=null,zs[3]=null,c}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Si)}dispose(){this.chainMaps={}}createRenderObject(e,t,r,i,s,o,a,l,u,c,d){let h=this.getChainMap(d),p=new oR(e,t,r,i,s,o,a,l,u,c);return p.onDispose=()=>{this.pipelines.delete(p),this.bindings.deleteForRender(p),this.nodes.delete(p),h.delete(p.getChainArray())},p}},aR=V0;var G0=class{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return t===void 0&&(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}},Ar=G0;var Wr={VERTEX:1,INDEX:2,STORAGE:3,INDIRECT:4},$s=16,lR=211,uR=212;var z0=class extends Ar{constructor(e,t){super(),this.backend=e,this.info=t}delete(e){let t=super.delete(e);return t!==null&&(this.backend.destroyAttribute(e),this.info.destroyAttribute(e)),t}update(e,t){let r=this.get(e);if(r.version===void 0)t===Wr.VERTEX?(this.backend.createAttribute(e),this.info.createAttribute(e)):t===Wr.INDEX?(this.backend.createIndexAttribute(e),this.info.createIndexAttribute(e)):t===Wr.STORAGE?(this.backend.createStorageAttribute(e),this.info.createStorageAttribute(e)):t===Wr.INDIRECT&&(this.backend.createIndirectStorageAttribute(e),this.info.createIndirectStorageAttribute(e)),r.version=this._getBufferAttribute(e).version;else{let i=this._getBufferAttribute(e);(r.version<i.version||i.usage===eo)&&(this.backend.updateAttribute(e),r.version=i.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}},cR=z0;function hR(n){return n.index!==null?n.index.version:n.attributes.position.version}function pR(n){return n.index!==null?n.index.id:n.attributes.position.id}function dR(n){let e=[],t=n.index,r=n.attributes.position;if(t!==null){let s=t.array;for(let o=0,a=s.length;o<a;o+=3){let l=s[o+0],u=s[o+1],c=s[o+2];e.push(l,u,u,c,c,l)}}else{let s=r.array;for(let o=0,a=s.length/3-1;o<a;o+=3){let l=o+0,u=o+1,c=o+2;e.push(l,u,u,c,c,l)}}let i=new(r.count>=65535?_l:bl)(e,1);return i.version=hR(n),i.__id=pR(n),i}var $0=class extends Ar{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap,this._geometryDisposeListeners=new Map}has(e){let t=e.geometry;return super.has(t)&&this.get(t).initialized===!0}updateForRender(e){this.has(e)===!1&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){let t=e.geometry,r=this.get(t);r.initialized=!0,this.info.memory.geometries++;let i=()=>{this.info.memory.geometries--;let s=t.index;s!==null&&this.attributes.delete(s);for(let l of Object.values(t.attributes))this.attributes.delete(l);let o=this.wireframes.get(t);o!==void 0&&this.attributes.delete(o);let a=new Set(Object.values(e.geometry.attributes));for(let l of e.getAttributes())a.has(l)===!1&&this.attributes.delete(l);t.removeEventListener("dispose",i),this._geometryDisposeListeners.delete(t)};t.addEventListener("dispose",i),this._geometryDisposeListeners.set(t,i)}updateAttributes(e){let t=e.getAttributes();for(let s of t)s.isStorageBufferAttribute||s.isStorageInstancedBufferAttribute?this.updateAttribute(s,Wr.STORAGE):this.updateAttribute(s,Wr.VERTEX);let r=this.getIndex(e);r!==null&&this.updateAttribute(r,Wr.INDEX);let i=e.geometry.indirect;i!==null&&this.updateAttribute(i,Wr.INDIRECT)}updateAttribute(e,t){let r=this.info.render.calls;e.isInterleavedBufferAttribute?this.attributeCall.get(e)===void 0?(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){let{geometry:t,material:r}=e,i=t.index;if(r.wireframe===!0){let s=this.wireframes,o=s.get(t);o===void 0?(o=dR(t),s.set(t,o)):(o.version!==hR(t)||o.__id!==pR(t))&&(this.attributes.delete(o),o=dR(t),s.set(t,o)),i=o}return i}dispose(){for(let[e,t]of this._geometryDisposeListeners.entries())e.removeEventListener("dispose",t);this._geometryDisposeListeners.clear()}},fR=$0;var W0=class{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={attributes:0,attributesSize:0,geometries:0,indexAttributes:0,indexAttributesSize:0,indirectStorageAttributes:0,indirectStorageAttributesSize:0,programs:0,programsSize:0,readbackBuffers:0,readbackBuffersSize:0,renderTargets:0,storageAttributes:0,storageAttributesSize:0,textures:0,texturesSize:0,uniformBuffers:0,uniformBuffersSize:0,total:0},this.memoryMap=new WeakMap}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):I("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;for(let e in this.memory)this.memory[e]=0;this.memoryMap=new WeakMap}createTexture(e){let t=this._getTextureMemorySize(e);this.memoryMap.set(e,t),this.memory.textures++,this.memory.total+=t,this.memory.texturesSize+=t}destroyTexture(e){let t=this.memoryMap.get(e)||0;this.memoryMap.delete(e),this.memory.textures--,this.memory.total-=t,this.memory.texturesSize-=t}_createAttribute(e,t){let r=this._getAttributeMemorySize(e);this.memoryMap.set(e,{size:r,type:t}),this.memory[t]++,this.memory.total+=r,this.memory[t+"Size"]+=r}createAttribute(e){this._createAttribute(e,"attributes")}createIndexAttribute(e){this._createAttribute(e,"indexAttributes")}createStorageAttribute(e){this._createAttribute(e,"storageAttributes")}createIndirectStorageAttribute(e){this._createAttribute(e,"indirectStorageAttributes")}destroyAttribute(e){let t=this.memoryMap.get(e);t&&(this.memoryMap.delete(e),this.memory[t.type]--,this.memory.total-=t.size,this.memory[t.type+"Size"]-=t.size)}createReadbackBuffer(e){let t=e.maxByteLength;this.memoryMap.set(e,{size:t,type:"readbackBuffers"}),this.memory.readbackBuffers++,this.memory.total+=t,this.memory.readbackBuffersSize+=t}destroyReadbackBuffer(e){let{size:t}=this.memoryMap.get(e);this.memoryMap.delete(e),this.memory.readbackBuffers--,this.memory.total-=t,this.memory.readbackBuffersSize-=t}createUniformBuffer(e){let t=e.byteLength;this.memoryMap.set(e,{size:t,type:"uniformBuffers"}),this.memory.uniformBuffers++,this.memory.total+=t,this.memory.uniformBuffersSize+=t}destroyUniformBuffer(e){let t=this.memoryMap.get(e);t&&(this.memoryMap.delete(e),this.memory.uniformBuffers--,this.memory.total-=t.size,this.memory.uniformBuffersSize-=t.size)}createProgram(e){let t=e.code.length;this.memoryMap.set(e,t),this.memory.programs++,this.memory.total+=t,this.memory.programsSize+=t}destroyProgram(e){let t=this.memoryMap.get(e)||0;this.memoryMap.delete(e),this.memory.programs--,this.memory.total-=t,this.memory.programsSize-=t}_getTextureMemorySize(e){if(e.isCompressedTexture)return 1;let t=1;e.type===Ci||e.type===it?t=1:e.type===mr||e.type===er||e.type===qe?t=2:(e.type===Je||e.type===Ce||e.type===ze)&&(t=4);let r=4;e.format===Xn||e.format===Bi||e.format===Fi||e.format===Mt||e.format===Ht?r=1:e.format===vt||e.format===Li?r=2:(e.format===Ei||e.format===sl)&&(r=3);let i=t*r;e.type===rl||e.type===il?i=2:(e.type===Qr||e.type===qn||e.type===jn)&&(i=4);let s=e.width||1,o=e.height||1,a=e.isCubeTexture?6:e.depth||1,l=s*o*a*i,u=e.mipmaps;if(u&&u.length>0){let c=0;for(let d=0;d<u.length;d++){let h=u[d];if(h.data)c+=h.data.byteLength;else{let p=h.width||Math.max(1,s>>d),f=h.height||Math.max(1,o>>d);c+=p*f*a*i}}l+=c}else e.generateMipmaps&&(l=l*1.333);return Math.round(l)}_getAttributeMemorySize(e){return e.isInterleavedBufferAttribute&&(e=e.data),e.array?e.array.byteLength:e.count&&e.itemSize?e.count*e.itemSize*4:0}},mR=W0;var H0=class{constructor(e){this.cacheKey=e,this.usedTimes=0}},Lf=H0;var q0=class extends Lf{constructor(e,t,r){super(e),this.vertexProgram=t,this.fragmentProgram=r}},gR=q0;var j0=class extends Lf{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}},xR=j0;var WL=0,X0=class{constructor(e,t,r,i=null,s=null){this.id=WL++,this.code=e,this.stage=t,this.name=r,this.transforms=i,this.attributes=s,this.usedTimes=0}},Pf=X0;var Y0=class extends Ar{constructor(e,t,r){super(),this.backend=e,this.nodes=t,this.info=r,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){let{backend:r}=this,i=this.get(e);if(this._needsComputeUpdate(e)){let s=i.pipeline;s&&(s.usedTimes--,s.computeProgram.usedTimes--);let o=this.nodes.getForCompute(e),a=this.programs.compute.get(o.computeShader);a===void 0&&(s&&s.computeProgram.usedTimes===0&&this._releaseProgram(s.computeProgram),a=new Pf(o.computeShader,"compute",e.name,o.transforms,o.nodeAttributes),this.programs.compute.set(o.computeShader,a),r.createProgram(a),this.info.createProgram(a));let l=this._getComputeCacheKey(e,a),u=this.caches.get(l);u===void 0&&(s&&s.usedTimes===0&&this._releasePipeline(s),u=this._getComputePipeline(e,a,l,t)),u.usedTimes++,a.usedTimes++,i.version=e.version,i.pipeline=u}return i.pipeline}getForRender(e,t=null){let{backend:r}=this,i=this.get(e);if(this._needsRenderUpdate(e)){let s=i.pipeline;s&&(s.usedTimes--,s.vertexProgram.usedTimes--,s.fragmentProgram.usedTimes--);let o=e.getNodeBuilderState(),a=e.material?e.material.name:"",l=this.programs.vertex.get(o.vertexShader);l===void 0&&(s&&s.vertexProgram.usedTimes===0&&this._releaseProgram(s.vertexProgram),l=new Pf(o.vertexShader,"vertex",a),this.programs.vertex.set(o.vertexShader,l),r.createProgram(l),this.info.createProgram(l));let u=this.programs.fragment.get(o.fragmentShader);u===void 0&&(s&&s.fragmentProgram.usedTimes===0&&this._releaseProgram(s.fragmentProgram),u=new Pf(o.fragmentShader,"fragment",a),this.programs.fragment.set(o.fragmentShader,u),r.createProgram(u),this.info.createProgram(u));let c=this._getRenderCacheKey(e,l,u),d=this.caches.get(c);d===void 0?(s&&s.usedTimes===0&&this._releasePipeline(s),d=this._getRenderPipeline(e,l,u,c,t)):e.pipeline=d,d.usedTimes++,l.usedTimes++,u.usedTimes++,i.pipeline=d}return i.pipeline}isReady(e){let r=this.get(e).pipeline;if(r===void 0)return!1;let i=this.backend.get(r);return i.pipeline!==void 0&&i.pipeline!==null}delete(e){let t=this.get(e).pipeline;return t&&(t.usedTimes--,t.usedTimes===0&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,t.computeProgram.usedTimes===0&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,t.vertexProgram.usedTimes===0&&this._releaseProgram(t.vertexProgram),t.fragmentProgram.usedTimes===0&&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,i){r=r||this._getComputeCacheKey(e,t);let s=this.caches.get(r);return s===void 0&&(s=new xR(r,t),this.caches.set(r,s),this.backend.createComputePipeline(s,i)),s}_getRenderPipeline(e,t,r,i,s){i=i||this._getRenderCacheKey(e,t,r);let o=this.caches.get(i);return o===void 0&&(o=new gR(i,t,r),this.caches.set(i,o),e.pipeline=o,this.backend.createRenderPipeline(e,s)),o}_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){let t=e.code,r=e.stage;this.programs[r].delete(t),this.info.destroyProgram(e)}_needsComputeUpdate(e){let t=this.get(e);return t.pipeline===void 0||t.version!==e.version}_needsRenderUpdate(e){return this.get(e).pipeline===void 0||this.backend.needsRenderUpdate(e)}},yR=Y0;var K0=class extends Ar{constructor(e,t,r,i,s,o){super(),this.backend=e,this.textures=r,this.pipelines=s,this.attributes=i,this.nodes=t,this.info=o,this.pipelines.bindings=this}getForRender(e){let t=e.getBindings(),r=this.get(e);return r.initialized!==!0&&(this._createBindings(t),r.initialized=!0),t}getForCompute(e){let t=this.nodes.getForCompute(e).bindings,r=this.get(e);return(r.initialized!==!0||r.bindings!==t)&&(r.bindings!==void 0&&this._destroyBindings(r.bindings),this._createBindings(t),r.initialized=!0,r.bindings=t),t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}deleteForCompute(e){let r=this.get(e).bindings||this.nodes.getForCompute(e).bindings;this._destroyBindings(r),this.delete(e)}deleteForRender(e){let t=e.getBindings();this._destroyBindings(t),this.delete(e)}_createBindings(e){for(let t of e){let r=this.get(t);if(r.bindGroup===void 0){for(let i of t.bindings)if(i.isUniformBuffer)this.backend.createUniformBuffer(i),this.info.createUniformBuffer(i);else if(i.isSampledTexture)this.textures.updateTexture(i.texture);else if(i.isSampler)this.textures.updateSampler(i);else if(i.isStorageBuffer){let s=i.attribute,o=s.isIndirectStorageBufferAttribute?Wr.INDIRECT:Wr.STORAGE;this.attributes.update(s,o)}this.backend.createBindings(t,e,0),r.bindGroup=t,r.usedTimes=1}else r.usedTimes++}}_destroyBindings(e){for(let t of e){let r=this.get(t);if(r.usedTimes--,r.usedTimes===0){for(let i of t.bindings)if(i.isUniformBuffer)this.backend.destroyUniformBuffer(i),this.info.destroyUniformBuffer(i),i.release();else if(i.isSampler){if(i.isSampledTexture!==!0)this.backend.destroySampler(i);else if(i.texture!==null){let s=this.textures.get(i.texture);s.bindGroups!==void 0&&s.bindGroups.delete(t)}i.release()}this.backend.deleteBindGroupData(t),this.delete(t)}}}_updateBindings(e){for(let t of e)this._update(t,e)}_update(e,t){let{backend:r}=this,i=!1,s=!0,o=0,a=0;for(let l of e.bindings)if(this.nodes.updateGroup(l)!==!1){if(l.isStorageBuffer){let c=l.attribute,d=c.isIndirectStorageBufferAttribute?Wr.INDIRECT:Wr.STORAGE,h=r.get(l);this.attributes.update(c,d),h.attribute!==c&&(h.attribute=c,i=!0)}if(l.isUniformBuffer)l.update()&&r.updateBinding(l);else if(l.isSampledTexture){let c=l.update(),d=l.texture,h=this.textures.get(d);if(c&&(this.textures.updateTexture(d),l.generation!==h.generation&&(l.generation=h.generation,i=!0),h.bindGroups.add(e)),r.get(d).externalTexture!==void 0||h.isDefaultTexture?s=!1:(o=o*10+d.id,a+=d.version),d.isStorageTexture===!0&&d.mipmapsAutoUpdate===!0){let f=this.get(d);l.store===!0?f.needsMipmap=!0:this.textures.needsMipmaps(d)&&f.needsMipmap===!0&&(this.backend.generateMipmaps(d),f.needsMipmap=!1)}}else if(l.isSampler&&l.update()){let d=this.textures.updateSampler(l);l.samplerKey!==d&&(l.samplerKey=d,i=!0)}l.isBuffer&&l.updateRanges.length>0&&l.clearUpdateRanges()}i===!0&&this.backend.updateBindings(e,t,s?o:0,a)}},bR=K0;var HL=Object.freeze([]);function qL(n,e){return n.groupOrder!==e.groupOrder?n.groupOrder-e.groupOrder:n.renderOrder!==e.renderOrder?n.renderOrder-e.renderOrder:n.z!==e.z?n.z-e.z:n.id-e.id}function _R(n,e){return n.groupOrder!==e.groupOrder?n.groupOrder-e.groupOrder:n.renderOrder!==e.renderOrder?n.renderOrder-e.renderOrder:n.z!==e.z?e.z-n.z:n.id-e.id}function TR(n){return(n.transmission>0||n.transmissionNode&&n.transmissionNode.isNode)&&n.side===Kr&&n.forceSinglePass===!1}var Q0=class{constructor(e,t,r){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lighting=e,this.lightsNode=e.getNode(t),this.lightsArray=[],this.scene=t,this.camera=r,this.occlusionQueryCount=0,this.frameId=-1,this._lastOcclusionObject=null}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,i,s,o,a){let l=this.renderItems[this.renderItemsIndex];return l===void 0?(l={id:e.id,object:e,geometry:t,material:r,groupOrder:i,renderOrder:e.renderOrder,z:s,group:o,clippingContext:a},this.renderItems[this.renderItemsIndex]=l):(l.id=e.id,l.object=e,l.geometry=t,l.material=r,l.groupOrder=i,l.renderOrder=e.renderOrder,l.z=s,l.group=o,l.clippingContext=a),this.renderItemsIndex++,l}push(e,t,r,i,s,o,a){this.camera.reversedDepth===!0&&(s=-s);let l=this.getNextRenderItem(e,t,r,i,s,o,a);e.occlusionTest===!0&&this._lastOcclusionObject!==e&&(this.occlusionQueryCount++,this._lastOcclusionObject=e),r.transparent===!0||r.transmission>0||r.transmissionNode&&r.transmissionNode.isNode||r.backdropNode&&r.backdropNode.isNode?(TR(r)&&this.transparentDoublePass.push(l),this.transparent.push(l)):this.opaque.push(l)}unshift(e,t,r,i,s,o,a){let l=this.getNextRenderItem(e,t,r,i,s,o,a);r.transparent===!0||r.transmission>0||r.transmissionNode&&r.transmissionNode.isNode||r.backdropNode&&r.backdropNode.isNode?(TR(r)&&this.transparentDoublePass.unshift(l),this.transparent.unshift(l)):this.opaque.unshift(l)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||qL),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||_R),this.transparent.length>1&&this.transparent.sort(t||_R)}finish(){this.lightsNode.setLights(this.lighting.enabled?this.lightsArray:HL);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){let r=this.renderItems[e];if(r.id===null)break;SR(r)}this._lastOcclusionObject=null}clear(){for(let e=0,t=this.renderItems.length;e<t;e++){let r=this.renderItems[e];if(r.id===null)break;SR(r)}this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0}};function SR(n){n.id=null,n.object=null,n.geometry=null,n.material=null,n.groupOrder=null,n.renderOrder=null,n.z=null,n.group=null,n.clippingContext=null}var NR=Q0;var No=[],Z0=class{constructor(){this.lists=new Si,this._activeLists=new Set,this._frameId=-1}get(e,t,r){let i=this.lists;No[0]=e,No[1]=t,No[2]=r;let s=i.get(No);return s===void 0&&(s=new NR(r,e,t),i.set(No,s)),No[0]=null,No[1]=null,No[2]=null,s.frameId=this._frameId,this._activeLists.add(s),s}update(e){if(e!==this._frameId){this._frameId=e;for(let t of this._activeLists)e-t.frameId>10&&(t.clear(),this._activeLists.delete(t))}}dispose(){this.lists=new Si,this._activeLists.clear(),this._frameId=-1}},wR=Z0;var jL=0,J0=class{constructor(){this.id=jL++,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 pe,this.scissor=!1,this.scissorValue=new pe,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.fullscreenPass=!1,this.isRenderContext=!0}getCacheKey(){return e_(this)}};function e_(n){let{textures:e,activeCubeFace:t,activeMipmapLevel:r}=n,i=[t,r];for(let s of e)i.push(s.id);return Ns(i)}var MR=J0;var t_=class{constructor(e){this.renderer=e,this._renderContexts={}}get(e=null,t=null,r=0){let i;if(e===null)i="default";else{let l=e.texture.format,u=e.texture.type;i=`${e.textures.length}:${l}:${u}:${e.samples}:${e.depthBuffer}:${e.stencilBuffer}`}let s=t!==null?t.id:"default",o=i+"-"+s+"-"+r,a=this._renderContexts[o];return a===void 0&&(a=new MR,a.mrt=t,this._renderContexts[o]=a),e!==null&&(a.sampleCount=e.samples===0?1:e.samples),a.clearDepthValue=this.renderer.getClearDepth(),a.clearStencilValue=this.renderer.getClearStencil(),a}dispose(){this._renderContexts={}}},vR=t_;var XL=new C,r_=class extends Ar{constructor(e,t,r){super(),this.renderer=e,this.backend=t,this.info=r,this._htmlTextures=new Set}updateRenderTarget(e,t=0){let r=this.get(e),i=e.samples===0?1:e.samples,s=r.depthTextureMips||(r.depthTextureMips={}),o=e.textures,a=this.getSize(o[0]),l=a.width>>t,u=a.height>>t,c=e.depthTexture||s[t],d=e.depthBuffer===!0||e.stencilBuffer===!0,h=!1,p=c!==void 0&&c.image!==void 0&&c.image.depth>1,f=a.depth>1&&(e.useArrayDepthTexture||e.multiview||p);c===void 0&&d&&(c=new ot,c.format=e.stencilBuffer?Ht:Mt,c.type=e.stencilBuffer?Qr:Ce,c.image.width=l,c.image.height=u,c.image.depth=a.depth,c.renderTarget=e,s[t]=c),c&&(c.isArrayTexture=f),(r.width!==a.width||a.height!==r.height)&&(h=!0,c&&c.renderTarget===e&&(c.needsUpdate=!0,c.image.width=l,c.image.height=u,c.image.depth=f?a.depth:1)),r.width=a.width,r.height=a.height,r.textures=o,r.depthTexture=c||null,r.depth=e.depthBuffer,r.stencil=e.stencilBuffer,r.renderTarget=e,r.sampleCount!==i&&(h=!0,c&&c.renderTarget===e&&(c.needsUpdate=!0),r.sampleCount=i);let m={sampleCount:i};if(e.isXRRenderTarget!==!0){for(let g=0;g<o.length;g++){let x=o[g];h&&(x.needsUpdate=!0),this.updateTexture(x,m)}c&&this.updateTexture(c,m)}r.initialized!==!0&&(r.initialized=!0,this.info.memory.renderTargets++,r.onDispose=()=>{this._destroyRenderTarget(e)},e.addEventListener("dispose",r.onDispose))}updateTexture(e,t={}){let r=this.get(e);if(r.initialized===!0&&r.version===e.version)return;let i=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,s=this.backend;if(i&&r.initialized===!0&&s.destroyTexture(e),e.isFramebufferTexture){let u=this.renderer.getRenderTarget();u?e.type=u.texture.type:e.type=it}if(e.isHTMLTexture&&e.image){let u=this.renderer.domElement;if("requestPaint"in u){if(u.hasAttribute("layoutsubtree")||u.setAttribute("layoutsubtree","true"),e.image.parentNode!==u&&u.appendChild(e.image),this._htmlTextures.size===0){let c=this._htmlTextures;u.onpaint=d=>{let h=d&&d.changedElements;for(let p of c)(!h||h.includes(p.image))&&(p.needsUpdate=!0)}}this._htmlTextures.add(e)}}let{width:o,height:a,depth:l}=this.getSize(e);if(t.width=o,t.height=a,t.depth=l,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,o,a):1,e.isCubeTexture&&e.mipmaps.length>0&&t.levels++,i||e.isStorageTexture===!0||e.isExternalTexture===!0)s.createTexture(e,t),r.generation=e.version;else if(e.version>0){let u=e.image;if(u===void 0)U("Renderer: Texture marked for update but image is undefined.");else if(u.complete===!1)U("Renderer: Texture marked for update but image is incomplete.");else{if(e.images){let d=[];for(let h of e.images)d.push(h);t.images=d}else t.image=u;(r.isDefaultTexture===void 0||r.isDefaultTexture===!0)&&(s.createTexture(e,t),r.isDefaultTexture=!1,r.generation=e.version),e.source.dataReady===!0&&s.updateTexture(e,t);let c=e.isStorageTexture===!0&&e.mipmapsAutoUpdate===!1;t.needsMipmaps&&e.mipmaps.length===0&&!c&&s.generateMipmaps(e),e.onUpdate&&e.onUpdate(e)}}else s.createDefaultTexture(e),r.isDefaultTexture=!0,r.generation=e.version;r.initialized!==!0&&(r.initialized=!0,r.generation=e.version,r.bindGroups=new Set,this.info.createTexture(e),e.isVideoTexture&&Me.enabled===!0&&Me.getTransfer(e.colorSpace)!==fe&&U("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=XL){let r=e.images?e.images[0]:e.image;return r?(r.image!==void 0&&(r=r.image),e.isHTMLTexture?(t.width=r.offsetWidth||1,t.height=r.offsetHeight||1,t.depth=1):typeof HTMLVideoElement<"u"&&r instanceof HTMLVideoElement?(t.width=r.videoWidth||1,t.height=r.videoHeight||1,t.depth=1):typeof VideoFrame<"u"&&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 i;return e.mipmaps.length>0?i=e.mipmaps.length:e.isCompressedTexture===!0?i=1:i=Math.floor(Math.log2(Math.max(t,r)))+1,i}needsMipmaps(e){return e.generateMipmaps===!0||e.mipmaps.length>0}_destroyRenderTarget(e){if(this.has(e)===!0){let t=this.get(e),r=t.textures,i=t.depthTexture;e.removeEventListener("dispose",t.onDispose);for(let s=0;s<r.length;s++)this._destroyTexture(r[s]);i&&i.renderTarget===e&&this._destroyTexture(i),this.delete(e),this.backend.delete(e),this.info.memory.renderTargets--}}_destroyTexture(e){if(this.has(e)===!0){let t=this.get(e);e.removeEventListener("dispose",t.onDispose);let r=t.isDefaultTexture;if(this.backend.destroyTexture(e,r),t.bindGroups)for(let i of t.bindGroups){let s=this.backend.get(i);s.groups=void 0,s.versions=void 0;for(let o of i.bindings)o.isSampler&&o.texture===e&&(o.isSampledTexture!==!0&&this.backend.destroySampler(o),o.reset(),o.release())}this._htmlTextures.delete(e),this.delete(e),this.info.destroyTexture(e)}}},AR=r_;var i_=class extends le{constructor(e,t,r,i=1){super(e,t,r),this.a=i}set(e,t,r,i=1){return this.a=i,super.set(e,t,r)}copy(e){return e.a!==void 0&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}},iu=i_;var mm={};tE(mm,{BRDF_GGX:()=>Jl,BRDF_Lambert:()=>us,BasicPointShadowFilter:()=>jR,BasicShadowFilter:()=>aT,Break:()=>xF,Const:()=>xv,Continue:()=>gF,DFGLUT:()=>eu,D_GGX:()=>bf,Discard:()=>Ev,EPSILON:()=>uc,F_Schlick:()=>Hi,Fn:()=>_,HALF_PI:()=>pB,INFINITY:()=>cB,If:()=>ie,Loop:()=>Ee,NodeAccess:()=>mt,NodeShaderStage:()=>Ra,NodeType:()=>WE,NodeUpdateType:()=>J,OnAfterRenderPipeline:()=>dF,OnBeforeFrameUpdate:()=>uF,OnBeforeMaterialUpdate:()=>lF,OnBeforeObjectUpdate:()=>aF,OnBeforeRenderPipeline:()=>cF,OnFrameUpdate:()=>Nb,OnMaterialUpdate:()=>oF,OnObjectUpdate:()=>So,PCFShadowFilter:()=>lT,PI:()=>cc,PI2:()=>dB,PointShadowFilter:()=>XR,Return:()=>SB,Schlick_to_F0:()=>Ic,ShaderNode:()=>Ea,Stack:()=>lM,Switch:()=>nB,TBNViewMatrix:()=>Rn,TWO_PI:()=>hB,VSMShadowFilter:()=>uT,V_GGX_SmithCorrelated:()=>yf,Var:()=>gv,VarIntent:()=>yv,abs:()=>Ue,acesFilmicToneMapping:()=>W_,acos:()=>gp,acosh:()=>qM,add:()=>Xe,addMethodChaining:()=>P,addNodeElement:()=>NB,agxToneMapping:()=>H_,all:()=>UM,alphaT:()=>Ul,ambientOcclusion:()=>dp,and:()=>SM,anisotropy:()=>As,anisotropyB:()=>Rs,anisotropyT:()=>La,any:()=>IM,array:()=>lc,asin:()=>WM,asinh:()=>HM,assign:()=>mM,atan:()=>xp,atanh:()=>jM,atomicAdd:()=>ID,atomicAnd:()=>GD,atomicFunc:()=>Hs,atomicLoad:()=>DD,atomicMax:()=>kD,atomicMin:()=>VD,atomicOr:()=>zD,atomicStore:()=>UD,atomicSub:()=>OD,atomicXor:()=>$D,attenuationColor:()=>nc,attenuationDistance:()=>sc,attribute:()=>Mr,attributeArray:()=>zP,backgroundBlurriness:()=>E_,backgroundIntensity:()=>Wf,backgroundRotation:()=>B_,batch:()=>Cb,batchColor:()=>of,bentNormalView:()=>Vy,billboarding:()=>RP,bitAnd:()=>vM,bitNot:()=>AM,bitOr:()=>RM,bitXor:()=>CM,bitangentGeometry:()=>QB,bitangentLocal:()=>ZB,bitangentView:()=>ky,bitangentWorld:()=>JB,bitcast:()=>p_,blendBurn:()=>ZP,blendColor:()=>rD,blendDodge:()=>JP,blendOverlay:()=>tD,blendScreen:()=>eD,bool:()=>nr,buffer:()=>Ls,bufferAttribute:()=>Bp,builtin:()=>$i,builtinAOContext:()=>fv,builtinShadowContext:()=>pv,bumpMap:()=>vc,bvec2:()=>cM,bvec3:()=>op,bvec4:()=>dM,bypass:()=>Rv,cache:()=>Av,call:()=>gM,cameraFar:()=>Us,cameraIndex:()=>yo,cameraNear:()=>Ds,cameraNormalMatrix:()=>EB,cameraPosition:()=>Sy,cameraProjectionMatrix:()=>zr,cameraProjectionMatrixInverse:()=>Ty,cameraViewMatrix:()=>yi,cameraViewport:()=>BB,cameraWorldMatrix:()=>bo,cbrt:()=>av,cdl:()=>aD,ceil:()=>zl,checker:()=>U2,cineonToneMapping:()=>$_,clamp:()=>ur,clearcoat:()=>Ll,clearcoatNormalView:()=>Os,clearcoatRoughness:()=>vn,clipSpace:()=>Uv,code:()=>Zf,color:()=>uM,colorSpaceToWorking:()=>Wl,colorToDirection:()=>rF,compute:()=>vv,computeKernel:()=>Yx,computeSkinning:()=>mF,context:()=>wr,convert:()=>pM,convertColorSpace:()=>xB,convertToTexture:()=>IP,cos:()=>Gr,cosh:()=>GM,countLeadingZeros:()=>nP,countOneBits:()=>oP,countTrailingZeros:()=>sP,cross:()=>gi,cubeTexture:()=>Ft,cubeTextureBase:()=>Fy,dFdx:()=>bp,dFdy:()=>_p,dashSize:()=>rc,debug:()=>Bv,decrement:()=>DM,decrementBefore:()=>LM,defaultBuildStages:()=>Xu,defaultShaderStages:()=>tM,defined:()=>Sn,degrees:()=>kM,deltaTime:()=>_P,densityFogFactor:()=>K_,depth:()=>df,depthPass:()=>hD,determinant:()=>ZM,difference:()=>rv,diffuseColor:()=>ve,diffuseContribution:()=>Mn,directPointLight:()=>YR,directionToColor:()=>tF,directionToFaceDirection:()=>WB,dispersion:()=>oc,disposeShadowMaterial:()=>dT,distance:()=>tv,div:()=>xt,dot:()=>ar,drawIndex:()=>jx,dynamicBufferAttribute:()=>yB,element:()=>hM,emissive:()=>up,equal:()=>xM,equirectDirection:()=>hf,equirectUV:()=>Pc,exp:()=>Gl,exp2:()=>mo,exponentialHeightFogFactor:()=>ND,expression:()=>dr,faceDirection:()=>Yp,faceForward:()=>Lx,faceforward:()=>fB,float:()=>y,floatBitsToInt:()=>tP,floatBitsToUint:()=>f_,floor:()=>Vr,fog:()=>em,fract:()=>ii,frameGroup:()=>lB,frameId:()=>x_,frontFacing:()=>Iv,fwidth:()=>Sp,gain:()=>lP,gapSize:()=>cp,getConstNodeType:()=>Mx,getCurrentStack:()=>ec,getDistanceAttenuation:()=>rd,getGeometryRoughness:()=>xf,getNormalFromDepth:()=>VP,getParallaxCorrectNormal:()=>gC,getRoughness:()=>Zl,getScreenPosition:()=>OP,getScreenPositionFromClip:()=>kP,getShIrradianceAt:()=>fm,getShadowMaterial:()=>cT,getShadowRenderObjectFunction:()=>HR,getTextureIndex:()=>ER,getViewPosition:()=>au,globalId:()=>AD,glsl:()=>_D,glslFn:()=>TD,grayscale:()=>iD,greaterThan:()=>mp,greaterThanEqual:()=>TM,hash:()=>aP,highpModelNormalViewMatrix:()=>Xp,highpModelViewMatrix:()=>jp,hue:()=>oD,increment:()=>PM,incrementBefore:()=>FM,inspector:()=>Fv,instance:()=>sA,instanceColor:()=>nf,instanceIndex:()=>cr,instancedArray:()=>$P,instancedBufferAttribute:()=>Hl,instancedDynamicBufferAttribute:()=>Fp,instancedMesh:()=>Rb,int:()=>A,intBitsToFloat:()=>rP,interleavedGradientNoise:()=>Kc,inverse:()=>JM,inverseSqrt:()=>Bx,inversesqrt:()=>mB,invocationLocalIndex:()=>TB,invocationSubgroupIndex:()=>_B,ior:()=>Pa,iridescence:()=>Fa,iridescenceIOR:()=>Pl,iridescenceThickness:()=>Dl,isolate:()=>Da,ivec2:()=>dt,ivec3:()=>np,ivec4:()=>ap,js:()=>yD,label:()=>mv,length:()=>mi,lengthSq:()=>Mp,lessThan:()=>bM,lessThanEqual:()=>_M,lightPosition:()=>im,lightProjectionUV:()=>iT,lightShadowMatrix:()=>lu,lightTargetDirection:()=>Jc,lightTargetPosition:()=>GR,lightViewPosition:()=>Zc,lightingContext:()=>kb,lights:()=>_2,linearDepth:()=>Lc,linearToneMapping:()=>G_,localId:()=>RD,log:()=>go,log2:()=>kr,logarithmicDepthToViewZ:()=>SF,luminance:()=>O_,mat2:()=>Fl,mat3:()=>rt,mat4:()=>Gi,matcapUV:()=>E0,materialAO:()=>Tb,materialAlphaTest:()=>Wy,materialAnisotropy:()=>nb,materialAnisotropyVector:()=>Kl,materialAttenuationColor:()=>pb,materialAttenuationDistance:()=>hb,materialClearcoat:()=>Jy,materialClearcoatNormal:()=>tb,materialClearcoatRoughness:()=>eb,materialColor:()=>Hy,materialDispersion:()=>bb,materialEmissive:()=>jy,materialEnvIntensity:()=>Sc,materialEnvRotation:()=>Xl,materialIOR:()=>db,materialIridescence:()=>ob,materialIridescenceIOR:()=>ab,materialIridescenceThickness:()=>lb,materialLightMap:()=>Cc,materialLineDashOffset:()=>xb,materialLineDashSize:()=>mb,materialLineGapSize:()=>gb,materialLineScale:()=>fb,materialLineWidth:()=>nF,materialMetalness:()=>Qy,materialNormal:()=>Zy,materialOpacity:()=>Ac,materialPointSize:()=>yb,materialReference:()=>bi,materialReflectivity:()=>Rc,materialRefractionRatio:()=>Ry,materialRetroreflective:()=>_b,materialRotation:()=>rb,materialRoughness:()=>Ky,materialSheen:()=>ib,materialSheenRoughness:()=>sb,materialShininess:()=>qy,materialSpecular:()=>Xy,materialSpecularColor:()=>Yy,materialSpecularIntensity:()=>rf,materialSpecularStrength:()=>Ia,materialThickness:()=>cb,materialTransmission:()=>ub,max:()=>Ie,maxMipLevel:()=>gc,mediumpModelViewMatrix:()=>Dv,metalness:()=>ss,min:()=>ht,mix:()=>xe,mixElement:()=>uv,mod:()=>Vl,modelDirection:()=>OB,modelNormalMatrix:()=>wy,modelPosition:()=>kB,modelRadius:()=>zB,modelScale:()=>VB,modelViewMatrix:()=>$r,modelViewPosition:()=>GB,modelViewProjection:()=>Sb,modelWorldMatrix:()=>fr,modelWorldMatrixInverse:()=>$B,morphReference:()=>Pb,mrt:()=>BR,mul:()=>ce,mx_aastep:()=>dC,mx_add:()=>zU,mx_atan2:()=>XU,mx_cell_noise_float:()=>OU,mx_contrast:()=>EU,mx_divide:()=>HU,mx_fractal_noise_float:()=>kU,mx_fractal_noise_vec2:()=>VU,mx_fractal_noise_vec3:()=>mC,mx_fractal_noise_vec4:()=>GU,mx_frame:()=>KU,mx_heighttonormal:()=>nI,mx_hsvtorgb:()=>lC,mx_ifequal:()=>eI,mx_ifgreater:()=>ZU,mx_ifgreatereq:()=>JU,mx_invert:()=>QU,mx_modulo:()=>qU,mx_multiply:()=>WU,mx_noise_float:()=>BU,mx_noise_vec3:()=>FU,mx_noise_vec4:()=>LU,mx_place2d:()=>rI,mx_power:()=>jU,mx_ramp4:()=>MU,mx_ramplr:()=>NU,mx_ramptb:()=>wU,mx_rgbtohsv:()=>uC,mx_rotate2d:()=>iI,mx_rotate3d:()=>sI,mx_safepower:()=>CU,mx_separate:()=>tI,mx_splitlr:()=>vU,mx_splittb:()=>AU,mx_srgb_texture_to_lin_rec709:()=>cC,mx_subtract:()=>$U,mx_timer:()=>YU,mx_transform_uv:()=>RU,mx_unifiednoise2d:()=>PU,mx_unifiednoise3d:()=>DU,mx_worley_noise_float:()=>UU,mx_worley_noise_vec2:()=>IU,mx_worley_noise_vec3:()=>fC,negate:()=>yp,negateOnBackSide:()=>Wi,neutralToneMapping:()=>q_,nodeArray:()=>_n,nodeImmutable:()=>q,nodeObject:()=>j,nodeObjectIntent:()=>Ku,nodeObjects:()=>Zu,nodeProxy:()=>te,nodeProxyConstructor:()=>Ju,nodeProxyIntent:()=>G,normalFlat:()=>Ov,normalGeometry:()=>jl,normalLocal:()=>pt,normalMap:()=>tf,normalView:()=>ye,normalViewGeometry:()=>_o,normalWorld:()=>ni,normalWorldGeometry:()=>vy,normalize:()=>_t,not:()=>wM,notEqual:()=>yM,numWorkgroups:()=>MD,objectDirection:()=>FB,objectGroup:()=>Ax,objectPosition:()=>PB,objectRadius:()=>IB,objectScale:()=>DB,objectViewPosition:()=>UB,objectWorldMatrix:()=>LB,oneMinus:()=>XM,or:()=>NM,orthographicDepthToViewZ:()=>Hb,oscSawtooth:()=>wP,oscSine:()=>TP,oscSquare:()=>SP,oscTriangle:()=>NP,output:()=>fo,outputStruct:()=>ZL,overloadingFn:()=>Xt,overrideNode:()=>RR,overrideNodes:()=>CR,packHalf2x16:()=>pP,packNormalToRGB:()=>Jp,packSnorm2x16:()=>dP,packUnorm2x16:()=>hP,parabola:()=>m_,parallaxDirection:()=>Zv,parallaxUV:()=>eF,parameter:()=>YL,pass:()=>cD,passTexture:()=>dD,pcurve:()=>uP,perspectiveDepthToViewZ:()=>Ql,pmremTexture:()=>$c,pointShadow:()=>xT,pointUV:()=>WP,pointWidth:()=>aB,positionGeometry:()=>Ua,positionLocal:()=>Le,positionPrevious:()=>Is,positionView:()=>$e,positionViewDirection:()=>De,positionWorld:()=>vr,positionWorldDirection:()=>Tc,posterize:()=>lD,pow:()=>lr,pow2:()=>Np,pow3:()=>iv,pow4:()=>wp,premultiplyAlpha:()=>mc,property:()=>wn,quadBroadcast:()=>f2,quadSwapDiagonal:()=>l2,quadSwapX:()=>o2,quadSwapY:()=>a2,radians:()=>OM,rand:()=>lv,range:()=>wD,rangeFogFactor:()=>Y_,reciprocal:()=>KM,reference:()=>ke,referenceBuffer:()=>Py,reflect:()=>ev,reflectVector:()=>Cy,reflectView:()=>kv,reflector:()=>LP,refract:()=>vp,refractVector:()=>Ey,refractView:()=>Vv,reinhardToneMapping:()=>z_,remap:()=>Zx,remapClamp:()=>Cv,renderGroup:()=>ee,renderOutput:()=>Pp,rendererReference:()=>Hx,replaceDefaultUV:()=>MP,retroreflective:()=>kl,rotate:()=>En,rotateUV:()=>vP,roughness:()=>Sr,round:()=>YM,rtt:()=>LR,sRGBTransferEOTF:()=>kx,sRGBTransferOETF:()=>Vx,sample:()=>GP,sampler:()=>AB,samplerComparison:()=>RB,saturate:()=>$l,saturation:()=>sD,screenCoordinate:()=>Ps,screenDPR:()=>hy,screenSize:()=>xo,screenUV:()=>pr,select:()=>St,setCurrentStack:()=>Ba,setName:()=>Dx,shaderStages:()=>Yu,shadow:()=>fT,shadowPositionWorld:()=>om,shapeCircle:()=>I2,sharedUniformGroup:()=>ac,sheen:()=>or,sheenRoughness:()=>ns,shiftLeft:()=>EM,shiftRight:()=>BM,shininess:()=>Il,sign:()=>Fx,sin:()=>Tt,sinc:()=>cP,sinh:()=>VM,skinning:()=>Bb,smoothstep:()=>Wt,smoothstepElement:()=>cv,specularColor:()=>Nr,specularColorBlended:()=>zi,specularF90:()=>fi,spherizeUV:()=>AP,split:()=>oB,spritesheetUV:()=>EP,sqrt:()=>Ct,stack:()=>Wc,step:()=>Cs,stepElement:()=>dv,storage:()=>as,storageBarrier:()=>BD,storageTexture:()=>UR,storageTexture3D:()=>qP,struct:()=>QL,sub:()=>Se,subBuild:()=>Es,subgroupAdd:()=>qD,subgroupAll:()=>i2,subgroupAnd:()=>ZD,subgroupAny:()=>s2,subgroupBallot:()=>HD,subgroupBroadcast:()=>u2,subgroupBroadcastFirst:()=>n2,subgroupElect:()=>WD,subgroupExclusiveAdd:()=>XD,subgroupExclusiveMul:()=>QD,subgroupInclusiveAdd:()=>jD,subgroupInclusiveMul:()=>KD,subgroupIndex:()=>bB,subgroupMax:()=>r2,subgroupMin:()=>t2,subgroupMul:()=>YD,subgroupOr:()=>JD,subgroupShuffle:()=>c2,subgroupShuffleDown:()=>p2,subgroupShuffleUp:()=>h2,subgroupShuffleXor:()=>d2,subgroupSize:()=>CD,subgroupXor:()=>e2,tan:()=>zM,tangentGeometry:()=>Mc,tangentLocal:()=>os,tangentView:()=>Yl,tangentWorld:()=>Oy,tanh:()=>$M,texture:()=>be,texture3D:()=>D_,texture3DLevel:()=>YP,texture3DLoad:()=>XP,textureBarrier:()=>FD,textureBicubic:()=>eL,textureBicubicLevel:()=>Nf,textureLevel:()=>vB,textureLoad:()=>at,textureSize:()=>Fs,textureStore:()=>HP,thickness:()=>ic,time:()=>wo,toneMapping:()=>Sv,toneMappingExposure:()=>Nv,toonOutlinePass:()=>pD,transformDirection:()=>sv,transformNormal:()=>Kp,transformNormalByInverseViewMatrix:()=>ov,transformNormalByViewMatrix:()=>nv,transformNormalToView:()=>Qp,transformedClearcoatNormalView:()=>jB,transformedNormalView:()=>HB,transformedNormalWorld:()=>qB,transmission:()=>Ol,transpose:()=>QM,triNoise3D:()=>yP,triplanarTexture:()=>BP,triplanarTextures:()=>FR,trunc:()=>Tp,uint:()=>k,uintBitsToFloat:()=>iP,uniform:()=>Y,uniformArray:()=>Et,uniformCubeTexture:()=>XB,uniformFlow:()=>hv,uniformGroup:()=>fM,uniformTexture:()=>MB,unpackHalf2x16:()=>gP,unpackNormal:()=>ef,unpackRGBToNormal:()=>Jv,unpackSnorm2x16:()=>fP,unpackUnorm2x16:()=>mP,unpremultiplyAlpha:()=>Jx,userData:()=>KP,uv:()=>Re,uvec2:()=>sp,uvec3:()=>Nn,uvec4:()=>lp,varying:()=>xi,varyingProperty:()=>tc,vec2:()=>V,vec3:()=>N,vec4:()=>X,vectorComponents:()=>ki,velocity:()=>QP,vertexColor:()=>Xb,vertexIndex:()=>ql,vertexStage:()=>bv,vibrance:()=>nD,viewZToLogarithmicDepth:()=>ka,viewZToOrthographicDepth:()=>ks,viewZToPerspectiveDepth:()=>cf,viewZToReversedOrthographicDepth:()=>TF,viewZToReversedPerspectiveDepth:()=>qb,viewport:()=>py,viewportCoordinate:()=>Lv,viewportDepthTexture:()=>Fc,viewportLinearDepth:()=>NF,viewportMipTexture:()=>uf,viewportOpaqueMipTexture:()=>zb,viewportSafeUV:()=>CP,viewportSharedTexture:()=>uD,viewportSize:()=>kp,viewportTexture:()=>bF,viewportUV:()=>CB,vogelDiskSample:()=>Ni,wgsl:()=>bD,wgslFn:()=>SD,workgroupArray:()=>LD,workgroupBarrier:()=>ED,workgroupId:()=>vD,workingToColorSpace:()=>_v,xor:()=>MM});var Df=class extends dc{static get type(){return"OverrideContextNode"}constructor(e,t=null){super(t,{overrideNodes:e}),this.isOverrideContextNode=!0}getFlowContextData(){let e=[];this.traverse(i=>{i.isOverrideContextNode===!0&&e.push(i.value.overrideNodes)});let t=new Map(e.flatMap(i=>Array.from(i.entries()))),r=super.getFlowContextData();return r.overrideNodes=t,r}};function RR(n,e=null,t=null){if(e&&e.isNode){let r=e;e=()=>r}return new Df(new Map([[n,e]]),t)}P("overrideNode",(n,e,t)=>RR(e,t,n));function CR(n,e=null){let t=new Map;for(let[r,i]of n){let s=i!==null?typeof i=="function"?i:()=>i:null;t.set(r,s)}return new Df(t,e)}P("overrideNodes",(n,e)=>CR(e,n));var Uf=class extends vx{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getMemberType(e,t){let r=this.getNodeType(e),i=e.getStructTypeNode(r),s;return i!==null?s=i.getMemberType(e,t):(I(`TSL: Member "${t}" not found in struct "${r}".`,new tt),s="float"),s}getHash(){return String(this.id)}generate(){return this.name}},s_=Uf,YL=(n,e)=>new Uf(n,e);var n_=class extends W{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._nodeDataLibrary=new Map,this.isStackNode=!0}getElementType(e){return this.outputNode?this.outputNode.getElementType(e):"void"}generateNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}getMemberType(e,t){return this.outputNode?this.outputNode.getMemberType(e,t):"void"}addToStack(e,t=-1){if(e.isNode!==!0)return I("TSL: Invalid node added to stack.",new tt),this;if(t===-1)if(this._currentNode){let r=this._nodeDataLibrary.get(this._currentNode);r===void 0&&(r={delta:0},this._nodeDataLibrary.set(this._currentNode,r)),r.delta++,t=this.nodes.indexOf(this._currentNode)+r.delta}else t=this.nodes.length;return this.nodes.splice(t,0,e),this}addToStackBefore(e){let t=this._currentNode?this.nodes.indexOf(this._currentNode):0;return this.addToStack(e,t)}If(e,t){let r=new Ea(t);return this._currentCond=St(e,r),this.addToStack(this._currentCond)}ElseIf(e,t){let r=new Ea(t),i=St(e,r);return this._currentCond.elseNode=i,this._currentCond=i,this}Else(e){return this._currentCond.elseNode=new Ea(e),this}Switch(e){return this._expressionNode=j(e),this}Case(...e){let t=[];if(e.length>=2)for(let a=0;a<e.length-1;a++)t.push(this._expressionNode.equal(j(e[a])));else I("TSL: Invalid parameter length. Case() requires at least two parameters.",new tt);let r=e[e.length-1],i=new Ea(r),s=t[0];for(let a=1;a<t.length;a++)s=s.or(t[a]);let o=St(s,i);return this._currentCond===null?(this._currentCond=o,this.addToStack(this._currentCond)):(this._currentCond.elseNode=o,this._currentCond=o,this)}Default(e){return this.Else(e),this}setup(e){let t=e.getNodeProperties(this),r=0;for(let i of this.getChildren())i.isVarNode&&i.isIntent(e)&&i.isAssign(e)!==!0||(t["node"+r++]=i);return t.outputNode||null}build(e,...t){let r=ec(),i=e.buildStage;Ba(this),e.setActiveStack(this);for(let o=0;o<this.nodes.length;o++){let a=this.nodes[o],l=this._currentNode;if(this._currentNode=a,!(a.isVarNode&&a.isIntent(e)&&a.isAssign(e)!==!0)){if(i==="setup")a.build(e);else if(i==="analyze")a.build(e,this);else if(i==="generate"){let u=e.getDataFromNode(a,"any").stages,c=u&&u[e.shaderStage];if(a.isVarNode&&c&&c.length===1&&c[0]&&c[0].isStackNode)continue;a.build(e,"void")}this._currentNode=l}}let s;if(this.outputNode){let o=this.outputNode.build(e,...t);(e.buildStage!=="generate"||this.outputNode.getNodeType(e)!=="void")&&(s=o)}else s=super.build(e,...t);return Ba(r),e.removeActiveStack(this),s}};var Wc=te(n_).setParameterLength(0,1);function KL(n){return Object.entries(n).map(([e,t])=>typeof t=="string"?{name:e,type:t,atomic:!1}:{name:e,type:t.type,atomic:t.atomic||!1})}var o_=class extends W{static get type(){return"StructTypeNode"}constructor(e,t=null){super("struct"),this.membersLayout=KL(e),this.name=t,this.isStructTypeNode=!0}getLength(){let e=1,t=0;for(let r of this.membersLayout){let i=r.type,s=Zw(i),o=Jw(i);e=Math.max(e,o);let l=t%e%o;l!==0&&(t+=o-l),t+=s}return Math.ceil(t/e)*e}getMemberType(e,t){let r=this.membersLayout.find(i=>i.name===t);return r?r.type:"void"}generateNodeType(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)}},a_=o_;var l_=class extends W{static get type(){return"StructNode"}constructor(e,t){super("vec3"),this.structTypeNode=e,this.values=t,this.isStructNode=!0}generateNodeType(e){return this.structTypeNode.getNodeType(e)}getMemberType(e,t){return this.structTypeNode.getMemberType(e,t)}_getChildren(){let e=super._getChildren(),t=e.find(r=>r.childNode===this.structTypeNode);return e.splice(e.indexOf(t),1),e.push(t),e}generate(e){let t=e.getVarFromNode(this),r=t.type,i=e.getPropertyName(t);return e.addLineFlowCode(`${i} = ${e.generateStruct(r,this.structTypeNode.membersLayout,this.values)}`,this),t.name}};var QL=(n,e=null)=>{let t=new a_(n,e);return Ju((...i)=>{let s=null;if(i.length>0)if(i[0].isNode){s={};let o=Object.keys(n);for(let a=0;a<i.length;a++)s[o[a]]=i[a]}else s=i[0];return new l_(t,s)},t)};var If=class extends W{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}generateNodeType(){return"OutputType"}generate(e){let t=e.getDataFromNode(this);if(t.membersLayout===void 0){let o=this.members,a=[];for(let l=0;l<o.length;l++){let u="m"+l,c=o[l].getNodeType(e);a.push({name:u,type:c,index:l})}t.membersLayout=a,t.structType=e.getOutputStructTypeFromNode(this,t.membersLayout)}let r=e.getOutputStructName(),i=this.members,s=r!==""?r+".":"";for(let o=0;o<i.length;o++){let a=i[o].build(e,t.membersLayout[o].type);e.addLineFlowCode(`${s}m${o} = ${a}`,this)}return r}},u_=If,ZL=te(If);var c_=class{constructor(e=Zt){this.blending=e,this.blendSrc=sn,this.blendDst=nn,this.blendEquation=Jt,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)}},d_=c_;var JL=new d_(Pr),eP=new d_(tl);function ER(n,e){for(let t=0;t<n.length;t++)if(n[t].name===e)return t;return-1}var h_=class extends u_{static get type(){return"MRTNode"}constructor(e){super(),this.outputNodes=e,this.blendModes={output:eP},this.isMRTNode=!0}setBlendMode(e,t){return this.blendModes[e]=t,this}getBlendMode(e){return this.blendModes[e]||JL}has(e){return this.outputNodes[e]!==void 0}get(e){return this.outputNodes[e]}merge(e){let t={...this.outputNodes,...e.outputNodes},r={...this.blendModes,...e.blendModes},i=BR(t);return i.blendings=r,i}setup(e){let t=this.outputNodes,r=e.renderer.getRenderTarget(),i=[],s=r.textures;for(let o in t){let a=ER(s,o);if(a===-1)continue;let l=e.getOutputType(a);i[a]=t[o].convert(l)}return this.members=i,super.setup(e)}};var BR=te(h_);var za=class extends _e{static get type(){return"BitcastNode"}constructor(e,t,r=null){super(),this.valueNode=e,this.conversionType=t,this.inputType=r,this.isBitcastNode=!0}generateNodeType(e){if(this.inputType!==null){let t=this.valueNode.getNodeType(e),r=e.getTypeLength(t);return e.getTypeFromLength(r,this.conversionType)}return this.conversionType}generate(e){let t=this.getNodeType(e),r="";if(this.inputType!==null){let i=this.valueNode.getNodeType(e);r=e.getTypeLength(i)===1?this.inputType:e.changeComponentType(i,this.inputType)}else r=this.valueNode.getNodeType(e);return`${e.getBitcastMethod(t,r)}( ${this.valueNode.build(e,r)} )`}};var p_=G(za).setParameterLength(2),tP=n=>new za(n,"int","float"),f_=n=>new za(n,"uint","float"),rP=n=>new za(n,"float","int"),iP=n=>new za(n,"float","uint");var Of={},cs=class n extends Ex{static get type(){return"BitcountNode"}constructor(e,t){super(e,t),this.isBitcountNode=!0}_resolveElementType(e,t,r){r==="int"?t.assign(p_(e,"uint")):t.assign(e)}_returnDataNode(e){switch(e){case"uint":return k;case"int":return A;case"uvec2":return sp;case"uvec3":return Nn;case"uvec4":return lp;case"ivec2":return dt;case"ivec3":return np;case"ivec4":return ap}}_createTrailingZerosBaseLayout(e,t){let r=this._returnDataNode(t);return _(([s])=>{let o=k(0);this._resolveElementType(s,o,t);let a=y(o.bitAnd(yp(o))),u=f_(a).shiftRight(23).sub(127);return r(u)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createLeadingZerosBaseLayout(e,t){let r=this._returnDataNode(t);return _(([s])=>{ie(s.equal(k(0)),()=>k(32));let o=k(0),a=k(0);return this._resolveElementType(s,o,t),ie(o.shiftRight(16).equal(0),()=>{a.addAssign(16),o.shiftLeftAssign(16)}),ie(o.shiftRight(24).equal(0),()=>{a.addAssign(8),o.shiftLeftAssign(8)}),ie(o.shiftRight(28).equal(0),()=>{a.addAssign(4),o.shiftLeftAssign(4)}),ie(o.shiftRight(30).equal(0),()=>{a.addAssign(2),o.shiftLeftAssign(2)}),ie(o.shiftRight(31).equal(0),()=>{a.addAssign(1)}),r(a)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createOneBitsBaseLayout(e,t){let r=this._returnDataNode(t);return _(([s])=>{let o=k(0);this._resolveElementType(s,o,t),o.assign(o.sub(o.shiftRight(k(1)).bitAnd(k(1431655765)))),o.assign(o.bitAnd(k(858993459)).add(o.shiftRight(k(2)).bitAnd(k(858993459))));let a=o.add(o.shiftRight(k(4))).bitAnd(k(252645135)).mul(k(16843009)).shiftRight(k(24));return r(a)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createMainLayout(e,t,r,i){let s=this._returnDataNode(t);return _(([a])=>{if(r===1)return s(i(a));{let l=s(0),u=["x","y","z","w"];for(let c=0;c<r;c++){let d=u[c];l[d].assign(i(a[d]))}return l}}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}setup(e){let{method:t,aNode:r}=this,{renderer:i}=e;if(i.backend.isWebGPUBackend)return super.setup(e);let s=this.getInputType(e),o=e.getElementType(s),a=e.getTypeLength(s),l=`${t}_base_${o}`,u=`${t}_${s}`,c=Of[l];if(c===void 0){switch(t){case n.COUNT_LEADING_ZEROS:{c=this._createLeadingZerosBaseLayout(l,o);break}case n.COUNT_TRAILING_ZEROS:{c=this._createTrailingZerosBaseLayout(l,o);break}case n.COUNT_ONE_BITS:{c=this._createOneBitsBaseLayout(l,o);break}}Of[l]=c}let d=Of[u];return d===void 0&&(d=this._createMainLayout(u,s,a,c),Of[u]=d),_(()=>d(r))()}};cs.COUNT_TRAILING_ZEROS="countTrailingZeros";cs.COUNT_LEADING_ZEROS="countLeadingZeros";cs.COUNT_ONE_BITS="countOneBits";var sP=G(cs,cs.COUNT_TRAILING_ZEROS).setParameterLength(1),nP=G(cs,cs.COUNT_LEADING_ZEROS).setParameterLength(1),oP=G(cs,cs.COUNT_ONE_BITS).setParameterLength(1);var aP=_(([n])=>{let e=n.toUint().mul(747796405).add(2891336453),t=e.shiftRight(e.shiftRight(28).add(4)).bitXor(e).mul(277803737);return t.shiftRight(22).bitXor(t).toFloat().mul(1/2**32)});var m_=(n,e)=>lr(ce(4,n.mul(Se(1,n))),e),lP=(n,e)=>n.lessThan(.5)?m_(n.mul(2),e).div(2):Se(1,m_(ce(Se(1,n),2),e).div(2)),uP=(n,e,t)=>lr(xt(lr(n,e),Xe(lr(n,e),lr(Se(1,n),t))),1/e),cP=(n,e)=>Tt(cc.mul(e.mul(n).sub(1))).div(cc.mul(e.mul(n).sub(1)));var Hc=class extends _e{static get type(){return"PackFloatNode"}constructor(e,t){super(),this.vectorNode=t,this.encoding=e,this.isPackFloatNode=!0}generateNodeType(){return"uint"}generate(e){let t=this.vectorNode.getNodeType(e);return`${e.getFloatPackingMethod(this.encoding)}(${this.vectorNode.build(e,t)})`}};var dP=G(Hc,"snorm").setParameterLength(1),hP=G(Hc,"unorm").setParameterLength(1),pP=G(Hc,"float16").setParameterLength(1);var qc=class extends _e{static get type(){return"UnpackFloatNode"}constructor(e,t){super(),this.uintNode=t,this.encoding=e,this.isUnpackFloatNode=!0}generateNodeType(){return"vec2"}generate(e){let t=this.uintNode.getNodeType(e);return`${e.getFloatUnpackingMethod(this.encoding)}(${this.uintNode.build(e,t)})`}};var fP=G(qc,"snorm").setParameterLength(1),mP=G(qc,"unorm").setParameterLength(1),gP=G(qc,"float16").setParameterLength(1);var Bn=_(([n])=>n.fract().sub(.5).abs()).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),xP=_(([n])=>N(Bn(n.z.add(Bn(n.y.mul(1)))),Bn(n.z.add(Bn(n.x.mul(1)))),Bn(n.y.add(Bn(n.x.mul(1)))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),yP=_(([n,e,t])=>{let r=N(n).toVar(),i=y(1.4).toVar(),s=y(0).toVar(),o=N(r).toVar();return Ee({start:y(0),end:y(3),type:"float",condition:"<="},()=>{let a=N(xP(o.mul(2))).toVar();r.addAssign(a.add(t.mul(y(.1).mul(e)))),o.mulAssign(1.8),i.mulAssign(1.5),r.mulAssign(1.2);let l=y(Bn(r.z.add(Bn(r.x.add(Bn(r.y)))))).toVar();s.addAssign(l.div(i)),o.addAssign(.14)}),s}).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"position",type:"vec3"},{name:"speed",type:"float"},{name:"time",type:"float"}]});var g_=class extends W{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFn=null,this.global=!0}generateNodeType(e){return this.getCandidateFn(e).shaderNode.layout.type}getCandidateFn(e){let t=this.parametersNodes,r=this._candidateFn;if(r===null){let i=null,s=-1;for(let o of this.functionNodes){let l=o.shaderNode.layout;if(l===null)throw new Error("THREE.FunctionOverloadingNode: FunctionNode must be a layout.");let u=l.inputs;if(t.length===u.length){let c=0;for(let d=0;d<t.length;d++){let h=t[d],p=u[d];h.getNodeType(e)===p.type&&c++}c>s&&(i=o,s=c)}}this._candidateFn=r=i}return r}setup(e){return this.getCandidateFn(e)(...this.parametersNodes)}};var bP=te(g_),Xt=n=>(...e)=>bP(n,...e);var wo=Y(0).setGroup(ee).onRenderUpdate(n=>n.time),_P=Y(0).setGroup(ee).onRenderUpdate(n=>n.deltaTime),x_=Y(0,"uint").setGroup(ee).onRenderUpdate(n=>n.frameId);var TP=(n=wo)=>n.add(.75).mul(Math.PI*2).sin().mul(.5).add(.5),SP=(n=wo)=>n.fract().round(),NP=(n=wo)=>n.add(.5).fract().mul(2).sub(1).abs(),wP=(n=wo)=>n.fract();function MP(n,e=null){return wr(e,{getUV:typeof n=="function"?n:()=>n})}var vP=_(([n,e,t=V(.5)])=>En(n.sub(t),e).add(t)),AP=_(([n,e,t=V(.5)])=>{let r=n.sub(t),i=r.dot(r),o=i.mul(i).mul(e);return n.add(r.mul(o))});var RP=_(({position:n=null,horizontal:e=!0,vertical:t=!1})=>{let r;n!==null?(r=fr.toVar(),r[3][0]=n.x,r[3][1]=n.y,r[3][2]=n.z):r=fr;let i=yi.mul(r);return Sn(e)&&(i[0][0]=fr[0].length(),i[0][1]=0,i[0][2]=0),Sn(t)&&(i[1][0]=0,i[1][1]=fr[1].length(),i[1][2]=0),i[2][0]=0,i[2][1]=0,i[2][2]=1,zr.mul(i).mul(Le)});var CP=_(([n=null])=>{let e=Lc();return Lc(Fc(n)).sub(e).lessThan(0).select(pr,n)});var EP=_(([n,e=Re(),t=y(0)])=>{let r=n.x,i=n.y,s=t.mod(r.mul(i)).floor(),o=s.mod(r),a=i.sub(s.add(1).div(r).ceil()),l=n.reciprocal(),u=V(o,a);return e.add(u).mul(l)});var FR=_(([n,e=null,t=null,r=y(1),i=Le,s=pt])=>{let o=s.abs().normalize();o=o.div(o.dot(N(1)));let a=i.yz.mul(r),l=i.zx.mul(r),u=i.xy.mul(r),c=n.value,d=e!==null?e.value:c,h=t!==null?t.value:c,p=be(c,a).mul(o.x),f=be(d,l).mul(o.y),m=be(h,u).mul(o.z);return Xe(p,f,m)}),BP=(...n)=>FR(...n);var su=new pi,$a=new C,nu=new C,y_=new C,jc=new ue,kf=new C(0,0,-1),Ws=new pe,Xc=new C,Vf=new C,Yc=new pe,Gf=new se,$f=new ct,FP=pr.flipX();$f.depthTexture=new ot(1,1);var zf=!1,b_=class n extends jt{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||$f.texture,FP),this._reflectorBaseNode=e.reflector||new __(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(this._depthNode===null){if(this._reflectorBaseNode.depth!==!0)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=new n({defaultTexture:$f.depthTexture,reflector:this._reflectorBaseNode})}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){let 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.gatherNode=this.gatherNode,e.offsetNode=this.offsetNode,e._reflectorBaseNode=this._reflectorBaseNode,e}dispose(){super.dispose(),this._reflectorBaseNode.dispose()}},__=class extends W{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();let{target:r=new Ke,resolutionScale:i=1,generateMipmaps:s=!1,bounces:o=!0,depth:a=!1,samples:l=0}=t;this.textureNode=e,this.target=r,this.resolutionScale=i,t.resolution!==void 0&&(he('ReflectorNode: The "resolution" parameter has been renamed to "resolutionScale".'),this.resolutionScale=t.resolution),this.generateMipmaps=s,this.bounces=o,this.depth=a,this.samples=l,this.updateBeforeType=o?J.RENDER:J.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new Map,this.forceUpdate=!1,this.hasOutput=!1}_updateResolution(e,t){let r=this.resolutionScale;t.getDrawingBufferSize(Gf),e.setSize(Math.round(Gf.width*r),Math.round(Gf.height*r))}setup(e){return this._updateResolution($f,e.renderer),super.setup(e)}dispose(){super.dispose();for(let e of this.renderTargets.values())e.dispose()}getVirtualCamera(e){let t=this.virtualCameras.get(e);return t===void 0&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return t===void 0&&(t=new ct(0,0,{type:qe,samples:this.samples}),this.generateMipmaps===!0&&(t.texture.minFilter=ow,t.texture.generateMipmaps=!0),this.depth===!0&&(t.depthTexture=new ot),this.renderTargets.set(e,t)),t}updateBefore(e){if(this.bounces===!1&&zf)return!1;zf=!0;let{scene:t,camera:r,renderer:i,material:s}=e,{target:o}=this,a=this.getVirtualCamera(r),l=this.getRenderTarget(a);i.getDrawingBufferSize(Gf),this._updateResolution(l,i),nu.setFromMatrixPosition(o.matrixWorld),y_.setFromMatrixPosition(r.matrixWorld),jc.extractRotation(o.matrixWorld),$a.set(0,0,1),$a.applyMatrix4(jc),Xc.subVectors(nu,y_);let u=Xc.dot($a)>0,c=!1;if(u===!0&&this.forceUpdate===!1){if(this.hasOutput===!1){zf=!1;return}c=!0}Xc.reflect($a).negate(),Xc.add(nu),jc.extractRotation(r.matrixWorld),kf.set(0,0,-1),kf.applyMatrix4(jc),kf.add(y_),Vf.subVectors(nu,kf),Vf.reflect($a).negate(),Vf.add(nu),a.coordinateSystem=r.coordinateSystem,a.position.copy(Xc),a.up.set(0,1,0),a.up.applyMatrix4(jc),a.up.reflect($a),a.lookAt(Vf),a.near=r.near,a.far=r.far,a.updateMatrixWorld(),a.projectionMatrix.copy(r.projectionMatrix),su.setFromNormalAndCoplanarPoint($a,nu),su.applyMatrix4(a.matrixWorldInverse),Ws.set(su.normal.x,su.normal.y,su.normal.z,su.constant);let d=a.projectionMatrix;Yc.x=(Math.sign(Ws.x)+d.elements[8])/d.elements[0],Yc.y=(Math.sign(Ws.y)+d.elements[9])/d.elements[5],Yc.z=-1,Yc.w=(1+d.elements[10])/d.elements[14],Ws.multiplyScalar(1/Ws.dot(Yc));let h=0;d.elements[2]=Ws.x,d.elements[6]=Ws.y,d.elements[10]=i.coordinateSystem===yt?Ws.z-h:Ws.z+1-h,d.elements[14]=Ws.w,this.textureNode.value=l.texture,this.depth===!0&&(this.textureNode.getDepthNode().value=l.depthTexture),s.visible=!1;let p=i.getRenderTarget(),f=i.getMRT(),m=i.autoClear;i.setMRT(null),i.setRenderTarget(l),i.autoClear=!0;let g=t.name;t.name=(t.name||"Scene")+" [ Reflector ]",c?(i.clear(),this.hasOutput=!1):(i.render(t,a),this.hasOutput=!0),t.name=g,i.setMRT(f),i.setRenderTarget(p),i.autoClear=m,s.visible=!0,zf=!1,this.forceUpdate=!1}get resolution(){return he('ReflectorNode: The "resolution" property has been renamed to "resolutionScale".'),this.resolutionScale}set resolution(e){he('ReflectorNode: The "resolution" property has been renamed to "resolutionScale".'),this.resolutionScale=e}},LP=n=>new b_(n);var T_=new Ss(-1,1,1,-1,0,1),S_=class extends ir{constructor(e=!1){super();let t=e===!1?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new ft([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new ft(t,2))}},PP=new S_,DP=X(lc([-1,-1,3]).element(ql),lc([3,-1,-1]).element(ql),0,1),N_=class extends sr{constructor(e){super(PP,e),this.camera=T_,this.isQuadMesh=!0}async renderAsync(e){he('QuadMesh: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await e.init(),e.render(this,T_)}render(e){let t=this.material.vertexNode;this.material.vertexNode=DP,e.render(this,T_),this.material.vertexNode=t}},ou=N_;var UP=new se,w_=class extends jt{static get type(){return"RTTNode"}constructor(e,t=null,r=null,i={type:qe}){let s=new ct(t,r,i);super(s.texture,Re()),this.isRTTNode=!0,this.node=e,this.width=t,this.height=r,this.renderTarget=s,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this._resolutionScale=1,this._quadMesh=new ou(new we),this.updateBeforeType=J.RENDER}get autoResize(){return this.width===null}setup(e){return this._quadMesh.material.contextNode=wr(e.getSharedContext()),this._quadMesh.material.fragmentNode=this.node,this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){let r=Math.floor(e*this._resolutionScale),i=Math.floor(t*this._resolutionScale);this.renderTarget.setSize(r,i),this.textureNeedsUpdate=!0}setResolutionScale(e){return this._resolutionScale=e,this.autoResize===!1&&this.setSize(this.width,this.height),this}getResolutionScale(){return this._resolutionScale}updateBefore({renderer:e}){if(this.textureNeedsUpdate===!1&&this.autoUpdate===!1)return;this.textureNeedsUpdate=!1;let t=e.getRenderTarget();if(this.autoResize===!0){let i=e.getDrawingBufferSize(UP),s=Math.floor(i.width*this._resolutionScale),o=Math.floor(i.height*this._resolutionScale);(s!==this.renderTarget.width||o!==this.renderTarget.height)&&(this.renderTarget.setSize(s,o),this.textureNeedsUpdate=!0)}let r="RTT";this.node.name&&(r=this.node.name+" [ "+r+" ]"),this._quadMesh.name=r,e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){let e=new jt(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}};var LR=(n,...e)=>new w_(j(n),...e),IP=(n,...e)=>n.isSampleNode||n.isTextureNode?n:n.isPassNode?n.getTextureNode():LR(n,...e);var au=_(([n,e,t],r)=>{let i;r.renderer.coordinateSystem===yt?(n=V(n.x,n.y.oneMinus()).mul(2).sub(1),i=X(N(n,e),1)):i=X(N(n.x,n.y.oneMinus(),e).mul(2).sub(1),1);let s=X(t.mul(i));return s.xyz.div(s.w)}),OP=_(([n,e])=>{let t=e.mul(X(n,1)),r=t.xy.div(t.w).mul(.5).add(.5).toVar();return V(r.x,r.y.oneMinus())}),kP=_(([n])=>{let e=n.xy.div(n.w).mul(.5).add(.5).toVar();return V(e.x,e.y.oneMinus())}).setLayout({name:"getScreenPositionFromClip",type:"vec2",inputs:[{name:"clipPosition",type:"vec4"}]}),VP=_(([n,e,t])=>{let r=Fs(at(e)),i=dt(n.mul(r)).toVar(),s=at(e,i).toVar(),o=at(e,i.sub(dt(2,0))).toVar(),a=at(e,i.sub(dt(1,0))).toVar(),l=at(e,i.add(dt(1,0))).toVar(),u=at(e,i.add(dt(2,0))).toVar(),c=at(e,i.add(dt(0,2))).toVar(),d=at(e,i.add(dt(0,1))).toVar(),h=at(e,i.sub(dt(0,1))).toVar(),p=at(e,i.sub(dt(0,2))).toVar(),f=Ue(Se(y(2).mul(a).sub(o),s)).toVar(),m=Ue(Se(y(2).mul(l).sub(u),s)).toVar(),g=Ue(Se(y(2).mul(d).sub(c),s)).toVar(),x=Ue(Se(y(2).mul(h).sub(p),s)).toVar(),w=au(n,s,t).toVar(),v=f.lessThan(m).select(w.sub(au(n.sub(V(y(1).div(r.x),0)),a,t)),w.negate().add(au(n.add(V(y(1).div(r.x),0)),l,t))),E=g.lessThan(x).select(w.sub(au(n.add(V(0,y(1).div(r.y))),d,t)),w.negate().add(au(n.sub(V(0,y(1).div(r.y))),h,t)));return _t(gi(v,E))}),Kc=_(([n])=>ii(y(52.9829189).mul(ii(ar(n,V(.06711056,.00583715)))))).setLayout({name:"interleavedGradientNoise",type:"float",inputs:[{name:"position",type:"vec2"}]}),Ni=_(([n,e,t])=>{let r=y(2.399963229728653),i=Ct(y(n).add(.5).div(y(e))),s=y(n).mul(r).add(t);return V(Gr(s),Tt(s)).mul(i)}).setLayout({name:"vogelDiskSample",type:"vec2",inputs:[{name:"sampleIndex",type:"int"},{name:"samplesCount",type:"int"},{name:"phi",type:"float"}]});var M_=class extends W{static get type(){return"SampleNode"}constructor(e,t=null){super(),this.callback=e,this.uvNode=t,this.isSampleNode=!0}setup(){return this.sample(Re())}sample(e){return this.callback(e)}};var GP=(n,e=null)=>new M_(n,j(e));var v_=class extends Ui{constructor(e,t,r=Float32Array){let i=ArrayBuffer.isView(e)?e:new r(e*t);super(i,t),this.isStorageInstancedBufferAttribute=!0}},PR=v_;var A_=class extends $t{constructor(e,t,r=Float32Array){let i=ArrayBuffer.isView(e)?e:new r(e*t);super(i,t),this.isStorageBufferAttribute=!0}},DR=A_;var zP=(n,e="float")=>{let t,r;e.isStructTypeNode===!0?(t=e.getLength(),r=ju("float")):(t=rx(e),r=ju(e));let i=new DR(n,t,r);return as(i,e,n)},$P=(n,e="float")=>{let t,r;e.isStructTypeNode===!0?(t=e.getLength(),r=ju("float")):(t=rx(e),r=ju(e));let i=new PR(n,t,r);return as(i,e,i.count)};var R_=class extends W{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}};var WP=q(R_);var C_=new ue,E_=Y(0).setGroup(ee).onRenderUpdate(({scene:n})=>n.backgroundBlurriness),Wf=Y(1).setGroup(ee).onRenderUpdate(({scene:n})=>n.backgroundIntensity),B_=Y(new ue).setGroup(ee).onRenderUpdate(({scene:n})=>{let e=n.background;return e!==null&&e.isTexture&&e.mapping!==Cu||n.backgroundNode&&n.backgroundNode.isNode?C_.makeRotationFromEuler(n.backgroundRotation).transpose():C_.identity(),C_});var Hf=class extends jt{static get type(){return"StorageTextureNode"}constructor(e,t,r=null){super(e,t),this.storeNode=r,this.mipLevel=0,this.isStorageTextureNode=!0,this.access=mt.WRITE_ONLY}getInputType(){return"storageTexture"}getTransformedUV(e){return e}setup(e){super.setup(e);let 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){return this.storeNode!==null?(this.generateStore(e),""):super.generate(e,t)}generateSnippet(e,t,r,i,s,o,a,l,u){let c=this.value;return e.generateStorageTextureLoad(c,t,r,i,o,u)}toReadWrite(){return this.setAccess(mt.READ_WRITE)}toReadOnly(){return this.setAccess(mt.READ_ONLY)}toWriteOnly(){return this.setAccess(mt.WRITE_ONLY)}store(e,t){let r=this.clone();return r.referenceNode=this.getBase(),r.uvNode=e,r.storeNode=t,t!==null&&r.toStack(),r}generateStore(e){let t=e.getNodeProperties(this),{uvNode:r,storeNode:i,depthNode:s}=t,o=super.generate(e,"property"),a=r.build(e,this.value.is3DTexture===!0?"uvec3":"uvec2"),l=i.build(e,"vec4"),u=s?s.build(e,"int"):null,c=e.generateTextureStore(this.value,o,a,u,l);e.addLineFlowCode(c,this)}clone(){let e=super.clone();return e.storeNode=this.storeNode,e.mipLevel=this.mipLevel,e.access=this.access,e}},F_=Hf,UR=te(Hf).setParameterLength(1,3),HP=(n,e,t)=>{let r;return n.isStorageTextureNode===!0?r=n.store(e,t):(r=UR(n,e,t),t!==null&&r.toStack()),r};var L_=class extends F_{static get type(){return"StorageTexture3DNode"}constructor(e,t,r=null){super(e,t,r),this.isStorageTexture3DNode=!0}getDefaultUV(){return N(.5,.5,.5)}setUpdateMatrix(){}generateUV(e,t){return t.build(e,this.sampler===!0?"vec3":"ivec3")}generateOffset(e,t){return t.build(e,"ivec3")}};var qP=te(L_).setParameterLength(1,3);var jP=_(({texture:n,uv:e})=>{let r=N().toVar();return ie(e.x.lessThan(1e-4),()=>{r.assign(N(1,0,0))}).ElseIf(e.y.lessThan(1e-4),()=>{r.assign(N(0,1,0))}).ElseIf(e.z.lessThan(1e-4),()=>{r.assign(N(0,0,1))}).ElseIf(e.x.greaterThan(1-1e-4),()=>{r.assign(N(-1,0,0))}).ElseIf(e.y.greaterThan(1-1e-4),()=>{r.assign(N(0,-1,0))}).ElseIf(e.z.greaterThan(1-1e-4),()=>{r.assign(N(0,0,-1))}).Else(()=>{let s=n.sample(e.add(N(-.01,0,0))).r.sub(n.sample(e.add(N(.01,0,0))).r),o=n.sample(e.add(N(0,-.01,0))).r.sub(n.sample(e.add(N(0,.01,0))).r),a=n.sample(e.add(N(0,0,-.01))).r.sub(n.sample(e.add(N(0,0,.01))).r);r.assign(N(s,o,a))}),r.normalize()}),P_=class extends jt{static get type(){return"Texture3DNode"}constructor(e,t=null,r=null){super(e,t,r),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return N(.5,.5,.5)}setUpdateMatrix(){}generateUV(e,t){return t.build(e,this.sampler===!0?"vec3":"ivec3")}generateOffset(e,t){return t.build(e,"ivec3")}normal(e){return jP({texture:this,uv:e})}};var D_=te(P_).setParameterLength(1,3),XP=(...n)=>D_(...n).setSampler(!1),YP=(n,e,t)=>D_(n,e).level(t);var U_=class extends wc{static get type(){return"UserDataNode"}constructor(e,t,r=null){super(e,t,r),this.userData=r}updateReference(e){return this.reference=this.userData!==null?this.userData:e.object.userData,this.reference}};var KP=(n,e,t)=>new U_(n,e,t);var IR=new WeakMap,I_=class extends _e{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=J.OBJECT,this.updateAfterType=J.OBJECT,this.previousModelWorldMatrix=Y(new ue),this.previousProjectionMatrix=Y(new ue).setGroup(ee),this.previousCameraViewMatrix=Y(new ue)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:r}){let i=OR(r);this.previousModelWorldMatrix.value.copy(i);let s=kR(t);s.frameId!==e&&(s.frameId=e,s.previousProjectionMatrix===void 0?(s.previousProjectionMatrix=new ue,s.previousCameraViewMatrix=new ue,s.currentProjectionMatrix=new ue,s.currentCameraViewMatrix=new ue,s.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),s.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(s.previousProjectionMatrix.copy(s.currentProjectionMatrix),s.previousCameraViewMatrix.copy(s.currentCameraViewMatrix)),s.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),s.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(s.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(s.previousCameraViewMatrix))}updateAfter({object:e}){OR(e).copy(e.matrixWorld)}setup(){let e=this.projectionMatrix===null?zr:Y(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),r=e.mul($r).mul(Le),i=this.previousProjectionMatrix.mul(t).mul(Is),s=r.xy.div(r.w),o=i.xy.div(i.w);return Se(s,o)}};function kR(n){let e=IR.get(n);return e===void 0&&(e={},IR.set(n,e)),e}function OR(n,e=0){let t=kR(n),r=t[e];return r===void 0&&(t[e]=r=new ue,t[e].copy(n.matrixWorld)),r}var QP=q(I_);var ZP=_(([n,e])=>ht(1,n.oneMinus().div(e)).oneMinus()).setLayout({name:"blendBurn",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),JP=_(([n,e])=>ht(n.div(e.oneMinus()),1)).setLayout({name:"blendDodge",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),eD=_(([n,e])=>n.oneMinus().mul(e.oneMinus()).oneMinus()).setLayout({name:"blendScreen",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),tD=_(([n,e])=>xe(n.mul(2).mul(e),n.oneMinus().mul(2).mul(e.oneMinus()).oneMinus(),Cs(.5,n))).setLayout({name:"blendOverlay",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),rD=_(([n,e])=>{let t=e.a.add(n.a.mul(e.a.oneMinus()));return X(e.rgb.mul(e.a).add(n.rgb.mul(n.a).mul(e.a.oneMinus())).div(t),t)}).setLayout({name:"blendColor",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]});var iD=_(([n])=>O_(n.rgb)),sD=_(([n,e=y(1)])=>e.mix(O_(n.rgb),n.rgb).max(0)),nD=_(([n,e=y(0)])=>{let t=Xe(n.r,n.g,n.b).div(3),r=n.r.max(n.g.max(n.b)),i=r.sub(t).mul(e).mul(-3);return xe(n.rgb,r,i).max(0)}),oD=_(([n,e=y(1)])=>{let t=N(.57735,.57735,.57735),r=e.cos();return N(n.rgb.mul(r).add(t.cross(n.rgb).mul(e.sin()).add(t.mul(ar(t,n.rgb).mul(r.oneMinus()))))).max(0)}),O_=(n,e=N(Me.getLuminanceCoefficients(new C)))=>ar(n,e),aD=_(([n,e=N(1),t=N(0),r=N(1),i=y(1),s=N(Me.getLuminanceCoefficients(new C,xa))])=>{let o=n.rgb.dot(N(s)),a=Ie(n.rgb.mul(e).add(t),0),l=a.pow(r);return ie(a.r.greaterThan(0),()=>{a.r.assign(l.r)}),ie(a.g.greaterThan(0),()=>{a.g.assign(l.g)}),ie(a.b.greaterThan(0),()=>{a.b.assign(l.b)}),a.assign(o.add(a.sub(o).mul(i)).max(0)),X(a.rgb,n.a)}),lD=_(([n,e])=>n.mul(e).floor().div(e));var qf=null,k_=class extends Bc{static get type(){return"ViewportSharedTextureNode"}constructor(e=pr,t=null){qf===null&&(qf=new lo),super(e,t,qf)}getTextureForReference(){return qf}updateReference(){return this}};var uD=te(k_).setParameterLength(0,2);var jf=new se,Xf=class extends jt{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.isPassTextureNode=!0,this.setUpdateMatrix(!1)}setup(e){let t=e.getNodeProperties(this);return t.passNode=this.passNode,super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}},Yf=class extends Xf{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(){let 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.gatherNode=this.gatherNode,e.offsetNode=this.offsetNode,e}},Fn=class n extends _e{static get type(){return"PassNode"}constructor(e,t,r,i={}){super("vec4"),this.scope=e,this.scene=t,this.camera=r,this.options=i,this._width=1,this._height=1;let s=new ct(this._width,this._height,{type:qe,...i});s.texture.name="output";let o=null;(this.scope===n.DEPTH||i.depthBuffer!==!1)&&(o=i.depthTexture||new ot,o.isRenderTargetTexture=!0,o.name="depth",s.depthTexture=o),this.renderTarget=s,this.overrideMaterial=null,this.transparent=!0,this.opaque=!0,this.lighting=null,this.autoClear=i.autoClear!==void 0?i.autoClear:!0,this.autoClearColor=i.autoClearColor!==void 0?i.autoClearColor:!0,this.autoClearDepth=i.autoClearDepth!==void 0?i.autoClearDepth:!0,this.autoClearStencil=i.autoClearStencil!==void 0?i.autoClearStencil:!0,this.contextNode=null,this._contextNodeCache=null,this._textures={output:s.texture},o!==null&&(this._textures.depth=o),this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=Y(0),this._cameraFar=Y(0),this._mrt=null,this._layers=null,this._resolutionScale=1,this._viewport=null,this._scissor=null,this.isPassNode=!0,this.updateBeforeType=J.FRAME,this.global=!0}setResolutionScale(e){return this._resolutionScale=e,this}getResolutionScale(){return this._resolutionScale}setResolution(e){return U("PassNode: .setResolution() is deprecated. Use .setResolutionScale() instead."),this.setResolutionScale(e)}getResolution(){return U("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(t===void 0){if(e==="depth")throw new Error("THREE.PassNode: Depth texture is not available for this pass.");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 t===void 0&&(t=this.getTexture(e).clone(),this._previousTextures[e]=t),t}toggleTexture(e){let t=this._previousTextures[e];if(t!==void 0){let r=this._textures[e],i=this.renderTarget.textures.indexOf(r);this.renderTarget.textures[i]=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 t===void 0&&(t=new Yf(this,e),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return t===void 0&&(this._textureNodes[e]===void 0&&this.getTextureNode(e),t=new Yf(this,e,!0),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(t===void 0){let r=this._cameraNear,i=this._cameraFar;this._viewZNodes[e]=t=Ql(this.getTextureNode(e),r,i)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(t===void 0){let r=this._cameraNear,i=this._cameraFar,s=this.getViewZNode(e);this._linearDepthNodes[e]=t=ks(s,r,i)}return t}async compileAsync(e){let 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=this.options.samples===void 0?e.samples:this.options.samples,this.renderTarget.texture.type=e.getOutputBufferType(),e.reversedDepthBuffer===!0&&this.renderTarget.depthTexture!==null&&(this.renderTarget.depthTexture.type=ze),this.scope===n.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){let{renderer:t}=e,{scene:r}=this,i,s=t.getOutputRenderTarget();s&&s.isXRRenderTarget===!0?(i=t.xr.getCamera(),t.xr.updateCamera(i),jf.set(s.width,s.height)):(i=this.camera,t.getDrawingBufferSize(jf)),this.setSize(jf.width,jf.height);let o=t.getRenderTarget(),a=t.getMRT(),l=t.autoClear,u=t.autoClearColor,c=t.autoClearDepth,d=t.autoClearStencil,h=t.transparent,p=t.opaque,f=t.lighting,m=i.layers.mask,g=t.contextNode,x=r.overrideMaterial;this._cameraNear.value=i.near,this._cameraFar.value=i.far,this._layers!==null&&(i.layers.mask=this._layers.mask);for(let v in this._previousTextures)this.toggleTexture(v);this.overrideMaterial!==null&&(r.overrideMaterial=this.overrideMaterial),t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.autoClear=this.autoClear,t.autoClearColor=this.autoClearColor,t.autoClearDepth=this.autoClearDepth,t.autoClearStencil=this.autoClearStencil,t.transparent=this.transparent,t.opaque=this.opaque,this.lighting!==null&&(t.lighting=this.lighting),this.contextNode!==null&&((this._contextNodeCache===null||this._contextNodeCache.version!==this.version)&&(this._contextNodeCache={version:this.version,context:wr({...t.contextNode.getFlowContextData(),...this.contextNode.getFlowContextData()})}),t.contextNode=this._contextNodeCache.context);let w=r.name;r.name=this.name?this.name:r.name,t.render(r,i),r.name=w,r.overrideMaterial=x,t.setRenderTarget(o),t.setMRT(a),t.autoClear=l,t.autoClearColor=u,t.autoClearDepth=c,t.autoClearStencil=d,t.transparent=h,t.opaque=p,t.contextNode=g,t.lighting=f,i.layers.mask=m}setSize(e,t){this._width=e,this._height=t;let r=Math.floor(this._width*this._resolutionScale),i=Math.floor(this._height*this._resolutionScale);this.renderTarget.setSize(r,i),this._scissor!==null?(this.renderTarget.scissor.copy(this._scissor).multiplyScalar(this._resolutionScale).floor(),this.renderTarget.scissorTest=!0):this.renderTarget.scissorTest=!1,this._viewport!==null&&this.renderTarget.viewport.copy(this._viewport).multiplyScalar(this._resolutionScale).floor()}setScissor(e,t,r,i){e===null?this._scissor=null:(this._scissor===null&&(this._scissor=new pe),e.isVector4?this._scissor.copy(e):this._scissor.set(e,t,r,i))}setViewport(e,t,r,i){e===null?this._viewport=null:(this._viewport===null&&(this._viewport=new pe),e.isVector4?this._viewport.copy(e):this._viewport.set(e,t,r,i))}dispose(){this.renderTarget.dispose()}};Fn.COLOR="color";Fn.DEPTH="depth";var Kf=Fn,cD=(n,e,t)=>new Fn(Fn.COLOR,n,e,t),dD=(n,e)=>new Xf(n,e),hD=(n,e,t)=>new Fn(Fn.DEPTH,n,e,t);var V_=class extends Kf{static get type(){return"ToonOutlinePassNode"}constructor(e,t,r,i,s){super(Kf.COLOR,e,t),this.colorNode=r,this.thicknessNode=i,this.alphaNode=s,this._materialCache=new WeakMap,this.name="Outline Pass"}updateBefore(e){let{renderer:t}=e,r=t.getRenderObjectFunction();t.setRenderObjectFunction((i,s,o,a,l,u,c,d)=>{if((l.isMeshToonMaterial||l.isMeshToonNodeMaterial)&&l.wireframe===!1){let h=this._getOutlineMaterial(l);t.renderObject(i,s,o,a,h,u,c,d)}t.renderObject(i,s,o,a,l,u,c,d)}),super.updateBefore(e),t.setRenderObjectFunction(r)}_createMaterial(){let e=new we;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=Ze;let t=pt.negate(),r=zr.mul($r),i=y(1),s=r.mul(X(Le,1)),o=r.mul(X(Le.add(t),1)),a=_t(s.sub(o));return e.vertexNode=s.add(a.mul(this.thicknessNode).mul(s.w).mul(i)),e.colorNode=X(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return t===void 0&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}};var pD=(n,e,t=new le(0,0,0),r=.003,i=1)=>new V_(n,e,j(t),j(r),j(i));var G_=_(([n,e])=>n.mul(e).clamp()).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),z_=_(([n,e])=>(n=n.mul(e),n.div(n.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),$_=_(([n,e])=>{n=n.mul(e),n=n.sub(.004).max(0);let t=n.mul(n.mul(6.2).add(.5)),r=n.mul(n.mul(6.2).add(1.7)).add(.06);return t.div(r).pow(2.2)}).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),fD=_(([n])=>{let e=n.mul(n.add(.0245786)).sub(90537e-9),t=n.mul(n.add(.432951).mul(.983729)).add(.238081);return e.div(t)}),W_=_(([n,e])=>{let t=rt(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),r=rt(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return n=n.mul(e).div(.6),n=t.mul(n),n=fD(n),n=r.mul(n),n.clamp()}).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),mD=rt(N(1.6605,-.1246,-.0182),N(-.5876,1.1329,-.1006),N(-.0728,-.0083,1.1187)),gD=rt(N(.6274,.0691,.0164),N(.3293,.9195,.088),N(.0433,.0113,.8956)),xD=_(([n])=>{let e=N(n).toVar(),t=N(e.mul(e)).toVar(),r=N(t.mul(t)).toVar();return y(15.5).mul(r.mul(t)).sub(ce(40.14,r.mul(e))).add(ce(31.96,r).sub(ce(6.868,t.mul(e))).add(ce(.4298,t).add(ce(.1191,e).sub(.00232))))}),H_=_(([n,e])=>{let t=N(n).toVar(),r=rt(N(.856627153315983,.137318972929847,.11189821299995),N(.0951212405381588,.761241990602591,.0767994186031903),N(.0482516061458583,.101439036467562,.811302368396859)),i=rt(N(1.1271005818144368,-.1413297634984383,-.14132976349843826),N(-.11060664309660323,1.157823702216272,-.11060664309660294),N(-.016493938717834573,-.016493938717834257,1.2519364065950405)),s=y(-12.47393),o=y(4.026069);return t.mulAssign(e),t.assign(gD.mul(t)),t.assign(r.mul(t)),t.assign(Ie(t,1e-10)),t.assign(kr(t)),t.assign(t.sub(s).div(o.sub(s))),t.assign(ur(t,0,1)),t.assign(xD(t)),t.assign(i.mul(t)),t.assign(lr(Ie(N(0),t),N(2.2))),t.assign(mD.mul(t)),t.assign(ur(t,0,1)),t}).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),q_=_(([n,e])=>{let t=y(.76),r=y(.15);n=n.mul(e);let i=ht(n.r,ht(n.g,n.b)),s=St(i.lessThan(.08),i.sub(ce(6.25,i.mul(i))),.04);n.subAssign(s);let o=Ie(n.r,Ie(n.g,n.b));ie(o.lessThan(t),()=>n);let a=Se(1,t),l=Se(1,a.mul(a).div(o.add(a.sub(t))));n.mulAssign(l.div(o));let u=Se(1,xt(1,r.mul(o.sub(l)).add(1)));return xe(n,N(l),u)}).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});var Qf=class extends W{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){let t=this.getIncludes(e);for(let i of t)i.build(e);let 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}},Qe=Qf,Zf=te(Qf).setParameterLength(1,3),yD=(n,e)=>Zf(n,e,"js"),bD=(n,e)=>Zf(n,e,"wgsl"),_D=(n,e)=>Zf(n,e,"glsl");var Jf=class extends Qe{static get type(){return"FunctionNode"}constructor(e="",t=[],r=""){super(e,t,r)}generateNodeType(e){return this.getNodeFunction(e).type}getMemberType(e,t){let r=this.getNodeType(e);return e.getStructTypeNode(r).getMemberType(e,t)}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){let t=e.getDataFromNode(this),r=t.nodeFunction;return r===void 0&&(r=e.parser.parseFunction(this.code),t.nodeFunction=r),r}generate(e,t){super.generate(e);let r=this.getNodeFunction(e),i=r.name,s=r.type,o=e.getCodeFromNode(this,s);if(i!==""){let u=e.getDataFromNode(this);u.declarationRegistered!==!0&&(o.name=i,e.registerDeclaration(o),u.declarationRegistered=!0)}let a=e.getPropertyName(o),l=this.getNodeFunction(e).getCode(a);return o.code=l+` | |
| `,t==="property"?a:e.format(`${a}()`,s,t)}},j_=Jf,VR=(n,e=[],t="")=>{let r=new Jf(n,e,t);return Ju((...s)=>r.call(...s),r)},TD=(n,e)=>VR(n,e,"glsl"),SD=(n,e)=>VR(n,e,"wgsl");function X_(n){let e,t=n.context.getViewZ;return t!==void 0&&(e=t(this)),(e||$e.z).negate()}var Y_=_(([n,e],t)=>{let r=X_(t);return Wt(n,e,r)}),K_=_(([n],e)=>{let t=X_(e);return n.mul(n,t,t).negate().exp().oneMinus()}),ND=_(([n,e],t)=>{let r=X_(t),s=e.sub(vr.y).max(0).toConst().mul(r).toConst();return n.mul(n,s,s).negate().exp().oneMinus()}),em=_(([n,e])=>X(e.toFloat().mix(fo.rgb,n.toVec3()),fo.a));var Wa=null,Ha=null,Q_=class extends W{static get type(){return"RangeNode"}constructor(e=y(),t=y()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){let t=this.getConstNode(this.minNode),r=this.getConstNode(this.maxNode),i=e.getTypeLength(Oi(t.value)),s=e.getTypeLength(Oi(r.value));return i>s?i:s}generateNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}getConstNode(e){let t=null;if(e.traverse(r=>{r.isConstNode===!0&&(t=r)}),t===null)throw new xc('THREE.TSL: No "ConstNode" found in node graph.',this.stackTrace);return t}setup(e){let t=e.object,r=null;if(t.count>1){let i=this.getConstNode(this.minNode),s=this.getConstNode(this.maxNode),o=i.value,a=s.value,l=e.getTypeLength(Oi(o)),u=e.getTypeLength(Oi(a));Wa=Wa||new pe,Ha=Ha||new pe,Wa.setScalar(0),Ha.setScalar(0),l===1?Wa.setScalar(o):o.isColor?Wa.set(o.r,o.g,o.b,1):Wa.set(o.x,o.y,o.z||0,o.w||0),u===1?Ha.setScalar(a):a.isColor?Ha.set(a.r,a.g,a.b,1):Ha.set(a.x,a.y,a.z||0,a.w||0);let c=4,d=c*t.count,h=new Float32Array(d);for(let m=0;m<d;m++){let g=m%c,x=Wa.getComponent(g),w=Ha.getComponent(g);h[m]=Jd.lerp(x,w,Math.random())}let p=this.getNodeType(e);if(t.count*4*4<=e.getUniformBufferLimit())r=Ls(h,"vec4",t.count).element(cr).convert(p);else{let m=new Ui(h,4);e.geometry.setAttribute("__range"+this.id,m),r=Hl(m).convert(p)}}else r=y(0);return r}};var wD=te(Q_).setParameterLength(2);var Z_=class extends W{static get type(){return"ComputeBuiltinNode"}constructor(e,t){super(t),this._builtinName=e}getHash(e){return this.getBuiltinName(e)}generateNodeType(){return this.nodeType}setBuiltinName(e){return this._builtinName=e,this}getBuiltinName(){return this._builtinName}hasBuiltin(e){return e.hasBuiltin(this._builtinName)}generate(e,t){let r=this.getBuiltinName(e),i=this.getNodeType(e);return e.shaderStage==="compute"?e.format(r,i,t):(U(`ComputeBuiltinNode: Compute built-in value ${r} 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}};var Qc=(n,e)=>new Z_(n,e),MD=Qc("numWorkgroups","uvec3"),vD=Qc("workgroupId","uvec3"),AD=Qc("globalId","uvec3"),RD=Qc("localId","uvec3"),CD=Qc("subgroupSize","uint");var J_=class extends W{constructor(e){super(),this.scope=e,this.isBarrierNode=!0}setup(e){e.allowEarlyReturns=!1,e.allowGlobalVariables=!1}generate(e){let{scope:t}=this,{renderer:r}=e;r.backend.isWebGLBackend===!0?e.addFlowCode(` // ${t}Barrier | |
| `):e.addLineFlowCode(`${t}Barrier()`,this)}};var eT=te(J_),ED=()=>eT("workgroup").toStack(),BD=()=>eT("storage").toStack(),FD=()=>eT("texture").toStack();var tT=class extends ri{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let r,i=e.isContextAssign();if(r=super.generate(e),i!==!0){let s=this.getNodeType(e);r=e.format(r,s,t)}return r}},rT=class extends W{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 U('TSL: "label()" has been deprecated. Use "setName()" instead.',new tt),this.setName(e)}setScope(e){return this.scope=e,this}getElementType(){return this.elementType}getInputType(){return`${this.scope}Array`}element(e){return new tT(this,e)}generate(e){let t=this.name!==""?this.name:`${this.scope}Array_${this.id}`;return e.getScopedArray(t,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}};var LD=(n,e)=>new rT("Workgroup",n,e);var Lt=class extends W{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)}generateNodeType(e){return this.getInputType(e)}generate(e){let t=e.getNodeProperties(this),r=t.parents,i=this.method,s=this.getNodeType(e),o=this.getInputType(e),a=this.pointerNode,l=this.valueNode,u=[];u.push(`&${a.build(e,o)}`),l!==null&&u.push(l.build(e,o));let c=`${e.getMethod(i,s)}( ${u.join(", ")} )`;if(r?r.length===1&&r[0].isStackNode===!0:!1)e.addLineFlowCode(c,this);else return t.constNode===void 0&&(t.constNode=dr(c,s).toConst()),t.constNode.build(e)}};Lt.ATOMIC_LOAD="atomicLoad";Lt.ATOMIC_STORE="atomicStore";Lt.ATOMIC_ADD="atomicAdd";Lt.ATOMIC_SUB="atomicSub";Lt.ATOMIC_MAX="atomicMax";Lt.ATOMIC_MIN="atomicMin";Lt.ATOMIC_AND="atomicAnd";Lt.ATOMIC_OR="atomicOr";Lt.ATOMIC_XOR="atomicXor";var PD=te(Lt),Hs=(n,e,t)=>PD(n,e,t).toStack(),DD=n=>Hs(Lt.ATOMIC_LOAD,n,null),UD=(n,e)=>Hs(Lt.ATOMIC_STORE,n,e),ID=(n,e)=>Hs(Lt.ATOMIC_ADD,n,e),OD=(n,e)=>Hs(Lt.ATOMIC_SUB,n,e),kD=(n,e)=>Hs(Lt.ATOMIC_MAX,n,e),VD=(n,e)=>Hs(Lt.ATOMIC_MIN,n,e),GD=(n,e)=>Hs(Lt.ATOMIC_AND,n,e),zD=(n,e)=>Hs(Lt.ATOMIC_OR,n,e),$D=(n,e)=>Hs(Lt.ATOMIC_XOR,n,e);var re=class n extends _e{static get type(){return"SubgroupFunctionNode"}constructor(e,t=null,r=null){super(),this.method=e,this.aNode=t,this.bNode=r}getInputType(e){let t=this.aNode?this.aNode.getNodeType(e):null,r=this.bNode?this.bNode.getNodeType(e):null,i=e.isMatrix(t)?0:e.getTypeLength(t),s=e.isMatrix(r)?0:e.getTypeLength(r);return i>s?t:r}generateNodeType(e){let t=this.method;return t===n.SUBGROUP_ELECT?"bool":t===n.SUBGROUP_BALLOT?"uvec4":this.getInputType(e)}generate(e,t){let r=this.method,i=this.getNodeType(e),s=this.getInputType(e),o=this.aNode,a=this.bNode,l=[];if(r===n.SUBGROUP_BROADCAST||r===n.SUBGROUP_SHUFFLE||r===n.QUAD_BROADCAST){let c=a.getNodeType(e);l.push(o.build(e,i),a.build(e,c==="float"?"int":i))}else r===n.SUBGROUP_SHUFFLE_XOR||r===n.SUBGROUP_SHUFFLE_DOWN||r===n.SUBGROUP_SHUFFLE_UP?l.push(o.build(e,i),a.build(e,"uint")):(o!==null&&l.push(o.build(e,s)),a!==null&&l.push(a.build(e,s)));let u=l.length===0?"()":`( ${l.join(", ")} )`;return e.format(`${e.getMethod(r,i)}${u}`,i,t)}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}};re.SUBGROUP_ELECT="subgroupElect";re.SUBGROUP_BALLOT="subgroupBallot";re.SUBGROUP_ADD="subgroupAdd";re.SUBGROUP_INCLUSIVE_ADD="subgroupInclusiveAdd";re.SUBGROUP_EXCLUSIVE_AND="subgroupExclusiveAdd";re.SUBGROUP_MUL="subgroupMul";re.SUBGROUP_INCLUSIVE_MUL="subgroupInclusiveMul";re.SUBGROUP_EXCLUSIVE_MUL="subgroupExclusiveMul";re.SUBGROUP_AND="subgroupAnd";re.SUBGROUP_OR="subgroupOr";re.SUBGROUP_XOR="subgroupXor";re.SUBGROUP_MIN="subgroupMin";re.SUBGROUP_MAX="subgroupMax";re.SUBGROUP_ALL="subgroupAll";re.SUBGROUP_ANY="subgroupAny";re.SUBGROUP_BROADCAST_FIRST="subgroupBroadcastFirst";re.QUAD_SWAP_X="quadSwapX";re.QUAD_SWAP_Y="quadSwapY";re.QUAD_SWAP_DIAGONAL="quadSwapDiagonal";re.SUBGROUP_BROADCAST="subgroupBroadcast";re.SUBGROUP_SHUFFLE="subgroupShuffle";re.SUBGROUP_SHUFFLE_XOR="subgroupShuffleXor";re.SUBGROUP_SHUFFLE_UP="subgroupShuffleUp";re.SUBGROUP_SHUFFLE_DOWN="subgroupShuffleDown";re.QUAD_BROADCAST="quadBroadcast";var WD=G(re,re.SUBGROUP_ELECT).setParameterLength(0),HD=G(re,re.SUBGROUP_BALLOT).setParameterLength(1),qD=G(re,re.SUBGROUP_ADD).setParameterLength(1),jD=G(re,re.SUBGROUP_INCLUSIVE_ADD).setParameterLength(1),XD=G(re,re.SUBGROUP_EXCLUSIVE_AND).setParameterLength(1),YD=G(re,re.SUBGROUP_MUL).setParameterLength(1),KD=G(re,re.SUBGROUP_INCLUSIVE_MUL).setParameterLength(1),QD=G(re,re.SUBGROUP_EXCLUSIVE_MUL).setParameterLength(1),ZD=G(re,re.SUBGROUP_AND).setParameterLength(1),JD=G(re,re.SUBGROUP_OR).setParameterLength(1),e2=G(re,re.SUBGROUP_XOR).setParameterLength(1),t2=G(re,re.SUBGROUP_MIN).setParameterLength(1),r2=G(re,re.SUBGROUP_MAX).setParameterLength(1),i2=G(re,re.SUBGROUP_ALL).setParameterLength(0),s2=G(re,re.SUBGROUP_ANY).setParameterLength(0),n2=G(re,re.SUBGROUP_BROADCAST_FIRST).setParameterLength(2),o2=G(re,re.QUAD_SWAP_X).setParameterLength(1),a2=G(re,re.QUAD_SWAP_Y).setParameterLength(1),l2=G(re,re.QUAD_SWAP_DIAGONAL).setParameterLength(1),u2=G(re,re.SUBGROUP_BROADCAST).setParameterLength(2),c2=G(re,re.SUBGROUP_SHUFFLE).setParameterLength(2),d2=G(re,re.SUBGROUP_SHUFFLE_XOR).setParameterLength(2),h2=G(re,re.SUBGROUP_SHUFFLE_UP).setParameterLength(2),p2=G(re,re.SUBGROUP_SHUFFLE_DOWN).setParameterLength(2),f2=G(re,re.QUAD_BROADCAST).setParameterLength(1);var tm;function rm(n){tm=tm||new WeakMap;let e=tm.get(n);return e===void 0&&tm.set(n,e={}),e}function lu(n){let e=rm(n);return e.shadowMatrix||(e.shadowMatrix=Y("mat4").setGroup(ee).onRenderUpdate(t=>((n.castShadow!==!0||t.renderer.shadowMap.enabled===!1)&&(n.shadow.camera.coordinateSystem!==t.camera.coordinateSystem&&(n.shadow.camera.coordinateSystem=t.camera.coordinateSystem,n.shadow.camera.updateProjectionMatrix()),n.shadow.updateMatrices(n)),n.shadow.matrix)))}function iT(n,e=vr){let t=lu(n).mul(e);return t.xyz.div(t.w)}function im(n){let e=rm(n);return e.position||(e.position=Y(new C).setGroup(ee).onRenderUpdate((t,r)=>r.value.setFromMatrixPosition(n.matrixWorld)))}function GR(n){let e=rm(n);return e.targetPosition||(e.targetPosition=Y(new C).setGroup(ee).onRenderUpdate((t,r)=>r.value.setFromMatrixPosition(n.target.matrixWorld)))}function Zc(n){let e=rm(n);return e.viewPosition||(e.viewPosition=Y(new C).setGroup(ee).onRenderUpdate(({camera:t},r)=>{r.value=r.value||new C,r.value.setFromMatrixPosition(n.matrixWorld),r.value.applyMatrix4(t.matrixWorldInverse)}))}var Jc=n=>yi.transformDirection(im(n).sub(GR(n)));var m2=wn("vec3","totalDiffuse"),g2=wn("vec3","totalSpecular"),x2=wn("vec3","outgoingLight"),y2=n=>n.sort((e,t)=>e.id-t.id),b2=(n,e)=>{for(let t of e)if(t.isAnalyticLightNode&&t.light.id===n)return t;return null},sT=new WeakMap,ed=[],sm=class extends W{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=m2,this.totalSpecularNode=g2,this.outgoingLightNode=x2,this._lights=[],this.global=!0}customCacheKey(){let e=this.getBuiltinLights();for(let r=0;r<e.length;r++){let i=e[r];if(ed.push(i.id),ed.push(i.castShadow?1:0),i.isSpotLight===!0){let s=i.map!==null?i.map.id:-1,o=i.colorNode?i.colorNode.getCacheKey():-1;ed.push(s,o)}}let t=Ns(ed);return ed.length=0,t}getHash(e){let t=e.getDataFromNode(this);if(t.lightNodesHash===void 0){let r=this.setupLightsNode(e);t.lightNodes=r;let i=[];for(let s of r)i.push(s.getHash());t.lightNodesHash="lights-"+i.join(",")}return t.lightNodesHash}analyze(e){let t=e.getNodeProperties(this);for(let r of t.nodes)r.build(e);t.outputNode.build(e)}setupLightsNode(e){let t=e.getDataFromNode(this),r=[],i=t.lightNodes||null,s=e.context.materialLightings,o=this.getBuiltinLights(),a=y2([...s,...o]),l=e.renderer.library;for(let u of a)if(u.isNode)r.push(u);else{let c=null;if(i!==null&&(c=b2(u.id,i)),c===null){let d=l.getLightNodeClass(u.constructor);if(d===null){U(`LightsNode.setupNodeLights: Light node not found for ${u.constructor.name}`);continue}sT.has(u)===!1&&sT.set(u,new d(u)),c=sT.get(u)}r.push(c)}return r}setupDirectLight(e,t,r){let{lightingModel:i,reflectedLight:s}=e.context;i.direct({...r,lightNode:t,reflectedLight:s},e)}setupDirectRectAreaLight(e,t,r){let{lightingModel:i,reflectedLight:s}=e.context;i.directRectArea({...r,lightNode:t,reflectedLight:s},e)}setupLights(e,t){for(let r of t)r.build(e)}getLightNodes(e){let t=e.getDataFromNode(this);return t.lightNodes===void 0&&(t.lightNodes=this.setupLightsNode(e)),t.lightNodes}setup(e){let t=e.lightsNode;e.lightsNode=this;let r=this.outgoingLightNode,i=e.context,s=i.lightingModel,o=e.getNodeProperties(this);if(s){let{totalDiffuseNode:a,totalSpecularNode:l}=this;i.outgoingLight=r;let u=e.addStack();o.nodes=u.nodes,s.start(e);let{backdrop:c,backdropAlpha:d}=i,{directDiffuse:h,directSpecular:p,indirectDiffuse:f,indirectSpecular:m}=i.reflectedLight,g=h.add(f);c!==null&&(d!==null?g=N(d.mix(g,c)):g=N(c)),a.assign(g),l.assign(p.add(m)),r.assign(a.add(l)),s.finish(e),r=r.bypass(e.removeStack())}else o.nodes=[];return e.lightsNode=t,r}setLights(e){return this._lights=e,this}getLights(){return this._lights}getBuiltinLights(){return this._lights}get hasLights(){return this._lights.length>0}},nm=sm,_2=(n=[])=>new sm().setLights(n);var nT=class extends W{static get type(){return"ShadowBaseNode"}constructor(e){super(),this.light=e,this.updateBeforeType=J.RENDER,this.isShadowBaseNode=!0}setupShadowPosition({context:e,material:t}){om.assign(t.receivedShadowPositionNode||e.shadowPositionWorld||vr)}},om=wn("vec3","shadowPositionWorld"),oT=nT;function T2(n,e={}){return e.toneMapping=n.toneMapping,e.toneMappingExposure=n.toneMappingExposure,e.outputColorSpace=n.outputColorSpace,e.renderTarget=n.getRenderTarget(),e.activeCubeFace=n.getActiveCubeFace(),e.activeMipmapLevel=n.getActiveMipmapLevel(),e.renderObjectFunction=n.getRenderObjectFunction(),e.pixelRatio=n.getPixelRatio(),e.mrt=n.getMRT(),e.clearColor=n.getClearColor(e.clearColor||new le),e.clearAlpha=n.getClearAlpha(),e.autoClear=n.autoClear,e.scissorTest=n.getScissorTest(),e}function S2(n,e){return e=T2(n,e),n.setMRT(null),n.setRenderObjectFunction(null),n.setClearColor(0,1),n.autoClear=!0,e}function N2(n,e){n.toneMapping=e.toneMapping,n.toneMappingExposure=e.toneMappingExposure,n.outputColorSpace=e.outputColorSpace,n.setRenderTarget(e.renderTarget,e.activeCubeFace,e.activeMipmapLevel),n.setRenderObjectFunction(e.renderObjectFunction),n.setPixelRatio(e.pixelRatio),n.setMRT(e.mrt),n.setClearColor(e.clearColor,e.clearAlpha),n.autoClear=e.autoClear,n.setScissorTest(e.scissorTest)}function w2(n,e={}){return e.background=n.background,e.backgroundNode=n.backgroundNode,e.overrideMaterial=n.overrideMaterial,e}function M2(n,e){return e=w2(n,e),n.background=null,n.backgroundNode=null,n.overrideMaterial=null,e}function v2(n,e){n.background=e.background,n.backgroundNode=e.backgroundNode,n.overrideMaterial=e.overrideMaterial}function zR(n,e,t){return t=S2(n,t),t=M2(e,t),t}function $R(n,e,t){N2(n,t),v2(e,t)}var am=new WeakMap,aT=_(({depthTexture:n,shadowCoord:e,depthLayer:t})=>{let r=be(n,e.xy).setName("t_basic");return n.isArrayTexture&&(r=r.depth(t)),r.compare(e.z)}),lT=_(({depthTexture:n,shadowCoord:e,shadow:t,depthLayer:r})=>{let i=(c,d)=>{let h=be(n,c);return n.isArrayTexture&&(h=h.depth(r)),h.compare(d)},s=ke("mapSize","vec2",t).setGroup(ee),o=ke("radius","float",t).setGroup(ee),a=V(1).div(s),l=o.mul(a.x),u=Kc(Ps.xy).mul(6.28318530718);return Xe(i(e.xy.add(Ni(0,5,u).mul(l)),e.z),i(e.xy.add(Ni(1,5,u).mul(l)),e.z),i(e.xy.add(Ni(2,5,u).mul(l)),e.z),i(e.xy.add(Ni(3,5,u).mul(l)),e.z),i(e.xy.add(Ni(4,5,u).mul(l)),e.z)).mul(1/5)}),uT=_(({depthTexture:n,shadowCoord:e,depthLayer:t},r)=>{let i=be(n).sample(e.xy);n.isArrayTexture&&(i=i.depth(t)),i=i.rg;let s=i.x,o=Ie(1e-7,i.y.mul(i.y)),a=r.renderer.reversedDepthBuffer?Cs(s,e.z):Cs(e.z,s),l=y(1).toVar();return ie(a.notEqual(1),()=>{let u=e.z.sub(s),c=o.div(o.add(u.mul(u)));c=ur(Se(c,.3).div(.65)),l.assign(Ie(a,c))}),l}),cT=n=>{let e=am.get(n);return e===void 0&&(e=new we,e.colorNode=X(0,0,0,1),e.isShadowPassMaterial=!0,e.name="ShadowMaterial",e.blending=Pr,e.fog=!1,am.set(n,e)),e},dT=n=>{let e=am.get(n);e!==void 0&&(e.dispose(),am.delete(n))};var WR=new Si,uu=[],HR=(n,e,t,r)=>{uu[0]=n,uu[1]=e;let i=WR.get(uu);return(i===void 0||i.shadowType!==t||i.useVelocity!==r)&&(i=(s,o,a,l,u,c,d,h,p)=>{(s.castShadow===!0||s.receiveShadow&&t===Do)&&(r&&(Qh(s).useVelocity=!0),s.onBeforeShadow(n,s,a,e.camera,l,o.overrideMaterial,c),n.renderObject(s,o,a,l,u,c,d,h,p),s.onAfterShadow(n,s,a,e.camera,l,o.overrideMaterial,c))},i.shadowType=t,i.useVelocity=r,WR.set(uu,i)),uu[0]=null,uu[1]=null,i},A2=_(({samples:n,radius:e,size:t,shadowPass:r,depthLayer:i})=>{let s=y(0).toVar("meanVertical"),o=y(0).toVar("squareMeanVertical"),a=n.lessThanEqual(y(1)).select(y(0),y(2).div(n.sub(1))),l=n.lessThanEqual(y(1)).select(y(0),y(-1));Ee({start:A(0),end:A(n),type:"int",condition:"<"},({i:c})=>{let d=l.add(y(c).mul(a)),h=r.sample(Xe(Ps.xy,V(0,d).mul(e)).div(t));r.value.isArrayTexture&&(h=h.depth(i)),h=h.x,s.addAssign(h),o.addAssign(h.mul(h))}),s.divAssign(n),o.divAssign(n);let u=Ct(o.sub(s.mul(s)).max(0));return V(s,u)}),R2=_(({samples:n,radius:e,size:t,shadowPass:r,depthLayer:i})=>{let s=y(0).toVar("meanHorizontal"),o=y(0).toVar("squareMeanHorizontal"),a=n.lessThanEqual(y(1)).select(y(0),y(2).div(n.sub(1))),l=n.lessThanEqual(y(1)).select(y(0),y(-1));Ee({start:A(0),end:A(n),type:"int",condition:"<"},({i:c})=>{let d=l.add(y(c).mul(a)),h=r.sample(Xe(Ps.xy,V(d,0).mul(e)).div(t));r.value.isArrayTexture&&(h=h.depth(i)),s.addAssign(h.x),o.addAssign(Xe(h.y.mul(h.y),h.x.mul(h.x)))}),s.divAssign(n),o.divAssign(n);let u=Ct(o.sub(s.mul(s)).max(0));return V(s,u)}),C2=[aT,lT,null,uT],hT,lm=new ou,um=class extends oT{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:i,shadow:s,depthLayer:o}){let a=i.x.greaterThanEqual(0).and(i.x.lessThanEqual(1)).and(i.y.greaterThanEqual(0)).and(i.y.lessThanEqual(1)).and(i.z.lessThanEqual(1)),l=t({depthTexture:r,shadowCoord:i,shadow:s,depthLayer:o});return a.select(l,y(1))}setupShadowCoord(e,t){let{shadow:r}=this,{renderer:i}=e,s=r.biasNode||ke("bias","float",r).setGroup(ee),o=t,a;if(r.camera.isOrthographicCamera||i.logarithmicDepthBuffer!==!0)o=o.xyz.div(o.w),a=o.z;else{let l=o.w;o=o.xy.div(l);let u=ke("near","float",r.camera).setGroup(ee),c=ke("far","float",r.camera).setGroup(ee);a=ka(l.negate(),u,c)}return o=N(o.x,o.y.oneMinus(),i.reversedDepthBuffer?a.sub(s):a.add(s)),o}getShadowFilterFn(e){return C2[e]}setupRenderTarget(e,t){let r=new ot(e.mapSize.width,e.mapSize.height);r.name="ShadowDepthTexture",r.compareFunction=t.renderer.reversedDepthBuffer?ui:Pi;let i=t.createRenderTarget(e.mapSize.width,e.mapSize.height);return i.texture.name="ShadowMap",i.texture.type=e.mapType,i.depthTexture=r,{shadowMap:i,depthTexture:r}}setupShadow(e){let{renderer:t,camera:r}=e,{light:i,shadow:s}=this,{depthTexture:o,shadowMap:a}=this.setupRenderTarget(s,e),l=t.shadowMap.type,u=t.hasCompatibility(xr.TEXTURE_COMPARE);if(l===Gn&&u?(o.minFilter=je,o.magFilter=je):(o.minFilter=Pe,o.magFilter=Pe),s.camera.coordinateSystem=r.coordinateSystem,s.camera.updateProjectionMatrix(),l===Do&&s.isPointLightShadow!==!0){o.compareFunction=null,a.depth>1?(a._vsmShadowMapVertical||(a._vsmShadowMapVertical=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:vt,type:qe,depth:a.depth,depthBuffer:!1}),a._vsmShadowMapVertical.texture.name="VSMVertical"),this.vsmShadowMapVertical=a._vsmShadowMapVertical,a._vsmShadowMapHorizontal||(a._vsmShadowMapHorizontal=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:vt,type:qe,depth:a.depth,depthBuffer:!1}),a._vsmShadowMapHorizontal.texture.name="VSMHorizontal"),this.vsmShadowMapHorizontal=a._vsmShadowMapHorizontal):(this.vsmShadowMapVertical=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:vt,type:qe,depthBuffer:!1}),this.vsmShadowMapHorizontal=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:vt,type:qe,depthBuffer:!1}));let S=be(o);o.isArrayTexture&&(S=S.depth(this.depthLayer));let T=be(this.vsmShadowMapVertical.texture);o.isArrayTexture&&(T=T.depth(this.depthLayer));let M=ke("blurSamples","float",s).setGroup(ee),B=ke("radius","float",s).setGroup(ee),D=ke("mapSize","vec2",s).setGroup(ee),O=wr(e.getSharedContext()),z=this.vsmMaterialVertical||(this.vsmMaterialVertical=new we);z.contextNode=O,z.fragmentNode=A2({samples:M,radius:B,size:D,shadowPass:S,depthLayer:this.depthLayer}),z.name="VSMVertical",z=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new we),z.contextNode=O,z.fragmentNode=R2({samples:M,radius:B,size:D,shadowPass:T,depthLayer:this.depthLayer}),z.name="VSMHorizontal"}let c=ke("intensity","float",s).setGroup(ee),d=ke("normalBias","float",s).setGroup(ee),h=lu(i),p=ni.mul(d),f;!t.highPrecision||e.material.receivedShadowPositionNode||e.context.shadowPositionWorld?f=h.mul(om.add(p)):f=Y("mat4").onObjectUpdate(({object:T},M)=>M.value.multiplyMatrices(h.value,T.matrixWorld)).mul(Le).add(h.mul(X(p,0)));let m=this.setupShadowCoord(e,f),g=s.filterNode||this.getShadowFilterFn(t.shadowMap.type)||null;if(g===null)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");let x=l===Do&&s.isPointLightShadow!==!0?this.vsmShadowMapHorizontal.texture:o,w=this.setupShadowFilter(e,{filterFn:g,shadowTexture:a.texture,depthTexture:x,shadowCoord:m,shadow:s,depthLayer:this.depthLayer}),v;t.shadowMap.transmitted===!0&&(a.texture.isCubeTexture?v=Ft(a.texture,m.xyz):(v=be(a.texture,m),o.isArrayTexture&&(v=v.depth(this.depthLayer))));let E;v?E=xe(1,w.rgb.mix(v,1),c.mul(v.a)).toVar():E=xe(1,w,c).toVar(),this.shadowMap=a,this.shadow.map=a;let b=`${this.light.type} Shadow [ ${this.light.name||"ID: "+this.light.id} ]`;return v&&E.toInspector(`${b} / Color`,()=>this.shadowMap.texture.isCubeTexture?Ft(this.shadowMap.texture,hf()):be(this.shadowMap.texture)),E.toInspector(`${b} / Depth`,()=>{let S=ke("near","float",this.shadow.camera),T=ke("far","float",this.shadow.camera),M;this.shadowMap.texture.isCubeTexture?M=Ft(this.shadowMap.depthTexture,hf()).r:M=be(this.shadowMap.depthTexture).r;let B;return this.shadow.camera.isPerspectiveCamera?B=Ql(M,S,T):B=Hb(M,S,T),B=ks(B,S,T),B.oneMinus()})}setup(e){if(e.renderer.shadowMap.enabled!==!1)return _(()=>{let t=e.renderer.shadowMap.type;this._currentShadowType!==t&&(this._reset(),this._node=null);let r=this._node;return this.setupShadowPosition(e),r===null&&(this._node=r=this.setupShadow(e),this._currentShadowType=t),e.material.receivedShadowNode&&(r=e.material.receivedShadowNode(r)),r})()}renderShadow(e){let{shadow:t,shadowMap:r,light:i}=this,{renderer:s,scene:o}=e;t.updateMatrices(i),r.setSize(t.mapSize.width,t.mapSize.height,r.depth);let a=o.name;o.name=`Shadow Map [ ${i.name||"ID: "+i.id} ]`,s.render(o,t.camera),o.name=a}updateShadow(e){let{shadowMap:t,light:r,shadow:i}=this,{renderer:s,scene:o,camera:a}=e,l=s.shadowMap.type,u=t.depthTexture.version;this._depthVersionCached=u;let c=i.camera.layers.mask;(i.camera.layers.mask&4294967294)===0&&(i.camera.layers.mask=a.layers.mask);let d=s.getRenderObjectFunction(),h=s.getMRT(),p=h?h.has("velocity"):!1;hT=zR(s,o,hT),o.overrideMaterial=cT(r),s.setRenderObjectFunction(HR(s,i,l,p)),s.setClearColor(0,0),s.setRenderTarget(t),this.renderShadow(e),s.setRenderObjectFunction(d),l===Do&&i.isPointLightShadow!==!0&&this.vsmPass(s),i.camera.layers.mask=c,$R(s,o,hT)}vsmPass(e){let{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),lm.material=this.vsmMaterialVertical,lm.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),lm.material=this.vsmMaterialHorizontal,lm.render(e)}dispose(){this._reset(),super.dispose()}_reset(){this._currentShadowType=null,dT(this.light),this.shadowMap&&(this.shadowMap.dispose(),this.shadowMap=null),this.vsmShadowMapVertical!==null&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),this.vsmShadowMapHorizontal!==null&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null)}updateBefore(e){if(e.renderer._isPreCompiling===!0)return;let{shadow:t}=this,r=t.needsUpdate||t.autoUpdate;r&&(this._cameraFrameId.get(e.camera)===e.frameId&&(r=!1),this._cameraFrameId.set(e.camera,e.frameId)),r&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}},pT=um,fT=(n,e)=>new um(n,e);var E2=new le,qR=new ue,td=new C,mT=new C,B2=[new C(1,0,0),new C(-1,0,0),new C(0,-1,0),new C(0,1,0),new C(0,0,1),new C(0,0,-1)],F2=[new C(0,-1,0),new C(0,-1,0),new C(0,0,-1),new C(0,0,1),new C(0,-1,0),new C(0,-1,0)],L2=[new C(1,0,0),new C(-1,0,0),new C(0,1,0),new C(0,-1,0),new C(0,0,1),new C(0,0,-1)],P2=[new C(0,-1,0),new C(0,-1,0),new C(0,0,1),new C(0,0,-1),new C(0,-1,0),new C(0,-1,0)],jR=_(({depthTexture:n,bd3D:e,dp:t})=>Ft(n,e).compare(t)),XR=_(({depthTexture:n,bd3D:e,dp:t,shadow:r})=>{let i=ke("radius","float",r).setGroup(ee),s=ke("mapSize","vec2",r).setGroup(ee),o=i.div(s.x),a=Ue(e),l=_t(gi(e,a.x.greaterThan(a.z).select(N(0,1,0),N(1,0,0)))),u=gi(e,l),c=Kc(Ps.xy).mul(6.28318530718),d=Ni(0,5,c),h=Ni(1,5,c),p=Ni(2,5,c),f=Ni(3,5,c),m=Ni(4,5,c);return Ft(n,e.add(l.mul(d.x).add(u.mul(d.y)).mul(o))).compare(t).add(Ft(n,e.add(l.mul(h.x).add(u.mul(h.y)).mul(o))).compare(t)).add(Ft(n,e.add(l.mul(p.x).add(u.mul(p.y)).mul(o))).compare(t)).add(Ft(n,e.add(l.mul(f.x).add(u.mul(f.y)).mul(o))).compare(t)).add(Ft(n,e.add(l.mul(m.x).add(u.mul(m.y)).mul(o))).compare(t)).mul(1/5)}),D2=_(({filterFn:n,depthTexture:e,shadowCoord:t,shadow:r},i)=>{let s=t.xyz.toConst(),o=s.abs().toConst(),a=o.x.max(o.y).max(o.z),l=Y("float").setGroup(ee).onRenderUpdate(()=>r.camera.near),u=Y("float").setGroup(ee).onRenderUpdate(()=>r.camera.far),c=ke("bias","float",r).setGroup(ee),d=y(1).toVar();return ie(a.sub(u).lessThanEqual(0).and(a.sub(l).greaterThanEqual(0)),()=>{let h;i.renderer.reversedDepthBuffer?(h=qb(a.negate(),l,u),h.subAssign(c)):i.renderer.logarithmicDepthBuffer?(h=ka(a.negate(),l,u),h.addAssign(c)):(h=cf(a.negate(),l,u),h.addAssign(c));let p=s.normalize();d.assign(n({depthTexture:e,bd3D:p,dp:h,shadow:r}))}),d}),gT=class extends pT{static get type(){return"PointShadowNode"}constructor(e,t=null){super(e,t)}getShadowFilterFn(e){return e===YN?jR:XR}setupShadowCoord(e,t){return t}setupShadowFilter(e,{filterFn:t,depthTexture:r,shadowCoord:i,shadow:s}){return D2({filterFn:t,depthTexture:r,shadowCoord:i,shadow:s})}setupRenderTarget(e,t){let r=new Mh(e.mapSize.width);r.name="PointShadowDepthTexture",r.compareFunction=t.renderer.reversedDepthBuffer?ui:Pi;let i=t.createCubeRenderTarget(e.mapSize.width);return i.texture.name="PointShadowMap",i.depthTexture=r,{shadowMap:i,depthTexture:r}}renderShadow(e){let{shadow:t,shadowMap:r,light:i}=this,{renderer:s,scene:o}=e,a=t.camera,l=t.matrix,u=s.coordinateSystem===yt,c=u?B2:L2,d=u?F2:P2;r.setSize(t.mapSize.width,t.mapSize.width);let h=s.autoClear,p=s.getClearColor(E2),f=s.getClearAlpha();s.autoClear=!1,s.setClearColor(t.clearColor,t.clearAlpha);for(let m=0;m<6;m++){s.setRenderTarget(r,m),s.clear();let g=i.distance||a.far;g!==a.far&&(a.far=g,a.updateProjectionMatrix()),td.setFromMatrixPosition(i.matrixWorld),a.position.copy(td),mT.copy(a.position),mT.add(c[m]),a.up.copy(d[m]),a.lookAt(mT),a.updateMatrixWorld(),l.makeTranslation(-td.x,-td.y,-td.z),qR.multiplyMatrices(a.projectionMatrix,a.matrixWorldInverse),t._frustum.setFromProjectionMatrix(qR,a.coordinateSystem,a.reversedDepth);let x=o.name;o.name=`Point Light Shadow [ ${i.name||"ID: "+i.id} ] - Face ${m+1}`,s.render(o,a),o.name=x}s.autoClear=h,s.setClearColor(p,f)}};var xT=(n,e)=>new gT(n,e);var yT=class extends Ti{static get type(){return"AnalyticLightNode"}constructor(e=null){super(),this.light=e,this.color=new le,this.colorNode=e&&e.colorNode||Y(this.color).setGroup(ee),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0,this.updateType=J.FRAME,e&&e.shadow&&(this._shadowDisposeListener=()=>{this.disposeShadow()},e.addEventListener("dispose",this._shadowDisposeListener))}dispose(){this._shadowDisposeListener&&this.light.removeEventListener("dispose",this._shadowDisposeListener),super.dispose()}disposeShadow(){this.shadowNode!==null&&(this.shadowNode.dispose(),this.shadowNode=null),this.shadowColorNode=null,this.baseColorNode!==null&&(this.colorNode=this.baseColorNode,this.baseColorNode=null)}getHash(){return this.light.uuid}getLightVector(e){return Zc(this.light).sub(e.context.positionView||$e)}setupDirect(){}setupDirectRectArea(){}setupShadowNode(){return fT(this.light)}setupShadow(e){let{renderer:t}=e;if(t.shadowMap.enabled===!1)return;let r=this.shadowColorNode;if(r===null){let i=this.light.shadow.shadowNode,s;i!==void 0?s=j(i):s=this.setupShadowNode(),this.shadowNode=s,this.shadowColorNode=r=this.colorNode.mul(s),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):this.shadowNode!==null&&(this.shadowNode.dispose(),this.shadowNode=null,this.shadowColorNode=null);let t=this.setupDirect(e),r=this.setupDirectRectArea(e);t&&e.lightsNode.setupDirectLight(e,this,t),r&&e.lightsNode.setupDirectRectAreaLight(e,this,r)}update(){let{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}},Hr=yT;var rd=_(({lightDistance:n,cutoffDistance:e,decayExponent:t})=>{let r=n.pow(t).max(.01).reciprocal();return e.greaterThan(0).select(r.mul(n.div(e).pow4().oneMinus().clamp().pow2()),r)});var YR=({color:n,lightVector:e,cutoffDistance:t,decayExponent:r})=>{let i=e.normalize(),s=e.length(),o=rd({lightDistance:s,cutoffDistance:t,decayExponent:r}),a=n.mul(o);return{lightDirection:i,lightColor:a}},bT=class extends Hr{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=Y(0).setGroup(ee),this.decayExponentNode=Y(2).setGroup(ee)}update(e){let{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setupShadowNode(){return xT(this.light)}setupDirect(e){return YR({color:this.colorNode,lightVector:this.getLightVector(e),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode})}},_T=bT;var U2=_(([n=Re()])=>{let e=n.mul(2),t=e.x.floor(),r=e.y.floor();return t.add(r).mod(2).sign()});var I2=_(([n=Re()],{renderer:e,material:t})=>{let r=Mp(n.mul(2).sub(1)),i;if(t.alphaToCoverage&&e.currentSamples>0){let s=y(r.fwidth()).toVar();i=Wt(s.oneMinus(),s.add(1),r).oneMinus()}else i=St(r.greaterThan(1),0,1);return i});var id=_(([n,e,t])=>{let r=y(t).toVar(),i=y(e).toVar(),s=nr(n).toVar();return St(s,i,r).uniformFlow()}).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),cm=_(([n,e])=>{let t=nr(e).toVar(),r=y(n).toVar();return St(t,r.negate(),r).uniformFlow()}).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),Pt=_(([n])=>{let e=y(n).toVar();return A(Vr(e))}).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),lt=_(([n,e])=>{let t=y(n).toVar();return e.assign(Pt(t)),t.sub(y(e))}),O2=_(([n,e,t,r,i,s])=>{let o=y(s).toVar(),a=y(i).toVar(),l=y(r).toVar(),u=y(t).toVar(),c=y(e).toVar(),d=y(n).toVar(),h=y(Se(1,a)).toVar();return Se(1,o).mul(d.mul(h).add(c.mul(a))).add(o.mul(u.mul(h).add(l.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"}]}),k2=_(([n,e,t,r,i,s])=>{let o=y(s).toVar(),a=y(i).toVar(),l=N(r).toVar(),u=N(t).toVar(),c=N(e).toVar(),d=N(n).toVar(),h=y(Se(1,a)).toVar();return Se(1,o).mul(d.mul(h).add(c.mul(a))).add(o.mul(u.mul(h).add(l.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"}]}),KR=Xt([O2,k2]),V2=_(([n,e,t,r,i,s,o,a,l,u,c])=>{let d=y(c).toVar(),h=y(u).toVar(),p=y(l).toVar(),f=y(a).toVar(),m=y(o).toVar(),g=y(s).toVar(),x=y(i).toVar(),w=y(r).toVar(),v=y(t).toVar(),E=y(e).toVar(),b=y(n).toVar(),S=y(Se(1,p)).toVar(),T=y(Se(1,h)).toVar();return y(Se(1,d)).toVar().mul(T.mul(b.mul(S).add(E.mul(p))).add(h.mul(v.mul(S).add(w.mul(p))))).add(d.mul(T.mul(x.mul(S).add(g.mul(p))).add(h.mul(m.mul(S).add(f.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"}]}),G2=_(([n,e,t,r,i,s,o,a,l,u,c])=>{let d=y(c).toVar(),h=y(u).toVar(),p=y(l).toVar(),f=N(a).toVar(),m=N(o).toVar(),g=N(s).toVar(),x=N(i).toVar(),w=N(r).toVar(),v=N(t).toVar(),E=N(e).toVar(),b=N(n).toVar(),S=y(Se(1,p)).toVar(),T=y(Se(1,h)).toVar();return y(Se(1,d)).toVar().mul(T.mul(b.mul(S).add(E.mul(p))).add(h.mul(v.mul(S).add(w.mul(p))))).add(d.mul(T.mul(x.mul(S).add(g.mul(p))).add(h.mul(m.mul(S).add(f.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"}]}),QR=Xt([V2,G2]),z2=_(([n,e,t])=>{let r=y(t).toVar(),i=y(e).toVar(),s=k(n).toVar(),o=k(s.bitAnd(k(7))).toVar(),a=y(id(o.lessThan(k(4)),i,r)).toVar(),l=y(ce(2,id(o.lessThan(k(4)),r,i))).toVar();return cm(a,nr(o.bitAnd(k(1)))).add(cm(l,nr(o.bitAnd(k(2)))))}).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),$2=_(([n,e,t,r])=>{let i=y(r).toVar(),s=y(t).toVar(),o=y(e).toVar(),a=k(n).toVar(),l=k(a.bitAnd(k(15))).toVar(),u=y(id(l.lessThan(k(8)),o,s)).toVar(),c=y(id(l.lessThan(k(4)),s,id(l.equal(k(12)).or(l.equal(k(14))),o,i))).toVar();return cm(u,nr(l.bitAnd(k(1)))).add(cm(c,nr(l.bitAnd(k(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"}]}),Yt=Xt([z2,$2]),W2=_(([n,e,t])=>{let r=y(t).toVar(),i=y(e).toVar(),s=Nn(n).toVar();return N(Yt(s.x,i,r),Yt(s.y,i,r),Yt(s.z,i,r))}).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),H2=_(([n,e,t,r])=>{let i=y(r).toVar(),s=y(t).toVar(),o=y(e).toVar(),a=Nn(n).toVar();return N(Yt(a.x,o,s,i),Yt(a.y,o,s,i),Yt(a.z,o,s,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"}]}),qi=Xt([W2,H2]),q2=_(([n])=>{let e=y(n).toVar();return ce(.6616,e)}).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),j2=_(([n])=>{let e=y(n).toVar();return ce(.982,e)}).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),X2=_(([n])=>{let e=N(n).toVar();return ce(.6616,e)}).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]}),ZR=Xt([q2,X2]),Y2=_(([n])=>{let e=N(n).toVar();return ce(.982,e)}).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]}),JR=Xt([j2,Y2]),wi=_(([n,e])=>{let t=A(e).toVar(),r=k(n).toVar();return r.shiftLeft(t).bitOr(r.shiftRight(A(32).sub(t)))}).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),eC=_(([n,e,t])=>{n.subAssign(t),n.bitXorAssign(wi(t,A(4))),t.addAssign(e),e.subAssign(n),e.bitXorAssign(wi(n,A(6))),n.addAssign(t),t.subAssign(e),t.bitXorAssign(wi(e,A(8))),e.addAssign(n),n.subAssign(t),n.bitXorAssign(wi(t,A(16))),t.addAssign(e),e.subAssign(n),e.bitXorAssign(wi(n,A(19))),n.addAssign(t),t.subAssign(e),t.bitXorAssign(wi(e,A(4))),e.addAssign(n)}),nd=_(([n,e,t])=>{let r=k(t).toVar(),i=k(e).toVar(),s=k(n).toVar();return r.bitXorAssign(i),r.subAssign(wi(i,A(14))),s.bitXorAssign(r),s.subAssign(wi(r,A(11))),i.bitXorAssign(s),i.subAssign(wi(s,A(25))),r.bitXorAssign(i),r.subAssign(wi(i,A(16))),s.bitXorAssign(r),s.subAssign(wi(r,A(4))),i.bitXorAssign(s),i.subAssign(wi(s,A(14))),r.bitXorAssign(i),r.subAssign(wi(i,A(24))),r}).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),Rr=_(([n])=>{let e=k(n).toVar();return y(e).div(y(k(A(4294967295))))}).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),qs=_(([n])=>{let e=y(n).toVar();return e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10))}).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),K2=_(([n])=>{let e=A(n).toVar(),t=k(k(1)).toVar(),r=k(k(A(3735928559)).add(t.shiftLeft(k(2))).add(k(13))).toVar();return nd(r.add(k(e)),r,r)}).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),Q2=_(([n,e])=>{let t=A(e).toVar(),r=A(n).toVar(),i=k(k(2)).toVar(),s=k().toVar(),o=k().toVar(),a=k().toVar();return s.assign(o.assign(a.assign(k(A(3735928559)).add(i.shiftLeft(k(2))).add(k(13))))),s.addAssign(k(r)),o.addAssign(k(t)),nd(s,o,a)}).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Z2=_(([n,e,t])=>{let r=A(t).toVar(),i=A(e).toVar(),s=A(n).toVar(),o=k(k(3)).toVar(),a=k().toVar(),l=k().toVar(),u=k().toVar();return a.assign(l.assign(u.assign(k(A(3735928559)).add(o.shiftLeft(k(2))).add(k(13))))),a.addAssign(k(s)),l.addAssign(k(i)),u.addAssign(k(r)),nd(a,l,u)}).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),J2=_(([n,e,t,r])=>{let i=A(r).toVar(),s=A(t).toVar(),o=A(e).toVar(),a=A(n).toVar(),l=k(k(4)).toVar(),u=k().toVar(),c=k().toVar(),d=k().toVar();return u.assign(c.assign(d.assign(k(A(3735928559)).add(l.shiftLeft(k(2))).add(k(13))))),u.addAssign(k(a)),c.addAssign(k(o)),d.addAssign(k(s)),eC(u,c,d),u.addAssign(k(i)),nd(u,c,d)}).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"}]}),eU=_(([n,e,t,r,i])=>{let s=A(i).toVar(),o=A(r).toVar(),a=A(t).toVar(),l=A(e).toVar(),u=A(n).toVar(),c=k(k(5)).toVar(),d=k().toVar(),h=k().toVar(),p=k().toVar();return d.assign(h.assign(p.assign(k(A(3735928559)).add(c.shiftLeft(k(2))).add(k(13))))),d.addAssign(k(u)),h.addAssign(k(l)),p.addAssign(k(a)),eC(d,h,p),d.addAssign(k(o)),h.addAssign(k(s)),nd(d,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"}]}),Ye=Xt([K2,Q2,Z2,J2,eU]),tU=_(([n,e])=>{let t=A(e).toVar(),r=A(n).toVar(),i=k(Ye(r,t)).toVar(),s=Nn().toVar();return s.x.assign(i.bitAnd(A(255))),s.y.assign(i.shiftRight(A(8)).bitAnd(A(255))),s.z.assign(i.shiftRight(A(16)).bitAnd(A(255))),s}).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),rU=_(([n,e,t])=>{let r=A(t).toVar(),i=A(e).toVar(),s=A(n).toVar(),o=k(Ye(s,i,r)).toVar(),a=Nn().toVar();return a.x.assign(o.bitAnd(A(255))),a.y.assign(o.shiftRight(A(8)).bitAnd(A(255))),a.z.assign(o.shiftRight(A(16)).bitAnd(A(255))),a}).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),ji=Xt([tU,rU]),iU=_(([n])=>{let e=V(n).toVar(),t=A().toVar(),r=A().toVar(),i=y(lt(e.x,t)).toVar(),s=y(lt(e.y,r)).toVar(),o=y(qs(i)).toVar(),a=y(qs(s)).toVar(),l=y(KR(Yt(Ye(t,r),i,s),Yt(Ye(t.add(A(1)),r),i.sub(1),s),Yt(Ye(t,r.add(A(1))),i,s.sub(1)),Yt(Ye(t.add(A(1)),r.add(A(1))),i.sub(1),s.sub(1)),o,a)).toVar();return ZR(l)}).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),sU=_(([n])=>{let e=N(n).toVar(),t=A().toVar(),r=A().toVar(),i=A().toVar(),s=y(lt(e.x,t)).toVar(),o=y(lt(e.y,r)).toVar(),a=y(lt(e.z,i)).toVar(),l=y(qs(s)).toVar(),u=y(qs(o)).toVar(),c=y(qs(a)).toVar(),d=y(QR(Yt(Ye(t,r,i),s,o,a),Yt(Ye(t.add(A(1)),r,i),s.sub(1),o,a),Yt(Ye(t,r.add(A(1)),i),s,o.sub(1),a),Yt(Ye(t.add(A(1)),r.add(A(1)),i),s.sub(1),o.sub(1),a),Yt(Ye(t,r,i.add(A(1))),s,o,a.sub(1)),Yt(Ye(t.add(A(1)),r,i.add(A(1))),s.sub(1),o,a.sub(1)),Yt(Ye(t,r.add(A(1)),i.add(A(1))),s,o.sub(1),a.sub(1)),Yt(Ye(t.add(A(1)),r.add(A(1)),i.add(A(1))),s.sub(1),o.sub(1),a.sub(1)),l,u,c)).toVar();return JR(d)}).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]}),dm=Xt([iU,sU]),nU=_(([n])=>{let e=V(n).toVar(),t=A().toVar(),r=A().toVar(),i=y(lt(e.x,t)).toVar(),s=y(lt(e.y,r)).toVar(),o=y(qs(i)).toVar(),a=y(qs(s)).toVar(),l=N(KR(qi(ji(t,r),i,s),qi(ji(t.add(A(1)),r),i.sub(1),s),qi(ji(t,r.add(A(1))),i,s.sub(1)),qi(ji(t.add(A(1)),r.add(A(1))),i.sub(1),s.sub(1)),o,a)).toVar();return ZR(l)}).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),oU=_(([n])=>{let e=N(n).toVar(),t=A().toVar(),r=A().toVar(),i=A().toVar(),s=y(lt(e.x,t)).toVar(),o=y(lt(e.y,r)).toVar(),a=y(lt(e.z,i)).toVar(),l=y(qs(s)).toVar(),u=y(qs(o)).toVar(),c=y(qs(a)).toVar(),d=N(QR(qi(ji(t,r,i),s,o,a),qi(ji(t.add(A(1)),r,i),s.sub(1),o,a),qi(ji(t,r.add(A(1)),i),s,o.sub(1),a),qi(ji(t.add(A(1)),r.add(A(1)),i),s.sub(1),o.sub(1),a),qi(ji(t,r,i.add(A(1))),s,o,a.sub(1)),qi(ji(t.add(A(1)),r,i.add(A(1))),s.sub(1),o,a.sub(1)),qi(ji(t,r.add(A(1)),i.add(A(1))),s,o.sub(1),a.sub(1)),qi(ji(t.add(A(1)),r.add(A(1)),i.add(A(1))),s.sub(1),o.sub(1),a.sub(1)),l,u,c)).toVar();return JR(d)}).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),cu=Xt([nU,oU]),aU=_(([n])=>{let e=y(n).toVar(),t=A(Pt(e)).toVar();return Rr(Ye(t))}).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),lU=_(([n])=>{let e=V(n).toVar(),t=A(Pt(e.x)).toVar(),r=A(Pt(e.y)).toVar();return Rr(Ye(t,r))}).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),uU=_(([n])=>{let e=N(n).toVar(),t=A(Pt(e.x)).toVar(),r=A(Pt(e.y)).toVar(),i=A(Pt(e.z)).toVar();return Rr(Ye(t,r,i))}).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),cU=_(([n])=>{let e=X(n).toVar(),t=A(Pt(e.x)).toVar(),r=A(Pt(e.y)).toVar(),i=A(Pt(e.z)).toVar(),s=A(Pt(e.w)).toVar();return Rr(Ye(t,r,i,s))}).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]}),tC=Xt([aU,lU,uU,cU]),dU=_(([n])=>{let e=y(n).toVar(),t=A(Pt(e)).toVar();return N(Rr(Ye(t,A(0))),Rr(Ye(t,A(1))),Rr(Ye(t,A(2))))}).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),hU=_(([n])=>{let e=V(n).toVar(),t=A(Pt(e.x)).toVar(),r=A(Pt(e.y)).toVar();return N(Rr(Ye(t,r,A(0))),Rr(Ye(t,r,A(1))),Rr(Ye(t,r,A(2))))}).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),pU=_(([n])=>{let e=N(n).toVar(),t=A(Pt(e.x)).toVar(),r=A(Pt(e.y)).toVar(),i=A(Pt(e.z)).toVar();return N(Rr(Ye(t,r,i,A(0))),Rr(Ye(t,r,i,A(1))),Rr(Ye(t,r,i,A(2))))}).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),fU=_(([n])=>{let e=X(n).toVar(),t=A(Pt(e.x)).toVar(),r=A(Pt(e.y)).toVar(),i=A(Pt(e.z)).toVar(),s=A(Pt(e.w)).toVar();return N(Rr(Ye(t,r,i,s,A(0))),Rr(Ye(t,r,i,s,A(1))),Rr(Ye(t,r,i,s,A(2))))}).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]}),hm=Xt([dU,hU,pU,fU]),sd=_(([n,e,t,r])=>{let i=y(r).toVar(),s=y(t).toVar(),o=A(e).toVar(),a=N(n).toVar(),l=y(0).toVar(),u=y(1).toVar();return Ee(o,()=>{l.addAssign(u.mul(dm(a))),u.mulAssign(i),a.mulAssign(s)}),l}).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"}]}),od=_(([n,e,t,r])=>{let i=y(r).toVar(),s=y(t).toVar(),o=A(e).toVar(),a=N(n).toVar(),l=N(0).toVar(),u=y(1).toVar();return Ee(o,()=>{l.addAssign(u.mul(cu(a))),u.mulAssign(i),a.mulAssign(s)}),l}).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"}]}),rC=_(([n,e,t,r])=>{let i=y(r).toVar(),s=y(t).toVar(),o=A(e).toVar(),a=N(n).toVar();return V(sd(a,o,s,i),sd(a.add(N(A(19),A(193),A(17))),o,s,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"}]}),iC=_(([n,e,t,r])=>{let i=y(r).toVar(),s=y(t).toVar(),o=A(e).toVar(),a=N(n).toVar(),l=N(od(a,o,s,i)).toVar(),u=y(sd(a.add(N(A(19),A(193),A(17))),o,s,i)).toVar();return X(l,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"}]}),mU=_(([n,e,t,r,i,s,o])=>{let a=A(o).toVar(),l=y(s).toVar(),u=A(i).toVar(),c=A(r).toVar(),d=A(t).toVar(),h=A(e).toVar(),p=V(n).toVar(),f=N(hm(V(h.add(c),d.add(u)))).toVar(),m=V(f.x,f.y).toVar();m.subAssign(.5),m.mulAssign(l),m.addAssign(.5);let g=V(V(y(h),y(d)).add(m)).toVar(),x=V(g.sub(p)).toVar();return ie(a.equal(A(2)),()=>Ue(x.x).add(Ue(x.y))),ie(a.equal(A(3)),()=>Ie(Ue(x.x),Ue(x.y))),ar(x,x)}).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"}]}),gU=_(([n,e,t,r,i,s,o,a,l])=>{let u=A(l).toVar(),c=y(a).toVar(),d=A(o).toVar(),h=A(s).toVar(),p=A(i).toVar(),f=A(r).toVar(),m=A(t).toVar(),g=A(e).toVar(),x=N(n).toVar(),w=N(hm(N(g.add(p),m.add(h),f.add(d)))).toVar();w.subAssign(.5),w.mulAssign(c),w.addAssign(.5);let v=N(N(y(g),y(m),y(f)).add(w)).toVar(),E=N(v.sub(x)).toVar();return ie(u.equal(A(2)),()=>Ue(E.x).add(Ue(E.y)).add(Ue(E.z))),ie(u.equal(A(3)),()=>Ie(Ue(E.x),Ue(E.y),Ue(E.z))),ar(E,E)}).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"}]}),du=Xt([mU,gU]),xU=_(([n,e,t])=>{let r=A(t).toVar(),i=y(e).toVar(),s=V(n).toVar(),o=A().toVar(),a=A().toVar(),l=V(lt(s.x,o),lt(s.y,a)).toVar(),u=y(1e6).toVar();return Ee({start:-1,end:A(1),name:"x",condition:"<="},({x:c})=>{Ee({start:-1,end:A(1),name:"y",condition:"<="},({y:d})=>{let h=y(du(l,c,d,o,a,i,r)).toVar();u.assign(ht(u,h))})}),ie(r.equal(A(0)),()=>{u.assign(Ct(u))}),u}).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),yU=_(([n,e,t])=>{let r=A(t).toVar(),i=y(e).toVar(),s=V(n).toVar(),o=A().toVar(),a=A().toVar(),l=V(lt(s.x,o),lt(s.y,a)).toVar(),u=V(1e6,1e6).toVar();return Ee({start:-1,end:A(1),name:"x",condition:"<="},({x:c})=>{Ee({start:-1,end:A(1),name:"y",condition:"<="},({y:d})=>{let h=y(du(l,c,d,o,a,i,r)).toVar();ie(h.lessThan(u.x),()=>{u.y.assign(u.x),u.x.assign(h)}).ElseIf(h.lessThan(u.y),()=>{u.y.assign(h)})})}),ie(r.equal(A(0)),()=>{u.assign(Ct(u))}),u}).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),bU=_(([n,e,t])=>{let r=A(t).toVar(),i=y(e).toVar(),s=V(n).toVar(),o=A().toVar(),a=A().toVar(),l=V(lt(s.x,o),lt(s.y,a)).toVar(),u=N(1e6,1e6,1e6).toVar();return Ee({start:-1,end:A(1),name:"x",condition:"<="},({x:c})=>{Ee({start:-1,end:A(1),name:"y",condition:"<="},({y:d})=>{let h=y(du(l,c,d,o,a,i,r)).toVar();ie(h.lessThan(u.x),()=>{u.z.assign(u.y),u.y.assign(u.x),u.x.assign(h)}).ElseIf(h.lessThan(u.y),()=>{u.z.assign(u.y),u.y.assign(h)}).ElseIf(h.lessThan(u.z),()=>{u.z.assign(h)})})}),ie(r.equal(A(0)),()=>{u.assign(Ct(u))}),u}).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),_U=_(([n,e,t])=>{let r=A(t).toVar(),i=y(e).toVar(),s=N(n).toVar(),o=A().toVar(),a=A().toVar(),l=A().toVar(),u=N(lt(s.x,o),lt(s.y,a),lt(s.z,l)).toVar(),c=y(1e6).toVar();return Ee({start:-1,end:A(1),name:"x",condition:"<="},({x:d})=>{Ee({start:-1,end:A(1),name:"y",condition:"<="},({y:h})=>{Ee({start:-1,end:A(1),name:"z",condition:"<="},({z:p})=>{let f=y(du(u,d,h,p,o,a,l,i,r)).toVar();c.assign(ht(c,f))})})}),ie(r.equal(A(0)),()=>{c.assign(Ct(c))}),c}).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),sC=Xt([xU,_U]),TU=_(([n,e,t])=>{let r=A(t).toVar(),i=y(e).toVar(),s=N(n).toVar(),o=A().toVar(),a=A().toVar(),l=A().toVar(),u=N(lt(s.x,o),lt(s.y,a),lt(s.z,l)).toVar(),c=V(1e6,1e6).toVar();return Ee({start:-1,end:A(1),name:"x",condition:"<="},({x:d})=>{Ee({start:-1,end:A(1),name:"y",condition:"<="},({y:h})=>{Ee({start:-1,end:A(1),name:"z",condition:"<="},({z:p})=>{let f=y(du(u,d,h,p,o,a,l,i,r)).toVar();ie(f.lessThan(c.x),()=>{c.y.assign(c.x),c.x.assign(f)}).ElseIf(f.lessThan(c.y),()=>{c.y.assign(f)})})})}),ie(r.equal(A(0)),()=>{c.assign(Ct(c))}),c}).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),nC=Xt([yU,TU]),SU=_(([n,e,t])=>{let r=A(t).toVar(),i=y(e).toVar(),s=N(n).toVar(),o=A().toVar(),a=A().toVar(),l=A().toVar(),u=N(lt(s.x,o),lt(s.y,a),lt(s.z,l)).toVar(),c=N(1e6,1e6,1e6).toVar();return Ee({start:-1,end:A(1),name:"x",condition:"<="},({x:d})=>{Ee({start:-1,end:A(1),name:"y",condition:"<="},({y:h})=>{Ee({start:-1,end:A(1),name:"z",condition:"<="},({z:p})=>{let f=y(du(u,d,h,p,o,a,l,i,r)).toVar();ie(f.lessThan(c.x),()=>{c.z.assign(c.y),c.y.assign(c.x),c.x.assign(f)}).ElseIf(f.lessThan(c.y),()=>{c.z.assign(c.y),c.y.assign(f)}).ElseIf(f.lessThan(c.z),()=>{c.z.assign(f)})})})}),ie(r.equal(A(0)),()=>{c.assign(Ct(c))}),c}).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),pm=Xt([bU,SU]),oC=_(([n,e,t,r,i,s,o,a,l,u,c])=>{let d=A(n).toVar(),h=V(e).toVar(),p=V(t).toVar(),f=V(r).toVar(),m=y(i).toVar(),g=y(s).toVar(),x=y(o).toVar(),w=nr(a).toVar(),v=A(l).toVar(),E=y(u).toVar(),b=y(c).toVar(),S=h.mul(p).add(f),T=y(0).toVar();return ie(d.equal(A(0)),()=>{T.assign(cu(S))}),ie(d.equal(A(1)),()=>{T.assign(hm(S))}),ie(d.equal(A(2)),()=>{T.assign(pm(S,m,A(0)))}),ie(d.equal(A(3)),()=>{T.assign(od(N(S,0),v,E,b))}),T.assign(T.mul(x.sub(g)).add(g)),ie(w,()=>{T.assign(ur(T,g,x))}),T}).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"}]}),aC=_(([n,e,t,r,i,s,o,a,l,u,c])=>{let d=A(n).toVar(),h=N(e).toVar(),p=N(t).toVar(),f=N(r).toVar(),m=y(i).toVar(),g=y(s).toVar(),x=y(o).toVar(),w=nr(a).toVar(),v=A(l).toVar(),E=y(u).toVar(),b=y(c).toVar(),S=h.mul(p).add(f),T=y(0).toVar();return ie(d.equal(A(0)),()=>{T.assign(cu(S))}),ie(d.equal(A(1)),()=>{T.assign(hm(S))}),ie(d.equal(A(2)),()=>{T.assign(pm(S,m,A(0)))}),ie(d.equal(A(3)),()=>{T.assign(od(S,v,E,b))}),T.assign(T.mul(x.sub(g)).add(g)),ie(w,()=>{T.assign(ur(T,g,x))}),T}).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"}]});var lC=_(([n])=>{let e=n.y,t=n.z,r=N().toVar();return ie(e.lessThan(1e-4),()=>{r.assign(N(t,t,t))}).Else(()=>{let i=n.x;i=i.sub(Vr(i)).mul(6).toVar();let s=A(Tp(i)),o=i.sub(y(s)),a=t.mul(e.oneMinus()),l=t.mul(e.mul(o).oneMinus()),u=t.mul(e.mul(o.oneMinus()).oneMinus());ie(s.equal(A(0)),()=>{r.assign(N(t,u,a))}).ElseIf(s.equal(A(1)),()=>{r.assign(N(l,t,a))}).ElseIf(s.equal(A(2)),()=>{r.assign(N(a,t,u))}).ElseIf(s.equal(A(3)),()=>{r.assign(N(a,l,t))}).ElseIf(s.equal(A(4)),()=>{r.assign(N(u,a,t))}).Else(()=>{r.assign(N(t,a,l))})}),r}).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),uC=_(([n])=>{let e=N(n).toVar(),t=y(e.x).toVar(),r=y(e.y).toVar(),i=y(e.z).toVar(),s=y(ht(t,ht(r,i))).toVar(),o=y(Ie(t,Ie(r,i))).toVar(),a=y(o.sub(s)).toVar(),l=y().toVar(),u=y().toVar(),c=y().toVar();return c.assign(o),ie(o.greaterThan(0),()=>{u.assign(a.div(o))}).Else(()=>{u.assign(0)}),ie(u.lessThanEqual(0),()=>{l.assign(0)}).Else(()=>{ie(t.greaterThanEqual(o),()=>{l.assign(r.sub(i).div(a))}).ElseIf(r.greaterThanEqual(o),()=>{l.assign(Xe(2,i.sub(t).div(a)))}).Else(()=>{l.assign(Xe(4,t.sub(r).div(a)))}),l.mulAssign(1/6),ie(l.lessThan(0),()=>{l.addAssign(1)})}),N(l,u,c)}).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]});var cC=_(([n])=>{let e=N(n).toVar(),t=op(mp(e,N(.04045))).toVar(),r=N(e.div(12.92)).toVar(),i=N(lr(Ie(e.add(N(.055)),N(0)).div(1.055),N(2.4))).toVar();return xe(r,i,t)}).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]});var dC=(n,e)=>{n=y(n),e=y(e);let t=V(e.dFdx(),e.dFdy()).length().mul(.7071067811865476);return Wt(n.sub(t),n.add(t),e)},hC=(n,e,t,r)=>xe(n,e,t[r].clamp()),NU=(n,e,t=Re())=>hC(n,e,t,"x"),wU=(n,e,t=Re())=>hC(n,e,t,"y"),MU=(n,e,t,r,i=Re())=>{let s=i.x.clamp(),o=i.y.clamp(),a=xe(n,e,s),l=xe(t,r,s);return xe(a,l,o)},pC=(n,e,t,r,i)=>xe(n,e,dC(t,r[i])),vU=(n,e,t,r=Re())=>pC(n,e,t,r,"x"),AU=(n,e,t,r=Re())=>pC(n,e,t,r,"y"),RU=(n=1,e=0,t=Re())=>t.mul(n).add(e),CU=(n,e=1)=>(n=y(n),n.abs().pow(e).mul(n.sign())),EU=(n,e=1,t=.5)=>y(n).sub(t).mul(e).add(t),BU=(n=Re(),e=1,t=0)=>dm(n.convert("vec2|vec3")).mul(e).add(t),FU=(n=Re(),e=1,t=0)=>cu(n.convert("vec2|vec3")).mul(e).add(t),LU=(n=Re(),e=1,t=0)=>(n=n.convert("vec2|vec3"),X(cu(n),dm(n.add(V(19,73)))).mul(e).add(t)),PU=(n,e=Re(),t=V(1,1),r=V(0,0),i=1,s=0,o=1,a=!1,l=1,u=2,c=.5)=>oC(n,e.convert("vec2|vec3"),t,r,i,s,o,a,l,u,c),DU=(n,e=Re(),t=V(1,1),r=V(0,0),i=1,s=0,o=1,a=!1,l=1,u=2,c=.5)=>aC(n,e.convert("vec2|vec3"),t,r,i,s,o,a,l,u,c),UU=(n=Re(),e=1)=>sC(n.convert("vec2|vec3"),e,A(1)),IU=(n=Re(),e=1)=>nC(n.convert("vec2|vec3"),e,A(1)),fC=(n=Re(),e=1)=>pm(n.convert("vec2|vec3"),e,A(1)),OU=(n=Re())=>tC(n.convert("vec2|vec3")),kU=(n=Re(),e=3,t=2,r=.5,i=1)=>sd(n,A(e),t,r).mul(i),VU=(n=Re(),e=3,t=2,r=.5,i=1)=>rC(n,A(e),t,r).mul(i),mC=(n=Re(),e=3,t=2,r=.5,i=1)=>od(n,A(e),t,r).mul(i),GU=(n=Re(),e=3,t=2,r=.5,i=1)=>iC(n,A(e),t,r).mul(i);var zU=(n,e=y(0))=>Xe(n,e),$U=(n,e=y(0))=>Se(n,e),WU=(n,e=y(1))=>ce(n,e),HU=(n,e=y(1))=>xt(n,e),qU=(n,e=y(1))=>Vl(n,e),jU=(n,e=y(1))=>lr(n,e),XU=(n=y(0),e=y(1))=>xp(n,e),YU=()=>wo,KU=()=>x_,QU=(n,e=y(1))=>Se(e,n),ZU=(n,e,t,r)=>n.greaterThan(e).mix(t,r),JU=(n,e,t,r)=>n.greaterThanEqual(e).mix(t,r),eI=(n,e,t,r)=>n.equal(e).mix(t,r),tI=(n,e=null)=>{if(typeof e=="string"){let t={x:0,r:0,y:1,g:1,z:2,b:2,w:3,a:3},r=e.replace(/^out/,"").toLowerCase();if(t[r]!==void 0)return n.element(t[r])}if(typeof e=="number")return n.element(e);if(typeof e=="string"&&e.length===1){let t={x:0,r:0,y:1,g:1,z:2,b:2,w:3,a:3};if(t[e]!==void 0)return n.element(t[e])}return n},rI=(n,e=V(.5,.5),t=V(1,1),r=y(0),i=V(0,0))=>{let s=n;if(e&&(s=s.sub(e)),t&&(s=s.mul(t)),r){let o=r.mul(Math.PI/180),a=o.cos(),l=o.sin();s=V(s.x.mul(a).sub(s.y.mul(l)),s.x.mul(l).add(s.y.mul(a)))}return e&&(s=s.add(e)),i&&(s=s.add(i)),s},iI=(n,e)=>{n=V(n),e=y(e);let t=e.mul(Math.PI/180);return En(n,t)},sI=(n,e,t)=>{n=N(n),e=y(e),t=N(t);let r=e.mul(Math.PI/180),i=t.normalize(),s=r.cos(),o=r.sin(),a=y(1).sub(s);return n.mul(s).add(i.cross(n).mul(o)).add(i.mul(i.dot(n)).mul(a))},nI=(n,e)=>(n=N(n),e=y(e),vc(n,e));var oI=_(([n,e,t])=>{let r=_t(n).toVar(),i=e.mul(.5).add(t).sub(vr).div(r).toVar(),s=e.mul(-.5).add(t).sub(vr).div(r).toVar(),o=N().toVar();o.x=r.x.greaterThan(y(0)).select(i.x,s.x),o.y=r.y.greaterThan(y(0)).select(i.y,s.y),o.z=r.z.greaterThan(y(0)).select(i.z,s.z);let a=ht(o.x,o.y,o.z).toVar();return vr.add(r.mul(a)).toVar().sub(t)}),gC=oI;var aI=_(([n,e])=>{let t=n.x,r=n.y,i=n.z,s=e.element(0).mul(.886227);return s=s.add(e.element(1).mul(2*.511664).mul(r)),s=s.add(e.element(2).mul(2*.511664).mul(i)),s=s.add(e.element(3).mul(2*.511664).mul(t)),s=s.add(e.element(4).mul(2*.429043).mul(t).mul(r)),s=s.add(e.element(5).mul(2*.429043).mul(r).mul(i)),s=s.add(e.element(6).mul(i.mul(i).mul(.743125).sub(.247708))),s=s.add(e.element(7).mul(2*.429043).mul(t).mul(i)),s=s.add(e.element(8).mul(.429043).mul(ce(t,t).sub(ce(r,r)))),s}),fm=aI;var ds=new iu,TT=class extends Ar{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,r){let i=this.renderer,s=this.nodes.getBackgroundNode(e)||e.background,o=!1;if(s===null)i._clearColor.getRGB(ds),ds.a=i._clearColor.a;else if(s.isColor===!0)s.getRGB(ds),ds.a=1,o=!0;else if(s.isNode===!0){let l=this.get(e),u=s;ds.copy(i._clearColor);let c=l.backgroundMesh;if(c===void 0){let v=function(){s.removeEventListener("dispose",v),c.material.dispose(),c.geometry.dispose()},h=X(u).mul(Wf).context({getUV:()=>B_.mul(vy),getTextureLevel:()=>E_}),p=zr.element(3).element(3).equal(1),f=xt(1,zr.element(1).element(1)).mul(3),m=p.select(Le.mul(f),Le),g=$r.mul(X(m,0)),x=zr.mul(X(g.xyz,1));x=x.setZ(x.w);let w=new we;w.name="Background.material",w.side=Ze,w.depthTest=!1,w.depthWrite=!1,w.allowOverride=!1,w.fog=!1,w.lights=!1,w.vertexNode=x,w.colorNode=h,l.backgroundMeshNode=h,l.backgroundMesh=c=new sr(new Ah(1,32,32),w),c.frustumCulled=!1,c.name="Background.mesh",s.addEventListener("dispose",v)}let d=u.getCacheKey();l.backgroundCacheKey!==d&&(l.backgroundMeshNode.node=X(u).mul(Wf),l.backgroundMeshNode.needsUpdate=!0,c.material.needsUpdate=!0,l.backgroundCacheKey=d),t.unshift(c,c.geometry,c.material,0,0,null,null)}else I("Renderer: Unsupported background configuration.",s);let a=i.xr.getEnvironmentBlendMode();if(a==="additive"?ds.set(0,0,0,1):a==="alpha-blend"&&ds.set(0,0,0,0),i.autoClear===!0||o===!0){let l=r.clearColorValue;l.r=ds.r,l.g=ds.g,l.b=ds.b,l.a=ds.a,(i.backend.isWebGLBackend===!0||i.alpha===!0)&&(l.r*=l.a,l.g*=l.a,l.b*=l.a),r.depthClearValue=i.getClearDepth(),r.stencilClearValue=i.getClearStencil(),r.clearColor=i.autoClearColor===!0,r.clearDepth=i.autoClearDepth===!0,r.clearStencil=i.autoClearStencil===!0}else r.clearColor=!1,r.clearDepth=!1,r.clearStencil=!1}},xC=TT;var lI=0,ST=class{constructor(e="",t=[]){this.name=e,this.bindings=t,this.id=lI++}},ad=ST;var NT=class{constructor(e,t,r,i,s,o,a,l,u,c,d=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=r,this.transforms=d,this.nodeAttributes=i,this.bindings=s,this.updateNodes=o,this.updateBeforeNodes=a,this.updateAfterNodes=l,this.observer=u,this.hardwareClipping=c,this.usedTimes=0}createBindings(){let e=[];for(let t of this.bindings)if(t.bindings[0].groupNode.shared!==!0){let i=new ad(t.name,[]);e.push(i);for(let s of t.bindings)i.bindings.push(s.clone())}else e.push(t);return e}},gm=NT;var wT=class{constructor(e,t,r=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=r}},xm=wT;var MT=class{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}},vT=MT;var AT=class{constructor(e,t,r=!1,i=null){this.isNodeVar=!0,this.name=e,this.type=t,this.readOnly=r,this.count=i}},ld=AT;var RT=class extends ld{constructor(e,t,r=null,i=null){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0,this.interpolationType=r,this.interpolationSampling=i}},CT=RT;var ET=class{constructor(e,t,r=""){this.name=e,this.type=t,this.code=r,Object.defineProperty(this,"isNodeCode",{value:!0})}},BT=ET;var uI=0,FT=class{constructor(e=null){this.id=uI++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return t===void 0&&this.parent!==null&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}},ud=FT;var LT=class{constructor(e,t){this.name=e,this.members=t,this.output=!1}},yC=LT;var js=class{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}},ym=class extends js{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}},bm=class extends js{constructor(e,t=new se){super(e,t),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}},_m=class extends js{constructor(e,t=new C){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}},Tm=class extends js{constructor(e,t=new pe){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}},Sm=class extends js{constructor(e,t=new le){super(e,t),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}},Nm=class extends js{constructor(e,t=new El){super(e,t),this.isMatrix2Uniform=!0,this.boundary=8,this.itemSize=4}},wm=class extends js{constructor(e,t=new et){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}},Mm=class extends js{constructor(e,t=new ue){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}};var vm=class extends ym{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Am=class extends bm{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Rm=class extends _m{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Cm=class extends Tm{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Em=class extends Sm{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Bm=class extends Nm{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Fm=class extends wm{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Lm=class extends Mm{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}};var cI=0,bC=new WeakMap,_C=new WeakMap,dI=new WeakMap,hI=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),Pm=n=>/e/g.test(n)?String(n).replace(/\+/g,""):(n=Number(n),n+(n%1?"":".0")),TC=n=>{if(n.writeUsageCount>0)return!0;if(n.subBuildsCache!==void 0){for(let e in n.subBuildsCache)if(TC(n.subBuildsCache[e]))return!0}return!1},PT=class{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=new Set,this.sequentialNodes=new Set,this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.observer=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.hardwareClipping=!1,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=Wc(),this.stacks=[],this.tab=" ",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new ud,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:cI++})}isFlatShading(){return this.material.flatShading===!0||this.geometry.hasAttribute("normal")===!1}isOpaque(){let e=this.material;return e.transparent===!1&&e.blending===Zt&&e.alphaToCoverage===!1}createRenderTarget(e,t,r){return new ct(e,t,r)}createCubeRenderTarget(e,t){return new pf(e,t)}includes(e){return this.nodes.has(e)}getOutputType(e=0){let t=this.renderer.getRenderTarget();return t!==null?Kh(t.textures[e]):"vec4"}getOutputStructName(){}_getBindGroup(e,t){let r=t[0].groupNode,i=r.shared;if(i)for(let o=1;o<t.length;o++)r!==t[o].groupNode&&(i=!1);let s;if(i){let o="";for(let c of t)if(c.isNodeUniformsGroup){c.uniforms.sort((d,h)=>d.nodeUniform.node.id-h.nodeUniform.node.id);for(let d of c.uniforms)o+=d.nodeUniform.node.id}else o+=c.nodeUniform.id;let a=this.renderer._currentRenderContext||this.renderer,l=bC.get(a);l===void 0&&(l=new Map,bC.set(a,l));let u=Ii(o);s=l.get(u),s===void 0&&(s=new ad(e,t),l.set(u,s))}else s=new ad(e,t);return s}getBindGroupArray(e,t){let r=this.bindings[t],i=r[e];return i===void 0&&(this.bindingsIndexes[e]===void 0&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),r[e]=i=[]),i}getBindings(){let e=this.bindGroups;if(e===null){let t={},r=this.bindings;for(let i of Yu)for(let s in r[i]){let o=r[i][s],a=t[s]||(t[s]=[]);for(let l of o)a.includes(l)===!1&&a.push(l)}e=[];for(let i in t){let s=t[i],o=this._getBindGroup(i,s);e.push(o)}this.bindGroups=e}return e}sortBindingGroups(){let e=this.getBindings();e.sort((t,r)=>t.bindings[0].groupNode.order-r.bindings[0].groupNode.order);for(let t=0;t<e.length;t++){let r=e[t];this.bindingsIndexes[r.name].group=t}}setHashNode(e,t){this.hashNodes[t]=e}addNode(e){this.nodes.has(e)===!1&&(this.nodes.add(e),this.setHashNode(e,e.getHash(this)))}addSequentialNode(e){let t=e.getUpdateBeforeType(),r=e.getUpdateAfterType();(t!==J.NONE||r!==J.NONE)&&this.sequentialNodes.add(e)}buildUpdateNodes(){for(let e of this.nodes)e.getUpdateType()!==J.NONE&&this.updateNodes.push(e);for(let e of this.sequentialNodes){let t=e.getUpdateBeforeType(),r=e.getUpdateAfterType();t!==J.NONE&&this.updateBeforeNodes.push(e),r!==J.NONE&&this.updateAfterNodes.push(e)}}get currentNode(){return this.chaining[this.chaining.length-1]}get renderPipeline(){return this.context.renderPipeline}isFilteredTexture(e){return e.magFilter===je||e.magFilter===Fu||e.magFilter===on||e.magFilter===Ur||e.minFilter===je||e.minFilter===Fu||e.minFilter===on||e.minFilter===Ur}getUniformBufferLimit(){return this.renderer.backend.capabilities.getUniformBufferLimit()}addChain(e){this.chaining.push(e)}removeChain(e){if(this.chaining.pop()!==e)throw new Error("THREE.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){let t=this.getContext();return this.setContext({...this.context,...e}),t}getSharedContext(){let 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){let r=this.getDataFromNode(e);return r.cache===void 0&&(r.cache=new ud(t?this.getCache():null)),r.cache}isAvailable(){return!1}getVertexIndex(){U("Abstract function.")}getInstanceIndex(){U("Abstract function.")}getDrawIndex(){U("Abstract function.")}getFrontFacing(){U("Abstract function.")}getFragCoord(){U("Abstract function.")}isFlipY(){return!1}isContextAssign(){return this.context.assign===!0}increaseUsage(e){let t=this.getDataFromNode(e);return t.usageCount=t.usageCount===void 0?1:t.usageCount+1,this.isContextAssign()?t.writeUsageCount=t.writeUsageCount===void 0?1:t.writeUsageCount+1:t.readUsageCount=t.readUsageCount===void 0?1:t.readUsageCount+1,t.usageCount}hasWriteUsage(e){let t=e.getShared(this),i=(t.isGlobal(this)?this.globalCache:this.cache).getData(t);if(i!==void 0){for(let s in i)if(TC(i[s]))return!0}return!1}generateTexture(){U("Abstract function.")}generateTextureLod(){U("Abstract function.")}generateTextureSize(){U("Abstract function.")}generateArrayDeclaration(e,t){return this.getType(e)+"[ "+t+" ]"}generateArray(e,t,r=null){let i=this.generateArrayDeclaration(e,t)+"( ";for(let s=0;s<t;s++){let o=r?r[s]:null;o!==null?i+=o.build(this,e):i+=this.generateConst(e),s<t-1&&(i+=", ")}return i+=" )",i}generateStruct(e,t,r=null){let i=[];for(let s of t){let{name:o,type:a}=s;r&&r[o]&&r[o].isNode?i.push(r[o].build(this,a)):i.push(this.generateConst(a))}return e+"( "+i.join(", ")+" )"}generateConst(e,t=null){if(t===null&&(e==="float"||e==="int"||e==="uint"?t=0:e==="bool"?t=!1:e==="color"?t=new le:e==="vec2"||e==="uvec2"||e==="ivec2"?t=new se:e==="vec3"||e==="uvec3"||e==="ivec3"?t=new C:(e==="vec4"||e==="uvec4"||e==="ivec4")&&(t=new pe)),e==="float")return Pm(t);if(e==="int")return`${Math.round(t)}`;if(e==="uint")return t>=0?`${Math.round(t)}u`:"0u";if(e==="bool")return t?"true":"false";if(e==="color")return`${this.getType("vec3")}( ${Pm(t.r)}, ${Pm(t.g)}, ${Pm(t.b)} )`;let r=this.getTypeLength(e),i=this.getComponentType(e),s=o=>this.generateConst(i,o);if(r===2)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)} )`;if(r===3)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)}, ${s(t.z)} )`;if(r===4&&e!=="mat2")return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)}, ${s(t.z)}, ${s(t.w)} )`;if(r>=4&&t&&(t.isMatrix2||t.isMatrix3||t.isMatrix4))return`${this.getType(e)}( ${t.elements.map(s).join(", ")} )`;if(r>4)return`${this.getType(e)}()`;throw new Error(`THREE.NodeBuilder: Type '${e}' not found in generate constant attempt.`)}getType(e){return e==="color"?"vec3":e}hasGeometryAttribute(e){return this.geometry&&this.geometry.getAttribute(e)!==void 0}getAttribute(e,t){let r=this.attributes;for(let s of r)if(s.name===e)return s;let i=new xm(e,t);return this.registerDeclaration(i),r.push(i),i}getPropertyName(e){return e.name}isReservedKeyword(){return!1}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return e==="void"||e==="property"||e==="sampler"||e==="samplerComparison"||e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="depthTexture"||e==="texture3D"}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){let t=e.type;return e.isDepthTexture===!0?"float":t===Je?"int":t===Ce?"uint":"float"}getElementType(e){return e==="mat2"?"vec2":e==="mat3"?"vec3":e==="mat4"?"vec4":this.getComponentType(e)}getComponentType(e){if(e=this.getVectorType(e),e==="float"||e==="bool"||e==="int"||e==="uint")return e;let t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return t===null?null:t[1]==="b"?"bool":t[1]==="i"?"int":t[1]==="u"?"uint":"float"}getVectorType(e){return e==="color"?"vec3":e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="texture3D"?"vec4":e}getTypeFromLength(e,t="float"){if(e===1)return t;let r=qu(e),i=t==="float"?"":t[0];return/mat2/.test(t)===!0&&(r=r.replace("vec","mat")),i+r}getTypeFromArray(e){return hI.get(e.constructor)}isInteger(e){return/int|uint|(i|u)vec/.test(e)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);let r=t.array,i=e.itemSize,s=e.normalized,o;return!(e instanceof Tl)&&s!==!0&&(o=this.getTypeFromArray(r)),this.getTypeFromLength(i,o)}getTypeLength(e){let t=this.getVectorType(e),r=/vec([2-4])/.exec(t);return r!==null?Number(r[1]):t==="float"||t==="bool"||t==="int"||t==="uint"?1:/mat2/.test(e)===!0?4:/mat3/.test(e)===!0?9:/mat4/.test(e)===!0?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){let t=this.getComponentType(e);return t==="int"||t==="uint"?e:this.changeComponentType(e,"int")}setActiveStack(e){this.activeStacks.push(e)}removeActiveStack(e){if(this.activeStacks[this.activeStacks.length-1]===e)this.activeStacks.pop();else throw new Error("THREE.NodeBuilder: Invalid active stack removal.")}getActiveStack(){return this.activeStacks[this.activeStacks.length-1]}getBaseStack(){return this.activeStacks[0]}addStack(){this.stack=Wc(this.stack);let e=ec();return this.stacks.push(e),Ba(this.stack),this.stack}removeStack(){let e=this.stack;for(let t of e.nodes){let r=this.getDataFromNode(t);r.stack=e}return this.stack=e.parent,Ba(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,r=null){r=r===null?e.isGlobal(this)?this.globalCache:this.cache:r;let i=r.getData(e);i===void 0&&(i={},r.setData(e,i)),i[t]===void 0&&(i[t]={});let s=i[t];if(this.subBuildLayers.length===0)return s;let o=i.any?i.any.subBuilds:null,a=this.getClosestSubBuild(o);return a&&(s.subBuildsCache===void 0&&(s.subBuildsCache={}),s=s.subBuildsCache[a]||(s.subBuildsCache[a]={}),s.subBuilds=o),s}getNodeProperties(e,t="any"){let r=this.getDataFromNode(e,t);return r.properties||(r.properties={outputNode:null})}getBufferAttributeFromNode(e,t,r=null){let i=this.getDataFromNode(e,"vertex"),s=i.bufferAttribute;if(s===void 0){let o=this.uniforms.index++;r===null&&(r="nodeAttribute"+o),s=new xm(r,t,e),this.bufferAttributes.push(s),i.bufferAttribute=s}return s}getStructTypeNode(e,t=this.shaderStage){return this.types[t][e]||null}getStructTypeFromNode(e,t,r=null,i=this.shaderStage){let s=this.getDataFromNode(e,i,this.globalCache),o=s.structType;if(o===void 0){let a=this.structs.index++;r===null&&(r="StructType"+a),o=new yC(r,t),this.structs[i].push(o),this.types[i][r]=e,s.structType=o}return o}getOutputStructTypeFromNode(e,t){let r=this.getStructTypeFromNode(e,t,"OutputType","fragment");return r.output=!0,r}getUniformFromNode(e,t,r=this.shaderStage,i=null){let s=this.getDataFromNode(e,r,this.globalCache),o=s.uniform;if(o===void 0){let a=this.uniforms.index++;o=new vT(i||"nodeUniform"+a,t,e),this.uniforms[r].push(o),this.registerDeclaration(o),s.uniform=o}return o}getVarFromNode(e,t=null,r=e.getNodeType(this),i=this.shaderStage,s=!1){let o=this.getDataFromNode(e,i),a=this.getSubBuildProperty("variable",o.subBuilds),l=o[a];if(l===void 0){let u=s?"_const":"_var",c=this.vars[i]||(this.vars[i]=[]),d=this.vars[u]||(this.vars[u]=0);t===null&&(t=(s?"nodeConst":"nodeVar")+d,this.vars[u]++),a!=="variable"&&(t=this.getSubBuildProperty(t,o.subBuilds));let h=e.getArrayCount(this);l=new ld(t,r,s,h),s||c.push(l),this.registerDeclaration(l),o[a]=l}return l}isDeterministic(e){if(e.isMathNode)return this.isDeterministic(e.aNode)&&(e.bNode?this.isDeterministic(e.bNode):!0)&&(e.cNode?this.isDeterministic(e.cNode):!0);if(e.isOperatorNode)return this.isDeterministic(e.aNode)&&(e.bNode?this.isDeterministic(e.bNode):!0);if(e.isArrayNode){if(e.values!==null){for(let t of e.values)if(!this.isDeterministic(t))return!1}return!0}else if(e.isConstNode)return!0;return!1}getVaryingFromNode(e,t=null,r=e.getNodeType(this),i=null,s=null){let o=this.getDataFromNode(e,"any"),a=this.getSubBuildProperty("varying",o.subBuilds),l=o[a];if(l===void 0){let u=this.varyings,c=u.length;t===null&&(t="nodeVarying"+c),a!=="varying"&&(t=this.getSubBuildProperty(t,o.subBuilds)),l=new CT(t,r,i,s),u.push(l),this.registerDeclaration(l),o[a]=l}return l}registerDeclaration(e){let t=this.shaderStage,r=this.declarations[t]||(this.declarations[t]={}),i=this.renderer.debug.diagnostics.keywords,s=e.name,o=s,a=this.getPropertyName(e),l=1;for(;i&&this.isReservedKeyword(o)||r[a]!==void 0;)o=s+"_"+l++,e.name=o,a=this.getPropertyName(e);o!==s&&U(`TSL: Declaration name '${s}' of '${e.type}' is a reserved keyword or already in use. Renamed to '${o}'.`),r[a]=e}getCodeFromNode(e,t,r=this.shaderStage){let i=this.getDataFromNode(e),s=i.code;if(s===void 0){let o=this.codes[r]||(this.codes[r]=[]),a=o.length;s=new BT("nodeCode"+a,t),o.push(s),i.code=s}return s}addFlowCodeHierarchy(e,t){let{flowCodes:r,flowCodeBlock:i}=this.getDataFromNode(e),s=!0,o=t;for(;o;){if(i.get(o)===!0){s=!1;break}o=this.getDataFromNode(o).parentNodeBlock}if(s)for(let a of r)this.addLineFlowCode(a)}addLineFlowCodeBlock(e,t,r){let i=this.getDataFromNode(e),s=i.flowCodes||(i.flowCodes=[]),o=i.flowCodeBlock||(i.flowCodeBlock=new WeakMap);s.push(t),o.set(r,!0)}addLineFlowCode(e,t=null){return e===""?this:(t!==null&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e=e+`; | |
| `),this.flow.code+=e,this)}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+=" ",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){let t=e.getNodeType(this),r=this.flowChildNode(e,t);return this.flowsData.set(e,r),r}addInclude(e){this.currentFunctionNode!==null&&this.currentFunctionNode.includes.push(e)}buildFunctionNode(e){let t=this.renderer.backend,r=_C.get(t);r===void 0&&(r=new WeakMap,_C.set(t,r));let i=r.get(e);if(i===void 0){i=new j_;let s=this.currentFunctionNode;this.currentFunctionNode=i,i.code=this.buildFunctionCode(e),this.currentFunctionNode=s,r.set(e,i)}return i}flowShaderNode(e){let t=e.layout,r={[Symbol.iterator](){let o=0,a=Object.values(this);return{next:()=>({value:a[o],done:o++>=a.length})}}};for(let o of t.inputs)r[o.name]=new s_(o.type,o.name);e.layout=null;let i=e.call(r),s=this.flowStagesNode(i,t.type);return e.layout=t,s}flowBuildStage(e,t,r=null){let i=this.getBuildStage();this.setBuildStage(t);let s=e.build(this,r);return this.setBuildStage(i),s}flowStagesNode(e,t=null){let r=this.flow,i=this.vars,s=this.declarations,o=this.cache,a=this.buildStage,l=this.stack,u={code:""};this.flow=u,this.vars={},this.declarations={},this.cache=new ud,this.stack=Wc();for(let c of Xu)this.setBuildStage(c),u.result=e.build(this,t);return u.vars=this.getVars(this.shaderStage),this.flow=r,this.vars=i,this.declarations=s,this.cache=o,this.stack=l,this.setBuildStage(a),u}getFunctionOperator(){return null}buildFunctionCode(){U("Abstract function.")}flowChildNode(e,t=null){let r=this.flow,i={code:""};return this.flow=i,i.result=e.build(this,t),this.flow=r,i}flowNodeFromShaderStage(e,t,r=null,i=null){let s=this.tab,o=this.cache,a=this.shaderStage,l=this.context;this.setShaderStage(e);let u={...this.context};delete u.nodeBlock,this.cache=this.globalCache,this.tab=" ",this.context=u;let c=null;if(this.buildStage==="generate"){let d=this.flowChildNode(t,r);i!==null&&(d.code+=`${this.tab+i} = ${d.result}; | |
| `),this.flowCode[e]=this.flowCode[e]+d.code,c=d}else c=t.build(this);return this.setShaderStage(a),this.cache=o,this.tab=s,this.context=l,c}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){U("Abstract function.")}getVaryings(){U("Abstract function.")}getVar(e,t,r=null){return`${r!==null?this.generateArrayDeclaration(e,r):this.getType(e)} ${t}`}getVars(e,t=!1){let r=[],i=this.vars[e];if(i!==void 0)for(let s of i)r.push(`${this.getVar(s.type,s.name,s.count)};`);return r.join(t?` | |
| `:` | |
| `)}getUniforms(){U("Abstract function.")}getCodes(e){let t=this.codes[e],r="";if(t!==void 0)for(let i of t)r+=i.code+` | |
| `;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(){U("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(e&&e.isNode?e.isShaderCallNodeInternal?t=e.shaderNode.subBuilds:e.isStackNode?t=[e.subBuild]:t=this.getDataFromNode(e,"any").subBuilds:e instanceof Set?t=[...e]:t=e,!t)return null;let r=this.subBuildLayers;for(let i=t.length-1;i>=0;i--){let s=t[i];if(r.includes(s))return s}return null}getSubBuildOutput(e){return this.getSubBuildProperty("outputNode",e)}getSubBuildProperty(e="",t=null){let r;t!==null?r=this.getClosestSubBuild(t):r=this.subBuildFn;let i;return r?i=e?r+"_"+e:r:i=e,i}prebuild(){let{object:e,renderer:t,material:r}=this;if(t.contextNode.isContextNode===!0?this.context={...this.context,...t.contextNode.getFlowContextData()}:I('NodeBuilder: "renderer.contextNode" must be an instance of `context()`.'),r&&r.contextNode&&(r.contextNode.isContextNode===!0?this.context={...this.context,...r.contextNode.getFlowContextData()}:I('NodeBuilder: "material.contextNode" must be an instance of `context()`.')),r!==null){let i=t.library.fromMaterial(r);i===null&&(I(`NodeBuilder: Material "${r.type}" is not compatible.`),i=new we),i.build(this)}else this.addFlow("compute",e)}build(){this.prebuild();for(let e of Xu){this.setBuildStage(e),this.context.position&&this.context.position.isNode&&this.flowNodeFromShaderStage("vertex",this.context.position);for(let t of Yu){this.setShaderStage(t);let r=this.flowNodes[t];for(let i of r)e==="generate"?this.flowNode(i):i.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}async buildAsync(){this.prebuild();for(let e of Xu){this.setBuildStage(e),this.context.position&&this.context.position.isNode&&this.flowNodeFromShaderStage("vertex",this.context.position);for(let t of Yu){this.setShaderStage(t);let r=this.flowNodes[t];for(let i of r)e==="generate"?this.flowNode(i):i.build(this);await Kd()}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getSharedDataFromNode(e){let t=dI.get(e);return t===void 0&&(t={}),t}getNodeUniform(e,t){let r=this.getSharedDataFromNode(e),i=r.cache;if(i===void 0){if(t==="float"||t==="int"||t==="uint")i=new vm(e);else if(t==="vec2"||t==="ivec2"||t==="uvec2")i=new Am(e);else if(t==="vec3"||t==="ivec3"||t==="uvec3")i=new Rm(e);else if(t==="vec4"||t==="ivec4"||t==="uvec4")i=new Cm(e);else if(t==="color")i=new Em(e);else if(t==="mat2")i=new Bm(e);else if(t==="mat3")i=new Fm(e);else if(t==="mat4")i=new Lm(e);else throw new Error(`THREE.NodeBuilder: Uniform "${t}" not implemented.`);r.cache=i}return i}format(e,t,r){if(t=this.getVectorType(t),r=this.getVectorType(r),t===r||r===null||this.isReference(r))return e;let i=this.getTypeLength(t),s=this.getTypeLength(r);return i===16&&s===9?`${this.getType(r)}( ${e}[ 0 ].xyz, ${e}[ 1 ].xyz, ${e}[ 2 ].xyz )`:i===9&&s===4?`${this.getType(r)}( ${e}[ 0 ].xy, ${e}[ 1 ].xy )`:i>4||s>4||s===0?e:i===s?`${this.getType(r)}( ${e} )`:i>s?(e=r==="bool"?`all( ${e} )`:`${e}.${"xyz".slice(0,s)}`,this.format(e,this.getTypeFromLength(s,this.getComponentType(t)),r)):s===4&&i>1?`${this.getType(r)}( ${this.format(e,t,"vec3")}, 1.0 )`:i===2?`${this.getType(r)}( ${this.format(e,t,"vec2")}, 0.0 )`:(i===1&&s>1&&t!==this.getComponentType(r)&&(e=`${this.getType(this.getComponentType(r))}( ${e} )`),`${this.getType(r)}( ${e} )`)}getSignature(){return`// Three.js r${tn} - Node System | |
| `}needsPreviousData(){let e=this.renderer.getMRT();return e&&e.has("velocity")||Qh(this.object).useVelocity===!0}},cd=PT;var DT=class{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 r===void 0&&(r={renderId:0,frameId:0},e.set(t,r)),r}updateBeforeNode(e){let t=e.getUpdateBeforeType(),r=e.updateReference(this);if(t===J.FRAME){let i=this._getMaps(this.updateBeforeMap,r);if(i.frameId!==this.frameId){let s=i.frameId;i.frameId=this.frameId,e.updateBefore(this)===!1&&(i.frameId=s)}}else if(t===J.RENDER){let i=this._getMaps(this.updateBeforeMap,r);if(i.renderId!==this.renderId){let s=i.renderId;i.renderId=this.renderId,e.updateBefore(this)===!1&&(i.renderId=s)}}else t===J.OBJECT&&e.updateBefore(this)}updateAfterNode(e){let t=e.getUpdateAfterType(),r=e.updateReference(this);if(t===J.FRAME){let i=this._getMaps(this.updateAfterMap,r);i.frameId!==this.frameId&&e.updateAfter(this)!==!1&&(i.frameId=this.frameId)}else if(t===J.RENDER){let i=this._getMaps(this.updateAfterMap,r);i.renderId!==this.renderId&&e.updateAfter(this)!==!1&&(i.renderId=this.renderId)}else t===J.OBJECT&&e.updateAfter(this)}updateNode(e){let t=e.getUpdateType(),r=e.updateReference(this);if(t===J.FRAME){let i=this._getMaps(this.updateMap,r);i.frameId!==this.frameId&&e.update(this)!==!1&&(i.frameId=this.frameId)}else if(t===J.RENDER){let i=this._getMaps(this.updateMap,r);i.renderId!==this.renderId&&e.update(this)!==!1&&(i.renderId=this.renderId)}else t===J.OBJECT&&e.update(this)}update(){this.frameId++,this.lastTime===void 0&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}},Dm=DT;var Um=class{constructor(e,t,r=null,i="",s=!1){this.type=e,this.name=t,this.count=r,this.qualifier=i,this.isConst=s}};Um.isNodeFunctionInput=!0;var dd=Um;var UT=class extends Hr{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}},IT=UT;var OT=class extends Hr{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setupDirect(){let e=this.colorNode;return{lightDirection:Jc(this.light),lightColor:e}}},kT=OT;var VT=class extends Hr{static get type(){return"HemisphereLightNode"}constructor(e=null){super(e),this.lightPositionNode=im(e),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=Y(new le).setGroup(ee)}update(e){let{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){let{colorNode:t,groundColorNode:r,lightDirectionNode:i}=this,o=ni.dot(i).mul(.5).add(.5),a=xe(r,t,o);e.context.irradiance.addAssign(a)}},GT=VT;var zT=class extends Hr{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=Y(0).setGroup(ee),this.penumbraCosNode=Y(0).setGroup(ee),this.cutoffDistanceNode=Y(0).setGroup(ee),this.decayExponentNode=Y(0).setGroup(ee),this.colorNode=Y(this.color).setGroup(ee)}update(e){super.update(e);let{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){let{coneCosNode:r,penumbraCosNode:i}=this;return Wt(r,i,t)}getLightCoord(e){let t=e.getNodeProperties(this),r=t.projectionUV;return r===void 0&&(r=iT(this.light,e.context.positionWorld),t.projectionUV=r),r}setupDirect(e){let{colorNode:t,cutoffDistanceNode:r,decayExponentNode:i,light:s}=this,o=this.getLightVector(e),a=o.normalize(),l=a.dot(Jc(s)),u=this.getSpotAttenuation(e,l),c=o.length(),d=rd({lightDistance:c,cutoffDistance:r,decayExponent:i}),h=t.mul(u).mul(d),p,f;return s.colorNode?(f=this.getLightCoord(e),p=s.colorNode(f)):s.map&&(f=this.getLightCoord(e),p=be(s.map,f.xy).onRenderUpdate(()=>s.map)),p&&(h=f.mul(2).sub(1).abs().lessThan(1).all().select(h.mul(p),h)),{lightColor:h,lightDirection:a}}},qa=zT;var $T=class extends qa{static get type(){return"IESSpotLightNode"}constructor(e=null){super(e),this._iesTextureNode=null}getSpotAttenuation(e,t){let r=this.light.iesMap,i=null;if(r&&r.isTexture===!0){let s=t.acos().mul(1/Math.PI);this._iesTextureNode=be(r,V(s,0),0),i=this._iesTextureNode.r}else i=super.getSpotAttenuation(e,t);return i}update(e){super.update(e),this._iesTextureNode!==null&&this.light.iesMap&&(this._iesTextureNode.value=this.light.iesMap)}},WT=$T;var HT=class extends Hr{static get type(){return"LightProbeNode"}constructor(e=null){super(e);let t=[];for(let r=0;r<9;r++)t.push(new C);this.lightProbe=Et(t)}update(e){let{light:t}=this;super.update(e);for(let r=0;r<9;r++)this.lightProbe.array[r].copy(t.sh.coefficients[r]).multiplyScalar(t.intensity)}setup(e){let t=fm(ni,this.lightProbe);e.context.irradiance.addAssign(t)}},qT=HT;var pI=_(([n,e])=>{let t=n.abs().sub(e);return mi(Ie(t,0)).add(ht(Ie(t.x,t.y),0))}),jT=class extends qa{static get type(){return"ProjectorLightNode"}update(e){super.update(e);let t=this.light;if(this.penumbraCosNode.value=Math.min(Math.cos(t.angle*(1-t.penumbra)),.99999),t.aspect===null){let r=1;t.map!==null&&(r=t.map.width/t.map.height),t.shadow.aspect=r}else t.shadow.aspect=t.aspect}getSpotAttenuation(e){let t=y(0),r=this.penumbraCosNode,i=lu(this.light).mul(e.context.positionWorld||vr);return ie(i.w.greaterThan(0),()=>{let s=i.xyz.div(i.w),o=pI(s.xy.sub(V(.5)),V(.5)),a=xt(-1,Se(1,gp(r)).sub(1));t.assign($l(o.mul(-2).mul(a)))}),t}},XT=jT;var YT=new ue,Im=new ue,hd=null,KT=class extends Hr{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=Y(new C).setGroup(ee),this.halfWidth=Y(new C).setGroup(ee),this.updateType=J.RENDER}update(e){super.update(e);let{light:t}=this,r=e.camera.matrixWorldInverse;Im.identity(),YT.copy(t.matrixWorld),YT.premultiply(r),Im.extractRotation(YT),this.halfWidth.value.set(t.width*.5,0,0),this.halfHeight.value.set(0,t.height*.5,0),this.halfWidth.value.applyMatrix4(Im),this.halfHeight.value.applyMatrix4(Im)}setupDirectRectArea(e){let t,r;e.isAvailable("float32Filterable")?(t=be(hd.LTC_FLOAT_1),r=be(hd.LTC_FLOAT_2)):(t=be(hd.LTC_HALF_1),r=be(hd.LTC_HALF_2));let{colorNode:i,light:s}=this,o=Zc(s);return{lightColor:i,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,ltc_1:t,ltc_2:r}}static setLTC(e){hd=e}},QT=KT;var ZT=class{parseFunction(){U("Abstract function.")}},Om=ZT;var km=class{constructor(e,t,r="",i=""){this.type=e,this.inputs=t,this.name=r,this.precision=i}getCode(){U("Abstract function.")}};km.isNodeFunction=!0;var Vm=km;var fI=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,mI=/[a-z_0-9]+/ig,SC="#pragma main",gI=n=>{n=n.trim();let e=n.indexOf(SC),t=e!==-1?n.slice(e+SC.length):n,r=t.match(fI);if(r!==null&&r.length===5){let i=r[4],s=[],o=null;for(;(o=mI.exec(i))!==null;)s.push(o);let a=[],l=0;for(;l<s.length;){let f=s[l][0]==="const";f===!0&&l++;let m=s[l][0];m==="in"||m==="out"||m==="inout"?l++:m="";let g=s[l++][0],x=Number.parseInt(s[l][0]);Number.isNaN(x)===!1?l++:x=null;let w=s[l++][0];a.push(new dd(g,w,x,m,f))}let u=t.substring(r[0].length),c=r[3]!==void 0?r[3]:"",d=r[2],h=r[1]!==void 0?r[1]:"",p=e!==-1?n.slice(0,e):"";return{type:d,inputs:a,name:c,precision:h,inputsCode:i,blockCode:u,headerCode:p}}else throw new Error("THREE.FunctionNode: Function is not a GLSL code.")},JT=class extends Vm{constructor(e){let{type:t,inputs:r,name:i,precision:s,inputsCode:o,blockCode:a,headerCode:l}=gI(e);super(t,r,i,s),this.inputsCode=o,this.blockCode=a,this.headerCode=l}getCode(e=this.name){let t,r=this.blockCode;if(r!==""){let{type:i,inputsCode:s,headerCode:o,precision:a}=this,l=`${i} ${e} ( ${s.trim()} )`;a!==""&&(l=`${a} ${l}`),t=o+l+r}else t="";return t}},NC=JT;var eS=class extends Om{parseFunction(e){return new NC(e)}},tS=eS;var Xi=[],Ln=[],wC=Y(0,"int").setGroup(ee),rS=class extends Ar{constructor(e,t){super(),this.renderer=e,this.backend=t,this.nodeFrame=new Dm,this.nodeBuilderCache=new Map,this.callHashCache=new Si,this.groupsData=new Si,this._buildQueue=[],this._buildInProgress=!1,this.cacheLib={}}updateGroup(e){let t=e.groupNode;if(t.updateType===J.OBJECT)return!0;Xi[0]=t,Xi[1]=e;let r=this.groupsData.get(Xi);return r===void 0&&this.groupsData.set(Xi,r={}),Xi[0]=null,Xi[1]=null,r.version!==t.version?(r.version=t.version,!0):!1}getForRenderCacheKey(e){return e.initialCacheKey}_createNodeBuilder(e,t){let 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}getForRender(e,t=!1){let r=this.get(e),i=r.nodeBuilderState;if(i===void 0){let{nodeBuilderCache:s}=this,o=this.getForRenderCacheKey(e);if(i=s.get(o),i===void 0){let a=this.renderer.nodeBuilderStateProvider;if(a!==null){let u=a.getForRender(e,gm);if(u!=null)return s.set(o,u),u.usedTimes++,r.nodeBuilderState=u,u}let l=async()=>{let u=this._createNodeBuilder(e,e.material);try{t?await u.buildAsync():u.build()}catch(c){u=this._createNodeBuilder(e,new we),t?await u.buildAsync():u.build(),I("TSL: "+c)}return u};if(t)return l().then(u=>(i=this._createNodeBuilderState(u),s.set(o,i),i.usedTimes++,r.nodeBuilderState=i,i));{let u=this._createNodeBuilder(e,e.material);try{u.build()}catch(c){u=this._createNodeBuilder(e,new we),u.build();let d=c.stackTrace;!d&&c.stack&&(d=new tt(c.stack)),I("TSL: "+c,d)}i=this._createNodeBuilderState(u),s.set(o,i)}}i.usedTimes++,r.nodeBuilderState=i}return i}getForRenderAsync(e){let t=this.getForRender(e,!0);return t.then?t:Promise.resolve(t)}getForRenderDeferred(e){let t=this.get(e);if(t.nodeBuilderState!==void 0)return t.nodeBuilderState;let r=this.getForRenderCacheKey(e),i=this.nodeBuilderCache.get(r);return i!==void 0?(i.usedTimes++,t.nodeBuilderState=i,i):(t.pendingBuild!==!0&&(t.pendingBuild=!0,this._buildQueue.push(()=>this.getForRenderAsync(e).then(()=>{t.pendingBuild=!1})),this._processBuildQueue()),null)}_processBuildQueue(){if(this._buildInProgress||this._buildQueue.length===0)return;this._buildInProgress=!0,this._buildQueue.shift()().then(()=>{this._buildInProgress=!1,this._processBuildQueue()})}delete(e){if(e.isRenderObject){let t=this.get(e).nodeBuilderState;t!==void 0&&(t.usedTimes--,t.usedTimes===0&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(e)))}return super.delete(e)}getForCompute(e){let t=this.get(e),r=t.nodeBuilderState;if(r===void 0||t.version!==e.version){let i=this.renderer.nodeBuilderStateProvider;if(i!==null&&(r=i.getForCompute(e,gm)),r==null){let s=this.backend.createNodeBuilder(e,this.renderer);s.build(),r=this._createNodeBuilderState(s)}t.nodeBuilderState=r,t.version=e.version}return r}_createNodeBuilderState(e){return new gm(e.vertexShader,e.fragmentShader,e.computeShader,e.getAttributesArray(),e.getBindings(),e.updateNodes,e.updateBeforeNodes,e.updateAfterNodes,e.observer,e.hardwareClipping,e.transforms)}getEnvironmentNode(e){if(this.renderer.lighting.enabled===!1)return null;this.updateEnvironment(e);let t=null;if(e.environmentNode&&e.environmentNode.isNode)t=e.environmentNode;else{let 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{let 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){Xi[0]=e,Xi[1]=t;let r=this.renderer.info.calls,i=this.callHashCache.get(Xi)||{};if(i.callId!==r){if(Ln.push(this.renderer.getOutputRenderTarget()&&this.renderer.getOutputRenderTarget().multiview?1:0),Ln.push(this.renderer.lighting.enabled?1:0),this.renderer.lighting.enabled){Ln.push(t.getCacheKey(!0)),Ln.push(this.renderer.shadowMap.enabled?1:0),Ln.push(this.renderer.shadowMap.type);let o=this.getEnvironmentNode(e);o&&Ln.push(o.getCacheKey())}let s=this.getFogNode(e);s&&Ln.push(s.getCacheKey()),i.callId=r,i.cacheKey=Ns(Ln),this.callHashCache.set(Xi,i),Ln.length=0}return Xi[0]=null,Xi[1]=null,i.cacheKey}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(e){let t=this.get(e),r=e.background;if(r){let i=e.backgroundBlurriness===0&&t.backgroundBlurriness>0||e.backgroundBlurriness>0&&t.backgroundBlurriness===0;if(t.background!==r||i){let s=this.getCacheNode("background",r,()=>{if(r.isCubeTexture===!0||r.mapping===Eu||r.mapping===Bu||r.mapping===Wo){if(e.backgroundBlurriness>0||r.mapping===Wo)return $c(r);{let o;return r.isCubeTexture===!0?o=Ft(r):o=be(r),ff(o)}}else{if(r.isTexture===!0)return be(r,pr.flipY()).setUpdateMatrix(!0);r.isColor!==!0&&I("WebGPUNodes: Unsupported background configuration.",r)}},i);t.backgroundNode=s,t.background=r,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}getCacheNode(e,t,r,i=!1){let s=this.cacheLib[e]||(this.cacheLib[e]=new WeakMap),o=s.get(t);return(o===void 0||i)&&(o=r(),s.set(t,o)),o}updateFog(e){let t=this.get(e),r=e.fog;if(r){if(t.fog!==r){let i=this.getCacheNode("fog",r,()=>{if(r.isFogExp2){let s=ke("color","color",r).setGroup(ee),o=ke("density","float",r).setGroup(ee);return em(s,K_(o))}else if(r.isFog){let s=ke("color","color",r).setGroup(ee),o=ke("near","float",r).setGroup(ee),a=ke("far","float",r).setGroup(ee);return em(s,Y_(o,a))}else I("Renderer: Unsupported fog configuration.",r)});t.fogNode=i,t.fog=r}}else delete t.fogNode,delete t.fog}updateEnvironment(e){let t=this.get(e),r=e.environment;if(r){if(t.environment!==r){let i=this.getCacheNode("environment",r,()=>{if(r.isCubeTexture===!0)return Ft(r);if(r.isTexture===!0)return be(r);I("Nodes: Unsupported environment configuration.",r)});t.environmentNode=i,t.environment=r}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,r=null,i=null,s=null){let o=this.nodeFrame;return o.renderer=e,o.scene=t,o.object=r,o.camera=i,o.material=s,o}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){let e=this.renderer;return e.toneMapping+","+e.currentColorSpace+","+e.xr.isPresenting}getOutputNode(e){let t=this.renderer,r;return e.isArrayTexture?this.backend.isWebGLBackend?r=be(e,pr).depth($i("gl_ViewID_OVR")).renderOutput(t.toneMapping,t.currentColorSpace):r=be(e,pr).depth(wC).renderOutput(t.toneMapping,t.currentColorSpace):r=be(e,pr).renderOutput(t.toneMapping,t.currentColorSpace),r}setOutputLayerIndex(e){wC.value=e}updateBefore(e){let t=e.getNodeBuilderState();for(let r of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(r)}updateAfter(e){let t=e.getNodeBuilderState();for(let r of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(r)}updateForCompute(e){let t=this.getNodeFrame(),r=this.getForCompute(e);for(let i of r.updateNodes)t.updateNode(i)}updateForRender(e){let t=this.getNodeFrameForRender(e),r=e.getNodeBuilderState();for(let i of r.updateNodes)t.updateNode(i)}needsRefresh(e){let t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new Dm,this.nodeBuilderCache=new Map,this.cacheLib={}}},MC=rS;var iS=new pi,sS=class n{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",this.shadowPass=!1,this.viewMatrix=new ue,this.viewNormalMatrix=new et,this.clippingGroupContexts=new WeakMap,this.intersectionPlanes=[],this.unionPlanes=[],this.parentVersion=null,e!==null&&(this.viewMatrix=e.viewMatrix,this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass)}projectPlanes(e,t,r){let i=e.length;for(let s=0;s<i;s++){iS.copy(e[s]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);let o=t[r+s],a=iS.normal;o.x=-a.x,o.y=-a.y,o.z=-a.z,o.w=iS.constant}}updateGlobal(e,t){this.shadowPass=e.overrideMaterial!==null&&e.overrideMaterial.isShadowPassMaterial,this.viewMatrix.copy(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);let i=t.clippingPlanes,s=i.length,o,a;if(this.clipIntersection?(o=this.intersectionPlanes,a=e.intersectionPlanes.length):(o=this.unionPlanes,a=e.unionPlanes.length),o.length!==a+s){o.length=a+s;for(let l=0;l<s;l++)o[a+l]=new pe;r=!0}this.projectPlanes(i,o,a),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 t===void 0&&(t=new n(this),this.clippingGroupContexts.set(e,t)),t.update(this,e),t}get unionClippingCount(){return this.unionPlanes.length}},nS=sS;var oS=class{constructor(e,t,r){this.bundleGroup=e,this.camera=t,this.renderContext=r}},vC=oS;var Mo=[],aS=class{constructor(){this.bundles=new Si}get(e,t,r){let i=this.bundles;Mo[0]=e,Mo[1]=t,Mo[2]=r;let s=i.get(Mo);return s===void 0&&(s=new vC(e,t,r),i.set(Mo,s)),Mo[0]=null,Mo[1]=null,Mo[2]=null,s}dispose(){this.bundles=new Si}},AC=aS;var lS=class{constructor(){this.lightNodes=new WeakMap,this.materialNodes=new Map,this.toneMappingNodes=new Map}fromMaterial(e){if(e.isNodeMaterial)return e;let t=null,r=this.getMaterialNodeClass(e.type);if(r!==null){t=new r;for(let i in e)t[i]=e[i]}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)){U(`Redefinition of node ${t}`);return}if(typeof e!="function")throw new Error(`THREE.NodeLibrary: Node class ${e.name} is not a class.`);if(typeof t=="function"||typeof t=="object")throw new Error(`THREE.NodeLibrary: Base class ${t} is not a class.`);r.set(t,e)}addClass(e,t,r){if(r.has(t)){U(`Redefinition of node ${t.name}`);return}if(typeof e!="function")throw new Error(`THREE.NodeLibrary: Node class ${e.name} is not a class.`);if(typeof t!="function")throw new Error(`THREE.NodeLibrary: Base class ${t.name} is not a class.`);r.set(t,e)}},Gm=lS;var xI=new nm,uS=class{constructor(){this.enabled=!0,this._cache=[],this._lightsNodeMap=new WeakMap}createNode(e=[]){return new nm().setLights(e)}getNode(e){if(e.isScene!==!0&&e.isGroup!==!0)return xI;let t=this._lightsNodeMap.get(e);return t===void 0&&(t=this.createNode(),this._lightsNodeMap.set(e,t)),t}beginRender(e){this._cache.push(this.getNode(e).getLights())}finishRender(e){this.getNode(e).setLights(this._cache.pop())}},RC=uS;var vo=class extends ct{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}};var CC=new C,EC=new C,BC=new WeakMap,cS=class extends bt{constructor(e,t=!1){super(),this.enabled=!1,this.isPresenting=!1,this.cameraAutoUpdate=!0,this._renderer=e,this._cameraL=new Rt,this._cameraL.viewport=new pe,this._cameraL.matrixWorldAutoUpdate=!1,this._cameraR=new Rt,this._cameraR.viewport=new pe,this._cameraR.matrixWorldAutoUpdate=!1,this._cameras=[this._cameraL,this._cameraR],this._cameraXR=new Yh,this._currentDepthNear=null,this._currentDepthFar=null,this._controllers=[],this._controllerInputSources=[],this._xrRenderTarget=null,this._layers=[],this._sessionUsesLayers=!1,this._supportsGlBinding=typeof XRWebGLBinding<"u",this._supportsWebGPUBinding=typeof globalThis.XRGPUBinding<"u",this._createXRLayer=NI.bind(this),this._gl=null,this._currentAnimationContext=null,this._currentAnimationLoop=null,this._currentPixelRatio=null,this._currentSamples=null,this._currentSize=new se,this._onSessionEvent=_I.bind(this),this._onSessionEnd=TI.bind(this),this._onInputSourcesChange=SI.bind(this),this._onAnimationFrame=wI.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._webgpuBinding=null,this._glProjLayer=null,this._xrFrame=null,this._supportsLayers=this._supportsGlBinding&&"createProjectionLayer"in XRWebGLBinding.prototype,this._useMultiviewIfPossible=t,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(){return this._foveation}setFoveation(e){this._foveation=e,this._glProjLayer!==null&&(this._glProjLayer.fixedFoveation=e),this._glBaseLayer!==null&&this._glBaseLayer.fixedFoveation!==void 0&&(this._glBaseLayer.fixedFoveation=e)}getFramebufferScaleFactor(){return this._framebufferScaleFactor}setFramebufferScaleFactor(e){this._framebufferScaleFactor=e,this.isPresenting===!0&&U("XRManager: Cannot change framebuffer scale while presenting.")}getReferenceSpaceType(){return this._referenceSpaceType}setReferenceSpaceType(e){this._referenceSpaceType=e,this.isPresenting===!0&&U("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(this._session!==null)return this._session.environmentBlendMode}getBaseLayer(){return this._glProjLayer!==null?this._glProjLayer:this._glBaseLayer}getBinding(){return this._glBinding===null&&this._supportsGlBinding&&(this._glBinding=new XRWebGLBinding(this._session,this._gl)),this._glBinding}foveateBoundTexture(e){if(e.isPostProcessingRenderTarget!==!0||this.isPresenting!==!0||this._glProjLayer===null)return;let t=this._renderer.backend;if(t===void 0||t.isWebGLBackend!==!0||t.state===null)return;let r=this._renderer.getOutputRenderTarget();if(r===null||r.isXRRenderTarget!==!0)return;let i=this.getBinding();if(i===null||typeof i.foveateBoundTexture!="function")return;this._renderer._textures.updateRenderTarget(e);let{textureGPU:s,glTextureType:o}=t.get(e.texture);if(!(s===void 0||o===void 0)&&e._xrFoveationTextureGPU!==s){e._xrFoveationTextureGPU=s,t.state.bindTexture(o,s);try{i.foveateBoundTexture(o,this.getFoveation())}catch(a){he(`XRManager: Unable to foveate bound XR post-processing texture. ${a.name}: ${a.message}`)}finally{t.state.unbindTexture()}}}getWebGPUBinding(){return this._webgpuBinding===null&&this._supportsWebGPUBinding&&(this._webgpuBinding=new globalThis.XRGPUBinding(this._session,this._renderer.backend.device)),this._webgpuBinding}_isWebGPUSession(){return this._renderer.backend.isWebGPUBackend===!0&&this._session!==null&&this._session.enabledFeatures.includes("webgpu")}_validateWebGPUSession(){let e=this._renderer;if(e.backend.isWebGPUBackend===!0){if(this._session.enabledFeatures.includes("webgpu")===!1)throw new Error('THREE.XRManager: WebGPU XR sessions require the "webgpu" session feature. Use VRButtonGPU/XRButton with "webgpu" enabled or use a WebGL backend.');e.samples>0&&(he("THREE.XRManager: WebGPU XR does not support MSAA yet. Disabling MSAA for this XR session."),this._currentSamples===null&&(this._currentSamples=e.samples),e._samples=0)}}async _initWebGPUSession(e){let t=this.getWebGPUBinding(),r=t.createProjectionLayer({colorFormat:t.getPreferredColorFormat(),depthStencilFormat:"depth24plus"});this._glProjLayer=r,e.updateRenderState({layers:[r]}),this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType()),this._xrRenderTarget=new ct(r.textureWidth,r.textureHeight,{depth:2,minFilter:je,magFilter:je,depthBuffer:!0,multiview:!1,useArrayDepthTexture:!0,samples:0}),this._xrRenderTarget.texture.isArrayTexture=!0,this._useMultiviewIfPossible===!0&&he("THREE.XRManager: WebGPU XR does not support multiview yet. Disabling multiview for this XR session."),this._useMultiview=!1}_disposeWebGPUSession(){let e=this._renderer,t=this._xrRenderTarget;if(t===null||e.backend.isWebGPUBackend!==!0)return;let r=e.backend,i=e._textures,s=r.get?r.get(t):null;s&&(s.descriptors=void 0);let o=a=>{a!=null&&(r.delete&&r.delete(a),i.delete&&i.delete(a))};for(let a=0;a<t.textures.length;a++)o(t.textures[a]);o(t.depthTexture),o(t),e._renderContexts&&e._renderContexts.dispose&&e._renderContexts.dispose(),t.dispose()}_getWebGPUViewData(e){let t=this.getWebGPUBinding(),r={colorTexture:null,viewDescriptors:[],viewports:[]};for(let i=0;i<e.length;i++){let s=t.getViewSubImage(this._glProjLayer,e[i]);r.colorTexture===null&&(r.colorTexture=s.colorTexture),r.viewports.push(s.viewport),s.getViewDescriptor&&r.viewDescriptors.push(s.getViewDescriptor())}return r}getFrame(){return this._xrFrame}useMultiview(){return this._useMultiview}createQuadLayer(e,t,r,i,s,o,a,l={}){let u=new Wu(e,t),c=new vo(s,o,{format:wt,type:it,depthTexture:new ot(s,o,l.stencil?Qr:Ce,void 0,void 0,void 0,void 0,void 0,void 0,l.stencil?Ht:Mt),stencilBuffer:l.stencil,resolveDepthBuffer:!1,resolveStencilBuffer:!1,storeMultisampledDepthBuffer:!1,storeMultisampledStencilBuffer:!1});c._autoAllocateDepthBuffer=!0;let d=new ti({color:16777215,side:Yr});d.map=c.texture,d.map.offset.y=1,d.map.repeat.y=-1;let h=new sr(u,d);h.position.copy(r),h.quaternion.copy(i);let p={type:"quad",width:e,height:t,translation:r,quaternion:i,pixelwidth:s,pixelheight:o,plane:h,material:d,rendercall:a,renderTarget:c};if(this._layers.push(p),this._session!==null){p.plane.material=new ti({color:16777215,side:Yr}),p.plane.material.blending=rn,p.plane.material.blendEquation=Jt,p.plane.material.blendSrc=Zi,p.plane.material.blendDst=Zi,p.xrlayer=this._createXRLayer(p);let f=this._session.renderState.layers;f.unshift(p.xrlayer),this._session.updateRenderState({layers:f})}else c.isXRRenderTarget=!1;return h}createCylinderLayer(e,t,r,i,s,o,a,l,u={}){let c=new vh(e,e,e*t/r,64,64,!0,Math.PI-t/2,t),d=new vo(o,a,{format:wt,type:it,depthTexture:new ot(o,a,u.stencil?Qr:Ce,void 0,void 0,void 0,void 0,void 0,void 0,u.stencil?Ht:Mt),stencilBuffer:u.stencil,resolveDepthBuffer:!1,resolveStencilBuffer:!1,storeMultisampledDepthBuffer:!1,storeMultisampledStencilBuffer:!1});d._autoAllocateDepthBuffer=!0;let h=new ti({color:16777215,side:Ze});h.map=d.texture,h.map.offset.y=1,h.map.repeat.y=-1;let p=new sr(c,h);p.position.copy(i),p.quaternion.copy(s);let f={type:"cylinder",radius:e,centralAngle:t,aspectratio:r,translation:i,quaternion:s,pixelwidth:o,pixelheight:a,plane:p,material:h,rendercall:l,renderTarget:d};if(this._layers.push(f),this._session!==null){f.plane.material=new ti({color:16777215,side:Ze}),f.plane.material.blending=rn,f.plane.material.blendEquation=Jt,f.plane.material.blendSrc=Zi,f.plane.material.blendDst=Zi,f.xrlayer=this._createXRLayer(f);let m=this._session.renderState.layers;m.unshift(f.xrlayer),this._session.updateRenderState({layers:m})}else d.isXRRenderTarget=!1;return p}renderLayers(){let e=new C,t=new Jr,r=this._renderer,i=this.isPresenting;this.isPresenting=!1;let s=new se;r.getSize(s);let o=r.getRenderTarget();for(let a of this._layers){a.renderTarget.isXRRenderTarget=this._session!==null,a.renderTarget._hasExternalTextures=a.renderTarget.isXRRenderTarget;let l=r.contextNode,u;if(a.renderTarget.isXRRenderTarget&&this._sessionUsesLayers){a.xrlayer.transform=new XRRigidTransform(a.plane.getWorldPosition(e),a.plane.getWorldQuaternion(t));let c=this._glBinding.getSubImage(a.xrlayer,this._xrFrame);r.backend.setXRRenderTargetTextures(a.renderTarget,c.colorTexture,void 0),r._setXRLayerSize(a.renderTarget.width,a.renderTarget.height),u=BC.get(l),u===void 0&&(u=l.context({getOutput:d=>Pp(d,r.toneMapping,r.outputColorSpace)}),BC.set(l,u))}else u=l;r.contextNode=u,r.setRenderTarget(a.renderTarget),a.rendercall(),r.contextNode=l}r.setRenderTarget(o),r._setXRLayerSize(s.x,s.y),this.isPresenting=i}getSession(){return this._session}async setSession(e){let t=this._renderer;t.initialized===!1&&await t.init(),this._gl=t.getContext();let r=this._gl;if(this._session=e,e!==null){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),this._validateWebGPUSession(),this._currentPixelRatio=t.getPixelRatio(),t.getSize(this._currentSize),this._currentAnimationContext=t._animation.getContext(),this._currentAnimationLoop=t._animation.getAnimationLoop(),t._animation.stop(),this._isWebGPUSession())await this._initWebGPUSession(e);else if(this._supportsLayers===!0){let i=null,s=null,o=null,a=r.getContextAttributes();await t.backend.makeXRCompatible(),this.setFoveation(this.getFoveation()),t.depth&&(o=t.stencil?r.DEPTH24_STENCIL8:r.DEPTH_COMPONENT24,i=t.stencil?Ht:Mt,s=t.stencil?Qr:Ce);let l={colorFormat:r.RGBA8,depthFormat:o,scaleFactor:this._framebufferScaleFactor,clearOnAccess:!1};this._useMultiviewIfPossible&&t.hasFeature("OVR_multiview2")&&(l.textureType="texture-array",this._useMultiview=!0),this._glBinding=this.getBinding();let u=this._glBinding.createProjectionLayer(l),c=[u];this._glProjLayer=u,t.setPixelRatio(1),t._setXRLayerSize(u.textureWidth,u.textureHeight);let d=this._useMultiview?2:1,h=new ot(u.textureWidth,u.textureHeight,s,void 0,void 0,void 0,void 0,void 0,void 0,i,d);if(this._xrRenderTarget=new vo(u.textureWidth,u.textureHeight,{format:wt,type:it,colorSpace:t.outputColorSpace,depthTexture:h,stencilBuffer:t.stencil,samples:a.antialias?4:0,resolveDepthBuffer:u.ignoreDepthValues===!1,resolveStencilBuffer:u.ignoreDepthValues===!1,storeMultisampledColorBuffer:!1,storeMultisampledDepthBuffer:u.ignoreDepthValues===!1,storeMultisampledStencilBuffer:u.ignoreDepthValues===!1,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(let p of this._layers)p.plane.material=new ti({color:16777215,side:p.type==="cylinder"?Ze:Yr}),p.plane.material.blending=rn,p.plane.material.blendEquation=Jt,p.plane.material.blendSrc=Zi,p.plane.material.blendDst=Zi,p.xrlayer=this._createXRLayer(p),c.unshift(p.xrlayer);e.updateRenderState({layers:c})}else{await t.backend.makeXRCompatible(),this.setFoveation(this.getFoveation());let i={antialias:t.currentSamples>0,alpha:!0,depth:t.depth,stencil:t.stencil,framebufferScaleFactor:this.getFramebufferScaleFactor()},s=new XRWebGLLayer(e,r,i);this._glBaseLayer=s,e.updateRenderState({baseLayer:s}),t.setPixelRatio(1),t._setXRLayerSize(s.framebufferWidth,s.framebufferHeight),this._xrRenderTarget=new vo(s.framebufferWidth,s.framebufferHeight,{format:wt,type:it,colorSpace:t.outputColorSpace,stencilBuffer:t.stencil,resolveDepthBuffer:s.ignoreDepthValues===!1,resolveStencilBuffer:s.ignoreDepthValues===!1,storeMultisampledDepthBuffer:s.ignoreDepthValues===!1,storeMultisampledStencilBuffer:s.ignoreDepthValues===!1}),this._xrRenderTarget._isOpaqueFramebuffer=!0,this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType())}t._animation.setAnimationLoop(this._onAnimationFrame),t._animation.setContext(e),t._animation.start(),this.isPresenting=!0,this.dispatchEvent({type:"sessionstart"})}}updateCamera(e){let t=this._session;if(t===null)return;let r=e.near,i=e.far,s=this._cameraXR,o=this._cameraL,a=this._cameraR;s.near=a.near=o.near=r,s.far=a.far=o.far=i,s.isMultiViewCamera=this._useMultiview,(this._currentDepthNear!==s.near||this._currentDepthFar!==s.far)&&(t.updateRenderState({depthNear:s.near,depthFar:s.far}),this._currentDepthNear=s.near,this._currentDepthFar=s.far),s.layers.mask=e.layers.mask|6,o.layers.mask=s.layers.mask&-5,a.layers.mask=s.layers.mask&-3;let l=e.parent,u=s.cameras;FC(s,l);for(let c=0;c<u.length;c++)FC(u[c],l);u.length===2?yI(s,o,a):s.projectionMatrix.copy(o.projectionMatrix),bI(e,s,l)}_getController(e){let t=this._controllers[e];return t===void 0&&(t=new sh,this._controllers[e]=t),t}};function yI(n,e,t){CC.setFromMatrixPosition(e.matrixWorld),EC.setFromMatrixPosition(t.matrixWorld);let r=CC.distanceTo(EC),i=e.projectionMatrix.elements,s=t.projectionMatrix.elements,o=i[14]/(i[10]-1),a=i[14]/(i[10]+1),l=(i[9]+1)/i[5],u=(i[9]-1)/i[5],c=(i[8]-1)/i[0],d=(s[8]+1)/s[0],h=o*c,p=o*d,f=r/(-c+d),m=f*-c;if(e.matrixWorld.decompose(n.position,n.quaternion,n.scale),n.translateX(m),n.translateZ(f),n.matrixWorld.compose(n.position,n.quaternion,n.scale),n.matrixWorldInverse.copy(n.matrixWorld).invert(),i[10]===-1)n.projectionMatrix.copy(e.projectionMatrix),n.projectionMatrixInverse.copy(e.projectionMatrixInverse);else{let g=o+f,x=a+f,w=h-m,v=p+(r-m),E=l*a/x*g,b=u*a/x*g;n.projectionMatrix.makePerspective(w,v,E,b,g,x),n.projectionMatrixInverse.copy(n.projectionMatrix).invert()}}function FC(n,e){e===null?n.matrixWorld.copy(n.matrix):n.matrixWorld.multiplyMatrices(e.matrixWorld,n.matrix),n.matrixWorldInverse.copy(n.matrixWorld).invert()}function bI(n,e,t){t===null?n.matrix.copy(e.matrixWorld):(n.matrix.copy(t.matrixWorld),n.matrix.invert(),n.matrix.multiply(e.matrixWorld)),n.matrix.decompose(n.position,n.quaternion,n.scale),n.updateMatrixWorld(!0),n.projectionMatrix.copy(e.projectionMatrix),n.projectionMatrixInverse.copy(e.projectionMatrixInverse),n.isPerspectiveCamera&&(n.fov=cn*2*Math.atan(1/n.projectionMatrix.elements[5]),n.zoom=1)}function _I(n){let e=this._controllerInputSources.indexOf(n.inputSource);if(e===-1)return;let t=this._controllers[e];if(t!==void 0){let r=this.getReferenceSpace();t.update(n.inputSource,n.frame,r),t.dispatchEvent({type:n.type,data:n.inputSource})}}function TI(){let n=this._session,e=this._renderer;n.removeEventListener("select",this._onSessionEvent),n.removeEventListener("selectstart",this._onSessionEvent),n.removeEventListener("selectend",this._onSessionEvent),n.removeEventListener("squeeze",this._onSessionEvent),n.removeEventListener("squeezestart",this._onSessionEvent),n.removeEventListener("squeezeend",this._onSessionEvent),n.removeEventListener("end",this._onSessionEnd),n.removeEventListener("inputsourceschange",this._onInputSourcesChange);for(let t=0;t<this._controllers.length;t++){let r=this._controllerInputSources[t];r!==null&&(this._controllerInputSources[t]=null,this._controllers[t].disconnect(r))}if(this._currentDepthNear=null,this._currentDepthFar=null,this._currentSamples!==null&&(e._samples=this._currentSamples,this._currentSamples=null),e._resetXRState(),this._disposeWebGPUSession(),this._session=null,this._xrRenderTarget=null,this._glBinding=null,this._webgpuBinding=null,this._glBaseLayer=null,this._glProjLayer=null,this._sessionUsesLayers===!0)for(let t of this._layers)t.renderTarget=new vo(t.pixelwidth,t.pixelheight,{format:wt,type:it,depthTexture:new ot(t.pixelwidth,t.pixelheight,t.stencilBuffer?Qr:Ce,void 0,void 0,void 0,void 0,void 0,void 0,t.stencilBuffer?Ht:Mt),stencilBuffer:t.stencilBuffer,resolveDepthBuffer:!1,resolveStencilBuffer:!1,storeMultisampledDepthBuffer:!1,storeMultisampledStencilBuffer:!1}),t.renderTarget.isXRRenderTarget=!1,t.plane.material=t.material,t.material.map=t.renderTarget.texture,t.material.map.offset.y=1,t.material.map.repeat.y=-1,delete t.xrlayer;this.isPresenting=!1,this._useMultiview=!1,e._animation.stop(),e._animation.setAnimationLoop(this._currentAnimationLoop),e._animation.setContext(this._currentAnimationContext),e._animation.start(),e.setPixelRatio(this._currentPixelRatio),e.setSize(this._currentSize.width,this._currentSize.height,!1),this.dispatchEvent({type:"sessionend"})}function SI(n){let e=this._controllers,t=this._controllerInputSources;for(let r=0;r<n.removed.length;r++){let i=n.removed[r],s=t.indexOf(i);s>=0&&(t[s]=null,e[s].disconnect(i))}for(let r=0;r<n.added.length;r++){let i=n.added[r],s=t.indexOf(i);if(s===-1){for(let a=0;a<e.length;a++)if(a>=t.length){t.push(i),s=a;break}else if(t[a]===null){t[a]=i,s=a;break}if(s===-1)break}let o=e[s];o&&o.connect(i)}}function NI(n){return n.type==="quad"?this._glBinding.createQuadLayer({transform:new XRRigidTransform(n.translation,n.quaternion),width:n.width/2,height:n.height/2,space:this._referenceSpace,viewPixelWidth:n.pixelwidth,viewPixelHeight:n.pixelheight,clearOnAccess:!1}):this._glBinding.createCylinderLayer({transform:new XRRigidTransform(n.translation,n.quaternion),radius:n.radius,centralAngle:n.centralAngle,aspectRatio:n.aspectRatio,space:this._referenceSpace,viewPixelWidth:n.pixelwidth,viewPixelHeight:n.pixelheight,clearOnAccess:!1})}function wI(n,e){if(e===void 0)return;let t=this._cameraXR,r=this._renderer,i=r.backend,s=this._glBaseLayer,o=this.getReferenceSpace(),a=e.getViewerPose(o);if(this._xrFrame=e,a!==null){let l=a.views,u=this._isWebGPUSession()?this._getWebGPUViewData(l):null;this._glBaseLayer!==null&&u===null&&i.setXRTarget(s.framebuffer);let c=!1;l.length!==t.cameras.length&&(t.cameras.length=0,c=!0);for(let h=0;h<l.length;h++){let p=l[h],f;if(u!==null)f=u.viewports[h];else if(this._supportsLayers===!0){let g=this._glBinding.getViewSubImage(this._glProjLayer,p);f=g.viewport,h===0&&i.setXRRenderTargetTextures(this._xrRenderTarget,g.colorTexture,this._glProjLayer.ignoreDepthValues&&!this._useMultiview?void 0:g.depthStencilTexture)}else f=s.getViewport(p);let m=this._cameras[h];m===void 0&&(m=new Rt,m.layers.enable(h),m.viewport=new pe,m.matrixWorldAutoUpdate=!1,this._cameras[h]=m),m.matrix.fromArray(p.transform.matrix),m.matrix.decompose(m.position,m.quaternion,m.scale),m.projectionMatrix.fromArray(p.projectionMatrix),m.projectionMatrixInverse.copy(m.projectionMatrix).invert(),m.viewport.set(f.x,f.y,f.width,f.height),h===0&&(t.matrix.copy(m.matrix),t.matrix.decompose(t.position,t.quaternion,t.scale)),c===!0&&t.cameras.push(m)}u!==null&&u.colorTexture!==null&&i.setXRRenderTargetTextures(this._xrRenderTarget,u.colorTexture,u.viewDescriptors),r.setOutputRenderTarget(this._xrRenderTarget);let d=r._getFrameBufferTarget();r.xr.foveateBoundTexture(d)}for(let l=0;l<this._controllers.length;l++){let u=this._controllerInputSources[l],c=this._controllers[l];u!==null&&c!==void 0&&c.update(u,e,o)}this._currentAnimationLoop&&this._currentAnimationLoop(n,e),e.detectedPlanes&&this.dispatchEvent({type:"planesdetected",data:e}),this._xrFrame=null}var LC=cS;var dS=class extends bt{constructor(e){super(),this.domElement=e,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new pe(0,0,this._width,this._height),this._scissor=new pe(0,0,this._width,this._height),this._scissorTest=!1,this.colorTexture=new lo,this.depthTexture=new ot}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),r===!0&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._dispatchResize())}getScissor(e){let 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,i){let s=this._scissor;e.isVector4?s.copy(e):s.set(e,t,r,i)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,r,i,s=0,o=1){let a=this._viewport;e.isVector4?a.copy(e):a.set(e,t,r,i),a.minDepth=s,a.maxDepth=o}_dispatchResize(){this.dispatchEvent({type:"resize"})}dispose(){this.dispatchEvent({type:"dispose"})}},PC=dS;var DC=new so,hu=new se,hS=new pe,zm=new bn,$m=new Nh,pu=new ue,Pn=new pe,MI={[Yr]:Ze,[Ze]:Yr,[Kr]:Kr},pS=class{constructor(e,t={}){this.isRenderer=!0;let{logarithmicDepthBuffer:r=!1,reversedDepthBuffer:i=!1,alpha:s=!0,depth:o=!0,stencil:a=!1,antialias:l=!1,samples:u=0,getFallback:c=null,outputBufferType:d=qe,multiview:h=!1}=t;this.backend=e,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=s,this.logarithmicDepthBuffer=r,this.reversedDepthBuffer=i,this.outputColorSpace=tr,this.toneMapping=ms,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=o,this.stencil=a,this.info=new mR,this.contextNode=wr(),this.library=new Gm,this.lighting=new RC,this.nodeBuilderStateProvider=null,this._samples=u||(l===!0?4:0),this._onCanvasTargetResize=this._onCanvasTargetResize.bind(this),this._canvasTarget=new PC(e.getDomElement()),this._canvasTarget.addEventListener("resize",this._onCanvasTargetResize),this._canvasTarget.isDefaultCanvasTarget=!0,this._inspector=new Dp,this._inspector.setRenderer(this),this._getFallback=c,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._quadCache=new Map,this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTargets=new Map;let p=this.alpha===!0?0:1;this._clearColor=new iu(0,0,0,p),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.onError=this._onError,this._outputBufferType=d,this._cacheShadowNodes=new WeakMap,this._initialized=!1,this._callDepth=-1,this._initPromise=null,this._compilationPromises=null,this._isPreCompiling=!1,this._currentSourceMaterial=null,this.transparent=!0,this.opaque=!0,this.shadowMap={enabled:!1,transmitted:!1,type:Gn},this.xr=new LC(this,h),this.debug={checkShaderErrors:!0,diagnostics:{keywords:!1},onShaderError:null,getShaderAsync:async(f,m,g)=>{await this.compileAsync(g,m,f);let w=this.needsFrameBufferTarget&&this._renderTarget===null?this._getFrameBufferTarget():this._renderTarget||this._outputRenderTarget,v=this._renderLists.get(f,m,this.lighting),E=this._renderContexts.get(w,this._mrt),b=f.overrideMaterial||g.material,S=this._objects.get(g,b,f,m,v.lightsNode,E,E.clippingContext),{fragmentShader:T,vertexShader:M}=S.getNodeBuilderState();return{fragmentShader:T,vertexShader:M}}}}async init(){return this._initPromise!==null?this._initPromise:(this._initPromise=new Promise(async(e,t)=>{let r=this.backend;try{await r.init(this)}catch(i){if(this._getFallback!==null)try{this.backend=r=this._getFallback(i),await r.init(this)}catch(s){t(s);return}else{t(i);return}}this._nodes=new MC(this,r),this._animation=new sR(this,this._nodes,this.info),this._attributes=new cR(r,this.info),this._background=new xC(this,this._nodes),this._geometries=new fR(this._attributes,this.info),this._textures=new AR(this,r,this.info),this._pipelines=new yR(r,this._nodes,this.info),this._bindings=new bR(r,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new aR(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new wR,this._bundles=new AC,this._renderContexts=new vR(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(this._isDeviceLost===!0)return;this._initialized===!1&&await this.init(),this.shadowMap.type===Ru&&(U("WebGPURenderer: PCFSoftShadowMap has been removed. Using PCFShadowMap instead."),this.shadowMap.type=Gn);let i=this._nodes.nodeFrame,s=i.renderId,o=this._currentRenderContext,a=this._currentRenderObjectFunction,l=this._handleObjectFunction,u=this._compilationPromises;r===null&&(r=e);let c=e.isScene===!0?e:r.isScene===!0?r:DC,h=this.needsFrameBufferTarget&&this._renderTarget===null?this._getFrameBufferTarget():this._renderTarget||this._outputRenderTarget,p=this._renderContexts.get(h,this._mrt),f=this._activeMipmapLevel,m=[];this._currentRenderContext=p,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=m,i.renderId++,i.update(),p.depth=this.depth,p.stencil=this.stencil,p.clippingContext||(p.clippingContext=new nS),p.clippingContext.updateGlobal(c,t),e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t=this._updateCamera(t),c.onBeforeRender(this,e,t,h),pu.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),t.isArrayCamera?$m.setFromArrayCamera(t):zm.setFromProjectionMatrix(pu,t.coordinateSystem,t.reversedDepth);let g=this._renderLists.get(c,t,this.lighting);if(g.begin(),this._projectObject(e,t,0,g,p.clippingContext),r!==e&&r.traverseVisible(function(b){b.isLight&&b.layers.test(t.layers)&&g.pushLight(b)}),g.finish(),h!==null){this._textures.updateRenderTarget(h,f);let b=this._textures.get(h);p.textures=b.textures,p.depthTexture=b.depthTexture}else p.textures=null,p.depthTexture=null;r!==e?this._background.update(r,g,p):this._background.update(c,g,p);let x=g.opaque,w=g.transparent,v=g.transparentDoublePass,E=g.lightsNode;this.opaque===!0&&x.length>0&&this._renderObjects(x,t,c,E),this.transparent===!0&&w.length>0&&this._renderTransparents(w,v,t,c,E),i.renderId=s,this._currentRenderContext=o,this._currentRenderObjectFunction=a,this._handleObjectFunction=l,this._compilationPromises=u;for(let b of m){let S=this._objects.get(b.object,b.material,b.scene,b.camera,b.lightsNode,b.renderContext,b.clippingContext,b.passId);S.drawRange=b.object.geometry.drawRange,S.group=b.group,await this._nodes.getForRenderAsync(S),this._isPreCompiling=!0,this._nodes.updateBefore(S),this._geometries.updateForRender(S),this._nodes.updateForRender(S),this._bindings.updateForRender(S),this._isPreCompiling=!1;let T=[];this._pipelines.getForRender(S,T),T.length>0&&await Promise.all(T),this._isPreCompiling=!0,this._nodes.updateAfter(S),this._isPreCompiling=!1,await Kd()}}async renderAsync(e,t){he('Renderer: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.render(e,t)}async waitForGPU(){I("Renderer: waitForGPU() has been removed. Read https://github.com/mrdoob/three.js/issues/32012 for more information.")}set inspector(e){this._inspector!==null&&this._inspector.setRenderer(null),this._inspector=e,this._inspector.setRenderer(this)}get inspector(){return this._inspector}set highPrecision(e){let t=this.contextNode.value;e===!0?(t.modelViewMatrix=jp,t.modelNormalViewMatrix=Xp):this.highPrecision&&(delete t.modelViewMatrix,delete t.modelNormalViewMatrix)}get highPrecision(){let e=this.contextNode.value;return e.modelViewMatrix===jp&&e.modelNormalViewMatrix===Xp}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getOutputBufferType(){return this._outputBufferType}getColorBufferType(){return he('Renderer: ".getColorBufferType()" has been renamed to ".getOutputBufferType()".'),this.getOutputBufferType()}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost: | |
| Message: ${e.message}`;e.reason&&(t+=` | |
| Reason: ${e.reason}`),I(t),this._isDeviceLost=!0}_onError(e){let t=`WebGPURenderer: Uncaptured ${e.api} ${e.type}`;e.message&&(t+=`: ${e.message}`),I(t)}_bundleNeedsUpdate(e,t){return t.bundleGPU===void 0||e.version!==t.version}_renderBundle(e,t,r){let{bundleGroup:i,camera:s,renderList:o}=e,a=this._currentRenderContext,l=this._bundles.get(i,s,a),u=this.backend.get(l);if(this._bundleNeedsUpdate(i,u)){this.backend.beginBundle(a),this._currentRenderBundle=l;let{transparentDoublePass:d,transparent:h,opaque:p}=o;this.opaque===!0&&p.length>0&&this._renderObjects(p,s,t,r),this.transparent===!0&&h.length>0&&this._renderTransparents(h,d,s,t,r),this._currentRenderBundle=null,this.backend.finishBundle(a,l),u.version=i.version}else{let{renderObjects:d}=u;for(let h=0,p=d.length;h<p;h++){let f=d[h];this._nodes.needsRefresh(f)&&(this._nodes.updateBefore(f),this._geometries.updateForRender(f),this._nodes.updateForRender(f),this._bindings.updateForRender(f),this._nodes.updateAfter(f))}}this.backend.addBundle(a,l)}render(e,t){if(this._initialized===!1)throw new Error('THREE.Renderer: .render() called before the backend is initialized. Use "await renderer.init();" before rendering.');this._renderScene(e,t)}get initialized(){return this._initialized}_renderOutputLayers(e,t){if(t.texture.isArrayTexture!==!0||t.texture.image.depth<=1){this._renderScene(e,e.camera,!1);return}let r=this._activeCubeFace;try{for(let i=0;i<t.texture.image.depth;i++)this._nodes.setOutputLayerIndex(i),this._activeCubeFace=i,this._renderScene(e,e.camera,!1)}finally{this._nodes.setOutputLayerIndex(0),this._activeCubeFace=r}}_getFrameBufferTarget(){let{currentToneMapping:e,currentColorSpace:t}=this,r=e!==ms,i=t!==Me.workingColorSpace;if(r===!1&&i===!1)return null;let{width:s,height:o}=this.getDrawingBufferSize(hu),{depth:a,stencil:l}=this,u=this._outputRenderTarget||this._canvasTarget,c=this._frameBufferTargets.get(u);if(c===void 0){c=new ct(s,o,{depthBuffer:a,stencilBuffer:l,type:this._outputBufferType,format:wt,colorSpace:Me.workingColorSpace,generateMipmaps:!1,minFilter:je,magFilter:je,samples:this.samples}),c.isPostProcessingRenderTarget=!0;let g=()=>{u.removeEventListener("dispose",g),c.dispose(),this._frameBufferTargets.delete(u)};u.addEventListener("dispose",g),this._frameBufferTargets.set(u,c)}let d=this.getOutputRenderTarget();c.depthBuffer=a,c.stencilBuffer=l,d!==null?c.setSize(d.width,d.height,d.depth):c.setSize(s,o,1);let h=this._outputRenderTarget?this._outputRenderTarget.viewport:u._viewport,p=this._outputRenderTarget?this._outputRenderTarget.scissor:u._scissor,f=this._outputRenderTarget?1:u._pixelRatio,m=this._outputRenderTarget?this._outputRenderTarget.scissorTest:u._scissorTest;return c.viewport.copy(h),c.scissor.copy(p),c.viewport.multiplyScalar(f),c.scissor.multiplyScalar(f),c.scissorTest=m,c.multiview=d!==null?d.multiview:!1,c.useArrayDepthTexture=d!==null?d.useArrayDepthTexture:!1,c.resolveDepthBuffer=d!==null?d.resolveDepthBuffer:!0,c.resolveStencilBuffer=d!==null?d.resolveStencilBuffer:!0,c.storeMultisampledColorBuffer=d!==null?d.storeMultisampledColorBuffer:!0,c.storeMultisampledDepthBuffer=d!==null?d.storeMultisampledDepthBuffer:!0,c.storeMultisampledStencilBuffer=d!==null?d.storeMultisampledStencilBuffer:!0,c._autoAllocateDepthBuffer=d!==null?d._autoAllocateDepthBuffer:!1,c}_renderScene(e,t,r=!0){if(this._isDeviceLost===!0)return;this.shadowMap.type===Ru&&(U("WebGPURenderer: PCFSoftShadowMap has been removed. Using PCFShadowMap instead."),this.shadowMap.type=Gn);let i=r?this._getFrameBufferTarget():null,s=this._nodes.nodeFrame,o=s.renderId,a=this._currentRenderContext,l=this._currentRenderObjectFunction,u=this._handleObjectFunction;this.lighting.beginRender(e),this._callDepth++;let c=e.isScene===!0?e:DC,d=this._renderTarget||this._outputRenderTarget,h=this._activeCubeFace,p=this._activeMipmapLevel,f;if(i!==null?(f=i,this.setRenderTarget(f)):f=d,f!==null&&f.depthBuffer===!0){let z=this._textures.get(f);z.depthInitialized!==!0&&((this.autoClear===!1||this.autoClear===!0&&this.autoClearDepth===!1)&&this.clearDepth(),z.depthInitialized=!0)}let m=this._renderContexts.get(f,this._mrt,this._callDepth);this._currentRenderContext=m,this._currentRenderObjectFunction=this._renderObjectFunction||this.renderObject,this._handleObjectFunction=this._renderObjectDirect,this.info.calls++,this.info.render.calls++,this.info.render.frameCalls++,s.renderId=this.info.calls,this.backend.updateTimeStampUID(m),this.inspector.beginRender(this.backend.getTimestampUID(m),e,t,f),e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t=this._updateCamera(t);let g=this._canvasTarget,x=g._viewport,w=g._scissor,v=g._pixelRatio;f!==null&&(x=f.viewport,w=f.scissor,v=1),this.getDrawingBufferSize(hu),hS.set(0,0,hu.width,hu.height);let E=x.minDepth===void 0?0:x.minDepth,b=x.maxDepth===void 0?1:x.maxDepth;m.viewportValue.copy(x).multiplyScalar(v).floor(),m.viewportValue.width>>=p,m.viewportValue.height>>=p,m.viewportValue.minDepth=E,m.viewportValue.maxDepth=b,m.viewport=m.viewportValue.equals(hS)===!1,m.scissorValue.copy(w).multiplyScalar(v).floor(),m.scissor=g._scissorTest&&m.scissorValue.equals(hS)===!1,m.scissorValue.width>>=p,m.scissorValue.height>>=p,m.clippingContext||(m.clippingContext=new nS),m.clippingContext.updateGlobal(c,t),c.onBeforeRender(this,e,t,f),pu.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),t.isArrayCamera?$m.setFromArrayCamera(t):zm.setFromProjectionMatrix(pu,t.coordinateSystem,t.reversedDepth),this._renderLists.update(s.frameId);let S=this._renderLists.get(e,t,this.lighting);if(S.begin(),this._projectObject(e,t,0,S,m.clippingContext),S.finish(),this.sortObjects===!0&&S.sort(this._opaqueSort,this._transparentSort),f!==null){this._textures.updateRenderTarget(f,p);let z=this._textures.get(f);m.textures=z.textures,m.depthTexture=z.depthTexture,m.width=z.width,m.height=z.height,m.renderTarget=f,m.depth=f.depthBuffer,m.stencil=f.stencilBuffer}else m.textures=null,m.depthTexture=null,m.width=hu.width,m.height=hu.height,m.depth=this.depth,m.stencil=this.stencil;m.width>>=p,m.height>>=p,m.activeCubeFace=h,m.activeMipmapLevel=p,m.occlusionQueryCount=S.occlusionQueryCount,m.fullscreenPass=e.isQuadMesh===!0,m.scissorValue.max(Pn.set(0,0,0,0)),m.scissorValue.x+m.scissorValue.width>m.width&&(m.scissorValue.width=Math.max(m.width-m.scissorValue.x,0)),m.scissorValue.y+m.scissorValue.height>m.height&&(m.scissorValue.height=Math.max(m.height-m.scissorValue.y,0)),this._background.update(c,S,m),m.camera=t,this.backend.beginRender(m);let{bundles:T,lightsNode:M,transparentDoublePass:B,transparent:D,opaque:O}=S;return T.length>0&&this._renderBundles(T,c,M),this.opaque===!0&&O.length>0&&this._renderObjects(O,t,c,M),this.transparent===!0&&D.length>0&&this._renderTransparents(D,B,t,c,M),this.backend.finishRender(m),s.renderId=o,this._currentRenderContext=a,this._currentRenderObjectFunction=l,this._handleObjectFunction=u,this.lighting.finishRender(e),this._callDepth--,i!==null&&(this.setRenderTarget(d,h,p),this._renderOutput(f)),c.onAfterRender(this,e,t,f),this.inspector.finishRender(this.backend.getTimestampUID(m)),m}_setXRLayerSize(e,t){this._canvasTarget._width=e,this._canvasTarget._height=t,this.setViewport(0,0,e,t)}_renderOutput(e){let t=this._nodes.getOutputCacheKey(),r=this._quadCache.get(e.texture),i;if(r===void 0){i=new ou(new we),i.name="Output Color Transform",i.material.name="outputColorTransform",i.material.fragmentNode=this._nodes.getOutputNode(e.texture),r={quad:i,cacheKey:t},this._quadCache.set(e.texture,r);let a=()=>{i.material.dispose(),this._quadCache.delete(e.texture),e.texture.removeEventListener("dispose",a)};e.texture.addEventListener("dispose",a)}else i=r.quad,r.cacheKey!==t&&(i.material.fragmentNode=this._nodes.getOutputNode(e.texture),i.material.needsUpdate=!0,r.cacheKey=t);let s=this.autoClear,o=this.xr.enabled;this.autoClear=!1,this.xr.enabled=!1,this._renderOutputLayers(i,e),this.autoClear=s,this.xr.enabled=o}getMaxAnisotropy(){return this.backend.capabilities.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){this._initialized===!1&&await this.init(),this._animation.setAnimationLoop(e)}getAnimationLoop(){return this._animation.getAnimationLoop()}async getArrayBufferAsync(e,t=null,r=0,i=-1){if(t!==null&&t.isReadbackBuffer&&this.info.memoryMap.has(t)===!1){this.info.createReadbackBuffer(t);let s=()=>{t.removeEventListener("dispose",s),this.info.destroyReadbackBuffer(t)};t.addEventListener("dispose",s)}if(r%4!==0||i>0&&i%4!==0)throw new Error('THREE.Renderer: "getArrayBufferAsync()" offset and count must be a multiple of 4.');return await this.backend.getArrayBufferAsync(e,t,r,i)}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,i){this._canvasTarget.setScissor(e,t,r,i)}getScissorTest(){return this._canvasTarget.getScissorTest()}setScissorTest(e){this._canvasTarget.setScissorTest(e),this.backend.setScissorTest(e)}resetState(){if(this._initialized===!1)throw new Error('THREE.Renderer: .resetState() called before the backend is initialized. Use "await renderer.init();" before using this method.');this.backend.resetState()}getViewport(e){return this._canvasTarget.getViewport(e)}setViewport(e,t,r,i,s=0,o=1){this._canvasTarget.setViewport(e,t,r,i,s,o)}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.reversedDepthBuffer===!0?1-this._clearDepth:this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){let t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,r=!0){if(this._initialized===!1)throw new Error('THREE.Renderer: .clear() called before the backend is initialized. Use "await renderer.init();" before using this method.');let i=this._renderTarget||this._getFrameBufferTarget(),s=null;if(i!==null){this._textures.updateRenderTarget(i);let o=this._textures.get(i);s=this._renderContexts.get(i,null,-1),s.textures=o.textures,s.depthTexture=o.depthTexture,s.width=o.width,s.height=o.height,s.renderTarget=i,s.depth=i.depthBuffer,s.stencil=i.stencilBuffer;let a=this.backend.getClearColor();s.clearColorValue.r=a.r,s.clearColorValue.g=a.g,s.clearColorValue.b=a.b,s.clearColorValue.a=a.a,s.clearDepthValue=this.getClearDepth(),s.clearStencilValue=this.getClearStencil(),s.activeCubeFace=this.getActiveCubeFace(),s.activeMipmapLevel=this.getActiveMipmapLevel(),i.depthBuffer===!0&&(o.depthInitialized=!0)}this.backend.clear(e,t,r,s),i!==null&&this._renderTarget===null&&this._renderOutput(i)}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){he('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(){he('Renderer: "clearColorAsync()" has been deprecated. Use "clearColor()" and "await renderer.init();" when creating the renderer.'),this.clear(!0,!1,!1)}async clearDepthAsync(){he('Renderer: "clearDepthAsync()" has been deprecated. Use "clearDepth()" and "await renderer.init();" when creating the renderer.'),this.clear(!1,!0,!1)}async clearStencilAsync(){he('Renderer: "clearStencilAsync()" has been deprecated. Use "clearStencil()" and "await renderer.init();" when creating the renderer.'),this.clear(!1,!1,!0)}get needsFrameBufferTarget(){let e=this.currentToneMapping!==ms,t=this.currentColorSpace!==Me.workingColorSpace;return e||t}get samples(){return this._samples}get currentSamples(){let e=this._samples;return this._renderTarget!==null?e=this._renderTarget.samples:(this.needsFrameBufferTarget||this._currentRenderContext?.fullscreenPass===!0)&&(e=0),e}get currentToneMapping(){return this.isOutputTarget?this.toneMapping:ms}get currentColorSpace(){return this.isOutputTarget?this.outputColorSpace:Me.workingColorSpace}get isOutputTarget(){return this._renderTarget===this._outputRenderTarget||this._renderTarget===null}dispose(){if(this._initialized===!0){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();for(let e of this._frameBufferTargets.keys())e.dispose();Object.values(this.backend.timestampQueryPool).forEach(e=>{e!==null&&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);for(let e of this._frameBufferTargets.keys())e.dispose()}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e,t=null){if(this._isDeviceLost===!0)return;if(this._initialized===!1)return U("Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e,t);let r=this._nodes.nodeFrame,i=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);let s=this.backend,o=this._pipelines,a=this._bindings,l=this._nodes,u=Array.isArray(e)?e:[e];if(u[0]===void 0||u[0].isComputeNode!==!0)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");s.beginCompute(e);for(let c of u){if(o.has(c)===!1){let p=()=>{c.removeEventListener("dispose",p),o.delete(c),a.deleteForCompute(c),l.delete(c)};c.addEventListener("dispose",p);let f=c.onInitFunction;f!==null&&f.call(c,{renderer:this})}l.updateForCompute(c),a.updateForCompute(c);let d=a.getForCompute(c),h=o.getForCompute(c,d);s.compute(e,c,d,h,t)}s.finishCompute(e),r.renderId=i,this.inspector.finishCompute(this.backend.getTimestampUID(e))}async computeAsync(e,t=null){this._initialized===!1&&await this.init(),this.compute(e,t)}async hasFeatureAsync(e){return he('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 this._initialized===!1&&await this.init(),this.backend.resolveTimestampsAsync(e)}hasFeature(e){if(this._initialized===!1)throw new Error('THREE.Renderer: .hasFeature() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this.backend.hasFeature(e)}hasInitialized(){return this._initialized}async initTextureAsync(e){he('Renderer: "initTextureAsync()" has been deprecated. Use "initTexture()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.initTexture(e)}initTexture(e){if(this._initialized===!1)throw new Error('THREE.Renderer: .initTexture() called before the backend is initialized. Use "await renderer.init();" before using this method.');this._textures.updateTexture(e)}initRenderTarget(e){if(this._initialized===!1)throw new Error('THREE.Renderer: .initRenderTarget() called before the backend is initialized. Use "await renderer.init();" before using this method.');this._textures.updateRenderTarget(e);let 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(t!==null)if(t.isVector2)t=Pn.set(t.x,t.y,e.image.width,e.image.height).floor();else if(t.isVector4)t=Pn.copy(t).floor();else{I("Renderer.copyFramebufferToTexture: Invalid rectangle.");return}else t=Pn.set(0,0,e.image.width,e.image.height);let r=this._currentRenderContext,i;r!==null?i=r.renderTarget:(i=this._renderTarget||this._getFrameBufferTarget(),i!==null&&(this._textures.updateRenderTarget(i),r=this._textures.get(i))),this._textures.updateTexture(e,{renderTarget:i}),this.backend.copyFramebufferToTexture(e,r,t),this._inspector.copyFramebufferToTexture(e)}copyTextureToTexture(e,t,r=null,i=null,s=0,o=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,r,i,s,o),this._inspector.copyTextureToTexture(e,t)}async readRenderTargetPixelsAsync(e,t,r,i,s,o=0,a=0){return this.backend.copyTextureToBuffer(e.textures[o],t,r,i,s,a)}_projectObject(e,t,r,i,s){if(e.visible===!1)return;if(e.layers.test(t.layers)){if(e.isGroup)r=e.renderOrder,e.isClippingGroup&&e.enabled&&(s=s.getGroupContext(e));else if(e.isLOD)e.autoUpdate===!0&&e.update(t);else if(e.isLight)i.pushLight(e);else if(e.isSprite){let l=t.isArrayCamera?$m:zm;if(!e.frustumCulled||l.intersectsSprite(e)){this.sortObjects===!0&&Pn.setFromMatrixPosition(e.matrixWorld).applyMatrix4(pu);let{geometry:u,material:c}=e;c.visible&&i.push(e,u,c,r,Pn.z,null,s)}}else if(e.isLineLoop)I("Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if(e.isMesh||e.isLine||e.isPoints){let l=t.isArrayCamera?$m:zm;if(!e.frustumCulled||l.intersectsObject(e)){let{geometry:u,material:c}=e;if(this.sortObjects===!0&&(u.boundingSphere===null&&u.computeBoundingSphere(),Pn.copy(u.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(pu)),Array.isArray(c)){let d=u.groups;for(let h=0,p=d.length;h<p;h++){let f=d[h],m=c[f.materialIndex];m&&m.visible&&i.push(e,u,m,r,Pn.z,f,s)}}else c.visible&&i.push(e,u,c,r,Pn.z,null,s)}}}if(e.isBundleGroup===!0&&this.backend.beginBundle!==void 0){let l=i;i=this._renderLists.get(e,t,this.lighting);let u=this._bundles.get(e,t,this._currentRenderContext),c=this.backend.get(u);if(this._bundleNeedsUpdate(e,c)){i.begin(),c.renderObjects===void 0?c.renderObjects=[]:c.renderObjects.length=0;let h=e.children;for(let p=0,f=h.length;p<f;p++)this._projectObject(h[p],t,r,i,s);i.finish()}l.pushBundle({bundleGroup:e,camera:t,renderList:i});return}let a=e.children;for(let l=0,u=a.length;l<u;l++)this._projectObject(a[l],t,r,i,s)}_renderBundles(e,t,r){for(let i of e)this._renderBundle(i,t,r)}_renderTransparents(e,t,r,i,s){if(t.length>0){for(let{material:o}of t)o.side=Ze;this._renderObjects(t,r,i,s,"backSide");for(let{material:o}of t)o.side=Yr;this._renderObjects(e,r,i,s);for(let{material:o}of t)o.side=Kr}else this._renderObjects(e,r,i,s)}_renderObjects(e,t,r,i,s=null){for(let o=0,a=e.length;o<a;o++){let{object:l,geometry:u,material:c,group:d,clippingContext:h}=e[o];this._currentRenderObjectFunction(l,r,t,u,c,d,i,h,s)}}_getShadowNodes(e){let t=e.version,r=this._cacheShadowNodes.get(e);if(r===void 0||r.version!==t){let i=e.map&&e.map.isTexture,s=e.colorNode&&e.colorNode.isNode,o=e.castShadowNode&&e.castShadowNode.isNode,a=e.maskShadowNode&&e.maskShadowNode.isNode||e.maskNode&&e.maskNode.isNode,l=null,u=null,c=null;if(i||s||o||a){let d,h;if(o?(d=e.castShadowNode.rgb,h=e.castShadowNode.a,this.shadowMap.transmitted!==!0&&he("Renderer: `shadowMap.transmitted` needs to be set to `true` when using `material.castShadowNode`.")):(d=N(0),h=y(1)),i&&(h=h.mul(ke("map","texture",e).a)),s&&(h=h.mul(e.colorNode.a)),u=X(d,h),a){let p=e.maskShadowNode||e.maskNode;u=_(([f])=>(p.not().discard(),f))(u)}}e.depthNode&&e.depthNode.isNode&&(c=e.depthNode),e.castShadowPositionNode&&e.castShadowPositionNode.isNode?l=e.castShadowPositionNode:e.positionNode&&e.positionNode.isNode&&(l=e.positionNode),r={version:t,colorNode:u,depthNode:c,positionNode:l},this._cacheShadowNodes.set(e,r)}return r}_updateCamera(e){let t=this.xr;if(t.isPresenting===!1){let r=!1;if(this.reversedDepthBuffer===!0&&e.reversedDepth!==!0){if(e._reversedDepth=!0,e.isArrayCamera)for(let s of e.cameras)s._reversedDepth=!0;r=!0}let i=this.coordinateSystem;if(e.coordinateSystem!==i){if(e.coordinateSystem=i,e.isArrayCamera)for(let s of e.cameras)s.coordinateSystem=i;r=!0}if(r===!0&&(e.updateProjectionMatrix(),e.isArrayCamera))for(let s of e.cameras)s.updateProjectionMatrix()}return e.parent===null&&e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t.enabled===!0&&t.isPresenting===!0&&(t.cameraAutoUpdate===!0&&t.updateCamera(e),e=t.getCamera()),e}renderObject(e,t,r,i,s,o,a,l=null,u=null){let c=!1,d,h,p,f,m,g,x,w=this._currentSourceMaterial;if(e.onBeforeRender(this,t,r,i,s,o),s.allowOverride===!0&&t.overrideMaterial!==null){this._currentSourceMaterial=s;let v=t.overrideMaterial;if(c=!0,d=v.isNodeMaterial?v.colorNode:null,h=v.isNodeMaterial?v.depthNode:null,p=v.isNodeMaterial?v.positionNode:null,f=t.overrideMaterial.side,m=v.displacementMap,g=v.displacementScale,x=v.displacementBias,s.positionNode&&s.positionNode.isNode&&(v.positionNode=s.positionNode),v.alphaTest=s.alphaTest,v.alphaMap=s.alphaMap,v.displacementMap=s.displacementMap,v.displacementScale=s.displacementScale,v.displacementBias=s.displacementBias,v.transparent=s.transparent||s.transmission>0||s.transmissionNode&&s.transmissionNode.isNode||s.backdropNode&&s.backdropNode.isNode,v.isShadowPassMaterial){let{colorNode:E,depthNode:b,positionNode:S}=this._getShadowNodes(s);this.shadowMap.type===Do?v.side=s.shadowSide!==null?s.shadowSide:s.side:v.side=s.shadowSide!==null?s.shadowSide:MI[s.side],E!==null&&(v.colorNode=E),b!==null&&(v.depthNode=b),S!==null&&(v.positionNode=S)}s=v}s.transparent===!0&&s.side===Kr&&s.forceSinglePass===!1?(s.side=Ze,this._handleObjectFunction(e,s,t,r,a,o,l,"backSide"),s.side=Yr,this._handleObjectFunction(e,s,t,r,a,o,l,u),s.side=Kr):this._handleObjectFunction(e,s,t,r,a,o,l,u),c&&(t.overrideMaterial.colorNode=d,t.overrideMaterial.depthNode=h,t.overrideMaterial.positionNode=p,t.overrideMaterial.side=f,t.overrideMaterial.displacementMap=m,t.overrideMaterial.displacementScale=g,t.overrideMaterial.displacementBias=x),this._currentSourceMaterial=w,e.onAfterRender(this,t,r,i,s,o)}hasCompatibility(e){if(this._initialized===!1)throw new Error('THREE.Renderer: .hasCompatibility() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this.backend.hasCompatibility(e)}_renderObjectDirect(e,t,r,i,s,o,a,l){let u=this._objects.get(e,t,r,i,s,this._currentRenderContext,a,l);u.drawRange=e.geometry.drawRange,u.group=o,this._currentRenderBundle!==null&&(this.backend.get(this._currentRenderBundle).renderObjects.push(u),u.bundle=this._currentRenderBundle.bundleGroup);let c=this._nodes.needsRefresh(u);c&&(this._nodes.updateBefore(u),this._geometries.updateForRender(u),this._nodes.updateForRender(u),this._bindings.updateForRender(u)),this._pipelines.updateForRender(u),this._pipelines.isReady(u)&&(this.backend.draw(u,this.info),c&&this._nodes.updateAfter(u))}_createObjectPipeline(e,t,r,i,s,o,a,l){if(this._compilationPromises!==null){this._compilationPromises.push({object:e,material:t,scene:r,camera:i,lightsNode:s,group:o,clippingContext:a,passId:l,renderContext:this._currentRenderContext});return}let u=this._objects.get(e,t,r,i,s,this._currentRenderContext,a,l);u.drawRange=e.geometry.drawRange,u.group=o,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}},UC=pS;var fS=class{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)}},Wm=fS;function Hm(n){return n+($s-n%$s)%$s}var mS=class extends Wm{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 Hm(this._buffer.byteLength)}get buffer(){return this._buffer}update(){return!0}release(){this._buffer=null}},qm=mS;var gS=class extends qm{constructor(e,t=null){super(e,t),this.isUniformBuffer=!0}},jm=gS;var vI=0,xS=class extends jm{constructor(e,t){super("UniformBuffer_"+vI++,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 byteLength(){return Hm(this.buffer.byteLength)}get buffer(){return this.nodeUniform.value}},Xm=xS;var yS=class extends jm{constructor(e){super(e),this.isUniformsGroup=!0,this._values=null,this.uniforms=[],this._updateRangeCache=new Map,this._addedIndices=new Set}addUniformUpdateRange(e){let t=e.index;if(this._addedIndices.has(t))return;let r=this._updateRangeCache.get(t);r===void 0&&(r={start:0,count:0},this._updateRangeCache.set(t,r)),r.start=e.offset,r.count=e.itemSize,this._addedIndices.add(t),this.updateRanges.push(r)}clearUpdateRanges(){this._addedIndices.clear(),super.clearUpdateRanges()}addUniform(e){return this.uniforms.push(e),this}removeUniform(e){let t=this.uniforms.indexOf(e);return t!==-1&&this.uniforms.splice(t,1),this}get values(){return this._values===null&&(this._values=Array.from(this.buffer)),this._values}get buffer(){let e=this._buffer;if(e===null){let t=this.byteLength;e=new Float32Array(new ArrayBuffer(t)),this._buffer=e}return e}get byteLength(){let e=this.bytesPerElement,t=0;for(let r=0,i=this.uniforms.length;r<i;r++){let s=this.uniforms[r],o=s.boundary,a=s.itemSize*e,l=t%$s,u=l%o,c=l+u;t+=u,c!==0&&$s-c<a&&(t+=$s-c),s.offset=t/e,s.index=r,t+=a}return Math.ceil(t/$s)*$s}update(){let e=!1;for(let t of this.uniforms)this.updateByType(t)===!0&&(e=!0);return e}release(){super.release(),this._values=null}updateByType(e){if(e.isNumberUniform)return this.updateNumber(e);if(e.isVector2Uniform)return this.updateVector2(e);if(e.isVector3Uniform)return this.updateVector3(e);if(e.isVector4Uniform)return this.updateVector4(e);if(e.isColorUniform)return this.updateColor(e);if(e.isMatrix3Uniform)return this.updateMatrix3(e);if(e.isMatrix4Uniform)return this.updateMatrix4(e);I("WebGPUUniformsGroup: Unsupported uniform type.",e)}updateNumber(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset,o=e.getType();if(r[s]!==i){let a=this._getBufferForType(o);a[s]=r[s]=i,t=!0,this.addUniformUpdateRange(e)}return t}updateVector2(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset,o=e.getType();if(r[s+0]!==i.x||r[s+1]!==i.y){let a=this._getBufferForType(o);a[s+0]=r[s+0]=i.x,a[s+1]=r[s+1]=i.y,t=!0,this.addUniformUpdateRange(e)}return t}updateVector3(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset,o=e.getType();if(r[s+0]!==i.x||r[s+1]!==i.y||r[s+2]!==i.z){let a=this._getBufferForType(o);a[s+0]=r[s+0]=i.x,a[s+1]=r[s+1]=i.y,a[s+2]=r[s+2]=i.z,t=!0,this.addUniformUpdateRange(e)}return t}updateVector4(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset,o=e.getType();if(r[s+0]!==i.x||r[s+1]!==i.y||r[s+2]!==i.z||r[s+3]!==i.w){let a=this._getBufferForType(o);a[s+0]=r[s+0]=i.x,a[s+1]=r[s+1]=i.y,a[s+2]=r[s+2]=i.z,a[s+3]=r[s+3]=i.w,t=!0,this.addUniformUpdateRange(e)}return t}updateColor(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset;if(r[s+0]!==i.r||r[s+1]!==i.g||r[s+2]!==i.b){let o=this.buffer;o[s+0]=r[s+0]=i.r,o[s+1]=r[s+1]=i.g,o[s+2]=r[s+2]=i.b,t=!0,this.addUniformUpdateRange(e)}return t}updateMatrix3(e){let t=!1,r=this.values,i=e.getValue().elements,s=e.offset;if(r[s+0]!==i[0]||r[s+1]!==i[1]||r[s+2]!==i[2]||r[s+4]!==i[3]||r[s+5]!==i[4]||r[s+6]!==i[5]||r[s+8]!==i[6]||r[s+9]!==i[7]||r[s+10]!==i[8]){let o=this.buffer;o[s+0]=r[s+0]=i[0],o[s+1]=r[s+1]=i[1],o[s+2]=r[s+2]=i[2],o[s+4]=r[s+4]=i[3],o[s+5]=r[s+5]=i[4],o[s+6]=r[s+6]=i[5],o[s+8]=r[s+8]=i[6],o[s+9]=r[s+9]=i[7],o[s+10]=r[s+10]=i[8],t=!0,this.addUniformUpdateRange(e)}return t}updateMatrix4(e){let t=!1,r=this.values,i=e.getValue().elements,s=e.offset;return RI(r,i,s)===!1&&(this.buffer.set(i,s),AI(r,i,s),t=!0,this.addUniformUpdateRange(e)),t}_getBufferForType(e){return e==="int"||e==="ivec2"||e==="ivec3"||e==="ivec4"?new Int32Array(this.buffer.buffer):e==="uint"||e==="uvec2"||e==="uvec3"||e==="uvec4"?new Uint32Array(this.buffer.buffer):this.buffer}};function AI(n,e,t){for(let r=0,i=e.length;r<i;r++)n[t+r]=e[r]}function RI(n,e,t){for(let r=0,i=e.length;r<i;r++)if(n[t+r]!==e[r])return!1;return!0}var IC=yS;var CI=0,bS=class extends IC{constructor(e,t){super(e),this.id=CI++,this.groupNode=t,this.isNodeUniformsGroup=!0}},Ym=bS;var _S=class extends Wm{constructor(e,t){super(e),this._texture=t,this.version=-1,this.generation=null,this.samplerKey="",this.isSampler=!0}set texture(e){this._texture!==e&&(this._texture=e,this.reset())}get texture(){return this._texture}update(){let{texture:e,version:t}=this;return t!==e.version?(this.version=e.version,!0):!1}reset(){this.generation=null,this.version=-1}release(){this._texture=null}},Km=_S;var EI=0,Qm=class extends Km{constructor(e,t){super(e,t),this.id=EI++,this.store=!1,this.mipLevel=0,this.isSampledTexture=!0}};var Ao=class extends Qm{constructor(e,t,r,i=null){super(e,t?t.value:null),this.textureNode=t,this.groupNode=r,this.access=i}update(){let{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}},fu=class extends Ao{constructor(e,t,r,i=null){super(e,t,r,i),this.isSampledCubeTexture=!0}},ja=class extends Ao{constructor(e,t,r,i=null){super(e,t,r,i),this.isSampledTexture3D=!0}};var OC={bitcast_int_uint:new Qe("uint tsl_bitcast_int_to_uint ( int x ) { return floatBitsToUint( intBitsToFloat ( x ) ); }"),bitcast_uint_int:new Qe("uint tsl_bitcast_uint_to_int ( uint x ) { return floatBitsToInt( uintBitsToFloat ( x ) ); }"),textureGather:new Qe(` | |
| vec4 tsl_textureGather( const int comp, sampler2D map, vec2 coord, ivec2 offset, bool flipY ) { | |
| if ( flipY ) offset.y = - offset.y; | |
| vec2 size = vec2( textureSize( map, 0 ) ); | |
| vec2 st = floor( coord * size + vec2( offset ) - 0.5 ); | |
| vec4 ij = vec4( st + 0.5, st + 1.5 ) / size.xyxy; | |
| vec4 ret = vec4( | |
| textureLod( map, ij.xw, 0.0 )[ comp ], | |
| textureLod( map, ij.zw, 0.0 )[ comp ], | |
| textureLod( map, ij.zy, 0.0 )[ comp ], | |
| textureLod( map, ij.xy, 0.0 )[ comp ] | |
| ); | |
| return flipY ? ret.wzyx : ret; | |
| } | |
| `),textureGatherArray:new Qe(` | |
| vec4 tsl_textureGather_array( const int comp, sampler2DArray map, vec3 coord, ivec2 offset, bool flipY ) { | |
| if ( flipY ) offset.y = - offset.y; | |
| vec2 size = vec2( textureSize( map, 0 ).xy ); | |
| vec2 st = floor( coord.xy * size + vec2( offset ) - 0.5 ); | |
| vec4 ij = vec4( st + 0.5, st + 1.5 ) / size.xyxy; | |
| vec4 ret = vec4( | |
| textureLod( map, vec3( ij.xw, coord.z ), 0.0 )[ comp ], | |
| textureLod( map, vec3( ij.zw, coord.z ), 0.0 )[ comp ], | |
| textureLod( map, vec3( ij.zy, coord.z ), 0.0 )[ comp ], | |
| textureLod( map, vec3( ij.xy, coord.z ), 0.0 )[ comp ] | |
| ); | |
| return flipY ? ret.wzyx : ret; | |
| } | |
| `),textureGatherCompare:new Qe(` | |
| vec4 tsl_textureGatherCompare( sampler2DShadow map, vec2 coord, ivec2 offset, float ref, bool flipY ) { | |
| if ( flipY ) offset.y = - offset.y; | |
| vec2 size = vec2( textureSize( map, 0 ) ); | |
| vec2 st = floor( coord * size + vec2( offset ) - 0.5 ); | |
| vec4 ij = vec4( st + 0.5, st + 1.5 ) / size.xyxy; | |
| vec4 ret = vec4( | |
| textureLod( map, vec3( ij.xw, ref ), 0.0 ), | |
| textureLod( map, vec3( ij.zw, ref ), 0.0 ), | |
| textureLod( map, vec3( ij.zy, ref ), 0.0 ), | |
| textureLod( map, vec3( ij.xy, ref ), 0.0 ) | |
| ); | |
| return flipY ? ret.wzyx : ret; | |
| } | |
| `),textureGatherCompareArray:new Qe(` | |
| vec4 tsl_textureGatherCompare_array( sampler2DArrayShadow map, vec3 coord, ivec2 offset, float ref, bool flipY ) { | |
| if ( flipY ) offset.y = - offset.y; | |
| vec2 size = vec2( textureSize( map, 0 ).xy ); | |
| vec2 st = floor( coord.xy * size + vec2( offset ) - 0.5 ); | |
| vec4 ij = vec4( st + 0.5, st + 1.5 ) / size.xyxy; | |
| vec4 ret = vec4( | |
| texture( map, vec4( ij.xw, coord.z, ref ) ), | |
| texture( map, vec4( ij.zw, coord.z, ref ) ), | |
| texture( map, vec4( ij.zy, coord.z, ref ) ), | |
| texture( map, vec4( ij.xy, coord.z, ref ) ) | |
| ); | |
| return flipY ? ret.wzyx : ret; | |
| } | |
| `)},BI={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"},kC={low:"lowp",medium:"mediump",high:"highp"},VC={swizzleAssign:!0,storageBuffer:!1},GC={perspective:"smooth",linear:"noperspective"},zC={centroid:"centroid"},$C=` | |
| precision highp float; | |
| precision highp int; | |
| precision highp sampler2D; | |
| precision highp sampler3D; | |
| precision highp samplerCube; | |
| precision highp sampler2DArray; | |
| precision highp usampler2D; | |
| precision highp usampler3D; | |
| precision highp usamplerCube; | |
| precision highp usampler2DArray; | |
| precision highp isampler2D; | |
| precision highp isampler3D; | |
| precision highp isamplerCube; | |
| precision highp isampler2DArray; | |
| precision highp sampler2DShadow; | |
| precision highp sampler2DArrayShadow; | |
| precision highp samplerCubeShadow; | |
| `,FI=new Set(["const","uniform","buffer","shared","attribute","varying","coherent","volatile","restrict","readonly","writeonly","atomic_uint","layout","centroid","flat","smooth","noperspective","patch","sample","invariant","precise","break","continue","do","for","while","switch","case","default","if","else","subroutine","in","out","inout","int","void","bool","true","false","float","double","discard","return","vec2","vec3","vec4","ivec2","ivec3","ivec4","bvec2","bvec3","bvec4","uint","uvec2","uvec3","uvec4","dvec2","dvec3","dvec4","mat2","mat3","mat4","mat2x2","mat2x3","mat2x4","mat3x2","mat3x3","mat3x4","mat4x2","mat4x3","mat4x4","dmat2","dmat3","dmat4","dmat2x2","dmat2x3","dmat2x4","dmat3x2","dmat3x3","dmat3x4","dmat4x2","dmat4x3","dmat4x4","lowp","mediump","highp","precision","sampler2D","sampler3D","samplerCube","sampler2DShadow","samplerCubeShadow","sampler2DArray","sampler2DArrayShadow","isampler2D","isampler3D","isamplerCube","isampler2DArray","usampler2D","usampler3D","usamplerCube","usampler2DArray","struct","common","partition","active","asm","class","union","enum","typedef","template","this","resource","goto","inline","noinline","public","static","extern","external","interface","long","short","half","fixed","unsigned","superp","input","output","hvec2","hvec3","hvec4","fvec2","fvec3","fvec4","sampler3DRect","filter","sizeof","cast","namespace","using","main"]),TS=class extends cd{constructor(e,t){super(e,t,new tS),this.uniformGroups={},this.transforms=[],this.extensions={},this.builtins={vertex:[],fragment:[],compute:[]}}needsToWorkingColorSpace(e){return e.isVideoTexture===!0&&e.colorSpace!==Zr}_include(e){let t=OC[e];return t.build(this),this.addInclude(t),t}getMethod(e){return OC[e]!==void 0&&this._include(e),BI[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){let t=e.layout,r=this.flowShaderNode(e),i=[];for(let o of t.inputs)i.push(this.getType(o.type)+" "+o.name);return`${this.getType(t.type)} ${t.name}( ${i.join(", ")} ) { | |
| ${r.vars} | |
| ${r.code} | |
| return ${r.result}; | |
| }`}setupPBO(e){let t=e.value;if(t.pbo===void 0){let r=t.array,i=t.count*t.itemSize,{itemSize:s}=t,o=t.array.constructor.name.toLowerCase().includes("int"),a=o?Fi:Bi;s===2?a=o?Li:vt:s===3?a=o?sl:Ei:s===4&&(a=o?Yn:wt);let l={Float32Array:ze,Uint8Array:it,Uint16Array:er,Uint32Array:Ce,Int8Array:Ci,Int16Array:mr,Int32Array:Je,Uint8ClampedArray:it},u=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(i/s)))),c=Math.ceil(i/s/u);u*c*s<i&&c++;let d=u*c*s,h=new r.constructor(d);h.set(r,0),t.array=h;let p=new yn(t.array,u,c,a,l[t.array.constructor.name]||ze);p.needsUpdate=!0,p.isPBOTexture=!0;let f=new jt(p,null,null);f.setPrecision("high"),t.pboNode=f,t.pbo=f.value,this.getUniformFromNode(t.pboNode,"texture",this.shaderStage,this.context.nodeName)}}getPropertyName(e,t=this.shaderStage){return e.isNodeUniform&&e.node.isTextureNode!==!0&&e.node.isBufferNode!==!0?e.name:super.getPropertyName(e,t)}isReservedKeyword(e){return FI.has(e)}generatePBO(e){let{node:t,indexNode:r}=e,i=t.value;if(this.renderer.backend.has(i)){let c=this.renderer.backend.get(i);c.pbo=i.pbo}let s=this.getUniformFromNode(i.pboNode,"texture",this.shaderStage,this.context.nodeName),o=this.getPropertyName(s);this.increaseUsage(r);let a=r.build(this,"uint"),l=this.getDataFromNode(e),u=l.propertyName;if(u===void 0){let c=this.getVarFromNode(e);u=this.getPropertyName(c);let d=this.getDataFromNode(t),h=d.propertySizeName;h===void 0&&(h=u+"Size",this.getVarFromNode(t,h,"uint"),this.addLineFlowCode(`${h} = uint( textureSize( ${o}, 0 ).x )`,e),d.propertySizeName=h);let{itemSize:p}=i,f="."+ki.join("").slice(0,p),m=`ivec2(${a} % ${h}, ${a} / ${h})`,g=this.generateTextureLoad(null,o,m,"0",null,null),x="vec4";i.pbo.type===Ce?x="uvec4":i.pbo.type===Je&&(x="ivec4"),this.addLineFlowCode(`${u} = ${x}(${g})${f}`,e),l.propertyName=u}return u}generateTextureLoad(e,t,r,i,s,o){i===null&&(i="0");let a;return s?o?a=`texelFetchOffset( ${t}, ivec3( ${r}, ${s} ), int( ${i} ), ${o} )`:a=`texelFetch( ${t}, ivec3( ${r}, ${s} ), int( ${i} ) )`:o?a=`texelFetchOffset( ${t}, ${r}, int( ${i} ), ${o} )`:a=`texelFetch( ${t}, ${r}, int( ${i} ) )`,e!==null&&e.isDepthTexture&&(a+=".x"),a}generateTexture(e,t,r,i,s){return i&&(r=`vec3( ${r}, ${i} )`),e.isDepthTexture?s?`textureOffset( ${t}, ${r}, ${s} ).x`:`texture( ${t}, ${r} ).x`:s?`textureOffset( ${t}, ${r}, ${s} )`:`texture( ${t}, ${r} )`}generateTextureSize(e,t,r){return`textureSize( ${t}, ${r} )`}generateTextureLevel(e,t,r,i,s,o){return s&&(r=`vec3( ${r}, ${s} )`),o?`textureLodOffset( ${t}, ${r}, ${i}, ${o} )`:`textureLod( ${t}, ${r}, ${i} )`}generateTextureBias(e,t,r,i,s,o){return s&&(r=`vec3( ${r}, ${s} )`),o?`textureOffset( ${t}, ${r}, ${o}, ${i} )`:`texture( ${t}, ${r}, ${i} )`}generateTextureGrad(e,t,r,i,s,o){return s&&(r=`vec3( ${r}, ${s} )`),o?`textureGradOffset( ${t}, ${r}, ${i[0]}, ${i[1]}, ${o} )`:`textureGrad( ${t}, ${r}, ${i[0]}, ${i[1]} )`}generateTextureCompare(e,t,r,i,s,o,a=this.shaderStage){if(a==="fragment")return e.isCubeTexture?`texture( ${t}, vec4( ${r}, ${i} ) )`:s?o?`textureOffset( ${t}, vec4( ${r}, ${s}, ${i} ), ${o} )`:`texture( ${t}, vec4( ${r}, ${s}, ${i} ) )`:o?`textureOffset( ${t}, vec3( ${r}, ${i} ), ${o} )`:`texture( ${t}, vec3( ${r}, ${i} ) )`;I(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${a} shader.`)}generateTextureGather(e,t,r,i,s,o,a){return e.isDepthTexture&&(i="0"),o===null&&(o="ivec2( 0 )"),a===null&&(a="false"),s?(this._include("textureGatherArray"),`tsl_textureGather_array( ${i}, ${t}, vec3( ${r}, ${s} ), ${o}, ${a} )`):(this._include("textureGather"),`tsl_textureGather( ${i}, ${t}, ${r}, ${o}, ${a} )`)}generateTextureGatherCompare(e,t,r,i,s,o,a){return o===null&&(o="ivec2( 0 )"),a===null&&(a="false"),s?(this._include("textureGatherCompareArray"),`tsl_textureGatherCompare_array( ${t}, vec3( ${r}, ${s} ), ${o}, ${i}, ${a} )`):(this._include("textureGatherCompare"),`tsl_textureGatherCompare( ${t}, ${r}, ${o}, ${i}, ${a} )`)}getUniforms(e){let t=this.uniforms[e],r=[],i={};for(let o of t){let a=null,l=!1;if(o.type==="texture"||o.type==="texture3D"){let u=o.node,c=u.value,d="";(c.isDataTexture===!0||c.isData3DTexture===!0)&&(c.type===Ce?d="u":c.type===Je&&(d="i")),o.type==="texture3D"&&c.isArrayTexture===!1?a=`${d}sampler3D ${o.name};`:c.compareFunction&&u.compareNode!==null?c.isArrayTexture===!0?a=`sampler2DArrayShadow ${o.name};`:a=`sampler2DShadow ${o.name};`:c.isArrayTexture===!0||c.isDataArrayTexture===!0||c.isCompressedArrayTexture===!0?a=`${d}sampler2DArray ${o.name};`:a=`${d}sampler2D ${o.name};`}else if(o.type==="cubeTexture")a=`samplerCube ${o.name};`;else if(o.type==="cubeDepthTexture")o.node.value.compareFunction?a=`samplerCubeShadow ${o.name};`:a=`samplerCube ${o.name};`;else if(o.type==="buffer"){let u=o.node,c=this.getType(u.bufferType),d=u.bufferCount,h=d>0?d:"";a=`${u.name} { | |
| ${c} ${o.name}[${h}]; | |
| }; | |
| `}else{let u=o.groupNode.name;if(i[u]===void 0){let c=this.uniformGroups[u];if(c!==void 0){let d=[];for(let h of c.uniforms){let p=h.getType(),f=this.getVectorType(p),m=h.nodeUniform.node.precision,g=`${f} ${h.name};`;m!==null&&(g=kC[m]+" "+g),d.push(" "+g)}i[u]=d}}l=!0}if(!l){let u=o.node.precision;u!==null&&(a=kC[u]+" "+a),a="uniform "+a,r.push(a)}}let s="";for(let o in i){let a=i[o];s+=this._getGLSLUniformStruct(o,a.join(` | |
| `))+` | |
| `}return s+=r.join(` | |
| `),s}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==Je){let r=e;e.isInterleavedBufferAttribute&&(r=e.data);let i=r.array;i instanceof Uint32Array||i instanceof Int32Array||(t=t.slice(1))}return t}getAttributes(e){let t="";if(e==="vertex"||e==="compute"){let r=this.getAttributesArray(),i=0;for(let s of r)t+=`layout( location = ${i++} ) in ${s.type} ${s.name}; | |
| `}return t}getStructMembers(e){let t=[];for(let r of e.members)t.push(` ${r.type} ${r.name};`);return t.join(` | |
| `)}getStructs(e){let t=[],r=this.structs[e],i=[];for(let s of r)if(s.output)for(let o of s.members)i.push(`layout( location = ${o.index} ) out ${o.type} ${o.name};`);else{let o="struct "+s.name+` { | |
| `;o+=this.getStructMembers(s),o+=` | |
| }; | |
| `,t.push(o)}return e==="fragment"&&i.length===0&&i.push(`layout( location = 0 ) out ${this.getOutputType()} fragColor;`),` | |
| `+i.join(` | |
| `)+` | |
| `+t.join(` | |
| `)}getVaryings(e){let t="",r=this.varyings;if(e==="vertex"||e==="compute")for(let i of r){e==="compute"&&(i.needsInterpolation=!0);let s=this.getType(i.type);if(i.needsInterpolation)if(i.interpolationType){let o=GC[i.interpolationType]||i.interpolationType,a=zC[i.interpolationSampling]||"";t+=`${o} ${a} out ${s} ${i.name}; | |
| `}else{let o=s.includes("int")||s.includes("uv")||s.includes("iv")?"flat ":"";t+=`${o}out ${s} ${i.name}; | |
| `}else t+=`${s} ${i.name}; | |
| `}else if(e==="fragment"){for(let i of r)if(i.needsInterpolation){let s=this.getType(i.type);if(i.interpolationType){let o=GC[i.interpolationType]||i.interpolationType,a=zC[i.interpolationSampling]||"";t+=`${o} ${a} in ${s} ${i.name}; | |
| `}else{let o=s.includes("int")||s.includes("uv")||s.includes("iv")?"flat ":"";t+=`${o}in ${s} ${i.name}; | |
| `}}}for(let i of this.builtins[e])t+=`${i}; | |
| `;return t}getVertexIndex(){return"uint( gl_VertexID )"}getInstanceIndex(){return"uint( gl_InstanceID )"}getInvocationLocalIndex(){return`uint( gl_InstanceID ) % ${this.object.workgroupSize.reduce((r,i)=>r*i,1)}u`}getSubgroupSize(){I("GLSLNodeBuilder: WebGLBackend does not support the subgroupSize node")}getInvocationSubgroupIndex(){I("GLSLNodeBuilder: WebGLBackend does not support the invocationSubgroupIndex node")}getSubgroupIndex(){I("GLSLNodeBuilder: WebGLBackend does not support the subgroupIndex node")}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":"nodeUniformDrawId"}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,r=this.shaderStage){let i=this.extensions[r]||(this.extensions[r]=new Map);i.has(e)===!1&&i.set(e,{name:e,behavior:t})}getExtensions(e){let t=[];if(e==="vertex"){let i=this.renderer.backend.extensions;this.object.isBatchedMesh&&i.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}let r=this.extensions[e];if(r!==void 0)for(let{name:i,behavior:s}of r.values())t.push(`#extension ${i} : ${s}`);return t.join(` | |
| `)}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=VC[e];if(t===void 0){let r;switch(t=!1,e){case"float32Filterable":r="OES_texture_float_linear";break;case"clipDistance":r="WEBGL_clip_cull_distance";break}if(r!==void 0){let i=this.renderer.backend.extensions;i.has(r)&&(i.get(r),t=!0)}VC[e]=t}return t}isFlipY(){return!0}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(){let e=this.transforms,t="";for(let r=0;r<e.length;r++){let i=e[r],s=this.getPropertyName(i.attributeNode);s&&(t+=`${i.varyingName} = ${s}; | |
| `)}return t}_getGLSLUniformStruct(e,t){return` | |
| layout( std140 ) uniform ${e} { | |
| ${t} | |
| };`}_getGLSLVertexCode(e){return`#version 300 es | |
| ${this.getSignature()} | |
| // extensions | |
| ${e.extensions} | |
| // precision | |
| ${$C} | |
| // structs | |
| ${e.structs} | |
| // uniforms | |
| ${e.uniforms} | |
| // varyings | |
| ${e.varyings} | |
| // attributes | |
| ${e.attributes} | |
| // vars | |
| ${e.vars} | |
| // codes | |
| ${e.codes} | |
| void main() { | |
| // transforms | |
| ${e.transforms} | |
| // flow | |
| ${e.flow} | |
| gl_PointSize = 1.0; | |
| } | |
| `}_getGLSLFragmentCode(e){return`#version 300 es | |
| ${this.getSignature()} | |
| // extensions | |
| ${e.extensions} | |
| // precision | |
| ${$C} | |
| // structs | |
| ${e.structs} | |
| // uniforms | |
| ${e.uniforms} | |
| // varyings | |
| ${e.varyings} | |
| // vars | |
| ${e.vars} | |
| // codes | |
| ${e.codes} | |
| void main() { | |
| // flow | |
| ${e.flow} | |
| } | |
| `}buildCode(){let e=this.material!==null?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(let t in e){let r=`// code | |
| `;r+=this.flowCode[t];let i=this.flowNodes[t],s=i[i.length-1];for(let a of i){let l=this.getFlowData(a),u=a.name;u&&(r.length>0&&(r+=` | |
| `),r+=` // flow -> ${u} | |
| `),r+=`${l.code} | |
| `,a===s&&t!=="compute"&&(r+=`// result | |
| `,t==="vertex"?(r+="gl_Position = ",r+=`${this.format(l.result,s.getNodeType(this),"vec4")};`):t==="fragment"&&(a.outputNode.isOutputStructNode||(r+="fragColor = ",r+=`${this.format(l.result,s.getNodeType(this),this.getOutputType())};`)))}let o=e[t];if(o.extensions=this.getExtensions(t),o.uniforms=this.getUniforms(t),o.attributes=this.getAttributes(t),o.varyings=this.getVaryings(t),o.vars=this.getVars(t,!0),o.structs=this.getStructs(t),o.codes=this.getCodes(t),o.transforms=this.getTransforms(t),o.flow=r,t==="vertex"){let a=this.renderer.backend.extensions;this.object.isBatchedMesh&&a.has("WEBGL_multi_draw")===!1&&(o.uniforms+=` | |
| uniform uint nodeUniformDrawId; | |
| `)}}this.material!==null?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,r,i=null){let s=super.getUniformFromNode(e,t,r,i),o=this.getDataFromNode(e,r,this.globalCache),a=o.uniformGPU;if(a===void 0){let l=e.groupNode,u=l.name,c=this.getBindGroupArray(u,r);if(t==="texture")a=new Ao(s.name,s.node,l),c.push(a);else if(t==="cubeTexture"||t==="cubeDepthTexture")a=new fu(s.name,s.node,l),c.push(a);else if(t==="texture3D")a=new ja(s.name,s.node,l),c.push(a);else if(t==="buffer"){s.name=`buffer${e.id}`;let d=this.getSharedDataFromNode(e),h=d.buffer;h===void 0&&(e.name=`NodeBuffer_${e.id}`,h=new Xm(e,l),h.name=e.name,d.buffer=h),c.push(h),a=h}else{let d=this.uniformGroups[u];d===void 0?(d=new Ym(u,l),this.uniformGroups[u]=d,c.push(d)):c.indexOf(d)===-1&&c.push(d),a=this.getNodeUniform(s,t);let h=a.name;d.uniforms.some(f=>f.name===h)||d.addUniform(a)}o.uniformGPU=a}return s}},WC=TS;var SS=null,mu=null,NS=class{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null,this.timestampQueryPool={[ci.RENDER]:null,[ci.COMPUTE]:null},this.trackTimestamp=e.trackTimestamp===!0}async init(e){this.renderer=e}get coordinateSystem(){}beginRender(){}finishRender(){}setXRTarget(){}beginCompute(){}finishCompute(){}draw(){}compute(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}updateBinding(){}createRenderPipeline(){}createComputePipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}updateSampler(){}destroySampler(){}createDefaultTexture(){}createTexture(){}updateTexture(){}generateMipmaps(){}destroyTexture(){}async copyTextureToBuffer(){}copyTextureToTexture(){}copyFramebufferToTexture(){}createAttribute(){}createIndexAttribute(){}createStorageAttribute(){}createUniformBuffer(){}destroyUniformBuffer(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}updateViewport(){}updateTimeStampUID(e){let t=this.get(e),r=this.renderer.info.frame,i;e.isComputeNode===!0?i="c:"+this.renderer.info.compute.frameCalls:i="r:"+this.renderer.info.render.frameCalls,t.timestampUID=i+":"+e.id+":f"+r}getTimestampUID(e){return this.get(e).timestampUID}getTimestampFrames(e){let t=this.timestampQueryPool[e];return t?t.getTimestampFrames():[]}_getQueryPool(e){let t=e.startsWith("c:")?ci.COMPUTE:ci.RENDER;return this.timestampQueryPool[t]}getTimestamp(e){return this._getQueryPool(e).getTimestamp(e)}get hasTimestamp(){return!1}hasTimestampQuery(e){return this._getQueryPool(e).hasTimestampQuery(e)}isOccluded(){}async resolveTimestampsAsync(e="render"){if(!this.trackTimestamp){he("WebGPURenderer: Timestamp tracking is disabled.");return}let t=this.timestampQueryPool[e];if(!t)return;let r=await t.resolveQueriesAsync();return this.renderer.info[e].timestamp=r,r}async getArrayBufferAsync(){}async hasFeatureAsync(){}hasFeature(){}getDrawingBufferSize(){return SS=SS||new se,this.renderer.getDrawingBufferSize(SS)}setScissorTest(){}resetState(){}getClearColor(){let e=this.renderer;return mu=mu||new iu,e.getClearColor(mu),mu.getRGB(mu),mu}getDomElement(){let e=this.domElement;return e===null&&(e=this.parameters.canvas!==void 0?this.parameters.canvas:Mw(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${tn} 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 t===void 0&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}deleteBindGroupData(){}dispose(){}},Zm=NS;var LI=0,wS=class{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[this.activeBufferIndex^1]}switchBuffers(){this.activeBufferIndex^=1}},MS=class{constructor(e){this.backend=e}createAttribute(e,t){let r=this.backend,{gl:i}=r,s=e.array,o=e.usage||i.STATIC_DRAW,a=e.isInterleavedBufferAttribute?e.data:e,l=r.get(a),u=l.bufferGPU;u===void 0&&(u=this._createBuffer(i,t,s,o),l.bufferGPU=u,l.bufferType=t,l.version=a.version);let c;if(s instanceof Float32Array)c=i.FLOAT;else if(typeof Float16Array<"u"&&s instanceof Float16Array)c=i.HALF_FLOAT;else if(s instanceof Uint16Array)e.isFloat16BufferAttribute?c=i.HALF_FLOAT:c=i.UNSIGNED_SHORT;else if(s instanceof Int16Array)c=i.SHORT;else if(s instanceof Uint32Array)c=i.UNSIGNED_INT;else if(s instanceof Int32Array)c=i.INT;else if(s instanceof Int8Array)c=i.BYTE;else if(s instanceof Uint8Array)c=i.UNSIGNED_BYTE;else if(s instanceof Uint8ClampedArray)c=i.UNSIGNED_BYTE;else throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+s);let d={bufferGPU:u,bufferType:t,type:c,byteLength:s.byteLength,bytesPerElement:s.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:c===i.INT||c===i.UNSIGNED_INT||e.gpuType===Je,id:LI++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){let h=this._createBuffer(i,t,s,o);d=new wS(d,h)}r.set(e,d)}updateAttribute(e){let t=this.backend,{gl:r}=t,i=e.array,s=e.isInterleavedBufferAttribute?e.data:e,o=t.get(s),a=o.bufferType,l=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(r.bindBuffer(a,o.bufferGPU),l.length===0)r.bufferSubData(a,0,i);else{for(let u=0,c=l.length;u<c;u++){let d=l[u];r.bufferSubData(a,d.start*i.BYTES_PER_ELEMENT,i,d.start,d.count)}s.clearUpdateRanges()}r.bindBuffer(a,null),o.version=s.version}destroyAttribute(e){let t=this.backend,{gl:r}=t;e.isInterleavedBufferAttribute&&t.delete(e.data);let i=t.get(e);r.deleteBuffer(i.bufferGPU),t.delete(e)}async getArrayBufferAsync(e,t=null,r=0,i=-1){let s=this.backend,{gl:o}=s,a=e.isInterleavedBufferAttribute?e.data:e,l=s.get(a),{bufferGPU:u}=l,c=i===-1?l.byteLength-r:i,d;if(t===null)d=new Uint8Array(new ArrayBuffer(c));else if(t.isReadbackBuffer){if(t._mapped===!0)throw new Error("THREE.WebGPURenderer: ReadbackBuffer must be released before being used again.");let h=()=>{t.buffer=null,t._mapped=!1,t.removeEventListener("release",h),t.removeEventListener("dispose",h)};t.addEventListener("release",h),t.addEventListener("dispose",h),d=new Uint8Array(new ArrayBuffer(c)),t.buffer=d.buffer}else d=new Uint8Array(t);return o.bindBuffer(o.COPY_READ_BUFFER,u),o.getBufferSubData(o.COPY_READ_BUFFER,r,d),o.bindBuffer(o.COPY_READ_BUFFER,null),o.bindBuffer(o.COPY_WRITE_BUFFER,null),t&&t.isReadbackBuffer?t:d.buffer}_createBuffer(e,t,r,i){let s=e.createBuffer();return e.bindBuffer(t,s),e.bufferData(t,r,i),e.bindBuffer(t,null),s}},HC=MS;var pd,Dn,vS=class{constructor(e){this.backend=e,this.gl=this.backend.gl,this.enabled={},this.parameters={},this.currentFlipSided=null,this.currentCullFace=null,this.currentProgram=null,this.currentBlendingEnabled=!1,this.currentBlending=null,this.currentBlendEquation=null,this.currentBlendEquationAlpha=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(){let e=this.gl;pd={[Jt]:e.FUNC_ADD,[Fd]:e.FUNC_SUBTRACT,[Ld]:e.FUNC_REVERSE_SUBTRACT},Dn={[Zi]:e.ZERO,[Pd]:e.ONE,[Dd]:e.SRC_COLOR,[sn]:e.SRC_ALPHA,[Gd]:e.SRC_ALPHA_SATURATE,[kd]:e.DST_COLOR,[Id]:e.DST_ALPHA,[Ud]:e.ONE_MINUS_SRC_COLOR,[nn]:e.ONE_MINUS_SRC_ALPHA,[Vd]:e.ONE_MINUS_DST_COLOR,[Od]:e.ONE_MINUS_DST_ALPHA};let t=e.getParameter(e.SCISSOR_BOX),r=e.getParameter(e.VIEWPORT);this.currentScissor=new pe().fromArray(t),this.currentViewport=new pe().fromArray(r),this._tempVec4=new pe}enable(e){let{enabled:t}=this;t[e]!==!0&&(this.gl.enable(e),t[e]=!0)}disable(e){let{enabled:t}=this;t[e]!==!1&&(this.gl.disable(e),t[e]=!1)}setFlipSided(e){if(this.currentFlipSided!==e){let{gl:t}=this;e?t.frontFace(t.CW):t.frontFace(t.CCW),this.currentFlipSided=e}}setCullFace(e){let{gl:t}=this;e!==qN?(this.enable(t.CULL_FACE),e!==this.currentCullFace&&(e===jN?t.cullFace(t.BACK):e===XN?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):this.disable(t.CULL_FACE),this.currentCullFace=e}setLineWidth(e){let{currentLineWidth:t,gl:r}=this;e!==t&&(r.lineWidth(e),this.currentLineWidth=e)}setMRTBlending(e,t,r){let i=this.gl,s=this.backend.drawBuffersIndexedExt;if(!s){he("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets.");return}for(let o=0;o<e.length;o++){let a=e[o],l=null;if(t!==null){let u=t.getBlendMode(a.name);u.blending===tl?l=r:u.blending!==Pr&&(l=u)}else l=r;l!==null?this._setMRTBlendingIndex(o,l):s.blendFuncSeparateiOES(o,i.ONE,i.ZERO,i.ONE,i.ZERO)}}_setMRTBlendingIndex(e,t){let{gl:r}=this,i=this.backend.drawBuffersIndexedExt,s=t.blending,o=t.blendSrc,a=t.blendDst,l=t.blendEquation,u=t.premultipliedAlpha;if(s===rn){let c=t.blendSrcAlpha!==null?t.blendSrcAlpha:o,d=t.blendDstAlpha!==null?t.blendDstAlpha:a,h=t.blendEquationAlpha!==null?t.blendEquationAlpha:l;i.blendEquationSeparateiOES(e,pd[l],pd[h]),i.blendFuncSeparateiOES(e,Dn[o],Dn[a],Dn[c],Dn[d])}else if(i.blendEquationSeparateiOES(e,r.FUNC_ADD,r.FUNC_ADD),u)switch(s){case Zt:i.blendFuncSeparateiOES(e,r.ONE,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case zn:i.blendFuncSeparateiOES(e,r.ONE,r.ONE,r.ONE,r.ONE);break;case $n:i.blendFuncSeparateiOES(e,r.ZERO,r.ONE_MINUS_SRC_COLOR,r.ZERO,r.ONE);break;case Wn:i.blendFuncSeparateiOES(e,r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ZERO,r.ONE);break;default:i.blendFuncSeparateiOES(e,r.ONE,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break}else switch(s){case Zt:i.blendFuncSeparateiOES(e,r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case zn:i.blendFuncSeparateiOES(e,r.SRC_ALPHA,r.ONE,r.ONE,r.ONE);break;case $n:i.blendFuncSeparateiOES(e,r.ZERO,r.ONE_MINUS_SRC_COLOR,r.ZERO,r.ONE);break;case Wn:i.blendFuncSeparateiOES(e,r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ZERO,r.ONE);break;default:i.blendFuncSeparateiOES(e,r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break}}setBlending(e,t,r,i,s,o,a,l){let{gl:u}=this;if(e===Pr){this.currentBlendingEnabled===!0&&(this.disable(u.BLEND),this.currentBlendingEnabled=!1);return}if(this.currentBlendingEnabled===!1&&(this.enable(u.BLEND),this.currentBlendingEnabled=!0),e!==rn){if(e!==this.currentBlending||l!==this.currentPremultipledAlpha){if((this.currentBlendEquation!==Jt||this.currentBlendEquationAlpha!==Jt)&&(u.blendEquation(u.FUNC_ADD),this.currentBlendEquation=Jt,this.currentBlendEquationAlpha=Jt),l)switch(e){case Zt:u.blendFuncSeparate(u.ONE,u.ONE_MINUS_SRC_ALPHA,u.ONE,u.ONE_MINUS_SRC_ALPHA);break;case zn:u.blendFunc(u.ONE,u.ONE);break;case $n:u.blendFuncSeparate(u.ZERO,u.ONE_MINUS_SRC_COLOR,u.ZERO,u.ONE);break;case Wn:u.blendFuncSeparate(u.DST_COLOR,u.ONE_MINUS_SRC_ALPHA,u.ZERO,u.ONE);break;default:I("WebGLState: Invalid blending: ",e);break}else switch(e){case Zt:u.blendFuncSeparate(u.SRC_ALPHA,u.ONE_MINUS_SRC_ALPHA,u.ONE,u.ONE_MINUS_SRC_ALPHA);break;case zn:u.blendFuncSeparate(u.SRC_ALPHA,u.ONE,u.ONE,u.ONE);break;case $n:I("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case Wn:I("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:I("WebGLState: Invalid blending: ",e);break}this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlending=e,this.currentPremultipledAlpha=l}return}s=s||t,o=o||r,a=a||i,(t!==this.currentBlendEquation||s!==this.currentBlendEquationAlpha)&&(u.blendEquationSeparate(pd[t],pd[s]),this.currentBlendEquation=t,this.currentBlendEquationAlpha=s),(r!==this.currentBlendSrc||i!==this.currentBlendDst||o!==this.currentBlendSrcAlpha||a!==this.currentBlendDstAlpha)&&(u.blendFuncSeparate(Dn[r],Dn[i],Dn[o],Dn[a]),this.currentBlendSrc=r,this.currentBlendDst=i,this.currentBlendSrcAlpha=o,this.currentBlendDstAlpha=a),this.currentBlending=e,this.currentPremultipledAlpha=!1}setColorMask(e){this.currentColorMask!==e&&(this.gl.colorMask(e,e,e,e),this.currentColorMask=e)}setDepthTest(e){let{gl:t}=this;e?this.enable(t.DEPTH_TEST):this.disable(t.DEPTH_TEST)}setReversedDepth(e){if(this.currentDepthReversed!==e){let 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=Qd[e]),this.currentDepthFunc!==e){let{gl:t}=this;switch(e){case Uo:t.depthFunc(t.NEVER);break;case Io:t.depthFunc(t.ALWAYS);break;case Oo:t.depthFunc(t.LESS);break;case fs:t.depthFunc(t.LEQUAL);break;case ko:t.depthFunc(t.EQUAL);break;case Vo:t.depthFunc(t.GEQUAL);break;case Go:t.depthFunc(t.GREATER);break;case zo:t.depthFunc(t.NOTEQUAL);break;default:t.depthFunc(t.LEQUAL)}this.currentDepthFunc=e}}scissor(e,t,r,i){let s=this._tempVec4.set(e,t,r,i);if(this.currentScissor.equals(s)===!1){let{gl:o}=this;o.scissor(s.x,s.y,s.z,s.w),this.currentScissor.copy(s)}}viewport(e,t,r,i){let s=this._tempVec4.set(e,t,r,i);if(this.currentViewport.equals(s)===!1){let{gl:o}=this;o.viewport(s.x,s.y,s.z,s.w),this.currentViewport.copy(s)}}setScissorTest(e){let t=this.gl;e?this.enable(t.SCISSOR_TEST):this.disable(t.SCISSOR_TEST)}setStencilTest(e){let{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){let{gl:i}=this;e.side===Kr?this.disable(i.CULL_FACE):this.enable(i.CULL_FACE);let s=e.side===Ze;t&&(s=!s),this.setFlipSided(s),e.blending===Zt&&e.transparent===!1?this.setBlending(Pr):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);let o=e.stencilWrite;if(this.setStencilTest(o),o&&(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),e.alphaToCoverage===!0&&this.backend.renderer.currentSamples>0?this.enable(i.SAMPLE_ALPHA_TO_COVERAGE):this.disable(i.SAMPLE_ALPHA_TO_COVERAGE),r>0&&this.currentClippingPlanes!==r)for(let l=0;l<8;l++)l<r?this.enable(12288+l):this.disable(12288+l)}setPolygonOffset(e,t,r){let{gl:i}=this;e?(this.enable(i.POLYGON_OFFSET_FILL),(this.currentPolygonOffsetFactor!==t||this.currentPolygonOffsetUnits!==r)&&(i.polygonOffset(t,r),this.currentPolygonOffsetFactor=t,this.currentPolygonOffsetUnits=r)):this.disable(i.POLYGON_OFFSET_FILL)}useProgram(e){return this.currentProgram!==e?(this.gl.useProgram(e),this.currentProgram=e,!0):!1}setVertexState(e,t=null){let r=this.gl;return this.currentVAO!==e||this.currentIndex!==t?(r.bindVertexArray(e),t!==null&&r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,t),this.currentVAO=e,this.currentIndex=t,!0):!1}resetVertexState(){let e=this.gl;e.bindVertexArray(null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),this.currentVAO=null,this.currentIndex=null}bindFramebuffer(e,t){let{gl:r,currentBoundFramebuffers:i}=this;return i[e]!==t?(r.bindFramebuffer(e,t),i[e]=t,e===r.DRAW_FRAMEBUFFER&&(i[r.FRAMEBUFFER]=t),e===r.FRAMEBUFFER&&(i[r.DRAW_FRAMEBUFFER]=t),!0):!1}drawBuffers(e,t){let{gl:r}=this,i=[],s=!1;if(e.textures!==null){i=this.currentDrawbuffers.get(t),i===void 0&&(i=[],this.currentDrawbuffers.set(t,i));let o=e.textures;if(i.length!==o.length||i[0]!==r.COLOR_ATTACHMENT0){for(let a=0,l=o.length;a<l;a++)i[a]=r.COLOR_ATTACHMENT0+a;i.length=o.length,s=!0}}else i[0]!==r.BACK&&(i[0]=r.BACK,s=!0);s&&r.drawBuffers(i)}activeTexture(e){let{gl:t,currentTextureSlot:r,maxTextures:i}=this;e===void 0&&(e=t.TEXTURE0+i-1),r!==e&&(t.activeTexture(e),this.currentTextureSlot=e)}bindTexture(e,t,r){let{gl:i,currentTextureSlot:s,currentBoundTextures:o,maxTextures:a}=this;r===void 0&&(s===null?r=i.TEXTURE0+a-1:r=s);let l=o[r];l===void 0&&(l={type:void 0,texture:void 0},o[r]=l),(l.type!==e||l.texture!==t)&&(s!==r&&(i.activeTexture(r),this.currentTextureSlot=r),i.bindTexture(e,t),l.type=e,l.texture=t)}bindBufferBase(e,t,r){let{gl:i}=this,s=`${e}-${t}`;return this.currentBoundBufferBases[s]!==r?(i.bindBufferBase(e,t,r),this.currentBoundBufferBases[s]=r,!0):!1}unbindTexture(){let{gl:e,currentTextureSlot:t,currentBoundTextures:r}=this,i=r[t];i!==void 0&&i.type!==void 0&&(e.bindTexture(i.type,null),i.type=void 0,i.texture=void 0)}getParameter(e){let{gl:t,parameters:r}=this;return r[e]!==void 0?r[e]:t.getParameter(e)}pixelStorei(e,t){let{gl:r,parameters:i}=this;i[e]!==t&&(r.pixelStorei(e,t),i[e]=t)}reset(){let{gl:e}=this;e.disable(e.BLEND),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.POLYGON_OFFSET_FILL),e.disable(e.SCISSOR_TEST),e.disable(e.STENCIL_TEST),e.disable(e.SAMPLE_ALPHA_TO_COVERAGE),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ZERO),e.blendFuncSeparate(e.ONE,e.ZERO,e.ONE,e.ZERO),e.blendColor(0,0,0,0),e.colorMask(!0,!0,!0,!0),e.clearColor(0,0,0,0),e.depthMask(!0),e.depthFunc(e.LESS),e.clearDepth(1),e.stencilMask(4294967295),e.stencilFunc(e.ALWAYS,0,4294967295),e.stencilOp(e.KEEP,e.KEEP,e.KEEP),e.clearStencil(0),e.cullFace(e.BACK),e.frontFace(e.CCW),e.polygonOffset(0,0),e.activeTexture(e.TEXTURE0),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null),e.bindFramebuffer(e.READ_FRAMEBUFFER,null),e.useProgram(null),e.lineWidth(1),e.scissor(0,0,e.canvas.width,e.canvas.height),e.viewport(0,0,e.canvas.width,e.canvas.height),e.pixelStorei(e.PACK_ALIGNMENT,4),e.pixelStorei(e.UNPACK_ALIGNMENT,4),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.BROWSER_DEFAULT_WEBGL),e.pixelStorei(e.PACK_ROW_LENGTH,0),e.pixelStorei(e.PACK_SKIP_PIXELS,0),e.pixelStorei(e.PACK_SKIP_ROWS,0),e.pixelStorei(e.UNPACK_ROW_LENGTH,0),e.pixelStorei(e.UNPACK_IMAGE_HEIGHT,0),e.pixelStorei(e.UNPACK_SKIP_PIXELS,0),e.pixelStorei(e.UNPACK_SKIP_ROWS,0),e.pixelStorei(e.UNPACK_SKIP_IMAGES,0),this.resetVertexState(),this.enabled={},this.parameters={},this.currentFlipSided=null,this.currentCullFace=null,this.currentProgram=null,this.currentBlendingEnabled=!1,this.currentBlending=null,this.currentBlendEquation=null,this.currentBlendEquationAlpha=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.currentClippingPlanes=0,this.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.currentTextureSlot=null,this.currentBoundTextures={},this.currentBoundBufferBases={},this.currentScissor.set(0,0,e.canvas.width,e.canvas.height),this.currentViewport.set(0,0,e.canvas.width,e.canvas.height),this.currentDepthReversed=!1,this.backend.renderer.reversedDepthBuffer===!0&&this.setReversedDepth(!0)}},qC=vS;var AS=class{constructor(e){this.backend=e,this.gl=this.backend.gl,this.extensions=e.extensions}convert(e,t=Zr){let{gl:r,extensions:i}=this,s,o=Me.getTransfer(t);if(e===it)return r.UNSIGNED_BYTE;if(e===rl)return r.UNSIGNED_SHORT_4_4_4_4;if(e===il)return r.UNSIGNED_SHORT_5_5_5_1;if(e===qn)return r.UNSIGNED_INT_5_9_9_9_REV;if(e===jn)return r.UNSIGNED_INT_10F_11F_11F_REV;if(e===Ci)return r.BYTE;if(e===mr)return r.SHORT;if(e===er)return r.UNSIGNED_SHORT;if(e===Je)return r.INT;if(e===Ce)return r.UNSIGNED_INT;if(e===ze)return r.FLOAT;if(e===qe)return r.HALF_FLOAT;if(e===Xn)return r.ALPHA;if(e===Ei)return r.RGB;if(e===wt)return r.RGBA;if(e===Mt)return r.DEPTH_COMPONENT;if(e===Ht)return r.DEPTH_STENCIL;if(e===Bi)return r.RED;if(e===Fi)return r.RED_INTEGER;if(e===vt)return r.RG;if(e===Li)return r.RG_INTEGER;if(e===Yn)return r.RGBA_INTEGER;if(e===Kn||e===Qn||e===Zn||e===Jn)if(o===fe)if(s=i.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(e===Kn)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(e===Qn)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(e===Zn)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(e===Jn)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=i.get("WEBGL_compressed_texture_s3tc"),s!==null){if(e===Kn)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(e===Qn)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(e===Zn)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(e===Jn)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(e===Lu||e===Pu||e===Du||e===Uu)if(s=i.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(e===Lu)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(e===Pu)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(e===Du)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(e===Uu)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(e===Ho||e===qo||e===jo||e===Xo||e===Yo||e===an||e===Ko)if(s=i.get("WEBGL_compressed_texture_etc"),s!==null){if(e===Ho||e===qo)return o===fe?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(e===jo)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(e===Xo)return s.COMPRESSED_R11_EAC;if(e===Yo)return s.COMPRESSED_SIGNED_R11_EAC;if(e===an)return s.COMPRESSED_RG11_EAC;if(e===Ko)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(e===Qo||e===Zo||e===Jo||e===ea||e===ta||e===ra||e===ia||e===sa||e===na||e===oa||e===aa||e===la||e===ua||e===ca)if(s=i.get("WEBGL_compressed_texture_astc"),s!==null){if(e===Qo)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(e===Zo)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(e===Jo)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(e===ea)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(e===ta)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(e===ra)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(e===ia)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(e===sa)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(e===na)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(e===oa)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(e===aa)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(e===la)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(e===ua)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(e===ca)return o===fe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(e===da||e===ha||e===pa)if(s=i.get("EXT_texture_compression_bptc"),s!==null){if(e===da)return o===fe?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(e===ha)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(e===pa)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(e===fa||e===ma||e===ln||e===ga)if(s=i.get("EXT_texture_compression_rgtc"),s!==null){if(e===fa)return s.COMPRESSED_RED_RGTC1_EXT;if(e===ma)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(e===ln)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(e===ga)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return e===Qr?r.UNSIGNED_INT_24_8:r[e]!==void 0?r[e]:null}_clientWaitAsync(){let{gl:e}=this,t=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),new Promise((r,i)=>{function s(){let o=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(o===e.WAIT_FAILED){e.deleteSync(t),i();return}if(o===e.TIMEOUT_EXPIRED){requestAnimationFrame(s);return}e.deleteSync(t),r()}s()})}},jC=AS;var XC=!1,Jm,RS,YC,CS=class{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},this._srcFramebuffer=null,this._dstFramebuffer=null,XC===!1&&(this._init(),XC=!0)}_init(){let e=this.gl;Jm={[gs]:e.REPEAT,[Dr]:e.CLAMP_TO_EDGE,[xs]:e.MIRRORED_REPEAT},RS={[Pe]:e.NEAREST,[zd]:e.NEAREST_MIPMAP_NEAREST,[on]:e.NEAREST_MIPMAP_LINEAR,[je]:e.LINEAR,[Fu]:e.LINEAR_MIPMAP_NEAREST,[Ur]:e.LINEAR_MIPMAP_LINEAR},YC={[Hd]:e.NEVER,[Xd]:e.ALWAYS,[ol]:e.LESS,[Pi]:e.LEQUAL,[qd]:e.EQUAL,[ui]:e.GEQUAL,[ya]:e.GREATER,[jd]:e.NOTEQUAL}}getGLTextureType(e){let{gl:t}=this,r;return e.isCubeTexture===!0?r=t.TEXTURE_CUBE_MAP:e.isArrayTexture===!0||e.isDataArrayTexture===!0||e.isCompressedArrayTexture===!0?r=t.TEXTURE_2D_ARRAY:e.isData3DTexture===!0?r=t.TEXTURE_3D:r=t.TEXTURE_2D,r}getInternalFormat(e,t,r,i,s,o=!1){let{gl:a,extensions:l}=this;if(e!==null){if(a[e]!==void 0)return a[e];U("WebGLBackend: Attempt to use non-existing WebGL internal format '"+e+"'")}let u=null;i&&(u=l.get("EXT_texture_norm16"),u||U("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let c=t;if(t===a.RED&&(r===a.FLOAT&&(c=a.R32F),r===a.HALF_FLOAT&&(c=a.R16F),r===a.UNSIGNED_BYTE&&(c=a.R8),r===a.BYTE&&(c=a.R8_SNORM),r===a.UNSIGNED_SHORT&&u&&(c=u.R16_EXT),r===a.SHORT&&u&&(c=u.R16_SNORM_EXT)),t===a.RED_INTEGER&&(r===a.UNSIGNED_BYTE&&(c=a.R8UI),r===a.UNSIGNED_SHORT&&(c=a.R16UI),r===a.UNSIGNED_INT&&(c=a.R32UI),r===a.BYTE&&(c=a.R8I),r===a.SHORT&&(c=a.R16I),r===a.INT&&(c=a.R32I)),t===a.RG&&(r===a.FLOAT&&(c=a.RG32F),r===a.HALF_FLOAT&&(c=a.RG16F),r===a.UNSIGNED_BYTE&&(c=a.RG8),r===a.BYTE&&(c=a.RG8_SNORM),r===a.UNSIGNED_SHORT&&u&&(c=u.RG16_EXT),r===a.SHORT&&u&&(c=u.RG16_SNORM_EXT)),t===a.RG_INTEGER&&(r===a.UNSIGNED_BYTE&&(c=a.RG8UI),r===a.UNSIGNED_SHORT&&(c=a.RG16UI),r===a.UNSIGNED_INT&&(c=a.RG32UI),r===a.BYTE&&(c=a.RG8I),r===a.SHORT&&(c=a.RG16I),r===a.INT&&(c=a.RG32I)),t===a.RGB){let d=o?nl:Me.getTransfer(s);r===a.FLOAT&&(c=a.RGB32F),r===a.HALF_FLOAT&&(c=a.RGB16F),r===a.UNSIGNED_BYTE&&(c=d===fe?a.SRGB8:a.RGB8),r===a.BYTE&&(c=a.RGB8_SNORM),r===a.UNSIGNED_SHORT&&u&&(c=u.RGB16_EXT),r===a.SHORT&&u&&(c=u.RGB16_SNORM_EXT),r===a.UNSIGNED_SHORT_5_6_5&&(c=a.RGB565),r===a.UNSIGNED_SHORT_5_5_5_1&&(c=a.RGB5_A1),r===a.UNSIGNED_SHORT_4_4_4_4&&(c=a.RGB4),r===a.UNSIGNED_INT_5_9_9_9_REV&&(c=a.RGB9_E5),r===a.UNSIGNED_INT_10F_11F_11F_REV&&(c=a.R11F_G11F_B10F)}if(t===a.RGB_INTEGER&&(r===a.UNSIGNED_BYTE&&(c=a.RGB8UI),r===a.UNSIGNED_SHORT&&(c=a.RGB16UI),r===a.UNSIGNED_INT&&(c=a.RGB32UI),r===a.BYTE&&(c=a.RGB8I),r===a.SHORT&&(c=a.RGB16I),r===a.INT&&(c=a.RGB32I)),t===a.RGBA){let d=o?nl:Me.getTransfer(s);r===a.FLOAT&&(c=a.RGBA32F),r===a.HALF_FLOAT&&(c=a.RGBA16F),r===a.UNSIGNED_BYTE&&(c=d===fe?a.SRGB8_ALPHA8:a.RGBA8),r===a.BYTE&&(c=a.RGBA8_SNORM),r===a.UNSIGNED_SHORT&&u&&(c=u.RGBA16_EXT),r===a.SHORT&&u&&(c=u.RGBA16_SNORM_EXT),r===a.UNSIGNED_SHORT_4_4_4_4&&(c=a.RGBA4),r===a.UNSIGNED_SHORT_5_5_5_1&&(c=a.RGB5_A1)}return t===a.RGBA_INTEGER&&(r===a.UNSIGNED_BYTE&&(c=a.RGBA8UI),r===a.UNSIGNED_SHORT&&(c=a.RGBA16UI),r===a.UNSIGNED_INT&&(c=a.RGBA32UI),r===a.BYTE&&(c=a.RGBA8I),r===a.SHORT&&(c=a.RGBA16I),r===a.INT&&(c=a.RGBA32I)),t===a.DEPTH_COMPONENT&&(r===a.UNSIGNED_SHORT&&(c=a.DEPTH_COMPONENT16),r===a.UNSIGNED_INT&&(c=a.DEPTH_COMPONENT24),r===a.FLOAT&&(c=a.DEPTH_COMPONENT32F)),t===a.DEPTH_STENCIL&&r===a.UNSIGNED_INT_24_8&&(c=a.DEPTH24_STENCIL8),(c===a.R16F||c===a.R32F||c===a.RG16F||c===a.RG32F||c===a.RGBA16F||c===a.RGBA32F)&&l.get("EXT_color_buffer_float"),c}setTextureParameters(e,t){let{gl:r,extensions:i,backend:s}=this,{state:o}=this.backend,a=Me.getPrimaries(Me.workingColorSpace),l=t.colorSpace===Zr?null:Me.getPrimaries(t.colorSpace),u=t.colorSpace===Zr||a===l?r.NONE:r.BROWSER_DEFAULT_WEBGL;o.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,t.flipY),o.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),o.pixelStorei(r.UNPACK_ALIGNMENT,t.unpackAlignment),o.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,u),r.texParameteri(e,r.TEXTURE_WRAP_S,Jm[t.wrapS]),r.texParameteri(e,r.TEXTURE_WRAP_T,Jm[t.wrapT]),(e===r.TEXTURE_3D||e===r.TEXTURE_2D_ARRAY)&&(t.isArrayTexture||r.texParameteri(e,r.TEXTURE_WRAP_R,Jm[t.wrapR])),r.texParameteri(e,r.TEXTURE_MAG_FILTER,RS[t.magFilter]);let c=t.mipmaps!==void 0&&t.mipmaps.length>0,d=t.minFilter===je&&c?Ur:t.minFilter;if(r.texParameteri(e,r.TEXTURE_MIN_FILTER,RS[d]),t.compareFunction&&(r.texParameteri(e,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(e,r.TEXTURE_COMPARE_FUNC,YC[t.compareFunction])),i.has("EXT_texture_filter_anisotropic")===!0){if(t.magFilter===Pe||t.minFilter!==on&&t.minFilter!==Ur||t.type===ze&&i.has("OES_texture_float_linear")===!1)return;if(t.anisotropy>1){let h=i.get("EXT_texture_filter_anisotropic");r.texParameterf(e,h.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,s.capabilities.getMaxAnisotropy()))}}}createDefaultTexture(e){let{gl:t,backend:r,defaultTextures:i}=this,s=this.getGLTextureType(e),o=i[s];o===void 0&&(o=t.createTexture(),r.state.bindTexture(s,o),t.texParameteri(s,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(s,t.TEXTURE_MAG_FILTER,t.NEAREST),i[s]=o),r.set(e,{textureGPU:o,glTextureType:s})}createTexture(e,t){let{gl:r,backend:i}=this,s,o,a,l,u;if(e.isExternalTexture===!0)s=e.sourceTexture,o=this.getGLTextureType(e);else{let{levels:c,width:d,height:h,depth:p}=t;a=i.utils.convert(e.format,e.colorSpace),l=i.utils.convert(e.type),u=this.getInternalFormat(e.internalFormat,a,l,e.normalized,e.colorSpace,e.isVideoTexture),s=r.createTexture(),o=this.getGLTextureType(e),i.state.bindTexture(o,s),this.setTextureParameters(o,e),e.isArrayTexture||e.isDataArrayTexture||e.isCompressedArrayTexture?r.texStorage3D(r.TEXTURE_2D_ARRAY,c,u,d,h,p):e.isData3DTexture?r.texStorage3D(r.TEXTURE_3D,c,u,d,h,p):e.isVideoTexture||r.texStorage2D(o,c,u,d,h)}i.set(e,{textureGPU:s,glTextureType:o,glFormat:a,glType:l,glInternalFormat:u})}copyBufferToTexture(e,t){let{gl:r,backend:i}=this,{state:s}=i,{textureGPU:o,glTextureType:a,glFormat:l,glType:u}=i.get(t),{width:c,height:d}=t.source.data;r.bindBuffer(r.PIXEL_UNPACK_BUFFER,e),i.state.bindTexture(a,o),s.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.texSubImage2D(a,0,0,0,c,d,l,u,0),r.bindBuffer(r.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(e,t){let{gl:r}=this,{width:i,height:s}=t,{textureGPU:o,glTextureType:a,glFormat:l,glType:u,glInternalFormat:c}=this.backend.get(e);if(!(e.isRenderTargetTexture||o===void 0))if(this.backend.state.bindTexture(a,o),this.setTextureParameters(a,e),e.isCompressedTexture){let d=e.mipmaps,h=t.image;for(let p=0;p<d.length;p++){let f=d[p];if(e.isCompressedArrayTexture)if(e.format!==r.RGBA)if(l!==null)if(e.layerUpdates.size>0){let m=Zg(f.width,f.height,e.format,e.type);for(let g of e.layerUpdates){let x=f.data.subarray(g*m/f.data.BYTES_PER_ELEMENT,(g+1)*m/f.data.BYTES_PER_ELEMENT);r.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,p,0,0,g,f.width,f.height,1,l,x)}}else r.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,p,0,0,0,f.width,f.height,h.depth,l,f.data);else U("WebGLBackend: Attempt to load unsupported compressed texture format in .uploadTexture()");else r.texSubImage3D(r.TEXTURE_2D_ARRAY,p,0,0,0,f.width,f.height,h.depth,l,u,f.data);else l!==null?r.compressedTexSubImage2D(r.TEXTURE_2D,p,0,0,f.width,f.height,l,f.data):U("WebGLBackend: Unsupported compressed texture format")}e.isCompressedArrayTexture&&e.layerUpdates.size>0&&e.clearLayerUpdates()}else if(e.isCubeTexture){let d=t.images,h=e.mipmaps;for(let p=0;p<6;p++){let f=eg(d[p]);r.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+p,0,0,0,i,s,l,u,f);for(let m=0;m<h.length;m++){let g=h[m],x=eg(g.images[p]);r.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+p,m+1,0,0,x.width,x.height,l,u,x)}}}else if(e.isDataArrayTexture||e.isArrayTexture){let d=t.image;if(e.layerUpdates.size>0){let h=Zg(d.width,d.height,e.format,e.type);for(let p of e.layerUpdates){let f=d.data.subarray(p*h/d.data.BYTES_PER_ELEMENT,(p+1)*h/d.data.BYTES_PER_ELEMENT);r.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,p,d.width,d.height,1,l,u,f)}e.clearLayerUpdates()}else r.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,0,d.width,d.height,d.depth,l,u,d.data)}else if(e.isData3DTexture){let d=t.image;r.texSubImage3D(r.TEXTURE_3D,0,0,0,0,d.width,d.height,d.depth,l,u,d.data)}else if(e.isVideoTexture)e.update(),r.texImage2D(a,0,c,l,u,t.image);else if(e.isHTMLTexture)typeof r.texElementImage2D=="function"&&(r.texElementImage2D.length===3?r.texElementImage2D(r.TEXTURE_2D,r.RGBA8,t.image):r.texElementImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t.image));else{let d=e.mipmaps;if(d.length>0)for(let h=0,p=d.length;h<p;h++){let f=d[h],m=eg(f);r.texSubImage2D(a,h,0,0,f.width,f.height,l,u,m)}else{let h=eg(t.image);r.texSubImage2D(a,0,0,0,i,s,l,u,h)}}}generateMipmaps(e){let{gl:t,backend:r}=this,{textureGPU:i,glTextureType:s}=r.get(e);r.state.bindTexture(s,i),t.generateMipmap(s)}deallocateRenderBuffers(e){let{gl:t,backend:r}=this;if(e){let i=r.get(e);if(i.renderBufferStorageSetup=void 0,i.framebuffers){for(let s in i.framebuffers)t.deleteFramebuffer(i.framebuffers[s]);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 s=0;s<i.msaaRenderbuffers.length;s++)t.deleteRenderbuffer(i.msaaRenderbuffers[s]);delete i.msaaRenderbuffers}}}destroyTexture(e,t=!1){let{gl:r,backend:i}=this,{textureGPU:s,renderTarget:o}=i.get(e);this.deallocateRenderBuffers(o),t===!1&&e.isExternalTexture!==!0&&r.deleteTexture(s),i.delete(e)}copyTextureToTexture(e,t,r=null,i=null,s=0,o=0){let{gl:a,backend:l}=this,{state:u}=this.backend,{textureGPU:c,glTextureType:d,glType:h,glFormat:p}=l.get(t);u.bindTexture(d,c);let f,m,g,x,w,v,E,b,S,T=e.isCompressedTexture?e.mipmaps[o]:e.image;if(r!==null)f=r.max.x-r.min.x,m=r.max.y-r.min.y,g=r.isBox3?r.max.z-r.min.z:1,x=r.min.x,w=r.min.y,v=r.isBox3?r.min.z:0;else{let H=Math.pow(2,-s);f=Math.floor(T.width*H),m=Math.floor(T.height*H),e.isDataArrayTexture||e.isArrayTexture?g=T.depth:e.isData3DTexture?g=Math.floor(T.depth*H):g=1,x=0,w=0,v=0}i!==null?(E=i.x,b=i.y,S=i.z):(E=0,b=0,S=0),u.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,t.flipY),u.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),u.pixelStorei(a.UNPACK_ALIGNMENT,t.unpackAlignment);let M=u.getParameter(a.UNPACK_ROW_LENGTH),B=u.getParameter(a.UNPACK_IMAGE_HEIGHT),D=u.getParameter(a.UNPACK_SKIP_PIXELS),O=u.getParameter(a.UNPACK_SKIP_ROWS),z=u.getParameter(a.UNPACK_SKIP_IMAGES);u.pixelStorei(a.UNPACK_ROW_LENGTH,T.width),u.pixelStorei(a.UNPACK_IMAGE_HEIGHT,T.height),u.pixelStorei(a.UNPACK_SKIP_PIXELS,x),u.pixelStorei(a.UNPACK_SKIP_ROWS,w),u.pixelStorei(a.UNPACK_SKIP_IMAGES,v);let Q=e.isDataArrayTexture||e.isData3DTexture||t.isArrayTexture,oe=t.isDataArrayTexture||t.isData3DTexture||t.isArrayTexture;if(e.isDepthTexture){let H=l.get(e),ae=l.get(t),de=l.get(H.renderTarget),me=l.get(ae.renderTarget),Ae=de.framebuffers[H.cacheKey],ge=me.framebuffers[ae.cacheKey],Oe=u.currentBoundFramebuffers[a.READ_FRAMEBUFFER]??null,Ge=u.currentBoundFramebuffers[a.DRAW_FRAMEBUFFER]??null;u.bindFramebuffer(a.READ_FRAMEBUFFER,Ae),u.bindFramebuffer(a.DRAW_FRAMEBUFFER,ge);for(let He=0;He<g;He++)Q&&(a.framebufferTextureLayer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,H.textureGPU,s,v+He),a.framebufferTextureLayer(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,c,o,S+He)),a.blitFramebuffer(x,w,f,m,E,b,f,m,a.DEPTH_BUFFER_BIT,a.NEAREST);u.bindFramebuffer(a.READ_FRAMEBUFFER,Oe),u.bindFramebuffer(a.DRAW_FRAMEBUFFER,Ge)}else if(s!==0||e.isRenderTargetTexture||l.has(e)){let H=l.get(e);this._srcFramebuffer===null&&(this._srcFramebuffer=a.createFramebuffer()),this._dstFramebuffer===null&&(this._dstFramebuffer=a.createFramebuffer());let ae=u.currentBoundFramebuffers[a.READ_FRAMEBUFFER]??null,de=u.currentBoundFramebuffers[a.DRAW_FRAMEBUFFER]??null;u.bindFramebuffer(a.READ_FRAMEBUFFER,this._srcFramebuffer),u.bindFramebuffer(a.DRAW_FRAMEBUFFER,this._dstFramebuffer);for(let me=0;me<g;me++)Q?a.framebufferTextureLayer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,H.textureGPU,s,v+me):a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,H.textureGPU,s),oe?a.framebufferTextureLayer(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,c,o,S+me):a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,c,o),s!==0?a.blitFramebuffer(x,w,f,m,E,b,f,m,a.COLOR_BUFFER_BIT,a.NEAREST):oe?a.copyTexSubImage3D(d,o,E,b,S+me,x,w,f,m):a.copyTexSubImage2D(d,o,E,b,x,w,f,m);u.bindFramebuffer(a.READ_FRAMEBUFFER,ae),u.bindFramebuffer(a.DRAW_FRAMEBUFFER,de)}else oe?e.isDataTexture||e.isData3DTexture?a.texSubImage3D(d,o,E,b,S,f,m,g,p,h,T.data):t.isCompressedArrayTexture?a.compressedTexSubImage3D(d,o,E,b,S,f,m,g,p,T.data):a.texSubImage3D(d,o,E,b,S,f,m,g,p,h,T):e.isDataTexture?a.texSubImage2D(a.TEXTURE_2D,o,E,b,f,m,p,h,T.data):e.isCompressedTexture?a.compressedTexSubImage2D(a.TEXTURE_2D,o,E,b,T.width,T.height,p,T.data):a.texSubImage2D(a.TEXTURE_2D,o,E,b,f,m,p,h,T);u.pixelStorei(a.UNPACK_ROW_LENGTH,M),u.pixelStorei(a.UNPACK_IMAGE_HEIGHT,B),u.pixelStorei(a.UNPACK_SKIP_PIXELS,D),u.pixelStorei(a.UNPACK_SKIP_ROWS,O),u.pixelStorei(a.UNPACK_SKIP_IMAGES,z),o===0&&t.generateMipmaps&&a.generateMipmap(d),u.unbindTexture()}copyFramebufferToTexture(e,t,r){let{gl:i}=this,{state:s}=this.backend,{textureGPU:o}=this.backend.get(e),{x:a,y:l,z:u,w:c}=r,d=e.isDepthTexture===!0||t.renderTarget&&t.renderTarget.samples>0,h=t.renderTarget?t.renderTarget.height:this.backend.getDrawingBufferSize().y;if(d){let p=a!==0||l!==0,f,m;if(e.isDepthTexture===!0?(f=i.DEPTH_BUFFER_BIT,m=i.DEPTH_ATTACHMENT,t.stencil&&(f|=i.STENCIL_BUFFER_BIT)):(f=i.COLOR_BUFFER_BIT,m=i.COLOR_ATTACHMENT0),p){let g=this.backend.get(t.renderTarget),x=g.framebuffers[t.getCacheKey()],w=g.msaaFrameBuffer;s.bindFramebuffer(i.DRAW_FRAMEBUFFER,x),s.bindFramebuffer(i.READ_FRAMEBUFFER,w);let v=h-l-c;i.blitFramebuffer(a,v,a+u,v+c,a,v,a+u,v+c,f,i.NEAREST),s.bindFramebuffer(i.READ_FRAMEBUFFER,x),s.bindTexture(i.TEXTURE_2D,o),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,v,u,c),s.unbindTexture()}else{let g=i.createFramebuffer();s.bindFramebuffer(i.DRAW_FRAMEBUFFER,g),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,m,i.TEXTURE_2D,o,0),i.blitFramebuffer(0,0,u,c,0,0,u,c,f,i.NEAREST),i.deleteFramebuffer(g)}}else s.bindTexture(i.TEXTURE_2D,o),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,h-c-l,u,c),s.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t,r,i=!1){let{gl:s}=this,o=t.renderTarget,{depthTexture:a,depthBuffer:l,stencilBuffer:u,width:c,height:d}=o;if(s.bindRenderbuffer(s.RENDERBUFFER,e),l&&!u){let h=s.DEPTH_COMPONENT24;i===!0?this.extensions.get("WEBGL_multisampled_render_to_texture").renderbufferStorageMultisampleEXT(s.RENDERBUFFER,o.samples,h,c,d):r>0?(a&&a.isDepthTexture&&a.type===s.FLOAT&&(h=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,r,h,c,d)):s.renderbufferStorage(s.RENDERBUFFER,h,c,d),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else l&&u&&(r>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,r,s.DEPTH24_STENCIL8,c,d):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,c,d),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e));s.bindRenderbuffer(s.RENDERBUFFER,null)}async copyTextureToBuffer(e,t,r,i,s,o){let{backend:a,gl:l}=this,{textureGPU:u,glFormat:c,glType:d}=this.backend.get(e),h=l.createFramebuffer();a.state.bindFramebuffer(l.READ_FRAMEBUFFER,h);let p=e.isCubeTexture?l.TEXTURE_CUBE_MAP_POSITIVE_X+o:l.TEXTURE_2D;l.framebufferTexture2D(l.READ_FRAMEBUFFER,l.COLOR_ATTACHMENT0,p,u,0);let f=this._getTypedArrayType(d),m=this._getBytesPerTexel(d,c),x=i*s*m,w=l.createBuffer();l.bindBuffer(l.PIXEL_PACK_BUFFER,w),l.bufferData(l.PIXEL_PACK_BUFFER,x,l.STREAM_READ),l.readPixels(t,r,i,s,c,d,0),l.bindBuffer(l.PIXEL_PACK_BUFFER,null),await a.utils._clientWaitAsync();let v=new f(x/f.BYTES_PER_ELEMENT);return l.bindBuffer(l.PIXEL_PACK_BUFFER,w),l.getBufferSubData(l.PIXEL_PACK_BUFFER,0,v),l.bindBuffer(l.PIXEL_PACK_BUFFER,null),a.state.bindFramebuffer(l.READ_FRAMEBUFFER,null),l.deleteFramebuffer(h),v}_getTypedArrayType(e){let{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4||e===t.UNSIGNED_SHORT_5_5_5_1||e===t.UNSIGNED_SHORT_5_6_5||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(`THREE.WebGLTextureUtils: Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){let{gl:r}=this,i=0;if(e===r.UNSIGNED_BYTE&&(i=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)&&(i=2),(e===r.UNSIGNED_INT||e===r.FLOAT)&&(i=4),t===r.RGBA)return i*4;if(t===r.RGB)return i*3;if(t===r.ALPHA)return i}dispose(){let{gl:e}=this;this._srcFramebuffer!==null&&e.deleteFramebuffer(this._srcFramebuffer),this._dstFramebuffer!==null&&e.deleteFramebuffer(this._dstFramebuffer)}};function eg(n){return n.isDataTexture?n.image.data:typeof HTMLImageElement<"u"&&n instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&n instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&n instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&n instanceof OffscreenCanvas?n:n.data}var KC=CS;var ES=class{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 t===void 0&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}},QC=ES;var BS=class{constructor(e){this.backend=e,this.maxAnisotropy=null,this.maxUniformBlockSize=null}getMaxAnisotropy(){if(this.maxAnisotropy!==null)return this.maxAnisotropy;let e=this.backend.gl,t=this.backend.extensions;if(t.has("EXT_texture_filter_anisotropic")===!0){let r=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(r.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}getUniformBufferLimit(){if(this.maxUniformBlockSize!==null)return this.maxUniformBlockSize;let e=this.backend.gl;return this.maxUniformBlockSize=e.getParameter(e.MAX_UNIFORM_BLOCK_SIZE),this.maxUniformBlockSize}},ZC=BS;var FS={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"};var tg=class{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){let{gl:r,mode:i,object:s,type:o,info:a,index:l}=this;l!==0?r.drawElements(i,t,o,e):r.drawArrays(i,e,t),a.update(s,t,1)}renderInstances(e,t,r){let{gl:i,mode:s,type:o,index:a,object:l,info:u}=this;r!==0&&(a!==0?i.drawElementsInstanced(s,t,o,e,r):i.drawArraysInstanced(s,e,t,r),u.update(l,t,r))}renderMultiDraw(e,t,r){let{extensions:i,mode:s,object:o,info:a}=this;if(r===0)return;let l=i.get("WEBGL_multi_draw");if(l===null)for(let u=0;u<r;u++)this.render(e[u],t[u]);else{this.index!==0?l.multiDrawElementsWEBGL(s,t,0,this.type,e,0,r):l.multiDrawArraysWEBGL(s,e,0,t,0,r);let u=0;for(let c=0;c<r;c++)u+=t[c];a.update(o,u,1)}}};var LS=class{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 t===void 0&&(U(`TimestampQueryPool: No timestamp available for uid ${e}.`),t=0),t}hasTimestampQuery(e){return this.timestamps.has(e)}allocateQueriesForContext(){}async resolveQueriesAsync(){}dispose(){}},rg=LS;var PS=class extends rg{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){U("EXT_disjoint_timer_query not supported; timestamps will be disabled."),this.trackTimestamp=!1;return}this.queries=[];for(let i=0;i<this.maxQueries;i++)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 he(`WebGLTimestampQueryPool [${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;let 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;let t=this.queryOffsets.get(e);if(t==null||this.activeQuery!==null)return;let r=this.queries[t];if(r)try{this.queryStates.get(t)==="inactive"&&(this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT,r),this.activeQuery=t,this.queryStates.set(t,"started"))}catch(i){I("Error in beginQuery:",i),this.activeQuery=null,this.queryStates.set(t,"inactive")}}endQuery(e){if(!this.trackTimestamp||this.isDisposed)return;let t=this.queryOffsets.get(e);if(t!=null&&this.activeQuery===t)try{this.gl.endQuery(this.ext.TIME_ELAPSED_EXT),this.queryStates.set(t,"ended"),this.activeQuery=null}catch(r){I("Error in endQuery:",r),this.queryStates.set(t,"inactive"),this.activeQuery=null}}async resolveQueriesAsync(){if(!this.trackTimestamp||this.pendingResolve)return this.lastValue;this.pendingResolve=!0;try{let e=new Map;for(let[s,o]of this.queryOffsets)if(this.queryStates.get(o)==="ended"){let l=this.queries[o];e.set(s,this.resolveQuery(l))}if(e.size===0)return this.lastValue;let t={},r=[];for(let[s,o]of e){let a=s.match(/^(.*):f(\d+)$/),l=parseInt(a[2]);r.includes(l)===!1&&r.push(l),t[l]===void 0&&(t[l]=0);let u=await o;this.timestamps.set(s,u),t[l]+=u}let i=t[r[r.length-1]];return this.lastValue=i,this.frames=r,this.currentQueryIndex=0,this.queryOffsets.clear(),this.queryStates.clear(),this.activeQuery=null,i}catch(e){return I("Error resolving queries:",e),this.lastValue}finally{this.pendingResolve=!1}}async resolveQuery(e){return new Promise(t=>{if(this.isDisposed){t(this.lastValue);return}let r,i=!1,s=()=>{r&&(clearTimeout(r),r=null)},o=l=>{i||(i=!0,s(),t(l))},a=()=>{if(this.isDisposed){o(this.lastValue);return}try{if(this.gl.getParameter(this.ext.GPU_DISJOINT_EXT)){o(this.lastValue);return}if(!this.gl.getQueryParameter(e,this.gl.QUERY_RESULT_AVAILABLE)){r=setTimeout(a,1);return}let c=this.gl.getQueryParameter(e,this.gl.QUERY_RESULT);t(Number(c)/1e6)}catch(l){I("Error checking query:",l),t(this.lastValue)}};a()})}dispose(){if(!this.isDisposed&&(this.isDisposed=!0,!!this.trackTimestamp)){for(let e of this.queries)this.gl.deleteQuery(e);this.queries=[],this.queryStates.clear(),this.queryOffsets.clear(),this.lastValue=0,this.activeQuery=null}}},JC=PS;var fd=[],DS=class extends Zm{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=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),this._xrFramebuffer=null}init(e){super.init(e);let t=this.parameters,r={antialias:e.currentSamples>0,alpha:!0,depth:e.depth,stencil:e.stencil},i=t.context!==void 0?t.context:e.domElement.getContext("webgl2",r);function s(o){o.preventDefault();let a={api:"WebGL",message:o.statusMessage||"Unknown reason",reason:null,originalEvent:o};e.onDeviceLost(a)}this._onContextLost=s,e.domElement.addEventListener("webglcontextlost",s,!1),this.gl=i,this.extensions=new QC(this),this.capabilities=new ZC(this),this.attributeUtils=new HC(this),this.textureUtils=new KC(this),this.bufferRenderer=new tg(this),this.state=new qC(this),this.utils=new jC(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"),t.reversedDepthBuffer&&(this.extensions.has("EXT_clip_control")?e.reversedDepthBuffer=!0:(U("WebGPURenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer."),e.reversedDepthBuffer=!1)),e.reversedDepthBuffer&&this.state.setReversedDepth(!0)}get coordinateSystem(){return At}get hasTimestamp(){return this.disjoint!==null}async getArrayBufferAsync(e,t=null,r=0,i=-1){return await this.attributeUtils.getArrayBufferAsync(e,t,r,i)}async makeXRCompatible(){this.gl.getContextAttributes().xrCompatible!==!0&&await this.gl.makeXRCompatible()}setXRTarget(e){this._xrFramebuffer=e}setXRRenderTargetTextures(e,t,r=null){let i=this.gl;if(this.set(e.texture,{textureGPU:t,glInternalFormat:i.RGBA8}),r!==null){let s=e.stencilBuffer?i.DEPTH24_STENCIL8:i.DEPTH_COMPONENT24;this.set(e.depthTexture,{textureGPU:r,glInternalFormat:s}),this.extensions.has("WEBGL_multisampled_render_to_texture")===!0&&e._autoAllocateDepthBuffer===!0&&e.multiview===!1&&U("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 JC(this.gl,e,2048));let r=this.timestampQueryPool[e];r.allocateQueriesForContext(t)!==null&&r.beginQuery(t)}prepareTimestampBuffer(e,t){if(!this.disjoint||!this.trackTimestamp)return;this.timestampQueryPool[e].endQuery(t)}getContext(){return this.gl}beginRender(e){let{state:t}=this,r=this.get(e);if(e.viewport)this.updateViewport(e);else{let{width:s,height:o}=this.getDrawingBufferSize();t.viewport(0,0,s,o)}if(e.scissor)this.updateScissor(e);else{let{width:s,height:o}=this.getDrawingBufferSize();t.scissor(0,0,s,o)}this.initTimestampQuery(ci.RENDER,this.getTimestampUID(e)),r.previousContext=this._currentContext,this._currentContext=e,this._setFramebuffer(e),this.clear(e.clearColor,e.clearDepth,e.clearStencil,e,!1);let i=e.occlusionQueryCount;i>0?(r.currentOcclusionQueries=r.occlusionQueries,r.currentOcclusionQueryObjects=r.occlusionQueryObjects,r.lastOcclusionObject=null,r.occlusionQueries=new Array(i),r.occlusionQueryObjects=new Array(i),r.occlusionQueryIndex=0):r.lastOcclusionObject!==void 0&&(r.lastOcclusionObject=void 0)}finishRender(e){let{gl:t,state:r}=this,i=this.get(e),s=i.previousContext;if(r.resetVertexState(),e.occlusionQueryCount>0){let l=i.lastOcclusionObject;l&&l.occlusionTest===!0&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e)}let a=e.textures;if(a!==null)for(let l=0;l<a.length;l++){let u=a[l];u.generateMipmaps&&this.generateMipmaps(u)}if(this._currentContext=s,this._resolveRenderTarget(e),s!==null){if(this._setFramebuffer(s),s.viewport)this.updateViewport(s);else{let{width:l,height:u}=this.getDrawingBufferSize();r.viewport(0,0,l,u)}if(s.scissor)this.updateScissor(s);else{let{width:l,height:u}=this.getDrawingBufferSize();r.scissor(0,0,l,u)}}this.prepareTimestampBuffer(ci.RENDER,this.getTimestampUID(e))}resolveOccludedAsync(e){let t=this.get(e),{currentOcclusionQueries:r,currentOcclusionQueryObjects:i}=t;if(r&&i){let s=new WeakSet,{gl:o}=this;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueries=null;let a=()=>{let l=!0;for(let u=0;u<r.length;u++){let c=r[u];c&&(o.getQueryParameter(c,o.QUERY_RESULT_AVAILABLE)?(o.getQueryParameter(c,o.QUERY_RESULT)===0&&s.add(i[u]),r[u]=null,o.deleteQuery(c)):l=!1)}l===!1?requestAnimationFrame(a):t.occluded=s};a()}}isOccluded(e,t){let r=this.get(e);return r.occluded&&r.occluded.has(t)}updateViewport(e){let{state:t}=this,{x:r,y:i,width:s,height:o}=e.viewportValue;t.viewport(r,e.height-o-i,s,o)}updateScissor(e){let{state:t}=this,{x:r,y:i,width:s,height:o}=e.scissorValue;t.scissor(r,e.height-o-i,s,o)}setScissorTest(e){this.state.setScissorTest(e)}resetState(){this.state.reset()}getClearColor(){let e=super.getClearColor();return e.r*=e.a,e.g*=e.a,e.b*=e.a,e}clear(e,t,r,i=null,s=!0,o=!0){let{gl:a,renderer:l}=this;i===null&&(i={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),u!==0){let c;i.clearColorValue?c=i.clearColorValue:c=this.getClearColor();let d=l.getClearDepth(),h=l.getClearStencil();if(t&&this.state.setDepthMask(!0),i.textures===null)a.clearColor(c.r,c.g,c.b,c.a),a.clear(u);else{if(s&&this._setFramebuffer(i),e)for(let p=0;p<i.textures.length;p++)p===0?a.clearBufferfv(a.COLOR,p,[c.r,c.g,c.b,c.a]):a.clearBufferfv(a.COLOR,p,[0,0,0,1]);t&&r?a.clearBufferfi(a.DEPTH_STENCIL,0,d,h):t?a.clearBufferfv(a.DEPTH,0,[d]):r&&a.clearBufferiv(a.STENCIL,0,[h]),s&&o&&this._resolveRenderTarget(i),s&&this._currentContext!==null&&this._currentContext!==i&&this._setFramebuffer(this._currentContext)}}}beginCompute(e){let{state:t,gl:r}=this;t.bindFramebuffer(r.FRAMEBUFFER,null),this.initTimestampQuery(ci.COMPUTE,this.getTimestampUID(e))}compute(e,t,r,i,s=null){let{state:o,gl:a}=this;this.discard===!1&&(o.enable(a.RASTERIZER_DISCARD),this.discard=!0);let{programGPU:l,transformBuffers:u,attributes:c}=this.get(i),d=this._getVaoKey(c),h=this.vaoCache[d];h===void 0?this.vaoCache[d]=this._createVao(c):o.setVertexState(h),o.useProgram(l),this._bindUniforms(r);let p=this._getTransformFeedback(u);a.bindTransformFeedback(a.TRANSFORM_FEEDBACK,p),a.beginTransformFeedback(a.POINTS),s=s!==null?s:t.count,Array.isArray(s)?(he("WebGLBackend.compute(): The count parameter must be a single number, not an array."),s=s[0]):s&&typeof s=="object"&&s.isIndirectStorageBufferAttribute&&(he("WebGLBackend.compute(): The count parameter must be a single number, not IndirectStorageBufferAttribute"),s=t.count),c[0].isStorageInstancedBufferAttribute?a.drawArraysInstanced(a.POINTS,0,1,s):a.drawArrays(a.POINTS,0,s),a.endTransformFeedback(),a.bindTransformFeedback(a.TRANSFORM_FEEDBACK,null);for(let f=0;f<u.length;f++){let m=u[f];m.pbo&&this.has(m.pbo)&&this.textureUtils.copyBufferToTexture(m.transformBuffer,m.pbo),m.switchBuffers()}}finishCompute(e){let{state:t,gl:r}=this;this.discard=!1,t.disable(r.RASTERIZER_DISCARD),this.prepareTimestampBuffer(ci.COMPUTE,this.getTimestampUID(e)),this._currentContext&&this._setFramebuffer(this._currentContext)}_isRenderCameraDepthArray(e){return e.depthTexture&&e.depthTexture.isArrayTexture&&e.camera.isArrayCamera}_draw(e,t,r,i,s,o){if(e.isBatchedMesh)if(this.hasFeature("WEBGL_multi_draw")===!1){let{gl:a}=this,l=a.getUniformLocation(o,"nodeUniformDrawId"),u=e._multiDrawStarts,c=e._multiDrawCounts,d=e._multiDrawCount;for(let h=0;h<d;h++)a.uniform1ui(l,h),t.render(u[h],c[h])}else t.renderMultiDraw(e._multiDrawStarts,e._multiDrawCounts,e._multiDrawCount);else s>1?t.renderInstances(r,i,s):t.render(r,i)}draw(e){let{object:t,pipeline:r,material:i,context:s,hardwareClippingPlanes:o}=e,{programGPU:a}=this.get(r),{gl:l,state:u}=this,c=this.get(s),d=e.getDrawParameters();if(d===null)return;this._bindUniforms(e.getBindings());let h=t.isMesh&&t.matrixWorld.determinantAffine()<0;u.setMaterial(i,h,o),s.mrt!==null&&s.textures!==null&&u.setMRTBlending(s.textures,s.mrt,i),u.useProgram(a);let p=e.getAttributes(),f=this.get(p),m=f.vaoGPU;if(m===void 0){let T=this._getVaoKey(p);m=this.vaoCache[T],m===void 0&&(m=this._createVao(p),this.vaoCache[T]=m,f.vaoGPU=m)}let g=e.getIndex(),x=g!==null?this.get(g).bufferGPU:null;u.setVertexState(m,x);let w=c.lastOcclusionObject;if(w!==t&&w!==void 0){if(w!==null&&w.occlusionTest===!0&&(l.endQuery(l.ANY_SAMPLES_PASSED),c.occlusionQueryIndex++),t.occlusionTest===!0){let T=l.createQuery();l.beginQuery(l.ANY_SAMPLES_PASSED,T),c.occlusionQueries[c.occlusionQueryIndex]=T,c.occlusionQueryObjects[c.occlusionQueryIndex]=t}c.lastOcclusionObject=t}let v=this.bufferRenderer;t.isPoints?v.mode=l.POINTS:t.isLineSegments?v.mode=l.LINES:t.isLine?v.mode=l.LINE_STRIP:t.isLineLoop?v.mode=l.LINE_LOOP:i.wireframe===!0?(u.setLineWidth(i.wireframeLinewidth*this.renderer.getPixelRatio()),v.mode=l.LINES):v.mode=l.TRIANGLES;let{vertexCount:E,instanceCount:b}=d,{firstVertex:S}=d;if(v.object=t,g!==null){S*=g.array.BYTES_PER_ELEMENT;let T=this.get(g);v.index=g.count,v.type=T.type}else v.index=0;if(e.camera.isArrayCamera===!0&&e.camera.cameras.length>0&&e.camera.isMultiViewCamera===!1){let T=this.get(e.camera),M=e.camera.cameras,B=e.getBindingGroup("cameraIndex").bindings[0];if(T.indexesGPU===void 0||T.indexesGPU.length!==M.length){let H=new Uint32Array([0,0,0,0]),ae=[];for(let de=0,me=M.length;de<me;de++){let Ae=l.createBuffer();H[0]=de,l.bindBuffer(l.UNIFORM_BUFFER,Ae),l.bufferData(l.UNIFORM_BUFFER,H,l.STATIC_DRAW),ae.push(Ae)}T.indexesGPU=ae}let D=0;e:for(let H of e.getBindings())for(let ae of H.bindings){if(ae===B)break e;(ae.isUniformsGroup||ae.isUniformBuffer)&&D++}let O=this.renderer.getPixelRatio(),z=this._currentContext.renderTarget,Q=this._isRenderCameraDepthArray(this._currentContext),oe=this._currentContext.activeCubeFace;if(Q){let H=this.get(z.depthTexture);if(H.clearedRenderId!==this.renderer._nodes.nodeFrame.renderId){H.clearedRenderId=this.renderer._nodes.nodeFrame.renderId;let{stencilBuffer:ae}=z;for(let de=0,me=M.length;de<me;de++)this.renderer._activeCubeFace=de,this._currentContext.activeCubeFace=de,this._setFramebuffer(this._currentContext),this.clear(!1,!0,ae,this._currentContext,!1,!1);this.renderer._activeCubeFace=oe,this._currentContext.activeCubeFace=oe}}for(let H=0,ae=M.length;H<ae;H++){let de=M[H];if(t.layers.test(de.layers)){Q&&(this.renderer._activeCubeFace=H,this._currentContext.activeCubeFace=H,this._setFramebuffer(this._currentContext));let me=de.viewport;if(me!==void 0){let Ae=me.x*O,ge=me.y*O,Oe=me.width*O,Ge=me.height*O;u.viewport(Math.floor(Ae),Math.floor(e.context.height-Ge-ge),Math.floor(Oe),Math.floor(Ge))}u.bindBufferBase(l.UNIFORM_BUFFER,D,T.indexesGPU[H]),this._draw(t,v,S,E,b,a)}this._currentContext.activeCubeFace=oe,this.renderer._activeCubeFace=oe}}else this._draw(t,v,S,E,b,a)}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,i,s,o){return this.textureUtils.copyTextureToBuffer(e,t,r,i,s,o)}updateSampler(){return""}createNodeBuilder(e,t){return new WC(e,t)}createProgram(e){let t=this.gl,{stage:r,code:i}=e,s=r==="fragment"?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(s,i),t.compileShader(s),this.set(e,{shaderGPU:s})}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){let r=this.gl,i=e.pipeline,{fragmentProgram:s,vertexProgram:o}=i,a=r.createProgram(),l=this.get(s).shaderGPU,u=this.get(o).shaderGPU;if(r.attachShader(a,l),r.attachShader(a,u),r.linkProgram(a),this.set(i,{programGPU:a,fragmentShader:l,vertexShader:u}),t!==null&&this.parallel){let c=new Promise(d=>{let h=this.parallel,p=()=>{r.getProgramParameter(a,h.COMPLETION_STATUS_KHR)?(this._completeCompile(e,i),d()):requestAnimationFrame(p)};p()});t.push(c);return}this._completeCompile(e,i)}_handleSource(e,t){let r=e.split(` | |
| `),i=[],s=Math.max(t-6,0),o=Math.min(t+6,r.length);for(let a=s;a<o;a++){let l=a+1;i.push(`${l===t?">":" "} ${l}: ${r[a]}`)}return i.join(` | |
| `)}_getShaderErrors(e,t,r){let i=e.getShaderParameter(t,e.COMPILE_STATUS),o=(e.getShaderInfoLog(t)||"").trim();if(i&&o==="")return"";let a=/ERROR: 0:(\d+)/.exec(o);if(a){let l=parseInt(a[1]);return r.toUpperCase()+` | |
| `+o+` | |
| `+this._handleSource(e.getShaderSource(t),l)}else return o}_logProgramError(e,t,r){if(this.renderer.debug.checkShaderErrors){let i=this.gl,o=(i.getProgramInfoLog(e)||"").trim();if(i.getProgramParameter(e,i.LINK_STATUS)===!1)if(typeof this.renderer.debug.onShaderError=="function")this.renderer.debug.onShaderError(i,e,r,t);else{let a=this._getShaderErrors(i,r,"vertex"),l=this._getShaderErrors(i,t,"fragment");I("WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(e,i.VALIDATE_STATUS)+` | |
| Program Info Log: `+o+` | |
| `+a+` | |
| `+l)}else o!==""&&U("WebGLProgram: Program Info Log:",o)}}_completeCompile(e,t){let{state:r,gl:i}=this,s=this.get(t),{programGPU:o,fragmentShader:a,vertexShader:l}=s;i.getProgramParameter(o,i.LINK_STATUS)===!1&&this._logProgramError(o,a,l),r.useProgram(o);let u=e.getBindings();this._setupBindings(u,o),this.set(t,{programGPU:o,pipeline:o})}createComputePipeline(e,t){let{state:r,gl:i}=this,s={stage:"fragment",code:`#version 300 es | |
| precision highp float; | |
| void main() {}`};this.createProgram(s);let{computeProgram:o}=e,a=i.createProgram(),l=this.get(s).shaderGPU,u=this.get(o).shaderGPU,c=o.transforms,d=[],h=[];for(let g=0;g<c.length;g++){let x=c[g];d.push(x.varyingName),h.push(x.attributeNode)}i.attachShader(a,l),i.attachShader(a,u),i.transformFeedbackVaryings(a,d,i.SEPARATE_ATTRIBS),i.linkProgram(a),i.getProgramParameter(a,i.LINK_STATUS)===!1&&this._logProgramError(a,l,u),r.useProgram(a),this._setupBindings(t,a);let p=o.attributes,f=[],m=[];for(let g=0;g<p.length;g++){let x=p[g].node.attribute;f.push(x),this.has(x)||this.attributeUtils.createAttribute(x,i.ARRAY_BUFFER)}for(let g=0;g<h.length;g++){let x=h[g].attribute;this.has(x)||this.attributeUtils.createAttribute(x,i.ARRAY_BUFFER);let w=this.get(x);m.push(w)}this.set(e,{programGPU:a,transformBuffers:m,attributes:f})}createBindings(e,t){if(this._knownBindings.has(t)===!1){this._knownBindings.add(t);let r=0,i=0;for(let s of t){this.set(s,{textures:i,uniformBuffers:r});for(let o of s.bindings)o.isUniformBuffer&&r++,o.isSampledTexture&&i++}}this.updateBindings(e,t)}updateBindings(e){let{gl:t}=this;for(let r of e.bindings){let i=this.get(r);if(r.isUniformsGroup||r.isUniformBuffer){let s=r.buffer,o=i.bufferGPU;t.bindBuffer(t.UNIFORM_BUFFER,o);let a=r.updateRanges;if(t.bindBuffer(t.UNIFORM_BUFFER,o),a.length===0)t.bufferData(t.UNIFORM_BUFFER,s,t.DYNAMIC_DRAW);else{let l=ba(s),u=l?1:s.BYTES_PER_ELEMENT;for(let c=0,d=a.length;c<d;c++){let h=a[c],p=h.start*u,f=h.count*u,m=p*(l?s.BYTES_PER_ELEMENT:1);t.bufferSubData(t.UNIFORM_BUFFER,m,s,p,f)}}this.set(r,i)}else if(r.isSampledTexture){let{textureGPU:s,glTextureType:o}=this.get(r.texture);i.textureGPU=s,i.glTextureType=o,this.set(r,i)}}}updateBinding(e){let t=this.gl;if(e.isUniformsGroup||e.isUniformBuffer){let i=this.get(e).bufferGPU,s=e.buffer,o=e.updateRanges;if(t.bindBuffer(t.UNIFORM_BUFFER,i),o.length===0)t.bufferData(t.UNIFORM_BUFFER,s,t.DYNAMIC_DRAW);else{let a=ba(s),l=a?1:s.BYTES_PER_ELEMENT,u=o[0].start;for(let c=0,d=o.length;c<d;c++){let h=o[c],p=o[c+1],f=h.start+h.count;if(p!==void 0&&p.start===f)continue;let m=u*l,g=(f-u)*l,x=m*(a?s.BYTES_PER_ELEMENT:1);t.bufferSubData(t.UNIFORM_BUFFER,x,s,m,g),p!==void 0&&(u=p.start)}}}}createUniformBuffer(e){let t=this.get(e);if(t.bufferGPU===void 0){let r=this.gl,i=e.buffer;t.bufferGPU=r.createBuffer(),r.bindBuffer(r.UNIFORM_BUFFER,t.bufferGPU),r.bufferData(r.UNIFORM_BUFFER,i.byteLength,r.DYNAMIC_DRAW)}}destroyUniformBuffer(e){let t=this.get(e);this.gl.deleteBuffer(t.bufferGPU),this.delete(e)}createIndexAttribute(e){let t=this.gl;this.attributeUtils.createAttribute(e,t.ELEMENT_ARRAY_BUFFER)}createAttribute(e){if(this.has(e))return;let t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}createStorageAttribute(e){if(this.has(e))return;let t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}hasFeature(e){let t=Object.keys(FS).filter(i=>FS[i]===e),r=this.extensions;for(let i=0;i<t.length;i++)if(r.has(t[i]))return!0;return!1}copyTextureToTexture(e,t,r=null,i=null,s=0,o=0){this.textureUtils.copyTextureToTexture(e,t,r,i,s,o)}copyFramebufferToTexture(e,t,r){this.textureUtils.copyFramebufferToTexture(e,t,r)}hasCompatibility(e){return e===xr.TEXTURE_COMPARE?!0:super.hasCompatibility(e)}initRenderTarget(e){let{gl:t,state:r}=this;this._setFramebuffer(e),r.bindFramebuffer(t.FRAMEBUFFER,null)}_setFramebuffer(e){let{gl:t,state:r}=this,i=null;if(e.textures!==null){let s=e.renderTarget,o=this.get(s),{depthBuffer:a,stencilBuffer:l}=s,u=s.isCubeRenderTarget===!0,c=s.isRenderTarget3D===!0,d=s.depth>1,h=s.isXRRenderTarget===!0,p=h===!0&&s._hasExternalTextures===!0,f=o.msaaFrameBuffer,m=o.depthRenderbuffer,g=this.extensions.get("WEBGL_multisampled_render_to_texture"),x=this.extensions.get("OVR_multiview2"),w=this._useMultisampledExtension(s),v=s.samples;e.depthTexture!==null&&e.depthTexture.renderTarget!==s&&w===!1&&v>0&&(he('WebGLBackend: Shared depth texture is not supported with MSAA when "WEBGL_multisampled_render_to_texture" is unsupported. Falling back to single-sample rendering.'),v=0);let E=e_(e),b;if(u?(o.cubeFramebuffers||(o.cubeFramebuffers={}),b=o.cubeFramebuffers[E]):h&&p===!1?b=this._xrFramebuffer:(o.framebuffers||(o.framebuffers={}),b=o.framebuffers[E]),b===void 0){b=t.createFramebuffer(),r.bindFramebuffer(t.FRAMEBUFFER,b);let S=e.textures,T=[];if(u){o.cubeFramebuffers[E]=b;let{textureGPU:B}=this.get(S[0]),D=this.renderer._activeCubeFace,O=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+D,B,O)}else{o.framebuffers[E]=b;for(let B=0;B<S.length;B++){let D=S[B],O=this.get(D);O.renderTarget=e.renderTarget,O.cacheKey=E;let z=t.COLOR_ATTACHMENT0+B;if(s.multiview)x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,z,O.textureGPU,0,v,0,2);else if(c||d){let Q=this.renderer._activeCubeFace,oe=this.renderer._activeMipmapLevel;t.framebufferTextureLayer(t.FRAMEBUFFER,z,O.textureGPU,oe,Q)}else if(w)g.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,z,t.TEXTURE_2D,O.textureGPU,0,v);else{let Q=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,z,t.TEXTURE_2D,O.textureGPU,Q)}}}let M=l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(s._autoAllocateDepthBuffer===!0){let B=t.createRenderbuffer();this.textureUtils.setupRenderBufferStorage(B,e,0,w),o.xrDepthRenderbuffer=B,T.push(l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT),t.bindRenderbuffer(t.RENDERBUFFER,B),t.framebufferRenderbuffer(t.FRAMEBUFFER,M,t.RENDERBUFFER,B)}else if(e.depthTexture!==null){T.push(l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT);let B=this.get(e.depthTexture);if(B.renderTarget=e.renderTarget,B.cacheKey=E,s.multiview)x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,M,B.textureGPU,0,v,0,2);else if(p&&w)g.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,M,t.TEXTURE_2D,B.textureGPU,0,v);else if(e.depthTexture.isArrayTexture){let D=this.renderer._activeCubeFace;t.framebufferTextureLayer(t.FRAMEBUFFER,M,B.textureGPU,0,D)}else if(e.depthTexture.isCubeTexture){let D=this.renderer._activeCubeFace;t.framebufferTexture2D(t.FRAMEBUFFER,M,t.TEXTURE_CUBE_MAP_POSITIVE_X+D,B.textureGPU,0)}else t.framebufferTexture2D(t.FRAMEBUFFER,M,t.TEXTURE_2D,B.textureGPU,0)}o.depthInvalidationArray=T}else{if(this._isRenderCameraDepthArray(e)){r.bindFramebuffer(t.FRAMEBUFFER,b);let T=this.renderer._activeCubeFace,M=this.get(e.depthTexture),B=l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;t.framebufferTextureLayer(t.FRAMEBUFFER,B,M.textureGPU,0,T)}if((h||w||s.multiview)&&s._isOpaqueFramebuffer!==!0){r.bindFramebuffer(t.FRAMEBUFFER,b);let T=this.get(e.textures[0]);s.multiview?x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,T.textureGPU,0,v,0,2):w?g.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,T.textureGPU,0,v):t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,T.textureGPU,0);let M=l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(s._autoAllocateDepthBuffer===!0){let B=o.xrDepthRenderbuffer;t.bindRenderbuffer(t.RENDERBUFFER,B),t.framebufferRenderbuffer(t.FRAMEBUFFER,M,t.RENDERBUFFER,B)}else{let B=this.get(e.depthTexture);s.multiview?x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,M,B.textureGPU,0,v,0,2):w?g.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,M,t.TEXTURE_2D,B.textureGPU,0,v):t.framebufferTexture2D(t.FRAMEBUFFER,M,t.TEXTURE_2D,B.textureGPU,0)}}}if(v>0&&w===!1&&!s.multiview){if(f===void 0){f=t.createFramebuffer(),r.bindFramebuffer(t.FRAMEBUFFER,f);let S=[],T=e.textures;for(let M=0;M<T.length;M++){S[M]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,S[M]);let B=e.textures[M],D=this.get(B);t.renderbufferStorageMultisample(t.RENDERBUFFER,v,D.glInternalFormat,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+M,t.RENDERBUFFER,S[M])}t.bindRenderbuffer(t.RENDERBUFFER,null),o.msaaFrameBuffer=f,o.msaaRenderbuffers=S,a&&m===void 0&&(m=t.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(m,e,v),o.depthRenderbuffer=m)}i=o.msaaFrameBuffer}else i=b;r.drawBuffers(e,b)}r.bindFramebuffer(t.FRAMEBUFFER,i)}_getVaoKey(e){let t="";for(let r=0;r<e.length;r++){let i=this.get(e[r]);t+=":"+i.id}return t}_createVao(e){let{gl:t}=this,r=t.createVertexArray();t.bindVertexArray(r);for(let i=0;i<e.length;i++){let s=e[i],o=this.get(s);t.bindBuffer(t.ARRAY_BUFFER,o.bufferGPU),t.enableVertexAttribArray(i);let a,l;s.isInterleavedBufferAttribute===!0?(a=s.data.stride*o.bytesPerElement,l=s.offset*o.bytesPerElement):(a=0,l=0),o.isInteger?t.vertexAttribIPointer(i,s.itemSize,o.type,a,l):t.vertexAttribPointer(i,s.itemSize,o.type,s.normalized,a,l),s.isInstancedBufferAttribute&&!s.isInterleavedBufferAttribute?t.vertexAttribDivisor(i,s.meshPerAttribute):s.isInterleavedBufferAttribute&&s.data.isInstancedInterleavedBuffer&&t.vertexAttribDivisor(i,s.data.meshPerAttribute)}return t.bindBuffer(t.ARRAY_BUFFER,null),r}_getTransformFeedback(e){let t="";for(let s=0;s<e.length;s++)t+=":"+e[s].id;let r=this.transformFeedbackCache[t];if(r!==void 0)return r;let{gl:i}=this;r=i.createTransformFeedback(),i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,r);for(let s=0;s<e.length;s++){let o=e[s];i.bindBufferBase(i.TRANSFORM_FEEDBACK_BUFFER,s,o.transformBuffer)}return i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[t]=r,r}_setupBindings(e,t){let r=this.gl,i=0,s=0;for(let o of e)for(let a of o.bindings)if(a.isUniformsGroup||a.isUniformBuffer){let l=i++,u=r.getUniformBlockIndex(t,a.name);r.uniformBlockBinding(t,u,l)}else if(a.isSampledTexture){let l=s++,u=r.getUniformLocation(t,a.name);r.uniform1i(u,l)}}_bindUniforms(e){let{gl:t,state:r}=this,i=0,s=0;for(let o of e)for(let a of o.bindings){let l=this.get(a);if(a.isUniformsGroup||a.isUniformBuffer){let u=i++;r.bindBufferBase(t.UNIFORM_BUFFER,u,l.bufferGPU)}else if(a.isSampledTexture){let u=s++;r.bindTexture(l.glTextureType,l.textureGPU,t.TEXTURE0+u)}}}_resolveRenderTarget(e){let{gl:t,state:r}=this,i=e.renderTarget;if(e.textures!==null&&i){let s=this.get(i);if(i.samples>0&&s.msaaFrameBuffer!==void 0&&this._useMultisampledExtension(i)===!1){let o=s.framebuffers[e.getCacheKey()],a=i.resolveColorBuffer===!1?0:t.COLOR_BUFFER_BIT;i.resolveDepthBuffer&&(i.depthBuffer&&(a|=t.DEPTH_BUFFER_BIT),i.stencilBuffer&&i.resolveStencilBuffer&&(a|=t.STENCIL_BUFFER_BIT));let l=s.msaaFrameBuffer,u=s.msaaRenderbuffers,c=e.textures,d=c.length>1;if(r.bindFramebuffer(t.READ_FRAMEBUFFER,l),r.bindFramebuffer(t.DRAW_FRAMEBUFFER,o),d)for(let h=0;h<c.length;h++)t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0+h,t.RENDERBUFFER,null),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+h,t.TEXTURE_2D,null,0);for(let h=0;h<c.length;h++){if(d){let{textureGPU:p}=this.get(c[h]);t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,u[h]),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,p,0)}if(e.scissor){let{x:p,y:f,width:m,height:g}=e.scissorValue,x=e.height-g-f;t.blitFramebuffer(p,x,p+m,x+g,p,x,p+m,x+g,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 h=0;h<c.length;h++){let{textureGPU:p}=this.get(c[h]);t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0+h,t.RENDERBUFFER,u[h]),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+h,t.TEXTURE_2D,p,0)}if(this._supportsInvalidateFramebuffer===!0){if(i.storeMultisampledColorBuffer===!1)for(let h=0;h<c.length;h++)fd.push(t.COLOR_ATTACHMENT0+h);i.depthBuffer&&i.storeMultisampledDepthBuffer===!1&&fd.push(i.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT),fd.length>0&&(t.invalidateFramebuffer(t.READ_FRAMEBUFFER,fd),fd.length=0)}}else if(i.storeMultisampledDepthBuffer===!1&&s.framebuffers){let o=s.framebuffers[e.getCacheKey()];r.bindFramebuffer(t.DRAW_FRAMEBUFFER,o),t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,s.depthInvalidationArray)}}}_useMultisampledExtension(e){return e.multiview===!0?!0:e.samples>0&&this.extensions.has("WEBGL_multisampled_render_to_texture")===!0&&e._autoAllocateDepthBuffer!==!1}dispose(){this.textureUtils!==null&&this.textureUtils.dispose();let e=this.extensions.get("WEBGL_lose_context");e&&e.loseContext(),this.renderer.domElement.removeEventListener("webglcontextlost",this._onContextLost)}},US=DS;var Xa={PointList:"point-list",LineList:"line-list",LineStrip:"line-strip",TriangleList:"triangle-list",TriangleStrip:"triangle-strip"},oi=typeof self<"u"&&self.GPUShaderStage?self.GPUShaderStage:{VERTEX:1,FRAGMENT:2,COMPUTE:4},Kt={Never:"never",Less:"less",Equal:"equal",LessEqual:"less-equal",Greater:"greater",NotEqual:"not-equal",GreaterEqual:"greater-equal",Always:"always"},Vt={Store:"store",Discard:"discard"},Ve={Load:"load",Clear:"clear"},IS={CCW:"ccw",CW:"cw"},OS={None:"none",Front:"front",Back:"back"},gu={Uint16:"uint16",Uint32:"uint32"};var R={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R16Unorm:"r16unorm",R16Snorm:"r16snorm",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",RG16Unorm:"rg16unorm",RG16Snorm:"rg16snorm",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10UFloat:"rg11b10ufloat",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA16Unorm:"rgba16unorm",RGBA16Snorm:"rgba16snorm",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-unorm-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"},ig={ClampToEdge:"clamp-to-edge",Repeat:"repeat",MirrorRepeat:"mirror-repeat"},ai={Linear:"linear",Nearest:"nearest"},Be={Zero:"zero",One:"one",Src:"src",OneMinusSrc:"one-minus-src",SrcAlpha:"src-alpha",OneMinusSrcAlpha:"one-minus-src-alpha",Dst:"dst",OneMinusDst:"one-minus-dst",DstAlpha:"dst-alpha",OneMinusDstAlpha:"one-minus-dst-alpha",SrcAlphaSaturated:"src-alpha-saturated",Constant:"constant",OneMinusConstant:"one-minus-constant"},Ro={Add:"add",Subtract:"subtract",ReverseSubtract:"reverse-subtract",Min:"min",Max:"max"},kS={None:0,Red:1,Green:2,Blue:4,Alpha:8,All:15},Un={Keep:"keep",Zero:"zero",Replace:"replace",Invert:"invert",IncrementClamp:"increment-clamp",DecrementClamp:"decrement-clamp",IncrementWrap:"increment-wrap",DecrementWrap:"decrement-wrap"},md={Uniform:"uniform",Storage:"storage",ReadOnlyStorage:"read-only-storage"},sg={WriteOnly:"write-only",ReadOnly:"read-only",ReadWrite:"read-write"},VS={Filtering:"filtering",NonFiltering:"non-filtering",Comparison:"comparison"},In={Float:"float",UnfilterableFloat:"unfilterable-float",Depth:"depth",SInt:"sint",UInt:"uint"},GS={OneD:"1d",TwoD:"2d",ThreeD:"3d"},Gt={OneD:"1d",TwoD:"2d",TwoDArray:"2d-array",Cube:"cube",CubeArray:"cube-array",ThreeD:"3d"},e1={All:"all",StencilOnly:"stencil-only",DepthOnly:"depth-only"},gd={Vertex:"vertex",Instance:"instance"},xu={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"},zS={"texture-compression-s3tc":"texture-compression-bc","texture-compression-etc1":"texture-compression-etc2"};var $S=class extends Km{constructor(e,t,r){super(e,t?t.value:null),this.textureNode=t,this.groupNode=r}update(){let{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}},t1=$S;var WS=class extends qm{constructor(e,t){super(e,t?t.array:null),this._attribute=t,this.isStorageBuffer=!0}get attribute(){return this._attribute}},r1=WS;var PI=0,HS=class extends r1{constructor(e,t){super("StorageBuffer_"+PI++,e?e.value:null),this.nodeUniform=e,this.access=e?e.access:mt.READ_WRITE,this.groupNode=t}get attribute(){return this.nodeUniform.value}get buffer(){return this.nodeUniform.value.array}},i1=HS;var qS=[null],jS=class{constructor(e){this.backend=e,this._preferredCanvasFormat=null}getCurrentDepthStencilFormat(e){let t;return e.depth&&(e.depthTexture!==null?t=this.getTextureFormatGPU(e.depthTexture):e.stencil?this.backend.renderer.reversedDepthBuffer===!0?t=R.Depth32FloatStencil8:t=R.Depth24PlusStencil8:this.backend.renderer.reversedDepthBuffer===!0?t=R.Depth32Float:t=R.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getTextureSampleData(e){let t;if(e.isFramebufferTexture)t=1;else if(e.isDepthTexture&&!e.renderTarget){let s=this.backend.renderer,o=s.getRenderTarget();t=o?o.samples:s.currentSamples}else e.renderTarget&&(t=e.renderTarget.samples);t=this.getSampleCount(t||1);let r=t>1&&e.renderTarget!==null&&e.isDepthTexture!==!0&&e.isFramebufferTexture!==!0;return{samples:t,primarySamples:r?1:t,isMSAA:r}}getCurrentColorFormat(e){let t;return e.textures!==null?t=this.getTextureFormatGPU(e.textures[0]):t=this.getPreferredCanvasFormat(),t}getCurrentColorFormats(e){return e.textures!==null?e.textures.map(t=>this.getTextureFormatGPU(t)):[this.getPreferredCanvasFormat()]}getCurrentColorSpace(e){return e.textures!==null?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){if(e.isPoints)return Xa.PointList;if(e.isLineSegments||e.isMesh&&t.wireframe===!0)return Xa.LineList;if(e.isLine)return Xa.LineStrip;if(e.isMesh)return Xa.TriangleList}getSampleCount(e){return e>=4?4:1}getSampleCountRenderContext(e){return e.textures!==null?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.currentSamples)}getPreferredCanvasFormat(){let t=this.backend.parameters.outputType;if(t===void 0)return this._preferredCanvasFormat===null&&(this._preferredCanvasFormat=navigator.gpu.getPreferredCanvasFormat()),this._preferredCanvasFormat;if(t===it)return R.BGRA8Unorm;if(t===qe)return R.RGBA16Float;throw new Error("THREE.WebGPUUtils: Unsupported output buffer type.")}};function qr(n,e){qS[0]=e,n.queue.submit(qS),qS[0]=null}var s1=jS;var XS=class{constructor(){this.label="",this.layout=null,this.entries=[]}reset(){this.label="",this.layout=null,this.entries.length=0}},ng=XS;var YS=class{constructor(){this.label="",this.size=0,this.usage=0,this.mappedAtCreation=!1}reset(){this.label="",this.size=0,this.usage=0,this.mappedAtCreation=!1}},Yi=YS;var KS=class{constructor(){this.label=""}reset(){this.label=""}},Xs=KS;var QS=class{constructor(){this.label="",this.colorFormats=null,this.depthStencilFormat=void 0,this.sampleCount=1,this.depthReadOnly=!1,this.stencilReadOnly=!1}reset(){this.label="",this.colorFormats=null,this.depthStencilFormat=void 0,this.sampleCount=1,this.depthReadOnly=!1,this.stencilReadOnly=!1}},og=QS;var ZS=class{constructor(){this.view=null,this.depthSlice=void 0,this.resolveTarget=void 0,this.clearValue=void 0,this.loadOp=void 0,this.storeOp=void 0}reset(){this.view=null,this.depthSlice=void 0,this.resolveTarget=void 0,this.clearValue=void 0,this.loadOp=void 0,this.storeOp=void 0}},Ya=ZS;var JS=class{constructor(){this.label="",this.colorAttachments=[],this.depthStencilAttachment=void 0,this.occlusionQuerySet=void 0,this.timestampWrites=void 0,this.maxDrawCount=5e7}reset(){this.label="",this.colorAttachments.length=0,this.depthStencilAttachment=void 0,this.occlusionQuerySet=void 0,this.timestampWrites=void 0,this.maxDrawCount=5e7}},Ka=JS;var eN=class{constructor(){this.label="",this.layout=null,this.vertex=null,this.primitive={},this.depthStencil=void 0,this.multisample=new tN,this.fragment=null}reset(){this.label="",this.layout=null,this.vertex=null,this.primitive={},this.depthStencil=void 0,this.multisample.reset(),this.fragment=null}},tN=class{constructor(){this.count=1,this.mask=4294967295,this.alphaToCoverageEnabled=!1}reset(){this.count=1,this.mask=4294967295,this.alphaToCoverageEnabled=!1}},ag=eN;var rN=class{constructor(){this.label="",this.code="",this.compilationHints=[]}reset(){this.label="",this.code="",this.compilationHints.length=0}},lg=rN;var iN=class{constructor(){this.label="",this.size={width:0,height:1,depthOrArrayLayers:1},this.mipLevelCount=1,this.sampleCount=1,this.dimension="2d",this.format=void 0,this.usage=void 0,this.viewFormats=[],this.textureBindingViewDimension=void 0}reset(){this.label="",this.size.width=0,this.size.height=1,this.size.depthOrArrayLayers=1,this.mipLevelCount=1,this.sampleCount=1,this.dimension="2d",this.format=void 0,this.usage=void 0,this.viewFormats.length=0,this.textureBindingViewDimension=void 0}},xd=iN;var sN=class{constructor(){this.label="",this.format=void 0,this.dimension=void 0,this.usage=0,this.aspect="all",this.baseMipLevel=0,this.mipLevelCount=void 0,this.baseArrayLayer=0,this.arrayLayerCount=void 0,this.swizzle="rgba"}reset(){this.label="",this.format=void 0,this.dimension=void 0,this.usage=0,this.aspect="all",this.baseMipLevel=0,this.mipLevelCount=void 0,this.baseArrayLayer=0,this.arrayLayerCount=void 0,this.swizzle="rgba"}},yu=sN;var Co=new ng,Eo=new Yi,ug=new Xs,nN=new og,oN=new Ka,bu=new ag,yd=new Ya,cg=new lg,_u=new xd,Nt=new yu,aN=class extends Ar{constructor(e){super(),this.device=e;let t=` | |
| struct VarysStruct { | |
| @builtin( position ) Position: vec4f, | |
| @location( 0 ) vTex : vec2f, | |
| @location( 1 ) @interpolate(flat, either) vBaseArrayLayer: u32, | |
| }; | |
| @group( 0 ) @binding ( 2 ) | |
| var<uniform> flipY: u32; | |
| @vertex | |
| fn mainVS( | |
| @builtin( vertex_index ) vertexIndex : u32, | |
| @builtin( instance_index ) instanceIndex : u32 ) -> VarysStruct { | |
| var Varys : VarysStruct; | |
| var pos = array( | |
| vec2f( -1, -1 ), | |
| vec2f( -1, 3 ), | |
| vec2f( 3, -1 ), | |
| ); | |
| let p = pos[ vertexIndex ]; | |
| let mult = select( vec2f( 0.5, -0.5 ), vec2f( 0.5, 0.5 ), flipY != 0 ); | |
| Varys.vTex = p * mult + vec2f( 0.5 ); | |
| Varys.Position = vec4f( p, 0, 1 ); | |
| Varys.vBaseArrayLayer = instanceIndex; | |
| return Varys; | |
| } | |
| @group( 0 ) @binding( 0 ) | |
| var imgSampler : sampler; | |
| @group( 0 ) @binding( 1 ) | |
| var img2d : texture_2d<f32>; | |
| @fragment | |
| fn main_2d( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> { | |
| return textureSample( img2d, imgSampler, Varys.vTex ); | |
| } | |
| @group( 0 ) @binding( 1 ) | |
| var img2dArray : texture_2d_array<f32>; | |
| @fragment | |
| fn main_2d_array( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> { | |
| return textureSample( img2dArray, imgSampler, Varys.vTex, Varys.vBaseArrayLayer ); | |
| } | |
| const faceMat = array( | |
| mat3x3f( 0, 0, -2, 0, -2, 0, 1, 1, 1 ), // pos-x | |
| mat3x3f( 0, 0, 2, 0, -2, 0, -1, 1, -1 ), // neg-x | |
| mat3x3f( 2, 0, 0, 0, 0, 2, -1, 1, -1 ), // pos-y | |
| mat3x3f( 2, 0, 0, 0, 0, -2, -1, -1, 1 ), // neg-y | |
| mat3x3f( 2, 0, 0, 0, -2, 0, -1, 1, 1 ), // pos-z | |
| mat3x3f( -2, 0, 0, 0, -2, 0, 1, 1, -1 ), // neg-z | |
| ); | |
| @group( 0 ) @binding( 1 ) | |
| var imgCube : texture_cube<f32>; | |
| @fragment | |
| fn main_cube( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> { | |
| return textureSample( imgCube, imgSampler, faceMat[ Varys.vBaseArrayLayer ] * vec3f( fract( Varys.vTex ), 1 ) ); | |
| } | |
| `;this.mipmapSampler=e.createSampler({minFilter:ai.Linear}),this.flipYSampler=e.createSampler({minFilter:ai.Nearest}),Eo.size=4,Eo.usage=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,this.flipUniformBuffer=e.createBuffer(Eo),Eo.reset(),e.queue.writeBuffer(this.flipUniformBuffer,0,new Uint32Array([1])),Eo.size=4,Eo.usage=GPUBufferUsage.UNIFORM,this.noFlipUniformBuffer=e.createBuffer(Eo),Eo.reset(),this.transferPipelines={},cg.label="mipmap",cg.code=t,this.mipmapShaderModule=e.createShaderModule(cg),cg.reset()}getTransferPipeline(e,t){t=t||"2d-array";let r=`${e}-${t}`,i=this.transferPipelines[r];return i===void 0&&(bu.label=`mipmap-${e}-${t}`,bu.vertex={module:this.mipmapShaderModule},bu.fragment={module:this.mipmapShaderModule,entryPoint:`main_${t.replace("-","_")}`,targets:[{format:e}]},bu.layout="auto",i=this.device.createRenderPipeline(bu),bu.reset(),this.transferPipelines[r]=i),i}flipY(e,t,r=0){let i=t.format,{width:s,height:o}=t.size;_u.size.width=s,_u.size.height=o,_u.format=i,_u.usage=GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING;let a=this.device.createTexture(_u);_u.reset();let l=this.getTransferPipeline(i,e.textureBindingViewDimension),u=this.getTransferPipeline(i,a.textureBindingViewDimension),c=this.device.createCommandEncoder(ug),d=(h,p,f,m,g,x)=>{let w=h.getBindGroupLayout(0);Nt.dimension=p.textureBindingViewDimension||"2d-array",Nt.mipLevelCount=1;let v=p.createView(Nt);Nt.reset(),Co.layout=w,Co.entries.push({binding:0,resource:this.flipYSampler},{binding:1,resource:v},{binding:2,resource:{buffer:x?this.flipUniformBuffer:this.noFlipUniformBuffer}});let E=this.device.createBindGroup(Co);Co.reset(),Nt.dimension="2d",Nt.mipLevelCount=1,Nt.baseArrayLayer=g,Nt.arrayLayerCount=1;let b=m.createView(Nt);Nt.reset(),yd.view=b,yd.loadOp=Ve.Clear,yd.storeOp=Vt.Store,oN.colorAttachments.push(yd);let S=c.beginRenderPass(oN);oN.reset(),yd.reset(),S.setPipeline(h),S.setBindGroup(0,E),S.draw(3,1,0,f),S.end()};d(l,e,r,a,0,!1),d(u,a,0,e,r,!0),qr(this.device,c.finish()),a.destroy()}generateMipmaps(e,t=null){let r=this.get(e),i=r.layers||this._mipmapCreateBundles(e),s=t;s===null&&(ug.label="mipmapEncoder",s=this.device.createCommandEncoder(ug),ug.reset()),this._mipmapRunBundles(s,i),t===null&&qr(this.device,s.finish()),r.layers=i}_mipmapCreateBundles(e){let t=e.textureBindingViewDimension||"2d-array",r=this.getTransferPipeline(e.format,t),i=r.getBindGroupLayout(0),s=[];for(let o=1;o<e.mipLevelCount;o++)for(let a=0;a<e.depthOrArrayLayers;a++){Nt.dimension=t,Nt.baseMipLevel=o-1,Nt.mipLevelCount=1;let l=e.createView(Nt);Nt.reset(),Co.layout=i,Co.entries.push({binding:0,resource:this.mipmapSampler},{binding:1,resource:l},{binding:2,resource:{buffer:this.noFlipUniformBuffer}});let u=this.device.createBindGroup(Co);Co.reset(),Nt.dimension="2d",Nt.baseMipLevel=o,Nt.mipLevelCount=1,Nt.baseArrayLayer=a,Nt.arrayLayerCount=1;let c=e.createView(Nt);Nt.reset();let d=new Ya;d.view=c,d.loadOp=Ve.Clear,d.storeOp=Vt.Store;let h=new Ka;h.colorAttachments.push(d),nN.colorFormats=[e.format];let p=this.device.createRenderBundleEncoder(nN);nN.reset(),p.setPipeline(r),p.setBindGroup(0,u),p.draw(3,1,0,a),s.push({renderBundles:[p.finish()],passDescriptor:h})}return s}_mipmapRunBundles(e,t){let r=t.length;for(let i=0;i<r;i++){let s=t[i],o=e.beginRenderPass(s.passDescriptor);o.executeBundles(s.renderBundles),o.end()}}},n1=aN;var lN=class{constructor(){this.label="",this.addressModeU="clamp-to-edge",this.addressModeV="clamp-to-edge",this.addressModeW="clamp-to-edge",this.magFilter="nearest",this.minFilter="nearest",this.mipmapFilter="nearest",this.lodMinClamp=0,this.lodMaxClamp=32,this.compare=void 0,this.maxAnisotropy=1}reset(){this.label="",this.addressModeU="clamp-to-edge",this.addressModeV="clamp-to-edge",this.addressModeW="clamp-to-edge",this.magFilter="nearest",this.minFilter="nearest",this.mipmapFilter="nearest",this.lodMinClamp=0,this.lodMaxClamp=32,this.compare=void 0,this.maxAnisotropy=1}},o1=lN;var uN=class{constructor(){this.texture=null,this.mipLevel=0,this.origin={x:0,y:0,z:0},this.aspect="all"}reset(){this.texture=null,this.mipLevel=0,this.origin.x=0,this.origin.y=0,this.origin.z=0,this.aspect="all"}},Qa=uN;var cN=class{constructor(){this.buffer=null,this.offset=0,this.bytesPerRow=void 0,this.rowsPerImage=void 0}reset(){this.buffer=null,this.offset=0,this.bytesPerRow=void 0,this.rowsPerImage=void 0}},a1=cN;var dN=class{constructor(){this.offset=0,this.bytesPerRow=void 0,this.rowsPerImage=void 0}reset(){this.offset=0,this.bytesPerRow=void 0,this.rowsPerImage=void 0}},l1=dN;var hN=class{constructor(){this.source=null,this.origin={x:0,y:0},this.flipY=!1}reset(){this.source=null,this.origin.x=0,this.origin.y=0,this.flipY=!1}},u1=hN;var pN=class extends Qa{constructor(){super(),this.colorSpace="srgb",this.premultipliedAlpha=!1}reset(){super.reset(),this.colorSpace="srgb",this.premultipliedAlpha=!1}},c1=pN;var fN=class{constructor(){this.width=0,this.height=1,this.depthOrArrayLayers=1}reset(){this.width=0,this.height=1,this.depthOrArrayLayers=1}},dg=fN;var hg=new Yi,DI=new Xs,Cr=new o1,Br=new Qa,pg=new a1,On=new l1,fg=new u1,Tu=new c1,Bo=new xd,Er=new dg,UI={[Hd]:"never",[ol]:"less",[qd]:"equal",[Pi]:"less-equal",[ya]:"greater",[ui]:"greater-equal",[Xd]:"always",[jd]:"not-equal"},II=[0,1,3,2,4,5];function d1(n,e,t,r,i,s,o,a,l,u){Br.texture=e,Br.mipLevel=t,Br.origin.z=r,On.offset=r*s,On.bytesPerRow=o,On.rowsPerImage=a,Er.width=l,Er.height=u,n.queue.writeTexture(Br,i.data,On,Er),Br.reset(),On.reset(),Er.reset()}var mN=class{constructor(e){this.backend=e,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this._samplerCache=new Map}updateSampler(e){let t=this.backend,r=e.texture,i=e.textureNode,s=r.minFilter+"-"+r.magFilter+"-"+r.wrapS+"-"+r.wrapT+"-"+(r.wrapR||"0")+"-"+r.anisotropy+"-"+(r.isDepthTexture===!0?1:0)+"-"+(r.compareFunction!==null&&i.compareNode!==null?r.compareFunction:0),o=this._samplerCache.get(s);if(o===void 0){Cr.addressModeU=this._convertAddressMode(r.wrapS),Cr.addressModeV=this._convertAddressMode(r.wrapT),Cr.addressModeW=this._convertAddressMode(r.wrapR),Cr.magFilter=this._convertFilterMode(r.magFilter),Cr.minFilter=this._convertFilterMode(r.minFilter),Cr.mipmapFilter=this._convertMipmapFilterMode(r.minFilter),r.isDepthTexture&&(r.compareFunction===null||i.compareNode===null)&&(Cr.magFilter=ai.Nearest,Cr.minFilter=ai.Nearest,Cr.mipmapFilter=ai.Nearest),Cr.magFilter===ai.Linear&&Cr.minFilter===ai.Linear&&Cr.mipmapFilter===ai.Linear&&(Cr.maxAnisotropy=r.anisotropy),r.isDepthTexture&&r.compareFunction!==null&&i.compareNode!==null&&t.hasCompatibility(xr.TEXTURE_COMPARE)&&(Cr.compare=UI[r.compareFunction]);let l=t.device.createSampler(Cr);Cr.reset(),o={sampler:l,usedTimes:0},this._samplerCache.set(s,o)}let a=t.get(e);return a.sampler!==o.sampler&&(this._releaseSampler(a),a.samplerKey=s,a.sampler=o.sampler,o.usedTimes++),s}destroySampler(e){this._releaseSampler(this.backend.get(e))}_releaseSampler(e){if(e.sampler!==void 0){let t=this._samplerCache.get(e.samplerKey);t.usedTimes--,t.usedTimes===0&&this._samplerCache.delete(e.samplerKey),e.sampler=void 0,e.samplerKey=void 0}}createDefaultTexture(e){let t,r=mg(e,this.backend.device);e.isCubeTexture?t=this._getDefaultCubeTextureGPU(r):t=this._getDefaultTextureGPU(r),this.backend.get(e).texture=t}createTexture(e,t={}){let r=this.backend,i=r.get(e);if(i.initialized){if(i.externalTexture===!0)return;throw new Error("THREE.WebGPUTextureUtils: Texture already initialized.")}if(e.isExternalTexture){i.texture=e.sourceTexture,i.initialized=!0;return}t.needsMipmaps===void 0&&(t.needsMipmaps=!1),t.levels===void 0&&(t.levels=1),t.depth===void 0&&(t.depth=1);let{width:s,height:o,depth:a,levels:l}=t;e.isFramebufferTexture&&(t.renderTarget?t.format=this.backend.utils.getCurrentColorFormat(t.renderTarget):t.format=this.backend.utils.getPreferredCanvasFormat());let u=this._getDimension(e),c=e.internalFormat||t.format||mg(e,r.device);i.format=c;let{samples:d,primarySamples:h,isMSAA:p}=r.utils.getTextureSampleData(e),f=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;e.isStorageTexture===!0&&(f|=GPUTextureUsage.STORAGE_BINDING),e.isCompressedTexture!==!0&&e.isCompressedArrayTexture!==!0&&c!==R.RGB9E5UFloat&&(f|=GPUTextureUsage.RENDER_ATTACHMENT);let m=e.renderTarget;e.isDepthTexture===!0&&h>1&&GPUTextureUsage.TRANSIENT_ATTACHMENT!==void 0&&m?.storeMultisampledDepthBuffer===!1&&(m.stencilBuffer===!1||m.storeMultisampledStencilBuffer===!1)&&(f=GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TRANSIENT_ATTACHMENT);let g=new xd;if(g.label=e.name,g.size.width=s,g.size.height=o,g.size.depthOrArrayLayers=a,g.mipLevelCount=l,g.sampleCount=h,g.dimension=u,g.format=c,g.usage=f,c===void 0){U("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(e);return}e.isCubeTexture&&(g.textureBindingViewDimension=Gt.Cube);try{i.texture=r.device.createTexture(g)}catch{U("WebGPURenderer: Failed to create texture with descriptor:",g),this.createDefaultTexture(e);return}if(p){let x=Object.assign({},g);x.label=x.label+"-msaa",x.sampleCount=d,x.mipLevelCount=1,m?.storeMultisampledColorBuffer===!1&&GPUTextureUsage.TRANSIENT_ATTACHMENT!==void 0&&(x.usage=GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TRANSIENT_ATTACHMENT),i.msaaTexture=r.device.createTexture(x)}i.initialized=!0,i.textureDescriptorGPU=g}destroyTexture(e,t=!1){let r=this.backend,i=r.get(e);i.texture!==void 0&&t===!1&&e.isExternalTexture!==!0&&i.texture.destroy(),i.msaaTexture!==void 0&&i.msaaTexture.destroy(),r.delete(e)}generateMipmaps(e,t=null){let r=this.backend.get(e);this._generateMipmaps(r.texture,t)}getColorBuffer(){let e=this.backend,t=e.renderer.getCanvasTarget(),{width:r,height:i}=e.getDrawingBufferSize(),s=e.renderer.currentSamples,o=t.colorTexture,a=e.get(o);if(o.width===r&&o.height===i&&o.samples===s)return a.texture;let l=a.texture;return l&&l.destroy(),Bo.label="colorBuffer",Bo.size.width=r,Bo.size.height=i,Bo.sampleCount=e.utils.getSampleCount(e.renderer.currentSamples),Bo.format=e.utils.getPreferredCanvasFormat(),Bo.usage=GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,l=e.device.createTexture(Bo),Bo.reset(),o.source.width=r,o.source.height=i,o.samples=s,a.texture=l,l}getDepthBuffer(e=!0,t=!1){let r=this.backend,i=r.renderer.getCanvasTarget(),{width:s,height:o}=r.getDrawingBufferSize(),a=r.renderer.currentSamples,l=i.depthTexture;if(l.width===s&&l.height===o&&l.samples===a&&l.depth===e&&l.stencil===t)return r.get(l).texture;let u=r.get(l).texture,c,d;if(t?(c=Ht,d=r.renderer.reversedDepthBuffer===!0?ze:Qr):e&&(c=Mt,d=r.renderer.reversedDepthBuffer===!0?ze:Ce),u!==void 0){if(l.image.width===s&&l.image.height===o&&l.format===c&&l.type===d&&l.samples===a)return u;this.destroyTexture(l)}return l.name="depthBuffer",l.format=c,l.type=d,l.image.width=s,l.image.height=o,l.samples=a,this.createTexture(l,{width:s,height:o}),r.get(l).texture}updateTexture(e,t){let r=this.backend.get(e),i=e.mipmaps,{textureDescriptorGPU:s}=r;if(!(e.isRenderTargetTexture||s===void 0)){if(e.isDataTexture)if(i.length>0)for(let o=0,a=i.length;o<a;o++){let l=i[o];this._copyBufferToTexture(l,r.texture,s,0,e.flipY,0,o)}else this._copyBufferToTexture(t.image,r.texture,s,0,e.flipY);else if(e.isArrayTexture||e.isDataArrayTexture||e.isData3DTexture)if(e.layerUpdates&&e.layerUpdates.size>0){for(let o of e.layerUpdates)this._copyBufferToTexture(t.image,r.texture,s,o,e.flipY,o);e.clearLayerUpdates()}else for(let o=0;o<t.image.depth;o++)this._copyBufferToTexture(t.image,r.texture,s,o,e.flipY,o);else if(e.isCompressedTexture||e.isCompressedArrayTexture)e.isCompressedArrayTexture&&e.layerUpdates.size>0?(this._copyCompressedBufferToTexture(e.mipmaps,r.texture,s,e.layerUpdates),e.clearLayerUpdates()):this._copyCompressedBufferToTexture(e.mipmaps,r.texture,s);else if(e.isCubeTexture)this._copyCubeMapToTexture(e,r.texture,s);else if(e.isHTMLTexture){let o=this.backend.device,a=this.backend.renderer.domElement,l=e.image;if(typeof o.queue.copyElementImageToTexture!="function")return;if(!r.hasPaintCallback){r.hasPaintCallback=!0,a.requestPaint();return}let u=s.size.width,c=s.size.height;o.queue.copyElementImageToTexture.length===2?o.queue.copyElementImageToTexture({source:l},{destination:{texture:r.texture},width:u,height:c}):o.queue.copyElementImageToTexture(l,u,c,{texture:r.texture}),e.flipY&&this._flipY(r.texture,s)}else if(i.length>0)for(let o=0,a=i.length;o<a;o++){let l=i[o];this._copyImageToTexture(l,r.texture,s,0,e.flipY,e.premultiplyAlpha,o)}else this._copyImageToTexture(t.image,r.texture,s,0,e.flipY,e.premultiplyAlpha);r.version=e.version}}async copyTextureToBuffer(e,t,r,i,s,o){let a=this.backend.device,l=this.backend.get(e),u=l.texture,c=l.textureDescriptorGPU.format,d=this._getBytesPerTexel(c),h=i*d;h=Math.ceil(h/256)*256,hg.size=(s-1)*h+i*d,hg.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ;let p=a.createBuffer(hg);hg.reset();let f=a.createCommandEncoder(DI);Br.texture=u,Br.origin.x=t,Br.origin.y=r,Br.origin.z=o,pg.buffer=p,pg.bytesPerRow=h,Er.width=i,Er.height=s,f.copyTextureToBuffer(Br,pg,Er),Br.reset(),pg.reset(),Er.reset();let m=this._getTypedArrayType(c);qr(a,f.finish()),await p.mapAsync(GPUMapMode.READ);let g=p.getMappedRange().slice();return p.destroy(),new m(g)}dispose(){this._samplerCache.clear()}_getDefaultTextureGPU(e){let t=this.defaultTexture[e];if(t===void 0){let r=new nt;r.minFilter=Pe,r.magFilter=Pe,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(t===void 0){let r=new _s;r.minFilter=Pe,r.magFilter=Pe,this.createTexture(r,{width:1,height:1,depth:6}),this.defaultCubeTexture[e]=t=r}return this.backend.get(t).texture}_copyCubeMapToTexture(e,t,r){let i=e.images,s=e.mipmaps;for(let o=0;o<6;o++){let a=i[o],l=e.flipY===!0?II[o]:o;a.isDataTexture?this._copyBufferToTexture(a.image,t,r,l,e.flipY):this._copyImageToTexture(a,t,r,l,e.flipY,e.premultiplyAlpha);for(let u=0;u<s.length;u++){let d=s[u].images[o];d.isDataTexture?this._copyBufferToTexture(d.image,t,r,l,e.flipY,0,u+1):this._copyImageToTexture(d,t,r,l,e.flipY,e.premultiplyAlpha,u+1)}}}_copyImageToTexture(e,t,r,i,s,o,a=0){let l=this.backend.device,u=a>0?e.width:r.size.width,c=a>0?e.height:r.size.height;fg.source=e,fg.flipY=s,Tu.texture=t,Tu.mipLevel=a,Tu.origin.z=i,Tu.premultipliedAlpha=o,Er.width=u,Er.height=c;try{l.queue.copyExternalImageToTexture(fg,Tu,Er)}catch{}finally{fg.reset(),Tu.reset(),Er.reset()}}_getPassUtils(){let e=this._passUtils;return e===null&&(this._passUtils=e=new n1(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,i,s,o=0,a=0){let l=this.backend.device,u=e.data,c=this._getBytesPerTexel(r.format),d=e.width*c;Br.texture=t,Br.mipLevel=a,Br.origin.z=i,On.offset=e.width*e.height*c*o,On.bytesPerRow=d,Er.width=e.width,Er.height=e.height,l.queue.writeTexture(Br,u,On,Er),Br.reset(),On.reset(),Er.reset(),s===!0&&this._flipY(t,r,i)}_copyCompressedBufferToTexture(e,t,r,i=null){let s=this.backend.device,o=this._getBlockData(r.format),a=r.size.depthOrArrayLayers>1,l=i&&i.size>0?i:null;for(let u=0;u<e.length;u++){let c=e[u],d=c.width,h=c.height,p=a?r.size.depthOrArrayLayers:1,f=Math.ceil(d/o.width)*o.byteLength,m=Math.ceil(h/o.height),g=f*m,x=Math.ceil(d/o.width)*o.width,w=m*o.height;if(l!==null)for(let v of l)d1(s,t,u,v,c,g,f,m,x,w);else for(let v=0;v<p;v++)d1(s,t,u,v,c,g,f,m,x,w)}}_getBlockData(e){if(e===R.BC1RGBAUnorm||e===R.BC1RGBAUnormSRGB)return{byteLength:8,width:4,height:4};if(e===R.BC2RGBAUnorm||e===R.BC2RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===R.BC3RGBAUnorm||e===R.BC3RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===R.BC4RUnorm||e===R.BC4RSnorm)return{byteLength:8,width:4,height:4};if(e===R.BC5RGUnorm||e===R.BC5RGSnorm)return{byteLength:16,width:4,height:4};if(e===R.BC6HRGBUFloat||e===R.BC6HRGBFloat)return{byteLength:16,width:4,height:4};if(e===R.BC7RGBAUnorm||e===R.BC7RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===R.ETC2RGB8Unorm||e===R.ETC2RGB8UnormSRGB)return{byteLength:8,width:4,height:4};if(e===R.ETC2RGB8A1Unorm||e===R.ETC2RGB8A1UnormSRGB)return{byteLength:8,width:4,height:4};if(e===R.ETC2RGBA8Unorm||e===R.ETC2RGBA8UnormSRGB)return{byteLength:16,width:4,height:4};if(e===R.EACR11Unorm)return{byteLength:8,width:4,height:4};if(e===R.EACR11Snorm)return{byteLength:8,width:4,height:4};if(e===R.EACRG11Unorm)return{byteLength:16,width:4,height:4};if(e===R.EACRG11Snorm)return{byteLength:16,width:4,height:4};if(e===R.ASTC4x4Unorm||e===R.ASTC4x4UnormSRGB)return{byteLength:16,width:4,height:4};if(e===R.ASTC5x4Unorm||e===R.ASTC5x4UnormSRGB)return{byteLength:16,width:5,height:4};if(e===R.ASTC5x5Unorm||e===R.ASTC5x5UnormSRGB)return{byteLength:16,width:5,height:5};if(e===R.ASTC6x5Unorm||e===R.ASTC6x5UnormSRGB)return{byteLength:16,width:6,height:5};if(e===R.ASTC6x6Unorm||e===R.ASTC6x6UnormSRGB)return{byteLength:16,width:6,height:6};if(e===R.ASTC8x5Unorm||e===R.ASTC8x5UnormSRGB)return{byteLength:16,width:8,height:5};if(e===R.ASTC8x6Unorm||e===R.ASTC8x6UnormSRGB)return{byteLength:16,width:8,height:6};if(e===R.ASTC8x8Unorm||e===R.ASTC8x8UnormSRGB)return{byteLength:16,width:8,height:8};if(e===R.ASTC10x5Unorm||e===R.ASTC10x5UnormSRGB)return{byteLength:16,width:10,height:5};if(e===R.ASTC10x6Unorm||e===R.ASTC10x6UnormSRGB)return{byteLength:16,width:10,height:6};if(e===R.ASTC10x8Unorm||e===R.ASTC10x8UnormSRGB)return{byteLength:16,width:10,height:8};if(e===R.ASTC10x10Unorm||e===R.ASTC10x10UnormSRGB)return{byteLength:16,width:10,height:10};if(e===R.ASTC12x10Unorm||e===R.ASTC12x10UnormSRGB)return{byteLength:16,width:12,height:10};if(e===R.ASTC12x12Unorm||e===R.ASTC12x12UnormSRGB)return{byteLength:16,width:12,height:12}}_convertAddressMode(e){let t=ig.ClampToEdge;return e===gs?t=ig.Repeat:e===xs&&(t=ig.MirrorRepeat),t}_convertFilterMode(e){let t=ai.Linear;return(e===Pe||e===zd||e===on)&&(t=ai.Nearest),t}_convertMipmapFilterMode(e){return e===on||e===Ur?ai.Linear:ai.Nearest}_getBytesPerTexel(e){if(e===R.R8Unorm||e===R.R8Snorm||e===R.R8Uint||e===R.R8Sint)return 1;if(e===R.R16Uint||e===R.R16Sint||e===R.R16Float||e===R.RG8Unorm||e===R.RG8Snorm||e===R.RG8Uint||e===R.RG8Sint||e===R.R16Unorm||e===R.R16Snorm)return 2;if(e===R.R32Uint||e===R.R32Sint||e===R.R32Float||e===R.RG16Uint||e===R.RG16Sint||e===R.RG16Float||e===R.RGBA8Unorm||e===R.RGBA8UnormSRGB||e===R.RGBA8Snorm||e===R.RGBA8Uint||e===R.RGBA8Sint||e===R.BGRA8Unorm||e===R.BGRA8UnormSRGB||e===R.RG16Unorm||e===R.RG16Snorm||e===R.RGB9E5UFloat||e===R.RGB10A2Unorm||e===R.RG11B10UFloat||e===R.Depth32Float||e===R.Depth24Plus||e===R.Depth24PlusStencil8||e===R.Depth32FloatStencil8)return 4;if(e===R.RG32Uint||e===R.RG32Sint||e===R.RG32Float||e===R.RGBA16Uint||e===R.RGBA16Sint||e===R.RGBA16Float||e===R.RGBA16Unorm||e===R.RGBA16Snorm)return 8;if(e===R.RGBA32Uint||e===R.RGBA32Sint||e===R.RGBA32Float)return 16}_getTypedArrayType(e){if(e===R.R8Uint)return Uint8Array;if(e===R.R8Sint)return Int8Array;if(e===R.R8Unorm)return Uint8Array;if(e===R.R8Snorm)return Int8Array;if(e===R.RG8Uint)return Uint8Array;if(e===R.RG8Sint)return Int8Array;if(e===R.RG8Unorm)return Uint8Array;if(e===R.RG8Snorm)return Int8Array;if(e===R.RGBA8Uint)return Uint8Array;if(e===R.RGBA8Sint)return Int8Array;if(e===R.RGBA8Unorm||e===R.RGBA8UnormSRGB)return Uint8Array;if(e===R.RGBA8Snorm)return Int8Array;if(e===R.R16Uint)return Uint16Array;if(e===R.R16Sint)return Int16Array;if(e===R.RG16Uint)return Uint16Array;if(e===R.RG16Sint)return Int16Array;if(e===R.RGBA16Uint)return Uint16Array;if(e===R.RGBA16Sint)return Int16Array;if(e===R.R16Float||e===R.RG16Float||e===R.RGBA16Float||e===R.R16Unorm)return Uint16Array;if(e===R.R16Snorm)return Int16Array;if(e===R.RG16Unorm)return Uint16Array;if(e===R.RG16Snorm)return Int16Array;if(e===R.RGBA16Unorm)return Uint16Array;if(e===R.RGBA16Snorm)return Int16Array;if(e===R.R32Uint)return Uint32Array;if(e===R.R32Sint)return Int32Array;if(e===R.R32Float)return Float32Array;if(e===R.RG32Uint)return Uint32Array;if(e===R.RG32Sint)return Int32Array;if(e===R.RG32Float)return Float32Array;if(e===R.RGBA32Uint)return Uint32Array;if(e===R.RGBA32Sint)return Int32Array;if(e===R.RGBA32Float)return Float32Array;if(e===R.BGRA8Unorm||e===R.BGRA8UnormSRGB)return Uint8Array;if(e===R.RGB10A2Unorm||e===R.RGB9E5UFloat||e===R.RG11B10UFloat)return Uint32Array;if(e===R.Depth32Float)return Float32Array;if(e===R.Depth24Plus||e===R.Depth24PlusStencil8)return Uint32Array;if(e===R.Depth32FloatStencil8)return Float32Array}_getDimension(e){let t;return e.is3DTexture||e.isData3DTexture?t=GS.ThreeD:t=GS.TwoD,t}};function mg(n,e){let t=n.format,r=n.type,i=n.normalized,s=n.colorSpace,o=Me.getTransfer(s),a,l=!1;if(i&&(l=e.features.has(xu.TextureFormatsTier1),l===!1&&U("WebGPURenderer: Unable to use normalized textures without texture-formats-tier1 feature.")),n.isCompressedTexture===!0||n.isCompressedArrayTexture===!0)switch(t){case Kn:case Qn:a=o===fe?R.BC1RGBAUnormSRGB:R.BC1RGBAUnorm;break;case Zn:a=o===fe?R.BC2RGBAUnormSRGB:R.BC2RGBAUnorm;break;case Jn:a=o===fe?R.BC3RGBAUnormSRGB:R.BC3RGBAUnorm;break;case fa:a=R.BC4RUnorm;break;case ma:a=R.BC4RSnorm;break;case ln:a=R.BC5RGUnorm;break;case ga:a=R.BC5RGSnorm;break;case da:a=o===fe?R.BC7RGBAUnormSRGB:R.BC7RGBAUnorm;break;case ha:a=R.BC6HRGBFloat;break;case pa:a=R.BC6HRGBUFloat;break;case qo:case Ho:a=o===fe?R.ETC2RGB8UnormSRGB:R.ETC2RGB8Unorm;break;case jo:a=o===fe?R.ETC2RGBA8UnormSRGB:R.ETC2RGBA8Unorm;break;case Xo:a=R.EACR11Unorm;break;case Yo:a=R.EACR11Snorm;break;case an:a=R.EACRG11Unorm;break;case Ko:a=R.EACRG11Snorm;break;case Qo:a=o===fe?R.ASTC4x4UnormSRGB:R.ASTC4x4Unorm;break;case Zo:a=o===fe?R.ASTC5x4UnormSRGB:R.ASTC5x4Unorm;break;case Jo:a=o===fe?R.ASTC5x5UnormSRGB:R.ASTC5x5Unorm;break;case ea:a=o===fe?R.ASTC6x5UnormSRGB:R.ASTC6x5Unorm;break;case ta:a=o===fe?R.ASTC6x6UnormSRGB:R.ASTC6x6Unorm;break;case ra:a=o===fe?R.ASTC8x5UnormSRGB:R.ASTC8x5Unorm;break;case ia:a=o===fe?R.ASTC8x6UnormSRGB:R.ASTC8x6Unorm;break;case sa:a=o===fe?R.ASTC8x8UnormSRGB:R.ASTC8x8Unorm;break;case na:a=o===fe?R.ASTC10x5UnormSRGB:R.ASTC10x5Unorm;break;case oa:a=o===fe?R.ASTC10x6UnormSRGB:R.ASTC10x6Unorm;break;case aa:a=o===fe?R.ASTC10x8UnormSRGB:R.ASTC10x8Unorm;break;case la:a=o===fe?R.ASTC10x10UnormSRGB:R.ASTC10x10Unorm;break;case ua:a=o===fe?R.ASTC12x10UnormSRGB:R.ASTC12x10Unorm;break;case ca:a=o===fe?R.ASTC12x12UnormSRGB:R.ASTC12x12Unorm;break;case wt:a=o===fe?R.RGBA8UnormSRGB:R.RGBA8Unorm;break;default:I("WebGPURenderer: Unsupported texture format.",t)}else switch(t){case wt:switch(r){case Ci:a=R.RGBA8Snorm;break;case mr:a=l?R.RGBA16Snorm:R.RGBA16Sint;break;case er:a=l?R.RGBA16Unorm:R.RGBA16Uint;break;case Ce:a=R.RGBA32Uint;break;case Je:a=R.RGBA32Sint;break;case it:a=o===fe?R.RGBA8UnormSRGB:R.RGBA8Unorm;break;case qe:a=R.RGBA16Float;break;case ze:a=R.RGBA32Float;break;default:I("WebGPURenderer: Unsupported texture type with RGBAFormat.",r)}break;case Ei:switch(r){case qn:a=R.RGB9E5UFloat;break;case jn:a=R.RG11B10UFloat;break;default:I("WebGPURenderer: Unsupported texture type with RGBFormat.",r)}break;case Bi:switch(r){case Ci:a=R.R8Snorm;break;case mr:a=l?R.R16Snorm:R.R16Sint;break;case er:a=l?R.R16Unorm:R.R16Uint;break;case Ce:a=R.R32Uint;break;case Je:a=R.R32Sint;break;case it:a=R.R8Unorm;break;case qe:a=R.R16Float;break;case ze:a=R.R32Float;break;default:I("WebGPURenderer: Unsupported texture type with RedFormat.",r)}break;case vt:switch(r){case Ci:a=R.RG8Snorm;break;case mr:a=l?R.RG16Snorm:R.RG16Sint;break;case er:a=l?R.RG16Unorm:R.RG16Uint;break;case Ce:a=R.RG32Uint;break;case Je:a=R.RG32Sint;break;case it:a=R.RG8Unorm;break;case qe:a=R.RG16Float;break;case ze:a=R.RG32Float;break;default:I("WebGPURenderer: Unsupported texture type with RGFormat.",r)}break;case Mt:switch(r){case er:a=R.Depth16Unorm;break;case Ce:a=R.Depth24Plus;break;case ze:a=R.Depth32Float;break;default:I("WebGPURenderer: Unsupported texture type with DepthFormat.",r)}break;case Ht:switch(r){case Qr:a=R.Depth24PlusStencil8;break;case ze:e&&e.features.has(xu.Depth32FloatStencil8)===!1&&I('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),a=R.Depth32FloatStencil8;break;default:I("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",r)}break;case Fi:switch(r){case Je:a=R.R32Sint;break;case Ce:a=R.R32Uint;break;default:I("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",r)}break;case Li:switch(r){case Je:a=R.RG32Sint;break;case Ce:a=R.RG32Uint;break;default:I("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",r)}break;case Yn:switch(r){case Je:a=R.RGBA32Sint;break;case Ce:a=R.RGBA32Uint;break;default:I("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",r)}break;default:I("WebGPURenderer: Unsupported texture format.",t)}return a}var h1=mN;var OI=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,kI=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/ig,p1={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"},VI=n=>{n=n.trim();let e=n.match(OI);if(e!==null&&e.length===4){let t=e[2],r=[],i=null;for(;(i=kI.exec(t))!==null;)r.push({name:i[1],type:i[2]});let s=[];for(let c=0;c<r.length;c++){let{name:d,type:h}=r[c],p=h;p.startsWith("ptr")?p="pointer":(p.startsWith("texture")&&(p=h.split("<")[0]),p=p1[p]),s.push(new dd(p,d))}let o=n.substring(e[0].length),a=e[3]||"void",l=e[1]!==void 0?e[1]:"";return{type:p1[a]||a,inputs:s,name:l,inputsCode:t,blockCode:o,outputType:a}}else throw new Error("THREE.WGSLNodeFunction: Function is not a WGSL code.")},gN=class extends Vm{constructor(e){let{type:t,inputs:r,name:i,inputsCode:s,blockCode:o,outputType:a}=VI(e);super(t,r,i),this.inputsCode=s,this.blockCode=o,this.outputType=a}getCode(e=this.name){let t=this.outputType!=="void"?"-> "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}},f1=gN;var xN=class extends Om{parseFunction(e){return new f1(e)}},m1=xN;var GI={[mt.READ_ONLY]:"read",[mt.WRITE_ONLY]:"write",[mt.READ_WRITE]:"read_write"},g1={[gs]:"repeat",[Dr]:"clamp",[xs]:"mirror"},yN={vertex:oi.VERTEX,fragment:oi.FRAGMENT,compute:oi.COMPUTE},x1={instance:!0,swizzleAssign:!1,storageBuffer:!0},zI={"^^":"tsl_xor"},$I={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>"},y1={},bd={tsl_xor:new Qe("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new Qe("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new Qe("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new Qe("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new Qe("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new Qe("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new Qe("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new Qe("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 Qe("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 Qe("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new Qe("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 Qe("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),inverse_mat2:new Qe(` | |
| fn tsl_inverse_mat2( m : mat2x2<f32> ) -> mat2x2<f32> { | |
| let det = m[ 0 ][ 0 ] * m[ 1 ][ 1 ] - m[ 0 ][ 1 ] * m[ 1 ][ 0 ]; | |
| return mat2x2<f32>( | |
| m[ 1 ][ 1 ], - m[ 0 ][ 1 ], | |
| - m[ 1 ][ 0 ], m[ 0 ][ 0 ] | |
| ) * ( 1.0 / det ); | |
| } | |
| `),inverse_mat3:new Qe(` | |
| fn tsl_inverse_mat3( m : mat3x3<f32> ) -> mat3x3<f32> { | |
| let a00 = m[ 0 ][ 0 ]; let a01 = m[ 0 ][ 1 ]; let a02 = m[ 0 ][ 2 ]; | |
| let a10 = m[ 1 ][ 0 ]; let a11 = m[ 1 ][ 1 ]; let a12 = m[ 1 ][ 2 ]; | |
| let a20 = m[ 2 ][ 0 ]; let a21 = m[ 2 ][ 1 ]; let a22 = m[ 2 ][ 2 ]; | |
| let b01 = a22 * a11 - a12 * a21; | |
| let b11 = - a22 * a10 + a12 * a20; | |
| let b21 = a21 * a10 - a11 * a20; | |
| let det = a00 * b01 + a01 * b11 + a02 * b21; | |
| return mat3x3<f32>( | |
| b01, ( - a22 * a01 + a02 * a21 ), ( a12 * a01 - a02 * a11 ), | |
| b11, ( a22 * a00 - a02 * a20 ), ( - a12 * a00 + a02 * a10 ), | |
| b21, ( - a21 * a00 + a01 * a20 ), ( a11 * a00 - a01 * a10 ) | |
| ) * ( 1.0 / det ); | |
| } | |
| `),inverse_mat4:new Qe(` | |
| fn tsl_inverse_mat4( m : mat4x4<f32> ) -> mat4x4<f32> { | |
| let a00 = m[ 0 ][ 0 ]; let a01 = m[ 0 ][ 1 ]; let a02 = m[ 0 ][ 2 ]; let a03 = m[ 0 ][ 3 ]; | |
| let a10 = m[ 1 ][ 0 ]; let a11 = m[ 1 ][ 1 ]; let a12 = m[ 1 ][ 2 ]; let a13 = m[ 1 ][ 3 ]; | |
| let a20 = m[ 2 ][ 0 ]; let a21 = m[ 2 ][ 1 ]; let a22 = m[ 2 ][ 2 ]; let a23 = m[ 2 ][ 3 ]; | |
| let a30 = m[ 3 ][ 0 ]; let a31 = m[ 3 ][ 1 ]; let a32 = m[ 3 ][ 2 ]; let a33 = m[ 3 ][ 3 ]; | |
| let b00 = a00 * a11 - a01 * a10; | |
| let b01 = a00 * a12 - a02 * a10; | |
| let b02 = a00 * a13 - a03 * a10; | |
| let b03 = a01 * a12 - a02 * a11; | |
| let b04 = a01 * a13 - a03 * a11; | |
| let b05 = a02 * a13 - a03 * a12; | |
| let b06 = a20 * a31 - a21 * a30; | |
| let b07 = a20 * a32 - a22 * a30; | |
| let b08 = a20 * a33 - a23 * a30; | |
| let b09 = a21 * a32 - a22 * a31; | |
| let b10 = a21 * a33 - a23 * a31; | |
| let b11 = a22 * a33 - a23 * a32; | |
| let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; | |
| return mat4x4<f32>( | |
| a11 * b11 - a12 * b10 + a13 * b09, | |
| a02 * b10 - a01 * b11 - a03 * b09, | |
| a31 * b05 - a32 * b04 + a33 * b03, | |
| a22 * b04 - a21 * b05 - a23 * b03, | |
| a12 * b08 - a10 * b11 - a13 * b07, | |
| a00 * b11 - a02 * b08 + a03 * b07, | |
| a32 * b02 - a30 * b05 - a33 * b01, | |
| a20 * b05 - a22 * b02 + a23 * b01, | |
| a10 * b10 - a11 * b08 + a13 * b06, | |
| a01 * b08 - a00 * b10 - a03 * b06, | |
| a30 * b04 - a31 * b02 + a33 * b00, | |
| a21 * b02 - a20 * b04 - a23 * b00, | |
| a11 * b07 - a10 * b09 - a12 * b06, | |
| a00 * b09 - a01 * b07 + a02 * b06, | |
| a31 * b01 - a30 * b03 - a32 * b00, | |
| a20 * b03 - a21 * b01 + a22 * b00 | |
| ) * ( 1.0 / det ); | |
| } | |
| `),biquadraticTexture:new Qe(` | |
| fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f { | |
| let res = vec2f( iRes ); | |
| let uvScaled = coord * res; | |
| let uvWrapping = ( ( uvScaled % res ) + res ) % res; | |
| // https://www.shadertoy.com/view/WtyXRy | |
| let uv = uvWrapping - 0.5; | |
| let iuv = floor( uv ); | |
| let f = fract( uv ); | |
| let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level ); | |
| let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level ); | |
| let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level ); | |
| let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level ); | |
| return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y ); | |
| } | |
| `),biquadraticTextureArray:new Qe(` | |
| fn tsl_biquadraticTexture_array( map : texture_2d_array<f32>, coord : vec2f, iRes : vec2u, layer : u32, level : u32 ) -> vec4f { | |
| let res = vec2f( iRes ); | |
| let uvScaled = coord * res; | |
| let uvWrapping = ( ( uvScaled % res ) + res ) % res; | |
| // https://www.shadertoy.com/view/WtyXRy | |
| let uv = uvWrapping - 0.5; | |
| let iuv = floor( uv ); | |
| let f = fract( uv ); | |
| let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, layer, level ); | |
| let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, layer, level ); | |
| let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, layer, level ); | |
| let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, layer, level ); | |
| return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y ); | |
| } | |
| `)},WI={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",inverse_mat2:"tsl_inverse_mat2",inverse_mat3:"tsl_inverse_mat3",inverse_mat4:"tsl_inverse_mat4",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"},HI=new Set(["alias","break","case","const","const_assert","continue","continuing","default","diagnostic","discard","else","enable","false","fn","for","if","let","loop","override","requires","return","struct","switch","true","var","while","NULL","Self","abstract","active","alignas","alignof","as","asm","asm_fragment","async","attribute","auto","await","become","binding_array","cast","catch","class","co_await","co_return","co_yield","coherent","column_major","common","compile","compile_fragment","concept","const_cast","consteval","constexpr","constinit","crate","debugger","decltype","delete","demote","demote_to_helper","do","dynamic_cast","enum","explicit","export","extends","extern","external","fallthrough","filter","final","finally","friend","from","fxgroup","get","goto","groupshared","highp","impl","implements","import","inline","instanceof","interface","layout","lowp","macro","macro_rules","match","mediump","meta","mod","module","move","mut","mutable","namespace","new","nil","noexcept","noinline","nointerpolation","non_coherent","noncoherent","noperspective","null","nullptr","of","operator","package","packoffset","partition","pass","patch","pixelfragment","precise","precision","premerge","priv","protected","pub","public","readonly","ref","regardless","register","reinterpret_cast","require","resource","restrict","self","set","shared","sizeof","smooth","snorm","static","static_assert","static_cast","std","subroutine","super","target","template","this","thread_local","throw","trait","try","type","typedef","typeid","typename","typeof","union","unless","unorm","unsafe","unsized","use","using","varying","virtual","volatile","wgsl","where","with","writeonly","yield","main"]),b1="";(typeof navigator<"u"&&/Firefox|Deno/g.test(navigator.userAgent))!==!0&&(b1+=`diagnostic( off, derivative_uniformity ); | |
| `);var bN=class extends cd{constructor(e,t){super(e,t,new m1),this.uniformGroups={},this.uniformGroupsBindings={},this.builtins={},this.directives={},this.scopedArrays=new Map,this.allowEarlyReturns=!0,this.allowGlobalVariables=!0}_generateTextureSample(e,t,r,i,s,o=this.shaderStage){return o==="fragment"?i?s?`textureSample( ${t}, ${t}_sampler, ${r}, ${i}, ${s} )`:`textureSample( ${t}, ${t}_sampler, ${r}, ${i} )`:s?`textureSample( ${t}, ${t}_sampler, ${r}, ${s} )`:`textureSample( ${t}, ${t}_sampler, ${r} )`:this.generateTextureSampleLevel(e,t,r,"0",i)}generateTextureSampleLevel(e,t,r,i,s,o){return this.isUnfilterable(e)===!1?s?o?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${o} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`:o?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i}, ${o} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,r,o,i,s):this.generateTextureLod(e,t,r,s,o,i)}generateWrapFunction(e){let t=`tsl_coord_${g1[e.wrapS]}S_${g1[e.wrapT]}T_${e.is3DTexture||e.isData3DTexture?"3d":"2d"}`,r=y1[t];if(r===void 0){let i=[],s=e.is3DTexture||e.isData3DTexture?"vec3f":"vec2f",o=`fn ${t}( coord : ${s} ) -> ${s} { | |
| return ${s}( | |
| `,a=(l,u)=>{l===gs?(i.push(bd.repeatWrapping_float),o+=` tsl_repeatWrapping_float( coord.${u} )`):l===Dr?(i.push(bd.clampWrapping_float),o+=` tsl_clampWrapping_float( coord.${u} )`):l===xs?(i.push(bd.mirrorWrapping_float),o+=` tsl_mirrorWrapping_float( coord.${u} )`):(o+=` coord.${u}`,U(`WebGPURenderer: Unsupported texture wrap type "${l}" for vertex shader.`))};a(e.wrapS,"x"),o+=`, | |
| `,a(e.wrapT,"y"),(e.is3DTexture||e.isData3DTexture)&&(o+=`, | |
| `,a(e.wrapR,"z")),o+=` | |
| ); | |
| } | |
| `,y1[t]=r=new Qe(o,i)}return r.build(this),t}generateArrayDeclaration(e,t){return`array< ${this.getType(e)}, ${t} >`}generateTextureDimension(e,t,r){let i=this.getDataFromNode(e,this.shaderStage,this.cache);i.dimensionsSnippet===void 0&&(i.dimensionsSnippet={});let s=i.dimensionsSnippet[r];if(i.dimensionsSnippet[r]===void 0){let o,a,{primarySamples:l}=this.renderer.backend.utils.getTextureSampleData(e),u=l>1;e.is3DTexture||e.isData3DTexture?a="vec3<u32>":a="vec2<u32>",u||e.isStorageTexture?o=t:o=`${t}${r?`, u32( ${r} )`:""}`,s=new hc(new fc(`textureDimensions( ${o} )`,a)),i.dimensionsSnippet[r]=s,(e.isArrayTexture||e.isDataArrayTexture||e.is3DTexture||e.isData3DTexture)&&(i.arrayLayerCount=new hc(new fc(`textureNumLayers(${t})`,"u32"))),e.isTextureCube&&(i.cubeFaceCount=new hc(new fc("6u","u32")))}return s.build(this)}generateTextureSize(e,t,r){let{primarySamples:i}=this.renderer.backend.utils.getTextureSampleData(e);return`textureDimensions( ${i>1||e.isStorageTexture?t:`${t}, ${r}`} )`}generateFilteredTexture(e,t,r,i,s="0u",o){let a=this.generateWrapFunction(e),l=this.generateTextureDimension(e,t,s);return i&&(r=`${r} + vec2<f32>(${i}) / ${l}`),o?(this._include("biquadraticTextureArray"),`tsl_biquadraticTexture_array( ${t}, ${a}( ${r} ), ${l}, u32( ${o} ), u32( ${s} ) )`):(this._include("biquadraticTexture"),`tsl_biquadraticTexture( ${t}, ${a}( ${r} ), ${l}, u32( ${s} ) )`)}generateTextureLod(e,t,r,i,s,o="0u"){if(e.isCubeTexture===!0){s&&(r=`${r} + vec3<f32>(${s})`);let p=e.isDepthTexture?"u32":"f32";return`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${p}( ${o} ) )`}let a=this.generateWrapFunction(e),l=this.generateTextureDimension(e,t,o),u=e.is3DTexture||e.isData3DTexture?"vec3":"vec2",c=u==="vec3"?"vec3<u32>( 1, 1, 1 )":"vec2<u32>( 1, 1 )";s&&(r=`${r} + ${u}<f32>(${s}) / ${u}<f32>( ${l} )`);let d=`${u}<f32>( 0 )`,h=`${u}<f32>( ${l} - ${c} )`;return r=`${u}<u32>( clamp( floor( ${a}( ${r} ) * ${u}<f32>( ${l} ) ), ${d}, ${h} ) )`,this.generateTextureLoad(e,t,r,o,i,null)}generateStorageTextureLoad(e,t,r,i,s,o){o&&(r=`${r} + ${o}`);let a;return s?a=`textureLoad( ${t}, ${r}, ${s} )`:a=`textureLoad( ${t}, ${r} )`,a}generateTextureLoad(e,t,r,i,s,o){i===null&&(i="0u"),o&&(r=`${r} + ${o}`);let a;return s?a=`textureLoad( ${t}, ${r}, ${s}, u32( ${i} ) )`:(a=`textureLoad( ${t}, ${r}, u32( ${i} ) )`,this.renderer.backend.compatibilityMode&&e.isDepthTexture&&(a+=".x")),a}generateTextureStore(e,t,r,i,s){let o;return i?o=`textureStore( ${t}, ${r}, ${i}, ${s} )`:o=`textureStore( ${t}, ${r}, ${s} )`,o}isSampleCompare(e){return e.isDepthTexture===!0&&e.compareFunction!==null&&this.renderer.hasCompatibility(xr.TEXTURE_COMPARE)}isUnfilterable(e){return this.getComponentTypeFromTexture(e)!=="float"||!this.isAvailable("float32Filterable")&&e.type===ze||this.isSampleCompare(e)===!1&&e.minFilter===Pe&&e.magFilter===Pe||this.renderer.backend.utils.getTextureSampleData(e).primarySamples>1||e.normalized===!0&&(e.type===mr||e.type===er)}generateTexture(e,t,r,i,s,o=this.shaderStage){let a=null;return this.isUnfilterable(e)?a=this.generateTextureLod(e,t,r,i,s,"0",o):a=this._generateTextureSample(e,t,r,i,s,o),a}generateTextureGrad(e,t,r,i,s,o,a=this.shaderStage){if(a==="fragment")return s?o?`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${s}, ${i[0]}, ${i[1]}, ${o} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${s}, ${i[0]}, ${i[1]} )`:o?`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${i[0]}, ${i[1]}, ${o} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${i[0]}, ${i[1]} )`;I(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${a} shader.`)}generateTextureCompare(e,t,r,i,s,o,a=this.shaderStage){if(a==="fragment")return e.isDepthTexture===!0&&e.isArrayTexture===!0?o?`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${o} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`:o?`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${i}, ${o} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${i} )`;I(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${a} shader.`)}generateTextureGather(e,t,r,i,s,o){let a=e.isDepthTexture===!0?"":`${i}, `;return s?o?`textureGather( ${a}${t}, ${t}_sampler, ${r}, ${s}, ${o} )`:`textureGather( ${a}${t}, ${t}_sampler, ${r}, ${s} )`:o?`textureGather( ${a}${t}, ${t}_sampler, ${r}, ${o} )`:`textureGather( ${a}${t}, ${t}_sampler, ${r})`}generateTextureGatherCompare(e,t,r,i,s,o){return s?o?`textureGatherCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${o} )`:`textureGatherCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i})`:o?`textureGatherCompare( ${t}, ${t}_sampler, ${r}, ${i}, ${o} )`:`textureGatherCompare( ${t}, ${t}_sampler, ${r}, ${i})`}generateTextureLevel(e,t,r,i,s,o){return this.isUnfilterable(e)===!1?s?o?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${o} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`:o?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i}, ${o} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,r,o,i,s):this.generateTextureLod(e,t,r,s,o,i)}generateTextureBias(e,t,r,i,s,o,a=this.shaderStage){if(a==="fragment")return s?o?`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${o} )`:`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`:o?`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${i}, ${o} )`:`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${i} )`;I(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${a} shader.`)}getPropertyName(e,t=this.shaderStage){if(e.isNodeVarying===!0&&e.needsInterpolation===!0){if(t==="vertex")return`varyings.${e.name}`}else if(e.isNodeUniform===!0){let r=e.name,i=e.type;return i==="texture"||i==="cubeTexture"||i==="cubeDepthTexture"||i==="storageTexture"||i==="texture3D"?r:i==="buffer"||i==="storageBuffer"||i==="indirectStorageBuffer"?this.isCustomStruct(e)?r:r+".value":e.groupNode.name+"."+r}return super.getPropertyName(e)}isReservedKeyword(e){return HI.has(e)}getOutputStructName(){return"output"}getFunctionOperator(e){let t=zI[e];return t!==void 0?(this._include(t),t):null}getNodeAccess(e,t){return t!=="compute"?e.isAtomic===!0?t==="vertex"?(U("WebGPURenderer: Atomic operations are not supported in the vertex stage. They are only available in the fragment and compute stages."),mt.READ_ONLY):mt.READ_WRITE:mt.READ_ONLY:e.access}getStorageAccess(e,t){return GI[this.getNodeAccess(e,t)]}getUniformFromNode(e,t,r,i=null){let s=super.getUniformFromNode(e,t,r,i),o=this.getDataFromNode(e,r,this.globalCache);if(o.uniformGPU===void 0){let a,l=e.groupNode,u=l.name,c=this.getBindGroupArray(u,r);if(t==="texture"||t==="cubeTexture"||t==="cubeDepthTexture"||t==="storageTexture"||t==="texture3D"){let d=null,h=this.getNodeAccess(e,r);if(t==="texture"||t==="storageTexture"?e.value.is3DTexture===!0?d=new ja(s.name,s.node,l,h):d=new Ao(s.name,s.node,l,h):t==="cubeTexture"||t==="cubeDepthTexture"?d=new fu(s.name,s.node,l,h):t==="texture3D"&&(d=new ja(s.name,s.node,l,h)),d.store=e.isStorageTextureNode===!0,d.mipLevel=d.store?e.mipLevel:0,d.setVisibility(yN[r]),e.value.isCubeTexture===!0||this.isUnfilterable(e.value)===!1&&d.store===!1||e.gatherNode!==null){let f=new t1(`${s.name}_sampler`,s.node,l);f.setVisibility(yN[r]),c.push(f,d),a=[f,d]}else c.push(d),a=[d]}else if(t==="buffer"||t==="storageBuffer"||t==="indirectStorageBuffer"){let d=this.getSharedDataFromNode(e),h=d.buffer;if(h===void 0){let p=t==="buffer"?Xm:i1;h=new p(e,l),d.buffer=h}h.setVisibility(h.getVisibility()|yN[r]),c.push(h),a=h,s.name=i||"NodeBuffer_"+s.id}else{let d=this.uniformGroups[u];d===void 0&&(d=new Ym(u,l),d.setVisibility(oi.VERTEX|oi.FRAGMENT|oi.COMPUTE),this.uniformGroups[u]=d),c.indexOf(d)===-1&&c.push(d),a=this.getNodeUniform(s,t);let h=a.name;d.uniforms.some(f=>f.name===h)||d.addUniform(a)}o.uniformGPU=a}return s}getBuiltin(e,t,r,i=this.shaderStage){let s=this.builtins[i]||(this.builtins[i]=new Map);return s.has(e)===!1&&s.set(e,{name:e,property:t,type:r}),t}hasBuiltin(e,t=this.shaderStage){return this.builtins[t]!==void 0&&this.builtins[t].has(e)}getVertexIndex(){return this.shaderStage==="vertex"?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){let t=e.layout,r=this.flowShaderNode(e),i=[];for(let o of t.inputs)i.push(o.name+" : "+this.getType(o.type));let s=`fn ${t.name}( ${i.join(", ")} ) -> ${this.getType(t.type)} { | |
| ${r.vars} | |
| ${r.code} | |
| `;return r.result&&(s+=` return ${r.result}; | |
| `),s+=` | |
| } | |
| `,s}getInstanceIndex(){return this.shaderStage==="vertex"?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){let t=[],r=this.directives[e];if(r!==void 0)for(let i of r)t.push(`enable ${i};`);return t.join(` | |
| `)}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){let t=[],r=this.builtins[e];if(r!==void 0)for(let{name:i,property:s,type:o}of r.values())t.push(`@builtin( ${i} ) ${s} : ${o}`);return t.join(`, | |
| `)}getScopedArray(e,t,r,i){return this.scopedArrays.has(e)===!1&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:r,bufferCount:i}),e}getScopedArrays(e){if(e!=="compute")return;let t=[];for(let{name:r,scope:i,bufferType:s,bufferCount:o}of this.scopedArrays.values()){let a=this.getType(s);t.push(`var<${i}> ${r}: array< ${a}, ${o} >;`)}return t.join(` | |
| `)}getAttributes(e){let t=[];if(e==="compute"&&(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"))),e==="vertex"||e==="compute"){let r=this.getBuiltins("attribute");r&&t.push(r);let i=this.getAttributesArray();for(let s=0,o=i.length;s<o;s++){let a=i[s],l=a.name,u=this.getType(a.type);t.push(`@location( ${s} ) ${l} : ${u}`)}}return t.join(`, | |
| `)}getStructMembers(e){let t=[];for(let r of e.members){let i=e.output?"@location( "+r.index+" ) ":"",s=this.getType(r.type);r.atomic&&(s="atomic< "+s+" >"),t.push(` ${i+r.name} : ${s}`)}return e.output&&t.push(` ${this.getBuiltins("output")}`),t.join(`, | |
| `)}getStructs(e){let t="",r=this.structs[e];if(r.length>0){let i=[];for(let s of r){let o=`struct ${s.name} { | |
| `;o+=this.getStructMembers(s),o+=` | |
| };`,i.push(o)}t=` | |
| `+i.join(` | |
| `)+` | |
| `}return t}getVar(e,t,r=null,i=""){let s=`var${i} ${t} : `;return r!==null?s+=this.generateArrayDeclaration(e,r):s+=this.getType(e),s}getVars(e,t=!1){let r="";t&&(r="<private>");let i=[],s=this.vars[e];if(s!==void 0)for(let o of s)i.push(`${this.getVar(o.type,o.name,o.count,r)};`);return t?i.join(` | |
| `):` | |
| ${i.join(` | |
| `)} | |
| `}getVaryings(e){let t=[];if(e==="vertex"&&this.getBuiltin("position","builtinClipSpace","vec4<f32>","vertex"),e==="vertex"||e==="fragment"){let s=this.varyings,o=this.vars[e],a=0;for(let l=0;l<s.length;l++){let u=s[l];if(u.needsInterpolation){let c=`@location( ${a++} )`;if(u.interpolationType){let d=u.interpolationSampling!==null?`, ${u.interpolationSampling} )`:" )";c+=` @interpolate( ${u.interpolationType}${d}`}else/^(int|uint|ivec|uvec)/.test(u.type)&&(c+=" @interpolate(flat, either)");t.push(`${c} ${u.name} : ${this.getType(u.type)}`)}else e==="vertex"&&o.includes(u)===!1&&o.push(u)}}let r=this.getBuiltins(e);r&&t.push(r);let i=t.join(`, | |
| `);return e==="vertex"?this._getWGSLStruct("VaryingsStruct"," "+i):i}isCustomStruct(e){let t=e.value,r=e.node,i=(t.isBufferAttribute||t.isInstancedBufferAttribute)&&r.structTypeNode!==null,s=r.value&&r.value.array&&typeof r.value.itemSize=="number"&&r.value.array.length>r.value.itemSize;return i&&!s}getUniforms(e){let t=this.renderer.backend,r=this.uniforms[e],i=[],s=[],o=[],a={};for(let u of r){let c=u.groupNode.name,d=this.bindingsIndexes[c];if(u.type==="texture"||u.type==="cubeTexture"||u.type==="cubeDepthTexture"||u.type==="storageTexture"||u.type==="texture3D"){let h=u.node,p=h.value;(p.isCubeTexture===!0||this.isUnfilterable(p)===!1&&h.isStorageTextureNode!==!0||h.gatherNode!==null)&&(this.isSampleCompare(p)&&h.compareNode!==null?i.push(`@binding( ${d.binding++} ) @group( ${d.group} ) var ${u.name}_sampler : sampler_comparison;`):i.push(`@binding( ${d.binding++} ) @group( ${d.group} ) var ${u.name}_sampler : sampler;`));let m,g="",{primarySamples:x}=t.utils.getTextureSampleData(p);if(x>1&&(g="_multisampled"),p.isCubeTexture===!0&&p.isDepthTexture===!0)m="texture_depth_cube";else if(p.isCubeTexture===!0)m="texture_cube<f32>";else if(p.isDepthTexture===!0)t.compatibilityMode&&p.compareFunction===null?m=`texture${g}_2d<f32>`:m=`texture_depth${g}_2d${p.isArrayTexture===!0?"_array":""}`;else if(u.node.isStorageTextureNode===!0){let w=mg(p,t.device),v=this.getStorageAccess(u.node,e),E=u.node.value.is3DTexture,b=u.node.value.isArrayTexture;m=`texture_storage_${E?"3d":`2d${b?"_array":""}`}<${w}, ${v}>`}else if(p.isArrayTexture===!0||p.isDataArrayTexture===!0||p.isCompressedArrayTexture===!0)m="texture_2d_array<f32>";else if(p.is3DTexture===!0||p.isData3DTexture===!0)m="texture_3d<f32>";else{let w=this.getComponentTypeFromTexture(p).charAt(0);m=`texture${g}_2d<${w}32>`}i.push(`@binding( ${d.binding++} ) @group( ${d.group} ) var ${u.name} : ${m};`)}else if(u.type==="buffer"||u.type==="storageBuffer"||u.type==="indirectStorageBuffer"){let h=u.node,p=this.getType(h.getNodeType(this)),f=h.bufferCount,m=f>0&&u.type==="buffer"?", "+f:"",g=h.isStorageBufferNode?`storage, ${this.getStorageAccess(h,e)}`:"uniform";if(this.isCustomStruct(u))s.push(`@binding( ${d.binding++} ) @group( ${d.group} ) var<${g}> ${u.name} : ${p};`);else{let w=` value : array< ${h.isAtomic?`atomic<${p}>`:`${p}`}${m} >`;s.push(this._getWGSLStructBinding(u.name,w,g,d.binding++,d.group))}}else{let h=u.groupNode.name;if(a[h]===void 0){let p=this.uniformGroups[h];if(p!==void 0){let f=[];for(let g of p.uniforms){let x=g.getType(),w=this.getType(this.getVectorType(x));f.push(` ${g.name} : ${w}`)}let m=this.uniformGroupsBindings[h];m===void 0&&(m={index:d.binding++,id:d.group},this.uniformGroupsBindings[h]=m),a[h]={index:m.index,id:m.id,snippets:f}}}}}for(let u in a){let c=a[u];o.push(this._getWGSLStructBinding(u,c.snippets.join(`, | |
| `),"uniform",c.index,c.id))}return[...i,...s,...o].join(` | |
| `)}buildCode(){let e=this.material!==null?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(let t in e){this.shaderStage=t;let r=this.allowGlobalVariables,i=e[t];i.uniforms=this.getUniforms(t),i.attributes=this.getAttributes(t),i.varyings=this.getVaryings(t),i.structs=this.getStructs(t),i.vars=this.getVars(t,r),i.codes=this.getCodes(t),i.directives=this.getDirectives(t),i.scopedArrays=this.getScopedArrays(t);let s=`// code | |
| `;s+=this.flowCode[t];let o=this.flowNodes[t],a=o[o.length-1],l=a.outputNode,u=l!==void 0&&l.isOutputStructNode===!0;for(let c of o){let d=this.getFlowData(c),h=c.name;if(h&&(s.length>0&&(s+=` | |
| `),s+=` // flow -> ${h} | |
| `),s+=`${d.code} | |
| `,c===a&&t!=="compute"){if(s+=`// result | |
| `,t==="vertex")s+=`varyings.builtinClipSpace = ${d.result};`;else if(t==="fragment")if(u)i.returnType=l.getNodeType(this),i.structs+="var<private> output : "+i.returnType+";",s+=`return ${d.result};`;else{let p=` @location( 0 ) color: ${this.getType(this.getOutputType())}`,f=this.getBuiltins("output");f&&(p+=`, | |
| `+f),i.returnType="OutputStruct",i.structs+=this._getWGSLStruct("OutputStruct",p),i.structs+=` | |
| var<private> output : OutputStruct;`,s+=`output.color = ${this.format(d.result,a.getNodeType(this),this.getOutputType())}; | |
| return output;`}}}i.flow=s}if(this.shaderStage=null,this.material!==null)this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment);else{let t=this.object.workgroupSize;this.computeShader=this._getWGSLComputeCode(e.compute,t)}}getMethod(e,t=null){let r;return t!==null&&(r=this._getWGSLMethod(e+"_"+t)),r===void 0&&(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 $I[e]||e}isAvailable(e){let t=x1[e];return t===void 0&&(e==="float32Filterable"?t=this.renderer.hasFeature("float32-filterable"):e==="clipDistance"&&(t=this.renderer.hasFeature("clip-distances")),x1[e]=t),t}_getWGSLMethod(e){return bd[e]!==void 0&&this._include(e),WI[e]}_include(e){let t=bd[e];return t.build(this),this.addInclude(t),t}_getWGSLVertexCode(e){return`${this.getSignature()} | |
| // directives | |
| ${e.directives} | |
| // structs | |
| ${e.structs} | |
| // uniforms | |
| ${e.uniforms} | |
| // varyings | |
| ${e.varyings} | |
| var<private> varyings : VaryingsStruct; | |
| // vars | |
| ${e.vars} | |
| // codes | |
| ${e.codes} | |
| @vertex | |
| fn main( ${e.attributes} ) -> VaryingsStruct { | |
| // flow | |
| ${e.flow} | |
| return varyings; | |
| } | |
| `}_getWGSLFragmentCode(e){return`${this.getSignature()} | |
| // global | |
| ${b1} | |
| // structs | |
| ${e.structs} | |
| // uniforms | |
| ${e.uniforms} | |
| // vars | |
| ${e.vars} | |
| // codes | |
| ${e.codes} | |
| @fragment | |
| fn main( ${e.varyings} ) -> ${e.returnType} { | |
| // flow | |
| ${e.flow} | |
| } | |
| `}_getWGSLComputeCode(e,t){let[r,i,s]=t;return`${this.getSignature()} | |
| // directives | |
| ${e.directives} | |
| // system | |
| var<private> instanceIndex : u32; | |
| // locals | |
| ${e.scopedArrays} | |
| // structs | |
| ${e.structs} | |
| // uniforms | |
| ${e.uniforms} | |
| // vars | |
| ${this.allowGlobalVariables?e.vars:""} | |
| // codes | |
| ${e.codes} | |
| @compute @workgroup_size( ${r}, ${i}, ${s} ) | |
| fn main( ${e.attributes} ) { | |
| // local vars | |
| ${this.allowGlobalVariables?"":e.vars} | |
| // system | |
| instanceIndex = globalId.x | |
| + globalId.y * ( ${r} * numWorkgroups.x ) | |
| + globalId.z * ( ${r} * numWorkgroups.x ) * ( ${i} * numWorkgroups.y ); | |
| // flow | |
| ${e.flow} | |
| } | |
| `}_getWGSLStruct(e,t){return` | |
| struct ${e} { | |
| ${t} | |
| };`}_getWGSLStructBinding(e,t,r,i=0,s=0){let o=e+"Struct";return`${this._getWGSLStruct(o,t)} | |
| @binding( ${i} ) @group( ${s} ) | |
| var<${r}> ${e} : ${o};`}},_1=bN;var Fr=new Yi,_N=new Xs,T1=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]);typeof Float16Array<"u"&&T1.set(Float16Array,["float16"]);var qI=new Map([[Tl,["float16"]]]),jI=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]),TN=class{constructor(e){this.backend=e}createAttribute(e,t){let r=this._getBufferAttribute(e),i=this.backend,s=i.get(r),o=s.buffer;if(o===void 0){let a=i.device,l=r.array;if(e.normalized===!1){if(l.constructor===Int16Array||l.constructor===Int8Array)l=new Int32Array(l);else if((l.constructor===Uint16Array||l.constructor===Uint8Array)&&(l=new Uint32Array(l),t&GPUBufferUsage.INDEX))for(let h=0;h<l.length;h++)l[h]===65535&&(l[h]=4294967295)}r.array=l;let u;if((r.isStorageBufferAttribute||r.isStorageInstancedBufferAttribute)&&r.itemSize===3)u=4;else if(r.itemSize>1&&r.itemSize*l.BYTES_PER_ELEMENT%4!==0){let h=r.itemSize*l.BYTES_PER_ELEMENT;u=Math.floor((h+3)/4)*4/l.BYTES_PER_ELEMENT}if(u!==void 0){let h=r.itemSize,p=new l.constructor(r.count*u);for(let f=0;f<r.count;f++)p.set(l.subarray(f*h,f*h+h),f*u);(r.isStorageBufferAttribute||r.isStorageInstancedBufferAttribute)&&(r.itemSize=u,r.array=p),l=p,s._itemSize=h,s._paddedItemSize=u}let c=l.byteLength,d=c+(4-c%4)%4;Fr.label=r.name,Fr.size=d,Fr.usage=t,Fr.mappedAtCreation=!0,o=a.createBuffer(Fr),Fr.reset(),new l.constructor(o.getMappedRange()).set(l),o.unmap(),s.buffer=o}}updateAttribute(e){let t=this._getBufferAttribute(e),r=this.backend,i=r.device,s=r.get(t),o=r.get(t).buffer,a=t.array,l=s._itemSize,u=s._paddedItemSize;if(u!==void 0){a=new a.constructor(t.count*u);for(let d=0;d<t.count;d++)a.set(t.array.subarray(d*l,d*l+l),d*u);(t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute)&&(t.array=a)}let c=t.updateRanges;if(c.length===0)i.queue.writeBuffer(o,0,a,0);else{let d=ba(a),h=d?1:a.BYTES_PER_ELEMENT;for(let p=0,f=c.length;p<f;p++){let m=c[p],g,x;if(u!==void 0){let v=Math.floor(m.start/l),E=Math.ceil((m.start+m.count)/l)-v;g=v*u*h,x=E*u*h}else g=m.start*h,x=m.count*h;let w=g*(d?a.BYTES_PER_ELEMENT:1);i.queue.writeBuffer(o,w,a,g,x)}t.clearUpdateRanges()}}createShaderVertexBuffers(e){let t=e.getAttributes(),r=new Map;for(let i=0;i<t.length;i++){let s=t[i],o=s.array.BYTES_PER_ELEMENT,a=this._getBufferAttribute(s),l=r.get(a);if(l===void 0){let d,h;s.isInterleavedBufferAttribute===!0?(d=s.data.stride*o,h=s.data.isInstancedInterleavedBuffer?gd.Instance:gd.Vertex):(d=s.itemSize*o,h=s.isInstancedBufferAttribute?gd.Instance:gd.Vertex,s.itemSize>1&&d%4!==0&&(d=Math.floor((d+3)/4)*4)),s.normalized===!1&&(s.array.constructor===Int16Array||s.array.constructor===Uint16Array)&&(d=4),l={arrayStride:d,attributes:[],stepMode:h},r.set(a,l)}let u=this._getVertexFormat(s),c=s.isInterleavedBufferAttribute===!0?s.offset*o:0;l.attributes.push({shaderLocation:i,offset:c,format:u})}return Array.from(r.values())}destroyAttribute(e){let t=this.backend;t.get(this._getBufferAttribute(e)).buffer.destroy(),t.delete(e)}async getArrayBufferAsync(e,t=null,r=0,i=-1){let s=this.backend,o=s.device,l=s.get(this._getBufferAttribute(e)).buffer,u=i===-1?l.size-r:i,c;if(t!==null&&t.isReadbackBuffer){let p=s.get(t);if(t._mapped===!0)throw new Error("THREE.WebGPUAttributeUtils: ReadbackBuffer must be released before being used again.");if(t._mapped=!0,p.readBufferGPU===void 0){Fr.label=`${t.name}_readback`,Fr.size=t.maxByteLength,Fr.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,c=o.createBuffer(Fr),Fr.reset();let f=()=>{t.buffer=null,t._mapped=!1,c.unmap()},m=()=>{t.buffer=null,t._mapped=!1,c.destroy(),s.delete(t),t.removeEventListener("release",f),t.removeEventListener("dispose",m)};t.addEventListener("release",f),t.addEventListener("dispose",m),p.readBufferGPU=c}else c=p.readBufferGPU}else Fr.label=`${e.name}_readback`,Fr.size=u,Fr.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,c=o.createBuffer(Fr),Fr.reset();_N.label=`readback_encoder_${e.name}`;let d=o.createCommandEncoder(_N);_N.reset(),d.copyBufferToBuffer(l,r,c,0,u);let h=d.finish();if(qr(o,h),await c.mapAsync(GPUMapMode.READ,0,u),t===null){let f=c.getMappedRange(0,u).slice();return c.destroy(),f}else{if(t.isReadbackBuffer)return t.buffer=c.getMappedRange(0,u),t;{let p=c.getMappedRange(0,u);return new Uint8Array(t).set(new Uint8Array(p)),c.destroy(),t}}}_getVertexFormat(e){let{itemSize:t,normalized:r}=e,i=e.array.constructor,s=e.constructor,o;if(t===1)o=jI.get(i);else{let l=(qI.get(s)||T1.get(i))[r?1:0];if(l){let u=i.BYTES_PER_ELEMENT*t,d=Math.floor((u+3)/4)*4/i.BYTES_PER_ELEMENT;if(d%1)throw new Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");o=`${l}x${d}`}}return o||I("WebGPUAttributeUtils: Vertex format not supported yet."),o}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}},S1=TN;var Mi=new ng,_d=new Yi,Su=new yu,SN=class{constructor(e){this.layoutGPU=e,this.usedTimes=0}},NN=class{constructor(e){this.backend=e,this._bindGroupLayoutCache=new Map}createBindingsLayout(e){let t=this.backend,r=t.device,i=t.get(e);if(i.layout)return i.layout.layoutGPU;let s=this._createLayoutEntries(e),o=Ii(JSON.stringify(s)),a=this._bindGroupLayoutCache.get(o);return a===void 0&&(a=new SN(r.createBindGroupLayout({entries:s})),this._bindGroupLayoutCache.set(o,a)),a.usedTimes++,i.layout=a,i.layoutKey=o,a.layoutGPU}createBindings(e,t,r,i=0){let{backend:s}=this,o=s.get(e),a=this.createBindingsLayout(e),l;r>0&&(o.groups===void 0&&(o.groups=[],o.versions=[]),o.versions[r]===i&&(l=o.groups[r])),l===void 0&&(l=this.createBindGroup(e,a),r>0&&(o.groups[r]=l,o.versions[r]=i)),o.group=l}updateBinding(e){let t=this.backend,r=t.device,i=e.buffer,s=t.get(e).buffer,o=e.updateRanges;if(o.length===0)r.queue.writeBuffer(s,0,i,0);else{let a=ba(i),l=a?1:i.BYTES_PER_ELEMENT,u=o[0].start;for(let c=0,d=o.length;c<d;c++){let h=o[c],p=o[c+1],f=h.start+h.count;if(p!==void 0&&p.start===f)continue;let m=u*l,g=(f-u)*l,x=m*(a?i.BYTES_PER_ELEMENT:1);r.queue.writeBuffer(s,x,i,m,g),p!==void 0&&(u=p.start)}}}createBindGroupIndex(e,t){let i=this.backend.device,s=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,o=e[0];_d.label="bindingCameraIndex_"+o,_d.size=16,_d.usage=s;let a=i.createBuffer(_d);_d.reset(),i.queue.writeBuffer(a,0,e,0),Mi.label="bindGroupCameraIndex_"+o,Mi.layout=t,Mi.entries.push({binding:0,resource:{buffer:a}});let l=i.createBindGroup(Mi);return Mi.reset(),l}createBindGroup(e,t){let r=this.backend,i=r.device,s=0;Mi.label="bindGroup_"+e.name,Mi.layout=t;for(let a of e.bindings){if(a.isUniformBuffer){let l=r.get(a);Mi.entries.push({binding:s,resource:{buffer:l.buffer}})}else if(a.isStorageBuffer){let l=r.get(a.attribute).buffer;Mi.entries.push({binding:s,resource:{buffer:l}})}else if(a.isSampledTexture){let l=r.get(a.texture),u;if(l.externalTexture!==void 0)u=i.importExternalTexture({source:l.externalTexture});else{let c=a.store?1:l.texture.mipLevelCount,d=a.store?a.mipLevel:0,h=`view-${l.texture.width}-${l.texture.height}`;if(l.texture.depthOrArrayLayers>1&&(h+=`-${l.texture.depthOrArrayLayers}`),h+=`-${c}-${d}`,u=l[h],u===void 0){let p=e1.All,f;a.isSampledCubeTexture?f=Gt.Cube:a.texture.isArrayTexture||a.texture.isDataArrayTexture||a.texture.isCompressedArrayTexture?f=Gt.TwoDArray:a.isSampledTexture3D?f=Gt.ThreeD:f=Gt.TwoD,Su.aspect=p,Su.dimension=f,Su.mipLevelCount=c,Su.baseMipLevel=d,u=l[h]=l.texture.createView(Su),Su.reset()}}Mi.entries.push({binding:s,resource:u})}else if(a.isSampler){let l=r.get(a);Mi.entries.push({binding:s,resource:l.sampler})}s++}let o=i.createBindGroup(Mi);return Mi.reset(),o}_createLayoutEntries(e){let t=[],r=0;for(let i of e.bindings){let s=this.backend,o={binding:r,visibility:i.visibility};if(i.isUniformBuffer||i.isStorageBuffer){let a={};i.isStorageBuffer&&(i.visibility&oi.COMPUTE?i.access===mt.READ_WRITE||i.access===mt.WRITE_ONLY?a.type=md.Storage:a.type=md.ReadOnlyStorage:i.nodeUniform&&i.nodeUniform.isAtomic&&i.visibility&oi.FRAGMENT?a.type=md.Storage:a.type=md.ReadOnlyStorage),o.buffer=a}else if(i.isSampledTexture&&i.store){let a={};a.format=this.backend.get(i.texture).texture.format;let l=i.access;l===mt.READ_WRITE?a.access=sg.ReadWrite:l===mt.WRITE_ONLY?a.access=sg.WriteOnly:a.access=sg.ReadOnly,i.texture.isArrayTexture?a.viewDimension=Gt.TwoDArray:i.texture.is3DTexture&&(a.viewDimension=Gt.ThreeD),o.storageTexture=a}else if(i.isSampledTexture){let a={},{primarySamples:l}=s.utils.getTextureSampleData(i.texture);if(l>1&&(a.multisampled=!0,i.texture.isDepthTexture||(a.sampleType=In.UnfilterableFloat)),i.texture.isDepthTexture)s.compatibilityMode&&i.texture.compareFunction===null?a.sampleType=In.UnfilterableFloat:a.sampleType=In.Depth;else{let u=i.texture.type;u===Je?a.sampleType=In.SInt:u===Ce?a.sampleType=In.UInt:i.texture.normalized===!0&&(u===mr||u===er)?a.sampleType=In.UnfilterableFloat:u===ze&&(this.backend.hasFeature("float32-filterable")?a.sampleType=In.Float:a.sampleType=In.UnfilterableFloat)}i.isSampledCubeTexture?a.viewDimension=Gt.Cube:i.texture.isArrayTexture||i.texture.isDataArrayTexture||i.texture.isCompressedArrayTexture?a.viewDimension=Gt.TwoDArray:i.isSampledTexture3D&&(a.viewDimension=Gt.ThreeD),o.texture=a}else if(i.isSampler){let a={};i.texture.isDepthTexture&&(i.texture.compareFunction!==null&&i.textureNode.compareNode!==null&&s.hasCompatibility(xr.TEXTURE_COMPARE)?a.type=VS.Comparison:a.type=VS.NonFiltering),o.sampler=a}else I(`WebGPUBindingUtils: Unsupported binding "${i}".`);t.push(o),r++}return t}deleteBindGroupData(e){let{backend:t}=this,r=t.get(e);r.layout&&(r.layout.usedTimes--,r.layout.usedTimes===0&&this._bindGroupLayoutCache.delete(r.layoutKey),r.layout=void 0,r.layoutKey=void 0)}dispose(){this._bindGroupLayoutCache.clear()}},N1=NN;var wN=class{constructor(e){this.backend=e}getMaxAnisotropy(){return 16}getUniformBufferLimit(){return this.backend.device.limits.maxUniformBufferBindingSize}},w1=wN;var MN=class{constructor(){this.label="",this.layout=null,this.compute=null}reset(){this.label="",this.layout=null,this.compute=null}},M1=MN;var vN=class{constructor(){this.label="",this.bindGroupLayouts=null}reset(){this.label="",this.bindGroupLayouts=null}},v1=vN;var Td=new M1,Nu=new v1,wu=new og,vi=new ag,AN=class{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){let{object:r,material:i,geometry:s,pipeline:o}=e,{vertexProgram:a,fragmentProgram:l}=o,u=this.backend,c=u.device,d=u.utils,h=u.get(o),p=[];for(let H of e.getBindings()){let ae=u.get(H),{layoutGPU:de}=ae.layout;p.push(de)}let f=u.attributeUtils.createShaderVertexBuffers(e),m;i.blending!==Pr&&(i.blending!==Zt||i.transparent!==!1)&&(m=this._getBlending(i));let g={};i.stencilWrite===!0&&(g={compare:this._getStencilCompare(i),failOp:this._getStencilOperation(i.stencilFail),depthFailOp:this._getStencilOperation(i.stencilZFail),passOp:this._getStencilOperation(i.stencilZPass)});let x=this._getColorWriteMask(i),w=[];if(e.context.textures!==null){let H=e.context.textures,ae=e.context.mrt;for(let de=0;de<H.length;de++){let me=H[de],Ae=d.getTextureFormatGPU(me),ge;if(ae!==null)if(this.backend.compatibilityMode!==!0){let Oe=ae.getBlendMode(me.name);Oe.blending===tl?ge=m:Oe.blending!==Pr&&(ge=this._getBlending(Oe))}else he("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets."),ge=m;else ge=m;w.push({format:Ae,blend:ge,writeMask:x})}}else{let H=d.getCurrentColorFormat(e.context);w.push({format:H,blend:m,writeMask:x})}let v=u.get(a).module,E=u.get(l).module,b=this._getPrimitiveState(r,s,i),S=this._getDepthCompare(i),T=d.getCurrentDepthStencilFormat(e.context),M=this._getSampleCount(e.context);Nu.bindGroupLayouts=p;let B=c.createPipelineLayout(Nu);Nu.reset(),vi.label=`renderPipeline_${i.name||i.type}_${i.id}`,vi.vertex=Object.assign({},v,{buffers:f}),vi.fragment=Object.assign({},E,{targets:w}),vi.primitive=b,vi.multisample.count=M,vi.multisample.alphaToCoverageEnabled=i.alphaToCoverage&&M>1,vi.layout=B;let D={},O=e.context.depth,z=e.context.stencil;(O===!0||z===!0)&&(O===!0&&(D.format=T,D.depthWriteEnabled=i.depthWrite,D.depthCompare=S),z===!0&&(D.stencilFront=g,D.stencilBack=g,D.stencilReadMask=i.stencilFuncMask,D.stencilWriteMask=i.stencilWriteMask),i.polygonOffset===!0&&b.topology===Xa.TriangleList&&(D.depthBias=i.polygonOffsetUnits,D.depthBiasSlopeScale=i.polygonOffsetFactor,D.depthBiasClamp=0),vi.depthStencil=D),c.pushErrorScope("validation");let Q=[{program:a,module:v.module},{program:l,module:E.module}],oe=vi.label;if(t===null)h.pipeline=c.createRenderPipeline(vi),vi.reset(),c.popErrorScope().then(H=>{H!==null&&(h.error=!0,I(`WebGPURenderer: Render pipeline creation failed (${oe}): ${H.message}`),this._reportShaderDiagnostics(Q,oe))});else{let H=new Promise(async ae=>{try{let de=null,me=null;try{me=c.createRenderPipelineAsync(vi)}catch(ge){de=ge}if(vi.reset(),me!==null)try{h.pipeline=await me}catch(ge){de=ge}let Ae=await c.popErrorScope();if(Ae!==null||de!==null){h.error=!0;let ge=Ae&&Ae.message||de&&de.message||"unknown";I(`WebGPURenderer: Async render pipeline creation failed (${oe}): ${ge}`),await this._reportShaderDiagnostics(Q,oe)}}finally{ae()}});t.push(H)}}createBundleEncoder(e,t="renderBundleEncoder"){let r=this.backend,{utils:i,device:s}=r,o=i.getCurrentDepthStencilFormat(e),a=i.getCurrentColorFormats(e),l=this._getSampleCount(e);wu.label=t,wu.colorFormats=a,wu.depthStencilFormat=o,wu.sampleCount=l;let u=s.createRenderBundleEncoder(wu);return wu.reset(),u}createComputePipeline(e,t){let r=this.backend,i=r.device,s=r.get(e.computeProgram).module,o=r.get(e),a=[];for(let d of t){let h=r.get(d),{layoutGPU:p}=h.layout;a.push(p)}let l=e.computeProgram,u=`computePipeline_${l.stage}${l.name?`_${l.name}`:""}`;i.pushErrorScope("validation"),Nu.bindGroupLayouts=a;let c=i.createPipelineLayout(Nu);Nu.reset(),Td.label=u,Td.compute=s,Td.layout=c,o.pipeline=i.createComputePipeline(Td),Td.reset(),i.popErrorScope().then(d=>{d!==null&&(o.error=!0,I(`WebGPURenderer: Compute pipeline creation failed (${u}): ${d.message}`),this._reportShaderDiagnostics([{program:l,module:s.module}],u))})}async _reportShaderDiagnostics(e,t){for(let{program:r,module:i}of e){let s=await i.getCompilationInfo();if(s.messages.length===0)continue;let o=r.code.split(` | |
| `);for(let a of s.messages){let l=a.lineNum>0?` at line ${a.lineNum}${a.linePos>0?`:${a.linePos}`:""}`:"",u=`WebGPURenderer [${t} / ${r.stage} ${a.type}]${l}: ${a.message}`,c="";a.lineNum>0&&a.lineNum<=o.length&&(c=` | |
| ${o[a.lineNum-1]}`,a.linePos>0&&(c+=` | |
| ${" ".repeat(a.linePos-1)}^`)),(a.type==="error"?I:U)(u+c)}}}_getBlending(e){let t,r,i=e.blending,s=e.blendSrc,o=e.blendDst,a=e.blendEquation;if(i===rn){let l=e.blendSrcAlpha!==null?e.blendSrcAlpha:s,u=e.blendDstAlpha!==null?e.blendDstAlpha:o,c=e.blendEquationAlpha!==null?e.blendEquationAlpha:a;t={srcFactor:this._getBlendFactor(s),dstFactor:this._getBlendFactor(o),operation:this._getBlendOperation(a)},r={srcFactor:this._getBlendFactor(l),dstFactor:this._getBlendFactor(u),operation:this._getBlendOperation(c)}}else{let l=e.premultipliedAlpha,u=(c,d,h,p)=>{t={srcFactor:c,dstFactor:d,operation:Ro.Add},r={srcFactor:h,dstFactor:p,operation:Ro.Add}};if(l)switch(i){case Zt:u(Be.One,Be.OneMinusSrcAlpha,Be.One,Be.OneMinusSrcAlpha);break;case zn:u(Be.One,Be.One,Be.One,Be.One);break;case $n:u(Be.Zero,Be.OneMinusSrc,Be.Zero,Be.One);break;case Wn:u(Be.Dst,Be.OneMinusSrcAlpha,Be.Zero,Be.One);break}else switch(i){case Zt:u(Be.SrcAlpha,Be.OneMinusSrcAlpha,Be.One,Be.OneMinusSrcAlpha);break;case zn:u(Be.SrcAlpha,Be.One,Be.One,Be.One);break;case $n:I(`WebGPURenderer: "SubtractiveBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`);break;case Wn:I(`WebGPURenderer: "MultiplyBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`);break}}if(t!==void 0&&r!==void 0)return{color:t,alpha:r};I("WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(e){let t;switch(e){case Zi:t=Be.Zero;break;case Pd:t=Be.One;break;case Dd:t=Be.Src;break;case Ud:t=Be.OneMinusSrc;break;case sn:t=Be.SrcAlpha;break;case nn:t=Be.OneMinusSrcAlpha;break;case kd:t=Be.Dst;break;case Vd:t=Be.OneMinusDst;break;case Id:t=Be.DstAlpha;break;case Od:t=Be.OneMinusDstAlpha;break;case Gd:t=Be.SrcAlphaSaturated;break;case lR:t=Be.Constant;break;case uR:t=Be.OneMinusConstant;break;default:I("WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t,r=e.stencilFunc;switch(r){case gw:t=Kt.Never;break;case Iu:t=Kt.Always;break;case xw:t=Kt.Less;break;case bw:t=Kt.LessEqual;break;case yw:t=Kt.Equal;break;case Sw:t=Kt.GreaterEqual;break;case _w:t=Kt.Greater;break;case Tw:t=Kt.NotEqual;break;default:I("WebGPURenderer: Invalid stencil function.",r)}return t}_getStencilOperation(e){let t;switch(e){case un:t=Un.Keep;break;case uw:t=Un.Zero;break;case cw:t=Un.Replace;break;case mw:t=Un.Invert;break;case dw:t=Un.IncrementClamp;break;case hw:t=Un.DecrementClamp;break;case pw:t=Un.IncrementWrap;break;case fw:t=Un.DecrementWrap;break;default:I("WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Jt:t=Ro.Add;break;case Fd:t=Ro.Subtract;break;case Ld:t=Ro.ReverseSubtract;break;case KN:t=Ro.Min;break;case QN:t=Ro.Max;break;default:I("WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,r){let i={},s=this.backend.utils;i.topology=s.getPrimitiveTopology(e,r),t.index!==null&&e.isLine===!0&&e.isLineSegments!==!0&&(i.stripIndexFormat=t.index.array instanceof Uint16Array?gu.Uint16:gu.Uint32);let o=r.side===Ze;return e.isMesh&&e.matrixWorld.determinantAffine()<0&&(o=!o),i.frontFace=o===!0?IS.CW:IS.CCW,i.cullMode=r.side===Kr?OS.None:OS.Back,i}_getColorWriteMask(e){return e.colorWrite===!0?kS.All:kS.None}_getDepthCompare(e){let t;if(e.depthTest===!1)t=Kt.Always;else{let r=this.backend.parameters.reversedDepthBuffer?Qd[e.depthFunc]:e.depthFunc;switch(r){case Uo:t=Kt.Never;break;case Io:t=Kt.Always;break;case Oo:t=Kt.Less;break;case fs:t=Kt.LessEqual;break;case ko:t=Kt.Equal;break;case Vo:t=Kt.GreaterEqual;break;case Go:t=Kt.Greater;break;case zo:t=Kt.NotEqual;break;default:I("WebGPUPipelineUtils: Invalid depth function.",r)}}return t}},A1=AN;var RN=class{constructor(){this.label="",this.type=void 0,this.count=0}reset(){this.label="",this.type=void 0,this.count=0}},gg=RN;var Ys=new Yi,XI=new Xs,Sd=new gg,CN=class extends rg{constructor(e,t,r=2048){super(r),this.device=e,this.type=t,Sd.label=`queryset_global_timestamp_${t}`,Sd.type="timestamp",Sd.count=this.maxQueries,this.querySet=this.device.createQuerySet(Sd),Sd.reset();let i=this.maxQueries*8;Ys.label=`buffer_timestamp_resolve_${t}`,Ys.size=i,Ys.usage=GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC,this.resolveBuffer=this.device.createBuffer(Ys),Ys.reset(),Ys.label=`buffer_timestamp_result_${t}`,Ys.size=i,Ys.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this.resultBuffer=this.device.createBuffer(Ys),Ys.reset()}allocateQueriesForContext(e){if(!this.trackTimestamp||this.isDisposed)return null;if(this.currentQueryIndex+2>this.maxQueries)return he(`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;let t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryOffsets.set(e,t),t}async resolveQueriesAsync(){if(!this.trackTimestamp||this.currentQueryIndex===0||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(this.resultBuffer.mapState!=="unmapped")return this.lastValue;let e=new Map(this.queryOffsets),t=this.currentQueryIndex,r=t*8;this.currentQueryIndex=0,this.queryOffsets.clear();let i=this.device.createCommandEncoder(XI);i.resolveQuerySet(this.querySet,0,t,this.resolveBuffer,0),i.copyBufferToBuffer(this.resolveBuffer,0,this.resultBuffer,0,r);let s=i.finish();if(qr(this.device,s),this.resultBuffer.mapState!=="unmapped")return this.lastValue;if(await this.resultBuffer.mapAsync(GPUMapMode.READ,0,r),this.isDisposed)return this.resultBuffer.mapState==="mapped"&&this.resultBuffer.unmap(),this.lastValue;let o=new BigUint64Array(this.resultBuffer.getMappedRange(0,r)),a={},l=[];for(let[c,d]of e){let h=c.match(/^(.*):f(\d+)$/),p=parseInt(h[2]);l.includes(p)===!1&&l.push(p),a[p]===void 0&&(a[p]=0);let f=o[d],m=o[d+1],g=Number(m-f)/1e6;this.timestamps.set(c,g),a[p]+=g}let u=a[l[l.length-1]];return this.resultBuffer.unmap(),this.lastValue=u,this.frames=l,u}catch(e){return I("Error resolving queries:",e),this.resultBuffer.mapState==="mapped"&&this.resultBuffer.unmap(),this.lastValue}}async dispose(){if(!this.isDisposed){if(this.isDisposed=!0,this.pendingResolve)try{await this.pendingResolve}catch(e){I("Error waiting for pending resolve:",e)}if(this.resultBuffer&&this.resultBuffer.mapState==="mapped")try{this.resultBuffer.unmap()}catch(e){I("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}}},R1=CN;var EN=class{constructor(){this.label="",this.timestampWrites=void 0}reset(){this.label="",this.timestampWrites=void 0}},C1=EN;var BN=class{constructor(){this.view=null,this.depthLoadOp=void 0,this.depthStoreOp=void 0,this.depthClearValue=void 0,this.depthReadOnly=!1,this.stencilLoadOp=void 0,this.stencilStoreOp=void 0,this.stencilClearValue=0,this.stencilReadOnly=!1}reset(){this.view=null,this.depthLoadOp=void 0,this.depthStoreOp=void 0,this.depthClearValue=void 0,this.depthReadOnly=!1,this.stencilLoadOp=void 0,this.stencilStoreOp=void 0,this.stencilClearValue=0,this.stencilReadOnly=!1}},Nd=BN;var FN=class{constructor(){this.querySet=null,this.beginningOfPassWriteIndex=void 0,this.endOfPassWriteIndex=void 0}reset(){this.querySet=null,this.beginningOfPassWriteIndex=void 0,this.endOfPassWriteIndex=void 0}},E1=FN;var hs={r:0,g:0,b:0,a:1},Ai=new Yi,jr=new Xs,xg=new C1,wd=new gg,yg=new lg,bg=new E1,Ki=new Qa,Ks=new Qa,ut=new yu,kn=new dg,LN=class extends Zm{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=e.alpha===void 0?!0:e.alpha,this.parameters.requiredLimits=e.requiredLimits===void 0?{}:e.requiredLimits,this.compatibilityMode=null,this.device=null,this.defaultRenderPassdescriptor=null,this.utils=new s1(this),this.attributeUtils=new S1(this),this.bindingUtils=new N1(this),this.capabilities=new w1(this),this.pipelineUtils=new A1(this),this.textureUtils=new h1(this),this.occludedResolveCache=new Map;let t=typeof navigator>"u"?!0:/Android/.test(navigator.userAgent)===!1;this._compatibility={[xr.TEXTURE_COMPARE]:t}}async init(e){await super.init(e);let t=this.parameters,r;if(t.device===void 0){let i={powerPreference:t.powerPreference,featureLevel:"compatibility",xrCompatible:e.xr.enabled},s=typeof navigator<"u"?await navigator.gpu.requestAdapter(i):null;if(s===null)throw new Error("THREE.WebGPUBackend: Unable to create WebGPU adapter.");let o=Object.values(xu),a=[];for(let u of o)s.features.has(u)&&a.push(u);let l={requiredFeatures:a,requiredLimits:t.requiredLimits};r=await s.requestDevice(l)}else r=t.device;this.compatibilityMode=!r.features.has("core-features-and-limits"),this.compatibilityMode&&(e._samples=0),r.lost.then(i=>{if(i.reason==="destroyed")return;let s={api:"WebGPU",message:i.message||"Unknown reason",reason:i.reason||null,originalEvent:i};e.onDeviceLost(s)}),r.onuncapturederror=i=>{let s=i.error,o=s&&s.constructor?s.constructor.name:"GPUError",a=s&&s.message||"Unknown uncaptured GPU error";e.onError({api:"WebGPU",type:o,message:a,originalEvent:i})},this.device=r,this.trackTimestamp=this.trackTimestamp&&this.hasFeature(xu.TimestampQuery),this.updateSize()}setXRRenderTargetTextures(e,t,r=null){this.set(e.texture,{texture:t,format:t.format,externalTexture:!0,xrViewDescriptors:r,initialized:!0})}get context(){let e=this.renderer.getCanvasTarget(),t=this.get(e),r=t.context;if(r===void 0){let i=this.parameters;e.isDefaultCanvasTarget===!0&&i.context!==void 0?r=i.context:r=e.domElement.getContext("webgpu"),"setAttribute"in e.domElement&&e.domElement.setAttribute("data-engine",`three.js r${tn} webgpu`);let s=i.alpha?"premultiplied":"opaque",o=i.outputType===qe?"extended":"standard";r.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:s,toneMapping:{mode:o}}),t.context=r}return r}get coordinateSystem(){return yt}get hasTimestamp(){return!0}async getArrayBufferAsync(e,t=null,r=0,i=-1){return await this.attributeUtils.getArrayBufferAsync(e,t,r,i)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.renderer,t=e.getCanvasTarget(),r=this.get(t),i=e.currentSamples,s=r.descriptor;if(s===void 0||r.samples!==i){if(s=new Ka,s.colorAttachments.push(new Ya),e.depth===!0||e.stencil===!0){let l=new Nd;l.view=this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView(),s.depthStencilAttachment=l}let a=s.colorAttachments[0];i>0?a.view=this.textureUtils.getColorBuffer().createView():a.resolveTarget=void 0,r.descriptor=s,r.samples=i}let o=s.colorAttachments[0];return i>0?o.resolveTarget=this.context.getCurrentTexture().createView():o.view=this.context.getCurrentTexture().createView(),s}_isRenderCameraDepthArray(e){let t=e.camera;return e.depthTexture&&e.depthTexture.isArrayTexture===!0&&t!==null&&t.isArrayCamera===!0}_hasExternalTexture(e){let t=e.textures;if(t===null)return!1;for(let r=0;r<t.length;r++)if(this.get(t[r]).externalTexture===!0)return!0;return!1}_createExternalTextureViews(e,t){let r=[],i=e.camera;if(t.xrViewDescriptors&&i!==null&&i.isArrayCamera===!0)for(let s=0;s<t.xrViewDescriptors.length;s++)r.push({view:t.texture.createView(t.xrViewDescriptors[s]),resolveTarget:void 0,depthSlice:void 0});else r.push({view:t.texture.createView({dimension:Gt.TwoD,baseArrayLayer:e.activeCubeFace,arrayLayerCount:1}),resolveTarget:void 0,depthSlice:void 0});return r}_getRenderPassDescriptor(e,t={}){let r=e.renderTarget,i=this.get(r),s=this._hasExternalTexture(e),o=i.descriptors;(o===void 0||i.width!==r.width||i.height!==r.height||i.samples!==r.samples||s)&&(o={},i.descriptors=o);let a=e.getCacheKey(),l=o[a];if(l===void 0||s){let c=e.textures,d=[],h,p=this._isRenderCameraDepthArray(e);for(let m=0;m<c.length;m++){let g=this.get(c[m]);if(g.externalTexture===!0){d.push(...this._createExternalTextureViews(e,g));continue}if(ut.label=`colorAttachment_${m}`,ut.baseMipLevel=e.activeMipmapLevel,ut.mipLevelCount=1,ut.baseArrayLayer=e.activeCubeFace,ut.arrayLayerCount=1,ut.dimension=Gt.TwoD,r.isRenderTarget3D)h=e.activeCubeFace,ut.baseArrayLayer=0,ut.dimension=Gt.ThreeD;else if(r.isRenderTarget&&c[m].image.depth>1)if(p===!0){let x=e.camera.cameras;for(let w=0;w<x.length;w++){ut.baseArrayLayer=w,ut.arrayLayerCount=1,ut.dimension=Gt.TwoD;let v=g.texture.createView(ut);d.push({view:v,resolveTarget:void 0,depthSlice:void 0})}}else ut.dimension=Gt.TwoDArray;if(p!==!0){let x=g.texture.createView(ut),w,v;g.msaaTexture!==void 0?(w=g.msaaTexture.createView(),v=r.resolveColorBuffer===!0?x:void 0):(w=x,v=void 0),d.push({view:w,resolveTarget:v,depthSlice:h})}ut.reset()}let f=[];for(let m=0;m<d.length;m++){let g=d[m],x=new Ya;x.view=g.view,x.depthSlice=g.depthSlice,x.resolveTarget=g.resolveTarget,f.push(x)}if(l={textureViews:d,colorAttachments:f,descriptor:new Ka},e.depth){let m=this.get(e.depthTexture);(e.depthTexture.isArrayTexture||e.depthTexture.isCubeTexture)&&(ut.dimension=Gt.TwoD,ut.arrayLayerCount=1,ut.baseArrayLayer=e.activeCubeFace);let g=new Nd;g.view=m.texture.createView(ut),l.depthStencilAttachment=g,ut.reset()}o[a]=l,i.width=r.width,i.height=r.height,i.samples=r.samples,i.activeMipmapLevel=e.activeMipmapLevel,i.activeCubeFace=e.activeCubeFace}let u=l.descriptor;u.reset();for(let c=0;c<l.colorAttachments.length;c++){let d=l.colorAttachments[c],h={r:0,g:0,b:0,a:1};c===0&&t.clearValue&&(h=t.clearValue),d.loadOp=t.loadOp||Ve.Load,d.storeOp=t.storeOp||Vt.Store,d.clearValue=h,u.colorAttachments.push(d)}return l.depthStencilAttachment&&(u.depthStencilAttachment=l.depthStencilAttachment),u}beginRender(e){let t=this.get(e),r=this.device,i=e.occlusionQueryCount,s;i>0?(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,wd.label=`occlusionQuerySet_${e.id}`,wd.type="occlusion",wd.count=i,s=r.createQuerySet(wd),wd.reset(),t.occlusionQuerySet=s,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(i),t.lastOcclusionObject=null):t.lastOcclusionObject!==void 0&&(t.lastOcclusionObject=void 0,t.occlusionQuerySet.destroy(),t.occlusionQuerySet=void 0);let o;e.textures===null?o=this._getDefaultRenderPassDescriptor():o=this._getRenderPassDescriptor(e,{loadOp:Ve.Load}),this.initTimestampQuery(ci.RENDER,this.getTimestampUID(e),o),o.occlusionQuerySet=s;let a=o.depthStencilAttachment,l=e.renderTarget;if(e.textures!==null){let c=o.colorAttachments;for(let d=0;d<c.length;d++){let h=c[d];e.clearColor?(d===0?h.clearValue=e.clearColorValue:(hs.r=0,hs.g=0,hs.b=0,hs.a=1,h.clearValue=hs),h.loadOp=Ve.Clear):h.loadOp=Ve.Load,e.sampleCount>1&&l?.storeMultisampledColorBuffer===!1?h.storeOp=Vt.Discard:h.storeOp=Vt.Store}}else{let c=o.colorAttachments[0];e.clearColor?(c.clearValue=e.clearColorValue,c.loadOp=Ve.Clear):c.loadOp=Ve.Load,c.storeOp=Vt.Store}e.depth&&(e.clearDepth?(a.depthClearValue=e.clearDepthValue,a.depthLoadOp=Ve.Clear):a.depthLoadOp=Ve.Load,e.sampleCount>1&&l?.storeMultisampledDepthBuffer===!1?a.depthStoreOp=Vt.Discard:a.depthStoreOp=Vt.Store),e.stencil&&(e.clearStencil?(a.stencilClearValue=e.clearStencilValue,a.stencilLoadOp=Ve.Clear):a.stencilLoadOp=Ve.Load,e.sampleCount>1&&l?.storeMultisampledStencilBuffer===!1?a.stencilStoreOp=Vt.Discard:a.stencilStoreOp=Vt.Store),jr.label="renderContext_"+e.id;let u=r.createCommandEncoder(jr);if(jr.reset(),this._isRenderCameraDepthArray(e)===!0){let c=e.camera.cameras;!t.layerDescriptors||t.layerDescriptors.length!==c.length?this._createArrayCameraLayerDescriptors(e,t,o,c):this._updateArrayCameraLayerDescriptors(e,t,c),t.bundleEncoders=[],t.bundleSets=[];for(let d=0;d<c.length;d++){let h=this.pipelineUtils.createBundleEncoder(e,"renderBundleArrayCamera_"+d),p={attributes:{},bindingGroups:[],pipeline:null,index:null};t.bundleEncoders.push(h),t.bundleSets.push(p)}t.currentPass=null}else{let c=u.beginRenderPass(o);t.currentPass=c,e.viewport&&this.updateViewport(e),e.scissor&&this.updateScissor(e)}t.descriptor=o,t.encoder=u,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.renderBundles=[]}_createArrayCameraLayerDescriptors(e,t,r,i){let s=r.depthStencilAttachment;t.layerDescriptors=[];let o=this.get(e.depthTexture);o.viewCache||(o.viewCache=[]);for(let a=0;a<i.length;a++){let l=r.colorAttachments[0],u=new Ya;u.view=r.colorAttachments[a].view,u.depthSlice=l.depthSlice,u.resolveTarget=l.resolveTarget,u.loadOp=l.loadOp,u.storeOp=l.storeOp,u.clearValue=l.clearValue;let c=new Ka;if(c.label=r.label,c.occlusionQuerySet=r.occlusionQuerySet,c.timestampWrites=r.timestampWrites,c.colorAttachments.push(u),r.depthStencilAttachment){let d=a;o.viewCache[d]||(ut.dimension=Gt.TwoD,ut.baseArrayLayer=a,ut.arrayLayerCount=1,o.viewCache[d]=o.texture.createView(ut),ut.reset());let h=new Nd;h.view=o.viewCache[d],h.depthLoadOp=s.depthLoadOp||Ve.Clear,h.depthStoreOp=s.depthStoreOp||Vt.Store,h.depthClearValue=s.depthClearValue||1,e.stencil&&(h.stencilLoadOp=s.stencilLoadOp,h.stencilStoreOp=s.stencilStoreOp,h.stencilClearValue=s.stencilClearValue),c.depthStencilAttachment=h}else{let d=new Nd;d.view=s.view,d.depthLoadOp=s.depthLoadOp,d.depthStoreOp=s.depthStoreOp,d.depthClearValue=s.depthClearValue,d.depthReadOnly=s.depthReadOnly,d.stencilLoadOp=s.stencilLoadOp,d.stencilStoreOp=s.stencilStoreOp,d.stencilClearValue=s.stencilClearValue,d.stencilReadOnly=s.stencilReadOnly,c.depthStencilAttachment=d}t.layerDescriptors.push(c)}}_updateArrayCameraLayerDescriptors(e,t,r){for(let i=0;i<r.length;i++){let s=t.layerDescriptors[i];if(s.depthStencilAttachment){let o=s.depthStencilAttachment;e.depth&&(e.clearDepth?(o.depthClearValue=e.clearDepthValue,o.depthLoadOp=Ve.Clear):o.depthLoadOp=Ve.Load),e.stencil&&(e.clearStencil?(o.stencilClearValue=e.clearStencilValue,o.stencilLoadOp=Ve.Clear):o.stencilLoadOp=Ve.Load)}}}finishRender(e){let t=this.get(e),r=e.occlusionQueryCount;t.renderBundles.length>0&&t.currentPass.executeBundles(t.renderBundles);let i=t.lastOcclusionObject;i&&i.occlusionTest===!0&&t.currentPass.endOcclusionQuery();let s=t.encoder;if(this._isRenderCameraDepthArray(e)===!0){let o=[];for(let a=0;a<t.bundleEncoders.length;a++){let l=t.bundleEncoders[a];o.push(l.finish())}for(let a=0;a<t.layerDescriptors.length;a++)if(a<o.length){let l=t.layerDescriptors[a],u=s.beginRenderPass(l);if(e.viewport){let{x:c,y:d,width:h,height:p,minDepth:f,maxDepth:m}=e.viewportValue;u.setViewport(c,d,h,p,f,m)}if(e.scissor){let{x:c,y:d,width:h,height:p}=e.scissorValue;u.setScissorRect(c,d,h,p)}u.executeBundles([o[a]]),u.end()}}else t.currentPass&&t.currentPass.end();if(r>0){let o=r*8,a=this.occludedResolveCache.get(o);a===void 0&&(Ai.size=o,Ai.usage=GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC,a=this.device.createBuffer(Ai),Ai.reset(),this.occludedResolveCache.set(o,a)),Ai.size=o,Ai.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ;let l=this.device.createBuffer(Ai);Ai.reset(),t.encoder.resolveQuerySet(t.occlusionQuerySet,0,r,a,0),t.encoder.copyBufferToBuffer(a,0,l,0,o),t.occlusionQueryBuffer=l,this.resolveOccludedAsync(e)}if(qr(this.device,t.encoder.finish()),e.textures!==null){let o=e.textures;for(let a=0;a<o.length;a++){let l=o[a];l.generateMipmaps===!0&&this.textureUtils.generateMipmaps(l)}}}isOccluded(e,t){let r=this.get(e);return r.occluded&&r.occluded.has(t)}async resolveOccludedAsync(e){let t=this.get(e),{currentOcclusionQueryBuffer:r,currentOcclusionQueryObjects:i}=t;if(r&&i){let s=new WeakSet;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueryBuffer=null,await r.mapAsync(GPUMapMode.READ);let o=r.getMappedRange(),a=new BigUint64Array(o);for(let l=0;l<i.length;l++){let u=i[l];u!==void 0&&a[l]===BigInt(0)&&s.add(u)}r.destroy(),t.occluded=s}}updateViewport(e){let{currentPass:t}=this.get(e),{x:r,y:i,width:s,height:o,minDepth:a,maxDepth:l}=e.viewportValue;t.setViewport(r,i,s,o,a,l)}updateScissor(e){let{currentPass:t}=this.get(e),{x:r,y:i,width:s,height:o}=e.scissorValue;t.setScissorRect(r,i,s,o)}getClearColor(){let e=super.getClearColor();return this.renderer.alpha===!0&&(e.r*=e.a,e.g*=e.a,e.b*=e.a),e}clear(e,t,r,i=null){let s=this.device,o=this.renderer,a=[],l,u,c;if(e){let p=this.getClearColor();hs.r=p.r,hs.g=p.g,hs.b=p.b,hs.a=p.a}if(i===null){u=o.depth,c=o.stencil;let p=this._getDefaultRenderPassDescriptor();if(e){a=p.colorAttachments;let f=a[0];f.clearValue=hs,f.loadOp=Ve.Clear,f.storeOp=Vt.Store}(u||c)&&(l=p.depthStencilAttachment)}else{u=i.depth,c=i.stencil;let p={loadOp:e?Ve.Clear:Ve.Load,clearValue:e?hs:void 0};u&&(p.depthLoadOp=t?Ve.Clear:Ve.Load,p.depthClearValue=t?o.getClearDepth():void 0,p.depthStoreOp=Vt.Store),c&&(p.stencilLoadOp=r?Ve.Clear:Ve.Load,p.stencilClearValue=r?o.getClearStencil():void 0,p.stencilStoreOp=Vt.Store);let f=this._getRenderPassDescriptor(i,p);a=f.colorAttachments,l=f.depthStencilAttachment}u&&l&&(t?(l.depthLoadOp=Ve.Clear,l.depthClearValue=o.getClearDepth(),l.depthStoreOp=Vt.Store):(l.depthLoadOp=Ve.Load,l.depthStoreOp=Vt.Store)),c&&l&&(r?(l.stencilLoadOp=Ve.Clear,l.stencilClearValue=o.getClearStencil(),l.stencilStoreOp=Vt.Store):(l.stencilLoadOp=Ve.Load,l.stencilStoreOp=Vt.Store)),jr.label="clear";let d=s.createCommandEncoder(jr);jr.reset(),d.beginRenderPass({colorAttachments:a,depthStencilAttachment:l}).end(),qr(s,d.finish())}beginCompute(e){let t=this.get(e),r="computeGroup_"+e.id;xg.label=r,jr.label=r,this.initTimestampQuery(ci.COMPUTE,this.getTimestampUID(e),xg),t.cmdEncoderGPU=this.device.createCommandEncoder(jr),t.passEncoderGPU=t.cmdEncoderGPU.beginComputePass(xg),t.currentPipeline=null,jr.reset(),xg.reset()}compute(e,t,r,i,s=null){let o=this.get(t),a=this.get(e),{passEncoderGPU:l}=a,u=this.get(i).pipeline;a.currentPipeline!==u&&(l.setPipeline(u),a.currentPipeline=u);for(let c=0,d=r.length;c<d;c++){let h=r[c],p=this.get(h);l.setBindGroup(c,p.group)}if(s===null&&(s=t.dispatchSize||t.count),s&&s.isIndirectStorageBufferAttribute){let c=this.get(s).buffer;l.dispatchWorkgroupsIndirect(c,0);return}if(typeof s=="number"){let c=s;if(o.dispatchSize===void 0||o.count!==c){o.dispatchSize=[0,1,1],o.count=c;let d=t.workgroupSize,h=d[0];for(let m=1;m<d.length;m++)h*=d[m];let p=Math.ceil(c/h),f=this.device.limits.maxComputeWorkgroupsPerDimension;s=[p,1,1],p>f&&(s[0]=Math.min(p,f),s[1]=Math.ceil(p/f)),o.dispatchSize=s}s=o.dispatchSize}l.dispatchWorkgroups(s[0],s[1]||1,s[2]||1)}finishCompute(e){let t=this.get(e);t.passEncoderGPU.end(),qr(this.device,t.cmdEncoderGPU.finish())}_draw(e,t,r,i,s,o,a,l,u){let{object:c,material:d,context:h}=e,p=e.getIndex(),f=p!==null;u.pipeline!==i&&(l.setPipeline(i),u.pipeline=i);let m=u.bindingGroups;for(let g=0,x=s.length;g<x;g++){let w=s[g];if(m[g]!==w.id){let v=this.get(w);l.setBindGroup(g,v.group),m[g]=w.id}}if(f===!0&&u.index!==p){let g=this.get(p).buffer,x=p.array instanceof Uint16Array?gu.Uint16:gu.Uint32;l.setIndexBuffer(g,x),u.index=p}for(let g=0,x=o.length;g<x;g++){let w=o[g];if(u.attributes[g]!==w){let v=this.get(w).buffer;l.setVertexBuffer(g,v),u.attributes[g]=w}}if(h.stencil===!0&&d.stencilWrite===!0&&r.currentStencilRef!==d.stencilRef&&(l.setStencilReference(d.stencilRef),r.currentStencilRef=d.stencilRef),c.isBatchedMesh===!0){let g=c._multiDrawStarts,x=c._multiDrawCounts,w=c._multiDrawCount,v=f===!0?p.array.BYTES_PER_ELEMENT:1;d.wireframe&&(v=c.geometry.attributes.position.count>65535?4:2);for(let E=0;E<w;E++)f===!0?l.drawIndexed(x[E],1,g[E]/v,0,E):l.draw(x[E],1,g[E],E),t.update(c,x[E],1)}else if(f===!0){let{vertexCount:g,instanceCount:x,firstVertex:w}=a,v=e.getIndirect();if(v!==null){let E=this.get(v).buffer,b=e.getIndirectOffset(),S=Array.isArray(b)?b:[b];for(let T=0;T<S.length;T++)l.drawIndexedIndirect(E,S[T])}else l.drawIndexed(g,x,w,0,0);t.update(c,g,x)}else{let{vertexCount:g,instanceCount:x,firstVertex:w}=a,v=e.getIndirect();if(v!==null){let E=this.get(v).buffer,b=e.getIndirectOffset(),S=Array.isArray(b)?b:[b];for(let T=0;T<S.length;T++)l.drawIndirect(E,S[T])}else l.draw(g,x,w,0);t.update(c,g,x)}}draw(e,t){let{object:r,context:i,pipeline:s}=e,o=this.get(i),a=this.get(s),l=a.pipeline;if(a.error===!0)return;let u=e.getDrawParameters();if(u===null)return;let c=e.getBindings(),d=e.getVertexBuffers();if(e.camera.isArrayCamera&&e.camera.cameras.length>0){let h=this.get(e.camera),p=e.camera.cameras,f=e.getBindingGroup("cameraIndex");if(h.indexesGPU===void 0||h.indexesGPU.length!==p.length){let g=this.get(f),x=[],w=new Uint32Array([0,0,0,0]);for(let v=0,E=p.length;v<E;v++){w[0]=v;let{layoutGPU:b}=g.layout,S=this.bindingUtils.createBindGroupIndex(w,b);x.push(S)}h.indexesGPU=x}let m=this.renderer.getPixelRatio();for(let g=0,x=p.length;g<x;g++){let w=p[g];if(r.layers.test(w.layers)){let v=w.viewport,E=o.currentPass,b=o.currentSets,S=o.bundleEncoders!==void 0;if(S){let T=o.bundleEncoders[g],M=o.bundleSets[g];E=T,b=M}if(v&&!S&&E.setViewport(Math.floor(v.x*m),Math.floor(v.y*m),Math.floor(v.width*m),Math.floor(v.height*m),i.viewportValue.minDepth,i.viewportValue.maxDepth),f&&h.indexesGPU){let T=c.indexOf(f);E.setBindGroup(T,h.indexesGPU[g]),b.bindingGroups[T]=f.id}this._draw(e,t,o,l,c,d,u,E,b)}}}else if(o.currentPass){if(o.occlusionQuerySet!==void 0){let h=o.lastOcclusionObject;h!==r&&(h!==null&&h.occlusionTest===!0&&(o.currentPass.endOcclusionQuery(),o.occlusionQueryIndex++),r.occlusionTest===!0&&(o.currentPass.beginOcclusionQuery(o.occlusionQueryIndex),o.occlusionQueryObjects[o.occlusionQueryIndex]=r),o.lastOcclusionObject=r)}this._draw(e,t,o,l,c,d,u,o.currentPass,o.currentSets)}}needsRenderUpdate(e){let t=this.get(e),{object:r,material:i}=e,s=this.utils,o=s.getSampleCountRenderContext(e.context),a=s.getCurrentColorSpace(e.context),l=s.getCurrentColorFormat(e.context),u=s.getCurrentDepthStencilFormat(e.context),c=s.getPrimitiveTopology(r,i),d=r.isMesh&&r.matrixWorld.determinantAffine()<0,h=!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!==o||t.colorSpace!==a||t.colorFormat!==l||t.depthStencilFormat!==u||t.primitiveTopology!==c||t.frontFaceCW!==d||t.clippingContextCacheKey!==e.clippingContextCacheKey)&&(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=o,t.colorSpace=a,t.colorFormat=l,t.depthStencilFormat=u,t.primitiveTopology=c,t.frontFaceCW=d,t.clippingContextCacheKey=e.clippingContextCacheKey,h=!0),h}getRenderCacheKey(e){let{object:t,material:r}=e,i=this.utils,s=e.context,o=t.isMesh&&t.matrixWorld.determinantAffine()<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,o,i.getSampleCountRenderContext(s),i.getCurrentColorSpace(s),i.getCurrentColorFormat(s),i.getCurrentDepthStencilFormat(s),i.getPrimitiveTopology(t,r),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}updateSampler(e){return this.textureUtils.updateSampler(e)}destroySampler(e){this.textureUtils.destroySampler(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,i,s,o){return this.textureUtils.copyTextureToBuffer(e,t,r,i,s,o)}initTimestampQuery(e,t,r){if(!this.trackTimestamp)return;this.timestampQueryPool[e]||(this.timestampQueryPool[e]=new R1(this.device,e,2048));let i=this.timestampQueryPool[e],s=i.allocateQueriesForContext(t);bg.querySet=i.querySet,bg.beginningOfPassWriteIndex=s,bg.endOfPassWriteIndex=s+1,r.timestampWrites=bg}createNodeBuilder(e,t){return new _1(e,t)}createProgram(e){let t=this.get(e);yg.label=e.stage+(e.name!==""?`_${e.name}`:""),yg.code=e.code,t.module={module:this.device.createShaderModule(yg),entryPoint:"main"},yg.reset()}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){let 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){let r=this.get(e),s=r.currentPass.finish();this.get(t).bundleGPU=s,r.currentSets=r._currentSets,r.currentPass=r._currentPass,r._currentPass=null,r._currentSets=null}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createUniformBuffer(e){let t=this.get(e);if(t.buffer===void 0){let r=e.byteLength,i=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,s=[];e.visibility&oi.VERTEX&&s.push("vertex"),e.visibility&oi.FRAGMENT&&s.push("fragment"),e.visibility&oi.COMPUTE&&s.push("compute");let o=`(${s.join(",")})`;Ai.label=`bindingBuffer${e.id}_${e.name}_${o}`,Ai.size=r,Ai.usage=i;let a=this.device.createBuffer(Ai);Ai.reset(),t.buffer=a}}destroyUniformBuffer(e){this.get(e).buffer.destroy(),this.delete(e)}createBindings(e,t,r,i){this.bindingUtils.createBindings(e,t,r,i)}updateBindings(e,t,r,i){this.bindingUtils.createBindings(e,t,r,i)}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())}hasFeature(e){return zS[e]!==void 0&&(e=zS[e]),this.device.features.has(e)}copyTextureToTexture(e,t,r=null,i=null,s=0,o=0){let a=0,l=0,u=0,c=0,d=0,h=0,p=e.image.width,f=e.image.height,m=1;r!==null&&(r.isBox3===!0?(c=r.min.x,d=r.min.y,h=r.min.z,p=r.max.x-r.min.x,f=r.max.y-r.min.y,m=r.max.z-r.min.z):(c=r.min.x,d=r.min.y,p=r.max.x-r.min.x,f=r.max.y-r.min.y,m=1)),i!==null&&(a=i.x,l=i.y,u=i.z||0),jr.label="copyTextureToTexture_"+e.id+"_"+t.id;let g=this.device.createCommandEncoder(jr);jr.reset();let x=this.get(e).texture,w=this.get(t).texture;Ki.texture=x,Ki.mipLevel=s,Ki.origin.x=c,Ki.origin.y=d,Ki.origin.z=h,Ks.texture=w,Ks.mipLevel=o,Ks.origin.x=a,Ks.origin.y=l,Ks.origin.z=u,kn.width=p,kn.height=f,kn.depthOrArrayLayers=m,g.copyTextureToTexture(Ki,Ks,kn),Ki.reset(),Ks.reset(),kn.reset(),qr(this.device,g.finish()),o===0&&t.generateMipmaps&&this.textureUtils.generateMipmaps(t)}copyFramebufferToTexture(e,t,r){let i=this.get(t),s=null;t.renderTarget?e.isDepthTexture?s=this.get(t.depthTexture).texture:s=this.get(t.textures[0]).texture:e.isDepthTexture?s=this.textureUtils.getDepthBuffer(t.depth,t.stencil):s=this.context.getCurrentTexture();let o=this.get(e).texture;if(s.format!==o.format){I("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",s.format,o.format);return}let a;if(i.currentPass?(i.currentPass.end(),a=i.encoder):(jr.label="copyFramebufferToTexture_"+e.id,a=this.device.createCommandEncoder(jr),jr.reset()),Ki.texture=s,Ki.origin.x=r.x,Ki.origin.y=r.y,Ks.texture=o,kn.width=r.z,kn.height=r.w,a.copyTextureToTexture(Ki,Ks,kn),Ki.reset(),Ks.reset(),kn.reset(),e.generateMipmaps&&this.textureUtils.generateMipmaps(e,a),i.currentPass){let{descriptor:l}=i;for(let u=0;u<l.colorAttachments.length;u++)l.colorAttachments[u].loadOp=Ve.Load;t.depth&&(l.depthStencilAttachment.depthLoadOp=Ve.Load),t.stencil&&(l.depthStencilAttachment.stencilLoadOp=Ve.Load),i.currentPass=a.beginRenderPass(l),i.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.viewport&&this.updateViewport(t),t.scissor&&this.updateScissor(t)}else qr(this.device,a.finish())}hasCompatibility(e){return this._compatibility[e]!==void 0?this._compatibility[e]:super.hasCompatibility(e)}dispose(){if(this.bindingUtils.dispose(),this.textureUtils.dispose(),this.occludedResolveCache){for(let e of this.occludedResolveCache.values())e.destroy();this.occludedResolveCache.clear()}if(this.timestampQueryPool)for(let e of Object.values(this.timestampQueryPool))e!==null&&e.dispose();this.parameters.device===void 0&&this.device!==null&&this.device.destroy()}},B1=LN;var PN=class extends ho{constructor(e,t,r,i,s,o){super(e,t,r,i,s,o),this.iesMap=null}copy(e,t){return super.copy(e,t),this.iesMap=e.iesMap,this}},F1=PN;var DN=class extends ho{constructor(e,t,r,i,s,o){super(e,t,r,i,s,o),this.aspect=null}copy(e,t){return super.copy(e,t),this.aspect=e.aspect,this}},L1=DN;var UN=class extends Gm{constructor(){super(),this.addMaterial(SA,"MeshPhongMaterial"),this.addMaterial(Bf,"MeshStandardMaterial"),this.addMaterial(QA,"MeshPhysicalMaterial"),this.addMaterial(JA,"MeshToonMaterial"),this.addMaterial(gf,"MeshBasicMaterial"),this.addMaterial(TA,"MeshLambertMaterial"),this.addMaterial(yA,"MeshNormalMaterial"),this.addMaterial(eR,"MeshMatcapMaterial"),this.addMaterial(gA,"LineBasicMaterial"),this.addMaterial(xA,"LineDashedMaterial"),this.addMaterial(tR,"PointsMaterial"),this.addMaterial(Ff,"SpriteMaterial"),this.addMaterial(iR,"ShadowMaterial"),this.addLight(_T,Gh),this.addLight(kT,$h),this.addLight(QT,Hh),this.addLight(qa,ho),this.addLight(IT,Wh),this.addLight(GT,Uh),this.addLight(qT,jh),this.addLight(WT,F1),this.addLight(XT,L1),this.addToneMapping(G_,ew),this.addToneMapping(z_,tw),this.addToneMapping($_,rw),this.addToneMapping(W_,iw),this.addToneMapping(H_,sw),this.addToneMapping(q_,nw)}},P1=UN;var IN=class extends UC{constructor(e={}){let t;e.forceWebGL?t=US:(t=B1,e.getFallback=()=>(U("WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new US(e)));let r=new t(e);super(r,e),this.library=new P1,this.isWebGPURenderer=!0,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}},D1=IN;var YI=new Set(["__proto__","prototype","constructor"]),Qs=class extends Error{key;address;constructor(e,t,r){super(`Shader key "${e}" could not resolve ${JSON.stringify(t)}: ${r}`),this.name="ShaderAddressError",this.key=e,this.address=t}};function Tg(n){return n!==null&&typeof n=="object"&&Reflect.get(n,"isNode")===!0}function U1(n){if(typeof n.getSerializeChildren!="function")return[];let e=[];for(let t of n.getSerializeChildren()){if(e.length>=4096)throw new RangeError("A shader node exposes more than 4096 serializable children.");Tg(t.childNode)&&e.push(t.childNode)}return e}function KI(n,e){let t=n;for(let r of e){if(t===void 0)return;t=U1(t)[r]}return t}function ON(n,e){if(!(typeof e=="string"&&YI.has(e))){if(typeof e=="string"&&e.startsWith("map:")&&n instanceof Map){let t=e.slice(4);return n.has(t)?n.get(t):n.get(Number(t))}return Reflect.get(n,e)}}function Sg(n,e){let t=n;for(let r of e){if(t===null||typeof t!="object")return;t=ON(t,r)}return t}function QI(n){if(n===null)return[];let e=[],t=Reflect.get(n,"traverse");return typeof t=="function"&&Reflect.apply(t,n,[r=>{r!==null&&typeof r=="object"&&e.push(r)}]),e}function Ng(n,e){switch(n){case"@material":return e.material??void 0;case"@renderObject":return e.renderObject;case"@object":return e.object;case"@scene":return e.scene??void 0;case"@renderer":return e.renderer;default:{let t=/^@sceneObject:(\d+)$/u.exec(n);return t?QI(e.scene)[Number(t[1])]:e.container(n)}}}function _g(n,e,t){if(!Tg(n))throw new Qs(e.key,t,"the resolved value is not a live Three.js node");return n}function ZI(n,e,t,r){if(r>=16)throw new Qs(e.key,n,"owned-node nesting is too deep");let s=I1(n.owner,e,t,r+1);for(let o of n.path){if(!Tg(s))throw new Qs(e.key,n,"an intermediate owned value is not a node");t.primeOwnedAddress?.(s,e),s=typeof o=="number"?U1(s)[o]:ON(s,o)}return _g(s,e,n)}function I1(n,e,t,r){switch(n.k){case"anchor":{if(n.key!==void 0&&n.key!==e.key)throw new Qs(e.key,n,`address belongs to key "${n.key}"`);let i=e.anchors.find(s=>s.slot===n.slot)?.node;if(i===void 0)throw new Qs(e.key,n,`anchor slot "${n.slot}" is absent`);return _g(KI(i,n.path),e,n)}case"container":{let i=Ng(n.key,e);if(i===void 0)throw new Qs(e.key,n,`container "${n.key}" is absent`);let s=i;for(let o of n.path){if(s===null||typeof s!="object"){s=void 0;break}Tg(s)&&t.primeOwnedAddress?.(s,e),s=ON(s,o)}return _g(s,e,n)}case"owned":return ZI(n,e,t,r);default:return _g(t.resolveRecipeAddress(n,e),e,n)}}function Fo(n,e,t){try{return I1(n,e,t,0)}catch(r){throw r instanceof Qs?r:new Qs(e.key,n,r instanceof Error?r.message:String(r))}}var JI=/[\u0000-\u001f\u007f]/u,O1=Symbol.for("three-blocks.shader-automatic-render-hint.v1"),e3=Symbol.for("three-blocks.shader-automatic-render-variant.v1"),G1=Symbol.for("three-blocks.shader-capture.cache.v1"),z1=Symbol.for("three-blocks.shader-capture.cache-value.v1");function Zs(n,e){return Reflect.get(n,e)}function Lo(n){Reflect.set(globalThis,z1,n);let e=Zs(globalThis,G1);typeof e=="function"&&e(n)}function t3(n,e){let t=Zs(n,e3);return`side=${String(e)}|variant=${typeof t=="string"?t.slice(0,4096):"default"}`}function r3(n,e,t){let r=Zs(e,"object"),i=r!==null&&typeof r=="object"?Zs(r,O1):void 0,s=Zs(n,O1);if(typeof i!="string"&&typeof s!="string")return;let o=`${typeof i=="string"?i:"object"}|${typeof s=="string"?s:"material"}|${t}`,a=2166136261;for(let l=0;l<o.length;l++)a=Math.imul(a^o.charCodeAt(l),16777619)>>>0;return`h${a.toString(36)}`}function Ri(n,e){if(n.length===0||n.length>256||JI.test(n))throw new TypeError(`${e} must contain 1...256 characters and no control characters.`)}function wg(n,e){let t=n.get(e);return t||(t=new Map,n.set(e,t)),t}function k1(n,e){let t=n.get(e);return t||(t=new Map,n.set(e,t)),t}function i3(n){let e=Zs(n,"_quadMesh"),t=e&&typeof e=="object"?Zs(e,"material"):void 0;if(!t||typeof t!="object")throw new TypeError("ShaderCache.pipeline() expected a Three.js RenderPipeline with `_quadMesh.material`.");return t}function V1(n){return n.computeShader===null?"render":"compute"}var Md=class{#t;#i;#r=new Set;scene;constructor(e,t,r={}){Ri(t,"Shader scene"),this.#t=e,this.#i=r.replaceExisting??!1,this.scene=t}material(e,t,r={}){return this.#t.material(e,t,this.#s("material",e,r))}pipeline(e,t,r={}){return this.#t.pipeline(e,t,this.#s("pipeline",e,r))}compute(e,t,r={}){return this.#t.compute(e,t,this.#s("compute",e,r))}container(e,t,r={}){return this.#t.container(e,t,this.#s("container",e,r))}invalidateKey(e,t){this.#t.invalidateKey(e,t,this.scene)}invalidate(e){this.#t.invalidateScene(this.scene,e)}#s(e,t,r){let i=`${e}:${t}`,s=!this.#r.has(i);return this.#r.add(i),{...r,scene:this.scene,...r.replace===void 0&&s&&this.#i?{replace:!0}:{}}}},Mg=class{#t=new Map;#i=new Map;#r=new WeakMap;#s=new WeakMap;#c=new Map;#d=new Map;#n=new Map;#o=new Map;#e;constructor(e="default"){Ri(e,"Shader scene"),this.#e=e,Lo(this)}get activeScene(){return this.#e}activateScene(e){return Ri(e,"Shader scene"),this.#e=e,Lo(this),new Md(this,e)}forScene(e,t={}){return new Md(this,e,t)}enableAutomaticRegistration(e={}){let t=e.scene??this.#e,r=e.prefix??"auto";Ri(t,"Shader scene"),Ri(r,"Automatic shader key prefix");let i=this.#n.get(t);if(i!==void 0&&i!==r)throw new Error(`Automatic shader registration for scene "${t}" already uses prefix "${i}".`);this.#n.set(t,r),this.#o.set(t,this.#o.get(t)??{render:new Map,compute:new Map}),Lo(this)}automaticRegistrationPrefix(e=this.#e){return Ri(e,"Shader scene"),this.#n.get(e)}material(e,t,r={}){return this.#a("material",e,t,t,r)}pipeline(e,t,r={}){return this.#a("pipeline",e,i3(t),t,r)}post(e,t,r={}){return this.pipeline(e,t,r)}compute(e,t,r={}){return this.#a("compute",e,t,t,r)}container(e,t,r={}){Ri(e,"Shader container key");let i=r.scene??this.#e;Ri(i,"Shader scene");let s=wg(this.#i,i),o=s.get(e),a=k1(this.#r,t),l=a.get(i);if(o?.target===t&&l?.key===e)return Lo(this),this.#g(o);if(!r.replace&&(o||l))throw this.#f(i,e,"container",o?.key,l);o&&this.#y(o),l&&this.#b(t,i,l);let u={scene:i,key:e,target:t,token:{}};return s.set(e,u),a.set(i,{key:e,kind:"container"}),Lo(this),r.replace&&this.invalidateScene(i,`shader container "${e}" replaced during HMR`),this.#g(u)}registrationForRender(e,t=this.#e,r){let i=this.#r.get(e)?.get(t);if(i&&i.kind!=="compute"&&i.kind!=="container"){let s=this.#t.get(t)?.get(i.key);if(s?.automatic!==!0||r===void 0)return s}return r?this.#p(e,r,t):this.#h("material",e,t)}registrationForCompute(e,t=this.#e){let r=this.#r.get(e)?.get(t);return r?.kind==="compute"?this.#t.get(t)?.get(r.key):this.#h("compute",e,t)}registration(e,t=this.#e){return this.#t.get(t)?.get(e)}containerFor(e,t=this.#e){return this.#i.get(t)?.get(e)?.target}containers(e=this.#e){return[...this.#i.get(e)?.values()??[]].map(t=>({scene:t.scene,key:t.key,target:t.target}))}registrations(e=this.#e){return[...this.#t.get(e)?.values()??[]]}invalidateKey(e,t="shader-producing module changed",r=this.#e){Ri(e,"Shader key"),Ri(r,"Shader scene"),wg(this.#c,r).set(e,t)}invalidateScene(e=this.#e,t="scene shader graph changed"){Ri(e,"Shader scene"),this.#d.set(e,t)}invalidationFor(e,t=this.#e){let r=this.#d.get(t);if(r!==void 0)return{scene:t,reason:r};let i=this.#c.get(t)?.get(e);return i===void 0?void 0:{scene:t,key:e,reason:i}}coverage(e,t=this.#e){let r=this.registrations(t),i=e.scene===t?Object.entries(e.entries):[],s=new Set(r.map(l=>l.key)),o=new Set(i.map(([l])=>l)),a=r.filter(l=>o.has(l.key));return{registered:r.length,registeredRender:r.filter(l=>l.kind!=="compute").length,registeredCompute:r.filter(l=>l.kind==="compute").length,manifest:i.length,manifestRender:i.filter(([,l])=>V1(l)==="render").length,manifestCompute:i.filter(([,l])=>V1(l)==="compute").length,covered:a.length,coveredRender:a.filter(l=>l.kind!=="compute").length,coveredCompute:a.filter(l=>l.kind==="compute").length,missing:r.filter(l=>!o.has(l.key)).map(l=>l.key).sort(),extra:[...o].filter(l=>!s.has(l)).sort()}}#a(e,t,r,i,s,o=!1){Ri(t,"Shader key");let a=s.scene??this.#e;Ri(a,"Shader scene");let l=wg(this.#t,a),u=l.get(t),c=k1(this.#r,r),d=c.get(a);if(u?.target===r&&u.kind===e&&d?.key===t)return Lo(this),this.#m(u);if(!s.replace&&(u||d))throw this.#f(a,t,e,u?.key,d);u&&this.#x(u),d&&this.#b(r,a,d);let h={scene:a,key:t,kind:e,target:r,owner:i,...o?{automatic:!0}:{},token:{}};return l.set(t,h),c.set(a,{key:t,kind:e}),Lo(this),s.replace&&this.invalidateKey(t,"shader registration replaced during HMR",a),this.#m(h)}#h(e,t,r){let i=this.#u(e,t,r);if(i!==void 0)return this.#a(e,i,t,t,{scene:r},!0),this.#t.get(r)?.get(i)}#p(e,t,r){if(this.#n.get(r)===void 0)return;let i=this.#s.get(t);i||(i=new WeakMap,this.#s.set(t,i));let s=i.get(e);s||(s=new Map,i.set(e,s));let o=Zs(e,"side"),a=t3(e,o),l=`${r}:${a}`,u=s.get(l);if(u)return u;let c=this.#n.get(r),d=r3(e,t,a),h=c!==void 0&&d!==void 0?`${c}/render-${d}-${this.#l(e)}`:this.#u("material",e,r);if(h===void 0)return;let p={scene:r,key:h,kind:"material",target:e,owner:e,automatic:!0,token:{}};return wg(this.#t,r).set(h,p),s.set(l,p),Lo(this),p}#l(e){let t=Zs(e,"name")||Zs(e,"type")||e.constructor&&e.constructor.name||"shader";return String(t).toLowerCase().replace(/[^a-z0-9._-]+/gu,"-").replace(/^[-.]+|[-.]+$/gu,"").slice(0,48)||"shader"}#u(e,t,r){let i=this.#n.get(r);if(i===void 0)return;let s=this.#o.get(r)??{render:new Map,compute:new Map};this.#o.set(r,s);let o=this.#l(t),a=e==="compute"?"compute":"render",l=s[a],u=l.get(o)??0;return l.set(o,u+1),`${i}/${a}-${String(u).padStart(4,"0")}-${o}`}#f(e,t,r,i,s){let o=i!==void 0?`key is already registered as "${i}"`:`object is already registered as "${s?.key}" (${s?.kind})`;return new Error(`Shader registration conflict in scene "${e}" for "${t}" (${r}): ${o}. Use { replace: true } only for an intentional HMR replacement.`)}#m(e){return{scene:e.scene,key:e.key,kind:e.kind,dispose:()=>{let t=this.#t.get(e.scene)?.get(e.key);t?.token===e.token&&(this.#x(t),this.invalidateKey(e.key,"shader registration removed",e.scene))}}}#g(e){return{scene:e.scene,key:e.key,kind:"container",dispose:()=>{let t=this.#i.get(e.scene)?.get(e.key);t?.token===e.token&&(this.#y(t),this.invalidateScene(e.scene,`shader container "${e.key}" removed`))}}}#x(e){this.#t.get(e.scene)?.delete(e.key),this.#r.get(e.target)?.delete(e.scene)}#y(e){this.#i.get(e.scene)?.delete(e.key),this.#r.get(e.target)?.delete(e.scene)}#b(e,t,r){r.kind==="container"?this.#i.get(t)?.get(r.key)?.target===e&&this.#i.get(t)?.delete(r.key):this.#t.get(t)?.get(r.key)?.target===e&&this.#t.get(t)?.delete(r.key),this.#r.get(e)?.delete(t)}};function kN(n){return new Mg(n)}var VN=kN();var vg="three-webgpu-r185-v1";var $1=4096,n3=32*1024*1024,Za=65536,W1=64,o3=16,a3=32,l3=/[\u0000-\u001f\u007f]/u,$N=new Set(["__proto__","prototype","constructor"]);function u3(n,e){return e.length===0}var Rd=class extends Error{issues;constructor(e,t){super(e),this.name="ShaderManifestError",this.issues=t}};function Xr(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}function K(n,e){return Object.prototype.hasOwnProperty.call(n,e)?n[e]:void 0}function We(n,e=256){return typeof n=="string"&&n.length>0&&n.length<=e&&!l3.test(n)}function Z(n,e,t){return n.push({path:e,message:t}),!1}function vd(n,e,t,r=!1){if(!Array.isArray(n)||n.length>W1)return Z(t,e,`must be an array with at most ${W1} segments`);let i=!0;for(let s=0;s<n.length;s++){let o=n[s];if(!Number.isSafeInteger(o)&&(r||!We(o,256))){i=Z(t,`${e}[${s}]`,r?"must be a non-negative integer":"must be a safe integer or non-empty string")&&i;continue}typeof o=="number"&&o<0&&(i=Z(t,`${e}[${s}]`,"must not be negative")&&i),typeof o=="string"&&$N.has(o)&&(i=Z(t,`${e}[${s}]`,"is an unsafe object path segment")&&i)}return i}function Ag(n,e,t,r=0,i=new WeakSet){if(n===null||typeof n=="boolean"||typeof n=="string")return!0;if(typeof n=="number")return Number.isFinite(n)||Z(t,e,"must be finite");if(r>=a3)return Z(t,e,"exceeds the maximum JSON depth");if(typeof n!="object")return Z(t,e,"must be JSON-serializable");if(i.has(n))return Z(t,e,"must not contain cycles");i.add(n);let s=!0;if(Array.isArray(n)){n.length>Za&&(s=Z(t,e,"contains too many items"));for(let o=0;o<n.length;o++)s=Ag(n[o],`${e}[${o}]`,t,r+1,i)&&s}else if(Xr(n))for(let[o,a]of Object.entries(n))!We(o)||$N.has(o)?s=Z(t,`${e}.${o}`,"has an unsafe property name")&&s:s=Ag(a,`${e}.${o}`,t,r+1,i)&&s;else s=Z(t,e,"must be a JSON object or array");return i.delete(n),s}function Rg(n,e,t,r=0,i=new WeakSet){if(r>=o3)return Z(t,e,"exceeds the maximum address depth");if(!Xr(n))return Z(t,e,"must be an address object");if(i.has(n))return Z(t,e,"must not contain a cycle");i.add(n);let s=K(n,"k"),o=!0;switch(s){case"anchor":We(K(n,"slot"))||(o=Z(t,`${e}.slot`,"must be a stable slot name")),K(n,"key")!==void 0&&!We(K(n,"key"))&&(o=Z(t,`${e}.key`,"must be a stable key")&&o),o=vd(K(n,"path"),`${e}.path`,t,!0)&&o;break;case"container":We(K(n,"key"))||(o=Z(t,`${e}.key`,"must be a stable container key")),o=vd(K(n,"path"),`${e}.path`,t)&&o;break;case"owned":o=Rg(K(n,"owner"),`${e}.owner`,t,r+1,i)&&o,o=vd(K(n,"path"),`${e}.path`,t)&&o,K(n,"prime")!==void 0&&K(n,"prime")!=="reference"&&(o=Z(t,`${e}.prime`,'must be "reference"')&&o);break;case"tsl":case"namedRenderUniform":We(K(n,"name"))||(o=Z(t,`${e}.name`,"must be a stable name"));break;case"lightNode":(!Number.isSafeInteger(K(n,"light"))||Number(K(n,"light"))<0)&&(o=Z(t,`${e}.light`,"must be a non-negative integer")),K(n,"sceneLight")!==void 0&&(!Number.isSafeInteger(K(n,"sceneLight"))||Number(K(n,"sceneLight"))<0)&&(o=Z(t,`${e}.sceneLight`,"must be a non-negative integer")&&o);break;case"lightUniform":{let a=K(n,"fn");["lightPosition","lightTargetPosition","lightViewPosition","lightShadowMatrix"].includes(String(a))||(o=Z(t,`${e}.fn`,"is not a supported light recipe")),(!Number.isSafeInteger(K(n,"light"))||Number(K(n,"light"))<0)&&(o=Z(t,`${e}.light`,"must be a non-negative integer")&&o),K(n,"sceneLight")!==void 0&&(!Number.isSafeInteger(K(n,"sceneLight"))||Number(K(n,"sceneLight"))<0)&&(o=Z(t,`${e}.sceneLight`,"must be a non-negative integer")&&o);break}case"materialCache":We(K(n,"property"))||(o=Z(t,`${e}.property`,"must be a property name")),K(n,"type")!==null&&!We(K(n,"type"))&&(o=Z(t,`${e}.type`,"must be a node type or null")&&o);break;case"sceneEnv":break;case"reference":{We(K(n,"property"))||(o=Z(t,`${e}.property`,"must be a property path")),We(K(n,"uniformType"))||(o=Z(t,`${e}.uniformType`,"must be a uniform type")&&o);let a=K(n,"count");a!==void 0&&(!Number.isSafeInteger(a)||Number(a)<0)&&(o=Z(t,`${e}.count`,"must be a non-negative integer")&&o);let l=K(n,"object");l!==void 0&&(Xr(l)?(We(K(l,"container"))||(o=Z(t,`${e}.object.container`,"must be a container key")&&o),o=vd(K(l,"path"),`${e}.object.path`,t)&&o):o=Z(t,`${e}.object`,"must be a container reference")&&o),K(n,"group")!==void 0&&!We(K(n,"group"))&&(o=Z(t,`${e}.group`,"must be a TSL group name")&&o),K(n,"name")!==void 0&&!We(K(n,"name"))&&(o=Z(t,`${e}.name`,"must be a uniform name")&&o);break}case"inputNode":{We(K(n,"nodeClass"))||(o=Z(t,`${e}.nodeClass`,"must be a recipe class"));let a=K(n,"value");Xr(a)?(We(K(a,"container"))||(o=Z(t,`${e}.value.container`,"must be a container key")&&o),o=vd(K(a,"path"),`${e}.value.path`,t)&&o):o=Z(t,`${e}.value`,"must be a container reference")&&o,o=H1(n,e,t)&&o;break}case"inputValue":We(K(n,"nodeClass"))||(o=Z(t,`${e}.nodeClass`,"must be a recipe class")),o=Ag(K(n,"json"),`${e}.json`,t)&&o,o=H1(n,e,t)&&o;break;case"recipe":We(K(n,"id"))||(o=Z(t,`${e}.id`,"must be a recipe identifier")),K(n,"version")!==1&&(o=Z(t,`${e}.version`,`must be ${1}`)&&o),K(n,"input")!==void 0&&(o=Ag(K(n,"input"),`${e}.input`,t)&&o);break;default:o=Z(t,`${e}.k`,`contains unknown address kind "${String(s)}"`)}return i.delete(n),o}function H1(n,e,t){let r=!0;for(let o of["access","uniformType","group"]){let a=K(n,o);a!=null&&!We(a)&&(r=Z(t,`${e}.${o}`,"must be null or a non-empty string")&&r)}let i=K(n,"n");i!==void 0&&(!Number.isSafeInteger(i)||Number(i)<0)&&(r=Z(t,`${e}.n`,"must be a non-negative integer")&&r);let s=K(n,"bufferCount");s!==void 0&&(!Number.isSafeInteger(s)||Number(s)<0)&&(r=Z(t,`${e}.bufferCount`,"must be a non-negative integer")&&r);for(let o of["stride","offset","usage"]){let a=K(n,o);a!==void 0&&(!Number.isSafeInteger(a)||Number(a)<0)&&(r=Z(t,`${e}.${o}`,"must be a non-negative integer")&&r)}for(let o of["atomic","pbo","instanced","comparison"]){let a=K(n,o);a!==void 0&&typeof a!="boolean"&&(r=Z(t,`${e}.${o}`,"must be a boolean")&&r)}return r}function c3(n,e,t){if(!Array.isArray(n)||n.length>Za)return Z(t,e,"must be a bounded address array");let r=!0;for(let i=0;i<n.length;i++)r=Rg(n[i],`${e}[${i}]`,t)&&r;return r}function d3(n,e,t,r){return n===null?!0:typeof n!="string"||n.length===0||n.length>n3?Z(r,e,"must be null or a bounded non-empty WGSL string"):n.includes(t)||Z(r,e,`must contain ${t}`)}function h3(n,e,t,r){if(!Xr(n))return Z(r,t,"must be an entry object");let i=!0;K(n,"key")!==e&&(i=Z(r,`${t}.key`,`must equal "${e}"`));for(let[h,p]of[["vertexShader","@vertex"],["fragmentShader","@fragment"],["computeShader","@compute"]])i=d3(K(n,h),`${t}.${h}`,p,r)&&i;let s=K(n,"vertexShader")!==null,o=K(n,"fragmentShader")!==null,a=K(n,"computeShader")!==null;a&&(s||o)&&(i=Z(r,t,"must not mix render and compute stages")&&i),!a&&!s&&!o&&(i=Z(r,t,"must contain at least one shader stage")&&i);let l=K(n,"uniformCalls");if(!Array.isArray(l)||l.length>Za)i=Z(r,`${t}.uniformCalls`,"must be a bounded array")&&i;else for(let h=0;h<l.length;h++){let p=l[h],f=`${t}.uniformCalls[${h}]`;if(!Xr(p)){i=Z(r,f,"must be an object")&&i;continue}i=Rg(K(p,"node"),`${f}.node`,r)&&i,We(K(p,"type"))||(i=Z(r,`${f}.type`,"must be a node type")&&i),["vertex","fragment","compute"].includes(String(K(p,"stage")))||(i=Z(r,`${f}.stage`,"must be a shader stage")&&i);let m=K(p,"name");m!==null&&!We(m)&&(i=Z(r,`${f}.name`,"must be null or a stable name")&&i);let g=K(p,"nid");g!==void 0&&(!Number.isSafeInteger(g)||Number(g)<0||Number(g)>=1e9)&&(i=Z(r,`${f}.nid`,"must be an integer in 0...999999999")&&i)}let u=K(n,"attributes");if(!Array.isArray(u)||u.length>Za)i=Z(r,`${t}.attributes`,"must be a bounded array")&&i;else for(let h=0;h<u.length;h++){let p=u[h],f=`${t}.attributes[${h}]`;if(!Xr(p)){i=Z(r,f,"must be an object")&&i;continue}We(K(p,"name"))||(i=Z(r,`${f}.name`,"must be an attribute name")&&i),We(K(p,"type"))||(i=Z(r,`${f}.type`,"must be an attribute type")&&i);let m=K(p,"node");m!==null&&(i=Rg(m,`${f}.node`,r)&&i)}let c=K(n,"bindGroups");if(!Array.isArray(c)||c.length>Za)i=Z(r,`${t}.bindGroups`,"must be a bounded array")&&i;else for(let h=0;h<c.length;h++){let p=c[h],f=`${t}.bindGroups[${h}]`;if(!Xr(p)){i=Z(r,f,"must be an object")&&i;continue}K(p,"index")!==h&&(i=Z(r,`${f}.index`,`must equal ${h}`)&&i),We(K(p,"name"))||(i=Z(r,`${f}.name`,"must be a bind group name")&&i);let m=K(p,"bindings");if(!Array.isArray(m)||m.length>Za)i=Z(r,`${f}.bindings`,"must be a bounded array")&&i;else for(let g=0;g<m.length;g++){let x=m[g],w=`${f}.bindings[${g}]`;if(!Xr(x)||!We(K(x,"name"))||!We(K(x,"kind"))){i=Z(r,w,"must contain stable name and kind strings")&&i;continue}let v=K(x,"uniforms");if(v!==void 0)if(K(x,"kind")!=="NodeUniformsGroup"&&(i=Z(r,`${w}.uniforms`,"is supported only for NodeUniformsGroup bindings")&&i),!Array.isArray(v)||v.length>Za)i=Z(r,`${w}.uniforms`,"must be a bounded array")&&i;else for(let E=0;E<v.length;E++){let b=v[E];(!Xr(b)||!We(K(b,"name"))||!We(K(b,"type")))&&(i=Z(r,`${w}.uniforms[${E}]`,"must contain stable name and type strings")&&i)}}}for(let h of["updateNodes","updateBeforeNodes","updateAfterNodes"])i=c3(K(n,h),`${t}.${h}`,r)&&i;let d=K(n,"observer");return d!==null&&(!Xr(d)||typeof K(d,"hasNode")!="boolean"||typeof K(d,"hasAnimation")!="boolean")&&(i=Z(r,`${t}.observer`,"must be null or contain boolean hasNode/hasAnimation")&&i),typeof K(n,"hardwareClipping")!="boolean"&&(i=Z(r,`${t}.hardwareClipping`,"must be boolean")&&i),i}function p3(n){let e=[];if(!Xr(n))return{ok:!1,issues:[{path:"$",message:"must be an object"}]};K(n,"version")!==2&&Z(e,"$.version",`must be ${2}`),We(K(n,"scene"))||Z(e,"$.scene","must be a stable scene key");for(let s of["three","threeBlocks"]){let o=K(n,s);o!==void 0&&!We(o,128)&&Z(e,`$.${s}`,"must be a non-empty version string")}let t=K(n,"runtime");t!==void 0&&(Xr(t)?(We(K(t,"id"))||Z(e,"$.runtime.id","must be a compatibility identifier"),K(t,"address")!==1&&Z(e,"$.runtime.address",`must be ${1}`),K(t,"recipe")!==1&&Z(e,"$.runtime.recipe",`must be ${1}`),K(t,"hydration")!==1&&Z(e,"$.runtime.hydration",`must be ${1}`)):Z(e,"$.runtime","must be an object"));let r=K(n,"automatic");r!==void 0&&(Xr(r)?We(K(r,"prefix"))||Z(e,"$.automatic.prefix","must be a stable key prefix"):Z(e,"$.automatic","must be an object"));let i=K(n,"entries");if(!Xr(i))Z(e,"$.entries","must be an object");else{let s=Object.entries(i);s.length>$1&&Z(e,"$.entries",`must contain at most ${$1} entries`);for(let[o,a]of s)!We(o)||$N.has(o)?Z(e,`$.entries.${o}`,"uses an unsafe key"):h3(a,o,`$.entries.${o}`,e)}return u3(n,e)?{ok:!0,manifest:n}:{ok:!1,issues:e}}function q1(n){let e=p3(n);if(e.ok)return e.manifest;throw new Rd(`Invalid precompiled shader manifest: ${e.issues[0]?.path??"$"} ${e.issues[0]?.message??"is invalid"}.`,e.issues)}var f3=1e9,m3=[{directive:/(?:^|\n)\s*enable\s+subgroups\s*;/u,feature:"subgroups"},{directive:/(?:^|\n)\s*enable\s+subgroups[-_]f16\s*;/u,feature:"subgroups-f16"},{directive:/(?:^|\n)\s*enable\s+f16\s*;/u,feature:"shader-f16"},{directive:/(?:^|\n)\s*enable\s+clip_distances\s*;/u,feature:"clip-distances"},{directive:/(?:^|\n)\s*enable\s+dual_source_blending\s*;/u,feature:"dual-source-blending"}];function g3(n,e){let t=Reflect.get(globalThis,"console");if(t===null||typeof t!="object")return;let r=Reflect.get(t,n);typeof r=="function"&&r.call(t,`[three-blocks/shaders] ${e}`)}var Cg=class extends Error{scene;key;kind;causeValue;constructor(e,t,r,i){super(`Precompiled ${r} hydration failed for shader key "${t}" in scene "${e}": `+(i instanceof Error?i.message:String(i))),this.name="ShaderHydrationError",this.scene=e,this.key=t,this.kind=r,this.causeValue=i}};function x3(){return{lookups:0,renderLookups:0,computeLookups:0,injected:0,injectedRender:0,injectedCompute:0,missed:0,missedRender:0,missedCompute:0,live:0,liveRender:0,liveCompute:0,invalidated:0,hydrationFailures:0}}function WN(n,e){return e.bindingKind?.(n)??n.kind??n.constructor?.name??""}function y3(n,e){let t=[n.vertexShader,n.fragmentShader,n.computeShader].filter(i=>i!==null),r=Reflect.get(e,"hasFeature");for(let i of m3)if(t.some(s=>i.directive.test(s))!==!1){if(typeof r!="function")return i.feature;try{if(r.call(e,i.feature)!==!0)return i.feature}catch{return i.feature}}return null}function b3(n,e,t){return n===e?!0:t==="NodeStorageBuffer"?/^StorageBuffer_\d+$/u.test(n)&&/^StorageBuffer_\d+$/u.test(e):t==="NodeUniformBuffer"?/^UniformBuffer_\d+$/u.test(n)&&/^UniformBuffer_\d+$/u.test(e):!1}function _3(n){let e=n.getType?.();return typeof e=="string"?e:""}function T3(n){if(n==="mat2")return 4;if(n==="mat3")return 9;if(n==="mat4")return 16}function S3(n,e,t){let r=T3(e);if(r===void 0||t!=="container"||Reflect.get(n,"isUniformNode")!==!0)return;let i=Reflect.get(n,"value"),s=i!==null&&typeof i=="object"?Reflect.get(i,"elements"):void 0,o=s!==null&&typeof s=="object"?Reflect.get(s,"length"):void 0;if(o!==r)throw new Error(`direct ${e} uniform has an invalid matrix value (expected ${r} elements, got ${typeof o=="number"?o:"none"})`)}function N3(n,e,t){if(n.uniforms===void 0)return;let r=e.uniforms;if(!Array.isArray(r))throw new Error(`${t} has no uniform member list`);let i=r;if(i.length!==n.uniforms.length)throw new Error(`${t} uniform count mismatch (${i.length} != ${n.uniforms.length})`);let s=[...i],o=n.uniforms.map((a,l)=>{let u=s.findIndex(d=>d.name===a.name&&_3(d)===a.type);if(u<0)throw new Error(`${t} uniform ${l} mismatch: expected "${a.name}"/${a.type}`);let[c]=s.splice(u,1);if(c===void 0)throw new Error(`${t} uniform ${l} disappeared during layout restoration`);return c});if(s.length>0)throw new Error(`${t} contains unexpected uniform members`);i.splice(0,i.length,...o)}function w3(n,e,t){if(e.length!==n.bindGroups.length)throw new Error(`binding group count mismatch (${e.length} != ${n.bindGroups.length})`);for(let r=0;r<e.length;r++){let i=e[r],s=n.bindGroups[r];if(i===void 0||s===void 0)throw new Error("binding group disappeared during replay");if(i.name!==s.name||i.bindings.length!==s.bindings.length){let o=i.bindings.map(l=>`${l.name}/${WN(l,t)}`).join(", "),a=s.bindings.map(l=>`${l.name}/${l.kind}`).join(", ");throw new Error(`binding group ${r} mismatch: got "${i.name}"(${i.bindings.length}), expected "${s.name}"(${s.bindings.length}); got [${o}], expected [${a}]`)}for(let o=0;o<i.bindings.length;o++){let a=i.bindings[o],l=s.bindings[o];if(a===void 0||l===void 0)throw new Error("binding disappeared during replay");let u=WN(a,t);if(u!==l.kind||!b3(a.name,l.name,u))throw new Error(`binding ${r}:${o} mismatch: got "${a.name}"/${u}, expected "${l.name}"/${l.kind}`);N3(l,a,`binding ${r}:${o}`)}}}var M3=[/@binding\(\s*(?<binding>\d+)\s*\)\s*@group\(\s*(?<group>\d+)\s*\)\s*var\s*<\s*storage\s*(?:,\s*(?<access>read_write|read|write)\s*)?>/gu,/@group\(\s*(?<group>\d+)\s*\)\s*@binding\(\s*(?<binding>\d+)\s*\)\s*var\s*<\s*storage\s*(?:,\s*(?<access>read_write|read|write)\s*)?>/gu],v3=[/@binding\(\s*(?<binding>\d+)\s*\)\s*@group\(\s*(?<group>\d+)\s*\)\s*var\s+\w+\s*:\s*texture_storage_\w+<\s*\w+\s*,\s*(?<access>read_write|read|write)\s*>/gu,/@group\(\s*(?<group>\d+)\s*\)\s*@binding\(\s*(?<binding>\d+)\s*\)\s*var\s+\w+\s*:\s*texture_storage_\w+<\s*\w+\s*,\s*(?<access>read_write|read|write)\s*>/gu];function A3(n){let e=new Map,t=(r,i)=>{for(let s of r)for(let o of n.matchAll(s)){let{group:a,binding:l,access:u}=o.groups??{};a===void 0||l===void 0||e.set(`${a}:${l}`,{resource:i,access:u??"read"})}};return t(M3,"buffer"),t(v3,"texture"),e}function R3(n,e,t){if(n.computeShader===null)return;let r=A3(n.computeShader);for(let i=0;i<e.length;i++){let s=e[i];if(s===void 0)continue;let o=Reflect.get(s,"index"),a=typeof o=="number"?o:i;for(let l=0;l<s.bindings.length;l++){let u=s.bindings[l];if(u===void 0)continue;let c=r.get(`${a}:${l}`),d=WN(u,t),h=Reflect.get(u,"access"),p=`binding ${a}:${l} ("${u.name}")`;if(d==="NodeStorageBuffer"||d==="StorageBuffer"){if(c===void 0||c.resource!=="buffer")throw new Error(`${p} is a storage buffer, but the captured WGSL declares none at that slot`);let f=h==="readWrite"||h==="writeOnly"?"read_write":"read",m=c.access==="read"?"read":"read_write";if(f!==m)throw new Error(`${p} storage access drift: captured WGSL requires "${m}" but the live layout is "${f}"`)}else if(d.includes("Sampled")&&Reflect.get(u,"store")===!0){if(c===void 0||c.resource!=="texture")throw new Error(`${p} is a storage texture, but the captured WGSL declares none at that slot`);let f=h==="readWrite"?"read_write":h==="writeOnly"?"write":"read";if(f!==c.access)throw new Error(`${p} storage texture access drift: captured WGSL requires "${c.access}" but the live layout is "${f}"`)}else if(c!==void 0)throw new Error(`${p} mismatch: captured WGSL declares a storage ${c.resource} at that slot, but the live binding is ${d}`)}}}function C3(n,e,t,r,i,s,o,a,l,u){return{sceneKey:n.scene,key:n.key,kind:e,renderer:t,...r?{renderObject:r}:{},target:n.target,object:i,material:s,scene:o,lightsNode:a,anchors:u.anchorsFor(n.target,e),container:c=>l.containerFor(c,n.scene)}}function E3(n,e,t){let r=t.createBindingBuilder(e);e.builder=r,r.material=e.material,r.scene=e.scene,r.lightsNode=e.lightsNode,e.material!==null&&(r.context??={},r.context.material=e.material);let i=new Map,s=new Map;for(let p=0;p<n.uniformCalls.length;p++){let f=n.uniformCalls[p];if(f===void 0)throw new Error(`uniform replay call ${p} is absent`);try{let m=JSON.stringify(f.node),g=f.nid===void 0?m:`${m}\0${f.nid}`,x=i.get(g);if(x===void 0){x=Fo(f.node,e,t),S3(x,f.type,f.node.k);let w=s.get(m);if(w!==void 0&&w!==g){if(t.cloneBindingNode===void 0)throw new Error("captured node identity alias is not cloneable");x=t.cloneBindingNode(x)}else w===void 0&&s.set(m,g);i.set(g,x)}t.primeBindingNode?.(x,r),f.nid!==void 0&&typeof x.id=="number"&&(x.id=f3+f.nid),r.shaderStage=f.stage,r.getUniformFromNode(x,f.type,f.stage,f.name)}catch(m){throw new Error(`uniform replay ${p}/${n.uniformCalls.length} (${f.name??"<anonymous>"} ${f.type}@${f.stage}) failed: ${m instanceof Error?m.message:String(m)}`)}}r.shaderStage=null;let o;t.getBindings?o=t.getBindings(r,e):(r.sortBindingGroups(),o=r.getBindings()),w3(n,o,t),R3(n,o,t);let a=n.attributes.map(p=>{let f=p.node===null?null:Fo(p.node,e,t);return t.createAttribute?.(p.name,p.type,f,r)??{isNodeAttribute:!0,name:p.name,type:p.type,node:f}}),l=p=>{let f=Fo(p,e,t);return t.primeOwnedAddress?.(f,e),t.primeBindingNode?.(f,r),f},u=n.updateNodes.map(l),c=n.updateBeforeNodes.map(l),d=n.updateAfterNodes.map(l),h=t.createObserver?.(n,e)??null;return[n.vertexShader,n.fragmentShader,n.computeShader,a,o,u,c,d,h,n.hardwareClipping,[]]}var Eg=class{#t;#i;#r;#s;#c;#d;#n=new Set;#o=new Set;#e=x3();#a=0;constructor(e){let t=q1(e.manifest);if(!e.compatibility.supportsManifest(t))throw new Rd(`Manifest compatibility is not supported by ${e.compatibility.id}.`,[{path:"$.runtime",message:"does not match the active Three.js adapter"}]);this.#t=t,this.#i=e.renderer,this.#r=e.cache??VN,this.#s=e.compatibility,this.#c=e.logger??g3,this.#d=e.strict===!0}get manifest(){return this.#t}get stats(){return{...this.#r.coverage(this.#t),...this.#e}}invalidateKey(e,t){this.#r.invalidateKey(e,t,this.#t.scene)}invalidateScene(e){this.#r.invalidateScene(this.#t.scene,e)}getForRender(e){this.#e.lookups++,this.#e.renderLookups++;let t=this.#r.registrationForRender(e.material,this.#t.scene,e);return t===void 0?null:this.#h(t,"render",e,e.object,e.material,e.scene??null,e.lightsNode??null)}getForCompute(e){this.#e.lookups++,this.#e.computeLookups++;let t=this.#r.registrationForCompute(e,this.#t.scene);return t===void 0?null:this.#h(t,"compute",void 0,e,null,null,null)}#h(e,t,r,i,s,o,a){if(this.#o.has(e.key))return this.#l(t),null;let l=this.#r.invalidationFor(e.key,e.scene);if(l!==void 0)return this.#e.invalidated++,this.#l(t),this.#u(`invalidated:${e.key}`,`Shader key "${e.key}" is invalidated (${l.reason}); building live.`),null;let u=this.#t.entries[e.key];if(u===void 0)return this.#e.missed++,t==="compute"?this.#e.missedCompute++:this.#e.missedRender++,this.#l(t),this.#n.has(`missing:${e.key}`)||this.#a++,this.#a<=3?this.#u(`missing:${e.key}`,`Shader key "${e.key}" has no entry in scene "${e.scene}"; building live.`):(this.#n.add(`missing:${e.key}`),this.#u("missing:summary",`More shader keys have no entry in scene "${e.scene}" \u2014 the shader manifest does not match this build. Affected keys stay on live compilation; run \`three-blocks shaders capture\` to refresh the manifest.`)),null;let c=u.computeShader===null?"render":"compute";if(c!==t)return this.#p(e,t,new Error(`manifest entry is ${c}, not ${t}`));let d=y3(u,this.#i);if(d!==null)return this.#p(e,t,new Error(`captured WGSL requires unavailable WebGPU feature "${d}"`));let h=C3(e,t,this.#i,r,i,s,o,a,this.#r,this.#s);try{let p=E3(u,h,this.#s);return this.#e.injected++,t==="compute"?this.#e.injectedCompute++:this.#e.injectedRender++,p}catch(p){return this.#p(e,t,p)}}#p(e,t,r){this.#e.hydrationFailures++;let i=new Cg(e.scene,e.key,t,r);if(this.#d)throw i;return this.#o.add(e.key),this.#l(t),this.#u(`hydration:${e.key}`,`${i.message} Building live; run \`three-blocks shaders capture\` to refresh the manifest.`,"error"),null}#l(e){this.#e.live++,e==="compute"?this.#e.liveCompute++:this.#e.liveRender++}#u(e,t,r="warn"){this.#n.has(e)||(this.#n.add(e),this.#c(r,t))}};var Y1=["fragmentNode","vertexNode","colorNode","positionNode","normalNode","opacityNode","alphaTestNode","backdropNode","backdropAlphaNode","emissiveNode","metalnessNode","roughnessNode","clearcoatNode","clearcoatRoughnessNode","transmissionNode","thicknessNode","iorNode","outputNode","mrtNode","depthNode","castShadowNode","receivedShadowNode","maskNode","envNode"],B3={Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,Int8Array,Int16Array,Int32Array,Float32Array,Float64Array};function F3(n){let e=/^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/u.exec(n);return e?.[1]==="0"&&e[2]==="185"}function K1(n){if(!F3(n))throw new Error(`Three Blocks shader compatibility ${vg} supports Three.js 0.185.x; received "${n}".`)}function ne(n){return n!==null&&typeof n=="object"}function L3(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}function P3(n){return Reflect.has(n,"_generator")&&Reflect.has(n,"_pmrem")&&ne(F(n,"_texture"))&&F(F(n,"_texture"),"isNode")===!0}function Dt(n,e){let t=ne(n)?F(n,"getSelf"):void 0,r=ne(n)&&typeof t=="function"?t.call(n):n;if(!ne(r)||F(r,"isNode")!==!0)throw new Error(`${e} did not create a Three.js node.`);return r}function Ed(n){return F(mm,n)}function Qt(n){let e=Ed(n);if(typeof e!="function")throw new Error(`Three.js r185 TSL factory "${n}" is unavailable.`);return e}function Bd(n,e){let t=e===void 0?Qt("uniform")(n):Qt("uniform")(n,e);return Dt(t,"uniform()")}function F(n,e){return Reflect.get(n,e)}function D3(n,e,t){let r=e.at(-3)==="shadow"&&e.at(-2)==="map"&&e.at(-1)==="_depthTexture",i=e.at(-4)==="shadow"&&e.at(-3)==="map"&&e.at(-2)==="textures"&&e.at(-1)===0;if(!r&&!i)return;let s=e.length-(r?3:4),o=s===0?n:Sg(n,e.slice(0,s));if(!ne(o))return;let a=F(o,"shadow");if(!ne(a))return;let l=F(a,"shadowNode");ne(l)&&F(l,"isNode")===!0&&HN(l,t);let u=F(a,"map");if(ne(u)){if(r&&!ne(F(u,"_depthTexture"))){let b=F(u,"depthTexture");ne(b)&&Reflect.set(u,"_depthTexture",b)}return}let c=F(a,"mapSize");if(!ne(c))return;let d=Number(F(c,"width")),h=Number(F(c,"height"));if(!Number.isFinite(d)||!Number.isFinite(h))return;let p=new ot(d,h);p.name="ShadowDepthTexture",p.compareFunction=F(t.renderer,"reversedDepthBuffer")===!0?ui:Pi;let f=new ct(d,h);f.texture.name="ShadowMap";let m=F(a,"mapType");typeof m=="number"&&Reflect.set(f.texture,"type",m),f.depthTexture=p;let g=F(t.renderer,"shadowMap"),x=ne(g)?F(g,"type"):void 0,w=F(t.renderer,"hasCompatibility"),v=typeof w=="function"&&w.call(t.renderer,xr.TEXTURE_COMPARE),E=(x===Gn||x===Ru)&&v?je:Pe;p.minFilter=E,p.magFilter=E,Reflect.set(f,"_depthTexture",p),Reflect.set(a,"map",f)}function Cd(n){return e=>{let t=F(e,"camera");if(!ne(t))throw new Error("Three.js render update has no camera.");return F(t,n)}}function Mu(n,e,t){let r=Bd(n),i=Ed("renderGroup");if(!r.setName||!r.setGroup||!r.onRenderUpdate||i===void 0)throw new Error("Three.js r185 named-render-uniform API drifted.");let s=r.setName(e),o=s.setGroup;if(!o)throw new Error("Three.js r185 uniform lost setGroup().");let a=o.call(s,i),l=a.onRenderUpdate;if(!l)throw new Error("Three.js r185 uniform lost onRenderUpdate().");return l.call(a,t)}function U3(n){switch(n){case"cameraProjectionMatrix":return Mu(new ue,n,Cd("projectionMatrix"));case"cameraProjectionMatrixInverse":return Mu(new ue,n,Cd("projectionMatrixInverse"));case"cameraViewMatrix":return Mu(new ue,n,Cd("matrixWorldInverse"));case"cameraWorldMatrix":return Mu(new ue,n,Cd("matrixWorld"));case"cameraNormalMatrix":return Mu(new et,n,Cd("normalMatrix"));case"cameraPosition":return Mu(new C,n,(e,t)=>{let r=F(e,"camera"),i=F(t,"value");if(!ne(r)||!ne(i))throw new Error("cameraPosition recipe has no camera/value.");let s=F(i,"setFromMatrixPosition");if(typeof s!="function")throw new Error("cameraPosition value is not a Vector3.");return s.call(i,F(r,"matrixWorld"))});default:throw new Error(`Three.js r185 has no named uniform recipe "${n}".`)}}function j1(n){if(typeof n=="number"||typeof n=="boolean")return n;if(!ne(n)||Array.isArray(n))throw new Error("Invalid embedded shader value item.");let e=F(n,"t"),t=F(n,"a");if(!Array.isArray(t)||!t.every(r=>typeof r=="number"))throw new Error(`Embedded shader value "${String(e)}" has no numeric array.`);switch(e){case"v2":return new se().fromArray(t);case"v3":return new C().fromArray(t);case"v4":return new pe().fromArray(t);case"c":return new le().fromArray(t);case"m3":return new et().fromArray(t);case"m4":return new ue().fromArray(t);default:throw new Error(`Unknown embedded shader value tag "${String(e)}".`)}}function Po(n,e){let t=F(n,e);if(typeof t!="number"||!Number.isFinite(t))throw new Error(`Embedded texture ${e} is invalid.`);return t}function I3(n){let e=F(n,"arrayType"),t=F(n,"data");if(typeof e!="string"||!Array.isArray(t)||!t.every(o=>typeof o=="number"))throw new Error("Embedded texture data is invalid.");let r=B3[e];if(r===void 0)throw new Error(`Unsupported embedded texture array "${e}".`);let i=new yn(new r(t),Po(n,"width"),Po(n,"height"),Po(n,"format"),Po(n,"type"));i.minFilter=Po(n,"minFilter"),i.magFilter=Po(n,"magFilter"),i.wrapS=Po(n,"wrapS"),i.wrapT=Po(n,"wrapT");let s=F(n,"name");return i.name=typeof s=="string"?s:"",i.generateMipmaps=!1,i.needsUpdate=!0,i}function O3(n){if(ne(n)&&!Array.isArray(n)){let e=F(n,"t");if(e==="arr"){let t=F(n,"items");if(!Array.isArray(t))throw new Error("Embedded shader array is invalid.");return t.map(r=>j1(r))}if(e==="dtex")return I3(n);if(e==="tex")return new nt;if(e===void 0)return n}return j1(n)}function k3(n){if(F(n,"isComputeNode")!==!0)return;let e=F(n,"count");if(e!==null&&F(n,"countNode")===null){let t=Bd(e,"uint"),r=t.onObjectUpdate;Reflect.set(n,"countNode",r?r.call(t,()=>F(n,"count")):t)}}function V3(n,e){if(F(n,"node")!==null)return;let t=F(n,"updateReference");typeof t=="function"&&t.call(n,{material:e.material,object:e.object,renderer:e.renderer});let r=F(n,"updateValue");typeof r=="function"&&r.call(n)}function HN(n,e){V3(n,e);let t=F(n,"constructor");if((typeof t=="function"||ne(t))&&F(t,"name")==="CubeMapNode"&&F(n,"_cubeTexture")===null&&e.builder!==void 0){let i=F(n,"setup");typeof i=="function"&&i.call(n,e.builder)}if(F(n,"isPassNode")===!0&&e.builder!==void 0){let i=F(n,"setup");typeof i=="function"&&i.call(n,e.builder)}if(F(n,"isGaussianBlurNode")===!0&&F(n,"_material")===null&&e.builder!==void 0){let i=F(n,"setup");typeof i=="function"&&i.call(n,e.builder)}if(F(n,"isRTTNode")===!0&&F(n,"_rttNode")===null&&e.builder!==void 0){let i=F(n,"setup");typeof i=="function"&&i.call(n,e.builder)}if(F(n,"isSmokeNodeRTT")===!0&&F(n,"_materialsBuilt")===!1){let i=F(n,"setup");typeof i=="function"&&i.call(n)}if((typeof t=="function"||ne(t))&&F(t,"name")==="BloomNode"&&Array.isArray(F(n,"_separableBlurMaterials"))&&F(n,"_separableBlurMaterials").length===0&&e.builder!==void 0){let i=F(n,"setup");typeof i=="function"&&i.call(n,e.builder)}if(F(n,"isMRTNode")===!0&&Array.isArray(F(n,"members"))&&F(n,"members").length===0&&e.builder!==void 0){let i=F(n,"setup");typeof i=="function"&&i.call(n,e.builder)}if(P3(n)&&(F(n,"_generator")===null&&Reflect.set(n,"_generator",new zc(e.renderer)),F(n,"_pmrem")===null)){let i=F(n,"updateBefore");typeof i=="function"&&i.call(n,{renderer:e.renderer})}if(F(n,"isAnalyticLightNode")===!0){let i=F(n,"baseColorNode");ne(i)&&Reflect.set(n,"colorNode",i);let s=F(n,"light");if(ne(s)&&F(s,"castShadow")===!0&&F(e.object,"receiveShadow")===!0&&e.builder!==void 0){let o=F(n,"setupShadow");typeof o=="function"&&o.call(n,e.builder)}}let r=F(n,"isShadowNode")===!0?n:F(n,"shadowNode");if(ne(r)&&F(r,"shadowMap")===null&&e.builder!==void 0){let i=F(r,"setupShadow");if(typeof i=="function"){let s=i.call(r,e.builder);Reflect.set(r,"_node",s);let o=F(e.renderer,"shadowMap");ne(o)&&Reflect.set(r,"_currentShadowType",F(o,"type"))}}if(F(n,"isTextureNode")===!0){if(!F(n,"_matrixUniform")){let i=F(n,"value"),s=ne(i)?F(i,"matrix"):void 0;ne(s)&&(Reflect.set(n,"_matrixUniform",Bd(s)),Reflect.set(n,"updateType","object"))}F(n,"_flipYUniform")||(Reflect.set(n,"_flipYUniform",Bd(!1)),Reflect.set(n,"updateType","object"))}if(F(n,"isViewportNode")===!0&&!F(n,"_output")){let i=F(n,"setup");typeof i=="function"&&i.call(n)}}function G3(n,e){if(F(n,"isArrayBufferNode")!==!0||F(n,"value")!==null)return;let t=F(n,"array"),r=F(n,"elementType"),i=F(n,"paddedType"),s=F(e,"getTypeLength");if(!Array.isArray(t)||typeof r!="string"||typeof i!="string"||typeof s!="function")throw new Error("Three.js r185 UniformArrayNode internals drifted.");let o=s.call(e,i),a=r.startsWith("i")?Int32Array:r.startsWith("u")?Uint32Array:Float32Array;Reflect.set(n,"value",new a(t.length*o)),Reflect.set(n,"bufferCount",t.length),Reflect.set(n,"bufferType",i);let l=F(n,"update");typeof l=="function"&&l.call(n)}function Q1(n){let e=r=>F(n,r)===!0,t=ne(F(n,"textureNode"))||ne(F(n,"nodeUniform"));return e("isNodeUniformsGroup")?"NodeUniformsGroup":e("isUniformsGroup")?"UniformsGroup":e("isNodeUniformBuffer")?"NodeUniformBuffer":e("isUniformBuffer")?"UniformBuffer":e("isStorageBuffer")?t?"NodeStorageBuffer":"StorageBuffer":e("isSampledCubeTexture")?t?"NodeSampledCubeTexture":"SampledCubeTexture":e("isSampledTexture3D")?"NodeSampledTexture3D":e("isSampled3DTexture")?"Sampled3DTexture":e("isSampledArrayTexture")?t?"NodeSampledArrayTexture":"SampledArrayTexture":e("isSampledTexture")?t?"NodeSampledTexture":"SampledTexture":e("isSampler")?t?"NodeSampler":"Sampler":n.kind??n.constructor?.name??""}function z3(n){return["getUniformFromNode","sortBindingGroups","getBindings"].every(e=>typeof F(n,e)=="function")}function $3(n){if(!ne(n))throw new Error("Three.js r185 did not create a binding builder.");if(!z3(n))throw new Error("Three.js r185 builder is missing its binding methods.");return n}function X1(n){if(n===null)return[];let e=[],t=F(n,"traverse");return typeof t=="function"&&t.call(n,r=>{ne(r)&&F(r,"isLight")===!0&&e.push(r)}),e}function Z1(n){let e=new WeakMap;K1(n.threeVersion);let t=new Map,r=new Map,i=new WeakMap,s=new Map,o=new WeakMap,a=new WeakMap,l=b=>{let S=F(b.object,"geometry");if(!ne(S))throw new Error("The morph-target texture recipe requires render-object geometry.");let T=F(S,"attributes"),M=F(S,"morphAttributes");if(!ne(T)||!ne(M))throw new Error("The morph-target geometry has no attributes.");let B=F(T,"position"),D=F(M,"position"),O=F(M,"normal"),z=F(M,"color"),Q=Array.isArray(D)?D:[],oe=Array.isArray(O)?O:[],H=Array.isArray(z)?z:[],ae=Q.length>0?Q:oe.length>0?oe:H,de=ne(B)?F(B,"count"):void 0;if(ae.length===0||!Number.isSafeInteger(de)||Number(de)<0)throw new Error("The morph-target texture recipe received incompatible geometry.");let me=o.get(S);if(me?.count===ae.length)return me.node;me?.dispose();let Ae=H.length>0?3:oe.length>0?2:1,ge=Number(de)*Ae,Oe=1;ge>4096&&(Oe=Math.ceil(ge/4096),ge=4096);let Ge=new Float32Array(ge*Oe*4*ae.length),He=new pe;for(let zt=0;zt<ae.length;zt++){let Qi=Q[zt],en=oe[zt],ps=H[zt];if(Q.length>0&&!ne(Qi))throw new Error(`Morph position layer ${zt} is absent.`);if(oe.length>0&&!ne(en))throw new Error(`Morph normal layer ${zt} is absent.`);if(H.length>0&&!ne(ps))throw new Error(`Morph color layer ${zt} is absent.`);let Bg=ne(Qi)?F(Qi,"count"):ne(en)?F(en,"count"):ne(ps)?F(ps,"count"):void 0;if(!Number.isSafeInteger(Bg)||Number(Bg)!==Number(de))throw new Error(`Morph target layer ${zt} has an incompatible vertex count.`);let J1=ge*Oe*4*zt;for(let el=0;el<Number(Bg);el++){let Au=J1+el*Ae*4;if(ne(Qi)&&(He.fromBufferAttribute(Qi,el),Ge[Au]=He.x,Ge[Au+1]=He.y,Ge[Au+2]=He.z),ne(en)){He.fromBufferAttribute(en,el);let Vn=Au+4;Ge[Vn]=He.x,Ge[Vn+1]=He.y,Ge[Vn+2]=He.z}if(ne(ps)){He.fromBufferAttribute(ps,el);let Vn=Au+8;Ge[Vn]=He.x,Ge[Vn+1]=He.y,Ge[Vn+2]=He.z,Ge[Vn+3]=F(ps,"itemSize")===4?He.w:1}}}let Lr=new Ta(Ge,ge,Oe,ae.length);Lr.type=ze,Lr.needsUpdate=!0;let li=Dt(Qt("textureLoad")(Lr),"morph textureLoad()"),vu=F(S,"addEventListener"),Ja,Js=()=>{Lr.dispose(),o.get(S)===Ja&&o.delete(S);let zt=F(S,"removeEventListener");typeof zt=="function"&&zt.call(S,"dispose",Js)};return Ja={count:ae.length,node:li,dispose:Js},o.set(S,Ja),typeof vu=="function"&&vu.call(S,"dispose",Js),li},u=b=>{if(b.lightsNode===null)throw new Error("The render object has no LightsNode.");let S=F(b.lightsNode,"getLightNodes");if(typeof S!="function")throw new Error("Three.js r185 LightsNode internals drifted.");let T={renderer:b.renderer,context:{materialLightings:[]},getDataFromNode(B){let D=a.get(B);return D===void 0&&(D={},a.set(B,D)),D}},M=S.call(b.lightsNode,T);if(!Array.isArray(M))throw new Error("Three.js r185 LightsNode returned no light list.");return M.map((B,D)=>Dt(B,`light node ${D}`))},c=b=>{if(!ne(b))return r;let S=i.get(b);return S===void 0&&(S=new Map,i.set(b,S)),S},d=new Set(["texture","cubeTexture","texture3D","storageTexture","pmremTexture"]),h=new WeakMap,p=0,f=(b,S,T,M)=>{let B=b.nodeClass;if(d.has(B)&&ne(S)){let Q=h.get(S);Q===void 0&&(Q=p++,h.set(S,Q)),M=`${M}\0v${Q}`}let D=T.get(M);if(D!==void 0)return D;let O;switch(B){case"uniform":O=b.uniformType?Qt("uniform")(S,b.uniformType):Qt("uniform")(S);break;case"buffer":O=Qt("buffer")(S,b.uniformType,b.bufferCount??0);break;case"bufferAttribute":O=Qt("bufferAttribute")(b.instanced===!0&&L3(S)&&(b.stride??0)>0?new Aa(S,b.stride??0,1):S,b.uniformType??null,b.stride??0,b.offset??0);break;case"texture":case"cubeTexture":case"texture3D":case"storageTexture":case"pmremTexture":O=Qt(B)(S);break;case"textureReference":case"cubeTextureReference":{let Q=Dt(S,`${B} input`),oe=B==="textureReference"?"texture":"cubeTexture";O=Qt(oe)(Reflect.get(Q,"value")),Reflect.set(Dt(O,`${oe}()`),"referenceNode",Q);break}case"uniformArray":O=Qt("uniformArray")(S,b.uniformType);break;case"storage":O=Qt("storage")(S,b.uniformType??null,b.bufferCount??0);break;case"viewportMipTexture":O=Qt("viewportMipTexture")();break;default:throw new Error(`Unknown Three.js r185 input recipe "${B}".`)}let z=Dt(O,`${B}()`);if(b.group!==void 0){let Q=Ed(b.group);if(Q===void 0||!z.setGroup)throw new Error(`Three.js r185 input recipe lost TSL group "${b.group}".`);z.setGroup(Dt(Q,`TSL group "${b.group}"`))}return b.comparison===!0&&Reflect.set(z,"compareNode",Dt(Qt("float")(0),"float()")),b.access&&z.setAccess&&z.setAccess(b.access),b.atomic!==void 0&&z.setAtomic&&z.setAtomic(b.atomic),b.pbo!==void 0&&z.setPBO&&z.setPBO(b.pbo),b.usage!==void 0&&z.setUsage&&z.setUsage(b.usage),b.instanced!==void 0&&z.setInstanced&&z.setInstanced(b.instanced),T.set(M,z),z},m=(b,S)=>{let T=JSON.stringify(b),M,B=r;if(b.k==="inputValue")M=O3(b.json);else{let D=Ng(b.value.container,S);if(D===void 0)throw new Error(`Input container "${b.value.container}" is absent.`);if(B=c(D),D3(D,b.value.path,S),M=Sg(D,b.value.path),M==null)throw new Error(`Input path in "${b.value.container}" is absent.`)}return f(b,M,B,T)},g=(b,S,T)=>{let M=b.split(":"),B=S.split(":");if(M.length!==6||B.length!==6||![0,1,2,4,5].every(O=>M[O]===B[O]))return!1;if(T===void 0)return!0;let D=Number(B[3]);return Number.isSafeInteger(D)&&D>=0?D===T:!0},x=b=>{let S=F(b.renderer,"_renderContexts"),T=ne(S)?F(S,"_renderContexts"):void 0;if(!ne(T))throw new Error("Three.js r185 render-context cache is absent.");return T},w=(b,S)=>{if(!ne(b))return!1;for(let[T,M]of Object.entries(S)){if(T==="name"||T==="samples")continue;let B=F(b,T);if(typeof M=="boolean"){if(B===!0!==M)return!1}else if(M===null?B!=null:B!==M)return!1}return!0},v=b=>{if(!ne(b)||typeof F(b,"nodeClass")!="string")throw new Error("The render-context input recipe has invalid node options.");for(let T of["access","uniformType"]){let M=F(b,T);if(M!=null&&typeof M!="string")throw new Error(`The render-context input recipe has invalid ${T}.`)}let S=F(b,"group");if(S!==void 0&&typeof S!="string")throw new Error("The render-context input recipe has an invalid group.");for(let T of["comparison","atomic","pbo","instanced"]){let M=F(b,T);if(M!==void 0&&typeof M!="boolean")throw new Error(`The render-context input recipe has invalid ${T}.`)}for(let T of["bufferCount","stride","offset","usage","n"]){let M=F(b,T);if(M!==void 0&&!Number.isSafeInteger(M))throw new Error(`The render-context input recipe has invalid ${T}.`)}return b},E=(b,S)=>{let T=b.input;if(!ne(T))throw new Error("The render-context input recipe has no signature.");let M=F(T,"attachmentState"),B=F(T,"callDepth"),D=F(T,"mrt"),O=F(T,"resource"),z=F(T,"index"),Q=F(T,"texture"),oe=v(F(T,"node")),H=ne(Q)?F(Q,"samples"):void 0;if(typeof M!="string"||!Number.isSafeInteger(B)||typeof D!="boolean"||O!=="texture"&&O!=="depthTexture"||O==="texture"&&(!Number.isSafeInteger(z)||Number(z)<0)||!ne(Q)||H!==void 0&&(!Number.isSafeInteger(H)||Number(H)<0))throw new Error("The render-context input signature is invalid.");let ae=x(S),de=[];for(let[Ge,He]of Object.entries(ae)){let Lr=/^(.*)-([^-]+)-(-?\d+)$/u.exec(Ge);if(Lr?.[1]===void 0||Lr[2]===void 0||Number(Lr[3])!==B||Lr[2]!=="default"!==D||!g(M,Lr[1],H)||!ne(He))continue;let li=O==="depthTexture"?F(He,"depthTexture"):Array.isArray(F(He,"textures"))?F(He,"textures")[Number(z)]:void 0;ne(li)&&w(li,Q)&&!de.includes(li)&&de.push(li)}let me=F(Q,"name"),Ae=typeof me=="string"?de.filter(Ge=>F(Ge,"name")===me):[],ge=Ae.length===1?Ae:de;if(ge.length!==1)throw new Error(`Three.js r185 matching render-context ${String(O)} is ${ge.length===0?"absent":"ambiguous"} (available: ${Object.keys(ae).slice(0,8).join(", ")||"none"}).`);let Oe=ge[0];return f(oe,Oe,c(Oe),JSON.stringify(b))};return{id:vg,threeVersion:n.threeVersion,supportsManifest(b){return b.three===n.threeVersion&&b.runtime?.id===vg&&b.runtime.address===1&&b.runtime.recipe===1&&b.runtime.hydration===1},isWebGPU(b){return b.backend?.isWebGPUBackend===!0},anchorsFor(b,S){if(S==="compute"){let M=Dt(b,"compute registration");return k3(M),[{slot:"compute",node:M}]}let T=[];for(let M of Y1){let B=F(b,M);if(ne(B))try{T.push({slot:M,node:Dt(B,`material.${M}`)})}catch{}}return T},createBindingBuilder(b){let S=b.renderer.backend;if(typeof S?.createNodeBuilder!="function")throw new Error("Three.js r185 WebGPU backend has no createNodeBuilder().");let T=$3(S.createNodeBuilder(b.object,b.renderer));if(b.renderObject!==void 0)for(let M of["camera","clippingContext"]){let B=F(b.renderObject,M);B!==void 0&&Reflect.set(T,M,B)}return T},getBindings(b,S){let T=S.renderer,M="_currentRenderContext",B=Object.prototype.hasOwnProperty.call(T,M),D=T[M];T[M]=b;try{return b.sortBindingGroups(),b.getBindings()}finally{B?T[M]=D:delete T[M]}},resolveRecipeAddress(b,S){switch(b.k){case"tsl":{let T=Dt(Ed(b.name),`TSL export "${b.name}"`);return HN(T,S),T}case"namedRenderUniform":{let T=t.get(b.name);return T===void 0&&(T=U3(b.name),t.set(b.name,T)),T}case"materialCache":{let T=new $y(b.property),M=F(T,"getCache");if(typeof M!="function")throw new Error("Three.js r185 MaterialNode.getCache() is unavailable.");return Dt(M.call(T,b.property,b.type),`material cache "${b.property}"`)}case"sceneEnv":{if(S.scene===null)throw new Error("The shader entry requires a scene environment.");let T=S.renderer._nodes,M=T?.getEnvironmentNode;if(typeof M!="function")throw new Error("Three.js r185 environment-node API drifted.");return Dt(M.call(T,S.scene),"scene environment")}case"reference":{let T=JSON.stringify(b),M=s.get(T);if(M!==void 0)return M;let B;if(b.object!==void 0){let z=Ng(b.object.container,S);if(z===void 0)throw new Error(`Reference container "${b.object.container}" is absent.`);if(B=Sg(z,b.object.path),B==null)throw new Error(`Reference object path in "${b.object.container}" is absent.`)}let D=b.count===void 0?Qt("reference")(b.property,b.uniformType,B):Qt("referenceBuffer")(b.property,b.uniformType,b.count,B),O=Dt(D,"reference()");if(b.group!==void 0){let z=Dt(Ed(b.group),`TSL group "${b.group}"`);if(!O.setGroup)throw new Error("Three.js r185 reference node lost setGroup().");O.setGroup(z)}if(b.name!==void 0){if(!O.setName)throw new Error("Three.js r185 reference node lost setName().");O.setName(b.name)}return s.set(T,O),O}case"lightNode":{let T=b.sceneLight===void 0?u(S)[b.light]:void 0;if(b.sceneLight!==void 0){let M=X1(S.scene)[b.sceneLight],B=F(S.renderer,"library"),D=ne(B)?F(B,"getLightNodeClass"):void 0,O=typeof D=="function"&&ne(M)?D.call(B,F(M,"constructor")):void 0;typeof O=="function"&&ne(M)&&(T=Dt(new O(M),`scene light node ${b.sceneLight}`))}if(T===void 0)throw new Error(`Light index ${b.light} is absent.`);return T}case"lightUniform":{let T=b.sceneLight===void 0?u(S)[b.light]:void 0,M=b.sceneLight===void 0?T?F(T,"light"):void 0:X1(S.scene)[b.sceneLight];if(!ne(M))throw new Error(`Light index ${b.light} has no light object.`);return Dt(Qt(b.fn)(M),`${b.fn}()`)}case"inputNode":case"inputValue":return m(b,S);case"recipe":{if(b.id==="three-r185-morph-target-texture")return l(S);if(b.id==="three-r185-render-context-input")return E(b,S);if(b.id==="three-r185-render-context-mrt"){let M=b.input;if(!ne(M))throw new Error("The render-context MRT recipe has no signature.");let B=F(M,"attachmentState"),D=F(M,"callDepth"),O=F(M,"samples");if(typeof B!="string"||!Number.isSafeInteger(D)||O!==void 0&&(!Number.isSafeInteger(O)||Number(O)<0))throw new Error("The render-context MRT signature is invalid.");let z=x(S);for(let[Q,oe]of Object.entries(z)){let H=/^(.*)-[^-]+-(-?\d+)$/u.exec(Q);if(H?.[1]===void 0||Number(H[2])!==D||!g(B,H[1],O)||!ne(oe))continue;let ae=F(oe,"mrt");if(ne(ae)&&F(ae,"isNode")===!0)return Dt(ae,"render-context MRT")}throw new Error(`Three.js r185 matching render-context MRT is absent (available: ${Object.keys(z).slice(0,8).join(", ")||"none"}).`)}if(b.id==="three-r185-max-mip"){let M=JSON.stringify(b),B=s.get(M);if(B!==void 0)return B;if(!ne(b.input))throw new Error("The max-mip recipe has no texture address.");let D=Fo(b.input,S,this),O=Dt(Qt("maxMipLevel")(D),"maxMipLevel()");return s.set(M,O),O}if(b.id==="three-r185-morph-update-event"){let M=b.input;if(!ne(M))throw new Error("The morph-update event recipe has no signature.");let B=F(M,"base"),D=F(M,"influences"),O=F(M,"count"),z=F(S.object,"morphTargetInfluences");if(!ne(B)||!ne(D)||!Number.isSafeInteger(O)||Number(O)<1||!Array.isArray(z)||z.length!==O)throw new Error("The morph-update event signature is invalid for the render object.");let Q=Fo(B,S,this),oe=Fo(D,S,this);if(F(Q,"isUniformNode")!==!0||F(oe,"isArrayBufferNode")!==!0||F(oe,"array")!==z)throw new Error("The morph-update event did not resolve its captured uniform nodes.");return new sf("object",H=>{let ae=F(H,"object"),de=ne(ae)?F(ae,"morphTargetInfluences"):void 0,me=ne(ae)?F(ae,"geometry"):void 0;if(!Array.isArray(de)||!ne(me))return;let Ae=de.reduce((Oe,Ge)=>Oe+Ge,0);Reflect.set(Q,"value",F(me,"morphTargetsRelative")?1:1-Ae),Reflect.set(oe,"array",de);let ge=F(oe,"update");typeof ge=="function"&&ge.call(oe)})}if(b.id==="three-r185-skinning-event")return new sf("object",M=>{let B=F(M,"object"),D=ne(B)?F(B,"skeleton"):void 0;if(!ne(D))return;let O=F(M,"frameId");if(O!==void 0&&e.get(D)===O)return;O!==void 0&&e.set(D,O);let z=F(D,"update");typeof z=="function"&&z.call(D)});let T=n.recipes?.[b.id];if(T===void 0)throw new Error(`No Three.js r185 recipe is registered for "${b.id}".`);return T({address:b,context:S})}}},primeOwnedAddress:HN,primeBindingNode:G3,cloneBindingNode(b){let S=F(b,"clone");if(typeof S=="function")return Dt(S.call(b),"cloned binding node");if(F(b,"isArrayBufferNode")===!0&&Array.isArray(F(b,"array"))){let T=F(b,"elementType"),M=Dt(Qt("uniformArray")(F(b,"array"),typeof T=="string"?T:null),"cloned uniform array"),B=F(b,"groupNode");return ne(B)&&M.setGroup&&M.setGroup(B),M}if(F(b,"isUniformNode")===!0){let T=F(b,"nodeType"),M=Bd(F(b,"value"),typeof T=="string"?T:void 0),B=F(b,"groupNode");ne(B)&&M.setGroup&&M.setGroup(B);let D=F(b,"name");typeof D=="string"&&D.length>0&&M.setName&&M.setName(D);for(let O of["updateType","updateBeforeType","updateAfterType"])Reflect.set(M,O,F(b,O));return M}throw new Error("Three.js r185 setup-owned binding node is not cloneable.")},createAttribute(b,S,T,M){if(T&&F(T,"isBufferNode")===!0&&F(T,"attribute")===null){let B=F(T,"setup");typeof B=="function"&&B.call(T,M)}return{isNodeAttribute:!0,name:b,type:S,node:T}},createObserver(b,S){if(S.material===null)return null;let T=new Hu({material:S.material,object:S.object,context:{}});return Object.assign(T,b.observer? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment