@react-three/drei 9.56.0 → 9.56.1
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"),a=require("@react-three/fiber"),r=require("./useFBO.cjs.js"),o=require("../materials/DiscardMaterial.cjs.js");function i(n){return n&&"object"==typeof n&&"default"in n?n:{default:n}}function s(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)}require("./shaderMaterial.cjs.js");var l=i(n),c=s(e),m=s(t);class u extends c.MeshPhysicalMaterial{constructor(n=6,e=!1){super(),this.uniforms={chromaticAberration:{value:.05},transmission:{value:0},_transmission:{value:1},transmissionMap:{value:null},roughness:{value:0},thickness:{value:0},thicknessMap:{value:null},attenuationDistance:{value:1/0},attenuationColor:{value:new c.Color("white")},anisotropy:{value:.1},time:{value:0},distortion:{value:0},distortionScale:{value:.5},temporalDistortion:{value:0},buffer:{value:null}},this.onBeforeCompile=t=>{t.uniforms={...t.uniforms,...this.uniforms},e?t.defines.USE_SAMPLER="":t.defines.USE_TRANSMISSION="",t.fragmentShader="\n uniform float chromaticAberration; \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 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 m &= ieeeMantissa; // Keep only mantissa bits (fractional part)\n m |= ieeeOne; // Add fractional part to 1.0\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 float framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior ); \n #ifdef USE_SAMPLER\n #ifdef texture2DLodEXT\n return texture2DLodEXT(transmissionSamplerMap, fragCoord.xy, framebufferLod);\n #else\n return texture2D(transmissionSamplerMap, fragCoord.xy, framebufferLod);\n #endif\n #else\n return texture2D(buffer, fragCoord.xy);\n #endif\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 // 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 f=m.forwardRef((({buffer:n,transmissionSampler:e=!1,backside:t=!1,transmission:i=1,thickness:s=0,ior:f=1.5,samples:d=10,resolution:v,backsideResolution:h,background:p,...x},g)=>{a.extend({MeshTransmissionMaterial:u});const M=m.useRef(null),[S]=m.useState((()=>new o.DiscardMaterial)),C=r.useFBO(h||v),y=r.useFBO(v);let b,w,k;return a.useFrame((a=>{M.current.time=a.clock.getElapsedTime(),n||e||(k=M.current.__r3f.parent,k&&(w=a.gl.toneMapping,b=a.scene.background,a.gl.toneMapping=c.NoToneMapping,p&&(a.scene.background=p),k.material=S,t&&(a.gl.setRenderTarget(C),a.gl.render(a.scene,a.camera),k.material=M.current,k.material.buffer=C.texture,k.material.thickness=0,k.material.ior=1,k.material.side=c.BackSide),a.gl.setRenderTarget(y),a.gl.render(a.scene,a.camera),k.material=M.current,k.material.thickness=s,k.material.ior=f,k.material.side=c.FrontSide,k.material.buffer=y.texture,a.scene.background=b,a.gl.setRenderTarget(null),k.material=M.current,a.gl.toneMapping=w))})),m.useImperativeHandle(g,(()=>M.current),[]),m.createElement("meshTransmissionMaterial",l.default({args:[d,e],ref:M},x,{buffer:n||y.texture,_transmission:i,transmission:e?i:0,thickness:s,ior:f}))}));exports.MeshTransmissionMaterial=f;
|
|
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"),r=require("./useFBO.cjs.js"),o=require("../materials/DiscardMaterial.cjs.js");function i(n){return n&&"object"==typeof n&&"default"in n?n:{default:n}}function s(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)}require("./shaderMaterial.cjs.js");var l=i(n),c=s(e),m=s(t);class u extends c.MeshPhysicalMaterial{constructor(n=6,e=!1){super(),this.uniforms={chromaticAberration:{value:.05},transmission:{value:0},_transmission:{value:1},transmissionMap:{value:null},roughness:{value:0},thickness:{value:0},thicknessMap:{value:null},attenuationDistance:{value:1/0},attenuationColor:{value:new c.Color("white")},anisotropy:{value:.1},time:{value:0},distortion:{value:0},distortionScale:{value:.5},temporalDistortion:{value:0},buffer:{value:null}},this.onBeforeCompile=t=>{t.uniforms={...t.uniforms,...this.uniforms},e?t.defines.USE_SAMPLER="":t.defines.USE_TRANSMISSION="",t.fragmentShader="\n uniform float chromaticAberration; \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 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 m &= ieeeMantissa; // Keep only mantissa bits (fractional part)\n m |= ieeeOne; // Add fractional part to 1.0\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 float framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior ); \n #ifdef USE_SAMPLER\n #ifdef texture2DLodEXT\n return texture2DLodEXT(transmissionSamplerMap, fragCoord.xy, framebufferLod);\n #else\n return texture2D(transmissionSamplerMap, fragCoord.xy, framebufferLod);\n #endif\n #else\n return texture2D(buffer, fragCoord.xy);\n #endif\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 // 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 f=m.forwardRef((({buffer:n,transmissionSampler:e=!1,backside:t=!1,transmission:i=1,thickness:s=0,samples:f=10,resolution:d,backsideResolution:v,background:h,...p},x)=>{a.extend({MeshTransmissionMaterial:u});const g=m.useRef(null),[M]=m.useState((()=>new o.DiscardMaterial)),S=r.useFBO(v||d),C=r.useFBO(d);let y,b,w;return a.useFrame((a=>{g.current.time=a.clock.getElapsedTime(),n||e||(w=g.current.__r3f.parent,w&&(b=a.gl.toneMapping,y=a.scene.background,a.gl.toneMapping=c.NoToneMapping,h&&(a.scene.background=h),w.material=M,t&&(a.gl.setRenderTarget(S),a.gl.render(a.scene,a.camera),w.material=g.current,w.material.buffer=S.texture,w.material.thickness=1/(s+.01),w.material.side=c.BackSide),a.gl.setRenderTarget(C),a.gl.render(a.scene,a.camera),w.material=g.current,w.material.thickness=s,w.material.side=c.FrontSide,w.material.buffer=C.texture,a.scene.background=y,a.gl.setRenderTarget(null),w.material=g.current,a.gl.toneMapping=b))})),m.useImperativeHandle(x,(()=>g.current),[]),m.createElement("meshTransmissionMaterial",l.default({args:[f,e],ref:g},p,{buffer:n||C.texture,_transmission:i,transmission:e?i:0,thickness:s}))}));exports.MeshTransmissionMaterial=f;
|
|
@@ -310,7 +310,6 @@ const MeshTransmissionMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
310
310
|
backside = false,
|
|
311
311
|
transmission = 1,
|
|
312
312
|
thickness = 0,
|
|
313
|
-
ior = 1.5,
|
|
314
313
|
samples = 10,
|
|
315
314
|
resolution,
|
|
316
315
|
backsideResolution,
|
|
@@ -351,8 +350,7 @@ const MeshTransmissionMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
351
350
|
|
|
352
351
|
parent.material = ref.current;
|
|
353
352
|
parent.material.buffer = fboBack.texture;
|
|
354
|
-
parent.material.thickness = 0;
|
|
355
|
-
parent.material.ior = 1.0;
|
|
353
|
+
parent.material.thickness = 1.0 / (thickness + 0.01);
|
|
356
354
|
parent.material.side = THREE.BackSide;
|
|
357
355
|
} // Render into the main buffer
|
|
358
356
|
|
|
@@ -361,7 +359,6 @@ const MeshTransmissionMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
361
359
|
state.gl.render(state.scene, state.camera);
|
|
362
360
|
parent.material = ref.current;
|
|
363
361
|
parent.material.thickness = thickness;
|
|
364
|
-
parent.material.ior = ior;
|
|
365
362
|
parent.material.side = THREE.FrontSide;
|
|
366
363
|
parent.material.buffer = fboMain.texture; // Set old state back
|
|
367
364
|
|
|
@@ -386,8 +383,7 @@ const MeshTransmissionMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
386
383
|
// The exception is when transmissionSampler is set, in which case we are using three's built in sampler.
|
|
387
384
|
,
|
|
388
385
|
transmission: transmissionSampler ? transmission : 0,
|
|
389
|
-
thickness: thickness
|
|
390
|
-
ior: ior
|
|
386
|
+
thickness: thickness
|
|
391
387
|
}));
|
|
392
388
|
});
|
|
393
389
|
|
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("maath"),l=require("@react-spring/three"),c=require("@use-gesture/react"),u=require("zustand/middleware"),d=require("three-stdlib"),m=require("zustand/shallow"),f=require("troika-three-text"),p=require("suspend-react"),h=require("meshline"),v=require("lodash.pick"),g=require("lodash.omit"),x=require("camera-controls"),y=require("stats.js"),w=require("detect-gpu"),M=require("three-mesh-bvh"),E=require("react-composer"),b=require("lodash.clamp");function S(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function T(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 P=S(e),C=T(t),R=T(r),D=T(n),z=S(a),_=S(i),F=S(m),k=S(v),L=S(g),A=S(x),B=S(y),U=S(E),I=S(b);const V=new n.Vector3,j=new n.Vector3,O=new n.Vector3;function W(e,t,r){const n=V.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 G=e=>Math.abs(e)<1e-10?0:e;function N(e,t,r=""){let n="matrix3d(";for(let r=0;16!==r;r++)n+=G(t[r]*e.elements[r])+(15!==r?",":")");return r+n}const H=($=[1,-1,1,1,1,-1,1,1,1,-1,1,1,1,-1,1,1],e=>N(e,$));var $;const q=(e,t)=>{return N(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 X=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=W,as:M="div",wrapperClass:E,pointerEvents:b="auto",...S},T)=>{const{gl:D,camera:z,scene:_,size:F,raycaster:k,events:L,viewport:A}=o.useThree(),[B]=C.useState((()=>document.createElement(M))),U=C.useRef(),I=C.useRef(null),N=C.useRef(0),$=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(I.current){const e=U.current=R.createRoot(B);if(_.updateMatrixWorld(),m)B.style.cssText="position:absolute;top:0;left:0;pointer-events:none;overflow:hidden;";else{const e=w(I.current,z,F);B.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(B):Z.appendChild(B)),()=>{Z&&Z.removeChild(B),e.unmount()}}}),[Z,m]),C.useLayoutEffect((()=>{E&&(B.className=E)}),[E]);const ee=C.useMemo((()=>m?{position:"absolute",top:0,left:0,width:F.width,height:F.height,transformStyle:"preserve-3d",pointerEvents:"none"}:{position:"absolute",transform:s?"translate3d(-50%,-50%,0)":"none",...l&&{top:-F.height/2,left:-F.width/2,width:F.width,height:F.height},...r}),[r,s,l,F,m]),te=C.useMemo((()=>({position:"absolute",pointerEvents:b})),[b]);C.useLayoutEffect((()=>{var t,n;(Q.current=!1,m)?null==(t=U.current)||t.render(C.createElement("div",{ref:X,style:ee},C.createElement("div",{ref:Y,style:te},C.createElement("div",{ref:T,className:a,style:r,children:e})))):null==(n=U.current)||n.render(C.createElement("div",{ref:T,style:ee,className:a,children:e}))}));const re=C.useRef(!0);o.useFrame((e=>{if(I.current){z.updateMatrixWorld(),I.current.updateWorldMatrix(!0,!1);const e=m?$.current:w(I.current,z,F);if(m||Math.abs(N.current-z.zoom)>t||Math.abs($.current[0]-e[0])>t||Math.abs($.current[1]-e[1])>t){const t=function(e,t){const r=V.setFromMatrixPosition(e.matrixWorld),n=j.setFromMatrixPosition(t.matrixWorld),o=r.sub(n),a=t.getWorldDirection(O);return o.angleTo(a)>Math.PI/2}(I.current,z);let r=!1;J&&("blending"!==f?r=[_]:Array.isArray(f)&&(r=f.map((e=>e.current))));const o=re.current;if(r){const e=function(e,t,r,n){const o=V.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}(I.current,z,k,r);re.current=e&&!t}else re.current=!t;o!==re.current&&(p?p(!re.current):B.style.display=re.current?"block":"none");const a=Math.floor(y[0]/2),i=f?J?[y[0],a]:[a-1,0]:y;if(B.style.zIndex=`${function(e,t,r){if(t instanceof n.PerspectiveCamera||t instanceof n.OrthographicCamera){const n=V.setFromMatrixPosition(e.matrixWorld),o=j.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)}}(I.current,z,i)}`,m){const[e,t]=[F.width/2,F.height/2],r=z.projectionMatrix.elements[5]*t,{isOrthographicCamera:n,top:o,left:a,bottom:i,right:s}=z,l=H(z.matrixWorldInverse),c=n?`scale(${r})translate(${G(-(s+a)/2)}px,${G((o+i)/2)}px)`:`translateZ(${r}px)`;let m=I.current.matrixWorld;d&&(m=z.matrixWorldInverse.clone().transpose().copyPosition(m).scale(I.current.scale),m.elements[3]=m.elements[7]=m.elements[11]=0,m.elements[15]=1),B.style.width=F.width+"px",B.style.height=F.height+"px",B.style.perspective=n?"":`${r}px`,X.current&&Y.current&&(X.current.style.transform=`${c}${l}translate(${e}px,${t}px)`,Y.current.style.transform=q(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=V.setFromMatrixPosition(e.matrixWorld),n=j.setFromMatrixPosition(t.matrixWorld),o=t.fov*Math.PI/180,a=r.distanceTo(n);return 1/(2*Math.tan(o/2)*a)}return 1}(I.current,z)*u;B.style.transform=`translate3d(${e[0]}px,${e[1]}px,0) scale(${t})`}$.current=e,N.current=z.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}=z;if(t||x)S.scale&&(Array.isArray(S.scale)?S.scale instanceof n.Vector3?K.current.scale.copy(S.scale.clone().divideScalar(1)):K.current.scale.set(1/S.scale[0],1/S.scale[1],1/S.scale[2]):K.current.scale.setScalar(1/S.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=B.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",P.default({},S,{ref:I}),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 Y=0;const Z=z.default((e=>(n.DefaultLoadingManager.onStart=(t,r,n)=>{e({active:!0,item:t,loaded:r,total:n,progress:(r-Y)/(n-Y)*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&&(Y=n),e({active:!0,item:t,loaded:r,total:n,progress:(r-Y)/(n-Y)*100||100})},{errors:[],active:!1,progress:0,item:"",loaded:0,total:0}))),K=e=>`Loading ${e.toFixed(2)}%`;const Q={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"}},J=C.createContext(null);function ee(){return C.useContext(J)}const te=C.forwardRef((({children:e},t)=>{const r=C.useRef(null),n=ee(),{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:_.default([t,r])},e)})),re=C.forwardRef((({children:e,style:t,...r},n)=>{const a=ee(),i=C.useRef(null),{width:s,height:l}=o.useThree((e=>e.size)),c=C.useContext(o.context),u=C.useMemo((()=>R.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",P.default({ref:_.default([n,i]),style:{...t,position:"absolute",top:0,left:0,willChange:"transform"}},r),C.createElement(J.Provider,{value:a},C.createElement(o.context.Provider,{value:c},e)))),null})),ne=C.forwardRef((({html:e,...t},r)=>{const n=e?re:te;return C.createElement(n,P.default({ref:r},t))}));const oe=C.createContext(null);const ae=C.createContext([]);const ie=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",P.default({ref:_.default([s,i])},a))})),se=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",P.default({ref:_.default([n,a])},r),C.createElement("group",{"position-z":-t},e))})),le=C.forwardRef((function({points:e,color:t="black",vertexColors:r,linewidth:a,lineWidth:i,segments:s,dashed:l,...c},u){const m=o.useThree((e=>e.size)),f=C.useMemo((()=>s?new d.LineSegments2:new d.Line2),[s]),[p]=C.useState((()=>new d.LineMaterial)),h=C.useMemo((()=>{const t=s?new d.LineSegmentsGeometry:new d.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,s,r]);return C.useLayoutEffect((()=>{f.computeLineDistances()}),[e,f]),C.useLayoutEffect((()=>{l?p.defines.USE_DASH="":delete p.defines.USE_DASH,p.needsUpdate=!0}),[l,p]),C.useEffect((()=>()=>h.dispose()),[h]),C.createElement("primitive",P.default({object:f,ref:u},c),C.createElement("primitive",{object:h,attach:"geometry"}),C.createElement("primitive",P.default({object:p,attach:"material",color:t,vertexColors:Boolean(r),resolution:[m.width,m.height],linewidth:null!=a?a:i,dashed:l},c)))})),ce=new n.Vector3,ue=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(ce.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(le,P.default({ref:_.default([s,i]),points:u},a))})),de=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(le,P.default({ref:s,points:l},i))})),me=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(le,P.default({ref:l,points:u,vertexColors:d},s))})),fe=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",P.default({ref:_.default([l,s]),args:[u]},i))})),pe=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 f.Text)),[m,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 p.suspend((()=>new Promise((e=>f.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",P.default({object:d,ref:c,font:r,text:h,anchorX:e,anchorY:t,fontSize:n},l),m)})),he=["string","number"],ve=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:u=0,bevelSegments:m=4,curveSegments:f=8,children:h,...v},g)=>{C.useMemo((()=>o.extend({RenamedTextGeometry:d.TextGeometry})),[]);const x=p.suspend((async()=>{let t="string"==typeof e?await(await fetch(e)).json():e;return(new d.FontLoader).parse(t)}),[e]),y=t.useMemo((()=>({font:x,size:a,height:i,bevelThickness:s,bevelSize:l,bevelEnabled:c,bevelSegments:m,bevelOffset:u,curveSegments:f,letterSpacing:r,lineHeight:n})),[x,a,i,s,l,c,m,u,f,r,n]),[w,...M]=t.useMemo((()=>(e=>{let t="";const r=[];return C.Children.forEach(e,(e=>{he.includes(typeof e)?t+=e+"":r.push(e)})),[t,...r]})(h)),[h]),E=C.useMemo((()=>[w,y]),[w,y]);return C.createElement("mesh",P.default({},v,{ref:g}),C.createElement("renamedTextGeometry",{args:E}),M)})),ge=C.forwardRef((({children:e,multisamping:t=8,renderIndex:r=1,disableRender:a,disableGamma:i,disableRenderPass:s,depthBuffer:l=!0,stencilBuffer:c=!1,anisotropy:u=1,encoding:m,type:f,...p},h)=>{C.useMemo((()=>o.extend({EffectComposer:d.EffectComposer,RenderPass:d.RenderPass,ShaderPass:d.ShaderPass})),[]);const v=C.useRef(),{scene:g,camera:x,gl:y,size:w,viewport:M}=o.useThree(),[E]=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:u});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(M.dpr)}),[y,w,M.dpr]),o.useFrame((()=>{var e;a||null==(e=v.current)||e.render()}),r);const b=[];return s||b.push(C.createElement("renderPass",{key:"renderpass",attach:`passes-${b.length}`,args:[g,x]})),i||b.push(C.createElement("shaderPass",{attach:`passes-${b.length}`,key:"gammapass",args:[d.GammaCorrectionShader]})),C.Children.forEach(e,(e=>{e&&b.push(C.cloneElement(e,{key:b.length,attach:`passes-${b.length}`}))})),C.createElement("effectComposer",P.default({ref:_.default([h,v]),args:[y,E]},p),b)}));function xe(e,t,r,n){const o=class extends D.ShaderMaterial{constructor(o={}){const a=Object.entries(e);super({uniforms:a.reduce(((e,[t,r])=>({...e,...D.UniformsUtils.clone({[t]:{value:r}})})),{}),vertexShader:t,fragmentShader:r}),this.key="",a.forEach((([e])=>Object.defineProperty(this,e,{get:()=>this.uniforms[e].value,set:t=>this.uniforms[e].value=t}))),Object.assign(this,o),n&&n(this)}};return o.key=D.MathUtils.generateUUID(),o}const ye=e=>e===Object(e)&&!Array.isArray(e)&&"function"!=typeof e;function we(e,r){const a=o.useThree((e=>e.gl)),i=o.useLoader(n.TextureLoader,ye(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]),ye(e)){const t=Object.keys(e),r={};return t.forEach((e=>Object.assign(r,{[e]:i[t.indexOf(e)]}))),r}return i}we.preload=e=>o.useLoader.preload(n.TextureLoader,e),we.clear=e=>o.useLoader.clear(n.TextureLoader,e);const Me=xe({color:new D.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"),Ee=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:Me});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",P.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)})),be=C.forwardRef((({url:e,...t},r)=>{const n=we(e);return C.createElement(Ee,P.default({},t,{texture:n,ref:r}))})),Se=C.forwardRef((({url:e,...t},r)=>C.createElement(Ee,P.default({},t,{ref:r})))),Te=C.forwardRef(((e,t)=>{if(e.url)return C.createElement(be,P.default({},e,{ref:t}));if(e.texture)return C.createElement(Se,P.default({},e,{ref:t}));throw new Error("<Image /> requires a url or texture")}));function Pe({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 D.EdgesGeometry(t,n))}})),C.createElement("lineSegments",P.default({ref:i,raycast:()=>null},a),t||C.createElement("lineBasicMaterial",{color:o}))}const Ce={width:.2,length:1,decay:1,local:!1,stride:0,interval:1},Re=(e,t=1)=>(e.set(e.subarray(t)),e.fill(-1/0,-t),e);function De(e,t){const{length:r,local:a,decay:i,interval:s,stride:l}={...Ce,...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||(Re(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 ze=C.forwardRef(((e,t)=>{const{children:r}=e,{width:a,length:i,decay:s,local:l,stride:c,interval:u}={...Ce,...e},{color:d="hotpink",attenuation:m,target:f}=e,p=o.useThree((e=>e.size)),v=o.useThree((e=>e.scene)),g=C.useRef(null),[x,y]=C.useState(null),w=De(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 M=C.useMemo((()=>new h.MeshLineGeometry),[]),E=C.useMemo((()=>{var e;const t=new h.MeshLineMaterial({lineWidth:.1*a,color:d,sizeAttenuation:1,resolution:new n.Vector2(p.width,p.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,p,r]);return C.useEffect((()=>{E.uniforms.resolution.value.set(p.width,p.height)}),[p]),o.useFrame((()=>{w.current&&M.setPoints(w.current,m)})),C.createElement("group",null,o.createPortal(C.createElement("mesh",{ref:t,geometry:M,material:E}),v),C.createElement("group",{ref:g},r))}));function _e(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 d.MeshSurfaceSampler(e.current);o&&l.setWeightAttribute(o),l.build();const c=new n.Vector3,u=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,u,m),"function"==typeof r?r({dummy:f,sampledMesh:e.current,position:c,normal:u,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 Fe=C.forwardRef((({isChild:e=!1,object:t,children:r,deep:n,castShadow:o,receiveShadow:a,inject:i,keys:s,...l},c)=>{var u;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 d.SkeletonUtils.clone(t)}return t}),[t,e]),Array.isArray(t))return C.createElement("group",P.default({},l,{ref:c}),t.map((e=>C.createElement(Fe,P.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=k.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 D.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,P.default({},p,l,{ref:c}),(null==(u=t)?void 0:u.children).map((e=>"Bone"===e.type?C.createElement("primitive",P.default({key:e.uuid,object:e},m)):C.createElement(Fe,P.default({key:e.uuid,object:e},m,{isChild:!0})))),r,f)})),ke=C.createContext(null),Le=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 d.MarchingCubes(e,null,r,n,t)),[e,t,r,n]),u=C.useMemo((()=>({getParent:()=>l})),[]);return o.useFrame((()=>{c.reset()}),-1),C.createElement(C.Fragment,null,C.createElement("primitive",P.default({object:c,ref:_.default([l,s])},i),C.createElement(ke.Provider,{value:u},a)))})),Ae=C.forwardRef((({strength:e=.5,subtract:t=12,color:r,...n},a)=>{const{getParent:i}=C.useContext(ke),s=C.useMemo((()=>i()),[i]),l=C.useRef(),c=new D.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",P.default({ref:_.default([a,l])},n))})),Be=C.forwardRef((({planeType:e="x",strength:t=.5,subtract:r=12,...n},a)=>{const{getParent:i}=C.useContext(ke),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",P.default({ref:_.default([a,l])},n))}));function Ue(e=[0,0,0]){return function(e){return Array.isArray(e)}(e)?e:e instanceof D.Vector3||e instanceof D.Euler?[e.x,e.y,e.z]:[e,e,e]}const Ie=t.forwardRef((function({src:e,skipFill:r,skipStrokes:a,fillMaterial:i,strokeMaterial:s,fillMeshProps:l,strokeMeshProps:c,...u},m){const f=o.useLoader(d.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=>d.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",P.default({ref:m},u),C.createElement("object3D",{scale:[1,-1,1]},f.paths.map(((e,o)=>{var u,m;return C.createElement(t.Fragment,{key:o},!r&&void 0!==(null==(u=e.userData)?void 0:u.style.fill)&&"none"!==e.userData.style.fill&&d.SVGLoader.createShapes(e).map(((t,r)=>C.createElement("mesh",P.default({key:r},l),C.createElement("shapeGeometry",{args:[t]}),C.createElement("meshBasicMaterial",P.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",P.default({key:r,geometry:p[o][r]},c),C.createElement("meshBasicMaterial",P.default({color:e.userData.style.stroke,opacity:e.userData.style.strokeOpacity,transparent:!0,side:n.DoubleSide,depthWrite:!1},s))))))}))))}));let Ve=null;function je(e,t,r){return n=>{r&&r(n),e&&(Ve||(Ve=new d.DRACOLoader),Ve.setDecoderPath("string"==typeof e?e:"https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),n.setDRACOLoader(Ve)),t&&n.setMeshoptDecoder("function"==typeof d.MeshoptDecoder?d.MeshoptDecoder():d.MeshoptDecoder)}}function Oe(e,t=!0,r=!0,n){return o.useLoader(d.GLTFLoader,e,je(t,r,n))}Oe.preload=(e,t=!0,r=!0,n)=>o.useLoader.preload(d.GLTFLoader,e,je(t,r,n)),Oe.clear=e=>o.useLoader.clear(d.GLTFLoader,e);const We=C.forwardRef((({src:e,...t},r)=>{const{scene:n}=Oe(e);return C.createElement(Fe,P.default({ref:r},t,{object:n}))}));function Ge(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=0,depth:d,...m}=c,f=C.useMemo((()=>{let e;return e=new D.WebGLRenderTarget(s,l,{minFilter:D.LinearFilter,magFilter:D.LinearFilter,encoding:n.outputEncoding,type:D.HalfFloatType,...m}),d&&(e.depthTexture=new D.DepthTexture(s,l,D.FloatType)),e.samples=u,e}),[]);return C.useLayoutEffect((()=>{f.setSize(s,l),u&&(f.samples=u)}),[u,f,s,l]),C.useEffect((()=>()=>f.dispose()),[]),f}const Ne=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=Ge(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",P.default({left:u.width/-2,right:u.width/2,top:u.height/2,bottom:u.height/-2,ref:_.default([d,s])},i),!v&&n),C.createElement("group",{ref:m},v&&n(f.texture)))})),He=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=Ge(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",P.default({ref:_.default([d,s])},i),!v&&a),C.createElement("group",{ref:m},v&&a(f.texture)))}));const $e=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)),u=o.useThree((e=>e.set)),m=r||s,[f]=C.useState((()=>new d.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 u({controls:f}),()=>u({controls:e})}}),[a,f]),f?C.createElement("primitive",P.default({ref:t,object:f},i)):null})),qe=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)),u=o.useThree((e=>e.events)),m=o.useThree((e=>e.get)),f=o.useThree((e=>e.set)),p=e||u.connected||c.domElement,h=C.useMemo((()=>new d.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",P.default({ref:r,object:h,args:[l,p]},i))})),Xe=C.forwardRef(((e={enableDamping:!0},t)=>{const{domElement:r,camera:n,makeDefault:a,onChange:i,onStart:s,onEnd:l,...c}=e,u=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 d.MapControls(x)),[x]);return C.useEffect((()=>{y.connect(g);const e=e=>{u(),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,u,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",P.default({ref:t,object:y,enableDamping:!0},c))})),Ye=C.forwardRef((({makeDefault:e,events:t,camera:r,regress:n,domElement:a,enableDamping:i=!0,onChange:s,onStart:l,onEnd:c,...u},m)=>{const f=o.useThree((e=>e.invalidate)),p=o.useThree((e=>e.camera)),h=o.useThree((e=>e.gl)),v=o.useThree((e=>e.events)),g=o.useThree((e=>e.setEvents)),x=o.useThree((e=>e.set)),y=o.useThree((e=>e.get)),w=o.useThree((e=>e.performance)),M=r||p,E=a||v.connected||h.domElement,b=C.useMemo((()=>new d.OrbitControls(M)),[M]);return o.useFrame((()=>{b.enabled&&b.update()}),-1),C.useEffect((()=>(b.connect(E),()=>{b.dispose()})),[E,n,b,f]),C.useEffect((()=>{t&&g({enabled:!0});const e=e=>{f(),n&&w.regress(),s&&s(e)},r=e=>{l&&l(e),t||g({enabled:!1})},o=e=>{c&&c(e),t||g({enabled:!0})};return b.addEventListener("change",e),b.addEventListener("start",r),b.addEventListener("end",o),()=>{b.removeEventListener("start",r),b.removeEventListener("end",o),b.removeEventListener("change",e)}}),[s,l,c,b,f,t,g]),C.useEffect((()=>{if(e){const e=y().controls;return x({controls:b}),()=>x({controls:e})}}),[e,b]),C.createElement("primitive",P.default({ref:m,object:b,enableDamping:i},u))})),Ze=C.forwardRef((({makeDefault:e,camera:t,domElement:r,regress:n,onChange:a,onStart:i,onEnd:s,...l},c)=>{const{invalidate:u,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,M=C.useMemo((()=>new d.TrackballControls(y)),[y]);return o.useFrame((()=>{M.enabled&&M.update()}),-1),C.useEffect((()=>(M.connect(w),()=>{M.dispose()})),[w,n,M,u]),C.useEffect((()=>{const e=e=>{u(),n&&g.regress(),a&&a(e)};return M.addEventListener("change",e),i&&M.addEventListener("start",i),s&&M.addEventListener("end",s),()=>{i&&M.removeEventListener("start",i),s&&M.removeEventListener("end",s),M.removeEventListener("change",e)}}),[a,i,s,M,u]),C.useEffect((()=>{M.handleResize()}),[x]),C.useEffect((()=>{if(e){const e=v().controls;return h({controls:M}),()=>h({controls:e})}}),[e,M]),C.createElement("primitive",P.default({ref:c,object:M},l))})),Ke=t.forwardRef((({camera:e,makeDefault:r,regress:n,domElement:a,onChange:i,onStart:s,onEnd:l,...c},u)=>{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,M=t.useMemo((()=>new d.ArcballControls(y)),[y]);return o.useFrame((()=>{M.enabled&&M.update()}),-1),t.useEffect((()=>(M.connect(w),()=>{M.dispose()})),[w,n,M,m]),t.useEffect((()=>{const e=e=>{m(),n&&x.regress(),i&&i(e)};return M.addEventListener("change",e),s&&M.addEventListener("start",s),l&&M.addEventListener("end",l),()=>{M.removeEventListener("change",e),s&&M.removeEventListener("start",s),l&&M.removeEventListener("end",l)}}),[i,s,l]),t.useEffect((()=>{if(r){const e=g().controls;return v({controls:M}),()=>v({controls:e})}}),[r,M]),C.createElement("primitive",P.default({ref:u,object:M},c))})),Qe=C.forwardRef((({children:e,domElement:t,onChange:r,onMouseDown:n,onMouseUp:a,onObjectChange:i,object:s,makeDefault:l,...c},u)=>{const m=["enabled","axis","mode","translationSnap","rotationSnap","scaleSnap","space","size","showX","showY","showZ"],{camera:f,...p}=c,h=k.default(p,m),v=L.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)),M=o.useThree((e=>e.invalidate)),E=o.useThree((e=>e.get)),b=o.useThree((e=>e.set)),S=f||w,T=t||y.connected||x.domElement,R=C.useMemo((()=>new d.TransformControls(S,T)),[S,T]),z=C.useRef();C.useLayoutEffect((()=>(s?R.attach(s instanceof D.Object3D?s:s.current):z.current instanceof D.Object3D&&R.attach(z.current),()=>{R.detach()})),[s,e,R]),C.useEffect((()=>{if(g){const e=e=>g.enabled=!e.value;return R.addEventListener("dragging-changed",e),()=>R.removeEventListener("dragging-changed",e)}}),[R,g]);const _=C.useRef(),F=C.useRef(),A=C.useRef(),B=C.useRef();return C.useLayoutEffect((()=>{_.current=r}),[r]),C.useLayoutEffect((()=>{F.current=n}),[n]),C.useLayoutEffect((()=>{A.current=a}),[a]),C.useLayoutEffect((()=>{B.current=i}),[i]),C.useEffect((()=>{const e=e=>{M(),null==_.current||_.current(e)},t=e=>null==F.current?void 0:F.current(e),r=e=>null==A.current?void 0:A.current(e),n=e=>null==B.current?void 0:B.current(e);return R.addEventListener("change",e),R.addEventListener("mouseDown",t),R.addEventListener("mouseUp",r),R.addEventListener("objectChange",n),()=>{R.removeEventListener("change",e),R.removeEventListener("mouseDown",t),R.removeEventListener("mouseUp",r),R.removeEventListener("objectChange",n)}}),[M,R]),C.useEffect((()=>{if(l){const e=E().controls;return b({controls:R}),()=>b({controls:e})}}),[l,R]),R?C.createElement(C.Fragment,null,C.createElement("primitive",P.default({ref:u,object:R},h)),C.createElement("group",P.default({ref:z},v),e)):null})),Je=C.forwardRef((({domElement:e,selector:t,onChange:r,onLock:n,onUnlock:a,enabled:i=!0,makeDefault:s,...l},c)=>{const{camera:u,...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=u||h,M=e||g.connected||p.domElement,[E]=C.useState((()=>new d.PointerLockControls(w)));return C.useEffect((()=>{if(i){E.connect(M);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)}}),()=>{E.disconnect(),f({compute:e})}}}),[i,E]),C.useEffect((()=>{const e=e=>{v(),r&&r(e)};E.addEventListener("change",e),n&&E.addEventListener("lock",n),a&&E.addEventListener("unlock",a);const o=()=>E.lock(),i=t?Array.from(document.querySelectorAll(t)):[document];return i.forEach((e=>e&&e.addEventListener("click",o))),()=>{E.removeEventListener("change",e),n&&E.addEventListener("lock",n),a&&E.addEventListener("unlock",a),i.forEach((e=>e?e.removeEventListener("click",o):void 0))}}),[r,n,a,t,E,v]),C.useEffect((()=>{if(s){const e=x().controls;return y({controls:E}),()=>y({controls:e})}}),[s,E]),C.createElement("primitive",P.default({ref:c,object:E},m))})),et=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)),u=e||s.connected||i.domElement,[m]=C.useState((()=>new d.FirstPersonControls(a,u)));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",P.default({ref:n,object:m},r)):null})),tt=t.forwardRef(((e,r)=>{t.useMemo((()=>{A.default.install({THREE:D}),o.extend({CameraControlsImpl:A.default})}),[]);const{camera:n,domElement:a,onStart:i,onEnd:s,onChange:l,events:c,regress:u,...d}=e,m=o.useThree((e=>e.camera)),f=o.useThree((e=>e.gl)),p=o.useThree((e=>e.invalidate)),h=o.useThree((e=>e.events)),v=o.useThree((e=>e.setEvents)),g=o.useThree((e=>e.performance)),x=n||m,y=a||h.connected||f.domElement,w=t.useMemo((()=>new A.default(x)),[x]);return o.useFrame(((e,t)=>{w.enabled&&w.update(t)}),-1),t.useEffect((()=>(w.connect(y),()=>{w.disconnect()})),[y,w]),C.useEffect((()=>{c&&v({enabled:!0});const e=e=>{p(),u&&g.regress(),l&&l(e)},t=e=>{i&&i(e),c||v({enabled:!1})},r=e=>{s&&s(e),c||v({enabled:!0})};return w.addEventListener("control",e),w.addEventListener("controlstart",t),w.addEventListener("controlend",r),()=>{w.removeEventListener("control",e),w.removeEventListener("controlstart",t),w.removeEventListener("controlend",r)}}),[w,c,i,s,p,v,u,l]),C.createElement("primitive",P.default({ref:r,object:w},d))}));function rt({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 nt({children:e,renderPriority:t=1}){const{scene:r,camera:n}=o.useThree(),[a]=C.useState((()=>new D.Scene));return C.createElement(C.Fragment,null,o.createPortal(C.createElement(C.Fragment,null,e,C.createElement(rt,{defaultScene:r,defaultCamera:n,renderPriority:t})),a,{events:{priority:t+1}}))}const ot=C.createContext({}),at=()=>C.useContext(ot),it=2*Math.PI,st=new n.Object3D,lt=new n.Matrix4,[ct,ut]=[new n.Quaternion,new n.Quaternion],dt=new n.Vector3,mt=new n.Vector3,ft="#f0f0f0",pt="#999",ht="black",vt="black",gt=["Right","Left","Top","Bottom","Front","Back"],xt=e=>new n.Vector3(...e).multiplyScalar(.38),yt=[[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(xt),wt=[.25,.25,.25],Mt=[[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(xt),Et=Mt.map((e=>e.toArray().map((e=>0==e?.5:.25)))),bt=({hover:e,index:t,font:r="20px Inter var, Arial, sans-serif",faces:a=gt,color:i=ft,hoverColor:s=pt,textColor:l=ht,strokeColor:c=vt,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})},St=e=>{const{tweenCamera:t}=at(),[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(bt,P.default({key:n,index:n,hover:r===n},e)))),C.createElement("boxGeometry",null))},Tt=({onClick:e,dimensions:t,position:r,hoverColor:n=pt})=>{const{tweenCamera:o}=at(),[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 Pt({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 Ct({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",P.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 Rt=xe({cellSize:.5,sectionSize:1,fadeDistance:100,fadeStrength:1,cellThickness:.5,sectionThickness:1,cellColor:new D.Color,sectionColor:new D.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 }"),Dt=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,side:m=D.BackSide,...f},p)=>{o.extend({GridMaterial:Rt});const h={cellSize:n,sectionSize:a,cellColor:t,sectionColor:r,cellThickness:u,sectionThickness:d},v={fadeDistance:l,fadeStrength:c,infiniteGrid:s,followCamera:i};return C.createElement("mesh",P.default({ref:p,frustumCulled:!1},f),C.createElement("gridMaterial",P.default({transparent:!0,"extensions-derivatives":!0,side:m},h,v)),C.createElement("planeGeometry",{args:e}))}));function zt(e,{path:t}){const[r]=o.useLoader(n.CubeTextureLoader,[e],(e=>e.setPath(t)));return r}function _t(e){return o.useLoader(d.FBXLoader,e)}zt.preload=(e,{path:t})=>o.useLoader.preload(n.CubeTextureLoader,[e],(e=>e.setPath(t))),_t.preload=e=>o.useLoader.preload(d.FBXLoader,e),_t.clear=e=>o.useLoader.clear(d.FBXLoader,e);const Ft="https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master";function kt(e,r=`${Ft}/basis/`){const n=o.useThree((e=>e.gl)),a=o.useLoader(d.KTX2Loader,ye(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]),ye(e)){const t=Object.keys(e),r={};return t.forEach((e=>Object.assign(r,{[e]:a[t.indexOf(e)]}))),r}return a}function Lt(e,t){"function"==typeof e?e(t):null!=e&&(e.current=t)}kt.preload=(e,t=`${Ft}/basis/`)=>o.useLoader.preload(d.KTX2Loader,e,(e=>{e.setTranscoderPath(t)})),kt.clear=e=>o.useLoader.clear(d.KTX2Loader,e);function At(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}const Bt=e=>e.isMesh;const Ut=C.forwardRef((({enabled:e=!0,firstHitOnly:t=!1,children:r,splitStrategy:a="SAH",verbose:i=!1,setBoundingBox:s=!0,maxDepth:l=40,maxLeafTris:c=10,...u},d)=>{const m=C.useRef(null),f=o.useThree((e=>e.raycaster));return C.useImperativeHandle(d,(()=>m.current),[]),C.useEffect((()=>{if(e){const e={splitStrategy:a,verbose:i,setBoundingBox:s,maxDepth:l,maxLeafTris:c},r=m.current;return f.firstHitOnly=t,r.traverse((t=>{Bt(t)&&!t.geometry.boundsTree&&t.raycast===n.Mesh.prototype.raycast&&(t.raycast=M.acceleratedRaycast,t.geometry.computeBoundsTree=M.computeBoundsTree,t.geometry.disposeBoundsTree=M.disposeBoundsTree,t.geometry.computeBoundsTree(e))})),()=>{delete f.firstHitOnly,r.traverse((e=>{Bt(e)&&e.geometry.boundsTree&&(e.geometry.disposeBoundsTree(),e.raycast=n.Mesh.prototype.raycast)}))}}})),C.createElement("group",P.default({ref:m},u),r)}));const It=new D.Box3,Vt=new D.Vector3;const jt=e=>Math.sqrt(1-Math.pow(e-1,2));class Ot{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=jt}={}){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 Wt=C.forwardRef((({children:e,curve:t},r)=>{const[n]=C.useState((()=>new D.Scene)),[a,i]=C.useState(),s=C.useRef();return C.useEffect((()=>{s.current=new d.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 Gt 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 Nt=C.forwardRef((({speed:e=1,...t},r)=>{const[n]=C.useState((()=>new Gt));return o.useFrame((t=>n&&(n.time=t.clock.getElapsedTime()*e))),C.createElement("primitive",P.default({object:n,ref:r,attach:"material"},t))}));class Ht 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 $t=C.forwardRef((({speed:e=1,...t},r)=>{const[n]=C.useState((()=>new Ht));return o.useFrame((t=>n&&(n.time=t.clock.getElapsedTime()*e))),C.createElement("primitive",P.default({object:n,ref:r,attach:"material"},t))}));class qt 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 Xt{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 qt,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 Yt 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:Yt});const Zt=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,M=C.useRef(null),[E]=C.useState((()=>new n.Plane)),[b]=C.useState((()=>new n.Vector3)),[S]=C.useState((()=>new n.Vector3)),[T]=C.useState((()=>new n.Vector3)),[R]=C.useState((()=>new n.Matrix4)),[D]=C.useState((()=>new n.Vector3(0,0,-1))),[z]=C.useState((()=>new n.Vector4)),[F]=C.useState((()=>new n.Vector3)),[k]=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=M.current.parent||(null==(e=M.current)?void 0:e.__r3f.parent);if(!t)return;if(S.setFromMatrixPosition(t.matrixWorld),T.setFromMatrixPosition(x.matrixWorld),R.extractRotation(t.matrixWorld),b.set(0,0,1),b.applyMatrix4(R),S.addScaledVector(b,p),F.subVectors(S,T),F.dot(b)>0)return;F.reflect(b).negate(),F.add(S),R.extractRotation(x.matrixWorld),D.set(0,0,-1),D.applyMatrix4(R),D.add(T),k.subVectors(S,D),k.reflect(b).negate(),k.add(S),B.position.copy(F),B.up.set(0,1,0),B.up.applyMatrix4(R),B.up.reflect(b),B.lookAt(k),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),E.setFromNormalAndCoplanarPoint(b,S),E.applyMatrix4(B.matrixWorldInverse),z.set(E.normal.x,E.normal.y,E.normal.z,E.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]),[I,V,j,O]=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 Xt({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=M.current.parent||(null==(e=M.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(I),g.state.buffers.depth.setMask(!0),g.autoClear||g.clear(),g.render(y,B),w&&j.render(g,I,V),g.xr.enabled=r,g.shadowMap.autoUpdate=n,t.visible=!0,g.setRenderTarget(null)})),C.createElement("meshReflectorMaterialImpl",P.default({attach:"material",key:"key"+O["defines-USE_BLUR"]+O["defines-USE_DEPTH"]+O["defines-USE_DISTORTION"],ref:_.default([M,v])},O,h))})),Kt=xe({envMap:null,bounces:3,ior:2.4,correctMips:!0,aberrationStrength:.01,fresnel:0,bvh:new M.MeshBVHUniformStruct,color:new D.Color("white"),resolution:new D.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 ${M.shaderStructs}\n ${M.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 }`);const Qt=xe({},"void main() { }","void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); discard; }");class Jt extends D.MeshPhysicalMaterial{constructor(e=6,t=!1){super(),this.uniforms={chromaticAberration:{value:.05},transmission:{value:0},_transmission:{value:1},transmissionMap:{value:null},roughness:{value:0},thickness:{value:0},thicknessMap:{value:null},attenuationDistance:{value:1/0},attenuationColor:{value:new D.Color("white")},anisotropy:{value:.1},time:{value:0},distortion:{value:0},distortionScale:{value:.5},temporalDistortion:{value:0},buffer:{value:null}},this.onBeforeCompile=r=>{r.uniforms={...r.uniforms,...this.uniforms},t?r.defines.USE_SAMPLER="":r.defines.USE_TRANSMISSION="",r.fragmentShader="\n uniform float chromaticAberration; \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 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 m &= ieeeMantissa; // Keep only mantissa bits (fractional part)\n m |= ieeeOne; // Add fractional part to 1.0\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"+r.fragmentShader,r.fragmentShader=r.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 float framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior ); \n #ifdef USE_SAMPLER\n #ifdef texture2DLodEXT\n return texture2DLodEXT(transmissionSamplerMap, fragCoord.xy, framebufferLod);\n #else\n return texture2D(transmissionSamplerMap, fragCoord.xy, framebufferLod);\n #endif\n #else\n return texture2D(buffer, fragCoord.xy);\n #endif\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"),r.fragmentShader=r.fragmentShader.replace("#include <transmission_fragment>",` \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 er=C.forwardRef((({buffer:e,transmissionSampler:t=!1,backside:r=!1,transmission:n=1,thickness:a=0,ior:i=1.5,samples:s=10,resolution:l,backsideResolution:c,background:u,...d},m)=>{o.extend({MeshTransmissionMaterial:Jt});const f=C.useRef(null),[p]=C.useState((()=>new Qt)),h=Ge(c||l),v=Ge(l);let g,x,y;return o.useFrame((n=>{f.current.time=n.clock.getElapsedTime(),e||t||(y=f.current.__r3f.parent,y&&(x=n.gl.toneMapping,g=n.scene.background,n.gl.toneMapping=D.NoToneMapping,u&&(n.scene.background=u),y.material=p,r&&(n.gl.setRenderTarget(h),n.gl.render(n.scene,n.camera),y.material=f.current,y.material.buffer=h.texture,y.material.thickness=0,y.material.ior=1,y.material.side=D.BackSide),n.gl.setRenderTarget(v),n.gl.render(n.scene,n.camera),y.material=f.current,y.material.thickness=a,y.material.ior=i,y.material.side=D.FrontSide,y.material.buffer=v.texture,n.scene.background=g,n.gl.setRenderTarget(null),y.material=f.current,n.gl.toneMapping=x))})),C.useImperativeHandle(m,(()=>f.current),[]),C.createElement("meshTransmissionMaterial",P.default({args:[s,t],ref:f},d,{buffer:e||v.texture,_transmission:n,transmission:t?n:0,thickness:a,ior:i}))}));class tr extends D.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 rr=C.forwardRef(((e,t)=>{const[r]=C.useState((()=>new tr(null)));return C.createElement("primitive",P.default({},e,{object:r,ref:t,attach:"material"}))})),nr=({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 or=!1;function ar(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 ir(e){const t=e+"Geometry";return C.forwardRef((({args:e,children:r,...n},o)=>C.createElement("mesh",P.default({ref:o},n),C.createElement(t,{attach:"geometry",args:e}),r)))}const sr=ir("box"),lr=ir("circle"),cr=ir("cone"),ur=ir("cylinder"),dr=ir("sphere"),mr=ir("plane"),fr=ir("tube"),pr=ir("torus"),hr=ir("torusKnot"),vr=ir("tetrahedron"),gr=ir("ring"),xr=ir("polyhedron"),yr=ir("icosahedron"),wr=ir("octahedron"),Mr=ir("dodecahedron"),Er=ir("extrude"),br=ir("lathe"),Sr=ir("capsule"),Tr=1e-5;const Pr=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-Tr;return o.absarc(Tr,Tr,Tr,-Math.PI/2,-Math.PI,!0),o.absarc(Tr,t-2*a,Tr,Math.PI,Math.PI/2,!0),o.absarc(e-2*a,t-2*a,Tr,Math.PI/2,0,!0),o.absarc(e-2*a,Tr,Tr,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-Tr,bevelThickness:o,curveSegments:i})),[r,o,i]),m=C.useRef();return C.useLayoutEffect((()=>{m.current&&m.current.center()}),[u,d]),C.createElement("mesh",P.default({ref:c},l),C.createElement("extrudeGeometry",{ref:m,args:[u,d]}),s)}));function Cr(){const e=new D.BufferGeometry,t=new Float32Array([-1,-1,3,-1,-1,3]);return e.setAttribute("position",new D.BufferAttribute(t,2)),e}const Rr=C.forwardRef((function({children:e,...t},r){const n=C.useMemo(Cr,[]);return C.createElement("mesh",P.default({ref:r,geometry:n,frustumCulled:!1},t),e)})),Dr=C.forwardRef((function({children:e,disable:t,disableX:r,disableY:o,disableZ:a,left:i,right:s,top:l,bottom:c,front:u,back:d,onCentered:m,precise:f=!0,...p},h){const v=C.useRef(null),g=C.useRef(null),x=C.useRef(null);return C.useLayoutEffect((()=>{g.current.matrixWorld.identity();const e=(new n.Box3).setFromObject(x.current,f),p=new n.Vector3,h=new n.Sphere,y=e.max.x-e.min.x,w=e.max.y-e.min.y,M=e.max.z-e.min.z;e.getCenter(p),e.getBoundingSphere(h);const E=l?w/2:c?-w/2:0,b=i?-y/2:s?y/2:0,S=u?M/2:d?-M/2:0;g.current.position.set(t||r?0:-p.x+b,t||o?0:-p.y+E,t||a?0:-p.z+S),void 0!==m&&m({parent:v.current.parent,container:v.current,width:y,height:w,depth:M,boundingBox:e,boundingSphere:h,center:p,verticalAlignment:E,horizontalAlignment:b,depthAlignment:S})}),[e]),C.useImperativeHandle(h,(()=>v.current),[]),C.createElement("group",P.default({ref:v},p),C.createElement("group",{ref:g},C.createElement("group",{ref:x},e)))})),zr=e=>e&&e.isOrthographicCamera,_r=C.createContext(null);function Fr({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=D.MathUtils.damp(e.x,t.x,r,n),e.y=D.MathUtils.damp(e.y,t.y,r,n),e.z=D.MathUtils.damp(e.z,t.z,r,n)}h.current=l;const[x]=C.useState((()=>({animating:!1,focus:new D.Vector3,camera:new D.Vector3,zoom:1}))),[y]=C.useState((()=>({focus:new D.Vector3,camera:new D.Vector3,zoom:1}))),[w]=C.useState((()=>new D.Box3)),M=C.useMemo((()=>{function e(){const e=w.getSize(new D.Vector3),t=w.getCenter(new D.Vector3),r=Math.max(e.x,e.y,e.z),n=zr(u)?4*r:r/(2*Math.atan(Math.PI*u.fov/360)),o=zr(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 D.Vector3,new D.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),zr(u)){x.zoom=u.zoom;let e=0,n=0;const o=[new D.Vector3(w.min.x,w.min.y,w.min.z),new D.Vector3(w.min.x,w.max.y,w.min.z),new D.Vector3(w.min.x,w.min.y,w.max.z),new D.Vector3(w.min.x,w.max.y,w.max.z),new D.Vector3(w.max.x,w.max.y,w.max.z),new D.Vector3(w.max.x,w.max.y,w.min.z),new D.Vector3(w.max.x,w.min.y,w.max.z),new D.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 E=C.useRef(0);return C.useLayoutEffect((()=>{(a||0==E.current++)&&(M.refresh(),r&&M.fit(),n&&M.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=D.MathUtils.damp(x.zoom,y.zoom,t,r),u.position.copy(x.camera),zr(u)&&(u.zoom=x.zoom,u.updateProjectionMatrix()),p?(p.target.copy(x.focus),p.update()):u.lookAt(x.focus),d(),zr(u)&&!(Math.abs(x.zoom-y.zoom)<s))return;if(!zr(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(_r.Provider,{value:M},e))}function kr(){return C.useContext(_r)}const Lr=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},u)=>{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 d.SimplexNoise)),[g]=C.useState((()=>new d.SimplexNoise)),[x]=C.useState((()=>new d.SimplexNoise)),y=()=>{(p.current<0||p.current>1)&&(p.current=p.current<0?0:1)};return C.useImperativeHandle(u,(()=>({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})),Ar=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=D.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:_.default([l,s])},e))})),Br={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 Ur(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 Ir({scene:e,background:t=!1,blur:r,map:n}){const a=o.useThree((e=>e.scene));return C.useLayoutEffect((()=>{if(n)return Ur(t,e,a,n,r)}),[a,e,n,t,r]),null}function Vr({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 Br))throw new Error("Preset must be one of: "+Object.keys(Br).join(", "));e=Br[r],t="https://market-assets.fra1.cdn.digitaloceanspaces.com/market-assets/hdris/"}const s=Array.isArray(e),l=s?n.CubeTextureLoader:d.RGBELoader,c=o.useLoader(l,s?[e]:e,(e=>{e.setPath(t),i&&i(e)})),u=s?c[0]:c;return u.mapping=s?n.CubeReflectionMapping:n.EquirectangularReflectionMapping,u.encoding=(null!=a?a:s)?n.sRGBEncoding:n.LinearEncoding,u}function jr({background:e=!1,scene:t,blur:r,...n}){const a=Vr(n),i=o.useThree((e=>e.scene));return C.useLayoutEffect((()=>Ur(e,t,i,a,r)),[a,e,t,i,r]),null}function Or({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),Ur(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(jr,{background:!0,files:d,preset:f,path:m,extensions:p}):s?C.createElement(Ir,{background:!0,map:s,extensions:p}):null),x))}function Wr(e){var t,r,n,a;const i=Vr(e),s=e.map||i;C.useMemo((()=>o.extend({GroundProjectedEnvImpl:d.GroundProjectedEnv})),[]);const l=C.useMemo((()=>[s]),[s]),c=null==(t=e.ground)?void 0:t.height,u=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(Ir,P.default({},e,{map:s})),C.createElement("groundProjectedEnvImpl",{args:l,scale:m,height:c,radius:u}))}function Gr(e){return e.ground?C.createElement(Wr,e):e.map?C.createElement(Ir,e):e.children?C.createElement(Or,e):C.createElement(jr,e)}const Nr=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:u="#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,M,E,b,S,T]=C.useMemo((()=>{const e=new D.WebGLRenderTarget(l,l),t=new D.WebGLRenderTarget(l,l);t.texture.generateMipmaps=e.texture.generateMipmaps=!1;const r=new D.PlaneGeometry(n,a).rotateX(Math.PI/2),o=new D.Mesh(r),i=new D.MeshDepthMaterial;i.depthTest=i.depthWrite=!1,i.onBeforeCompile=e=>{e.uniforms={...e.uniforms,ucolor:{value:new D.Color(u)}},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 D.ShaderMaterial(d.HorizontalBlurShader),c=new D.ShaderMaterial(d.VerticalBlurShader);return c.depthTest=s.depthTest=!1,[e,r,i,o,s,c,t]}),[l,n,a,e,u]),R=e=>{E.visible=!0,E.material=b,b.uniforms.tDiffuse.value=y.texture,b.uniforms.h.value=1*e/256,g.setRenderTarget(T),g.render(E,x.current),E.material=S,S.uniforms.tDiffuse.value=T.texture,S.uniforms.v.value=1*e/256,g.setRenderTarget(y),g.render(E,x.current),E.visible=!1};let z=0;return o.useFrame((()=>{if(x.current&&(t===1/0||z<t)){const e=v.background;v.background=null;const t=v.overrideMaterial;v.overrideMaterial=M,g.setRenderTarget(y),g.render(v,x.current),v.overrideMaterial=t,R(i),c&&R(.4*i),g.setRenderTarget(null),v.background=e,z++}})),C.createElement("group",P.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 Hr=C.createContext(null),$r=xe({color:new D.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 }"),qr=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:$r});const h=o.useThree((e=>e.gl)),v=o.useThree((e=>e.scene)),g=o.useThree((e=>e.camera)),x=o.useThree((e=>e.invalidate)),y=C.useRef(null),w=C.useRef(null),[M]=C.useState((()=>new Yr(h,v,d)));C.useLayoutEffect((()=>{M.configure(y.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:()=>y.current,reset:()=>{M.clear();const e=y.current.material;e.opacity=0,e.alphaTest=0,E.count=0},update:(e=1)=>{const t=y.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),w.current.visible=!0,M.prepare();for(let t=0;t<e;t++)E.lights.forEach((e=>e.update())),M.update(g,E.blend);w.current.visible=!1,M.finish()}})),[M,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&&(x(),E.update(),E.count++)})),C.createElement("group",f,C.createElement("group",{traverse:()=>null,ref:w},C.createElement(Hr.Provider,{value:E},e)),C.createElement("mesh",{receiveShadow:!0,ref:y,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:M.progressiveLightMap2.texture})))})),Xr=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 D.Vector3(...s).length(),v=C.useContext(Hr),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]+D.MathUtils.randFloatSpread(l),s[1]+D.MathUtils.randFloatSpread(l),s[2]+D.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",P.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 Yr{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 D.Color,this.clearAlpha=0;const n=/(Android|iPad|iPhone|iPod)/g.test(navigator.userAgent)?D.HalfFloatType:D.FloatType;this.progressiveLightMap1=new D.WebGLRenderTarget(this.res,this.res,{type:n,encoding:e.outputEncoding}),this.progressiveLightMap2=new D.WebGLRenderTarget(this.res,this.res,{type:n,encoding:e.outputEncoding}),this.discardMat=new Qt,this.targetMat=new D.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 Zr={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 Kr({radius:e,adjustCamera:t}){const r=kr();return C.useEffect((()=>{t&&r.refresh().clip().fit()}),[e,t]),null}const Qr=e=>0===e?0:Math.pow(2,10*e-10);const Jr=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",P.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]})))}));function en(e=D.FrontSide){const t={value:new D.Matrix4};return Object.assign(new D.MeshNormalMaterial({side:e}),{viewMatrix:t,onBeforeCompile:e=>{e.uniforms.viewMatrix=t,e.fragmentShader="vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n }\n"+e.fragmentShader.replace("#include <normal_fragment_maps>","#include <normal_fragment_maps>\n normal = inverseTransformDirection( normal, viewMatrix );\n")}})}const tn=xe({causticsTexture:null,causticsTextureB:null,color:new D.Color,lightProjMatrix:new D.Matrix4,lightViewMatrix:new D.Matrix4},"varying vec3 vWorldPosition; \n void main() {\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);\n vec4 worldPosition = modelMatrix * vec4(position, 1.);\n vWorldPosition = worldPosition.xyz;\n }","varying vec3 vWorldPosition;\n uniform vec3 color;\n uniform sampler2D causticsTexture; \n uniform sampler2D causticsTextureB; \n uniform mat4 lightProjMatrix;\n uniform mat4 lightViewMatrix;\n void main() {\n // Apply caustics \n vec4 lightSpacePos = lightProjMatrix * lightViewMatrix * vec4(vWorldPosition, 1.0);\n lightSpacePos.xyz /= lightSpacePos.w;\n lightSpacePos.xyz = lightSpacePos.xyz * 0.5 + 0.5; \n vec3 front = texture2D(causticsTexture, lightSpacePos.xy).rgb;\n vec3 back = texture2D(causticsTextureB, lightSpacePos.xy).rgb;\n gl_FragColor = vec4((front + back) * color, 1.0);\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }"),rn=xe({cameraMatrixWorld:new D.Matrix4,cameraProjectionMatrixInv:new D.Matrix4,normalTexture:null,depthTexture:null,lightDir:new D.Vector3(0,1,0),lightPlaneNormal:new D.Vector3(0,1,0),lightPlaneConstant:0,near:.1,far:100,modelMatrix:new D.Matrix4,worldRadius:1/40,ior:1.1,bounces:0,resolution:1024,size:10,intensity:.5},"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }"," \n uniform mat4 cameraMatrixWorld;\n uniform mat4 cameraProjectionMatrixInv;\n uniform vec3 lightDir;\n uniform vec3 lightPlaneNormal;\n uniform float lightPlaneConstant;\n uniform float near;\n uniform float far;\n uniform float time;\n uniform float worldRadius;\n uniform float resolution;\n uniform float size;\n uniform float intensity;\n uniform float ior;\n precision highp isampler2D;\n precision highp usampler2D;\n uniform sampler2D normalTexture;\n uniform sampler2D depthTexture;\n uniform float bounces;\n varying vec2 vUv;\n vec3 WorldPosFromDepth(float depth, vec2 coord) {\n float z = depth * 2.0 - 1.0;\n vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);\n vec4 viewSpacePosition = cameraProjectionMatrixInv * clipSpacePosition;\n // Perspective division\n viewSpacePosition /= viewSpacePosition.w;\n vec4 worldSpacePosition = cameraMatrixWorld * viewSpacePosition;\n return worldSpacePosition.xyz;\n } \n float sdPlane( vec3 p, vec3 n, float h ) {\n // n must be normalized\n return dot(p,n) + h;\n }\n float planeIntersect( vec3 ro, vec3 rd, vec4 p ) {\n return -(dot(ro,p.xyz)+p.w)/dot(rd,p.xyz);\n }\n vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 pos, vec3 normal, float ior, out vec3 rayOrigin, out vec3 rayDirection) {\n rayOrigin = ro;\n rayDirection = rd;\n rayDirection = refract(rayDirection, normal, 1.0 / ior);\n rayOrigin = pos + rayDirection * 0.1;\n return rayDirection;\n }\n void main() {\n // Each sample consists of random offset in the x and y direction\n float caustic = 0.0;\n float causticTexelSize = (1.0 / resolution) * size * 2.0;\n float texelsNeeded = worldRadius / causticTexelSize;\n float sampleRadius = texelsNeeded / resolution;\n float sum = 0.0;\n if (texture2D(depthTexture, vUv).x == 1.0) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n return;\n }\n vec2 offset1 = vec2(-0.5, -0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 offset2 = vec2(-0.5, 0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 offset3 = vec2(0.5, 0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 offset4 = vec2(0.5, -0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 uv1 = vUv + offset1 * sampleRadius;\n vec2 uv2 = vUv + offset2 * sampleRadius;\n vec2 uv3 = vUv + offset3 * sampleRadius;\n vec2 uv4 = vUv + offset4 * sampleRadius;\n vec3 normal1 = texture2D(normalTexture, uv1, -10.0).rgb * 2.0 - 1.0;\n vec3 normal2 = texture2D(normalTexture, uv2, -10.0).rgb * 2.0 - 1.0;\n vec3 normal3 = texture2D(normalTexture, uv3, -10.0).rgb * 2.0 - 1.0;\n vec3 normal4 = texture2D(normalTexture, uv4, -10.0).rgb * 2.0 - 1.0;\n float depth1 = texture2D(depthTexture, uv1, -10.0).x;\n float depth2 = texture2D(depthTexture, uv2, -10.0).x;\n float depth3 = texture2D(depthTexture, uv3, -10.0).x;\n float depth4 = texture2D(depthTexture, uv4, -10.0).x;\n // Sanity check the depths\n if (depth1 == 1.0 || depth2 == 1.0 || depth3 == 1.0 || depth4 == 1.0) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n return;\n }\n vec3 pos1 = WorldPosFromDepth(depth1, uv1);\n vec3 pos2 = WorldPosFromDepth(depth2, uv2);\n vec3 pos3 = WorldPosFromDepth(depth3, uv3);\n vec3 pos4 = WorldPosFromDepth(depth4, uv4);\n vec3 originPos1 = WorldPosFromDepth(0.0, uv1);\n vec3 originPos2 = WorldPosFromDepth(0.0, uv2);\n vec3 originPos3 = WorldPosFromDepth(0.0, uv3);\n vec3 originPos4 = WorldPosFromDepth(0.0, uv4);\n vec3 endPos1, endPos2, endPos3, endPos4;\n vec3 endDir1, endDir2, endDir3, endDir4;\n totalInternalReflection(originPos1, lightDir, pos1, normal1, ior, endPos1, endDir1);\n totalInternalReflection(originPos2, lightDir, pos2, normal2, ior, endPos2, endDir2);\n totalInternalReflection(originPos3, lightDir, pos3, normal3, ior, endPos3, endDir3);\n totalInternalReflection(originPos4, lightDir, pos4, normal4, ior, endPos4, endDir4);\n float lightPosArea = length(cross(originPos2 - originPos1, originPos3 - originPos1)) + length(cross(originPos3 - originPos1, originPos4 - originPos1));\n float t1 = planeIntersect(endPos1, endDir1, vec4(lightPlaneNormal, lightPlaneConstant));\n float t2 = planeIntersect(endPos2, endDir2, vec4(lightPlaneNormal, lightPlaneConstant));\n float t3 = planeIntersect(endPos3, endDir3, vec4(lightPlaneNormal, lightPlaneConstant));\n float t4 = planeIntersect(endPos4, endDir4, vec4(lightPlaneNormal, lightPlaneConstant));\n vec3 finalPos1 = endPos1 + endDir1 * t1;\n vec3 finalPos2 = endPos2 + endDir2 * t2;\n vec3 finalPos3 = endPos3 + endDir3 * t3;\n vec3 finalPos4 = endPos4 + endDir4 * t4;\n float finalArea = length(cross(finalPos2 - finalPos1, finalPos3 - finalPos1)) + length(cross(finalPos3 - finalPos1, finalPos4 - finalPos1));\n caustic += intensity * (lightPosArea / finalArea);\n // Calculate the area of the triangle in light spaces\n gl_FragColor = vec4(vec3(max(caustic, 0.0)), 1.0);\n }"),nn={depth:!0,minFilter:D.LinearFilter,magFilter:D.LinearFilter,encoding:D.LinearEncoding,type:D.UnsignedByteType},on={minFilter:D.LinearMipmapLinearFilter,magFilter:D.LinearFilter,encoding:D.LinearEncoding,format:D.RGBAFormat,type:D.FloatType,generateMipmaps:!0},an=C.forwardRef((({debug:e,children:t,frames:r=1,ior:n=1.1,color:a="white",causticsOnly:i=!1,backside:s=!1,backsideIOR:l=1.1,worldRadius:c=.3125,intensity:u=.05,resolution:m=2024,lightSource:f=[5,5,5],...p},h)=>{o.extend({CausticsProjectionMaterial:tn});const v=C.useRef(null),g=C.useRef(null),x=C.useRef(null),y=C.useRef(null),w=o.useThree((e=>e.gl)),M=At(e&&g,D.CameraHelper),E=Ge(m,m,nn),b=Ge(m,m,nn),S=Ge(m,m,on),T=Ge(m,m,on),[R]=C.useState((()=>en())),[z]=C.useState((()=>en(D.BackSide))),[_]=C.useState((()=>new rn)),[F]=C.useState((()=>new d.FullScreenQuad(_)));C.useLayoutEffect((()=>{v.current.updateWorldMatrix(!1,!0)}));let k=0;const L=new D.Vector3,A=new D.Frustum,B=new D.Matrix4,U=new D.Plane,I=new D.Vector3,V=new D.Vector3,j=new D.Box3,O=new D.Vector3;return o.useFrame(((t,o)=>{if(r===1/0||k++<r){var a,d;Array.isArray(f)?I.fromArray(f).normalize():I.copy(v.current.worldToLocal(f.current.getWorldPosition(L)).normalize()),V.copy(I).multiplyScalar(-1);let t=[];null==(a=x.current.parent)||a.matrixWorld.identity(),j.setFromObject(x.current,!0),t.push(new D.Vector3(j.min.x,j.min.y,j.min.z)),t.push(new D.Vector3(j.min.x,j.min.y,j.max.z)),t.push(new D.Vector3(j.min.x,j.max.y,j.min.z)),t.push(new D.Vector3(j.min.x,j.max.y,j.max.z)),t.push(new D.Vector3(j.max.x,j.min.y,j.min.z)),t.push(new D.Vector3(j.max.x,j.min.y,j.max.z)),t.push(new D.Vector3(j.max.x,j.max.y,j.min.z)),t.push(new D.Vector3(j.max.x,j.max.y,j.max.z));const r=t.map((e=>e.clone()));j.getCenter(O),t=t.map((e=>e.clone().sub(O)));const o=U.set(V,0),p=t.map((e=>o.projectPoint(e,new D.Vector3))),h=p.reduce(((e,t)=>e.add(t)),L.set(0,0,0)).divideScalar(p.length),P=p.map((e=>e.distanceTo(h))).reduce(((e,t)=>Math.max(e,t))),C=t.map((e=>e.dot(I))).reduce(((e,t)=>Math.max(e,t)));g.current.position.copy(I.clone().multiplyScalar(C).add(O)),g.current.lookAt(x.current.localToWorld(O.clone()));const k=B.lookAt(g.current.position,O,L.set(0,1,0));g.current.left=-P,g.current.right=P,g.current.top=P,g.current.bottom=-P;const W=L.set(0,P,0).applyMatrix4(k),G=(g.current.position.y+W.y)/I.y;g.current.near=.1,g.current.far=G,g.current.updateProjectionMatrix(),g.current.updateMatrixWorld();const N=r.map((e=>e.add(I.clone().multiplyScalar(-e.y/I.y)))),H=N.reduce(((e,t)=>e.add(t)),L.set(0,0,0)).divideScalar(N.length),$=2*N.map((e=>Math.hypot(e.x-H.x,e.z-H.z))).reduce(((e,t)=>Math.max(e,t)));y.current.scale.setScalar($),y.current.position.copy(H),e&&(null==(d=M.current)||d.update()),z.viewMatrix.value=R.viewMatrix.value=g.current.matrixWorldInverse;const q=A.setFromProjectionMatrix(B.multiplyMatrices(g.current.projectionMatrix,g.current.matrixWorldInverse)).planes[4];_.cameraMatrixWorld=g.current.matrixWorld,_.cameraProjectionMatrixInv=g.current.projectionMatrixInverse,_.lightDir=V,_.lightPlaneNormal=q.normal,_.lightPlaneConstant=q.constant,_.near=g.current.near,_.far=g.current.far,_.resolution=m,_.size=P,_.intensity=u,_.worldRadius=c,x.current.visible=!0,w.setRenderTarget(E),w.clear(),x.current.overrideMaterial=R,w.render(x.current,g.current),w.setRenderTarget(b),w.clear(),s&&(x.current.overrideMaterial=z,w.render(x.current,g.current)),x.current.overrideMaterial=null,_.ior=n,y.current.material.lightProjMatrix=g.current.projectionMatrix,y.current.material.lightViewMatrix=g.current.matrixWorldInverse,_.normalTexture=E.texture,_.depthTexture=E.depthTexture,w.setRenderTarget(S),w.clear(),F.render(w),_.ior=l,_.normalTexture=b.texture,_.depthTexture=b.depthTexture,w.setRenderTarget(T),w.clear(),s&&F.render(w),w.setRenderTarget(null),i&&(x.current.visible=!1)}})),C.useImperativeHandle(h,(()=>v.current),[]),C.createElement("group",P.default({ref:v},p),C.createElement("scene",{ref:x},C.createElement("orthographicCamera",{ref:g,up:[0,1,0]}),t),C.createElement("mesh",{renderOrder:2,ref:y,"rotation-x":-Math.PI/2},C.createElement("planeGeometry",null),C.createElement("causticsProjectionMaterial",{transparent:!0,color:a,causticsTexture:S.texture,causticsTextureB:T.texture,blending:D.CustomBlending,blendSrc:D.OneFactor,blendDst:D.SrcAlphaFactor,depthWrite:!1}),e&&C.createElement(Pe,null,C.createElement("lineBasicMaterial",{color:"#ffff00",toneMapped:!1}))))}));o.extend({MeshReflectorMaterial:Yt});const sn=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)),M=o.useThree((({scene:e})=>e)),E=(a=Array.isArray(a)?a:[a,a])[0]+a[1]>0,b=C.useRef(null),[S]=C.useState((()=>new n.Plane)),[T]=C.useState((()=>new n.Vector3)),[R]=C.useState((()=>new n.Vector3)),[D]=C.useState((()=>new n.Vector3)),[z]=C.useState((()=>new n.Matrix4)),[F]=C.useState((()=>new n.Vector3(0,0,-1))),[k]=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)),[I]=C.useState((()=>new n.PerspectiveCamera)),V=C.useCallback((()=>{if(R.setFromMatrixPosition(b.current.matrixWorld),D.setFromMatrixPosition(w.matrixWorld),z.extractRotation(b.current.matrixWorld),T.set(0,0,1),T.applyMatrix4(z),L.subVectors(R,D),L.dot(T)>0)return;L.reflect(T).negate(),L.add(R),z.extractRotation(w.matrixWorld),F.set(0,0,-1),F.applyMatrix4(z),F.add(D),A.subVectors(R,F),A.reflect(T).negate(),A.add(R),I.position.copy(L),I.up.set(0,1,0),I.up.applyMatrix4(z),I.up.reflect(T),I.lookAt(A),I.far=w.far,I.updateMatrixWorld(),I.projectionMatrix.copy(w.projectionMatrix),U.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),U.multiply(I.projectionMatrix),U.multiply(I.matrixWorldInverse),U.multiply(b.current.matrixWorld),S.setFromNormalAndCoplanarPoint(T,R),S.applyMatrix4(I.matrixWorldInverse),k.set(S.normal.x,S.normal.y,S.normal.z,S.constant);const e=I.projectionMatrix;B.x=(Math.sign(k.x)+e.elements[8])/e.elements[0],B.y=(Math.sign(k.y)+e.elements[9])/e.elements[5],B.z=-1,B.w=(1+e.elements[10])/e.elements[14],k.multiplyScalar(2/k.dot(B)),e.elements[2]=k.x,e.elements[6]=k.y,e.elements[10]=k.z+1,e.elements[14]=k.w}),[]),[j,O,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 Xt({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:E,mixStrength:t,minDepthThreshold:s,maxDepthThreshold:l,depthScale:c,depthToBlurRatioBias:u,transparent:!0,debug:f,distortion:p,distortionMap:v,mixContrast:h,"defines-USE_BLUR":E?"":void 0,"defines-USE_DEPTH":c>0?"":void 0,"defines-USE_DISTORTION":v?"":void 0}]}),[y,a,U,r,d,E,e,t,s,l,c,u,f,p,v,h]);return o.useFrame((()=>{if(null==b||!b.current)return;b.current.visible=!1;const e=y.xr.enabled,t=y.shadowMap.autoUpdate;V(),y.xr.enabled=!1,y.shadowMap.autoUpdate=!1,y.setRenderTarget(j),y.state.buffers.depth.setMask(!0),y.autoClear||y.clear(),y.render(M,I),E&&W.render(y,j,O),y.xr.enabled=e,y.shadowMap.autoUpdate=t,b.current.visible=!0,y.setRenderTarget(null)})),C.createElement("mesh",P.default({ref:_.default([b,x])},g),C.createElement("planeGeometry",{args:i}),m?m("meshReflectorMaterial",G):C.createElement("meshReflectorMaterial",G))}));class ln 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 cn({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 ln)),[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 un(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 dn({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,...u}){const m=C.useRef(null),f=u.spotlightRef,p=u.debug;un(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 d.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 mn({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 un(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 fn=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",P.default({ref:_.default([f,p]),angle:i,color:o,distance:a,castShadow:!0},m),c&&C.createElement(cn,{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}))})),pn=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 D.Vector3(...l):l)}),[l]),s=Array.isArray(s)&&2===s.length?[s[0],s[1],1]:s,C.createElement("mesh",P.default({ref:_.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:D.DoubleSide})))}));function hn(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 vn=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=hn(e,t),...c},u)=>{const m=C.useMemo((()=>(new n.Vector3).setScalar(r)),[r]),[f]=C.useState((()=>new d.Sky));return C.createElement("primitive",P.default({object:f,ref:u,"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 gn 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 xn=e=>(new n.Vector3).setFromSpherical(new n.Spherical(e,Math.acos(1-2*Math.random()),2*Math.random()*Math.PI)),yn=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(...xn(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 gn));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 wn=xe({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);}"),Mn=e=>e&&e.constructor===Float32Array,En=e=>e instanceof D.Vector2||e instanceof D.Vector3||e instanceof D.Vector4,bn=e=>Array.isArray(e)?e:En(e)?e.toArray():[e,e,e];function Sn(e,t,r){return C.useMemo((()=>{if(void 0!==t){if(Mn(t))return t;if(t instanceof D.Color){const r=Array.from({length:3*e},(()=>(e=>[e.r,e.g,e.b])(t))).flat();return Float32Array.from(r)}if(En(t)||Array.isArray(t)){const r=Array.from({length:3*e},(()=>bn(t))).flat();return Float32Array.from(r)}return Float32Array.from({length:e},(()=>t))}return Float32Array.from({length:e},r)}),[t])}const Tn=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:wn})),[]);const u=C.useRef(),d=o.useThree((e=>e.viewport.dpr)),m=C.useMemo((()=>Float32Array.from(Array.from({length:t},(()=>bn(a).map(D.MathUtils.randFloatSpread))).flat())),[t,a]),f=Sn(t,i,Math.random),p=Sn(t,n),h=Sn(t,r),v=Sn(3*t,e),g=Sn(void 0===s?3*t:t,Mn(s)?s:new D.Color(s),(()=>1));return o.useFrame((e=>u.current.uniforms.time.value=e.clock.elapsedTime)),C.createElement("points",P.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 Pn=new D.Matrix4,Cn=new D.Ray,Rn=new D.Sphere,Dn=new D.Vector3;class zn extends D.Group{constructor(){super(),this.size=0,this.color=new D.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(Rn.set(this.getWorldPosition(Dn),i),!1===e.ray.intersectsSphere(Rn))return;Pn.copy(o.matrixWorld).invert(),Cn.copy(e.ray).applyMatrix4(Pn);const s=i/((this.scale.x+this.scale.y+this.scale.z)/3),l=s*s,c=Cn.distanceSqToPoint(Dn);if(c<l){const r=new D.Vector3;Cn.closestPointToPoint(Dn,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 _n,Fn;const kn=C.createContext(null),Ln=new D.Matrix4,An=new D.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(),Ln.copy(i.current.matrixWorld).invert(),i.current.geometry.drawRange.count=Math.min(r,void 0!==t?t:r,s.length),_n=0;_n<s.length;_n++)Fn=s[_n].current,Fn.getWorldPosition(An).applyMatrix4(Ln),An.toArray(c,3*_n),i.current.geometry.attributes.position.needsUpdate=!0,Fn.matrixWorldNeedsUpdate=!0,Fn.color.toArray(u,3*_n),i.current.geometry.attributes.color.needsUpdate=!0,d.set([Fn.size],_n),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",P.default({userData:{instances:s},matrixAutoUpdate:!1,ref:_.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:D.DynamicDrawUsage}),C.createElement("bufferAttribute",{attach:"attributes-color",count:u.length/3,array:u,itemSize:3,usage:D.DynamicDrawUsage}),C.createElement("bufferAttribute",{attach:"attributes-size",count:d.length,array:d,itemSize:1,usage:D.DynamicDrawUsage})),C.createElement(kn.Provider,{value:m},e))})),Un=C.forwardRef((({children:e,...t},r)=>{C.useMemo((()=>o.extend({PositionPoint:zn})),[]);const n=C.useRef(),{subscribe:a,getParent:i}=C.useContext(kn);return C.useLayoutEffect((()=>a(n)),[]),C.createElement("positionPoint",P.default({instance:i(),instanceKey:n,ref:_.default([r,n])},t),e)})),In=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",P.default({ref:_.default([s,l])},i),C.createElement("bufferGeometry",null,C.createElement("bufferAttribute",{attach:"attributes-position",count:t.length/a,array:t,itemSize:a,usage:D.DynamicDrawUsage}),r&&C.createElement("bufferAttribute",{attach:"attributes-color",count:r.length/a,array:r,itemSize:3,usage:D.DynamicDrawUsage}),n&&C.createElement("bufferAttribute",{attach:"attributes-size",count:n.length/a,array:n,itemSize:1,usage:D.DynamicDrawUsage})),e)})),Vn=C.forwardRef(((e,t)=>e.positions instanceof Float32Array?C.createElement(In,P.default({},e,{ref:t})):C.createElement(Bn,P.default({},e,{ref:t})))),jn=new D.Matrix4,On=new D.Matrix4,Wn=[],Gn=new D.Mesh;class Nn extends D.Group{constructor(){super(),this.color=new D.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;Gn.geometry=r.geometry;const n=r.matrixWorld,o=r.userData.instances.indexOf(this.instanceKey);if(!(-1===o||o>r.count)){r.getMatrixAt(o,jn),On.multiplyMatrices(n,jn),Gn.matrixWorld=On,r.material instanceof D.Material?Gn.material.side=r.material.side:Gn.material.side=r.material[0].side,Gn.raycast(e,Wn);for(let e=0,r=Wn.length;e<r;e++){const r=Wn[e];r.instanceId=o,r.object=this,t.push(r)}Wn.length=0}}}const Hn=C.createContext(null),$n=new D.Matrix4,qn=new D.Matrix4,Xn=new D.Matrix4,Yn=new D.Vector3,Zn=new D.Quaternion,Kn=new D.Vector3,Qn=C.forwardRef((({context:e,children:t,...r},n)=>{C.useMemo((()=>o.extend({PositionMesh:Nn})),[]);const a=C.useRef(),{subscribe:i,getParent:s}=C.useContext(e||Hn);return C.useLayoutEffect((()=>i(a)),[]),C.createElement("positionMesh",P.default({instance:s(),instanceKey:a,ref:_.default([n,a])},r),t)})),Jn=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(Qn,P.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++)Xn.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(),$n.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(Yn,Zn,Kn),qn.compose(Yn,Zn,Kn).premultiply($n),qn.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",P.default({userData:{instances:u},matrixAutoUpdate:!1,ref:_.default([i,c]),args:[null,null,0],raycast:()=>null},a),C.createElement("instancedBufferAttribute",{attach:"instanceMatrix",count:m.length/16,array:m,itemSize:16,usage:D.DynamicDrawUsage}),C.createElement("instancedBufferAttribute",{attach:"instanceColor",count:f.length/3,array:f,itemSize:3,usage:D.DynamicDrawUsage}),"function"==typeof e?C.createElement(s.Provider,{value:v},e(l)):C.createElement(Hn.Provider,{value:v},e))})),eo=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(U.default,{components:(o?e:Object.values(e)).map((({geometry:e,material:t})=>C.createElement(Jn,P.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]})),{})))))})),to=C.createContext(null),ro=C.forwardRef(((e,t)=>{C.useMemo((()=>o.extend({SegmentObject:no})),[]);const{limit:r=1e3,lineWidth:n=1,children:a,...i}=e,[s,l]=C.useState([]),[c]=C.useState((()=>new d.Line2)),[u]=C.useState((()=>new d.LineMaterial)),[m]=C.useState((()=>new d.LineSegmentsGeometry)),[f]=C.useState((()=>new D.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",P.default({object:u,attach:"material",vertexColors:!0,resolution:f,linewidth:n},i)),C.createElement(to.Provider,{value:v},a))}));class no{constructor(){this.color=new D.Color("white"),this.start=new D.Vector3(0,0,0),this.end=new D.Vector3(0,0,0)}}const oo=e=>e instanceof D.Vector3?e:new D.Vector3(..."number"==typeof e?[e,e,e]:e),ao=C.forwardRef((({color:e,start:t,end:r},n)=>{const o=C.useContext(to);if(!o)throw"Segment must used inside Segments component.";const a=C.useRef(null);return C.useLayoutEffect((()=>o.subscribe(a)),[]),C.createElement("segmentObject",{ref:_.default([a,n]),color:e,start:oo(t),end:oo(r)})})),io=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",P.default({ref:_.default([a,n])},r),e)}));const so=new n.Matrix4,lo=new n.Ray,co=new n.Sphere,uo=new n.Vector3;const mo=t.createContext(null);const fo=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=Ge((t||u.width)*d.dpr,(r||u.height)*d.dpr,{samples:n}),[f]=C.useState((()=>new D.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 D.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(po,{renderPriority:a,frames:s,fbo:m},e),f,{events:{compute:p,priority:i}}),C.createElement("primitive",P.default({object:m.texture},l)))}));function po({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 ho=new D.Color;function vo(e){return"top"in e}function go({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(vo(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(ho),r.gl.setClearColor(ho,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((()=>{vo(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 xo=C.createContext(null),yo=new D.Vector3,wo=new D.Vector3,Mo=new D.Vector3(0,1,0),Eo=new D.Matrix4,bo=({direction:e,axis:t})=>{const{translation:r,translationLimits:n,annotations:a,annotationsClass:i,depthTest:s,scale:l,lineWidth:c,fixed:u,axisColors:d,hoveredColor:m,opacity:f,onDragStart:p,onDrag:h,onDragEnd:v,userData:g}=C.useContext(xo),x=o.useThree((e=>e.controls)),y=C.useRef(null),w=C.useRef(null),M=C.useRef(null),E=C.useRef(0),[b,S]=C.useState(!1),T=C.useCallback((n=>{a&&(y.current.innerText=`${r.current[t].toFixed(2)}`,y.current.style.display="block"),n.stopPropagation();const o=(new D.Matrix4).extractRotation(w.current.matrixWorld),i=n.point.clone(),s=(new D.Vector3).setFromMatrixPosition(w.current.matrixWorld),l=e.clone().applyMatrix4(o).normalize();M.current={clickPoint:i,dir:l},E.current=r.current[t],p({component:"Arrow",axis:t,origin:s,directions:[l]}),x&&(x.enabled=!1),n.target.setPointerCapture(n.pointerId)}),[a,e,x,p,r,t]),P=C.useCallback((e=>{if(e.stopPropagation(),b||S(!0),M.current){const{clickPoint:o,dir:i}=M.current,[s,l]=(null==n?void 0:n[t])||[void 0,void 0];let c=((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:(yo.copy(n).multiplyScalar(o/i).sub(t),wo.copy(n).multiplyScalar(a/i).add(r).sub(e),-yo.dot(wo)/yo.dot(yo))})(o,i,e.ray.origin,e.ray.direction);void 0!==s&&(c=Math.max(c,s-E.current)),void 0!==l&&(c=Math.min(c,l-E.current)),r.current[t]=E.current+c,a&&(y.current.innerText=`${r.current[t].toFixed(2)}`),Eo.makeTranslation(i.x*c,i.y*c,i.z*c),h(Eo)}}),[a,h,b,r,n,t]),R=C.useCallback((e=>{a&&(y.current.style.display="none"),e.stopPropagation(),M.current=null,v(),x&&(x.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[a,x,v]),z=C.useCallback((e=>{e.stopPropagation(),S(!1)}),[]),{cylinderLength:_,coneWidth:F,coneLength:k,matrixL:L}=C.useMemo((()=>{const t=u?c/l*1.6:l/20,r=u?.2:l/5,n=u?1-r:l-r,o=(new D.Quaternion).setFromUnitVectors(Mo,e.clone().normalize());return{cylinderLength:n,coneWidth:t,coneLength:r,matrixL:(new D.Matrix4).makeRotationFromQuaternion(o)}}),[e,l,c,u]),A=b?m:d[t];return C.createElement("group",{ref:w},C.createElement("group",{matrix:L,matrixAutoUpdate:!1,onPointerDown:T,onPointerMove:P,onPointerUp:R,onPointerOut:z},a&&C.createElement(X,{position:[0,-k,0]},C.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:i,ref:y})),C.createElement("mesh",{visible:!1,position:[0,(_+k)/2,0],userData:g},C.createElement("cylinderGeometry",{args:[1.4*F,1.4*F,_+k,8,1]})),C.createElement(le,{transparent:!0,raycast:()=>null,depthTest:s,points:[0,0,0,0,_,0],lineWidth:c,color:A,opacity:f,polygonOffset:!0,renderOrder:1,polygonOffsetFactor:-10}),C.createElement("mesh",{raycast:()=>null,position:[0,_+k/2,0],renderOrder:500},C.createElement("coneGeometry",{args:[F,k,24,1]}),C.createElement("meshBasicMaterial",{transparent:!0,depthTest:s,color:A,opacity:f,polygonOffset:!0,polygonOffsetFactor:-10}))))},So=new D.Ray,To=new D.Vector3,Po=new D.Matrix4,Co=({dir1:e,dir2:t,axis:r})=>{const{translation:n,translationLimits:a,annotations:i,annotationsClass:s,depthTest:l,scale:c,lineWidth:u,fixed:d,axisColors:m,hoveredColor:f,opacity:p,onDragStart:h,onDrag:v,onDragEnd:g,userData:x}=C.useContext(xo),y=o.useThree((e=>e.controls)),w=C.useRef(null),M=C.useRef(null),E=C.useRef(null),b=C.useRef(0),S=C.useRef(0),[T,P]=C.useState(!1),R=C.useCallback((e=>{i&&(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 D.Vector3).setFromMatrixPosition(M.current.matrixWorld),a=(new D.Vector3).setFromMatrixColumn(M.current.matrixWorld,0).normalize(),s=(new D.Vector3).setFromMatrixColumn(M.current.matrixWorld,1).normalize(),l=(new D.Vector3).setFromMatrixColumn(M.current.matrixWorld,2).normalize(),c=(new D.Plane).setFromNormalAndCoplanarPoint(l,o);E.current={clickPoint:t,e1:a,e2:s,plane:c},b.current=n.current[(r+1)%3],S.current=n.current[(r+2)%3],h({component:"Slider",axis:r,origin:o,directions:[a,s,l]}),y&&(y.enabled=!1),e.target.setPointerCapture(e.pointerId)}),[i,y,h,r]),z=C.useCallback((e=>{if(e.stopPropagation(),T||P(!0),E.current){const{clickPoint:t,e1:o,e2:s,plane:l}=E.current,[c,u]=(null==a?void 0:a[(r+1)%3])||[void 0,void 0],[d,m]=(null==a?void 0:a[(r+2)%3])||[void 0,void 0];So.copy(e.ray),So.intersectPlane(l,To),So.direction.negate(),So.intersectPlane(l,To),To.sub(t);let[f,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,s,To);void 0!==c&&(f=Math.max(f,c-b.current)),void 0!==u&&(f=Math.min(f,u-b.current)),void 0!==d&&(p=Math.max(p,d-S.current)),void 0!==m&&(p=Math.min(p,m-S.current)),n.current[(r+1)%3]=b.current+f,n.current[(r+2)%3]=S.current+p,i&&(w.current.innerText=`${n.current[(r+1)%3].toFixed(2)}, ${n.current[(r+2)%3].toFixed(2)}`),Po.makeTranslation(f*o.x+p*s.x,f*o.y+p*s.y,f*o.z+p*s.z),v(Po)}}),[i,v,T,n,a,r]),_=C.useCallback((e=>{i&&(w.current.style.display="none"),e.stopPropagation(),E.current=null,g(),y&&(y.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[i,y,g]),F=C.useCallback((e=>{e.stopPropagation(),P(!1)}),[]),k=C.useMemo((()=>{const r=e.clone().normalize(),n=t.clone().normalize();return(new D.Matrix4).makeBasis(r,n,r.clone().cross(n))}),[e,t]),L=d?1/7:c/7,A=d?.225:.225*c,B=T?f:m[r],U=C.useMemo((()=>[new D.Vector3(0,0,0),new D.Vector3(0,A,0),new D.Vector3(A,A,0),new D.Vector3(A,0,0),new D.Vector3(0,0,0)]),[A]);return C.createElement("group",{ref:M,matrix:k,matrixAutoUpdate:!1},i&&C.createElement(X,{position:[0,0,0]},C.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:s,ref:w})),C.createElement("group",{position:[1.7*L,1.7*L,0]},C.createElement("mesh",{visible:!0,onPointerDown:R,onPointerMove:z,onPointerUp:_,onPointerOut:F,scale:A,userData:x},C.createElement("planeGeometry",null),C.createElement("meshBasicMaterial",{transparent:!0,depthTest:l,color:B,polygonOffset:!0,polygonOffsetFactor:-10,side:D.DoubleSide})),C.createElement(le,{position:[-A/2,-A/2,0],transparent:!0,depthTest:l,points:U,lineWidth:u,color:B,opacity:p,polygonOffset:!0,polygonOffsetFactor:-10,userData:x})))},Ro=new D.Vector3,Do=new D.Vector3,zo=e=>180*e/Math.PI,_o=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)},Fo=new D.Matrix4,ko=new D.Vector3,Lo=new D.Ray,Ao=new D.Vector3,Bo=({dir1:e,dir2:t,axis:r})=>{const{rotationLimits:n,annotations:a,annotationsClass:i,depthTest:s,scale:l,lineWidth:c,fixed:u,axisColors:d,hoveredColor:m,opacity:f,onDragStart:p,onDrag:h,onDragEnd:v,userData:g}=C.useContext(xo),x=o.useThree((e=>e.controls)),y=C.useRef(null),w=C.useRef(null),M=C.useRef(0),E=C.useRef(0),b=C.useRef(null),[S,T]=C.useState(!1),P=C.useCallback((e=>{a&&(y.current.innerText=`${zo(E.current).toFixed(0)}º`,y.current.style.display="block"),e.stopPropagation();const t=e.point.clone(),n=(new D.Vector3).setFromMatrixPosition(w.current.matrixWorld),o=(new D.Vector3).setFromMatrixColumn(w.current.matrixWorld,0).normalize(),i=(new D.Vector3).setFromMatrixColumn(w.current.matrixWorld,1).normalize(),s=(new D.Vector3).setFromMatrixColumn(w.current.matrixWorld,2).normalize(),l=(new D.Plane).setFromNormalAndCoplanarPoint(s,n);b.current={clickPoint:t,origin:n,e1:o,e2:i,normal:s,plane:l},p({component:"Rotator",axis:r,origin:n,directions:[o,i,s]}),x&&(x.enabled=!1),e.target.setPointerCapture(e.pointerId)}),[a,x,p,r]),R=C.useCallback((e=>{if(e.stopPropagation(),S||T(!0),b.current){const{clickPoint:t,origin:o,e1:i,e2:s,normal:l,plane:c}=b.current,[u,d]=(null==n?void 0:n[r])||[void 0,void 0];Lo.copy(e.ray),Lo.intersectPlane(c,Ao),Lo.direction.negate(),Lo.intersectPlane(c,Ao);let m=((e,t,r,n,o)=>{Ro.copy(e).sub(r),Do.copy(t).sub(r);const a=n.dot(n),i=o.dot(o),s=Ro.dot(n)/a,l=Ro.dot(o)/i,c=Do.dot(n)/a,u=Do.dot(o)/i,d=Math.atan2(l,s);return Math.atan2(u,c)-d})(t,Ao,o,i,s),f=zo(m);e.shiftKey&&(f=10*Math.round(f/10),m=(e=>e*Math.PI/180)(f)),void 0!==u&&void 0!==d&&d-u<2*Math.PI?(m=_o(m),m=m>Math.PI?m-2*Math.PI:m,m=I.default(m,u-M.current,d-M.current),E.current=M.current+m):(E.current=_o(M.current+m),E.current=E.current>Math.PI?E.current-2*Math.PI:E.current),a&&(f=zo(E.current),y.current.innerText=`${f.toFixed(0)}º`),Fo.makeRotationAxis(l,m),ko.copy(o).applyMatrix4(Fo).sub(o).negate(),Fo.setPosition(ko),h(Fo)}}),[a,h,S,n,r]),z=C.useCallback((e=>{a&&(y.current.style.display="none"),e.stopPropagation(),M.current=E.current,b.current=null,v(),x&&(x.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[a,x,v]),_=C.useCallback((e=>{e.stopPropagation(),T(!1)}),[]),F=C.useMemo((()=>{const r=e.clone().normalize(),n=t.clone().normalize();return(new D.Matrix4).makeBasis(r,n,r.clone().cross(n))}),[e,t]),k=u?.65:.65*l,L=C.useMemo((()=>{const e=[];for(let t=0;t<=32;t++){const r=t*(Math.PI/2)/32;e.push(new D.Vector3(Math.cos(r)*k,Math.sin(r)*k,0))}return e}),[k]);return C.createElement("group",{ref:w,onPointerDown:P,onPointerMove:R,onPointerUp:z,onPointerOut:_,matrix:F,matrixAutoUpdate:!1},a&&C.createElement(X,{position:[k,k,0]},C.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:i,ref:y})),C.createElement(le,{points:L,lineWidth:4*c,visible:!1,userData:g}),C.createElement(le,{transparent:!0,raycast:()=>null,depthTest:s,points:L,lineWidth:c,color:S?m:d[r],opacity:f,polygonOffset:!0,polygonOffsetFactor:-10}))},Uo=new D.Vector3,Io=new D.Vector3,Vo=new D.Vector3,jo=(e,t,r,n=1)=>{const o=Uo.set(e.x/r.width*2-1,-e.y/r.height*2+1,n);return o.unproject(t),o},Oo=(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})(Vo.copy(e),r,n);let a=0;for(let i=0;i<2;++i){const s=Io.copy(o).setComponent(i,o.getComponent(i)+t),l=jo(s,r,n,s.z);a=Math.max(a,e.distanceTo(l))}return a},Wo=new D.Matrix4,Go=new D.Matrix4,No=new D.Matrix4,Ho=new D.Matrix4,$o=new D.Matrix4,qo=new D.Matrix4,Xo=new D.Matrix4,Yo=new D.Matrix4,Zo=new D.Box3,Ko=new D.Box3,Qo=new D.Vector3,Jo=new D.Vector3,ea=new D.Vector3,ta=new D.Vector3,ra=new D.Vector3(1,0,0),na=new D.Vector3(0,1,0),oa=new D.Vector3(0,0,1),aa=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",annotations:M=!1,annotationsClass:E,opacity:b=1,visible:S=!0,userData:T,children:R,...z},_)=>{const F=o.useThree((e=>e.invalidate)),k=C.useRef(null),L=C.useRef(null),A=C.useRef(null),B=C.useRef(null),U=C.useRef([0,0,0]);C.useLayoutEffect((()=>{i&&(B.current.updateWorldMatrix(!0,!0),Ho.copy(B.current.matrixWorld).invert(),Zo.makeEmpty(),B.current.traverse((e=>{e.geometry&&(e.geometry.boundingBox||e.geometry.computeBoundingBox(),qo.copy(e.matrixWorld).premultiply(Ho),Ko.copy(e.geometry.boundingBox),Ko.applyMatrix4(qo),Zo.union(Ko))})),Qo.copy(Zo.max).add(Zo.min).multiplyScalar(.5),Jo.copy(Zo.max).sub(Zo.min).multiplyScalar(.5),ea.copy(Jo).multiply(new D.Vector3(...i)).add(Qo),ta.set(...d).add(ea),A.current.position.copy(ta),F())}));const I=C.useMemo((()=>({onDragStart:e=>{Wo.copy(L.current.matrix),Go.copy(L.current.matrixWorld),t&&t(e),F()},onDrag:e=>{No.copy(k.current.matrixWorld),Ho.copy(No).invert(),$o.copy(Go).premultiply(e),qo.copy($o).premultiply(Ho),Xo.copy(Wo).invert(),Yo.copy(qo).multiply(Xo),a&&L.current.matrix.copy(qo),r&&r(qo,Yo,$o,e),F()},onDragEnd:()=>{n&&n(),F()},translation:U,translationLimits:v,rotationLimits:g,axisColors:y,hoveredColor:w,opacity:b,scale:f,lineWidth:p,fixed:h,depthTest:x,userData:T,annotations:M,annotationsClass:E})),[t,r,n,U,v,g,x,f,p,h,...y,w,b,T,a,M,E]),V=new D.Vector3;return o.useFrame((e=>{if(h){const o=Oo(A.current.getWorldPosition(V),f,e.camera,e.size);var t,r,n;if(A.current)(null==(t=A.current)?void 0:t.scale.x)===o&&(null==(r=A.current)?void 0:r.scale.y)===o&&(null==(n=A.current)?void 0:n.scale.z)===o||(A.current.scale.setScalar(o),e.invalidate())}})),C.useImperativeHandle(_,(()=>L.current),[]),C.useLayoutEffect((()=>{e&&e instanceof D.Matrix4&&(L.current.matrix=e)}),[e]),C.createElement(xo.Provider,{value:I},C.createElement("group",{ref:k},C.createElement("group",P.default({ref:L,matrix:e,matrixAutoUpdate:!1},z),C.createElement("group",{visible:S,ref:A,position:d,rotation:m},!s&&u[0]&&C.createElement(bo,{axis:0,direction:ra}),!s&&u[1]&&C.createElement(bo,{axis:1,direction:na}),!s&&u[2]&&C.createElement(bo,{axis:2,direction:oa}),!l&&u[0]&&u[1]&&C.createElement(Co,{axis:2,dir1:ra,dir2:na}),!l&&u[0]&&u[2]&&C.createElement(Co,{axis:1,dir1:oa,dir2:ra}),!l&&u[2]&&u[1]&&C.createElement(Co,{axis:0,dir1:na,dir2:oa}),!c&&u[0]&&u[1]&&C.createElement(Bo,{axis:2,dir1:ra,dir2:na}),!c&&u[0]&&u[2]&&C.createElement(Bo,{axis:1,dir1:oa,dir2:ra}),!c&&u[2]&&u[1]&&C.createElement(Bo,{axis:0,dir1:na,dir2:oa})),C.createElement("group",{ref:B},R))))}));exports.AccumulativeShadows=qr,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=Ke,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:u,camera:m}=o.useThree(),f=C.useMemo((()=>{const e=new d.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(u,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&&(It.setFromObject(n.current),It.getSize(Vt),r.current.position.set(n.current.position.x+Vt.x*e[0]/2,n.current.position.y+Vt.y*e[1]/2,n.current.position.z+Vt.z*e[2]/2))})),C.createElement("group",P.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,Qr(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=ie,exports.Bounds=Fr,exports.Box=sr,exports.Bvh=Ut,exports.CameraControls=tt,exports.CameraShake=Lr,exports.Capsule=Sr,exports.CatmullRomLine=me,exports.Caustics=an,exports.Center=Dr,exports.Circle=lr,exports.Clone=Fe,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=we(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(ie,{key:i,position:[t,r,-i*n]},C.createElement(mr,{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",P.default({ref:a,object:o,attach:`attributes-${t}`},r))},exports.Cone=cr,exports.ContactShadows=Nr,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=de,exports.CurveModifier=Wt,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=ur,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 D.Mesh))throw new Error('Decal must have a Mesh as parent or specify its "mesh" prop');const s={position:new D.Vector3,rotation:new D.Euler,scale:new D.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 D.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 d.DecalGeometry(e,s.position,s.rotation,s.scale),c.current&&o.applyProps(c.current,s),e.matrixWorld=t,()=>{r.geometry.dispose()}}}),[t,...Ue(n),...Ue(i),...Ue(a)]),C.createElement("mesh",{ref:l},r||C.createElement("meshStandardMaterial",P.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=io,exports.DeviceOrientationControls=$e,exports.Dodecahedron=Mr,exports.Edges=Pe,exports.Effects=ge,exports.Environment=Gr,exports.EnvironmentCube=jr,exports.EnvironmentMap=Ir,exports.EnvironmentPortal=Or,exports.Extrude=Er,exports.FirstPersonControls=et,exports.Float=Ar,exports.FlyControls=qe,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(dt),ct.copy(c.quaternion),mt.copy(e).multiplyScalar(h.current).add(dt),st.lookAt(mt),ut.copy(st.quaternion),d()}),[u,c,i,d]);o.useFrame(((e,t)=>{if(f.current&&m.current){var r;if(p.current)if(ct.angleTo(ut)<.01)p.current=!1,"minPolarAngle"in u&&c.up.copy(g.current);else{const e=t*it;ct.rotateTowards(ut,e),c.position.set(0,0,1).applyQuaternion(ct).multiplyScalar(h.current).add(v.current),c.up.set(0,1,0).applyQuaternion(ct).normalize(),c.quaternion.copy(ct),a?a():u&&u.update(),d()}lt.copy(c.matrix).invert(),null==(r=m.current)||r.quaternion.setFromRotationMatrix(lt)}}));const y=C.useMemo((()=>({tweenCamera:x})),[x]),[w,M]=t,E=e.endsWith("-center")?0:e.endsWith("-left")?-l.width/2+w:l.width/2-w,b=e.startsWith("center-")?0:e.startsWith("top-")?l.height/2-M:-l.height/2+M;return C.createElement(nt,{renderPriority:r},C.createElement(ot.Provider,{value:y},C.createElement(Ne,{makeDefault:!0,ref:f,position:[0,0,200]}),C.createElement("group",{ref:m,position:[E,b,0]},s)))},exports.GizmoViewcube=e=>C.createElement("group",{scale:[60,60,60]},C.createElement(St,e),Mt.map(((t,r)=>C.createElement(Tt,P.default({key:r,position:t,dimensions:Et[r]},e)))),yt.map(((t,r)=>C.createElement(Tt,P.default({key:r,position:t,dimensions:wt},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}=at(),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",P.default({scale:40},u),C.createElement(Pt,{color:d,rotation:[0,0,0],scale:i}),C.createElement(Pt,{color:m,rotation:[0,0,Math.PI/2],scale:i}),C.createElement(Pt,{color:f,rotation:[0,-Math.PI/2,0],scale:i}),!t&&C.createElement(C.Fragment,null,C.createElement(Ct,P.default({arcStyle:d,position:[1,0,0],label:s[0]},h)),C.createElement(Ct,P.default({arcStyle:m,position:[0,1,0],label:s[1]},h)),C.createElement(Ct,P.default({arcStyle:f,position:[0,0,1],label:s[2]},h)),!e&&C.createElement(C.Fragment,null,C.createElement(Ct,P.default({arcStyle:d,position:[-1,0,0]},h)),C.createElement(Ct,P.default({arcStyle:m,position:[0,-1,0]},h)),C.createElement(Ct,P.default({arcStyle:f,position:[0,0,-1]},h)))),C.createElement("ambientLight",{intensity:.5}),C.createElement("pointLight",{position:[10,10,10],intensity:.5}))},exports.Gltf=We,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 D.Texture(n);return s.needsUpdate=!0,s}),[e]);return C.useEffect((()=>()=>{i.dispose()}),[i]),C.createElement("primitive",P.default({object:i,attach:"map",encoding:a.outputEncoding},n))},exports.Grid=Dt,exports.Html=X,exports.Hud=nt,exports.Icosahedron=yr,exports.Image=Te,exports.Instance=Qn,exports.Instances=Jn,exports.IsObject=ye,exports.KeyboardControls=function({map:e,children:t,onChange:r,domElement:n}){const o=e.map((e=>e.name+e.keys)).join("-"),a=C.useMemo((()=>z.default(u.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(oe.Provider,{value:i,children:t})},exports.Lathe=br,exports.Lightformer=pn,exports.Line=le,exports.Loader=function({containerStyles:e,innerStyles:t,barStyles:r,dataStyles:n,dataInterpolation:o=K,initialState:a=(e=>e)}){const{active:i,progress:s}=Z(),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:{...Q.container,opacity:i?1:0,...e}},C.createElement("div",null,C.createElement("div",{style:{...Q.inner,...t}},C.createElement("div",{style:{...Q.bar,transform:`scaleX(${s/100})`,...r}}),C.createElement("span",{ref:u,style:{...Q.data,...n}})))):null},exports.MapControls=Xe,exports.MarchingCube=Ae,exports.MarchingCubes=Le,exports.MarchingPlane=Be,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:D.AlwaysStencilFunc,stencilFail:D.ReplaceStencilOp,stencilZFail:D.ReplaceStencilOp,stencilZPass:D.ReplaceStencilOp})),[e,r,n]);return C.createElement("mesh",P.default({renderOrder:-e},o),C.createElement("meshBasicMaterial",a),"function"==typeof t?t(a):t)},exports.Merged=eo,exports.MeshDistortMaterial=Nt,exports.MeshReflectorMaterial=Zt,exports.MeshRefractionMaterial=function({aberrationStrength:e=0,fastChroma:r=!0,envMap:n,...a}){o.extend({MeshRefractionMaterial:Kt});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 M.MeshBVH(n.toNonIndexed(),{lazyGeneration:!1,strategy:M.SAH}))}),[]),C.createElement("meshRefractionMaterial",P.default({key:JSON.stringify(l),defines:l,ref:i,resolution:[s.width,s.height],aberrationStrength:e,envMap:n},a))},exports.MeshTransmissionMaterial=er,exports.MeshWobbleMaterial=$t,exports.Octahedron=wr,exports.OrbitControls=Ye,exports.OrthographicCamera=Ne,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(mo.Provider,{value:h},f)},exports.PerspectiveCamera=He,exports.PivotControls=aa,exports.Plane=mr,exports.Point=Un,exports.PointMaterial=rr,exports.PointMaterialImpl=tr,exports.PointerLockControls=Je,exports.Points=Vn,exports.PointsBuffer=In,exports.Polyhedron=xr,exports.PositionPoint=zn,exports.PositionalAudio=fe,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:s=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,M]=l.useSpring((()=>({scale:1,rotation:y,config:p})));C.useEffect((()=>{M.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 E=c.useGesture({onHover:({last:t})=>{a&&!r&&e&&(v.domElement.style.cursor=t?"auto":"grab")},onDrag:({down:r,delta:[o,i],memo:[l,c]=w.rotation.animation.to||y})=>{if(!e)return[i,o];a&&(v.domElement.style.cursor=r?"grabbing":"grab"),o=n.MathUtils.clamp(c+o/h.width*Math.PI*s,...x),i=n.MathUtils.clamp(l+i/h.height*Math.PI*s,...g);const u=t&&!r&&"boolean"!=typeof t?t:p;return M.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(l.a.group,P.default({},null==E?void 0:E(),w),i)},exports.QuadraticBezierLine=ue,exports.RandomizedLight=Xr,exports.Reflector=sn,exports.RenderTexture=fo,exports.Ring=gr,exports.RoundedBox=Pr,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]),_e(c,a,r,t,l),C.createElement("group",P.default({ref:s},i),e)},exports.ScreenQuad=Rr,exports.ScreenSpace=se,exports.Scroll=ne,exports.ScrollControls=function({eps:e=1e-5,enabled:t=!0,infinite:r,horizontal:n,pages:a=1,distance:i=1,damping:l=.25,maxSpeed:c=1/0,style:u={},children:d}){const{get:m,setEvents:f,gl:p,size:h,invalidate:v,events:g}=o.useThree(),[x]=C.useState((()=>document.createElement("div"))),[y]=C.useState((()=>document.createElement("div"))),[w]=C.useState((()=>document.createElement("div"))),M=p.domElement.parentNode,E=C.useRef(0),b=C.useMemo((()=>{const t={el:x,eps:e,fill:y,fixed:w,horizontal:n,damping:l,offset:0,delta:0,scroll:E,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,l,n,a]);C.useEffect((()=>{x.style.position="absolute",x.style.width="100%",x.style.height="100%",x.style[n?"overflowX":"overflowY"]="auto",x.style[n?"overflowY":"overflowX"]="hidden",x.style.top="0px",x.style.left="0px";for(const e in u)x.style[e]=u[e];w.style.position="sticky",w.style.top="0px",w.style.left="0px",w.style.width="100%",w.style.height="100%",w.style.overflow="hidden",x.appendChild(w),y.style.height=n?"100%":a*i*100+"%",y.style.width=n?a*i*100+"%":"100%",y.style.pointerEvents="none",x.appendChild(y),M.appendChild(x),x[n?"scrollLeft":"scrollTop"]=1;const e=g.connected||p.domElement;requestAnimationFrame((()=>null==g.connect?void 0:g.connect(x)));const t=m().events.compute;return f({compute(e,t){const{left:r,top:n}=M.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)}}),()=>{M.removeChild(x),f({compute:t}),null==g.connect||g.connect(e)}}),[a,i,n,x,y,w,M]),C.useEffect((()=>{if(g.connected===x){const e=h[n?"width":"height"],o=x[n?"scrollWidth":"scrollHeight"],a=o-e;let i=0,s=!0,l=!0;const c=()=>{if(t&&!l&&(v(),i=x[n?"scrollLeft":"scrollTop"],E.current=i/a,r)){if(!s)if(i>=a){const e=1-b.offset;x[n?"scrollLeft":"scrollTop"]=1,E.current=b.offset=-e,s=!0}else if(i<=0){const e=1+b.offset;x[n?"scrollLeft":"scrollTop"]=o,E.current=b.offset=e,s=!0}s&&setTimeout((()=>s=!1),40)}};x.addEventListener("scroll",c,{passive:!0}),requestAnimationFrame((()=>l=!1));const u=e=>x.scrollLeft+=e.deltaY/2;return n&&x.addEventListener("wheel",u,{passive:!0}),()=>{x.removeEventListener("scroll",c),n&&x.removeEventListener("wheel",u)}}}),[x,g,h,r,b,v,n,t]);let S=0;return o.useFrame(((t,r)=>{S=b.offset,s.easing.damp(b,"offset",E.current,l,r,c,void 0,e),s.easing.damp(b,"delta",Math.abs(S-b.offset),l,r,c,void 0,e),b.delta>e&&v()})),C.createElement(J.Provider,{value:b},d)},exports.Segment=ao,exports.SegmentObject=no,exports.Segments=ro,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:u,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 M=C.useCallback((e=>{e.stopPropagation(),w({object:s([e.object])[0],shift:t&&e.shiftKey})}),[]),E=C.useCallback((e=>!g&&w({})),[g]),b=C.useRef(null);return C.useEffect((()=>{if(!e||!t)return;const r=new d.SelectionBox(u,b.current),n=document.createElement("div");n.style.pointerEvents="none",n.style.border=a,n.style.backgroundColor=i,n.style.position="fixed";const o=new D.Vector2,l=new D.Vector2,m=new D.Vector2,g=v().events.enabled,x=null==p?void 0:p.enabled;let y=!1;function M(e,t){const{offsetX:r,offsetY:n}=e,{width:o,height:a}=h;t.set(r/o*2-1,-n/a*2+1)}function E(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),M(e,r.startPoint))}let S=[];function T(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),M(e,r.endPoint);const t=r.select().sort((e=>e.uuid)).filter((e=>e.isMesh));F.default(t,S)||(S=t,w({object:s(t)}))}}function P(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",E,{passive:!0}),document.addEventListener("pointermove",T,{passive:!0,capture:!0}),document.addEventListener("pointerup",P,{passive:!0}),()=>{document.removeEventListener("pointerdown",E),document.removeEventListener("pointermove",T),document.removeEventListener("pointerup",P)}}),[h.width,h.height,m,u,p,f]),C.createElement("group",P.default({ref:b,onClick:M,onPointerOver:()=>x(!0),onPointerOut:()=>x(!1),onPointerMissed:E},l),C.createElement(ae.Provider,{value:y},r))},exports.Shadow=Jr,exports.Sky=vn,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=D.ShaderChunk.shadowmap_pars_fragment;let c=D.ShaderChunk.shadowmap_pars_fragment;return c=c.replace("#ifdef USE_SHADOWMAP","#ifdef USE_SHADOWMAP\n"+nr({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 )"),D.ShaderChunk.shadowmap_pars_fragment=c,ar(i,s,l),()=>{D.ShaderChunk.shadowmap_pars_fragment=o,ar(i,s,l)}}),[e,t,r,n,a])},exports.Sparkles=Tn,exports.Sphere=dr,exports.SpotLight=fn,exports.SpotLightShadow=function(e){return e.shader?C.createElement(dn,e):C.createElement(mn,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?Zr[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,M=null!==(c=null==o?void 0:o.normalBias)&&void 0!==c?c:0,E=null!==(u=null==o?void 0:o.size)&&void 0!==u?u:1024,b=null!==(d=null==o?void 0:o.offset)&&void 0!==d?d:0,S="contact"===o||"contact"===(null==o?void 0:o.type),T="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":M,"shadow-mapSize":E}),C.createElement("pointLight",{position:[v.fill[0]*g,v.fill[1]*g,v.fill[2]*g],intensity:n}),C.createElement(Fr,P.default({fit:!!r,clip:!!r,margin:Number(r),observe:!0},s),C.createElement(Kr,{radius:g,adjustCamera:r}),C.createElement(Dr,P.default({},t,{position:[0,b/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-b/2,0]},S&&C.createElement(Nr,P.default({scale:4*g,far:g,blur:2},R)),T&&C.createElement(qr,P.default({temporal:!0,frames:100,alphaTest:.9,toneMapped:!0,scale:4*g},R),C.createElement(Xr,{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:E}))),a&&C.createElement(Gr,D))},exports.Stars=yn,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),Lt(r,t),()=>Lt(r,null)}),t),n}((()=>new B.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=Ie,exports.Tetrahedron=vr,exports.Text=pe,exports.Text3D=ve,exports.Torus=pr,exports.TorusKnot=hr,exports.TrackballControls=Ze,exports.Trail=ze,exports.TransformControls=Qe,exports.Tube=fr,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 D.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(go,{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=Hr,exports.calcPosFromAngles=hn,exports.calculateScaleFactor=Oo,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(),co.copy(r.boundingSphere),co.applyMatrix4(o),!1!==e.ray.intersectsSphere(co)&&(so.copy(o).invert(),lo.copy(e.ray).applyMatrix4(so),null!==r.boundingBox&&null===lo.intersectBox(r.boundingBox,uo)||t.push({distance:uo.distanceTo(e.ray.origin),point:uo.clone(),object:this})))},exports.shaderMaterial=xe,exports.softShadows=e=>{if(!or){console.warn("drei/softShadows() is deprecated, use <SoftShadows> instead"),or=!0;let t=D.ShaderChunk.shadowmap_pars_fragment;t=t.replace("#ifdef USE_SHADOWMAP","#ifdef USE_SHADOWMAP\n"+nr({...e})),t=t.replace("#if defined( SHADOWMAP_TYPE_PCF )","\nreturn PCSS(shadowMap, shadowCoord);\n#if defined( SHADOWMAP_TYPE_PCF )"),D.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){t={splitStrategy:"SAH",verbose:!1,setBoundingBox:!0,maxDepth:40,maxLeafTris:10,...t},C.useEffect((()=>{if(e.current){e.current.raycast=M.acceleratedRaycast;const r=e.current.geometry;return r.computeBoundsTree=M.computeBoundsTree,r.disposeBoundsTree=M.disposeBoundsTree,r.computeBoundsTree(t),()=>{r.boundsTree&&r.disposeBoundsTree()}}}),[e,JSON.stringify(t)])},exports.useBounds=kr,exports.useBoxProjectedEnv=function(e=new D.Vector3,t=new D.Vector3){const[r]=C.useState((()=>({position:new D.Vector3,size:new D.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>",D.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=zt,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=Ge(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=>p.suspend((()=>w.getGPUTier(e)),["useDetectGPU"]),exports.useEnvironment=Vr,exports.useFBO=Ge,exports.useFBX=_t,exports.useGLTF=Oe,exports.useGizmoContext=at,exports.useHelper=At,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=kt,exports.useKeyboardControls=function(e){const[t,r,n]=C.useContext(oe);return e?n(e):[t,r]},exports.useMask=function(e,t=!1){return{stencilWrite:!0,stencilRef:e,stencilFunc:t?D.NotEqualStencilFunc:D.EqualStencilFunc,stencilFail:D.KeepStencilOp,stencilZFail:D.KeepStencilOp,stencilZPass:D.KeepStencilOp}},exports.useMatcapTexture=function(e=0,t=1024,r){const n=p.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[we(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=p.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=we(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(mo),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=Z,exports.useScroll=ee,exports.useSelect=function(){return C.useContext(ae)},exports.useSurfaceSampler=_e,exports.useTexture=we,exports.useTrail=De,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 Ot(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=p.suspend((()=>new Promise(((t,r)=>{const o=Object.assign(document.createElement("video"),{src:e,crossOrigin:i,loop:l,muted:s,...c}),a=new D.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("maath"),l=require("@react-spring/three"),c=require("@use-gesture/react"),u=require("zustand/middleware"),d=require("three-stdlib"),m=require("zustand/shallow"),f=require("troika-three-text"),p=require("suspend-react"),h=require("meshline"),v=require("lodash.pick"),g=require("lodash.omit"),x=require("camera-controls"),y=require("stats.js"),w=require("detect-gpu"),M=require("three-mesh-bvh"),E=require("react-composer"),b=require("lodash.clamp");function S(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function T(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 P=S(e),C=T(t),R=T(r),D=T(n),z=S(a),_=S(i),F=S(m),k=S(v),L=S(g),A=S(x),B=S(y),U=S(E),I=S(b);const V=new n.Vector3,j=new n.Vector3,O=new n.Vector3;function W(e,t,r){const n=V.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 G=e=>Math.abs(e)<1e-10?0:e;function N(e,t,r=""){let n="matrix3d(";for(let r=0;16!==r;r++)n+=G(t[r]*e.elements[r])+(15!==r?",":")");return r+n}const H=($=[1,-1,1,1,1,-1,1,1,1,-1,1,1,1,-1,1,1],e=>N(e,$));var $;const q=(e,t)=>{return N(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 X=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=W,as:M="div",wrapperClass:E,pointerEvents:b="auto",...S},T)=>{const{gl:D,camera:z,scene:_,size:F,raycaster:k,events:L,viewport:A}=o.useThree(),[B]=C.useState((()=>document.createElement(M))),U=C.useRef(),I=C.useRef(null),N=C.useRef(0),$=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(I.current){const e=U.current=R.createRoot(B);if(_.updateMatrixWorld(),m)B.style.cssText="position:absolute;top:0;left:0;pointer-events:none;overflow:hidden;";else{const e=w(I.current,z,F);B.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(B):Z.appendChild(B)),()=>{Z&&Z.removeChild(B),e.unmount()}}}),[Z,m]),C.useLayoutEffect((()=>{E&&(B.className=E)}),[E]);const ee=C.useMemo((()=>m?{position:"absolute",top:0,left:0,width:F.width,height:F.height,transformStyle:"preserve-3d",pointerEvents:"none"}:{position:"absolute",transform:s?"translate3d(-50%,-50%,0)":"none",...l&&{top:-F.height/2,left:-F.width/2,width:F.width,height:F.height},...r}),[r,s,l,F,m]),te=C.useMemo((()=>({position:"absolute",pointerEvents:b})),[b]);C.useLayoutEffect((()=>{var t,n;(Q.current=!1,m)?null==(t=U.current)||t.render(C.createElement("div",{ref:X,style:ee},C.createElement("div",{ref:Y,style:te},C.createElement("div",{ref:T,className:a,style:r,children:e})))):null==(n=U.current)||n.render(C.createElement("div",{ref:T,style:ee,className:a,children:e}))}));const re=C.useRef(!0);o.useFrame((e=>{if(I.current){z.updateMatrixWorld(),I.current.updateWorldMatrix(!0,!1);const e=m?$.current:w(I.current,z,F);if(m||Math.abs(N.current-z.zoom)>t||Math.abs($.current[0]-e[0])>t||Math.abs($.current[1]-e[1])>t){const t=function(e,t){const r=V.setFromMatrixPosition(e.matrixWorld),n=j.setFromMatrixPosition(t.matrixWorld),o=r.sub(n),a=t.getWorldDirection(O);return o.angleTo(a)>Math.PI/2}(I.current,z);let r=!1;J&&("blending"!==f?r=[_]:Array.isArray(f)&&(r=f.map((e=>e.current))));const o=re.current;if(r){const e=function(e,t,r,n){const o=V.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}(I.current,z,k,r);re.current=e&&!t}else re.current=!t;o!==re.current&&(p?p(!re.current):B.style.display=re.current?"block":"none");const a=Math.floor(y[0]/2),i=f?J?[y[0],a]:[a-1,0]:y;if(B.style.zIndex=`${function(e,t,r){if(t instanceof n.PerspectiveCamera||t instanceof n.OrthographicCamera){const n=V.setFromMatrixPosition(e.matrixWorld),o=j.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)}}(I.current,z,i)}`,m){const[e,t]=[F.width/2,F.height/2],r=z.projectionMatrix.elements[5]*t,{isOrthographicCamera:n,top:o,left:a,bottom:i,right:s}=z,l=H(z.matrixWorldInverse),c=n?`scale(${r})translate(${G(-(s+a)/2)}px,${G((o+i)/2)}px)`:`translateZ(${r}px)`;let m=I.current.matrixWorld;d&&(m=z.matrixWorldInverse.clone().transpose().copyPosition(m).scale(I.current.scale),m.elements[3]=m.elements[7]=m.elements[11]=0,m.elements[15]=1),B.style.width=F.width+"px",B.style.height=F.height+"px",B.style.perspective=n?"":`${r}px`,X.current&&Y.current&&(X.current.style.transform=`${c}${l}translate(${e}px,${t}px)`,Y.current.style.transform=q(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=V.setFromMatrixPosition(e.matrixWorld),n=j.setFromMatrixPosition(t.matrixWorld),o=t.fov*Math.PI/180,a=r.distanceTo(n);return 1/(2*Math.tan(o/2)*a)}return 1}(I.current,z)*u;B.style.transform=`translate3d(${e[0]}px,${e[1]}px,0) scale(${t})`}$.current=e,N.current=z.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}=z;if(t||x)S.scale&&(Array.isArray(S.scale)?S.scale instanceof n.Vector3?K.current.scale.copy(S.scale.clone().divideScalar(1)):K.current.scale.set(1/S.scale[0],1/S.scale[1],1/S.scale[2]):K.current.scale.setScalar(1/S.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=B.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",P.default({},S,{ref:I}),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 Y=0;const Z=z.default((e=>(n.DefaultLoadingManager.onStart=(t,r,n)=>{e({active:!0,item:t,loaded:r,total:n,progress:(r-Y)/(n-Y)*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&&(Y=n),e({active:!0,item:t,loaded:r,total:n,progress:(r-Y)/(n-Y)*100||100})},{errors:[],active:!1,progress:0,item:"",loaded:0,total:0}))),K=e=>`Loading ${e.toFixed(2)}%`;const Q={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"}},J=C.createContext(null);function ee(){return C.useContext(J)}const te=C.forwardRef((({children:e},t)=>{const r=C.useRef(null),n=ee(),{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:_.default([t,r])},e)})),re=C.forwardRef((({children:e,style:t,...r},n)=>{const a=ee(),i=C.useRef(null),{width:s,height:l}=o.useThree((e=>e.size)),c=C.useContext(o.context),u=C.useMemo((()=>R.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",P.default({ref:_.default([n,i]),style:{...t,position:"absolute",top:0,left:0,willChange:"transform"}},r),C.createElement(J.Provider,{value:a},C.createElement(o.context.Provider,{value:c},e)))),null})),ne=C.forwardRef((({html:e,...t},r)=>{const n=e?re:te;return C.createElement(n,P.default({ref:r},t))}));const oe=C.createContext(null);const ae=C.createContext([]);const ie=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",P.default({ref:_.default([s,i])},a))})),se=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",P.default({ref:_.default([n,a])},r),C.createElement("group",{"position-z":-t},e))})),le=C.forwardRef((function({points:e,color:t="black",vertexColors:r,linewidth:a,lineWidth:i,segments:s,dashed:l,...c},u){const m=o.useThree((e=>e.size)),f=C.useMemo((()=>s?new d.LineSegments2:new d.Line2),[s]),[p]=C.useState((()=>new d.LineMaterial)),h=C.useMemo((()=>{const t=s?new d.LineSegmentsGeometry:new d.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,s,r]);return C.useLayoutEffect((()=>{f.computeLineDistances()}),[e,f]),C.useLayoutEffect((()=>{l?p.defines.USE_DASH="":delete p.defines.USE_DASH,p.needsUpdate=!0}),[l,p]),C.useEffect((()=>()=>h.dispose()),[h]),C.createElement("primitive",P.default({object:f,ref:u},c),C.createElement("primitive",{object:h,attach:"geometry"}),C.createElement("primitive",P.default({object:p,attach:"material",color:t,vertexColors:Boolean(r),resolution:[m.width,m.height],linewidth:null!=a?a:i,dashed:l},c)))})),ce=new n.Vector3,ue=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(ce.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(le,P.default({ref:_.default([s,i]),points:u},a))})),de=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(le,P.default({ref:s,points:l},i))})),me=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(le,P.default({ref:l,points:u,vertexColors:d},s))})),fe=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",P.default({ref:_.default([l,s]),args:[u]},i))})),pe=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 f.Text)),[m,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 p.suspend((()=>new Promise((e=>f.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",P.default({object:d,ref:c,font:r,text:h,anchorX:e,anchorY:t,fontSize:n},l),m)})),he=["string","number"],ve=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:u=0,bevelSegments:m=4,curveSegments:f=8,children:h,...v},g)=>{C.useMemo((()=>o.extend({RenamedTextGeometry:d.TextGeometry})),[]);const x=p.suspend((async()=>{let t="string"==typeof e?await(await fetch(e)).json():e;return(new d.FontLoader).parse(t)}),[e]),y=t.useMemo((()=>({font:x,size:a,height:i,bevelThickness:s,bevelSize:l,bevelEnabled:c,bevelSegments:m,bevelOffset:u,curveSegments:f,letterSpacing:r,lineHeight:n})),[x,a,i,s,l,c,m,u,f,r,n]),[w,...M]=t.useMemo((()=>(e=>{let t="";const r=[];return C.Children.forEach(e,(e=>{he.includes(typeof e)?t+=e+"":r.push(e)})),[t,...r]})(h)),[h]),E=C.useMemo((()=>[w,y]),[w,y]);return C.createElement("mesh",P.default({},v,{ref:g}),C.createElement("renamedTextGeometry",{args:E}),M)})),ge=C.forwardRef((({children:e,multisamping:t=8,renderIndex:r=1,disableRender:a,disableGamma:i,disableRenderPass:s,depthBuffer:l=!0,stencilBuffer:c=!1,anisotropy:u=1,encoding:m,type:f,...p},h)=>{C.useMemo((()=>o.extend({EffectComposer:d.EffectComposer,RenderPass:d.RenderPass,ShaderPass:d.ShaderPass})),[]);const v=C.useRef(),{scene:g,camera:x,gl:y,size:w,viewport:M}=o.useThree(),[E]=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:u});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(M.dpr)}),[y,w,M.dpr]),o.useFrame((()=>{var e;a||null==(e=v.current)||e.render()}),r);const b=[];return s||b.push(C.createElement("renderPass",{key:"renderpass",attach:`passes-${b.length}`,args:[g,x]})),i||b.push(C.createElement("shaderPass",{attach:`passes-${b.length}`,key:"gammapass",args:[d.GammaCorrectionShader]})),C.Children.forEach(e,(e=>{e&&b.push(C.cloneElement(e,{key:b.length,attach:`passes-${b.length}`}))})),C.createElement("effectComposer",P.default({ref:_.default([h,v]),args:[y,E]},p),b)}));function xe(e,t,r,n){const o=class extends D.ShaderMaterial{constructor(o={}){const a=Object.entries(e);super({uniforms:a.reduce(((e,[t,r])=>({...e,...D.UniformsUtils.clone({[t]:{value:r}})})),{}),vertexShader:t,fragmentShader:r}),this.key="",a.forEach((([e])=>Object.defineProperty(this,e,{get:()=>this.uniforms[e].value,set:t=>this.uniforms[e].value=t}))),Object.assign(this,o),n&&n(this)}};return o.key=D.MathUtils.generateUUID(),o}const ye=e=>e===Object(e)&&!Array.isArray(e)&&"function"!=typeof e;function we(e,r){const a=o.useThree((e=>e.gl)),i=o.useLoader(n.TextureLoader,ye(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]),ye(e)){const t=Object.keys(e),r={};return t.forEach((e=>Object.assign(r,{[e]:i[t.indexOf(e)]}))),r}return i}we.preload=e=>o.useLoader.preload(n.TextureLoader,e),we.clear=e=>o.useLoader.clear(n.TextureLoader,e);const Me=xe({color:new D.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"),Ee=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:Me});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",P.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)})),be=C.forwardRef((({url:e,...t},r)=>{const n=we(e);return C.createElement(Ee,P.default({},t,{texture:n,ref:r}))})),Se=C.forwardRef((({url:e,...t},r)=>C.createElement(Ee,P.default({},t,{ref:r})))),Te=C.forwardRef(((e,t)=>{if(e.url)return C.createElement(be,P.default({},e,{ref:t}));if(e.texture)return C.createElement(Se,P.default({},e,{ref:t}));throw new Error("<Image /> requires a url or texture")}));function Pe({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 D.EdgesGeometry(t,n))}})),C.createElement("lineSegments",P.default({ref:i,raycast:()=>null},a),t||C.createElement("lineBasicMaterial",{color:o}))}const Ce={width:.2,length:1,decay:1,local:!1,stride:0,interval:1},Re=(e,t=1)=>(e.set(e.subarray(t)),e.fill(-1/0,-t),e);function De(e,t){const{length:r,local:a,decay:i,interval:s,stride:l}={...Ce,...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||(Re(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 ze=C.forwardRef(((e,t)=>{const{children:r}=e,{width:a,length:i,decay:s,local:l,stride:c,interval:u}={...Ce,...e},{color:d="hotpink",attenuation:m,target:f}=e,p=o.useThree((e=>e.size)),v=o.useThree((e=>e.scene)),g=C.useRef(null),[x,y]=C.useState(null),w=De(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 M=C.useMemo((()=>new h.MeshLineGeometry),[]),E=C.useMemo((()=>{var e;const t=new h.MeshLineMaterial({lineWidth:.1*a,color:d,sizeAttenuation:1,resolution:new n.Vector2(p.width,p.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,p,r]);return C.useEffect((()=>{E.uniforms.resolution.value.set(p.width,p.height)}),[p]),o.useFrame((()=>{w.current&&M.setPoints(w.current,m)})),C.createElement("group",null,o.createPortal(C.createElement("mesh",{ref:t,geometry:M,material:E}),v),C.createElement("group",{ref:g},r))}));function _e(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 d.MeshSurfaceSampler(e.current);o&&l.setWeightAttribute(o),l.build();const c=new n.Vector3,u=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,u,m),"function"==typeof r?r({dummy:f,sampledMesh:e.current,position:c,normal:u,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 Fe=C.forwardRef((({isChild:e=!1,object:t,children:r,deep:n,castShadow:o,receiveShadow:a,inject:i,keys:s,...l},c)=>{var u;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 d.SkeletonUtils.clone(t)}return t}),[t,e]),Array.isArray(t))return C.createElement("group",P.default({},l,{ref:c}),t.map((e=>C.createElement(Fe,P.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=k.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 D.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,P.default({},p,l,{ref:c}),(null==(u=t)?void 0:u.children).map((e=>"Bone"===e.type?C.createElement("primitive",P.default({key:e.uuid,object:e},m)):C.createElement(Fe,P.default({key:e.uuid,object:e},m,{isChild:!0})))),r,f)})),ke=C.createContext(null),Le=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 d.MarchingCubes(e,null,r,n,t)),[e,t,r,n]),u=C.useMemo((()=>({getParent:()=>l})),[]);return o.useFrame((()=>{c.reset()}),-1),C.createElement(C.Fragment,null,C.createElement("primitive",P.default({object:c,ref:_.default([l,s])},i),C.createElement(ke.Provider,{value:u},a)))})),Ae=C.forwardRef((({strength:e=.5,subtract:t=12,color:r,...n},a)=>{const{getParent:i}=C.useContext(ke),s=C.useMemo((()=>i()),[i]),l=C.useRef(),c=new D.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",P.default({ref:_.default([a,l])},n))})),Be=C.forwardRef((({planeType:e="x",strength:t=.5,subtract:r=12,...n},a)=>{const{getParent:i}=C.useContext(ke),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",P.default({ref:_.default([a,l])},n))}));function Ue(e=[0,0,0]){return function(e){return Array.isArray(e)}(e)?e:e instanceof D.Vector3||e instanceof D.Euler?[e.x,e.y,e.z]:[e,e,e]}const Ie=t.forwardRef((function({src:e,skipFill:r,skipStrokes:a,fillMaterial:i,strokeMaterial:s,fillMeshProps:l,strokeMeshProps:c,...u},m){const f=o.useLoader(d.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=>d.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",P.default({ref:m},u),C.createElement("object3D",{scale:[1,-1,1]},f.paths.map(((e,o)=>{var u,m;return C.createElement(t.Fragment,{key:o},!r&&void 0!==(null==(u=e.userData)?void 0:u.style.fill)&&"none"!==e.userData.style.fill&&d.SVGLoader.createShapes(e).map(((t,r)=>C.createElement("mesh",P.default({key:r},l),C.createElement("shapeGeometry",{args:[t]}),C.createElement("meshBasicMaterial",P.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",P.default({key:r,geometry:p[o][r]},c),C.createElement("meshBasicMaterial",P.default({color:e.userData.style.stroke,opacity:e.userData.style.strokeOpacity,transparent:!0,side:n.DoubleSide,depthWrite:!1},s))))))}))))}));let Ve=null;function je(e,t,r){return n=>{r&&r(n),e&&(Ve||(Ve=new d.DRACOLoader),Ve.setDecoderPath("string"==typeof e?e:"https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),n.setDRACOLoader(Ve)),t&&n.setMeshoptDecoder("function"==typeof d.MeshoptDecoder?d.MeshoptDecoder():d.MeshoptDecoder)}}function Oe(e,t=!0,r=!0,n){return o.useLoader(d.GLTFLoader,e,je(t,r,n))}Oe.preload=(e,t=!0,r=!0,n)=>o.useLoader.preload(d.GLTFLoader,e,je(t,r,n)),Oe.clear=e=>o.useLoader.clear(d.GLTFLoader,e);const We=C.forwardRef((({src:e,...t},r)=>{const{scene:n}=Oe(e);return C.createElement(Fe,P.default({ref:r},t,{object:n}))}));function Ge(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=0,depth:d,...m}=c,f=C.useMemo((()=>{let e;return e=new D.WebGLRenderTarget(s,l,{minFilter:D.LinearFilter,magFilter:D.LinearFilter,encoding:n.outputEncoding,type:D.HalfFloatType,...m}),d&&(e.depthTexture=new D.DepthTexture(s,l,D.FloatType)),e.samples=u,e}),[]);return C.useLayoutEffect((()=>{f.setSize(s,l),u&&(f.samples=u)}),[u,f,s,l]),C.useEffect((()=>()=>f.dispose()),[]),f}const Ne=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=Ge(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",P.default({left:u.width/-2,right:u.width/2,top:u.height/2,bottom:u.height/-2,ref:_.default([d,s])},i),!v&&n),C.createElement("group",{ref:m},v&&n(f.texture)))})),He=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=Ge(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",P.default({ref:_.default([d,s])},i),!v&&a),C.createElement("group",{ref:m},v&&a(f.texture)))}));const $e=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)),u=o.useThree((e=>e.set)),m=r||s,[f]=C.useState((()=>new d.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 u({controls:f}),()=>u({controls:e})}}),[a,f]),f?C.createElement("primitive",P.default({ref:t,object:f},i)):null})),qe=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)),u=o.useThree((e=>e.events)),m=o.useThree((e=>e.get)),f=o.useThree((e=>e.set)),p=e||u.connected||c.domElement,h=C.useMemo((()=>new d.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",P.default({ref:r,object:h,args:[l,p]},i))})),Xe=C.forwardRef(((e={enableDamping:!0},t)=>{const{domElement:r,camera:n,makeDefault:a,onChange:i,onStart:s,onEnd:l,...c}=e,u=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 d.MapControls(x)),[x]);return C.useEffect((()=>{y.connect(g);const e=e=>{u(),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,u,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",P.default({ref:t,object:y,enableDamping:!0},c))})),Ye=C.forwardRef((({makeDefault:e,events:t,camera:r,regress:n,domElement:a,enableDamping:i=!0,onChange:s,onStart:l,onEnd:c,...u},m)=>{const f=o.useThree((e=>e.invalidate)),p=o.useThree((e=>e.camera)),h=o.useThree((e=>e.gl)),v=o.useThree((e=>e.events)),g=o.useThree((e=>e.setEvents)),x=o.useThree((e=>e.set)),y=o.useThree((e=>e.get)),w=o.useThree((e=>e.performance)),M=r||p,E=a||v.connected||h.domElement,b=C.useMemo((()=>new d.OrbitControls(M)),[M]);return o.useFrame((()=>{b.enabled&&b.update()}),-1),C.useEffect((()=>(b.connect(E),()=>{b.dispose()})),[E,n,b,f]),C.useEffect((()=>{t&&g({enabled:!0});const e=e=>{f(),n&&w.regress(),s&&s(e)},r=e=>{l&&l(e),t||g({enabled:!1})},o=e=>{c&&c(e),t||g({enabled:!0})};return b.addEventListener("change",e),b.addEventListener("start",r),b.addEventListener("end",o),()=>{b.removeEventListener("start",r),b.removeEventListener("end",o),b.removeEventListener("change",e)}}),[s,l,c,b,f,t,g]),C.useEffect((()=>{if(e){const e=y().controls;return x({controls:b}),()=>x({controls:e})}}),[e,b]),C.createElement("primitive",P.default({ref:m,object:b,enableDamping:i},u))})),Ze=C.forwardRef((({makeDefault:e,camera:t,domElement:r,regress:n,onChange:a,onStart:i,onEnd:s,...l},c)=>{const{invalidate:u,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,M=C.useMemo((()=>new d.TrackballControls(y)),[y]);return o.useFrame((()=>{M.enabled&&M.update()}),-1),C.useEffect((()=>(M.connect(w),()=>{M.dispose()})),[w,n,M,u]),C.useEffect((()=>{const e=e=>{u(),n&&g.regress(),a&&a(e)};return M.addEventListener("change",e),i&&M.addEventListener("start",i),s&&M.addEventListener("end",s),()=>{i&&M.removeEventListener("start",i),s&&M.removeEventListener("end",s),M.removeEventListener("change",e)}}),[a,i,s,M,u]),C.useEffect((()=>{M.handleResize()}),[x]),C.useEffect((()=>{if(e){const e=v().controls;return h({controls:M}),()=>h({controls:e})}}),[e,M]),C.createElement("primitive",P.default({ref:c,object:M},l))})),Ke=t.forwardRef((({camera:e,makeDefault:r,regress:n,domElement:a,onChange:i,onStart:s,onEnd:l,...c},u)=>{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,M=t.useMemo((()=>new d.ArcballControls(y)),[y]);return o.useFrame((()=>{M.enabled&&M.update()}),-1),t.useEffect((()=>(M.connect(w),()=>{M.dispose()})),[w,n,M,m]),t.useEffect((()=>{const e=e=>{m(),n&&x.regress(),i&&i(e)};return M.addEventListener("change",e),s&&M.addEventListener("start",s),l&&M.addEventListener("end",l),()=>{M.removeEventListener("change",e),s&&M.removeEventListener("start",s),l&&M.removeEventListener("end",l)}}),[i,s,l]),t.useEffect((()=>{if(r){const e=g().controls;return v({controls:M}),()=>v({controls:e})}}),[r,M]),C.createElement("primitive",P.default({ref:u,object:M},c))})),Qe=C.forwardRef((({children:e,domElement:t,onChange:r,onMouseDown:n,onMouseUp:a,onObjectChange:i,object:s,makeDefault:l,...c},u)=>{const m=["enabled","axis","mode","translationSnap","rotationSnap","scaleSnap","space","size","showX","showY","showZ"],{camera:f,...p}=c,h=k.default(p,m),v=L.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)),M=o.useThree((e=>e.invalidate)),E=o.useThree((e=>e.get)),b=o.useThree((e=>e.set)),S=f||w,T=t||y.connected||x.domElement,R=C.useMemo((()=>new d.TransformControls(S,T)),[S,T]),z=C.useRef();C.useLayoutEffect((()=>(s?R.attach(s instanceof D.Object3D?s:s.current):z.current instanceof D.Object3D&&R.attach(z.current),()=>{R.detach()})),[s,e,R]),C.useEffect((()=>{if(g){const e=e=>g.enabled=!e.value;return R.addEventListener("dragging-changed",e),()=>R.removeEventListener("dragging-changed",e)}}),[R,g]);const _=C.useRef(),F=C.useRef(),A=C.useRef(),B=C.useRef();return C.useLayoutEffect((()=>{_.current=r}),[r]),C.useLayoutEffect((()=>{F.current=n}),[n]),C.useLayoutEffect((()=>{A.current=a}),[a]),C.useLayoutEffect((()=>{B.current=i}),[i]),C.useEffect((()=>{const e=e=>{M(),null==_.current||_.current(e)},t=e=>null==F.current?void 0:F.current(e),r=e=>null==A.current?void 0:A.current(e),n=e=>null==B.current?void 0:B.current(e);return R.addEventListener("change",e),R.addEventListener("mouseDown",t),R.addEventListener("mouseUp",r),R.addEventListener("objectChange",n),()=>{R.removeEventListener("change",e),R.removeEventListener("mouseDown",t),R.removeEventListener("mouseUp",r),R.removeEventListener("objectChange",n)}}),[M,R]),C.useEffect((()=>{if(l){const e=E().controls;return b({controls:R}),()=>b({controls:e})}}),[l,R]),R?C.createElement(C.Fragment,null,C.createElement("primitive",P.default({ref:u,object:R},h)),C.createElement("group",P.default({ref:z},v),e)):null})),Je=C.forwardRef((({domElement:e,selector:t,onChange:r,onLock:n,onUnlock:a,enabled:i=!0,makeDefault:s,...l},c)=>{const{camera:u,...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=u||h,M=e||g.connected||p.domElement,[E]=C.useState((()=>new d.PointerLockControls(w)));return C.useEffect((()=>{if(i){E.connect(M);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)}}),()=>{E.disconnect(),f({compute:e})}}}),[i,E]),C.useEffect((()=>{const e=e=>{v(),r&&r(e)};E.addEventListener("change",e),n&&E.addEventListener("lock",n),a&&E.addEventListener("unlock",a);const o=()=>E.lock(),i=t?Array.from(document.querySelectorAll(t)):[document];return i.forEach((e=>e&&e.addEventListener("click",o))),()=>{E.removeEventListener("change",e),n&&E.addEventListener("lock",n),a&&E.addEventListener("unlock",a),i.forEach((e=>e?e.removeEventListener("click",o):void 0))}}),[r,n,a,t,E,v]),C.useEffect((()=>{if(s){const e=x().controls;return y({controls:E}),()=>y({controls:e})}}),[s,E]),C.createElement("primitive",P.default({ref:c,object:E},m))})),et=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)),u=e||s.connected||i.domElement,[m]=C.useState((()=>new d.FirstPersonControls(a,u)));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",P.default({ref:n,object:m},r)):null})),tt=t.forwardRef(((e,r)=>{t.useMemo((()=>{A.default.install({THREE:D}),o.extend({CameraControlsImpl:A.default})}),[]);const{camera:n,domElement:a,onStart:i,onEnd:s,onChange:l,events:c,regress:u,...d}=e,m=o.useThree((e=>e.camera)),f=o.useThree((e=>e.gl)),p=o.useThree((e=>e.invalidate)),h=o.useThree((e=>e.events)),v=o.useThree((e=>e.setEvents)),g=o.useThree((e=>e.performance)),x=n||m,y=a||h.connected||f.domElement,w=t.useMemo((()=>new A.default(x)),[x]);return o.useFrame(((e,t)=>{w.enabled&&w.update(t)}),-1),t.useEffect((()=>(w.connect(y),()=>{w.disconnect()})),[y,w]),C.useEffect((()=>{c&&v({enabled:!0});const e=e=>{p(),u&&g.regress(),l&&l(e)},t=e=>{i&&i(e),c||v({enabled:!1})},r=e=>{s&&s(e),c||v({enabled:!0})};return w.addEventListener("control",e),w.addEventListener("controlstart",t),w.addEventListener("controlend",r),()=>{w.removeEventListener("control",e),w.removeEventListener("controlstart",t),w.removeEventListener("controlend",r)}}),[w,c,i,s,p,v,u,l]),C.createElement("primitive",P.default({ref:r,object:w},d))}));function rt({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 nt({children:e,renderPriority:t=1}){const{scene:r,camera:n}=o.useThree(),[a]=C.useState((()=>new D.Scene));return C.createElement(C.Fragment,null,o.createPortal(C.createElement(C.Fragment,null,e,C.createElement(rt,{defaultScene:r,defaultCamera:n,renderPriority:t})),a,{events:{priority:t+1}}))}const ot=C.createContext({}),at=()=>C.useContext(ot),it=2*Math.PI,st=new n.Object3D,lt=new n.Matrix4,[ct,ut]=[new n.Quaternion,new n.Quaternion],dt=new n.Vector3,mt=new n.Vector3,ft="#f0f0f0",pt="#999",ht="black",vt="black",gt=["Right","Left","Top","Bottom","Front","Back"],xt=e=>new n.Vector3(...e).multiplyScalar(.38),yt=[[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(xt),wt=[.25,.25,.25],Mt=[[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(xt),Et=Mt.map((e=>e.toArray().map((e=>0==e?.5:.25)))),bt=({hover:e,index:t,font:r="20px Inter var, Arial, sans-serif",faces:a=gt,color:i=ft,hoverColor:s=pt,textColor:l=ht,strokeColor:c=vt,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})},St=e=>{const{tweenCamera:t}=at(),[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(bt,P.default({key:n,index:n,hover:r===n},e)))),C.createElement("boxGeometry",null))},Tt=({onClick:e,dimensions:t,position:r,hoverColor:n=pt})=>{const{tweenCamera:o}=at(),[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 Pt({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 Ct({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",P.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 Rt=xe({cellSize:.5,sectionSize:1,fadeDistance:100,fadeStrength:1,cellThickness:.5,sectionThickness:1,cellColor:new D.Color,sectionColor:new D.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 }"),Dt=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,side:m=D.BackSide,...f},p)=>{o.extend({GridMaterial:Rt});const h={cellSize:n,sectionSize:a,cellColor:t,sectionColor:r,cellThickness:u,sectionThickness:d},v={fadeDistance:l,fadeStrength:c,infiniteGrid:s,followCamera:i};return C.createElement("mesh",P.default({ref:p,frustumCulled:!1},f),C.createElement("gridMaterial",P.default({transparent:!0,"extensions-derivatives":!0,side:m},h,v)),C.createElement("planeGeometry",{args:e}))}));function zt(e,{path:t}){const[r]=o.useLoader(n.CubeTextureLoader,[e],(e=>e.setPath(t)));return r}function _t(e){return o.useLoader(d.FBXLoader,e)}zt.preload=(e,{path:t})=>o.useLoader.preload(n.CubeTextureLoader,[e],(e=>e.setPath(t))),_t.preload=e=>o.useLoader.preload(d.FBXLoader,e),_t.clear=e=>o.useLoader.clear(d.FBXLoader,e);const Ft="https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master";function kt(e,r=`${Ft}/basis/`){const n=o.useThree((e=>e.gl)),a=o.useLoader(d.KTX2Loader,ye(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]),ye(e)){const t=Object.keys(e),r={};return t.forEach((e=>Object.assign(r,{[e]:a[t.indexOf(e)]}))),r}return a}function Lt(e,t){"function"==typeof e?e(t):null!=e&&(e.current=t)}kt.preload=(e,t=`${Ft}/basis/`)=>o.useLoader.preload(d.KTX2Loader,e,(e=>{e.setTranscoderPath(t)})),kt.clear=e=>o.useLoader.clear(d.KTX2Loader,e);function At(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}const Bt=e=>e.isMesh;const Ut=C.forwardRef((({enabled:e=!0,firstHitOnly:t=!1,children:r,splitStrategy:a="SAH",verbose:i=!1,setBoundingBox:s=!0,maxDepth:l=40,maxLeafTris:c=10,...u},d)=>{const m=C.useRef(null),f=o.useThree((e=>e.raycaster));return C.useImperativeHandle(d,(()=>m.current),[]),C.useEffect((()=>{if(e){const e={splitStrategy:a,verbose:i,setBoundingBox:s,maxDepth:l,maxLeafTris:c},r=m.current;return f.firstHitOnly=t,r.traverse((t=>{Bt(t)&&!t.geometry.boundsTree&&t.raycast===n.Mesh.prototype.raycast&&(t.raycast=M.acceleratedRaycast,t.geometry.computeBoundsTree=M.computeBoundsTree,t.geometry.disposeBoundsTree=M.disposeBoundsTree,t.geometry.computeBoundsTree(e))})),()=>{delete f.firstHitOnly,r.traverse((e=>{Bt(e)&&e.geometry.boundsTree&&(e.geometry.disposeBoundsTree(),e.raycast=n.Mesh.prototype.raycast)}))}}})),C.createElement("group",P.default({ref:m},u),r)}));const It=new D.Box3,Vt=new D.Vector3;const jt=e=>Math.sqrt(1-Math.pow(e-1,2));class Ot{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=jt}={}){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 Wt=C.forwardRef((({children:e,curve:t},r)=>{const[n]=C.useState((()=>new D.Scene)),[a,i]=C.useState(),s=C.useRef();return C.useEffect((()=>{s.current=new d.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 Gt 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 Nt=C.forwardRef((({speed:e=1,...t},r)=>{const[n]=C.useState((()=>new Gt));return o.useFrame((t=>n&&(n.time=t.clock.getElapsedTime()*e))),C.createElement("primitive",P.default({object:n,ref:r,attach:"material"},t))}));class Ht 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 $t=C.forwardRef((({speed:e=1,...t},r)=>{const[n]=C.useState((()=>new Ht));return o.useFrame((t=>n&&(n.time=t.clock.getElapsedTime()*e))),C.createElement("primitive",P.default({object:n,ref:r,attach:"material"},t))}));class qt 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 Xt{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 qt,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 Yt 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:Yt});const Zt=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,M=C.useRef(null),[E]=C.useState((()=>new n.Plane)),[b]=C.useState((()=>new n.Vector3)),[S]=C.useState((()=>new n.Vector3)),[T]=C.useState((()=>new n.Vector3)),[R]=C.useState((()=>new n.Matrix4)),[D]=C.useState((()=>new n.Vector3(0,0,-1))),[z]=C.useState((()=>new n.Vector4)),[F]=C.useState((()=>new n.Vector3)),[k]=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=M.current.parent||(null==(e=M.current)?void 0:e.__r3f.parent);if(!t)return;if(S.setFromMatrixPosition(t.matrixWorld),T.setFromMatrixPosition(x.matrixWorld),R.extractRotation(t.matrixWorld),b.set(0,0,1),b.applyMatrix4(R),S.addScaledVector(b,p),F.subVectors(S,T),F.dot(b)>0)return;F.reflect(b).negate(),F.add(S),R.extractRotation(x.matrixWorld),D.set(0,0,-1),D.applyMatrix4(R),D.add(T),k.subVectors(S,D),k.reflect(b).negate(),k.add(S),B.position.copy(F),B.up.set(0,1,0),B.up.applyMatrix4(R),B.up.reflect(b),B.lookAt(k),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),E.setFromNormalAndCoplanarPoint(b,S),E.applyMatrix4(B.matrixWorldInverse),z.set(E.normal.x,E.normal.y,E.normal.z,E.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]),[I,V,j,O]=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 Xt({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=M.current.parent||(null==(e=M.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(I),g.state.buffers.depth.setMask(!0),g.autoClear||g.clear(),g.render(y,B),w&&j.render(g,I,V),g.xr.enabled=r,g.shadowMap.autoUpdate=n,t.visible=!0,g.setRenderTarget(null)})),C.createElement("meshReflectorMaterialImpl",P.default({attach:"material",key:"key"+O["defines-USE_BLUR"]+O["defines-USE_DEPTH"]+O["defines-USE_DISTORTION"],ref:_.default([M,v])},O,h))})),Kt=xe({envMap:null,bounces:3,ior:2.4,correctMips:!0,aberrationStrength:.01,fresnel:0,bvh:new M.MeshBVHUniformStruct,color:new D.Color("white"),resolution:new D.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 ${M.shaderStructs}\n ${M.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 }`);const Qt=xe({},"void main() { }","void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); discard; }");class Jt extends D.MeshPhysicalMaterial{constructor(e=6,t=!1){super(),this.uniforms={chromaticAberration:{value:.05},transmission:{value:0},_transmission:{value:1},transmissionMap:{value:null},roughness:{value:0},thickness:{value:0},thicknessMap:{value:null},attenuationDistance:{value:1/0},attenuationColor:{value:new D.Color("white")},anisotropy:{value:.1},time:{value:0},distortion:{value:0},distortionScale:{value:.5},temporalDistortion:{value:0},buffer:{value:null}},this.onBeforeCompile=r=>{r.uniforms={...r.uniforms,...this.uniforms},t?r.defines.USE_SAMPLER="":r.defines.USE_TRANSMISSION="",r.fragmentShader="\n uniform float chromaticAberration; \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 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 m &= ieeeMantissa; // Keep only mantissa bits (fractional part)\n m |= ieeeOne; // Add fractional part to 1.0\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"+r.fragmentShader,r.fragmentShader=r.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 float framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior ); \n #ifdef USE_SAMPLER\n #ifdef texture2DLodEXT\n return texture2DLodEXT(transmissionSamplerMap, fragCoord.xy, framebufferLod);\n #else\n return texture2D(transmissionSamplerMap, fragCoord.xy, framebufferLod);\n #endif\n #else\n return texture2D(buffer, fragCoord.xy);\n #endif\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"),r.fragmentShader=r.fragmentShader.replace("#include <transmission_fragment>",` \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 er=C.forwardRef((({buffer:e,transmissionSampler:t=!1,backside:r=!1,transmission:n=1,thickness:a=0,samples:i=10,resolution:s,backsideResolution:l,background:c,...u},d)=>{o.extend({MeshTransmissionMaterial:Jt});const m=C.useRef(null),[f]=C.useState((()=>new Qt)),p=Ge(l||s),h=Ge(s);let v,g,x;return o.useFrame((n=>{m.current.time=n.clock.getElapsedTime(),e||t||(x=m.current.__r3f.parent,x&&(g=n.gl.toneMapping,v=n.scene.background,n.gl.toneMapping=D.NoToneMapping,c&&(n.scene.background=c),x.material=f,r&&(n.gl.setRenderTarget(p),n.gl.render(n.scene,n.camera),x.material=m.current,x.material.buffer=p.texture,x.material.thickness=1/(a+.01),x.material.side=D.BackSide),n.gl.setRenderTarget(h),n.gl.render(n.scene,n.camera),x.material=m.current,x.material.thickness=a,x.material.side=D.FrontSide,x.material.buffer=h.texture,n.scene.background=v,n.gl.setRenderTarget(null),x.material=m.current,n.gl.toneMapping=g))})),C.useImperativeHandle(d,(()=>m.current),[]),C.createElement("meshTransmissionMaterial",P.default({args:[i,t],ref:m},u,{buffer:e||h.texture,_transmission:n,transmission:t?n:0,thickness:a}))}));class tr extends D.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 rr=C.forwardRef(((e,t)=>{const[r]=C.useState((()=>new tr(null)));return C.createElement("primitive",P.default({},e,{object:r,ref:t,attach:"material"}))})),nr=({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 or=!1;function ar(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 ir(e){const t=e+"Geometry";return C.forwardRef((({args:e,children:r,...n},o)=>C.createElement("mesh",P.default({ref:o},n),C.createElement(t,{attach:"geometry",args:e}),r)))}const sr=ir("box"),lr=ir("circle"),cr=ir("cone"),ur=ir("cylinder"),dr=ir("sphere"),mr=ir("plane"),fr=ir("tube"),pr=ir("torus"),hr=ir("torusKnot"),vr=ir("tetrahedron"),gr=ir("ring"),xr=ir("polyhedron"),yr=ir("icosahedron"),wr=ir("octahedron"),Mr=ir("dodecahedron"),Er=ir("extrude"),br=ir("lathe"),Sr=ir("capsule"),Tr=1e-5;const Pr=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-Tr;return o.absarc(Tr,Tr,Tr,-Math.PI/2,-Math.PI,!0),o.absarc(Tr,t-2*a,Tr,Math.PI,Math.PI/2,!0),o.absarc(e-2*a,t-2*a,Tr,Math.PI/2,0,!0),o.absarc(e-2*a,Tr,Tr,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-Tr,bevelThickness:o,curveSegments:i})),[r,o,i]),m=C.useRef();return C.useLayoutEffect((()=>{m.current&&m.current.center()}),[u,d]),C.createElement("mesh",P.default({ref:c},l),C.createElement("extrudeGeometry",{ref:m,args:[u,d]}),s)}));function Cr(){const e=new D.BufferGeometry,t=new Float32Array([-1,-1,3,-1,-1,3]);return e.setAttribute("position",new D.BufferAttribute(t,2)),e}const Rr=C.forwardRef((function({children:e,...t},r){const n=C.useMemo(Cr,[]);return C.createElement("mesh",P.default({ref:r,geometry:n,frustumCulled:!1},t),e)})),Dr=C.forwardRef((function({children:e,disable:t,disableX:r,disableY:o,disableZ:a,left:i,right:s,top:l,bottom:c,front:u,back:d,onCentered:m,precise:f=!0,...p},h){const v=C.useRef(null),g=C.useRef(null),x=C.useRef(null);return C.useLayoutEffect((()=>{g.current.matrixWorld.identity();const e=(new n.Box3).setFromObject(x.current,f),p=new n.Vector3,h=new n.Sphere,y=e.max.x-e.min.x,w=e.max.y-e.min.y,M=e.max.z-e.min.z;e.getCenter(p),e.getBoundingSphere(h);const E=l?w/2:c?-w/2:0,b=i?-y/2:s?y/2:0,S=u?M/2:d?-M/2:0;g.current.position.set(t||r?0:-p.x+b,t||o?0:-p.y+E,t||a?0:-p.z+S),void 0!==m&&m({parent:v.current.parent,container:v.current,width:y,height:w,depth:M,boundingBox:e,boundingSphere:h,center:p,verticalAlignment:E,horizontalAlignment:b,depthAlignment:S})}),[e]),C.useImperativeHandle(h,(()=>v.current),[]),C.createElement("group",P.default({ref:v},p),C.createElement("group",{ref:g},C.createElement("group",{ref:x},e)))})),zr=e=>e&&e.isOrthographicCamera,_r=C.createContext(null);function Fr({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=D.MathUtils.damp(e.x,t.x,r,n),e.y=D.MathUtils.damp(e.y,t.y,r,n),e.z=D.MathUtils.damp(e.z,t.z,r,n)}h.current=l;const[x]=C.useState((()=>({animating:!1,focus:new D.Vector3,camera:new D.Vector3,zoom:1}))),[y]=C.useState((()=>({focus:new D.Vector3,camera:new D.Vector3,zoom:1}))),[w]=C.useState((()=>new D.Box3)),M=C.useMemo((()=>{function e(){const e=w.getSize(new D.Vector3),t=w.getCenter(new D.Vector3),r=Math.max(e.x,e.y,e.z),n=zr(u)?4*r:r/(2*Math.atan(Math.PI*u.fov/360)),o=zr(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 D.Vector3,new D.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),zr(u)){x.zoom=u.zoom;let e=0,n=0;const o=[new D.Vector3(w.min.x,w.min.y,w.min.z),new D.Vector3(w.min.x,w.max.y,w.min.z),new D.Vector3(w.min.x,w.min.y,w.max.z),new D.Vector3(w.min.x,w.max.y,w.max.z),new D.Vector3(w.max.x,w.max.y,w.max.z),new D.Vector3(w.max.x,w.max.y,w.min.z),new D.Vector3(w.max.x,w.min.y,w.max.z),new D.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 E=C.useRef(0);return C.useLayoutEffect((()=>{(a||0==E.current++)&&(M.refresh(),r&&M.fit(),n&&M.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=D.MathUtils.damp(x.zoom,y.zoom,t,r),u.position.copy(x.camera),zr(u)&&(u.zoom=x.zoom,u.updateProjectionMatrix()),p?(p.target.copy(x.focus),p.update()):u.lookAt(x.focus),d(),zr(u)&&!(Math.abs(x.zoom-y.zoom)<s))return;if(!zr(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(_r.Provider,{value:M},e))}function kr(){return C.useContext(_r)}const Lr=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},u)=>{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 d.SimplexNoise)),[g]=C.useState((()=>new d.SimplexNoise)),[x]=C.useState((()=>new d.SimplexNoise)),y=()=>{(p.current<0||p.current>1)&&(p.current=p.current<0?0:1)};return C.useImperativeHandle(u,(()=>({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})),Ar=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=D.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:_.default([l,s])},e))})),Br={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 Ur(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 Ir({scene:e,background:t=!1,blur:r,map:n}){const a=o.useThree((e=>e.scene));return C.useLayoutEffect((()=>{if(n)return Ur(t,e,a,n,r)}),[a,e,n,t,r]),null}function Vr({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 Br))throw new Error("Preset must be one of: "+Object.keys(Br).join(", "));e=Br[r],t="https://market-assets.fra1.cdn.digitaloceanspaces.com/market-assets/hdris/"}const s=Array.isArray(e),l=s?n.CubeTextureLoader:d.RGBELoader,c=o.useLoader(l,s?[e]:e,(e=>{e.setPath(t),i&&i(e)})),u=s?c[0]:c;return u.mapping=s?n.CubeReflectionMapping:n.EquirectangularReflectionMapping,u.encoding=(null!=a?a:s)?n.sRGBEncoding:n.LinearEncoding,u}function jr({background:e=!1,scene:t,blur:r,...n}){const a=Vr(n),i=o.useThree((e=>e.scene));return C.useLayoutEffect((()=>Ur(e,t,i,a,r)),[a,e,t,i,r]),null}function Or({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),Ur(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(jr,{background:!0,files:d,preset:f,path:m,extensions:p}):s?C.createElement(Ir,{background:!0,map:s,extensions:p}):null),x))}function Wr(e){var t,r,n,a;const i=Vr(e),s=e.map||i;C.useMemo((()=>o.extend({GroundProjectedEnvImpl:d.GroundProjectedEnv})),[]);const l=C.useMemo((()=>[s]),[s]),c=null==(t=e.ground)?void 0:t.height,u=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(Ir,P.default({},e,{map:s})),C.createElement("groundProjectedEnvImpl",{args:l,scale:m,height:c,radius:u}))}function Gr(e){return e.ground?C.createElement(Wr,e):e.map?C.createElement(Ir,e):e.children?C.createElement(Or,e):C.createElement(jr,e)}const Nr=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:u="#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,M,E,b,S,T]=C.useMemo((()=>{const e=new D.WebGLRenderTarget(l,l),t=new D.WebGLRenderTarget(l,l);t.texture.generateMipmaps=e.texture.generateMipmaps=!1;const r=new D.PlaneGeometry(n,a).rotateX(Math.PI/2),o=new D.Mesh(r),i=new D.MeshDepthMaterial;i.depthTest=i.depthWrite=!1,i.onBeforeCompile=e=>{e.uniforms={...e.uniforms,ucolor:{value:new D.Color(u)}},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 D.ShaderMaterial(d.HorizontalBlurShader),c=new D.ShaderMaterial(d.VerticalBlurShader);return c.depthTest=s.depthTest=!1,[e,r,i,o,s,c,t]}),[l,n,a,e,u]),R=e=>{E.visible=!0,E.material=b,b.uniforms.tDiffuse.value=y.texture,b.uniforms.h.value=1*e/256,g.setRenderTarget(T),g.render(E,x.current),E.material=S,S.uniforms.tDiffuse.value=T.texture,S.uniforms.v.value=1*e/256,g.setRenderTarget(y),g.render(E,x.current),E.visible=!1};let z=0;return o.useFrame((()=>{if(x.current&&(t===1/0||z<t)){const e=v.background;v.background=null;const t=v.overrideMaterial;v.overrideMaterial=M,g.setRenderTarget(y),g.render(v,x.current),v.overrideMaterial=t,R(i),c&&R(.4*i),g.setRenderTarget(null),v.background=e,z++}})),C.createElement("group",P.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 Hr=C.createContext(null),$r=xe({color:new D.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 }"),qr=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:$r});const h=o.useThree((e=>e.gl)),v=o.useThree((e=>e.scene)),g=o.useThree((e=>e.camera)),x=o.useThree((e=>e.invalidate)),y=C.useRef(null),w=C.useRef(null),[M]=C.useState((()=>new Yr(h,v,d)));C.useLayoutEffect((()=>{M.configure(y.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:()=>y.current,reset:()=>{M.clear();const e=y.current.material;e.opacity=0,e.alphaTest=0,E.count=0},update:(e=1)=>{const t=y.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),w.current.visible=!0,M.prepare();for(let t=0;t<e;t++)E.lights.forEach((e=>e.update())),M.update(g,E.blend);w.current.visible=!1,M.finish()}})),[M,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&&(x(),E.update(),E.count++)})),C.createElement("group",f,C.createElement("group",{traverse:()=>null,ref:w},C.createElement(Hr.Provider,{value:E},e)),C.createElement("mesh",{receiveShadow:!0,ref:y,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:M.progressiveLightMap2.texture})))})),Xr=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 D.Vector3(...s).length(),v=C.useContext(Hr),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]+D.MathUtils.randFloatSpread(l),s[1]+D.MathUtils.randFloatSpread(l),s[2]+D.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",P.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 Yr{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 D.Color,this.clearAlpha=0;const n=/(Android|iPad|iPhone|iPod)/g.test(navigator.userAgent)?D.HalfFloatType:D.FloatType;this.progressiveLightMap1=new D.WebGLRenderTarget(this.res,this.res,{type:n,encoding:e.outputEncoding}),this.progressiveLightMap2=new D.WebGLRenderTarget(this.res,this.res,{type:n,encoding:e.outputEncoding}),this.discardMat=new Qt,this.targetMat=new D.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 Zr={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 Kr({radius:e,adjustCamera:t}){const r=kr();return C.useEffect((()=>{t&&r.refresh().clip().fit()}),[e,t]),null}const Qr=e=>0===e?0:Math.pow(2,10*e-10);const Jr=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",P.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]})))}));function en(e=D.FrontSide){const t={value:new D.Matrix4};return Object.assign(new D.MeshNormalMaterial({side:e}),{viewMatrix:t,onBeforeCompile:e=>{e.uniforms.viewMatrix=t,e.fragmentShader="vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n }\n"+e.fragmentShader.replace("#include <normal_fragment_maps>","#include <normal_fragment_maps>\n normal = inverseTransformDirection( normal, viewMatrix );\n")}})}const tn=xe({causticsTexture:null,causticsTextureB:null,color:new D.Color,lightProjMatrix:new D.Matrix4,lightViewMatrix:new D.Matrix4},"varying vec3 vWorldPosition; \n void main() {\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);\n vec4 worldPosition = modelMatrix * vec4(position, 1.);\n vWorldPosition = worldPosition.xyz;\n }","varying vec3 vWorldPosition;\n uniform vec3 color;\n uniform sampler2D causticsTexture; \n uniform sampler2D causticsTextureB; \n uniform mat4 lightProjMatrix;\n uniform mat4 lightViewMatrix;\n void main() {\n // Apply caustics \n vec4 lightSpacePos = lightProjMatrix * lightViewMatrix * vec4(vWorldPosition, 1.0);\n lightSpacePos.xyz /= lightSpacePos.w;\n lightSpacePos.xyz = lightSpacePos.xyz * 0.5 + 0.5; \n vec3 front = texture2D(causticsTexture, lightSpacePos.xy).rgb;\n vec3 back = texture2D(causticsTextureB, lightSpacePos.xy).rgb;\n gl_FragColor = vec4((front + back) * color, 1.0);\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n }"),rn=xe({cameraMatrixWorld:new D.Matrix4,cameraProjectionMatrixInv:new D.Matrix4,normalTexture:null,depthTexture:null,lightDir:new D.Vector3(0,1,0),lightPlaneNormal:new D.Vector3(0,1,0),lightPlaneConstant:0,near:.1,far:100,modelMatrix:new D.Matrix4,worldRadius:1/40,ior:1.1,bounces:0,resolution:1024,size:10,intensity:.5},"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }"," \n uniform mat4 cameraMatrixWorld;\n uniform mat4 cameraProjectionMatrixInv;\n uniform vec3 lightDir;\n uniform vec3 lightPlaneNormal;\n uniform float lightPlaneConstant;\n uniform float near;\n uniform float far;\n uniform float time;\n uniform float worldRadius;\n uniform float resolution;\n uniform float size;\n uniform float intensity;\n uniform float ior;\n precision highp isampler2D;\n precision highp usampler2D;\n uniform sampler2D normalTexture;\n uniform sampler2D depthTexture;\n uniform float bounces;\n varying vec2 vUv;\n vec3 WorldPosFromDepth(float depth, vec2 coord) {\n float z = depth * 2.0 - 1.0;\n vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);\n vec4 viewSpacePosition = cameraProjectionMatrixInv * clipSpacePosition;\n // Perspective division\n viewSpacePosition /= viewSpacePosition.w;\n vec4 worldSpacePosition = cameraMatrixWorld * viewSpacePosition;\n return worldSpacePosition.xyz;\n } \n float sdPlane( vec3 p, vec3 n, float h ) {\n // n must be normalized\n return dot(p,n) + h;\n }\n float planeIntersect( vec3 ro, vec3 rd, vec4 p ) {\n return -(dot(ro,p.xyz)+p.w)/dot(rd,p.xyz);\n }\n vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 pos, vec3 normal, float ior, out vec3 rayOrigin, out vec3 rayDirection) {\n rayOrigin = ro;\n rayDirection = rd;\n rayDirection = refract(rayDirection, normal, 1.0 / ior);\n rayOrigin = pos + rayDirection * 0.1;\n return rayDirection;\n }\n void main() {\n // Each sample consists of random offset in the x and y direction\n float caustic = 0.0;\n float causticTexelSize = (1.0 / resolution) * size * 2.0;\n float texelsNeeded = worldRadius / causticTexelSize;\n float sampleRadius = texelsNeeded / resolution;\n float sum = 0.0;\n if (texture2D(depthTexture, vUv).x == 1.0) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n return;\n }\n vec2 offset1 = vec2(-0.5, -0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 offset2 = vec2(-0.5, 0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 offset3 = vec2(0.5, 0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 offset4 = vec2(0.5, -0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 uv1 = vUv + offset1 * sampleRadius;\n vec2 uv2 = vUv + offset2 * sampleRadius;\n vec2 uv3 = vUv + offset3 * sampleRadius;\n vec2 uv4 = vUv + offset4 * sampleRadius;\n vec3 normal1 = texture2D(normalTexture, uv1, -10.0).rgb * 2.0 - 1.0;\n vec3 normal2 = texture2D(normalTexture, uv2, -10.0).rgb * 2.0 - 1.0;\n vec3 normal3 = texture2D(normalTexture, uv3, -10.0).rgb * 2.0 - 1.0;\n vec3 normal4 = texture2D(normalTexture, uv4, -10.0).rgb * 2.0 - 1.0;\n float depth1 = texture2D(depthTexture, uv1, -10.0).x;\n float depth2 = texture2D(depthTexture, uv2, -10.0).x;\n float depth3 = texture2D(depthTexture, uv3, -10.0).x;\n float depth4 = texture2D(depthTexture, uv4, -10.0).x;\n // Sanity check the depths\n if (depth1 == 1.0 || depth2 == 1.0 || depth3 == 1.0 || depth4 == 1.0) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n return;\n }\n vec3 pos1 = WorldPosFromDepth(depth1, uv1);\n vec3 pos2 = WorldPosFromDepth(depth2, uv2);\n vec3 pos3 = WorldPosFromDepth(depth3, uv3);\n vec3 pos4 = WorldPosFromDepth(depth4, uv4);\n vec3 originPos1 = WorldPosFromDepth(0.0, uv1);\n vec3 originPos2 = WorldPosFromDepth(0.0, uv2);\n vec3 originPos3 = WorldPosFromDepth(0.0, uv3);\n vec3 originPos4 = WorldPosFromDepth(0.0, uv4);\n vec3 endPos1, endPos2, endPos3, endPos4;\n vec3 endDir1, endDir2, endDir3, endDir4;\n totalInternalReflection(originPos1, lightDir, pos1, normal1, ior, endPos1, endDir1);\n totalInternalReflection(originPos2, lightDir, pos2, normal2, ior, endPos2, endDir2);\n totalInternalReflection(originPos3, lightDir, pos3, normal3, ior, endPos3, endDir3);\n totalInternalReflection(originPos4, lightDir, pos4, normal4, ior, endPos4, endDir4);\n float lightPosArea = length(cross(originPos2 - originPos1, originPos3 - originPos1)) + length(cross(originPos3 - originPos1, originPos4 - originPos1));\n float t1 = planeIntersect(endPos1, endDir1, vec4(lightPlaneNormal, lightPlaneConstant));\n float t2 = planeIntersect(endPos2, endDir2, vec4(lightPlaneNormal, lightPlaneConstant));\n float t3 = planeIntersect(endPos3, endDir3, vec4(lightPlaneNormal, lightPlaneConstant));\n float t4 = planeIntersect(endPos4, endDir4, vec4(lightPlaneNormal, lightPlaneConstant));\n vec3 finalPos1 = endPos1 + endDir1 * t1;\n vec3 finalPos2 = endPos2 + endDir2 * t2;\n vec3 finalPos3 = endPos3 + endDir3 * t3;\n vec3 finalPos4 = endPos4 + endDir4 * t4;\n float finalArea = length(cross(finalPos2 - finalPos1, finalPos3 - finalPos1)) + length(cross(finalPos3 - finalPos1, finalPos4 - finalPos1));\n caustic += intensity * (lightPosArea / finalArea);\n // Calculate the area of the triangle in light spaces\n gl_FragColor = vec4(vec3(max(caustic, 0.0)), 1.0);\n }"),nn={depth:!0,minFilter:D.LinearFilter,magFilter:D.LinearFilter,encoding:D.LinearEncoding,type:D.UnsignedByteType},on={minFilter:D.LinearMipmapLinearFilter,magFilter:D.LinearFilter,encoding:D.LinearEncoding,format:D.RGBAFormat,type:D.FloatType,generateMipmaps:!0},an=C.forwardRef((({debug:e,children:t,frames:r=1,ior:n=1.1,color:a="white",causticsOnly:i=!1,backside:s=!1,backsideIOR:l=1.1,worldRadius:c=.3125,intensity:u=.05,resolution:m=2024,lightSource:f=[5,5,5],...p},h)=>{o.extend({CausticsProjectionMaterial:tn});const v=C.useRef(null),g=C.useRef(null),x=C.useRef(null),y=C.useRef(null),w=o.useThree((e=>e.gl)),M=At(e&&g,D.CameraHelper),E=Ge(m,m,nn),b=Ge(m,m,nn),S=Ge(m,m,on),T=Ge(m,m,on),[R]=C.useState((()=>en())),[z]=C.useState((()=>en(D.BackSide))),[_]=C.useState((()=>new rn)),[F]=C.useState((()=>new d.FullScreenQuad(_)));C.useLayoutEffect((()=>{v.current.updateWorldMatrix(!1,!0)}));let k=0;const L=new D.Vector3,A=new D.Frustum,B=new D.Matrix4,U=new D.Plane,I=new D.Vector3,V=new D.Vector3,j=new D.Box3,O=new D.Vector3;return o.useFrame(((t,o)=>{if(r===1/0||k++<r){var a,d;Array.isArray(f)?I.fromArray(f).normalize():I.copy(v.current.worldToLocal(f.current.getWorldPosition(L)).normalize()),V.copy(I).multiplyScalar(-1);let t=[];null==(a=x.current.parent)||a.matrixWorld.identity(),j.setFromObject(x.current,!0),t.push(new D.Vector3(j.min.x,j.min.y,j.min.z)),t.push(new D.Vector3(j.min.x,j.min.y,j.max.z)),t.push(new D.Vector3(j.min.x,j.max.y,j.min.z)),t.push(new D.Vector3(j.min.x,j.max.y,j.max.z)),t.push(new D.Vector3(j.max.x,j.min.y,j.min.z)),t.push(new D.Vector3(j.max.x,j.min.y,j.max.z)),t.push(new D.Vector3(j.max.x,j.max.y,j.min.z)),t.push(new D.Vector3(j.max.x,j.max.y,j.max.z));const r=t.map((e=>e.clone()));j.getCenter(O),t=t.map((e=>e.clone().sub(O)));const o=U.set(V,0),p=t.map((e=>o.projectPoint(e,new D.Vector3))),h=p.reduce(((e,t)=>e.add(t)),L.set(0,0,0)).divideScalar(p.length),P=p.map((e=>e.distanceTo(h))).reduce(((e,t)=>Math.max(e,t))),C=t.map((e=>e.dot(I))).reduce(((e,t)=>Math.max(e,t)));g.current.position.copy(I.clone().multiplyScalar(C).add(O)),g.current.lookAt(x.current.localToWorld(O.clone()));const k=B.lookAt(g.current.position,O,L.set(0,1,0));g.current.left=-P,g.current.right=P,g.current.top=P,g.current.bottom=-P;const W=L.set(0,P,0).applyMatrix4(k),G=(g.current.position.y+W.y)/I.y;g.current.near=.1,g.current.far=G,g.current.updateProjectionMatrix(),g.current.updateMatrixWorld();const N=r.map((e=>e.add(I.clone().multiplyScalar(-e.y/I.y)))),H=N.reduce(((e,t)=>e.add(t)),L.set(0,0,0)).divideScalar(N.length),$=2*N.map((e=>Math.hypot(e.x-H.x,e.z-H.z))).reduce(((e,t)=>Math.max(e,t)));y.current.scale.setScalar($),y.current.position.copy(H),e&&(null==(d=M.current)||d.update()),z.viewMatrix.value=R.viewMatrix.value=g.current.matrixWorldInverse;const q=A.setFromProjectionMatrix(B.multiplyMatrices(g.current.projectionMatrix,g.current.matrixWorldInverse)).planes[4];_.cameraMatrixWorld=g.current.matrixWorld,_.cameraProjectionMatrixInv=g.current.projectionMatrixInverse,_.lightDir=V,_.lightPlaneNormal=q.normal,_.lightPlaneConstant=q.constant,_.near=g.current.near,_.far=g.current.far,_.resolution=m,_.size=P,_.intensity=u,_.worldRadius=c,x.current.visible=!0,w.setRenderTarget(E),w.clear(),x.current.overrideMaterial=R,w.render(x.current,g.current),w.setRenderTarget(b),w.clear(),s&&(x.current.overrideMaterial=z,w.render(x.current,g.current)),x.current.overrideMaterial=null,_.ior=n,y.current.material.lightProjMatrix=g.current.projectionMatrix,y.current.material.lightViewMatrix=g.current.matrixWorldInverse,_.normalTexture=E.texture,_.depthTexture=E.depthTexture,w.setRenderTarget(S),w.clear(),F.render(w),_.ior=l,_.normalTexture=b.texture,_.depthTexture=b.depthTexture,w.setRenderTarget(T),w.clear(),s&&F.render(w),w.setRenderTarget(null),i&&(x.current.visible=!1)}})),C.useImperativeHandle(h,(()=>v.current),[]),C.createElement("group",P.default({ref:v},p),C.createElement("scene",{ref:x},C.createElement("orthographicCamera",{ref:g,up:[0,1,0]}),t),C.createElement("mesh",{renderOrder:2,ref:y,"rotation-x":-Math.PI/2},C.createElement("planeGeometry",null),C.createElement("causticsProjectionMaterial",{transparent:!0,color:a,causticsTexture:S.texture,causticsTextureB:T.texture,blending:D.CustomBlending,blendSrc:D.OneFactor,blendDst:D.SrcAlphaFactor,depthWrite:!1}),e&&C.createElement(Pe,null,C.createElement("lineBasicMaterial",{color:"#ffff00",toneMapped:!1}))))}));o.extend({MeshReflectorMaterial:Yt});const sn=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)),M=o.useThree((({scene:e})=>e)),E=(a=Array.isArray(a)?a:[a,a])[0]+a[1]>0,b=C.useRef(null),[S]=C.useState((()=>new n.Plane)),[T]=C.useState((()=>new n.Vector3)),[R]=C.useState((()=>new n.Vector3)),[D]=C.useState((()=>new n.Vector3)),[z]=C.useState((()=>new n.Matrix4)),[F]=C.useState((()=>new n.Vector3(0,0,-1))),[k]=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)),[I]=C.useState((()=>new n.PerspectiveCamera)),V=C.useCallback((()=>{if(R.setFromMatrixPosition(b.current.matrixWorld),D.setFromMatrixPosition(w.matrixWorld),z.extractRotation(b.current.matrixWorld),T.set(0,0,1),T.applyMatrix4(z),L.subVectors(R,D),L.dot(T)>0)return;L.reflect(T).negate(),L.add(R),z.extractRotation(w.matrixWorld),F.set(0,0,-1),F.applyMatrix4(z),F.add(D),A.subVectors(R,F),A.reflect(T).negate(),A.add(R),I.position.copy(L),I.up.set(0,1,0),I.up.applyMatrix4(z),I.up.reflect(T),I.lookAt(A),I.far=w.far,I.updateMatrixWorld(),I.projectionMatrix.copy(w.projectionMatrix),U.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),U.multiply(I.projectionMatrix),U.multiply(I.matrixWorldInverse),U.multiply(b.current.matrixWorld),S.setFromNormalAndCoplanarPoint(T,R),S.applyMatrix4(I.matrixWorldInverse),k.set(S.normal.x,S.normal.y,S.normal.z,S.constant);const e=I.projectionMatrix;B.x=(Math.sign(k.x)+e.elements[8])/e.elements[0],B.y=(Math.sign(k.y)+e.elements[9])/e.elements[5],B.z=-1,B.w=(1+e.elements[10])/e.elements[14],k.multiplyScalar(2/k.dot(B)),e.elements[2]=k.x,e.elements[6]=k.y,e.elements[10]=k.z+1,e.elements[14]=k.w}),[]),[j,O,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 Xt({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:E,mixStrength:t,minDepthThreshold:s,maxDepthThreshold:l,depthScale:c,depthToBlurRatioBias:u,transparent:!0,debug:f,distortion:p,distortionMap:v,mixContrast:h,"defines-USE_BLUR":E?"":void 0,"defines-USE_DEPTH":c>0?"":void 0,"defines-USE_DISTORTION":v?"":void 0}]}),[y,a,U,r,d,E,e,t,s,l,c,u,f,p,v,h]);return o.useFrame((()=>{if(null==b||!b.current)return;b.current.visible=!1;const e=y.xr.enabled,t=y.shadowMap.autoUpdate;V(),y.xr.enabled=!1,y.shadowMap.autoUpdate=!1,y.setRenderTarget(j),y.state.buffers.depth.setMask(!0),y.autoClear||y.clear(),y.render(M,I),E&&W.render(y,j,O),y.xr.enabled=e,y.shadowMap.autoUpdate=t,b.current.visible=!0,y.setRenderTarget(null)})),C.createElement("mesh",P.default({ref:_.default([b,x])},g),C.createElement("planeGeometry",{args:i}),m?m("meshReflectorMaterial",G):C.createElement("meshReflectorMaterial",G))}));class ln 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 cn({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 ln)),[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 un(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 dn({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,...u}){const m=C.useRef(null),f=u.spotlightRef,p=u.debug;un(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 d.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 mn({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 un(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 fn=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",P.default({ref:_.default([f,p]),angle:i,color:o,distance:a,castShadow:!0},m),c&&C.createElement(cn,{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}))})),pn=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 D.Vector3(...l):l)}),[l]),s=Array.isArray(s)&&2===s.length?[s[0],s[1],1]:s,C.createElement("mesh",P.default({ref:_.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:D.DoubleSide})))}));function hn(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 vn=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=hn(e,t),...c},u)=>{const m=C.useMemo((()=>(new n.Vector3).setScalar(r)),[r]),[f]=C.useState((()=>new d.Sky));return C.createElement("primitive",P.default({object:f,ref:u,"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 gn 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 xn=e=>(new n.Vector3).setFromSpherical(new n.Spherical(e,Math.acos(1-2*Math.random()),2*Math.random()*Math.PI)),yn=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(...xn(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 gn));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 wn=xe({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);}"),Mn=e=>e&&e.constructor===Float32Array,En=e=>e instanceof D.Vector2||e instanceof D.Vector3||e instanceof D.Vector4,bn=e=>Array.isArray(e)?e:En(e)?e.toArray():[e,e,e];function Sn(e,t,r){return C.useMemo((()=>{if(void 0!==t){if(Mn(t))return t;if(t instanceof D.Color){const r=Array.from({length:3*e},(()=>(e=>[e.r,e.g,e.b])(t))).flat();return Float32Array.from(r)}if(En(t)||Array.isArray(t)){const r=Array.from({length:3*e},(()=>bn(t))).flat();return Float32Array.from(r)}return Float32Array.from({length:e},(()=>t))}return Float32Array.from({length:e},r)}),[t])}const Tn=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:wn})),[]);const u=C.useRef(),d=o.useThree((e=>e.viewport.dpr)),m=C.useMemo((()=>Float32Array.from(Array.from({length:t},(()=>bn(a).map(D.MathUtils.randFloatSpread))).flat())),[t,a]),f=Sn(t,i,Math.random),p=Sn(t,n),h=Sn(t,r),v=Sn(3*t,e),g=Sn(void 0===s?3*t:t,Mn(s)?s:new D.Color(s),(()=>1));return o.useFrame((e=>u.current.uniforms.time.value=e.clock.elapsedTime)),C.createElement("points",P.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 Pn=new D.Matrix4,Cn=new D.Ray,Rn=new D.Sphere,Dn=new D.Vector3;class zn extends D.Group{constructor(){super(),this.size=0,this.color=new D.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(Rn.set(this.getWorldPosition(Dn),i),!1===e.ray.intersectsSphere(Rn))return;Pn.copy(o.matrixWorld).invert(),Cn.copy(e.ray).applyMatrix4(Pn);const s=i/((this.scale.x+this.scale.y+this.scale.z)/3),l=s*s,c=Cn.distanceSqToPoint(Dn);if(c<l){const r=new D.Vector3;Cn.closestPointToPoint(Dn,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 _n,Fn;const kn=C.createContext(null),Ln=new D.Matrix4,An=new D.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(),Ln.copy(i.current.matrixWorld).invert(),i.current.geometry.drawRange.count=Math.min(r,void 0!==t?t:r,s.length),_n=0;_n<s.length;_n++)Fn=s[_n].current,Fn.getWorldPosition(An).applyMatrix4(Ln),An.toArray(c,3*_n),i.current.geometry.attributes.position.needsUpdate=!0,Fn.matrixWorldNeedsUpdate=!0,Fn.color.toArray(u,3*_n),i.current.geometry.attributes.color.needsUpdate=!0,d.set([Fn.size],_n),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",P.default({userData:{instances:s},matrixAutoUpdate:!1,ref:_.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:D.DynamicDrawUsage}),C.createElement("bufferAttribute",{attach:"attributes-color",count:u.length/3,array:u,itemSize:3,usage:D.DynamicDrawUsage}),C.createElement("bufferAttribute",{attach:"attributes-size",count:d.length,array:d,itemSize:1,usage:D.DynamicDrawUsage})),C.createElement(kn.Provider,{value:m},e))})),Un=C.forwardRef((({children:e,...t},r)=>{C.useMemo((()=>o.extend({PositionPoint:zn})),[]);const n=C.useRef(),{subscribe:a,getParent:i}=C.useContext(kn);return C.useLayoutEffect((()=>a(n)),[]),C.createElement("positionPoint",P.default({instance:i(),instanceKey:n,ref:_.default([r,n])},t),e)})),In=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",P.default({ref:_.default([s,l])},i),C.createElement("bufferGeometry",null,C.createElement("bufferAttribute",{attach:"attributes-position",count:t.length/a,array:t,itemSize:a,usage:D.DynamicDrawUsage}),r&&C.createElement("bufferAttribute",{attach:"attributes-color",count:r.length/a,array:r,itemSize:3,usage:D.DynamicDrawUsage}),n&&C.createElement("bufferAttribute",{attach:"attributes-size",count:n.length/a,array:n,itemSize:1,usage:D.DynamicDrawUsage})),e)})),Vn=C.forwardRef(((e,t)=>e.positions instanceof Float32Array?C.createElement(In,P.default({},e,{ref:t})):C.createElement(Bn,P.default({},e,{ref:t})))),jn=new D.Matrix4,On=new D.Matrix4,Wn=[],Gn=new D.Mesh;class Nn extends D.Group{constructor(){super(),this.color=new D.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;Gn.geometry=r.geometry;const n=r.matrixWorld,o=r.userData.instances.indexOf(this.instanceKey);if(!(-1===o||o>r.count)){r.getMatrixAt(o,jn),On.multiplyMatrices(n,jn),Gn.matrixWorld=On,r.material instanceof D.Material?Gn.material.side=r.material.side:Gn.material.side=r.material[0].side,Gn.raycast(e,Wn);for(let e=0,r=Wn.length;e<r;e++){const r=Wn[e];r.instanceId=o,r.object=this,t.push(r)}Wn.length=0}}}const Hn=C.createContext(null),$n=new D.Matrix4,qn=new D.Matrix4,Xn=new D.Matrix4,Yn=new D.Vector3,Zn=new D.Quaternion,Kn=new D.Vector3,Qn=C.forwardRef((({context:e,children:t,...r},n)=>{C.useMemo((()=>o.extend({PositionMesh:Nn})),[]);const a=C.useRef(),{subscribe:i,getParent:s}=C.useContext(e||Hn);return C.useLayoutEffect((()=>i(a)),[]),C.createElement("positionMesh",P.default({instance:s(),instanceKey:a,ref:_.default([n,a])},r),t)})),Jn=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(Qn,P.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++)Xn.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(),$n.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(Yn,Zn,Kn),qn.compose(Yn,Zn,Kn).premultiply($n),qn.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",P.default({userData:{instances:u},matrixAutoUpdate:!1,ref:_.default([i,c]),args:[null,null,0],raycast:()=>null},a),C.createElement("instancedBufferAttribute",{attach:"instanceMatrix",count:m.length/16,array:m,itemSize:16,usage:D.DynamicDrawUsage}),C.createElement("instancedBufferAttribute",{attach:"instanceColor",count:f.length/3,array:f,itemSize:3,usage:D.DynamicDrawUsage}),"function"==typeof e?C.createElement(s.Provider,{value:v},e(l)):C.createElement(Hn.Provider,{value:v},e))})),eo=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(U.default,{components:(o?e:Object.values(e)).map((({geometry:e,material:t})=>C.createElement(Jn,P.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]})),{})))))})),to=C.createContext(null),ro=C.forwardRef(((e,t)=>{C.useMemo((()=>o.extend({SegmentObject:no})),[]);const{limit:r=1e3,lineWidth:n=1,children:a,...i}=e,[s,l]=C.useState([]),[c]=C.useState((()=>new d.Line2)),[u]=C.useState((()=>new d.LineMaterial)),[m]=C.useState((()=>new d.LineSegmentsGeometry)),[f]=C.useState((()=>new D.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",P.default({object:u,attach:"material",vertexColors:!0,resolution:f,linewidth:n},i)),C.createElement(to.Provider,{value:v},a))}));class no{constructor(){this.color=new D.Color("white"),this.start=new D.Vector3(0,0,0),this.end=new D.Vector3(0,0,0)}}const oo=e=>e instanceof D.Vector3?e:new D.Vector3(..."number"==typeof e?[e,e,e]:e),ao=C.forwardRef((({color:e,start:t,end:r},n)=>{const o=C.useContext(to);if(!o)throw"Segment must used inside Segments component.";const a=C.useRef(null);return C.useLayoutEffect((()=>o.subscribe(a)),[]),C.createElement("segmentObject",{ref:_.default([a,n]),color:e,start:oo(t),end:oo(r)})})),io=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",P.default({ref:_.default([a,n])},r),e)}));const so=new n.Matrix4,lo=new n.Ray,co=new n.Sphere,uo=new n.Vector3;const mo=t.createContext(null);const fo=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=Ge((t||u.width)*d.dpr,(r||u.height)*d.dpr,{samples:n}),[f]=C.useState((()=>new D.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 D.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(po,{renderPriority:a,frames:s,fbo:m},e),f,{events:{compute:p,priority:i}}),C.createElement("primitive",P.default({object:m.texture},l)))}));function po({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 ho=new D.Color;function vo(e){return"top"in e}function go({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(vo(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(ho),r.gl.setClearColor(ho,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((()=>{vo(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 xo=C.createContext(null),yo=new D.Vector3,wo=new D.Vector3,Mo=new D.Vector3(0,1,0),Eo=new D.Matrix4,bo=({direction:e,axis:t})=>{const{translation:r,translationLimits:n,annotations:a,annotationsClass:i,depthTest:s,scale:l,lineWidth:c,fixed:u,axisColors:d,hoveredColor:m,opacity:f,onDragStart:p,onDrag:h,onDragEnd:v,userData:g}=C.useContext(xo),x=o.useThree((e=>e.controls)),y=C.useRef(null),w=C.useRef(null),M=C.useRef(null),E=C.useRef(0),[b,S]=C.useState(!1),T=C.useCallback((n=>{a&&(y.current.innerText=`${r.current[t].toFixed(2)}`,y.current.style.display="block"),n.stopPropagation();const o=(new D.Matrix4).extractRotation(w.current.matrixWorld),i=n.point.clone(),s=(new D.Vector3).setFromMatrixPosition(w.current.matrixWorld),l=e.clone().applyMatrix4(o).normalize();M.current={clickPoint:i,dir:l},E.current=r.current[t],p({component:"Arrow",axis:t,origin:s,directions:[l]}),x&&(x.enabled=!1),n.target.setPointerCapture(n.pointerId)}),[a,e,x,p,r,t]),P=C.useCallback((e=>{if(e.stopPropagation(),b||S(!0),M.current){const{clickPoint:o,dir:i}=M.current,[s,l]=(null==n?void 0:n[t])||[void 0,void 0];let c=((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:(yo.copy(n).multiplyScalar(o/i).sub(t),wo.copy(n).multiplyScalar(a/i).add(r).sub(e),-yo.dot(wo)/yo.dot(yo))})(o,i,e.ray.origin,e.ray.direction);void 0!==s&&(c=Math.max(c,s-E.current)),void 0!==l&&(c=Math.min(c,l-E.current)),r.current[t]=E.current+c,a&&(y.current.innerText=`${r.current[t].toFixed(2)}`),Eo.makeTranslation(i.x*c,i.y*c,i.z*c),h(Eo)}}),[a,h,b,r,n,t]),R=C.useCallback((e=>{a&&(y.current.style.display="none"),e.stopPropagation(),M.current=null,v(),x&&(x.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[a,x,v]),z=C.useCallback((e=>{e.stopPropagation(),S(!1)}),[]),{cylinderLength:_,coneWidth:F,coneLength:k,matrixL:L}=C.useMemo((()=>{const t=u?c/l*1.6:l/20,r=u?.2:l/5,n=u?1-r:l-r,o=(new D.Quaternion).setFromUnitVectors(Mo,e.clone().normalize());return{cylinderLength:n,coneWidth:t,coneLength:r,matrixL:(new D.Matrix4).makeRotationFromQuaternion(o)}}),[e,l,c,u]),A=b?m:d[t];return C.createElement("group",{ref:w},C.createElement("group",{matrix:L,matrixAutoUpdate:!1,onPointerDown:T,onPointerMove:P,onPointerUp:R,onPointerOut:z},a&&C.createElement(X,{position:[0,-k,0]},C.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:i,ref:y})),C.createElement("mesh",{visible:!1,position:[0,(_+k)/2,0],userData:g},C.createElement("cylinderGeometry",{args:[1.4*F,1.4*F,_+k,8,1]})),C.createElement(le,{transparent:!0,raycast:()=>null,depthTest:s,points:[0,0,0,0,_,0],lineWidth:c,color:A,opacity:f,polygonOffset:!0,renderOrder:1,polygonOffsetFactor:-10}),C.createElement("mesh",{raycast:()=>null,position:[0,_+k/2,0],renderOrder:500},C.createElement("coneGeometry",{args:[F,k,24,1]}),C.createElement("meshBasicMaterial",{transparent:!0,depthTest:s,color:A,opacity:f,polygonOffset:!0,polygonOffsetFactor:-10}))))},So=new D.Ray,To=new D.Vector3,Po=new D.Matrix4,Co=({dir1:e,dir2:t,axis:r})=>{const{translation:n,translationLimits:a,annotations:i,annotationsClass:s,depthTest:l,scale:c,lineWidth:u,fixed:d,axisColors:m,hoveredColor:f,opacity:p,onDragStart:h,onDrag:v,onDragEnd:g,userData:x}=C.useContext(xo),y=o.useThree((e=>e.controls)),w=C.useRef(null),M=C.useRef(null),E=C.useRef(null),b=C.useRef(0),S=C.useRef(0),[T,P]=C.useState(!1),R=C.useCallback((e=>{i&&(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 D.Vector3).setFromMatrixPosition(M.current.matrixWorld),a=(new D.Vector3).setFromMatrixColumn(M.current.matrixWorld,0).normalize(),s=(new D.Vector3).setFromMatrixColumn(M.current.matrixWorld,1).normalize(),l=(new D.Vector3).setFromMatrixColumn(M.current.matrixWorld,2).normalize(),c=(new D.Plane).setFromNormalAndCoplanarPoint(l,o);E.current={clickPoint:t,e1:a,e2:s,plane:c},b.current=n.current[(r+1)%3],S.current=n.current[(r+2)%3],h({component:"Slider",axis:r,origin:o,directions:[a,s,l]}),y&&(y.enabled=!1),e.target.setPointerCapture(e.pointerId)}),[i,y,h,r]),z=C.useCallback((e=>{if(e.stopPropagation(),T||P(!0),E.current){const{clickPoint:t,e1:o,e2:s,plane:l}=E.current,[c,u]=(null==a?void 0:a[(r+1)%3])||[void 0,void 0],[d,m]=(null==a?void 0:a[(r+2)%3])||[void 0,void 0];So.copy(e.ray),So.intersectPlane(l,To),So.direction.negate(),So.intersectPlane(l,To),To.sub(t);let[f,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,s,To);void 0!==c&&(f=Math.max(f,c-b.current)),void 0!==u&&(f=Math.min(f,u-b.current)),void 0!==d&&(p=Math.max(p,d-S.current)),void 0!==m&&(p=Math.min(p,m-S.current)),n.current[(r+1)%3]=b.current+f,n.current[(r+2)%3]=S.current+p,i&&(w.current.innerText=`${n.current[(r+1)%3].toFixed(2)}, ${n.current[(r+2)%3].toFixed(2)}`),Po.makeTranslation(f*o.x+p*s.x,f*o.y+p*s.y,f*o.z+p*s.z),v(Po)}}),[i,v,T,n,a,r]),_=C.useCallback((e=>{i&&(w.current.style.display="none"),e.stopPropagation(),E.current=null,g(),y&&(y.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[i,y,g]),F=C.useCallback((e=>{e.stopPropagation(),P(!1)}),[]),k=C.useMemo((()=>{const r=e.clone().normalize(),n=t.clone().normalize();return(new D.Matrix4).makeBasis(r,n,r.clone().cross(n))}),[e,t]),L=d?1/7:c/7,A=d?.225:.225*c,B=T?f:m[r],U=C.useMemo((()=>[new D.Vector3(0,0,0),new D.Vector3(0,A,0),new D.Vector3(A,A,0),new D.Vector3(A,0,0),new D.Vector3(0,0,0)]),[A]);return C.createElement("group",{ref:M,matrix:k,matrixAutoUpdate:!1},i&&C.createElement(X,{position:[0,0,0]},C.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:s,ref:w})),C.createElement("group",{position:[1.7*L,1.7*L,0]},C.createElement("mesh",{visible:!0,onPointerDown:R,onPointerMove:z,onPointerUp:_,onPointerOut:F,scale:A,userData:x},C.createElement("planeGeometry",null),C.createElement("meshBasicMaterial",{transparent:!0,depthTest:l,color:B,polygonOffset:!0,polygonOffsetFactor:-10,side:D.DoubleSide})),C.createElement(le,{position:[-A/2,-A/2,0],transparent:!0,depthTest:l,points:U,lineWidth:u,color:B,opacity:p,polygonOffset:!0,polygonOffsetFactor:-10,userData:x})))},Ro=new D.Vector3,Do=new D.Vector3,zo=e=>180*e/Math.PI,_o=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)},Fo=new D.Matrix4,ko=new D.Vector3,Lo=new D.Ray,Ao=new D.Vector3,Bo=({dir1:e,dir2:t,axis:r})=>{const{rotationLimits:n,annotations:a,annotationsClass:i,depthTest:s,scale:l,lineWidth:c,fixed:u,axisColors:d,hoveredColor:m,opacity:f,onDragStart:p,onDrag:h,onDragEnd:v,userData:g}=C.useContext(xo),x=o.useThree((e=>e.controls)),y=C.useRef(null),w=C.useRef(null),M=C.useRef(0),E=C.useRef(0),b=C.useRef(null),[S,T]=C.useState(!1),P=C.useCallback((e=>{a&&(y.current.innerText=`${zo(E.current).toFixed(0)}º`,y.current.style.display="block"),e.stopPropagation();const t=e.point.clone(),n=(new D.Vector3).setFromMatrixPosition(w.current.matrixWorld),o=(new D.Vector3).setFromMatrixColumn(w.current.matrixWorld,0).normalize(),i=(new D.Vector3).setFromMatrixColumn(w.current.matrixWorld,1).normalize(),s=(new D.Vector3).setFromMatrixColumn(w.current.matrixWorld,2).normalize(),l=(new D.Plane).setFromNormalAndCoplanarPoint(s,n);b.current={clickPoint:t,origin:n,e1:o,e2:i,normal:s,plane:l},p({component:"Rotator",axis:r,origin:n,directions:[o,i,s]}),x&&(x.enabled=!1),e.target.setPointerCapture(e.pointerId)}),[a,x,p,r]),R=C.useCallback((e=>{if(e.stopPropagation(),S||T(!0),b.current){const{clickPoint:t,origin:o,e1:i,e2:s,normal:l,plane:c}=b.current,[u,d]=(null==n?void 0:n[r])||[void 0,void 0];Lo.copy(e.ray),Lo.intersectPlane(c,Ao),Lo.direction.negate(),Lo.intersectPlane(c,Ao);let m=((e,t,r,n,o)=>{Ro.copy(e).sub(r),Do.copy(t).sub(r);const a=n.dot(n),i=o.dot(o),s=Ro.dot(n)/a,l=Ro.dot(o)/i,c=Do.dot(n)/a,u=Do.dot(o)/i,d=Math.atan2(l,s);return Math.atan2(u,c)-d})(t,Ao,o,i,s),f=zo(m);e.shiftKey&&(f=10*Math.round(f/10),m=(e=>e*Math.PI/180)(f)),void 0!==u&&void 0!==d&&d-u<2*Math.PI?(m=_o(m),m=m>Math.PI?m-2*Math.PI:m,m=I.default(m,u-M.current,d-M.current),E.current=M.current+m):(E.current=_o(M.current+m),E.current=E.current>Math.PI?E.current-2*Math.PI:E.current),a&&(f=zo(E.current),y.current.innerText=`${f.toFixed(0)}º`),Fo.makeRotationAxis(l,m),ko.copy(o).applyMatrix4(Fo).sub(o).negate(),Fo.setPosition(ko),h(Fo)}}),[a,h,S,n,r]),z=C.useCallback((e=>{a&&(y.current.style.display="none"),e.stopPropagation(),M.current=E.current,b.current=null,v(),x&&(x.enabled=!0),e.target.releasePointerCapture(e.pointerId)}),[a,x,v]),_=C.useCallback((e=>{e.stopPropagation(),T(!1)}),[]),F=C.useMemo((()=>{const r=e.clone().normalize(),n=t.clone().normalize();return(new D.Matrix4).makeBasis(r,n,r.clone().cross(n))}),[e,t]),k=u?.65:.65*l,L=C.useMemo((()=>{const e=[];for(let t=0;t<=32;t++){const r=t*(Math.PI/2)/32;e.push(new D.Vector3(Math.cos(r)*k,Math.sin(r)*k,0))}return e}),[k]);return C.createElement("group",{ref:w,onPointerDown:P,onPointerMove:R,onPointerUp:z,onPointerOut:_,matrix:F,matrixAutoUpdate:!1},a&&C.createElement(X,{position:[k,k,0]},C.createElement("div",{style:{display:"none",background:"#151520",color:"white",padding:"6px 8px",borderRadius:7,whiteSpace:"nowrap"},className:i,ref:y})),C.createElement(le,{points:L,lineWidth:4*c,visible:!1,userData:g}),C.createElement(le,{transparent:!0,raycast:()=>null,depthTest:s,points:L,lineWidth:c,color:S?m:d[r],opacity:f,polygonOffset:!0,polygonOffsetFactor:-10}))},Uo=new D.Vector3,Io=new D.Vector3,Vo=new D.Vector3,jo=(e,t,r,n=1)=>{const o=Uo.set(e.x/r.width*2-1,-e.y/r.height*2+1,n);return o.unproject(t),o},Oo=(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})(Vo.copy(e),r,n);let a=0;for(let i=0;i<2;++i){const s=Io.copy(o).setComponent(i,o.getComponent(i)+t),l=jo(s,r,n,s.z);a=Math.max(a,e.distanceTo(l))}return a},Wo=new D.Matrix4,Go=new D.Matrix4,No=new D.Matrix4,Ho=new D.Matrix4,$o=new D.Matrix4,qo=new D.Matrix4,Xo=new D.Matrix4,Yo=new D.Matrix4,Zo=new D.Box3,Ko=new D.Box3,Qo=new D.Vector3,Jo=new D.Vector3,ea=new D.Vector3,ta=new D.Vector3,ra=new D.Vector3(1,0,0),na=new D.Vector3(0,1,0),oa=new D.Vector3(0,0,1),aa=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",annotations:M=!1,annotationsClass:E,opacity:b=1,visible:S=!0,userData:T,children:R,...z},_)=>{const F=o.useThree((e=>e.invalidate)),k=C.useRef(null),L=C.useRef(null),A=C.useRef(null),B=C.useRef(null),U=C.useRef([0,0,0]);C.useLayoutEffect((()=>{i&&(B.current.updateWorldMatrix(!0,!0),Ho.copy(B.current.matrixWorld).invert(),Zo.makeEmpty(),B.current.traverse((e=>{e.geometry&&(e.geometry.boundingBox||e.geometry.computeBoundingBox(),qo.copy(e.matrixWorld).premultiply(Ho),Ko.copy(e.geometry.boundingBox),Ko.applyMatrix4(qo),Zo.union(Ko))})),Qo.copy(Zo.max).add(Zo.min).multiplyScalar(.5),Jo.copy(Zo.max).sub(Zo.min).multiplyScalar(.5),ea.copy(Jo).multiply(new D.Vector3(...i)).add(Qo),ta.set(...d).add(ea),A.current.position.copy(ta),F())}));const I=C.useMemo((()=>({onDragStart:e=>{Wo.copy(L.current.matrix),Go.copy(L.current.matrixWorld),t&&t(e),F()},onDrag:e=>{No.copy(k.current.matrixWorld),Ho.copy(No).invert(),$o.copy(Go).premultiply(e),qo.copy($o).premultiply(Ho),Xo.copy(Wo).invert(),Yo.copy(qo).multiply(Xo),a&&L.current.matrix.copy(qo),r&&r(qo,Yo,$o,e),F()},onDragEnd:()=>{n&&n(),F()},translation:U,translationLimits:v,rotationLimits:g,axisColors:y,hoveredColor:w,opacity:b,scale:f,lineWidth:p,fixed:h,depthTest:x,userData:T,annotations:M,annotationsClass:E})),[t,r,n,U,v,g,x,f,p,h,...y,w,b,T,a,M,E]),V=new D.Vector3;return o.useFrame((e=>{if(h){const o=Oo(A.current.getWorldPosition(V),f,e.camera,e.size);var t,r,n;if(A.current)(null==(t=A.current)?void 0:t.scale.x)===o&&(null==(r=A.current)?void 0:r.scale.y)===o&&(null==(n=A.current)?void 0:n.scale.z)===o||(A.current.scale.setScalar(o),e.invalidate())}})),C.useImperativeHandle(_,(()=>L.current),[]),C.useLayoutEffect((()=>{e&&e instanceof D.Matrix4&&(L.current.matrix=e)}),[e]),C.createElement(xo.Provider,{value:I},C.createElement("group",{ref:k},C.createElement("group",P.default({ref:L,matrix:e,matrixAutoUpdate:!1},z),C.createElement("group",{visible:S,ref:A,position:d,rotation:m},!s&&u[0]&&C.createElement(bo,{axis:0,direction:ra}),!s&&u[1]&&C.createElement(bo,{axis:1,direction:na}),!s&&u[2]&&C.createElement(bo,{axis:2,direction:oa}),!l&&u[0]&&u[1]&&C.createElement(Co,{axis:2,dir1:ra,dir2:na}),!l&&u[0]&&u[2]&&C.createElement(Co,{axis:1,dir1:oa,dir2:ra}),!l&&u[2]&&u[1]&&C.createElement(Co,{axis:0,dir1:na,dir2:oa}),!c&&u[0]&&u[1]&&C.createElement(Bo,{axis:2,dir1:ra,dir2:na}),!c&&u[0]&&u[2]&&C.createElement(Bo,{axis:1,dir1:oa,dir2:ra}),!c&&u[2]&&u[1]&&C.createElement(Bo,{axis:0,dir1:na,dir2:oa})),C.createElement("group",{ref:B},R))))}));exports.AccumulativeShadows=qr,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=Ke,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:u,camera:m}=o.useThree(),f=C.useMemo((()=>{const e=new d.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(u,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&&(It.setFromObject(n.current),It.getSize(Vt),r.current.position.set(n.current.position.x+Vt.x*e[0]/2,n.current.position.y+Vt.y*e[1]/2,n.current.position.z+Vt.z*e[2]/2))})),C.createElement("group",P.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,Qr(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=ie,exports.Bounds=Fr,exports.Box=sr,exports.Bvh=Ut,exports.CameraControls=tt,exports.CameraShake=Lr,exports.Capsule=Sr,exports.CatmullRomLine=me,exports.Caustics=an,exports.Center=Dr,exports.Circle=lr,exports.Clone=Fe,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=we(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(ie,{key:i,position:[t,r,-i*n]},C.createElement(mr,{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",P.default({ref:a,object:o,attach:`attributes-${t}`},r))},exports.Cone=cr,exports.ContactShadows=Nr,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=de,exports.CurveModifier=Wt,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=ur,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 D.Mesh))throw new Error('Decal must have a Mesh as parent or specify its "mesh" prop');const s={position:new D.Vector3,rotation:new D.Euler,scale:new D.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 D.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 d.DecalGeometry(e,s.position,s.rotation,s.scale),c.current&&o.applyProps(c.current,s),e.matrixWorld=t,()=>{r.geometry.dispose()}}}),[t,...Ue(n),...Ue(i),...Ue(a)]),C.createElement("mesh",{ref:l},r||C.createElement("meshStandardMaterial",P.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=io,exports.DeviceOrientationControls=$e,exports.Dodecahedron=Mr,exports.Edges=Pe,exports.Effects=ge,exports.Environment=Gr,exports.EnvironmentCube=jr,exports.EnvironmentMap=Ir,exports.EnvironmentPortal=Or,exports.Extrude=Er,exports.FirstPersonControls=et,exports.Float=Ar,exports.FlyControls=qe,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(dt),ct.copy(c.quaternion),mt.copy(e).multiplyScalar(h.current).add(dt),st.lookAt(mt),ut.copy(st.quaternion),d()}),[u,c,i,d]);o.useFrame(((e,t)=>{if(f.current&&m.current){var r;if(p.current)if(ct.angleTo(ut)<.01)p.current=!1,"minPolarAngle"in u&&c.up.copy(g.current);else{const e=t*it;ct.rotateTowards(ut,e),c.position.set(0,0,1).applyQuaternion(ct).multiplyScalar(h.current).add(v.current),c.up.set(0,1,0).applyQuaternion(ct).normalize(),c.quaternion.copy(ct),a?a():u&&u.update(),d()}lt.copy(c.matrix).invert(),null==(r=m.current)||r.quaternion.setFromRotationMatrix(lt)}}));const y=C.useMemo((()=>({tweenCamera:x})),[x]),[w,M]=t,E=e.endsWith("-center")?0:e.endsWith("-left")?-l.width/2+w:l.width/2-w,b=e.startsWith("center-")?0:e.startsWith("top-")?l.height/2-M:-l.height/2+M;return C.createElement(nt,{renderPriority:r},C.createElement(ot.Provider,{value:y},C.createElement(Ne,{makeDefault:!0,ref:f,position:[0,0,200]}),C.createElement("group",{ref:m,position:[E,b,0]},s)))},exports.GizmoViewcube=e=>C.createElement("group",{scale:[60,60,60]},C.createElement(St,e),Mt.map(((t,r)=>C.createElement(Tt,P.default({key:r,position:t,dimensions:Et[r]},e)))),yt.map(((t,r)=>C.createElement(Tt,P.default({key:r,position:t,dimensions:wt},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}=at(),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",P.default({scale:40},u),C.createElement(Pt,{color:d,rotation:[0,0,0],scale:i}),C.createElement(Pt,{color:m,rotation:[0,0,Math.PI/2],scale:i}),C.createElement(Pt,{color:f,rotation:[0,-Math.PI/2,0],scale:i}),!t&&C.createElement(C.Fragment,null,C.createElement(Ct,P.default({arcStyle:d,position:[1,0,0],label:s[0]},h)),C.createElement(Ct,P.default({arcStyle:m,position:[0,1,0],label:s[1]},h)),C.createElement(Ct,P.default({arcStyle:f,position:[0,0,1],label:s[2]},h)),!e&&C.createElement(C.Fragment,null,C.createElement(Ct,P.default({arcStyle:d,position:[-1,0,0]},h)),C.createElement(Ct,P.default({arcStyle:m,position:[0,-1,0]},h)),C.createElement(Ct,P.default({arcStyle:f,position:[0,0,-1]},h)))),C.createElement("ambientLight",{intensity:.5}),C.createElement("pointLight",{position:[10,10,10],intensity:.5}))},exports.Gltf=We,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 D.Texture(n);return s.needsUpdate=!0,s}),[e]);return C.useEffect((()=>()=>{i.dispose()}),[i]),C.createElement("primitive",P.default({object:i,attach:"map",encoding:a.outputEncoding},n))},exports.Grid=Dt,exports.Html=X,exports.Hud=nt,exports.Icosahedron=yr,exports.Image=Te,exports.Instance=Qn,exports.Instances=Jn,exports.IsObject=ye,exports.KeyboardControls=function({map:e,children:t,onChange:r,domElement:n}){const o=e.map((e=>e.name+e.keys)).join("-"),a=C.useMemo((()=>z.default(u.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(oe.Provider,{value:i,children:t})},exports.Lathe=br,exports.Lightformer=pn,exports.Line=le,exports.Loader=function({containerStyles:e,innerStyles:t,barStyles:r,dataStyles:n,dataInterpolation:o=K,initialState:a=(e=>e)}){const{active:i,progress:s}=Z(),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:{...Q.container,opacity:i?1:0,...e}},C.createElement("div",null,C.createElement("div",{style:{...Q.inner,...t}},C.createElement("div",{style:{...Q.bar,transform:`scaleX(${s/100})`,...r}}),C.createElement("span",{ref:u,style:{...Q.data,...n}})))):null},exports.MapControls=Xe,exports.MarchingCube=Ae,exports.MarchingCubes=Le,exports.MarchingPlane=Be,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:D.AlwaysStencilFunc,stencilFail:D.ReplaceStencilOp,stencilZFail:D.ReplaceStencilOp,stencilZPass:D.ReplaceStencilOp})),[e,r,n]);return C.createElement("mesh",P.default({renderOrder:-e},o),C.createElement("meshBasicMaterial",a),"function"==typeof t?t(a):t)},exports.Merged=eo,exports.MeshDistortMaterial=Nt,exports.MeshReflectorMaterial=Zt,exports.MeshRefractionMaterial=function({aberrationStrength:e=0,fastChroma:r=!0,envMap:n,...a}){o.extend({MeshRefractionMaterial:Kt});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 M.MeshBVH(n.toNonIndexed(),{lazyGeneration:!1,strategy:M.SAH}))}),[]),C.createElement("meshRefractionMaterial",P.default({key:JSON.stringify(l),defines:l,ref:i,resolution:[s.width,s.height],aberrationStrength:e,envMap:n},a))},exports.MeshTransmissionMaterial=er,exports.MeshWobbleMaterial=$t,exports.Octahedron=wr,exports.OrbitControls=Ye,exports.OrthographicCamera=Ne,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(mo.Provider,{value:h},f)},exports.PerspectiveCamera=He,exports.PivotControls=aa,exports.Plane=mr,exports.Point=Un,exports.PointMaterial=rr,exports.PointMaterialImpl=tr,exports.PointerLockControls=Je,exports.Points=Vn,exports.PointsBuffer=In,exports.Polyhedron=xr,exports.PositionPoint=zn,exports.PositionalAudio=fe,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:s=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,M]=l.useSpring((()=>({scale:1,rotation:y,config:p})));C.useEffect((()=>{M.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 E=c.useGesture({onHover:({last:t})=>{a&&!r&&e&&(v.domElement.style.cursor=t?"auto":"grab")},onDrag:({down:r,delta:[o,i],memo:[l,c]=w.rotation.animation.to||y})=>{if(!e)return[i,o];a&&(v.domElement.style.cursor=r?"grabbing":"grab"),o=n.MathUtils.clamp(c+o/h.width*Math.PI*s,...x),i=n.MathUtils.clamp(l+i/h.height*Math.PI*s,...g);const u=t&&!r&&"boolean"!=typeof t?t:p;return M.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(l.a.group,P.default({},null==E?void 0:E(),w),i)},exports.QuadraticBezierLine=ue,exports.RandomizedLight=Xr,exports.Reflector=sn,exports.RenderTexture=fo,exports.Ring=gr,exports.RoundedBox=Pr,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]),_e(c,a,r,t,l),C.createElement("group",P.default({ref:s},i),e)},exports.ScreenQuad=Rr,exports.ScreenSpace=se,exports.Scroll=ne,exports.ScrollControls=function({eps:e=1e-5,enabled:t=!0,infinite:r,horizontal:n,pages:a=1,distance:i=1,damping:l=.25,maxSpeed:c=1/0,style:u={},children:d}){const{get:m,setEvents:f,gl:p,size:h,invalidate:v,events:g}=o.useThree(),[x]=C.useState((()=>document.createElement("div"))),[y]=C.useState((()=>document.createElement("div"))),[w]=C.useState((()=>document.createElement("div"))),M=p.domElement.parentNode,E=C.useRef(0),b=C.useMemo((()=>{const t={el:x,eps:e,fill:y,fixed:w,horizontal:n,damping:l,offset:0,delta:0,scroll:E,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,l,n,a]);C.useEffect((()=>{x.style.position="absolute",x.style.width="100%",x.style.height="100%",x.style[n?"overflowX":"overflowY"]="auto",x.style[n?"overflowY":"overflowX"]="hidden",x.style.top="0px",x.style.left="0px";for(const e in u)x.style[e]=u[e];w.style.position="sticky",w.style.top="0px",w.style.left="0px",w.style.width="100%",w.style.height="100%",w.style.overflow="hidden",x.appendChild(w),y.style.height=n?"100%":a*i*100+"%",y.style.width=n?a*i*100+"%":"100%",y.style.pointerEvents="none",x.appendChild(y),M.appendChild(x),x[n?"scrollLeft":"scrollTop"]=1;const e=g.connected||p.domElement;requestAnimationFrame((()=>null==g.connect?void 0:g.connect(x)));const t=m().events.compute;return f({compute(e,t){const{left:r,top:n}=M.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)}}),()=>{M.removeChild(x),f({compute:t}),null==g.connect||g.connect(e)}}),[a,i,n,x,y,w,M]),C.useEffect((()=>{if(g.connected===x){const e=h[n?"width":"height"],o=x[n?"scrollWidth":"scrollHeight"],a=o-e;let i=0,s=!0,l=!0;const c=()=>{if(t&&!l&&(v(),i=x[n?"scrollLeft":"scrollTop"],E.current=i/a,r)){if(!s)if(i>=a){const e=1-b.offset;x[n?"scrollLeft":"scrollTop"]=1,E.current=b.offset=-e,s=!0}else if(i<=0){const e=1+b.offset;x[n?"scrollLeft":"scrollTop"]=o,E.current=b.offset=e,s=!0}s&&setTimeout((()=>s=!1),40)}};x.addEventListener("scroll",c,{passive:!0}),requestAnimationFrame((()=>l=!1));const u=e=>x.scrollLeft+=e.deltaY/2;return n&&x.addEventListener("wheel",u,{passive:!0}),()=>{x.removeEventListener("scroll",c),n&&x.removeEventListener("wheel",u)}}}),[x,g,h,r,b,v,n,t]);let S=0;return o.useFrame(((t,r)=>{S=b.offset,s.easing.damp(b,"offset",E.current,l,r,c,void 0,e),s.easing.damp(b,"delta",Math.abs(S-b.offset),l,r,c,void 0,e),b.delta>e&&v()})),C.createElement(J.Provider,{value:b},d)},exports.Segment=ao,exports.SegmentObject=no,exports.Segments=ro,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:u,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 M=C.useCallback((e=>{e.stopPropagation(),w({object:s([e.object])[0],shift:t&&e.shiftKey})}),[]),E=C.useCallback((e=>!g&&w({})),[g]),b=C.useRef(null);return C.useEffect((()=>{if(!e||!t)return;const r=new d.SelectionBox(u,b.current),n=document.createElement("div");n.style.pointerEvents="none",n.style.border=a,n.style.backgroundColor=i,n.style.position="fixed";const o=new D.Vector2,l=new D.Vector2,m=new D.Vector2,g=v().events.enabled,x=null==p?void 0:p.enabled;let y=!1;function M(e,t){const{offsetX:r,offsetY:n}=e,{width:o,height:a}=h;t.set(r/o*2-1,-n/a*2+1)}function E(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),M(e,r.startPoint))}let S=[];function T(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),M(e,r.endPoint);const t=r.select().sort((e=>e.uuid)).filter((e=>e.isMesh));F.default(t,S)||(S=t,w({object:s(t)}))}}function P(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",E,{passive:!0}),document.addEventListener("pointermove",T,{passive:!0,capture:!0}),document.addEventListener("pointerup",P,{passive:!0}),()=>{document.removeEventListener("pointerdown",E),document.removeEventListener("pointermove",T),document.removeEventListener("pointerup",P)}}),[h.width,h.height,m,u,p,f]),C.createElement("group",P.default({ref:b,onClick:M,onPointerOver:()=>x(!0),onPointerOut:()=>x(!1),onPointerMissed:E},l),C.createElement(ae.Provider,{value:y},r))},exports.Shadow=Jr,exports.Sky=vn,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=D.ShaderChunk.shadowmap_pars_fragment;let c=D.ShaderChunk.shadowmap_pars_fragment;return c=c.replace("#ifdef USE_SHADOWMAP","#ifdef USE_SHADOWMAP\n"+nr({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 )"),D.ShaderChunk.shadowmap_pars_fragment=c,ar(i,s,l),()=>{D.ShaderChunk.shadowmap_pars_fragment=o,ar(i,s,l)}}),[e,t,r,n,a])},exports.Sparkles=Tn,exports.Sphere=dr,exports.SpotLight=fn,exports.SpotLightShadow=function(e){return e.shader?C.createElement(dn,e):C.createElement(mn,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?Zr[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,M=null!==(c=null==o?void 0:o.normalBias)&&void 0!==c?c:0,E=null!==(u=null==o?void 0:o.size)&&void 0!==u?u:1024,b=null!==(d=null==o?void 0:o.offset)&&void 0!==d?d:0,S="contact"===o||"contact"===(null==o?void 0:o.type),T="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":M,"shadow-mapSize":E}),C.createElement("pointLight",{position:[v.fill[0]*g,v.fill[1]*g,v.fill[2]*g],intensity:n}),C.createElement(Fr,P.default({fit:!!r,clip:!!r,margin:Number(r),observe:!0},s),C.createElement(Kr,{radius:g,adjustCamera:r}),C.createElement(Dr,P.default({},t,{position:[0,b/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-b/2,0]},S&&C.createElement(Nr,P.default({scale:4*g,far:g,blur:2},R)),T&&C.createElement(qr,P.default({temporal:!0,frames:100,alphaTest:.9,toneMapped:!0,scale:4*g},R),C.createElement(Xr,{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:E}))),a&&C.createElement(Gr,D))},exports.Stars=yn,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),Lt(r,t),()=>Lt(r,null)}),t),n}((()=>new B.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=Ie,exports.Tetrahedron=vr,exports.Text=pe,exports.Text3D=ve,exports.Torus=pr,exports.TorusKnot=hr,exports.TrackballControls=Ze,exports.Trail=ze,exports.TransformControls=Qe,exports.Tube=fr,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 D.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(go,{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=Hr,exports.calcPosFromAngles=hn,exports.calculateScaleFactor=Oo,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(),co.copy(r.boundingSphere),co.applyMatrix4(o),!1!==e.ray.intersectsSphere(co)&&(so.copy(o).invert(),lo.copy(e.ray).applyMatrix4(so),null!==r.boundingBox&&null===lo.intersectBox(r.boundingBox,uo)||t.push({distance:uo.distanceTo(e.ray.origin),point:uo.clone(),object:this})))},exports.shaderMaterial=xe,exports.softShadows=e=>{if(!or){console.warn("drei/softShadows() is deprecated, use <SoftShadows> instead"),or=!0;let t=D.ShaderChunk.shadowmap_pars_fragment;t=t.replace("#ifdef USE_SHADOWMAP","#ifdef USE_SHADOWMAP\n"+nr({...e})),t=t.replace("#if defined( SHADOWMAP_TYPE_PCF )","\nreturn PCSS(shadowMap, shadowCoord);\n#if defined( SHADOWMAP_TYPE_PCF )"),D.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){t={splitStrategy:"SAH",verbose:!1,setBoundingBox:!0,maxDepth:40,maxLeafTris:10,...t},C.useEffect((()=>{if(e.current){e.current.raycast=M.acceleratedRaycast;const r=e.current.geometry;return r.computeBoundsTree=M.computeBoundsTree,r.disposeBoundsTree=M.disposeBoundsTree,r.computeBoundsTree(t),()=>{r.boundsTree&&r.disposeBoundsTree()}}}),[e,JSON.stringify(t)])},exports.useBounds=kr,exports.useBoxProjectedEnv=function(e=new D.Vector3,t=new D.Vector3){const[r]=C.useState((()=>({position:new D.Vector3,size:new D.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>",D.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=zt,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=Ge(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=>p.suspend((()=>w.getGPUTier(e)),["useDetectGPU"]),exports.useEnvironment=Vr,exports.useFBO=Ge,exports.useFBX=_t,exports.useGLTF=Oe,exports.useGizmoContext=at,exports.useHelper=At,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=kt,exports.useKeyboardControls=function(e){const[t,r,n]=C.useContext(oe);return e?n(e):[t,r]},exports.useMask=function(e,t=!1){return{stencilWrite:!0,stencilRef:e,stencilFunc:t?D.NotEqualStencilFunc:D.EqualStencilFunc,stencilFail:D.KeepStencilOp,stencilZFail:D.KeepStencilOp,stencilZPass:D.KeepStencilOp}},exports.useMatcapTexture=function(e=0,t=1024,r){const n=p.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[we(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=p.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=we(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(mo),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=Z,exports.useScroll=ee,exports.useSelect=function(){return C.useContext(ae)},exports.useSurfaceSampler=_e,exports.useTexture=we,exports.useTrail=De,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 Ot(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=p.suspend((()=>new Promise(((t,r)=>{const o=Object.assign(document.createElement("video"),{src:e,crossOrigin:i,loop:l,muted:s,...c}),a=new D.VideoTexture(o);a.encoding=u.outputEncoding,o.addEventListener(n,(()=>t(a)))}))),[e]);return t.useEffect((()=>{a&&d.image.play()}),[d,a]),d};
|