@react-three/drei 9.51.10 → 9.51.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("@babel/runtime/helpers/extends"),e=require("three"),t=require("react"),o=require("@react-three/fiber"),a=require("./useFBO.cjs.js");function r(n){return n&&"object"==typeof n&&"default"in n?n:{default:n}}function i(n){if(n&&n.__esModule)return n;var e=Object.create(null);return n&&Object.keys(n).forEach((function(t){if("default"!==t){var o=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:function(){return n[t]}})}})),e.default=n,Object.freeze(e)}var s=r(n),l=i(e),c=i(t);class m extends l.MeshPhysicalMaterial{constructor({samples:n=6,...e}={}){super(e),this.uniforms={chromaticAberration:{value:.05},transmission:{value:1},thickness:{value:1},anisotropy:{value:.1},time:{value:0},distortion:{value:0},distortionScale:{value:.5},temporalDistortion:{value:.5},buffer:{value:null},resolution:{value:new l.Vector2}},this.onBeforeCompile=e=>{e.uniforms={...e.uniforms,...this.uniforms},e.fragmentShader="\n uniform float chromaticAberration;\n uniform vec2 resolution; \n uniform float anisotropy; \n uniform float time;\n uniform float distortion;\n uniform float distortionScale;\n uniform float temporalDistortion;\n uniform sampler2D buffer;\n \n vec3 sat(vec3 rgb, float adjustment) {\n const vec3 W = vec3(0.2125, 0.7154, 0.0721);\n vec3 intensity = vec3(dot(rgb, W));\n return mix(intensity, rgb, adjustment);\n }\n vec3 random3(vec3 c) {\n float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));\n vec3 r;\n r.z = fract(512.0*j);\n j *= .125;\n r.x = fract(512.0*j);\n j *= .125;\n r.y = fract(512.0*j);\n return r-0.5;\n }\n\n float seed = 0.0;\n uint hash( uint x ) {\n x += ( x << 10u );\n x ^= ( x >> 6u );\n x += ( x << 3u );\n x ^= ( x >> 11u );\n x += ( x << 15u );\n return x;\n }\n\n // Compound versions of the hashing algorithm I whipped together.\n uint hash( uvec2 v ) { return hash( v.x ^ hash(v.y) ); }\n uint hash( uvec3 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ); }\n uint hash( uvec4 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ^ hash(v.w) ); }\n\n // Construct a float with half-open range [0:1] using low 23 bits.\n // All zeroes yields 0.0, all ones yields the next smallest representable value below 1.0.\n float floatConstruct( uint m ) {\n const uint ieeeMantissa = 0x007FFFFFu; // binary32 mantissa bitmask\n const uint ieeeOne = 0x3F800000u; // 1.0 in IEEE binary32\n\n m &= ieeeMantissa; // Keep only mantissa bits (fractional part)\n m |= ieeeOne; // Add fractional part to 1.0\n\n float f = uintBitsToFloat( m ); // Range [1:2]\n return f - 1.0; // Range [0:1]\n }\n\n // Pseudo-random value in half-open range [0:1].\n float random( float x ) { return floatConstruct(hash(floatBitsToUint(x))); }\n float random( vec2 v ) { return floatConstruct(hash(floatBitsToUint(v))); }\n float random( vec3 v ) { return floatConstruct(hash(floatBitsToUint(v))); }\n float random( vec4 v ) { return floatConstruct(hash(floatBitsToUint(v))); }\n\n float rand() {\n float result = random(vec3(gl_FragCoord.xy, seed));\n seed += 1.0;\n return result;\n }\n\n const float F3 = 0.3333333;\n const float G3 = 0.1666667;\n\n float snoise(vec3 p) {\n vec3 s = floor(p + dot(p, vec3(F3)));\n vec3 x = p - s + dot(s, vec3(G3));\n vec3 e = step(vec3(0.0), x - x.yzx);\n vec3 i1 = e*(1.0 - e.zxy);\n vec3 i2 = 1.0 - e.zxy*(1.0 - e);\n vec3 x1 = x - i1 + G3;\n vec3 x2 = x - i2 + 2.0*G3;\n vec3 x3 = x - 1.0 + 3.0*G3;\n vec4 w, d;\n w.x = dot(x, x);\n w.y = dot(x1, x1);\n w.z = dot(x2, x2);\n w.w = dot(x3, x3);\n w = max(0.6 - w, 0.0);\n d.x = dot(random3(s), x);\n d.y = dot(random3(s + i1), x1);\n d.z = dot(random3(s + i2), x2);\n d.w = dot(random3(s + 1.0), x3);\n w *= w;\n w *= w;\n d *= w;\n return dot(d, vec4(52.0));\n }\n\n float snoiseFractal(vec3 m) {\n return 0.5333333* snoise(m)\n +0.2666667* snoise(2.0*m)\n +0.1333333* snoise(4.0*m)\n +0.0666667* snoise(8.0*m);\n }\n"+e.fragmentShader,e.fragmentShader=e.fragmentShader.replace("#include <transmission_pars_fragment>","\n #ifdef USE_TRANSMISSION\n // Transmission code is based on glTF-Sampler-Viewer\n // https://github.com/KhronosGroup/glTF-Sample-Viewer\n uniform float transmission;\n uniform float thickness;\n uniform float attenuationDistance;\n uniform vec3 attenuationColor;\n #ifdef USE_TRANSMISSIONMAP\n uniform sampler2D transmissionMap;\n #endif\n #ifdef USE_THICKNESSMAP\n uniform sampler2D thicknessMap;\n #endif\n uniform vec2 transmissionSamplerSize;\n uniform sampler2D transmissionSamplerMap;\n uniform mat4 modelMatrix;\n uniform mat4 projectionMatrix;\n varying vec3 vWorldPosition;\n vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n // Direction of refracted light.\n vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n // Compute rotation-independant scaling of the model matrix.\n vec3 modelScale;\n modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n // The thickness is specified in local space.\n return normalize( refractionVector ) * thickness * modelScale;\n }\n float applyIorToRoughness( const in float roughness, const in float ior ) {\n // Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and\n // an IOR of 1.5 results in the default amount of microfacet refraction.\n return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n }\n vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n return texture2D(buffer, fragCoord.xy);\n }\n vec3 applyVolumeAttenuation( const in vec3 radiance, const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n if ( isinf( attenuationDistance ) ) {\n // Attenuation distance is +∞, i.e. the transmitted color is not attenuated at all.\n return radiance;\n } else {\n // Compute light attenuation using Beer's law.\n vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); // Beer's law\n return transmittance * radiance;\n }\n }\n vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness,\n const in vec3 attenuationColor, const in float attenuationDistance ) {\n vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n vec3 refractedRayExit = position + transmissionRay;\n // Project refracted vector on the framebuffer, while mapping to normalized device coordinates.\n vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n vec2 refractionCoords = ndcPos.xy / ndcPos.w;\n refractionCoords += 1.0;\n refractionCoords /= 2.0;\n // Sample framebuffer to get pixel the refracted ray hits.\n vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n vec3 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );\n // Get the specular component.\n vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n return vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );\n }\n #endif\n"),e.fragmentShader=e.fragmentShader.replace("#include <transmission_fragment>",`\n vec2 uv = gl_FragCoord.xy / resolution.xy; \n // Improve the refraction to use the world pos\n material.transmission = transmission;\n material.transmissionAlpha = 1.0;\n material.thickness = thickness;\n material.attenuationDistance = attenuationDistance;\n material.attenuationColor = attenuationColor;\n #ifdef USE_TRANSMISSIONMAP\n material.transmission *= texture2D( transmissionMap, vUv ).r;\n #endif\n #ifdef USE_THICKNESSMAP\n material.thickness *= texture2D( thicknessMap, vUv ).g;\n #endif\n \n vec3 pos = vWorldPosition;\n vec3 v = normalize( cameraPosition - pos );\n vec3 n = inverseTransformDirection( normal, viewMatrix );\n vec3 transmission = vec3(0.0);\n float transmissionR, transmissionB, transmissionG;\n float randomCoords = rand();\n float thickness_smear = thickness * max(pow(roughness, 0.33), anisotropy);\n vec3 distortionNormal = vec3(0.0);\n vec3 temporalOffset = vec3(time, -time, -time) * temporalDistortion;\n if (distortion > 0.0) {\n distortionNormal = distortion * vec3(snoiseFractal(vec3((pos * distortionScale + temporalOffset))), snoiseFractal(vec3(pos.zxy * distortionScale - temporalOffset)), snoiseFractal(vec3(pos.yxz * distortionScale + temporalOffset)));\n }\n for (float i = 0.0; i < ${n}.0; i ++) {\n vec3 sampleNorm = normalize(n + roughness * roughness * 2.0 * normalize(vec3(rand() - 0.5, rand() - 0.5, rand() - 0.5)) * pow(rand(), 0.33) + distortionNormal);\n transmissionR = getIBLVolumeRefraction(\n sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior, material.thickness + thickness_smear * (i + randomCoords) / float(${n}),\n material.attenuationColor, material.attenuationDistance\n ).r;\n transmissionG = getIBLVolumeRefraction(\n sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior * (1.0 + chromaticAberration * (i + randomCoords) / float(${n})) , material.thickness + thickness_smear * (i + randomCoords) / float(${n}),\n material.attenuationColor, material.attenuationDistance\n ).g;\n transmissionB = getIBLVolumeRefraction(\n sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior * (1.0 + 2.0 * chromaticAberration * (i + randomCoords) / float(${n})), material.thickness + thickness_smear * (i + randomCoords) / float(${n}),\n material.attenuationColor, material.attenuationDistance\n ).b;\n transmission.r += transmissionR;\n transmission.g += transmissionG;\n transmission.b += transmissionB;\n }\n transmission /= ${n}.0;\n material.transmissionAlpha = 1.0;\n totalDiffuse = mix( totalDiffuse, transmission.rgb, material.transmission );\n`)},Object.keys(this.uniforms).forEach((n=>Object.defineProperty(this,n,{get:()=>this.uniforms[n].value,set:e=>this.uniforms[n].value=e})))}}const u=c.forwardRef((({buffer:n,distortionSpeed:e=1,samples:t=10,resolution:r,background:i,...l},u)=>{o.extend({MeshTransmissionMaterial:m});const f=c.useRef(null),{size:d,viewport:v}=o.useThree(),h=a.useFBO(r);let p,x,g;return o.useFrame((t=>{n||(g=f.current.__r3f.parent,f.current.time=t.clock.getElapsedTime()*e,g&&(x=g.visible,g.visible=!1,t.gl.setRenderTarget(h),p=t.scene.background,i&&(t.scene.background=i),t.gl.render(t.scene,t.camera),t.scene.background=p,t.gl.setRenderTarget(null),g.visible=x))})),c.useImperativeHandle(u,(()=>f.current),[]),c.createElement("meshTransmissionMaterial",s.default({args:[c.useMemo((()=>({samples:t})),[t])],ref:f,buffer:n||h.texture,resolution:[d.width*v.dpr,d.height*v.dpr]},l))}));exports.MeshTransmissionMaterial=u;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("@babel/runtime/helpers/extends"),e=require("three"),t=require("react"),a=require("@react-three/fiber"),o=require("./useFBO.cjs.js");function r(n){return n&&"object"==typeof n&&"default"in n?n:{default:n}}function i(n){if(n&&n.__esModule)return n;var e=Object.create(null);return n&&Object.keys(n).forEach((function(t){if("default"!==t){var a=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,a.get?a:{enumerable:!0,get:function(){return n[t]}})}})),e.default=n,Object.freeze(e)}var s=r(n),l=i(e),c=i(t);class m extends l.MeshPhysicalMaterial{constructor({samples:n=6,...e}={}){super(e),this.uniforms={chromaticAberration:{value:.05},transmission:{value:0},_transmission:{value:1},transmissionMap:{value:null},thickness:{value:1},thicknessMap:{value:null},attenuationDistance:{value:0},attenuationColor:{value:new l.Color},anisotropy:{value:.1},time:{value:0},distortion:{value:0},distortionScale:{value:.5},temporalDistortion:{value:.5},buffer:{value:null},resolution:{value:new l.Vector2}},this.onBeforeCompile=e=>{e.uniforms={...e.uniforms,...this.uniforms},e.defines.USE_TRANSMISSION="",e.fragmentShader="\n uniform float chromaticAberration;\n uniform vec2 resolution; \n uniform float anisotropy; \n uniform float time;\n uniform float distortion;\n uniform float distortionScale;\n uniform float temporalDistortion;\n uniform sampler2D buffer;\n \n vec3 sat(vec3 rgb, float adjustment) {\n const vec3 W = vec3(0.2125, 0.7154, 0.0721);\n vec3 intensity = vec3(dot(rgb, W));\n return mix(intensity, rgb, adjustment);\n }\n vec3 random3(vec3 c) {\n float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));\n vec3 r;\n r.z = fract(512.0*j);\n j *= .125;\n r.x = fract(512.0*j);\n j *= .125;\n r.y = fract(512.0*j);\n return r-0.5;\n }\n\n float seed = 0.0;\n uint hash( uint x ) {\n x += ( x << 10u );\n x ^= ( x >> 6u );\n x += ( x << 3u );\n x ^= ( x >> 11u );\n x += ( x << 15u );\n return x;\n }\n\n // Compound versions of the hashing algorithm I whipped together.\n uint hash( uvec2 v ) { return hash( v.x ^ hash(v.y) ); }\n uint hash( uvec3 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ); }\n uint hash( uvec4 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ^ hash(v.w) ); }\n\n // Construct a float with half-open range [0:1] using low 23 bits.\n // All zeroes yields 0.0, all ones yields the next smallest representable value below 1.0.\n float floatConstruct( uint m ) {\n const uint ieeeMantissa = 0x007FFFFFu; // binary32 mantissa bitmask\n const uint ieeeOne = 0x3F800000u; // 1.0 in IEEE binary32\n\n m &= ieeeMantissa; // Keep only mantissa bits (fractional part)\n m |= ieeeOne; // Add fractional part to 1.0\n\n float f = uintBitsToFloat( m ); // Range [1:2]\n return f - 1.0; // Range [0:1]\n }\n\n // Pseudo-random value in half-open range [0:1].\n float random( float x ) { return floatConstruct(hash(floatBitsToUint(x))); }\n float random( vec2 v ) { return floatConstruct(hash(floatBitsToUint(v))); }\n float random( vec3 v ) { return floatConstruct(hash(floatBitsToUint(v))); }\n float random( vec4 v ) { return floatConstruct(hash(floatBitsToUint(v))); }\n\n float rand() {\n float result = random(vec3(gl_FragCoord.xy, seed));\n seed += 1.0;\n return result;\n }\n\n const float F3 = 0.3333333;\n const float G3 = 0.1666667;\n\n float snoise(vec3 p) {\n vec3 s = floor(p + dot(p, vec3(F3)));\n vec3 x = p - s + dot(s, vec3(G3));\n vec3 e = step(vec3(0.0), x - x.yzx);\n vec3 i1 = e*(1.0 - e.zxy);\n vec3 i2 = 1.0 - e.zxy*(1.0 - e);\n vec3 x1 = x - i1 + G3;\n vec3 x2 = x - i2 + 2.0*G3;\n vec3 x3 = x - 1.0 + 3.0*G3;\n vec4 w, d;\n w.x = dot(x, x);\n w.y = dot(x1, x1);\n w.z = dot(x2, x2);\n w.w = dot(x3, x3);\n w = max(0.6 - w, 0.0);\n d.x = dot(random3(s), x);\n d.y = dot(random3(s + i1), x1);\n d.z = dot(random3(s + i2), x2);\n d.w = dot(random3(s + 1.0), x3);\n w *= w;\n w *= w;\n d *= w;\n return dot(d, vec4(52.0));\n }\n\n float snoiseFractal(vec3 m) {\n return 0.5333333* snoise(m)\n +0.2666667* snoise(2.0*m)\n +0.1333333* snoise(4.0*m)\n +0.0666667* snoise(8.0*m);\n }\n"+e.fragmentShader,e.fragmentShader=e.fragmentShader.replace("#include <transmission_pars_fragment>","\n #ifdef USE_TRANSMISSION\n // Transmission code is based on glTF-Sampler-Viewer\n // https://github.com/KhronosGroup/glTF-Sample-Viewer\n uniform float _transmission;\n uniform float thickness;\n uniform float attenuationDistance;\n uniform vec3 attenuationColor;\n #ifdef USE_TRANSMISSIONMAP\n uniform sampler2D transmissionMap;\n #endif\n #ifdef USE_THICKNESSMAP\n uniform sampler2D thicknessMap;\n #endif\n uniform vec2 transmissionSamplerSize;\n uniform sampler2D transmissionSamplerMap;\n uniform mat4 modelMatrix;\n uniform mat4 projectionMatrix;\n varying vec3 vWorldPosition;\n vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n // Direction of refracted light.\n vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n // Compute rotation-independant scaling of the model matrix.\n vec3 modelScale;\n modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n // The thickness is specified in local space.\n return normalize( refractionVector ) * thickness * modelScale;\n }\n float applyIorToRoughness( const in float roughness, const in float ior ) {\n // Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and\n // an IOR of 1.5 results in the default amount of microfacet refraction.\n return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n }\n vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n return texture2D(buffer, fragCoord.xy);\n }\n vec3 applyVolumeAttenuation( const in vec3 radiance, const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n if ( isinf( attenuationDistance ) ) {\n // Attenuation distance is +∞, i.e. the transmitted color is not attenuated at all.\n return radiance;\n } else {\n // Compute light attenuation using Beer's law.\n vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); // Beer's law\n return transmittance * radiance;\n }\n }\n vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness,\n const in vec3 attenuationColor, const in float attenuationDistance ) {\n vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n vec3 refractedRayExit = position + transmissionRay;\n // Project refracted vector on the framebuffer, while mapping to normalized device coordinates.\n vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n vec2 refractionCoords = ndcPos.xy / ndcPos.w;\n refractionCoords += 1.0;\n refractionCoords /= 2.0;\n // Sample framebuffer to get pixel the refracted ray hits.\n vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n vec3 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );\n // Get the specular component.\n vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n return vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );\n }\n #endif\n"),e.fragmentShader=e.fragmentShader.replace("#include <transmission_fragment>",`\n vec2 uv = gl_FragCoord.xy / resolution.xy; \n // Improve the refraction to use the world pos\n material.transmission = _transmission;\n material.transmissionAlpha = 1.0;\n material.thickness = thickness;\n material.attenuationDistance = attenuationDistance;\n material.attenuationColor = attenuationColor;\n #ifdef USE_TRANSMISSIONMAP\n material.transmission *= texture2D( transmissionMap, vUv ).r;\n #endif\n #ifdef USE_THICKNESSMAP\n material.thickness *= texture2D( thicknessMap, vUv ).g;\n #endif\n \n vec3 pos = vWorldPosition;\n vec3 v = normalize( cameraPosition - pos );\n vec3 n = inverseTransformDirection( normal, viewMatrix );\n vec3 transmission = vec3(0.0);\n float transmissionR, transmissionB, transmissionG;\n float randomCoords = rand();\n float thickness_smear = thickness * max(pow(roughness, 0.33), anisotropy);\n vec3 distortionNormal = vec3(0.0);\n vec3 temporalOffset = vec3(time, -time, -time) * temporalDistortion;\n if (distortion > 0.0) {\n distortionNormal = distortion * vec3(snoiseFractal(vec3((pos * distortionScale + temporalOffset))), snoiseFractal(vec3(pos.zxy * distortionScale - temporalOffset)), snoiseFractal(vec3(pos.yxz * distortionScale + temporalOffset)));\n }\n for (float i = 0.0; i < ${n}.0; i ++) {\n vec3 sampleNorm = normalize(n + roughness * roughness * 2.0 * normalize(vec3(rand() - 0.5, rand() - 0.5, rand() - 0.5)) * pow(rand(), 0.33) + distortionNormal);\n transmissionR = getIBLVolumeRefraction(\n sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior, material.thickness + thickness_smear * (i + randomCoords) / float(${n}),\n material.attenuationColor, material.attenuationDistance\n ).r;\n transmissionG = getIBLVolumeRefraction(\n sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior * (1.0 + chromaticAberration * (i + randomCoords) / float(${n})) , material.thickness + thickness_smear * (i + randomCoords) / float(${n}),\n material.attenuationColor, material.attenuationDistance\n ).g;\n transmissionB = getIBLVolumeRefraction(\n sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior * (1.0 + 2.0 * chromaticAberration * (i + randomCoords) / float(${n})), material.thickness + thickness_smear * (i + randomCoords) / float(${n}),\n material.attenuationColor, material.attenuationDistance\n ).b;\n transmission.r += transmissionR;\n transmission.g += transmissionG;\n transmission.b += transmissionB;\n }\n transmission /= ${n}.0;\n totalDiffuse = mix( totalDiffuse, transmission.rgb, material.transmission );\n`)},Object.keys(this.uniforms).forEach((n=>Object.defineProperty(this,n,{get:()=>this.uniforms[n].value,set:e=>this.uniforms[n].value=e})))}}const u=c.forwardRef((({buffer:n,transmission:e=1,distortionSpeed:t=1,samples:r=10,resolution:i,background:l,...u},f)=>{a.extend({MeshTransmissionMaterial:m});const d=c.useRef(null),{size:v,viewport:h}=a.useThree(),p=o.useFBO(i);let x,g,C;return a.useFrame((e=>{n||(C=d.current.__r3f.parent,d.current.time=e.clock.getElapsedTime()*t,C&&(g=C.visible,C.visible=!1,e.gl.setRenderTarget(p),x=e.scene.background,l&&(e.scene.background=l),e.gl.render(e.scene,e.camera),e.scene.background=x,e.gl.setRenderTarget(null),C.visible=g))})),c.useImperativeHandle(f,(()=>d.current),[]),c.createElement("meshTransmissionMaterial",s.default({args:[c.useMemo((()=>({samples:r})),[r])],ref:d},u,{buffer:n||p.texture,_transmission:e,transmission:0,resolution:[v.width*h.dpr,v.height*h.dpr]}))}));exports.MeshTransmissionMaterial=u;
@@ -2,11 +2,12 @@ import * as THREE from 'three';
2
2
  import * as React from 'react';
3
3
  import { ReactThreeFiber } from '@react-three/fiber';
4
4
  declare type MeshTransmissionMaterialType = Omit<JSX.IntrinsicElements['meshPhysicalMaterial'], 'args'> & {
5
+ transmission?: number;
5
6
  chromaticAberration?: number;
6
7
  anisotropy?: number;
7
8
  distortion?: number;
8
- distortionScale?: number;
9
- temporalDistortion?: number;
9
+ distortionScale: Uniform<number>;
10
+ temporalDistortion: Uniform<number>;
10
11
  time?: number;
11
12
  resolution?: ReactThreeFiber.Vector2;
12
13
  buffer?: THREE.Texture;
@@ -14,6 +15,9 @@ declare type MeshTransmissionMaterialType = Omit<JSX.IntrinsicElements['meshPhys
14
15
  samples: number;
15
16
  }];
16
17
  };
18
+ interface Uniform<T> {
19
+ value: T;
20
+ }
17
21
  declare global {
18
22
  namespace JSX {
19
23
  interface IntrinsicElements {
@@ -14,12 +14,29 @@ class MeshTransmissionMaterialImpl extends THREE.MeshPhysicalMaterial {
14
14
  chromaticAberration: {
15
15
  value: 0.05
16
16
  },
17
+ // Transmission must always be 0
17
18
  transmission: {
19
+ value: 0
20
+ },
21
+ // Instead a workaround is used, see below for reasons why
22
+ _transmission: {
18
23
  value: 1
19
24
  },
25
+ transmissionMap: {
26
+ value: null
27
+ },
20
28
  thickness: {
21
29
  value: 1
22
30
  },
31
+ thicknessMap: {
32
+ value: null
33
+ },
34
+ attenuationDistance: {
35
+ value: 0
36
+ },
37
+ attenuationColor: {
38
+ value: new THREE.Color()
39
+ },
23
40
  anisotropy: {
24
41
  value: 0.1
25
42
  },
@@ -46,7 +63,8 @@ class MeshTransmissionMaterialImpl extends THREE.MeshPhysicalMaterial {
46
63
  this.onBeforeCompile = shader => {
47
64
  shader.uniforms = { ...shader.uniforms,
48
65
  ...this.uniforms
49
- }; // Head
66
+ };
67
+ shader.defines.USE_TRANSMISSION = ''; // Head
50
68
 
51
69
  shader.fragmentShader =
52
70
  /*glsl*/
@@ -149,7 +167,7 @@ class MeshTransmissionMaterialImpl extends THREE.MeshPhysicalMaterial {
149
167
  +0.2666667* snoise(2.0*m)
150
168
  +0.1333333* snoise(4.0*m)
151
169
  +0.0666667* snoise(8.0*m);
152
- }\n` + shader.fragmentShader; // Replace transmission
170
+ }\n` + shader.fragmentShader; // Remove transmission
153
171
 
154
172
  shader.fragmentShader = shader.fragmentShader.replace('#include <transmission_pars_fragment>',
155
173
  /*glsl*/
@@ -157,7 +175,7 @@ class MeshTransmissionMaterialImpl extends THREE.MeshPhysicalMaterial {
157
175
  #ifdef USE_TRANSMISSION
158
176
  // Transmission code is based on glTF-Sampler-Viewer
159
177
  // https://github.com/KhronosGroup/glTF-Sample-Viewer
160
- uniform float transmission;
178
+ uniform float _transmission;
161
179
  uniform float thickness;
162
180
  uniform float attenuationDistance;
163
181
  uniform vec3 attenuationColor;
@@ -220,13 +238,14 @@ class MeshTransmissionMaterialImpl extends THREE.MeshPhysicalMaterial {
220
238
  vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
221
239
  return vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );
222
240
  }
223
- #endif\n`);
241
+ #endif\n`); // Add refraction
242
+
224
243
  shader.fragmentShader = shader.fragmentShader.replace('#include <transmission_fragment>',
225
244
  /*glsl*/
226
245
  `
227
246
  vec2 uv = gl_FragCoord.xy / resolution.xy;
228
247
  // Improve the refraction to use the world pos
229
- material.transmission = transmission;
248
+ material.transmission = _transmission;
230
249
  material.transmissionAlpha = 1.0;
231
250
  material.thickness = thickness;
232
251
  material.attenuationDistance = attenuationDistance;
@@ -272,7 +291,6 @@ class MeshTransmissionMaterialImpl extends THREE.MeshPhysicalMaterial {
272
291
  transmission.b += transmissionB;
273
292
  }
274
293
  transmission /= ${samples}.0;
275
- material.transmissionAlpha = 1.0;
276
294
  totalDiffuse = mix( totalDiffuse, transmission.rgb, material.transmission );\n`);
277
295
  };
278
296
 
@@ -286,6 +304,7 @@ class MeshTransmissionMaterialImpl extends THREE.MeshPhysicalMaterial {
286
304
 
287
305
  const MeshTransmissionMaterial = /*#__PURE__*/React.forwardRef(({
288
306
  buffer,
307
+ transmission = 1,
289
308
  distortionSpeed = 1,
290
309
  samples = 10,
291
310
  resolution,
@@ -334,10 +353,16 @@ const MeshTransmissionMaterial = /*#__PURE__*/React.forwardRef(({
334
353
  args: [React.useMemo(() => ({
335
354
  samples
336
355
  }), [samples])],
337
- ref: ref,
338
- buffer: buffer || fbo.texture,
356
+ ref: ref
357
+ }, props, {
358
+ buffer: buffer || fbo.texture // @ts-ignore
359
+ ,
360
+ _transmission: transmission // In order for this to not incur extra cost "transmission" must be set to 0 and treated as a reserved prop.
361
+ // This is because THREE.WebGLRenderer will check for transmission > 0 and executed extra renders.
362
+ ,
363
+ transmission: 0,
339
364
  resolution: [size.width * viewport.dpr, size.height * viewport.dpr]
340
- }, props));
365
+ }));
341
366
  });
342
367
 
343
368
  export { MeshTransmissionMaterial };
package/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("react-dom/client"),n=require("three"),o=require("@react-three/fiber"),a=require("zustand"),i=require("react-merge-refs"),s=require("@react-spring/three"),l=require("@use-gesture/react"),c=require("zustand/middleware"),u=require("three-stdlib"),d=require("zustand/shallow"),m=require("troika-three-text"),f=require("suspend-react"),p=require("meshline"),h=require("lodash.pick"),v=require("lodash.omit"),g=require("stats.js"),x=require("detect-gpu"),y=require("three-mesh-bvh"),w=require("react-composer"),E=require("lodash.clamp");function b(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function M(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var S=b(e),C=M(t),T=M(r),P=M(n),R=b(a),D=b(i),_=b(d),z=b(h),k=b(v),F=b(g),L=b(w),A=b(E);const B=new n.Vector3,U=new n.Vector3,V=new n.Vector3;function I(e,t,r){const n=B.setFromMatrixPosition(e.matrixWorld);n.project(t);const o=r.width/2,a=r.height/2;return[n.x*o+o,-n.y*a+a]}const O=e=>Math.abs(e)<1e-10?0:e;function j(e,t,r=""){let n="matrix3d(";for(let r=0;16!==r;r++)n+=O(t[r]*e.elements[r])+(15!==r?",":")");return r+n}const W=(G=[1,-1,1,1,1,-1,1,1,1,-1,1,1,1,-1,1,1],e=>j(e,G));var G;const N=(e,t)=>{return j(e,[1/(r=t),1/r,1/r,1,-1/r,-1/r,-1/r,-1,1/r,1/r,1/r,1,1,1,1,1],"translate(-50%,-50%)");var r};const H=C.forwardRef((({children:e,eps:t=.001,style:r,className:a,prepend:i,center:s,fullscreen:l,portal:c,distanceFactor:u,sprite:d=!1,transform:m=!1,occlude:f,onOcclude:p,castShadow:h,receiveShadow:v,material:g,geometry:x,zIndexRange:y=[16777271,0],calculatePosition:w=I,as:E="div",wrapperClass:b,pointerEvents:M="auto",...P},R)=>{const{gl:D,camera:_,scene:z,size:k,raycaster:F,events:L,viewport:A}=o.useThree(),[j]=C.useState((()=>document.createElement(E))),G=C.useRef(),H=C.useRef(null),$=C.useRef(0),q=C.useRef([0,0]),X=C.useRef(null),Y=C.useRef(null),Z=(null==c?void 0:c.current)||L.connected||D.domElement.parentNode,K=C.useRef(null),Q=C.useRef(!1),J=C.useMemo((()=>f&&"blending"!==f||Array.isArray(f)&&f.length&&function(e){return e&&"object"==typeof e&&"current"in e}(f[0])),[f]);C.useLayoutEffect((()=>{const e=D.domElement;f?(e.style.zIndex=`${Math.floor(y[0]/2)}`,e.style.position="absolute",e.style.pointerEvents="none"):(e.style.zIndex=null,e.style.position=null,e.style.pointerEvents=null)}),[f,J]),C.useLayoutEffect((()=>{if(H.current){const e=G.current=T.createRoot(j);if(z.updateMatrixWorld(),m)j.style.cssText="position:absolute;top:0;left:0;pointer-events:none;overflow:hidden;";else{const e=w(H.current,_,k);j.style.cssText=`position:absolute;top:0;left:0;transform:translate3d(${e[0]}px,${e[1]}px,0);transform-origin:0 0;`}return Z&&(i?Z.prepend(j):Z.appendChild(j)),()=>{Z&&Z.removeChild(j),e.unmount()}}}),[Z,m]),C.useLayoutEffect((()=>{b&&(j.className=b)}),[b]);const ee=C.useMemo((()=>m?{position:"absolute",top:0,left:0,width:k.width,height:k.height,transformStyle:"preserve-3d",pointerEvents:"none"}:{position:"absolute",transform:s?"translate3d(-50%,-50%,0)":"none",...l&&{top:-k.height/2,left:-k.width/2,width:k.width,height:k.height},...r}),[r,s,l,k,m]),te=C.useMemo((()=>({position:"absolute",pointerEvents:M})),[M]);C.useLayoutEffect((()=>{var t,n;(Q.current=!1,m)?null==(t=G.current)||t.render(C.createElement("div",{ref:X,style:ee},C.createElement("div",{ref:Y,style:te},C.createElement("div",{ref:R,className:a,style:r,children:e})))):null==(n=G.current)||n.render(C.createElement("div",{ref:R,style:ee,className:a,children:e}))}));const re=C.useRef(!0);o.useFrame((e=>{if(H.current){_.updateMatrixWorld(),H.current.updateWorldMatrix(!0,!1);const e=m?q.current:w(H.current,_,k);if(m||Math.abs($.current-_.zoom)>t||Math.abs(q.current[0]-e[0])>t||Math.abs(q.current[1]-e[1])>t){const t=function(e,t){const r=B.setFromMatrixPosition(e.matrixWorld),n=U.setFromMatrixPosition(t.matrixWorld),o=r.sub(n),a=t.getWorldDirection(V);return o.angleTo(a)>Math.PI/2}(H.current,_);let r=!1;J&&("blending"!==f?r=[z]:Array.isArray(f)&&(r=f.map((e=>e.current))));const o=re.current;if(r){const e=function(e,t,r,n){const o=B.setFromMatrixPosition(e.matrixWorld),a=o.clone();a.project(t),r.setFromCamera(a,t);const i=r.intersectObjects(n,!0);if(i.length){const e=i[0].distance;return o.distanceTo(r.ray.origin)<e}return!0}(H.current,_,F,r);re.current=e&&!t}else re.current=!t;o!==re.current&&(p?p(!re.current):j.style.display=re.current?"block":"none");const a=Math.floor(y[0]/2),i=f?J?[y[0],a]:[a-1,0]:y;if(j.style.zIndex=`${function(e,t,r){if(t instanceof n.PerspectiveCamera||t instanceof n.OrthographicCamera){const n=B.setFromMatrixPosition(e.matrixWorld),o=U.setFromMatrixPosition(t.matrixWorld),a=n.distanceTo(o),i=(r[1]-r[0])/(t.far-t.near),s=r[1]-i*t.far;return Math.round(i*a+s)}}(H.current,_,i)}`,m){const[e,t]=[k.width/2,k.height/2],r=_.projectionMatrix.elements[5]*t,{isOrthographicCamera:n,top:o,left:a,bottom:i,right:s}=_,l=W(_.matrixWorldInverse),c=n?`scale(${r})translate(${O(-(s+a)/2)}px,${O((o+i)/2)}px)`:`translateZ(${r}px)`;let m=H.current.matrixWorld;d&&(m=_.matrixWorldInverse.clone().transpose().copyPosition(m).scale(H.current.scale),m.elements[3]=m.elements[7]=m.elements[11]=0,m.elements[15]=1),j.style.width=k.width+"px",j.style.height=k.height+"px",j.style.perspective=n?"":`${r}px`,X.current&&Y.current&&(X.current.style.transform=`${c}${l}translate(${e}px,${t}px)`,Y.current.style.transform=N(m,1/((u||10)/400)))}else{const t=void 0===u?1:function(e,t){if(t instanceof n.OrthographicCamera)return t.zoom;if(t instanceof n.PerspectiveCamera){const r=B.setFromMatrixPosition(e.matrixWorld),n=U.setFromMatrixPosition(t.matrixWorld),o=t.fov*Math.PI/180,a=r.distanceTo(n);return 1/(2*Math.tan(o/2)*a)}return 1}(H.current,_)*u;j.style.transform=`translate3d(${e[0]}px,${e[1]}px,0) scale(${t})`}q.current=e,$.current=_.zoom}}if(!J&&K.current&&!Q.current)if(m){if(X.current){const e=X.current.children[0];if(null!=e&&e.clientWidth&&null!=e&&e.clientHeight){const{isOrthographicCamera:t}=_;if(t||x)P.scale&&(Array.isArray(P.scale)?P.scale instanceof n.Vector3?K.current.scale.copy(P.scale.clone().divideScalar(1)):K.current.scale.set(1/P.scale[0],1/P.scale[1],1/P.scale[2]):K.current.scale.setScalar(1/P.scale));else{const t=(u||10)/400,r=e.clientWidth*t,n=e.clientHeight*t;K.current.scale.set(r,n,1)}Q.current=!0}}}else{const t=j.children[0];if(null!=t&&t.clientWidth&&null!=t&&t.clientHeight){const e=1/A.factor,r=t.clientWidth*e,n=t.clientHeight*e;K.current.scale.set(r,n,1),Q.current=!0}K.current.lookAt(e.camera.position)}}));const ne=C.useMemo((()=>({vertexShader:m?void 0:'\n /*\n This shader is from the THREE\'s SpriteMaterial.\n We need to turn the backing plane into a Sprite\n (make it always face the camera) if "transfrom" \n is false. \n */\n #include <common>\n\n void main() {\n vec2 center = vec2(0., 1.);\n float rotation = 0.0;\n \n // This is somewhat arbitrary, but it seems to work well\n // Need to figure out how to derive this dynamically if it even matters\n float size = 0.03;\n\n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\n bool isPerspective = isPerspectiveMatrix( projectionMatrix );\n if ( isPerspective ) scale *= - mvPosition.z;\n\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale * size;\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n mvPosition.xy += rotatedPosition;\n\n gl_Position = projectionMatrix * mvPosition;\n }\n ',fragmentShader:"\n void main() {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n }\n "})),[m]);return C.createElement("group",S.default({},P,{ref:H}),f&&!J&&C.createElement("mesh",{castShadow:h,receiveShadow:v,ref:K},x||C.createElement("planeGeometry",null),g||C.createElement("shaderMaterial",{side:n.DoubleSide,vertexShader:ne.vertexShader,fragmentShader:ne.fragmentShader})))}));let $=0;const q=R.default((e=>(n.DefaultLoadingManager.onStart=(t,r,n)=>{e({active:!0,item:t,loaded:r,total:n,progress:(r-$)/(n-$)*100})},n.DefaultLoadingManager.onLoad=()=>{e({active:!1})},n.DefaultLoadingManager.onError=t=>e((e=>({errors:[...e.errors,t]}))),n.DefaultLoadingManager.onProgress=(t,r,n)=>{r===n&&($=n),e({active:!0,item:t,loaded:r,total:n,progress:(r-$)/(n-$)*100||100})},{errors:[],active:!1,progress:0,item:"",loaded:0,total:0}))),X=e=>`Loading ${e.toFixed(2)}%`;const Y={container:{position:"absolute",top:0,left:0,width:"100%",height:"100%",background:"#171717",display:"flex",alignItems:"center",justifyContent:"center",transition:"opacity 300ms ease",zIndex:1e3},inner:{width:100,height:3,background:"#272727",textAlign:"center"},bar:{height:3,width:"100%",background:"white",transition:"transform 200ms",transformOrigin:"left center"},data:{display:"inline-block",position:"relative",fontVariantNumeric:"tabular-nums",marginTop:"0.8em",color:"#f0f0f0",fontSize:"0.6em",fontFamily:'-apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "Helvetica Neue", Helvetica, Arial, Roboto, Ubuntu, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',whiteSpace:"nowrap"}},Z=C.createContext(null);function K(){return C.useContext(Z)}const Q=C.forwardRef((({children:e},t)=>{const r=C.useRef(null),n=K(),{width:a,height:i}=o.useThree((e=>e.viewport));return o.useFrame((()=>{r.current.position.x=n.horizontal?-a*(n.pages-1)*n.offset:0,r.current.position.y=n.horizontal?0:i*(n.pages-1)*n.offset})),C.createElement("group",{ref:D.default([t,r])},e)})),J=C.forwardRef((({children:e,style:t,...r},n)=>{const a=K(),i=C.useRef(null),{width:s,height:l}=o.useThree((e=>e.size)),c=C.useContext(o.context),u=C.useMemo((()=>T.createRoot(a.fixed)),[a.fixed]);return o.useFrame((()=>{a.delta>a.eps&&(i.current.style.transform=`translate3d(${a.horizontal?-s*(a.pages-1)*a.offset:0}px,${a.horizontal?0:l*(a.pages-1)*-a.offset}px,0)`)})),u.render(C.createElement("div",S.default({ref:D.default([n,i]),style:{...t,position:"absolute",top:0,left:0,willChange:"transform"}},r),C.createElement(Z.Provider,{value:a},C.createElement(o.context.Provider,{value:c},e)))),null})),ee=C.forwardRef((({html:e,...t},r)=>{const n=e?J:Q;return C.createElement(n,S.default({ref:r},t))}));const te=C.createContext(null);const re=C.createContext([]);const ne=C.forwardRef((function({follow:e=!0,lockX:t=!1,lockY:r=!1,lockZ:n=!1,...a},i){const s=C.useRef();return o.useFrame((({camera:o})=>{if(!e||!s.current)return;const a=s.current.rotation.clone();s.current.quaternion.copy(o.quaternion),t&&(s.current.rotation.x=a.x),r&&(s.current.rotation.y=a.y),n&&(s.current.rotation.z=a.z)})),C.createElement("group",S.default({ref:D.default([s,i])},a))})),oe=C.forwardRef((({children:e,depth:t=-1,...r},n)=>{const a=C.useRef(null);return o.useFrame((({camera:e})=>{a.current.quaternion.copy(e.quaternion),a.current.position.copy(e.position)})),C.createElement("group",S.default({ref:D.default([n,a])},r),C.createElement("group",{"position-z":-t},e))})),ae=C.forwardRef((function({points:e,color:t="black",vertexColors:r,linewidth:a,lineWidth:i,dashed:s,...l},c){const d=o.useThree((e=>e.size)),[m]=C.useState((()=>new u.Line2)),[f]=C.useState((()=>new u.LineMaterial)),p=C.useMemo((()=>{const t=new u.LineGeometry,o=e.map((e=>{const t=Array.isArray(e);return e instanceof n.Vector3?[e.x,e.y,e.z]:e instanceof n.Vector2?[e.x,e.y,0]:t&&3===e.length?[e[0],e[1],e[2]]:t&&2===e.length?[e[0],e[1],0]:e}));if(t.setPositions(o.flat()),r){const e=r.map((e=>e instanceof n.Color?e.toArray():e));t.setColors(e.flat())}return t}),[e,r]);return C.useLayoutEffect((()=>{m.computeLineDistances()}),[e,m]),C.useLayoutEffect((()=>{s?f.defines.USE_DASH="":delete f.defines.USE_DASH,f.needsUpdate=!0}),[s,f]),C.useEffect((()=>()=>p.dispose()),[p]),C.createElement("primitive",S.default({object:m,ref:c},l),C.createElement("primitive",{object:p,attach:"geometry"}),C.createElement("primitive",S.default({object:f,attach:"material",color:t,vertexColors:Boolean(r),resolution:[d.width,d.height],linewidth:null!=a?a:i,dashed:s},l)))})),ie=new n.Vector3,se=C.forwardRef((function({start:e=[0,0,0],end:t=[0,0,0],mid:r,segments:o=20,...a},i){const s=C.useRef(null),[l]=C.useState((()=>new n.QuadraticBezierCurve3(void 0,void 0,void 0))),c=C.useCallback(((e,t,r,o=20)=>(e instanceof n.Vector3?l.v0.copy(e):l.v0.set(...e),t instanceof n.Vector3?l.v2.copy(t):l.v2.set(...t),r instanceof n.Vector3?l.v1.copy(r):l.v1.copy(l.v0.clone().add(l.v2.clone().sub(l.v0)).add(ie.set(0,l.v0.y-l.v2.y,0))),l.getPoints(o))),[]);C.useLayoutEffect((()=>{s.current.setPoints=(e,t,r)=>{const n=c(e,t,r);s.current.geometry&&s.current.geometry.setPositions(n.map((e=>e.toArray())).flat())}}),[]);const u=C.useMemo((()=>c(e,t,r,o)),[e,t,r,o]);return C.createElement(ae,S.default({ref:D.default([s,i]),points:u},a))})),le=C.forwardRef((function({start:e,end:t,midA:r,midB:o,segments:a=20,...i},s){const l=C.useMemo((()=>{const i=e instanceof n.Vector3?e:new n.Vector3(...e),s=t instanceof n.Vector3?t:new n.Vector3(...t),l=r instanceof n.Vector3?r:new n.Vector3(...r),c=o instanceof n.Vector3?o:new n.Vector3(...o);return new n.CubicBezierCurve3(i,l,c,s).getPoints(a)}),[e,t,r,o,a]);return C.createElement(ae,S.default({ref:s,points:l},i))})),ce=C.forwardRef((function({points:e,closed:t=!1,curveType:r="centripetal",tension:o=.5,segments:a=20,vertexColors:i,...s},l){const c=C.useMemo((()=>{const a=e.map((e=>e instanceof n.Vector3?e:new n.Vector3(...e)));return new n.CatmullRomCurve3(a,t,r,o)}),[e,t,r,o]),u=C.useMemo((()=>c.getPoints(a)),[c,a]),d=C.useMemo((()=>{if(!i||i.length<2)return;if(i.length===a+1)return i;const e=i.map((e=>e instanceof n.Color?e:new n.Color(...e)));t&&e.push(e[0].clone());const r=[e[0]],o=a/(e.length-1);for(let t=1;t<a;t++){const n=t%o/o,a=Math.floor(t/o);r.push(e[a].clone().lerp(e[a+1],n))}return r.push(e[e.length-1]),r}),[i,a]);return C.createElement(ae,S.default({ref:l,points:u,vertexColors:d},s))})),ue=C.forwardRef((({url:e,distance:t=1,loop:r=!0,autoplay:a,...i},s)=>{const l=C.useRef(),c=o.useThree((({camera:e})=>e)),[u]=C.useState((()=>new n.AudioListener)),d=o.useLoader(n.AudioLoader,e);return C.useEffect((()=>{const e=l.current;e&&(e.setBuffer(d),e.setRefDistance(t),e.setLoop(r),a&&!e.isPlaying&&e.play())}),[d,c,t,r]),C.useEffect((()=>{const e=l.current;return c.add(u),()=>{c.remove(u),e&&(e.isPlaying&&e.stop(),e.source&&e.source._connected&&e.disconnect())}}),[]),C.createElement("positionalAudio",S.default({ref:D.default([l,s]),args:[u]},i))})),de=C.forwardRef((({anchorX:e="center",anchorY:t="middle",font:r,fontSize:n=1,children:a,characters:i,onSync:s,...l},c)=>{const u=o.useThree((({invalidate:e})=>e)),[d]=C.useState((()=>new m.Text)),[p,h]=C.useMemo((()=>{const e=[];let t="";return C.Children.forEach(a,(r=>{"string"==typeof r||"number"==typeof r?t+=r:e.push(r)})),[e,t]}),[a]);return f.suspend((()=>new Promise((e=>m.preloadFont({font:r,characters:i},e)))),["troika-text",r,i]),C.useLayoutEffect((()=>{d.sync((()=>{u(),s&&s(d)}))})),C.useEffect((()=>()=>d.dispose()),[d]),C.createElement("primitive",S.default({object:d,ref:c,font:r,text:h,anchorX:e,anchorY:t,fontSize:n},l),p)})),me=["string","number"],fe=C.forwardRef((({font:e,letterSpacing:r=0,lineHeight:n=1,size:a=1,height:i=.2,bevelThickness:s=.1,bevelSize:l=.01,bevelEnabled:c=!1,bevelOffset:d=0,bevelSegments:m=4,curveSegments:p=8,children:h,...v},g)=>{C.useMemo((()=>o.extend({RenamedTextGeometry:u.TextGeometry})),[]);const x=f.suspend((async()=>{let t="string"==typeof e?await(await fetch(e)).json():e;return(new u.FontLoader).parse(t)}),[e]),y=t.useMemo((()=>({font:x,size:a,height:i,bevelThickness:s,bevelSize:l,bevelEnabled:c,bevelSegments:m,bevelOffset:d,curveSegments:p,letterSpacing:r,lineHeight:n})),[x,a,i,s,l,c,m,d,p,r,n]),[w,...E]=t.useMemo((()=>(e=>{let t="";const r=[];return C.Children.forEach(e,(e=>{me.includes(typeof e)?t+=e+"":r.push(e)})),[t,...r]})(h)),[h]),b=C.useMemo((()=>[w,y]),[w,y]);return C.createElement("mesh",S.default({},v,{ref:g}),C.createElement("renamedTextGeometry",{args:b}),E)})),pe=C.forwardRef((({children:e,multisamping:t=8,renderIndex:r=1,disableRender:a,disableGamma:i,disableRenderPass:s,depthBuffer:l=!0,stencilBuffer:c=!1,anisotropy:d=1,encoding:m,type:f,...p},h)=>{C.useMemo((()=>o.extend({EffectComposer:u.EffectComposer,RenderPass:u.RenderPass,ShaderPass:u.ShaderPass})),[]);const v=C.useRef(),{scene:g,camera:x,gl:y,size:w,viewport:E}=o.useThree(),[b]=C.useState((()=>{const e=new n.WebGLRenderTarget(w.width,w.height,{type:f||n.HalfFloatType,format:n.RGBAFormat,encoding:m||y.outputEncoding,depthBuffer:l,stencilBuffer:c,anisotropy:d});return e.samples=t,e}));C.useEffect((()=>{var e,t;null==(e=v.current)||e.setSize(w.width,w.height),null==(t=v.current)||t.setPixelRatio(E.dpr)}),[y,w,E.dpr]),o.useFrame((()=>{var e;a||null==(e=v.current)||e.render()}),r);const M=[];return s||M.push(C.createElement("renderPass",{key:"renderpass",attach:`passes-${M.length}`,args:[g,x]})),i||M.push(C.createElement("shaderPass",{attach:`passes-${M.length}`,key:"gammapass",args:[u.GammaCorrectionShader]})),C.Children.forEach(e,(e=>{e&&M.push(C.cloneElement(e,{key:M.length,attach:`passes-${M.length}`}))})),C.createElement("effectComposer",S.default({ref:D.default([h,v]),args:[y,b]},p),M)}));function he(e,t,r,n){const o=class extends P.ShaderMaterial{constructor(o={}){const a=Object.entries(e);super({uniforms:a.reduce(((e,[t,r])=>({...e,...P.UniformsUtils.clone({[t]:{value:r}})})),{}),vertexShader:t,fragmentShader:r,...o}),this.key="",a.forEach((([e])=>Object.defineProperty(this,e,{get:()=>this.uniforms[e].value,set:t=>this.uniforms[e].value=t}))),n&&n(this)}};return o.key=P.MathUtils.generateUUID(),o}const ve=e=>e===Object(e)&&!Array.isArray(e)&&"function"!=typeof e;function ge(e,r){const a=o.useThree((e=>e.gl)),i=o.useLoader(n.TextureLoader,ve(e)?Object.values(e):e);if(t.useLayoutEffect((()=>{null==r||r(i)}),[r]),t.useEffect((()=>{(Array.isArray(i)?i:[i]).forEach(a.initTexture)}),[a,i]),ve(e)){const t=Object.keys(e),r={};return t.forEach((e=>Object.assign(r,{[e]:i[t.indexOf(e)]}))),r}return i}ge.preload=e=>o.useLoader.preload(n.TextureLoader,e),ge.clear=e=>o.useLoader.clear(n.TextureLoader,e);const xe=he({color:new P.Color("white"),scale:[1,1],imageBounds:[1,1],map:null,zoom:1,grayscale:0,opacity:1},"\n varying vec2 vUv;\n void main() {\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);\n vUv = uv;\n }\n","\n // mostly from https://gist.github.com/statico/df64c5d167362ecf7b34fca0b1459a44\n varying vec2 vUv;\n uniform vec2 scale;\n uniform vec2 imageBounds;\n uniform vec3 color;\n uniform sampler2D map;\n uniform float zoom;\n uniform float grayscale;\n uniform float opacity;\n const vec3 luma = vec3(.299, 0.587, 0.114);\n vec4 toGrayscale(vec4 color, float intensity) {\n return vec4(mix(color.rgb, vec3(dot(color.rgb, luma)), intensity), color.a);\n }\n vec2 aspect(vec2 size) {\n return size / min(size.x, size.y);\n }\n void main() {\n vec2 s = aspect(scale);\n vec2 i = aspect(imageBounds);\n float rs = s.x / s.y;\n float ri = i.x / i.y;\n vec2 new = rs < ri ? vec2(i.x * s.y / i.y, s.y) : vec2(s.x, i.y * s.x / i.x);\n vec2 offset = (rs < ri ? vec2((new.x - s.x) / 2.0, 0.0) : vec2(0.0, (new.y - s.y) / 2.0)) / new;\n vec2 uv = vUv * s / new + offset;\n vec2 zUv = (uv - vec2(0.5, 0.5)) / zoom + vec2(0.5, 0.5);\n gl_FragColor = toGrayscale(texture2D(map, zUv) * vec4(color, opacity), grayscale);\n \n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }\n"),ye=C.forwardRef((({children:e,color:t,segments:r=1,scale:n=1,zoom:a=1,grayscale:i=0,opacity:s=1,texture:l,toneMapped:c,transparent:u,...d},m)=>{o.extend({ImageMaterial:xe});const f=o.useThree((e=>e.gl)),p=Array.isArray(n)?[n[0],n[1]]:[n,n],h=[l.image.width,l.image.height];return C.createElement("mesh",S.default({ref:m,scale:Array.isArray(n)?[...n,1]:n},d),C.createElement("planeGeometry",{args:[1,1,r,r]}),C.createElement("imageMaterial",{color:t,map:l,"map-encoding":f.outputEncoding,zoom:a,grayscale:i,opacity:s,scale:p,imageBounds:h,toneMapped:c,transparent:u}),e)})),we=C.forwardRef((({url:e,...t},r)=>{const n=ge(e);return C.createElement(ye,S.default({},t,{texture:n,ref:r}))})),Ee=C.forwardRef((({url:e,...t},r)=>C.createElement(ye,S.default({},t,{ref:r})))),be=C.forwardRef(((e,t)=>{if(e.url)return C.createElement(we,S.default({},e,{ref:t}));if(e.texture)return C.createElement(Ee,S.default({},e,{ref:t}));throw new Error("<Image /> requires a url or texture")}));const Me={width:.2,length:1,decay:1,local:!1,stride:0,interval:1},Se=(e,t=1)=>(e.set(e.subarray(t)),e.fill(-1/0,-t),e);function Ce(e,t){const{length:r,local:a,decay:i,interval:s,stride:l}={...Me,...t},c=C.useRef(),[u]=C.useState((()=>new n.Vector3));C.useLayoutEffect((()=>{e&&(c.current=Float32Array.from({length:10*r*3},((t,r)=>e.position.getComponent(r%3))))}),[r,e]);const d=C.useRef(new n.Vector3),m=C.useRef(0);return o.useFrame((()=>{if(e&&c.current){if(0===m.current){let t;a?t=e.position:(e.getWorldPosition(u),t=u);const r=1*i;for(let e=0;e<r;e++)t.distanceTo(d.current)<l||(Se(c.current,3),c.current.set(t.toArray(),c.current.length-3));d.current.copy(t)}m.current++,m.current=m.current%s}})),c}const Te=C.forwardRef(((e,t)=>{const{children:r}=e,{width:a,length:i,decay:s,local:l,stride:c,interval:u}={...Me,...e},{color:d="hotpink",attenuation:m,target:f}=e,h=o.useThree((e=>e.size)),v=o.useThree((e=>e.scene)),g=C.useRef(null),[x,y]=C.useState(null),w=Ce(x,{length:i,decay:s,local:l,stride:c,interval:u});C.useEffect((()=>{const e=(null==f?void 0:f.current)||g.current.children.find((e=>e instanceof n.Object3D));e&&y(e)}),[w,f]);const E=C.useMemo((()=>new p.MeshLineGeometry),[]),b=C.useMemo((()=>{var e;const t=new p.MeshLineMaterial({lineWidth:.1*a,color:d,sizeAttenuation:1,resolution:new n.Vector2(h.width,h.height)});let o;if(r)if(Array.isArray(r))o=r.find((e=>{const t=e;return"string"==typeof t.type&&"meshLineMaterial"===t.type}));else{const e=r;"string"==typeof e.type&&"meshLineMaterial"===e.type&&(o=e)}return"object"==typeof(null==(e=o)?void 0:e.props)&&t.setValues(o.props),t}),[a,d,h,r]);return C.useEffect((()=>{b.uniforms.resolution.value.set(h.width,h.height)}),[h]),o.useFrame((()=>{w.current&&E.setPoints(w.current,m)})),C.createElement("group",null,o.createPortal(C.createElement("mesh",{ref:t,geometry:E,material:b}),v),C.createElement("group",{ref:g},r))}));function Pe(e,t=16,r,o,a){const[i,s]=C.useState((()=>{const e=Array.from({length:t},(()=>[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])).flat();return new n.InstancedBufferAttribute(Float32Array.from(e),16)}));return C.useEffect((()=>{if(void 0===e.current)return;const l=new u.MeshSurfaceSampler(e.current);o&&l.setWeightAttribute(o),l.build();const c=new n.Vector3,d=new n.Vector3,m=new n.Color,f=new n.Object3D;e.current.updateMatrixWorld(!0);for(let n=0;n<t;n++)l.sample(c,d,m),"function"==typeof r?r({dummy:f,sampledMesh:e.current,position:c,normal:d,color:m},n):f.position.copy(c),f.updateMatrix(),null!=a&&a.current&&a.current.setMatrixAt(n,f.matrix),f.matrix.toArray(i.array,16*n);null!=a&&a.current&&(a.current.instanceMatrix.needsUpdate=!0),i.needsUpdate=!0,s(i.clone())}),[e,a,o,t,r]),i}const Re=C.forwardRef((({isChild:e=!1,object:t,children:r,deep:n,castShadow:o,receiveShadow:a,inject:i,keys:s,...l},c)=>{var d;const m={keys:s,deep:n,inject:i,castShadow:o,receiveShadow:a};if(t=C.useMemo((()=>{if(!1===e&&!Array.isArray(t)){let e=!1;if(t.traverse((t=>{t.isSkinnedMesh&&(e=!0)})),e)return u.SkeletonUtils.clone(t)}return t}),[t,e]),Array.isArray(t))return C.createElement("group",S.default({},l,{ref:c}),t.map((e=>C.createElement(Re,S.default({key:e.uuid,object:e},m)))),r);const{children:f,...p}=function(e,{keys:t=["near","far","color","distance","decay","penumbra","angle","intensity","skeleton","visible","castShadow","receiveShadow","morphTargetDictionary","morphTargetInfluences","name","geometry","material","position","rotation","scale","up","userData","bindMode","bindMatrix","bindMatrixInverse","skeleton"],deep:r,inject:n,castShadow:o,receiveShadow:a}){let i=z.default(e,t);return r&&(i.geometry&&"materialsOnly"!==r&&(i.geometry=i.geometry.clone()),i.material&&"geometriesOnly"!==r&&(i.material=i.material.clone())),n&&(i="function"==typeof n?{...i,children:n(e)}:C.isValidElement(n)?{...i,children:n}:{...i,...n}),e instanceof P.Mesh&&(o&&(i.castShadow=!0),a&&(i.receiveShadow=!0)),i}(t,m),h=t.type[0].toLowerCase()+t.type.slice(1);return C.createElement(h,S.default({},p,l,{ref:c}),(null==(d=t)?void 0:d.children).map((e=>"Bone"===e.type?C.createElement("primitive",S.default({key:e.uuid,object:e},m)):C.createElement(Re,S.default({key:e.uuid,object:e},m,{isChild:!0})))),r,f)})),De=C.createContext(null),_e=C.forwardRef((({resolution:e=28,maxPolyCount:t=1e4,enableUvs:r=!1,enableColors:n=!1,children:a,...i},s)=>{const l=C.useRef(null),c=C.useMemo((()=>new u.MarchingCubes(e,null,r,n,t)),[e,t,r,n]),d=C.useMemo((()=>({getParent:()=>l})),[]);return o.useFrame((()=>{c.reset()}),-1),C.createElement(C.Fragment,null,C.createElement("primitive",S.default({object:c,ref:D.default([l,s])},i),C.createElement(De.Provider,{value:d},a)))})),ze=C.forwardRef((({strength:e=.5,subtract:t=12,color:r,...n},a)=>{const{getParent:i}=C.useContext(De),s=C.useMemo((()=>i()),[i]),l=C.useRef(),c=new P.Vector3;return o.useFrame((n=>{s.current&&l.current&&(l.current.getWorldPosition(c),s.current.addBall(.5+.5*c.x,.5+.5*c.y,.5+.5*c.z,e,t,r))})),C.createElement("group",S.default({ref:D.default([a,l])},n))})),ke=C.forwardRef((({planeType:e="x",strength:t=.5,subtract:r=12,...n},a)=>{const{getParent:i}=C.useContext(De),s=C.useMemo((()=>i()),[i]),l=C.useRef(),c=C.useMemo((()=>"x"===e?"addPlaneX":"y"===e?"addPlaneY":"addPlaneZ"),[e]);return o.useFrame((()=>{s.current&&l.current&&s.current[c](t,r)})),C.createElement("group",S.default({ref:D.default([a,l])},n))}));function Fe(e=[0,0,0]){return function(e){return Array.isArray(e)}(e)?e:e instanceof P.Vector3||e instanceof P.Euler?[e.x,e.y,e.z]:[e,e,e]}const Le=t.forwardRef((function({src:e,skipFill:r,skipStrokes:a,fillMaterial:i,strokeMaterial:s,fillMeshProps:l,strokeMeshProps:c,...d},m){const f=o.useLoader(u.SVGLoader,e.startsWith("<svg")?`data:image/svg+xml;utf8,${e}`:e),p=t.useMemo((()=>a?[]:f.paths.map((e=>{var t;return void 0===(null==(t=e.userData)?void 0:t.style.stroke)||"none"===e.userData.style.stroke?null:e.subPaths.map((t=>u.SVGLoader.pointsToStroke(t.getPoints(),e.userData.style)))}))),[f,a]);return t.useEffect((()=>()=>p.forEach((e=>e&&e.map((e=>e.dispose()))))),[p]),C.createElement("object3D",S.default({ref:m},d),C.createElement("object3D",{scale:[1,-1,1]},f.paths.map(((e,o)=>{var d,m;return C.createElement(t.Fragment,{key:o},!r&&void 0!==(null==(d=e.userData)?void 0:d.style.fill)&&"none"!==e.userData.style.fill&&u.SVGLoader.createShapes(e).map(((t,r)=>C.createElement("mesh",S.default({key:r},l),C.createElement("shapeGeometry",{args:[t]}),C.createElement("meshBasicMaterial",S.default({color:e.userData.style.fill,opacity:e.userData.style.fillOpacity,transparent:!0,side:n.DoubleSide,depthWrite:!1},i))))),!a&&void 0!==(null==(m=e.userData)?void 0:m.style.stroke)&&"none"!==e.userData.style.stroke&&e.subPaths.map(((t,r)=>C.createElement("mesh",S.default({key:r,geometry:p[o][r]},c),C.createElement("meshBasicMaterial",S.default({color:e.userData.style.stroke,opacity:e.userData.style.strokeOpacity,transparent:!0,side:n.DoubleSide,depthWrite:!1},s))))))}))))}));let Ae=null;function Be(e,t,r){return n=>{r&&r(n),e&&(Ae||(Ae=new u.DRACOLoader),Ae.setDecoderPath("string"==typeof e?e:"https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),n.setDRACOLoader(Ae)),t&&n.setMeshoptDecoder("function"==typeof u.MeshoptDecoder?u.MeshoptDecoder():u.MeshoptDecoder)}}function Ue(e,t=!0,r=!0,n){return o.useLoader(u.GLTFLoader,e,Be(t,r,n))}Ue.preload=(e,t=!0,r=!0,n)=>o.useLoader.preload(u.GLTFLoader,e,Be(t,r,n)),Ue.clear=e=>o.useLoader.clear(u.GLTFLoader,e);const Ve=C.forwardRef((({src:e,...t},r)=>{const{scene:n}=Ue(e);return C.createElement(Re,S.default({ref:r},t,{object:n}))}));function Ie(e,t,r){const{gl:n,size:a,viewport:i}=o.useThree(),s="number"==typeof e?e:a.width*i.dpr,l="number"==typeof t?t:a.height*i.dpr,c=("number"==typeof e?r:e)||{},{samples:u,...d}=c,m=C.useMemo((()=>{let e;return e=new P.WebGLRenderTarget(s,l,{minFilter:P.LinearFilter,magFilter:P.LinearFilter,encoding:n.outputEncoding,type:P.HalfFloatType,...d}),e.samples=u,e}),[]);return C.useLayoutEffect((()=>{m.setSize(s,l),u&&(m.samples=u)}),[u,m,s,l]),C.useEffect((()=>()=>m.dispose()),[]),m}const Oe=C.forwardRef((({envMap:e,resolution:t=256,frames:r=1/0,children:n,makeDefault:a,...i},s)=>{const l=o.useThree((({set:e})=>e)),c=o.useThree((({camera:e})=>e)),u=o.useThree((({size:e})=>e)),d=C.useRef(null),m=C.useRef(null),f=Ie(t);C.useLayoutEffect((()=>{i.manual||d.current.updateProjectionMatrix()}),[u,i]),C.useLayoutEffect((()=>{d.current.updateProjectionMatrix()})),C.useLayoutEffect((()=>{if(a){const e=c;return l((()=>({camera:d.current}))),()=>l((()=>({camera:e})))}}),[d,a,l]);let p=0,h=null;const v="function"==typeof n;return o.useFrame((t=>{v&&(r===1/0||p<r)&&(m.current.visible=!1,t.gl.setRenderTarget(f),h=t.scene.background,e&&(t.scene.background=e),t.gl.render(t.scene,d.current),t.scene.background=h,t.gl.setRenderTarget(null),m.current.visible=!0,p++)})),C.createElement(C.Fragment,null,C.createElement("orthographicCamera",S.default({left:u.width/-2,right:u.width/2,top:u.height/2,bottom:u.height/-2,ref:D.default([d,s])},i),!v&&n),C.createElement("group",{ref:m},v&&n(f.texture)))})),je=C.forwardRef((({envMap:e,resolution:t=256,frames:r=1/0,makeDefault:n,children:a,...i},s)=>{const l=o.useThree((({set:e})=>e)),c=o.useThree((({camera:e})=>e)),u=o.useThree((({size:e})=>e)),d=C.useRef(null),m=C.useRef(null),f=Ie(t);C.useLayoutEffect((()=>{i.manual||(d.current.aspect=u.width/u.height)}),[u,i]),C.useLayoutEffect((()=>{d.current.updateProjectionMatrix()}));let p=0,h=null;const v="function"==typeof a;return o.useFrame((t=>{v&&(r===1/0||p<r)&&(m.current.visible=!1,t.gl.setRenderTarget(f),h=t.scene.background,e&&(t.scene.background=e),t.gl.render(t.scene,d.current),t.scene.background=h,t.gl.setRenderTarget(null),m.current.visible=!0,p++)})),C.useLayoutEffect((()=>{if(n){const e=c;return l((()=>({camera:d.current}))),()=>l((()=>({camera:e})))}}),[d,n,l]),C.createElement(C.Fragment,null,C.createElement("perspectiveCamera",S.default({ref:D.default([d,s])},i),!v&&a),C.createElement("group",{ref:m},v&&a(f.texture)))}));const We=C.forwardRef(((e,t)=>{const{camera:r,onChange:n,makeDefault:a,...i}=e,s=o.useThree((e=>e.camera)),l=o.useThree((e=>e.invalidate)),c=o.useThree((e=>e.get)),d=o.useThree((e=>e.set)),m=r||s,[f]=C.useState((()=>new u.DeviceOrientationControls(m)));return C.useEffect((()=>{const e=e=>{l(),n&&n(e)};return null==f||null==f.addEventListener||f.addEventListener("change",e),()=>null==f||null==f.removeEventListener?void 0:f.removeEventListener("change",e)}),[n,f,l]),o.useFrame((()=>null==f?void 0:f.update()),-1),C.useEffect((()=>{const e=f;return null==e||e.connect(),()=>null==e?void 0:e.dispose()}),[f]),C.useEffect((()=>{if(a){const e=c().controls;return d({controls:f}),()=>d({controls:e})}}),[a,f]),f?C.createElement("primitive",S.default({ref:t,object:f},i)):null})),Ge=C.forwardRef((({domElement:e,...t},r)=>{const{onChange:n,makeDefault:a,...i}=t,s=o.useThree((e=>e.invalidate)),l=o.useThree((e=>e.camera)),c=o.useThree((e=>e.gl)),d=o.useThree((e=>e.events)),m=o.useThree((e=>e.get)),f=o.useThree((e=>e.set)),p=e||d.connected||c.domElement,h=C.useMemo((()=>new u.FlyControls(l)),[l]);return C.useEffect((()=>(h.connect(p),()=>{h.dispose()})),[p,h,s]),C.useEffect((()=>{const e=e=>{s(),n&&n(e)};return null==h.addEventListener||h.addEventListener("change",e),()=>null==h.removeEventListener?void 0:h.removeEventListener("change",e)}),[n,s]),C.useEffect((()=>{if(a){const e=m().controls;return f({controls:h}),()=>f({controls:e})}}),[a,h]),o.useFrame(((e,t)=>h.update(t))),C.createElement("primitive",S.default({ref:r,object:h,args:[l,p]},i))})),Ne=C.forwardRef(((e={enableDamping:!0},t)=>{const{domElement:r,camera:n,makeDefault:a,onChange:i,onStart:s,onEnd:l,...c}=e,d=o.useThree((e=>e.invalidate)),m=o.useThree((e=>e.camera)),f=o.useThree((e=>e.gl)),p=o.useThree((e=>e.events)),h=o.useThree((e=>e.set)),v=o.useThree((e=>e.get)),g=r||p.connected||f.domElement,x=n||m,y=C.useMemo((()=>new u.MapControls(x)),[x]);return C.useEffect((()=>{y.connect(g);const e=e=>{d(),i&&i(e)};return y.addEventListener("change",e),s&&y.addEventListener("start",s),l&&y.addEventListener("end",l),()=>{y.dispose(),y.removeEventListener("change",e),s&&y.removeEventListener("start",s),l&&y.removeEventListener("end",l)}}),[i,s,l,y,d,g]),C.useEffect((()=>{if(a){const e=v().controls;return h({controls:y}),()=>h({controls:e})}}),[a,y]),o.useFrame((()=>y.update()),-1),C.createElement("primitive",S.default({ref:t,object:y,enableDamping:!0},c))})),He=C.forwardRef((({makeDefault:e,camera:t,regress:r,domElement:n,enableDamping:a=!0,onChange:i,onStart:s,onEnd:l,...c},d)=>{const m=o.useThree((e=>e.invalidate)),f=o.useThree((e=>e.camera)),p=o.useThree((e=>e.gl)),h=o.useThree((e=>e.events)),v=o.useThree((e=>e.set)),g=o.useThree((e=>e.get)),x=o.useThree((e=>e.performance)),y=t||f,w=n||h.connected||p.domElement,E=C.useMemo((()=>new u.OrbitControls(y)),[y]);return o.useFrame((()=>{E.enabled&&E.update()}),-1),C.useEffect((()=>(E.connect(w),()=>{E.dispose()})),[w,r,E,m]),C.useEffect((()=>{const e=e=>{m(),r&&x.regress(),i&&i(e)};return E.addEventListener("change",e),s&&E.addEventListener("start",s),l&&E.addEventListener("end",l),()=>{s&&E.removeEventListener("start",s),l&&E.removeEventListener("end",l),E.removeEventListener("change",e)}}),[i,s,l,E,m]),C.useEffect((()=>{if(e){const e=g().controls;return v({controls:E}),()=>v({controls:e})}}),[e,E]),C.createElement("primitive",S.default({ref:d,object:E,enableDamping:a},c))})),$e=C.forwardRef((({makeDefault:e,camera:t,domElement:r,regress:n,onChange:a,onStart:i,onEnd:s,...l},c)=>{const{invalidate:d,camera:m,gl:f,events:p,set:h,get:v,performance:g,viewport:x}=o.useThree(),y=t||m,w=r||p.connected||f.domElement,E=C.useMemo((()=>new u.TrackballControls(y)),[y]);return o.useFrame((()=>{E.enabled&&E.update()}),-1),C.useEffect((()=>(E.connect(w),()=>{E.dispose()})),[w,n,E,d]),C.useEffect((()=>{const e=e=>{d(),n&&g.regress(),a&&a(e)};return E.addEventListener("change",e),i&&E.addEventListener("start",i),s&&E.addEventListener("end",s),()=>{i&&E.removeEventListener("start",i),s&&E.removeEventListener("end",s),E.removeEventListener("change",e)}}),[a,i,s,E,d]),C.useEffect((()=>{E.handleResize()}),[x]),C.useEffect((()=>{if(e){const e=v().controls;return h({controls:E}),()=>h({controls:e})}}),[e,E]),C.createElement("primitive",S.default({ref:c,object:E},l))})),qe=t.forwardRef((({camera:e,makeDefault:r,regress:n,domElement:a,onChange:i,onStart:s,onEnd:l,...c},d)=>{const m=o.useThree((e=>e.invalidate)),f=o.useThree((e=>e.camera)),p=o.useThree((e=>e.gl)),h=o.useThree((e=>e.events)),v=o.useThree((e=>e.set)),g=o.useThree((e=>e.get)),x=o.useThree((e=>e.performance)),y=e||f,w=a||h.connected||p.domElement,E=t.useMemo((()=>new u.ArcballControls(y)),[y]);return o.useFrame((()=>{E.enabled&&E.update()}),-1),t.useEffect((()=>(E.connect(w),()=>{E.dispose()})),[w,n,E,m]),t.useEffect((()=>{const e=e=>{m(),n&&x.regress(),i&&i(e)};return E.addEventListener("change",e),s&&E.addEventListener("start",s),l&&E.addEventListener("end",l),()=>{E.removeEventListener("change",e),s&&E.removeEventListener("start",s),l&&E.removeEventListener("end",l)}}),[i,s,l]),t.useEffect((()=>{if(r){const e=g().controls;return v({controls:E}),()=>v({controls:e})}}),[r,E]),C.createElement("primitive",S.default({ref:d,object:E},c))})),Xe=C.forwardRef((({children:e,domElement:t,onChange:r,onMouseDown:n,onMouseUp:a,onObjectChange:i,object:s,makeDefault:l,...c},d)=>{const m=["enabled","axis","mode","translationSnap","rotationSnap","scaleSnap","space","size","showX","showY","showZ"],{camera:f,...p}=c,h=z.default(p,m),v=k.default(p,m),g=o.useThree((e=>e.controls)),x=o.useThree((e=>e.gl)),y=o.useThree((e=>e.events)),w=o.useThree((e=>e.camera)),E=o.useThree((e=>e.invalidate)),b=o.useThree((e=>e.get)),M=o.useThree((e=>e.set)),T=f||w,R=t||y.connected||x.domElement,D=C.useMemo((()=>new u.TransformControls(T,R)),[T,R]),_=C.useRef();C.useLayoutEffect((()=>(s?D.attach(s instanceof P.Object3D?s:s.current):_.current instanceof P.Object3D&&D.attach(_.current),()=>{D.detach()})),[s,e,D]),C.useEffect((()=>{if(g){const e=e=>g.enabled=!e.value;return D.addEventListener("dragging-changed",e),()=>D.removeEventListener("dragging-changed",e)}}),[D,g]);const F=C.useRef(),L=C.useRef(),A=C.useRef(),B=C.useRef();return C.useLayoutEffect((()=>{F.current=r}),[r]),C.useLayoutEffect((()=>{L.current=n}),[n]),C.useLayoutEffect((()=>{A.current=a}),[a]),C.useLayoutEffect((()=>{B.current=i}),[i]),C.useEffect((()=>{const e=e=>{E(),null==F.current||F.current(e)},t=e=>null==L.current?void 0:L.current(e),r=e=>null==A.current?void 0:A.current(e),n=e=>null==B.current?void 0:B.current(e);return D.addEventListener("change",e),D.addEventListener("mouseDown",t),D.addEventListener("mouseUp",r),D.addEventListener("objectChange",n),()=>{D.removeEventListener("change",e),D.removeEventListener("mouseDown",t),D.removeEventListener("mouseUp",r),D.removeEventListener("objectChange",n)}}),[E,D]),C.useEffect((()=>{if(l){const e=b().controls;return M({controls:D}),()=>M({controls:e})}}),[l,D]),D?C.createElement(C.Fragment,null,C.createElement("primitive",S.default({ref:d,object:D},h)),C.createElement("group",S.default({ref:_},v),e)):null})),Ye=C.forwardRef((({domElement:e,selector:t,onChange:r,onLock:n,onUnlock:a,enabled:i=!0,makeDefault:s,...l},c)=>{const{camera:d,...m}=l,f=o.useThree((e=>e.setEvents)),p=o.useThree((e=>e.gl)),h=o.useThree((e=>e.camera)),v=o.useThree((e=>e.invalidate)),g=o.useThree((e=>e.events)),x=o.useThree((e=>e.get)),y=o.useThree((e=>e.set)),w=d||h,E=e||g.connected||p.domElement,[b]=C.useState((()=>new u.PointerLockControls(w)));return C.useEffect((()=>{if(i){b.connect(E);const e=x().events.compute;return f({compute(e,t){const r=t.size.width/2,n=t.size.height/2;t.pointer.set(r/t.size.width*2-1,-n/t.size.height*2+1),t.raycaster.setFromCamera(t.pointer,t.camera)}}),()=>{b.disconnect(),f({compute:e})}}}),[i,b]),C.useEffect((()=>{const e=e=>{v(),r&&r(e)};b.addEventListener("change",e),n&&b.addEventListener("lock",n),a&&b.addEventListener("unlock",a);const o=()=>b.lock(),i=t?Array.from(document.querySelectorAll(t)):[document];return i.forEach((e=>e&&e.addEventListener("click",o))),()=>{b.removeEventListener("change",e),n&&b.addEventListener("lock",n),a&&b.addEventListener("unlock",a),i.forEach((e=>e?e.removeEventListener("click",o):void 0))}}),[r,n,a,t,b,v]),C.useEffect((()=>{if(s){const e=x().controls;return y({controls:b}),()=>y({controls:e})}}),[s,b]),C.createElement("primitive",S.default({ref:c,object:b},m))})),Ze=C.forwardRef((({domElement:e,makeDefault:t,...r},n)=>{const a=o.useThree((e=>e.camera)),i=o.useThree((e=>e.gl)),s=o.useThree((e=>e.events)),l=o.useThree((e=>e.get)),c=o.useThree((e=>e.set)),d=e||s.connected||i.domElement,[m]=C.useState((()=>new u.FirstPersonControls(a,d)));return C.useEffect((()=>{if(t){const e=l().controls;return c({controls:m}),()=>c({controls:e})}}),[t,m]),o.useFrame(((e,t)=>{m.update(t)}),-1),m?C.createElement("primitive",S.default({ref:n,object:m},r)):null}));function Ke({defaultScene:e,defaultCamera:t,renderPriority:r=1}){const{gl:n,scene:a,camera:i}=o.useThree();let s;return o.useFrame((()=>{s=n.autoClear,1===r&&(n.autoClear=!0,n.render(e,t)),n.autoClear=!1,n.clearDepth(),n.render(a,i),n.autoClear=s}),r),C.createElement(C.Fragment,null)}function Qe({children:e,renderPriority:t=1}){const{scene:r,camera:n}=o.useThree(),[a]=C.useState((()=>new P.Scene));return C.createElement(C.Fragment,null,o.createPortal(C.createElement(C.Fragment,null,e,C.createElement(Ke,{defaultScene:r,defaultCamera:n,renderPriority:t})),a,{events:{priority:t+1}}))}const Je=C.createContext({}),et=()=>C.useContext(Je),tt=2*Math.PI,rt=new n.Object3D,nt=new n.Matrix4,[ot,at]=[new n.Quaternion,new n.Quaternion],it=new n.Vector3,st=new n.Vector3,lt="#f0f0f0",ct="#999",ut="black",dt="black",mt=["Right","Left","Top","Bottom","Front","Back"],ft=e=>new n.Vector3(...e).multiplyScalar(.38),pt=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]].map(ft),ht=[.25,.25,.25],vt=[[1,1,0],[1,0,1],[1,0,-1],[1,-1,0],[0,1,1],[0,1,-1],[0,-1,1],[0,-1,-1],[-1,1,0],[-1,0,1],[-1,0,-1],[-1,-1,0]].map(ft),gt=vt.map((e=>e.toArray().map((e=>0==e?.5:.25)))),xt=({hover:e,index:t,font:r="20px Inter var, Arial, sans-serif",faces:a=mt,color:i=lt,hoverColor:s=ct,textColor:l=ut,strokeColor:c=dt,opacity:u=1})=>{const d=o.useThree((e=>e.gl)),m=C.useMemo((()=>{const e=document.createElement("canvas");e.width=128,e.height=128;const o=e.getContext("2d");return o.fillStyle=i,o.fillRect(0,0,e.width,e.height),o.strokeStyle=c,o.strokeRect(0,0,e.width,e.height),o.font=r,o.textAlign="center",o.fillStyle=l,o.fillText(a[t].toUpperCase(),64,76),new n.CanvasTexture(e)}),[t,a,r,i,l,c]);return C.createElement("meshLambertMaterial",{map:m,"map-encoding":d.outputEncoding,"map-anisotropy":d.capabilities.getMaxAnisotropy()||1,attach:`material-${t}`,color:e?s:"white",transparent:!0,opacity:u})},yt=e=>{const{tweenCamera:t}=et(),[r,n]=C.useState(null);return C.createElement("mesh",{onPointerOut:e=>{e.stopPropagation(),n(null)},onPointerMove:e=>{e.stopPropagation(),n(Math.floor(e.faceIndex/2))},onClick:e.onClick||(e=>{e.stopPropagation(),t(e.face.normal)})},[...Array(6)].map(((t,n)=>C.createElement(xt,S.default({key:n,index:n,hover:r===n},e)))),C.createElement("boxGeometry",null))},wt=({onClick:e,dimensions:t,position:r,hoverColor:n=ct})=>{const{tweenCamera:o}=et(),[a,i]=C.useState(!1);return C.createElement("mesh",{scale:1.01,position:r,onPointerOver:e=>{e.stopPropagation(),i(!0)},onPointerOut:e=>{e.stopPropagation(),i(!1)},onClick:e||(e=>{e.stopPropagation(),o(r)})},C.createElement("meshBasicMaterial",{color:a?n:"white",transparent:!0,opacity:.6,visible:a}),C.createElement("boxGeometry",{args:t}))};function Et({scale:e=[.8,.05,.05],color:t,rotation:r}){return C.createElement("group",{rotation:r},C.createElement("mesh",{position:[.4,0,0]},C.createElement("boxGeometry",{args:e}),C.createElement("meshBasicMaterial",{color:t,toneMapped:!1})))}function bt({onClick:e,font:t,disabled:r,arcStyle:a,label:i,labelColor:s,axisHeadScale:l=1,...c}){const u=o.useThree((e=>e.gl)),d=C.useMemo((()=>{const e=document.createElement("canvas");e.width=64,e.height=64;const r=e.getContext("2d");return r.beginPath(),r.arc(32,32,16,0,2*Math.PI),r.closePath(),r.fillStyle=a,r.fill(),i&&(r.font=t,r.textAlign="center",r.fillStyle=s,r.fillText(i,32,41)),new n.CanvasTexture(e)}),[a,i,s,t]),[m,f]=C.useState(!1),p=(i?1:.75)*(m?1.2:1)*l;return C.createElement("sprite",S.default({scale:p,onPointerOver:r?void 0:e=>{e.stopPropagation(),f(!0)},onPointerOut:r?void 0:e||(e=>{e.stopPropagation(),f(!1)})},c),C.createElement("spriteMaterial",{map:d,"map-encoding":u.outputEncoding,"map-anisotropy":u.capabilities.getMaxAnisotropy()||1,alphaTest:.3,opacity:i?1:.75,toneMapped:!1}))}const Mt=he({cellSize:.5,sectionSize:1,fadeDistance:100,fadeStrength:1,cellThickness:.5,sectionThickness:1,cellColor:new P.Color,sectionColor:new P.Color,infiniteGrid:0,followCamera:0},"varying vec3 worldPosition;\n uniform float fadeDistance;\n uniform float infiniteGrid;\n uniform float followCamera;\n void main() {\n vec3 pos = position.xzy * (1. + fadeDistance * infiniteGrid);\n pos.xz += (cameraPosition.xz * followCamera);\n worldPosition = pos;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);\n }","varying vec3 worldPosition;\n uniform float cellSize;\n uniform float sectionSize;\n uniform vec3 cellColor;\n uniform vec3 sectionColor;\n uniform float fadeDistance;\n uniform float fadeStrength;\n uniform float cellThickness;\n uniform float sectionThickness;\n uniform float infiniteGrid;\n float getGrid(float size, float thickness) {\n vec2 r = worldPosition.xz / size;\n vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n float line = min(grid.x, grid.y) + 1. - thickness;\n return 1.0 - min(line, 1.);\n }\n void main() {\n float g1 = getGrid(cellSize, cellThickness);\n float g2 = getGrid(sectionSize, sectionThickness);\n float d = 1.0 - min(distance(cameraPosition.xz, worldPosition.xz) / fadeDistance, 1.);\n vec3 color = mix(cellColor, sectionColor, min(1.,sectionThickness * g2));\n gl_FragColor = vec4(color, (g1 + g2) * pow(d,fadeStrength));\n gl_FragColor.a = mix(0.75 * gl_FragColor.a, gl_FragColor.a, g2);\n if (gl_FragColor.a <= 0.0) discard;\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }"),St=C.forwardRef((({args:e,cellColor:t="#000000",sectionColor:r="#2080ff",cellSize:n=.5,sectionSize:a=1,followCamera:i=!1,infiniteGrid:s=!1,fadeDistance:l=100,fadeStrength:c=1,cellThickness:u=.5,sectionThickness:d=1,...m},f)=>{o.extend({GridMaterial:Mt});const p={cellSize:n,sectionSize:a,cellColor:t,sectionColor:r,cellThickness:u,sectionThickness:d},h={fadeDistance:l,fadeStrength:c,infiniteGrid:s,followCamera:i};return C.createElement("mesh",S.default({ref:f,frustumCulled:!1},m),C.createElement("gridMaterial",S.default({transparent:!0,"extensions-derivatives":!0,side:P.DoubleSide},p,h)),C.createElement("planeGeometry",{args:e}))}));function Ct(e,{path:t}){const[r]=o.useLoader(n.CubeTextureLoader,[e],(e=>e.setPath(t)));return r}function Tt(e){return o.useLoader(u.FBXLoader,e)}Ct.preload=(e,{path:t})=>o.useLoader.preload(n.CubeTextureLoader,[e],(e=>e.setPath(t))),Tt.preload=e=>o.useLoader.preload(u.FBXLoader,e),Tt.clear=e=>o.useLoader.clear(u.FBXLoader,e);const Pt="https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master";function Rt(e,r=`${Pt}/basis/`){const n=o.useThree((e=>e.gl)),a=o.useLoader(u.KTX2Loader,ve(e)?Object.values(e):e,(e=>{e.detectSupport(n),e.setTranscoderPath(r)}));if(t.useEffect((()=>{(Array.isArray(a)?a:[a]).forEach(n.initTexture)}),[n,a]),ve(e)){const t=Object.keys(e),r={};return t.forEach((e=>Object.assign(r,{[e]:a[t.indexOf(e)]}))),r}return a}function Dt(e,t){"function"==typeof e?e(t):null!=e&&(e.current=t)}Rt.preload=(e,t=`${Pt}/basis/`)=>o.useLoader.preload(u.KTX2Loader,e,(e=>{e.setTranscoderPath(t)})),Rt.clear=e=>o.useLoader.clear(u.KTX2Loader,e);const _t=new P.Box3,zt=new P.Vector3;const kt=e=>Math.sqrt(1-Math.pow(e-1,2));class Ft{constructor({size:e=256,maxAge:t=750,radius:r=.3,intensity:n=.2,interpolate:o=0,smoothing:a=0,minForce:i=.3,blend:s="screen",ease:l=kt}={}){this.size=e,this.maxAge=t,this.radius=r,this.intensity=n,this.ease=l,this.interpolate=o,this.smoothing=a,this.minForce=i,this.blend=s,this.trail=[],this.force=0,this.initTexture()}initTexture(){this.canvas=document.createElement("canvas"),this.canvas.width=this.canvas.height=this.size,this.ctx=this.canvas.getContext("2d"),this.ctx.fillStyle="black",this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height),this.texture=new n.Texture(this.canvas),this.canvas.id="touchTexture",this.canvas.style.width=this.canvas.style.height=`${this.canvas.width}px`}update(e){this.clear(),this.trail.forEach(((t,r)=>{t.age+=1e3*e,t.age>this.maxAge&&this.trail.splice(r,1)})),this.trail.length||(this.force=0),this.trail.forEach((e=>{this.drawTouch(e)})),this.texture.needsUpdate=!0}clear(){this.ctx.globalCompositeOperation="source-over",this.ctx.fillStyle="black",this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}addTouch(e){const t=this.trail[this.trail.length-1];if(t){const r=t.x-e.x,n=t.y-e.y,o=r*r+n*n,a=Math.max(this.minForce,Math.min(1e4*o,1));if(this.force=function(e,t,r=.9){return t*r+e*(1-r)}(a,this.force,this.smoothing),this.interpolate){const e=Math.ceil(o/Math.pow(.5*this.radius/this.interpolate,2));if(e>1)for(let o=1;o<e;o++)this.trail.push({x:t.x-r/e*o,y:t.y-n/e*o,age:0,force:a})}}this.trail.push({x:e.x,y:e.y,age:0,force:this.force})}drawTouch(e){const t={x:e.x*this.size,y:(1-e.y)*this.size};let r=1;r=e.age<.3*this.maxAge?this.ease(e.age/(.3*this.maxAge)):this.ease(1-(e.age-.3*this.maxAge)/(.7*this.maxAge)),r*=e.force,this.ctx.globalCompositeOperation=this.blend;const n=this.size*this.radius*r,o=this.ctx.createRadialGradient(t.x,t.y,Math.max(0,.25*n),t.x,t.y,Math.max(0,n));o.addColorStop(0,`rgba(255, 255, 255, ${this.intensity})`),o.addColorStop(1,"rgba(0, 0, 0, 0.0)"),this.ctx.beginPath(),this.ctx.fillStyle=o,this.ctx.arc(t.x,t.y,Math.max(0,n),0,2*Math.PI),this.ctx.fill()}}const Lt=C.forwardRef((({children:e,curve:t},r)=>{const[n]=C.useState((()=>new P.Scene)),[a,i]=C.useState(),s=C.useRef();return C.useEffect((()=>{s.current=new u.Flow(n.children[0]),i(s.current.object3D)}),[e]),C.useEffect((()=>{var e;t&&(null==(e=s.current)||e.updateCurve(0,t))}),[t]),C.useImperativeHandle(r,(()=>({moveAlongCurve:e=>{var t;null==(t=s.current)||t.moveAlongCurve(e)}}))),C.createElement(C.Fragment,null,o.createPortal(e,n),a&&C.createElement("primitive",{object:a}))}));class At extends n.MeshPhysicalMaterial{constructor(e={}){super(e),this.setValues(e),this._time={value:0},this._distort={value:.4},this._radius={value:1}}onBeforeCompile(e){e.uniforms.time=this._time,e.uniforms.radius=this._radius,e.uniforms.distort=this._distort,e.vertexShader=`\n uniform float time;\n uniform float radius;\n uniform float distort;\n #define GLSLIFY 1\nvec3 mod289(vec3 x){return x-floor(x*(1.0/289.0))*289.0;}vec4 mod289(vec4 x){return x-floor(x*(1.0/289.0))*289.0;}vec4 permute(vec4 x){return mod289(((x*34.0)+1.0)*x);}vec4 taylorInvSqrt(vec4 r){return 1.79284291400159-0.85373472095314*r;}float snoise(vec3 v){const vec2 C=vec2(1.0/6.0,1.0/3.0);const vec4 D=vec4(0.0,0.5,1.0,2.0);vec3 i=floor(v+dot(v,C.yyy));vec3 x0=v-i+dot(i,C.xxx);vec3 g=step(x0.yzx,x0.xyz);vec3 l=1.0-g;vec3 i1=min(g.xyz,l.zxy);vec3 i2=max(g.xyz,l.zxy);vec3 x1=x0-i1+C.xxx;vec3 x2=x0-i2+C.yyy;vec3 x3=x0-D.yyy;i=mod289(i);vec4 p=permute(permute(permute(i.z+vec4(0.0,i1.z,i2.z,1.0))+i.y+vec4(0.0,i1.y,i2.y,1.0))+i.x+vec4(0.0,i1.x,i2.x,1.0));float n_=0.142857142857;vec3 ns=n_*D.wyz-D.xzx;vec4 j=p-49.0*floor(p*ns.z*ns.z);vec4 x_=floor(j*ns.z);vec4 y_=floor(j-7.0*x_);vec4 x=x_*ns.x+ns.yyyy;vec4 y=y_*ns.x+ns.yyyy;vec4 h=1.0-abs(x)-abs(y);vec4 b0=vec4(x.xy,y.xy);vec4 b1=vec4(x.zw,y.zw);vec4 s0=floor(b0)*2.0+1.0;vec4 s1=floor(b1)*2.0+1.0;vec4 sh=-step(h,vec4(0.0));vec4 a0=b0.xzyw+s0.xzyw*sh.xxyy;vec4 a1=b1.xzyw+s1.xzyw*sh.zzww;vec3 p0=vec3(a0.xy,h.x);vec3 p1=vec3(a0.zw,h.y);vec3 p2=vec3(a1.xy,h.z);vec3 p3=vec3(a1.zw,h.w);vec4 norm=taylorInvSqrt(vec4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));p0*=norm.x;p1*=norm.y;p2*=norm.z;p3*=norm.w;vec4 m=max(0.6-vec4(dot(x0,x0),dot(x1,x1),dot(x2,x2),dot(x3,x3)),0.0);m=m*m;return 42.0*dot(m*m,vec4(dot(p0,x0),dot(p1,x1),dot(p2,x2),dot(p3,x3)));}\n ${e.vertexShader}\n `,e.vertexShader=e.vertexShader.replace("#include <begin_vertex>","\n float updateTime = time / 50.0;\n float noise = snoise(vec3(position / 2.0 + updateTime * 5.0));\n vec3 transformed = vec3(position * (noise * pow(distort, 2.0) + radius));\n ")}get time(){return this._time.value}set time(e){this._time.value=e}get distort(){return this._distort.value}set distort(e){this._distort.value=e}get radius(){return this._radius.value}set radius(e){this._radius.value=e}}const Bt=C.forwardRef((({speed:e=1,...t},r)=>{const[n]=C.useState((()=>new At));return o.useFrame((t=>n&&(n.time=t.clock.getElapsedTime()*e))),C.createElement("primitive",S.default({object:n,ref:r,attach:"material"},t))}));class Ut extends n.MeshStandardMaterial{constructor(e={}){super(e),this.setValues(e),this._time={value:0},this._factor={value:1}}onBeforeCompile(e){e.uniforms.time=this._time,e.uniforms.factor=this._factor,e.vertexShader=`\n uniform float time;\n uniform float factor;\n ${e.vertexShader}\n `,e.vertexShader=e.vertexShader.replace("#include <begin_vertex>","float theta = sin( time + position.y ) / 2.0 * factor;\n float c = cos( theta );\n float s = sin( theta );\n mat3 m = mat3( c, 0, s, 0, 1, 0, -s, 0, c );\n vec3 transformed = vec3( position ) * m;\n vNormal = vNormal * m;")}get time(){return this._time.value}set time(e){this._time.value=e}get factor(){return this._factor.value}set factor(e){this._factor.value=e}}const Vt=C.forwardRef((({speed:e=1,...t},r)=>{const[n]=C.useState((()=>new Ut));return o.useFrame((t=>n&&(n.time=t.clock.getElapsedTime()*e))),C.createElement("primitive",S.default({object:n,ref:r,attach:"material"},t))}));class It extends n.ShaderMaterial{constructor(e=new n.Vector2){super({uniforms:{inputBuffer:new n.Uniform(null),depthBuffer:new n.Uniform(null),resolution:new n.Uniform(new n.Vector2),texelSize:new n.Uniform(new n.Vector2),halfTexelSize:new n.Uniform(new n.Vector2),kernel:new n.Uniform(0),scale:new n.Uniform(1),cameraNear:new n.Uniform(0),cameraFar:new n.Uniform(1),minDepthThreshold:new n.Uniform(0),maxDepthThreshold:new n.Uniform(1),depthScale:new n.Uniform(0),depthToBlurRatioBias:new n.Uniform(.25)},fragmentShader:"#include <common>\n #include <dithering_pars_fragment> \n uniform sampler2D inputBuffer;\n uniform sampler2D depthBuffer;\n uniform float cameraNear;\n uniform float cameraFar;\n uniform float minDepthThreshold;\n uniform float maxDepthThreshold;\n uniform float depthScale;\n uniform float depthToBlurRatioBias;\n varying vec2 vUv;\n varying vec2 vUv0;\n varying vec2 vUv1;\n varying vec2 vUv2;\n varying vec2 vUv3;\n\n void main() {\n float depthFactor = 0.0;\n \n #ifdef USE_DEPTH\n vec4 depth = texture2D(depthBuffer, vUv);\n depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));\n depthFactor *= depthScale;\n depthFactor = max(0.0, min(1.0, depthFactor + 0.25));\n #endif\n \n vec4 sum = texture2D(inputBuffer, mix(vUv0, vUv, depthFactor));\n sum += texture2D(inputBuffer, mix(vUv1, vUv, depthFactor));\n sum += texture2D(inputBuffer, mix(vUv2, vUv, depthFactor));\n sum += texture2D(inputBuffer, mix(vUv3, vUv, depthFactor));\n gl_FragColor = sum * 0.25 ;\n\n #include <dithering_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }",vertexShader:"uniform vec2 texelSize;\n uniform vec2 halfTexelSize;\n uniform float kernel;\n uniform float scale;\n varying vec2 vUv;\n varying vec2 vUv0;\n varying vec2 vUv1;\n varying vec2 vUv2;\n varying vec2 vUv3;\n\n void main() {\n vec2 uv = position.xy * 0.5 + 0.5;\n vUv = uv;\n\n vec2 dUv = (texelSize * vec2(kernel) + halfTexelSize) * scale;\n vUv0 = vec2(uv.x - dUv.x, uv.y + dUv.y);\n vUv1 = vec2(uv.x + dUv.x, uv.y + dUv.y);\n vUv2 = vec2(uv.x + dUv.x, uv.y - dUv.y);\n vUv3 = vec2(uv.x - dUv.x, uv.y - dUv.y);\n\n gl_Position = vec4(position.xy, 1.0, 1.0);\n }",blending:n.NoBlending,depthWrite:!1,depthTest:!1}),this.toneMapped=!1,this.setTexelSize(e.x,e.y),this.kernel=new Float32Array([0,1,2,2,3])}setTexelSize(e,t){this.uniforms.texelSize.value.set(e,t),this.uniforms.halfTexelSize.value.set(e,t).multiplyScalar(.5)}setResolution(e){this.uniforms.resolution.value.copy(e)}}class Ot{constructor({gl:e,resolution:t,width:r=500,height:o=500,minDepthThreshold:a=0,maxDepthThreshold:i=1,depthScale:s=0,depthToBlurRatioBias:l=.25}){this.renderToScreen=!1,this.renderTargetA=new n.WebGLRenderTarget(t,t,{minFilter:n.LinearFilter,magFilter:n.LinearFilter,stencilBuffer:!1,depthBuffer:!1,encoding:e.outputEncoding}),this.renderTargetB=this.renderTargetA.clone(),this.convolutionMaterial=new It,this.convolutionMaterial.setTexelSize(1/r,1/o),this.convolutionMaterial.setResolution(new n.Vector2(r,o)),this.scene=new n.Scene,this.camera=new n.Camera,this.convolutionMaterial.uniforms.minDepthThreshold.value=a,this.convolutionMaterial.uniforms.maxDepthThreshold.value=i,this.convolutionMaterial.uniforms.depthScale.value=s,this.convolutionMaterial.uniforms.depthToBlurRatioBias.value=l,this.convolutionMaterial.defines.USE_DEPTH=s>0;const c=new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),u=new Float32Array([0,0,2,0,0,2]),d=new n.BufferGeometry;d.setAttribute("position",new n.BufferAttribute(c,3)),d.setAttribute("uv",new n.BufferAttribute(u,2)),this.screen=new n.Mesh(d,this.convolutionMaterial),this.screen.frustumCulled=!1,this.scene.add(this.screen)}render(e,t,r){const n=this.scene,o=this.camera,a=this.renderTargetA,i=this.renderTargetB;let s=this.convolutionMaterial,l=s.uniforms;l.depthBuffer.value=t.depthTexture;const c=s.kernel;let u,d,m,f=t;for(d=0,m=c.length-1;d<m;++d)u=0==(1&d)?a:i,l.kernel.value=c[d],l.inputBuffer.value=f.texture,e.setRenderTarget(u),e.render(n,o),f=u;l.kernel.value=c[d],l.inputBuffer.value=f.texture,e.setRenderTarget(this.renderToScreen?null:r),e.render(n,o)}}class jt extends n.MeshStandardMaterial{constructor(e={}){super(e),this._tDepth={value:null},this._distortionMap={value:null},this._tDiffuse={value:null},this._tDiffuseBlur={value:null},this._textureMatrix={value:null},this._hasBlur={value:!1},this._mirror={value:0},this._mixBlur={value:0},this._blurStrength={value:.5},this._minDepthThreshold={value:.9},this._maxDepthThreshold={value:1},this._depthScale={value:0},this._depthToBlurRatioBias={value:.25},this._distortion={value:1},this._mixContrast={value:1},this.setValues(e)}onBeforeCompile(e){var t;null!=(t=e.defines)&&t.USE_UV||(e.defines.USE_UV=""),e.uniforms.hasBlur=this._hasBlur,e.uniforms.tDiffuse=this._tDiffuse,e.uniforms.tDepth=this._tDepth,e.uniforms.distortionMap=this._distortionMap,e.uniforms.tDiffuseBlur=this._tDiffuseBlur,e.uniforms.textureMatrix=this._textureMatrix,e.uniforms.mirror=this._mirror,e.uniforms.mixBlur=this._mixBlur,e.uniforms.mixStrength=this._blurStrength,e.uniforms.minDepthThreshold=this._minDepthThreshold,e.uniforms.maxDepthThreshold=this._maxDepthThreshold,e.uniforms.depthScale=this._depthScale,e.uniforms.depthToBlurRatioBias=this._depthToBlurRatioBias,e.uniforms.distortion=this._distortion,e.uniforms.mixContrast=this._mixContrast,e.vertexShader=`\n uniform mat4 textureMatrix;\n varying vec4 my_vUv;\n ${e.vertexShader}`,e.vertexShader=e.vertexShader.replace("#include <project_vertex>","#include <project_vertex>\n my_vUv = textureMatrix * vec4( position, 1.0 );\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );"),e.fragmentShader=`\n uniform sampler2D tDiffuse;\n uniform sampler2D tDiffuseBlur;\n uniform sampler2D tDepth;\n uniform sampler2D distortionMap;\n uniform float distortion;\n uniform float cameraNear;\n\t\t\t uniform float cameraFar;\n uniform bool hasBlur;\n uniform float mixBlur;\n uniform float mirror;\n uniform float mixStrength;\n uniform float minDepthThreshold;\n uniform float maxDepthThreshold;\n uniform float mixContrast;\n uniform float depthScale;\n uniform float depthToBlurRatioBias;\n varying vec4 my_vUv;\n ${e.fragmentShader}`,e.fragmentShader=e.fragmentShader.replace("#include <emissivemap_fragment>","#include <emissivemap_fragment>\n\n float distortionFactor = 0.0;\n #ifdef USE_DISTORTION\n distortionFactor = texture2D(distortionMap, vUv).r * distortion;\n #endif\n\n vec4 new_vUv = my_vUv;\n new_vUv.x += distortionFactor;\n new_vUv.y += distortionFactor;\n\n vec4 base = texture2DProj(tDiffuse, new_vUv);\n vec4 blur = texture2DProj(tDiffuseBlur, new_vUv);\n\n vec4 merge = base;\n\n #ifdef USE_NORMALMAP\n vec2 normal_uv = vec2(0.0);\n vec4 normalColor = texture2D(normalMap, vUv * normalScale);\n vec3 my_normal = normalize( vec3( normalColor.r * 2.0 - 1.0, normalColor.b, normalColor.g * 2.0 - 1.0 ) );\n vec3 coord = new_vUv.xyz / new_vUv.w;\n normal_uv = coord.xy + coord.z * my_normal.xz * 0.05;\n vec4 base_normal = texture2D(tDiffuse, normal_uv);\n vec4 blur_normal = texture2D(tDiffuseBlur, normal_uv);\n merge = base_normal;\n blur = blur_normal;\n #endif\n\n float depthFactor = 0.0001;\n float blurFactor = 0.0;\n\n #ifdef USE_DEPTH\n vec4 depth = texture2DProj(tDepth, new_vUv);\n depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));\n depthFactor *= depthScale;\n depthFactor = max(0.0001, min(1.0, depthFactor));\n\n #ifdef USE_BLUR\n blur = blur * min(1.0, depthFactor + depthToBlurRatioBias);\n merge = merge * min(1.0, depthFactor + 0.5);\n #else\n merge = merge * depthFactor;\n #endif\n\n #endif\n\n float reflectorRoughnessFactor = roughness;\n #ifdef USE_ROUGHNESSMAP\n vec4 reflectorTexelRoughness = texture2D( roughnessMap, vUv );\n reflectorRoughnessFactor *= reflectorTexelRoughness.g;\n #endif\n\n #ifdef USE_BLUR\n blurFactor = min(1.0, mixBlur * reflectorRoughnessFactor);\n merge = mix(merge, blur, blurFactor);\n #endif\n\n vec4 newMerge = vec4(0.0, 0.0, 0.0, 1.0);\n newMerge.r = (merge.r - 0.5) * mixContrast + 0.5;\n newMerge.g = (merge.g - 0.5) * mixContrast + 0.5;\n newMerge.b = (merge.b - 0.5) * mixContrast + 0.5;\n\n diffuseColor.rgb = diffuseColor.rgb * ((1.0 - min(1.0, mirror)) + newMerge.rgb * mixStrength);\n ")}get tDiffuse(){return this._tDiffuse.value}set tDiffuse(e){this._tDiffuse.value=e}get tDepth(){return this._tDepth.value}set tDepth(e){this._tDepth.value=e}get distortionMap(){return this._distortionMap.value}set distortionMap(e){this._distortionMap.value=e}get tDiffuseBlur(){return this._tDiffuseBlur.value}set tDiffuseBlur(e){this._tDiffuseBlur.value=e}get textureMatrix(){return this._textureMatrix.value}set textureMatrix(e){this._textureMatrix.value=e}get hasBlur(){return this._hasBlur.value}set hasBlur(e){this._hasBlur.value=e}get mirror(){return this._mirror.value}set mirror(e){this._mirror.value=e}get mixBlur(){return this._mixBlur.value}set mixBlur(e){this._mixBlur.value=e}get mixStrength(){return this._blurStrength.value}set mixStrength(e){this._blurStrength.value=e}get minDepthThreshold(){return this._minDepthThreshold.value}set minDepthThreshold(e){this._minDepthThreshold.value=e}get maxDepthThreshold(){return this._maxDepthThreshold.value}set maxDepthThreshold(e){this._maxDepthThreshold.value=e}get depthScale(){return this._depthScale.value}set depthScale(e){this._depthScale.value=e}get depthToBlurRatioBias(){return this._depthToBlurRatioBias.value}set depthToBlurRatioBias(e){this._depthToBlurRatioBias.value=e}get distortion(){return this._distortion.value}set distortion(e){this._distortion.value=e}get mixContrast(){return this._mixContrast.value}set mixContrast(e){this._mixContrast.value=e}}o.extend({MeshReflectorMaterialImpl:jt});const Wt=C.forwardRef((({mixBlur:e=0,mixStrength:t=1,resolution:r=256,blur:a=[0,0],minDepthThreshold:i=.9,maxDepthThreshold:s=1,depthScale:l=0,depthToBlurRatioBias:c=.25,mirror:u=0,distortion:d=1,mixContrast:m=1,distortionMap:f,reflectorOffset:p=0,...h},v)=>{const g=o.useThree((({gl:e})=>e)),x=o.useThree((({camera:e})=>e)),y=o.useThree((({scene:e})=>e)),w=(a=Array.isArray(a)?a:[a,a])[0]+a[1]>0,E=C.useRef(null),[b]=C.useState((()=>new n.Plane)),[M]=C.useState((()=>new n.Vector3)),[T]=C.useState((()=>new n.Vector3)),[P]=C.useState((()=>new n.Vector3)),[R]=C.useState((()=>new n.Matrix4)),[_]=C.useState((()=>new n.Vector3(0,0,-1))),[z]=C.useState((()=>new n.Vector4)),[k]=C.useState((()=>new n.Vector3)),[F]=C.useState((()=>new n.Vector3)),[L]=C.useState((()=>new n.Vector4)),[A]=C.useState((()=>new n.Matrix4)),[B]=C.useState((()=>new n.PerspectiveCamera)),U=C.useCallback((()=>{var e;const t=E.current.parent||(null==(e=E.current)?void 0:e.__r3f.parent);if(!t)return;if(T.setFromMatrixPosition(t.matrixWorld),P.setFromMatrixPosition(x.matrixWorld),R.extractRotation(t.matrixWorld),M.set(0,0,1),M.applyMatrix4(R),T.addScaledVector(M,p),k.subVectors(T,P),k.dot(M)>0)return;k.reflect(M).negate(),k.add(T),R.extractRotation(x.matrixWorld),_.set(0,0,-1),_.applyMatrix4(R),_.add(P),F.subVectors(T,_),F.reflect(M).negate(),F.add(T),B.position.copy(k),B.up.set(0,1,0),B.up.applyMatrix4(R),B.up.reflect(M),B.lookAt(F),B.far=x.far,B.updateMatrixWorld(),B.projectionMatrix.copy(x.projectionMatrix),A.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),A.multiply(B.projectionMatrix),A.multiply(B.matrixWorldInverse),A.multiply(t.matrixWorld),b.setFromNormalAndCoplanarPoint(M,T),b.applyMatrix4(B.matrixWorldInverse),z.set(b.normal.x,b.normal.y,b.normal.z,b.constant);const r=B.projectionMatrix;L.x=(Math.sign(z.x)+r.elements[8])/r.elements[0],L.y=(Math.sign(z.y)+r.elements[9])/r.elements[5],L.z=-1,L.w=(1+r.elements[10])/r.elements[14],z.multiplyScalar(2/z.dot(L)),r.elements[2]=z.x,r.elements[6]=z.y,r.elements[10]=z.z+1,r.elements[14]=z.w}),[x,p]),[V,I,O,j]=C.useMemo((()=>{const o={minFilter:n.LinearFilter,magFilter:n.LinearFilter,encoding:g.outputEncoding,type:n.HalfFloatType},p=new n.WebGLRenderTarget(r,r,o);p.depthBuffer=!0,p.depthTexture=new n.DepthTexture(r,r),p.depthTexture.format=n.DepthFormat,p.depthTexture.type=n.UnsignedShortType;const h=new n.WebGLRenderTarget(r,r,o);return[p,h,new Ot({gl:g,resolution:r,width:a[0],height:a[1],minDepthThreshold:i,maxDepthThreshold:s,depthScale:l,depthToBlurRatioBias:c}),{mirror:u,textureMatrix:A,mixBlur:e,tDiffuse:p.texture,tDepth:p.depthTexture,tDiffuseBlur:h.texture,hasBlur:w,mixStrength:t,minDepthThreshold:i,maxDepthThreshold:s,depthScale:l,depthToBlurRatioBias:c,distortion:d,distortionMap:f,mixContrast:m,"defines-USE_BLUR":w?"":void 0,"defines-USE_DEPTH":l>0?"":void 0,"defines-USE_DISTORTION":f?"":void 0}]}),[g,a,A,r,u,w,e,t,i,s,l,c,d,f,m]);return o.useFrame((()=>{var e;const t=E.current.parent||(null==(e=E.current)?void 0:e.__r3f.parent);if(!t)return;t.visible=!1;const r=g.xr.enabled,n=g.shadowMap.autoUpdate;U(),g.xr.enabled=!1,g.shadowMap.autoUpdate=!1,g.setRenderTarget(V),g.state.buffers.depth.setMask(!0),g.autoClear||g.clear(),g.render(y,B),w&&O.render(g,V,I),g.xr.enabled=r,g.shadowMap.autoUpdate=n,t.visible=!0,g.setRenderTarget(null)})),C.createElement("meshReflectorMaterialImpl",S.default({attach:"material",key:"key"+j["defines-USE_BLUR"]+j["defines-USE_DEPTH"]+j["defines-USE_DISTORTION"],ref:D.default([E,v])},j,h))})),Gt=he({envMap:null,bounces:3,ior:2.4,correctMips:!0,aberrationStrength:.01,fresnel:0,bvh:new y.MeshBVHUniformStruct,color:new P.Color("white"),resolution:new P.Vector2},"\n #ifndef USE_COLOR\n uniform vec3 color;\n #endif\n varying vec3 vWorldPosition; \n varying vec3 vNormal;\n varying mat4 projectionMatrixInv;\n varying mat4 viewMatrixInv;\n varying vec3 viewDirection;\n varying mat4 vInstanceMatrix;\n varying vec3 vColor;\n \n void main() { \n vec4 transformedNormal = vec4(normal, 0.0);\n vec4 transformedPosition = vec4(position, 1.0);\n #ifdef USE_INSTANCING\n vInstanceMatrix = instanceMatrix;\n transformedNormal = instanceMatrix * transformedNormal;\n transformedPosition = instanceMatrix * transformedPosition;\n #else\n vInstanceMatrix = mat4(1.0);\n #endif\n\n vColor = color;\n #ifdef USE_INSTANCING_COLOR\n vColor *= instanceColor.rgb;\n #endif\n \n projectionMatrixInv = inverse(projectionMatrix);\n viewMatrixInv = inverse(viewMatrix);\n\n vWorldPosition = (modelMatrix * transformedPosition).xyz;\n vNormal = normalize((viewMatrixInv * vec4(normalMatrix * transformedNormal.xyz, 0.0)).xyz);\n viewDirection = normalize(vWorldPosition - cameraPosition);\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * transformedPosition;\n }",`\n #define ENVMAP_TYPE_CUBE_UV\n precision highp isampler2D;\n precision highp usampler2D;\n varying vec3 vWorldPosition;\n varying vec3 vNormal;\n \n #ifdef ENVMAP_TYPE_CUBEM\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n \n uniform float bounces;\n ${y.shaderStructs}\n ${y.shaderIntersectFunction}\n uniform BVH bvh;\n uniform float ior;\n uniform bool correctMips;\n uniform vec2 resolution;\n uniform float fresnel;\n uniform mat4 modelMatrix;\n \n uniform float aberrationStrength;\n varying mat4 projectionMatrixInv;\n varying mat4 viewMatrixInv;\n varying vec3 viewDirection; \n varying mat4 vInstanceMatrix;\n varying vec3 vColor;\n \n float fresnelFunc(vec3 viewDirection, vec3 worldNormal) {\n return pow( 1.0 + dot( viewDirection, worldNormal), 10.0 );\n }\n \n vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 normal, float ior, mat4 modelMatrixInverse) {\n vec3 rayOrigin = ro;\n vec3 rayDirection = rd;\n rayDirection = refract(rayDirection, normal, 1.0 / ior);\n rayOrigin = vWorldPosition + rayDirection * 0.001;\n rayOrigin = (modelMatrixInverse * vec4(rayOrigin, 1.0)).xyz;\n rayDirection = normalize((modelMatrixInverse * vec4(rayDirection, 0.0)).xyz);\n for(float i = 0.0; i < bounces; i++) {\n uvec4 faceIndices = uvec4( 0u );\n vec3 faceNormal = vec3( 0.0, 0.0, 1.0 );\n vec3 barycoord = vec3( 0.0 );\n float side = 1.0;\n float dist = 0.0;\n bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist );\n vec3 hitPos = rayOrigin + rayDirection * max(dist - 0.001, 0.0); \n vec3 tempDir = refract(rayDirection, faceNormal, ior);\n if (length(tempDir) != 0.0) {\n rayDirection = tempDir;\n break;\n }\n rayDirection = reflect(rayDirection, faceNormal);\n rayOrigin = hitPos + rayDirection * 0.01;\n }\n rayDirection = normalize((modelMatrix * vec4(rayDirection, 0.0)).xyz);\n return rayDirection;\n }\n \n #include <common>\n #include <cube_uv_reflection_fragment>\n \n #ifdef ENVMAP_TYPE_CUBEM\n vec4 textureGradient(samplerCube envMap, vec3 rayDirection, vec3 directionCamPerfect) {\n return textureGrad(envMap, rayDirection, dFdx(correctMips ? directionCamPerfect: rayDirection), dFdy(correctMips ? directionCamPerfect: rayDirection));\n }\n #else\n vec4 textureGradient(sampler2D envMap, vec3 rayDirection, vec3 directionCamPerfect) {\n vec2 uvv = equirectUv( rayDirection );\n vec2 smoothUv = equirectUv( directionCamPerfect );\n return textureGrad(envMap, uvv, dFdx(correctMips ? smoothUv : uvv), dFdy(correctMips ? smoothUv : uvv));\n }\n #endif\n \n void main() {\n mat4 modelMatrixInverse = inverse(modelMatrix * vInstanceMatrix);\n vec2 uv = gl_FragCoord.xy / resolution;\n vec3 directionCamPerfect = (projectionMatrixInv * vec4(uv * 2.0 - 1.0, 0.0, 1.0)).xyz;\n directionCamPerfect = (viewMatrixInv * vec4(directionCamPerfect, 0.0)).xyz;\n directionCamPerfect = normalize(directionCamPerfect);\n vec3 normal = vNormal;\n vec3 rayOrigin = cameraPosition;\n vec3 rayDirection = normalize(vWorldPosition - cameraPosition);\n vec3 finalColor;\n #ifdef CHROMATIC_ABERRATIONS\n vec3 rayDirectionG = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), modelMatrixInverse);\n #ifdef FAST_CHROMA \n vec3 rayDirectionR = normalize(rayDirectionG + 1.0 * vec3(aberrationStrength / 2.0));\n vec3 rayDirectionB = normalize(rayDirectionG - 1.0 * vec3(aberrationStrength / 2.0));\n #else\n vec3 rayDirectionR = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 - aberrationStrength), 1.0), modelMatrixInverse);\n vec3 rayDirectionB = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 + aberrationStrength), 1.0), modelMatrixInverse);\n #endif\n float finalColorR = textureGradient(envMap, rayDirectionR, directionCamPerfect).r;\n float finalColorG = textureGradient(envMap, rayDirectionG, directionCamPerfect).g;\n float finalColorB = textureGradient(envMap, rayDirectionB, directionCamPerfect).b;\n finalColor = vec3(finalColorR, finalColorG, finalColorB) * vColor;\n #else\n rayDirection = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), modelMatrixInverse);\n finalColor = textureGradient(envMap, rayDirection, directionCamPerfect).rgb; \n finalColor *= vColor;\n #endif\n float nFresnel = fresnelFunc(viewDirection, normal) * fresnel;\n gl_FragColor = vec4(mix(finalColor, vec3(1.0), nFresnel), 1.0); \n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }`);class Nt extends P.MeshPhysicalMaterial{constructor({samples:e=6,...t}={}){super(t),this.uniforms={chromaticAberration:{value:.05},transmission:{value:1},thickness:{value:1},anisotropy:{value:.1},time:{value:0},distortion:{value:0},distortionScale:{value:.5},temporalDistortion:{value:.5},buffer:{value:null},resolution:{value:new P.Vector2}},this.onBeforeCompile=t=>{t.uniforms={...t.uniforms,...this.uniforms},t.fragmentShader="\n uniform float chromaticAberration;\n uniform vec2 resolution; \n uniform float anisotropy; \n uniform float time;\n uniform float distortion;\n uniform float distortionScale;\n uniform float temporalDistortion;\n uniform sampler2D buffer;\n \n vec3 sat(vec3 rgb, float adjustment) {\n const vec3 W = vec3(0.2125, 0.7154, 0.0721);\n vec3 intensity = vec3(dot(rgb, W));\n return mix(intensity, rgb, adjustment);\n }\n vec3 random3(vec3 c) {\n float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));\n vec3 r;\n r.z = fract(512.0*j);\n j *= .125;\n r.x = fract(512.0*j);\n j *= .125;\n r.y = fract(512.0*j);\n return r-0.5;\n }\n\n float seed = 0.0;\n uint hash( uint x ) {\n x += ( x << 10u );\n x ^= ( x >> 6u );\n x += ( x << 3u );\n x ^= ( x >> 11u );\n x += ( x << 15u );\n return x;\n }\n\n // Compound versions of the hashing algorithm I whipped together.\n uint hash( uvec2 v ) { return hash( v.x ^ hash(v.y) ); }\n uint hash( uvec3 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ); }\n uint hash( uvec4 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ^ hash(v.w) ); }\n\n // Construct a float with half-open range [0:1] using low 23 bits.\n // All zeroes yields 0.0, all ones yields the next smallest representable value below 1.0.\n float floatConstruct( uint m ) {\n const uint ieeeMantissa = 0x007FFFFFu; // binary32 mantissa bitmask\n const uint ieeeOne = 0x3F800000u; // 1.0 in IEEE binary32\n\n m &= ieeeMantissa; // Keep only mantissa bits (fractional part)\n m |= ieeeOne; // Add fractional part to 1.0\n\n float f = uintBitsToFloat( m ); // Range [1:2]\n return f - 1.0; // Range [0:1]\n }\n\n // Pseudo-random value in half-open range [0:1].\n float random( float x ) { return floatConstruct(hash(floatBitsToUint(x))); }\n float random( vec2 v ) { return floatConstruct(hash(floatBitsToUint(v))); }\n float random( vec3 v ) { return floatConstruct(hash(floatBitsToUint(v))); }\n float random( vec4 v ) { return floatConstruct(hash(floatBitsToUint(v))); }\n\n float rand() {\n float result = random(vec3(gl_FragCoord.xy, seed));\n seed += 1.0;\n return result;\n }\n\n const float F3 = 0.3333333;\n const float G3 = 0.1666667;\n\n float snoise(vec3 p) {\n vec3 s = floor(p + dot(p, vec3(F3)));\n vec3 x = p - s + dot(s, vec3(G3));\n vec3 e = step(vec3(0.0), x - x.yzx);\n vec3 i1 = e*(1.0 - e.zxy);\n vec3 i2 = 1.0 - e.zxy*(1.0 - e);\n vec3 x1 = x - i1 + G3;\n vec3 x2 = x - i2 + 2.0*G3;\n vec3 x3 = x - 1.0 + 3.0*G3;\n vec4 w, d;\n w.x = dot(x, x);\n w.y = dot(x1, x1);\n w.z = dot(x2, x2);\n w.w = dot(x3, x3);\n w = max(0.6 - w, 0.0);\n d.x = dot(random3(s), x);\n d.y = dot(random3(s + i1), x1);\n d.z = dot(random3(s + i2), x2);\n d.w = dot(random3(s + 1.0), x3);\n w *= w;\n w *= w;\n d *= w;\n return dot(d, vec4(52.0));\n }\n\n float snoiseFractal(vec3 m) {\n return 0.5333333* snoise(m)\n +0.2666667* snoise(2.0*m)\n +0.1333333* snoise(4.0*m)\n +0.0666667* snoise(8.0*m);\n }\n"+t.fragmentShader,t.fragmentShader=t.fragmentShader.replace("#include <transmission_pars_fragment>","\n #ifdef USE_TRANSMISSION\n // Transmission code is based on glTF-Sampler-Viewer\n // https://github.com/KhronosGroup/glTF-Sample-Viewer\n uniform float transmission;\n uniform float thickness;\n uniform float attenuationDistance;\n uniform vec3 attenuationColor;\n #ifdef USE_TRANSMISSIONMAP\n uniform sampler2D transmissionMap;\n #endif\n #ifdef USE_THICKNESSMAP\n uniform sampler2D thicknessMap;\n #endif\n uniform vec2 transmissionSamplerSize;\n uniform sampler2D transmissionSamplerMap;\n uniform mat4 modelMatrix;\n uniform mat4 projectionMatrix;\n varying vec3 vWorldPosition;\n vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n // Direction of refracted light.\n vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n // Compute rotation-independant scaling of the model matrix.\n vec3 modelScale;\n modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n // The thickness is specified in local space.\n return normalize( refractionVector ) * thickness * modelScale;\n }\n float applyIorToRoughness( const in float roughness, const in float ior ) {\n // Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and\n // an IOR of 1.5 results in the default amount of microfacet refraction.\n return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n }\n vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n return texture2D(buffer, fragCoord.xy);\n }\n vec3 applyVolumeAttenuation( const in vec3 radiance, const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n if ( isinf( attenuationDistance ) ) {\n // Attenuation distance is +∞, i.e. the transmitted color is not attenuated at all.\n return radiance;\n } else {\n // Compute light attenuation using Beer's law.\n vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); // Beer's law\n return transmittance * radiance;\n }\n }\n vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness,\n const in vec3 attenuationColor, const in float attenuationDistance ) {\n vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n vec3 refractedRayExit = position + transmissionRay;\n // Project refracted vector on the framebuffer, while mapping to normalized device coordinates.\n vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n vec2 refractionCoords = ndcPos.xy / ndcPos.w;\n refractionCoords += 1.0;\n refractionCoords /= 2.0;\n // Sample framebuffer to get pixel the refracted ray hits.\n vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n vec3 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );\n // Get the specular component.\n vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n return vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );\n }\n #endif\n"),t.fragmentShader=t.fragmentShader.replace("#include <transmission_fragment>",`\n vec2 uv = gl_FragCoord.xy / resolution.xy; \n // Improve the refraction to use the world pos\n material.transmission = transmission;\n material.transmissionAlpha = 1.0;\n material.thickness = thickness;\n material.attenuationDistance = attenuationDistance;\n material.attenuationColor = attenuationColor;\n #ifdef USE_TRANSMISSIONMAP\n material.transmission *= texture2D( transmissionMap, vUv ).r;\n #endif\n #ifdef USE_THICKNESSMAP\n material.thickness *= texture2D( thicknessMap, vUv ).g;\n #endif\n \n vec3 pos = vWorldPosition;\n vec3 v = normalize( cameraPosition - pos );\n vec3 n = inverseTransformDirection( normal, viewMatrix );\n vec3 transmission = vec3(0.0);\n float transmissionR, transmissionB, transmissionG;\n float randomCoords = rand();\n float thickness_smear = thickness * max(pow(roughness, 0.33), anisotropy);\n vec3 distortionNormal = vec3(0.0);\n vec3 temporalOffset = vec3(time, -time, -time) * temporalDistortion;\n if (distortion > 0.0) {\n distortionNormal = distortion * vec3(snoiseFractal(vec3((pos * distortionScale + temporalOffset))), snoiseFractal(vec3(pos.zxy * distortionScale - temporalOffset)), snoiseFractal(vec3(pos.yxz * distortionScale + temporalOffset)));\n }\n for (float i = 0.0; i < ${e}.0; i ++) {\n vec3 sampleNorm = normalize(n + roughness * roughness * 2.0 * normalize(vec3(rand() - 0.5, rand() - 0.5, rand() - 0.5)) * pow(rand(), 0.33) + distortionNormal);\n transmissionR = getIBLVolumeRefraction(\n sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior, material.thickness + thickness_smear * (i + randomCoords) / float(${e}),\n material.attenuationColor, material.attenuationDistance\n ).r;\n transmissionG = getIBLVolumeRefraction(\n sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior * (1.0 + chromaticAberration * (i + randomCoords) / float(${e})) , material.thickness + thickness_smear * (i + randomCoords) / float(${e}),\n material.attenuationColor, material.attenuationDistance\n ).g;\n transmissionB = getIBLVolumeRefraction(\n sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior * (1.0 + 2.0 * chromaticAberration * (i + randomCoords) / float(${e})), material.thickness + thickness_smear * (i + randomCoords) / float(${e}),\n material.attenuationColor, material.attenuationDistance\n ).b;\n transmission.r += transmissionR;\n transmission.g += transmissionG;\n transmission.b += transmissionB;\n }\n transmission /= ${e}.0;\n material.transmissionAlpha = 1.0;\n totalDiffuse = mix( totalDiffuse, transmission.rgb, material.transmission );\n`)},Object.keys(this.uniforms).forEach((e=>Object.defineProperty(this,e,{get:()=>this.uniforms[e].value,set:t=>this.uniforms[e].value=t})))}}const Ht=C.forwardRef((({buffer:e,distortionSpeed:t=1,samples:r=10,resolution:n,background:a,...i},s)=>{o.extend({MeshTransmissionMaterial:Nt});const l=C.useRef(null),{size:c,viewport:u}=o.useThree(),d=Ie(n);let m,f,p;return o.useFrame((r=>{e||(p=l.current.__r3f.parent,l.current.time=r.clock.getElapsedTime()*t,p&&(f=p.visible,p.visible=!1,r.gl.setRenderTarget(d),m=r.scene.background,a&&(r.scene.background=a),r.gl.render(r.scene,r.camera),r.scene.background=m,r.gl.setRenderTarget(null),p.visible=f))})),C.useImperativeHandle(s,(()=>l.current),[]),C.createElement("meshTransmissionMaterial",S.default({args:[C.useMemo((()=>({samples:r})),[r])],ref:l,buffer:e||d.texture,resolution:[c.width*u.dpr,c.height*u.dpr]},i))}));class $t extends P.PointsMaterial{constructor(e){super(e),this.onBeforeCompile=(e,t)=>{const{isWebGL2:r}=t.capabilities;e.fragmentShader=e.fragmentShader.replace("#include <output_fragment>",`\n ${r?"#include <output_fragment>":"#extension GL_OES_standard_derivatives : enable\n#include <output_fragment>"}\n vec2 cxy = 2.0 * gl_PointCoord - 1.0;\n float r = dot(cxy, cxy);\n float delta = fwidth(r); \n float mask = 1.0 - smoothstep(1.0 - delta, 1.0 + delta, r);\n gl_FragColor = vec4(gl_FragColor.rgb, mask * gl_FragColor.a );\n `)}}}const qt=C.forwardRef(((e,t)=>{const[r]=C.useState((()=>new $t(null)));return C.createElement("primitive",S.default({},e,{object:r,ref:t,attach:"material"}))})),Xt=({frustum:e=3.75,size:t=.005,near:r=9.5,samples:n=10,rings:o=11}={})=>`#define LIGHT_WORLD_SIZE ${t}\n#define LIGHT_FRUSTUM_WIDTH ${e}\n#define LIGHT_SIZE_UV (LIGHT_WORLD_SIZE / LIGHT_FRUSTUM_WIDTH)\n#define NEAR_PLANE ${r}\n\n#define NUM_SAMPLES ${n}\n#define NUM_RINGS ${o}\n#define BLOCKER_SEARCH_NUM_SAMPLES NUM_SAMPLES\n\nvec2 poissonDisk[NUM_SAMPLES];\n\nvoid initPoissonSamples( const in vec2 randomSeed ) {\n float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/\n float angle = rand( randomSeed ) * PI2;\n float radius = INV_NUM_SAMPLES;\n float radiusStep = radius;\n\n #pragma unroll_loop_start\n for( int i = 0; i < ${n}; i ++ ) {\n poissonDisk[i] = vec2( cos( angle ), sin( angle ) ) * pow( radius, 0.75 );\n radius += radiusStep;\n angle += ANGLE_STEP;\n }\n #pragma unroll_loop_end\n}\n\nfloat penumbraSize( const in float zReceiver, const in float zBlocker ) { // Parallel plane estimation\n return (zReceiver - zBlocker) / zBlocker;\n}\n\nfloat findBlocker( sampler2D shadowMap, const in vec2 uv, const in float zReceiver ) {\n // This uses similar triangles to compute what\n // area of the shadow map we should search\n float searchRadius = LIGHT_SIZE_UV * ( zReceiver - NEAR_PLANE ) / zReceiver;\n float blockerDepthSum = 0.0;\n float shadowMapDepth = 0.0;\n int numBlockers = 0; \n #pragma unroll_loop_start\n for( int i = 0; i < ${n}; i++ ) {\n shadowMapDepth = unpackRGBAToDepth(texture2D(shadowMap, uv + poissonDisk[i] * searchRadius));\n if ( shadowMapDepth < zReceiver ) {\n blockerDepthSum += shadowMapDepth;\n numBlockers ++;\n }\n }\n #pragma unroll_loop_end\n\n if( numBlockers == 0 ) return -1.0;\n return blockerDepthSum / float( numBlockers );\n}\n\nfloat PCF_Filter(sampler2D shadowMap, vec2 uv, float zReceiver, float filterRadius ) {\n float sum = 0.0;\n float depth;\n #pragma unroll_loop_start\n for( int i = 0; i < ${n}; i ++ ) {\n depth = unpackRGBAToDepth( texture2D( shadowMap, uv + poissonDisk[ i ] * filterRadius ) );\n if( zReceiver <= depth ) sum += 1.0;\n }\n #pragma unroll_loop_end\n #pragma unroll_loop_start\n for( int i = 0; i < ${n}; i ++ ) {\n depth = unpackRGBAToDepth( texture2D( shadowMap, uv + -poissonDisk[ i ].yx * filterRadius ) );\n if( zReceiver <= depth ) sum += 1.0;\n }\n #pragma unroll_loop_end\n return sum / ( 2.0 * float( ${n} ) );\n}\n\nfloat PCSS ( sampler2D shadowMap, vec4 coords ) {\n vec2 uv = coords.xy;\n float zReceiver = coords.z; // Assumed to be eye-space z in this code\n\n initPoissonSamples( uv );\n // STEP 1: blocker search\n float avgBlockerDepth = findBlocker( shadowMap, uv, zReceiver );\n\n //There are no occluders so early out (this saves filtering)\n if( avgBlockerDepth == -1.0 ) return 1.0;\n\n // STEP 2: penumbra size\n float penumbraRatio = penumbraSize( zReceiver, avgBlockerDepth );\n float filterRadius = penumbraRatio * LIGHT_SIZE_UV * NEAR_PLANE / zReceiver;\n\n // STEP 3: filtering\n //return avgBlockerDepth;\n return PCF_Filter( shadowMap, uv, zReceiver, filterRadius );\n}`;let Yt=!1;function Zt(e,t,r){t.traverse((t=>{t.material&&(e.properties.remove(t.material),t.material.dispose())})),e.info.programs.length=0,e.compile(t,r)}function Kt(e){const t=e+"Geometry";return C.forwardRef((({args:e,children:r,...n},o)=>C.createElement("mesh",S.default({ref:o},n),C.createElement(t,{attach:"geometry",args:e}),r)))}const Qt=Kt("box"),Jt=Kt("circle"),er=Kt("cone"),tr=Kt("cylinder"),rr=Kt("sphere"),nr=Kt("plane"),or=Kt("tube"),ar=Kt("torus"),ir=Kt("torusKnot"),sr=Kt("tetrahedron"),lr=Kt("ring"),cr=Kt("polyhedron"),ur=Kt("icosahedron"),dr=Kt("octahedron"),mr=Kt("dodecahedron"),fr=Kt("extrude"),pr=Kt("lathe"),hr=Kt("capsule"),vr=1e-5;const gr=C.forwardRef((function({args:[e=1,t=1,r=1]=[],radius:o=.05,steps:a=1,smoothness:i=4,children:s,...l},c){const u=C.useMemo((()=>function(e,t,r){const o=new n.Shape,a=r-vr;return o.absarc(vr,vr,vr,-Math.PI/2,-Math.PI,!0),o.absarc(vr,t-2*a,vr,Math.PI,Math.PI/2,!0),o.absarc(e-2*a,t-2*a,vr,Math.PI/2,0,!0),o.absarc(e-2*a,vr,vr,0,-Math.PI/2,!0),o}(e,t,o)),[e,t,o]),d=C.useMemo((()=>({depth:r-2*o,bevelEnabled:!0,bevelSegments:2*i,steps:a,bevelSize:o-vr,bevelThickness:o,curveSegments:i})),[r,o,i]),m=C.useRef();return C.useLayoutEffect((()=>{m.current&&m.current.center()}),[u,d]),C.createElement("mesh",S.default({ref:c},l),C.createElement("extrudeGeometry",{ref:m,args:[u,d]}),s)}));function xr(){const e=new P.BufferGeometry,t=new Float32Array([-1,-1,3,-1,-1,3]);return e.setAttribute("position",new P.BufferAttribute(t,2)),e}const yr=C.forwardRef((function({children:e,...t},r){const n=C.useMemo(xr,[]);return C.createElement("mesh",S.default({ref:r,geometry:n,frustumCulled:!1},t),e)})),wr=C.forwardRef((function({children:e,disableX:t,disableY:r,disableZ:o,left:a,right:i,top:s,bottom:l,front:c,back:u,onCentered:d,precise:m=!0,...f},p){const h=C.useRef(null),v=C.useRef(null),g=C.useRef(null);return C.useLayoutEffect((()=>{v.current.matrixWorld.identity();const e=(new n.Box3).setFromObject(g.current,m),f=new n.Vector3,p=new n.Sphere,x=e.max.x-e.min.x,y=e.max.y-e.min.y,w=e.max.z-e.min.z;e.getCenter(f),e.getBoundingSphere(p);const E=s?y/2:l?-y/2:0,b=a?-x/2:i?x/2:0,M=c?w/2:u?-w/2:0;v.current.position.set(t?0:-f.x+b,r?0:-f.y+E,o?0:-f.z+M),void 0!==d&&d({parent:h.current.parent,container:h.current,width:x,height:y,depth:w,boundingBox:e,boundingSphere:p,center:f,verticalAlignment:E,horizontalAlignment:b,depthAlignment:M})}),[e]),C.useImperativeHandle(p,(()=>h.current),[]),C.createElement("group",S.default({ref:h},f),C.createElement("group",{ref:v},C.createElement("group",{ref:g},e)))})),Er=e=>e&&e.isOrthographicCamera,br=C.createContext(null);function Mr({children:e,damping:t=6,fit:r,clip:n,observe:a,margin:i=1.2,eps:s=.01,onFit:l}){const c=C.useRef(null),{camera:u,invalidate:d,size:m,controls:f}=o.useThree(),p=f,h=C.useRef(l);function v(e,t){return Math.abs(e.x-t.x)<s&&Math.abs(e.y-t.y)<s&&Math.abs(e.z-t.z)<s}function g(e,t,r,n){e.x=P.MathUtils.damp(e.x,t.x,r,n),e.y=P.MathUtils.damp(e.y,t.y,r,n),e.z=P.MathUtils.damp(e.z,t.z,r,n)}h.current=l;const[x]=C.useState((()=>({animating:!1,focus:new P.Vector3,camera:new P.Vector3,zoom:1}))),[y]=C.useState((()=>({focus:new P.Vector3,camera:new P.Vector3,zoom:1}))),[w]=C.useState((()=>new P.Box3)),E=C.useMemo((()=>{function e(){const e=w.getSize(new P.Vector3),t=w.getCenter(new P.Vector3),r=Math.max(e.x,e.y,e.z),n=Er(u)?4*r:r/(2*Math.atan(Math.PI*u.fov/360)),o=Er(u)?4*r:n/u.aspect,a=i*Math.max(n,o);return{box:w,size:e,center:t,distance:a}}return{getSize:e,refresh(t){if((r=t)&&r.isBox3)w.copy(t);else{const e=t||c.current;e.updateWorldMatrix(!0,!0),w.setFromObject(e)}var r;if(w.isEmpty()){const e=u.position.length()||10;w.setFromCenterAndSize(new P.Vector3,new P.Vector3(e,e,e))}if("OrthographicTrackballControls"===(null==p?void 0:p.constructor.name)){const{distance:t}=e(),r=u.position.clone().sub(p.target).normalize().multiplyScalar(t),n=p.target.clone().add(r);u.position.copy(n)}return this},clip(){const{distance:t}=e();return p&&(p.maxDistance=10*t),u.near=t/100,u.far=100*t,u.updateProjectionMatrix(),p&&p.update(),d(),this},to({position:r,target:n}){x.camera.copy(u.position);const{center:o}=e();return y.camera.set(...r),n?y.focus.set(...n):y.focus.copy(o),t?x.animating=!0:u.position.set(...r),this},fit(){x.camera.copy(u.position),p&&x.focus.copy(p.target);const{center:r,distance:n}=e(),o=r.clone().sub(u.position).normalize().multiplyScalar(n);if(y.camera.copy(r).sub(o),y.focus.copy(r),Er(u)){x.zoom=u.zoom;let e=0,n=0;const o=[new P.Vector3(w.min.x,w.min.y,w.min.z),new P.Vector3(w.min.x,w.max.y,w.min.z),new P.Vector3(w.min.x,w.min.y,w.max.z),new P.Vector3(w.min.x,w.max.y,w.max.z),new P.Vector3(w.max.x,w.max.y,w.max.z),new P.Vector3(w.max.x,w.max.y,w.min.z),new P.Vector3(w.max.x,w.min.y,w.max.z),new P.Vector3(w.max.x,w.min.y,w.min.z)];r.applyMatrix4(u.matrixWorldInverse);for(const t of o)t.applyMatrix4(u.matrixWorldInverse),e=Math.max(e,Math.abs(t.y-r.y)),n=Math.max(n,Math.abs(t.x-r.x));e*=2,n*=2;const a=(u.top-u.bottom)/e,s=(u.right-u.left)/n;y.zoom=Math.min(a,s)/i,t||(u.zoom=y.zoom,u.updateProjectionMatrix())}return t?x.animating=!0:(u.position.copy(y.camera),u.lookAt(y.focus),p&&(p.target.copy(y.focus),p.update())),h.current&&h.current(this.getSize()),d(),this}}}),[w,u,p,i,t,d]);C.useLayoutEffect((()=>{if(p){const e=()=>x.animating=!1;return p.addEventListener("start",e),()=>p.removeEventListener("start",e)}}),[p]);const b=C.useRef(0);return C.useLayoutEffect((()=>{(a||0==b.current++)&&(E.refresh(),r&&E.fit(),n&&E.clip())}),[m,n,r,a,u,p]),o.useFrame(((e,r)=>{if(x.animating){if(g(x.focus,y.focus,t,r),g(x.camera,y.camera,t,r),x.zoom=P.MathUtils.damp(x.zoom,y.zoom,t,r),u.position.copy(x.camera),Er(u)&&(u.zoom=x.zoom,u.updateProjectionMatrix()),p?(p.target.copy(x.focus),p.update()):u.lookAt(x.focus),d(),Er(u)&&!(Math.abs(x.zoom-y.zoom)<s))return;if(!Er(u)&&!v(x.camera,y.camera))return;if(p&&!v(x.focus,y.focus))return;x.animating=!1}})),C.createElement("group",{ref:c},C.createElement(br.Provider,{value:E},e))}function Sr(){return C.useContext(br)}const Cr=C.forwardRef((({intensity:e=1,decay:t,decayRate:r=.65,maxYaw:n=.1,maxPitch:a=.1,maxRoll:i=.1,yawFrequency:s=.1,pitchFrequency:l=.1,rollFrequency:c=.1},d)=>{const m=o.useThree((e=>e.camera)),f=o.useThree((e=>e.controls)),p=C.useRef(e),h=C.useRef(m.rotation.clone()),[v]=C.useState((()=>new u.SimplexNoise)),[g]=C.useState((()=>new u.SimplexNoise)),[x]=C.useState((()=>new u.SimplexNoise)),y=()=>{(p.current<0||p.current>1)&&(p.current=p.current<0?0:1)};return C.useImperativeHandle(d,(()=>({getIntensity:()=>p.current,setIntensity:e=>{p.current=e,y()}})),[]),C.useEffect((()=>{if(f){const e=()=>{h.current=m.rotation.clone()};return f.addEventListener("change",e),e(),()=>{f.removeEventListener("change",e)}}}),[m,f]),o.useFrame(((e,o)=>{const u=Math.pow(p.current,2),d=n*u*v.noise(e.clock.elapsedTime*s,1),f=a*u*g.noise(e.clock.elapsedTime*l,1),w=i*u*x.noise(e.clock.elapsedTime*c,1);m.rotation.set(h.current.x+f,h.current.y+d,h.current.z+w),t&&p.current>0&&(p.current-=r*o,y())})),null})),Tr=C.forwardRef((({children:e,speed:t=1,rotationIntensity:r=1,floatIntensity:n=1,floatingRange:a=[-.1,.1],...i},s)=>{const l=C.useRef(null),c=C.useRef(1e4*Math.random());return o.useFrame((e=>{var o,i;const s=c.current+e.clock.getElapsedTime();l.current.rotation.x=Math.cos(s/4*t)/8*r,l.current.rotation.y=Math.sin(s/4*t)/8*r,l.current.rotation.z=Math.sin(s/4*t)/20*r;let u=Math.sin(s/4*t)/10;u=P.MathUtils.mapLinear(u,-.1,.1,null!==(o=null==a?void 0:a[0])&&void 0!==o?o:-.1,null!==(i=null==a?void 0:a[1])&&void 0!==i?i:.1),l.current.position.y=u*n})),C.createElement("group",i,C.createElement("group",{ref:D.default([l,s])},e))})),Pr={sunset:"venice/venice_sunset_1k.hdr",dawn:"kiara/kiara_1_dawn_1k.hdr",night:"dikhololo/dikhololo_night_1k.hdr",warehouse:"empty-wharehouse/empty_warehouse_01_1k.hdr",forest:"forrest-slope/forest_slope_1k.hdr",apartment:"lebombo/lebombo_1k.hdr",studio:"studio-small-3/studio_small_03_1k.hdr",city:"potsdamer-platz/potsdamer_platz_1k.hdr",park:"rooitou/rooitou_park_1k.hdr",lobby:"st-fagans/st_fagans_interior_1k.hdr"};function Rr(e,t,r,n,o=0){const a=(e=>{return(t=e).current&&t.current.isScene?e.current:e;var t})(t||r),i=a.background,s=a.environment,l=a.backgroundBlurriness||0;return"only"!==e&&(a.environment=n),e&&(a.background=n),e&&void 0!==a.backgroundBlurriness&&(a.backgroundBlurriness=o),()=>{"only"!==e&&(a.environment=s),e&&(a.background=i),e&&void 0!==a.backgroundBlurriness&&(a.backgroundBlurriness=l)}}function Dr({scene:e,background:t=!1,blur:r,map:n}){const a=o.useThree((e=>e.scene));return C.useLayoutEffect((()=>{if(n)return Rr(t,e,a,n,r)}),[a,e,n,t,r]),null}function _r({files:e=["/px.png","/nx.png","/py.png","/ny.png","/pz.png","/nz.png"],path:t="",preset:r,encoding:a,extensions:i}){if(r){if(!(r in Pr))throw new Error("Preset must be one of: "+Object.keys(Pr).join(", "));e=Pr[r],t="https://market-assets.fra1.cdn.digitaloceanspaces.com/market-assets/hdris/"}const s=Array.isArray(e),l=s?n.CubeTextureLoader:u.RGBELoader,c=o.useLoader(l,s?[e]:e,(e=>{e.setPath(t),i&&i(e)})),d=s?c[0]:c;return d.mapping=s?n.CubeReflectionMapping:n.EquirectangularReflectionMapping,d.encoding=(null!=a?a:s)?n.sRGBEncoding:n.LinearEncoding,d}function zr({background:e=!1,scene:t,blur:r,...n}){const a=_r(n),i=o.useThree((e=>e.scene));return C.useLayoutEffect((()=>Rr(e,t,i,a,r)),[a,e,t,i,r]),null}function kr({children:e,near:t=1,far:r=1e3,resolution:a=256,frames:i=1,map:s,background:l=!1,blur:c,scene:u,files:d,path:m,preset:f,extensions:p}){const h=o.useThree((e=>e.gl)),v=o.useThree((e=>e.scene)),g=C.useRef(null),[x]=C.useState((()=>new n.Scene)),y=C.useMemo((()=>{const e=new n.WebGLCubeRenderTarget(a);return e.texture.type=n.HalfFloatType,e}),[a]);C.useLayoutEffect((()=>(1===i&&g.current.update(h,x),Rr(l,u,v,y.texture,c))),[e,x,y.texture,u,v,l,i,h]);let w=1;return o.useFrame((()=>{(i===1/0||w<i)&&(g.current.update(h,x),w++)})),C.createElement(C.Fragment,null,o.createPortal(C.createElement(C.Fragment,null,e,C.createElement("cubeCamera",{ref:g,args:[t,r,y]}),d||f?C.createElement(zr,{background:!0,files:d,preset:f,path:m,extensions:p}):s?C.createElement(Dr,{background:!0,map:s,extensions:p}):null),x))}function Fr(e){var t,r,n,a;const i=_r(e),s=e.map||i;C.useMemo((()=>o.extend({GroundProjectedEnvImpl:u.GroundProjectedEnv})),[]);const l=C.useMemo((()=>[s]),[s]),c=null==(t=e.ground)?void 0:t.height,d=null==(r=e.ground)?void 0:r.radius,m=null!==(n=null==(a=e.ground)?void 0:a.scale)&&void 0!==n?n:1e3;return C.createElement(C.Fragment,null,C.createElement(Dr,S.default({},e,{map:s})),C.createElement("groundProjectedEnvImpl",{args:l,scale:m,height:c,radius:d}))}function Lr(e){return e.ground?C.createElement(Fr,e):e.map?C.createElement(Dr,e):e.children?C.createElement(kr,e):C.createElement(zr,e)}const Ar=C.forwardRef((({scale:e=10,frames:t=1/0,opacity:r=1,width:n=1,height:a=1,blur:i=1,far:s=10,resolution:l=512,smooth:c=!0,color:d="#000000",depthWrite:m=!1,renderOrder:f,...p},h)=>{const v=o.useThree((e=>e.scene)),g=o.useThree((e=>e.gl)),x=C.useRef(null);n*=Array.isArray(e)?e[0]:e||1,a*=Array.isArray(e)?e[1]:e||1;const[y,w,E,b,M,T,R]=C.useMemo((()=>{const e=new P.WebGLRenderTarget(l,l),t=new P.WebGLRenderTarget(l,l);t.texture.generateMipmaps=e.texture.generateMipmaps=!1;const r=new P.PlaneGeometry(n,a).rotateX(Math.PI/2),o=new P.Mesh(r),i=new P.MeshDepthMaterial;i.depthTest=i.depthWrite=!1,i.onBeforeCompile=e=>{e.uniforms={...e.uniforms,ucolor:{value:new P.Color(d)}},e.fragmentShader=e.fragmentShader.replace("void main() {","uniform vec3 ucolor;\n void main() {\n "),e.fragmentShader=e.fragmentShader.replace("vec4( vec3( 1.0 - fragCoordZ ), opacity );","vec4( ucolor * fragCoordZ * 2.0, ( 1.0 - fragCoordZ ) * 1.0 );")};const s=new P.ShaderMaterial(u.HorizontalBlurShader),c=new P.ShaderMaterial(u.VerticalBlurShader);return c.depthTest=s.depthTest=!1,[e,r,i,o,s,c,t]}),[l,n,a,e,d]),D=e=>{b.visible=!0,b.material=M,M.uniforms.tDiffuse.value=y.texture,M.uniforms.h.value=1*e/256,g.setRenderTarget(R),g.render(b,x.current),b.material=T,T.uniforms.tDiffuse.value=R.texture,T.uniforms.v.value=1*e/256,g.setRenderTarget(y),g.render(b,x.current),b.visible=!1};let _=0;return o.useFrame((()=>{if(x.current&&(t===1/0||_<t)){const e=v.background;v.background=null;const t=v.overrideMaterial;v.overrideMaterial=E,g.setRenderTarget(y),g.render(v,x.current),v.overrideMaterial=t,D(i),c&&D(.4*i),g.setRenderTarget(null),v.background=e,_++}})),C.createElement("group",S.default({"rotation-x":Math.PI/2},p,{ref:h}),C.createElement("mesh",{renderOrder:f,geometry:w,scale:[1,-1,1],rotation:[-Math.PI/2,0,0]},C.createElement("meshBasicMaterial",{map:y.texture,"map-encoding":g.outputEncoding,transparent:!0,opacity:r,depthWrite:m})),C.createElement("orthographicCamera",{ref:x,args:[-n/2,n/2,a/2,-a/2,0,s]}))}));const Br=C.createContext(null),Ur=he({color:new P.Color,blend:2,alphaTest:.75,opacity:0,map:null},"varying vec2 vUv;\n void main() {\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);\n vUv = uv;\n }","varying vec2 vUv;\n uniform sampler2D map;\n uniform vec3 color;\n uniform float opacity;\n uniform float alphaTest;\n uniform float blend;\n void main() {\n vec4 sampledDiffuseColor = texture2D(map, vUv);\n gl_FragColor = vec4(color * sampledDiffuseColor.r * blend, max(0.0, (1.0 - (sampledDiffuseColor.r + sampledDiffuseColor.g + sampledDiffuseColor.b) / alphaTest)) * opacity);\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }"),Vr=he({},"void main() { gl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }","void main() { discard; }"),Ir=C.forwardRef((({children:e,temporal:t,frames:r=40,limit:n=1/0,blend:a=20,scale:i=10,opacity:s=1,alphaTest:l=.75,color:c="black",colorBlend:u=2,resolution:d=1024,toneMapped:m=!0,...f},p)=>{o.extend({SoftShadowMaterial:Ur});const h=o.useThree((e=>e.gl)),v=o.useThree((e=>e.scene)),g=o.useThree((e=>e.camera)),x=C.useRef(null),y=C.useRef(null),[w]=C.useState((()=>new jr(h,v,d)));C.useLayoutEffect((()=>{w.configure(x.current)}),[]);const E=C.useMemo((()=>({lights:new Map,temporal:!!t,frames:Math.max(2,r),blend:Math.max(2,r===1/0?a:r),count:0,getMesh:()=>x.current,reset:()=>{w.clear();const e=x.current.material;e.opacity=0,e.alphaTest=0,E.count=0},update:(e=1)=>{const t=x.current.material;E.temporal?(t.opacity=Math.min(s,t.opacity+s/E.blend),t.alphaTest=Math.min(l,t.alphaTest+l/E.blend)):(t.opacity=s,t.alphaTest=l),y.current.visible=!0,w.prepare();for(let t=0;t<e;t++)E.lights.forEach((e=>e.update())),w.update(g,E.blend);y.current.visible=!1,w.finish()}})),[w,g,v,t,r,a,s,l]);return C.useLayoutEffect((()=>{E.reset(),E.temporal||E.frames===1/0||E.update(E.blend)})),C.useImperativeHandle(p,(()=>E),[E]),o.useFrame((()=>{(E.temporal||E.frames===1/0)&&E.count<E.frames&&E.count<n&&(E.update(),E.count++)})),C.createElement("group",f,C.createElement("group",{traverse:()=>null,ref:y},C.createElement(Br.Provider,{value:E},e)),C.createElement("mesh",{receiveShadow:!0,ref:x,scale:i,rotation:[-Math.PI/2,0,0]},C.createElement("planeGeometry",null),C.createElement("softShadowMaterial",{transparent:!0,depthWrite:!1,toneMapped:m,color:c,blend:u,map:w.progressiveLightMap2.texture})))})),Or=C.forwardRef((({castShadow:e=!0,bias:t=.001,mapSize:r=512,size:n=5,near:o=.5,far:a=500,frames:i=1,position:s=[0,0,0],radius:l=1,amount:c=8,intensity:u=1,ambient:d=.5,...m},f)=>{const p=C.useRef(null),h=new P.Vector3(...s).length(),v=C.useContext(Br),g=C.useCallback((()=>{let e;if(p.current)for(let t=0;t<p.current.children.length;t++)if(e=p.current.children[t],Math.random()>d)e.position.set(s[0]+P.MathUtils.randFloatSpread(l),s[1]+P.MathUtils.randFloatSpread(l),s[2]+P.MathUtils.randFloatSpread(l));else{let t=Math.acos(2*Math.random()-1)-Math.PI/2,r=2*Math.PI*Math.random();e.position.set(Math.cos(t)*Math.cos(r)*h,Math.abs(Math.cos(t)*Math.sin(r)*h),Math.sin(t)*h)}}),[l,d,h,...s]),x=C.useMemo((()=>({update:g})),[g]);return C.useImperativeHandle(f,(()=>x),[x]),C.useLayoutEffect((()=>{const e=p.current;return v&&v.lights.set(e.uuid,x),()=>{v.lights.delete(e.uuid)}}),[v,x]),C.createElement("group",S.default({ref:p},m),Array.from({length:c},((i,s)=>C.createElement("directionalLight",{key:s,castShadow:e,"shadow-bias":t,"shadow-mapSize":[r,r],intensity:u/c},C.createElement("orthographicCamera",{attach:"shadow-camera",args:[-n,n,n,-n,o,a]})))))}));class jr{constructor(e,t,r=1024){this.renderer=e,this.res=r,this.scene=t,this.buffer1Active=!1,this.lights=[],this.meshes=[],this.object=null,this.clearColor=new P.Color,this.clearAlpha=0;const n=/(Android|iPad|iPhone|iPod)/g.test(navigator.userAgent)?P.HalfFloatType:P.FloatType;this.progressiveLightMap1=new P.WebGLRenderTarget(this.res,this.res,{type:n,encoding:e.outputEncoding}),this.progressiveLightMap2=new P.WebGLRenderTarget(this.res,this.res,{type:n,encoding:e.outputEncoding}),this.discardMat=new Vr,this.targetMat=new P.MeshLambertMaterial({fog:!1}),this.previousShadowMap={value:this.progressiveLightMap1.texture},this.averagingWindow={value:100},this.targetMat.onBeforeCompile=e=>{e.vertexShader="varying vec2 vUv;\n"+e.vertexShader.slice(0,-1)+"vUv = uv; gl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }";const t=e.fragmentShader.indexOf("void main() {");e.fragmentShader="varying vec2 vUv;\n"+e.fragmentShader.slice(0,t)+"uniform sampler2D previousShadowMap;\n\tuniform float averagingWindow;\n"+e.fragmentShader.slice(t-1,-1)+"\nvec3 texelOld = texture2D(previousShadowMap, vUv).rgb;\n gl_FragColor.rgb = mix(texelOld, gl_FragColor.rgb, 1.0/ averagingWindow);\n }",e.uniforms.previousShadowMap=this.previousShadowMap,e.uniforms.averagingWindow=this.averagingWindow}}clear(){this.renderer.getClearColor(this.clearColor),this.clearAlpha=this.renderer.getClearAlpha(),this.renderer.setClearColor("black",1),this.renderer.setRenderTarget(this.progressiveLightMap1),this.renderer.clear(),this.renderer.setRenderTarget(this.progressiveLightMap2),this.renderer.clear(),this.renderer.setRenderTarget(null),this.renderer.setClearColor(this.clearColor,this.clearAlpha),this.lights=[],this.meshes=[],this.scene.traverse((e=>{!function(e){return!!e.geometry}(e)?function(e){return e.isLight}(e)&&this.lights.push({object:e,intensity:e.intensity}):this.meshes.push({object:e,material:e.material})}))}prepare(){this.lights.forEach((e=>e.object.intensity=0)),this.meshes.forEach((e=>e.object.material=this.discardMat))}finish(){this.lights.forEach((e=>e.object.intensity=e.intensity)),this.meshes.forEach((e=>e.object.material=e.material))}configure(e){this.object=e}update(e,t=100){if(!this.object)return;this.averagingWindow.value=t,this.object.material=this.targetMat;const r=this.buffer1Active?this.progressiveLightMap1:this.progressiveLightMap2,n=this.buffer1Active?this.progressiveLightMap2:this.progressiveLightMap1,o=this.scene.background;this.scene.background=null,this.renderer.setRenderTarget(r),this.previousShadowMap.value=n.texture,this.buffer1Active=!this.buffer1Active,this.renderer.render(this.scene,e),this.renderer.setRenderTarget(null),this.scene.background=o}}const Wr={rembrandt:{main:[1,2,1],fill:[-2,-.5,-2]},portrait:{main:[-1,2,.5],fill:[-1,.5,-1.5]},upfront:{main:[0,2,1],fill:[-1,.5,-1.5]},soft:{main:[-2,4,4],fill:[-1,.5,-1.5]}};function Gr({radius:e,adjustCamera:t}){const r=Sr();return C.useEffect((()=>{t&&r.refresh().clip().fit()}),[e,t]),null}const Nr=e=>0===e?0:Math.pow(2,10*e-10);const Hr=C.forwardRef((({fog:e=!1,renderOrder:t,depthWrite:r=!1,colorStop:o=0,color:a="black",opacity:i=.5,...s},l)=>{const c=C.useMemo((()=>{const e=document.createElement("canvas");e.width=128,e.height=128;const t=e.getContext("2d"),r=t.createRadialGradient(e.width/2,e.height/2,0,e.width/2,e.height/2,e.width/2);return r.addColorStop(o,new n.Color(a).getStyle()),r.addColorStop(1,"rgba(0,0,0,0)"),t.fillStyle=r,t.fillRect(0,0,e.width,e.height),e}),[a,o]);return C.createElement("mesh",S.default({renderOrder:t,ref:l,"rotation-x":-Math.PI/2},s),C.createElement("planeGeometry",null),C.createElement("meshBasicMaterial",{transparent:!0,opacity:i,fog:e,depthWrite:r,side:n.DoubleSide},C.createElement("canvasTexture",{attach:"map",args:[c]})))}));o.extend({MeshReflectorMaterial:jt});const $r=C.forwardRef((({mixBlur:e=0,mixStrength:t=.5,resolution:r=256,blur:a=[0,0],args:i=[1,1],minDepthThreshold:s=.9,maxDepthThreshold:l=1,depthScale:c=0,depthToBlurRatioBias:u=.25,mirror:d=0,children:m,debug:f=0,distortion:p=1,mixContrast:h=1,distortionMap:v,...g},x)=>{C.useEffect((()=>{console.warn("Reflector has been deprecated and will be removed next major. Replace it with <MeshReflectorMaterial />!")}),[]);const y=o.useThree((({gl:e})=>e)),w=o.useThree((({camera:e})=>e)),E=o.useThree((({scene:e})=>e)),b=(a=Array.isArray(a)?a:[a,a])[0]+a[1]>0,M=C.useRef(null),[T]=C.useState((()=>new n.Plane)),[P]=C.useState((()=>new n.Vector3)),[R]=C.useState((()=>new n.Vector3)),[_]=C.useState((()=>new n.Vector3)),[z]=C.useState((()=>new n.Matrix4)),[k]=C.useState((()=>new n.Vector3(0,0,-1))),[F]=C.useState((()=>new n.Vector4)),[L]=C.useState((()=>new n.Vector3)),[A]=C.useState((()=>new n.Vector3)),[B]=C.useState((()=>new n.Vector4)),[U]=C.useState((()=>new n.Matrix4)),[V]=C.useState((()=>new n.PerspectiveCamera)),I=C.useCallback((()=>{if(R.setFromMatrixPosition(M.current.matrixWorld),_.setFromMatrixPosition(w.matrixWorld),z.extractRotation(M.current.matrixWorld),P.set(0,0,1),P.applyMatrix4(z),L.subVectors(R,_),L.dot(P)>0)return;L.reflect(P).negate(),L.add(R),z.extractRotation(w.matrixWorld),k.set(0,0,-1),k.applyMatrix4(z),k.add(_),A.subVectors(R,k),A.reflect(P).negate(),A.add(R),V.position.copy(L),V.up.set(0,1,0),V.up.applyMatrix4(z),V.up.reflect(P),V.lookAt(A),V.far=w.far,V.updateMatrixWorld(),V.projectionMatrix.copy(w.projectionMatrix),U.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),U.multiply(V.projectionMatrix),U.multiply(V.matrixWorldInverse),U.multiply(M.current.matrixWorld),T.setFromNormalAndCoplanarPoint(P,R),T.applyMatrix4(V.matrixWorldInverse),F.set(T.normal.x,T.normal.y,T.normal.z,T.constant);const e=V.projectionMatrix;B.x=(Math.sign(F.x)+e.elements[8])/e.elements[0],B.y=(Math.sign(F.y)+e.elements[9])/e.elements[5],B.z=-1,B.w=(1+e.elements[10])/e.elements[14],F.multiplyScalar(2/F.dot(B)),e.elements[2]=F.x,e.elements[6]=F.y,e.elements[10]=F.z+1,e.elements[14]=F.w}),[]),[O,j,W,G]=C.useMemo((()=>{const o={minFilter:n.LinearFilter,magFilter:n.LinearFilter,encoding:y.outputEncoding},i=new n.WebGLRenderTarget(r,r,o);i.depthBuffer=!0,i.depthTexture=new n.DepthTexture(r,r),i.depthTexture.format=n.DepthFormat,i.depthTexture.type=n.UnsignedShortType;const m=new n.WebGLRenderTarget(r,r,o);return[i,m,new Ot({gl:y,resolution:r,width:a[0],height:a[1],minDepthThreshold:s,maxDepthThreshold:l,depthScale:c,depthToBlurRatioBias:u}),{mirror:d,textureMatrix:U,mixBlur:e,tDiffuse:i.texture,tDepth:i.depthTexture,tDiffuseBlur:m.texture,hasBlur:b,mixStrength:t,minDepthThreshold:s,maxDepthThreshold:l,depthScale:c,depthToBlurRatioBias:u,transparent:!0,debug:f,distortion:p,distortionMap:v,mixContrast:h,"defines-USE_BLUR":b?"":void 0,"defines-USE_DEPTH":c>0?"":void 0,"defines-USE_DISTORTION":v?"":void 0}]}),[y,a,U,r,d,b,e,t,s,l,c,u,f,p,v,h]);return o.useFrame((()=>{if(null==M||!M.current)return;M.current.visible=!1;const e=y.xr.enabled,t=y.shadowMap.autoUpdate;I(),y.xr.enabled=!1,y.shadowMap.autoUpdate=!1,y.setRenderTarget(O),y.state.buffers.depth.setMask(!0),y.autoClear||y.clear(),y.render(E,V),b&&W.render(y,O,j),y.xr.enabled=e,y.shadowMap.autoUpdate=t,M.current.visible=!0,y.setRenderTarget(null)})),C.createElement("mesh",S.default({ref:D.default([M,x])},g),C.createElement("planeGeometry",{args:i}),m?m("meshReflectorMaterial",G):C.createElement("meshReflectorMaterial",G))}));class qr extends n.ShaderMaterial{constructor(){super({uniforms:{depth:{value:null},opacity:{value:1},attenuation:{value:2.5},anglePower:{value:12},spotPosition:{value:new n.Vector3(0,0,0)},lightColor:{value:new n.Color("white")},cameraNear:{value:0},cameraFar:{value:1},resolution:{value:new n.Vector2(0,0)}},transparent:!0,depthWrite:!1,vertexShader:"\n varying vec3 vNormal;\n varying vec3 vWorldPosition;\n varying float vViewZ;\n varying float vIntensity;\n uniform vec3 spotPosition;\n uniform float attenuation; \n\n void main() {\n // compute intensity\n vNormal = normalize( normalMatrix * normal );\n vec4 worldPosition\t= modelMatrix * vec4( position, 1.0 );\n vWorldPosition = worldPosition.xyz;\n vec4 viewPosition = viewMatrix * worldPosition;\n vViewZ = viewPosition.z;\n float intensity\t= distance(worldPosition.xyz, spotPosition) / attenuation;\n intensity\t= 1.0 - clamp(intensity, 0.0, 1.0);\n vIntensity = intensity; \n // set gl_Position\n gl_Position\t= projectionMatrix * viewPosition;\n\n }",fragmentShader:"\n #include <packing>\n\n varying vec3 vNormal;\n varying vec3 vWorldPosition;\n uniform vec3 lightColor;\n uniform vec3 spotPosition;\n uniform float attenuation;\n uniform float anglePower;\n uniform sampler2D depth;\n uniform vec2 resolution;\n uniform float cameraNear;\n uniform float cameraFar;\n varying float vViewZ;\n varying float vIntensity;\n uniform float opacity;\n\n float readDepth( sampler2D depthSampler, vec2 coord ) {\n float fragCoordZ = texture2D( depthSampler, coord ).x;\n float viewZ = perspectiveDepthToViewZ(fragCoordZ, cameraNear, cameraFar);\n return viewZ;\n }\n\n void main() {\n float d = 1.0;\n bool isSoft = resolution[0] > 0.0 && resolution[1] > 0.0;\n if (isSoft) {\n vec2 sUv = gl_FragCoord.xy / resolution;\n d = readDepth(depth, sUv);\n }\n float intensity = vIntensity;\n vec3 normal\t= vec3(vNormal.x, vNormal.y, abs(vNormal.z));\n float angleIntensity\t= pow( dot(normal, vec3(0.0, 0.0, 1.0)), anglePower );\n intensity\t*= angleIntensity;\n // fades when z is close to sampled depth, meaning the cone is intersecting existing geometry\n if (isSoft) {\n intensity\t*= smoothstep(0., 1., vViewZ - d);\n }\n gl_FragColor = vec4(lightColor, intensity * opacity);\n\n #include <tonemapping_fragment>\n\t #include <encodings_fragment>\n }"})}}function Xr({opacity:e=1,radiusTop:t,radiusBottom:r,depthBuffer:a,color:i="white",distance:s=5,angle:l=.15,attenuation:c=5,anglePower:u=5}){const d=C.useRef(null),m=o.useThree((e=>e.size)),f=o.useThree((e=>e.camera)),p=o.useThree((e=>e.viewport.dpr)),[h]=C.useState((()=>new qr)),[v]=C.useState((()=>new n.Vector3));t=void 0===t?.1:t,r=void 0===r?7*l:r,o.useFrame((()=>{h.uniforms.spotPosition.value.copy(d.current.getWorldPosition(v)),d.current.lookAt(d.current.parent.target.getWorldPosition(v))}));const g=C.useMemo((()=>{const e=new n.CylinderGeometry(t,r,s,128,64,!0);return e.applyMatrix4((new n.Matrix4).makeTranslation(0,-s/2,0)),e.applyMatrix4((new n.Matrix4).makeRotationX(-Math.PI/2)),e}),[s,t,r]);return C.createElement(C.Fragment,null,C.createElement("mesh",{ref:d,geometry:g,raycast:()=>null},C.createElement("primitive",{object:h,attach:"material","uniforms-opacity-value":e,"uniforms-lightColor-value":i,"uniforms-attenuation-value":c,"uniforms-anglePower-value":u,"uniforms-depth-value":a,"uniforms-cameraNear-value":f.near,"uniforms-cameraFar-value":f.far,"uniforms-resolution-value":a?[m.width*p,m.height*p]:[0,0]})))}function Yr(e,t,r,a,i){const[[s,l]]=C.useState((()=>[new n.Vector3,new n.Vector3]));C.useLayoutEffect((()=>{if(!(null==(t=e.current)?void 0:t.isSpotLight))throw new Error("SpotlightShadow must be a child of a SpotLight");var t;console.log(e.current),e.current.shadow.mapSize.set(r,a),e.current.shadow.needsUpdate=!0}),[e,r,a]),o.useFrame((()=>{if(!e.current)return;const r=e.current.position,n=e.current.target.position;l.copy(n).sub(r);var o=l.length();l.normalize().multiplyScalar(o*i),s.copy(r).add(l),t.current.position.copy(s),t.current.lookAt(e.current.target.position)}))}function Zr({distance:e=.4,alphaTest:t=.5,map:r,shader:a="#define GLSLIFY 1\nvarying vec2 vUv;uniform sampler2D uShadowMap;uniform float uTime;void main(){vec3 color=texture2D(uShadowMap,vUv).xyz;gl_FragColor=vec4(color,1.);}",width:i=512,height:s=512,scale:l=1,children:c,...d}){const m=C.useRef(null),f=d.spotlightRef,p=d.debug;Yr(f,m,i,s,e);const h=C.useMemo((()=>new n.WebGLRenderTarget(i,s,{format:n.RGBAFormat,encoding:n.LinearEncoding,stencilBuffer:!1})),[i,s]),v=C.useRef({uShadowMap:{value:r},uTime:{value:0}});C.useEffect((()=>{v.current.uShadowMap.value=r}),[r]);const g=C.useMemo((()=>new u.FullScreenQuad(new n.ShaderMaterial({uniforms:v.current,vertexShader:"\n varying vec2 vUv;\n\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:a}))),[a]);return C.useEffect((()=>()=>{g.material.dispose(),g.dispose()}),[g]),C.useEffect((()=>()=>h.dispose()),[h]),o.useFrame((({gl:e},t)=>{v.current.uTime.value+=t,e.setRenderTarget(h),g.render(e),e.setRenderTarget(null)})),C.createElement(C.Fragment,null,C.createElement("mesh",{ref:m,scale:l,castShadow:!0},C.createElement("planeGeometry",null),C.createElement("meshBasicMaterial",{transparent:!0,side:n.DoubleSide,alphaTest:t,alphaMap:h.texture,"alphaMap-wrapS":n.RepeatWrapping,"alphaMap-wrapT":n.RepeatWrapping,opacity:p?1:0},c)))}function Kr({distance:e=.4,alphaTest:t=.5,map:r,width:o=512,height:a=512,scale:i,children:s,...l}){const c=C.useRef(null),u=l.spotlightRef,d=l.debug;return Yr(u,c,o,a,e),C.createElement(C.Fragment,null,C.createElement("mesh",{ref:c,scale:i,castShadow:!0},C.createElement("planeGeometry",null),C.createElement("meshBasicMaterial",{transparent:!0,side:n.DoubleSide,alphaTest:t,alphaMap:r,"alphaMap-wrapS":n.RepeatWrapping,"alphaMap-wrapT":n.RepeatWrapping,opacity:d?1:0},s)))}const Qr=C.forwardRef((({opacity:e=1,radiusTop:t,radiusBottom:r,depthBuffer:n,color:o="white",distance:a=5,angle:i=.15,attenuation:s=5,anglePower:l=5,volumetric:c=!0,debug:u=!1,children:d,...m},f)=>{const p=C.useRef(null);return C.createElement("group",null,u&&p.current&&C.createElement("spotLightHelper",{args:[p.current]}),C.createElement("spotLight",S.default({ref:D.default([f,p]),angle:i,color:o,distance:a,castShadow:!0},m),c&&C.createElement(Xr,{debug:u,opacity:e,radiusTop:t,radiusBottom:r,depthBuffer:n,color:o,distance:a,angle:i,attenuation:s,anglePower:l})),d&&C.cloneElement(d,{spotlightRef:p,debug:u}))})),Jr=C.forwardRef((({args:e,map:t,toneMapped:r=!1,color:n="white",form:a="rect",intensity:i=1,scale:s=1,target:l,children:c,...u},d)=>{const m=C.useRef(null);return C.useLayoutEffect((()=>{c||u.material||(o.applyProps(m.current.material,{color:n}),m.current.material.color.multiplyScalar(i))}),[n,i,c,u.material]),C.useLayoutEffect((()=>{l&&m.current.lookAt(Array.isArray(l)?new P.Vector3(...l):l)}),[l]),s=Array.isArray(s)&&2===s.length?[s[0],s[1],1]:s,C.createElement("mesh",S.default({ref:D.default([m,d]),scale:s},u),"circle"===a?C.createElement("ringGeometry",{args:[0,1,64]}):"ring"===a?C.createElement("ringGeometry",{args:[.5,1,64]}):"rect"===a?C.createElement("planeGeometry",null):C.createElement(a,{args:e}),c||(u.material?null:C.createElement("meshBasicMaterial",{toneMapped:r,map:t,side:P.DoubleSide})))}));function en(e,t,r=new n.Vector3){const o=Math.PI*(e-.5),a=2*Math.PI*(t-.5);return r.x=Math.cos(a),r.y=Math.sin(o),r.z=Math.sin(a),r}const tn=C.forwardRef((({inclination:e=.6,azimuth:t=.1,distance:r=1e3,mieCoefficient:o=.005,mieDirectionalG:a=.8,rayleigh:i=.5,turbidity:s=10,sunPosition:l=en(e,t),...c},d)=>{const m=C.useMemo((()=>(new n.Vector3).setScalar(r)),[r]),[f]=C.useState((()=>new u.Sky));return C.createElement("primitive",S.default({object:f,ref:d,"material-uniforms-mieCoefficient-value":o,"material-uniforms-mieDirectionalG-value":a,"material-uniforms-rayleigh-value":i,"material-uniforms-sunPosition-value":l,"material-uniforms-turbidity-value":s,scale:m},c))}));class rn extends n.ShaderMaterial{constructor(){super({uniforms:{time:{value:0},fade:{value:1}},vertexShader:"\n uniform float time;\n attribute float size;\n varying vec3 vColor;\n void main() {\n vColor = color;\n vec4 mvPosition = modelViewMatrix * vec4(position, 0.5);\n gl_PointSize = size * (30.0 / -mvPosition.z) * (3.0 + sin(time + 100.0));\n gl_Position = projectionMatrix * mvPosition;\n }",fragmentShader:"\n uniform sampler2D pointTexture;\n uniform float fade;\n varying vec3 vColor;\n void main() {\n float opacity = 1.0;\n if (fade == 1.0) {\n float d = distance(gl_PointCoord, vec2(0.5, 0.5));\n opacity = 1.0 / (1.0 + exp(16.0 * (d - 0.25)));\n }\n gl_FragColor = vec4(vColor, opacity);\n\n #include <tonemapping_fragment>\n\t #include <encodings_fragment>\n }"})}}const nn=e=>(new n.Vector3).setFromSpherical(new n.Spherical(e,Math.acos(1-2*Math.random()),2*Math.random()*Math.PI)),on=C.forwardRef((({radius:e=100,depth:t=50,count:r=5e3,saturation:a=0,factor:i=4,fade:s=!1,speed:l=1},c)=>{const u=C.useRef(),[d,m,f]=C.useMemo((()=>{const o=[],s=[],l=Array.from({length:r},(()=>(.5+.5*Math.random())*i)),c=new n.Color;let u=e+t;const d=t/r;for(let e=0;e<r;e++)u-=d*Math.random(),o.push(...nn(u).toArray()),c.setHSL(e/r,a,.9),s.push(c.r,c.g,c.b);return[new Float32Array(o),new Float32Array(s),new Float32Array(l)]}),[r,t,i,e,a]);o.useFrame((e=>u.current&&(u.current.uniforms.time.value=e.clock.getElapsedTime()*l)));const[p]=C.useState((()=>new rn));return C.createElement("points",{ref:c},C.createElement("bufferGeometry",null,C.createElement("bufferAttribute",{attach:"attributes-position",args:[d,3]}),C.createElement("bufferAttribute",{attach:"attributes-color",args:[m,3]}),C.createElement("bufferAttribute",{attach:"attributes-size",args:[f,1]})),C.createElement("primitive",{ref:u,object:p,attach:"material",blending:n.AdditiveBlending,"uniforms-fade-value":s,depthWrite:!1,transparent:!0,vertexColors:!0}))}));const an=he({time:0,pixelRatio:1},"#define GLSLIFY 1\nuniform float pixelRatio;uniform float time;attribute float size;attribute float speed;attribute float opacity;attribute vec3 noise;attribute vec3 color;varying vec3 vColor;varying float vOpacity;void main(){vec4 modelPosition=modelMatrix*vec4(position,1.0);modelPosition.y+=sin(time*speed+modelPosition.x*noise.x*100.0)*0.2;modelPosition.z+=cos(time*speed+modelPosition.x*noise.y*100.0)*0.2;modelPosition.x+=cos(time*speed+modelPosition.x*noise.z*100.0)*0.2;vec4 viewPosition=viewMatrix*modelPosition;vec4 projectionPostion=projectionMatrix*viewPosition;gl_Position=projectionPostion;gl_PointSize=size*25.*pixelRatio;gl_PointSize*=(1.0/-viewPosition.z);vColor=color;vOpacity=opacity;}","#define GLSLIFY 1\nvarying vec3 vColor;varying float vOpacity;void main(){float distanceToCenter=distance(gl_PointCoord,vec2(0.5));float strength=0.05/distanceToCenter-0.1;gl_FragColor=vec4(vColor,strength*vOpacity);}"),sn=e=>e&&e.constructor===Float32Array,ln=e=>e instanceof P.Vector2||e instanceof P.Vector3||e instanceof P.Vector4,cn=e=>Array.isArray(e)?e:ln(e)?e.toArray():[e,e,e];function un(e,t,r){return C.useMemo((()=>{if(void 0!==t){if(sn(t))return t;if(t instanceof P.Color){const r=Array.from({length:3*e},(()=>(e=>[e.r,e.g,e.b])(t))).flat();return Float32Array.from(r)}if(ln(t)||Array.isArray(t)){const r=Array.from({length:3*e},(()=>cn(t))).flat();return Float32Array.from(r)}return Float32Array.from({length:e},(()=>t))}return Float32Array.from({length:e},r)}),[t])}const dn=C.forwardRef((({noise:e=1,count:t=100,speed:r=1,opacity:n=1,scale:a=1,size:i,color:s,...l},c)=>{C.useMemo((()=>o.extend({SparklesMaterial:an})),[]);const u=C.useRef(),d=o.useThree((e=>e.viewport.dpr)),m=C.useMemo((()=>Float32Array.from(Array.from({length:t},(()=>cn(a).map(P.MathUtils.randFloatSpread))).flat())),[t,a]),f=un(t,i,Math.random),p=un(t,n),h=un(t,r),v=un(3*t,e),g=un(void 0===s?3*t:t,sn(s)?s:new P.Color(s),(()=>1));return o.useFrame((e=>u.current.uniforms.time.value=e.clock.elapsedTime)),C.createElement("points",S.default({key:`particle-${t}-${JSON.stringify(a)}`},l,{ref:c}),C.createElement("bufferGeometry",null,C.createElement("bufferAttribute",{attach:"attributes-position",args:[m,3]}),C.createElement("bufferAttribute",{attach:"attributes-size",args:[f,1]}),C.createElement("bufferAttribute",{attach:"attributes-opacity",args:[p,1]}),C.createElement("bufferAttribute",{attach:"attributes-speed",args:[h,1]}),C.createElement("bufferAttribute",{attach:"attributes-color",args:[g,3]}),C.createElement("bufferAttribute",{attach:"attributes-noise",args:[v,3]})),C.createElement("sparklesMaterial",{ref:u,transparent:!0,pixelRatio:d,depthWrite:!1}))}));const mn=new P.Matrix4,fn=new P.Ray,pn=new P.Sphere,hn=new P.Vector3;class vn extends P.Group{constructor(){super(),this.size=0,this.color=new P.Color("white"),this.instance={current:void 0},this.instanceKey={current:void 0}}get geometry(){var e;return null==(e=this.instance.current)?void 0:e.geometry}raycast(e,t){var r,n;const o=this.instance.current;if(!o||!o.geometry)return;const a=o.userData.instances.indexOf(this.instanceKey);if(-1===a||a>o.geometry.drawRange.count)return;const i=null!==(r=null==(n=e.params.Points)?void 0:n.threshold)&&void 0!==r?r:1;if(pn.set(this.getWorldPosition(hn),i),!1===e.ray.intersectsSphere(pn))return;mn.copy(o.matrixWorld).invert(),fn.copy(e.ray).applyMatrix4(mn);const s=i/((this.scale.x+this.scale.y+this.scale.z)/3),l=s*s,c=fn.distanceSqToPoint(hn);if(c<l){const r=new P.Vector3;fn.closestPointToPoint(hn,r),r.applyMatrix4(this.matrixWorld);const n=e.ray.origin.distanceTo(r);if(n<e.near||n>e.far)return;t.push({distance:n,distanceToRay:Math.sqrt(c),point:r,index:a,face:null,object:this})}}}let gn,xn;const yn=C.createContext(null),wn=new P.Matrix4,En=new P.Vector3,bn=C.forwardRef((({children:e,range:t,limit:r=1e3,...n},a)=>{const i=C.useRef(null),[s,l]=C.useState([]),[[c,u,d]]=C.useState((()=>[new Float32Array(3*r),Float32Array.from({length:3*r},(()=>1)),Float32Array.from({length:r},(()=>1))]));C.useEffect((()=>{i.current.geometry.attributes.position.needsUpdate=!0})),o.useFrame((()=>{for(i.current.updateMatrix(),i.current.updateMatrixWorld(),wn.copy(i.current.matrixWorld).invert(),i.current.geometry.drawRange.count=Math.min(r,void 0!==t?t:r,s.length),gn=0;gn<s.length;gn++)xn=s[gn].current,xn.getWorldPosition(En).applyMatrix4(wn),En.toArray(c,3*gn),i.current.geometry.attributes.position.needsUpdate=!0,xn.matrixWorldNeedsUpdate=!0,xn.color.toArray(u,3*gn),i.current.geometry.attributes.color.needsUpdate=!0,d.set([xn.size],gn),i.current.geometry.attributes.size.needsUpdate=!0}));const m=C.useMemo((()=>({getParent:()=>i,subscribe:e=>(l((t=>[...t,e])),()=>l((t=>t.filter((t=>t.current!==e.current)))))})),[]);return C.createElement("points",S.default({userData:{instances:s},matrixAutoUpdate:!1,ref:D.default([a,i]),raycast:()=>null},n),C.createElement("bufferGeometry",null,C.createElement("bufferAttribute",{attach:"attributes-position",count:c.length/3,array:c,itemSize:3,usage:P.DynamicDrawUsage}),C.createElement("bufferAttribute",{attach:"attributes-color",count:u.length/3,array:u,itemSize:3,usage:P.DynamicDrawUsage}),C.createElement("bufferAttribute",{attach:"attributes-size",count:d.length,array:d,itemSize:1,usage:P.DynamicDrawUsage})),C.createElement(yn.Provider,{value:m},e))})),Mn=C.forwardRef((({children:e,...t},r)=>{C.useMemo((()=>o.extend({PositionPoint:vn})),[]);const n=C.useRef(),{subscribe:a,getParent:i}=C.useContext(yn);return C.useLayoutEffect((()=>a(n)),[]),C.createElement("positionPoint",S.default({instance:i(),instanceKey:n,ref:D.default([r,n])},t),e)})),Sn=C.forwardRef((({children:e,positions:t,colors:r,sizes:n,stride:a=3,...i},s)=>{const l=C.useRef(null);return o.useFrame((()=>{const e=l.current.geometry.attributes;e.position.needsUpdate=!0,r&&(e.color.needsUpdate=!0),n&&(e.size.needsUpdate=!0)})),C.createElement("points",S.default({ref:D.default([s,l])},i),C.createElement("bufferGeometry",null,C.createElement("bufferAttribute",{attach:"attributes-position",count:t.length/a,array:t,itemSize:a,usage:P.DynamicDrawUsage}),r&&C.createElement("bufferAttribute",{attach:"attributes-color",count:r.length/a,array:r,itemSize:3,usage:P.DynamicDrawUsage}),n&&C.createElement("bufferAttribute",{attach:"attributes-size",count:n.length/a,array:n,itemSize:1,usage:P.DynamicDrawUsage})),e)})),Cn=C.forwardRef(((e,t)=>e.positions instanceof Float32Array?C.createElement(Sn,S.default({},e,{ref:t})):C.createElement(bn,S.default({},e,{ref:t})))),Tn=new P.Matrix4,Pn=new P.Matrix4,Rn=[],Dn=new P.Mesh;class _n extends P.Group{constructor(){super(),this.color=new P.Color("white"),this.instance={current:void 0},this.instanceKey={current:void 0}}get geometry(){var e;return null==(e=this.instance.current)?void 0:e.geometry}raycast(e,t){const r=this.instance.current;if(!r)return;if(!r.geometry||!r.material)return;Dn.geometry=r.geometry;const n=r.matrixWorld,o=r.userData.instances.indexOf(this.instanceKey);if(!(-1===o||o>r.count)){r.getMatrixAt(o,Tn),Pn.multiplyMatrices(n,Tn),Dn.matrixWorld=Pn,r.material instanceof P.Material?Dn.material.side=r.material.side:Dn.material.side=r.material[0].side,Dn.raycast(e,Rn);for(let e=0,r=Rn.length;e<r;e++){const r=Rn[e];r.instanceId=o,r.object=this,t.push(r)}Rn.length=0}}}const zn=C.createContext(null),kn=new P.Matrix4,Fn=new P.Matrix4,Ln=new P.Matrix4,An=new P.Vector3,Bn=new P.Quaternion,Un=new P.Vector3,Vn=C.forwardRef((({context:e,children:t,...r},n)=>{C.useMemo((()=>o.extend({PositionMesh:_n})),[]);const a=C.useRef(),{subscribe:i,getParent:s}=C.useContext(e||zn);return C.useLayoutEffect((()=>i(a)),[]),C.createElement("positionMesh",S.default({instance:s(),instanceKey:a,ref:D.default([n,a])},r),t)})),In=C.forwardRef((({children:e,range:t,limit:r=1e3,frames:n=1/0,...a},i)=>{const[{context:s,instance:l}]=C.useState((()=>{const e=C.createContext(null);return{context:e,instance:C.forwardRef(((t,r)=>C.createElement(Vn,S.default({context:e},t,{ref:r}))))}})),c=C.useRef(null),[u,d]=C.useState([]),[[m,f]]=C.useState((()=>{const e=new Float32Array(16*r);for(let t=0;t<r;t++)Ln.identity().toArray(e,16*t);return[e,new Float32Array([...new Array(3*r)].map((()=>1)))]}));C.useEffect((()=>{c.current.instanceMatrix.needsUpdate=!0}));let p=0,h=0;o.useFrame((()=>{if(n===1/0||p<n){c.current.updateMatrix(),c.current.updateMatrixWorld(),kn.copy(c.current.matrixWorld).invert(),h=Math.min(r,void 0!==t?t:r,u.length),c.current.count=h,c.current.instanceMatrix.updateRange.count=16*h,c.current.instanceColor.updateRange.count=3*h;for(let e=0;e<u.length;e++){const t=u[e].current;t.matrixWorld.decompose(An,Bn,Un),Fn.compose(An,Bn,Un).premultiply(kn),Fn.toArray(m,16*e),c.current.instanceMatrix.needsUpdate=!0,t.color.toArray(f,3*e),c.current.instanceColor.needsUpdate=!0}p++}}));const v=C.useMemo((()=>({getParent:()=>c,subscribe:e=>(d((t=>[...t,e])),()=>d((t=>t.filter((t=>t.current!==e.current)))))})),[]);return C.createElement("instancedMesh",S.default({userData:{instances:u},matrixAutoUpdate:!1,ref:D.default([i,c]),args:[null,null,0],raycast:()=>null},a),C.createElement("instancedBufferAttribute",{attach:"instanceMatrix",count:m.length/16,array:m,itemSize:16,usage:P.DynamicDrawUsage}),C.createElement("instancedBufferAttribute",{attach:"instanceColor",count:f.length/3,array:f,itemSize:3,usage:P.DynamicDrawUsage}),"function"==typeof e?C.createElement(s.Provider,{value:v},e(l)):C.createElement(zn.Provider,{value:v},e))})),On=C.forwardRef((function({meshes:e,children:t,...r},n){const o=Array.isArray(e);if(!o)for(const t of Object.keys(e))e[t].isMesh||delete e[t];return C.createElement("group",{ref:n},C.createElement(L.default,{components:(o?e:Object.values(e)).map((({geometry:e,material:t})=>C.createElement(In,S.default({key:e.uuid,geometry:e,material:t},r))))},(r=>o?t(...r):t(Object.keys(e).filter((t=>e[t].isMesh)).reduce(((e,t,n)=>({...e,[t]:r[n]})),{})))))})),jn=C.createContext(null),Wn=C.forwardRef(((e,t)=>{C.useMemo((()=>o.extend({SegmentObject:Gn})),[]);const{limit:r=1e3,lineWidth:n=1,children:a,...i}=e,[s,l]=C.useState([]),[c]=C.useState((()=>new u.Line2)),[d]=C.useState((()=>new u.LineMaterial)),[m]=C.useState((()=>new u.LineSegmentsGeometry)),[f]=C.useState((()=>new P.Vector2(512,512))),[p]=C.useState((()=>Array(6*r).fill(0))),[h]=C.useState((()=>Array(6*r).fill(0))),v=C.useMemo((()=>({subscribe:e=>(l((t=>[...t,e])),()=>l((t=>t.filter((t=>t.current!==e.current)))))})),[]);return o.useFrame((()=>{for(let t=0;t<r;t++){var e;const r=null==(e=s[t])?void 0:e.current;r&&(p[6*t+0]=r.start.x,p[6*t+1]=r.start.y,p[6*t+2]=r.start.z,p[6*t+3]=r.end.x,p[6*t+4]=r.end.y,p[6*t+5]=r.end.z,h[6*t+0]=r.color.r,h[6*t+1]=r.color.g,h[6*t+2]=r.color.b,h[6*t+3]=r.color.r,h[6*t+4]=r.color.g,h[6*t+5]=r.color.b)}m.setColors(h),m.setPositions(p),c.computeLineDistances()})),C.createElement("primitive",{object:c,ref:t},C.createElement("primitive",{object:m,attach:"geometry"}),C.createElement("primitive",S.default({object:d,attach:"material",vertexColors:!0,resolution:f,linewidth:n},i)),C.createElement(jn.Provider,{value:v},a))}));class Gn{constructor(){this.color=new P.Color("white"),this.start=new P.Vector3(0,0,0),this.end=new P.Vector3(0,0,0)}}const Nn=e=>e instanceof P.Vector3?e:new P.Vector3(..."number"==typeof e?[e,e,e]:e),Hn=C.forwardRef((({color:e,start:t,end:r},n)=>{const o=C.useContext(jn);if(!o)throw"Segment must used inside Segments component.";const a=C.useRef(null);return C.useLayoutEffect((()=>o.subscribe(a)),[]),C.createElement("segmentObject",{ref:D.default([a,n]),color:e,start:Nn(t),end:Nn(r)})})),$n=C.forwardRef((({children:e,distances:t,...r},n)=>{const a=C.useRef(null);return C.useLayoutEffect((()=>{const{current:e}=a;e.levels.length=0,e.children.forEach(((r,n)=>e.levels.push({object:r,distance:t[n]})))})),o.useFrame((e=>{var t;return null==(t=a.current)?void 0:t.update(e.camera)})),C.createElement("lOD",S.default({ref:D.default([a,n])},r),e)}));const qn=new n.Matrix4,Xn=new n.Ray,Yn=new n.Sphere,Zn=new n.Vector3;const Kn=t.createContext(null);const Qn=C.forwardRef((({children:e,width:t,height:r,samples:n=8,renderPriority:a=0,eventPriority:i=0,frames:s=1/0,...l},c)=>{const{size:u,viewport:d}=o.useThree(),m=Ie((t||u.width)*d.dpr,(r||u.height)*d.dpr,{samples:n}),[f]=C.useState((()=>new P.Scene)),p=C.useCallback(((e,t,r)=>{var n,o;let a=null==(n=m.texture)?void 0:n.__r3f.parent;for(;a&&!(a instanceof P.Object3D);)a=a.__r3f.parent;if(!a)return!1;r.raycaster.camera||r.events.compute(e,r,null==(o=r.previousRoot)?void 0:o.getState());const[i]=r.raycaster.intersectObject(a);if(!i)return!1;const s=i.uv;if(!s)return!1;t.raycaster.setFromCamera(t.pointer.set(2*s.x-1,2*s.y-1),t.camera)}),[]);return C.useImperativeHandle(c,(()=>m.texture),[m]),C.createElement(C.Fragment,null,o.createPortal(C.createElement(Jn,{renderPriority:a,frames:s,fbo:m},e),f,{events:{compute:p,priority:i}}),C.createElement("primitive",S.default({object:m.texture},l)))}));function Jn({frames:e,renderPriority:t,children:r,fbo:n}){let a=0;return o.useFrame((t=>{(e===1/0||a<e)&&(t.gl.setRenderTarget(n),t.gl.render(t.scene,t.camera),t.gl.setRenderTarget(null),a++)}),t),C.createElement(C.Fragment,null,r)}const eo=new P.Color;function to(e){return"top"in e}function ro({canvasSize:e,scene:t,index:r,children:n,frames:a,rect:i,track:s}){const l=o.useThree((e=>e.get)),c=o.useThree((e=>e.camera)),u=o.useThree((e=>e.scene)),d=o.useThree((e=>e.setEvents));let m=0;return o.useFrame((r=>{var o,l;(a===1/0||m<=a)&&(i.current=null==(o=s.current)?void 0:o.getBoundingClientRect(),m++);if(i.current){const{position:{left:o,bottom:a,width:s,height:d},isOffscreen:m}=function(e,t){const{right:r,top:n,left:o,bottom:a,width:i,height:s}=t,l=t.bottom<0||n>e.height||r<0||t.left>e.width;if(to(e)){const t=e.top+e.height-a;return{position:{width:i,height:s,left:o-e.left,top:n,bottom:t,right:r},isOffscreen:l}}return{position:{width:i,height:s,top:n,left:o,bottom:e.height-a,right:r},isOffscreen:l}}(e,i.current),f=s/d;if((l=c)&&l.isOrthographicCamera?c.left===s/-2&&c.right===s/2&&c.top===d/2&&c.bottom===d/-2||(Object.assign(c,{left:s/-2,right:s/2,top:d/2,bottom:d/-2}),c.updateProjectionMatrix()):c.aspect!==f&&(c.aspect=f,c.updateProjectionMatrix()),r.gl.setViewport(o,a,s,d),r.gl.setScissor(o,a,s,d),r.gl.setScissorTest(!0),m)return r.gl.getClearColor(eo),r.gl.setClearColor(eo,r.gl.getClearAlpha()),void r.gl.clear(!0,!0);r.gl.render(n?u:t,c)}}),r),C.useEffect((()=>{const e=l().events.connected;return d({connected:s.current}),()=>d({connected:e})}),[]),C.useEffect((()=>{to(e)||console.warn("Detected @react-three/fiber canvas size does not include position information. <View /> may not work as expected. Upgrade to @react-three/fiber ^8.1.0 for support.\n See https://github.com/pmndrs/drei/issues/944")}),[]),C.createElement(C.Fragment,null,n)}const no=C.createContext(null),oo=new P.Vector3,ao=new P.Vector3,io=new P.Vector3(0,1,0),so=new P.Matrix4,lo=({direction:e,axis:t})=>{const{translation:r,translationLimits:n,annotationsClass:a,depthTest:i,scale:s,lineWidth:l,fixed:c,axisColors:u,hoveredColor:d,displayValues:m,opacity:f,onDragStart:p,onDrag:h,onDragEnd:v,userData:g}=C.useContext(no),x=o.useThree((e=>e.controls)),y=C.useRef(null),w=C.useRef(null),E=C.useRef(null),b=C.useRef(0),[M,S]=C.useState(!1),T=C.useCallback((n=>{m&&(y.current.innerText=`${r.current[t].toFixed(2)}`,y.current.style.display="block"),n.stopPropagation();const o=(new P.Matrix4).extractRotation(w.current.matrixWorld),a=n.point.clone(),i=(new P.Vector3).setFromMatrixPosition(w.current.matrixWorld),s=e.clone().applyMatrix4(o).normalize();E.current={clickPoint:a,dir:s},b.current=r.current[t],p({component:"Arrow",axis:t,origin:i,directions:[s]}),x&&(x.enabled=!1),n.target.setPointerCapture(n.pointerId)}),[e,x,p,r,t]),R=C.useCallback((e=>{if(e.stopPropagation(),M||S(!0),E.current){const{clickPoint:o,dir:a}=E.current,[i,s]=(null==n?void 0:n[t])||[void 0,void 0];let l=((e,t,r,n)=>{const o=t.dot(t),a=t.dot(e)-t.dot(r),i=t.dot(n);return 0===i?-a/o:(oo.copy(n).multiplyScalar(o/i).sub(t),ao.copy(n).multiplyScalar(a/i).add(r).sub(e),-oo.dot(ao)/oo.dot(oo))})(o,a,e.ray.origin,e.ray.direction);void 0!==i&&(l=Math.max(l,i-b.current)),void 0!==s&&(l=Math.min(l,s-b.current)),r.current[t]=b.current+l,m&&(y.current.innerText=`${r.current[t].toFixed(2)}`),so.makeTranslation(a.x*l,a.y*l,a.z*l),h(so)}}),[h,M,r,n,t]),D=C.useCallback((e=>{m&&(y.current.style.display="none"),e.stopPropagation(),E.current=null,v(),x&&(x.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[x,v]),_=C.useCallback((e=>{e.stopPropagation(),S(!1)}),[]),{cylinderLength:z,coneWidth:k,coneLength:F,matrixL:L}=C.useMemo((()=>{const t=c?l/s*1.6:s/20,r=c?.2:s/5,n=c?1-r:s-r,o=(new P.Quaternion).setFromUnitVectors(io,e.clone().normalize());return{cylinderLength:n,coneWidth:t,coneLength:r,matrixL:(new P.Matrix4).makeRotationFromQuaternion(o)}}),[e,s,l,c]),A=M?d:u[t];return C.createElement("group",{ref:w},C.createElement("group",{matrix:L,matrixAutoUpdate:!1,onPointerDown:T,onPointerMove:R,onPointerUp:D,onPointerOut:_},C.createElement(H,{position:[0,-F,0]},C.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:a,ref:y})),C.createElement("mesh",{visible:!1,position:[0,(z+F)/2,0],userData:g},C.createElement("cylinderGeometry",{args:[1.4*k,1.4*k,z+F,8,1]})),C.createElement(ae,{transparent:!0,raycast:()=>null,depthTest:i,points:[0,0,0,0,z,0],lineWidth:l,color:A,opacity:f,polygonOffset:!0,renderOrder:1,polygonOffsetFactor:-10}),C.createElement("mesh",{raycast:()=>null,position:[0,z+F/2,0],renderOrder:500},C.createElement("coneGeometry",{args:[k,F,24,1]}),C.createElement("meshBasicMaterial",{transparent:!0,depthTest:i,color:A,opacity:f,polygonOffset:!0,polygonOffsetFactor:-10}))))},co=new P.Ray,uo=new P.Vector3,mo=new P.Matrix4,fo=({dir1:e,dir2:t,axis:r})=>{const{translation:n,translationLimits:a,annotationsClass:i,depthTest:s,scale:l,lineWidth:c,fixed:u,axisColors:d,hoveredColor:m,displayValues:f,opacity:p,onDragStart:h,onDrag:v,onDragEnd:g,userData:x}=C.useContext(no),y=o.useThree((e=>e.controls)),w=C.useRef(null),E=C.useRef(null),b=C.useRef(null),M=C.useRef(0),S=C.useRef(0),[T,R]=C.useState(!1),D=C.useCallback((e=>{f&&(w.current.innerText=`${n.current[(r+1)%3].toFixed(2)}, ${n.current[(r+2)%3].toFixed(2)}`,w.current.style.display="block"),e.stopPropagation();const t=e.point.clone(),o=(new P.Vector3).setFromMatrixPosition(E.current.matrixWorld),a=(new P.Vector3).setFromMatrixColumn(E.current.matrixWorld,0).normalize(),i=(new P.Vector3).setFromMatrixColumn(E.current.matrixWorld,1).normalize(),s=(new P.Vector3).setFromMatrixColumn(E.current.matrixWorld,2).normalize(),l=(new P.Plane).setFromNormalAndCoplanarPoint(s,o);b.current={clickPoint:t,e1:a,e2:i,plane:l},M.current=n.current[(r+1)%3],S.current=n.current[(r+2)%3],h({component:"Slider",axis:r,origin:o,directions:[a,i,s]}),y&&(y.enabled=!1),e.target.setPointerCapture(e.pointerId)}),[y,h,r]),_=C.useCallback((e=>{if(e.stopPropagation(),T||R(!0),b.current){const{clickPoint:t,e1:o,e2:i,plane:s}=b.current,[l,c]=(null==a?void 0:a[(r+1)%3])||[void 0,void 0],[u,d]=(null==a?void 0:a[(r+2)%3])||[void 0,void 0];co.copy(e.ray),co.intersectPlane(s,uo),co.direction.negate(),co.intersectPlane(s,uo),uo.sub(t);let[m,p]=((e,t,r)=>{const n=Math.abs(e.x)>=Math.abs(e.y)&&Math.abs(e.x)>=Math.abs(e.z)?0:Math.abs(e.y)>=Math.abs(e.x)&&Math.abs(e.y)>=Math.abs(e.z)?1:2,o=[0,1,2].sort(((e,r)=>Math.abs(t.getComponent(r))-Math.abs(t.getComponent(e)))),a=n===o[0]?o[1]:o[0],i=e.getComponent(n),s=e.getComponent(a),l=t.getComponent(n),c=t.getComponent(a),u=r.getComponent(n),d=(r.getComponent(a)-u*(s/i))/(c-l*(s/i));return[(u-d*l)/i,d]})(o,i,uo);void 0!==l&&(m=Math.max(m,l-M.current)),void 0!==c&&(m=Math.min(m,c-M.current)),void 0!==u&&(p=Math.max(p,u-S.current)),void 0!==d&&(p=Math.min(p,d-S.current)),n.current[(r+1)%3]=M.current+m,n.current[(r+2)%3]=S.current+p,f&&(w.current.innerText=`${n.current[(r+1)%3].toFixed(2)}, ${n.current[(r+2)%3].toFixed(2)}`),mo.makeTranslation(m*o.x+p*i.x,m*o.y+p*i.y,m*o.z+p*i.z),v(mo)}}),[v,T,n,a,r]),z=C.useCallback((e=>{f&&(w.current.style.display="none"),e.stopPropagation(),b.current=null,g(),y&&(y.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[y,g]),k=C.useCallback((e=>{e.stopPropagation(),R(!1)}),[]),F=C.useMemo((()=>{const r=e.clone().normalize(),n=t.clone().normalize();return(new P.Matrix4).makeBasis(r,n,r.clone().cross(n))}),[e,t]),L=u?1/7:l/7,A=u?.225:.225*l,B=T?m:d[r],U=C.useMemo((()=>[new P.Vector3(0,0,0),new P.Vector3(0,A,0),new P.Vector3(A,A,0),new P.Vector3(A,0,0),new P.Vector3(0,0,0)]),[A]);return C.createElement("group",{ref:E,matrix:F,matrixAutoUpdate:!1},C.createElement(H,{position:[0,0,0]},C.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:i,ref:w})),C.createElement("group",{position:[1.7*L,1.7*L,0]},C.createElement("mesh",{visible:!0,onPointerDown:D,onPointerMove:_,onPointerUp:z,onPointerOut:k,scale:A,userData:x},C.createElement("planeGeometry",null),C.createElement("meshBasicMaterial",{transparent:!0,depthTest:s,color:B,polygonOffset:!0,polygonOffsetFactor:-10,side:P.DoubleSide})),C.createElement(ae,{position:[-A/2,-A/2,0],transparent:!0,depthTest:s,points:U,lineWidth:c,color:B,opacity:p,polygonOffset:!0,polygonOffsetFactor:-10,userData:x})))},po=new P.Vector3,ho=new P.Vector3,vo=e=>180*e/Math.PI,go=e=>{let t=((e,t)=>{let r=Math.floor(e/t);return r=r<0?r+1:r,e-r*t})(e,2*Math.PI);return Math.abs(t)<1e-6?0:(t<0&&(t+=2*Math.PI),t)},xo=new P.Matrix4,yo=new P.Vector3,wo=new P.Ray,Eo=new P.Vector3,bo=({dir1:e,dir2:t,axis:r})=>{const{rotationLimits:n,annotationsClass:a,depthTest:i,scale:s,lineWidth:l,fixed:c,axisColors:u,hoveredColor:d,displayValues:m,opacity:f,onDragStart:p,onDrag:h,onDragEnd:v,userData:g}=C.useContext(no),x=o.useThree((e=>e.controls)),y=C.useRef(null),w=C.useRef(null),E=C.useRef(0),b=C.useRef(0),M=C.useRef(null),[S,T]=C.useState(!1),R=C.useCallback((e=>{m&&(y.current.innerText=`${vo(b.current).toFixed(0)}º`,y.current.style.display="block"),e.stopPropagation();const t=e.point.clone(),n=(new P.Vector3).setFromMatrixPosition(w.current.matrixWorld),o=(new P.Vector3).setFromMatrixColumn(w.current.matrixWorld,0).normalize(),a=(new P.Vector3).setFromMatrixColumn(w.current.matrixWorld,1).normalize(),i=(new P.Vector3).setFromMatrixColumn(w.current.matrixWorld,2).normalize(),s=(new P.Plane).setFromNormalAndCoplanarPoint(i,n);M.current={clickPoint:t,origin:n,e1:o,e2:a,normal:i,plane:s},p({component:"Rotator",axis:r,origin:n,directions:[o,a,i]}),x&&(x.enabled=!1),e.target.setPointerCapture(e.pointerId)}),[x,p,r]),D=C.useCallback((e=>{if(e.stopPropagation(),S||T(!0),M.current){const{clickPoint:t,origin:o,e1:a,e2:i,normal:s,plane:l}=M.current,[c,u]=(null==n?void 0:n[r])||[void 0,void 0];wo.copy(e.ray),wo.intersectPlane(l,Eo),wo.direction.negate(),wo.intersectPlane(l,Eo);let d=((e,t,r,n,o)=>{po.copy(e).sub(r),ho.copy(t).sub(r);const a=n.dot(n),i=o.dot(o),s=po.dot(n)/a,l=po.dot(o)/i,c=ho.dot(n)/a,u=ho.dot(o)/i,d=Math.atan2(l,s);return Math.atan2(u,c)-d})(t,Eo,o,a,i),f=vo(d);e.shiftKey&&(f=10*Math.round(f/10),d=(e=>e*Math.PI/180)(f)),void 0!==c&&void 0!==u&&u-c<2*Math.PI?(d=go(d),d=d>Math.PI?d-2*Math.PI:d,d=A.default(d,c-E.current,u-E.current),b.current=E.current+d):(b.current=go(E.current+d),b.current=b.current>Math.PI?b.current-2*Math.PI:b.current),m&&(f=vo(b.current),y.current.innerText=`${f.toFixed(0)}º`),xo.makeRotationAxis(s,d),yo.copy(o).applyMatrix4(xo).sub(o).negate(),xo.setPosition(yo),h(xo)}}),[h,S,n,r]),_=C.useCallback((e=>{m&&(y.current.style.display="none"),e.stopPropagation(),E.current=b.current,M.current=null,v(),x&&(x.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[x,v]),z=C.useCallback((e=>{e.stopPropagation(),T(!1)}),[]),k=C.useMemo((()=>{const r=e.clone().normalize(),n=t.clone().normalize();return(new P.Matrix4).makeBasis(r,n,r.clone().cross(n))}),[e,t]),F=c?.65:.65*s,L=C.useMemo((()=>{const e=[];for(let t=0;t<=32;t++){const r=t*(Math.PI/2)/32;e.push(new P.Vector3(Math.cos(r)*F,Math.sin(r)*F,0))}return e}),[F]);return C.createElement("group",{ref:w,onPointerDown:R,onPointerMove:D,onPointerUp:_,onPointerOut:z,matrix:k,matrixAutoUpdate:!1},C.createElement(H,{position:[F,F,0]},C.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:a,ref:y})),C.createElement(ae,{points:L,lineWidth:4*l,visible:!1,userData:g}),C.createElement(ae,{transparent:!0,raycast:()=>null,depthTest:i,points:L,lineWidth:l,color:S?d:u[r],opacity:f,polygonOffset:!0,polygonOffsetFactor:-10}))},Mo=new P.Vector3,So=new P.Vector3,Co=new P.Vector3,To=(e,t,r,n=1)=>{const o=Mo.set(e.x/r.width*2-1,-e.y/r.height*2+1,n);return o.unproject(t),o},Po=(e,t,r,n)=>{const o=((e,t,r)=>{const n=r.width/2,o=r.height/2;t.updateMatrixWorld(!1);const a=e.project(t);return a.x=a.x*n+n,a.y=-a.y*o+o,a})(Co.copy(e),r,n);let a=0;for(let i=0;i<2;++i){const s=So.copy(o).setComponent(i,o.getComponent(i)+t),l=To(s,r,n,s.z);a=Math.max(a,e.distanceTo(l))}return a},Ro=new P.Matrix4,Do=new P.Matrix4,_o=new P.Matrix4,zo=new P.Matrix4,ko=new P.Matrix4,Fo=new P.Matrix4,Lo=new P.Matrix4,Ao=new P.Matrix4,Bo=new P.Box3,Uo=new P.Box3,Vo=new P.Vector3,Io=new P.Vector3,Oo=new P.Vector3,jo=new P.Vector3,Wo=new P.Vector3(1,0,0),Go=new P.Vector3(0,1,0),No=new P.Vector3(0,0,1),Ho=C.forwardRef((({matrix:e,onDragStart:t,onDrag:r,onDragEnd:n,autoTransform:a=!0,anchor:i,disableAxes:s=!1,disableSliders:l=!1,disableRotations:c=!1,activeAxes:u=[!0,!0,!0],offset:d=[0,0,0],rotation:m=[0,0,0],scale:f=1,lineWidth:p=4,fixed:h=!1,translationLimits:v,rotationLimits:g,depthTest:x=!0,axisColors:y=["#ff2060","#20df80","#2080ff"],hoveredColor:w="#ffff40",displayValues:E=!0,annotationsClass:b,opacity:M=1,visible:S=!0,userData:T,children:R},D)=>{const _=o.useThree((e=>e.invalidate)),z=C.useRef(null),k=C.useRef(null),F=C.useRef(null),L=C.useRef(null),A=C.useRef([0,0,0]);C.useLayoutEffect((()=>{i&&(L.current.updateWorldMatrix(!0,!0),zo.copy(L.current.matrixWorld).invert(),Bo.makeEmpty(),L.current.traverse((e=>{e.geometry&&(e.geometry.boundingBox||e.geometry.computeBoundingBox(),Fo.copy(e.matrixWorld).premultiply(zo),Uo.copy(e.geometry.boundingBox),Uo.applyMatrix4(Fo),Bo.union(Uo))})),Vo.copy(Bo.max).add(Bo.min).multiplyScalar(.5),Io.copy(Bo.max).sub(Bo.min).multiplyScalar(.5),Oo.copy(Io).multiply(new P.Vector3(...i)).add(Vo),jo.set(...d).add(Oo),F.current.position.copy(jo),_())}));const B=C.useMemo((()=>({onDragStart:e=>{Ro.copy(k.current.matrix),Do.copy(k.current.matrixWorld),t&&t(e),_()},onDrag:e=>{_o.copy(z.current.matrixWorld),zo.copy(_o).invert(),ko.copy(Do).premultiply(e),Fo.copy(ko).premultiply(zo),Lo.copy(Ro).invert(),Ao.copy(Fo).multiply(Lo),a&&k.current.matrix.copy(Fo),r&&r(Fo,Ao,ko,e),_()},onDragEnd:()=>{n&&n(),_()},translation:A,translationLimits:v,rotationLimits:g,axisColors:y,hoveredColor:w,opacity:M,scale:f,lineWidth:p,fixed:h,displayValues:E,depthTest:x,userData:T,annotationsClass:b})),[t,r,n,A,v,g,x,f,p,h,...y,w,M,E,T,a,b]),U=new P.Vector3;return o.useFrame((e=>{if(h){const o=Po(F.current.getWorldPosition(U),f,e.camera,e.size);var t,r,n;if(F.current)(null==(t=F.current)?void 0:t.scale.x)===o&&(null==(r=F.current)?void 0:r.scale.y)===o&&(null==(n=F.current)?void 0:n.scale.z)===o||(F.current.scale.setScalar(o),e.invalidate())}})),C.useImperativeHandle(D,(()=>k.current),[]),C.createElement(no.Provider,{value:B},C.createElement("group",{ref:z},C.createElement("group",{ref:k,matrix:e,matrixAutoUpdate:!1},C.createElement("group",{visible:S,ref:F,position:d,rotation:m},!s&&u[0]&&C.createElement(lo,{axis:0,direction:Wo}),!s&&u[1]&&C.createElement(lo,{axis:1,direction:Go}),!s&&u[2]&&C.createElement(lo,{axis:2,direction:No}),!l&&u[0]&&u[1]&&C.createElement(fo,{axis:2,dir1:Wo,dir2:Go}),!l&&u[0]&&u[2]&&C.createElement(fo,{axis:1,dir1:No,dir2:Wo}),!l&&u[2]&&u[1]&&C.createElement(fo,{axis:0,dir1:Go,dir2:No}),!c&&u[0]&&u[1]&&C.createElement(bo,{axis:2,dir1:Wo,dir2:Go}),!c&&u[0]&&u[2]&&C.createElement(bo,{axis:1,dir1:No,dir2:Wo}),!c&&u[2]&&u[1]&&C.createElement(bo,{axis:0,dir1:Go,dir2:No})),C.createElement("group",{ref:L},R))))}));exports.AccumulativeShadows=Ir,exports.AdaptiveDpr=function({pixelated:e}){const t=o.useThree((e=>e.gl)),r=o.useThree((e=>e.internal.active)),n=o.useThree((e=>e.performance.current)),a=o.useThree((e=>e.viewport.initialDpr)),i=o.useThree((e=>e.setDpr));return C.useEffect((()=>{const n=t.domElement;return()=>{r&&i(a),e&&n&&(n.style.imageRendering="auto")}}),[]),C.useEffect((()=>{i(n*a),e&&t.domElement&&(t.domElement.style.imageRendering=1===n?"auto":"pixelated")}),[n]),null},exports.AdaptiveEvents=function(){const e=o.useThree((e=>e.get)),t=o.useThree((e=>e.setEvents)),r=o.useThree((e=>e.performance.current));return C.useEffect((()=>{const r=e().events.enabled;return()=>t({enabled:r})}),[]),C.useEffect((()=>t({enabled:1===r})),[r]),null},exports.ArcballControls=qe,exports.AsciiRenderer=function({renderIndex:e=1,bgColor:t="black",fgColor:r="white",characters:n=" .:-+*=%@#",invert:a=!0,color:i=!1,resolution:s=.15}){const{size:l,gl:c,scene:d,camera:m}=o.useThree(),f=C.useMemo((()=>{const e=new u.AsciiEffect(c,n,{invert:a,color:i,resolution:s});return e.domElement.style.position="absolute",e.domElement.style.top="0px",e.domElement.style.left="0px",e.domElement.style.pointerEvents="none",e}),[n,a,i,s]);C.useLayoutEffect((()=>{f.domElement.style.color=r,f.domElement.style.backgroundColor=t}),[r,t]),C.useEffect((()=>(c.domElement.style.opacity="0",c.domElement.parentNode.appendChild(f.domElement),()=>{c.domElement.style.opacity="1",c.domElement.parentNode.removeChild(f.domElement)})),[f]),C.useEffect((()=>{f.setSize(l.width,l.height)}),[f,l]),o.useFrame((e=>{f.render(d,m)}),e)},exports.BBAnchor=({anchor:e,...t})=>{const r=C.useRef(null),n=C.useRef(null);return C.useEffect((()=>{var e,t;null!=(e=r.current)&&null!=(t=e.parent)&&t.parent&&(n.current=r.current.parent,r.current.parent.parent.add(r.current))}),[]),o.useFrame((()=>{n.current&&(_t.setFromObject(n.current),_t.getSize(zt),r.current.position.set(n.current.position.x+zt.x*e[0]/2,n.current.position.y+zt.y*e[1]/2,n.current.position.z+zt.z*e[2]/2))})),C.createElement("group",S.default({ref:r},t))},exports.Backdrop=function({children:e,floor:t=.25,segments:r=20,receiveShadow:n,...o}){const a=C.useRef(null);return C.useLayoutEffect((()=>{let e=0;const n=r/r/2,o=a.current.attributes.position;for(let a=0;a<r+1;a++)for(let i=0;i<r+1;i++)o.setXYZ(e++,a/r-n+(0===a?-t:0),i/r-n,Nr(a/r));o.needsUpdate=!0,a.current.computeVertexNormals()}),[r,t]),C.createElement("group",o,C.createElement("mesh",{receiveShadow:n,rotation:[-Math.PI/2,0,Math.PI/2]},C.createElement("planeGeometry",{ref:a,args:[1,1,r,r]}),e))},exports.BakeShadows=function(){const e=o.useThree((e=>e.gl));return t.useEffect((()=>(e.shadowMap.autoUpdate=!1,e.shadowMap.needsUpdate=!0,()=>{e.shadowMap.autoUpdate=e.shadowMap.needsUpdate=!0})),[e.shadowMap]),null},exports.Billboard=ne,exports.Bounds=Mr,exports.Box=Qt,exports.CameraShake=Cr,exports.Capsule=hr,exports.CatmullRomLine=ce,exports.Center=wr,exports.Circle=Jt,exports.Clone=Re,exports.Cloud=function({opacity:e=.5,speed:t=.4,width:r=10,depth:n=1.5,segments:a=20,texture:i="https://rawcdn.githack.com/pmndrs/drei-assets/9225a9f1fbd449d9411125c2f419b843d0308c9f/cloud.png",color:s="#ffffff",depthTest:l=!0,...c}){const u=o.useThree((e=>e.gl)),d=C.useRef(),m=ge(i),f=C.useMemo((()=>[...new Array(a)].map(((e,n)=>({x:r/2-Math.random()*r,y:r/2-Math.random()*r,scale:.4+Math.sin((n+1)/a*Math.PI)*(10*(.2+Math.random())),density:Math.max(.2,Math.random()),rotation:Math.max(.002,.005*Math.random())*t})))),[r,a,t]);return o.useFrame((e=>{var t;return null==(t=d.current)?void 0:t.children.forEach(((t,r)=>{t.children[0].rotation.z+=f[r].rotation,t.children[0].scale.setScalar(f[r].scale+(1+Math.sin(e.clock.getElapsedTime()/10))/2*r/10)}))})),C.createElement("group",c,C.createElement("group",{position:[0,0,a/2*n],ref:d},f.map((({x:t,y:r,scale:o,density:a},i)=>C.createElement(ne,{key:i,position:[t,r,-i*n]},C.createElement(nr,{scale:o,rotation:[0,0,0]},C.createElement("meshStandardMaterial",{map:m,"map-encoding":u.outputEncoding,transparent:!0,opacity:o/6*a*e,depthTest:l,color:s})))))))},exports.ComputedAttribute=({compute:e,name:t,...r})=>{const[o]=C.useState((()=>new n.BufferAttribute(new Float32Array(0),1))),a=C.useRef(null);return C.useLayoutEffect((()=>{if(a.current){var t;const r=null!==(t=a.current.parent)&&void 0!==t?t:a.current.__r3f.parent,n=e(r);a.current.copy(n)}}),[e]),C.createElement("primitive",S.default({ref:a,object:o,attach:`attributes-${t}`},r))},exports.Cone=er,exports.ContactShadows=Ar,exports.CubeCamera=function({children:e,fog:t,frames:r=1/0,resolution:a=256,near:i=.1,far:s=1e3,envMap:l,...c}){const u=C.useRef(),[d,m]=C.useState(null),f=o.useThree((({scene:e})=>e)),p=o.useThree((({gl:e})=>e)),h=C.useMemo((()=>{const e=new n.WebGLCubeRenderTarget(a);return e.texture.encoding=p.outputEncoding,e.texture.type=n.HalfFloatType,e}),[a]);let v,g,x=0;return o.useFrame((()=>{d&&u.current&&(r===1/0||x<r)&&(u.current.visible=!1,v=f.fog,g=f.background,f.background=l||g,f.fog=t||v,d.update(p,f),f.fog=v,f.background=g,u.current.visible=!0,x++)})),C.createElement("group",c,C.createElement("cubeCamera",{ref:m,args:[i,s,h]}),C.createElement("group",{ref:u},e(h.texture)))},exports.CubicBezierLine=le,exports.CurveModifier=Lt,exports.CycleRaycast=function({onChanged:e,portal:t,preventDefault:r=!0,scroll:n=!0,keyCode:a=9}){const i=C.useRef(0),s=o.useThree((e=>e.setEvents)),l=o.useThree((e=>e.get)),c=o.useThree((e=>e.gl));return C.useEffect((()=>{var o;let u,d=[];const m=l().events.filter,f=null!==(o=null==t?void 0:t.current)&&void 0!==o?o:c.domElement.parentNode,p=()=>f&&e&&e(d,Math.round(i.current)%d.length);s({filter:(e,t)=>{let r=[...e];r.length===d.length&&d.every((e=>r.map((e=>e.object.uuid)).includes(e.object.uuid)))||(i.current=0,d=r,p()),m&&(r=m(r,t));for(let e=0;e<Math.round(i.current)%r.length;e++){const e=r.shift();r=[...r,e]}return r}});const h=e=>{var t,r;i.current=e(i.current),null==(t=l().events.handlers)||t.onPointerCancel(void 0),null==(r=l().events.handlers)||r.onPointerMove(u),p()},v=e=>{(e.keyCode||e.which===a)&&(r&&e.preventDefault(),d.length>1&&h((e=>e+1)))},g=e=>{r&&e.preventDefault();let t=0;e||(e=window.event),e.wheelDelta?t=e.wheelDelta/120:e.detail&&(t=-e.detail/3),d.length>1&&h((e=>Math.abs(e-t)))},x=e=>u=e;return document.addEventListener("pointermove",x,{passive:!0}),n&&document.addEventListener("wheel",g),void 0!==a&&document.addEventListener("keydown",v),()=>{s({filter:m}),void 0!==a&&document.removeEventListener("keydown",v),n&&document.removeEventListener("wheel",g),document.removeEventListener("pointermove",x)}}),[c,l,s,r,n,a]),null},exports.Cylinder=tr,exports.Decal=function({debug:e,mesh:t,children:r,position:n,rotation:a,scale:i,...s}){const l=C.useRef(null),c=C.useRef(null);return C.useLayoutEffect((()=>{const e=(null==t?void 0:t.current)||l.current.parent,r=l.current;if(!(e instanceof P.Mesh))throw new Error('Decal must have a Mesh as parent or specify its "mesh" prop');const s={position:new P.Vector3,rotation:new P.Euler,scale:new P.Vector3(1,1,1)};if(e){o.applyProps(s,{position:n,scale:i});const t=e.matrixWorld.clone();if(e.matrixWorld.identity(),a&&"number"!=typeof a)o.applyProps(s,{rotation:a});else{const t=new P.Object3D;t.position.copy(s.position),t.lookAt(e.position),"number"==typeof a&&t.rotateZ(a),o.applyProps(s,{rotation:t.rotation})}return r.geometry=new u.DecalGeometry(e,s.position,s.rotation,s.scale),c.current&&o.applyProps(c.current,s),e.matrixWorld=t,()=>{r.geometry.dispose()}}}),[t,...Fe(n),...Fe(i),...Fe(a)]),C.createElement("mesh",{ref:l},r||C.createElement("meshStandardMaterial",S.default({transparent:!0,polygonOffset:!0,polygonOffsetFactor:-10},s)),e&&C.createElement("mesh",{ref:c},C.createElement("boxGeometry",null),C.createElement("meshNormalMaterial",{wireframe:!0}),C.createElement("axesHelper",null)))},exports.Detailed=$n,exports.DeviceOrientationControls=We,exports.Dodecahedron=mr,exports.Edges=function({userData:e,children:t,geometry:r,threshold:n=15,color:o="black",...a}){const i=C.useRef(null);return C.useLayoutEffect((()=>{const e=i.current.parent;if(e){const t=r||e.geometry;t===i.current.userData.currentGeom&&n===i.current.userData.currentThreshold||(i.current.userData.currentGeom=t,i.current.userData.currentThreshold=n,i.current.geometry=new P.EdgesGeometry(t,n))}})),C.createElement("lineSegments",S.default({ref:i,raycast:()=>null},a),t||C.createElement("lineBasicMaterial",{color:o}))},exports.Effects=pe,exports.Environment=Lr,exports.EnvironmentCube=zr,exports.EnvironmentMap=Dr,exports.EnvironmentPortal=kr,exports.Extrude=fr,exports.FirstPersonControls=Ze,exports.Float=Tr,exports.FlyControls=Ge,exports.GizmoHelper=({alignment:e="bottom-right",margin:t=[80,80],renderPriority:r=1,onUpdate:a,onTarget:i,children:s})=>{const l=o.useThree((e=>e.size)),c=o.useThree((e=>e.camera)),u=o.useThree((e=>e.controls)),d=o.useThree((e=>e.invalidate)),m=C.useRef(),f=C.useRef(null),p=C.useRef(!1),h=C.useRef(0),v=C.useRef(new n.Vector3(0,0,0)),g=C.useRef(new n.Vector3(0,0,0));C.useEffect((()=>{g.current.copy(c.up)}),[c]);const x=C.useCallback((e=>{p.current=!0,(u||i)&&(v.current=(null==u?void 0:u.target)||(null==i?void 0:i())),h.current=c.position.distanceTo(it),ot.copy(c.quaternion),st.copy(e).multiplyScalar(h.current).add(it),rt.lookAt(st),at.copy(rt.quaternion),d()}),[u,c,i,d]);o.useFrame(((e,t)=>{if(f.current&&m.current){var r;if(p.current)if(ot.angleTo(at)<.01)p.current=!1,"minPolarAngle"in u&&c.up.copy(g.current);else{const e=t*tt;ot.rotateTowards(at,e),c.position.set(0,0,1).applyQuaternion(ot).multiplyScalar(h.current).add(v.current),c.up.set(0,1,0).applyQuaternion(ot).normalize(),c.quaternion.copy(ot),a?a():u&&u.update(),d()}nt.copy(c.matrix).invert(),null==(r=m.current)||r.quaternion.setFromRotationMatrix(nt)}}));const y=C.useMemo((()=>({tweenCamera:x})),[x]),[w,E]=t,b=e.endsWith("-center")?0:e.endsWith("-left")?-l.width/2+w:l.width/2-w,M=e.startsWith("center-")?0:e.startsWith("top-")?l.height/2-E:-l.height/2+E;return C.createElement(Qe,{renderPriority:r},C.createElement(Je.Provider,{value:y},C.createElement(Oe,{makeDefault:!0,ref:f,position:[0,0,200]}),C.createElement("group",{ref:m,position:[b,M,0]},s)))},exports.GizmoViewcube=e=>C.createElement("group",{scale:[60,60,60]},C.createElement(yt,e),vt.map(((t,r)=>C.createElement(wt,S.default({key:r,position:t,dimensions:gt[r]},e)))),pt.map(((t,r)=>C.createElement(wt,S.default({key:r,position:t,dimensions:ht},e)))),C.createElement("ambientLight",{intensity:.5}),C.createElement("pointLight",{position:[10,10,10],intensity:.5})),exports.GizmoViewport=({hideNegativeAxes:e,hideAxisHeads:t,disabled:r,font:n="18px Inter var, Arial, sans-serif",axisColors:o=["#ff2060","#20df80","#2080ff"],axisHeadScale:a=1,axisScale:i,labels:s=["X","Y","Z"],labelColor:l="#000",onClick:c,...u})=>{const[d,m,f]=o,{tweenCamera:p}=et(),h={font:n,disabled:r,labelColor:l,onClick:c,axisHeadScale:a,onPointerDown:r?void 0:e=>{p(e.object.position),e.stopPropagation()}};return C.createElement("group",S.default({scale:40},u),C.createElement(Et,{color:d,rotation:[0,0,0],scale:i}),C.createElement(Et,{color:m,rotation:[0,0,Math.PI/2],scale:i}),C.createElement(Et,{color:f,rotation:[0,-Math.PI/2,0],scale:i}),!t&&C.createElement(C.Fragment,null,C.createElement(bt,S.default({arcStyle:d,position:[1,0,0],label:s[0]},h)),C.createElement(bt,S.default({arcStyle:m,position:[0,1,0],label:s[1]},h)),C.createElement(bt,S.default({arcStyle:f,position:[0,0,1],label:s[2]},h)),!e&&C.createElement(C.Fragment,null,C.createElement(bt,S.default({arcStyle:d,position:[-1,0,0]},h)),C.createElement(bt,S.default({arcStyle:m,position:[0,-1,0]},h)),C.createElement(bt,S.default({arcStyle:f,position:[0,0,-1]},h)))),C.createElement("ambientLight",{intensity:.5}),C.createElement("pointLight",{position:[10,10,10],intensity:.5}))},exports.Gltf=Ve,exports.GradientTexture=function({stops:e,colors:t,size:r=1024,...n}){const a=o.useThree((e=>e.gl)),i=C.useMemo((()=>{const n=document.createElement("canvas"),o=n.getContext("2d");n.width=16,n.height=r;const a=o.createLinearGradient(0,0,0,r);let i=e.length;for(;i--;)a.addColorStop(e[i],t[i]);o.fillStyle=a,o.fillRect(0,0,16,r);const s=new P.Texture(n);return s.needsUpdate=!0,s}),[e]);return C.useEffect((()=>()=>{i.dispose()}),[i]),C.createElement("primitive",S.default({object:i,attach:"map",encoding:a.outputEncoding},n))},exports.Grid=St,exports.Html=H,exports.Hud=Qe,exports.Icosahedron=ur,exports.Image=be,exports.Instance=Vn,exports.Instances=In,exports.IsObject=ve,exports.KeyboardControls=function({map:e,children:t,onChange:r,domElement:n}){const o=e.map((e=>e.name+e.keys)).join("-"),a=C.useMemo((()=>R.default(c.subscribeWithSelector((()=>e.reduce(((e,t)=>({...e,[t.name]:!1})),{}))))),[o]),i=C.useMemo((()=>[a.subscribe,a.getState,a]),[o]),s=a.setState;return C.useEffect((()=>{const t=e.map((({name:e,keys:t,up:n})=>({keys:t,up:n,fn:t=>{s({[e]:t}),r&&r(e,t,i[2]())}}))).reduce(((e,{keys:t,fn:r,up:n=!0})=>(t.forEach((t=>e[t]={fn:r,pressed:!1,up:n})),e)),{}),o=({key:e,code:r})=>{const n=t[e]||t[r];if(!n)return;const{fn:o,pressed:a,up:i}=n;n.pressed=!0,!i&&a||o(!0)},a=({key:e,code:r})=>{const n=t[e]||t[r];if(!n)return;const{fn:o,up:a}=n;n.pressed=!1,a&&o(!1)},l=n||window;return l.addEventListener("keydown",o,{passive:!0}),l.addEventListener("keyup",a,{passive:!0}),()=>{l.removeEventListener("keydown",o),l.removeEventListener("keyup",a)}}),[n,o]),C.createElement(te.Provider,{value:i,children:t})},exports.Lathe=pr,exports.Lightformer=Jr,exports.Line=ae,exports.Loader=function({containerStyles:e,innerStyles:t,barStyles:r,dataStyles:n,dataInterpolation:o=X,initialState:a=(e=>e)}){const{active:i,progress:s}=q(),l=C.useRef(0),c=C.useRef(0),u=C.useRef(null),[d,m]=C.useState(a(i));C.useEffect((()=>{let e;return i!==d&&(e=setTimeout((()=>m(i)),300)),()=>clearTimeout(e)}),[d,i]);const f=C.useCallback((()=>{u.current&&(l.current+=(s-l.current)/2,(l.current>.95*s||100===s)&&(l.current=s),u.current.innerText=o(l.current),l.current<s&&(c.current=requestAnimationFrame(f)))}),[o,s]);return C.useEffect((()=>(f(),()=>cancelAnimationFrame(c.current))),[f]),d?C.createElement("div",{style:{...Y.container,opacity:i?1:0,...e}},C.createElement("div",null,C.createElement("div",{style:{...Y.inner,...t}},C.createElement("div",{style:{...Y.bar,transform:`scaleX(${s/100})`,...r}}),C.createElement("span",{ref:u,style:{...Y.data,...n}})))):null},exports.MapControls=Ne,exports.MarchingCube=ze,exports.MarchingCubes=_e,exports.MarchingPlane=ke,exports.Mask=function({id:e=1,children:t,colorWrite:r=!1,depthWrite:n=!1,...o}){const a=C.useMemo((()=>({colorWrite:r,depthWrite:n,stencilWrite:!0,stencilRef:e,stencilFunc:P.AlwaysStencilFunc,stencilFail:P.ReplaceStencilOp,stencilZFail:P.ReplaceStencilOp,stencilZPass:P.ReplaceStencilOp})),[e,r,n]);return C.createElement("mesh",S.default({renderOrder:-e},o),C.createElement("meshBasicMaterial",a),"function"==typeof t?t(a):t)},exports.Merged=On,exports.MeshDistortMaterial=Bt,exports.MeshReflectorMaterial=Wt,exports.MeshRefractionMaterial=function({aberrationStrength:e=0,fastChroma:r=!0,envMap:n,...a}){o.extend({MeshRefractionMaterial:Gt});const i=t.useRef(),{size:s}=o.useThree(),l=t.useMemo((()=>{var t,o;const a={},i=(s=n)&&s.isCubeTexture;var s;const l=(null!==(t=i?null==(o=n.image[0])?void 0:o.width:n.image.width)&&void 0!==t?t:1024)/4,c=Math.floor(Math.log2(l)),u=Math.pow(2,c),d=3*Math.max(u,112),m=4*u;return i&&(a.ENVMAP_TYPE_CUBEM=""),a.CUBEUV_TEXEL_WIDTH=""+1/d,a.CUBEUV_TEXEL_HEIGHT=""+1/m,a.CUBEUV_MAX_MIP=`${c}.0`,e>0&&(a.CHROMATIC_ABERRATIONS=""),r&&(a.FAST_CHROMA=""),a}),[e,r]);return t.useLayoutEffect((()=>{var e,t,r;const n=null==(e=i.current)||null==(t=e.__r3f)||null==(r=t.parent)?void 0:r.geometry;n&&i.current.bvh.updateFrom(new y.MeshBVH(n.toNonIndexed(),{lazyGeneration:!1,strategy:y.SAH}))}),[]),C.createElement("meshRefractionMaterial",S.default({key:JSON.stringify(l),defines:l,ref:i,resolution:[s.width,s.height],aberrationStrength:e,envMap:n},a))},exports.MeshTransmissionMaterial=Ht,exports.MeshWobbleMaterial=Vt,exports.Octahedron=dr,exports.OrbitControls=He,exports.OrthographicCamera=Oe,exports.PerformanceMonitor=function({iterations:e=10,ms:r=250,threshold:n=.75,step:a=.1,factor:i=.5,flipflops:s=1/0,bounds:l=(e=>e>100?[60,100]:[40,60]),onIncline:c,onDecline:u,onChange:d,onFallback:m,children:f}){const p=Math.pow(10,0),[h,v]=t.useState((()=>({fps:0,index:0,factor:i,flipped:0,refreshrate:0,fallback:!1,frames:[],averages:[],subscriptions:new Map,subscribe:e=>{const t=Symbol();return h.subscriptions.set(t,e.current),()=>{h.subscriptions.delete(t)}}})));let g=0;return o.useFrame((()=>{const{frames:t,averages:o}=h;if(!h.fallback&&o.length<e){t.push(performance.now());const i=t[t.length-1]-t[0];if(i>=r){if(h.fps=Math.round(t.length/i*1e3*p)/p,h.refreshrate=Math.max(h.refreshrate,h.fps),o[h.index++%e]=h.fps,o.length===e){const[t,r]=l(h.refreshrate),i=o.filter((e=>e>=r)),f=o.filter((e=>e<t));i.length>e*n&&(h.factor=Math.min(1,h.factor+a),h.flipped++,c&&c(h),h.subscriptions.forEach((e=>e.onIncline&&e.onIncline(h)))),f.length>e*n&&(h.factor=Math.max(0,h.factor-a),h.flipped++,u&&u(h),h.subscriptions.forEach((e=>e.onDecline&&e.onDecline(h)))),g!==h.factor&&(g=h.factor,d&&d(h),h.subscriptions.forEach((e=>e.onChange&&e.onChange(h)))),h.flipped>s&&!h.fallback&&(h.fallback=!0,m&&m(h),h.subscriptions.forEach((e=>e.onFallback&&e.onFallback(h)))),h.averages=[]}h.frames=[]}}})),C.createElement(Kn.Provider,{value:h},f)},exports.PerspectiveCamera=je,exports.PivotControls=Ho,exports.Plane=nr,exports.Point=Mn,exports.PointMaterial=qt,exports.PointMaterialImpl=$t,exports.PointerLockControls=Ye,exports.Points=Cn,exports.PointsBuffer=Sn,exports.Polyhedron=cr,exports.PositionPoint=vn,exports.PositionalAudio=ue,exports.Preload=function({all:e,scene:t,camera:r}){const a=o.useThree((({gl:e})=>e)),i=o.useThree((({camera:e})=>e)),s=o.useThree((({scene:e})=>e));return C.useLayoutEffect((()=>{const o=[];e&&(t||s).traverse((e=>{!1===e.visible&&(o.push(e),e.visible=!0)})),a.compile(t||s,r||i);const l=new n.WebGLCubeRenderTarget(128);new n.CubeCamera(.01,1e5,l).update(a,t||s),l.dispose(),o.forEach((e=>e.visible=!1))}),[]),null},exports.PresentationControls=function({enabled:e=!0,snap:t,global:r,cursor:a=!0,children:i,speed:c=1,rotation:u=[0,0,0],zoom:d=1,polar:m=[0,Math.PI/2],azimuth:f=[-1/0,1/0],config:p={mass:1,tension:170,friction:26}}){const{size:h,gl:v}=o.useThree(),g=C.useMemo((()=>[u[0]+m[0],u[0]+m[1]]),[u[0],m[0],m[1]]),x=C.useMemo((()=>[u[1]+f[0],u[1]+f[1]]),[u[1],f[0],f[1]]),y=C.useMemo((()=>[n.MathUtils.clamp(u[0],...g),n.MathUtils.clamp(u[1],...x),u[2]]),[u[0],u[1],u[2],g,x]),[w,E]=s.useSpring((()=>({scale:1,rotation:y,config:p})));C.useEffect((()=>{E.start({scale:1,rotation:y,config:p})}),[y]),C.useEffect((()=>(r&&a&&e&&(v.domElement.style.cursor="grab"),()=>{v.domElement.style.cursor="default"})),[r,a,v.domElement,e]);const b=l.useGesture({onHover:({last:t})=>{a&&!r&&e&&(v.domElement.style.cursor=t?"auto":"grab")},onDrag:({down:r,delta:[o,i],memo:[s,l]=w.rotation.animation.to||y})=>{if(!e)return[i,o];a&&(v.domElement.style.cursor=r?"grabbing":"grab"),o=n.MathUtils.clamp(l+o/h.width*Math.PI*c,...x),i=n.MathUtils.clamp(s+i/h.height*Math.PI*c,...g);const u=t&&!r&&"boolean"!=typeof t?t:p;return E.start({scale:r&&i>g[1]/2?d:1,rotation:t&&!r?y:[i,o,0],config:e=>"scale"===e?{...u,friction:3*u.friction}:u}),[i,o]}},{target:r?v.domElement:void 0});return C.createElement(s.a.group,S.default({},null==b?void 0:b(),w),i)},exports.QuadraticBezierLine=se,exports.RandomizedLight=Or,exports.Reflector=$r,exports.RenderTexture=Qn,exports.Ring=lr,exports.RoundedBox=gr,exports.Sampler=function({children:e,weight:t,transform:r,instances:n,mesh:o,count:a=16,...i}){const s=C.useRef(null),l=C.useRef(null),c=C.useRef(null);return C.useEffect((()=>{var e,t;l.current=null!==(e=null==n?void 0:n.current)&&void 0!==e?e:s.current.children.find((e=>e.hasOwnProperty("instanceMatrix"))),c.current=null!==(t=null==o?void 0:o.current)&&void 0!==t?t:s.current.children.find((e=>"Mesh"===e.type))}),[e,null==o?void 0:o.current,null==n?void 0:n.current]),Pe(c,a,r,t,l),C.createElement("group",S.default({ref:s},i),e)},exports.ScreenQuad=yr,exports.ScreenSpace=oe,exports.Scroll=ee,exports.ScrollControls=function({eps:e=1e-5,enabled:t=!0,infinite:r,horizontal:n,pages:a=1,distance:i=1,damping:s=4,style:l={},children:c}){const{get:u,setEvents:d,gl:m,size:f,invalidate:p,events:h}=o.useThree(),[v]=C.useState((()=>document.createElement("div"))),[g]=C.useState((()=>document.createElement("div"))),[x]=C.useState((()=>document.createElement("div"))),y=m.domElement.parentNode,w=C.useRef(0),E=C.useMemo((()=>{const t={el:v,eps:e,fill:g,fixed:x,horizontal:n,damping:s,offset:0,delta:0,scroll:w,pages:a,range(e,t,r=0){const n=e-r,o=n+t+2*r;return this.offset<n?0:this.offset>o?1:(this.offset-n)/(o-n)},curve(e,t,r=0){return Math.sin(this.range(e,t,r)*Math.PI)},visible(e,t,r=0){const n=e-r,o=n+t+2*r;return this.offset>=n&&this.offset<=o}};return t}),[e,s,n,a]);C.useEffect((()=>{v.style.position="absolute",v.style.width="100%",v.style.height="100%",v.style[n?"overflowX":"overflowY"]="auto",v.style[n?"overflowY":"overflowX"]="hidden",v.style.top="0px",v.style.left="0px";for(const e in l)v.style[e]=l[e];x.style.position="sticky",x.style.top="0px",x.style.left="0px",x.style.width="100%",x.style.height="100%",x.style.overflow="hidden",v.appendChild(x),g.style.height=n?"100%":a*i*100+"%",g.style.width=n?a*i*100+"%":"100%",g.style.pointerEvents="none",v.appendChild(g),y.appendChild(v),v[n?"scrollLeft":"scrollTop"]=1;const e=h.connected||m.domElement;requestAnimationFrame((()=>null==h.connect?void 0:h.connect(v)));const t=u().events.compute;return d({compute(e,t){const{left:r,top:n}=y.getBoundingClientRect(),o=e.clientX-r,a=e.clientY-n;t.pointer.set(o/t.size.width*2-1,-a/t.size.height*2+1),t.raycaster.setFromCamera(t.pointer,t.camera)}}),()=>{y.removeChild(v),d({compute:t}),null==h.connect||h.connect(e)}}),[a,i,n,v,g,x,y]),C.useEffect((()=>{if(h.connected===v){const e=f[n?"width":"height"],o=v[n?"scrollWidth":"scrollHeight"],a=o-e;let i=0,s=!0,l=!0;const c=()=>{if(t&&!l&&(p(),i=v[n?"scrollLeft":"scrollTop"],w.current=i/a,r)){if(!s)if(i>=a){const e=1-E.offset;v[n?"scrollLeft":"scrollTop"]=1,w.current=E.offset=-e,s=!0}else if(i<=0){const e=1+E.offset;v[n?"scrollLeft":"scrollTop"]=o,w.current=E.offset=e,s=!0}s&&setTimeout((()=>s=!1),40)}};v.addEventListener("scroll",c,{passive:!0}),requestAnimationFrame((()=>l=!1));const u=e=>v.scrollLeft+=e.deltaY/2;return n&&v.addEventListener("wheel",u,{passive:!0}),()=>{v.removeEventListener("scroll",c),n&&v.removeEventListener("wheel",u)}}}),[v,h,f,r,E,p,n,t]);let b=0;return o.useFrame(((t,r)=>{E.offset=P.MathUtils.damp(b=E.offset,w.current,s,r),E.delta=P.MathUtils.damp(E.delta,Math.abs(b-E.offset),s,r),E.delta>e&&p()})),C.createElement(Z.Provider,{value:E},c)},exports.Segment=Hn,exports.SegmentObject=Gn,exports.Segments=Wn,exports.Select=function({box:e,multiple:t,children:r,onChange:n,border:a="1px solid #55aaff",backgroundColor:i="rgba(75, 160, 255, 0.1)",filter:s=(e=>e),...l}){const{setEvents:c,camera:d,raycaster:m,gl:f,controls:p,size:h,get:v}=o.useThree(),[g,x]=C.useState(!1),[y,w]=C.useReducer(((e,{object:t,shift:r})=>void 0===t?[]:Array.isArray(t)?t:r?e.includes(t)?e.filter((e=>e!==t)):[t,...e]:e[0]===t?[]:[t]),[]);C.useEffect((()=>{null==n||n(y)}),[y]);const E=C.useCallback((e=>{e.stopPropagation(),w({object:s([e.object])[0],shift:t&&e.shiftKey})}),[]),b=C.useCallback((e=>!g&&w({})),[g]),M=C.useRef(null);return C.useEffect((()=>{if(!e||!t)return;const r=new u.SelectionBox(d,M.current),n=document.createElement("div");n.style.pointerEvents="none",n.style.border=a,n.style.backgroundColor=i,n.style.position="fixed";const o=new P.Vector2,l=new P.Vector2,m=new P.Vector2,g=v().events.enabled,x=null==p?void 0:p.enabled;let y=!1;function E(e,t){const{offsetX:r,offsetY:n}=e,{width:o,height:a}=h;t.set(r/o*2-1,-n/a*2+1)}function b(e){e.shiftKey&&(!function(e){var t;p&&(p.enabled=!1),c({enabled:!1}),y=!0,null==(t=f.domElement.parentElement)||t.appendChild(n),n.style.left=`${e.clientX}px`,n.style.top=`${e.clientY}px`,n.style.width="0px",n.style.height="0px",o.x=e.clientX,o.y=e.clientY}(e),E(e,r.startPoint))}let S=[];function C(e){if(y){!function(e){m.x=Math.max(o.x,e.clientX),m.y=Math.max(o.y,e.clientY),l.x=Math.min(o.x,e.clientX),l.y=Math.min(o.y,e.clientY),n.style.left=`${l.x}px`,n.style.top=`${l.y}px`,n.style.width=m.x-l.x+"px",n.style.height=m.y-l.y+"px"}(e),E(e,r.endPoint);const t=r.select().sort((e=>e.uuid)).filter((e=>e.isMesh));_.default(t,S)||(S=t,w({object:s(t)}))}}function T(e){var t;y&&y&&(p&&(p.enabled=x),c({enabled:g}),y=!1,null==(t=n.parentElement)||t.removeChild(n))}return document.addEventListener("pointerdown",b,{passive:!0}),document.addEventListener("pointermove",C,{passive:!0,capture:!0}),document.addEventListener("pointerup",T,{passive:!0}),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("pointermove",C),document.removeEventListener("pointerup",T)}}),[h,m,d,p,f]),C.createElement("group",S.default({ref:M,onClick:E,onPointerOver:()=>x(!0),onPointerOut:()=>x(!1),onPointerMissed:b},l),C.createElement(re.Provider,{value:y},r))},exports.Shadow=Hr,exports.Sky=tn,exports.SoftShadows=function({frustum:e=3.75,size:t=.005,near:r=9.5,samples:n=10,rings:a=11}){const i=o.useThree((e=>e.gl)),s=o.useThree((e=>e.scene)),l=o.useThree((e=>e.camera));C.useEffect((()=>{const o=P.ShaderChunk.shadowmap_pars_fragment;let c=P.ShaderChunk.shadowmap_pars_fragment;return c=c.replace("#ifdef USE_SHADOWMAP","#ifdef USE_SHADOWMAP\n"+Xt({frustum:e,size:t,near:r,samples:n,rings:a})),c=c.replace("#if defined( SHADOWMAP_TYPE_PCF )","\nreturn PCSS(shadowMap, shadowCoord);\n#if defined( SHADOWMAP_TYPE_PCF )"),P.ShaderChunk.shadowmap_pars_fragment=c,Zt(i,s,l),()=>{P.ShaderChunk.shadowmap_pars_fragment=o,Zt(i,s,l)}}),[e,t,r,n,a])},exports.Sparkles=dn,exports.Sphere=rr,exports.SpotLight=Qr,exports.SpotLightShadow=function(e){return e.shader?C.createElement(Zr,e):C.createElement(Kr,e)},exports.Stage=function({children:e,center:t,adjustCamera:r=!0,intensity:n=.5,shadows:o="contact",environment:a="city",preset:i="rembrandt",...s}){var l,c,u,d,m,f,p,h;const v="string"==typeof i?Wr[i]:i,[{radius:g,height:x},y]=C.useState({radius:0,width:0,height:0,depth:0}),w=null!==(l=null==o?void 0:o.bias)&&void 0!==l?l:-1e-4,E=null!==(c=null==o?void 0:o.normalBias)&&void 0!==c?c:0,b=null!==(u=null==o?void 0:o.size)&&void 0!==u?u:1024,M=null!==(d=null==o?void 0:o.offset)&&void 0!==d?d:0,T="contact"===o||"contact"===(null==o?void 0:o.type),P="accumulative"===o||"accumulative"===(null==o?void 0:o.type),R={..."object"==typeof o?o:{}},D=a?"string"==typeof a?{preset:a}:a:null;return C.createElement(C.Fragment,null,C.createElement("ambientLight",{intensity:n/3}),C.createElement("spotLight",{penumbra:1,position:[v.main[0]*g,v.main[1]*g,v.main[2]*g],intensity:2*n,castShadow:!!o,"shadow-bias":w,"shadow-normalBias":E,"shadow-mapSize":b}),C.createElement("pointLight",{position:[v.fill[0]*g,v.fill[1]*g,v.fill[2]*g],intensity:n}),C.createElement(Mr,S.default({fit:!!r,clip:!!r,margin:Number(r),observe:!0},s),C.createElement(Gr,{radius:g,adjustCamera:r}),C.createElement(wr,S.default({},t,{position:[0,M/2,0],onCentered:e=>{const{width:r,height:n,depth:o,boundingSphere:a}=e;y({radius:a.radius,width:r,height:n,depth:o}),null!=t&&t.onCentered&&t.onCentered(e)}}),e)),C.createElement("group",{position:[0,-x/2-M/2,0]},T&&C.createElement(Ar,S.default({scale:4*g,far:g,blur:2},R)),P&&C.createElement(Ir,S.default({temporal:!0,frames:100,alphaTest:.9,toneMapped:!0,scale:4*g},R),C.createElement(Or,{amount:null!==(m=R.amount)&&void 0!==m?m:8,radius:null!==(f=R.radius)&&void 0!==f?f:g,ambient:null!==(p=R.ambient)&&void 0!==p?p:.5,intensity:null!==(h=R.intensity)&&void 0!==h?h:1,position:[v.main[0]*g,v.main[1]*g,v.main[2]*g],size:4*g,bias:-w,mapSize:b}))),a&&C.createElement(Lr,D))},exports.Stars=on,exports.Stats=function({showPanel:e=0,className:t,parent:r}){const n=function(e,t=[],r){const[n,o]=C.useState();return C.useLayoutEffect((()=>{const t=e();return o(t),Dt(r,t),()=>Dt(r,null)}),t),n}((()=>new F.default),[]);return C.useEffect((()=>{if(n){const a=r&&r.current||document.body;n.showPanel(e),null==a||a.appendChild(n.dom),t&&n.dom.classList.add(...t.split(" ").filter((e=>e)));const i=o.addEffect((()=>n.begin())),s=o.addAfterEffect((()=>n.end()));return()=>{null==a||a.removeChild(n.dom),i(),s()}}}),[r,n,t,e]),null},exports.Svg=Le,exports.Tetrahedron=sr,exports.Text=de,exports.Text3D=fe,exports.Torus=ar,exports.TorusKnot=ir,exports.TrackballControls=$e,exports.Trail=Te,exports.TransformControls=Xe,exports.Tube=or,exports.View=({track:e,index:t=1,frames:r=1/0,children:n})=>{const a=C.useRef(null),{size:i,scene:s}=o.useThree(),[l]=C.useState((()=>new P.Scene)),c=C.useCallback(((t,r)=>{if(e.current&&t.target===e.current){const{width:e,height:n,left:o,top:i}=a.current,s=t.clientX-o,l=t.clientY-i;r.pointer.set(s/e*2-1,-l/n*2+1),r.raycaster.setFromCamera(r.pointer,r.camera)}}),[a]),[u,d]=C.useReducer((()=>!0),!1);return C.useEffect((()=>{var t;a.current=null==(t=e.current)?void 0:t.getBoundingClientRect(),d()}),[]),C.createElement(C.Fragment,null,u&&o.createPortal(C.createElement(ro,{canvasSize:i,frames:r,scene:s,track:e,rect:a,index:t},n),l,{events:{compute:c,priority:t},size:{width:a.current.width,height:a.current.height}}))},exports.accumulativeContext=Br,exports.calcPosFromAngles=en,exports.calculateScaleFactor=Po,exports.isWebGL2Available=()=>{try{var e=document.createElement("canvas");return!(!window.WebGL2RenderingContext||!e.getContext("webgl2"))}catch(e){return!1}},exports.meshBounds=function(e,t){const r=this.geometry,n=this.material,o=this.matrixWorld;void 0!==n&&(null===r.boundingSphere&&r.computeBoundingSphere(),Yn.copy(r.boundingSphere),Yn.applyMatrix4(o),!1!==e.ray.intersectsSphere(Yn)&&(qn.copy(o).invert(),Xn.copy(e.ray).applyMatrix4(qn),null!==r.boundingBox&&null===Xn.intersectBox(r.boundingBox,Zn)||t.push({distance:Zn.distanceTo(e.ray.origin),point:Zn.clone(),object:this})))},exports.shaderMaterial=he,exports.softShadows=e=>{if(!Yt){console.warn("drei/softShadows() is deprecated, use <SoftShadows> instead"),Yt=!0;let t=P.ShaderChunk.shadowmap_pars_fragment;t=t.replace("#ifdef USE_SHADOWMAP","#ifdef USE_SHADOWMAP\n"+Xt({...e})),t=t.replace("#if defined( SHADOWMAP_TYPE_PCF )","\nreturn PCSS(shadowMap, shadowCoord);\n#if defined( SHADOWMAP_TYPE_PCF )"),P.ShaderChunk.shadowmap_pars_fragment=t}},exports.useAnimations=function(e,t){const r=C.useRef(),[a]=C.useState((()=>t?t instanceof n.Object3D?{current:t}:t:r)),[i]=C.useState((()=>new n.AnimationMixer(void 0))),s=C.useRef({}),[l]=C.useState((()=>{const t={};return e.forEach((e=>Object.defineProperty(t,e.name,{enumerable:!0,get(){if(a.current)return s.current[e.name]||(s.current[e.name]=i.clipAction(e,a.current))}}))),{ref:a,clips:e,actions:t,names:e.map((e=>e.name)),mixer:i}}));return o.useFrame(((e,t)=>i.update(t))),C.useEffect((()=>{const e=a.current;return()=>{s.current={},Object.values(l.actions).forEach((t=>{e&&i.uncacheAction(t,e)}))}}),[e]),C.useEffect((()=>()=>{i.stopAllAction()}),[i]),l},exports.useAspect=function(e,t,r=1){const n=o.useThree((e=>e.viewport)),a=t*(n.aspect>e/t?n.width/e:n.height/t);return[e*(n.aspect>e/t?n.width/e:n.height/t)*r,a*r,1]},exports.useBVH=function(e,t){C.useEffect((()=>{if(e.current){e.current.raycast=y.acceleratedRaycast;const r=e.current.geometry;return r.computeBoundsTree=y.computeBoundsTree,r.disposeBoundsTree=y.disposeBoundsTree,r.computeBoundsTree(t),()=>{r.boundsTree&&r.disposeBoundsTree()}}}),[e,t])},exports.useBounds=Sr,exports.useBoxProjectedEnv=function(e=new P.Vector3,t=new P.Vector3){const[r]=C.useState((()=>({position:new P.Vector3,size:new P.Vector3})));o.applyProps(r,{position:e,size:t});const n=C.useRef(null),a=C.useMemo((()=>({ref:n,onBeforeCompile:e=>function(e,t,r){e.defines.BOX_PROJECTED_ENV_MAP=!0,e.uniforms.envMapPosition={value:t},e.uniforms.envMapSize={value:r},e.vertexShader=`\n varying vec3 vWorldPosition;\n ${e.vertexShader.replace("#include <worldpos_vertex>","\n#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n #ifdef BOX_PROJECTED_ENV_MAP\n vWorldPosition = worldPosition.xyz;\n #endif\n#endif\n")}`,e.fragmentShader=`\n \n#ifdef BOX_PROJECTED_ENV_MAP\n uniform vec3 envMapSize;\n uniform vec3 envMapPosition;\n varying vec3 vWorldPosition;\n \n vec3 parallaxCorrectNormal( vec3 v, vec3 cubeSize, vec3 cubePos ) {\n vec3 nDir = normalize( v );\n vec3 rbmax = ( .5 * cubeSize + cubePos - vWorldPosition ) / nDir;\n vec3 rbmin = ( -.5 * cubeSize + cubePos - vWorldPosition ) / nDir;\n vec3 rbminmax;\n rbminmax.x = ( nDir.x > 0. ) ? rbmax.x : rbmin.x;\n rbminmax.y = ( nDir.y > 0. ) ? rbmax.y : rbmin.y;\n rbminmax.z = ( nDir.z > 0. ) ? rbmax.z : rbmin.z;\n float correction = min( min( rbminmax.x, rbminmax.y ), rbminmax.z );\n vec3 boxIntersection = vWorldPosition + nDir * correction; \n return boxIntersection - cubePos;\n }\n#endif\n\n ${e.fragmentShader.replace("#include <envmap_physical_pars_fragment>",P.ShaderChunk.envmap_physical_pars_fragment).replace("vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );","vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n \n#ifdef BOX_PROJECTED_ENV_MAP\n worldNormal = parallaxCorrectNormal( worldNormal, envMapSize, envMapPosition );\n#endif\n\n ").replace("reflectVec = inverseTransformDirection( reflectVec, viewMatrix );","reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n \n#ifdef BOX_PROJECTED_ENV_MAP\n reflectVec = parallaxCorrectNormal( reflectVec, envMapSize, envMapPosition );\n#endif\n\n ")}`}(e,r.position,r.size),customProgramCacheKey:()=>JSON.stringify(r.position.toArray())+JSON.stringify(r.size.toArray())})),[...r.position.toArray(),...r.size.toArray()]);return C.useLayoutEffect((()=>{n.current.needsUpdate=!0}),[r]),a},exports.useCamera=function(e,t){const r=o.useThree((e=>e.pointer)),[a]=C.useState((()=>{const a=new n.Raycaster;return t&&o.applyProps(a,t,{}),function(t,o){a.setFromCamera(r,e instanceof n.Camera?e:e.current);const i=this.constructor.prototype.raycast.bind(this);i&&i(a,o)}}));return a},exports.useContextBridge=function(...e){const t=C.useRef([]);return t.current=e.map((e=>C.useContext(e))),C.useMemo((()=>({children:r})=>e.reduceRight(((e,r,n)=>C.createElement(r.Provider,{value:t.current[n],children:e})),r)),[])},exports.useCubeTexture=Ct,exports.useCursor=function(e,t="pointer",r="auto"){C.useEffect((()=>{if(e)return document.body.style.cursor=t,()=>{document.body.style.cursor=r}}),[e])},exports.useDepthBuffer=function({size:e=256,frames:t=1/0}={}){const r=o.useThree((e=>e.viewport.dpr)),{width:a,height:i}=o.useThree((e=>e.size)),s=e||a*r,l=e||i*r,c=C.useMemo((()=>{const e=new n.DepthTexture(s,l);return e.format=n.DepthFormat,e.type=n.UnsignedShortType,{depthTexture:e}}),[s,l]);let u=0;const d=Ie(s,l,c);return o.useFrame((e=>{(t===1/0||u<t)&&(e.gl.setRenderTarget(d),e.gl.render(e.scene,e.camera),e.gl.setRenderTarget(null),u++)})),d.depthTexture},exports.useDetectGPU=e=>f.suspend((()=>x.getGPUTier(e)),["useDetectGPU"]),exports.useEnvironment=_r,exports.useFBO=Ie,exports.useFBX=Tt,exports.useGLTF=Ue,exports.useGizmoContext=et,exports.useHelper=function(e,t,...r){const n=C.useRef(),a=o.useThree((e=>e.scene));return C.useEffect((()=>{let o;if(e&&null!=e&&e.current&&t&&(n.current=o=new t(e.current,...r)),o)return a.add(o),()=>{n.current=void 0,a.remove(o),null==o.dispose||o.dispose()}}),[a,t,e,...r]),o.useFrame((()=>{var e;null==(e=n.current)||null==e.update||e.update()})),n},exports.useIntersect=function(e){const t=C.useRef(null),r=C.useRef(!1),n=C.useRef(!1),a=C.useRef(e);return C.useLayoutEffect((()=>{a.current=e}),[e]),C.useEffect((()=>{const e=t.current;if(e){const t=o.addEffect((()=>(r.current=!1,!0))),i=e.onBeforeRender;e.onBeforeRender=()=>r.current=!0;const s=o.addAfterEffect((()=>(r.current!==n.current&&(null==a.current||a.current(n.current=r.current)),!0)));return()=>{e.onBeforeRender=i,t(),s()}}}),[]),t},exports.useKTX2=Rt,exports.useKeyboardControls=function(e){const[t,r,n]=C.useContext(te);return e?n(e):[t,r]},exports.useMask=function(e,t=!1){return{stencilWrite:!0,stencilRef:e,stencilFunc:t?P.NotEqualStencilFunc:P.EqualStencilFunc,stencilFail:P.KeepStencilOp,stencilZFail:P.KeepStencilOp,stencilZPass:P.KeepStencilOp}},exports.useMatcapTexture=function(e=0,t=1024,r){const n=f.suspend((()=>fetch("https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master/matcaps.json").then((e=>e.json()))),["matcapList"]),o=n[0],a=C.useMemo((()=>Object.keys(n).length),[]),i=`${C.useMemo((()=>"string"==typeof e?e:"number"==typeof e?n[e]:null),[e])||o}${function(e){switch(e){case 64:return"-64px";case 128:return"-128px";case 256:return"-256px";case 512:return"-512px";default:return""}}(t)}.png`,s=`https://rawcdn.githack.com/emmelleppi/matcaps/9b36ccaaf0a24881a39062d05566c9e92be4aa0d/${t}/${i}`;return[ge(s,r),s,a]},exports.useNormalTexture=function(e=0,t={},r){const{repeat:o=[1,1],anisotropy:a=1,offset:i=[0,0]}=t,s=f.suspend((()=>fetch("https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master/normals/normals.json").then((e=>e.json()))),["normalsList"]),l=C.useMemo((()=>Object.keys(s).length),[]),c=s[0],u=`https://rawcdn.githack.com/pmndrs/drei-assets/7a3104997e1576f83472829815b00880d88b32fb/normals/${s[e]||c}`,d=ge(u,r);return C.useLayoutEffect((()=>{d&&(d.wrapS=d.wrapT=n.RepeatWrapping,d.repeat=new n.Vector2(o[0],o[1]),d.offset=new n.Vector2(i[0],i[1]),d.anisotropy=a)}),[d,a,o,i]),[d,u,l]},exports.usePerformanceMonitor=function({onIncline:e,onDecline:r,onChange:n,onFallback:o}){const a=t.useContext(Kn),i=t.useRef({onIncline:e,onDecline:r,onChange:n,onFallback:o});t.useLayoutEffect((()=>{i.current.onIncline=e,i.current.onDecline=r,i.current.onChange=n,i.current.onFallback=o}),[e,r,n,o]),t.useLayoutEffect((()=>a.subscribe(i)),[a])},exports.useProgress=q,exports.useScroll=K,exports.useSelect=function(){return C.useContext(re)},exports.useSurfaceSampler=Pe,exports.useTexture=ge,exports.useTrail=Ce,exports.useTrailTexture=function(e={}){const{size:r,maxAge:n,radius:a,intensity:i,interpolate:s,smoothing:l,minForce:c,blend:u,ease:d}=e,m=t.useMemo((()=>new Ft(e)),[r,n,a,i,s,l,c,u,d]);o.useFrame(((e,t)=>{m.update(t)}));const f=t.useCallback((e=>m.addTouch(e.uv)),[m]);return[m.texture,f]},exports.useVideoTexture=function(e,r){const{unsuspend:n,start:a,crossOrigin:i,muted:s,loop:l,...c}={unsuspend:"loadedmetadata",crossOrigin:"Anonymous",muted:!0,loop:!0,start:!0,playsInline:!0,...r},u=o.useThree((e=>e.gl)),d=f.suspend((()=>new Promise(((t,r)=>{const o=Object.assign(document.createElement("video"),{src:e,crossOrigin:i,loop:l,muted:s,...c}),a=new P.VideoTexture(o);a.encoding=u.outputEncoding,o.addEventListener(n,(()=>t(a)))}))),[e]);return t.useEffect((()=>{a&&d.image.play()}),[d,a]),d};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("react-dom/client"),n=require("three"),o=require("@react-three/fiber"),a=require("zustand"),i=require("react-merge-refs"),s=require("@react-spring/three"),l=require("@use-gesture/react"),c=require("zustand/middleware"),u=require("three-stdlib"),d=require("zustand/shallow"),m=require("troika-three-text"),f=require("suspend-react"),p=require("meshline"),h=require("lodash.pick"),v=require("lodash.omit"),g=require("stats.js"),x=require("detect-gpu"),y=require("three-mesh-bvh"),w=require("react-composer"),E=require("lodash.clamp");function b(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function M(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var S=b(e),C=M(t),T=M(r),P=M(n),R=b(a),D=b(i),_=b(d),z=b(h),k=b(v),F=b(g),L=b(w),A=b(E);const B=new n.Vector3,U=new n.Vector3,V=new n.Vector3;function I(e,t,r){const n=B.setFromMatrixPosition(e.matrixWorld);n.project(t);const o=r.width/2,a=r.height/2;return[n.x*o+o,-n.y*a+a]}const O=e=>Math.abs(e)<1e-10?0:e;function j(e,t,r=""){let n="matrix3d(";for(let r=0;16!==r;r++)n+=O(t[r]*e.elements[r])+(15!==r?",":")");return r+n}const W=(G=[1,-1,1,1,1,-1,1,1,1,-1,1,1,1,-1,1,1],e=>j(e,G));var G;const N=(e,t)=>{return j(e,[1/(r=t),1/r,1/r,1,-1/r,-1/r,-1/r,-1,1/r,1/r,1/r,1,1,1,1,1],"translate(-50%,-50%)");var r};const H=C.forwardRef((({children:e,eps:t=.001,style:r,className:a,prepend:i,center:s,fullscreen:l,portal:c,distanceFactor:u,sprite:d=!1,transform:m=!1,occlude:f,onOcclude:p,castShadow:h,receiveShadow:v,material:g,geometry:x,zIndexRange:y=[16777271,0],calculatePosition:w=I,as:E="div",wrapperClass:b,pointerEvents:M="auto",...P},R)=>{const{gl:D,camera:_,scene:z,size:k,raycaster:F,events:L,viewport:A}=o.useThree(),[j]=C.useState((()=>document.createElement(E))),G=C.useRef(),H=C.useRef(null),$=C.useRef(0),q=C.useRef([0,0]),X=C.useRef(null),Y=C.useRef(null),Z=(null==c?void 0:c.current)||L.connected||D.domElement.parentNode,K=C.useRef(null),Q=C.useRef(!1),J=C.useMemo((()=>f&&"blending"!==f||Array.isArray(f)&&f.length&&function(e){return e&&"object"==typeof e&&"current"in e}(f[0])),[f]);C.useLayoutEffect((()=>{const e=D.domElement;f?(e.style.zIndex=`${Math.floor(y[0]/2)}`,e.style.position="absolute",e.style.pointerEvents="none"):(e.style.zIndex=null,e.style.position=null,e.style.pointerEvents=null)}),[f,J]),C.useLayoutEffect((()=>{if(H.current){const e=G.current=T.createRoot(j);if(z.updateMatrixWorld(),m)j.style.cssText="position:absolute;top:0;left:0;pointer-events:none;overflow:hidden;";else{const e=w(H.current,_,k);j.style.cssText=`position:absolute;top:0;left:0;transform:translate3d(${e[0]}px,${e[1]}px,0);transform-origin:0 0;`}return Z&&(i?Z.prepend(j):Z.appendChild(j)),()=>{Z&&Z.removeChild(j),e.unmount()}}}),[Z,m]),C.useLayoutEffect((()=>{b&&(j.className=b)}),[b]);const ee=C.useMemo((()=>m?{position:"absolute",top:0,left:0,width:k.width,height:k.height,transformStyle:"preserve-3d",pointerEvents:"none"}:{position:"absolute",transform:s?"translate3d(-50%,-50%,0)":"none",...l&&{top:-k.height/2,left:-k.width/2,width:k.width,height:k.height},...r}),[r,s,l,k,m]),te=C.useMemo((()=>({position:"absolute",pointerEvents:M})),[M]);C.useLayoutEffect((()=>{var t,n;(Q.current=!1,m)?null==(t=G.current)||t.render(C.createElement("div",{ref:X,style:ee},C.createElement("div",{ref:Y,style:te},C.createElement("div",{ref:R,className:a,style:r,children:e})))):null==(n=G.current)||n.render(C.createElement("div",{ref:R,style:ee,className:a,children:e}))}));const re=C.useRef(!0);o.useFrame((e=>{if(H.current){_.updateMatrixWorld(),H.current.updateWorldMatrix(!0,!1);const e=m?q.current:w(H.current,_,k);if(m||Math.abs($.current-_.zoom)>t||Math.abs(q.current[0]-e[0])>t||Math.abs(q.current[1]-e[1])>t){const t=function(e,t){const r=B.setFromMatrixPosition(e.matrixWorld),n=U.setFromMatrixPosition(t.matrixWorld),o=r.sub(n),a=t.getWorldDirection(V);return o.angleTo(a)>Math.PI/2}(H.current,_);let r=!1;J&&("blending"!==f?r=[z]:Array.isArray(f)&&(r=f.map((e=>e.current))));const o=re.current;if(r){const e=function(e,t,r,n){const o=B.setFromMatrixPosition(e.matrixWorld),a=o.clone();a.project(t),r.setFromCamera(a,t);const i=r.intersectObjects(n,!0);if(i.length){const e=i[0].distance;return o.distanceTo(r.ray.origin)<e}return!0}(H.current,_,F,r);re.current=e&&!t}else re.current=!t;o!==re.current&&(p?p(!re.current):j.style.display=re.current?"block":"none");const a=Math.floor(y[0]/2),i=f?J?[y[0],a]:[a-1,0]:y;if(j.style.zIndex=`${function(e,t,r){if(t instanceof n.PerspectiveCamera||t instanceof n.OrthographicCamera){const n=B.setFromMatrixPosition(e.matrixWorld),o=U.setFromMatrixPosition(t.matrixWorld),a=n.distanceTo(o),i=(r[1]-r[0])/(t.far-t.near),s=r[1]-i*t.far;return Math.round(i*a+s)}}(H.current,_,i)}`,m){const[e,t]=[k.width/2,k.height/2],r=_.projectionMatrix.elements[5]*t,{isOrthographicCamera:n,top:o,left:a,bottom:i,right:s}=_,l=W(_.matrixWorldInverse),c=n?`scale(${r})translate(${O(-(s+a)/2)}px,${O((o+i)/2)}px)`:`translateZ(${r}px)`;let m=H.current.matrixWorld;d&&(m=_.matrixWorldInverse.clone().transpose().copyPosition(m).scale(H.current.scale),m.elements[3]=m.elements[7]=m.elements[11]=0,m.elements[15]=1),j.style.width=k.width+"px",j.style.height=k.height+"px",j.style.perspective=n?"":`${r}px`,X.current&&Y.current&&(X.current.style.transform=`${c}${l}translate(${e}px,${t}px)`,Y.current.style.transform=N(m,1/((u||10)/400)))}else{const t=void 0===u?1:function(e,t){if(t instanceof n.OrthographicCamera)return t.zoom;if(t instanceof n.PerspectiveCamera){const r=B.setFromMatrixPosition(e.matrixWorld),n=U.setFromMatrixPosition(t.matrixWorld),o=t.fov*Math.PI/180,a=r.distanceTo(n);return 1/(2*Math.tan(o/2)*a)}return 1}(H.current,_)*u;j.style.transform=`translate3d(${e[0]}px,${e[1]}px,0) scale(${t})`}q.current=e,$.current=_.zoom}}if(!J&&K.current&&!Q.current)if(m){if(X.current){const e=X.current.children[0];if(null!=e&&e.clientWidth&&null!=e&&e.clientHeight){const{isOrthographicCamera:t}=_;if(t||x)P.scale&&(Array.isArray(P.scale)?P.scale instanceof n.Vector3?K.current.scale.copy(P.scale.clone().divideScalar(1)):K.current.scale.set(1/P.scale[0],1/P.scale[1],1/P.scale[2]):K.current.scale.setScalar(1/P.scale));else{const t=(u||10)/400,r=e.clientWidth*t,n=e.clientHeight*t;K.current.scale.set(r,n,1)}Q.current=!0}}}else{const t=j.children[0];if(null!=t&&t.clientWidth&&null!=t&&t.clientHeight){const e=1/A.factor,r=t.clientWidth*e,n=t.clientHeight*e;K.current.scale.set(r,n,1),Q.current=!0}K.current.lookAt(e.camera.position)}}));const ne=C.useMemo((()=>({vertexShader:m?void 0:'\n /*\n This shader is from the THREE\'s SpriteMaterial.\n We need to turn the backing plane into a Sprite\n (make it always face the camera) if "transfrom" \n is false. \n */\n #include <common>\n\n void main() {\n vec2 center = vec2(0., 1.);\n float rotation = 0.0;\n \n // This is somewhat arbitrary, but it seems to work well\n // Need to figure out how to derive this dynamically if it even matters\n float size = 0.03;\n\n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\n bool isPerspective = isPerspectiveMatrix( projectionMatrix );\n if ( isPerspective ) scale *= - mvPosition.z;\n\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale * size;\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n mvPosition.xy += rotatedPosition;\n\n gl_Position = projectionMatrix * mvPosition;\n }\n ',fragmentShader:"\n void main() {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n }\n "})),[m]);return C.createElement("group",S.default({},P,{ref:H}),f&&!J&&C.createElement("mesh",{castShadow:h,receiveShadow:v,ref:K},x||C.createElement("planeGeometry",null),g||C.createElement("shaderMaterial",{side:n.DoubleSide,vertexShader:ne.vertexShader,fragmentShader:ne.fragmentShader})))}));let $=0;const q=R.default((e=>(n.DefaultLoadingManager.onStart=(t,r,n)=>{e({active:!0,item:t,loaded:r,total:n,progress:(r-$)/(n-$)*100})},n.DefaultLoadingManager.onLoad=()=>{e({active:!1})},n.DefaultLoadingManager.onError=t=>e((e=>({errors:[...e.errors,t]}))),n.DefaultLoadingManager.onProgress=(t,r,n)=>{r===n&&($=n),e({active:!0,item:t,loaded:r,total:n,progress:(r-$)/(n-$)*100||100})},{errors:[],active:!1,progress:0,item:"",loaded:0,total:0}))),X=e=>`Loading ${e.toFixed(2)}%`;const Y={container:{position:"absolute",top:0,left:0,width:"100%",height:"100%",background:"#171717",display:"flex",alignItems:"center",justifyContent:"center",transition:"opacity 300ms ease",zIndex:1e3},inner:{width:100,height:3,background:"#272727",textAlign:"center"},bar:{height:3,width:"100%",background:"white",transition:"transform 200ms",transformOrigin:"left center"},data:{display:"inline-block",position:"relative",fontVariantNumeric:"tabular-nums",marginTop:"0.8em",color:"#f0f0f0",fontSize:"0.6em",fontFamily:'-apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "Helvetica Neue", Helvetica, Arial, Roboto, Ubuntu, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',whiteSpace:"nowrap"}},Z=C.createContext(null);function K(){return C.useContext(Z)}const Q=C.forwardRef((({children:e},t)=>{const r=C.useRef(null),n=K(),{width:a,height:i}=o.useThree((e=>e.viewport));return o.useFrame((()=>{r.current.position.x=n.horizontal?-a*(n.pages-1)*n.offset:0,r.current.position.y=n.horizontal?0:i*(n.pages-1)*n.offset})),C.createElement("group",{ref:D.default([t,r])},e)})),J=C.forwardRef((({children:e,style:t,...r},n)=>{const a=K(),i=C.useRef(null),{width:s,height:l}=o.useThree((e=>e.size)),c=C.useContext(o.context),u=C.useMemo((()=>T.createRoot(a.fixed)),[a.fixed]);return o.useFrame((()=>{a.delta>a.eps&&(i.current.style.transform=`translate3d(${a.horizontal?-s*(a.pages-1)*a.offset:0}px,${a.horizontal?0:l*(a.pages-1)*-a.offset}px,0)`)})),u.render(C.createElement("div",S.default({ref:D.default([n,i]),style:{...t,position:"absolute",top:0,left:0,willChange:"transform"}},r),C.createElement(Z.Provider,{value:a},C.createElement(o.context.Provider,{value:c},e)))),null})),ee=C.forwardRef((({html:e,...t},r)=>{const n=e?J:Q;return C.createElement(n,S.default({ref:r},t))}));const te=C.createContext(null);const re=C.createContext([]);const ne=C.forwardRef((function({follow:e=!0,lockX:t=!1,lockY:r=!1,lockZ:n=!1,...a},i){const s=C.useRef();return o.useFrame((({camera:o})=>{if(!e||!s.current)return;const a=s.current.rotation.clone();s.current.quaternion.copy(o.quaternion),t&&(s.current.rotation.x=a.x),r&&(s.current.rotation.y=a.y),n&&(s.current.rotation.z=a.z)})),C.createElement("group",S.default({ref:D.default([s,i])},a))})),oe=C.forwardRef((({children:e,depth:t=-1,...r},n)=>{const a=C.useRef(null);return o.useFrame((({camera:e})=>{a.current.quaternion.copy(e.quaternion),a.current.position.copy(e.position)})),C.createElement("group",S.default({ref:D.default([n,a])},r),C.createElement("group",{"position-z":-t},e))})),ae=C.forwardRef((function({points:e,color:t="black",vertexColors:r,linewidth:a,lineWidth:i,dashed:s,...l},c){const d=o.useThree((e=>e.size)),[m]=C.useState((()=>new u.Line2)),[f]=C.useState((()=>new u.LineMaterial)),p=C.useMemo((()=>{const t=new u.LineGeometry,o=e.map((e=>{const t=Array.isArray(e);return e instanceof n.Vector3?[e.x,e.y,e.z]:e instanceof n.Vector2?[e.x,e.y,0]:t&&3===e.length?[e[0],e[1],e[2]]:t&&2===e.length?[e[0],e[1],0]:e}));if(t.setPositions(o.flat()),r){const e=r.map((e=>e instanceof n.Color?e.toArray():e));t.setColors(e.flat())}return t}),[e,r]);return C.useLayoutEffect((()=>{m.computeLineDistances()}),[e,m]),C.useLayoutEffect((()=>{s?f.defines.USE_DASH="":delete f.defines.USE_DASH,f.needsUpdate=!0}),[s,f]),C.useEffect((()=>()=>p.dispose()),[p]),C.createElement("primitive",S.default({object:m,ref:c},l),C.createElement("primitive",{object:p,attach:"geometry"}),C.createElement("primitive",S.default({object:f,attach:"material",color:t,vertexColors:Boolean(r),resolution:[d.width,d.height],linewidth:null!=a?a:i,dashed:s},l)))})),ie=new n.Vector3,se=C.forwardRef((function({start:e=[0,0,0],end:t=[0,0,0],mid:r,segments:o=20,...a},i){const s=C.useRef(null),[l]=C.useState((()=>new n.QuadraticBezierCurve3(void 0,void 0,void 0))),c=C.useCallback(((e,t,r,o=20)=>(e instanceof n.Vector3?l.v0.copy(e):l.v0.set(...e),t instanceof n.Vector3?l.v2.copy(t):l.v2.set(...t),r instanceof n.Vector3?l.v1.copy(r):l.v1.copy(l.v0.clone().add(l.v2.clone().sub(l.v0)).add(ie.set(0,l.v0.y-l.v2.y,0))),l.getPoints(o))),[]);C.useLayoutEffect((()=>{s.current.setPoints=(e,t,r)=>{const n=c(e,t,r);s.current.geometry&&s.current.geometry.setPositions(n.map((e=>e.toArray())).flat())}}),[]);const u=C.useMemo((()=>c(e,t,r,o)),[e,t,r,o]);return C.createElement(ae,S.default({ref:D.default([s,i]),points:u},a))})),le=C.forwardRef((function({start:e,end:t,midA:r,midB:o,segments:a=20,...i},s){const l=C.useMemo((()=>{const i=e instanceof n.Vector3?e:new n.Vector3(...e),s=t instanceof n.Vector3?t:new n.Vector3(...t),l=r instanceof n.Vector3?r:new n.Vector3(...r),c=o instanceof n.Vector3?o:new n.Vector3(...o);return new n.CubicBezierCurve3(i,l,c,s).getPoints(a)}),[e,t,r,o,a]);return C.createElement(ae,S.default({ref:s,points:l},i))})),ce=C.forwardRef((function({points:e,closed:t=!1,curveType:r="centripetal",tension:o=.5,segments:a=20,vertexColors:i,...s},l){const c=C.useMemo((()=>{const a=e.map((e=>e instanceof n.Vector3?e:new n.Vector3(...e)));return new n.CatmullRomCurve3(a,t,r,o)}),[e,t,r,o]),u=C.useMemo((()=>c.getPoints(a)),[c,a]),d=C.useMemo((()=>{if(!i||i.length<2)return;if(i.length===a+1)return i;const e=i.map((e=>e instanceof n.Color?e:new n.Color(...e)));t&&e.push(e[0].clone());const r=[e[0]],o=a/(e.length-1);for(let t=1;t<a;t++){const n=t%o/o,a=Math.floor(t/o);r.push(e[a].clone().lerp(e[a+1],n))}return r.push(e[e.length-1]),r}),[i,a]);return C.createElement(ae,S.default({ref:l,points:u,vertexColors:d},s))})),ue=C.forwardRef((({url:e,distance:t=1,loop:r=!0,autoplay:a,...i},s)=>{const l=C.useRef(),c=o.useThree((({camera:e})=>e)),[u]=C.useState((()=>new n.AudioListener)),d=o.useLoader(n.AudioLoader,e);return C.useEffect((()=>{const e=l.current;e&&(e.setBuffer(d),e.setRefDistance(t),e.setLoop(r),a&&!e.isPlaying&&e.play())}),[d,c,t,r]),C.useEffect((()=>{const e=l.current;return c.add(u),()=>{c.remove(u),e&&(e.isPlaying&&e.stop(),e.source&&e.source._connected&&e.disconnect())}}),[]),C.createElement("positionalAudio",S.default({ref:D.default([l,s]),args:[u]},i))})),de=C.forwardRef((({anchorX:e="center",anchorY:t="middle",font:r,fontSize:n=1,children:a,characters:i,onSync:s,...l},c)=>{const u=o.useThree((({invalidate:e})=>e)),[d]=C.useState((()=>new m.Text)),[p,h]=C.useMemo((()=>{const e=[];let t="";return C.Children.forEach(a,(r=>{"string"==typeof r||"number"==typeof r?t+=r:e.push(r)})),[e,t]}),[a]);return f.suspend((()=>new Promise((e=>m.preloadFont({font:r,characters:i},e)))),["troika-text",r,i]),C.useLayoutEffect((()=>{d.sync((()=>{u(),s&&s(d)}))})),C.useEffect((()=>()=>d.dispose()),[d]),C.createElement("primitive",S.default({object:d,ref:c,font:r,text:h,anchorX:e,anchorY:t,fontSize:n},l),p)})),me=["string","number"],fe=C.forwardRef((({font:e,letterSpacing:r=0,lineHeight:n=1,size:a=1,height:i=.2,bevelThickness:s=.1,bevelSize:l=.01,bevelEnabled:c=!1,bevelOffset:d=0,bevelSegments:m=4,curveSegments:p=8,children:h,...v},g)=>{C.useMemo((()=>o.extend({RenamedTextGeometry:u.TextGeometry})),[]);const x=f.suspend((async()=>{let t="string"==typeof e?await(await fetch(e)).json():e;return(new u.FontLoader).parse(t)}),[e]),y=t.useMemo((()=>({font:x,size:a,height:i,bevelThickness:s,bevelSize:l,bevelEnabled:c,bevelSegments:m,bevelOffset:d,curveSegments:p,letterSpacing:r,lineHeight:n})),[x,a,i,s,l,c,m,d,p,r,n]),[w,...E]=t.useMemo((()=>(e=>{let t="";const r=[];return C.Children.forEach(e,(e=>{me.includes(typeof e)?t+=e+"":r.push(e)})),[t,...r]})(h)),[h]),b=C.useMemo((()=>[w,y]),[w,y]);return C.createElement("mesh",S.default({},v,{ref:g}),C.createElement("renamedTextGeometry",{args:b}),E)})),pe=C.forwardRef((({children:e,multisamping:t=8,renderIndex:r=1,disableRender:a,disableGamma:i,disableRenderPass:s,depthBuffer:l=!0,stencilBuffer:c=!1,anisotropy:d=1,encoding:m,type:f,...p},h)=>{C.useMemo((()=>o.extend({EffectComposer:u.EffectComposer,RenderPass:u.RenderPass,ShaderPass:u.ShaderPass})),[]);const v=C.useRef(),{scene:g,camera:x,gl:y,size:w,viewport:E}=o.useThree(),[b]=C.useState((()=>{const e=new n.WebGLRenderTarget(w.width,w.height,{type:f||n.HalfFloatType,format:n.RGBAFormat,encoding:m||y.outputEncoding,depthBuffer:l,stencilBuffer:c,anisotropy:d});return e.samples=t,e}));C.useEffect((()=>{var e,t;null==(e=v.current)||e.setSize(w.width,w.height),null==(t=v.current)||t.setPixelRatio(E.dpr)}),[y,w,E.dpr]),o.useFrame((()=>{var e;a||null==(e=v.current)||e.render()}),r);const M=[];return s||M.push(C.createElement("renderPass",{key:"renderpass",attach:`passes-${M.length}`,args:[g,x]})),i||M.push(C.createElement("shaderPass",{attach:`passes-${M.length}`,key:"gammapass",args:[u.GammaCorrectionShader]})),C.Children.forEach(e,(e=>{e&&M.push(C.cloneElement(e,{key:M.length,attach:`passes-${M.length}`}))})),C.createElement("effectComposer",S.default({ref:D.default([h,v]),args:[y,b]},p),M)}));function he(e,t,r,n){const o=class extends P.ShaderMaterial{constructor(o={}){const a=Object.entries(e);super({uniforms:a.reduce(((e,[t,r])=>({...e,...P.UniformsUtils.clone({[t]:{value:r}})})),{}),vertexShader:t,fragmentShader:r,...o}),this.key="",a.forEach((([e])=>Object.defineProperty(this,e,{get:()=>this.uniforms[e].value,set:t=>this.uniforms[e].value=t}))),n&&n(this)}};return o.key=P.MathUtils.generateUUID(),o}const ve=e=>e===Object(e)&&!Array.isArray(e)&&"function"!=typeof e;function ge(e,r){const a=o.useThree((e=>e.gl)),i=o.useLoader(n.TextureLoader,ve(e)?Object.values(e):e);if(t.useLayoutEffect((()=>{null==r||r(i)}),[r]),t.useEffect((()=>{(Array.isArray(i)?i:[i]).forEach(a.initTexture)}),[a,i]),ve(e)){const t=Object.keys(e),r={};return t.forEach((e=>Object.assign(r,{[e]:i[t.indexOf(e)]}))),r}return i}ge.preload=e=>o.useLoader.preload(n.TextureLoader,e),ge.clear=e=>o.useLoader.clear(n.TextureLoader,e);const xe=he({color:new P.Color("white"),scale:[1,1],imageBounds:[1,1],map:null,zoom:1,grayscale:0,opacity:1},"\n varying vec2 vUv;\n void main() {\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);\n vUv = uv;\n }\n","\n // mostly from https://gist.github.com/statico/df64c5d167362ecf7b34fca0b1459a44\n varying vec2 vUv;\n uniform vec2 scale;\n uniform vec2 imageBounds;\n uniform vec3 color;\n uniform sampler2D map;\n uniform float zoom;\n uniform float grayscale;\n uniform float opacity;\n const vec3 luma = vec3(.299, 0.587, 0.114);\n vec4 toGrayscale(vec4 color, float intensity) {\n return vec4(mix(color.rgb, vec3(dot(color.rgb, luma)), intensity), color.a);\n }\n vec2 aspect(vec2 size) {\n return size / min(size.x, size.y);\n }\n void main() {\n vec2 s = aspect(scale);\n vec2 i = aspect(imageBounds);\n float rs = s.x / s.y;\n float ri = i.x / i.y;\n vec2 new = rs < ri ? vec2(i.x * s.y / i.y, s.y) : vec2(s.x, i.y * s.x / i.x);\n vec2 offset = (rs < ri ? vec2((new.x - s.x) / 2.0, 0.0) : vec2(0.0, (new.y - s.y) / 2.0)) / new;\n vec2 uv = vUv * s / new + offset;\n vec2 zUv = (uv - vec2(0.5, 0.5)) / zoom + vec2(0.5, 0.5);\n gl_FragColor = toGrayscale(texture2D(map, zUv) * vec4(color, opacity), grayscale);\n \n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }\n"),ye=C.forwardRef((({children:e,color:t,segments:r=1,scale:n=1,zoom:a=1,grayscale:i=0,opacity:s=1,texture:l,toneMapped:c,transparent:u,...d},m)=>{o.extend({ImageMaterial:xe});const f=o.useThree((e=>e.gl)),p=Array.isArray(n)?[n[0],n[1]]:[n,n],h=[l.image.width,l.image.height];return C.createElement("mesh",S.default({ref:m,scale:Array.isArray(n)?[...n,1]:n},d),C.createElement("planeGeometry",{args:[1,1,r,r]}),C.createElement("imageMaterial",{color:t,map:l,"map-encoding":f.outputEncoding,zoom:a,grayscale:i,opacity:s,scale:p,imageBounds:h,toneMapped:c,transparent:u}),e)})),we=C.forwardRef((({url:e,...t},r)=>{const n=ge(e);return C.createElement(ye,S.default({},t,{texture:n,ref:r}))})),Ee=C.forwardRef((({url:e,...t},r)=>C.createElement(ye,S.default({},t,{ref:r})))),be=C.forwardRef(((e,t)=>{if(e.url)return C.createElement(we,S.default({},e,{ref:t}));if(e.texture)return C.createElement(Ee,S.default({},e,{ref:t}));throw new Error("<Image /> requires a url or texture")}));const Me={width:.2,length:1,decay:1,local:!1,stride:0,interval:1},Se=(e,t=1)=>(e.set(e.subarray(t)),e.fill(-1/0,-t),e);function Ce(e,t){const{length:r,local:a,decay:i,interval:s,stride:l}={...Me,...t},c=C.useRef(),[u]=C.useState((()=>new n.Vector3));C.useLayoutEffect((()=>{e&&(c.current=Float32Array.from({length:10*r*3},((t,r)=>e.position.getComponent(r%3))))}),[r,e]);const d=C.useRef(new n.Vector3),m=C.useRef(0);return o.useFrame((()=>{if(e&&c.current){if(0===m.current){let t;a?t=e.position:(e.getWorldPosition(u),t=u);const r=1*i;for(let e=0;e<r;e++)t.distanceTo(d.current)<l||(Se(c.current,3),c.current.set(t.toArray(),c.current.length-3));d.current.copy(t)}m.current++,m.current=m.current%s}})),c}const Te=C.forwardRef(((e,t)=>{const{children:r}=e,{width:a,length:i,decay:s,local:l,stride:c,interval:u}={...Me,...e},{color:d="hotpink",attenuation:m,target:f}=e,h=o.useThree((e=>e.size)),v=o.useThree((e=>e.scene)),g=C.useRef(null),[x,y]=C.useState(null),w=Ce(x,{length:i,decay:s,local:l,stride:c,interval:u});C.useEffect((()=>{const e=(null==f?void 0:f.current)||g.current.children.find((e=>e instanceof n.Object3D));e&&y(e)}),[w,f]);const E=C.useMemo((()=>new p.MeshLineGeometry),[]),b=C.useMemo((()=>{var e;const t=new p.MeshLineMaterial({lineWidth:.1*a,color:d,sizeAttenuation:1,resolution:new n.Vector2(h.width,h.height)});let o;if(r)if(Array.isArray(r))o=r.find((e=>{const t=e;return"string"==typeof t.type&&"meshLineMaterial"===t.type}));else{const e=r;"string"==typeof e.type&&"meshLineMaterial"===e.type&&(o=e)}return"object"==typeof(null==(e=o)?void 0:e.props)&&t.setValues(o.props),t}),[a,d,h,r]);return C.useEffect((()=>{b.uniforms.resolution.value.set(h.width,h.height)}),[h]),o.useFrame((()=>{w.current&&E.setPoints(w.current,m)})),C.createElement("group",null,o.createPortal(C.createElement("mesh",{ref:t,geometry:E,material:b}),v),C.createElement("group",{ref:g},r))}));function Pe(e,t=16,r,o,a){const[i,s]=C.useState((()=>{const e=Array.from({length:t},(()=>[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])).flat();return new n.InstancedBufferAttribute(Float32Array.from(e),16)}));return C.useEffect((()=>{if(void 0===e.current)return;const l=new u.MeshSurfaceSampler(e.current);o&&l.setWeightAttribute(o),l.build();const c=new n.Vector3,d=new n.Vector3,m=new n.Color,f=new n.Object3D;e.current.updateMatrixWorld(!0);for(let n=0;n<t;n++)l.sample(c,d,m),"function"==typeof r?r({dummy:f,sampledMesh:e.current,position:c,normal:d,color:m},n):f.position.copy(c),f.updateMatrix(),null!=a&&a.current&&a.current.setMatrixAt(n,f.matrix),f.matrix.toArray(i.array,16*n);null!=a&&a.current&&(a.current.instanceMatrix.needsUpdate=!0),i.needsUpdate=!0,s(i.clone())}),[e,a,o,t,r]),i}const Re=C.forwardRef((({isChild:e=!1,object:t,children:r,deep:n,castShadow:o,receiveShadow:a,inject:i,keys:s,...l},c)=>{var d;const m={keys:s,deep:n,inject:i,castShadow:o,receiveShadow:a};if(t=C.useMemo((()=>{if(!1===e&&!Array.isArray(t)){let e=!1;if(t.traverse((t=>{t.isSkinnedMesh&&(e=!0)})),e)return u.SkeletonUtils.clone(t)}return t}),[t,e]),Array.isArray(t))return C.createElement("group",S.default({},l,{ref:c}),t.map((e=>C.createElement(Re,S.default({key:e.uuid,object:e},m)))),r);const{children:f,...p}=function(e,{keys:t=["near","far","color","distance","decay","penumbra","angle","intensity","skeleton","visible","castShadow","receiveShadow","morphTargetDictionary","morphTargetInfluences","name","geometry","material","position","rotation","scale","up","userData","bindMode","bindMatrix","bindMatrixInverse","skeleton"],deep:r,inject:n,castShadow:o,receiveShadow:a}){let i=z.default(e,t);return r&&(i.geometry&&"materialsOnly"!==r&&(i.geometry=i.geometry.clone()),i.material&&"geometriesOnly"!==r&&(i.material=i.material.clone())),n&&(i="function"==typeof n?{...i,children:n(e)}:C.isValidElement(n)?{...i,children:n}:{...i,...n}),e instanceof P.Mesh&&(o&&(i.castShadow=!0),a&&(i.receiveShadow=!0)),i}(t,m),h=t.type[0].toLowerCase()+t.type.slice(1);return C.createElement(h,S.default({},p,l,{ref:c}),(null==(d=t)?void 0:d.children).map((e=>"Bone"===e.type?C.createElement("primitive",S.default({key:e.uuid,object:e},m)):C.createElement(Re,S.default({key:e.uuid,object:e},m,{isChild:!0})))),r,f)})),De=C.createContext(null),_e=C.forwardRef((({resolution:e=28,maxPolyCount:t=1e4,enableUvs:r=!1,enableColors:n=!1,children:a,...i},s)=>{const l=C.useRef(null),c=C.useMemo((()=>new u.MarchingCubes(e,null,r,n,t)),[e,t,r,n]),d=C.useMemo((()=>({getParent:()=>l})),[]);return o.useFrame((()=>{c.reset()}),-1),C.createElement(C.Fragment,null,C.createElement("primitive",S.default({object:c,ref:D.default([l,s])},i),C.createElement(De.Provider,{value:d},a)))})),ze=C.forwardRef((({strength:e=.5,subtract:t=12,color:r,...n},a)=>{const{getParent:i}=C.useContext(De),s=C.useMemo((()=>i()),[i]),l=C.useRef(),c=new P.Vector3;return o.useFrame((n=>{s.current&&l.current&&(l.current.getWorldPosition(c),s.current.addBall(.5+.5*c.x,.5+.5*c.y,.5+.5*c.z,e,t,r))})),C.createElement("group",S.default({ref:D.default([a,l])},n))})),ke=C.forwardRef((({planeType:e="x",strength:t=.5,subtract:r=12,...n},a)=>{const{getParent:i}=C.useContext(De),s=C.useMemo((()=>i()),[i]),l=C.useRef(),c=C.useMemo((()=>"x"===e?"addPlaneX":"y"===e?"addPlaneY":"addPlaneZ"),[e]);return o.useFrame((()=>{s.current&&l.current&&s.current[c](t,r)})),C.createElement("group",S.default({ref:D.default([a,l])},n))}));function Fe(e=[0,0,0]){return function(e){return Array.isArray(e)}(e)?e:e instanceof P.Vector3||e instanceof P.Euler?[e.x,e.y,e.z]:[e,e,e]}const Le=t.forwardRef((function({src:e,skipFill:r,skipStrokes:a,fillMaterial:i,strokeMaterial:s,fillMeshProps:l,strokeMeshProps:c,...d},m){const f=o.useLoader(u.SVGLoader,e.startsWith("<svg")?`data:image/svg+xml;utf8,${e}`:e),p=t.useMemo((()=>a?[]:f.paths.map((e=>{var t;return void 0===(null==(t=e.userData)?void 0:t.style.stroke)||"none"===e.userData.style.stroke?null:e.subPaths.map((t=>u.SVGLoader.pointsToStroke(t.getPoints(),e.userData.style)))}))),[f,a]);return t.useEffect((()=>()=>p.forEach((e=>e&&e.map((e=>e.dispose()))))),[p]),C.createElement("object3D",S.default({ref:m},d),C.createElement("object3D",{scale:[1,-1,1]},f.paths.map(((e,o)=>{var d,m;return C.createElement(t.Fragment,{key:o},!r&&void 0!==(null==(d=e.userData)?void 0:d.style.fill)&&"none"!==e.userData.style.fill&&u.SVGLoader.createShapes(e).map(((t,r)=>C.createElement("mesh",S.default({key:r},l),C.createElement("shapeGeometry",{args:[t]}),C.createElement("meshBasicMaterial",S.default({color:e.userData.style.fill,opacity:e.userData.style.fillOpacity,transparent:!0,side:n.DoubleSide,depthWrite:!1},i))))),!a&&void 0!==(null==(m=e.userData)?void 0:m.style.stroke)&&"none"!==e.userData.style.stroke&&e.subPaths.map(((t,r)=>C.createElement("mesh",S.default({key:r,geometry:p[o][r]},c),C.createElement("meshBasicMaterial",S.default({color:e.userData.style.stroke,opacity:e.userData.style.strokeOpacity,transparent:!0,side:n.DoubleSide,depthWrite:!1},s))))))}))))}));let Ae=null;function Be(e,t,r){return n=>{r&&r(n),e&&(Ae||(Ae=new u.DRACOLoader),Ae.setDecoderPath("string"==typeof e?e:"https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),n.setDRACOLoader(Ae)),t&&n.setMeshoptDecoder("function"==typeof u.MeshoptDecoder?u.MeshoptDecoder():u.MeshoptDecoder)}}function Ue(e,t=!0,r=!0,n){return o.useLoader(u.GLTFLoader,e,Be(t,r,n))}Ue.preload=(e,t=!0,r=!0,n)=>o.useLoader.preload(u.GLTFLoader,e,Be(t,r,n)),Ue.clear=e=>o.useLoader.clear(u.GLTFLoader,e);const Ve=C.forwardRef((({src:e,...t},r)=>{const{scene:n}=Ue(e);return C.createElement(Re,S.default({ref:r},t,{object:n}))}));function Ie(e,t,r){const{gl:n,size:a,viewport:i}=o.useThree(),s="number"==typeof e?e:a.width*i.dpr,l="number"==typeof t?t:a.height*i.dpr,c=("number"==typeof e?r:e)||{},{samples:u,...d}=c,m=C.useMemo((()=>{let e;return e=new P.WebGLRenderTarget(s,l,{minFilter:P.LinearFilter,magFilter:P.LinearFilter,encoding:n.outputEncoding,type:P.HalfFloatType,...d}),e.samples=u,e}),[]);return C.useLayoutEffect((()=>{m.setSize(s,l),u&&(m.samples=u)}),[u,m,s,l]),C.useEffect((()=>()=>m.dispose()),[]),m}const Oe=C.forwardRef((({envMap:e,resolution:t=256,frames:r=1/0,children:n,makeDefault:a,...i},s)=>{const l=o.useThree((({set:e})=>e)),c=o.useThree((({camera:e})=>e)),u=o.useThree((({size:e})=>e)),d=C.useRef(null),m=C.useRef(null),f=Ie(t);C.useLayoutEffect((()=>{i.manual||d.current.updateProjectionMatrix()}),[u,i]),C.useLayoutEffect((()=>{d.current.updateProjectionMatrix()})),C.useLayoutEffect((()=>{if(a){const e=c;return l((()=>({camera:d.current}))),()=>l((()=>({camera:e})))}}),[d,a,l]);let p=0,h=null;const v="function"==typeof n;return o.useFrame((t=>{v&&(r===1/0||p<r)&&(m.current.visible=!1,t.gl.setRenderTarget(f),h=t.scene.background,e&&(t.scene.background=e),t.gl.render(t.scene,d.current),t.scene.background=h,t.gl.setRenderTarget(null),m.current.visible=!0,p++)})),C.createElement(C.Fragment,null,C.createElement("orthographicCamera",S.default({left:u.width/-2,right:u.width/2,top:u.height/2,bottom:u.height/-2,ref:D.default([d,s])},i),!v&&n),C.createElement("group",{ref:m},v&&n(f.texture)))})),je=C.forwardRef((({envMap:e,resolution:t=256,frames:r=1/0,makeDefault:n,children:a,...i},s)=>{const l=o.useThree((({set:e})=>e)),c=o.useThree((({camera:e})=>e)),u=o.useThree((({size:e})=>e)),d=C.useRef(null),m=C.useRef(null),f=Ie(t);C.useLayoutEffect((()=>{i.manual||(d.current.aspect=u.width/u.height)}),[u,i]),C.useLayoutEffect((()=>{d.current.updateProjectionMatrix()}));let p=0,h=null;const v="function"==typeof a;return o.useFrame((t=>{v&&(r===1/0||p<r)&&(m.current.visible=!1,t.gl.setRenderTarget(f),h=t.scene.background,e&&(t.scene.background=e),t.gl.render(t.scene,d.current),t.scene.background=h,t.gl.setRenderTarget(null),m.current.visible=!0,p++)})),C.useLayoutEffect((()=>{if(n){const e=c;return l((()=>({camera:d.current}))),()=>l((()=>({camera:e})))}}),[d,n,l]),C.createElement(C.Fragment,null,C.createElement("perspectiveCamera",S.default({ref:D.default([d,s])},i),!v&&a),C.createElement("group",{ref:m},v&&a(f.texture)))}));const We=C.forwardRef(((e,t)=>{const{camera:r,onChange:n,makeDefault:a,...i}=e,s=o.useThree((e=>e.camera)),l=o.useThree((e=>e.invalidate)),c=o.useThree((e=>e.get)),d=o.useThree((e=>e.set)),m=r||s,[f]=C.useState((()=>new u.DeviceOrientationControls(m)));return C.useEffect((()=>{const e=e=>{l(),n&&n(e)};return null==f||null==f.addEventListener||f.addEventListener("change",e),()=>null==f||null==f.removeEventListener?void 0:f.removeEventListener("change",e)}),[n,f,l]),o.useFrame((()=>null==f?void 0:f.update()),-1),C.useEffect((()=>{const e=f;return null==e||e.connect(),()=>null==e?void 0:e.dispose()}),[f]),C.useEffect((()=>{if(a){const e=c().controls;return d({controls:f}),()=>d({controls:e})}}),[a,f]),f?C.createElement("primitive",S.default({ref:t,object:f},i)):null})),Ge=C.forwardRef((({domElement:e,...t},r)=>{const{onChange:n,makeDefault:a,...i}=t,s=o.useThree((e=>e.invalidate)),l=o.useThree((e=>e.camera)),c=o.useThree((e=>e.gl)),d=o.useThree((e=>e.events)),m=o.useThree((e=>e.get)),f=o.useThree((e=>e.set)),p=e||d.connected||c.domElement,h=C.useMemo((()=>new u.FlyControls(l)),[l]);return C.useEffect((()=>(h.connect(p),()=>{h.dispose()})),[p,h,s]),C.useEffect((()=>{const e=e=>{s(),n&&n(e)};return null==h.addEventListener||h.addEventListener("change",e),()=>null==h.removeEventListener?void 0:h.removeEventListener("change",e)}),[n,s]),C.useEffect((()=>{if(a){const e=m().controls;return f({controls:h}),()=>f({controls:e})}}),[a,h]),o.useFrame(((e,t)=>h.update(t))),C.createElement("primitive",S.default({ref:r,object:h,args:[l,p]},i))})),Ne=C.forwardRef(((e={enableDamping:!0},t)=>{const{domElement:r,camera:n,makeDefault:a,onChange:i,onStart:s,onEnd:l,...c}=e,d=o.useThree((e=>e.invalidate)),m=o.useThree((e=>e.camera)),f=o.useThree((e=>e.gl)),p=o.useThree((e=>e.events)),h=o.useThree((e=>e.set)),v=o.useThree((e=>e.get)),g=r||p.connected||f.domElement,x=n||m,y=C.useMemo((()=>new u.MapControls(x)),[x]);return C.useEffect((()=>{y.connect(g);const e=e=>{d(),i&&i(e)};return y.addEventListener("change",e),s&&y.addEventListener("start",s),l&&y.addEventListener("end",l),()=>{y.dispose(),y.removeEventListener("change",e),s&&y.removeEventListener("start",s),l&&y.removeEventListener("end",l)}}),[i,s,l,y,d,g]),C.useEffect((()=>{if(a){const e=v().controls;return h({controls:y}),()=>h({controls:e})}}),[a,y]),o.useFrame((()=>y.update()),-1),C.createElement("primitive",S.default({ref:t,object:y,enableDamping:!0},c))})),He=C.forwardRef((({makeDefault:e,camera:t,regress:r,domElement:n,enableDamping:a=!0,onChange:i,onStart:s,onEnd:l,...c},d)=>{const m=o.useThree((e=>e.invalidate)),f=o.useThree((e=>e.camera)),p=o.useThree((e=>e.gl)),h=o.useThree((e=>e.events)),v=o.useThree((e=>e.set)),g=o.useThree((e=>e.get)),x=o.useThree((e=>e.performance)),y=t||f,w=n||h.connected||p.domElement,E=C.useMemo((()=>new u.OrbitControls(y)),[y]);return o.useFrame((()=>{E.enabled&&E.update()}),-1),C.useEffect((()=>(E.connect(w),()=>{E.dispose()})),[w,r,E,m]),C.useEffect((()=>{const e=e=>{m(),r&&x.regress(),i&&i(e)};return E.addEventListener("change",e),s&&E.addEventListener("start",s),l&&E.addEventListener("end",l),()=>{s&&E.removeEventListener("start",s),l&&E.removeEventListener("end",l),E.removeEventListener("change",e)}}),[i,s,l,E,m]),C.useEffect((()=>{if(e){const e=g().controls;return v({controls:E}),()=>v({controls:e})}}),[e,E]),C.createElement("primitive",S.default({ref:d,object:E,enableDamping:a},c))})),$e=C.forwardRef((({makeDefault:e,camera:t,domElement:r,regress:n,onChange:a,onStart:i,onEnd:s,...l},c)=>{const{invalidate:d,camera:m,gl:f,events:p,set:h,get:v,performance:g,viewport:x}=o.useThree(),y=t||m,w=r||p.connected||f.domElement,E=C.useMemo((()=>new u.TrackballControls(y)),[y]);return o.useFrame((()=>{E.enabled&&E.update()}),-1),C.useEffect((()=>(E.connect(w),()=>{E.dispose()})),[w,n,E,d]),C.useEffect((()=>{const e=e=>{d(),n&&g.regress(),a&&a(e)};return E.addEventListener("change",e),i&&E.addEventListener("start",i),s&&E.addEventListener("end",s),()=>{i&&E.removeEventListener("start",i),s&&E.removeEventListener("end",s),E.removeEventListener("change",e)}}),[a,i,s,E,d]),C.useEffect((()=>{E.handleResize()}),[x]),C.useEffect((()=>{if(e){const e=v().controls;return h({controls:E}),()=>h({controls:e})}}),[e,E]),C.createElement("primitive",S.default({ref:c,object:E},l))})),qe=t.forwardRef((({camera:e,makeDefault:r,regress:n,domElement:a,onChange:i,onStart:s,onEnd:l,...c},d)=>{const m=o.useThree((e=>e.invalidate)),f=o.useThree((e=>e.camera)),p=o.useThree((e=>e.gl)),h=o.useThree((e=>e.events)),v=o.useThree((e=>e.set)),g=o.useThree((e=>e.get)),x=o.useThree((e=>e.performance)),y=e||f,w=a||h.connected||p.domElement,E=t.useMemo((()=>new u.ArcballControls(y)),[y]);return o.useFrame((()=>{E.enabled&&E.update()}),-1),t.useEffect((()=>(E.connect(w),()=>{E.dispose()})),[w,n,E,m]),t.useEffect((()=>{const e=e=>{m(),n&&x.regress(),i&&i(e)};return E.addEventListener("change",e),s&&E.addEventListener("start",s),l&&E.addEventListener("end",l),()=>{E.removeEventListener("change",e),s&&E.removeEventListener("start",s),l&&E.removeEventListener("end",l)}}),[i,s,l]),t.useEffect((()=>{if(r){const e=g().controls;return v({controls:E}),()=>v({controls:e})}}),[r,E]),C.createElement("primitive",S.default({ref:d,object:E},c))})),Xe=C.forwardRef((({children:e,domElement:t,onChange:r,onMouseDown:n,onMouseUp:a,onObjectChange:i,object:s,makeDefault:l,...c},d)=>{const m=["enabled","axis","mode","translationSnap","rotationSnap","scaleSnap","space","size","showX","showY","showZ"],{camera:f,...p}=c,h=z.default(p,m),v=k.default(p,m),g=o.useThree((e=>e.controls)),x=o.useThree((e=>e.gl)),y=o.useThree((e=>e.events)),w=o.useThree((e=>e.camera)),E=o.useThree((e=>e.invalidate)),b=o.useThree((e=>e.get)),M=o.useThree((e=>e.set)),T=f||w,R=t||y.connected||x.domElement,D=C.useMemo((()=>new u.TransformControls(T,R)),[T,R]),_=C.useRef();C.useLayoutEffect((()=>(s?D.attach(s instanceof P.Object3D?s:s.current):_.current instanceof P.Object3D&&D.attach(_.current),()=>{D.detach()})),[s,e,D]),C.useEffect((()=>{if(g){const e=e=>g.enabled=!e.value;return D.addEventListener("dragging-changed",e),()=>D.removeEventListener("dragging-changed",e)}}),[D,g]);const F=C.useRef(),L=C.useRef(),A=C.useRef(),B=C.useRef();return C.useLayoutEffect((()=>{F.current=r}),[r]),C.useLayoutEffect((()=>{L.current=n}),[n]),C.useLayoutEffect((()=>{A.current=a}),[a]),C.useLayoutEffect((()=>{B.current=i}),[i]),C.useEffect((()=>{const e=e=>{E(),null==F.current||F.current(e)},t=e=>null==L.current?void 0:L.current(e),r=e=>null==A.current?void 0:A.current(e),n=e=>null==B.current?void 0:B.current(e);return D.addEventListener("change",e),D.addEventListener("mouseDown",t),D.addEventListener("mouseUp",r),D.addEventListener("objectChange",n),()=>{D.removeEventListener("change",e),D.removeEventListener("mouseDown",t),D.removeEventListener("mouseUp",r),D.removeEventListener("objectChange",n)}}),[E,D]),C.useEffect((()=>{if(l){const e=b().controls;return M({controls:D}),()=>M({controls:e})}}),[l,D]),D?C.createElement(C.Fragment,null,C.createElement("primitive",S.default({ref:d,object:D},h)),C.createElement("group",S.default({ref:_},v),e)):null})),Ye=C.forwardRef((({domElement:e,selector:t,onChange:r,onLock:n,onUnlock:a,enabled:i=!0,makeDefault:s,...l},c)=>{const{camera:d,...m}=l,f=o.useThree((e=>e.setEvents)),p=o.useThree((e=>e.gl)),h=o.useThree((e=>e.camera)),v=o.useThree((e=>e.invalidate)),g=o.useThree((e=>e.events)),x=o.useThree((e=>e.get)),y=o.useThree((e=>e.set)),w=d||h,E=e||g.connected||p.domElement,[b]=C.useState((()=>new u.PointerLockControls(w)));return C.useEffect((()=>{if(i){b.connect(E);const e=x().events.compute;return f({compute(e,t){const r=t.size.width/2,n=t.size.height/2;t.pointer.set(r/t.size.width*2-1,-n/t.size.height*2+1),t.raycaster.setFromCamera(t.pointer,t.camera)}}),()=>{b.disconnect(),f({compute:e})}}}),[i,b]),C.useEffect((()=>{const e=e=>{v(),r&&r(e)};b.addEventListener("change",e),n&&b.addEventListener("lock",n),a&&b.addEventListener("unlock",a);const o=()=>b.lock(),i=t?Array.from(document.querySelectorAll(t)):[document];return i.forEach((e=>e&&e.addEventListener("click",o))),()=>{b.removeEventListener("change",e),n&&b.addEventListener("lock",n),a&&b.addEventListener("unlock",a),i.forEach((e=>e?e.removeEventListener("click",o):void 0))}}),[r,n,a,t,b,v]),C.useEffect((()=>{if(s){const e=x().controls;return y({controls:b}),()=>y({controls:e})}}),[s,b]),C.createElement("primitive",S.default({ref:c,object:b},m))})),Ze=C.forwardRef((({domElement:e,makeDefault:t,...r},n)=>{const a=o.useThree((e=>e.camera)),i=o.useThree((e=>e.gl)),s=o.useThree((e=>e.events)),l=o.useThree((e=>e.get)),c=o.useThree((e=>e.set)),d=e||s.connected||i.domElement,[m]=C.useState((()=>new u.FirstPersonControls(a,d)));return C.useEffect((()=>{if(t){const e=l().controls;return c({controls:m}),()=>c({controls:e})}}),[t,m]),o.useFrame(((e,t)=>{m.update(t)}),-1),m?C.createElement("primitive",S.default({ref:n,object:m},r)):null}));function Ke({defaultScene:e,defaultCamera:t,renderPriority:r=1}){const{gl:n,scene:a,camera:i}=o.useThree();let s;return o.useFrame((()=>{s=n.autoClear,1===r&&(n.autoClear=!0,n.render(e,t)),n.autoClear=!1,n.clearDepth(),n.render(a,i),n.autoClear=s}),r),C.createElement(C.Fragment,null)}function Qe({children:e,renderPriority:t=1}){const{scene:r,camera:n}=o.useThree(),[a]=C.useState((()=>new P.Scene));return C.createElement(C.Fragment,null,o.createPortal(C.createElement(C.Fragment,null,e,C.createElement(Ke,{defaultScene:r,defaultCamera:n,renderPriority:t})),a,{events:{priority:t+1}}))}const Je=C.createContext({}),et=()=>C.useContext(Je),tt=2*Math.PI,rt=new n.Object3D,nt=new n.Matrix4,[ot,at]=[new n.Quaternion,new n.Quaternion],it=new n.Vector3,st=new n.Vector3,lt="#f0f0f0",ct="#999",ut="black",dt="black",mt=["Right","Left","Top","Bottom","Front","Back"],ft=e=>new n.Vector3(...e).multiplyScalar(.38),pt=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]].map(ft),ht=[.25,.25,.25],vt=[[1,1,0],[1,0,1],[1,0,-1],[1,-1,0],[0,1,1],[0,1,-1],[0,-1,1],[0,-1,-1],[-1,1,0],[-1,0,1],[-1,0,-1],[-1,-1,0]].map(ft),gt=vt.map((e=>e.toArray().map((e=>0==e?.5:.25)))),xt=({hover:e,index:t,font:r="20px Inter var, Arial, sans-serif",faces:a=mt,color:i=lt,hoverColor:s=ct,textColor:l=ut,strokeColor:c=dt,opacity:u=1})=>{const d=o.useThree((e=>e.gl)),m=C.useMemo((()=>{const e=document.createElement("canvas");e.width=128,e.height=128;const o=e.getContext("2d");return o.fillStyle=i,o.fillRect(0,0,e.width,e.height),o.strokeStyle=c,o.strokeRect(0,0,e.width,e.height),o.font=r,o.textAlign="center",o.fillStyle=l,o.fillText(a[t].toUpperCase(),64,76),new n.CanvasTexture(e)}),[t,a,r,i,l,c]);return C.createElement("meshLambertMaterial",{map:m,"map-encoding":d.outputEncoding,"map-anisotropy":d.capabilities.getMaxAnisotropy()||1,attach:`material-${t}`,color:e?s:"white",transparent:!0,opacity:u})},yt=e=>{const{tweenCamera:t}=et(),[r,n]=C.useState(null);return C.createElement("mesh",{onPointerOut:e=>{e.stopPropagation(),n(null)},onPointerMove:e=>{e.stopPropagation(),n(Math.floor(e.faceIndex/2))},onClick:e.onClick||(e=>{e.stopPropagation(),t(e.face.normal)})},[...Array(6)].map(((t,n)=>C.createElement(xt,S.default({key:n,index:n,hover:r===n},e)))),C.createElement("boxGeometry",null))},wt=({onClick:e,dimensions:t,position:r,hoverColor:n=ct})=>{const{tweenCamera:o}=et(),[a,i]=C.useState(!1);return C.createElement("mesh",{scale:1.01,position:r,onPointerOver:e=>{e.stopPropagation(),i(!0)},onPointerOut:e=>{e.stopPropagation(),i(!1)},onClick:e||(e=>{e.stopPropagation(),o(r)})},C.createElement("meshBasicMaterial",{color:a?n:"white",transparent:!0,opacity:.6,visible:a}),C.createElement("boxGeometry",{args:t}))};function Et({scale:e=[.8,.05,.05],color:t,rotation:r}){return C.createElement("group",{rotation:r},C.createElement("mesh",{position:[.4,0,0]},C.createElement("boxGeometry",{args:e}),C.createElement("meshBasicMaterial",{color:t,toneMapped:!1})))}function bt({onClick:e,font:t,disabled:r,arcStyle:a,label:i,labelColor:s,axisHeadScale:l=1,...c}){const u=o.useThree((e=>e.gl)),d=C.useMemo((()=>{const e=document.createElement("canvas");e.width=64,e.height=64;const r=e.getContext("2d");return r.beginPath(),r.arc(32,32,16,0,2*Math.PI),r.closePath(),r.fillStyle=a,r.fill(),i&&(r.font=t,r.textAlign="center",r.fillStyle=s,r.fillText(i,32,41)),new n.CanvasTexture(e)}),[a,i,s,t]),[m,f]=C.useState(!1),p=(i?1:.75)*(m?1.2:1)*l;return C.createElement("sprite",S.default({scale:p,onPointerOver:r?void 0:e=>{e.stopPropagation(),f(!0)},onPointerOut:r?void 0:e||(e=>{e.stopPropagation(),f(!1)})},c),C.createElement("spriteMaterial",{map:d,"map-encoding":u.outputEncoding,"map-anisotropy":u.capabilities.getMaxAnisotropy()||1,alphaTest:.3,opacity:i?1:.75,toneMapped:!1}))}const Mt=he({cellSize:.5,sectionSize:1,fadeDistance:100,fadeStrength:1,cellThickness:.5,sectionThickness:1,cellColor:new P.Color,sectionColor:new P.Color,infiniteGrid:0,followCamera:0},"varying vec3 worldPosition;\n uniform float fadeDistance;\n uniform float infiniteGrid;\n uniform float followCamera;\n void main() {\n vec3 pos = position.xzy * (1. + fadeDistance * infiniteGrid);\n pos.xz += (cameraPosition.xz * followCamera);\n worldPosition = pos;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);\n }","varying vec3 worldPosition;\n uniform float cellSize;\n uniform float sectionSize;\n uniform vec3 cellColor;\n uniform vec3 sectionColor;\n uniform float fadeDistance;\n uniform float fadeStrength;\n uniform float cellThickness;\n uniform float sectionThickness;\n uniform float infiniteGrid;\n float getGrid(float size, float thickness) {\n vec2 r = worldPosition.xz / size;\n vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n float line = min(grid.x, grid.y) + 1. - thickness;\n return 1.0 - min(line, 1.);\n }\n void main() {\n float g1 = getGrid(cellSize, cellThickness);\n float g2 = getGrid(sectionSize, sectionThickness);\n float d = 1.0 - min(distance(cameraPosition.xz, worldPosition.xz) / fadeDistance, 1.);\n vec3 color = mix(cellColor, sectionColor, min(1.,sectionThickness * g2));\n gl_FragColor = vec4(color, (g1 + g2) * pow(d,fadeStrength));\n gl_FragColor.a = mix(0.75 * gl_FragColor.a, gl_FragColor.a, g2);\n if (gl_FragColor.a <= 0.0) discard;\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }"),St=C.forwardRef((({args:e,cellColor:t="#000000",sectionColor:r="#2080ff",cellSize:n=.5,sectionSize:a=1,followCamera:i=!1,infiniteGrid:s=!1,fadeDistance:l=100,fadeStrength:c=1,cellThickness:u=.5,sectionThickness:d=1,...m},f)=>{o.extend({GridMaterial:Mt});const p={cellSize:n,sectionSize:a,cellColor:t,sectionColor:r,cellThickness:u,sectionThickness:d},h={fadeDistance:l,fadeStrength:c,infiniteGrid:s,followCamera:i};return C.createElement("mesh",S.default({ref:f,frustumCulled:!1},m),C.createElement("gridMaterial",S.default({transparent:!0,"extensions-derivatives":!0,side:P.DoubleSide},p,h)),C.createElement("planeGeometry",{args:e}))}));function Ct(e,{path:t}){const[r]=o.useLoader(n.CubeTextureLoader,[e],(e=>e.setPath(t)));return r}function Tt(e){return o.useLoader(u.FBXLoader,e)}Ct.preload=(e,{path:t})=>o.useLoader.preload(n.CubeTextureLoader,[e],(e=>e.setPath(t))),Tt.preload=e=>o.useLoader.preload(u.FBXLoader,e),Tt.clear=e=>o.useLoader.clear(u.FBXLoader,e);const Pt="https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master";function Rt(e,r=`${Pt}/basis/`){const n=o.useThree((e=>e.gl)),a=o.useLoader(u.KTX2Loader,ve(e)?Object.values(e):e,(e=>{e.detectSupport(n),e.setTranscoderPath(r)}));if(t.useEffect((()=>{(Array.isArray(a)?a:[a]).forEach(n.initTexture)}),[n,a]),ve(e)){const t=Object.keys(e),r={};return t.forEach((e=>Object.assign(r,{[e]:a[t.indexOf(e)]}))),r}return a}function Dt(e,t){"function"==typeof e?e(t):null!=e&&(e.current=t)}Rt.preload=(e,t=`${Pt}/basis/`)=>o.useLoader.preload(u.KTX2Loader,e,(e=>{e.setTranscoderPath(t)})),Rt.clear=e=>o.useLoader.clear(u.KTX2Loader,e);const _t=new P.Box3,zt=new P.Vector3;const kt=e=>Math.sqrt(1-Math.pow(e-1,2));class Ft{constructor({size:e=256,maxAge:t=750,radius:r=.3,intensity:n=.2,interpolate:o=0,smoothing:a=0,minForce:i=.3,blend:s="screen",ease:l=kt}={}){this.size=e,this.maxAge=t,this.radius=r,this.intensity=n,this.ease=l,this.interpolate=o,this.smoothing=a,this.minForce=i,this.blend=s,this.trail=[],this.force=0,this.initTexture()}initTexture(){this.canvas=document.createElement("canvas"),this.canvas.width=this.canvas.height=this.size,this.ctx=this.canvas.getContext("2d"),this.ctx.fillStyle="black",this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height),this.texture=new n.Texture(this.canvas),this.canvas.id="touchTexture",this.canvas.style.width=this.canvas.style.height=`${this.canvas.width}px`}update(e){this.clear(),this.trail.forEach(((t,r)=>{t.age+=1e3*e,t.age>this.maxAge&&this.trail.splice(r,1)})),this.trail.length||(this.force=0),this.trail.forEach((e=>{this.drawTouch(e)})),this.texture.needsUpdate=!0}clear(){this.ctx.globalCompositeOperation="source-over",this.ctx.fillStyle="black",this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}addTouch(e){const t=this.trail[this.trail.length-1];if(t){const r=t.x-e.x,n=t.y-e.y,o=r*r+n*n,a=Math.max(this.minForce,Math.min(1e4*o,1));if(this.force=function(e,t,r=.9){return t*r+e*(1-r)}(a,this.force,this.smoothing),this.interpolate){const e=Math.ceil(o/Math.pow(.5*this.radius/this.interpolate,2));if(e>1)for(let o=1;o<e;o++)this.trail.push({x:t.x-r/e*o,y:t.y-n/e*o,age:0,force:a})}}this.trail.push({x:e.x,y:e.y,age:0,force:this.force})}drawTouch(e){const t={x:e.x*this.size,y:(1-e.y)*this.size};let r=1;r=e.age<.3*this.maxAge?this.ease(e.age/(.3*this.maxAge)):this.ease(1-(e.age-.3*this.maxAge)/(.7*this.maxAge)),r*=e.force,this.ctx.globalCompositeOperation=this.blend;const n=this.size*this.radius*r,o=this.ctx.createRadialGradient(t.x,t.y,Math.max(0,.25*n),t.x,t.y,Math.max(0,n));o.addColorStop(0,`rgba(255, 255, 255, ${this.intensity})`),o.addColorStop(1,"rgba(0, 0, 0, 0.0)"),this.ctx.beginPath(),this.ctx.fillStyle=o,this.ctx.arc(t.x,t.y,Math.max(0,n),0,2*Math.PI),this.ctx.fill()}}const Lt=C.forwardRef((({children:e,curve:t},r)=>{const[n]=C.useState((()=>new P.Scene)),[a,i]=C.useState(),s=C.useRef();return C.useEffect((()=>{s.current=new u.Flow(n.children[0]),i(s.current.object3D)}),[e]),C.useEffect((()=>{var e;t&&(null==(e=s.current)||e.updateCurve(0,t))}),[t]),C.useImperativeHandle(r,(()=>({moveAlongCurve:e=>{var t;null==(t=s.current)||t.moveAlongCurve(e)}}))),C.createElement(C.Fragment,null,o.createPortal(e,n),a&&C.createElement("primitive",{object:a}))}));class At extends n.MeshPhysicalMaterial{constructor(e={}){super(e),this.setValues(e),this._time={value:0},this._distort={value:.4},this._radius={value:1}}onBeforeCompile(e){e.uniforms.time=this._time,e.uniforms.radius=this._radius,e.uniforms.distort=this._distort,e.vertexShader=`\n uniform float time;\n uniform float radius;\n uniform float distort;\n #define GLSLIFY 1\nvec3 mod289(vec3 x){return x-floor(x*(1.0/289.0))*289.0;}vec4 mod289(vec4 x){return x-floor(x*(1.0/289.0))*289.0;}vec4 permute(vec4 x){return mod289(((x*34.0)+1.0)*x);}vec4 taylorInvSqrt(vec4 r){return 1.79284291400159-0.85373472095314*r;}float snoise(vec3 v){const vec2 C=vec2(1.0/6.0,1.0/3.0);const vec4 D=vec4(0.0,0.5,1.0,2.0);vec3 i=floor(v+dot(v,C.yyy));vec3 x0=v-i+dot(i,C.xxx);vec3 g=step(x0.yzx,x0.xyz);vec3 l=1.0-g;vec3 i1=min(g.xyz,l.zxy);vec3 i2=max(g.xyz,l.zxy);vec3 x1=x0-i1+C.xxx;vec3 x2=x0-i2+C.yyy;vec3 x3=x0-D.yyy;i=mod289(i);vec4 p=permute(permute(permute(i.z+vec4(0.0,i1.z,i2.z,1.0))+i.y+vec4(0.0,i1.y,i2.y,1.0))+i.x+vec4(0.0,i1.x,i2.x,1.0));float n_=0.142857142857;vec3 ns=n_*D.wyz-D.xzx;vec4 j=p-49.0*floor(p*ns.z*ns.z);vec4 x_=floor(j*ns.z);vec4 y_=floor(j-7.0*x_);vec4 x=x_*ns.x+ns.yyyy;vec4 y=y_*ns.x+ns.yyyy;vec4 h=1.0-abs(x)-abs(y);vec4 b0=vec4(x.xy,y.xy);vec4 b1=vec4(x.zw,y.zw);vec4 s0=floor(b0)*2.0+1.0;vec4 s1=floor(b1)*2.0+1.0;vec4 sh=-step(h,vec4(0.0));vec4 a0=b0.xzyw+s0.xzyw*sh.xxyy;vec4 a1=b1.xzyw+s1.xzyw*sh.zzww;vec3 p0=vec3(a0.xy,h.x);vec3 p1=vec3(a0.zw,h.y);vec3 p2=vec3(a1.xy,h.z);vec3 p3=vec3(a1.zw,h.w);vec4 norm=taylorInvSqrt(vec4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));p0*=norm.x;p1*=norm.y;p2*=norm.z;p3*=norm.w;vec4 m=max(0.6-vec4(dot(x0,x0),dot(x1,x1),dot(x2,x2),dot(x3,x3)),0.0);m=m*m;return 42.0*dot(m*m,vec4(dot(p0,x0),dot(p1,x1),dot(p2,x2),dot(p3,x3)));}\n ${e.vertexShader}\n `,e.vertexShader=e.vertexShader.replace("#include <begin_vertex>","\n float updateTime = time / 50.0;\n float noise = snoise(vec3(position / 2.0 + updateTime * 5.0));\n vec3 transformed = vec3(position * (noise * pow(distort, 2.0) + radius));\n ")}get time(){return this._time.value}set time(e){this._time.value=e}get distort(){return this._distort.value}set distort(e){this._distort.value=e}get radius(){return this._radius.value}set radius(e){this._radius.value=e}}const Bt=C.forwardRef((({speed:e=1,...t},r)=>{const[n]=C.useState((()=>new At));return o.useFrame((t=>n&&(n.time=t.clock.getElapsedTime()*e))),C.createElement("primitive",S.default({object:n,ref:r,attach:"material"},t))}));class Ut extends n.MeshStandardMaterial{constructor(e={}){super(e),this.setValues(e),this._time={value:0},this._factor={value:1}}onBeforeCompile(e){e.uniforms.time=this._time,e.uniforms.factor=this._factor,e.vertexShader=`\n uniform float time;\n uniform float factor;\n ${e.vertexShader}\n `,e.vertexShader=e.vertexShader.replace("#include <begin_vertex>","float theta = sin( time + position.y ) / 2.0 * factor;\n float c = cos( theta );\n float s = sin( theta );\n mat3 m = mat3( c, 0, s, 0, 1, 0, -s, 0, c );\n vec3 transformed = vec3( position ) * m;\n vNormal = vNormal * m;")}get time(){return this._time.value}set time(e){this._time.value=e}get factor(){return this._factor.value}set factor(e){this._factor.value=e}}const Vt=C.forwardRef((({speed:e=1,...t},r)=>{const[n]=C.useState((()=>new Ut));return o.useFrame((t=>n&&(n.time=t.clock.getElapsedTime()*e))),C.createElement("primitive",S.default({object:n,ref:r,attach:"material"},t))}));class It extends n.ShaderMaterial{constructor(e=new n.Vector2){super({uniforms:{inputBuffer:new n.Uniform(null),depthBuffer:new n.Uniform(null),resolution:new n.Uniform(new n.Vector2),texelSize:new n.Uniform(new n.Vector2),halfTexelSize:new n.Uniform(new n.Vector2),kernel:new n.Uniform(0),scale:new n.Uniform(1),cameraNear:new n.Uniform(0),cameraFar:new n.Uniform(1),minDepthThreshold:new n.Uniform(0),maxDepthThreshold:new n.Uniform(1),depthScale:new n.Uniform(0),depthToBlurRatioBias:new n.Uniform(.25)},fragmentShader:"#include <common>\n #include <dithering_pars_fragment> \n uniform sampler2D inputBuffer;\n uniform sampler2D depthBuffer;\n uniform float cameraNear;\n uniform float cameraFar;\n uniform float minDepthThreshold;\n uniform float maxDepthThreshold;\n uniform float depthScale;\n uniform float depthToBlurRatioBias;\n varying vec2 vUv;\n varying vec2 vUv0;\n varying vec2 vUv1;\n varying vec2 vUv2;\n varying vec2 vUv3;\n\n void main() {\n float depthFactor = 0.0;\n \n #ifdef USE_DEPTH\n vec4 depth = texture2D(depthBuffer, vUv);\n depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));\n depthFactor *= depthScale;\n depthFactor = max(0.0, min(1.0, depthFactor + 0.25));\n #endif\n \n vec4 sum = texture2D(inputBuffer, mix(vUv0, vUv, depthFactor));\n sum += texture2D(inputBuffer, mix(vUv1, vUv, depthFactor));\n sum += texture2D(inputBuffer, mix(vUv2, vUv, depthFactor));\n sum += texture2D(inputBuffer, mix(vUv3, vUv, depthFactor));\n gl_FragColor = sum * 0.25 ;\n\n #include <dithering_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }",vertexShader:"uniform vec2 texelSize;\n uniform vec2 halfTexelSize;\n uniform float kernel;\n uniform float scale;\n varying vec2 vUv;\n varying vec2 vUv0;\n varying vec2 vUv1;\n varying vec2 vUv2;\n varying vec2 vUv3;\n\n void main() {\n vec2 uv = position.xy * 0.5 + 0.5;\n vUv = uv;\n\n vec2 dUv = (texelSize * vec2(kernel) + halfTexelSize) * scale;\n vUv0 = vec2(uv.x - dUv.x, uv.y + dUv.y);\n vUv1 = vec2(uv.x + dUv.x, uv.y + dUv.y);\n vUv2 = vec2(uv.x + dUv.x, uv.y - dUv.y);\n vUv3 = vec2(uv.x - dUv.x, uv.y - dUv.y);\n\n gl_Position = vec4(position.xy, 1.0, 1.0);\n }",blending:n.NoBlending,depthWrite:!1,depthTest:!1}),this.toneMapped=!1,this.setTexelSize(e.x,e.y),this.kernel=new Float32Array([0,1,2,2,3])}setTexelSize(e,t){this.uniforms.texelSize.value.set(e,t),this.uniforms.halfTexelSize.value.set(e,t).multiplyScalar(.5)}setResolution(e){this.uniforms.resolution.value.copy(e)}}class Ot{constructor({gl:e,resolution:t,width:r=500,height:o=500,minDepthThreshold:a=0,maxDepthThreshold:i=1,depthScale:s=0,depthToBlurRatioBias:l=.25}){this.renderToScreen=!1,this.renderTargetA=new n.WebGLRenderTarget(t,t,{minFilter:n.LinearFilter,magFilter:n.LinearFilter,stencilBuffer:!1,depthBuffer:!1,encoding:e.outputEncoding}),this.renderTargetB=this.renderTargetA.clone(),this.convolutionMaterial=new It,this.convolutionMaterial.setTexelSize(1/r,1/o),this.convolutionMaterial.setResolution(new n.Vector2(r,o)),this.scene=new n.Scene,this.camera=new n.Camera,this.convolutionMaterial.uniforms.minDepthThreshold.value=a,this.convolutionMaterial.uniforms.maxDepthThreshold.value=i,this.convolutionMaterial.uniforms.depthScale.value=s,this.convolutionMaterial.uniforms.depthToBlurRatioBias.value=l,this.convolutionMaterial.defines.USE_DEPTH=s>0;const c=new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),u=new Float32Array([0,0,2,0,0,2]),d=new n.BufferGeometry;d.setAttribute("position",new n.BufferAttribute(c,3)),d.setAttribute("uv",new n.BufferAttribute(u,2)),this.screen=new n.Mesh(d,this.convolutionMaterial),this.screen.frustumCulled=!1,this.scene.add(this.screen)}render(e,t,r){const n=this.scene,o=this.camera,a=this.renderTargetA,i=this.renderTargetB;let s=this.convolutionMaterial,l=s.uniforms;l.depthBuffer.value=t.depthTexture;const c=s.kernel;let u,d,m,f=t;for(d=0,m=c.length-1;d<m;++d)u=0==(1&d)?a:i,l.kernel.value=c[d],l.inputBuffer.value=f.texture,e.setRenderTarget(u),e.render(n,o),f=u;l.kernel.value=c[d],l.inputBuffer.value=f.texture,e.setRenderTarget(this.renderToScreen?null:r),e.render(n,o)}}class jt extends n.MeshStandardMaterial{constructor(e={}){super(e),this._tDepth={value:null},this._distortionMap={value:null},this._tDiffuse={value:null},this._tDiffuseBlur={value:null},this._textureMatrix={value:null},this._hasBlur={value:!1},this._mirror={value:0},this._mixBlur={value:0},this._blurStrength={value:.5},this._minDepthThreshold={value:.9},this._maxDepthThreshold={value:1},this._depthScale={value:0},this._depthToBlurRatioBias={value:.25},this._distortion={value:1},this._mixContrast={value:1},this.setValues(e)}onBeforeCompile(e){var t;null!=(t=e.defines)&&t.USE_UV||(e.defines.USE_UV=""),e.uniforms.hasBlur=this._hasBlur,e.uniforms.tDiffuse=this._tDiffuse,e.uniforms.tDepth=this._tDepth,e.uniforms.distortionMap=this._distortionMap,e.uniforms.tDiffuseBlur=this._tDiffuseBlur,e.uniforms.textureMatrix=this._textureMatrix,e.uniforms.mirror=this._mirror,e.uniforms.mixBlur=this._mixBlur,e.uniforms.mixStrength=this._blurStrength,e.uniforms.minDepthThreshold=this._minDepthThreshold,e.uniforms.maxDepthThreshold=this._maxDepthThreshold,e.uniforms.depthScale=this._depthScale,e.uniforms.depthToBlurRatioBias=this._depthToBlurRatioBias,e.uniforms.distortion=this._distortion,e.uniforms.mixContrast=this._mixContrast,e.vertexShader=`\n uniform mat4 textureMatrix;\n varying vec4 my_vUv;\n ${e.vertexShader}`,e.vertexShader=e.vertexShader.replace("#include <project_vertex>","#include <project_vertex>\n my_vUv = textureMatrix * vec4( position, 1.0 );\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );"),e.fragmentShader=`\n uniform sampler2D tDiffuse;\n uniform sampler2D tDiffuseBlur;\n uniform sampler2D tDepth;\n uniform sampler2D distortionMap;\n uniform float distortion;\n uniform float cameraNear;\n\t\t\t uniform float cameraFar;\n uniform bool hasBlur;\n uniform float mixBlur;\n uniform float mirror;\n uniform float mixStrength;\n uniform float minDepthThreshold;\n uniform float maxDepthThreshold;\n uniform float mixContrast;\n uniform float depthScale;\n uniform float depthToBlurRatioBias;\n varying vec4 my_vUv;\n ${e.fragmentShader}`,e.fragmentShader=e.fragmentShader.replace("#include <emissivemap_fragment>","#include <emissivemap_fragment>\n\n float distortionFactor = 0.0;\n #ifdef USE_DISTORTION\n distortionFactor = texture2D(distortionMap, vUv).r * distortion;\n #endif\n\n vec4 new_vUv = my_vUv;\n new_vUv.x += distortionFactor;\n new_vUv.y += distortionFactor;\n\n vec4 base = texture2DProj(tDiffuse, new_vUv);\n vec4 blur = texture2DProj(tDiffuseBlur, new_vUv);\n\n vec4 merge = base;\n\n #ifdef USE_NORMALMAP\n vec2 normal_uv = vec2(0.0);\n vec4 normalColor = texture2D(normalMap, vUv * normalScale);\n vec3 my_normal = normalize( vec3( normalColor.r * 2.0 - 1.0, normalColor.b, normalColor.g * 2.0 - 1.0 ) );\n vec3 coord = new_vUv.xyz / new_vUv.w;\n normal_uv = coord.xy + coord.z * my_normal.xz * 0.05;\n vec4 base_normal = texture2D(tDiffuse, normal_uv);\n vec4 blur_normal = texture2D(tDiffuseBlur, normal_uv);\n merge = base_normal;\n blur = blur_normal;\n #endif\n\n float depthFactor = 0.0001;\n float blurFactor = 0.0;\n\n #ifdef USE_DEPTH\n vec4 depth = texture2DProj(tDepth, new_vUv);\n depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));\n depthFactor *= depthScale;\n depthFactor = max(0.0001, min(1.0, depthFactor));\n\n #ifdef USE_BLUR\n blur = blur * min(1.0, depthFactor + depthToBlurRatioBias);\n merge = merge * min(1.0, depthFactor + 0.5);\n #else\n merge = merge * depthFactor;\n #endif\n\n #endif\n\n float reflectorRoughnessFactor = roughness;\n #ifdef USE_ROUGHNESSMAP\n vec4 reflectorTexelRoughness = texture2D( roughnessMap, vUv );\n reflectorRoughnessFactor *= reflectorTexelRoughness.g;\n #endif\n\n #ifdef USE_BLUR\n blurFactor = min(1.0, mixBlur * reflectorRoughnessFactor);\n merge = mix(merge, blur, blurFactor);\n #endif\n\n vec4 newMerge = vec4(0.0, 0.0, 0.0, 1.0);\n newMerge.r = (merge.r - 0.5) * mixContrast + 0.5;\n newMerge.g = (merge.g - 0.5) * mixContrast + 0.5;\n newMerge.b = (merge.b - 0.5) * mixContrast + 0.5;\n\n diffuseColor.rgb = diffuseColor.rgb * ((1.0 - min(1.0, mirror)) + newMerge.rgb * mixStrength);\n ")}get tDiffuse(){return this._tDiffuse.value}set tDiffuse(e){this._tDiffuse.value=e}get tDepth(){return this._tDepth.value}set tDepth(e){this._tDepth.value=e}get distortionMap(){return this._distortionMap.value}set distortionMap(e){this._distortionMap.value=e}get tDiffuseBlur(){return this._tDiffuseBlur.value}set tDiffuseBlur(e){this._tDiffuseBlur.value=e}get textureMatrix(){return this._textureMatrix.value}set textureMatrix(e){this._textureMatrix.value=e}get hasBlur(){return this._hasBlur.value}set hasBlur(e){this._hasBlur.value=e}get mirror(){return this._mirror.value}set mirror(e){this._mirror.value=e}get mixBlur(){return this._mixBlur.value}set mixBlur(e){this._mixBlur.value=e}get mixStrength(){return this._blurStrength.value}set mixStrength(e){this._blurStrength.value=e}get minDepthThreshold(){return this._minDepthThreshold.value}set minDepthThreshold(e){this._minDepthThreshold.value=e}get maxDepthThreshold(){return this._maxDepthThreshold.value}set maxDepthThreshold(e){this._maxDepthThreshold.value=e}get depthScale(){return this._depthScale.value}set depthScale(e){this._depthScale.value=e}get depthToBlurRatioBias(){return this._depthToBlurRatioBias.value}set depthToBlurRatioBias(e){this._depthToBlurRatioBias.value=e}get distortion(){return this._distortion.value}set distortion(e){this._distortion.value=e}get mixContrast(){return this._mixContrast.value}set mixContrast(e){this._mixContrast.value=e}}o.extend({MeshReflectorMaterialImpl:jt});const Wt=C.forwardRef((({mixBlur:e=0,mixStrength:t=1,resolution:r=256,blur:a=[0,0],minDepthThreshold:i=.9,maxDepthThreshold:s=1,depthScale:l=0,depthToBlurRatioBias:c=.25,mirror:u=0,distortion:d=1,mixContrast:m=1,distortionMap:f,reflectorOffset:p=0,...h},v)=>{const g=o.useThree((({gl:e})=>e)),x=o.useThree((({camera:e})=>e)),y=o.useThree((({scene:e})=>e)),w=(a=Array.isArray(a)?a:[a,a])[0]+a[1]>0,E=C.useRef(null),[b]=C.useState((()=>new n.Plane)),[M]=C.useState((()=>new n.Vector3)),[T]=C.useState((()=>new n.Vector3)),[P]=C.useState((()=>new n.Vector3)),[R]=C.useState((()=>new n.Matrix4)),[_]=C.useState((()=>new n.Vector3(0,0,-1))),[z]=C.useState((()=>new n.Vector4)),[k]=C.useState((()=>new n.Vector3)),[F]=C.useState((()=>new n.Vector3)),[L]=C.useState((()=>new n.Vector4)),[A]=C.useState((()=>new n.Matrix4)),[B]=C.useState((()=>new n.PerspectiveCamera)),U=C.useCallback((()=>{var e;const t=E.current.parent||(null==(e=E.current)?void 0:e.__r3f.parent);if(!t)return;if(T.setFromMatrixPosition(t.matrixWorld),P.setFromMatrixPosition(x.matrixWorld),R.extractRotation(t.matrixWorld),M.set(0,0,1),M.applyMatrix4(R),T.addScaledVector(M,p),k.subVectors(T,P),k.dot(M)>0)return;k.reflect(M).negate(),k.add(T),R.extractRotation(x.matrixWorld),_.set(0,0,-1),_.applyMatrix4(R),_.add(P),F.subVectors(T,_),F.reflect(M).negate(),F.add(T),B.position.copy(k),B.up.set(0,1,0),B.up.applyMatrix4(R),B.up.reflect(M),B.lookAt(F),B.far=x.far,B.updateMatrixWorld(),B.projectionMatrix.copy(x.projectionMatrix),A.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),A.multiply(B.projectionMatrix),A.multiply(B.matrixWorldInverse),A.multiply(t.matrixWorld),b.setFromNormalAndCoplanarPoint(M,T),b.applyMatrix4(B.matrixWorldInverse),z.set(b.normal.x,b.normal.y,b.normal.z,b.constant);const r=B.projectionMatrix;L.x=(Math.sign(z.x)+r.elements[8])/r.elements[0],L.y=(Math.sign(z.y)+r.elements[9])/r.elements[5],L.z=-1,L.w=(1+r.elements[10])/r.elements[14],z.multiplyScalar(2/z.dot(L)),r.elements[2]=z.x,r.elements[6]=z.y,r.elements[10]=z.z+1,r.elements[14]=z.w}),[x,p]),[V,I,O,j]=C.useMemo((()=>{const o={minFilter:n.LinearFilter,magFilter:n.LinearFilter,encoding:g.outputEncoding,type:n.HalfFloatType},p=new n.WebGLRenderTarget(r,r,o);p.depthBuffer=!0,p.depthTexture=new n.DepthTexture(r,r),p.depthTexture.format=n.DepthFormat,p.depthTexture.type=n.UnsignedShortType;const h=new n.WebGLRenderTarget(r,r,o);return[p,h,new Ot({gl:g,resolution:r,width:a[0],height:a[1],minDepthThreshold:i,maxDepthThreshold:s,depthScale:l,depthToBlurRatioBias:c}),{mirror:u,textureMatrix:A,mixBlur:e,tDiffuse:p.texture,tDepth:p.depthTexture,tDiffuseBlur:h.texture,hasBlur:w,mixStrength:t,minDepthThreshold:i,maxDepthThreshold:s,depthScale:l,depthToBlurRatioBias:c,distortion:d,distortionMap:f,mixContrast:m,"defines-USE_BLUR":w?"":void 0,"defines-USE_DEPTH":l>0?"":void 0,"defines-USE_DISTORTION":f?"":void 0}]}),[g,a,A,r,u,w,e,t,i,s,l,c,d,f,m]);return o.useFrame((()=>{var e;const t=E.current.parent||(null==(e=E.current)?void 0:e.__r3f.parent);if(!t)return;t.visible=!1;const r=g.xr.enabled,n=g.shadowMap.autoUpdate;U(),g.xr.enabled=!1,g.shadowMap.autoUpdate=!1,g.setRenderTarget(V),g.state.buffers.depth.setMask(!0),g.autoClear||g.clear(),g.render(y,B),w&&O.render(g,V,I),g.xr.enabled=r,g.shadowMap.autoUpdate=n,t.visible=!0,g.setRenderTarget(null)})),C.createElement("meshReflectorMaterialImpl",S.default({attach:"material",key:"key"+j["defines-USE_BLUR"]+j["defines-USE_DEPTH"]+j["defines-USE_DISTORTION"],ref:D.default([E,v])},j,h))})),Gt=he({envMap:null,bounces:3,ior:2.4,correctMips:!0,aberrationStrength:.01,fresnel:0,bvh:new y.MeshBVHUniformStruct,color:new P.Color("white"),resolution:new P.Vector2},"\n #ifndef USE_COLOR\n uniform vec3 color;\n #endif\n varying vec3 vWorldPosition; \n varying vec3 vNormal;\n varying mat4 projectionMatrixInv;\n varying mat4 viewMatrixInv;\n varying vec3 viewDirection;\n varying mat4 vInstanceMatrix;\n varying vec3 vColor;\n \n void main() { \n vec4 transformedNormal = vec4(normal, 0.0);\n vec4 transformedPosition = vec4(position, 1.0);\n #ifdef USE_INSTANCING\n vInstanceMatrix = instanceMatrix;\n transformedNormal = instanceMatrix * transformedNormal;\n transformedPosition = instanceMatrix * transformedPosition;\n #else\n vInstanceMatrix = mat4(1.0);\n #endif\n\n vColor = color;\n #ifdef USE_INSTANCING_COLOR\n vColor *= instanceColor.rgb;\n #endif\n \n projectionMatrixInv = inverse(projectionMatrix);\n viewMatrixInv = inverse(viewMatrix);\n\n vWorldPosition = (modelMatrix * transformedPosition).xyz;\n vNormal = normalize((viewMatrixInv * vec4(normalMatrix * transformedNormal.xyz, 0.0)).xyz);\n viewDirection = normalize(vWorldPosition - cameraPosition);\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * transformedPosition;\n }",`\n #define ENVMAP_TYPE_CUBE_UV\n precision highp isampler2D;\n precision highp usampler2D;\n varying vec3 vWorldPosition;\n varying vec3 vNormal;\n \n #ifdef ENVMAP_TYPE_CUBEM\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n \n uniform float bounces;\n ${y.shaderStructs}\n ${y.shaderIntersectFunction}\n uniform BVH bvh;\n uniform float ior;\n uniform bool correctMips;\n uniform vec2 resolution;\n uniform float fresnel;\n uniform mat4 modelMatrix;\n \n uniform float aberrationStrength;\n varying mat4 projectionMatrixInv;\n varying mat4 viewMatrixInv;\n varying vec3 viewDirection; \n varying mat4 vInstanceMatrix;\n varying vec3 vColor;\n \n float fresnelFunc(vec3 viewDirection, vec3 worldNormal) {\n return pow( 1.0 + dot( viewDirection, worldNormal), 10.0 );\n }\n \n vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 normal, float ior, mat4 modelMatrixInverse) {\n vec3 rayOrigin = ro;\n vec3 rayDirection = rd;\n rayDirection = refract(rayDirection, normal, 1.0 / ior);\n rayOrigin = vWorldPosition + rayDirection * 0.001;\n rayOrigin = (modelMatrixInverse * vec4(rayOrigin, 1.0)).xyz;\n rayDirection = normalize((modelMatrixInverse * vec4(rayDirection, 0.0)).xyz);\n for(float i = 0.0; i < bounces; i++) {\n uvec4 faceIndices = uvec4( 0u );\n vec3 faceNormal = vec3( 0.0, 0.0, 1.0 );\n vec3 barycoord = vec3( 0.0 );\n float side = 1.0;\n float dist = 0.0;\n bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist );\n vec3 hitPos = rayOrigin + rayDirection * max(dist - 0.001, 0.0); \n vec3 tempDir = refract(rayDirection, faceNormal, ior);\n if (length(tempDir) != 0.0) {\n rayDirection = tempDir;\n break;\n }\n rayDirection = reflect(rayDirection, faceNormal);\n rayOrigin = hitPos + rayDirection * 0.01;\n }\n rayDirection = normalize((modelMatrix * vec4(rayDirection, 0.0)).xyz);\n return rayDirection;\n }\n \n #include <common>\n #include <cube_uv_reflection_fragment>\n \n #ifdef ENVMAP_TYPE_CUBEM\n vec4 textureGradient(samplerCube envMap, vec3 rayDirection, vec3 directionCamPerfect) {\n return textureGrad(envMap, rayDirection, dFdx(correctMips ? directionCamPerfect: rayDirection), dFdy(correctMips ? directionCamPerfect: rayDirection));\n }\n #else\n vec4 textureGradient(sampler2D envMap, vec3 rayDirection, vec3 directionCamPerfect) {\n vec2 uvv = equirectUv( rayDirection );\n vec2 smoothUv = equirectUv( directionCamPerfect );\n return textureGrad(envMap, uvv, dFdx(correctMips ? smoothUv : uvv), dFdy(correctMips ? smoothUv : uvv));\n }\n #endif\n \n void main() {\n mat4 modelMatrixInverse = inverse(modelMatrix * vInstanceMatrix);\n vec2 uv = gl_FragCoord.xy / resolution;\n vec3 directionCamPerfect = (projectionMatrixInv * vec4(uv * 2.0 - 1.0, 0.0, 1.0)).xyz;\n directionCamPerfect = (viewMatrixInv * vec4(directionCamPerfect, 0.0)).xyz;\n directionCamPerfect = normalize(directionCamPerfect);\n vec3 normal = vNormal;\n vec3 rayOrigin = cameraPosition;\n vec3 rayDirection = normalize(vWorldPosition - cameraPosition);\n vec3 finalColor;\n #ifdef CHROMATIC_ABERRATIONS\n vec3 rayDirectionG = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), modelMatrixInverse);\n #ifdef FAST_CHROMA \n vec3 rayDirectionR = normalize(rayDirectionG + 1.0 * vec3(aberrationStrength / 2.0));\n vec3 rayDirectionB = normalize(rayDirectionG - 1.0 * vec3(aberrationStrength / 2.0));\n #else\n vec3 rayDirectionR = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 - aberrationStrength), 1.0), modelMatrixInverse);\n vec3 rayDirectionB = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 + aberrationStrength), 1.0), modelMatrixInverse);\n #endif\n float finalColorR = textureGradient(envMap, rayDirectionR, directionCamPerfect).r;\n float finalColorG = textureGradient(envMap, rayDirectionG, directionCamPerfect).g;\n float finalColorB = textureGradient(envMap, rayDirectionB, directionCamPerfect).b;\n finalColor = vec3(finalColorR, finalColorG, finalColorB) * vColor;\n #else\n rayDirection = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), modelMatrixInverse);\n finalColor = textureGradient(envMap, rayDirection, directionCamPerfect).rgb; \n finalColor *= vColor;\n #endif\n float nFresnel = fresnelFunc(viewDirection, normal) * fresnel;\n gl_FragColor = vec4(mix(finalColor, vec3(1.0), nFresnel), 1.0); \n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }`);class Nt extends P.MeshPhysicalMaterial{constructor({samples:e=6,...t}={}){super(t),this.uniforms={chromaticAberration:{value:.05},transmission:{value:0},_transmission:{value:1},transmissionMap:{value:null},thickness:{value:1},thicknessMap:{value:null},attenuationDistance:{value:0},attenuationColor:{value:new P.Color},anisotropy:{value:.1},time:{value:0},distortion:{value:0},distortionScale:{value:.5},temporalDistortion:{value:.5},buffer:{value:null},resolution:{value:new P.Vector2}},this.onBeforeCompile=t=>{t.uniforms={...t.uniforms,...this.uniforms},t.defines.USE_TRANSMISSION="",t.fragmentShader="\n uniform float chromaticAberration;\n uniform vec2 resolution; \n uniform float anisotropy; \n uniform float time;\n uniform float distortion;\n uniform float distortionScale;\n uniform float temporalDistortion;\n uniform sampler2D buffer;\n \n vec3 sat(vec3 rgb, float adjustment) {\n const vec3 W = vec3(0.2125, 0.7154, 0.0721);\n vec3 intensity = vec3(dot(rgb, W));\n return mix(intensity, rgb, adjustment);\n }\n vec3 random3(vec3 c) {\n float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));\n vec3 r;\n r.z = fract(512.0*j);\n j *= .125;\n r.x = fract(512.0*j);\n j *= .125;\n r.y = fract(512.0*j);\n return r-0.5;\n }\n\n float seed = 0.0;\n uint hash( uint x ) {\n x += ( x << 10u );\n x ^= ( x >> 6u );\n x += ( x << 3u );\n x ^= ( x >> 11u );\n x += ( x << 15u );\n return x;\n }\n\n // Compound versions of the hashing algorithm I whipped together.\n uint hash( uvec2 v ) { return hash( v.x ^ hash(v.y) ); }\n uint hash( uvec3 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ); }\n uint hash( uvec4 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ^ hash(v.w) ); }\n\n // Construct a float with half-open range [0:1] using low 23 bits.\n // All zeroes yields 0.0, all ones yields the next smallest representable value below 1.0.\n float floatConstruct( uint m ) {\n const uint ieeeMantissa = 0x007FFFFFu; // binary32 mantissa bitmask\n const uint ieeeOne = 0x3F800000u; // 1.0 in IEEE binary32\n\n m &= ieeeMantissa; // Keep only mantissa bits (fractional part)\n m |= ieeeOne; // Add fractional part to 1.0\n\n float f = uintBitsToFloat( m ); // Range [1:2]\n return f - 1.0; // Range [0:1]\n }\n\n // Pseudo-random value in half-open range [0:1].\n float random( float x ) { return floatConstruct(hash(floatBitsToUint(x))); }\n float random( vec2 v ) { return floatConstruct(hash(floatBitsToUint(v))); }\n float random( vec3 v ) { return floatConstruct(hash(floatBitsToUint(v))); }\n float random( vec4 v ) { return floatConstruct(hash(floatBitsToUint(v))); }\n\n float rand() {\n float result = random(vec3(gl_FragCoord.xy, seed));\n seed += 1.0;\n return result;\n }\n\n const float F3 = 0.3333333;\n const float G3 = 0.1666667;\n\n float snoise(vec3 p) {\n vec3 s = floor(p + dot(p, vec3(F3)));\n vec3 x = p - s + dot(s, vec3(G3));\n vec3 e = step(vec3(0.0), x - x.yzx);\n vec3 i1 = e*(1.0 - e.zxy);\n vec3 i2 = 1.0 - e.zxy*(1.0 - e);\n vec3 x1 = x - i1 + G3;\n vec3 x2 = x - i2 + 2.0*G3;\n vec3 x3 = x - 1.0 + 3.0*G3;\n vec4 w, d;\n w.x = dot(x, x);\n w.y = dot(x1, x1);\n w.z = dot(x2, x2);\n w.w = dot(x3, x3);\n w = max(0.6 - w, 0.0);\n d.x = dot(random3(s), x);\n d.y = dot(random3(s + i1), x1);\n d.z = dot(random3(s + i2), x2);\n d.w = dot(random3(s + 1.0), x3);\n w *= w;\n w *= w;\n d *= w;\n return dot(d, vec4(52.0));\n }\n\n float snoiseFractal(vec3 m) {\n return 0.5333333* snoise(m)\n +0.2666667* snoise(2.0*m)\n +0.1333333* snoise(4.0*m)\n +0.0666667* snoise(8.0*m);\n }\n"+t.fragmentShader,t.fragmentShader=t.fragmentShader.replace("#include <transmission_pars_fragment>","\n #ifdef USE_TRANSMISSION\n // Transmission code is based on glTF-Sampler-Viewer\n // https://github.com/KhronosGroup/glTF-Sample-Viewer\n uniform float _transmission;\n uniform float thickness;\n uniform float attenuationDistance;\n uniform vec3 attenuationColor;\n #ifdef USE_TRANSMISSIONMAP\n uniform sampler2D transmissionMap;\n #endif\n #ifdef USE_THICKNESSMAP\n uniform sampler2D thicknessMap;\n #endif\n uniform vec2 transmissionSamplerSize;\n uniform sampler2D transmissionSamplerMap;\n uniform mat4 modelMatrix;\n uniform mat4 projectionMatrix;\n varying vec3 vWorldPosition;\n vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n // Direction of refracted light.\n vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n // Compute rotation-independant scaling of the model matrix.\n vec3 modelScale;\n modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n // The thickness is specified in local space.\n return normalize( refractionVector ) * thickness * modelScale;\n }\n float applyIorToRoughness( const in float roughness, const in float ior ) {\n // Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and\n // an IOR of 1.5 results in the default amount of microfacet refraction.\n return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n }\n vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n return texture2D(buffer, fragCoord.xy);\n }\n vec3 applyVolumeAttenuation( const in vec3 radiance, const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n if ( isinf( attenuationDistance ) ) {\n // Attenuation distance is +∞, i.e. the transmitted color is not attenuated at all.\n return radiance;\n } else {\n // Compute light attenuation using Beer's law.\n vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); // Beer's law\n return transmittance * radiance;\n }\n }\n vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness,\n const in vec3 attenuationColor, const in float attenuationDistance ) {\n vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n vec3 refractedRayExit = position + transmissionRay;\n // Project refracted vector on the framebuffer, while mapping to normalized device coordinates.\n vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n vec2 refractionCoords = ndcPos.xy / ndcPos.w;\n refractionCoords += 1.0;\n refractionCoords /= 2.0;\n // Sample framebuffer to get pixel the refracted ray hits.\n vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n vec3 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );\n // Get the specular component.\n vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n return vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );\n }\n #endif\n"),t.fragmentShader=t.fragmentShader.replace("#include <transmission_fragment>",`\n vec2 uv = gl_FragCoord.xy / resolution.xy; \n // Improve the refraction to use the world pos\n material.transmission = _transmission;\n material.transmissionAlpha = 1.0;\n material.thickness = thickness;\n material.attenuationDistance = attenuationDistance;\n material.attenuationColor = attenuationColor;\n #ifdef USE_TRANSMISSIONMAP\n material.transmission *= texture2D( transmissionMap, vUv ).r;\n #endif\n #ifdef USE_THICKNESSMAP\n material.thickness *= texture2D( thicknessMap, vUv ).g;\n #endif\n \n vec3 pos = vWorldPosition;\n vec3 v = normalize( cameraPosition - pos );\n vec3 n = inverseTransformDirection( normal, viewMatrix );\n vec3 transmission = vec3(0.0);\n float transmissionR, transmissionB, transmissionG;\n float randomCoords = rand();\n float thickness_smear = thickness * max(pow(roughness, 0.33), anisotropy);\n vec3 distortionNormal = vec3(0.0);\n vec3 temporalOffset = vec3(time, -time, -time) * temporalDistortion;\n if (distortion > 0.0) {\n distortionNormal = distortion * vec3(snoiseFractal(vec3((pos * distortionScale + temporalOffset))), snoiseFractal(vec3(pos.zxy * distortionScale - temporalOffset)), snoiseFractal(vec3(pos.yxz * distortionScale + temporalOffset)));\n }\n for (float i = 0.0; i < ${e}.0; i ++) {\n vec3 sampleNorm = normalize(n + roughness * roughness * 2.0 * normalize(vec3(rand() - 0.5, rand() - 0.5, rand() - 0.5)) * pow(rand(), 0.33) + distortionNormal);\n transmissionR = getIBLVolumeRefraction(\n sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior, material.thickness + thickness_smear * (i + randomCoords) / float(${e}),\n material.attenuationColor, material.attenuationDistance\n ).r;\n transmissionG = getIBLVolumeRefraction(\n sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior * (1.0 + chromaticAberration * (i + randomCoords) / float(${e})) , material.thickness + thickness_smear * (i + randomCoords) / float(${e}),\n material.attenuationColor, material.attenuationDistance\n ).g;\n transmissionB = getIBLVolumeRefraction(\n sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior * (1.0 + 2.0 * chromaticAberration * (i + randomCoords) / float(${e})), material.thickness + thickness_smear * (i + randomCoords) / float(${e}),\n material.attenuationColor, material.attenuationDistance\n ).b;\n transmission.r += transmissionR;\n transmission.g += transmissionG;\n transmission.b += transmissionB;\n }\n transmission /= ${e}.0;\n totalDiffuse = mix( totalDiffuse, transmission.rgb, material.transmission );\n`)},Object.keys(this.uniforms).forEach((e=>Object.defineProperty(this,e,{get:()=>this.uniforms[e].value,set:t=>this.uniforms[e].value=t})))}}const Ht=C.forwardRef((({buffer:e,transmission:t=1,distortionSpeed:r=1,samples:n=10,resolution:a,background:i,...s},l)=>{o.extend({MeshTransmissionMaterial:Nt});const c=C.useRef(null),{size:u,viewport:d}=o.useThree(),m=Ie(a);let f,p,h;return o.useFrame((t=>{e||(h=c.current.__r3f.parent,c.current.time=t.clock.getElapsedTime()*r,h&&(p=h.visible,h.visible=!1,t.gl.setRenderTarget(m),f=t.scene.background,i&&(t.scene.background=i),t.gl.render(t.scene,t.camera),t.scene.background=f,t.gl.setRenderTarget(null),h.visible=p))})),C.useImperativeHandle(l,(()=>c.current),[]),C.createElement("meshTransmissionMaterial",S.default({args:[C.useMemo((()=>({samples:n})),[n])],ref:c},s,{buffer:e||m.texture,_transmission:t,transmission:0,resolution:[u.width*d.dpr,u.height*d.dpr]}))}));class $t extends P.PointsMaterial{constructor(e){super(e),this.onBeforeCompile=(e,t)=>{const{isWebGL2:r}=t.capabilities;e.fragmentShader=e.fragmentShader.replace("#include <output_fragment>",`\n ${r?"#include <output_fragment>":"#extension GL_OES_standard_derivatives : enable\n#include <output_fragment>"}\n vec2 cxy = 2.0 * gl_PointCoord - 1.0;\n float r = dot(cxy, cxy);\n float delta = fwidth(r); \n float mask = 1.0 - smoothstep(1.0 - delta, 1.0 + delta, r);\n gl_FragColor = vec4(gl_FragColor.rgb, mask * gl_FragColor.a );\n `)}}}const qt=C.forwardRef(((e,t)=>{const[r]=C.useState((()=>new $t(null)));return C.createElement("primitive",S.default({},e,{object:r,ref:t,attach:"material"}))})),Xt=({frustum:e=3.75,size:t=.005,near:r=9.5,samples:n=10,rings:o=11}={})=>`#define LIGHT_WORLD_SIZE ${t}\n#define LIGHT_FRUSTUM_WIDTH ${e}\n#define LIGHT_SIZE_UV (LIGHT_WORLD_SIZE / LIGHT_FRUSTUM_WIDTH)\n#define NEAR_PLANE ${r}\n\n#define NUM_SAMPLES ${n}\n#define NUM_RINGS ${o}\n#define BLOCKER_SEARCH_NUM_SAMPLES NUM_SAMPLES\n\nvec2 poissonDisk[NUM_SAMPLES];\n\nvoid initPoissonSamples( const in vec2 randomSeed ) {\n float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/\n float angle = rand( randomSeed ) * PI2;\n float radius = INV_NUM_SAMPLES;\n float radiusStep = radius;\n\n #pragma unroll_loop_start\n for( int i = 0; i < ${n}; i ++ ) {\n poissonDisk[i] = vec2( cos( angle ), sin( angle ) ) * pow( radius, 0.75 );\n radius += radiusStep;\n angle += ANGLE_STEP;\n }\n #pragma unroll_loop_end\n}\n\nfloat penumbraSize( const in float zReceiver, const in float zBlocker ) { // Parallel plane estimation\n return (zReceiver - zBlocker) / zBlocker;\n}\n\nfloat findBlocker( sampler2D shadowMap, const in vec2 uv, const in float zReceiver ) {\n // This uses similar triangles to compute what\n // area of the shadow map we should search\n float searchRadius = LIGHT_SIZE_UV * ( zReceiver - NEAR_PLANE ) / zReceiver;\n float blockerDepthSum = 0.0;\n float shadowMapDepth = 0.0;\n int numBlockers = 0; \n #pragma unroll_loop_start\n for( int i = 0; i < ${n}; i++ ) {\n shadowMapDepth = unpackRGBAToDepth(texture2D(shadowMap, uv + poissonDisk[i] * searchRadius));\n if ( shadowMapDepth < zReceiver ) {\n blockerDepthSum += shadowMapDepth;\n numBlockers ++;\n }\n }\n #pragma unroll_loop_end\n\n if( numBlockers == 0 ) return -1.0;\n return blockerDepthSum / float( numBlockers );\n}\n\nfloat PCF_Filter(sampler2D shadowMap, vec2 uv, float zReceiver, float filterRadius ) {\n float sum = 0.0;\n float depth;\n #pragma unroll_loop_start\n for( int i = 0; i < ${n}; i ++ ) {\n depth = unpackRGBAToDepth( texture2D( shadowMap, uv + poissonDisk[ i ] * filterRadius ) );\n if( zReceiver <= depth ) sum += 1.0;\n }\n #pragma unroll_loop_end\n #pragma unroll_loop_start\n for( int i = 0; i < ${n}; i ++ ) {\n depth = unpackRGBAToDepth( texture2D( shadowMap, uv + -poissonDisk[ i ].yx * filterRadius ) );\n if( zReceiver <= depth ) sum += 1.0;\n }\n #pragma unroll_loop_end\n return sum / ( 2.0 * float( ${n} ) );\n}\n\nfloat PCSS ( sampler2D shadowMap, vec4 coords ) {\n vec2 uv = coords.xy;\n float zReceiver = coords.z; // Assumed to be eye-space z in this code\n\n initPoissonSamples( uv );\n // STEP 1: blocker search\n float avgBlockerDepth = findBlocker( shadowMap, uv, zReceiver );\n\n //There are no occluders so early out (this saves filtering)\n if( avgBlockerDepth == -1.0 ) return 1.0;\n\n // STEP 2: penumbra size\n float penumbraRatio = penumbraSize( zReceiver, avgBlockerDepth );\n float filterRadius = penumbraRatio * LIGHT_SIZE_UV * NEAR_PLANE / zReceiver;\n\n // STEP 3: filtering\n //return avgBlockerDepth;\n return PCF_Filter( shadowMap, uv, zReceiver, filterRadius );\n}`;let Yt=!1;function Zt(e,t,r){t.traverse((t=>{t.material&&(e.properties.remove(t.material),t.material.dispose())})),e.info.programs.length=0,e.compile(t,r)}function Kt(e){const t=e+"Geometry";return C.forwardRef((({args:e,children:r,...n},o)=>C.createElement("mesh",S.default({ref:o},n),C.createElement(t,{attach:"geometry",args:e}),r)))}const Qt=Kt("box"),Jt=Kt("circle"),er=Kt("cone"),tr=Kt("cylinder"),rr=Kt("sphere"),nr=Kt("plane"),or=Kt("tube"),ar=Kt("torus"),ir=Kt("torusKnot"),sr=Kt("tetrahedron"),lr=Kt("ring"),cr=Kt("polyhedron"),ur=Kt("icosahedron"),dr=Kt("octahedron"),mr=Kt("dodecahedron"),fr=Kt("extrude"),pr=Kt("lathe"),hr=Kt("capsule"),vr=1e-5;const gr=C.forwardRef((function({args:[e=1,t=1,r=1]=[],radius:o=.05,steps:a=1,smoothness:i=4,children:s,...l},c){const u=C.useMemo((()=>function(e,t,r){const o=new n.Shape,a=r-vr;return o.absarc(vr,vr,vr,-Math.PI/2,-Math.PI,!0),o.absarc(vr,t-2*a,vr,Math.PI,Math.PI/2,!0),o.absarc(e-2*a,t-2*a,vr,Math.PI/2,0,!0),o.absarc(e-2*a,vr,vr,0,-Math.PI/2,!0),o}(e,t,o)),[e,t,o]),d=C.useMemo((()=>({depth:r-2*o,bevelEnabled:!0,bevelSegments:2*i,steps:a,bevelSize:o-vr,bevelThickness:o,curveSegments:i})),[r,o,i]),m=C.useRef();return C.useLayoutEffect((()=>{m.current&&m.current.center()}),[u,d]),C.createElement("mesh",S.default({ref:c},l),C.createElement("extrudeGeometry",{ref:m,args:[u,d]}),s)}));function xr(){const e=new P.BufferGeometry,t=new Float32Array([-1,-1,3,-1,-1,3]);return e.setAttribute("position",new P.BufferAttribute(t,2)),e}const yr=C.forwardRef((function({children:e,...t},r){const n=C.useMemo(xr,[]);return C.createElement("mesh",S.default({ref:r,geometry:n,frustumCulled:!1},t),e)})),wr=C.forwardRef((function({children:e,disableX:t,disableY:r,disableZ:o,left:a,right:i,top:s,bottom:l,front:c,back:u,onCentered:d,precise:m=!0,...f},p){const h=C.useRef(null),v=C.useRef(null),g=C.useRef(null);return C.useLayoutEffect((()=>{v.current.matrixWorld.identity();const e=(new n.Box3).setFromObject(g.current,m),f=new n.Vector3,p=new n.Sphere,x=e.max.x-e.min.x,y=e.max.y-e.min.y,w=e.max.z-e.min.z;e.getCenter(f),e.getBoundingSphere(p);const E=s?y/2:l?-y/2:0,b=a?-x/2:i?x/2:0,M=c?w/2:u?-w/2:0;v.current.position.set(t?0:-f.x+b,r?0:-f.y+E,o?0:-f.z+M),void 0!==d&&d({parent:h.current.parent,container:h.current,width:x,height:y,depth:w,boundingBox:e,boundingSphere:p,center:f,verticalAlignment:E,horizontalAlignment:b,depthAlignment:M})}),[e]),C.useImperativeHandle(p,(()=>h.current),[]),C.createElement("group",S.default({ref:h},f),C.createElement("group",{ref:v},C.createElement("group",{ref:g},e)))})),Er=e=>e&&e.isOrthographicCamera,br=C.createContext(null);function Mr({children:e,damping:t=6,fit:r,clip:n,observe:a,margin:i=1.2,eps:s=.01,onFit:l}){const c=C.useRef(null),{camera:u,invalidate:d,size:m,controls:f}=o.useThree(),p=f,h=C.useRef(l);function v(e,t){return Math.abs(e.x-t.x)<s&&Math.abs(e.y-t.y)<s&&Math.abs(e.z-t.z)<s}function g(e,t,r,n){e.x=P.MathUtils.damp(e.x,t.x,r,n),e.y=P.MathUtils.damp(e.y,t.y,r,n),e.z=P.MathUtils.damp(e.z,t.z,r,n)}h.current=l;const[x]=C.useState((()=>({animating:!1,focus:new P.Vector3,camera:new P.Vector3,zoom:1}))),[y]=C.useState((()=>({focus:new P.Vector3,camera:new P.Vector3,zoom:1}))),[w]=C.useState((()=>new P.Box3)),E=C.useMemo((()=>{function e(){const e=w.getSize(new P.Vector3),t=w.getCenter(new P.Vector3),r=Math.max(e.x,e.y,e.z),n=Er(u)?4*r:r/(2*Math.atan(Math.PI*u.fov/360)),o=Er(u)?4*r:n/u.aspect,a=i*Math.max(n,o);return{box:w,size:e,center:t,distance:a}}return{getSize:e,refresh(t){if((r=t)&&r.isBox3)w.copy(t);else{const e=t||c.current;e.updateWorldMatrix(!0,!0),w.setFromObject(e)}var r;if(w.isEmpty()){const e=u.position.length()||10;w.setFromCenterAndSize(new P.Vector3,new P.Vector3(e,e,e))}if("OrthographicTrackballControls"===(null==p?void 0:p.constructor.name)){const{distance:t}=e(),r=u.position.clone().sub(p.target).normalize().multiplyScalar(t),n=p.target.clone().add(r);u.position.copy(n)}return this},clip(){const{distance:t}=e();return p&&(p.maxDistance=10*t),u.near=t/100,u.far=100*t,u.updateProjectionMatrix(),p&&p.update(),d(),this},to({position:r,target:n}){x.camera.copy(u.position);const{center:o}=e();return y.camera.set(...r),n?y.focus.set(...n):y.focus.copy(o),t?x.animating=!0:u.position.set(...r),this},fit(){x.camera.copy(u.position),p&&x.focus.copy(p.target);const{center:r,distance:n}=e(),o=r.clone().sub(u.position).normalize().multiplyScalar(n);if(y.camera.copy(r).sub(o),y.focus.copy(r),Er(u)){x.zoom=u.zoom;let e=0,n=0;const o=[new P.Vector3(w.min.x,w.min.y,w.min.z),new P.Vector3(w.min.x,w.max.y,w.min.z),new P.Vector3(w.min.x,w.min.y,w.max.z),new P.Vector3(w.min.x,w.max.y,w.max.z),new P.Vector3(w.max.x,w.max.y,w.max.z),new P.Vector3(w.max.x,w.max.y,w.min.z),new P.Vector3(w.max.x,w.min.y,w.max.z),new P.Vector3(w.max.x,w.min.y,w.min.z)];r.applyMatrix4(u.matrixWorldInverse);for(const t of o)t.applyMatrix4(u.matrixWorldInverse),e=Math.max(e,Math.abs(t.y-r.y)),n=Math.max(n,Math.abs(t.x-r.x));e*=2,n*=2;const a=(u.top-u.bottom)/e,s=(u.right-u.left)/n;y.zoom=Math.min(a,s)/i,t||(u.zoom=y.zoom,u.updateProjectionMatrix())}return t?x.animating=!0:(u.position.copy(y.camera),u.lookAt(y.focus),p&&(p.target.copy(y.focus),p.update())),h.current&&h.current(this.getSize()),d(),this}}}),[w,u,p,i,t,d]);C.useLayoutEffect((()=>{if(p){const e=()=>x.animating=!1;return p.addEventListener("start",e),()=>p.removeEventListener("start",e)}}),[p]);const b=C.useRef(0);return C.useLayoutEffect((()=>{(a||0==b.current++)&&(E.refresh(),r&&E.fit(),n&&E.clip())}),[m,n,r,a,u,p]),o.useFrame(((e,r)=>{if(x.animating){if(g(x.focus,y.focus,t,r),g(x.camera,y.camera,t,r),x.zoom=P.MathUtils.damp(x.zoom,y.zoom,t,r),u.position.copy(x.camera),Er(u)&&(u.zoom=x.zoom,u.updateProjectionMatrix()),p?(p.target.copy(x.focus),p.update()):u.lookAt(x.focus),d(),Er(u)&&!(Math.abs(x.zoom-y.zoom)<s))return;if(!Er(u)&&!v(x.camera,y.camera))return;if(p&&!v(x.focus,y.focus))return;x.animating=!1}})),C.createElement("group",{ref:c},C.createElement(br.Provider,{value:E},e))}function Sr(){return C.useContext(br)}const Cr=C.forwardRef((({intensity:e=1,decay:t,decayRate:r=.65,maxYaw:n=.1,maxPitch:a=.1,maxRoll:i=.1,yawFrequency:s=.1,pitchFrequency:l=.1,rollFrequency:c=.1},d)=>{const m=o.useThree((e=>e.camera)),f=o.useThree((e=>e.controls)),p=C.useRef(e),h=C.useRef(m.rotation.clone()),[v]=C.useState((()=>new u.SimplexNoise)),[g]=C.useState((()=>new u.SimplexNoise)),[x]=C.useState((()=>new u.SimplexNoise)),y=()=>{(p.current<0||p.current>1)&&(p.current=p.current<0?0:1)};return C.useImperativeHandle(d,(()=>({getIntensity:()=>p.current,setIntensity:e=>{p.current=e,y()}})),[]),C.useEffect((()=>{if(f){const e=()=>{h.current=m.rotation.clone()};return f.addEventListener("change",e),e(),()=>{f.removeEventListener("change",e)}}}),[m,f]),o.useFrame(((e,o)=>{const u=Math.pow(p.current,2),d=n*u*v.noise(e.clock.elapsedTime*s,1),f=a*u*g.noise(e.clock.elapsedTime*l,1),w=i*u*x.noise(e.clock.elapsedTime*c,1);m.rotation.set(h.current.x+f,h.current.y+d,h.current.z+w),t&&p.current>0&&(p.current-=r*o,y())})),null})),Tr=C.forwardRef((({children:e,speed:t=1,rotationIntensity:r=1,floatIntensity:n=1,floatingRange:a=[-.1,.1],...i},s)=>{const l=C.useRef(null),c=C.useRef(1e4*Math.random());return o.useFrame((e=>{var o,i;const s=c.current+e.clock.getElapsedTime();l.current.rotation.x=Math.cos(s/4*t)/8*r,l.current.rotation.y=Math.sin(s/4*t)/8*r,l.current.rotation.z=Math.sin(s/4*t)/20*r;let u=Math.sin(s/4*t)/10;u=P.MathUtils.mapLinear(u,-.1,.1,null!==(o=null==a?void 0:a[0])&&void 0!==o?o:-.1,null!==(i=null==a?void 0:a[1])&&void 0!==i?i:.1),l.current.position.y=u*n})),C.createElement("group",i,C.createElement("group",{ref:D.default([l,s])},e))})),Pr={sunset:"venice/venice_sunset_1k.hdr",dawn:"kiara/kiara_1_dawn_1k.hdr",night:"dikhololo/dikhololo_night_1k.hdr",warehouse:"empty-wharehouse/empty_warehouse_01_1k.hdr",forest:"forrest-slope/forest_slope_1k.hdr",apartment:"lebombo/lebombo_1k.hdr",studio:"studio-small-3/studio_small_03_1k.hdr",city:"potsdamer-platz/potsdamer_platz_1k.hdr",park:"rooitou/rooitou_park_1k.hdr",lobby:"st-fagans/st_fagans_interior_1k.hdr"};function Rr(e,t,r,n,o=0){const a=(e=>{return(t=e).current&&t.current.isScene?e.current:e;var t})(t||r),i=a.background,s=a.environment,l=a.backgroundBlurriness||0;return"only"!==e&&(a.environment=n),e&&(a.background=n),e&&void 0!==a.backgroundBlurriness&&(a.backgroundBlurriness=o),()=>{"only"!==e&&(a.environment=s),e&&(a.background=i),e&&void 0!==a.backgroundBlurriness&&(a.backgroundBlurriness=l)}}function Dr({scene:e,background:t=!1,blur:r,map:n}){const a=o.useThree((e=>e.scene));return C.useLayoutEffect((()=>{if(n)return Rr(t,e,a,n,r)}),[a,e,n,t,r]),null}function _r({files:e=["/px.png","/nx.png","/py.png","/ny.png","/pz.png","/nz.png"],path:t="",preset:r,encoding:a,extensions:i}){if(r){if(!(r in Pr))throw new Error("Preset must be one of: "+Object.keys(Pr).join(", "));e=Pr[r],t="https://market-assets.fra1.cdn.digitaloceanspaces.com/market-assets/hdris/"}const s=Array.isArray(e),l=s?n.CubeTextureLoader:u.RGBELoader,c=o.useLoader(l,s?[e]:e,(e=>{e.setPath(t),i&&i(e)})),d=s?c[0]:c;return d.mapping=s?n.CubeReflectionMapping:n.EquirectangularReflectionMapping,d.encoding=(null!=a?a:s)?n.sRGBEncoding:n.LinearEncoding,d}function zr({background:e=!1,scene:t,blur:r,...n}){const a=_r(n),i=o.useThree((e=>e.scene));return C.useLayoutEffect((()=>Rr(e,t,i,a,r)),[a,e,t,i,r]),null}function kr({children:e,near:t=1,far:r=1e3,resolution:a=256,frames:i=1,map:s,background:l=!1,blur:c,scene:u,files:d,path:m,preset:f,extensions:p}){const h=o.useThree((e=>e.gl)),v=o.useThree((e=>e.scene)),g=C.useRef(null),[x]=C.useState((()=>new n.Scene)),y=C.useMemo((()=>{const e=new n.WebGLCubeRenderTarget(a);return e.texture.type=n.HalfFloatType,e}),[a]);C.useLayoutEffect((()=>(1===i&&g.current.update(h,x),Rr(l,u,v,y.texture,c))),[e,x,y.texture,u,v,l,i,h]);let w=1;return o.useFrame((()=>{(i===1/0||w<i)&&(g.current.update(h,x),w++)})),C.createElement(C.Fragment,null,o.createPortal(C.createElement(C.Fragment,null,e,C.createElement("cubeCamera",{ref:g,args:[t,r,y]}),d||f?C.createElement(zr,{background:!0,files:d,preset:f,path:m,extensions:p}):s?C.createElement(Dr,{background:!0,map:s,extensions:p}):null),x))}function Fr(e){var t,r,n,a;const i=_r(e),s=e.map||i;C.useMemo((()=>o.extend({GroundProjectedEnvImpl:u.GroundProjectedEnv})),[]);const l=C.useMemo((()=>[s]),[s]),c=null==(t=e.ground)?void 0:t.height,d=null==(r=e.ground)?void 0:r.radius,m=null!==(n=null==(a=e.ground)?void 0:a.scale)&&void 0!==n?n:1e3;return C.createElement(C.Fragment,null,C.createElement(Dr,S.default({},e,{map:s})),C.createElement("groundProjectedEnvImpl",{args:l,scale:m,height:c,radius:d}))}function Lr(e){return e.ground?C.createElement(Fr,e):e.map?C.createElement(Dr,e):e.children?C.createElement(kr,e):C.createElement(zr,e)}const Ar=C.forwardRef((({scale:e=10,frames:t=1/0,opacity:r=1,width:n=1,height:a=1,blur:i=1,far:s=10,resolution:l=512,smooth:c=!0,color:d="#000000",depthWrite:m=!1,renderOrder:f,...p},h)=>{const v=o.useThree((e=>e.scene)),g=o.useThree((e=>e.gl)),x=C.useRef(null);n*=Array.isArray(e)?e[0]:e||1,a*=Array.isArray(e)?e[1]:e||1;const[y,w,E,b,M,T,R]=C.useMemo((()=>{const e=new P.WebGLRenderTarget(l,l),t=new P.WebGLRenderTarget(l,l);t.texture.generateMipmaps=e.texture.generateMipmaps=!1;const r=new P.PlaneGeometry(n,a).rotateX(Math.PI/2),o=new P.Mesh(r),i=new P.MeshDepthMaterial;i.depthTest=i.depthWrite=!1,i.onBeforeCompile=e=>{e.uniforms={...e.uniforms,ucolor:{value:new P.Color(d)}},e.fragmentShader=e.fragmentShader.replace("void main() {","uniform vec3 ucolor;\n void main() {\n "),e.fragmentShader=e.fragmentShader.replace("vec4( vec3( 1.0 - fragCoordZ ), opacity );","vec4( ucolor * fragCoordZ * 2.0, ( 1.0 - fragCoordZ ) * 1.0 );")};const s=new P.ShaderMaterial(u.HorizontalBlurShader),c=new P.ShaderMaterial(u.VerticalBlurShader);return c.depthTest=s.depthTest=!1,[e,r,i,o,s,c,t]}),[l,n,a,e,d]),D=e=>{b.visible=!0,b.material=M,M.uniforms.tDiffuse.value=y.texture,M.uniforms.h.value=1*e/256,g.setRenderTarget(R),g.render(b,x.current),b.material=T,T.uniforms.tDiffuse.value=R.texture,T.uniforms.v.value=1*e/256,g.setRenderTarget(y),g.render(b,x.current),b.visible=!1};let _=0;return o.useFrame((()=>{if(x.current&&(t===1/0||_<t)){const e=v.background;v.background=null;const t=v.overrideMaterial;v.overrideMaterial=E,g.setRenderTarget(y),g.render(v,x.current),v.overrideMaterial=t,D(i),c&&D(.4*i),g.setRenderTarget(null),v.background=e,_++}})),C.createElement("group",S.default({"rotation-x":Math.PI/2},p,{ref:h}),C.createElement("mesh",{renderOrder:f,geometry:w,scale:[1,-1,1],rotation:[-Math.PI/2,0,0]},C.createElement("meshBasicMaterial",{map:y.texture,"map-encoding":g.outputEncoding,transparent:!0,opacity:r,depthWrite:m})),C.createElement("orthographicCamera",{ref:x,args:[-n/2,n/2,a/2,-a/2,0,s]}))}));const Br=C.createContext(null),Ur=he({color:new P.Color,blend:2,alphaTest:.75,opacity:0,map:null},"varying vec2 vUv;\n void main() {\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);\n vUv = uv;\n }","varying vec2 vUv;\n uniform sampler2D map;\n uniform vec3 color;\n uniform float opacity;\n uniform float alphaTest;\n uniform float blend;\n void main() {\n vec4 sampledDiffuseColor = texture2D(map, vUv);\n gl_FragColor = vec4(color * sampledDiffuseColor.r * blend, max(0.0, (1.0 - (sampledDiffuseColor.r + sampledDiffuseColor.g + sampledDiffuseColor.b) / alphaTest)) * opacity);\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }"),Vr=he({},"void main() { gl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }","void main() { discard; }"),Ir=C.forwardRef((({children:e,temporal:t,frames:r=40,limit:n=1/0,blend:a=20,scale:i=10,opacity:s=1,alphaTest:l=.75,color:c="black",colorBlend:u=2,resolution:d=1024,toneMapped:m=!0,...f},p)=>{o.extend({SoftShadowMaterial:Ur});const h=o.useThree((e=>e.gl)),v=o.useThree((e=>e.scene)),g=o.useThree((e=>e.camera)),x=C.useRef(null),y=C.useRef(null),[w]=C.useState((()=>new jr(h,v,d)));C.useLayoutEffect((()=>{w.configure(x.current)}),[]);const E=C.useMemo((()=>({lights:new Map,temporal:!!t,frames:Math.max(2,r),blend:Math.max(2,r===1/0?a:r),count:0,getMesh:()=>x.current,reset:()=>{w.clear();const e=x.current.material;e.opacity=0,e.alphaTest=0,E.count=0},update:(e=1)=>{const t=x.current.material;E.temporal?(t.opacity=Math.min(s,t.opacity+s/E.blend),t.alphaTest=Math.min(l,t.alphaTest+l/E.blend)):(t.opacity=s,t.alphaTest=l),y.current.visible=!0,w.prepare();for(let t=0;t<e;t++)E.lights.forEach((e=>e.update())),w.update(g,E.blend);y.current.visible=!1,w.finish()}})),[w,g,v,t,r,a,s,l]);return C.useLayoutEffect((()=>{E.reset(),E.temporal||E.frames===1/0||E.update(E.blend)})),C.useImperativeHandle(p,(()=>E),[E]),o.useFrame((()=>{(E.temporal||E.frames===1/0)&&E.count<E.frames&&E.count<n&&(E.update(),E.count++)})),C.createElement("group",f,C.createElement("group",{traverse:()=>null,ref:y},C.createElement(Br.Provider,{value:E},e)),C.createElement("mesh",{receiveShadow:!0,ref:x,scale:i,rotation:[-Math.PI/2,0,0]},C.createElement("planeGeometry",null),C.createElement("softShadowMaterial",{transparent:!0,depthWrite:!1,toneMapped:m,color:c,blend:u,map:w.progressiveLightMap2.texture})))})),Or=C.forwardRef((({castShadow:e=!0,bias:t=.001,mapSize:r=512,size:n=5,near:o=.5,far:a=500,frames:i=1,position:s=[0,0,0],radius:l=1,amount:c=8,intensity:u=1,ambient:d=.5,...m},f)=>{const p=C.useRef(null),h=new P.Vector3(...s).length(),v=C.useContext(Br),g=C.useCallback((()=>{let e;if(p.current)for(let t=0;t<p.current.children.length;t++)if(e=p.current.children[t],Math.random()>d)e.position.set(s[0]+P.MathUtils.randFloatSpread(l),s[1]+P.MathUtils.randFloatSpread(l),s[2]+P.MathUtils.randFloatSpread(l));else{let t=Math.acos(2*Math.random()-1)-Math.PI/2,r=2*Math.PI*Math.random();e.position.set(Math.cos(t)*Math.cos(r)*h,Math.abs(Math.cos(t)*Math.sin(r)*h),Math.sin(t)*h)}}),[l,d,h,...s]),x=C.useMemo((()=>({update:g})),[g]);return C.useImperativeHandle(f,(()=>x),[x]),C.useLayoutEffect((()=>{const e=p.current;return v&&v.lights.set(e.uuid,x),()=>{v.lights.delete(e.uuid)}}),[v,x]),C.createElement("group",S.default({ref:p},m),Array.from({length:c},((i,s)=>C.createElement("directionalLight",{key:s,castShadow:e,"shadow-bias":t,"shadow-mapSize":[r,r],intensity:u/c},C.createElement("orthographicCamera",{attach:"shadow-camera",args:[-n,n,n,-n,o,a]})))))}));class jr{constructor(e,t,r=1024){this.renderer=e,this.res=r,this.scene=t,this.buffer1Active=!1,this.lights=[],this.meshes=[],this.object=null,this.clearColor=new P.Color,this.clearAlpha=0;const n=/(Android|iPad|iPhone|iPod)/g.test(navigator.userAgent)?P.HalfFloatType:P.FloatType;this.progressiveLightMap1=new P.WebGLRenderTarget(this.res,this.res,{type:n,encoding:e.outputEncoding}),this.progressiveLightMap2=new P.WebGLRenderTarget(this.res,this.res,{type:n,encoding:e.outputEncoding}),this.discardMat=new Vr,this.targetMat=new P.MeshLambertMaterial({fog:!1}),this.previousShadowMap={value:this.progressiveLightMap1.texture},this.averagingWindow={value:100},this.targetMat.onBeforeCompile=e=>{e.vertexShader="varying vec2 vUv;\n"+e.vertexShader.slice(0,-1)+"vUv = uv; gl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }";const t=e.fragmentShader.indexOf("void main() {");e.fragmentShader="varying vec2 vUv;\n"+e.fragmentShader.slice(0,t)+"uniform sampler2D previousShadowMap;\n\tuniform float averagingWindow;\n"+e.fragmentShader.slice(t-1,-1)+"\nvec3 texelOld = texture2D(previousShadowMap, vUv).rgb;\n gl_FragColor.rgb = mix(texelOld, gl_FragColor.rgb, 1.0/ averagingWindow);\n }",e.uniforms.previousShadowMap=this.previousShadowMap,e.uniforms.averagingWindow=this.averagingWindow}}clear(){this.renderer.getClearColor(this.clearColor),this.clearAlpha=this.renderer.getClearAlpha(),this.renderer.setClearColor("black",1),this.renderer.setRenderTarget(this.progressiveLightMap1),this.renderer.clear(),this.renderer.setRenderTarget(this.progressiveLightMap2),this.renderer.clear(),this.renderer.setRenderTarget(null),this.renderer.setClearColor(this.clearColor,this.clearAlpha),this.lights=[],this.meshes=[],this.scene.traverse((e=>{!function(e){return!!e.geometry}(e)?function(e){return e.isLight}(e)&&this.lights.push({object:e,intensity:e.intensity}):this.meshes.push({object:e,material:e.material})}))}prepare(){this.lights.forEach((e=>e.object.intensity=0)),this.meshes.forEach((e=>e.object.material=this.discardMat))}finish(){this.lights.forEach((e=>e.object.intensity=e.intensity)),this.meshes.forEach((e=>e.object.material=e.material))}configure(e){this.object=e}update(e,t=100){if(!this.object)return;this.averagingWindow.value=t,this.object.material=this.targetMat;const r=this.buffer1Active?this.progressiveLightMap1:this.progressiveLightMap2,n=this.buffer1Active?this.progressiveLightMap2:this.progressiveLightMap1,o=this.scene.background;this.scene.background=null,this.renderer.setRenderTarget(r),this.previousShadowMap.value=n.texture,this.buffer1Active=!this.buffer1Active,this.renderer.render(this.scene,e),this.renderer.setRenderTarget(null),this.scene.background=o}}const Wr={rembrandt:{main:[1,2,1],fill:[-2,-.5,-2]},portrait:{main:[-1,2,.5],fill:[-1,.5,-1.5]},upfront:{main:[0,2,1],fill:[-1,.5,-1.5]},soft:{main:[-2,4,4],fill:[-1,.5,-1.5]}};function Gr({radius:e,adjustCamera:t}){const r=Sr();return C.useEffect((()=>{t&&r.refresh().clip().fit()}),[e,t]),null}const Nr=e=>0===e?0:Math.pow(2,10*e-10);const Hr=C.forwardRef((({fog:e=!1,renderOrder:t,depthWrite:r=!1,colorStop:o=0,color:a="black",opacity:i=.5,...s},l)=>{const c=C.useMemo((()=>{const e=document.createElement("canvas");e.width=128,e.height=128;const t=e.getContext("2d"),r=t.createRadialGradient(e.width/2,e.height/2,0,e.width/2,e.height/2,e.width/2);return r.addColorStop(o,new n.Color(a).getStyle()),r.addColorStop(1,"rgba(0,0,0,0)"),t.fillStyle=r,t.fillRect(0,0,e.width,e.height),e}),[a,o]);return C.createElement("mesh",S.default({renderOrder:t,ref:l,"rotation-x":-Math.PI/2},s),C.createElement("planeGeometry",null),C.createElement("meshBasicMaterial",{transparent:!0,opacity:i,fog:e,depthWrite:r,side:n.DoubleSide},C.createElement("canvasTexture",{attach:"map",args:[c]})))}));o.extend({MeshReflectorMaterial:jt});const $r=C.forwardRef((({mixBlur:e=0,mixStrength:t=.5,resolution:r=256,blur:a=[0,0],args:i=[1,1],minDepthThreshold:s=.9,maxDepthThreshold:l=1,depthScale:c=0,depthToBlurRatioBias:u=.25,mirror:d=0,children:m,debug:f=0,distortion:p=1,mixContrast:h=1,distortionMap:v,...g},x)=>{C.useEffect((()=>{console.warn("Reflector has been deprecated and will be removed next major. Replace it with <MeshReflectorMaterial />!")}),[]);const y=o.useThree((({gl:e})=>e)),w=o.useThree((({camera:e})=>e)),E=o.useThree((({scene:e})=>e)),b=(a=Array.isArray(a)?a:[a,a])[0]+a[1]>0,M=C.useRef(null),[T]=C.useState((()=>new n.Plane)),[P]=C.useState((()=>new n.Vector3)),[R]=C.useState((()=>new n.Vector3)),[_]=C.useState((()=>new n.Vector3)),[z]=C.useState((()=>new n.Matrix4)),[k]=C.useState((()=>new n.Vector3(0,0,-1))),[F]=C.useState((()=>new n.Vector4)),[L]=C.useState((()=>new n.Vector3)),[A]=C.useState((()=>new n.Vector3)),[B]=C.useState((()=>new n.Vector4)),[U]=C.useState((()=>new n.Matrix4)),[V]=C.useState((()=>new n.PerspectiveCamera)),I=C.useCallback((()=>{if(R.setFromMatrixPosition(M.current.matrixWorld),_.setFromMatrixPosition(w.matrixWorld),z.extractRotation(M.current.matrixWorld),P.set(0,0,1),P.applyMatrix4(z),L.subVectors(R,_),L.dot(P)>0)return;L.reflect(P).negate(),L.add(R),z.extractRotation(w.matrixWorld),k.set(0,0,-1),k.applyMatrix4(z),k.add(_),A.subVectors(R,k),A.reflect(P).negate(),A.add(R),V.position.copy(L),V.up.set(0,1,0),V.up.applyMatrix4(z),V.up.reflect(P),V.lookAt(A),V.far=w.far,V.updateMatrixWorld(),V.projectionMatrix.copy(w.projectionMatrix),U.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),U.multiply(V.projectionMatrix),U.multiply(V.matrixWorldInverse),U.multiply(M.current.matrixWorld),T.setFromNormalAndCoplanarPoint(P,R),T.applyMatrix4(V.matrixWorldInverse),F.set(T.normal.x,T.normal.y,T.normal.z,T.constant);const e=V.projectionMatrix;B.x=(Math.sign(F.x)+e.elements[8])/e.elements[0],B.y=(Math.sign(F.y)+e.elements[9])/e.elements[5],B.z=-1,B.w=(1+e.elements[10])/e.elements[14],F.multiplyScalar(2/F.dot(B)),e.elements[2]=F.x,e.elements[6]=F.y,e.elements[10]=F.z+1,e.elements[14]=F.w}),[]),[O,j,W,G]=C.useMemo((()=>{const o={minFilter:n.LinearFilter,magFilter:n.LinearFilter,encoding:y.outputEncoding},i=new n.WebGLRenderTarget(r,r,o);i.depthBuffer=!0,i.depthTexture=new n.DepthTexture(r,r),i.depthTexture.format=n.DepthFormat,i.depthTexture.type=n.UnsignedShortType;const m=new n.WebGLRenderTarget(r,r,o);return[i,m,new Ot({gl:y,resolution:r,width:a[0],height:a[1],minDepthThreshold:s,maxDepthThreshold:l,depthScale:c,depthToBlurRatioBias:u}),{mirror:d,textureMatrix:U,mixBlur:e,tDiffuse:i.texture,tDepth:i.depthTexture,tDiffuseBlur:m.texture,hasBlur:b,mixStrength:t,minDepthThreshold:s,maxDepthThreshold:l,depthScale:c,depthToBlurRatioBias:u,transparent:!0,debug:f,distortion:p,distortionMap:v,mixContrast:h,"defines-USE_BLUR":b?"":void 0,"defines-USE_DEPTH":c>0?"":void 0,"defines-USE_DISTORTION":v?"":void 0}]}),[y,a,U,r,d,b,e,t,s,l,c,u,f,p,v,h]);return o.useFrame((()=>{if(null==M||!M.current)return;M.current.visible=!1;const e=y.xr.enabled,t=y.shadowMap.autoUpdate;I(),y.xr.enabled=!1,y.shadowMap.autoUpdate=!1,y.setRenderTarget(O),y.state.buffers.depth.setMask(!0),y.autoClear||y.clear(),y.render(E,V),b&&W.render(y,O,j),y.xr.enabled=e,y.shadowMap.autoUpdate=t,M.current.visible=!0,y.setRenderTarget(null)})),C.createElement("mesh",S.default({ref:D.default([M,x])},g),C.createElement("planeGeometry",{args:i}),m?m("meshReflectorMaterial",G):C.createElement("meshReflectorMaterial",G))}));class qr extends n.ShaderMaterial{constructor(){super({uniforms:{depth:{value:null},opacity:{value:1},attenuation:{value:2.5},anglePower:{value:12},spotPosition:{value:new n.Vector3(0,0,0)},lightColor:{value:new n.Color("white")},cameraNear:{value:0},cameraFar:{value:1},resolution:{value:new n.Vector2(0,0)}},transparent:!0,depthWrite:!1,vertexShader:"\n varying vec3 vNormal;\n varying vec3 vWorldPosition;\n varying float vViewZ;\n varying float vIntensity;\n uniform vec3 spotPosition;\n uniform float attenuation; \n\n void main() {\n // compute intensity\n vNormal = normalize( normalMatrix * normal );\n vec4 worldPosition\t= modelMatrix * vec4( position, 1.0 );\n vWorldPosition = worldPosition.xyz;\n vec4 viewPosition = viewMatrix * worldPosition;\n vViewZ = viewPosition.z;\n float intensity\t= distance(worldPosition.xyz, spotPosition) / attenuation;\n intensity\t= 1.0 - clamp(intensity, 0.0, 1.0);\n vIntensity = intensity; \n // set gl_Position\n gl_Position\t= projectionMatrix * viewPosition;\n\n }",fragmentShader:"\n #include <packing>\n\n varying vec3 vNormal;\n varying vec3 vWorldPosition;\n uniform vec3 lightColor;\n uniform vec3 spotPosition;\n uniform float attenuation;\n uniform float anglePower;\n uniform sampler2D depth;\n uniform vec2 resolution;\n uniform float cameraNear;\n uniform float cameraFar;\n varying float vViewZ;\n varying float vIntensity;\n uniform float opacity;\n\n float readDepth( sampler2D depthSampler, vec2 coord ) {\n float fragCoordZ = texture2D( depthSampler, coord ).x;\n float viewZ = perspectiveDepthToViewZ(fragCoordZ, cameraNear, cameraFar);\n return viewZ;\n }\n\n void main() {\n float d = 1.0;\n bool isSoft = resolution[0] > 0.0 && resolution[1] > 0.0;\n if (isSoft) {\n vec2 sUv = gl_FragCoord.xy / resolution;\n d = readDepth(depth, sUv);\n }\n float intensity = vIntensity;\n vec3 normal\t= vec3(vNormal.x, vNormal.y, abs(vNormal.z));\n float angleIntensity\t= pow( dot(normal, vec3(0.0, 0.0, 1.0)), anglePower );\n intensity\t*= angleIntensity;\n // fades when z is close to sampled depth, meaning the cone is intersecting existing geometry\n if (isSoft) {\n intensity\t*= smoothstep(0., 1., vViewZ - d);\n }\n gl_FragColor = vec4(lightColor, intensity * opacity);\n\n #include <tonemapping_fragment>\n\t #include <encodings_fragment>\n }"})}}function Xr({opacity:e=1,radiusTop:t,radiusBottom:r,depthBuffer:a,color:i="white",distance:s=5,angle:l=.15,attenuation:c=5,anglePower:u=5}){const d=C.useRef(null),m=o.useThree((e=>e.size)),f=o.useThree((e=>e.camera)),p=o.useThree((e=>e.viewport.dpr)),[h]=C.useState((()=>new qr)),[v]=C.useState((()=>new n.Vector3));t=void 0===t?.1:t,r=void 0===r?7*l:r,o.useFrame((()=>{h.uniforms.spotPosition.value.copy(d.current.getWorldPosition(v)),d.current.lookAt(d.current.parent.target.getWorldPosition(v))}));const g=C.useMemo((()=>{const e=new n.CylinderGeometry(t,r,s,128,64,!0);return e.applyMatrix4((new n.Matrix4).makeTranslation(0,-s/2,0)),e.applyMatrix4((new n.Matrix4).makeRotationX(-Math.PI/2)),e}),[s,t,r]);return C.createElement(C.Fragment,null,C.createElement("mesh",{ref:d,geometry:g,raycast:()=>null},C.createElement("primitive",{object:h,attach:"material","uniforms-opacity-value":e,"uniforms-lightColor-value":i,"uniforms-attenuation-value":c,"uniforms-anglePower-value":u,"uniforms-depth-value":a,"uniforms-cameraNear-value":f.near,"uniforms-cameraFar-value":f.far,"uniforms-resolution-value":a?[m.width*p,m.height*p]:[0,0]})))}function Yr(e,t,r,a,i){const[[s,l]]=C.useState((()=>[new n.Vector3,new n.Vector3]));C.useLayoutEffect((()=>{if(!(null==(t=e.current)?void 0:t.isSpotLight))throw new Error("SpotlightShadow must be a child of a SpotLight");var t;console.log(e.current),e.current.shadow.mapSize.set(r,a),e.current.shadow.needsUpdate=!0}),[e,r,a]),o.useFrame((()=>{if(!e.current)return;const r=e.current.position,n=e.current.target.position;l.copy(n).sub(r);var o=l.length();l.normalize().multiplyScalar(o*i),s.copy(r).add(l),t.current.position.copy(s),t.current.lookAt(e.current.target.position)}))}function Zr({distance:e=.4,alphaTest:t=.5,map:r,shader:a="#define GLSLIFY 1\nvarying vec2 vUv;uniform sampler2D uShadowMap;uniform float uTime;void main(){vec3 color=texture2D(uShadowMap,vUv).xyz;gl_FragColor=vec4(color,1.);}",width:i=512,height:s=512,scale:l=1,children:c,...d}){const m=C.useRef(null),f=d.spotlightRef,p=d.debug;Yr(f,m,i,s,e);const h=C.useMemo((()=>new n.WebGLRenderTarget(i,s,{format:n.RGBAFormat,encoding:n.LinearEncoding,stencilBuffer:!1})),[i,s]),v=C.useRef({uShadowMap:{value:r},uTime:{value:0}});C.useEffect((()=>{v.current.uShadowMap.value=r}),[r]);const g=C.useMemo((()=>new u.FullScreenQuad(new n.ShaderMaterial({uniforms:v.current,vertexShader:"\n varying vec2 vUv;\n\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:a}))),[a]);return C.useEffect((()=>()=>{g.material.dispose(),g.dispose()}),[g]),C.useEffect((()=>()=>h.dispose()),[h]),o.useFrame((({gl:e},t)=>{v.current.uTime.value+=t,e.setRenderTarget(h),g.render(e),e.setRenderTarget(null)})),C.createElement(C.Fragment,null,C.createElement("mesh",{ref:m,scale:l,castShadow:!0},C.createElement("planeGeometry",null),C.createElement("meshBasicMaterial",{transparent:!0,side:n.DoubleSide,alphaTest:t,alphaMap:h.texture,"alphaMap-wrapS":n.RepeatWrapping,"alphaMap-wrapT":n.RepeatWrapping,opacity:p?1:0},c)))}function Kr({distance:e=.4,alphaTest:t=.5,map:r,width:o=512,height:a=512,scale:i,children:s,...l}){const c=C.useRef(null),u=l.spotlightRef,d=l.debug;return Yr(u,c,o,a,e),C.createElement(C.Fragment,null,C.createElement("mesh",{ref:c,scale:i,castShadow:!0},C.createElement("planeGeometry",null),C.createElement("meshBasicMaterial",{transparent:!0,side:n.DoubleSide,alphaTest:t,alphaMap:r,"alphaMap-wrapS":n.RepeatWrapping,"alphaMap-wrapT":n.RepeatWrapping,opacity:d?1:0},s)))}const Qr=C.forwardRef((({opacity:e=1,radiusTop:t,radiusBottom:r,depthBuffer:n,color:o="white",distance:a=5,angle:i=.15,attenuation:s=5,anglePower:l=5,volumetric:c=!0,debug:u=!1,children:d,...m},f)=>{const p=C.useRef(null);return C.createElement("group",null,u&&p.current&&C.createElement("spotLightHelper",{args:[p.current]}),C.createElement("spotLight",S.default({ref:D.default([f,p]),angle:i,color:o,distance:a,castShadow:!0},m),c&&C.createElement(Xr,{debug:u,opacity:e,radiusTop:t,radiusBottom:r,depthBuffer:n,color:o,distance:a,angle:i,attenuation:s,anglePower:l})),d&&C.cloneElement(d,{spotlightRef:p,debug:u}))})),Jr=C.forwardRef((({args:e,map:t,toneMapped:r=!1,color:n="white",form:a="rect",intensity:i=1,scale:s=1,target:l,children:c,...u},d)=>{const m=C.useRef(null);return C.useLayoutEffect((()=>{c||u.material||(o.applyProps(m.current.material,{color:n}),m.current.material.color.multiplyScalar(i))}),[n,i,c,u.material]),C.useLayoutEffect((()=>{l&&m.current.lookAt(Array.isArray(l)?new P.Vector3(...l):l)}),[l]),s=Array.isArray(s)&&2===s.length?[s[0],s[1],1]:s,C.createElement("mesh",S.default({ref:D.default([m,d]),scale:s},u),"circle"===a?C.createElement("ringGeometry",{args:[0,1,64]}):"ring"===a?C.createElement("ringGeometry",{args:[.5,1,64]}):"rect"===a?C.createElement("planeGeometry",null):C.createElement(a,{args:e}),c||(u.material?null:C.createElement("meshBasicMaterial",{toneMapped:r,map:t,side:P.DoubleSide})))}));function en(e,t,r=new n.Vector3){const o=Math.PI*(e-.5),a=2*Math.PI*(t-.5);return r.x=Math.cos(a),r.y=Math.sin(o),r.z=Math.sin(a),r}const tn=C.forwardRef((({inclination:e=.6,azimuth:t=.1,distance:r=1e3,mieCoefficient:o=.005,mieDirectionalG:a=.8,rayleigh:i=.5,turbidity:s=10,sunPosition:l=en(e,t),...c},d)=>{const m=C.useMemo((()=>(new n.Vector3).setScalar(r)),[r]),[f]=C.useState((()=>new u.Sky));return C.createElement("primitive",S.default({object:f,ref:d,"material-uniforms-mieCoefficient-value":o,"material-uniforms-mieDirectionalG-value":a,"material-uniforms-rayleigh-value":i,"material-uniforms-sunPosition-value":l,"material-uniforms-turbidity-value":s,scale:m},c))}));class rn extends n.ShaderMaterial{constructor(){super({uniforms:{time:{value:0},fade:{value:1}},vertexShader:"\n uniform float time;\n attribute float size;\n varying vec3 vColor;\n void main() {\n vColor = color;\n vec4 mvPosition = modelViewMatrix * vec4(position, 0.5);\n gl_PointSize = size * (30.0 / -mvPosition.z) * (3.0 + sin(time + 100.0));\n gl_Position = projectionMatrix * mvPosition;\n }",fragmentShader:"\n uniform sampler2D pointTexture;\n uniform float fade;\n varying vec3 vColor;\n void main() {\n float opacity = 1.0;\n if (fade == 1.0) {\n float d = distance(gl_PointCoord, vec2(0.5, 0.5));\n opacity = 1.0 / (1.0 + exp(16.0 * (d - 0.25)));\n }\n gl_FragColor = vec4(vColor, opacity);\n\n #include <tonemapping_fragment>\n\t #include <encodings_fragment>\n }"})}}const nn=e=>(new n.Vector3).setFromSpherical(new n.Spherical(e,Math.acos(1-2*Math.random()),2*Math.random()*Math.PI)),on=C.forwardRef((({radius:e=100,depth:t=50,count:r=5e3,saturation:a=0,factor:i=4,fade:s=!1,speed:l=1},c)=>{const u=C.useRef(),[d,m,f]=C.useMemo((()=>{const o=[],s=[],l=Array.from({length:r},(()=>(.5+.5*Math.random())*i)),c=new n.Color;let u=e+t;const d=t/r;for(let e=0;e<r;e++)u-=d*Math.random(),o.push(...nn(u).toArray()),c.setHSL(e/r,a,.9),s.push(c.r,c.g,c.b);return[new Float32Array(o),new Float32Array(s),new Float32Array(l)]}),[r,t,i,e,a]);o.useFrame((e=>u.current&&(u.current.uniforms.time.value=e.clock.getElapsedTime()*l)));const[p]=C.useState((()=>new rn));return C.createElement("points",{ref:c},C.createElement("bufferGeometry",null,C.createElement("bufferAttribute",{attach:"attributes-position",args:[d,3]}),C.createElement("bufferAttribute",{attach:"attributes-color",args:[m,3]}),C.createElement("bufferAttribute",{attach:"attributes-size",args:[f,1]})),C.createElement("primitive",{ref:u,object:p,attach:"material",blending:n.AdditiveBlending,"uniforms-fade-value":s,depthWrite:!1,transparent:!0,vertexColors:!0}))}));const an=he({time:0,pixelRatio:1},"#define GLSLIFY 1\nuniform float pixelRatio;uniform float time;attribute float size;attribute float speed;attribute float opacity;attribute vec3 noise;attribute vec3 color;varying vec3 vColor;varying float vOpacity;void main(){vec4 modelPosition=modelMatrix*vec4(position,1.0);modelPosition.y+=sin(time*speed+modelPosition.x*noise.x*100.0)*0.2;modelPosition.z+=cos(time*speed+modelPosition.x*noise.y*100.0)*0.2;modelPosition.x+=cos(time*speed+modelPosition.x*noise.z*100.0)*0.2;vec4 viewPosition=viewMatrix*modelPosition;vec4 projectionPostion=projectionMatrix*viewPosition;gl_Position=projectionPostion;gl_PointSize=size*25.*pixelRatio;gl_PointSize*=(1.0/-viewPosition.z);vColor=color;vOpacity=opacity;}","#define GLSLIFY 1\nvarying vec3 vColor;varying float vOpacity;void main(){float distanceToCenter=distance(gl_PointCoord,vec2(0.5));float strength=0.05/distanceToCenter-0.1;gl_FragColor=vec4(vColor,strength*vOpacity);}"),sn=e=>e&&e.constructor===Float32Array,ln=e=>e instanceof P.Vector2||e instanceof P.Vector3||e instanceof P.Vector4,cn=e=>Array.isArray(e)?e:ln(e)?e.toArray():[e,e,e];function un(e,t,r){return C.useMemo((()=>{if(void 0!==t){if(sn(t))return t;if(t instanceof P.Color){const r=Array.from({length:3*e},(()=>(e=>[e.r,e.g,e.b])(t))).flat();return Float32Array.from(r)}if(ln(t)||Array.isArray(t)){const r=Array.from({length:3*e},(()=>cn(t))).flat();return Float32Array.from(r)}return Float32Array.from({length:e},(()=>t))}return Float32Array.from({length:e},r)}),[t])}const dn=C.forwardRef((({noise:e=1,count:t=100,speed:r=1,opacity:n=1,scale:a=1,size:i,color:s,...l},c)=>{C.useMemo((()=>o.extend({SparklesMaterial:an})),[]);const u=C.useRef(),d=o.useThree((e=>e.viewport.dpr)),m=C.useMemo((()=>Float32Array.from(Array.from({length:t},(()=>cn(a).map(P.MathUtils.randFloatSpread))).flat())),[t,a]),f=un(t,i,Math.random),p=un(t,n),h=un(t,r),v=un(3*t,e),g=un(void 0===s?3*t:t,sn(s)?s:new P.Color(s),(()=>1));return o.useFrame((e=>u.current.uniforms.time.value=e.clock.elapsedTime)),C.createElement("points",S.default({key:`particle-${t}-${JSON.stringify(a)}`},l,{ref:c}),C.createElement("bufferGeometry",null,C.createElement("bufferAttribute",{attach:"attributes-position",args:[m,3]}),C.createElement("bufferAttribute",{attach:"attributes-size",args:[f,1]}),C.createElement("bufferAttribute",{attach:"attributes-opacity",args:[p,1]}),C.createElement("bufferAttribute",{attach:"attributes-speed",args:[h,1]}),C.createElement("bufferAttribute",{attach:"attributes-color",args:[g,3]}),C.createElement("bufferAttribute",{attach:"attributes-noise",args:[v,3]})),C.createElement("sparklesMaterial",{ref:u,transparent:!0,pixelRatio:d,depthWrite:!1}))}));const mn=new P.Matrix4,fn=new P.Ray,pn=new P.Sphere,hn=new P.Vector3;class vn extends P.Group{constructor(){super(),this.size=0,this.color=new P.Color("white"),this.instance={current:void 0},this.instanceKey={current:void 0}}get geometry(){var e;return null==(e=this.instance.current)?void 0:e.geometry}raycast(e,t){var r,n;const o=this.instance.current;if(!o||!o.geometry)return;const a=o.userData.instances.indexOf(this.instanceKey);if(-1===a||a>o.geometry.drawRange.count)return;const i=null!==(r=null==(n=e.params.Points)?void 0:n.threshold)&&void 0!==r?r:1;if(pn.set(this.getWorldPosition(hn),i),!1===e.ray.intersectsSphere(pn))return;mn.copy(o.matrixWorld).invert(),fn.copy(e.ray).applyMatrix4(mn);const s=i/((this.scale.x+this.scale.y+this.scale.z)/3),l=s*s,c=fn.distanceSqToPoint(hn);if(c<l){const r=new P.Vector3;fn.closestPointToPoint(hn,r),r.applyMatrix4(this.matrixWorld);const n=e.ray.origin.distanceTo(r);if(n<e.near||n>e.far)return;t.push({distance:n,distanceToRay:Math.sqrt(c),point:r,index:a,face:null,object:this})}}}let gn,xn;const yn=C.createContext(null),wn=new P.Matrix4,En=new P.Vector3,bn=C.forwardRef((({children:e,range:t,limit:r=1e3,...n},a)=>{const i=C.useRef(null),[s,l]=C.useState([]),[[c,u,d]]=C.useState((()=>[new Float32Array(3*r),Float32Array.from({length:3*r},(()=>1)),Float32Array.from({length:r},(()=>1))]));C.useEffect((()=>{i.current.geometry.attributes.position.needsUpdate=!0})),o.useFrame((()=>{for(i.current.updateMatrix(),i.current.updateMatrixWorld(),wn.copy(i.current.matrixWorld).invert(),i.current.geometry.drawRange.count=Math.min(r,void 0!==t?t:r,s.length),gn=0;gn<s.length;gn++)xn=s[gn].current,xn.getWorldPosition(En).applyMatrix4(wn),En.toArray(c,3*gn),i.current.geometry.attributes.position.needsUpdate=!0,xn.matrixWorldNeedsUpdate=!0,xn.color.toArray(u,3*gn),i.current.geometry.attributes.color.needsUpdate=!0,d.set([xn.size],gn),i.current.geometry.attributes.size.needsUpdate=!0}));const m=C.useMemo((()=>({getParent:()=>i,subscribe:e=>(l((t=>[...t,e])),()=>l((t=>t.filter((t=>t.current!==e.current)))))})),[]);return C.createElement("points",S.default({userData:{instances:s},matrixAutoUpdate:!1,ref:D.default([a,i]),raycast:()=>null},n),C.createElement("bufferGeometry",null,C.createElement("bufferAttribute",{attach:"attributes-position",count:c.length/3,array:c,itemSize:3,usage:P.DynamicDrawUsage}),C.createElement("bufferAttribute",{attach:"attributes-color",count:u.length/3,array:u,itemSize:3,usage:P.DynamicDrawUsage}),C.createElement("bufferAttribute",{attach:"attributes-size",count:d.length,array:d,itemSize:1,usage:P.DynamicDrawUsage})),C.createElement(yn.Provider,{value:m},e))})),Mn=C.forwardRef((({children:e,...t},r)=>{C.useMemo((()=>o.extend({PositionPoint:vn})),[]);const n=C.useRef(),{subscribe:a,getParent:i}=C.useContext(yn);return C.useLayoutEffect((()=>a(n)),[]),C.createElement("positionPoint",S.default({instance:i(),instanceKey:n,ref:D.default([r,n])},t),e)})),Sn=C.forwardRef((({children:e,positions:t,colors:r,sizes:n,stride:a=3,...i},s)=>{const l=C.useRef(null);return o.useFrame((()=>{const e=l.current.geometry.attributes;e.position.needsUpdate=!0,r&&(e.color.needsUpdate=!0),n&&(e.size.needsUpdate=!0)})),C.createElement("points",S.default({ref:D.default([s,l])},i),C.createElement("bufferGeometry",null,C.createElement("bufferAttribute",{attach:"attributes-position",count:t.length/a,array:t,itemSize:a,usage:P.DynamicDrawUsage}),r&&C.createElement("bufferAttribute",{attach:"attributes-color",count:r.length/a,array:r,itemSize:3,usage:P.DynamicDrawUsage}),n&&C.createElement("bufferAttribute",{attach:"attributes-size",count:n.length/a,array:n,itemSize:1,usage:P.DynamicDrawUsage})),e)})),Cn=C.forwardRef(((e,t)=>e.positions instanceof Float32Array?C.createElement(Sn,S.default({},e,{ref:t})):C.createElement(bn,S.default({},e,{ref:t})))),Tn=new P.Matrix4,Pn=new P.Matrix4,Rn=[],Dn=new P.Mesh;class _n extends P.Group{constructor(){super(),this.color=new P.Color("white"),this.instance={current:void 0},this.instanceKey={current:void 0}}get geometry(){var e;return null==(e=this.instance.current)?void 0:e.geometry}raycast(e,t){const r=this.instance.current;if(!r)return;if(!r.geometry||!r.material)return;Dn.geometry=r.geometry;const n=r.matrixWorld,o=r.userData.instances.indexOf(this.instanceKey);if(!(-1===o||o>r.count)){r.getMatrixAt(o,Tn),Pn.multiplyMatrices(n,Tn),Dn.matrixWorld=Pn,r.material instanceof P.Material?Dn.material.side=r.material.side:Dn.material.side=r.material[0].side,Dn.raycast(e,Rn);for(let e=0,r=Rn.length;e<r;e++){const r=Rn[e];r.instanceId=o,r.object=this,t.push(r)}Rn.length=0}}}const zn=C.createContext(null),kn=new P.Matrix4,Fn=new P.Matrix4,Ln=new P.Matrix4,An=new P.Vector3,Bn=new P.Quaternion,Un=new P.Vector3,Vn=C.forwardRef((({context:e,children:t,...r},n)=>{C.useMemo((()=>o.extend({PositionMesh:_n})),[]);const a=C.useRef(),{subscribe:i,getParent:s}=C.useContext(e||zn);return C.useLayoutEffect((()=>i(a)),[]),C.createElement("positionMesh",S.default({instance:s(),instanceKey:a,ref:D.default([n,a])},r),t)})),In=C.forwardRef((({children:e,range:t,limit:r=1e3,frames:n=1/0,...a},i)=>{const[{context:s,instance:l}]=C.useState((()=>{const e=C.createContext(null);return{context:e,instance:C.forwardRef(((t,r)=>C.createElement(Vn,S.default({context:e},t,{ref:r}))))}})),c=C.useRef(null),[u,d]=C.useState([]),[[m,f]]=C.useState((()=>{const e=new Float32Array(16*r);for(let t=0;t<r;t++)Ln.identity().toArray(e,16*t);return[e,new Float32Array([...new Array(3*r)].map((()=>1)))]}));C.useEffect((()=>{c.current.instanceMatrix.needsUpdate=!0}));let p=0,h=0;o.useFrame((()=>{if(n===1/0||p<n){c.current.updateMatrix(),c.current.updateMatrixWorld(),kn.copy(c.current.matrixWorld).invert(),h=Math.min(r,void 0!==t?t:r,u.length),c.current.count=h,c.current.instanceMatrix.updateRange.count=16*h,c.current.instanceColor.updateRange.count=3*h;for(let e=0;e<u.length;e++){const t=u[e].current;t.matrixWorld.decompose(An,Bn,Un),Fn.compose(An,Bn,Un).premultiply(kn),Fn.toArray(m,16*e),c.current.instanceMatrix.needsUpdate=!0,t.color.toArray(f,3*e),c.current.instanceColor.needsUpdate=!0}p++}}));const v=C.useMemo((()=>({getParent:()=>c,subscribe:e=>(d((t=>[...t,e])),()=>d((t=>t.filter((t=>t.current!==e.current)))))})),[]);return C.createElement("instancedMesh",S.default({userData:{instances:u},matrixAutoUpdate:!1,ref:D.default([i,c]),args:[null,null,0],raycast:()=>null},a),C.createElement("instancedBufferAttribute",{attach:"instanceMatrix",count:m.length/16,array:m,itemSize:16,usage:P.DynamicDrawUsage}),C.createElement("instancedBufferAttribute",{attach:"instanceColor",count:f.length/3,array:f,itemSize:3,usage:P.DynamicDrawUsage}),"function"==typeof e?C.createElement(s.Provider,{value:v},e(l)):C.createElement(zn.Provider,{value:v},e))})),On=C.forwardRef((function({meshes:e,children:t,...r},n){const o=Array.isArray(e);if(!o)for(const t of Object.keys(e))e[t].isMesh||delete e[t];return C.createElement("group",{ref:n},C.createElement(L.default,{components:(o?e:Object.values(e)).map((({geometry:e,material:t})=>C.createElement(In,S.default({key:e.uuid,geometry:e,material:t},r))))},(r=>o?t(...r):t(Object.keys(e).filter((t=>e[t].isMesh)).reduce(((e,t,n)=>({...e,[t]:r[n]})),{})))))})),jn=C.createContext(null),Wn=C.forwardRef(((e,t)=>{C.useMemo((()=>o.extend({SegmentObject:Gn})),[]);const{limit:r=1e3,lineWidth:n=1,children:a,...i}=e,[s,l]=C.useState([]),[c]=C.useState((()=>new u.Line2)),[d]=C.useState((()=>new u.LineMaterial)),[m]=C.useState((()=>new u.LineSegmentsGeometry)),[f]=C.useState((()=>new P.Vector2(512,512))),[p]=C.useState((()=>Array(6*r).fill(0))),[h]=C.useState((()=>Array(6*r).fill(0))),v=C.useMemo((()=>({subscribe:e=>(l((t=>[...t,e])),()=>l((t=>t.filter((t=>t.current!==e.current)))))})),[]);return o.useFrame((()=>{for(let t=0;t<r;t++){var e;const r=null==(e=s[t])?void 0:e.current;r&&(p[6*t+0]=r.start.x,p[6*t+1]=r.start.y,p[6*t+2]=r.start.z,p[6*t+3]=r.end.x,p[6*t+4]=r.end.y,p[6*t+5]=r.end.z,h[6*t+0]=r.color.r,h[6*t+1]=r.color.g,h[6*t+2]=r.color.b,h[6*t+3]=r.color.r,h[6*t+4]=r.color.g,h[6*t+5]=r.color.b)}m.setColors(h),m.setPositions(p),c.computeLineDistances()})),C.createElement("primitive",{object:c,ref:t},C.createElement("primitive",{object:m,attach:"geometry"}),C.createElement("primitive",S.default({object:d,attach:"material",vertexColors:!0,resolution:f,linewidth:n},i)),C.createElement(jn.Provider,{value:v},a))}));class Gn{constructor(){this.color=new P.Color("white"),this.start=new P.Vector3(0,0,0),this.end=new P.Vector3(0,0,0)}}const Nn=e=>e instanceof P.Vector3?e:new P.Vector3(..."number"==typeof e?[e,e,e]:e),Hn=C.forwardRef((({color:e,start:t,end:r},n)=>{const o=C.useContext(jn);if(!o)throw"Segment must used inside Segments component.";const a=C.useRef(null);return C.useLayoutEffect((()=>o.subscribe(a)),[]),C.createElement("segmentObject",{ref:D.default([a,n]),color:e,start:Nn(t),end:Nn(r)})})),$n=C.forwardRef((({children:e,distances:t,...r},n)=>{const a=C.useRef(null);return C.useLayoutEffect((()=>{const{current:e}=a;e.levels.length=0,e.children.forEach(((r,n)=>e.levels.push({object:r,distance:t[n]})))})),o.useFrame((e=>{var t;return null==(t=a.current)?void 0:t.update(e.camera)})),C.createElement("lOD",S.default({ref:D.default([a,n])},r),e)}));const qn=new n.Matrix4,Xn=new n.Ray,Yn=new n.Sphere,Zn=new n.Vector3;const Kn=t.createContext(null);const Qn=C.forwardRef((({children:e,width:t,height:r,samples:n=8,renderPriority:a=0,eventPriority:i=0,frames:s=1/0,...l},c)=>{const{size:u,viewport:d}=o.useThree(),m=Ie((t||u.width)*d.dpr,(r||u.height)*d.dpr,{samples:n}),[f]=C.useState((()=>new P.Scene)),p=C.useCallback(((e,t,r)=>{var n,o;let a=null==(n=m.texture)?void 0:n.__r3f.parent;for(;a&&!(a instanceof P.Object3D);)a=a.__r3f.parent;if(!a)return!1;r.raycaster.camera||r.events.compute(e,r,null==(o=r.previousRoot)?void 0:o.getState());const[i]=r.raycaster.intersectObject(a);if(!i)return!1;const s=i.uv;if(!s)return!1;t.raycaster.setFromCamera(t.pointer.set(2*s.x-1,2*s.y-1),t.camera)}),[]);return C.useImperativeHandle(c,(()=>m.texture),[m]),C.createElement(C.Fragment,null,o.createPortal(C.createElement(Jn,{renderPriority:a,frames:s,fbo:m},e),f,{events:{compute:p,priority:i}}),C.createElement("primitive",S.default({object:m.texture},l)))}));function Jn({frames:e,renderPriority:t,children:r,fbo:n}){let a=0;return o.useFrame((t=>{(e===1/0||a<e)&&(t.gl.setRenderTarget(n),t.gl.render(t.scene,t.camera),t.gl.setRenderTarget(null),a++)}),t),C.createElement(C.Fragment,null,r)}const eo=new P.Color;function to(e){return"top"in e}function ro({canvasSize:e,scene:t,index:r,children:n,frames:a,rect:i,track:s}){const l=o.useThree((e=>e.get)),c=o.useThree((e=>e.camera)),u=o.useThree((e=>e.scene)),d=o.useThree((e=>e.setEvents));let m=0;return o.useFrame((r=>{var o,l;(a===1/0||m<=a)&&(i.current=null==(o=s.current)?void 0:o.getBoundingClientRect(),m++);if(i.current){const{position:{left:o,bottom:a,width:s,height:d},isOffscreen:m}=function(e,t){const{right:r,top:n,left:o,bottom:a,width:i,height:s}=t,l=t.bottom<0||n>e.height||r<0||t.left>e.width;if(to(e)){const t=e.top+e.height-a;return{position:{width:i,height:s,left:o-e.left,top:n,bottom:t,right:r},isOffscreen:l}}return{position:{width:i,height:s,top:n,left:o,bottom:e.height-a,right:r},isOffscreen:l}}(e,i.current),f=s/d;if((l=c)&&l.isOrthographicCamera?c.left===s/-2&&c.right===s/2&&c.top===d/2&&c.bottom===d/-2||(Object.assign(c,{left:s/-2,right:s/2,top:d/2,bottom:d/-2}),c.updateProjectionMatrix()):c.aspect!==f&&(c.aspect=f,c.updateProjectionMatrix()),r.gl.setViewport(o,a,s,d),r.gl.setScissor(o,a,s,d),r.gl.setScissorTest(!0),m)return r.gl.getClearColor(eo),r.gl.setClearColor(eo,r.gl.getClearAlpha()),void r.gl.clear(!0,!0);r.gl.render(n?u:t,c)}}),r),C.useEffect((()=>{const e=l().events.connected;return d({connected:s.current}),()=>d({connected:e})}),[]),C.useEffect((()=>{to(e)||console.warn("Detected @react-three/fiber canvas size does not include position information. <View /> may not work as expected. Upgrade to @react-three/fiber ^8.1.0 for support.\n See https://github.com/pmndrs/drei/issues/944")}),[]),C.createElement(C.Fragment,null,n)}const no=C.createContext(null),oo=new P.Vector3,ao=new P.Vector3,io=new P.Vector3(0,1,0),so=new P.Matrix4,lo=({direction:e,axis:t})=>{const{translation:r,translationLimits:n,annotationsClass:a,depthTest:i,scale:s,lineWidth:l,fixed:c,axisColors:u,hoveredColor:d,displayValues:m,opacity:f,onDragStart:p,onDrag:h,onDragEnd:v,userData:g}=C.useContext(no),x=o.useThree((e=>e.controls)),y=C.useRef(null),w=C.useRef(null),E=C.useRef(null),b=C.useRef(0),[M,S]=C.useState(!1),T=C.useCallback((n=>{m&&(y.current.innerText=`${r.current[t].toFixed(2)}`,y.current.style.display="block"),n.stopPropagation();const o=(new P.Matrix4).extractRotation(w.current.matrixWorld),a=n.point.clone(),i=(new P.Vector3).setFromMatrixPosition(w.current.matrixWorld),s=e.clone().applyMatrix4(o).normalize();E.current={clickPoint:a,dir:s},b.current=r.current[t],p({component:"Arrow",axis:t,origin:i,directions:[s]}),x&&(x.enabled=!1),n.target.setPointerCapture(n.pointerId)}),[e,x,p,r,t]),R=C.useCallback((e=>{if(e.stopPropagation(),M||S(!0),E.current){const{clickPoint:o,dir:a}=E.current,[i,s]=(null==n?void 0:n[t])||[void 0,void 0];let l=((e,t,r,n)=>{const o=t.dot(t),a=t.dot(e)-t.dot(r),i=t.dot(n);return 0===i?-a/o:(oo.copy(n).multiplyScalar(o/i).sub(t),ao.copy(n).multiplyScalar(a/i).add(r).sub(e),-oo.dot(ao)/oo.dot(oo))})(o,a,e.ray.origin,e.ray.direction);void 0!==i&&(l=Math.max(l,i-b.current)),void 0!==s&&(l=Math.min(l,s-b.current)),r.current[t]=b.current+l,m&&(y.current.innerText=`${r.current[t].toFixed(2)}`),so.makeTranslation(a.x*l,a.y*l,a.z*l),h(so)}}),[h,M,r,n,t]),D=C.useCallback((e=>{m&&(y.current.style.display="none"),e.stopPropagation(),E.current=null,v(),x&&(x.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[x,v]),_=C.useCallback((e=>{e.stopPropagation(),S(!1)}),[]),{cylinderLength:z,coneWidth:k,coneLength:F,matrixL:L}=C.useMemo((()=>{const t=c?l/s*1.6:s/20,r=c?.2:s/5,n=c?1-r:s-r,o=(new P.Quaternion).setFromUnitVectors(io,e.clone().normalize());return{cylinderLength:n,coneWidth:t,coneLength:r,matrixL:(new P.Matrix4).makeRotationFromQuaternion(o)}}),[e,s,l,c]),A=M?d:u[t];return C.createElement("group",{ref:w},C.createElement("group",{matrix:L,matrixAutoUpdate:!1,onPointerDown:T,onPointerMove:R,onPointerUp:D,onPointerOut:_},C.createElement(H,{position:[0,-F,0]},C.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:a,ref:y})),C.createElement("mesh",{visible:!1,position:[0,(z+F)/2,0],userData:g},C.createElement("cylinderGeometry",{args:[1.4*k,1.4*k,z+F,8,1]})),C.createElement(ae,{transparent:!0,raycast:()=>null,depthTest:i,points:[0,0,0,0,z,0],lineWidth:l,color:A,opacity:f,polygonOffset:!0,renderOrder:1,polygonOffsetFactor:-10}),C.createElement("mesh",{raycast:()=>null,position:[0,z+F/2,0],renderOrder:500},C.createElement("coneGeometry",{args:[k,F,24,1]}),C.createElement("meshBasicMaterial",{transparent:!0,depthTest:i,color:A,opacity:f,polygonOffset:!0,polygonOffsetFactor:-10}))))},co=new P.Ray,uo=new P.Vector3,mo=new P.Matrix4,fo=({dir1:e,dir2:t,axis:r})=>{const{translation:n,translationLimits:a,annotationsClass:i,depthTest:s,scale:l,lineWidth:c,fixed:u,axisColors:d,hoveredColor:m,displayValues:f,opacity:p,onDragStart:h,onDrag:v,onDragEnd:g,userData:x}=C.useContext(no),y=o.useThree((e=>e.controls)),w=C.useRef(null),E=C.useRef(null),b=C.useRef(null),M=C.useRef(0),S=C.useRef(0),[T,R]=C.useState(!1),D=C.useCallback((e=>{f&&(w.current.innerText=`${n.current[(r+1)%3].toFixed(2)}, ${n.current[(r+2)%3].toFixed(2)}`,w.current.style.display="block"),e.stopPropagation();const t=e.point.clone(),o=(new P.Vector3).setFromMatrixPosition(E.current.matrixWorld),a=(new P.Vector3).setFromMatrixColumn(E.current.matrixWorld,0).normalize(),i=(new P.Vector3).setFromMatrixColumn(E.current.matrixWorld,1).normalize(),s=(new P.Vector3).setFromMatrixColumn(E.current.matrixWorld,2).normalize(),l=(new P.Plane).setFromNormalAndCoplanarPoint(s,o);b.current={clickPoint:t,e1:a,e2:i,plane:l},M.current=n.current[(r+1)%3],S.current=n.current[(r+2)%3],h({component:"Slider",axis:r,origin:o,directions:[a,i,s]}),y&&(y.enabled=!1),e.target.setPointerCapture(e.pointerId)}),[y,h,r]),_=C.useCallback((e=>{if(e.stopPropagation(),T||R(!0),b.current){const{clickPoint:t,e1:o,e2:i,plane:s}=b.current,[l,c]=(null==a?void 0:a[(r+1)%3])||[void 0,void 0],[u,d]=(null==a?void 0:a[(r+2)%3])||[void 0,void 0];co.copy(e.ray),co.intersectPlane(s,uo),co.direction.negate(),co.intersectPlane(s,uo),uo.sub(t);let[m,p]=((e,t,r)=>{const n=Math.abs(e.x)>=Math.abs(e.y)&&Math.abs(e.x)>=Math.abs(e.z)?0:Math.abs(e.y)>=Math.abs(e.x)&&Math.abs(e.y)>=Math.abs(e.z)?1:2,o=[0,1,2].sort(((e,r)=>Math.abs(t.getComponent(r))-Math.abs(t.getComponent(e)))),a=n===o[0]?o[1]:o[0],i=e.getComponent(n),s=e.getComponent(a),l=t.getComponent(n),c=t.getComponent(a),u=r.getComponent(n),d=(r.getComponent(a)-u*(s/i))/(c-l*(s/i));return[(u-d*l)/i,d]})(o,i,uo);void 0!==l&&(m=Math.max(m,l-M.current)),void 0!==c&&(m=Math.min(m,c-M.current)),void 0!==u&&(p=Math.max(p,u-S.current)),void 0!==d&&(p=Math.min(p,d-S.current)),n.current[(r+1)%3]=M.current+m,n.current[(r+2)%3]=S.current+p,f&&(w.current.innerText=`${n.current[(r+1)%3].toFixed(2)}, ${n.current[(r+2)%3].toFixed(2)}`),mo.makeTranslation(m*o.x+p*i.x,m*o.y+p*i.y,m*o.z+p*i.z),v(mo)}}),[v,T,n,a,r]),z=C.useCallback((e=>{f&&(w.current.style.display="none"),e.stopPropagation(),b.current=null,g(),y&&(y.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[y,g]),k=C.useCallback((e=>{e.stopPropagation(),R(!1)}),[]),F=C.useMemo((()=>{const r=e.clone().normalize(),n=t.clone().normalize();return(new P.Matrix4).makeBasis(r,n,r.clone().cross(n))}),[e,t]),L=u?1/7:l/7,A=u?.225:.225*l,B=T?m:d[r],U=C.useMemo((()=>[new P.Vector3(0,0,0),new P.Vector3(0,A,0),new P.Vector3(A,A,0),new P.Vector3(A,0,0),new P.Vector3(0,0,0)]),[A]);return C.createElement("group",{ref:E,matrix:F,matrixAutoUpdate:!1},C.createElement(H,{position:[0,0,0]},C.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:i,ref:w})),C.createElement("group",{position:[1.7*L,1.7*L,0]},C.createElement("mesh",{visible:!0,onPointerDown:D,onPointerMove:_,onPointerUp:z,onPointerOut:k,scale:A,userData:x},C.createElement("planeGeometry",null),C.createElement("meshBasicMaterial",{transparent:!0,depthTest:s,color:B,polygonOffset:!0,polygonOffsetFactor:-10,side:P.DoubleSide})),C.createElement(ae,{position:[-A/2,-A/2,0],transparent:!0,depthTest:s,points:U,lineWidth:c,color:B,opacity:p,polygonOffset:!0,polygonOffsetFactor:-10,userData:x})))},po=new P.Vector3,ho=new P.Vector3,vo=e=>180*e/Math.PI,go=e=>{let t=((e,t)=>{let r=Math.floor(e/t);return r=r<0?r+1:r,e-r*t})(e,2*Math.PI);return Math.abs(t)<1e-6?0:(t<0&&(t+=2*Math.PI),t)},xo=new P.Matrix4,yo=new P.Vector3,wo=new P.Ray,Eo=new P.Vector3,bo=({dir1:e,dir2:t,axis:r})=>{const{rotationLimits:n,annotationsClass:a,depthTest:i,scale:s,lineWidth:l,fixed:c,axisColors:u,hoveredColor:d,displayValues:m,opacity:f,onDragStart:p,onDrag:h,onDragEnd:v,userData:g}=C.useContext(no),x=o.useThree((e=>e.controls)),y=C.useRef(null),w=C.useRef(null),E=C.useRef(0),b=C.useRef(0),M=C.useRef(null),[S,T]=C.useState(!1),R=C.useCallback((e=>{m&&(y.current.innerText=`${vo(b.current).toFixed(0)}º`,y.current.style.display="block"),e.stopPropagation();const t=e.point.clone(),n=(new P.Vector3).setFromMatrixPosition(w.current.matrixWorld),o=(new P.Vector3).setFromMatrixColumn(w.current.matrixWorld,0).normalize(),a=(new P.Vector3).setFromMatrixColumn(w.current.matrixWorld,1).normalize(),i=(new P.Vector3).setFromMatrixColumn(w.current.matrixWorld,2).normalize(),s=(new P.Plane).setFromNormalAndCoplanarPoint(i,n);M.current={clickPoint:t,origin:n,e1:o,e2:a,normal:i,plane:s},p({component:"Rotator",axis:r,origin:n,directions:[o,a,i]}),x&&(x.enabled=!1),e.target.setPointerCapture(e.pointerId)}),[x,p,r]),D=C.useCallback((e=>{if(e.stopPropagation(),S||T(!0),M.current){const{clickPoint:t,origin:o,e1:a,e2:i,normal:s,plane:l}=M.current,[c,u]=(null==n?void 0:n[r])||[void 0,void 0];wo.copy(e.ray),wo.intersectPlane(l,Eo),wo.direction.negate(),wo.intersectPlane(l,Eo);let d=((e,t,r,n,o)=>{po.copy(e).sub(r),ho.copy(t).sub(r);const a=n.dot(n),i=o.dot(o),s=po.dot(n)/a,l=po.dot(o)/i,c=ho.dot(n)/a,u=ho.dot(o)/i,d=Math.atan2(l,s);return Math.atan2(u,c)-d})(t,Eo,o,a,i),f=vo(d);e.shiftKey&&(f=10*Math.round(f/10),d=(e=>e*Math.PI/180)(f)),void 0!==c&&void 0!==u&&u-c<2*Math.PI?(d=go(d),d=d>Math.PI?d-2*Math.PI:d,d=A.default(d,c-E.current,u-E.current),b.current=E.current+d):(b.current=go(E.current+d),b.current=b.current>Math.PI?b.current-2*Math.PI:b.current),m&&(f=vo(b.current),y.current.innerText=`${f.toFixed(0)}º`),xo.makeRotationAxis(s,d),yo.copy(o).applyMatrix4(xo).sub(o).negate(),xo.setPosition(yo),h(xo)}}),[h,S,n,r]),_=C.useCallback((e=>{m&&(y.current.style.display="none"),e.stopPropagation(),E.current=b.current,M.current=null,v(),x&&(x.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[x,v]),z=C.useCallback((e=>{e.stopPropagation(),T(!1)}),[]),k=C.useMemo((()=>{const r=e.clone().normalize(),n=t.clone().normalize();return(new P.Matrix4).makeBasis(r,n,r.clone().cross(n))}),[e,t]),F=c?.65:.65*s,L=C.useMemo((()=>{const e=[];for(let t=0;t<=32;t++){const r=t*(Math.PI/2)/32;e.push(new P.Vector3(Math.cos(r)*F,Math.sin(r)*F,0))}return e}),[F]);return C.createElement("group",{ref:w,onPointerDown:R,onPointerMove:D,onPointerUp:_,onPointerOut:z,matrix:k,matrixAutoUpdate:!1},C.createElement(H,{position:[F,F,0]},C.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:a,ref:y})),C.createElement(ae,{points:L,lineWidth:4*l,visible:!1,userData:g}),C.createElement(ae,{transparent:!0,raycast:()=>null,depthTest:i,points:L,lineWidth:l,color:S?d:u[r],opacity:f,polygonOffset:!0,polygonOffsetFactor:-10}))},Mo=new P.Vector3,So=new P.Vector3,Co=new P.Vector3,To=(e,t,r,n=1)=>{const o=Mo.set(e.x/r.width*2-1,-e.y/r.height*2+1,n);return o.unproject(t),o},Po=(e,t,r,n)=>{const o=((e,t,r)=>{const n=r.width/2,o=r.height/2;t.updateMatrixWorld(!1);const a=e.project(t);return a.x=a.x*n+n,a.y=-a.y*o+o,a})(Co.copy(e),r,n);let a=0;for(let i=0;i<2;++i){const s=So.copy(o).setComponent(i,o.getComponent(i)+t),l=To(s,r,n,s.z);a=Math.max(a,e.distanceTo(l))}return a},Ro=new P.Matrix4,Do=new P.Matrix4,_o=new P.Matrix4,zo=new P.Matrix4,ko=new P.Matrix4,Fo=new P.Matrix4,Lo=new P.Matrix4,Ao=new P.Matrix4,Bo=new P.Box3,Uo=new P.Box3,Vo=new P.Vector3,Io=new P.Vector3,Oo=new P.Vector3,jo=new P.Vector3,Wo=new P.Vector3(1,0,0),Go=new P.Vector3(0,1,0),No=new P.Vector3(0,0,1),Ho=C.forwardRef((({matrix:e,onDragStart:t,onDrag:r,onDragEnd:n,autoTransform:a=!0,anchor:i,disableAxes:s=!1,disableSliders:l=!1,disableRotations:c=!1,activeAxes:u=[!0,!0,!0],offset:d=[0,0,0],rotation:m=[0,0,0],scale:f=1,lineWidth:p=4,fixed:h=!1,translationLimits:v,rotationLimits:g,depthTest:x=!0,axisColors:y=["#ff2060","#20df80","#2080ff"],hoveredColor:w="#ffff40",displayValues:E=!0,annotationsClass:b,opacity:M=1,visible:S=!0,userData:T,children:R},D)=>{const _=o.useThree((e=>e.invalidate)),z=C.useRef(null),k=C.useRef(null),F=C.useRef(null),L=C.useRef(null),A=C.useRef([0,0,0]);C.useLayoutEffect((()=>{i&&(L.current.updateWorldMatrix(!0,!0),zo.copy(L.current.matrixWorld).invert(),Bo.makeEmpty(),L.current.traverse((e=>{e.geometry&&(e.geometry.boundingBox||e.geometry.computeBoundingBox(),Fo.copy(e.matrixWorld).premultiply(zo),Uo.copy(e.geometry.boundingBox),Uo.applyMatrix4(Fo),Bo.union(Uo))})),Vo.copy(Bo.max).add(Bo.min).multiplyScalar(.5),Io.copy(Bo.max).sub(Bo.min).multiplyScalar(.5),Oo.copy(Io).multiply(new P.Vector3(...i)).add(Vo),jo.set(...d).add(Oo),F.current.position.copy(jo),_())}));const B=C.useMemo((()=>({onDragStart:e=>{Ro.copy(k.current.matrix),Do.copy(k.current.matrixWorld),t&&t(e),_()},onDrag:e=>{_o.copy(z.current.matrixWorld),zo.copy(_o).invert(),ko.copy(Do).premultiply(e),Fo.copy(ko).premultiply(zo),Lo.copy(Ro).invert(),Ao.copy(Fo).multiply(Lo),a&&k.current.matrix.copy(Fo),r&&r(Fo,Ao,ko,e),_()},onDragEnd:()=>{n&&n(),_()},translation:A,translationLimits:v,rotationLimits:g,axisColors:y,hoveredColor:w,opacity:M,scale:f,lineWidth:p,fixed:h,displayValues:E,depthTest:x,userData:T,annotationsClass:b})),[t,r,n,A,v,g,x,f,p,h,...y,w,M,E,T,a,b]),U=new P.Vector3;return o.useFrame((e=>{if(h){const o=Po(F.current.getWorldPosition(U),f,e.camera,e.size);var t,r,n;if(F.current)(null==(t=F.current)?void 0:t.scale.x)===o&&(null==(r=F.current)?void 0:r.scale.y)===o&&(null==(n=F.current)?void 0:n.scale.z)===o||(F.current.scale.setScalar(o),e.invalidate())}})),C.useImperativeHandle(D,(()=>k.current),[]),C.createElement(no.Provider,{value:B},C.createElement("group",{ref:z},C.createElement("group",{ref:k,matrix:e,matrixAutoUpdate:!1},C.createElement("group",{visible:S,ref:F,position:d,rotation:m},!s&&u[0]&&C.createElement(lo,{axis:0,direction:Wo}),!s&&u[1]&&C.createElement(lo,{axis:1,direction:Go}),!s&&u[2]&&C.createElement(lo,{axis:2,direction:No}),!l&&u[0]&&u[1]&&C.createElement(fo,{axis:2,dir1:Wo,dir2:Go}),!l&&u[0]&&u[2]&&C.createElement(fo,{axis:1,dir1:No,dir2:Wo}),!l&&u[2]&&u[1]&&C.createElement(fo,{axis:0,dir1:Go,dir2:No}),!c&&u[0]&&u[1]&&C.createElement(bo,{axis:2,dir1:Wo,dir2:Go}),!c&&u[0]&&u[2]&&C.createElement(bo,{axis:1,dir1:No,dir2:Wo}),!c&&u[2]&&u[1]&&C.createElement(bo,{axis:0,dir1:Go,dir2:No})),C.createElement("group",{ref:L},R))))}));exports.AccumulativeShadows=Ir,exports.AdaptiveDpr=function({pixelated:e}){const t=o.useThree((e=>e.gl)),r=o.useThree((e=>e.internal.active)),n=o.useThree((e=>e.performance.current)),a=o.useThree((e=>e.viewport.initialDpr)),i=o.useThree((e=>e.setDpr));return C.useEffect((()=>{const n=t.domElement;return()=>{r&&i(a),e&&n&&(n.style.imageRendering="auto")}}),[]),C.useEffect((()=>{i(n*a),e&&t.domElement&&(t.domElement.style.imageRendering=1===n?"auto":"pixelated")}),[n]),null},exports.AdaptiveEvents=function(){const e=o.useThree((e=>e.get)),t=o.useThree((e=>e.setEvents)),r=o.useThree((e=>e.performance.current));return C.useEffect((()=>{const r=e().events.enabled;return()=>t({enabled:r})}),[]),C.useEffect((()=>t({enabled:1===r})),[r]),null},exports.ArcballControls=qe,exports.AsciiRenderer=function({renderIndex:e=1,bgColor:t="black",fgColor:r="white",characters:n=" .:-+*=%@#",invert:a=!0,color:i=!1,resolution:s=.15}){const{size:l,gl:c,scene:d,camera:m}=o.useThree(),f=C.useMemo((()=>{const e=new u.AsciiEffect(c,n,{invert:a,color:i,resolution:s});return e.domElement.style.position="absolute",e.domElement.style.top="0px",e.domElement.style.left="0px",e.domElement.style.pointerEvents="none",e}),[n,a,i,s]);C.useLayoutEffect((()=>{f.domElement.style.color=r,f.domElement.style.backgroundColor=t}),[r,t]),C.useEffect((()=>(c.domElement.style.opacity="0",c.domElement.parentNode.appendChild(f.domElement),()=>{c.domElement.style.opacity="1",c.domElement.parentNode.removeChild(f.domElement)})),[f]),C.useEffect((()=>{f.setSize(l.width,l.height)}),[f,l]),o.useFrame((e=>{f.render(d,m)}),e)},exports.BBAnchor=({anchor:e,...t})=>{const r=C.useRef(null),n=C.useRef(null);return C.useEffect((()=>{var e,t;null!=(e=r.current)&&null!=(t=e.parent)&&t.parent&&(n.current=r.current.parent,r.current.parent.parent.add(r.current))}),[]),o.useFrame((()=>{n.current&&(_t.setFromObject(n.current),_t.getSize(zt),r.current.position.set(n.current.position.x+zt.x*e[0]/2,n.current.position.y+zt.y*e[1]/2,n.current.position.z+zt.z*e[2]/2))})),C.createElement("group",S.default({ref:r},t))},exports.Backdrop=function({children:e,floor:t=.25,segments:r=20,receiveShadow:n,...o}){const a=C.useRef(null);return C.useLayoutEffect((()=>{let e=0;const n=r/r/2,o=a.current.attributes.position;for(let a=0;a<r+1;a++)for(let i=0;i<r+1;i++)o.setXYZ(e++,a/r-n+(0===a?-t:0),i/r-n,Nr(a/r));o.needsUpdate=!0,a.current.computeVertexNormals()}),[r,t]),C.createElement("group",o,C.createElement("mesh",{receiveShadow:n,rotation:[-Math.PI/2,0,Math.PI/2]},C.createElement("planeGeometry",{ref:a,args:[1,1,r,r]}),e))},exports.BakeShadows=function(){const e=o.useThree((e=>e.gl));return t.useEffect((()=>(e.shadowMap.autoUpdate=!1,e.shadowMap.needsUpdate=!0,()=>{e.shadowMap.autoUpdate=e.shadowMap.needsUpdate=!0})),[e.shadowMap]),null},exports.Billboard=ne,exports.Bounds=Mr,exports.Box=Qt,exports.CameraShake=Cr,exports.Capsule=hr,exports.CatmullRomLine=ce,exports.Center=wr,exports.Circle=Jt,exports.Clone=Re,exports.Cloud=function({opacity:e=.5,speed:t=.4,width:r=10,depth:n=1.5,segments:a=20,texture:i="https://rawcdn.githack.com/pmndrs/drei-assets/9225a9f1fbd449d9411125c2f419b843d0308c9f/cloud.png",color:s="#ffffff",depthTest:l=!0,...c}){const u=o.useThree((e=>e.gl)),d=C.useRef(),m=ge(i),f=C.useMemo((()=>[...new Array(a)].map(((e,n)=>({x:r/2-Math.random()*r,y:r/2-Math.random()*r,scale:.4+Math.sin((n+1)/a*Math.PI)*(10*(.2+Math.random())),density:Math.max(.2,Math.random()),rotation:Math.max(.002,.005*Math.random())*t})))),[r,a,t]);return o.useFrame((e=>{var t;return null==(t=d.current)?void 0:t.children.forEach(((t,r)=>{t.children[0].rotation.z+=f[r].rotation,t.children[0].scale.setScalar(f[r].scale+(1+Math.sin(e.clock.getElapsedTime()/10))/2*r/10)}))})),C.createElement("group",c,C.createElement("group",{position:[0,0,a/2*n],ref:d},f.map((({x:t,y:r,scale:o,density:a},i)=>C.createElement(ne,{key:i,position:[t,r,-i*n]},C.createElement(nr,{scale:o,rotation:[0,0,0]},C.createElement("meshStandardMaterial",{map:m,"map-encoding":u.outputEncoding,transparent:!0,opacity:o/6*a*e,depthTest:l,color:s})))))))},exports.ComputedAttribute=({compute:e,name:t,...r})=>{const[o]=C.useState((()=>new n.BufferAttribute(new Float32Array(0),1))),a=C.useRef(null);return C.useLayoutEffect((()=>{if(a.current){var t;const r=null!==(t=a.current.parent)&&void 0!==t?t:a.current.__r3f.parent,n=e(r);a.current.copy(n)}}),[e]),C.createElement("primitive",S.default({ref:a,object:o,attach:`attributes-${t}`},r))},exports.Cone=er,exports.ContactShadows=Ar,exports.CubeCamera=function({children:e,fog:t,frames:r=1/0,resolution:a=256,near:i=.1,far:s=1e3,envMap:l,...c}){const u=C.useRef(),[d,m]=C.useState(null),f=o.useThree((({scene:e})=>e)),p=o.useThree((({gl:e})=>e)),h=C.useMemo((()=>{const e=new n.WebGLCubeRenderTarget(a);return e.texture.encoding=p.outputEncoding,e.texture.type=n.HalfFloatType,e}),[a]);let v,g,x=0;return o.useFrame((()=>{d&&u.current&&(r===1/0||x<r)&&(u.current.visible=!1,v=f.fog,g=f.background,f.background=l||g,f.fog=t||v,d.update(p,f),f.fog=v,f.background=g,u.current.visible=!0,x++)})),C.createElement("group",c,C.createElement("cubeCamera",{ref:m,args:[i,s,h]}),C.createElement("group",{ref:u},e(h.texture)))},exports.CubicBezierLine=le,exports.CurveModifier=Lt,exports.CycleRaycast=function({onChanged:e,portal:t,preventDefault:r=!0,scroll:n=!0,keyCode:a=9}){const i=C.useRef(0),s=o.useThree((e=>e.setEvents)),l=o.useThree((e=>e.get)),c=o.useThree((e=>e.gl));return C.useEffect((()=>{var o;let u,d=[];const m=l().events.filter,f=null!==(o=null==t?void 0:t.current)&&void 0!==o?o:c.domElement.parentNode,p=()=>f&&e&&e(d,Math.round(i.current)%d.length);s({filter:(e,t)=>{let r=[...e];r.length===d.length&&d.every((e=>r.map((e=>e.object.uuid)).includes(e.object.uuid)))||(i.current=0,d=r,p()),m&&(r=m(r,t));for(let e=0;e<Math.round(i.current)%r.length;e++){const e=r.shift();r=[...r,e]}return r}});const h=e=>{var t,r;i.current=e(i.current),null==(t=l().events.handlers)||t.onPointerCancel(void 0),null==(r=l().events.handlers)||r.onPointerMove(u),p()},v=e=>{(e.keyCode||e.which===a)&&(r&&e.preventDefault(),d.length>1&&h((e=>e+1)))},g=e=>{r&&e.preventDefault();let t=0;e||(e=window.event),e.wheelDelta?t=e.wheelDelta/120:e.detail&&(t=-e.detail/3),d.length>1&&h((e=>Math.abs(e-t)))},x=e=>u=e;return document.addEventListener("pointermove",x,{passive:!0}),n&&document.addEventListener("wheel",g),void 0!==a&&document.addEventListener("keydown",v),()=>{s({filter:m}),void 0!==a&&document.removeEventListener("keydown",v),n&&document.removeEventListener("wheel",g),document.removeEventListener("pointermove",x)}}),[c,l,s,r,n,a]),null},exports.Cylinder=tr,exports.Decal=function({debug:e,mesh:t,children:r,position:n,rotation:a,scale:i,...s}){const l=C.useRef(null),c=C.useRef(null);return C.useLayoutEffect((()=>{const e=(null==t?void 0:t.current)||l.current.parent,r=l.current;if(!(e instanceof P.Mesh))throw new Error('Decal must have a Mesh as parent or specify its "mesh" prop');const s={position:new P.Vector3,rotation:new P.Euler,scale:new P.Vector3(1,1,1)};if(e){o.applyProps(s,{position:n,scale:i});const t=e.matrixWorld.clone();if(e.matrixWorld.identity(),a&&"number"!=typeof a)o.applyProps(s,{rotation:a});else{const t=new P.Object3D;t.position.copy(s.position),t.lookAt(e.position),"number"==typeof a&&t.rotateZ(a),o.applyProps(s,{rotation:t.rotation})}return r.geometry=new u.DecalGeometry(e,s.position,s.rotation,s.scale),c.current&&o.applyProps(c.current,s),e.matrixWorld=t,()=>{r.geometry.dispose()}}}),[t,...Fe(n),...Fe(i),...Fe(a)]),C.createElement("mesh",{ref:l},r||C.createElement("meshStandardMaterial",S.default({transparent:!0,polygonOffset:!0,polygonOffsetFactor:-10},s)),e&&C.createElement("mesh",{ref:c},C.createElement("boxGeometry",null),C.createElement("meshNormalMaterial",{wireframe:!0}),C.createElement("axesHelper",null)))},exports.Detailed=$n,exports.DeviceOrientationControls=We,exports.Dodecahedron=mr,exports.Edges=function({userData:e,children:t,geometry:r,threshold:n=15,color:o="black",...a}){const i=C.useRef(null);return C.useLayoutEffect((()=>{const e=i.current.parent;if(e){const t=r||e.geometry;t===i.current.userData.currentGeom&&n===i.current.userData.currentThreshold||(i.current.userData.currentGeom=t,i.current.userData.currentThreshold=n,i.current.geometry=new P.EdgesGeometry(t,n))}})),C.createElement("lineSegments",S.default({ref:i,raycast:()=>null},a),t||C.createElement("lineBasicMaterial",{color:o}))},exports.Effects=pe,exports.Environment=Lr,exports.EnvironmentCube=zr,exports.EnvironmentMap=Dr,exports.EnvironmentPortal=kr,exports.Extrude=fr,exports.FirstPersonControls=Ze,exports.Float=Tr,exports.FlyControls=Ge,exports.GizmoHelper=({alignment:e="bottom-right",margin:t=[80,80],renderPriority:r=1,onUpdate:a,onTarget:i,children:s})=>{const l=o.useThree((e=>e.size)),c=o.useThree((e=>e.camera)),u=o.useThree((e=>e.controls)),d=o.useThree((e=>e.invalidate)),m=C.useRef(),f=C.useRef(null),p=C.useRef(!1),h=C.useRef(0),v=C.useRef(new n.Vector3(0,0,0)),g=C.useRef(new n.Vector3(0,0,0));C.useEffect((()=>{g.current.copy(c.up)}),[c]);const x=C.useCallback((e=>{p.current=!0,(u||i)&&(v.current=(null==u?void 0:u.target)||(null==i?void 0:i())),h.current=c.position.distanceTo(it),ot.copy(c.quaternion),st.copy(e).multiplyScalar(h.current).add(it),rt.lookAt(st),at.copy(rt.quaternion),d()}),[u,c,i,d]);o.useFrame(((e,t)=>{if(f.current&&m.current){var r;if(p.current)if(ot.angleTo(at)<.01)p.current=!1,"minPolarAngle"in u&&c.up.copy(g.current);else{const e=t*tt;ot.rotateTowards(at,e),c.position.set(0,0,1).applyQuaternion(ot).multiplyScalar(h.current).add(v.current),c.up.set(0,1,0).applyQuaternion(ot).normalize(),c.quaternion.copy(ot),a?a():u&&u.update(),d()}nt.copy(c.matrix).invert(),null==(r=m.current)||r.quaternion.setFromRotationMatrix(nt)}}));const y=C.useMemo((()=>({tweenCamera:x})),[x]),[w,E]=t,b=e.endsWith("-center")?0:e.endsWith("-left")?-l.width/2+w:l.width/2-w,M=e.startsWith("center-")?0:e.startsWith("top-")?l.height/2-E:-l.height/2+E;return C.createElement(Qe,{renderPriority:r},C.createElement(Je.Provider,{value:y},C.createElement(Oe,{makeDefault:!0,ref:f,position:[0,0,200]}),C.createElement("group",{ref:m,position:[b,M,0]},s)))},exports.GizmoViewcube=e=>C.createElement("group",{scale:[60,60,60]},C.createElement(yt,e),vt.map(((t,r)=>C.createElement(wt,S.default({key:r,position:t,dimensions:gt[r]},e)))),pt.map(((t,r)=>C.createElement(wt,S.default({key:r,position:t,dimensions:ht},e)))),C.createElement("ambientLight",{intensity:.5}),C.createElement("pointLight",{position:[10,10,10],intensity:.5})),exports.GizmoViewport=({hideNegativeAxes:e,hideAxisHeads:t,disabled:r,font:n="18px Inter var, Arial, sans-serif",axisColors:o=["#ff2060","#20df80","#2080ff"],axisHeadScale:a=1,axisScale:i,labels:s=["X","Y","Z"],labelColor:l="#000",onClick:c,...u})=>{const[d,m,f]=o,{tweenCamera:p}=et(),h={font:n,disabled:r,labelColor:l,onClick:c,axisHeadScale:a,onPointerDown:r?void 0:e=>{p(e.object.position),e.stopPropagation()}};return C.createElement("group",S.default({scale:40},u),C.createElement(Et,{color:d,rotation:[0,0,0],scale:i}),C.createElement(Et,{color:m,rotation:[0,0,Math.PI/2],scale:i}),C.createElement(Et,{color:f,rotation:[0,-Math.PI/2,0],scale:i}),!t&&C.createElement(C.Fragment,null,C.createElement(bt,S.default({arcStyle:d,position:[1,0,0],label:s[0]},h)),C.createElement(bt,S.default({arcStyle:m,position:[0,1,0],label:s[1]},h)),C.createElement(bt,S.default({arcStyle:f,position:[0,0,1],label:s[2]},h)),!e&&C.createElement(C.Fragment,null,C.createElement(bt,S.default({arcStyle:d,position:[-1,0,0]},h)),C.createElement(bt,S.default({arcStyle:m,position:[0,-1,0]},h)),C.createElement(bt,S.default({arcStyle:f,position:[0,0,-1]},h)))),C.createElement("ambientLight",{intensity:.5}),C.createElement("pointLight",{position:[10,10,10],intensity:.5}))},exports.Gltf=Ve,exports.GradientTexture=function({stops:e,colors:t,size:r=1024,...n}){const a=o.useThree((e=>e.gl)),i=C.useMemo((()=>{const n=document.createElement("canvas"),o=n.getContext("2d");n.width=16,n.height=r;const a=o.createLinearGradient(0,0,0,r);let i=e.length;for(;i--;)a.addColorStop(e[i],t[i]);o.fillStyle=a,o.fillRect(0,0,16,r);const s=new P.Texture(n);return s.needsUpdate=!0,s}),[e]);return C.useEffect((()=>()=>{i.dispose()}),[i]),C.createElement("primitive",S.default({object:i,attach:"map",encoding:a.outputEncoding},n))},exports.Grid=St,exports.Html=H,exports.Hud=Qe,exports.Icosahedron=ur,exports.Image=be,exports.Instance=Vn,exports.Instances=In,exports.IsObject=ve,exports.KeyboardControls=function({map:e,children:t,onChange:r,domElement:n}){const o=e.map((e=>e.name+e.keys)).join("-"),a=C.useMemo((()=>R.default(c.subscribeWithSelector((()=>e.reduce(((e,t)=>({...e,[t.name]:!1})),{}))))),[o]),i=C.useMemo((()=>[a.subscribe,a.getState,a]),[o]),s=a.setState;return C.useEffect((()=>{const t=e.map((({name:e,keys:t,up:n})=>({keys:t,up:n,fn:t=>{s({[e]:t}),r&&r(e,t,i[2]())}}))).reduce(((e,{keys:t,fn:r,up:n=!0})=>(t.forEach((t=>e[t]={fn:r,pressed:!1,up:n})),e)),{}),o=({key:e,code:r})=>{const n=t[e]||t[r];if(!n)return;const{fn:o,pressed:a,up:i}=n;n.pressed=!0,!i&&a||o(!0)},a=({key:e,code:r})=>{const n=t[e]||t[r];if(!n)return;const{fn:o,up:a}=n;n.pressed=!1,a&&o(!1)},l=n||window;return l.addEventListener("keydown",o,{passive:!0}),l.addEventListener("keyup",a,{passive:!0}),()=>{l.removeEventListener("keydown",o),l.removeEventListener("keyup",a)}}),[n,o]),C.createElement(te.Provider,{value:i,children:t})},exports.Lathe=pr,exports.Lightformer=Jr,exports.Line=ae,exports.Loader=function({containerStyles:e,innerStyles:t,barStyles:r,dataStyles:n,dataInterpolation:o=X,initialState:a=(e=>e)}){const{active:i,progress:s}=q(),l=C.useRef(0),c=C.useRef(0),u=C.useRef(null),[d,m]=C.useState(a(i));C.useEffect((()=>{let e;return i!==d&&(e=setTimeout((()=>m(i)),300)),()=>clearTimeout(e)}),[d,i]);const f=C.useCallback((()=>{u.current&&(l.current+=(s-l.current)/2,(l.current>.95*s||100===s)&&(l.current=s),u.current.innerText=o(l.current),l.current<s&&(c.current=requestAnimationFrame(f)))}),[o,s]);return C.useEffect((()=>(f(),()=>cancelAnimationFrame(c.current))),[f]),d?C.createElement("div",{style:{...Y.container,opacity:i?1:0,...e}},C.createElement("div",null,C.createElement("div",{style:{...Y.inner,...t}},C.createElement("div",{style:{...Y.bar,transform:`scaleX(${s/100})`,...r}}),C.createElement("span",{ref:u,style:{...Y.data,...n}})))):null},exports.MapControls=Ne,exports.MarchingCube=ze,exports.MarchingCubes=_e,exports.MarchingPlane=ke,exports.Mask=function({id:e=1,children:t,colorWrite:r=!1,depthWrite:n=!1,...o}){const a=C.useMemo((()=>({colorWrite:r,depthWrite:n,stencilWrite:!0,stencilRef:e,stencilFunc:P.AlwaysStencilFunc,stencilFail:P.ReplaceStencilOp,stencilZFail:P.ReplaceStencilOp,stencilZPass:P.ReplaceStencilOp})),[e,r,n]);return C.createElement("mesh",S.default({renderOrder:-e},o),C.createElement("meshBasicMaterial",a),"function"==typeof t?t(a):t)},exports.Merged=On,exports.MeshDistortMaterial=Bt,exports.MeshReflectorMaterial=Wt,exports.MeshRefractionMaterial=function({aberrationStrength:e=0,fastChroma:r=!0,envMap:n,...a}){o.extend({MeshRefractionMaterial:Gt});const i=t.useRef(),{size:s}=o.useThree(),l=t.useMemo((()=>{var t,o;const a={},i=(s=n)&&s.isCubeTexture;var s;const l=(null!==(t=i?null==(o=n.image[0])?void 0:o.width:n.image.width)&&void 0!==t?t:1024)/4,c=Math.floor(Math.log2(l)),u=Math.pow(2,c),d=3*Math.max(u,112),m=4*u;return i&&(a.ENVMAP_TYPE_CUBEM=""),a.CUBEUV_TEXEL_WIDTH=""+1/d,a.CUBEUV_TEXEL_HEIGHT=""+1/m,a.CUBEUV_MAX_MIP=`${c}.0`,e>0&&(a.CHROMATIC_ABERRATIONS=""),r&&(a.FAST_CHROMA=""),a}),[e,r]);return t.useLayoutEffect((()=>{var e,t,r;const n=null==(e=i.current)||null==(t=e.__r3f)||null==(r=t.parent)?void 0:r.geometry;n&&i.current.bvh.updateFrom(new y.MeshBVH(n.toNonIndexed(),{lazyGeneration:!1,strategy:y.SAH}))}),[]),C.createElement("meshRefractionMaterial",S.default({key:JSON.stringify(l),defines:l,ref:i,resolution:[s.width,s.height],aberrationStrength:e,envMap:n},a))},exports.MeshTransmissionMaterial=Ht,exports.MeshWobbleMaterial=Vt,exports.Octahedron=dr,exports.OrbitControls=He,exports.OrthographicCamera=Oe,exports.PerformanceMonitor=function({iterations:e=10,ms:r=250,threshold:n=.75,step:a=.1,factor:i=.5,flipflops:s=1/0,bounds:l=(e=>e>100?[60,100]:[40,60]),onIncline:c,onDecline:u,onChange:d,onFallback:m,children:f}){const p=Math.pow(10,0),[h,v]=t.useState((()=>({fps:0,index:0,factor:i,flipped:0,refreshrate:0,fallback:!1,frames:[],averages:[],subscriptions:new Map,subscribe:e=>{const t=Symbol();return h.subscriptions.set(t,e.current),()=>{h.subscriptions.delete(t)}}})));let g=0;return o.useFrame((()=>{const{frames:t,averages:o}=h;if(!h.fallback&&o.length<e){t.push(performance.now());const i=t[t.length-1]-t[0];if(i>=r){if(h.fps=Math.round(t.length/i*1e3*p)/p,h.refreshrate=Math.max(h.refreshrate,h.fps),o[h.index++%e]=h.fps,o.length===e){const[t,r]=l(h.refreshrate),i=o.filter((e=>e>=r)),f=o.filter((e=>e<t));i.length>e*n&&(h.factor=Math.min(1,h.factor+a),h.flipped++,c&&c(h),h.subscriptions.forEach((e=>e.onIncline&&e.onIncline(h)))),f.length>e*n&&(h.factor=Math.max(0,h.factor-a),h.flipped++,u&&u(h),h.subscriptions.forEach((e=>e.onDecline&&e.onDecline(h)))),g!==h.factor&&(g=h.factor,d&&d(h),h.subscriptions.forEach((e=>e.onChange&&e.onChange(h)))),h.flipped>s&&!h.fallback&&(h.fallback=!0,m&&m(h),h.subscriptions.forEach((e=>e.onFallback&&e.onFallback(h)))),h.averages=[]}h.frames=[]}}})),C.createElement(Kn.Provider,{value:h},f)},exports.PerspectiveCamera=je,exports.PivotControls=Ho,exports.Plane=nr,exports.Point=Mn,exports.PointMaterial=qt,exports.PointMaterialImpl=$t,exports.PointerLockControls=Ye,exports.Points=Cn,exports.PointsBuffer=Sn,exports.Polyhedron=cr,exports.PositionPoint=vn,exports.PositionalAudio=ue,exports.Preload=function({all:e,scene:t,camera:r}){const a=o.useThree((({gl:e})=>e)),i=o.useThree((({camera:e})=>e)),s=o.useThree((({scene:e})=>e));return C.useLayoutEffect((()=>{const o=[];e&&(t||s).traverse((e=>{!1===e.visible&&(o.push(e),e.visible=!0)})),a.compile(t||s,r||i);const l=new n.WebGLCubeRenderTarget(128);new n.CubeCamera(.01,1e5,l).update(a,t||s),l.dispose(),o.forEach((e=>e.visible=!1))}),[]),null},exports.PresentationControls=function({enabled:e=!0,snap:t,global:r,cursor:a=!0,children:i,speed:c=1,rotation:u=[0,0,0],zoom:d=1,polar:m=[0,Math.PI/2],azimuth:f=[-1/0,1/0],config:p={mass:1,tension:170,friction:26}}){const{size:h,gl:v}=o.useThree(),g=C.useMemo((()=>[u[0]+m[0],u[0]+m[1]]),[u[0],m[0],m[1]]),x=C.useMemo((()=>[u[1]+f[0],u[1]+f[1]]),[u[1],f[0],f[1]]),y=C.useMemo((()=>[n.MathUtils.clamp(u[0],...g),n.MathUtils.clamp(u[1],...x),u[2]]),[u[0],u[1],u[2],g,x]),[w,E]=s.useSpring((()=>({scale:1,rotation:y,config:p})));C.useEffect((()=>{E.start({scale:1,rotation:y,config:p})}),[y]),C.useEffect((()=>(r&&a&&e&&(v.domElement.style.cursor="grab"),()=>{v.domElement.style.cursor="default"})),[r,a,v.domElement,e]);const b=l.useGesture({onHover:({last:t})=>{a&&!r&&e&&(v.domElement.style.cursor=t?"auto":"grab")},onDrag:({down:r,delta:[o,i],memo:[s,l]=w.rotation.animation.to||y})=>{if(!e)return[i,o];a&&(v.domElement.style.cursor=r?"grabbing":"grab"),o=n.MathUtils.clamp(l+o/h.width*Math.PI*c,...x),i=n.MathUtils.clamp(s+i/h.height*Math.PI*c,...g);const u=t&&!r&&"boolean"!=typeof t?t:p;return E.start({scale:r&&i>g[1]/2?d:1,rotation:t&&!r?y:[i,o,0],config:e=>"scale"===e?{...u,friction:3*u.friction}:u}),[i,o]}},{target:r?v.domElement:void 0});return C.createElement(s.a.group,S.default({},null==b?void 0:b(),w),i)},exports.QuadraticBezierLine=se,exports.RandomizedLight=Or,exports.Reflector=$r,exports.RenderTexture=Qn,exports.Ring=lr,exports.RoundedBox=gr,exports.Sampler=function({children:e,weight:t,transform:r,instances:n,mesh:o,count:a=16,...i}){const s=C.useRef(null),l=C.useRef(null),c=C.useRef(null);return C.useEffect((()=>{var e,t;l.current=null!==(e=null==n?void 0:n.current)&&void 0!==e?e:s.current.children.find((e=>e.hasOwnProperty("instanceMatrix"))),c.current=null!==(t=null==o?void 0:o.current)&&void 0!==t?t:s.current.children.find((e=>"Mesh"===e.type))}),[e,null==o?void 0:o.current,null==n?void 0:n.current]),Pe(c,a,r,t,l),C.createElement("group",S.default({ref:s},i),e)},exports.ScreenQuad=yr,exports.ScreenSpace=oe,exports.Scroll=ee,exports.ScrollControls=function({eps:e=1e-5,enabled:t=!0,infinite:r,horizontal:n,pages:a=1,distance:i=1,damping:s=4,style:l={},children:c}){const{get:u,setEvents:d,gl:m,size:f,invalidate:p,events:h}=o.useThree(),[v]=C.useState((()=>document.createElement("div"))),[g]=C.useState((()=>document.createElement("div"))),[x]=C.useState((()=>document.createElement("div"))),y=m.domElement.parentNode,w=C.useRef(0),E=C.useMemo((()=>{const t={el:v,eps:e,fill:g,fixed:x,horizontal:n,damping:s,offset:0,delta:0,scroll:w,pages:a,range(e,t,r=0){const n=e-r,o=n+t+2*r;return this.offset<n?0:this.offset>o?1:(this.offset-n)/(o-n)},curve(e,t,r=0){return Math.sin(this.range(e,t,r)*Math.PI)},visible(e,t,r=0){const n=e-r,o=n+t+2*r;return this.offset>=n&&this.offset<=o}};return t}),[e,s,n,a]);C.useEffect((()=>{v.style.position="absolute",v.style.width="100%",v.style.height="100%",v.style[n?"overflowX":"overflowY"]="auto",v.style[n?"overflowY":"overflowX"]="hidden",v.style.top="0px",v.style.left="0px";for(const e in l)v.style[e]=l[e];x.style.position="sticky",x.style.top="0px",x.style.left="0px",x.style.width="100%",x.style.height="100%",x.style.overflow="hidden",v.appendChild(x),g.style.height=n?"100%":a*i*100+"%",g.style.width=n?a*i*100+"%":"100%",g.style.pointerEvents="none",v.appendChild(g),y.appendChild(v),v[n?"scrollLeft":"scrollTop"]=1;const e=h.connected||m.domElement;requestAnimationFrame((()=>null==h.connect?void 0:h.connect(v)));const t=u().events.compute;return d({compute(e,t){const{left:r,top:n}=y.getBoundingClientRect(),o=e.clientX-r,a=e.clientY-n;t.pointer.set(o/t.size.width*2-1,-a/t.size.height*2+1),t.raycaster.setFromCamera(t.pointer,t.camera)}}),()=>{y.removeChild(v),d({compute:t}),null==h.connect||h.connect(e)}}),[a,i,n,v,g,x,y]),C.useEffect((()=>{if(h.connected===v){const e=f[n?"width":"height"],o=v[n?"scrollWidth":"scrollHeight"],a=o-e;let i=0,s=!0,l=!0;const c=()=>{if(t&&!l&&(p(),i=v[n?"scrollLeft":"scrollTop"],w.current=i/a,r)){if(!s)if(i>=a){const e=1-E.offset;v[n?"scrollLeft":"scrollTop"]=1,w.current=E.offset=-e,s=!0}else if(i<=0){const e=1+E.offset;v[n?"scrollLeft":"scrollTop"]=o,w.current=E.offset=e,s=!0}s&&setTimeout((()=>s=!1),40)}};v.addEventListener("scroll",c,{passive:!0}),requestAnimationFrame((()=>l=!1));const u=e=>v.scrollLeft+=e.deltaY/2;return n&&v.addEventListener("wheel",u,{passive:!0}),()=>{v.removeEventListener("scroll",c),n&&v.removeEventListener("wheel",u)}}}),[v,h,f,r,E,p,n,t]);let b=0;return o.useFrame(((t,r)=>{E.offset=P.MathUtils.damp(b=E.offset,w.current,s,r),E.delta=P.MathUtils.damp(E.delta,Math.abs(b-E.offset),s,r),E.delta>e&&p()})),C.createElement(Z.Provider,{value:E},c)},exports.Segment=Hn,exports.SegmentObject=Gn,exports.Segments=Wn,exports.Select=function({box:e,multiple:t,children:r,onChange:n,border:a="1px solid #55aaff",backgroundColor:i="rgba(75, 160, 255, 0.1)",filter:s=(e=>e),...l}){const{setEvents:c,camera:d,raycaster:m,gl:f,controls:p,size:h,get:v}=o.useThree(),[g,x]=C.useState(!1),[y,w]=C.useReducer(((e,{object:t,shift:r})=>void 0===t?[]:Array.isArray(t)?t:r?e.includes(t)?e.filter((e=>e!==t)):[t,...e]:e[0]===t?[]:[t]),[]);C.useEffect((()=>{null==n||n(y)}),[y]);const E=C.useCallback((e=>{e.stopPropagation(),w({object:s([e.object])[0],shift:t&&e.shiftKey})}),[]),b=C.useCallback((e=>!g&&w({})),[g]),M=C.useRef(null);return C.useEffect((()=>{if(!e||!t)return;const r=new u.SelectionBox(d,M.current),n=document.createElement("div");n.style.pointerEvents="none",n.style.border=a,n.style.backgroundColor=i,n.style.position="fixed";const o=new P.Vector2,l=new P.Vector2,m=new P.Vector2,g=v().events.enabled,x=null==p?void 0:p.enabled;let y=!1;function E(e,t){const{offsetX:r,offsetY:n}=e,{width:o,height:a}=h;t.set(r/o*2-1,-n/a*2+1)}function b(e){e.shiftKey&&(!function(e){var t;p&&(p.enabled=!1),c({enabled:!1}),y=!0,null==(t=f.domElement.parentElement)||t.appendChild(n),n.style.left=`${e.clientX}px`,n.style.top=`${e.clientY}px`,n.style.width="0px",n.style.height="0px",o.x=e.clientX,o.y=e.clientY}(e),E(e,r.startPoint))}let S=[];function C(e){if(y){!function(e){m.x=Math.max(o.x,e.clientX),m.y=Math.max(o.y,e.clientY),l.x=Math.min(o.x,e.clientX),l.y=Math.min(o.y,e.clientY),n.style.left=`${l.x}px`,n.style.top=`${l.y}px`,n.style.width=m.x-l.x+"px",n.style.height=m.y-l.y+"px"}(e),E(e,r.endPoint);const t=r.select().sort((e=>e.uuid)).filter((e=>e.isMesh));_.default(t,S)||(S=t,w({object:s(t)}))}}function T(e){var t;y&&y&&(p&&(p.enabled=x),c({enabled:g}),y=!1,null==(t=n.parentElement)||t.removeChild(n))}return document.addEventListener("pointerdown",b,{passive:!0}),document.addEventListener("pointermove",C,{passive:!0,capture:!0}),document.addEventListener("pointerup",T,{passive:!0}),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("pointermove",C),document.removeEventListener("pointerup",T)}}),[h,m,d,p,f]),C.createElement("group",S.default({ref:M,onClick:E,onPointerOver:()=>x(!0),onPointerOut:()=>x(!1),onPointerMissed:b},l),C.createElement(re.Provider,{value:y},r))},exports.Shadow=Hr,exports.Sky=tn,exports.SoftShadows=function({frustum:e=3.75,size:t=.005,near:r=9.5,samples:n=10,rings:a=11}){const i=o.useThree((e=>e.gl)),s=o.useThree((e=>e.scene)),l=o.useThree((e=>e.camera));C.useEffect((()=>{const o=P.ShaderChunk.shadowmap_pars_fragment;let c=P.ShaderChunk.shadowmap_pars_fragment;return c=c.replace("#ifdef USE_SHADOWMAP","#ifdef USE_SHADOWMAP\n"+Xt({frustum:e,size:t,near:r,samples:n,rings:a})),c=c.replace("#if defined( SHADOWMAP_TYPE_PCF )","\nreturn PCSS(shadowMap, shadowCoord);\n#if defined( SHADOWMAP_TYPE_PCF )"),P.ShaderChunk.shadowmap_pars_fragment=c,Zt(i,s,l),()=>{P.ShaderChunk.shadowmap_pars_fragment=o,Zt(i,s,l)}}),[e,t,r,n,a])},exports.Sparkles=dn,exports.Sphere=rr,exports.SpotLight=Qr,exports.SpotLightShadow=function(e){return e.shader?C.createElement(Zr,e):C.createElement(Kr,e)},exports.Stage=function({children:e,center:t,adjustCamera:r=!0,intensity:n=.5,shadows:o="contact",environment:a="city",preset:i="rembrandt",...s}){var l,c,u,d,m,f,p,h;const v="string"==typeof i?Wr[i]:i,[{radius:g,height:x},y]=C.useState({radius:0,width:0,height:0,depth:0}),w=null!==(l=null==o?void 0:o.bias)&&void 0!==l?l:-1e-4,E=null!==(c=null==o?void 0:o.normalBias)&&void 0!==c?c:0,b=null!==(u=null==o?void 0:o.size)&&void 0!==u?u:1024,M=null!==(d=null==o?void 0:o.offset)&&void 0!==d?d:0,T="contact"===o||"contact"===(null==o?void 0:o.type),P="accumulative"===o||"accumulative"===(null==o?void 0:o.type),R={..."object"==typeof o?o:{}},D=a?"string"==typeof a?{preset:a}:a:null;return C.createElement(C.Fragment,null,C.createElement("ambientLight",{intensity:n/3}),C.createElement("spotLight",{penumbra:1,position:[v.main[0]*g,v.main[1]*g,v.main[2]*g],intensity:2*n,castShadow:!!o,"shadow-bias":w,"shadow-normalBias":E,"shadow-mapSize":b}),C.createElement("pointLight",{position:[v.fill[0]*g,v.fill[1]*g,v.fill[2]*g],intensity:n}),C.createElement(Mr,S.default({fit:!!r,clip:!!r,margin:Number(r),observe:!0},s),C.createElement(Gr,{radius:g,adjustCamera:r}),C.createElement(wr,S.default({},t,{position:[0,M/2,0],onCentered:e=>{const{width:r,height:n,depth:o,boundingSphere:a}=e;y({radius:a.radius,width:r,height:n,depth:o}),null!=t&&t.onCentered&&t.onCentered(e)}}),e)),C.createElement("group",{position:[0,-x/2-M/2,0]},T&&C.createElement(Ar,S.default({scale:4*g,far:g,blur:2},R)),P&&C.createElement(Ir,S.default({temporal:!0,frames:100,alphaTest:.9,toneMapped:!0,scale:4*g},R),C.createElement(Or,{amount:null!==(m=R.amount)&&void 0!==m?m:8,radius:null!==(f=R.radius)&&void 0!==f?f:g,ambient:null!==(p=R.ambient)&&void 0!==p?p:.5,intensity:null!==(h=R.intensity)&&void 0!==h?h:1,position:[v.main[0]*g,v.main[1]*g,v.main[2]*g],size:4*g,bias:-w,mapSize:b}))),a&&C.createElement(Lr,D))},exports.Stars=on,exports.Stats=function({showPanel:e=0,className:t,parent:r}){const n=function(e,t=[],r){const[n,o]=C.useState();return C.useLayoutEffect((()=>{const t=e();return o(t),Dt(r,t),()=>Dt(r,null)}),t),n}((()=>new F.default),[]);return C.useEffect((()=>{if(n){const a=r&&r.current||document.body;n.showPanel(e),null==a||a.appendChild(n.dom),t&&n.dom.classList.add(...t.split(" ").filter((e=>e)));const i=o.addEffect((()=>n.begin())),s=o.addAfterEffect((()=>n.end()));return()=>{null==a||a.removeChild(n.dom),i(),s()}}}),[r,n,t,e]),null},exports.Svg=Le,exports.Tetrahedron=sr,exports.Text=de,exports.Text3D=fe,exports.Torus=ar,exports.TorusKnot=ir,exports.TrackballControls=$e,exports.Trail=Te,exports.TransformControls=Xe,exports.Tube=or,exports.View=({track:e,index:t=1,frames:r=1/0,children:n})=>{const a=C.useRef(null),{size:i,scene:s}=o.useThree(),[l]=C.useState((()=>new P.Scene)),c=C.useCallback(((t,r)=>{if(e.current&&t.target===e.current){const{width:e,height:n,left:o,top:i}=a.current,s=t.clientX-o,l=t.clientY-i;r.pointer.set(s/e*2-1,-l/n*2+1),r.raycaster.setFromCamera(r.pointer,r.camera)}}),[a]),[u,d]=C.useReducer((()=>!0),!1);return C.useEffect((()=>{var t;a.current=null==(t=e.current)?void 0:t.getBoundingClientRect(),d()}),[]),C.createElement(C.Fragment,null,u&&o.createPortal(C.createElement(ro,{canvasSize:i,frames:r,scene:s,track:e,rect:a,index:t},n),l,{events:{compute:c,priority:t},size:{width:a.current.width,height:a.current.height}}))},exports.accumulativeContext=Br,exports.calcPosFromAngles=en,exports.calculateScaleFactor=Po,exports.isWebGL2Available=()=>{try{var e=document.createElement("canvas");return!(!window.WebGL2RenderingContext||!e.getContext("webgl2"))}catch(e){return!1}},exports.meshBounds=function(e,t){const r=this.geometry,n=this.material,o=this.matrixWorld;void 0!==n&&(null===r.boundingSphere&&r.computeBoundingSphere(),Yn.copy(r.boundingSphere),Yn.applyMatrix4(o),!1!==e.ray.intersectsSphere(Yn)&&(qn.copy(o).invert(),Xn.copy(e.ray).applyMatrix4(qn),null!==r.boundingBox&&null===Xn.intersectBox(r.boundingBox,Zn)||t.push({distance:Zn.distanceTo(e.ray.origin),point:Zn.clone(),object:this})))},exports.shaderMaterial=he,exports.softShadows=e=>{if(!Yt){console.warn("drei/softShadows() is deprecated, use <SoftShadows> instead"),Yt=!0;let t=P.ShaderChunk.shadowmap_pars_fragment;t=t.replace("#ifdef USE_SHADOWMAP","#ifdef USE_SHADOWMAP\n"+Xt({...e})),t=t.replace("#if defined( SHADOWMAP_TYPE_PCF )","\nreturn PCSS(shadowMap, shadowCoord);\n#if defined( SHADOWMAP_TYPE_PCF )"),P.ShaderChunk.shadowmap_pars_fragment=t}},exports.useAnimations=function(e,t){const r=C.useRef(),[a]=C.useState((()=>t?t instanceof n.Object3D?{current:t}:t:r)),[i]=C.useState((()=>new n.AnimationMixer(void 0))),s=C.useRef({}),[l]=C.useState((()=>{const t={};return e.forEach((e=>Object.defineProperty(t,e.name,{enumerable:!0,get(){if(a.current)return s.current[e.name]||(s.current[e.name]=i.clipAction(e,a.current))}}))),{ref:a,clips:e,actions:t,names:e.map((e=>e.name)),mixer:i}}));return o.useFrame(((e,t)=>i.update(t))),C.useEffect((()=>{const e=a.current;return()=>{s.current={},Object.values(l.actions).forEach((t=>{e&&i.uncacheAction(t,e)}))}}),[e]),C.useEffect((()=>()=>{i.stopAllAction()}),[i]),l},exports.useAspect=function(e,t,r=1){const n=o.useThree((e=>e.viewport)),a=t*(n.aspect>e/t?n.width/e:n.height/t);return[e*(n.aspect>e/t?n.width/e:n.height/t)*r,a*r,1]},exports.useBVH=function(e,t){C.useEffect((()=>{if(e.current){e.current.raycast=y.acceleratedRaycast;const r=e.current.geometry;return r.computeBoundsTree=y.computeBoundsTree,r.disposeBoundsTree=y.disposeBoundsTree,r.computeBoundsTree(t),()=>{r.boundsTree&&r.disposeBoundsTree()}}}),[e,t])},exports.useBounds=Sr,exports.useBoxProjectedEnv=function(e=new P.Vector3,t=new P.Vector3){const[r]=C.useState((()=>({position:new P.Vector3,size:new P.Vector3})));o.applyProps(r,{position:e,size:t});const n=C.useRef(null),a=C.useMemo((()=>({ref:n,onBeforeCompile:e=>function(e,t,r){e.defines.BOX_PROJECTED_ENV_MAP=!0,e.uniforms.envMapPosition={value:t},e.uniforms.envMapSize={value:r},e.vertexShader=`\n varying vec3 vWorldPosition;\n ${e.vertexShader.replace("#include <worldpos_vertex>","\n#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n #ifdef BOX_PROJECTED_ENV_MAP\n vWorldPosition = worldPosition.xyz;\n #endif\n#endif\n")}`,e.fragmentShader=`\n \n#ifdef BOX_PROJECTED_ENV_MAP\n uniform vec3 envMapSize;\n uniform vec3 envMapPosition;\n varying vec3 vWorldPosition;\n \n vec3 parallaxCorrectNormal( vec3 v, vec3 cubeSize, vec3 cubePos ) {\n vec3 nDir = normalize( v );\n vec3 rbmax = ( .5 * cubeSize + cubePos - vWorldPosition ) / nDir;\n vec3 rbmin = ( -.5 * cubeSize + cubePos - vWorldPosition ) / nDir;\n vec3 rbminmax;\n rbminmax.x = ( nDir.x > 0. ) ? rbmax.x : rbmin.x;\n rbminmax.y = ( nDir.y > 0. ) ? rbmax.y : rbmin.y;\n rbminmax.z = ( nDir.z > 0. ) ? rbmax.z : rbmin.z;\n float correction = min( min( rbminmax.x, rbminmax.y ), rbminmax.z );\n vec3 boxIntersection = vWorldPosition + nDir * correction; \n return boxIntersection - cubePos;\n }\n#endif\n\n ${e.fragmentShader.replace("#include <envmap_physical_pars_fragment>",P.ShaderChunk.envmap_physical_pars_fragment).replace("vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );","vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n \n#ifdef BOX_PROJECTED_ENV_MAP\n worldNormal = parallaxCorrectNormal( worldNormal, envMapSize, envMapPosition );\n#endif\n\n ").replace("reflectVec = inverseTransformDirection( reflectVec, viewMatrix );","reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n \n#ifdef BOX_PROJECTED_ENV_MAP\n reflectVec = parallaxCorrectNormal( reflectVec, envMapSize, envMapPosition );\n#endif\n\n ")}`}(e,r.position,r.size),customProgramCacheKey:()=>JSON.stringify(r.position.toArray())+JSON.stringify(r.size.toArray())})),[...r.position.toArray(),...r.size.toArray()]);return C.useLayoutEffect((()=>{n.current.needsUpdate=!0}),[r]),a},exports.useCamera=function(e,t){const r=o.useThree((e=>e.pointer)),[a]=C.useState((()=>{const a=new n.Raycaster;return t&&o.applyProps(a,t,{}),function(t,o){a.setFromCamera(r,e instanceof n.Camera?e:e.current);const i=this.constructor.prototype.raycast.bind(this);i&&i(a,o)}}));return a},exports.useContextBridge=function(...e){const t=C.useRef([]);return t.current=e.map((e=>C.useContext(e))),C.useMemo((()=>({children:r})=>e.reduceRight(((e,r,n)=>C.createElement(r.Provider,{value:t.current[n],children:e})),r)),[])},exports.useCubeTexture=Ct,exports.useCursor=function(e,t="pointer",r="auto"){C.useEffect((()=>{if(e)return document.body.style.cursor=t,()=>{document.body.style.cursor=r}}),[e])},exports.useDepthBuffer=function({size:e=256,frames:t=1/0}={}){const r=o.useThree((e=>e.viewport.dpr)),{width:a,height:i}=o.useThree((e=>e.size)),s=e||a*r,l=e||i*r,c=C.useMemo((()=>{const e=new n.DepthTexture(s,l);return e.format=n.DepthFormat,e.type=n.UnsignedShortType,{depthTexture:e}}),[s,l]);let u=0;const d=Ie(s,l,c);return o.useFrame((e=>{(t===1/0||u<t)&&(e.gl.setRenderTarget(d),e.gl.render(e.scene,e.camera),e.gl.setRenderTarget(null),u++)})),d.depthTexture},exports.useDetectGPU=e=>f.suspend((()=>x.getGPUTier(e)),["useDetectGPU"]),exports.useEnvironment=_r,exports.useFBO=Ie,exports.useFBX=Tt,exports.useGLTF=Ue,exports.useGizmoContext=et,exports.useHelper=function(e,t,...r){const n=C.useRef(),a=o.useThree((e=>e.scene));return C.useEffect((()=>{let o;if(e&&null!=e&&e.current&&t&&(n.current=o=new t(e.current,...r)),o)return a.add(o),()=>{n.current=void 0,a.remove(o),null==o.dispose||o.dispose()}}),[a,t,e,...r]),o.useFrame((()=>{var e;null==(e=n.current)||null==e.update||e.update()})),n},exports.useIntersect=function(e){const t=C.useRef(null),r=C.useRef(!1),n=C.useRef(!1),a=C.useRef(e);return C.useLayoutEffect((()=>{a.current=e}),[e]),C.useEffect((()=>{const e=t.current;if(e){const t=o.addEffect((()=>(r.current=!1,!0))),i=e.onBeforeRender;e.onBeforeRender=()=>r.current=!0;const s=o.addAfterEffect((()=>(r.current!==n.current&&(null==a.current||a.current(n.current=r.current)),!0)));return()=>{e.onBeforeRender=i,t(),s()}}}),[]),t},exports.useKTX2=Rt,exports.useKeyboardControls=function(e){const[t,r,n]=C.useContext(te);return e?n(e):[t,r]},exports.useMask=function(e,t=!1){return{stencilWrite:!0,stencilRef:e,stencilFunc:t?P.NotEqualStencilFunc:P.EqualStencilFunc,stencilFail:P.KeepStencilOp,stencilZFail:P.KeepStencilOp,stencilZPass:P.KeepStencilOp}},exports.useMatcapTexture=function(e=0,t=1024,r){const n=f.suspend((()=>fetch("https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master/matcaps.json").then((e=>e.json()))),["matcapList"]),o=n[0],a=C.useMemo((()=>Object.keys(n).length),[]),i=`${C.useMemo((()=>"string"==typeof e?e:"number"==typeof e?n[e]:null),[e])||o}${function(e){switch(e){case 64:return"-64px";case 128:return"-128px";case 256:return"-256px";case 512:return"-512px";default:return""}}(t)}.png`,s=`https://rawcdn.githack.com/emmelleppi/matcaps/9b36ccaaf0a24881a39062d05566c9e92be4aa0d/${t}/${i}`;return[ge(s,r),s,a]},exports.useNormalTexture=function(e=0,t={},r){const{repeat:o=[1,1],anisotropy:a=1,offset:i=[0,0]}=t,s=f.suspend((()=>fetch("https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master/normals/normals.json").then((e=>e.json()))),["normalsList"]),l=C.useMemo((()=>Object.keys(s).length),[]),c=s[0],u=`https://rawcdn.githack.com/pmndrs/drei-assets/7a3104997e1576f83472829815b00880d88b32fb/normals/${s[e]||c}`,d=ge(u,r);return C.useLayoutEffect((()=>{d&&(d.wrapS=d.wrapT=n.RepeatWrapping,d.repeat=new n.Vector2(o[0],o[1]),d.offset=new n.Vector2(i[0],i[1]),d.anisotropy=a)}),[d,a,o,i]),[d,u,l]},exports.usePerformanceMonitor=function({onIncline:e,onDecline:r,onChange:n,onFallback:o}){const a=t.useContext(Kn),i=t.useRef({onIncline:e,onDecline:r,onChange:n,onFallback:o});t.useLayoutEffect((()=>{i.current.onIncline=e,i.current.onDecline=r,i.current.onChange=n,i.current.onFallback=o}),[e,r,n,o]),t.useLayoutEffect((()=>a.subscribe(i)),[a])},exports.useProgress=q,exports.useScroll=K,exports.useSelect=function(){return C.useContext(re)},exports.useSurfaceSampler=Pe,exports.useTexture=ge,exports.useTrail=Ce,exports.useTrailTexture=function(e={}){const{size:r,maxAge:n,radius:a,intensity:i,interpolate:s,smoothing:l,minForce:c,blend:u,ease:d}=e,m=t.useMemo((()=>new Ft(e)),[r,n,a,i,s,l,c,u,d]);o.useFrame(((e,t)=>{m.update(t)}));const f=t.useCallback((e=>m.addTouch(e.uv)),[m]);return[m.texture,f]},exports.useVideoTexture=function(e,r){const{unsuspend:n,start:a,crossOrigin:i,muted:s,loop:l,...c}={unsuspend:"loadedmetadata",crossOrigin:"Anonymous",muted:!0,loop:!0,start:!0,playsInline:!0,...r},u=o.useThree((e=>e.gl)),d=f.suspend((()=>new Promise(((t,r)=>{const o=Object.assign(document.createElement("video"),{src:e,crossOrigin:i,loop:l,muted:s,...c}),a=new P.VideoTexture(o);a.encoding=u.outputEncoding,o.addEventListener(n,(()=>t(a)))}))),[e]);return t.useEffect((()=>{a&&d.image.play()}),[d,a]),d};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/drei",
3
- "version": "9.51.10",
3
+ "version": "9.51.11",
4
4
  "private": false,
5
5
  "description": "useful add-ons for react-three-fiber",
6
6
  "keywords": [