three-cad-viewer 4.3.6 → 4.3.7
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.
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Copyright 2010-2026 Three.js Authors
|
|
10
10
|
* SPDX-License-Identifier: MIT
|
|
11
11
|
*/
|
|
12
|
-
function md(){let t=null,e=!1,i=null,n=null;function s(e,r){i(e,r),n=t.requestAnimationFrame(s)}return{start:function(){!0!==e&&null!==i&&(n=t.requestAnimationFrame(s),e=!0)},stop:function(){t.cancelAnimationFrame(n),e=!1},setAnimationLoop:function(t){i=t},setContext:function(e){t=e}}}function fd(t){const e=new WeakMap;return{get:function(t){return t.isInterleavedBufferAttribute&&(t=t.data),e.get(t)},remove:function(i){i.isInterleavedBufferAttribute&&(i=i.data);const n=e.get(i);n&&(t.deleteBuffer(n.buffer),e.delete(i))},update:function(i,n){if(i.isInterleavedBufferAttribute&&(i=i.data),i.isGLBufferAttribute){const t=e.get(i);return void((!t||t.version<i.version)&&e.set(i,{buffer:i.buffer,type:i.type,bytesPerElement:i.elementSize,version:i.version}))}const s=e.get(i);if(void 0===s)e.set(i,function(e,i){const n=e.array,s=e.usage,r=n.byteLength,a=t.createBuffer();let o;if(t.bindBuffer(i,a),t.bufferData(i,n,s),e.onUploadCallback(),n instanceof Float32Array)o=t.FLOAT;else if("undefined"!=typeof Float16Array&&n instanceof Float16Array)o=t.HALF_FLOAT;else if(n instanceof Uint16Array)o=e.isFloat16BufferAttribute?t.HALF_FLOAT:t.UNSIGNED_SHORT;else if(n instanceof Int16Array)o=t.SHORT;else if(n instanceof Uint32Array)o=t.UNSIGNED_INT;else if(n instanceof Int32Array)o=t.INT;else if(n instanceof Int8Array)o=t.BYTE;else if(n instanceof Uint8Array)o=t.UNSIGNED_BYTE;else{if(!(n instanceof Uint8ClampedArray))throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+n);o=t.UNSIGNED_BYTE}return{buffer:a,type:o,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version,size:r}}(i,n));else if(s.version<i.version){if(s.size!==i.array.byteLength)throw new Error("THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.");!function(e,i,n){const s=i.array,r=i.updateRanges;if(t.bindBuffer(n,e),0===r.length)t.bufferSubData(n,0,s);else{r.sort((t,e)=>t.start-e.start);let e=0;for(let t=1;t<r.length;t++){const i=r[e],n=r[t];n.start<=i.start+i.count+1?i.count=Math.max(i.count,n.start+n.count-i.start):(++e,r[e]=n)}r.length=e+1;for(let e=0,i=r.length;e<i;e++){const i=r[e];t.bufferSubData(n,i.start*s.BYTES_PER_ELEMENT,s,i.start,i.count)}i.clearUpdateRanges()}i.onUploadCallback()}(s.buffer,i,n),s.version=i.version}}}}"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:e}})),"undefined"!=typeof window&&(window.__THREE__?ii("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=e);const gd={alphahash_fragment:"#ifdef USE_ALPHAHASH\n\tif ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;\n#endif",alphahash_pars_fragment:"#ifdef USE_ALPHAHASH\n\tconst float ALPHA_HASH_SCALE = 0.05;\n\tfloat hash2D( vec2 value ) {\n\t\treturn fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );\n\t}\n\tfloat hash3D( vec3 value ) {\n\t\treturn hash2D( vec2( hash2D( value.xy ), value.z ) );\n\t}\n\tfloat getAlphaHashThreshold( vec3 position ) {\n\t\tfloat maxDeriv = max(\n\t\t\tlength( dFdx( position.xyz ) ),\n\t\t\tlength( dFdy( position.xyz ) )\n\t\t);\n\t\tfloat pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );\n\t\tvec2 pixScales = vec2(\n\t\t\texp2( floor( log2( pixScale ) ) ),\n\t\t\texp2( ceil( log2( pixScale ) ) )\n\t\t);\n\t\tvec2 alpha = vec2(\n\t\t\thash3D( floor( pixScales.x * position.xyz ) ),\n\t\t\thash3D( floor( pixScales.y * position.xyz ) )\n\t\t);\n\t\tfloat lerpFactor = fract( log2( pixScale ) );\n\t\tfloat x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;\n\t\tfloat a = min( lerpFactor, 1.0 - lerpFactor );\n\t\tvec3 cases = vec3(\n\t\t\tx * x / ( 2.0 * a * ( 1.0 - a ) ),\n\t\t\t( x - 0.5 * a ) / ( 1.0 - a ),\n\t\t\t1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )\n\t\t);\n\t\tfloat threshold = ( x < ( 1.0 - a ) )\n\t\t\t? ( ( x < a ) ? cases.x : cases.y )\n\t\t\t: cases.z;\n\t\treturn clamp( threshold , 1.0e-6, 1.0 );\n\t}\n#endif",alphamap_fragment:"#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;\n#endif",alphamap_pars_fragment:"#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",alphatest_fragment:"#ifdef USE_ALPHATEST\n\t#ifdef ALPHA_TO_COVERAGE\n\tdiffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );\n\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\tif ( diffuseColor.a < alphaTest ) discard;\n\t#endif\n#endif",alphatest_pars_fragment:"#ifdef USE_ALPHATEST\n\tuniform float alphaTest;\n#endif",aomap_fragment:"#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_CLEARCOAT ) \n\t\tclearcoatSpecularIndirect *= ambientOcclusion;\n\t#endif\n\t#if defined( USE_SHEEN ) \n\t\tsheenSpecularIndirect *= ambientOcclusion;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\t#endif\n#endif",aomap_pars_fragment:"#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif",batching_pars_vertex:"#ifdef USE_BATCHING\n\t#if ! defined( GL_ANGLE_multi_draw )\n\t#define gl_DrawID _gl_DrawID\n\tuniform int _gl_DrawID;\n\t#endif\n\tuniform highp sampler2D batchingTexture;\n\tuniform highp usampler2D batchingIdTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n\tfloat getIndirectIndex( const in int i ) {\n\t\tint size = textureSize( batchingIdTexture, 0 ).x;\n\t\tint x = i % size;\n\t\tint y = i / size;\n\t\treturn float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );\n\t}\n#endif\n#ifdef USE_BATCHING_COLOR\n\tuniform sampler2D batchingColorTexture;\n\tvec4 getBatchingColor( const in float i ) {\n\t\tint size = textureSize( batchingColorTexture, 0 ).x;\n\t\tint j = int( i );\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\treturn texelFetch( batchingColorTexture, ivec2( x, y ), 0 );\n\t}\n#endif",batching_vertex:"#ifdef USE_BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );\n#endif",begin_vertex:"vec3 transformed = vec3( position );\n#ifdef USE_ALPHAHASH\n\tvPosition = vec3( position );\n#endif",beginnormal_vertex:"vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif",bsdfs:"float G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, 1.0, dotVH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n} // validated",iridescence_fragment:"#ifdef USE_IRIDESCENCE\n\tconst mat3 XYZ_TO_REC709 = mat3(\n\t\t 3.2404542, -0.9692660, 0.0556434,\n\t\t-1.5371385, 1.8760108, -0.2040259,\n\t\t-0.4985314, 0.0415560, 1.0572252\n\t);\n\tvec3 Fresnel0ToIor( vec3 fresnel0 ) {\n\t\tvec3 sqrtF0 = sqrt( fresnel0 );\n\t\treturn ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );\n\t}\n\tvec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {\n\t\treturn pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );\n\t}\n\tfloat IorToFresnel0( float transmittedIor, float incidentIor ) {\n\t\treturn pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));\n\t}\n\tvec3 evalSensitivity( float OPD, vec3 shift ) {\n\t\tfloat phase = 2.0 * PI * OPD * 1.0e-9;\n\t\tvec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );\n\t\tvec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );\n\t\tvec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );\n\t\tvec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );\n\t\txyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );\n\t\txyz /= 1.0685e-7;\n\t\tvec3 rgb = XYZ_TO_REC709 * xyz;\n\t\treturn rgb;\n\t}\n\tvec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {\n\t\tvec3 I;\n\t\tfloat iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );\n\t\tfloat sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );\n\t\tfloat cosTheta2Sq = 1.0 - sinTheta2Sq;\n\t\tif ( cosTheta2Sq < 0.0 ) {\n\t\t\treturn vec3( 1.0 );\n\t\t}\n\t\tfloat cosTheta2 = sqrt( cosTheta2Sq );\n\t\tfloat R0 = IorToFresnel0( iridescenceIOR, outsideIOR );\n\t\tfloat R12 = F_Schlick( R0, 1.0, cosTheta1 );\n\t\tfloat T121 = 1.0 - R12;\n\t\tfloat phi12 = 0.0;\n\t\tif ( iridescenceIOR < outsideIOR ) phi12 = PI;\n\t\tfloat phi21 = PI - phi12;\n\t\tvec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) );\t\tvec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );\n\t\tvec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );\n\t\tvec3 phi23 = vec3( 0.0 );\n\t\tif ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;\n\t\tif ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;\n\t\tif ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;\n\t\tfloat OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;\n\t\tvec3 phi = vec3( phi21 ) + phi23;\n\t\tvec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );\n\t\tvec3 r123 = sqrt( R123 );\n\t\tvec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );\n\t\tvec3 C0 = R12 + Rs;\n\t\tI = C0;\n\t\tvec3 Cm = Rs - T121;\n\t\tfor ( int m = 1; m <= 2; ++ m ) {\n\t\t\tCm *= r123;\n\t\t\tvec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );\n\t\t\tI += Cm * Sm;\n\t\t}\n\t\treturn max( I, vec3( 0.0 ) );\n\t}\n#endif",bumpmap_pars_fragment:"#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vBumpMapUv );\n\t\tvec2 dSTdy = dFdy( vBumpMapUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );\n\t\tvec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif",clipping_planes_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#ifdef ALPHA_TO_COVERAGE\n\t\tfloat distanceToPlane, distanceGradient;\n\t\tfloat clipOpacity = 1.0;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\tclipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\tif ( clipOpacity == 0.0 ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tfloat unionClipOpacity = 1.0;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\t\tunionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tclipOpacity *= 1.0 - unionClipOpacity;\n\t\t#endif\n\t\tdiffuseColor.a *= clipOpacity;\n\t\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tbool clipped = true;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tif ( clipped ) discard;\n\t\t#endif\n\t#endif\n#endif",clipping_planes_pars_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif",clipping_planes_pars_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif",clipping_planes_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif",color_fragment:"#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#endif",color_pars_fragment:"#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#endif",color_pars_vertex:"#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvarying vec4 vColor;\n#endif",color_vertex:"#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvColor = vec4( 1.0 );\n#endif\n#ifdef USE_COLOR_ALPHA\n\tvColor *= color;\n#elif defined( USE_COLOR )\n\tvColor.rgb *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.rgb *= instanceColor.rgb;\n#endif\n#ifdef USE_BATCHING_COLOR\n\tvColor *= getBatchingColor( getIndirectIndex( gl_DrawID ) );\n#endif",common:"#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\n#ifdef USE_ALPHAHASH\n\tvarying vec3 vPosition;\n#endif\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n} // validated",cube_uv_reflection_fragment:"#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\thighp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tuv.x += filterInt * 3.0 * cubeUV_minTileSize;\n\t\tuv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );\n\t\tuv.x *= CUBEUV_TEXEL_WIDTH;\n\t\tuv.y *= CUBEUV_TEXEL_HEIGHT;\n\t\t#ifdef texture2DGradEXT\n\t\t\treturn texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;\n\t\t#else\n\t\t\treturn texture2D( envMap, uv ).rgb;\n\t\t#endif\n\t}\n\t#define cubeUV_r0 1.0\n\t#define cubeUV_m0 - 2.0\n\t#define cubeUV_r1 0.8\n\t#define cubeUV_m1 - 1.0\n\t#define cubeUV_r4 0.4\n\t#define cubeUV_m4 2.0\n\t#define cubeUV_r5 0.305\n\t#define cubeUV_m5 3.0\n\t#define cubeUV_r6 0.21\n\t#define cubeUV_m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= cubeUV_r1 ) {\n\t\t\tmip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;\n\t\t} else if ( roughness >= cubeUV_r4 ) {\n\t\t\tmip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;\n\t\t} else if ( roughness >= cubeUV_r5 ) {\n\t\t\tmip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;\n\t\t} else if ( roughness >= cubeUV_r6 ) {\n\t\t\tmip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif",defaultnormal_vertex:"vec3 transformedNormal = objectNormal;\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = objectTangent;\n#endif\n#ifdef USE_BATCHING\n\tmat3 bm = mat3( batchingMatrix );\n\ttransformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );\n\ttransformedNormal = bm * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = bm * transformedTangent;\n\t#endif\n#endif\n#ifdef USE_INSTANCING\n\tmat3 im = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );\n\ttransformedNormal = im * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = im * transformedTangent;\n\t#endif\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\ttransformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif",displacementmap_pars_vertex:"#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif",displacementmap_vertex:"#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\n#endif",emissivemap_fragment:"#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE\n\t\temissiveColor = sRGBTransferEOTF( emissiveColor );\n\t#endif\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif",emissivemap_pars_fragment:"#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif",colorspace_fragment:"gl_FragColor = linearToOutputTexel( gl_FragColor );",colorspace_pars_fragment:"vec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBTransferEOTF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}",envmap_fragment:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t\t#endif\n\t#endif\n#endif",envmap_common_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform mat3 envMapRotation;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif",envmap_physical_pars_fragment:"#ifdef USE_ENVMAP\n\tvec3 getIBLIrradiance( const in vec3 normal ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );\n\t\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );\n\t\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );\n\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\t#ifdef USE_ANISOTROPY\n\t\tvec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n\t\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\t\tvec3 bentNormal = cross( bitangent, viewDir );\n\t\t\t\tbentNormal = normalize( cross( bentNormal, bitangent ) );\n\t\t\t\tbentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n\t\t\t\treturn getIBLRadiance( viewDir, bentNormal, roughness );\n\t\t\t#else\n\t\t\t\treturn vec3( 0.0 );\n\t\t\t#endif\n\t\t}\n\t#endif\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif",fog_vertex:"#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n#endif",fog_pars_vertex:"#ifdef USE_FOG\n\tvarying float vFogDepth;\n#endif",fog_fragment:"#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif",fog_pars_fragment:"#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float vFogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif",gradientmap_pars_fragment:"#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn vec3( texture2D( gradientMap, coord ).r );\n\t#else\n\t\tvec2 fw = fwidth( coord ) * 0.5;\n\t\treturn mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );\n\t#endif\n}",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif",lights_lambert_fragment:"LambertMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularStrength = specularStrength;",lights_lambert_pars_fragment:"varying vec3 vViewPosition;\nstruct LambertMaterial {\n\tvec3 diffuseColor;\n\tfloat specularStrength;\n};\nvoid RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Lambert\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Lambert",lights_pars_begin:"uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n#if defined( USE_LIGHT_PROBES )\n\tuniform vec3 lightProbe[ 9 ];\n#endif\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif ( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif",lights_toon_fragment:"ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;",lights_toon_pars_fragment:"varying vec3 vViewPosition;\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon",lights_phong_fragment:"BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;",lights_phong_pars_fragment:"varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong",lights_physical_fragment:"PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.diffuseContribution = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.metalness = metalnessFactor;\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\tmaterial.ior = ior;\n\t#ifdef USE_SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULAR_COLORMAP\n\t\t\tspecularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n\t\t#endif\n\t\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor;\n\tmaterial.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = vec3( 0.04 );\n\tmaterial.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_DISPERSION\n\tmaterial.dispersion = dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tmaterial.iridescence = iridescence;\n\tmaterial.iridescenceIOR = iridescenceIOR;\n\t#ifdef USE_IRIDESCENCEMAP\n\t\tmaterial.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n\t#endif\n\t#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\t\tmaterial.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n\t#else\n\t\tmaterial.iridescenceThickness = iridescenceThicknessMaximum;\n\t#endif\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tmaterial.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.0001, 1.0 );\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\t#ifdef USE_ANISOTROPYMAP\n\t\tmat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n\t\tvec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n\t\tvec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n\t#else\n\t\tvec2 anisotropyV = anisotropyVector;\n\t#endif\n\tmaterial.anisotropy = length( anisotropyV );\n\tif( material.anisotropy == 0.0 ) {\n\t\tanisotropyV = vec2( 1.0, 0.0 );\n\t} else {\n\t\tanisotropyV /= material.anisotropy;\n\t\tmaterial.anisotropy = saturate( material.anisotropy );\n\t}\n\tmaterial.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n\tmaterial.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;\n\tmaterial.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;\n#endif",lights_physical_pars_fragment:"uniform sampler2D dfgLUT;\nstruct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tvec3 diffuseContribution;\n\tvec3 specularColor;\n\tvec3 specularColorBlended;\n\tfloat roughness;\n\tfloat metalness;\n\tfloat specularF90;\n\tfloat dispersion;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_IRIDESCENCE\n\t\tfloat iridescence;\n\t\tfloat iridescenceIOR;\n\t\tfloat iridescenceThickness;\n\t\tvec3 iridescenceFresnel;\n\t\tvec3 iridescenceF0;\n\t\tvec3 iridescenceFresnelDielectric;\n\t\tvec3 iridescenceFresnelMetallic;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n\t#ifdef IOR\n\t\tfloat ior;\n\t#endif\n\t#ifdef USE_TRANSMISSION\n\t\tfloat transmission;\n\t\tfloat transmissionAlpha;\n\t\tfloat thickness;\n\t\tfloat attenuationDistance;\n\t\tvec3 attenuationColor;\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat anisotropy;\n\t\tfloat alphaT;\n\t\tvec3 anisotropyT;\n\t\tvec3 anisotropyB;\n\t#endif\n};\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\nvec3 sheenSpecularDirect = vec3( 0.0 );\nvec3 sheenSpecularIndirect = vec3(0.0 );\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n#ifdef USE_ANISOTROPY\n\tfloat V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {\n\t\tfloat gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n\t\tfloat gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n\t\tfloat v = 0.5 / ( gv + gl );\n\t\treturn v;\n\t}\n\tfloat D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n\t\tfloat a2 = alphaT * alphaB;\n\t\thighp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n\t\thighp float v2 = dot( v, v );\n\t\tfloat w2 = a2 / v2;\n\t\treturn RECIPROCAL_PI * a2 * pow2 ( w2 );\n\t}\n#endif\n#ifdef USE_CLEARCOAT\n\tvec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n\t\tvec3 f0 = material.clearcoatF0;\n\t\tfloat f90 = material.clearcoatF90;\n\t\tfloat roughness = material.clearcoatRoughness;\n\t\tfloat alpha = pow2( roughness );\n\t\tvec3 halfDir = normalize( lightDir + viewDir );\n\t\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\t\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\t\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\t\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\t\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t\treturn F * ( V * D );\n\t}\n#endif\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 f0 = material.specularColorBlended;\n\tfloat f90 = material.specularF90;\n\tfloat roughness = material.roughness;\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t#ifdef USE_IRIDESCENCE\n\t\tF = mix( F, material.iridescenceFresnel, material.iridescence );\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat dotTL = dot( material.anisotropyT, lightDir );\n\t\tfloat dotTV = dot( material.anisotropyT, viewDir );\n\t\tfloat dotTH = dot( material.anisotropyT, halfDir );\n\t\tfloat dotBL = dot( material.anisotropyB, lightDir );\n\t\tfloat dotBV = dot( material.anisotropyB, viewDir );\n\t\tfloat dotBH = dot( material.anisotropyB, halfDir );\n\t\tfloat V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n\t\tfloat D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\n\t#else\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t#endif\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transpose( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenColor * ( D * V );\n}\n#endif\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat rInv = 1.0 / ( roughness + 0.1 );\n\tfloat a = -1.9362 + 1.0678 * roughness + 0.4573 * r2 - 0.8469 * rInv;\n\tfloat b = -0.6014 + 0.5538 * roughness - 0.4670 * r2 - 0.1255 * rInv;\n\tfloat DG = exp( a * dotNV + b );\n\treturn saturate( DG );\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;\n\t#ifdef USE_IRIDESCENCE\n\t\tvec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n\t#else\n\t\tvec3 Fr = specularColor;\n\t#endif\n\tvec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nvec3 BRDF_GGX_Multiscatter( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 singleScatter = BRDF_GGX( lightDir, viewDir, normal, material );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 dfgV = texture2D( dfgLUT, vec2( material.roughness, dotNV ) ).rg;\n\tvec2 dfgL = texture2D( dfgLUT, vec2( material.roughness, dotNL ) ).rg;\n\tvec3 FssEss_V = material.specularColorBlended * dfgV.x + material.specularF90 * dfgV.y;\n\tvec3 FssEss_L = material.specularColorBlended * dfgL.x + material.specularF90 * dfgL.y;\n\tfloat Ess_V = dfgV.x + dfgV.y;\n\tfloat Ess_L = dfgL.x + dfgL.y;\n\tfloat Ems_V = 1.0 - Ess_V;\n\tfloat Ems_L = 1.0 - Ess_L;\n\tvec3 Favg = material.specularColorBlended + ( 1.0 - material.specularColorBlended ) * 0.047619;\n\tvec3 Fms = FssEss_V * FssEss_L * Favg / ( 1.0 - Ems_V * Ems_L * Favg + EPSILON );\n\tfloat compensationFactor = Ems_V * Ems_L;\n\tvec3 multiScatter = Fms * compensationFactor;\n\treturn singleScatter + multiScatter;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometryNormal;\n\t\tvec3 viewDir = geometryViewDir;\n\t\tvec3 position = geometryPosition;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColorBlended * t2.x + ( material.specularF90 - material.specularColorBlended ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseContribution * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t\t#ifdef USE_CLEARCOAT\n\t\t\tvec3 Ncc = geometryClearcoatNormal;\n\t\t\tvec2 uvClearcoat = LTC_Uv( Ncc, viewDir, material.clearcoatRoughness );\n\t\t\tvec4 t1Clearcoat = texture2D( ltc_1, uvClearcoat );\n\t\t\tvec4 t2Clearcoat = texture2D( ltc_2, uvClearcoat );\n\t\t\tmat3 mInvClearcoat = mat3(\n\t\t\t\tvec3( t1Clearcoat.x, 0, t1Clearcoat.y ),\n\t\t\t\tvec3( 0, 1, 0 ),\n\t\t\t\tvec3( t1Clearcoat.z, 0, t1Clearcoat.w )\n\t\t\t);\n\t\t\tvec3 fresnelClearcoat = material.clearcoatF0 * t2Clearcoat.x + ( material.clearcoatF90 - material.clearcoatF0 ) * t2Clearcoat.y;\n\t\t\tclearcoatSpecularDirect += lightColor * fresnelClearcoat * LTC_Evaluate( Ncc, viewDir, position, mInvClearcoat, rectCoords );\n\t\t#endif\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\t#endif\n\t#ifdef USE_SHEEN\n \n \t\tsheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n \n \t\tfloat sheenAlbedoV = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n \t\tfloat sheenAlbedoL = IBLSheenBRDF( geometryNormal, directLight.direction, material.sheenRoughness );\n \n \t\tfloat sheenEnergyComp = 1.0 - max3( material.sheenColor ) * max( sheenAlbedoV, sheenAlbedoL );\n \n \t\tirradiance *= sheenEnergyComp;\n \n \t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX_Multiscatter( directLight.direction, geometryViewDir, geometryNormal, material );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseContribution );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 diffuse = irradiance * BRDF_Lambert( material.diffuseContribution );\n\t#ifdef USE_SHEEN\n\t\tfloat sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t\tfloat sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;\n\t\tdiffuse *= sheenEnergyComp;\n\t#endif\n\treflectedLight.indirectDiffuse += diffuse;\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ) * RECIPROCAL_PI;\n \t#endif\n\tvec3 singleScatteringDielectric = vec3( 0.0 );\n\tvec3 multiScatteringDielectric = vec3( 0.0 );\n\tvec3 singleScatteringMetallic = vec3( 0.0 );\n\tvec3 multiScatteringMetallic = vec3( 0.0 );\n\t#ifdef USE_IRIDESCENCE\n\t\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnelDielectric, material.roughness, singleScatteringDielectric, multiScatteringDielectric );\n\t\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.diffuseColor, material.specularF90, material.iridescence, material.iridescenceFresnelMetallic, material.roughness, singleScatteringMetallic, multiScatteringMetallic );\n\t#else\n\t\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScatteringDielectric, multiScatteringDielectric );\n\t\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.diffuseColor, material.specularF90, material.roughness, singleScatteringMetallic, multiScatteringMetallic );\n\t#endif\n\tvec3 singleScattering = mix( singleScatteringDielectric, singleScatteringMetallic, material.metalness );\n\tvec3 multiScattering = mix( multiScatteringDielectric, multiScatteringMetallic, material.metalness );\n\tvec3 totalScatteringDielectric = singleScatteringDielectric + multiScatteringDielectric;\n\tvec3 diffuse = material.diffuseContribution * ( 1.0 - totalScatteringDielectric );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tvec3 indirectSpecular = radiance * singleScattering;\n\tindirectSpecular += multiScattering * cosineWeightedIrradiance;\n\tvec3 indirectDiffuse = diffuse * cosineWeightedIrradiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t\tfloat sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;\n\t\tindirectSpecular *= sheenEnergyComp;\n\t\tindirectDiffuse *= sheenEnergyComp;\n\t#endif\n\treflectedLight.indirectSpecular += indirectSpecular;\n\treflectedLight.indirectDiffuse += indirectDiffuse;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}",lights_fragment_begin:"\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n#ifdef USE_CLEARCOAT\n\tgeometryClearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\tif ( material.iridescenceThickness == 0.0 ) {\n\t\tmaterial.iridescence = 0.0;\n\t} else {\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\t}\n\tif ( material.iridescence > 0.0 ) {\n\t\tmaterial.iridescenceFresnelDielectric = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\t\tmaterial.iridescenceFresnelMetallic = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.diffuseColor );\n\t\tmaterial.iridescenceFresnel = mix( material.iridescenceFresnelDielectric, material.iridescenceFresnelMetallic, material.metalness );\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\t}\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if defined( USE_LIGHT_PROBES )\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\t#endif\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif",lights_fragment_maps:"#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\t#if defined( STANDARD ) || defined( LAMBERT ) || defined( PHONG )\n\t\t\tiblIrradiance += getIBLIrradiance( geometryNormal );\n\t\t#endif\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\t#ifdef USE_ANISOTROPY\n\t\tradiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n\t#else\n\t\tradiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif",lights_fragment_end:"#if defined( RE_IndirectDiffuse )\n\t#if defined( LAMBERT ) || defined( PHONG )\n\t\tirradiance += iblIrradiance;\n\t#endif\n\tRE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif",logdepthbuf_fragment:"#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )\n\tgl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif",logdepthbuf_pars_fragment:"#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_pars_vertex:"#ifdef USE_LOGARITHMIC_DEPTH_BUFFER\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_vertex:"#ifdef USE_LOGARITHMIC_DEPTH_BUFFER\n\tvFragDepth = 1.0 + gl_Position.w;\n\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n#endif",map_fragment:"#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif",map_pars_fragment:"#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif",map_particle_fragment:"#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t#if defined( USE_POINTS_UV )\n\t\tvec2 uv = vUv;\n\t#else\n\t\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tdiffuseColor *= texture2D( map, uv );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif",map_particle_pars_fragment:"#if defined( USE_POINTS_UV )\n\tvarying vec2 vUv;\n#else\n\t#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t\tuniform mat3 uvTransform;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",metalnessmap_fragment:"float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif",metalnessmap_pars_fragment:"#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif",morphinstance_vertex:"#ifdef USE_INSTANCING_MORPH\n\tfloat morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\tfloat morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tmorphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;\n\t}\n#endif",morphcolor_vertex:"#if defined( USE_MORPHCOLORS )\n\tvColor *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t#if defined( USE_COLOR_ALPHA )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n\t\t#elif defined( USE_COLOR )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n\t\t#endif\n\t}\n#endif",morphnormal_vertex:"#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif",morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\n\t#ifndef USE_INSTANCING_MORPH\n\t\tuniform float morphTargetBaseInfluence;\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t#endif\n\tuniform sampler2DArray morphTargetsTexture;\n\tuniform ivec2 morphTargetsTextureSize;\n\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\t\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n\t\tint y = texelIndex / morphTargetsTextureSize.x;\n\t\tint x = texelIndex - y * morphTargetsTextureSize.x;\n\t\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\n\t\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\n\t}\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif",normal_fragment_begin:"float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = dFdx( vViewPosition );\n\tvec3 fdy = dFdy( vViewPosition );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal *= faceDirection;\n\t#endif\n#endif\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn = getTangentFrame( - vViewPosition, normal,\n\t\t#if defined( USE_NORMALMAP )\n\t\t\tvNormalMapUv\n\t\t#elif defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tvClearcoatNormalMapUv\n\t\t#else\n\t\t\tvUv\n\t\t#endif\n\t\t);\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn[0] *= faceDirection;\n\t\ttbn[1] *= faceDirection;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn2[0] *= faceDirection;\n\t\ttbn2[1] *= faceDirection;\n\t#endif\n#endif\nvec3 nonPerturbedNormal = normal;",normal_fragment_maps:"#ifdef USE_NORMALMAP_OBJECTSPACE\n\tnormal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n\tvec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\tnormal = normalize( tbn * mapN );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif",normal_pars_fragment:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_pars_vertex:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_vertex:"#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif",normalmap_pars_fragment:"#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef USE_NORMALMAP_OBJECTSPACE\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )\n\tmat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {\n\t\tvec3 q0 = dFdx( eye_pos.xyz );\n\t\tvec3 q1 = dFdy( eye_pos.xyz );\n\t\tvec2 st0 = dFdx( uv.st );\n\t\tvec2 st1 = dFdy( uv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );\n\t\treturn mat3( T * scale, B * scale, N );\n\t}\n#endif",clearcoat_normal_fragment_begin:"#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal = nonPerturbedNormal;\n#endif",clearcoat_normal_fragment_maps:"#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\tclearcoatNormal = normalize( tbn2 * clearcoatMapN );\n#endif",clearcoat_pars_fragment:"#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif",iridescence_pars_fragment:"#ifdef USE_IRIDESCENCEMAP\n\tuniform sampler2D iridescenceMap;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform sampler2D iridescenceThicknessMap;\n#endif",opaque_fragment:"#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= material.transmissionAlpha;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );",packing:"vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;\nconst float Inv255 = 1. / 255.;\nconst vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\nconst vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );\nconst vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );\nconst vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );\nvec4 packDepthToRGBA( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec4( 0., 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec4( 1., 1., 1., 1. );\n\tfloat vuf;\n\tfloat af = modf( v * PackFactors.a, vuf );\n\tfloat bf = modf( vuf * ShiftRight8, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );\n}\nvec3 packDepthToRGB( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec3( 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec3( 1., 1., 1. );\n\tfloat vuf;\n\tfloat bf = modf( v * PackFactors.b, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec3( vuf * Inv255, gf * PackUpscale, bf );\n}\nvec2 packDepthToRG( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec2( 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec2( 1., 1. );\n\tfloat vuf;\n\tfloat gf = modf( v * 256., vuf );\n\treturn vec2( vuf * Inv255, gf );\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors4 );\n}\nfloat unpackRGBToDepth( const in vec3 v ) {\n\treturn dot( v, UnpackFactors3 );\n}\nfloat unpackRGToDepth( const in vec2 v ) {\n\treturn v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;\n}\nvec4 pack2HalfToRGBA( const in vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( const in vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\n\t\treturn depth * ( far - near ) - far;\n\t#else\n\t\treturn depth * ( near - far ) - near;\n\t#endif\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\t\n\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\treturn ( near * far ) / ( ( near - far ) * depth - near );\n\t#else\n\t\treturn ( near * far ) / ( ( far - near ) * depth - far );\n\t#endif\n}",premultiplied_alpha_fragment:"#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif",project_vertex:"vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_BATCHING\n\tmvPosition = batchingMatrix * mvPosition;\n#endif\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;",dithering_fragment:"#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif",dithering_pars_fragment:"#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif",roughnessmap_fragment:"float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );\n\troughnessFactor *= texelRoughness.g;\n#endif",roughnessmap_pars_fragment:"#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif",shadowmap_pars_fragment:"#if NUM_SPOT_LIGHT_COORDS > 0\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#if NUM_SPOT_LIGHT_MAPS > 0\n\tuniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform sampler2DShadow directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\t#else\n\t\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform sampler2DShadow spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\t#else\n\t\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform samplerCubeShadow pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\t#elif defined( SHADOWMAP_TYPE_BASIC )\n\t\t\tuniform samplerCube pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\tfloat interleavedGradientNoise( vec2 position ) {\n\t\t\treturn fract( 52.9829189 * fract( dot( position, vec2( 0.06711056, 0.00583715 ) ) ) );\n\t\t}\n\t\tvec2 vogelDiskSample( int sampleIndex, int samplesCount, float phi ) {\n\t\t\tconst float goldenAngle = 2.399963229728653;\n\t\t\tfloat r = sqrt( ( float( sampleIndex ) + 0.5 ) / float( samplesCount ) );\n\t\t\tfloat theta = float( sampleIndex ) * goldenAngle + phi;\n\t\t\treturn vec2( cos( theta ), sin( theta ) ) * r;\n\t\t}\n\t#endif\n\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\tfloat getShadow( sampler2DShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\t\tfloat shadow = 1.0;\n\t\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\t\tshadowCoord.z += shadowBias;\n\t\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\t\tif ( frustumTest ) {\n\t\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\t\tfloat radius = shadowRadius * texelSize.x;\n\t\t\t\tfloat phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;\n\t\t\t\tshadow = (\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 0, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 1, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 2, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 3, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 4, 5, phi ) * radius, shadowCoord.z ) )\n\t\t\t\t) * 0.2;\n\t\t\t}\n\t\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t\t}\n\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\t\tfloat shadow = 1.0;\n\t\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tshadowCoord.z -= shadowBias;\n\t\t\t#else\n\t\t\t\tshadowCoord.z += shadowBias;\n\t\t\t#endif\n\t\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\t\tif ( frustumTest ) {\n\t\t\t\tvec2 distribution = texture2D( shadowMap, shadowCoord.xy ).rg;\n\t\t\t\tfloat mean = distribution.x;\n\t\t\t\tfloat variance = distribution.y * distribution.y;\n\t\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\t\tfloat hard_shadow = step( mean, shadowCoord.z );\n\t\t\t\t#else\n\t\t\t\t\tfloat hard_shadow = step( shadowCoord.z, mean );\n\t\t\t\t#endif\n\t\t\t\t\n\t\t\t\tif ( hard_shadow == 1.0 ) {\n\t\t\t\t\tshadow = 1.0;\n\t\t\t\t} else {\n\t\t\t\t\tvariance = max( variance, 0.0000001 );\n\t\t\t\t\tfloat d = shadowCoord.z - mean;\n\t\t\t\t\tfloat p_max = variance / ( variance + d * d );\n\t\t\t\t\tp_max = clamp( ( p_max - 0.3 ) / 0.65, 0.0, 1.0 );\n\t\t\t\t\tshadow = max( hard_shadow, p_max );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t\t}\n\t#else\n\t\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\t\tfloat shadow = 1.0;\n\t\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tshadowCoord.z -= shadowBias;\n\t\t\t#else\n\t\t\t\tshadowCoord.z += shadowBias;\n\t\t\t#endif\n\t\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\t\tif ( frustumTest ) {\n\t\t\t\tfloat depth = texture2D( shadowMap, shadowCoord.xy ).r;\n\t\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\t\tshadow = step( depth, shadowCoord.z );\n\t\t\t\t#else\n\t\t\t\t\tshadow = step( shadowCoord.z, depth );\n\t\t\t\t#endif\n\t\t\t}\n\t\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t\t}\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#if defined( SHADOWMAP_TYPE_PCF )\n\tfloat getPointShadow( samplerCubeShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\tvec3 absVec = abs( lightToPosition );\n\t\tfloat viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );\n\t\tif ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tfloat dp = ( shadowCameraNear * ( shadowCameraFar - viewSpaceZ ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );\n\t\t\t\tdp -= shadowBias;\n\t\t\t#else\n\t\t\t\tfloat dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );\n\t\t\t\tdp += shadowBias;\n\t\t\t#endif\n\t\t\tfloat texelSize = shadowRadius / shadowMapSize.x;\n\t\t\tvec3 absDir = abs( bd3D );\n\t\t\tvec3 tangent = absDir.x > absDir.z ? vec3( 0.0, 1.0, 0.0 ) : vec3( 1.0, 0.0, 0.0 );\n\t\t\ttangent = normalize( cross( bd3D, tangent ) );\n\t\t\tvec3 bitangent = cross( bd3D, tangent );\n\t\t\tfloat phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;\n\t\t\tvec2 sample0 = vogelDiskSample( 0, 5, phi );\n\t\t\tvec2 sample1 = vogelDiskSample( 1, 5, phi );\n\t\t\tvec2 sample2 = vogelDiskSample( 2, 5, phi );\n\t\t\tvec2 sample3 = vogelDiskSample( 3, 5, phi );\n\t\t\tvec2 sample4 = vogelDiskSample( 4, 5, phi );\n\t\t\tshadow = (\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample0.x + bitangent * sample0.y ) * texelSize, dp ) ) +\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample1.x + bitangent * sample1.y ) * texelSize, dp ) ) +\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample2.x + bitangent * sample2.y ) * texelSize, dp ) ) +\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample3.x + bitangent * sample3.y ) * texelSize, dp ) ) +\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample4.x + bitangent * sample4.y ) * texelSize, dp ) )\n\t\t\t) * 0.2;\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\t#elif defined( SHADOWMAP_TYPE_BASIC )\n\tfloat getPointShadow( samplerCube shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tvec3 absVec = abs( lightToPosition );\n\t\tfloat viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );\n\t\tif ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {\n\t\t\tfloat dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );\n\t\t\tdp += shadowBias;\n\t\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t\tfloat depth = textureCube( shadowMap, bd3D ).r;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tdepth = 1.0 - depth;\n\t\t\t#endif\n\t\t\tshadow = step( dp, depth );\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\t#endif\n\t#endif\n#endif",shadowmap_pars_vertex:"#if NUM_SPOT_LIGHT_COORDS > 0\n\tuniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif",shadowmap_vertex:"#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\tvec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition;\n\t\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n\t\t#endif\n\t\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n#endif",shadowmask_pars_fragment:"float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0 && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}",skinbase_vertex:"#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\tuniform highp sampler2D boneTexture;\n\tmat4 getBoneMatrix( const in float i ) {\n\t\tint size = textureSize( boneTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n#endif",skinning_vertex:"#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif",skinnormal_vertex:"#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif",specularmap_fragment:"float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif",specularmap_pars_fragment:"#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif",tonemapping_fragment:"#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif",tonemapping_pars_fragment:"#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn saturate( toneMappingExposure * color );\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 CineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nconst mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.6605, - 0.1246, - 0.0182 ),\n\tvec3( - 0.5876, 1.1329, - 0.1006 ),\n\tvec3( - 0.0728, - 0.0083, 1.1187 )\n);\nconst mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(\n\tvec3( 0.6274, 0.0691, 0.0164 ),\n\tvec3( 0.3293, 0.9195, 0.0880 ),\n\tvec3( 0.0433, 0.0113, 0.8956 )\n);\nvec3 agxDefaultContrastApprox( vec3 x ) {\n\tvec3 x2 = x * x;\n\tvec3 x4 = x2 * x2;\n\treturn + 15.5 * x4 * x2\n\t\t- 40.14 * x4 * x\n\t\t+ 31.96 * x4\n\t\t- 6.868 * x2 * x\n\t\t+ 0.4298 * x2\n\t\t+ 0.1191 * x\n\t\t- 0.00232;\n}\nvec3 AgXToneMapping( vec3 color ) {\n\tconst mat3 AgXInsetMatrix = mat3(\n\t\tvec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n\t\tvec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n\t\tvec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )\n\t);\n\tconst mat3 AgXOutsetMatrix = mat3(\n\t\tvec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),\n\t\tvec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),\n\t\tvec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )\n\t);\n\tconst float AgxMinEv = - 12.47393;\tconst float AgxMaxEv = 4.026069;\n\tcolor *= toneMappingExposure;\n\tcolor = LINEAR_SRGB_TO_LINEAR_REC2020 * color;\n\tcolor = AgXInsetMatrix * color;\n\tcolor = max( color, 1e-10 );\tcolor = log2( color );\n\tcolor = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );\n\tcolor = clamp( color, 0.0, 1.0 );\n\tcolor = agxDefaultContrastApprox( color );\n\tcolor = AgXOutsetMatrix * color;\n\tcolor = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );\n\tcolor = LINEAR_REC2020_TO_LINEAR_SRGB * color;\n\tcolor = clamp( color, 0.0, 1.0 );\n\treturn color;\n}\nvec3 NeutralToneMapping( vec3 color ) {\n\tconst float StartCompression = 0.8 - 0.04;\n\tconst float Desaturation = 0.15;\n\tcolor *= toneMappingExposure;\n\tfloat x = min( color.r, min( color.g, color.b ) );\n\tfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\n\tcolor -= offset;\n\tfloat peak = max( color.r, max( color.g, color.b ) );\n\tif ( peak < StartCompression ) return color;\n\tfloat d = 1. - StartCompression;\n\tfloat newPeak = 1. - d * d / ( peak + d - StartCompression );\n\tcolor *= newPeak / peak;\n\tfloat g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );\n\treturn mix( color, vec3( newPeak ), g );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }",transmission_fragment:"#ifdef USE_TRANSMISSION\n\tmaterial.transmission = transmission;\n\tmaterial.transmissionAlpha = 1.0;\n\tmaterial.thickness = thickness;\n\tmaterial.attenuationDistance = attenuationDistance;\n\tmaterial.attenuationColor = attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tmaterial.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tmaterial.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmitted = getIBLVolumeRefraction(\n\t\tn, v, material.roughness, material.diffuseContribution, material.specularColorBlended, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,\n\t\tmaterial.attenuationColor, material.attenuationDistance );\n\tmaterial.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n\ttotalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n#endif",transmission_pars_fragment:"#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tfloat w0( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\n\t}\n\tfloat w1( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\n\t}\n\tfloat w2( float a ){\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\n\t}\n\tfloat w3( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * a );\n\t}\n\tfloat g0( float a ) {\n\t\treturn w0( a ) + w1( a );\n\t}\n\tfloat g1( float a ) {\n\t\treturn w2( a ) + w3( a );\n\t}\n\tfloat h0( float a ) {\n\t\treturn - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\n\t}\n\tfloat h1( float a ) {\n\t\treturn 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\n\t}\n\tvec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\n\t\tuv = uv * texelSize.zw + 0.5;\n\t\tvec2 iuv = floor( uv );\n\t\tvec2 fuv = fract( uv );\n\t\tfloat g0x = g0( fuv.x );\n\t\tfloat g1x = g1( fuv.x );\n\t\tfloat h0x = h0( fuv.x );\n\t\tfloat h1x = h1( fuv.x );\n\t\tfloat h0y = h0( fuv.y );\n\t\tfloat h1y = h1( fuv.y );\n\t\tvec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\treturn g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\n\t\t\tg1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\n\t}\n\tvec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\n\t\tvec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\n\t\tvec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\n\t\tvec2 fLodSizeInv = 1.0 / fLodSize;\n\t\tvec2 cLodSizeInv = 1.0 / cLodSize;\n\t\tvec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\n\t\tvec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\n\t\treturn mix( fSample, cSample, fract( lod ) );\n\t}\n\tvec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( const in float roughness, const in float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n\t\tfloat lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\treturn textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\n\t}\n\tvec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tif ( isinf( attenuationDistance ) ) {\n\t\t\treturn vec3( 1.0 );\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n\t\tconst in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n\t\tconst in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,\n\t\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tvec4 transmittedLight;\n\t\tvec3 transmittance;\n\t\t#ifdef USE_DISPERSION\n\t\t\tfloat halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;\n\t\t\tvec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );\n\t\t\tfor ( int i = 0; i < 3; i ++ ) {\n\t\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );\n\t\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\t\trefractionCoords += 1.0;\n\t\t\t\trefractionCoords /= 2.0;\n\t\t\t\tvec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );\n\t\t\t\ttransmittedLight[ i ] = transmissionSample[ i ];\n\t\t\t\ttransmittedLight.a += transmissionSample.a;\n\t\t\t\ttransmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];\n\t\t\t}\n\t\t\ttransmittedLight.a /= 3.0;\n\t\t#else\n\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\trefractionCoords += 1.0;\n\t\t\trefractionCoords /= 2.0;\n\t\t\ttransmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\t\ttransmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\t#endif\n\t\tvec3 attenuatedColor = transmittance * transmittedLight.rgb;\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\tfloat transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\n\t}\n#endif",uv_pars_fragment:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif",uv_pars_vertex:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tuniform mat3 mapTransform;\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform mat3 alphaMapTransform;\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tuniform mat3 lightMapTransform;\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tuniform mat3 aoMapTransform;\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tuniform mat3 bumpMapTransform;\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tuniform mat3 normalMapTransform;\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tuniform mat3 displacementMapTransform;\n\tvarying vec2 vDisplacementMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tuniform mat3 emissiveMapTransform;\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tuniform mat3 metalnessMapTransform;\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tuniform mat3 roughnessMapTransform;\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tuniform mat3 anisotropyMapTransform;\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tuniform mat3 clearcoatMapTransform;\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform mat3 clearcoatNormalMapTransform;\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform mat3 clearcoatRoughnessMapTransform;\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tuniform mat3 sheenColorMapTransform;\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tuniform mat3 sheenRoughnessMapTransform;\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tuniform mat3 iridescenceMapTransform;\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform mat3 iridescenceThicknessMapTransform;\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tuniform mat3 specularMapTransform;\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tuniform mat3 specularColorMapTransform;\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tuniform mat3 specularIntensityMapTransform;\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif",uv_vertex:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvUv = vec3( uv, 1 ).xy;\n#endif\n#ifdef USE_MAP\n\tvMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ALPHAMAP\n\tvAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_LIGHTMAP\n\tvLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_AOMAP\n\tvAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_BUMPMAP\n\tvBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_NORMALMAP\n\tvNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tvDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_METALNESSMAP\n\tvMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULARMAP\n\tvSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tvTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_THICKNESSMAP\n\tvThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;\n#endif",worldpos_vertex:"#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_BATCHING\n\t\tworldPosition = batchingMatrix * worldPosition;\n\t#endif\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif",background_vert:"varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}",background_frag:"uniform sampler2D t2D;\nuniform float backgroundIntensity;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\ttexColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}",backgroundCube_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}",backgroundCube_frag:"#ifdef ENVMAP_TYPE_CUBE\n\tuniform samplerCube envMap;\n#elif defined( ENVMAP_TYPE_CUBE_UV )\n\tuniform sampler2D envMap;\n#endif\nuniform float flipEnvMap;\nuniform float backgroundBlurriness;\nuniform float backgroundIntensity;\nuniform mat3 backgroundRotation;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );\n\t#else\n\t\tvec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}",cube_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}",cube_frag:"uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n\tgl_FragColor = texColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}",depth_vert:"#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <skinbase_vertex>\n\t#include <morphinstance_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}",depth_frag:"#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <clipping_planes_fragment>\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <logdepthbuf_fragment>\n\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\tfloat fragCoordZ = vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ];\n\t#else\n\t\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ] + 0.5;\n\t#endif\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#elif DEPTH_PACKING == 3202\n\t\tgl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );\n\t#elif DEPTH_PACKING == 3203\n\t\tgl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );\n\t#endif\n}",distance_vert:"#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <skinbase_vertex>\n\t#include <morphinstance_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}",distance_frag:"#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <clipping_planes_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = vec4( dist, 0.0, 0.0, 1.0 );\n}",equirect_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}",equirect_frag:"uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}",linedashed_vert:"uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}",linedashed_frag:"uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}",meshbasic_vert:"#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinbase_vertex>\n\t\t#include <skinnormal_vertex>\n\t\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}",meshbasic_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\treflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshlambert_vert:"#define LAMBERT\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshlambert_frag:"#define LAMBERT\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_lambert_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_lambert_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshmatcap_vert:"#define MATCAP\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}",meshmatcap_frag:"#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t#else\n\t\tvec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshnormal_vert:"#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}",meshnormal_frag:"#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include <uv_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( normalize( normal ) * 0.5 + 0.5, diffuseColor.a );\n\t#ifdef OPAQUE\n\t\tgl_FragColor.a = 1.0;\n\t#endif\n}",meshphong_vert:"#define PHONG\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshphong_frag:"#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshphysical_vert:"#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n#ifdef USE_TRANSMISSION\n\tvWorldPosition = worldPosition.xyz;\n#endif\n}",meshphysical_frag:"#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define USE_SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef USE_SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULAR_COLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_DISPERSION\n\tuniform float dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\tuniform vec2 anisotropyVector;\n\t#ifdef USE_ANISOTROPYMAP\n\t\tuniform sampler2D anisotropyMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <iridescence_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n \n\t\toutgoingLight = outgoingLight + sheenSpecularDirect + sheenSpecularIndirect;\n \n \t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\t#endif\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshtoon_vert:"#define TOON\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshtoon_frag:"#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",points_vert:"uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n#ifdef USE_POINTS_UV\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif\nvoid main() {\n\t#ifdef USE_POINTS_UV\n\t\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\t#endif\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}",points_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}",shadow_vert:"#include <common>\n#include <batching_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",shadow_frag:"uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <logdepthbuf_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\t#include <logdepthbuf_fragment>\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}",sprite_vert:"uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix[ 3 ];\n\tvec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}",sprite_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n}"},vd={common:{diffuse:{value:new En(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Mi},alphaMap:{value:null},alphaMapTransform:{value:new Mi},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Mi}},envmap:{envMap:{value:null},envMapRotation:{value:new Mi},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Mi}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Mi}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Mi},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Mi},normalScale:{value:new yi(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Mi},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Mi}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Mi}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Mi}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new En(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new En(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Mi},alphaTest:{value:0},uvTransform:{value:new Mi}},sprite:{diffuse:{value:new En(16777215)},opacity:{value:1},center:{value:new yi(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Mi},alphaMap:{value:null},alphaMapTransform:{value:new Mi},alphaTest:{value:0}}},yd={basic:{uniforms:El([vd.common,vd.specularmap,vd.envmap,vd.aomap,vd.lightmap,vd.fog]),vertexShader:gd.meshbasic_vert,fragmentShader:gd.meshbasic_frag},lambert:{uniforms:El([vd.common,vd.specularmap,vd.envmap,vd.aomap,vd.lightmap,vd.emissivemap,vd.bumpmap,vd.normalmap,vd.displacementmap,vd.fog,vd.lights,{emissive:{value:new En(0)},envMapIntensity:{value:1}}]),vertexShader:gd.meshlambert_vert,fragmentShader:gd.meshlambert_frag},phong:{uniforms:El([vd.common,vd.specularmap,vd.envmap,vd.aomap,vd.lightmap,vd.emissivemap,vd.bumpmap,vd.normalmap,vd.displacementmap,vd.fog,vd.lights,{emissive:{value:new En(0)},specular:{value:new En(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:gd.meshphong_vert,fragmentShader:gd.meshphong_frag},standard:{uniforms:El([vd.common,vd.envmap,vd.aomap,vd.lightmap,vd.emissivemap,vd.bumpmap,vd.normalmap,vd.displacementmap,vd.roughnessmap,vd.metalnessmap,vd.fog,vd.lights,{emissive:{value:new En(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:gd.meshphysical_vert,fragmentShader:gd.meshphysical_frag},toon:{uniforms:El([vd.common,vd.aomap,vd.lightmap,vd.emissivemap,vd.bumpmap,vd.normalmap,vd.displacementmap,vd.gradientmap,vd.fog,vd.lights,{emissive:{value:new En(0)}}]),vertexShader:gd.meshtoon_vert,fragmentShader:gd.meshtoon_frag},matcap:{uniforms:El([vd.common,vd.bumpmap,vd.normalmap,vd.displacementmap,vd.fog,{matcap:{value:null}}]),vertexShader:gd.meshmatcap_vert,fragmentShader:gd.meshmatcap_frag},points:{uniforms:El([vd.points,vd.fog]),vertexShader:gd.points_vert,fragmentShader:gd.points_frag},dashed:{uniforms:El([vd.common,vd.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:gd.linedashed_vert,fragmentShader:gd.linedashed_frag},depth:{uniforms:El([vd.common,vd.displacementmap]),vertexShader:gd.depth_vert,fragmentShader:gd.depth_frag},normal:{uniforms:El([vd.common,vd.bumpmap,vd.normalmap,vd.displacementmap,{opacity:{value:1}}]),vertexShader:gd.meshnormal_vert,fragmentShader:gd.meshnormal_frag},sprite:{uniforms:El([vd.sprite,vd.fog]),vertexShader:gd.sprite_vert,fragmentShader:gd.sprite_frag},background:{uniforms:{uvTransform:{value:new Mi},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:gd.background_vert,fragmentShader:gd.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new Mi}},vertexShader:gd.backgroundCube_vert,fragmentShader:gd.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:gd.cube_vert,fragmentShader:gd.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:gd.equirect_vert,fragmentShader:gd.equirect_frag},distance:{uniforms:El([vd.common,vd.displacementmap,{referencePosition:{value:new xi},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:gd.distance_vert,fragmentShader:gd.distance_frag},shadow:{uniforms:El([vd.lights,vd.fog,{color:{value:new En(0)},opacity:{value:1}}]),vertexShader:gd.shadow_vert,fragmentShader:gd.shadow_frag}};yd.physical={uniforms:El([yd.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Mi},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Mi},clearcoatNormalScale:{value:new yi(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Mi},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Mi},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Mi},sheen:{value:0},sheenColor:{value:new En(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Mi},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Mi},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Mi},transmissionSamplerSize:{value:new yi},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Mi},attenuationDistance:{value:0},attenuationColor:{value:new En(0)},specularColor:{value:new En(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Mi},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Mi},anisotropyVector:{value:new yi},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Mi}}]),vertexShader:gd.meshphysical_vert,fragmentShader:gd.meshphysical_frag};const _d={r:0,b:0,g:0},xd=new tn,bd=new Wi;function Sd(t,e,i,n,s,r){const a=new En(0);let o,l,h=!0===s?0:1,c=null,d=0,u=null;function p(t){let i=!0===t.isScene?t.background:null;if(i&&i.isTexture){const n=t.backgroundBlurriness>0;i=e.get(i,n)}return i}function m(e,n){e.getRGB(_d,Tl(t)),i.buffers.color.setClear(_d.r,_d.g,_d.b,n,r)}return{getClearColor:function(){return a},setClearColor:function(t,e=1){a.set(t),h=e,m(a,h)},getClearAlpha:function(){return h},setClearAlpha:function(t){h=t,m(a,h)},render:function(e){let n=!1;const s=p(e);null===s?m(a,h):s&&s.isColor&&(m(s,1),n=!0);const o=t.xr.getEnvironmentBlendMode();"additive"===o?i.buffers.color.setClear(0,0,0,1,r):"alpha-blend"===o&&i.buffers.color.setClear(0,0,0,0,r),(t.autoClear||n)&&(i.buffers.depth.setTest(!0),i.buffers.depth.setMask(!0),i.buffers.color.setMask(!0),t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil))},addToRenderList:function(e,i){const s=p(i);s&&(s.isCubeTexture||s.mapping===J)?(void 0===l&&(l=new xr(new Qa(1,1,1),new Dl({name:"BackgroundCubeMaterial",uniforms:Al(yd.backgroundCube.uniforms),vertexShader:yd.backgroundCube.vertexShader,fragmentShader:yd.backgroundCube.fragmentShader,side:1,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute("normal"),l.geometry.deleteAttribute("uv"),l.onBeforeRender=function(t,e,i){this.matrixWorld.copyPosition(i.matrixWorld)},Object.defineProperty(l.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),n.update(l)),xd.copy(i.backgroundRotation),xd.x*=-1,xd.y*=-1,xd.z*=-1,s.isCubeTexture&&!1===s.isRenderTargetTexture&&(xd.y*=-1,xd.z*=-1),l.material.uniforms.envMap.value=s,l.material.uniforms.flipEnvMap.value=s.isCubeTexture&&!1===s.isRenderTargetTexture?-1:1,l.material.uniforms.backgroundBlurriness.value=i.backgroundBlurriness,l.material.uniforms.backgroundIntensity.value=i.backgroundIntensity,l.material.uniforms.backgroundRotation.value.setFromMatrix4(bd.makeRotationFromEuler(xd)),l.material.toneMapped=Ci.getTransfer(s.colorSpace)!==De,c===s&&d===s.version&&u===t.toneMapping||(l.material.needsUpdate=!0,c=s,d=s.version,u=t.toneMapping),l.layers.enableAll(),e.unshift(l,l.geometry,l.material,0,0,null)):s&&s.isTexture&&(void 0===o&&(o=new xr(new pl(2,2),new Dl({name:"BackgroundMaterial",uniforms:Al(yd.background.uniforms),vertexShader:yd.background.vertexShader,fragmentShader:yd.background.fragmentShader,side:0,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),o.geometry.deleteAttribute("normal"),Object.defineProperty(o.material,"map",{get:function(){return this.uniforms.t2D.value}}),n.update(o)),o.material.uniforms.t2D.value=s,o.material.uniforms.backgroundIntensity.value=i.backgroundIntensity,o.material.toneMapped=Ci.getTransfer(s.colorSpace)!==De,!0===s.matrixAutoUpdate&&s.updateMatrix(),o.material.uniforms.uvTransform.value.copy(s.matrix),c===s&&d===s.version&&u===t.toneMapping||(o.material.needsUpdate=!0,c=s,d=s.version,u=t.toneMapping),o.layers.enableAll(),e.unshift(o,o.geometry,o.material,0,0,null))},dispose:function(){void 0!==l&&(l.geometry.dispose(),l.material.dispose(),l=void 0),void 0!==o&&(o.geometry.dispose(),o.material.dispose(),o=void 0)}}}function Md(t,e){const i=t.getParameter(t.MAX_VERTEX_ATTRIBS),n={},s=h(null);let r=s,a=!1;function o(e){return t.bindVertexArray(e)}function l(e){return t.deleteVertexArray(e)}function h(t){const e=[],n=[],s=[];for(let t=0;t<i;t++)e[t]=0,n[t]=0,s[t]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:e,enabledAttributes:n,attributeDivisors:s,object:t,attributes:{},index:null}}function c(){const t=r.newAttributes;for(let e=0,i=t.length;e<i;e++)t[e]=0}function d(t){u(t,0)}function u(e,i){const n=r.newAttributes,s=r.enabledAttributes,a=r.attributeDivisors;n[e]=1,0===s[e]&&(t.enableVertexAttribArray(e),s[e]=1),a[e]!==i&&(t.vertexAttribDivisor(e,i),a[e]=i)}function p(){const e=r.newAttributes,i=r.enabledAttributes;for(let n=0,s=i.length;n<s;n++)i[n]!==e[n]&&(t.disableVertexAttribArray(n),i[n]=0)}function m(e,i,n,s,r,a,o){!0===o?t.vertexAttribIPointer(e,i,n,r,a):t.vertexAttribPointer(e,i,n,s,r,a)}function f(){g(),a=!0,r!==s&&(r=s,o(r.object))}function g(){s.geometry=null,s.program=null,s.wireframe=!1}return{setup:function(i,s,l,f,g){let v=!1;const y=function(e,i,s,r){const a=!0===r.wireframe;let o=n[i.id];void 0===o&&(o={},n[i.id]=o);const l=!0===e.isInstancedMesh?e.id:0;let c=o[l];void 0===c&&(c={},o[l]=c);let d=c[s.id];void 0===d&&(d={},c[s.id]=d);let u=d[a];void 0===u&&(u=h(t.createVertexArray()),d[a]=u);return u}(i,f,l,s);r!==y&&(r=y,o(r.object)),v=function(t,e,i,n){const s=r.attributes,a=e.attributes;let o=0;const l=i.getAttributes();for(const e in l){if(l[e].location>=0){const i=s[e];let n=a[e];if(void 0===n&&("instanceMatrix"===e&&t.instanceMatrix&&(n=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(n=t.instanceColor)),void 0===i)return!0;if(i.attribute!==n)return!0;if(n&&i.data!==n.data)return!0;o++}}return r.attributesNum!==o||r.index!==n}(i,f,l,g),v&&function(t,e,i,n){const s={},a=e.attributes;let o=0;const l=i.getAttributes();for(const e in l){if(l[e].location>=0){let i=a[e];void 0===i&&("instanceMatrix"===e&&t.instanceMatrix&&(i=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(i=t.instanceColor));const n={};n.attribute=i,i&&i.data&&(n.data=i.data),s[e]=n,o++}}r.attributes=s,r.attributesNum=o,r.index=n}(i,f,l,g),null!==g&&e.update(g,t.ELEMENT_ARRAY_BUFFER),(v||a)&&(a=!1,function(i,n,s,r){c();const a=r.attributes,o=s.getAttributes(),l=n.defaultAttributeValues;for(const n in o){const s=o[n];if(s.location>=0){let o=a[n];if(void 0===o&&("instanceMatrix"===n&&i.instanceMatrix&&(o=i.instanceMatrix),"instanceColor"===n&&i.instanceColor&&(o=i.instanceColor)),void 0!==o){const n=o.normalized,a=o.itemSize,l=e.get(o);if(void 0===l)continue;const h=l.buffer,c=l.type,p=l.bytesPerElement,f=c===t.INT||c===t.UNSIGNED_INT||o.gpuType===ut;if(o.isInterleavedBufferAttribute){const e=o.data,l=e.stride,g=o.offset;if(e.isInstancedInterleavedBuffer){for(let t=0;t<s.locationSize;t++)u(s.location+t,e.meshPerAttribute);!0!==i.isInstancedMesh&&void 0===r._maxInstanceCount&&(r._maxInstanceCount=e.meshPerAttribute*e.count)}else for(let t=0;t<s.locationSize;t++)d(s.location+t);t.bindBuffer(t.ARRAY_BUFFER,h);for(let t=0;t<s.locationSize;t++)m(s.location+t,a/s.locationSize,c,n,l*p,(g+a/s.locationSize*t)*p,f)}else{if(o.isInstancedBufferAttribute){for(let t=0;t<s.locationSize;t++)u(s.location+t,o.meshPerAttribute);!0!==i.isInstancedMesh&&void 0===r._maxInstanceCount&&(r._maxInstanceCount=o.meshPerAttribute*o.count)}else for(let t=0;t<s.locationSize;t++)d(s.location+t);t.bindBuffer(t.ARRAY_BUFFER,h);for(let t=0;t<s.locationSize;t++)m(s.location+t,a/s.locationSize,c,n,a*p,a/s.locationSize*t*p,f)}}else if(void 0!==l){const e=l[n];if(void 0!==e)switch(e.length){case 2:t.vertexAttrib2fv(s.location,e);break;case 3:t.vertexAttrib3fv(s.location,e);break;case 4:t.vertexAttrib4fv(s.location,e);break;default:t.vertexAttrib1fv(s.location,e)}}}}p()}(i,s,l,f),null!==g&&t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,e.get(g).buffer))},reset:f,resetDefaultState:g,dispose:function(){f();for(const t in n){const e=n[t];for(const t in e){const i=e[t];for(const t in i){const e=i[t];for(const t in e)l(e[t].object),delete e[t];delete i[t]}}delete n[t]}},releaseStatesOfGeometry:function(t){if(void 0===n[t.id])return;const e=n[t.id];for(const t in e){const i=e[t];for(const t in i){const e=i[t];for(const t in e)l(e[t].object),delete e[t];delete i[t]}}delete n[t.id]},releaseStatesOfObject:function(t){for(const e in n){const i=n[e],s=!0===t.isInstancedMesh?t.id:0,r=i[s];if(void 0!==r){for(const t in r){const e=r[t];for(const t in e)l(e[t].object),delete e[t];delete r[t]}delete i[s],0===Object.keys(i).length&&delete n[e]}}},releaseStatesOfProgram:function(t){for(const e in n){const i=n[e];for(const e in i){const n=i[e];if(void 0===n[t.id])continue;const s=n[t.id];for(const t in s)l(s[t].object),delete s[t];delete n[t.id]}}},initAttributes:c,enableAttribute:d,disableUnusedAttributes:p}}function wd(t,e,i){let n;function s(e,s,r){0!==r&&(t.drawArraysInstanced(n,e,s,r),i.update(s,n,r))}this.setMode=function(t){n=t},this.render=function(e,s){t.drawArrays(n,e,s),i.update(s,n,1)},this.renderInstances=s,this.renderMultiDraw=function(t,s,r){if(0===r)return;e.get("WEBGL_multi_draw").multiDrawArraysWEBGL(n,t,0,s,0,r);let a=0;for(let t=0;t<r;t++)a+=s[t];i.update(a,n,1)},this.renderMultiDrawInstances=function(t,r,a,o){if(0===a)return;const l=e.get("WEBGL_multi_draw");if(null===l)for(let e=0;e<t.length;e++)s(t[e],r[e],o[e]);else{l.multiDrawArraysInstancedWEBGL(n,t,0,r,0,o,0,a);let e=0;for(let t=0;t<a;t++)e+=r[t]*o[t];i.update(e,n,1)}}}function Ad(t,e,i,n){let s;function r(e){if("highp"===e){if(t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.HIGH_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT).precision>0)return"highp";e="mediump"}return"mediump"===e&&t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.MEDIUM_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let a=void 0!==i.precision?i.precision:"highp";const o=r(a);o!==a&&(ii("WebGLRenderer:",a,"not supported, using",o,"instead."),a=o);return{isWebGL2:!0,getMaxAnisotropy:function(){if(void 0!==s)return s;if(!0===e.has("EXT_texture_filter_anisotropic")){const i=e.get("EXT_texture_filter_anisotropic");s=t.getParameter(i.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else s=0;return s},getMaxPrecision:r,textureFormatReadable:function(e){return e===Mt||n.convert(e)===t.getParameter(t.IMPLEMENTATION_COLOR_READ_FORMAT)},textureTypeReadable:function(i){const s=i===ft&&(e.has("EXT_color_buffer_half_float")||e.has("EXT_color_buffer_float"));return!(i!==lt&&n.convert(i)!==t.getParameter(t.IMPLEMENTATION_COLOR_READ_TYPE)&&i!==mt&&!s)},precision:a,logarithmicDepthBuffer:!0===i.logarithmicDepthBuffer,reversedDepthBuffer:!0===i.reversedDepthBuffer&&e.has("EXT_clip_control"),maxTextures:t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),maxVertexTextures:t.getParameter(t.MAX_VERTEX_TEXTURE_IMAGE_UNITS),maxTextureSize:t.getParameter(t.MAX_TEXTURE_SIZE),maxCubemapSize:t.getParameter(t.MAX_CUBE_MAP_TEXTURE_SIZE),maxAttributes:t.getParameter(t.MAX_VERTEX_ATTRIBS),maxVertexUniforms:t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS),maxVaryings:t.getParameter(t.MAX_VARYING_VECTORS),maxFragmentUniforms:t.getParameter(t.MAX_FRAGMENT_UNIFORM_VECTORS),maxSamples:t.getParameter(t.MAX_SAMPLES),samples:t.getParameter(t.SAMPLES)}}function Ed(t){const e=this;let i=null,n=0,s=!1,r=!1;const a=new qr,o=new Mi,l={value:null,needsUpdate:!1};function h(t,i,n,s){const r=null!==t?t.length:0;let h=null;if(0!==r){if(h=l.value,!0!==s||null===h){const e=n+4*r,s=i.matrixWorldInverse;o.getNormalMatrix(s),(null===h||h.length<e)&&(h=new Float32Array(e));for(let e=0,i=n;e!==r;++e,i+=4)a.copy(t[e]).applyMatrix4(s,o),a.normal.toArray(h,i),h[i+3]=a.constant}l.value=h,l.needsUpdate=!0}return e.numPlanes=r,e.numIntersection=0,h}this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(t,e){const i=0!==t.length||e||0!==n||s;return s=e,n=t.length,i},this.beginShadows=function(){r=!0,h(null)},this.endShadows=function(){r=!1},this.setGlobalState=function(t,e){i=h(t,e,0)},this.setState=function(a,o,c){const d=a.clippingPlanes,u=a.clipIntersection,p=a.clipShadows,m=t.get(a);if(!s||null===d||0===d.length||r&&!p)r?h(null):function(){l.value!==i&&(l.value=i,l.needsUpdate=n>0);e.numPlanes=n,e.numIntersection=0}();else{const t=r?0:n,e=4*t;let s=m.clippingState||null;l.value=s,s=h(d,o,e,c);for(let t=0;t!==e;++t)s[t]=i[t];m.clippingState=s,this.numIntersection=u?this.numPlanes:0,this.numPlanes+=t}}}const Td=[.125,.215,.35,.446,.526,.582],Cd=20,Dd=new Fh,Rd=new En;let Pd=null,Id=0,Ld=0,Bd=!1;const Od=new xi;class Fd{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._backgroundBox=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._blurMaterial=null,this._ggxMaterial=null}fromScene(t,e=0,i=.1,n=100,s={}){const{size:r=256,position:a=Od}=s;Pd=this._renderer.getRenderTarget(),Id=this._renderer.getActiveCubeFace(),Ld=this._renderer.getActiveMipmapLevel(),Bd=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(r);const o=this._allocateTargets();return o.depthBuffer=!0,this._sceneToCubeUV(t,i,n,o,a),e>0&&this._blur(o,0,0,e),this._applyPMREM(o),this._cleanup(o),o}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=zd(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=kd(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._ggxMaterial&&this._ggxMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let t=0;t<this._lodMeshes.length;t++)this._lodMeshes[t].geometry.dispose()}_cleanup(t){this._renderer.setRenderTarget(Pd,Id,Ld),this._renderer.xr.enabled=Bd,t.scissorTest=!1,Ud(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===Z||t.mapping===q?this._setSize(0===t.image.length?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),Pd=this._renderer.getRenderTarget(),Id=this._renderer.getActiveCubeFace(),Ld=this._renderer.getActiveMipmapLevel(),Bd=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;const i=e||this._allocateTargets();return this._textureToCubeUV(t,i),this._applyPMREM(i),this._cleanup(i),i}_allocateTargets(){const t=3*Math.max(this._cubeSize,112),e=4*this._cubeSize,i={magFilter:rt,minFilter:rt,generateMipmaps:!1,type:ft,format:Mt,colorSpace:Te,depthBuffer:!1},n=Nd(t,e,i);if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=Nd(t,e,i);const{_lodMax:n}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=function(t){const e=[],i=[],n=[];let s=t;const r=t-4+1+Td.length;for(let a=0;a<r;a++){const r=Math.pow(2,s);e.push(r);let o=1/r;a>t-4?o=Td[a-t+4-1]:0===a&&(o=0),i.push(o);const l=1/(r-2),h=-l,c=1+l,d=[h,h,c,h,c,c,h,h,c,c,h,c],u=6,p=6,m=3,f=2,g=1,v=new Float32Array(m*p*u),y=new Float32Array(f*p*u),_=new Float32Array(g*p*u);for(let t=0;t<u;t++){const e=t%3*2/3-1,i=t>2?0:-1,n=[e,i,0,e+2/3,i,0,e+2/3,i+1,0,e,i,0,e+2/3,i+1,0,e,i+1,0];v.set(n,m*p*t),y.set(d,f*p*t);const s=[t,t,t,t,t,t];_.set(s,g*p*t)}const x=new Ds;x.setAttribute("position",new ms(v,m)),x.setAttribute("uv",new ms(y,f)),x.setAttribute("faceIndex",new ms(_,g)),n.push(new xr(x,null)),s>4&&s--}return{lodMeshes:n,sizeLods:e,sigmas:i}}(n)),this._blurMaterial=function(t,e,i){const n=new Float32Array(Cd),s=new xi(0,1,0),r=new Dl({name:"SphericalGaussianBlur",defines:{n:Cd,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/i,CUBEUV_MAX_MIP:`${t}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:n},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:s}},vertexShader:Gd(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform int samples;\n\t\t\tuniform float weights[ n ];\n\t\t\tuniform bool latitudinal;\n\t\t\tuniform float dTheta;\n\t\t\tuniform float mipInt;\n\t\t\tuniform vec3 poleAxis;\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include <cube_uv_reflection_fragment>\n\n\t\t\tvec3 getSample( float theta, vec3 axis ) {\n\n\t\t\t\tfloat cosTheta = cos( theta );\n\t\t\t\t// Rodrigues' axis-angle rotation\n\t\t\t\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t\t\t\t+ cross( axis, vOutputDirection ) * sin( theta )\n\t\t\t\t\t+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );\n\n\t\t\t\treturn bilinearCubeUV( envMap, sampleDirection, mipInt );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );\n\n\t\t\t\tif ( all( equal( axis, vec3( 0.0 ) ) ) ) {\n\n\t\t\t\t\taxis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );\n\n\t\t\t\t}\n\n\t\t\t\taxis = normalize( axis );\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );\n\n\t\t\t\tfor ( int i = 1; i < n; i++ ) {\n\n\t\t\t\t\tif ( i >= samples ) {\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t}\n\n\t\t\t\t\tfloat theta = dTheta * float( i );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( theta, axis );\n\n\t\t\t\t}\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1});return r}(n,t,e),this._ggxMaterial=function(t,e,i){const n=new Dl({name:"PMREMGGXConvolution",defines:{GGX_SAMPLES:256,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/i,CUBEUV_MAX_MIP:`${t}.0`},uniforms:{envMap:{value:null},roughness:{value:0},mipInt:{value:0}},vertexShader:Gd(),fragmentShader:'\n\n\t\t\tprecision highp float;\n\t\t\tprecision highp int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform float roughness;\n\t\t\tuniform float mipInt;\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include <cube_uv_reflection_fragment>\n\n\t\t\t#define PI 3.14159265359\n\n\t\t\t// Van der Corput radical inverse\n\t\t\tfloat radicalInverse_VdC(uint bits) {\n\t\t\t\tbits = (bits << 16u) | (bits >> 16u);\n\t\t\t\tbits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);\n\t\t\t\tbits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);\n\t\t\t\tbits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);\n\t\t\t\tbits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);\n\t\t\t\treturn float(bits) * 2.3283064365386963e-10; // / 0x100000000\n\t\t\t}\n\n\t\t\t// Hammersley sequence\n\t\t\tvec2 hammersley(uint i, uint N) {\n\t\t\t\treturn vec2(float(i) / float(N), radicalInverse_VdC(i));\n\t\t\t}\n\n\t\t\t// GGX VNDF importance sampling (Eric Heitz 2018)\n\t\t\t// "Sampling the GGX Distribution of Visible Normals"\n\t\t\t// https://jcgt.org/published/0007/04/01/\n\t\t\tvec3 importanceSampleGGX_VNDF(vec2 Xi, vec3 V, float roughness) {\n\t\t\t\tfloat alpha = roughness * roughness;\n\n\t\t\t\t// Section 4.1: Orthonormal basis\n\t\t\t\tvec3 T1 = vec3(1.0, 0.0, 0.0);\n\t\t\t\tvec3 T2 = cross(V, T1);\n\n\t\t\t\t// Section 4.2: Parameterization of projected area\n\t\t\t\tfloat r = sqrt(Xi.x);\n\t\t\t\tfloat phi = 2.0 * PI * Xi.y;\n\t\t\t\tfloat t1 = r * cos(phi);\n\t\t\t\tfloat t2 = r * sin(phi);\n\t\t\t\tfloat s = 0.5 * (1.0 + V.z);\n\t\t\t\tt2 = (1.0 - s) * sqrt(1.0 - t1 * t1) + s * t2;\n\n\t\t\t\t// Section 4.3: Reprojection onto hemisphere\n\t\t\t\tvec3 Nh = t1 * T1 + t2 * T2 + sqrt(max(0.0, 1.0 - t1 * t1 - t2 * t2)) * V;\n\n\t\t\t\t// Section 3.4: Transform back to ellipsoid configuration\n\t\t\t\treturn normalize(vec3(alpha * Nh.x, alpha * Nh.y, max(0.0, Nh.z)));\n\t\t\t}\n\n\t\t\tvoid main() {\n\t\t\t\tvec3 N = normalize(vOutputDirection);\n\t\t\t\tvec3 V = N; // Assume view direction equals normal for pre-filtering\n\n\t\t\t\tvec3 prefilteredColor = vec3(0.0);\n\t\t\t\tfloat totalWeight = 0.0;\n\n\t\t\t\t// For very low roughness, just sample the environment directly\n\t\t\t\tif (roughness < 0.001) {\n\t\t\t\t\tgl_FragColor = vec4(bilinearCubeUV(envMap, N, mipInt), 1.0);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Tangent space basis for VNDF sampling\n\t\t\t\tvec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\n\t\t\t\tvec3 tangent = normalize(cross(up, N));\n\t\t\t\tvec3 bitangent = cross(N, tangent);\n\n\t\t\t\tfor(uint i = 0u; i < uint(GGX_SAMPLES); i++) {\n\t\t\t\t\tvec2 Xi = hammersley(i, uint(GGX_SAMPLES));\n\n\t\t\t\t\t// For PMREM, V = N, so in tangent space V is always (0, 0, 1)\n\t\t\t\t\tvec3 H_tangent = importanceSampleGGX_VNDF(Xi, vec3(0.0, 0.0, 1.0), roughness);\n\n\t\t\t\t\t// Transform H back to world space\n\t\t\t\t\tvec3 H = normalize(tangent * H_tangent.x + bitangent * H_tangent.y + N * H_tangent.z);\n\t\t\t\t\tvec3 L = normalize(2.0 * dot(V, H) * H - V);\n\n\t\t\t\t\tfloat NdotL = max(dot(N, L), 0.0);\n\n\t\t\t\t\tif(NdotL > 0.0) {\n\t\t\t\t\t\t// Sample environment at fixed mip level\n\t\t\t\t\t\t// VNDF importance sampling handles the distribution filtering\n\t\t\t\t\t\tvec3 sampleColor = bilinearCubeUV(envMap, L, mipInt);\n\n\t\t\t\t\t\t// Weight by NdotL for the split-sum approximation\n\t\t\t\t\t\t// VNDF PDF naturally accounts for the visible microfacet distribution\n\t\t\t\t\t\tprefilteredColor += sampleColor * NdotL;\n\t\t\t\t\t\ttotalWeight += NdotL;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (totalWeight > 0.0) {\n\t\t\t\t\tprefilteredColor = prefilteredColor / totalWeight;\n\t\t\t\t}\n\n\t\t\t\tgl_FragColor = vec4(prefilteredColor, 1.0);\n\t\t\t}\n\t\t',blending:0,depthTest:!1,depthWrite:!1});return n}(n,t,e)}return n}_compileMaterial(t){const e=new xr(new Ds,t);this._renderer.compile(e,Dd)}_sceneToCubeUV(t,e,i,n,s){const r=new Ph(90,1,e,i),a=[1,-1,1,1,1,1],o=[1,1,1,-1,-1,-1],l=this._renderer,h=l.autoClear,c=l.toneMapping;l.getClearColor(Rd),l.toneMapping=0,l.autoClear=!1;l.state.buffers.depth.getReversed()&&(l.setRenderTarget(n),l.clearDepth(),l.setRenderTarget(null)),null===this._backgroundBox&&(this._backgroundBox=new xr(new Qa,new lr({name:"PMREM.Background",side:1,depthWrite:!1,depthTest:!1})));const d=this._backgroundBox,u=d.material;let p=!1;const m=t.background;m?m.isColor&&(u.color.copy(m),t.background=null,p=!0):(u.color.copy(Rd),p=!0);for(let e=0;e<6;e++){const i=e%3;0===i?(r.up.set(0,a[e],0),r.position.set(s.x,s.y,s.z),r.lookAt(s.x+o[e],s.y,s.z)):1===i?(r.up.set(0,0,a[e]),r.position.set(s.x,s.y,s.z),r.lookAt(s.x,s.y+o[e],s.z)):(r.up.set(0,a[e],0),r.position.set(s.x,s.y,s.z),r.lookAt(s.x,s.y,s.z+o[e]));const h=this._cubeSize;Ud(n,i*h,e>2?h:0,h,h),l.setRenderTarget(n),p&&l.render(d,r),l.render(t,r)}l.toneMapping=c,l.autoClear=h,t.background=m}_textureToCubeUV(t,e){const i=this._renderer,n=t.mapping===Z||t.mapping===q;n?(null===this._cubemapMaterial&&(this._cubemapMaterial=zd()),this._cubemapMaterial.uniforms.flipEnvMap.value=!1===t.isRenderTargetTexture?-1:1):null===this._equirectMaterial&&(this._equirectMaterial=kd());const s=n?this._cubemapMaterial:this._equirectMaterial,r=this._lodMeshes[0];r.material=s;s.uniforms.envMap.value=t;const a=this._cubeSize;Ud(e,0,0,3*a,2*a),i.setRenderTarget(e),i.render(r,Dd)}_applyPMREM(t){const e=this._renderer,i=e.autoClear;e.autoClear=!1;const n=this._lodMeshes.length;for(let e=1;e<n;e++)this._applyGGXFilter(t,e-1,e);e.autoClear=i}_applyGGXFilter(t,e,i){const n=this._renderer,s=this._pingPongRenderTarget,r=this._ggxMaterial,a=this._lodMeshes[i];a.material=r;const o=r.uniforms,l=i/(this._lodMeshes.length-1),h=e/(this._lodMeshes.length-1),c=Math.sqrt(l*l-h*h)*(0+1.25*l),{_lodMax:d}=this,u=this._sizeLods[i],p=3*u*(i>d-4?i-d+4:0),m=4*(this._cubeSize-u);o.envMap.value=t.texture,o.roughness.value=c,o.mipInt.value=d-e,Ud(s,p,m,3*u,2*u),n.setRenderTarget(s),n.render(a,Dd),o.envMap.value=s.texture,o.roughness.value=0,o.mipInt.value=d-i,Ud(t,p,m,3*u,2*u),n.setRenderTarget(t),n.render(a,Dd)}_blur(t,e,i,n,s){const r=this._pingPongRenderTarget;this._halfBlur(t,r,e,i,n,"latitudinal",s),this._halfBlur(r,t,i,i,n,"longitudinal",s)}_halfBlur(t,e,i,n,s,r,a){const o=this._renderer,l=this._blurMaterial;"latitudinal"!==r&&"longitudinal"!==r&&ni("blur direction must be either latitudinal or longitudinal!");const h=this._lodMeshes[n];h.material=l;const c=l.uniforms,d=this._sizeLods[i]-1,u=isFinite(s)?Math.PI/(2*d):2*Math.PI/39,p=s/u,m=isFinite(s)?1+Math.floor(3*p):Cd;m>Cd&&ii(`sigmaRadians, ${s}, is too large and will clip, as it requested ${m} samples when the maximum is set to 20`);const f=[];let g=0;for(let t=0;t<Cd;++t){const e=t/p,i=Math.exp(-e*e/2);f.push(i),0===t?g+=i:t<m&&(g+=2*i)}for(let t=0;t<f.length;t++)f[t]=f[t]/g;c.envMap.value=t.texture,c.samples.value=m,c.weights.value=f,c.latitudinal.value="latitudinal"===r,a&&(c.poleAxis.value=a);const{_lodMax:v}=this;c.dTheta.value=u,c.mipInt.value=v-i;const y=this._sizeLods[n];Ud(e,3*y*(n>v-4?n-v+4:0),4*(this._cubeSize-y),3*y,2*y),o.setRenderTarget(e),o.render(h,Dd)}}function Nd(t,e,i){const n=new Gi(t,e,i);return n.texture.mapping=J,n.texture.name="PMREM.cubeUv",n.scissorTest=!0,n}function Ud(t,e,i,n,s){t.viewport.set(e,i,n,s),t.scissor.set(e,i,n,s)}function kd(){return new Dl({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:Gd(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\n\t\t\t#include <common>\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 outputDirection = normalize( vOutputDirection );\n\t\t\t\tvec2 uv = equirectUv( outputDirection );\n\n\t\t\t\tgl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1})}function zd(){return new Dl({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:Gd(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tuniform float flipEnvMap;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform samplerCube envMap;\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1})}function Gd(){return"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t"}class Hd extends Gi{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const i={width:t,height:t,depth:1},n=[i,i,i,i,i,i];this.texture=new ja(n),this._setTextureOptions(e),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const i={uniforms:{tEquirect:{value:null}},vertexShader:"\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include <begin_vertex>\n\t\t\t\t\t#include <project_vertex>\n\n\t\t\t\t}\n\t\t\t",fragmentShader:"\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include <common>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t"},n=new Qa(5,5,5),s=new Dl({name:"CubemapFromEquirect",uniforms:Al(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:1,blending:0});s.uniforms.tEquirect.value=e;const r=new xr(n,s),a=e.minFilter;e.minFilter===ot&&(e.minFilter=rt);return new nc(1,10,this).update(t,r),e.minFilter=a,r.geometry.dispose(),r.material.dispose(),this}clear(t,e=!0,i=!0,n=!0){const s=t.getRenderTarget();for(let s=0;s<6;s++)t.setRenderTarget(this,s),t.clear(e,i,n);t.setRenderTarget(s)}}function Vd(t){let e=new WeakMap,i=new WeakMap,n=null;function s(t,e){return e===Q?t.mapping=Z:e===K&&(t.mapping=q),t}function r(t){const i=t.target;i.removeEventListener("dispose",r);const n=e.get(i);void 0!==n&&(e.delete(i),n.dispose())}function a(t){const e=t.target;e.removeEventListener("dispose",a);const n=i.get(e);void 0!==n&&(i.delete(e),n.dispose())}return{get:function(o,l=!1){return null==o?null:l?function(e){if(e&&e.isTexture){const s=e.mapping,r=s===Q||s===K,o=s===Z||s===q;if(r||o){let s=i.get(e);const l=void 0!==s?s.texture.pmremVersion:0;if(e.isRenderTargetTexture&&e.pmremVersion!==l)return null===n&&(n=new Fd(t)),s=r?n.fromEquirectangular(e,s):n.fromCubemap(e,s),s.texture.pmremVersion=e.pmremVersion,i.set(e,s),s.texture;if(void 0!==s)return s.texture;{const l=e.image;return r&&l&&l.height>0||o&&l&&function(t){let e=0;const i=6;for(let n=0;n<i;n++)void 0!==t[n]&&e++;return e===i}(l)?(null===n&&(n=new Fd(t)),s=r?n.fromEquirectangular(e):n.fromCubemap(e),s.texture.pmremVersion=e.pmremVersion,i.set(e,s),e.addEventListener("dispose",a),s.texture):null}}}return e}(o):function(i){if(i&&i.isTexture){const n=i.mapping;if(n===Q||n===K){if(e.has(i)){return s(e.get(i).texture,i.mapping)}{const n=i.image;if(n&&n.height>0){const a=new Hd(n.height);return a.fromEquirectangularTexture(t,i),e.set(i,a),i.addEventListener("dispose",r),s(a.texture,i.mapping)}return null}}}return i}(o)},dispose:function(){e=new WeakMap,i=new WeakMap,null!==n&&(n.dispose(),n=null)}}}function Wd(t){const e={};function i(i){if(void 0!==e[i])return e[i];const n=t.getExtension(i);return e[i]=n,n}return{has:function(t){return null!==i(t)},init:function(){i("EXT_color_buffer_float"),i("WEBGL_clip_cull_distance"),i("OES_texture_float_linear"),i("EXT_color_buffer_half_float"),i("WEBGL_multisampled_render_to_texture"),i("WEBGL_render_shared_exponent")},get:function(t){const e=i(t);return null===e&&si("WebGLRenderer: "+t+" extension not supported."),e}}}function jd(t,e,i,n){const s={},r=new WeakMap;function a(t){const o=t.target;null!==o.index&&e.remove(o.index);for(const t in o.attributes)e.remove(o.attributes[t]);o.removeEventListener("dispose",a),delete s[o.id];const l=r.get(o);l&&(e.remove(l),r.delete(o)),n.releaseStatesOfGeometry(o),!0===o.isInstancedBufferGeometry&&delete o._maxInstanceCount,i.memory.geometries--}function o(t){const i=[],n=t.index,s=t.attributes.position;let a=0;if(void 0===s)return;if(null!==n){const t=n.array;a=n.version;for(let e=0,n=t.length;e<n;e+=3){const n=t[e+0],s=t[e+1],r=t[e+2];i.push(n,s,s,r,r,n)}}else{const t=s.array;a=s.version;for(let e=0,n=t.length/3-1;e<n;e+=3){const t=e+0,n=e+1,s=e+2;i.push(t,n,n,s,s,t)}}const o=new(s.count>=65535?gs:fs)(i,1);o.version=a;const l=r.get(t);l&&e.remove(l),r.set(t,o)}return{get:function(t,e){return!0===s[e.id]||(e.addEventListener("dispose",a),s[e.id]=!0,i.memory.geometries++),e},update:function(i){const n=i.attributes;for(const i in n)e.update(n[i],t.ARRAY_BUFFER)},getWireframeAttribute:function(t){const e=r.get(t);if(e){const i=t.index;null!==i&&e.version<i.version&&o(t)}else o(t);return r.get(t)}}}function Xd(t,e,i){let n,s,r;function a(e,a,o){0!==o&&(t.drawElementsInstanced(n,a,s,e*r,o),i.update(a,n,o))}this.setMode=function(t){n=t},this.setIndex=function(t){s=t.type,r=t.bytesPerElement},this.render=function(e,a){t.drawElements(n,a,s,e*r),i.update(a,n,1)},this.renderInstances=a,this.renderMultiDraw=function(t,r,a){if(0===a)return;e.get("WEBGL_multi_draw").multiDrawElementsWEBGL(n,r,0,s,t,0,a);let o=0;for(let t=0;t<a;t++)o+=r[t];i.update(o,n,1)},this.renderMultiDrawInstances=function(t,o,l,h){if(0===l)return;const c=e.get("WEBGL_multi_draw");if(null===c)for(let e=0;e<t.length;e++)a(t[e]/r,o[e],h[e]);else{c.multiDrawElementsInstancedWEBGL(n,o,0,s,t,0,h,0,l);let e=0;for(let t=0;t<l;t++)e+=o[t]*h[t];i.update(e,n,1)}}}function Yd(t){const e={frame:0,calls:0,triangles:0,points:0,lines:0};return{memory:{geometries:0,textures:0},render:e,programs:null,autoReset:!0,reset:function(){e.calls=0,e.triangles=0,e.points=0,e.lines=0},update:function(i,n,s){switch(e.calls++,n){case t.TRIANGLES:e.triangles+=s*(i/3);break;case t.LINES:e.lines+=s*(i/2);break;case t.LINE_STRIP:e.lines+=s*(i-1);break;case t.LINE_LOOP:e.lines+=s*i;break;case t.POINTS:e.points+=s*i;break;default:ni("WebGLInfo: Unknown draw mode:",n)}}}}function Zd(t,e,i){const n=new WeakMap,s=new ki;return{update:function(r,a,o){const l=r.morphTargetInfluences,h=a.morphAttributes.position||a.morphAttributes.normal||a.morphAttributes.color,c=void 0!==h?h.length:0;let d=n.get(a);if(void 0===d||d.count!==c){void 0!==d&&d.texture.dispose();const u=void 0!==a.morphAttributes.position,p=void 0!==a.morphAttributes.normal,m=void 0!==a.morphAttributes.color,f=a.morphAttributes.position||[],g=a.morphAttributes.normal||[],v=a.morphAttributes.color||[];let y=0;!0===u&&(y=1),!0===p&&(y=2),!0===m&&(y=3);let _=a.attributes.position.count*y,x=1;_>e.maxTextureSize&&(x=Math.ceil(_/e.maxTextureSize),_=e.maxTextureSize);const b=new Float32Array(_*x*4*c),S=new Hi(b,_,x,c);S.type=mt,S.needsUpdate=!0;const M=4*y;for(let A=0;A<c;A++){const E=f[A],T=g[A],C=v[A],D=_*x*4*A;for(let R=0;R<E.count;R++){const P=R*M;!0===u&&(s.fromBufferAttribute(E,R),b[D+P+0]=s.x,b[D+P+1]=s.y,b[D+P+2]=s.z,b[D+P+3]=0),!0===p&&(s.fromBufferAttribute(T,R),b[D+P+4]=s.x,b[D+P+5]=s.y,b[D+P+6]=s.z,b[D+P+7]=0),!0===m&&(s.fromBufferAttribute(C,R),b[D+P+8]=s.x,b[D+P+9]=s.y,b[D+P+10]=s.z,b[D+P+11]=4===C.itemSize?s.w:1)}}function w(){S.dispose(),n.delete(a),a.removeEventListener("dispose",w)}d={count:c,texture:S,size:new yi(_,x)},n.set(a,d),a.addEventListener("dispose",w)}if(!0===r.isInstancedMesh&&null!==r.morphTexture)o.getUniforms().setValue(t,"morphTexture",r.morphTexture,i);else{let I=0;for(let B=0;B<l.length;B++)I+=l[B];const L=a.morphTargetsRelative?1:1-I;o.getUniforms().setValue(t,"morphTargetBaseInfluence",L),o.getUniforms().setValue(t,"morphTargetInfluences",l)}o.getUniforms().setValue(t,"morphTargetsTexture",d.texture,i),o.getUniforms().setValue(t,"morphTargetsTextureSize",d.size)}}}function qd(t,e,i,n,s){let r=new WeakMap;function a(t){const e=t.target;e.removeEventListener("dispose",a),n.releaseStatesOfObject(e),i.remove(e.instanceMatrix),null!==e.instanceColor&&i.remove(e.instanceColor)}return{update:function(n){const o=s.render.frame,l=n.geometry,h=e.get(n,l);if(r.get(h)!==o&&(e.update(h),r.set(h,o)),n.isInstancedMesh&&(!1===n.hasEventListener("dispose",a)&&n.addEventListener("dispose",a),r.get(n)!==o&&(i.update(n.instanceMatrix,t.ARRAY_BUFFER),null!==n.instanceColor&&i.update(n.instanceColor,t.ARRAY_BUFFER),r.set(n,o))),n.isSkinnedMesh){const t=n.skeleton;r.get(t)!==o&&(t.update(),r.set(t,o))}return h},dispose:function(){r=new WeakMap}}}const Qd={[U]:"LINEAR_TONE_MAPPING",[k]:"REINHARD_TONE_MAPPING",[z]:"CINEON_TONE_MAPPING",[G]:"ACES_FILMIC_TONE_MAPPING",[V]:"AGX_TONE_MAPPING",[W]:"NEUTRAL_TONE_MAPPING",[H]:"CUSTOM_TONE_MAPPING"};function Kd(t,e,i,n,s){const r=new Gi(e,i,{type:t,depthBuffer:n,stencilBuffer:s}),a=new Gi(e,i,{type:ft,depthBuffer:!1,stencilBuffer:!1}),o=new Ds;o.setAttribute("position",new vs([-1,3,0,-1,-1,0,3,-1,0],3)),o.setAttribute("uv",new vs([0,2,0,0,2,0],2));const l=new Rl({uniforms:{tDiffuse:{value:null}},vertexShader:"\n\t\t\tprecision highp float;\n\n\t\t\tuniform mat4 modelViewMatrix;\n\t\t\tuniform mat4 projectionMatrix;\n\n\t\t\tattribute vec3 position;\n\t\t\tattribute vec2 uv;\n\n\t\t\tvarying vec2 vUv;\n\n\t\t\tvoid main() {\n\t\t\t\tvUv = uv;\n\t\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\t\t\t}",fragmentShader:"\n\t\t\tprecision highp float;\n\n\t\t\tuniform sampler2D tDiffuse;\n\n\t\t\tvarying vec2 vUv;\n\n\t\t\t#include <tonemapping_pars_fragment>\n\t\t\t#include <colorspace_pars_fragment>\n\n\t\t\tvoid main() {\n\t\t\t\tgl_FragColor = texture2D( tDiffuse, vUv );\n\n\t\t\t\t#ifdef LINEAR_TONE_MAPPING\n\t\t\t\t\tgl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );\n\t\t\t\t#elif defined( REINHARD_TONE_MAPPING )\n\t\t\t\t\tgl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );\n\t\t\t\t#elif defined( CINEON_TONE_MAPPING )\n\t\t\t\t\tgl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );\n\t\t\t\t#elif defined( ACES_FILMIC_TONE_MAPPING )\n\t\t\t\t\tgl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );\n\t\t\t\t#elif defined( AGX_TONE_MAPPING )\n\t\t\t\t\tgl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );\n\t\t\t\t#elif defined( NEUTRAL_TONE_MAPPING )\n\t\t\t\t\tgl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );\n\t\t\t\t#elif defined( CUSTOM_TONE_MAPPING )\n\t\t\t\t\tgl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef SRGB_TRANSFER\n\t\t\t\t\tgl_FragColor = sRGBTransferOETF( gl_FragColor );\n\t\t\t\t#endif\n\t\t\t}",depthTest:!1,depthWrite:!1}),h=new xr(o,l),c=new Fh(-1,1,1,-1,0,1);let d,u=null,p=null,m=!1,f=null,g=[],v=!1;this.setSize=function(t,e){r.setSize(t,e),a.setSize(t,e);for(let i=0;i<g.length;i++){const n=g[i];n.setSize&&n.setSize(t,e)}},this.setEffects=function(t){g=t,v=g.length>0&&!0===g[0].isRenderPass;const e=r.width,i=r.height;for(let t=0;t<g.length;t++){const n=g[t];n.setSize&&n.setSize(e,i)}},this.begin=function(t,e){if(m)return!1;if(0===t.toneMapping&&0===g.length)return!1;if(f=e,null!==e){const t=e.width,i=e.height;r.width===t&&r.height===i||this.setSize(t,i)}return!1===v&&t.setRenderTarget(r),d=t.toneMapping,t.toneMapping=0,!0},this.hasRenderPass=function(){return v},this.end=function(t,e){t.toneMapping=d,m=!0;let i=r,n=a;for(let s=0;s<g.length;s++){const r=g[s];if(!1!==r.enabled&&(r.render(t,n,i,e),!1!==r.needsSwap)){const t=i;i=n,n=t}}if(u!==t.outputColorSpace||p!==t.toneMapping){u=t.outputColorSpace,p=t.toneMapping,l.defines={},Ci.getTransfer(u)===De&&(l.defines.SRGB_TRANSFER="");const e=Qd[p];e&&(l.defines[e]=""),l.needsUpdate=!0}l.uniforms.tDiffuse.value=i.texture,t.setRenderTarget(f),t.render(h,c),f=null,m=!1},this.isCompositing=function(){return m},this.dispose=function(){r.dispose(),a.dispose(),o.dispose(),l.dispose()}}const Jd=new Ui,$d=new Ya(1,1),tu=new Hi,eu=new Vi,iu=new ja,nu=[],su=[],ru=new Float32Array(16),au=new Float32Array(9),ou=new Float32Array(4);function lu(t,e,i){const n=t[0];if(n<=0||n>0)return t;const s=e*i;let r=nu[s];if(void 0===r&&(r=new Float32Array(s),nu[s]=r),0!==e){n.toArray(r,0);for(let n=1,s=0;n!==e;++n)s+=i,t[n].toArray(r,s)}return r}function hu(t,e){if(t.length!==e.length)return!1;for(let i=0,n=t.length;i<n;i++)if(t[i]!==e[i])return!1;return!0}function cu(t,e){for(let i=0,n=e.length;i<n;i++)t[i]=e[i]}function du(t,e){let i=su[e];void 0===i&&(i=new Int32Array(e),su[e]=i);for(let n=0;n!==e;++n)i[n]=t.allocateTextureUnit();return i}function uu(t,e){const i=this.cache;i[0]!==e&&(t.uniform1f(this.addr,e),i[0]=e)}function pu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2f(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(hu(i,e))return;t.uniform2fv(this.addr,e),cu(i,e)}}function mu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3f(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else if(void 0!==e.r)i[0]===e.r&&i[1]===e.g&&i[2]===e.b||(t.uniform3f(this.addr,e.r,e.g,e.b),i[0]=e.r,i[1]=e.g,i[2]=e.b);else{if(hu(i,e))return;t.uniform3fv(this.addr,e),cu(i,e)}}function fu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4f(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(hu(i,e))return;t.uniform4fv(this.addr,e),cu(i,e)}}function gu(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(hu(i,e))return;t.uniformMatrix2fv(this.addr,!1,e),cu(i,e)}else{if(hu(i,n))return;ou.set(n),t.uniformMatrix2fv(this.addr,!1,ou),cu(i,n)}}function vu(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(hu(i,e))return;t.uniformMatrix3fv(this.addr,!1,e),cu(i,e)}else{if(hu(i,n))return;au.set(n),t.uniformMatrix3fv(this.addr,!1,au),cu(i,n)}}function yu(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(hu(i,e))return;t.uniformMatrix4fv(this.addr,!1,e),cu(i,e)}else{if(hu(i,n))return;ru.set(n),t.uniformMatrix4fv(this.addr,!1,ru),cu(i,n)}}function _u(t,e){const i=this.cache;i[0]!==e&&(t.uniform1i(this.addr,e),i[0]=e)}function xu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2i(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(hu(i,e))return;t.uniform2iv(this.addr,e),cu(i,e)}}function bu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3i(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else{if(hu(i,e))return;t.uniform3iv(this.addr,e),cu(i,e)}}function Su(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4i(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(hu(i,e))return;t.uniform4iv(this.addr,e),cu(i,e)}}function Mu(t,e){const i=this.cache;i[0]!==e&&(t.uniform1ui(this.addr,e),i[0]=e)}function wu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2ui(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(hu(i,e))return;t.uniform2uiv(this.addr,e),cu(i,e)}}function Au(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3ui(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else{if(hu(i,e))return;t.uniform3uiv(this.addr,e),cu(i,e)}}function Eu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4ui(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(hu(i,e))return;t.uniform4uiv(this.addr,e),cu(i,e)}}function Tu(t,e,i){const n=this.cache,s=i.allocateTextureUnit();let r;n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),this.type===t.SAMPLER_2D_SHADOW?($d.compareFunction=i.isReversedDepthBuffer()?Ge:Ue,r=$d):r=Jd,i.setTexture2D(e||r,s)}function Cu(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.setTexture3D(e||eu,s)}function Du(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.setTextureCube(e||iu,s)}function Ru(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.setTexture2DArray(e||tu,s)}function Pu(t,e){t.uniform1fv(this.addr,e)}function Iu(t,e){const i=lu(e,this.size,2);t.uniform2fv(this.addr,i)}function Lu(t,e){const i=lu(e,this.size,3);t.uniform3fv(this.addr,i)}function Bu(t,e){const i=lu(e,this.size,4);t.uniform4fv(this.addr,i)}function Ou(t,e){const i=lu(e,this.size,4);t.uniformMatrix2fv(this.addr,!1,i)}function Fu(t,e){const i=lu(e,this.size,9);t.uniformMatrix3fv(this.addr,!1,i)}function Nu(t,e){const i=lu(e,this.size,16);t.uniformMatrix4fv(this.addr,!1,i)}function Uu(t,e){t.uniform1iv(this.addr,e)}function ku(t,e){t.uniform2iv(this.addr,e)}function zu(t,e){t.uniform3iv(this.addr,e)}function Gu(t,e){t.uniform4iv(this.addr,e)}function Hu(t,e){t.uniform1uiv(this.addr,e)}function Vu(t,e){t.uniform2uiv(this.addr,e)}function Wu(t,e){t.uniform3uiv(this.addr,e)}function ju(t,e){t.uniform4uiv(this.addr,e)}function Xu(t,e,i){const n=this.cache,s=e.length,r=du(i,s);let a;hu(n,r)||(t.uniform1iv(this.addr,r),cu(n,r)),a=this.type===t.SAMPLER_2D_SHADOW?$d:Jd;for(let t=0;t!==s;++t)i.setTexture2D(e[t]||a,r[t])}function Yu(t,e,i){const n=this.cache,s=e.length,r=du(i,s);hu(n,r)||(t.uniform1iv(this.addr,r),cu(n,r));for(let t=0;t!==s;++t)i.setTexture3D(e[t]||eu,r[t])}function Zu(t,e,i){const n=this.cache,s=e.length,r=du(i,s);hu(n,r)||(t.uniform1iv(this.addr,r),cu(n,r));for(let t=0;t!==s;++t)i.setTextureCube(e[t]||iu,r[t])}function qu(t,e,i){const n=this.cache,s=e.length,r=du(i,s);hu(n,r)||(t.uniform1iv(this.addr,r),cu(n,r));for(let t=0;t!==s;++t)i.setTexture2DArray(e[t]||tu,r[t])}class Qu{constructor(t,e,i){this.id=t,this.addr=i,this.cache=[],this.type=e.type,this.setValue=function(t){switch(t){case 5126:return uu;case 35664:return pu;case 35665:return mu;case 35666:return fu;case 35674:return gu;case 35675:return vu;case 35676:return yu;case 5124:case 35670:return _u;case 35667:case 35671:return xu;case 35668:case 35672:return bu;case 35669:case 35673:return Su;case 5125:return Mu;case 36294:return wu;case 36295:return Au;case 36296:return Eu;case 35678:case 36198:case 36298:case 36306:case 35682:return Tu;case 35679:case 36299:case 36307:return Cu;case 35680:case 36300:case 36308:case 36293:return Du;case 36289:case 36303:case 36311:case 36292:return Ru}}(e.type)}}class Ku{constructor(t,e,i){this.id=t,this.addr=i,this.cache=[],this.type=e.type,this.size=e.size,this.setValue=function(t){switch(t){case 5126:return Pu;case 35664:return Iu;case 35665:return Lu;case 35666:return Bu;case 35674:return Ou;case 35675:return Fu;case 35676:return Nu;case 5124:case 35670:return Uu;case 35667:case 35671:return ku;case 35668:case 35672:return zu;case 35669:case 35673:return Gu;case 5125:return Hu;case 36294:return Vu;case 36295:return Wu;case 36296:return ju;case 35678:case 36198:case 36298:case 36306:case 35682:return Xu;case 35679:case 36299:case 36307:return Yu;case 35680:case 36300:case 36308:case 36293:return Zu;case 36289:case 36303:case 36311:case 36292:return qu}}(e.type)}}class Ju{constructor(t){this.id=t,this.seq=[],this.map={}}setValue(t,e,i){const n=this.seq;for(let s=0,r=n.length;s!==r;++s){const r=n[s];r.setValue(t,e[r.id],i)}}}const $u=/(\w+)(\])?(\[|\.)?/g;function tp(t,e){t.seq.push(e),t.map[e.id]=e}function ep(t,e,i){const n=t.name,s=n.length;for($u.lastIndex=0;;){const r=$u.exec(n),a=$u.lastIndex;let o=r[1];const l="]"===r[2],h=r[3];if(l&&(o|=0),void 0===h||"["===h&&a+2===s){tp(i,void 0===h?new Qu(o,t,e):new Ku(o,t,e));break}{let t=i.map[o];void 0===t&&(t=new Ju(o),tp(i,t)),i=t}}}class ip{constructor(t,e){this.seq=[],this.map={};const i=t.getProgramParameter(e,t.ACTIVE_UNIFORMS);for(let n=0;n<i;++n){const i=t.getActiveUniform(e,n);ep(i,t.getUniformLocation(e,i.name),this)}const n=[],s=[];for(const e of this.seq)e.type===t.SAMPLER_2D_SHADOW||e.type===t.SAMPLER_CUBE_SHADOW||e.type===t.SAMPLER_2D_ARRAY_SHADOW?n.push(e):s.push(e);n.length>0&&(this.seq=n.concat(s))}setValue(t,e,i,n){const s=this.map[e];void 0!==s&&s.setValue(t,i,n)}setOptional(t,e,i){const n=e[i];void 0!==n&&this.setValue(t,i,n)}static upload(t,e,i,n){for(let s=0,r=e.length;s!==r;++s){const r=e[s],a=i[r.id];!1!==a.needsUpdate&&r.setValue(t,a.value,n)}}static seqWithValue(t,e){const i=[];for(let n=0,s=t.length;n!==s;++n){const s=t[n];s.id in e&&i.push(s)}return i}}function np(t,e,i){const n=t.createShader(e);return t.shaderSource(n,i),t.compileShader(n),n}let sp=0;const rp=new Mi;function ap(t,e,i){const n=t.getShaderParameter(e,t.COMPILE_STATUS),s=(t.getShaderInfoLog(e)||"").trim();if(n&&""===s)return"";const r=/ERROR: 0:(\d+)/.exec(s);if(r){const n=parseInt(r[1]);return i.toUpperCase()+"\n\n"+s+"\n\n"+function(t,e){const i=t.split("\n"),n=[],s=Math.max(e-6,0),r=Math.min(e+6,i.length);for(let t=s;t<r;t++){const s=t+1;n.push(`${s===e?">":" "} ${s}: ${i[t]}`)}return n.join("\n")}(t.getShaderSource(e),n)}return s}function op(t,e){const i=function(t){Ci._getMatrix(rp,Ci.workingColorSpace,t);const e=`mat3( ${rp.elements.map(t=>t.toFixed(4))} )`;switch(Ci.getTransfer(t)){case Ce:return[e,"LinearTransferOETF"];case De:return[e,"sRGBTransferOETF"];default:return ii("WebGLProgram: Unsupported color space: ",t),[e,"LinearTransferOETF"]}}(e);return[`vec4 ${t}( vec4 value ) {`,`\treturn ${i[1]}( vec4( value.rgb * ${i[0]}, value.a ) );`,"}"].join("\n")}const lp={[U]:"Linear",[k]:"Reinhard",[z]:"Cineon",[G]:"ACESFilmic",[V]:"AgX",[W]:"Neutral",[H]:"Custom"};function hp(t,e){const i=lp[e];return void 0===i?(ii("WebGLProgram: Unsupported toneMapping:",e),"vec3 "+t+"( vec3 color ) { return LinearToneMapping( color ); }"):"vec3 "+t+"( vec3 color ) { return "+i+"ToneMapping( color ); }"}const cp=new xi;function dp(){Ci.getLuminanceCoefficients(cp);return["float luminance( const in vec3 rgb ) {",`\tconst vec3 weights = vec3( ${cp.x.toFixed(4)}, ${cp.y.toFixed(4)}, ${cp.z.toFixed(4)} );`,"\treturn dot( weights, rgb );","}"].join("\n")}function up(t){return""!==t}function pp(t,e){const i=e.numSpotLightShadows+e.numSpotLightMaps-e.numSpotLightShadowsWithMaps;return t.replace(/NUM_DIR_LIGHTS/g,e.numDirLights).replace(/NUM_SPOT_LIGHTS/g,e.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,e.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,i).replace(/NUM_RECT_AREA_LIGHTS/g,e.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,e.numPointLights).replace(/NUM_HEMI_LIGHTS/g,e.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,e.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,e.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,e.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,e.numPointLightShadows)}function mp(t,e){return t.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}const fp=/^[ \t]*#include +<([\w\d./]+)>/gm;function gp(t){return t.replace(fp,yp)}const vp=new Map;function yp(t,e){let i=gd[e];if(void 0===i){const t=vp.get(e);if(void 0===t)throw new Error("Can not resolve #include <"+e+">");i=gd[t],ii('WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',e,t)}return gp(i)}const _p=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function xp(t){return t.replace(_p,bp)}function bp(t,e,i,n){let s="";for(let t=parseInt(e);t<parseInt(i);t++)s+=n.replace(/\[\s*i\s*\]/g,"[ "+t+" ]").replace(/UNROLLED_LOOP_INDEX/g,t);return s}function Sp(t){let e=`precision ${t.precision} float;\n\tprecision ${t.precision} int;\n\tprecision ${t.precision} sampler2D;\n\tprecision ${t.precision} samplerCube;\n\tprecision ${t.precision} sampler3D;\n\tprecision ${t.precision} sampler2DArray;\n\tprecision ${t.precision} sampler2DShadow;\n\tprecision ${t.precision} samplerCubeShadow;\n\tprecision ${t.precision} sampler2DArrayShadow;\n\tprecision ${t.precision} isampler2D;\n\tprecision ${t.precision} isampler3D;\n\tprecision ${t.precision} isamplerCube;\n\tprecision ${t.precision} isampler2DArray;\n\tprecision ${t.precision} usampler2D;\n\tprecision ${t.precision} usampler3D;\n\tprecision ${t.precision} usamplerCube;\n\tprecision ${t.precision} usampler2DArray;\n\t`;return"highp"===t.precision?e+="\n#define HIGH_PRECISION":"mediump"===t.precision?e+="\n#define MEDIUM_PRECISION":"lowp"===t.precision&&(e+="\n#define LOW_PRECISION"),e}const Mp={[s]:"SHADOWMAP_TYPE_PCF",[r]:"SHADOWMAP_TYPE_VSM"};const wp={[Z]:"ENVMAP_TYPE_CUBE",[q]:"ENVMAP_TYPE_CUBE",[J]:"ENVMAP_TYPE_CUBE_UV"};const Ap={[q]:"ENVMAP_MODE_REFRACTION"};const Ep={[O]:"ENVMAP_BLENDING_MULTIPLY",[F]:"ENVMAP_BLENDING_MIX",[N]:"ENVMAP_BLENDING_ADD"};function Tp(t,e,i,n){const s=t.getContext(),r=i.defines;let a=i.vertexShader,o=i.fragmentShader;const l=function(t){return Mp[t.shadowMapType]||"SHADOWMAP_TYPE_BASIC"}(i),h=function(t){return!1===t.envMap?"ENVMAP_TYPE_CUBE":wp[t.envMapMode]||"ENVMAP_TYPE_CUBE"}(i),c=function(t){return!1===t.envMap?"ENVMAP_MODE_REFLECTION":Ap[t.envMapMode]||"ENVMAP_MODE_REFLECTION"}(i),d=function(t){return!1===t.envMap?"ENVMAP_BLENDING_NONE":Ep[t.combine]||"ENVMAP_BLENDING_NONE"}(i),u=function(t){const e=t.envMapCubeUVHeight;if(null===e)return null;const i=Math.log2(e)-2,n=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,i),112)),texelHeight:n,maxMip:i}}(i),p=function(t){return[t.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":"",t.extensionMultiDraw?"#extension GL_ANGLE_multi_draw : require":""].filter(up).join("\n")}(i),m=function(t){const e=[];for(const i in t){const n=t[i];!1!==n&&e.push("#define "+i+" "+n)}return e.join("\n")}(r),f=s.createProgram();let g,v,y=i.glslVersion?"#version "+i.glslVersion+"\n":"";i.isRawShaderMaterial?(g=["#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,m].filter(up).join("\n"),g.length>0&&(g+="\n"),v=["#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,m].filter(up).join("\n"),v.length>0&&(v+="\n")):(g=[Sp(i),"#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,m,i.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",i.batching?"#define USE_BATCHING":"",i.batchingColor?"#define USE_BATCHING_COLOR":"",i.instancing?"#define USE_INSTANCING":"",i.instancingColor?"#define USE_INSTANCING_COLOR":"",i.instancingMorph?"#define USE_INSTANCING_MORPH":"",i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+c:"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",i.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",i.displacementMap?"#define USE_DISPLACEMENTMAP":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.anisotropy?"#define USE_ANISOTROPY":"",i.anisotropyMap?"#define USE_ANISOTROPYMAP":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",i.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",i.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.alphaHash?"#define USE_ALPHAHASH":"",i.transmission?"#define USE_TRANSMISSION":"",i.transmissionMap?"#define USE_TRANSMISSIONMAP":"",i.thicknessMap?"#define USE_THICKNESSMAP":"",i.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",i.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",i.mapUv?"#define MAP_UV "+i.mapUv:"",i.alphaMapUv?"#define ALPHAMAP_UV "+i.alphaMapUv:"",i.lightMapUv?"#define LIGHTMAP_UV "+i.lightMapUv:"",i.aoMapUv?"#define AOMAP_UV "+i.aoMapUv:"",i.emissiveMapUv?"#define EMISSIVEMAP_UV "+i.emissiveMapUv:"",i.bumpMapUv?"#define BUMPMAP_UV "+i.bumpMapUv:"",i.normalMapUv?"#define NORMALMAP_UV "+i.normalMapUv:"",i.displacementMapUv?"#define DISPLACEMENTMAP_UV "+i.displacementMapUv:"",i.metalnessMapUv?"#define METALNESSMAP_UV "+i.metalnessMapUv:"",i.roughnessMapUv?"#define ROUGHNESSMAP_UV "+i.roughnessMapUv:"",i.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+i.anisotropyMapUv:"",i.clearcoatMapUv?"#define CLEARCOATMAP_UV "+i.clearcoatMapUv:"",i.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+i.clearcoatNormalMapUv:"",i.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+i.clearcoatRoughnessMapUv:"",i.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+i.iridescenceMapUv:"",i.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+i.iridescenceThicknessMapUv:"",i.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+i.sheenColorMapUv:"",i.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+i.sheenRoughnessMapUv:"",i.specularMapUv?"#define SPECULARMAP_UV "+i.specularMapUv:"",i.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+i.specularColorMapUv:"",i.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+i.specularIntensityMapUv:"",i.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+i.transmissionMapUv:"",i.thicknessMapUv?"#define THICKNESSMAP_UV "+i.thicknessMapUv:"",i.vertexTangents&&!1===i.flatShading?"#define USE_TANGENT":"",i.vertexColors?"#define USE_COLOR":"",i.vertexAlphas?"#define USE_COLOR_ALPHA":"",i.vertexUv1s?"#define USE_UV1":"",i.vertexUv2s?"#define USE_UV2":"",i.vertexUv3s?"#define USE_UV3":"",i.pointsUvs?"#define USE_POINTS_UV":"",i.flatShading?"#define FLAT_SHADED":"",i.skinning?"#define USE_SKINNING":"",i.morphTargets?"#define USE_MORPHTARGETS":"",i.morphNormals&&!1===i.flatShading?"#define USE_MORPHNORMALS":"",i.morphColors?"#define USE_MORPHCOLORS":"",i.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+i.morphTextureStride:"",i.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+i.morphTargetsCount:"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+l:"",i.sizeAttenuation?"#define USE_SIZEATTENUATION":"",i.numLightProbes>0?"#define USE_LIGHT_PROBES":"",i.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",i.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING","\tattribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR","\tattribute vec3 instanceColor;","#endif","#ifdef USE_INSTANCING_MORPH","\tuniform sampler2D morphTexture;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1","\tattribute vec2 uv1;","#endif","#ifdef USE_UV2","\tattribute vec2 uv2;","#endif","#ifdef USE_UV3","\tattribute vec2 uv3;","#endif","#ifdef USE_TANGENT","\tattribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )","\tattribute vec4 color;","#elif defined( USE_COLOR )","\tattribute vec3 color;","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter(up).join("\n"),v=[Sp(i),"#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,m,i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",i.map?"#define USE_MAP":"",i.matcap?"#define USE_MATCAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+h:"",i.envMap?"#define "+c:"",i.envMap?"#define "+d:"",u?"#define CUBEUV_TEXEL_WIDTH "+u.texelWidth:"",u?"#define CUBEUV_TEXEL_HEIGHT "+u.texelHeight:"",u?"#define CUBEUV_MAX_MIP "+u.maxMip+".0":"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",i.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.anisotropy?"#define USE_ANISOTROPY":"",i.anisotropyMap?"#define USE_ANISOTROPYMAP":"",i.clearcoat?"#define USE_CLEARCOAT":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.dispersion?"#define USE_DISPERSION":"",i.iridescence?"#define USE_IRIDESCENCE":"",i.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",i.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",i.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.alphaTest?"#define USE_ALPHATEST":"",i.alphaHash?"#define USE_ALPHAHASH":"",i.sheen?"#define USE_SHEEN":"",i.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",i.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",i.transmission?"#define USE_TRANSMISSION":"",i.transmissionMap?"#define USE_TRANSMISSIONMAP":"",i.thicknessMap?"#define USE_THICKNESSMAP":"",i.vertexTangents&&!1===i.flatShading?"#define USE_TANGENT":"",i.vertexColors||i.instancingColor?"#define USE_COLOR":"",i.vertexAlphas||i.batchingColor?"#define USE_COLOR_ALPHA":"",i.vertexUv1s?"#define USE_UV1":"",i.vertexUv2s?"#define USE_UV2":"",i.vertexUv3s?"#define USE_UV3":"",i.pointsUvs?"#define USE_POINTS_UV":"",i.gradientMap?"#define USE_GRADIENTMAP":"",i.flatShading?"#define FLAT_SHADED":"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+l:"",i.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",i.numLightProbes>0?"#define USE_LIGHT_PROBES":"",i.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",i.decodeVideoTextureEmissive?"#define DECODE_VIDEO_TEXTURE_EMISSIVE":"",i.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",i.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",0!==i.toneMapping?"#define TONE_MAPPING":"",0!==i.toneMapping?gd.tonemapping_pars_fragment:"",0!==i.toneMapping?hp("toneMapping",i.toneMapping):"",i.dithering?"#define DITHERING":"",i.opaque?"#define OPAQUE":"",gd.colorspace_pars_fragment,op("linearToOutputTexel",i.outputColorSpace),dp(),i.useDepthPacking?"#define DEPTH_PACKING "+i.depthPacking:"","\n"].filter(up).join("\n")),a=gp(a),a=pp(a,i),a=mp(a,i),o=gp(o),o=pp(o,i),o=mp(o,i),a=xp(a),o=xp(o),!0!==i.isRawShaderMaterial&&(y="#version 300 es\n",g=[p,"#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+g,v=["#define varying in",i.glslVersion===We?"":"layout(location = 0) out highp vec4 pc_fragColor;",i.glslVersion===We?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join("\n")+"\n"+v);const _=y+g+a,x=y+v+o,b=np(s,s.VERTEX_SHADER,_),S=np(s,s.FRAGMENT_SHADER,x);function M(e){if(t.debug.checkShaderErrors){const i=s.getProgramInfoLog(f)||"",n=s.getShaderInfoLog(b)||"",r=s.getShaderInfoLog(S)||"",a=i.trim(),o=n.trim(),l=r.trim();let h=!0,c=!0;if(!1===s.getProgramParameter(f,s.LINK_STATUS))if(h=!1,"function"==typeof t.debug.onShaderError)t.debug.onShaderError(s,f,b,S);else{const t=ap(s,b,"vertex"),i=ap(s,S,"fragment");ni("THREE.WebGLProgram: Shader Error "+s.getError()+" - VALIDATE_STATUS "+s.getProgramParameter(f,s.VALIDATE_STATUS)+"\n\nMaterial Name: "+e.name+"\nMaterial Type: "+e.type+"\n\nProgram Info Log: "+a+"\n"+t+"\n"+i)}else""!==a?ii("WebGLProgram: Program Info Log:",a):""!==o&&""!==l||(c=!1);c&&(e.diagnostics={runnable:h,programLog:a,vertexShader:{log:o,prefix:g},fragmentShader:{log:l,prefix:v}})}s.deleteShader(b),s.deleteShader(S),w=new ip(s,f),A=function(t,e){const i={},n=t.getProgramParameter(e,t.ACTIVE_ATTRIBUTES);for(let s=0;s<n;s++){const n=t.getActiveAttrib(e,s),r=n.name;let a=1;n.type===t.FLOAT_MAT2&&(a=2),n.type===t.FLOAT_MAT3&&(a=3),n.type===t.FLOAT_MAT4&&(a=4),i[r]={type:n.type,location:t.getAttribLocation(e,r),locationSize:a}}return i}(s,f)}let w,A;s.attachShader(f,b),s.attachShader(f,S),void 0!==i.index0AttributeName?s.bindAttribLocation(f,0,i.index0AttributeName):!0===i.morphTargets&&s.bindAttribLocation(f,0,"position"),s.linkProgram(f),this.getUniforms=function(){return void 0===w&&M(this),w},this.getAttributes=function(){return void 0===A&&M(this),A};let E=!1===i.rendererExtensionParallelShaderCompile;return this.isReady=function(){return!1===E&&(E=s.getProgramParameter(f,37297)),E},this.destroy=function(){n.releaseStatesOfProgram(this),s.deleteProgram(f),this.program=void 0},this.type=i.shaderType,this.name=i.shaderName,this.id=sp++,this.cacheKey=e,this.usedTimes=1,this.program=f,this.vertexShader=b,this.fragmentShader=S,this}let Cp=0;class Dp{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t){const e=t.vertexShader,i=t.fragmentShader,n=this._getShaderStage(e),s=this._getShaderStage(i),r=this._getShaderCacheForMaterial(t);return!1===r.has(n)&&(r.add(n),n.usedTimes++),!1===r.has(s)&&(r.add(s),s.usedTimes++),this}remove(t){const e=this.materialCache.get(t);for(const t of e)t.usedTimes--,0===t.usedTimes&&this.shaderCache.delete(t.code);return this.materialCache.delete(t),this}getVertexShaderID(t){return this._getShaderStage(t.vertexShader).id}getFragmentShaderID(t){return this._getShaderStage(t.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(t){const e=this.materialCache;let i=e.get(t);return void 0===i&&(i=new Set,e.set(t,i)),i}_getShaderStage(t){const e=this.shaderCache;let i=e.get(t);return void 0===i&&(i=new Rp(t),e.set(t,i)),i}}class Rp{constructor(t){this.id=Cp++,this.code=t,this.usedTimes=0}}function Pp(t,e,i,n,s,r){const a=new en,o=new Dp,l=new Set,h=[],c=new Map,d=n.logarithmicDepthBuffer;let u=n.precision;const p={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distance",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function m(t){return l.add(t),0===t?"uv":`uv${t}`}return{getParameters:function(s,a,h,c,f){const g=c.fog,v=f.geometry,y=s.isMeshStandardMaterial||s.isMeshLambertMaterial||s.isMeshPhongMaterial?c.environment:null,_=s.isMeshStandardMaterial||s.isMeshLambertMaterial&&!s.envMap||s.isMeshPhongMaterial&&!s.envMap,x=e.get(s.envMap||y,_),b=x&&x.mapping===J?x.image.height:null,S=p[s.type];null!==s.precision&&(u=n.getMaxPrecision(s.precision),u!==s.precision&&ii("WebGLProgram.getParameters:",s.precision,"not supported, using",u,"instead."));const M=v.morphAttributes.position||v.morphAttributes.normal||v.morphAttributes.color,w=void 0!==M?M.length:0;let A,E,T,C,D=0;if(void 0!==v.morphAttributes.position&&(D=1),void 0!==v.morphAttributes.normal&&(D=2),void 0!==v.morphAttributes.color&&(D=3),S){const t=yd[S];A=t.vertexShader,E=t.fragmentShader}else A=s.vertexShader,E=s.fragmentShader,o.update(s),T=o.getVertexShaderID(s),C=o.getFragmentShaderID(s);const R=t.getRenderTarget(),P=t.state.buffers.depth.getReversed(),I=!0===f.isInstancedMesh,L=!0===f.isBatchedMesh,B=!!s.map,O=!!s.matcap,F=!!x,N=!!s.aoMap,U=!!s.lightMap,k=!!s.bumpMap,z=!!s.normalMap,G=!!s.displacementMap,H=!!s.emissiveMap,V=!!s.metalnessMap,W=!!s.roughnessMap,j=s.anisotropy>0,X=s.clearcoat>0,Y=s.dispersion>0,Z=s.iridescence>0,q=s.sheen>0,Q=s.transmission>0,K=j&&!!s.anisotropyMap,$=X&&!!s.clearcoatMap,tt=X&&!!s.clearcoatNormalMap,et=X&&!!s.clearcoatRoughnessMap,it=Z&&!!s.iridescenceMap,nt=Z&&!!s.iridescenceThicknessMap,st=q&&!!s.sheenColorMap,rt=q&&!!s.sheenRoughnessMap,at=!!s.specularMap,ot=!!s.specularColorMap,lt=!!s.specularIntensityMap,ht=Q&&!!s.transmissionMap,ct=Q&&!!s.thicknessMap,dt=!!s.gradientMap,ut=!!s.alphaMap,pt=s.alphaTest>0,mt=!!s.alphaHash,ft=!!s.extensions;let gt=0;s.toneMapped&&(null!==R&&!0!==R.isXRRenderTarget||(gt=t.toneMapping));const vt={shaderID:S,shaderType:s.type,shaderName:s.name,vertexShader:A,fragmentShader:E,defines:s.defines,customVertexShaderID:T,customFragmentShaderID:C,isRawShaderMaterial:!0===s.isRawShaderMaterial,glslVersion:s.glslVersion,precision:u,batching:L,batchingColor:L&&null!==f._colorsTexture,instancing:I,instancingColor:I&&null!==f.instanceColor,instancingMorph:I&&null!==f.morphTexture,outputColorSpace:null===R?t.outputColorSpace:!0===R.isXRRenderTarget?R.texture.colorSpace:Te,alphaToCoverage:!!s.alphaToCoverage,map:B,matcap:O,envMap:F,envMapMode:F&&x.mapping,envMapCubeUVHeight:b,aoMap:N,lightMap:U,bumpMap:k,normalMap:z,displacementMap:G,emissiveMap:H,normalMapObjectSpace:z&&1===s.normalMapType,normalMapTangentSpace:z&&0===s.normalMapType,metalnessMap:V,roughnessMap:W,anisotropy:j,anisotropyMap:K,clearcoat:X,clearcoatMap:$,clearcoatNormalMap:tt,clearcoatRoughnessMap:et,dispersion:Y,iridescence:Z,iridescenceMap:it,iridescenceThicknessMap:nt,sheen:q,sheenColorMap:st,sheenRoughnessMap:rt,specularMap:at,specularColorMap:ot,specularIntensityMap:lt,transmission:Q,transmissionMap:ht,thicknessMap:ct,gradientMap:dt,opaque:!1===s.transparent&&1===s.blending&&!1===s.alphaToCoverage,alphaMap:ut,alphaTest:pt,alphaHash:mt,combine:s.combine,mapUv:B&&m(s.map.channel),aoMapUv:N&&m(s.aoMap.channel),lightMapUv:U&&m(s.lightMap.channel),bumpMapUv:k&&m(s.bumpMap.channel),normalMapUv:z&&m(s.normalMap.channel),displacementMapUv:G&&m(s.displacementMap.channel),emissiveMapUv:H&&m(s.emissiveMap.channel),metalnessMapUv:V&&m(s.metalnessMap.channel),roughnessMapUv:W&&m(s.roughnessMap.channel),anisotropyMapUv:K&&m(s.anisotropyMap.channel),clearcoatMapUv:$&&m(s.clearcoatMap.channel),clearcoatNormalMapUv:tt&&m(s.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:et&&m(s.clearcoatRoughnessMap.channel),iridescenceMapUv:it&&m(s.iridescenceMap.channel),iridescenceThicknessMapUv:nt&&m(s.iridescenceThicknessMap.channel),sheenColorMapUv:st&&m(s.sheenColorMap.channel),sheenRoughnessMapUv:rt&&m(s.sheenRoughnessMap.channel),specularMapUv:at&&m(s.specularMap.channel),specularColorMapUv:ot&&m(s.specularColorMap.channel),specularIntensityMapUv:lt&&m(s.specularIntensityMap.channel),transmissionMapUv:ht&&m(s.transmissionMap.channel),thicknessMapUv:ct&&m(s.thicknessMap.channel),alphaMapUv:ut&&m(s.alphaMap.channel),vertexTangents:!!v.attributes.tangent&&(z||j),vertexColors:s.vertexColors,vertexAlphas:!0===s.vertexColors&&!!v.attributes.color&&4===v.attributes.color.itemSize,pointsUvs:!0===f.isPoints&&!!v.attributes.uv&&(B||ut),fog:!!g,useFog:!0===s.fog,fogExp2:!!g&&g.isFogExp2,flatShading:!1===s.wireframe&&(!0===s.flatShading||void 0===v.attributes.normal&&!1===z&&(s.isMeshLambertMaterial||s.isMeshPhongMaterial||s.isMeshStandardMaterial||s.isMeshPhysicalMaterial)),sizeAttenuation:!0===s.sizeAttenuation,logarithmicDepthBuffer:d,reversedDepthBuffer:P,skinning:!0===f.isSkinnedMesh,morphTargets:void 0!==v.morphAttributes.position,morphNormals:void 0!==v.morphAttributes.normal,morphColors:void 0!==v.morphAttributes.color,morphTargetsCount:w,morphTextureStride:D,numDirLights:a.directional.length,numPointLights:a.point.length,numSpotLights:a.spot.length,numSpotLightMaps:a.spotLightMap.length,numRectAreaLights:a.rectArea.length,numHemiLights:a.hemi.length,numDirLightShadows:a.directionalShadowMap.length,numPointLightShadows:a.pointShadowMap.length,numSpotLightShadows:a.spotShadowMap.length,numSpotLightShadowsWithMaps:a.numSpotLightShadowsWithMaps,numLightProbes:a.numLightProbes,numClippingPlanes:r.numPlanes,numClipIntersection:r.numIntersection,dithering:s.dithering,shadowMapEnabled:t.shadowMap.enabled&&h.length>0,shadowMapType:t.shadowMap.type,toneMapping:gt,decodeVideoTexture:B&&!0===s.map.isVideoTexture&&Ci.getTransfer(s.map.colorSpace)===De,decodeVideoTextureEmissive:H&&!0===s.emissiveMap.isVideoTexture&&Ci.getTransfer(s.emissiveMap.colorSpace)===De,premultipliedAlpha:s.premultipliedAlpha,doubleSided:2===s.side,flipSided:1===s.side,useDepthPacking:s.depthPacking>=0,depthPacking:s.depthPacking||0,index0AttributeName:s.index0AttributeName,extensionClipCullDistance:ft&&!0===s.extensions.clipCullDistance&&i.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(ft&&!0===s.extensions.multiDraw||L)&&i.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:i.has("KHR_parallel_shader_compile"),customProgramCacheKey:s.customProgramCacheKey()};return vt.vertexUv1s=l.has(1),vt.vertexUv2s=l.has(2),vt.vertexUv3s=l.has(3),l.clear(),vt},getProgramCacheKey:function(e){const i=[];if(e.shaderID?i.push(e.shaderID):(i.push(e.customVertexShaderID),i.push(e.customFragmentShaderID)),void 0!==e.defines)for(const t in e.defines)i.push(t),i.push(e.defines[t]);return!1===e.isRawShaderMaterial&&(!function(t,e){t.push(e.precision),t.push(e.outputColorSpace),t.push(e.envMapMode),t.push(e.envMapCubeUVHeight),t.push(e.mapUv),t.push(e.alphaMapUv),t.push(e.lightMapUv),t.push(e.aoMapUv),t.push(e.bumpMapUv),t.push(e.normalMapUv),t.push(e.displacementMapUv),t.push(e.emissiveMapUv),t.push(e.metalnessMapUv),t.push(e.roughnessMapUv),t.push(e.anisotropyMapUv),t.push(e.clearcoatMapUv),t.push(e.clearcoatNormalMapUv),t.push(e.clearcoatRoughnessMapUv),t.push(e.iridescenceMapUv),t.push(e.iridescenceThicknessMapUv),t.push(e.sheenColorMapUv),t.push(e.sheenRoughnessMapUv),t.push(e.specularMapUv),t.push(e.specularColorMapUv),t.push(e.specularIntensityMapUv),t.push(e.transmissionMapUv),t.push(e.thicknessMapUv),t.push(e.combine),t.push(e.fogExp2),t.push(e.sizeAttenuation),t.push(e.morphTargetsCount),t.push(e.morphAttributeCount),t.push(e.numDirLights),t.push(e.numPointLights),t.push(e.numSpotLights),t.push(e.numSpotLightMaps),t.push(e.numHemiLights),t.push(e.numRectAreaLights),t.push(e.numDirLightShadows),t.push(e.numPointLightShadows),t.push(e.numSpotLightShadows),t.push(e.numSpotLightShadowsWithMaps),t.push(e.numLightProbes),t.push(e.shadowMapType),t.push(e.toneMapping),t.push(e.numClippingPlanes),t.push(e.numClipIntersection),t.push(e.depthPacking)}(i,e),function(t,e){a.disableAll(),e.instancing&&a.enable(0);e.instancingColor&&a.enable(1);e.instancingMorph&&a.enable(2);e.matcap&&a.enable(3);e.envMap&&a.enable(4);e.normalMapObjectSpace&&a.enable(5);e.normalMapTangentSpace&&a.enable(6);e.clearcoat&&a.enable(7);e.iridescence&&a.enable(8);e.alphaTest&&a.enable(9);e.vertexColors&&a.enable(10);e.vertexAlphas&&a.enable(11);e.vertexUv1s&&a.enable(12);e.vertexUv2s&&a.enable(13);e.vertexUv3s&&a.enable(14);e.vertexTangents&&a.enable(15);e.anisotropy&&a.enable(16);e.alphaHash&&a.enable(17);e.batching&&a.enable(18);e.dispersion&&a.enable(19);e.batchingColor&&a.enable(20);e.gradientMap&&a.enable(21);t.push(a.mask),a.disableAll(),e.fog&&a.enable(0);e.useFog&&a.enable(1);e.flatShading&&a.enable(2);e.logarithmicDepthBuffer&&a.enable(3);e.reversedDepthBuffer&&a.enable(4);e.skinning&&a.enable(5);e.morphTargets&&a.enable(6);e.morphNormals&&a.enable(7);e.morphColors&&a.enable(8);e.premultipliedAlpha&&a.enable(9);e.shadowMapEnabled&&a.enable(10);e.doubleSided&&a.enable(11);e.flipSided&&a.enable(12);e.useDepthPacking&&a.enable(13);e.dithering&&a.enable(14);e.transmission&&a.enable(15);e.sheen&&a.enable(16);e.opaque&&a.enable(17);e.pointsUvs&&a.enable(18);e.decodeVideoTexture&&a.enable(19);e.decodeVideoTextureEmissive&&a.enable(20);e.alphaToCoverage&&a.enable(21);t.push(a.mask)}(i,e),i.push(t.outputColorSpace)),i.push(e.customProgramCacheKey),i.join()},getUniforms:function(t){const e=p[t.type];let i;if(e){const t=yd[e];i=Cl.clone(t.uniforms)}else i=t.uniforms;return i},acquireProgram:function(e,i){let n=c.get(i);return void 0!==n?++n.usedTimes:(n=new Tp(t,i,e,s),h.push(n),c.set(i,n)),n},releaseProgram:function(t){if(0===--t.usedTimes){const e=h.indexOf(t);h[e]=h[h.length-1],h.pop(),c.delete(t.cacheKey),t.destroy()}},releaseShaderCache:function(t){o.remove(t)},programs:h,dispose:function(){o.dispose()}}}function Ip(){let t=new WeakMap;return{has:function(e){return t.has(e)},get:function(e){let i=t.get(e);return void 0===i&&(i={},t.set(e,i)),i},remove:function(e){t.delete(e)},update:function(e,i,n){t.get(e)[i]=n},dispose:function(){t=new WeakMap}}}function Lp(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.material.id!==e.material.id?t.material.id-e.material.id:t.materialVariant!==e.materialVariant?t.materialVariant-e.materialVariant:t.z!==e.z?t.z-e.z:t.id-e.id}function Bp(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.z!==e.z?e.z-t.z:t.id-e.id}function Op(){const t=[];let e=0;const i=[],n=[],s=[];function r(t){let e=0;return t.isInstancedMesh&&(e+=2),t.isSkinnedMesh&&(e+=1),e}function a(i,n,s,a,o,l){let h=t[e];return void 0===h?(h={id:i.id,object:i,geometry:n,material:s,materialVariant:r(i),groupOrder:a,renderOrder:i.renderOrder,z:o,group:l},t[e]=h):(h.id=i.id,h.object=i,h.geometry=n,h.material=s,h.materialVariant=r(i),h.groupOrder=a,h.renderOrder=i.renderOrder,h.z=o,h.group=l),e++,h}return{opaque:i,transmissive:n,transparent:s,init:function(){e=0,i.length=0,n.length=0,s.length=0},push:function(t,e,r,o,l,h){const c=a(t,e,r,o,l,h);r.transmission>0?n.push(c):!0===r.transparent?s.push(c):i.push(c)},unshift:function(t,e,r,o,l,h){const c=a(t,e,r,o,l,h);r.transmission>0?n.unshift(c):!0===r.transparent?s.unshift(c):i.unshift(c)},finish:function(){for(let i=e,n=t.length;i<n;i++){const e=t[i];if(null===e.id)break;e.id=null,e.object=null,e.geometry=null,e.material=null,e.group=null}},sort:function(t,e){i.length>1&&i.sort(t||Lp),n.length>1&&n.sort(e||Bp),s.length>1&&s.sort(e||Bp)}}}function Fp(){let t=new WeakMap;return{get:function(e,i){const n=t.get(e);let s;return void 0===n?(s=new Op,t.set(e,[s])):i>=n.length?(s=new Op,n.push(s)):s=n[i],s},dispose:function(){t=new WeakMap}}}function Np(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let i;switch(e.type){case"DirectionalLight":i={direction:new xi,color:new En};break;case"SpotLight":i={position:new xi,direction:new xi,color:new En,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":i={position:new xi,color:new En,distance:0,decay:0};break;case"HemisphereLight":i={direction:new xi,skyColor:new En,groundColor:new En};break;case"RectAreaLight":i={color:new En,position:new xi,halfWidth:new xi,halfHeight:new xi}}return t[e.id]=i,i}}}let Up=0;function kp(t,e){return(e.castShadow?2:0)-(t.castShadow?2:0)+(e.map?1:0)-(t.map?1:0)}function zp(t){const e=new Np,i=function(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let i;switch(e.type){case"DirectionalLight":case"SpotLight":i={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new yi};break;case"PointLight":i={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new yi,shadowCameraNear:1,shadowCameraFar:1e3}}return t[e.id]=i,i}}}(),n={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let t=0;t<9;t++)n.probe.push(new xi);const s=new xi,r=new Wi,a=new Wi;return{setup:function(s){let r=0,a=0,o=0;for(let t=0;t<9;t++)n.probe[t].set(0,0,0);let l=0,h=0,c=0,d=0,u=0,p=0,m=0,f=0,g=0,v=0,y=0;s.sort(kp);for(let t=0,_=s.length;t<_;t++){const _=s[t],x=_.color,b=_.intensity,S=_.distance;let M=null;if(_.shadow&&_.shadow.map&&(M=_.shadow.map.texture.format===Ct?_.shadow.map.texture:_.shadow.map.depthTexture||_.shadow.map.texture),_.isAmbientLight)r+=x.r*b,a+=x.g*b,o+=x.b*b;else if(_.isLightProbe){for(let t=0;t<9;t++)n.probe[t].addScaledVector(_.sh.coefficients[t],b);y++}else if(_.isDirectionalLight){const t=e.get(_);if(t.color.copy(_.color).multiplyScalar(_.intensity),_.castShadow){const t=_.shadow,e=i.get(_);e.shadowIntensity=t.intensity,e.shadowBias=t.bias,e.shadowNormalBias=t.normalBias,e.shadowRadius=t.radius,e.shadowMapSize=t.mapSize,n.directionalShadow[l]=e,n.directionalShadowMap[l]=M,n.directionalShadowMatrix[l]=_.shadow.matrix,p++}n.directional[l]=t,l++}else if(_.isSpotLight){const t=e.get(_);t.position.setFromMatrixPosition(_.matrixWorld),t.color.copy(x).multiplyScalar(b),t.distance=S,t.coneCos=Math.cos(_.angle),t.penumbraCos=Math.cos(_.angle*(1-_.penumbra)),t.decay=_.decay,n.spot[c]=t;const s=_.shadow;if(_.map&&(n.spotLightMap[g]=_.map,g++,s.updateMatrices(_),_.castShadow&&v++),n.spotLightMatrix[c]=s.matrix,_.castShadow){const t=i.get(_);t.shadowIntensity=s.intensity,t.shadowBias=s.bias,t.shadowNormalBias=s.normalBias,t.shadowRadius=s.radius,t.shadowMapSize=s.mapSize,n.spotShadow[c]=t,n.spotShadowMap[c]=M,f++}c++}else if(_.isRectAreaLight){const t=e.get(_);t.color.copy(x).multiplyScalar(b),t.halfWidth.set(.5*_.width,0,0),t.halfHeight.set(0,.5*_.height,0),n.rectArea[d]=t,d++}else if(_.isPointLight){const t=e.get(_);if(t.color.copy(_.color).multiplyScalar(_.intensity),t.distance=_.distance,t.decay=_.decay,_.castShadow){const t=_.shadow,e=i.get(_);e.shadowIntensity=t.intensity,e.shadowBias=t.bias,e.shadowNormalBias=t.normalBias,e.shadowRadius=t.radius,e.shadowMapSize=t.mapSize,e.shadowCameraNear=t.camera.near,e.shadowCameraFar=t.camera.far,n.pointShadow[h]=e,n.pointShadowMap[h]=M,n.pointShadowMatrix[h]=_.shadow.matrix,m++}n.point[h]=t,h++}else if(_.isHemisphereLight){const t=e.get(_);t.skyColor.copy(_.color).multiplyScalar(b),t.groundColor.copy(_.groundColor).multiplyScalar(b),n.hemi[u]=t,u++}}d>0&&(!0===t.has("OES_texture_float_linear")?(n.rectAreaLTC1=vd.LTC_FLOAT_1,n.rectAreaLTC2=vd.LTC_FLOAT_2):(n.rectAreaLTC1=vd.LTC_HALF_1,n.rectAreaLTC2=vd.LTC_HALF_2)),n.ambient[0]=r,n.ambient[1]=a,n.ambient[2]=o;const _=n.hash;_.directionalLength===l&&_.pointLength===h&&_.spotLength===c&&_.rectAreaLength===d&&_.hemiLength===u&&_.numDirectionalShadows===p&&_.numPointShadows===m&&_.numSpotShadows===f&&_.numSpotMaps===g&&_.numLightProbes===y||(n.directional.length=l,n.spot.length=c,n.rectArea.length=d,n.point.length=h,n.hemi.length=u,n.directionalShadow.length=p,n.directionalShadowMap.length=p,n.pointShadow.length=m,n.pointShadowMap.length=m,n.spotShadow.length=f,n.spotShadowMap.length=f,n.directionalShadowMatrix.length=p,n.pointShadowMatrix.length=m,n.spotLightMatrix.length=f+g-v,n.spotLightMap.length=g,n.numSpotLightShadowsWithMaps=v,n.numLightProbes=y,_.directionalLength=l,_.pointLength=h,_.spotLength=c,_.rectAreaLength=d,_.hemiLength=u,_.numDirectionalShadows=p,_.numPointShadows=m,_.numSpotShadows=f,_.numSpotMaps=g,_.numLightProbes=y,n.version=Up++)},setupView:function(t,e){let i=0,o=0,l=0,h=0,c=0;const d=e.matrixWorldInverse;for(let e=0,u=t.length;e<u;e++){const u=t[e];if(u.isDirectionalLight){const t=n.directional[i];t.direction.setFromMatrixPosition(u.matrixWorld),s.setFromMatrixPosition(u.target.matrixWorld),t.direction.sub(s),t.direction.transformDirection(d),i++}else if(u.isSpotLight){const t=n.spot[l];t.position.setFromMatrixPosition(u.matrixWorld),t.position.applyMatrix4(d),t.direction.setFromMatrixPosition(u.matrixWorld),s.setFromMatrixPosition(u.target.matrixWorld),t.direction.sub(s),t.direction.transformDirection(d),l++}else if(u.isRectAreaLight){const t=n.rectArea[h];t.position.setFromMatrixPosition(u.matrixWorld),t.position.applyMatrix4(d),a.identity(),r.copy(u.matrixWorld),r.premultiply(d),a.extractRotation(r),t.halfWidth.set(.5*u.width,0,0),t.halfHeight.set(0,.5*u.height,0),t.halfWidth.applyMatrix4(a),t.halfHeight.applyMatrix4(a),h++}else if(u.isPointLight){const t=n.point[o];t.position.setFromMatrixPosition(u.matrixWorld),t.position.applyMatrix4(d),o++}else if(u.isHemisphereLight){const t=n.hemi[c];t.direction.setFromMatrixPosition(u.matrixWorld),t.direction.transformDirection(d),c++}}},state:n}}function Gp(t){const e=new zp(t),i=[],n=[];const s={lightsArray:i,shadowsArray:n,camera:null,lights:e,transmissionRenderTarget:{}};return{init:function(t){s.camera=t,i.length=0,n.length=0},state:s,setupLights:function(){e.setup(i)},setupLightsView:function(t){e.setupView(i,t)},pushLight:function(t){i.push(t)},pushShadow:function(t){n.push(t)}}}function Hp(t){let e=new WeakMap;return{get:function(i,n=0){const s=e.get(i);let r;return void 0===s?(r=new Gp(t),e.set(i,[r])):n>=s.length?(r=new Gp(t),s.push(r)):r=s[n],r},dispose:function(){e=new WeakMap}}}const Vp=[new xi(1,0,0),new xi(-1,0,0),new xi(0,1,0),new xi(0,-1,0),new xi(0,0,1),new xi(0,0,-1)],Wp=[new xi(0,-1,0),new xi(0,-1,0),new xi(0,0,1),new xi(0,0,-1),new xi(0,-1,0),new xi(0,-1,0)],jp=new Wi,Xp=new xi,Yp=new xi;function Zp(t,e,i){let n=new $r;const s=new yi,r=new yi,h=new ki,c=new Nl,d=new Ul,u={},p=i.maxTextureSize,m={[a]:1,[o]:0,[l]:2},f=new Dl({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new yi},radius:{value:4}},vertexShader:"void main() {\n\tgl_Position = vec4( position, 1.0 );\n}",fragmentShader:"uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ).rg;\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ).r;\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );\n\tgl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );\n}"}),g=f.clone();g.defines.HORIZONTAL_PASS=1;const v=new Ds;v.setAttribute("position",new ms(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const y=new xr(v,f),_=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=1;let x=this.type;function b(i,n){const r=e.update(y);f.defines.VSM_SAMPLES!==i.blurSamples&&(f.defines.VSM_SAMPLES=i.blurSamples,g.defines.VSM_SAMPLES=i.blurSamples,f.needsUpdate=!0,g.needsUpdate=!0),null===i.mapPass&&(i.mapPass=new Gi(s.x,s.y,{format:Ct,type:ft})),f.uniforms.shadow_pass.value=i.map.depthTexture,f.uniforms.resolution.value=i.mapSize,f.uniforms.radius.value=i.radius,t.setRenderTarget(i.mapPass),t.clear(),t.renderBufferDirect(n,null,r,f,y,null),g.uniforms.shadow_pass.value=i.mapPass.texture,g.uniforms.resolution.value=i.mapSize,g.uniforms.radius.value=i.radius,t.setRenderTarget(i.map),t.clear(),t.renderBufferDirect(n,null,r,g,y,null)}function S(e,i,n,s){let r=null;const a=!0===n.isPointLight?e.customDistanceMaterial:e.customDepthMaterial;if(void 0!==a)r=a;else if(r=!0===n.isPointLight?d:c,t.localClippingEnabled&&!0===i.clipShadows&&Array.isArray(i.clippingPlanes)&&0!==i.clippingPlanes.length||i.displacementMap&&0!==i.displacementScale||i.alphaMap&&i.alphaTest>0||i.map&&i.alphaTest>0||!0===i.alphaToCoverage){const t=r.uuid,e=i.uuid;let n=u[t];void 0===n&&(n={},u[t]=n);let s=n[e];void 0===s&&(s=r.clone(),n[e]=s,i.addEventListener("dispose",w)),r=s}if(r.visible=i.visible,r.wireframe=i.wireframe,r.side=3===s?null!==i.shadowSide?i.shadowSide:i.side:null!==i.shadowSide?i.shadowSide:m[i.side],r.alphaMap=i.alphaMap,r.alphaTest=!0===i.alphaToCoverage?.5:i.alphaTest,r.map=i.map,r.clipShadows=i.clipShadows,r.clippingPlanes=i.clippingPlanes,r.clipIntersection=i.clipIntersection,r.displacementMap=i.displacementMap,r.displacementScale=i.displacementScale,r.displacementBias=i.displacementBias,r.wireframeLinewidth=i.wireframeLinewidth,r.linewidth=i.linewidth,!0===n.isPointLight&&!0===r.isMeshDistanceMaterial){t.properties.get(r).light=n}return r}function M(i,s,r,a,o){if(!1===i.visible)return;if(i.layers.test(s.layers)&&(i.isMesh||i.isLine||i.isPoints)&&(i.castShadow||i.receiveShadow&&3===o)&&(!i.frustumCulled||n.intersectsObject(i))){i.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,i.matrixWorld);const n=e.update(i),l=i.material;if(Array.isArray(l)){const e=n.groups;for(let h=0,c=e.length;h<c;h++){const c=e[h],d=l[c.materialIndex];if(d&&d.visible){const e=S(i,d,a,o);i.onBeforeShadow(t,i,s,r,n,e,c),t.renderBufferDirect(r,null,n,e,i,c),i.onAfterShadow(t,i,s,r,n,e,c)}}}else if(l.visible){const e=S(i,l,a,o);i.onBeforeShadow(t,i,s,r,n,e,null),t.renderBufferDirect(r,null,n,e,i,null),i.onAfterShadow(t,i,s,r,n,e,null)}}const l=i.children;for(let t=0,e=l.length;t<e;t++)M(l[t],s,r,a,o)}function w(t){t.target.removeEventListener("dispose",w);for(const e in u){const i=u[e],n=t.target.uuid;if(n in i){i[n].dispose(),delete i[n]}}}this.render=function(e,i,a){if(!1===_.enabled)return;if(!1===_.autoUpdate&&!1===_.needsUpdate)return;if(0===e.length)return;2===this.type&&(ii("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=1);const o=t.getRenderTarget(),l=t.getActiveCubeFace(),c=t.getActiveMipmapLevel(),d=t.state;d.setBlending(0),!0===d.buffers.depth.getReversed()?d.buffers.color.setClear(0,0,0,0):d.buffers.color.setClear(1,1,1,1),d.buffers.depth.setTest(!0),d.setScissorTest(!1);const u=x!==this.type;u&&i.traverse(function(t){t.material&&(Array.isArray(t.material)?t.material.forEach(t=>t.needsUpdate=!0):t.material.needsUpdate=!0)});for(let o=0,l=e.length;o<l;o++){const l=e[o],c=l.shadow;if(void 0===c){ii("WebGLShadowMap:",l,"has no shadow.");continue}if(!1===c.autoUpdate&&!1===c.needsUpdate)continue;s.copy(c.mapSize);const m=c.getFrameExtents();s.multiply(m),r.copy(c.mapSize),(s.x>p||s.y>p)&&(s.x>p&&(r.x=Math.floor(p/m.x),s.x=r.x*m.x,c.mapSize.x=r.x),s.y>p&&(r.y=Math.floor(p/m.y),s.y=r.y*m.y,c.mapSize.y=r.y));const f=t.state.buffers.depth.getReversed();if(c.camera._reversedDepth=f,null===c.map||!0===u){if(null!==c.map&&(null!==c.map.depthTexture&&(c.map.depthTexture.dispose(),c.map.depthTexture=null),c.map.dispose()),3===this.type){if(l.isPointLight){ii("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}c.map=new Gi(s.x,s.y,{format:Ct,type:ft,minFilter:rt,magFilter:rt,generateMipmaps:!1}),c.map.texture.name=l.name+".shadowMap",c.map.depthTexture=new Ya(s.x,s.y,mt),c.map.depthTexture.name=l.name+".shadowMapDepth",c.map.depthTexture.format=wt,c.map.depthTexture.compareFunction=null,c.map.depthTexture.minFilter=it,c.map.depthTexture.magFilter=it}else l.isPointLight?(c.map=new Hd(s.x),c.map.depthTexture=new Za(s.x,pt)):(c.map=new Gi(s.x,s.y),c.map.depthTexture=new Ya(s.x,s.y,pt)),c.map.depthTexture.name=l.name+".shadowMap",c.map.depthTexture.format=wt,1===this.type?(c.map.depthTexture.compareFunction=f?Ge:Ue,c.map.depthTexture.minFilter=rt,c.map.depthTexture.magFilter=rt):(c.map.depthTexture.compareFunction=null,c.map.depthTexture.minFilter=it,c.map.depthTexture.magFilter=it);c.camera.updateProjectionMatrix()}const g=c.map.isWebGLCubeRenderTarget?6:1;for(let e=0;e<g;e++){if(c.map.isWebGLCubeRenderTarget)t.setRenderTarget(c.map,e),t.clear();else{0===e&&(t.setRenderTarget(c.map),t.clear());const i=c.getViewport(e);h.set(r.x*i.x,r.y*i.y,r.x*i.z,r.y*i.w),d.viewport(h)}if(l.isPointLight){const t=c.camera,i=c.matrix,n=l.distance||t.far;n!==t.far&&(t.far=n,t.updateProjectionMatrix()),Xp.setFromMatrixPosition(l.matrixWorld),t.position.copy(Xp),Yp.copy(t.position),Yp.add(Vp[e]),t.up.copy(Wp[e]),t.lookAt(Yp),t.updateMatrixWorld(),i.makeTranslation(-Xp.x,-Xp.y,-Xp.z),jp.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),c._frustum.setFromProjectionMatrix(jp,t.coordinateSystem,t.reversedDepth)}else c.updateMatrices(l);n=c.getFrustum(),M(i,a,c.camera,l,this.type)}!0!==c.isPointLightShadow&&3===this.type&&b(c,a),c.needsUpdate=!1}x=this.type,_.needsUpdate=!1,t.setRenderTarget(o,l,c)}}function qp(t,e){const i=new function(){let e=!1;const i=new ki;let n=null;const s=new ki(0,0,0,0);return{setMask:function(i){n===i||e||(t.colorMask(i,i,i,i),n=i)},setLocked:function(t){e=t},setClear:function(e,n,r,a,o){!0===o&&(e*=a,n*=a,r*=a),i.set(e,n,r,a),!1===s.equals(i)&&(t.clearColor(e,n,r,a),s.copy(i))},reset:function(){e=!1,n=null,s.set(-1,0,0,0)}}},n=new function(){let i=!1,n=!1,s=null,r=null,a=null;return{setReversed:function(t){if(n!==t){const i=e.get("EXT_clip_control");t?i.clipControlEXT(i.LOWER_LEFT_EXT,i.ZERO_TO_ONE_EXT):i.clipControlEXT(i.LOWER_LEFT_EXT,i.NEGATIVE_ONE_TO_ONE_EXT),n=t;const s=a;a=null,this.setClear(s)}},getReversed:function(){return n},setTest:function(e){e?st(t.DEPTH_TEST):rt(t.DEPTH_TEST)},setMask:function(e){s===e||i||(t.depthMask(e),s=e)},setFunc:function(e){if(n&&(e=ri[e]),r!==e){switch(e){case 0:t.depthFunc(t.NEVER);break;case 1:t.depthFunc(t.ALWAYS);break;case 2:t.depthFunc(t.LESS);break;case 3:default:t.depthFunc(t.LEQUAL);break;case 4:t.depthFunc(t.EQUAL);break;case 5:t.depthFunc(t.GEQUAL);break;case 6:t.depthFunc(t.GREATER);break;case 7:t.depthFunc(t.NOTEQUAL)}r=e}},setLocked:function(t){i=t},setClear:function(e){a!==e&&(a=e,n&&(e=1-e),t.clearDepth(e))},reset:function(){i=!1,s=null,r=null,a=null,n=!1}}},s=new function(){let e=!1,i=null,n=null,s=null,r=null,a=null,o=null,l=null,h=null;return{setTest:function(i){e||(i?st(t.STENCIL_TEST):rt(t.STENCIL_TEST))},setMask:function(n){i===n||e||(t.stencilMask(n),i=n)},setFunc:function(e,i,a){n===e&&s===i&&r===a||(t.stencilFunc(e,i,a),n=e,s=i,r=a)},setOp:function(e,i,n){a===e&&o===i&&l===n||(t.stencilOp(e,i,n),a=e,o=i,l=n)},setLocked:function(t){e=t},setClear:function(e){h!==e&&(t.clearStencil(e),h=e)},reset:function(){e=!1,i=null,n=null,s=null,r=null,a=null,o=null,l=null,h=null}}},r=new WeakMap,a=new WeakMap;let o={},l={},T=new WeakMap,C=[],D=null,R=!1,P=null,I=null,L=null,B=null,O=null,F=null,N=null,U=new En(0,0,0),k=0,z=!1,G=null,H=null,V=null,W=null,j=null;const X=t.getParameter(t.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let Y=!1,Z=0;const q=t.getParameter(t.VERSION);-1!==q.indexOf("WebGL")?(Z=parseFloat(/^WebGL (\d)/.exec(q)[1]),Y=Z>=1):-1!==q.indexOf("OpenGL ES")&&(Z=parseFloat(/^OpenGL ES (\d)/.exec(q)[1]),Y=Z>=2);let Q=null,K={};const J=t.getParameter(t.SCISSOR_BOX),$=t.getParameter(t.VIEWPORT),tt=(new ki).fromArray(J),et=(new ki).fromArray($);function it(e,i,n,s){const r=new Uint8Array(4),a=t.createTexture();t.bindTexture(e,a),t.texParameteri(e,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(e,t.TEXTURE_MAG_FILTER,t.NEAREST);for(let a=0;a<n;a++)e===t.TEXTURE_3D||e===t.TEXTURE_2D_ARRAY?t.texImage3D(i,0,t.RGBA,1,1,s,0,t.RGBA,t.UNSIGNED_BYTE,r):t.texImage2D(i+a,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,r);return a}const nt={};function st(e){!0!==o[e]&&(t.enable(e),o[e]=!0)}function rt(e){!1!==o[e]&&(t.disable(e),o[e]=!1)}nt[t.TEXTURE_2D]=it(t.TEXTURE_2D,t.TEXTURE_2D,1),nt[t.TEXTURE_CUBE_MAP]=it(t.TEXTURE_CUBE_MAP,t.TEXTURE_CUBE_MAP_POSITIVE_X,6),nt[t.TEXTURE_2D_ARRAY]=it(t.TEXTURE_2D_ARRAY,t.TEXTURE_2D_ARRAY,1,1),nt[t.TEXTURE_3D]=it(t.TEXTURE_3D,t.TEXTURE_3D,1,1),i.setClear(0,0,0,1),n.setClear(1),s.setClear(0),st(t.DEPTH_TEST),n.setFunc(3),ht(!1),ct(1),st(t.CULL_FACE),lt(0);const at={[h]:t.FUNC_ADD,[c]:t.FUNC_SUBTRACT,[d]:t.FUNC_REVERSE_SUBTRACT};at[103]=t.MIN,at[104]=t.MAX;const ot={[u]:t.ZERO,[p]:t.ONE,[m]:t.SRC_COLOR,[g]:t.SRC_ALPHA,[S]:t.SRC_ALPHA_SATURATE,[x]:t.DST_COLOR,[y]:t.DST_ALPHA,[f]:t.ONE_MINUS_SRC_COLOR,[v]:t.ONE_MINUS_SRC_ALPHA,[b]:t.ONE_MINUS_DST_COLOR,[_]:t.ONE_MINUS_DST_ALPHA,[M]:t.CONSTANT_COLOR,[w]:t.ONE_MINUS_CONSTANT_COLOR,[A]:t.CONSTANT_ALPHA,[E]:t.ONE_MINUS_CONSTANT_ALPHA};function lt(e,i,n,s,r,a,o,l,c,d){if(0!==e){if(!1===R&&(st(t.BLEND),R=!0),5===e)r=r||i,a=a||n,o=o||s,i===I&&r===O||(t.blendEquationSeparate(at[i],at[r]),I=i,O=r),n===L&&s===B&&a===F&&o===N||(t.blendFuncSeparate(ot[n],ot[s],ot[a],ot[o]),L=n,B=s,F=a,N=o),!1!==l.equals(U)&&c===k||(t.blendColor(l.r,l.g,l.b,c),U.copy(l),k=c),P=e,z=!1;else if(e!==P||d!==z){if(I===h&&O===h||(t.blendEquation(t.FUNC_ADD),I=h,O=h),d)switch(e){case 1:t.blendFuncSeparate(t.ONE,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA);break;case 2:t.blendFunc(t.ONE,t.ONE);break;case 3:t.blendFuncSeparate(t.ZERO,t.ONE_MINUS_SRC_COLOR,t.ZERO,t.ONE);break;case 4:t.blendFuncSeparate(t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ZERO,t.ONE);break;default:ni("WebGLState: Invalid blending: ",e)}else switch(e){case 1:t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA);break;case 2:t.blendFuncSeparate(t.SRC_ALPHA,t.ONE,t.ONE,t.ONE);break;case 3:ni("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case 4:ni("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:ni("WebGLState: Invalid blending: ",e)}L=null,B=null,F=null,N=null,U.set(0,0,0),k=0,P=e,z=d}}else!0===R&&(rt(t.BLEND),R=!1)}function ht(e){G!==e&&(e?t.frontFace(t.CW):t.frontFace(t.CCW),G=e)}function ct(e){0!==e?(st(t.CULL_FACE),e!==H&&(1===e?t.cullFace(t.BACK):2===e?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):rt(t.CULL_FACE),H=e}function dt(e,i,s){e?(st(t.POLYGON_OFFSET_FILL),W===i&&j===s||(W=i,j=s,n.getReversed()&&(i=-i),t.polygonOffset(i,s))):rt(t.POLYGON_OFFSET_FILL)}return{buffers:{color:i,depth:n,stencil:s},enable:st,disable:rt,bindFramebuffer:function(e,i){return l[e]!==i&&(t.bindFramebuffer(e,i),l[e]=i,e===t.DRAW_FRAMEBUFFER&&(l[t.FRAMEBUFFER]=i),e===t.FRAMEBUFFER&&(l[t.DRAW_FRAMEBUFFER]=i),!0)},drawBuffers:function(e,i){let n=C,s=!1;if(e){n=T.get(i),void 0===n&&(n=[],T.set(i,n));const r=e.textures;if(n.length!==r.length||n[0]!==t.COLOR_ATTACHMENT0){for(let e=0,i=r.length;e<i;e++)n[e]=t.COLOR_ATTACHMENT0+e;n.length=r.length,s=!0}}else n[0]!==t.BACK&&(n[0]=t.BACK,s=!0);s&&t.drawBuffers(n)},useProgram:function(e){return D!==e&&(t.useProgram(e),D=e,!0)},setBlending:lt,setMaterial:function(e,r){2===e.side?rt(t.CULL_FACE):st(t.CULL_FACE);let a=1===e.side;r&&(a=!a),ht(a),1===e.blending&&!1===e.transparent?lt(0):lt(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.blendColor,e.blendAlpha,e.premultipliedAlpha),n.setFunc(e.depthFunc),n.setTest(e.depthTest),n.setMask(e.depthWrite),i.setMask(e.colorWrite);const o=e.stencilWrite;s.setTest(o),o&&(s.setMask(e.stencilWriteMask),s.setFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),s.setOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),dt(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),!0===e.alphaToCoverage?st(t.SAMPLE_ALPHA_TO_COVERAGE):rt(t.SAMPLE_ALPHA_TO_COVERAGE)},setFlipSided:ht,setCullFace:ct,setLineWidth:function(e){e!==V&&(Y&&t.lineWidth(e),V=e)},setPolygonOffset:dt,setScissorTest:function(e){e?st(t.SCISSOR_TEST):rt(t.SCISSOR_TEST)},activeTexture:function(e){void 0===e&&(e=t.TEXTURE0+X-1),Q!==e&&(t.activeTexture(e),Q=e)},bindTexture:function(e,i,n){void 0===n&&(n=null===Q?t.TEXTURE0+X-1:Q);let s=K[n];void 0===s&&(s={type:void 0,texture:void 0},K[n]=s),s.type===e&&s.texture===i||(Q!==n&&(t.activeTexture(n),Q=n),t.bindTexture(e,i||nt[e]),s.type=e,s.texture=i)},unbindTexture:function(){const e=K[Q];void 0!==e&&void 0!==e.type&&(t.bindTexture(e.type,null),e.type=void 0,e.texture=void 0)},compressedTexImage2D:function(){try{t.compressedTexImage2D(...arguments)}catch(t){ni("WebGLState:",t)}},compressedTexImage3D:function(){try{t.compressedTexImage3D(...arguments)}catch(t){ni("WebGLState:",t)}},texImage2D:function(){try{t.texImage2D(...arguments)}catch(t){ni("WebGLState:",t)}},texImage3D:function(){try{t.texImage3D(...arguments)}catch(t){ni("WebGLState:",t)}},updateUBOMapping:function(e,i){let n=a.get(i);void 0===n&&(n=new WeakMap,a.set(i,n));let s=n.get(e);void 0===s&&(s=t.getUniformBlockIndex(i,e.name),n.set(e,s))},uniformBlockBinding:function(e,i){const n=a.get(i).get(e);r.get(i)!==n&&(t.uniformBlockBinding(i,n,e.__bindingPointIndex),r.set(i,n))},texStorage2D:function(){try{t.texStorage2D(...arguments)}catch(t){ni("WebGLState:",t)}},texStorage3D:function(){try{t.texStorage3D(...arguments)}catch(t){ni("WebGLState:",t)}},texSubImage2D:function(){try{t.texSubImage2D(...arguments)}catch(t){ni("WebGLState:",t)}},texSubImage3D:function(){try{t.texSubImage3D(...arguments)}catch(t){ni("WebGLState:",t)}},compressedTexSubImage2D:function(){try{t.compressedTexSubImage2D(...arguments)}catch(t){ni("WebGLState:",t)}},compressedTexSubImage3D:function(){try{t.compressedTexSubImage3D(...arguments)}catch(t){ni("WebGLState:",t)}},scissor:function(e){!1===tt.equals(e)&&(t.scissor(e.x,e.y,e.z,e.w),tt.copy(e))},viewport:function(e){!1===et.equals(e)&&(t.viewport(e.x,e.y,e.z,e.w),et.copy(e))},reset:function(){t.disable(t.BLEND),t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST),t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.SCISSOR_TEST),t.disable(t.STENCIL_TEST),t.disable(t.SAMPLE_ALPHA_TO_COVERAGE),t.blendEquation(t.FUNC_ADD),t.blendFunc(t.ONE,t.ZERO),t.blendFuncSeparate(t.ONE,t.ZERO,t.ONE,t.ZERO),t.blendColor(0,0,0,0),t.colorMask(!0,!0,!0,!0),t.clearColor(0,0,0,0),t.depthMask(!0),t.depthFunc(t.LESS),n.setReversed(!1),t.clearDepth(1),t.stencilMask(4294967295),t.stencilFunc(t.ALWAYS,0,4294967295),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),t.clearStencil(0),t.cullFace(t.BACK),t.frontFace(t.CCW),t.polygonOffset(0,0),t.activeTexture(t.TEXTURE0),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),t.bindFramebuffer(t.READ_FRAMEBUFFER,null),t.useProgram(null),t.lineWidth(1),t.scissor(0,0,t.canvas.width,t.canvas.height),t.viewport(0,0,t.canvas.width,t.canvas.height),o={},Q=null,K={},l={},T=new WeakMap,C=[],D=null,R=!1,P=null,I=null,L=null,B=null,O=null,F=null,N=null,U=new En(0,0,0),k=0,z=!1,G=null,H=null,V=null,W=null,j=null,tt.set(0,0,t.canvas.width,t.canvas.height),et.set(0,0,t.canvas.width,t.canvas.height),i.reset(),n.reset(),s.reset()}}}function Qp(t,e,i,n,s,r,a){const o=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,l="undefined"!=typeof navigator&&/OculusBrowser/g.test(navigator.userAgent),h=new yi,c=new WeakMap;let d;const u=new WeakMap;let p=!1;try{p="undefined"!=typeof OffscreenCanvas&&null!==new OffscreenCanvas(1,1).getContext("2d")}catch(t){}function m(t,e){return p?new OffscreenCanvas(t,e):Qe("canvas")}function f(t,e,i){let n=1;const s=V(t);if((s.width>i||s.height>i)&&(n=i/Math.max(s.width,s.height)),n<1){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap||"undefined"!=typeof VideoFrame&&t instanceof VideoFrame){const i=Math.floor(n*s.width),r=Math.floor(n*s.height);void 0===d&&(d=m(i,r));const a=e?m(i,r):d;a.width=i,a.height=r;return a.getContext("2d").drawImage(t,0,0,i,r),ii("WebGLRenderer: Texture has been resized from ("+s.width+"x"+s.height+") to ("+i+"x"+r+")."),a}return"data"in t&&ii("WebGLRenderer: Image in DataTexture is too big ("+s.width+"x"+s.height+")."),t}return t}function g(t){return t.generateMipmaps}function v(e){t.generateMipmap(e)}function y(e){return e.isWebGLCubeRenderTarget?t.TEXTURE_CUBE_MAP:e.isWebGL3DRenderTarget?t.TEXTURE_3D:e.isWebGLArrayRenderTarget||e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:t.TEXTURE_2D}function _(i,n,s,r,a=!1){if(null!==i){if(void 0!==t[i])return t[i];ii("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+i+"'")}let o=n;if(n===t.RED&&(s===t.FLOAT&&(o=t.R32F),s===t.HALF_FLOAT&&(o=t.R16F),s===t.UNSIGNED_BYTE&&(o=t.R8)),n===t.RED_INTEGER&&(s===t.UNSIGNED_BYTE&&(o=t.R8UI),s===t.UNSIGNED_SHORT&&(o=t.R16UI),s===t.UNSIGNED_INT&&(o=t.R32UI),s===t.BYTE&&(o=t.R8I),s===t.SHORT&&(o=t.R16I),s===t.INT&&(o=t.R32I)),n===t.RG&&(s===t.FLOAT&&(o=t.RG32F),s===t.HALF_FLOAT&&(o=t.RG16F),s===t.UNSIGNED_BYTE&&(o=t.RG8)),n===t.RG_INTEGER&&(s===t.UNSIGNED_BYTE&&(o=t.RG8UI),s===t.UNSIGNED_SHORT&&(o=t.RG16UI),s===t.UNSIGNED_INT&&(o=t.RG32UI),s===t.BYTE&&(o=t.RG8I),s===t.SHORT&&(o=t.RG16I),s===t.INT&&(o=t.RG32I)),n===t.RGB_INTEGER&&(s===t.UNSIGNED_BYTE&&(o=t.RGB8UI),s===t.UNSIGNED_SHORT&&(o=t.RGB16UI),s===t.UNSIGNED_INT&&(o=t.RGB32UI),s===t.BYTE&&(o=t.RGB8I),s===t.SHORT&&(o=t.RGB16I),s===t.INT&&(o=t.RGB32I)),n===t.RGBA_INTEGER&&(s===t.UNSIGNED_BYTE&&(o=t.RGBA8UI),s===t.UNSIGNED_SHORT&&(o=t.RGBA16UI),s===t.UNSIGNED_INT&&(o=t.RGBA32UI),s===t.BYTE&&(o=t.RGBA8I),s===t.SHORT&&(o=t.RGBA16I),s===t.INT&&(o=t.RGBA32I)),n===t.RGB&&(s===t.UNSIGNED_INT_5_9_9_9_REV&&(o=t.RGB9_E5),s===t.UNSIGNED_INT_10F_11F_11F_REV&&(o=t.R11F_G11F_B10F)),n===t.RGBA){const e=a?Ce:Ci.getTransfer(r);s===t.FLOAT&&(o=t.RGBA32F),s===t.HALF_FLOAT&&(o=t.RGBA16F),s===t.UNSIGNED_BYTE&&(o=e===De?t.SRGB8_ALPHA8:t.RGBA8),s===t.UNSIGNED_SHORT_4_4_4_4&&(o=t.RGBA4),s===t.UNSIGNED_SHORT_5_5_5_1&&(o=t.RGB5_A1)}return o!==t.R16F&&o!==t.R32F&&o!==t.RG16F&&o!==t.RG32F&&o!==t.RGBA16F&&o!==t.RGBA32F||e.get("EXT_color_buffer_float"),o}function x(e,i){let n;return e?null===i||i===pt||i===yt?n=t.DEPTH24_STENCIL8:i===mt?n=t.DEPTH32F_STENCIL8:i===dt&&(n=t.DEPTH24_STENCIL8,ii("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):null===i||i===pt||i===yt?n=t.DEPTH_COMPONENT24:i===mt?n=t.DEPTH_COMPONENT32F:i===dt&&(n=t.DEPTH_COMPONENT16),n}function b(t,e){return!0===g(t)||t.isFramebufferTexture&&t.minFilter!==it&&t.minFilter!==rt?Math.log2(Math.max(e.width,e.height))+1:void 0!==t.mipmaps&&t.mipmaps.length>0?t.mipmaps.length:t.isCompressedTexture&&Array.isArray(t.image)?e.mipmaps.length:1}function S(t){const e=t.target;e.removeEventListener("dispose",S),function(t){const e=n.get(t);if(void 0===e.__webglInit)return;const i=t.source,s=u.get(i);if(s){const n=s[e.__cacheKey];n.usedTimes--,0===n.usedTimes&&w(t),0===Object.keys(s).length&&u.delete(i)}n.remove(t)}(e),e.isVideoTexture&&c.delete(e)}function M(e){const i=e.target;i.removeEventListener("dispose",M),function(e){const i=n.get(e);e.depthTexture&&(e.depthTexture.dispose(),n.remove(e.depthTexture));if(e.isWebGLCubeRenderTarget)for(let e=0;e<6;e++){if(Array.isArray(i.__webglFramebuffer[e]))for(let n=0;n<i.__webglFramebuffer[e].length;n++)t.deleteFramebuffer(i.__webglFramebuffer[e][n]);else t.deleteFramebuffer(i.__webglFramebuffer[e]);i.__webglDepthbuffer&&t.deleteRenderbuffer(i.__webglDepthbuffer[e])}else{if(Array.isArray(i.__webglFramebuffer))for(let e=0;e<i.__webglFramebuffer.length;e++)t.deleteFramebuffer(i.__webglFramebuffer[e]);else t.deleteFramebuffer(i.__webglFramebuffer);if(i.__webglDepthbuffer&&t.deleteRenderbuffer(i.__webglDepthbuffer),i.__webglMultisampledFramebuffer&&t.deleteFramebuffer(i.__webglMultisampledFramebuffer),i.__webglColorRenderbuffer)for(let e=0;e<i.__webglColorRenderbuffer.length;e++)i.__webglColorRenderbuffer[e]&&t.deleteRenderbuffer(i.__webglColorRenderbuffer[e]);i.__webglDepthRenderbuffer&&t.deleteRenderbuffer(i.__webglDepthRenderbuffer)}const s=e.textures;for(let e=0,i=s.length;e<i;e++){const i=n.get(s[e]);i.__webglTexture&&(t.deleteTexture(i.__webglTexture),a.memory.textures--),n.remove(s[e])}n.remove(e)}(i)}function w(e){const i=n.get(e);t.deleteTexture(i.__webglTexture);const s=e.source;delete u.get(s)[i.__cacheKey],a.memory.textures--}let A=0;function E(e,s){const r=n.get(e);if(e.isVideoTexture&&function(t){const e=a.render.frame;c.get(t)!==e&&(c.set(t,e),t.update())}(e),!1===e.isRenderTargetTexture&&!0!==e.isExternalTexture&&e.version>0&&r.__version!==e.version){const t=e.image;if(null===t)ii("WebGLRenderer: Texture marked for update but no image data found.");else{if(!1!==t.complete)return void L(r,e,s);ii("WebGLRenderer: Texture marked for update but image is incomplete")}}else e.isExternalTexture&&(r.__webglTexture=e.sourceTexture?e.sourceTexture:null);i.bindTexture(t.TEXTURE_2D,r.__webglTexture,t.TEXTURE0+s)}const T={[$]:t.REPEAT,[tt]:t.CLAMP_TO_EDGE,[et]:t.MIRRORED_REPEAT},C={[it]:t.NEAREST,[nt]:t.NEAREST_MIPMAP_NEAREST,[st]:t.NEAREST_MIPMAP_LINEAR,[rt]:t.LINEAR,[at]:t.LINEAR_MIPMAP_NEAREST,[ot]:t.LINEAR_MIPMAP_LINEAR},D={[Oe]:t.NEVER,[He]:t.ALWAYS,[Fe]:t.LESS,[Ue]:t.LEQUAL,[Ne]:t.EQUAL,[Ge]:t.GEQUAL,[ke]:t.GREATER,[ze]:t.NOTEQUAL};function R(i,r){if(r.type!==mt||!1!==e.has("OES_texture_float_linear")||r.magFilter!==rt&&r.magFilter!==at&&r.magFilter!==st&&r.magFilter!==ot&&r.minFilter!==rt&&r.minFilter!==at&&r.minFilter!==st&&r.minFilter!==ot||ii("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),t.texParameteri(i,t.TEXTURE_WRAP_S,T[r.wrapS]),t.texParameteri(i,t.TEXTURE_WRAP_T,T[r.wrapT]),i!==t.TEXTURE_3D&&i!==t.TEXTURE_2D_ARRAY||t.texParameteri(i,t.TEXTURE_WRAP_R,T[r.wrapR]),t.texParameteri(i,t.TEXTURE_MAG_FILTER,C[r.magFilter]),t.texParameteri(i,t.TEXTURE_MIN_FILTER,C[r.minFilter]),r.compareFunction&&(t.texParameteri(i,t.TEXTURE_COMPARE_MODE,t.COMPARE_REF_TO_TEXTURE),t.texParameteri(i,t.TEXTURE_COMPARE_FUNC,D[r.compareFunction])),!0===e.has("EXT_texture_filter_anisotropic")){if(r.magFilter===it)return;if(r.minFilter!==st&&r.minFilter!==ot)return;if(r.type===mt&&!1===e.has("OES_texture_float_linear"))return;if(r.anisotropy>1||n.get(r).__currentAnisotropy){const a=e.get("EXT_texture_filter_anisotropic");t.texParameterf(i,a.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(r.anisotropy,s.getMaxAnisotropy())),n.get(r).__currentAnisotropy=r.anisotropy}}}function P(e,i){let n=!1;void 0===e.__webglInit&&(e.__webglInit=!0,i.addEventListener("dispose",S));const s=i.source;let r=u.get(s);void 0===r&&(r={},u.set(s,r));const o=function(t){const e=[];return e.push(t.wrapS),e.push(t.wrapT),e.push(t.wrapR||0),e.push(t.magFilter),e.push(t.minFilter),e.push(t.anisotropy),e.push(t.internalFormat),e.push(t.format),e.push(t.type),e.push(t.generateMipmaps),e.push(t.premultiplyAlpha),e.push(t.flipY),e.push(t.unpackAlignment),e.push(t.colorSpace),e.join()}(i);if(o!==e.__cacheKey){void 0===r[o]&&(r[o]={texture:t.createTexture(),usedTimes:0},a.memory.textures++,n=!0),r[o].usedTimes++;const s=r[e.__cacheKey];void 0!==s&&(r[e.__cacheKey].usedTimes--,0===s.usedTimes&&w(i)),e.__cacheKey=o,e.__webglTexture=r[o].texture}return n}function I(t,e,i){return Math.floor(Math.floor(t/i)/e)}function L(e,a,o){let l=t.TEXTURE_2D;(a.isDataArrayTexture||a.isCompressedArrayTexture)&&(l=t.TEXTURE_2D_ARRAY),a.isData3DTexture&&(l=t.TEXTURE_3D);const h=P(e,a),c=a.source;i.bindTexture(l,e.__webglTexture,t.TEXTURE0+o);const d=n.get(c);if(c.version!==d.__version||!0===h){i.activeTexture(t.TEXTURE0+o);const e=Ci.getPrimaries(Ci.workingColorSpace),n=a.colorSpace===Ae?null:Ci.getPrimaries(a.colorSpace),u=a.colorSpace===Ae||e===n?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,a.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,a.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,u);let p=f(a.image,!1,s.maxTextureSize);p=H(a,p);const m=r.convert(a.format,a.colorSpace),y=r.convert(a.type);let S,M=_(a.internalFormat,m,y,a.colorSpace,a.isVideoTexture);R(l,a);const w=a.mipmaps,A=!0!==a.isVideoTexture,E=void 0===d.__version||!0===h,T=c.dataReady,C=b(a,p);if(a.isDepthTexture)M=x(a.format===At,a.type),E&&(A?i.texStorage2D(t.TEXTURE_2D,1,M,p.width,p.height):i.texImage2D(t.TEXTURE_2D,0,M,p.width,p.height,0,m,y,null));else if(a.isDataTexture)if(w.length>0){A&&E&&i.texStorage2D(t.TEXTURE_2D,C,M,w[0].width,w[0].height);for(let e=0,n=w.length;e<n;e++)S=w[e],A?T&&i.texSubImage2D(t.TEXTURE_2D,e,0,0,S.width,S.height,m,y,S.data):i.texImage2D(t.TEXTURE_2D,e,M,S.width,S.height,0,m,y,S.data);a.generateMipmaps=!1}else A?(E&&i.texStorage2D(t.TEXTURE_2D,C,M,p.width,p.height),T&&function(e,n,s,r){const a=e.updateRanges;if(0===a.length)i.texSubImage2D(t.TEXTURE_2D,0,0,0,n.width,n.height,s,r,n.data);else{a.sort((t,e)=>t.start-e.start);let o=0;for(let t=1;t<a.length;t++){const e=a[o],i=a[t],s=e.start+e.count,r=I(i.start,n.width,4),l=I(e.start,n.width,4);i.start<=s+1&&r===l&&I(i.start+i.count-1,n.width,4)===r?e.count=Math.max(e.count,i.start+i.count-e.start):(++o,a[o]=i)}a.length=o+1;const l=t.getParameter(t.UNPACK_ROW_LENGTH),h=t.getParameter(t.UNPACK_SKIP_PIXELS),c=t.getParameter(t.UNPACK_SKIP_ROWS);t.pixelStorei(t.UNPACK_ROW_LENGTH,n.width);for(let e=0,o=a.length;e<o;e++){const o=a[e],l=Math.floor(o.start/4),h=Math.ceil(o.count/4),c=l%n.width,d=Math.floor(l/n.width),u=h,p=1;t.pixelStorei(t.UNPACK_SKIP_PIXELS,c),t.pixelStorei(t.UNPACK_SKIP_ROWS,d),i.texSubImage2D(t.TEXTURE_2D,0,c,d,u,p,s,r,n.data)}e.clearUpdateRanges(),t.pixelStorei(t.UNPACK_ROW_LENGTH,l),t.pixelStorei(t.UNPACK_SKIP_PIXELS,h),t.pixelStorei(t.UNPACK_SKIP_ROWS,c)}}(a,p,m,y)):i.texImage2D(t.TEXTURE_2D,0,M,p.width,p.height,0,m,y,p.data);else if(a.isCompressedTexture)if(a.isCompressedArrayTexture){A&&E&&i.texStorage3D(t.TEXTURE_2D_ARRAY,C,M,w[0].width,w[0].height,p.depth);for(let e=0,n=w.length;e<n;e++)if(S=w[e],a.format!==Mt)if(null!==m)if(A){if(T)if(a.layerUpdates.size>0){const n=pd(S.width,S.height,a.format,a.type);for(const s of a.layerUpdates){const r=S.data.subarray(s*n/S.data.BYTES_PER_ELEMENT,(s+1)*n/S.data.BYTES_PER_ELEMENT);i.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,s,S.width,S.height,1,m,r)}a.clearLayerUpdates()}else i.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,S.width,S.height,p.depth,m,S.data)}else i.compressedTexImage3D(t.TEXTURE_2D_ARRAY,e,M,S.width,S.height,p.depth,0,S.data,0,0);else ii("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else A?T&&i.texSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,S.width,S.height,p.depth,m,y,S.data):i.texImage3D(t.TEXTURE_2D_ARRAY,e,M,S.width,S.height,p.depth,0,m,y,S.data)}else{A&&E&&i.texStorage2D(t.TEXTURE_2D,C,M,w[0].width,w[0].height);for(let e=0,n=w.length;e<n;e++)S=w[e],a.format!==Mt?null!==m?A?T&&i.compressedTexSubImage2D(t.TEXTURE_2D,e,0,0,S.width,S.height,m,S.data):i.compressedTexImage2D(t.TEXTURE_2D,e,M,S.width,S.height,0,S.data):ii("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):A?T&&i.texSubImage2D(t.TEXTURE_2D,e,0,0,S.width,S.height,m,y,S.data):i.texImage2D(t.TEXTURE_2D,e,M,S.width,S.height,0,m,y,S.data)}else if(a.isDataArrayTexture)if(A){if(E&&i.texStorage3D(t.TEXTURE_2D_ARRAY,C,M,p.width,p.height,p.depth),T)if(a.layerUpdates.size>0){const e=pd(p.width,p.height,a.format,a.type);for(const n of a.layerUpdates){const s=p.data.subarray(n*e/p.data.BYTES_PER_ELEMENT,(n+1)*e/p.data.BYTES_PER_ELEMENT);i.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,n,p.width,p.height,1,m,y,s)}a.clearLayerUpdates()}else i.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,0,p.width,p.height,p.depth,m,y,p.data)}else i.texImage3D(t.TEXTURE_2D_ARRAY,0,M,p.width,p.height,p.depth,0,m,y,p.data);else if(a.isData3DTexture)A?(E&&i.texStorage3D(t.TEXTURE_3D,C,M,p.width,p.height,p.depth),T&&i.texSubImage3D(t.TEXTURE_3D,0,0,0,0,p.width,p.height,p.depth,m,y,p.data)):i.texImage3D(t.TEXTURE_3D,0,M,p.width,p.height,p.depth,0,m,y,p.data);else if(a.isFramebufferTexture){if(E)if(A)i.texStorage2D(t.TEXTURE_2D,C,M,p.width,p.height);else{let e=p.width,n=p.height;for(let s=0;s<C;s++)i.texImage2D(t.TEXTURE_2D,s,M,e,n,0,m,y,null),e>>=1,n>>=1}}else if(w.length>0){if(A&&E){const e=V(w[0]);i.texStorage2D(t.TEXTURE_2D,C,M,e.width,e.height)}for(let e=0,n=w.length;e<n;e++)S=w[e],A?T&&i.texSubImage2D(t.TEXTURE_2D,e,0,0,m,y,S):i.texImage2D(t.TEXTURE_2D,e,M,m,y,S);a.generateMipmaps=!1}else if(A){if(E){const e=V(p);i.texStorage2D(t.TEXTURE_2D,C,M,e.width,e.height)}T&&i.texSubImage2D(t.TEXTURE_2D,0,0,0,m,y,p)}else i.texImage2D(t.TEXTURE_2D,0,M,m,y,p);g(a)&&v(l),d.__version=c.version,a.onUpdate&&a.onUpdate(a)}e.__version=a.version}function B(e,s,a,l,h,c){const d=r.convert(a.format,a.colorSpace),u=r.convert(a.type),p=_(a.internalFormat,d,u,a.colorSpace),m=n.get(s),f=n.get(a);if(f.__renderTarget=s,!m.__hasExternalTextures){const e=Math.max(1,s.width>>c),n=Math.max(1,s.height>>c);h===t.TEXTURE_3D||h===t.TEXTURE_2D_ARRAY?i.texImage3D(h,c,p,e,n,s.depth,0,d,u,null):i.texImage2D(h,c,p,e,n,0,d,u,null)}i.bindFramebuffer(t.FRAMEBUFFER,e),G(s)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,l,h,f.__webglTexture,0,z(s)):(h===t.TEXTURE_2D||h>=t.TEXTURE_CUBE_MAP_POSITIVE_X&&h<=t.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&t.framebufferTexture2D(t.FRAMEBUFFER,l,h,f.__webglTexture,c),i.bindFramebuffer(t.FRAMEBUFFER,null)}function O(e,i,n){if(t.bindRenderbuffer(t.RENDERBUFFER,e),i.depthBuffer){const s=i.depthTexture,r=s&&s.isDepthTexture?s.type:null,a=x(i.stencilBuffer,r),l=i.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;G(i)?o.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,z(i),a,i.width,i.height):n?t.renderbufferStorageMultisample(t.RENDERBUFFER,z(i),a,i.width,i.height):t.renderbufferStorage(t.RENDERBUFFER,a,i.width,i.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,l,t.RENDERBUFFER,e)}else{const e=i.textures;for(let s=0;s<e.length;s++){const a=e[s],l=r.convert(a.format,a.colorSpace),h=r.convert(a.type),c=_(a.internalFormat,l,h,a.colorSpace);G(i)?o.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,z(i),c,i.width,i.height):n?t.renderbufferStorageMultisample(t.RENDERBUFFER,z(i),c,i.width,i.height):t.renderbufferStorage(t.RENDERBUFFER,c,i.width,i.height)}}t.bindRenderbuffer(t.RENDERBUFFER,null)}function F(e,s,a){const l=!0===s.isWebGLCubeRenderTarget;if(i.bindFramebuffer(t.FRAMEBUFFER,e),!s.depthTexture||!s.depthTexture.isDepthTexture)throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");const h=n.get(s.depthTexture);if(h.__renderTarget=s,h.__webglTexture&&s.depthTexture.image.width===s.width&&s.depthTexture.image.height===s.height||(s.depthTexture.image.width=s.width,s.depthTexture.image.height=s.height,s.depthTexture.needsUpdate=!0),l){if(void 0===h.__webglInit&&(h.__webglInit=!0,s.depthTexture.addEventListener("dispose",S)),void 0===h.__webglTexture){h.__webglTexture=t.createTexture(),i.bindTexture(t.TEXTURE_CUBE_MAP,h.__webglTexture),R(t.TEXTURE_CUBE_MAP,s.depthTexture);const e=r.convert(s.depthTexture.format),n=r.convert(s.depthTexture.type);let a;s.depthTexture.format===wt?a=t.DEPTH_COMPONENT24:s.depthTexture.format===At&&(a=t.DEPTH24_STENCIL8);for(let i=0;i<6;i++)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+i,0,a,s.width,s.height,0,e,n,null)}}else E(s.depthTexture,0);const c=h.__webglTexture,d=z(s),u=l?t.TEXTURE_CUBE_MAP_POSITIVE_X+a:t.TEXTURE_2D,p=s.depthTexture.format===At?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(s.depthTexture.format===wt)G(s)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,p,u,c,0,d):t.framebufferTexture2D(t.FRAMEBUFFER,p,u,c,0);else{if(s.depthTexture.format!==At)throw new Error("Unknown depthTexture format");G(s)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,p,u,c,0,d):t.framebufferTexture2D(t.FRAMEBUFFER,p,u,c,0)}}function N(e){const s=n.get(e),r=!0===e.isWebGLCubeRenderTarget;if(s.__boundDepthTexture!==e.depthTexture){const t=e.depthTexture;if(s.__depthDisposeCallback&&s.__depthDisposeCallback(),t){const e=()=>{delete s.__boundDepthTexture,delete s.__depthDisposeCallback,t.removeEventListener("dispose",e)};t.addEventListener("dispose",e),s.__depthDisposeCallback=e}s.__boundDepthTexture=t}if(e.depthTexture&&!s.__autoAllocateDepthBuffer)if(r)for(let t=0;t<6;t++)F(s.__webglFramebuffer[t],e,t);else{const t=e.texture.mipmaps;t&&t.length>0?F(s.__webglFramebuffer[0],e,0):F(s.__webglFramebuffer,e,0)}else if(r){s.__webglDepthbuffer=[];for(let n=0;n<6;n++)if(i.bindFramebuffer(t.FRAMEBUFFER,s.__webglFramebuffer[n]),void 0===s.__webglDepthbuffer[n])s.__webglDepthbuffer[n]=t.createRenderbuffer(),O(s.__webglDepthbuffer[n],e,!1);else{const i=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,r=s.__webglDepthbuffer[n];t.bindRenderbuffer(t.RENDERBUFFER,r),t.framebufferRenderbuffer(t.FRAMEBUFFER,i,t.RENDERBUFFER,r)}}else{const n=e.texture.mipmaps;if(n&&n.length>0?i.bindFramebuffer(t.FRAMEBUFFER,s.__webglFramebuffer[0]):i.bindFramebuffer(t.FRAMEBUFFER,s.__webglFramebuffer),void 0===s.__webglDepthbuffer)s.__webglDepthbuffer=t.createRenderbuffer(),O(s.__webglDepthbuffer,e,!1);else{const i=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,n=s.__webglDepthbuffer;t.bindRenderbuffer(t.RENDERBUFFER,n),t.framebufferRenderbuffer(t.FRAMEBUFFER,i,t.RENDERBUFFER,n)}}i.bindFramebuffer(t.FRAMEBUFFER,null)}const U=[],k=[];function z(t){return Math.min(s.maxSamples,t.samples)}function G(t){const i=n.get(t);return t.samples>0&&!0===e.has("WEBGL_multisampled_render_to_texture")&&!1!==i.__useRenderToTexture}function H(t,e){const i=t.colorSpace,n=t.format,s=t.type;return!0===t.isCompressedTexture||!0===t.isVideoTexture||i!==Te&&i!==Ae&&(Ci.getTransfer(i)===De?n===Mt&&s===lt||ii("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):ni("WebGLTextures: Unsupported texture color space:",i)),e}function V(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement?(h.width=t.naturalWidth||t.width,h.height=t.naturalHeight||t.height):"undefined"!=typeof VideoFrame&&t instanceof VideoFrame?(h.width=t.displayWidth,h.height=t.displayHeight):(h.width=t.width,h.height=t.height),h}this.allocateTextureUnit=function(){const t=A;return t>=s.maxTextures&&ii("WebGLTextures: Trying to use "+t+" texture units while this GPU supports only "+s.maxTextures),A+=1,t},this.resetTextureUnits=function(){A=0},this.setTexture2D=E,this.setTexture2DArray=function(e,s){const r=n.get(e);!1===e.isRenderTargetTexture&&e.version>0&&r.__version!==e.version?L(r,e,s):(e.isExternalTexture&&(r.__webglTexture=e.sourceTexture?e.sourceTexture:null),i.bindTexture(t.TEXTURE_2D_ARRAY,r.__webglTexture,t.TEXTURE0+s))},this.setTexture3D=function(e,s){const r=n.get(e);!1===e.isRenderTargetTexture&&e.version>0&&r.__version!==e.version?L(r,e,s):i.bindTexture(t.TEXTURE_3D,r.__webglTexture,t.TEXTURE0+s)},this.setTextureCube=function(e,a){const o=n.get(e);!0!==e.isCubeDepthTexture&&e.version>0&&o.__version!==e.version?function(e,a,o){if(6!==a.image.length)return;const l=P(e,a),h=a.source;i.bindTexture(t.TEXTURE_CUBE_MAP,e.__webglTexture,t.TEXTURE0+o);const c=n.get(h);if(h.version!==c.__version||!0===l){i.activeTexture(t.TEXTURE0+o);const e=Ci.getPrimaries(Ci.workingColorSpace),n=a.colorSpace===Ae?null:Ci.getPrimaries(a.colorSpace),d=a.colorSpace===Ae||e===n?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,a.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,a.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,d);const u=a.isCompressedTexture||a.image[0].isCompressedTexture,p=a.image[0]&&a.image[0].isDataTexture,m=[];for(let t=0;t<6;t++)m[t]=u||p?p?a.image[t].image:a.image[t]:f(a.image[t],!0,s.maxCubemapSize),m[t]=H(a,m[t]);const y=m[0],x=r.convert(a.format,a.colorSpace),S=r.convert(a.type),M=_(a.internalFormat,x,S,a.colorSpace),w=!0!==a.isVideoTexture,A=void 0===c.__version||!0===l,E=h.dataReady;let T,C=b(a,y);if(R(t.TEXTURE_CUBE_MAP,a),u){w&&A&&i.texStorage2D(t.TEXTURE_CUBE_MAP,C,M,y.width,y.height);for(let e=0;e<6;e++){T=m[e].mipmaps;for(let n=0;n<T.length;n++){const s=T[n];a.format!==Mt?null!==x?w?E&&i.compressedTexSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n,0,0,s.width,s.height,x,s.data):i.compressedTexImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n,M,s.width,s.height,0,s.data):ii("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):w?E&&i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n,0,0,s.width,s.height,x,S,s.data):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n,M,s.width,s.height,0,x,S,s.data)}}}else{if(T=a.mipmaps,w&&A){T.length>0&&C++;const e=V(m[0]);i.texStorage2D(t.TEXTURE_CUBE_MAP,C,M,e.width,e.height)}for(let e=0;e<6;e++)if(p){w?E&&i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,m[e].width,m[e].height,x,S,m[e].data):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,M,m[e].width,m[e].height,0,x,S,m[e].data);for(let n=0;n<T.length;n++){const s=T[n].image[e].image;w?E&&i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n+1,0,0,s.width,s.height,x,S,s.data):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n+1,M,s.width,s.height,0,x,S,s.data)}}else{w?E&&i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,x,S,m[e]):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,M,x,S,m[e]);for(let n=0;n<T.length;n++){const s=T[n];w?E&&i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n+1,0,0,x,S,s.image[e]):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n+1,M,x,S,s.image[e])}}}g(a)&&v(t.TEXTURE_CUBE_MAP),c.__version=h.version,a.onUpdate&&a.onUpdate(a)}e.__version=a.version}(o,e,a):i.bindTexture(t.TEXTURE_CUBE_MAP,o.__webglTexture,t.TEXTURE0+a)},this.rebindTextures=function(e,i,s){const r=n.get(e);void 0!==i&&B(r.__webglFramebuffer,e,e.texture,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,0),void 0!==s&&N(e)},this.setupRenderTarget=function(e){const s=e.texture,o=n.get(e),l=n.get(s);e.addEventListener("dispose",M);const h=e.textures,c=!0===e.isWebGLCubeRenderTarget,d=h.length>1;if(d||(void 0===l.__webglTexture&&(l.__webglTexture=t.createTexture()),l.__version=s.version,a.memory.textures++),c){o.__webglFramebuffer=[];for(let e=0;e<6;e++)if(s.mipmaps&&s.mipmaps.length>0){o.__webglFramebuffer[e]=[];for(let i=0;i<s.mipmaps.length;i++)o.__webglFramebuffer[e][i]=t.createFramebuffer()}else o.__webglFramebuffer[e]=t.createFramebuffer()}else{if(s.mipmaps&&s.mipmaps.length>0){o.__webglFramebuffer=[];for(let e=0;e<s.mipmaps.length;e++)o.__webglFramebuffer[e]=t.createFramebuffer()}else o.__webglFramebuffer=t.createFramebuffer();if(d)for(let e=0,i=h.length;e<i;e++){const i=n.get(h[e]);void 0===i.__webglTexture&&(i.__webglTexture=t.createTexture(),a.memory.textures++)}if(e.samples>0&&!1===G(e)){o.__webglMultisampledFramebuffer=t.createFramebuffer(),o.__webglColorRenderbuffer=[],i.bindFramebuffer(t.FRAMEBUFFER,o.__webglMultisampledFramebuffer);for(let i=0;i<h.length;i++){const n=h[i];o.__webglColorRenderbuffer[i]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,o.__webglColorRenderbuffer[i]);const s=r.convert(n.format,n.colorSpace),a=r.convert(n.type),l=_(n.internalFormat,s,a,n.colorSpace,!0===e.isXRRenderTarget),c=z(e);t.renderbufferStorageMultisample(t.RENDERBUFFER,c,l,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+i,t.RENDERBUFFER,o.__webglColorRenderbuffer[i])}t.bindRenderbuffer(t.RENDERBUFFER,null),e.depthBuffer&&(o.__webglDepthRenderbuffer=t.createRenderbuffer(),O(o.__webglDepthRenderbuffer,e,!0)),i.bindFramebuffer(t.FRAMEBUFFER,null)}}if(c){i.bindTexture(t.TEXTURE_CUBE_MAP,l.__webglTexture),R(t.TEXTURE_CUBE_MAP,s);for(let i=0;i<6;i++)if(s.mipmaps&&s.mipmaps.length>0)for(let n=0;n<s.mipmaps.length;n++)B(o.__webglFramebuffer[i][n],e,s,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+i,n);else B(o.__webglFramebuffer[i],e,s,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+i,0);g(s)&&v(t.TEXTURE_CUBE_MAP),i.unbindTexture()}else if(d){for(let s=0,r=h.length;s<r;s++){const r=h[s],a=n.get(r);let l=t.TEXTURE_2D;(e.isWebGL3DRenderTarget||e.isWebGLArrayRenderTarget)&&(l=e.isWebGL3DRenderTarget?t.TEXTURE_3D:t.TEXTURE_2D_ARRAY),i.bindTexture(l,a.__webglTexture),R(l,r),B(o.__webglFramebuffer,e,r,t.COLOR_ATTACHMENT0+s,l,0),g(r)&&v(l)}i.unbindTexture()}else{let n=t.TEXTURE_2D;if((e.isWebGL3DRenderTarget||e.isWebGLArrayRenderTarget)&&(n=e.isWebGL3DRenderTarget?t.TEXTURE_3D:t.TEXTURE_2D_ARRAY),i.bindTexture(n,l.__webglTexture),R(n,s),s.mipmaps&&s.mipmaps.length>0)for(let i=0;i<s.mipmaps.length;i++)B(o.__webglFramebuffer[i],e,s,t.COLOR_ATTACHMENT0,n,i);else B(o.__webglFramebuffer,e,s,t.COLOR_ATTACHMENT0,n,0);g(s)&&v(n),i.unbindTexture()}e.depthBuffer&&N(e)},this.updateRenderTargetMipmap=function(t){const e=t.textures;for(let s=0,r=e.length;s<r;s++){const r=e[s];if(g(r)){const e=y(t),s=n.get(r).__webglTexture;i.bindTexture(e,s),v(e),i.unbindTexture()}}},this.updateMultisampleRenderTarget=function(e){if(e.samples>0)if(!1===G(e)){const s=e.textures,r=e.width,a=e.height;let o=t.COLOR_BUFFER_BIT;const h=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,c=n.get(e),d=s.length>1;if(d)for(let e=0;e<s.length;e++)i.bindFramebuffer(t.FRAMEBUFFER,c.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,null),i.bindFramebuffer(t.FRAMEBUFFER,c.__webglFramebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,null,0);i.bindFramebuffer(t.READ_FRAMEBUFFER,c.__webglMultisampledFramebuffer);const u=e.texture.mipmaps;u&&u.length>0?i.bindFramebuffer(t.DRAW_FRAMEBUFFER,c.__webglFramebuffer[0]):i.bindFramebuffer(t.DRAW_FRAMEBUFFER,c.__webglFramebuffer);for(let i=0;i<s.length;i++){if(e.resolveDepthBuffer&&(e.depthBuffer&&(o|=t.DEPTH_BUFFER_BIT),e.stencilBuffer&&e.resolveStencilBuffer&&(o|=t.STENCIL_BUFFER_BIT)),d){t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,c.__webglColorRenderbuffer[i]);const e=n.get(s[i]).__webglTexture;t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e,0)}t.blitFramebuffer(0,0,r,a,0,0,r,a,o,t.NEAREST),!0===l&&(U.length=0,k.length=0,U.push(t.COLOR_ATTACHMENT0+i),e.depthBuffer&&!1===e.resolveDepthBuffer&&(U.push(h),k.push(h),t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,k)),t.invalidateFramebuffer(t.READ_FRAMEBUFFER,U))}if(i.bindFramebuffer(t.READ_FRAMEBUFFER,null),i.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),d)for(let e=0;e<s.length;e++){i.bindFramebuffer(t.FRAMEBUFFER,c.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,c.__webglColorRenderbuffer[e]);const r=n.get(s[e]).__webglTexture;i.bindFramebuffer(t.FRAMEBUFFER,c.__webglFramebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,r,0)}i.bindFramebuffer(t.DRAW_FRAMEBUFFER,c.__webglMultisampledFramebuffer)}else if(e.depthBuffer&&!1===e.resolveDepthBuffer&&l){const i=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,[i])}},this.setupDepthRenderbuffer=N,this.setupFrameBufferTexture=B,this.useMultisampledRTT=G,this.isReversedDepthBuffer=function(){return i.buffers.depth.getReversed()}}function Kp(t,e){return{convert:function(i,n=""){let s;const r=Ci.getTransfer(n);if(i===lt)return t.UNSIGNED_BYTE;if(i===gt)return t.UNSIGNED_SHORT_4_4_4_4;if(i===vt)return t.UNSIGNED_SHORT_5_5_5_1;if(i===_t)return t.UNSIGNED_INT_5_9_9_9_REV;if(i===xt)return t.UNSIGNED_INT_10F_11F_11F_REV;if(i===ht)return t.BYTE;if(i===ct)return t.SHORT;if(i===dt)return t.UNSIGNED_SHORT;if(i===ut)return t.INT;if(i===pt)return t.UNSIGNED_INT;if(i===mt)return t.FLOAT;if(i===ft)return t.HALF_FLOAT;if(i===bt)return t.ALPHA;if(i===St)return t.RGB;if(i===Mt)return t.RGBA;if(i===wt)return t.DEPTH_COMPONENT;if(i===At)return t.DEPTH_STENCIL;if(i===Et)return t.RED;if(i===Tt)return t.RED_INTEGER;if(i===Ct)return t.RG;if(i===Dt)return t.RG_INTEGER;if(i===Rt)return t.RGBA_INTEGER;if(i===Pt||i===It||i===Lt||i===Bt)if(r===De){if(s=e.get("WEBGL_compressed_texture_s3tc_srgb"),null===s)return null;if(i===Pt)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===It)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===Lt)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===Bt)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(s=e.get("WEBGL_compressed_texture_s3tc"),null===s)return null;if(i===Pt)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===It)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===Lt)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===Bt)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(i===Ot||i===Ft||i===Nt||i===Ut){if(s=e.get("WEBGL_compressed_texture_pvrtc"),null===s)return null;if(i===Ot)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(i===Ft)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(i===Nt)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(i===Ut)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(i===kt||i===zt||i===Gt||i===Ht||i===Vt||i===Wt||i===jt){if(s=e.get("WEBGL_compressed_texture_etc"),null===s)return null;if(i===kt||i===zt)return r===De?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(i===Gt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(i===Ht)return s.COMPRESSED_R11_EAC;if(i===Vt)return s.COMPRESSED_SIGNED_R11_EAC;if(i===Wt)return s.COMPRESSED_RG11_EAC;if(i===jt)return s.COMPRESSED_SIGNED_RG11_EAC}if(i===Xt||i===Yt||i===Zt||i===qt||i===Qt||i===Kt||i===Jt||i===$t||i===te||i===ee||i===ie||i===ne||i===se||i===re){if(s=e.get("WEBGL_compressed_texture_astc"),null===s)return null;if(i===Xt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(i===Yt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(i===Zt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(i===qt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(i===Qt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(i===Kt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(i===Jt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(i===$t)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(i===te)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(i===ee)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(i===ie)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(i===ne)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(i===se)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(i===re)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}if(i===ae||i===oe||i===le){if(s=e.get("EXT_texture_compression_bptc"),null===s)return null;if(i===ae)return r===De?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(i===oe)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(i===le)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}if(i===he||i===ce||i===de||i===ue){if(s=e.get("EXT_texture_compression_rgtc"),null===s)return null;if(i===he)return s.COMPRESSED_RED_RGTC1_EXT;if(i===ce)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(i===de)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(i===ue)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return i===yt?t.UNSIGNED_INT_24_8:void 0!==t[i]?t[i]:null}}}class Jp{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(t,e){if(null===this.texture){const i=new qa(t.texture);t.depthNear===e.depthNear&&t.depthFar===e.depthFar||(this.depthNear=t.depthNear,this.depthFar=t.depthFar),this.texture=i}}getMesh(t){if(null!==this.texture&&null===this.mesh){const e=t.cameras[0].viewport,i=new Dl({vertexShader:"\nvoid main() {\n\n\tgl_Position = vec4( position, 1.0 );\n\n}",fragmentShader:"\nuniform sampler2DArray depthColor;\nuniform float depthWidth;\nuniform float depthHeight;\n\nvoid main() {\n\n\tvec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );\n\n\tif ( coord.x >= 1.0 ) {\n\n\t\tgl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;\n\n\t} else {\n\n\t\tgl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;\n\n\t}\n\n}",uniforms:{depthColor:{value:this.texture},depthWidth:{value:e.z},depthHeight:{value:e.w}}});this.mesh=new xr(new pl(20,20),i)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class $p extends ai{constructor(t,e){super();const i=this;let n=null,s=1,r=null,a="local-floor",o=1,l=null,h=null,c=null,d=null,u=null,p=null;const m="undefined"!=typeof XRWebGLBinding,f=new Jp,g={},v=e.getContextAttributes();let y=null,_=null;const x=[],b=[],S=new yi;let M=null;const w=new Ph;w.viewport=new ki;const A=new Ph;A.viewport=new ki;const E=[w,A],T=new sc;let C=null,D=null;function R(t){const e=b.indexOf(t.inputSource);if(-1===e)return;const i=x[e];void 0!==i&&(i.update(t.inputSource,t.frame,l||r),i.dispatchEvent({type:t.type,data:t.inputSource}))}function P(){n.removeEventListener("select",R),n.removeEventListener("selectstart",R),n.removeEventListener("selectend",R),n.removeEventListener("squeeze",R),n.removeEventListener("squeezestart",R),n.removeEventListener("squeezeend",R),n.removeEventListener("end",P),n.removeEventListener("inputsourceschange",I);for(let t=0;t<x.length;t++){const e=b[t];null!==e&&(b[t]=null,x[t].disconnect(e))}C=null,D=null,f.reset();for(const t in g)delete g[t];t.setRenderTarget(y),u=null,d=null,c=null,n=null,_=null,N.stop(),i.isPresenting=!1,t.setPixelRatio(M),t.setSize(S.width,S.height,!1),i.dispatchEvent({type:"sessionend"})}function I(t){for(let e=0;e<t.removed.length;e++){const i=t.removed[e],n=b.indexOf(i);n>=0&&(b[n]=null,x[n].disconnect(i))}for(let e=0;e<t.added.length;e++){const i=t.added[e];let n=b.indexOf(i);if(-1===n){for(let t=0;t<x.length;t++){if(t>=b.length){b.push(i),n=t;break}if(null===b[t]){b[t]=i,n=t;break}}if(-1===n)break}const s=x[n];s&&s.connect(i)}}this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(t){let e=x[t];return void 0===e&&(e=new bn,x[t]=e),e.getTargetRaySpace()},this.getControllerGrip=function(t){let e=x[t];return void 0===e&&(e=new bn,x[t]=e),e.getGripSpace()},this.getHand=function(t){let e=x[t];return void 0===e&&(e=new bn,x[t]=e),e.getHandSpace()},this.setFramebufferScaleFactor=function(t){s=t,!0===i.isPresenting&&ii("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(t){a=t,!0===i.isPresenting&&ii("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return l||r},this.setReferenceSpace=function(t){l=t},this.getBaseLayer=function(){return null!==d?d:u},this.getBinding=function(){return null===c&&m&&(c=new XRWebGLBinding(n,e)),c},this.getFrame=function(){return p},this.getSession=function(){return n},this.setSession=async function(h){if(n=h,null!==n){y=t.getRenderTarget(),n.addEventListener("select",R),n.addEventListener("selectstart",R),n.addEventListener("selectend",R),n.addEventListener("squeeze",R),n.addEventListener("squeezestart",R),n.addEventListener("squeezeend",R),n.addEventListener("end",P),n.addEventListener("inputsourceschange",I),!0!==v.xrCompatible&&await e.makeXRCompatible(),M=t.getPixelRatio(),t.getSize(S);if(m&&"createProjectionLayer"in XRWebGLBinding.prototype){let i=null,r=null,a=null;v.depth&&(a=v.stencil?e.DEPTH24_STENCIL8:e.DEPTH_COMPONENT24,i=v.stencil?At:wt,r=v.stencil?yt:pt);const o={colorFormat:e.RGBA8,depthFormat:a,scaleFactor:s};c=this.getBinding(),d=c.createProjectionLayer(o),n.updateRenderState({layers:[d]}),t.setPixelRatio(1),t.setSize(d.textureWidth,d.textureHeight,!1),_=new Gi(d.textureWidth,d.textureHeight,{format:Mt,type:lt,depthTexture:new Ya(d.textureWidth,d.textureHeight,r,void 0,void 0,void 0,void 0,void 0,void 0,i),stencilBuffer:v.stencil,colorSpace:t.outputColorSpace,samples:v.antialias?4:0,resolveDepthBuffer:!1===d.ignoreDepthValues,resolveStencilBuffer:!1===d.ignoreDepthValues})}else{const i={antialias:v.antialias,alpha:!0,depth:v.depth,stencil:v.stencil,framebufferScaleFactor:s};u=new XRWebGLLayer(n,e,i),n.updateRenderState({baseLayer:u}),t.setPixelRatio(1),t.setSize(u.framebufferWidth,u.framebufferHeight,!1),_=new Gi(u.framebufferWidth,u.framebufferHeight,{format:Mt,type:lt,colorSpace:t.outputColorSpace,stencilBuffer:v.stencil,resolveDepthBuffer:!1===u.ignoreDepthValues,resolveStencilBuffer:!1===u.ignoreDepthValues})}_.isXRRenderTarget=!0,this.setFoveation(o),l=null,r=await n.requestReferenceSpace(a),N.setContext(n),N.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(null!==n)return n.environmentBlendMode},this.getDepthTexture=function(){return f.getDepthTexture()};const L=new xi,B=new xi;function O(t,e){null===e?t.matrixWorld.copy(t.matrix):t.matrixWorld.multiplyMatrices(e.matrixWorld,t.matrix),t.matrixWorldInverse.copy(t.matrixWorld).invert()}this.updateCamera=function(t){if(null===n)return;let e=t.near,i=t.far;null!==f.texture&&(f.depthNear>0&&(e=f.depthNear),f.depthFar>0&&(i=f.depthFar)),T.near=A.near=w.near=e,T.far=A.far=w.far=i,C===T.near&&D===T.far||(n.updateRenderState({depthNear:T.near,depthFar:T.far}),C=T.near,D=T.far),T.layers.mask=6|t.layers.mask,w.layers.mask=-5&T.layers.mask,A.layers.mask=-3&T.layers.mask;const s=t.parent,r=T.cameras;O(T,s);for(let t=0;t<r.length;t++)O(r[t],s);2===r.length?function(t,e,i){L.setFromMatrixPosition(e.matrixWorld),B.setFromMatrixPosition(i.matrixWorld);const n=L.distanceTo(B),s=e.projectionMatrix.elements,r=i.projectionMatrix.elements,a=s[14]/(s[10]-1),o=s[14]/(s[10]+1),l=(s[9]+1)/s[5],h=(s[9]-1)/s[5],c=(s[8]-1)/s[0],d=(r[8]+1)/r[0],u=a*c,p=a*d,m=n/(-c+d),f=m*-c;if(e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.translateX(f),t.translateZ(m),t.matrixWorld.compose(t.position,t.quaternion,t.scale),t.matrixWorldInverse.copy(t.matrixWorld).invert(),-1===s[10])t.projectionMatrix.copy(e.projectionMatrix),t.projectionMatrixInverse.copy(e.projectionMatrixInverse);else{const e=a+m,i=o+m,s=u-f,r=p+(n-f),c=l*o/i*e,d=h*o/i*e;t.projectionMatrix.makePerspective(s,r,c,d,e,i),t.projectionMatrixInverse.copy(t.projectionMatrix).invert()}}(T,w,A):T.projectionMatrix.copy(w.projectionMatrix),function(t,e,i){null===i?t.matrix.copy(e.matrixWorld):(t.matrix.copy(i.matrixWorld),t.matrix.invert(),t.matrix.multiply(e.matrixWorld));t.matrix.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld(!0),t.projectionMatrix.copy(e.projectionMatrix),t.projectionMatrixInverse.copy(e.projectionMatrixInverse),t.isPerspectiveCamera&&(t.fov=2*ci*Math.atan(1/t.projectionMatrix.elements[5]),t.zoom=1)}(t,T,s)},this.getCamera=function(){return T},this.getFoveation=function(){if(null!==d||null!==u)return o},this.setFoveation=function(t){o=t,null!==d&&(d.fixedFoveation=t),null!==u&&void 0!==u.fixedFoveation&&(u.fixedFoveation=t)},this.hasDepthSensing=function(){return null!==f.texture},this.getDepthSensingMesh=function(){return f.getMesh(T)},this.getCameraTexture=function(t){return g[t]};let F=null;const N=new md;N.setAnimationLoop(function(e,s){if(h=s.getViewerPose(l||r),p=s,null!==h){const e=h.views;null!==u&&(t.setRenderTargetFramebuffer(_,u.framebuffer),t.setRenderTarget(_));let s=!1;e.length!==T.cameras.length&&(T.cameras.length=0,s=!0);for(let i=0;i<e.length;i++){const n=e[i];let r=null;if(null!==u)r=u.getViewport(n);else{const e=c.getViewSubImage(d,n);r=e.viewport,0===i&&(t.setRenderTargetTextures(_,e.colorTexture,e.depthStencilTexture),t.setRenderTarget(_))}let a=E[i];void 0===a&&(a=new Ph,a.layers.enable(i),a.viewport=new ki,E[i]=a),a.matrix.fromArray(n.transform.matrix),a.matrix.decompose(a.position,a.quaternion,a.scale),a.projectionMatrix.fromArray(n.projectionMatrix),a.projectionMatrixInverse.copy(a.projectionMatrix).invert(),a.viewport.set(r.x,r.y,r.width,r.height),0===i&&(T.matrix.copy(a.matrix),T.matrix.decompose(T.position,T.quaternion,T.scale)),!0===s&&T.cameras.push(a)}const r=n.enabledFeatures;if(r&&r.includes("depth-sensing")&&"gpu-optimized"==n.depthUsage&&m){c=i.getBinding();const t=c.getDepthInformation(e[0]);t&&t.isValid&&t.texture&&f.init(t,n.renderState)}if(r&&r.includes("camera-access")&&m){t.state.unbindTexture(),c=i.getBinding();for(let t=0;t<e.length;t++){const i=e[t].camera;if(i){let t=g[i];t||(t=new qa,g[i]=t);const e=c.getCameraImage(i);t.sourceTexture=e}}}}for(let t=0;t<x.length;t++){const e=b[t],i=x[t];null!==e&&void 0!==i&&i.update(e,s,l||r)}F&&F(e,s),s.detectedPlanes&&i.dispatchEvent({type:"planesdetected",data:s}),p=null}),this.setAnimationLoop=function(t){F=t},this.dispose=function(){}}}const tm=new tn,em=new Wi;function im(t,e){function i(t,e){!0===t.matrixAutoUpdate&&t.updateMatrix(),e.value.copy(t.matrix)}function n(t,n){t.opacity.value=n.opacity,n.color&&t.diffuse.value.copy(n.color),n.emissive&&t.emissive.value.copy(n.emissive).multiplyScalar(n.emissiveIntensity),n.map&&(t.map.value=n.map,i(n.map,t.mapTransform)),n.alphaMap&&(t.alphaMap.value=n.alphaMap,i(n.alphaMap,t.alphaMapTransform)),n.bumpMap&&(t.bumpMap.value=n.bumpMap,i(n.bumpMap,t.bumpMapTransform),t.bumpScale.value=n.bumpScale,1===n.side&&(t.bumpScale.value*=-1)),n.normalMap&&(t.normalMap.value=n.normalMap,i(n.normalMap,t.normalMapTransform),t.normalScale.value.copy(n.normalScale),1===n.side&&t.normalScale.value.negate()),n.displacementMap&&(t.displacementMap.value=n.displacementMap,i(n.displacementMap,t.displacementMapTransform),t.displacementScale.value=n.displacementScale,t.displacementBias.value=n.displacementBias),n.emissiveMap&&(t.emissiveMap.value=n.emissiveMap,i(n.emissiveMap,t.emissiveMapTransform)),n.specularMap&&(t.specularMap.value=n.specularMap,i(n.specularMap,t.specularMapTransform)),n.alphaTest>0&&(t.alphaTest.value=n.alphaTest);const s=e.get(n),r=s.envMap,a=s.envMapRotation;r&&(t.envMap.value=r,tm.copy(a),tm.x*=-1,tm.y*=-1,tm.z*=-1,r.isCubeTexture&&!1===r.isRenderTargetTexture&&(tm.y*=-1,tm.z*=-1),t.envMapRotation.value.setFromMatrix4(em.makeRotationFromEuler(tm)),t.flipEnvMap.value=r.isCubeTexture&&!1===r.isRenderTargetTexture?-1:1,t.reflectivity.value=n.reflectivity,t.ior.value=n.ior,t.refractionRatio.value=n.refractionRatio),n.lightMap&&(t.lightMap.value=n.lightMap,t.lightMapIntensity.value=n.lightMapIntensity,i(n.lightMap,t.lightMapTransform)),n.aoMap&&(t.aoMap.value=n.aoMap,t.aoMapIntensity.value=n.aoMapIntensity,i(n.aoMap,t.aoMapTransform))}return{refreshFogUniforms:function(e,i){i.color.getRGB(e.fogColor.value,Tl(t)),i.isFog?(e.fogNear.value=i.near,e.fogFar.value=i.far):i.isFogExp2&&(e.fogDensity.value=i.density)},refreshMaterialUniforms:function(t,s,r,a,o){s.isMeshBasicMaterial?n(t,s):s.isMeshLambertMaterial?(n(t,s),s.envMap&&(t.envMapIntensity.value=s.envMapIntensity)):s.isMeshToonMaterial?(n(t,s),function(t,e){e.gradientMap&&(t.gradientMap.value=e.gradientMap)}(t,s)):s.isMeshPhongMaterial?(n(t,s),function(t,e){t.specular.value.copy(e.specular),t.shininess.value=Math.max(e.shininess,1e-4)}(t,s),s.envMap&&(t.envMapIntensity.value=s.envMapIntensity)):s.isMeshStandardMaterial?(n(t,s),function(t,e){t.metalness.value=e.metalness,e.metalnessMap&&(t.metalnessMap.value=e.metalnessMap,i(e.metalnessMap,t.metalnessMapTransform));t.roughness.value=e.roughness,e.roughnessMap&&(t.roughnessMap.value=e.roughnessMap,i(e.roughnessMap,t.roughnessMapTransform));e.envMap&&(t.envMapIntensity.value=e.envMapIntensity)}(t,s),s.isMeshPhysicalMaterial&&function(t,e,n){t.ior.value=e.ior,e.sheen>0&&(t.sheenColor.value.copy(e.sheenColor).multiplyScalar(e.sheen),t.sheenRoughness.value=e.sheenRoughness,e.sheenColorMap&&(t.sheenColorMap.value=e.sheenColorMap,i(e.sheenColorMap,t.sheenColorMapTransform)),e.sheenRoughnessMap&&(t.sheenRoughnessMap.value=e.sheenRoughnessMap,i(e.sheenRoughnessMap,t.sheenRoughnessMapTransform)));e.clearcoat>0&&(t.clearcoat.value=e.clearcoat,t.clearcoatRoughness.value=e.clearcoatRoughness,e.clearcoatMap&&(t.clearcoatMap.value=e.clearcoatMap,i(e.clearcoatMap,t.clearcoatMapTransform)),e.clearcoatRoughnessMap&&(t.clearcoatRoughnessMap.value=e.clearcoatRoughnessMap,i(e.clearcoatRoughnessMap,t.clearcoatRoughnessMapTransform)),e.clearcoatNormalMap&&(t.clearcoatNormalMap.value=e.clearcoatNormalMap,i(e.clearcoatNormalMap,t.clearcoatNormalMapTransform),t.clearcoatNormalScale.value.copy(e.clearcoatNormalScale),1===e.side&&t.clearcoatNormalScale.value.negate()));e.dispersion>0&&(t.dispersion.value=e.dispersion);e.iridescence>0&&(t.iridescence.value=e.iridescence,t.iridescenceIOR.value=e.iridescenceIOR,t.iridescenceThicknessMinimum.value=e.iridescenceThicknessRange[0],t.iridescenceThicknessMaximum.value=e.iridescenceThicknessRange[1],e.iridescenceMap&&(t.iridescenceMap.value=e.iridescenceMap,i(e.iridescenceMap,t.iridescenceMapTransform)),e.iridescenceThicknessMap&&(t.iridescenceThicknessMap.value=e.iridescenceThicknessMap,i(e.iridescenceThicknessMap,t.iridescenceThicknessMapTransform)));e.transmission>0&&(t.transmission.value=e.transmission,t.transmissionSamplerMap.value=n.texture,t.transmissionSamplerSize.value.set(n.width,n.height),e.transmissionMap&&(t.transmissionMap.value=e.transmissionMap,i(e.transmissionMap,t.transmissionMapTransform)),t.thickness.value=e.thickness,e.thicknessMap&&(t.thicknessMap.value=e.thicknessMap,i(e.thicknessMap,t.thicknessMapTransform)),t.attenuationDistance.value=e.attenuationDistance,t.attenuationColor.value.copy(e.attenuationColor));e.anisotropy>0&&(t.anisotropyVector.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation)),e.anisotropyMap&&(t.anisotropyMap.value=e.anisotropyMap,i(e.anisotropyMap,t.anisotropyMapTransform)));t.specularIntensity.value=e.specularIntensity,t.specularColor.value.copy(e.specularColor),e.specularColorMap&&(t.specularColorMap.value=e.specularColorMap,i(e.specularColorMap,t.specularColorMapTransform));e.specularIntensityMap&&(t.specularIntensityMap.value=e.specularIntensityMap,i(e.specularIntensityMap,t.specularIntensityMapTransform))}(t,s,o)):s.isMeshMatcapMaterial?(n(t,s),function(t,e){e.matcap&&(t.matcap.value=e.matcap)}(t,s)):s.isMeshDepthMaterial?n(t,s):s.isMeshDistanceMaterial?(n(t,s),function(t,i){const n=e.get(i).light;t.referencePosition.value.setFromMatrixPosition(n.matrixWorld),t.nearDistance.value=n.shadow.camera.near,t.farDistance.value=n.shadow.camera.far}(t,s)):s.isMeshNormalMaterial?n(t,s):s.isLineBasicMaterial?(function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,e.map&&(t.map.value=e.map,i(e.map,t.mapTransform))}(t,s),s.isLineDashedMaterial&&function(t,e){t.dashSize.value=e.dashSize,t.totalSize.value=e.dashSize+e.gapSize,t.scale.value=e.scale}(t,s)):s.isPointsMaterial?function(t,e,n,s){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.size.value=e.size*n,t.scale.value=.5*s,e.map&&(t.map.value=e.map,i(e.map,t.uvTransform));e.alphaMap&&(t.alphaMap.value=e.alphaMap,i(e.alphaMap,t.alphaMapTransform));e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,s,r,a):s.isSpriteMaterial?function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.rotation.value=e.rotation,e.map&&(t.map.value=e.map,i(e.map,t.mapTransform));e.alphaMap&&(t.alphaMap.value=e.alphaMap,i(e.alphaMap,t.alphaMapTransform));e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,s):s.isShadowMaterial?(t.color.value.copy(s.color),t.opacity.value=s.opacity):s.isShaderMaterial&&(s.uniformsNeedUpdate=!1)}}}function nm(t,e,i,n){let s={},r={},a=[];const o=t.getParameter(t.MAX_UNIFORM_BUFFER_BINDINGS);function l(t,e,i,n){const s=t.value,r=e+"_"+i;if(void 0===n[r])return n[r]="number"==typeof s||"boolean"==typeof s?s:s.clone(),!0;{const t=n[r];if("number"==typeof s||"boolean"==typeof s){if(t!==s)return n[r]=s,!0}else if(!1===t.equals(s))return t.copy(s),!0}return!1}function h(t){const e={boundary:0,storage:0};return"number"==typeof t||"boolean"==typeof t?(e.boundary=4,e.storage=4):t.isVector2?(e.boundary=8,e.storage=8):t.isVector3||t.isColor?(e.boundary=16,e.storage=12):t.isVector4?(e.boundary=16,e.storage=16):t.isMatrix3?(e.boundary=48,e.storage=48):t.isMatrix4?(e.boundary=64,e.storage=64):t.isTexture?ii("WebGLRenderer: Texture samplers can not be part of an uniforms group."):ii("WebGLRenderer: Unsupported uniform value type.",t),e}function c(e){const i=e.target;i.removeEventListener("dispose",c);const n=a.indexOf(i.__bindingPointIndex);a.splice(n,1),t.deleteBuffer(s[i.id]),delete s[i.id],delete r[i.id]}return{bind:function(t,e){const i=e.program;n.uniformBlockBinding(t,i)},update:function(i,d){let u=s[i.id];void 0===u&&(!function(t){const e=t.uniforms;let i=0;const n=16;for(let t=0,s=e.length;t<s;t++){const s=Array.isArray(e[t])?e[t]:[e[t]];for(let t=0,e=s.length;t<e;t++){const e=s[t],r=Array.isArray(e.value)?e.value:[e.value];for(let t=0,s=r.length;t<s;t++){const s=h(r[t]),a=i%n,o=a%s.boundary,l=a+o;i+=o,0!==l&&n-l<s.storage&&(i+=n-l),e.__data=new Float32Array(s.storage/Float32Array.BYTES_PER_ELEMENT),e.__offset=i,i+=s.storage}}}const s=i%n;s>0&&(i+=n-s);t.__size=i,t.__cache={}}(i),u=function(e){const i=function(){for(let t=0;t<o;t++)if(-1===a.indexOf(t))return a.push(t),t;return ni("WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}();e.__bindingPointIndex=i;const n=t.createBuffer(),s=e.__size,r=e.usage;return t.bindBuffer(t.UNIFORM_BUFFER,n),t.bufferData(t.UNIFORM_BUFFER,s,r),t.bindBuffer(t.UNIFORM_BUFFER,null),t.bindBufferBase(t.UNIFORM_BUFFER,i,n),n}(i),s[i.id]=u,i.addEventListener("dispose",c));const p=d.program;n.updateUBOMapping(i,p);const m=e.render.frame;r[i.id]!==m&&(!function(e){const i=s[e.id],n=e.uniforms,r=e.__cache;t.bindBuffer(t.UNIFORM_BUFFER,i);for(let e=0,i=n.length;e<i;e++){const i=Array.isArray(n[e])?n[e]:[n[e]];for(let n=0,s=i.length;n<s;n++){const s=i[n];if(!0===l(s,e,n,r)){const e=s.__offset,i=Array.isArray(s.value)?s.value:[s.value];let n=0;for(let r=0;r<i.length;r++){const a=i[r],o=h(a);"number"==typeof a||"boolean"==typeof a?(s.__data[0]=a,t.bufferSubData(t.UNIFORM_BUFFER,e+n,s.__data)):a.isMatrix3?(s.__data[0]=a.elements[0],s.__data[1]=a.elements[1],s.__data[2]=a.elements[2],s.__data[3]=0,s.__data[4]=a.elements[3],s.__data[5]=a.elements[4],s.__data[6]=a.elements[5],s.__data[7]=0,s.__data[8]=a.elements[6],s.__data[9]=a.elements[7],s.__data[10]=a.elements[8],s.__data[11]=0):(a.toArray(s.__data,n),n+=o.storage/Float32Array.BYTES_PER_ELEMENT)}t.bufferSubData(t.UNIFORM_BUFFER,e,s.__data)}}}t.bindBuffer(t.UNIFORM_BUFFER,null)}(i),r[i.id]=m)},dispose:function(){for(const e in s)t.deleteBuffer(s[e]);a=[],s={},r={}}}}const sm=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]);let rm=null;class am{constructor(t={}){const{canvas:i=Ke(),context:n=null,depth:s=!0,stencil:r=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:h=!1,powerPreference:c="default",failIfMajorPerformanceCaveat:d=!1,reversedDepthBuffer:u=!1,outputBufferType:p=lt}=t;let m;if(this.isWebGLRenderer=!0,null!==n){if("undefined"!=typeof WebGLRenderingContext&&n instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");m=n.getContextAttributes().alpha}else m=a;const f=p,g=new Set([Rt,Dt,Tt]),v=new Set([lt,pt,dt,yt,gt,vt]),y=new Uint32Array(4),_=new Int32Array(4);let x=null,b=null;const S=[],M=[];let w=null;this.domElement=i,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=0,this.toneMappingExposure=1,this.transmissionResolutionScale=1;const A=this;let E=!1;this._outputColorSpace=Ee;let T=0,C=0,D=null,R=-1,P=null;const I=new ki,L=new ki;let B=null;const O=new En(0);let F=0,N=i.width,U=i.height,k=1,z=null,G=null;const H=new ki(0,0,N,U),V=new ki(0,0,N,U);let W=!1;const j=new $r;let X=!1,Y=!1;const Z=new Wi,q=new xi,Q=new ki,K={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let J=!1;function $(){return null===D?k:1}let et,it,nt,st,at,ht,ct,ut,mt,_t,xt,bt,St,Mt,wt,At,Et,Pt,It,Lt,Bt,Ot,Ft,Nt=n;function Ut(t,e){return i.getContext(t,e)}try{const t={alpha:!0,depth:s,stencil:r,antialias:o,premultipliedAlpha:l,preserveDrawingBuffer:h,powerPreference:c,failIfMajorPerformanceCaveat:d};if("setAttribute"in i&&i.setAttribute("data-engine",`three.js r${e}`),i.addEventListener("webglcontextlost",Gt,!1),i.addEventListener("webglcontextrestored",Ht,!1),i.addEventListener("webglcontextcreationerror",Vt,!1),null===Nt){const e="webgl2";if(Nt=Ut(e,t),null===Nt)throw Ut(e)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}}catch(t){throw ni("WebGLRenderer: "+t.message),t}function kt(){et=new Wd(Nt),et.init(),Bt=new Kp(Nt,et),it=new Ad(Nt,et,t,Bt),nt=new qp(Nt,et),it.reversedDepthBuffer&&u&&nt.buffers.depth.setReversed(!0),st=new Yd(Nt),at=new Ip,ht=new Qp(Nt,et,nt,at,it,Bt,st),ct=new Vd(A),ut=new fd(Nt),Ot=new Md(Nt,ut),mt=new jd(Nt,ut,st,Ot),_t=new qd(Nt,mt,ut,Ot,st),Pt=new Zd(Nt,it,ht),wt=new Ed(at),xt=new Pp(A,ct,et,it,Ot,wt),bt=new im(A,at),St=new Fp,Mt=new Hp(et),Et=new Sd(A,ct,nt,_t,m,l),At=new Zp(A,_t,it),Ft=new nm(Nt,st,it,nt),It=new wd(Nt,et,st),Lt=new Xd(Nt,et,st),st.programs=xt.programs,A.capabilities=it,A.extensions=et,A.properties=at,A.renderLists=St,A.shadowMap=At,A.state=nt,A.info=st}kt(),f!==lt&&(w=new Kd(f,i.width,i.height,s,r));const zt=new $p(A,Nt);function Gt(t){t.preventDefault(),ti("WebGLRenderer: Context Lost."),E=!0}function Ht(){ti("WebGLRenderer: Context Restored."),E=!1;const t=st.autoReset,e=At.enabled,i=At.autoUpdate,n=At.needsUpdate,s=At.type;kt(),st.autoReset=t,At.enabled=e,At.autoUpdate=i,At.needsUpdate=n,At.type=s}function Vt(t){ni("WebGLRenderer: A WebGL context could not be created. Reason: ",t.statusMessage)}function Wt(t){const e=t.target;e.removeEventListener("dispose",Wt),function(t){(function(t){const e=at.get(t).programs;void 0!==e&&(e.forEach(function(t){xt.releaseProgram(t)}),t.isShaderMaterial&&xt.releaseShaderCache(t))})(t),at.remove(t)}(e)}function jt(t,e,i){!0===t.transparent&&2===t.side&&!1===t.forceSinglePass?(t.side=1,t.needsUpdate=!0,ee(t,e,i),t.side=0,t.needsUpdate=!0,ee(t,e,i),t.side=2):ee(t,e,i)}this.xr=zt,this.getContext=function(){return Nt},this.getContextAttributes=function(){return Nt.getContextAttributes()},this.forceContextLoss=function(){const t=et.get("WEBGL_lose_context");t&&t.loseContext()},this.forceContextRestore=function(){const t=et.get("WEBGL_lose_context");t&&t.restoreContext()},this.getPixelRatio=function(){return k},this.setPixelRatio=function(t){void 0!==t&&(k=t,this.setSize(N,U,!1))},this.getSize=function(t){return t.set(N,U)},this.setSize=function(t,e,n=!0){zt.isPresenting?ii("WebGLRenderer: Can't change size while VR device is presenting."):(N=t,U=e,i.width=Math.floor(t*k),i.height=Math.floor(e*k),!0===n&&(i.style.width=t+"px",i.style.height=e+"px"),null!==w&&w.setSize(i.width,i.height),this.setViewport(0,0,t,e))},this.getDrawingBufferSize=function(t){return t.set(N*k,U*k).floor()},this.setDrawingBufferSize=function(t,e,n){N=t,U=e,k=n,i.width=Math.floor(t*n),i.height=Math.floor(e*n),this.setViewport(0,0,t,e)},this.setEffects=function(t){if(f!==lt){if(t)for(let e=0;e<t.length;e++)if(!0===t[e].isOutputPass){console.warn("THREE.WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.");break}w.setEffects(t||[])}else console.error("THREE.WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.")},this.getCurrentViewport=function(t){return t.copy(I)},this.getViewport=function(t){return t.copy(H)},this.setViewport=function(t,e,i,n){t.isVector4?H.set(t.x,t.y,t.z,t.w):H.set(t,e,i,n),nt.viewport(I.copy(H).multiplyScalar(k).round())},this.getScissor=function(t){return t.copy(V)},this.setScissor=function(t,e,i,n){t.isVector4?V.set(t.x,t.y,t.z,t.w):V.set(t,e,i,n),nt.scissor(L.copy(V).multiplyScalar(k).round())},this.getScissorTest=function(){return W},this.setScissorTest=function(t){nt.setScissorTest(W=t)},this.setOpaqueSort=function(t){z=t},this.setTransparentSort=function(t){G=t},this.getClearColor=function(t){return t.copy(Et.getClearColor())},this.setClearColor=function(){Et.setClearColor(...arguments)},this.getClearAlpha=function(){return Et.getClearAlpha()},this.setClearAlpha=function(){Et.setClearAlpha(...arguments)},this.clear=function(t=!0,e=!0,i=!0){let n=0;if(t){let t=!1;if(null!==D){const e=D.texture.format;t=g.has(e)}if(t){const t=D.texture.type,e=v.has(t),i=Et.getClearColor(),n=Et.getClearAlpha(),s=i.r,r=i.g,a=i.b;e?(y[0]=s,y[1]=r,y[2]=a,y[3]=n,Nt.clearBufferuiv(Nt.COLOR,0,y)):(_[0]=s,_[1]=r,_[2]=a,_[3]=n,Nt.clearBufferiv(Nt.COLOR,0,_))}else n|=Nt.COLOR_BUFFER_BIT}e&&(n|=Nt.DEPTH_BUFFER_BIT),i&&(n|=Nt.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),0!==n&&Nt.clear(n)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.dispose=function(){i.removeEventListener("webglcontextlost",Gt,!1),i.removeEventListener("webglcontextrestored",Ht,!1),i.removeEventListener("webglcontextcreationerror",Vt,!1),Et.dispose(),St.dispose(),Mt.dispose(),at.dispose(),ct.dispose(),_t.dispose(),Ot.dispose(),Ft.dispose(),xt.dispose(),zt.dispose(),zt.removeEventListener("sessionstart",Yt),zt.removeEventListener("sessionend",Zt),qt.stop()},this.renderBufferDirect=function(t,e,i,n,s,r){null===e&&(e=K);const a=s.isMesh&&s.matrixWorld.determinant()<0,o=function(t,e,i,n,s){!0!==e.isScene&&(e=K);ht.resetTextureUnits();const r=e.fog,a=n.isMeshStandardMaterial||n.isMeshLambertMaterial||n.isMeshPhongMaterial?e.environment:null,o=null===D?A.outputColorSpace:!0===D.isXRRenderTarget?D.texture.colorSpace:Te,l=n.isMeshStandardMaterial||n.isMeshLambertMaterial&&!n.envMap||n.isMeshPhongMaterial&&!n.envMap,h=ct.get(n.envMap||a,l),c=!0===n.vertexColors&&!!i.attributes.color&&4===i.attributes.color.itemSize,d=!!i.attributes.tangent&&(!!n.normalMap||n.anisotropy>0),u=!!i.morphAttributes.position,p=!!i.morphAttributes.normal,m=!!i.morphAttributes.color;let f=0;n.toneMapped&&(null!==D&&!0!==D.isXRRenderTarget||(f=A.toneMapping));const g=i.morphAttributes.position||i.morphAttributes.normal||i.morphAttributes.color,v=void 0!==g?g.length:0,y=at.get(n),_=b.state.lights;if(!0===X&&(!0===Y||t!==P)){const e=t===P&&n.id===R;wt.setState(n,t,e)}let x=!1;n.version===y.__version?y.needsLights&&y.lightsStateVersion!==_.state.version||y.outputColorSpace!==o||s.isBatchedMesh&&!1===y.batching?x=!0:s.isBatchedMesh||!0!==y.batching?s.isBatchedMesh&&!0===y.batchingColor&&null===s.colorTexture||s.isBatchedMesh&&!1===y.batchingColor&&null!==s.colorTexture||s.isInstancedMesh&&!1===y.instancing?x=!0:s.isInstancedMesh||!0!==y.instancing?s.isSkinnedMesh&&!1===y.skinning?x=!0:s.isSkinnedMesh||!0!==y.skinning?s.isInstancedMesh&&!0===y.instancingColor&&null===s.instanceColor||s.isInstancedMesh&&!1===y.instancingColor&&null!==s.instanceColor||s.isInstancedMesh&&!0===y.instancingMorph&&null===s.morphTexture||s.isInstancedMesh&&!1===y.instancingMorph&&null!==s.morphTexture||y.envMap!==h||!0===n.fog&&y.fog!==r?x=!0:void 0===y.numClippingPlanes||y.numClippingPlanes===wt.numPlanes&&y.numIntersection===wt.numIntersection?(y.vertexAlphas!==c||y.vertexTangents!==d||y.morphTargets!==u||y.morphNormals!==p||y.morphColors!==m||y.toneMapping!==f||y.morphTargetsCount!==v)&&(x=!0):x=!0:x=!0:x=!0:x=!0:(x=!0,y.__version=n.version);let S=y.currentProgram;!0===x&&(S=ee(n,e,s));let M=!1,w=!1,E=!1;const T=S.getUniforms(),C=y.uniforms;nt.useProgram(S.program)&&(M=!0,w=!0,E=!0);n.id!==R&&(R=n.id,w=!0);if(M||P!==t){nt.buffers.depth.getReversed()&&!0!==t.reversedDepth&&(t._reversedDepth=!0,t.updateProjectionMatrix()),T.setValue(Nt,"projectionMatrix",t.projectionMatrix),T.setValue(Nt,"viewMatrix",t.matrixWorldInverse);const e=T.map.cameraPosition;void 0!==e&&e.setValue(Nt,q.setFromMatrixPosition(t.matrixWorld)),it.logarithmicDepthBuffer&&T.setValue(Nt,"logDepthBufFC",2/(Math.log(t.far+1)/Math.LN2)),(n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshLambertMaterial||n.isMeshBasicMaterial||n.isMeshStandardMaterial||n.isShaderMaterial)&&T.setValue(Nt,"isOrthographic",!0===t.isOrthographicCamera),P!==t&&(P=t,w=!0,E=!0)}y.needsLights&&(_.state.directionalShadowMap.length>0&&T.setValue(Nt,"directionalShadowMap",_.state.directionalShadowMap,ht),_.state.spotShadowMap.length>0&&T.setValue(Nt,"spotShadowMap",_.state.spotShadowMap,ht),_.state.pointShadowMap.length>0&&T.setValue(Nt,"pointShadowMap",_.state.pointShadowMap,ht));if(s.isSkinnedMesh){T.setOptional(Nt,s,"bindMatrix"),T.setOptional(Nt,s,"bindMatrixInverse");const t=s.skeleton;t&&(null===t.boneTexture&&t.computeBoneTexture(),T.setValue(Nt,"boneTexture",t.boneTexture,ht))}s.isBatchedMesh&&(T.setOptional(Nt,s,"batchingTexture"),T.setValue(Nt,"batchingTexture",s._matricesTexture,ht),T.setOptional(Nt,s,"batchingIdTexture"),T.setValue(Nt,"batchingIdTexture",s._indirectTexture,ht),T.setOptional(Nt,s,"batchingColorTexture"),null!==s._colorsTexture&&T.setValue(Nt,"batchingColorTexture",s._colorsTexture,ht));const I=i.morphAttributes;void 0===I.position&&void 0===I.normal&&void 0===I.color||Pt.update(s,i,S);(w||y.receiveShadow!==s.receiveShadow)&&(y.receiveShadow=s.receiveShadow,T.setValue(Nt,"receiveShadow",s.receiveShadow));(n.isMeshStandardMaterial||n.isMeshLambertMaterial||n.isMeshPhongMaterial)&&null===n.envMap&&null!==e.environment&&(C.envMapIntensity.value=e.environmentIntensity);void 0!==C.dfgLUT&&(C.dfgLUT.value=(null===rm&&(rm=new Lr(sm,16,16,Ct,ft),rm.name="DFG_LUT",rm.minFilter=rt,rm.magFilter=rt,rm.wrapS=tt,rm.wrapT=tt,rm.generateMipmaps=!1,rm.needsUpdate=!0),rm));w&&(T.setValue(Nt,"toneMappingExposure",A.toneMappingExposure),y.needsLights&&(B=E,(L=C).ambientLightColor.needsUpdate=B,L.lightProbe.needsUpdate=B,L.directionalLights.needsUpdate=B,L.directionalLightShadows.needsUpdate=B,L.pointLights.needsUpdate=B,L.pointLightShadows.needsUpdate=B,L.spotLights.needsUpdate=B,L.spotLightShadows.needsUpdate=B,L.rectAreaLights.needsUpdate=B,L.hemisphereLights.needsUpdate=B),r&&!0===n.fog&&bt.refreshFogUniforms(C,r),bt.refreshMaterialUniforms(C,n,k,U,b.state.transmissionRenderTarget[t.id]),ip.upload(Nt,ie(y),C,ht));var L,B;n.isShaderMaterial&&!0===n.uniformsNeedUpdate&&(ip.upload(Nt,ie(y),C,ht),n.uniformsNeedUpdate=!1);n.isSpriteMaterial&&T.setValue(Nt,"center",s.center);if(T.setValue(Nt,"modelViewMatrix",s.modelViewMatrix),T.setValue(Nt,"normalMatrix",s.normalMatrix),T.setValue(Nt,"modelMatrix",s.matrixWorld),n.isShaderMaterial||n.isRawShaderMaterial){const t=n.uniformsGroups;for(let e=0,i=t.length;e<i;e++){const i=t[e];Ft.update(i,S),Ft.bind(i,S)}}return S}(t,e,i,n,s);nt.setMaterial(n,a);let l=i.index,h=1;if(!0===n.wireframe){if(l=mt.getWireframeAttribute(i),void 0===l)return;h=2}const c=i.drawRange,d=i.attributes.position;let u=c.start*h,p=(c.start+c.count)*h;null!==r&&(u=Math.max(u,r.start*h),p=Math.min(p,(r.start+r.count)*h)),null!==l?(u=Math.max(u,0),p=Math.min(p,l.count)):null!=d&&(u=Math.max(u,0),p=Math.min(p,d.count));const m=p-u;if(m<0||m===1/0)return;let f;Ot.setup(s,n,o,i,l);let g=It;if(null!==l&&(f=ut.get(l),g=Lt,g.setIndex(f)),s.isMesh)!0===n.wireframe?(nt.setLineWidth(n.wireframeLinewidth*$()),g.setMode(Nt.LINES)):g.setMode(Nt.TRIANGLES);else if(s.isLine){let t=n.linewidth;void 0===t&&(t=1),nt.setLineWidth(t*$()),s.isLineSegments?g.setMode(Nt.LINES):s.isLineLoop?g.setMode(Nt.LINE_LOOP):g.setMode(Nt.LINE_STRIP)}else s.isPoints?g.setMode(Nt.POINTS):s.isSprite&&g.setMode(Nt.TRIANGLES);if(s.isBatchedMesh)if(null!==s._multiDrawInstances)si("WebGLRenderer: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection."),g.renderMultiDrawInstances(s._multiDrawStarts,s._multiDrawCounts,s._multiDrawCount,s._multiDrawInstances);else if(et.get("WEBGL_multi_draw"))g.renderMultiDraw(s._multiDrawStarts,s._multiDrawCounts,s._multiDrawCount);else{const t=s._multiDrawStarts,e=s._multiDrawCounts,i=s._multiDrawCount,r=l?ut.get(l).bytesPerElement:1,a=at.get(n).currentProgram.getUniforms();for(let n=0;n<i;n++)a.setValue(Nt,"_gl_DrawID",n),g.render(t[n]/r,e[n])}else if(s.isInstancedMesh)g.renderInstances(u,m,s.count);else if(i.isInstancedBufferGeometry){const t=void 0!==i._maxInstanceCount?i._maxInstanceCount:1/0,e=Math.min(i.instanceCount,t);g.renderInstances(u,m,e)}else g.render(u,m)},this.compile=function(t,e,i=null){null===i&&(i=t),b=Mt.get(i),b.init(e),M.push(b),i.traverseVisible(function(t){t.isLight&&t.layers.test(e.layers)&&(b.pushLight(t),t.castShadow&&b.pushShadow(t))}),t!==i&&t.traverseVisible(function(t){t.isLight&&t.layers.test(e.layers)&&(b.pushLight(t),t.castShadow&&b.pushShadow(t))}),b.setupLights();const n=new Set;return t.traverse(function(t){if(!(t.isMesh||t.isPoints||t.isLine||t.isSprite))return;const e=t.material;if(e)if(Array.isArray(e))for(let s=0;s<e.length;s++){const r=e[s];jt(r,i,t),n.add(r)}else jt(e,i,t),n.add(e)}),b=M.pop(),n},this.compileAsync=function(t,e,i=null){const n=this.compile(t,e,i);return new Promise(e=>{function i(){n.forEach(function(t){at.get(t).currentProgram.isReady()&&n.delete(t)}),0!==n.size?setTimeout(i,10):e(t)}null!==et.get("KHR_parallel_shader_compile")?i():setTimeout(i,10)})};let Xt=null;function Yt(){qt.stop()}function Zt(){qt.start()}const qt=new md;function Qt(t,e,i,n){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)i=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)b.pushLight(t),t.castShadow&&b.pushShadow(t);else if(t.isSprite){if(!t.frustumCulled||j.intersectsSprite(t)){n&&Q.setFromMatrixPosition(t.matrixWorld).applyMatrix4(Z);const e=_t.update(t),s=t.material;s.visible&&x.push(t,e,s,i,Q.z,null)}}else if((t.isMesh||t.isLine||t.isPoints)&&(!t.frustumCulled||j.intersectsObject(t))){const e=_t.update(t),s=t.material;if(n&&(void 0!==t.boundingSphere?(null===t.boundingSphere&&t.computeBoundingSphere(),Q.copy(t.boundingSphere.center)):(null===e.boundingSphere&&e.computeBoundingSphere(),Q.copy(e.boundingSphere.center)),Q.applyMatrix4(t.matrixWorld).applyMatrix4(Z)),Array.isArray(s)){const n=e.groups;for(let r=0,a=n.length;r<a;r++){const a=n[r],o=s[a.materialIndex];o&&o.visible&&x.push(t,e,o,i,Q.z,a)}}else s.visible&&x.push(t,e,s,i,Q.z,null)}const s=t.children;for(let t=0,r=s.length;t<r;t++)Qt(s[t],e,i,n)}function Kt(t,e,i,n){const{opaque:s,transmissive:r,transparent:a}=t;b.setupLightsView(i),!0===X&&wt.setGlobalState(A.clippingPlanes,i),n&&nt.viewport(I.copy(n)),s.length>0&&$t(s,e,i),r.length>0&&$t(r,e,i),a.length>0&&$t(a,e,i),nt.buffers.depth.setTest(!0),nt.buffers.depth.setMask(!0),nt.buffers.color.setMask(!0),nt.setPolygonOffset(!1)}function Jt(t,e,i,n){if(null!==(!0===i.isScene?i.overrideMaterial:null))return;if(void 0===b.state.transmissionRenderTarget[n.id]){const t=et.has("EXT_color_buffer_half_float")||et.has("EXT_color_buffer_float");b.state.transmissionRenderTarget[n.id]=new Gi(1,1,{generateMipmaps:!0,type:t?ft:lt,minFilter:ot,samples:it.samples,stencilBuffer:r,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:Ci.workingColorSpace})}const s=b.state.transmissionRenderTarget[n.id],a=n.viewport||I;s.setSize(a.z*A.transmissionResolutionScale,a.w*A.transmissionResolutionScale);const o=A.getRenderTarget(),l=A.getActiveCubeFace(),h=A.getActiveMipmapLevel();A.setRenderTarget(s),A.getClearColor(O),F=A.getClearAlpha(),F<1&&A.setClearColor(16777215,.5),A.clear(),J&&Et.render(i);const c=A.toneMapping;A.toneMapping=0;const d=n.viewport;if(void 0!==n.viewport&&(n.viewport=void 0),b.setupLightsView(n),!0===X&&wt.setGlobalState(A.clippingPlanes,n),$t(t,i,n),ht.updateMultisampleRenderTarget(s),ht.updateRenderTargetMipmap(s),!1===et.has("WEBGL_multisampled_render_to_texture")){let t=!1;for(let s=0,r=e.length;s<r;s++){const r=e[s],{object:a,geometry:o,material:l,group:h}=r;if(2===l.side&&a.layers.test(n.layers)){const e=l.side;l.side=1,l.needsUpdate=!0,te(a,i,n,o,l,h),l.side=e,l.needsUpdate=!0,t=!0}}!0===t&&(ht.updateMultisampleRenderTarget(s),ht.updateRenderTargetMipmap(s))}A.setRenderTarget(o,l,h),A.setClearColor(O,F),void 0!==d&&(n.viewport=d),A.toneMapping=c}function $t(t,e,i){const n=!0===e.isScene?e.overrideMaterial:null;for(let s=0,r=t.length;s<r;s++){const r=t[s],{object:a,geometry:o,group:l}=r;let h=r.material;!0===h.allowOverride&&null!==n&&(h=n),a.layers.test(i.layers)&&te(a,e,i,o,h,l)}}function te(t,e,i,n,s,r){t.onBeforeRender(A,e,i,n,s,r),t.modelViewMatrix.multiplyMatrices(i.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix),s.onBeforeRender(A,e,i,n,t,r),!0===s.transparent&&2===s.side&&!1===s.forceSinglePass?(s.side=1,s.needsUpdate=!0,A.renderBufferDirect(i,e,n,s,t,r),s.side=0,s.needsUpdate=!0,A.renderBufferDirect(i,e,n,s,t,r),s.side=2):A.renderBufferDirect(i,e,n,s,t,r),t.onAfterRender(A,e,i,n,s,r)}function ee(t,e,i){!0!==e.isScene&&(e=K);const n=at.get(t),s=b.state.lights,r=b.state.shadowsArray,a=s.state.version,o=xt.getParameters(t,s.state,r,e,i),l=xt.getProgramCacheKey(o);let h=n.programs;n.environment=t.isMeshStandardMaterial||t.isMeshLambertMaterial||t.isMeshPhongMaterial?e.environment:null,n.fog=e.fog;const c=t.isMeshStandardMaterial||t.isMeshLambertMaterial&&!t.envMap||t.isMeshPhongMaterial&&!t.envMap;n.envMap=ct.get(t.envMap||n.environment,c),n.envMapRotation=null!==n.environment&&null===t.envMap?e.environmentRotation:t.envMapRotation,void 0===h&&(t.addEventListener("dispose",Wt),h=new Map,n.programs=h);let d=h.get(l);if(void 0!==d){if(n.currentProgram===d&&n.lightsStateVersion===a)return ne(t,o),d}else o.uniforms=xt.getUniforms(t),t.onBeforeCompile(o,A),d=xt.acquireProgram(o,l),h.set(l,d),n.uniforms=o.uniforms;const u=n.uniforms;return(t.isShaderMaterial||t.isRawShaderMaterial)&&!0!==t.clipping||(u.clippingPlanes=wt.uniform),ne(t,o),n.needsLights=function(t){return t.isMeshLambertMaterial||t.isMeshToonMaterial||t.isMeshPhongMaterial||t.isMeshStandardMaterial||t.isShadowMaterial||t.isShaderMaterial&&!0===t.lights}(t),n.lightsStateVersion=a,n.needsLights&&(u.ambientLightColor.value=s.state.ambient,u.lightProbe.value=s.state.probe,u.directionalLights.value=s.state.directional,u.directionalLightShadows.value=s.state.directionalShadow,u.spotLights.value=s.state.spot,u.spotLightShadows.value=s.state.spotShadow,u.rectAreaLights.value=s.state.rectArea,u.ltc_1.value=s.state.rectAreaLTC1,u.ltc_2.value=s.state.rectAreaLTC2,u.pointLights.value=s.state.point,u.pointLightShadows.value=s.state.pointShadow,u.hemisphereLights.value=s.state.hemi,u.directionalShadowMatrix.value=s.state.directionalShadowMatrix,u.spotLightMatrix.value=s.state.spotLightMatrix,u.spotLightMap.value=s.state.spotLightMap,u.pointShadowMatrix.value=s.state.pointShadowMatrix),n.currentProgram=d,n.uniformsList=null,d}function ie(t){if(null===t.uniformsList){const e=t.currentProgram.getUniforms();t.uniformsList=ip.seqWithValue(e.seq,t.uniforms)}return t.uniformsList}function ne(t,e){const i=at.get(t);i.outputColorSpace=e.outputColorSpace,i.batching=e.batching,i.batchingColor=e.batchingColor,i.instancing=e.instancing,i.instancingColor=e.instancingColor,i.instancingMorph=e.instancingMorph,i.skinning=e.skinning,i.morphTargets=e.morphTargets,i.morphNormals=e.morphNormals,i.morphColors=e.morphColors,i.morphTargetsCount=e.morphTargetsCount,i.numClippingPlanes=e.numClippingPlanes,i.numIntersection=e.numClipIntersection,i.vertexAlphas=e.vertexAlphas,i.vertexTangents=e.vertexTangents,i.toneMapping=e.toneMapping}qt.setAnimationLoop(function(t){Xt&&Xt(t)}),"undefined"!=typeof self&&qt.setContext(self),this.setAnimationLoop=function(t){Xt=t,zt.setAnimationLoop(t),null===t?qt.stop():qt.start()},zt.addEventListener("sessionstart",Yt),zt.addEventListener("sessionend",Zt),this.render=function(t,e){if(void 0!==e&&!0!==e.isCamera)return void ni("WebGLRenderer.render: camera is not an instance of THREE.Camera.");if(!0===E)return;const i=!0===zt.enabled&&!0===zt.isPresenting,n=null!==w&&(null===D||i)&&w.begin(A,D);if(!0===t.matrixWorldAutoUpdate&&t.updateMatrixWorld(),null===e.parent&&!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld(),!0!==zt.enabled||!0!==zt.isPresenting||null!==w&&!1!==w.isCompositing()||(!0===zt.cameraAutoUpdate&&zt.updateCamera(e),e=zt.getCamera()),!0===t.isScene&&t.onBeforeRender(A,t,e,D),b=Mt.get(t,M.length),b.init(e),M.push(b),Z.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),j.setFromProjectionMatrix(Z,je,e.reversedDepth),Y=this.localClippingEnabled,X=wt.init(this.clippingPlanes,Y),x=St.get(t,S.length),x.init(),S.push(x),!0===zt.enabled&&!0===zt.isPresenting){const t=A.xr.getDepthSensingMesh();null!==t&&Qt(t,e,-1/0,A.sortObjects)}Qt(t,e,0,A.sortObjects),x.finish(),!0===A.sortObjects&&x.sort(z,G),J=!1===zt.enabled||!1===zt.isPresenting||!1===zt.hasDepthSensing(),J&&Et.addToRenderList(x,t),this.info.render.frame++,!0===X&&wt.beginShadows();const s=b.state.shadowsArray;At.render(s,t,e),!0===X&&wt.endShadows(),!0===this.info.autoReset&&this.info.reset();if(!1===(n&&w.hasRenderPass())){const i=x.opaque,n=x.transmissive;if(b.setupLights(),e.isArrayCamera){const s=e.cameras;if(n.length>0)for(let e=0,r=s.length;e<r;e++){Jt(i,n,t,s[e])}J&&Et.render(t);for(let e=0,i=s.length;e<i;e++){const i=s[e];Kt(x,t,i,i.viewport)}}else n.length>0&&Jt(i,n,t,e),J&&Et.render(t),Kt(x,t,e)}null!==D&&0===C&&(ht.updateMultisampleRenderTarget(D),ht.updateRenderTargetMipmap(D)),n&&w.end(A),!0===t.isScene&&t.onAfterRender(A,t,e),Ot.resetDefaultState(),R=-1,P=null,M.pop(),M.length>0?(b=M[M.length-1],!0===X&&wt.setGlobalState(A.clippingPlanes,b.state.camera)):b=null,S.pop(),x=S.length>0?S[S.length-1]:null},this.getActiveCubeFace=function(){return T},this.getActiveMipmapLevel=function(){return C},this.getRenderTarget=function(){return D},this.setRenderTargetTextures=function(t,e,i){const n=at.get(t);n.__autoAllocateDepthBuffer=!1===t.resolveDepthBuffer,!1===n.__autoAllocateDepthBuffer&&(n.__useRenderToTexture=!1),at.get(t.texture).__webglTexture=e,at.get(t.depthTexture).__webglTexture=n.__autoAllocateDepthBuffer?void 0:i,n.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(t,e){const i=at.get(t);i.__webglFramebuffer=e,i.__useDefaultFramebuffer=void 0===e};const se=Nt.createFramebuffer();this.setRenderTarget=function(t,e=0,i=0){D=t,T=e,C=i;let n=null,s=!1,r=!1;if(t){const a=at.get(t);if(void 0!==a.__useDefaultFramebuffer)return nt.bindFramebuffer(Nt.FRAMEBUFFER,a.__webglFramebuffer),I.copy(t.viewport),L.copy(t.scissor),B=t.scissorTest,nt.viewport(I),nt.scissor(L),nt.setScissorTest(B),void(R=-1);if(void 0===a.__webglFramebuffer)ht.setupRenderTarget(t);else if(a.__hasExternalTextures)ht.rebindTextures(t,at.get(t.texture).__webglTexture,at.get(t.depthTexture).__webglTexture);else if(t.depthBuffer){const e=t.depthTexture;if(a.__boundDepthTexture!==e){if(null!==e&&at.has(e)&&(t.width!==e.image.width||t.height!==e.image.height))throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");ht.setupDepthRenderbuffer(t)}}const o=t.texture;(o.isData3DTexture||o.isDataArrayTexture||o.isCompressedArrayTexture)&&(r=!0);const l=at.get(t).__webglFramebuffer;t.isWebGLCubeRenderTarget?(n=Array.isArray(l[e])?l[e][i]:l[e],s=!0):n=t.samples>0&&!1===ht.useMultisampledRTT(t)?at.get(t).__webglMultisampledFramebuffer:Array.isArray(l)?l[i]:l,I.copy(t.viewport),L.copy(t.scissor),B=t.scissorTest}else I.copy(H).multiplyScalar(k).floor(),L.copy(V).multiplyScalar(k).floor(),B=W;0!==i&&(n=se);if(nt.bindFramebuffer(Nt.FRAMEBUFFER,n)&&nt.drawBuffers(t,n),nt.viewport(I),nt.scissor(L),nt.setScissorTest(B),s){const n=at.get(t.texture);Nt.framebufferTexture2D(Nt.FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,Nt.TEXTURE_CUBE_MAP_POSITIVE_X+e,n.__webglTexture,i)}else if(r){const n=e;for(let e=0;e<t.textures.length;e++){const s=at.get(t.textures[e]);Nt.framebufferTextureLayer(Nt.FRAMEBUFFER,Nt.COLOR_ATTACHMENT0+e,s.__webglTexture,i,n)}}else if(null!==t&&0!==i){const e=at.get(t.texture);Nt.framebufferTexture2D(Nt.FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,Nt.TEXTURE_2D,e.__webglTexture,i)}R=-1},this.readRenderTargetPixels=function(t,e,i,n,s,r,a,o=0){if(!t||!t.isWebGLRenderTarget)return void ni("WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let l=at.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(l=l[a]),l){nt.bindFramebuffer(Nt.FRAMEBUFFER,l);try{const a=t.textures[o],l=a.format,h=a.type;if(t.textures.length>1&&Nt.readBuffer(Nt.COLOR_ATTACHMENT0+o),!it.textureFormatReadable(l))return void ni("WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");if(!it.textureTypeReadable(h))return void ni("WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");e>=0&&e<=t.width-n&&i>=0&&i<=t.height-s&&Nt.readPixels(e,i,n,s,Bt.convert(l),Bt.convert(h),r)}finally{const t=null!==D?at.get(D).__webglFramebuffer:null;nt.bindFramebuffer(Nt.FRAMEBUFFER,t)}}},this.readRenderTargetPixelsAsync=async function(t,e,i,n,s,r,a,o=0){if(!t||!t.isWebGLRenderTarget)throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let l=at.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(l=l[a]),l){if(e>=0&&e<=t.width-n&&i>=0&&i<=t.height-s){nt.bindFramebuffer(Nt.FRAMEBUFFER,l);const a=t.textures[o],h=a.format,c=a.type;if(t.textures.length>1&&Nt.readBuffer(Nt.COLOR_ATTACHMENT0+o),!it.textureFormatReadable(h))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!it.textureTypeReadable(c))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");const d=Nt.createBuffer();Nt.bindBuffer(Nt.PIXEL_PACK_BUFFER,d),Nt.bufferData(Nt.PIXEL_PACK_BUFFER,r.byteLength,Nt.STREAM_READ),Nt.readPixels(e,i,n,s,Bt.convert(h),Bt.convert(c),0);const u=null!==D?at.get(D).__webglFramebuffer:null;nt.bindFramebuffer(Nt.FRAMEBUFFER,u);const p=Nt.fenceSync(Nt.SYNC_GPU_COMMANDS_COMPLETE,0);return Nt.flush(),await function(t,e,i){return new Promise(function(n,s){setTimeout(function r(){switch(t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0)){case t.WAIT_FAILED:s();break;case t.TIMEOUT_EXPIRED:setTimeout(r,i);break;default:n()}},i)})}(Nt,p,4),Nt.bindBuffer(Nt.PIXEL_PACK_BUFFER,d),Nt.getBufferSubData(Nt.PIXEL_PACK_BUFFER,0,r),Nt.deleteBuffer(d),Nt.deleteSync(p),r}throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")}},this.copyFramebufferToTexture=function(t,e=null,i=0){const n=Math.pow(2,-i),s=Math.floor(t.image.width*n),r=Math.floor(t.image.height*n),a=null!==e?e.x:0,o=null!==e?e.y:0;ht.setTexture2D(t,0),Nt.copyTexSubImage2D(Nt.TEXTURE_2D,i,0,0,a,o,s,r),nt.unbindTexture()};const re=Nt.createFramebuffer(),ae=Nt.createFramebuffer();this.copyTextureToTexture=function(t,e,i=null,n=null,s=0,r=0){let a,o,l,h,c,d,u,p,m;const f=t.isCompressedTexture?t.mipmaps[r]:t.image;if(null!==i)a=i.max.x-i.min.x,o=i.max.y-i.min.y,l=i.isBox3?i.max.z-i.min.z:1,h=i.min.x,c=i.min.y,d=i.isBox3?i.min.z:0;else{const e=Math.pow(2,-s);a=Math.floor(f.width*e),o=Math.floor(f.height*e),l=t.isDataArrayTexture?f.depth:t.isData3DTexture?Math.floor(f.depth*e):1,h=0,c=0,d=0}null!==n?(u=n.x,p=n.y,m=n.z):(u=0,p=0,m=0);const g=Bt.convert(e.format),v=Bt.convert(e.type);let y;e.isData3DTexture?(ht.setTexture3D(e,0),y=Nt.TEXTURE_3D):e.isDataArrayTexture||e.isCompressedArrayTexture?(ht.setTexture2DArray(e,0),y=Nt.TEXTURE_2D_ARRAY):(ht.setTexture2D(e,0),y=Nt.TEXTURE_2D),Nt.pixelStorei(Nt.UNPACK_FLIP_Y_WEBGL,e.flipY),Nt.pixelStorei(Nt.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultiplyAlpha),Nt.pixelStorei(Nt.UNPACK_ALIGNMENT,e.unpackAlignment);const _=Nt.getParameter(Nt.UNPACK_ROW_LENGTH),x=Nt.getParameter(Nt.UNPACK_IMAGE_HEIGHT),b=Nt.getParameter(Nt.UNPACK_SKIP_PIXELS),S=Nt.getParameter(Nt.UNPACK_SKIP_ROWS),M=Nt.getParameter(Nt.UNPACK_SKIP_IMAGES);Nt.pixelStorei(Nt.UNPACK_ROW_LENGTH,f.width),Nt.pixelStorei(Nt.UNPACK_IMAGE_HEIGHT,f.height),Nt.pixelStorei(Nt.UNPACK_SKIP_PIXELS,h),Nt.pixelStorei(Nt.UNPACK_SKIP_ROWS,c),Nt.pixelStorei(Nt.UNPACK_SKIP_IMAGES,d);const w=t.isDataArrayTexture||t.isData3DTexture,A=e.isDataArrayTexture||e.isData3DTexture;if(t.isDepthTexture){const i=at.get(t),n=at.get(e),f=at.get(i.__renderTarget),g=at.get(n.__renderTarget);nt.bindFramebuffer(Nt.READ_FRAMEBUFFER,f.__webglFramebuffer),nt.bindFramebuffer(Nt.DRAW_FRAMEBUFFER,g.__webglFramebuffer);for(let i=0;i<l;i++)w&&(Nt.framebufferTextureLayer(Nt.READ_FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,at.get(t).__webglTexture,s,d+i),Nt.framebufferTextureLayer(Nt.DRAW_FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,at.get(e).__webglTexture,r,m+i)),Nt.blitFramebuffer(h,c,a,o,u,p,a,o,Nt.DEPTH_BUFFER_BIT,Nt.NEAREST);nt.bindFramebuffer(Nt.READ_FRAMEBUFFER,null),nt.bindFramebuffer(Nt.DRAW_FRAMEBUFFER,null)}else if(0!==s||t.isRenderTargetTexture||at.has(t)){const i=at.get(t),n=at.get(e);nt.bindFramebuffer(Nt.READ_FRAMEBUFFER,re),nt.bindFramebuffer(Nt.DRAW_FRAMEBUFFER,ae);for(let t=0;t<l;t++)w?Nt.framebufferTextureLayer(Nt.READ_FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,i.__webglTexture,s,d+t):Nt.framebufferTexture2D(Nt.READ_FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,Nt.TEXTURE_2D,i.__webglTexture,s),A?Nt.framebufferTextureLayer(Nt.DRAW_FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,n.__webglTexture,r,m+t):Nt.framebufferTexture2D(Nt.DRAW_FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,Nt.TEXTURE_2D,n.__webglTexture,r),0!==s?Nt.blitFramebuffer(h,c,a,o,u,p,a,o,Nt.COLOR_BUFFER_BIT,Nt.NEAREST):A?Nt.copyTexSubImage3D(y,r,u,p,m+t,h,c,a,o):Nt.copyTexSubImage2D(y,r,u,p,h,c,a,o);nt.bindFramebuffer(Nt.READ_FRAMEBUFFER,null),nt.bindFramebuffer(Nt.DRAW_FRAMEBUFFER,null)}else A?t.isDataTexture||t.isData3DTexture?Nt.texSubImage3D(y,r,u,p,m,a,o,l,g,v,f.data):e.isCompressedArrayTexture?Nt.compressedTexSubImage3D(y,r,u,p,m,a,o,l,g,f.data):Nt.texSubImage3D(y,r,u,p,m,a,o,l,g,v,f):t.isDataTexture?Nt.texSubImage2D(Nt.TEXTURE_2D,r,u,p,a,o,g,v,f.data):t.isCompressedTexture?Nt.compressedTexSubImage2D(Nt.TEXTURE_2D,r,u,p,f.width,f.height,g,f.data):Nt.texSubImage2D(Nt.TEXTURE_2D,r,u,p,a,o,g,v,f);Nt.pixelStorei(Nt.UNPACK_ROW_LENGTH,_),Nt.pixelStorei(Nt.UNPACK_IMAGE_HEIGHT,x),Nt.pixelStorei(Nt.UNPACK_SKIP_PIXELS,b),Nt.pixelStorei(Nt.UNPACK_SKIP_ROWS,S),Nt.pixelStorei(Nt.UNPACK_SKIP_IMAGES,M),0===r&&e.generateMipmaps&&Nt.generateMipmap(y),nt.unbindTexture()},this.initRenderTarget=function(t){void 0===at.get(t).__webglFramebuffer&&ht.setupRenderTarget(t)},this.initTexture=function(t){t.isCubeTexture?ht.setTextureCube(t,0):t.isData3DTexture?ht.setTexture3D(t,0):t.isDataArrayTexture||t.isCompressedArrayTexture?ht.setTexture2DArray(t,0):ht.setTexture2D(t,0),nt.unbindTexture()},this.resetState=function(){T=0,C=0,D=null,nt.reset(),Ot.reset()},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return je}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(t){this._outputColorSpace=t;const e=this.getContext();e.drawingBufferColorSpace=Ci._getDrawingBufferColorSpace(t),e.unpackColorSpace=Ci._getUnpackColorSpace()}}var om=Object.freeze({__proto__:null,ACESFilmicToneMapping:4,AddEquation:h,AddOperation:2,AdditiveAnimationBlendMode:Me,AdditiveBlending:2,AgXToneMapping:6,AlphaFormat:bt,AlwaysCompare:519,AlwaysDepth:1,AlwaysStencilFunc:Be,AmbientLight:kh,AnimationAction:wc,AnimationClip:sh,AnimationLoader:class extends ch{constructor(t){super(t)}load(t,e,i,n){const s=this,r=new ph(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,function(i){try{e(s.parse(JSON.parse(i)))}catch(e){n?n(e):ni(e),s.manager.itemError(t)}},i,n)}parse(t){const e=[];for(let i=0;i<t.length;i++){const n=sh.parse(t[i]);e.push(n)}return e}},AnimationMixer:Ec,AnimationObjectGroup:class{constructor(){this.isAnimationObjectGroup=!0,this.uuid=di(),this._objects=Array.prototype.slice.call(arguments),this.nCachedObjects_=0;const t={};this._indicesByUUID=t;for(let e=0,i=arguments.length;e!==i;++e)t[arguments[e].uuid]=e;this._paths=[],this._parsedPaths=[],this._bindings=[],this._bindingsIndicesByPath={};const e=this;this.stats={objects:{get total(){return e._objects.length},get inUse(){return this.total-e.nCachedObjects_}},get bindingsPerObject(){return e._bindings.length}}}add(){const t=this._objects,e=this._indicesByUUID,i=this._paths,n=this._parsedPaths,s=this._bindings,r=s.length;let a,o=t.length,l=this.nCachedObjects_;for(let h=0,c=arguments.length;h!==c;++h){const c=arguments[h],d=c.uuid;let u=e[d];if(void 0===u){u=o++,e[d]=u,t.push(c);for(let t=0,e=r;t!==e;++t)s[t].push(new Mc(c,i[t],n[t]))}else if(u<l){a=t[u];const o=--l,h=t[o];e[h.uuid]=u,t[u]=h,e[d]=o,t[o]=c;for(let t=0,e=r;t!==e;++t){const e=s[t],r=e[o];let a=e[u];e[u]=r,void 0===a&&(a=new Mc(c,i[t],n[t])),e[o]=a}}else t[u]!==a&&ni("AnimationObjectGroup: Different objects with the same UUID detected. Clean the caches or recreate your infrastructure when reloading scenes.")}this.nCachedObjects_=l}remove(){const t=this._objects,e=this._indicesByUUID,i=this._bindings,n=i.length;let s=this.nCachedObjects_;for(let r=0,a=arguments.length;r!==a;++r){const a=arguments[r],o=a.uuid,l=e[o];if(void 0!==l&&l>=s){const r=s++,h=t[r];e[h.uuid]=l,t[l]=h,e[o]=r,t[r]=a;for(let t=0,e=n;t!==e;++t){const e=i[t],n=e[r],s=e[l];e[l]=n,e[r]=s}}}this.nCachedObjects_=s}uncache(){const t=this._objects,e=this._indicesByUUID,i=this._bindings,n=i.length;let s=this.nCachedObjects_,r=t.length;for(let a=0,o=arguments.length;a!==o;++a){const o=arguments[a].uuid,l=e[o];if(void 0!==l)if(delete e[o],l<s){const a=--s,o=t[a],h=--r,c=t[h];e[o.uuid]=l,t[l]=o,e[c.uuid]=a,t[a]=c,t.pop();for(let t=0,e=n;t!==e;++t){const e=i[t],n=e[a],s=e[h];e[l]=n,e[a]=s,e.pop()}}else{const s=--r,a=t[s];s>0&&(e[a.uuid]=l),t[l]=a,t.pop();for(let t=0,e=n;t!==e;++t){const e=i[t];e[l]=e[s],e.pop()}}}this.nCachedObjects_=s}subscribe_(t,e){const i=this._bindingsIndicesByPath;let n=i[t];const s=this._bindings;if(void 0!==n)return s[n];const r=this._paths,a=this._parsedPaths,o=this._objects,l=o.length,h=this.nCachedObjects_,c=new Array(l);n=s.length,i[t]=n,r.push(t),a.push(e),s.push(c);for(let i=h,n=o.length;i!==n;++i){const n=o[i];c[i]=new Mc(n,t,e)}return c}unsubscribe_(t){const e=this._bindingsIndicesByPath,i=e[t];if(void 0!==i){const n=this._paths,s=this._parsedPaths,r=this._bindings,a=r.length-1,o=r[a];e[t[a]]=i,r[i]=o,r.pop(),s[i]=s[a],s.pop(),n[i]=n[a],n.pop()}}},AnimationUtils:class{static convertArray(t,e){return Gl(t,e)}static isTypedArray(t){return qe(t)}static getKeyframeOrder(t){return Hl(t)}static sortedArray(t,e,i){return Vl(t,e,i)}static flattenJSON(t,e,i,n){Wl(t,e,i,n)}static subclip(t,e,i,n,s=30){return function(t,e,i,n,s=30){const r=t.clone();r.name=e;const a=[];for(let t=0;t<r.tracks.length;++t){const e=r.tracks[t],o=e.getValueSize(),l=[],h=[];for(let t=0;t<e.times.length;++t){const r=e.times[t]*s;if(!(r<i||r>=n)){l.push(e.times[t]);for(let i=0;i<o;++i)h.push(e.values[t*o+i])}}0!==l.length&&(e.times=Gl(l,e.times.constructor),e.values=Gl(h,e.values.constructor),a.push(e))}r.tracks=a;let o=1/0;for(let t=0;t<r.tracks.length;++t)o>r.tracks[t].times[0]&&(o=r.tracks[t].times[0]);for(let t=0;t<r.tracks.length;++t)r.tracks[t].shift(-1*o);return r.resetDuration(),r}(t,e,i,n,s)}static makeClipAdditive(t,e=0,i=t,n=30){return function(t,e=0,i=t,n=30){n<=0&&(n=30);const s=i.tracks.length,r=e/n;for(let e=0;e<s;++e){const n=i.tracks[e],s=n.ValueTypeName;if("bool"===s||"string"===s)continue;const a=t.tracks.find(function(t){return t.name===n.name&&t.ValueTypeName===s});if(void 0===a)continue;let o=0;const l=n.getValueSize();n.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(o=l/3);let h=0;const c=a.getValueSize();a.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(h=c/3);const d=n.times.length-1;let u;if(r<=n.times[0]){const t=o,e=l-o;u=n.values.slice(t,e)}else if(r>=n.times[d]){const t=d*l+o,e=t+l-o;u=n.values.slice(t,e)}else{const t=n.createInterpolant(),e=o,i=l-o;t.evaluate(r),u=t.resultBuffer.slice(e,i)}"quaternion"===s&&(new _i).fromArray(u).normalize().conjugate().toArray(u);const p=a.times.length;for(let t=0;t<p;++t){const e=t*c+h;if("quaternion"===s)_i.multiplyQuaternionsFlat(a.values,e,u,0,a.values,e);else{const t=c-2*h;for(let i=0;i<t;++i)a.values[e+i]-=u[i]}}}return t.blendMode=Me,t}(t,e,i,n)}},ArcCurve:co,ArrayCamera:sc,ArrowHelper:class extends yn{constructor(t=new xi(0,0,1),e=new xi(0,0,0),i=1,n=16776960,s=.2*i,r=.2*s){super(),this.type="ArrowHelper",void 0===hd&&(hd=new Ds,hd.setAttribute("position",new vs([0,0,0,0,1,0],3)),cd=new to(.5,1,5,1),cd.translate(0,-.5,0)),this.position.copy(e),this.line=new Ra(hd,new Sa({color:n,toneMapped:!1})),this.line.matrixAutoUpdate=!1,this.add(this.line),this.cone=new xr(cd,new lr({color:n,toneMapped:!1})),this.cone.matrixAutoUpdate=!1,this.add(this.cone),this.setDirection(t),this.setLength(i,s,r)}setDirection(t){if(t.y>.99999)this.quaternion.set(0,0,0,1);else if(t.y<-.99999)this.quaternion.set(1,0,0,0);else{ld.set(t.z,0,-t.x).normalize();const e=Math.acos(t.y);this.quaternion.setFromAxisAngle(ld,e)}}setLength(t,e=.2*t,i=.2*e){this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(i,e,i),this.cone.position.y=t,this.cone.updateMatrix()}setColor(t){this.line.material.color.set(t),this.cone.material.color.set(t)}copy(t){return super.copy(t,!1),this.line.copy(t.line),this.cone.copy(t.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}},AttachedBindMode:j,Audio:dc,AudioAnalyser:class{constructor(t,e=2048){this.analyser=t.context.createAnalyser(),this.analyser.fftSize=e,this.data=new Uint8Array(this.analyser.frequencyBinCount),t.getOutput().connect(this.analyser)}getFrequencyData(){return this.analyser.getByteFrequencyData(this.data),this.data}getAverageFrequency(){let t=0;const e=this.getFrequencyData();for(let i=0;i<e.length;i++)t+=e[i];return t/e.length}},AudioContext:Jh,AudioListener:class extends yn{constructor(){super(),this.type="AudioListener",this.context=Jh.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new rc}getInput(){return this.gain}removeFilter(){return null!==this.filter&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this}getFilter(){return this.filter}setFilter(t){return null!==this.filter?(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)):this.gain.disconnect(this.context.destination),this.filter=t,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}updateMatrixWorld(t){super.updateMatrixWorld(t);const e=this.context.listener;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(ac,oc,lc),hc.set(0,0,-1).applyQuaternion(oc),cc.set(0,1,0).applyQuaternion(oc),e.positionX){const t=this.context.currentTime+this.timeDelta;e.positionX.linearRampToValueAtTime(ac.x,t),e.positionY.linearRampToValueAtTime(ac.y,t),e.positionZ.linearRampToValueAtTime(ac.z,t),e.forwardX.linearRampToValueAtTime(hc.x,t),e.forwardY.linearRampToValueAtTime(hc.y,t),e.forwardZ.linearRampToValueAtTime(hc.z,t),e.upX.linearRampToValueAtTime(cc.x,t),e.upY.linearRampToValueAtTime(cc.y,t),e.upZ.linearRampToValueAtTime(cc.z,t)}else e.setPosition(ac.x,ac.y,ac.z),e.setOrientation(hc.x,hc.y,hc.z,cc.x,cc.y,cc.z)}},AudioLoader:class extends ch{constructor(t){super(t)}load(t,e,i,n){const s=this,r=new ph(this.manager);function a(e){n?n(e):ni(e),s.manager.itemError(t)}r.setResponseType("arraybuffer"),r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,function(t){try{const i=t.slice(0);Jh.getContext().decodeAudioData(i,function(t){e(t)}).catch(a)}catch(t){a(t)}},i,n)}},AxesHelper:class extends Ba{constructor(t=1){const e=[0,0,0,t,0,0,0,0,0,0,t,0,0,0,0,0,0,t],i=new Ds;i.setAttribute("position",new vs(e,3)),i.setAttribute("color",new vs([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],3));super(i,new Sa({vertexColors:!0,toneMapped:!1})),this.type="AxesHelper"}setColors(t,e,i){const n=new En,s=this.geometry.attributes.color.array;return n.set(t),n.toArray(s,0),n.toArray(s,3),n.set(e),n.toArray(s,6),n.toArray(s,9),n.set(i),n.toArray(s,12),n.toArray(s,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}},BackSide:1,BasicDepthPacking:we,BasicShadowMap:0,BatchedMesh:ba,BezierInterpolant:ql,Bone:Ir,BooleanKeyframeTrack:Kl,Box2:class{constructor(t=new yi(1/0,1/0),e=new yi(-1/0,-1/0)){this.isBox2=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=Uc.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=1/0,this.max.x=this.max.y=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y}getCenter(t){return this.isEmpty()?t.set(0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Uc).distanceTo(t)}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}},Box3:jn,Box3Helper:class extends Ba{constructor(t,e=16776960){const i=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),n=new Ds;n.setIndex(new ms(i,1)),n.setAttribute("position",new vs([1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,-1,1,-1,-1],3)),super(n,new Sa({color:e,toneMapped:!1})),this.box=t,this.type="Box3Helper",this.geometry.computeBoundingSphere()}updateMatrixWorld(t){const e=this.box;e.isEmpty()||(e.getCenter(this.position),e.getSize(this.scale),this.scale.multiplyScalar(.5),super.updateMatrixWorld(t))}dispose(){this.geometry.dispose(),this.material.dispose()}},BoxGeometry:Qa,BoxHelper:class extends Ba{constructor(t,e=16776960){const i=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),n=new Float32Array(24),s=new Ds;s.setIndex(new ms(i,1)),s.setAttribute("position",new ms(n,3)),super(s,new Sa({color:e,toneMapped:!1})),this.object=t,this.type="BoxHelper",this.matrixAutoUpdate=!1,this.update()}update(){if(void 0!==this.object&&od.setFromObject(this.object),od.isEmpty())return;const t=od.min,e=od.max,i=this.geometry.attributes.position,n=i.array;n[0]=e.x,n[1]=e.y,n[2]=e.z,n[3]=t.x,n[4]=e.y,n[5]=e.z,n[6]=t.x,n[7]=t.y,n[8]=e.z,n[9]=e.x,n[10]=t.y,n[11]=e.z,n[12]=e.x,n[13]=e.y,n[14]=t.z,n[15]=t.x,n[16]=e.y,n[17]=t.z,n[18]=t.x,n[19]=t.y,n[20]=t.z,n[21]=e.x,n[22]=t.y,n[23]=t.z,i.needsUpdate=!0,this.geometry.computeBoundingSphere()}setFromObject(t){return this.object=t,this.update(),this}copy(t,e){return super.copy(t,e),this.object=t.object,this}dispose(){this.geometry.dispose(),this.material.dispose()}},BufferAttribute:ms,BufferGeometry:Ds,BufferGeometryLoader:Xh,ByteType:ht,Cache:ah,Camera:Th,CameraHelper:class extends Ba{constructor(t){const e=new Ds,i=new Sa({color:16777215,vertexColors:!0,toneMapped:!1}),n=[],s=[],r={};function a(t,e){o(t),o(e)}function o(t){n.push(0,0,0),s.push(0,0,0),void 0===r[t]&&(r[t]=[]),r[t].push(n.length/3-1)}a("n1","n2"),a("n2","n4"),a("n4","n3"),a("n3","n1"),a("f1","f2"),a("f2","f4"),a("f4","f3"),a("f3","f1"),a("n1","f1"),a("n2","f2"),a("n3","f3"),a("n4","f4"),a("p","n1"),a("p","n2"),a("p","n3"),a("p","n4"),a("u1","u2"),a("u2","u3"),a("u3","u1"),a("c","t"),a("p","c"),a("cn1","cn2"),a("cn3","cn4"),a("cf1","cf2"),a("cf3","cf4"),e.setAttribute("position",new vs(n,3)),e.setAttribute("color",new vs(s,3)),super(e,i),this.type="CameraHelper",this.camera=t,this.camera.updateProjectionMatrix&&this.camera.updateProjectionMatrix(),this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=r,this.update();const l=new En(16755200),h=new En(16711680),c=new En(43775),d=new En(16777215),u=new En(3355443);this.setColors(l,h,c,d,u)}setColors(t,e,i,n,s){const r=this.geometry.getAttribute("color");return r.setXYZ(0,t.r,t.g,t.b),r.setXYZ(1,t.r,t.g,t.b),r.setXYZ(2,t.r,t.g,t.b),r.setXYZ(3,t.r,t.g,t.b),r.setXYZ(4,t.r,t.g,t.b),r.setXYZ(5,t.r,t.g,t.b),r.setXYZ(6,t.r,t.g,t.b),r.setXYZ(7,t.r,t.g,t.b),r.setXYZ(8,t.r,t.g,t.b),r.setXYZ(9,t.r,t.g,t.b),r.setXYZ(10,t.r,t.g,t.b),r.setXYZ(11,t.r,t.g,t.b),r.setXYZ(12,t.r,t.g,t.b),r.setXYZ(13,t.r,t.g,t.b),r.setXYZ(14,t.r,t.g,t.b),r.setXYZ(15,t.r,t.g,t.b),r.setXYZ(16,t.r,t.g,t.b),r.setXYZ(17,t.r,t.g,t.b),r.setXYZ(18,t.r,t.g,t.b),r.setXYZ(19,t.r,t.g,t.b),r.setXYZ(20,t.r,t.g,t.b),r.setXYZ(21,t.r,t.g,t.b),r.setXYZ(22,t.r,t.g,t.b),r.setXYZ(23,t.r,t.g,t.b),r.setXYZ(24,e.r,e.g,e.b),r.setXYZ(25,e.r,e.g,e.b),r.setXYZ(26,e.r,e.g,e.b),r.setXYZ(27,e.r,e.g,e.b),r.setXYZ(28,e.r,e.g,e.b),r.setXYZ(29,e.r,e.g,e.b),r.setXYZ(30,e.r,e.g,e.b),r.setXYZ(31,e.r,e.g,e.b),r.setXYZ(32,i.r,i.g,i.b),r.setXYZ(33,i.r,i.g,i.b),r.setXYZ(34,i.r,i.g,i.b),r.setXYZ(35,i.r,i.g,i.b),r.setXYZ(36,i.r,i.g,i.b),r.setXYZ(37,i.r,i.g,i.b),r.setXYZ(38,n.r,n.g,n.b),r.setXYZ(39,n.r,n.g,n.b),r.setXYZ(40,s.r,s.g,s.b),r.setXYZ(41,s.r,s.g,s.b),r.setXYZ(42,s.r,s.g,s.b),r.setXYZ(43,s.r,s.g,s.b),r.setXYZ(44,s.r,s.g,s.b),r.setXYZ(45,s.r,s.g,s.b),r.setXYZ(46,s.r,s.g,s.b),r.setXYZ(47,s.r,s.g,s.b),r.setXYZ(48,s.r,s.g,s.b),r.setXYZ(49,s.r,s.g,s.b),r.needsUpdate=!0,this}update(){const t=this.geometry,e=this.pointMap;let i,n;if(rd.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse),!0===this.camera.reversedDepth)i=1,n=0;else if(this.camera.coordinateSystem===je)i=-1,n=1;else{if(this.camera.coordinateSystem!==Xe)throw new Error("THREE.CameraHelper.update(): Invalid coordinate system: "+this.camera.coordinateSystem);i=0,n=1}ad("c",e,t,rd,0,0,i),ad("t",e,t,rd,0,0,n),ad("n1",e,t,rd,-1,-1,i),ad("n2",e,t,rd,1,-1,i),ad("n3",e,t,rd,-1,1,i),ad("n4",e,t,rd,1,1,i),ad("f1",e,t,rd,-1,-1,n),ad("f2",e,t,rd,1,-1,n),ad("f3",e,t,rd,-1,1,n),ad("f4",e,t,rd,1,1,n),ad("u1",e,t,rd,.7,1.1,i),ad("u2",e,t,rd,-.7,1.1,i),ad("u3",e,t,rd,0,2,i),ad("cf1",e,t,rd,-1,0,n),ad("cf2",e,t,rd,1,0,n),ad("cf3",e,t,rd,0,-1,n),ad("cf4",e,t,rd,0,1,n),ad("cn1",e,t,rd,-1,0,i),ad("cn2",e,t,rd,1,0,i),ad("cn3",e,t,rd,0,-1,i),ad("cn4",e,t,rd,0,1,i),t.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}},CanvasTexture:Xa,CapsuleGeometry:Ka,CatmullRomCurve3:vo,CineonToneMapping:3,CircleGeometry:Ja,ClampToEdgeWrapping:tt,Clock:rc,Color:En,ColorKeyframeTrack:Jl,ColorManagement:Ci,Compatibility:{TEXTURE_COMPARE:"depthTextureCompare"},CompressedArrayTexture:class extends Wa{constructor(t,e,i,n,s,r){super(t,e,i,s,r),this.isCompressedArrayTexture=!0,this.image.depth=n,this.wrapR=tt,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}},CompressedCubeTexture:class extends Wa{constructor(t,e,i){super(void 0,t[0].width,t[0].height,e,i,Z),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=t}},CompressedTexture:Wa,CompressedTextureLoader:class extends ch{constructor(t){super(t)}load(t,e,i,n){const s=this,r=[],a=new Wa,o=new ph(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(s.withCredentials);let l=0;function h(h){o.load(t[h],function(t){const i=s.parse(t,!0);r[h]={width:i.width,height:i.height,format:i.format,mipmaps:i.mipmaps},l+=1,6===l&&(1===i.mipmapCount&&(a.minFilter=rt),a.image=r,a.format=i.format,a.needsUpdate=!0,e&&e(a))},i,n)}if(Array.isArray(t))for(let e=0,i=t.length;e<i;++e)h(e);else o.load(t,function(t){const i=s.parse(t,!0);if(i.isCubemap){const t=i.mipmaps.length/i.mipmapCount;for(let e=0;e<t;e++){r[e]={mipmaps:[]};for(let t=0;t<i.mipmapCount;t++)r[e].mipmaps.push(i.mipmaps[e*i.mipmapCount+t]),r[e].format=i.format,r[e].width=i.width,r[e].height=i.height}a.image=r}else a.image.width=i.width,a.image.height=i.height,a.mipmaps=i.mipmaps;1===i.mipmapCount&&(a.minFilter=rt),a.format=i.format,a.needsUpdate=!0,e&&e(a)},i,n);return a}},ConeGeometry:to,ConstantAlphaFactor:213,ConstantColorFactor:211,Controls:ud,CubeCamera:nc,CubeDepthTexture:Za,CubeReflectionMapping:Z,CubeRefractionMapping:q,CubeTexture:ja,CubeTextureLoader:class extends ch{constructor(t){super(t)}load(t,e,i,n){const s=new ja;s.colorSpace=Ee;const r=new fh(this.manager);r.setCrossOrigin(this.crossOrigin),r.setPath(this.path);let a=0;function o(i){r.load(t[i],function(t){s.images[i]=t,a++,6===a&&(s.needsUpdate=!0,e&&e(s))},void 0,n)}for(let e=0;e<t.length;++e)o(e);return s}},CubeUVReflectionMapping:J,CubicBezierCurve:bo,CubicBezierCurve3:So,CubicInterpolant:Xl,CullFaceBack:1,CullFaceFront:2,CullFaceFrontBack:3,CullFaceNone:0,Curve:lo,CurvePath:Do,CustomBlending:5,CustomToneMapping:5,CylinderGeometry:$a,Cylindrical:class{constructor(t=1,e=0,i=0){this.radius=t,this.theta=e,this.y=i}set(t,e,i){return this.radius=t,this.theta=e,this.y=i,this}copy(t){return this.radius=t.radius,this.theta=t.theta,this.y=t.y,this}setFromVector3(t){return this.setFromCartesianCoords(t.x,t.y,t.z)}setFromCartesianCoords(t,e,i){return this.radius=Math.sqrt(t*t+i*i),this.theta=Math.atan2(t,i),this.y=e,this}clone(){return(new this.constructor).copy(this)}},Data3DTexture:Vi,DataArrayTexture:Hi,DataTexture:Lr,DataTextureLoader:gh,DataUtils:cs,DecrementStencilOp:7683,DecrementWrapStencilOp:Le,DefaultLoadingManager:hh,DepthFormat:wt,DepthStencilFormat:At,DepthTexture:Ya,DetachedBindMode:X,DirectionalLight:Uh,DirectionalLightHelper:class extends yn{constructor(t,e,i){super(),this.light=t,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.color=i,this.type="DirectionalLightHelper",void 0===e&&(e=1);let n=new Ds;n.setAttribute("position",new vs([-e,e,0,e,e,0,e,-e,0,-e,-e,0,-e,e,0],3));const s=new Sa({fog:!1,toneMapped:!1});this.lightPlane=new Ra(n,s),this.add(this.lightPlane),n=new Ds,n.setAttribute("position",new vs([0,0,0,0,0,1],3)),this.targetLine=new Ra(n,s),this.add(this.targetLine),this.update()}dispose(){this.lightPlane.geometry.dispose(),this.lightPlane.material.dispose(),this.targetLine.geometry.dispose(),this.targetLine.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),this.light.target.updateWorldMatrix(!0,!1),ed.setFromMatrixPosition(this.light.matrixWorld),id.setFromMatrixPosition(this.light.target.matrixWorld),nd.subVectors(id,ed),this.lightPlane.lookAt(id),void 0!==this.color?(this.lightPlane.material.color.set(this.color),this.targetLine.material.color.set(this.color)):(this.lightPlane.material.color.copy(this.light.color),this.targetLine.material.color.copy(this.light.color)),this.targetLine.lookAt(id),this.targetLine.scale.z=nd.length()}},DiscreteInterpolant:Zl,DodecahedronGeometry:io,DoubleSide:2,DstAlphaFactor:206,DstColorFactor:208,DynamicCopyUsage:35050,DynamicDrawUsage:35048,DynamicReadUsage:35049,EdgesGeometry:oo,EllipseCurve:ho,EqualCompare:514,EqualDepth:4,EqualStencilFunc:514,EquirectangularReflectionMapping:Q,EquirectangularRefractionMapping:K,Euler:tn,EventDispatcher:ai,ExternalTexture:qa,ExtrudeGeometry:ll,FileLoader:ph,Float16BufferAttribute:class extends ms{constructor(t,e,i){super(new Uint16Array(t),e,i),this.isFloat16BufferAttribute=!0}getX(t){let e=hs(this.array[t*this.itemSize]);return this.normalized&&(e=fi(e,this.array)),e}setX(t,e){return this.normalized&&(e=gi(e,this.array)),this.array[t*this.itemSize]=ls(e),this}getY(t){let e=hs(this.array[t*this.itemSize+1]);return this.normalized&&(e=fi(e,this.array)),e}setY(t,e){return this.normalized&&(e=gi(e,this.array)),this.array[t*this.itemSize+1]=ls(e),this}getZ(t){let e=hs(this.array[t*this.itemSize+2]);return this.normalized&&(e=fi(e,this.array)),e}setZ(t,e){return this.normalized&&(e=gi(e,this.array)),this.array[t*this.itemSize+2]=ls(e),this}getW(t){let e=hs(this.array[t*this.itemSize+3]);return this.normalized&&(e=fi(e,this.array)),e}setW(t,e){return this.normalized&&(e=gi(e,this.array)),this.array[t*this.itemSize+3]=ls(e),this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=gi(e,this.array),i=gi(i,this.array)),this.array[t+0]=ls(e),this.array[t+1]=ls(i),this}setXYZ(t,e,i,n){return t*=this.itemSize,this.normalized&&(e=gi(e,this.array),i=gi(i,this.array),n=gi(n,this.array)),this.array[t+0]=ls(e),this.array[t+1]=ls(i),this.array[t+2]=ls(n),this}setXYZW(t,e,i,n,s){return t*=this.itemSize,this.normalized&&(e=gi(e,this.array),i=gi(i,this.array),n=gi(n,this.array),s=gi(s,this.array)),this.array[t+0]=ls(e),this.array[t+1]=ls(i),this.array[t+2]=ls(n),this.array[t+3]=ls(s),this}},Float32BufferAttribute:vs,FloatType:mt,Fog:Dn,FogExp2:Cn,FramebufferTexture:class extends Ui{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=it,this.minFilter=it,this.generateMipmaps=!1,this.needsUpdate=!0}},FrontSide:0,Frustum:$r,FrustumArray:ia,GLBufferAttribute:class{constructor(t,e,i,n,s,r=!1){this.isGLBufferAttribute=!0,this.name="",this.buffer=t,this.type=e,this.itemSize=i,this.elementSize=n,this.count=s,this.normalized=r,this.version=0}set needsUpdate(t){!0===t&&this.version++}setBuffer(t){return this.buffer=t,this}setType(t,e){return this.type=t,this.elementSize=e,this}setItemSize(t){return this.itemSize=t,this}setCount(t){return this.count=t,this}},GLSL1:"100",GLSL3:We,GreaterCompare:516,GreaterDepth:6,GreaterEqualCompare:Ge,GreaterEqualDepth:5,GreaterEqualStencilFunc:518,GreaterStencilFunc:516,GridHelper:class extends Ba{constructor(t=10,e=10,i=4473924,n=8947848){i=new En(i),n=new En(n);const s=e/2,r=t/e,a=t/2,o=[],l=[];for(let t=0,h=0,c=-a;t<=e;t++,c+=r){o.push(-a,0,c,a,0,c),o.push(c,0,-a,c,0,a);const e=t===s?i:n;e.toArray(l,h),h+=3,e.toArray(l,h),h+=3,e.toArray(l,h),h+=3,e.toArray(l,h),h+=3}const h=new Ds;h.setAttribute("position",new vs(o,3)),h.setAttribute("color",new vs(l,3));super(h,new Sa({vertexColors:!0,toneMapped:!1})),this.type="GridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}},Group:_n,HalfFloatType:ft,HemisphereLight:_h,HemisphereLightHelper:class extends yn{constructor(t,e,i){super(),this.light=t,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.color=i,this.type="HemisphereLightHelper";const n=new ul(e);n.rotateY(.5*Math.PI),this.material=new lr({wireframe:!0,fog:!1,toneMapped:!1}),void 0===this.color&&(this.material.vertexColors=!0);const s=n.getAttribute("position"),r=new Float32Array(3*s.count);n.setAttribute("color",new ms(r,3)),this.add(new xr(n,this.material)),this.update()}dispose(){this.children[0].geometry.dispose(),this.children[0].material.dispose()}update(){const t=this.children[0];if(void 0!==this.color)this.material.color.set(this.color);else{const e=t.geometry.getAttribute("color");$c.copy(this.light.color),td.copy(this.light.groundColor);for(let t=0,i=e.count;t<i;t++){const n=t<i/2?$c:td;e.setXYZ(t,n.r,n.g,n.b)}e.needsUpdate=!0}this.light.updateWorldMatrix(!0,!1),t.lookAt(Jc.setFromMatrixPosition(this.light.matrixWorld).negate())}},IcosahedronGeometry:cl,ImageBitmapLoader:class extends ch{constructor(t){super(t),this.isImageBitmapLoader=!0,"undefined"==typeof createImageBitmap&&ii("ImageBitmapLoader: createImageBitmap() not supported."),"undefined"==typeof fetch&&ii("ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"},this._abortController=new AbortController}setOptions(t){return this.options=t,this}load(t,e,i,n){void 0===t&&(t=""),void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const s=this,r=ah.get(`image-bitmap:${t}`);if(void 0!==r)return s.manager.itemStart(t),r.then?void r.then(i=>{if(!0!==Qh.has(r))return e&&e(i),s.manager.itemEnd(t),i;n&&n(Qh.get(r)),s.manager.itemError(t),s.manager.itemEnd(t)}):(setTimeout(function(){e&&e(r),s.manager.itemEnd(t)},0),r);const a={};a.credentials="anonymous"===this.crossOrigin?"same-origin":"include",a.headers=this.requestHeader,a.signal="function"==typeof AbortSignal.any?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal;const o=fetch(t,a).then(function(t){return t.blob()}).then(function(t){return createImageBitmap(t,Object.assign(s.options,{colorSpaceConversion:"none"}))}).then(function(i){return ah.add(`image-bitmap:${t}`,i),e&&e(i),s.manager.itemEnd(t),i}).catch(function(e){n&&n(e),Qh.set(o,e),ah.remove(`image-bitmap:${t}`),s.manager.itemError(t),s.manager.itemEnd(t)});ah.add(`image-bitmap:${t}`,o),s.manager.itemStart(t)}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}},ImageLoader:fh,ImageUtils:Ii,IncrementStencilOp:7682,IncrementWrapStencilOp:Ie,InstancedBufferAttribute:Nr,InstancedBufferGeometry:jh,InstancedInterleavedBuffer:Dc,InstancedMesh:jr,Int16BufferAttribute:class extends ms{constructor(t,e,i){super(new Int16Array(t),e,i)}},Int32BufferAttribute:class extends ms{constructor(t,e,i){super(new Int32Array(t),e,i)}},Int8BufferAttribute:class extends ms{constructor(t,e,i){super(new Int8Array(t),e,i)}},IntType:ut,InterleavedBuffer:Rs,InterleavedBufferAttribute:Is,Interpolant:jl,InterpolateBezier:ye,InterpolateDiscrete:fe,InterpolateLinear:ge,InterpolateSmooth:ve,InterpolationSamplingMode:{NORMAL:"normal",CENTROID:"centroid",SAMPLE:"sample",FIRST:"first",EITHER:"either"},InterpolationSamplingType:{PERSPECTIVE:"perspective",LINEAR:"linear",FLAT:"flat"},InvertStencilOp:5386,KeepStencilOp:Re,KeyframeTrack:Ql,LOD:$s,LatheGeometry:dl,Layers:en,LessCompare:513,LessDepth:2,LessEqualCompare:Ue,LessEqualDepth:3,LessEqualStencilFunc:515,LessStencilFunc:513,Light:yh,LightProbe:Hh,Line:Ra,Line3:Xc,LineBasicMaterial:Sa,LineCurve:Mo,LineCurve3:wo,LineDashedMaterial:zl,LineLoop:Oa,LineSegments:Ba,LinearFilter:rt,LinearInterpolant:Yl,LinearMipMapLinearFilter:1008,LinearMipMapNearestFilter:1007,LinearMipmapLinearFilter:ot,LinearMipmapNearestFilter:at,LinearSRGBColorSpace:Te,LinearToneMapping:1,LinearTransfer:Ce,Loader:ch,LoaderUtils:Wh,LoadingManager:lh,LoopOnce:2200,LoopPingPong:me,LoopRepeat:pe,MOUSE:i,Material:Os,MaterialBlending:6,MaterialLoader:Vh,MathUtils:vi,Matrix2:Nc,Matrix3:Mi,Matrix4:Wi,MaxEquation:104,Mesh:xr,MeshBasicMaterial:lr,MeshDepthMaterial:Nl,MeshDistanceMaterial:Ul,MeshLambertMaterial:Fl,MeshMatcapMaterial:kl,MeshNormalMaterial:Ol,MeshPhongMaterial:Ll,MeshPhysicalMaterial:Il,MeshStandardMaterial:Pl,MeshToonMaterial:Bl,MinEquation:103,MirroredRepeatWrapping:et,MixOperation:1,MultiplyBlending:4,MultiplyOperation:0,NearestFilter:it,NearestMipMapLinearFilter:1005,NearestMipMapNearestFilter:1004,NearestMipmapLinearFilter:st,NearestMipmapNearestFilter:nt,NeutralToneMapping:7,NeverCompare:512,NeverDepth:0,NeverStencilFunc:512,NoBlending:0,NoColorSpace:Ae,NoNormalPacking:"",NoToneMapping:0,NormalAnimationBlendMode:Se,NormalBlending:1,NormalGAPacking:"ga",NormalRGPacking:"rg",NotEqualCompare:517,NotEqualDepth:7,NotEqualStencilFunc:517,NumberKeyframeTrack:$l,Object3D:yn,ObjectLoader:class extends ch{constructor(t){super(t)}load(t,e,i,n){const s=this,r=""===this.path?Wh.extractUrlBase(t):this.path;this.resourcePath=this.resourcePath||r;const a=new ph(this.manager);a.setPath(this.path),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(t,function(i){let r=null;try{r=JSON.parse(i)}catch(e){return void 0!==n&&n(e),void e("ObjectLoader: Can't parse "+t+".",e.message)}const a=r.metadata;if(void 0===a||void 0===a.type||"geometry"===a.type.toLowerCase())return void 0!==n&&n(new Error("THREE.ObjectLoader: Can't load "+t)),void ni("ObjectLoader: Can't load "+t);s.parse(r,e)},i,n)}async loadAsync(t,e){const i=""===this.path?Wh.extractUrlBase(t):this.path;this.resourcePath=this.resourcePath||i;const n=new ph(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials);const s=await n.loadAsync(t,e);let r;try{r=JSON.parse(s)}catch(e){throw new Error("ObjectLoader: Can't parse "+t+". "+e.message)}const a=r.metadata;if(void 0===a||void 0===a.type||"geometry"===a.type.toLowerCase())throw new Error("THREE.ObjectLoader: Can't load "+t);return await this.parseAsync(r)}parse(t,e){const i=this.parseAnimations(t.animations),n=this.parseShapes(t.shapes),s=this.parseGeometries(t.geometries,n),r=this.parseImages(t.images,function(){void 0!==e&&e(l)}),a=this.parseTextures(t.textures,r),o=this.parseMaterials(t.materials,a),l=this.parseObject(t.object,s,o,a,i),h=this.parseSkeletons(t.skeletons,l);if(this.bindSkeletons(l,h),this.bindLightTargets(l),void 0!==e){let t=!1;for(const e in r)if(r[e].data instanceof HTMLImageElement){t=!0;break}!1===t&&e(l)}return l}async parseAsync(t){const e=this.parseAnimations(t.animations),i=this.parseShapes(t.shapes),n=this.parseGeometries(t.geometries,i),s=await this.parseImagesAsync(t.images),r=this.parseTextures(t.textures,s),a=this.parseMaterials(t.materials,r),o=this.parseObject(t.object,n,a,r,e),l=this.parseSkeletons(t.skeletons,o);return this.bindSkeletons(o,l),this.bindLightTargets(o),o}parseShapes(t){const e={};if(void 0!==t)for(let i=0,n=t.length;i<n;i++){const n=(new Po).fromJSON(t[i]);e[n.uuid]=n}return e}parseSkeletons(t,e){const i={},n={};if(e.traverse(function(t){t.isBone&&(n[t.uuid]=t)}),void 0!==t)for(let e=0,s=t.length;e<s;e++){const s=(new Fr).fromJSON(t[e],n);i[s.uuid]=s}return i}parseGeometries(t,e){const i={};if(void 0!==t){const n=new Xh;for(let s=0,r=t.length;s<r;s++){let r;const a=t[s];switch(a.type){case"BufferGeometry":case"InstancedBufferGeometry":r=n.parse(a);break;default:a.type in Ml?r=Ml[a.type].fromJSON(a,e):ii(`ObjectLoader: Unsupported geometry type "${a.type}"`)}r.uuid=a.uuid,void 0!==a.name&&(r.name=a.name),void 0!==a.userData&&(r.userData=a.userData),i[a.uuid]=r}}return i}parseMaterials(t,e){const i={},n={};if(void 0!==t){const s=new Vh;s.setTextures(e);for(let e=0,r=t.length;e<r;e++){const r=t[e];void 0===i[r.uuid]&&(i[r.uuid]=s.parse(r)),n[r.uuid]=i[r.uuid]}}return n}parseAnimations(t){const e={};if(void 0!==t)for(let i=0;i<t.length;i++){const n=t[i],s=sh.parse(n);e[s.uuid]=s}return e}parseImages(t,e){const i=this,n={};let s;function r(t){if("string"==typeof t){const e=t;return function(t){return i.manager.itemStart(t),s.load(t,function(){i.manager.itemEnd(t)},void 0,function(){i.manager.itemError(t),i.manager.itemEnd(t)})}(/^(\/\/)|([a-z]+:(\/\/)?)/i.test(e)?e:i.resourcePath+e)}return t.data?{data:Ze(t.type,t.data),width:t.width,height:t.height}:null}if(void 0!==t&&t.length>0){const i=new lh(e);s=new fh(i),s.setCrossOrigin(this.crossOrigin);for(let e=0,i=t.length;e<i;e++){const i=t[e],s=i.url;if(Array.isArray(s)){const t=[];for(let e=0,i=s.length;e<i;e++){const i=r(s[e]);null!==i&&(i instanceof HTMLImageElement?t.push(i):t.push(new Lr(i.data,i.width,i.height)))}n[i.uuid]=new Bi(t)}else{const t=r(i.url);n[i.uuid]=new Bi(t)}}}return n}async parseImagesAsync(t){const e=this,i={};let n;async function s(t){if("string"==typeof t){const i=t,s=/^(\/\/)|([a-z]+:(\/\/)?)/i.test(i)?i:e.resourcePath+i;return await n.loadAsync(s)}return t.data?{data:Ze(t.type,t.data),width:t.width,height:t.height}:null}if(void 0!==t&&t.length>0){n=new fh(this.manager),n.setCrossOrigin(this.crossOrigin);for(let e=0,n=t.length;e<n;e++){const n=t[e],r=n.url;if(Array.isArray(r)){const t=[];for(let e=0,i=r.length;e<i;e++){const i=r[e],n=await s(i);null!==n&&(n instanceof HTMLImageElement?t.push(n):t.push(new Lr(n.data,n.width,n.height)))}i[n.uuid]=new Bi(t)}else{const t=await s(n.url);i[n.uuid]=new Bi(t)}}}return i}parseTextures(t,e){function i(t,e){return"number"==typeof t?t:(ii("ObjectLoader.parseTexture: Constant should be in numeric form.",t),e[t])}const n={};if(void 0!==t)for(let s=0,r=t.length;s<r;s++){const r=t[s];void 0===r.image&&ii('ObjectLoader: No "image" specified for',r.uuid),void 0===e[r.image]&&ii("ObjectLoader: Undefined image",r.image);const a=e[r.image],o=a.data;let l;Array.isArray(o)?(l=new ja,6===o.length&&(l.needsUpdate=!0)):(l=o&&o.data?new Lr:new Ui,o&&(l.needsUpdate=!0)),l.source=a,l.uuid=r.uuid,void 0!==r.name&&(l.name=r.name),void 0!==r.mapping&&(l.mapping=i(r.mapping,Yh)),void 0!==r.channel&&(l.channel=r.channel),void 0!==r.offset&&l.offset.fromArray(r.offset),void 0!==r.repeat&&l.repeat.fromArray(r.repeat),void 0!==r.center&&l.center.fromArray(r.center),void 0!==r.rotation&&(l.rotation=r.rotation),void 0!==r.wrap&&(l.wrapS=i(r.wrap[0],Zh),l.wrapT=i(r.wrap[1],Zh)),void 0!==r.format&&(l.format=r.format),void 0!==r.internalFormat&&(l.internalFormat=r.internalFormat),void 0!==r.type&&(l.type=r.type),void 0!==r.colorSpace&&(l.colorSpace=r.colorSpace),void 0!==r.minFilter&&(l.minFilter=i(r.minFilter,qh)),void 0!==r.magFilter&&(l.magFilter=i(r.magFilter,qh)),void 0!==r.anisotropy&&(l.anisotropy=r.anisotropy),void 0!==r.flipY&&(l.flipY=r.flipY),void 0!==r.generateMipmaps&&(l.generateMipmaps=r.generateMipmaps),void 0!==r.premultiplyAlpha&&(l.premultiplyAlpha=r.premultiplyAlpha),void 0!==r.unpackAlignment&&(l.unpackAlignment=r.unpackAlignment),void 0!==r.compareFunction&&(l.compareFunction=r.compareFunction),void 0!==r.userData&&(l.userData=r.userData),n[r.uuid]=l}return n}parseObject(t,e,i,n,s){let r,a,o;function l(t){return void 0===e[t]&&ii("ObjectLoader: Undefined geometry",t),e[t]}function h(t){if(void 0!==t){if(Array.isArray(t)){const e=[];for(let n=0,s=t.length;n<s;n++){const s=t[n];void 0===i[s]&&ii("ObjectLoader: Undefined material",s),e.push(i[s])}return e}return void 0===i[t]&&ii("ObjectLoader: Undefined material",t),i[t]}}function c(t){return void 0===n[t]&&ii("ObjectLoader: Undefined texture",t),n[t]}switch(t.type){case"Scene":r=new Rn,void 0!==t.background&&(Number.isInteger(t.background)?r.background=new En(t.background):r.background=c(t.background)),void 0!==t.environment&&(r.environment=c(t.environment)),void 0!==t.fog&&("Fog"===t.fog.type?r.fog=new Dn(t.fog.color,t.fog.near,t.fog.far):"FogExp2"===t.fog.type&&(r.fog=new Cn(t.fog.color,t.fog.density)),""!==t.fog.name&&(r.fog.name=t.fog.name)),void 0!==t.backgroundBlurriness&&(r.backgroundBlurriness=t.backgroundBlurriness),void 0!==t.backgroundIntensity&&(r.backgroundIntensity=t.backgroundIntensity),void 0!==t.backgroundRotation&&r.backgroundRotation.fromArray(t.backgroundRotation),void 0!==t.environmentIntensity&&(r.environmentIntensity=t.environmentIntensity),void 0!==t.environmentRotation&&r.environmentRotation.fromArray(t.environmentRotation);break;case"PerspectiveCamera":r=new Ph(t.fov,t.aspect,t.near,t.far),void 0!==t.focus&&(r.focus=t.focus),void 0!==t.zoom&&(r.zoom=t.zoom),void 0!==t.filmGauge&&(r.filmGauge=t.filmGauge),void 0!==t.filmOffset&&(r.filmOffset=t.filmOffset),void 0!==t.view&&(r.view=Object.assign({},t.view));break;case"OrthographicCamera":r=new Fh(t.left,t.right,t.top,t.bottom,t.near,t.far),void 0!==t.zoom&&(r.zoom=t.zoom),void 0!==t.view&&(r.view=Object.assign({},t.view));break;case"AmbientLight":r=new kh(t.color,t.intensity);break;case"DirectionalLight":r=new Uh(t.color,t.intensity),r.target=t.target||"";break;case"PointLight":r=new Oh(t.color,t.intensity,t.distance,t.decay);break;case"RectAreaLight":r=new zh(t.color,t.intensity,t.width,t.height);break;case"SpotLight":r=new Lh(t.color,t.intensity,t.distance,t.angle,t.penumbra,t.decay),r.target=t.target||"";break;case"HemisphereLight":r=new _h(t.color,t.groundColor,t.intensity);break;case"LightProbe":const e=(new Gh).fromArray(t.sh);r=new Hh(e,t.intensity);break;case"SkinnedMesh":a=l(t.geometry),o=h(t.material),r=new Pr(a,o),void 0!==t.bindMode&&(r.bindMode=t.bindMode),void 0!==t.bindMatrix&&r.bindMatrix.fromArray(t.bindMatrix),void 0!==t.skeleton&&(r.skeleton=t.skeleton);break;case"Mesh":a=l(t.geometry),o=h(t.material),r=new xr(a,o);break;case"InstancedMesh":a=l(t.geometry),o=h(t.material);const i=t.count,n=t.instanceMatrix,s=t.instanceColor;r=new jr(a,o,i),r.instanceMatrix=new Nr(new Float32Array(n.array),16),void 0!==s&&(r.instanceColor=new Nr(new Float32Array(s.array),s.itemSize));break;case"BatchedMesh":a=l(t.geometry),o=h(t.material),r=new ba(t.maxInstanceCount,t.maxVertexCount,t.maxIndexCount,o),r.geometry=a,r.perObjectFrustumCulled=t.perObjectFrustumCulled,r.sortObjects=t.sortObjects,r._drawRanges=t.drawRanges,r._reservedRanges=t.reservedRanges,r._geometryInfo=t.geometryInfo.map(t=>{let e=null,i=null;return void 0!==t.boundingBox&&(e=(new jn).fromJSON(t.boundingBox)),void 0!==t.boundingSphere&&(i=(new bs).fromJSON(t.boundingSphere)),{...t,boundingBox:e,boundingSphere:i}}),r._instanceInfo=t.instanceInfo,r._availableInstanceIds=t._availableInstanceIds,r._availableGeometryIds=t._availableGeometryIds,r._nextIndexStart=t.nextIndexStart,r._nextVertexStart=t.nextVertexStart,r._geometryCount=t.geometryCount,r._maxInstanceCount=t.maxInstanceCount,r._maxVertexCount=t.maxVertexCount,r._maxIndexCount=t.maxIndexCount,r._geometryInitialized=t.geometryInitialized,r._matricesTexture=c(t.matricesTexture.uuid),r._indirectTexture=c(t.indirectTexture.uuid),void 0!==t.colorsTexture&&(r._colorsTexture=c(t.colorsTexture.uuid)),void 0!==t.boundingSphere&&(r.boundingSphere=(new bs).fromJSON(t.boundingSphere)),void 0!==t.boundingBox&&(r.boundingBox=(new jn).fromJSON(t.boundingBox));break;case"LOD":r=new $s;break;case"Line":r=new Ra(l(t.geometry),h(t.material));break;case"LineLoop":r=new Oa(l(t.geometry),h(t.material));break;case"LineSegments":r=new Ba(l(t.geometry),h(t.material));break;case"PointCloud":case"Points":r=new Ga(l(t.geometry),h(t.material));break;case"Sprite":r=new qs(h(t.material));break;case"Group":r=new _n;break;case"Bone":r=new Ir;break;default:r=new yn}if(r.uuid=t.uuid,void 0!==t.name&&(r.name=t.name),void 0!==t.matrix?(r.matrix.fromArray(t.matrix),void 0!==t.matrixAutoUpdate&&(r.matrixAutoUpdate=t.matrixAutoUpdate),r.matrixAutoUpdate&&r.matrix.decompose(r.position,r.quaternion,r.scale)):(void 0!==t.position&&r.position.fromArray(t.position),void 0!==t.rotation&&r.rotation.fromArray(t.rotation),void 0!==t.quaternion&&r.quaternion.fromArray(t.quaternion),void 0!==t.scale&&r.scale.fromArray(t.scale)),void 0!==t.up&&r.up.fromArray(t.up),void 0!==t.pivot&&(r.pivot=(new xi).fromArray(t.pivot)),void 0!==t.morphTargetDictionary&&(r.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),void 0!==t.morphTargetInfluences&&(r.morphTargetInfluences=t.morphTargetInfluences.slice()),void 0!==t.castShadow&&(r.castShadow=t.castShadow),void 0!==t.receiveShadow&&(r.receiveShadow=t.receiveShadow),t.shadow&&(void 0!==t.shadow.intensity&&(r.shadow.intensity=t.shadow.intensity),void 0!==t.shadow.bias&&(r.shadow.bias=t.shadow.bias),void 0!==t.shadow.normalBias&&(r.shadow.normalBias=t.shadow.normalBias),void 0!==t.shadow.radius&&(r.shadow.radius=t.shadow.radius),void 0!==t.shadow.mapSize&&r.shadow.mapSize.fromArray(t.shadow.mapSize),void 0!==t.shadow.camera&&(r.shadow.camera=this.parseObject(t.shadow.camera))),void 0!==t.visible&&(r.visible=t.visible),void 0!==t.frustumCulled&&(r.frustumCulled=t.frustumCulled),void 0!==t.renderOrder&&(r.renderOrder=t.renderOrder),void 0!==t.static&&(r.static=t.static),void 0!==t.userData&&(r.userData=t.userData),void 0!==t.layers&&(r.layers.mask=t.layers),void 0!==t.children){const a=t.children;for(let t=0;t<a.length;t++)r.add(this.parseObject(a[t],e,i,n,s))}if(void 0!==t.animations){const e=t.animations;for(let t=0;t<e.length;t++){const i=e[t];r.animations.push(s[i])}}if("LOD"===t.type){void 0!==t.autoUpdate&&(r.autoUpdate=t.autoUpdate);const e=t.levels;for(let t=0;t<e.length;t++){const i=e[t],n=r.getObjectByProperty("uuid",i.object);void 0!==n&&r.addLevel(n,i.distance,i.hysteresis)}}return r}bindSkeletons(t,e){0!==Object.keys(e).length&&t.traverse(function(t){if(!0===t.isSkinnedMesh&&void 0!==t.skeleton){const i=e[t.skeleton];void 0===i?ii("ObjectLoader: No skeleton found with UUID:",t.skeleton):t.bind(i,t.bindMatrix)}})}bindLightTargets(t){t.traverse(function(e){if(e.isDirectionalLight||e.isSpotLight){const i=e.target,n=t.getObjectByProperty("uuid",i);e.target=void 0!==n?n:new yn}})}},ObjectSpaceNormalMap:1,OctahedronGeometry:ul,OneFactor:201,OneMinusConstantAlphaFactor:214,OneMinusConstantColorFactor:212,OneMinusDstAlphaFactor:207,OneMinusDstColorFactor:209,OneMinusSrcAlphaFactor:v,OneMinusSrcColorFactor:203,OrthographicCamera:Fh,PCFShadowMap:1,PCFSoftShadowMap:2,PMREMGenerator:Fd,Path:Ro,PerspectiveCamera:Ph,Plane:qr,PlaneGeometry:pl,PlaneHelper:class extends Ra{constructor(t,e=1,i=16776960){const n=i,s=new Ds;s.setAttribute("position",new vs([1,-1,0,-1,1,0,-1,-1,0,1,1,0,-1,1,0,-1,-1,0,1,-1,0,1,1,0],3)),s.computeBoundingSphere(),super(s,new Sa({color:n,toneMapped:!1})),this.type="PlaneHelper",this.plane=t,this.size=e;const r=new Ds;r.setAttribute("position",new vs([1,1,0,-1,1,0,-1,-1,0,1,1,0,-1,-1,0,1,-1,0],3)),r.computeBoundingSphere(),this.add(new xr(r,new lr({color:n,opacity:.2,transparent:!0,depthWrite:!1,toneMapped:!1})))}updateMatrixWorld(t){this.position.set(0,0,0),this.scale.set(.5*this.size,.5*this.size,1),this.lookAt(this.plane.normal),this.translateZ(-this.plane.constant),super.updateMatrixWorld(t)}dispose(){this.geometry.dispose(),this.material.dispose(),this.children[0].geometry.dispose(),this.children[0].material.dispose()}},PointLight:Oh,PointLightHelper:class extends xr{constructor(t,e,i){super(new gl(e,4,2),new lr({wireframe:!0,fog:!1,toneMapped:!1})),this.light=t,this.color=i,this.type="PointLightHelper",this.matrix=this.light.matrixWorld,this.matrixAutoUpdate=!1,this.update()}dispose(){this.geometry.dispose(),this.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),void 0!==this.color?this.material.color.set(this.color):this.material.color.copy(this.light.color)}},Points:Ga,PointsMaterial:Fa,PolarGridHelper:class extends Ba{constructor(t=10,e=16,i=8,n=64,s=4473924,r=8947848){s=new En(s),r=new En(r);const a=[],o=[];if(e>1)for(let i=0;i<e;i++){const n=i/e*(2*Math.PI),l=Math.sin(n)*t,h=Math.cos(n)*t;a.push(0,0,0),a.push(l,0,h);const c=1&i?s:r;o.push(c.r,c.g,c.b),o.push(c.r,c.g,c.b)}for(let e=0;e<i;e++){const l=1&e?s:r,h=t-t/i*e;for(let t=0;t<n;t++){let e=t/n*(2*Math.PI),i=Math.sin(e)*h,s=Math.cos(e)*h;a.push(i,0,s),o.push(l.r,l.g,l.b),e=(t+1)/n*(2*Math.PI),i=Math.sin(e)*h,s=Math.cos(e)*h,a.push(i,0,s),o.push(l.r,l.g,l.b)}}const l=new Ds;l.setAttribute("position",new vs(a,3)),l.setAttribute("color",new vs(o,3));super(l,new Sa({vertexColors:!0,toneMapped:!1})),this.type="PolarGridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}},PolyhedronGeometry:eo,PositionalAudio:class extends dc{constructor(t){super(t),this.panner=this.context.createPanner(),this.panner.panningModel="HRTF",this.panner.connect(this.gain)}connect(){return super.connect(),this.panner.connect(this.gain),this}disconnect(){return super.disconnect(),this.panner.disconnect(this.gain),this}getOutput(){return this.panner}getRefDistance(){return this.panner.refDistance}setRefDistance(t){return this.panner.refDistance=t,this}getRolloffFactor(){return this.panner.rolloffFactor}setRolloffFactor(t){return this.panner.rolloffFactor=t,this}getDistanceModel(){return this.panner.distanceModel}setDistanceModel(t){return this.panner.distanceModel=t,this}getMaxDistance(){return this.panner.maxDistance}setMaxDistance(t){return this.panner.maxDistance=t,this}setDirectionalCone(t,e,i){return this.panner.coneInnerAngle=t,this.panner.coneOuterAngle=e,this.panner.coneOuterGain=i,this}updateMatrixWorld(t){if(super.updateMatrixWorld(t),!0===this.hasPlaybackControl&&!1===this.isPlaying)return;this.matrixWorld.decompose(uc,pc,mc),fc.set(0,0,1).applyQuaternion(pc);const e=this.panner;if(e.positionX){const t=this.context.currentTime+this.listener.timeDelta;e.positionX.linearRampToValueAtTime(uc.x,t),e.positionY.linearRampToValueAtTime(uc.y,t),e.positionZ.linearRampToValueAtTime(uc.z,t),e.orientationX.linearRampToValueAtTime(fc.x,t),e.orientationY.linearRampToValueAtTime(fc.y,t),e.orientationZ.linearRampToValueAtTime(fc.z,t)}else e.setPosition(uc.x,uc.y,uc.z),e.setOrientation(fc.x,fc.y,fc.z)}},PropertyBinding:Mc,PropertyMixer:gc,QuadraticBezierCurve:Ao,QuadraticBezierCurve3:Eo,Quaternion:_i,QuaternionKeyframeTrack:eh,QuaternionLinearInterpolant:th,R11_EAC_Format:Ht,RED_GREEN_RGTC2_Format:de,RED_RGTC1_Format:he,REVISION:e,RG11_EAC_Format:Wt,RGBADepthPacking:3201,RGBAFormat:Mt,RGBAIntegerFormat:Rt,RGBA_ASTC_10x10_Format:ne,RGBA_ASTC_10x5_Format:te,RGBA_ASTC_10x6_Format:ee,RGBA_ASTC_10x8_Format:ie,RGBA_ASTC_12x10_Format:se,RGBA_ASTC_12x12_Format:re,RGBA_ASTC_4x4_Format:Xt,RGBA_ASTC_5x4_Format:Yt,RGBA_ASTC_5x5_Format:Zt,RGBA_ASTC_6x5_Format:qt,RGBA_ASTC_6x6_Format:Qt,RGBA_ASTC_8x5_Format:Kt,RGBA_ASTC_8x6_Format:Jt,RGBA_ASTC_8x8_Format:$t,RGBA_BPTC_Format:ae,RGBA_ETC2_EAC_Format:Gt,RGBA_PVRTC_2BPPV1_Format:Ut,RGBA_PVRTC_4BPPV1_Format:Nt,RGBA_S3TC_DXT1_Format:It,RGBA_S3TC_DXT3_Format:Lt,RGBA_S3TC_DXT5_Format:Bt,RGBDepthPacking:3202,RGBFormat:St,RGBIntegerFormat:1032,RGB_BPTC_SIGNED_Format:oe,RGB_BPTC_UNSIGNED_Format:le,RGB_ETC1_Format:kt,RGB_ETC2_Format:zt,RGB_PVRTC_2BPPV1_Format:Ft,RGB_PVRTC_4BPPV1_Format:Ot,RGB_S3TC_DXT1_Format:Pt,RGDepthPacking:3203,RGFormat:Ct,RGIntegerFormat:Dt,RawShaderMaterial:Rl,Ray:or,Raycaster:Pc,RectAreaLight:zh,RedFormat:Et,RedIntegerFormat:Tt,ReinhardToneMapping:2,RenderTarget:zi,RenderTarget3D:class extends zi{constructor(t=1,e=1,i=1,n={}){super(t,e,n),this.isRenderTarget3D=!0,this.depth=i,this.texture=new Vi(null,t,e,i),this._setTextureOptions(n),this.texture.isRenderTargetTexture=!0}},RepeatWrapping:$,ReplaceStencilOp:Pe,ReverseSubtractEquation:102,RingGeometry:ml,SIGNED_R11_EAC_Format:Vt,SIGNED_RED_GREEN_RGTC2_Format:ue,SIGNED_RED_RGTC1_Format:ce,SIGNED_RG11_EAC_Format:jt,SRGBColorSpace:Ee,SRGBTransfer:De,Scene:Rn,ShaderChunk:gd,ShaderLib:yd,ShaderMaterial:Dl,ShadowMaterial:wl,Shape:Po,ShapeGeometry:fl,ShapePath:dd,ShapeUtils:rl,ShortType:ct,Skeleton:Fr,SkeletonHelper:class extends Ba{constructor(t){const e=Kc(t),i=new Ds,n=[],s=[];for(let t=0;t<e.length;t++){const i=e[t];i.parent&&i.parent.isBone&&(n.push(0,0,0),n.push(0,0,0),s.push(0,0,0),s.push(0,0,0))}i.setAttribute("position",new vs(n,3)),i.setAttribute("color",new vs(s,3));super(i,new Sa({vertexColors:!0,depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0})),this.isSkeletonHelper=!0,this.type="SkeletonHelper",this.root=t,this.bones=e,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1;const r=new En(255),a=new En(65280);this.setColors(r,a)}updateMatrixWorld(t){const e=this.bones,i=this.geometry,n=i.getAttribute("position");Qc.copy(this.root.matrixWorld).invert();for(let t=0,i=0;t<e.length;t++){const s=e[t];s.parent&&s.parent.isBone&&(qc.multiplyMatrices(Qc,s.matrixWorld),Zc.setFromMatrixPosition(qc),n.setXYZ(i,Zc.x,Zc.y,Zc.z),qc.multiplyMatrices(Qc,s.parent.matrixWorld),Zc.setFromMatrixPosition(qc),n.setXYZ(i+1,Zc.x,Zc.y,Zc.z),i+=2)}i.getAttribute("position").needsUpdate=!0,super.updateMatrixWorld(t)}setColors(t,e){const i=this.geometry.getAttribute("color");for(let n=0;n<i.count;n+=2)i.setXYZ(n,t.r,t.g,t.b),i.setXYZ(n+1,e.r,e.g,e.b);return i.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}},SkinnedMesh:Pr,Source:Bi,Sphere:bs,SphereGeometry:gl,Spherical:Fc,SphericalHarmonics3:Gh,SplineCurve:To,SpotLight:Lh,SpotLightHelper:class extends yn{constructor(t,e){super(),this.light=t,this.matrixAutoUpdate=!1,this.color=e,this.type="SpotLightHelper";const i=new Ds,n=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(let t=0,e=1,i=32;t<i;t++,e++){const s=t/i*Math.PI*2,r=e/i*Math.PI*2;n.push(Math.cos(s),Math.sin(s),1,Math.cos(r),Math.sin(r),1)}i.setAttribute("position",new vs(n,3));const s=new Sa({fog:!1,toneMapped:!1});this.cone=new Ba(i,s),this.add(this.cone),this.update()}dispose(){this.cone.geometry.dispose(),this.cone.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),this.light.target.updateWorldMatrix(!0,!1),this.parent?(this.parent.updateWorldMatrix(!0),this.matrix.copy(this.parent.matrixWorld).invert().multiply(this.light.matrixWorld)):this.matrix.copy(this.light.matrixWorld),this.matrixWorld.copy(this.light.matrixWorld);const t=this.light.distance?this.light.distance:1e3,e=t*Math.tan(this.light.angle);this.cone.scale.set(e,e,t),Yc.setFromMatrixPosition(this.light.target.matrixWorld),this.cone.lookAt(Yc),void 0!==this.color?this.cone.material.color.set(this.color):this.cone.material.color.copy(this.light.color)}},Sprite:qs,SpriteMaterial:Fs,SrcAlphaFactor:g,SrcAlphaSaturateFactor:210,SrcColorFactor:202,StaticCopyUsage:35046,StaticDrawUsage:Ve,StaticReadUsage:35045,StereoCamera:class{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Ph,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Ph,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(t){const e=this._cache;if(e.focus!==t.focus||e.fov!==t.fov||e.aspect!==t.aspect*this.aspect||e.near!==t.near||e.far!==t.far||e.zoom!==t.zoom||e.eyeSep!==this.eyeSep){e.focus=t.focus,e.fov=t.fov,e.aspect=t.aspect*this.aspect,e.near=t.near,e.far=t.far,e.zoom=t.zoom,e.eyeSep=this.eyeSep,ec.copy(t.projectionMatrix);const i=e.eyeSep/2,n=i*e.near/e.focus,s=e.near*Math.tan(hi*e.fov*.5)/e.zoom;let r,a;tc.elements[12]=-i,$h.elements[12]=i,r=-s*e.aspect+n,a=s*e.aspect+n,ec.elements[0]=2*e.near/(a-r),ec.elements[8]=(a+r)/(a-r),this.cameraL.projectionMatrix.copy(ec),r=-s*e.aspect-n,a=s*e.aspect-n,ec.elements[0]=2*e.near/(a-r),ec.elements[8]=(a+r)/(a-r),this.cameraR.projectionMatrix.copy(ec)}this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(tc),this.cameraR.matrixWorld.copy(t.matrixWorld).multiply($h)}},StreamCopyUsage:35042,StreamDrawUsage:35040,StreamReadUsage:35041,StringKeyframeTrack:ih,SubtractEquation:101,SubtractiveBlending:3,TOUCH:n,TangentSpaceNormalMap:0,TetrahedronGeometry:vl,Texture:Ui,TextureLoader:vh,TextureUtils:class{static contain(t,e){return function(t,e){const i=t.image&&t.image.width?t.image.width/t.image.height:1;return i>e?(t.repeat.x=1,t.repeat.y=i/e,t.offset.x=0,t.offset.y=(1-t.repeat.y)/2):(t.repeat.x=e/i,t.repeat.y=1,t.offset.x=(1-t.repeat.x)/2,t.offset.y=0),t}(t,e)}static cover(t,e){return function(t,e){const i=t.image&&t.image.width?t.image.width/t.image.height:1;return i>e?(t.repeat.x=e/i,t.repeat.y=1,t.offset.x=(1-t.repeat.x)/2,t.offset.y=0):(t.repeat.x=1,t.repeat.y=i/e,t.offset.x=0,t.offset.y=(1-t.repeat.y)/2),t}(t,e)}static fill(t){return function(t){return t.repeat.x=1,t.repeat.y=1,t.offset.x=0,t.offset.y=0,t}(t)}static getByteLength(t,e,i,n){return pd(t,e,i,n)}},Timer:Bc,TimestampQuery:{COMPUTE:"compute",RENDER:"render"},TorusGeometry:yl,TorusKnotGeometry:_l,Triangle:Wn,TriangleFanDrawMode:2,TriangleStripDrawMode:1,TrianglesDrawMode:0,TubeGeometry:xl,UVMapping:Y,Uint16BufferAttribute:fs,Uint32BufferAttribute:gs,Uint8BufferAttribute:class extends ms{constructor(t,e,i){super(new Uint8Array(t),e,i)}},Uint8ClampedBufferAttribute:class extends ms{constructor(t,e,i){super(new Uint8ClampedArray(t),e,i)}},Uniform:Tc,UniformsGroup:class extends ai{constructor(){super(),this.isUniformsGroup=!0,Object.defineProperty(this,"id",{value:Cc++}),this.name="",this.usage=Ve,this.uniforms=[]}add(t){return this.uniforms.push(t),this}remove(t){const e=this.uniforms.indexOf(t);return-1!==e&&this.uniforms.splice(e,1),this}setName(t){return this.name=t,this}setUsage(t){return this.usage=t,this}dispose(){this.dispatchEvent({type:"dispose"})}copy(t){this.name=t.name,this.usage=t.usage;const e=t.uniforms;this.uniforms.length=0;for(let t=0,i=e.length;t<i;t++){const i=Array.isArray(e[t])?e[t]:[e[t]];for(let t=0;t<i.length;t++)this.uniforms.push(i[t].clone())}return this}clone(){return(new this.constructor).copy(this)}},UniformsLib:vd,UniformsUtils:Cl,UnsignedByteType:lt,UnsignedInt101111Type:xt,UnsignedInt248Type:yt,UnsignedInt5999Type:_t,UnsignedIntType:pt,UnsignedShort4444Type:gt,UnsignedShort5551Type:vt,UnsignedShortType:dt,VSMShadowMap:3,Vector2:yi,Vector3:xi,Vector4:ki,VectorKeyframeTrack:nh,VideoFrameTexture:class extends Va{constructor(t,e,i,n,s,r,a,o){super({},t,e,i,n,s,r,a,o),this.isVideoFrameTexture=!0}update(){}clone(){return(new this.constructor).copy(this)}setFrame(t){this.image=t,this.needsUpdate=!0}},VideoTexture:Va,WebGL3DRenderTarget:class extends Gi{constructor(t=1,e=1,i=1,n={}){super(t,e,n),this.isWebGL3DRenderTarget=!0,this.depth=i,this.texture=new Vi(null,t,e,i),this._setTextureOptions(n),this.texture.isRenderTargetTexture=!0}},WebGLArrayRenderTarget:class extends Gi{constructor(t=1,e=1,i=1,n={}){super(t,e,n),this.isWebGLArrayRenderTarget=!0,this.depth=i,this.texture=new Hi(null,t,e,i),this._setTextureOptions(n),this.texture.isRenderTargetTexture=!0}},WebGLCoordinateSystem:je,WebGLCubeRenderTarget:Hd,WebGLRenderTarget:Gi,WebGLRenderer:am,WebGLUtils:Kp,WebGPUCoordinateSystem:Xe,WebXRController:bn,WireframeGeometry:bl,WrapAroundEnding:be,ZeroCurvatureEnding:_e,ZeroFactor:200,ZeroSlopeEnding:xe,ZeroStencilOp:0,createCanvasElement:Ke,error:ni,getConsoleFunction:function(){return $e},log:ti,setConsoleFunction:function(t){$e=t},warn:ii,warnOnce:si});const lm=new jn,hm=new xi;let cm=class extends jh{constructor(){super(),this.isLineSegmentsGeometry=!0,this.type="LineSegmentsGeometry";this.setIndex([0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5]),this.setAttribute("position",new vs([-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0],3)),this.setAttribute("uv",new vs([-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2],2))}applyMatrix4(t){const e=this.attributes.instanceStart,i=this.attributes.instanceEnd;return void 0!==e&&(e.applyMatrix4(t),i.applyMatrix4(t),e.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}setPositions(t){let e;t instanceof Float32Array?e=t:Array.isArray(t)&&(e=new Float32Array(t));const i=new Dc(e,6,1);return this.setAttribute("instanceStart",new Is(i,3,0)),this.setAttribute("instanceEnd",new Is(i,3,3)),this.instanceCount=this.attributes.instanceStart.count,this.computeBoundingBox(),this.computeBoundingSphere(),this}setColors(t){let e;t instanceof Float32Array?e=t:Array.isArray(t)&&(e=new Float32Array(t));const i=new Dc(e,6,1);return this.setAttribute("instanceColorStart",new Is(i,3,0)),this.setAttribute("instanceColorEnd",new Is(i,3,3)),this}fromWireframeGeometry(t){return this.setPositions(t.attributes.position.array),this}fromEdgesGeometry(t){return this.setPositions(t.attributes.position.array),this}fromMesh(t){return this.fromWireframeGeometry(new bl(t.geometry)),this}fromLineSegments(t){const e=t.geometry;return this.setPositions(e.attributes.position.array),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new jn);const t=this.attributes.instanceStart,e=this.attributes.instanceEnd;void 0!==t&&void 0!==e&&(this.boundingBox.setFromBufferAttribute(t),lm.setFromBufferAttribute(e),this.boundingBox.union(lm))}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new bs),null===this.boundingBox&&this.computeBoundingBox();const t=this.attributes.instanceStart,e=this.attributes.instanceEnd;if(void 0!==t&&void 0!==e){const i=this.boundingSphere.center;this.boundingBox.getCenter(i);let n=0;for(let s=0,r=t.count;s<r;s++)hm.fromBufferAttribute(t,s),n=Math.max(n,i.distanceToSquared(hm)),hm.fromBufferAttribute(e,s),n=Math.max(n,i.distanceToSquared(hm));this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&console.error("THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.",this)}}toJSON(){}};vd.line={worldUnits:{value:1},linewidth:{value:1},resolution:{value:new yi(1,1)},dashOffset:{value:0},dashScale:{value:1},dashSize:{value:1},gapSize:{value:1}},yd.line={uniforms:Cl.merge([vd.common,vd.fog,vd.line]),vertexShader:"\n\t\t#include <common>\n\t\t#include <color_pars_vertex>\n\t\t#include <fog_pars_vertex>\n\t\t#include <logdepthbuf_pars_vertex>\n\t\t#include <clipping_planes_pars_vertex>\n\n\t\tuniform float linewidth;\n\t\tuniform vec2 resolution;\n\n\t\tattribute vec3 instanceStart;\n\t\tattribute vec3 instanceEnd;\n\n\t\tattribute vec3 instanceColorStart;\n\t\tattribute vec3 instanceColorEnd;\n\n\t\t#ifdef WORLD_UNITS\n\n\t\t\tvarying vec4 worldPos;\n\t\t\tvarying vec3 worldStart;\n\t\t\tvarying vec3 worldEnd;\n\n\t\t\t#ifdef USE_DASH\n\n\t\t\t\tvarying vec2 vUv;\n\n\t\t\t#endif\n\n\t\t#else\n\n\t\t\tvarying vec2 vUv;\n\n\t\t#endif\n\n\t\t#ifdef USE_DASH\n\n\t\t\tuniform float dashScale;\n\t\t\tattribute float instanceDistanceStart;\n\t\t\tattribute float instanceDistanceEnd;\n\t\t\tvarying float vLineDistance;\n\n\t\t#endif\n\n\t\tvoid trimSegment( const in vec4 start, inout vec4 end ) {\n\n\t\t\t// trim end segment so it terminates between the camera plane and the near plane\n\n\t\t\t// conservative estimate of the near plane\n\t\t\tfloat a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column\n\t\t\tfloat b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column\n\t\t\tfloat nearEstimate = - 0.5 * b / a;\n\n\t\t\tfloat alpha = ( nearEstimate - start.z ) / ( end.z - start.z );\n\n\t\t\tend.xyz = mix( start.xyz, end.xyz, alpha );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\t#ifdef USE_COLOR\n\n\t\t\t\tvColor.xyz = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;\n\n\t\t\t#endif\n\n\t\t\t#ifdef USE_DASH\n\n\t\t\t\tvLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;\n\t\t\t\tvUv = uv;\n\n\t\t\t#endif\n\n\t\t\tfloat aspect = resolution.x / resolution.y;\n\n\t\t\t// camera space\n\t\t\tvec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );\n\t\t\tvec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );\n\n\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\tworldStart = start.xyz;\n\t\t\t\tworldEnd = end.xyz;\n\n\t\t\t#else\n\n\t\t\t\tvUv = uv;\n\n\t\t\t#endif\n\n\t\t\t// special case for perspective projection, and segments that terminate either in, or behind, the camera plane\n\t\t\t// clearly the gpu firmware has a way of addressing this issue when projecting into ndc space\n\t\t\t// but we need to perform ndc-space calculations in the shader, so we must address this issue directly\n\t\t\t// perhaps there is a more elegant solution -- WestLangley\n\n\t\t\tbool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column\n\n\t\t\tif ( perspective ) {\n\n\t\t\t\tif ( start.z < 0.0 && end.z >= 0.0 ) {\n\n\t\t\t\t\ttrimSegment( start, end );\n\n\t\t\t\t} else if ( end.z < 0.0 && start.z >= 0.0 ) {\n\n\t\t\t\t\ttrimSegment( end, start );\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\t// clip space\n\t\t\tvec4 clipStart = projectionMatrix * start;\n\t\t\tvec4 clipEnd = projectionMatrix * end;\n\n\t\t\t// ndc space\n\t\t\tvec3 ndcStart = clipStart.xyz / clipStart.w;\n\t\t\tvec3 ndcEnd = clipEnd.xyz / clipEnd.w;\n\n\t\t\t// direction\n\t\t\tvec2 dir = ndcEnd.xy - ndcStart.xy;\n\n\t\t\t// account for clip-space aspect ratio\n\t\t\tdir.x *= aspect;\n\t\t\tdir = normalize( dir );\n\n\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\tvec3 worldDir = normalize( end.xyz - start.xyz );\n\t\t\t\tvec3 tmpFwd = normalize( mix( start.xyz, end.xyz, 0.5 ) );\n\t\t\t\tvec3 worldUp = normalize( cross( worldDir, tmpFwd ) );\n\t\t\t\tvec3 worldFwd = cross( worldDir, worldUp );\n\t\t\t\tworldPos = position.y < 0.5 ? start: end;\n\n\t\t\t\t// height offset\n\t\t\t\tfloat hw = linewidth * 0.5;\n\t\t\t\tworldPos.xyz += position.x < 0.0 ? hw * worldUp : - hw * worldUp;\n\n\t\t\t\t// don't extend the line if we're rendering dashes because we\n\t\t\t\t// won't be rendering the endcaps\n\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t// cap extension\n\t\t\t\t\tworldPos.xyz += position.y < 0.5 ? - hw * worldDir : hw * worldDir;\n\n\t\t\t\t\t// add width to the box\n\t\t\t\t\tworldPos.xyz += worldFwd * hw;\n\n\t\t\t\t\t// endcaps\n\t\t\t\t\tif ( position.y > 1.0 || position.y < 0.0 ) {\n\n\t\t\t\t\t\tworldPos.xyz -= worldFwd * 2.0 * hw;\n\n\t\t\t\t\t}\n\n\t\t\t\t#endif\n\n\t\t\t\t// project the worldpos\n\t\t\t\tvec4 clip = projectionMatrix * worldPos;\n\n\t\t\t\t// shift the depth of the projected points so the line\n\t\t\t\t// segments overlap neatly\n\t\t\t\tvec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;\n\t\t\t\tclip.z = clipPose.z * clip.w;\n\n\t\t\t#else\n\n\t\t\t\tvec2 offset = vec2( dir.y, - dir.x );\n\t\t\t\t// undo aspect ratio adjustment\n\t\t\t\tdir.x /= aspect;\n\t\t\t\toffset.x /= aspect;\n\n\t\t\t\t// sign flip\n\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t// endcaps\n\t\t\t\tif ( position.y < 0.0 ) {\n\n\t\t\t\t\toffset += - dir;\n\n\t\t\t\t} else if ( position.y > 1.0 ) {\n\n\t\t\t\t\toffset += dir;\n\n\t\t\t\t}\n\n\t\t\t\t// adjust for linewidth\n\t\t\t\toffset *= linewidth;\n\n\t\t\t\t// adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...\n\t\t\t\toffset /= resolution.y;\n\n\t\t\t\t// select end\n\t\t\t\tvec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;\n\n\t\t\t\t// back to clip space\n\t\t\t\toffset *= clip.w;\n\n\t\t\t\tclip.xy += offset;\n\n\t\t\t#endif\n\n\t\t\tgl_Position = clip;\n\n\t\t\tvec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation\n\n\t\t\t#include <logdepthbuf_vertex>\n\t\t\t#include <clipping_planes_vertex>\n\t\t\t#include <fog_vertex>\n\n\t\t}\n\t\t",fragmentShader:"\n\t\tuniform vec3 diffuse;\n\t\tuniform float opacity;\n\t\tuniform float linewidth;\n\n\t\t#ifdef USE_DASH\n\n\t\t\tuniform float dashOffset;\n\t\t\tuniform float dashSize;\n\t\t\tuniform float gapSize;\n\n\t\t#endif\n\n\t\tvarying float vLineDistance;\n\n\t\t#ifdef WORLD_UNITS\n\n\t\t\tvarying vec4 worldPos;\n\t\t\tvarying vec3 worldStart;\n\t\t\tvarying vec3 worldEnd;\n\n\t\t\t#ifdef USE_DASH\n\n\t\t\t\tvarying vec2 vUv;\n\n\t\t\t#endif\n\n\t\t#else\n\n\t\t\tvarying vec2 vUv;\n\n\t\t#endif\n\n\t\t#include <common>\n\t\t#include <color_pars_fragment>\n\t\t#include <fog_pars_fragment>\n\t\t#include <logdepthbuf_pars_fragment>\n\t\t#include <clipping_planes_pars_fragment>\n\n\t\tvec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {\n\n\t\t\tfloat mua;\n\t\t\tfloat mub;\n\n\t\t\tvec3 p13 = p1 - p3;\n\t\t\tvec3 p43 = p4 - p3;\n\n\t\t\tvec3 p21 = p2 - p1;\n\n\t\t\tfloat d1343 = dot( p13, p43 );\n\t\t\tfloat d4321 = dot( p43, p21 );\n\t\t\tfloat d1321 = dot( p13, p21 );\n\t\t\tfloat d4343 = dot( p43, p43 );\n\t\t\tfloat d2121 = dot( p21, p21 );\n\n\t\t\tfloat denom = d2121 * d4343 - d4321 * d4321;\n\n\t\t\tfloat numer = d1343 * d4321 - d1321 * d4343;\n\n\t\t\tmua = numer / denom;\n\t\t\tmua = clamp( mua, 0.0, 1.0 );\n\t\t\tmub = ( d1343 + d4321 * ( mua ) ) / d4343;\n\t\t\tmub = clamp( mub, 0.0, 1.0 );\n\n\t\t\treturn vec2( mua, mub );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tfloat alpha = opacity;\n\t\t\tvec4 diffuseColor = vec4( diffuse, alpha );\n\n\t\t\t#include <clipping_planes_fragment>\n\n\t\t\t#ifdef USE_DASH\n\n\t\t\t\tif ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps\n\n\t\t\t\tif ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX\n\n\t\t\t#endif\n\n\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t// Find the closest points on the view ray and the line segment\n\t\t\t\tvec3 rayEnd = normalize( worldPos.xyz ) * 1e5;\n\t\t\t\tvec3 lineDir = worldEnd - worldStart;\n\t\t\t\tvec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );\n\n\t\t\t\tvec3 p1 = worldStart + lineDir * params.x;\n\t\t\t\tvec3 p2 = rayEnd * params.y;\n\t\t\t\tvec3 delta = p1 - p2;\n\t\t\t\tfloat len = length( delta );\n\t\t\t\tfloat norm = len / linewidth;\n\n\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\tfloat dnorm = fwidth( norm );\n\t\t\t\t\t\talpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tif ( norm > 0.5 ) {\n\n\t\t\t\t\t\t\tdiscard;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#endif\n\n\t\t\t#else\n\n\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t// artifacts appear on some hardware if a derivative is taken within a conditional\n\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\tfloat len2 = a * a + b * b;\n\t\t\t\t\tfloat dlen = fwidth( len2 );\n\n\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\talpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );\n\n\t\t\t\t\t}\n\n\t\t\t\t#else\n\n\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\n\t\t\t\t\t\tif ( len2 > 1.0 ) discard;\n\n\t\t\t\t\t}\n\n\t\t\t\t#endif\n\n\t\t\t#endif\n\n\t\t\t#include <logdepthbuf_fragment>\n\t\t\t#include <color_fragment>\n\n\t\t\tgl_FragColor = vec4( diffuseColor.rgb, alpha );\n\n\t\t\t#include <tonemapping_fragment>\n\t\t\t#include <colorspace_fragment>\n\t\t\t#include <fog_fragment>\n\t\t\t#include <premultiplied_alpha_fragment>\n\n\t\t}\n\t\t"};class dm extends Dl{constructor(t){super({type:"LineMaterial",uniforms:Cl.clone(yd.line.uniforms),vertexShader:yd.line.vertexShader,fragmentShader:yd.line.fragmentShader,clipping:!0}),this.isLineMaterial=!0,this.setValues(t)}get color(){return this.uniforms.diffuse.value}set color(t){this.uniforms.diffuse.value=t}get worldUnits(){return"WORLD_UNITS"in this.defines}set worldUnits(t){!0===t!==this.worldUnits&&(this.needsUpdate=!0),!0===t?this.defines.WORLD_UNITS="":delete this.defines.WORLD_UNITS}get linewidth(){return this.uniforms.linewidth.value}set linewidth(t){this.uniforms.linewidth&&(this.uniforms.linewidth.value=t)}get dashed(){return"USE_DASH"in this.defines}set dashed(t){!0===t!==this.dashed&&(this.needsUpdate=!0),!0===t?this.defines.USE_DASH="":delete this.defines.USE_DASH}get dashScale(){return this.uniforms.dashScale.value}set dashScale(t){this.uniforms.dashScale.value=t}get dashSize(){return this.uniforms.dashSize.value}set dashSize(t){this.uniforms.dashSize.value=t}get dashOffset(){return this.uniforms.dashOffset.value}set dashOffset(t){this.uniforms.dashOffset.value=t}get gapSize(){return this.uniforms.gapSize.value}set gapSize(t){this.uniforms.gapSize.value=t}get opacity(){return this.uniforms.opacity.value}set opacity(t){this.uniforms&&(this.uniforms.opacity.value=t)}get resolution(){return this.uniforms.resolution.value}set resolution(t){this.uniforms.resolution.value.copy(t)}get alphaToCoverage(){return"USE_ALPHA_TO_COVERAGE"in this.defines}set alphaToCoverage(t){this.defines&&(!0===t!==this.alphaToCoverage&&(this.needsUpdate=!0),!0===t?this.defines.USE_ALPHA_TO_COVERAGE="":delete this.defines.USE_ALPHA_TO_COVERAGE)}}const um=new ki,pm=new xi,mm=new xi,fm=new ki,gm=new ki,vm=new ki,ym=new xi,_m=new Wi,xm=new Xc,bm=new xi,Sm=new jn,Mm=new bs,wm=new ki;let Am,Em;function Tm(t,e,i){return wm.set(0,0,-e,1).applyMatrix4(t.projectionMatrix),wm.multiplyScalar(1/wm.w),wm.x=Em/i.width,wm.y=Em/i.height,wm.applyMatrix4(t.projectionMatrixInverse),wm.multiplyScalar(1/wm.w),Math.abs(Math.max(wm.x,wm.y))}class Cm extends xr{constructor(t=new cm,e=new dm({color:16777215*Math.random()})){super(t,e),this.isLineSegments2=!0,this.type="LineSegments2"}computeLineDistances(){const t=this.geometry,e=t.attributes.instanceStart,i=t.attributes.instanceEnd,n=new Float32Array(2*e.count);for(let t=0,s=0,r=e.count;t<r;t++,s+=2)pm.fromBufferAttribute(e,t),mm.fromBufferAttribute(i,t),n[s]=0===s?0:n[s-1],n[s+1]=n[s]+pm.distanceTo(mm);const s=new Dc(n,2,1);return t.setAttribute("instanceDistanceStart",new Is(s,1,0)),t.setAttribute("instanceDistanceEnd",new Is(s,1,1)),this}raycast(t,e){const i=this.material.worldUnits,n=t.camera;null!==n||i||console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');const s=void 0!==t.params.Line2&&t.params.Line2.threshold||0;Am=t.ray;const r=this.matrixWorld,a=this.geometry,o=this.material;let l,h;if(Em=o.linewidth+s,null===a.boundingSphere&&a.computeBoundingSphere(),Mm.copy(a.boundingSphere).applyMatrix4(r),i)l=.5*Em;else{l=Tm(n,Math.max(n.near,Mm.distanceToPoint(Am.origin)),o.resolution)}if(Mm.radius+=l,!1!==Am.intersectsSphere(Mm)){if(null===a.boundingBox&&a.computeBoundingBox(),Sm.copy(a.boundingBox).applyMatrix4(r),i)h=.5*Em;else{h=Tm(n,Math.max(n.near,Sm.distanceToPoint(Am.origin)),o.resolution)}Sm.expandByScalar(h),!1!==Am.intersectsBox(Sm)&&(i?function(t,e){const i=t.matrixWorld,n=t.geometry,s=n.attributes.instanceStart,r=n.attributes.instanceEnd;for(let a=0,o=Math.min(n.instanceCount,s.count);a<o;a++){xm.start.fromBufferAttribute(s,a),xm.end.fromBufferAttribute(r,a),xm.applyMatrix4(i);const n=new xi,o=new xi;Am.distanceSqToSegment(xm.start,xm.end,o,n),o.distanceTo(n)<.5*Em&&e.push({point:o,pointOnLine:n,distance:Am.origin.distanceTo(o),object:t,face:null,faceIndex:a,uv:null,uv1:null})}}(this,e):function(t,e,i){const n=e.projectionMatrix,s=t.material.resolution,r=t.matrixWorld,a=t.geometry,o=a.attributes.instanceStart,l=a.attributes.instanceEnd,h=Math.min(a.instanceCount,o.count),c=-e.near;Am.at(1,vm),vm.w=1,vm.applyMatrix4(e.matrixWorldInverse),vm.applyMatrix4(n),vm.multiplyScalar(1/vm.w),vm.x*=s.x/2,vm.y*=s.y/2,vm.z=0,ym.copy(vm),_m.multiplyMatrices(e.matrixWorldInverse,r);for(let e=0,a=h;e<a;e++){if(fm.fromBufferAttribute(o,e),gm.fromBufferAttribute(l,e),fm.w=1,gm.w=1,fm.applyMatrix4(_m),gm.applyMatrix4(_m),fm.z>c&&gm.z>c)continue;if(fm.z>c){const t=fm.z-gm.z,e=(fm.z-c)/t;fm.lerp(gm,e)}else if(gm.z>c){const t=gm.z-fm.z,e=(gm.z-c)/t;gm.lerp(fm,e)}fm.applyMatrix4(n),gm.applyMatrix4(n),fm.multiplyScalar(1/fm.w),gm.multiplyScalar(1/gm.w),fm.x*=s.x/2,fm.y*=s.y/2,gm.x*=s.x/2,gm.y*=s.y/2,xm.start.copy(fm),xm.start.z=0,xm.end.copy(gm),xm.end.z=0;const a=xm.closestPointToPointParameter(ym,!0);xm.at(a,bm);const h=vi.lerp(fm.z,gm.z,a),d=h>=-1&&h<=1,u=ym.distanceTo(bm)<.5*Em;if(d&&u){xm.start.fromBufferAttribute(o,e),xm.end.fromBufferAttribute(l,e),xm.start.applyMatrix4(r),xm.end.applyMatrix4(r);const n=new xi,s=new xi;Am.distanceSqToSegment(xm.start,xm.end,s,n),i.push({point:s,pointOnLine:n,distance:Am.origin.distanceTo(s),object:t,face:null,faceIndex:e,uv:null,uv1:null})}}}(this,n,e))}}onBeforeRender(t){const e=this.material.uniforms;e&&e.resolution&&(t.getViewport(um),this.material.uniforms.resolution.value.set(um.z,um.w))}}class Dm extends cm{toJSON(){return jh.prototype.toJSON.call(this)}}const Rm=new xi,Pm=new xi,Im=new Mi;class Lm extends Ba{constructor(t,e=1,i=16711680){const n=new Ds,s=t.geometry.attributes.normal.count,r=new vs(2*s*3,3);n.setAttribute("position",r),super(n,new Sa({color:i,toneMapped:!1})),this.object=t,this.size=e,this.type="VertexNormalsHelper",this.matrixAutoUpdate=!1,this.isVertexNormalsHelper=!0,this.update()}update(){this.object.updateMatrixWorld(!0),Im.getNormalMatrix(this.object.matrixWorld);const t=this.object.matrixWorld,e=this.geometry.attributes.position,i=this.object.geometry;if(i){const n=i.attributes.position,s=i.attributes.normal;let r=0;for(let i=0,a=n.count;i<a;i++)Rm.fromBufferAttribute(n,i).applyMatrix4(t),Pm.fromBufferAttribute(s,i),Pm.applyMatrix3(Im).normalize().multiplyScalar(this.size).add(Rm),e.setXYZ(r,Rm.x,Rm.y,Rm.z),r+=1,e.setXYZ(r,Pm.x,Pm.y,Pm.z),r+=1}e.needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}}const Bm={debug:0,info:1,warn:2,error:3,silent:4};let Om="warn";const Fm={setLevel(t){Om=t},getLevel:()=>Om,debug(...t){Bm[Om]<=Bm.debug&&console.log("[three-cad-viewer]",...t)},info(...t){Bm[Om]<=Bm.info&&console.log("[three-cad-viewer]",...t)},warn(...t){Bm[Om]<=Bm.warn&&console.warn("[three-cad-viewer]",...t)},error(...t){Bm[Om]<=Bm.error&&console.error("[three-cad-viewer]",...t)}},Nm={geometry:0,material:0,texture:0};let Um=!1;const km=new Map,zm={enableDebug(){Um=!0,Fm.info("GPU tracker debug mode enabled")},disableDebug(){Um=!1,km.clear(),Fm.info("GPU tracker debug mode disabled")},get isDebugEnabled(){return Um},track(t,e,i){if(Nm[t]++,Um){const n=(new Error).stack?.split("\n").slice(2,6).join("\n")??"";km.set(e,{type:t,label:i??"unlabeled",stack:n,timestamp:performance.now()})}},untrack(t,e){if(Um&&e){const t=km.get(e);if(t)return Nm[t.type]--,void km.delete(e)}Nm[t]>0&&Nm[t]--},get summary(){return{geometry:Nm.geometry,material:Nm.material,texture:Nm.texture,total:Nm.geometry+Nm.material+Nm.texture}},getResources:()=>Um?Array.from(km.values()):(Fm.warn("GPU tracker: getResources() requires debug mode - call enableDebug() first"),[]),getResourcesByType(){const t=this.getResources();return{geometry:t.filter(t=>"geometry"===t.type),material:t.filter(t=>"material"===t.type),texture:t.filter(t=>"texture"===t.type)}},details(){const{total:t,geometry:e,material:i,texture:n}=this.summary;if(0!==t)if(console.log(`GPU tracker: ${t} resources allocated:`),console.log(` - Geometries: ${e}`),console.log(` - Materials: ${i}`),console.log(` - Textures: ${n}`),Um){const t=this.getResources();console.log("\nResource details:"),t.forEach((t,e)=>{console.log(`\n[${e+1}] ${t.type}: ${t.label}`),console.log(` Created at: ${t.timestamp.toFixed(2)}ms`),console.log(` Stack:\n${t.stack}`)})}else console.log("\nFor detailed resource info, enable debug mode before creating resources:"),console.log(" gpuTracker.enableDebug()");else console.log("GPU tracker: No resources currently allocated")},reset(){Nm.geometry=0,Nm.material=0,Nm.texture=0,km.clear()},assertEmpty(){const{total:t}=this.summary;if(0!==t)throw this.details(),new Error(`GPU tracker: ${t} resources not disposed`)},trackGeometry(t,e){return this.track("geometry",t,e),t},trackMaterial(t,e){return this.track("material",t,e),t},trackTexture(t,e){return this.track("texture",t,e),t}};"undefined"!=typeof window&&(window.tcv_gpu=zm);const Gm={x:new xi(1,0,0),y:new xi(0,1,0),z:new xi(0,0,1)};function Hm(t,e=1){return t.flat(e)}function Vm(t){if(!Array.isArray(t)||3!==t.length)throw new Error(`Expected array of length 3, got ${Array.isArray(t)?t.length:typeof t}`);return t}function Wm(t){if(!Array.isArray(t)||4!==t.length)throw new Error(`Expected array of length 4, got ${Array.isArray(t)?t.length:typeof t}`);return t}function jm(t,e,i=1e-9){if(Array.isArray(t)&&Array.isArray(e))return t.length===e.length&&t.every((t,n)=>jm(t,e[n],i));if(null!==t&&null!==e&&"object"==typeof t&&"object"==typeof e){const n=t,s=e,r=Object.keys(n),a=Object.keys(s);return!(r.length!==a.length||!r.every(t=>Object.prototype.hasOwnProperty.call(s,t)))&&r.every(t=>jm(n[t],s[t],i))}return"number"==typeof t&&"number"==typeof e?Math.abs(t-e)<i:t===e}function Xm(t,e){t&&(e(t),t.children&&t.children.length>0&&t.children.forEach(t=>{Xm(t,e)}))}function Ym(t){if(t){zm.untrack("geometry",t),t.dispose();for(const e of Object.values(t.attributes))e&&"object"==typeof e&&"dispose"in e&&"function"==typeof e.dispose&&e.dispose()}}const Zm=["map","normalMap","roughnessMap","metalnessMap","aoMap","emissiveMap","alphaMap","bumpMap","transmissionMap","clearcoatMap","clearcoatRoughnessMap","clearcoatNormalMap","thicknessMap","specularIntensityMap","specularColorMap","sheenColorMap","sheenRoughnessMap","anisotropyMap"];function qm(t){if(t){for(const e of Zm)t[e]&&(t[e]=null);zm.untrack("material",t),t.dispose()}}function Qm(t){var e;t&&(Array.isArray(t)?t.forEach(Qm):(Array.isArray(t.children)&&t.children.forEach(Qm),t.dispose?t.dispose():(t.isMesh||t.isLine||t.isPoints)&&((e=t).geometry&&Ym(e.geometry),e.material&&(Array.isArray(e.material)?e.material.forEach(qm):qm(e.material)))))}function Km(t){return Math.round(Math.PI*t)}function Jm(t){return"isMesh"in t&&!0===t.isMesh}function $m(t){return"isLine"in t&&!0===t.isLine}function tf(t){return"isPoints"in t&&!0===t.isPoints}function ef(t){return"isOrthographicCamera"in t&&!0===t.isOrthographicCamera}function nf(t){return"isPerspectiveCamera"in t&&!0===t.isPerspectiveCamera}function sf(t){return"LineSegments2"===t.type}const rf=new class{constructor(){this.getshortcuts=t=>this.keyMapping[t].replace("Key",""),this.get=(t,e)=>t[this.keyMapping[e]],this.set=t=>{for(const e of Object.keys(t)){const i=t[e];void 0!==i&&(this.keyMapping[e]=i)}},this.setActionShortcuts=t=>{this.actionShortcuts={...t},this.reverseActionShortcuts={};for(const[e,i]of Object.entries(t))this.reverseActionShortcuts[i]=e},this.getActionForKey=t=>this.reverseActionShortcuts[t],this.getShortcutForAction=t=>this.actionShortcuts[t],this.getActionShortcuts=()=>({...this.actionShortcuts}),this.keyMapping={shift:"ctrlKey",ctrl:"shiftKey",meta:"altKey",alt:"metaKey"},this.actionShortcuts={},this.reverseActionShortcuts={}}get_config(){return Object.assign({},this.keyMapping)}};class af{constructor(){this.originalMaterials=new Map,this.zebraMaterials=new Map,this.settings={stripeCount:15,stripeDirection:0,colorScheme:"blackwhite",opacity:1,mappingMode:"normal"},this.zebraTexture=null,this.createZebraTexture()}createZebraTexture(){const t=document.createElement("canvas");t.width=1,t.height=4096;const e=t.getContext("2d"),i=this.settings.stripeCount%2==1,n=i?this.settings.stripeCount-1:this.settings.stripeCount,s=t.height/n;let r=0;for(let n=0;n<this.settings.stripeCount;n++){let a,o;switch(this.settings.colorScheme){case"blackwhite":a="#000000",o="#ffffff";break;case"colorful":{let t;if(i&&n===this.settings.stripeCount-1)t=0;else{t=n/(i?this.settings.stripeCount-1:this.settings.stripeCount)*360}a=`hsl(${t}, 100%, 50%)`,o=`hsl(${(t+180)%360}, 100%, 50%)`;break}case"grayscale":a="#D2D2D2",o="#464646"}const l=!i||0!==n&&n!==this.settings.stripeCount-1?s:.5*s;e.fillStyle=n%2==0?a:o,e.fillRect(0,r,t.width,l),r+=l}this.zebraTexture&&this.zebraTexture.dispose(),this.zebraTexture=new Xa(t),this.zebraTexture.wrapS=$,this.zebraTexture.wrapT=$,this.zebraTexture.needsUpdate=!0,this.zebraMaterials.forEach(t=>{t.uniforms.zebraTexture.value=this.zebraTexture,t.uniforms.zebraTexture.value.needsUpdate=!0,t.uniformsNeedUpdate=!0,t.needsUpdate=!0})}createZebraMaterial(){const t=this.settings.stripeDirection*Math.PI/180,e=new xi(Math.cos(t),Math.sin(t),0).normalize();return new Dl({uniforms:{zebraTexture:{value:this.zebraTexture},direction:{value:e},opacity:{value:this.settings.opacity},baseColor:{value:new En(.7,.7,.7)},mappingMode:{value:"reflection"===this.settings.mappingMode?0:1}},vertexShader:"\n varying vec3 vViewNormal;\n varying vec3 vViewPosition;\n varying vec4 vScreenPosition;\n\n void main() {\n // Transform normal to view space\n vViewNormal = normalize(normalMatrix * normal);\n\n // Transform position to view space\n vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);\n vViewPosition = mvPosition.xyz;\n\n gl_Position = projectionMatrix * mvPosition;\n\n // Store screen position for normal mode\n vScreenPosition = gl_Position;\n }\n ",fragmentShader:"\n uniform sampler2D zebraTexture;\n uniform vec3 direction;\n uniform float opacity;\n uniform vec3 baseColor;\n uniform int mappingMode; // 0 = reflection, 1 = normal\n\n varying vec3 vViewNormal;\n varying vec3 vViewPosition;\n varying vec4 vScreenPosition;\n\n void main() {\n // Normalize view-space normal\n vec3 normal = normalize(vViewNormal);\n\n float v;\n\n if (mappingMode == 0) {\n // Reflection mode (Onshape-like): circular/elliptical stripes\n // View direction in view space (points toward camera)\n vec3 viewDir = normalize(-vViewPosition);\n\n // Calculate reflection in view space\n vec3 mappingVector = reflect(-viewDir, normal);\n\n // Use the reflection vector with screen-space direction\n v = dot(mappingVector, direction) * 3.0 * 0.5 + 0.5;\n } else {\n // Normal mode (Fusion360/Shapr3D-like): zoom-independent view-based stripes\n // Use view direction normalized by distance (zoom-independent)\n\n // Normalize view position by distance to make it zoom-independent\n float dist = length(vViewPosition);\n vec2 viewDir2D = vViewPosition.xy / dist;\n\n // Rotate by stripe direction\n float cosA = direction.x / length(direction.xy);\n float sinA = direction.y / length(direction.xy);\n float rotatedPos = viewDir2D.x * cosA + viewDir2D.y * sinA;\n\n // Scale for stripe frequency (zoom-independent)\n float positionValue = rotatedPos * 2.0;\n\n // Add normal influence to follow curvature\n float normalValue = dot(normal, direction) * 0.5;\n\n // Combine: position creates base stripes, normal makes them follow curvature\n v = (positionValue + normalValue) * 3.0 * 0.5 + 0.5;\n }\n\n // Sample the zebra texture (texture varies in V/Y direction)\n vec4 zebraColor = texture2D(zebraTexture, vec2(0.5, v));\n\n // Blend zebra stripes with original material color based on opacity\n vec3 finalColor = mix(baseColor, zebraColor.rgb, opacity);\n\n gl_FragColor = vec4(finalColor, 1.0);\n }\n ",side:2})}applyToMesh(t,e){if(!t.isMesh)return;if(t.userData.excludeFromZebra)return;const i=Array.isArray(t.material)?t.material[0]:t.material;if(this.originalMaterials.has(t.uuid)||this.originalMaterials.set(t.uuid,i),!this.zebraMaterials.has(t.uuid)){const e=this.createZebraMaterial();let n=new En(.7,.7,.7);"color"in i?n=i.color.clone():function(t){return"isMeshStandardMaterial"in t&&!0===t.isMeshStandardMaterial}(i)&&i.map&&(n=new En(1,1,1)),e.uniforms.baseColor={value:n},this.zebraMaterials.set(t.uuid,e)}t.material=this.zebraMaterials.get(t.uuid),t.material.visible=e}restoreMesh(t,e){if(!t.isMesh)return;const i=this.originalMaterials.get(t.uuid);i&&(t.material=i,i.visible=e)}setStripeCount(t){this.settings.stripeCount=Math.max(2,Math.min(50,t)),this.createZebraTexture()}setStripeDirection(t){this.settings.stripeDirection=t;const e=t*Math.PI/180,i=new xi(Math.cos(e),Math.sin(e),0).normalize();this.zebraMaterials.forEach(t=>{t.uniforms.direction.value=i})}setColorScheme(t){["blackwhite","colorful","grayscale"].includes(t)&&(this.settings.colorScheme=t,this.createZebraTexture())}setStripeOpacity(t){this.settings.opacity=Math.max(0,Math.min(1,t)),this.zebraMaterials.forEach(t=>{t.uniforms.opacity.value=this.settings.opacity})}setMappingMode(t){if(["reflection","normal"].includes(t)){this.settings.mappingMode=t;const e="reflection"===t?0:1;this.zebraMaterials.forEach(t=>{t.uniforms.mappingMode.value=e,t.uniformsNeedUpdate=!0,t.needsUpdate=!0})}}update(){}dispose(){this.zebraTexture&&this.zebraTexture.dispose(),this.zebraMaterials.forEach(t=>{t.dispose()}),this.originalMaterials.clear(),this.zebraMaterials.clear()}}class of extends _n{constructor(t,e,i,n,s,r=!1){super(),this.type="ObjectGroup",this.isObjectGroup=!0,this.opacity=t,this.alpha=null==e?1:e,this.transparent=!1,this.edge_color=i,this.shapeInfo=n,this.subtype=s,this.renderback=r,this.front=null,this.back=null,this.edges=null,this.edgeMaterial=null,this.vertices=null,this.clipping=new Map,this.isSelected=!1,this.originalColor=null,this.originalBackColor=null,this.originalWidth=null,this.vertexFocusSize=8,this.edgeFocusWidth=5,this._zebra=null,this.materialTag="",this._cadFrontMaterial=null,this._cadBackMaterial=null,this._cadOriginalColor=null,this._cadOriginalBackColor=null,this._isStudioMode=!1,this._cadEdgesVisible=null}get zebra(){return this._zebra||(this._zebra=new af),this._zebra}get isStudioMode(){return this._isStudioMode}dispose(){this.shapeGeometry&&(Ym(this.shapeGeometry),this.shapeGeometry=null),this.children&&(Qm(this.children),this.clear()),this._zebra&&(this._zebra.dispose(),this._zebra=null),this._cadFrontMaterial=null,this._cadBackMaterial=null,this._cadOriginalColor=null,this._cadOriginalBackColor=null,this._isStudioMode=!1,this._cadEdgesVisible=null}setFront(t){this.add(t),this.front=t,this.originalColor=t.material.color.clone()}setBack(t){this.add(t),this.back=t,this.front||(this.originalBackColor=t.material.color.clone())}setEdges(t){this.add(t),this.edges=t;const e=t.material;if(Array.isArray(e))throw new Error("Multi-material edges are not supported");if(!function(t){return"color"in t&&"linewidth"in t}(e))throw new Error("Edge material must have color and linewidth properties");this.edgeMaterial=e,this.front||(this.originalColor=this.edgeMaterial.color.clone(),this.originalWidth=this.edgeMaterial.linewidth)}setVertices(t){this.add(t),this.vertices=t,this.originalColor=t.material.color.clone(),this.originalWidth=t.material.size}addClipping(t,e){this.add(t),this.clipping.set(e,t)}widen(t){this.vertices?this.vertices.material.size=t?this.vertexFocusSize:this.isSelected?this.vertexFocusSize-2:this.originalWidth:this.edgeMaterial&&(this.edgeMaterial.linewidth=t?this.edgeFocusWidth:this.isSelected?this.edgeFocusWidth-2:this.originalWidth)}toggleSelection(){const t=!this.isSelected;this.isSelected=t,this.highlight(t),this.widen(!1)}unhighlight(t){t&&this.isSelected||(this.isSelected=!1,this.highlight(!1)),this.widen(!1)}_getHighlightColor(){return new En(this.isSelected?5480675:9026019)}_applyColorToMaterial(t,e){t.color=e,t.needsUpdate=!0}_forEachMaterial(t){for(const e of this.children)if(!e.name.startsWith("clipping")&&Jm(e)){if(Array.isArray(e.material))throw new Error("Multi-material meshes are not supported");t(e.material)}}_forEachStandardMaterial(t){this.front&&this.front.material instanceof Pl&&t(this.front.material),this.back&&this.back.material instanceof Pl&&t(this.back.material)}highlight(t){const e=this._getHighlightColor(),i=this.front?.material||this.vertices?.material||this.edgeMaterial;i&&(this.widen(t),this._applyColorToMaterial(i,t?e:this.originalColor)),this.back&&this._applyColorToMaterial(this.back.material,t?e:this.originalBackColor)}clearHighlights(){this.highlight(!1),this.isSelected=!1,this.widen(!1)}metrics(){return this.front?{name:"face",value:0}:this.vertices?{name:"vertex",value:0}:this.edges?{name:"edge",value:0}:null}setMetalness(t){this._forEachStandardMaterial(e=>{e.metalness=t,e.needsUpdate=!0})}setRoughness(t){this._forEachStandardMaterial(e=>{e.roughness=t,e.needsUpdate=!0})}setTransparent(t){this.transparent=t;const e=t?this.opacity*this.alpha:this.alpha;this.back&&(this.back.material.opacity=e),this.front&&(this.front.material.opacity=e),this._forEachMaterial(e=>{e.depthWrite=!(this.alpha<1)&&!t,e.depthTest=!0,e.needsUpdate=!0})}setBlackEdges(t){if(this.edgeMaterial&&!this.edgeMaterial.vertexColors){const e=t?0:this.edge_color;this.front||(this.originalColor=new En(e)),this.edgeMaterial.color=new En(e),this.edgeMaterial.needsUpdate=!0}}setEdgeColor(t){this.edgeMaterial&&!this.edgeMaterial.vertexColors&&(this.edge_color=t,this.edgeMaterial.color=new En(t),this.edgeMaterial.needsUpdate=!0)}setOpacity(t){if(this.opacity=t,this.transparent){const t=this.opacity*this.alpha;this.front&&(this.front.material.opacity=t,this.front.material.needsUpdate=!0),this.back&&(this.back.material.opacity=t,this.back.material.needsUpdate=!0)}}setShapeVisible(t){this.front&&(this._isStudioMode?this.front.visible=t:this.front.material.visible=t);for(const e of this.clipping.values()){const i=e.children[0],n=e.children[1];if(Jm(i)){if(Array.isArray(i.material))throw new Error("Multi-material meshes are not supported");i.material.visible=t}if(Jm(n)){if(Array.isArray(n.material))throw new Error("Multi-material meshes are not supported");n.material.visible=t}}this.back&&this.renderback&&(this._isStudioMode?this.back.visible=t:this.back.material.visible=t)}setEdgesVisible(t){this.edgeMaterial&&(this.edgeMaterial.visible=t),this.vertices&&(this.vertices.material.visible=t)}setBackVisible(t){if(this.back&&this.front){(this._isStudioMode?this.front.visible:this.front.material.visible)&&(this._isStudioMode?this.back.visible=this.renderback||t:this.back.material.visible=this.renderback||t)}}getVisibility(){if(this.front){const t=this._isStudioMode?this.front.visible:this.front.material.visible;return this.edgeMaterial?t||this.edgeMaterial.visible:t}return this.edgeMaterial?this.edgeMaterial.visible:!!this.vertices&&this.vertices.material.visible}setClipIntersection(t){this._forEachMaterial(e=>{e.clipIntersection=t})}setClipPlanes(t){this.back&&(this.back.material.clippingPlanes=t),this.front&&(this.front.material.clippingPlanes=t),this.edgeMaterial&&(this.edgeMaterial.clippingPlanes=t),this.vertices&&(this.vertices.material.clippingPlanes=t),this.updateMaterials(!0)}setPolygonOffset(t){this.back&&(this.back.material.polygonOffsetUnits=t)}setZScale(t){const e=(i,n,s,r=!0)=>{for(const a of i.children)"isMesh"in a||"isLine"in a?(a.scale.z=t,r&&a.parent&&(a.parent.position.z=n*t)):"isGroup"in a&&e(a,n,s,!a.name.startsWith("clipping"))};(this.front||this.back||this.edges)&&e(this,this.minZ,this.height)}updateMaterials(t){this.back&&(this.back.material.needsUpdate=t),this.front&&(this.front.material.needsUpdate=t),this.edgeMaterial&&(this.edgeMaterial.needsUpdate=t),this.vertices&&(this.vertices.material.needsUpdate=t)}clearClipping(){for(const[,t]of this.clipping)this.remove(t),Qm(t);this.clipping.clear()}setZebra(t){if(this.front){const e=this.front.material.visible;t?this.zebra.applyToMesh(this.front,e):this.zebra.restoreMesh(this.front,e)}}setZebraCount(t){this.zebra.setStripeCount(t)}setZebraOpacity(t){this.zebra.setStripeOpacity(t)}setZebraDirection(t){this.zebra.setStripeDirection(t)}setZebraColorScheme(t){this.zebra.setColorScheme(t)}setZebraMappingMode(t){this.zebra.setMappingMode(t)}enterStudioMode(t,e){this._isStudioMode||(this.front&&(this._cadFrontMaterial=this.front.material),this.back&&(this._cadBackMaterial=this.back.material),this._cadOriginalColor=this.originalColor?this.originalColor.clone():null,this._cadOriginalBackColor=this.originalBackColor?this.originalBackColor.clone():null,this._cadEdgesVisible=this.edgeMaterial?this.edgeMaterial.visible:null,this.front&&t&&(this.front.visible=this.front.material.visible,this.front.material=t,this.originalColor=t.color),this.back&&e&&this.renderback&&(this.back.visible=this.back.material.visible,this.back.material=e,this.originalBackColor=e.color),this._isStudioMode=!0)}leaveStudioMode(){this._isStudioMode&&(this.front&&this._cadFrontMaterial&&(this._cadFrontMaterial.visible=this.front.visible,this.front.material=this._cadFrontMaterial,this.front.visible=!0),this.back&&this._cadBackMaterial&&this.renderback&&(this._cadBackMaterial.visible=this.back.visible,this.back.material=this._cadBackMaterial,this.back.visible=!0),this._cadOriginalColor&&(this.originalColor=this._cadOriginalColor.clone()),this._cadOriginalBackColor&&(this.originalBackColor=this._cadOriginalBackColor.clone()),this.edgeMaterial&&null!==this._cadEdgesVisible&&(this.edgeMaterial.visible=this._cadEdgesVisible),this._isStudioMode=!1)}setStudioShowEdges(t){this.edgeMaterial&&(this.edgeMaterial.visible=t)}}function lf(t){return null!=t&&"isObjectGroup"in t&&!0===t.isObjectGroup}class hf extends jn{expandByObject(t,e=!1){if(t.updateWorldMatrix(!1,!1),lf(t))return this.expandByObject(t.children[0],e),this;const i=function(t){return"geometry"in t&&t.geometry instanceof Ds?t.geometry:null}(t);if(null!==i)if(e&&void 0!==i.attributes&&void 0!==i.attributes.position)if(t.type.startsWith("LineSegment")){const e=i.clone();e.applyMatrix4(t.matrixWorld),e.boundingBox=null,e.computeBoundingBox(),this.union(e.boundingBox),e.dispose()}else{const e=i.attributes.position;for(let i=0,n=e.count;i<n;i++)df.fromBufferAttribute(e,i).applyMatrix4(t.matrixWorld),this.expandByPoint(df)}else null===i.boundingBox&&i.computeBoundingBox(),uf.copy(i.boundingBox),uf.applyMatrix4(t.matrixWorld),this.union(uf);const n=t.children;for(let t=0,i=n.length;t<i;t++){const i=n[t];"PlaneMeshes"===i.name&&i.children&&i.children.length>0&&i.children[0].type.startsWith("StencilPlane")||this.expandByObject(i,e)}return this}max_dist_from_center(){return Math.max(...this.min.toArray().concat(this.max.toArray()).map(t=>Math.abs(t)))}boundingSphere(){return this.getBoundingSphere(mf),mf}center(){return this.getCenter(df),Vm(df.toArray())}}class cf extends Ba{constructor(t,e=16776960){const i=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),n=new Float32Array(24),s=new Ds;s.setIndex(new ms(i,1)),s.setAttribute("position",new ms(n,3)),super(s,new Sa({color:e,toneMapped:!1})),this.object=t,this.type="BoxHelper",this.matrixAutoUpdate=!1,this.update()}update(){if(void 0!==this.object&&pf.setFromObject(this.object,!0),pf.isEmpty())return;const t=pf.min,e=pf.max,i=this.geometry.attributes.position,n=i.array;n[0]=e.x,n[1]=e.y,n[2]=e.z,n[3]=t.x,n[4]=e.y,n[5]=e.z,n[6]=t.x,n[7]=t.y,n[8]=e.z,n[9]=e.x,n[10]=t.y,n[11]=e.z,n[12]=e.x,n[13]=e.y,n[14]=t.z,n[15]=t.x,n[16]=e.y,n[17]=t.z,n[18]=t.x,n[19]=t.y,n[20]=t.z,n[21]=e.x,n[22]=t.y,n[23]=t.z,i.needsUpdate=!0,this.geometry.computeBoundingSphere()}setFromObject(t){return this.object=t,this.update(),this}dispose(){Ym(this.geometry)}}const df=new xi,uf=new hf,pf=new hf,mf=new bs,ff=new Set(["baseColorTexture","emissiveTexture","sheenColorTexture","specularColorTexture"]),gf=new Set(["map","emissiveMap","sheenColorMap","specularColorMap"]);class vf{constructor(){this._cache=new Map,this._inflight=new Map,this._textureLoader=null,this._disposed=!1,this.maxAnisotropy=16}async get(t,e){if(this._disposed)return Fm.warn("TextureCache.get() called after dispose"),null;if(!t)return null;const i=ff.has(e)?Ee:Te;return t.startsWith("data:")?this._getFromDataUri(t,i):this._getFromUrl(t,i)}dispose(){for(const[t,e]of this._cache)zm.untrack("texture",e),e.dispose(),Fm.debug(`Disposed texture: ${t}`);this._cache.clear(),this._inflight.clear()}disposeFull(){this._disposed=!0,this.dispose(),this._textureLoader=null,Fm.debug("TextureCache fully disposed")}async _getFromDataUri(t,e){const i=t,n=this._cache.get(i);if(n)return n.colorSpace=e,n;const s=this._inflight.get(i);if(s){const t=await s;return t.colorSpace=e,t}return this._loadAndCache(i,t,e)}async _getFromUrl(t,e){const i=this._cache.get(t);if(i)return i.colorSpace=e,i;const n=this._inflight.get(t);if(n){const t=await n;return t.colorSpace=e,t}return this._loadAndCache(t,t,e)}async _loadAndCache(t,e,i){const n=this._doLoad(e,i);this._inflight.set(t,n);try{const e=await n;if(this._disposed||!this._inflight.has(t))return e.dispose(),null;this._cache.set(t,e);const i=t.startsWith("data:")?`Texture (data URI, ${t.length} chars)`:`Texture: ${t}`;return zm.trackTexture(e,i),Fm.debug(`Loaded and cached texture: ${i}`),e}catch(e){if(this._disposed)return null;const i=t.startsWith("data:")?`data URI (${t.length} chars)`:t;return Fm.warn(`Failed to load texture "${i}":`,e instanceof Error?e.message:e),null}finally{this._inflight.delete(t)}}_doLoad(t,e){const i=this._ensureTextureLoader();return new Promise((n,s)=>{i.load(t,t=>{t.colorSpace=e,t.wrapS=$,t.wrapT=$,t.anisotropy=this.maxAnisotropy,n(t)},void 0,e=>{s(e instanceof Error?e:new Error(`Texture load failed: ${t.substring(0,100)}`))})})}_ensureTextureLoader(){return this._textureLoader||(this._textureLoader=new vh,Fm.debug("Created TextureLoader")),this._textureLoader}}function yf(t){return gf.has(t)?Ee:Te}const _f=new Set(["color","specularColor","sheenColor","emissive","attenuationColor"]),xf={color:"map",metalness:"metalnessMap",roughness:"roughnessMap",normal:"normalMap",emissive:"emissiveMap",specularIntensity:"specularIntensityMap",specularColor:"specularColorMap",clearcoat:"clearcoatMap",clearcoatRoughness:"clearcoatRoughnessMap",clearcoatNormal:"clearcoatNormalMap",transmission:"transmissionMap",sheenColor:"sheenColorMap",sheenRoughness:"sheenRoughnessMap",anisotropy:"anisotropyMap",iridescence:"iridescenceMap",iridescenceThickness:"iridescenceThicknessMap",ao:"aoMap",occlusion:"aoMap",thickness:"thicknessMap",opacity:"alphaMap"};class bf{constructor(t={}){this.defaultOpacity=t.defaultOpacity??1,this.metalness=t.metalness??.3,this.roughness=t.roughness??.65,this.edgeColor=t.edgeColor??7368816,this.transparent=t.transparent??!1}_createBaseProps(t){return{polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1,transparent:!0,opacity:this.transparent?this.defaultOpacity*t:t,depthWrite:!this.transparent,depthTest:!0,clipIntersection:!1}}createFrontFaceMaterial({color:t,alpha:e,visible:i=!0},n){const s=new Pl({...this._createBaseProps(e),color:t,metalness:this.metalness,roughness:this.roughness,flatShading:!1,side:0,visible:i});return zm.track("material",s,n??"MeshStandardMaterial (front face)"),s}createBackFaceStandardMaterial({color:t,alpha:e,polygonOffsetUnits:i=2,visible:n=!0},s){const r=new Pl({...this._createBaseProps(e),color:t,metalness:this.metalness,roughness:this.roughness,flatShading:!1,side:1,visible:n});return r.polygonOffsetUnits=i,zm.track("material",r,s??"MeshStandardMaterial (back face)"),r}createBackFaceBasicMaterial({color:t,alpha:e,polygonOffsetUnits:i=2,visible:n=!0},s){const r=new lr({...this._createBaseProps(e),color:t,side:1,visible:n});return r.polygonOffsetUnits=i,zm.track("material",r,s??"MeshBasicMaterial (back face)"),r}createBasicFaceMaterial({color:t,alpha:e,visible:i=!0},n){const s=new lr({...this._createBaseProps(e),color:t,side:0,visible:i});return zm.track("material",s,n??"MeshBasicMaterial (front face)"),s}createEdgeMaterial({lineWidth:t,color:e,vertexColors:i=!1,visible:n=!0,resolution:s},r){const a=new dm({linewidth:t,transparent:!0,depthWrite:!this.transparent,depthTest:!this.transparent,clipIntersection:!1,vertexColors:i,toneMapped:!1});return i||(a.color=new En(e??this.edgeColor)),a.visible=n,s&&a.resolution.set(s.width,s.height),zm.track("material",a,r??"LineMaterial (edges)"),a}createSimpleEdgeMaterial({color:t,visible:e=!0},i){const n=new Sa({color:t??this.edgeColor,depthWrite:!this.transparent,depthTest:!this.transparent,visible:e});return zm.track("material",n,i??"LineBasicMaterial (simple edges)"),n}createVertexMaterial({size:t,color:e,visible:i=!0},n){const s=new Fa({color:e??this.edgeColor,sizeAttenuation:!1,size:t,transparent:!0,clipIntersection:!1,visible:i});return zm.track("material",s,n??"PointsMaterial (vertices)"),s}createTextureMaterial({texture:t,visible:e=!0},i){const n=new lr({color:"#ffffff",map:t,side:2,visible:e});return zm.track("material",n,i??"MeshBasicMaterial (textured)"),n}async createStudioMaterial({materialDef:t,fallbackColor:e,fallbackAlpha:i,textureCache:n},s){const r=t,a=r.doubleSided?2:0;let o,l;if(r.color?"string"==typeof r.color?(o=new En(r.color),l=1):(o=(new En).setRGB(r.color[0],r.color[1],r.color[2],Ee),l=r.color[3]??1):(o=new En(e),l=i),r.unlit){const t=new lr({...this._createBaseProps(l),color:o,side:a});if(this._applyAlphaMode(t,r,l),r.map&&n){const e=await n.get(r.map,"baseColorTexture");e&&(t.map=e)}return zm.track("material",t,s??"MeshBasicMaterial (studio unlit)"),t}const h="BLEND"===r.alphaMode||!r.alphaMode&&l<1,c=new Il({color:o,metalness:r.metalness??0,roughness:r.roughness??.5,flatShading:!1,side:a,transparent:h,opacity:l,depthWrite:!h,depthTest:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});return this._applyAlphaMode(c,r,l),r.emissive&&(c.emissive=new En(r.emissive[0],r.emissive[1],r.emissive[2])),void 0!==r.emissiveIntensity&&(c.emissiveIntensity=r.emissiveIntensity),void 0!==r.transmission&&(c.transmission=r.transmission,r.transmission>0&&(c.transparent=!1,c.opacity=1,c.depthWrite=!0)),void 0!==r.clearcoat&&(c.clearcoat=r.clearcoat),void 0!==r.clearcoatRoughness&&(c.clearcoatRoughness=r.clearcoatRoughness),void 0!==r.thickness&&(c.thickness=r.thickness),void 0!==r.attenuationDistance&&(c.attenuationDistance=r.attenuationDistance),r.attenuationColor&&(c.attenuationColor=new En(r.attenuationColor[0],r.attenuationColor[1],r.attenuationColor[2])),void 0!==r.ior&&(c.ior=r.ior),void 0!==r.specularIntensity&&(c.specularIntensity=r.specularIntensity),r.specularColor&&(c.specularColor=new En(r.specularColor[0],r.specularColor[1],r.specularColor[2])),void 0!==r.sheen&&r.sheen>0&&(c.sheen=r.sheen,r.sheenColor&&(c.sheenColor=new En(r.sheenColor[0],r.sheenColor[1],r.sheenColor[2])),void 0!==r.sheenRoughness&&(c.sheenRoughness=r.sheenRoughness)),void 0!==r.anisotropy&&r.anisotropy>0&&(c.anisotropy=r.anisotropy,void 0!==r.anisotropyRotation&&(c.anisotropyRotation=r.anisotropyRotation)),n&&await this._applyStudioTextures(c,r,n),zm.track("material",c,s??"MeshPhysicalMaterial (studio)"),c}async createStudioMaterialFromMaterialX(t,e,i,n,s){const r={flatShading:!1,side:0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1,depthTest:!0};(e.displacement||void 0!==t.displacementScale)&&Fm.warn("Displacement not supported by the Studio");for(const[e,i]of Object.entries(t))if("displacement"!==e&&"displacementScale"!==e&&"displacementBias"!==e)if(_f.has(e)&&Array.isArray(i)){const[t,n,s]=i;r[e]=new En(t,n,s)}else"normalScale"!==e&&"clearcoatNormalScale"!==e||!Array.isArray(i)?("iridescenceThicknessRange"===e&&Array.isArray(i),r[e]=i):r[e]=new yi(i[0],i[1]);const a=t.transmission,o=t.opacity,l=t.transparent;"number"==typeof a&&a>0?(r.transparent=!1,r.opacity=1,r.depthWrite=!0):!0===l||"number"==typeof o&&o<1?(r.transparent=!0,r.depthWrite=!1):(r.transparent=!1,r.depthWrite=!0);const h=new Il(r);let c=!1;if(n)for(const[t,s]of Object.entries(e)){const e=xf[t];if(!e)continue;const r=yf(e)===Ee?"baseColorTexture":"normalTexture";let a=await n.get(s,r);a&&(!i||1===i[0]&&1===i[1]||(a=a.clone(),a.repeat.set(i[0],i[1])),h[e]=a,c=!0)}return h.alphaMap&&(h.alphaTest=.5,h.side=2),c&&(h.needsUpdate=!0),zm.track("material",h,s??"MeshPhysicalMaterial (threejs-materials)"),h}_applyAlphaMode(t,e,i){switch(e.alphaMode){case"OPAQUE":t.transparent=!1,t.opacity=1,t.depthWrite=!0;break;case"MASK":t.transparent=!1,t.alphaTest=e.alphaCutoff??.5,t.opacity=i,t.depthWrite=!0;break;case"BLEND":t.transparent=!0,t.opacity=i,t.depthWrite=!1}}async _applyStudioTextures(t,e,i){const n=async(t,e)=>t?i.get(t,e):null,s=await n(e.map,"baseColorTexture");s&&(t.map=s);const r=await n(e.emissiveMap,"emissiveTexture");r&&(t.emissiveMap=r);const a=await n(e.sheenColorMap,"sheenColorTexture");a&&(t.sheenColorMap=a);const o=await n(e.specularColorMap,"specularColorTexture");o&&(t.specularColorMap=o);const l=await n(e.normalMap,"normalTexture");l&&(t.normalMap=l);const h=await n(e.aoMap,"occlusionTexture");h&&(t.aoMap=h);const c=await n(e.metalnessMap,"metallicRoughnessTexture");c&&(t.metalnessMap=c);const d=await n(e.roughnessMap,"metallicRoughnessTexture");d&&(t.roughnessMap=d);const u=await n(e.transmissionMap,"transmissionTexture");u&&(t.transmissionMap=u);const p=await n(e.thicknessMap,"thicknessTexture");p&&(t.thicknessMap=p);const m=await n(e.clearcoatMap,"clearcoatTexture");m&&(t.clearcoatMap=m);const f=await n(e.clearcoatRoughnessMap,"clearcoatRoughnessTexture");f&&(t.clearcoatRoughnessMap=f);const g=await n(e.clearcoatNormalMap,"clearcoatNormalTexture");g&&(t.clearcoatNormalMap=g);const v=await n(e.specularIntensityMap,"specularIntensityTexture");v&&(t.specularIntensityMap=v);const y=await n(e.sheenRoughnessMap,"sheenRoughnessTexture");y&&(t.sheenRoughnessMap=y);const _=await n(e.anisotropyMap,"anisotropyTexture");_&&(t.anisotropyMap=_)}update(t){void 0!==t.metalness&&(this.metalness=t.metalness),void 0!==t.roughness&&(this.roughness=t.roughness),void 0!==t.transparent&&(this.transparent=t.transparent),void 0!==t.defaultOpacity&&(this.defaultOpacity=t.defaultOpacity),void 0!==t.edgeColor&&(this.edgeColor=t.edgeColor)}}const Sf=[0,1,2];function Mf(t){return 0===t||1===t||2===t}var wf;function Af(t){return"object"==typeof t&&null!==t&&"values"in t}function Ef(t){return void 0!==t.triangles_per_face}function Tf(t){return void 0!==t.segments_per_edge}t.CollapseState=void 0,(wf=t.CollapseState||(t.CollapseState={}))[wf.LEAVES=-1]="LEAVES",wf[wf.COLLAPSED=0]="COLLAPSED",wf[wf.ROOT=1]="ROOT",wf[wf.EXPANDED=2]="EXPANDED";const Cf={chrome:{name:"Chrome",color:[.98,.98,.98,1],metalness:1,roughness:.05},"polished-steel":{name:"Polished Steel",color:[.91,.91,.92,1],metalness:1,roughness:.1},"polished-aluminum":{name:"Polished Aluminum",color:[.916,.923,.924,1],metalness:1,roughness:.1},gold:{name:"Gold",color:[1,.93,0,1],metalness:1,roughness:.1},copper:{name:"Copper",color:[.98,.82,.76,1],metalness:1,roughness:.15},brass:{name:"Brass",color:[.95,.9,.7,1],metalness:1,roughness:.15},"stainless-steel":{name:"Stainless Steel",color:[.91,.91,.92,1],metalness:1,roughness:.4},"brushed-aluminum":{name:"Brushed Aluminum",color:[.916,.923,.924,1],metalness:1,roughness:.35,anisotropy:.5},"cast-iron":{name:"Cast Iron",color:[.68,.68,.69,1],metalness:.9,roughness:.7},titanium:{name:"Titanium",color:[.81,.79,.77,1],metalness:1,roughness:.45},galvanized:{name:"Galvanized",color:[.88,.88,.9,1],metalness:.8,roughness:.5},"plastic-glossy":{name:"Plastic (Glossy)",color:[.91,.91,.91,1],metalness:0,roughness:.4},"plastic-matte":{name:"Plastic (Matte)",color:[.91,.91,.91,1],metalness:0,roughness:.6},"abs-black":{name:"ABS Black",color:[.25,.25,.25,1],metalness:0,roughness:.4},nylon:{name:"Nylon",color:[.95,.94,.92,1],metalness:0,roughness:.55},"acrylic-clear":{name:"Acrylic (Clear)",color:[1,1,1,1],metalness:0,roughness:0,transmission:.95,ior:1.49},"glass-clear":{name:"Glass (Clear)",color:[1,1,1,1],metalness:0,roughness:0,transmission:1,ior:1.52,thickness:2},"glass-tinted":{name:"Glass (Tinted)",color:[.8,.91,.95,1],metalness:0,roughness:0,transmission:.9,ior:1.52,thickness:3},"glass-frosted":{name:"Glass (Frosted)",color:[1,1,1,1],metalness:0,roughness:.3,transmission:.85,ior:1.52,thickness:2},"rubber-black":{name:"Rubber (Black)",color:[.31,.31,.31,1],metalness:0,roughness:.9},"rubber-gray":{name:"Rubber (Gray)",color:[.63,.63,.63,1],metalness:0,roughness:.85},"rubber-red":{name:"Rubber (Red)",color:[.85,.35,.35,1],metalness:0,roughness:.8},"paint-matte":{name:"Paint (Matte)",color:[.91,.91,.91,1],metalness:0,roughness:.7},"paint-glossy":{name:"Paint (Glossy)",color:[.91,.91,.91,1],metalness:0,roughness:.15},"paint-metallic":{name:"Paint (Metallic)",color:[.91,.91,.91,1],metalness:.5,roughness:.25},"car-paint":{name:"Car Paint",color:[.91,0,0,1],metalness:.5,roughness:.2,clearcoat:1,clearcoatRoughness:.03},"ceramic-white":{name:"Ceramic (White)",color:[.98,.98,.97,1],metalness:0,roughness:.1},"carbon-fiber":{name:"Carbon Fiber",color:[.25,.25,.25,1],metalness:.3,roughness:.35,anisotropy:.3},concrete:{name:"Concrete",color:[.83,.82,.8,1],metalness:0,roughness:.85}},Df=Object.keys(Cf).sort(),Rf=[["#include <logdepthbuf_fragment>","\n#include <logdepthbuf_fragment>\ninitTriplanarUVs();\n"],["#include <map_fragment>","\n#ifdef USE_MAP\n vec4 sampledDiffuseColor = triplanarSample( map );\n #ifdef DECODE_VIDEO_TEXTURE\n sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );\n #endif\n diffuseColor *= sampledDiffuseColor;\n#endif\n"],["#include <roughnessmap_fragment>","\nfloat roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = triplanarSample( roughnessMap );\n roughnessFactor *= texelRoughness.g;\n#endif\n"],["#include <metalnessmap_fragment>","\nfloat metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = triplanarSample( metalnessMap );\n metalnessFactor *= texelMetalness.b;\n#endif\n"],["#include <emissivemap_fragment>","\n#ifdef USE_EMISSIVEMAP\n vec4 emissiveColor = triplanarSample( emissiveMap );\n #ifdef DECODE_VIDEO_TEXTURE_EMISSIVE\n emissiveColor = sRGBTransferEOTF( emissiveColor );\n #endif\n totalEmissiveRadiance *= emissiveColor.rgb;\n#endif\n"],["#include <aomap_fragment>","\n#ifdef USE_AOMAP\n float ambientOcclusion = ( triplanarSample( aoMap ).r - 1.0 ) * aoMapIntensity + 1.0;\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n #if defined( USE_CLEARCOAT )\n clearcoatSpecularIndirect *= ambientOcclusion;\n #endif\n #if defined( USE_SHEEN )\n sheenSpecularIndirect *= ambientOcclusion;\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n #endif\n#endif\n"],["#include <normal_fragment_maps>","\n#ifdef USE_NORMALMAP_OBJECTSPACE\n normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n #ifdef FLIP_SIDED\n normal = - normal;\n #endif\n #ifdef DOUBLE_SIDED\n normal = normal * faceDirection;\n #endif\n normal = normalize( normalMatrix * normal );\n\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n // Triplanar normal mapping: sample normal map 3x (one per projection axis),\n // swizzle each to model space, blend, and transform to view space.\n normal = normalize(normalMatrix * triplanarNormal(normalMap, normalScale));\n\n#elif defined( USE_BUMPMAP )\n normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n\n#endif\n"],["#include <clearcoat_normal_fragment_maps>","\n#ifdef USE_CLEARCOAT_NORMALMAP\n // Reuse triplanarNormal with clearcoat normal map and scale\n vec3 clearcoatModelNormal = triplanarNormal(clearcoatNormalMap, clearcoatNormalScale);\n clearcoatNormal = normalize(normalMatrix * clearcoatModelNormal);\n#endif\n"],["#include <alphamap_fragment>","\n#ifdef USE_ALPHAMAP\n diffuseColor.a *= triplanarSample( alphaMap ).g;\n#endif\n"]];function Pf(t,e){e.computeBoundingBox();const i=e.boundingBox,n=new xi;i.getSize(n);const s=Math.max(n.x,n.y,n.z,1e-6),r=i.min.clone(),a=1/s,o=t.map?.repeat?.clone()??new yi(1,1);t.onBeforeCompile=t=>{t.uniforms.triplanarOffset={value:r},t.uniforms.triplanarScale={value:a},t.uniforms.triplanarRepeat={value:o},t.vertexShader=t.vertexShader.replace("#include <common>","#include <common>\n\nvarying vec3 vTriplanarPos;\nvarying vec3 vTriplanarNormal;\n"),t.vertexShader=t.vertexShader.replace("#include <worldpos_vertex>","#include <worldpos_vertex>\n vTriplanarPos = transformed;\n vTriplanarNormal = normalize(objectNormal);"),t.fragmentShader=t.fragmentShader.replace("#include <common>",'#include <common>\n\nvarying vec3 vTriplanarPos;\nvarying vec3 vTriplanarNormal;\nuniform vec3 triplanarOffset;\nuniform float triplanarScale;\nuniform vec2 triplanarRepeat;\n\n// normalMatrix is only declared in the fragment shader for object-space\n// normal maps. We need it for triplanar tangent-space normal mapping too.\n#ifndef USE_NORMALMAP_OBJECTSPACE\nuniform mat3 normalMatrix;\n#endif\n\n// --- Global triplanar state (computed once, reused by all samples) ---\nvec2 tri_uvX, tri_uvY, tri_uvZ;\nvec3 tri_blend;\n\n// Initialize global triplanar UVs and blend weights from varyings.\n// Must be called before any texture sampling.\nvoid initTriplanarUVs() {\n tri_blend = abs(vTriplanarNormal);\n tri_blend = pow(tri_blend, vec3(3.0));\n tri_blend /= (tri_blend.x + tri_blend.y + tri_blend.z);\n vec3 p = (vTriplanarPos - triplanarOffset) * triplanarScale;\n vec2 r = triplanarRepeat;\n tri_uvX = p.yz * r;\n tri_uvY = p.xz * r;\n tri_uvZ = p.xy * r;\n}\n\n// Sample a texture using the global triplanar UVs and blend weights.\nvec4 triplanarSample(sampler2D tex) {\n return texture2D(tex, tri_uvX) * tri_blend.x\n + texture2D(tex, tri_uvY) * tri_blend.y\n + texture2D(tex, tri_uvZ) * tri_blend.z;\n}\n\n// Surface-gradient triplanar normal mapping.\n// Instead of constructing full 3D normals per axis (which creates faceted\n// shading at axis boundaries), we extract the tangent-space perturbation (xy)\n// from each axis sample, project it into model space as a gradient, blend\n// the gradients, and add to the geometric normal. Gradients blend smoothly.\n// Ref: Morten Mikkelsen, "Surface Gradient Based Bump Mapping Framework"\n//\n// normalScale is declared in normalmap_pars_fragment (after this header),\n// so we accept it as a parameter to avoid forward-reference errors.\nvec3 triplanarNormal(sampler2D normalTex, vec2 nScale) {\n vec3 N = vTriplanarNormal;\n\n // Sample tangent-space normals for each projection axis\n vec3 tnX = texture2D(normalTex, tri_uvX).xyz * 2.0 - 1.0;\n vec3 tnY = texture2D(normalTex, tri_uvY).xyz * 2.0 - 1.0;\n vec3 tnZ = texture2D(normalTex, tri_uvZ).xyz * 2.0 - 1.0;\n\n // Apply normal scale to perturbation components\n tnX.xy *= nScale;\n tnY.xy *= nScale;\n tnZ.xy *= nScale;\n\n // Project each tangent-space perturbation (xy) into model space.\n // X proj: UV=(y,z) -> tangent=(0,1,0), bitangent=(0,0,1) -> grad=(0, tx, ty)\n // Y proj: UV=(x,z) -> tangent=(1,0,0), bitangent=(0,0,1) -> grad=(tx, 0, ty)\n // Z proj: UV=(x,y) -> tangent=(1,0,0), bitangent=(0,1,0) -> grad=(tx, ty, 0)\n vec3 surfGrad =\n vec3(0.0, tnX.x, tnX.y) * tri_blend.x +\n vec3(tnY.x, 0.0, tnY.y) * tri_blend.y +\n vec3(tnZ.x, tnZ.y, 0.0) * tri_blend.z;\n\n return normalize(N + surfGrad);\n}\n');for(const[e,i]of Rf)t.fragmentShader=t.fragmentShader.replace(e,i)},t.customProgramCacheKey=()=>"triplanar"}function If(t){return"parts"in t}class Lf extends _n{constructor(){super(...arguments),this.type="CompoundGroup",this.isCompoundGroup=!0}}const Bf=["map","normalMap","aoMap","metalnessMap","roughnessMap","emissiveMap","transmissionMap","clearcoatMap","clearcoatRoughnessMap","clearcoatNormalMap","thicknessMap","specularIntensityMap","specularColorMap","sheenColorMap","sheenRoughnessMap","anisotropyMap"];function Of(t){for(const e of Bf)if(t[e])return!0;return!1}function Ff(t){return Object.keys(t.textures).length>0}class Nf{constructor(t,e,i,n,s,r,a,o,l,h=0){this.shapes=t,this.width=e,this.height=i,this.edgeColor=n,this.transparent=s,this.metalness=a,this.roughness=o,this.defaultOpacity=r,this.normalLen=l,this.blackEdges=!1,this.backVisible=!1,this.bb_max=h,this.delim="|",this.rootGroup=null,this.instances=null,this.bbox=null,this.bsphere=null,this.groups={},this.clipPlanes=null,this.materialsTable=null,this.resolvedMaterials=new Map,this.resolvedMaterialX=new Map,this._textureCache=null,this._studioMaterialCache=new Map,this._texturedMaterialKeys=new Set,this._isStudioMode=!1,this.materialFactory=new bf({defaultOpacity:r,metalness:a,roughness:o,edgeColor:n,transparent:s})}dispose(){Object.keys(this.groups).length>0&&(Qm(Object.values(this.groups)),this.groups={}),this.rootGroup&&(Qm(this.rootGroup),this.rootGroup=null),this._disposeStudioResources(),this.resolvedMaterials.clear(),this.resolvedMaterialX.clear(),this.materialsTable=null}resolveMaterialTag(t,e){if(""===t)return null;const i=this.resolvedMaterials.get(t);if(void 0!==i)return i;const n=this.resolvedMaterialX.get(t);if(void 0!==n)return n;if(this.materialsTable&&t in this.materialsTable){const i=this.materialsTable[t];if("string"==typeof i){if(i.startsWith("builtin:")){const n=i.slice(8),s=Cf[n];if(s){const e={...s};return this.resolvedMaterials.set(t,e),e}return Fm.warn(`Unknown builtin preset '${n}' referenced by '${t}' on '${e}'`),null}return Fm.warn(`Invalid material string '${i}' for tag '${t}' (expected "builtin:" prefix)`),null}if(Af(i))return this.resolvedMaterialX.set(t,i),i;if("object"==typeof i&&"builtin"in i){const n=i,s=n.builtin,r=Cf[s];if(!r)return Fm.warn(`Unknown builtin preset '${s}' referenced by '${t}' on '${e}'`),null;const{color:a,...o}=r,l="color"in n?{...r,...n}:{...o,...n};return this.resolvedMaterials.set(t,l),l}return Fm.warn(`Unrecognised material entry for tag '${t}' on '${e}'`),null}const s=Cf[t];if(s){const e={...s};return this.resolvedMaterials.set(t,e),e}return Fm.warn(`Unknown material tag '${t}' on object '${e}'`),null}_isNestedArray(t){return t.length>0&&Array.isArray(t[0])}_toFloat32Array(t,e=1){return t instanceof Float32Array?t:this._isNestedArray(t)?new Float32Array(Hm(t,e)):new Float32Array(t)}_toUint32Array(t,e=1){return t instanceof Uint32Array?t:this._isNestedArray(t)?new Uint32Array(Hm(t,e)):new Uint32Array(t)}_renderEdges(t,e,i,n,s){const r=this._toFloat32Array(t,3),a=zm.trackGeometry(new Dm,s?`LineSegmentsGeometry for ${s}`:"LineSegmentsGeometry (edges)");if(a.setPositions(r),Array.isArray(i)){const t=i.map(t=>{const e=new En(t);return[e.r,e.g,e.b,e.r,e.g,e.b]}).flat();a.setColors(new Float32Array(t))}const o=this.materialFactory.createEdgeMaterial({lineWidth:e,color:Array.isArray(i)?null:i??this.edgeColor,vertexColors:Array.isArray(i),visible:1==n,resolution:{width:this.width,height:this.height}},s?`LineMaterial for ${s}`:"LineMaterial (edges)"),l=new Cm(a,o);return l.renderOrder=999,l}renderEdges(t,e,i,n,s,r,a=null){const o=Array.isArray(i)?this.edgeColor:i??this.edgeColor,l=new of(this.defaultOpacity,1,o,a,"edges"),h=this._renderEdges(t.edges,e,i,r,n);return s&&(h.name=s),l.setEdges(h),this.groups[n]=l,l.name=n.replaceAll("/",this.delim),l}renderVertices(t,e,i,n,s,r,a=null){const o=new of(this.defaultOpacity,1,i??this.edgeColor,a,"vertices"),l=this._toFloat32Array(t.obj_vertices),h=zm.trackGeometry(new Ds,`BufferGeometry (vertices) for ${n}`);h.setAttribute("position",new vs(l,3));const c=this.materialFactory.createVertexMaterial({size:e,color:i,visible:1==r},`PointsMaterial for ${n}`),d=new Ga(h,c);return s&&(d.name=s),o.setVertices(d),this.groups[n]=o,o.name=n.replaceAll("/",this.delim),o}renderShape(t,e,i,n,s,r,a,o,l=null,h=null,c=null,d=null,u=null){const p=this._toFloat32Array(t.vertices),m=this._toFloat32Array(t.normals),f=this._toUint32Array(t.triangles),g=new of(this.defaultOpacity,i??1,this.edgeColor,l,h,n);let v;this.groups[r]=g,g.name=r.replaceAll("/",this.delim),null==i?i=1:i<1&&(this.transparent=!0);let y,_=null;if(null!=c){const t=`data:image/${c.format};base64,${c.data}`,e=new Image;v=zm.trackGeometry(new pl(d,u),`PlaneGeometry (textured) for ${r}`),_=zm.trackTexture(new Ui(e),`Texture for ${r}`),_.colorSpace=Ee,e.onload=()=>{_.needsUpdate=!0},e.src=t,y=this.materialFactory.createTextureMaterial({texture:_},`MeshBasicMaterial (textured) for ${r}`),n=!1}else{if(v=zm.trackGeometry(new Ds,`BufferGeometry (shape) for ${r}`),v.setAttribute("position",new ms(p,3)),v.setAttribute("normal",new ms(m,3)),v.setIndex(new ms(f,1)),t.uvs&&t.uvs.length>0){const e=t.uvs instanceof Float32Array?t.uvs:new Float32Array(t.uvs);v.setAttribute("uv",new ms(e,2))}g.shapeGeometry=v,y=this.materialFactory.createFrontFaceMaterial({color:e,alpha:i,visible:1==o[0]},`MeshStandardMaterial (front) for ${r}`),y.name="frontMaterial"}const x="solid"!==g.subtype||s?new En(this.edgeColor).lerp(new En(1,1,1),.15).getHex():e,b=this.materialFactory.createBackFaceBasicMaterial({color:x,alpha:i,visible:1==o[0]&&(n||this.backVisible)},`MeshBasicMaterial (back) for ${r}`);b.name="backMaterial";const S=new xr(v,b);S.name=a;const M=new xr(v,y);if(M.name=a,i<1&&(S.renderOrder=999,M.renderOrder=999),null==M.geometry.boundingBox&&M.geometry.computeBoundingBox(),g.setBack(S),g.setFront(M),this.normalLen>0){const t=new Lm(M,this.normalLen,16711935);g.add(t)}const w=t.edges;if(w&&w.length>0){const t=this._renderEdges(w,1,null,o[1],r);t.name=a,g.setEdges(t)}return g}_createEdgesFromPolygons(t,e){const i=[],n=[];let s=0;for(let r=0;r<t.length;r++){const a=t[r].getPoints(),o=a.map(t=>new xi(t.x,t.y,0)),l=a.map(t=>new xi(t.x,t.y,e)),h=t=>{for(let e=0;e<t.length;e++){const i=(e+1)%t.length;n.push(s+e,s+i)}i.push(...t),s+=t.length};h(o),h(l);for(let t=0;t<a.length;t++)n.push(s-2*a.length+t,s-a.length+t)}const r=new Ds;return r.setFromPoints(i),r.setIndex(n),r}renderPolygons(t,e,i,n,s,r,a,o,l,h=null,c=null){const d=new of(this.defaultOpacity,1,this.edgeColor,h,c,s);d.name=a.replaceAll("/",this.delim),d.minZ=e,d.height=t.height,this.groups[a]=d;const u=[];let p;p=t.matrices&&t.matrices.length>0?t.matrices:[1,0,0,0,1,0];for(const e of t.refs){const t=this.instances[e],i=t.length/2,n=new Array(i);for(let e=0;e<p.length/6;e++){const s=p[6*e],r=p[6*e+1],a=p[6*e+2],o=p[6*e+3],l=p[6*e+4],h=p[6*e+5];for(let e=0;e<i;e++)n[e]=new yi(s*t[2*e]+r*t[2*e+1]+a,o*t[2*e]+l*t[2*e+1]+h);const c=new Po(n);u.push(c)}}const m={depth:t.height,bevelEnabled:!1},f=zm.trackGeometry(new ll(u,m),`ExtrudeGeometry (polygon) for ${a}`),g=this.materialFactory.createFrontFaceMaterial({color:i,alpha:n,visible:1==l[0]},`MeshStandardMaterial (front polygon) for ${a}`);g.name="frontMaterial";const v=this.materialFactory.createBackFaceStandardMaterial({color:i,alpha:n,visible:1==l[0]&&(s||this.backVisible)},`MeshStandardMaterial (back polygon) for ${a}`);v.name="backMaterial";const y=new xr(f,v);y.name=o;const _=new xr(f,g);_.name=o;const x=zm.trackGeometry(this._createEdgesFromPolygons(u,t.height),`BufferGeometry (polygon edges) for ${a}`),b=this.materialFactory.createSimpleEdgeMaterial({},`LineBasicMaterial (polygon edges) for ${a}`),S=new Ba(x,b);return d.shapeGeometry=f,d.setFront(_),d.setBack(y),d.setEdges(S),d}renderLoop(t){const e=(t,e,i,n)=>{let s;switch(t.type){case"edges":s=this.renderEdges(t.shape,t.width,t.color,t.id,t.name,t.state[1],{topo:"edge",geomtype:t.geomtype||null});break;case"vertices":s=this.renderVertices(t.shape,t.size,t.color??null,t.id,t.name,t.state[1],{topo:"vertex",geomtype:null});break;case"polygon":s=this.renderPolygons(t.shape,t.loc[0][2],t.color??this.edgeColor,1,null!=t.renderback&&t.renderback,!1,t.id,t.name,t.state,{topo:"face",geomtype:t.geomtype||null},t.subtype||null);break;default:{const r=Array.isArray(t.color)?t.color[0]:t.color;s=this.renderShape(t.shape,r??this.edgeColor,t.alpha??null,null!=t.renderback&&t.renderback,t.exploded??!1,t.id,t.name,t.state,{topo:"face",geomtype:t.geomtype||null},t.subtype||null,e,i,n)}}return null!=t.loc&&(s.position.set(...t.loc[0]),s.quaternion.set(...t.loc[1])),s},i=new Lf;null==t.loc&&(t.loc=[[0,0,0],[0,0,0,1]]),i.position.set(...t.loc[0]),i.quaternion.set(...t.loc[1]),this.groups[t.id]=i,i.name=t.id.replaceAll("/","|");for(const n of t.parts)if(If(n))i.add(this.renderLoop(n));else{const t=n,s=n.material;null!=s&&(t.material=s);const r=null!=t.texture,a=e(t,r?t.texture.image:null,r?t.texture.width:null,r?t.texture.height:null);this.groups[t.id]=a,void 0!==t.material&&null!==t.material&&(a.materialTag=t.material),i.add(a)}return i}render(){return"GDS"==this.shapes.format&&(this.instances=this.shapes.instances||null),this.materialsTable=this.shapes.materials||null,this.resolvedMaterials.clear(),this.resolvedMaterialX.clear(),this.rootGroup=this.renderLoop(this.shapes),this.rootGroup}boundingBox(){return null==this.bbox&&(this.bbox=new hf,this.bbox.setFromObject(this.rootGroup,!1)),this.bbox}_traverse(t,e){for(const i in this.groups){const n=this.groups[i];if(n instanceof of){const i=n[t];"function"==typeof i&&i.call(n,e)}}}selection(){const t=[];for(const e in this.groups)for(const i of this.groups[e].children)i instanceof of&&i.isSelected&&t.push(i);return t}clearSelection(){for(const t of this.selection())t.clearHighlights()}setMetalness(t){this.metalness=t,this.materialFactory.update({metalness:t}),this._traverse("setMetalness",t)}setRoughness(t){this.roughness=t,this.materialFactory.update({roughness:t}),this._traverse("setRoughness",t)}setTransparent(t){this.transparent=t,this.materialFactory.update({transparent:t}),this._traverse("setTransparent",t)}setBlackEdges(t){this.blackEdges=t,this._traverse("setBlackEdges",t)}setBackVisible(t){this.backVisible=t,this._traverse("setBackVisible",t)}setEdgeColor(t){this.edgeColor=t,this._traverse("setEdgeColor",t)}setOpacity(t){this.defaultOpacity=t,this._traverse("setOpacity",t)}setClipIntersection(t){this._traverse("setClipIntersection",t)}setClipPlanes(t){this.clipPlanes=t,this._traverse("setClipPlanes",t)}setPolygonOffset(t){this._traverse("setPolygonOffset",t)}setZScale(t){this._traverse("setZScale",t)}setMinZ(){this._traverse("setMinZ")}updateMaterials(){this._traverse("updateMaterials",!0)}setZebra(t){this._traverse("setZebra",t)}setZebraCount(t){this._traverse("setZebraCount",t)}setZebraOpacity(t){this._traverse("setZebraOpacity",t)}setZebraDirection(t){this._traverse("setZebraDirection",t)}setZebraColorScheme(t){this._traverse("setZebraColorScheme",t)}setZebraMappingMode(t){this._traverse("setZebraMappingMode",t)}async enterStudioMode(t="triplanar"){this._textureCache||(this._textureCache=new vf);const e=new Set;for(const i in this.groups){const n=this.groups[i];if(!(n instanceof of))continue;if(!n.front)continue;const s=n.materialTag||"",r=n.originalColor?"#"+n.originalColor.getHexString():"#707070",a=n.alpha,o=`${s}:${r}:${a}`;let l=this._studioMaterialCache.get(o);if(!l){const t=s?this.resolveMaterialTag(s,i):null;s&&!t&&e.add(s);try{if(t&&Af(t))l=await this.materialFactory.createStudioMaterialFromMaterialX(t.values,t.textures,t.textureRepeat,this._textureCache),Ff(t)&&this._texturedMaterialKeys.add(o);else{let e;if(t)e=t;else if(a<1){const{color:t,...i}=Cf["acrylic-clear"];e={...i,transmission:1-a}}else{const{color:t,...i}=Cf["plastic-glossy"];e=i}l=await this.materialFactory.createStudioMaterial({materialDef:e,fallbackColor:r,fallbackAlpha:a,textureCache:this._textureCache}),Of(e)&&this._texturedMaterialKeys.add(o)}}catch(t){Fm.warn(`Studio material creation failed for "${i}" (tag="${s}"), skipping`,t);continue}this._studioMaterialCache.set(o,l)}const h=this._texturedMaterialKeys.has(o),c=null!=n.shapeGeometry?.getAttribute("uv"),d=h&&null!=n.shapeGeometry&&("triplanar"===t||!c);if(h&&Fm.debug(`Studio "${i}": ${d?"using triplanar":"using parametric UVs"}`),d&&l instanceof Il){const t=`${o}:tri:${i}`;let e=this._studioMaterialCache.get(t);e||(e=l.clone(),Pf(e,n.shapeGeometry),this._studioMaterialCache.set(t,e)),l=e}let u=null;if(n.renderback&&l instanceof Il){const t=d?`${o}:tri:${i}:back`:`${o}:back`;let e=this._studioMaterialCache.get(t);e||(e=l.clone(),e.side=1,d&&n.shapeGeometry&&Pf(e,n.shapeGeometry),this._studioMaterialCache.set(t,e)),u=e}if(l instanceof Il&&l.anisotropy>0&&null!=n.shapeGeometry?.getAttribute("uv")&&null==n.shapeGeometry.getAttribute("tangent"))try{n.shapeGeometry.computeTangents()}catch{Fm.debug(`Studio "${i}": tangent computation failed, anisotropy may have artifacts`)}n.enterStudioMode(l instanceof Il?l:null,u)}return this._isStudioMode=!0,[...e]}leaveStudioMode(){for(const t in this.groups){const e=this.groups[t];e instanceof of&&e.leaveStudioMode()}this._isStudioMode=!1}clearStudioMaterialCache(){for(const[,t]of this._studioMaterialCache)t.dispose();this._studioMaterialCache.clear(),this._texturedMaterialKeys.clear()}setStudioShowEdges(t){for(const e in this.groups){const i=this.groups[e];i instanceof of&&i.setStudioShowEdges(t)}}_disposeStudioResources(){this._isStudioMode&&this.leaveStudioMode();for(const[,t]of this._studioMaterialCache)t.dispose();this._studioMaterialCache.clear(),this._texturedMaterialKeys.clear(),this._textureCache&&(this._textureCache.disposeFull(),this._textureCache=null),this._isStudioMode=!1}}function Uf(t){let e=t.replace(/(\.\d*[1-9])0+$/,"$1").replace(/\.0+$/,"");return"-0"===e&&(e="0"),e.indexOf(".")<0&&(e=`${e}.0`),e}class kf extends yn{constructor(t,e,i,n,s){super();const r=t/e,a=t/2,o=[],l=[],h=[];let c=!1,d=!1;for(let t=0;t<=e;t++){const e=t*r-a,i=Math.abs(e)<1e-10;i?d||(h.push(-a,0,0,a,0,0),d=!0):o.push(-a,0,e,a,0,e),i?c||(l.push(0,0,-a,0,0,a),c=!0):o.push(e,0,-a,e,0,a)}d||h.push(-a,0,0,a,0,0),c||l.push(0,0,-a,0,0,a);const u=new Ds;u.setAttribute("position",new vs(o,3));const p=u.getAttribute("position"),m=new Float32Array(p.count);for(let t=0;t<p.count;t+=2){const e=p.getX(t),i=p.getY(t),n=p.getZ(t),s=p.getX(t+1),r=p.getY(t+1),a=p.getZ(t+1);m[t]=0,m[t+1]=Math.sqrt((s-e)**2+(r-i)**2+(a-n)**2)}u.setAttribute("lineDistance",new ms(m,1));const f=new zl({color:s,dashSize:r/20,gapSize:r/20,opacity:1,transparent:!1,vertexColors:!1}),g=new Ba(u,f);this.add(g);const v=new Ds;v.setAttribute("position",new vs(l,3));const y=new Sa({color:i});this.add(new Ba(v,y));const _=new Ds;_.setAttribute("position",new vs(h,3));const x=new Sa({color:n});this.add(new Ba(_,x))}}class zf extends _n{constructor(t){super();const e=["bbox","gridFontSize","grid","theme","cadWidth","height","maxAnisotropy","getCamera","getAxes0"];for(const i of e)if(void 0===t[i])throw new Error(`Grid: required option "${i}" is missing`);const{bbox:i,ticks:n=5,gridFontSize:s,centerGrid:r,axes0:a,grid:o,flipY:l,theme:h,cadWidth:c,height:d,maxAnisotropy:u,tickValueElement:p,tickInfoElement:m,getCamera:f,getAxes0:g,onGridChange:v}=t;this.ticks=n,this.ticks0=n,this.gridFontSize=s,this.bbox=i,this.centerGrid=r||!1,this.axes0=a||!1,this.grid=o,this.allGrid=!!(o[0]||o[1]||o[2]),this.theme=h,this.flipY=l||!1,this.lastZoomIndex=0,this.lastFontIndex=50,this.cadWidth=c,this.height=d,this.maxAnisotropy=u,this.tickValue=p||null,this.info=m||null,this.getCamera=f,this.getAxes0=g,this.onGridChange=v||null;const y=i.max_dist_from_center(),_=Math.min(c,d),x=Math.max(1,6-Math.log2(_/100));this.minFontIndex=Math.round((y<2?6:y<1e3?5:3)*x),this.minZoomIndex=-4,this.zoomMaxIndex=5,this.canvasHeight=128,this.geomCache={},this.textureAspectRatios={},this.labelCache={},this.materialCache={},this.size=0,this.delta=0,this.colors={dark:["#ff4500","#32cd32","#3b9eff"],light:["#ff4500","#32cd32","#3b9eff"]},this.create()}calculateTextScale(t){const e=this.getCamera();if(!e)return t;const i=this.height,n=(r=.8,a=800,o=1,((l=i)<(s=300)?r:l>a?o:(o-r)/(a-s)*(l-s)+r)*t);var s,r,a,o,l;if(e instanceof Fh){return n/(i/((e.top-e.bottom)/e.zoom))*1.6}return n/i*.6}scaleLabels(){for(const t of this.children)if(t instanceof _n)for(let e=1;e<t.children.length;e++){const i=t.children[e];if(!(i instanceof qs))continue;const n=this.calculateTextScale(this.gridFontSize),s=i.userData.aspectRatio||4;i.scale.set(n*s,n,1)}}showLabels(t){for(const e of this.children)if(e instanceof _n)for(let i=1;i<e.children.length;i++)e.children[i].visible=t}async update(t,e=!1,i=null){if(!this.getVisible())return;i&&(this.theme=i);let n=Math.round(Math.log2(.4*t));if(Math.abs(n)<1e-6&&(n=0),e||n!=this.lastZoomIndex&&n<this.zoomMaxIndex&&n>this.minZoomIndex){Qm(this.children),this.children=[];const t=this.ticks0/2*2**n;this.ticks=Math.round(2*t),await this.create(!1),this.lastZoomIndex=n,e=!0}const s=Math.round(50*t);(e||s!=this.lastFontIndex)&&(s<this.minFontIndex?this.showLabels(!1):(this.getCamera()instanceof Fh&&this.scaleLabels(),this.showLabels(!0)),this.lastFontIndex=s)}async create(t=!0){if(t){const t=Math.max(Math.abs(this.bbox.max.x),Math.abs(this.bbox.max.y),Math.abs(this.bbox.max.z),Math.abs(this.bbox.min.x),Math.abs(this.bbox.min.y),Math.abs(this.bbox.min.z)),[e,i,n]=this.niceBounds(1.05*-t,1.05*t,this.ticks);this.size=i-e,this.ticks=this.size/n,this.ticks0=this.ticks,this.delta=n}else this.delta=this.size/this.ticks;this.setTickInfo();for(let t=0;t<3;t++){const e=new Lf;let i;e.name=`GridHelper-${t}`,e.add(new kf(this.size,2*this.ticks,this.colors[this.theme][0===t?1:1===t?0:2],this.colors[this.theme][0===t?0:1===t?2:1],"dark"==this.theme?125269879:12303291));for(let n=-this.size/2;n<=this.size/2;n+=this.delta/2){if(Math.abs(n)<1e-6)continue;let s=Uf(n.toFixed(4));n>0&&(s="+"+s),i=this.createLabel(s,n,t,!0),e.add(i),i=this.createLabel(s,n,t,!1),e.add(i)}this.add(e)}this.children[0].rotateX(Math.PI/2),this.children[1].rotateY(Math.PI/2),this.children[2].rotateZ(Math.PI/2),this.setCenter(this.axes0,this.flipY),this.scaleLabels(),this.setCenter(this.getAxes0(),this.flipY),this.setVisible()}createTextTexture(t){if(this.geomCache[t])return this.geomCache[t];const e=document.createElement("canvas"),i=e.getContext("2d",{alpha:!0,desynchronized:!1,willReadFrequently:!1}),n=`${"dark"===this.theme?"500":"560"} 80px Verdana, Arial, sans-serif`;i.font=n;const s=i.measureText(t).width,r=Math.round(s+40),a=this.canvasHeight;e.width=r,e.height=a,i.textRendering="optimizeLegibility",i.font=n,i.textAlign="center",i.textBaseline="middle",i.clearRect(0,0,e.width,e.height);const o=e.width/2,l=e.height/2;i.lineWidth=12,i.lineJoin="round",i.miterLimit=2,i.strokeStyle="dark"===this.theme?"#444444":"#ffffff",i.strokeText(t,o,l),i.fillStyle="dark"===this.theme?"#aaaaaa":"#333333",i.fillText(t,o,l);const h=new Xa(e);return h.needsUpdate=!0,h.colorSpace="dark"===this.theme?Ee:Te,h.minFilter=rt,h.magFilter=rt,h.generateMipmaps=!1,h.anisotropy=this.maxAnisotropy,h.premultiplyAlpha=!1,h.wrapS=tt,h.wrapT=tt,this.geomCache[t]=h,this.textureAspectRatios[t]=r/a,h}createLabel(t,e,i,n){const s=`${t}_${i}_${n}`;if(this.labelCache[s]){const t=this.labelCache[s],e=new qs(t.material);return e.position.copy(t.position),e.scale.copy(t.scale),e.userData.aspectRatio=t.userData.aspectRatio,e}const r=this.createTextTexture(t);let a=0;a=0===i?0:1===i?n?Math.PI/2:0:n?0:Math.PI/2;const o=`${t}_${i}_${n}`;let l=this.materialCache[o];l||(l=new Fs({map:r,transparent:!0,depthTest:!0,depthWrite:!1,blending:1,rotation:a,sizeAttenuation:!1}),this.materialCache[o]=l);const h=new qs(l);let c;c=0===i?n?1:-1:1===i&&n?-1:1,n?h.position.set(c*e,0,0):h.position.set(0,0,c*e);const d=this.textureAspectRatios[t]||4;return h.scale.set(d,1,1),h.userData.aspectRatio=d,this.labelCache[s]=h,h}niceBounds(t,e,i){i||(i=8);const n=Math.max(Math.abs(t),Math.abs(e));if(0===n)return[0,0,0];const s=n/i,r=Math.floor(Math.log10(s)),a=Math.pow(10,r),o=s/a;let l;l=o<=1?1:o<=2?2:o<=2.5?2.5:o<=5?5:10;const h=l*a,c=h*Math.ceil(n/h);return[-c,c,h]}computeGrid(){this.allGrid=!!(this.grid[0]||this.grid[1]||this.grid[2]),this.onGridChange&&this.onGridChange(this.allGrid,this.grid),this.setVisible()}setGrid(t,e=null){switch(t){case"grid":this.allGrid=null==e?!this.allGrid:e,this.grid[0]=this.allGrid,this.grid[1]=this.allGrid,this.grid[2]=this.allGrid;break;case"grid-xy":this.grid[0]=!this.grid[0];break;case"grid-xz":this.grid[1]=!this.grid[1];break;case"grid-yz":this.grid[2]=!this.grid[2]}this.computeGrid()}setGrids(t,e,i){this.grid[0]=t,this.grid[1]=e,this.grid[2]=i,this.computeGrid()}setCenter(t,e){const i=t?[0,0,0]:this.bbox.center();this.children.forEach(t=>t.position.set(i[0],i[1],i[2])),this.centerGrid||(this.children[0].position.z-=this.size/2,this.children[1].position.y-=(e?-1:1)*this.size/2,this.children[2].position.x-=this.size/2)}setVisible(){this.children.forEach((t,e)=>{t.visible=this.grid[e]}),this.info&&(this.info.style.display=this.allGrid?"block":"none")}setTickInfo(){this.tickValue&&(this.tickValue.innerText=Uf((this.delta/2).toFixed(4)))}getVisible(){return this.allGrid}clearCache(){if(Object.keys(this.geomCache).length>0){for(const t of Object.keys(this.geomCache)){this.geomCache[t].dispose()}this.geomCache={}}if(this.textureAspectRatios={},this.materialCache&&Object.keys(this.materialCache).length>0){for(const t of Object.keys(this.materialCache)){this.materialCache[t].dispose()}this.materialCache={}}Object.keys(this.labelCache).length>0&&(this.labelCache={})}dispose(){this.clearCache()}}class Gf extends Cm{constructor(t,e,i,n,s,r,a,o){const l=new Float32Array([0,0,0,e,0,0,0,0,0,0,e,0,0,0,0,0,0,e]),h=new Dm;h.setPositions(l);const c=new dm({vertexColors:!0,toneMapped:!1,linewidth:i,transparent:!0});c.resolution.set(n,s),super(h,c),this.colors={dark:[1,69/255,0,1,69/255,0,50/255,205/255,50/255,50/255,205/255,50/255,59/255,158/255,1,59/255,158/255,1],light:[1,0,0,1,0,0,0,.5,0,0,.5,0,0,0,1,0,0,1]},h.setColors(new Float32Array(this.colors[o])),this.geometry=h,this.center=t,this.type="AxesHelper",this.name="AxesHelper",this.visible=a,this.setCenter(r)}setCenter(t){t?this.position.set(0,0,0):this.position.set(this.center[0],this.center[1],this.center[2])}setVisible(t){this.visible=t}changeTheme(t){this.geometry.setColors(new Float32Array(this.colors[t]))}}class Hf{constructor(t){this.isFont=!0,this.type="Font",this.data=t}generateShapes(t,e=100,i="ltr"){const n=[],s=function(t,e,i,n){const s=Array.from(t),r=e/i.resolution,a=(i.boundingBox.yMax-i.boundingBox.yMin+i.underlineThickness)*r,o=[];let l=0,h=0;"rtl"!=n&&"tb"!=n||s.reverse();for(let t=0;t<s.length;t++){const e=s[t];if("\n"===e)l=0,h-=a;else{const t=Vf(e,r,l,h,i);"tb"==n?(l=0,h+=i.ascender*r):l+=t.offsetX,o.push(t.path)}}return o}(t,e,this.data,i);for(let t=0,e=s.length;t<e;t++)n.push(...s[t].toShapes());return n}}function Vf(t,e,i,n,s){const r=s.glyphs[t]||s.glyphs["?"];if(!r)return void console.error('THREE.Font: character "'+t+'" does not exists in font family '+s.familyName+".");const a=new dd;let o,l,h,c,d,u,p,m;if(r.o){const t=r._cachedOutline||(r._cachedOutline=r.o.split(" "));for(let s=0,r=t.length;s<r;){switch(t[s++]){case"m":o=t[s++]*e+i,l=t[s++]*e+n,a.moveTo(o,l);break;case"l":o=t[s++]*e+i,l=t[s++]*e+n,a.lineTo(o,l);break;case"q":h=t[s++]*e+i,c=t[s++]*e+n,d=t[s++]*e+i,u=t[s++]*e+n,a.quadraticCurveTo(d,u,h,c);break;case"b":h=t[s++]*e+i,c=t[s++]*e+n,d=t[s++]*e+i,u=t[s++]*e+n,p=t[s++]*e+i,m=t[s++]*e+n,a.bezierCurveTo(d,u,p,m,h,c)}}}return{offsetX:r.ha*e,path:a}}const Wf={glyphs:{X:{x_min:-.015625,x_max:854.15625,ha:940,o:"m 854 0 l 683 0 l 423 409 l 166 0 l 0 0 l 347 519 l 18 1013 l 186 1013 l 428 637 l 675 1013 l 836 1013 l 504 520 l 854 0 "},Y:{x_min:0,x_max:820,ha:886,o:"m 820 1013 l 482 416 l 482 0 l 342 0 l 342 416 l 0 1013 l 140 1013 l 411 534 l 679 1012 l 820 1013 "},Z:{x_min:0,x_max:779,ha:849,o:"m 779 0 l 0 0 l 0 113 l 621 896 l 40 896 l 40 1013 l 779 1013 l 778 887 l 171 124 l 779 124 l 779 0 "}},cssFontWeight:"normal",ascender:1189,underlinePosition:-100,cssFontStyle:"normal",boundingBox:{yMin:-334,xMin:-111,yMax:1189,xMax:1672},resolution:1e3,descender:-334,familyName:"Helvetiker",lineHeight:1522,underlineThickness:50,original_font_information:{}};class jf{constructor(t,e,i,n){this.width=t,this.height=e,this.cad_camera=i,this.theme=n,this.camera=null,this.scene=null,this.renderer=null,this.labels=[],this.ready=!1,this.colors={dark:[[1,69/255,0],[50/255,205/255,50/255],[59/255,158/255,1]],light:[[1,0,0],[0,.5,0],[0,0,1]]},this.cones=[],this.axes=null}create(){const t=new Hf(Wf),e=2.5;this.scene=new Rn,this.camera=new Fh(-this.width,this.width,this.height,-this.height,1,1e3),this.camera.up=this.cad_camera.up,this.camera.lookAt(new xi(0,0,0)),this.axes=new Gf([0,0,0],54,e,this.width,this.height,!0,!0,this.theme),this.scene.add(this.axes),this.cones=[];for(let t=0;t<3;t++){const e=new $a(0,6.25,12.5,20,1),i=new lr({color:new En(...this.colors[this.theme][t]),toneMapped:!1}),n=new xr(e,i);n.matrixAutoUpdate=!1,this.cones.push(n)}this.cones[0].geometry.rotateZ(-Math.PI/2),this.cones[0].geometry.translate(54,0,0),this.cones[1].geometry.translate(0,54,0),this.cones[2].geometry.rotateX(Math.PI/2),this.cones[2].geometry.translate(0,0,54),this.scene.add(...this.cones);const i=["X","Y","Z"];for(let e=0;e<3;e++){const n=new Sa({color:"dark"===this.theme?new En(.9,.9,.9):new En(0,0,0),side:2}),s=t.generateShapes(i[e],16),r=new fl(s);r.computeBoundingBox();const a=-.5*(r.boundingBox.max.x-r.boundingBox.min.x),o=-.5*(r.boundingBox.max.y-r.boundingBox.min.y);r.translate(a,o,0);const l=new xr(r,n);this.scene.add(l),this.labels.push(l)}const n=new gl(7.5,20,20),s=new lr({color:10526880}),r=new xr(n,s);this.scene.add(r),this.scene.background=null,this.ready=!0}setVisible(t){if(this.scene)for(const e of this.scene.children)e.visible=t}dispose(){Xm(this.scene,t=>{t instanceof xr&&(t.geometry?.dispose(),t.material instanceof Os&&t.material.dispose())}),this.scene=null,this.camera=null,this.cad_camera=null,this.cones=[],this.labels=[]}render(t){if(this.ready&&this.scene&&this.camera){const e=t.getViewport(new ki),i=t.getScissor(new ki),n=t.getScissorTest();t.setViewport(0,0,this.width,this.height),t.render(this.scene,this.camera),t.setViewport(e),t.setScissor(i),t.setScissorTest(n)}}update(t,e){if(this.ready&&this.camera){const i=(new _i).setFromUnitVectors(new xi(0,0,1),t.normalize());this.camera.position.set(0,0,1).applyQuaternion(i).multiplyScalar(300),this.camera.quaternion.copy(e);for(let t=0;t<3;t++)this.labels[t].position.set(0==t?72:0,1==t?72:0,2==t?72:0),this.labels[t].quaternion.copy(e)}}changeTheme(t){for(const e in this.cones){this.cones[e].material.color=new En(...this.colors[t][e])}this.axes&&this.axes.changeTheme(t);for(const e in this.labels){this.labels[e].material.color="dark"===t?new En(.9,.9,.9):new En(0,0,0)}}}const Xf=0,Yf=1,Zf=2,qf=3;function Qf(t){return Array.isArray(t)&&2===t.length}function Kf(t){return"object"==typeof t&&!Array.isArray(t)}class Jf{constructor(t,e={}){this.linkIcons=void 0===e.linkIcons||e.linkIcons,this.onStateChange=e.onStateChange||null,this.maxLevel=0,this.root=this._buildTreeStructure(t)}_buildTreeStructure(t){const e=(t,i,n)=>{const s=[Xf,Xf],r={};this.maxLevel<n&&(this.maxLevel=n);const a=[[!1,!1],[!1,!1],[!1,!1],[!1,!1]];for(const s in t){let o,l="";l=null==i?s:`${i}/${s}`;const h=t[s];if(Qf(h))o=h,a[h[0]][0]=!0,a[h[1]][1]=!0,r[s]={name:s,state:o,path:l,rendered:!1,level:n};else if(Kf(h)&&Object.keys(h).length>0){let t;[t,o]=e(h,l,n+1),a[o[0]][0]=!0,a[o[1]][1]=!0,r[s]={name:s,state:o,path:l,rendered:!1,level:n,children:t,expanded:!1}}else o=[qf,qf],a[qf][0]=!0,a[qf][1]=!0,r[s]={name:s,state:o,path:l,rendered:!1,level:n}}return[r,(t=>{for(const e of[0,1])t[Zf][e]||t[Yf][e]&&t[Xf][e]?s[e]=Zf:t[Yf][e]?s[e]=Yf:t[Xf][e]?s[e]=Xf:t[qf][e]&&(s[e]=qf);return s})(a)]},i=e(t,null,0)[0];return i[Object.keys(i)[0]]}traverse(t,e){if(e(t),t.children)for(const i of Object.keys(t.children))this.traverse(t.children[i],e)}isLeaf(t){return null==t.children}getNodePath(t){return null==t?"":"/"+t.path}findNodeByPath(t){if(!this.root)return null;const e=Array.isArray(t)?t:t.split("/").filter(Boolean);let i=this.root;for(let t=1;t<e.length;t++){const n=e[t];if(!i.children||!i.children[n])return null;i=i.children[n]}return i}getParent(t){const e=t.path.substring(0,t.path.lastIndexOf("/"));return 0===e.length?null:this.findNodeByPath(e)}getState(t){const e=this.findNodeByPath(t);return e?e.state:null}getStates(){const t={};return this.root&&this.traverse(this.root,e=>{this.isLeaf(e)&&(t[this.getNodePath(e)]=e.state)}),t}setState(t,e){const i=this.findNodeByPath(t);i&&(this.toggleNodeState(i,0,e[0]===Yf),this.toggleNodeState(i,1,e[1]===Yf))}setStates(t){for(const e in t)this.setState(e,t[e])}toggleNodeState(t,e,i=null){const n=t.state[e];if(n===qf)return!1;const s=0===e?this.linkIcons?[0,1]:[0]:[1];for(const e of s)t.state[e]!==qf&&(t.state[e]=null!==i?i?Yf:Xf:n===Yf?Xf:Yf,this.onStateChange&&this.onStateChange(t,e),this._updateParentStates(t,e),this._updateChildrenStates(t,e));return!0}_updateParentStates(t,e){let i=this.getParent(t);for(;i;){const t=Object.values(i.children),n=t.every(t=>t.state[e]===Yf||t.state[e]===qf),s=t.every(t=>t.state[e]===Xf||t.state[e]===qf),r=n?Yf:s?Xf:Zf;i.state[e]!==r&&i.state[e]!==qf&&(i.state[e]=r,this.onStateChange&&this.onStateChange(i,e)),i=this.getParent(i)}}_updateChildrenStates(t,e){const i=t.state[e],n=t=>{if(t.state[e]!==i&&t.state[e]!==qf&&(t.state[e]=i,this.onStateChange&&this.onStateChange(t,e)),t.children)for(const e in t.children)n(t.children[e])};n(t)}hideAll(){this.root&&(this.toggleNodeState(this.root,0,!1),this.linkIcons&&this.root.state[0]!==qf||this.toggleNodeState(this.root,1,!1))}showAll(){this.root&&(this.toggleNodeState(this.root,0,!0),this.linkIcons||this.toggleNodeState(this.root,1,!0))}show(t){const e=this.findNodeByPath(t);e&&this.toggleNodeState(e,0,!0)}hide(t){const e=this.findNodeByPath(t);e&&this.toggleNodeState(e,0,!1)}setExpandedLevel(t){this.root&&this.traverse(this.root,e=>{this.isLeaf(e)||(e.expanded=-1===t?null!=e.children&&!(1===Object.keys(e.children).length&&this.isLeaf(Object.values(e.children)[0])):e.level<t)})}expandPath(t){const e=t.split("/").filter(Boolean);let i="",n=null;for(const t of e){if(i+="/"+t,n=this.findNodeByPath(i),!n)return null;n.children&&(n.expanded=!0)}return n}collapsePath(t){const e=this.findNodeByPath(t);return e&&(e.expanded=!1),e}dispose(){this.root=null,this.onStateChange=null}}const $f="▾",tg="▸",eg=[["shape_no","shape","shape_mix","shape_empty"],["mesh_no","mesh","mesh_mix","mesh_empty"]],ig=[0,1];class ng{constructor(t,e,i,n,s,r,a,o,l,h=!1){this.handleScroll=()=>{this.scrollContainer&&(this.lastScrollTop=this.scrollContainer.scrollTop,this.debug&&Fm.debug("update => scroll"),this.update())},this.handleNavigationClick=t=>e=>{e.stopPropagation(),t.expanded=!t.expanded,this.showChildContainer(t),this.debug&&Fm.debug("update => navClick"),this.update()},this.handleIconClick=(t,e)=>i=>{i.stopPropagation(),this.toggleIcon(t,e)},this.update=(t=null)=>{if(!this.container||!this.model)return;const e=this.getVisibleElements().filter(e=>e instanceof HTMLElement&&(null==t||(e.dataset.path||"").startsWith(t)));for(const t of e){const e=t.dataset.path||"",i=this.findNodeByPath(e);if(null!=i){if(i.rendered||(this.renderNode(i,t),i.rendered=!0),i.expanded){const n=t.querySelector(".tv-children");if(n instanceof HTMLElement&&0===n.children.length){for(const t in i.children){const e=i.children[t];this.renderPlaceholder(e,n)}this.showChildContainer(i),this.update(e)}}for(const e of ig){const n=t.dataset[`state${e}`],s=i.state[e];n!=String(s)&&this.updateIconInDOM(i,e)}this.showChildContainer(i)}else Fm.error(`Node not found: ${e}`)}},this.getDomNode=t=>{if(!this.container)return null;const e=this.container.querySelector(`[data-path="${t}"]`);return e instanceof HTMLElement?e:null},this.tree=t,this.scrollContainer=e,this.objectHandler=i,this.pickHandler=n,this.updateHandler=s,this.notificationHandler=r,this.colorGetter=a,this.theme=o,this.linkIcons=l,this.debug=h,this.model=null,this.container=null,this.lastLabel=null,this.lastScrollTop=0}create(){return this.model=new Jf(this.tree,{linkIcons:this.linkIcons,onStateChange:(t,e)=>this._handleStateChange(t,e)}),this.container=document.createElement("ul"),this.container.classList.add("tcv_toplevel"),this.scrollContainer.addEventListener("scroll",this.handleScroll),this.container}_handleStateChange(t,e){const i=0===e&&this.linkIcons?[0,1]:[e];for(const e of i)this.objectHandler(this.getNodePath(t),t.state[e],e,!0,!1)}get root(){return this.model?this.model.root:null}get maxLevel(){return this.model?this.model.maxLevel:0}getVisibleElements(){if(!this.container)return[];const t=this.container.querySelectorAll(".tv-tree-node"),e=this.scrollContainer.getBoundingClientRect(),i=Array.from(t).filter(t=>((t,e)=>{const i=t.getBoundingClientRect();return i.height>0&&i.top>=-12&&i.top<=e.bottom+12})(t,e));return this.debug&&this._logVisibleElements(i),i}_logVisibleElements(t){Fm.debug(`\nVisible elements (${t.length}):`);for(const e of t){if(!(e instanceof HTMLElement))continue;const t=this.findNodeByPath(e.dataset.path||"");t&&Fm.debug(t.path,t.state[0],t.state[1]," => ",e.dataset.state0,e.dataset.state1)}}handleLabelClick(t,e){const i=e instanceof MouseEvent;this.pickHandler(this.getNodePath(this.getParent(t)),t.name,!!i&&rf.get(e,"meta"),!!i&&rf.get(e,"shift"),!!i&&rf.get(e,"alt"),null,this.isLeaf(t)?"leaf":"node",!0),this.debug&&Fm.debug(`Label clicked: ${this.getNodePath(t)}`)}render(){this.container&&this.root&&(this.container.innerHTML="",this.renderPlaceholder(this.root,this.container),this.debug&&Fm.debug("update => render"),this.update())}renderPlaceholder(t,e,i=null){this.debug&&Fm.debug("renderPlaceholder",t.path,t.level);const n=document.createElement("div");n.className="tv-tree-node",n.dataset.path=this.getNodePath(t),n.dataset.openPath=i||"",n.dataset.state0=String(t.state[0]),n.dataset.state1=String(t.state[1]);const s=document.createElement("div");s.className="tv-node-content",this.debug&&(s.innerText=t.path),n.appendChild(s),e.appendChild(n)}renderNode(t,e){this.debug&&Fm.debug("renderNode",t.path,t.level);const i=document.createElement("div");i.className="tv-node-content",e.removeChild(e.firstChild),e.appendChild(i);const n=document.createElement("span");n.className="tv-nav-marker",n.innerHTML=t.children?t.expanded?$f:tg:"",n.onclick=this.handleNavigationClick(t),i.dataset.state0=String(t.state[0]),i.dataset.state1=String(t.state[1]),i.appendChild(n);for(const e of ig){const n=document.createElement("span"),s=t.state[e];let r=`tv-icon tv-icon${e}`;s!==qf&&(r+=" tv-pointer"),n.className=r,n.classList.add("tcv_tree_button"),n.classList.add(`tcv_button_${eg[e][s]}`),s!==qf&&(n.onmousedown=t=>{t.preventDefault()},n.onclick=this.handleIconClick(t,e)),i.appendChild(n)}const s=document.createElement("span");s.className="tv-node-label",s.innerHTML=t.name;const r=this.colorGetter(t.path);null!=r&&(s.innerHTML+=`<span style="color:${r}"> ⚈</span>`),s.onmousedown=t=>{t.preventDefault()},s.oncontextmenu=e=>{e.preventDefault(),e.stopPropagation(),this.handleLabelClick(t,e)},s.onclick=e=>{e.stopPropagation(),this.handleLabelClick(t,e)},i.appendChild(s);let a=null;return t.children&&(a=document.createElement("div"),a.className="tv-children",a.style.display="none",e.appendChild(a)),a}showChildContainer(t){if(null==t.expanded)return;const e=this.getNodePath(t),i=this.getDomNode(e);if(i){const e=i.querySelector(".tv-children");if(e instanceof HTMLElement){if("none"!==e.style.display!==t.expanded){e.style.display=t.expanded?"block":"none";const n=i.querySelector(".tv-nav-marker");n&&(n.innerHTML=t.expanded?$f:tg),t.expanded||(this.debug&&Fm.debug("update => showChildContainer"),this.update())}}}else Fm.error(`Element not found: ${e}`)}updateIconInDOM(t,e){if(!this.container)return;const i=this.getNodePath(t),n=this.container.querySelector(`[data-path="${i}"]`);if(n instanceof HTMLElement){const i=n.querySelector(`.tv-icon${e}`);if(i){for(const t of eg[e])i.classList.remove(`tcv_button_${t}`);i.classList.add(`tcv_button_${eg[e][t.state[e]]}`)}n.dataset[`state${e}`]=String(t.state[e])}}toggleLabelColor(t,e=null){if(!this.container)return;const i=null==e&&t?this.getNodePath(t):e;if(!i)return;const n=this.container.querySelector(`[data-path="${i}"]`);if(this.lastLabel&&this.lastLabel.classList.remove("tv-node-label-highlight"),n){const t=n.querySelector(".tv-node-label");t instanceof HTMLElement&&(this.lastLabel===t?this.lastLabel=null:(t.classList.toggle("tv-node-label-highlight"),this.lastLabel=t))}}traverse(t,e){this.model&&this.model.traverse(t,e)}isLeaf(t){return!this.model||this.model.isLeaf(t)}getNodePath(t){return this.model?this.model.getNodePath(t):""}findNodeByPath(t){return this.model?this.model.findNodeByPath(t):null}getParent(t){return this.model?this.model.getParent(t):null}toggleIcon(t,e,i=null){if(!this.model)return;this.model.toggleNodeState(t,e,i)&&(this.update(),this.updateHandler(!0),this.notificationHandler())}hideAll(){this.model&&(this.model.hideAll(),this.update(),this.updateHandler(!0),this.notificationHandler())}showAll(){this.model&&(this.model.showAll(),this.update(),this.updateHandler(!0),this.notificationHandler())}show(t){this.model&&(this.model.show(t),this.update(),this.updateHandler(!0),this.notificationHandler())}hide(t){this.model&&(this.model.hide(t),this.update(),this.updateHandler(!0),this.notificationHandler())}getState(t){return this.model?this.model.getState(t):null}getStates(){return this.model?this.model.getStates():{}}setState(t,e){this.model&&(this.model.setState(t,e),this.update(),this.updateHandler(!0),this.notificationHandler())}setStates(t){this.model&&(this.model.setStates(t),this.update(),this.updateHandler(!0),this.notificationHandler())}scrollCentered(t){if(null!=t){const e=this.scrollContainer,i=t.offsetHeight,n=e.clientHeight,s=t.offsetTop-e.offsetTop-n/2+i/2,r=e.scrollHeight-n,a=Math.max(0,Math.min(s,r));e.scrollTo({top:a,behavior:"smooth"})}}_ensureNodeRendered(t){const e=this.getNodePath(t);let i=this.getDomNode(e);if(!i){const n=this.getParent(t);n&&(this._ensureNodeRendered(n),i=this.getDomNode(e))}if(!i){const n=this.getParent(t);if(n){const s=this.getDomNode(this.getNodePath(n));if(s){let r=s.querySelector(".tv-children");!r&&n.children&&(n.rendered||(this.renderNode(n,s),n.rendered=!0),r=s.querySelector(".tv-children")),r instanceof HTMLElement&&(this.renderPlaceholder(t,r),i=this.getDomNode(e))}}}if(i&&!t.rendered&&(this.renderNode(t,i),t.rendered=!0),i&&t.expanded&&t.children){const e=i.querySelector(".tv-children");if(e instanceof HTMLElement){if(0===e.children.length)for(const i in t.children)this.renderPlaceholder(t.children[i],e);e.style.display="block"}}return i}openPath(t){const e=t.split("/").filter(Boolean);let i="",n=null,s=null;for(const t of e){if(i+="/"+t,n=this.findNodeByPath(i),!n){Fm.error(`Path not found: ${i}`);break}if(n.children&&(n.expanded=!0),s=this._ensureNodeRendered(n),s){const t=s.querySelector(".tv-nav-marker");t&&n.children&&(t.innerHTML=$f)}this.debug&&Fm.debug("update => openPath",i)}this.update(),this.scrollCentered(s),n&&this.toggleLabelColor(n)}closePath(t){const e=this.findNodeByPath(t);if(e){e.expanded=!1,this.showChildContainer(e);const i=this.getDomNode(t);null!=i&&(this.scrollContainer.scrollTop=i.offsetTop-this.scrollContainer.offsetTop),this.debug&&Fm.debug("update => collapsePath"),this.update()}else Fm.error(`Path not found: ${t}`)}openLevel(t){if(!this.model||!this.root)return;this.model.setExpandedLevel(t);const e=this.getDomNode(this.getNodePath(this.root));null!=e&&(this.scrollContainer.scrollTop=e.offsetTop-this.scrollContainer.offsetTop);const i=-1===t?this.maxLevel:t;for(let t=0;t<=i;t++)this.debug&&Fm.debug("update => openLevel",t),this.update()}collapseAll(){this.openLevel(0)}expandAll(){this.openLevel(this.maxLevel)}dispose(){this.model&&(this.model.dispose(),this.model=null),this.tree=null,this.container=null,this.lastLabel=null,this.scrollContainer.removeEventListener("scroll",this.handleScroll)}}let sg=class{constructor(t,e){this.prefix=t,this.timeit=e,this.start=performance.now(),this.last=this.start,e&&console.info(`three-cad-viewer: ${t}:timer start`)}split(t){if(this.timeit){const e=performance.now();console.info(`three-cad-viewer: ${this.prefix}:${t}:timer split ${(e-this.last).toFixed(1)} ms`),this.last=e}}stop(){if(this.timeit){const t=performance.now();console.info(`three-cad-viewer: ${this.prefix}:timer stop ${(t-this.start).toFixed(1)} ms:`)}}};const rg=[new xi(-1,0,0),new xi(0,-1,0),new xi(0,0,-1)],ag={light:[16711680,65280,255],dark:[16729344,3329330,3907327]},og={light:.1,dark:.2};class lg{static createPlaneHelperMaterial(t){return new lr({opacity:og[t]||.1,transparent:!0,depthWrite:!1,toneMapped:!1,side:2})}static createBackStencilMaterial(){return new lr({depthWrite:!1,depthTest:!1,colorWrite:!1,side:1,stencilWrite:!0,stencilFunc:Be,stencilFail:Ie,stencilZFail:Ie,stencilZPass:Ie})}static createFrontStencilMaterial(){return new lr({depthWrite:!1,depthTest:!1,colorWrite:!1,side:0,stencilWrite:!0,stencilFunc:Be,stencilFail:Le,stencilZFail:Le,stencilZPass:Le})}static createStencilPlaneMaterial(t,e){return new Pl({color:new En(t),metalness:.3,roughness:.65,opacity:1,transparent:!1,side:2,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1,stencilWrite:!0,stencilRef:0,stencilFunc:517,stencilFail:Pe,stencilZFail:Pe,stencilZPass:Pe,clippingPlanes:e})}}class hg extends qr{constructor(t,e,i){super(t,e),this.center=i,this.centeredConstant=e,this.setConstant(e)}setConstant(t){this.centeredConstant=t;const e=this.distanceToPoint(new xi(...this.center)),i=this.distanceToPoint(new xi(0,0,0));this.constant=i-e+t}clone(){return new hg(this.normal.clone(),this.centeredConstant,[...this.center])}}class cg extends _n{}class dg extends xr{constructor(t,e,i,n,s,r,a){const o=new pl(2,2);o.computeBoundingSphere(),s.color.set(new En(r)),super(o,s),this.onAfterRender=t=>{this.type.startsWith("StencilPlane")&&t.clearStencil()},this.type=a,this.index=t,this.plane=e,this.size=n,this.center=i}updateMatrixWorld(t){this.position.set(0,0,0),this.scale.set(.5*this.size,.5*this.size,1),dg.matrix.lookAt(this.position,this.plane.normal,this.up),this.quaternion.setFromRotationMatrix(dg.matrix),this.translateZ(this.plane.constant),super.updateMatrixWorld(t)}}function ug(t,e,i,n){e.clippingPlanes=[n];const s=new xr(i,e);return s.name=t,s}dg.matrix=new Wi;class pg extends _n{constructor(t,e,i,n,s){super(),this.setNormal=(t,e)=>{const i=e.clone();this.clipPlanes[t].normal=i,this.reverseClipPlanes[t].normal=i.clone().negate(),this.setConstant(t,this.distance),this.onNormalChange&&this.onNormalChange(t,Vm(i.toArray()))},this.getObjectColorCaps=()=>this.objectColorCaps,this.setObjectColorCaps=t=>{if(!this._planeMeshGroup)return;let e=0,i=-1;const n=this._planeMeshGroup.children.length/3;for(const s of this._planeMeshGroup.children){e%n===0&&i++;const r=t?this.objectColors[e]:ag[this.theme][i];s.material.color.set(new En(r)),e++}this.objectColorCaps=t},this.setVisible=t=>{if(this._planeMeshGroup)for(const e of this._planeMeshGroup.children)e.material.visible=t},this.center=t,this.distance=e/2,this.onNormalChange=n.onNormalChange||null,this.theme=s,this.nestedGroup=i,this.size=e,this.clipPlanes=[],this.reverseClipPlanes=[],this.objectColors=[],this.objectColorCaps=!1,this._planeMeshGroup=null,this.name="PlaneHelpers",this._createClipPlanes(t),this._createPlaneHelpers(t,e,s),this._createStencils(t,e,s)}_createClipPlanes(t){for(const e of Sf){const i=new hg(rg[e],this.distance,t);this.clipPlanes.push(i);const n=new hg(rg[e].clone().negate(),-this.distance,t);this.reverseClipPlanes.push(n),this.onNormalChange&&this.onNormalChange(e,Vm(rg[e].toArray()))}}_createPlaneHelpers(t,e,i){this.planeHelpers=new cg,this.planeHelpers.name="PlaneHelpers";for(let n=0;n<3;n++){const s=lg.createPlaneHelperMaterial(i);this.planeHelpers.add(new dg(n,this.clipPlanes[n],t,e,s,ag[i][n],"PlaneHelper"))}for(let t=0;t<3;t++){const e=this.clipPlanes.filter((e,i)=>i!==t);this.planeHelpers.children[t].material.clippingPlanes=e}this.planeHelpers.visible=!1,this.add(this.planeHelpers)}_createStencils(t,e,i){this._planeMeshGroup=new cg,this._planeMeshGroup.name="PlaneMeshes";for(let n=0;n<3;n++){const s=this.clipPlanes[n],r=this.clipPlanes.filter((t,e)=>e!==n);let a=0;for(const o in this.nestedGroup.groups){const l=this.nestedGroup.groups[o];if(l instanceof of&&"solid"===l.subtype&&l.front){const o=l.front.material;this.objectColors.push(o.color.getHex());const h=new _n;h.name=`clipping-${n}`,h.add(ug(`frontStencil-${n}-${a}`,lg.createFrontStencilMaterial(),l.shapeGeometry,s)),h.add(ug(`backStencil-${n}-${a}`,lg.createBackStencilMaterial(),l.shapeGeometry,s)),l.addClipping(h,n);const c=lg.createStencilPlaneMaterial(ag[i][n],r);this._planeMeshGroup.add(new dg(n,s,t,e,c,ag[i][n],`StencilPlane-${n}-${a}`)),a++}}}this.nestedGroup.rootGroup.add(this._planeMeshGroup)}rebuildStencils(t,e){for(const t in this.nestedGroup.groups){const e=this.nestedGroup.groups[t];e instanceof of&&e.clearClipping()}this._planeMeshGroup&&this.nestedGroup.rootGroup&&(this.nestedGroup.rootGroup.remove(this._planeMeshGroup),Qm(this._planeMeshGroup),this._planeMeshGroup=null),this.objectColors=[],this.center=t,this.size=e,this.distance=e/2,this._createStencils(t,e,this.theme),this.objectColorCaps&&this.setObjectColorCaps(!0)}setConstant(t,e){this.clipPlanes[t].setConstant(e),this.reverseClipPlanes[t].setConstant(-e)}saveState(){return{planeConstants:[this.clipPlanes[0].centeredConstant,this.clipPlanes[1].centeredConstant,this.clipPlanes[2].centeredConstant],helperVisible:this.planeHelpers?.visible??!1,planesVisible:!!this._planeMeshGroup?.children.length&&this._planeMeshGroup.children[0].material.visible}}restoreState(t){for(const e of Sf)this.setConstant(e,t.planeConstants[e]);this.planeHelpers&&(this.planeHelpers.visible=t.helperVisible),this.setVisible(t.planesVisible)}dispose(){this.onNormalChange=null,this.center=null,this.planeHelpers=null,this._planeMeshGroup=null}}class mg{constructor(t){this.delim=t,this.tracks=[],this.mixer=null,this.clip=null,this.clipAction=null,this.clock=new Bc,this.duration=null,this._backup=null,this.root=null,this.speed=null,this.repeat=null}_prepareSelector(t){return t.replaceAll("/",this.delim)}_validateArrayLengths(t,e){return t.length===e.length||(Fm.error("times and values arrays need to have the same length"),!1)}addPositionTrack(t,e,i,n){if(!this._validateArrayLengths(i,n))return;const s=e.position,r=n.map(t=>s.clone().add(new xi(...t)).toArray());this.tracks.push(new nh(this._prepareSelector(t)+".position",i,r.flat()))}addTranslationTrack(t,e,i,n,s){if(!this._validateArrayLengths(n,s))return;const r=e.position,a={x:t=>new xi(t,0,0),y:t=>new xi(0,t,0),z:t=>new xi(0,0,t)},o=s.map(t=>r.clone().add(a[i](t)).toArray());this.tracks.push(new nh(this._prepareSelector(t)+".position",n,o.flat()))}addQuaternionTrack(t,e,i,n){if(!this._validateArrayLengths(i,n))return;const s=e.quaternion,r=n.map(t=>s.clone().multiply(new _i(...t)).toArray());this.tracks.push(new eh(this._prepareSelector(t)+".quaternion",i,r.flat()))}addRotationTrack(t,e,i,n,s){if(!this._validateArrayLengths(n,s))return;const r=e.quaternion,a=s.map(t=>r.clone().multiply(function(t,e){const i=new _i;return i.setFromAxisAngle(Gm[t],e/180*Math.PI),i}(i,t)).toArray());this.tracks.push(new eh(this._prepareSelector(t)+".quaternion",n,a.flat()))}backup(){this._backup={tracks:this.tracks,root:this.root,duration:this.duration,speed:this.speed,repeat:this.repeat}}restore(){return null===this._backup?{duration:null,speed:null,repeat:null}:(this.tracks=this._backup.tracks,{duration:this._backup.duration,speed:this._backup.speed,repeat:this._backup.repeat})}cleanBackup(){this._backup=null}hasTracks(){return null!=this.tracks&&this.tracks.length>0}hasBackup(){return null!==this._backup}animate(t,e,i,n=!0){return this.root=t,this.duration=e,this.speed=i,this.repeat=n,this.clip=new sh("track",e,this.tracks),this.mixer=new Ec(t),this.mixer.timeScale=i,this.clipAction=this.mixer.clipAction(this.clip),this.clipAction.setLoop(n?pe:me,1/0),this.clipAction}setRelativeTime(t){if(!this.clipAction||!this.duration)return;this.clipAction.play(),this.clipAction.paused=!0;const e=this.duration*t;this.clipAction.time=e}getRelativeTime(){return this.clipAction&&this.duration?this.clipAction.time/this.duration:0}dispose(){this.mixer&&(this.mixer.stopAllAction(),this.clip&&this.mixer.uncacheClip(this.clip),this.root&&this.mixer.uncacheRoot(this.root)),this.mixer=null,this.clipAction=null,this.clip=null,this.tracks=[],this.root=null}update(){this.mixer&&(this.clock.update(),this.mixer.update(this.clock.getDelta()))}}function fg(t){return"string"==typeof t?t.startsWith("#")?t:`#${t}`:`#${t.toString(16).padStart(6,"0")}`}class gg{constructor(t){this._bbox=null,this.config=t}get bbox(){return this._bbox}updateConfig(t){this.config={...this.config,...t}}_renderTessellatedShapes(t){const e=new Nf(t,this.config.cadWidth,this.config.height,this.config.edgeColor,this.config.transparent,this.config.defaultOpacity,this.config.metalness,this.config.roughness,this.config.normalLen);return t.bb&&(this._bbox=new hf(new xi(t.bb.xmin,t.bb.ymin,t.bb.zmin),new xi(t.bb.xmax,t.bb.ymax,t.bb.zmax))),e.render(),e}_getTree(t){const e=t=>{const i={};for(const n of t)null!=n.parts?i[n.name]=e(n.parts):i[n.name]=n.state;return i},i={};return i[t.name]=e(t.parts??[]),i}_decompose(t){const e=t.shape;let i;if(t.parts=[],"shapes"===t.type){const n={version:2,name:"faces",id:`${t.id}/faces`,parts:[],loc:[[0,0,0],[0,0,0,1]]};let s;if(!(e.vertices instanceof Float32Array))throw new Error("_decompose requires shape.vertices to be Float32Array (call _convertArrays first)");if(!(e.normals instanceof Float32Array))throw new Error("_decompose requires shape.normals to be Float32Array (call _convertArrays first)");const r=e.vertices,a=e.normals,o=e.uvs instanceof Float32Array?e.uvs:null;let l=0;if(Ef(e)){if(!(e.triangles instanceof Uint32Array))throw new Error("Expected Uint32Array for triangles in binary format");const h=e.triangles,c=e.triangles_per_face,d=c.length;for(i=0;i<d;i++){s=h.subarray(l,l+3*c[i]),l+=3*c[i];const d=new Float32Array(3*s.length),u=new Float32Array(3*s.length),p=o?new Float32Array(2*s.length):null;for(let t=0;t<s.length;t++){const e=s[t];d[3*t]=r[3*e],d[3*t+1]=r[3*e+1],d[3*t+2]=r[3*e+2],u[3*t]=a[3*e],u[3*t+1]=a[3*e+1],u[3*t+2]=a[3*e+2],o&&p&&(p[2*t]=o[2*e],p[2*t+1]=o[2*e+1])}const m={triangles:[...Array(s.length).keys()],vertices:Array.from(d),normals:Array.from(u),edges:[],obj_vertices:[],edge_types:[],face_types:[e.face_types[i]]};p&&(m.uvs=Array.from(p));const f={version:2,loc:[[0,0,0],[0,0,0,1]],name:`faces_${i}`,id:`${t.id}/faces/faces_${i}`,type:"shapes",color:t.color,alpha:t.alpha,renderback:"solid"!==t.subtype,state:[1,3],accuracy:t.accuracy,bb:null,shape:m};t.texture&&(f.texture=t.texture),t.material&&(f.material=t.material),f.geomtype=e.face_types[i],f.subtype=t.subtype,f.exploded=!0,n.parts.push(f)}}else{if(!Array.isArray(e.triangles)||!Array.isArray(e.triangles[0]))throw new Error("Expected nested array for triangles in non-binary format");const l=e.triangles,h=l.length;for(i=0;i<h;i++){s=l[i];const h=new Float32Array(3*s.length),c=new Float32Array(3*s.length),d=o?new Float32Array(2*s.length):null;for(let t=0;t<s.length;t++){const e=s[t];h[3*t]=r[3*e],h[3*t+1]=r[3*e+1],h[3*t+2]=r[3*e+2],c[3*t]=a[3*e],c[3*t+1]=a[3*e+1],c[3*t+2]=a[3*e+2],o&&d&&(d[2*t]=o[2*e],d[2*t+1]=o[2*e+1])}const u={triangles:[...Array(s.length).keys()],vertices:Array.from(h),normals:Array.from(c),edges:[],obj_vertices:[],edge_types:[],face_types:[e.face_types[i]]};d&&(u.uvs=Array.from(d));const p={version:2,loc:[[0,0,0],[0,0,0,1]],name:`faces_${i}`,id:`${t.id}/faces/faces_${i}`,type:"shapes",color:t.color,alpha:t.alpha,renderback:"solid"!==t.subtype,state:[1,3],accuracy:t.accuracy,bb:null,shape:u};t.texture&&(p.texture=t.texture),t.material&&(p.material=t.material),p.geomtype=e.face_types[i],p.subtype=t.subtype,p.exploded=!0,n.parts.push(p)}}t.parts.push(n)}if("shapes"===t.type||"edges"===t.type){const n={version:2,parts:[],loc:[[0,0,0],[0,0,0,1]],name:"edges",id:`${t.id}/edges`},s=Array.isArray(t.color)?t.color:null;let r,a,o=0;if(Tf(e)){if(!(e.edges instanceof Float32Array))throw new Error("Expected Float32Array for edges in binary format");const l=e.edges,h=e.segments_per_edge,c=h.length;for(i=0;i<c;i++){a=l.subarray(o,o+6*h[i]),o+=6*h[i],r=s?s[i]:t.color;const c={version:2,loc:[[0,0,0],[0,0,0,1]],name:`edges_${i}`,id:`${t.id}/edges/edges_${i}`,type:"edges",color:"shapes"===t.type?fg(this.config.edgeColor):r,state:[3,1],bb:null,shape:{edges:Array.from(a),vertices:[],normals:[],triangles:[],obj_vertices:[],edge_types:[e.edge_types[i]],face_types:[]}};c.width="shapes"===t.type?1:t.width,c.geomtype=e.edge_types[i],n.parts.push(c)}}else{const o=e.edges;if(!Array.isArray(o)||o.length>0&&!Array.isArray(o[0]))throw new Error("Expected nested array for edges in non-binary format");const l=o,h=l.length;for(i=0;i<h;i++){a=l[i],r=s?s[i]:t.color;const o={version:2,loc:[[0,0,0],[0,0,0,1]],name:`edges_${i}`,id:`${t.id}/edges/edges_${i}`,type:"edges",color:"shapes"===t.type?fg(this.config.edgeColor):r,state:[3,1],bb:null,shape:{edges:a,vertices:[],normals:[],triangles:[],obj_vertices:[],edge_types:[e.edge_types[i]],face_types:[]}};o.width="shapes"===t.type?1:t.width,o.geomtype=e.edge_types[i],n.parts.push(o)}}n.parts.length>0&&t.parts.push(n)}const n={version:2,parts:[],loc:[[0,0,0],[0,0,0,1]],name:"vertices",id:`${t.id}/vertices`},s=e.obj_vertices;for(i=0;i<s.length/3;i++){const e={version:2,loc:[[0,0,0],[0,0,0,1]],name:`vertices_${i}`,id:`${t.id}/vertices/vertices_${i}`,type:"vertices",color:"shapes"===t.type||"edges"===t.type?fg(this.config.edgeColor):t.color,state:[3,1],bb:null,shape:{obj_vertices:[s[3*i],s[3*i+1],s[3*i+2]],vertices:[],normals:[],triangles:[],edges:[],edge_types:[],face_types:[]}};e.size="shapes"===t.type||"edges"===t.type?4:t.size,n.parts.push(e)}return n.parts.length>0&&t.parts.push(n),delete t.shape,delete t.color,delete t.alpha,delete t.accuracy,delete t.renderback,t}_convertArrays(t){const e=t;null==e.triangles||e.triangles instanceof Uint32Array||void 0!==e.triangles_per_face&&(Array.isArray(e.triangles[0])||(e.triangles=new Uint32Array(e.triangles))),null==e.edges||e.edges instanceof Float32Array||void 0!==e.segments_per_edge&&(Array.isArray(e.edges[0])?e.edges=new Float32Array(Hm(e.edges,1)):e.edges=new Float32Array(e.edges)),null==e.vertices||e.vertices instanceof Float32Array||(e.vertices=new Float32Array(e.vertices)),null==e.normals||e.normals instanceof Float32Array||Array.isArray(e.normals)&&e.normals.length>0&&(Array.isArray(e.normals[0])?e.normals=new Float32Array(Hm(e.normals,2)):e.normals=new Float32Array(e.normals)),null==e.obj_vertices||e.obj_vertices instanceof Float32Array||(e.obj_vertices=new Float32Array(e.obj_vertices)),null==e.uvs||e.uvs instanceof Float32Array||(e.uvs=new Float32Array(e.uvs)),null==e.face_types||e.face_types instanceof Uint32Array||(e.face_types=new Uint32Array(e.face_types)),null==e.edge_types||e.edge_types instanceof Uint32Array||(e.edge_types,Uint8Array,e.edge_types=new Uint32Array(e.edge_types)),null==e.triangles_per_face||e.triangles_per_face instanceof Uint32Array||(e.triangles_per_face=new Uint32Array(e.triangles_per_face)),null==e.segments_per_edge||e.segments_per_edge instanceof Uint32Array||(e.segments_per_edge=new Uint32Array(e.segments_per_edge))}_processShapes(t){if(2===t.version||3===t.version){const e=[];for(let i=0;i<(t.parts?.length??0);i++){const n=t.parts[i];if(null!=n.shape&&this._convertArrays(n.shape),null!=n.parts){const t=this._processShapes(n);e.push(t)}else e.push(this._decompose(n))}t.parts=e}return t}render(t,e){let i;i=t?this._processShapes(structuredClone(e)):structuredClone(e);return{group:this._renderTessellatedShapes(i),tree:this._getTree(i)}}}const vg={type:"change"},yg={type:"start"},_g={type:"end"},xg=new or,bg=new qr,Sg=Math.cos(70*vi.DEG2RAD),Mg=new xi,wg=2*Math.PI,Ag=-1,Eg=0,Tg=1,Cg=2,Dg=3,Rg=4,Pg=5,Ig=6,Lg=1e-6;class Bg extends ud{constructor(t,e=null){super(t,e),this.state=Ag,this.target=new xi,this.cursor=new xi,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:i.ROTATE,MIDDLE:i.DOLLY,RIGHT:i.PAN},this.touches={ONE:n.ROTATE,TWO:n.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle="auto",this._domElementKeyEvents=null,this._lastPosition=new xi,this._lastQuaternion=new _i,this._lastTargetPosition=new xi,this._quat=(new _i).setFromUnitVectors(t.up,new xi(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new Fc,this._sphericalDelta=new Fc,this._scale=1,this._panOffset=new xi,this._rotateStart=new yi,this._rotateEnd=new yi,this._rotateDelta=new yi,this._panStart=new yi,this._panEnd=new yi,this._panDelta=new yi,this._dollyStart=new yi,this._dollyEnd=new yi,this._dollyDelta=new yi,this._dollyDirection=new xi,this._mouse=new yi,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=Fg.bind(this),this._onPointerDown=Og.bind(this),this._onPointerUp=Ng.bind(this),this._onContextMenu=Wg.bind(this),this._onMouseWheel=zg.bind(this),this._onKeyDown=Gg.bind(this),this._onTouchStart=Hg.bind(this),this._onTouchMove=Vg.bind(this),this._onMouseDown=Ug.bind(this),this._onMouseMove=kg.bind(this),this._interceptControlDown=jg.bind(this),this._interceptControlUp=Xg.bind(this),null!==this.domElement&&this.connect(this.domElement),this.update()}set cursorStyle(t){this._cursorStyle=t,this.domElement.style.cursor="grab"===t?"grab":"auto"}get cursorStyle(){return this._cursorStyle}connect(t){super.connect(t),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1});this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents();this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(t){t.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=t}stopListenToKeyEvents(){null!==this._domElementKeyEvents&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(vg),this.update(),this.state=Ag}pan(t,e){this._pan(t,e),this.update()}dollyIn(t){this._dollyIn(t),this.update()}dollyOut(t){this._dollyOut(t),this.update()}rotateLeft(t){this._rotateLeft(t),this.update()}rotateUp(t){this._rotateUp(t),this.update()}update(t=null){const e=this.object.position;Mg.copy(e).sub(this.target),Mg.applyQuaternion(this._quat),this._spherical.setFromVector3(Mg),this.autoRotate&&this.state===Ag&&this._rotateLeft(this._getAutoRotationAngle(t)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let i=this.minAzimuthAngle,n=this.maxAzimuthAngle;isFinite(i)&&isFinite(n)&&(i<-Math.PI?i+=wg:i>Math.PI&&(i-=wg),n<-Math.PI?n+=wg:n>Math.PI&&(n-=wg),this._spherical.theta=i<=n?Math.max(i,Math.min(n,this._spherical.theta)):this._spherical.theta>(i+n)/2?Math.max(i,this._spherical.theta):Math.min(n,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),!0===this.enableDamping?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let s=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const t=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),s=t!=this._spherical.radius}if(Mg.setFromSpherical(this._spherical),Mg.applyQuaternion(this._quatInverse),e.copy(this.target).add(Mg),this.object.lookAt(this.target),!0===this.enableDamping?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let t=null;if(this.object.isPerspectiveCamera){const e=Mg.length();t=this._clampDistance(e*this._scale);const i=e-t;this.object.position.addScaledVector(this._dollyDirection,i),this.object.updateMatrixWorld(),s=!!i}else if(this.object.isOrthographicCamera){const e=new xi(this._mouse.x,this._mouse.y,0);e.unproject(this.object);const i=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),s=i!==this.object.zoom;const n=new xi(this._mouse.x,this._mouse.y,0);n.unproject(this.object),this.object.position.sub(n).add(e),this.object.updateMatrixWorld(),t=Mg.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;null!==t&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(t).add(this.object.position):(xg.origin.copy(this.object.position),xg.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(xg.direction))<Sg?this.object.lookAt(this.target):(bg.setFromNormalAndCoplanarPoint(this.object.up,this.target),xg.intersectPlane(bg,this.target))))}else if(this.object.isOrthographicCamera){const t=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),t!==this.object.zoom&&(this.object.updateProjectionMatrix(),s=!0)}return this._scale=1,this._performCursorZoom=!1,!!(s||this._lastPosition.distanceToSquared(this.object.position)>Lg||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Lg||this._lastTargetPosition.distanceToSquared(this.target)>Lg)&&(this.dispatchEvent(vg),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0)}_getAutoRotationAngle(t){return null!==t?wg/60*this.autoRotateSpeed*t:wg/60/60*this.autoRotateSpeed}_getZoomScale(t){const e=Math.abs(.01*t);return Math.pow(.95,this.zoomSpeed*e)}_rotateLeft(t){this._sphericalDelta.theta-=t}_rotateUp(t){this._sphericalDelta.phi-=t}_panLeft(t,e){Mg.setFromMatrixColumn(e,0),Mg.multiplyScalar(-t),this._panOffset.add(Mg)}_panUp(t,e){!0===this.screenSpacePanning?Mg.setFromMatrixColumn(e,1):(Mg.setFromMatrixColumn(e,0),Mg.crossVectors(this.object.up,Mg)),Mg.multiplyScalar(t),this._panOffset.add(Mg)}_pan(t,e){const i=this.domElement;if(this.object.isPerspectiveCamera){const n=this.object.position;Mg.copy(n).sub(this.target);let s=Mg.length();s*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*t*s/i.clientHeight,this.object.matrix),this._panUp(2*e*s/i.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(t*(this.object.right-this.object.left)/this.object.zoom/i.clientWidth,this.object.matrix),this._panUp(e*(this.object.top-this.object.bottom)/this.object.zoom/i.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(t,e){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const i=this.domElement.getBoundingClientRect(),n=t-i.left,s=e-i.top,r=i.width,a=i.height;this._mouse.x=n/r*2-1,this._mouse.y=-s/a*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(t){return Math.max(this.minDistance,Math.min(this.maxDistance,t))}_handleMouseDownRotate(t){this._rotateStart.set(t.clientX,t.clientY)}_handleMouseDownDolly(t){this._updateZoomParameters(t.clientX,t.clientX),this._dollyStart.set(t.clientX,t.clientY)}_handleMouseDownPan(t){this._panStart.set(t.clientX,t.clientY)}_handleMouseMoveRotate(t){this._rotateEnd.set(t.clientX,t.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(wg*this._rotateDelta.x/e.clientHeight),this._rotateUp(wg*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(t){this._dollyEnd.set(t.clientX,t.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(t){this._panEnd.set(t.clientX,t.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(t){this._updateZoomParameters(t.clientX,t.clientY),t.deltaY<0?this._dollyIn(this._getZoomScale(t.deltaY)):t.deltaY>0&&this._dollyOut(this._getZoomScale(t.deltaY)),this.update()}_handleKeyDown(t){let e=!1;switch(t.code){case this.keys.UP:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateUp(wg*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),e=!0;break;case this.keys.BOTTOM:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateUp(-wg*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),e=!0;break;case this.keys.LEFT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateLeft(wg*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),e=!0;break;case this.keys.RIGHT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateLeft(-wg*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),e=!0}e&&(t.preventDefault(),this.update())}_handleTouchStartRotate(t){if(1===this._pointers.length)this._rotateStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),i=.5*(t.pageX+e.x),n=.5*(t.pageY+e.y);this._rotateStart.set(i,n)}}_handleTouchStartPan(t){if(1===this._pointers.length)this._panStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),i=.5*(t.pageX+e.x),n=.5*(t.pageY+e.y);this._panStart.set(i,n)}}_handleTouchStartDolly(t){const e=this._getSecondPointerPosition(t),i=t.pageX-e.x,n=t.pageY-e.y,s=Math.sqrt(i*i+n*n);this._dollyStart.set(0,s)}_handleTouchStartDollyPan(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enablePan&&this._handleTouchStartPan(t)}_handleTouchStartDollyRotate(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enableRotate&&this._handleTouchStartRotate(t)}_handleTouchMoveRotate(t){if(1==this._pointers.length)this._rotateEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),i=.5*(t.pageX+e.x),n=.5*(t.pageY+e.y);this._rotateEnd.set(i,n)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(wg*this._rotateDelta.x/e.clientHeight),this._rotateUp(wg*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(t){if(1===this._pointers.length)this._panEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),i=.5*(t.pageX+e.x),n=.5*(t.pageY+e.y);this._panEnd.set(i,n)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(t){const e=this._getSecondPointerPosition(t),i=t.pageX-e.x,n=t.pageY-e.y,s=Math.sqrt(i*i+n*n);this._dollyEnd.set(0,s),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const r=.5*(t.pageX+e.x),a=.5*(t.pageY+e.y);this._updateZoomParameters(r,a)}_handleTouchMoveDollyPan(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enablePan&&this._handleTouchMovePan(t)}_handleTouchMoveDollyRotate(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enableRotate&&this._handleTouchMoveRotate(t)}_addPointer(t){this._pointers.push(t.pointerId)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId)return void this._pointers.splice(e,1)}_isTrackingPointer(t){for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId)return!0;return!1}_trackPointer(t){let e=this._pointerPositions[t.pointerId];void 0===e&&(e=new yi,this._pointerPositions[t.pointerId]=e),e.set(t.pageX,t.pageY)}_getSecondPointerPosition(t){const e=t.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[e]}_customWheelEvent(t){const e=t.deltaMode,i={clientX:t.clientX,clientY:t.clientY,deltaY:t.deltaY};switch(e){case 1:i.deltaY*=16;break;case 2:i.deltaY*=100}return t.ctrlKey&&!this._controlActive&&(i.deltaY*=10),i}}function Og(t){!1!==this.enabled&&(0===this._pointers.length&&(this.domElement.setPointerCapture(t.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),this._isTrackingPointer(t)||(this._addPointer(t),"touch"===t.pointerType?this._onTouchStart(t):this._onMouseDown(t),"grab"===this._cursorStyle&&(this.domElement.style.cursor="grabbing")))}function Fg(t){!1!==this.enabled&&("touch"===t.pointerType?this._onTouchMove(t):this._onMouseMove(t))}function Ng(t){switch(this._removePointer(t),this._pointers.length){case 0:this.domElement.releasePointerCapture(t.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(_g),this.state=Ag,"grab"===this._cursorStyle&&(this.domElement.style.cursor="grab");break;case 1:const e=this._pointers[0],i=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:i.x,pageY:i.y})}}function Ug(t){let e;switch(t.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case i.DOLLY:if(!1===this.enableZoom)return;this._handleMouseDownDolly(t),this.state=Tg;break;case i.ROTATE:if(t.ctrlKey||t.metaKey||t.shiftKey){if(!1===this.enablePan)return;this._handleMouseDownPan(t),this.state=Cg}else{if(!1===this.enableRotate)return;this._handleMouseDownRotate(t),this.state=Eg}break;case i.PAN:if(t.ctrlKey||t.metaKey||t.shiftKey){if(!1===this.enableRotate)return;this._handleMouseDownRotate(t),this.state=Eg}else{if(!1===this.enablePan)return;this._handleMouseDownPan(t),this.state=Cg}break;default:this.state=Ag}this.state!==Ag&&this.dispatchEvent(yg)}function kg(t){switch(this.state){case Eg:if(!1===this.enableRotate)return;this._handleMouseMoveRotate(t);break;case Tg:if(!1===this.enableZoom)return;this._handleMouseMoveDolly(t);break;case Cg:if(!1===this.enablePan)return;this._handleMouseMovePan(t)}}function zg(t){!1!==this.enabled&&!1!==this.enableZoom&&this.state===Ag&&(t.preventDefault(),this.dispatchEvent(yg),this._handleMouseWheel(this._customWheelEvent(t)),this.dispatchEvent(_g))}function Gg(t){!1!==this.enabled&&this._handleKeyDown(t)}function Hg(t){switch(this._trackPointer(t),this._pointers.length){case 1:switch(this.touches.ONE){case n.ROTATE:if(!1===this.enableRotate)return;this._handleTouchStartRotate(t),this.state=Dg;break;case n.PAN:if(!1===this.enablePan)return;this._handleTouchStartPan(t),this.state=Rg;break;default:this.state=Ag}break;case 2:switch(this.touches.TWO){case n.DOLLY_PAN:if(!1===this.enableZoom&&!1===this.enablePan)return;this._handleTouchStartDollyPan(t),this.state=Pg;break;case n.DOLLY_ROTATE:if(!1===this.enableZoom&&!1===this.enableRotate)return;this._handleTouchStartDollyRotate(t),this.state=Ig;break;default:this.state=Ag}break;default:this.state=Ag}this.state!==Ag&&this.dispatchEvent(yg)}function Vg(t){switch(this._trackPointer(t),this.state){case Dg:if(!1===this.enableRotate)return;this._handleTouchMoveRotate(t),this.update();break;case Rg:if(!1===this.enablePan)return;this._handleTouchMovePan(t),this.update();break;case Pg:if(!1===this.enableZoom&&!1===this.enablePan)return;this._handleTouchMoveDollyPan(t),this.update();break;case Ig:if(!1===this.enableZoom&&!1===this.enableRotate)return;this._handleTouchMoveDollyRotate(t),this.update();break;default:this.state=Ag}}function Wg(t){!1!==this.enabled&&t.preventDefault()}function jg(t){if("Control"===t.key){this._controlActive=!0;this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0})}}function Xg(t){if("Control"===t.key){this._controlActive=!1;this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0})}}const Yg=-1,Zg=0,qg=1,Qg=2;class Kg extends Bg{constructor(t,e=null){super(t,e),this.quaternion0=this.object.quaternion.clone(),this._horizontalRotate=!0,this._verticalRotate=!0,e&&(this._onCADPointerDown=this._handleCADPointerDown.bind(this),this._onCADPointerUp=this._handleCADPointerUp.bind(this),e.addEventListener("pointerdown",this._onCADPointerDown),e.addEventListener("pointerup",this._onCADPointerUp),e.addEventListener("pointercancel",this._onCADPointerUp)),this._onMouseDown=this._handleMouseDown.bind(this)}_handleCADPointerDown(t){this._horizontalRotate=!rf.get(t,"ctrl"),this._verticalRotate=!rf.get(t,"meta")}_handleCADPointerUp(){this._horizontalRotate=!0,this._verticalRotate=!0}dispose(){this.domElement&&this._onCADPointerDown&&this._onCADPointerUp&&(this.domElement.removeEventListener("pointerdown",this._onCADPointerDown),this.domElement.removeEventListener("pointerup",this._onCADPointerUp),this.domElement.removeEventListener("pointercancel",this._onCADPointerUp)),super.dispose()}_handleMouseDown(t){let e;switch(t.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case i.DOLLY:if(!1===this.enableZoom)return;this._handleMouseDownDolly(t),this.state=qg;break;case i.ROTATE:if(rf.get(t,"shift")){if(!1===this.enablePan)return;this._handleMouseDownPan(t),this.state=Qg}else{if(!1===this.enableRotate)return;this._handleMouseDownRotate(t),this.state=Zg}break;case i.PAN:if(rf.get(t,"ctrl")||rf.get(t,"meta")||rf.get(t,"shift")){if(!1===this.enableRotate)return;this._handleMouseDownRotate(t),this.state=Zg}else{if(!1===this.enablePan)return;this._handleMouseDownPan(t),this.state=Qg}break;default:this.state=Yg}}_rotateLeft(t){this._horizontalRotate&&(this._sphericalDelta.theta-=t)}_rotateUp(t){this._verticalRotate&&(this._sphericalDelta.phi-=t)}saveState(){super.saveState(),this.quaternion0.copy(this.object.quaternion)}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.quaternion.copy(this.quaternion0),(nf(this.object)||ef(this.object))&&(this.object.zoom=this.zoom0,this.object.updateProjectionMatrix()),this.dispatchEvent({type:"change"}),this.update(),this.state=-1}rotateLeft(t){this._sphericalDelta.theta-=t}rotateUp(t){this._sphericalDelta.phi-=t}}const Jg={type:"change"},$g={type:"start"},tv={type:"end"},ev=1e-6,iv=-1,nv=0,sv=1,rv=2,av=3,ov=4,lv=new yi,hv=new yi,cv=new xi,dv=new xi,uv=new xi,pv=new _i,mv=new xi,fv=new xi,gv=new xi,vv=new xi;class yv extends ud{constructor(t,e=null){super(t,e),this.screen={left:0,top:0,width:0,height:0},this.rotateSpeed=1,this.zoomSpeed=1.2,this.panSpeed=.3,this.noRotate=!1,this.noZoom=!1,this.noPan=!1,this.staticMoving=!1,this.dynamicDampingFactor=.2,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.keys=["KeyA","KeyS","KeyD"],this.mouseButtons={LEFT:i.ROTATE,MIDDLE:i.DOLLY,RIGHT:i.PAN},this.target=new xi,this.state=iv,this.keyState=iv,this._lastPosition=new xi,this._lastZoom=1,this._touchZoomDistanceStart=0,this._touchZoomDistanceEnd=0,this._lastAngle=0,this._eye=new xi,this._movePrev=new yi,this._moveCurr=new yi,this._lastAxis=new xi,this._zoomStart=new yi,this._zoomEnd=new yi,this._panStart=new yi,this._panEnd=new yi,this._pointers=[],this._pointerPositions={},this._onPointerMove=xv.bind(this),this._onPointerDown=_v.bind(this),this._onPointerUp=bv.bind(this),this._onPointerCancel=Sv.bind(this),this._onContextMenu=Dv.bind(this),this._onMouseWheel=Cv.bind(this),this._onKeyDown=wv.bind(this),this._onKeyUp=Mv.bind(this),this._onTouchStart=Rv.bind(this),this._onTouchMove=Pv.bind(this),this._onTouchEnd=Iv.bind(this),this._onMouseDown=Av.bind(this),this._onMouseMove=Ev.bind(this),this._onMouseUp=Tv.bind(this),this._target0=this.target.clone(),this._position0=this.object.position.clone(),this._up0=this.object.up.clone(),this._zoom0=this.object.zoom,null!==e&&(this.connect(e),this.handleResize()),this.update()}connect(t){super.connect(t),window.addEventListener("keydown",this._onKeyDown),window.addEventListener("keyup",this._onKeyUp),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerCancel),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="none"}disconnect(){window.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("keyup",this._onKeyUp),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerCancel),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}handleResize(){const t=this.domElement.getBoundingClientRect(),e=this.domElement.ownerDocument.documentElement;this.screen.left=t.left+window.pageXOffset-e.clientLeft,this.screen.top=t.top+window.pageYOffset-e.clientTop,this.screen.width=t.width,this.screen.height=t.height}update(){this._eye.subVectors(this.object.position,this.target),this.noRotate||this._rotateCamera(),this.noZoom||this._zoomCamera(),this.noPan||this._panCamera(),this.object.position.addVectors(this.target,this._eye),this.object.isPerspectiveCamera?(this._checkDistances(),this.object.lookAt(this.target),this._lastPosition.distanceToSquared(this.object.position)>ev&&(this.dispatchEvent(Jg),this._lastPosition.copy(this.object.position))):this.object.isOrthographicCamera?(this.object.lookAt(this.target),(this._lastPosition.distanceToSquared(this.object.position)>ev||this._lastZoom!==this.object.zoom)&&(this.dispatchEvent(Jg),this._lastPosition.copy(this.object.position),this._lastZoom=this.object.zoom)):console.warn("THREE.TrackballControls: Unsupported camera type.")}reset(){this.state=iv,this.keyState=iv,this.target.copy(this._target0),this.object.position.copy(this._position0),this.object.up.copy(this._up0),this.object.zoom=this._zoom0,this.object.updateProjectionMatrix(),this._eye.subVectors(this.object.position,this.target),this.object.lookAt(this.target),this.dispatchEvent(Jg),this._lastPosition.copy(this.object.position),this._lastZoom=this.object.zoom}_panCamera(){if(hv.copy(this._panEnd).sub(this._panStart),hv.lengthSq()){if(this.object.isOrthographicCamera){const t=(this.object.right-this.object.left)/this.object.zoom/this.domElement.clientWidth,e=(this.object.top-this.object.bottom)/this.object.zoom/this.domElement.clientWidth;hv.x*=t,hv.y*=e}hv.multiplyScalar(this._eye.length()*this.panSpeed),dv.copy(this._eye).cross(this.object.up).setLength(hv.x),dv.add(cv.copy(this.object.up).setLength(hv.y)),this.object.position.add(dv),this.target.add(dv),this.staticMoving?this._panStart.copy(this._panEnd):this._panStart.add(hv.subVectors(this._panEnd,this._panStart).multiplyScalar(this.dynamicDampingFactor))}}_rotateCamera(){vv.set(this._moveCurr.x-this._movePrev.x,this._moveCurr.y-this._movePrev.y,0);let t=vv.length();t?(this._eye.copy(this.object.position).sub(this.target),mv.copy(this._eye).normalize(),fv.copy(this.object.up).normalize(),gv.crossVectors(fv,mv).normalize(),fv.setLength(this._moveCurr.y-this._movePrev.y),gv.setLength(this._moveCurr.x-this._movePrev.x),vv.copy(fv.add(gv)),uv.crossVectors(vv,this._eye).normalize(),t*=this.rotateSpeed,pv.setFromAxisAngle(uv,t),this._eye.applyQuaternion(pv),this.object.up.applyQuaternion(pv),this._lastAxis.copy(uv),this._lastAngle=t):!this.staticMoving&&this._lastAngle&&(this._lastAngle*=Math.sqrt(1-this.dynamicDampingFactor),this._eye.copy(this.object.position).sub(this.target),pv.setFromAxisAngle(this._lastAxis,this._lastAngle),this._eye.applyQuaternion(pv),this.object.up.applyQuaternion(pv)),this._movePrev.copy(this._moveCurr)}_zoomCamera(){let t;this.state===ov?(t=this._touchZoomDistanceStart/this._touchZoomDistanceEnd,this._touchZoomDistanceStart=this._touchZoomDistanceEnd,this.object.isPerspectiveCamera?this._eye.multiplyScalar(t):this.object.isOrthographicCamera?(this.object.zoom=vi.clamp(this.object.zoom/t,this.minZoom,this.maxZoom),this._lastZoom!==this.object.zoom&&this.object.updateProjectionMatrix()):console.warn("THREE.TrackballControls: Unsupported camera type")):(t=1+(this._zoomEnd.y-this._zoomStart.y)*this.zoomSpeed,1!==t&&t>0&&(this.object.isPerspectiveCamera?this._eye.multiplyScalar(t):this.object.isOrthographicCamera?(this.object.zoom=vi.clamp(this.object.zoom/t,this.minZoom,this.maxZoom),this._lastZoom!==this.object.zoom&&this.object.updateProjectionMatrix()):console.warn("THREE.TrackballControls: Unsupported camera type")),this.staticMoving?this._zoomStart.copy(this._zoomEnd):this._zoomStart.y+=(this._zoomEnd.y-this._zoomStart.y)*this.dynamicDampingFactor)}_getMouseOnScreen(t,e){return lv.set((t-this.screen.left)/this.screen.width,(e-this.screen.top)/this.screen.height),lv}_getMouseOnCircle(t,e){return lv.set((t-.5*this.screen.width-this.screen.left)/(.5*this.screen.width),(this.screen.height+2*(this.screen.top-e))/this.screen.width),lv}_addPointer(t){this._pointers.push(t)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;e<this._pointers.length;e++)if(this._pointers[e].pointerId==t.pointerId)return void this._pointers.splice(e,1)}_trackPointer(t){let e=this._pointerPositions[t.pointerId];void 0===e&&(e=new yi,this._pointerPositions[t.pointerId]=e),e.set(t.pageX,t.pageY)}_getSecondPointerPosition(t){const e=t.pointerId===this._pointers[0].pointerId?this._pointers[1]:this._pointers[0];return this._pointerPositions[e.pointerId]}_checkDistances(){this.noZoom&&this.noPan||(this._eye.lengthSq()>this.maxDistance*this.maxDistance&&(this.object.position.addVectors(this.target,this._eye.setLength(this.maxDistance)),this._zoomStart.copy(this._zoomEnd)),this._eye.lengthSq()<this.minDistance*this.minDistance&&(this.object.position.addVectors(this.target,this._eye.setLength(this.minDistance)),this._zoomStart.copy(this._zoomEnd)))}}function _v(t){!1!==this.enabled&&(0===this._pointers.length&&(this.domElement.setPointerCapture(t.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),this._addPointer(t),"touch"===t.pointerType?this._onTouchStart(t):this._onMouseDown(t))}function xv(t){!1!==this.enabled&&("touch"===t.pointerType?this._onTouchMove(t):this._onMouseMove(t))}function bv(t){!1!==this.enabled&&("touch"===t.pointerType?this._onTouchEnd(t):this._onMouseUp(),this._removePointer(t),0===this._pointers.length&&(this.domElement.releasePointerCapture(t.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp)))}function Sv(t){this._removePointer(t)}function Mv(){!1!==this.enabled&&(this.keyState=iv,window.addEventListener("keydown",this._onKeyDown))}function wv(t){!1!==this.enabled&&(window.removeEventListener("keydown",this._onKeyDown),this.keyState===iv&&(t.code!==this.keys[nv]||this.noRotate?t.code!==this.keys[sv]||this.noZoom?t.code!==this.keys[rv]||this.noPan||(this.keyState=rv):this.keyState=sv:this.keyState=nv))}function Av(t){let e;switch(t.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case i.DOLLY:this.state=sv;break;case i.ROTATE:this.state=nv;break;case i.PAN:this.state=rv;break;default:this.state=iv}const n=this.keyState!==iv?this.keyState:this.state;n!==nv||this.noRotate?n!==sv||this.noZoom?n!==rv||this.noPan||(this._panStart.copy(this._getMouseOnScreen(t.pageX,t.pageY)),this._panEnd.copy(this._panStart)):(this._zoomStart.copy(this._getMouseOnScreen(t.pageX,t.pageY)),this._zoomEnd.copy(this._zoomStart)):(this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY)),this._movePrev.copy(this._moveCurr)),this.dispatchEvent($g)}function Ev(t){const e=this.keyState!==iv?this.keyState:this.state;e!==nv||this.noRotate?e!==sv||this.noZoom?e!==rv||this.noPan||this._panEnd.copy(this._getMouseOnScreen(t.pageX,t.pageY)):this._zoomEnd.copy(this._getMouseOnScreen(t.pageX,t.pageY)):(this._movePrev.copy(this._moveCurr),this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY)))}function Tv(){this.state=iv,this.dispatchEvent(tv)}function Cv(t){if(!1!==this.enabled&&!0!==this.noZoom){switch(t.preventDefault(),t.deltaMode){case 2:this._zoomStart.y-=.025*t.deltaY;break;case 1:this._zoomStart.y-=.01*t.deltaY;break;default:this._zoomStart.y-=25e-5*t.deltaY}this.dispatchEvent($g),this.dispatchEvent(tv)}}function Dv(t){!1!==this.enabled&&t.preventDefault()}function Rv(t){if(this._trackPointer(t),1===this._pointers.length)this.state=av,this._moveCurr.copy(this._getMouseOnCircle(this._pointers[0].pageX,this._pointers[0].pageY)),this._movePrev.copy(this._moveCurr);else{this.state=ov;const t=this._pointers[0].pageX-this._pointers[1].pageX,e=this._pointers[0].pageY-this._pointers[1].pageY;this._touchZoomDistanceEnd=this._touchZoomDistanceStart=Math.sqrt(t*t+e*e);const i=(this._pointers[0].pageX+this._pointers[1].pageX)/2,n=(this._pointers[0].pageY+this._pointers[1].pageY)/2;this._panStart.copy(this._getMouseOnScreen(i,n)),this._panEnd.copy(this._panStart)}this.dispatchEvent($g)}function Pv(t){if(this._trackPointer(t),1===this._pointers.length)this._movePrev.copy(this._moveCurr),this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY));else{const e=this._getSecondPointerPosition(t),i=t.pageX-e.x,n=t.pageY-e.y;this._touchZoomDistanceEnd=Math.sqrt(i*i+n*n);const s=(t.pageX+e.x)/2,r=(t.pageY+e.y)/2;this._panEnd.copy(this._getMouseOnScreen(s,r))}}function Iv(t){switch(this._pointers.length){case 0:this.state=iv;break;case 1:this.state=av,this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY)),this._movePrev.copy(this._moveCurr);break;case 2:this.state=ov;for(let e=0;e<this._pointers.length;e++)if(this._pointers[e].pointerId!==t.pointerId){const t=this._pointerPositions[this._pointers[e].pointerId];this._moveCurr.copy(this._getMouseOnCircle(t.x,t.y)),this._movePrev.copy(this._moveCurr);break}}this.dispatchEvent(tv)}const Lv=-1,Bv=0,Ov=1,Fv=2,Nv=new _i;let Uv=1;const kv=new _i,zv=new xi,Gv=new xi,Hv=new xi,Vv=new xi,Wv=new xi,jv=new xi;class Xv extends yv{constructor(t,e=null){super(t,e),this.holroyd=!0,this.radius=.9,this.quaternion0=this.object.quaternion.clone(),this._holroydStart=new yi,this._holroydEnd=new yi,this._holroydActive=!1,this._horizontalRotate=!0,this._verticalRotate=!0,e&&(this._holroydPointerDown=this._onHolroydPointerDown.bind(this),this._holroydPointerMove=this._onHolroydPointerMove.bind(this),this._holroydPointerUp=this._onHolroydPointerUp.bind(this),this._holroydWheel=this._onHolroydWheel.bind(this),e.addEventListener("pointerdown",this._holroydPointerDown),e.addEventListener("pointermove",this._holroydPointerMove),e.addEventListener("pointerup",this._holroydPointerUp),e.addEventListener("pointercancel",this._holroydPointerUp),e.addEventListener("wheel",this._holroydWheel,{passive:!1})),this._parentOnMouseDown=this._onMouseDown,this._onMouseDown=this._handleMouseDown.bind(this)}_handleMouseDown(t){if(!this.holroyd)return void this._parentOnMouseDown(t);let e;switch(t.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e===i.ROTATE&&rf.get(t,"shift")&&(e=i.PAN),e){case i.DOLLY:this.state=Ov;break;case i.ROTATE:this.state=Bv;break;case i.PAN:this.state=Fv;break;default:this.state=Lv}const n=this.keyState!==Lv?this.keyState:this.state;n!==Bv||this.noRotate?n!==Ov||this.noZoom?n!==Fv||this.noPan||(this._panStart.copy(this._getMouseOnScreen(t.pageX,t.pageY)),this._panEnd.copy(this._panStart)):(this._zoomStart.copy(this._getMouseOnScreen(t.pageX,t.pageY)),this._zoomEnd.copy(this._zoomStart)):(this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY)),this._movePrev.copy(this._moveCurr)),this.dispatchEvent({type:"start"})}_onHolroydPointerDown(t){this.holroyd&&0===t.button&&(rf.get(t,"shift")||(this._holroydStart.set(t.pageX,t.pageY),this._holroydEnd.set(t.pageX,t.pageY),this._holroydActive=!0,this._horizontalRotate=!rf.get(t,"ctrl"),this._verticalRotate=!rf.get(t,"meta")))}_onHolroydPointerMove(t){this.holroyd&&this._holroydActive&&this._holroydEnd.set(t.pageX,t.pageY),-1!==this.state&&this.update()}_onHolroydPointerUp(){this._holroydActive=!1,this._horizontalRotate=!0,this._verticalRotate=!0}_onHolroydWheel(){this.update(),this._zoomStart.copy(this._zoomEnd)}dispose(){this.domElement&&this._holroydPointerDown&&this._holroydPointerMove&&this._holroydPointerUp&&this._holroydWheel&&(this.domElement.removeEventListener("pointerdown",this._holroydPointerDown),this.domElement.removeEventListener("pointermove",this._holroydPointerMove),this.domElement.removeEventListener("pointerup",this._holroydPointerUp),this.domElement.removeEventListener("pointercancel",this._holroydPointerUp),this.domElement.removeEventListener("wheel",this._holroydWheel)),super.dispose()}saveState(){this._target0.copy(this.target),this._position0.copy(this.object.position),this._up0.copy(this.object.up),(nf(this.object)||ef(this.object))&&(this._zoom0=this.object.zoom),this.quaternion0.copy(this.object.quaternion)}reset(){super.reset(),this.object.quaternion.copy(this.quaternion0)}get target0(){return this._target0}get position0(){return this._position0}get zoom0(){return this._zoom0}set zoom0(t){this._zoom0=t}_getMouseOnSphere(t,e,i){const n=this.domElement.getBoundingClientRect(),s=this._horizontalRotate?(t-n.left)/(n.width/2)-1:0,r=this._verticalRotate?1-(e-n.top)/(n.height/2):0,a=this.radius*this.radius,o=s*s+r*r;return o<=a/2?i.set(s,r,Math.sqrt(a-o)):i.set(s,r,a/(2*Math.sqrt(o))),i}update(){if(!this.holroyd)return void super.update();this._eye.subVectors(this.object.position,this.target),this.noRotate||this._rotateCamera(),this.noZoom||this._zoomCamera(),this.noPan||this._panCamera(),this.object.position.addVectors(this.target,this._eye);const t=nf(this.object)||ef(this.object)?this.object.zoom:1,e=Math.abs(t-Uv)>1e-6;(this._lastPosition.distanceToSquared(this.object.position)>1e-6||Nv.dot(this.object.quaternion)<.999999||e)&&(this.dispatchEvent({type:"change"}),this._lastPosition.copy(this.object.position),Nv.copy(this.object.quaternion),Uv=t)}_rotateCamera(){if(!this.holroyd)return void super._rotateCamera();if(this._holroydStart.x===this._holroydEnd.x&&this._holroydStart.y===this._holroydEnd.y)return void this._movePrev.copy(this._moveCurr);this._getMouseOnSphere(this._holroydStart.x,this._holroydStart.y,Gv),this._getMouseOnSphere(this._holroydEnd.x,this._holroydEnd.y,Hv),zv.crossVectors(Gv,Hv);const t=Math.atan(zv.length()/Gv.dot(Hv));if(t){zv.normalize(),zv.applyQuaternion(this.object.quaternion);const e=-2*t*this.rotateSpeed;kv.setFromAxisAngle(zv,e),this.object.quaternion.premultiply(kv),this._eye.applyQuaternion(kv)}this._holroydStart.copy(this._holroydEnd),this._movePrev.copy(this._moveCurr)}_panCamera(){if(!this.holroyd)return void super._panCamera();const t=Vv.set(this._panEnd.x-this._panStart.x,this._panEnd.y-this._panStart.y,0);if(0!==t.lengthSq()){if(ef(this.object)){const e=(this.object.right-this.object.left)/this.object.zoom,i=(this.object.top-this.object.bottom)/this.object.zoom;t.x*=e*this.panSpeed*4,t.y*=i*this.panSpeed*4}else if(nf(this.object)&&this.domElement){const e=this.domElement.clientWidth/this.domElement.clientHeight;t.x*=e,t.multiplyScalar(this._eye.length()*this.panSpeed*1.6)}else t.multiplyScalar(this._eye.length()*this.panSpeed*2);jv.set(1,0,0).applyQuaternion(this.object.quaternion),Wv.set(0,1,0).applyQuaternion(this.object.quaternion),jv.multiplyScalar(-t.x),Wv.multiplyScalar(t.y),this.object.position.add(jv).add(Wv),this.target.add(jv).add(Wv),this._panStart.copy(this._panEnd)}}rotateX(t){this._rotateAroundAxis("x",t)}rotateY(t){this._rotateAroundAxis("y",t)}rotateZ(t){this._rotateAroundAxis("z",t)}_rotateAroundAxis(t,e){const i=Gm[t];kv.setFromAxisAngle(i,e),this.object.quaternion.premultiply(kv),this.object.position.sub(this.target).applyQuaternion(kv).add(this.target)}}const Yv={trackball:{pan:.22,rotate:1,zoom:2},orbit:{pan:1,rotate:1,zoom:1}};class Zv{constructor(t,e,i,n,s=1,r=1,a=1,o=!0){switch(this.getResetLocation=()=>({target0:this.controls.target0.clone(),position0:this.controls.position0.clone(),quaternion0:this.controls.quaternion0.clone(),zoom0:this.controls.zoom0}),this.setResetLocation=(t,e,i,n)=>{this.controls.target0.copy(t),this.controls.position0.copy(e),this.controls.quaternion0.copy(i),this.controls.zoom0=n},this.type=t,this.camera=e,this.target=i,this.target0=i.clone(),this.domElement=n,this.rotateSpeed=s,this.zoomSpeed=r,this.panSpeed=a,this.holroyd=o,t){case"orbit":this.initOrbitControls();break;case"trackball":this.initTrackballControls(o)}this.controls.target.copy(this.target),this._applySpeedFactors(),this.currentUpdateCallback=null,this.saveState(),this.update()}_getSpeedFactors(){return Yv[this.type]}_applySpeedFactors(){const t=this._getSpeedFactors();this.controls.rotateSpeed=this.rotateSpeed*t.rotate,this.controls.zoomSpeed=this.zoomSpeed*t.zoom,this.controls.panSpeed=this.panSpeed*t.pan}dispose(){this.controls.dispose()}saveState(){this.controls.saveState()}initTrackballControls(t=!0){this.controls=new Xv(this.camera,this.domElement),this.setHolroydTrackball(t)}initOrbitControls(){this.controls=new Kg(this.camera,this.domElement)}addChangeListener(t){null==this.currentUpdateCallback&&(this.currentUpdateCallback=t,this.controls.addEventListener("change",t))}removeChangeListener(){null!=this.currentUpdateCallback&&(this.controls.removeEventListener("change",this.currentUpdateCallback),this.currentUpdateCallback=null)}update(){this.controls.update()}handleResize(){this.controls instanceof Xv&&this.controls.handleResize()}reset(){this.controls.reset()}setCamera(t){this.controls.object=t}setHolroydTrackball(t){this.getTrackballControls().holroyd=t}getTarget(){return this.controls.target}isInteracting(){return-1!==this.controls.state}getZoom0(){return this.controls.zoom0}setTarget(t){this.controls.target.copy(t)}setZoomSpeed(t){this.zoomSpeed=t,this.controls.zoomSpeed=t*this._getSpeedFactors().zoom}setPanSpeed(t){this.panSpeed=t,this.controls.panSpeed=t*this._getSpeedFactors().pan}setRotateSpeed(t){this.rotateSpeed=t,this.controls.rotateSpeed=t*this._getSpeedFactors().rotate}getOrbitControls(){if(!(this.controls instanceof Kg))throw new Error("Operation requires OrbitControls");return this.controls}getTrackballControls(){if(!(this.controls instanceof Xv))throw new Error("Operation requires TrackballControls");return this.controls}rotateUp(t){this.getOrbitControls().rotateUp(-t/180*Math.PI),this.update()}rotateLeft(t){this.getOrbitControls().rotateLeft(t/180*Math.PI),this.update()}rotateX(t){this.getTrackballControls().rotateX(t/180*Math.PI),this.update()}rotateY(t){this.getTrackballControls().rotateY(t/180*Math.PI),this.update()}rotateZ(t){this.getTrackballControls().rotateZ(t/180*Math.PI),this.update()}}const qv={y_up:{iso:{pos:new xi(1,1,1),quat:null},front:{pos:new xi(0,0,1),quat:null},rear:{pos:new xi(0,0,-1),quat:null},left:{pos:new xi(-1,0,0),quat:null},right:{pos:new xi(1,0,0),quat:null},top:{pos:new xi(0,1,0),quat:null},bottom:{pos:new xi(0,-1,0),quat:null}},z_up:{iso:{pos:new xi(1,-1,1),quat:null},front:{pos:new xi(0,-1,0),quat:null},rear:{pos:new xi(0,1,0),quat:null},left:{pos:new xi(-1,0,0),quat:null},right:{pos:new xi(1,0,0),quat:null},top:{pos:new xi(0,0,1),quat:new _i(0,0,0,1)},bottom:{pos:new xi(0,0,-1),quat:new _i(1,0,0,0)}},legacy:{iso:{pos:new xi(1,1,1),quat:null},front:{pos:new xi(1,0,0),quat:null},rear:{pos:new xi(-1,0,0),quat:null},left:{pos:new xi(0,1,0),quat:null},right:{pos:new xi(0,-1,0),quat:null},top:{pos:new xi(0,0,1),quat:null},bottom:{pos:new xi(0,0,-1),quat:null}}},Qv={y_up:[0,1,0],z_up:[0,0,1],legacy:[0,0,1]};class Kv{static _computeNear(t){return Math.max(.1,Kv.NEAR_FACTOR*t)}constructor(t,e,i,n,s,r){this.target=new xi(...n),this.ortho=s,this.up={Y:"y_up",Z:"z_up",L:"legacy"}[r]||"z_up",this.yaxis=new xi(0,1,0),this.zaxis=new xi(0,0,1);const a=t/e;this.camera_distance=Kv.DISTANCE_FACTOR*i;const o=Kv._computeNear(i),l=100*i;this.pCamera=new Ph(22,a,o,l),this.pCamera.up.set(...Qv[this.up]),this.pCamera.lookAt(this.target);const h=this.projectSize(i,a);this.oCamera=new Fh(-h[0],h[0],h[1],-h[1],o,l),this.oCamera.up.set(...Qv[this.up]),this.oCamera.lookAt(this.target),this.camera=s?this.oCamera:this.pCamera,this.camera.up.set(...Qv[this.up])}updateFarPlane(t){const e=Kv._computeNear(t),i=100*t;this.pCamera.near=e,this.pCamera.far=i,this.oCamera.near=e,this.oCamera.far=i,this.camera.updateProjectionMatrix()}updateCameraDistance(t){this.camera_distance=Kv.DISTANCE_FACTOR*t}dispose(){}getCamera(){return this.camera}lookAtTarget(){this.camera.lookAt(this.target)}updateProjectionMatrix(){this.camera.updateProjectionMatrix()}switchCamera(t){const e=this.getPosition().clone(),i=this.getZoom(),n=this.getQuaternion().clone();t?(this.camera=this.oCamera,this.ortho=!0):(this.camera=this.pCamera,this.ortho=!1),this.setPosition(e,!1),this.setZoom(i),this.setQuaternion(n),this.updateProjectionMatrix()}projectSize(t,e){let i,n;return e<1?(i=t,n=i/e):(n=t,i=n*e),[i,n]}setupCamera(t,e=null,i=null,n=null){if(null!=e){const i=t?e.clone().normalize().multiplyScalar(this.camera_distance).add(this.target):e;this.camera.position.set(...i.toArray())}null!=i&&this.camera.quaternion.set(...i.toArray()),null!=n&&this.setZoom(n),this.updateProjectionMatrix()}presetCamera(t,e=null){null==e&&(e=this.camera.zoom),this.setupCamera(!0,qv[this.up][t].pos,null,e),this.lookAtTarget();const i=qv[this.up][t].quat;null!=i&&this.setQuaternion(i)}getZoom(){if(this.ortho)return this.camera.zoom;{const t=this.camera.position.clone().sub(this.target);return this.camera_distance/t.length()}}setZoom(t){this.ortho?this.camera.zoom=t:this.camera.position.sub(this.target).setLength(this.camera_distance/t).add(this.target),this.updateProjectionMatrix()}getPosition(){return this.camera.position}setPosition(t,e){Array.isArray(t)&&3===t.length?this.setupCamera(e,new xi(...t)):t instanceof xi?this.setupCamera(e,t):Fm.error("wrong type for position",t)}getQuaternion(){return this.camera.quaternion}setQuaternion(t){Array.isArray(t)&&4===t.length?this.setupCamera(!1,null,new _i(...t)):t instanceof _i?this.setupCamera(!1,null,t):Fm.error("wrong type for quaternion",t),this.updateProjectionMatrix()}getRotation(){return this.camera.rotation}getVisibleArea(){if(this.ortho&&this.oCamera){const t=(this.oCamera.top-this.oCamera.bottom)/this.oCamera.zoom;return{width:(this.oCamera.right-this.oCamera.left)/this.oCamera.zoom,height:t}}if(this.pCamera){const t=this.pCamera.position.distanceTo(this.target),e=this.pCamera.fov*Math.PI/180,i=2*Math.tan(e/2)*t;return{width:i*this.pCamera.aspect,height:i}}return{width:0,height:0}}changeDimensions(t,e,i){const n=e/i,s=this.projectSize(t,n);this.oCamera&&(this.oCamera.left=-s[0],this.oCamera.right=s[0],this.oCamera.top=s[1],this.oCamera.bottom=-s[1]),this.pCamera&&(this.pCamera.aspect=n),this.camera&&this.camera.updateProjectionMatrix()}}Kv.DISTANCE_FACTOR=5,Kv.NEAR_FACTOR=.01;const Jv={none:null,vertex:"vertex",edge:"edge",face:"face",solid:"solid"};class $v{constructor(t,e){this.obj=t,this.fromSolid=e}_getSolidObjectGroups(t){const e=t.parent.parent;let i;for(let t=0;t<e.children.length;t++){const n=e.children[t];if(n.name===e.name+"|faces"){i=n;break}}return(i?.children||[]).filter(lf)}objs(){return this.fromSolid?this._getSolidObjectGroups(this.obj):[this.obj]}}class ty{constructor(t,e,n,s,r,a,o){this.onMouseKeyDown=t=>{this.raycastMode&&this.camera&&(t.button!=i.LEFT&&t.button!=i.RIGHT||(this.lastPosition=this.camera.getPosition().clone()))},this.onMouseKeyUp=t=>{this.raycastMode&&this.camera&&this.lastPosition&&(t.button==i.LEFT?this.lastPosition.distanceTo(this.camera.getPosition())<1e-6&&this.callback({mouse:"left",shift:rf.get(t,"shift")}):t.button==i.RIGHT&&this.lastPosition.distanceTo(this.camera.getPosition())<1e-6&&this.callback({mouse:"right"}))},this.onKeyDown=t=>{this.raycastMode&&("Backspace"==t.key?this.callback({key:"Backspace"}):"Escape"==t.key&&this.callback({key:"Escape"}))},this.onPointerMove=t=>{if(!this.domElement)return;const e=this.domElement.getBoundingClientRect(),i=e.x+window.scrollX,n=e.y+window.scrollY;this.mouse.x=(t.pageX-i)/this.width*2-1,this.mouse.y=-(t.pageY-n)/this.height*2+1,this.mouseMoved=!0},this.camera=t,this.group=a,this.domElement=e,this.width=n,this.height=s,this.threshold=r,this.callback=o,this.raycaster=new Pc,this.raycastMode=!1,this.lastPosition=null,this.mouse=new yi,this.mouseMoved=!1,this.filters={topoFilter:[Jv.none]}}dispose(){this.domElement&&(this.domElement.removeEventListener("mousemove",this.onPointerMove),this.domElement.removeEventListener("mouseup",this.onMouseKeyUp),this.domElement.removeEventListener("mousedown",this.onMouseKeyDown)),document.removeEventListener("keydown",this.onKeyDown),this.raycastMode=!1,this.group=null,this.domElement=null,this.camera=null}init(){this.domElement&&(this.domElement.addEventListener("mousemove",this.onPointerMove),this.domElement.addEventListener("mouseup",this.onMouseKeyUp,!1),this.domElement.addEventListener("mousedown",this.onMouseKeyDown,!1),document.addEventListener("keydown",this.onKeyDown,!1),this.raycastMode=!0)}getIntersectedObjs(){if(!this.camera||!this.group)return[];this.raycaster.setFromCamera(this.mouse,this.camera.getCamera()),this.raycaster.params.Points.threshold=this.threshold/this.camera.getZoom(),this.raycaster.params.Line2={threshold:4};const t=this.raycaster.intersectObjects([this.group],!0),e=[];for(const i of t){const t=i.object;(Jm(t)||tf(t)||$m(t))&&t.visible&&!Array.isArray(t.material)&&t.material.visible&&e.push(i)}return e}getValidIntersectedObjs(){const t=[];if(this.mouseMoved){const e=this.getIntersectedObjs();for(const i of e){const e=i.object;if(!(Jm(e)||tf(e)||$m(e)))continue;if(!e.visible||Array.isArray(e.material)||!e.material.visible)continue;const n=i.object.parent;if(!lf(n))continue;if(!n.shapeInfo)continue;const s=n.shapeInfo.topo,r="solid"===n.subtype,a=this.filters.topoFilter.includes(Jv.solid)&&r,o=this.filters.topoFilter.some(t=>t===s);(a||this.filters.topoFilter.includes(Jv.none)||o)&&t.push(i)}}return t}}function ey(t,e){return Array.isArray(t)&&t.length===e&&t.every(t=>"number"==typeof t)}function iy(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)&&Object.values(t).every(t=>ey(t,3))}function ny(t){return t.toLowerCase().replace(/(\D)(\d+)$/,"$1 $2")}function sy(t,e){const i=["tcv_x_measure_val","tcv_y_measure_val","tcv_z_measure_val"],n=document.createElement("tr"),s=document.createElement("th");s.textContent=ny(t),s.classList.add("tcv_measure_key"),s.classList.add("tcv_measure_cell"),n.appendChild(s);const r=document.createElement("td");r.textContent="(",r.classList.add("tcv_measure_cell_bracket"),n.appendChild(r);for(let t=0;t<3;++t){const s=document.createElement("td");s.textContent=e[t].toFixed(3),s.classList.add("tcv_measure_val"),s.classList.add("tcv_measure_cell"),s.classList.add(i[t]),n.appendChild(s)}const a=document.createElement("td");return a.textContent=")",a.classList.add("tcv_measure_cell_bracket"),n.appendChild(a),n}function ry(t,e){const i=document.createElement("tr"),n=document.createElement("th"),s=document.createElement("td");return n.textContent=ny(t),n.classList.add("tcv_measure_key"),n.classList.add("tcv_measure_cell"),i.appendChild(n),s.textContent=e,s.classList.add("tcv_measure_val_center"),s.classList.add("tcv_measure_cell"),s.colSpan=5,i.appendChild(s),i}function ay(t,e,i=null){const n=document.createElement("tr"),s=document.createElement("th"),r=document.createElement("td");s.textContent=ny(t),s.classList.add("tcv_measure_key"),s.classList.add("tcv_measure_cell"),n.appendChild(s);for(let t=0;t<2;t++){const t=document.createElement("td");n.appendChild(t)}if(r.textContent=e.toFixed(3),r.classList.add("tcv_measure_val"),r.classList.add("tcv_measure_cell"),n.appendChild(r),null==i)for(let t=0;t<2;t++){const t=document.createElement("td");n.appendChild(t)}else{const t=document.createElement("td");t.textContent=`(${i})`,t.classList.add("tcv_measure_cell"),n.appendChild(t);const e=document.createElement("td");n.appendChild(e)}return n}class oy{constructor(t){this.show=t=>{this.html.style.display=t?"inline-block":"none"},this.isVisible=()=>"inline-block"==this.html.style.display,this.relocate=(t,e)=>{this.html.style.left=`${t}px`,this.html.style.top=`${e}px`},this.display=t,this.html=this.getHtmlElement(),this.finished=!1,this.callbacks=[],this.html.addEventListener("contextmenu",t=>{t.preventDefault()})}removeTable(){const t=this.html.getElementsByTagName("table");t.length>0&&t[0].remove(),this.finished=!1}resetTable(){this.removeTable()}registerCallback(t,e){this.callbacks.push({callback:e,type:t}),this.html.addEventListener(t,e)}dispose(){for(const t of this.callbacks)this.html.removeEventListener(t.type,t.callback)}}const ly=["type","tool_type","subtype","info","refpoint","refpoint1","refpoint2","shape_type","geom_type","groups","result"];function hy(t,e,i){let n=!0;for(const s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;if(ly.includes(s.toLowerCase()))continue;const r=t[s];let a;if("bb"===s.toLowerCase()&&iy(r))for(const t in r){const s=sy(`bb ${t}`,r[t]);i&&n&&(s.classList.add("tcv_measure_cell_top_border"),n=!1),e.appendChild(s)}else if(ey(r,3))a=sy(s,r);else if("number"==typeof r)if("distance"===s.toLowerCase()){a=ay(s,r,("string"==typeof t.info?t.info:void 0)??null)}else a=ay(s,r);else"string"==typeof r&&(a=ry(s,r));a&&(i&&n&&a.classList.add("tcv_measure_cell_top_border"),e.appendChild(a),n=!1)}}function cy(t,e){const i=t.result??t.groups;if(Array.isArray(i))for(let t=0;t<i.length;t++)hy(i[t],e,t>0);else hy(t,e,!1)}class dy extends oy{constructor(t){super(t)}getHtmlElement(){return this.display.measurementPanels.distancePanel}createTable(t){if(this.finished)return;this.resetTable();const e=document.createElement("table");e.classList.add("tcv_properties_table");const i=document.createElement("tbody");cy(t,i),e.appendChild(i),this.html.append(e),this.finished=!0}}class uy extends oy{constructor(t){super(t)}getHtmlElement(){return this.display.measurementPanels.propertiesPanel}setSubHeader(t){this.html.getElementsByClassName("tcv_measure_subheader")[0].textContent=t}createTable(t){if(this.finished)return;this.resetTable(),this.setSubHeader(`${t.shape_type??""} / ${t.geom_type??""}`);const e=document.createElement("table");e.classList.add("tcv_properties_table");const i=document.createElement("tbody");cy(t,i),e.appendChild(i),this.html.append(e),this.finished=!0}}class py{constructor(t){this.setValue=t=>{if(null!=this.raycaster){this.elements.value.innerText=t;const e=t.toLowerCase();"none"===e?this.raycaster.filters.topoFilter=[Jv.none]:e in Jv&&(this.raycaster.filters.topoFilter=[Jv[e]])}},this.toggleDropdown=t=>{null!=t&&t.stopPropagation(),this.elements.dropdown.classList.contains("tcv_filter_dropdown_active")?(this.elements.dropdown.classList.remove("tcv_filter_dropdown_active"),this.elements.icon.innerText="⏶"):(this.elements.dropdown.classList.add("tcv_filter_dropdown_active"),this.elements.icon.innerText="⏷")},this.closeDropdown=t=>{this.elements.dropdown.classList.contains("tcv_filter_dropdown_active")&&this.toggleDropdown(t)},this.handleSelection=t=>{const e=t.target;e instanceof HTMLElement&&(this.setValue(e.innerText),this.toggleDropdown(t))},this.reset=()=>{this.setValue("None")},this.keybindSelect=t=>{-1!==["n","v","e","f","s","Escape"].indexOf(t.key)&&("n"==t.key?this.setValue("None"):"v"==t.key?this.setValue("Vertex"):"e"==t.key?this.setValue("Edge"):"f"==t.key?this.setValue("Face"):"s"==t.key?this.setValue("Solid"):"Escape"==t.key&&this.closeDropdown(t))},this.display=t,this.elements=t.filterDropdown,this.elements.container.style.display="none",this.raycaster=null}setRaycaster(t){this.raycaster=t}getOptionElements(){const t=this.elements.options;return[t.none,t.vertex,t.edge,t.face,t.solid]}show(t){if(t){document.addEventListener("keydown",this.keybindSelect),this.display.container.addEventListener("click",this.closeDropdown),this.elements.content.addEventListener("click",this.toggleDropdown);for(const t of this.getOptionElements())t.addEventListener("click",this.handleSelection)}else{document.removeEventListener("keydown",this.keybindSelect),this.display.container.removeEventListener("click",this.closeDropdown),this.elements.content.removeEventListener("click",this.toggleDropdown);for(const t of this.getOptionElements())t.removeEventListener("click",this.handleSelection)}this.elements.container.style.display=t?"block":"none"}}class my extends _n{constructor(t,e,i,n,s,r=!0,a=!0){super(),this.coneLength=t,this.point1=e,this.point2=i,this.linewidth=n,this.color=s,this.arrowStart=r,this.arrowEnd=a,this.type="DistanceLineArrow",this.mode="inward",this.renderMode="arrows",this.initialize()}initialize(){const t=.8*this.coneLength,e=this.point1.distanceTo(this.point2);if(e<1e-9){this.renderMode="dot";const e=new gl(t/6,16,12),i=new lr({color:this.color}),n=new xr(e,i);return n.name="dot",n.position.copy(this.point1),void this.add(n)}this.renderMode="arrows",this.lineVec=this.point1.clone().sub(this.point2.clone()).normalize(),this.mode=e<t?"outward":"inward";const i="inward"===this.mode?1:-1;let n,s;n=this.arrowStart?this.point1.clone().sub(this.lineVec.clone().multiplyScalar(i*t*.3)):this.point1.clone(),s=this.arrowEnd?this.point2.clone().sub(this.lineVec.clone().multiplyScalar(-i*t*.3)):this.point2.clone();const r=new dm({linewidth:this.linewidth,color:this.color}),a=new cm;a.setPositions([...n.toArray(),...s.toArray()]);const o=new Cm(a,r),l=new to(t/4,.6*t,10),h=new lr({color:this.color}),c=new xr(l,h),d=new xr(l,h);c.name="startCone",d.name="endCone";const u=new Wi,p=new _i;"inward"===this.mode?(u.lookAt(this.point1,this.point2,c.up),p.setFromRotationMatrix(u),c.setRotationFromQuaternion(p),u.lookAt(this.point2,this.point1,d.up),p.setFromRotationMatrix(u),d.setRotationFromQuaternion(p)):(u.lookAt(this.point2,this.point1,c.up),p.setFromRotationMatrix(u),c.setRotationFromQuaternion(p),u.lookAt(this.point1,this.point2,d.up),p.setFromRotationMatrix(u),d.setRotationFromQuaternion(p)),c.rotateX(90*Math.PI/180),d.rotateX(90*Math.PI/180),c.position.copy(n),d.position.copy(s),this.arrowStart&&this.add(c),this.arrowEnd&&this.add(d),this.add(o)}update(t){if("dot"===this.renderMode){const e=this.children.find(t=>Jm(t)&&"dot"===t.name);return void(e&&Jm(e)&&e.scale.set(t,t,t))}const e=.8*this.coneLength,i="inward"===this.mode?1:-1,n=this.point1.clone().sub(this.lineVec.clone().multiplyScalar(i*t*e*.3)),s=this.point2.clone().sub(this.lineVec.clone().multiplyScalar(-i*t*e*.3)),r=this.children.find(t=>sf(t));if(r&&sf(r)&&r.geometry.setPositions([...this.arrowStart?n.toArray():this.point1.toArray(),...this.arrowEnd?s.toArray():this.point2.toArray()]),this.arrowStart){const e=this.children.find(t=>Jm(t)&&"startCone"===t.name);e&&Jm(e)&&(e.position.copy(n),e.scale.set(t,t,t))}if(this.arrowEnd){const e=this.children.find(t=>Jm(t)&&"endCone"===t.name);e&&Jm(e)&&(e.position.copy(s),e.scale.set(t,t,t))}}dispose(){const t=this.children.find(t=>sf(t));t&&sf(t)&&(t.geometry.dispose(),t.material.dispose());const e=this.children.find(t=>Jm(t)&&"startCone"===t.name);if(e&&Jm(e)){e.geometry.dispose();const t=e.material;Array.isArray(t)?t.forEach(t=>t.dispose()):t.dispose()}const i=this.children.find(t=>Jm(t)&&"dot"===t.name);if(i&&Jm(i)){i.geometry.dispose();const t=i.material;Array.isArray(t)?t.forEach(t=>t.dispose()):t.dispose()}this.clear()}}class fy{constructor(t,e){this.handleSelection=(t,e=!1)=>{this.shift=e,void 0!==this.selectedShapes.find(e=>e.obj.name===t.obj.name)?this.selectedShapes.splice(this.selectedShapes.indexOf(t),1):this.selectedShapes.push(t),this.panel&&(this.panel.finished=!1),this._updateMeasurement()},this._mouseup=t=>{this.panelDragData.clicked=!1,t.stopPropagation()},this._movePanel=()=>{if(!(this.panel&&this.viewer&&this.viewer.camera&&this.panel.isVisible()))return;const t=this.viewer.renderer.domElement.getBoundingClientRect(),e=this.panel.html.getBoundingClientRect();if(null==this.panelX&&null!=this.middlePoint){const i=this.middlePoint.clone().project(this.viewer.camera.getCamera()),n=(i.x+1)*(t.width/2),s=(1-i.y)*(t.height/2);n<t.width/2?this.panelX=n+e.width/2:this.panelX=n-e.width-e.width/2,this.panelX=Math.max(0,Math.min(t.width-e.width,this.panelX)),this.panelY=s,this.panelY=Math.max(0,Math.min(t.height-e.height,this.panelY))}if(this.panel.relocate(this.panelX,this.panelY),null==this.panelX||null==this.panelY)return;const i=this.panelX+e.width/2,n=this.panelY+e.height/2,s=i/(t.width/2)-1,r=1-n/(t.height/2),a=this.viewer.ortho?-.9:1,o=new xi(s,r,a),l=this.viewer.camera.getCamera();(nf(l)||ef(l))&&(l.updateProjectionMatrix(),l.updateMatrixWorld(),this.panelCenter=o.unproject(l)),this.scene&&this.scene.children.length>0&&this._updateConnectionLine()},this._dragPanel=t=>{if(!this.panelDragData.clicked||!this.panel||!this.viewer)return;if(null==this.panelDragData.x||null==this.panelDragData.y)return;const e=this.panel.html.getBoundingClientRect(),i=this.viewer.renderer.domElement.getBoundingClientRect(),n=t.clientX-this.panelDragData.x,s=t.clientY-this.panelDragData.y;e.x+n<i.x&&t.movementX<=0||e.x+n>i.x+i.width-e.width&&t.movementX>=0||null!==this.panelX&&(this.panelX+=n),e.y+s<i.y&&t.movementY<=0||e.y+s>i.y+i.height-e.height&&t.movementY>=0||null!==this.panelY&&(this.panelY+=s),this._updateMeasurement(),this.panelDragData.x=t.clientX,this.panelDragData.y=t.clientY},this.selectedShapes=[],this.point1=null,this.point2=null,this.middlePoint=null,this.contextEnabled=!1,this.viewer=t,this.scene=new Rn,this.panel=e,this.panelCenter=null,this.panelX=null,this.panelY=null,this.panelShown=!1,this.responseData=null,this.measurementLineColor=0,this.connectingLineColor=8388736,this.coneLength=void 0,this.debug=!1,this.panelDragData={x:null,y:null,clicked:!1},this.panel.registerCallback("mousedown",t=>{this.panelDragData.clicked=!0,this.panelDragData.x=t.clientX,this.panelDragData.y=t.clientY,t.stopPropagation()}),this.shift=!1}enableContext(){this.contextEnabled=!0,this.panelCenter=new xi(1,0,0),document.addEventListener("mouseup",this._mouseup),document.addEventListener("mousemove",this._dragPanel)}disableContext(){this._hideMeasurement(),this.contextEnabled=!1,this.responseData=null;for(const t of this.selectedShapes)t.obj.clearHighlights();this.selectedShapes=[],document.removeEventListener("mouseup",this._mouseup),document.removeEventListener("mousemove",this._dragPanel),this.viewer?.checkChanges({selectedShapeIDs:[]})}_hideMeasurement(){this.panel?.show(!1),this.disposeArrows(),this.scene?.clear()}handleResponse(t){}_createPanel(){throw new Error("Subclass needs to override this method")}_makeLines(){throw new Error("Subclass needs to override this method")}_updateConnectionLine(){throw new Error("Subclass needs to override this method")}_getMaxObjSelected(){throw new Error("Subclass needs to override this method")}_waitResponse(t,e){this.responseData?t(this.responseData):setTimeout(()=>{this._waitResponse(t,e)},100)}_updateMeasurement(){const t=this.selectedShapes.map(t=>{if(t.fromSolid){return t.obj.name.replace(/\|faces.*$/,"").replace(/\|edges.*$/,"").replace(/\|vertices.*$/,"").replaceAll("|","/")}return t.obj.name.replaceAll("|","/")});if(this.responseData=null,this.debug){const t=50+Math.floor(200*Math.random());setTimeout(()=>{if(0==this.selectedShapes.length)return;const t=t=>{const e=t.children[0];return e&&Jm(e)?(e.geometry.computeBoundingSphere(),e.geometry.boundingSphere?.center.clone()??null):null};let e;if(this instanceof yy){if(this.selectedShapes.length<2)return;const i=this.selectedShapes[0].obj,n=this.selectedShapes[1].obj,s=t(i),r=t(n);if(!s||!r)return;this.point1=i.localToWorld(s),this.point2=n.localToWorld(r),e={groups:[{distance:2.345,info:"center"},{"point 1":this.point1.toArray(),"point 2":this.point2.toArray()},{angle:43.21,"reference 1":"Plane (Face)","reference 2":"Plane (Face)"}],type:"backend_response",refpoint1:this.point1.toArray(),refpoint2:this.point2.toArray()}}else{if(!(this instanceof _y))return;{const i=this.selectedShapes[0].obj,n=t(i);if(!n)return;this.point1=i.localToWorld(n),e={type:"backend_response",shape_type:"Edge",geom_type:"EllipseArc",refpoint:this.point1.toArray(),groups:[{center:this.point1.toArray(),"major radius":.4,"minor radius":.2},{start:[2.4,-1,0],end:[1.8,-.8267949192431111,0]},{length:.6868592404716374},{bb:{min:[1.8,-1,0],center:[2.1,-.9,0],max:[2.4,-.8,0],size:[.56,.2,0]}}]}}}this.handleResponse(e)},t)}else this.viewer?.checkChanges({selectedShapeIDs:[...t,this.shift]});if(this.selectedShapes.length!=this._getMaxObjSelected())return void this._hideMeasurement();new Promise((t,e)=>{this._waitResponse(t,e)}).then(t=>{this._createPanel(),this._makeLines(),this.panel?.show(!0),this._movePanel()})}removeLastSelectedObj(t=!1){if(t||this.selectedShapes.length==this._getMaxObjSelected()){const t=this.selectedShapes.pop();if(t){const e=t.objs();for(const t of e)t.clearHighlights()}this._updateMeasurement()}}_adjustArrowsScaleFactor(t){if(!this.scene)return;const e=1/t;this.scene.children.forEach(t=>{t instanceof my&&t.update(e)})}update(){if(!this.viewer||!this.viewer.camera||!this.scene)return;const t=this.viewer.camera.getCamera(),e=this.viewer.camera.getZoom(),i=this.viewer.state.get("cadWidth"),n=this.viewer.state.get("height");"number"==typeof i&&"number"==typeof n&&(this.coneLength=this.viewer.bb_radius/(Math.max(i,n)/60)),this._adjustArrowsScaleFactor(e),this.viewer.renderer.clearDepth(),this._movePanel(),this.viewer.renderer.render(this.scene,t)}disposeArrows(){this.scene&&(Qm(this.scene),this.scene.clear())}dispose(){this.panel&&(this.panel.show(!1),Qm(this.panel)),this.disposeArrows(),this.panel=null,this.viewer=null,this.scene=null}}function gy(t){return null!==t&&"refpoint1"in t&&"refpoint2"in t}function vy(t){return null!==t&&"refpoint"in t}class yy extends fy{constructor(t,e){super(t,new dy(t.display)),this.point1=null,this.point2=null,this.middlePoint=null,this.debug=e}_createPanel(){this.panel instanceof dy&&gy(this.responseData)&&this.panel.createTable(this.responseData)}_getMaxObjSelected(){return 2}_getPoints(){gy(this.responseData)&&(this.responseData.refpoint1&&(this.point1=new xi(...this.responseData.refpoint1)),this.responseData.refpoint2&&(this.point2=new xi(...this.responseData.refpoint2)))}_makeLines(){if(!this.scene||0!==this.scene.children.length)return;if(!(this.coneLength&&this.point1&&this.point2&&this.panelCenter))return;const t=new my(this.coneLength,this.point1,this.point2,1.5,this.measurementLineColor);this.scene.add(t),this.middlePoint=(new xi).addVectors(this.point1,this.point2).multiplyScalar(.5);const e=new my(this.coneLength,this.panelCenter,this.middlePoint,1.5,this.connectingLineColor,!1,!1);this.scene.add(e)}_updateConnectionLine(){if(!this.scene||!this.middlePoint||!this.panelCenter)return;const t=this.scene.children[1];if(!(t instanceof my))return;const e=t.children.find(t=>sf(t));e&&sf(e)&&e.geometry.setPositions([...this.middlePoint.toArray(),...this.panelCenter.toArray()])}handleResponse(t){this.responseData={...t},this._getPoints()}}class _y extends fy{constructor(t,e){super(t,new uy(t.display)),this.middlePoint=null,this.debug=e}_createPanel(){this.panel instanceof uy&&vy(this.responseData)&&this.panel.createTable(this.responseData)}_getMaxObjSelected(){return 1}_getPoint(){vy(this.responseData)&&this.responseData.refpoint&&(this.point1=new xi(...this.responseData.refpoint))}_makeLines(){if(!this.scene||0!==this.scene.children.length)return;if(!this.coneLength||!this.panelCenter||!this.point1)return;this.middlePoint=this.point1;const t=new my(this.coneLength,this.panelCenter,this.middlePoint,1.5,this.connectingLineColor,!1,!1);this.scene.add(t)}_updateConnectionLine(){if(!this.scene||!this.middlePoint||!this.panelCenter)return;const t=this.scene.children[0];if(!(t instanceof my))return;const e=t.children.find(t=>sf(t));e&&sf(e)&&e.geometry.setPositions([...this.middlePoint.toArray(),...this.panelCenter.toArray()])}handleResponse(t){this.responseData={...t},this._getPoint()}}class xy{constructor(t){this.viewer=t,this.selectedShapes=[],this.contextEnabled=!1}enableContext(){this.contextEnabled=!0}disableContext(){this.contextEnabled=!1;for(const t of this.selectedShapes)t.obj.clearHighlights();this.selectedShapes=[]}_getMaxObjSelected(){return null}_getIndex(t){const e=t.split("|");return e[e.length-1].split("_")[1]}_includes(t){for(const e of this.selectedShapes)if(t===e.obj.name)return!0;return!1}notify(){const t=[];for(const e of this.selectedShapes){const i=e.obj.name;t.push(this._getIndex(i))}this.viewer.checkChanges({selected:t},!0)}handleSelection(t){if(!t)return;const e=t.obj.name;this._includes(e)?this.selectedShapes=this.selectedShapes.filter(t=>t.obj.name!==e):this.selectedShapes.push(t),this.notify()}_removeLastSelectedObj(t){if(t){const e=t.objs();for(const t of e)t.clearHighlights()}this.notify()}removeLastSelectedObj(t){if(t){for(const t of this.selectedShapes)this._removeLastSelectedObj(t);this.selectedShapes=[]}else{const t=this.selectedShapes.pop();this._removeLastSelectedObj(t),this.notify()}}update(){}handleResponse(t){}dispose(){this.disableContext()}}const by="None",Sy="DistanceMeasurement",My="PropertiesMeasurement",wy="SelectObjects";class Ay{constructor(t,e){this.viewer=t,this.distanceMeasurement=new yy(t,e),this.propertiesMeasurement=new _y(t,e),this.selectObject=new xy(t),this.enabledTool=null}enable(t){switch(this.enabledTool&&this.disable(),t){case Sy:this.distanceMeasurement.enableContext();break;case My:this.propertiesMeasurement.enableContext();break;case wy:this.selectObject.enableContext();break;default:throw new Error(`Unknown tool type: ${t}`)}this.enabledTool=t}disable(){this.enabledTool&&(this.viewer.display.shapeFilterDropDownMenu.reset(),this._disable())}_disable(){if(this.enabledTool){switch(this.enabledTool){case Sy:this.distanceMeasurement.disableContext();break;case My:this.propertiesMeasurement.disableContext();break;case wy:this.selectObject.disableContext();break;default:throw new Error(`Unknown tool type: ${this.enabledTool}`)}this.enabledTool=null}}handleRemoveLastSelection(t=!1){this.distanceMeasurement.contextEnabled?this.distanceMeasurement.removeLastSelectedObj(t):this.propertiesMeasurement.contextEnabled?this.propertiesMeasurement.removeLastSelectedObj(t):this.selectObject.contextEnabled&&this.selectObject.removeLastSelectedObj(!1)}handleSelectedObj(t,e,i){this.distanceMeasurement.contextEnabled?(e&&this.distanceMeasurement.removeLastSelectedObj(),this.distanceMeasurement.handleSelection(t,i)):this.propertiesMeasurement.contextEnabled?(e&&this.propertiesMeasurement.removeLastSelectedObj(),this.propertiesMeasurement.handleSelection(t)):this.selectObject.contextEnabled&&this.selectObject.handleSelection(t)}handleResetSelection(){this.distanceMeasurement.contextEnabled?(this.distanceMeasurement.removeLastSelectedObj(!0),this.distanceMeasurement.removeLastSelectedObj(!0)):this.propertiesMeasurement.contextEnabled?this.propertiesMeasurement.removeLastSelectedObj(!0):this.selectObject.contextEnabled&&this.selectObject.removeLastSelectedObj(!0)}handleResponse(t){switch(t.tool_type){case Sy:this.distanceMeasurement.handleResponse(t);break;case My:this.propertiesMeasurement.handleResponse(t);break;case wy:this.selectObject.handleResponse(t)}}update(){this.distanceMeasurement.contextEnabled?this.distanceMeasurement.update():this.propertiesMeasurement.contextEnabled?this.propertiesMeasurement.update():this.selectObject.contextEnabled&&this.selectObject.update()}dispose(){this.distanceMeasurement.dispose(),this.propertiesMeasurement.dispose(),this.selectObject.dispose()}}const Ey="4.3.6";class Ty extends Rn{constructor(){super(),this.name="CleanRoomEnvironment",this.position.y=-3.5,this.rotation.y=45*Math.PI/180;const t=new Qa;t.deleteAttribute("uv");const e=new Pl({side:1}),i=new Oh(16777215,900,28,2);i.position.set(.418,16.199,.3),this.add(i);const n=new xr(t,e);n.position.set(-.757,13.219,.717),n.scale.set(31.713,28.305,28.591),this.add(n);const s=15.8565,r=13.219-14.1525,a=-.757-s,o=new xr(function(t,e,i){const n=[],s=[],r=[],a=-1;for(let r=0;r<=i;r++){const o=r/i*Math.PI/2,l=a*e*Math.sin(o),h=e*(1-Math.cos(o)),c=a*Math.sin(o),d=-Math.cos(o);n.push(0,h,l),s.push(0,d,c),n.push(t,h,l),s.push(0,d,c)}for(let t=0;t<i;t++){const e=2*t,i=e+1,n=e+2,s=e+3;r.push(e,n,i,i,n,s)}const o=new Ds;return o.setAttribute("position",new vs(n,3)),o.setAttribute("normal",new vs(s,3)),o.setIndex(r),o}(2*s,6,12),e);o.position.set(a,r,-7.5785),this.add(o);const l=new xr(t,Cy(50));l.position.set(-16.116,14.37,8.208),l.scale.set(.1,2.428,2.739),this.add(l);const h=new xr(t,Cy(50));h.position.set(-16.109,18.021,-8.207),h.scale.set(.1,2.425,2.751),this.add(h);const c=new xr(t,Cy(17));c.position.set(14.904,12.198,-1.832),c.scale.set(.15,4.265,6.331),this.add(c);const d=new xr(t,Cy(43));d.position.set(-.462,8.89,14.52),d.scale.set(4.38,5.441,.088),this.add(d);const u=new xr(t,Cy(20));u.position.set(3.235,11.486,-12.541),u.scale.set(2.5,2,.1),this.add(u);const p=new xr(t,Cy(100));p.position.set(0,20,0),p.scale.set(1,.1,1),this.add(p)}dispose(){const t=new Set;this.traverse(e=>{if("isMesh"in e&&e.isMesh){const i=e;t.add(i.geometry),Array.isArray(i.material)||t.add(i.material)}});for(const e of t)e.dispose()}}function Cy(t){return new Fl({color:0,emissive:16777215,emissiveIntensity:t})}class Dy extends gh{constructor(t){super(t),this.type=ft}parse(t){const e=function(t,e){switch(t){case 1:throw new Error("THREE.HDRLoader: Read Error: "+(e||""));case 2:throw new Error("THREE.HDRLoader: Write Error: "+(e||""));case 3:throw new Error("THREE.HDRLoader: Bad File Format: "+(e||""));default:throw new Error("THREE.HDRLoader: Memory Error: "+(e||""))}},i=function(t,e,i){e=e||1024;let n=t.pos,s=-1,r=0,a="",o=String.fromCharCode.apply(null,new Uint16Array(t.subarray(n,n+128)));for(;0>(s=o.indexOf("\n"))&&r<e&&n<t.byteLength;)a+=o,r+=o.length,n+=128,o+=String.fromCharCode.apply(null,new Uint16Array(t.subarray(n,n+128)));return-1<s&&(t.pos+=r+s+1,a+o.slice(0,s))},n=function(t,e,i,n){const s=t[e+3],r=Math.pow(2,s-128)/255;i[n+0]=t[e+0]*r,i[n+1]=t[e+1]*r,i[n+2]=t[e+2]*r,i[n+3]=1},s=function(t,e,i,n){const s=t[e+3],r=Math.pow(2,s-128)/255;i[n+0]=cs.toHalfFloat(Math.min(t[e+0]*r,65504)),i[n+1]=cs.toHalfFloat(Math.min(t[e+1]*r,65504)),i[n+2]=cs.toHalfFloat(Math.min(t[e+2]*r,65504)),i[n+3]=cs.toHalfFloat(1)},r=new Uint8Array(t);r.pos=0;const a=function(t){const n=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,s=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,r=/^\s*FORMAT=(\S+)\s*$/,a=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,o={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let l,h;for((t.pos>=t.byteLength||!(l=i(t)))&&e(1,"no header found"),(h=l.match(/^#\?(\S+)/))||e(3,"bad initial token"),o.valid|=1,o.programtype=h[1],o.string+=l+"\n";l=i(t),!1!==l;)if(o.string+=l+"\n","#"!==l.charAt(0)){if((h=l.match(n))&&(o.gamma=parseFloat(h[1])),(h=l.match(s))&&(o.exposure=parseFloat(h[1])),(h=l.match(r))&&(o.valid|=2,o.format=h[1]),(h=l.match(a))&&(o.valid|=4,o.height=parseInt(h[1],10),o.width=parseInt(h[2],10)),2&o.valid&&4&o.valid)break}else o.comments+=l+"\n";return 2&o.valid||e(3,"missing format specifier"),4&o.valid||e(3,"missing image size specifier"),o}(r),o=a.width,l=a.height,h=function(t,i,n){const s=i;if(s<8||s>32767||2!==t[0]||2!==t[1]||128&t[2])return new Uint8Array(t);s!==(t[2]<<8|t[3])&&e(3,"wrong scanline width");const r=new Uint8Array(4*i*n);r.length||e(4,"unable to allocate buffer space");let a=0,o=0;const l=4*s,h=new Uint8Array(4),c=new Uint8Array(l);let d=n;for(;d>0&&o<t.byteLength;){o+4>t.byteLength&&e(1),h[0]=t[o++],h[1]=t[o++],h[2]=t[o++],h[3]=t[o++],2==h[0]&&2==h[1]&&(h[2]<<8|h[3])==s||e(3,"bad rgbe scanline format");let i,n=0;for(;n<l&&o<t.byteLength;){i=t[o++];const s=i>128;if(s&&(i-=128),(0===i||n+i>l)&&e(3,"bad scanline data"),s){const e=t[o++];for(let t=0;t<i;t++)c[n++]=e}else c.set(t.subarray(o,o+i),n),n+=i,o+=i}const u=s;for(let t=0;t<u;t++){let e=0;r[a]=c[t+e],e+=s,r[a+1]=c[t+e],e+=s,r[a+2]=c[t+e],e+=s,r[a+3]=c[t+e],a+=4}d--}return r}(r.subarray(r.pos),o,l);let c,d,u;switch(this.type){case mt:u=h.length/4;const t=new Float32Array(4*u);for(let e=0;e<u;e++)n(h,4*e,t,4*e);c=t,d=mt;break;case ft:u=h.length/4;const e=new Uint16Array(4*u);for(let t=0;t<u;t++)s(h,4*t,e,4*t);c=e,d=ft;break;default:throw new Error("THREE.HDRLoader: Unsupported type: "+this.type)}return{width:o,height:l,data:c,header:a.string,gamma:a.gamma,exposure:a.exposure,type:d}}setDataType(t){return this.type=t,this}load(t,e,i,n){return super.load(t,function(t,i){switch(t.type){case mt:case ft:t.colorSpace=Te,t.minFilter=rt,t.magFilter=rt,t.generateMipmaps=!1,t.flipY=!0}e&&e(t,i)},i,n)}}const Ry=128,Py=64;function Iy(t){const e=t>>15&1,i=t>>10&31,n=1023&t;return 0===i?(e?-1:1)*Math.pow(2,-14)*(n/1024):31===i?n?NaN:e?-1/0:1/0:(e?-1:1)*Math.pow(2,i-15)*(1+n/1024)}function Ly(){return{lights:[{direction:function(t){const e=Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);return 0===e?[0,1,0]:[t[0]/e,t[1]/e,t[2]/e]}([.3,.8,.5]),intensity:1,color:[1,1,1]}],wasAnalyzed:!1}}const By=new En(.18,.18,.18),Oy=new yi,Fy=new En(.03,.03,.03),Ny=new En(1,1,1);function Uy(t,e){const i=512,n=document.createElement("canvas");n.width=i,n.height=i;const s=n.getContext("2d"),r=s.createRadialGradient(256,256,0,256,256,358.4);r.addColorStop(0,t),r.addColorStop(1,e),s.fillStyle=e,s.fillRect(0,0,i,i),s.fillStyle=r,s.fillRect(0,0,i,i);const a=new Xa(n);return a.colorSpace=Ee,a}let ky=null,zy=null;const Gy=["studio_small_08","studio_small_03","white_studio_05","white_studio_03","photo_studio_01","studio_small_09","cyclorama_hard_light","canary_wharf","kiara_1_dawn","empty_warehouse_01","san_giuseppe_bridge"];function Hy(t){const e=t?"4k":"2k",i={};for(const t of Gy)i[t]=`https://dl.polyhaven.org/file/ph-assets/HDRIs/hdr/${e}/${t}_${e}.hdr`;return i}class Vy{constructor(t={}){this._cache=new Map,this._lightDetectionCache=new Map,this._inflight=new Map,this._pmremGenerator=null,this._use4k=!1,this._userOverrides={},this._hdrLoader=null,this._currentTexture=null,this._disposed=!1,this._bgScene=null,this._bgCamera=null,this._bgRenderTarget=null,this._orthoEnvMainScene=null,this._envBackgroundActive=!1,this._deferredApply=null,this._userOverrides=t.presetUrls??{},this._presetUrls={...Hy(!1),...this._userOverrides}}async loadEnvironment(t,e){if(this._disposed)return Fm.warn("EnvironmentManager.loadEnvironment() called after dispose"),null;if("none"===t)return this._currentTexture=null,null;const i=t,n=this._cache.get(i);if(n)return Fm.debug(`Environment "${i}" loaded from cache`),this._currentTexture=n.texture,n.texture;const s=this._inflight.get(i);if(s){Fm.debug(`Environment "${i}" already loading, reusing promise`);const t=await s;return this._currentTexture=t,t}const r=this._load(t,e);this._inflight.set(i,r);try{const t=await r;if(this._currentTexture=t,this._deferredApply){const{scene:t,envIntensity:e,upIsZ:i,ortho:n}=this._deferredApply;this._deferredApply=null,this.apply(t,e,"environment",i,n)}return t}finally{this._inflight.delete(i)}}apply(t,e,i="grey",n=!0,s=!1,r=0){const a=r*Math.PI/180;switch(this._currentTexture?(t.environment=this._currentTexture,t.environmentIntensity=e,n?t.environmentRotation.set(Math.PI/2,0,a):t.environmentRotation.set(0,a,0)):(t.environment=null,t.environmentIntensity=1,t.environmentRotation.set(0,0,0)),"environment"!==i&&(this._deferredApply=null),i){case"white":t.background=Ny,t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground();break;case"gradient":t.background=(ky||(ky=Uy("#f0f0f0","#c8c8c8")),ky),t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground();break;case"gradient-dark":t.background=(zy||(zy=Uy("#808080","#606060")),zy),t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground();break;case"environment":this._currentTexture?(this._setupEnvBackground(t,this._currentTexture,n,a),this._deferredApply=null):(this._deferredApply={scene:t,envIntensity:e,upIsZ:n,ortho:s},t.background=By,t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground());break;case"transparent":t.background=null,t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground();break;case"darkgrey":t.background=Fy,t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground();break;default:t.background=By,t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground()}}remove(t){this._deferredApply=null,this._teardownEnvBackground(),t.environment=null,t.background=null,t.environmentIntensity=1,t.environmentRotation.set(0,0,0),t.backgroundIntensity=1,t.backgroundBlurriness=0,t.backgroundRotation.set(0,0,0)}async setUse4kEnvMaps(t,e,i){if(t===this._use4k)return this._currentTexture;this._use4k=t,this._presetUrls={...Hy(t),...this._userOverrides};for(const t of Gy){const e=this._cache.get(t);e&&(zm.untrack("texture",e.texture),e.dispose(),this._cache.delete(t),this._lightDetectionCache.delete(t),Fm.debug(`Evicted cached environment "${t}" for resolution switch`))}return e&&"none"!==e&&"studio"!==e?this.loadEnvironment(e,i):this._currentTexture}get use4kEnvMaps(){return this._use4k}isPreset(t){return Gy.includes(t)}get isEnvBackgroundActive(){return this._envBackgroundActive}getLightDetection(t){return this._lightDetectionCache.get(t)??null}updateEnvBackground(t,e){if(!(this._envBackgroundActive&&this._bgScene&&this._bgCamera&&this._orthoEnvMainScene))return;const i=t.getDrawingBufferSize(Oy),n=i.x,s=i.y;this._bgRenderTarget&&this._bgRenderTarget.width===n&&this._bgRenderTarget.height===s||(this._bgRenderTarget?.dispose(),this._bgRenderTarget=new Gi(n,s));const r=n/s;this._bgCamera.aspect!==r&&(this._bgCamera.aspect=r,this._bgCamera.updateProjectionMatrix()),e&&this._bgCamera.quaternion.copy(e.quaternion),t.setRenderTarget(this._bgRenderTarget),t.clear(),t.render(this._bgScene,this._bgCamera),t.setRenderTarget(null),this._orthoEnvMainScene.background=this._bgRenderTarget.texture,this._orthoEnvMainScene.backgroundIntensity=1,this._orthoEnvMainScene.backgroundBlurriness=0}dispose(){this._disposed=!0,this._currentTexture=null,this._deferredApply=null,this._teardownEnvBackground(),this._bgScene=null,this._bgCamera=null,this._bgRenderTarget&&(this._bgRenderTarget.dispose(),this._bgRenderTarget=null);for(const[t,e]of this._cache)zm.untrack("texture",e.texture),e.dispose(),Fm.debug(`Disposed cached environment render target: ${t}`);this._cache.clear(),this._lightDetectionCache.clear(),this._inflight.clear(),this._pmremGenerator&&(this._pmremGenerator.dispose(),this._pmremGenerator=null,Fm.debug("Disposed PMREMGenerator")),this._hdrLoader=null,function(){ky&&(ky.dispose(),ky=null);zy&&(zy.dispose(),zy=null)}()}_setupEnvBackground(t,e,i,n=0){this._bgScene||(this._bgScene=new Rn),this._bgCamera||(this._bgCamera=new Ph(50,1,.1,10)),this._bgScene.background=e,this._bgScene.backgroundIntensity=1,this._bgScene.backgroundBlurriness=0,i?this._bgScene.backgroundRotation.set(Math.PI/2,0,n):this._bgScene.backgroundRotation.set(0,n,0),this._orthoEnvMainScene=t,this._envBackgroundActive=!0}_teardownEnvBackground(){this._envBackgroundActive=!1,this._orthoEnvMainScene=null}_resolveUrl(t){if("studio"===t)return null;const e=this._presetUrls[t];return e||t}_ensurePmremGenerator(t){return this._pmremGenerator||(this._pmremGenerator=new Fd(t),Fm.debug("Created PMREMGenerator")),this._pmremGenerator}_ensureHdrLoader(){return this._hdrLoader||(this._hdrLoader=new Dy,Fm.debug("Created HDRLoader")),this._hdrLoader}async _load(t,e){if("studio"===t)return this._loadRoomEnvironment(t,e);const i=this._resolveUrl(t);try{return await this._loadHdr(i,t,e)}catch(n){if(this._disposed)throw n;const s=t in this._presetUrls?t:`custom URL (${i})`;return Fm.warn(`Could not load environment "${s}", using default "studio" environment.`,n instanceof Error?n.message:n),this._loadRoomEnvironment("studio",e)}}_loadRoomEnvironment(t,e){if(this._disposed)throw new Error("EnvironmentManager was disposed");const i=this._cache.get(t);if(i)return i.texture;const n=this._ensurePmremGenerator(e),s=new Ty,r=n.fromScene(s,0,.1,100,{size:2048});return s.traverse(t=>{t instanceof xr&&(t.geometry.dispose(),Array.isArray(t.material)?t.material.forEach(t=>t.dispose()):t.material.dispose())}),this._cache.set(t,r),zm.trackTexture(r.texture,`PMREM environment: ${t}`),this._lightDetectionCache.set(t,Ly()),Fm.debug(`Generated RoomEnvironment PMREM, cached as "${t}"`),r.texture}async _loadHdr(t,e,i){const n=this._ensureHdrLoader(),s=this._ensurePmremGenerator(i);Fm.debug(`Loading HDR environment from: ${t}`);const r=await Promise.race([n.loadAsync(t),new Promise((e,i)=>setTimeout(()=>i(new Error(`HDR load timed out after 30 s: ${t}`)),3e4))]);if(this._disposed)throw r.dispose(),new Error("EnvironmentManager was disposed during HDR load");const a=s.fromEquirectangular(r);if(r.image?.data&&r.image.width&&r.image.height){const t=function(t,e,i){const n=t instanceof Uint16Array,s=t.length/(e*i);if(s<3)return Fm.warn("Light detection: unexpected channel count",s),{lights:[],wasAnalyzed:!1};const r=new Float32Array(8192),a=new Float32Array(8192),o=new Float32Array(8192),l=new Float32Array(8192),h=new Float32Array(8192);for(let c=0;c<i;c++){const d=Math.min(Math.floor(c/i*Py),63),u=(.5-c/i)*Math.PI,p=Math.cos(u);for(let i=0;i<e;i++){const u=Math.min(Math.floor(i/e*Ry),127),m=(c*e+i)*s;let f,g,v;n?(f=Iy(t[m]),g=Iy(t[m+1]),v=Iy(t[m+2])):(f=t[m],g=t[m+1],v=t[m+2]),f=Math.max(0,f),g=Math.max(0,g),v=Math.max(0,v);const y=.2126*f+.7152*g+.0722*v,_=d*Ry+u;r[_]+=y*p,a[_]+=f*p,o[_]+=g*p,l[_]+=v*p,h[_]+=p}}for(let t=0;t<r.length;t++)h[t]>0&&(r[t]/=h[t],a[t]/=h[t],o[t]/=h[t],l[t]/=h[t]);const c=Array.from(r).filter(t=>t>0).sort((t,e)=>t-e);if(0===c.length)return{lights:[],wasAnalyzed:!0};const d=10*c[Math.floor(c.length/2)],u=new Uint8Array(8192);for(let t=0;t<r.length;t++)u[t]=r[t]>=d?1:0;const p=new Uint8Array(8192),m=[];for(let t=0;t<Py;t++)for(let e=0;e<Ry;e++){const i=t*Ry+e;if(!u[i]||p[i])continue;const n={totalLum:0,totalR:0,totalG:0,totalB:0,weightedGx:0,weightedGy:0,count:0},s=[i];for(p[i]=1;s.length>0;){const t=s.pop(),e=Math.floor(t/Ry),i=t%Ry,h=r[t];n.totalLum+=h,n.totalR+=a[t]*h,n.totalG+=o[t]*h,n.totalB+=l[t]*h,n.weightedGx+=i*h,n.weightedGy+=e*h,n.count++;const c=[[i,e-1],[i,e+1],[(i-1+Ry)%Ry,e],[(i+1)%Ry,e]];for(const[t,e]of c){if(e<0||e>=Py)continue;const i=e*Ry+t;u[i]&&!p[i]&&(p[i]=1,s.push(i))}}n.count>0&&m.push(n)}if(0===m.length)return{lights:[],wasAnalyzed:!0};m.sort((t,e)=>e.totalLum-t.totalLum);const f=m.slice(0,1),g=f[0].totalLum,v=f.map(t=>{const e=t.weightedGx/t.totalLum,i=t.weightedGy/t.totalLum/Py,n=2*(e/Ry-.5)*Math.PI,s=(.5-i)*Math.PI,r=Math.cos(s),a=[Math.cos(n)*r,Math.sin(s),Math.sin(n)*r],o=t.totalR+t.totalG+t.totalB;let l;return o>0?(l=[t.totalR/o*3,t.totalG/o*3,t.totalB/o*3],l=[Math.min(1,l[0]),Math.min(1,l[1]),Math.min(1,l[2])]):l=[1,1,1],{direction:a,intensity:t.totalLum/g,color:l}});return Fm.debug(`Light detection: found ${v.length} dominant light(s) from ${m.length} cluster(s)`),{lights:v,wasAnalyzed:!0}}(r.image.data,r.image.width,r.image.height);this._lightDetectionCache.set(e,t)}return r.dispose(),this._cache.set(e,a),zm.trackTexture(a.texture,`PMREM environment: ${e}`),Fm.debug(`Loaded HDR environment from "${t}", cached as "${e}"`),a.texture}}class Wy{constructor(){this._shadowPlane=null,this._shadowsEnabled=!1,this.group=new _n,this.group.name="studioFloor",this.group.visible=!1}configure(t,e){this._clearCurrent(),this._createShadowPlane(t,e)}setShadowsEnabled(t){this._shadowsEnabled=t,this._shadowPlane&&(this._shadowPlane.visible=t),this.group.visible=this._shadowsEnabled}setShadowIntensity(t){this._shadowPlane&&(this._shadowPlane.material.opacity=1*t)}dispose(){this._clearCurrent()}_createShadowPlane(t,e){const i=6*e,n=new pl(i,i),s=new wl({opacity:.5,depthWrite:!1}),r=new xr(n,s);r.position.z=t,r.receiveShadow=!0,r.name="studioShadowPlane",r.visible=this._shadowsEnabled,this._shadowPlane=r,this.group.add(r)}_clearCurrent(){this._shadowPlane&&(this.group.remove(this._shadowPlane),this._shadowPlane.geometry.dispose(),this._shadowPlane.material.dispose(),this._shadowPlane=null)}}
|
|
12
|
+
function md(){let t=null,e=!1,i=null,n=null;function s(e,r){i(e,r),n=t.requestAnimationFrame(s)}return{start:function(){!0!==e&&null!==i&&(n=t.requestAnimationFrame(s),e=!0)},stop:function(){t.cancelAnimationFrame(n),e=!1},setAnimationLoop:function(t){i=t},setContext:function(e){t=e}}}function fd(t){const e=new WeakMap;return{get:function(t){return t.isInterleavedBufferAttribute&&(t=t.data),e.get(t)},remove:function(i){i.isInterleavedBufferAttribute&&(i=i.data);const n=e.get(i);n&&(t.deleteBuffer(n.buffer),e.delete(i))},update:function(i,n){if(i.isInterleavedBufferAttribute&&(i=i.data),i.isGLBufferAttribute){const t=e.get(i);return void((!t||t.version<i.version)&&e.set(i,{buffer:i.buffer,type:i.type,bytesPerElement:i.elementSize,version:i.version}))}const s=e.get(i);if(void 0===s)e.set(i,function(e,i){const n=e.array,s=e.usage,r=n.byteLength,a=t.createBuffer();let o;if(t.bindBuffer(i,a),t.bufferData(i,n,s),e.onUploadCallback(),n instanceof Float32Array)o=t.FLOAT;else if("undefined"!=typeof Float16Array&&n instanceof Float16Array)o=t.HALF_FLOAT;else if(n instanceof Uint16Array)o=e.isFloat16BufferAttribute?t.HALF_FLOAT:t.UNSIGNED_SHORT;else if(n instanceof Int16Array)o=t.SHORT;else if(n instanceof Uint32Array)o=t.UNSIGNED_INT;else if(n instanceof Int32Array)o=t.INT;else if(n instanceof Int8Array)o=t.BYTE;else if(n instanceof Uint8Array)o=t.UNSIGNED_BYTE;else{if(!(n instanceof Uint8ClampedArray))throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+n);o=t.UNSIGNED_BYTE}return{buffer:a,type:o,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version,size:r}}(i,n));else if(s.version<i.version){if(s.size!==i.array.byteLength)throw new Error("THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.");!function(e,i,n){const s=i.array,r=i.updateRanges;if(t.bindBuffer(n,e),0===r.length)t.bufferSubData(n,0,s);else{r.sort((t,e)=>t.start-e.start);let e=0;for(let t=1;t<r.length;t++){const i=r[e],n=r[t];n.start<=i.start+i.count+1?i.count=Math.max(i.count,n.start+n.count-i.start):(++e,r[e]=n)}r.length=e+1;for(let e=0,i=r.length;e<i;e++){const i=r[e];t.bufferSubData(n,i.start*s.BYTES_PER_ELEMENT,s,i.start,i.count)}i.clearUpdateRanges()}i.onUploadCallback()}(s.buffer,i,n),s.version=i.version}}}}"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:e}})),"undefined"!=typeof window&&(window.__THREE__?ii("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=e);const gd={alphahash_fragment:"#ifdef USE_ALPHAHASH\n\tif ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;\n#endif",alphahash_pars_fragment:"#ifdef USE_ALPHAHASH\n\tconst float ALPHA_HASH_SCALE = 0.05;\n\tfloat hash2D( vec2 value ) {\n\t\treturn fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );\n\t}\n\tfloat hash3D( vec3 value ) {\n\t\treturn hash2D( vec2( hash2D( value.xy ), value.z ) );\n\t}\n\tfloat getAlphaHashThreshold( vec3 position ) {\n\t\tfloat maxDeriv = max(\n\t\t\tlength( dFdx( position.xyz ) ),\n\t\t\tlength( dFdy( position.xyz ) )\n\t\t);\n\t\tfloat pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );\n\t\tvec2 pixScales = vec2(\n\t\t\texp2( floor( log2( pixScale ) ) ),\n\t\t\texp2( ceil( log2( pixScale ) ) )\n\t\t);\n\t\tvec2 alpha = vec2(\n\t\t\thash3D( floor( pixScales.x * position.xyz ) ),\n\t\t\thash3D( floor( pixScales.y * position.xyz ) )\n\t\t);\n\t\tfloat lerpFactor = fract( log2( pixScale ) );\n\t\tfloat x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;\n\t\tfloat a = min( lerpFactor, 1.0 - lerpFactor );\n\t\tvec3 cases = vec3(\n\t\t\tx * x / ( 2.0 * a * ( 1.0 - a ) ),\n\t\t\t( x - 0.5 * a ) / ( 1.0 - a ),\n\t\t\t1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )\n\t\t);\n\t\tfloat threshold = ( x < ( 1.0 - a ) )\n\t\t\t? ( ( x < a ) ? cases.x : cases.y )\n\t\t\t: cases.z;\n\t\treturn clamp( threshold , 1.0e-6, 1.0 );\n\t}\n#endif",alphamap_fragment:"#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;\n#endif",alphamap_pars_fragment:"#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",alphatest_fragment:"#ifdef USE_ALPHATEST\n\t#ifdef ALPHA_TO_COVERAGE\n\tdiffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );\n\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\tif ( diffuseColor.a < alphaTest ) discard;\n\t#endif\n#endif",alphatest_pars_fragment:"#ifdef USE_ALPHATEST\n\tuniform float alphaTest;\n#endif",aomap_fragment:"#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_CLEARCOAT ) \n\t\tclearcoatSpecularIndirect *= ambientOcclusion;\n\t#endif\n\t#if defined( USE_SHEEN ) \n\t\tsheenSpecularIndirect *= ambientOcclusion;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\t#endif\n#endif",aomap_pars_fragment:"#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif",batching_pars_vertex:"#ifdef USE_BATCHING\n\t#if ! defined( GL_ANGLE_multi_draw )\n\t#define gl_DrawID _gl_DrawID\n\tuniform int _gl_DrawID;\n\t#endif\n\tuniform highp sampler2D batchingTexture;\n\tuniform highp usampler2D batchingIdTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n\tfloat getIndirectIndex( const in int i ) {\n\t\tint size = textureSize( batchingIdTexture, 0 ).x;\n\t\tint x = i % size;\n\t\tint y = i / size;\n\t\treturn float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );\n\t}\n#endif\n#ifdef USE_BATCHING_COLOR\n\tuniform sampler2D batchingColorTexture;\n\tvec4 getBatchingColor( const in float i ) {\n\t\tint size = textureSize( batchingColorTexture, 0 ).x;\n\t\tint j = int( i );\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\treturn texelFetch( batchingColorTexture, ivec2( x, y ), 0 );\n\t}\n#endif",batching_vertex:"#ifdef USE_BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );\n#endif",begin_vertex:"vec3 transformed = vec3( position );\n#ifdef USE_ALPHAHASH\n\tvPosition = vec3( position );\n#endif",beginnormal_vertex:"vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif",bsdfs:"float G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, 1.0, dotVH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n} // validated",iridescence_fragment:"#ifdef USE_IRIDESCENCE\n\tconst mat3 XYZ_TO_REC709 = mat3(\n\t\t 3.2404542, -0.9692660, 0.0556434,\n\t\t-1.5371385, 1.8760108, -0.2040259,\n\t\t-0.4985314, 0.0415560, 1.0572252\n\t);\n\tvec3 Fresnel0ToIor( vec3 fresnel0 ) {\n\t\tvec3 sqrtF0 = sqrt( fresnel0 );\n\t\treturn ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );\n\t}\n\tvec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {\n\t\treturn pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );\n\t}\n\tfloat IorToFresnel0( float transmittedIor, float incidentIor ) {\n\t\treturn pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));\n\t}\n\tvec3 evalSensitivity( float OPD, vec3 shift ) {\n\t\tfloat phase = 2.0 * PI * OPD * 1.0e-9;\n\t\tvec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );\n\t\tvec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );\n\t\tvec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );\n\t\tvec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );\n\t\txyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );\n\t\txyz /= 1.0685e-7;\n\t\tvec3 rgb = XYZ_TO_REC709 * xyz;\n\t\treturn rgb;\n\t}\n\tvec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {\n\t\tvec3 I;\n\t\tfloat iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );\n\t\tfloat sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );\n\t\tfloat cosTheta2Sq = 1.0 - sinTheta2Sq;\n\t\tif ( cosTheta2Sq < 0.0 ) {\n\t\t\treturn vec3( 1.0 );\n\t\t}\n\t\tfloat cosTheta2 = sqrt( cosTheta2Sq );\n\t\tfloat R0 = IorToFresnel0( iridescenceIOR, outsideIOR );\n\t\tfloat R12 = F_Schlick( R0, 1.0, cosTheta1 );\n\t\tfloat T121 = 1.0 - R12;\n\t\tfloat phi12 = 0.0;\n\t\tif ( iridescenceIOR < outsideIOR ) phi12 = PI;\n\t\tfloat phi21 = PI - phi12;\n\t\tvec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) );\t\tvec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );\n\t\tvec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );\n\t\tvec3 phi23 = vec3( 0.0 );\n\t\tif ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;\n\t\tif ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;\n\t\tif ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;\n\t\tfloat OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;\n\t\tvec3 phi = vec3( phi21 ) + phi23;\n\t\tvec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );\n\t\tvec3 r123 = sqrt( R123 );\n\t\tvec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );\n\t\tvec3 C0 = R12 + Rs;\n\t\tI = C0;\n\t\tvec3 Cm = Rs - T121;\n\t\tfor ( int m = 1; m <= 2; ++ m ) {\n\t\t\tCm *= r123;\n\t\t\tvec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );\n\t\t\tI += Cm * Sm;\n\t\t}\n\t\treturn max( I, vec3( 0.0 ) );\n\t}\n#endif",bumpmap_pars_fragment:"#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vBumpMapUv );\n\t\tvec2 dSTdy = dFdy( vBumpMapUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );\n\t\tvec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif",clipping_planes_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#ifdef ALPHA_TO_COVERAGE\n\t\tfloat distanceToPlane, distanceGradient;\n\t\tfloat clipOpacity = 1.0;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\tclipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\tif ( clipOpacity == 0.0 ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tfloat unionClipOpacity = 1.0;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\t\tunionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tclipOpacity *= 1.0 - unionClipOpacity;\n\t\t#endif\n\t\tdiffuseColor.a *= clipOpacity;\n\t\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tbool clipped = true;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tif ( clipped ) discard;\n\t\t#endif\n\t#endif\n#endif",clipping_planes_pars_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif",clipping_planes_pars_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif",clipping_planes_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif",color_fragment:"#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#endif",color_pars_fragment:"#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#endif",color_pars_vertex:"#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvarying vec4 vColor;\n#endif",color_vertex:"#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvColor = vec4( 1.0 );\n#endif\n#ifdef USE_COLOR_ALPHA\n\tvColor *= color;\n#elif defined( USE_COLOR )\n\tvColor.rgb *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.rgb *= instanceColor.rgb;\n#endif\n#ifdef USE_BATCHING_COLOR\n\tvColor *= getBatchingColor( getIndirectIndex( gl_DrawID ) );\n#endif",common:"#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\n#ifdef USE_ALPHAHASH\n\tvarying vec3 vPosition;\n#endif\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n} // validated",cube_uv_reflection_fragment:"#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\thighp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tuv.x += filterInt * 3.0 * cubeUV_minTileSize;\n\t\tuv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );\n\t\tuv.x *= CUBEUV_TEXEL_WIDTH;\n\t\tuv.y *= CUBEUV_TEXEL_HEIGHT;\n\t\t#ifdef texture2DGradEXT\n\t\t\treturn texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;\n\t\t#else\n\t\t\treturn texture2D( envMap, uv ).rgb;\n\t\t#endif\n\t}\n\t#define cubeUV_r0 1.0\n\t#define cubeUV_m0 - 2.0\n\t#define cubeUV_r1 0.8\n\t#define cubeUV_m1 - 1.0\n\t#define cubeUV_r4 0.4\n\t#define cubeUV_m4 2.0\n\t#define cubeUV_r5 0.305\n\t#define cubeUV_m5 3.0\n\t#define cubeUV_r6 0.21\n\t#define cubeUV_m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= cubeUV_r1 ) {\n\t\t\tmip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;\n\t\t} else if ( roughness >= cubeUV_r4 ) {\n\t\t\tmip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;\n\t\t} else if ( roughness >= cubeUV_r5 ) {\n\t\t\tmip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;\n\t\t} else if ( roughness >= cubeUV_r6 ) {\n\t\t\tmip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif",defaultnormal_vertex:"vec3 transformedNormal = objectNormal;\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = objectTangent;\n#endif\n#ifdef USE_BATCHING\n\tmat3 bm = mat3( batchingMatrix );\n\ttransformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );\n\ttransformedNormal = bm * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = bm * transformedTangent;\n\t#endif\n#endif\n#ifdef USE_INSTANCING\n\tmat3 im = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );\n\ttransformedNormal = im * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = im * transformedTangent;\n\t#endif\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\ttransformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif",displacementmap_pars_vertex:"#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif",displacementmap_vertex:"#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\n#endif",emissivemap_fragment:"#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE\n\t\temissiveColor = sRGBTransferEOTF( emissiveColor );\n\t#endif\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif",emissivemap_pars_fragment:"#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif",colorspace_fragment:"gl_FragColor = linearToOutputTexel( gl_FragColor );",colorspace_pars_fragment:"vec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBTransferEOTF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}",envmap_fragment:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t\t#endif\n\t#endif\n#endif",envmap_common_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform mat3 envMapRotation;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif",envmap_physical_pars_fragment:"#ifdef USE_ENVMAP\n\tvec3 getIBLIrradiance( const in vec3 normal ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );\n\t\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );\n\t\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );\n\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\t#ifdef USE_ANISOTROPY\n\t\tvec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n\t\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\t\tvec3 bentNormal = cross( bitangent, viewDir );\n\t\t\t\tbentNormal = normalize( cross( bentNormal, bitangent ) );\n\t\t\t\tbentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n\t\t\t\treturn getIBLRadiance( viewDir, bentNormal, roughness );\n\t\t\t#else\n\t\t\t\treturn vec3( 0.0 );\n\t\t\t#endif\n\t\t}\n\t#endif\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif",fog_vertex:"#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n#endif",fog_pars_vertex:"#ifdef USE_FOG\n\tvarying float vFogDepth;\n#endif",fog_fragment:"#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif",fog_pars_fragment:"#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float vFogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif",gradientmap_pars_fragment:"#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn vec3( texture2D( gradientMap, coord ).r );\n\t#else\n\t\tvec2 fw = fwidth( coord ) * 0.5;\n\t\treturn mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );\n\t#endif\n}",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif",lights_lambert_fragment:"LambertMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularStrength = specularStrength;",lights_lambert_pars_fragment:"varying vec3 vViewPosition;\nstruct LambertMaterial {\n\tvec3 diffuseColor;\n\tfloat specularStrength;\n};\nvoid RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Lambert\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Lambert",lights_pars_begin:"uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n#if defined( USE_LIGHT_PROBES )\n\tuniform vec3 lightProbe[ 9 ];\n#endif\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif ( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif",lights_toon_fragment:"ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;",lights_toon_pars_fragment:"varying vec3 vViewPosition;\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon",lights_phong_fragment:"BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;",lights_phong_pars_fragment:"varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong",lights_physical_fragment:"PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.diffuseContribution = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.metalness = metalnessFactor;\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\tmaterial.ior = ior;\n\t#ifdef USE_SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULAR_COLORMAP\n\t\t\tspecularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n\t\t#endif\n\t\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor;\n\tmaterial.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = vec3( 0.04 );\n\tmaterial.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_DISPERSION\n\tmaterial.dispersion = dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tmaterial.iridescence = iridescence;\n\tmaterial.iridescenceIOR = iridescenceIOR;\n\t#ifdef USE_IRIDESCENCEMAP\n\t\tmaterial.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n\t#endif\n\t#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\t\tmaterial.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n\t#else\n\t\tmaterial.iridescenceThickness = iridescenceThicknessMaximum;\n\t#endif\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tmaterial.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.0001, 1.0 );\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\t#ifdef USE_ANISOTROPYMAP\n\t\tmat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n\t\tvec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n\t\tvec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n\t#else\n\t\tvec2 anisotropyV = anisotropyVector;\n\t#endif\n\tmaterial.anisotropy = length( anisotropyV );\n\tif( material.anisotropy == 0.0 ) {\n\t\tanisotropyV = vec2( 1.0, 0.0 );\n\t} else {\n\t\tanisotropyV /= material.anisotropy;\n\t\tmaterial.anisotropy = saturate( material.anisotropy );\n\t}\n\tmaterial.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n\tmaterial.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;\n\tmaterial.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;\n#endif",lights_physical_pars_fragment:"uniform sampler2D dfgLUT;\nstruct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tvec3 diffuseContribution;\n\tvec3 specularColor;\n\tvec3 specularColorBlended;\n\tfloat roughness;\n\tfloat metalness;\n\tfloat specularF90;\n\tfloat dispersion;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_IRIDESCENCE\n\t\tfloat iridescence;\n\t\tfloat iridescenceIOR;\n\t\tfloat iridescenceThickness;\n\t\tvec3 iridescenceFresnel;\n\t\tvec3 iridescenceF0;\n\t\tvec3 iridescenceFresnelDielectric;\n\t\tvec3 iridescenceFresnelMetallic;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n\t#ifdef IOR\n\t\tfloat ior;\n\t#endif\n\t#ifdef USE_TRANSMISSION\n\t\tfloat transmission;\n\t\tfloat transmissionAlpha;\n\t\tfloat thickness;\n\t\tfloat attenuationDistance;\n\t\tvec3 attenuationColor;\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat anisotropy;\n\t\tfloat alphaT;\n\t\tvec3 anisotropyT;\n\t\tvec3 anisotropyB;\n\t#endif\n};\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\nvec3 sheenSpecularDirect = vec3( 0.0 );\nvec3 sheenSpecularIndirect = vec3(0.0 );\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n#ifdef USE_ANISOTROPY\n\tfloat V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {\n\t\tfloat gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n\t\tfloat gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n\t\tfloat v = 0.5 / ( gv + gl );\n\t\treturn v;\n\t}\n\tfloat D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n\t\tfloat a2 = alphaT * alphaB;\n\t\thighp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n\t\thighp float v2 = dot( v, v );\n\t\tfloat w2 = a2 / v2;\n\t\treturn RECIPROCAL_PI * a2 * pow2 ( w2 );\n\t}\n#endif\n#ifdef USE_CLEARCOAT\n\tvec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n\t\tvec3 f0 = material.clearcoatF0;\n\t\tfloat f90 = material.clearcoatF90;\n\t\tfloat roughness = material.clearcoatRoughness;\n\t\tfloat alpha = pow2( roughness );\n\t\tvec3 halfDir = normalize( lightDir + viewDir );\n\t\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\t\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\t\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\t\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\t\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t\treturn F * ( V * D );\n\t}\n#endif\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 f0 = material.specularColorBlended;\n\tfloat f90 = material.specularF90;\n\tfloat roughness = material.roughness;\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t#ifdef USE_IRIDESCENCE\n\t\tF = mix( F, material.iridescenceFresnel, material.iridescence );\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat dotTL = dot( material.anisotropyT, lightDir );\n\t\tfloat dotTV = dot( material.anisotropyT, viewDir );\n\t\tfloat dotTH = dot( material.anisotropyT, halfDir );\n\t\tfloat dotBL = dot( material.anisotropyB, lightDir );\n\t\tfloat dotBV = dot( material.anisotropyB, viewDir );\n\t\tfloat dotBH = dot( material.anisotropyB, halfDir );\n\t\tfloat V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n\t\tfloat D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\n\t#else\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t#endif\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transpose( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenColor * ( D * V );\n}\n#endif\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat rInv = 1.0 / ( roughness + 0.1 );\n\tfloat a = -1.9362 + 1.0678 * roughness + 0.4573 * r2 - 0.8469 * rInv;\n\tfloat b = -0.6014 + 0.5538 * roughness - 0.4670 * r2 - 0.1255 * rInv;\n\tfloat DG = exp( a * dotNV + b );\n\treturn saturate( DG );\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;\n\t#ifdef USE_IRIDESCENCE\n\t\tvec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n\t#else\n\t\tvec3 Fr = specularColor;\n\t#endif\n\tvec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nvec3 BRDF_GGX_Multiscatter( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 singleScatter = BRDF_GGX( lightDir, viewDir, normal, material );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 dfgV = texture2D( dfgLUT, vec2( material.roughness, dotNV ) ).rg;\n\tvec2 dfgL = texture2D( dfgLUT, vec2( material.roughness, dotNL ) ).rg;\n\tvec3 FssEss_V = material.specularColorBlended * dfgV.x + material.specularF90 * dfgV.y;\n\tvec3 FssEss_L = material.specularColorBlended * dfgL.x + material.specularF90 * dfgL.y;\n\tfloat Ess_V = dfgV.x + dfgV.y;\n\tfloat Ess_L = dfgL.x + dfgL.y;\n\tfloat Ems_V = 1.0 - Ess_V;\n\tfloat Ems_L = 1.0 - Ess_L;\n\tvec3 Favg = material.specularColorBlended + ( 1.0 - material.specularColorBlended ) * 0.047619;\n\tvec3 Fms = FssEss_V * FssEss_L * Favg / ( 1.0 - Ems_V * Ems_L * Favg + EPSILON );\n\tfloat compensationFactor = Ems_V * Ems_L;\n\tvec3 multiScatter = Fms * compensationFactor;\n\treturn singleScatter + multiScatter;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometryNormal;\n\t\tvec3 viewDir = geometryViewDir;\n\t\tvec3 position = geometryPosition;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColorBlended * t2.x + ( material.specularF90 - material.specularColorBlended ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseContribution * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t\t#ifdef USE_CLEARCOAT\n\t\t\tvec3 Ncc = geometryClearcoatNormal;\n\t\t\tvec2 uvClearcoat = LTC_Uv( Ncc, viewDir, material.clearcoatRoughness );\n\t\t\tvec4 t1Clearcoat = texture2D( ltc_1, uvClearcoat );\n\t\t\tvec4 t2Clearcoat = texture2D( ltc_2, uvClearcoat );\n\t\t\tmat3 mInvClearcoat = mat3(\n\t\t\t\tvec3( t1Clearcoat.x, 0, t1Clearcoat.y ),\n\t\t\t\tvec3( 0, 1, 0 ),\n\t\t\t\tvec3( t1Clearcoat.z, 0, t1Clearcoat.w )\n\t\t\t);\n\t\t\tvec3 fresnelClearcoat = material.clearcoatF0 * t2Clearcoat.x + ( material.clearcoatF90 - material.clearcoatF0 ) * t2Clearcoat.y;\n\t\t\tclearcoatSpecularDirect += lightColor * fresnelClearcoat * LTC_Evaluate( Ncc, viewDir, position, mInvClearcoat, rectCoords );\n\t\t#endif\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\t#endif\n\t#ifdef USE_SHEEN\n \n \t\tsheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n \n \t\tfloat sheenAlbedoV = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n \t\tfloat sheenAlbedoL = IBLSheenBRDF( geometryNormal, directLight.direction, material.sheenRoughness );\n \n \t\tfloat sheenEnergyComp = 1.0 - max3( material.sheenColor ) * max( sheenAlbedoV, sheenAlbedoL );\n \n \t\tirradiance *= sheenEnergyComp;\n \n \t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX_Multiscatter( directLight.direction, geometryViewDir, geometryNormal, material );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseContribution );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 diffuse = irradiance * BRDF_Lambert( material.diffuseContribution );\n\t#ifdef USE_SHEEN\n\t\tfloat sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t\tfloat sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;\n\t\tdiffuse *= sheenEnergyComp;\n\t#endif\n\treflectedLight.indirectDiffuse += diffuse;\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ) * RECIPROCAL_PI;\n \t#endif\n\tvec3 singleScatteringDielectric = vec3( 0.0 );\n\tvec3 multiScatteringDielectric = vec3( 0.0 );\n\tvec3 singleScatteringMetallic = vec3( 0.0 );\n\tvec3 multiScatteringMetallic = vec3( 0.0 );\n\t#ifdef USE_IRIDESCENCE\n\t\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnelDielectric, material.roughness, singleScatteringDielectric, multiScatteringDielectric );\n\t\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.diffuseColor, material.specularF90, material.iridescence, material.iridescenceFresnelMetallic, material.roughness, singleScatteringMetallic, multiScatteringMetallic );\n\t#else\n\t\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScatteringDielectric, multiScatteringDielectric );\n\t\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.diffuseColor, material.specularF90, material.roughness, singleScatteringMetallic, multiScatteringMetallic );\n\t#endif\n\tvec3 singleScattering = mix( singleScatteringDielectric, singleScatteringMetallic, material.metalness );\n\tvec3 multiScattering = mix( multiScatteringDielectric, multiScatteringMetallic, material.metalness );\n\tvec3 totalScatteringDielectric = singleScatteringDielectric + multiScatteringDielectric;\n\tvec3 diffuse = material.diffuseContribution * ( 1.0 - totalScatteringDielectric );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tvec3 indirectSpecular = radiance * singleScattering;\n\tindirectSpecular += multiScattering * cosineWeightedIrradiance;\n\tvec3 indirectDiffuse = diffuse * cosineWeightedIrradiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t\tfloat sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;\n\t\tindirectSpecular *= sheenEnergyComp;\n\t\tindirectDiffuse *= sheenEnergyComp;\n\t#endif\n\treflectedLight.indirectSpecular += indirectSpecular;\n\treflectedLight.indirectDiffuse += indirectDiffuse;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}",lights_fragment_begin:"\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n#ifdef USE_CLEARCOAT\n\tgeometryClearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\tif ( material.iridescenceThickness == 0.0 ) {\n\t\tmaterial.iridescence = 0.0;\n\t} else {\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\t}\n\tif ( material.iridescence > 0.0 ) {\n\t\tmaterial.iridescenceFresnelDielectric = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\t\tmaterial.iridescenceFresnelMetallic = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.diffuseColor );\n\t\tmaterial.iridescenceFresnel = mix( material.iridescenceFresnelDielectric, material.iridescenceFresnelMetallic, material.metalness );\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\t}\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if defined( USE_LIGHT_PROBES )\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\t#endif\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif",lights_fragment_maps:"#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\t#if defined( STANDARD ) || defined( LAMBERT ) || defined( PHONG )\n\t\t\tiblIrradiance += getIBLIrradiance( geometryNormal );\n\t\t#endif\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\t#ifdef USE_ANISOTROPY\n\t\tradiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n\t#else\n\t\tradiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif",lights_fragment_end:"#if defined( RE_IndirectDiffuse )\n\t#if defined( LAMBERT ) || defined( PHONG )\n\t\tirradiance += iblIrradiance;\n\t#endif\n\tRE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif",logdepthbuf_fragment:"#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )\n\tgl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif",logdepthbuf_pars_fragment:"#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_pars_vertex:"#ifdef USE_LOGARITHMIC_DEPTH_BUFFER\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_vertex:"#ifdef USE_LOGARITHMIC_DEPTH_BUFFER\n\tvFragDepth = 1.0 + gl_Position.w;\n\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n#endif",map_fragment:"#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif",map_pars_fragment:"#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif",map_particle_fragment:"#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t#if defined( USE_POINTS_UV )\n\t\tvec2 uv = vUv;\n\t#else\n\t\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tdiffuseColor *= texture2D( map, uv );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif",map_particle_pars_fragment:"#if defined( USE_POINTS_UV )\n\tvarying vec2 vUv;\n#else\n\t#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t\tuniform mat3 uvTransform;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",metalnessmap_fragment:"float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif",metalnessmap_pars_fragment:"#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif",morphinstance_vertex:"#ifdef USE_INSTANCING_MORPH\n\tfloat morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\tfloat morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tmorphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;\n\t}\n#endif",morphcolor_vertex:"#if defined( USE_MORPHCOLORS )\n\tvColor *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t#if defined( USE_COLOR_ALPHA )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n\t\t#elif defined( USE_COLOR )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n\t\t#endif\n\t}\n#endif",morphnormal_vertex:"#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif",morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\n\t#ifndef USE_INSTANCING_MORPH\n\t\tuniform float morphTargetBaseInfluence;\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t#endif\n\tuniform sampler2DArray morphTargetsTexture;\n\tuniform ivec2 morphTargetsTextureSize;\n\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\t\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n\t\tint y = texelIndex / morphTargetsTextureSize.x;\n\t\tint x = texelIndex - y * morphTargetsTextureSize.x;\n\t\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\n\t\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\n\t}\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif",normal_fragment_begin:"float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = dFdx( vViewPosition );\n\tvec3 fdy = dFdy( vViewPosition );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal *= faceDirection;\n\t#endif\n#endif\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn = getTangentFrame( - vViewPosition, normal,\n\t\t#if defined( USE_NORMALMAP )\n\t\t\tvNormalMapUv\n\t\t#elif defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tvClearcoatNormalMapUv\n\t\t#else\n\t\t\tvUv\n\t\t#endif\n\t\t);\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn[0] *= faceDirection;\n\t\ttbn[1] *= faceDirection;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn2[0] *= faceDirection;\n\t\ttbn2[1] *= faceDirection;\n\t#endif\n#endif\nvec3 nonPerturbedNormal = normal;",normal_fragment_maps:"#ifdef USE_NORMALMAP_OBJECTSPACE\n\tnormal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n\tvec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\tnormal = normalize( tbn * mapN );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif",normal_pars_fragment:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_pars_vertex:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_vertex:"#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif",normalmap_pars_fragment:"#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef USE_NORMALMAP_OBJECTSPACE\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )\n\tmat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {\n\t\tvec3 q0 = dFdx( eye_pos.xyz );\n\t\tvec3 q1 = dFdy( eye_pos.xyz );\n\t\tvec2 st0 = dFdx( uv.st );\n\t\tvec2 st1 = dFdy( uv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );\n\t\treturn mat3( T * scale, B * scale, N );\n\t}\n#endif",clearcoat_normal_fragment_begin:"#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal = nonPerturbedNormal;\n#endif",clearcoat_normal_fragment_maps:"#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\tclearcoatNormal = normalize( tbn2 * clearcoatMapN );\n#endif",clearcoat_pars_fragment:"#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif",iridescence_pars_fragment:"#ifdef USE_IRIDESCENCEMAP\n\tuniform sampler2D iridescenceMap;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform sampler2D iridescenceThicknessMap;\n#endif",opaque_fragment:"#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= material.transmissionAlpha;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );",packing:"vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;\nconst float Inv255 = 1. / 255.;\nconst vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\nconst vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );\nconst vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );\nconst vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );\nvec4 packDepthToRGBA( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec4( 0., 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec4( 1., 1., 1., 1. );\n\tfloat vuf;\n\tfloat af = modf( v * PackFactors.a, vuf );\n\tfloat bf = modf( vuf * ShiftRight8, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );\n}\nvec3 packDepthToRGB( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec3( 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec3( 1., 1., 1. );\n\tfloat vuf;\n\tfloat bf = modf( v * PackFactors.b, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec3( vuf * Inv255, gf * PackUpscale, bf );\n}\nvec2 packDepthToRG( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec2( 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec2( 1., 1. );\n\tfloat vuf;\n\tfloat gf = modf( v * 256., vuf );\n\treturn vec2( vuf * Inv255, gf );\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors4 );\n}\nfloat unpackRGBToDepth( const in vec3 v ) {\n\treturn dot( v, UnpackFactors3 );\n}\nfloat unpackRGToDepth( const in vec2 v ) {\n\treturn v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;\n}\nvec4 pack2HalfToRGBA( const in vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( const in vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\n\t\treturn depth * ( far - near ) - far;\n\t#else\n\t\treturn depth * ( near - far ) - near;\n\t#endif\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\t\n\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\treturn ( near * far ) / ( ( near - far ) * depth - near );\n\t#else\n\t\treturn ( near * far ) / ( ( far - near ) * depth - far );\n\t#endif\n}",premultiplied_alpha_fragment:"#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif",project_vertex:"vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_BATCHING\n\tmvPosition = batchingMatrix * mvPosition;\n#endif\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;",dithering_fragment:"#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif",dithering_pars_fragment:"#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif",roughnessmap_fragment:"float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );\n\troughnessFactor *= texelRoughness.g;\n#endif",roughnessmap_pars_fragment:"#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif",shadowmap_pars_fragment:"#if NUM_SPOT_LIGHT_COORDS > 0\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#if NUM_SPOT_LIGHT_MAPS > 0\n\tuniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform sampler2DShadow directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\t#else\n\t\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform sampler2DShadow spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\t#else\n\t\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform samplerCubeShadow pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\t#elif defined( SHADOWMAP_TYPE_BASIC )\n\t\t\tuniform samplerCube pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\tfloat interleavedGradientNoise( vec2 position ) {\n\t\t\treturn fract( 52.9829189 * fract( dot( position, vec2( 0.06711056, 0.00583715 ) ) ) );\n\t\t}\n\t\tvec2 vogelDiskSample( int sampleIndex, int samplesCount, float phi ) {\n\t\t\tconst float goldenAngle = 2.399963229728653;\n\t\t\tfloat r = sqrt( ( float( sampleIndex ) + 0.5 ) / float( samplesCount ) );\n\t\t\tfloat theta = float( sampleIndex ) * goldenAngle + phi;\n\t\t\treturn vec2( cos( theta ), sin( theta ) ) * r;\n\t\t}\n\t#endif\n\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\tfloat getShadow( sampler2DShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\t\tfloat shadow = 1.0;\n\t\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\t\tshadowCoord.z += shadowBias;\n\t\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\t\tif ( frustumTest ) {\n\t\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\t\tfloat radius = shadowRadius * texelSize.x;\n\t\t\t\tfloat phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;\n\t\t\t\tshadow = (\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 0, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 1, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 2, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 3, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 4, 5, phi ) * radius, shadowCoord.z ) )\n\t\t\t\t) * 0.2;\n\t\t\t}\n\t\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t\t}\n\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\t\tfloat shadow = 1.0;\n\t\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tshadowCoord.z -= shadowBias;\n\t\t\t#else\n\t\t\t\tshadowCoord.z += shadowBias;\n\t\t\t#endif\n\t\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\t\tif ( frustumTest ) {\n\t\t\t\tvec2 distribution = texture2D( shadowMap, shadowCoord.xy ).rg;\n\t\t\t\tfloat mean = distribution.x;\n\t\t\t\tfloat variance = distribution.y * distribution.y;\n\t\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\t\tfloat hard_shadow = step( mean, shadowCoord.z );\n\t\t\t\t#else\n\t\t\t\t\tfloat hard_shadow = step( shadowCoord.z, mean );\n\t\t\t\t#endif\n\t\t\t\t\n\t\t\t\tif ( hard_shadow == 1.0 ) {\n\t\t\t\t\tshadow = 1.0;\n\t\t\t\t} else {\n\t\t\t\t\tvariance = max( variance, 0.0000001 );\n\t\t\t\t\tfloat d = shadowCoord.z - mean;\n\t\t\t\t\tfloat p_max = variance / ( variance + d * d );\n\t\t\t\t\tp_max = clamp( ( p_max - 0.3 ) / 0.65, 0.0, 1.0 );\n\t\t\t\t\tshadow = max( hard_shadow, p_max );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t\t}\n\t#else\n\t\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\t\tfloat shadow = 1.0;\n\t\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tshadowCoord.z -= shadowBias;\n\t\t\t#else\n\t\t\t\tshadowCoord.z += shadowBias;\n\t\t\t#endif\n\t\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\t\tif ( frustumTest ) {\n\t\t\t\tfloat depth = texture2D( shadowMap, shadowCoord.xy ).r;\n\t\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\t\tshadow = step( depth, shadowCoord.z );\n\t\t\t\t#else\n\t\t\t\t\tshadow = step( shadowCoord.z, depth );\n\t\t\t\t#endif\n\t\t\t}\n\t\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t\t}\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#if defined( SHADOWMAP_TYPE_PCF )\n\tfloat getPointShadow( samplerCubeShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\tvec3 absVec = abs( lightToPosition );\n\t\tfloat viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );\n\t\tif ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tfloat dp = ( shadowCameraNear * ( shadowCameraFar - viewSpaceZ ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );\n\t\t\t\tdp -= shadowBias;\n\t\t\t#else\n\t\t\t\tfloat dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );\n\t\t\t\tdp += shadowBias;\n\t\t\t#endif\n\t\t\tfloat texelSize = shadowRadius / shadowMapSize.x;\n\t\t\tvec3 absDir = abs( bd3D );\n\t\t\tvec3 tangent = absDir.x > absDir.z ? vec3( 0.0, 1.0, 0.0 ) : vec3( 1.0, 0.0, 0.0 );\n\t\t\ttangent = normalize( cross( bd3D, tangent ) );\n\t\t\tvec3 bitangent = cross( bd3D, tangent );\n\t\t\tfloat phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;\n\t\t\tvec2 sample0 = vogelDiskSample( 0, 5, phi );\n\t\t\tvec2 sample1 = vogelDiskSample( 1, 5, phi );\n\t\t\tvec2 sample2 = vogelDiskSample( 2, 5, phi );\n\t\t\tvec2 sample3 = vogelDiskSample( 3, 5, phi );\n\t\t\tvec2 sample4 = vogelDiskSample( 4, 5, phi );\n\t\t\tshadow = (\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample0.x + bitangent * sample0.y ) * texelSize, dp ) ) +\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample1.x + bitangent * sample1.y ) * texelSize, dp ) ) +\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample2.x + bitangent * sample2.y ) * texelSize, dp ) ) +\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample3.x + bitangent * sample3.y ) * texelSize, dp ) ) +\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample4.x + bitangent * sample4.y ) * texelSize, dp ) )\n\t\t\t) * 0.2;\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\t#elif defined( SHADOWMAP_TYPE_BASIC )\n\tfloat getPointShadow( samplerCube shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tvec3 absVec = abs( lightToPosition );\n\t\tfloat viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );\n\t\tif ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {\n\t\t\tfloat dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );\n\t\t\tdp += shadowBias;\n\t\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t\tfloat depth = textureCube( shadowMap, bd3D ).r;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tdepth = 1.0 - depth;\n\t\t\t#endif\n\t\t\tshadow = step( dp, depth );\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\t#endif\n\t#endif\n#endif",shadowmap_pars_vertex:"#if NUM_SPOT_LIGHT_COORDS > 0\n\tuniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif",shadowmap_vertex:"#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\tvec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition;\n\t\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n\t\t#endif\n\t\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n#endif",shadowmask_pars_fragment:"float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0 && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}",skinbase_vertex:"#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\tuniform highp sampler2D boneTexture;\n\tmat4 getBoneMatrix( const in float i ) {\n\t\tint size = textureSize( boneTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n#endif",skinning_vertex:"#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif",skinnormal_vertex:"#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif",specularmap_fragment:"float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif",specularmap_pars_fragment:"#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif",tonemapping_fragment:"#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif",tonemapping_pars_fragment:"#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn saturate( toneMappingExposure * color );\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 CineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nconst mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.6605, - 0.1246, - 0.0182 ),\n\tvec3( - 0.5876, 1.1329, - 0.1006 ),\n\tvec3( - 0.0728, - 0.0083, 1.1187 )\n);\nconst mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(\n\tvec3( 0.6274, 0.0691, 0.0164 ),\n\tvec3( 0.3293, 0.9195, 0.0880 ),\n\tvec3( 0.0433, 0.0113, 0.8956 )\n);\nvec3 agxDefaultContrastApprox( vec3 x ) {\n\tvec3 x2 = x * x;\n\tvec3 x4 = x2 * x2;\n\treturn + 15.5 * x4 * x2\n\t\t- 40.14 * x4 * x\n\t\t+ 31.96 * x4\n\t\t- 6.868 * x2 * x\n\t\t+ 0.4298 * x2\n\t\t+ 0.1191 * x\n\t\t- 0.00232;\n}\nvec3 AgXToneMapping( vec3 color ) {\n\tconst mat3 AgXInsetMatrix = mat3(\n\t\tvec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n\t\tvec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n\t\tvec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )\n\t);\n\tconst mat3 AgXOutsetMatrix = mat3(\n\t\tvec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),\n\t\tvec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),\n\t\tvec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )\n\t);\n\tconst float AgxMinEv = - 12.47393;\tconst float AgxMaxEv = 4.026069;\n\tcolor *= toneMappingExposure;\n\tcolor = LINEAR_SRGB_TO_LINEAR_REC2020 * color;\n\tcolor = AgXInsetMatrix * color;\n\tcolor = max( color, 1e-10 );\tcolor = log2( color );\n\tcolor = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );\n\tcolor = clamp( color, 0.0, 1.0 );\n\tcolor = agxDefaultContrastApprox( color );\n\tcolor = AgXOutsetMatrix * color;\n\tcolor = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );\n\tcolor = LINEAR_REC2020_TO_LINEAR_SRGB * color;\n\tcolor = clamp( color, 0.0, 1.0 );\n\treturn color;\n}\nvec3 NeutralToneMapping( vec3 color ) {\n\tconst float StartCompression = 0.8 - 0.04;\n\tconst float Desaturation = 0.15;\n\tcolor *= toneMappingExposure;\n\tfloat x = min( color.r, min( color.g, color.b ) );\n\tfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\n\tcolor -= offset;\n\tfloat peak = max( color.r, max( color.g, color.b ) );\n\tif ( peak < StartCompression ) return color;\n\tfloat d = 1. - StartCompression;\n\tfloat newPeak = 1. - d * d / ( peak + d - StartCompression );\n\tcolor *= newPeak / peak;\n\tfloat g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );\n\treturn mix( color, vec3( newPeak ), g );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }",transmission_fragment:"#ifdef USE_TRANSMISSION\n\tmaterial.transmission = transmission;\n\tmaterial.transmissionAlpha = 1.0;\n\tmaterial.thickness = thickness;\n\tmaterial.attenuationDistance = attenuationDistance;\n\tmaterial.attenuationColor = attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tmaterial.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tmaterial.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmitted = getIBLVolumeRefraction(\n\t\tn, v, material.roughness, material.diffuseContribution, material.specularColorBlended, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,\n\t\tmaterial.attenuationColor, material.attenuationDistance );\n\tmaterial.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n\ttotalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n#endif",transmission_pars_fragment:"#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tfloat w0( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\n\t}\n\tfloat w1( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\n\t}\n\tfloat w2( float a ){\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\n\t}\n\tfloat w3( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * a );\n\t}\n\tfloat g0( float a ) {\n\t\treturn w0( a ) + w1( a );\n\t}\n\tfloat g1( float a ) {\n\t\treturn w2( a ) + w3( a );\n\t}\n\tfloat h0( float a ) {\n\t\treturn - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\n\t}\n\tfloat h1( float a ) {\n\t\treturn 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\n\t}\n\tvec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\n\t\tuv = uv * texelSize.zw + 0.5;\n\t\tvec2 iuv = floor( uv );\n\t\tvec2 fuv = fract( uv );\n\t\tfloat g0x = g0( fuv.x );\n\t\tfloat g1x = g1( fuv.x );\n\t\tfloat h0x = h0( fuv.x );\n\t\tfloat h1x = h1( fuv.x );\n\t\tfloat h0y = h0( fuv.y );\n\t\tfloat h1y = h1( fuv.y );\n\t\tvec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\treturn g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\n\t\t\tg1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\n\t}\n\tvec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\n\t\tvec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\n\t\tvec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\n\t\tvec2 fLodSizeInv = 1.0 / fLodSize;\n\t\tvec2 cLodSizeInv = 1.0 / cLodSize;\n\t\tvec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\n\t\tvec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\n\t\treturn mix( fSample, cSample, fract( lod ) );\n\t}\n\tvec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( const in float roughness, const in float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n\t\tfloat lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\treturn textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\n\t}\n\tvec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tif ( isinf( attenuationDistance ) ) {\n\t\t\treturn vec3( 1.0 );\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n\t\tconst in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n\t\tconst in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,\n\t\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tvec4 transmittedLight;\n\t\tvec3 transmittance;\n\t\t#ifdef USE_DISPERSION\n\t\t\tfloat halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;\n\t\t\tvec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );\n\t\t\tfor ( int i = 0; i < 3; i ++ ) {\n\t\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );\n\t\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\t\trefractionCoords += 1.0;\n\t\t\t\trefractionCoords /= 2.0;\n\t\t\t\tvec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );\n\t\t\t\ttransmittedLight[ i ] = transmissionSample[ i ];\n\t\t\t\ttransmittedLight.a += transmissionSample.a;\n\t\t\t\ttransmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];\n\t\t\t}\n\t\t\ttransmittedLight.a /= 3.0;\n\t\t#else\n\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\trefractionCoords += 1.0;\n\t\t\trefractionCoords /= 2.0;\n\t\t\ttransmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\t\ttransmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\t#endif\n\t\tvec3 attenuatedColor = transmittance * transmittedLight.rgb;\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\tfloat transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\n\t}\n#endif",uv_pars_fragment:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif",uv_pars_vertex:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tuniform mat3 mapTransform;\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform mat3 alphaMapTransform;\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tuniform mat3 lightMapTransform;\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tuniform mat3 aoMapTransform;\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tuniform mat3 bumpMapTransform;\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tuniform mat3 normalMapTransform;\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tuniform mat3 displacementMapTransform;\n\tvarying vec2 vDisplacementMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tuniform mat3 emissiveMapTransform;\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tuniform mat3 metalnessMapTransform;\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tuniform mat3 roughnessMapTransform;\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tuniform mat3 anisotropyMapTransform;\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tuniform mat3 clearcoatMapTransform;\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform mat3 clearcoatNormalMapTransform;\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform mat3 clearcoatRoughnessMapTransform;\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tuniform mat3 sheenColorMapTransform;\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tuniform mat3 sheenRoughnessMapTransform;\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tuniform mat3 iridescenceMapTransform;\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform mat3 iridescenceThicknessMapTransform;\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tuniform mat3 specularMapTransform;\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tuniform mat3 specularColorMapTransform;\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tuniform mat3 specularIntensityMapTransform;\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif",uv_vertex:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvUv = vec3( uv, 1 ).xy;\n#endif\n#ifdef USE_MAP\n\tvMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ALPHAMAP\n\tvAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_LIGHTMAP\n\tvLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_AOMAP\n\tvAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_BUMPMAP\n\tvBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_NORMALMAP\n\tvNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tvDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_METALNESSMAP\n\tvMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULARMAP\n\tvSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tvTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_THICKNESSMAP\n\tvThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;\n#endif",worldpos_vertex:"#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_BATCHING\n\t\tworldPosition = batchingMatrix * worldPosition;\n\t#endif\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif",background_vert:"varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}",background_frag:"uniform sampler2D t2D;\nuniform float backgroundIntensity;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\ttexColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}",backgroundCube_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}",backgroundCube_frag:"#ifdef ENVMAP_TYPE_CUBE\n\tuniform samplerCube envMap;\n#elif defined( ENVMAP_TYPE_CUBE_UV )\n\tuniform sampler2D envMap;\n#endif\nuniform float flipEnvMap;\nuniform float backgroundBlurriness;\nuniform float backgroundIntensity;\nuniform mat3 backgroundRotation;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );\n\t#else\n\t\tvec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}",cube_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}",cube_frag:"uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n\tgl_FragColor = texColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}",depth_vert:"#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <skinbase_vertex>\n\t#include <morphinstance_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}",depth_frag:"#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <clipping_planes_fragment>\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <logdepthbuf_fragment>\n\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\tfloat fragCoordZ = vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ];\n\t#else\n\t\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ] + 0.5;\n\t#endif\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#elif DEPTH_PACKING == 3202\n\t\tgl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );\n\t#elif DEPTH_PACKING == 3203\n\t\tgl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );\n\t#endif\n}",distance_vert:"#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <skinbase_vertex>\n\t#include <morphinstance_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}",distance_frag:"#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <clipping_planes_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = vec4( dist, 0.0, 0.0, 1.0 );\n}",equirect_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}",equirect_frag:"uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}",linedashed_vert:"uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}",linedashed_frag:"uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}",meshbasic_vert:"#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinbase_vertex>\n\t\t#include <skinnormal_vertex>\n\t\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}",meshbasic_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\treflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshlambert_vert:"#define LAMBERT\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshlambert_frag:"#define LAMBERT\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_lambert_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_lambert_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshmatcap_vert:"#define MATCAP\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}",meshmatcap_frag:"#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t#else\n\t\tvec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshnormal_vert:"#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}",meshnormal_frag:"#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include <uv_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( normalize( normal ) * 0.5 + 0.5, diffuseColor.a );\n\t#ifdef OPAQUE\n\t\tgl_FragColor.a = 1.0;\n\t#endif\n}",meshphong_vert:"#define PHONG\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshphong_frag:"#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshphysical_vert:"#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n#ifdef USE_TRANSMISSION\n\tvWorldPosition = worldPosition.xyz;\n#endif\n}",meshphysical_frag:"#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define USE_SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef USE_SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULAR_COLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_DISPERSION\n\tuniform float dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\tuniform vec2 anisotropyVector;\n\t#ifdef USE_ANISOTROPYMAP\n\t\tuniform sampler2D anisotropyMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <iridescence_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n \n\t\toutgoingLight = outgoingLight + sheenSpecularDirect + sheenSpecularIndirect;\n \n \t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\t#endif\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshtoon_vert:"#define TOON\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshtoon_frag:"#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",points_vert:"uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n#ifdef USE_POINTS_UV\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif\nvoid main() {\n\t#ifdef USE_POINTS_UV\n\t\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\t#endif\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}",points_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}",shadow_vert:"#include <common>\n#include <batching_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",shadow_frag:"uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <logdepthbuf_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\t#include <logdepthbuf_fragment>\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}",sprite_vert:"uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix[ 3 ];\n\tvec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}",sprite_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n}"},vd={common:{diffuse:{value:new En(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Mi},alphaMap:{value:null},alphaMapTransform:{value:new Mi},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Mi}},envmap:{envMap:{value:null},envMapRotation:{value:new Mi},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Mi}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Mi}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Mi},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Mi},normalScale:{value:new yi(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Mi},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Mi}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Mi}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Mi}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new En(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new En(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Mi},alphaTest:{value:0},uvTransform:{value:new Mi}},sprite:{diffuse:{value:new En(16777215)},opacity:{value:1},center:{value:new yi(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Mi},alphaMap:{value:null},alphaMapTransform:{value:new Mi},alphaTest:{value:0}}},yd={basic:{uniforms:El([vd.common,vd.specularmap,vd.envmap,vd.aomap,vd.lightmap,vd.fog]),vertexShader:gd.meshbasic_vert,fragmentShader:gd.meshbasic_frag},lambert:{uniforms:El([vd.common,vd.specularmap,vd.envmap,vd.aomap,vd.lightmap,vd.emissivemap,vd.bumpmap,vd.normalmap,vd.displacementmap,vd.fog,vd.lights,{emissive:{value:new En(0)},envMapIntensity:{value:1}}]),vertexShader:gd.meshlambert_vert,fragmentShader:gd.meshlambert_frag},phong:{uniforms:El([vd.common,vd.specularmap,vd.envmap,vd.aomap,vd.lightmap,vd.emissivemap,vd.bumpmap,vd.normalmap,vd.displacementmap,vd.fog,vd.lights,{emissive:{value:new En(0)},specular:{value:new En(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:gd.meshphong_vert,fragmentShader:gd.meshphong_frag},standard:{uniforms:El([vd.common,vd.envmap,vd.aomap,vd.lightmap,vd.emissivemap,vd.bumpmap,vd.normalmap,vd.displacementmap,vd.roughnessmap,vd.metalnessmap,vd.fog,vd.lights,{emissive:{value:new En(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:gd.meshphysical_vert,fragmentShader:gd.meshphysical_frag},toon:{uniforms:El([vd.common,vd.aomap,vd.lightmap,vd.emissivemap,vd.bumpmap,vd.normalmap,vd.displacementmap,vd.gradientmap,vd.fog,vd.lights,{emissive:{value:new En(0)}}]),vertexShader:gd.meshtoon_vert,fragmentShader:gd.meshtoon_frag},matcap:{uniforms:El([vd.common,vd.bumpmap,vd.normalmap,vd.displacementmap,vd.fog,{matcap:{value:null}}]),vertexShader:gd.meshmatcap_vert,fragmentShader:gd.meshmatcap_frag},points:{uniforms:El([vd.points,vd.fog]),vertexShader:gd.points_vert,fragmentShader:gd.points_frag},dashed:{uniforms:El([vd.common,vd.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:gd.linedashed_vert,fragmentShader:gd.linedashed_frag},depth:{uniforms:El([vd.common,vd.displacementmap]),vertexShader:gd.depth_vert,fragmentShader:gd.depth_frag},normal:{uniforms:El([vd.common,vd.bumpmap,vd.normalmap,vd.displacementmap,{opacity:{value:1}}]),vertexShader:gd.meshnormal_vert,fragmentShader:gd.meshnormal_frag},sprite:{uniforms:El([vd.sprite,vd.fog]),vertexShader:gd.sprite_vert,fragmentShader:gd.sprite_frag},background:{uniforms:{uvTransform:{value:new Mi},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:gd.background_vert,fragmentShader:gd.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new Mi}},vertexShader:gd.backgroundCube_vert,fragmentShader:gd.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:gd.cube_vert,fragmentShader:gd.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:gd.equirect_vert,fragmentShader:gd.equirect_frag},distance:{uniforms:El([vd.common,vd.displacementmap,{referencePosition:{value:new xi},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:gd.distance_vert,fragmentShader:gd.distance_frag},shadow:{uniforms:El([vd.lights,vd.fog,{color:{value:new En(0)},opacity:{value:1}}]),vertexShader:gd.shadow_vert,fragmentShader:gd.shadow_frag}};yd.physical={uniforms:El([yd.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Mi},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Mi},clearcoatNormalScale:{value:new yi(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Mi},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Mi},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Mi},sheen:{value:0},sheenColor:{value:new En(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Mi},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Mi},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Mi},transmissionSamplerSize:{value:new yi},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Mi},attenuationDistance:{value:0},attenuationColor:{value:new En(0)},specularColor:{value:new En(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Mi},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Mi},anisotropyVector:{value:new yi},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Mi}}]),vertexShader:gd.meshphysical_vert,fragmentShader:gd.meshphysical_frag};const _d={r:0,b:0,g:0},xd=new tn,bd=new Wi;function Sd(t,e,i,n,s,r){const a=new En(0);let o,l,h=!0===s?0:1,c=null,d=0,u=null;function p(t){let i=!0===t.isScene?t.background:null;if(i&&i.isTexture){const n=t.backgroundBlurriness>0;i=e.get(i,n)}return i}function m(e,n){e.getRGB(_d,Tl(t)),i.buffers.color.setClear(_d.r,_d.g,_d.b,n,r)}return{getClearColor:function(){return a},setClearColor:function(t,e=1){a.set(t),h=e,m(a,h)},getClearAlpha:function(){return h},setClearAlpha:function(t){h=t,m(a,h)},render:function(e){let n=!1;const s=p(e);null===s?m(a,h):s&&s.isColor&&(m(s,1),n=!0);const o=t.xr.getEnvironmentBlendMode();"additive"===o?i.buffers.color.setClear(0,0,0,1,r):"alpha-blend"===o&&i.buffers.color.setClear(0,0,0,0,r),(t.autoClear||n)&&(i.buffers.depth.setTest(!0),i.buffers.depth.setMask(!0),i.buffers.color.setMask(!0),t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil))},addToRenderList:function(e,i){const s=p(i);s&&(s.isCubeTexture||s.mapping===J)?(void 0===l&&(l=new xr(new Qa(1,1,1),new Dl({name:"BackgroundCubeMaterial",uniforms:Al(yd.backgroundCube.uniforms),vertexShader:yd.backgroundCube.vertexShader,fragmentShader:yd.backgroundCube.fragmentShader,side:1,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute("normal"),l.geometry.deleteAttribute("uv"),l.onBeforeRender=function(t,e,i){this.matrixWorld.copyPosition(i.matrixWorld)},Object.defineProperty(l.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),n.update(l)),xd.copy(i.backgroundRotation),xd.x*=-1,xd.y*=-1,xd.z*=-1,s.isCubeTexture&&!1===s.isRenderTargetTexture&&(xd.y*=-1,xd.z*=-1),l.material.uniforms.envMap.value=s,l.material.uniforms.flipEnvMap.value=s.isCubeTexture&&!1===s.isRenderTargetTexture?-1:1,l.material.uniforms.backgroundBlurriness.value=i.backgroundBlurriness,l.material.uniforms.backgroundIntensity.value=i.backgroundIntensity,l.material.uniforms.backgroundRotation.value.setFromMatrix4(bd.makeRotationFromEuler(xd)),l.material.toneMapped=Ci.getTransfer(s.colorSpace)!==De,c===s&&d===s.version&&u===t.toneMapping||(l.material.needsUpdate=!0,c=s,d=s.version,u=t.toneMapping),l.layers.enableAll(),e.unshift(l,l.geometry,l.material,0,0,null)):s&&s.isTexture&&(void 0===o&&(o=new xr(new pl(2,2),new Dl({name:"BackgroundMaterial",uniforms:Al(yd.background.uniforms),vertexShader:yd.background.vertexShader,fragmentShader:yd.background.fragmentShader,side:0,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),o.geometry.deleteAttribute("normal"),Object.defineProperty(o.material,"map",{get:function(){return this.uniforms.t2D.value}}),n.update(o)),o.material.uniforms.t2D.value=s,o.material.uniforms.backgroundIntensity.value=i.backgroundIntensity,o.material.toneMapped=Ci.getTransfer(s.colorSpace)!==De,!0===s.matrixAutoUpdate&&s.updateMatrix(),o.material.uniforms.uvTransform.value.copy(s.matrix),c===s&&d===s.version&&u===t.toneMapping||(o.material.needsUpdate=!0,c=s,d=s.version,u=t.toneMapping),o.layers.enableAll(),e.unshift(o,o.geometry,o.material,0,0,null))},dispose:function(){void 0!==l&&(l.geometry.dispose(),l.material.dispose(),l=void 0),void 0!==o&&(o.geometry.dispose(),o.material.dispose(),o=void 0)}}}function Md(t,e){const i=t.getParameter(t.MAX_VERTEX_ATTRIBS),n={},s=h(null);let r=s,a=!1;function o(e){return t.bindVertexArray(e)}function l(e){return t.deleteVertexArray(e)}function h(t){const e=[],n=[],s=[];for(let t=0;t<i;t++)e[t]=0,n[t]=0,s[t]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:e,enabledAttributes:n,attributeDivisors:s,object:t,attributes:{},index:null}}function c(){const t=r.newAttributes;for(let e=0,i=t.length;e<i;e++)t[e]=0}function d(t){u(t,0)}function u(e,i){const n=r.newAttributes,s=r.enabledAttributes,a=r.attributeDivisors;n[e]=1,0===s[e]&&(t.enableVertexAttribArray(e),s[e]=1),a[e]!==i&&(t.vertexAttribDivisor(e,i),a[e]=i)}function p(){const e=r.newAttributes,i=r.enabledAttributes;for(let n=0,s=i.length;n<s;n++)i[n]!==e[n]&&(t.disableVertexAttribArray(n),i[n]=0)}function m(e,i,n,s,r,a,o){!0===o?t.vertexAttribIPointer(e,i,n,r,a):t.vertexAttribPointer(e,i,n,s,r,a)}function f(){g(),a=!0,r!==s&&(r=s,o(r.object))}function g(){s.geometry=null,s.program=null,s.wireframe=!1}return{setup:function(i,s,l,f,g){let v=!1;const y=function(e,i,s,r){const a=!0===r.wireframe;let o=n[i.id];void 0===o&&(o={},n[i.id]=o);const l=!0===e.isInstancedMesh?e.id:0;let c=o[l];void 0===c&&(c={},o[l]=c);let d=c[s.id];void 0===d&&(d={},c[s.id]=d);let u=d[a];void 0===u&&(u=h(t.createVertexArray()),d[a]=u);return u}(i,f,l,s);r!==y&&(r=y,o(r.object)),v=function(t,e,i,n){const s=r.attributes,a=e.attributes;let o=0;const l=i.getAttributes();for(const e in l){if(l[e].location>=0){const i=s[e];let n=a[e];if(void 0===n&&("instanceMatrix"===e&&t.instanceMatrix&&(n=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(n=t.instanceColor)),void 0===i)return!0;if(i.attribute!==n)return!0;if(n&&i.data!==n.data)return!0;o++}}return r.attributesNum!==o||r.index!==n}(i,f,l,g),v&&function(t,e,i,n){const s={},a=e.attributes;let o=0;const l=i.getAttributes();for(const e in l){if(l[e].location>=0){let i=a[e];void 0===i&&("instanceMatrix"===e&&t.instanceMatrix&&(i=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(i=t.instanceColor));const n={};n.attribute=i,i&&i.data&&(n.data=i.data),s[e]=n,o++}}r.attributes=s,r.attributesNum=o,r.index=n}(i,f,l,g),null!==g&&e.update(g,t.ELEMENT_ARRAY_BUFFER),(v||a)&&(a=!1,function(i,n,s,r){c();const a=r.attributes,o=s.getAttributes(),l=n.defaultAttributeValues;for(const n in o){const s=o[n];if(s.location>=0){let o=a[n];if(void 0===o&&("instanceMatrix"===n&&i.instanceMatrix&&(o=i.instanceMatrix),"instanceColor"===n&&i.instanceColor&&(o=i.instanceColor)),void 0!==o){const n=o.normalized,a=o.itemSize,l=e.get(o);if(void 0===l)continue;const h=l.buffer,c=l.type,p=l.bytesPerElement,f=c===t.INT||c===t.UNSIGNED_INT||o.gpuType===ut;if(o.isInterleavedBufferAttribute){const e=o.data,l=e.stride,g=o.offset;if(e.isInstancedInterleavedBuffer){for(let t=0;t<s.locationSize;t++)u(s.location+t,e.meshPerAttribute);!0!==i.isInstancedMesh&&void 0===r._maxInstanceCount&&(r._maxInstanceCount=e.meshPerAttribute*e.count)}else for(let t=0;t<s.locationSize;t++)d(s.location+t);t.bindBuffer(t.ARRAY_BUFFER,h);for(let t=0;t<s.locationSize;t++)m(s.location+t,a/s.locationSize,c,n,l*p,(g+a/s.locationSize*t)*p,f)}else{if(o.isInstancedBufferAttribute){for(let t=0;t<s.locationSize;t++)u(s.location+t,o.meshPerAttribute);!0!==i.isInstancedMesh&&void 0===r._maxInstanceCount&&(r._maxInstanceCount=o.meshPerAttribute*o.count)}else for(let t=0;t<s.locationSize;t++)d(s.location+t);t.bindBuffer(t.ARRAY_BUFFER,h);for(let t=0;t<s.locationSize;t++)m(s.location+t,a/s.locationSize,c,n,a*p,a/s.locationSize*t*p,f)}}else if(void 0!==l){const e=l[n];if(void 0!==e)switch(e.length){case 2:t.vertexAttrib2fv(s.location,e);break;case 3:t.vertexAttrib3fv(s.location,e);break;case 4:t.vertexAttrib4fv(s.location,e);break;default:t.vertexAttrib1fv(s.location,e)}}}}p()}(i,s,l,f),null!==g&&t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,e.get(g).buffer))},reset:f,resetDefaultState:g,dispose:function(){f();for(const t in n){const e=n[t];for(const t in e){const i=e[t];for(const t in i){const e=i[t];for(const t in e)l(e[t].object),delete e[t];delete i[t]}}delete n[t]}},releaseStatesOfGeometry:function(t){if(void 0===n[t.id])return;const e=n[t.id];for(const t in e){const i=e[t];for(const t in i){const e=i[t];for(const t in e)l(e[t].object),delete e[t];delete i[t]}}delete n[t.id]},releaseStatesOfObject:function(t){for(const e in n){const i=n[e],s=!0===t.isInstancedMesh?t.id:0,r=i[s];if(void 0!==r){for(const t in r){const e=r[t];for(const t in e)l(e[t].object),delete e[t];delete r[t]}delete i[s],0===Object.keys(i).length&&delete n[e]}}},releaseStatesOfProgram:function(t){for(const e in n){const i=n[e];for(const e in i){const n=i[e];if(void 0===n[t.id])continue;const s=n[t.id];for(const t in s)l(s[t].object),delete s[t];delete n[t.id]}}},initAttributes:c,enableAttribute:d,disableUnusedAttributes:p}}function wd(t,e,i){let n;function s(e,s,r){0!==r&&(t.drawArraysInstanced(n,e,s,r),i.update(s,n,r))}this.setMode=function(t){n=t},this.render=function(e,s){t.drawArrays(n,e,s),i.update(s,n,1)},this.renderInstances=s,this.renderMultiDraw=function(t,s,r){if(0===r)return;e.get("WEBGL_multi_draw").multiDrawArraysWEBGL(n,t,0,s,0,r);let a=0;for(let t=0;t<r;t++)a+=s[t];i.update(a,n,1)},this.renderMultiDrawInstances=function(t,r,a,o){if(0===a)return;const l=e.get("WEBGL_multi_draw");if(null===l)for(let e=0;e<t.length;e++)s(t[e],r[e],o[e]);else{l.multiDrawArraysInstancedWEBGL(n,t,0,r,0,o,0,a);let e=0;for(let t=0;t<a;t++)e+=r[t]*o[t];i.update(e,n,1)}}}function Ad(t,e,i,n){let s;function r(e){if("highp"===e){if(t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.HIGH_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT).precision>0)return"highp";e="mediump"}return"mediump"===e&&t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.MEDIUM_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let a=void 0!==i.precision?i.precision:"highp";const o=r(a);o!==a&&(ii("WebGLRenderer:",a,"not supported, using",o,"instead."),a=o);return{isWebGL2:!0,getMaxAnisotropy:function(){if(void 0!==s)return s;if(!0===e.has("EXT_texture_filter_anisotropic")){const i=e.get("EXT_texture_filter_anisotropic");s=t.getParameter(i.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else s=0;return s},getMaxPrecision:r,textureFormatReadable:function(e){return e===Mt||n.convert(e)===t.getParameter(t.IMPLEMENTATION_COLOR_READ_FORMAT)},textureTypeReadable:function(i){const s=i===ft&&(e.has("EXT_color_buffer_half_float")||e.has("EXT_color_buffer_float"));return!(i!==lt&&n.convert(i)!==t.getParameter(t.IMPLEMENTATION_COLOR_READ_TYPE)&&i!==mt&&!s)},precision:a,logarithmicDepthBuffer:!0===i.logarithmicDepthBuffer,reversedDepthBuffer:!0===i.reversedDepthBuffer&&e.has("EXT_clip_control"),maxTextures:t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),maxVertexTextures:t.getParameter(t.MAX_VERTEX_TEXTURE_IMAGE_UNITS),maxTextureSize:t.getParameter(t.MAX_TEXTURE_SIZE),maxCubemapSize:t.getParameter(t.MAX_CUBE_MAP_TEXTURE_SIZE),maxAttributes:t.getParameter(t.MAX_VERTEX_ATTRIBS),maxVertexUniforms:t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS),maxVaryings:t.getParameter(t.MAX_VARYING_VECTORS),maxFragmentUniforms:t.getParameter(t.MAX_FRAGMENT_UNIFORM_VECTORS),maxSamples:t.getParameter(t.MAX_SAMPLES),samples:t.getParameter(t.SAMPLES)}}function Ed(t){const e=this;let i=null,n=0,s=!1,r=!1;const a=new qr,o=new Mi,l={value:null,needsUpdate:!1};function h(t,i,n,s){const r=null!==t?t.length:0;let h=null;if(0!==r){if(h=l.value,!0!==s||null===h){const e=n+4*r,s=i.matrixWorldInverse;o.getNormalMatrix(s),(null===h||h.length<e)&&(h=new Float32Array(e));for(let e=0,i=n;e!==r;++e,i+=4)a.copy(t[e]).applyMatrix4(s,o),a.normal.toArray(h,i),h[i+3]=a.constant}l.value=h,l.needsUpdate=!0}return e.numPlanes=r,e.numIntersection=0,h}this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(t,e){const i=0!==t.length||e||0!==n||s;return s=e,n=t.length,i},this.beginShadows=function(){r=!0,h(null)},this.endShadows=function(){r=!1},this.setGlobalState=function(t,e){i=h(t,e,0)},this.setState=function(a,o,c){const d=a.clippingPlanes,u=a.clipIntersection,p=a.clipShadows,m=t.get(a);if(!s||null===d||0===d.length||r&&!p)r?h(null):function(){l.value!==i&&(l.value=i,l.needsUpdate=n>0);e.numPlanes=n,e.numIntersection=0}();else{const t=r?0:n,e=4*t;let s=m.clippingState||null;l.value=s,s=h(d,o,e,c);for(let t=0;t!==e;++t)s[t]=i[t];m.clippingState=s,this.numIntersection=u?this.numPlanes:0,this.numPlanes+=t}}}const Td=[.125,.215,.35,.446,.526,.582],Cd=20,Dd=new Fh,Rd=new En;let Pd=null,Id=0,Ld=0,Bd=!1;const Od=new xi;class Fd{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._backgroundBox=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._blurMaterial=null,this._ggxMaterial=null}fromScene(t,e=0,i=.1,n=100,s={}){const{size:r=256,position:a=Od}=s;Pd=this._renderer.getRenderTarget(),Id=this._renderer.getActiveCubeFace(),Ld=this._renderer.getActiveMipmapLevel(),Bd=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(r);const o=this._allocateTargets();return o.depthBuffer=!0,this._sceneToCubeUV(t,i,n,o,a),e>0&&this._blur(o,0,0,e),this._applyPMREM(o),this._cleanup(o),o}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=zd(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=kd(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._ggxMaterial&&this._ggxMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let t=0;t<this._lodMeshes.length;t++)this._lodMeshes[t].geometry.dispose()}_cleanup(t){this._renderer.setRenderTarget(Pd,Id,Ld),this._renderer.xr.enabled=Bd,t.scissorTest=!1,Ud(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===Z||t.mapping===q?this._setSize(0===t.image.length?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),Pd=this._renderer.getRenderTarget(),Id=this._renderer.getActiveCubeFace(),Ld=this._renderer.getActiveMipmapLevel(),Bd=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;const i=e||this._allocateTargets();return this._textureToCubeUV(t,i),this._applyPMREM(i),this._cleanup(i),i}_allocateTargets(){const t=3*Math.max(this._cubeSize,112),e=4*this._cubeSize,i={magFilter:rt,minFilter:rt,generateMipmaps:!1,type:ft,format:Mt,colorSpace:Te,depthBuffer:!1},n=Nd(t,e,i);if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=Nd(t,e,i);const{_lodMax:n}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=function(t){const e=[],i=[],n=[];let s=t;const r=t-4+1+Td.length;for(let a=0;a<r;a++){const r=Math.pow(2,s);e.push(r);let o=1/r;a>t-4?o=Td[a-t+4-1]:0===a&&(o=0),i.push(o);const l=1/(r-2),h=-l,c=1+l,d=[h,h,c,h,c,c,h,h,c,c,h,c],u=6,p=6,m=3,f=2,g=1,v=new Float32Array(m*p*u),y=new Float32Array(f*p*u),_=new Float32Array(g*p*u);for(let t=0;t<u;t++){const e=t%3*2/3-1,i=t>2?0:-1,n=[e,i,0,e+2/3,i,0,e+2/3,i+1,0,e,i,0,e+2/3,i+1,0,e,i+1,0];v.set(n,m*p*t),y.set(d,f*p*t);const s=[t,t,t,t,t,t];_.set(s,g*p*t)}const x=new Ds;x.setAttribute("position",new ms(v,m)),x.setAttribute("uv",new ms(y,f)),x.setAttribute("faceIndex",new ms(_,g)),n.push(new xr(x,null)),s>4&&s--}return{lodMeshes:n,sizeLods:e,sigmas:i}}(n)),this._blurMaterial=function(t,e,i){const n=new Float32Array(Cd),s=new xi(0,1,0),r=new Dl({name:"SphericalGaussianBlur",defines:{n:Cd,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/i,CUBEUV_MAX_MIP:`${t}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:n},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:s}},vertexShader:Gd(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform int samples;\n\t\t\tuniform float weights[ n ];\n\t\t\tuniform bool latitudinal;\n\t\t\tuniform float dTheta;\n\t\t\tuniform float mipInt;\n\t\t\tuniform vec3 poleAxis;\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include <cube_uv_reflection_fragment>\n\n\t\t\tvec3 getSample( float theta, vec3 axis ) {\n\n\t\t\t\tfloat cosTheta = cos( theta );\n\t\t\t\t// Rodrigues' axis-angle rotation\n\t\t\t\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t\t\t\t+ cross( axis, vOutputDirection ) * sin( theta )\n\t\t\t\t\t+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );\n\n\t\t\t\treturn bilinearCubeUV( envMap, sampleDirection, mipInt );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );\n\n\t\t\t\tif ( all( equal( axis, vec3( 0.0 ) ) ) ) {\n\n\t\t\t\t\taxis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );\n\n\t\t\t\t}\n\n\t\t\t\taxis = normalize( axis );\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );\n\n\t\t\t\tfor ( int i = 1; i < n; i++ ) {\n\n\t\t\t\t\tif ( i >= samples ) {\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t}\n\n\t\t\t\t\tfloat theta = dTheta * float( i );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( theta, axis );\n\n\t\t\t\t}\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1});return r}(n,t,e),this._ggxMaterial=function(t,e,i){const n=new Dl({name:"PMREMGGXConvolution",defines:{GGX_SAMPLES:256,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/i,CUBEUV_MAX_MIP:`${t}.0`},uniforms:{envMap:{value:null},roughness:{value:0},mipInt:{value:0}},vertexShader:Gd(),fragmentShader:'\n\n\t\t\tprecision highp float;\n\t\t\tprecision highp int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform float roughness;\n\t\t\tuniform float mipInt;\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include <cube_uv_reflection_fragment>\n\n\t\t\t#define PI 3.14159265359\n\n\t\t\t// Van der Corput radical inverse\n\t\t\tfloat radicalInverse_VdC(uint bits) {\n\t\t\t\tbits = (bits << 16u) | (bits >> 16u);\n\t\t\t\tbits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);\n\t\t\t\tbits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);\n\t\t\t\tbits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);\n\t\t\t\tbits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);\n\t\t\t\treturn float(bits) * 2.3283064365386963e-10; // / 0x100000000\n\t\t\t}\n\n\t\t\t// Hammersley sequence\n\t\t\tvec2 hammersley(uint i, uint N) {\n\t\t\t\treturn vec2(float(i) / float(N), radicalInverse_VdC(i));\n\t\t\t}\n\n\t\t\t// GGX VNDF importance sampling (Eric Heitz 2018)\n\t\t\t// "Sampling the GGX Distribution of Visible Normals"\n\t\t\t// https://jcgt.org/published/0007/04/01/\n\t\t\tvec3 importanceSampleGGX_VNDF(vec2 Xi, vec3 V, float roughness) {\n\t\t\t\tfloat alpha = roughness * roughness;\n\n\t\t\t\t// Section 4.1: Orthonormal basis\n\t\t\t\tvec3 T1 = vec3(1.0, 0.0, 0.0);\n\t\t\t\tvec3 T2 = cross(V, T1);\n\n\t\t\t\t// Section 4.2: Parameterization of projected area\n\t\t\t\tfloat r = sqrt(Xi.x);\n\t\t\t\tfloat phi = 2.0 * PI * Xi.y;\n\t\t\t\tfloat t1 = r * cos(phi);\n\t\t\t\tfloat t2 = r * sin(phi);\n\t\t\t\tfloat s = 0.5 * (1.0 + V.z);\n\t\t\t\tt2 = (1.0 - s) * sqrt(1.0 - t1 * t1) + s * t2;\n\n\t\t\t\t// Section 4.3: Reprojection onto hemisphere\n\t\t\t\tvec3 Nh = t1 * T1 + t2 * T2 + sqrt(max(0.0, 1.0 - t1 * t1 - t2 * t2)) * V;\n\n\t\t\t\t// Section 3.4: Transform back to ellipsoid configuration\n\t\t\t\treturn normalize(vec3(alpha * Nh.x, alpha * Nh.y, max(0.0, Nh.z)));\n\t\t\t}\n\n\t\t\tvoid main() {\n\t\t\t\tvec3 N = normalize(vOutputDirection);\n\t\t\t\tvec3 V = N; // Assume view direction equals normal for pre-filtering\n\n\t\t\t\tvec3 prefilteredColor = vec3(0.0);\n\t\t\t\tfloat totalWeight = 0.0;\n\n\t\t\t\t// For very low roughness, just sample the environment directly\n\t\t\t\tif (roughness < 0.001) {\n\t\t\t\t\tgl_FragColor = vec4(bilinearCubeUV(envMap, N, mipInt), 1.0);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Tangent space basis for VNDF sampling\n\t\t\t\tvec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\n\t\t\t\tvec3 tangent = normalize(cross(up, N));\n\t\t\t\tvec3 bitangent = cross(N, tangent);\n\n\t\t\t\tfor(uint i = 0u; i < uint(GGX_SAMPLES); i++) {\n\t\t\t\t\tvec2 Xi = hammersley(i, uint(GGX_SAMPLES));\n\n\t\t\t\t\t// For PMREM, V = N, so in tangent space V is always (0, 0, 1)\n\t\t\t\t\tvec3 H_tangent = importanceSampleGGX_VNDF(Xi, vec3(0.0, 0.0, 1.0), roughness);\n\n\t\t\t\t\t// Transform H back to world space\n\t\t\t\t\tvec3 H = normalize(tangent * H_tangent.x + bitangent * H_tangent.y + N * H_tangent.z);\n\t\t\t\t\tvec3 L = normalize(2.0 * dot(V, H) * H - V);\n\n\t\t\t\t\tfloat NdotL = max(dot(N, L), 0.0);\n\n\t\t\t\t\tif(NdotL > 0.0) {\n\t\t\t\t\t\t// Sample environment at fixed mip level\n\t\t\t\t\t\t// VNDF importance sampling handles the distribution filtering\n\t\t\t\t\t\tvec3 sampleColor = bilinearCubeUV(envMap, L, mipInt);\n\n\t\t\t\t\t\t// Weight by NdotL for the split-sum approximation\n\t\t\t\t\t\t// VNDF PDF naturally accounts for the visible microfacet distribution\n\t\t\t\t\t\tprefilteredColor += sampleColor * NdotL;\n\t\t\t\t\t\ttotalWeight += NdotL;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (totalWeight > 0.0) {\n\t\t\t\t\tprefilteredColor = prefilteredColor / totalWeight;\n\t\t\t\t}\n\n\t\t\t\tgl_FragColor = vec4(prefilteredColor, 1.0);\n\t\t\t}\n\t\t',blending:0,depthTest:!1,depthWrite:!1});return n}(n,t,e)}return n}_compileMaterial(t){const e=new xr(new Ds,t);this._renderer.compile(e,Dd)}_sceneToCubeUV(t,e,i,n,s){const r=new Ph(90,1,e,i),a=[1,-1,1,1,1,1],o=[1,1,1,-1,-1,-1],l=this._renderer,h=l.autoClear,c=l.toneMapping;l.getClearColor(Rd),l.toneMapping=0,l.autoClear=!1;l.state.buffers.depth.getReversed()&&(l.setRenderTarget(n),l.clearDepth(),l.setRenderTarget(null)),null===this._backgroundBox&&(this._backgroundBox=new xr(new Qa,new lr({name:"PMREM.Background",side:1,depthWrite:!1,depthTest:!1})));const d=this._backgroundBox,u=d.material;let p=!1;const m=t.background;m?m.isColor&&(u.color.copy(m),t.background=null,p=!0):(u.color.copy(Rd),p=!0);for(let e=0;e<6;e++){const i=e%3;0===i?(r.up.set(0,a[e],0),r.position.set(s.x,s.y,s.z),r.lookAt(s.x+o[e],s.y,s.z)):1===i?(r.up.set(0,0,a[e]),r.position.set(s.x,s.y,s.z),r.lookAt(s.x,s.y+o[e],s.z)):(r.up.set(0,a[e],0),r.position.set(s.x,s.y,s.z),r.lookAt(s.x,s.y,s.z+o[e]));const h=this._cubeSize;Ud(n,i*h,e>2?h:0,h,h),l.setRenderTarget(n),p&&l.render(d,r),l.render(t,r)}l.toneMapping=c,l.autoClear=h,t.background=m}_textureToCubeUV(t,e){const i=this._renderer,n=t.mapping===Z||t.mapping===q;n?(null===this._cubemapMaterial&&(this._cubemapMaterial=zd()),this._cubemapMaterial.uniforms.flipEnvMap.value=!1===t.isRenderTargetTexture?-1:1):null===this._equirectMaterial&&(this._equirectMaterial=kd());const s=n?this._cubemapMaterial:this._equirectMaterial,r=this._lodMeshes[0];r.material=s;s.uniforms.envMap.value=t;const a=this._cubeSize;Ud(e,0,0,3*a,2*a),i.setRenderTarget(e),i.render(r,Dd)}_applyPMREM(t){const e=this._renderer,i=e.autoClear;e.autoClear=!1;const n=this._lodMeshes.length;for(let e=1;e<n;e++)this._applyGGXFilter(t,e-1,e);e.autoClear=i}_applyGGXFilter(t,e,i){const n=this._renderer,s=this._pingPongRenderTarget,r=this._ggxMaterial,a=this._lodMeshes[i];a.material=r;const o=r.uniforms,l=i/(this._lodMeshes.length-1),h=e/(this._lodMeshes.length-1),c=Math.sqrt(l*l-h*h)*(0+1.25*l),{_lodMax:d}=this,u=this._sizeLods[i],p=3*u*(i>d-4?i-d+4:0),m=4*(this._cubeSize-u);o.envMap.value=t.texture,o.roughness.value=c,o.mipInt.value=d-e,Ud(s,p,m,3*u,2*u),n.setRenderTarget(s),n.render(a,Dd),o.envMap.value=s.texture,o.roughness.value=0,o.mipInt.value=d-i,Ud(t,p,m,3*u,2*u),n.setRenderTarget(t),n.render(a,Dd)}_blur(t,e,i,n,s){const r=this._pingPongRenderTarget;this._halfBlur(t,r,e,i,n,"latitudinal",s),this._halfBlur(r,t,i,i,n,"longitudinal",s)}_halfBlur(t,e,i,n,s,r,a){const o=this._renderer,l=this._blurMaterial;"latitudinal"!==r&&"longitudinal"!==r&&ni("blur direction must be either latitudinal or longitudinal!");const h=this._lodMeshes[n];h.material=l;const c=l.uniforms,d=this._sizeLods[i]-1,u=isFinite(s)?Math.PI/(2*d):2*Math.PI/39,p=s/u,m=isFinite(s)?1+Math.floor(3*p):Cd;m>Cd&&ii(`sigmaRadians, ${s}, is too large and will clip, as it requested ${m} samples when the maximum is set to 20`);const f=[];let g=0;for(let t=0;t<Cd;++t){const e=t/p,i=Math.exp(-e*e/2);f.push(i),0===t?g+=i:t<m&&(g+=2*i)}for(let t=0;t<f.length;t++)f[t]=f[t]/g;c.envMap.value=t.texture,c.samples.value=m,c.weights.value=f,c.latitudinal.value="latitudinal"===r,a&&(c.poleAxis.value=a);const{_lodMax:v}=this;c.dTheta.value=u,c.mipInt.value=v-i;const y=this._sizeLods[n];Ud(e,3*y*(n>v-4?n-v+4:0),4*(this._cubeSize-y),3*y,2*y),o.setRenderTarget(e),o.render(h,Dd)}}function Nd(t,e,i){const n=new Gi(t,e,i);return n.texture.mapping=J,n.texture.name="PMREM.cubeUv",n.scissorTest=!0,n}function Ud(t,e,i,n,s){t.viewport.set(e,i,n,s),t.scissor.set(e,i,n,s)}function kd(){return new Dl({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:Gd(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\n\t\t\t#include <common>\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 outputDirection = normalize( vOutputDirection );\n\t\t\t\tvec2 uv = equirectUv( outputDirection );\n\n\t\t\t\tgl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1})}function zd(){return new Dl({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:Gd(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tuniform float flipEnvMap;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform samplerCube envMap;\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1})}function Gd(){return"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t"}class Hd extends Gi{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const i={width:t,height:t,depth:1},n=[i,i,i,i,i,i];this.texture=new ja(n),this._setTextureOptions(e),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const i={uniforms:{tEquirect:{value:null}},vertexShader:"\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include <begin_vertex>\n\t\t\t\t\t#include <project_vertex>\n\n\t\t\t\t}\n\t\t\t",fragmentShader:"\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include <common>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t"},n=new Qa(5,5,5),s=new Dl({name:"CubemapFromEquirect",uniforms:Al(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:1,blending:0});s.uniforms.tEquirect.value=e;const r=new xr(n,s),a=e.minFilter;e.minFilter===ot&&(e.minFilter=rt);return new nc(1,10,this).update(t,r),e.minFilter=a,r.geometry.dispose(),r.material.dispose(),this}clear(t,e=!0,i=!0,n=!0){const s=t.getRenderTarget();for(let s=0;s<6;s++)t.setRenderTarget(this,s),t.clear(e,i,n);t.setRenderTarget(s)}}function Vd(t){let e=new WeakMap,i=new WeakMap,n=null;function s(t,e){return e===Q?t.mapping=Z:e===K&&(t.mapping=q),t}function r(t){const i=t.target;i.removeEventListener("dispose",r);const n=e.get(i);void 0!==n&&(e.delete(i),n.dispose())}function a(t){const e=t.target;e.removeEventListener("dispose",a);const n=i.get(e);void 0!==n&&(i.delete(e),n.dispose())}return{get:function(o,l=!1){return null==o?null:l?function(e){if(e&&e.isTexture){const s=e.mapping,r=s===Q||s===K,o=s===Z||s===q;if(r||o){let s=i.get(e);const l=void 0!==s?s.texture.pmremVersion:0;if(e.isRenderTargetTexture&&e.pmremVersion!==l)return null===n&&(n=new Fd(t)),s=r?n.fromEquirectangular(e,s):n.fromCubemap(e,s),s.texture.pmremVersion=e.pmremVersion,i.set(e,s),s.texture;if(void 0!==s)return s.texture;{const l=e.image;return r&&l&&l.height>0||o&&l&&function(t){let e=0;const i=6;for(let n=0;n<i;n++)void 0!==t[n]&&e++;return e===i}(l)?(null===n&&(n=new Fd(t)),s=r?n.fromEquirectangular(e):n.fromCubemap(e),s.texture.pmremVersion=e.pmremVersion,i.set(e,s),e.addEventListener("dispose",a),s.texture):null}}}return e}(o):function(i){if(i&&i.isTexture){const n=i.mapping;if(n===Q||n===K){if(e.has(i)){return s(e.get(i).texture,i.mapping)}{const n=i.image;if(n&&n.height>0){const a=new Hd(n.height);return a.fromEquirectangularTexture(t,i),e.set(i,a),i.addEventListener("dispose",r),s(a.texture,i.mapping)}return null}}}return i}(o)},dispose:function(){e=new WeakMap,i=new WeakMap,null!==n&&(n.dispose(),n=null)}}}function Wd(t){const e={};function i(i){if(void 0!==e[i])return e[i];const n=t.getExtension(i);return e[i]=n,n}return{has:function(t){return null!==i(t)},init:function(){i("EXT_color_buffer_float"),i("WEBGL_clip_cull_distance"),i("OES_texture_float_linear"),i("EXT_color_buffer_half_float"),i("WEBGL_multisampled_render_to_texture"),i("WEBGL_render_shared_exponent")},get:function(t){const e=i(t);return null===e&&si("WebGLRenderer: "+t+" extension not supported."),e}}}function jd(t,e,i,n){const s={},r=new WeakMap;function a(t){const o=t.target;null!==o.index&&e.remove(o.index);for(const t in o.attributes)e.remove(o.attributes[t]);o.removeEventListener("dispose",a),delete s[o.id];const l=r.get(o);l&&(e.remove(l),r.delete(o)),n.releaseStatesOfGeometry(o),!0===o.isInstancedBufferGeometry&&delete o._maxInstanceCount,i.memory.geometries--}function o(t){const i=[],n=t.index,s=t.attributes.position;let a=0;if(void 0===s)return;if(null!==n){const t=n.array;a=n.version;for(let e=0,n=t.length;e<n;e+=3){const n=t[e+0],s=t[e+1],r=t[e+2];i.push(n,s,s,r,r,n)}}else{const t=s.array;a=s.version;for(let e=0,n=t.length/3-1;e<n;e+=3){const t=e+0,n=e+1,s=e+2;i.push(t,n,n,s,s,t)}}const o=new(s.count>=65535?gs:fs)(i,1);o.version=a;const l=r.get(t);l&&e.remove(l),r.set(t,o)}return{get:function(t,e){return!0===s[e.id]||(e.addEventListener("dispose",a),s[e.id]=!0,i.memory.geometries++),e},update:function(i){const n=i.attributes;for(const i in n)e.update(n[i],t.ARRAY_BUFFER)},getWireframeAttribute:function(t){const e=r.get(t);if(e){const i=t.index;null!==i&&e.version<i.version&&o(t)}else o(t);return r.get(t)}}}function Xd(t,e,i){let n,s,r;function a(e,a,o){0!==o&&(t.drawElementsInstanced(n,a,s,e*r,o),i.update(a,n,o))}this.setMode=function(t){n=t},this.setIndex=function(t){s=t.type,r=t.bytesPerElement},this.render=function(e,a){t.drawElements(n,a,s,e*r),i.update(a,n,1)},this.renderInstances=a,this.renderMultiDraw=function(t,r,a){if(0===a)return;e.get("WEBGL_multi_draw").multiDrawElementsWEBGL(n,r,0,s,t,0,a);let o=0;for(let t=0;t<a;t++)o+=r[t];i.update(o,n,1)},this.renderMultiDrawInstances=function(t,o,l,h){if(0===l)return;const c=e.get("WEBGL_multi_draw");if(null===c)for(let e=0;e<t.length;e++)a(t[e]/r,o[e],h[e]);else{c.multiDrawElementsInstancedWEBGL(n,o,0,s,t,0,h,0,l);let e=0;for(let t=0;t<l;t++)e+=o[t]*h[t];i.update(e,n,1)}}}function Yd(t){const e={frame:0,calls:0,triangles:0,points:0,lines:0};return{memory:{geometries:0,textures:0},render:e,programs:null,autoReset:!0,reset:function(){e.calls=0,e.triangles=0,e.points=0,e.lines=0},update:function(i,n,s){switch(e.calls++,n){case t.TRIANGLES:e.triangles+=s*(i/3);break;case t.LINES:e.lines+=s*(i/2);break;case t.LINE_STRIP:e.lines+=s*(i-1);break;case t.LINE_LOOP:e.lines+=s*i;break;case t.POINTS:e.points+=s*i;break;default:ni("WebGLInfo: Unknown draw mode:",n)}}}}function Zd(t,e,i){const n=new WeakMap,s=new ki;return{update:function(r,a,o){const l=r.morphTargetInfluences,h=a.morphAttributes.position||a.morphAttributes.normal||a.morphAttributes.color,c=void 0!==h?h.length:0;let d=n.get(a);if(void 0===d||d.count!==c){void 0!==d&&d.texture.dispose();const u=void 0!==a.morphAttributes.position,p=void 0!==a.morphAttributes.normal,m=void 0!==a.morphAttributes.color,f=a.morphAttributes.position||[],g=a.morphAttributes.normal||[],v=a.morphAttributes.color||[];let y=0;!0===u&&(y=1),!0===p&&(y=2),!0===m&&(y=3);let _=a.attributes.position.count*y,x=1;_>e.maxTextureSize&&(x=Math.ceil(_/e.maxTextureSize),_=e.maxTextureSize);const b=new Float32Array(_*x*4*c),S=new Hi(b,_,x,c);S.type=mt,S.needsUpdate=!0;const M=4*y;for(let A=0;A<c;A++){const E=f[A],T=g[A],C=v[A],D=_*x*4*A;for(let R=0;R<E.count;R++){const P=R*M;!0===u&&(s.fromBufferAttribute(E,R),b[D+P+0]=s.x,b[D+P+1]=s.y,b[D+P+2]=s.z,b[D+P+3]=0),!0===p&&(s.fromBufferAttribute(T,R),b[D+P+4]=s.x,b[D+P+5]=s.y,b[D+P+6]=s.z,b[D+P+7]=0),!0===m&&(s.fromBufferAttribute(C,R),b[D+P+8]=s.x,b[D+P+9]=s.y,b[D+P+10]=s.z,b[D+P+11]=4===C.itemSize?s.w:1)}}function w(){S.dispose(),n.delete(a),a.removeEventListener("dispose",w)}d={count:c,texture:S,size:new yi(_,x)},n.set(a,d),a.addEventListener("dispose",w)}if(!0===r.isInstancedMesh&&null!==r.morphTexture)o.getUniforms().setValue(t,"morphTexture",r.morphTexture,i);else{let I=0;for(let B=0;B<l.length;B++)I+=l[B];const L=a.morphTargetsRelative?1:1-I;o.getUniforms().setValue(t,"morphTargetBaseInfluence",L),o.getUniforms().setValue(t,"morphTargetInfluences",l)}o.getUniforms().setValue(t,"morphTargetsTexture",d.texture,i),o.getUniforms().setValue(t,"morphTargetsTextureSize",d.size)}}}function qd(t,e,i,n,s){let r=new WeakMap;function a(t){const e=t.target;e.removeEventListener("dispose",a),n.releaseStatesOfObject(e),i.remove(e.instanceMatrix),null!==e.instanceColor&&i.remove(e.instanceColor)}return{update:function(n){const o=s.render.frame,l=n.geometry,h=e.get(n,l);if(r.get(h)!==o&&(e.update(h),r.set(h,o)),n.isInstancedMesh&&(!1===n.hasEventListener("dispose",a)&&n.addEventListener("dispose",a),r.get(n)!==o&&(i.update(n.instanceMatrix,t.ARRAY_BUFFER),null!==n.instanceColor&&i.update(n.instanceColor,t.ARRAY_BUFFER),r.set(n,o))),n.isSkinnedMesh){const t=n.skeleton;r.get(t)!==o&&(t.update(),r.set(t,o))}return h},dispose:function(){r=new WeakMap}}}const Qd={[U]:"LINEAR_TONE_MAPPING",[k]:"REINHARD_TONE_MAPPING",[z]:"CINEON_TONE_MAPPING",[G]:"ACES_FILMIC_TONE_MAPPING",[V]:"AGX_TONE_MAPPING",[W]:"NEUTRAL_TONE_MAPPING",[H]:"CUSTOM_TONE_MAPPING"};function Kd(t,e,i,n,s){const r=new Gi(e,i,{type:t,depthBuffer:n,stencilBuffer:s}),a=new Gi(e,i,{type:ft,depthBuffer:!1,stencilBuffer:!1}),o=new Ds;o.setAttribute("position",new vs([-1,3,0,-1,-1,0,3,-1,0],3)),o.setAttribute("uv",new vs([0,2,0,0,2,0],2));const l=new Rl({uniforms:{tDiffuse:{value:null}},vertexShader:"\n\t\t\tprecision highp float;\n\n\t\t\tuniform mat4 modelViewMatrix;\n\t\t\tuniform mat4 projectionMatrix;\n\n\t\t\tattribute vec3 position;\n\t\t\tattribute vec2 uv;\n\n\t\t\tvarying vec2 vUv;\n\n\t\t\tvoid main() {\n\t\t\t\tvUv = uv;\n\t\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\t\t\t}",fragmentShader:"\n\t\t\tprecision highp float;\n\n\t\t\tuniform sampler2D tDiffuse;\n\n\t\t\tvarying vec2 vUv;\n\n\t\t\t#include <tonemapping_pars_fragment>\n\t\t\t#include <colorspace_pars_fragment>\n\n\t\t\tvoid main() {\n\t\t\t\tgl_FragColor = texture2D( tDiffuse, vUv );\n\n\t\t\t\t#ifdef LINEAR_TONE_MAPPING\n\t\t\t\t\tgl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );\n\t\t\t\t#elif defined( REINHARD_TONE_MAPPING )\n\t\t\t\t\tgl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );\n\t\t\t\t#elif defined( CINEON_TONE_MAPPING )\n\t\t\t\t\tgl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );\n\t\t\t\t#elif defined( ACES_FILMIC_TONE_MAPPING )\n\t\t\t\t\tgl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );\n\t\t\t\t#elif defined( AGX_TONE_MAPPING )\n\t\t\t\t\tgl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );\n\t\t\t\t#elif defined( NEUTRAL_TONE_MAPPING )\n\t\t\t\t\tgl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );\n\t\t\t\t#elif defined( CUSTOM_TONE_MAPPING )\n\t\t\t\t\tgl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef SRGB_TRANSFER\n\t\t\t\t\tgl_FragColor = sRGBTransferOETF( gl_FragColor );\n\t\t\t\t#endif\n\t\t\t}",depthTest:!1,depthWrite:!1}),h=new xr(o,l),c=new Fh(-1,1,1,-1,0,1);let d,u=null,p=null,m=!1,f=null,g=[],v=!1;this.setSize=function(t,e){r.setSize(t,e),a.setSize(t,e);for(let i=0;i<g.length;i++){const n=g[i];n.setSize&&n.setSize(t,e)}},this.setEffects=function(t){g=t,v=g.length>0&&!0===g[0].isRenderPass;const e=r.width,i=r.height;for(let t=0;t<g.length;t++){const n=g[t];n.setSize&&n.setSize(e,i)}},this.begin=function(t,e){if(m)return!1;if(0===t.toneMapping&&0===g.length)return!1;if(f=e,null!==e){const t=e.width,i=e.height;r.width===t&&r.height===i||this.setSize(t,i)}return!1===v&&t.setRenderTarget(r),d=t.toneMapping,t.toneMapping=0,!0},this.hasRenderPass=function(){return v},this.end=function(t,e){t.toneMapping=d,m=!0;let i=r,n=a;for(let s=0;s<g.length;s++){const r=g[s];if(!1!==r.enabled&&(r.render(t,n,i,e),!1!==r.needsSwap)){const t=i;i=n,n=t}}if(u!==t.outputColorSpace||p!==t.toneMapping){u=t.outputColorSpace,p=t.toneMapping,l.defines={},Ci.getTransfer(u)===De&&(l.defines.SRGB_TRANSFER="");const e=Qd[p];e&&(l.defines[e]=""),l.needsUpdate=!0}l.uniforms.tDiffuse.value=i.texture,t.setRenderTarget(f),t.render(h,c),f=null,m=!1},this.isCompositing=function(){return m},this.dispose=function(){r.dispose(),a.dispose(),o.dispose(),l.dispose()}}const Jd=new Ui,$d=new Ya(1,1),tu=new Hi,eu=new Vi,iu=new ja,nu=[],su=[],ru=new Float32Array(16),au=new Float32Array(9),ou=new Float32Array(4);function lu(t,e,i){const n=t[0];if(n<=0||n>0)return t;const s=e*i;let r=nu[s];if(void 0===r&&(r=new Float32Array(s),nu[s]=r),0!==e){n.toArray(r,0);for(let n=1,s=0;n!==e;++n)s+=i,t[n].toArray(r,s)}return r}function hu(t,e){if(t.length!==e.length)return!1;for(let i=0,n=t.length;i<n;i++)if(t[i]!==e[i])return!1;return!0}function cu(t,e){for(let i=0,n=e.length;i<n;i++)t[i]=e[i]}function du(t,e){let i=su[e];void 0===i&&(i=new Int32Array(e),su[e]=i);for(let n=0;n!==e;++n)i[n]=t.allocateTextureUnit();return i}function uu(t,e){const i=this.cache;i[0]!==e&&(t.uniform1f(this.addr,e),i[0]=e)}function pu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2f(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(hu(i,e))return;t.uniform2fv(this.addr,e),cu(i,e)}}function mu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3f(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else if(void 0!==e.r)i[0]===e.r&&i[1]===e.g&&i[2]===e.b||(t.uniform3f(this.addr,e.r,e.g,e.b),i[0]=e.r,i[1]=e.g,i[2]=e.b);else{if(hu(i,e))return;t.uniform3fv(this.addr,e),cu(i,e)}}function fu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4f(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(hu(i,e))return;t.uniform4fv(this.addr,e),cu(i,e)}}function gu(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(hu(i,e))return;t.uniformMatrix2fv(this.addr,!1,e),cu(i,e)}else{if(hu(i,n))return;ou.set(n),t.uniformMatrix2fv(this.addr,!1,ou),cu(i,n)}}function vu(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(hu(i,e))return;t.uniformMatrix3fv(this.addr,!1,e),cu(i,e)}else{if(hu(i,n))return;au.set(n),t.uniformMatrix3fv(this.addr,!1,au),cu(i,n)}}function yu(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(hu(i,e))return;t.uniformMatrix4fv(this.addr,!1,e),cu(i,e)}else{if(hu(i,n))return;ru.set(n),t.uniformMatrix4fv(this.addr,!1,ru),cu(i,n)}}function _u(t,e){const i=this.cache;i[0]!==e&&(t.uniform1i(this.addr,e),i[0]=e)}function xu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2i(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(hu(i,e))return;t.uniform2iv(this.addr,e),cu(i,e)}}function bu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3i(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else{if(hu(i,e))return;t.uniform3iv(this.addr,e),cu(i,e)}}function Su(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4i(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(hu(i,e))return;t.uniform4iv(this.addr,e),cu(i,e)}}function Mu(t,e){const i=this.cache;i[0]!==e&&(t.uniform1ui(this.addr,e),i[0]=e)}function wu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2ui(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(hu(i,e))return;t.uniform2uiv(this.addr,e),cu(i,e)}}function Au(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3ui(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else{if(hu(i,e))return;t.uniform3uiv(this.addr,e),cu(i,e)}}function Eu(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4ui(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(hu(i,e))return;t.uniform4uiv(this.addr,e),cu(i,e)}}function Tu(t,e,i){const n=this.cache,s=i.allocateTextureUnit();let r;n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),this.type===t.SAMPLER_2D_SHADOW?($d.compareFunction=i.isReversedDepthBuffer()?Ge:Ue,r=$d):r=Jd,i.setTexture2D(e||r,s)}function Cu(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.setTexture3D(e||eu,s)}function Du(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.setTextureCube(e||iu,s)}function Ru(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.setTexture2DArray(e||tu,s)}function Pu(t,e){t.uniform1fv(this.addr,e)}function Iu(t,e){const i=lu(e,this.size,2);t.uniform2fv(this.addr,i)}function Lu(t,e){const i=lu(e,this.size,3);t.uniform3fv(this.addr,i)}function Bu(t,e){const i=lu(e,this.size,4);t.uniform4fv(this.addr,i)}function Ou(t,e){const i=lu(e,this.size,4);t.uniformMatrix2fv(this.addr,!1,i)}function Fu(t,e){const i=lu(e,this.size,9);t.uniformMatrix3fv(this.addr,!1,i)}function Nu(t,e){const i=lu(e,this.size,16);t.uniformMatrix4fv(this.addr,!1,i)}function Uu(t,e){t.uniform1iv(this.addr,e)}function ku(t,e){t.uniform2iv(this.addr,e)}function zu(t,e){t.uniform3iv(this.addr,e)}function Gu(t,e){t.uniform4iv(this.addr,e)}function Hu(t,e){t.uniform1uiv(this.addr,e)}function Vu(t,e){t.uniform2uiv(this.addr,e)}function Wu(t,e){t.uniform3uiv(this.addr,e)}function ju(t,e){t.uniform4uiv(this.addr,e)}function Xu(t,e,i){const n=this.cache,s=e.length,r=du(i,s);let a;hu(n,r)||(t.uniform1iv(this.addr,r),cu(n,r)),a=this.type===t.SAMPLER_2D_SHADOW?$d:Jd;for(let t=0;t!==s;++t)i.setTexture2D(e[t]||a,r[t])}function Yu(t,e,i){const n=this.cache,s=e.length,r=du(i,s);hu(n,r)||(t.uniform1iv(this.addr,r),cu(n,r));for(let t=0;t!==s;++t)i.setTexture3D(e[t]||eu,r[t])}function Zu(t,e,i){const n=this.cache,s=e.length,r=du(i,s);hu(n,r)||(t.uniform1iv(this.addr,r),cu(n,r));for(let t=0;t!==s;++t)i.setTextureCube(e[t]||iu,r[t])}function qu(t,e,i){const n=this.cache,s=e.length,r=du(i,s);hu(n,r)||(t.uniform1iv(this.addr,r),cu(n,r));for(let t=0;t!==s;++t)i.setTexture2DArray(e[t]||tu,r[t])}class Qu{constructor(t,e,i){this.id=t,this.addr=i,this.cache=[],this.type=e.type,this.setValue=function(t){switch(t){case 5126:return uu;case 35664:return pu;case 35665:return mu;case 35666:return fu;case 35674:return gu;case 35675:return vu;case 35676:return yu;case 5124:case 35670:return _u;case 35667:case 35671:return xu;case 35668:case 35672:return bu;case 35669:case 35673:return Su;case 5125:return Mu;case 36294:return wu;case 36295:return Au;case 36296:return Eu;case 35678:case 36198:case 36298:case 36306:case 35682:return Tu;case 35679:case 36299:case 36307:return Cu;case 35680:case 36300:case 36308:case 36293:return Du;case 36289:case 36303:case 36311:case 36292:return Ru}}(e.type)}}class Ku{constructor(t,e,i){this.id=t,this.addr=i,this.cache=[],this.type=e.type,this.size=e.size,this.setValue=function(t){switch(t){case 5126:return Pu;case 35664:return Iu;case 35665:return Lu;case 35666:return Bu;case 35674:return Ou;case 35675:return Fu;case 35676:return Nu;case 5124:case 35670:return Uu;case 35667:case 35671:return ku;case 35668:case 35672:return zu;case 35669:case 35673:return Gu;case 5125:return Hu;case 36294:return Vu;case 36295:return Wu;case 36296:return ju;case 35678:case 36198:case 36298:case 36306:case 35682:return Xu;case 35679:case 36299:case 36307:return Yu;case 35680:case 36300:case 36308:case 36293:return Zu;case 36289:case 36303:case 36311:case 36292:return qu}}(e.type)}}class Ju{constructor(t){this.id=t,this.seq=[],this.map={}}setValue(t,e,i){const n=this.seq;for(let s=0,r=n.length;s!==r;++s){const r=n[s];r.setValue(t,e[r.id],i)}}}const $u=/(\w+)(\])?(\[|\.)?/g;function tp(t,e){t.seq.push(e),t.map[e.id]=e}function ep(t,e,i){const n=t.name,s=n.length;for($u.lastIndex=0;;){const r=$u.exec(n),a=$u.lastIndex;let o=r[1];const l="]"===r[2],h=r[3];if(l&&(o|=0),void 0===h||"["===h&&a+2===s){tp(i,void 0===h?new Qu(o,t,e):new Ku(o,t,e));break}{let t=i.map[o];void 0===t&&(t=new Ju(o),tp(i,t)),i=t}}}class ip{constructor(t,e){this.seq=[],this.map={};const i=t.getProgramParameter(e,t.ACTIVE_UNIFORMS);for(let n=0;n<i;++n){const i=t.getActiveUniform(e,n);ep(i,t.getUniformLocation(e,i.name),this)}const n=[],s=[];for(const e of this.seq)e.type===t.SAMPLER_2D_SHADOW||e.type===t.SAMPLER_CUBE_SHADOW||e.type===t.SAMPLER_2D_ARRAY_SHADOW?n.push(e):s.push(e);n.length>0&&(this.seq=n.concat(s))}setValue(t,e,i,n){const s=this.map[e];void 0!==s&&s.setValue(t,i,n)}setOptional(t,e,i){const n=e[i];void 0!==n&&this.setValue(t,i,n)}static upload(t,e,i,n){for(let s=0,r=e.length;s!==r;++s){const r=e[s],a=i[r.id];!1!==a.needsUpdate&&r.setValue(t,a.value,n)}}static seqWithValue(t,e){const i=[];for(let n=0,s=t.length;n!==s;++n){const s=t[n];s.id in e&&i.push(s)}return i}}function np(t,e,i){const n=t.createShader(e);return t.shaderSource(n,i),t.compileShader(n),n}let sp=0;const rp=new Mi;function ap(t,e,i){const n=t.getShaderParameter(e,t.COMPILE_STATUS),s=(t.getShaderInfoLog(e)||"").trim();if(n&&""===s)return"";const r=/ERROR: 0:(\d+)/.exec(s);if(r){const n=parseInt(r[1]);return i.toUpperCase()+"\n\n"+s+"\n\n"+function(t,e){const i=t.split("\n"),n=[],s=Math.max(e-6,0),r=Math.min(e+6,i.length);for(let t=s;t<r;t++){const s=t+1;n.push(`${s===e?">":" "} ${s}: ${i[t]}`)}return n.join("\n")}(t.getShaderSource(e),n)}return s}function op(t,e){const i=function(t){Ci._getMatrix(rp,Ci.workingColorSpace,t);const e=`mat3( ${rp.elements.map(t=>t.toFixed(4))} )`;switch(Ci.getTransfer(t)){case Ce:return[e,"LinearTransferOETF"];case De:return[e,"sRGBTransferOETF"];default:return ii("WebGLProgram: Unsupported color space: ",t),[e,"LinearTransferOETF"]}}(e);return[`vec4 ${t}( vec4 value ) {`,`\treturn ${i[1]}( vec4( value.rgb * ${i[0]}, value.a ) );`,"}"].join("\n")}const lp={[U]:"Linear",[k]:"Reinhard",[z]:"Cineon",[G]:"ACESFilmic",[V]:"AgX",[W]:"Neutral",[H]:"Custom"};function hp(t,e){const i=lp[e];return void 0===i?(ii("WebGLProgram: Unsupported toneMapping:",e),"vec3 "+t+"( vec3 color ) { return LinearToneMapping( color ); }"):"vec3 "+t+"( vec3 color ) { return "+i+"ToneMapping( color ); }"}const cp=new xi;function dp(){Ci.getLuminanceCoefficients(cp);return["float luminance( const in vec3 rgb ) {",`\tconst vec3 weights = vec3( ${cp.x.toFixed(4)}, ${cp.y.toFixed(4)}, ${cp.z.toFixed(4)} );`,"\treturn dot( weights, rgb );","}"].join("\n")}function up(t){return""!==t}function pp(t,e){const i=e.numSpotLightShadows+e.numSpotLightMaps-e.numSpotLightShadowsWithMaps;return t.replace(/NUM_DIR_LIGHTS/g,e.numDirLights).replace(/NUM_SPOT_LIGHTS/g,e.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,e.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,i).replace(/NUM_RECT_AREA_LIGHTS/g,e.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,e.numPointLights).replace(/NUM_HEMI_LIGHTS/g,e.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,e.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,e.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,e.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,e.numPointLightShadows)}function mp(t,e){return t.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}const fp=/^[ \t]*#include +<([\w\d./]+)>/gm;function gp(t){return t.replace(fp,yp)}const vp=new Map;function yp(t,e){let i=gd[e];if(void 0===i){const t=vp.get(e);if(void 0===t)throw new Error("Can not resolve #include <"+e+">");i=gd[t],ii('WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',e,t)}return gp(i)}const _p=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function xp(t){return t.replace(_p,bp)}function bp(t,e,i,n){let s="";for(let t=parseInt(e);t<parseInt(i);t++)s+=n.replace(/\[\s*i\s*\]/g,"[ "+t+" ]").replace(/UNROLLED_LOOP_INDEX/g,t);return s}function Sp(t){let e=`precision ${t.precision} float;\n\tprecision ${t.precision} int;\n\tprecision ${t.precision} sampler2D;\n\tprecision ${t.precision} samplerCube;\n\tprecision ${t.precision} sampler3D;\n\tprecision ${t.precision} sampler2DArray;\n\tprecision ${t.precision} sampler2DShadow;\n\tprecision ${t.precision} samplerCubeShadow;\n\tprecision ${t.precision} sampler2DArrayShadow;\n\tprecision ${t.precision} isampler2D;\n\tprecision ${t.precision} isampler3D;\n\tprecision ${t.precision} isamplerCube;\n\tprecision ${t.precision} isampler2DArray;\n\tprecision ${t.precision} usampler2D;\n\tprecision ${t.precision} usampler3D;\n\tprecision ${t.precision} usamplerCube;\n\tprecision ${t.precision} usampler2DArray;\n\t`;return"highp"===t.precision?e+="\n#define HIGH_PRECISION":"mediump"===t.precision?e+="\n#define MEDIUM_PRECISION":"lowp"===t.precision&&(e+="\n#define LOW_PRECISION"),e}const Mp={[s]:"SHADOWMAP_TYPE_PCF",[r]:"SHADOWMAP_TYPE_VSM"};const wp={[Z]:"ENVMAP_TYPE_CUBE",[q]:"ENVMAP_TYPE_CUBE",[J]:"ENVMAP_TYPE_CUBE_UV"};const Ap={[q]:"ENVMAP_MODE_REFRACTION"};const Ep={[O]:"ENVMAP_BLENDING_MULTIPLY",[F]:"ENVMAP_BLENDING_MIX",[N]:"ENVMAP_BLENDING_ADD"};function Tp(t,e,i,n){const s=t.getContext(),r=i.defines;let a=i.vertexShader,o=i.fragmentShader;const l=function(t){return Mp[t.shadowMapType]||"SHADOWMAP_TYPE_BASIC"}(i),h=function(t){return!1===t.envMap?"ENVMAP_TYPE_CUBE":wp[t.envMapMode]||"ENVMAP_TYPE_CUBE"}(i),c=function(t){return!1===t.envMap?"ENVMAP_MODE_REFLECTION":Ap[t.envMapMode]||"ENVMAP_MODE_REFLECTION"}(i),d=function(t){return!1===t.envMap?"ENVMAP_BLENDING_NONE":Ep[t.combine]||"ENVMAP_BLENDING_NONE"}(i),u=function(t){const e=t.envMapCubeUVHeight;if(null===e)return null;const i=Math.log2(e)-2,n=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,i),112)),texelHeight:n,maxMip:i}}(i),p=function(t){return[t.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":"",t.extensionMultiDraw?"#extension GL_ANGLE_multi_draw : require":""].filter(up).join("\n")}(i),m=function(t){const e=[];for(const i in t){const n=t[i];!1!==n&&e.push("#define "+i+" "+n)}return e.join("\n")}(r),f=s.createProgram();let g,v,y=i.glslVersion?"#version "+i.glslVersion+"\n":"";i.isRawShaderMaterial?(g=["#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,m].filter(up).join("\n"),g.length>0&&(g+="\n"),v=["#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,m].filter(up).join("\n"),v.length>0&&(v+="\n")):(g=[Sp(i),"#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,m,i.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",i.batching?"#define USE_BATCHING":"",i.batchingColor?"#define USE_BATCHING_COLOR":"",i.instancing?"#define USE_INSTANCING":"",i.instancingColor?"#define USE_INSTANCING_COLOR":"",i.instancingMorph?"#define USE_INSTANCING_MORPH":"",i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+c:"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",i.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",i.displacementMap?"#define USE_DISPLACEMENTMAP":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.anisotropy?"#define USE_ANISOTROPY":"",i.anisotropyMap?"#define USE_ANISOTROPYMAP":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",i.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",i.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.alphaHash?"#define USE_ALPHAHASH":"",i.transmission?"#define USE_TRANSMISSION":"",i.transmissionMap?"#define USE_TRANSMISSIONMAP":"",i.thicknessMap?"#define USE_THICKNESSMAP":"",i.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",i.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",i.mapUv?"#define MAP_UV "+i.mapUv:"",i.alphaMapUv?"#define ALPHAMAP_UV "+i.alphaMapUv:"",i.lightMapUv?"#define LIGHTMAP_UV "+i.lightMapUv:"",i.aoMapUv?"#define AOMAP_UV "+i.aoMapUv:"",i.emissiveMapUv?"#define EMISSIVEMAP_UV "+i.emissiveMapUv:"",i.bumpMapUv?"#define BUMPMAP_UV "+i.bumpMapUv:"",i.normalMapUv?"#define NORMALMAP_UV "+i.normalMapUv:"",i.displacementMapUv?"#define DISPLACEMENTMAP_UV "+i.displacementMapUv:"",i.metalnessMapUv?"#define METALNESSMAP_UV "+i.metalnessMapUv:"",i.roughnessMapUv?"#define ROUGHNESSMAP_UV "+i.roughnessMapUv:"",i.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+i.anisotropyMapUv:"",i.clearcoatMapUv?"#define CLEARCOATMAP_UV "+i.clearcoatMapUv:"",i.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+i.clearcoatNormalMapUv:"",i.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+i.clearcoatRoughnessMapUv:"",i.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+i.iridescenceMapUv:"",i.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+i.iridescenceThicknessMapUv:"",i.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+i.sheenColorMapUv:"",i.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+i.sheenRoughnessMapUv:"",i.specularMapUv?"#define SPECULARMAP_UV "+i.specularMapUv:"",i.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+i.specularColorMapUv:"",i.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+i.specularIntensityMapUv:"",i.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+i.transmissionMapUv:"",i.thicknessMapUv?"#define THICKNESSMAP_UV "+i.thicknessMapUv:"",i.vertexTangents&&!1===i.flatShading?"#define USE_TANGENT":"",i.vertexColors?"#define USE_COLOR":"",i.vertexAlphas?"#define USE_COLOR_ALPHA":"",i.vertexUv1s?"#define USE_UV1":"",i.vertexUv2s?"#define USE_UV2":"",i.vertexUv3s?"#define USE_UV3":"",i.pointsUvs?"#define USE_POINTS_UV":"",i.flatShading?"#define FLAT_SHADED":"",i.skinning?"#define USE_SKINNING":"",i.morphTargets?"#define USE_MORPHTARGETS":"",i.morphNormals&&!1===i.flatShading?"#define USE_MORPHNORMALS":"",i.morphColors?"#define USE_MORPHCOLORS":"",i.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+i.morphTextureStride:"",i.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+i.morphTargetsCount:"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+l:"",i.sizeAttenuation?"#define USE_SIZEATTENUATION":"",i.numLightProbes>0?"#define USE_LIGHT_PROBES":"",i.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",i.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING","\tattribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR","\tattribute vec3 instanceColor;","#endif","#ifdef USE_INSTANCING_MORPH","\tuniform sampler2D morphTexture;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1","\tattribute vec2 uv1;","#endif","#ifdef USE_UV2","\tattribute vec2 uv2;","#endif","#ifdef USE_UV3","\tattribute vec2 uv3;","#endif","#ifdef USE_TANGENT","\tattribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )","\tattribute vec4 color;","#elif defined( USE_COLOR )","\tattribute vec3 color;","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter(up).join("\n"),v=[Sp(i),"#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,m,i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",i.map?"#define USE_MAP":"",i.matcap?"#define USE_MATCAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+h:"",i.envMap?"#define "+c:"",i.envMap?"#define "+d:"",u?"#define CUBEUV_TEXEL_WIDTH "+u.texelWidth:"",u?"#define CUBEUV_TEXEL_HEIGHT "+u.texelHeight:"",u?"#define CUBEUV_MAX_MIP "+u.maxMip+".0":"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",i.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.anisotropy?"#define USE_ANISOTROPY":"",i.anisotropyMap?"#define USE_ANISOTROPYMAP":"",i.clearcoat?"#define USE_CLEARCOAT":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.dispersion?"#define USE_DISPERSION":"",i.iridescence?"#define USE_IRIDESCENCE":"",i.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",i.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",i.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.alphaTest?"#define USE_ALPHATEST":"",i.alphaHash?"#define USE_ALPHAHASH":"",i.sheen?"#define USE_SHEEN":"",i.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",i.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",i.transmission?"#define USE_TRANSMISSION":"",i.transmissionMap?"#define USE_TRANSMISSIONMAP":"",i.thicknessMap?"#define USE_THICKNESSMAP":"",i.vertexTangents&&!1===i.flatShading?"#define USE_TANGENT":"",i.vertexColors||i.instancingColor?"#define USE_COLOR":"",i.vertexAlphas||i.batchingColor?"#define USE_COLOR_ALPHA":"",i.vertexUv1s?"#define USE_UV1":"",i.vertexUv2s?"#define USE_UV2":"",i.vertexUv3s?"#define USE_UV3":"",i.pointsUvs?"#define USE_POINTS_UV":"",i.gradientMap?"#define USE_GRADIENTMAP":"",i.flatShading?"#define FLAT_SHADED":"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+l:"",i.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",i.numLightProbes>0?"#define USE_LIGHT_PROBES":"",i.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",i.decodeVideoTextureEmissive?"#define DECODE_VIDEO_TEXTURE_EMISSIVE":"",i.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",i.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",0!==i.toneMapping?"#define TONE_MAPPING":"",0!==i.toneMapping?gd.tonemapping_pars_fragment:"",0!==i.toneMapping?hp("toneMapping",i.toneMapping):"",i.dithering?"#define DITHERING":"",i.opaque?"#define OPAQUE":"",gd.colorspace_pars_fragment,op("linearToOutputTexel",i.outputColorSpace),dp(),i.useDepthPacking?"#define DEPTH_PACKING "+i.depthPacking:"","\n"].filter(up).join("\n")),a=gp(a),a=pp(a,i),a=mp(a,i),o=gp(o),o=pp(o,i),o=mp(o,i),a=xp(a),o=xp(o),!0!==i.isRawShaderMaterial&&(y="#version 300 es\n",g=[p,"#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+g,v=["#define varying in",i.glslVersion===We?"":"layout(location = 0) out highp vec4 pc_fragColor;",i.glslVersion===We?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join("\n")+"\n"+v);const _=y+g+a,x=y+v+o,b=np(s,s.VERTEX_SHADER,_),S=np(s,s.FRAGMENT_SHADER,x);function M(e){if(t.debug.checkShaderErrors){const i=s.getProgramInfoLog(f)||"",n=s.getShaderInfoLog(b)||"",r=s.getShaderInfoLog(S)||"",a=i.trim(),o=n.trim(),l=r.trim();let h=!0,c=!0;if(!1===s.getProgramParameter(f,s.LINK_STATUS))if(h=!1,"function"==typeof t.debug.onShaderError)t.debug.onShaderError(s,f,b,S);else{const t=ap(s,b,"vertex"),i=ap(s,S,"fragment");ni("THREE.WebGLProgram: Shader Error "+s.getError()+" - VALIDATE_STATUS "+s.getProgramParameter(f,s.VALIDATE_STATUS)+"\n\nMaterial Name: "+e.name+"\nMaterial Type: "+e.type+"\n\nProgram Info Log: "+a+"\n"+t+"\n"+i)}else""!==a?ii("WebGLProgram: Program Info Log:",a):""!==o&&""!==l||(c=!1);c&&(e.diagnostics={runnable:h,programLog:a,vertexShader:{log:o,prefix:g},fragmentShader:{log:l,prefix:v}})}s.deleteShader(b),s.deleteShader(S),w=new ip(s,f),A=function(t,e){const i={},n=t.getProgramParameter(e,t.ACTIVE_ATTRIBUTES);for(let s=0;s<n;s++){const n=t.getActiveAttrib(e,s),r=n.name;let a=1;n.type===t.FLOAT_MAT2&&(a=2),n.type===t.FLOAT_MAT3&&(a=3),n.type===t.FLOAT_MAT4&&(a=4),i[r]={type:n.type,location:t.getAttribLocation(e,r),locationSize:a}}return i}(s,f)}let w,A;s.attachShader(f,b),s.attachShader(f,S),void 0!==i.index0AttributeName?s.bindAttribLocation(f,0,i.index0AttributeName):!0===i.morphTargets&&s.bindAttribLocation(f,0,"position"),s.linkProgram(f),this.getUniforms=function(){return void 0===w&&M(this),w},this.getAttributes=function(){return void 0===A&&M(this),A};let E=!1===i.rendererExtensionParallelShaderCompile;return this.isReady=function(){return!1===E&&(E=s.getProgramParameter(f,37297)),E},this.destroy=function(){n.releaseStatesOfProgram(this),s.deleteProgram(f),this.program=void 0},this.type=i.shaderType,this.name=i.shaderName,this.id=sp++,this.cacheKey=e,this.usedTimes=1,this.program=f,this.vertexShader=b,this.fragmentShader=S,this}let Cp=0;class Dp{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t){const e=t.vertexShader,i=t.fragmentShader,n=this._getShaderStage(e),s=this._getShaderStage(i),r=this._getShaderCacheForMaterial(t);return!1===r.has(n)&&(r.add(n),n.usedTimes++),!1===r.has(s)&&(r.add(s),s.usedTimes++),this}remove(t){const e=this.materialCache.get(t);for(const t of e)t.usedTimes--,0===t.usedTimes&&this.shaderCache.delete(t.code);return this.materialCache.delete(t),this}getVertexShaderID(t){return this._getShaderStage(t.vertexShader).id}getFragmentShaderID(t){return this._getShaderStage(t.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(t){const e=this.materialCache;let i=e.get(t);return void 0===i&&(i=new Set,e.set(t,i)),i}_getShaderStage(t){const e=this.shaderCache;let i=e.get(t);return void 0===i&&(i=new Rp(t),e.set(t,i)),i}}class Rp{constructor(t){this.id=Cp++,this.code=t,this.usedTimes=0}}function Pp(t,e,i,n,s,r){const a=new en,o=new Dp,l=new Set,h=[],c=new Map,d=n.logarithmicDepthBuffer;let u=n.precision;const p={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distance",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function m(t){return l.add(t),0===t?"uv":`uv${t}`}return{getParameters:function(s,a,h,c,f){const g=c.fog,v=f.geometry,y=s.isMeshStandardMaterial||s.isMeshLambertMaterial||s.isMeshPhongMaterial?c.environment:null,_=s.isMeshStandardMaterial||s.isMeshLambertMaterial&&!s.envMap||s.isMeshPhongMaterial&&!s.envMap,x=e.get(s.envMap||y,_),b=x&&x.mapping===J?x.image.height:null,S=p[s.type];null!==s.precision&&(u=n.getMaxPrecision(s.precision),u!==s.precision&&ii("WebGLProgram.getParameters:",s.precision,"not supported, using",u,"instead."));const M=v.morphAttributes.position||v.morphAttributes.normal||v.morphAttributes.color,w=void 0!==M?M.length:0;let A,E,T,C,D=0;if(void 0!==v.morphAttributes.position&&(D=1),void 0!==v.morphAttributes.normal&&(D=2),void 0!==v.morphAttributes.color&&(D=3),S){const t=yd[S];A=t.vertexShader,E=t.fragmentShader}else A=s.vertexShader,E=s.fragmentShader,o.update(s),T=o.getVertexShaderID(s),C=o.getFragmentShaderID(s);const R=t.getRenderTarget(),P=t.state.buffers.depth.getReversed(),I=!0===f.isInstancedMesh,L=!0===f.isBatchedMesh,B=!!s.map,O=!!s.matcap,F=!!x,N=!!s.aoMap,U=!!s.lightMap,k=!!s.bumpMap,z=!!s.normalMap,G=!!s.displacementMap,H=!!s.emissiveMap,V=!!s.metalnessMap,W=!!s.roughnessMap,j=s.anisotropy>0,X=s.clearcoat>0,Y=s.dispersion>0,Z=s.iridescence>0,q=s.sheen>0,Q=s.transmission>0,K=j&&!!s.anisotropyMap,$=X&&!!s.clearcoatMap,tt=X&&!!s.clearcoatNormalMap,et=X&&!!s.clearcoatRoughnessMap,it=Z&&!!s.iridescenceMap,nt=Z&&!!s.iridescenceThicknessMap,st=q&&!!s.sheenColorMap,rt=q&&!!s.sheenRoughnessMap,at=!!s.specularMap,ot=!!s.specularColorMap,lt=!!s.specularIntensityMap,ht=Q&&!!s.transmissionMap,ct=Q&&!!s.thicknessMap,dt=!!s.gradientMap,ut=!!s.alphaMap,pt=s.alphaTest>0,mt=!!s.alphaHash,ft=!!s.extensions;let gt=0;s.toneMapped&&(null!==R&&!0!==R.isXRRenderTarget||(gt=t.toneMapping));const vt={shaderID:S,shaderType:s.type,shaderName:s.name,vertexShader:A,fragmentShader:E,defines:s.defines,customVertexShaderID:T,customFragmentShaderID:C,isRawShaderMaterial:!0===s.isRawShaderMaterial,glslVersion:s.glslVersion,precision:u,batching:L,batchingColor:L&&null!==f._colorsTexture,instancing:I,instancingColor:I&&null!==f.instanceColor,instancingMorph:I&&null!==f.morphTexture,outputColorSpace:null===R?t.outputColorSpace:!0===R.isXRRenderTarget?R.texture.colorSpace:Te,alphaToCoverage:!!s.alphaToCoverage,map:B,matcap:O,envMap:F,envMapMode:F&&x.mapping,envMapCubeUVHeight:b,aoMap:N,lightMap:U,bumpMap:k,normalMap:z,displacementMap:G,emissiveMap:H,normalMapObjectSpace:z&&1===s.normalMapType,normalMapTangentSpace:z&&0===s.normalMapType,metalnessMap:V,roughnessMap:W,anisotropy:j,anisotropyMap:K,clearcoat:X,clearcoatMap:$,clearcoatNormalMap:tt,clearcoatRoughnessMap:et,dispersion:Y,iridescence:Z,iridescenceMap:it,iridescenceThicknessMap:nt,sheen:q,sheenColorMap:st,sheenRoughnessMap:rt,specularMap:at,specularColorMap:ot,specularIntensityMap:lt,transmission:Q,transmissionMap:ht,thicknessMap:ct,gradientMap:dt,opaque:!1===s.transparent&&1===s.blending&&!1===s.alphaToCoverage,alphaMap:ut,alphaTest:pt,alphaHash:mt,combine:s.combine,mapUv:B&&m(s.map.channel),aoMapUv:N&&m(s.aoMap.channel),lightMapUv:U&&m(s.lightMap.channel),bumpMapUv:k&&m(s.bumpMap.channel),normalMapUv:z&&m(s.normalMap.channel),displacementMapUv:G&&m(s.displacementMap.channel),emissiveMapUv:H&&m(s.emissiveMap.channel),metalnessMapUv:V&&m(s.metalnessMap.channel),roughnessMapUv:W&&m(s.roughnessMap.channel),anisotropyMapUv:K&&m(s.anisotropyMap.channel),clearcoatMapUv:$&&m(s.clearcoatMap.channel),clearcoatNormalMapUv:tt&&m(s.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:et&&m(s.clearcoatRoughnessMap.channel),iridescenceMapUv:it&&m(s.iridescenceMap.channel),iridescenceThicknessMapUv:nt&&m(s.iridescenceThicknessMap.channel),sheenColorMapUv:st&&m(s.sheenColorMap.channel),sheenRoughnessMapUv:rt&&m(s.sheenRoughnessMap.channel),specularMapUv:at&&m(s.specularMap.channel),specularColorMapUv:ot&&m(s.specularColorMap.channel),specularIntensityMapUv:lt&&m(s.specularIntensityMap.channel),transmissionMapUv:ht&&m(s.transmissionMap.channel),thicknessMapUv:ct&&m(s.thicknessMap.channel),alphaMapUv:ut&&m(s.alphaMap.channel),vertexTangents:!!v.attributes.tangent&&(z||j),vertexColors:s.vertexColors,vertexAlphas:!0===s.vertexColors&&!!v.attributes.color&&4===v.attributes.color.itemSize,pointsUvs:!0===f.isPoints&&!!v.attributes.uv&&(B||ut),fog:!!g,useFog:!0===s.fog,fogExp2:!!g&&g.isFogExp2,flatShading:!1===s.wireframe&&(!0===s.flatShading||void 0===v.attributes.normal&&!1===z&&(s.isMeshLambertMaterial||s.isMeshPhongMaterial||s.isMeshStandardMaterial||s.isMeshPhysicalMaterial)),sizeAttenuation:!0===s.sizeAttenuation,logarithmicDepthBuffer:d,reversedDepthBuffer:P,skinning:!0===f.isSkinnedMesh,morphTargets:void 0!==v.morphAttributes.position,morphNormals:void 0!==v.morphAttributes.normal,morphColors:void 0!==v.morphAttributes.color,morphTargetsCount:w,morphTextureStride:D,numDirLights:a.directional.length,numPointLights:a.point.length,numSpotLights:a.spot.length,numSpotLightMaps:a.spotLightMap.length,numRectAreaLights:a.rectArea.length,numHemiLights:a.hemi.length,numDirLightShadows:a.directionalShadowMap.length,numPointLightShadows:a.pointShadowMap.length,numSpotLightShadows:a.spotShadowMap.length,numSpotLightShadowsWithMaps:a.numSpotLightShadowsWithMaps,numLightProbes:a.numLightProbes,numClippingPlanes:r.numPlanes,numClipIntersection:r.numIntersection,dithering:s.dithering,shadowMapEnabled:t.shadowMap.enabled&&h.length>0,shadowMapType:t.shadowMap.type,toneMapping:gt,decodeVideoTexture:B&&!0===s.map.isVideoTexture&&Ci.getTransfer(s.map.colorSpace)===De,decodeVideoTextureEmissive:H&&!0===s.emissiveMap.isVideoTexture&&Ci.getTransfer(s.emissiveMap.colorSpace)===De,premultipliedAlpha:s.premultipliedAlpha,doubleSided:2===s.side,flipSided:1===s.side,useDepthPacking:s.depthPacking>=0,depthPacking:s.depthPacking||0,index0AttributeName:s.index0AttributeName,extensionClipCullDistance:ft&&!0===s.extensions.clipCullDistance&&i.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(ft&&!0===s.extensions.multiDraw||L)&&i.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:i.has("KHR_parallel_shader_compile"),customProgramCacheKey:s.customProgramCacheKey()};return vt.vertexUv1s=l.has(1),vt.vertexUv2s=l.has(2),vt.vertexUv3s=l.has(3),l.clear(),vt},getProgramCacheKey:function(e){const i=[];if(e.shaderID?i.push(e.shaderID):(i.push(e.customVertexShaderID),i.push(e.customFragmentShaderID)),void 0!==e.defines)for(const t in e.defines)i.push(t),i.push(e.defines[t]);return!1===e.isRawShaderMaterial&&(!function(t,e){t.push(e.precision),t.push(e.outputColorSpace),t.push(e.envMapMode),t.push(e.envMapCubeUVHeight),t.push(e.mapUv),t.push(e.alphaMapUv),t.push(e.lightMapUv),t.push(e.aoMapUv),t.push(e.bumpMapUv),t.push(e.normalMapUv),t.push(e.displacementMapUv),t.push(e.emissiveMapUv),t.push(e.metalnessMapUv),t.push(e.roughnessMapUv),t.push(e.anisotropyMapUv),t.push(e.clearcoatMapUv),t.push(e.clearcoatNormalMapUv),t.push(e.clearcoatRoughnessMapUv),t.push(e.iridescenceMapUv),t.push(e.iridescenceThicknessMapUv),t.push(e.sheenColorMapUv),t.push(e.sheenRoughnessMapUv),t.push(e.specularMapUv),t.push(e.specularColorMapUv),t.push(e.specularIntensityMapUv),t.push(e.transmissionMapUv),t.push(e.thicknessMapUv),t.push(e.combine),t.push(e.fogExp2),t.push(e.sizeAttenuation),t.push(e.morphTargetsCount),t.push(e.morphAttributeCount),t.push(e.numDirLights),t.push(e.numPointLights),t.push(e.numSpotLights),t.push(e.numSpotLightMaps),t.push(e.numHemiLights),t.push(e.numRectAreaLights),t.push(e.numDirLightShadows),t.push(e.numPointLightShadows),t.push(e.numSpotLightShadows),t.push(e.numSpotLightShadowsWithMaps),t.push(e.numLightProbes),t.push(e.shadowMapType),t.push(e.toneMapping),t.push(e.numClippingPlanes),t.push(e.numClipIntersection),t.push(e.depthPacking)}(i,e),function(t,e){a.disableAll(),e.instancing&&a.enable(0);e.instancingColor&&a.enable(1);e.instancingMorph&&a.enable(2);e.matcap&&a.enable(3);e.envMap&&a.enable(4);e.normalMapObjectSpace&&a.enable(5);e.normalMapTangentSpace&&a.enable(6);e.clearcoat&&a.enable(7);e.iridescence&&a.enable(8);e.alphaTest&&a.enable(9);e.vertexColors&&a.enable(10);e.vertexAlphas&&a.enable(11);e.vertexUv1s&&a.enable(12);e.vertexUv2s&&a.enable(13);e.vertexUv3s&&a.enable(14);e.vertexTangents&&a.enable(15);e.anisotropy&&a.enable(16);e.alphaHash&&a.enable(17);e.batching&&a.enable(18);e.dispersion&&a.enable(19);e.batchingColor&&a.enable(20);e.gradientMap&&a.enable(21);t.push(a.mask),a.disableAll(),e.fog&&a.enable(0);e.useFog&&a.enable(1);e.flatShading&&a.enable(2);e.logarithmicDepthBuffer&&a.enable(3);e.reversedDepthBuffer&&a.enable(4);e.skinning&&a.enable(5);e.morphTargets&&a.enable(6);e.morphNormals&&a.enable(7);e.morphColors&&a.enable(8);e.premultipliedAlpha&&a.enable(9);e.shadowMapEnabled&&a.enable(10);e.doubleSided&&a.enable(11);e.flipSided&&a.enable(12);e.useDepthPacking&&a.enable(13);e.dithering&&a.enable(14);e.transmission&&a.enable(15);e.sheen&&a.enable(16);e.opaque&&a.enable(17);e.pointsUvs&&a.enable(18);e.decodeVideoTexture&&a.enable(19);e.decodeVideoTextureEmissive&&a.enable(20);e.alphaToCoverage&&a.enable(21);t.push(a.mask)}(i,e),i.push(t.outputColorSpace)),i.push(e.customProgramCacheKey),i.join()},getUniforms:function(t){const e=p[t.type];let i;if(e){const t=yd[e];i=Cl.clone(t.uniforms)}else i=t.uniforms;return i},acquireProgram:function(e,i){let n=c.get(i);return void 0!==n?++n.usedTimes:(n=new Tp(t,i,e,s),h.push(n),c.set(i,n)),n},releaseProgram:function(t){if(0===--t.usedTimes){const e=h.indexOf(t);h[e]=h[h.length-1],h.pop(),c.delete(t.cacheKey),t.destroy()}},releaseShaderCache:function(t){o.remove(t)},programs:h,dispose:function(){o.dispose()}}}function Ip(){let t=new WeakMap;return{has:function(e){return t.has(e)},get:function(e){let i=t.get(e);return void 0===i&&(i={},t.set(e,i)),i},remove:function(e){t.delete(e)},update:function(e,i,n){t.get(e)[i]=n},dispose:function(){t=new WeakMap}}}function Lp(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.material.id!==e.material.id?t.material.id-e.material.id:t.materialVariant!==e.materialVariant?t.materialVariant-e.materialVariant:t.z!==e.z?t.z-e.z:t.id-e.id}function Bp(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.z!==e.z?e.z-t.z:t.id-e.id}function Op(){const t=[];let e=0;const i=[],n=[],s=[];function r(t){let e=0;return t.isInstancedMesh&&(e+=2),t.isSkinnedMesh&&(e+=1),e}function a(i,n,s,a,o,l){let h=t[e];return void 0===h?(h={id:i.id,object:i,geometry:n,material:s,materialVariant:r(i),groupOrder:a,renderOrder:i.renderOrder,z:o,group:l},t[e]=h):(h.id=i.id,h.object=i,h.geometry=n,h.material=s,h.materialVariant=r(i),h.groupOrder=a,h.renderOrder=i.renderOrder,h.z=o,h.group=l),e++,h}return{opaque:i,transmissive:n,transparent:s,init:function(){e=0,i.length=0,n.length=0,s.length=0},push:function(t,e,r,o,l,h){const c=a(t,e,r,o,l,h);r.transmission>0?n.push(c):!0===r.transparent?s.push(c):i.push(c)},unshift:function(t,e,r,o,l,h){const c=a(t,e,r,o,l,h);r.transmission>0?n.unshift(c):!0===r.transparent?s.unshift(c):i.unshift(c)},finish:function(){for(let i=e,n=t.length;i<n;i++){const e=t[i];if(null===e.id)break;e.id=null,e.object=null,e.geometry=null,e.material=null,e.group=null}},sort:function(t,e){i.length>1&&i.sort(t||Lp),n.length>1&&n.sort(e||Bp),s.length>1&&s.sort(e||Bp)}}}function Fp(){let t=new WeakMap;return{get:function(e,i){const n=t.get(e);let s;return void 0===n?(s=new Op,t.set(e,[s])):i>=n.length?(s=new Op,n.push(s)):s=n[i],s},dispose:function(){t=new WeakMap}}}function Np(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let i;switch(e.type){case"DirectionalLight":i={direction:new xi,color:new En};break;case"SpotLight":i={position:new xi,direction:new xi,color:new En,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":i={position:new xi,color:new En,distance:0,decay:0};break;case"HemisphereLight":i={direction:new xi,skyColor:new En,groundColor:new En};break;case"RectAreaLight":i={color:new En,position:new xi,halfWidth:new xi,halfHeight:new xi}}return t[e.id]=i,i}}}let Up=0;function kp(t,e){return(e.castShadow?2:0)-(t.castShadow?2:0)+(e.map?1:0)-(t.map?1:0)}function zp(t){const e=new Np,i=function(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let i;switch(e.type){case"DirectionalLight":case"SpotLight":i={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new yi};break;case"PointLight":i={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new yi,shadowCameraNear:1,shadowCameraFar:1e3}}return t[e.id]=i,i}}}(),n={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let t=0;t<9;t++)n.probe.push(new xi);const s=new xi,r=new Wi,a=new Wi;return{setup:function(s){let r=0,a=0,o=0;for(let t=0;t<9;t++)n.probe[t].set(0,0,0);let l=0,h=0,c=0,d=0,u=0,p=0,m=0,f=0,g=0,v=0,y=0;s.sort(kp);for(let t=0,_=s.length;t<_;t++){const _=s[t],x=_.color,b=_.intensity,S=_.distance;let M=null;if(_.shadow&&_.shadow.map&&(M=_.shadow.map.texture.format===Ct?_.shadow.map.texture:_.shadow.map.depthTexture||_.shadow.map.texture),_.isAmbientLight)r+=x.r*b,a+=x.g*b,o+=x.b*b;else if(_.isLightProbe){for(let t=0;t<9;t++)n.probe[t].addScaledVector(_.sh.coefficients[t],b);y++}else if(_.isDirectionalLight){const t=e.get(_);if(t.color.copy(_.color).multiplyScalar(_.intensity),_.castShadow){const t=_.shadow,e=i.get(_);e.shadowIntensity=t.intensity,e.shadowBias=t.bias,e.shadowNormalBias=t.normalBias,e.shadowRadius=t.radius,e.shadowMapSize=t.mapSize,n.directionalShadow[l]=e,n.directionalShadowMap[l]=M,n.directionalShadowMatrix[l]=_.shadow.matrix,p++}n.directional[l]=t,l++}else if(_.isSpotLight){const t=e.get(_);t.position.setFromMatrixPosition(_.matrixWorld),t.color.copy(x).multiplyScalar(b),t.distance=S,t.coneCos=Math.cos(_.angle),t.penumbraCos=Math.cos(_.angle*(1-_.penumbra)),t.decay=_.decay,n.spot[c]=t;const s=_.shadow;if(_.map&&(n.spotLightMap[g]=_.map,g++,s.updateMatrices(_),_.castShadow&&v++),n.spotLightMatrix[c]=s.matrix,_.castShadow){const t=i.get(_);t.shadowIntensity=s.intensity,t.shadowBias=s.bias,t.shadowNormalBias=s.normalBias,t.shadowRadius=s.radius,t.shadowMapSize=s.mapSize,n.spotShadow[c]=t,n.spotShadowMap[c]=M,f++}c++}else if(_.isRectAreaLight){const t=e.get(_);t.color.copy(x).multiplyScalar(b),t.halfWidth.set(.5*_.width,0,0),t.halfHeight.set(0,.5*_.height,0),n.rectArea[d]=t,d++}else if(_.isPointLight){const t=e.get(_);if(t.color.copy(_.color).multiplyScalar(_.intensity),t.distance=_.distance,t.decay=_.decay,_.castShadow){const t=_.shadow,e=i.get(_);e.shadowIntensity=t.intensity,e.shadowBias=t.bias,e.shadowNormalBias=t.normalBias,e.shadowRadius=t.radius,e.shadowMapSize=t.mapSize,e.shadowCameraNear=t.camera.near,e.shadowCameraFar=t.camera.far,n.pointShadow[h]=e,n.pointShadowMap[h]=M,n.pointShadowMatrix[h]=_.shadow.matrix,m++}n.point[h]=t,h++}else if(_.isHemisphereLight){const t=e.get(_);t.skyColor.copy(_.color).multiplyScalar(b),t.groundColor.copy(_.groundColor).multiplyScalar(b),n.hemi[u]=t,u++}}d>0&&(!0===t.has("OES_texture_float_linear")?(n.rectAreaLTC1=vd.LTC_FLOAT_1,n.rectAreaLTC2=vd.LTC_FLOAT_2):(n.rectAreaLTC1=vd.LTC_HALF_1,n.rectAreaLTC2=vd.LTC_HALF_2)),n.ambient[0]=r,n.ambient[1]=a,n.ambient[2]=o;const _=n.hash;_.directionalLength===l&&_.pointLength===h&&_.spotLength===c&&_.rectAreaLength===d&&_.hemiLength===u&&_.numDirectionalShadows===p&&_.numPointShadows===m&&_.numSpotShadows===f&&_.numSpotMaps===g&&_.numLightProbes===y||(n.directional.length=l,n.spot.length=c,n.rectArea.length=d,n.point.length=h,n.hemi.length=u,n.directionalShadow.length=p,n.directionalShadowMap.length=p,n.pointShadow.length=m,n.pointShadowMap.length=m,n.spotShadow.length=f,n.spotShadowMap.length=f,n.directionalShadowMatrix.length=p,n.pointShadowMatrix.length=m,n.spotLightMatrix.length=f+g-v,n.spotLightMap.length=g,n.numSpotLightShadowsWithMaps=v,n.numLightProbes=y,_.directionalLength=l,_.pointLength=h,_.spotLength=c,_.rectAreaLength=d,_.hemiLength=u,_.numDirectionalShadows=p,_.numPointShadows=m,_.numSpotShadows=f,_.numSpotMaps=g,_.numLightProbes=y,n.version=Up++)},setupView:function(t,e){let i=0,o=0,l=0,h=0,c=0;const d=e.matrixWorldInverse;for(let e=0,u=t.length;e<u;e++){const u=t[e];if(u.isDirectionalLight){const t=n.directional[i];t.direction.setFromMatrixPosition(u.matrixWorld),s.setFromMatrixPosition(u.target.matrixWorld),t.direction.sub(s),t.direction.transformDirection(d),i++}else if(u.isSpotLight){const t=n.spot[l];t.position.setFromMatrixPosition(u.matrixWorld),t.position.applyMatrix4(d),t.direction.setFromMatrixPosition(u.matrixWorld),s.setFromMatrixPosition(u.target.matrixWorld),t.direction.sub(s),t.direction.transformDirection(d),l++}else if(u.isRectAreaLight){const t=n.rectArea[h];t.position.setFromMatrixPosition(u.matrixWorld),t.position.applyMatrix4(d),a.identity(),r.copy(u.matrixWorld),r.premultiply(d),a.extractRotation(r),t.halfWidth.set(.5*u.width,0,0),t.halfHeight.set(0,.5*u.height,0),t.halfWidth.applyMatrix4(a),t.halfHeight.applyMatrix4(a),h++}else if(u.isPointLight){const t=n.point[o];t.position.setFromMatrixPosition(u.matrixWorld),t.position.applyMatrix4(d),o++}else if(u.isHemisphereLight){const t=n.hemi[c];t.direction.setFromMatrixPosition(u.matrixWorld),t.direction.transformDirection(d),c++}}},state:n}}function Gp(t){const e=new zp(t),i=[],n=[];const s={lightsArray:i,shadowsArray:n,camera:null,lights:e,transmissionRenderTarget:{}};return{init:function(t){s.camera=t,i.length=0,n.length=0},state:s,setupLights:function(){e.setup(i)},setupLightsView:function(t){e.setupView(i,t)},pushLight:function(t){i.push(t)},pushShadow:function(t){n.push(t)}}}function Hp(t){let e=new WeakMap;return{get:function(i,n=0){const s=e.get(i);let r;return void 0===s?(r=new Gp(t),e.set(i,[r])):n>=s.length?(r=new Gp(t),s.push(r)):r=s[n],r},dispose:function(){e=new WeakMap}}}const Vp=[new xi(1,0,0),new xi(-1,0,0),new xi(0,1,0),new xi(0,-1,0),new xi(0,0,1),new xi(0,0,-1)],Wp=[new xi(0,-1,0),new xi(0,-1,0),new xi(0,0,1),new xi(0,0,-1),new xi(0,-1,0),new xi(0,-1,0)],jp=new Wi,Xp=new xi,Yp=new xi;function Zp(t,e,i){let n=new $r;const s=new yi,r=new yi,h=new ki,c=new Nl,d=new Ul,u={},p=i.maxTextureSize,m={[a]:1,[o]:0,[l]:2},f=new Dl({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new yi},radius:{value:4}},vertexShader:"void main() {\n\tgl_Position = vec4( position, 1.0 );\n}",fragmentShader:"uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ).rg;\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ).r;\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );\n\tgl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );\n}"}),g=f.clone();g.defines.HORIZONTAL_PASS=1;const v=new Ds;v.setAttribute("position",new ms(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const y=new xr(v,f),_=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=1;let x=this.type;function b(i,n){const r=e.update(y);f.defines.VSM_SAMPLES!==i.blurSamples&&(f.defines.VSM_SAMPLES=i.blurSamples,g.defines.VSM_SAMPLES=i.blurSamples,f.needsUpdate=!0,g.needsUpdate=!0),null===i.mapPass&&(i.mapPass=new Gi(s.x,s.y,{format:Ct,type:ft})),f.uniforms.shadow_pass.value=i.map.depthTexture,f.uniforms.resolution.value=i.mapSize,f.uniforms.radius.value=i.radius,t.setRenderTarget(i.mapPass),t.clear(),t.renderBufferDirect(n,null,r,f,y,null),g.uniforms.shadow_pass.value=i.mapPass.texture,g.uniforms.resolution.value=i.mapSize,g.uniforms.radius.value=i.radius,t.setRenderTarget(i.map),t.clear(),t.renderBufferDirect(n,null,r,g,y,null)}function S(e,i,n,s){let r=null;const a=!0===n.isPointLight?e.customDistanceMaterial:e.customDepthMaterial;if(void 0!==a)r=a;else if(r=!0===n.isPointLight?d:c,t.localClippingEnabled&&!0===i.clipShadows&&Array.isArray(i.clippingPlanes)&&0!==i.clippingPlanes.length||i.displacementMap&&0!==i.displacementScale||i.alphaMap&&i.alphaTest>0||i.map&&i.alphaTest>0||!0===i.alphaToCoverage){const t=r.uuid,e=i.uuid;let n=u[t];void 0===n&&(n={},u[t]=n);let s=n[e];void 0===s&&(s=r.clone(),n[e]=s,i.addEventListener("dispose",w)),r=s}if(r.visible=i.visible,r.wireframe=i.wireframe,r.side=3===s?null!==i.shadowSide?i.shadowSide:i.side:null!==i.shadowSide?i.shadowSide:m[i.side],r.alphaMap=i.alphaMap,r.alphaTest=!0===i.alphaToCoverage?.5:i.alphaTest,r.map=i.map,r.clipShadows=i.clipShadows,r.clippingPlanes=i.clippingPlanes,r.clipIntersection=i.clipIntersection,r.displacementMap=i.displacementMap,r.displacementScale=i.displacementScale,r.displacementBias=i.displacementBias,r.wireframeLinewidth=i.wireframeLinewidth,r.linewidth=i.linewidth,!0===n.isPointLight&&!0===r.isMeshDistanceMaterial){t.properties.get(r).light=n}return r}function M(i,s,r,a,o){if(!1===i.visible)return;if(i.layers.test(s.layers)&&(i.isMesh||i.isLine||i.isPoints)&&(i.castShadow||i.receiveShadow&&3===o)&&(!i.frustumCulled||n.intersectsObject(i))){i.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,i.matrixWorld);const n=e.update(i),l=i.material;if(Array.isArray(l)){const e=n.groups;for(let h=0,c=e.length;h<c;h++){const c=e[h],d=l[c.materialIndex];if(d&&d.visible){const e=S(i,d,a,o);i.onBeforeShadow(t,i,s,r,n,e,c),t.renderBufferDirect(r,null,n,e,i,c),i.onAfterShadow(t,i,s,r,n,e,c)}}}else if(l.visible){const e=S(i,l,a,o);i.onBeforeShadow(t,i,s,r,n,e,null),t.renderBufferDirect(r,null,n,e,i,null),i.onAfterShadow(t,i,s,r,n,e,null)}}const l=i.children;for(let t=0,e=l.length;t<e;t++)M(l[t],s,r,a,o)}function w(t){t.target.removeEventListener("dispose",w);for(const e in u){const i=u[e],n=t.target.uuid;if(n in i){i[n].dispose(),delete i[n]}}}this.render=function(e,i,a){if(!1===_.enabled)return;if(!1===_.autoUpdate&&!1===_.needsUpdate)return;if(0===e.length)return;2===this.type&&(ii("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=1);const o=t.getRenderTarget(),l=t.getActiveCubeFace(),c=t.getActiveMipmapLevel(),d=t.state;d.setBlending(0),!0===d.buffers.depth.getReversed()?d.buffers.color.setClear(0,0,0,0):d.buffers.color.setClear(1,1,1,1),d.buffers.depth.setTest(!0),d.setScissorTest(!1);const u=x!==this.type;u&&i.traverse(function(t){t.material&&(Array.isArray(t.material)?t.material.forEach(t=>t.needsUpdate=!0):t.material.needsUpdate=!0)});for(let o=0,l=e.length;o<l;o++){const l=e[o],c=l.shadow;if(void 0===c){ii("WebGLShadowMap:",l,"has no shadow.");continue}if(!1===c.autoUpdate&&!1===c.needsUpdate)continue;s.copy(c.mapSize);const m=c.getFrameExtents();s.multiply(m),r.copy(c.mapSize),(s.x>p||s.y>p)&&(s.x>p&&(r.x=Math.floor(p/m.x),s.x=r.x*m.x,c.mapSize.x=r.x),s.y>p&&(r.y=Math.floor(p/m.y),s.y=r.y*m.y,c.mapSize.y=r.y));const f=t.state.buffers.depth.getReversed();if(c.camera._reversedDepth=f,null===c.map||!0===u){if(null!==c.map&&(null!==c.map.depthTexture&&(c.map.depthTexture.dispose(),c.map.depthTexture=null),c.map.dispose()),3===this.type){if(l.isPointLight){ii("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}c.map=new Gi(s.x,s.y,{format:Ct,type:ft,minFilter:rt,magFilter:rt,generateMipmaps:!1}),c.map.texture.name=l.name+".shadowMap",c.map.depthTexture=new Ya(s.x,s.y,mt),c.map.depthTexture.name=l.name+".shadowMapDepth",c.map.depthTexture.format=wt,c.map.depthTexture.compareFunction=null,c.map.depthTexture.minFilter=it,c.map.depthTexture.magFilter=it}else l.isPointLight?(c.map=new Hd(s.x),c.map.depthTexture=new Za(s.x,pt)):(c.map=new Gi(s.x,s.y),c.map.depthTexture=new Ya(s.x,s.y,pt)),c.map.depthTexture.name=l.name+".shadowMap",c.map.depthTexture.format=wt,1===this.type?(c.map.depthTexture.compareFunction=f?Ge:Ue,c.map.depthTexture.minFilter=rt,c.map.depthTexture.magFilter=rt):(c.map.depthTexture.compareFunction=null,c.map.depthTexture.minFilter=it,c.map.depthTexture.magFilter=it);c.camera.updateProjectionMatrix()}const g=c.map.isWebGLCubeRenderTarget?6:1;for(let e=0;e<g;e++){if(c.map.isWebGLCubeRenderTarget)t.setRenderTarget(c.map,e),t.clear();else{0===e&&(t.setRenderTarget(c.map),t.clear());const i=c.getViewport(e);h.set(r.x*i.x,r.y*i.y,r.x*i.z,r.y*i.w),d.viewport(h)}if(l.isPointLight){const t=c.camera,i=c.matrix,n=l.distance||t.far;n!==t.far&&(t.far=n,t.updateProjectionMatrix()),Xp.setFromMatrixPosition(l.matrixWorld),t.position.copy(Xp),Yp.copy(t.position),Yp.add(Vp[e]),t.up.copy(Wp[e]),t.lookAt(Yp),t.updateMatrixWorld(),i.makeTranslation(-Xp.x,-Xp.y,-Xp.z),jp.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),c._frustum.setFromProjectionMatrix(jp,t.coordinateSystem,t.reversedDepth)}else c.updateMatrices(l);n=c.getFrustum(),M(i,a,c.camera,l,this.type)}!0!==c.isPointLightShadow&&3===this.type&&b(c,a),c.needsUpdate=!1}x=this.type,_.needsUpdate=!1,t.setRenderTarget(o,l,c)}}function qp(t,e){const i=new function(){let e=!1;const i=new ki;let n=null;const s=new ki(0,0,0,0);return{setMask:function(i){n===i||e||(t.colorMask(i,i,i,i),n=i)},setLocked:function(t){e=t},setClear:function(e,n,r,a,o){!0===o&&(e*=a,n*=a,r*=a),i.set(e,n,r,a),!1===s.equals(i)&&(t.clearColor(e,n,r,a),s.copy(i))},reset:function(){e=!1,n=null,s.set(-1,0,0,0)}}},n=new function(){let i=!1,n=!1,s=null,r=null,a=null;return{setReversed:function(t){if(n!==t){const i=e.get("EXT_clip_control");t?i.clipControlEXT(i.LOWER_LEFT_EXT,i.ZERO_TO_ONE_EXT):i.clipControlEXT(i.LOWER_LEFT_EXT,i.NEGATIVE_ONE_TO_ONE_EXT),n=t;const s=a;a=null,this.setClear(s)}},getReversed:function(){return n},setTest:function(e){e?st(t.DEPTH_TEST):rt(t.DEPTH_TEST)},setMask:function(e){s===e||i||(t.depthMask(e),s=e)},setFunc:function(e){if(n&&(e=ri[e]),r!==e){switch(e){case 0:t.depthFunc(t.NEVER);break;case 1:t.depthFunc(t.ALWAYS);break;case 2:t.depthFunc(t.LESS);break;case 3:default:t.depthFunc(t.LEQUAL);break;case 4:t.depthFunc(t.EQUAL);break;case 5:t.depthFunc(t.GEQUAL);break;case 6:t.depthFunc(t.GREATER);break;case 7:t.depthFunc(t.NOTEQUAL)}r=e}},setLocked:function(t){i=t},setClear:function(e){a!==e&&(a=e,n&&(e=1-e),t.clearDepth(e))},reset:function(){i=!1,s=null,r=null,a=null,n=!1}}},s=new function(){let e=!1,i=null,n=null,s=null,r=null,a=null,o=null,l=null,h=null;return{setTest:function(i){e||(i?st(t.STENCIL_TEST):rt(t.STENCIL_TEST))},setMask:function(n){i===n||e||(t.stencilMask(n),i=n)},setFunc:function(e,i,a){n===e&&s===i&&r===a||(t.stencilFunc(e,i,a),n=e,s=i,r=a)},setOp:function(e,i,n){a===e&&o===i&&l===n||(t.stencilOp(e,i,n),a=e,o=i,l=n)},setLocked:function(t){e=t},setClear:function(e){h!==e&&(t.clearStencil(e),h=e)},reset:function(){e=!1,i=null,n=null,s=null,r=null,a=null,o=null,l=null,h=null}}},r=new WeakMap,a=new WeakMap;let o={},l={},T=new WeakMap,C=[],D=null,R=!1,P=null,I=null,L=null,B=null,O=null,F=null,N=null,U=new En(0,0,0),k=0,z=!1,G=null,H=null,V=null,W=null,j=null;const X=t.getParameter(t.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let Y=!1,Z=0;const q=t.getParameter(t.VERSION);-1!==q.indexOf("WebGL")?(Z=parseFloat(/^WebGL (\d)/.exec(q)[1]),Y=Z>=1):-1!==q.indexOf("OpenGL ES")&&(Z=parseFloat(/^OpenGL ES (\d)/.exec(q)[1]),Y=Z>=2);let Q=null,K={};const J=t.getParameter(t.SCISSOR_BOX),$=t.getParameter(t.VIEWPORT),tt=(new ki).fromArray(J),et=(new ki).fromArray($);function it(e,i,n,s){const r=new Uint8Array(4),a=t.createTexture();t.bindTexture(e,a),t.texParameteri(e,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(e,t.TEXTURE_MAG_FILTER,t.NEAREST);for(let a=0;a<n;a++)e===t.TEXTURE_3D||e===t.TEXTURE_2D_ARRAY?t.texImage3D(i,0,t.RGBA,1,1,s,0,t.RGBA,t.UNSIGNED_BYTE,r):t.texImage2D(i+a,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,r);return a}const nt={};function st(e){!0!==o[e]&&(t.enable(e),o[e]=!0)}function rt(e){!1!==o[e]&&(t.disable(e),o[e]=!1)}nt[t.TEXTURE_2D]=it(t.TEXTURE_2D,t.TEXTURE_2D,1),nt[t.TEXTURE_CUBE_MAP]=it(t.TEXTURE_CUBE_MAP,t.TEXTURE_CUBE_MAP_POSITIVE_X,6),nt[t.TEXTURE_2D_ARRAY]=it(t.TEXTURE_2D_ARRAY,t.TEXTURE_2D_ARRAY,1,1),nt[t.TEXTURE_3D]=it(t.TEXTURE_3D,t.TEXTURE_3D,1,1),i.setClear(0,0,0,1),n.setClear(1),s.setClear(0),st(t.DEPTH_TEST),n.setFunc(3),ht(!1),ct(1),st(t.CULL_FACE),lt(0);const at={[h]:t.FUNC_ADD,[c]:t.FUNC_SUBTRACT,[d]:t.FUNC_REVERSE_SUBTRACT};at[103]=t.MIN,at[104]=t.MAX;const ot={[u]:t.ZERO,[p]:t.ONE,[m]:t.SRC_COLOR,[g]:t.SRC_ALPHA,[S]:t.SRC_ALPHA_SATURATE,[x]:t.DST_COLOR,[y]:t.DST_ALPHA,[f]:t.ONE_MINUS_SRC_COLOR,[v]:t.ONE_MINUS_SRC_ALPHA,[b]:t.ONE_MINUS_DST_COLOR,[_]:t.ONE_MINUS_DST_ALPHA,[M]:t.CONSTANT_COLOR,[w]:t.ONE_MINUS_CONSTANT_COLOR,[A]:t.CONSTANT_ALPHA,[E]:t.ONE_MINUS_CONSTANT_ALPHA};function lt(e,i,n,s,r,a,o,l,c,d){if(0!==e){if(!1===R&&(st(t.BLEND),R=!0),5===e)r=r||i,a=a||n,o=o||s,i===I&&r===O||(t.blendEquationSeparate(at[i],at[r]),I=i,O=r),n===L&&s===B&&a===F&&o===N||(t.blendFuncSeparate(ot[n],ot[s],ot[a],ot[o]),L=n,B=s,F=a,N=o),!1!==l.equals(U)&&c===k||(t.blendColor(l.r,l.g,l.b,c),U.copy(l),k=c),P=e,z=!1;else if(e!==P||d!==z){if(I===h&&O===h||(t.blendEquation(t.FUNC_ADD),I=h,O=h),d)switch(e){case 1:t.blendFuncSeparate(t.ONE,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA);break;case 2:t.blendFunc(t.ONE,t.ONE);break;case 3:t.blendFuncSeparate(t.ZERO,t.ONE_MINUS_SRC_COLOR,t.ZERO,t.ONE);break;case 4:t.blendFuncSeparate(t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ZERO,t.ONE);break;default:ni("WebGLState: Invalid blending: ",e)}else switch(e){case 1:t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA);break;case 2:t.blendFuncSeparate(t.SRC_ALPHA,t.ONE,t.ONE,t.ONE);break;case 3:ni("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case 4:ni("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:ni("WebGLState: Invalid blending: ",e)}L=null,B=null,F=null,N=null,U.set(0,0,0),k=0,P=e,z=d}}else!0===R&&(rt(t.BLEND),R=!1)}function ht(e){G!==e&&(e?t.frontFace(t.CW):t.frontFace(t.CCW),G=e)}function ct(e){0!==e?(st(t.CULL_FACE),e!==H&&(1===e?t.cullFace(t.BACK):2===e?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):rt(t.CULL_FACE),H=e}function dt(e,i,s){e?(st(t.POLYGON_OFFSET_FILL),W===i&&j===s||(W=i,j=s,n.getReversed()&&(i=-i),t.polygonOffset(i,s))):rt(t.POLYGON_OFFSET_FILL)}return{buffers:{color:i,depth:n,stencil:s},enable:st,disable:rt,bindFramebuffer:function(e,i){return l[e]!==i&&(t.bindFramebuffer(e,i),l[e]=i,e===t.DRAW_FRAMEBUFFER&&(l[t.FRAMEBUFFER]=i),e===t.FRAMEBUFFER&&(l[t.DRAW_FRAMEBUFFER]=i),!0)},drawBuffers:function(e,i){let n=C,s=!1;if(e){n=T.get(i),void 0===n&&(n=[],T.set(i,n));const r=e.textures;if(n.length!==r.length||n[0]!==t.COLOR_ATTACHMENT0){for(let e=0,i=r.length;e<i;e++)n[e]=t.COLOR_ATTACHMENT0+e;n.length=r.length,s=!0}}else n[0]!==t.BACK&&(n[0]=t.BACK,s=!0);s&&t.drawBuffers(n)},useProgram:function(e){return D!==e&&(t.useProgram(e),D=e,!0)},setBlending:lt,setMaterial:function(e,r){2===e.side?rt(t.CULL_FACE):st(t.CULL_FACE);let a=1===e.side;r&&(a=!a),ht(a),1===e.blending&&!1===e.transparent?lt(0):lt(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.blendColor,e.blendAlpha,e.premultipliedAlpha),n.setFunc(e.depthFunc),n.setTest(e.depthTest),n.setMask(e.depthWrite),i.setMask(e.colorWrite);const o=e.stencilWrite;s.setTest(o),o&&(s.setMask(e.stencilWriteMask),s.setFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),s.setOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),dt(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),!0===e.alphaToCoverage?st(t.SAMPLE_ALPHA_TO_COVERAGE):rt(t.SAMPLE_ALPHA_TO_COVERAGE)},setFlipSided:ht,setCullFace:ct,setLineWidth:function(e){e!==V&&(Y&&t.lineWidth(e),V=e)},setPolygonOffset:dt,setScissorTest:function(e){e?st(t.SCISSOR_TEST):rt(t.SCISSOR_TEST)},activeTexture:function(e){void 0===e&&(e=t.TEXTURE0+X-1),Q!==e&&(t.activeTexture(e),Q=e)},bindTexture:function(e,i,n){void 0===n&&(n=null===Q?t.TEXTURE0+X-1:Q);let s=K[n];void 0===s&&(s={type:void 0,texture:void 0},K[n]=s),s.type===e&&s.texture===i||(Q!==n&&(t.activeTexture(n),Q=n),t.bindTexture(e,i||nt[e]),s.type=e,s.texture=i)},unbindTexture:function(){const e=K[Q];void 0!==e&&void 0!==e.type&&(t.bindTexture(e.type,null),e.type=void 0,e.texture=void 0)},compressedTexImage2D:function(){try{t.compressedTexImage2D(...arguments)}catch(t){ni("WebGLState:",t)}},compressedTexImage3D:function(){try{t.compressedTexImage3D(...arguments)}catch(t){ni("WebGLState:",t)}},texImage2D:function(){try{t.texImage2D(...arguments)}catch(t){ni("WebGLState:",t)}},texImage3D:function(){try{t.texImage3D(...arguments)}catch(t){ni("WebGLState:",t)}},updateUBOMapping:function(e,i){let n=a.get(i);void 0===n&&(n=new WeakMap,a.set(i,n));let s=n.get(e);void 0===s&&(s=t.getUniformBlockIndex(i,e.name),n.set(e,s))},uniformBlockBinding:function(e,i){const n=a.get(i).get(e);r.get(i)!==n&&(t.uniformBlockBinding(i,n,e.__bindingPointIndex),r.set(i,n))},texStorage2D:function(){try{t.texStorage2D(...arguments)}catch(t){ni("WebGLState:",t)}},texStorage3D:function(){try{t.texStorage3D(...arguments)}catch(t){ni("WebGLState:",t)}},texSubImage2D:function(){try{t.texSubImage2D(...arguments)}catch(t){ni("WebGLState:",t)}},texSubImage3D:function(){try{t.texSubImage3D(...arguments)}catch(t){ni("WebGLState:",t)}},compressedTexSubImage2D:function(){try{t.compressedTexSubImage2D(...arguments)}catch(t){ni("WebGLState:",t)}},compressedTexSubImage3D:function(){try{t.compressedTexSubImage3D(...arguments)}catch(t){ni("WebGLState:",t)}},scissor:function(e){!1===tt.equals(e)&&(t.scissor(e.x,e.y,e.z,e.w),tt.copy(e))},viewport:function(e){!1===et.equals(e)&&(t.viewport(e.x,e.y,e.z,e.w),et.copy(e))},reset:function(){t.disable(t.BLEND),t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST),t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.SCISSOR_TEST),t.disable(t.STENCIL_TEST),t.disable(t.SAMPLE_ALPHA_TO_COVERAGE),t.blendEquation(t.FUNC_ADD),t.blendFunc(t.ONE,t.ZERO),t.blendFuncSeparate(t.ONE,t.ZERO,t.ONE,t.ZERO),t.blendColor(0,0,0,0),t.colorMask(!0,!0,!0,!0),t.clearColor(0,0,0,0),t.depthMask(!0),t.depthFunc(t.LESS),n.setReversed(!1),t.clearDepth(1),t.stencilMask(4294967295),t.stencilFunc(t.ALWAYS,0,4294967295),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),t.clearStencil(0),t.cullFace(t.BACK),t.frontFace(t.CCW),t.polygonOffset(0,0),t.activeTexture(t.TEXTURE0),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),t.bindFramebuffer(t.READ_FRAMEBUFFER,null),t.useProgram(null),t.lineWidth(1),t.scissor(0,0,t.canvas.width,t.canvas.height),t.viewport(0,0,t.canvas.width,t.canvas.height),o={},Q=null,K={},l={},T=new WeakMap,C=[],D=null,R=!1,P=null,I=null,L=null,B=null,O=null,F=null,N=null,U=new En(0,0,0),k=0,z=!1,G=null,H=null,V=null,W=null,j=null,tt.set(0,0,t.canvas.width,t.canvas.height),et.set(0,0,t.canvas.width,t.canvas.height),i.reset(),n.reset(),s.reset()}}}function Qp(t,e,i,n,s,r,a){const o=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,l="undefined"!=typeof navigator&&/OculusBrowser/g.test(navigator.userAgent),h=new yi,c=new WeakMap;let d;const u=new WeakMap;let p=!1;try{p="undefined"!=typeof OffscreenCanvas&&null!==new OffscreenCanvas(1,1).getContext("2d")}catch(t){}function m(t,e){return p?new OffscreenCanvas(t,e):Qe("canvas")}function f(t,e,i){let n=1;const s=V(t);if((s.width>i||s.height>i)&&(n=i/Math.max(s.width,s.height)),n<1){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap||"undefined"!=typeof VideoFrame&&t instanceof VideoFrame){const i=Math.floor(n*s.width),r=Math.floor(n*s.height);void 0===d&&(d=m(i,r));const a=e?m(i,r):d;a.width=i,a.height=r;return a.getContext("2d").drawImage(t,0,0,i,r),ii("WebGLRenderer: Texture has been resized from ("+s.width+"x"+s.height+") to ("+i+"x"+r+")."),a}return"data"in t&&ii("WebGLRenderer: Image in DataTexture is too big ("+s.width+"x"+s.height+")."),t}return t}function g(t){return t.generateMipmaps}function v(e){t.generateMipmap(e)}function y(e){return e.isWebGLCubeRenderTarget?t.TEXTURE_CUBE_MAP:e.isWebGL3DRenderTarget?t.TEXTURE_3D:e.isWebGLArrayRenderTarget||e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:t.TEXTURE_2D}function _(i,n,s,r,a=!1){if(null!==i){if(void 0!==t[i])return t[i];ii("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+i+"'")}let o=n;if(n===t.RED&&(s===t.FLOAT&&(o=t.R32F),s===t.HALF_FLOAT&&(o=t.R16F),s===t.UNSIGNED_BYTE&&(o=t.R8)),n===t.RED_INTEGER&&(s===t.UNSIGNED_BYTE&&(o=t.R8UI),s===t.UNSIGNED_SHORT&&(o=t.R16UI),s===t.UNSIGNED_INT&&(o=t.R32UI),s===t.BYTE&&(o=t.R8I),s===t.SHORT&&(o=t.R16I),s===t.INT&&(o=t.R32I)),n===t.RG&&(s===t.FLOAT&&(o=t.RG32F),s===t.HALF_FLOAT&&(o=t.RG16F),s===t.UNSIGNED_BYTE&&(o=t.RG8)),n===t.RG_INTEGER&&(s===t.UNSIGNED_BYTE&&(o=t.RG8UI),s===t.UNSIGNED_SHORT&&(o=t.RG16UI),s===t.UNSIGNED_INT&&(o=t.RG32UI),s===t.BYTE&&(o=t.RG8I),s===t.SHORT&&(o=t.RG16I),s===t.INT&&(o=t.RG32I)),n===t.RGB_INTEGER&&(s===t.UNSIGNED_BYTE&&(o=t.RGB8UI),s===t.UNSIGNED_SHORT&&(o=t.RGB16UI),s===t.UNSIGNED_INT&&(o=t.RGB32UI),s===t.BYTE&&(o=t.RGB8I),s===t.SHORT&&(o=t.RGB16I),s===t.INT&&(o=t.RGB32I)),n===t.RGBA_INTEGER&&(s===t.UNSIGNED_BYTE&&(o=t.RGBA8UI),s===t.UNSIGNED_SHORT&&(o=t.RGBA16UI),s===t.UNSIGNED_INT&&(o=t.RGBA32UI),s===t.BYTE&&(o=t.RGBA8I),s===t.SHORT&&(o=t.RGBA16I),s===t.INT&&(o=t.RGBA32I)),n===t.RGB&&(s===t.UNSIGNED_INT_5_9_9_9_REV&&(o=t.RGB9_E5),s===t.UNSIGNED_INT_10F_11F_11F_REV&&(o=t.R11F_G11F_B10F)),n===t.RGBA){const e=a?Ce:Ci.getTransfer(r);s===t.FLOAT&&(o=t.RGBA32F),s===t.HALF_FLOAT&&(o=t.RGBA16F),s===t.UNSIGNED_BYTE&&(o=e===De?t.SRGB8_ALPHA8:t.RGBA8),s===t.UNSIGNED_SHORT_4_4_4_4&&(o=t.RGBA4),s===t.UNSIGNED_SHORT_5_5_5_1&&(o=t.RGB5_A1)}return o!==t.R16F&&o!==t.R32F&&o!==t.RG16F&&o!==t.RG32F&&o!==t.RGBA16F&&o!==t.RGBA32F||e.get("EXT_color_buffer_float"),o}function x(e,i){let n;return e?null===i||i===pt||i===yt?n=t.DEPTH24_STENCIL8:i===mt?n=t.DEPTH32F_STENCIL8:i===dt&&(n=t.DEPTH24_STENCIL8,ii("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):null===i||i===pt||i===yt?n=t.DEPTH_COMPONENT24:i===mt?n=t.DEPTH_COMPONENT32F:i===dt&&(n=t.DEPTH_COMPONENT16),n}function b(t,e){return!0===g(t)||t.isFramebufferTexture&&t.minFilter!==it&&t.minFilter!==rt?Math.log2(Math.max(e.width,e.height))+1:void 0!==t.mipmaps&&t.mipmaps.length>0?t.mipmaps.length:t.isCompressedTexture&&Array.isArray(t.image)?e.mipmaps.length:1}function S(t){const e=t.target;e.removeEventListener("dispose",S),function(t){const e=n.get(t);if(void 0===e.__webglInit)return;const i=t.source,s=u.get(i);if(s){const n=s[e.__cacheKey];n.usedTimes--,0===n.usedTimes&&w(t),0===Object.keys(s).length&&u.delete(i)}n.remove(t)}(e),e.isVideoTexture&&c.delete(e)}function M(e){const i=e.target;i.removeEventListener("dispose",M),function(e){const i=n.get(e);e.depthTexture&&(e.depthTexture.dispose(),n.remove(e.depthTexture));if(e.isWebGLCubeRenderTarget)for(let e=0;e<6;e++){if(Array.isArray(i.__webglFramebuffer[e]))for(let n=0;n<i.__webglFramebuffer[e].length;n++)t.deleteFramebuffer(i.__webglFramebuffer[e][n]);else t.deleteFramebuffer(i.__webglFramebuffer[e]);i.__webglDepthbuffer&&t.deleteRenderbuffer(i.__webglDepthbuffer[e])}else{if(Array.isArray(i.__webglFramebuffer))for(let e=0;e<i.__webglFramebuffer.length;e++)t.deleteFramebuffer(i.__webglFramebuffer[e]);else t.deleteFramebuffer(i.__webglFramebuffer);if(i.__webglDepthbuffer&&t.deleteRenderbuffer(i.__webglDepthbuffer),i.__webglMultisampledFramebuffer&&t.deleteFramebuffer(i.__webglMultisampledFramebuffer),i.__webglColorRenderbuffer)for(let e=0;e<i.__webglColorRenderbuffer.length;e++)i.__webglColorRenderbuffer[e]&&t.deleteRenderbuffer(i.__webglColorRenderbuffer[e]);i.__webglDepthRenderbuffer&&t.deleteRenderbuffer(i.__webglDepthRenderbuffer)}const s=e.textures;for(let e=0,i=s.length;e<i;e++){const i=n.get(s[e]);i.__webglTexture&&(t.deleteTexture(i.__webglTexture),a.memory.textures--),n.remove(s[e])}n.remove(e)}(i)}function w(e){const i=n.get(e);t.deleteTexture(i.__webglTexture);const s=e.source;delete u.get(s)[i.__cacheKey],a.memory.textures--}let A=0;function E(e,s){const r=n.get(e);if(e.isVideoTexture&&function(t){const e=a.render.frame;c.get(t)!==e&&(c.set(t,e),t.update())}(e),!1===e.isRenderTargetTexture&&!0!==e.isExternalTexture&&e.version>0&&r.__version!==e.version){const t=e.image;if(null===t)ii("WebGLRenderer: Texture marked for update but no image data found.");else{if(!1!==t.complete)return void L(r,e,s);ii("WebGLRenderer: Texture marked for update but image is incomplete")}}else e.isExternalTexture&&(r.__webglTexture=e.sourceTexture?e.sourceTexture:null);i.bindTexture(t.TEXTURE_2D,r.__webglTexture,t.TEXTURE0+s)}const T={[$]:t.REPEAT,[tt]:t.CLAMP_TO_EDGE,[et]:t.MIRRORED_REPEAT},C={[it]:t.NEAREST,[nt]:t.NEAREST_MIPMAP_NEAREST,[st]:t.NEAREST_MIPMAP_LINEAR,[rt]:t.LINEAR,[at]:t.LINEAR_MIPMAP_NEAREST,[ot]:t.LINEAR_MIPMAP_LINEAR},D={[Oe]:t.NEVER,[He]:t.ALWAYS,[Fe]:t.LESS,[Ue]:t.LEQUAL,[Ne]:t.EQUAL,[Ge]:t.GEQUAL,[ke]:t.GREATER,[ze]:t.NOTEQUAL};function R(i,r){if(r.type!==mt||!1!==e.has("OES_texture_float_linear")||r.magFilter!==rt&&r.magFilter!==at&&r.magFilter!==st&&r.magFilter!==ot&&r.minFilter!==rt&&r.minFilter!==at&&r.minFilter!==st&&r.minFilter!==ot||ii("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),t.texParameteri(i,t.TEXTURE_WRAP_S,T[r.wrapS]),t.texParameteri(i,t.TEXTURE_WRAP_T,T[r.wrapT]),i!==t.TEXTURE_3D&&i!==t.TEXTURE_2D_ARRAY||t.texParameteri(i,t.TEXTURE_WRAP_R,T[r.wrapR]),t.texParameteri(i,t.TEXTURE_MAG_FILTER,C[r.magFilter]),t.texParameteri(i,t.TEXTURE_MIN_FILTER,C[r.minFilter]),r.compareFunction&&(t.texParameteri(i,t.TEXTURE_COMPARE_MODE,t.COMPARE_REF_TO_TEXTURE),t.texParameteri(i,t.TEXTURE_COMPARE_FUNC,D[r.compareFunction])),!0===e.has("EXT_texture_filter_anisotropic")){if(r.magFilter===it)return;if(r.minFilter!==st&&r.minFilter!==ot)return;if(r.type===mt&&!1===e.has("OES_texture_float_linear"))return;if(r.anisotropy>1||n.get(r).__currentAnisotropy){const a=e.get("EXT_texture_filter_anisotropic");t.texParameterf(i,a.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(r.anisotropy,s.getMaxAnisotropy())),n.get(r).__currentAnisotropy=r.anisotropy}}}function P(e,i){let n=!1;void 0===e.__webglInit&&(e.__webglInit=!0,i.addEventListener("dispose",S));const s=i.source;let r=u.get(s);void 0===r&&(r={},u.set(s,r));const o=function(t){const e=[];return e.push(t.wrapS),e.push(t.wrapT),e.push(t.wrapR||0),e.push(t.magFilter),e.push(t.minFilter),e.push(t.anisotropy),e.push(t.internalFormat),e.push(t.format),e.push(t.type),e.push(t.generateMipmaps),e.push(t.premultiplyAlpha),e.push(t.flipY),e.push(t.unpackAlignment),e.push(t.colorSpace),e.join()}(i);if(o!==e.__cacheKey){void 0===r[o]&&(r[o]={texture:t.createTexture(),usedTimes:0},a.memory.textures++,n=!0),r[o].usedTimes++;const s=r[e.__cacheKey];void 0!==s&&(r[e.__cacheKey].usedTimes--,0===s.usedTimes&&w(i)),e.__cacheKey=o,e.__webglTexture=r[o].texture}return n}function I(t,e,i){return Math.floor(Math.floor(t/i)/e)}function L(e,a,o){let l=t.TEXTURE_2D;(a.isDataArrayTexture||a.isCompressedArrayTexture)&&(l=t.TEXTURE_2D_ARRAY),a.isData3DTexture&&(l=t.TEXTURE_3D);const h=P(e,a),c=a.source;i.bindTexture(l,e.__webglTexture,t.TEXTURE0+o);const d=n.get(c);if(c.version!==d.__version||!0===h){i.activeTexture(t.TEXTURE0+o);const e=Ci.getPrimaries(Ci.workingColorSpace),n=a.colorSpace===Ae?null:Ci.getPrimaries(a.colorSpace),u=a.colorSpace===Ae||e===n?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,a.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,a.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,u);let p=f(a.image,!1,s.maxTextureSize);p=H(a,p);const m=r.convert(a.format,a.colorSpace),y=r.convert(a.type);let S,M=_(a.internalFormat,m,y,a.colorSpace,a.isVideoTexture);R(l,a);const w=a.mipmaps,A=!0!==a.isVideoTexture,E=void 0===d.__version||!0===h,T=c.dataReady,C=b(a,p);if(a.isDepthTexture)M=x(a.format===At,a.type),E&&(A?i.texStorage2D(t.TEXTURE_2D,1,M,p.width,p.height):i.texImage2D(t.TEXTURE_2D,0,M,p.width,p.height,0,m,y,null));else if(a.isDataTexture)if(w.length>0){A&&E&&i.texStorage2D(t.TEXTURE_2D,C,M,w[0].width,w[0].height);for(let e=0,n=w.length;e<n;e++)S=w[e],A?T&&i.texSubImage2D(t.TEXTURE_2D,e,0,0,S.width,S.height,m,y,S.data):i.texImage2D(t.TEXTURE_2D,e,M,S.width,S.height,0,m,y,S.data);a.generateMipmaps=!1}else A?(E&&i.texStorage2D(t.TEXTURE_2D,C,M,p.width,p.height),T&&function(e,n,s,r){const a=e.updateRanges;if(0===a.length)i.texSubImage2D(t.TEXTURE_2D,0,0,0,n.width,n.height,s,r,n.data);else{a.sort((t,e)=>t.start-e.start);let o=0;for(let t=1;t<a.length;t++){const e=a[o],i=a[t],s=e.start+e.count,r=I(i.start,n.width,4),l=I(e.start,n.width,4);i.start<=s+1&&r===l&&I(i.start+i.count-1,n.width,4)===r?e.count=Math.max(e.count,i.start+i.count-e.start):(++o,a[o]=i)}a.length=o+1;const l=t.getParameter(t.UNPACK_ROW_LENGTH),h=t.getParameter(t.UNPACK_SKIP_PIXELS),c=t.getParameter(t.UNPACK_SKIP_ROWS);t.pixelStorei(t.UNPACK_ROW_LENGTH,n.width);for(let e=0,o=a.length;e<o;e++){const o=a[e],l=Math.floor(o.start/4),h=Math.ceil(o.count/4),c=l%n.width,d=Math.floor(l/n.width),u=h,p=1;t.pixelStorei(t.UNPACK_SKIP_PIXELS,c),t.pixelStorei(t.UNPACK_SKIP_ROWS,d),i.texSubImage2D(t.TEXTURE_2D,0,c,d,u,p,s,r,n.data)}e.clearUpdateRanges(),t.pixelStorei(t.UNPACK_ROW_LENGTH,l),t.pixelStorei(t.UNPACK_SKIP_PIXELS,h),t.pixelStorei(t.UNPACK_SKIP_ROWS,c)}}(a,p,m,y)):i.texImage2D(t.TEXTURE_2D,0,M,p.width,p.height,0,m,y,p.data);else if(a.isCompressedTexture)if(a.isCompressedArrayTexture){A&&E&&i.texStorage3D(t.TEXTURE_2D_ARRAY,C,M,w[0].width,w[0].height,p.depth);for(let e=0,n=w.length;e<n;e++)if(S=w[e],a.format!==Mt)if(null!==m)if(A){if(T)if(a.layerUpdates.size>0){const n=pd(S.width,S.height,a.format,a.type);for(const s of a.layerUpdates){const r=S.data.subarray(s*n/S.data.BYTES_PER_ELEMENT,(s+1)*n/S.data.BYTES_PER_ELEMENT);i.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,s,S.width,S.height,1,m,r)}a.clearLayerUpdates()}else i.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,S.width,S.height,p.depth,m,S.data)}else i.compressedTexImage3D(t.TEXTURE_2D_ARRAY,e,M,S.width,S.height,p.depth,0,S.data,0,0);else ii("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else A?T&&i.texSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,S.width,S.height,p.depth,m,y,S.data):i.texImage3D(t.TEXTURE_2D_ARRAY,e,M,S.width,S.height,p.depth,0,m,y,S.data)}else{A&&E&&i.texStorage2D(t.TEXTURE_2D,C,M,w[0].width,w[0].height);for(let e=0,n=w.length;e<n;e++)S=w[e],a.format!==Mt?null!==m?A?T&&i.compressedTexSubImage2D(t.TEXTURE_2D,e,0,0,S.width,S.height,m,S.data):i.compressedTexImage2D(t.TEXTURE_2D,e,M,S.width,S.height,0,S.data):ii("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):A?T&&i.texSubImage2D(t.TEXTURE_2D,e,0,0,S.width,S.height,m,y,S.data):i.texImage2D(t.TEXTURE_2D,e,M,S.width,S.height,0,m,y,S.data)}else if(a.isDataArrayTexture)if(A){if(E&&i.texStorage3D(t.TEXTURE_2D_ARRAY,C,M,p.width,p.height,p.depth),T)if(a.layerUpdates.size>0){const e=pd(p.width,p.height,a.format,a.type);for(const n of a.layerUpdates){const s=p.data.subarray(n*e/p.data.BYTES_PER_ELEMENT,(n+1)*e/p.data.BYTES_PER_ELEMENT);i.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,n,p.width,p.height,1,m,y,s)}a.clearLayerUpdates()}else i.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,0,p.width,p.height,p.depth,m,y,p.data)}else i.texImage3D(t.TEXTURE_2D_ARRAY,0,M,p.width,p.height,p.depth,0,m,y,p.data);else if(a.isData3DTexture)A?(E&&i.texStorage3D(t.TEXTURE_3D,C,M,p.width,p.height,p.depth),T&&i.texSubImage3D(t.TEXTURE_3D,0,0,0,0,p.width,p.height,p.depth,m,y,p.data)):i.texImage3D(t.TEXTURE_3D,0,M,p.width,p.height,p.depth,0,m,y,p.data);else if(a.isFramebufferTexture){if(E)if(A)i.texStorage2D(t.TEXTURE_2D,C,M,p.width,p.height);else{let e=p.width,n=p.height;for(let s=0;s<C;s++)i.texImage2D(t.TEXTURE_2D,s,M,e,n,0,m,y,null),e>>=1,n>>=1}}else if(w.length>0){if(A&&E){const e=V(w[0]);i.texStorage2D(t.TEXTURE_2D,C,M,e.width,e.height)}for(let e=0,n=w.length;e<n;e++)S=w[e],A?T&&i.texSubImage2D(t.TEXTURE_2D,e,0,0,m,y,S):i.texImage2D(t.TEXTURE_2D,e,M,m,y,S);a.generateMipmaps=!1}else if(A){if(E){const e=V(p);i.texStorage2D(t.TEXTURE_2D,C,M,e.width,e.height)}T&&i.texSubImage2D(t.TEXTURE_2D,0,0,0,m,y,p)}else i.texImage2D(t.TEXTURE_2D,0,M,m,y,p);g(a)&&v(l),d.__version=c.version,a.onUpdate&&a.onUpdate(a)}e.__version=a.version}function B(e,s,a,l,h,c){const d=r.convert(a.format,a.colorSpace),u=r.convert(a.type),p=_(a.internalFormat,d,u,a.colorSpace),m=n.get(s),f=n.get(a);if(f.__renderTarget=s,!m.__hasExternalTextures){const e=Math.max(1,s.width>>c),n=Math.max(1,s.height>>c);h===t.TEXTURE_3D||h===t.TEXTURE_2D_ARRAY?i.texImage3D(h,c,p,e,n,s.depth,0,d,u,null):i.texImage2D(h,c,p,e,n,0,d,u,null)}i.bindFramebuffer(t.FRAMEBUFFER,e),G(s)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,l,h,f.__webglTexture,0,z(s)):(h===t.TEXTURE_2D||h>=t.TEXTURE_CUBE_MAP_POSITIVE_X&&h<=t.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&t.framebufferTexture2D(t.FRAMEBUFFER,l,h,f.__webglTexture,c),i.bindFramebuffer(t.FRAMEBUFFER,null)}function O(e,i,n){if(t.bindRenderbuffer(t.RENDERBUFFER,e),i.depthBuffer){const s=i.depthTexture,r=s&&s.isDepthTexture?s.type:null,a=x(i.stencilBuffer,r),l=i.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;G(i)?o.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,z(i),a,i.width,i.height):n?t.renderbufferStorageMultisample(t.RENDERBUFFER,z(i),a,i.width,i.height):t.renderbufferStorage(t.RENDERBUFFER,a,i.width,i.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,l,t.RENDERBUFFER,e)}else{const e=i.textures;for(let s=0;s<e.length;s++){const a=e[s],l=r.convert(a.format,a.colorSpace),h=r.convert(a.type),c=_(a.internalFormat,l,h,a.colorSpace);G(i)?o.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,z(i),c,i.width,i.height):n?t.renderbufferStorageMultisample(t.RENDERBUFFER,z(i),c,i.width,i.height):t.renderbufferStorage(t.RENDERBUFFER,c,i.width,i.height)}}t.bindRenderbuffer(t.RENDERBUFFER,null)}function F(e,s,a){const l=!0===s.isWebGLCubeRenderTarget;if(i.bindFramebuffer(t.FRAMEBUFFER,e),!s.depthTexture||!s.depthTexture.isDepthTexture)throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");const h=n.get(s.depthTexture);if(h.__renderTarget=s,h.__webglTexture&&s.depthTexture.image.width===s.width&&s.depthTexture.image.height===s.height||(s.depthTexture.image.width=s.width,s.depthTexture.image.height=s.height,s.depthTexture.needsUpdate=!0),l){if(void 0===h.__webglInit&&(h.__webglInit=!0,s.depthTexture.addEventListener("dispose",S)),void 0===h.__webglTexture){h.__webglTexture=t.createTexture(),i.bindTexture(t.TEXTURE_CUBE_MAP,h.__webglTexture),R(t.TEXTURE_CUBE_MAP,s.depthTexture);const e=r.convert(s.depthTexture.format),n=r.convert(s.depthTexture.type);let a;s.depthTexture.format===wt?a=t.DEPTH_COMPONENT24:s.depthTexture.format===At&&(a=t.DEPTH24_STENCIL8);for(let i=0;i<6;i++)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+i,0,a,s.width,s.height,0,e,n,null)}}else E(s.depthTexture,0);const c=h.__webglTexture,d=z(s),u=l?t.TEXTURE_CUBE_MAP_POSITIVE_X+a:t.TEXTURE_2D,p=s.depthTexture.format===At?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(s.depthTexture.format===wt)G(s)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,p,u,c,0,d):t.framebufferTexture2D(t.FRAMEBUFFER,p,u,c,0);else{if(s.depthTexture.format!==At)throw new Error("Unknown depthTexture format");G(s)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,p,u,c,0,d):t.framebufferTexture2D(t.FRAMEBUFFER,p,u,c,0)}}function N(e){const s=n.get(e),r=!0===e.isWebGLCubeRenderTarget;if(s.__boundDepthTexture!==e.depthTexture){const t=e.depthTexture;if(s.__depthDisposeCallback&&s.__depthDisposeCallback(),t){const e=()=>{delete s.__boundDepthTexture,delete s.__depthDisposeCallback,t.removeEventListener("dispose",e)};t.addEventListener("dispose",e),s.__depthDisposeCallback=e}s.__boundDepthTexture=t}if(e.depthTexture&&!s.__autoAllocateDepthBuffer)if(r)for(let t=0;t<6;t++)F(s.__webglFramebuffer[t],e,t);else{const t=e.texture.mipmaps;t&&t.length>0?F(s.__webglFramebuffer[0],e,0):F(s.__webglFramebuffer,e,0)}else if(r){s.__webglDepthbuffer=[];for(let n=0;n<6;n++)if(i.bindFramebuffer(t.FRAMEBUFFER,s.__webglFramebuffer[n]),void 0===s.__webglDepthbuffer[n])s.__webglDepthbuffer[n]=t.createRenderbuffer(),O(s.__webglDepthbuffer[n],e,!1);else{const i=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,r=s.__webglDepthbuffer[n];t.bindRenderbuffer(t.RENDERBUFFER,r),t.framebufferRenderbuffer(t.FRAMEBUFFER,i,t.RENDERBUFFER,r)}}else{const n=e.texture.mipmaps;if(n&&n.length>0?i.bindFramebuffer(t.FRAMEBUFFER,s.__webglFramebuffer[0]):i.bindFramebuffer(t.FRAMEBUFFER,s.__webglFramebuffer),void 0===s.__webglDepthbuffer)s.__webglDepthbuffer=t.createRenderbuffer(),O(s.__webglDepthbuffer,e,!1);else{const i=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,n=s.__webglDepthbuffer;t.bindRenderbuffer(t.RENDERBUFFER,n),t.framebufferRenderbuffer(t.FRAMEBUFFER,i,t.RENDERBUFFER,n)}}i.bindFramebuffer(t.FRAMEBUFFER,null)}const U=[],k=[];function z(t){return Math.min(s.maxSamples,t.samples)}function G(t){const i=n.get(t);return t.samples>0&&!0===e.has("WEBGL_multisampled_render_to_texture")&&!1!==i.__useRenderToTexture}function H(t,e){const i=t.colorSpace,n=t.format,s=t.type;return!0===t.isCompressedTexture||!0===t.isVideoTexture||i!==Te&&i!==Ae&&(Ci.getTransfer(i)===De?n===Mt&&s===lt||ii("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):ni("WebGLTextures: Unsupported texture color space:",i)),e}function V(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement?(h.width=t.naturalWidth||t.width,h.height=t.naturalHeight||t.height):"undefined"!=typeof VideoFrame&&t instanceof VideoFrame?(h.width=t.displayWidth,h.height=t.displayHeight):(h.width=t.width,h.height=t.height),h}this.allocateTextureUnit=function(){const t=A;return t>=s.maxTextures&&ii("WebGLTextures: Trying to use "+t+" texture units while this GPU supports only "+s.maxTextures),A+=1,t},this.resetTextureUnits=function(){A=0},this.setTexture2D=E,this.setTexture2DArray=function(e,s){const r=n.get(e);!1===e.isRenderTargetTexture&&e.version>0&&r.__version!==e.version?L(r,e,s):(e.isExternalTexture&&(r.__webglTexture=e.sourceTexture?e.sourceTexture:null),i.bindTexture(t.TEXTURE_2D_ARRAY,r.__webglTexture,t.TEXTURE0+s))},this.setTexture3D=function(e,s){const r=n.get(e);!1===e.isRenderTargetTexture&&e.version>0&&r.__version!==e.version?L(r,e,s):i.bindTexture(t.TEXTURE_3D,r.__webglTexture,t.TEXTURE0+s)},this.setTextureCube=function(e,a){const o=n.get(e);!0!==e.isCubeDepthTexture&&e.version>0&&o.__version!==e.version?function(e,a,o){if(6!==a.image.length)return;const l=P(e,a),h=a.source;i.bindTexture(t.TEXTURE_CUBE_MAP,e.__webglTexture,t.TEXTURE0+o);const c=n.get(h);if(h.version!==c.__version||!0===l){i.activeTexture(t.TEXTURE0+o);const e=Ci.getPrimaries(Ci.workingColorSpace),n=a.colorSpace===Ae?null:Ci.getPrimaries(a.colorSpace),d=a.colorSpace===Ae||e===n?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,a.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,a.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,d);const u=a.isCompressedTexture||a.image[0].isCompressedTexture,p=a.image[0]&&a.image[0].isDataTexture,m=[];for(let t=0;t<6;t++)m[t]=u||p?p?a.image[t].image:a.image[t]:f(a.image[t],!0,s.maxCubemapSize),m[t]=H(a,m[t]);const y=m[0],x=r.convert(a.format,a.colorSpace),S=r.convert(a.type),M=_(a.internalFormat,x,S,a.colorSpace),w=!0!==a.isVideoTexture,A=void 0===c.__version||!0===l,E=h.dataReady;let T,C=b(a,y);if(R(t.TEXTURE_CUBE_MAP,a),u){w&&A&&i.texStorage2D(t.TEXTURE_CUBE_MAP,C,M,y.width,y.height);for(let e=0;e<6;e++){T=m[e].mipmaps;for(let n=0;n<T.length;n++){const s=T[n];a.format!==Mt?null!==x?w?E&&i.compressedTexSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n,0,0,s.width,s.height,x,s.data):i.compressedTexImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n,M,s.width,s.height,0,s.data):ii("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):w?E&&i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n,0,0,s.width,s.height,x,S,s.data):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n,M,s.width,s.height,0,x,S,s.data)}}}else{if(T=a.mipmaps,w&&A){T.length>0&&C++;const e=V(m[0]);i.texStorage2D(t.TEXTURE_CUBE_MAP,C,M,e.width,e.height)}for(let e=0;e<6;e++)if(p){w?E&&i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,m[e].width,m[e].height,x,S,m[e].data):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,M,m[e].width,m[e].height,0,x,S,m[e].data);for(let n=0;n<T.length;n++){const s=T[n].image[e].image;w?E&&i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n+1,0,0,s.width,s.height,x,S,s.data):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n+1,M,s.width,s.height,0,x,S,s.data)}}else{w?E&&i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,x,S,m[e]):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,M,x,S,m[e]);for(let n=0;n<T.length;n++){const s=T[n];w?E&&i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n+1,0,0,x,S,s.image[e]):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,n+1,M,x,S,s.image[e])}}}g(a)&&v(t.TEXTURE_CUBE_MAP),c.__version=h.version,a.onUpdate&&a.onUpdate(a)}e.__version=a.version}(o,e,a):i.bindTexture(t.TEXTURE_CUBE_MAP,o.__webglTexture,t.TEXTURE0+a)},this.rebindTextures=function(e,i,s){const r=n.get(e);void 0!==i&&B(r.__webglFramebuffer,e,e.texture,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,0),void 0!==s&&N(e)},this.setupRenderTarget=function(e){const s=e.texture,o=n.get(e),l=n.get(s);e.addEventListener("dispose",M);const h=e.textures,c=!0===e.isWebGLCubeRenderTarget,d=h.length>1;if(d||(void 0===l.__webglTexture&&(l.__webglTexture=t.createTexture()),l.__version=s.version,a.memory.textures++),c){o.__webglFramebuffer=[];for(let e=0;e<6;e++)if(s.mipmaps&&s.mipmaps.length>0){o.__webglFramebuffer[e]=[];for(let i=0;i<s.mipmaps.length;i++)o.__webglFramebuffer[e][i]=t.createFramebuffer()}else o.__webglFramebuffer[e]=t.createFramebuffer()}else{if(s.mipmaps&&s.mipmaps.length>0){o.__webglFramebuffer=[];for(let e=0;e<s.mipmaps.length;e++)o.__webglFramebuffer[e]=t.createFramebuffer()}else o.__webglFramebuffer=t.createFramebuffer();if(d)for(let e=0,i=h.length;e<i;e++){const i=n.get(h[e]);void 0===i.__webglTexture&&(i.__webglTexture=t.createTexture(),a.memory.textures++)}if(e.samples>0&&!1===G(e)){o.__webglMultisampledFramebuffer=t.createFramebuffer(),o.__webglColorRenderbuffer=[],i.bindFramebuffer(t.FRAMEBUFFER,o.__webglMultisampledFramebuffer);for(let i=0;i<h.length;i++){const n=h[i];o.__webglColorRenderbuffer[i]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,o.__webglColorRenderbuffer[i]);const s=r.convert(n.format,n.colorSpace),a=r.convert(n.type),l=_(n.internalFormat,s,a,n.colorSpace,!0===e.isXRRenderTarget),c=z(e);t.renderbufferStorageMultisample(t.RENDERBUFFER,c,l,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+i,t.RENDERBUFFER,o.__webglColorRenderbuffer[i])}t.bindRenderbuffer(t.RENDERBUFFER,null),e.depthBuffer&&(o.__webglDepthRenderbuffer=t.createRenderbuffer(),O(o.__webglDepthRenderbuffer,e,!0)),i.bindFramebuffer(t.FRAMEBUFFER,null)}}if(c){i.bindTexture(t.TEXTURE_CUBE_MAP,l.__webglTexture),R(t.TEXTURE_CUBE_MAP,s);for(let i=0;i<6;i++)if(s.mipmaps&&s.mipmaps.length>0)for(let n=0;n<s.mipmaps.length;n++)B(o.__webglFramebuffer[i][n],e,s,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+i,n);else B(o.__webglFramebuffer[i],e,s,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+i,0);g(s)&&v(t.TEXTURE_CUBE_MAP),i.unbindTexture()}else if(d){for(let s=0,r=h.length;s<r;s++){const r=h[s],a=n.get(r);let l=t.TEXTURE_2D;(e.isWebGL3DRenderTarget||e.isWebGLArrayRenderTarget)&&(l=e.isWebGL3DRenderTarget?t.TEXTURE_3D:t.TEXTURE_2D_ARRAY),i.bindTexture(l,a.__webglTexture),R(l,r),B(o.__webglFramebuffer,e,r,t.COLOR_ATTACHMENT0+s,l,0),g(r)&&v(l)}i.unbindTexture()}else{let n=t.TEXTURE_2D;if((e.isWebGL3DRenderTarget||e.isWebGLArrayRenderTarget)&&(n=e.isWebGL3DRenderTarget?t.TEXTURE_3D:t.TEXTURE_2D_ARRAY),i.bindTexture(n,l.__webglTexture),R(n,s),s.mipmaps&&s.mipmaps.length>0)for(let i=0;i<s.mipmaps.length;i++)B(o.__webglFramebuffer[i],e,s,t.COLOR_ATTACHMENT0,n,i);else B(o.__webglFramebuffer,e,s,t.COLOR_ATTACHMENT0,n,0);g(s)&&v(n),i.unbindTexture()}e.depthBuffer&&N(e)},this.updateRenderTargetMipmap=function(t){const e=t.textures;for(let s=0,r=e.length;s<r;s++){const r=e[s];if(g(r)){const e=y(t),s=n.get(r).__webglTexture;i.bindTexture(e,s),v(e),i.unbindTexture()}}},this.updateMultisampleRenderTarget=function(e){if(e.samples>0)if(!1===G(e)){const s=e.textures,r=e.width,a=e.height;let o=t.COLOR_BUFFER_BIT;const h=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,c=n.get(e),d=s.length>1;if(d)for(let e=0;e<s.length;e++)i.bindFramebuffer(t.FRAMEBUFFER,c.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,null),i.bindFramebuffer(t.FRAMEBUFFER,c.__webglFramebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,null,0);i.bindFramebuffer(t.READ_FRAMEBUFFER,c.__webglMultisampledFramebuffer);const u=e.texture.mipmaps;u&&u.length>0?i.bindFramebuffer(t.DRAW_FRAMEBUFFER,c.__webglFramebuffer[0]):i.bindFramebuffer(t.DRAW_FRAMEBUFFER,c.__webglFramebuffer);for(let i=0;i<s.length;i++){if(e.resolveDepthBuffer&&(e.depthBuffer&&(o|=t.DEPTH_BUFFER_BIT),e.stencilBuffer&&e.resolveStencilBuffer&&(o|=t.STENCIL_BUFFER_BIT)),d){t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,c.__webglColorRenderbuffer[i]);const e=n.get(s[i]).__webglTexture;t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e,0)}t.blitFramebuffer(0,0,r,a,0,0,r,a,o,t.NEAREST),!0===l&&(U.length=0,k.length=0,U.push(t.COLOR_ATTACHMENT0+i),e.depthBuffer&&!1===e.resolveDepthBuffer&&(U.push(h),k.push(h),t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,k)),t.invalidateFramebuffer(t.READ_FRAMEBUFFER,U))}if(i.bindFramebuffer(t.READ_FRAMEBUFFER,null),i.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),d)for(let e=0;e<s.length;e++){i.bindFramebuffer(t.FRAMEBUFFER,c.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,c.__webglColorRenderbuffer[e]);const r=n.get(s[e]).__webglTexture;i.bindFramebuffer(t.FRAMEBUFFER,c.__webglFramebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,r,0)}i.bindFramebuffer(t.DRAW_FRAMEBUFFER,c.__webglMultisampledFramebuffer)}else if(e.depthBuffer&&!1===e.resolveDepthBuffer&&l){const i=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,[i])}},this.setupDepthRenderbuffer=N,this.setupFrameBufferTexture=B,this.useMultisampledRTT=G,this.isReversedDepthBuffer=function(){return i.buffers.depth.getReversed()}}function Kp(t,e){return{convert:function(i,n=""){let s;const r=Ci.getTransfer(n);if(i===lt)return t.UNSIGNED_BYTE;if(i===gt)return t.UNSIGNED_SHORT_4_4_4_4;if(i===vt)return t.UNSIGNED_SHORT_5_5_5_1;if(i===_t)return t.UNSIGNED_INT_5_9_9_9_REV;if(i===xt)return t.UNSIGNED_INT_10F_11F_11F_REV;if(i===ht)return t.BYTE;if(i===ct)return t.SHORT;if(i===dt)return t.UNSIGNED_SHORT;if(i===ut)return t.INT;if(i===pt)return t.UNSIGNED_INT;if(i===mt)return t.FLOAT;if(i===ft)return t.HALF_FLOAT;if(i===bt)return t.ALPHA;if(i===St)return t.RGB;if(i===Mt)return t.RGBA;if(i===wt)return t.DEPTH_COMPONENT;if(i===At)return t.DEPTH_STENCIL;if(i===Et)return t.RED;if(i===Tt)return t.RED_INTEGER;if(i===Ct)return t.RG;if(i===Dt)return t.RG_INTEGER;if(i===Rt)return t.RGBA_INTEGER;if(i===Pt||i===It||i===Lt||i===Bt)if(r===De){if(s=e.get("WEBGL_compressed_texture_s3tc_srgb"),null===s)return null;if(i===Pt)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===It)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===Lt)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===Bt)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(s=e.get("WEBGL_compressed_texture_s3tc"),null===s)return null;if(i===Pt)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===It)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===Lt)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===Bt)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(i===Ot||i===Ft||i===Nt||i===Ut){if(s=e.get("WEBGL_compressed_texture_pvrtc"),null===s)return null;if(i===Ot)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(i===Ft)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(i===Nt)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(i===Ut)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(i===kt||i===zt||i===Gt||i===Ht||i===Vt||i===Wt||i===jt){if(s=e.get("WEBGL_compressed_texture_etc"),null===s)return null;if(i===kt||i===zt)return r===De?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(i===Gt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(i===Ht)return s.COMPRESSED_R11_EAC;if(i===Vt)return s.COMPRESSED_SIGNED_R11_EAC;if(i===Wt)return s.COMPRESSED_RG11_EAC;if(i===jt)return s.COMPRESSED_SIGNED_RG11_EAC}if(i===Xt||i===Yt||i===Zt||i===qt||i===Qt||i===Kt||i===Jt||i===$t||i===te||i===ee||i===ie||i===ne||i===se||i===re){if(s=e.get("WEBGL_compressed_texture_astc"),null===s)return null;if(i===Xt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(i===Yt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(i===Zt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(i===qt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(i===Qt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(i===Kt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(i===Jt)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(i===$t)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(i===te)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(i===ee)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(i===ie)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(i===ne)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(i===se)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(i===re)return r===De?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}if(i===ae||i===oe||i===le){if(s=e.get("EXT_texture_compression_bptc"),null===s)return null;if(i===ae)return r===De?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(i===oe)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(i===le)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}if(i===he||i===ce||i===de||i===ue){if(s=e.get("EXT_texture_compression_rgtc"),null===s)return null;if(i===he)return s.COMPRESSED_RED_RGTC1_EXT;if(i===ce)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(i===de)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(i===ue)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return i===yt?t.UNSIGNED_INT_24_8:void 0!==t[i]?t[i]:null}}}class Jp{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(t,e){if(null===this.texture){const i=new qa(t.texture);t.depthNear===e.depthNear&&t.depthFar===e.depthFar||(this.depthNear=t.depthNear,this.depthFar=t.depthFar),this.texture=i}}getMesh(t){if(null!==this.texture&&null===this.mesh){const e=t.cameras[0].viewport,i=new Dl({vertexShader:"\nvoid main() {\n\n\tgl_Position = vec4( position, 1.0 );\n\n}",fragmentShader:"\nuniform sampler2DArray depthColor;\nuniform float depthWidth;\nuniform float depthHeight;\n\nvoid main() {\n\n\tvec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );\n\n\tif ( coord.x >= 1.0 ) {\n\n\t\tgl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;\n\n\t} else {\n\n\t\tgl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;\n\n\t}\n\n}",uniforms:{depthColor:{value:this.texture},depthWidth:{value:e.z},depthHeight:{value:e.w}}});this.mesh=new xr(new pl(20,20),i)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class $p extends ai{constructor(t,e){super();const i=this;let n=null,s=1,r=null,a="local-floor",o=1,l=null,h=null,c=null,d=null,u=null,p=null;const m="undefined"!=typeof XRWebGLBinding,f=new Jp,g={},v=e.getContextAttributes();let y=null,_=null;const x=[],b=[],S=new yi;let M=null;const w=new Ph;w.viewport=new ki;const A=new Ph;A.viewport=new ki;const E=[w,A],T=new sc;let C=null,D=null;function R(t){const e=b.indexOf(t.inputSource);if(-1===e)return;const i=x[e];void 0!==i&&(i.update(t.inputSource,t.frame,l||r),i.dispatchEvent({type:t.type,data:t.inputSource}))}function P(){n.removeEventListener("select",R),n.removeEventListener("selectstart",R),n.removeEventListener("selectend",R),n.removeEventListener("squeeze",R),n.removeEventListener("squeezestart",R),n.removeEventListener("squeezeend",R),n.removeEventListener("end",P),n.removeEventListener("inputsourceschange",I);for(let t=0;t<x.length;t++){const e=b[t];null!==e&&(b[t]=null,x[t].disconnect(e))}C=null,D=null,f.reset();for(const t in g)delete g[t];t.setRenderTarget(y),u=null,d=null,c=null,n=null,_=null,N.stop(),i.isPresenting=!1,t.setPixelRatio(M),t.setSize(S.width,S.height,!1),i.dispatchEvent({type:"sessionend"})}function I(t){for(let e=0;e<t.removed.length;e++){const i=t.removed[e],n=b.indexOf(i);n>=0&&(b[n]=null,x[n].disconnect(i))}for(let e=0;e<t.added.length;e++){const i=t.added[e];let n=b.indexOf(i);if(-1===n){for(let t=0;t<x.length;t++){if(t>=b.length){b.push(i),n=t;break}if(null===b[t]){b[t]=i,n=t;break}}if(-1===n)break}const s=x[n];s&&s.connect(i)}}this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(t){let e=x[t];return void 0===e&&(e=new bn,x[t]=e),e.getTargetRaySpace()},this.getControllerGrip=function(t){let e=x[t];return void 0===e&&(e=new bn,x[t]=e),e.getGripSpace()},this.getHand=function(t){let e=x[t];return void 0===e&&(e=new bn,x[t]=e),e.getHandSpace()},this.setFramebufferScaleFactor=function(t){s=t,!0===i.isPresenting&&ii("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(t){a=t,!0===i.isPresenting&&ii("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return l||r},this.setReferenceSpace=function(t){l=t},this.getBaseLayer=function(){return null!==d?d:u},this.getBinding=function(){return null===c&&m&&(c=new XRWebGLBinding(n,e)),c},this.getFrame=function(){return p},this.getSession=function(){return n},this.setSession=async function(h){if(n=h,null!==n){y=t.getRenderTarget(),n.addEventListener("select",R),n.addEventListener("selectstart",R),n.addEventListener("selectend",R),n.addEventListener("squeeze",R),n.addEventListener("squeezestart",R),n.addEventListener("squeezeend",R),n.addEventListener("end",P),n.addEventListener("inputsourceschange",I),!0!==v.xrCompatible&&await e.makeXRCompatible(),M=t.getPixelRatio(),t.getSize(S);if(m&&"createProjectionLayer"in XRWebGLBinding.prototype){let i=null,r=null,a=null;v.depth&&(a=v.stencil?e.DEPTH24_STENCIL8:e.DEPTH_COMPONENT24,i=v.stencil?At:wt,r=v.stencil?yt:pt);const o={colorFormat:e.RGBA8,depthFormat:a,scaleFactor:s};c=this.getBinding(),d=c.createProjectionLayer(o),n.updateRenderState({layers:[d]}),t.setPixelRatio(1),t.setSize(d.textureWidth,d.textureHeight,!1),_=new Gi(d.textureWidth,d.textureHeight,{format:Mt,type:lt,depthTexture:new Ya(d.textureWidth,d.textureHeight,r,void 0,void 0,void 0,void 0,void 0,void 0,i),stencilBuffer:v.stencil,colorSpace:t.outputColorSpace,samples:v.antialias?4:0,resolveDepthBuffer:!1===d.ignoreDepthValues,resolveStencilBuffer:!1===d.ignoreDepthValues})}else{const i={antialias:v.antialias,alpha:!0,depth:v.depth,stencil:v.stencil,framebufferScaleFactor:s};u=new XRWebGLLayer(n,e,i),n.updateRenderState({baseLayer:u}),t.setPixelRatio(1),t.setSize(u.framebufferWidth,u.framebufferHeight,!1),_=new Gi(u.framebufferWidth,u.framebufferHeight,{format:Mt,type:lt,colorSpace:t.outputColorSpace,stencilBuffer:v.stencil,resolveDepthBuffer:!1===u.ignoreDepthValues,resolveStencilBuffer:!1===u.ignoreDepthValues})}_.isXRRenderTarget=!0,this.setFoveation(o),l=null,r=await n.requestReferenceSpace(a),N.setContext(n),N.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(null!==n)return n.environmentBlendMode},this.getDepthTexture=function(){return f.getDepthTexture()};const L=new xi,B=new xi;function O(t,e){null===e?t.matrixWorld.copy(t.matrix):t.matrixWorld.multiplyMatrices(e.matrixWorld,t.matrix),t.matrixWorldInverse.copy(t.matrixWorld).invert()}this.updateCamera=function(t){if(null===n)return;let e=t.near,i=t.far;null!==f.texture&&(f.depthNear>0&&(e=f.depthNear),f.depthFar>0&&(i=f.depthFar)),T.near=A.near=w.near=e,T.far=A.far=w.far=i,C===T.near&&D===T.far||(n.updateRenderState({depthNear:T.near,depthFar:T.far}),C=T.near,D=T.far),T.layers.mask=6|t.layers.mask,w.layers.mask=-5&T.layers.mask,A.layers.mask=-3&T.layers.mask;const s=t.parent,r=T.cameras;O(T,s);for(let t=0;t<r.length;t++)O(r[t],s);2===r.length?function(t,e,i){L.setFromMatrixPosition(e.matrixWorld),B.setFromMatrixPosition(i.matrixWorld);const n=L.distanceTo(B),s=e.projectionMatrix.elements,r=i.projectionMatrix.elements,a=s[14]/(s[10]-1),o=s[14]/(s[10]+1),l=(s[9]+1)/s[5],h=(s[9]-1)/s[5],c=(s[8]-1)/s[0],d=(r[8]+1)/r[0],u=a*c,p=a*d,m=n/(-c+d),f=m*-c;if(e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.translateX(f),t.translateZ(m),t.matrixWorld.compose(t.position,t.quaternion,t.scale),t.matrixWorldInverse.copy(t.matrixWorld).invert(),-1===s[10])t.projectionMatrix.copy(e.projectionMatrix),t.projectionMatrixInverse.copy(e.projectionMatrixInverse);else{const e=a+m,i=o+m,s=u-f,r=p+(n-f),c=l*o/i*e,d=h*o/i*e;t.projectionMatrix.makePerspective(s,r,c,d,e,i),t.projectionMatrixInverse.copy(t.projectionMatrix).invert()}}(T,w,A):T.projectionMatrix.copy(w.projectionMatrix),function(t,e,i){null===i?t.matrix.copy(e.matrixWorld):(t.matrix.copy(i.matrixWorld),t.matrix.invert(),t.matrix.multiply(e.matrixWorld));t.matrix.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld(!0),t.projectionMatrix.copy(e.projectionMatrix),t.projectionMatrixInverse.copy(e.projectionMatrixInverse),t.isPerspectiveCamera&&(t.fov=2*ci*Math.atan(1/t.projectionMatrix.elements[5]),t.zoom=1)}(t,T,s)},this.getCamera=function(){return T},this.getFoveation=function(){if(null!==d||null!==u)return o},this.setFoveation=function(t){o=t,null!==d&&(d.fixedFoveation=t),null!==u&&void 0!==u.fixedFoveation&&(u.fixedFoveation=t)},this.hasDepthSensing=function(){return null!==f.texture},this.getDepthSensingMesh=function(){return f.getMesh(T)},this.getCameraTexture=function(t){return g[t]};let F=null;const N=new md;N.setAnimationLoop(function(e,s){if(h=s.getViewerPose(l||r),p=s,null!==h){const e=h.views;null!==u&&(t.setRenderTargetFramebuffer(_,u.framebuffer),t.setRenderTarget(_));let s=!1;e.length!==T.cameras.length&&(T.cameras.length=0,s=!0);for(let i=0;i<e.length;i++){const n=e[i];let r=null;if(null!==u)r=u.getViewport(n);else{const e=c.getViewSubImage(d,n);r=e.viewport,0===i&&(t.setRenderTargetTextures(_,e.colorTexture,e.depthStencilTexture),t.setRenderTarget(_))}let a=E[i];void 0===a&&(a=new Ph,a.layers.enable(i),a.viewport=new ki,E[i]=a),a.matrix.fromArray(n.transform.matrix),a.matrix.decompose(a.position,a.quaternion,a.scale),a.projectionMatrix.fromArray(n.projectionMatrix),a.projectionMatrixInverse.copy(a.projectionMatrix).invert(),a.viewport.set(r.x,r.y,r.width,r.height),0===i&&(T.matrix.copy(a.matrix),T.matrix.decompose(T.position,T.quaternion,T.scale)),!0===s&&T.cameras.push(a)}const r=n.enabledFeatures;if(r&&r.includes("depth-sensing")&&"gpu-optimized"==n.depthUsage&&m){c=i.getBinding();const t=c.getDepthInformation(e[0]);t&&t.isValid&&t.texture&&f.init(t,n.renderState)}if(r&&r.includes("camera-access")&&m){t.state.unbindTexture(),c=i.getBinding();for(let t=0;t<e.length;t++){const i=e[t].camera;if(i){let t=g[i];t||(t=new qa,g[i]=t);const e=c.getCameraImage(i);t.sourceTexture=e}}}}for(let t=0;t<x.length;t++){const e=b[t],i=x[t];null!==e&&void 0!==i&&i.update(e,s,l||r)}F&&F(e,s),s.detectedPlanes&&i.dispatchEvent({type:"planesdetected",data:s}),p=null}),this.setAnimationLoop=function(t){F=t},this.dispose=function(){}}}const tm=new tn,em=new Wi;function im(t,e){function i(t,e){!0===t.matrixAutoUpdate&&t.updateMatrix(),e.value.copy(t.matrix)}function n(t,n){t.opacity.value=n.opacity,n.color&&t.diffuse.value.copy(n.color),n.emissive&&t.emissive.value.copy(n.emissive).multiplyScalar(n.emissiveIntensity),n.map&&(t.map.value=n.map,i(n.map,t.mapTransform)),n.alphaMap&&(t.alphaMap.value=n.alphaMap,i(n.alphaMap,t.alphaMapTransform)),n.bumpMap&&(t.bumpMap.value=n.bumpMap,i(n.bumpMap,t.bumpMapTransform),t.bumpScale.value=n.bumpScale,1===n.side&&(t.bumpScale.value*=-1)),n.normalMap&&(t.normalMap.value=n.normalMap,i(n.normalMap,t.normalMapTransform),t.normalScale.value.copy(n.normalScale),1===n.side&&t.normalScale.value.negate()),n.displacementMap&&(t.displacementMap.value=n.displacementMap,i(n.displacementMap,t.displacementMapTransform),t.displacementScale.value=n.displacementScale,t.displacementBias.value=n.displacementBias),n.emissiveMap&&(t.emissiveMap.value=n.emissiveMap,i(n.emissiveMap,t.emissiveMapTransform)),n.specularMap&&(t.specularMap.value=n.specularMap,i(n.specularMap,t.specularMapTransform)),n.alphaTest>0&&(t.alphaTest.value=n.alphaTest);const s=e.get(n),r=s.envMap,a=s.envMapRotation;r&&(t.envMap.value=r,tm.copy(a),tm.x*=-1,tm.y*=-1,tm.z*=-1,r.isCubeTexture&&!1===r.isRenderTargetTexture&&(tm.y*=-1,tm.z*=-1),t.envMapRotation.value.setFromMatrix4(em.makeRotationFromEuler(tm)),t.flipEnvMap.value=r.isCubeTexture&&!1===r.isRenderTargetTexture?-1:1,t.reflectivity.value=n.reflectivity,t.ior.value=n.ior,t.refractionRatio.value=n.refractionRatio),n.lightMap&&(t.lightMap.value=n.lightMap,t.lightMapIntensity.value=n.lightMapIntensity,i(n.lightMap,t.lightMapTransform)),n.aoMap&&(t.aoMap.value=n.aoMap,t.aoMapIntensity.value=n.aoMapIntensity,i(n.aoMap,t.aoMapTransform))}return{refreshFogUniforms:function(e,i){i.color.getRGB(e.fogColor.value,Tl(t)),i.isFog?(e.fogNear.value=i.near,e.fogFar.value=i.far):i.isFogExp2&&(e.fogDensity.value=i.density)},refreshMaterialUniforms:function(t,s,r,a,o){s.isMeshBasicMaterial?n(t,s):s.isMeshLambertMaterial?(n(t,s),s.envMap&&(t.envMapIntensity.value=s.envMapIntensity)):s.isMeshToonMaterial?(n(t,s),function(t,e){e.gradientMap&&(t.gradientMap.value=e.gradientMap)}(t,s)):s.isMeshPhongMaterial?(n(t,s),function(t,e){t.specular.value.copy(e.specular),t.shininess.value=Math.max(e.shininess,1e-4)}(t,s),s.envMap&&(t.envMapIntensity.value=s.envMapIntensity)):s.isMeshStandardMaterial?(n(t,s),function(t,e){t.metalness.value=e.metalness,e.metalnessMap&&(t.metalnessMap.value=e.metalnessMap,i(e.metalnessMap,t.metalnessMapTransform));t.roughness.value=e.roughness,e.roughnessMap&&(t.roughnessMap.value=e.roughnessMap,i(e.roughnessMap,t.roughnessMapTransform));e.envMap&&(t.envMapIntensity.value=e.envMapIntensity)}(t,s),s.isMeshPhysicalMaterial&&function(t,e,n){t.ior.value=e.ior,e.sheen>0&&(t.sheenColor.value.copy(e.sheenColor).multiplyScalar(e.sheen),t.sheenRoughness.value=e.sheenRoughness,e.sheenColorMap&&(t.sheenColorMap.value=e.sheenColorMap,i(e.sheenColorMap,t.sheenColorMapTransform)),e.sheenRoughnessMap&&(t.sheenRoughnessMap.value=e.sheenRoughnessMap,i(e.sheenRoughnessMap,t.sheenRoughnessMapTransform)));e.clearcoat>0&&(t.clearcoat.value=e.clearcoat,t.clearcoatRoughness.value=e.clearcoatRoughness,e.clearcoatMap&&(t.clearcoatMap.value=e.clearcoatMap,i(e.clearcoatMap,t.clearcoatMapTransform)),e.clearcoatRoughnessMap&&(t.clearcoatRoughnessMap.value=e.clearcoatRoughnessMap,i(e.clearcoatRoughnessMap,t.clearcoatRoughnessMapTransform)),e.clearcoatNormalMap&&(t.clearcoatNormalMap.value=e.clearcoatNormalMap,i(e.clearcoatNormalMap,t.clearcoatNormalMapTransform),t.clearcoatNormalScale.value.copy(e.clearcoatNormalScale),1===e.side&&t.clearcoatNormalScale.value.negate()));e.dispersion>0&&(t.dispersion.value=e.dispersion);e.iridescence>0&&(t.iridescence.value=e.iridescence,t.iridescenceIOR.value=e.iridescenceIOR,t.iridescenceThicknessMinimum.value=e.iridescenceThicknessRange[0],t.iridescenceThicknessMaximum.value=e.iridescenceThicknessRange[1],e.iridescenceMap&&(t.iridescenceMap.value=e.iridescenceMap,i(e.iridescenceMap,t.iridescenceMapTransform)),e.iridescenceThicknessMap&&(t.iridescenceThicknessMap.value=e.iridescenceThicknessMap,i(e.iridescenceThicknessMap,t.iridescenceThicknessMapTransform)));e.transmission>0&&(t.transmission.value=e.transmission,t.transmissionSamplerMap.value=n.texture,t.transmissionSamplerSize.value.set(n.width,n.height),e.transmissionMap&&(t.transmissionMap.value=e.transmissionMap,i(e.transmissionMap,t.transmissionMapTransform)),t.thickness.value=e.thickness,e.thicknessMap&&(t.thicknessMap.value=e.thicknessMap,i(e.thicknessMap,t.thicknessMapTransform)),t.attenuationDistance.value=e.attenuationDistance,t.attenuationColor.value.copy(e.attenuationColor));e.anisotropy>0&&(t.anisotropyVector.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation)),e.anisotropyMap&&(t.anisotropyMap.value=e.anisotropyMap,i(e.anisotropyMap,t.anisotropyMapTransform)));t.specularIntensity.value=e.specularIntensity,t.specularColor.value.copy(e.specularColor),e.specularColorMap&&(t.specularColorMap.value=e.specularColorMap,i(e.specularColorMap,t.specularColorMapTransform));e.specularIntensityMap&&(t.specularIntensityMap.value=e.specularIntensityMap,i(e.specularIntensityMap,t.specularIntensityMapTransform))}(t,s,o)):s.isMeshMatcapMaterial?(n(t,s),function(t,e){e.matcap&&(t.matcap.value=e.matcap)}(t,s)):s.isMeshDepthMaterial?n(t,s):s.isMeshDistanceMaterial?(n(t,s),function(t,i){const n=e.get(i).light;t.referencePosition.value.setFromMatrixPosition(n.matrixWorld),t.nearDistance.value=n.shadow.camera.near,t.farDistance.value=n.shadow.camera.far}(t,s)):s.isMeshNormalMaterial?n(t,s):s.isLineBasicMaterial?(function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,e.map&&(t.map.value=e.map,i(e.map,t.mapTransform))}(t,s),s.isLineDashedMaterial&&function(t,e){t.dashSize.value=e.dashSize,t.totalSize.value=e.dashSize+e.gapSize,t.scale.value=e.scale}(t,s)):s.isPointsMaterial?function(t,e,n,s){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.size.value=e.size*n,t.scale.value=.5*s,e.map&&(t.map.value=e.map,i(e.map,t.uvTransform));e.alphaMap&&(t.alphaMap.value=e.alphaMap,i(e.alphaMap,t.alphaMapTransform));e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,s,r,a):s.isSpriteMaterial?function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.rotation.value=e.rotation,e.map&&(t.map.value=e.map,i(e.map,t.mapTransform));e.alphaMap&&(t.alphaMap.value=e.alphaMap,i(e.alphaMap,t.alphaMapTransform));e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,s):s.isShadowMaterial?(t.color.value.copy(s.color),t.opacity.value=s.opacity):s.isShaderMaterial&&(s.uniformsNeedUpdate=!1)}}}function nm(t,e,i,n){let s={},r={},a=[];const o=t.getParameter(t.MAX_UNIFORM_BUFFER_BINDINGS);function l(t,e,i,n){const s=t.value,r=e+"_"+i;if(void 0===n[r])return n[r]="number"==typeof s||"boolean"==typeof s?s:s.clone(),!0;{const t=n[r];if("number"==typeof s||"boolean"==typeof s){if(t!==s)return n[r]=s,!0}else if(!1===t.equals(s))return t.copy(s),!0}return!1}function h(t){const e={boundary:0,storage:0};return"number"==typeof t||"boolean"==typeof t?(e.boundary=4,e.storage=4):t.isVector2?(e.boundary=8,e.storage=8):t.isVector3||t.isColor?(e.boundary=16,e.storage=12):t.isVector4?(e.boundary=16,e.storage=16):t.isMatrix3?(e.boundary=48,e.storage=48):t.isMatrix4?(e.boundary=64,e.storage=64):t.isTexture?ii("WebGLRenderer: Texture samplers can not be part of an uniforms group."):ii("WebGLRenderer: Unsupported uniform value type.",t),e}function c(e){const i=e.target;i.removeEventListener("dispose",c);const n=a.indexOf(i.__bindingPointIndex);a.splice(n,1),t.deleteBuffer(s[i.id]),delete s[i.id],delete r[i.id]}return{bind:function(t,e){const i=e.program;n.uniformBlockBinding(t,i)},update:function(i,d){let u=s[i.id];void 0===u&&(!function(t){const e=t.uniforms;let i=0;const n=16;for(let t=0,s=e.length;t<s;t++){const s=Array.isArray(e[t])?e[t]:[e[t]];for(let t=0,e=s.length;t<e;t++){const e=s[t],r=Array.isArray(e.value)?e.value:[e.value];for(let t=0,s=r.length;t<s;t++){const s=h(r[t]),a=i%n,o=a%s.boundary,l=a+o;i+=o,0!==l&&n-l<s.storage&&(i+=n-l),e.__data=new Float32Array(s.storage/Float32Array.BYTES_PER_ELEMENT),e.__offset=i,i+=s.storage}}}const s=i%n;s>0&&(i+=n-s);t.__size=i,t.__cache={}}(i),u=function(e){const i=function(){for(let t=0;t<o;t++)if(-1===a.indexOf(t))return a.push(t),t;return ni("WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}();e.__bindingPointIndex=i;const n=t.createBuffer(),s=e.__size,r=e.usage;return t.bindBuffer(t.UNIFORM_BUFFER,n),t.bufferData(t.UNIFORM_BUFFER,s,r),t.bindBuffer(t.UNIFORM_BUFFER,null),t.bindBufferBase(t.UNIFORM_BUFFER,i,n),n}(i),s[i.id]=u,i.addEventListener("dispose",c));const p=d.program;n.updateUBOMapping(i,p);const m=e.render.frame;r[i.id]!==m&&(!function(e){const i=s[e.id],n=e.uniforms,r=e.__cache;t.bindBuffer(t.UNIFORM_BUFFER,i);for(let e=0,i=n.length;e<i;e++){const i=Array.isArray(n[e])?n[e]:[n[e]];for(let n=0,s=i.length;n<s;n++){const s=i[n];if(!0===l(s,e,n,r)){const e=s.__offset,i=Array.isArray(s.value)?s.value:[s.value];let n=0;for(let r=0;r<i.length;r++){const a=i[r],o=h(a);"number"==typeof a||"boolean"==typeof a?(s.__data[0]=a,t.bufferSubData(t.UNIFORM_BUFFER,e+n,s.__data)):a.isMatrix3?(s.__data[0]=a.elements[0],s.__data[1]=a.elements[1],s.__data[2]=a.elements[2],s.__data[3]=0,s.__data[4]=a.elements[3],s.__data[5]=a.elements[4],s.__data[6]=a.elements[5],s.__data[7]=0,s.__data[8]=a.elements[6],s.__data[9]=a.elements[7],s.__data[10]=a.elements[8],s.__data[11]=0):(a.toArray(s.__data,n),n+=o.storage/Float32Array.BYTES_PER_ELEMENT)}t.bufferSubData(t.UNIFORM_BUFFER,e,s.__data)}}}t.bindBuffer(t.UNIFORM_BUFFER,null)}(i),r[i.id]=m)},dispose:function(){for(const e in s)t.deleteBuffer(s[e]);a=[],s={},r={}}}}const sm=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]);let rm=null;class am{constructor(t={}){const{canvas:i=Ke(),context:n=null,depth:s=!0,stencil:r=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:h=!1,powerPreference:c="default",failIfMajorPerformanceCaveat:d=!1,reversedDepthBuffer:u=!1,outputBufferType:p=lt}=t;let m;if(this.isWebGLRenderer=!0,null!==n){if("undefined"!=typeof WebGLRenderingContext&&n instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");m=n.getContextAttributes().alpha}else m=a;const f=p,g=new Set([Rt,Dt,Tt]),v=new Set([lt,pt,dt,yt,gt,vt]),y=new Uint32Array(4),_=new Int32Array(4);let x=null,b=null;const S=[],M=[];let w=null;this.domElement=i,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=0,this.toneMappingExposure=1,this.transmissionResolutionScale=1;const A=this;let E=!1;this._outputColorSpace=Ee;let T=0,C=0,D=null,R=-1,P=null;const I=new ki,L=new ki;let B=null;const O=new En(0);let F=0,N=i.width,U=i.height,k=1,z=null,G=null;const H=new ki(0,0,N,U),V=new ki(0,0,N,U);let W=!1;const j=new $r;let X=!1,Y=!1;const Z=new Wi,q=new xi,Q=new ki,K={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let J=!1;function $(){return null===D?k:1}let et,it,nt,st,at,ht,ct,ut,mt,_t,xt,bt,St,Mt,wt,At,Et,Pt,It,Lt,Bt,Ot,Ft,Nt=n;function Ut(t,e){return i.getContext(t,e)}try{const t={alpha:!0,depth:s,stencil:r,antialias:o,premultipliedAlpha:l,preserveDrawingBuffer:h,powerPreference:c,failIfMajorPerformanceCaveat:d};if("setAttribute"in i&&i.setAttribute("data-engine",`three.js r${e}`),i.addEventListener("webglcontextlost",Gt,!1),i.addEventListener("webglcontextrestored",Ht,!1),i.addEventListener("webglcontextcreationerror",Vt,!1),null===Nt){const e="webgl2";if(Nt=Ut(e,t),null===Nt)throw Ut(e)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}}catch(t){throw ni("WebGLRenderer: "+t.message),t}function kt(){et=new Wd(Nt),et.init(),Bt=new Kp(Nt,et),it=new Ad(Nt,et,t,Bt),nt=new qp(Nt,et),it.reversedDepthBuffer&&u&&nt.buffers.depth.setReversed(!0),st=new Yd(Nt),at=new Ip,ht=new Qp(Nt,et,nt,at,it,Bt,st),ct=new Vd(A),ut=new fd(Nt),Ot=new Md(Nt,ut),mt=new jd(Nt,ut,st,Ot),_t=new qd(Nt,mt,ut,Ot,st),Pt=new Zd(Nt,it,ht),wt=new Ed(at),xt=new Pp(A,ct,et,it,Ot,wt),bt=new im(A,at),St=new Fp,Mt=new Hp(et),Et=new Sd(A,ct,nt,_t,m,l),At=new Zp(A,_t,it),Ft=new nm(Nt,st,it,nt),It=new wd(Nt,et,st),Lt=new Xd(Nt,et,st),st.programs=xt.programs,A.capabilities=it,A.extensions=et,A.properties=at,A.renderLists=St,A.shadowMap=At,A.state=nt,A.info=st}kt(),f!==lt&&(w=new Kd(f,i.width,i.height,s,r));const zt=new $p(A,Nt);function Gt(t){t.preventDefault(),ti("WebGLRenderer: Context Lost."),E=!0}function Ht(){ti("WebGLRenderer: Context Restored."),E=!1;const t=st.autoReset,e=At.enabled,i=At.autoUpdate,n=At.needsUpdate,s=At.type;kt(),st.autoReset=t,At.enabled=e,At.autoUpdate=i,At.needsUpdate=n,At.type=s}function Vt(t){ni("WebGLRenderer: A WebGL context could not be created. Reason: ",t.statusMessage)}function Wt(t){const e=t.target;e.removeEventListener("dispose",Wt),function(t){(function(t){const e=at.get(t).programs;void 0!==e&&(e.forEach(function(t){xt.releaseProgram(t)}),t.isShaderMaterial&&xt.releaseShaderCache(t))})(t),at.remove(t)}(e)}function jt(t,e,i){!0===t.transparent&&2===t.side&&!1===t.forceSinglePass?(t.side=1,t.needsUpdate=!0,ee(t,e,i),t.side=0,t.needsUpdate=!0,ee(t,e,i),t.side=2):ee(t,e,i)}this.xr=zt,this.getContext=function(){return Nt},this.getContextAttributes=function(){return Nt.getContextAttributes()},this.forceContextLoss=function(){const t=et.get("WEBGL_lose_context");t&&t.loseContext()},this.forceContextRestore=function(){const t=et.get("WEBGL_lose_context");t&&t.restoreContext()},this.getPixelRatio=function(){return k},this.setPixelRatio=function(t){void 0!==t&&(k=t,this.setSize(N,U,!1))},this.getSize=function(t){return t.set(N,U)},this.setSize=function(t,e,n=!0){zt.isPresenting?ii("WebGLRenderer: Can't change size while VR device is presenting."):(N=t,U=e,i.width=Math.floor(t*k),i.height=Math.floor(e*k),!0===n&&(i.style.width=t+"px",i.style.height=e+"px"),null!==w&&w.setSize(i.width,i.height),this.setViewport(0,0,t,e))},this.getDrawingBufferSize=function(t){return t.set(N*k,U*k).floor()},this.setDrawingBufferSize=function(t,e,n){N=t,U=e,k=n,i.width=Math.floor(t*n),i.height=Math.floor(e*n),this.setViewport(0,0,t,e)},this.setEffects=function(t){if(f!==lt){if(t)for(let e=0;e<t.length;e++)if(!0===t[e].isOutputPass){console.warn("THREE.WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.");break}w.setEffects(t||[])}else console.error("THREE.WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.")},this.getCurrentViewport=function(t){return t.copy(I)},this.getViewport=function(t){return t.copy(H)},this.setViewport=function(t,e,i,n){t.isVector4?H.set(t.x,t.y,t.z,t.w):H.set(t,e,i,n),nt.viewport(I.copy(H).multiplyScalar(k).round())},this.getScissor=function(t){return t.copy(V)},this.setScissor=function(t,e,i,n){t.isVector4?V.set(t.x,t.y,t.z,t.w):V.set(t,e,i,n),nt.scissor(L.copy(V).multiplyScalar(k).round())},this.getScissorTest=function(){return W},this.setScissorTest=function(t){nt.setScissorTest(W=t)},this.setOpaqueSort=function(t){z=t},this.setTransparentSort=function(t){G=t},this.getClearColor=function(t){return t.copy(Et.getClearColor())},this.setClearColor=function(){Et.setClearColor(...arguments)},this.getClearAlpha=function(){return Et.getClearAlpha()},this.setClearAlpha=function(){Et.setClearAlpha(...arguments)},this.clear=function(t=!0,e=!0,i=!0){let n=0;if(t){let t=!1;if(null!==D){const e=D.texture.format;t=g.has(e)}if(t){const t=D.texture.type,e=v.has(t),i=Et.getClearColor(),n=Et.getClearAlpha(),s=i.r,r=i.g,a=i.b;e?(y[0]=s,y[1]=r,y[2]=a,y[3]=n,Nt.clearBufferuiv(Nt.COLOR,0,y)):(_[0]=s,_[1]=r,_[2]=a,_[3]=n,Nt.clearBufferiv(Nt.COLOR,0,_))}else n|=Nt.COLOR_BUFFER_BIT}e&&(n|=Nt.DEPTH_BUFFER_BIT),i&&(n|=Nt.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),0!==n&&Nt.clear(n)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.dispose=function(){i.removeEventListener("webglcontextlost",Gt,!1),i.removeEventListener("webglcontextrestored",Ht,!1),i.removeEventListener("webglcontextcreationerror",Vt,!1),Et.dispose(),St.dispose(),Mt.dispose(),at.dispose(),ct.dispose(),_t.dispose(),Ot.dispose(),Ft.dispose(),xt.dispose(),zt.dispose(),zt.removeEventListener("sessionstart",Yt),zt.removeEventListener("sessionend",Zt),qt.stop()},this.renderBufferDirect=function(t,e,i,n,s,r){null===e&&(e=K);const a=s.isMesh&&s.matrixWorld.determinant()<0,o=function(t,e,i,n,s){!0!==e.isScene&&(e=K);ht.resetTextureUnits();const r=e.fog,a=n.isMeshStandardMaterial||n.isMeshLambertMaterial||n.isMeshPhongMaterial?e.environment:null,o=null===D?A.outputColorSpace:!0===D.isXRRenderTarget?D.texture.colorSpace:Te,l=n.isMeshStandardMaterial||n.isMeshLambertMaterial&&!n.envMap||n.isMeshPhongMaterial&&!n.envMap,h=ct.get(n.envMap||a,l),c=!0===n.vertexColors&&!!i.attributes.color&&4===i.attributes.color.itemSize,d=!!i.attributes.tangent&&(!!n.normalMap||n.anisotropy>0),u=!!i.morphAttributes.position,p=!!i.morphAttributes.normal,m=!!i.morphAttributes.color;let f=0;n.toneMapped&&(null!==D&&!0!==D.isXRRenderTarget||(f=A.toneMapping));const g=i.morphAttributes.position||i.morphAttributes.normal||i.morphAttributes.color,v=void 0!==g?g.length:0,y=at.get(n),_=b.state.lights;if(!0===X&&(!0===Y||t!==P)){const e=t===P&&n.id===R;wt.setState(n,t,e)}let x=!1;n.version===y.__version?y.needsLights&&y.lightsStateVersion!==_.state.version||y.outputColorSpace!==o||s.isBatchedMesh&&!1===y.batching?x=!0:s.isBatchedMesh||!0!==y.batching?s.isBatchedMesh&&!0===y.batchingColor&&null===s.colorTexture||s.isBatchedMesh&&!1===y.batchingColor&&null!==s.colorTexture||s.isInstancedMesh&&!1===y.instancing?x=!0:s.isInstancedMesh||!0!==y.instancing?s.isSkinnedMesh&&!1===y.skinning?x=!0:s.isSkinnedMesh||!0!==y.skinning?s.isInstancedMesh&&!0===y.instancingColor&&null===s.instanceColor||s.isInstancedMesh&&!1===y.instancingColor&&null!==s.instanceColor||s.isInstancedMesh&&!0===y.instancingMorph&&null===s.morphTexture||s.isInstancedMesh&&!1===y.instancingMorph&&null!==s.morphTexture||y.envMap!==h||!0===n.fog&&y.fog!==r?x=!0:void 0===y.numClippingPlanes||y.numClippingPlanes===wt.numPlanes&&y.numIntersection===wt.numIntersection?(y.vertexAlphas!==c||y.vertexTangents!==d||y.morphTargets!==u||y.morphNormals!==p||y.morphColors!==m||y.toneMapping!==f||y.morphTargetsCount!==v)&&(x=!0):x=!0:x=!0:x=!0:x=!0:(x=!0,y.__version=n.version);let S=y.currentProgram;!0===x&&(S=ee(n,e,s));let M=!1,w=!1,E=!1;const T=S.getUniforms(),C=y.uniforms;nt.useProgram(S.program)&&(M=!0,w=!0,E=!0);n.id!==R&&(R=n.id,w=!0);if(M||P!==t){nt.buffers.depth.getReversed()&&!0!==t.reversedDepth&&(t._reversedDepth=!0,t.updateProjectionMatrix()),T.setValue(Nt,"projectionMatrix",t.projectionMatrix),T.setValue(Nt,"viewMatrix",t.matrixWorldInverse);const e=T.map.cameraPosition;void 0!==e&&e.setValue(Nt,q.setFromMatrixPosition(t.matrixWorld)),it.logarithmicDepthBuffer&&T.setValue(Nt,"logDepthBufFC",2/(Math.log(t.far+1)/Math.LN2)),(n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshLambertMaterial||n.isMeshBasicMaterial||n.isMeshStandardMaterial||n.isShaderMaterial)&&T.setValue(Nt,"isOrthographic",!0===t.isOrthographicCamera),P!==t&&(P=t,w=!0,E=!0)}y.needsLights&&(_.state.directionalShadowMap.length>0&&T.setValue(Nt,"directionalShadowMap",_.state.directionalShadowMap,ht),_.state.spotShadowMap.length>0&&T.setValue(Nt,"spotShadowMap",_.state.spotShadowMap,ht),_.state.pointShadowMap.length>0&&T.setValue(Nt,"pointShadowMap",_.state.pointShadowMap,ht));if(s.isSkinnedMesh){T.setOptional(Nt,s,"bindMatrix"),T.setOptional(Nt,s,"bindMatrixInverse");const t=s.skeleton;t&&(null===t.boneTexture&&t.computeBoneTexture(),T.setValue(Nt,"boneTexture",t.boneTexture,ht))}s.isBatchedMesh&&(T.setOptional(Nt,s,"batchingTexture"),T.setValue(Nt,"batchingTexture",s._matricesTexture,ht),T.setOptional(Nt,s,"batchingIdTexture"),T.setValue(Nt,"batchingIdTexture",s._indirectTexture,ht),T.setOptional(Nt,s,"batchingColorTexture"),null!==s._colorsTexture&&T.setValue(Nt,"batchingColorTexture",s._colorsTexture,ht));const I=i.morphAttributes;void 0===I.position&&void 0===I.normal&&void 0===I.color||Pt.update(s,i,S);(w||y.receiveShadow!==s.receiveShadow)&&(y.receiveShadow=s.receiveShadow,T.setValue(Nt,"receiveShadow",s.receiveShadow));(n.isMeshStandardMaterial||n.isMeshLambertMaterial||n.isMeshPhongMaterial)&&null===n.envMap&&null!==e.environment&&(C.envMapIntensity.value=e.environmentIntensity);void 0!==C.dfgLUT&&(C.dfgLUT.value=(null===rm&&(rm=new Lr(sm,16,16,Ct,ft),rm.name="DFG_LUT",rm.minFilter=rt,rm.magFilter=rt,rm.wrapS=tt,rm.wrapT=tt,rm.generateMipmaps=!1,rm.needsUpdate=!0),rm));w&&(T.setValue(Nt,"toneMappingExposure",A.toneMappingExposure),y.needsLights&&(B=E,(L=C).ambientLightColor.needsUpdate=B,L.lightProbe.needsUpdate=B,L.directionalLights.needsUpdate=B,L.directionalLightShadows.needsUpdate=B,L.pointLights.needsUpdate=B,L.pointLightShadows.needsUpdate=B,L.spotLights.needsUpdate=B,L.spotLightShadows.needsUpdate=B,L.rectAreaLights.needsUpdate=B,L.hemisphereLights.needsUpdate=B),r&&!0===n.fog&&bt.refreshFogUniforms(C,r),bt.refreshMaterialUniforms(C,n,k,U,b.state.transmissionRenderTarget[t.id]),ip.upload(Nt,ie(y),C,ht));var L,B;n.isShaderMaterial&&!0===n.uniformsNeedUpdate&&(ip.upload(Nt,ie(y),C,ht),n.uniformsNeedUpdate=!1);n.isSpriteMaterial&&T.setValue(Nt,"center",s.center);if(T.setValue(Nt,"modelViewMatrix",s.modelViewMatrix),T.setValue(Nt,"normalMatrix",s.normalMatrix),T.setValue(Nt,"modelMatrix",s.matrixWorld),n.isShaderMaterial||n.isRawShaderMaterial){const t=n.uniformsGroups;for(let e=0,i=t.length;e<i;e++){const i=t[e];Ft.update(i,S),Ft.bind(i,S)}}return S}(t,e,i,n,s);nt.setMaterial(n,a);let l=i.index,h=1;if(!0===n.wireframe){if(l=mt.getWireframeAttribute(i),void 0===l)return;h=2}const c=i.drawRange,d=i.attributes.position;let u=c.start*h,p=(c.start+c.count)*h;null!==r&&(u=Math.max(u,r.start*h),p=Math.min(p,(r.start+r.count)*h)),null!==l?(u=Math.max(u,0),p=Math.min(p,l.count)):null!=d&&(u=Math.max(u,0),p=Math.min(p,d.count));const m=p-u;if(m<0||m===1/0)return;let f;Ot.setup(s,n,o,i,l);let g=It;if(null!==l&&(f=ut.get(l),g=Lt,g.setIndex(f)),s.isMesh)!0===n.wireframe?(nt.setLineWidth(n.wireframeLinewidth*$()),g.setMode(Nt.LINES)):g.setMode(Nt.TRIANGLES);else if(s.isLine){let t=n.linewidth;void 0===t&&(t=1),nt.setLineWidth(t*$()),s.isLineSegments?g.setMode(Nt.LINES):s.isLineLoop?g.setMode(Nt.LINE_LOOP):g.setMode(Nt.LINE_STRIP)}else s.isPoints?g.setMode(Nt.POINTS):s.isSprite&&g.setMode(Nt.TRIANGLES);if(s.isBatchedMesh)if(null!==s._multiDrawInstances)si("WebGLRenderer: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection."),g.renderMultiDrawInstances(s._multiDrawStarts,s._multiDrawCounts,s._multiDrawCount,s._multiDrawInstances);else if(et.get("WEBGL_multi_draw"))g.renderMultiDraw(s._multiDrawStarts,s._multiDrawCounts,s._multiDrawCount);else{const t=s._multiDrawStarts,e=s._multiDrawCounts,i=s._multiDrawCount,r=l?ut.get(l).bytesPerElement:1,a=at.get(n).currentProgram.getUniforms();for(let n=0;n<i;n++)a.setValue(Nt,"_gl_DrawID",n),g.render(t[n]/r,e[n])}else if(s.isInstancedMesh)g.renderInstances(u,m,s.count);else if(i.isInstancedBufferGeometry){const t=void 0!==i._maxInstanceCount?i._maxInstanceCount:1/0,e=Math.min(i.instanceCount,t);g.renderInstances(u,m,e)}else g.render(u,m)},this.compile=function(t,e,i=null){null===i&&(i=t),b=Mt.get(i),b.init(e),M.push(b),i.traverseVisible(function(t){t.isLight&&t.layers.test(e.layers)&&(b.pushLight(t),t.castShadow&&b.pushShadow(t))}),t!==i&&t.traverseVisible(function(t){t.isLight&&t.layers.test(e.layers)&&(b.pushLight(t),t.castShadow&&b.pushShadow(t))}),b.setupLights();const n=new Set;return t.traverse(function(t){if(!(t.isMesh||t.isPoints||t.isLine||t.isSprite))return;const e=t.material;if(e)if(Array.isArray(e))for(let s=0;s<e.length;s++){const r=e[s];jt(r,i,t),n.add(r)}else jt(e,i,t),n.add(e)}),b=M.pop(),n},this.compileAsync=function(t,e,i=null){const n=this.compile(t,e,i);return new Promise(e=>{function i(){n.forEach(function(t){at.get(t).currentProgram.isReady()&&n.delete(t)}),0!==n.size?setTimeout(i,10):e(t)}null!==et.get("KHR_parallel_shader_compile")?i():setTimeout(i,10)})};let Xt=null;function Yt(){qt.stop()}function Zt(){qt.start()}const qt=new md;function Qt(t,e,i,n){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)i=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)b.pushLight(t),t.castShadow&&b.pushShadow(t);else if(t.isSprite){if(!t.frustumCulled||j.intersectsSprite(t)){n&&Q.setFromMatrixPosition(t.matrixWorld).applyMatrix4(Z);const e=_t.update(t),s=t.material;s.visible&&x.push(t,e,s,i,Q.z,null)}}else if((t.isMesh||t.isLine||t.isPoints)&&(!t.frustumCulled||j.intersectsObject(t))){const e=_t.update(t),s=t.material;if(n&&(void 0!==t.boundingSphere?(null===t.boundingSphere&&t.computeBoundingSphere(),Q.copy(t.boundingSphere.center)):(null===e.boundingSphere&&e.computeBoundingSphere(),Q.copy(e.boundingSphere.center)),Q.applyMatrix4(t.matrixWorld).applyMatrix4(Z)),Array.isArray(s)){const n=e.groups;for(let r=0,a=n.length;r<a;r++){const a=n[r],o=s[a.materialIndex];o&&o.visible&&x.push(t,e,o,i,Q.z,a)}}else s.visible&&x.push(t,e,s,i,Q.z,null)}const s=t.children;for(let t=0,r=s.length;t<r;t++)Qt(s[t],e,i,n)}function Kt(t,e,i,n){const{opaque:s,transmissive:r,transparent:a}=t;b.setupLightsView(i),!0===X&&wt.setGlobalState(A.clippingPlanes,i),n&&nt.viewport(I.copy(n)),s.length>0&&$t(s,e,i),r.length>0&&$t(r,e,i),a.length>0&&$t(a,e,i),nt.buffers.depth.setTest(!0),nt.buffers.depth.setMask(!0),nt.buffers.color.setMask(!0),nt.setPolygonOffset(!1)}function Jt(t,e,i,n){if(null!==(!0===i.isScene?i.overrideMaterial:null))return;if(void 0===b.state.transmissionRenderTarget[n.id]){const t=et.has("EXT_color_buffer_half_float")||et.has("EXT_color_buffer_float");b.state.transmissionRenderTarget[n.id]=new Gi(1,1,{generateMipmaps:!0,type:t?ft:lt,minFilter:ot,samples:it.samples,stencilBuffer:r,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:Ci.workingColorSpace})}const s=b.state.transmissionRenderTarget[n.id],a=n.viewport||I;s.setSize(a.z*A.transmissionResolutionScale,a.w*A.transmissionResolutionScale);const o=A.getRenderTarget(),l=A.getActiveCubeFace(),h=A.getActiveMipmapLevel();A.setRenderTarget(s),A.getClearColor(O),F=A.getClearAlpha(),F<1&&A.setClearColor(16777215,.5),A.clear(),J&&Et.render(i);const c=A.toneMapping;A.toneMapping=0;const d=n.viewport;if(void 0!==n.viewport&&(n.viewport=void 0),b.setupLightsView(n),!0===X&&wt.setGlobalState(A.clippingPlanes,n),$t(t,i,n),ht.updateMultisampleRenderTarget(s),ht.updateRenderTargetMipmap(s),!1===et.has("WEBGL_multisampled_render_to_texture")){let t=!1;for(let s=0,r=e.length;s<r;s++){const r=e[s],{object:a,geometry:o,material:l,group:h}=r;if(2===l.side&&a.layers.test(n.layers)){const e=l.side;l.side=1,l.needsUpdate=!0,te(a,i,n,o,l,h),l.side=e,l.needsUpdate=!0,t=!0}}!0===t&&(ht.updateMultisampleRenderTarget(s),ht.updateRenderTargetMipmap(s))}A.setRenderTarget(o,l,h),A.setClearColor(O,F),void 0!==d&&(n.viewport=d),A.toneMapping=c}function $t(t,e,i){const n=!0===e.isScene?e.overrideMaterial:null;for(let s=0,r=t.length;s<r;s++){const r=t[s],{object:a,geometry:o,group:l}=r;let h=r.material;!0===h.allowOverride&&null!==n&&(h=n),a.layers.test(i.layers)&&te(a,e,i,o,h,l)}}function te(t,e,i,n,s,r){t.onBeforeRender(A,e,i,n,s,r),t.modelViewMatrix.multiplyMatrices(i.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix),s.onBeforeRender(A,e,i,n,t,r),!0===s.transparent&&2===s.side&&!1===s.forceSinglePass?(s.side=1,s.needsUpdate=!0,A.renderBufferDirect(i,e,n,s,t,r),s.side=0,s.needsUpdate=!0,A.renderBufferDirect(i,e,n,s,t,r),s.side=2):A.renderBufferDirect(i,e,n,s,t,r),t.onAfterRender(A,e,i,n,s,r)}function ee(t,e,i){!0!==e.isScene&&(e=K);const n=at.get(t),s=b.state.lights,r=b.state.shadowsArray,a=s.state.version,o=xt.getParameters(t,s.state,r,e,i),l=xt.getProgramCacheKey(o);let h=n.programs;n.environment=t.isMeshStandardMaterial||t.isMeshLambertMaterial||t.isMeshPhongMaterial?e.environment:null,n.fog=e.fog;const c=t.isMeshStandardMaterial||t.isMeshLambertMaterial&&!t.envMap||t.isMeshPhongMaterial&&!t.envMap;n.envMap=ct.get(t.envMap||n.environment,c),n.envMapRotation=null!==n.environment&&null===t.envMap?e.environmentRotation:t.envMapRotation,void 0===h&&(t.addEventListener("dispose",Wt),h=new Map,n.programs=h);let d=h.get(l);if(void 0!==d){if(n.currentProgram===d&&n.lightsStateVersion===a)return ne(t,o),d}else o.uniforms=xt.getUniforms(t),t.onBeforeCompile(o,A),d=xt.acquireProgram(o,l),h.set(l,d),n.uniforms=o.uniforms;const u=n.uniforms;return(t.isShaderMaterial||t.isRawShaderMaterial)&&!0!==t.clipping||(u.clippingPlanes=wt.uniform),ne(t,o),n.needsLights=function(t){return t.isMeshLambertMaterial||t.isMeshToonMaterial||t.isMeshPhongMaterial||t.isMeshStandardMaterial||t.isShadowMaterial||t.isShaderMaterial&&!0===t.lights}(t),n.lightsStateVersion=a,n.needsLights&&(u.ambientLightColor.value=s.state.ambient,u.lightProbe.value=s.state.probe,u.directionalLights.value=s.state.directional,u.directionalLightShadows.value=s.state.directionalShadow,u.spotLights.value=s.state.spot,u.spotLightShadows.value=s.state.spotShadow,u.rectAreaLights.value=s.state.rectArea,u.ltc_1.value=s.state.rectAreaLTC1,u.ltc_2.value=s.state.rectAreaLTC2,u.pointLights.value=s.state.point,u.pointLightShadows.value=s.state.pointShadow,u.hemisphereLights.value=s.state.hemi,u.directionalShadowMatrix.value=s.state.directionalShadowMatrix,u.spotLightMatrix.value=s.state.spotLightMatrix,u.spotLightMap.value=s.state.spotLightMap,u.pointShadowMatrix.value=s.state.pointShadowMatrix),n.currentProgram=d,n.uniformsList=null,d}function ie(t){if(null===t.uniformsList){const e=t.currentProgram.getUniforms();t.uniformsList=ip.seqWithValue(e.seq,t.uniforms)}return t.uniformsList}function ne(t,e){const i=at.get(t);i.outputColorSpace=e.outputColorSpace,i.batching=e.batching,i.batchingColor=e.batchingColor,i.instancing=e.instancing,i.instancingColor=e.instancingColor,i.instancingMorph=e.instancingMorph,i.skinning=e.skinning,i.morphTargets=e.morphTargets,i.morphNormals=e.morphNormals,i.morphColors=e.morphColors,i.morphTargetsCount=e.morphTargetsCount,i.numClippingPlanes=e.numClippingPlanes,i.numIntersection=e.numClipIntersection,i.vertexAlphas=e.vertexAlphas,i.vertexTangents=e.vertexTangents,i.toneMapping=e.toneMapping}qt.setAnimationLoop(function(t){Xt&&Xt(t)}),"undefined"!=typeof self&&qt.setContext(self),this.setAnimationLoop=function(t){Xt=t,zt.setAnimationLoop(t),null===t?qt.stop():qt.start()},zt.addEventListener("sessionstart",Yt),zt.addEventListener("sessionend",Zt),this.render=function(t,e){if(void 0!==e&&!0!==e.isCamera)return void ni("WebGLRenderer.render: camera is not an instance of THREE.Camera.");if(!0===E)return;const i=!0===zt.enabled&&!0===zt.isPresenting,n=null!==w&&(null===D||i)&&w.begin(A,D);if(!0===t.matrixWorldAutoUpdate&&t.updateMatrixWorld(),null===e.parent&&!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld(),!0!==zt.enabled||!0!==zt.isPresenting||null!==w&&!1!==w.isCompositing()||(!0===zt.cameraAutoUpdate&&zt.updateCamera(e),e=zt.getCamera()),!0===t.isScene&&t.onBeforeRender(A,t,e,D),b=Mt.get(t,M.length),b.init(e),M.push(b),Z.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),j.setFromProjectionMatrix(Z,je,e.reversedDepth),Y=this.localClippingEnabled,X=wt.init(this.clippingPlanes,Y),x=St.get(t,S.length),x.init(),S.push(x),!0===zt.enabled&&!0===zt.isPresenting){const t=A.xr.getDepthSensingMesh();null!==t&&Qt(t,e,-1/0,A.sortObjects)}Qt(t,e,0,A.sortObjects),x.finish(),!0===A.sortObjects&&x.sort(z,G),J=!1===zt.enabled||!1===zt.isPresenting||!1===zt.hasDepthSensing(),J&&Et.addToRenderList(x,t),this.info.render.frame++,!0===X&&wt.beginShadows();const s=b.state.shadowsArray;At.render(s,t,e),!0===X&&wt.endShadows(),!0===this.info.autoReset&&this.info.reset();if(!1===(n&&w.hasRenderPass())){const i=x.opaque,n=x.transmissive;if(b.setupLights(),e.isArrayCamera){const s=e.cameras;if(n.length>0)for(let e=0,r=s.length;e<r;e++){Jt(i,n,t,s[e])}J&&Et.render(t);for(let e=0,i=s.length;e<i;e++){const i=s[e];Kt(x,t,i,i.viewport)}}else n.length>0&&Jt(i,n,t,e),J&&Et.render(t),Kt(x,t,e)}null!==D&&0===C&&(ht.updateMultisampleRenderTarget(D),ht.updateRenderTargetMipmap(D)),n&&w.end(A),!0===t.isScene&&t.onAfterRender(A,t,e),Ot.resetDefaultState(),R=-1,P=null,M.pop(),M.length>0?(b=M[M.length-1],!0===X&&wt.setGlobalState(A.clippingPlanes,b.state.camera)):b=null,S.pop(),x=S.length>0?S[S.length-1]:null},this.getActiveCubeFace=function(){return T},this.getActiveMipmapLevel=function(){return C},this.getRenderTarget=function(){return D},this.setRenderTargetTextures=function(t,e,i){const n=at.get(t);n.__autoAllocateDepthBuffer=!1===t.resolveDepthBuffer,!1===n.__autoAllocateDepthBuffer&&(n.__useRenderToTexture=!1),at.get(t.texture).__webglTexture=e,at.get(t.depthTexture).__webglTexture=n.__autoAllocateDepthBuffer?void 0:i,n.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(t,e){const i=at.get(t);i.__webglFramebuffer=e,i.__useDefaultFramebuffer=void 0===e};const se=Nt.createFramebuffer();this.setRenderTarget=function(t,e=0,i=0){D=t,T=e,C=i;let n=null,s=!1,r=!1;if(t){const a=at.get(t);if(void 0!==a.__useDefaultFramebuffer)return nt.bindFramebuffer(Nt.FRAMEBUFFER,a.__webglFramebuffer),I.copy(t.viewport),L.copy(t.scissor),B=t.scissorTest,nt.viewport(I),nt.scissor(L),nt.setScissorTest(B),void(R=-1);if(void 0===a.__webglFramebuffer)ht.setupRenderTarget(t);else if(a.__hasExternalTextures)ht.rebindTextures(t,at.get(t.texture).__webglTexture,at.get(t.depthTexture).__webglTexture);else if(t.depthBuffer){const e=t.depthTexture;if(a.__boundDepthTexture!==e){if(null!==e&&at.has(e)&&(t.width!==e.image.width||t.height!==e.image.height))throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");ht.setupDepthRenderbuffer(t)}}const o=t.texture;(o.isData3DTexture||o.isDataArrayTexture||o.isCompressedArrayTexture)&&(r=!0);const l=at.get(t).__webglFramebuffer;t.isWebGLCubeRenderTarget?(n=Array.isArray(l[e])?l[e][i]:l[e],s=!0):n=t.samples>0&&!1===ht.useMultisampledRTT(t)?at.get(t).__webglMultisampledFramebuffer:Array.isArray(l)?l[i]:l,I.copy(t.viewport),L.copy(t.scissor),B=t.scissorTest}else I.copy(H).multiplyScalar(k).floor(),L.copy(V).multiplyScalar(k).floor(),B=W;0!==i&&(n=se);if(nt.bindFramebuffer(Nt.FRAMEBUFFER,n)&&nt.drawBuffers(t,n),nt.viewport(I),nt.scissor(L),nt.setScissorTest(B),s){const n=at.get(t.texture);Nt.framebufferTexture2D(Nt.FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,Nt.TEXTURE_CUBE_MAP_POSITIVE_X+e,n.__webglTexture,i)}else if(r){const n=e;for(let e=0;e<t.textures.length;e++){const s=at.get(t.textures[e]);Nt.framebufferTextureLayer(Nt.FRAMEBUFFER,Nt.COLOR_ATTACHMENT0+e,s.__webglTexture,i,n)}}else if(null!==t&&0!==i){const e=at.get(t.texture);Nt.framebufferTexture2D(Nt.FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,Nt.TEXTURE_2D,e.__webglTexture,i)}R=-1},this.readRenderTargetPixels=function(t,e,i,n,s,r,a,o=0){if(!t||!t.isWebGLRenderTarget)return void ni("WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let l=at.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(l=l[a]),l){nt.bindFramebuffer(Nt.FRAMEBUFFER,l);try{const a=t.textures[o],l=a.format,h=a.type;if(t.textures.length>1&&Nt.readBuffer(Nt.COLOR_ATTACHMENT0+o),!it.textureFormatReadable(l))return void ni("WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");if(!it.textureTypeReadable(h))return void ni("WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");e>=0&&e<=t.width-n&&i>=0&&i<=t.height-s&&Nt.readPixels(e,i,n,s,Bt.convert(l),Bt.convert(h),r)}finally{const t=null!==D?at.get(D).__webglFramebuffer:null;nt.bindFramebuffer(Nt.FRAMEBUFFER,t)}}},this.readRenderTargetPixelsAsync=async function(t,e,i,n,s,r,a,o=0){if(!t||!t.isWebGLRenderTarget)throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let l=at.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(l=l[a]),l){if(e>=0&&e<=t.width-n&&i>=0&&i<=t.height-s){nt.bindFramebuffer(Nt.FRAMEBUFFER,l);const a=t.textures[o],h=a.format,c=a.type;if(t.textures.length>1&&Nt.readBuffer(Nt.COLOR_ATTACHMENT0+o),!it.textureFormatReadable(h))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!it.textureTypeReadable(c))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");const d=Nt.createBuffer();Nt.bindBuffer(Nt.PIXEL_PACK_BUFFER,d),Nt.bufferData(Nt.PIXEL_PACK_BUFFER,r.byteLength,Nt.STREAM_READ),Nt.readPixels(e,i,n,s,Bt.convert(h),Bt.convert(c),0);const u=null!==D?at.get(D).__webglFramebuffer:null;nt.bindFramebuffer(Nt.FRAMEBUFFER,u);const p=Nt.fenceSync(Nt.SYNC_GPU_COMMANDS_COMPLETE,0);return Nt.flush(),await function(t,e,i){return new Promise(function(n,s){setTimeout(function r(){switch(t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0)){case t.WAIT_FAILED:s();break;case t.TIMEOUT_EXPIRED:setTimeout(r,i);break;default:n()}},i)})}(Nt,p,4),Nt.bindBuffer(Nt.PIXEL_PACK_BUFFER,d),Nt.getBufferSubData(Nt.PIXEL_PACK_BUFFER,0,r),Nt.deleteBuffer(d),Nt.deleteSync(p),r}throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")}},this.copyFramebufferToTexture=function(t,e=null,i=0){const n=Math.pow(2,-i),s=Math.floor(t.image.width*n),r=Math.floor(t.image.height*n),a=null!==e?e.x:0,o=null!==e?e.y:0;ht.setTexture2D(t,0),Nt.copyTexSubImage2D(Nt.TEXTURE_2D,i,0,0,a,o,s,r),nt.unbindTexture()};const re=Nt.createFramebuffer(),ae=Nt.createFramebuffer();this.copyTextureToTexture=function(t,e,i=null,n=null,s=0,r=0){let a,o,l,h,c,d,u,p,m;const f=t.isCompressedTexture?t.mipmaps[r]:t.image;if(null!==i)a=i.max.x-i.min.x,o=i.max.y-i.min.y,l=i.isBox3?i.max.z-i.min.z:1,h=i.min.x,c=i.min.y,d=i.isBox3?i.min.z:0;else{const e=Math.pow(2,-s);a=Math.floor(f.width*e),o=Math.floor(f.height*e),l=t.isDataArrayTexture?f.depth:t.isData3DTexture?Math.floor(f.depth*e):1,h=0,c=0,d=0}null!==n?(u=n.x,p=n.y,m=n.z):(u=0,p=0,m=0);const g=Bt.convert(e.format),v=Bt.convert(e.type);let y;e.isData3DTexture?(ht.setTexture3D(e,0),y=Nt.TEXTURE_3D):e.isDataArrayTexture||e.isCompressedArrayTexture?(ht.setTexture2DArray(e,0),y=Nt.TEXTURE_2D_ARRAY):(ht.setTexture2D(e,0),y=Nt.TEXTURE_2D),Nt.pixelStorei(Nt.UNPACK_FLIP_Y_WEBGL,e.flipY),Nt.pixelStorei(Nt.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultiplyAlpha),Nt.pixelStorei(Nt.UNPACK_ALIGNMENT,e.unpackAlignment);const _=Nt.getParameter(Nt.UNPACK_ROW_LENGTH),x=Nt.getParameter(Nt.UNPACK_IMAGE_HEIGHT),b=Nt.getParameter(Nt.UNPACK_SKIP_PIXELS),S=Nt.getParameter(Nt.UNPACK_SKIP_ROWS),M=Nt.getParameter(Nt.UNPACK_SKIP_IMAGES);Nt.pixelStorei(Nt.UNPACK_ROW_LENGTH,f.width),Nt.pixelStorei(Nt.UNPACK_IMAGE_HEIGHT,f.height),Nt.pixelStorei(Nt.UNPACK_SKIP_PIXELS,h),Nt.pixelStorei(Nt.UNPACK_SKIP_ROWS,c),Nt.pixelStorei(Nt.UNPACK_SKIP_IMAGES,d);const w=t.isDataArrayTexture||t.isData3DTexture,A=e.isDataArrayTexture||e.isData3DTexture;if(t.isDepthTexture){const i=at.get(t),n=at.get(e),f=at.get(i.__renderTarget),g=at.get(n.__renderTarget);nt.bindFramebuffer(Nt.READ_FRAMEBUFFER,f.__webglFramebuffer),nt.bindFramebuffer(Nt.DRAW_FRAMEBUFFER,g.__webglFramebuffer);for(let i=0;i<l;i++)w&&(Nt.framebufferTextureLayer(Nt.READ_FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,at.get(t).__webglTexture,s,d+i),Nt.framebufferTextureLayer(Nt.DRAW_FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,at.get(e).__webglTexture,r,m+i)),Nt.blitFramebuffer(h,c,a,o,u,p,a,o,Nt.DEPTH_BUFFER_BIT,Nt.NEAREST);nt.bindFramebuffer(Nt.READ_FRAMEBUFFER,null),nt.bindFramebuffer(Nt.DRAW_FRAMEBUFFER,null)}else if(0!==s||t.isRenderTargetTexture||at.has(t)){const i=at.get(t),n=at.get(e);nt.bindFramebuffer(Nt.READ_FRAMEBUFFER,re),nt.bindFramebuffer(Nt.DRAW_FRAMEBUFFER,ae);for(let t=0;t<l;t++)w?Nt.framebufferTextureLayer(Nt.READ_FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,i.__webglTexture,s,d+t):Nt.framebufferTexture2D(Nt.READ_FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,Nt.TEXTURE_2D,i.__webglTexture,s),A?Nt.framebufferTextureLayer(Nt.DRAW_FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,n.__webglTexture,r,m+t):Nt.framebufferTexture2D(Nt.DRAW_FRAMEBUFFER,Nt.COLOR_ATTACHMENT0,Nt.TEXTURE_2D,n.__webglTexture,r),0!==s?Nt.blitFramebuffer(h,c,a,o,u,p,a,o,Nt.COLOR_BUFFER_BIT,Nt.NEAREST):A?Nt.copyTexSubImage3D(y,r,u,p,m+t,h,c,a,o):Nt.copyTexSubImage2D(y,r,u,p,h,c,a,o);nt.bindFramebuffer(Nt.READ_FRAMEBUFFER,null),nt.bindFramebuffer(Nt.DRAW_FRAMEBUFFER,null)}else A?t.isDataTexture||t.isData3DTexture?Nt.texSubImage3D(y,r,u,p,m,a,o,l,g,v,f.data):e.isCompressedArrayTexture?Nt.compressedTexSubImage3D(y,r,u,p,m,a,o,l,g,f.data):Nt.texSubImage3D(y,r,u,p,m,a,o,l,g,v,f):t.isDataTexture?Nt.texSubImage2D(Nt.TEXTURE_2D,r,u,p,a,o,g,v,f.data):t.isCompressedTexture?Nt.compressedTexSubImage2D(Nt.TEXTURE_2D,r,u,p,f.width,f.height,g,f.data):Nt.texSubImage2D(Nt.TEXTURE_2D,r,u,p,a,o,g,v,f);Nt.pixelStorei(Nt.UNPACK_ROW_LENGTH,_),Nt.pixelStorei(Nt.UNPACK_IMAGE_HEIGHT,x),Nt.pixelStorei(Nt.UNPACK_SKIP_PIXELS,b),Nt.pixelStorei(Nt.UNPACK_SKIP_ROWS,S),Nt.pixelStorei(Nt.UNPACK_SKIP_IMAGES,M),0===r&&e.generateMipmaps&&Nt.generateMipmap(y),nt.unbindTexture()},this.initRenderTarget=function(t){void 0===at.get(t).__webglFramebuffer&&ht.setupRenderTarget(t)},this.initTexture=function(t){t.isCubeTexture?ht.setTextureCube(t,0):t.isData3DTexture?ht.setTexture3D(t,0):t.isDataArrayTexture||t.isCompressedArrayTexture?ht.setTexture2DArray(t,0):ht.setTexture2D(t,0),nt.unbindTexture()},this.resetState=function(){T=0,C=0,D=null,nt.reset(),Ot.reset()},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return je}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(t){this._outputColorSpace=t;const e=this.getContext();e.drawingBufferColorSpace=Ci._getDrawingBufferColorSpace(t),e.unpackColorSpace=Ci._getUnpackColorSpace()}}var om=Object.freeze({__proto__:null,ACESFilmicToneMapping:4,AddEquation:h,AddOperation:2,AdditiveAnimationBlendMode:Me,AdditiveBlending:2,AgXToneMapping:6,AlphaFormat:bt,AlwaysCompare:519,AlwaysDepth:1,AlwaysStencilFunc:Be,AmbientLight:kh,AnimationAction:wc,AnimationClip:sh,AnimationLoader:class extends ch{constructor(t){super(t)}load(t,e,i,n){const s=this,r=new ph(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,function(i){try{e(s.parse(JSON.parse(i)))}catch(e){n?n(e):ni(e),s.manager.itemError(t)}},i,n)}parse(t){const e=[];for(let i=0;i<t.length;i++){const n=sh.parse(t[i]);e.push(n)}return e}},AnimationMixer:Ec,AnimationObjectGroup:class{constructor(){this.isAnimationObjectGroup=!0,this.uuid=di(),this._objects=Array.prototype.slice.call(arguments),this.nCachedObjects_=0;const t={};this._indicesByUUID=t;for(let e=0,i=arguments.length;e!==i;++e)t[arguments[e].uuid]=e;this._paths=[],this._parsedPaths=[],this._bindings=[],this._bindingsIndicesByPath={};const e=this;this.stats={objects:{get total(){return e._objects.length},get inUse(){return this.total-e.nCachedObjects_}},get bindingsPerObject(){return e._bindings.length}}}add(){const t=this._objects,e=this._indicesByUUID,i=this._paths,n=this._parsedPaths,s=this._bindings,r=s.length;let a,o=t.length,l=this.nCachedObjects_;for(let h=0,c=arguments.length;h!==c;++h){const c=arguments[h],d=c.uuid;let u=e[d];if(void 0===u){u=o++,e[d]=u,t.push(c);for(let t=0,e=r;t!==e;++t)s[t].push(new Mc(c,i[t],n[t]))}else if(u<l){a=t[u];const o=--l,h=t[o];e[h.uuid]=u,t[u]=h,e[d]=o,t[o]=c;for(let t=0,e=r;t!==e;++t){const e=s[t],r=e[o];let a=e[u];e[u]=r,void 0===a&&(a=new Mc(c,i[t],n[t])),e[o]=a}}else t[u]!==a&&ni("AnimationObjectGroup: Different objects with the same UUID detected. Clean the caches or recreate your infrastructure when reloading scenes.")}this.nCachedObjects_=l}remove(){const t=this._objects,e=this._indicesByUUID,i=this._bindings,n=i.length;let s=this.nCachedObjects_;for(let r=0,a=arguments.length;r!==a;++r){const a=arguments[r],o=a.uuid,l=e[o];if(void 0!==l&&l>=s){const r=s++,h=t[r];e[h.uuid]=l,t[l]=h,e[o]=r,t[r]=a;for(let t=0,e=n;t!==e;++t){const e=i[t],n=e[r],s=e[l];e[l]=n,e[r]=s}}}this.nCachedObjects_=s}uncache(){const t=this._objects,e=this._indicesByUUID,i=this._bindings,n=i.length;let s=this.nCachedObjects_,r=t.length;for(let a=0,o=arguments.length;a!==o;++a){const o=arguments[a].uuid,l=e[o];if(void 0!==l)if(delete e[o],l<s){const a=--s,o=t[a],h=--r,c=t[h];e[o.uuid]=l,t[l]=o,e[c.uuid]=a,t[a]=c,t.pop();for(let t=0,e=n;t!==e;++t){const e=i[t],n=e[a],s=e[h];e[l]=n,e[a]=s,e.pop()}}else{const s=--r,a=t[s];s>0&&(e[a.uuid]=l),t[l]=a,t.pop();for(let t=0,e=n;t!==e;++t){const e=i[t];e[l]=e[s],e.pop()}}}this.nCachedObjects_=s}subscribe_(t,e){const i=this._bindingsIndicesByPath;let n=i[t];const s=this._bindings;if(void 0!==n)return s[n];const r=this._paths,a=this._parsedPaths,o=this._objects,l=o.length,h=this.nCachedObjects_,c=new Array(l);n=s.length,i[t]=n,r.push(t),a.push(e),s.push(c);for(let i=h,n=o.length;i!==n;++i){const n=o[i];c[i]=new Mc(n,t,e)}return c}unsubscribe_(t){const e=this._bindingsIndicesByPath,i=e[t];if(void 0!==i){const n=this._paths,s=this._parsedPaths,r=this._bindings,a=r.length-1,o=r[a];e[t[a]]=i,r[i]=o,r.pop(),s[i]=s[a],s.pop(),n[i]=n[a],n.pop()}}},AnimationUtils:class{static convertArray(t,e){return Gl(t,e)}static isTypedArray(t){return qe(t)}static getKeyframeOrder(t){return Hl(t)}static sortedArray(t,e,i){return Vl(t,e,i)}static flattenJSON(t,e,i,n){Wl(t,e,i,n)}static subclip(t,e,i,n,s=30){return function(t,e,i,n,s=30){const r=t.clone();r.name=e;const a=[];for(let t=0;t<r.tracks.length;++t){const e=r.tracks[t],o=e.getValueSize(),l=[],h=[];for(let t=0;t<e.times.length;++t){const r=e.times[t]*s;if(!(r<i||r>=n)){l.push(e.times[t]);for(let i=0;i<o;++i)h.push(e.values[t*o+i])}}0!==l.length&&(e.times=Gl(l,e.times.constructor),e.values=Gl(h,e.values.constructor),a.push(e))}r.tracks=a;let o=1/0;for(let t=0;t<r.tracks.length;++t)o>r.tracks[t].times[0]&&(o=r.tracks[t].times[0]);for(let t=0;t<r.tracks.length;++t)r.tracks[t].shift(-1*o);return r.resetDuration(),r}(t,e,i,n,s)}static makeClipAdditive(t,e=0,i=t,n=30){return function(t,e=0,i=t,n=30){n<=0&&(n=30);const s=i.tracks.length,r=e/n;for(let e=0;e<s;++e){const n=i.tracks[e],s=n.ValueTypeName;if("bool"===s||"string"===s)continue;const a=t.tracks.find(function(t){return t.name===n.name&&t.ValueTypeName===s});if(void 0===a)continue;let o=0;const l=n.getValueSize();n.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(o=l/3);let h=0;const c=a.getValueSize();a.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(h=c/3);const d=n.times.length-1;let u;if(r<=n.times[0]){const t=o,e=l-o;u=n.values.slice(t,e)}else if(r>=n.times[d]){const t=d*l+o,e=t+l-o;u=n.values.slice(t,e)}else{const t=n.createInterpolant(),e=o,i=l-o;t.evaluate(r),u=t.resultBuffer.slice(e,i)}"quaternion"===s&&(new _i).fromArray(u).normalize().conjugate().toArray(u);const p=a.times.length;for(let t=0;t<p;++t){const e=t*c+h;if("quaternion"===s)_i.multiplyQuaternionsFlat(a.values,e,u,0,a.values,e);else{const t=c-2*h;for(let i=0;i<t;++i)a.values[e+i]-=u[i]}}}return t.blendMode=Me,t}(t,e,i,n)}},ArcCurve:co,ArrayCamera:sc,ArrowHelper:class extends yn{constructor(t=new xi(0,0,1),e=new xi(0,0,0),i=1,n=16776960,s=.2*i,r=.2*s){super(),this.type="ArrowHelper",void 0===hd&&(hd=new Ds,hd.setAttribute("position",new vs([0,0,0,0,1,0],3)),cd=new to(.5,1,5,1),cd.translate(0,-.5,0)),this.position.copy(e),this.line=new Ra(hd,new Sa({color:n,toneMapped:!1})),this.line.matrixAutoUpdate=!1,this.add(this.line),this.cone=new xr(cd,new lr({color:n,toneMapped:!1})),this.cone.matrixAutoUpdate=!1,this.add(this.cone),this.setDirection(t),this.setLength(i,s,r)}setDirection(t){if(t.y>.99999)this.quaternion.set(0,0,0,1);else if(t.y<-.99999)this.quaternion.set(1,0,0,0);else{ld.set(t.z,0,-t.x).normalize();const e=Math.acos(t.y);this.quaternion.setFromAxisAngle(ld,e)}}setLength(t,e=.2*t,i=.2*e){this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(i,e,i),this.cone.position.y=t,this.cone.updateMatrix()}setColor(t){this.line.material.color.set(t),this.cone.material.color.set(t)}copy(t){return super.copy(t,!1),this.line.copy(t.line),this.cone.copy(t.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}},AttachedBindMode:j,Audio:dc,AudioAnalyser:class{constructor(t,e=2048){this.analyser=t.context.createAnalyser(),this.analyser.fftSize=e,this.data=new Uint8Array(this.analyser.frequencyBinCount),t.getOutput().connect(this.analyser)}getFrequencyData(){return this.analyser.getByteFrequencyData(this.data),this.data}getAverageFrequency(){let t=0;const e=this.getFrequencyData();for(let i=0;i<e.length;i++)t+=e[i];return t/e.length}},AudioContext:Jh,AudioListener:class extends yn{constructor(){super(),this.type="AudioListener",this.context=Jh.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new rc}getInput(){return this.gain}removeFilter(){return null!==this.filter&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this}getFilter(){return this.filter}setFilter(t){return null!==this.filter?(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)):this.gain.disconnect(this.context.destination),this.filter=t,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}updateMatrixWorld(t){super.updateMatrixWorld(t);const e=this.context.listener;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(ac,oc,lc),hc.set(0,0,-1).applyQuaternion(oc),cc.set(0,1,0).applyQuaternion(oc),e.positionX){const t=this.context.currentTime+this.timeDelta;e.positionX.linearRampToValueAtTime(ac.x,t),e.positionY.linearRampToValueAtTime(ac.y,t),e.positionZ.linearRampToValueAtTime(ac.z,t),e.forwardX.linearRampToValueAtTime(hc.x,t),e.forwardY.linearRampToValueAtTime(hc.y,t),e.forwardZ.linearRampToValueAtTime(hc.z,t),e.upX.linearRampToValueAtTime(cc.x,t),e.upY.linearRampToValueAtTime(cc.y,t),e.upZ.linearRampToValueAtTime(cc.z,t)}else e.setPosition(ac.x,ac.y,ac.z),e.setOrientation(hc.x,hc.y,hc.z,cc.x,cc.y,cc.z)}},AudioLoader:class extends ch{constructor(t){super(t)}load(t,e,i,n){const s=this,r=new ph(this.manager);function a(e){n?n(e):ni(e),s.manager.itemError(t)}r.setResponseType("arraybuffer"),r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,function(t){try{const i=t.slice(0);Jh.getContext().decodeAudioData(i,function(t){e(t)}).catch(a)}catch(t){a(t)}},i,n)}},AxesHelper:class extends Ba{constructor(t=1){const e=[0,0,0,t,0,0,0,0,0,0,t,0,0,0,0,0,0,t],i=new Ds;i.setAttribute("position",new vs(e,3)),i.setAttribute("color",new vs([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],3));super(i,new Sa({vertexColors:!0,toneMapped:!1})),this.type="AxesHelper"}setColors(t,e,i){const n=new En,s=this.geometry.attributes.color.array;return n.set(t),n.toArray(s,0),n.toArray(s,3),n.set(e),n.toArray(s,6),n.toArray(s,9),n.set(i),n.toArray(s,12),n.toArray(s,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}},BackSide:1,BasicDepthPacking:we,BasicShadowMap:0,BatchedMesh:ba,BezierInterpolant:ql,Bone:Ir,BooleanKeyframeTrack:Kl,Box2:class{constructor(t=new yi(1/0,1/0),e=new yi(-1/0,-1/0)){this.isBox2=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=Uc.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=1/0,this.max.x=this.max.y=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y}getCenter(t){return this.isEmpty()?t.set(0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Uc).distanceTo(t)}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}},Box3:jn,Box3Helper:class extends Ba{constructor(t,e=16776960){const i=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),n=new Ds;n.setIndex(new ms(i,1)),n.setAttribute("position",new vs([1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,-1,1,-1,-1],3)),super(n,new Sa({color:e,toneMapped:!1})),this.box=t,this.type="Box3Helper",this.geometry.computeBoundingSphere()}updateMatrixWorld(t){const e=this.box;e.isEmpty()||(e.getCenter(this.position),e.getSize(this.scale),this.scale.multiplyScalar(.5),super.updateMatrixWorld(t))}dispose(){this.geometry.dispose(),this.material.dispose()}},BoxGeometry:Qa,BoxHelper:class extends Ba{constructor(t,e=16776960){const i=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),n=new Float32Array(24),s=new Ds;s.setIndex(new ms(i,1)),s.setAttribute("position",new ms(n,3)),super(s,new Sa({color:e,toneMapped:!1})),this.object=t,this.type="BoxHelper",this.matrixAutoUpdate=!1,this.update()}update(){if(void 0!==this.object&&od.setFromObject(this.object),od.isEmpty())return;const t=od.min,e=od.max,i=this.geometry.attributes.position,n=i.array;n[0]=e.x,n[1]=e.y,n[2]=e.z,n[3]=t.x,n[4]=e.y,n[5]=e.z,n[6]=t.x,n[7]=t.y,n[8]=e.z,n[9]=e.x,n[10]=t.y,n[11]=e.z,n[12]=e.x,n[13]=e.y,n[14]=t.z,n[15]=t.x,n[16]=e.y,n[17]=t.z,n[18]=t.x,n[19]=t.y,n[20]=t.z,n[21]=e.x,n[22]=t.y,n[23]=t.z,i.needsUpdate=!0,this.geometry.computeBoundingSphere()}setFromObject(t){return this.object=t,this.update(),this}copy(t,e){return super.copy(t,e),this.object=t.object,this}dispose(){this.geometry.dispose(),this.material.dispose()}},BufferAttribute:ms,BufferGeometry:Ds,BufferGeometryLoader:Xh,ByteType:ht,Cache:ah,Camera:Th,CameraHelper:class extends Ba{constructor(t){const e=new Ds,i=new Sa({color:16777215,vertexColors:!0,toneMapped:!1}),n=[],s=[],r={};function a(t,e){o(t),o(e)}function o(t){n.push(0,0,0),s.push(0,0,0),void 0===r[t]&&(r[t]=[]),r[t].push(n.length/3-1)}a("n1","n2"),a("n2","n4"),a("n4","n3"),a("n3","n1"),a("f1","f2"),a("f2","f4"),a("f4","f3"),a("f3","f1"),a("n1","f1"),a("n2","f2"),a("n3","f3"),a("n4","f4"),a("p","n1"),a("p","n2"),a("p","n3"),a("p","n4"),a("u1","u2"),a("u2","u3"),a("u3","u1"),a("c","t"),a("p","c"),a("cn1","cn2"),a("cn3","cn4"),a("cf1","cf2"),a("cf3","cf4"),e.setAttribute("position",new vs(n,3)),e.setAttribute("color",new vs(s,3)),super(e,i),this.type="CameraHelper",this.camera=t,this.camera.updateProjectionMatrix&&this.camera.updateProjectionMatrix(),this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=r,this.update();const l=new En(16755200),h=new En(16711680),c=new En(43775),d=new En(16777215),u=new En(3355443);this.setColors(l,h,c,d,u)}setColors(t,e,i,n,s){const r=this.geometry.getAttribute("color");return r.setXYZ(0,t.r,t.g,t.b),r.setXYZ(1,t.r,t.g,t.b),r.setXYZ(2,t.r,t.g,t.b),r.setXYZ(3,t.r,t.g,t.b),r.setXYZ(4,t.r,t.g,t.b),r.setXYZ(5,t.r,t.g,t.b),r.setXYZ(6,t.r,t.g,t.b),r.setXYZ(7,t.r,t.g,t.b),r.setXYZ(8,t.r,t.g,t.b),r.setXYZ(9,t.r,t.g,t.b),r.setXYZ(10,t.r,t.g,t.b),r.setXYZ(11,t.r,t.g,t.b),r.setXYZ(12,t.r,t.g,t.b),r.setXYZ(13,t.r,t.g,t.b),r.setXYZ(14,t.r,t.g,t.b),r.setXYZ(15,t.r,t.g,t.b),r.setXYZ(16,t.r,t.g,t.b),r.setXYZ(17,t.r,t.g,t.b),r.setXYZ(18,t.r,t.g,t.b),r.setXYZ(19,t.r,t.g,t.b),r.setXYZ(20,t.r,t.g,t.b),r.setXYZ(21,t.r,t.g,t.b),r.setXYZ(22,t.r,t.g,t.b),r.setXYZ(23,t.r,t.g,t.b),r.setXYZ(24,e.r,e.g,e.b),r.setXYZ(25,e.r,e.g,e.b),r.setXYZ(26,e.r,e.g,e.b),r.setXYZ(27,e.r,e.g,e.b),r.setXYZ(28,e.r,e.g,e.b),r.setXYZ(29,e.r,e.g,e.b),r.setXYZ(30,e.r,e.g,e.b),r.setXYZ(31,e.r,e.g,e.b),r.setXYZ(32,i.r,i.g,i.b),r.setXYZ(33,i.r,i.g,i.b),r.setXYZ(34,i.r,i.g,i.b),r.setXYZ(35,i.r,i.g,i.b),r.setXYZ(36,i.r,i.g,i.b),r.setXYZ(37,i.r,i.g,i.b),r.setXYZ(38,n.r,n.g,n.b),r.setXYZ(39,n.r,n.g,n.b),r.setXYZ(40,s.r,s.g,s.b),r.setXYZ(41,s.r,s.g,s.b),r.setXYZ(42,s.r,s.g,s.b),r.setXYZ(43,s.r,s.g,s.b),r.setXYZ(44,s.r,s.g,s.b),r.setXYZ(45,s.r,s.g,s.b),r.setXYZ(46,s.r,s.g,s.b),r.setXYZ(47,s.r,s.g,s.b),r.setXYZ(48,s.r,s.g,s.b),r.setXYZ(49,s.r,s.g,s.b),r.needsUpdate=!0,this}update(){const t=this.geometry,e=this.pointMap;let i,n;if(rd.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse),!0===this.camera.reversedDepth)i=1,n=0;else if(this.camera.coordinateSystem===je)i=-1,n=1;else{if(this.camera.coordinateSystem!==Xe)throw new Error("THREE.CameraHelper.update(): Invalid coordinate system: "+this.camera.coordinateSystem);i=0,n=1}ad("c",e,t,rd,0,0,i),ad("t",e,t,rd,0,0,n),ad("n1",e,t,rd,-1,-1,i),ad("n2",e,t,rd,1,-1,i),ad("n3",e,t,rd,-1,1,i),ad("n4",e,t,rd,1,1,i),ad("f1",e,t,rd,-1,-1,n),ad("f2",e,t,rd,1,-1,n),ad("f3",e,t,rd,-1,1,n),ad("f4",e,t,rd,1,1,n),ad("u1",e,t,rd,.7,1.1,i),ad("u2",e,t,rd,-.7,1.1,i),ad("u3",e,t,rd,0,2,i),ad("cf1",e,t,rd,-1,0,n),ad("cf2",e,t,rd,1,0,n),ad("cf3",e,t,rd,0,-1,n),ad("cf4",e,t,rd,0,1,n),ad("cn1",e,t,rd,-1,0,i),ad("cn2",e,t,rd,1,0,i),ad("cn3",e,t,rd,0,-1,i),ad("cn4",e,t,rd,0,1,i),t.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}},CanvasTexture:Xa,CapsuleGeometry:Ka,CatmullRomCurve3:vo,CineonToneMapping:3,CircleGeometry:Ja,ClampToEdgeWrapping:tt,Clock:rc,Color:En,ColorKeyframeTrack:Jl,ColorManagement:Ci,Compatibility:{TEXTURE_COMPARE:"depthTextureCompare"},CompressedArrayTexture:class extends Wa{constructor(t,e,i,n,s,r){super(t,e,i,s,r),this.isCompressedArrayTexture=!0,this.image.depth=n,this.wrapR=tt,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}},CompressedCubeTexture:class extends Wa{constructor(t,e,i){super(void 0,t[0].width,t[0].height,e,i,Z),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=t}},CompressedTexture:Wa,CompressedTextureLoader:class extends ch{constructor(t){super(t)}load(t,e,i,n){const s=this,r=[],a=new Wa,o=new ph(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(s.withCredentials);let l=0;function h(h){o.load(t[h],function(t){const i=s.parse(t,!0);r[h]={width:i.width,height:i.height,format:i.format,mipmaps:i.mipmaps},l+=1,6===l&&(1===i.mipmapCount&&(a.minFilter=rt),a.image=r,a.format=i.format,a.needsUpdate=!0,e&&e(a))},i,n)}if(Array.isArray(t))for(let e=0,i=t.length;e<i;++e)h(e);else o.load(t,function(t){const i=s.parse(t,!0);if(i.isCubemap){const t=i.mipmaps.length/i.mipmapCount;for(let e=0;e<t;e++){r[e]={mipmaps:[]};for(let t=0;t<i.mipmapCount;t++)r[e].mipmaps.push(i.mipmaps[e*i.mipmapCount+t]),r[e].format=i.format,r[e].width=i.width,r[e].height=i.height}a.image=r}else a.image.width=i.width,a.image.height=i.height,a.mipmaps=i.mipmaps;1===i.mipmapCount&&(a.minFilter=rt),a.format=i.format,a.needsUpdate=!0,e&&e(a)},i,n);return a}},ConeGeometry:to,ConstantAlphaFactor:213,ConstantColorFactor:211,Controls:ud,CubeCamera:nc,CubeDepthTexture:Za,CubeReflectionMapping:Z,CubeRefractionMapping:q,CubeTexture:ja,CubeTextureLoader:class extends ch{constructor(t){super(t)}load(t,e,i,n){const s=new ja;s.colorSpace=Ee;const r=new fh(this.manager);r.setCrossOrigin(this.crossOrigin),r.setPath(this.path);let a=0;function o(i){r.load(t[i],function(t){s.images[i]=t,a++,6===a&&(s.needsUpdate=!0,e&&e(s))},void 0,n)}for(let e=0;e<t.length;++e)o(e);return s}},CubeUVReflectionMapping:J,CubicBezierCurve:bo,CubicBezierCurve3:So,CubicInterpolant:Xl,CullFaceBack:1,CullFaceFront:2,CullFaceFrontBack:3,CullFaceNone:0,Curve:lo,CurvePath:Do,CustomBlending:5,CustomToneMapping:5,CylinderGeometry:$a,Cylindrical:class{constructor(t=1,e=0,i=0){this.radius=t,this.theta=e,this.y=i}set(t,e,i){return this.radius=t,this.theta=e,this.y=i,this}copy(t){return this.radius=t.radius,this.theta=t.theta,this.y=t.y,this}setFromVector3(t){return this.setFromCartesianCoords(t.x,t.y,t.z)}setFromCartesianCoords(t,e,i){return this.radius=Math.sqrt(t*t+i*i),this.theta=Math.atan2(t,i),this.y=e,this}clone(){return(new this.constructor).copy(this)}},Data3DTexture:Vi,DataArrayTexture:Hi,DataTexture:Lr,DataTextureLoader:gh,DataUtils:cs,DecrementStencilOp:7683,DecrementWrapStencilOp:Le,DefaultLoadingManager:hh,DepthFormat:wt,DepthStencilFormat:At,DepthTexture:Ya,DetachedBindMode:X,DirectionalLight:Uh,DirectionalLightHelper:class extends yn{constructor(t,e,i){super(),this.light=t,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.color=i,this.type="DirectionalLightHelper",void 0===e&&(e=1);let n=new Ds;n.setAttribute("position",new vs([-e,e,0,e,e,0,e,-e,0,-e,-e,0,-e,e,0],3));const s=new Sa({fog:!1,toneMapped:!1});this.lightPlane=new Ra(n,s),this.add(this.lightPlane),n=new Ds,n.setAttribute("position",new vs([0,0,0,0,0,1],3)),this.targetLine=new Ra(n,s),this.add(this.targetLine),this.update()}dispose(){this.lightPlane.geometry.dispose(),this.lightPlane.material.dispose(),this.targetLine.geometry.dispose(),this.targetLine.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),this.light.target.updateWorldMatrix(!0,!1),ed.setFromMatrixPosition(this.light.matrixWorld),id.setFromMatrixPosition(this.light.target.matrixWorld),nd.subVectors(id,ed),this.lightPlane.lookAt(id),void 0!==this.color?(this.lightPlane.material.color.set(this.color),this.targetLine.material.color.set(this.color)):(this.lightPlane.material.color.copy(this.light.color),this.targetLine.material.color.copy(this.light.color)),this.targetLine.lookAt(id),this.targetLine.scale.z=nd.length()}},DiscreteInterpolant:Zl,DodecahedronGeometry:io,DoubleSide:2,DstAlphaFactor:206,DstColorFactor:208,DynamicCopyUsage:35050,DynamicDrawUsage:35048,DynamicReadUsage:35049,EdgesGeometry:oo,EllipseCurve:ho,EqualCompare:514,EqualDepth:4,EqualStencilFunc:514,EquirectangularReflectionMapping:Q,EquirectangularRefractionMapping:K,Euler:tn,EventDispatcher:ai,ExternalTexture:qa,ExtrudeGeometry:ll,FileLoader:ph,Float16BufferAttribute:class extends ms{constructor(t,e,i){super(new Uint16Array(t),e,i),this.isFloat16BufferAttribute=!0}getX(t){let e=hs(this.array[t*this.itemSize]);return this.normalized&&(e=fi(e,this.array)),e}setX(t,e){return this.normalized&&(e=gi(e,this.array)),this.array[t*this.itemSize]=ls(e),this}getY(t){let e=hs(this.array[t*this.itemSize+1]);return this.normalized&&(e=fi(e,this.array)),e}setY(t,e){return this.normalized&&(e=gi(e,this.array)),this.array[t*this.itemSize+1]=ls(e),this}getZ(t){let e=hs(this.array[t*this.itemSize+2]);return this.normalized&&(e=fi(e,this.array)),e}setZ(t,e){return this.normalized&&(e=gi(e,this.array)),this.array[t*this.itemSize+2]=ls(e),this}getW(t){let e=hs(this.array[t*this.itemSize+3]);return this.normalized&&(e=fi(e,this.array)),e}setW(t,e){return this.normalized&&(e=gi(e,this.array)),this.array[t*this.itemSize+3]=ls(e),this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=gi(e,this.array),i=gi(i,this.array)),this.array[t+0]=ls(e),this.array[t+1]=ls(i),this}setXYZ(t,e,i,n){return t*=this.itemSize,this.normalized&&(e=gi(e,this.array),i=gi(i,this.array),n=gi(n,this.array)),this.array[t+0]=ls(e),this.array[t+1]=ls(i),this.array[t+2]=ls(n),this}setXYZW(t,e,i,n,s){return t*=this.itemSize,this.normalized&&(e=gi(e,this.array),i=gi(i,this.array),n=gi(n,this.array),s=gi(s,this.array)),this.array[t+0]=ls(e),this.array[t+1]=ls(i),this.array[t+2]=ls(n),this.array[t+3]=ls(s),this}},Float32BufferAttribute:vs,FloatType:mt,Fog:Dn,FogExp2:Cn,FramebufferTexture:class extends Ui{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=it,this.minFilter=it,this.generateMipmaps=!1,this.needsUpdate=!0}},FrontSide:0,Frustum:$r,FrustumArray:ia,GLBufferAttribute:class{constructor(t,e,i,n,s,r=!1){this.isGLBufferAttribute=!0,this.name="",this.buffer=t,this.type=e,this.itemSize=i,this.elementSize=n,this.count=s,this.normalized=r,this.version=0}set needsUpdate(t){!0===t&&this.version++}setBuffer(t){return this.buffer=t,this}setType(t,e){return this.type=t,this.elementSize=e,this}setItemSize(t){return this.itemSize=t,this}setCount(t){return this.count=t,this}},GLSL1:"100",GLSL3:We,GreaterCompare:516,GreaterDepth:6,GreaterEqualCompare:Ge,GreaterEqualDepth:5,GreaterEqualStencilFunc:518,GreaterStencilFunc:516,GridHelper:class extends Ba{constructor(t=10,e=10,i=4473924,n=8947848){i=new En(i),n=new En(n);const s=e/2,r=t/e,a=t/2,o=[],l=[];for(let t=0,h=0,c=-a;t<=e;t++,c+=r){o.push(-a,0,c,a,0,c),o.push(c,0,-a,c,0,a);const e=t===s?i:n;e.toArray(l,h),h+=3,e.toArray(l,h),h+=3,e.toArray(l,h),h+=3,e.toArray(l,h),h+=3}const h=new Ds;h.setAttribute("position",new vs(o,3)),h.setAttribute("color",new vs(l,3));super(h,new Sa({vertexColors:!0,toneMapped:!1})),this.type="GridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}},Group:_n,HalfFloatType:ft,HemisphereLight:_h,HemisphereLightHelper:class extends yn{constructor(t,e,i){super(),this.light=t,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.color=i,this.type="HemisphereLightHelper";const n=new ul(e);n.rotateY(.5*Math.PI),this.material=new lr({wireframe:!0,fog:!1,toneMapped:!1}),void 0===this.color&&(this.material.vertexColors=!0);const s=n.getAttribute("position"),r=new Float32Array(3*s.count);n.setAttribute("color",new ms(r,3)),this.add(new xr(n,this.material)),this.update()}dispose(){this.children[0].geometry.dispose(),this.children[0].material.dispose()}update(){const t=this.children[0];if(void 0!==this.color)this.material.color.set(this.color);else{const e=t.geometry.getAttribute("color");$c.copy(this.light.color),td.copy(this.light.groundColor);for(let t=0,i=e.count;t<i;t++){const n=t<i/2?$c:td;e.setXYZ(t,n.r,n.g,n.b)}e.needsUpdate=!0}this.light.updateWorldMatrix(!0,!1),t.lookAt(Jc.setFromMatrixPosition(this.light.matrixWorld).negate())}},IcosahedronGeometry:cl,ImageBitmapLoader:class extends ch{constructor(t){super(t),this.isImageBitmapLoader=!0,"undefined"==typeof createImageBitmap&&ii("ImageBitmapLoader: createImageBitmap() not supported."),"undefined"==typeof fetch&&ii("ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"},this._abortController=new AbortController}setOptions(t){return this.options=t,this}load(t,e,i,n){void 0===t&&(t=""),void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const s=this,r=ah.get(`image-bitmap:${t}`);if(void 0!==r)return s.manager.itemStart(t),r.then?void r.then(i=>{if(!0!==Qh.has(r))return e&&e(i),s.manager.itemEnd(t),i;n&&n(Qh.get(r)),s.manager.itemError(t),s.manager.itemEnd(t)}):(setTimeout(function(){e&&e(r),s.manager.itemEnd(t)},0),r);const a={};a.credentials="anonymous"===this.crossOrigin?"same-origin":"include",a.headers=this.requestHeader,a.signal="function"==typeof AbortSignal.any?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal;const o=fetch(t,a).then(function(t){return t.blob()}).then(function(t){return createImageBitmap(t,Object.assign(s.options,{colorSpaceConversion:"none"}))}).then(function(i){return ah.add(`image-bitmap:${t}`,i),e&&e(i),s.manager.itemEnd(t),i}).catch(function(e){n&&n(e),Qh.set(o,e),ah.remove(`image-bitmap:${t}`),s.manager.itemError(t),s.manager.itemEnd(t)});ah.add(`image-bitmap:${t}`,o),s.manager.itemStart(t)}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}},ImageLoader:fh,ImageUtils:Ii,IncrementStencilOp:7682,IncrementWrapStencilOp:Ie,InstancedBufferAttribute:Nr,InstancedBufferGeometry:jh,InstancedInterleavedBuffer:Dc,InstancedMesh:jr,Int16BufferAttribute:class extends ms{constructor(t,e,i){super(new Int16Array(t),e,i)}},Int32BufferAttribute:class extends ms{constructor(t,e,i){super(new Int32Array(t),e,i)}},Int8BufferAttribute:class extends ms{constructor(t,e,i){super(new Int8Array(t),e,i)}},IntType:ut,InterleavedBuffer:Rs,InterleavedBufferAttribute:Is,Interpolant:jl,InterpolateBezier:ye,InterpolateDiscrete:fe,InterpolateLinear:ge,InterpolateSmooth:ve,InterpolationSamplingMode:{NORMAL:"normal",CENTROID:"centroid",SAMPLE:"sample",FIRST:"first",EITHER:"either"},InterpolationSamplingType:{PERSPECTIVE:"perspective",LINEAR:"linear",FLAT:"flat"},InvertStencilOp:5386,KeepStencilOp:Re,KeyframeTrack:Ql,LOD:$s,LatheGeometry:dl,Layers:en,LessCompare:513,LessDepth:2,LessEqualCompare:Ue,LessEqualDepth:3,LessEqualStencilFunc:515,LessStencilFunc:513,Light:yh,LightProbe:Hh,Line:Ra,Line3:Xc,LineBasicMaterial:Sa,LineCurve:Mo,LineCurve3:wo,LineDashedMaterial:zl,LineLoop:Oa,LineSegments:Ba,LinearFilter:rt,LinearInterpolant:Yl,LinearMipMapLinearFilter:1008,LinearMipMapNearestFilter:1007,LinearMipmapLinearFilter:ot,LinearMipmapNearestFilter:at,LinearSRGBColorSpace:Te,LinearToneMapping:1,LinearTransfer:Ce,Loader:ch,LoaderUtils:Wh,LoadingManager:lh,LoopOnce:2200,LoopPingPong:me,LoopRepeat:pe,MOUSE:i,Material:Os,MaterialBlending:6,MaterialLoader:Vh,MathUtils:vi,Matrix2:Nc,Matrix3:Mi,Matrix4:Wi,MaxEquation:104,Mesh:xr,MeshBasicMaterial:lr,MeshDepthMaterial:Nl,MeshDistanceMaterial:Ul,MeshLambertMaterial:Fl,MeshMatcapMaterial:kl,MeshNormalMaterial:Ol,MeshPhongMaterial:Ll,MeshPhysicalMaterial:Il,MeshStandardMaterial:Pl,MeshToonMaterial:Bl,MinEquation:103,MirroredRepeatWrapping:et,MixOperation:1,MultiplyBlending:4,MultiplyOperation:0,NearestFilter:it,NearestMipMapLinearFilter:1005,NearestMipMapNearestFilter:1004,NearestMipmapLinearFilter:st,NearestMipmapNearestFilter:nt,NeutralToneMapping:7,NeverCompare:512,NeverDepth:0,NeverStencilFunc:512,NoBlending:0,NoColorSpace:Ae,NoNormalPacking:"",NoToneMapping:0,NormalAnimationBlendMode:Se,NormalBlending:1,NormalGAPacking:"ga",NormalRGPacking:"rg",NotEqualCompare:517,NotEqualDepth:7,NotEqualStencilFunc:517,NumberKeyframeTrack:$l,Object3D:yn,ObjectLoader:class extends ch{constructor(t){super(t)}load(t,e,i,n){const s=this,r=""===this.path?Wh.extractUrlBase(t):this.path;this.resourcePath=this.resourcePath||r;const a=new ph(this.manager);a.setPath(this.path),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(t,function(i){let r=null;try{r=JSON.parse(i)}catch(e){return void 0!==n&&n(e),void e("ObjectLoader: Can't parse "+t+".",e.message)}const a=r.metadata;if(void 0===a||void 0===a.type||"geometry"===a.type.toLowerCase())return void 0!==n&&n(new Error("THREE.ObjectLoader: Can't load "+t)),void ni("ObjectLoader: Can't load "+t);s.parse(r,e)},i,n)}async loadAsync(t,e){const i=""===this.path?Wh.extractUrlBase(t):this.path;this.resourcePath=this.resourcePath||i;const n=new ph(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials);const s=await n.loadAsync(t,e);let r;try{r=JSON.parse(s)}catch(e){throw new Error("ObjectLoader: Can't parse "+t+". "+e.message)}const a=r.metadata;if(void 0===a||void 0===a.type||"geometry"===a.type.toLowerCase())throw new Error("THREE.ObjectLoader: Can't load "+t);return await this.parseAsync(r)}parse(t,e){const i=this.parseAnimations(t.animations),n=this.parseShapes(t.shapes),s=this.parseGeometries(t.geometries,n),r=this.parseImages(t.images,function(){void 0!==e&&e(l)}),a=this.parseTextures(t.textures,r),o=this.parseMaterials(t.materials,a),l=this.parseObject(t.object,s,o,a,i),h=this.parseSkeletons(t.skeletons,l);if(this.bindSkeletons(l,h),this.bindLightTargets(l),void 0!==e){let t=!1;for(const e in r)if(r[e].data instanceof HTMLImageElement){t=!0;break}!1===t&&e(l)}return l}async parseAsync(t){const e=this.parseAnimations(t.animations),i=this.parseShapes(t.shapes),n=this.parseGeometries(t.geometries,i),s=await this.parseImagesAsync(t.images),r=this.parseTextures(t.textures,s),a=this.parseMaterials(t.materials,r),o=this.parseObject(t.object,n,a,r,e),l=this.parseSkeletons(t.skeletons,o);return this.bindSkeletons(o,l),this.bindLightTargets(o),o}parseShapes(t){const e={};if(void 0!==t)for(let i=0,n=t.length;i<n;i++){const n=(new Po).fromJSON(t[i]);e[n.uuid]=n}return e}parseSkeletons(t,e){const i={},n={};if(e.traverse(function(t){t.isBone&&(n[t.uuid]=t)}),void 0!==t)for(let e=0,s=t.length;e<s;e++){const s=(new Fr).fromJSON(t[e],n);i[s.uuid]=s}return i}parseGeometries(t,e){const i={};if(void 0!==t){const n=new Xh;for(let s=0,r=t.length;s<r;s++){let r;const a=t[s];switch(a.type){case"BufferGeometry":case"InstancedBufferGeometry":r=n.parse(a);break;default:a.type in Ml?r=Ml[a.type].fromJSON(a,e):ii(`ObjectLoader: Unsupported geometry type "${a.type}"`)}r.uuid=a.uuid,void 0!==a.name&&(r.name=a.name),void 0!==a.userData&&(r.userData=a.userData),i[a.uuid]=r}}return i}parseMaterials(t,e){const i={},n={};if(void 0!==t){const s=new Vh;s.setTextures(e);for(let e=0,r=t.length;e<r;e++){const r=t[e];void 0===i[r.uuid]&&(i[r.uuid]=s.parse(r)),n[r.uuid]=i[r.uuid]}}return n}parseAnimations(t){const e={};if(void 0!==t)for(let i=0;i<t.length;i++){const n=t[i],s=sh.parse(n);e[s.uuid]=s}return e}parseImages(t,e){const i=this,n={};let s;function r(t){if("string"==typeof t){const e=t;return function(t){return i.manager.itemStart(t),s.load(t,function(){i.manager.itemEnd(t)},void 0,function(){i.manager.itemError(t),i.manager.itemEnd(t)})}(/^(\/\/)|([a-z]+:(\/\/)?)/i.test(e)?e:i.resourcePath+e)}return t.data?{data:Ze(t.type,t.data),width:t.width,height:t.height}:null}if(void 0!==t&&t.length>0){const i=new lh(e);s=new fh(i),s.setCrossOrigin(this.crossOrigin);for(let e=0,i=t.length;e<i;e++){const i=t[e],s=i.url;if(Array.isArray(s)){const t=[];for(let e=0,i=s.length;e<i;e++){const i=r(s[e]);null!==i&&(i instanceof HTMLImageElement?t.push(i):t.push(new Lr(i.data,i.width,i.height)))}n[i.uuid]=new Bi(t)}else{const t=r(i.url);n[i.uuid]=new Bi(t)}}}return n}async parseImagesAsync(t){const e=this,i={};let n;async function s(t){if("string"==typeof t){const i=t,s=/^(\/\/)|([a-z]+:(\/\/)?)/i.test(i)?i:e.resourcePath+i;return await n.loadAsync(s)}return t.data?{data:Ze(t.type,t.data),width:t.width,height:t.height}:null}if(void 0!==t&&t.length>0){n=new fh(this.manager),n.setCrossOrigin(this.crossOrigin);for(let e=0,n=t.length;e<n;e++){const n=t[e],r=n.url;if(Array.isArray(r)){const t=[];for(let e=0,i=r.length;e<i;e++){const i=r[e],n=await s(i);null!==n&&(n instanceof HTMLImageElement?t.push(n):t.push(new Lr(n.data,n.width,n.height)))}i[n.uuid]=new Bi(t)}else{const t=await s(n.url);i[n.uuid]=new Bi(t)}}}return i}parseTextures(t,e){function i(t,e){return"number"==typeof t?t:(ii("ObjectLoader.parseTexture: Constant should be in numeric form.",t),e[t])}const n={};if(void 0!==t)for(let s=0,r=t.length;s<r;s++){const r=t[s];void 0===r.image&&ii('ObjectLoader: No "image" specified for',r.uuid),void 0===e[r.image]&&ii("ObjectLoader: Undefined image",r.image);const a=e[r.image],o=a.data;let l;Array.isArray(o)?(l=new ja,6===o.length&&(l.needsUpdate=!0)):(l=o&&o.data?new Lr:new Ui,o&&(l.needsUpdate=!0)),l.source=a,l.uuid=r.uuid,void 0!==r.name&&(l.name=r.name),void 0!==r.mapping&&(l.mapping=i(r.mapping,Yh)),void 0!==r.channel&&(l.channel=r.channel),void 0!==r.offset&&l.offset.fromArray(r.offset),void 0!==r.repeat&&l.repeat.fromArray(r.repeat),void 0!==r.center&&l.center.fromArray(r.center),void 0!==r.rotation&&(l.rotation=r.rotation),void 0!==r.wrap&&(l.wrapS=i(r.wrap[0],Zh),l.wrapT=i(r.wrap[1],Zh)),void 0!==r.format&&(l.format=r.format),void 0!==r.internalFormat&&(l.internalFormat=r.internalFormat),void 0!==r.type&&(l.type=r.type),void 0!==r.colorSpace&&(l.colorSpace=r.colorSpace),void 0!==r.minFilter&&(l.minFilter=i(r.minFilter,qh)),void 0!==r.magFilter&&(l.magFilter=i(r.magFilter,qh)),void 0!==r.anisotropy&&(l.anisotropy=r.anisotropy),void 0!==r.flipY&&(l.flipY=r.flipY),void 0!==r.generateMipmaps&&(l.generateMipmaps=r.generateMipmaps),void 0!==r.premultiplyAlpha&&(l.premultiplyAlpha=r.premultiplyAlpha),void 0!==r.unpackAlignment&&(l.unpackAlignment=r.unpackAlignment),void 0!==r.compareFunction&&(l.compareFunction=r.compareFunction),void 0!==r.userData&&(l.userData=r.userData),n[r.uuid]=l}return n}parseObject(t,e,i,n,s){let r,a,o;function l(t){return void 0===e[t]&&ii("ObjectLoader: Undefined geometry",t),e[t]}function h(t){if(void 0!==t){if(Array.isArray(t)){const e=[];for(let n=0,s=t.length;n<s;n++){const s=t[n];void 0===i[s]&&ii("ObjectLoader: Undefined material",s),e.push(i[s])}return e}return void 0===i[t]&&ii("ObjectLoader: Undefined material",t),i[t]}}function c(t){return void 0===n[t]&&ii("ObjectLoader: Undefined texture",t),n[t]}switch(t.type){case"Scene":r=new Rn,void 0!==t.background&&(Number.isInteger(t.background)?r.background=new En(t.background):r.background=c(t.background)),void 0!==t.environment&&(r.environment=c(t.environment)),void 0!==t.fog&&("Fog"===t.fog.type?r.fog=new Dn(t.fog.color,t.fog.near,t.fog.far):"FogExp2"===t.fog.type&&(r.fog=new Cn(t.fog.color,t.fog.density)),""!==t.fog.name&&(r.fog.name=t.fog.name)),void 0!==t.backgroundBlurriness&&(r.backgroundBlurriness=t.backgroundBlurriness),void 0!==t.backgroundIntensity&&(r.backgroundIntensity=t.backgroundIntensity),void 0!==t.backgroundRotation&&r.backgroundRotation.fromArray(t.backgroundRotation),void 0!==t.environmentIntensity&&(r.environmentIntensity=t.environmentIntensity),void 0!==t.environmentRotation&&r.environmentRotation.fromArray(t.environmentRotation);break;case"PerspectiveCamera":r=new Ph(t.fov,t.aspect,t.near,t.far),void 0!==t.focus&&(r.focus=t.focus),void 0!==t.zoom&&(r.zoom=t.zoom),void 0!==t.filmGauge&&(r.filmGauge=t.filmGauge),void 0!==t.filmOffset&&(r.filmOffset=t.filmOffset),void 0!==t.view&&(r.view=Object.assign({},t.view));break;case"OrthographicCamera":r=new Fh(t.left,t.right,t.top,t.bottom,t.near,t.far),void 0!==t.zoom&&(r.zoom=t.zoom),void 0!==t.view&&(r.view=Object.assign({},t.view));break;case"AmbientLight":r=new kh(t.color,t.intensity);break;case"DirectionalLight":r=new Uh(t.color,t.intensity),r.target=t.target||"";break;case"PointLight":r=new Oh(t.color,t.intensity,t.distance,t.decay);break;case"RectAreaLight":r=new zh(t.color,t.intensity,t.width,t.height);break;case"SpotLight":r=new Lh(t.color,t.intensity,t.distance,t.angle,t.penumbra,t.decay),r.target=t.target||"";break;case"HemisphereLight":r=new _h(t.color,t.groundColor,t.intensity);break;case"LightProbe":const e=(new Gh).fromArray(t.sh);r=new Hh(e,t.intensity);break;case"SkinnedMesh":a=l(t.geometry),o=h(t.material),r=new Pr(a,o),void 0!==t.bindMode&&(r.bindMode=t.bindMode),void 0!==t.bindMatrix&&r.bindMatrix.fromArray(t.bindMatrix),void 0!==t.skeleton&&(r.skeleton=t.skeleton);break;case"Mesh":a=l(t.geometry),o=h(t.material),r=new xr(a,o);break;case"InstancedMesh":a=l(t.geometry),o=h(t.material);const i=t.count,n=t.instanceMatrix,s=t.instanceColor;r=new jr(a,o,i),r.instanceMatrix=new Nr(new Float32Array(n.array),16),void 0!==s&&(r.instanceColor=new Nr(new Float32Array(s.array),s.itemSize));break;case"BatchedMesh":a=l(t.geometry),o=h(t.material),r=new ba(t.maxInstanceCount,t.maxVertexCount,t.maxIndexCount,o),r.geometry=a,r.perObjectFrustumCulled=t.perObjectFrustumCulled,r.sortObjects=t.sortObjects,r._drawRanges=t.drawRanges,r._reservedRanges=t.reservedRanges,r._geometryInfo=t.geometryInfo.map(t=>{let e=null,i=null;return void 0!==t.boundingBox&&(e=(new jn).fromJSON(t.boundingBox)),void 0!==t.boundingSphere&&(i=(new bs).fromJSON(t.boundingSphere)),{...t,boundingBox:e,boundingSphere:i}}),r._instanceInfo=t.instanceInfo,r._availableInstanceIds=t._availableInstanceIds,r._availableGeometryIds=t._availableGeometryIds,r._nextIndexStart=t.nextIndexStart,r._nextVertexStart=t.nextVertexStart,r._geometryCount=t.geometryCount,r._maxInstanceCount=t.maxInstanceCount,r._maxVertexCount=t.maxVertexCount,r._maxIndexCount=t.maxIndexCount,r._geometryInitialized=t.geometryInitialized,r._matricesTexture=c(t.matricesTexture.uuid),r._indirectTexture=c(t.indirectTexture.uuid),void 0!==t.colorsTexture&&(r._colorsTexture=c(t.colorsTexture.uuid)),void 0!==t.boundingSphere&&(r.boundingSphere=(new bs).fromJSON(t.boundingSphere)),void 0!==t.boundingBox&&(r.boundingBox=(new jn).fromJSON(t.boundingBox));break;case"LOD":r=new $s;break;case"Line":r=new Ra(l(t.geometry),h(t.material));break;case"LineLoop":r=new Oa(l(t.geometry),h(t.material));break;case"LineSegments":r=new Ba(l(t.geometry),h(t.material));break;case"PointCloud":case"Points":r=new Ga(l(t.geometry),h(t.material));break;case"Sprite":r=new qs(h(t.material));break;case"Group":r=new _n;break;case"Bone":r=new Ir;break;default:r=new yn}if(r.uuid=t.uuid,void 0!==t.name&&(r.name=t.name),void 0!==t.matrix?(r.matrix.fromArray(t.matrix),void 0!==t.matrixAutoUpdate&&(r.matrixAutoUpdate=t.matrixAutoUpdate),r.matrixAutoUpdate&&r.matrix.decompose(r.position,r.quaternion,r.scale)):(void 0!==t.position&&r.position.fromArray(t.position),void 0!==t.rotation&&r.rotation.fromArray(t.rotation),void 0!==t.quaternion&&r.quaternion.fromArray(t.quaternion),void 0!==t.scale&&r.scale.fromArray(t.scale)),void 0!==t.up&&r.up.fromArray(t.up),void 0!==t.pivot&&(r.pivot=(new xi).fromArray(t.pivot)),void 0!==t.morphTargetDictionary&&(r.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),void 0!==t.morphTargetInfluences&&(r.morphTargetInfluences=t.morphTargetInfluences.slice()),void 0!==t.castShadow&&(r.castShadow=t.castShadow),void 0!==t.receiveShadow&&(r.receiveShadow=t.receiveShadow),t.shadow&&(void 0!==t.shadow.intensity&&(r.shadow.intensity=t.shadow.intensity),void 0!==t.shadow.bias&&(r.shadow.bias=t.shadow.bias),void 0!==t.shadow.normalBias&&(r.shadow.normalBias=t.shadow.normalBias),void 0!==t.shadow.radius&&(r.shadow.radius=t.shadow.radius),void 0!==t.shadow.mapSize&&r.shadow.mapSize.fromArray(t.shadow.mapSize),void 0!==t.shadow.camera&&(r.shadow.camera=this.parseObject(t.shadow.camera))),void 0!==t.visible&&(r.visible=t.visible),void 0!==t.frustumCulled&&(r.frustumCulled=t.frustumCulled),void 0!==t.renderOrder&&(r.renderOrder=t.renderOrder),void 0!==t.static&&(r.static=t.static),void 0!==t.userData&&(r.userData=t.userData),void 0!==t.layers&&(r.layers.mask=t.layers),void 0!==t.children){const a=t.children;for(let t=0;t<a.length;t++)r.add(this.parseObject(a[t],e,i,n,s))}if(void 0!==t.animations){const e=t.animations;for(let t=0;t<e.length;t++){const i=e[t];r.animations.push(s[i])}}if("LOD"===t.type){void 0!==t.autoUpdate&&(r.autoUpdate=t.autoUpdate);const e=t.levels;for(let t=0;t<e.length;t++){const i=e[t],n=r.getObjectByProperty("uuid",i.object);void 0!==n&&r.addLevel(n,i.distance,i.hysteresis)}}return r}bindSkeletons(t,e){0!==Object.keys(e).length&&t.traverse(function(t){if(!0===t.isSkinnedMesh&&void 0!==t.skeleton){const i=e[t.skeleton];void 0===i?ii("ObjectLoader: No skeleton found with UUID:",t.skeleton):t.bind(i,t.bindMatrix)}})}bindLightTargets(t){t.traverse(function(e){if(e.isDirectionalLight||e.isSpotLight){const i=e.target,n=t.getObjectByProperty("uuid",i);e.target=void 0!==n?n:new yn}})}},ObjectSpaceNormalMap:1,OctahedronGeometry:ul,OneFactor:201,OneMinusConstantAlphaFactor:214,OneMinusConstantColorFactor:212,OneMinusDstAlphaFactor:207,OneMinusDstColorFactor:209,OneMinusSrcAlphaFactor:v,OneMinusSrcColorFactor:203,OrthographicCamera:Fh,PCFShadowMap:1,PCFSoftShadowMap:2,PMREMGenerator:Fd,Path:Ro,PerspectiveCamera:Ph,Plane:qr,PlaneGeometry:pl,PlaneHelper:class extends Ra{constructor(t,e=1,i=16776960){const n=i,s=new Ds;s.setAttribute("position",new vs([1,-1,0,-1,1,0,-1,-1,0,1,1,0,-1,1,0,-1,-1,0,1,-1,0,1,1,0],3)),s.computeBoundingSphere(),super(s,new Sa({color:n,toneMapped:!1})),this.type="PlaneHelper",this.plane=t,this.size=e;const r=new Ds;r.setAttribute("position",new vs([1,1,0,-1,1,0,-1,-1,0,1,1,0,-1,-1,0,1,-1,0],3)),r.computeBoundingSphere(),this.add(new xr(r,new lr({color:n,opacity:.2,transparent:!0,depthWrite:!1,toneMapped:!1})))}updateMatrixWorld(t){this.position.set(0,0,0),this.scale.set(.5*this.size,.5*this.size,1),this.lookAt(this.plane.normal),this.translateZ(-this.plane.constant),super.updateMatrixWorld(t)}dispose(){this.geometry.dispose(),this.material.dispose(),this.children[0].geometry.dispose(),this.children[0].material.dispose()}},PointLight:Oh,PointLightHelper:class extends xr{constructor(t,e,i){super(new gl(e,4,2),new lr({wireframe:!0,fog:!1,toneMapped:!1})),this.light=t,this.color=i,this.type="PointLightHelper",this.matrix=this.light.matrixWorld,this.matrixAutoUpdate=!1,this.update()}dispose(){this.geometry.dispose(),this.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),void 0!==this.color?this.material.color.set(this.color):this.material.color.copy(this.light.color)}},Points:Ga,PointsMaterial:Fa,PolarGridHelper:class extends Ba{constructor(t=10,e=16,i=8,n=64,s=4473924,r=8947848){s=new En(s),r=new En(r);const a=[],o=[];if(e>1)for(let i=0;i<e;i++){const n=i/e*(2*Math.PI),l=Math.sin(n)*t,h=Math.cos(n)*t;a.push(0,0,0),a.push(l,0,h);const c=1&i?s:r;o.push(c.r,c.g,c.b),o.push(c.r,c.g,c.b)}for(let e=0;e<i;e++){const l=1&e?s:r,h=t-t/i*e;for(let t=0;t<n;t++){let e=t/n*(2*Math.PI),i=Math.sin(e)*h,s=Math.cos(e)*h;a.push(i,0,s),o.push(l.r,l.g,l.b),e=(t+1)/n*(2*Math.PI),i=Math.sin(e)*h,s=Math.cos(e)*h,a.push(i,0,s),o.push(l.r,l.g,l.b)}}const l=new Ds;l.setAttribute("position",new vs(a,3)),l.setAttribute("color",new vs(o,3));super(l,new Sa({vertexColors:!0,toneMapped:!1})),this.type="PolarGridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}},PolyhedronGeometry:eo,PositionalAudio:class extends dc{constructor(t){super(t),this.panner=this.context.createPanner(),this.panner.panningModel="HRTF",this.panner.connect(this.gain)}connect(){return super.connect(),this.panner.connect(this.gain),this}disconnect(){return super.disconnect(),this.panner.disconnect(this.gain),this}getOutput(){return this.panner}getRefDistance(){return this.panner.refDistance}setRefDistance(t){return this.panner.refDistance=t,this}getRolloffFactor(){return this.panner.rolloffFactor}setRolloffFactor(t){return this.panner.rolloffFactor=t,this}getDistanceModel(){return this.panner.distanceModel}setDistanceModel(t){return this.panner.distanceModel=t,this}getMaxDistance(){return this.panner.maxDistance}setMaxDistance(t){return this.panner.maxDistance=t,this}setDirectionalCone(t,e,i){return this.panner.coneInnerAngle=t,this.panner.coneOuterAngle=e,this.panner.coneOuterGain=i,this}updateMatrixWorld(t){if(super.updateMatrixWorld(t),!0===this.hasPlaybackControl&&!1===this.isPlaying)return;this.matrixWorld.decompose(uc,pc,mc),fc.set(0,0,1).applyQuaternion(pc);const e=this.panner;if(e.positionX){const t=this.context.currentTime+this.listener.timeDelta;e.positionX.linearRampToValueAtTime(uc.x,t),e.positionY.linearRampToValueAtTime(uc.y,t),e.positionZ.linearRampToValueAtTime(uc.z,t),e.orientationX.linearRampToValueAtTime(fc.x,t),e.orientationY.linearRampToValueAtTime(fc.y,t),e.orientationZ.linearRampToValueAtTime(fc.z,t)}else e.setPosition(uc.x,uc.y,uc.z),e.setOrientation(fc.x,fc.y,fc.z)}},PropertyBinding:Mc,PropertyMixer:gc,QuadraticBezierCurve:Ao,QuadraticBezierCurve3:Eo,Quaternion:_i,QuaternionKeyframeTrack:eh,QuaternionLinearInterpolant:th,R11_EAC_Format:Ht,RED_GREEN_RGTC2_Format:de,RED_RGTC1_Format:he,REVISION:e,RG11_EAC_Format:Wt,RGBADepthPacking:3201,RGBAFormat:Mt,RGBAIntegerFormat:Rt,RGBA_ASTC_10x10_Format:ne,RGBA_ASTC_10x5_Format:te,RGBA_ASTC_10x6_Format:ee,RGBA_ASTC_10x8_Format:ie,RGBA_ASTC_12x10_Format:se,RGBA_ASTC_12x12_Format:re,RGBA_ASTC_4x4_Format:Xt,RGBA_ASTC_5x4_Format:Yt,RGBA_ASTC_5x5_Format:Zt,RGBA_ASTC_6x5_Format:qt,RGBA_ASTC_6x6_Format:Qt,RGBA_ASTC_8x5_Format:Kt,RGBA_ASTC_8x6_Format:Jt,RGBA_ASTC_8x8_Format:$t,RGBA_BPTC_Format:ae,RGBA_ETC2_EAC_Format:Gt,RGBA_PVRTC_2BPPV1_Format:Ut,RGBA_PVRTC_4BPPV1_Format:Nt,RGBA_S3TC_DXT1_Format:It,RGBA_S3TC_DXT3_Format:Lt,RGBA_S3TC_DXT5_Format:Bt,RGBDepthPacking:3202,RGBFormat:St,RGBIntegerFormat:1032,RGB_BPTC_SIGNED_Format:oe,RGB_BPTC_UNSIGNED_Format:le,RGB_ETC1_Format:kt,RGB_ETC2_Format:zt,RGB_PVRTC_2BPPV1_Format:Ft,RGB_PVRTC_4BPPV1_Format:Ot,RGB_S3TC_DXT1_Format:Pt,RGDepthPacking:3203,RGFormat:Ct,RGIntegerFormat:Dt,RawShaderMaterial:Rl,Ray:or,Raycaster:Pc,RectAreaLight:zh,RedFormat:Et,RedIntegerFormat:Tt,ReinhardToneMapping:2,RenderTarget:zi,RenderTarget3D:class extends zi{constructor(t=1,e=1,i=1,n={}){super(t,e,n),this.isRenderTarget3D=!0,this.depth=i,this.texture=new Vi(null,t,e,i),this._setTextureOptions(n),this.texture.isRenderTargetTexture=!0}},RepeatWrapping:$,ReplaceStencilOp:Pe,ReverseSubtractEquation:102,RingGeometry:ml,SIGNED_R11_EAC_Format:Vt,SIGNED_RED_GREEN_RGTC2_Format:ue,SIGNED_RED_RGTC1_Format:ce,SIGNED_RG11_EAC_Format:jt,SRGBColorSpace:Ee,SRGBTransfer:De,Scene:Rn,ShaderChunk:gd,ShaderLib:yd,ShaderMaterial:Dl,ShadowMaterial:wl,Shape:Po,ShapeGeometry:fl,ShapePath:dd,ShapeUtils:rl,ShortType:ct,Skeleton:Fr,SkeletonHelper:class extends Ba{constructor(t){const e=Kc(t),i=new Ds,n=[],s=[];for(let t=0;t<e.length;t++){const i=e[t];i.parent&&i.parent.isBone&&(n.push(0,0,0),n.push(0,0,0),s.push(0,0,0),s.push(0,0,0))}i.setAttribute("position",new vs(n,3)),i.setAttribute("color",new vs(s,3));super(i,new Sa({vertexColors:!0,depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0})),this.isSkeletonHelper=!0,this.type="SkeletonHelper",this.root=t,this.bones=e,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1;const r=new En(255),a=new En(65280);this.setColors(r,a)}updateMatrixWorld(t){const e=this.bones,i=this.geometry,n=i.getAttribute("position");Qc.copy(this.root.matrixWorld).invert();for(let t=0,i=0;t<e.length;t++){const s=e[t];s.parent&&s.parent.isBone&&(qc.multiplyMatrices(Qc,s.matrixWorld),Zc.setFromMatrixPosition(qc),n.setXYZ(i,Zc.x,Zc.y,Zc.z),qc.multiplyMatrices(Qc,s.parent.matrixWorld),Zc.setFromMatrixPosition(qc),n.setXYZ(i+1,Zc.x,Zc.y,Zc.z),i+=2)}i.getAttribute("position").needsUpdate=!0,super.updateMatrixWorld(t)}setColors(t,e){const i=this.geometry.getAttribute("color");for(let n=0;n<i.count;n+=2)i.setXYZ(n,t.r,t.g,t.b),i.setXYZ(n+1,e.r,e.g,e.b);return i.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}},SkinnedMesh:Pr,Source:Bi,Sphere:bs,SphereGeometry:gl,Spherical:Fc,SphericalHarmonics3:Gh,SplineCurve:To,SpotLight:Lh,SpotLightHelper:class extends yn{constructor(t,e){super(),this.light=t,this.matrixAutoUpdate=!1,this.color=e,this.type="SpotLightHelper";const i=new Ds,n=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(let t=0,e=1,i=32;t<i;t++,e++){const s=t/i*Math.PI*2,r=e/i*Math.PI*2;n.push(Math.cos(s),Math.sin(s),1,Math.cos(r),Math.sin(r),1)}i.setAttribute("position",new vs(n,3));const s=new Sa({fog:!1,toneMapped:!1});this.cone=new Ba(i,s),this.add(this.cone),this.update()}dispose(){this.cone.geometry.dispose(),this.cone.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),this.light.target.updateWorldMatrix(!0,!1),this.parent?(this.parent.updateWorldMatrix(!0),this.matrix.copy(this.parent.matrixWorld).invert().multiply(this.light.matrixWorld)):this.matrix.copy(this.light.matrixWorld),this.matrixWorld.copy(this.light.matrixWorld);const t=this.light.distance?this.light.distance:1e3,e=t*Math.tan(this.light.angle);this.cone.scale.set(e,e,t),Yc.setFromMatrixPosition(this.light.target.matrixWorld),this.cone.lookAt(Yc),void 0!==this.color?this.cone.material.color.set(this.color):this.cone.material.color.copy(this.light.color)}},Sprite:qs,SpriteMaterial:Fs,SrcAlphaFactor:g,SrcAlphaSaturateFactor:210,SrcColorFactor:202,StaticCopyUsage:35046,StaticDrawUsage:Ve,StaticReadUsage:35045,StereoCamera:class{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Ph,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Ph,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(t){const e=this._cache;if(e.focus!==t.focus||e.fov!==t.fov||e.aspect!==t.aspect*this.aspect||e.near!==t.near||e.far!==t.far||e.zoom!==t.zoom||e.eyeSep!==this.eyeSep){e.focus=t.focus,e.fov=t.fov,e.aspect=t.aspect*this.aspect,e.near=t.near,e.far=t.far,e.zoom=t.zoom,e.eyeSep=this.eyeSep,ec.copy(t.projectionMatrix);const i=e.eyeSep/2,n=i*e.near/e.focus,s=e.near*Math.tan(hi*e.fov*.5)/e.zoom;let r,a;tc.elements[12]=-i,$h.elements[12]=i,r=-s*e.aspect+n,a=s*e.aspect+n,ec.elements[0]=2*e.near/(a-r),ec.elements[8]=(a+r)/(a-r),this.cameraL.projectionMatrix.copy(ec),r=-s*e.aspect-n,a=s*e.aspect-n,ec.elements[0]=2*e.near/(a-r),ec.elements[8]=(a+r)/(a-r),this.cameraR.projectionMatrix.copy(ec)}this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(tc),this.cameraR.matrixWorld.copy(t.matrixWorld).multiply($h)}},StreamCopyUsage:35042,StreamDrawUsage:35040,StreamReadUsage:35041,StringKeyframeTrack:ih,SubtractEquation:101,SubtractiveBlending:3,TOUCH:n,TangentSpaceNormalMap:0,TetrahedronGeometry:vl,Texture:Ui,TextureLoader:vh,TextureUtils:class{static contain(t,e){return function(t,e){const i=t.image&&t.image.width?t.image.width/t.image.height:1;return i>e?(t.repeat.x=1,t.repeat.y=i/e,t.offset.x=0,t.offset.y=(1-t.repeat.y)/2):(t.repeat.x=e/i,t.repeat.y=1,t.offset.x=(1-t.repeat.x)/2,t.offset.y=0),t}(t,e)}static cover(t,e){return function(t,e){const i=t.image&&t.image.width?t.image.width/t.image.height:1;return i>e?(t.repeat.x=e/i,t.repeat.y=1,t.offset.x=(1-t.repeat.x)/2,t.offset.y=0):(t.repeat.x=1,t.repeat.y=i/e,t.offset.x=0,t.offset.y=(1-t.repeat.y)/2),t}(t,e)}static fill(t){return function(t){return t.repeat.x=1,t.repeat.y=1,t.offset.x=0,t.offset.y=0,t}(t)}static getByteLength(t,e,i,n){return pd(t,e,i,n)}},Timer:Bc,TimestampQuery:{COMPUTE:"compute",RENDER:"render"},TorusGeometry:yl,TorusKnotGeometry:_l,Triangle:Wn,TriangleFanDrawMode:2,TriangleStripDrawMode:1,TrianglesDrawMode:0,TubeGeometry:xl,UVMapping:Y,Uint16BufferAttribute:fs,Uint32BufferAttribute:gs,Uint8BufferAttribute:class extends ms{constructor(t,e,i){super(new Uint8Array(t),e,i)}},Uint8ClampedBufferAttribute:class extends ms{constructor(t,e,i){super(new Uint8ClampedArray(t),e,i)}},Uniform:Tc,UniformsGroup:class extends ai{constructor(){super(),this.isUniformsGroup=!0,Object.defineProperty(this,"id",{value:Cc++}),this.name="",this.usage=Ve,this.uniforms=[]}add(t){return this.uniforms.push(t),this}remove(t){const e=this.uniforms.indexOf(t);return-1!==e&&this.uniforms.splice(e,1),this}setName(t){return this.name=t,this}setUsage(t){return this.usage=t,this}dispose(){this.dispatchEvent({type:"dispose"})}copy(t){this.name=t.name,this.usage=t.usage;const e=t.uniforms;this.uniforms.length=0;for(let t=0,i=e.length;t<i;t++){const i=Array.isArray(e[t])?e[t]:[e[t]];for(let t=0;t<i.length;t++)this.uniforms.push(i[t].clone())}return this}clone(){return(new this.constructor).copy(this)}},UniformsLib:vd,UniformsUtils:Cl,UnsignedByteType:lt,UnsignedInt101111Type:xt,UnsignedInt248Type:yt,UnsignedInt5999Type:_t,UnsignedIntType:pt,UnsignedShort4444Type:gt,UnsignedShort5551Type:vt,UnsignedShortType:dt,VSMShadowMap:3,Vector2:yi,Vector3:xi,Vector4:ki,VectorKeyframeTrack:nh,VideoFrameTexture:class extends Va{constructor(t,e,i,n,s,r,a,o){super({},t,e,i,n,s,r,a,o),this.isVideoFrameTexture=!0}update(){}clone(){return(new this.constructor).copy(this)}setFrame(t){this.image=t,this.needsUpdate=!0}},VideoTexture:Va,WebGL3DRenderTarget:class extends Gi{constructor(t=1,e=1,i=1,n={}){super(t,e,n),this.isWebGL3DRenderTarget=!0,this.depth=i,this.texture=new Vi(null,t,e,i),this._setTextureOptions(n),this.texture.isRenderTargetTexture=!0}},WebGLArrayRenderTarget:class extends Gi{constructor(t=1,e=1,i=1,n={}){super(t,e,n),this.isWebGLArrayRenderTarget=!0,this.depth=i,this.texture=new Hi(null,t,e,i),this._setTextureOptions(n),this.texture.isRenderTargetTexture=!0}},WebGLCoordinateSystem:je,WebGLCubeRenderTarget:Hd,WebGLRenderTarget:Gi,WebGLRenderer:am,WebGLUtils:Kp,WebGPUCoordinateSystem:Xe,WebXRController:bn,WireframeGeometry:bl,WrapAroundEnding:be,ZeroCurvatureEnding:_e,ZeroFactor:200,ZeroSlopeEnding:xe,ZeroStencilOp:0,createCanvasElement:Ke,error:ni,getConsoleFunction:function(){return $e},log:ti,setConsoleFunction:function(t){$e=t},warn:ii,warnOnce:si});const lm=new jn,hm=new xi;let cm=class extends jh{constructor(){super(),this.isLineSegmentsGeometry=!0,this.type="LineSegmentsGeometry";this.setIndex([0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5]),this.setAttribute("position",new vs([-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0],3)),this.setAttribute("uv",new vs([-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2],2))}applyMatrix4(t){const e=this.attributes.instanceStart,i=this.attributes.instanceEnd;return void 0!==e&&(e.applyMatrix4(t),i.applyMatrix4(t),e.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}setPositions(t){let e;t instanceof Float32Array?e=t:Array.isArray(t)&&(e=new Float32Array(t));const i=new Dc(e,6,1);return this.setAttribute("instanceStart",new Is(i,3,0)),this.setAttribute("instanceEnd",new Is(i,3,3)),this.instanceCount=this.attributes.instanceStart.count,this.computeBoundingBox(),this.computeBoundingSphere(),this}setColors(t){let e;t instanceof Float32Array?e=t:Array.isArray(t)&&(e=new Float32Array(t));const i=new Dc(e,6,1);return this.setAttribute("instanceColorStart",new Is(i,3,0)),this.setAttribute("instanceColorEnd",new Is(i,3,3)),this}fromWireframeGeometry(t){return this.setPositions(t.attributes.position.array),this}fromEdgesGeometry(t){return this.setPositions(t.attributes.position.array),this}fromMesh(t){return this.fromWireframeGeometry(new bl(t.geometry)),this}fromLineSegments(t){const e=t.geometry;return this.setPositions(e.attributes.position.array),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new jn);const t=this.attributes.instanceStart,e=this.attributes.instanceEnd;void 0!==t&&void 0!==e&&(this.boundingBox.setFromBufferAttribute(t),lm.setFromBufferAttribute(e),this.boundingBox.union(lm))}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new bs),null===this.boundingBox&&this.computeBoundingBox();const t=this.attributes.instanceStart,e=this.attributes.instanceEnd;if(void 0!==t&&void 0!==e){const i=this.boundingSphere.center;this.boundingBox.getCenter(i);let n=0;for(let s=0,r=t.count;s<r;s++)hm.fromBufferAttribute(t,s),n=Math.max(n,i.distanceToSquared(hm)),hm.fromBufferAttribute(e,s),n=Math.max(n,i.distanceToSquared(hm));this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&console.error("THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.",this)}}toJSON(){}};vd.line={worldUnits:{value:1},linewidth:{value:1},resolution:{value:new yi(1,1)},dashOffset:{value:0},dashScale:{value:1},dashSize:{value:1},gapSize:{value:1}},yd.line={uniforms:Cl.merge([vd.common,vd.fog,vd.line]),vertexShader:"\n\t\t#include <common>\n\t\t#include <color_pars_vertex>\n\t\t#include <fog_pars_vertex>\n\t\t#include <logdepthbuf_pars_vertex>\n\t\t#include <clipping_planes_pars_vertex>\n\n\t\tuniform float linewidth;\n\t\tuniform vec2 resolution;\n\n\t\tattribute vec3 instanceStart;\n\t\tattribute vec3 instanceEnd;\n\n\t\tattribute vec3 instanceColorStart;\n\t\tattribute vec3 instanceColorEnd;\n\n\t\t#ifdef WORLD_UNITS\n\n\t\t\tvarying vec4 worldPos;\n\t\t\tvarying vec3 worldStart;\n\t\t\tvarying vec3 worldEnd;\n\n\t\t\t#ifdef USE_DASH\n\n\t\t\t\tvarying vec2 vUv;\n\n\t\t\t#endif\n\n\t\t#else\n\n\t\t\tvarying vec2 vUv;\n\n\t\t#endif\n\n\t\t#ifdef USE_DASH\n\n\t\t\tuniform float dashScale;\n\t\t\tattribute float instanceDistanceStart;\n\t\t\tattribute float instanceDistanceEnd;\n\t\t\tvarying float vLineDistance;\n\n\t\t#endif\n\n\t\tvoid trimSegment( const in vec4 start, inout vec4 end ) {\n\n\t\t\t// trim end segment so it terminates between the camera plane and the near plane\n\n\t\t\t// conservative estimate of the near plane\n\t\t\tfloat a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column\n\t\t\tfloat b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column\n\t\t\tfloat nearEstimate = - 0.5 * b / a;\n\n\t\t\tfloat alpha = ( nearEstimate - start.z ) / ( end.z - start.z );\n\n\t\t\tend.xyz = mix( start.xyz, end.xyz, alpha );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\t#ifdef USE_COLOR\n\n\t\t\t\tvColor.xyz = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;\n\n\t\t\t#endif\n\n\t\t\t#ifdef USE_DASH\n\n\t\t\t\tvLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;\n\t\t\t\tvUv = uv;\n\n\t\t\t#endif\n\n\t\t\tfloat aspect = resolution.x / resolution.y;\n\n\t\t\t// camera space\n\t\t\tvec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );\n\t\t\tvec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );\n\n\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\tworldStart = start.xyz;\n\t\t\t\tworldEnd = end.xyz;\n\n\t\t\t#else\n\n\t\t\t\tvUv = uv;\n\n\t\t\t#endif\n\n\t\t\t// special case for perspective projection, and segments that terminate either in, or behind, the camera plane\n\t\t\t// clearly the gpu firmware has a way of addressing this issue when projecting into ndc space\n\t\t\t// but we need to perform ndc-space calculations in the shader, so we must address this issue directly\n\t\t\t// perhaps there is a more elegant solution -- WestLangley\n\n\t\t\tbool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column\n\n\t\t\tif ( perspective ) {\n\n\t\t\t\tif ( start.z < 0.0 && end.z >= 0.0 ) {\n\n\t\t\t\t\ttrimSegment( start, end );\n\n\t\t\t\t} else if ( end.z < 0.0 && start.z >= 0.0 ) {\n\n\t\t\t\t\ttrimSegment( end, start );\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\t// clip space\n\t\t\tvec4 clipStart = projectionMatrix * start;\n\t\t\tvec4 clipEnd = projectionMatrix * end;\n\n\t\t\t// ndc space\n\t\t\tvec3 ndcStart = clipStart.xyz / clipStart.w;\n\t\t\tvec3 ndcEnd = clipEnd.xyz / clipEnd.w;\n\n\t\t\t// direction\n\t\t\tvec2 dir = ndcEnd.xy - ndcStart.xy;\n\n\t\t\t// account for clip-space aspect ratio\n\t\t\tdir.x *= aspect;\n\t\t\tdir = normalize( dir );\n\n\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\tvec3 worldDir = normalize( end.xyz - start.xyz );\n\t\t\t\tvec3 tmpFwd = normalize( mix( start.xyz, end.xyz, 0.5 ) );\n\t\t\t\tvec3 worldUp = normalize( cross( worldDir, tmpFwd ) );\n\t\t\t\tvec3 worldFwd = cross( worldDir, worldUp );\n\t\t\t\tworldPos = position.y < 0.5 ? start: end;\n\n\t\t\t\t// height offset\n\t\t\t\tfloat hw = linewidth * 0.5;\n\t\t\t\tworldPos.xyz += position.x < 0.0 ? hw * worldUp : - hw * worldUp;\n\n\t\t\t\t// don't extend the line if we're rendering dashes because we\n\t\t\t\t// won't be rendering the endcaps\n\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t// cap extension\n\t\t\t\t\tworldPos.xyz += position.y < 0.5 ? - hw * worldDir : hw * worldDir;\n\n\t\t\t\t\t// add width to the box\n\t\t\t\t\tworldPos.xyz += worldFwd * hw;\n\n\t\t\t\t\t// endcaps\n\t\t\t\t\tif ( position.y > 1.0 || position.y < 0.0 ) {\n\n\t\t\t\t\t\tworldPos.xyz -= worldFwd * 2.0 * hw;\n\n\t\t\t\t\t}\n\n\t\t\t\t#endif\n\n\t\t\t\t// project the worldpos\n\t\t\t\tvec4 clip = projectionMatrix * worldPos;\n\n\t\t\t\t// shift the depth of the projected points so the line\n\t\t\t\t// segments overlap neatly\n\t\t\t\tvec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;\n\t\t\t\tclip.z = clipPose.z * clip.w;\n\n\t\t\t#else\n\n\t\t\t\tvec2 offset = vec2( dir.y, - dir.x );\n\t\t\t\t// undo aspect ratio adjustment\n\t\t\t\tdir.x /= aspect;\n\t\t\t\toffset.x /= aspect;\n\n\t\t\t\t// sign flip\n\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t// endcaps\n\t\t\t\tif ( position.y < 0.0 ) {\n\n\t\t\t\t\toffset += - dir;\n\n\t\t\t\t} else if ( position.y > 1.0 ) {\n\n\t\t\t\t\toffset += dir;\n\n\t\t\t\t}\n\n\t\t\t\t// adjust for linewidth\n\t\t\t\toffset *= linewidth;\n\n\t\t\t\t// adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...\n\t\t\t\toffset /= resolution.y;\n\n\t\t\t\t// select end\n\t\t\t\tvec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;\n\n\t\t\t\t// back to clip space\n\t\t\t\toffset *= clip.w;\n\n\t\t\t\tclip.xy += offset;\n\n\t\t\t#endif\n\n\t\t\tgl_Position = clip;\n\n\t\t\tvec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation\n\n\t\t\t#include <logdepthbuf_vertex>\n\t\t\t#include <clipping_planes_vertex>\n\t\t\t#include <fog_vertex>\n\n\t\t}\n\t\t",fragmentShader:"\n\t\tuniform vec3 diffuse;\n\t\tuniform float opacity;\n\t\tuniform float linewidth;\n\n\t\t#ifdef USE_DASH\n\n\t\t\tuniform float dashOffset;\n\t\t\tuniform float dashSize;\n\t\t\tuniform float gapSize;\n\n\t\t#endif\n\n\t\tvarying float vLineDistance;\n\n\t\t#ifdef WORLD_UNITS\n\n\t\t\tvarying vec4 worldPos;\n\t\t\tvarying vec3 worldStart;\n\t\t\tvarying vec3 worldEnd;\n\n\t\t\t#ifdef USE_DASH\n\n\t\t\t\tvarying vec2 vUv;\n\n\t\t\t#endif\n\n\t\t#else\n\n\t\t\tvarying vec2 vUv;\n\n\t\t#endif\n\n\t\t#include <common>\n\t\t#include <color_pars_fragment>\n\t\t#include <fog_pars_fragment>\n\t\t#include <logdepthbuf_pars_fragment>\n\t\t#include <clipping_planes_pars_fragment>\n\n\t\tvec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {\n\n\t\t\tfloat mua;\n\t\t\tfloat mub;\n\n\t\t\tvec3 p13 = p1 - p3;\n\t\t\tvec3 p43 = p4 - p3;\n\n\t\t\tvec3 p21 = p2 - p1;\n\n\t\t\tfloat d1343 = dot( p13, p43 );\n\t\t\tfloat d4321 = dot( p43, p21 );\n\t\t\tfloat d1321 = dot( p13, p21 );\n\t\t\tfloat d4343 = dot( p43, p43 );\n\t\t\tfloat d2121 = dot( p21, p21 );\n\n\t\t\tfloat denom = d2121 * d4343 - d4321 * d4321;\n\n\t\t\tfloat numer = d1343 * d4321 - d1321 * d4343;\n\n\t\t\tmua = numer / denom;\n\t\t\tmua = clamp( mua, 0.0, 1.0 );\n\t\t\tmub = ( d1343 + d4321 * ( mua ) ) / d4343;\n\t\t\tmub = clamp( mub, 0.0, 1.0 );\n\n\t\t\treturn vec2( mua, mub );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tfloat alpha = opacity;\n\t\t\tvec4 diffuseColor = vec4( diffuse, alpha );\n\n\t\t\t#include <clipping_planes_fragment>\n\n\t\t\t#ifdef USE_DASH\n\n\t\t\t\tif ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps\n\n\t\t\t\tif ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX\n\n\t\t\t#endif\n\n\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t// Find the closest points on the view ray and the line segment\n\t\t\t\tvec3 rayEnd = normalize( worldPos.xyz ) * 1e5;\n\t\t\t\tvec3 lineDir = worldEnd - worldStart;\n\t\t\t\tvec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );\n\n\t\t\t\tvec3 p1 = worldStart + lineDir * params.x;\n\t\t\t\tvec3 p2 = rayEnd * params.y;\n\t\t\t\tvec3 delta = p1 - p2;\n\t\t\t\tfloat len = length( delta );\n\t\t\t\tfloat norm = len / linewidth;\n\n\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\tfloat dnorm = fwidth( norm );\n\t\t\t\t\t\talpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tif ( norm > 0.5 ) {\n\n\t\t\t\t\t\t\tdiscard;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#endif\n\n\t\t\t#else\n\n\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t// artifacts appear on some hardware if a derivative is taken within a conditional\n\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\tfloat len2 = a * a + b * b;\n\t\t\t\t\tfloat dlen = fwidth( len2 );\n\n\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\talpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );\n\n\t\t\t\t\t}\n\n\t\t\t\t#else\n\n\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\n\t\t\t\t\t\tif ( len2 > 1.0 ) discard;\n\n\t\t\t\t\t}\n\n\t\t\t\t#endif\n\n\t\t\t#endif\n\n\t\t\t#include <logdepthbuf_fragment>\n\t\t\t#include <color_fragment>\n\n\t\t\tgl_FragColor = vec4( diffuseColor.rgb, alpha );\n\n\t\t\t#include <tonemapping_fragment>\n\t\t\t#include <colorspace_fragment>\n\t\t\t#include <fog_fragment>\n\t\t\t#include <premultiplied_alpha_fragment>\n\n\t\t}\n\t\t"};class dm extends Dl{constructor(t){super({type:"LineMaterial",uniforms:Cl.clone(yd.line.uniforms),vertexShader:yd.line.vertexShader,fragmentShader:yd.line.fragmentShader,clipping:!0}),this.isLineMaterial=!0,this.setValues(t)}get color(){return this.uniforms.diffuse.value}set color(t){this.uniforms.diffuse.value=t}get worldUnits(){return"WORLD_UNITS"in this.defines}set worldUnits(t){!0===t!==this.worldUnits&&(this.needsUpdate=!0),!0===t?this.defines.WORLD_UNITS="":delete this.defines.WORLD_UNITS}get linewidth(){return this.uniforms.linewidth.value}set linewidth(t){this.uniforms.linewidth&&(this.uniforms.linewidth.value=t)}get dashed(){return"USE_DASH"in this.defines}set dashed(t){!0===t!==this.dashed&&(this.needsUpdate=!0),!0===t?this.defines.USE_DASH="":delete this.defines.USE_DASH}get dashScale(){return this.uniforms.dashScale.value}set dashScale(t){this.uniforms.dashScale.value=t}get dashSize(){return this.uniforms.dashSize.value}set dashSize(t){this.uniforms.dashSize.value=t}get dashOffset(){return this.uniforms.dashOffset.value}set dashOffset(t){this.uniforms.dashOffset.value=t}get gapSize(){return this.uniforms.gapSize.value}set gapSize(t){this.uniforms.gapSize.value=t}get opacity(){return this.uniforms.opacity.value}set opacity(t){this.uniforms&&(this.uniforms.opacity.value=t)}get resolution(){return this.uniforms.resolution.value}set resolution(t){this.uniforms.resolution.value.copy(t)}get alphaToCoverage(){return"USE_ALPHA_TO_COVERAGE"in this.defines}set alphaToCoverage(t){this.defines&&(!0===t!==this.alphaToCoverage&&(this.needsUpdate=!0),!0===t?this.defines.USE_ALPHA_TO_COVERAGE="":delete this.defines.USE_ALPHA_TO_COVERAGE)}}const um=new ki,pm=new xi,mm=new xi,fm=new ki,gm=new ki,vm=new ki,ym=new xi,_m=new Wi,xm=new Xc,bm=new xi,Sm=new jn,Mm=new bs,wm=new ki;let Am,Em;function Tm(t,e,i){return wm.set(0,0,-e,1).applyMatrix4(t.projectionMatrix),wm.multiplyScalar(1/wm.w),wm.x=Em/i.width,wm.y=Em/i.height,wm.applyMatrix4(t.projectionMatrixInverse),wm.multiplyScalar(1/wm.w),Math.abs(Math.max(wm.x,wm.y))}class Cm extends xr{constructor(t=new cm,e=new dm({color:16777215*Math.random()})){super(t,e),this.isLineSegments2=!0,this.type="LineSegments2"}computeLineDistances(){const t=this.geometry,e=t.attributes.instanceStart,i=t.attributes.instanceEnd,n=new Float32Array(2*e.count);for(let t=0,s=0,r=e.count;t<r;t++,s+=2)pm.fromBufferAttribute(e,t),mm.fromBufferAttribute(i,t),n[s]=0===s?0:n[s-1],n[s+1]=n[s]+pm.distanceTo(mm);const s=new Dc(n,2,1);return t.setAttribute("instanceDistanceStart",new Is(s,1,0)),t.setAttribute("instanceDistanceEnd",new Is(s,1,1)),this}raycast(t,e){const i=this.material.worldUnits,n=t.camera;null!==n||i||console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');const s=void 0!==t.params.Line2&&t.params.Line2.threshold||0;Am=t.ray;const r=this.matrixWorld,a=this.geometry,o=this.material;let l,h;if(Em=o.linewidth+s,null===a.boundingSphere&&a.computeBoundingSphere(),Mm.copy(a.boundingSphere).applyMatrix4(r),i)l=.5*Em;else{l=Tm(n,Math.max(n.near,Mm.distanceToPoint(Am.origin)),o.resolution)}if(Mm.radius+=l,!1!==Am.intersectsSphere(Mm)){if(null===a.boundingBox&&a.computeBoundingBox(),Sm.copy(a.boundingBox).applyMatrix4(r),i)h=.5*Em;else{h=Tm(n,Math.max(n.near,Sm.distanceToPoint(Am.origin)),o.resolution)}Sm.expandByScalar(h),!1!==Am.intersectsBox(Sm)&&(i?function(t,e){const i=t.matrixWorld,n=t.geometry,s=n.attributes.instanceStart,r=n.attributes.instanceEnd;for(let a=0,o=Math.min(n.instanceCount,s.count);a<o;a++){xm.start.fromBufferAttribute(s,a),xm.end.fromBufferAttribute(r,a),xm.applyMatrix4(i);const n=new xi,o=new xi;Am.distanceSqToSegment(xm.start,xm.end,o,n),o.distanceTo(n)<.5*Em&&e.push({point:o,pointOnLine:n,distance:Am.origin.distanceTo(o),object:t,face:null,faceIndex:a,uv:null,uv1:null})}}(this,e):function(t,e,i){const n=e.projectionMatrix,s=t.material.resolution,r=t.matrixWorld,a=t.geometry,o=a.attributes.instanceStart,l=a.attributes.instanceEnd,h=Math.min(a.instanceCount,o.count),c=-e.near;Am.at(1,vm),vm.w=1,vm.applyMatrix4(e.matrixWorldInverse),vm.applyMatrix4(n),vm.multiplyScalar(1/vm.w),vm.x*=s.x/2,vm.y*=s.y/2,vm.z=0,ym.copy(vm),_m.multiplyMatrices(e.matrixWorldInverse,r);for(let e=0,a=h;e<a;e++){if(fm.fromBufferAttribute(o,e),gm.fromBufferAttribute(l,e),fm.w=1,gm.w=1,fm.applyMatrix4(_m),gm.applyMatrix4(_m),fm.z>c&&gm.z>c)continue;if(fm.z>c){const t=fm.z-gm.z,e=(fm.z-c)/t;fm.lerp(gm,e)}else if(gm.z>c){const t=gm.z-fm.z,e=(gm.z-c)/t;gm.lerp(fm,e)}fm.applyMatrix4(n),gm.applyMatrix4(n),fm.multiplyScalar(1/fm.w),gm.multiplyScalar(1/gm.w),fm.x*=s.x/2,fm.y*=s.y/2,gm.x*=s.x/2,gm.y*=s.y/2,xm.start.copy(fm),xm.start.z=0,xm.end.copy(gm),xm.end.z=0;const a=xm.closestPointToPointParameter(ym,!0);xm.at(a,bm);const h=vi.lerp(fm.z,gm.z,a),d=h>=-1&&h<=1,u=ym.distanceTo(bm)<.5*Em;if(d&&u){xm.start.fromBufferAttribute(o,e),xm.end.fromBufferAttribute(l,e),xm.start.applyMatrix4(r),xm.end.applyMatrix4(r);const n=new xi,s=new xi;Am.distanceSqToSegment(xm.start,xm.end,s,n),i.push({point:s,pointOnLine:n,distance:Am.origin.distanceTo(s),object:t,face:null,faceIndex:e,uv:null,uv1:null})}}}(this,n,e))}}onBeforeRender(t){const e=this.material.uniforms;e&&e.resolution&&(t.getViewport(um),this.material.uniforms.resolution.value.set(um.z,um.w))}}class Dm extends cm{toJSON(){return jh.prototype.toJSON.call(this)}}const Rm=new xi,Pm=new xi,Im=new Mi;class Lm extends Ba{constructor(t,e=1,i=16711680){const n=new Ds,s=t.geometry.attributes.normal.count,r=new vs(2*s*3,3);n.setAttribute("position",r),super(n,new Sa({color:i,toneMapped:!1})),this.object=t,this.size=e,this.type="VertexNormalsHelper",this.matrixAutoUpdate=!1,this.isVertexNormalsHelper=!0,this.update()}update(){this.object.updateMatrixWorld(!0),Im.getNormalMatrix(this.object.matrixWorld);const t=this.object.matrixWorld,e=this.geometry.attributes.position,i=this.object.geometry;if(i){const n=i.attributes.position,s=i.attributes.normal;let r=0;for(let i=0,a=n.count;i<a;i++)Rm.fromBufferAttribute(n,i).applyMatrix4(t),Pm.fromBufferAttribute(s,i),Pm.applyMatrix3(Im).normalize().multiplyScalar(this.size).add(Rm),e.setXYZ(r,Rm.x,Rm.y,Rm.z),r+=1,e.setXYZ(r,Pm.x,Pm.y,Pm.z),r+=1}e.needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}}const Bm={debug:0,info:1,warn:2,error:3,silent:4};let Om="warn";const Fm={setLevel(t){Om=t},getLevel:()=>Om,debug(...t){Bm[Om]<=Bm.debug&&console.log("[three-cad-viewer]",...t)},info(...t){Bm[Om]<=Bm.info&&console.log("[three-cad-viewer]",...t)},warn(...t){Bm[Om]<=Bm.warn&&console.warn("[three-cad-viewer]",...t)},error(...t){Bm[Om]<=Bm.error&&console.error("[three-cad-viewer]",...t)}},Nm={geometry:0,material:0,texture:0};let Um=!1;const km=new Map,zm={enableDebug(){Um=!0,Fm.info("GPU tracker debug mode enabled")},disableDebug(){Um=!1,km.clear(),Fm.info("GPU tracker debug mode disabled")},get isDebugEnabled(){return Um},track(t,e,i){if(Nm[t]++,Um){const n=(new Error).stack?.split("\n").slice(2,6).join("\n")??"";km.set(e,{type:t,label:i??"unlabeled",stack:n,timestamp:performance.now()})}},untrack(t,e){if(Um&&e){const t=km.get(e);if(t)return Nm[t.type]--,void km.delete(e)}Nm[t]>0&&Nm[t]--},get summary(){return{geometry:Nm.geometry,material:Nm.material,texture:Nm.texture,total:Nm.geometry+Nm.material+Nm.texture}},getResources:()=>Um?Array.from(km.values()):(Fm.warn("GPU tracker: getResources() requires debug mode - call enableDebug() first"),[]),getResourcesByType(){const t=this.getResources();return{geometry:t.filter(t=>"geometry"===t.type),material:t.filter(t=>"material"===t.type),texture:t.filter(t=>"texture"===t.type)}},details(){const{total:t,geometry:e,material:i,texture:n}=this.summary;if(0!==t)if(console.log(`GPU tracker: ${t} resources allocated:`),console.log(` - Geometries: ${e}`),console.log(` - Materials: ${i}`),console.log(` - Textures: ${n}`),Um){const t=this.getResources();console.log("\nResource details:"),t.forEach((t,e)=>{console.log(`\n[${e+1}] ${t.type}: ${t.label}`),console.log(` Created at: ${t.timestamp.toFixed(2)}ms`),console.log(` Stack:\n${t.stack}`)})}else console.log("\nFor detailed resource info, enable debug mode before creating resources:"),console.log(" gpuTracker.enableDebug()");else console.log("GPU tracker: No resources currently allocated")},reset(){Nm.geometry=0,Nm.material=0,Nm.texture=0,km.clear()},assertEmpty(){const{total:t}=this.summary;if(0!==t)throw this.details(),new Error(`GPU tracker: ${t} resources not disposed`)},trackGeometry(t,e){return this.track("geometry",t,e),t},trackMaterial(t,e){return this.track("material",t,e),t},trackTexture(t,e){return this.track("texture",t,e),t}};"undefined"!=typeof window&&(window.tcv_gpu=zm);const Gm={x:new xi(1,0,0),y:new xi(0,1,0),z:new xi(0,0,1)};function Hm(t,e=1){return t.flat(e)}function Vm(t){if(!Array.isArray(t)||3!==t.length)throw new Error(`Expected array of length 3, got ${Array.isArray(t)?t.length:typeof t}`);return t}function Wm(t){if(!Array.isArray(t)||4!==t.length)throw new Error(`Expected array of length 4, got ${Array.isArray(t)?t.length:typeof t}`);return t}function jm(t,e,i=1e-9){if(Array.isArray(t)&&Array.isArray(e))return t.length===e.length&&t.every((t,n)=>jm(t,e[n],i));if(null!==t&&null!==e&&"object"==typeof t&&"object"==typeof e){const n=t,s=e,r=Object.keys(n),a=Object.keys(s);return!(r.length!==a.length||!r.every(t=>Object.prototype.hasOwnProperty.call(s,t)))&&r.every(t=>jm(n[t],s[t],i))}return"number"==typeof t&&"number"==typeof e?Math.abs(t-e)<i:t===e}function Xm(t,e){t&&(e(t),t.children&&t.children.length>0&&t.children.forEach(t=>{Xm(t,e)}))}function Ym(t){if(t){zm.untrack("geometry",t),t.dispose();for(const e of Object.values(t.attributes))e&&"object"==typeof e&&"dispose"in e&&"function"==typeof e.dispose&&e.dispose()}}const Zm=["map","normalMap","roughnessMap","metalnessMap","aoMap","emissiveMap","alphaMap","bumpMap","transmissionMap","clearcoatMap","clearcoatRoughnessMap","clearcoatNormalMap","thicknessMap","specularIntensityMap","specularColorMap","sheenColorMap","sheenRoughnessMap","anisotropyMap"];function qm(t){if(t){for(const e of Zm)t[e]&&(t[e]=null);zm.untrack("material",t),t.dispose()}}function Qm(t){var e;t&&(Array.isArray(t)?t.forEach(Qm):(Array.isArray(t.children)&&t.children.forEach(Qm),t.dispose?t.dispose():(t.isMesh||t.isLine||t.isPoints)&&((e=t).geometry&&Ym(e.geometry),e.material&&(Array.isArray(e.material)?e.material.forEach(qm):qm(e.material)))))}function Km(t){return Math.round(Math.PI*t)}function Jm(t){return"isMesh"in t&&!0===t.isMesh}function $m(t){return"isLine"in t&&!0===t.isLine}function tf(t){return"isPoints"in t&&!0===t.isPoints}function ef(t){return"isOrthographicCamera"in t&&!0===t.isOrthographicCamera}function nf(t){return"isPerspectiveCamera"in t&&!0===t.isPerspectiveCamera}function sf(t){return"LineSegments2"===t.type}const rf=new class{constructor(){this.getshortcuts=t=>this.keyMapping[t].replace("Key",""),this.get=(t,e)=>t[this.keyMapping[e]],this.set=t=>{for(const e of Object.keys(t)){const i=t[e];void 0!==i&&(this.keyMapping[e]=i)}},this.setActionShortcuts=t=>{this.actionShortcuts={...t},this.reverseActionShortcuts={};for(const[e,i]of Object.entries(t))this.reverseActionShortcuts[i]=e},this.getActionForKey=t=>this.reverseActionShortcuts[t],this.getShortcutForAction=t=>this.actionShortcuts[t],this.getActionShortcuts=()=>({...this.actionShortcuts}),this.keyMapping={shift:"ctrlKey",ctrl:"shiftKey",meta:"altKey",alt:"metaKey"},this.actionShortcuts={},this.reverseActionShortcuts={}}get_config(){return Object.assign({},this.keyMapping)}};class af{constructor(){this.originalMaterials=new Map,this.zebraMaterials=new Map,this.settings={stripeCount:15,stripeDirection:0,colorScheme:"blackwhite",opacity:1,mappingMode:"normal"},this.zebraTexture=null,this.createZebraTexture()}createZebraTexture(){const t=document.createElement("canvas");t.width=1,t.height=4096;const e=t.getContext("2d"),i=this.settings.stripeCount%2==1,n=i?this.settings.stripeCount-1:this.settings.stripeCount,s=t.height/n;let r=0;for(let n=0;n<this.settings.stripeCount;n++){let a,o;switch(this.settings.colorScheme){case"blackwhite":a="#000000",o="#ffffff";break;case"colorful":{let t;if(i&&n===this.settings.stripeCount-1)t=0;else{t=n/(i?this.settings.stripeCount-1:this.settings.stripeCount)*360}a=`hsl(${t}, 100%, 50%)`,o=`hsl(${(t+180)%360}, 100%, 50%)`;break}case"grayscale":a="#D2D2D2",o="#464646"}const l=!i||0!==n&&n!==this.settings.stripeCount-1?s:.5*s;e.fillStyle=n%2==0?a:o,e.fillRect(0,r,t.width,l),r+=l}this.zebraTexture&&this.zebraTexture.dispose(),this.zebraTexture=new Xa(t),this.zebraTexture.wrapS=$,this.zebraTexture.wrapT=$,this.zebraTexture.needsUpdate=!0,this.zebraMaterials.forEach(t=>{t.uniforms.zebraTexture.value=this.zebraTexture,t.uniforms.zebraTexture.value.needsUpdate=!0,t.uniformsNeedUpdate=!0,t.needsUpdate=!0})}createZebraMaterial(){const t=this.settings.stripeDirection*Math.PI/180,e=new xi(Math.cos(t),Math.sin(t),0).normalize();return new Dl({uniforms:{zebraTexture:{value:this.zebraTexture},direction:{value:e},opacity:{value:this.settings.opacity},baseColor:{value:new En(.7,.7,.7)},mappingMode:{value:"reflection"===this.settings.mappingMode?0:1}},vertexShader:"\n varying vec3 vViewNormal;\n varying vec3 vViewPosition;\n varying vec4 vScreenPosition;\n\n void main() {\n // Transform normal to view space\n vViewNormal = normalize(normalMatrix * normal);\n\n // Transform position to view space\n vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);\n vViewPosition = mvPosition.xyz;\n\n gl_Position = projectionMatrix * mvPosition;\n\n // Store screen position for normal mode\n vScreenPosition = gl_Position;\n }\n ",fragmentShader:"\n uniform sampler2D zebraTexture;\n uniform vec3 direction;\n uniform float opacity;\n uniform vec3 baseColor;\n uniform int mappingMode; // 0 = reflection, 1 = normal\n\n varying vec3 vViewNormal;\n varying vec3 vViewPosition;\n varying vec4 vScreenPosition;\n\n void main() {\n // Normalize view-space normal\n vec3 normal = normalize(vViewNormal);\n\n float v;\n\n if (mappingMode == 0) {\n // Reflection mode (Onshape-like): circular/elliptical stripes\n // View direction in view space (points toward camera)\n vec3 viewDir = normalize(-vViewPosition);\n\n // Calculate reflection in view space\n vec3 mappingVector = reflect(-viewDir, normal);\n\n // Use the reflection vector with screen-space direction\n v = dot(mappingVector, direction) * 3.0 * 0.5 + 0.5;\n } else {\n // Normal mode (Fusion360/Shapr3D-like): zoom-independent view-based stripes\n // Use view direction normalized by distance (zoom-independent)\n\n // Normalize view position by distance to make it zoom-independent\n float dist = length(vViewPosition);\n vec2 viewDir2D = vViewPosition.xy / dist;\n\n // Rotate by stripe direction\n float cosA = direction.x / length(direction.xy);\n float sinA = direction.y / length(direction.xy);\n float rotatedPos = viewDir2D.x * cosA + viewDir2D.y * sinA;\n\n // Scale for stripe frequency (zoom-independent)\n float positionValue = rotatedPos * 2.0;\n\n // Add normal influence to follow curvature\n float normalValue = dot(normal, direction) * 0.5;\n\n // Combine: position creates base stripes, normal makes them follow curvature\n v = (positionValue + normalValue) * 3.0 * 0.5 + 0.5;\n }\n\n // Sample the zebra texture (texture varies in V/Y direction)\n vec4 zebraColor = texture2D(zebraTexture, vec2(0.5, v));\n\n // Blend zebra stripes with original material color based on opacity\n vec3 finalColor = mix(baseColor, zebraColor.rgb, opacity);\n\n gl_FragColor = vec4(finalColor, 1.0);\n }\n ",side:2})}applyToMesh(t,e){if(!t.isMesh)return;if(t.userData.excludeFromZebra)return;const i=Array.isArray(t.material)?t.material[0]:t.material;if(this.originalMaterials.has(t.uuid)||this.originalMaterials.set(t.uuid,i),!this.zebraMaterials.has(t.uuid)){const e=this.createZebraMaterial();let n=new En(.7,.7,.7);"color"in i?n=i.color.clone():function(t){return"isMeshStandardMaterial"in t&&!0===t.isMeshStandardMaterial}(i)&&i.map&&(n=new En(1,1,1)),e.uniforms.baseColor={value:n},this.zebraMaterials.set(t.uuid,e)}t.material=this.zebraMaterials.get(t.uuid),t.material.visible=e}restoreMesh(t,e){if(!t.isMesh)return;const i=this.originalMaterials.get(t.uuid);i&&(t.material=i,i.visible=e)}setStripeCount(t){this.settings.stripeCount=Math.max(2,Math.min(50,t)),this.createZebraTexture()}setStripeDirection(t){this.settings.stripeDirection=t;const e=t*Math.PI/180,i=new xi(Math.cos(e),Math.sin(e),0).normalize();this.zebraMaterials.forEach(t=>{t.uniforms.direction.value=i})}setColorScheme(t){["blackwhite","colorful","grayscale"].includes(t)&&(this.settings.colorScheme=t,this.createZebraTexture())}setStripeOpacity(t){this.settings.opacity=Math.max(0,Math.min(1,t)),this.zebraMaterials.forEach(t=>{t.uniforms.opacity.value=this.settings.opacity})}setMappingMode(t){if(["reflection","normal"].includes(t)){this.settings.mappingMode=t;const e="reflection"===t?0:1;this.zebraMaterials.forEach(t=>{t.uniforms.mappingMode.value=e,t.uniformsNeedUpdate=!0,t.needsUpdate=!0})}}update(){}dispose(){this.zebraTexture&&this.zebraTexture.dispose(),this.zebraMaterials.forEach(t=>{t.dispose()}),this.originalMaterials.clear(),this.zebraMaterials.clear()}}class of extends _n{constructor(t,e,i,n,s,r=!1){super(),this.type="ObjectGroup",this.isObjectGroup=!0,this.opacity=t,this.alpha=null==e?1:e,this.transparent=!1,this.edge_color=i,this.shapeInfo=n,this.subtype=s,this.renderback=r,this.front=null,this.back=null,this.edges=null,this.edgeMaterial=null,this.vertices=null,this.clipping=new Map,this.isSelected=!1,this.originalColor=null,this.originalBackColor=null,this.originalWidth=null,this.vertexFocusSize=8,this.edgeFocusWidth=5,this._zebra=null,this.materialTag="",this._cadFrontMaterial=null,this._cadBackMaterial=null,this._cadOriginalColor=null,this._cadOriginalBackColor=null,this._isStudioMode=!1,this._cadEdgesVisible=null}get zebra(){return this._zebra||(this._zebra=new af),this._zebra}get isStudioMode(){return this._isStudioMode}dispose(){this.shapeGeometry&&(Ym(this.shapeGeometry),this.shapeGeometry=null),this.children&&(Qm(this.children),this.clear()),this._zebra&&(this._zebra.dispose(),this._zebra=null),this._cadFrontMaterial=null,this._cadBackMaterial=null,this._cadOriginalColor=null,this._cadOriginalBackColor=null,this._isStudioMode=!1,this._cadEdgesVisible=null}setFront(t){this.add(t),this.front=t,this.originalColor=t.material.color.clone()}setBack(t){this.add(t),this.back=t,this.front||(this.originalBackColor=t.material.color.clone())}setEdges(t){this.add(t),this.edges=t;const e=t.material;if(Array.isArray(e))throw new Error("Multi-material edges are not supported");if(!function(t){return"color"in t&&"linewidth"in t}(e))throw new Error("Edge material must have color and linewidth properties");this.edgeMaterial=e,this.front||(this.originalColor=this.edgeMaterial.color.clone(),this.originalWidth=this.edgeMaterial.linewidth)}setVertices(t){this.add(t),this.vertices=t,this.originalColor=t.material.color.clone(),this.originalWidth=t.material.size}addClipping(t,e){this.add(t),this.clipping.set(e,t)}widen(t){this.vertices?this.vertices.material.size=t?this.vertexFocusSize:this.isSelected?this.vertexFocusSize-2:this.originalWidth:this.edgeMaterial&&(this.edgeMaterial.linewidth=t?this.edgeFocusWidth:this.isSelected?this.edgeFocusWidth-2:this.originalWidth)}toggleSelection(){const t=!this.isSelected;this.isSelected=t,this.highlight(t),this.widen(!1)}unhighlight(t){t&&this.isSelected||(this.isSelected=!1,this.highlight(!1)),this.widen(!1)}_getHighlightColor(){return new En(this.isSelected?5480675:9026019)}_applyColorToMaterial(t,e){t.color=e,t.needsUpdate=!0}_forEachMaterial(t){for(const e of this.children)if(!e.name.startsWith("clipping")&&Jm(e)){if(Array.isArray(e.material))throw new Error("Multi-material meshes are not supported");t(e.material)}}_forEachStandardMaterial(t){this.front&&this.front.material instanceof Pl&&t(this.front.material),this.back&&this.back.material instanceof Pl&&t(this.back.material)}highlight(t){const e=this._getHighlightColor(),i=this.front?.material||this.vertices?.material||this.edgeMaterial;i&&(this.widen(t),this._applyColorToMaterial(i,t?e:this.originalColor)),this.back&&this._applyColorToMaterial(this.back.material,t?e:this.originalBackColor)}clearHighlights(){this.highlight(!1),this.isSelected=!1,this.widen(!1)}metrics(){return this.front?{name:"face",value:0}:this.vertices?{name:"vertex",value:0}:this.edges?{name:"edge",value:0}:null}setMetalness(t){this._forEachStandardMaterial(e=>{e.metalness=t,e.needsUpdate=!0})}setRoughness(t){this._forEachStandardMaterial(e=>{e.roughness=t,e.needsUpdate=!0})}setTransparent(t){this.transparent=t;const e=t?this.opacity*this.alpha:this.alpha;this.back&&(this.back.material.opacity=e),this.front&&(this.front.material.opacity=e),this._forEachMaterial(e=>{e.depthWrite=!(this.alpha<1)&&!t,e.depthTest=!0,e.needsUpdate=!0})}setBlackEdges(t){if(this.edgeMaterial&&!this.edgeMaterial.vertexColors){const e=t?0:this.edge_color;this.front||(this.originalColor=new En(e)),this.edgeMaterial.color=new En(e),this.edgeMaterial.needsUpdate=!0}}setEdgeColor(t){this.edgeMaterial&&!this.edgeMaterial.vertexColors&&(this.edge_color=t,this.edgeMaterial.color=new En(t),this.edgeMaterial.needsUpdate=!0)}setOpacity(t){if(this.opacity=t,this.transparent){const t=this.opacity*this.alpha;this.front&&(this.front.material.opacity=t,this.front.material.needsUpdate=!0),this.back&&(this.back.material.opacity=t,this.back.material.needsUpdate=!0)}}setShapeVisible(t){this.front&&(this._isStudioMode?this.front.visible=t:this.front.material.visible=t);for(const e of this.clipping.values()){const i=e.children[0],n=e.children[1];if(Jm(i)){if(Array.isArray(i.material))throw new Error("Multi-material meshes are not supported");i.material.visible=t}if(Jm(n)){if(Array.isArray(n.material))throw new Error("Multi-material meshes are not supported");n.material.visible=t}}this.back&&this.renderback&&(this._isStudioMode?this.back.visible=t:this.back.material.visible=t)}setEdgesVisible(t){this.edgeMaterial&&(this.edgeMaterial.visible=t),this.vertices&&(this.vertices.material.visible=t)}setBackVisible(t){if(this.back&&this.front){(this._isStudioMode?this.front.visible:this.front.material.visible)&&(this._isStudioMode?this.back.visible=this.renderback||t:this.back.material.visible=this.renderback||t)}}getVisibility(){if(this.front){const t=this._isStudioMode?this.front.visible:this.front.material.visible;return this.edgeMaterial?t||this.edgeMaterial.visible:t}return this.edgeMaterial?this.edgeMaterial.visible:!!this.vertices&&this.vertices.material.visible}setClipIntersection(t){this._forEachMaterial(e=>{e.clipIntersection=t})}setClipPlanes(t){this.back&&(this.back.material.clippingPlanes=t),this.front&&(this.front.material.clippingPlanes=t),this.edgeMaterial&&(this.edgeMaterial.clippingPlanes=t),this.vertices&&(this.vertices.material.clippingPlanes=t),this.updateMaterials(!0)}setPolygonOffset(t){this.back&&(this.back.material.polygonOffsetUnits=t)}setZScale(t){const e=(i,n,s,r=!0)=>{for(const a of i.children)"isMesh"in a||"isLine"in a?(a.scale.z=t,r&&a.parent&&(a.parent.position.z=n*t)):"isGroup"in a&&e(a,n,s,!a.name.startsWith("clipping"))};(this.front||this.back||this.edges)&&e(this,this.minZ,this.height)}updateMaterials(t){this.back&&(this.back.material.needsUpdate=t),this.front&&(this.front.material.needsUpdate=t),this.edgeMaterial&&(this.edgeMaterial.needsUpdate=t),this.vertices&&(this.vertices.material.needsUpdate=t)}clearClipping(){for(const[,t]of this.clipping)this.remove(t),Qm(t);this.clipping.clear()}setZebra(t){if(this.front){const e=this.front.material.visible;t?this.zebra.applyToMesh(this.front,e):this.zebra.restoreMesh(this.front,e)}}setZebraCount(t){this.zebra.setStripeCount(t)}setZebraOpacity(t){this.zebra.setStripeOpacity(t)}setZebraDirection(t){this.zebra.setStripeDirection(t)}setZebraColorScheme(t){this.zebra.setColorScheme(t)}setZebraMappingMode(t){this.zebra.setMappingMode(t)}enterStudioMode(t,e){this._isStudioMode||(this.front&&(this._cadFrontMaterial=this.front.material),this.back&&(this._cadBackMaterial=this.back.material),this._cadOriginalColor=this.originalColor?this.originalColor.clone():null,this._cadOriginalBackColor=this.originalBackColor?this.originalBackColor.clone():null,this._cadEdgesVisible=this.edgeMaterial?this.edgeMaterial.visible:null,this.front&&t&&(this.front.visible=this.front.material.visible,this.front.material=t,this.originalColor=t.color),this.back&&e&&this.renderback&&(this.back.visible=this.back.material.visible,this.back.material=e,this.originalBackColor=e.color),this._isStudioMode=!0)}leaveStudioMode(){this._isStudioMode&&(this.front&&this._cadFrontMaterial&&(this._cadFrontMaterial.visible=this.front.visible,this.front.material=this._cadFrontMaterial,this.front.visible=!0),this.back&&this._cadBackMaterial&&this.renderback&&(this._cadBackMaterial.visible=this.back.visible,this.back.material=this._cadBackMaterial,this.back.visible=!0),this._cadOriginalColor&&(this.originalColor=this._cadOriginalColor.clone()),this._cadOriginalBackColor&&(this.originalBackColor=this._cadOriginalBackColor.clone()),this.edgeMaterial&&null!==this._cadEdgesVisible&&(this.edgeMaterial.visible=this._cadEdgesVisible),this._isStudioMode=!1)}setStudioShowEdges(t){this.edgeMaterial&&(this.edgeMaterial.visible=t)}}function lf(t){return null!=t&&"isObjectGroup"in t&&!0===t.isObjectGroup}class hf extends jn{expandByObject(t,e=!1){if(t.updateWorldMatrix(!1,!1),lf(t))return this.expandByObject(t.children[0],e),this;const i=function(t){return"geometry"in t&&t.geometry instanceof Ds?t.geometry:null}(t);if(null!==i)if(e&&void 0!==i.attributes&&void 0!==i.attributes.position)if(t.type.startsWith("LineSegment")){const e=i.clone();e.applyMatrix4(t.matrixWorld),e.boundingBox=null,e.computeBoundingBox(),this.union(e.boundingBox),e.dispose()}else{const e=i.attributes.position;for(let i=0,n=e.count;i<n;i++)df.fromBufferAttribute(e,i).applyMatrix4(t.matrixWorld),this.expandByPoint(df)}else null===i.boundingBox&&i.computeBoundingBox(),uf.copy(i.boundingBox),uf.applyMatrix4(t.matrixWorld),this.union(uf);const n=t.children;for(let t=0,i=n.length;t<i;t++){const i=n[t];"PlaneMeshes"===i.name&&i.children&&i.children.length>0&&i.children[0].type.startsWith("StencilPlane")||this.expandByObject(i,e)}return this}max_dist_from_center(){return Math.max(...this.min.toArray().concat(this.max.toArray()).map(t=>Math.abs(t)))}boundingSphere(){return this.getBoundingSphere(mf),mf}center(){return this.getCenter(df),Vm(df.toArray())}}class cf extends Ba{constructor(t,e=16776960){const i=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),n=new Float32Array(24),s=new Ds;s.setIndex(new ms(i,1)),s.setAttribute("position",new ms(n,3)),super(s,new Sa({color:e,toneMapped:!1})),this.object=t,this.type="BoxHelper",this.matrixAutoUpdate=!1,this.update()}update(){if(void 0!==this.object&&pf.setFromObject(this.object,!0),pf.isEmpty())return;const t=pf.min,e=pf.max,i=this.geometry.attributes.position,n=i.array;n[0]=e.x,n[1]=e.y,n[2]=e.z,n[3]=t.x,n[4]=e.y,n[5]=e.z,n[6]=t.x,n[7]=t.y,n[8]=e.z,n[9]=e.x,n[10]=t.y,n[11]=e.z,n[12]=e.x,n[13]=e.y,n[14]=t.z,n[15]=t.x,n[16]=e.y,n[17]=t.z,n[18]=t.x,n[19]=t.y,n[20]=t.z,n[21]=e.x,n[22]=t.y,n[23]=t.z,i.needsUpdate=!0,this.geometry.computeBoundingSphere()}setFromObject(t){return this.object=t,this.update(),this}dispose(){Ym(this.geometry)}}const df=new xi,uf=new hf,pf=new hf,mf=new bs,ff=new Set(["baseColorTexture","emissiveTexture","sheenColorTexture","specularColorTexture"]),gf=new Set(["map","emissiveMap","sheenColorMap","specularColorMap"]);class vf{constructor(){this._cache=new Map,this._inflight=new Map,this._textureLoader=null,this._disposed=!1,this.maxAnisotropy=16}async get(t,e){if(this._disposed)return Fm.warn("TextureCache.get() called after dispose"),null;if(!t)return null;const i=ff.has(e)?Ee:Te;return t.startsWith("data:")?this._getFromDataUri(t,i):this._getFromUrl(t,i)}dispose(){for(const[t,e]of this._cache)zm.untrack("texture",e),e.dispose(),Fm.debug(`Disposed texture: ${t}`);this._cache.clear(),this._inflight.clear()}disposeFull(){this._disposed=!0,this.dispose(),this._textureLoader=null,Fm.debug("TextureCache fully disposed")}async _getFromDataUri(t,e){const i=t,n=this._cache.get(i);if(n)return n.colorSpace=e,n;const s=this._inflight.get(i);if(s){const t=await s;return t.colorSpace=e,t}return this._loadAndCache(i,t,e)}async _getFromUrl(t,e){const i=this._cache.get(t);if(i)return i.colorSpace=e,i;const n=this._inflight.get(t);if(n){const t=await n;return t.colorSpace=e,t}return this._loadAndCache(t,t,e)}async _loadAndCache(t,e,i){const n=this._doLoad(e,i);this._inflight.set(t,n);try{const e=await n;if(this._disposed||!this._inflight.has(t))return e.dispose(),null;this._cache.set(t,e);const i=t.startsWith("data:")?`Texture (data URI, ${t.length} chars)`:`Texture: ${t}`;return zm.trackTexture(e,i),Fm.debug(`Loaded and cached texture: ${i}`),e}catch(e){if(this._disposed)return null;const i=t.startsWith("data:")?`data URI (${t.length} chars)`:t;return Fm.warn(`Failed to load texture "${i}":`,e instanceof Error?e.message:e),null}finally{this._inflight.delete(t)}}_doLoad(t,e){const i=this._ensureTextureLoader();return new Promise((n,s)=>{i.load(t,t=>{t.colorSpace=e,t.wrapS=$,t.wrapT=$,t.anisotropy=this.maxAnisotropy,n(t)},void 0,e=>{s(e instanceof Error?e:new Error(`Texture load failed: ${t.substring(0,100)}`))})})}_ensureTextureLoader(){return this._textureLoader||(this._textureLoader=new vh,Fm.debug("Created TextureLoader")),this._textureLoader}}function yf(t){return gf.has(t)?Ee:Te}const _f=new Set(["color","specularColor","sheenColor","emissive","attenuationColor"]),xf={color:"map",metalness:"metalnessMap",roughness:"roughnessMap",normal:"normalMap",emissive:"emissiveMap",specularIntensity:"specularIntensityMap",specularColor:"specularColorMap",clearcoat:"clearcoatMap",clearcoatRoughness:"clearcoatRoughnessMap",clearcoatNormal:"clearcoatNormalMap",transmission:"transmissionMap",sheenColor:"sheenColorMap",sheenRoughness:"sheenRoughnessMap",anisotropy:"anisotropyMap",iridescence:"iridescenceMap",iridescenceThickness:"iridescenceThicknessMap",ao:"aoMap",occlusion:"aoMap",thickness:"thicknessMap",opacity:"alphaMap"};class bf{constructor(t={}){this.defaultOpacity=t.defaultOpacity??1,this.metalness=t.metalness??.3,this.roughness=t.roughness??.65,this.edgeColor=t.edgeColor??7368816,this.transparent=t.transparent??!1}_createBaseProps(t){return{polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1,transparent:!0,opacity:this.transparent?this.defaultOpacity*t:t,depthWrite:!this.transparent,depthTest:!0,clipIntersection:!1}}createFrontFaceMaterial({color:t,alpha:e,visible:i=!0},n){const s=new Pl({...this._createBaseProps(e),color:t,metalness:this.metalness,roughness:this.roughness,flatShading:!1,side:0,visible:i});return zm.track("material",s,n??"MeshStandardMaterial (front face)"),s}createBackFaceStandardMaterial({color:t,alpha:e,polygonOffsetUnits:i=2,visible:n=!0},s){const r=new Pl({...this._createBaseProps(e),color:t,metalness:this.metalness,roughness:this.roughness,flatShading:!1,side:1,visible:n});return r.polygonOffsetUnits=i,zm.track("material",r,s??"MeshStandardMaterial (back face)"),r}createBackFaceBasicMaterial({color:t,alpha:e,polygonOffsetUnits:i=2,visible:n=!0},s){const r=new lr({...this._createBaseProps(e),color:t,side:1,visible:n});return r.polygonOffsetUnits=i,zm.track("material",r,s??"MeshBasicMaterial (back face)"),r}createBasicFaceMaterial({color:t,alpha:e,visible:i=!0},n){const s=new lr({...this._createBaseProps(e),color:t,side:0,visible:i});return zm.track("material",s,n??"MeshBasicMaterial (front face)"),s}createEdgeMaterial({lineWidth:t,color:e,vertexColors:i=!1,visible:n=!0,resolution:s},r){const a=new dm({linewidth:t,transparent:!0,depthWrite:!this.transparent,depthTest:!this.transparent,clipIntersection:!1,vertexColors:i,toneMapped:!1});return i||(a.color=new En(e??this.edgeColor)),a.visible=n,s&&a.resolution.set(s.width,s.height),zm.track("material",a,r??"LineMaterial (edges)"),a}createSimpleEdgeMaterial({color:t,visible:e=!0},i){const n=new Sa({color:t??this.edgeColor,depthWrite:!this.transparent,depthTest:!this.transparent,visible:e});return zm.track("material",n,i??"LineBasicMaterial (simple edges)"),n}createVertexMaterial({size:t,color:e,visible:i=!0},n){const s=new Fa({color:e??this.edgeColor,sizeAttenuation:!1,size:t,transparent:!0,clipIntersection:!1,visible:i});return zm.track("material",s,n??"PointsMaterial (vertices)"),s}createTextureMaterial({texture:t,visible:e=!0},i){const n=new lr({color:"#ffffff",map:t,side:2,visible:e});return zm.track("material",n,i??"MeshBasicMaterial (textured)"),n}async createStudioMaterial({materialDef:t,fallbackColor:e,fallbackAlpha:i,textureCache:n},s){const r=t,a=r.doubleSided?2:0;let o,l;if(r.color?"string"==typeof r.color?(o=new En(r.color),l=1):(o=(new En).setRGB(r.color[0],r.color[1],r.color[2],Ee),l=r.color[3]??1):(o=new En(e),l=i),r.unlit){const t=new lr({...this._createBaseProps(l),color:o,side:a});if(this._applyAlphaMode(t,r,l),r.map&&n){const e=await n.get(r.map,"baseColorTexture");e&&(t.map=e)}return zm.track("material",t,s??"MeshBasicMaterial (studio unlit)"),t}const h="BLEND"===r.alphaMode||!r.alphaMode&&l<1,c=new Il({color:o,metalness:r.metalness??0,roughness:r.roughness??.5,flatShading:!1,side:a,transparent:h,opacity:l,depthWrite:!h,depthTest:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});return this._applyAlphaMode(c,r,l),r.emissive&&(c.emissive=new En(r.emissive[0],r.emissive[1],r.emissive[2])),void 0!==r.emissiveIntensity&&(c.emissiveIntensity=r.emissiveIntensity),void 0!==r.transmission&&(c.transmission=r.transmission,r.transmission>0&&(c.transparent=!1,c.opacity=1,c.depthWrite=!0)),void 0!==r.clearcoat&&(c.clearcoat=r.clearcoat),void 0!==r.clearcoatRoughness&&(c.clearcoatRoughness=r.clearcoatRoughness),void 0!==r.thickness&&(c.thickness=r.thickness),void 0!==r.attenuationDistance&&(c.attenuationDistance=r.attenuationDistance),r.attenuationColor&&(c.attenuationColor=new En(r.attenuationColor[0],r.attenuationColor[1],r.attenuationColor[2])),void 0!==r.ior&&(c.ior=r.ior),void 0!==r.specularIntensity&&(c.specularIntensity=r.specularIntensity),r.specularColor&&(c.specularColor=new En(r.specularColor[0],r.specularColor[1],r.specularColor[2])),void 0!==r.sheen&&r.sheen>0&&(c.sheen=r.sheen,r.sheenColor&&(c.sheenColor=new En(r.sheenColor[0],r.sheenColor[1],r.sheenColor[2])),void 0!==r.sheenRoughness&&(c.sheenRoughness=r.sheenRoughness)),void 0!==r.anisotropy&&r.anisotropy>0&&(c.anisotropy=r.anisotropy,void 0!==r.anisotropyRotation&&(c.anisotropyRotation=r.anisotropyRotation)),n&&await this._applyStudioTextures(c,r,n),zm.track("material",c,s??"MeshPhysicalMaterial (studio)"),c}async createStudioMaterialFromMaterialX(t,e,i,n,s){const r={flatShading:!1,side:0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1,depthTest:!0};(e.displacement||void 0!==t.displacementScale)&&Fm.warn("Displacement not supported by the Studio");for(const[e,i]of Object.entries(t))if("displacement"!==e&&"displacementScale"!==e&&"displacementBias"!==e)if(_f.has(e)&&Array.isArray(i)){const[t,n,s]=i;r[e]=new En(t,n,s)}else"normalScale"!==e&&"clearcoatNormalScale"!==e||!Array.isArray(i)?("iridescenceThicknessRange"===e&&Array.isArray(i),r[e]=i):r[e]=new yi(i[0],i[1]);const a=t.transmission,o=t.opacity,l=t.transparent;"number"==typeof a&&a>0?(r.transparent=!1,r.opacity=1,r.depthWrite=!0):!0===l||"number"==typeof o&&o<1?(r.transparent=!0,r.depthWrite=!1):(r.transparent=!1,r.depthWrite=!0);const h=new Il(r);let c=!1;if(n)for(const[t,s]of Object.entries(e)){const e=xf[t];if(!e)continue;const r=yf(e)===Ee?"baseColorTexture":"normalTexture";let a=await n.get(s,r);a&&(!i||1===i[0]&&1===i[1]||(a=a.clone(),a.repeat.set(i[0],i[1])),h[e]=a,c=!0)}return h.alphaMap&&(h.alphaTest=.5,h.side=2),c&&(h.needsUpdate=!0),zm.track("material",h,s??"MeshPhysicalMaterial (threejs-materials)"),h}_applyAlphaMode(t,e,i){switch(e.alphaMode){case"OPAQUE":t.transparent=!1,t.opacity=1,t.depthWrite=!0;break;case"MASK":t.transparent=!1,t.alphaTest=e.alphaCutoff??.5,t.opacity=i,t.depthWrite=!0;break;case"BLEND":t.transparent=!0,t.opacity=i,t.depthWrite=!1}}async _applyStudioTextures(t,e,i){const n=async(t,e)=>t?i.get(t,e):null,s=await n(e.map,"baseColorTexture");s&&(t.map=s);const r=await n(e.emissiveMap,"emissiveTexture");r&&(t.emissiveMap=r);const a=await n(e.sheenColorMap,"sheenColorTexture");a&&(t.sheenColorMap=a);const o=await n(e.specularColorMap,"specularColorTexture");o&&(t.specularColorMap=o);const l=await n(e.normalMap,"normalTexture");l&&(t.normalMap=l);const h=await n(e.aoMap,"occlusionTexture");h&&(t.aoMap=h);const c=await n(e.metalnessMap,"metallicRoughnessTexture");c&&(t.metalnessMap=c);const d=await n(e.roughnessMap,"metallicRoughnessTexture");d&&(t.roughnessMap=d);const u=await n(e.transmissionMap,"transmissionTexture");u&&(t.transmissionMap=u);const p=await n(e.thicknessMap,"thicknessTexture");p&&(t.thicknessMap=p);const m=await n(e.clearcoatMap,"clearcoatTexture");m&&(t.clearcoatMap=m);const f=await n(e.clearcoatRoughnessMap,"clearcoatRoughnessTexture");f&&(t.clearcoatRoughnessMap=f);const g=await n(e.clearcoatNormalMap,"clearcoatNormalTexture");g&&(t.clearcoatNormalMap=g);const v=await n(e.specularIntensityMap,"specularIntensityTexture");v&&(t.specularIntensityMap=v);const y=await n(e.sheenRoughnessMap,"sheenRoughnessTexture");y&&(t.sheenRoughnessMap=y);const _=await n(e.anisotropyMap,"anisotropyTexture");_&&(t.anisotropyMap=_)}update(t){void 0!==t.metalness&&(this.metalness=t.metalness),void 0!==t.roughness&&(this.roughness=t.roughness),void 0!==t.transparent&&(this.transparent=t.transparent),void 0!==t.defaultOpacity&&(this.defaultOpacity=t.defaultOpacity),void 0!==t.edgeColor&&(this.edgeColor=t.edgeColor)}}const Sf=[0,1,2];function Mf(t){return 0===t||1===t||2===t}var wf;function Af(t){return"object"==typeof t&&null!==t&&"values"in t}function Ef(t){return void 0!==t.triangles_per_face}function Tf(t){return void 0!==t.segments_per_edge}t.CollapseState=void 0,(wf=t.CollapseState||(t.CollapseState={}))[wf.LEAVES=-1]="LEAVES",wf[wf.COLLAPSED=0]="COLLAPSED",wf[wf.ROOT=1]="ROOT",wf[wf.EXPANDED=2]="EXPANDED";const Cf={chrome:{name:"Chrome",color:[.98,.98,.98,1],metalness:1,roughness:.05},"polished-steel":{name:"Polished Steel",color:[.91,.91,.92,1],metalness:1,roughness:.1},"polished-aluminum":{name:"Polished Aluminum",color:[.916,.923,.924,1],metalness:1,roughness:.1},gold:{name:"Gold",color:[1,.93,0,1],metalness:1,roughness:.1},copper:{name:"Copper",color:[.98,.82,.76,1],metalness:1,roughness:.15},brass:{name:"Brass",color:[.95,.9,.7,1],metalness:1,roughness:.15},"stainless-steel":{name:"Stainless Steel",color:[.91,.91,.92,1],metalness:1,roughness:.4},"brushed-aluminum":{name:"Brushed Aluminum",color:[.916,.923,.924,1],metalness:1,roughness:.35,anisotropy:.5},"cast-iron":{name:"Cast Iron",color:[.68,.68,.69,1],metalness:.9,roughness:.7},titanium:{name:"Titanium",color:[.81,.79,.77,1],metalness:1,roughness:.45},galvanized:{name:"Galvanized",color:[.88,.88,.9,1],metalness:.8,roughness:.5},"plastic-glossy":{name:"Plastic (Glossy)",color:[.91,.91,.91,1],metalness:0,roughness:.4},"plastic-matte":{name:"Plastic (Matte)",color:[.91,.91,.91,1],metalness:0,roughness:.6},"abs-black":{name:"ABS Black",color:[.25,.25,.25,1],metalness:0,roughness:.4},nylon:{name:"Nylon",color:[.95,.94,.92,1],metalness:0,roughness:.55},"acrylic-clear":{name:"Acrylic (Clear)",color:[1,1,1,1],metalness:0,roughness:0,transmission:.95,ior:1.49},"glass-clear":{name:"Glass (Clear)",color:[1,1,1,1],metalness:0,roughness:0,transmission:1,ior:1.52,thickness:2},"glass-tinted":{name:"Glass (Tinted)",color:[.8,.91,.95,1],metalness:0,roughness:0,transmission:.9,ior:1.52,thickness:3},"glass-frosted":{name:"Glass (Frosted)",color:[1,1,1,1],metalness:0,roughness:.3,transmission:.85,ior:1.52,thickness:2},"rubber-black":{name:"Rubber (Black)",color:[.31,.31,.31,1],metalness:0,roughness:.9},"rubber-gray":{name:"Rubber (Gray)",color:[.63,.63,.63,1],metalness:0,roughness:.85},"rubber-red":{name:"Rubber (Red)",color:[.85,.35,.35,1],metalness:0,roughness:.8},"paint-matte":{name:"Paint (Matte)",color:[.91,.91,.91,1],metalness:0,roughness:.7},"paint-glossy":{name:"Paint (Glossy)",color:[.91,.91,.91,1],metalness:0,roughness:.15},"paint-metallic":{name:"Paint (Metallic)",color:[.91,.91,.91,1],metalness:.5,roughness:.25},"car-paint":{name:"Car Paint",color:[.91,0,0,1],metalness:.5,roughness:.2,clearcoat:1,clearcoatRoughness:.03},"ceramic-white":{name:"Ceramic (White)",color:[.98,.98,.97,1],metalness:0,roughness:.1},"carbon-fiber":{name:"Carbon Fiber",color:[.25,.25,.25,1],metalness:.3,roughness:.35,anisotropy:.3},concrete:{name:"Concrete",color:[.83,.82,.8,1],metalness:0,roughness:.85}},Df=Object.keys(Cf).sort(),Rf=[["#include <logdepthbuf_fragment>","\n#include <logdepthbuf_fragment>\ninitTriplanarUVs();\n"],["#include <map_fragment>","\n#ifdef USE_MAP\n vec4 sampledDiffuseColor = triplanarSample( map );\n #ifdef DECODE_VIDEO_TEXTURE\n sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );\n #endif\n diffuseColor *= sampledDiffuseColor;\n#endif\n"],["#include <roughnessmap_fragment>","\nfloat roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = triplanarSample( roughnessMap );\n roughnessFactor *= texelRoughness.g;\n#endif\n"],["#include <metalnessmap_fragment>","\nfloat metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = triplanarSample( metalnessMap );\n metalnessFactor *= texelMetalness.b;\n#endif\n"],["#include <emissivemap_fragment>","\n#ifdef USE_EMISSIVEMAP\n vec4 emissiveColor = triplanarSample( emissiveMap );\n #ifdef DECODE_VIDEO_TEXTURE_EMISSIVE\n emissiveColor = sRGBTransferEOTF( emissiveColor );\n #endif\n totalEmissiveRadiance *= emissiveColor.rgb;\n#endif\n"],["#include <aomap_fragment>","\n#ifdef USE_AOMAP\n float ambientOcclusion = ( triplanarSample( aoMap ).r - 1.0 ) * aoMapIntensity + 1.0;\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n #if defined( USE_CLEARCOAT )\n clearcoatSpecularIndirect *= ambientOcclusion;\n #endif\n #if defined( USE_SHEEN )\n sheenSpecularIndirect *= ambientOcclusion;\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n #endif\n#endif\n"],["#include <normal_fragment_maps>","\n#ifdef USE_NORMALMAP_OBJECTSPACE\n normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n #ifdef FLIP_SIDED\n normal = - normal;\n #endif\n #ifdef DOUBLE_SIDED\n normal = normal * faceDirection;\n #endif\n normal = normalize( normalMatrix * normal );\n\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n // Triplanar normal mapping: sample normal map 3x (one per projection axis),\n // swizzle each to model space, blend, and transform to view space.\n normal = normalize(normalMatrix * triplanarNormal(normalMap, normalScale));\n\n#elif defined( USE_BUMPMAP )\n normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n\n#endif\n"],["#include <clearcoat_normal_fragment_maps>","\n#ifdef USE_CLEARCOAT_NORMALMAP\n // Reuse triplanarNormal with clearcoat normal map and scale\n vec3 clearcoatModelNormal = triplanarNormal(clearcoatNormalMap, clearcoatNormalScale);\n clearcoatNormal = normalize(normalMatrix * clearcoatModelNormal);\n#endif\n"],["#include <alphamap_fragment>","\n#ifdef USE_ALPHAMAP\n diffuseColor.a *= triplanarSample( alphaMap ).g;\n#endif\n"]];function Pf(t,e){e.computeBoundingBox();const i=e.boundingBox,n=new xi;i.getSize(n);const s=Math.max(n.x,n.y,n.z,1e-6),r=i.min.clone(),a=1/s,o=(t.map??t.roughnessMap??t.normalMap??t.metalnessMap??t.emissiveMap??t.aoMap)?.repeat?.clone()??new yi(1,1);t.onBeforeCompile=t=>{t.uniforms.triplanarOffset={value:r},t.uniforms.triplanarScale={value:a},t.uniforms.triplanarRepeat={value:o},t.vertexShader=t.vertexShader.replace("#include <common>","#include <common>\n\nvarying vec3 vTriplanarPos;\nvarying vec3 vTriplanarNormal;\n"),t.vertexShader=t.vertexShader.replace("#include <worldpos_vertex>","#include <worldpos_vertex>\n vTriplanarPos = transformed;\n vTriplanarNormal = normalize(objectNormal);"),t.fragmentShader=t.fragmentShader.replace("#include <common>",'#include <common>\n\nvarying vec3 vTriplanarPos;\nvarying vec3 vTriplanarNormal;\nuniform vec3 triplanarOffset;\nuniform float triplanarScale;\nuniform vec2 triplanarRepeat;\n\n// normalMatrix is only declared in the fragment shader for object-space\n// normal maps. We need it for triplanar tangent-space normal mapping too.\n#ifndef USE_NORMALMAP_OBJECTSPACE\nuniform mat3 normalMatrix;\n#endif\n\n// --- Global triplanar state (computed once, reused by all samples) ---\nvec2 tri_uvX, tri_uvY, tri_uvZ;\nvec3 tri_blend;\n\n// Initialize global triplanar UVs and blend weights from varyings.\n// Must be called before any texture sampling.\nvoid initTriplanarUVs() {\n tri_blend = abs(vTriplanarNormal);\n tri_blend = pow(tri_blend, vec3(3.0));\n tri_blend /= (tri_blend.x + tri_blend.y + tri_blend.z);\n vec3 p = (vTriplanarPos - triplanarOffset) * triplanarScale;\n vec2 r = triplanarRepeat;\n tri_uvX = p.yz * r;\n tri_uvY = p.xz * r;\n tri_uvZ = p.xy * r;\n}\n\n// Sample a texture using the global triplanar UVs and blend weights.\nvec4 triplanarSample(sampler2D tex) {\n return texture2D(tex, tri_uvX) * tri_blend.x\n + texture2D(tex, tri_uvY) * tri_blend.y\n + texture2D(tex, tri_uvZ) * tri_blend.z;\n}\n\n// Surface-gradient triplanar normal mapping.\n// Instead of constructing full 3D normals per axis (which creates faceted\n// shading at axis boundaries), we extract the tangent-space perturbation (xy)\n// from each axis sample, project it into model space as a gradient, blend\n// the gradients, and add to the geometric normal. Gradients blend smoothly.\n// Ref: Morten Mikkelsen, "Surface Gradient Based Bump Mapping Framework"\n//\n// normalScale is declared in normalmap_pars_fragment (after this header),\n// so we accept it as a parameter to avoid forward-reference errors.\nvec3 triplanarNormal(sampler2D normalTex, vec2 nScale) {\n vec3 N = vTriplanarNormal;\n\n // Sample tangent-space normals for each projection axis\n vec3 tnX = texture2D(normalTex, tri_uvX).xyz * 2.0 - 1.0;\n vec3 tnY = texture2D(normalTex, tri_uvY).xyz * 2.0 - 1.0;\n vec3 tnZ = texture2D(normalTex, tri_uvZ).xyz * 2.0 - 1.0;\n\n // Apply normal scale to perturbation components\n tnX.xy *= nScale;\n tnY.xy *= nScale;\n tnZ.xy *= nScale;\n\n // Project each tangent-space perturbation (xy) into model space.\n // X proj: UV=(y,z) -> tangent=(0,1,0), bitangent=(0,0,1) -> grad=(0, tx, ty)\n // Y proj: UV=(x,z) -> tangent=(1,0,0), bitangent=(0,0,1) -> grad=(tx, 0, ty)\n // Z proj: UV=(x,y) -> tangent=(1,0,0), bitangent=(0,1,0) -> grad=(tx, ty, 0)\n vec3 surfGrad =\n vec3(0.0, tnX.x, tnX.y) * tri_blend.x +\n vec3(tnY.x, 0.0, tnY.y) * tri_blend.y +\n vec3(tnZ.x, tnZ.y, 0.0) * tri_blend.z;\n\n return normalize(N + surfGrad);\n}\n');for(const[e,i]of Rf)t.fragmentShader=t.fragmentShader.replace(e,i)},t.customProgramCacheKey=()=>"triplanar"}function If(t){return"parts"in t}class Lf extends _n{constructor(){super(...arguments),this.type="CompoundGroup",this.isCompoundGroup=!0}}const Bf=["map","normalMap","aoMap","metalnessMap","roughnessMap","emissiveMap","transmissionMap","clearcoatMap","clearcoatRoughnessMap","clearcoatNormalMap","thicknessMap","specularIntensityMap","specularColorMap","sheenColorMap","sheenRoughnessMap","anisotropyMap"];function Of(t){for(const e of Bf)if(t[e])return!0;return!1}function Ff(t){return Object.keys(t.textures).length>0}class Nf{constructor(t,e,i,n,s,r,a,o,l,h=0){this.shapes=t,this.width=e,this.height=i,this.edgeColor=n,this.transparent=s,this.metalness=a,this.roughness=o,this.defaultOpacity=r,this.normalLen=l,this.blackEdges=!1,this.backVisible=!1,this.bb_max=h,this.delim="|",this.rootGroup=null,this.instances=null,this.bbox=null,this.bsphere=null,this.groups={},this.clipPlanes=null,this.materialsTable=null,this.resolvedMaterials=new Map,this.resolvedMaterialX=new Map,this._textureCache=null,this._studioMaterialCache=new Map,this._texturedMaterialKeys=new Set,this._isStudioMode=!1,this.materialFactory=new bf({defaultOpacity:r,metalness:a,roughness:o,edgeColor:n,transparent:s})}dispose(){Object.keys(this.groups).length>0&&(Qm(Object.values(this.groups)),this.groups={}),this.rootGroup&&(Qm(this.rootGroup),this.rootGroup=null),this._disposeStudioResources(),this.resolvedMaterials.clear(),this.resolvedMaterialX.clear(),this.materialsTable=null}resolveMaterialTag(t,e){if(""===t)return null;const i=this.resolvedMaterials.get(t);if(void 0!==i)return i;const n=this.resolvedMaterialX.get(t);if(void 0!==n)return n;if(this.materialsTable&&t in this.materialsTable){const i=this.materialsTable[t];if("string"==typeof i){if(i.startsWith("builtin:")){const n=i.slice(8),s=Cf[n];if(s){const e={...s};return this.resolvedMaterials.set(t,e),e}return Fm.warn(`Unknown builtin preset '${n}' referenced by '${t}' on '${e}'`),null}return Fm.warn(`Invalid material string '${i}' for tag '${t}' (expected "builtin:" prefix)`),null}if(Af(i))return this.resolvedMaterialX.set(t,i),i;if("object"==typeof i&&"builtin"in i){const n=i,s=n.builtin,r=Cf[s];if(!r)return Fm.warn(`Unknown builtin preset '${s}' referenced by '${t}' on '${e}'`),null;const{color:a,...o}=r,l="color"in n?{...r,...n}:{...o,...n};return this.resolvedMaterials.set(t,l),l}return Fm.warn(`Unrecognised material entry for tag '${t}' on '${e}'`),null}const s=Cf[t];if(s){const e={...s};return this.resolvedMaterials.set(t,e),e}return Fm.warn(`Unknown material tag '${t}' on object '${e}'`),null}_isNestedArray(t){return t.length>0&&Array.isArray(t[0])}_toFloat32Array(t,e=1){return t instanceof Float32Array?t:this._isNestedArray(t)?new Float32Array(Hm(t,e)):new Float32Array(t)}_toUint32Array(t,e=1){return t instanceof Uint32Array?t:this._isNestedArray(t)?new Uint32Array(Hm(t,e)):new Uint32Array(t)}_renderEdges(t,e,i,n,s){const r=this._toFloat32Array(t,3),a=zm.trackGeometry(new Dm,s?`LineSegmentsGeometry for ${s}`:"LineSegmentsGeometry (edges)");if(a.setPositions(r),Array.isArray(i)){const t=i.map(t=>{const e=new En(t);return[e.r,e.g,e.b,e.r,e.g,e.b]}).flat();a.setColors(new Float32Array(t))}const o=this.materialFactory.createEdgeMaterial({lineWidth:e,color:Array.isArray(i)?null:i??this.edgeColor,vertexColors:Array.isArray(i),visible:1==n,resolution:{width:this.width,height:this.height}},s?`LineMaterial for ${s}`:"LineMaterial (edges)"),l=new Cm(a,o);return l.renderOrder=999,l}renderEdges(t,e,i,n,s,r,a=null){const o=Array.isArray(i)?this.edgeColor:i??this.edgeColor,l=new of(this.defaultOpacity,1,o,a,"edges"),h=this._renderEdges(t.edges,e,i,r,n);return s&&(h.name=s),l.setEdges(h),this.groups[n]=l,l.name=n.replaceAll("/",this.delim),l}renderVertices(t,e,i,n,s,r,a=null){const o=new of(this.defaultOpacity,1,i??this.edgeColor,a,"vertices"),l=this._toFloat32Array(t.obj_vertices),h=zm.trackGeometry(new Ds,`BufferGeometry (vertices) for ${n}`);h.setAttribute("position",new vs(l,3));const c=this.materialFactory.createVertexMaterial({size:e,color:i,visible:1==r},`PointsMaterial for ${n}`),d=new Ga(h,c);return s&&(d.name=s),o.setVertices(d),this.groups[n]=o,o.name=n.replaceAll("/",this.delim),o}renderShape(t,e,i,n,s,r,a,o,l=null,h=null,c=null,d=null,u=null){const p=this._toFloat32Array(t.vertices),m=this._toFloat32Array(t.normals),f=this._toUint32Array(t.triangles),g=new of(this.defaultOpacity,i??1,this.edgeColor,l,h,n);let v;this.groups[r]=g,g.name=r.replaceAll("/",this.delim),null==i?i=1:i<1&&(this.transparent=!0);let y,_=null;if(null!=c){const t=`data:image/${c.format};base64,${c.data}`,e=new Image;v=zm.trackGeometry(new pl(d,u),`PlaneGeometry (textured) for ${r}`),_=zm.trackTexture(new Ui(e),`Texture for ${r}`),_.colorSpace=Ee,e.onload=()=>{_.needsUpdate=!0},e.src=t,y=this.materialFactory.createTextureMaterial({texture:_},`MeshBasicMaterial (textured) for ${r}`),n=!1}else{if(v=zm.trackGeometry(new Ds,`BufferGeometry (shape) for ${r}`),v.setAttribute("position",new ms(p,3)),v.setAttribute("normal",new ms(m,3)),v.setIndex(new ms(f,1)),t.uvs&&t.uvs.length>0){const e=t.uvs instanceof Float32Array?t.uvs:new Float32Array(t.uvs);v.setAttribute("uv",new ms(e,2))}g.shapeGeometry=v,y=this.materialFactory.createFrontFaceMaterial({color:e,alpha:i,visible:1==o[0]},`MeshStandardMaterial (front) for ${r}`),y.name="frontMaterial"}const x="solid"!==g.subtype||s?new En(this.edgeColor).lerp(new En(1,1,1),.15).getHex():e,b=this.materialFactory.createBackFaceBasicMaterial({color:x,alpha:i,visible:1==o[0]&&(n||this.backVisible)},`MeshBasicMaterial (back) for ${r}`);b.name="backMaterial";const S=new xr(v,b);S.name=a;const M=new xr(v,y);if(M.name=a,i<1&&(S.renderOrder=999,M.renderOrder=999),null==M.geometry.boundingBox&&M.geometry.computeBoundingBox(),g.setBack(S),g.setFront(M),this.normalLen>0){const t=new Lm(M,this.normalLen,16711935);g.add(t)}const w=t.edges;if(w&&w.length>0){const t=this._renderEdges(w,1,null,o[1],r);t.name=a,g.setEdges(t)}return g}_createEdgesFromPolygons(t,e){const i=[],n=[];let s=0;for(let r=0;r<t.length;r++){const a=t[r].getPoints(),o=a.map(t=>new xi(t.x,t.y,0)),l=a.map(t=>new xi(t.x,t.y,e)),h=t=>{for(let e=0;e<t.length;e++){const i=(e+1)%t.length;n.push(s+e,s+i)}i.push(...t),s+=t.length};h(o),h(l);for(let t=0;t<a.length;t++)n.push(s-2*a.length+t,s-a.length+t)}const r=new Ds;return r.setFromPoints(i),r.setIndex(n),r}renderPolygons(t,e,i,n,s,r,a,o,l,h=null,c=null){const d=new of(this.defaultOpacity,1,this.edgeColor,h,c,s);d.name=a.replaceAll("/",this.delim),d.minZ=e,d.height=t.height,this.groups[a]=d;const u=[];let p;p=t.matrices&&t.matrices.length>0?t.matrices:[1,0,0,0,1,0];for(const e of t.refs){const t=this.instances[e],i=t.length/2,n=new Array(i);for(let e=0;e<p.length/6;e++){const s=p[6*e],r=p[6*e+1],a=p[6*e+2],o=p[6*e+3],l=p[6*e+4],h=p[6*e+5];for(let e=0;e<i;e++)n[e]=new yi(s*t[2*e]+r*t[2*e+1]+a,o*t[2*e]+l*t[2*e+1]+h);const c=new Po(n);u.push(c)}}const m={depth:t.height,bevelEnabled:!1},f=zm.trackGeometry(new ll(u,m),`ExtrudeGeometry (polygon) for ${a}`),g=this.materialFactory.createFrontFaceMaterial({color:i,alpha:n,visible:1==l[0]},`MeshStandardMaterial (front polygon) for ${a}`);g.name="frontMaterial";const v=this.materialFactory.createBackFaceStandardMaterial({color:i,alpha:n,visible:1==l[0]&&(s||this.backVisible)},`MeshStandardMaterial (back polygon) for ${a}`);v.name="backMaterial";const y=new xr(f,v);y.name=o;const _=new xr(f,g);_.name=o;const x=zm.trackGeometry(this._createEdgesFromPolygons(u,t.height),`BufferGeometry (polygon edges) for ${a}`),b=this.materialFactory.createSimpleEdgeMaterial({},`LineBasicMaterial (polygon edges) for ${a}`),S=new Ba(x,b);return d.shapeGeometry=f,d.setFront(_),d.setBack(y),d.setEdges(S),d}renderLoop(t){const e=(t,e,i,n)=>{let s;switch(t.type){case"edges":s=this.renderEdges(t.shape,t.width,t.color,t.id,t.name,t.state[1],{topo:"edge",geomtype:t.geomtype||null});break;case"vertices":s=this.renderVertices(t.shape,t.size,t.color??null,t.id,t.name,t.state[1],{topo:"vertex",geomtype:null});break;case"polygon":s=this.renderPolygons(t.shape,t.loc[0][2],t.color??this.edgeColor,1,null!=t.renderback&&t.renderback,!1,t.id,t.name,t.state,{topo:"face",geomtype:t.geomtype||null},t.subtype||null);break;default:{const r=Array.isArray(t.color)?t.color[0]:t.color;s=this.renderShape(t.shape,r??this.edgeColor,t.alpha??null,null!=t.renderback&&t.renderback,t.exploded??!1,t.id,t.name,t.state,{topo:"face",geomtype:t.geomtype||null},t.subtype||null,e,i,n)}}return null!=t.loc&&(s.position.set(...t.loc[0]),s.quaternion.set(...t.loc[1])),s},i=new Lf;null==t.loc&&(t.loc=[[0,0,0],[0,0,0,1]]),i.position.set(...t.loc[0]),i.quaternion.set(...t.loc[1]),this.groups[t.id]=i,i.name=t.id.replaceAll("/","|");for(const n of t.parts)if(If(n))i.add(this.renderLoop(n));else{const t=n,s=n.material;null!=s&&(t.material=s);const r=null!=t.texture,a=e(t,r?t.texture.image:null,r?t.texture.width:null,r?t.texture.height:null);this.groups[t.id]=a,void 0!==t.material&&null!==t.material&&(a.materialTag=t.material),i.add(a)}return i}render(){return"GDS"==this.shapes.format&&(this.instances=this.shapes.instances||null),this.materialsTable=this.shapes.materials||null,this.resolvedMaterials.clear(),this.resolvedMaterialX.clear(),this.rootGroup=this.renderLoop(this.shapes),this.rootGroup}boundingBox(){return null==this.bbox&&(this.bbox=new hf,this.bbox.setFromObject(this.rootGroup,!1)),this.bbox}_traverse(t,e){for(const i in this.groups){const n=this.groups[i];if(n instanceof of){const i=n[t];"function"==typeof i&&i.call(n,e)}}}selection(){const t=[];for(const e in this.groups)for(const i of this.groups[e].children)i instanceof of&&i.isSelected&&t.push(i);return t}clearSelection(){for(const t of this.selection())t.clearHighlights()}setMetalness(t){this.metalness=t,this.materialFactory.update({metalness:t}),this._traverse("setMetalness",t)}setRoughness(t){this.roughness=t,this.materialFactory.update({roughness:t}),this._traverse("setRoughness",t)}setTransparent(t){this.transparent=t,this.materialFactory.update({transparent:t}),this._traverse("setTransparent",t)}setBlackEdges(t){this.blackEdges=t,this._traverse("setBlackEdges",t)}setBackVisible(t){this.backVisible=t,this._traverse("setBackVisible",t)}setEdgeColor(t){this.edgeColor=t,this._traverse("setEdgeColor",t)}setOpacity(t){this.defaultOpacity=t,this._traverse("setOpacity",t)}setClipIntersection(t){this._traverse("setClipIntersection",t)}setClipPlanes(t){this.clipPlanes=t,this._traverse("setClipPlanes",t)}setPolygonOffset(t){this._traverse("setPolygonOffset",t)}setZScale(t){this._traverse("setZScale",t)}setMinZ(){this._traverse("setMinZ")}updateMaterials(){this._traverse("updateMaterials",!0)}setZebra(t){this._traverse("setZebra",t)}setZebraCount(t){this._traverse("setZebraCount",t)}setZebraOpacity(t){this._traverse("setZebraOpacity",t)}setZebraDirection(t){this._traverse("setZebraDirection",t)}setZebraColorScheme(t){this._traverse("setZebraColorScheme",t)}setZebraMappingMode(t){this._traverse("setZebraMappingMode",t)}async enterStudioMode(t="triplanar"){this._textureCache||(this._textureCache=new vf);const e=new Set;for(const i in this.groups){const n=this.groups[i];if(!(n instanceof of))continue;if(!n.front)continue;const s=n.materialTag||"",r=n.originalColor?"#"+n.originalColor.getHexString():"#707070",a=n.alpha,o=`${s}:${r}:${a}`;let l=this._studioMaterialCache.get(o);if(!l){const t=s?this.resolveMaterialTag(s,i):null;s&&!t&&e.add(s);try{if(t&&Af(t))l=await this.materialFactory.createStudioMaterialFromMaterialX(t.values,t.textures,t.textureRepeat,this._textureCache),Ff(t)&&this._texturedMaterialKeys.add(o);else{let e;if(t)e=t;else if(a<1){const{color:t,...i}=Cf["acrylic-clear"];e={...i,transmission:1-a}}else{const{color:t,...i}=Cf["plastic-glossy"];e=i}l=await this.materialFactory.createStudioMaterial({materialDef:e,fallbackColor:r,fallbackAlpha:a,textureCache:this._textureCache}),Of(e)&&this._texturedMaterialKeys.add(o)}}catch(t){Fm.warn(`Studio material creation failed for "${i}" (tag="${s}"), skipping`,t);continue}this._studioMaterialCache.set(o,l)}const h=this._texturedMaterialKeys.has(o),c=null!=n.shapeGeometry?.getAttribute("uv"),d=h&&null!=n.shapeGeometry&&("triplanar"===t||!c);if(h&&Fm.debug(`Studio "${i}": ${d?"using triplanar":"using parametric UVs"}`),d&&l instanceof Il){const t=`${o}:tri:${i}`;let e=this._studioMaterialCache.get(t);e||(e=l.clone(),Pf(e,n.shapeGeometry),this._studioMaterialCache.set(t,e)),l=e}let u=null;if(n.renderback&&l instanceof Il){const t=d?`${o}:tri:${i}:back`:`${o}:back`;let e=this._studioMaterialCache.get(t);e||(e=l.clone(),e.side=1,d&&n.shapeGeometry&&Pf(e,n.shapeGeometry),this._studioMaterialCache.set(t,e)),u=e}if(l instanceof Il&&l.anisotropy>0&&null!=n.shapeGeometry?.getAttribute("uv")&&null==n.shapeGeometry.getAttribute("tangent"))try{n.shapeGeometry.computeTangents()}catch{Fm.debug(`Studio "${i}": tangent computation failed, anisotropy may have artifacts`)}n.enterStudioMode(l instanceof Il?l:null,u)}return this._isStudioMode=!0,[...e]}leaveStudioMode(){for(const t in this.groups){const e=this.groups[t];e instanceof of&&e.leaveStudioMode()}this._isStudioMode=!1}clearStudioMaterialCache(){for(const[,t]of this._studioMaterialCache)t.dispose();this._studioMaterialCache.clear(),this._texturedMaterialKeys.clear()}setStudioShowEdges(t){for(const e in this.groups){const i=this.groups[e];i instanceof of&&i.setStudioShowEdges(t)}}_disposeStudioResources(){this._isStudioMode&&this.leaveStudioMode();for(const[,t]of this._studioMaterialCache)t.dispose();this._studioMaterialCache.clear(),this._texturedMaterialKeys.clear(),this._textureCache&&(this._textureCache.disposeFull(),this._textureCache=null),this._isStudioMode=!1}}function Uf(t){let e=t.replace(/(\.\d*[1-9])0+$/,"$1").replace(/\.0+$/,"");return"-0"===e&&(e="0"),e.indexOf(".")<0&&(e=`${e}.0`),e}class kf extends yn{constructor(t,e,i,n,s){super();const r=t/e,a=t/2,o=[],l=[],h=[];let c=!1,d=!1;for(let t=0;t<=e;t++){const e=t*r-a,i=Math.abs(e)<1e-10;i?d||(h.push(-a,0,0,a,0,0),d=!0):o.push(-a,0,e,a,0,e),i?c||(l.push(0,0,-a,0,0,a),c=!0):o.push(e,0,-a,e,0,a)}d||h.push(-a,0,0,a,0,0),c||l.push(0,0,-a,0,0,a);const u=new Ds;u.setAttribute("position",new vs(o,3));const p=u.getAttribute("position"),m=new Float32Array(p.count);for(let t=0;t<p.count;t+=2){const e=p.getX(t),i=p.getY(t),n=p.getZ(t),s=p.getX(t+1),r=p.getY(t+1),a=p.getZ(t+1);m[t]=0,m[t+1]=Math.sqrt((s-e)**2+(r-i)**2+(a-n)**2)}u.setAttribute("lineDistance",new ms(m,1));const f=new zl({color:s,dashSize:r/20,gapSize:r/20,opacity:1,transparent:!1,vertexColors:!1}),g=new Ba(u,f);this.add(g);const v=new Ds;v.setAttribute("position",new vs(l,3));const y=new Sa({color:i});this.add(new Ba(v,y));const _=new Ds;_.setAttribute("position",new vs(h,3));const x=new Sa({color:n});this.add(new Ba(_,x))}}class zf extends _n{constructor(t){super();const e=["bbox","gridFontSize","grid","theme","cadWidth","height","maxAnisotropy","getCamera","getAxes0"];for(const i of e)if(void 0===t[i])throw new Error(`Grid: required option "${i}" is missing`);const{bbox:i,ticks:n=5,gridFontSize:s,centerGrid:r,axes0:a,grid:o,flipY:l,theme:h,cadWidth:c,height:d,maxAnisotropy:u,tickValueElement:p,tickInfoElement:m,getCamera:f,getAxes0:g,onGridChange:v}=t;this.ticks=n,this.ticks0=n,this.gridFontSize=s,this.bbox=i,this.centerGrid=r||!1,this.axes0=a||!1,this.grid=o,this.allGrid=!!(o[0]||o[1]||o[2]),this.theme=h,this.flipY=l||!1,this.lastZoomIndex=0,this.lastFontIndex=50,this.cadWidth=c,this.height=d,this.maxAnisotropy=u,this.tickValue=p||null,this.info=m||null,this.getCamera=f,this.getAxes0=g,this.onGridChange=v||null;const y=i.max_dist_from_center(),_=Math.min(c,d),x=Math.max(1,6-Math.log2(_/100));this.minFontIndex=Math.round((y<2?6:y<1e3?5:3)*x),this.minZoomIndex=-4,this.zoomMaxIndex=5,this.canvasHeight=128,this.geomCache={},this.textureAspectRatios={},this.labelCache={},this.materialCache={},this.size=0,this.delta=0,this.colors={dark:["#ff4500","#32cd32","#3b9eff"],light:["#ff4500","#32cd32","#3b9eff"]},this.create()}calculateTextScale(t){const e=this.getCamera();if(!e)return t;const i=this.height,n=(r=.8,a=800,o=1,((l=i)<(s=300)?r:l>a?o:(o-r)/(a-s)*(l-s)+r)*t);var s,r,a,o,l;if(e instanceof Fh){return n/(i/((e.top-e.bottom)/e.zoom))*1.6}return n/i*.6}scaleLabels(){for(const t of this.children)if(t instanceof _n)for(let e=1;e<t.children.length;e++){const i=t.children[e];if(!(i instanceof qs))continue;const n=this.calculateTextScale(this.gridFontSize),s=i.userData.aspectRatio||4;i.scale.set(n*s,n,1)}}showLabels(t){for(const e of this.children)if(e instanceof _n)for(let i=1;i<e.children.length;i++)e.children[i].visible=t}async update(t,e=!1,i=null){if(!this.getVisible())return;i&&(this.theme=i);let n=Math.round(Math.log2(.4*t));if(Math.abs(n)<1e-6&&(n=0),e||n!=this.lastZoomIndex&&n<this.zoomMaxIndex&&n>this.minZoomIndex){Qm(this.children),this.children=[];const t=this.ticks0/2*2**n;this.ticks=Math.round(2*t),await this.create(!1),this.lastZoomIndex=n,e=!0}const s=Math.round(50*t);(e||s!=this.lastFontIndex)&&(s<this.minFontIndex?this.showLabels(!1):(this.getCamera()instanceof Fh&&this.scaleLabels(),this.showLabels(!0)),this.lastFontIndex=s)}async create(t=!0){if(t){const t=Math.max(Math.abs(this.bbox.max.x),Math.abs(this.bbox.max.y),Math.abs(this.bbox.max.z),Math.abs(this.bbox.min.x),Math.abs(this.bbox.min.y),Math.abs(this.bbox.min.z)),[e,i,n]=this.niceBounds(1.05*-t,1.05*t,this.ticks);this.size=i-e,this.ticks=this.size/n,this.ticks0=this.ticks,this.delta=n}else this.delta=this.size/this.ticks;this.setTickInfo();for(let t=0;t<3;t++){const e=new Lf;let i;e.name=`GridHelper-${t}`,e.add(new kf(this.size,2*this.ticks,this.colors[this.theme][0===t?1:1===t?0:2],this.colors[this.theme][0===t?0:1===t?2:1],"dark"==this.theme?125269879:12303291));for(let n=-this.size/2;n<=this.size/2;n+=this.delta/2){if(Math.abs(n)<1e-6)continue;let s=Uf(n.toFixed(4));n>0&&(s="+"+s),i=this.createLabel(s,n,t,!0),e.add(i),i=this.createLabel(s,n,t,!1),e.add(i)}this.add(e)}this.children[0].rotateX(Math.PI/2),this.children[1].rotateY(Math.PI/2),this.children[2].rotateZ(Math.PI/2),this.setCenter(this.axes0,this.flipY),this.scaleLabels(),this.setCenter(this.getAxes0(),this.flipY),this.setVisible()}createTextTexture(t){if(this.geomCache[t])return this.geomCache[t];const e=document.createElement("canvas"),i=e.getContext("2d",{alpha:!0,desynchronized:!1,willReadFrequently:!1}),n=`${"dark"===this.theme?"500":"560"} 80px Verdana, Arial, sans-serif`;i.font=n;const s=i.measureText(t).width,r=Math.round(s+40),a=this.canvasHeight;e.width=r,e.height=a,i.textRendering="optimizeLegibility",i.font=n,i.textAlign="center",i.textBaseline="middle",i.clearRect(0,0,e.width,e.height);const o=e.width/2,l=e.height/2;i.lineWidth=12,i.lineJoin="round",i.miterLimit=2,i.strokeStyle="dark"===this.theme?"#444444":"#ffffff",i.strokeText(t,o,l),i.fillStyle="dark"===this.theme?"#aaaaaa":"#333333",i.fillText(t,o,l);const h=new Xa(e);return h.needsUpdate=!0,h.colorSpace="dark"===this.theme?Ee:Te,h.minFilter=rt,h.magFilter=rt,h.generateMipmaps=!1,h.anisotropy=this.maxAnisotropy,h.premultiplyAlpha=!1,h.wrapS=tt,h.wrapT=tt,this.geomCache[t]=h,this.textureAspectRatios[t]=r/a,h}createLabel(t,e,i,n){const s=`${t}_${i}_${n}`;if(this.labelCache[s]){const t=this.labelCache[s],e=new qs(t.material);return e.position.copy(t.position),e.scale.copy(t.scale),e.userData.aspectRatio=t.userData.aspectRatio,e}const r=this.createTextTexture(t);let a=0;a=0===i?0:1===i?n?Math.PI/2:0:n?0:Math.PI/2;const o=`${t}_${i}_${n}`;let l=this.materialCache[o];l||(l=new Fs({map:r,transparent:!0,depthTest:!0,depthWrite:!1,blending:1,rotation:a,sizeAttenuation:!1}),this.materialCache[o]=l);const h=new qs(l);let c;c=0===i?n?1:-1:1===i&&n?-1:1,n?h.position.set(c*e,0,0):h.position.set(0,0,c*e);const d=this.textureAspectRatios[t]||4;return h.scale.set(d,1,1),h.userData.aspectRatio=d,this.labelCache[s]=h,h}niceBounds(t,e,i){i||(i=8);const n=Math.max(Math.abs(t),Math.abs(e));if(0===n)return[0,0,0];const s=n/i,r=Math.floor(Math.log10(s)),a=Math.pow(10,r),o=s/a;let l;l=o<=1?1:o<=2?2:o<=2.5?2.5:o<=5?5:10;const h=l*a,c=h*Math.ceil(n/h);return[-c,c,h]}computeGrid(){this.allGrid=!!(this.grid[0]||this.grid[1]||this.grid[2]),this.onGridChange&&this.onGridChange(this.allGrid,this.grid),this.setVisible()}setGrid(t,e=null){switch(t){case"grid":this.allGrid=null==e?!this.allGrid:e,this.grid[0]=this.allGrid,this.grid[1]=this.allGrid,this.grid[2]=this.allGrid;break;case"grid-xy":this.grid[0]=!this.grid[0];break;case"grid-xz":this.grid[1]=!this.grid[1];break;case"grid-yz":this.grid[2]=!this.grid[2]}this.computeGrid()}setGrids(t,e,i){this.grid[0]=t,this.grid[1]=e,this.grid[2]=i,this.computeGrid()}setCenter(t,e){const i=t?[0,0,0]:this.bbox.center();this.children.forEach(t=>t.position.set(i[0],i[1],i[2])),this.centerGrid||(this.children[0].position.z-=this.size/2,this.children[1].position.y-=(e?-1:1)*this.size/2,this.children[2].position.x-=this.size/2)}setVisible(){this.children.forEach((t,e)=>{t.visible=this.grid[e]}),this.info&&(this.info.style.display=this.allGrid?"block":"none")}setTickInfo(){this.tickValue&&(this.tickValue.innerText=Uf((this.delta/2).toFixed(4)))}getVisible(){return this.allGrid}clearCache(){if(Object.keys(this.geomCache).length>0){for(const t of Object.keys(this.geomCache)){this.geomCache[t].dispose()}this.geomCache={}}if(this.textureAspectRatios={},this.materialCache&&Object.keys(this.materialCache).length>0){for(const t of Object.keys(this.materialCache)){this.materialCache[t].dispose()}this.materialCache={}}Object.keys(this.labelCache).length>0&&(this.labelCache={})}dispose(){this.clearCache()}}class Gf extends Cm{constructor(t,e,i,n,s,r,a,o){const l=new Float32Array([0,0,0,e,0,0,0,0,0,0,e,0,0,0,0,0,0,e]),h=new Dm;h.setPositions(l);const c=new dm({vertexColors:!0,toneMapped:!1,linewidth:i,transparent:!0});c.resolution.set(n,s),super(h,c),this.colors={dark:[1,69/255,0,1,69/255,0,50/255,205/255,50/255,50/255,205/255,50/255,59/255,158/255,1,59/255,158/255,1],light:[1,0,0,1,0,0,0,.5,0,0,.5,0,0,0,1,0,0,1]},h.setColors(new Float32Array(this.colors[o])),this.geometry=h,this.center=t,this.type="AxesHelper",this.name="AxesHelper",this.visible=a,this.setCenter(r)}setCenter(t){t?this.position.set(0,0,0):this.position.set(this.center[0],this.center[1],this.center[2])}setVisible(t){this.visible=t}changeTheme(t){this.geometry.setColors(new Float32Array(this.colors[t]))}}class Hf{constructor(t){this.isFont=!0,this.type="Font",this.data=t}generateShapes(t,e=100,i="ltr"){const n=[],s=function(t,e,i,n){const s=Array.from(t),r=e/i.resolution,a=(i.boundingBox.yMax-i.boundingBox.yMin+i.underlineThickness)*r,o=[];let l=0,h=0;"rtl"!=n&&"tb"!=n||s.reverse();for(let t=0;t<s.length;t++){const e=s[t];if("\n"===e)l=0,h-=a;else{const t=Vf(e,r,l,h,i);"tb"==n?(l=0,h+=i.ascender*r):l+=t.offsetX,o.push(t.path)}}return o}(t,e,this.data,i);for(let t=0,e=s.length;t<e;t++)n.push(...s[t].toShapes());return n}}function Vf(t,e,i,n,s){const r=s.glyphs[t]||s.glyphs["?"];if(!r)return void console.error('THREE.Font: character "'+t+'" does not exists in font family '+s.familyName+".");const a=new dd;let o,l,h,c,d,u,p,m;if(r.o){const t=r._cachedOutline||(r._cachedOutline=r.o.split(" "));for(let s=0,r=t.length;s<r;){switch(t[s++]){case"m":o=t[s++]*e+i,l=t[s++]*e+n,a.moveTo(o,l);break;case"l":o=t[s++]*e+i,l=t[s++]*e+n,a.lineTo(o,l);break;case"q":h=t[s++]*e+i,c=t[s++]*e+n,d=t[s++]*e+i,u=t[s++]*e+n,a.quadraticCurveTo(d,u,h,c);break;case"b":h=t[s++]*e+i,c=t[s++]*e+n,d=t[s++]*e+i,u=t[s++]*e+n,p=t[s++]*e+i,m=t[s++]*e+n,a.bezierCurveTo(d,u,p,m,h,c)}}}return{offsetX:r.ha*e,path:a}}const Wf={glyphs:{X:{x_min:-.015625,x_max:854.15625,ha:940,o:"m 854 0 l 683 0 l 423 409 l 166 0 l 0 0 l 347 519 l 18 1013 l 186 1013 l 428 637 l 675 1013 l 836 1013 l 504 520 l 854 0 "},Y:{x_min:0,x_max:820,ha:886,o:"m 820 1013 l 482 416 l 482 0 l 342 0 l 342 416 l 0 1013 l 140 1013 l 411 534 l 679 1012 l 820 1013 "},Z:{x_min:0,x_max:779,ha:849,o:"m 779 0 l 0 0 l 0 113 l 621 896 l 40 896 l 40 1013 l 779 1013 l 778 887 l 171 124 l 779 124 l 779 0 "}},cssFontWeight:"normal",ascender:1189,underlinePosition:-100,cssFontStyle:"normal",boundingBox:{yMin:-334,xMin:-111,yMax:1189,xMax:1672},resolution:1e3,descender:-334,familyName:"Helvetiker",lineHeight:1522,underlineThickness:50,original_font_information:{}};class jf{constructor(t,e,i,n){this.width=t,this.height=e,this.cad_camera=i,this.theme=n,this.camera=null,this.scene=null,this.renderer=null,this.labels=[],this.ready=!1,this.colors={dark:[[1,69/255,0],[50/255,205/255,50/255],[59/255,158/255,1]],light:[[1,0,0],[0,.5,0],[0,0,1]]},this.cones=[],this.axes=null}create(){const t=new Hf(Wf),e=2.5;this.scene=new Rn,this.camera=new Fh(-this.width,this.width,this.height,-this.height,1,1e3),this.camera.up=this.cad_camera.up,this.camera.lookAt(new xi(0,0,0)),this.axes=new Gf([0,0,0],54,e,this.width,this.height,!0,!0,this.theme),this.scene.add(this.axes),this.cones=[];for(let t=0;t<3;t++){const e=new $a(0,6.25,12.5,20,1),i=new lr({color:new En(...this.colors[this.theme][t]),toneMapped:!1}),n=new xr(e,i);n.matrixAutoUpdate=!1,this.cones.push(n)}this.cones[0].geometry.rotateZ(-Math.PI/2),this.cones[0].geometry.translate(54,0,0),this.cones[1].geometry.translate(0,54,0),this.cones[2].geometry.rotateX(Math.PI/2),this.cones[2].geometry.translate(0,0,54),this.scene.add(...this.cones);const i=["X","Y","Z"];for(let e=0;e<3;e++){const n=new Sa({color:"dark"===this.theme?new En(.9,.9,.9):new En(0,0,0),side:2}),s=t.generateShapes(i[e],16),r=new fl(s);r.computeBoundingBox();const a=-.5*(r.boundingBox.max.x-r.boundingBox.min.x),o=-.5*(r.boundingBox.max.y-r.boundingBox.min.y);r.translate(a,o,0);const l=new xr(r,n);this.scene.add(l),this.labels.push(l)}const n=new gl(7.5,20,20),s=new lr({color:10526880}),r=new xr(n,s);this.scene.add(r),this.scene.background=null,this.ready=!0}setVisible(t){if(this.scene)for(const e of this.scene.children)e.visible=t}dispose(){Xm(this.scene,t=>{t instanceof xr&&(t.geometry?.dispose(),t.material instanceof Os&&t.material.dispose())}),this.scene=null,this.camera=null,this.cad_camera=null,this.cones=[],this.labels=[]}render(t){if(this.ready&&this.scene&&this.camera){const e=t.getViewport(new ki),i=t.getScissor(new ki),n=t.getScissorTest();t.setViewport(0,0,this.width,this.height),t.render(this.scene,this.camera),t.setViewport(e),t.setScissor(i),t.setScissorTest(n)}}update(t,e){if(this.ready&&this.camera){const i=(new _i).setFromUnitVectors(new xi(0,0,1),t.normalize());this.camera.position.set(0,0,1).applyQuaternion(i).multiplyScalar(300),this.camera.quaternion.copy(e);for(let t=0;t<3;t++)this.labels[t].position.set(0==t?72:0,1==t?72:0,2==t?72:0),this.labels[t].quaternion.copy(e)}}changeTheme(t){for(const e in this.cones){this.cones[e].material.color=new En(...this.colors[t][e])}this.axes&&this.axes.changeTheme(t);for(const e in this.labels){this.labels[e].material.color="dark"===t?new En(.9,.9,.9):new En(0,0,0)}}}const Xf=0,Yf=1,Zf=2,qf=3;function Qf(t){return Array.isArray(t)&&2===t.length}function Kf(t){return"object"==typeof t&&!Array.isArray(t)}class Jf{constructor(t,e={}){this.linkIcons=void 0===e.linkIcons||e.linkIcons,this.onStateChange=e.onStateChange||null,this.maxLevel=0,this.root=this._buildTreeStructure(t)}_buildTreeStructure(t){const e=(t,i,n)=>{const s=[Xf,Xf],r={};this.maxLevel<n&&(this.maxLevel=n);const a=[[!1,!1],[!1,!1],[!1,!1],[!1,!1]];for(const s in t){let o,l="";l=null==i?s:`${i}/${s}`;const h=t[s];if(Qf(h))o=h,a[h[0]][0]=!0,a[h[1]][1]=!0,r[s]={name:s,state:o,path:l,rendered:!1,level:n};else if(Kf(h)&&Object.keys(h).length>0){let t;[t,o]=e(h,l,n+1),a[o[0]][0]=!0,a[o[1]][1]=!0,r[s]={name:s,state:o,path:l,rendered:!1,level:n,children:t,expanded:!1}}else o=[qf,qf],a[qf][0]=!0,a[qf][1]=!0,r[s]={name:s,state:o,path:l,rendered:!1,level:n}}return[r,(t=>{for(const e of[0,1])t[Zf][e]||t[Yf][e]&&t[Xf][e]?s[e]=Zf:t[Yf][e]?s[e]=Yf:t[Xf][e]?s[e]=Xf:t[qf][e]&&(s[e]=qf);return s})(a)]},i=e(t,null,0)[0];return i[Object.keys(i)[0]]}traverse(t,e){if(e(t),t.children)for(const i of Object.keys(t.children))this.traverse(t.children[i],e)}isLeaf(t){return null==t.children}getNodePath(t){return null==t?"":"/"+t.path}findNodeByPath(t){if(!this.root)return null;const e=Array.isArray(t)?t:t.split("/").filter(Boolean);let i=this.root;for(let t=1;t<e.length;t++){const n=e[t];if(!i.children||!i.children[n])return null;i=i.children[n]}return i}getParent(t){const e=t.path.substring(0,t.path.lastIndexOf("/"));return 0===e.length?null:this.findNodeByPath(e)}getState(t){const e=this.findNodeByPath(t);return e?e.state:null}getStates(){const t={};return this.root&&this.traverse(this.root,e=>{this.isLeaf(e)&&(t[this.getNodePath(e)]=e.state)}),t}setState(t,e){const i=this.findNodeByPath(t);i&&(this.toggleNodeState(i,0,e[0]===Yf),this.toggleNodeState(i,1,e[1]===Yf))}setStates(t){for(const e in t)this.setState(e,t[e])}toggleNodeState(t,e,i=null){const n=t.state[e];if(n===qf)return!1;const s=0===e?this.linkIcons?[0,1]:[0]:[1];for(const e of s)t.state[e]!==qf&&(t.state[e]=null!==i?i?Yf:Xf:n===Yf?Xf:Yf,this.onStateChange&&this.onStateChange(t,e),this._updateParentStates(t,e),this._updateChildrenStates(t,e));return!0}_updateParentStates(t,e){let i=this.getParent(t);for(;i;){const t=Object.values(i.children),n=t.every(t=>t.state[e]===Yf||t.state[e]===qf),s=t.every(t=>t.state[e]===Xf||t.state[e]===qf),r=n?Yf:s?Xf:Zf;i.state[e]!==r&&i.state[e]!==qf&&(i.state[e]=r,this.onStateChange&&this.onStateChange(i,e)),i=this.getParent(i)}}_updateChildrenStates(t,e){const i=t.state[e],n=t=>{if(t.state[e]!==i&&t.state[e]!==qf&&(t.state[e]=i,this.onStateChange&&this.onStateChange(t,e)),t.children)for(const e in t.children)n(t.children[e])};n(t)}hideAll(){this.root&&(this.toggleNodeState(this.root,0,!1),this.linkIcons&&this.root.state[0]!==qf||this.toggleNodeState(this.root,1,!1))}showAll(){this.root&&(this.toggleNodeState(this.root,0,!0),this.linkIcons||this.toggleNodeState(this.root,1,!0))}show(t){const e=this.findNodeByPath(t);e&&this.toggleNodeState(e,0,!0)}hide(t){const e=this.findNodeByPath(t);e&&this.toggleNodeState(e,0,!1)}setExpandedLevel(t){this.root&&this.traverse(this.root,e=>{this.isLeaf(e)||(e.expanded=-1===t?null!=e.children&&!(1===Object.keys(e.children).length&&this.isLeaf(Object.values(e.children)[0])):e.level<t)})}expandPath(t){const e=t.split("/").filter(Boolean);let i="",n=null;for(const t of e){if(i+="/"+t,n=this.findNodeByPath(i),!n)return null;n.children&&(n.expanded=!0)}return n}collapsePath(t){const e=this.findNodeByPath(t);return e&&(e.expanded=!1),e}dispose(){this.root=null,this.onStateChange=null}}const $f="▾",tg="▸",eg=[["shape_no","shape","shape_mix","shape_empty"],["mesh_no","mesh","mesh_mix","mesh_empty"]],ig=[0,1];class ng{constructor(t,e,i,n,s,r,a,o,l,h=!1){this.handleScroll=()=>{this.scrollContainer&&(this.lastScrollTop=this.scrollContainer.scrollTop,this.debug&&Fm.debug("update => scroll"),this.update())},this.handleNavigationClick=t=>e=>{e.stopPropagation(),t.expanded=!t.expanded,this.showChildContainer(t),this.debug&&Fm.debug("update => navClick"),this.update()},this.handleIconClick=(t,e)=>i=>{i.stopPropagation(),this.toggleIcon(t,e)},this.update=(t=null)=>{if(!this.container||!this.model)return;const e=this.getVisibleElements().filter(e=>e instanceof HTMLElement&&(null==t||(e.dataset.path||"").startsWith(t)));for(const t of e){const e=t.dataset.path||"",i=this.findNodeByPath(e);if(null!=i){if(i.rendered||(this.renderNode(i,t),i.rendered=!0),i.expanded){const n=t.querySelector(".tv-children");if(n instanceof HTMLElement&&0===n.children.length){for(const t in i.children){const e=i.children[t];this.renderPlaceholder(e,n)}this.showChildContainer(i),this.update(e)}}for(const e of ig){const n=t.dataset[`state${e}`],s=i.state[e];n!=String(s)&&this.updateIconInDOM(i,e)}this.showChildContainer(i)}else Fm.error(`Node not found: ${e}`)}},this.getDomNode=t=>{if(!this.container)return null;const e=this.container.querySelector(`[data-path="${t}"]`);return e instanceof HTMLElement?e:null},this.tree=t,this.scrollContainer=e,this.objectHandler=i,this.pickHandler=n,this.updateHandler=s,this.notificationHandler=r,this.colorGetter=a,this.theme=o,this.linkIcons=l,this.debug=h,this.model=null,this.container=null,this.lastLabel=null,this.lastScrollTop=0}create(){return this.model=new Jf(this.tree,{linkIcons:this.linkIcons,onStateChange:(t,e)=>this._handleStateChange(t,e)}),this.container=document.createElement("ul"),this.container.classList.add("tcv_toplevel"),this.scrollContainer.addEventListener("scroll",this.handleScroll),this.container}_handleStateChange(t,e){const i=0===e&&this.linkIcons?[0,1]:[e];for(const e of i)this.objectHandler(this.getNodePath(t),t.state[e],e,!0,!1)}get root(){return this.model?this.model.root:null}get maxLevel(){return this.model?this.model.maxLevel:0}getVisibleElements(){if(!this.container)return[];const t=this.container.querySelectorAll(".tv-tree-node"),e=this.scrollContainer.getBoundingClientRect(),i=Array.from(t).filter(t=>((t,e)=>{const i=t.getBoundingClientRect();return i.height>0&&i.top>=-12&&i.top<=e.bottom+12})(t,e));return this.debug&&this._logVisibleElements(i),i}_logVisibleElements(t){Fm.debug(`\nVisible elements (${t.length}):`);for(const e of t){if(!(e instanceof HTMLElement))continue;const t=this.findNodeByPath(e.dataset.path||"");t&&Fm.debug(t.path,t.state[0],t.state[1]," => ",e.dataset.state0,e.dataset.state1)}}handleLabelClick(t,e){const i=e instanceof MouseEvent;this.pickHandler(this.getNodePath(this.getParent(t)),t.name,!!i&&rf.get(e,"meta"),!!i&&rf.get(e,"shift"),!!i&&rf.get(e,"alt"),null,this.isLeaf(t)?"leaf":"node",!0),this.debug&&Fm.debug(`Label clicked: ${this.getNodePath(t)}`)}render(){this.container&&this.root&&(this.container.innerHTML="",this.renderPlaceholder(this.root,this.container),this.debug&&Fm.debug("update => render"),this.update())}renderPlaceholder(t,e,i=null){this.debug&&Fm.debug("renderPlaceholder",t.path,t.level);const n=document.createElement("div");n.className="tv-tree-node",n.dataset.path=this.getNodePath(t),n.dataset.openPath=i||"",n.dataset.state0=String(t.state[0]),n.dataset.state1=String(t.state[1]);const s=document.createElement("div");s.className="tv-node-content",this.debug&&(s.innerText=t.path),n.appendChild(s),e.appendChild(n)}renderNode(t,e){this.debug&&Fm.debug("renderNode",t.path,t.level);const i=document.createElement("div");i.className="tv-node-content",e.removeChild(e.firstChild),e.appendChild(i);const n=document.createElement("span");n.className="tv-nav-marker",n.innerHTML=t.children?t.expanded?$f:tg:"",n.onclick=this.handleNavigationClick(t),i.dataset.state0=String(t.state[0]),i.dataset.state1=String(t.state[1]),i.appendChild(n);for(const e of ig){const n=document.createElement("span"),s=t.state[e];let r=`tv-icon tv-icon${e}`;s!==qf&&(r+=" tv-pointer"),n.className=r,n.classList.add("tcv_tree_button"),n.classList.add(`tcv_button_${eg[e][s]}`),s!==qf&&(n.onmousedown=t=>{t.preventDefault()},n.onclick=this.handleIconClick(t,e)),i.appendChild(n)}const s=document.createElement("span");s.className="tv-node-label",s.innerHTML=t.name;const r=this.colorGetter(t.path);null!=r&&(s.innerHTML+=`<span style="color:${r}"> ⚈</span>`),s.onmousedown=t=>{t.preventDefault()},s.oncontextmenu=e=>{e.preventDefault(),e.stopPropagation(),this.handleLabelClick(t,e)},s.onclick=e=>{e.stopPropagation(),this.handleLabelClick(t,e)},i.appendChild(s);let a=null;return t.children&&(a=document.createElement("div"),a.className="tv-children",a.style.display="none",e.appendChild(a)),a}showChildContainer(t){if(null==t.expanded)return;const e=this.getNodePath(t),i=this.getDomNode(e);if(i){const e=i.querySelector(".tv-children");if(e instanceof HTMLElement){if("none"!==e.style.display!==t.expanded){e.style.display=t.expanded?"block":"none";const n=i.querySelector(".tv-nav-marker");n&&(n.innerHTML=t.expanded?$f:tg),t.expanded||(this.debug&&Fm.debug("update => showChildContainer"),this.update())}}}else Fm.error(`Element not found: ${e}`)}updateIconInDOM(t,e){if(!this.container)return;const i=this.getNodePath(t),n=this.container.querySelector(`[data-path="${i}"]`);if(n instanceof HTMLElement){const i=n.querySelector(`.tv-icon${e}`);if(i){for(const t of eg[e])i.classList.remove(`tcv_button_${t}`);i.classList.add(`tcv_button_${eg[e][t.state[e]]}`)}n.dataset[`state${e}`]=String(t.state[e])}}toggleLabelColor(t,e=null){if(!this.container)return;const i=null==e&&t?this.getNodePath(t):e;if(!i)return;const n=this.container.querySelector(`[data-path="${i}"]`);if(this.lastLabel&&this.lastLabel.classList.remove("tv-node-label-highlight"),n){const t=n.querySelector(".tv-node-label");t instanceof HTMLElement&&(this.lastLabel===t?this.lastLabel=null:(t.classList.toggle("tv-node-label-highlight"),this.lastLabel=t))}}traverse(t,e){this.model&&this.model.traverse(t,e)}isLeaf(t){return!this.model||this.model.isLeaf(t)}getNodePath(t){return this.model?this.model.getNodePath(t):""}findNodeByPath(t){return this.model?this.model.findNodeByPath(t):null}getParent(t){return this.model?this.model.getParent(t):null}toggleIcon(t,e,i=null){if(!this.model)return;this.model.toggleNodeState(t,e,i)&&(this.update(),this.updateHandler(!0),this.notificationHandler())}hideAll(){this.model&&(this.model.hideAll(),this.update(),this.updateHandler(!0),this.notificationHandler())}showAll(){this.model&&(this.model.showAll(),this.update(),this.updateHandler(!0),this.notificationHandler())}show(t){this.model&&(this.model.show(t),this.update(),this.updateHandler(!0),this.notificationHandler())}hide(t){this.model&&(this.model.hide(t),this.update(),this.updateHandler(!0),this.notificationHandler())}getState(t){return this.model?this.model.getState(t):null}getStates(){return this.model?this.model.getStates():{}}setState(t,e){this.model&&(this.model.setState(t,e),this.update(),this.updateHandler(!0),this.notificationHandler())}setStates(t){this.model&&(this.model.setStates(t),this.update(),this.updateHandler(!0),this.notificationHandler())}scrollCentered(t){if(null!=t){const e=this.scrollContainer,i=t.offsetHeight,n=e.clientHeight,s=t.offsetTop-e.offsetTop-n/2+i/2,r=e.scrollHeight-n,a=Math.max(0,Math.min(s,r));e.scrollTo({top:a,behavior:"smooth"})}}_ensureNodeRendered(t){const e=this.getNodePath(t);let i=this.getDomNode(e);if(!i){const n=this.getParent(t);n&&(this._ensureNodeRendered(n),i=this.getDomNode(e))}if(!i){const n=this.getParent(t);if(n){const s=this.getDomNode(this.getNodePath(n));if(s){let r=s.querySelector(".tv-children");!r&&n.children&&(n.rendered||(this.renderNode(n,s),n.rendered=!0),r=s.querySelector(".tv-children")),r instanceof HTMLElement&&(this.renderPlaceholder(t,r),i=this.getDomNode(e))}}}if(i&&!t.rendered&&(this.renderNode(t,i),t.rendered=!0),i&&t.expanded&&t.children){const e=i.querySelector(".tv-children");if(e instanceof HTMLElement){if(0===e.children.length)for(const i in t.children)this.renderPlaceholder(t.children[i],e);e.style.display="block"}}return i}openPath(t){const e=t.split("/").filter(Boolean);let i="",n=null,s=null;for(const t of e){if(i+="/"+t,n=this.findNodeByPath(i),!n){Fm.error(`Path not found: ${i}`);break}if(n.children&&(n.expanded=!0),s=this._ensureNodeRendered(n),s){const t=s.querySelector(".tv-nav-marker");t&&n.children&&(t.innerHTML=$f)}this.debug&&Fm.debug("update => openPath",i)}this.update(),this.scrollCentered(s),n&&this.toggleLabelColor(n)}closePath(t){const e=this.findNodeByPath(t);if(e){e.expanded=!1,this.showChildContainer(e);const i=this.getDomNode(t);null!=i&&(this.scrollContainer.scrollTop=i.offsetTop-this.scrollContainer.offsetTop),this.debug&&Fm.debug("update => collapsePath"),this.update()}else Fm.error(`Path not found: ${t}`)}openLevel(t){if(!this.model||!this.root)return;this.model.setExpandedLevel(t);const e=this.getDomNode(this.getNodePath(this.root));null!=e&&(this.scrollContainer.scrollTop=e.offsetTop-this.scrollContainer.offsetTop);const i=-1===t?this.maxLevel:t;for(let t=0;t<=i;t++)this.debug&&Fm.debug("update => openLevel",t),this.update()}collapseAll(){this.openLevel(0)}expandAll(){this.openLevel(this.maxLevel)}dispose(){this.model&&(this.model.dispose(),this.model=null),this.tree=null,this.container=null,this.lastLabel=null,this.scrollContainer.removeEventListener("scroll",this.handleScroll)}}let sg=class{constructor(t,e){this.prefix=t,this.timeit=e,this.start=performance.now(),this.last=this.start,e&&console.info(`three-cad-viewer: ${t}:timer start`)}split(t){if(this.timeit){const e=performance.now();console.info(`three-cad-viewer: ${this.prefix}:${t}:timer split ${(e-this.last).toFixed(1)} ms`),this.last=e}}stop(){if(this.timeit){const t=performance.now();console.info(`three-cad-viewer: ${this.prefix}:timer stop ${(t-this.start).toFixed(1)} ms:`)}}};const rg=[new xi(-1,0,0),new xi(0,-1,0),new xi(0,0,-1)],ag={light:[16711680,65280,255],dark:[16729344,3329330,3907327]},og={light:.1,dark:.2};class lg{static createPlaneHelperMaterial(t){return new lr({opacity:og[t]||.1,transparent:!0,depthWrite:!1,toneMapped:!1,side:2})}static createBackStencilMaterial(){return new lr({depthWrite:!1,depthTest:!1,colorWrite:!1,side:1,stencilWrite:!0,stencilFunc:Be,stencilFail:Ie,stencilZFail:Ie,stencilZPass:Ie})}static createFrontStencilMaterial(){return new lr({depthWrite:!1,depthTest:!1,colorWrite:!1,side:0,stencilWrite:!0,stencilFunc:Be,stencilFail:Le,stencilZFail:Le,stencilZPass:Le})}static createStencilPlaneMaterial(t,e){return new Pl({color:new En(t),metalness:.3,roughness:.65,opacity:1,transparent:!1,side:2,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1,stencilWrite:!0,stencilRef:0,stencilFunc:517,stencilFail:Pe,stencilZFail:Pe,stencilZPass:Pe,clippingPlanes:e})}}class hg extends qr{constructor(t,e,i){super(t,e),this.center=i,this.centeredConstant=e,this.setConstant(e)}setConstant(t){this.centeredConstant=t;const e=this.distanceToPoint(new xi(...this.center)),i=this.distanceToPoint(new xi(0,0,0));this.constant=i-e+t}clone(){return new hg(this.normal.clone(),this.centeredConstant,[...this.center])}}class cg extends _n{}class dg extends xr{constructor(t,e,i,n,s,r,a){const o=new pl(2,2);o.computeBoundingSphere(),s.color.set(new En(r)),super(o,s),this.onAfterRender=t=>{this.type.startsWith("StencilPlane")&&t.clearStencil()},this.type=a,this.index=t,this.plane=e,this.size=n,this.center=i}updateMatrixWorld(t){this.position.set(0,0,0),this.scale.set(.5*this.size,.5*this.size,1),dg.matrix.lookAt(this.position,this.plane.normal,this.up),this.quaternion.setFromRotationMatrix(dg.matrix),this.translateZ(this.plane.constant),super.updateMatrixWorld(t)}}function ug(t,e,i,n){e.clippingPlanes=[n];const s=new xr(i,e);return s.name=t,s}dg.matrix=new Wi;class pg extends _n{constructor(t,e,i,n,s){super(),this.setNormal=(t,e)=>{const i=e.clone();this.clipPlanes[t].normal=i,this.reverseClipPlanes[t].normal=i.clone().negate(),this.setConstant(t,this.distance),this.onNormalChange&&this.onNormalChange(t,Vm(i.toArray()))},this.getObjectColorCaps=()=>this.objectColorCaps,this.setObjectColorCaps=t=>{if(!this._planeMeshGroup)return;let e=0,i=-1;const n=this._planeMeshGroup.children.length/3;for(const s of this._planeMeshGroup.children){e%n===0&&i++;const r=t?this.objectColors[e]:ag[this.theme][i];s.material.color.set(new En(r)),e++}this.objectColorCaps=t},this.setVisible=t=>{if(this._planeMeshGroup)for(const e of this._planeMeshGroup.children)e.material.visible=t},this.center=t,this.distance=e/2,this.onNormalChange=n.onNormalChange||null,this.theme=s,this.nestedGroup=i,this.size=e,this.clipPlanes=[],this.reverseClipPlanes=[],this.objectColors=[],this.objectColorCaps=!1,this._planeMeshGroup=null,this.name="PlaneHelpers",this._createClipPlanes(t),this._createPlaneHelpers(t,e,s),this._createStencils(t,e,s)}_createClipPlanes(t){for(const e of Sf){const i=new hg(rg[e],this.distance,t);this.clipPlanes.push(i);const n=new hg(rg[e].clone().negate(),-this.distance,t);this.reverseClipPlanes.push(n),this.onNormalChange&&this.onNormalChange(e,Vm(rg[e].toArray()))}}_createPlaneHelpers(t,e,i){this.planeHelpers=new cg,this.planeHelpers.name="PlaneHelpers";for(let n=0;n<3;n++){const s=lg.createPlaneHelperMaterial(i);this.planeHelpers.add(new dg(n,this.clipPlanes[n],t,e,s,ag[i][n],"PlaneHelper"))}for(let t=0;t<3;t++){const e=this.clipPlanes.filter((e,i)=>i!==t);this.planeHelpers.children[t].material.clippingPlanes=e}this.planeHelpers.visible=!1,this.add(this.planeHelpers)}_createStencils(t,e,i){this._planeMeshGroup=new cg,this._planeMeshGroup.name="PlaneMeshes";for(let n=0;n<3;n++){const s=this.clipPlanes[n],r=this.clipPlanes.filter((t,e)=>e!==n);let a=0;for(const o in this.nestedGroup.groups){const l=this.nestedGroup.groups[o];if(l instanceof of&&"solid"===l.subtype&&l.front){const o=l.front.material;this.objectColors.push(o.color.getHex());const h=new _n;h.name=`clipping-${n}`,h.add(ug(`frontStencil-${n}-${a}`,lg.createFrontStencilMaterial(),l.shapeGeometry,s)),h.add(ug(`backStencil-${n}-${a}`,lg.createBackStencilMaterial(),l.shapeGeometry,s)),l.addClipping(h,n);const c=lg.createStencilPlaneMaterial(ag[i][n],r);this._planeMeshGroup.add(new dg(n,s,t,e,c,ag[i][n],`StencilPlane-${n}-${a}`)),a++}}}this.nestedGroup.rootGroup.add(this._planeMeshGroup)}rebuildStencils(t,e){for(const t in this.nestedGroup.groups){const e=this.nestedGroup.groups[t];e instanceof of&&e.clearClipping()}this._planeMeshGroup&&this.nestedGroup.rootGroup&&(this.nestedGroup.rootGroup.remove(this._planeMeshGroup),Qm(this._planeMeshGroup),this._planeMeshGroup=null),this.objectColors=[],this.center=t,this.size=e,this.distance=e/2,this._createStencils(t,e,this.theme),this.objectColorCaps&&this.setObjectColorCaps(!0)}setConstant(t,e){this.clipPlanes[t].setConstant(e),this.reverseClipPlanes[t].setConstant(-e)}saveState(){return{planeConstants:[this.clipPlanes[0].centeredConstant,this.clipPlanes[1].centeredConstant,this.clipPlanes[2].centeredConstant],helperVisible:this.planeHelpers?.visible??!1,planesVisible:!!this._planeMeshGroup?.children.length&&this._planeMeshGroup.children[0].material.visible}}restoreState(t){for(const e of Sf)this.setConstant(e,t.planeConstants[e]);this.planeHelpers&&(this.planeHelpers.visible=t.helperVisible),this.setVisible(t.planesVisible)}dispose(){this.onNormalChange=null,this.center=null,this.planeHelpers=null,this._planeMeshGroup=null}}class mg{constructor(t){this.delim=t,this.tracks=[],this.mixer=null,this.clip=null,this.clipAction=null,this.clock=new Bc,this.duration=null,this._backup=null,this.root=null,this.speed=null,this.repeat=null}_prepareSelector(t){return t.replaceAll("/",this.delim)}_validateArrayLengths(t,e){return t.length===e.length||(Fm.error("times and values arrays need to have the same length"),!1)}addPositionTrack(t,e,i,n){if(!this._validateArrayLengths(i,n))return;const s=e.position,r=n.map(t=>s.clone().add(new xi(...t)).toArray());this.tracks.push(new nh(this._prepareSelector(t)+".position",i,r.flat()))}addTranslationTrack(t,e,i,n,s){if(!this._validateArrayLengths(n,s))return;const r=e.position,a={x:t=>new xi(t,0,0),y:t=>new xi(0,t,0),z:t=>new xi(0,0,t)},o=s.map(t=>r.clone().add(a[i](t)).toArray());this.tracks.push(new nh(this._prepareSelector(t)+".position",n,o.flat()))}addQuaternionTrack(t,e,i,n){if(!this._validateArrayLengths(i,n))return;const s=e.quaternion,r=n.map(t=>s.clone().multiply(new _i(...t)).toArray());this.tracks.push(new eh(this._prepareSelector(t)+".quaternion",i,r.flat()))}addRotationTrack(t,e,i,n,s){if(!this._validateArrayLengths(n,s))return;const r=e.quaternion,a=s.map(t=>r.clone().multiply(function(t,e){const i=new _i;return i.setFromAxisAngle(Gm[t],e/180*Math.PI),i}(i,t)).toArray());this.tracks.push(new eh(this._prepareSelector(t)+".quaternion",n,a.flat()))}backup(){this._backup={tracks:this.tracks,root:this.root,duration:this.duration,speed:this.speed,repeat:this.repeat}}restore(){return null===this._backup?{duration:null,speed:null,repeat:null}:(this.tracks=this._backup.tracks,{duration:this._backup.duration,speed:this._backup.speed,repeat:this._backup.repeat})}cleanBackup(){this._backup=null}hasTracks(){return null!=this.tracks&&this.tracks.length>0}hasBackup(){return null!==this._backup}animate(t,e,i,n=!0){return this.root=t,this.duration=e,this.speed=i,this.repeat=n,this.clip=new sh("track",e,this.tracks),this.mixer=new Ec(t),this.mixer.timeScale=i,this.clipAction=this.mixer.clipAction(this.clip),this.clipAction.setLoop(n?pe:me,1/0),this.clipAction}setRelativeTime(t){if(!this.clipAction||!this.duration)return;this.clipAction.play(),this.clipAction.paused=!0;const e=this.duration*t;this.clipAction.time=e}getRelativeTime(){return this.clipAction&&this.duration?this.clipAction.time/this.duration:0}dispose(){this.mixer&&(this.mixer.stopAllAction(),this.clip&&this.mixer.uncacheClip(this.clip),this.root&&this.mixer.uncacheRoot(this.root)),this.mixer=null,this.clipAction=null,this.clip=null,this.tracks=[],this.root=null}update(){this.mixer&&(this.clock.update(),this.mixer.update(this.clock.getDelta()))}}function fg(t){return"string"==typeof t?t.startsWith("#")?t:`#${t}`:`#${t.toString(16).padStart(6,"0")}`}class gg{constructor(t){this._bbox=null,this.config=t}get bbox(){return this._bbox}updateConfig(t){this.config={...this.config,...t}}_renderTessellatedShapes(t){const e=new Nf(t,this.config.cadWidth,this.config.height,this.config.edgeColor,this.config.transparent,this.config.defaultOpacity,this.config.metalness,this.config.roughness,this.config.normalLen);return t.bb&&(this._bbox=new hf(new xi(t.bb.xmin,t.bb.ymin,t.bb.zmin),new xi(t.bb.xmax,t.bb.ymax,t.bb.zmax))),e.render(),e}_getTree(t){const e=t=>{const i={};for(const n of t)null!=n.parts?i[n.name]=e(n.parts):i[n.name]=n.state;return i},i={};return i[t.name]=e(t.parts??[]),i}_decompose(t){const e=t.shape;let i;if(t.parts=[],"shapes"===t.type){const n={version:2,name:"faces",id:`${t.id}/faces`,parts:[],loc:[[0,0,0],[0,0,0,1]]};let s;if(!(e.vertices instanceof Float32Array))throw new Error("_decompose requires shape.vertices to be Float32Array (call _convertArrays first)");if(!(e.normals instanceof Float32Array))throw new Error("_decompose requires shape.normals to be Float32Array (call _convertArrays first)");const r=e.vertices,a=e.normals,o=e.uvs instanceof Float32Array?e.uvs:null;let l=0;if(Ef(e)){if(!(e.triangles instanceof Uint32Array))throw new Error("Expected Uint32Array for triangles in binary format");const h=e.triangles,c=e.triangles_per_face,d=c.length;for(i=0;i<d;i++){s=h.subarray(l,l+3*c[i]),l+=3*c[i];const d=new Float32Array(3*s.length),u=new Float32Array(3*s.length),p=o?new Float32Array(2*s.length):null;for(let t=0;t<s.length;t++){const e=s[t];d[3*t]=r[3*e],d[3*t+1]=r[3*e+1],d[3*t+2]=r[3*e+2],u[3*t]=a[3*e],u[3*t+1]=a[3*e+1],u[3*t+2]=a[3*e+2],o&&p&&(p[2*t]=o[2*e],p[2*t+1]=o[2*e+1])}const m={triangles:[...Array(s.length).keys()],vertices:Array.from(d),normals:Array.from(u),edges:[],obj_vertices:[],edge_types:[],face_types:[e.face_types[i]]};p&&(m.uvs=Array.from(p));const f={version:2,loc:[[0,0,0],[0,0,0,1]],name:`faces_${i}`,id:`${t.id}/faces/faces_${i}`,type:"shapes",color:t.color,alpha:t.alpha,renderback:"solid"!==t.subtype,state:[1,3],accuracy:t.accuracy,bb:null,shape:m};t.texture&&(f.texture=t.texture),t.material&&(f.material=t.material),f.geomtype=e.face_types[i],f.subtype=t.subtype,f.exploded=!0,n.parts.push(f)}}else{if(!Array.isArray(e.triangles)||!Array.isArray(e.triangles[0]))throw new Error("Expected nested array for triangles in non-binary format");const l=e.triangles,h=l.length;for(i=0;i<h;i++){s=l[i];const h=new Float32Array(3*s.length),c=new Float32Array(3*s.length),d=o?new Float32Array(2*s.length):null;for(let t=0;t<s.length;t++){const e=s[t];h[3*t]=r[3*e],h[3*t+1]=r[3*e+1],h[3*t+2]=r[3*e+2],c[3*t]=a[3*e],c[3*t+1]=a[3*e+1],c[3*t+2]=a[3*e+2],o&&d&&(d[2*t]=o[2*e],d[2*t+1]=o[2*e+1])}const u={triangles:[...Array(s.length).keys()],vertices:Array.from(h),normals:Array.from(c),edges:[],obj_vertices:[],edge_types:[],face_types:[e.face_types[i]]};d&&(u.uvs=Array.from(d));const p={version:2,loc:[[0,0,0],[0,0,0,1]],name:`faces_${i}`,id:`${t.id}/faces/faces_${i}`,type:"shapes",color:t.color,alpha:t.alpha,renderback:"solid"!==t.subtype,state:[1,3],accuracy:t.accuracy,bb:null,shape:u};t.texture&&(p.texture=t.texture),t.material&&(p.material=t.material),p.geomtype=e.face_types[i],p.subtype=t.subtype,p.exploded=!0,n.parts.push(p)}}t.parts.push(n)}if("shapes"===t.type||"edges"===t.type){const n={version:2,parts:[],loc:[[0,0,0],[0,0,0,1]],name:"edges",id:`${t.id}/edges`},s=Array.isArray(t.color)?t.color:null;let r,a,o=0;if(Tf(e)){if(!(e.edges instanceof Float32Array))throw new Error("Expected Float32Array for edges in binary format");const l=e.edges,h=e.segments_per_edge,c=h.length;for(i=0;i<c;i++){a=l.subarray(o,o+6*h[i]),o+=6*h[i],r=s?s[i]:t.color;const c={version:2,loc:[[0,0,0],[0,0,0,1]],name:`edges_${i}`,id:`${t.id}/edges/edges_${i}`,type:"edges",color:"shapes"===t.type?fg(this.config.edgeColor):r,state:[3,1],bb:null,shape:{edges:Array.from(a),vertices:[],normals:[],triangles:[],obj_vertices:[],edge_types:[e.edge_types[i]],face_types:[]}};c.width="shapes"===t.type?1:t.width,c.geomtype=e.edge_types[i],n.parts.push(c)}}else{const o=e.edges;if(!Array.isArray(o)||o.length>0&&!Array.isArray(o[0]))throw new Error("Expected nested array for edges in non-binary format");const l=o,h=l.length;for(i=0;i<h;i++){a=l[i],r=s?s[i]:t.color;const o={version:2,loc:[[0,0,0],[0,0,0,1]],name:`edges_${i}`,id:`${t.id}/edges/edges_${i}`,type:"edges",color:"shapes"===t.type?fg(this.config.edgeColor):r,state:[3,1],bb:null,shape:{edges:a,vertices:[],normals:[],triangles:[],obj_vertices:[],edge_types:[e.edge_types[i]],face_types:[]}};o.width="shapes"===t.type?1:t.width,o.geomtype=e.edge_types[i],n.parts.push(o)}}n.parts.length>0&&t.parts.push(n)}const n={version:2,parts:[],loc:[[0,0,0],[0,0,0,1]],name:"vertices",id:`${t.id}/vertices`},s=e.obj_vertices;for(i=0;i<s.length/3;i++){const e={version:2,loc:[[0,0,0],[0,0,0,1]],name:`vertices_${i}`,id:`${t.id}/vertices/vertices_${i}`,type:"vertices",color:"shapes"===t.type||"edges"===t.type?fg(this.config.edgeColor):t.color,state:[3,1],bb:null,shape:{obj_vertices:[s[3*i],s[3*i+1],s[3*i+2]],vertices:[],normals:[],triangles:[],edges:[],edge_types:[],face_types:[]}};e.size="shapes"===t.type||"edges"===t.type?4:t.size,n.parts.push(e)}return n.parts.length>0&&t.parts.push(n),delete t.shape,delete t.color,delete t.alpha,delete t.accuracy,delete t.renderback,t}_convertArrays(t){const e=t;null==e.triangles||e.triangles instanceof Uint32Array||void 0!==e.triangles_per_face&&(Array.isArray(e.triangles[0])||(e.triangles=new Uint32Array(e.triangles))),null==e.edges||e.edges instanceof Float32Array||void 0!==e.segments_per_edge&&(Array.isArray(e.edges[0])?e.edges=new Float32Array(Hm(e.edges,1)):e.edges=new Float32Array(e.edges)),null==e.vertices||e.vertices instanceof Float32Array||(e.vertices=new Float32Array(e.vertices)),null==e.normals||e.normals instanceof Float32Array||Array.isArray(e.normals)&&e.normals.length>0&&(Array.isArray(e.normals[0])?e.normals=new Float32Array(Hm(e.normals,2)):e.normals=new Float32Array(e.normals)),null==e.obj_vertices||e.obj_vertices instanceof Float32Array||(e.obj_vertices=new Float32Array(e.obj_vertices)),null==e.uvs||e.uvs instanceof Float32Array||(e.uvs=new Float32Array(e.uvs)),null==e.face_types||e.face_types instanceof Uint32Array||(e.face_types=new Uint32Array(e.face_types)),null==e.edge_types||e.edge_types instanceof Uint32Array||(e.edge_types,Uint8Array,e.edge_types=new Uint32Array(e.edge_types)),null==e.triangles_per_face||e.triangles_per_face instanceof Uint32Array||(e.triangles_per_face=new Uint32Array(e.triangles_per_face)),null==e.segments_per_edge||e.segments_per_edge instanceof Uint32Array||(e.segments_per_edge=new Uint32Array(e.segments_per_edge))}_processShapes(t){if(2===t.version||3===t.version){const e=[];for(let i=0;i<(t.parts?.length??0);i++){const n=t.parts[i];if(null!=n.shape&&this._convertArrays(n.shape),null!=n.parts){const t=this._processShapes(n);e.push(t)}else e.push(this._decompose(n))}t.parts=e}return t}render(t,e){let i;i=t?this._processShapes(structuredClone(e)):structuredClone(e);return{group:this._renderTessellatedShapes(i),tree:this._getTree(i)}}}const vg={type:"change"},yg={type:"start"},_g={type:"end"},xg=new or,bg=new qr,Sg=Math.cos(70*vi.DEG2RAD),Mg=new xi,wg=2*Math.PI,Ag=-1,Eg=0,Tg=1,Cg=2,Dg=3,Rg=4,Pg=5,Ig=6,Lg=1e-6;class Bg extends ud{constructor(t,e=null){super(t,e),this.state=Ag,this.target=new xi,this.cursor=new xi,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:i.ROTATE,MIDDLE:i.DOLLY,RIGHT:i.PAN},this.touches={ONE:n.ROTATE,TWO:n.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle="auto",this._domElementKeyEvents=null,this._lastPosition=new xi,this._lastQuaternion=new _i,this._lastTargetPosition=new xi,this._quat=(new _i).setFromUnitVectors(t.up,new xi(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new Fc,this._sphericalDelta=new Fc,this._scale=1,this._panOffset=new xi,this._rotateStart=new yi,this._rotateEnd=new yi,this._rotateDelta=new yi,this._panStart=new yi,this._panEnd=new yi,this._panDelta=new yi,this._dollyStart=new yi,this._dollyEnd=new yi,this._dollyDelta=new yi,this._dollyDirection=new xi,this._mouse=new yi,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=Fg.bind(this),this._onPointerDown=Og.bind(this),this._onPointerUp=Ng.bind(this),this._onContextMenu=Wg.bind(this),this._onMouseWheel=zg.bind(this),this._onKeyDown=Gg.bind(this),this._onTouchStart=Hg.bind(this),this._onTouchMove=Vg.bind(this),this._onMouseDown=Ug.bind(this),this._onMouseMove=kg.bind(this),this._interceptControlDown=jg.bind(this),this._interceptControlUp=Xg.bind(this),null!==this.domElement&&this.connect(this.domElement),this.update()}set cursorStyle(t){this._cursorStyle=t,this.domElement.style.cursor="grab"===t?"grab":"auto"}get cursorStyle(){return this._cursorStyle}connect(t){super.connect(t),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1});this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents();this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(t){t.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=t}stopListenToKeyEvents(){null!==this._domElementKeyEvents&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(vg),this.update(),this.state=Ag}pan(t,e){this._pan(t,e),this.update()}dollyIn(t){this._dollyIn(t),this.update()}dollyOut(t){this._dollyOut(t),this.update()}rotateLeft(t){this._rotateLeft(t),this.update()}rotateUp(t){this._rotateUp(t),this.update()}update(t=null){const e=this.object.position;Mg.copy(e).sub(this.target),Mg.applyQuaternion(this._quat),this._spherical.setFromVector3(Mg),this.autoRotate&&this.state===Ag&&this._rotateLeft(this._getAutoRotationAngle(t)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let i=this.minAzimuthAngle,n=this.maxAzimuthAngle;isFinite(i)&&isFinite(n)&&(i<-Math.PI?i+=wg:i>Math.PI&&(i-=wg),n<-Math.PI?n+=wg:n>Math.PI&&(n-=wg),this._spherical.theta=i<=n?Math.max(i,Math.min(n,this._spherical.theta)):this._spherical.theta>(i+n)/2?Math.max(i,this._spherical.theta):Math.min(n,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),!0===this.enableDamping?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let s=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const t=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),s=t!=this._spherical.radius}if(Mg.setFromSpherical(this._spherical),Mg.applyQuaternion(this._quatInverse),e.copy(this.target).add(Mg),this.object.lookAt(this.target),!0===this.enableDamping?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let t=null;if(this.object.isPerspectiveCamera){const e=Mg.length();t=this._clampDistance(e*this._scale);const i=e-t;this.object.position.addScaledVector(this._dollyDirection,i),this.object.updateMatrixWorld(),s=!!i}else if(this.object.isOrthographicCamera){const e=new xi(this._mouse.x,this._mouse.y,0);e.unproject(this.object);const i=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),s=i!==this.object.zoom;const n=new xi(this._mouse.x,this._mouse.y,0);n.unproject(this.object),this.object.position.sub(n).add(e),this.object.updateMatrixWorld(),t=Mg.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;null!==t&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(t).add(this.object.position):(xg.origin.copy(this.object.position),xg.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(xg.direction))<Sg?this.object.lookAt(this.target):(bg.setFromNormalAndCoplanarPoint(this.object.up,this.target),xg.intersectPlane(bg,this.target))))}else if(this.object.isOrthographicCamera){const t=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),t!==this.object.zoom&&(this.object.updateProjectionMatrix(),s=!0)}return this._scale=1,this._performCursorZoom=!1,!!(s||this._lastPosition.distanceToSquared(this.object.position)>Lg||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Lg||this._lastTargetPosition.distanceToSquared(this.target)>Lg)&&(this.dispatchEvent(vg),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0)}_getAutoRotationAngle(t){return null!==t?wg/60*this.autoRotateSpeed*t:wg/60/60*this.autoRotateSpeed}_getZoomScale(t){const e=Math.abs(.01*t);return Math.pow(.95,this.zoomSpeed*e)}_rotateLeft(t){this._sphericalDelta.theta-=t}_rotateUp(t){this._sphericalDelta.phi-=t}_panLeft(t,e){Mg.setFromMatrixColumn(e,0),Mg.multiplyScalar(-t),this._panOffset.add(Mg)}_panUp(t,e){!0===this.screenSpacePanning?Mg.setFromMatrixColumn(e,1):(Mg.setFromMatrixColumn(e,0),Mg.crossVectors(this.object.up,Mg)),Mg.multiplyScalar(t),this._panOffset.add(Mg)}_pan(t,e){const i=this.domElement;if(this.object.isPerspectiveCamera){const n=this.object.position;Mg.copy(n).sub(this.target);let s=Mg.length();s*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*t*s/i.clientHeight,this.object.matrix),this._panUp(2*e*s/i.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(t*(this.object.right-this.object.left)/this.object.zoom/i.clientWidth,this.object.matrix),this._panUp(e*(this.object.top-this.object.bottom)/this.object.zoom/i.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(t,e){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const i=this.domElement.getBoundingClientRect(),n=t-i.left,s=e-i.top,r=i.width,a=i.height;this._mouse.x=n/r*2-1,this._mouse.y=-s/a*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(t){return Math.max(this.minDistance,Math.min(this.maxDistance,t))}_handleMouseDownRotate(t){this._rotateStart.set(t.clientX,t.clientY)}_handleMouseDownDolly(t){this._updateZoomParameters(t.clientX,t.clientX),this._dollyStart.set(t.clientX,t.clientY)}_handleMouseDownPan(t){this._panStart.set(t.clientX,t.clientY)}_handleMouseMoveRotate(t){this._rotateEnd.set(t.clientX,t.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(wg*this._rotateDelta.x/e.clientHeight),this._rotateUp(wg*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(t){this._dollyEnd.set(t.clientX,t.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(t){this._panEnd.set(t.clientX,t.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(t){this._updateZoomParameters(t.clientX,t.clientY),t.deltaY<0?this._dollyIn(this._getZoomScale(t.deltaY)):t.deltaY>0&&this._dollyOut(this._getZoomScale(t.deltaY)),this.update()}_handleKeyDown(t){let e=!1;switch(t.code){case this.keys.UP:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateUp(wg*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),e=!0;break;case this.keys.BOTTOM:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateUp(-wg*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),e=!0;break;case this.keys.LEFT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateLeft(wg*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),e=!0;break;case this.keys.RIGHT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateLeft(-wg*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),e=!0}e&&(t.preventDefault(),this.update())}_handleTouchStartRotate(t){if(1===this._pointers.length)this._rotateStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),i=.5*(t.pageX+e.x),n=.5*(t.pageY+e.y);this._rotateStart.set(i,n)}}_handleTouchStartPan(t){if(1===this._pointers.length)this._panStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),i=.5*(t.pageX+e.x),n=.5*(t.pageY+e.y);this._panStart.set(i,n)}}_handleTouchStartDolly(t){const e=this._getSecondPointerPosition(t),i=t.pageX-e.x,n=t.pageY-e.y,s=Math.sqrt(i*i+n*n);this._dollyStart.set(0,s)}_handleTouchStartDollyPan(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enablePan&&this._handleTouchStartPan(t)}_handleTouchStartDollyRotate(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enableRotate&&this._handleTouchStartRotate(t)}_handleTouchMoveRotate(t){if(1==this._pointers.length)this._rotateEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),i=.5*(t.pageX+e.x),n=.5*(t.pageY+e.y);this._rotateEnd.set(i,n)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(wg*this._rotateDelta.x/e.clientHeight),this._rotateUp(wg*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(t){if(1===this._pointers.length)this._panEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),i=.5*(t.pageX+e.x),n=.5*(t.pageY+e.y);this._panEnd.set(i,n)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(t){const e=this._getSecondPointerPosition(t),i=t.pageX-e.x,n=t.pageY-e.y,s=Math.sqrt(i*i+n*n);this._dollyEnd.set(0,s),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const r=.5*(t.pageX+e.x),a=.5*(t.pageY+e.y);this._updateZoomParameters(r,a)}_handleTouchMoveDollyPan(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enablePan&&this._handleTouchMovePan(t)}_handleTouchMoveDollyRotate(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enableRotate&&this._handleTouchMoveRotate(t)}_addPointer(t){this._pointers.push(t.pointerId)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId)return void this._pointers.splice(e,1)}_isTrackingPointer(t){for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId)return!0;return!1}_trackPointer(t){let e=this._pointerPositions[t.pointerId];void 0===e&&(e=new yi,this._pointerPositions[t.pointerId]=e),e.set(t.pageX,t.pageY)}_getSecondPointerPosition(t){const e=t.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[e]}_customWheelEvent(t){const e=t.deltaMode,i={clientX:t.clientX,clientY:t.clientY,deltaY:t.deltaY};switch(e){case 1:i.deltaY*=16;break;case 2:i.deltaY*=100}return t.ctrlKey&&!this._controlActive&&(i.deltaY*=10),i}}function Og(t){!1!==this.enabled&&(0===this._pointers.length&&(this.domElement.setPointerCapture(t.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),this._isTrackingPointer(t)||(this._addPointer(t),"touch"===t.pointerType?this._onTouchStart(t):this._onMouseDown(t),"grab"===this._cursorStyle&&(this.domElement.style.cursor="grabbing")))}function Fg(t){!1!==this.enabled&&("touch"===t.pointerType?this._onTouchMove(t):this._onMouseMove(t))}function Ng(t){switch(this._removePointer(t),this._pointers.length){case 0:this.domElement.releasePointerCapture(t.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(_g),this.state=Ag,"grab"===this._cursorStyle&&(this.domElement.style.cursor="grab");break;case 1:const e=this._pointers[0],i=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:i.x,pageY:i.y})}}function Ug(t){let e;switch(t.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case i.DOLLY:if(!1===this.enableZoom)return;this._handleMouseDownDolly(t),this.state=Tg;break;case i.ROTATE:if(t.ctrlKey||t.metaKey||t.shiftKey){if(!1===this.enablePan)return;this._handleMouseDownPan(t),this.state=Cg}else{if(!1===this.enableRotate)return;this._handleMouseDownRotate(t),this.state=Eg}break;case i.PAN:if(t.ctrlKey||t.metaKey||t.shiftKey){if(!1===this.enableRotate)return;this._handleMouseDownRotate(t),this.state=Eg}else{if(!1===this.enablePan)return;this._handleMouseDownPan(t),this.state=Cg}break;default:this.state=Ag}this.state!==Ag&&this.dispatchEvent(yg)}function kg(t){switch(this.state){case Eg:if(!1===this.enableRotate)return;this._handleMouseMoveRotate(t);break;case Tg:if(!1===this.enableZoom)return;this._handleMouseMoveDolly(t);break;case Cg:if(!1===this.enablePan)return;this._handleMouseMovePan(t)}}function zg(t){!1!==this.enabled&&!1!==this.enableZoom&&this.state===Ag&&(t.preventDefault(),this.dispatchEvent(yg),this._handleMouseWheel(this._customWheelEvent(t)),this.dispatchEvent(_g))}function Gg(t){!1!==this.enabled&&this._handleKeyDown(t)}function Hg(t){switch(this._trackPointer(t),this._pointers.length){case 1:switch(this.touches.ONE){case n.ROTATE:if(!1===this.enableRotate)return;this._handleTouchStartRotate(t),this.state=Dg;break;case n.PAN:if(!1===this.enablePan)return;this._handleTouchStartPan(t),this.state=Rg;break;default:this.state=Ag}break;case 2:switch(this.touches.TWO){case n.DOLLY_PAN:if(!1===this.enableZoom&&!1===this.enablePan)return;this._handleTouchStartDollyPan(t),this.state=Pg;break;case n.DOLLY_ROTATE:if(!1===this.enableZoom&&!1===this.enableRotate)return;this._handleTouchStartDollyRotate(t),this.state=Ig;break;default:this.state=Ag}break;default:this.state=Ag}this.state!==Ag&&this.dispatchEvent(yg)}function Vg(t){switch(this._trackPointer(t),this.state){case Dg:if(!1===this.enableRotate)return;this._handleTouchMoveRotate(t),this.update();break;case Rg:if(!1===this.enablePan)return;this._handleTouchMovePan(t),this.update();break;case Pg:if(!1===this.enableZoom&&!1===this.enablePan)return;this._handleTouchMoveDollyPan(t),this.update();break;case Ig:if(!1===this.enableZoom&&!1===this.enableRotate)return;this._handleTouchMoveDollyRotate(t),this.update();break;default:this.state=Ag}}function Wg(t){!1!==this.enabled&&t.preventDefault()}function jg(t){if("Control"===t.key){this._controlActive=!0;this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0})}}function Xg(t){if("Control"===t.key){this._controlActive=!1;this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0})}}const Yg=-1,Zg=0,qg=1,Qg=2;class Kg extends Bg{constructor(t,e=null){super(t,e),this.quaternion0=this.object.quaternion.clone(),this._horizontalRotate=!0,this._verticalRotate=!0,e&&(this._onCADPointerDown=this._handleCADPointerDown.bind(this),this._onCADPointerUp=this._handleCADPointerUp.bind(this),e.addEventListener("pointerdown",this._onCADPointerDown),e.addEventListener("pointerup",this._onCADPointerUp),e.addEventListener("pointercancel",this._onCADPointerUp)),this._onMouseDown=this._handleMouseDown.bind(this)}_handleCADPointerDown(t){this._horizontalRotate=!rf.get(t,"ctrl"),this._verticalRotate=!rf.get(t,"meta")}_handleCADPointerUp(){this._horizontalRotate=!0,this._verticalRotate=!0}dispose(){this.domElement&&this._onCADPointerDown&&this._onCADPointerUp&&(this.domElement.removeEventListener("pointerdown",this._onCADPointerDown),this.domElement.removeEventListener("pointerup",this._onCADPointerUp),this.domElement.removeEventListener("pointercancel",this._onCADPointerUp)),super.dispose()}_handleMouseDown(t){let e;switch(t.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case i.DOLLY:if(!1===this.enableZoom)return;this._handleMouseDownDolly(t),this.state=qg;break;case i.ROTATE:if(rf.get(t,"shift")){if(!1===this.enablePan)return;this._handleMouseDownPan(t),this.state=Qg}else{if(!1===this.enableRotate)return;this._handleMouseDownRotate(t),this.state=Zg}break;case i.PAN:if(rf.get(t,"ctrl")||rf.get(t,"meta")||rf.get(t,"shift")){if(!1===this.enableRotate)return;this._handleMouseDownRotate(t),this.state=Zg}else{if(!1===this.enablePan)return;this._handleMouseDownPan(t),this.state=Qg}break;default:this.state=Yg}}_rotateLeft(t){this._horizontalRotate&&(this._sphericalDelta.theta-=t)}_rotateUp(t){this._verticalRotate&&(this._sphericalDelta.phi-=t)}saveState(){super.saveState(),this.quaternion0.copy(this.object.quaternion)}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.quaternion.copy(this.quaternion0),(nf(this.object)||ef(this.object))&&(this.object.zoom=this.zoom0,this.object.updateProjectionMatrix()),this.dispatchEvent({type:"change"}),this.update(),this.state=-1}rotateLeft(t){this._sphericalDelta.theta-=t}rotateUp(t){this._sphericalDelta.phi-=t}}const Jg={type:"change"},$g={type:"start"},tv={type:"end"},ev=1e-6,iv=-1,nv=0,sv=1,rv=2,av=3,ov=4,lv=new yi,hv=new yi,cv=new xi,dv=new xi,uv=new xi,pv=new _i,mv=new xi,fv=new xi,gv=new xi,vv=new xi;class yv extends ud{constructor(t,e=null){super(t,e),this.screen={left:0,top:0,width:0,height:0},this.rotateSpeed=1,this.zoomSpeed=1.2,this.panSpeed=.3,this.noRotate=!1,this.noZoom=!1,this.noPan=!1,this.staticMoving=!1,this.dynamicDampingFactor=.2,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.keys=["KeyA","KeyS","KeyD"],this.mouseButtons={LEFT:i.ROTATE,MIDDLE:i.DOLLY,RIGHT:i.PAN},this.target=new xi,this.state=iv,this.keyState=iv,this._lastPosition=new xi,this._lastZoom=1,this._touchZoomDistanceStart=0,this._touchZoomDistanceEnd=0,this._lastAngle=0,this._eye=new xi,this._movePrev=new yi,this._moveCurr=new yi,this._lastAxis=new xi,this._zoomStart=new yi,this._zoomEnd=new yi,this._panStart=new yi,this._panEnd=new yi,this._pointers=[],this._pointerPositions={},this._onPointerMove=xv.bind(this),this._onPointerDown=_v.bind(this),this._onPointerUp=bv.bind(this),this._onPointerCancel=Sv.bind(this),this._onContextMenu=Dv.bind(this),this._onMouseWheel=Cv.bind(this),this._onKeyDown=wv.bind(this),this._onKeyUp=Mv.bind(this),this._onTouchStart=Rv.bind(this),this._onTouchMove=Pv.bind(this),this._onTouchEnd=Iv.bind(this),this._onMouseDown=Av.bind(this),this._onMouseMove=Ev.bind(this),this._onMouseUp=Tv.bind(this),this._target0=this.target.clone(),this._position0=this.object.position.clone(),this._up0=this.object.up.clone(),this._zoom0=this.object.zoom,null!==e&&(this.connect(e),this.handleResize()),this.update()}connect(t){super.connect(t),window.addEventListener("keydown",this._onKeyDown),window.addEventListener("keyup",this._onKeyUp),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerCancel),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="none"}disconnect(){window.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("keyup",this._onKeyUp),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerCancel),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}handleResize(){const t=this.domElement.getBoundingClientRect(),e=this.domElement.ownerDocument.documentElement;this.screen.left=t.left+window.pageXOffset-e.clientLeft,this.screen.top=t.top+window.pageYOffset-e.clientTop,this.screen.width=t.width,this.screen.height=t.height}update(){this._eye.subVectors(this.object.position,this.target),this.noRotate||this._rotateCamera(),this.noZoom||this._zoomCamera(),this.noPan||this._panCamera(),this.object.position.addVectors(this.target,this._eye),this.object.isPerspectiveCamera?(this._checkDistances(),this.object.lookAt(this.target),this._lastPosition.distanceToSquared(this.object.position)>ev&&(this.dispatchEvent(Jg),this._lastPosition.copy(this.object.position))):this.object.isOrthographicCamera?(this.object.lookAt(this.target),(this._lastPosition.distanceToSquared(this.object.position)>ev||this._lastZoom!==this.object.zoom)&&(this.dispatchEvent(Jg),this._lastPosition.copy(this.object.position),this._lastZoom=this.object.zoom)):console.warn("THREE.TrackballControls: Unsupported camera type.")}reset(){this.state=iv,this.keyState=iv,this.target.copy(this._target0),this.object.position.copy(this._position0),this.object.up.copy(this._up0),this.object.zoom=this._zoom0,this.object.updateProjectionMatrix(),this._eye.subVectors(this.object.position,this.target),this.object.lookAt(this.target),this.dispatchEvent(Jg),this._lastPosition.copy(this.object.position),this._lastZoom=this.object.zoom}_panCamera(){if(hv.copy(this._panEnd).sub(this._panStart),hv.lengthSq()){if(this.object.isOrthographicCamera){const t=(this.object.right-this.object.left)/this.object.zoom/this.domElement.clientWidth,e=(this.object.top-this.object.bottom)/this.object.zoom/this.domElement.clientWidth;hv.x*=t,hv.y*=e}hv.multiplyScalar(this._eye.length()*this.panSpeed),dv.copy(this._eye).cross(this.object.up).setLength(hv.x),dv.add(cv.copy(this.object.up).setLength(hv.y)),this.object.position.add(dv),this.target.add(dv),this.staticMoving?this._panStart.copy(this._panEnd):this._panStart.add(hv.subVectors(this._panEnd,this._panStart).multiplyScalar(this.dynamicDampingFactor))}}_rotateCamera(){vv.set(this._moveCurr.x-this._movePrev.x,this._moveCurr.y-this._movePrev.y,0);let t=vv.length();t?(this._eye.copy(this.object.position).sub(this.target),mv.copy(this._eye).normalize(),fv.copy(this.object.up).normalize(),gv.crossVectors(fv,mv).normalize(),fv.setLength(this._moveCurr.y-this._movePrev.y),gv.setLength(this._moveCurr.x-this._movePrev.x),vv.copy(fv.add(gv)),uv.crossVectors(vv,this._eye).normalize(),t*=this.rotateSpeed,pv.setFromAxisAngle(uv,t),this._eye.applyQuaternion(pv),this.object.up.applyQuaternion(pv),this._lastAxis.copy(uv),this._lastAngle=t):!this.staticMoving&&this._lastAngle&&(this._lastAngle*=Math.sqrt(1-this.dynamicDampingFactor),this._eye.copy(this.object.position).sub(this.target),pv.setFromAxisAngle(this._lastAxis,this._lastAngle),this._eye.applyQuaternion(pv),this.object.up.applyQuaternion(pv)),this._movePrev.copy(this._moveCurr)}_zoomCamera(){let t;this.state===ov?(t=this._touchZoomDistanceStart/this._touchZoomDistanceEnd,this._touchZoomDistanceStart=this._touchZoomDistanceEnd,this.object.isPerspectiveCamera?this._eye.multiplyScalar(t):this.object.isOrthographicCamera?(this.object.zoom=vi.clamp(this.object.zoom/t,this.minZoom,this.maxZoom),this._lastZoom!==this.object.zoom&&this.object.updateProjectionMatrix()):console.warn("THREE.TrackballControls: Unsupported camera type")):(t=1+(this._zoomEnd.y-this._zoomStart.y)*this.zoomSpeed,1!==t&&t>0&&(this.object.isPerspectiveCamera?this._eye.multiplyScalar(t):this.object.isOrthographicCamera?(this.object.zoom=vi.clamp(this.object.zoom/t,this.minZoom,this.maxZoom),this._lastZoom!==this.object.zoom&&this.object.updateProjectionMatrix()):console.warn("THREE.TrackballControls: Unsupported camera type")),this.staticMoving?this._zoomStart.copy(this._zoomEnd):this._zoomStart.y+=(this._zoomEnd.y-this._zoomStart.y)*this.dynamicDampingFactor)}_getMouseOnScreen(t,e){return lv.set((t-this.screen.left)/this.screen.width,(e-this.screen.top)/this.screen.height),lv}_getMouseOnCircle(t,e){return lv.set((t-.5*this.screen.width-this.screen.left)/(.5*this.screen.width),(this.screen.height+2*(this.screen.top-e))/this.screen.width),lv}_addPointer(t){this._pointers.push(t)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;e<this._pointers.length;e++)if(this._pointers[e].pointerId==t.pointerId)return void this._pointers.splice(e,1)}_trackPointer(t){let e=this._pointerPositions[t.pointerId];void 0===e&&(e=new yi,this._pointerPositions[t.pointerId]=e),e.set(t.pageX,t.pageY)}_getSecondPointerPosition(t){const e=t.pointerId===this._pointers[0].pointerId?this._pointers[1]:this._pointers[0];return this._pointerPositions[e.pointerId]}_checkDistances(){this.noZoom&&this.noPan||(this._eye.lengthSq()>this.maxDistance*this.maxDistance&&(this.object.position.addVectors(this.target,this._eye.setLength(this.maxDistance)),this._zoomStart.copy(this._zoomEnd)),this._eye.lengthSq()<this.minDistance*this.minDistance&&(this.object.position.addVectors(this.target,this._eye.setLength(this.minDistance)),this._zoomStart.copy(this._zoomEnd)))}}function _v(t){!1!==this.enabled&&(0===this._pointers.length&&(this.domElement.setPointerCapture(t.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),this._addPointer(t),"touch"===t.pointerType?this._onTouchStart(t):this._onMouseDown(t))}function xv(t){!1!==this.enabled&&("touch"===t.pointerType?this._onTouchMove(t):this._onMouseMove(t))}function bv(t){!1!==this.enabled&&("touch"===t.pointerType?this._onTouchEnd(t):this._onMouseUp(),this._removePointer(t),0===this._pointers.length&&(this.domElement.releasePointerCapture(t.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp)))}function Sv(t){this._removePointer(t)}function Mv(){!1!==this.enabled&&(this.keyState=iv,window.addEventListener("keydown",this._onKeyDown))}function wv(t){!1!==this.enabled&&(window.removeEventListener("keydown",this._onKeyDown),this.keyState===iv&&(t.code!==this.keys[nv]||this.noRotate?t.code!==this.keys[sv]||this.noZoom?t.code!==this.keys[rv]||this.noPan||(this.keyState=rv):this.keyState=sv:this.keyState=nv))}function Av(t){let e;switch(t.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case i.DOLLY:this.state=sv;break;case i.ROTATE:this.state=nv;break;case i.PAN:this.state=rv;break;default:this.state=iv}const n=this.keyState!==iv?this.keyState:this.state;n!==nv||this.noRotate?n!==sv||this.noZoom?n!==rv||this.noPan||(this._panStart.copy(this._getMouseOnScreen(t.pageX,t.pageY)),this._panEnd.copy(this._panStart)):(this._zoomStart.copy(this._getMouseOnScreen(t.pageX,t.pageY)),this._zoomEnd.copy(this._zoomStart)):(this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY)),this._movePrev.copy(this._moveCurr)),this.dispatchEvent($g)}function Ev(t){const e=this.keyState!==iv?this.keyState:this.state;e!==nv||this.noRotate?e!==sv||this.noZoom?e!==rv||this.noPan||this._panEnd.copy(this._getMouseOnScreen(t.pageX,t.pageY)):this._zoomEnd.copy(this._getMouseOnScreen(t.pageX,t.pageY)):(this._movePrev.copy(this._moveCurr),this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY)))}function Tv(){this.state=iv,this.dispatchEvent(tv)}function Cv(t){if(!1!==this.enabled&&!0!==this.noZoom){switch(t.preventDefault(),t.deltaMode){case 2:this._zoomStart.y-=.025*t.deltaY;break;case 1:this._zoomStart.y-=.01*t.deltaY;break;default:this._zoomStart.y-=25e-5*t.deltaY}this.dispatchEvent($g),this.dispatchEvent(tv)}}function Dv(t){!1!==this.enabled&&t.preventDefault()}function Rv(t){if(this._trackPointer(t),1===this._pointers.length)this.state=av,this._moveCurr.copy(this._getMouseOnCircle(this._pointers[0].pageX,this._pointers[0].pageY)),this._movePrev.copy(this._moveCurr);else{this.state=ov;const t=this._pointers[0].pageX-this._pointers[1].pageX,e=this._pointers[0].pageY-this._pointers[1].pageY;this._touchZoomDistanceEnd=this._touchZoomDistanceStart=Math.sqrt(t*t+e*e);const i=(this._pointers[0].pageX+this._pointers[1].pageX)/2,n=(this._pointers[0].pageY+this._pointers[1].pageY)/2;this._panStart.copy(this._getMouseOnScreen(i,n)),this._panEnd.copy(this._panStart)}this.dispatchEvent($g)}function Pv(t){if(this._trackPointer(t),1===this._pointers.length)this._movePrev.copy(this._moveCurr),this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY));else{const e=this._getSecondPointerPosition(t),i=t.pageX-e.x,n=t.pageY-e.y;this._touchZoomDistanceEnd=Math.sqrt(i*i+n*n);const s=(t.pageX+e.x)/2,r=(t.pageY+e.y)/2;this._panEnd.copy(this._getMouseOnScreen(s,r))}}function Iv(t){switch(this._pointers.length){case 0:this.state=iv;break;case 1:this.state=av,this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY)),this._movePrev.copy(this._moveCurr);break;case 2:this.state=ov;for(let e=0;e<this._pointers.length;e++)if(this._pointers[e].pointerId!==t.pointerId){const t=this._pointerPositions[this._pointers[e].pointerId];this._moveCurr.copy(this._getMouseOnCircle(t.x,t.y)),this._movePrev.copy(this._moveCurr);break}}this.dispatchEvent(tv)}const Lv=-1,Bv=0,Ov=1,Fv=2,Nv=new _i;let Uv=1;const kv=new _i,zv=new xi,Gv=new xi,Hv=new xi,Vv=new xi,Wv=new xi,jv=new xi;class Xv extends yv{constructor(t,e=null){super(t,e),this.holroyd=!0,this.radius=.9,this.quaternion0=this.object.quaternion.clone(),this._holroydStart=new yi,this._holroydEnd=new yi,this._holroydActive=!1,this._horizontalRotate=!0,this._verticalRotate=!0,e&&(this._holroydPointerDown=this._onHolroydPointerDown.bind(this),this._holroydPointerMove=this._onHolroydPointerMove.bind(this),this._holroydPointerUp=this._onHolroydPointerUp.bind(this),this._holroydWheel=this._onHolroydWheel.bind(this),e.addEventListener("pointerdown",this._holroydPointerDown),e.addEventListener("pointermove",this._holroydPointerMove),e.addEventListener("pointerup",this._holroydPointerUp),e.addEventListener("pointercancel",this._holroydPointerUp),e.addEventListener("wheel",this._holroydWheel,{passive:!1})),this._parentOnMouseDown=this._onMouseDown,this._onMouseDown=this._handleMouseDown.bind(this)}_handleMouseDown(t){if(!this.holroyd)return void this._parentOnMouseDown(t);let e;switch(t.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e===i.ROTATE&&rf.get(t,"shift")&&(e=i.PAN),e){case i.DOLLY:this.state=Ov;break;case i.ROTATE:this.state=Bv;break;case i.PAN:this.state=Fv;break;default:this.state=Lv}const n=this.keyState!==Lv?this.keyState:this.state;n!==Bv||this.noRotate?n!==Ov||this.noZoom?n!==Fv||this.noPan||(this._panStart.copy(this._getMouseOnScreen(t.pageX,t.pageY)),this._panEnd.copy(this._panStart)):(this._zoomStart.copy(this._getMouseOnScreen(t.pageX,t.pageY)),this._zoomEnd.copy(this._zoomStart)):(this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY)),this._movePrev.copy(this._moveCurr)),this.dispatchEvent({type:"start"})}_onHolroydPointerDown(t){this.holroyd&&0===t.button&&(rf.get(t,"shift")||(this._holroydStart.set(t.pageX,t.pageY),this._holroydEnd.set(t.pageX,t.pageY),this._holroydActive=!0,this._horizontalRotate=!rf.get(t,"ctrl"),this._verticalRotate=!rf.get(t,"meta")))}_onHolroydPointerMove(t){this.holroyd&&this._holroydActive&&this._holroydEnd.set(t.pageX,t.pageY),-1!==this.state&&this.update()}_onHolroydPointerUp(){this._holroydActive=!1,this._horizontalRotate=!0,this._verticalRotate=!0}_onHolroydWheel(){this.update(),this._zoomStart.copy(this._zoomEnd)}dispose(){this.domElement&&this._holroydPointerDown&&this._holroydPointerMove&&this._holroydPointerUp&&this._holroydWheel&&(this.domElement.removeEventListener("pointerdown",this._holroydPointerDown),this.domElement.removeEventListener("pointermove",this._holroydPointerMove),this.domElement.removeEventListener("pointerup",this._holroydPointerUp),this.domElement.removeEventListener("pointercancel",this._holroydPointerUp),this.domElement.removeEventListener("wheel",this._holroydWheel)),super.dispose()}saveState(){this._target0.copy(this.target),this._position0.copy(this.object.position),this._up0.copy(this.object.up),(nf(this.object)||ef(this.object))&&(this._zoom0=this.object.zoom),this.quaternion0.copy(this.object.quaternion)}reset(){super.reset(),this.object.quaternion.copy(this.quaternion0)}get target0(){return this._target0}get position0(){return this._position0}get zoom0(){return this._zoom0}set zoom0(t){this._zoom0=t}_getMouseOnSphere(t,e,i){const n=this.domElement.getBoundingClientRect(),s=this._horizontalRotate?(t-n.left)/(n.width/2)-1:0,r=this._verticalRotate?1-(e-n.top)/(n.height/2):0,a=this.radius*this.radius,o=s*s+r*r;return o<=a/2?i.set(s,r,Math.sqrt(a-o)):i.set(s,r,a/(2*Math.sqrt(o))),i}update(){if(!this.holroyd)return void super.update();this._eye.subVectors(this.object.position,this.target),this.noRotate||this._rotateCamera(),this.noZoom||this._zoomCamera(),this.noPan||this._panCamera(),this.object.position.addVectors(this.target,this._eye);const t=nf(this.object)||ef(this.object)?this.object.zoom:1,e=Math.abs(t-Uv)>1e-6;(this._lastPosition.distanceToSquared(this.object.position)>1e-6||Nv.dot(this.object.quaternion)<.999999||e)&&(this.dispatchEvent({type:"change"}),this._lastPosition.copy(this.object.position),Nv.copy(this.object.quaternion),Uv=t)}_rotateCamera(){if(!this.holroyd)return void super._rotateCamera();if(this._holroydStart.x===this._holroydEnd.x&&this._holroydStart.y===this._holroydEnd.y)return void this._movePrev.copy(this._moveCurr);this._getMouseOnSphere(this._holroydStart.x,this._holroydStart.y,Gv),this._getMouseOnSphere(this._holroydEnd.x,this._holroydEnd.y,Hv),zv.crossVectors(Gv,Hv);const t=Math.atan(zv.length()/Gv.dot(Hv));if(t){zv.normalize(),zv.applyQuaternion(this.object.quaternion);const e=-2*t*this.rotateSpeed;kv.setFromAxisAngle(zv,e),this.object.quaternion.premultiply(kv),this._eye.applyQuaternion(kv)}this._holroydStart.copy(this._holroydEnd),this._movePrev.copy(this._moveCurr)}_panCamera(){if(!this.holroyd)return void super._panCamera();const t=Vv.set(this._panEnd.x-this._panStart.x,this._panEnd.y-this._panStart.y,0);if(0!==t.lengthSq()){if(ef(this.object)){const e=(this.object.right-this.object.left)/this.object.zoom,i=(this.object.top-this.object.bottom)/this.object.zoom;t.x*=e*this.panSpeed*4,t.y*=i*this.panSpeed*4}else if(nf(this.object)&&this.domElement){const e=this.domElement.clientWidth/this.domElement.clientHeight;t.x*=e,t.multiplyScalar(this._eye.length()*this.panSpeed*1.6)}else t.multiplyScalar(this._eye.length()*this.panSpeed*2);jv.set(1,0,0).applyQuaternion(this.object.quaternion),Wv.set(0,1,0).applyQuaternion(this.object.quaternion),jv.multiplyScalar(-t.x),Wv.multiplyScalar(t.y),this.object.position.add(jv).add(Wv),this.target.add(jv).add(Wv),this._panStart.copy(this._panEnd)}}rotateX(t){this._rotateAroundAxis("x",t)}rotateY(t){this._rotateAroundAxis("y",t)}rotateZ(t){this._rotateAroundAxis("z",t)}_rotateAroundAxis(t,e){const i=Gm[t];kv.setFromAxisAngle(i,e),this.object.quaternion.premultiply(kv),this.object.position.sub(this.target).applyQuaternion(kv).add(this.target)}}const Yv={trackball:{pan:.22,rotate:1,zoom:2},orbit:{pan:1,rotate:1,zoom:1}};class Zv{constructor(t,e,i,n,s=1,r=1,a=1,o=!0){switch(this.getResetLocation=()=>({target0:this.controls.target0.clone(),position0:this.controls.position0.clone(),quaternion0:this.controls.quaternion0.clone(),zoom0:this.controls.zoom0}),this.setResetLocation=(t,e,i,n)=>{this.controls.target0.copy(t),this.controls.position0.copy(e),this.controls.quaternion0.copy(i),this.controls.zoom0=n},this.type=t,this.camera=e,this.target=i,this.target0=i.clone(),this.domElement=n,this.rotateSpeed=s,this.zoomSpeed=r,this.panSpeed=a,this.holroyd=o,t){case"orbit":this.initOrbitControls();break;case"trackball":this.initTrackballControls(o)}this.controls.target.copy(this.target),this._applySpeedFactors(),this.currentUpdateCallback=null,this.saveState(),this.update()}_getSpeedFactors(){return Yv[this.type]}_applySpeedFactors(){const t=this._getSpeedFactors();this.controls.rotateSpeed=this.rotateSpeed*t.rotate,this.controls.zoomSpeed=this.zoomSpeed*t.zoom,this.controls.panSpeed=this.panSpeed*t.pan}dispose(){this.controls.dispose()}saveState(){this.controls.saveState()}initTrackballControls(t=!0){this.controls=new Xv(this.camera,this.domElement),this.setHolroydTrackball(t)}initOrbitControls(){this.controls=new Kg(this.camera,this.domElement)}addChangeListener(t){null==this.currentUpdateCallback&&(this.currentUpdateCallback=t,this.controls.addEventListener("change",t))}removeChangeListener(){null!=this.currentUpdateCallback&&(this.controls.removeEventListener("change",this.currentUpdateCallback),this.currentUpdateCallback=null)}update(){this.controls.update()}handleResize(){this.controls instanceof Xv&&this.controls.handleResize()}reset(){this.controls.reset()}setCamera(t){this.controls.object=t}setHolroydTrackball(t){this.getTrackballControls().holroyd=t}getTarget(){return this.controls.target}isInteracting(){return-1!==this.controls.state}getZoom0(){return this.controls.zoom0}setTarget(t){this.controls.target.copy(t)}setZoomSpeed(t){this.zoomSpeed=t,this.controls.zoomSpeed=t*this._getSpeedFactors().zoom}setPanSpeed(t){this.panSpeed=t,this.controls.panSpeed=t*this._getSpeedFactors().pan}setRotateSpeed(t){this.rotateSpeed=t,this.controls.rotateSpeed=t*this._getSpeedFactors().rotate}getOrbitControls(){if(!(this.controls instanceof Kg))throw new Error("Operation requires OrbitControls");return this.controls}getTrackballControls(){if(!(this.controls instanceof Xv))throw new Error("Operation requires TrackballControls");return this.controls}rotateUp(t){this.getOrbitControls().rotateUp(-t/180*Math.PI),this.update()}rotateLeft(t){this.getOrbitControls().rotateLeft(t/180*Math.PI),this.update()}rotateX(t){this.getTrackballControls().rotateX(t/180*Math.PI),this.update()}rotateY(t){this.getTrackballControls().rotateY(t/180*Math.PI),this.update()}rotateZ(t){this.getTrackballControls().rotateZ(t/180*Math.PI),this.update()}}const qv={y_up:{iso:{pos:new xi(1,1,1),quat:null},front:{pos:new xi(0,0,1),quat:null},rear:{pos:new xi(0,0,-1),quat:null},left:{pos:new xi(-1,0,0),quat:null},right:{pos:new xi(1,0,0),quat:null},top:{pos:new xi(0,1,0),quat:null},bottom:{pos:new xi(0,-1,0),quat:null}},z_up:{iso:{pos:new xi(1,-1,1),quat:null},front:{pos:new xi(0,-1,0),quat:null},rear:{pos:new xi(0,1,0),quat:null},left:{pos:new xi(-1,0,0),quat:null},right:{pos:new xi(1,0,0),quat:null},top:{pos:new xi(0,0,1),quat:new _i(0,0,0,1)},bottom:{pos:new xi(0,0,-1),quat:new _i(1,0,0,0)}},legacy:{iso:{pos:new xi(1,1,1),quat:null},front:{pos:new xi(1,0,0),quat:null},rear:{pos:new xi(-1,0,0),quat:null},left:{pos:new xi(0,1,0),quat:null},right:{pos:new xi(0,-1,0),quat:null},top:{pos:new xi(0,0,1),quat:null},bottom:{pos:new xi(0,0,-1),quat:null}}},Qv={y_up:[0,1,0],z_up:[0,0,1],legacy:[0,0,1]};class Kv{static _computeNear(t){return Math.max(.1,Kv.NEAR_FACTOR*t)}constructor(t,e,i,n,s,r){this.target=new xi(...n),this.ortho=s,this.up={Y:"y_up",Z:"z_up",L:"legacy"}[r]||"z_up",this.yaxis=new xi(0,1,0),this.zaxis=new xi(0,0,1);const a=t/e;this.camera_distance=Kv.DISTANCE_FACTOR*i;const o=Kv._computeNear(i),l=100*i;this.pCamera=new Ph(22,a,o,l),this.pCamera.up.set(...Qv[this.up]),this.pCamera.lookAt(this.target);const h=this.projectSize(i,a);this.oCamera=new Fh(-h[0],h[0],h[1],-h[1],o,l),this.oCamera.up.set(...Qv[this.up]),this.oCamera.lookAt(this.target),this.camera=s?this.oCamera:this.pCamera,this.camera.up.set(...Qv[this.up])}updateFarPlane(t){const e=Kv._computeNear(t),i=100*t;this.pCamera.near=e,this.pCamera.far=i,this.oCamera.near=e,this.oCamera.far=i,this.camera.updateProjectionMatrix()}updateCameraDistance(t){this.camera_distance=Kv.DISTANCE_FACTOR*t}dispose(){}getCamera(){return this.camera}lookAtTarget(){this.camera.lookAt(this.target)}updateProjectionMatrix(){this.camera.updateProjectionMatrix()}switchCamera(t){const e=this.getPosition().clone(),i=this.getZoom(),n=this.getQuaternion().clone();t?(this.camera=this.oCamera,this.ortho=!0):(this.camera=this.pCamera,this.ortho=!1),this.setPosition(e,!1),this.setZoom(i),this.setQuaternion(n),this.updateProjectionMatrix()}projectSize(t,e){let i,n;return e<1?(i=t,n=i/e):(n=t,i=n*e),[i,n]}setupCamera(t,e=null,i=null,n=null){if(null!=e){const i=t?e.clone().normalize().multiplyScalar(this.camera_distance).add(this.target):e;this.camera.position.set(...i.toArray())}null!=i&&this.camera.quaternion.set(...i.toArray()),null!=n&&this.setZoom(n),this.updateProjectionMatrix()}presetCamera(t,e=null){null==e&&(e=this.camera.zoom),this.setupCamera(!0,qv[this.up][t].pos,null,e),this.lookAtTarget();const i=qv[this.up][t].quat;null!=i&&this.setQuaternion(i)}getZoom(){if(this.ortho)return this.camera.zoom;{const t=this.camera.position.clone().sub(this.target);return this.camera_distance/t.length()}}setZoom(t){this.ortho?this.camera.zoom=t:this.camera.position.sub(this.target).setLength(this.camera_distance/t).add(this.target),this.updateProjectionMatrix()}getPosition(){return this.camera.position}setPosition(t,e){Array.isArray(t)&&3===t.length?this.setupCamera(e,new xi(...t)):t instanceof xi?this.setupCamera(e,t):Fm.error("wrong type for position",t)}getQuaternion(){return this.camera.quaternion}setQuaternion(t){Array.isArray(t)&&4===t.length?this.setupCamera(!1,null,new _i(...t)):t instanceof _i?this.setupCamera(!1,null,t):Fm.error("wrong type for quaternion",t),this.updateProjectionMatrix()}getRotation(){return this.camera.rotation}getVisibleArea(){if(this.ortho&&this.oCamera){const t=(this.oCamera.top-this.oCamera.bottom)/this.oCamera.zoom;return{width:(this.oCamera.right-this.oCamera.left)/this.oCamera.zoom,height:t}}if(this.pCamera){const t=this.pCamera.position.distanceTo(this.target),e=this.pCamera.fov*Math.PI/180,i=2*Math.tan(e/2)*t;return{width:i*this.pCamera.aspect,height:i}}return{width:0,height:0}}changeDimensions(t,e,i){const n=e/i,s=this.projectSize(t,n);this.oCamera&&(this.oCamera.left=-s[0],this.oCamera.right=s[0],this.oCamera.top=s[1],this.oCamera.bottom=-s[1]),this.pCamera&&(this.pCamera.aspect=n),this.camera&&this.camera.updateProjectionMatrix()}}Kv.DISTANCE_FACTOR=5,Kv.NEAR_FACTOR=.01;const Jv={none:null,vertex:"vertex",edge:"edge",face:"face",solid:"solid"};class $v{constructor(t,e){this.obj=t,this.fromSolid=e}_getSolidObjectGroups(t){const e=t.parent.parent;let i;for(let t=0;t<e.children.length;t++){const n=e.children[t];if(n.name===e.name+"|faces"){i=n;break}}return(i?.children||[]).filter(lf)}objs(){return this.fromSolid?this._getSolidObjectGroups(this.obj):[this.obj]}}class ty{constructor(t,e,n,s,r,a,o){this.onMouseKeyDown=t=>{this.raycastMode&&this.camera&&(t.button!=i.LEFT&&t.button!=i.RIGHT||(this.lastPosition=this.camera.getPosition().clone()))},this.onMouseKeyUp=t=>{this.raycastMode&&this.camera&&this.lastPosition&&(t.button==i.LEFT?this.lastPosition.distanceTo(this.camera.getPosition())<1e-6&&this.callback({mouse:"left",shift:rf.get(t,"shift")}):t.button==i.RIGHT&&this.lastPosition.distanceTo(this.camera.getPosition())<1e-6&&this.callback({mouse:"right"}))},this.onKeyDown=t=>{this.raycastMode&&("Backspace"==t.key?this.callback({key:"Backspace"}):"Escape"==t.key&&this.callback({key:"Escape"}))},this.onPointerMove=t=>{if(!this.domElement)return;const e=this.domElement.getBoundingClientRect(),i=e.x+window.scrollX,n=e.y+window.scrollY;this.mouse.x=(t.pageX-i)/this.width*2-1,this.mouse.y=-(t.pageY-n)/this.height*2+1,this.mouseMoved=!0},this.camera=t,this.group=a,this.domElement=e,this.width=n,this.height=s,this.threshold=r,this.callback=o,this.raycaster=new Pc,this.raycastMode=!1,this.lastPosition=null,this.mouse=new yi,this.mouseMoved=!1,this.filters={topoFilter:[Jv.none]}}dispose(){this.domElement&&(this.domElement.removeEventListener("mousemove",this.onPointerMove),this.domElement.removeEventListener("mouseup",this.onMouseKeyUp),this.domElement.removeEventListener("mousedown",this.onMouseKeyDown)),document.removeEventListener("keydown",this.onKeyDown),this.raycastMode=!1,this.group=null,this.domElement=null,this.camera=null}init(){this.domElement&&(this.domElement.addEventListener("mousemove",this.onPointerMove),this.domElement.addEventListener("mouseup",this.onMouseKeyUp,!1),this.domElement.addEventListener("mousedown",this.onMouseKeyDown,!1),document.addEventListener("keydown",this.onKeyDown,!1),this.raycastMode=!0)}getIntersectedObjs(){if(!this.camera||!this.group)return[];this.raycaster.setFromCamera(this.mouse,this.camera.getCamera()),this.raycaster.params.Points.threshold=this.threshold/this.camera.getZoom(),this.raycaster.params.Line2={threshold:4};const t=this.raycaster.intersectObjects([this.group],!0),e=[];for(const i of t){const t=i.object;(Jm(t)||tf(t)||$m(t))&&t.visible&&!Array.isArray(t.material)&&t.material.visible&&e.push(i)}return e}getValidIntersectedObjs(){const t=[];if(this.mouseMoved){const e=this.getIntersectedObjs();for(const i of e){const e=i.object;if(!(Jm(e)||tf(e)||$m(e)))continue;if(!e.visible||Array.isArray(e.material)||!e.material.visible)continue;const n=i.object.parent;if(!lf(n))continue;if(!n.shapeInfo)continue;const s=n.shapeInfo.topo,r="solid"===n.subtype,a=this.filters.topoFilter.includes(Jv.solid)&&r,o=this.filters.topoFilter.some(t=>t===s);(a||this.filters.topoFilter.includes(Jv.none)||o)&&t.push(i)}}return t}}function ey(t,e){return Array.isArray(t)&&t.length===e&&t.every(t=>"number"==typeof t)}function iy(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)&&Object.values(t).every(t=>ey(t,3))}function ny(t){return t.toLowerCase().replace(/(\D)(\d+)$/,"$1 $2")}function sy(t,e){const i=["tcv_x_measure_val","tcv_y_measure_val","tcv_z_measure_val"],n=document.createElement("tr"),s=document.createElement("th");s.textContent=ny(t),s.classList.add("tcv_measure_key"),s.classList.add("tcv_measure_cell"),n.appendChild(s);const r=document.createElement("td");r.textContent="(",r.classList.add("tcv_measure_cell_bracket"),n.appendChild(r);for(let t=0;t<3;++t){const s=document.createElement("td");s.textContent=e[t].toFixed(3),s.classList.add("tcv_measure_val"),s.classList.add("tcv_measure_cell"),s.classList.add(i[t]),n.appendChild(s)}const a=document.createElement("td");return a.textContent=")",a.classList.add("tcv_measure_cell_bracket"),n.appendChild(a),n}function ry(t,e){const i=document.createElement("tr"),n=document.createElement("th"),s=document.createElement("td");return n.textContent=ny(t),n.classList.add("tcv_measure_key"),n.classList.add("tcv_measure_cell"),i.appendChild(n),s.textContent=e,s.classList.add("tcv_measure_val_center"),s.classList.add("tcv_measure_cell"),s.colSpan=5,i.appendChild(s),i}function ay(t,e,i=null){const n=document.createElement("tr"),s=document.createElement("th"),r=document.createElement("td");s.textContent=ny(t),s.classList.add("tcv_measure_key"),s.classList.add("tcv_measure_cell"),n.appendChild(s);for(let t=0;t<2;t++){const t=document.createElement("td");n.appendChild(t)}if(r.textContent=e.toFixed(3),r.classList.add("tcv_measure_val"),r.classList.add("tcv_measure_cell"),n.appendChild(r),null==i)for(let t=0;t<2;t++){const t=document.createElement("td");n.appendChild(t)}else{const t=document.createElement("td");t.textContent=`(${i})`,t.classList.add("tcv_measure_cell"),n.appendChild(t);const e=document.createElement("td");n.appendChild(e)}return n}class oy{constructor(t){this.show=t=>{this.html.style.display=t?"inline-block":"none"},this.isVisible=()=>"inline-block"==this.html.style.display,this.relocate=(t,e)=>{this.html.style.left=`${t}px`,this.html.style.top=`${e}px`},this.display=t,this.html=this.getHtmlElement(),this.finished=!1,this.callbacks=[],this.html.addEventListener("contextmenu",t=>{t.preventDefault()})}removeTable(){const t=this.html.getElementsByTagName("table");t.length>0&&t[0].remove(),this.finished=!1}resetTable(){this.removeTable()}registerCallback(t,e){this.callbacks.push({callback:e,type:t}),this.html.addEventListener(t,e)}dispose(){for(const t of this.callbacks)this.html.removeEventListener(t.type,t.callback)}}const ly=["type","tool_type","subtype","info","refpoint","refpoint1","refpoint2","shape_type","geom_type","groups","result"];function hy(t,e,i){let n=!0;for(const s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;if(ly.includes(s.toLowerCase()))continue;const r=t[s];let a;if("bb"===s.toLowerCase()&&iy(r))for(const t in r){const s=sy(`bb ${t}`,r[t]);i&&n&&(s.classList.add("tcv_measure_cell_top_border"),n=!1),e.appendChild(s)}else if(ey(r,3))a=sy(s,r);else if("number"==typeof r)if("distance"===s.toLowerCase()){a=ay(s,r,("string"==typeof t.info?t.info:void 0)??null)}else a=ay(s,r);else"string"==typeof r&&(a=ry(s,r));a&&(i&&n&&a.classList.add("tcv_measure_cell_top_border"),e.appendChild(a),n=!1)}}function cy(t,e){const i=t.result??t.groups;if(Array.isArray(i))for(let t=0;t<i.length;t++)hy(i[t],e,t>0);else hy(t,e,!1)}class dy extends oy{constructor(t){super(t)}getHtmlElement(){return this.display.measurementPanels.distancePanel}createTable(t){if(this.finished)return;this.resetTable();const e=document.createElement("table");e.classList.add("tcv_properties_table");const i=document.createElement("tbody");cy(t,i),e.appendChild(i),this.html.append(e),this.finished=!0}}class uy extends oy{constructor(t){super(t)}getHtmlElement(){return this.display.measurementPanels.propertiesPanel}setSubHeader(t){this.html.getElementsByClassName("tcv_measure_subheader")[0].textContent=t}createTable(t){if(this.finished)return;this.resetTable(),this.setSubHeader(`${t.shape_type??""} / ${t.geom_type??""}`);const e=document.createElement("table");e.classList.add("tcv_properties_table");const i=document.createElement("tbody");cy(t,i),e.appendChild(i),this.html.append(e),this.finished=!0}}class py{constructor(t){this.setValue=t=>{if(null!=this.raycaster){this.elements.value.innerText=t;const e=t.toLowerCase();"none"===e?this.raycaster.filters.topoFilter=[Jv.none]:e in Jv&&(this.raycaster.filters.topoFilter=[Jv[e]])}},this.toggleDropdown=t=>{null!=t&&t.stopPropagation(),this.elements.dropdown.classList.contains("tcv_filter_dropdown_active")?(this.elements.dropdown.classList.remove("tcv_filter_dropdown_active"),this.elements.icon.innerText="⏶"):(this.elements.dropdown.classList.add("tcv_filter_dropdown_active"),this.elements.icon.innerText="⏷")},this.closeDropdown=t=>{this.elements.dropdown.classList.contains("tcv_filter_dropdown_active")&&this.toggleDropdown(t)},this.handleSelection=t=>{const e=t.target;e instanceof HTMLElement&&(this.setValue(e.innerText),this.toggleDropdown(t))},this.reset=()=>{this.setValue("None")},this.keybindSelect=t=>{-1!==["n","v","e","f","s","Escape"].indexOf(t.key)&&("n"==t.key?this.setValue("None"):"v"==t.key?this.setValue("Vertex"):"e"==t.key?this.setValue("Edge"):"f"==t.key?this.setValue("Face"):"s"==t.key?this.setValue("Solid"):"Escape"==t.key&&this.closeDropdown(t))},this.display=t,this.elements=t.filterDropdown,this.elements.container.style.display="none",this.raycaster=null}setRaycaster(t){this.raycaster=t}getOptionElements(){const t=this.elements.options;return[t.none,t.vertex,t.edge,t.face,t.solid]}show(t){if(t){document.addEventListener("keydown",this.keybindSelect),this.display.container.addEventListener("click",this.closeDropdown),this.elements.content.addEventListener("click",this.toggleDropdown);for(const t of this.getOptionElements())t.addEventListener("click",this.handleSelection)}else{document.removeEventListener("keydown",this.keybindSelect),this.display.container.removeEventListener("click",this.closeDropdown),this.elements.content.removeEventListener("click",this.toggleDropdown);for(const t of this.getOptionElements())t.removeEventListener("click",this.handleSelection)}this.elements.container.style.display=t?"block":"none"}}class my extends _n{constructor(t,e,i,n,s,r=!0,a=!0){super(),this.coneLength=t,this.point1=e,this.point2=i,this.linewidth=n,this.color=s,this.arrowStart=r,this.arrowEnd=a,this.type="DistanceLineArrow",this.mode="inward",this.renderMode="arrows",this.initialize()}initialize(){const t=.8*this.coneLength,e=this.point1.distanceTo(this.point2);if(e<1e-9){this.renderMode="dot";const e=new gl(t/6,16,12),i=new lr({color:this.color}),n=new xr(e,i);return n.name="dot",n.position.copy(this.point1),void this.add(n)}this.renderMode="arrows",this.lineVec=this.point1.clone().sub(this.point2.clone()).normalize(),this.mode=e<t?"outward":"inward";const i="inward"===this.mode?1:-1;let n,s;n=this.arrowStart?this.point1.clone().sub(this.lineVec.clone().multiplyScalar(i*t*.3)):this.point1.clone(),s=this.arrowEnd?this.point2.clone().sub(this.lineVec.clone().multiplyScalar(-i*t*.3)):this.point2.clone();const r=new dm({linewidth:this.linewidth,color:this.color}),a=new cm;a.setPositions([...n.toArray(),...s.toArray()]);const o=new Cm(a,r),l=new to(t/4,.6*t,10),h=new lr({color:this.color}),c=new xr(l,h),d=new xr(l,h);c.name="startCone",d.name="endCone";const u=new Wi,p=new _i;"inward"===this.mode?(u.lookAt(this.point1,this.point2,c.up),p.setFromRotationMatrix(u),c.setRotationFromQuaternion(p),u.lookAt(this.point2,this.point1,d.up),p.setFromRotationMatrix(u),d.setRotationFromQuaternion(p)):(u.lookAt(this.point2,this.point1,c.up),p.setFromRotationMatrix(u),c.setRotationFromQuaternion(p),u.lookAt(this.point1,this.point2,d.up),p.setFromRotationMatrix(u),d.setRotationFromQuaternion(p)),c.rotateX(90*Math.PI/180),d.rotateX(90*Math.PI/180),c.position.copy(n),d.position.copy(s),this.arrowStart&&this.add(c),this.arrowEnd&&this.add(d),this.add(o)}update(t){if("dot"===this.renderMode){const e=this.children.find(t=>Jm(t)&&"dot"===t.name);return void(e&&Jm(e)&&e.scale.set(t,t,t))}const e=.8*this.coneLength,i="inward"===this.mode?1:-1,n=this.point1.clone().sub(this.lineVec.clone().multiplyScalar(i*t*e*.3)),s=this.point2.clone().sub(this.lineVec.clone().multiplyScalar(-i*t*e*.3)),r=this.children.find(t=>sf(t));if(r&&sf(r)&&r.geometry.setPositions([...this.arrowStart?n.toArray():this.point1.toArray(),...this.arrowEnd?s.toArray():this.point2.toArray()]),this.arrowStart){const e=this.children.find(t=>Jm(t)&&"startCone"===t.name);e&&Jm(e)&&(e.position.copy(n),e.scale.set(t,t,t))}if(this.arrowEnd){const e=this.children.find(t=>Jm(t)&&"endCone"===t.name);e&&Jm(e)&&(e.position.copy(s),e.scale.set(t,t,t))}}dispose(){const t=this.children.find(t=>sf(t));t&&sf(t)&&(t.geometry.dispose(),t.material.dispose());const e=this.children.find(t=>Jm(t)&&"startCone"===t.name);if(e&&Jm(e)){e.geometry.dispose();const t=e.material;Array.isArray(t)?t.forEach(t=>t.dispose()):t.dispose()}const i=this.children.find(t=>Jm(t)&&"dot"===t.name);if(i&&Jm(i)){i.geometry.dispose();const t=i.material;Array.isArray(t)?t.forEach(t=>t.dispose()):t.dispose()}this.clear()}}class fy{constructor(t,e){this.handleSelection=(t,e=!1)=>{this.shift=e,void 0!==this.selectedShapes.find(e=>e.obj.name===t.obj.name)?this.selectedShapes.splice(this.selectedShapes.indexOf(t),1):this.selectedShapes.push(t),this.panel&&(this.panel.finished=!1),this._updateMeasurement()},this._mouseup=t=>{this.panelDragData.clicked=!1,t.stopPropagation()},this._movePanel=()=>{if(!(this.panel&&this.viewer&&this.viewer.camera&&this.panel.isVisible()))return;const t=this.viewer.renderer.domElement.getBoundingClientRect(),e=this.panel.html.getBoundingClientRect();if(null==this.panelX&&null!=this.middlePoint){const i=this.middlePoint.clone().project(this.viewer.camera.getCamera()),n=(i.x+1)*(t.width/2),s=(1-i.y)*(t.height/2);n<t.width/2?this.panelX=n+e.width/2:this.panelX=n-e.width-e.width/2,this.panelX=Math.max(0,Math.min(t.width-e.width,this.panelX)),this.panelY=s,this.panelY=Math.max(0,Math.min(t.height-e.height,this.panelY))}if(this.panel.relocate(this.panelX,this.panelY),null==this.panelX||null==this.panelY)return;const i=this.panelX+e.width/2,n=this.panelY+e.height/2,s=i/(t.width/2)-1,r=1-n/(t.height/2),a=this.viewer.ortho?-.9:1,o=new xi(s,r,a),l=this.viewer.camera.getCamera();(nf(l)||ef(l))&&(l.updateProjectionMatrix(),l.updateMatrixWorld(),this.panelCenter=o.unproject(l)),this.scene&&this.scene.children.length>0&&this._updateConnectionLine()},this._dragPanel=t=>{if(!this.panelDragData.clicked||!this.panel||!this.viewer)return;if(null==this.panelDragData.x||null==this.panelDragData.y)return;const e=this.panel.html.getBoundingClientRect(),i=this.viewer.renderer.domElement.getBoundingClientRect(),n=t.clientX-this.panelDragData.x,s=t.clientY-this.panelDragData.y;e.x+n<i.x&&t.movementX<=0||e.x+n>i.x+i.width-e.width&&t.movementX>=0||null!==this.panelX&&(this.panelX+=n),e.y+s<i.y&&t.movementY<=0||e.y+s>i.y+i.height-e.height&&t.movementY>=0||null!==this.panelY&&(this.panelY+=s),this._updateMeasurement(),this.panelDragData.x=t.clientX,this.panelDragData.y=t.clientY},this.selectedShapes=[],this.point1=null,this.point2=null,this.middlePoint=null,this.contextEnabled=!1,this.viewer=t,this.scene=new Rn,this.panel=e,this.panelCenter=null,this.panelX=null,this.panelY=null,this.panelShown=!1,this.responseData=null,this.measurementLineColor=0,this.connectingLineColor=8388736,this.coneLength=void 0,this.debug=!1,this.panelDragData={x:null,y:null,clicked:!1},this.panel.registerCallback("mousedown",t=>{this.panelDragData.clicked=!0,this.panelDragData.x=t.clientX,this.panelDragData.y=t.clientY,t.stopPropagation()}),this.shift=!1}enableContext(){this.contextEnabled=!0,this.panelCenter=new xi(1,0,0),document.addEventListener("mouseup",this._mouseup),document.addEventListener("mousemove",this._dragPanel)}disableContext(){this._hideMeasurement(),this.contextEnabled=!1,this.responseData=null;for(const t of this.selectedShapes)t.obj.clearHighlights();this.selectedShapes=[],document.removeEventListener("mouseup",this._mouseup),document.removeEventListener("mousemove",this._dragPanel),this.viewer?.checkChanges({selectedShapeIDs:[]})}_hideMeasurement(){this.panel?.show(!1),this.disposeArrows(),this.scene?.clear()}handleResponse(t){}_createPanel(){throw new Error("Subclass needs to override this method")}_makeLines(){throw new Error("Subclass needs to override this method")}_updateConnectionLine(){throw new Error("Subclass needs to override this method")}_getMaxObjSelected(){throw new Error("Subclass needs to override this method")}_waitResponse(t,e){this.responseData?t(this.responseData):setTimeout(()=>{this._waitResponse(t,e)},100)}_updateMeasurement(){const t=this.selectedShapes.map(t=>{if(t.fromSolid){return t.obj.name.replace(/\|faces.*$/,"").replace(/\|edges.*$/,"").replace(/\|vertices.*$/,"").replaceAll("|","/")}return t.obj.name.replaceAll("|","/")});if(this.responseData=null,this.debug){const t=50+Math.floor(200*Math.random());setTimeout(()=>{if(0==this.selectedShapes.length)return;const t=t=>{const e=t.children[0];return e&&Jm(e)?(e.geometry.computeBoundingSphere(),e.geometry.boundingSphere?.center.clone()??null):null};let e;if(this instanceof yy){if(this.selectedShapes.length<2)return;const i=this.selectedShapes[0].obj,n=this.selectedShapes[1].obj,s=t(i),r=t(n);if(!s||!r)return;this.point1=i.localToWorld(s),this.point2=n.localToWorld(r),e={groups:[{distance:2.345,info:"center"},{"point 1":this.point1.toArray(),"point 2":this.point2.toArray()},{angle:43.21,"reference 1":"Plane (Face)","reference 2":"Plane (Face)"}],type:"backend_response",refpoint1:this.point1.toArray(),refpoint2:this.point2.toArray()}}else{if(!(this instanceof _y))return;{const i=this.selectedShapes[0].obj,n=t(i);if(!n)return;this.point1=i.localToWorld(n),e={type:"backend_response",shape_type:"Edge",geom_type:"EllipseArc",refpoint:this.point1.toArray(),groups:[{center:this.point1.toArray(),"major radius":.4,"minor radius":.2},{start:[2.4,-1,0],end:[1.8,-.8267949192431111,0]},{length:.6868592404716374},{bb:{min:[1.8,-1,0],center:[2.1,-.9,0],max:[2.4,-.8,0],size:[.56,.2,0]}}]}}}this.handleResponse(e)},t)}else this.viewer?.checkChanges({selectedShapeIDs:[...t,this.shift]});if(this.selectedShapes.length!=this._getMaxObjSelected())return void this._hideMeasurement();new Promise((t,e)=>{this._waitResponse(t,e)}).then(t=>{this._createPanel(),this._makeLines(),this.panel?.show(!0),this._movePanel()})}removeLastSelectedObj(t=!1){if(t||this.selectedShapes.length==this._getMaxObjSelected()){const t=this.selectedShapes.pop();if(t){const e=t.objs();for(const t of e)t.clearHighlights()}this._updateMeasurement()}}_adjustArrowsScaleFactor(t){if(!this.scene)return;const e=1/t;this.scene.children.forEach(t=>{t instanceof my&&t.update(e)})}update(){if(!this.viewer||!this.viewer.camera||!this.scene)return;const t=this.viewer.camera.getCamera(),e=this.viewer.camera.getZoom(),i=this.viewer.state.get("cadWidth"),n=this.viewer.state.get("height");"number"==typeof i&&"number"==typeof n&&(this.coneLength=this.viewer.bb_radius/(Math.max(i,n)/60)),this._adjustArrowsScaleFactor(e),this.viewer.renderer.clearDepth(),this._movePanel(),this.viewer.renderer.render(this.scene,t)}disposeArrows(){this.scene&&(Qm(this.scene),this.scene.clear())}dispose(){this.panel&&(this.panel.show(!1),Qm(this.panel)),this.disposeArrows(),this.panel=null,this.viewer=null,this.scene=null}}function gy(t){return null!==t&&"refpoint1"in t&&"refpoint2"in t}function vy(t){return null!==t&&"refpoint"in t}class yy extends fy{constructor(t,e){super(t,new dy(t.display)),this.point1=null,this.point2=null,this.middlePoint=null,this.debug=e}_createPanel(){this.panel instanceof dy&&gy(this.responseData)&&this.panel.createTable(this.responseData)}_getMaxObjSelected(){return 2}_getPoints(){gy(this.responseData)&&(this.responseData.refpoint1&&(this.point1=new xi(...this.responseData.refpoint1)),this.responseData.refpoint2&&(this.point2=new xi(...this.responseData.refpoint2)))}_makeLines(){if(!this.scene||0!==this.scene.children.length)return;if(!(this.coneLength&&this.point1&&this.point2&&this.panelCenter))return;const t=new my(this.coneLength,this.point1,this.point2,1.5,this.measurementLineColor);this.scene.add(t),this.middlePoint=(new xi).addVectors(this.point1,this.point2).multiplyScalar(.5);const e=new my(this.coneLength,this.panelCenter,this.middlePoint,1.5,this.connectingLineColor,!1,!1);this.scene.add(e)}_updateConnectionLine(){if(!this.scene||!this.middlePoint||!this.panelCenter)return;const t=this.scene.children[1];if(!(t instanceof my))return;const e=t.children.find(t=>sf(t));e&&sf(e)&&e.geometry.setPositions([...this.middlePoint.toArray(),...this.panelCenter.toArray()])}handleResponse(t){this.responseData={...t},this._getPoints()}}class _y extends fy{constructor(t,e){super(t,new uy(t.display)),this.middlePoint=null,this.debug=e}_createPanel(){this.panel instanceof uy&&vy(this.responseData)&&this.panel.createTable(this.responseData)}_getMaxObjSelected(){return 1}_getPoint(){vy(this.responseData)&&this.responseData.refpoint&&(this.point1=new xi(...this.responseData.refpoint))}_makeLines(){if(!this.scene||0!==this.scene.children.length)return;if(!this.coneLength||!this.panelCenter||!this.point1)return;this.middlePoint=this.point1;const t=new my(this.coneLength,this.panelCenter,this.middlePoint,1.5,this.connectingLineColor,!1,!1);this.scene.add(t)}_updateConnectionLine(){if(!this.scene||!this.middlePoint||!this.panelCenter)return;const t=this.scene.children[0];if(!(t instanceof my))return;const e=t.children.find(t=>sf(t));e&&sf(e)&&e.geometry.setPositions([...this.middlePoint.toArray(),...this.panelCenter.toArray()])}handleResponse(t){this.responseData={...t},this._getPoint()}}class xy{constructor(t){this.viewer=t,this.selectedShapes=[],this.contextEnabled=!1}enableContext(){this.contextEnabled=!0}disableContext(){this.contextEnabled=!1;for(const t of this.selectedShapes)t.obj.clearHighlights();this.selectedShapes=[]}_getMaxObjSelected(){return null}_getIndex(t){const e=t.split("|");return e[e.length-1].split("_")[1]}_includes(t){for(const e of this.selectedShapes)if(t===e.obj.name)return!0;return!1}notify(){const t=[];for(const e of this.selectedShapes){const i=e.obj.name;t.push(this._getIndex(i))}this.viewer.checkChanges({selected:t},!0)}handleSelection(t){if(!t)return;const e=t.obj.name;this._includes(e)?this.selectedShapes=this.selectedShapes.filter(t=>t.obj.name!==e):this.selectedShapes.push(t),this.notify()}_removeLastSelectedObj(t){if(t){const e=t.objs();for(const t of e)t.clearHighlights()}this.notify()}removeLastSelectedObj(t){if(t){for(const t of this.selectedShapes)this._removeLastSelectedObj(t);this.selectedShapes=[]}else{const t=this.selectedShapes.pop();this._removeLastSelectedObj(t),this.notify()}}update(){}handleResponse(t){}dispose(){this.disableContext()}}const by="None",Sy="DistanceMeasurement",My="PropertiesMeasurement",wy="SelectObjects";class Ay{constructor(t,e){this.viewer=t,this.distanceMeasurement=new yy(t,e),this.propertiesMeasurement=new _y(t,e),this.selectObject=new xy(t),this.enabledTool=null}enable(t){switch(this.enabledTool&&this.disable(),t){case Sy:this.distanceMeasurement.enableContext();break;case My:this.propertiesMeasurement.enableContext();break;case wy:this.selectObject.enableContext();break;default:throw new Error(`Unknown tool type: ${t}`)}this.enabledTool=t}disable(){this.enabledTool&&(this.viewer.display.shapeFilterDropDownMenu.reset(),this._disable())}_disable(){if(this.enabledTool){switch(this.enabledTool){case Sy:this.distanceMeasurement.disableContext();break;case My:this.propertiesMeasurement.disableContext();break;case wy:this.selectObject.disableContext();break;default:throw new Error(`Unknown tool type: ${this.enabledTool}`)}this.enabledTool=null}}handleRemoveLastSelection(t=!1){this.distanceMeasurement.contextEnabled?this.distanceMeasurement.removeLastSelectedObj(t):this.propertiesMeasurement.contextEnabled?this.propertiesMeasurement.removeLastSelectedObj(t):this.selectObject.contextEnabled&&this.selectObject.removeLastSelectedObj(!1)}handleSelectedObj(t,e,i){this.distanceMeasurement.contextEnabled?(e&&this.distanceMeasurement.removeLastSelectedObj(),this.distanceMeasurement.handleSelection(t,i)):this.propertiesMeasurement.contextEnabled?(e&&this.propertiesMeasurement.removeLastSelectedObj(),this.propertiesMeasurement.handleSelection(t)):this.selectObject.contextEnabled&&this.selectObject.handleSelection(t)}handleResetSelection(){this.distanceMeasurement.contextEnabled?(this.distanceMeasurement.removeLastSelectedObj(!0),this.distanceMeasurement.removeLastSelectedObj(!0)):this.propertiesMeasurement.contextEnabled?this.propertiesMeasurement.removeLastSelectedObj(!0):this.selectObject.contextEnabled&&this.selectObject.removeLastSelectedObj(!0)}handleResponse(t){switch(t.tool_type){case Sy:this.distanceMeasurement.handleResponse(t);break;case My:this.propertiesMeasurement.handleResponse(t);break;case wy:this.selectObject.handleResponse(t)}}update(){this.distanceMeasurement.contextEnabled?this.distanceMeasurement.update():this.propertiesMeasurement.contextEnabled?this.propertiesMeasurement.update():this.selectObject.contextEnabled&&this.selectObject.update()}dispose(){this.distanceMeasurement.dispose(),this.propertiesMeasurement.dispose(),this.selectObject.dispose()}}const Ey="4.3.7";class Ty extends Rn{constructor(){super(),this.name="CleanRoomEnvironment",this.position.y=-3.5,this.rotation.y=45*Math.PI/180;const t=new Qa;t.deleteAttribute("uv");const e=new Pl({side:1}),i=new Oh(16777215,900,28,2);i.position.set(.418,16.199,.3),this.add(i);const n=new xr(t,e);n.position.set(-.757,13.219,.717),n.scale.set(31.713,28.305,28.591),this.add(n);const s=15.8565,r=13.219-14.1525,a=-.757-s,o=new xr(function(t,e,i){const n=[],s=[],r=[],a=-1;for(let r=0;r<=i;r++){const o=r/i*Math.PI/2,l=a*e*Math.sin(o),h=e*(1-Math.cos(o)),c=a*Math.sin(o),d=-Math.cos(o);n.push(0,h,l),s.push(0,d,c),n.push(t,h,l),s.push(0,d,c)}for(let t=0;t<i;t++){const e=2*t,i=e+1,n=e+2,s=e+3;r.push(e,n,i,i,n,s)}const o=new Ds;return o.setAttribute("position",new vs(n,3)),o.setAttribute("normal",new vs(s,3)),o.setIndex(r),o}(2*s,6,12),e);o.position.set(a,r,-7.5785),this.add(o);const l=new xr(t,Cy(50));l.position.set(-16.116,14.37,8.208),l.scale.set(.1,2.428,2.739),this.add(l);const h=new xr(t,Cy(50));h.position.set(-16.109,18.021,-8.207),h.scale.set(.1,2.425,2.751),this.add(h);const c=new xr(t,Cy(17));c.position.set(14.904,12.198,-1.832),c.scale.set(.15,4.265,6.331),this.add(c);const d=new xr(t,Cy(43));d.position.set(-.462,8.89,14.52),d.scale.set(4.38,5.441,.088),this.add(d);const u=new xr(t,Cy(20));u.position.set(3.235,11.486,-12.541),u.scale.set(2.5,2,.1),this.add(u);const p=new xr(t,Cy(100));p.position.set(0,20,0),p.scale.set(1,.1,1),this.add(p)}dispose(){const t=new Set;this.traverse(e=>{if("isMesh"in e&&e.isMesh){const i=e;t.add(i.geometry),Array.isArray(i.material)||t.add(i.material)}});for(const e of t)e.dispose()}}function Cy(t){return new Fl({color:0,emissive:16777215,emissiveIntensity:t})}class Dy extends gh{constructor(t){super(t),this.type=ft}parse(t){const e=function(t,e){switch(t){case 1:throw new Error("THREE.HDRLoader: Read Error: "+(e||""));case 2:throw new Error("THREE.HDRLoader: Write Error: "+(e||""));case 3:throw new Error("THREE.HDRLoader: Bad File Format: "+(e||""));default:throw new Error("THREE.HDRLoader: Memory Error: "+(e||""))}},i=function(t,e,i){e=e||1024;let n=t.pos,s=-1,r=0,a="",o=String.fromCharCode.apply(null,new Uint16Array(t.subarray(n,n+128)));for(;0>(s=o.indexOf("\n"))&&r<e&&n<t.byteLength;)a+=o,r+=o.length,n+=128,o+=String.fromCharCode.apply(null,new Uint16Array(t.subarray(n,n+128)));return-1<s&&(t.pos+=r+s+1,a+o.slice(0,s))},n=function(t,e,i,n){const s=t[e+3],r=Math.pow(2,s-128)/255;i[n+0]=t[e+0]*r,i[n+1]=t[e+1]*r,i[n+2]=t[e+2]*r,i[n+3]=1},s=function(t,e,i,n){const s=t[e+3],r=Math.pow(2,s-128)/255;i[n+0]=cs.toHalfFloat(Math.min(t[e+0]*r,65504)),i[n+1]=cs.toHalfFloat(Math.min(t[e+1]*r,65504)),i[n+2]=cs.toHalfFloat(Math.min(t[e+2]*r,65504)),i[n+3]=cs.toHalfFloat(1)},r=new Uint8Array(t);r.pos=0;const a=function(t){const n=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,s=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,r=/^\s*FORMAT=(\S+)\s*$/,a=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,o={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let l,h;for((t.pos>=t.byteLength||!(l=i(t)))&&e(1,"no header found"),(h=l.match(/^#\?(\S+)/))||e(3,"bad initial token"),o.valid|=1,o.programtype=h[1],o.string+=l+"\n";l=i(t),!1!==l;)if(o.string+=l+"\n","#"!==l.charAt(0)){if((h=l.match(n))&&(o.gamma=parseFloat(h[1])),(h=l.match(s))&&(o.exposure=parseFloat(h[1])),(h=l.match(r))&&(o.valid|=2,o.format=h[1]),(h=l.match(a))&&(o.valid|=4,o.height=parseInt(h[1],10),o.width=parseInt(h[2],10)),2&o.valid&&4&o.valid)break}else o.comments+=l+"\n";return 2&o.valid||e(3,"missing format specifier"),4&o.valid||e(3,"missing image size specifier"),o}(r),o=a.width,l=a.height,h=function(t,i,n){const s=i;if(s<8||s>32767||2!==t[0]||2!==t[1]||128&t[2])return new Uint8Array(t);s!==(t[2]<<8|t[3])&&e(3,"wrong scanline width");const r=new Uint8Array(4*i*n);r.length||e(4,"unable to allocate buffer space");let a=0,o=0;const l=4*s,h=new Uint8Array(4),c=new Uint8Array(l);let d=n;for(;d>0&&o<t.byteLength;){o+4>t.byteLength&&e(1),h[0]=t[o++],h[1]=t[o++],h[2]=t[o++],h[3]=t[o++],2==h[0]&&2==h[1]&&(h[2]<<8|h[3])==s||e(3,"bad rgbe scanline format");let i,n=0;for(;n<l&&o<t.byteLength;){i=t[o++];const s=i>128;if(s&&(i-=128),(0===i||n+i>l)&&e(3,"bad scanline data"),s){const e=t[o++];for(let t=0;t<i;t++)c[n++]=e}else c.set(t.subarray(o,o+i),n),n+=i,o+=i}const u=s;for(let t=0;t<u;t++){let e=0;r[a]=c[t+e],e+=s,r[a+1]=c[t+e],e+=s,r[a+2]=c[t+e],e+=s,r[a+3]=c[t+e],a+=4}d--}return r}(r.subarray(r.pos),o,l);let c,d,u;switch(this.type){case mt:u=h.length/4;const t=new Float32Array(4*u);for(let e=0;e<u;e++)n(h,4*e,t,4*e);c=t,d=mt;break;case ft:u=h.length/4;const e=new Uint16Array(4*u);for(let t=0;t<u;t++)s(h,4*t,e,4*t);c=e,d=ft;break;default:throw new Error("THREE.HDRLoader: Unsupported type: "+this.type)}return{width:o,height:l,data:c,header:a.string,gamma:a.gamma,exposure:a.exposure,type:d}}setDataType(t){return this.type=t,this}load(t,e,i,n){return super.load(t,function(t,i){switch(t.type){case mt:case ft:t.colorSpace=Te,t.minFilter=rt,t.magFilter=rt,t.generateMipmaps=!1,t.flipY=!0}e&&e(t,i)},i,n)}}const Ry=128,Py=64;function Iy(t){const e=t>>15&1,i=t>>10&31,n=1023&t;return 0===i?(e?-1:1)*Math.pow(2,-14)*(n/1024):31===i?n?NaN:e?-1/0:1/0:(e?-1:1)*Math.pow(2,i-15)*(1+n/1024)}function Ly(){return{lights:[{direction:function(t){const e=Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);return 0===e?[0,1,0]:[t[0]/e,t[1]/e,t[2]/e]}([.3,.8,.5]),intensity:1,color:[1,1,1]}],wasAnalyzed:!1}}const By=new En(.18,.18,.18),Oy=new yi,Fy=new En(.03,.03,.03),Ny=new En(1,1,1);function Uy(t,e){const i=512,n=document.createElement("canvas");n.width=i,n.height=i;const s=n.getContext("2d"),r=s.createRadialGradient(256,256,0,256,256,358.4);r.addColorStop(0,t),r.addColorStop(1,e),s.fillStyle=e,s.fillRect(0,0,i,i),s.fillStyle=r,s.fillRect(0,0,i,i);const a=new Xa(n);return a.colorSpace=Ee,a}let ky=null,zy=null;const Gy=["studio_small_08","studio_small_03","white_studio_05","white_studio_03","photo_studio_01","studio_small_09","cyclorama_hard_light","canary_wharf","kiara_1_dawn","empty_warehouse_01","san_giuseppe_bridge"];function Hy(t){const e=t?"4k":"2k",i={};for(const t of Gy)i[t]=`https://dl.polyhaven.org/file/ph-assets/HDRIs/hdr/${e}/${t}_${e}.hdr`;return i}class Vy{constructor(t={}){this._cache=new Map,this._lightDetectionCache=new Map,this._inflight=new Map,this._pmremGenerator=null,this._use4k=!1,this._userOverrides={},this._hdrLoader=null,this._currentTexture=null,this._disposed=!1,this._bgScene=null,this._bgCamera=null,this._bgRenderTarget=null,this._orthoEnvMainScene=null,this._envBackgroundActive=!1,this._deferredApply=null,this._userOverrides=t.presetUrls??{},this._presetUrls={...Hy(!1),...this._userOverrides}}async loadEnvironment(t,e){if(this._disposed)return Fm.warn("EnvironmentManager.loadEnvironment() called after dispose"),null;if("none"===t)return this._currentTexture=null,null;const i=t,n=this._cache.get(i);if(n)return Fm.debug(`Environment "${i}" loaded from cache`),this._currentTexture=n.texture,n.texture;const s=this._inflight.get(i);if(s){Fm.debug(`Environment "${i}" already loading, reusing promise`);const t=await s;return this._currentTexture=t,t}const r=this._load(t,e);this._inflight.set(i,r);try{const t=await r;if(this._currentTexture=t,this._deferredApply){const{scene:t,envIntensity:e,upIsZ:i,ortho:n}=this._deferredApply;this._deferredApply=null,this.apply(t,e,"environment",i,n)}return t}finally{this._inflight.delete(i)}}apply(t,e,i="grey",n=!0,s=!1,r=0){const a=r*Math.PI/180;switch(this._currentTexture?(t.environment=this._currentTexture,t.environmentIntensity=e,n?t.environmentRotation.set(Math.PI/2,0,a):t.environmentRotation.set(0,a,0)):(t.environment=null,t.environmentIntensity=1,t.environmentRotation.set(0,0,0)),"environment"!==i&&(this._deferredApply=null),i){case"white":t.background=Ny,t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground();break;case"gradient":t.background=(ky||(ky=Uy("#f0f0f0","#c8c8c8")),ky),t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground();break;case"gradient-dark":t.background=(zy||(zy=Uy("#808080","#606060")),zy),t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground();break;case"environment":this._currentTexture?(this._setupEnvBackground(t,this._currentTexture,n,a),this._deferredApply=null):(this._deferredApply={scene:t,envIntensity:e,upIsZ:n,ortho:s},t.background=By,t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground());break;case"transparent":t.background=null,t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground();break;case"darkgrey":t.background=Fy,t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground();break;default:t.background=By,t.backgroundIntensity=1,t.backgroundBlurriness=0,this._teardownEnvBackground()}}remove(t){this._deferredApply=null,this._teardownEnvBackground(),t.environment=null,t.background=null,t.environmentIntensity=1,t.environmentRotation.set(0,0,0),t.backgroundIntensity=1,t.backgroundBlurriness=0,t.backgroundRotation.set(0,0,0)}async setUse4kEnvMaps(t,e,i){if(t===this._use4k)return this._currentTexture;this._use4k=t,this._presetUrls={...Hy(t),...this._userOverrides};for(const t of Gy){const e=this._cache.get(t);e&&(zm.untrack("texture",e.texture),e.dispose(),this._cache.delete(t),this._lightDetectionCache.delete(t),Fm.debug(`Evicted cached environment "${t}" for resolution switch`))}return e&&"none"!==e&&"studio"!==e?this.loadEnvironment(e,i):this._currentTexture}get use4kEnvMaps(){return this._use4k}isPreset(t){return Gy.includes(t)}get isEnvBackgroundActive(){return this._envBackgroundActive}getLightDetection(t){return this._lightDetectionCache.get(t)??null}updateEnvBackground(t,e){if(!(this._envBackgroundActive&&this._bgScene&&this._bgCamera&&this._orthoEnvMainScene))return;const i=t.getDrawingBufferSize(Oy),n=i.x,s=i.y;this._bgRenderTarget&&this._bgRenderTarget.width===n&&this._bgRenderTarget.height===s||(this._bgRenderTarget?.dispose(),this._bgRenderTarget=new Gi(n,s));const r=n/s;this._bgCamera.aspect!==r&&(this._bgCamera.aspect=r,this._bgCamera.updateProjectionMatrix()),e&&this._bgCamera.quaternion.copy(e.quaternion),t.setRenderTarget(this._bgRenderTarget),t.clear(),t.render(this._bgScene,this._bgCamera),t.setRenderTarget(null),this._orthoEnvMainScene.background=this._bgRenderTarget.texture,this._orthoEnvMainScene.backgroundIntensity=1,this._orthoEnvMainScene.backgroundBlurriness=0}dispose(){this._disposed=!0,this._currentTexture=null,this._deferredApply=null,this._teardownEnvBackground(),this._bgScene=null,this._bgCamera=null,this._bgRenderTarget&&(this._bgRenderTarget.dispose(),this._bgRenderTarget=null);for(const[t,e]of this._cache)zm.untrack("texture",e.texture),e.dispose(),Fm.debug(`Disposed cached environment render target: ${t}`);this._cache.clear(),this._lightDetectionCache.clear(),this._inflight.clear(),this._pmremGenerator&&(this._pmremGenerator.dispose(),this._pmremGenerator=null,Fm.debug("Disposed PMREMGenerator")),this._hdrLoader=null,function(){ky&&(ky.dispose(),ky=null);zy&&(zy.dispose(),zy=null)}()}_setupEnvBackground(t,e,i,n=0){this._bgScene||(this._bgScene=new Rn),this._bgCamera||(this._bgCamera=new Ph(50,1,.1,10)),this._bgScene.background=e,this._bgScene.backgroundIntensity=1,this._bgScene.backgroundBlurriness=0,i?this._bgScene.backgroundRotation.set(Math.PI/2,0,n):this._bgScene.backgroundRotation.set(0,n,0),this._orthoEnvMainScene=t,this._envBackgroundActive=!0}_teardownEnvBackground(){this._envBackgroundActive=!1,this._orthoEnvMainScene=null}_resolveUrl(t){if("studio"===t)return null;const e=this._presetUrls[t];return e||t}_ensurePmremGenerator(t){return this._pmremGenerator||(this._pmremGenerator=new Fd(t),Fm.debug("Created PMREMGenerator")),this._pmremGenerator}_ensureHdrLoader(){return this._hdrLoader||(this._hdrLoader=new Dy,Fm.debug("Created HDRLoader")),this._hdrLoader}async _load(t,e){if("studio"===t)return this._loadRoomEnvironment(t,e);const i=this._resolveUrl(t);try{return await this._loadHdr(i,t,e)}catch(n){if(this._disposed)throw n;const s=t in this._presetUrls?t:`custom URL (${i})`;return Fm.warn(`Could not load environment "${s}", using default "studio" environment.`,n instanceof Error?n.message:n),this._loadRoomEnvironment("studio",e)}}_loadRoomEnvironment(t,e){if(this._disposed)throw new Error("EnvironmentManager was disposed");const i=this._cache.get(t);if(i)return i.texture;const n=this._ensurePmremGenerator(e),s=new Ty,r=n.fromScene(s,0,.1,100,{size:2048});return s.traverse(t=>{t instanceof xr&&(t.geometry.dispose(),Array.isArray(t.material)?t.material.forEach(t=>t.dispose()):t.material.dispose())}),this._cache.set(t,r),zm.trackTexture(r.texture,`PMREM environment: ${t}`),this._lightDetectionCache.set(t,Ly()),Fm.debug(`Generated RoomEnvironment PMREM, cached as "${t}"`),r.texture}async _loadHdr(t,e,i){const n=this._ensureHdrLoader(),s=this._ensurePmremGenerator(i);Fm.debug(`Loading HDR environment from: ${t}`);const r=await Promise.race([n.loadAsync(t),new Promise((e,i)=>setTimeout(()=>i(new Error(`HDR load timed out after 30 s: ${t}`)),3e4))]);if(this._disposed)throw r.dispose(),new Error("EnvironmentManager was disposed during HDR load");const a=s.fromEquirectangular(r);if(r.image?.data&&r.image.width&&r.image.height){const t=function(t,e,i){const n=t instanceof Uint16Array,s=t.length/(e*i);if(s<3)return Fm.warn("Light detection: unexpected channel count",s),{lights:[],wasAnalyzed:!1};const r=new Float32Array(8192),a=new Float32Array(8192),o=new Float32Array(8192),l=new Float32Array(8192),h=new Float32Array(8192);for(let c=0;c<i;c++){const d=Math.min(Math.floor(c/i*Py),63),u=(.5-c/i)*Math.PI,p=Math.cos(u);for(let i=0;i<e;i++){const u=Math.min(Math.floor(i/e*Ry),127),m=(c*e+i)*s;let f,g,v;n?(f=Iy(t[m]),g=Iy(t[m+1]),v=Iy(t[m+2])):(f=t[m],g=t[m+1],v=t[m+2]),f=Math.max(0,f),g=Math.max(0,g),v=Math.max(0,v);const y=.2126*f+.7152*g+.0722*v,_=d*Ry+u;r[_]+=y*p,a[_]+=f*p,o[_]+=g*p,l[_]+=v*p,h[_]+=p}}for(let t=0;t<r.length;t++)h[t]>0&&(r[t]/=h[t],a[t]/=h[t],o[t]/=h[t],l[t]/=h[t]);const c=Array.from(r).filter(t=>t>0).sort((t,e)=>t-e);if(0===c.length)return{lights:[],wasAnalyzed:!0};const d=10*c[Math.floor(c.length/2)],u=new Uint8Array(8192);for(let t=0;t<r.length;t++)u[t]=r[t]>=d?1:0;const p=new Uint8Array(8192),m=[];for(let t=0;t<Py;t++)for(let e=0;e<Ry;e++){const i=t*Ry+e;if(!u[i]||p[i])continue;const n={totalLum:0,totalR:0,totalG:0,totalB:0,weightedGx:0,weightedGy:0,count:0},s=[i];for(p[i]=1;s.length>0;){const t=s.pop(),e=Math.floor(t/Ry),i=t%Ry,h=r[t];n.totalLum+=h,n.totalR+=a[t]*h,n.totalG+=o[t]*h,n.totalB+=l[t]*h,n.weightedGx+=i*h,n.weightedGy+=e*h,n.count++;const c=[[i,e-1],[i,e+1],[(i-1+Ry)%Ry,e],[(i+1)%Ry,e]];for(const[t,e]of c){if(e<0||e>=Py)continue;const i=e*Ry+t;u[i]&&!p[i]&&(p[i]=1,s.push(i))}}n.count>0&&m.push(n)}if(0===m.length)return{lights:[],wasAnalyzed:!0};m.sort((t,e)=>e.totalLum-t.totalLum);const f=m.slice(0,1),g=f[0].totalLum,v=f.map(t=>{const e=t.weightedGx/t.totalLum,i=t.weightedGy/t.totalLum/Py,n=2*(e/Ry-.5)*Math.PI,s=(.5-i)*Math.PI,r=Math.cos(s),a=[Math.cos(n)*r,Math.sin(s),Math.sin(n)*r],o=t.totalR+t.totalG+t.totalB;let l;return o>0?(l=[t.totalR/o*3,t.totalG/o*3,t.totalB/o*3],l=[Math.min(1,l[0]),Math.min(1,l[1]),Math.min(1,l[2])]):l=[1,1,1],{direction:a,intensity:t.totalLum/g,color:l}});return Fm.debug(`Light detection: found ${v.length} dominant light(s) from ${m.length} cluster(s)`),{lights:v,wasAnalyzed:!0}}(r.image.data,r.image.width,r.image.height);this._lightDetectionCache.set(e,t)}return r.dispose(),this._cache.set(e,a),zm.trackTexture(a.texture,`PMREM environment: ${e}`),Fm.debug(`Loaded HDR environment from "${t}", cached as "${e}"`),a.texture}}class Wy{constructor(){this._shadowPlane=null,this._shadowsEnabled=!1,this.group=new _n,this.group.name="studioFloor",this.group.visible=!1}configure(t,e){this._clearCurrent(),this._createShadowPlane(t,e)}setShadowsEnabled(t){this._shadowsEnabled=t,this._shadowPlane&&(this._shadowPlane.visible=t),this.group.visible=this._shadowsEnabled}setShadowIntensity(t){this._shadowPlane&&(this._shadowPlane.material.opacity=1*t)}dispose(){this._clearCurrent()}_createShadowPlane(t,e){const i=6*e,n=new pl(i,i),s=new wl({opacity:.5,depthWrite:!1}),r=new xr(n,s);r.position.z=t,r.receiveShadow=!0,r.name="studioShadowPlane",r.visible=this._shadowsEnabled,this._shadowPlane=r,this.group.add(r)}_clearCurrent(){this._shadowPlane&&(this.group.remove(this._shadowPlane),this._shadowPlane.geometry.dispose(),this._shadowPlane.material.dispose(),this._shadowPlane=null)}}
|
|
13
13
|
/**
|
|
14
14
|
* postprocessing v6.38.3 build Thu Feb 19 2026
|
|
15
15
|
* https://github.com/pmndrs/postprocessing
|