@needle-tools/engine 4.12.0-beta.1 → 4.12.0-next.c6c0281
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components.needle.json +1 -1
- package/dist/{generateMeshBVH.worker-mO20N_b8.js → generateMeshBVH.worker-BvGEI0r7.js} +4 -4
- package/dist/{gltf-progressive-DZrY8VT6.min.js → gltf-progressive-BmSygnAC.min.js} +2 -2
- package/dist/{gltf-progressive-DgYz5BYa.js → gltf-progressive-DnLBuGK5.js} +24 -24
- package/dist/{gltf-progressive-DWcmTMCh.umd.cjs → gltf-progressive-Rs-ojtXy.umd.cjs} +1 -1
- package/dist/{loader.worker-Dip-PthR.js → loader.worker-DWzfDpAl.js} +4 -4
- package/dist/{needle-engine.bundle-BxG30KEV.js → needle-engine.bundle-BVdPECIB.js} +1106 -1167
- package/dist/{needle-engine.bundle-C08Ag6_H.umd.cjs → needle-engine.bundle-Dk2U2sIu.umd.cjs} +76 -77
- package/dist/{needle-engine.bundle-BeTUOBiO.min.js → needle-engine.bundle-ThW_g39D.min.js} +80 -81
- package/dist/needle-engine.d.ts +96 -40
- package/dist/needle-engine.js +4 -4
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/{postprocessing-DYDtB188.min.js → postprocessing-B5ksn9-G.min.js} +54 -54
- package/dist/{postprocessing-CMgoN5t5.umd.cjs → postprocessing-DZtb9Nnn.umd.cjs} +81 -81
- package/dist/{postprocessing-BTW9pD_s.js → postprocessing-__7s9wON.js} +450 -441
- package/dist/{three-DfMvBzXi.js → three-BCCkyCA5.js} +1 -7
- package/dist/{three-qj71I7J3.umd.cjs → three-Bf2NBxAw.umd.cjs} +2 -2
- package/dist/{three-B7CT31Bt.min.js → three-W7zWTcfP.min.js} +1 -1
- package/dist/{three-examples-CsW4_6LI.umd.cjs → three-examples-Dho7cuu4.umd.cjs} +4 -4
- package/dist/{three-examples-D1P7eEhn.min.js → three-examples-MsJjauyk.min.js} +10 -10
- package/dist/{three-examples-D1SK93ek.js → three-examples-y2GeYlze.js} +2 -20
- package/dist/{three-mesh-ui-C_uSB5dD.js → three-mesh-ui-3nSSizT4.js} +1 -1
- package/dist/{three-mesh-ui-LQ44s0AL.min.js → three-mesh-ui-CIez6qJQ.min.js} +1 -1
- package/dist/{three-mesh-ui-DpATDXwU.umd.cjs → three-mesh-ui-zsOOA5Pq.umd.cjs} +1 -1
- package/dist/vendor-BiJQtqow.min.js +1116 -0
- package/dist/{vendor-D0zoswDa.js → vendor-C_oHRUjX.js} +2686 -2663
- package/dist/{vendor-UCpFAwt1.umd.cjs → vendor-DN-NsXVB.umd.cjs} +30 -30
- package/lib/engine/codegen/register_types.js +0 -2
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/engine_license.js +3 -9
- package/lib/engine/engine_license.js.map +1 -1
- package/lib/engine/engine_physics_rapier.js +1 -1
- package/lib/engine/engine_physics_rapier.js.map +1 -1
- package/lib/engine/extensions/extensions.d.ts +29 -7
- package/lib/engine/extensions/extensions.js.map +1 -1
- package/lib/engine/webcomponents/needle menu/needle-menu.js +4 -5
- package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.js +1 -1
- package/lib/engine/webcomponents/needle-engine.js.map +1 -1
- package/lib/engine-components/AlignmentConstraint.d.ts +1 -1
- package/lib/engine-components/AlignmentConstraint.js +1 -1
- package/lib/engine-components/Animation.d.ts +1 -1
- package/lib/engine-components/Animation.js +1 -1
- package/lib/engine-components/Animator.d.ts +1 -1
- package/lib/engine-components/Animator.js +1 -1
- package/lib/engine-components/AudioListener.d.ts +1 -1
- package/lib/engine-components/AudioListener.js +1 -1
- package/lib/engine-components/AudioSource.d.ts +1 -1
- package/lib/engine-components/AudioSource.js +1 -1
- package/lib/engine-components/Camera.d.ts +1 -1
- package/lib/engine-components/Camera.js +1 -1
- package/lib/engine-components/CharacterController.d.ts +6 -2
- package/lib/engine-components/CharacterController.js +6 -2
- package/lib/engine-components/CharacterController.js.map +1 -1
- package/lib/engine-components/Collider.d.ts +1 -1
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Joints.d.ts +14 -0
- package/lib/engine-components/Joints.js +14 -0
- package/lib/engine-components/Joints.js.map +1 -1
- package/lib/engine-components/LookAtConstraint.d.ts +1 -1
- package/lib/engine-components/LookAtConstraint.js +1 -1
- package/lib/engine-components/OrbitControls.d.ts +1 -1
- package/lib/engine-components/OrbitControls.js +1 -1
- package/lib/engine-components/Renderer.d.ts +6 -0
- package/lib/engine-components/Renderer.js +6 -0
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/RendererInstancing.js +5 -3
- package/lib/engine-components/RendererInstancing.js.map +1 -1
- package/lib/engine-components/SceneSwitcher.js +18 -14
- package/lib/engine-components/SceneSwitcher.js.map +1 -1
- package/lib/engine-components/SpriteRenderer.d.ts +2 -1
- package/lib/engine-components/SpriteRenderer.js +2 -1
- package/lib/engine-components/SpriteRenderer.js.map +1 -1
- package/lib/engine-components/api.d.ts +1 -0
- package/lib/engine-components/api.js +1 -0
- package/lib/engine-components/api.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +0 -1
- package/lib/engine-components/codegen/components.js +0 -1
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/timeline/SignalAsset.d.ts +1 -1
- package/lib/engine-components/timeline/SignalAsset.js +1 -1
- package/lib/engine-components/ui/Raycaster.d.ts +3 -2
- package/lib/engine-components/ui/Raycaster.js +3 -2
- package/lib/engine-components/ui/Raycaster.js.map +1 -1
- package/lib/engine-components/ui/RectTransform.d.ts +6 -0
- package/lib/engine-components/ui/RectTransform.js +6 -0
- package/lib/engine-components/ui/RectTransform.js.map +1 -1
- package/lib/engine-components/utils/LookAt.d.ts +2 -1
- package/lib/engine-components/utils/LookAt.js +2 -1
- package/lib/engine-components/utils/LookAt.js.map +1 -1
- package/lib/engine-components/web/CursorFollow.d.ts +1 -1
- package/lib/engine-components/web/CursorFollow.js +1 -1
- package/lib/engine-components/web/HoverAnimation.d.ts +1 -1
- package/lib/engine-components/web/HoverAnimation.js +1 -1
- package/lib/engine-components/web/ViewBox.d.ts +1 -1
- package/lib/engine-components/web/ViewBox.js +1 -1
- package/package.json +2 -2
- package/src/engine/codegen/register_types.ts +0 -2
- package/src/engine/engine_license.ts +3 -8
- package/src/engine/engine_physics_rapier.ts +1 -1
- package/src/engine/extensions/extensions.ts +30 -6
- package/src/engine/webcomponents/needle menu/needle-menu.ts +4 -5
- package/src/engine/webcomponents/needle-engine.ts +2 -2
- package/src/engine-components/AlignmentConstraint.ts +1 -1
- package/src/engine-components/Animation.ts +1 -1
- package/src/engine-components/Animator.ts +1 -1
- package/src/engine-components/AudioListener.ts +1 -1
- package/src/engine-components/AudioSource.ts +1 -1
- package/src/engine-components/Camera.ts +1 -1
- package/src/engine-components/CharacterController.ts +6 -2
- package/src/engine-components/Collider.ts +1 -1
- package/src/engine-components/Joints.ts +14 -0
- package/src/engine-components/LookAtConstraint.ts +1 -1
- package/src/engine-components/OrbitControls.ts +1 -1
- package/src/engine-components/Renderer.ts +6 -0
- package/src/engine-components/RendererInstancing.ts +6 -3
- package/src/engine-components/SceneSwitcher.ts +17 -17
- package/src/engine-components/SpriteRenderer.ts +2 -1
- package/src/engine-components/api.ts +2 -1
- package/src/engine-components/codegen/components.ts +0 -1
- package/src/engine-components/timeline/SignalAsset.ts +1 -1
- package/src/engine-components/ui/Raycaster.ts +3 -2
- package/src/engine-components/ui/RectTransform.ts +6 -0
- package/src/engine-components/utils/LookAt.ts +2 -1
- package/src/engine-components/web/CursorFollow.ts +1 -1
- package/src/engine-components/web/HoverAnimation.ts +1 -1
- package/src/engine-components/web/ViewBox.ts +1 -1
- package/dist/vendor-BKGa4GE0.min.js +0 -1116
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){"use strict";const Wt="srgb",Es="srgb-linear",yo="display-p3",Pi="display-p3-linear",Nn="linear",vi="srgb",Li="rec709";class je{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const s=this._listeners;s[t]===void 0&&(s[t]=[]),s[t].indexOf(e)===-1&&s[t].push(e)}hasEventListener(t,e){if(this._listeners===void 0)return!1;const s=this._listeners;return s[t]!==void 0&&s[t].indexOf(e)!==-1}removeEventListener(t,e){if(this._listeners===void 0)return;const n=this._listeners[t];if(n!==void 0){const i=n.indexOf(e);i!==-1&&n.splice(i,1)}}dispatchEvent(t){if(this._listeners===void 0)return;const s=this._listeners[t.type];if(s!==void 0){t.target=this;const n=s.slice(0);for(let i=0,o=n.length;i<o;i++)n[i].call(this,t);t.target=null}}}const at=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let Oi=1234567;const Di=Math.PI/180,Vi=180/Math.PI;function ee(){const r=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,s=Math.random()*4294967295|0;return(at[r&255]+at[r>>8&255]+at[r>>16&255]+at[r>>24&255]+"-"+at[t&255]+at[t>>8&255]+"-"+at[t>>16&15|64]+at[t>>24&255]+"-"+at[e&63|128]+at[e>>8&255]+"-"+at[e>>16&255]+at[e>>24&255]+at[s&255]+at[s>>8&255]+at[s>>16&255]+at[s>>24&255]).toLowerCase()}function ct(r,t,e){return Math.max(t,Math.min(e,r))}function wn(r,t){return(r%t+t)%t}function go(r,t,e,s,n){return s+(r-t)*(n-s)/(e-t)}function xo(r,t,e){return r!==t?(e-r)/(t-r):0}function Ke(r,t,e){return(1-e)*r+e*t}function To(r,t,e,s){return Ke(r,t,1-Math.exp(-e*s))}function No(r,t=1){return t-Math.abs(wn(r,t*2)-t)}function wo(r,t,e){return r<=t?0:r>=e?1:(r=(r-t)/(e-t),r*r*(3-2*r))}function Ao(r,t,e){return r<=t?0:r>=e?1:(r=(r-t)/(e-t),r*r*r*(r*(r*6-15)+10))}function So(r,t){return r+Math.floor(Math.random()*(t-r+1))}function Mo(r,t){return r+Math.random()*(t-r)}function _o(r){return r*(.5-Math.random())}function zo(r){r!==void 0&&(Oi=r);let t=Oi+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function bo(r){return r*Di}function Eo(r){return r*Vi}function Co(r){return(r&r-1)===0&&r!==0}function Fo(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function Ro(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function Bo(r,t,e,s,n){const i=Math.cos,o=Math.sin,a=i(e/2),c=o(e/2),u=i((t+s)/2),h=o((t+s)/2),l=i((t-s)/2),d=o((t-s)/2),p=i((s-t)/2),f=o((s-t)/2);switch(n){case"XYX":r.set(a*h,c*l,c*d,a*u);break;case"YZY":r.set(c*d,a*h,c*l,a*u);break;case"ZXZ":r.set(c*l,c*d,a*h,a*u);break;case"XZX":r.set(a*h,c*f,c*p,a*u);break;case"YXY":r.set(c*p,a*h,c*f,a*u);break;case"ZYZ":r.set(c*f,c*p,a*h,a*u);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+n)}}function Rt(r,t){switch(t.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("Invalid component type.")}}function W(r,t){switch(t.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("Invalid component type.")}}const Io={DEG2RAD:Di,RAD2DEG:Vi,generateUUID:ee,clamp:ct,euclideanModulo:wn,mapLinear:go,inverseLerp:xo,lerp:Ke,damp:To,pingpong:No,smoothstep:wo,smootherstep:Ao,randInt:So,randFloat:Mo,randFloatSpread:_o,seededRandom:zo,degToRad:bo,radToDeg:Eo,isPowerOfTwo:Co,ceilPowerOfTwo:Fo,floorPowerOfTwo:Ro,setQuaternionFromProperEuler:Bo,normalize:W,denormalize:Rt};class Z{constructor(t=0,e=0){Z.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,s=this.y,n=t.elements;return this.x=n[0]*e+n[3]*s+n[6],this.y=n[1]*e+n[4]*s+n[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(ct(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y;return e*e+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const s=Math.cos(e),n=Math.sin(e),i=this.x-t.x,o=this.y-t.y;return this.x=i*s-o*n+t.x,this.y=i*n+o*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Bt{constructor(t,e,s,n,i,o,a,c,u){Bt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,s,n,i,o,a,c,u)}set(t,e,s,n,i,o,a,c,u){const h=this.elements;return h[0]=t,h[1]=n,h[2]=a,h[3]=e,h[4]=i,h[5]=c,h[6]=s,h[7]=o,h[8]=u,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],this}extractBasis(t,e,s){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),s.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,n=e.elements,i=this.elements,o=s[0],a=s[3],c=s[6],u=s[1],h=s[4],l=s[7],d=s[2],p=s[5],f=s[8],y=n[0],N=n[3],A=n[6],x=n[1],w=n[4],g=n[7],m=n[2],M=n[5],S=n[8];return i[0]=o*y+a*x+c*m,i[3]=o*N+a*w+c*M,i[6]=o*A+a*g+c*S,i[1]=u*y+h*x+l*m,i[4]=u*N+h*w+l*M,i[7]=u*A+h*g+l*S,i[2]=d*y+p*x+f*m,i[5]=d*N+p*w+f*M,i[8]=d*A+p*g+f*S,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[1],n=t[2],i=t[3],o=t[4],a=t[5],c=t[6],u=t[7],h=t[8];return e*o*h-e*a*u-s*i*h+s*a*c+n*i*u-n*o*c}invert(){const t=this.elements,e=t[0],s=t[1],n=t[2],i=t[3],o=t[4],a=t[5],c=t[6],u=t[7],h=t[8],l=h*o-a*u,d=a*c-h*i,p=u*i-o*c,f=e*l+s*d+n*p;if(f===0)return this.set(0,0,0,0,0,0,0,0,0);const y=1/f;return t[0]=l*y,t[1]=(n*u-h*s)*y,t[2]=(a*s-n*o)*y,t[3]=d*y,t[4]=(h*e-n*c)*y,t[5]=(n*i-a*e)*y,t[6]=p*y,t[7]=(s*c-u*e)*y,t[8]=(o*e-s*i)*y,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,s,n,i,o,a){const c=Math.cos(i),u=Math.sin(i);return this.set(s*c,s*u,-s*(c*o+u*a)+o+t,-n*u,n*c,-n*(-u*o+c*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(An.makeScale(t,e)),this}rotate(t){return this.premultiply(An.makeRotation(-t)),this}translate(t,e){return this.premultiply(An.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,s,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,s=t.elements;for(let n=0;n<9;n++)if(e[n]!==s[n])return!1;return!0}fromArray(t,e=0){for(let s=0;s<9;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const An=new Bt;function Po(r){for(let t=r.length-1;t>=0;--t)if(r[t]>=65535)return!0;return!1}function Ui(r){return document.createElementNS("http://www.w3.org/1999/xhtml",r)}const ki=new Bt().set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),Hi=new Bt().set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),ts={[Es]:{transfer:Nn,primaries:Li,luminanceCoefficients:[.2126,.7152,.0722],toReference:r=>r,fromReference:r=>r},[Wt]:{transfer:vi,primaries:Li,luminanceCoefficients:[.2126,.7152,.0722],toReference:r=>r.convertSRGBToLinear(),fromReference:r=>r.convertLinearToSRGB()},[Pi]:{transfer:Nn,primaries:"p3",luminanceCoefficients:[.2289,.6917,.0793],toReference:r=>r.applyMatrix3(Hi),fromReference:r=>r.applyMatrix3(ki)},[yo]:{transfer:vi,primaries:"p3",luminanceCoefficients:[.2289,.6917,.0793],toReference:r=>r.convertSRGBToLinear().applyMatrix3(Hi),fromReference:r=>r.applyMatrix3(ki).convertLinearToSRGB()}},vo=new Set([Es,Pi]),yt={enabled:!0,_workingColorSpace:Es,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(r){if(!vo.has(r))throw new Error(`Unsupported working color space, "${r}".`);this._workingColorSpace=r},convert:function(r,t,e){if(this.enabled===!1||t===e||!t||!e)return r;const s=ts[t].toReference,n=ts[e].fromReference;return n(s(r))},fromWorkingColorSpace:function(r,t){return this.convert(r,this._workingColorSpace,t)},toWorkingColorSpace:function(r,t){return this.convert(r,t,this._workingColorSpace)},getPrimaries:function(r){return ts[r].primaries},getTransfer:function(r){return r===""?Nn:ts[r].transfer},getLuminanceCoefficients:function(r,t=this._workingColorSpace){return r.fromArray(ts[t].luminanceCoefficients)}};function Ae(r){return r<.04045?r*.0773993808:Math.pow(r*.9478672986+.0521327014,2.4)}function Sn(r){return r<.0031308?r*12.92:1.055*Math.pow(r,.41666)-.055}let Se;class Lo{static getDataURL(t){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{Se===void 0&&(Se=Ui("canvas")),Se.width=t.width,Se.height=t.height;const s=Se.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),e=Se}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=Ui("canvas");e.width=t.width,e.height=t.height;const s=e.getContext("2d");s.drawImage(t,0,0,t.width,t.height);const n=s.getImageData(0,0,t.width,t.height),i=n.data;for(let o=0;o<i.length;o++)i[o]=Ae(i[o]/255)*255;return s.putImageData(n,0,0),e}else if(t.data){const e=t.data.slice(0);for(let s=0;s<e.length;s++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[s]=Math.floor(Ae(e[s]/255)*255):e[s]=Ae(e[s]);return{data:e,width:t.width,height:t.height}}else return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let Oo=0;class qi{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Oo++}),this.uuid=ee(),this.data=t,this.dataReady=!0,this.version=0}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const s={uuid:this.uuid,url:""},n=this.data;if(n!==null){let i;if(Array.isArray(n)){i=[];for(let o=0,a=n.length;o<a;o++)n[o].isDataTexture?i.push(Mn(n[o].image)):i.push(Mn(n[o]))}else i=Mn(n);s.url=i}return e||(t.images[this.uuid]=s),s}}function Mn(r){return typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&r instanceof ImageBitmap?Lo.getDataURL(r):r.data?{data:Array.from(r.data),width:r.width,height:r.height,type:r.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}let Do=0;class kt extends je{constructor(t=kt.DEFAULT_IMAGE,e=kt.DEFAULT_MAPPING,s=1001,n=1001,i=1006,o=1008,a=1023,c=1009,u=kt.DEFAULT_ANISOTROPY,h=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Do++}),this.uuid=ee(),this.name="",this.source=new qi(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=s,this.wrapT=n,this.magFilter=i,this.minFilter=o,this.anisotropy=u,this.format=a,this.internalFormat=null,this.type=c,this.offset=new Z(0,0),this.repeat=new Z(1,1),this.center=new Z(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Bt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1,this.pmremVersion=0}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const s={metadata:{version:4.6,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(s.userData=this.userData),e||(t.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==300)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case 1e3:t.x=t.x-Math.floor(t.x);break;case 1001:t.x=t.x<0?0:1;break;case 1002:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case 1e3:t.y=t.y-Math.floor(t.y);break;case 1001:t.y=t.y<0?0:1;break;case 1002:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}kt.DEFAULT_IMAGE=null,kt.DEFAULT_MAPPING=300,kt.DEFAULT_ANISOTROPY=4;class It{constructor(t=0,e=0,s=0,n=1){It.prototype.isVector4=!0,this.x=t,this.y=e,this.z=s,this.w=n}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,s,n){return this.x=t,this.y=e,this.z=s,this.w=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,s=this.y,n=this.z,i=this.w,o=t.elements;return this.x=o[0]*e+o[4]*s+o[8]*n+o[12]*i,this.y=o[1]*e+o[5]*s+o[9]*n+o[13]*i,this.z=o[2]*e+o[6]*s+o[10]*n+o[14]*i,this.w=o[3]*e+o[7]*s+o[11]*n+o[15]*i,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,s,n,i;const c=t.elements,u=c[0],h=c[4],l=c[8],d=c[1],p=c[5],f=c[9],y=c[2],N=c[6],A=c[10];if(Math.abs(h-d)<.01&&Math.abs(l-y)<.01&&Math.abs(f-N)<.01){if(Math.abs(h+d)<.1&&Math.abs(l+y)<.1&&Math.abs(f+N)<.1&&Math.abs(u+p+A-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const w=(u+1)/2,g=(p+1)/2,m=(A+1)/2,M=(h+d)/4,S=(l+y)/4,z=(f+N)/4;return w>g&&w>m?w<.01?(s=0,n=.707106781,i=.707106781):(s=Math.sqrt(w),n=M/s,i=S/s):g>m?g<.01?(s=.707106781,n=0,i=.707106781):(n=Math.sqrt(g),s=M/n,i=z/n):m<.01?(s=.707106781,n=.707106781,i=0):(i=Math.sqrt(m),s=S/i,n=z/i),this.set(s,n,i,e),this}let x=Math.sqrt((N-f)*(N-f)+(l-y)*(l-y)+(d-h)*(d-h));return Math.abs(x)<.001&&(x=1),this.x=(N-f)/x,this.y=(l-y)/x,this.z=(d-h)/x,this.w=Math.acos((u+p+A-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this.w=t.w+(e.w-t.w)*s,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class $i extends je{constructor(t=1,e=1,s={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new It(0,0,t,e),this.scissorTest=!1,this.viewport=new It(0,0,t,e);const n={width:t,height:e,depth:1};s=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:1006,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},s);const i=new kt(n,s.mapping,s.wrapS,s.wrapT,s.magFilter,s.minFilter,s.format,s.type,s.anisotropy,s.colorSpace);i.flipY=!1,i.generateMipmaps=s.generateMipmaps,i.internalFormat=s.internalFormat,this.textures=[];const o=s.count;for(let a=0;a<o;a++)this.textures[a]=i.clone(),this.textures[a].isRenderTargetTexture=!0;this.depthBuffer=s.depthBuffer,this.stencilBuffer=s.stencilBuffer,this.resolveDepthBuffer=s.resolveDepthBuffer,this.resolveStencilBuffer=s.resolveStencilBuffer,this.depthTexture=s.depthTexture,this.samples=s.samples}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}setSize(t,e,s=1){if(this.width!==t||this.height!==e||this.depth!==s){this.width=t,this.height=e,this.depth=s;for(let n=0,i=this.textures.length;n<i;n++)this.textures[n].image.width=t,this.textures[n].image.height=e,this.textures[n].image.depth=s;this.dispose()}this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return new this.constructor().copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.textures.length=0;for(let s=0,n=t.textures.length;s<n;s++)this.textures[s]=t.textures[s].clone(),this.textures[s].isRenderTargetTexture=!0;const e=Object.assign({},t.texture.image);return this.texture.source=new qi(e),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.resolveDepthBuffer=t.resolveDepthBuffer,this.resolveStencilBuffer=t.resolveStencilBuffer,t.depthTexture!==null&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class es{constructor(t=0,e=0,s=0,n=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=s,this._w=n}static slerpFlat(t,e,s,n,i,o,a){let c=s[n+0],u=s[n+1],h=s[n+2],l=s[n+3];const d=i[o+0],p=i[o+1],f=i[o+2],y=i[o+3];if(a===0){t[e+0]=c,t[e+1]=u,t[e+2]=h,t[e+3]=l;return}if(a===1){t[e+0]=d,t[e+1]=p,t[e+2]=f,t[e+3]=y;return}if(l!==y||c!==d||u!==p||h!==f){let N=1-a;const A=c*d+u*p+h*f+l*y,x=A>=0?1:-1,w=1-A*A;if(w>Number.EPSILON){const m=Math.sqrt(w),M=Math.atan2(m,A*x);N=Math.sin(N*M)/m,a=Math.sin(a*M)/m}const g=a*x;if(c=c*N+d*g,u=u*N+p*g,h=h*N+f*g,l=l*N+y*g,N===1-a){const m=1/Math.sqrt(c*c+u*u+h*h+l*l);c*=m,u*=m,h*=m,l*=m}}t[e]=c,t[e+1]=u,t[e+2]=h,t[e+3]=l}static multiplyQuaternionsFlat(t,e,s,n,i,o){const a=s[n],c=s[n+1],u=s[n+2],h=s[n+3],l=i[o],d=i[o+1],p=i[o+2],f=i[o+3];return t[e]=a*f+h*l+c*p-u*d,t[e+1]=c*f+h*d+u*l-a*p,t[e+2]=u*f+h*p+a*d-c*l,t[e+3]=h*f-a*l-c*d-u*p,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,s,n){return this._x=t,this._y=e,this._z=s,this._w=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const s=t._x,n=t._y,i=t._z,o=t._order,a=Math.cos,c=Math.sin,u=a(s/2),h=a(n/2),l=a(i/2),d=c(s/2),p=c(n/2),f=c(i/2);switch(o){case"XYZ":this._x=d*h*l+u*p*f,this._y=u*p*l-d*h*f,this._z=u*h*f+d*p*l,this._w=u*h*l-d*p*f;break;case"YXZ":this._x=d*h*l+u*p*f,this._y=u*p*l-d*h*f,this._z=u*h*f-d*p*l,this._w=u*h*l+d*p*f;break;case"ZXY":this._x=d*h*l-u*p*f,this._y=u*p*l+d*h*f,this._z=u*h*f+d*p*l,this._w=u*h*l-d*p*f;break;case"ZYX":this._x=d*h*l-u*p*f,this._y=u*p*l+d*h*f,this._z=u*h*f-d*p*l,this._w=u*h*l+d*p*f;break;case"YZX":this._x=d*h*l+u*p*f,this._y=u*p*l+d*h*f,this._z=u*h*f-d*p*l,this._w=u*h*l-d*p*f;break;case"XZY":this._x=d*h*l-u*p*f,this._y=u*p*l-d*h*f,this._z=u*h*f+d*p*l,this._w=u*h*l+d*p*f;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+o)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,n=Math.sin(s);return this._x=t.x*n,this._y=t.y*n,this._z=t.z*n,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],n=e[4],i=e[8],o=e[1],a=e[5],c=e[9],u=e[2],h=e[6],l=e[10],d=s+a+l;if(d>0){const p=.5/Math.sqrt(d+1);this._w=.25/p,this._x=(h-c)*p,this._y=(i-u)*p,this._z=(o-n)*p}else if(s>a&&s>l){const p=2*Math.sqrt(1+s-a-l);this._w=(h-c)/p,this._x=.25*p,this._y=(n+o)/p,this._z=(i+u)/p}else if(a>l){const p=2*Math.sqrt(1+a-s-l);this._w=(i-u)/p,this._x=(n+o)/p,this._y=.25*p,this._z=(c+h)/p}else{const p=2*Math.sqrt(1+l-s-a);this._w=(o-n)/p,this._x=(i+u)/p,this._y=(c+h)/p,this._z=.25*p}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return s<Number.EPSILON?(s=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(ct(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(s===0)return this;const n=Math.min(1,e/s);return this.slerp(t,n),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const s=t._x,n=t._y,i=t._z,o=t._w,a=e._x,c=e._y,u=e._z,h=e._w;return this._x=s*h+o*a+n*u-i*c,this._y=n*h+o*c+i*a-s*u,this._z=i*h+o*u+s*c-n*a,this._w=o*h-s*a-n*c-i*u,this._onChangeCallback(),this}slerp(t,e){if(e===0)return this;if(e===1)return this.copy(t);const s=this._x,n=this._y,i=this._z,o=this._w;let a=o*t._w+s*t._x+n*t._y+i*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=o,this._x=s,this._y=n,this._z=i,this;const c=1-a*a;if(c<=Number.EPSILON){const p=1-e;return this._w=p*o+e*this._w,this._x=p*s+e*this._x,this._y=p*n+e*this._y,this._z=p*i+e*this._z,this.normalize(),this}const u=Math.sqrt(c),h=Math.atan2(u,a),l=Math.sin((1-e)*h)/u,d=Math.sin(e*h)/u;return this._w=o*l+this._w*d,this._x=s*l+this._x*d,this._y=n*l+this._y*d,this._z=i*l+this._z*d,this._onChangeCallback(),this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),n=Math.sqrt(1-s),i=Math.sqrt(s);return this.set(n*Math.sin(t),n*Math.cos(t),i*Math.sin(e),i*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class _{constructor(t=0,e=0,s=0){_.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return s===void 0&&(s=this.z),this.x=t,this.y=e,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(Wi.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Wi.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,n=this.z,i=t.elements;return this.x=i[0]*e+i[3]*s+i[6]*n,this.y=i[1]*e+i[4]*s+i[7]*n,this.z=i[2]*e+i[5]*s+i[8]*n,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,n=this.z,i=t.elements,o=1/(i[3]*e+i[7]*s+i[11]*n+i[15]);return this.x=(i[0]*e+i[4]*s+i[8]*n+i[12])*o,this.y=(i[1]*e+i[5]*s+i[9]*n+i[13])*o,this.z=(i[2]*e+i[6]*s+i[10]*n+i[14])*o,this}applyQuaternion(t){const e=this.x,s=this.y,n=this.z,i=t.x,o=t.y,a=t.z,c=t.w,u=2*(o*n-a*s),h=2*(a*e-i*n),l=2*(i*s-o*e);return this.x=e+c*u+o*l-a*h,this.y=s+c*h+a*u-i*l,this.z=n+c*l+i*h-o*u,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,n=this.z,i=t.elements;return this.x=i[0]*e+i[4]*s+i[8]*n,this.y=i[1]*e+i[5]*s+i[9]*n,this.z=i[2]*e+i[6]*s+i[10]*n,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,n=t.y,i=t.z,o=e.x,a=e.y,c=e.z;return this.x=n*c-i*a,this.y=i*o-s*c,this.z=s*a-n*o,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return _n.copy(this).projectOnVector(t),this.sub(_n)}reflect(t){return this.sub(_n.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(ct(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,n=this.z-t.z;return e*e+s*s+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,s){const n=Math.sin(e)*t;return this.x=n*Math.sin(s),this.y=Math.cos(e)*t,this.z=n*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),n=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=n,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const _n=new _,Wi=new es;class ut{constructor(t=new _(1/0,1/0,1/0),e=new _(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,s=t.length;e<s;e+=3)this.expandByPoint(Pt.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,s=t.count;e<s;e++)this.expandByPoint(Pt.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,s=t.length;e<s;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const s=Pt.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(s),this.max.copy(t).add(s),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}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=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,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}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const s=t.geometry;if(s!==void 0){const i=s.getAttribute("position");if(e===!0&&i!==void 0&&t.isInstancedMesh!==!0)for(let o=0,a=i.count;o<a;o++)t.isMesh===!0?t.getVertexPosition(o,Pt):Pt.fromBufferAttribute(i,o),Pt.applyMatrix4(t.matrixWorld),this.expandByPoint(Pt);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Cs.copy(t.boundingBox)):(s.boundingBox===null&&s.computeBoundingBox(),Cs.copy(s.boundingBox)),Cs.applyMatrix4(t.matrixWorld),this.union(Cs)}const n=t.children;for(let i=0,o=n.length;i<o;i++)this.expandByObject(n[i],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}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&&this.min.z<=t.min.z&&t.max.z<=this.max.z}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),(t.z-this.min.z)/(this.max.z-this.min.z))}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&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,Pt),Pt.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,s;return t.normal.x>0?(e=t.normal.x*this.min.x,s=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,s=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,s+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,s+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,s+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,s+=t.normal.z*this.min.z),e<=-t.constant&&s>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(ss),Fs.subVectors(this.max,ss),Me.subVectors(t.a,ss),_e.subVectors(t.b,ss),ze.subVectors(t.c,ss),se.subVectors(_e,Me),ne.subVectors(ze,_e),fe.subVectors(Me,ze);let e=[0,-se.z,se.y,0,-ne.z,ne.y,0,-fe.z,fe.y,se.z,0,-se.x,ne.z,0,-ne.x,fe.z,0,-fe.x,-se.y,se.x,0,-ne.y,ne.x,0,-fe.y,fe.x,0];return!zn(e,Me,_e,ze,Fs)||(e=[1,0,0,0,1,0,0,0,1],!zn(e,Me,_e,ze,Fs))?!1:(Rs.crossVectors(se,ne),e=[Rs.x,Rs.y,Rs.z],zn(e,Me,_e,ze,Fs))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Pt).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(Pt).length()*.5),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}applyMatrix4(t){return this.isEmpty()?this:(Gt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Gt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Gt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Gt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Gt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Gt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Gt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Gt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Gt),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)}}const Gt=[new _,new _,new _,new _,new _,new _,new _,new _],Pt=new _,Cs=new ut,Me=new _,_e=new _,ze=new _,se=new _,ne=new _,fe=new _,ss=new _,Fs=new _,Rs=new _,me=new _;function zn(r,t,e,s,n){for(let i=0,o=r.length-3;i<=o;i+=3){me.fromArray(r,i);const a=n.x*Math.abs(me.x)+n.y*Math.abs(me.y)+n.z*Math.abs(me.z),c=t.dot(me),u=e.dot(me),h=s.dot(me);if(Math.max(-Math.max(c,u,h),Math.min(c,u,h))>a)return!1}return!0}const Vo=new ut,ns=new _,bn=new _;class Uo{constructor(t=new _,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const s=this.center;e!==void 0?s.copy(e):Vo.setFromPoints(t).getCenter(s);let n=0;for(let i=0,o=t.length;i<o;i++)n=Math.max(n,s.distanceToSquared(t[i]));return this.radius=Math.sqrt(n),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const s=this.center.distanceToSquared(t);return e.copy(t),s>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;ns.subVectors(t,this.center);const e=ns.lengthSq();if(e>this.radius*this.radius){const s=Math.sqrt(e),n=(s-this.radius)*.5;this.center.addScaledVector(ns,n/s),this.radius+=n}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(bn.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(ns.copy(t.center).add(bn)),this.expandByPoint(ns.copy(t.center).sub(bn))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}}class nt{constructor(t,e,s,n,i,o,a,c,u,h,l,d,p,f,y,N){nt.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,s,n,i,o,a,c,u,h,l,d,p,f,y,N)}set(t,e,s,n,i,o,a,c,u,h,l,d,p,f,y,N){const A=this.elements;return A[0]=t,A[4]=e,A[8]=s,A[12]=n,A[1]=i,A[5]=o,A[9]=a,A[13]=c,A[2]=u,A[6]=h,A[10]=l,A[14]=d,A[3]=p,A[7]=f,A[11]=y,A[15]=N,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new nt().fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,s){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,s=t.elements,n=1/be.setFromMatrixColumn(t,0).length(),i=1/be.setFromMatrixColumn(t,1).length(),o=1/be.setFromMatrixColumn(t,2).length();return e[0]=s[0]*n,e[1]=s[1]*n,e[2]=s[2]*n,e[3]=0,e[4]=s[4]*i,e[5]=s[5]*i,e[6]=s[6]*i,e[7]=0,e[8]=s[8]*o,e[9]=s[9]*o,e[10]=s[10]*o,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,n=t.y,i=t.z,o=Math.cos(s),a=Math.sin(s),c=Math.cos(n),u=Math.sin(n),h=Math.cos(i),l=Math.sin(i);if(t.order==="XYZ"){const d=o*h,p=o*l,f=a*h,y=a*l;e[0]=c*h,e[4]=-c*l,e[8]=u,e[1]=p+f*u,e[5]=d-y*u,e[9]=-a*c,e[2]=y-d*u,e[6]=f+p*u,e[10]=o*c}else if(t.order==="YXZ"){const d=c*h,p=c*l,f=u*h,y=u*l;e[0]=d+y*a,e[4]=f*a-p,e[8]=o*u,e[1]=o*l,e[5]=o*h,e[9]=-a,e[2]=p*a-f,e[6]=y+d*a,e[10]=o*c}else if(t.order==="ZXY"){const d=c*h,p=c*l,f=u*h,y=u*l;e[0]=d-y*a,e[4]=-o*l,e[8]=f+p*a,e[1]=p+f*a,e[5]=o*h,e[9]=y-d*a,e[2]=-o*u,e[6]=a,e[10]=o*c}else if(t.order==="ZYX"){const d=o*h,p=o*l,f=a*h,y=a*l;e[0]=c*h,e[4]=f*u-p,e[8]=d*u+y,e[1]=c*l,e[5]=y*u+d,e[9]=p*u-f,e[2]=-u,e[6]=a*c,e[10]=o*c}else if(t.order==="YZX"){const d=o*c,p=o*u,f=a*c,y=a*u;e[0]=c*h,e[4]=y-d*l,e[8]=f*l+p,e[1]=l,e[5]=o*h,e[9]=-a*h,e[2]=-u*h,e[6]=p*l+f,e[10]=d-y*l}else if(t.order==="XZY"){const d=o*c,p=o*u,f=a*c,y=a*u;e[0]=c*h,e[4]=-l,e[8]=u*h,e[1]=d*l+y,e[5]=o*h,e[9]=p*l-f,e[2]=f*l-p,e[6]=a*h,e[10]=y*l+d}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(ko,t,Ho)}lookAt(t,e,s){const n=this.elements;return gt.subVectors(t,e),gt.lengthSq()===0&&(gt.z=1),gt.normalize(),ie.crossVectors(s,gt),ie.lengthSq()===0&&(Math.abs(s.z)===1?gt.x+=1e-4:gt.z+=1e-4,gt.normalize(),ie.crossVectors(s,gt)),ie.normalize(),Bs.crossVectors(gt,ie),n[0]=ie.x,n[4]=Bs.x,n[8]=gt.x,n[1]=ie.y,n[5]=Bs.y,n[9]=gt.y,n[2]=ie.z,n[6]=Bs.z,n[10]=gt.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,n=e.elements,i=this.elements,o=s[0],a=s[4],c=s[8],u=s[12],h=s[1],l=s[5],d=s[9],p=s[13],f=s[2],y=s[6],N=s[10],A=s[14],x=s[3],w=s[7],g=s[11],m=s[15],M=n[0],S=n[4],z=n[8],R=n[12],F=n[1],P=n[5],C=n[9],I=n[13],L=n[2],D=n[6],k=n[10],ot=n[14],wt=n[3],At=n[7],de=n[11],pe=n[15];return i[0]=o*M+a*F+c*L+u*wt,i[4]=o*S+a*P+c*D+u*At,i[8]=o*z+a*C+c*k+u*de,i[12]=o*R+a*I+c*ot+u*pe,i[1]=h*M+l*F+d*L+p*wt,i[5]=h*S+l*P+d*D+p*At,i[9]=h*z+l*C+d*k+p*de,i[13]=h*R+l*I+d*ot+p*pe,i[2]=f*M+y*F+N*L+A*wt,i[6]=f*S+y*P+N*D+A*At,i[10]=f*z+y*C+N*k+A*de,i[14]=f*R+y*I+N*ot+A*pe,i[3]=x*M+w*F+g*L+m*wt,i[7]=x*S+w*P+g*D+m*At,i[11]=x*z+w*C+g*k+m*de,i[15]=x*R+w*I+g*ot+m*pe,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[4],n=t[8],i=t[12],o=t[1],a=t[5],c=t[9],u=t[13],h=t[2],l=t[6],d=t[10],p=t[14],f=t[3],y=t[7],N=t[11],A=t[15];return f*(+i*c*l-n*u*l-i*a*d+s*u*d+n*a*p-s*c*p)+y*(+e*c*p-e*u*d+i*o*d-n*o*p+n*u*h-i*c*h)+N*(+e*u*l-e*a*p-i*o*l+s*o*p+i*a*h-s*u*h)+A*(-n*a*h-e*c*l+e*a*d+n*o*l-s*o*d+s*c*h)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,s){const n=this.elements;return t.isVector3?(n[12]=t.x,n[13]=t.y,n[14]=t.z):(n[12]=t,n[13]=e,n[14]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],n=t[2],i=t[3],o=t[4],a=t[5],c=t[6],u=t[7],h=t[8],l=t[9],d=t[10],p=t[11],f=t[12],y=t[13],N=t[14],A=t[15],x=l*N*u-y*d*u+y*c*p-a*N*p-l*c*A+a*d*A,w=f*d*u-h*N*u-f*c*p+o*N*p+h*c*A-o*d*A,g=h*y*u-f*l*u+f*a*p-o*y*p-h*a*A+o*l*A,m=f*l*c-h*y*c-f*a*d+o*y*d+h*a*N-o*l*N,M=e*x+s*w+n*g+i*m;if(M===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const S=1/M;return t[0]=x*S,t[1]=(y*d*i-l*N*i-y*n*p+s*N*p+l*n*A-s*d*A)*S,t[2]=(a*N*i-y*c*i+y*n*u-s*N*u-a*n*A+s*c*A)*S,t[3]=(l*c*i-a*d*i-l*n*u+s*d*u+a*n*p-s*c*p)*S,t[4]=w*S,t[5]=(h*N*i-f*d*i+f*n*p-e*N*p-h*n*A+e*d*A)*S,t[6]=(f*c*i-o*N*i-f*n*u+e*N*u+o*n*A-e*c*A)*S,t[7]=(o*d*i-h*c*i+h*n*u-e*d*u-o*n*p+e*c*p)*S,t[8]=g*S,t[9]=(f*l*i-h*y*i-f*s*p+e*y*p+h*s*A-e*l*A)*S,t[10]=(o*y*i-f*a*i+f*s*u-e*y*u-o*s*A+e*a*A)*S,t[11]=(h*a*i-o*l*i-h*s*u+e*l*u+o*s*p-e*a*p)*S,t[12]=m*S,t[13]=(h*y*n-f*l*n+f*s*d-e*y*d-h*s*N+e*l*N)*S,t[14]=(f*a*n-o*y*n-f*s*c+e*y*c+o*s*N-e*a*N)*S,t[15]=(o*l*n-h*a*n+h*s*c-e*l*c-o*s*d+e*a*d)*S,this}scale(t){const e=this.elements,s=t.x,n=t.y,i=t.z;return e[0]*=s,e[4]*=n,e[8]*=i,e[1]*=s,e[5]*=n,e[9]*=i,e[2]*=s,e[6]*=n,e[10]*=i,e[3]*=s,e[7]*=n,e[11]*=i,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],n=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,s,n))}makeTranslation(t,e,s){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),n=Math.sin(e),i=1-s,o=t.x,a=t.y,c=t.z,u=i*o,h=i*a;return this.set(u*o+s,u*a-n*c,u*c+n*a,0,u*a+n*c,h*a+s,h*c-n*o,0,u*c-n*a,h*c+n*o,i*c*c+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,n,i,o){return this.set(1,s,i,0,t,1,o,0,e,n,1,0,0,0,0,1),this}compose(t,e,s){const n=this.elements,i=e._x,o=e._y,a=e._z,c=e._w,u=i+i,h=o+o,l=a+a,d=i*u,p=i*h,f=i*l,y=o*h,N=o*l,A=a*l,x=c*u,w=c*h,g=c*l,m=s.x,M=s.y,S=s.z;return n[0]=(1-(y+A))*m,n[1]=(p+g)*m,n[2]=(f-w)*m,n[3]=0,n[4]=(p-g)*M,n[5]=(1-(d+A))*M,n[6]=(N+x)*M,n[7]=0,n[8]=(f+w)*S,n[9]=(N-x)*S,n[10]=(1-(d+y))*S,n[11]=0,n[12]=t.x,n[13]=t.y,n[14]=t.z,n[15]=1,this}decompose(t,e,s){const n=this.elements;let i=be.set(n[0],n[1],n[2]).length();const o=be.set(n[4],n[5],n[6]).length(),a=be.set(n[8],n[9],n[10]).length();this.determinant()<0&&(i=-i),t.x=n[12],t.y=n[13],t.z=n[14],vt.copy(this);const u=1/i,h=1/o,l=1/a;return vt.elements[0]*=u,vt.elements[1]*=u,vt.elements[2]*=u,vt.elements[4]*=h,vt.elements[5]*=h,vt.elements[6]*=h,vt.elements[8]*=l,vt.elements[9]*=l,vt.elements[10]*=l,e.setFromRotationMatrix(vt),s.x=i,s.y=o,s.z=a,this}makePerspective(t,e,s,n,i,o,a=2e3){const c=this.elements,u=2*i/(e-t),h=2*i/(s-n),l=(e+t)/(e-t),d=(s+n)/(s-n);let p,f;if(a===2e3)p=-(o+i)/(o-i),f=-2*o*i/(o-i);else if(a===2001)p=-o/(o-i),f=-o*i/(o-i);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=u,c[4]=0,c[8]=l,c[12]=0,c[1]=0,c[5]=h,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=p,c[14]=f,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(t,e,s,n,i,o,a=2e3){const c=this.elements,u=1/(e-t),h=1/(s-n),l=1/(o-i),d=(e+t)*u,p=(s+n)*h;let f,y;if(a===2e3)f=(o+i)*l,y=-2*l;else if(a===2001)f=i*l,y=-1*l;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=2*u,c[4]=0,c[8]=0,c[12]=-d,c[1]=0,c[5]=2*h,c[9]=0,c[13]=-p,c[2]=0,c[6]=0,c[10]=y,c[14]=-f,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let n=0;n<16;n++)if(e[n]!==s[n])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const be=new _,vt=new nt,ko=new _(0,0,0),Ho=new _(1,1,1),ie=new _,Bs=new _,gt=new _,Gi=new nt,Xi=new es;class Is{constructor(t=0,e=0,s=0,n=Is.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,this._order=n}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,s,n=this._order){return this._x=t,this._y=e,this._z=s,this._order=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,s=!0){const n=t.elements,i=n[0],o=n[4],a=n[8],c=n[1],u=n[5],h=n[9],l=n[2],d=n[6],p=n[10];switch(e){case"XYZ":this._y=Math.asin(ct(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,p),this._z=Math.atan2(-o,i)):(this._x=Math.atan2(d,u),this._z=0);break;case"YXZ":this._x=Math.asin(-ct(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,p),this._z=Math.atan2(c,u)):(this._y=Math.atan2(-l,i),this._z=0);break;case"ZXY":this._x=Math.asin(ct(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-l,p),this._z=Math.atan2(-o,u)):(this._y=0,this._z=Math.atan2(c,i));break;case"ZYX":this._y=Math.asin(-ct(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(d,p),this._z=Math.atan2(c,i)):(this._x=0,this._z=Math.atan2(-o,u));break;case"YZX":this._z=Math.asin(ct(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-h,u),this._y=Math.atan2(-l,i)):(this._x=0,this._y=Math.atan2(a,p));break;case"XZY":this._z=Math.asin(-ct(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(d,u),this._y=Math.atan2(a,i)):(this._x=Math.atan2(-h,p),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,s===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return Gi.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Gi,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Xi.setFromEuler(this),this.setFromQuaternion(Xi,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Is.DEFAULT_ORDER="XYZ";class qo{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let $o=0;const Yi=new _,Ee=new es,Xt=new nt,Ps=new _,is=new _,Wo=new _,Go=new es,Zi=new _(1,0,0),Ji=new _(0,1,0),Qi=new _(0,0,1),ji={type:"added"},Xo={type:"removed"},Ce={type:"childadded",child:null},En={type:"childremoved",child:null};class re extends je{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:$o++}),this.uuid=ee(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=re.DEFAULT_UP.clone();const t=new _,e=new Is,s=new es,n=new _(1,1,1);function i(){s.setFromEuler(e,!1)}function o(){e.setFromQuaternion(s,void 0,!1)}e._onChange(i),s._onChange(o),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:s},scale:{configurable:!0,enumerable:!0,value:n},modelViewMatrix:{value:new nt},normalMatrix:{value:new Bt}}),this.matrix=new nt,this.matrixWorld=new nt,this.matrixAutoUpdate=re.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=re.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new qo,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Ee.setFromAxisAngle(t,e),this.quaternion.multiply(Ee),this}rotateOnWorldAxis(t,e){return Ee.setFromAxisAngle(t,e),this.quaternion.premultiply(Ee),this}rotateX(t){return this.rotateOnAxis(Zi,t)}rotateY(t){return this.rotateOnAxis(Ji,t)}rotateZ(t){return this.rotateOnAxis(Qi,t)}translateOnAxis(t,e){return Yi.copy(t).applyQuaternion(this.quaternion),this.position.add(Yi.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Zi,t)}translateY(t){return this.translateOnAxis(Ji,t)}translateZ(t){return this.translateOnAxis(Qi,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(Xt.copy(this.matrixWorld).invert())}lookAt(t,e,s){t.isVector3?Ps.copy(t):Ps.set(t,e,s);const n=this.parent;this.updateWorldMatrix(!0,!1),is.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Xt.lookAt(is,Ps,this.up):Xt.lookAt(Ps,is,this.up),this.quaternion.setFromRotationMatrix(Xt),n&&(Xt.extractRotation(n.matrixWorld),Ee.setFromRotationMatrix(Xt),this.quaternion.premultiply(Ee.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(console.error("THREE.Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(ji),Ce.child=t,this.dispatchEvent(Ce),Ce.child=null):console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let s=0;s<arguments.length;s++)this.remove(arguments[s]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(Xo),En.child=t,this.dispatchEvent(En),En.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),Xt.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),Xt.multiply(t.parent.matrixWorld)),t.applyMatrix4(Xt),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(ji),Ce.child=t,this.dispatchEvent(Ce),Ce.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let s=0,n=this.children.length;s<n;s++){const o=this.children[s].getObjectByProperty(t,e);if(o!==void 0)return o}}getObjectsByProperty(t,e,s=[]){this[t]===e&&s.push(this);const n=this.children;for(let i=0,o=n.length;i<o;i++)n[i].getObjectsByProperty(t,e,s);return s}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(is,t,Wo),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(is,Go,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let s=0,n=e.length;s<n;s++)e[s].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let s=0,n=e.length;s<n;s++)e[s].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let s=0,n=e.length;s<n;s++)e[s].updateMatrixWorld(t)}updateWorldMatrix(t,e){const s=this.parent;if(t===!0&&s!==null&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),e===!0){const n=this.children;for(let i=0,o=n.length;i<o;i++)n[i].updateWorldMatrix(!1,!0)}}toJSON(t){const e=t===void 0||typeof t=="string",s={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},s.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const n={};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.castShadow===!0&&(n.castShadow=!0),this.receiveShadow===!0&&(n.receiveShadow=!0),this.visible===!1&&(n.visible=!1),this.frustumCulled===!1&&(n.frustumCulled=!1),this.renderOrder!==0&&(n.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(n.userData=this.userData),n.layers=this.layers.mask,n.matrix=this.matrix.toArray(),n.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(n.matrixAutoUpdate=!1),this.isInstancedMesh&&(n.type="InstancedMesh",n.count=this.count,n.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(n.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(n.type="BatchedMesh",n.perObjectFrustumCulled=this.perObjectFrustumCulled,n.sortObjects=this.sortObjects,n.drawRanges=this._drawRanges,n.reservedRanges=this._reservedRanges,n.visibility=this._visibility,n.active=this._active,n.bounds=this._bounds.map(a=>({boxInitialized:a.boxInitialized,boxMin:a.box.min.toArray(),boxMax:a.box.max.toArray(),sphereInitialized:a.sphereInitialized,sphereRadius:a.sphere.radius,sphereCenter:a.sphere.center.toArray()})),n.maxInstanceCount=this._maxInstanceCount,n.maxVertexCount=this._maxVertexCount,n.maxIndexCount=this._maxIndexCount,n.geometryInitialized=this._geometryInitialized,n.geometryCount=this._geometryCount,n.matricesTexture=this._matricesTexture.toJSON(t),this._colorsTexture!==null&&(n.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(n.boundingSphere={center:n.boundingSphere.center.toArray(),radius:n.boundingSphere.radius}),this.boundingBox!==null&&(n.boundingBox={min:n.boundingBox.min.toArray(),max:n.boundingBox.max.toArray()}));function i(a,c){return a[c.uuid]===void 0&&(a[c.uuid]=c.toJSON(t)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(n.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=i(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const c=a.shapes;if(Array.isArray(c))for(let u=0,h=c.length;u<h;u++){const l=c[u];i(t.shapes,l)}else i(t.shapes,c)}}if(this.isSkinnedMesh&&(n.bindMode=this.bindMode,n.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(i(t.skeletons,this.skeleton),n.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let c=0,u=this.material.length;c<u;c++)a.push(i(t.materials,this.material[c]));n.material=a}else n.material=i(t.materials,this.material);if(this.children.length>0){n.children=[];for(let a=0;a<this.children.length;a++)n.children.push(this.children[a].toJSON(t).object)}if(this.animations.length>0){n.animations=[];for(let a=0;a<this.animations.length;a++){const c=this.animations[a];n.animations.push(i(t.animations,c))}}if(e){const a=o(t.geometries),c=o(t.materials),u=o(t.textures),h=o(t.images),l=o(t.shapes),d=o(t.skeletons),p=o(t.animations),f=o(t.nodes);a.length>0&&(s.geometries=a),c.length>0&&(s.materials=c),u.length>0&&(s.textures=u),h.length>0&&(s.images=h),l.length>0&&(s.shapes=l),d.length>0&&(s.skeletons=d),p.length>0&&(s.animations=p),f.length>0&&(s.nodes=f)}return s.object=n,s;function o(a){const c=[];for(const u in a){const h=a[u];delete h.metadata,c.push(h)}return c}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let s=0;s<t.children.length;s++){const n=t.children[s];this.add(n.clone())}return this}}re.DEFAULT_UP=new _(0,1,0),re.DEFAULT_MATRIX_AUTO_UPDATE=!0,re.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const Lt=new _,Yt=new _,Cn=new _,Zt=new _,Fe=new _,Re=new _,Ki=new _,Fn=new _,Rn=new _,Bn=new _,In=new It,Pn=new It,vn=new It;class St{constructor(t=new _,e=new _,s=new _){this.a=t,this.b=e,this.c=s}static getNormal(t,e,s,n){n.subVectors(s,e),Lt.subVectors(t,e),n.cross(Lt);const i=n.lengthSq();return i>0?n.multiplyScalar(1/Math.sqrt(i)):n.set(0,0,0)}static getBarycoord(t,e,s,n,i){Lt.subVectors(n,e),Yt.subVectors(s,e),Cn.subVectors(t,e);const o=Lt.dot(Lt),a=Lt.dot(Yt),c=Lt.dot(Cn),u=Yt.dot(Yt),h=Yt.dot(Cn),l=o*u-a*a;if(l===0)return i.set(0,0,0),null;const d=1/l,p=(u*c-a*h)*d,f=(o*h-a*c)*d;return i.set(1-p-f,f,p)}static containsPoint(t,e,s,n){return this.getBarycoord(t,e,s,n,Zt)===null?!1:Zt.x>=0&&Zt.y>=0&&Zt.x+Zt.y<=1}static getInterpolation(t,e,s,n,i,o,a,c){return this.getBarycoord(t,e,s,n,Zt)===null?(c.x=0,c.y=0,"z"in c&&(c.z=0),"w"in c&&(c.w=0),null):(c.setScalar(0),c.addScaledVector(i,Zt.x),c.addScaledVector(o,Zt.y),c.addScaledVector(a,Zt.z),c)}static getInterpolatedAttribute(t,e,s,n,i,o){return In.setScalar(0),Pn.setScalar(0),vn.setScalar(0),In.fromBufferAttribute(t,e),Pn.fromBufferAttribute(t,s),vn.fromBufferAttribute(t,n),o.setScalar(0),o.addScaledVector(In,i.x),o.addScaledVector(Pn,i.y),o.addScaledVector(vn,i.z),o}static isFrontFacing(t,e,s,n){return Lt.subVectors(s,e),Yt.subVectors(t,e),Lt.cross(Yt).dot(n)<0}set(t,e,s){return this.a.copy(t),this.b.copy(e),this.c.copy(s),this}setFromPointsAndIndices(t,e,s,n){return this.a.copy(t[e]),this.b.copy(t[s]),this.c.copy(t[n]),this}setFromAttributeAndIndices(t,e,s,n){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,s),this.c.fromBufferAttribute(t,n),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return Lt.subVectors(this.c,this.b),Yt.subVectors(this.a,this.b),Lt.cross(Yt).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return St.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return St.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,s,n,i){return St.getInterpolation(t,this.a,this.b,this.c,e,s,n,i)}containsPoint(t){return St.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return St.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const s=this.a,n=this.b,i=this.c;let o,a;Fe.subVectors(n,s),Re.subVectors(i,s),Fn.subVectors(t,s);const c=Fe.dot(Fn),u=Re.dot(Fn);if(c<=0&&u<=0)return e.copy(s);Rn.subVectors(t,n);const h=Fe.dot(Rn),l=Re.dot(Rn);if(h>=0&&l<=h)return e.copy(n);const d=c*l-h*u;if(d<=0&&c>=0&&h<=0)return o=c/(c-h),e.copy(s).addScaledVector(Fe,o);Bn.subVectors(t,i);const p=Fe.dot(Bn),f=Re.dot(Bn);if(f>=0&&p<=f)return e.copy(i);const y=p*u-c*f;if(y<=0&&u>=0&&f<=0)return a=u/(u-f),e.copy(s).addScaledVector(Re,a);const N=h*f-p*l;if(N<=0&&l-h>=0&&p-f>=0)return Ki.subVectors(i,n),a=(l-h)/(l-h+(p-f)),e.copy(n).addScaledVector(Ki,a);const A=1/(N+y+d);return o=y*A,a=d*A,e.copy(s).addScaledVector(Fe,o).addScaledVector(Re,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const tr={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},oe={h:0,s:0,l:0},vs={h:0,s:0,l:0};function Ln(r,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?r+(t-r)*6*e:e<1/2?t:e<2/3?r+(t-r)*6*(2/3-e):r}class On{constructor(t,e,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,s)}set(t,e,s){if(e===void 0&&s===void 0){const n=t;n&&n.isColor?this.copy(n):typeof n=="number"?this.setHex(n):typeof n=="string"&&this.setStyle(n)}else this.setRGB(t,e,s);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Wt){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,yt.toWorkingColorSpace(this,e),this}setRGB(t,e,s,n=yt.workingColorSpace){return this.r=t,this.g=e,this.b=s,yt.toWorkingColorSpace(this,n),this}setHSL(t,e,s,n=yt.workingColorSpace){if(t=wn(t,1),e=ct(e,0,1),s=ct(s,0,1),e===0)this.r=this.g=this.b=s;else{const i=s<=.5?s*(1+e):s+e-s*e,o=2*s-i;this.r=Ln(o,i,t+1/3),this.g=Ln(o,i,t),this.b=Ln(o,i,t-1/3)}return yt.toWorkingColorSpace(this,n),this}setStyle(t,e=Wt){function s(i){i!==void 0&&parseFloat(i)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let n;if(n=/^(\w+)\(([^\)]*)\)/.exec(t)){let i;const o=n[1],a=n[2];switch(o){case"rgb":case"rgba":if(i=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(i[4]),this.setRGB(Math.min(255,parseInt(i[1],10))/255,Math.min(255,parseInt(i[2],10))/255,Math.min(255,parseInt(i[3],10))/255,e);if(i=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(i[4]),this.setRGB(Math.min(100,parseInt(i[1],10))/100,Math.min(100,parseInt(i[2],10))/100,Math.min(100,parseInt(i[3],10))/100,e);break;case"hsl":case"hsla":if(i=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(i[4]),this.setHSL(parseFloat(i[1])/360,parseFloat(i[2])/100,parseFloat(i[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(n=/^\#([A-Fa-f\d]+)$/.exec(t)){const i=n[1],o=i.length;if(o===3)return this.setRGB(parseInt(i.charAt(0),16)/15,parseInt(i.charAt(1),16)/15,parseInt(i.charAt(2),16)/15,e);if(o===6)return this.setHex(parseInt(i,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=Wt){const s=tr[t.toLowerCase()];return s!==void 0?this.setHex(s,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=Ae(t.r),this.g=Ae(t.g),this.b=Ae(t.b),this}copyLinearToSRGB(t){return this.r=Sn(t.r),this.g=Sn(t.g),this.b=Sn(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Wt){return yt.fromWorkingColorSpace(ht.copy(this),t),Math.round(ct(ht.r*255,0,255))*65536+Math.round(ct(ht.g*255,0,255))*256+Math.round(ct(ht.b*255,0,255))}getHexString(t=Wt){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=yt.workingColorSpace){yt.fromWorkingColorSpace(ht.copy(this),e);const s=ht.r,n=ht.g,i=ht.b,o=Math.max(s,n,i),a=Math.min(s,n,i);let c,u;const h=(a+o)/2;if(a===o)c=0,u=0;else{const l=o-a;switch(u=h<=.5?l/(o+a):l/(2-o-a),o){case s:c=(n-i)/l+(n<i?6:0);break;case n:c=(i-s)/l+2;break;case i:c=(s-n)/l+4;break}c/=6}return t.h=c,t.s=u,t.l=h,t}getRGB(t,e=yt.workingColorSpace){return yt.fromWorkingColorSpace(ht.copy(this),e),t.r=ht.r,t.g=ht.g,t.b=ht.b,t}getStyle(t=Wt){yt.fromWorkingColorSpace(ht.copy(this),t);const e=ht.r,s=ht.g,n=ht.b;return t!==Wt?`color(${t} ${e.toFixed(3)} ${s.toFixed(3)} ${n.toFixed(3)})`:`rgb(${Math.round(e*255)},${Math.round(s*255)},${Math.round(n*255)})`}offsetHSL(t,e,s){return this.getHSL(oe),this.setHSL(oe.h+t,oe.s+e,oe.l+s)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,s){return this.r=t.r+(e.r-t.r)*s,this.g=t.g+(e.g-t.g)*s,this.b=t.b+(e.b-t.b)*s,this}lerpHSL(t,e){this.getHSL(oe),t.getHSL(vs);const s=Ke(oe.h,vs.h,e),n=Ke(oe.s,vs.s,e),i=Ke(oe.l,vs.l,e);return this.setHSL(s,n,i),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,s=this.g,n=this.b,i=t.elements;return this.r=i[0]*e+i[3]*s+i[6]*n,this.g=i[1]*e+i[4]*s+i[7]*n,this.b=i[2]*e+i[5]*s+i[8]*n,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const ht=new On;On.NAMES=tr;const Q=new _,Ls=new Z;class Ot{constructor(t,e,s=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=s,this.usage=35044,this.updateRanges=[],this.gpuType=1015,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,s){t*=this.itemSize,s*=e.itemSize;for(let n=0,i=this.itemSize;n<i;n++)this.array[t+n]=e.array[s+n];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,s=this.count;e<s;e++)Ls.fromBufferAttribute(this,e),Ls.applyMatrix3(t),this.setXY(e,Ls.x,Ls.y);else if(this.itemSize===3)for(let e=0,s=this.count;e<s;e++)Q.fromBufferAttribute(this,e),Q.applyMatrix3(t),this.setXYZ(e,Q.x,Q.y,Q.z);return this}applyMatrix4(t){for(let e=0,s=this.count;e<s;e++)Q.fromBufferAttribute(this,e),Q.applyMatrix4(t),this.setXYZ(e,Q.x,Q.y,Q.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)Q.fromBufferAttribute(this,e),Q.applyNormalMatrix(t),this.setXYZ(e,Q.x,Q.y,Q.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)Q.fromBufferAttribute(this,e),Q.transformDirection(t),this.setXYZ(e,Q.x,Q.y,Q.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let s=this.array[t*this.itemSize+e];return this.normalized&&(s=Rt(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=W(s,this.array)),this.array[t*this.itemSize+e]=s,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=Rt(e,this.array)),e}setX(t,e){return this.normalized&&(e=W(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=Rt(e,this.array)),e}setY(t,e){return this.normalized&&(e=W(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=Rt(e,this.array)),e}setZ(t,e){return this.normalized&&(e=W(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=Rt(e,this.array)),e}setW(t,e){return this.normalized&&(e=W(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,s){return t*=this.itemSize,this.normalized&&(e=W(e,this.array),s=W(s,this.array)),this.array[t+0]=e,this.array[t+1]=s,this}setXYZ(t,e,s,n){return t*=this.itemSize,this.normalized&&(e=W(e,this.array),s=W(s,this.array),n=W(n,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=n,this}setXYZW(t,e,s,n,i){return t*=this.itemSize,this.normalized&&(e=W(e,this.array),s=W(s,this.array),n=W(n,this.array),i=W(i,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=n,this.array[t+3]=i,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(t.name=this.name),this.usage!==35044&&(t.usage=this.usage),t}}class Yo extends Ot{constructor(t,e,s){super(new Uint16Array(t),e,s)}}class Zo extends Ot{constructor(t,e,s){super(new Uint32Array(t),e,s)}}class Jo extends Ot{constructor(t,e,s){super(new Float32Array(t),e,s)}}let Qo=0;const Mt=new nt,Dn=new re,Be=new _,xt=new ut,rs=new ut,it=new _;class Vn extends je{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:Qo++}),this.uuid=ee(),this.name="",this.type="BufferGeometry",this.index=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(Po(t)?Zo:Yo)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,s=0){this.groups.push({start:t,count:e,materialIndex:s})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const s=this.attributes.normal;if(s!==void 0){const i=new Bt().getNormalMatrix(t);s.applyNormalMatrix(i),s.needsUpdate=!0}const n=this.attributes.tangent;return n!==void 0&&(n.transformDirection(t),n.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(t){return Mt.makeRotationFromQuaternion(t),this.applyMatrix4(Mt),this}rotateX(t){return Mt.makeRotationX(t),this.applyMatrix4(Mt),this}rotateY(t){return Mt.makeRotationY(t),this.applyMatrix4(Mt),this}rotateZ(t){return Mt.makeRotationZ(t),this.applyMatrix4(Mt),this}translate(t,e,s){return Mt.makeTranslation(t,e,s),this.applyMatrix4(Mt),this}scale(t,e,s){return Mt.makeScale(t,e,s),this.applyMatrix4(Mt),this}lookAt(t){return Dn.lookAt(t),Dn.updateMatrix(),this.applyMatrix4(Dn.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Be).negate(),this.translate(Be.x,Be.y,Be.z),this}setFromPoints(t){const e=[];for(let s=0,n=t.length;s<n;s++){const i=t[s];e.push(i.x,i.y,i.z||0)}return this.setAttribute("position",new Jo(e,3)),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new ut);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new _(-1/0,-1/0,-1/0),new _(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let s=0,n=e.length;s<n;s++){const i=e[s];xt.setFromBufferAttribute(i),this.morphTargetsRelative?(it.addVectors(this.boundingBox.min,xt.min),this.boundingBox.expandByPoint(it),it.addVectors(this.boundingBox.max,xt.max),this.boundingBox.expandByPoint(it)):(this.boundingBox.expandByPoint(xt.min),this.boundingBox.expandByPoint(xt.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new Uo);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new _,1/0);return}if(t){const s=this.boundingSphere.center;if(xt.setFromBufferAttribute(t),e)for(let i=0,o=e.length;i<o;i++){const a=e[i];rs.setFromBufferAttribute(a),this.morphTargetsRelative?(it.addVectors(xt.min,rs.min),xt.expandByPoint(it),it.addVectors(xt.max,rs.max),xt.expandByPoint(it)):(xt.expandByPoint(rs.min),xt.expandByPoint(rs.max))}xt.getCenter(s);let n=0;for(let i=0,o=t.count;i<o;i++)it.fromBufferAttribute(t,i),n=Math.max(n,s.distanceToSquared(it));if(e)for(let i=0,o=e.length;i<o;i++){const a=e[i],c=this.morphTargetsRelative;for(let u=0,h=a.count;u<h;u++)it.fromBufferAttribute(a,u),c&&(Be.fromBufferAttribute(t,u),it.add(Be)),n=Math.max(n,s.distanceToSquared(it))}this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const s=e.position,n=e.normal,i=e.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new Ot(new Float32Array(4*s.count),4));const o=this.getAttribute("tangent"),a=[],c=[];for(let z=0;z<s.count;z++)a[z]=new _,c[z]=new _;const u=new _,h=new _,l=new _,d=new Z,p=new Z,f=new Z,y=new _,N=new _;function A(z,R,F){u.fromBufferAttribute(s,z),h.fromBufferAttribute(s,R),l.fromBufferAttribute(s,F),d.fromBufferAttribute(i,z),p.fromBufferAttribute(i,R),f.fromBufferAttribute(i,F),h.sub(u),l.sub(u),p.sub(d),f.sub(d);const P=1/(p.x*f.y-f.x*p.y);isFinite(P)&&(y.copy(h).multiplyScalar(f.y).addScaledVector(l,-p.y).multiplyScalar(P),N.copy(l).multiplyScalar(p.x).addScaledVector(h,-f.x).multiplyScalar(P),a[z].add(y),a[R].add(y),a[F].add(y),c[z].add(N),c[R].add(N),c[F].add(N))}let x=this.groups;x.length===0&&(x=[{start:0,count:t.count}]);for(let z=0,R=x.length;z<R;++z){const F=x[z],P=F.start,C=F.count;for(let I=P,L=P+C;I<L;I+=3)A(t.getX(I+0),t.getX(I+1),t.getX(I+2))}const w=new _,g=new _,m=new _,M=new _;function S(z){m.fromBufferAttribute(n,z),M.copy(m);const R=a[z];w.copy(R),w.sub(m.multiplyScalar(m.dot(R))).normalize(),g.crossVectors(M,R);const P=g.dot(c[z])<0?-1:1;o.setXYZW(z,w.x,w.y,w.z,P)}for(let z=0,R=x.length;z<R;++z){const F=x[z],P=F.start,C=F.count;for(let I=P,L=P+C;I<L;I+=3)S(t.getX(I+0)),S(t.getX(I+1)),S(t.getX(I+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let s=this.getAttribute("normal");if(s===void 0)s=new Ot(new Float32Array(e.count*3),3),this.setAttribute("normal",s);else for(let d=0,p=s.count;d<p;d++)s.setXYZ(d,0,0,0);const n=new _,i=new _,o=new _,a=new _,c=new _,u=new _,h=new _,l=new _;if(t)for(let d=0,p=t.count;d<p;d+=3){const f=t.getX(d+0),y=t.getX(d+1),N=t.getX(d+2);n.fromBufferAttribute(e,f),i.fromBufferAttribute(e,y),o.fromBufferAttribute(e,N),h.subVectors(o,i),l.subVectors(n,i),h.cross(l),a.fromBufferAttribute(s,f),c.fromBufferAttribute(s,y),u.fromBufferAttribute(s,N),a.add(h),c.add(h),u.add(h),s.setXYZ(f,a.x,a.y,a.z),s.setXYZ(y,c.x,c.y,c.z),s.setXYZ(N,u.x,u.y,u.z)}else for(let d=0,p=e.count;d<p;d+=3)n.fromBufferAttribute(e,d+0),i.fromBufferAttribute(e,d+1),o.fromBufferAttribute(e,d+2),h.subVectors(o,i),l.subVectors(n,i),h.cross(l),s.setXYZ(d+0,h.x,h.y,h.z),s.setXYZ(d+1,h.x,h.y,h.z),s.setXYZ(d+2,h.x,h.y,h.z);this.normalizeNormals(),s.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,s=t.count;e<s;e++)it.fromBufferAttribute(t,e),it.normalize(),t.setXYZ(e,it.x,it.y,it.z)}toNonIndexed(){function t(a,c){const u=a.array,h=a.itemSize,l=a.normalized,d=new u.constructor(c.length*h);let p=0,f=0;for(let y=0,N=c.length;y<N;y++){a.isInterleavedBufferAttribute?p=c[y]*a.data.stride+a.offset:p=c[y]*h;for(let A=0;A<h;A++)d[f++]=u[p++]}return new Ot(d,h,l)}if(this.index===null)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Vn,s=this.index.array,n=this.attributes;for(const a in n){const c=n[a],u=t(c,s);e.setAttribute(a,u)}const i=this.morphAttributes;for(const a in i){const c=[],u=i[a];for(let h=0,l=u.length;h<l;h++){const d=u[h],p=t(d,s);c.push(p)}e.morphAttributes[a]=c}e.morphTargetsRelative=this.morphTargetsRelative;const o=this.groups;for(let a=0,c=o.length;a<c;a++){const u=o[a];e.addGroup(u.start,u.count,u.materialIndex)}return e}toJSON(){const t={metadata:{version:4.6,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,this.name!==""&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0){const c=this.parameters;for(const u in c)c[u]!==void 0&&(t[u]=c[u]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const s=this.attributes;for(const c in s){const u=s[c];t.data.attributes[c]=u.toJSON(t.data)}const n={};let i=!1;for(const c in this.morphAttributes){const u=this.morphAttributes[c],h=[];for(let l=0,d=u.length;l<d;l++){const p=u[l];h.push(p.toJSON(t.data))}h.length>0&&(n[c]=h,i=!0)}i&&(t.data.morphAttributes=n,t.data.morphTargetsRelative=this.morphTargetsRelative);const o=this.groups;o.length>0&&(t.data.groups=JSON.parse(JSON.stringify(o)));const a=this.boundingSphere;return a!==null&&(t.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const s=t.index;s!==null&&this.setIndex(s.clone(e));const n=t.attributes;for(const u in n){const h=n[u];this.setAttribute(u,h.clone(e))}const i=t.morphAttributes;for(const u in i){const h=[],l=i[u];for(let d=0,p=l.length;d<p;d++)h.push(l[d].clone(e));this.morphAttributes[u]=h}this.morphTargetsRelative=t.morphTargetsRelative;const o=t.groups;for(let u=0,h=o.length;u<h;u++){const l=o[u];this.addGroup(l.start,l.count,l.materialIndex)}const a=t.boundingBox;a!==null&&(this.boundingBox=a.clone());const c=t.boundingSphere;return c!==null&&(this.boundingSphere=c.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Un=new _,jo=new _,Ko=new Bt;class kn{constructor(t=new _(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,s,n){return this.normal.set(t,e,s),this.constant=n,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,s){const n=Un.subVectors(s,e).cross(jo.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(n,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const s=t.delta(Un),n=this.normal.dot(s);if(n===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const i=-(t.start.dot(this.normal)+this.constant)/n;return i<0||i>1?null:e.copy(t.start).addScaledVector(s,i)}intersectsLine(t){const e=this.distanceToPoint(t.start),s=this.distanceToPoint(t.end);return e<0&&s>0||s<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const s=e||Ko.getNormalMatrix(t),n=this.coplanarPoint(Un).applyMatrix4(t),i=this.normal.applyMatrix3(s).normalize();return this.constant=-n.dot(i),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}}class er extends kt{constructor(t,e,s,n,i,o,a,c,u,h=1026){if(h!==1026&&h!==1027)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");s===void 0&&h===1026&&(s=1014),s===void 0&&h===1027&&(s=1020),super(null,n,i,o,a,c,h,s,u),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=a!==void 0?a:1003,this.minFilter=c!==void 0?c:1003,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return this.compareFunction!==null&&(e.compareFunction=this.compareFunction),e}}class ta{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=t!==void 0?t.length/e:0,this.usage=35044,this.updateRanges=[],this.version=0,this.uuid=ee()}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,s){t*=this.stride,s*=e.stride;for(let n=0,i=this.stride;n<i;n++)this.array[t+n]=e.array[s+n];return this}set(t,e=0){return this.array.set(t,e),this}clone(t){t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=ee()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const e=new this.array.constructor(t.arrayBuffers[this.array.buffer._uuid]),s=new this.constructor(e,this.stride);return s.setUsage(this.usage),s}onUpload(t){return this.onUploadCallback=t,this}toJSON(t){return t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=ee()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}const lt=new _;class Hn{constructor(t,e,s,n=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=t,this.itemSize=e,this.offset=s,this.normalized=n}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(t){this.data.needsUpdate=t}applyMatrix4(t){for(let e=0,s=this.data.count;e<s;e++)lt.fromBufferAttribute(this,e),lt.applyMatrix4(t),this.setXYZ(e,lt.x,lt.y,lt.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)lt.fromBufferAttribute(this,e),lt.applyNormalMatrix(t),this.setXYZ(e,lt.x,lt.y,lt.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)lt.fromBufferAttribute(this,e),lt.transformDirection(t),this.setXYZ(e,lt.x,lt.y,lt.z);return this}getComponent(t,e){let s=this.array[t*this.data.stride+this.offset+e];return this.normalized&&(s=Rt(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=W(s,this.array)),this.data.array[t*this.data.stride+this.offset+e]=s,this}setX(t,e){return this.normalized&&(e=W(e,this.array)),this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.normalized&&(e=W(e,this.array)),this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.normalized&&(e=W(e,this.array)),this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.normalized&&(e=W(e,this.array)),this.data.array[t*this.data.stride+this.offset+3]=e,this}getX(t){let e=this.data.array[t*this.data.stride+this.offset];return this.normalized&&(e=Rt(e,this.array)),e}getY(t){let e=this.data.array[t*this.data.stride+this.offset+1];return this.normalized&&(e=Rt(e,this.array)),e}getZ(t){let e=this.data.array[t*this.data.stride+this.offset+2];return this.normalized&&(e=Rt(e,this.array)),e}getW(t){let e=this.data.array[t*this.data.stride+this.offset+3];return this.normalized&&(e=Rt(e,this.array)),e}setXY(t,e,s){return t=t*this.data.stride+this.offset,this.normalized&&(e=W(e,this.array),s=W(s,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=s,this}setXYZ(t,e,s,n){return t=t*this.data.stride+this.offset,this.normalized&&(e=W(e,this.array),s=W(s,this.array),n=W(n,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=s,this.data.array[t+2]=n,this}setXYZW(t,e,s,n,i){return t=t*this.data.stride+this.offset,this.normalized&&(e=W(e,this.array),s=W(s,this.array),n=W(n,this.array),i=W(i,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=s,this.data.array[t+2]=n,this.data.array[t+3]=i,this}clone(t){if(t===void 0){console.log("THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let s=0;s<this.count;s++){const n=s*this.data.stride+this.offset;for(let i=0;i<this.itemSize;i++)e.push(this.data.array[n+i])}return new Ot(new this.array.constructor(e),this.itemSize,this.normalized)}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.clone(t)),new Hn(t.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(t){if(t===void 0){console.log("THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let s=0;s<this.count;s++){const n=s*this.data.stride+this.offset;for(let i=0;i<this.itemSize;i++)e.push(this.data.array[n+i])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:e,normalized:this.normalized}}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.toJSON(t)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}class ea extends kt{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=1003,this.minFilter=1003,this.generateMipmaps=!1,this.needsUpdate=!0}}const sr=new _,Os=new _;class Jt{constructor(t=new _,e=new _){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){sr.subVectors(t,this.start),Os.subVectors(this.end,this.start);const s=Os.dot(Os);let i=Os.dot(sr)/s;return e&&(i=ct(i,0,1)),i}closestPointToPoint(t,e,s){const n=this.closestPointToPointParameter(t,e);return this.delta(s).multiplyScalar(n).add(this.start)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}function qn(r,t=0){let e=3735928559^t,s=1103547991^t;if(r instanceof Array)for(let n=0,i;n<r.length;n++)i=r[n],e=Math.imul(e^i,2654435761),s=Math.imul(s^i,1597334677);else for(let n=0,i;n<r.length;n++)i=r.charCodeAt(n),e=Math.imul(e^i,2654435761),s=Math.imul(s^i,1597334677);return e=Math.imul(e^e>>>16,2246822507),e^=Math.imul(s^s>>>13,3266489909),s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(e^e>>>13,3266489909),4294967296*(2097151&s)+(e>>>0)}const sa=(...r)=>qn(r);function na(r,t=!1){const e=[];r.isNode===!0&&(e.push(r.id),r=r.getSelf());for(const{property:s,childNode:n}of $n(r))e.push(e,qn(s.slice(0,-4)),n.getCacheKey(t));return qn(e)}function*$n(r,t=!1){for(const e in r){if(e.startsWith("_")===!0)continue;const s=r[e];if(Array.isArray(s)===!0)for(let n=0;n<s.length;n++){const i=s[n];i&&(i.isNode===!0||t&&typeof i.toJSON=="function")&&(yield{property:e,index:n,childNode:i})}else if(s&&s.isNode===!0)yield{property:e,childNode:s};else if(typeof s=="object")for(const n in s){const i=s[n];i&&(i.isNode===!0||t&&typeof i.toJSON=="function")&&(yield{property:e,index:n,childNode:i})}}}function Ds(r){if(r==null)return null;const t=typeof r;return r.isNode===!0?"node":t==="number"?"float":t==="boolean"?"bool":t==="string"?"string":t==="function"?"shader":r.isVector2===!0?"vec2":r.isVector3===!0?"vec3":r.isVector4===!0?"vec4":r.isMatrix3===!0?"mat3":r.isMatrix4===!0?"mat4":r.isColor===!0?"color":r instanceof ArrayBuffer?"ArrayBuffer":null}function nr(r,...t){const e=r?r.slice(-4):void 0;return t.length===1&&(e==="vec2"?t=[t[0],t[0]]:e==="vec3"?t=[t[0],t[0],t[0]]:e==="vec4"&&(t=[t[0],t[0],t[0],t[0]])),r==="color"?new On(...t):e==="vec2"?new Z(...t):e==="vec3"?new _(...t):e==="vec4"?new It(...t):e==="mat3"?new Bt(...t):e==="mat4"?new nt(...t):r==="bool"?t[0]||!1:r==="float"||r==="int"||r==="uint"?t[0]||0:r==="string"?t[0]||"":r==="ArrayBuffer"?ra(t[0]):null}function ia(r){let t="";const e=new Uint8Array(r);for(let s=0;s<e.length;s++)t+=String.fromCharCode(e[s]);return btoa(t)}function ra(r){return Uint8Array.from(atob(r),t=>t.charCodeAt(0)).buffer}const ir={VERTEX:"vertex"},j={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},os=["x","y","z","w"];let oa=0;class U extends je{static get type(){return"Node"}constructor(t=null){super(),this.nodeType=t,this.updateType=j.NONE,this.updateBeforeType=j.NONE,this.updateAfterType=j.NONE,this.uuid=Io.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:oa++})}set needsUpdate(t){t===!0&&this.version++}get type(){return this.constructor.type}onUpdate(t,e){return this.updateType=e,this.update=t.bind(this.getSelf()),this}onFrameUpdate(t){return this.onUpdate(t,j.FRAME)}onRenderUpdate(t){return this.onUpdate(t,j.RENDER)}onObjectUpdate(t){return this.onUpdate(t,j.OBJECT)}onReference(t){return this.updateReference=t.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:t}of $n(this))yield t}dispose(){this.dispatchEvent({type:"dispose"})}traverse(t){t(this);for(const e of this.getChildren())e.traverse(t)}getCacheKey(t=!1){return t=t||this.version!==this._cacheKeyVersion,(t===!0||this._cacheKey===null)&&(this._cacheKey=na(this,t),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(t){const e=this.getNodeType(t);return t.getElementType(e)}getNodeType(t){const e=t.getNodeProperties(this);return e.outputNode?e.outputNode.getNodeType(t):this.nodeType}getShared(t){const e=this.getHash(t);return t.getNodeFromHash(e)||this}setup(t){const e=t.getNodeProperties(this);let s=0;for(const n of this.getChildren())e["node"+s++]=n;return null}analyze(t){if(t.increaseUsage(this)===1){const s=t.getNodeProperties(this);for(const n of Object.values(s))n&&n.isNode===!0&&n.build(t)}}generate(t,e){const{outputNode:s}=t.getNodeProperties(this);if(s&&s.isNode===!0)return s.build(t,e)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(t,e=null){const s=this.getShared(t);if(this!==s)return s.build(t,e);t.addNode(this),t.addChain(this);let n=null;const i=t.getBuildStage();if(i==="setup"){this.updateReference(t);const o=t.getNodeProperties(this);if(o.initialized!==!0){const a=t.stack.nodes.length;o.initialized=!0,o.outputNode=this.setup(t),o.outputNode!==null&&t.stack.nodes.length;for(const c of Object.values(o))c&&c.isNode===!0&&c.build(t)}}else if(i==="analyze")this.analyze(t);else if(i==="generate")if(this.generate.length===1){const a=this.getNodeType(t),c=t.getDataFromNode(this);n=c.snippet,n===void 0?(n=this.generate(t)||"",c.snippet=n):c.flowCodes!==void 0&&t.context.nodeBlock!==void 0&&t.addFlowCodeHierarchy(this,t.context.nodeBlock),n=t.format(n,a,e)}else n=this.generate(t,e)||"";return t.removeChain(this),n}getSerializeChildren(){return $n(this)}serialize(t){const e=this.getSerializeChildren(),s={};for(const{property:n,index:i,childNode:o}of e)i!==void 0?(s[n]===void 0&&(s[n]=Number.isInteger(i)?[]:{}),s[n][i]=o.toJSON(t.meta).uuid):s[n]=o.toJSON(t.meta).uuid;Object.keys(s).length>0&&(t.inputNodes=s)}deserialize(t){if(t.inputNodes!==void 0){const e=t.meta.nodes;for(const s in t.inputNodes)if(Array.isArray(t.inputNodes[s])){const n=[];for(const i of t.inputNodes[s])n.push(e[i]);this[s]=n}else if(typeof t.inputNodes[s]=="object"){const n={};for(const i in t.inputNodes[s]){const o=t.inputNodes[s][i];n[i]=e[o]}this[s]=n}else{const n=t.inputNodes[s];this[s]=e[n]}}}toJSON(t){const{uuid:e,type:s}=this,n=t===void 0||typeof t=="string";n&&(t={textures:{},images:{},nodes:{}});let i=t.nodes[e];i===void 0&&(i={uuid:e,type:s,meta:t,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},n!==!0&&(t.nodes[i.uuid]=i),this.serialize(i),delete i.meta);function o(a){const c=[];for(const u in a){const h=a[u];delete h.metadata,c.push(h)}return c}if(n){const a=o(t.textures),c=o(t.images),u=o(t.nodes);a.length>0&&(i.textures=a),c.length>0&&(i.images=c),u.length>0&&(i.nodes=u)}return i}}class as extends U{static get type(){return"ArrayElementNode"}constructor(t,e){super(),this.node=t,this.indexNode=e,this.isArrayElementNode=!0}getNodeType(t){return this.node.getElementType(t)}generate(t){const e=this.node.build(t),s=this.indexNode.build(t,"uint");return`${e}[ ${s} ]`}}class rr extends U{static get type(){return"ConvertNode"}constructor(t,e){super(),this.node=t,this.convertTo=e}getNodeType(t){const e=this.node.getNodeType(t);let s=null;for(const n of this.convertTo.split("|"))(s===null||t.getTypeLength(e)===t.getTypeLength(n))&&(s=n);return s}serialize(t){super.serialize(t),t.convertTo=this.convertTo}deserialize(t){super.deserialize(t),this.convertTo=t.convertTo}generate(t,e){const s=this.node,n=this.getNodeType(t),i=s.build(t,n);return t.format(i,n,e)}}class pt extends U{static get type(){return"TempNode"}constructor(t){super(t),this.isTempNode=!0}hasDependencies(t){return t.getDataFromNode(this).usageCount>1}build(t,e){if(t.getBuildStage()==="generate"){const n=t.getVectorType(this.getNodeType(t,e)),i=t.getDataFromNode(this);if(i.propertyName!==void 0)return t.format(i.propertyName,n,e);if(n!=="void"&&e!=="void"&&this.hasDependencies(t)){const o=super.build(t,n),a=t.getVarFromNode(this,null,n),c=t.getPropertyName(a);return t.addLineFlowCode(`${c} = ${o}`,this),i.snippet=o,i.propertyName=c,t.format(i.propertyName,n,e)}}return super.build(t,e)}}class aa extends pt{static get type(){return"JoinNode"}constructor(t=[],e=null){super(e),this.nodes=t}getNodeType(t){return this.nodeType!==null?t.getVectorType(this.nodeType):t.getTypeFromLength(this.nodes.reduce((e,s)=>e+t.getTypeLength(s.getNodeType(t)),0))}generate(t,e){const s=this.getNodeType(t),n=this.nodes,i=t.getComponentType(s),o=[];for(const c of n){let u=c.build(t);const h=t.getComponentType(c.getNodeType(t));h!==i&&(u=t.format(u,h,i)),o.push(u)}const a=`${t.getType(s)}( ${o.join(", ")} )`;return t.format(a,s,e)}}const ca=os.join("");class or extends U{static get type(){return"SplitNode"}constructor(t,e="x"){super(),this.node=t,this.components=e,this.isSplitNode=!0}getVectorLength(){let t=this.components.length;for(const e of this.components)t=Math.max(os.indexOf(e)+1,t);return t}getComponentType(t){return t.getComponentType(this.node.getNodeType(t))}getNodeType(t){return t.getTypeFromLength(this.components.length,this.getComponentType(t))}generate(t,e){const s=this.node,n=t.getTypeLength(s.getNodeType(t));let i=null;if(n>1){let o=null;this.getVectorLength()>=n&&(o=t.getTypeFromLength(this.getVectorLength(),this.getComponentType(t)));const c=s.build(t,o);this.components.length===n&&this.components===ca.slice(0,this.components.length)?i=t.format(c,o,e):i=t.format(`${c}.${this.components}`,this.getNodeType(t),e)}else i=s.build(t,e);return i}serialize(t){super.serialize(t),t.components=this.components}deserialize(t){super.deserialize(t),this.components=t.components}}class ha extends pt{static get type(){return"SetNode"}constructor(t,e,s){super(),this.sourceNode=t,this.components=e,this.targetNode=s}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{sourceNode:e,components:s,targetNode:n}=this,i=this.getNodeType(t),o=t.getTypeFromLength(s.length,n.getNodeType(t)),a=n.build(t,o),c=e.build(t,i),u=t.getTypeLength(i),h=[];for(let l=0;l<u;l++){const d=os[l];d===s[0]?(h.push(a),l+=s.length-1):h.push(c+"."+d)}return`${t.getType(i)}( ${h.join(", ")} )`}}class ua extends pt{static get type(){return"FlipNode"}constructor(t,e){super(),this.sourceNode=t,this.components=e}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{components:e,sourceNode:s}=this,n=this.getNodeType(t),i=s.build(t),o=t.getVarFromNode(this),a=t.getPropertyName(o);t.addLineFlowCode(a+" = "+i,this);const c=t.getTypeLength(n),u=[];let h=0;for(let l=0;l<c;l++){const d=os[l];d===e[h]?(u.push("1.0 - "+(a+"."+d)),h++):u.push(a+"."+d)}return`${t.getType(n)}( ${u.join(", ")} )`}}class Wn extends U{static get type(){return"InputNode"}constructor(t,e=null){super(e),this.isInputNode=!0,this.value=t,this.precision=null}getNodeType(){return this.nodeType===null?Ds(this.value):this.nodeType}getInputType(t){return this.getNodeType(t)}setPrecision(t){return this.precision=t,this}serialize(t){super.serialize(t),t.value=this.value,this.value&&this.value.toArray&&(t.value=this.value.toArray()),t.valueType=Ds(this.value),t.nodeType=this.nodeType,t.valueType==="ArrayBuffer"&&(t.value=ia(t.value)),t.precision=this.precision}deserialize(t){super.deserialize(t),this.nodeType=t.nodeType,this.value=Array.isArray(t.value)?nr(t.valueType,...t.value):t.value,this.precision=t.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(t.value))}generate(){console.warn("Abstract function.")}}class Qt extends Wn{static get type(){return"ConstNode"}constructor(t,e=null){super(t,e),this.isConstNode=!0}generateConst(t){return t.generateConst(this.getNodeType(t),this.value)}generate(t,e){const s=this.getNodeType(t);return t.format(this.generateConst(t),s,e)}}let ar=null;const Ie=new Map;function E(r,t){if(Ie.has(r)){console.warn(`Redefinition of method chaining ${r}`);return}if(typeof t!="function")throw new Error(`Node element ${r} is not a function`);Ie.set(r,t)}const cr=r=>r.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),hr=r=>cr(r).split("").sort().join(""),ur={setup(r,t){const e=t.shift();return r(ks(e),...t)},get(r,t,e){if(typeof t=="string"&&r[t]===void 0){if(r.isStackNode!==!0&&t==="assign")return(...s)=>(ar.assign(e,...s),e);if(Ie.has(t)){const s=Ie.get(t);return r.isStackNode?(...n)=>e.add(s(...n)):(...n)=>s(e,...n)}else{if(t==="self")return r;if(t.endsWith("Assign")&&Ie.has(t.slice(0,t.length-6))){const s=Ie.get(t.slice(0,t.length-6));return r.isStackNode?(...n)=>e.assign(n[0],s(...n)):(...n)=>e.assign(s(e,...n))}else{if(/^[xyzwrgbastpq]{1,4}$/.test(t)===!0)return t=cr(t),v(new or(e,t));if(/^set[XYZWRGBASTPQ]{1,4}$/.test(t)===!0)return t=hr(t.slice(3).toLowerCase()),s=>v(new ha(r,t,s));if(/^flip[XYZWRGBASTPQ]{1,4}$/.test(t)===!0)return t=hr(t.slice(4).toLowerCase()),()=>v(new ua(v(r),t));if(t==="width"||t==="height"||t==="depth")return t==="width"?t="x":t==="height"?t="y":t==="depth"&&(t="z"),v(new or(r,t));if(/^\d+$/.test(t)===!0)return v(new as(e,new Qt(Number(t),"uint")))}}}return Reflect.get(r,t,e)},set(r,t,e,s){return typeof t=="string"&&r[t]===void 0&&(/^[xyzwrgbastpq]{1,4}$/.test(t)===!0||t==="width"||t==="height"||t==="depth"||/^\d+$/.test(t)===!0)?(s[t].assign(e),!0):Reflect.set(r,t,e,s)}},Gn=new WeakMap,lr=new WeakMap,la=function(r,t=null){const e=Ds(r);if(e==="node"){let s=Gn.get(r);return s===void 0&&(s=new Proxy(r,ur),Gn.set(r,s),Gn.set(s,s)),s}else{if(t===null&&(e==="float"||e==="boolean")||e&&e!=="shader"&&e!=="string")return v(Jn(r,t));if(e==="shader")return tt(r)}return r},da=function(r,t=null){for(const e in r)r[e]=v(r[e],t);return r},pa=function(r,t=null){const e=r.length;for(let s=0;s<e;s++)r[s]=v(r[s],t);return r},fa=function(r,t=null,e=null,s=null){const n=i=>v(s!==null?Object.assign(i,s):i);return t===null?(...i)=>n(new r(...Pe(i))):e!==null?(e=v(e),(...i)=>n(new r(t,...Pe(i),e))):(...i)=>n(new r(t,...Pe(i)))},ma=function(r,...t){return v(new r(...Pe(t)))};class ya extends U{constructor(t,e){super(),this.shaderNode=t,this.inputNodes=e}getNodeType(t){return this.shaderNode.nodeType||this.getOutputNode(t).getNodeType(t)}call(t){const{shaderNode:e,inputNodes:s}=this,n=t.getNodeProperties(e);if(n.onceOutput)return n.onceOutput;let i=null;if(e.layout){let o=lr.get(t.constructor);o===void 0&&(o=new WeakMap,lr.set(t.constructor,o));let a=o.get(e);a===void 0&&(a=v(t.buildFunctionNode(e)),o.set(e,a)),t.currentFunctionNode!==null&&t.currentFunctionNode.includes.push(a),i=v(a.call(s))}else{const o=e.jsFunc,a=s!==null?o(s,t):o(t);i=v(a)}return e.once&&(n.onceOutput=i),i}getOutputNode(t){const e=t.getNodeProperties(this);return e.outputNode===null&&(e.outputNode=this.setupOutput(t)),e.outputNode}setup(t){return this.getOutputNode(t)}setupOutput(t){return t.addStack(),t.stack.outputNode=this.call(t),t.removeStack()}generate(t,e){return this.getOutputNode(t).build(t,e)}}class ga extends U{constructor(t,e){super(e),this.jsFunc=t,this.layout=null,this.global=!0,this.once=!1}setLayout(t){return this.layout=t,this}call(t=null){return ks(t),v(new ya(this,t))}setup(){return this.call()}}const xa=[!1,!0],Ta=[0,1,2,3],Na=[-1,-2],dr=[.5,1.5,1/3,1e-6,1e6,Math.PI,Math.PI*2,1/Math.PI,2/Math.PI,1/(Math.PI*2),Math.PI/2],Xn=new Map;for(const r of xa)Xn.set(r,new Qt(r));const Yn=new Map;for(const r of Ta)Yn.set(r,new Qt(r,"uint"));const Zn=new Map([...Yn].map(r=>new Qt(r.value,"int")));for(const r of Na)Zn.set(r,new Qt(r,"int"));const Vs=new Map([...Zn].map(r=>new Qt(r.value)));for(const r of dr)Vs.set(r,new Qt(r));for(const r of dr)Vs.set(-r,new Qt(-r));const Us={bool:Xn,uint:Yn,ints:Zn,float:Vs},pr=new Map([...Xn,...Vs]),Jn=(r,t)=>pr.has(r)?pr.get(r):r.isNode===!0?r:new Qt(r,t),wa=r=>{try{return r.getNodeType()}catch{return}},K=function(r,t=null){return(...e)=>{if((e.length===0||!["bool","float","int","uint"].includes(r)&&e.every(n=>typeof n!="object"))&&(e=[nr(r,...e)]),e.length===1&&t!==null&&t.has(e[0]))return v(t.get(e[0]));if(e.length===1){const n=Jn(e[0],r);return wa(n)===r?v(n):v(new rr(n,r))}const s=e.map(n=>Jn(n));return v(new aa(s,r))}},Aa=r=>r!=null?r.nodeType||r.convertTo||(typeof r=="string"?r:null):null;function Sa(r,t){return new Proxy(new ga(r,t),ur)}const v=(r,t=null)=>la(r,t),ks=(r,t=null)=>new da(r,t),Pe=(r,t=null)=>new pa(r,t),B=(...r)=>new fa(...r),O=(...r)=>new ma(...r),tt=(r,t)=>{const e=new Sa(r,t),s=(...n)=>{let i;return ks(n),n[0]&&n[0].isNode?i=[...n]:i=n[0],e.call(i)};return s.shaderNode=e,s.setLayout=n=>(e.setLayout(n),s),s.once=()=>(e.once=!0,s),s};E("toGlobal",r=>(r.global=!0,r));const Qn=(...r)=>ar.If(...r);function Ma(r){return r}E("append",Ma);const _a=new K("color"),$=new K("float",Us.float),ve=new K("int",Us.ints),za=new K("uint",Us.uint),ba=new K("bool",Us.bool),V=new K("vec2"),Ea=new K("ivec2"),Ca=new K("uvec2"),Fa=new K("bvec2"),H=new K("vec3"),Ra=new K("ivec3"),Ba=new K("uvec3"),Ia=new K("bvec3"),Le=new K("vec4"),Pa=new K("ivec4"),va=new K("uvec4"),La=new K("bvec4"),fr=new K("mat2"),Hs=new K("mat3"),Oa=new K("mat4");E("toColor",_a),E("toFloat",$),E("toInt",ve),E("toUint",za),E("toBool",ba),E("toVec2",V),E("toIVec2",Ea),E("toUVec2",Ca),E("toBVec2",Fa),E("toVec3",H),E("toIVec3",Ra),E("toUVec3",Ba),E("toBVec3",Ia),E("toVec4",Le),E("toIVec4",Pa),E("toUVec4",va),E("toBVec4",La),E("toMat2",fr),E("toMat3",Hs),E("toMat4",Oa);const Da=B(as),Va=(r,t)=>v(new rr(v(r),t));E("element",Da),E("convert",Va);class mr extends U{static get type(){return"UniformGroupNode"}constructor(t,e=!1,s=1){super("string"),this.name=t,this.version=0,this.shared=e,this.order=s,this.isUniformGroup=!0}set needsUpdate(t){t===!0&&this.version++}serialize(t){super.serialize(t),t.name=this.name,t.version=this.version,t.shared=this.shared}deserialize(t){super.deserialize(t),this.name=t.name,this.version=t.version,this.shared=t.shared}}const Ua=r=>new mr(r),ye=((r,t=0)=>new mr(r,!0,t))("render"),ka=Ua("object");class Oe extends Wn{static get type(){return"UniformNode"}constructor(t,e=null){super(t,e),this.isUniformNode=!0,this.name="",this.groupNode=ka}label(t){return this.name=t,this}setGroup(t){return this.groupNode=t,this}getGroup(){return this.groupNode}getUniformHash(t){return this.getHash(t)}onUpdate(t,e){const s=this.getSelf();return t=t.bind(s),super.onUpdate(n=>{const i=t(n,s);i!==void 0&&(this.value=i)},e)}generate(t,e){const s=this.getNodeType(t),n=this.getUniformHash(t);let i=t.getNodeFromHash(n);i===void 0&&(t.setHashNode(this,n),i=this);const o=i.getInputType(t),a=t.getUniformFromNode(i,o,t.shaderStage,this.name||t.context.label),c=t.getPropertyName(a);return t.context.label!==void 0&&delete t.context.label,t.format(c,s,e)}}const Tt=(r,t)=>{const e=Aa(t||r),s=r&&r.isNode===!0?r.node&&r.node.value||r.value:r;return v(new Oe(s,e))};class yr extends U{static get type(){return"PropertyNode"}constructor(t,e=null,s=!1){super(t),this.name=e,this.varying=s,this.isPropertyNode=!0}getHash(t){return this.name||super.getHash(t)}isGlobal(){return!0}generate(t){let e;return this.varying===!0?(e=t.getVaryingFromNode(this,this.name),e.needsInterpolation=!0):e=t.getVarFromNode(this,this.name),t.getPropertyName(e)}}const De=(r,t)=>v(new yr(r,t)),gr=O(yr,"vec4","DiffuseColor");class Ha extends pt{static get type(){return"AssignNode"}constructor(t,e){super(),this.targetNode=t,this.sourceNode=e}hasDependencies(){return!1}getNodeType(t,e){return e!=="void"?this.targetNode.getNodeType(t):"void"}needsSplitAssign(t){const{targetNode:e}=this;if(t.isAvailable("swizzleAssign")===!1&&e.isSplitNode&&e.components.length>1){const s=t.getTypeLength(e.node.getNodeType(t));return os.join("").slice(0,s)!==e.components}return!1}generate(t,e){const{targetNode:s,sourceNode:n}=this,i=this.needsSplitAssign(t),o=s.getNodeType(t),a=s.context({assign:!0}).build(t),c=n.build(t,o),u=n.getNodeType(t),h=t.getDataFromNode(this);let l;if(h.initialized===!0)e!=="void"&&(l=a);else if(i){const d=t.getVarFromNode(this,null,o),p=t.getPropertyName(d);t.addLineFlowCode(`${p} = ${c}`,this);const f=s.node.context({assign:!0}).build(t);for(let y=0;y<s.components.length;y++){const N=s.components[y];t.addLineFlowCode(`${f}.${N} = ${p}[ ${y} ]`,this)}e!=="void"&&(l=a)}else l=`${a} = ${c}`,(e==="void"||u==="void")&&(t.addLineFlowCode(l,this),e!=="void"&&(l=a));return h.initialized=!0,t.format(l,o,e)}}E("assign",B(Ha));class qa extends pt{static get type(){return"FunctionCallNode"}constructor(t=null,e={}){super(),this.functionNode=t,this.parameters=e}setParameters(t){return this.parameters=t,this}getParameters(){return this.parameters}getNodeType(t){return this.functionNode.getNodeType(t)}generate(t){const e=[],s=this.functionNode,n=s.getInputs(t),i=this.parameters;if(Array.isArray(i))for(let a=0;a<i.length;a++){const c=n[a],u=i[a];e.push(u.build(t,c.type))}else for(const a of n){const c=i[a.name];if(c!==void 0)e.push(c.build(t,a.type));else throw new Error(`FunctionCallNode: Input '${a.name}' not found in FunctionNode.`)}return`${s.build(t,"property")}( ${e.join(", ")} )`}}E("call",(r,...t)=>(t=t.length>1||t[0]&&t[0].isNode===!0?Pe(t):ks(t[0]),v(new qa(v(r),t))));class Y extends pt{static get type(){return"OperatorNode"}constructor(t,e,s,...n){if(super(),n.length>0){let i=new Y(t,e,s);for(let o=0;o<n.length-1;o++)i=new Y(t,i,n[o]);e=i,s=n[n.length-1]}this.op=t,this.aNode=e,this.bNode=s}getNodeType(t,e){const s=this.op,n=this.aNode,i=this.bNode,o=n.getNodeType(t),a=typeof i<"u"?i.getNodeType(t):null;if(o==="void"||a==="void")return"void";if(s==="%")return o;if(s==="~"||s==="&"||s==="|"||s==="^"||s===">>"||s==="<<")return t.getIntegerType(o);if(s==="!"||s==="=="||s==="&&"||s==="||"||s==="^^")return"bool";if(s==="<"||s===">"||s==="<="||s===">="){const c=e?t.getTypeLength(e):Math.max(t.getTypeLength(o),t.getTypeLength(a));return c>1?`bvec${c}`:"bool"}else return o==="float"&&t.isMatrix(a)?a:t.isMatrix(o)&&t.isVector(a)?t.getVectorFromMatrix(o):t.isVector(o)&&t.isMatrix(a)?t.getVectorFromMatrix(a):t.getTypeLength(a)>t.getTypeLength(o)?a:o}generate(t,e){const s=this.op,n=this.aNode,i=this.bNode,o=this.getNodeType(t,e);let a=null,c=null;o!=="void"?(a=n.getNodeType(t),c=typeof i<"u"?i.getNodeType(t):null,s==="<"||s===">"||s==="<="||s===">="||s==="=="?t.isVector(a)?c=a:a!==c&&(a=c="float"):s===">>"||s==="<<"?(a=o,c=t.changeComponentType(c,"uint")):t.isMatrix(a)&&t.isVector(c)?c=t.getVectorFromMatrix(a):t.isVector(a)&&t.isMatrix(c)?a=t.getVectorFromMatrix(c):a=c=o):a=c=o;const u=n.build(t,a),h=typeof i<"u"?i.build(t,c):null,l=t.getTypeLength(e),d=t.getFunctionOperator(s);if(e!=="void")return s==="<"&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("lessThan",e)}( ${u}, ${h} )`,o,e):t.format(`( ${u} < ${h} )`,o,e):s==="<="&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("lessThanEqual",e)}( ${u}, ${h} )`,o,e):t.format(`( ${u} <= ${h} )`,o,e):s===">"&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("greaterThan",e)}( ${u}, ${h} )`,o,e):t.format(`( ${u} > ${h} )`,o,e):s===">="&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("greaterThanEqual",e)}( ${u}, ${h} )`,o,e):t.format(`( ${u} >= ${h} )`,o,e):s==="!"||s==="~"?t.format(`(${s}${u})`,a,e):d?t.format(`${d}( ${u}, ${h} )`,o,e):t.format(`( ${u} ${s} ${h} )`,o,e);if(a!=="void")return d?t.format(`${d}( ${u}, ${h} )`,o,e):t.format(`${u} ${s} ${h}`,o,e)}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}}const ge=B(Y,"+"),qs=B(Y,"-"),$s=B(Y,"*"),xr=B(Y,"/"),Tr=B(Y,"%"),$a=B(Y,"=="),Wa=B(Y,"!="),Ga=B(Y,"<"),Xa=B(Y,">"),Ya=B(Y,"<="),Za=B(Y,">="),Ja=B(Y,"&&"),Qa=B(Y,"||"),ja=B(Y,"!"),Ka=B(Y,"^^"),tc=B(Y,"&"),ec=B(Y,"~"),sc=B(Y,"|"),nc=B(Y,"^"),ic=B(Y,"<<"),rc=B(Y,">>");E("add",ge),E("sub",qs),E("mul",$s),E("div",xr),E("modInt",Tr),E("equal",$a),E("notEqual",Wa),E("lessThan",Ga),E("greaterThan",Xa),E("lessThanEqual",Ya),E("greaterThanEqual",Za),E("and",Ja),E("or",Qa),E("not",ja),E("xor",Ka),E("bitAnd",tc),E("bitNot",ec),E("bitOr",sc),E("bitXor",nc),E("shiftLeft",ic),E("shiftRight",rc),E("remainder",(...r)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),Tr(...r)));class T extends pt{static get type(){return"MathNode"}constructor(t,e,s=null,n=null){super(),this.method=t,this.aNode=e,this.bNode=s,this.cNode=n}getInputType(t){const e=this.aNode.getNodeType(t),s=this.bNode?this.bNode.getNodeType(t):null,n=this.cNode?this.cNode.getNodeType(t):null,i=t.isMatrix(e)?0:t.getTypeLength(e),o=t.isMatrix(s)?0:t.getTypeLength(s),a=t.isMatrix(n)?0:t.getTypeLength(n);return i>o&&i>a?e:o>a?s:a>i?n:e}getNodeType(t){const e=this.method;return e===T.LENGTH||e===T.DISTANCE||e===T.DOT?"float":e===T.CROSS?"vec3":e===T.ALL?"bool":e===T.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):e===T.MOD?this.aNode.getNodeType(t):this.getInputType(t)}generate(t,e){const s=this.method,n=this.getNodeType(t),i=this.getInputType(t),o=this.aNode,a=this.bNode,c=this.cNode,u=t.renderer.isWebGLRenderer===!0;if(s===T.TRANSFORM_DIRECTION){let h=o,l=a;t.isMatrix(h.getNodeType(t))?l=Le(H(l),0):h=Le(H(h),0);const d=$s(h,l).xyz;return Nr(d).build(t,e)}else{if(s===T.NEGATE)return t.format("( - "+o.build(t,i)+" )",n,e);if(s===T.ONE_MINUS)return qs(1,o).build(t,e);if(s===T.RECIPROCAL)return xr(1,o).build(t,e);if(s===T.DIFFERENCE)return ti(qs(o,a)).build(t,e);{const h=[];return s===T.CROSS||s===T.MOD?h.push(o.build(t,n),a.build(t,n)):u&&s===T.STEP?h.push(o.build(t,t.getTypeLength(o.getNodeType(t))===1?"float":i),a.build(t,i)):u&&(s===T.MIN||s===T.MAX)||s===T.MOD?h.push(o.build(t,i),a.build(t,t.getTypeLength(a.getNodeType(t))===1?"float":i)):s===T.REFRACT?h.push(o.build(t,i),a.build(t,i),c.build(t,"float")):s===T.MIX?h.push(o.build(t,i),a.build(t,i),c.build(t,t.getTypeLength(c.getNodeType(t))===1?"float":i)):(h.push(o.build(t,i)),a!==null&&h.push(a.build(t,i)),c!==null&&h.push(c.build(t,i))),t.format(`${t.getMethod(s,n)}( ${h.join(", ")} )`,n,e)}}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}T.ALL="all",T.ANY="any",T.EQUALS="equals",T.RADIANS="radians",T.DEGREES="degrees",T.EXP="exp",T.EXP2="exp2",T.LOG="log",T.LOG2="log2",T.SQRT="sqrt",T.INVERSE_SQRT="inversesqrt",T.FLOOR="floor",T.CEIL="ceil",T.NORMALIZE="normalize",T.FRACT="fract",T.SIN="sin",T.COS="cos",T.TAN="tan",T.ASIN="asin",T.ACOS="acos",T.ATAN="atan",T.ABS="abs",T.SIGN="sign",T.LENGTH="length",T.NEGATE="negate",T.ONE_MINUS="oneMinus",T.DFDX="dFdx",T.DFDY="dFdy",T.ROUND="round",T.RECIPROCAL="reciprocal",T.TRUNC="trunc",T.FWIDTH="fwidth",T.BITCAST="bitcast",T.TRANSPOSE="transpose",T.ATAN2="atan2",T.MIN="min",T.MAX="max",T.MOD="mod",T.STEP="step",T.REFLECT="reflect",T.DISTANCE="distance",T.DIFFERENCE="difference",T.DOT="dot",T.CROSS="cross",T.POW="pow",T.TRANSFORM_DIRECTION="transformDirection",T.MIX="mix",T.CLAMP="clamp",T.REFRACT="refract",T.SMOOTHSTEP="smoothstep",T.FACEFORWARD="faceforward";const oc=$(Math.PI),ac=B(T,T.ALL),cc=B(T,T.ANY),hc=B(T,T.EQUALS),uc=B(T,T.RADIANS),lc=B(T,T.DEGREES),dc=B(T,T.EXP),pc=B(T,T.EXP2),fc=B(T,T.LOG),mc=B(T,T.LOG2),jn=B(T,T.SQRT),yc=B(T,T.INVERSE_SQRT),gc=B(T,T.FLOOR),xc=B(T,T.CEIL),Nr=B(T,T.NORMALIZE),Kn=B(T,T.FRACT),wr=B(T,T.SIN),Tc=B(T,T.COS),Nc=B(T,T.TAN),wc=B(T,T.ASIN),Ac=B(T,T.ACOS),Sc=B(T,T.ATAN),ti=B(T,T.ABS),Ar=B(T,T.SIGN),Mc=B(T,T.LENGTH),_c=B(T,T.NEGATE),zc=B(T,T.ONE_MINUS),bc=B(T,T.DFDX),Ec=B(T,T.DFDY),Cc=B(T,T.ROUND),Fc=B(T,T.RECIPROCAL),Rc=B(T,T.TRUNC),Bc=B(T,T.FWIDTH);T.BITCAST;const Ic=B(T,T.TRANSPOSE),Pc=B(T,T.ATAN2),vc=B(T,T.MIN),ei=B(T,T.MAX),Sr=B(T,T.MOD),Mr=B(T,T.STEP),Lc=B(T,T.REFLECT),Oc=B(T,T.DISTANCE),Dc=B(T,T.DIFFERENCE),si=B(T,T.DOT),Vc=B(T,T.CROSS),_r=B(T,T.POW),Uc=B(T,T.POW,2),kc=B(T,T.POW,3),Hc=B(T,T.POW,4),qc=B(T,T.TRANSFORM_DIRECTION),$c=r=>$s(Ar(r),_r(ti(r),1/3)),Wc=r=>si(r,r),ae=B(T,T.MIX),Ws=(r,t=0,e=1)=>v(new T(T.CLAMP,v(r),v(t),v(e))),Gc=r=>Ws(r),Xc=B(T,T.REFRACT),ni=B(T,T.SMOOTHSTEP),Yc=B(T,T.FACEFORWARD),Zc=tt(([r])=>{const s=43758.5453,n=si(r.xy,V(12.9898,78.233)),i=Sr(n,oc);return Kn(wr(i).mul(s))}),Jc=(r,t,e)=>ae(t,e,r),Qc=(r,t,e)=>ni(t,e,r);E("all",ac),E("any",cc),E("equals",hc),E("radians",uc),E("degrees",lc),E("exp",dc),E("exp2",pc),E("log",fc),E("log2",mc),E("sqrt",jn),E("inverseSqrt",yc),E("floor",gc),E("ceil",xc),E("normalize",Nr),E("fract",Kn),E("sin",wr),E("cos",Tc),E("tan",Nc),E("asin",wc),E("acos",Ac),E("atan",Sc),E("abs",ti),E("sign",Ar),E("length",Mc),E("lengthSq",Wc),E("negate",_c),E("oneMinus",zc),E("dFdx",bc),E("dFdy",Ec),E("round",Cc),E("reciprocal",Fc),E("trunc",Rc),E("fwidth",Bc),E("atan2",Pc),E("min",vc),E("max",ei),E("mod",Sr),E("step",Mr),E("reflect",Lc),E("distance",Oc),E("dot",si),E("cross",Vc),E("pow",_r),E("pow2",Uc),E("pow3",kc),E("pow4",Hc),E("transformDirection",qc),E("mix",Jc),E("clamp",Ws),E("refract",Xc),E("smoothstep",Qc),E("faceForward",Yc),E("difference",Dc),E("saturate",Gc),E("cbrt",$c),E("transpose",Ic),E("rand",Zc);class jc extends U{static get type(){return"ConditionalNode"}constructor(t,e,s=null){super(),this.condNode=t,this.ifNode=e,this.elseNode=s}getNodeType(t){const e=this.ifNode.getNodeType(t);if(this.elseNode!==null){const s=this.elseNode.getNodeType(t);if(t.getTypeLength(s)>t.getTypeLength(e))return s}return e}setup(t){const e=this.condNode.cache(),s=this.ifNode.cache(),n=this.elseNode?this.elseNode.cache():null,i=t.context.nodeBlock;t.getDataFromNode(s).parentNodeBlock=i,n!==null&&(t.getDataFromNode(n).parentNodeBlock=i);const o=t.getNodeProperties(this);o.condNode=e,o.ifNode=s.context({nodeBlock:s}),o.elseNode=n?n.context({nodeBlock:n}):null}generate(t,e){const s=this.getNodeType(t),n=t.getDataFromNode(this);if(n.nodeProperty!==void 0)return n.nodeProperty;const{condNode:i,ifNode:o,elseNode:a}=t.getNodeProperties(this),c=e!=="void",u=c?De(s).build(t):"";n.nodeProperty=u;const h=i.build(t,"bool");t.addFlowCode(`
|
|
1
|
+
(function(){"use strict";const Wt="srgb",Es="srgb-linear",go="display-p3",vi="display-p3-linear",Tn="linear",Li="srgb",Oi="rec709";class ts{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const s=this._listeners;s[t]===void 0&&(s[t]=[]),s[t].indexOf(e)===-1&&s[t].push(e)}hasEventListener(t,e){if(this._listeners===void 0)return!1;const s=this._listeners;return s[t]!==void 0&&s[t].indexOf(e)!==-1}removeEventListener(t,e){if(this._listeners===void 0)return;const n=this._listeners[t];if(n!==void 0){const i=n.indexOf(e);i!==-1&&n.splice(i,1)}}dispatchEvent(t){if(this._listeners===void 0)return;const s=this._listeners[t.type];if(s!==void 0){t.target=this;const n=s.slice(0);for(let i=0,o=n.length;i<o;i++)n[i].call(this,t);t.target=null}}}const ut=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let Di=1234567;const Vi=Math.PI/180,Ui=180/Math.PI;function ee(){const r=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,s=Math.random()*4294967295|0;return(ut[r&255]+ut[r>>8&255]+ut[r>>16&255]+ut[r>>24&255]+"-"+ut[t&255]+ut[t>>8&255]+"-"+ut[t>>16&15|64]+ut[t>>24&255]+"-"+ut[e&63|128]+ut[e>>8&255]+"-"+ut[e>>16&255]+ut[e>>24&255]+ut[s&255]+ut[s>>8&255]+ut[s>>16&255]+ut[s>>24&255]).toLowerCase()}function lt(r,t,e){return Math.max(t,Math.min(e,r))}function Nn(r,t){return(r%t+t)%t}function xo(r,t,e,s,n){return s+(r-t)*(n-s)/(e-t)}function To(r,t,e){return r!==t?(e-r)/(t-r):0}function es(r,t,e){return(1-e)*r+e*t}function No(r,t,e,s){return es(r,t,1-Math.exp(-e*s))}function wo(r,t=1){return t-Math.abs(Nn(r,t*2)-t)}function Ao(r,t,e){return r<=t?0:r>=e?1:(r=(r-t)/(e-t),r*r*(3-2*r))}function So(r,t,e){return r<=t?0:r>=e?1:(r=(r-t)/(e-t),r*r*r*(r*(r*6-15)+10))}function Mo(r,t){return r+Math.floor(Math.random()*(t-r+1))}function _o(r,t){return r+Math.random()*(t-r)}function zo(r){return r*(.5-Math.random())}function bo(r){r!==void 0&&(Di=r);let t=Di+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function Eo(r){return r*Vi}function Co(r){return r*Ui}function Fo(r){return(r&r-1)===0&&r!==0}function Bo(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function Ro(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function Io(r,t,e,s,n){const i=Math.cos,o=Math.sin,a=i(e/2),c=o(e/2),u=i((t+s)/2),h=o((t+s)/2),l=i((t-s)/2),d=o((t-s)/2),f=i((s-t)/2),p=o((s-t)/2);switch(n){case"XYX":r.set(a*h,c*l,c*d,a*u);break;case"YZY":r.set(c*d,a*h,c*l,a*u);break;case"ZXZ":r.set(c*l,c*d,a*h,a*u);break;case"XZX":r.set(a*h,c*p,c*f,a*u);break;case"YXY":r.set(c*f,a*h,c*p,a*u);break;case"ZYZ":r.set(c*p,c*f,a*h,a*u);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+n)}}function Bt(r,t){switch(t.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("Invalid component type.")}}function $(r,t){switch(t.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("Invalid component type.")}}const Po={DEG2RAD:Vi,RAD2DEG:Ui,generateUUID:ee,clamp:lt,euclideanModulo:Nn,mapLinear:xo,inverseLerp:To,lerp:es,damp:No,pingpong:wo,smoothstep:Ao,smootherstep:So,randInt:Mo,randFloat:_o,randFloatSpread:zo,seededRandom:bo,degToRad:Eo,radToDeg:Co,isPowerOfTwo:Fo,ceilPowerOfTwo:Bo,floorPowerOfTwo:Ro,setQuaternionFromProperEuler:Io,normalize:$,denormalize:Bt};class Z{constructor(t=0,e=0){Z.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,s=this.y,n=t.elements;return this.x=n[0]*e+n[3]*s+n[6],this.y=n[1]*e+n[4]*s+n[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(lt(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y;return e*e+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const s=Math.cos(e),n=Math.sin(e),i=this.x-t.x,o=this.y-t.y;return this.x=i*s-o*n+t.x,this.y=i*n+o*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Rt{constructor(t,e,s,n,i,o,a,c,u){Rt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,s,n,i,o,a,c,u)}set(t,e,s,n,i,o,a,c,u){const h=this.elements;return h[0]=t,h[1]=n,h[2]=a,h[3]=e,h[4]=i,h[5]=c,h[6]=s,h[7]=o,h[8]=u,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],this}extractBasis(t,e,s){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),s.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,n=e.elements,i=this.elements,o=s[0],a=s[3],c=s[6],u=s[1],h=s[4],l=s[7],d=s[2],f=s[5],p=s[8],m=n[0],T=n[3],A=n[6],g=n[1],N=n[4],x=n[7],y=n[2],M=n[5],S=n[8];return i[0]=o*m+a*g+c*y,i[3]=o*T+a*N+c*M,i[6]=o*A+a*x+c*S,i[1]=u*m+h*g+l*y,i[4]=u*T+h*N+l*M,i[7]=u*A+h*x+l*S,i[2]=d*m+f*g+p*y,i[5]=d*T+f*N+p*M,i[8]=d*A+f*x+p*S,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[1],n=t[2],i=t[3],o=t[4],a=t[5],c=t[6],u=t[7],h=t[8];return e*o*h-e*a*u-s*i*h+s*a*c+n*i*u-n*o*c}invert(){const t=this.elements,e=t[0],s=t[1],n=t[2],i=t[3],o=t[4],a=t[5],c=t[6],u=t[7],h=t[8],l=h*o-a*u,d=a*c-h*i,f=u*i-o*c,p=e*l+s*d+n*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/p;return t[0]=l*m,t[1]=(n*u-h*s)*m,t[2]=(a*s-n*o)*m,t[3]=d*m,t[4]=(h*e-n*c)*m,t[5]=(n*i-a*e)*m,t[6]=f*m,t[7]=(s*c-u*e)*m,t[8]=(o*e-s*i)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,s,n,i,o,a){const c=Math.cos(i),u=Math.sin(i);return this.set(s*c,s*u,-s*(c*o+u*a)+o+t,-n*u,n*c,-n*(-u*o+c*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(wn.makeScale(t,e)),this}rotate(t){return this.premultiply(wn.makeRotation(-t)),this}translate(t,e){return this.premultiply(wn.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,s,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,s=t.elements;for(let n=0;n<9;n++)if(e[n]!==s[n])return!1;return!0}fromArray(t,e=0){for(let s=0;s<9;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const wn=new Rt;function vo(r){for(let t=r.length-1;t>=0;--t)if(r[t]>=65535)return!0;return!1}function ki(r){return document.createElementNS("http://www.w3.org/1999/xhtml",r)}const Hi=new Rt().set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),qi=new Rt().set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),ss={[Es]:{transfer:Tn,primaries:Oi,luminanceCoefficients:[.2126,.7152,.0722],toReference:r=>r,fromReference:r=>r},[Wt]:{transfer:Li,primaries:Oi,luminanceCoefficients:[.2126,.7152,.0722],toReference:r=>r.convertSRGBToLinear(),fromReference:r=>r.convertLinearToSRGB()},[vi]:{transfer:Tn,primaries:"p3",luminanceCoefficients:[.2289,.6917,.0793],toReference:r=>r.applyMatrix3(qi),fromReference:r=>r.applyMatrix3(Hi)},[go]:{transfer:Li,primaries:"p3",luminanceCoefficients:[.2289,.6917,.0793],toReference:r=>r.convertSRGBToLinear().applyMatrix3(qi),fromReference:r=>r.applyMatrix3(Hi).convertLinearToSRGB()}},Lo=new Set([Es,vi]),Tt={enabled:!0,_workingColorSpace:Es,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(r){if(!Lo.has(r))throw new Error(`Unsupported working color space, "${r}".`);this._workingColorSpace=r},convert:function(r,t,e){if(this.enabled===!1||t===e||!t||!e)return r;const s=ss[t].toReference,n=ss[e].fromReference;return n(s(r))},fromWorkingColorSpace:function(r,t){return this.convert(r,this._workingColorSpace,t)},toWorkingColorSpace:function(r,t){return this.convert(r,t,this._workingColorSpace)},getPrimaries:function(r){return ss[r].primaries},getTransfer:function(r){return r===""?Tn:ss[r].transfer},getLuminanceCoefficients:function(r,t=this._workingColorSpace){return r.fromArray(ss[t].luminanceCoefficients)}};function _e(r){return r<.04045?r*.0773993808:Math.pow(r*.9478672986+.0521327014,2.4)}function An(r){return r<.0031308?r*12.92:1.055*Math.pow(r,.41666)-.055}let ze;class Oo{static getDataURL(t){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{ze===void 0&&(ze=ki("canvas")),ze.width=t.width,ze.height=t.height;const s=ze.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),e=ze}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=ki("canvas");e.width=t.width,e.height=t.height;const s=e.getContext("2d");s.drawImage(t,0,0,t.width,t.height);const n=s.getImageData(0,0,t.width,t.height),i=n.data;for(let o=0;o<i.length;o++)i[o]=_e(i[o]/255)*255;return s.putImageData(n,0,0),e}else if(t.data){const e=t.data.slice(0);for(let s=0;s<e.length;s++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[s]=Math.floor(_e(e[s]/255)*255):e[s]=_e(e[s]);return{data:e,width:t.width,height:t.height}}else return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let Do=0;class $i{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Do++}),this.uuid=ee(),this.data=t,this.dataReady=!0,this.version=0}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const s={uuid:this.uuid,url:""},n=this.data;if(n!==null){let i;if(Array.isArray(n)){i=[];for(let o=0,a=n.length;o<a;o++)n[o].isDataTexture?i.push(Sn(n[o].image)):i.push(Sn(n[o]))}else i=Sn(n);s.url=i}return e||(t.images[this.uuid]=s),s}}function Sn(r){return typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&r instanceof ImageBitmap?Oo.getDataURL(r):r.data?{data:Array.from(r.data),width:r.width,height:r.height,type:r.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}let Vo=0;class kt extends ts{constructor(t=kt.DEFAULT_IMAGE,e=kt.DEFAULT_MAPPING,s=1001,n=1001,i=1006,o=1008,a=1023,c=1009,u=kt.DEFAULT_ANISOTROPY,h=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Vo++}),this.uuid=ee(),this.name="",this.source=new $i(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=s,this.wrapT=n,this.magFilter=i,this.minFilter=o,this.anisotropy=u,this.format=a,this.internalFormat=null,this.type=c,this.offset=new Z(0,0),this.repeat=new Z(1,1),this.center=new Z(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Rt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1,this.pmremVersion=0}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const s={metadata:{version:4.6,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(s.userData=this.userData),e||(t.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==300)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case 1e3:t.x=t.x-Math.floor(t.x);break;case 1001:t.x=t.x<0?0:1;break;case 1002:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case 1e3:t.y=t.y-Math.floor(t.y);break;case 1001:t.y=t.y<0?0:1;break;case 1002:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}kt.DEFAULT_IMAGE=null,kt.DEFAULT_MAPPING=300,kt.DEFAULT_ANISOTROPY=4;class It{constructor(t=0,e=0,s=0,n=1){It.prototype.isVector4=!0,this.x=t,this.y=e,this.z=s,this.w=n}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,s,n){return this.x=t,this.y=e,this.z=s,this.w=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,s=this.y,n=this.z,i=this.w,o=t.elements;return this.x=o[0]*e+o[4]*s+o[8]*n+o[12]*i,this.y=o[1]*e+o[5]*s+o[9]*n+o[13]*i,this.z=o[2]*e+o[6]*s+o[10]*n+o[14]*i,this.w=o[3]*e+o[7]*s+o[11]*n+o[15]*i,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,s,n,i;const c=t.elements,u=c[0],h=c[4],l=c[8],d=c[1],f=c[5],p=c[9],m=c[2],T=c[6],A=c[10];if(Math.abs(h-d)<.01&&Math.abs(l-m)<.01&&Math.abs(p-T)<.01){if(Math.abs(h+d)<.1&&Math.abs(l+m)<.1&&Math.abs(p+T)<.1&&Math.abs(u+f+A-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const N=(u+1)/2,x=(f+1)/2,y=(A+1)/2,M=(h+d)/4,S=(l+m)/4,z=(p+T)/4;return N>x&&N>y?N<.01?(s=0,n=.707106781,i=.707106781):(s=Math.sqrt(N),n=M/s,i=S/s):x>y?x<.01?(s=.707106781,n=0,i=.707106781):(n=Math.sqrt(x),s=M/n,i=z/n):y<.01?(s=.707106781,n=.707106781,i=0):(i=Math.sqrt(y),s=S/i,n=z/i),this.set(s,n,i,e),this}let g=Math.sqrt((T-p)*(T-p)+(l-m)*(l-m)+(d-h)*(d-h));return Math.abs(g)<.001&&(g=1),this.x=(T-p)/g,this.y=(l-m)/g,this.z=(d-h)/g,this.w=Math.acos((u+f+A-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this.w=t.w+(e.w-t.w)*s,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class Wi extends ts{constructor(t=1,e=1,s={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new It(0,0,t,e),this.scissorTest=!1,this.viewport=new It(0,0,t,e);const n={width:t,height:e,depth:1};s=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:1006,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},s);const i=new kt(n,s.mapping,s.wrapS,s.wrapT,s.magFilter,s.minFilter,s.format,s.type,s.anisotropy,s.colorSpace);i.flipY=!1,i.generateMipmaps=s.generateMipmaps,i.internalFormat=s.internalFormat,this.textures=[];const o=s.count;for(let a=0;a<o;a++)this.textures[a]=i.clone(),this.textures[a].isRenderTargetTexture=!0;this.depthBuffer=s.depthBuffer,this.stencilBuffer=s.stencilBuffer,this.resolveDepthBuffer=s.resolveDepthBuffer,this.resolveStencilBuffer=s.resolveStencilBuffer,this.depthTexture=s.depthTexture,this.samples=s.samples}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}setSize(t,e,s=1){if(this.width!==t||this.height!==e||this.depth!==s){this.width=t,this.height=e,this.depth=s;for(let n=0,i=this.textures.length;n<i;n++)this.textures[n].image.width=t,this.textures[n].image.height=e,this.textures[n].image.depth=s;this.dispose()}this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return new this.constructor().copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.textures.length=0;for(let s=0,n=t.textures.length;s<n;s++)this.textures[s]=t.textures[s].clone(),this.textures[s].isRenderTargetTexture=!0;const e=Object.assign({},t.texture.image);return this.texture.source=new $i(e),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.resolveDepthBuffer=t.resolveDepthBuffer,this.resolveStencilBuffer=t.resolveStencilBuffer,t.depthTexture!==null&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class ns{constructor(t=0,e=0,s=0,n=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=s,this._w=n}static slerpFlat(t,e,s,n,i,o,a){let c=s[n+0],u=s[n+1],h=s[n+2],l=s[n+3];const d=i[o+0],f=i[o+1],p=i[o+2],m=i[o+3];if(a===0){t[e+0]=c,t[e+1]=u,t[e+2]=h,t[e+3]=l;return}if(a===1){t[e+0]=d,t[e+1]=f,t[e+2]=p,t[e+3]=m;return}if(l!==m||c!==d||u!==f||h!==p){let T=1-a;const A=c*d+u*f+h*p+l*m,g=A>=0?1:-1,N=1-A*A;if(N>Number.EPSILON){const y=Math.sqrt(N),M=Math.atan2(y,A*g);T=Math.sin(T*M)/y,a=Math.sin(a*M)/y}const x=a*g;if(c=c*T+d*x,u=u*T+f*x,h=h*T+p*x,l=l*T+m*x,T===1-a){const y=1/Math.sqrt(c*c+u*u+h*h+l*l);c*=y,u*=y,h*=y,l*=y}}t[e]=c,t[e+1]=u,t[e+2]=h,t[e+3]=l}static multiplyQuaternionsFlat(t,e,s,n,i,o){const a=s[n],c=s[n+1],u=s[n+2],h=s[n+3],l=i[o],d=i[o+1],f=i[o+2],p=i[o+3];return t[e]=a*p+h*l+c*f-u*d,t[e+1]=c*p+h*d+u*l-a*f,t[e+2]=u*p+h*f+a*d-c*l,t[e+3]=h*p-a*l-c*d-u*f,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,s,n){return this._x=t,this._y=e,this._z=s,this._w=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const s=t._x,n=t._y,i=t._z,o=t._order,a=Math.cos,c=Math.sin,u=a(s/2),h=a(n/2),l=a(i/2),d=c(s/2),f=c(n/2),p=c(i/2);switch(o){case"XYZ":this._x=d*h*l+u*f*p,this._y=u*f*l-d*h*p,this._z=u*h*p+d*f*l,this._w=u*h*l-d*f*p;break;case"YXZ":this._x=d*h*l+u*f*p,this._y=u*f*l-d*h*p,this._z=u*h*p-d*f*l,this._w=u*h*l+d*f*p;break;case"ZXY":this._x=d*h*l-u*f*p,this._y=u*f*l+d*h*p,this._z=u*h*p+d*f*l,this._w=u*h*l-d*f*p;break;case"ZYX":this._x=d*h*l-u*f*p,this._y=u*f*l+d*h*p,this._z=u*h*p-d*f*l,this._w=u*h*l+d*f*p;break;case"YZX":this._x=d*h*l+u*f*p,this._y=u*f*l+d*h*p,this._z=u*h*p-d*f*l,this._w=u*h*l-d*f*p;break;case"XZY":this._x=d*h*l-u*f*p,this._y=u*f*l-d*h*p,this._z=u*h*p+d*f*l,this._w=u*h*l+d*f*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+o)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,n=Math.sin(s);return this._x=t.x*n,this._y=t.y*n,this._z=t.z*n,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],n=e[4],i=e[8],o=e[1],a=e[5],c=e[9],u=e[2],h=e[6],l=e[10],d=s+a+l;if(d>0){const f=.5/Math.sqrt(d+1);this._w=.25/f,this._x=(h-c)*f,this._y=(i-u)*f,this._z=(o-n)*f}else if(s>a&&s>l){const f=2*Math.sqrt(1+s-a-l);this._w=(h-c)/f,this._x=.25*f,this._y=(n+o)/f,this._z=(i+u)/f}else if(a>l){const f=2*Math.sqrt(1+a-s-l);this._w=(i-u)/f,this._x=(n+o)/f,this._y=.25*f,this._z=(c+h)/f}else{const f=2*Math.sqrt(1+l-s-a);this._w=(o-n)/f,this._x=(i+u)/f,this._y=(c+h)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return s<Number.EPSILON?(s=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(lt(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(s===0)return this;const n=Math.min(1,e/s);return this.slerp(t,n),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const s=t._x,n=t._y,i=t._z,o=t._w,a=e._x,c=e._y,u=e._z,h=e._w;return this._x=s*h+o*a+n*u-i*c,this._y=n*h+o*c+i*a-s*u,this._z=i*h+o*u+s*c-n*a,this._w=o*h-s*a-n*c-i*u,this._onChangeCallback(),this}slerp(t,e){if(e===0)return this;if(e===1)return this.copy(t);const s=this._x,n=this._y,i=this._z,o=this._w;let a=o*t._w+s*t._x+n*t._y+i*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=o,this._x=s,this._y=n,this._z=i,this;const c=1-a*a;if(c<=Number.EPSILON){const f=1-e;return this._w=f*o+e*this._w,this._x=f*s+e*this._x,this._y=f*n+e*this._y,this._z=f*i+e*this._z,this.normalize(),this}const u=Math.sqrt(c),h=Math.atan2(u,a),l=Math.sin((1-e)*h)/u,d=Math.sin(e*h)/u;return this._w=o*l+this._w*d,this._x=s*l+this._x*d,this._y=n*l+this._y*d,this._z=i*l+this._z*d,this._onChangeCallback(),this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),n=Math.sqrt(1-s),i=Math.sqrt(s);return this.set(n*Math.sin(t),n*Math.cos(t),i*Math.sin(e),i*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class _{constructor(t=0,e=0,s=0){_.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return s===void 0&&(s=this.z),this.x=t,this.y=e,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(Gi.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Gi.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,n=this.z,i=t.elements;return this.x=i[0]*e+i[3]*s+i[6]*n,this.y=i[1]*e+i[4]*s+i[7]*n,this.z=i[2]*e+i[5]*s+i[8]*n,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,n=this.z,i=t.elements,o=1/(i[3]*e+i[7]*s+i[11]*n+i[15]);return this.x=(i[0]*e+i[4]*s+i[8]*n+i[12])*o,this.y=(i[1]*e+i[5]*s+i[9]*n+i[13])*o,this.z=(i[2]*e+i[6]*s+i[10]*n+i[14])*o,this}applyQuaternion(t){const e=this.x,s=this.y,n=this.z,i=t.x,o=t.y,a=t.z,c=t.w,u=2*(o*n-a*s),h=2*(a*e-i*n),l=2*(i*s-o*e);return this.x=e+c*u+o*l-a*h,this.y=s+c*h+a*u-i*l,this.z=n+c*l+i*h-o*u,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,n=this.z,i=t.elements;return this.x=i[0]*e+i[4]*s+i[8]*n,this.y=i[1]*e+i[5]*s+i[9]*n,this.z=i[2]*e+i[6]*s+i[10]*n,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,n=t.y,i=t.z,o=e.x,a=e.y,c=e.z;return this.x=n*c-i*a,this.y=i*o-s*c,this.z=s*a-n*o,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return Mn.copy(this).projectOnVector(t),this.sub(Mn)}reflect(t){return this.sub(Mn.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(lt(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,n=this.z-t.z;return e*e+s*s+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,s){const n=Math.sin(e)*t;return this.x=n*Math.sin(s),this.y=Math.cos(e)*t,this.z=n*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),n=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=n,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Mn=new _,Gi=new ns;class ft{constructor(t=new _(1/0,1/0,1/0),e=new _(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,s=t.length;e<s;e+=3)this.expandByPoint(Pt.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,s=t.count;e<s;e++)this.expandByPoint(Pt.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,s=t.length;e<s;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const s=Pt.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(s),this.max.copy(t).add(s),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}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=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,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}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const s=t.geometry;if(s!==void 0){const i=s.getAttribute("position");if(e===!0&&i!==void 0&&t.isInstancedMesh!==!0)for(let o=0,a=i.count;o<a;o++)t.isMesh===!0?t.getVertexPosition(o,Pt):Pt.fromBufferAttribute(i,o),Pt.applyMatrix4(t.matrixWorld),this.expandByPoint(Pt);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Cs.copy(t.boundingBox)):(s.boundingBox===null&&s.computeBoundingBox(),Cs.copy(s.boundingBox)),Cs.applyMatrix4(t.matrixWorld),this.union(Cs)}const n=t.children;for(let i=0,o=n.length;i<o;i++)this.expandByObject(n[i],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}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&&this.min.z<=t.min.z&&t.max.z<=this.max.z}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),(t.z-this.min.z)/(this.max.z-this.min.z))}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&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,Pt),Pt.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,s;return t.normal.x>0?(e=t.normal.x*this.min.x,s=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,s=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,s+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,s+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,s+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,s+=t.normal.z*this.min.z),e<=-t.constant&&s>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(is),Fs.subVectors(this.max,is),be.subVectors(t.a,is),Ee.subVectors(t.b,is),Ce.subVectors(t.c,is),se.subVectors(Ee,be),ne.subVectors(Ce,Ee),pe.subVectors(be,Ce);let e=[0,-se.z,se.y,0,-ne.z,ne.y,0,-pe.z,pe.y,se.z,0,-se.x,ne.z,0,-ne.x,pe.z,0,-pe.x,-se.y,se.x,0,-ne.y,ne.x,0,-pe.y,pe.x,0];return!_n(e,be,Ee,Ce,Fs)||(e=[1,0,0,0,1,0,0,0,1],!_n(e,be,Ee,Ce,Fs))?!1:(Bs.crossVectors(se,ne),e=[Bs.x,Bs.y,Bs.z],_n(e,be,Ee,Ce,Fs))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Pt).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(Pt).length()*.5),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}applyMatrix4(t){return this.isEmpty()?this:(Gt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Gt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Gt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Gt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Gt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Gt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Gt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Gt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Gt),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)}}const Gt=[new _,new _,new _,new _,new _,new _,new _,new _],Pt=new _,Cs=new ft,be=new _,Ee=new _,Ce=new _,se=new _,ne=new _,pe=new _,is=new _,Fs=new _,Bs=new _,me=new _;function _n(r,t,e,s,n){for(let i=0,o=r.length-3;i<=o;i+=3){me.fromArray(r,i);const a=n.x*Math.abs(me.x)+n.y*Math.abs(me.y)+n.z*Math.abs(me.z),c=t.dot(me),u=e.dot(me),h=s.dot(me);if(Math.max(-Math.max(c,u,h),Math.min(c,u,h))>a)return!1}return!0}const Uo=new ft,rs=new _,zn=new _;class ko{constructor(t=new _,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const s=this.center;e!==void 0?s.copy(e):Uo.setFromPoints(t).getCenter(s);let n=0;for(let i=0,o=t.length;i<o;i++)n=Math.max(n,s.distanceToSquared(t[i]));return this.radius=Math.sqrt(n),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const s=this.center.distanceToSquared(t);return e.copy(t),s>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;rs.subVectors(t,this.center);const e=rs.lengthSq();if(e>this.radius*this.radius){const s=Math.sqrt(e),n=(s-this.radius)*.5;this.center.addScaledVector(rs,n/s),this.radius+=n}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(zn.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(rs.copy(t.center).add(zn)),this.expandByPoint(rs.copy(t.center).sub(zn))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}}class nt{constructor(t,e,s,n,i,o,a,c,u,h,l,d,f,p,m,T){nt.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,s,n,i,o,a,c,u,h,l,d,f,p,m,T)}set(t,e,s,n,i,o,a,c,u,h,l,d,f,p,m,T){const A=this.elements;return A[0]=t,A[4]=e,A[8]=s,A[12]=n,A[1]=i,A[5]=o,A[9]=a,A[13]=c,A[2]=u,A[6]=h,A[10]=l,A[14]=d,A[3]=f,A[7]=p,A[11]=m,A[15]=T,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new nt().fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,s){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,s=t.elements,n=1/Fe.setFromMatrixColumn(t,0).length(),i=1/Fe.setFromMatrixColumn(t,1).length(),o=1/Fe.setFromMatrixColumn(t,2).length();return e[0]=s[0]*n,e[1]=s[1]*n,e[2]=s[2]*n,e[3]=0,e[4]=s[4]*i,e[5]=s[5]*i,e[6]=s[6]*i,e[7]=0,e[8]=s[8]*o,e[9]=s[9]*o,e[10]=s[10]*o,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,n=t.y,i=t.z,o=Math.cos(s),a=Math.sin(s),c=Math.cos(n),u=Math.sin(n),h=Math.cos(i),l=Math.sin(i);if(t.order==="XYZ"){const d=o*h,f=o*l,p=a*h,m=a*l;e[0]=c*h,e[4]=-c*l,e[8]=u,e[1]=f+p*u,e[5]=d-m*u,e[9]=-a*c,e[2]=m-d*u,e[6]=p+f*u,e[10]=o*c}else if(t.order==="YXZ"){const d=c*h,f=c*l,p=u*h,m=u*l;e[0]=d+m*a,e[4]=p*a-f,e[8]=o*u,e[1]=o*l,e[5]=o*h,e[9]=-a,e[2]=f*a-p,e[6]=m+d*a,e[10]=o*c}else if(t.order==="ZXY"){const d=c*h,f=c*l,p=u*h,m=u*l;e[0]=d-m*a,e[4]=-o*l,e[8]=p+f*a,e[1]=f+p*a,e[5]=o*h,e[9]=m-d*a,e[2]=-o*u,e[6]=a,e[10]=o*c}else if(t.order==="ZYX"){const d=o*h,f=o*l,p=a*h,m=a*l;e[0]=c*h,e[4]=p*u-f,e[8]=d*u+m,e[1]=c*l,e[5]=m*u+d,e[9]=f*u-p,e[2]=-u,e[6]=a*c,e[10]=o*c}else if(t.order==="YZX"){const d=o*c,f=o*u,p=a*c,m=a*u;e[0]=c*h,e[4]=m-d*l,e[8]=p*l+f,e[1]=l,e[5]=o*h,e[9]=-a*h,e[2]=-u*h,e[6]=f*l+p,e[10]=d-m*l}else if(t.order==="XZY"){const d=o*c,f=o*u,p=a*c,m=a*u;e[0]=c*h,e[4]=-l,e[8]=u*h,e[1]=d*l+m,e[5]=o*h,e[9]=f*l-p,e[2]=p*l-f,e[6]=a*h,e[10]=m*l+d}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(Ho,t,qo)}lookAt(t,e,s){const n=this.elements;return Nt.subVectors(t,e),Nt.lengthSq()===0&&(Nt.z=1),Nt.normalize(),ie.crossVectors(s,Nt),ie.lengthSq()===0&&(Math.abs(s.z)===1?Nt.x+=1e-4:Nt.z+=1e-4,Nt.normalize(),ie.crossVectors(s,Nt)),ie.normalize(),Rs.crossVectors(Nt,ie),n[0]=ie.x,n[4]=Rs.x,n[8]=Nt.x,n[1]=ie.y,n[5]=Rs.y,n[9]=Nt.y,n[2]=ie.z,n[6]=Rs.z,n[10]=Nt.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,n=e.elements,i=this.elements,o=s[0],a=s[4],c=s[8],u=s[12],h=s[1],l=s[5],d=s[9],f=s[13],p=s[2],m=s[6],T=s[10],A=s[14],g=s[3],N=s[7],x=s[11],y=s[15],M=n[0],S=n[4],z=n[8],B=n[12],b=n[1],I=n[5],C=n[9],P=n[13],L=n[2],D=n[6],W=n[10],Ft=n[14],Se=n[3],Me=n[7],de=n[11],fe=n[15];return i[0]=o*M+a*b+c*L+u*Se,i[4]=o*S+a*I+c*D+u*Me,i[8]=o*z+a*C+c*W+u*de,i[12]=o*B+a*P+c*Ft+u*fe,i[1]=h*M+l*b+d*L+f*Se,i[5]=h*S+l*I+d*D+f*Me,i[9]=h*z+l*C+d*W+f*de,i[13]=h*B+l*P+d*Ft+f*fe,i[2]=p*M+m*b+T*L+A*Se,i[6]=p*S+m*I+T*D+A*Me,i[10]=p*z+m*C+T*W+A*de,i[14]=p*B+m*P+T*Ft+A*fe,i[3]=g*M+N*b+x*L+y*Se,i[7]=g*S+N*I+x*D+y*Me,i[11]=g*z+N*C+x*W+y*de,i[15]=g*B+N*P+x*Ft+y*fe,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[4],n=t[8],i=t[12],o=t[1],a=t[5],c=t[9],u=t[13],h=t[2],l=t[6],d=t[10],f=t[14],p=t[3],m=t[7],T=t[11],A=t[15];return p*(+i*c*l-n*u*l-i*a*d+s*u*d+n*a*f-s*c*f)+m*(+e*c*f-e*u*d+i*o*d-n*o*f+n*u*h-i*c*h)+T*(+e*u*l-e*a*f-i*o*l+s*o*f+i*a*h-s*u*h)+A*(-n*a*h-e*c*l+e*a*d+n*o*l-s*o*d+s*c*h)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,s){const n=this.elements;return t.isVector3?(n[12]=t.x,n[13]=t.y,n[14]=t.z):(n[12]=t,n[13]=e,n[14]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],n=t[2],i=t[3],o=t[4],a=t[5],c=t[6],u=t[7],h=t[8],l=t[9],d=t[10],f=t[11],p=t[12],m=t[13],T=t[14],A=t[15],g=l*T*u-m*d*u+m*c*f-a*T*f-l*c*A+a*d*A,N=p*d*u-h*T*u-p*c*f+o*T*f+h*c*A-o*d*A,x=h*m*u-p*l*u+p*a*f-o*m*f-h*a*A+o*l*A,y=p*l*c-h*m*c-p*a*d+o*m*d+h*a*T-o*l*T,M=e*g+s*N+n*x+i*y;if(M===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const S=1/M;return t[0]=g*S,t[1]=(m*d*i-l*T*i-m*n*f+s*T*f+l*n*A-s*d*A)*S,t[2]=(a*T*i-m*c*i+m*n*u-s*T*u-a*n*A+s*c*A)*S,t[3]=(l*c*i-a*d*i-l*n*u+s*d*u+a*n*f-s*c*f)*S,t[4]=N*S,t[5]=(h*T*i-p*d*i+p*n*f-e*T*f-h*n*A+e*d*A)*S,t[6]=(p*c*i-o*T*i-p*n*u+e*T*u+o*n*A-e*c*A)*S,t[7]=(o*d*i-h*c*i+h*n*u-e*d*u-o*n*f+e*c*f)*S,t[8]=x*S,t[9]=(p*l*i-h*m*i-p*s*f+e*m*f+h*s*A-e*l*A)*S,t[10]=(o*m*i-p*a*i+p*s*u-e*m*u-o*s*A+e*a*A)*S,t[11]=(h*a*i-o*l*i-h*s*u+e*l*u+o*s*f-e*a*f)*S,t[12]=y*S,t[13]=(h*m*n-p*l*n+p*s*d-e*m*d-h*s*T+e*l*T)*S,t[14]=(p*a*n-o*m*n-p*s*c+e*m*c+o*s*T-e*a*T)*S,t[15]=(o*l*n-h*a*n+h*s*c-e*l*c-o*s*d+e*a*d)*S,this}scale(t){const e=this.elements,s=t.x,n=t.y,i=t.z;return e[0]*=s,e[4]*=n,e[8]*=i,e[1]*=s,e[5]*=n,e[9]*=i,e[2]*=s,e[6]*=n,e[10]*=i,e[3]*=s,e[7]*=n,e[11]*=i,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],n=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,s,n))}makeTranslation(t,e,s){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),n=Math.sin(e),i=1-s,o=t.x,a=t.y,c=t.z,u=i*o,h=i*a;return this.set(u*o+s,u*a-n*c,u*c+n*a,0,u*a+n*c,h*a+s,h*c-n*o,0,u*c-n*a,h*c+n*o,i*c*c+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,n,i,o){return this.set(1,s,i,0,t,1,o,0,e,n,1,0,0,0,0,1),this}compose(t,e,s){const n=this.elements,i=e._x,o=e._y,a=e._z,c=e._w,u=i+i,h=o+o,l=a+a,d=i*u,f=i*h,p=i*l,m=o*h,T=o*l,A=a*l,g=c*u,N=c*h,x=c*l,y=s.x,M=s.y,S=s.z;return n[0]=(1-(m+A))*y,n[1]=(f+x)*y,n[2]=(p-N)*y,n[3]=0,n[4]=(f-x)*M,n[5]=(1-(d+A))*M,n[6]=(T+g)*M,n[7]=0,n[8]=(p+N)*S,n[9]=(T-g)*S,n[10]=(1-(d+m))*S,n[11]=0,n[12]=t.x,n[13]=t.y,n[14]=t.z,n[15]=1,this}decompose(t,e,s){const n=this.elements;let i=Fe.set(n[0],n[1],n[2]).length();const o=Fe.set(n[4],n[5],n[6]).length(),a=Fe.set(n[8],n[9],n[10]).length();this.determinant()<0&&(i=-i),t.x=n[12],t.y=n[13],t.z=n[14],vt.copy(this);const u=1/i,h=1/o,l=1/a;return vt.elements[0]*=u,vt.elements[1]*=u,vt.elements[2]*=u,vt.elements[4]*=h,vt.elements[5]*=h,vt.elements[6]*=h,vt.elements[8]*=l,vt.elements[9]*=l,vt.elements[10]*=l,e.setFromRotationMatrix(vt),s.x=i,s.y=o,s.z=a,this}makePerspective(t,e,s,n,i,o,a=2e3){const c=this.elements,u=2*i/(e-t),h=2*i/(s-n),l=(e+t)/(e-t),d=(s+n)/(s-n);let f,p;if(a===2e3)f=-(o+i)/(o-i),p=-2*o*i/(o-i);else if(a===2001)f=-o/(o-i),p=-o*i/(o-i);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=u,c[4]=0,c[8]=l,c[12]=0,c[1]=0,c[5]=h,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=f,c[14]=p,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(t,e,s,n,i,o,a=2e3){const c=this.elements,u=1/(e-t),h=1/(s-n),l=1/(o-i),d=(e+t)*u,f=(s+n)*h;let p,m;if(a===2e3)p=(o+i)*l,m=-2*l;else if(a===2001)p=i*l,m=-1*l;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=2*u,c[4]=0,c[8]=0,c[12]=-d,c[1]=0,c[5]=2*h,c[9]=0,c[13]=-f,c[2]=0,c[6]=0,c[10]=m,c[14]=-p,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let n=0;n<16;n++)if(e[n]!==s[n])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const Fe=new _,vt=new nt,Ho=new _(0,0,0),qo=new _(1,1,1),ie=new _,Rs=new _,Nt=new _,Xi=new nt,Yi=new ns;class Is{constructor(t=0,e=0,s=0,n=Is.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,this._order=n}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,s,n=this._order){return this._x=t,this._y=e,this._z=s,this._order=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,s=!0){const n=t.elements,i=n[0],o=n[4],a=n[8],c=n[1],u=n[5],h=n[9],l=n[2],d=n[6],f=n[10];switch(e){case"XYZ":this._y=Math.asin(lt(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,f),this._z=Math.atan2(-o,i)):(this._x=Math.atan2(d,u),this._z=0);break;case"YXZ":this._x=Math.asin(-lt(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,f),this._z=Math.atan2(c,u)):(this._y=Math.atan2(-l,i),this._z=0);break;case"ZXY":this._x=Math.asin(lt(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-l,f),this._z=Math.atan2(-o,u)):(this._y=0,this._z=Math.atan2(c,i));break;case"ZYX":this._y=Math.asin(-lt(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(c,i)):(this._x=0,this._z=Math.atan2(-o,u));break;case"YZX":this._z=Math.asin(lt(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-h,u),this._y=Math.atan2(-l,i)):(this._x=0,this._y=Math.atan2(a,f));break;case"XZY":this._z=Math.asin(-lt(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(d,u),this._y=Math.atan2(a,i)):(this._x=Math.atan2(-h,f),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,s===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return Xi.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Xi,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Yi.setFromEuler(this),this.setFromQuaternion(Yi,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Is.DEFAULT_ORDER="XYZ";class $o{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let Wo=0;const Zi=new _,Be=new ns,Xt=new nt,Ps=new _,os=new _,Go=new _,Xo=new ns,Ji=new _(1,0,0),Qi=new _(0,1,0),ji=new _(0,0,1),Ki={type:"added"},Yo={type:"removed"},Re={type:"childadded",child:null},bn={type:"childremoved",child:null};class re extends ts{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:Wo++}),this.uuid=ee(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=re.DEFAULT_UP.clone();const t=new _,e=new Is,s=new ns,n=new _(1,1,1);function i(){s.setFromEuler(e,!1)}function o(){e.setFromQuaternion(s,void 0,!1)}e._onChange(i),s._onChange(o),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:s},scale:{configurable:!0,enumerable:!0,value:n},modelViewMatrix:{value:new nt},normalMatrix:{value:new Rt}}),this.matrix=new nt,this.matrixWorld=new nt,this.matrixAutoUpdate=re.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=re.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new $o,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Be.setFromAxisAngle(t,e),this.quaternion.multiply(Be),this}rotateOnWorldAxis(t,e){return Be.setFromAxisAngle(t,e),this.quaternion.premultiply(Be),this}rotateX(t){return this.rotateOnAxis(Ji,t)}rotateY(t){return this.rotateOnAxis(Qi,t)}rotateZ(t){return this.rotateOnAxis(ji,t)}translateOnAxis(t,e){return Zi.copy(t).applyQuaternion(this.quaternion),this.position.add(Zi.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Ji,t)}translateY(t){return this.translateOnAxis(Qi,t)}translateZ(t){return this.translateOnAxis(ji,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(Xt.copy(this.matrixWorld).invert())}lookAt(t,e,s){t.isVector3?Ps.copy(t):Ps.set(t,e,s);const n=this.parent;this.updateWorldMatrix(!0,!1),os.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Xt.lookAt(os,Ps,this.up):Xt.lookAt(Ps,os,this.up),this.quaternion.setFromRotationMatrix(Xt),n&&(Xt.extractRotation(n.matrixWorld),Be.setFromRotationMatrix(Xt),this.quaternion.premultiply(Be.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(console.error("THREE.Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(Ki),Re.child=t,this.dispatchEvent(Re),Re.child=null):console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let s=0;s<arguments.length;s++)this.remove(arguments[s]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(Yo),bn.child=t,this.dispatchEvent(bn),bn.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),Xt.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),Xt.multiply(t.parent.matrixWorld)),t.applyMatrix4(Xt),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Ki),Re.child=t,this.dispatchEvent(Re),Re.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let s=0,n=this.children.length;s<n;s++){const o=this.children[s].getObjectByProperty(t,e);if(o!==void 0)return o}}getObjectsByProperty(t,e,s=[]){this[t]===e&&s.push(this);const n=this.children;for(let i=0,o=n.length;i<o;i++)n[i].getObjectsByProperty(t,e,s);return s}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(os,t,Go),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(os,Xo,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let s=0,n=e.length;s<n;s++)e[s].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let s=0,n=e.length;s<n;s++)e[s].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let s=0,n=e.length;s<n;s++)e[s].updateMatrixWorld(t)}updateWorldMatrix(t,e){const s=this.parent;if(t===!0&&s!==null&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),e===!0){const n=this.children;for(let i=0,o=n.length;i<o;i++)n[i].updateWorldMatrix(!1,!0)}}toJSON(t){const e=t===void 0||typeof t=="string",s={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},s.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const n={};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.castShadow===!0&&(n.castShadow=!0),this.receiveShadow===!0&&(n.receiveShadow=!0),this.visible===!1&&(n.visible=!1),this.frustumCulled===!1&&(n.frustumCulled=!1),this.renderOrder!==0&&(n.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(n.userData=this.userData),n.layers=this.layers.mask,n.matrix=this.matrix.toArray(),n.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(n.matrixAutoUpdate=!1),this.isInstancedMesh&&(n.type="InstancedMesh",n.count=this.count,n.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(n.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(n.type="BatchedMesh",n.perObjectFrustumCulled=this.perObjectFrustumCulled,n.sortObjects=this.sortObjects,n.drawRanges=this._drawRanges,n.reservedRanges=this._reservedRanges,n.visibility=this._visibility,n.active=this._active,n.bounds=this._bounds.map(a=>({boxInitialized:a.boxInitialized,boxMin:a.box.min.toArray(),boxMax:a.box.max.toArray(),sphereInitialized:a.sphereInitialized,sphereRadius:a.sphere.radius,sphereCenter:a.sphere.center.toArray()})),n.maxInstanceCount=this._maxInstanceCount,n.maxVertexCount=this._maxVertexCount,n.maxIndexCount=this._maxIndexCount,n.geometryInitialized=this._geometryInitialized,n.geometryCount=this._geometryCount,n.matricesTexture=this._matricesTexture.toJSON(t),this._colorsTexture!==null&&(n.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(n.boundingSphere={center:n.boundingSphere.center.toArray(),radius:n.boundingSphere.radius}),this.boundingBox!==null&&(n.boundingBox={min:n.boundingBox.min.toArray(),max:n.boundingBox.max.toArray()}));function i(a,c){return a[c.uuid]===void 0&&(a[c.uuid]=c.toJSON(t)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(n.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=i(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const c=a.shapes;if(Array.isArray(c))for(let u=0,h=c.length;u<h;u++){const l=c[u];i(t.shapes,l)}else i(t.shapes,c)}}if(this.isSkinnedMesh&&(n.bindMode=this.bindMode,n.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(i(t.skeletons,this.skeleton),n.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let c=0,u=this.material.length;c<u;c++)a.push(i(t.materials,this.material[c]));n.material=a}else n.material=i(t.materials,this.material);if(this.children.length>0){n.children=[];for(let a=0;a<this.children.length;a++)n.children.push(this.children[a].toJSON(t).object)}if(this.animations.length>0){n.animations=[];for(let a=0;a<this.animations.length;a++){const c=this.animations[a];n.animations.push(i(t.animations,c))}}if(e){const a=o(t.geometries),c=o(t.materials),u=o(t.textures),h=o(t.images),l=o(t.shapes),d=o(t.skeletons),f=o(t.animations),p=o(t.nodes);a.length>0&&(s.geometries=a),c.length>0&&(s.materials=c),u.length>0&&(s.textures=u),h.length>0&&(s.images=h),l.length>0&&(s.shapes=l),d.length>0&&(s.skeletons=d),f.length>0&&(s.animations=f),p.length>0&&(s.nodes=p)}return s.object=n,s;function o(a){const c=[];for(const u in a){const h=a[u];delete h.metadata,c.push(h)}return c}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let s=0;s<t.children.length;s++){const n=t.children[s];this.add(n.clone())}return this}}re.DEFAULT_UP=new _(0,1,0),re.DEFAULT_MATRIX_AUTO_UPDATE=!0,re.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const Lt=new _,Yt=new _,En=new _,Zt=new _,Ie=new _,Pe=new _,tr=new _,Cn=new _,Fn=new _,Bn=new _,Rn=new It,In=new It,Pn=new It;class Mt{constructor(t=new _,e=new _,s=new _){this.a=t,this.b=e,this.c=s}static getNormal(t,e,s,n){n.subVectors(s,e),Lt.subVectors(t,e),n.cross(Lt);const i=n.lengthSq();return i>0?n.multiplyScalar(1/Math.sqrt(i)):n.set(0,0,0)}static getBarycoord(t,e,s,n,i){Lt.subVectors(n,e),Yt.subVectors(s,e),En.subVectors(t,e);const o=Lt.dot(Lt),a=Lt.dot(Yt),c=Lt.dot(En),u=Yt.dot(Yt),h=Yt.dot(En),l=o*u-a*a;if(l===0)return i.set(0,0,0),null;const d=1/l,f=(u*c-a*h)*d,p=(o*h-a*c)*d;return i.set(1-f-p,p,f)}static containsPoint(t,e,s,n){return this.getBarycoord(t,e,s,n,Zt)===null?!1:Zt.x>=0&&Zt.y>=0&&Zt.x+Zt.y<=1}static getInterpolation(t,e,s,n,i,o,a,c){return this.getBarycoord(t,e,s,n,Zt)===null?(c.x=0,c.y=0,"z"in c&&(c.z=0),"w"in c&&(c.w=0),null):(c.setScalar(0),c.addScaledVector(i,Zt.x),c.addScaledVector(o,Zt.y),c.addScaledVector(a,Zt.z),c)}static getInterpolatedAttribute(t,e,s,n,i,o){return Rn.setScalar(0),In.setScalar(0),Pn.setScalar(0),Rn.fromBufferAttribute(t,e),In.fromBufferAttribute(t,s),Pn.fromBufferAttribute(t,n),o.setScalar(0),o.addScaledVector(Rn,i.x),o.addScaledVector(In,i.y),o.addScaledVector(Pn,i.z),o}static isFrontFacing(t,e,s,n){return Lt.subVectors(s,e),Yt.subVectors(t,e),Lt.cross(Yt).dot(n)<0}set(t,e,s){return this.a.copy(t),this.b.copy(e),this.c.copy(s),this}setFromPointsAndIndices(t,e,s,n){return this.a.copy(t[e]),this.b.copy(t[s]),this.c.copy(t[n]),this}setFromAttributeAndIndices(t,e,s,n){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,s),this.c.fromBufferAttribute(t,n),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return Lt.subVectors(this.c,this.b),Yt.subVectors(this.a,this.b),Lt.cross(Yt).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Mt.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Mt.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,s,n,i){return Mt.getInterpolation(t,this.a,this.b,this.c,e,s,n,i)}containsPoint(t){return Mt.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Mt.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const s=this.a,n=this.b,i=this.c;let o,a;Ie.subVectors(n,s),Pe.subVectors(i,s),Cn.subVectors(t,s);const c=Ie.dot(Cn),u=Pe.dot(Cn);if(c<=0&&u<=0)return e.copy(s);Fn.subVectors(t,n);const h=Ie.dot(Fn),l=Pe.dot(Fn);if(h>=0&&l<=h)return e.copy(n);const d=c*l-h*u;if(d<=0&&c>=0&&h<=0)return o=c/(c-h),e.copy(s).addScaledVector(Ie,o);Bn.subVectors(t,i);const f=Ie.dot(Bn),p=Pe.dot(Bn);if(p>=0&&f<=p)return e.copy(i);const m=f*u-c*p;if(m<=0&&u>=0&&p<=0)return a=u/(u-p),e.copy(s).addScaledVector(Pe,a);const T=h*p-f*l;if(T<=0&&l-h>=0&&f-p>=0)return tr.subVectors(i,n),a=(l-h)/(l-h+(f-p)),e.copy(n).addScaledVector(tr,a);const A=1/(T+m+d);return o=m*A,a=d*A,e.copy(s).addScaledVector(Ie,o).addScaledVector(Pe,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const er={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},oe={h:0,s:0,l:0},vs={h:0,s:0,l:0};function vn(r,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?r+(t-r)*6*e:e<1/2?t:e<2/3?r+(t-r)*6*(2/3-e):r}class Ln{constructor(t,e,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,s)}set(t,e,s){if(e===void 0&&s===void 0){const n=t;n&&n.isColor?this.copy(n):typeof n=="number"?this.setHex(n):typeof n=="string"&&this.setStyle(n)}else this.setRGB(t,e,s);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Wt){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,Tt.toWorkingColorSpace(this,e),this}setRGB(t,e,s,n=Tt.workingColorSpace){return this.r=t,this.g=e,this.b=s,Tt.toWorkingColorSpace(this,n),this}setHSL(t,e,s,n=Tt.workingColorSpace){if(t=Nn(t,1),e=lt(e,0,1),s=lt(s,0,1),e===0)this.r=this.g=this.b=s;else{const i=s<=.5?s*(1+e):s+e-s*e,o=2*s-i;this.r=vn(o,i,t+1/3),this.g=vn(o,i,t),this.b=vn(o,i,t-1/3)}return Tt.toWorkingColorSpace(this,n),this}setStyle(t,e=Wt){function s(i){i!==void 0&&parseFloat(i)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let n;if(n=/^(\w+)\(([^\)]*)\)/.exec(t)){let i;const o=n[1],a=n[2];switch(o){case"rgb":case"rgba":if(i=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(i[4]),this.setRGB(Math.min(255,parseInt(i[1],10))/255,Math.min(255,parseInt(i[2],10))/255,Math.min(255,parseInt(i[3],10))/255,e);if(i=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(i[4]),this.setRGB(Math.min(100,parseInt(i[1],10))/100,Math.min(100,parseInt(i[2],10))/100,Math.min(100,parseInt(i[3],10))/100,e);break;case"hsl":case"hsla":if(i=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(i[4]),this.setHSL(parseFloat(i[1])/360,parseFloat(i[2])/100,parseFloat(i[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(n=/^\#([A-Fa-f\d]+)$/.exec(t)){const i=n[1],o=i.length;if(o===3)return this.setRGB(parseInt(i.charAt(0),16)/15,parseInt(i.charAt(1),16)/15,parseInt(i.charAt(2),16)/15,e);if(o===6)return this.setHex(parseInt(i,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=Wt){const s=er[t.toLowerCase()];return s!==void 0?this.setHex(s,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=_e(t.r),this.g=_e(t.g),this.b=_e(t.b),this}copyLinearToSRGB(t){return this.r=An(t.r),this.g=An(t.g),this.b=An(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Wt){return Tt.fromWorkingColorSpace(dt.copy(this),t),Math.round(lt(dt.r*255,0,255))*65536+Math.round(lt(dt.g*255,0,255))*256+Math.round(lt(dt.b*255,0,255))}getHexString(t=Wt){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=Tt.workingColorSpace){Tt.fromWorkingColorSpace(dt.copy(this),e);const s=dt.r,n=dt.g,i=dt.b,o=Math.max(s,n,i),a=Math.min(s,n,i);let c,u;const h=(a+o)/2;if(a===o)c=0,u=0;else{const l=o-a;switch(u=h<=.5?l/(o+a):l/(2-o-a),o){case s:c=(n-i)/l+(n<i?6:0);break;case n:c=(i-s)/l+2;break;case i:c=(s-n)/l+4;break}c/=6}return t.h=c,t.s=u,t.l=h,t}getRGB(t,e=Tt.workingColorSpace){return Tt.fromWorkingColorSpace(dt.copy(this),e),t.r=dt.r,t.g=dt.g,t.b=dt.b,t}getStyle(t=Wt){Tt.fromWorkingColorSpace(dt.copy(this),t);const e=dt.r,s=dt.g,n=dt.b;return t!==Wt?`color(${t} ${e.toFixed(3)} ${s.toFixed(3)} ${n.toFixed(3)})`:`rgb(${Math.round(e*255)},${Math.round(s*255)},${Math.round(n*255)})`}offsetHSL(t,e,s){return this.getHSL(oe),this.setHSL(oe.h+t,oe.s+e,oe.l+s)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,s){return this.r=t.r+(e.r-t.r)*s,this.g=t.g+(e.g-t.g)*s,this.b=t.b+(e.b-t.b)*s,this}lerpHSL(t,e){this.getHSL(oe),t.getHSL(vs);const s=es(oe.h,vs.h,e),n=es(oe.s,vs.s,e),i=es(oe.l,vs.l,e);return this.setHSL(s,n,i),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,s=this.g,n=this.b,i=t.elements;return this.r=i[0]*e+i[3]*s+i[6]*n,this.g=i[1]*e+i[4]*s+i[7]*n,this.b=i[2]*e+i[5]*s+i[8]*n,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const dt=new Ln;Ln.NAMES=er;const Q=new _,Ls=new Z;class Ot{constructor(t,e,s=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=s,this.usage=35044,this.updateRanges=[],this.gpuType=1015,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,s){t*=this.itemSize,s*=e.itemSize;for(let n=0,i=this.itemSize;n<i;n++)this.array[t+n]=e.array[s+n];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,s=this.count;e<s;e++)Ls.fromBufferAttribute(this,e),Ls.applyMatrix3(t),this.setXY(e,Ls.x,Ls.y);else if(this.itemSize===3)for(let e=0,s=this.count;e<s;e++)Q.fromBufferAttribute(this,e),Q.applyMatrix3(t),this.setXYZ(e,Q.x,Q.y,Q.z);return this}applyMatrix4(t){for(let e=0,s=this.count;e<s;e++)Q.fromBufferAttribute(this,e),Q.applyMatrix4(t),this.setXYZ(e,Q.x,Q.y,Q.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)Q.fromBufferAttribute(this,e),Q.applyNormalMatrix(t),this.setXYZ(e,Q.x,Q.y,Q.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)Q.fromBufferAttribute(this,e),Q.transformDirection(t),this.setXYZ(e,Q.x,Q.y,Q.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let s=this.array[t*this.itemSize+e];return this.normalized&&(s=Bt(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=$(s,this.array)),this.array[t*this.itemSize+e]=s,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=Bt(e,this.array)),e}setX(t,e){return this.normalized&&(e=$(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=Bt(e,this.array)),e}setY(t,e){return this.normalized&&(e=$(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=Bt(e,this.array)),e}setZ(t,e){return this.normalized&&(e=$(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=Bt(e,this.array)),e}setW(t,e){return this.normalized&&(e=$(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,s){return t*=this.itemSize,this.normalized&&(e=$(e,this.array),s=$(s,this.array)),this.array[t+0]=e,this.array[t+1]=s,this}setXYZ(t,e,s,n){return t*=this.itemSize,this.normalized&&(e=$(e,this.array),s=$(s,this.array),n=$(n,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=n,this}setXYZW(t,e,s,n,i){return t*=this.itemSize,this.normalized&&(e=$(e,this.array),s=$(s,this.array),n=$(n,this.array),i=$(i,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=n,this.array[t+3]=i,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(t.name=this.name),this.usage!==35044&&(t.usage=this.usage),t}}class Zo extends Ot{constructor(t,e,s){super(new Uint16Array(t),e,s)}}class Jo extends Ot{constructor(t,e,s){super(new Uint32Array(t),e,s)}}class Qo extends Ot{constructor(t,e,s){super(new Float32Array(t),e,s)}}let jo=0;const _t=new nt,On=new re,ve=new _,wt=new ft,as=new ft,it=new _;class Dn extends ts{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:jo++}),this.uuid=ee(),this.name="",this.type="BufferGeometry",this.index=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(vo(t)?Jo:Zo)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,s=0){this.groups.push({start:t,count:e,materialIndex:s})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const s=this.attributes.normal;if(s!==void 0){const i=new Rt().getNormalMatrix(t);s.applyNormalMatrix(i),s.needsUpdate=!0}const n=this.attributes.tangent;return n!==void 0&&(n.transformDirection(t),n.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(t){return _t.makeRotationFromQuaternion(t),this.applyMatrix4(_t),this}rotateX(t){return _t.makeRotationX(t),this.applyMatrix4(_t),this}rotateY(t){return _t.makeRotationY(t),this.applyMatrix4(_t),this}rotateZ(t){return _t.makeRotationZ(t),this.applyMatrix4(_t),this}translate(t,e,s){return _t.makeTranslation(t,e,s),this.applyMatrix4(_t),this}scale(t,e,s){return _t.makeScale(t,e,s),this.applyMatrix4(_t),this}lookAt(t){return On.lookAt(t),On.updateMatrix(),this.applyMatrix4(On.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ve).negate(),this.translate(ve.x,ve.y,ve.z),this}setFromPoints(t){const e=[];for(let s=0,n=t.length;s<n;s++){const i=t[s];e.push(i.x,i.y,i.z||0)}return this.setAttribute("position",new Qo(e,3)),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new ft);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new _(-1/0,-1/0,-1/0),new _(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let s=0,n=e.length;s<n;s++){const i=e[s];wt.setFromBufferAttribute(i),this.morphTargetsRelative?(it.addVectors(this.boundingBox.min,wt.min),this.boundingBox.expandByPoint(it),it.addVectors(this.boundingBox.max,wt.max),this.boundingBox.expandByPoint(it)):(this.boundingBox.expandByPoint(wt.min),this.boundingBox.expandByPoint(wt.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new ko);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new _,1/0);return}if(t){const s=this.boundingSphere.center;if(wt.setFromBufferAttribute(t),e)for(let i=0,o=e.length;i<o;i++){const a=e[i];as.setFromBufferAttribute(a),this.morphTargetsRelative?(it.addVectors(wt.min,as.min),wt.expandByPoint(it),it.addVectors(wt.max,as.max),wt.expandByPoint(it)):(wt.expandByPoint(as.min),wt.expandByPoint(as.max))}wt.getCenter(s);let n=0;for(let i=0,o=t.count;i<o;i++)it.fromBufferAttribute(t,i),n=Math.max(n,s.distanceToSquared(it));if(e)for(let i=0,o=e.length;i<o;i++){const a=e[i],c=this.morphTargetsRelative;for(let u=0,h=a.count;u<h;u++)it.fromBufferAttribute(a,u),c&&(ve.fromBufferAttribute(t,u),it.add(ve)),n=Math.max(n,s.distanceToSquared(it))}this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const s=e.position,n=e.normal,i=e.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new Ot(new Float32Array(4*s.count),4));const o=this.getAttribute("tangent"),a=[],c=[];for(let z=0;z<s.count;z++)a[z]=new _,c[z]=new _;const u=new _,h=new _,l=new _,d=new Z,f=new Z,p=new Z,m=new _,T=new _;function A(z,B,b){u.fromBufferAttribute(s,z),h.fromBufferAttribute(s,B),l.fromBufferAttribute(s,b),d.fromBufferAttribute(i,z),f.fromBufferAttribute(i,B),p.fromBufferAttribute(i,b),h.sub(u),l.sub(u),f.sub(d),p.sub(d);const I=1/(f.x*p.y-p.x*f.y);isFinite(I)&&(m.copy(h).multiplyScalar(p.y).addScaledVector(l,-f.y).multiplyScalar(I),T.copy(l).multiplyScalar(f.x).addScaledVector(h,-p.x).multiplyScalar(I),a[z].add(m),a[B].add(m),a[b].add(m),c[z].add(T),c[B].add(T),c[b].add(T))}let g=this.groups;g.length===0&&(g=[{start:0,count:t.count}]);for(let z=0,B=g.length;z<B;++z){const b=g[z],I=b.start,C=b.count;for(let P=I,L=I+C;P<L;P+=3)A(t.getX(P+0),t.getX(P+1),t.getX(P+2))}const N=new _,x=new _,y=new _,M=new _;function S(z){y.fromBufferAttribute(n,z),M.copy(y);const B=a[z];N.copy(B),N.sub(y.multiplyScalar(y.dot(B))).normalize(),x.crossVectors(M,B);const I=x.dot(c[z])<0?-1:1;o.setXYZW(z,N.x,N.y,N.z,I)}for(let z=0,B=g.length;z<B;++z){const b=g[z],I=b.start,C=b.count;for(let P=I,L=I+C;P<L;P+=3)S(t.getX(P+0)),S(t.getX(P+1)),S(t.getX(P+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let s=this.getAttribute("normal");if(s===void 0)s=new Ot(new Float32Array(e.count*3),3),this.setAttribute("normal",s);else for(let d=0,f=s.count;d<f;d++)s.setXYZ(d,0,0,0);const n=new _,i=new _,o=new _,a=new _,c=new _,u=new _,h=new _,l=new _;if(t)for(let d=0,f=t.count;d<f;d+=3){const p=t.getX(d+0),m=t.getX(d+1),T=t.getX(d+2);n.fromBufferAttribute(e,p),i.fromBufferAttribute(e,m),o.fromBufferAttribute(e,T),h.subVectors(o,i),l.subVectors(n,i),h.cross(l),a.fromBufferAttribute(s,p),c.fromBufferAttribute(s,m),u.fromBufferAttribute(s,T),a.add(h),c.add(h),u.add(h),s.setXYZ(p,a.x,a.y,a.z),s.setXYZ(m,c.x,c.y,c.z),s.setXYZ(T,u.x,u.y,u.z)}else for(let d=0,f=e.count;d<f;d+=3)n.fromBufferAttribute(e,d+0),i.fromBufferAttribute(e,d+1),o.fromBufferAttribute(e,d+2),h.subVectors(o,i),l.subVectors(n,i),h.cross(l),s.setXYZ(d+0,h.x,h.y,h.z),s.setXYZ(d+1,h.x,h.y,h.z),s.setXYZ(d+2,h.x,h.y,h.z);this.normalizeNormals(),s.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,s=t.count;e<s;e++)it.fromBufferAttribute(t,e),it.normalize(),t.setXYZ(e,it.x,it.y,it.z)}toNonIndexed(){function t(a,c){const u=a.array,h=a.itemSize,l=a.normalized,d=new u.constructor(c.length*h);let f=0,p=0;for(let m=0,T=c.length;m<T;m++){a.isInterleavedBufferAttribute?f=c[m]*a.data.stride+a.offset:f=c[m]*h;for(let A=0;A<h;A++)d[p++]=u[f++]}return new Ot(d,h,l)}if(this.index===null)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Dn,s=this.index.array,n=this.attributes;for(const a in n){const c=n[a],u=t(c,s);e.setAttribute(a,u)}const i=this.morphAttributes;for(const a in i){const c=[],u=i[a];for(let h=0,l=u.length;h<l;h++){const d=u[h],f=t(d,s);c.push(f)}e.morphAttributes[a]=c}e.morphTargetsRelative=this.morphTargetsRelative;const o=this.groups;for(let a=0,c=o.length;a<c;a++){const u=o[a];e.addGroup(u.start,u.count,u.materialIndex)}return e}toJSON(){const t={metadata:{version:4.6,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,this.name!==""&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0){const c=this.parameters;for(const u in c)c[u]!==void 0&&(t[u]=c[u]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const s=this.attributes;for(const c in s){const u=s[c];t.data.attributes[c]=u.toJSON(t.data)}const n={};let i=!1;for(const c in this.morphAttributes){const u=this.morphAttributes[c],h=[];for(let l=0,d=u.length;l<d;l++){const f=u[l];h.push(f.toJSON(t.data))}h.length>0&&(n[c]=h,i=!0)}i&&(t.data.morphAttributes=n,t.data.morphTargetsRelative=this.morphTargetsRelative);const o=this.groups;o.length>0&&(t.data.groups=JSON.parse(JSON.stringify(o)));const a=this.boundingSphere;return a!==null&&(t.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const s=t.index;s!==null&&this.setIndex(s.clone(e));const n=t.attributes;for(const u in n){const h=n[u];this.setAttribute(u,h.clone(e))}const i=t.morphAttributes;for(const u in i){const h=[],l=i[u];for(let d=0,f=l.length;d<f;d++)h.push(l[d].clone(e));this.morphAttributes[u]=h}this.morphTargetsRelative=t.morphTargetsRelative;const o=t.groups;for(let u=0,h=o.length;u<h;u++){const l=o[u];this.addGroup(l.start,l.count,l.materialIndex)}const a=t.boundingBox;a!==null&&(this.boundingBox=a.clone());const c=t.boundingSphere;return c!==null&&(this.boundingSphere=c.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Vn=new _,Ko=new _,ta=new Rt;class Un{constructor(t=new _(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,s,n){return this.normal.set(t,e,s),this.constant=n,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,s){const n=Vn.subVectors(s,e).cross(Ko.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(n,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const s=t.delta(Vn),n=this.normal.dot(s);if(n===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const i=-(t.start.dot(this.normal)+this.constant)/n;return i<0||i>1?null:e.copy(t.start).addScaledVector(s,i)}intersectsLine(t){const e=this.distanceToPoint(t.start),s=this.distanceToPoint(t.end);return e<0&&s>0||s<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const s=e||ta.getNormalMatrix(t),n=this.coplanarPoint(Vn).applyMatrix4(t),i=this.normal.applyMatrix3(s).normalize();return this.constant=-n.dot(i),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}}class sr extends kt{constructor(t,e,s,n,i,o,a,c,u,h=1026){if(h!==1026&&h!==1027)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");s===void 0&&h===1026&&(s=1014),s===void 0&&h===1027&&(s=1020),super(null,n,i,o,a,c,h,s,u),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=a!==void 0?a:1003,this.minFilter=c!==void 0?c:1003,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return this.compareFunction!==null&&(e.compareFunction=this.compareFunction),e}}class ea{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=t!==void 0?t.length/e:0,this.usage=35044,this.updateRanges=[],this.version=0,this.uuid=ee()}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,s){t*=this.stride,s*=e.stride;for(let n=0,i=this.stride;n<i;n++)this.array[t+n]=e.array[s+n];return this}set(t,e=0){return this.array.set(t,e),this}clone(t){t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=ee()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const e=new this.array.constructor(t.arrayBuffers[this.array.buffer._uuid]),s=new this.constructor(e,this.stride);return s.setUsage(this.usage),s}onUpload(t){return this.onUploadCallback=t,this}toJSON(t){return t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=ee()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}const pt=new _;class kn{constructor(t,e,s,n=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=t,this.itemSize=e,this.offset=s,this.normalized=n}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(t){this.data.needsUpdate=t}applyMatrix4(t){for(let e=0,s=this.data.count;e<s;e++)pt.fromBufferAttribute(this,e),pt.applyMatrix4(t),this.setXYZ(e,pt.x,pt.y,pt.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)pt.fromBufferAttribute(this,e),pt.applyNormalMatrix(t),this.setXYZ(e,pt.x,pt.y,pt.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)pt.fromBufferAttribute(this,e),pt.transformDirection(t),this.setXYZ(e,pt.x,pt.y,pt.z);return this}getComponent(t,e){let s=this.array[t*this.data.stride+this.offset+e];return this.normalized&&(s=Bt(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=$(s,this.array)),this.data.array[t*this.data.stride+this.offset+e]=s,this}setX(t,e){return this.normalized&&(e=$(e,this.array)),this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.normalized&&(e=$(e,this.array)),this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.normalized&&(e=$(e,this.array)),this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.normalized&&(e=$(e,this.array)),this.data.array[t*this.data.stride+this.offset+3]=e,this}getX(t){let e=this.data.array[t*this.data.stride+this.offset];return this.normalized&&(e=Bt(e,this.array)),e}getY(t){let e=this.data.array[t*this.data.stride+this.offset+1];return this.normalized&&(e=Bt(e,this.array)),e}getZ(t){let e=this.data.array[t*this.data.stride+this.offset+2];return this.normalized&&(e=Bt(e,this.array)),e}getW(t){let e=this.data.array[t*this.data.stride+this.offset+3];return this.normalized&&(e=Bt(e,this.array)),e}setXY(t,e,s){return t=t*this.data.stride+this.offset,this.normalized&&(e=$(e,this.array),s=$(s,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=s,this}setXYZ(t,e,s,n){return t=t*this.data.stride+this.offset,this.normalized&&(e=$(e,this.array),s=$(s,this.array),n=$(n,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=s,this.data.array[t+2]=n,this}setXYZW(t,e,s,n,i){return t=t*this.data.stride+this.offset,this.normalized&&(e=$(e,this.array),s=$(s,this.array),n=$(n,this.array),i=$(i,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=s,this.data.array[t+2]=n,this.data.array[t+3]=i,this}clone(t){if(t===void 0){console.log("THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let s=0;s<this.count;s++){const n=s*this.data.stride+this.offset;for(let i=0;i<this.itemSize;i++)e.push(this.data.array[n+i])}return new Ot(new this.array.constructor(e),this.itemSize,this.normalized)}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.clone(t)),new kn(t.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(t){if(t===void 0){console.log("THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let s=0;s<this.count;s++){const n=s*this.data.stride+this.offset;for(let i=0;i<this.itemSize;i++)e.push(this.data.array[n+i])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:e,normalized:this.normalized}}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.toJSON(t)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}class sa extends kt{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=1003,this.minFilter=1003,this.generateMipmaps=!1,this.needsUpdate=!0}}const nr=new _,Os=new _;class Jt{constructor(t=new _,e=new _){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){nr.subVectors(t,this.start),Os.subVectors(this.end,this.start);const s=Os.dot(Os);let i=Os.dot(nr)/s;return e&&(i=lt(i,0,1)),i}closestPointToPoint(t,e,s){const n=this.closestPointToPointParameter(t,e);return this.delta(s).multiplyScalar(n).add(this.start)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}function Hn(r,t=0){let e=3735928559^t,s=1103547991^t;if(r instanceof Array)for(let n=0,i;n<r.length;n++)i=r[n],e=Math.imul(e^i,2654435761),s=Math.imul(s^i,1597334677);else for(let n=0,i;n<r.length;n++)i=r.charCodeAt(n),e=Math.imul(e^i,2654435761),s=Math.imul(s^i,1597334677);return e=Math.imul(e^e>>>16,2246822507),e^=Math.imul(s^s>>>13,3266489909),s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(e^e>>>13,3266489909),4294967296*(2097151&s)+(e>>>0)}const na=(...r)=>Hn(r);function ia(r,t=!1){const e=[];r.isNode===!0&&(e.push(r.id),r=r.getSelf());for(const{property:s,childNode:n}of qn(r))e.push(e,Hn(s.slice(0,-4)),n.getCacheKey(t));return Hn(e)}function*qn(r,t=!1){for(const e in r){if(e.startsWith("_")===!0)continue;const s=r[e];if(Array.isArray(s)===!0)for(let n=0;n<s.length;n++){const i=s[n];i&&(i.isNode===!0||t&&typeof i.toJSON=="function")&&(yield{property:e,index:n,childNode:i})}else if(s&&s.isNode===!0)yield{property:e,childNode:s};else if(typeof s=="object")for(const n in s){const i=s[n];i&&(i.isNode===!0||t&&typeof i.toJSON=="function")&&(yield{property:e,index:n,childNode:i})}}}function Ds(r){if(r==null)return null;const t=typeof r;return r.isNode===!0?"node":t==="number"?"float":t==="boolean"?"bool":t==="string"?"string":t==="function"?"shader":r.isVector2===!0?"vec2":r.isVector3===!0?"vec3":r.isVector4===!0?"vec4":r.isMatrix3===!0?"mat3":r.isMatrix4===!0?"mat4":r.isColor===!0?"color":r instanceof ArrayBuffer?"ArrayBuffer":null}function ir(r,...t){const e=r?r.slice(-4):void 0;return t.length===1&&(e==="vec2"?t=[t[0],t[0]]:e==="vec3"?t=[t[0],t[0],t[0]]:e==="vec4"&&(t=[t[0],t[0],t[0],t[0]])),r==="color"?new Ln(...t):e==="vec2"?new Z(...t):e==="vec3"?new _(...t):e==="vec4"?new It(...t):e==="mat3"?new Rt(...t):e==="mat4"?new nt(...t):r==="bool"?t[0]||!1:r==="float"||r==="int"||r==="uint"?t[0]||0:r==="string"?t[0]||"":r==="ArrayBuffer"?oa(t[0]):null}function ra(r){let t="";const e=new Uint8Array(r);for(let s=0;s<e.length;s++)t+=String.fromCharCode(e[s]);return btoa(t)}function oa(r){return Uint8Array.from(atob(r),t=>t.charCodeAt(0)).buffer}const rr={VERTEX:"vertex"},j={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},cs=["x","y","z","w"];let aa=0;class U extends ts{static get type(){return"Node"}constructor(t=null){super(),this.nodeType=t,this.updateType=j.NONE,this.updateBeforeType=j.NONE,this.updateAfterType=j.NONE,this.uuid=Po.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:aa++})}set needsUpdate(t){t===!0&&this.version++}get type(){return this.constructor.type}onUpdate(t,e){return this.updateType=e,this.update=t.bind(this.getSelf()),this}onFrameUpdate(t){return this.onUpdate(t,j.FRAME)}onRenderUpdate(t){return this.onUpdate(t,j.RENDER)}onObjectUpdate(t){return this.onUpdate(t,j.OBJECT)}onReference(t){return this.updateReference=t.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:t}of qn(this))yield t}dispose(){this.dispatchEvent({type:"dispose"})}traverse(t){t(this);for(const e of this.getChildren())e.traverse(t)}getCacheKey(t=!1){return t=t||this.version!==this._cacheKeyVersion,(t===!0||this._cacheKey===null)&&(this._cacheKey=ia(this,t),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(t){const e=this.getNodeType(t);return t.getElementType(e)}getNodeType(t){const e=t.getNodeProperties(this);return e.outputNode?e.outputNode.getNodeType(t):this.nodeType}getShared(t){const e=this.getHash(t);return t.getNodeFromHash(e)||this}setup(t){const e=t.getNodeProperties(this);let s=0;for(const n of this.getChildren())e["node"+s++]=n;return null}analyze(t){if(t.increaseUsage(this)===1){const s=t.getNodeProperties(this);for(const n of Object.values(s))n&&n.isNode===!0&&n.build(t)}}generate(t,e){const{outputNode:s}=t.getNodeProperties(this);if(s&&s.isNode===!0)return s.build(t,e)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(t,e=null){const s=this.getShared(t);if(this!==s)return s.build(t,e);t.addNode(this),t.addChain(this);let n=null;const i=t.getBuildStage();if(i==="setup"){this.updateReference(t);const o=t.getNodeProperties(this);if(o.initialized!==!0){const a=t.stack.nodes.length;o.initialized=!0,o.outputNode=this.setup(t),o.outputNode!==null&&t.stack.nodes.length;for(const c of Object.values(o))c&&c.isNode===!0&&c.build(t)}}else if(i==="analyze")this.analyze(t);else if(i==="generate")if(this.generate.length===1){const a=this.getNodeType(t),c=t.getDataFromNode(this);n=c.snippet,n===void 0?(n=this.generate(t)||"",c.snippet=n):c.flowCodes!==void 0&&t.context.nodeBlock!==void 0&&t.addFlowCodeHierarchy(this,t.context.nodeBlock),n=t.format(n,a,e)}else n=this.generate(t,e)||"";return t.removeChain(this),n}getSerializeChildren(){return qn(this)}serialize(t){const e=this.getSerializeChildren(),s={};for(const{property:n,index:i,childNode:o}of e)i!==void 0?(s[n]===void 0&&(s[n]=Number.isInteger(i)?[]:{}),s[n][i]=o.toJSON(t.meta).uuid):s[n]=o.toJSON(t.meta).uuid;Object.keys(s).length>0&&(t.inputNodes=s)}deserialize(t){if(t.inputNodes!==void 0){const e=t.meta.nodes;for(const s in t.inputNodes)if(Array.isArray(t.inputNodes[s])){const n=[];for(const i of t.inputNodes[s])n.push(e[i]);this[s]=n}else if(typeof t.inputNodes[s]=="object"){const n={};for(const i in t.inputNodes[s]){const o=t.inputNodes[s][i];n[i]=e[o]}this[s]=n}else{const n=t.inputNodes[s];this[s]=e[n]}}}toJSON(t){const{uuid:e,type:s}=this,n=t===void 0||typeof t=="string";n&&(t={textures:{},images:{},nodes:{}});let i=t.nodes[e];i===void 0&&(i={uuid:e,type:s,meta:t,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},n!==!0&&(t.nodes[i.uuid]=i),this.serialize(i),delete i.meta);function o(a){const c=[];for(const u in a){const h=a[u];delete h.metadata,c.push(h)}return c}if(n){const a=o(t.textures),c=o(t.images),u=o(t.nodes);a.length>0&&(i.textures=a),c.length>0&&(i.images=c),u.length>0&&(i.nodes=u)}return i}}class hs extends U{static get type(){return"ArrayElementNode"}constructor(t,e){super(),this.node=t,this.indexNode=e,this.isArrayElementNode=!0}getNodeType(t){return this.node.getElementType(t)}generate(t){const e=this.node.build(t),s=this.indexNode.build(t,"uint");return`${e}[ ${s} ]`}}class or extends U{static get type(){return"ConvertNode"}constructor(t,e){super(),this.node=t,this.convertTo=e}getNodeType(t){const e=this.node.getNodeType(t);let s=null;for(const n of this.convertTo.split("|"))(s===null||t.getTypeLength(e)===t.getTypeLength(n))&&(s=n);return s}serialize(t){super.serialize(t),t.convertTo=this.convertTo}deserialize(t){super.deserialize(t),this.convertTo=t.convertTo}generate(t,e){const s=this.node,n=this.getNodeType(t),i=s.build(t,n);return t.format(i,n,e)}}class gt extends U{static get type(){return"TempNode"}constructor(t){super(t),this.isTempNode=!0}hasDependencies(t){return t.getDataFromNode(this).usageCount>1}build(t,e){if(t.getBuildStage()==="generate"){const n=t.getVectorType(this.getNodeType(t,e)),i=t.getDataFromNode(this);if(i.propertyName!==void 0)return t.format(i.propertyName,n,e);if(n!=="void"&&e!=="void"&&this.hasDependencies(t)){const o=super.build(t,n),a=t.getVarFromNode(this,null,n),c=t.getPropertyName(a);return t.addLineFlowCode(`${c} = ${o}`,this),i.snippet=o,i.propertyName=c,t.format(i.propertyName,n,e)}}return super.build(t,e)}}class ca extends gt{static get type(){return"JoinNode"}constructor(t=[],e=null){super(e),this.nodes=t}getNodeType(t){return this.nodeType!==null?t.getVectorType(this.nodeType):t.getTypeFromLength(this.nodes.reduce((e,s)=>e+t.getTypeLength(s.getNodeType(t)),0))}generate(t,e){const s=this.getNodeType(t),n=this.nodes,i=t.getComponentType(s),o=[];for(const c of n){let u=c.build(t);const h=t.getComponentType(c.getNodeType(t));h!==i&&(u=t.format(u,h,i)),o.push(u)}const a=`${t.getType(s)}( ${o.join(", ")} )`;return t.format(a,s,e)}}const ha=cs.join("");class ar extends U{static get type(){return"SplitNode"}constructor(t,e="x"){super(),this.node=t,this.components=e,this.isSplitNode=!0}getVectorLength(){let t=this.components.length;for(const e of this.components)t=Math.max(cs.indexOf(e)+1,t);return t}getComponentType(t){return t.getComponentType(this.node.getNodeType(t))}getNodeType(t){return t.getTypeFromLength(this.components.length,this.getComponentType(t))}generate(t,e){const s=this.node,n=t.getTypeLength(s.getNodeType(t));let i=null;if(n>1){let o=null;this.getVectorLength()>=n&&(o=t.getTypeFromLength(this.getVectorLength(),this.getComponentType(t)));const c=s.build(t,o);this.components.length===n&&this.components===ha.slice(0,this.components.length)?i=t.format(c,o,e):i=t.format(`${c}.${this.components}`,this.getNodeType(t),e)}else i=s.build(t,e);return i}serialize(t){super.serialize(t),t.components=this.components}deserialize(t){super.deserialize(t),this.components=t.components}}class ua extends gt{static get type(){return"SetNode"}constructor(t,e,s){super(),this.sourceNode=t,this.components=e,this.targetNode=s}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{sourceNode:e,components:s,targetNode:n}=this,i=this.getNodeType(t),o=t.getTypeFromLength(s.length,n.getNodeType(t)),a=n.build(t,o),c=e.build(t,i),u=t.getTypeLength(i),h=[];for(let l=0;l<u;l++){const d=cs[l];d===s[0]?(h.push(a),l+=s.length-1):h.push(c+"."+d)}return`${t.getType(i)}( ${h.join(", ")} )`}}class la extends gt{static get type(){return"FlipNode"}constructor(t,e){super(),this.sourceNode=t,this.components=e}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{components:e,sourceNode:s}=this,n=this.getNodeType(t),i=s.build(t),o=t.getVarFromNode(this),a=t.getPropertyName(o);t.addLineFlowCode(a+" = "+i,this);const c=t.getTypeLength(n),u=[];let h=0;for(let l=0;l<c;l++){const d=cs[l];d===e[h]?(u.push("1.0 - "+(a+"."+d)),h++):u.push(a+"."+d)}return`${t.getType(n)}( ${u.join(", ")} )`}}class $n extends U{static get type(){return"InputNode"}constructor(t,e=null){super(e),this.isInputNode=!0,this.value=t,this.precision=null}getNodeType(){return this.nodeType===null?Ds(this.value):this.nodeType}getInputType(t){return this.getNodeType(t)}setPrecision(t){return this.precision=t,this}serialize(t){super.serialize(t),t.value=this.value,this.value&&this.value.toArray&&(t.value=this.value.toArray()),t.valueType=Ds(this.value),t.nodeType=this.nodeType,t.valueType==="ArrayBuffer"&&(t.value=ra(t.value)),t.precision=this.precision}deserialize(t){super.deserialize(t),this.nodeType=t.nodeType,this.value=Array.isArray(t.value)?ir(t.valueType,...t.value):t.value,this.precision=t.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(t.value))}generate(){console.warn("Abstract function.")}}class Qt extends $n{static get type(){return"ConstNode"}constructor(t,e=null){super(t,e),this.isConstNode=!0}generateConst(t){return t.generateConst(this.getNodeType(t),this.value)}generate(t,e){const s=this.getNodeType(t);return t.format(this.generateConst(t),s,e)}}let cr=null;const Le=new Map;function F(r,t){if(Le.has(r)){console.warn(`Redefinition of method chaining ${r}`);return}if(typeof t!="function")throw new Error(`Node element ${r} is not a function`);Le.set(r,t)}const hr=r=>r.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),ur=r=>hr(r).split("").sort().join(""),lr={setup(r,t){const e=t.shift();return r(ks(e),...t)},get(r,t,e){if(typeof t=="string"&&r[t]===void 0){if(r.isStackNode!==!0&&t==="assign")return(...s)=>(cr.assign(e,...s),e);if(Le.has(t)){const s=Le.get(t);return r.isStackNode?(...n)=>e.add(s(...n)):(...n)=>s(e,...n)}else{if(t==="self")return r;if(t.endsWith("Assign")&&Le.has(t.slice(0,t.length-6))){const s=Le.get(t.slice(0,t.length-6));return r.isStackNode?(...n)=>e.assign(n[0],s(...n)):(...n)=>e.assign(s(e,...n))}else{if(/^[xyzwrgbastpq]{1,4}$/.test(t)===!0)return t=hr(t),v(new ar(e,t));if(/^set[XYZWRGBASTPQ]{1,4}$/.test(t)===!0)return t=ur(t.slice(3).toLowerCase()),s=>v(new ua(r,t,s));if(/^flip[XYZWRGBASTPQ]{1,4}$/.test(t)===!0)return t=ur(t.slice(4).toLowerCase()),()=>v(new la(v(r),t));if(t==="width"||t==="height"||t==="depth")return t==="width"?t="x":t==="height"?t="y":t==="depth"&&(t="z"),v(new ar(r,t));if(/^\d+$/.test(t)===!0)return v(new hs(e,new Qt(Number(t),"uint")))}}}return Reflect.get(r,t,e)},set(r,t,e,s){return typeof t=="string"&&r[t]===void 0&&(/^[xyzwrgbastpq]{1,4}$/.test(t)===!0||t==="width"||t==="height"||t==="depth"||/^\d+$/.test(t)===!0)?(s[t].assign(e),!0):Reflect.set(r,t,e,s)}},Wn=new WeakMap,dr=new WeakMap,da=function(r,t=null){const e=Ds(r);if(e==="node"){let s=Wn.get(r);return s===void 0&&(s=new Proxy(r,lr),Wn.set(r,s),Wn.set(s,s)),s}else{if(t===null&&(e==="float"||e==="boolean")||e&&e!=="shader"&&e!=="string")return v(Zn(r,t));if(e==="shader")return tt(r)}return r},fa=function(r,t=null){for(const e in r)r[e]=v(r[e],t);return r},pa=function(r,t=null){const e=r.length;for(let s=0;s<e;s++)r[s]=v(r[s],t);return r},ma=function(r,t=null,e=null,s=null){const n=i=>v(s!==null?Object.assign(i,s):i);return t===null?(...i)=>n(new r(...Oe(i))):e!==null?(e=v(e),(...i)=>n(new r(t,...Oe(i),e))):(...i)=>n(new r(t,...Oe(i)))},ya=function(r,...t){return v(new r(...Oe(t)))};class ga extends U{constructor(t,e){super(),this.shaderNode=t,this.inputNodes=e}getNodeType(t){return this.shaderNode.nodeType||this.getOutputNode(t).getNodeType(t)}call(t){const{shaderNode:e,inputNodes:s}=this,n=t.getNodeProperties(e);if(n.onceOutput)return n.onceOutput;let i=null;if(e.layout){let o=dr.get(t.constructor);o===void 0&&(o=new WeakMap,dr.set(t.constructor,o));let a=o.get(e);a===void 0&&(a=v(t.buildFunctionNode(e)),o.set(e,a)),t.currentFunctionNode!==null&&t.currentFunctionNode.includes.push(a),i=v(a.call(s))}else{const o=e.jsFunc,a=s!==null?o(s,t):o(t);i=v(a)}return e.once&&(n.onceOutput=i),i}getOutputNode(t){const e=t.getNodeProperties(this);return e.outputNode===null&&(e.outputNode=this.setupOutput(t)),e.outputNode}setup(t){return this.getOutputNode(t)}setupOutput(t){return t.addStack(),t.stack.outputNode=this.call(t),t.removeStack()}generate(t,e){return this.getOutputNode(t).build(t,e)}}class xa extends U{constructor(t,e){super(e),this.jsFunc=t,this.layout=null,this.global=!0,this.once=!1}setLayout(t){return this.layout=t,this}call(t=null){return ks(t),v(new ga(this,t))}setup(){return this.call()}}const Ta=[!1,!0],Na=[0,1,2,3],wa=[-1,-2],fr=[.5,1.5,1/3,1e-6,1e6,Math.PI,Math.PI*2,1/Math.PI,2/Math.PI,1/(Math.PI*2),Math.PI/2],Gn=new Map;for(const r of Ta)Gn.set(r,new Qt(r));const Xn=new Map;for(const r of Na)Xn.set(r,new Qt(r,"uint"));const Yn=new Map([...Xn].map(r=>new Qt(r.value,"int")));for(const r of wa)Yn.set(r,new Qt(r,"int"));const Vs=new Map([...Yn].map(r=>new Qt(r.value)));for(const r of fr)Vs.set(r,new Qt(r));for(const r of fr)Vs.set(-r,new Qt(-r));const Us={bool:Gn,uint:Xn,ints:Yn,float:Vs},pr=new Map([...Gn,...Vs]),Zn=(r,t)=>pr.has(r)?pr.get(r):r.isNode===!0?r:new Qt(r,t),Aa=r=>{try{return r.getNodeType()}catch{return}},K=function(r,t=null){return(...e)=>{if((e.length===0||!["bool","float","int","uint"].includes(r)&&e.every(n=>typeof n!="object"))&&(e=[ir(r,...e)]),e.length===1&&t!==null&&t.has(e[0]))return v(t.get(e[0]));if(e.length===1){const n=Zn(e[0],r);return Aa(n)===r?v(n):v(new or(n,r))}const s=e.map(n=>Zn(n));return v(new ca(s,r))}},Sa=r=>r!=null?r.nodeType||r.convertTo||(typeof r=="string"?r:null):null;function Ma(r,t){return new Proxy(new xa(r,t),lr)}const v=(r,t=null)=>da(r,t),ks=(r,t=null)=>new fa(r,t),Oe=(r,t=null)=>new pa(r,t),R=(...r)=>new ma(...r),O=(...r)=>new ya(...r),tt=(r,t)=>{const e=new Ma(r,t),s=(...n)=>{let i;return ks(n),n[0]&&n[0].isNode?i=[...n]:i=n[0],e.call(i)};return s.shaderNode=e,s.setLayout=n=>(e.setLayout(n),s),s.once=()=>(e.once=!0,s),s};F("toGlobal",r=>(r.global=!0,r));const Jn=(...r)=>cr.If(...r);function _a(r){return r}F("append",_a);const za=new K("color"),q=new K("float",Us.float),De=new K("int",Us.ints),ba=new K("uint",Us.uint),Ea=new K("bool",Us.bool),V=new K("vec2"),Ca=new K("ivec2"),Fa=new K("uvec2"),Ba=new K("bvec2"),k=new K("vec3"),Ra=new K("ivec3"),Ia=new K("uvec3"),Pa=new K("bvec3"),Ve=new K("vec4"),va=new K("ivec4"),La=new K("uvec4"),Oa=new K("bvec4"),mr=new K("mat2"),Hs=new K("mat3"),Da=new K("mat4");F("toColor",za),F("toFloat",q),F("toInt",De),F("toUint",ba),F("toBool",Ea),F("toVec2",V),F("toIVec2",Ca),F("toUVec2",Fa),F("toBVec2",Ba),F("toVec3",k),F("toIVec3",Ra),F("toUVec3",Ia),F("toBVec3",Pa),F("toVec4",Ve),F("toIVec4",va),F("toUVec4",La),F("toBVec4",Oa),F("toMat2",mr),F("toMat3",Hs),F("toMat4",Da);const Va=R(hs),Ua=(r,t)=>v(new or(v(r),t));F("element",Va),F("convert",Ua);class yr extends U{static get type(){return"UniformGroupNode"}constructor(t,e=!1,s=1){super("string"),this.name=t,this.version=0,this.shared=e,this.order=s,this.isUniformGroup=!0}set needsUpdate(t){t===!0&&this.version++}serialize(t){super.serialize(t),t.name=this.name,t.version=this.version,t.shared=this.shared}deserialize(t){super.deserialize(t),this.name=t.name,this.version=t.version,this.shared=t.shared}}const ka=r=>new yr(r),ye=((r,t=0)=>new yr(r,!0,t))("render"),Ha=ka("object");class Ue extends $n{static get type(){return"UniformNode"}constructor(t,e=null){super(t,e),this.isUniformNode=!0,this.name="",this.groupNode=Ha}label(t){return this.name=t,this}setGroup(t){return this.groupNode=t,this}getGroup(){return this.groupNode}getUniformHash(t){return this.getHash(t)}onUpdate(t,e){const s=this.getSelf();return t=t.bind(s),super.onUpdate(n=>{const i=t(n,s);i!==void 0&&(this.value=i)},e)}generate(t,e){const s=this.getNodeType(t),n=this.getUniformHash(t);let i=t.getNodeFromHash(n);i===void 0&&(t.setHashNode(this,n),i=this);const o=i.getInputType(t),a=t.getUniformFromNode(i,o,t.shaderStage,this.name||t.context.label),c=t.getPropertyName(a);return t.context.label!==void 0&&delete t.context.label,t.format(c,s,e)}}const At=(r,t)=>{const e=Sa(t||r),s=r&&r.isNode===!0?r.node&&r.node.value||r.value:r;return v(new Ue(s,e))};class gr extends U{static get type(){return"PropertyNode"}constructor(t,e=null,s=!1){super(t),this.name=e,this.varying=s,this.isPropertyNode=!0}getHash(t){return this.name||super.getHash(t)}isGlobal(){return!0}generate(t){let e;return this.varying===!0?(e=t.getVaryingFromNode(this,this.name),e.needsInterpolation=!0):e=t.getVarFromNode(this,this.name),t.getPropertyName(e)}}const ke=(r,t)=>v(new gr(r,t)),xr=O(gr,"vec4","DiffuseColor");class qa extends gt{static get type(){return"AssignNode"}constructor(t,e){super(),this.targetNode=t,this.sourceNode=e}hasDependencies(){return!1}getNodeType(t,e){return e!=="void"?this.targetNode.getNodeType(t):"void"}needsSplitAssign(t){const{targetNode:e}=this;if(t.isAvailable("swizzleAssign")===!1&&e.isSplitNode&&e.components.length>1){const s=t.getTypeLength(e.node.getNodeType(t));return cs.join("").slice(0,s)!==e.components}return!1}generate(t,e){const{targetNode:s,sourceNode:n}=this,i=this.needsSplitAssign(t),o=s.getNodeType(t),a=s.context({assign:!0}).build(t),c=n.build(t,o),u=n.getNodeType(t),h=t.getDataFromNode(this);let l;if(h.initialized===!0)e!=="void"&&(l=a);else if(i){const d=t.getVarFromNode(this,null,o),f=t.getPropertyName(d);t.addLineFlowCode(`${f} = ${c}`,this);const p=s.node.context({assign:!0}).build(t);for(let m=0;m<s.components.length;m++){const T=s.components[m];t.addLineFlowCode(`${p}.${T} = ${f}[ ${m} ]`,this)}e!=="void"&&(l=a)}else l=`${a} = ${c}`,(e==="void"||u==="void")&&(t.addLineFlowCode(l,this),e!=="void"&&(l=a));return h.initialized=!0,t.format(l,o,e)}}F("assign",R(qa));class $a extends gt{static get type(){return"FunctionCallNode"}constructor(t=null,e={}){super(),this.functionNode=t,this.parameters=e}setParameters(t){return this.parameters=t,this}getParameters(){return this.parameters}getNodeType(t){return this.functionNode.getNodeType(t)}generate(t){const e=[],s=this.functionNode,n=s.getInputs(t),i=this.parameters;if(Array.isArray(i))for(let a=0;a<i.length;a++){const c=n[a],u=i[a];e.push(u.build(t,c.type))}else for(const a of n){const c=i[a.name];if(c!==void 0)e.push(c.build(t,a.type));else throw new Error(`FunctionCallNode: Input '${a.name}' not found in FunctionNode.`)}return`${s.build(t,"property")}( ${e.join(", ")} )`}}F("call",(r,...t)=>(t=t.length>1||t[0]&&t[0].isNode===!0?Oe(t):ks(t[0]),v(new $a(v(r),t))));class Y extends gt{static get type(){return"OperatorNode"}constructor(t,e,s,...n){if(super(),n.length>0){let i=new Y(t,e,s);for(let o=0;o<n.length-1;o++)i=new Y(t,i,n[o]);e=i,s=n[n.length-1]}this.op=t,this.aNode=e,this.bNode=s}getNodeType(t,e){const s=this.op,n=this.aNode,i=this.bNode,o=n.getNodeType(t),a=typeof i<"u"?i.getNodeType(t):null;if(o==="void"||a==="void")return"void";if(s==="%")return o;if(s==="~"||s==="&"||s==="|"||s==="^"||s===">>"||s==="<<")return t.getIntegerType(o);if(s==="!"||s==="=="||s==="&&"||s==="||"||s==="^^")return"bool";if(s==="<"||s===">"||s==="<="||s===">="){const c=e?t.getTypeLength(e):Math.max(t.getTypeLength(o),t.getTypeLength(a));return c>1?`bvec${c}`:"bool"}else return o==="float"&&t.isMatrix(a)?a:t.isMatrix(o)&&t.isVector(a)?t.getVectorFromMatrix(o):t.isVector(o)&&t.isMatrix(a)?t.getVectorFromMatrix(a):t.getTypeLength(a)>t.getTypeLength(o)?a:o}generate(t,e){const s=this.op,n=this.aNode,i=this.bNode,o=this.getNodeType(t,e);let a=null,c=null;o!=="void"?(a=n.getNodeType(t),c=typeof i<"u"?i.getNodeType(t):null,s==="<"||s===">"||s==="<="||s===">="||s==="=="?t.isVector(a)?c=a:a!==c&&(a=c="float"):s===">>"||s==="<<"?(a=o,c=t.changeComponentType(c,"uint")):t.isMatrix(a)&&t.isVector(c)?c=t.getVectorFromMatrix(a):t.isVector(a)&&t.isMatrix(c)?a=t.getVectorFromMatrix(c):a=c=o):a=c=o;const u=n.build(t,a),h=typeof i<"u"?i.build(t,c):null,l=t.getTypeLength(e),d=t.getFunctionOperator(s);if(e!=="void")return s==="<"&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("lessThan",e)}( ${u}, ${h} )`,o,e):t.format(`( ${u} < ${h} )`,o,e):s==="<="&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("lessThanEqual",e)}( ${u}, ${h} )`,o,e):t.format(`( ${u} <= ${h} )`,o,e):s===">"&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("greaterThan",e)}( ${u}, ${h} )`,o,e):t.format(`( ${u} > ${h} )`,o,e):s===">="&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("greaterThanEqual",e)}( ${u}, ${h} )`,o,e):t.format(`( ${u} >= ${h} )`,o,e):s==="!"||s==="~"?t.format(`(${s}${u})`,a,e):d?t.format(`${d}( ${u}, ${h} )`,o,e):t.format(`( ${u} ${s} ${h} )`,o,e);if(a!=="void")return d?t.format(`${d}( ${u}, ${h} )`,o,e):t.format(`${u} ${s} ${h}`,o,e)}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}}const ge=R(Y,"+"),qs=R(Y,"-"),$s=R(Y,"*"),Tr=R(Y,"/"),Nr=R(Y,"%"),Wa=R(Y,"=="),Ga=R(Y,"!="),Xa=R(Y,"<"),Ya=R(Y,">"),Za=R(Y,"<="),Ja=R(Y,">="),Qa=R(Y,"&&"),ja=R(Y,"||"),Ka=R(Y,"!"),tc=R(Y,"^^"),ec=R(Y,"&"),sc=R(Y,"~"),nc=R(Y,"|"),ic=R(Y,"^"),rc=R(Y,"<<"),oc=R(Y,">>");F("add",ge),F("sub",qs),F("mul",$s),F("div",Tr),F("modInt",Nr),F("equal",Wa),F("notEqual",Ga),F("lessThan",Xa),F("greaterThan",Ya),F("lessThanEqual",Za),F("greaterThanEqual",Ja),F("and",Qa),F("or",ja),F("not",Ka),F("xor",tc),F("bitAnd",ec),F("bitNot",sc),F("bitOr",nc),F("bitXor",ic),F("shiftLeft",rc),F("shiftRight",oc),F("remainder",(...r)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),Nr(...r)));class w extends gt{static get type(){return"MathNode"}constructor(t,e,s=null,n=null){super(),this.method=t,this.aNode=e,this.bNode=s,this.cNode=n}getInputType(t){const e=this.aNode.getNodeType(t),s=this.bNode?this.bNode.getNodeType(t):null,n=this.cNode?this.cNode.getNodeType(t):null,i=t.isMatrix(e)?0:t.getTypeLength(e),o=t.isMatrix(s)?0:t.getTypeLength(s),a=t.isMatrix(n)?0:t.getTypeLength(n);return i>o&&i>a?e:o>a?s:a>i?n:e}getNodeType(t){const e=this.method;return e===w.LENGTH||e===w.DISTANCE||e===w.DOT?"float":e===w.CROSS?"vec3":e===w.ALL?"bool":e===w.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):e===w.MOD?this.aNode.getNodeType(t):this.getInputType(t)}generate(t,e){const s=this.method,n=this.getNodeType(t),i=this.getInputType(t),o=this.aNode,a=this.bNode,c=this.cNode,u=t.renderer.isWebGLRenderer===!0;if(s===w.TRANSFORM_DIRECTION){let h=o,l=a;t.isMatrix(h.getNodeType(t))?l=Ve(k(l),0):h=Ve(k(h),0);const d=$s(h,l).xyz;return wr(d).build(t,e)}else{if(s===w.NEGATE)return t.format("( - "+o.build(t,i)+" )",n,e);if(s===w.ONE_MINUS)return qs(1,o).build(t,e);if(s===w.RECIPROCAL)return Tr(1,o).build(t,e);if(s===w.DIFFERENCE)return Kn(qs(o,a)).build(t,e);{const h=[];return s===w.CROSS||s===w.MOD?h.push(o.build(t,n),a.build(t,n)):u&&s===w.STEP?h.push(o.build(t,t.getTypeLength(o.getNodeType(t))===1?"float":i),a.build(t,i)):u&&(s===w.MIN||s===w.MAX)||s===w.MOD?h.push(o.build(t,i),a.build(t,t.getTypeLength(a.getNodeType(t))===1?"float":i)):s===w.REFRACT?h.push(o.build(t,i),a.build(t,i),c.build(t,"float")):s===w.MIX?h.push(o.build(t,i),a.build(t,i),c.build(t,t.getTypeLength(c.getNodeType(t))===1?"float":i)):(h.push(o.build(t,i)),a!==null&&h.push(a.build(t,i)),c!==null&&h.push(c.build(t,i))),t.format(`${t.getMethod(s,n)}( ${h.join(", ")} )`,n,e)}}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}w.ALL="all",w.ANY="any",w.EQUALS="equals",w.RADIANS="radians",w.DEGREES="degrees",w.EXP="exp",w.EXP2="exp2",w.LOG="log",w.LOG2="log2",w.SQRT="sqrt",w.INVERSE_SQRT="inversesqrt",w.FLOOR="floor",w.CEIL="ceil",w.NORMALIZE="normalize",w.FRACT="fract",w.SIN="sin",w.COS="cos",w.TAN="tan",w.ASIN="asin",w.ACOS="acos",w.ATAN="atan",w.ABS="abs",w.SIGN="sign",w.LENGTH="length",w.NEGATE="negate",w.ONE_MINUS="oneMinus",w.DFDX="dFdx",w.DFDY="dFdy",w.ROUND="round",w.RECIPROCAL="reciprocal",w.TRUNC="trunc",w.FWIDTH="fwidth",w.BITCAST="bitcast",w.TRANSPOSE="transpose",w.ATAN2="atan2",w.MIN="min",w.MAX="max",w.MOD="mod",w.STEP="step",w.REFLECT="reflect",w.DISTANCE="distance",w.DIFFERENCE="difference",w.DOT="dot",w.CROSS="cross",w.POW="pow",w.TRANSFORM_DIRECTION="transformDirection",w.MIX="mix",w.CLAMP="clamp",w.REFRACT="refract",w.SMOOTHSTEP="smoothstep",w.FACEFORWARD="faceforward";const ac=q(Math.PI),cc=R(w,w.ALL),hc=R(w,w.ANY),uc=R(w,w.EQUALS),lc=R(w,w.RADIANS),dc=R(w,w.DEGREES),fc=R(w,w.EXP),pc=R(w,w.EXP2),mc=R(w,w.LOG),yc=R(w,w.LOG2),Qn=R(w,w.SQRT),gc=R(w,w.INVERSE_SQRT),xc=R(w,w.FLOOR),Tc=R(w,w.CEIL),wr=R(w,w.NORMALIZE),jn=R(w,w.FRACT),Ar=R(w,w.SIN),Nc=R(w,w.COS),wc=R(w,w.TAN),Ac=R(w,w.ASIN),Sc=R(w,w.ACOS),Mc=R(w,w.ATAN),Kn=R(w,w.ABS),Sr=R(w,w.SIGN),_c=R(w,w.LENGTH),zc=R(w,w.NEGATE),bc=R(w,w.ONE_MINUS),Ec=R(w,w.DFDX),Cc=R(w,w.DFDY),Fc=R(w,w.ROUND),Bc=R(w,w.RECIPROCAL),Rc=R(w,w.TRUNC),Ic=R(w,w.FWIDTH);w.BITCAST;const Pc=R(w,w.TRANSPOSE),vc=R(w,w.ATAN2),Lc=R(w,w.MIN),ti=R(w,w.MAX),Mr=R(w,w.MOD),_r=R(w,w.STEP),Oc=R(w,w.REFLECT),Dc=R(w,w.DISTANCE),Vc=R(w,w.DIFFERENCE),ei=R(w,w.DOT),Uc=R(w,w.CROSS),zr=R(w,w.POW),kc=R(w,w.POW,2),Hc=R(w,w.POW,3),qc=R(w,w.POW,4),$c=R(w,w.TRANSFORM_DIRECTION),Wc=r=>$s(Sr(r),zr(Kn(r),1/3)),Gc=r=>ei(r,r),ae=R(w,w.MIX),Ws=(r,t=0,e=1)=>v(new w(w.CLAMP,v(r),v(t),v(e))),Xc=r=>Ws(r),Yc=R(w,w.REFRACT),si=R(w,w.SMOOTHSTEP),Zc=R(w,w.FACEFORWARD),Jc=tt(([r])=>{const s=43758.5453,n=ei(r.xy,V(12.9898,78.233)),i=Mr(n,ac);return jn(Ar(i).mul(s))}),Qc=(r,t,e)=>ae(t,e,r),jc=(r,t,e)=>si(t,e,r);F("all",cc),F("any",hc),F("equals",uc),F("radians",lc),F("degrees",dc),F("exp",fc),F("exp2",pc),F("log",mc),F("log2",yc),F("sqrt",Qn),F("inverseSqrt",gc),F("floor",xc),F("ceil",Tc),F("normalize",wr),F("fract",jn),F("sin",Ar),F("cos",Nc),F("tan",wc),F("asin",Ac),F("acos",Sc),F("atan",Mc),F("abs",Kn),F("sign",Sr),F("length",_c),F("lengthSq",Gc),F("negate",zc),F("oneMinus",bc),F("dFdx",Ec),F("dFdy",Cc),F("round",Fc),F("reciprocal",Bc),F("trunc",Rc),F("fwidth",Ic),F("atan2",vc),F("min",Lc),F("max",ti),F("mod",Mr),F("step",_r),F("reflect",Oc),F("distance",Dc),F("dot",ei),F("cross",Uc),F("pow",zr),F("pow2",kc),F("pow3",Hc),F("pow4",qc),F("transformDirection",$c),F("mix",Qc),F("clamp",Ws),F("refract",Yc),F("smoothstep",jc),F("faceForward",Zc),F("difference",Vc),F("saturate",Xc),F("cbrt",Wc),F("transpose",Pc),F("rand",Jc);class Kc extends U{static get type(){return"ConditionalNode"}constructor(t,e,s=null){super(),this.condNode=t,this.ifNode=e,this.elseNode=s}getNodeType(t){const e=this.ifNode.getNodeType(t);if(this.elseNode!==null){const s=this.elseNode.getNodeType(t);if(t.getTypeLength(s)>t.getTypeLength(e))return s}return e}setup(t){const e=this.condNode.cache(),s=this.ifNode.cache(),n=this.elseNode?this.elseNode.cache():null,i=t.context.nodeBlock;t.getDataFromNode(s).parentNodeBlock=i,n!==null&&(t.getDataFromNode(n).parentNodeBlock=i);const o=t.getNodeProperties(this);o.condNode=e,o.ifNode=s.context({nodeBlock:s}),o.elseNode=n?n.context({nodeBlock:n}):null}generate(t,e){const s=this.getNodeType(t),n=t.getDataFromNode(this);if(n.nodeProperty!==void 0)return n.nodeProperty;const{condNode:i,ifNode:o,elseNode:a}=t.getNodeProperties(this),c=e!=="void",u=c?ke(s).build(t):"";n.nodeProperty=u;const h=i.build(t,"bool");t.addFlowCode(`
|
|
2
2
|
${t.tab}if ( ${h} ) {
|
|
3
3
|
|
|
4
4
|
`).addFlowTab();let l=o.build(t,s);if(l&&(c?l=u+" = "+l+";":l="return "+l+";"),t.removeFlowTab().addFlowCode(t.tab+" "+l+`
|
|
@@ -11,11 +11,11 @@ ${t.tab}if ( ${h} ) {
|
|
|
11
11
|
|
|
12
12
|
`)}else t.addFlowCode(`
|
|
13
13
|
|
|
14
|
-
`);return t.format(u,s,e)}}const ii=B(jc);E("select",ii),E("cond",(...r)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),ii(...r)));class Kc extends U{static get type(){return"ContextNode"}constructor(t,e={}){super(),this.isContextNode=!0,this.node=t,this.value=e}getScope(){return this.node.getScope()}getNodeType(t){return this.node.getNodeType(t)}analyze(t){this.node.build(t)}setup(t){const e=t.getContext();t.setContext({...t.context,...this.value});const s=this.node.build(t);return t.setContext(e),s}generate(t,e){const s=t.getContext();t.setContext({...t.context,...this.value});const n=this.node.build(t,e);return t.setContext(s),n}}const zr=B(Kc),th=(r,t)=>zr(r,{label:t});E("context",zr),E("label",th);class eh extends U{static get type(){return"VarNode"}constructor(t,e=null){super(),this.node=t,this.name=e,this.global=!0,this.isVarNode=!0}getHash(t){return this.name||super.getHash(t)}getNodeType(t){return this.node.getNodeType(t)}generate(t){const{node:e,name:s}=this,n=t.getVarFromNode(this,s,t.getVectorType(this.getNodeType(t))),i=t.getPropertyName(n),o=e.build(t,n.type);return t.addLineFlowCode(`${i} = ${o}`,this),i}}const br=B(eh);E("temp",br),E("toVar",(...r)=>br(...r).append());class sh extends U{static get type(){return"VaryingNode"}constructor(t,e=null){super(),this.node=t,this.name=e,this.isVaryingNode=!0}isGlobal(){return!0}getHash(t){return this.name||super.getHash(t)}getNodeType(t){return this.node.getNodeType(t)}setupVarying(t){const e=t.getNodeProperties(this);let s=e.varying;if(s===void 0){const n=this.name,i=this.getNodeType(t);e.varying=s=t.getVaryingFromNode(this,n,i),e.node=this.node}return s.needsInterpolation||(s.needsInterpolation=t.shaderStage==="fragment"),s}setup(t){this.setupVarying(t)}analyze(t){return this.setupVarying(t),this.node.analyze(t)}generate(t){const e=t.getNodeProperties(this),s=this.setupVarying(t);if(e.propertyName===void 0){const n=this.getNodeType(t),i=t.getPropertyName(s,ir.VERTEX);t.flowNodeFromShaderStage(ir.VERTEX,this.node,n,i),e.propertyName=i}return t.getPropertyName(s)}}const Ve=B(sh);E("varying",Ve);const cs="WorkingColorSpace",ri="OutputColorSpace";function Er(r){let t=null;return r===Es?t="Linear":r===Wt&&(t="sRGB"),t}function nh(r,t){return Er(r)+"To"+Er(t)}class Gs extends pt{static get type(){return"ColorSpaceNode"}constructor(t,e,s){super("vec4"),this.colorNode=t,this.source=e,this.target=s}getColorSpace(t,e){return e===cs?yt.workingColorSpace:e===ri?t.context.outputColorSpace||t.renderer.outputColorSpace:e}setup(t){const{renderer:e}=t,{colorNode:s}=this,n=this.getColorSpace(t,this.source),i=this.getColorSpace(t,this.target);if(n===i)return s;const o=nh(n,i);let a=null;const c=e.nodes.library.getColorSpaceFunction(o);return c!==null?a=Le(c(s.rgb),s.a):(console.error("ColorSpaceNode: Unsupported Color Space configuration.",o),a=s),a}}const ih=r=>v(new Gs(v(r),cs,ri)),rh=r=>v(new Gs(v(r),ri,cs)),oh=(r,t)=>v(new Gs(v(r),cs,t)),Cr=(r,t)=>v(new Gs(v(r),t,cs));E("toOutputColorSpace",ih),E("toWorkingColorSpace",rh),E("workingToColorSpace",oh),E("colorSpaceToWorking",Cr);let ah=class extends as{static get type(){return"ReferenceElementNode"}constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),s=this.referenceNode.getNodeType(),n=this.getNodeType();return t.format(e,s,n)}};class ch extends U{static get type(){return"ReferenceBaseNode"}constructor(t,e,s=null,n=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=n,this.properties=t.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=j.OBJECT}setGroup(t){return this.group=t,this}element(t){return v(new ah(this,v(t)))}setNodeType(t){const e=Tt(null,t).getSelf();this.group!==null&&e.setGroup(this.group),this.node=e}getNodeType(t){return this.node===null&&(this.updateReference(t),this.updateValue()),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let s=t[e[0]];for(let n=1;n<e.length;n++)s=s[e[n]];return s}updateReference(t){return this.reference=this.object!==null?this.object:t.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);const t=this.getValueFromReference();Array.isArray(t)?this.node.array=t:this.node.value=t}}class hh extends ch{static get type(){return"RendererReferenceNode"}constructor(t,e,s=null){super(t,e,s),this.renderer=s,this.setGroup(ye)}updateReference(t){return this.reference=this.renderer!==null?this.renderer:t.renderer,this.reference}}const uh=(r,t,e)=>v(new hh(r,t,e));class lh extends pt{static get type(){return"ToneMappingNode"}constructor(t,e=ph,s=null){super("vec3"),this.toneMapping=t,this.exposureNode=e,this.colorNode=s}getCacheKey(){return sa(super.getCacheKey(),this.toneMapping)}setup(t){const e=this.colorNode||t.context.color,s=this.toneMapping;if(s===0)return e;let n=null;const i=t.renderer.nodes.library.getToneMappingFunction(s);return i!==null?n=Le(i(e.rgb,this.exposureNode),e.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),n=e),n}}const dh=(r,t,e)=>v(new lh(r,v(t),v(e))),ph=uh("toneMappingExposure","float");E("toneMapping",(r,t,e)=>dh(t,e,r));class fh extends Wn{static get type(){return"BufferAttributeNode"}constructor(t,e=null,s=0,n=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferStride=s,this.bufferOffset=n,this.usage=35044,this.instanced=!1,this.attribute=null,this.global=!0,t&&t.isBufferAttribute===!0&&(this.attribute=t,this.usage=t.usage,this.instanced=t.isInstancedBufferAttribute)}getHash(t){if(this.bufferStride===0&&this.bufferOffset===0){let e=t.globalCache.getData(this.value);return e===void 0&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getNodeType(t){return this.bufferType===null&&(this.bufferType=t.getTypeFromAttribute(this.attribute)),this.bufferType}setup(t){if(this.attribute!==null)return;const e=this.getNodeType(t),s=this.value,n=t.getTypeLength(e),i=this.bufferStride||n,o=this.bufferOffset,a=s.isInterleavedBuffer===!0?s:new ta(s,i),c=new Hn(a,n,o);a.setUsage(this.usage),this.attribute=c,this.attribute.isInstancedBufferAttribute=this.instanced}generate(t){const e=this.getNodeType(t),s=t.getBufferAttributeFromNode(this,e),n=t.getPropertyName(s);let i=null;return t.shaderStage==="vertex"||t.shaderStage==="compute"?(this.name=n,i=n):i=Ve(this).build(t,e),i}getInputType(){return"bufferAttribute"}setUsage(t){return this.usage=t,this.attribute&&this.attribute.isBufferAttribute===!0&&(this.attribute.usage=t),this}setInstanced(t){return this.instanced=t,this}}const mh=(r,t,e,s)=>v(new fh(r,t,e,s));E("toAttribute",r=>mh(r.value));class yh extends U{static get type(){return"ComputeNode"}constructor(t,e,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=t,this.count=e,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=j.OBJECT,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){t===!0&&this.version++}updateDispatchCount(){const{count:t,workgroupSize:e}=this;let s=e[0];for(let n=1;n<e.length;n++)s*=e[n];this.dispatchCount=Math.ceil(t/s)}onInit(){}updateBefore({renderer:t}){t.compute(this)}generate(t){const{shaderStage:e}=t;if(e==="compute"){const s=this.computeNode.build(t,"void");s!==""&&t.addLineFlowCode(s,this)}}}E("compute",(r,t,e)=>v(new yh(v(r),t,e)));class gh extends U{static get type(){return"CacheNode"}constructor(t,e=!0){super(),this.node=t,this.parent=e,this.isCacheNode=!0}getNodeType(t){return this.node.getNodeType(t)}build(t,...e){const s=t.getCache(),n=t.getCacheFromNode(this,this.parent);t.setCache(n);const i=this.node.build(t,...e);return t.setCache(s),i}}E("cache",(r,...t)=>v(new gh(v(r),...t)));class xh extends U{static get type(){return"BypassNode"}constructor(t,e){super(),this.isBypassNode=!0,this.outputNode=t,this.callNode=e}getNodeType(t){return this.outputNode.getNodeType(t)}generate(t){const e=this.callNode.build(t,"void");return e!==""&&t.addLineFlowCode(e,this),this.outputNode.build(t)}}E("bypass",B(xh));class Fr extends U{static get type(){return"RemapNode"}constructor(t,e,s,n=$(0),i=$(1)){super(),this.node=t,this.inLowNode=e,this.inHighNode=s,this.outLowNode=n,this.outHighNode=i,this.doClamp=!0}setup(){const{node:t,inLowNode:e,inHighNode:s,outLowNode:n,outHighNode:i,doClamp:o}=this;let a=t.sub(e).div(s.sub(e));return o===!0&&(a=a.clamp()),a.mul(i.sub(n)).add(n)}}const Th=B(Fr,null,null,{doClamp:!1}),Nh=B(Fr);E("remap",Th),E("remapClamp",Nh);class wh extends U{static get type(){return"ExpressionNode"}constructor(t="",e="void"){super(e),this.snippet=t}generate(t,e){const s=this.getNodeType(t),n=this.snippet;if(s==="void")t.addLineFlowCode(n,this);else return t.format(`( ${n} )`,s,e)}}const Xs=B(wh);E("discard",r=>(r?ii(r,Xs("discard")):Xs("discard")).append());class Ah extends pt{static get type(){return"RenderOutputNode"}constructor(t,e,s){super("vec4"),this.colorNode=t,this.toneMapping=e,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:t}){let e=this.colorNode||t.color;const s=(this.toneMapping!==null?this.toneMapping:t.toneMapping)||0,n=(this.outputColorSpace!==null?this.outputColorSpace:t.outputColorSpace)||"";return s!==0&&(e=e.toneMapping(s)),n!==""&&n!==yt.workingColorSpace&&(e=e.workingToColorSpace(n)),e}}E("renderOutput",(r,t=null,e=null)=>v(new Ah(v(r),t,e)));class Sh extends U{static get type(){return"AttributeNode"}constructor(t,e=null){super(e),this.global=!0,this._attributeName=t}getHash(t){return this.getAttributeName(t)}getNodeType(t){let e=this.nodeType;if(e===null){const s=this.getAttributeName(t);if(t.hasGeometryAttribute(s)){const n=t.geometry.getAttribute(s);e=t.getTypeFromAttribute(n)}else e="float"}return e}setAttributeName(t){return this._attributeName=t,this}getAttributeName(){return this._attributeName}generate(t){const e=this.getAttributeName(t),s=this.getNodeType(t);if(t.hasGeometryAttribute(e)===!0){const i=t.geometry.getAttribute(e),o=t.getTypeFromAttribute(i),a=t.getAttribute(e,o);return t.shaderStage==="vertex"?t.format(a.name,o,s):Ve(this).build(t,s)}else return console.warn(`AttributeNode: Vertex attribute "${e}" not found on geometry.`),t.generateConst(s)}serialize(t){super.serialize(t),t.global=this.global,t._attributeName=this._attributeName}deserialize(t){super.deserialize(t),this.global=t.global,this._attributeName=t._attributeName}}const hs=(r,t)=>v(new Sh(r,t)),Ys=r=>hs("uv"+(r>0?r:""),"vec2");class Mh extends U{static get type(){return"TextureSizeNode"}constructor(t,e=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=t,this.levelNode=e}generate(t,e){const s=this.textureNode.build(t,"property"),n=this.levelNode===null?"0":this.levelNode.build(t,"int");return t.format(`${t.getMethod("textureDimensions")}( ${s}, ${n} )`,this.getNodeType(t),e)}}const Rr=B(Mh);class _h extends Oe{static get type(){return"MaxMipLevelNode"}constructor(t){super(0),this._textureNode=t,this.updateType=j.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const t=this.texture,e=t.images,s=e&&e.length>0?e[0]&&e[0].image||e[0]:t.image;if(s&&s.width!==void 0){const{width:n,height:i}=s;this.value=Math.log2(Math.max(n,i))}}}const zh=B(_h);class Zs extends Oe{static get type(){return"TextureNode"}constructor(t,e=null,s=null,n=null){super(t),this.isTextureNode=!0,this.uvNode=e,this.levelNode=s,this.biasNode=n,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=j.NONE,this.referenceNode=null,this._value=t,this._matrixUniform=null,this.setUpdateMatrix(e===null)}set value(t){this.referenceNode?this.referenceNode.value=t:this._value=t}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return this.value.isDepthTexture===!0?"float":this.value.type===1014?"uvec4":this.value.type===1013?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return Ys(this.value.channel)}updateReference(){return this.value}getTransformedUV(t){return this._matrixUniform===null&&(this._matrixUniform=Tt(this.value.matrix)),this._matrixUniform.mul(H(t,1)).xy}setUpdateMatrix(t){return this.updateMatrix=t,this.updateType=t?j.FRAME:j.NONE,this}setupUV(t,e){const s=this.value;return t.isFlipY()&&(s.isRenderTargetTexture===!0||s.isFramebufferTexture===!0||s.isDepthTexture===!0)&&(this.sampler?e=e.flipY():e=e.setY(ve(Rr(this,this.levelNode).y).sub(e.y).sub(1))),e}setup(t){const e=t.getNodeProperties(this);e.referenceNode=this.referenceNode;let s=this.uvNode;(s===null||t.context.forceUVContext===!0)&&t.context.getUV&&(s=t.context.getUV(this)),s||(s=this.getDefaultUV()),this.updateMatrix===!0&&(s=this.getTransformedUV(s)),s=this.setupUV(t,s);let n=this.levelNode;n===null&&t.context.getTextureLevel&&(n=t.context.getTextureLevel(this)),e.uvNode=s,e.levelNode=n,e.biasNode=this.biasNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.depthNode=this.depthNode}generateUV(t,e){return e.build(t,this.sampler===!0?"vec2":"ivec2")}generateSnippet(t,e,s,n,i,o,a,c){const u=this.value;let h;return n?h=t.generateTextureLevel(u,e,s,n,o):i?h=t.generateTextureBias(u,e,s,i,o):c?h=t.generateTextureGrad(u,e,s,c,o):a?h=t.generateTextureCompare(u,e,s,a,o):this.sampler===!1?h=t.generateTextureLoad(u,e,s,o):h=t.generateTexture(u,e,s,o),h}generate(t,e){const s=t.getNodeProperties(this),n=this.value;if(!n||n.isTexture!==!0)throw new Error("TextureNode: Need a three.js texture.");const i=super.generate(t,"property");if(e==="sampler")return i+"_sampler";if(t.isReference(e))return i;{const o=t.getDataFromNode(this);let a=o.propertyName;if(a===void 0){const{uvNode:h,levelNode:l,biasNode:d,compareNode:p,depthNode:f,gradNode:y}=s,N=this.generateUV(t,h),A=l?l.build(t,"float"):null,x=d?d.build(t,"float"):null,w=f?f.build(t,"int"):null,g=p?p.build(t,"float"):null,m=y?[y[0].build(t,"vec2"),y[1].build(t,"vec2")]:null,M=t.getVarFromNode(this);a=t.getPropertyName(M);const S=this.generateSnippet(t,i,N,A,x,w,g,m);t.addLineFlowCode(`${a} = ${S}`,this),o.snippet=S,o.propertyName=a}let c=a;const u=this.getNodeType(t);return t.needsToWorkingColorSpace(n)&&(c=Cr(Xs(c,u),n.colorSpace).setup(t).build(t,u)),t.format(c,u,e)}}setSampler(t){return this.sampler=t,this}getSampler(){return this.sampler}uv(t){const e=this.clone();return e.uvNode=v(t),e.referenceNode=this.getSelf(),v(e)}blur(t){const e=this.clone();return e.biasNode=v(t).mul(zh(e)),e.referenceNode=this.getSelf(),v(e)}level(t){const e=this.clone();return e.levelNode=v(t),e.referenceNode=this.getSelf(),v(e)}size(t){return Rr(this,t)}bias(t){const e=this.clone();return e.biasNode=v(t),e.referenceNode=this.getSelf(),v(e)}compare(t){const e=this.clone();return e.compareNode=v(t),e.referenceNode=this.getSelf(),v(e)}grad(t,e){const s=this.clone();return s.gradNode=[v(t),v(e)],s.referenceNode=this.getSelf(),v(s)}depth(t){const e=this.clone();return e.depthNode=v(t),e.referenceNode=this.getSelf(),v(e)}serialize(t){super.serialize(t),t.value=this.value.toJSON(t.meta).uuid,t.sampler=this.sampler,t.updateMatrix=this.updateMatrix,t.updateType=this.updateType}deserialize(t){super.deserialize(t),this.value=t.meta.textures[t.value],this.sampler=t.sampler,this.updateMatrix=t.updateMatrix,this.updateType=t.updateType}update(){const t=this.value,e=this._matrixUniform;e!==null&&(e.value=t.matrix),t.matrixAutoUpdate===!0&&t.updateMatrix()}clone(){const t=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return t.sampler=this.sampler,t}}const us=B(Zs),ls=Tt("float").label("cameraNear").setGroup(ye).onRenderUpdate(({camera:r})=>r.near),ds=Tt("float").label("cameraFar").setGroup(ye).onRenderUpdate(({camera:r})=>r.far),Js=Tt("mat4").label("cameraViewMatrix").setGroup(ye).onRenderUpdate(({camera:r})=>r.matrixWorldInverse);class q extends U{static get type(){return"Object3DNode"}constructor(t,e=null){super(),this.scope=t,this.object3d=e,this.updateType=j.OBJECT,this._uniformNode=new Oe(null)}getNodeType(){const t=this.scope;if(t===q.WORLD_MATRIX)return"mat4";if(t===q.POSITION||t===q.VIEW_POSITION||t===q.DIRECTION||t===q.SCALE)return"vec3"}update(t){const e=this.object3d,s=this._uniformNode,n=this.scope;if(n===q.WORLD_MATRIX)s.value=e.matrixWorld;else if(n===q.POSITION)s.value=s.value||new _,s.value.setFromMatrixPosition(e.matrixWorld);else if(n===q.SCALE)s.value=s.value||new _,s.value.setFromMatrixScale(e.matrixWorld);else if(n===q.DIRECTION)s.value=s.value||new _,e.getWorldDirection(s.value);else if(n===q.VIEW_POSITION){const i=t.camera;s.value=s.value||new _,s.value.setFromMatrixPosition(e.matrixWorld),s.value.applyMatrix4(i.matrixWorldInverse)}}generate(t){const e=this.scope;return e===q.WORLD_MATRIX?this._uniformNode.nodeType="mat4":(e===q.POSITION||e===q.VIEW_POSITION||e===q.DIRECTION||e===q.SCALE)&&(this._uniformNode.nodeType="vec3"),this._uniformNode.build(t)}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}}q.WORLD_MATRIX="worldMatrix",q.POSITION="position",q.SCALE="scale",q.VIEW_POSITION="viewPosition",q.DIRECTION="direction",q.DIRECTION,q.WORLD_MATRIX,q.POSITION,q.SCALE,q.VIEW_POSITION;class Ht extends q{static get type(){return"ModelNode"}constructor(t){super(t)}update(t){this.object3d=t.object,super.update(t)}}Ht.DIRECTION;const bh=O(Ht,Ht.WORLD_MATRIX);Ht.POSITION,Ht.SCALE,Ht.VIEW_POSITION;const Eh=Tt(new Bt).onObjectUpdate(({object:r},t)=>t.value.getNormalMatrix(r.matrixWorld)),Br=Js.mul(bh).toVar("modelViewMatrix_2"),Ch=hs("position","vec3").varying("positionLocal"),_t=Br.mul(Ch).xyz.varying("v_positionView"),Ir=_t.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class Fh extends U{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(t){const{renderer:e,material:s}=t;return e.coordinateSystem===2e3&&s.side===1?"false":t.getFrontFacing()}}const oi=$(O(Fh)).mul(2).sub(1),Rh=hs("normal","vec3"),Bh=tt(r=>r.geometry.hasAttribute("normal")===!1?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),H(0,1,0)):Rh,"vec3").once()().toVar("normalLocal"),Ih=_t.dFdx().cross(_t.dFdy()).normalize().toVar("normalFlat"),Ue=tt(r=>{let t;return r.material.flatShading===!0?t=Ih:t=Ve(vr(Bh),"v_normalView").normalize(),t},"vec3").once()().toVar("normalView"),Pr=tt(r=>r.context.setupNormal(),"vec3").once()().mul(oi).toVar("transformedNormalView"),vr=tt(([r],t)=>{const e=t.renderer.nodes.modelNormalViewMatrix;if(e!==null)return e.transformDirection(r);const s=Eh.mul(r);return Js.transformDirection(s)}),Ph=Tt(0).onReference(({material:r})=>r).onRenderUpdate(({material:r})=>r.refractionRatio),vh=Ir.negate().reflect(Pr),Lh=Ir.negate().refract(Pr,Ph),Oh=vh.transformDirection(Js).toVar("reflectVector"),Dh=Lh.transformDirection(Js).toVar("reflectVector");class Vh extends Zs{static get type(){return"CubeTextureNode"}constructor(t,e=null,s=null,n=null){super(t,e,s,n),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const t=this.value;return t.mapping===301?Oh:t.mapping===302?Dh:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',t.mapping),H(0,0,0))}setUpdateMatrix(){}setupUV(t,e){const s=this.value;return t.renderer.coordinateSystem===2001||!s.isRenderTargetTexture?H(e.x.negate(),e.yz):e}generateUV(t,e){return e.build(t,"vec3")}}const Uh=B(Vh);class Lr extends Oe{static get type(){return"BufferNode"}constructor(t,e,s=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferCount=s}getElementType(t){return this.getNodeType(t)}getInputType(){return"buffer"}}const kh=(r,t,e)=>v(new Lr(r,t,e));class Hh extends as{static get type(){return"UniformArrayElementNode"}constructor(t,e){super(t,e),this.isArrayBufferElementNode=!0}generate(t){const e=super.generate(t),s=this.getNodeType();return t.format(e,"vec4",s)}}class qh extends Lr{static get type(){return"UniformArrayNode"}constructor(t,e=null){super(null,"vec4"),this.array=t,this.elementType=e,this._elementType=null,this._elementLength=0,this.updateType=j.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:t,value:e}=this,s=this.getElementLength(),n=this.getElementType();if(s===1)for(let i=0;i<t.length;i++){const o=i*4;e[o]=t[i]}else if(n==="color")for(let i=0;i<t.length;i++){const o=i*4,a=t[i];e[o]=a.r,e[o+1]=a.g,e[o+2]=a.b||0}else for(let i=0;i<t.length;i++){const o=i*4,a=t[i];e[o]=a.x,e[o+1]=a.y,e[o+2]=a.z||0,e[o+3]=a.w||0}}setup(t){const e=this.array.length;this._elementType=this.elementType===null?Ds(this.array[0]):this.elementType,this._elementLength=t.getTypeLength(this._elementType);let s=Float32Array;return this._elementType.charAt(0)==="i"?s=Int32Array:this._elementType.charAt(0)==="u"&&(s=Uint32Array),this.value=new s(e*4),this.bufferCount=e,this.bufferType=t.changeComponentType("vec4",t.getComponentType(this._elementType)),super.setup(t)}element(t){return v(new Hh(this,v(t)))}}const ai=(r,t)=>v(new qh(r,t));class $h extends as{static get type(){return"ReferenceElementNode"}constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),s=this.referenceNode.getNodeType(),n=this.getNodeType();return t.format(e,s,n)}}class Or extends U{static get type(){return"ReferenceNode"}constructor(t,e,s=null,n=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=n,this.properties=t.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=j.OBJECT}element(t){return v(new $h(this,v(t)))}setGroup(t){return this.group=t,this}label(t){return this.name=t,this}setNodeType(t){let e=null;this.count!==null?e=kh(null,t,this.count):Array.isArray(this.getValueFromReference())?e=ai(null,t):t==="texture"?e=us(null):t==="cubeTexture"?e=Uh(null):e=Tt(null,t),this.group!==null&&e.setGroup(this.group),this.name!==null&&e.label(this.name),this.node=e.getSelf()}getNodeType(t){return this.node===null&&(this.updateReference(t),this.updateValue()),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let s=t[e[0]];for(let n=1;n<e.length;n++)s=s[e[n]];return s}updateReference(t){return this.reference=this.object!==null?this.object:t.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);const t=this.getValueFromReference();Array.isArray(t)?this.node.array=t:this.node.value=t}}const xe=(r,t,e)=>v(new Or(r,t,e));class Wh extends Or{static get type(){return"MaterialReferenceNode"}constructor(t,e,s=null){super(t,e,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(t){return this.reference=this.material!==null?this.material:t.material,this.reference}}const Gh=(r,t,e)=>v(new Wh(r,t,e)),Dr=tt(r=>(r.geometry.hasAttribute("tangent")===!1&&r.geometry.computeTangents(),hs("tangent","vec4")))(),Xh=Dr.xyz.toVar("tangentLocal"),Vr=Br.mul(Le(Xh,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Yh=Hs(Vr,Ve((r=>r.mul(Dr.w).xyz)(Ue.cross(Vr)),"v_bitangentView").normalize().toVar("bitangentView"),Ue),Zh=tt(r=>{const{eye_pos:t,surf_norm:e,mapN:s,uv:n}=r,i=t.dFdx(),o=t.dFdy(),a=n.dFdx(),c=n.dFdy(),u=e,h=o.cross(u),l=u.cross(i),d=h.mul(a.x).add(l.mul(c.x)),p=h.mul(a.y).add(l.mul(c.y)),f=d.dot(d).max(p.dot(p)),y=oi.mul(f.inverseSqrt());return ge(d.mul(s.x,y),p.mul(s.y,y),u.mul(s.z)).normalize()});class Jh extends pt{static get type(){return"NormalMapNode"}constructor(t,e=null){super("vec3"),this.node=t,this.scaleNode=e,this.normalMapType=0}setup(t){const{normalMapType:e,scaleNode:s}=this;let n=this.node.mul(2).sub(1);s!==null&&(n=H(n.xy.mul(s),n.z));let i=null;return e===1?i=vr(n):e===0&&(t.hasGeometryAttribute("tangent")===!0?i=Yh.mul(n).normalize():i=Zh({eye_pos:_t,surf_norm:Ue,mapN:n,uv:Ys()})),i}}const Ur=B(Jh),Qh=tt(({textureNode:r,bumpScale:t})=>{const e=n=>r.cache().context({getUV:i=>n(i.uvNode||Ys()),forceUVContext:!0}),s=$(e(n=>n));return V($(e(n=>n.add(n.dFdx()))).sub(s),$(e(n=>n.add(n.dFdy()))).sub(s)).mul(t)}),jh=tt(r=>{const{surf_pos:t,surf_norm:e,dHdxy:s}=r,n=t.dFdx().normalize(),i=t.dFdy().normalize(),o=e,a=i.cross(o),c=o.cross(n),u=n.dot(a).mul(oi),h=u.sign().mul(s.x.mul(a).add(s.y.mul(c)));return u.abs().mul(e).sub(h).normalize()});class Kh extends pt{static get type(){return"BumpMapNode"}constructor(t,e=null){super("vec3"),this.textureNode=t,this.scaleNode=e}setup(){const t=this.scaleNode!==null?this.scaleNode:1,e=Qh({textureNode:this.textureNode,bumpScale:t});return jh({surf_pos:_t,surf_norm:Ue,dHdxy:e})}}const tu=B(Kh),kr=new Map;class b extends U{static get type(){return"MaterialNode"}constructor(t){super(),this.scope=t}getCache(t,e){let s=kr.get(t);return s===void 0&&(s=Gh(t,e),kr.set(t,s)),s}getFloat(t){return this.getCache(t,"float")}getColor(t){return this.getCache(t,"color")}getTexture(t){return this.getCache(t==="map"?"map":t+"Map","texture")}setup(t){const e=t.context.material,s=this.scope;let n=null;if(s===b.COLOR){const i=e.color!==void 0?this.getColor(s):H();e.map&&e.map.isTexture===!0?n=i.mul(this.getTexture("map")):n=i}else if(s===b.OPACITY){const i=this.getFloat(s);e.alphaMap&&e.alphaMap.isTexture===!0?n=i.mul(this.getTexture("alpha")):n=i}else if(s===b.SPECULAR_STRENGTH)e.specularMap&&e.specularMap.isTexture===!0?n=this.getTexture("specular").r:n=$(1);else if(s===b.SPECULAR_INTENSITY){const i=this.getFloat(s);e.specularMap?n=i.mul(this.getTexture(s).a):n=i}else if(s===b.SPECULAR_COLOR){const i=this.getColor(s);e.specularColorMap&&e.specularColorMap.isTexture===!0?n=i.mul(this.getTexture(s).rgb):n=i}else if(s===b.ROUGHNESS){const i=this.getFloat(s);e.roughnessMap&&e.roughnessMap.isTexture===!0?n=i.mul(this.getTexture(s).g):n=i}else if(s===b.METALNESS){const i=this.getFloat(s);e.metalnessMap&&e.metalnessMap.isTexture===!0?n=i.mul(this.getTexture(s).b):n=i}else if(s===b.EMISSIVE){const i=this.getFloat("emissiveIntensity"),o=this.getColor(s).mul(i);e.emissiveMap&&e.emissiveMap.isTexture===!0?n=o.mul(this.getTexture(s)):n=o}else if(s===b.NORMAL)e.normalMap?(n=Ur(this.getTexture("normal"),this.getCache("normalScale","vec2")),n.normalMapType=e.normalMapType):e.bumpMap?n=tu(this.getTexture("bump").r,this.getFloat("bumpScale")):n=Ue;else if(s===b.CLEARCOAT){const i=this.getFloat(s);e.clearcoatMap&&e.clearcoatMap.isTexture===!0?n=i.mul(this.getTexture(s).r):n=i}else if(s===b.CLEARCOAT_ROUGHNESS){const i=this.getFloat(s);e.clearcoatRoughnessMap&&e.clearcoatRoughnessMap.isTexture===!0?n=i.mul(this.getTexture(s).r):n=i}else if(s===b.CLEARCOAT_NORMAL)e.clearcoatNormalMap?n=Ur(this.getTexture(s),this.getCache(s+"Scale","vec2")):n=Ue;else if(s===b.SHEEN){const i=this.getColor("sheenColor").mul(this.getFloat("sheen"));e.sheenColorMap&&e.sheenColorMap.isTexture===!0?n=i.mul(this.getTexture("sheenColor").rgb):n=i}else if(s===b.SHEEN_ROUGHNESS){const i=this.getFloat(s);e.sheenRoughnessMap&&e.sheenRoughnessMap.isTexture===!0?n=i.mul(this.getTexture(s).a):n=i,n=n.clamp(.07,1)}else if(s===b.ANISOTROPY)if(e.anisotropyMap&&e.anisotropyMap.isTexture===!0){const i=this.getTexture(s);n=fr(ps.x,ps.y,ps.y.negate(),ps.x).mul(i.rg.mul(2).sub(V(1)).normalize().mul(i.b))}else n=ps;else if(s===b.IRIDESCENCE_THICKNESS){const i=xe("1","float",e.iridescenceThicknessRange);if(e.iridescenceThicknessMap){const o=xe("0","float",e.iridescenceThicknessRange);n=i.sub(o).mul(this.getTexture(s).g).add(o)}else n=i}else if(s===b.TRANSMISSION){const i=this.getFloat(s);e.transmissionMap?n=i.mul(this.getTexture(s).r):n=i}else if(s===b.THICKNESS){const i=this.getFloat(s);e.thicknessMap?n=i.mul(this.getTexture(s).g):n=i}else if(s===b.IOR)n=this.getFloat(s);else if(s===b.LIGHT_MAP)n=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===b.AO_MAP)n=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const i=this.getNodeType(t);n=this.getCache(s,i)}return n}}b.ALPHA_TEST="alphaTest",b.COLOR="color",b.OPACITY="opacity",b.SHININESS="shininess",b.SPECULAR="specular",b.SPECULAR_STRENGTH="specularStrength",b.SPECULAR_INTENSITY="specularIntensity",b.SPECULAR_COLOR="specularColor",b.REFLECTIVITY="reflectivity",b.ROUGHNESS="roughness",b.METALNESS="metalness",b.NORMAL="normal",b.CLEARCOAT="clearcoat",b.CLEARCOAT_ROUGHNESS="clearcoatRoughness",b.CLEARCOAT_NORMAL="clearcoatNormal",b.EMISSIVE="emissive",b.ROTATION="rotation",b.SHEEN="sheen",b.SHEEN_ROUGHNESS="sheenRoughness",b.ANISOTROPY="anisotropy",b.IRIDESCENCE="iridescence",b.IRIDESCENCE_IOR="iridescenceIOR",b.IRIDESCENCE_THICKNESS="iridescenceThickness",b.IOR="ior",b.TRANSMISSION="transmission",b.THICKNESS="thickness",b.ATTENUATION_DISTANCE="attenuationDistance",b.ATTENUATION_COLOR="attenuationColor",b.LINE_SCALE="scale",b.LINE_DASH_SIZE="dashSize",b.LINE_GAP_SIZE="gapSize",b.LINE_WIDTH="linewidth",b.LINE_DASH_OFFSET="dashOffset",b.POINT_WIDTH="pointWidth",b.DISPERSION="dispersion",b.LIGHT_MAP="light",b.AO_MAP="ao",b.ALPHA_TEST,b.COLOR,b.SHININESS,b.EMISSIVE,b.OPACITY,b.SPECULAR,b.SPECULAR_INTENSITY,b.SPECULAR_COLOR,b.SPECULAR_STRENGTH,b.REFLECTIVITY,b.ROUGHNESS,b.METALNESS,b.CLEARCOAT,b.CLEARCOAT_ROUGHNESS,b.ROTATION,b.SHEEN,b.SHEEN_ROUGHNESS,b.ANISOTROPY,b.IRIDESCENCE,b.IRIDESCENCE_IOR,b.IRIDESCENCE_THICKNESS,b.TRANSMISSION,b.THICKNESS,b.IOR,b.ATTENUATION_DISTANCE,b.ATTENUATION_COLOR,b.LINE_SCALE,b.LINE_DASH_SIZE,b.LINE_GAP_SIZE,b.LINE_WIDTH,b.LINE_DASH_OFFSET,b.POINT_WIDTH,b.DISPERSION,b.LIGHT_MAP,b.AO_MAP;const ps=Tt(new Z).onReference(function(r){return r.material}).onRenderUpdate(function({material:r}){this.value.set(r.anisotropy*Math.cos(r.anisotropyRotation),r.anisotropy*Math.sin(r.anisotropyRotation))});class G extends U{static get type(){return"IndexNode"}constructor(t){super("uint"),this.scope=t,this.isInstanceIndexNode=!0}generate(t){const e=this.getNodeType(t),s=this.scope;let n;if(s===G.VERTEX)n=t.getVertexIndex();else if(s===G.INSTANCE)n=t.getInstanceIndex();else if(s===G.DRAW)n=t.getDrawIndex();else if(s===G.INVOCATION_LOCAL)n=t.getInvocationLocalIndex();else if(s===G.INVOCATION_SUBGROUP)n=t.getInvocationSubgroupIndex();else if(s===G.SUBGROUP)n=t.getSubgroupIndex();else throw new Error("THREE.IndexNode: Unknown scope: "+s);let i;return t.shaderStage==="vertex"||t.shaderStage==="compute"?i=n:i=Ve(this).build(t,e),i}}G.VERTEX="vertex",G.INSTANCE="instance",G.SUBGROUP="subgroup",G.INVOCATION_LOCAL="invocationLocal",G.INVOCATION_SUBGROUP="invocationSubgroup",G.DRAW="draw",G.VERTEX,G.INSTANCE,G.SUBGROUP,G.INVOCATION_SUBGROUP,G.INVOCATION_LOCAL,G.DRAW;class eu extends U{static get type(){return"LoopNode"}constructor(t=[]){super(),this.params=t}getVarName(t){return String.fromCharCode(105+t)}getProperties(t){const e=t.getNodeProperties(this);if(e.stackNode!==void 0)return e;const s={};for(let i=0,o=this.params.length-1;i<o;i++){const a=this.params[i],c=a.isNode!==!0&&a.name||this.getVarName(i),u=a.isNode!==!0&&a.type||"int";s[c]=Xs(c,u)}const n=t.addStack();return e.returnsNode=this.params[this.params.length-1](s,n,t),e.stackNode=n,t.removeStack(),e}getNodeType(t){const{returnsNode:e}=this.getProperties(t);return e?e.getNodeType(t):"void"}setup(t){this.getProperties(t)}generate(t){const e=this.getProperties(t),s=this.params,n=e.stackNode;for(let a=0,c=s.length-1;a<c;a++){const u=s[a];let h=null,l=null,d=null,p=null,f=null,y=null;u.isNode?(p="int",d=this.getVarName(a),h="0",l=u.build(t,p),f="<"):(p=u.type||"int",d=u.name||this.getVarName(a),h=u.start,l=u.end,f=u.condition,y=u.update,typeof h=="number"?h=h.toString():h&&h.isNode&&(h=h.build(t,p)),typeof l=="number"?l=l.toString():l&&l.isNode&&(l=l.build(t,p)),h!==void 0&&l===void 0?(h=h+" - 1",l="0",f=">="):l!==void 0&&h===void 0&&(h="0",f="<"),f===void 0&&(Number(h)>Number(l)?f=">=":f="<"));const N={start:h,end:l},A=N.start,x=N.end;let w="",g="",m="";y||(p==="int"||p==="uint"?f.includes("<")?y="++":y="--":f.includes("<")?y="+= 1.":y="-= 1."),w+=t.getVar(p,d)+" = "+A,g+=d+" "+f+" "+x,m+=d+" "+y;const M=`for ( ${w}; ${g}; ${m} )`;t.addFlowCode((a===0?`
|
|
14
|
+
`);return t.format(u,s,e)}}const ni=R(Kc);F("select",ni),F("cond",(...r)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),ni(...r)));class th extends U{static get type(){return"ContextNode"}constructor(t,e={}){super(),this.isContextNode=!0,this.node=t,this.value=e}getScope(){return this.node.getScope()}getNodeType(t){return this.node.getNodeType(t)}analyze(t){this.node.build(t)}setup(t){const e=t.getContext();t.setContext({...t.context,...this.value});const s=this.node.build(t);return t.setContext(e),s}generate(t,e){const s=t.getContext();t.setContext({...t.context,...this.value});const n=this.node.build(t,e);return t.setContext(s),n}}const br=R(th),eh=(r,t)=>br(r,{label:t});F("context",br),F("label",eh);class sh extends U{static get type(){return"VarNode"}constructor(t,e=null){super(),this.node=t,this.name=e,this.global=!0,this.isVarNode=!0}getHash(t){return this.name||super.getHash(t)}getNodeType(t){return this.node.getNodeType(t)}generate(t){const{node:e,name:s}=this,n=t.getVarFromNode(this,s,t.getVectorType(this.getNodeType(t))),i=t.getPropertyName(n),o=e.build(t,n.type);return t.addLineFlowCode(`${i} = ${o}`,this),i}}const Er=R(sh);F("temp",Er),F("toVar",(...r)=>Er(...r).append());class nh extends U{static get type(){return"VaryingNode"}constructor(t,e=null){super(),this.node=t,this.name=e,this.isVaryingNode=!0}isGlobal(){return!0}getHash(t){return this.name||super.getHash(t)}getNodeType(t){return this.node.getNodeType(t)}setupVarying(t){const e=t.getNodeProperties(this);let s=e.varying;if(s===void 0){const n=this.name,i=this.getNodeType(t);e.varying=s=t.getVaryingFromNode(this,n,i),e.node=this.node}return s.needsInterpolation||(s.needsInterpolation=t.shaderStage==="fragment"),s}setup(t){this.setupVarying(t)}analyze(t){return this.setupVarying(t),this.node.analyze(t)}generate(t){const e=t.getNodeProperties(this),s=this.setupVarying(t);if(e.propertyName===void 0){const n=this.getNodeType(t),i=t.getPropertyName(s,rr.VERTEX);t.flowNodeFromShaderStage(rr.VERTEX,this.node,n,i),e.propertyName=i}return t.getPropertyName(s)}}const He=R(nh);F("varying",He);const us="WorkingColorSpace",ii="OutputColorSpace";function Cr(r){let t=null;return r===Es?t="Linear":r===Wt&&(t="sRGB"),t}function ih(r,t){return Cr(r)+"To"+Cr(t)}class Gs extends gt{static get type(){return"ColorSpaceNode"}constructor(t,e,s){super("vec4"),this.colorNode=t,this.source=e,this.target=s}getColorSpace(t,e){return e===us?Tt.workingColorSpace:e===ii?t.context.outputColorSpace||t.renderer.outputColorSpace:e}setup(t){const{renderer:e}=t,{colorNode:s}=this,n=this.getColorSpace(t,this.source),i=this.getColorSpace(t,this.target);if(n===i)return s;const o=ih(n,i);let a=null;const c=e.nodes.library.getColorSpaceFunction(o);return c!==null?a=Ve(c(s.rgb),s.a):(console.error("ColorSpaceNode: Unsupported Color Space configuration.",o),a=s),a}}const rh=r=>v(new Gs(v(r),us,ii)),oh=r=>v(new Gs(v(r),ii,us)),ah=(r,t)=>v(new Gs(v(r),us,t)),Fr=(r,t)=>v(new Gs(v(r),t,us));F("toOutputColorSpace",rh),F("toWorkingColorSpace",oh),F("workingToColorSpace",ah),F("colorSpaceToWorking",Fr);let ch=class extends hs{static get type(){return"ReferenceElementNode"}constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),s=this.referenceNode.getNodeType(),n=this.getNodeType();return t.format(e,s,n)}};class hh extends U{static get type(){return"ReferenceBaseNode"}constructor(t,e,s=null,n=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=n,this.properties=t.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=j.OBJECT}setGroup(t){return this.group=t,this}element(t){return v(new ch(this,v(t)))}setNodeType(t){const e=At(null,t).getSelf();this.group!==null&&e.setGroup(this.group),this.node=e}getNodeType(t){return this.node===null&&(this.updateReference(t),this.updateValue()),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let s=t[e[0]];for(let n=1;n<e.length;n++)s=s[e[n]];return s}updateReference(t){return this.reference=this.object!==null?this.object:t.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);const t=this.getValueFromReference();Array.isArray(t)?this.node.array=t:this.node.value=t}}class uh extends hh{static get type(){return"RendererReferenceNode"}constructor(t,e,s=null){super(t,e,s),this.renderer=s,this.setGroup(ye)}updateReference(t){return this.reference=this.renderer!==null?this.renderer:t.renderer,this.reference}}const lh=(r,t,e)=>v(new uh(r,t,e));class dh extends gt{static get type(){return"ToneMappingNode"}constructor(t,e=ph,s=null){super("vec3"),this.toneMapping=t,this.exposureNode=e,this.colorNode=s}getCacheKey(){return na(super.getCacheKey(),this.toneMapping)}setup(t){const e=this.colorNode||t.context.color,s=this.toneMapping;if(s===0)return e;let n=null;const i=t.renderer.nodes.library.getToneMappingFunction(s);return i!==null?n=Ve(i(e.rgb,this.exposureNode),e.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),n=e),n}}const fh=(r,t,e)=>v(new dh(r,v(t),v(e))),ph=lh("toneMappingExposure","float");F("toneMapping",(r,t,e)=>fh(t,e,r));class mh extends $n{static get type(){return"BufferAttributeNode"}constructor(t,e=null,s=0,n=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferStride=s,this.bufferOffset=n,this.usage=35044,this.instanced=!1,this.attribute=null,this.global=!0,t&&t.isBufferAttribute===!0&&(this.attribute=t,this.usage=t.usage,this.instanced=t.isInstancedBufferAttribute)}getHash(t){if(this.bufferStride===0&&this.bufferOffset===0){let e=t.globalCache.getData(this.value);return e===void 0&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getNodeType(t){return this.bufferType===null&&(this.bufferType=t.getTypeFromAttribute(this.attribute)),this.bufferType}setup(t){if(this.attribute!==null)return;const e=this.getNodeType(t),s=this.value,n=t.getTypeLength(e),i=this.bufferStride||n,o=this.bufferOffset,a=s.isInterleavedBuffer===!0?s:new ea(s,i),c=new kn(a,n,o);a.setUsage(this.usage),this.attribute=c,this.attribute.isInstancedBufferAttribute=this.instanced}generate(t){const e=this.getNodeType(t),s=t.getBufferAttributeFromNode(this,e),n=t.getPropertyName(s);let i=null;return t.shaderStage==="vertex"||t.shaderStage==="compute"?(this.name=n,i=n):i=He(this).build(t,e),i}getInputType(){return"bufferAttribute"}setUsage(t){return this.usage=t,this.attribute&&this.attribute.isBufferAttribute===!0&&(this.attribute.usage=t),this}setInstanced(t){return this.instanced=t,this}}const yh=(r,t,e,s)=>v(new mh(r,t,e,s));F("toAttribute",r=>yh(r.value));class gh extends U{static get type(){return"ComputeNode"}constructor(t,e,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=t,this.count=e,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=j.OBJECT,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){t===!0&&this.version++}updateDispatchCount(){const{count:t,workgroupSize:e}=this;let s=e[0];for(let n=1;n<e.length;n++)s*=e[n];this.dispatchCount=Math.ceil(t/s)}onInit(){}updateBefore({renderer:t}){t.compute(this)}generate(t){const{shaderStage:e}=t;if(e==="compute"){const s=this.computeNode.build(t,"void");s!==""&&t.addLineFlowCode(s,this)}}}F("compute",(r,t,e)=>v(new gh(v(r),t,e)));class xh extends U{static get type(){return"CacheNode"}constructor(t,e=!0){super(),this.node=t,this.parent=e,this.isCacheNode=!0}getNodeType(t){return this.node.getNodeType(t)}build(t,...e){const s=t.getCache(),n=t.getCacheFromNode(this,this.parent);t.setCache(n);const i=this.node.build(t,...e);return t.setCache(s),i}}F("cache",(r,...t)=>v(new xh(v(r),...t)));class Th extends U{static get type(){return"BypassNode"}constructor(t,e){super(),this.isBypassNode=!0,this.outputNode=t,this.callNode=e}getNodeType(t){return this.outputNode.getNodeType(t)}generate(t){const e=this.callNode.build(t,"void");return e!==""&&t.addLineFlowCode(e,this),this.outputNode.build(t)}}F("bypass",R(Th));class Br extends U{static get type(){return"RemapNode"}constructor(t,e,s,n=q(0),i=q(1)){super(),this.node=t,this.inLowNode=e,this.inHighNode=s,this.outLowNode=n,this.outHighNode=i,this.doClamp=!0}setup(){const{node:t,inLowNode:e,inHighNode:s,outLowNode:n,outHighNode:i,doClamp:o}=this;let a=t.sub(e).div(s.sub(e));return o===!0&&(a=a.clamp()),a.mul(i.sub(n)).add(n)}}const Nh=R(Br,null,null,{doClamp:!1}),wh=R(Br);F("remap",Nh),F("remapClamp",wh);class Ah extends U{static get type(){return"ExpressionNode"}constructor(t="",e="void"){super(e),this.snippet=t}generate(t,e){const s=this.getNodeType(t),n=this.snippet;if(s==="void")t.addLineFlowCode(n,this);else return t.format(`( ${n} )`,s,e)}}const Xs=R(Ah);F("discard",r=>(r?ni(r,Xs("discard")):Xs("discard")).append());class Sh extends gt{static get type(){return"RenderOutputNode"}constructor(t,e,s){super("vec4"),this.colorNode=t,this.toneMapping=e,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:t}){let e=this.colorNode||t.color;const s=(this.toneMapping!==null?this.toneMapping:t.toneMapping)||0,n=(this.outputColorSpace!==null?this.outputColorSpace:t.outputColorSpace)||"";return s!==0&&(e=e.toneMapping(s)),n!==""&&n!==Tt.workingColorSpace&&(e=e.workingToColorSpace(n)),e}}F("renderOutput",(r,t=null,e=null)=>v(new Sh(v(r),t,e)));class Mh extends U{static get type(){return"AttributeNode"}constructor(t,e=null){super(e),this.global=!0,this._attributeName=t}getHash(t){return this.getAttributeName(t)}getNodeType(t){let e=this.nodeType;if(e===null){const s=this.getAttributeName(t);if(t.hasGeometryAttribute(s)){const n=t.geometry.getAttribute(s);e=t.getTypeFromAttribute(n)}else e="float"}return e}setAttributeName(t){return this._attributeName=t,this}getAttributeName(){return this._attributeName}generate(t){const e=this.getAttributeName(t),s=this.getNodeType(t);if(t.hasGeometryAttribute(e)===!0){const i=t.geometry.getAttribute(e),o=t.getTypeFromAttribute(i),a=t.getAttribute(e,o);return t.shaderStage==="vertex"?t.format(a.name,o,s):He(this).build(t,s)}else return console.warn(`AttributeNode: Vertex attribute "${e}" not found on geometry.`),t.generateConst(s)}serialize(t){super.serialize(t),t.global=this.global,t._attributeName=this._attributeName}deserialize(t){super.deserialize(t),this.global=t.global,this._attributeName=t._attributeName}}const ls=(r,t)=>v(new Mh(r,t)),Ys=r=>ls("uv"+(r>0?r:""),"vec2");class _h extends U{static get type(){return"TextureSizeNode"}constructor(t,e=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=t,this.levelNode=e}generate(t,e){const s=this.textureNode.build(t,"property"),n=this.levelNode===null?"0":this.levelNode.build(t,"int");return t.format(`${t.getMethod("textureDimensions")}( ${s}, ${n} )`,this.getNodeType(t),e)}}const Rr=R(_h);class zh extends Ue{static get type(){return"MaxMipLevelNode"}constructor(t){super(0),this._textureNode=t,this.updateType=j.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const t=this.texture,e=t.images,s=e&&e.length>0?e[0]&&e[0].image||e[0]:t.image;if(s&&s.width!==void 0){const{width:n,height:i}=s;this.value=Math.log2(Math.max(n,i))}}}const bh=R(zh);class Zs extends Ue{static get type(){return"TextureNode"}constructor(t,e=null,s=null,n=null){super(t),this.isTextureNode=!0,this.uvNode=e,this.levelNode=s,this.biasNode=n,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=j.NONE,this.referenceNode=null,this._value=t,this._matrixUniform=null,this.setUpdateMatrix(e===null)}set value(t){this.referenceNode?this.referenceNode.value=t:this._value=t}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return this.value.isDepthTexture===!0?"float":this.value.type===1014?"uvec4":this.value.type===1013?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return Ys(this.value.channel)}updateReference(){return this.value}getTransformedUV(t){return this._matrixUniform===null&&(this._matrixUniform=At(this.value.matrix)),this._matrixUniform.mul(k(t,1)).xy}setUpdateMatrix(t){return this.updateMatrix=t,this.updateType=t?j.FRAME:j.NONE,this}setupUV(t,e){const s=this.value;return t.isFlipY()&&(s.isRenderTargetTexture===!0||s.isFramebufferTexture===!0||s.isDepthTexture===!0)&&(this.sampler?e=e.flipY():e=e.setY(De(Rr(this,this.levelNode).y).sub(e.y).sub(1))),e}setup(t){const e=t.getNodeProperties(this);e.referenceNode=this.referenceNode;let s=this.uvNode;(s===null||t.context.forceUVContext===!0)&&t.context.getUV&&(s=t.context.getUV(this)),s||(s=this.getDefaultUV()),this.updateMatrix===!0&&(s=this.getTransformedUV(s)),s=this.setupUV(t,s);let n=this.levelNode;n===null&&t.context.getTextureLevel&&(n=t.context.getTextureLevel(this)),e.uvNode=s,e.levelNode=n,e.biasNode=this.biasNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.depthNode=this.depthNode}generateUV(t,e){return e.build(t,this.sampler===!0?"vec2":"ivec2")}generateSnippet(t,e,s,n,i,o,a,c){const u=this.value;let h;return n?h=t.generateTextureLevel(u,e,s,n,o):i?h=t.generateTextureBias(u,e,s,i,o):c?h=t.generateTextureGrad(u,e,s,c,o):a?h=t.generateTextureCompare(u,e,s,a,o):this.sampler===!1?h=t.generateTextureLoad(u,e,s,o):h=t.generateTexture(u,e,s,o),h}generate(t,e){const s=t.getNodeProperties(this),n=this.value;if(!n||n.isTexture!==!0)throw new Error("TextureNode: Need a three.js texture.");const i=super.generate(t,"property");if(e==="sampler")return i+"_sampler";if(t.isReference(e))return i;{const o=t.getDataFromNode(this);let a=o.propertyName;if(a===void 0){const{uvNode:h,levelNode:l,biasNode:d,compareNode:f,depthNode:p,gradNode:m}=s,T=this.generateUV(t,h),A=l?l.build(t,"float"):null,g=d?d.build(t,"float"):null,N=p?p.build(t,"int"):null,x=f?f.build(t,"float"):null,y=m?[m[0].build(t,"vec2"),m[1].build(t,"vec2")]:null,M=t.getVarFromNode(this);a=t.getPropertyName(M);const S=this.generateSnippet(t,i,T,A,g,N,x,y);t.addLineFlowCode(`${a} = ${S}`,this),o.snippet=S,o.propertyName=a}let c=a;const u=this.getNodeType(t);return t.needsToWorkingColorSpace(n)&&(c=Fr(Xs(c,u),n.colorSpace).setup(t).build(t,u)),t.format(c,u,e)}}setSampler(t){return this.sampler=t,this}getSampler(){return this.sampler}uv(t){const e=this.clone();return e.uvNode=v(t),e.referenceNode=this.getSelf(),v(e)}blur(t){const e=this.clone();return e.biasNode=v(t).mul(bh(e)),e.referenceNode=this.getSelf(),v(e)}level(t){const e=this.clone();return e.levelNode=v(t),e.referenceNode=this.getSelf(),v(e)}size(t){return Rr(this,t)}bias(t){const e=this.clone();return e.biasNode=v(t),e.referenceNode=this.getSelf(),v(e)}compare(t){const e=this.clone();return e.compareNode=v(t),e.referenceNode=this.getSelf(),v(e)}grad(t,e){const s=this.clone();return s.gradNode=[v(t),v(e)],s.referenceNode=this.getSelf(),v(s)}depth(t){const e=this.clone();return e.depthNode=v(t),e.referenceNode=this.getSelf(),v(e)}serialize(t){super.serialize(t),t.value=this.value.toJSON(t.meta).uuid,t.sampler=this.sampler,t.updateMatrix=this.updateMatrix,t.updateType=this.updateType}deserialize(t){super.deserialize(t),this.value=t.meta.textures[t.value],this.sampler=t.sampler,this.updateMatrix=t.updateMatrix,this.updateType=t.updateType}update(){const t=this.value,e=this._matrixUniform;e!==null&&(e.value=t.matrix),t.matrixAutoUpdate===!0&&t.updateMatrix()}clone(){const t=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return t.sampler=this.sampler,t}}const ds=R(Zs),fs=At("float").label("cameraNear").setGroup(ye).onRenderUpdate(({camera:r})=>r.near),ps=At("float").label("cameraFar").setGroup(ye).onRenderUpdate(({camera:r})=>r.far),Js=At("mat4").label("cameraViewMatrix").setGroup(ye).onRenderUpdate(({camera:r})=>r.matrixWorldInverse);class H extends U{static get type(){return"Object3DNode"}constructor(t,e=null){super(),this.scope=t,this.object3d=e,this.updateType=j.OBJECT,this._uniformNode=new Ue(null)}getNodeType(){const t=this.scope;if(t===H.WORLD_MATRIX)return"mat4";if(t===H.POSITION||t===H.VIEW_POSITION||t===H.DIRECTION||t===H.SCALE)return"vec3"}update(t){const e=this.object3d,s=this._uniformNode,n=this.scope;if(n===H.WORLD_MATRIX)s.value=e.matrixWorld;else if(n===H.POSITION)s.value=s.value||new _,s.value.setFromMatrixPosition(e.matrixWorld);else if(n===H.SCALE)s.value=s.value||new _,s.value.setFromMatrixScale(e.matrixWorld);else if(n===H.DIRECTION)s.value=s.value||new _,e.getWorldDirection(s.value);else if(n===H.VIEW_POSITION){const i=t.camera;s.value=s.value||new _,s.value.setFromMatrixPosition(e.matrixWorld),s.value.applyMatrix4(i.matrixWorldInverse)}}generate(t){const e=this.scope;return e===H.WORLD_MATRIX?this._uniformNode.nodeType="mat4":(e===H.POSITION||e===H.VIEW_POSITION||e===H.DIRECTION||e===H.SCALE)&&(this._uniformNode.nodeType="vec3"),this._uniformNode.build(t)}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}}H.WORLD_MATRIX="worldMatrix",H.POSITION="position",H.SCALE="scale",H.VIEW_POSITION="viewPosition",H.DIRECTION="direction",H.DIRECTION,H.WORLD_MATRIX,H.POSITION,H.SCALE,H.VIEW_POSITION;class Ht extends H{static get type(){return"ModelNode"}constructor(t){super(t)}update(t){this.object3d=t.object,super.update(t)}}Ht.DIRECTION;const Eh=O(Ht,Ht.WORLD_MATRIX);Ht.POSITION,Ht.SCALE,Ht.VIEW_POSITION;const Ch=At(new Rt).onObjectUpdate(({object:r},t)=>t.value.getNormalMatrix(r.matrixWorld)),Ir=Js.mul(Eh).toVar("modelViewMatrix_2"),Fh=ls("position","vec3").varying("positionLocal"),zt=Ir.mul(Fh).xyz.varying("v_positionView"),Pr=zt.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class Bh extends U{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(t){const{renderer:e,material:s}=t;return e.coordinateSystem===2e3&&s.side===1?"false":t.getFrontFacing()}}const ri=q(O(Bh)).mul(2).sub(1),Rh=ls("normal","vec3"),Ih=tt(r=>r.geometry.hasAttribute("normal")===!1?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),k(0,1,0)):Rh,"vec3").once()().toVar("normalLocal"),Ph=zt.dFdx().cross(zt.dFdy()).normalize().toVar("normalFlat"),qe=tt(r=>{let t;return r.material.flatShading===!0?t=Ph:t=He(Lr(Ih),"v_normalView").normalize(),t},"vec3").once()().toVar("normalView"),vr=tt(r=>r.context.setupNormal(),"vec3").once()().mul(ri).toVar("transformedNormalView"),Lr=tt(([r],t)=>{const e=t.renderer.nodes.modelNormalViewMatrix;if(e!==null)return e.transformDirection(r);const s=Ch.mul(r);return Js.transformDirection(s)}),vh=At(0).onReference(({material:r})=>r).onRenderUpdate(({material:r})=>r.refractionRatio),Lh=Pr.negate().reflect(vr),Oh=Pr.negate().refract(vr,vh),Dh=Lh.transformDirection(Js).toVar("reflectVector"),Vh=Oh.transformDirection(Js).toVar("reflectVector");class Uh extends Zs{static get type(){return"CubeTextureNode"}constructor(t,e=null,s=null,n=null){super(t,e,s,n),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const t=this.value;return t.mapping===301?Dh:t.mapping===302?Vh:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',t.mapping),k(0,0,0))}setUpdateMatrix(){}setupUV(t,e){const s=this.value;return t.renderer.coordinateSystem===2001||!s.isRenderTargetTexture?k(e.x.negate(),e.yz):e}generateUV(t,e){return e.build(t,"vec3")}}const kh=R(Uh);class Or extends Ue{static get type(){return"BufferNode"}constructor(t,e,s=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferCount=s}getElementType(t){return this.getNodeType(t)}getInputType(){return"buffer"}}const Hh=(r,t,e)=>v(new Or(r,t,e));class qh extends hs{static get type(){return"UniformArrayElementNode"}constructor(t,e){super(t,e),this.isArrayBufferElementNode=!0}generate(t){const e=super.generate(t),s=this.getNodeType();return t.format(e,"vec4",s)}}class $h extends Or{static get type(){return"UniformArrayNode"}constructor(t,e=null){super(null,"vec4"),this.array=t,this.elementType=e,this._elementType=null,this._elementLength=0,this.updateType=j.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:t,value:e}=this,s=this.getElementLength(),n=this.getElementType();if(s===1)for(let i=0;i<t.length;i++){const o=i*4;e[o]=t[i]}else if(n==="color")for(let i=0;i<t.length;i++){const o=i*4,a=t[i];e[o]=a.r,e[o+1]=a.g,e[o+2]=a.b||0}else for(let i=0;i<t.length;i++){const o=i*4,a=t[i];e[o]=a.x,e[o+1]=a.y,e[o+2]=a.z||0,e[o+3]=a.w||0}}setup(t){const e=this.array.length;this._elementType=this.elementType===null?Ds(this.array[0]):this.elementType,this._elementLength=t.getTypeLength(this._elementType);let s=Float32Array;return this._elementType.charAt(0)==="i"?s=Int32Array:this._elementType.charAt(0)==="u"&&(s=Uint32Array),this.value=new s(e*4),this.bufferCount=e,this.bufferType=t.changeComponentType("vec4",t.getComponentType(this._elementType)),super.setup(t)}element(t){return v(new qh(this,v(t)))}}const oi=(r,t)=>v(new $h(r,t));class Wh extends hs{static get type(){return"ReferenceElementNode"}constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),s=this.referenceNode.getNodeType(),n=this.getNodeType();return t.format(e,s,n)}}class Dr extends U{static get type(){return"ReferenceNode"}constructor(t,e,s=null,n=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=n,this.properties=t.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=j.OBJECT}element(t){return v(new Wh(this,v(t)))}setGroup(t){return this.group=t,this}label(t){return this.name=t,this}setNodeType(t){let e=null;this.count!==null?e=Hh(null,t,this.count):Array.isArray(this.getValueFromReference())?e=oi(null,t):t==="texture"?e=ds(null):t==="cubeTexture"?e=kh(null):e=At(null,t),this.group!==null&&e.setGroup(this.group),this.name!==null&&e.label(this.name),this.node=e.getSelf()}getNodeType(t){return this.node===null&&(this.updateReference(t),this.updateValue()),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let s=t[e[0]];for(let n=1;n<e.length;n++)s=s[e[n]];return s}updateReference(t){return this.reference=this.object!==null?this.object:t.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);const t=this.getValueFromReference();Array.isArray(t)?this.node.array=t:this.node.value=t}}const xe=(r,t,e)=>v(new Dr(r,t,e));class Gh extends Dr{static get type(){return"MaterialReferenceNode"}constructor(t,e,s=null){super(t,e,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(t){return this.reference=this.material!==null?this.material:t.material,this.reference}}const Xh=(r,t,e)=>v(new Gh(r,t,e)),Vr=tt(r=>(r.geometry.hasAttribute("tangent")===!1&&r.geometry.computeTangents(),ls("tangent","vec4")))(),Yh=Vr.xyz.toVar("tangentLocal"),Ur=Ir.mul(Ve(Yh,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Zh=Hs(Ur,He((r=>r.mul(Vr.w).xyz)(qe.cross(Ur)),"v_bitangentView").normalize().toVar("bitangentView"),qe),Jh=tt(r=>{const{eye_pos:t,surf_norm:e,mapN:s,uv:n}=r,i=t.dFdx(),o=t.dFdy(),a=n.dFdx(),c=n.dFdy(),u=e,h=o.cross(u),l=u.cross(i),d=h.mul(a.x).add(l.mul(c.x)),f=h.mul(a.y).add(l.mul(c.y)),p=d.dot(d).max(f.dot(f)),m=ri.mul(p.inverseSqrt());return ge(d.mul(s.x,m),f.mul(s.y,m),u.mul(s.z)).normalize()});class Qh extends gt{static get type(){return"NormalMapNode"}constructor(t,e=null){super("vec3"),this.node=t,this.scaleNode=e,this.normalMapType=0}setup(t){const{normalMapType:e,scaleNode:s}=this;let n=this.node.mul(2).sub(1);s!==null&&(n=k(n.xy.mul(s),n.z));let i=null;return e===1?i=Lr(n):e===0&&(t.hasGeometryAttribute("tangent")===!0?i=Zh.mul(n).normalize():i=Jh({eye_pos:zt,surf_norm:qe,mapN:n,uv:Ys()})),i}}const kr=R(Qh),jh=tt(({textureNode:r,bumpScale:t})=>{const e=n=>r.cache().context({getUV:i=>n(i.uvNode||Ys()),forceUVContext:!0}),s=q(e(n=>n));return V(q(e(n=>n.add(n.dFdx()))).sub(s),q(e(n=>n.add(n.dFdy()))).sub(s)).mul(t)}),Kh=tt(r=>{const{surf_pos:t,surf_norm:e,dHdxy:s}=r,n=t.dFdx().normalize(),i=t.dFdy().normalize(),o=e,a=i.cross(o),c=o.cross(n),u=n.dot(a).mul(ri),h=u.sign().mul(s.x.mul(a).add(s.y.mul(c)));return u.abs().mul(e).sub(h).normalize()});class tu extends gt{static get type(){return"BumpMapNode"}constructor(t,e=null){super("vec3"),this.textureNode=t,this.scaleNode=e}setup(){const t=this.scaleNode!==null?this.scaleNode:1,e=jh({textureNode:this.textureNode,bumpScale:t});return Kh({surf_pos:zt,surf_norm:qe,dHdxy:e})}}const eu=R(tu),Hr=new Map;class E extends U{static get type(){return"MaterialNode"}constructor(t){super(),this.scope=t}getCache(t,e){let s=Hr.get(t);return s===void 0&&(s=Xh(t,e),Hr.set(t,s)),s}getFloat(t){return this.getCache(t,"float")}getColor(t){return this.getCache(t,"color")}getTexture(t){return this.getCache(t==="map"?"map":t+"Map","texture")}setup(t){const e=t.context.material,s=this.scope;let n=null;if(s===E.COLOR){const i=e.color!==void 0?this.getColor(s):k();e.map&&e.map.isTexture===!0?n=i.mul(this.getTexture("map")):n=i}else if(s===E.OPACITY){const i=this.getFloat(s);e.alphaMap&&e.alphaMap.isTexture===!0?n=i.mul(this.getTexture("alpha")):n=i}else if(s===E.SPECULAR_STRENGTH)e.specularMap&&e.specularMap.isTexture===!0?n=this.getTexture("specular").r:n=q(1);else if(s===E.SPECULAR_INTENSITY){const i=this.getFloat(s);e.specularMap?n=i.mul(this.getTexture(s).a):n=i}else if(s===E.SPECULAR_COLOR){const i=this.getColor(s);e.specularColorMap&&e.specularColorMap.isTexture===!0?n=i.mul(this.getTexture(s).rgb):n=i}else if(s===E.ROUGHNESS){const i=this.getFloat(s);e.roughnessMap&&e.roughnessMap.isTexture===!0?n=i.mul(this.getTexture(s).g):n=i}else if(s===E.METALNESS){const i=this.getFloat(s);e.metalnessMap&&e.metalnessMap.isTexture===!0?n=i.mul(this.getTexture(s).b):n=i}else if(s===E.EMISSIVE){const i=this.getFloat("emissiveIntensity"),o=this.getColor(s).mul(i);e.emissiveMap&&e.emissiveMap.isTexture===!0?n=o.mul(this.getTexture(s)):n=o}else if(s===E.NORMAL)e.normalMap?(n=kr(this.getTexture("normal"),this.getCache("normalScale","vec2")),n.normalMapType=e.normalMapType):e.bumpMap?n=eu(this.getTexture("bump").r,this.getFloat("bumpScale")):n=qe;else if(s===E.CLEARCOAT){const i=this.getFloat(s);e.clearcoatMap&&e.clearcoatMap.isTexture===!0?n=i.mul(this.getTexture(s).r):n=i}else if(s===E.CLEARCOAT_ROUGHNESS){const i=this.getFloat(s);e.clearcoatRoughnessMap&&e.clearcoatRoughnessMap.isTexture===!0?n=i.mul(this.getTexture(s).r):n=i}else if(s===E.CLEARCOAT_NORMAL)e.clearcoatNormalMap?n=kr(this.getTexture(s),this.getCache(s+"Scale","vec2")):n=qe;else if(s===E.SHEEN){const i=this.getColor("sheenColor").mul(this.getFloat("sheen"));e.sheenColorMap&&e.sheenColorMap.isTexture===!0?n=i.mul(this.getTexture("sheenColor").rgb):n=i}else if(s===E.SHEEN_ROUGHNESS){const i=this.getFloat(s);e.sheenRoughnessMap&&e.sheenRoughnessMap.isTexture===!0?n=i.mul(this.getTexture(s).a):n=i,n=n.clamp(.07,1)}else if(s===E.ANISOTROPY)if(e.anisotropyMap&&e.anisotropyMap.isTexture===!0){const i=this.getTexture(s);n=mr(ms.x,ms.y,ms.y.negate(),ms.x).mul(i.rg.mul(2).sub(V(1)).normalize().mul(i.b))}else n=ms;else if(s===E.IRIDESCENCE_THICKNESS){const i=xe("1","float",e.iridescenceThicknessRange);if(e.iridescenceThicknessMap){const o=xe("0","float",e.iridescenceThicknessRange);n=i.sub(o).mul(this.getTexture(s).g).add(o)}else n=i}else if(s===E.TRANSMISSION){const i=this.getFloat(s);e.transmissionMap?n=i.mul(this.getTexture(s).r):n=i}else if(s===E.THICKNESS){const i=this.getFloat(s);e.thicknessMap?n=i.mul(this.getTexture(s).g):n=i}else if(s===E.IOR)n=this.getFloat(s);else if(s===E.LIGHT_MAP)n=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===E.AO_MAP)n=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const i=this.getNodeType(t);n=this.getCache(s,i)}return n}}E.ALPHA_TEST="alphaTest",E.COLOR="color",E.OPACITY="opacity",E.SHININESS="shininess",E.SPECULAR="specular",E.SPECULAR_STRENGTH="specularStrength",E.SPECULAR_INTENSITY="specularIntensity",E.SPECULAR_COLOR="specularColor",E.REFLECTIVITY="reflectivity",E.ROUGHNESS="roughness",E.METALNESS="metalness",E.NORMAL="normal",E.CLEARCOAT="clearcoat",E.CLEARCOAT_ROUGHNESS="clearcoatRoughness",E.CLEARCOAT_NORMAL="clearcoatNormal",E.EMISSIVE="emissive",E.ROTATION="rotation",E.SHEEN="sheen",E.SHEEN_ROUGHNESS="sheenRoughness",E.ANISOTROPY="anisotropy",E.IRIDESCENCE="iridescence",E.IRIDESCENCE_IOR="iridescenceIOR",E.IRIDESCENCE_THICKNESS="iridescenceThickness",E.IOR="ior",E.TRANSMISSION="transmission",E.THICKNESS="thickness",E.ATTENUATION_DISTANCE="attenuationDistance",E.ATTENUATION_COLOR="attenuationColor",E.LINE_SCALE="scale",E.LINE_DASH_SIZE="dashSize",E.LINE_GAP_SIZE="gapSize",E.LINE_WIDTH="linewidth",E.LINE_DASH_OFFSET="dashOffset",E.POINT_WIDTH="pointWidth",E.DISPERSION="dispersion",E.LIGHT_MAP="light",E.AO_MAP="ao",E.ALPHA_TEST,E.COLOR,E.SHININESS,E.EMISSIVE,E.OPACITY,E.SPECULAR,E.SPECULAR_INTENSITY,E.SPECULAR_COLOR,E.SPECULAR_STRENGTH,E.REFLECTIVITY,E.ROUGHNESS,E.METALNESS,E.CLEARCOAT,E.CLEARCOAT_ROUGHNESS,E.ROTATION,E.SHEEN,E.SHEEN_ROUGHNESS,E.ANISOTROPY,E.IRIDESCENCE,E.IRIDESCENCE_IOR,E.IRIDESCENCE_THICKNESS,E.TRANSMISSION,E.THICKNESS,E.IOR,E.ATTENUATION_DISTANCE,E.ATTENUATION_COLOR,E.LINE_SCALE,E.LINE_DASH_SIZE,E.LINE_GAP_SIZE,E.LINE_WIDTH,E.LINE_DASH_OFFSET,E.POINT_WIDTH,E.DISPERSION,E.LIGHT_MAP,E.AO_MAP;const ms=At(new Z).onReference(function(r){return r.material}).onRenderUpdate(function({material:r}){this.value.set(r.anisotropy*Math.cos(r.anisotropyRotation),r.anisotropy*Math.sin(r.anisotropyRotation))});class G extends U{static get type(){return"IndexNode"}constructor(t){super("uint"),this.scope=t,this.isInstanceIndexNode=!0}generate(t){const e=this.getNodeType(t),s=this.scope;let n;if(s===G.VERTEX)n=t.getVertexIndex();else if(s===G.INSTANCE)n=t.getInstanceIndex();else if(s===G.DRAW)n=t.getDrawIndex();else if(s===G.INVOCATION_LOCAL)n=t.getInvocationLocalIndex();else if(s===G.INVOCATION_SUBGROUP)n=t.getInvocationSubgroupIndex();else if(s===G.SUBGROUP)n=t.getSubgroupIndex();else throw new Error("THREE.IndexNode: Unknown scope: "+s);let i;return t.shaderStage==="vertex"||t.shaderStage==="compute"?i=n:i=He(this).build(t,e),i}}G.VERTEX="vertex",G.INSTANCE="instance",G.SUBGROUP="subgroup",G.INVOCATION_LOCAL="invocationLocal",G.INVOCATION_SUBGROUP="invocationSubgroup",G.DRAW="draw",G.VERTEX,G.INSTANCE,G.SUBGROUP,G.INVOCATION_SUBGROUP,G.INVOCATION_LOCAL,G.DRAW;class su extends U{static get type(){return"LoopNode"}constructor(t=[]){super(),this.params=t}getVarName(t){return String.fromCharCode(105+t)}getProperties(t){const e=t.getNodeProperties(this);if(e.stackNode!==void 0)return e;const s={};for(let i=0,o=this.params.length-1;i<o;i++){const a=this.params[i],c=a.isNode!==!0&&a.name||this.getVarName(i),u=a.isNode!==!0&&a.type||"int";s[c]=Xs(c,u)}const n=t.addStack();return e.returnsNode=this.params[this.params.length-1](s,n,t),e.stackNode=n,t.removeStack(),e}getNodeType(t){const{returnsNode:e}=this.getProperties(t);return e?e.getNodeType(t):"void"}setup(t){this.getProperties(t)}generate(t){const e=this.getProperties(t),s=this.params,n=e.stackNode;for(let a=0,c=s.length-1;a<c;a++){const u=s[a];let h=null,l=null,d=null,f=null,p=null,m=null;u.isNode?(f="int",d=this.getVarName(a),h="0",l=u.build(t,f),p="<"):(f=u.type||"int",d=u.name||this.getVarName(a),h=u.start,l=u.end,p=u.condition,m=u.update,typeof h=="number"?h=h.toString():h&&h.isNode&&(h=h.build(t,f)),typeof l=="number"?l=l.toString():l&&l.isNode&&(l=l.build(t,f)),h!==void 0&&l===void 0?(h=h+" - 1",l="0",p=">="):l!==void 0&&h===void 0&&(h="0",p="<"),p===void 0&&(Number(h)>Number(l)?p=">=":p="<"));const T={start:h,end:l},A=T.start,g=T.end;let N="",x="",y="";m||(f==="int"||f==="uint"?p.includes("<")?m="++":m="--":p.includes("<")?m="+= 1.":m="-= 1."),N+=t.getVar(f,d)+" = "+A,x+=d+" "+p+" "+g,y+=d+" "+m;const M=`for ( ${N}; ${x}; ${y} )`;t.addFlowCode((a===0?`
|
|
15
15
|
`:"")+t.tab+M+` {
|
|
16
16
|
|
|
17
17
|
`).addFlowTab()}const i=n.build(t,"void"),o=e.returnsNode?e.returnsNode.build(t):"";t.removeFlowTab().addFlowCode(`
|
|
18
18
|
`+t.tab+i);for(let a=0,c=this.params.length-1;a<c;a++)t.addFlowCode((a===0?"":t.tab)+`}
|
|
19
19
|
|
|
20
|
-
`).removeFlowTab();return t.addFlowTab(),o}}const ke=(...r)=>v(new eu(Pe(r,"int"))).append();let fs,ms;class et extends U{static get type(){return"ScreenNode"}constructor(t){super(),this.scope=t,this.isViewportNode=!0}getNodeType(){return this.scope===et.VIEWPORT?"vec4":"vec2"}getUpdateType(){let t=j.NONE;return(this.scope===et.SIZE||this.scope===et.VIEWPORT)&&(t=j.RENDER),this.updateType=t,t}update({renderer:t}){const e=t.getRenderTarget();this.scope===et.VIEWPORT?e!==null?ms.copy(e.viewport):(t.getViewport(ms),ms.multiplyScalar(t.getPixelRatio())):e!==null?(fs.width=e.width,fs.height=e.height):t.getDrawingBufferSize(fs)}setup(){const t=this.scope;let e=null;return t===et.SIZE?e=Tt(fs||(fs=new Z)):t===et.VIEWPORT?e=Tt(ms||(ms=new It)):e=V(Qs.div(Hr)),e}generate(t){if(this.scope===et.COORDINATE){let e=t.getFragCoord();if(t.isFlipY()){const s=t.getNodeProperties(Hr).outputNode.build(t);e=`${t.getType("vec2")}( ${e}.x, ${s}.y - ${e}.y )`}return e}return super.generate(t)}}et.COORDINATE="coordinate",et.VIEWPORT="viewport",et.SIZE="size",et.UV="uv";const ci=O(et,et.UV),Hr=O(et,et.SIZE),Qs=O(et,et.COORDINATE),qr=O(et,et.VIEWPORT);qr.zw,qr.xy;const ys=new Z;class su extends Zs{static get type(){return"ViewportTextureNode"}constructor(t=ci,e=null,s=null){s===null&&(s=new ea,s.minFilter=1008),super(s,t,e),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=j.FRAME}updateBefore(t){const e=t.renderer;e.getDrawingBufferSize(ys);const s=this.value;(s.image.width!==ys.width||s.image.height!==ys.height)&&(s.image.width=ys.width,s.image.height=ys.height,s.needsUpdate=!0);const n=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,e.copyFramebufferToTexture(s),s.generateMipmaps=n}clone(){const t=new this.constructor(this.uvNode,this.levelNode,this.value);return t.generateMipmaps=this.generateMipmaps,t}}let hi=null;class nu extends su{static get type(){return"ViewportDepthTextureNode"}constructor(t=ci,e=null){hi===null&&(hi=new er),super(t,e,hi)}}const iu=B(nu);class ft extends U{static get type(){return"ViewportDepthNode"}constructor(t,e=null){super("float"),this.scope=t,this.valueNode=e,this.isViewportDepthNode=!0}generate(t){const{scope:e}=this;return e===ft.DEPTH_BASE?t.getFragDepth():super.generate(t)}setup({camera:t}){const{scope:e}=this,s=this.valueNode;let n=null;if(e===ft.DEPTH_BASE)s!==null&&(n=Wr().assign(s));else if(e===ft.DEPTH)t.isPerspectiveCamera?n=ru(_t.z,ls,ds):n=js(_t.z,ls,ds);else if(e===ft.LINEAR_DEPTH)if(s!==null)if(t.isPerspectiveCamera){const i=$r(s,ls,ds);n=js(i,ls,ds)}else n=s;else n=js(_t.z,ls,ds);return n}}ft.DEPTH_BASE="depthBase",ft.DEPTH="depth",ft.LINEAR_DEPTH="linearDepth";const js=(r,t,e)=>r.add(t).div(t.sub(e)),ru=(r,t,e)=>t.add(r).mul(e).div(e.sub(t).mul(r)),$r=(r,t,e)=>t.mul(e).div(e.sub(t).mul(r).sub(e)),Wr=B(ft,ft.DEPTH_BASE),ou=O(ft,ft.DEPTH),au=B(ft,ft.LINEAR_DEPTH);iu(),ou.assign=r=>Wr(r);class gs extends U{static get type(){return"ClippingNode"}constructor(t=gs.DEFAULT){super(),this.scope=t}setup(t){super.setup(t);const e=t.clippingContext,{localClipIntersection:s,localClippingCount:n,globalClippingCount:i}=e,o=i+n,a=s?o-n:o;return this.scope===gs.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(e.planes,o,a):this.setupDefault(e.planes,o,a)}setupAlphaToCoverage(t,e,s){return tt(()=>{const n=ai(t),i=De("float","distanceToPlane"),o=De("float","distanceToGradient"),a=De("float","clipOpacity");a.assign(1);let c;if(ke(s,({i:u})=>{c=n.element(u),i.assign(_t.dot(c.xyz).negate().add(c.w)),o.assign(i.fwidth().div(2)),a.mulAssign(ni(o.negate(),o,i)),a.equal(0).discard()}),s<e){const u=De("float","unionclipOpacity");u.assign(1),ke({start:s,end:e},({i:h})=>{c=n.element(h),i.assign(_t.dot(c.xyz).negate().add(c.w)),o.assign(i.fwidth().div(2)),u.mulAssign(ni(o.negate(),o,i).oneMinus())}),a.mulAssign(u.oneMinus())}gr.a.mulAssign(a),gr.a.equal(0).discard()})()}setupDefault(t,e,s){return tt(()=>{const n=ai(t);let i;if(ke(s,({i:o})=>{i=n.element(o),_t.dot(i.xyz).greaterThan(i.w).discard()}),s<e){const o=De("bool","clipped");o.assign(!0),ke({start:s,end:e},({i:a})=>{i=n.element(a),o.assign(_t.dot(i.xyz).greaterThan(i.w).and(o))}),o.discard()}})()}}gs.ALPHA_TO_COVERAGE="alphaToCoverage",gs.DEFAULT="default",H(.04),$(1);const cu=tt(([r,t])=>{const e=r.toVar();e.assign($s(2,e).sub(1));const s=H(e,1).toVar();return Qn(t.equal(0),()=>{s.assign(s.zyx)}).ElseIf(t.equal(1),()=>{s.assign(s.xzy),s.xz.mulAssign(-1)}).ElseIf(t.equal(2),()=>{s.x.mulAssign(-1)}).ElseIf(t.equal(3),()=>{s.assign(s.zyx),s.xz.mulAssign(-1)}).ElseIf(t.equal(4),()=>{s.assign(s.xzy),s.xy.mulAssign(-1)}).ElseIf(t.equal(5),()=>{s.z.mulAssign(-1)}),s}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]});tt(({texture:r,uv:t})=>{const s=H().toVar();return Qn(t.x.lessThan(1e-4),()=>{s.assign(H(1,0,0))}).ElseIf(t.y.lessThan(1e-4),()=>{s.assign(H(0,1,0))}).ElseIf(t.z.lessThan(1e-4),()=>{s.assign(H(0,0,1))}).ElseIf(t.x.greaterThan(1-1e-4),()=>{s.assign(H(-1,0,0))}).ElseIf(t.y.greaterThan(1-1e-4),()=>{s.assign(H(0,-1,0))}).ElseIf(t.z.greaterThan(1-1e-4),()=>{s.assign(H(0,0,-1))}).Else(()=>{const i=r.uv(t.add(H(-.01,0,0))).r.sub(r.uv(t.add(H(.01,0,0))).r),o=r.uv(t.add(H(0,-.01,0))).r.sub(r.uv(t.add(H(0,.01,0))).r),a=r.uv(t.add(H(0,0,-.01))).r.sub(r.uv(t.add(H(0,0,.01))).r);s.assign(H(i,o,a))}),s.normalize()});const ui=cu(Ys(),hs("faceIndex")).normalize();H(ui.x,ui.y.negate(),ui.z);class Dt extends Oe{static get type(){return"TimerNode"}constructor(t=Dt.LOCAL,e=1,s=0){super(s),this.scope=t,this.scale=e,this.updateType=j.FRAME}update(t){const e=this.scope,s=this.scale;e===Dt.LOCAL?this.value+=t.deltaTime*s:e===Dt.DELTA?this.value=t.deltaTime*s:e===Dt.FRAME?this.value=t.frameId:this.value=t.time*s}serialize(t){super.serialize(t),t.scope=this.scope,t.scale=this.scale}deserialize(t){super.deserialize(t),this.scope=t.scope,this.scale=t.scale}}Dt.LOCAL="local",Dt.GLOBAL="global",Dt.DELTA="delta",Dt.FRAME="frame";const hu=(r,t=0)=>v(new Dt(Dt.LOCAL,r,t));class rt extends U{static get type(){return"OscNode"}constructor(t=rt.SINE,e=hu()){super(),this.method=t,this.timeNode=e}getNodeType(t){return this.timeNode.getNodeType(t)}setup(){const t=this.method,e=v(this.timeNode);let s=null;return t===rt.SINE?s=e.add(.75).mul(Math.PI*2).sin().mul(.5).add(.5):t===rt.SQUARE?s=e.fract().round():t===rt.TRIANGLE?s=e.add(.5).fract().mul(2).sub(1).abs():t===rt.SAWTOOTH&&(s=e.fract()),s}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}rt.SINE="sine",rt.SQUARE="square",rt.TRIANGLE="triangle",rt.SAWTOOTH="sawtooth",rt.SINE,rt.SQUARE,rt.TRIANGLE,rt.SAWTOOTH,new kn,new _,new _,new _,new nt,new _(0,0,-1),new It,new _,new _,new It,new Z,new $i,ci.flipX();class qt extends U{static get type(){return"SceneNode"}constructor(t=qt.BACKGROUND_BLURRINESS,e=null){super(),this.scope=t,this.scene=e}setup(t){const e=this.scope,s=this.scene!==null?this.scene:t.scene;let n;return e===qt.BACKGROUND_BLURRINESS?n=xe("backgroundBlurriness","float",s):e===qt.BACKGROUND_INTENSITY?n=xe("backgroundIntensity","float",s):console.error("THREE.SceneNode: Unknown scope:",e),n}}qt.BACKGROUND_BLURRINESS="backgroundBlurriness",qt.BACKGROUND_INTENSITY="backgroundIntensity",qt.BACKGROUND_BLURRINESS,qt.BACKGROUND_INTENSITY;const uu=new Z;class lu extends Zs{static get type(){return"PassTextureNode"}constructor(t,e){super(e),this.passNode=t,this.setUpdateMatrix(!1)}setup(t){return t.object.isQuadMesh&&this.passNode.build(t),super.setup(t)}clone(){return new this.constructor(this.passNode,this.value)}}class Gr extends lu{static get type(){return"PassMultipleTextureNode"}constructor(t,e,s=!1){super(t,null),this.textureName=e,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(t){return this.updateTexture(),super.setup(t)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class Ks extends pt{static get type(){return"PassNode"}constructor(t,e,s,n={}){super("vec4"),this.scope=t,this.scene=e,this.camera=s,this.options=n,this._pixelRatio=1,this._width=1,this._height=1;const i=new er;i.isRenderTargetTexture=!0,i.name="depth";const o=new $i(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:1016,...n});o.texture.name="output",o.depthTexture=i,this.renderTarget=o,this.updateBeforeType=j.FRAME,this._textures={output:o.texture,depth:i},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=Tt(0),this._cameraFar=Tt(0),this._mrt=null,this.isPassNode=!0}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(t){let e=this._textures[t];return e===void 0&&(e=this.renderTarget.texture.clone(),e.isRenderTargetTexture=!0,e.name=t,this._textures[t]=e,this.renderTarget.textures.push(e)),e}getPreviousTexture(t){let e=this._previousTextures[t];return e===void 0&&(e=this.getTexture(t).clone(),e.isRenderTargetTexture=!0,this._previousTextures[t]=e),e}toggleTexture(t){const e=this._previousTextures[t];if(e!==void 0){const s=this._textures[t],n=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[n]=e,this._textures[t]=e,this._previousTextures[t]=s,this._textureNodes[t].updateTexture(),this._previousTextureNodes[t].updateTexture()}}getTextureNode(t="output"){let e=this._textureNodes[t];return e===void 0&&(this._textureNodes[t]=e=v(new Gr(this,t)),this._textureNodes[t].updateTexture()),e}getPreviousTextureNode(t="output"){let e=this._previousTextureNodes[t];return e===void 0&&(this._textureNodes[t]===void 0&&this.getTextureNode(t),this._previousTextureNodes[t]=e=v(new Gr(this,t,!0)),this._previousTextureNodes[t].updateTexture()),e}getViewZNode(t="depth"){let e=this._viewZNodes[t];if(e===void 0){const s=this._cameraNear,n=this._cameraFar;this._viewZNodes[t]=e=$r(this.getTextureNode(t),s,n)}return e}getLinearDepthNode(t="depth"){let e=this._linearDepthNodes[t];if(e===void 0){const s=this._cameraNear,n=this._cameraFar,i=this.getViewZNode(t);this._linearDepthNodes[t]=e=js(i,s,n)}return e}setup({renderer:t}){return this.renderTarget.samples=this.options.samples===void 0?t.samples:this.options.samples,t.backend.isWebGLBackend===!0&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===Ks.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){const{renderer:e}=t,{scene:s,camera:n}=this;this._pixelRatio=e.getPixelRatio();const i=e.getSize(uu);this.setSize(i.width,i.height);const o=e.getRenderTarget(),a=e.getMRT();this._cameraNear.value=n.near,this._cameraFar.value=n.far;for(const c in this._previousTextures)this.toggleTexture(c);e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),e.render(s,n),e.setRenderTarget(o),e.setMRT(a)}setSize(t,e){this._width=t,this._height=e;const s=this._width*this._pixelRatio,n=this._height*this._pixelRatio;this.renderTarget.setSize(s,n)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}Ks.COLOR="color",Ks.DEPTH="depth",tt(({depthTexture:r,shadowCoord:t})=>us(r,t.xy).compare(t.z)),tt(({depthTexture:r,shadowCoord:t,shadow:e})=>{const s=(y,N)=>us(r,y).compare(N),n=xe("mapSize","vec2",e).setGroup(ye),i=xe("radius","float",e).setGroup(ye),o=V(1).div(n),a=o.x.negate().mul(i),c=o.y.negate().mul(i),u=o.x.mul(i),h=o.y.mul(i),l=a.div(2),d=c.div(2),p=u.div(2),f=h.div(2);return ge(s(t.xy.add(V(a,c)),t.z),s(t.xy.add(V(0,c)),t.z),s(t.xy.add(V(u,c)),t.z),s(t.xy.add(V(l,d)),t.z),s(t.xy.add(V(0,d)),t.z),s(t.xy.add(V(p,d)),t.z),s(t.xy.add(V(a,0)),t.z),s(t.xy.add(V(l,0)),t.z),s(t.xy,t.z),s(t.xy.add(V(p,0)),t.z),s(t.xy.add(V(u,0)),t.z),s(t.xy.add(V(l,f)),t.z),s(t.xy.add(V(0,f)),t.z),s(t.xy.add(V(p,f)),t.z),s(t.xy.add(V(a,h)),t.z),s(t.xy.add(V(0,h)),t.z),s(t.xy.add(V(u,h)),t.z)).mul(1/17)}),tt(({depthTexture:r,shadowCoord:t,shadow:e})=>{const s=(h,l)=>us(r,h).compare(l),n=xe("mapSize","vec2",e).setGroup(ye),i=V(1).div(n),o=i.x,a=i.y,c=t.xy,u=Kn(c.mul(n).add(.5));return c.subAssign(u.mul(i)),ge(s(c,t.z),s(c.add(V(o,0)),t.z),s(c.add(V(0,a)),t.z),s(c.add(i),t.z),ae(s(c.add(V(o.negate(),0)),t.z),s(c.add(V(o.mul(2),0)),t.z),u.x),ae(s(c.add(V(o.negate(),a)),t.z),s(c.add(V(o.mul(2),a)),t.z),u.x),ae(s(c.add(V(0,a.negate())),t.z),s(c.add(V(0,a.mul(2))),t.z),u.y),ae(s(c.add(V(o,a.negate())),t.z),s(c.add(V(o,a.mul(2))),t.z),u.y),ae(ae(s(c.add(V(o.negate(),a.negate())),t.z),s(c.add(V(o.mul(2),a.negate())),t.z),u.x),ae(s(c.add(V(o.negate(),a.mul(2))),t.z),s(c.add(V(o.mul(2),a.mul(2))),t.z),u.x),u.y)).mul(1/9)}),tt(({depthTexture:r,shadowCoord:t})=>{const e=$(1).toVar(),s=us(r).uv(t.xy).rg,n=Mr(t.z,s.x);return Qn(n.notEqual($(1)),()=>{const i=t.z.sub(s.x),o=ei(0,s.y.mul(s.y));let a=o.div(o.add(i.mul(i)));a=Ws(qs(a,.3).div(.95-.3)),e.assign(Ws(ei(n,a)))}),e}),tt(({samples:r,radius:t,size:e,shadowPass:s})=>{const n=$(0).toVar(),i=$(0).toVar(),o=r.lessThanEqual($(1)).select($(0),$(2).div(r.sub(1))),a=r.lessThanEqual($(1)).select($(0),$(-1));ke({start:ve(0),end:ve(r),type:"int",condition:"<"},({i:u})=>{const h=a.add($(u).mul(o)),l=s.uv(ge(Qs.xy,V(0,h).mul(t)).div(e)).x;n.addAssign(l),i.addAssign(l.mul(l))}),n.divAssign(r),i.divAssign(r);const c=jn(i.sub(n.mul(n)));return V(n,c)}),tt(({samples:r,radius:t,size:e,shadowPass:s})=>{const n=$(0).toVar(),i=$(0).toVar(),o=r.lessThanEqual($(1)).select($(0),$(2).div(r.sub(1))),a=r.lessThanEqual($(1)).select($(0),$(-1));ke({start:ve(0),end:ve(r),type:"int",condition:"<"},({i:u})=>{const h=a.add($(u).mul(o)),l=s.uv(ge(Qs.xy,V(h,0).mul(t)).div(e));n.addAssign(l.x),i.addAssign(ge(l.y.mul(l.y),l.x.mul(l.x)))}),n.divAssign(r),i.divAssign(r);const c=jn(i.sub(n.mul(n)));return V(n,c)}),H(1.6605,-.1246,-.0182),H(-.5876,1.1329,-.1006),H(-.0728,-.0083,1.1187),H(.6274,.0691,.0164),H(.3293,.9195,.088),H(.0433,.0113,.8956);class du extends U{constructor(t){super(),this.scope=t}generate(t){const{scope:e}=this,{renderer:s}=t;s.backend.isWebGLBackend===!0?t.addFlowCode(` // ${e}Barrier
|
|
21
|
-
`):t.addLineFlowCode(`${e}Barrier()`,this)}}B(du);class $t extends pt{static get type(){return"AtomicFunctionNode"}constructor(t,e,s,n=null){super("uint"),this.method=t,this.pointerNode=e,this.valueNode=s,this.storeNode=n}getInputType(t){return this.pointerNode.getNodeType(t)}getNodeType(t){return this.getInputType(t)}generate(t){const e=this.method,s=this.getNodeType(t),n=this.getInputType(t),i=this.pointerNode,o=this.valueNode,a=[];a.push(`&${i.build(t,n)}`),a.push(o.build(t,n));const c=`${t.getMethod(e,s)}( ${a.join(", ")} )`;if(this.storeNode!==null){const u=this.storeNode.build(t,n);t.addLineFlowCode(`${u} = ${c}`,this)}else t.addLineFlowCode(c,this)}}if($t.ATOMIC_LOAD="atomicLoad",$t.ATOMIC_STORE="atomicStore",$t.ATOMIC_ADD="atomicAdd",$t.ATOMIC_SUB="atomicSub",$t.ATOMIC_MAX="atomicMax",$t.ATOMIC_MIN="atomicMin",$t.ATOMIC_AND="atomicAnd",$t.ATOMIC_OR="atomicOr",$t.ATOMIC_XOR="atomicXor",B($t),typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"169"}})),typeof window<"u"){try{self.location.href,window.__THREE__IMPORTS__||(window.__THREE__IMPORTS__=[]),window.__THREE__IMPORTS__.push({url:self.location.href,revision:"169"})}catch{}window.__THREE__?(console.warn("WARNING: Multiple instances of Three.js being imported. Existing: "+window.__THREE__+", new: 169"),console.warn(window.__THREE__IMPORTS__)):window.__THREE__="169"}const Xr=0,pu=1,fu=2,Yr=2,li=1.25,Zr=1,xs=32,tn=65535,mu=Math.pow(2,-24),di=Symbol("SKIP_GENERATION");function yu(r){return r.index?r.index.count:r.attributes.position.count}function He(r){return yu(r)/3}function gu(r,t=ArrayBuffer){return r>65535?new Uint32Array(new t(4*r)):new Uint16Array(new t(2*r))}function xu(r,t){if(!r.index){const e=r.attributes.position.count,s=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=gu(e,s);r.setIndex(new Ot(n,1));for(let i=0;i<e;i++)n[i]=i}}function Jr(r,t){const e=He(r),s=t||r.drawRange,n=s.start/3,i=(s.start+s.count)/3,o=Math.max(0,n),a=Math.min(e,i)-o;return[{offset:Math.floor(o),count:Math.floor(a)}]}function Qr(r,t){if(!r.groups||!r.groups.length)return Jr(r,t);const e=[],s=t||r.drawRange,n=s.start/3,i=(s.start+s.count)/3,o=[];for(const u of r.groups){const h=u.start/3,l=(u.start+u.count)/3;h<i&&l>n&&(o.push({pos:Math.max(n,h),isStart:!0}),o.push({pos:Math.min(i,l),isStart:!1}))}o.sort((u,h)=>u.pos!==h.pos?u.pos-h.pos:u.type==="end"?-1:1);let a=0,c=null;for(const u of o){const h=u.pos;a!==0&&h!==c&&e.push({offset:c,count:h-c}),a+=u.isStart?1:-1,c=h}return e}function pi(r,t,e,s,n){let i=1/0,o=1/0,a=1/0,c=-1/0,u=-1/0,h=-1/0,l=1/0,d=1/0,p=1/0,f=-1/0,y=-1/0,N=-1/0;const A=r.offset||0;for(let x=(t-A)*6,w=(t+e-A)*6;x<w;x+=6){const g=r[x+0],m=r[x+1],M=g-m,S=g+m;M<i&&(i=M),S>c&&(c=S),g<l&&(l=g),g>f&&(f=g);const z=r[x+2],R=r[x+3],F=z-R,P=z+R;F<o&&(o=F),P>u&&(u=P),z<d&&(d=z),z>y&&(y=z);const C=r[x+4],I=r[x+5],L=C-I,D=C+I;L<a&&(a=L),D>h&&(h=D),C<p&&(p=C),C>N&&(N=C)}s[0]=i,s[1]=o,s[2]=a,s[3]=c,s[4]=u,s[5]=h,n[0]=l,n[1]=d,n[2]=p,n[3]=f,n[4]=y,n[5]=N}function jr(r,t,e=null,s=null,n=null){const i=r.attributes.position,o=r.index?r.index.array:null,a=i.normalized;if(n===null)n=new Float32Array(e*6),n.offset=t;else if(t<0||e+t>n.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const c=i.array,u=i.offset||0;let h=3;i.isInterleavedBufferAttribute&&(h=i.data.stride);const l=["getX","getY","getZ"],d=n.offset;for(let p=t,f=t+e;p<f;p++){const N=(s?s[p]:p)*3,A=(p-d)*6;let x=N+0,w=N+1,g=N+2;o&&(x=o[x],w=o[w],g=o[g]),a||(x=x*h+u,w=w*h+u,g=g*h+u);for(let m=0;m<3;m++){let M,S,z;a?(M=i[l[m]](x),S=i[l[m]](w),z=i[l[m]](g)):(M=c[x+m],S=c[w+m],z=c[g+m]);let R=M;S<R&&(R=S),z<R&&(R=z);let F=M;S>F&&(F=S),z>F&&(F=z);const P=(F-R)/2,C=m*2;n[A+C+0]=R+P,n[A+C+1]=P+(Math.abs(R)+P)*mu}}return n}function J(r,t,e){return e.min.x=t[r],e.min.y=t[r+1],e.min.z=t[r+2],e.max.x=t[r+3],e.max.y=t[r+4],e.max.z=t[r+5],e}function Kr(r){let t=-1,e=-1/0;for(let s=0;s<3;s++){const n=r[s+3]-r[s];n>e&&(e=n,t=s)}return t}function to(r,t){t.set(r)}function eo(r,t,e){let s,n;for(let i=0;i<3;i++){const o=i+3;s=r[i],n=t[i],e[i]=s<n?s:n,s=r[o],n=t[o],e[o]=s>n?s:n}}function en(r,t,e){for(let s=0;s<3;s++){const n=t[r+2*s],i=t[r+2*s+1],o=n-i,a=n+i;o<e[s]&&(e[s]=o),a>e[s+3]&&(e[s+3]=a)}}function Ts(r){const t=r[3]-r[0],e=r[4]-r[1],s=r[5]-r[2];return 2*(t*e+e*s+s*t)}const jt=32,Tu=(r,t)=>r.candidate-t.candidate,ce=new Array(jt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),sn=new Float32Array(6);function Nu(r,t,e,s,n,i){let o=-1,a=0;if(i===Xr)o=Kr(t),o!==-1&&(a=(t[o]+t[o+3])/2);else if(i===pu)o=Kr(r),o!==-1&&(a=wu(e,s,n,o));else if(i===fu){const c=Ts(r);let u=li*n;const h=e.offset||0,l=(s-h)*6,d=(s+n-h)*6;for(let p=0;p<3;p++){const f=t[p],A=(t[p+3]-f)/jt;if(n<jt/4){const x=[...ce];x.length=n;let w=0;for(let m=l;m<d;m+=6,w++){const M=x[w];M.candidate=e[m+2*p],M.count=0;const{bounds:S,leftCacheBounds:z,rightCacheBounds:R}=M;for(let F=0;F<3;F++)R[F]=1/0,R[F+3]=-1/0,z[F]=1/0,z[F+3]=-1/0,S[F]=1/0,S[F+3]=-1/0;en(m,e,S)}x.sort(Tu);let g=n;for(let m=0;m<g;m++){const M=x[m];for(;m+1<g&&x[m+1].candidate===M.candidate;)x.splice(m+1,1),g--}for(let m=l;m<d;m+=6){const M=e[m+2*p];for(let S=0;S<g;S++){const z=x[S];M>=z.candidate?en(m,e,z.rightCacheBounds):(en(m,e,z.leftCacheBounds),z.count++)}}for(let m=0;m<g;m++){const M=x[m],S=M.count,z=n-M.count,R=M.leftCacheBounds,F=M.rightCacheBounds;let P=0;S!==0&&(P=Ts(R)/c);let C=0;z!==0&&(C=Ts(F)/c);const I=Zr+li*(P*S+C*z);I<u&&(o=p,u=I,a=M.candidate)}}else{for(let g=0;g<jt;g++){const m=ce[g];m.count=0,m.candidate=f+A+g*A;const M=m.bounds;for(let S=0;S<3;S++)M[S]=1/0,M[S+3]=-1/0}for(let g=l;g<d;g+=6){let S=~~((e[g+2*p]-f)/A);S>=jt&&(S=jt-1);const z=ce[S];z.count++,en(g,e,z.bounds)}const x=ce[jt-1];to(x.bounds,x.rightCacheBounds);for(let g=jt-2;g>=0;g--){const m=ce[g],M=ce[g+1];eo(m.bounds,M.rightCacheBounds,m.rightCacheBounds)}let w=0;for(let g=0;g<jt-1;g++){const m=ce[g],M=m.count,S=m.bounds,R=ce[g+1].rightCacheBounds;M!==0&&(w===0?to(S,sn):eo(S,sn,sn)),w+=M;let F=0,P=0;w!==0&&(F=Ts(sn)/c);const C=n-w;C!==0&&(P=Ts(R)/c);const I=Zr+li*(F*w+P*C);I<u&&(o=p,u=I,a=m.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${i} used.`);return{axis:o,pos:a}}function wu(r,t,e,s){let n=0;const i=r.offset;for(let o=t,a=t+e;o<a;o++)n+=r[(o-i)*6+s*2];return n/e}class fi{constructor(){this.boundingData=new Float32Array(6)}}function Au(r,t,e,s,n,i){let o=s,a=s+n-1;const c=i.pos,u=i.axis*2,h=e.offset||0;for(;;){for(;o<=a&&e[(o-h)*6+u]<c;)o++;for(;o<=a&&e[(a-h)*6+u]>=c;)a--;if(o<a){for(let l=0;l<3;l++){let d=t[o*3+l];t[o*3+l]=t[a*3+l],t[a*3+l]=d}for(let l=0;l<6;l++){const d=o-h,p=a-h,f=e[d*6+l];e[d*6+l]=e[p*6+l],e[p*6+l]=f}o++,a--}else return o}}function Su(r,t,e,s,n,i){let o=s,a=s+n-1;const c=i.pos,u=i.axis*2,h=e.offset||0;for(;;){for(;o<=a&&e[(o-h)*6+u]<c;)o++;for(;o<=a&&e[(a-h)*6+u]>=c;)a--;if(o<a){let l=r[o];r[o]=r[a],r[a]=l;for(let d=0;d<6;d++){const p=o-h,f=a-h,y=e[p*6+d];e[p*6+d]=e[f*6+d],e[f*6+d]=y}o++,a--}else return o}}function mt(r,t){return t[r+15]===65535}function Nt(r,t){return t[r+6]}function zt(r,t){return t[r+14]}function bt(r){return r+8}function Et(r,t){return t[r+6]}function so(r,t){return t[r+7]}function hd(r){return r}let no,Ns,nn,io;const Mu=Math.pow(2,32);function mi(r){return"count"in r?1:1+mi(r.left)+mi(r.right)}function _u(r,t,e){return no=new Float32Array(e),Ns=new Uint32Array(e),nn=new Uint16Array(e),io=new Uint8Array(e),yi(r,t)}function yi(r,t){const e=r/4,s=r/2,n="count"in t,i=t.boundingData;for(let o=0;o<6;o++)no[e+o]=i[o];if(n)if(t.buffer){const o=t.buffer;io.set(new Uint8Array(o),r);for(let a=r,c=r+o.byteLength;a<c;a+=xs){const u=a/2;mt(u,nn)||(Ns[a/4+6]+=e)}return r+o.byteLength}else{const o=t.offset,a=t.count;return Ns[e+6]=o,nn[s+14]=a,nn[s+15]=tn,r+xs}else{const o=t.left,a=t.right,c=t.splitAxis;let u;if(u=yi(r+xs,o),u/4>Mu)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Ns[e+6]=u/4,u=yi(u,a),Ns[e+7]=c,u}}function zu(r,t,e){const n=(r.index?r.index.count:r.attributes.position.count)/3>2**16,i=e.reduce((h,l)=>h+l.count,0),o=n?4:2,a=t?new SharedArrayBuffer(i*o):new ArrayBuffer(i*o),c=n?new Uint32Array(a):new Uint16Array(a);let u=0;for(let h=0;h<e.length;h++){const{offset:l,count:d}=e[h];for(let p=0;p<d;p++)c[u+p]=l+p;u+=d}return c}function bu(r,t,e,s,n){const{maxDepth:i,verbose:o,maxLeafTris:a,strategy:c,onProgress:u,indirect:h}=n,l=r._indirectBuffer,d=r.geometry,p=d.index?d.index.array:null,f=h?Su:Au,y=He(d),N=new Float32Array(6);let A=!1;const x=new fi;return pi(t,e,s,x.boundingData,N),g(x,e,s,N),x;function w(m){u&&u(m/y)}function g(m,M,S,z=null,R=0){if(!A&&R>=i&&(A=!0,o&&(console.warn(`MeshBVH: Max depth of ${i} reached when generating BVH. Consider increasing maxDepth.`),console.warn(d))),S<=a||R>=i)return w(M+S),m.offset=M,m.count=S,m;const F=Nu(m.boundingData,z,t,M,S,c);if(F.axis===-1)return w(M+S),m.offset=M,m.count=S,m;const P=f(l,p,t,M,S,F);if(P===M||P===M+S)w(M+S),m.offset=M,m.count=S;else{m.splitAxis=F.axis;const C=new fi,I=M,L=P-M;m.left=C,pi(t,I,L,C.boundingData,N),g(C,I,L,N,R+1);const D=new fi,k=P,ot=S-L;m.right=D,pi(t,k,ot,D.boundingData,N),g(D,k,ot,N,R+1)}return m}}function Eu(r,t){const e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=r.geometry;let n,i;if(t.indirect){const o=Qr(s,t.range),a=zu(s,t.useSharedArrayBuffer,o);r._indirectBuffer=a,n=jr(s,0,a.length,a),i=[{offset:0,count:a.length}]}else{xu(s,t);const o=Jr(s,t.range)[0];n=jr(s,o.offset,o.count),i=Qr(s,t.range)}r._roots=i.map(o=>{const a=bu(r,n,o.offset,o.count,t),c=mi(a),u=new e(xs*c);return _u(0,a,u),u})}class Kt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let s=1/0,n=-1/0;for(let i=0,o=t.length;i<o;i++){const c=t[i][e];s=c<s?c:s,n=c>n?c:n}this.min=s,this.max=n}setFromPoints(t,e){let s=1/0,n=-1/0;for(let i=0,o=e.length;i<o;i++){const a=e[i],c=t.dot(a);s=c<s?c:s,n=c>n?c:n}this.min=s,this.max=n}isSeparated(t){return this.min>t.max||t.min>this.max}}Kt.prototype.setFromBox=(function(){const r=new _;return function(e,s){const n=s.min,i=s.max;let o=1/0,a=-1/0;for(let c=0;c<=1;c++)for(let u=0;u<=1;u++)for(let h=0;h<=1;h++){r.x=n.x*c+i.x*(1-c),r.y=n.y*u+i.y*(1-u),r.z=n.z*h+i.z*(1-h);const l=e.dot(r);o=Math.min(l,o),a=Math.max(l,a)}this.min=o,this.max=a}})();const Cu=(function(){const r=new _,t=new _,e=new _;return function(n,i,o){const a=n.start,c=r,u=i.start,h=t;e.subVectors(a,u),r.subVectors(n.end,n.start),t.subVectors(i.end,i.start);const l=e.dot(h),d=h.dot(c),p=h.dot(h),f=e.dot(c),N=c.dot(c)*p-d*d;let A,x;N!==0?A=(l*d-f*p)/N:A=0,x=(l+A*d)/p,o.x=A,o.y=x}})(),gi=(function(){const r=new Z,t=new _,e=new _;return function(n,i,o,a){Cu(n,i,r);let c=r.x,u=r.y;if(c>=0&&c<=1&&u>=0&&u<=1){n.at(c,o),i.at(u,a);return}else if(c>=0&&c<=1){u<0?i.at(0,a):i.at(1,a),n.closestPointToPoint(a,!0,o);return}else if(u>=0&&u<=1){c<0?n.at(0,o):n.at(1,o),i.closestPointToPoint(o,!0,a);return}else{let h;c<0?h=n.start:h=n.end;let l;u<0?l=i.start:l=i.end;const d=t,p=e;if(n.closestPointToPoint(l,!0,t),i.closestPointToPoint(h,!0,e),d.distanceToSquared(l)<=p.distanceToSquared(h)){o.copy(d),a.copy(l);return}else{o.copy(h),a.copy(p);return}}}})(),Fu=(function(){const r=new _,t=new _,e=new kn,s=new Jt;return function(i,o){const{radius:a,center:c}=i,{a:u,b:h,c:l}=o;if(s.start=u,s.end=h,s.closestPointToPoint(c,!0,r).distanceTo(c)<=a||(s.start=u,s.end=l,s.closestPointToPoint(c,!0,r).distanceTo(c)<=a)||(s.start=h,s.end=l,s.closestPointToPoint(c,!0,r).distanceTo(c)<=a))return!0;const y=o.getPlane(e);if(Math.abs(y.distanceToPoint(c))<=a){const A=y.projectPoint(c,t);if(o.containsPoint(A))return!0}return!1}})(),Ru=["x","y","z"],te=1e-15,ro=te*te;function Ct(r){return Math.abs(r)<te}class Vt extends St{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new _),this.satBounds=new Array(4).fill().map(()=>new Kt),this.points=[this.a,this.b,this.c],this.plane=new kn,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new Jt,this.needsUpdate=!0}intersectsSphere(t){return Fu(t,this)}update(){const t=this.a,e=this.b,s=this.c,n=this.points,i=this.satAxes,o=this.satBounds,a=i[0],c=o[0];this.getNormal(a),c.setFromPoints(a,n);const u=i[1],h=o[1];u.subVectors(t,e),h.setFromPoints(u,n);const l=i[2],d=o[2];l.subVectors(e,s),d.setFromPoints(l,n);const p=i[3],f=o[3];p.subVectors(s,t),f.setFromPoints(p,n);const y=u.length(),N=l.length(),A=p.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,y<te?N<te||A<te?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(s)):N<te?A<te?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):A<te&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(s),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}Vt.prototype.closestPointToSegment=(function(){const r=new _,t=new _,e=new Jt;return function(n,i=null,o=null){const{start:a,end:c}=n,u=this.points;let h,l=1/0;for(let d=0;d<3;d++){const p=(d+1)%3;e.start.copy(u[d]),e.end.copy(u[p]),gi(e,n,r,t),h=r.distanceToSquared(t),h<l&&(l=h,i&&i.copy(r),o&&o.copy(t))}return this.closestPointToPoint(a,r),h=a.distanceToSquared(r),h<l&&(l=h,i&&i.copy(r),o&&o.copy(a)),this.closestPointToPoint(c,r),h=c.distanceToSquared(r),h<l&&(l=h,i&&i.copy(r),o&&o.copy(c)),Math.sqrt(l)}})(),Vt.prototype.intersectsTriangle=(function(){const r=new Vt,t=new Kt,e=new Kt,s=new _,n=new _,i=new _,o=new _,a=new Jt,c=new Jt,u=new _,h=new Z,l=new Z;function d(w,g,m,M){const S=s;!w.isDegenerateIntoPoint&&!w.isDegenerateIntoSegment?S.copy(w.plane.normal):S.copy(g.plane.normal);const z=w.satBounds,R=w.satAxes;for(let C=1;C<4;C++){const I=z[C],L=R[C];if(t.setFromPoints(L,g.points),I.isSeparated(t)||(o.copy(S).cross(L),t.setFromPoints(o,w.points),e.setFromPoints(o,g.points),t.isSeparated(e)))return!1}const F=g.satBounds,P=g.satAxes;for(let C=1;C<4;C++){const I=F[C],L=P[C];if(t.setFromPoints(L,w.points),I.isSeparated(t)||(o.crossVectors(S,L),t.setFromPoints(o,w.points),e.setFromPoints(o,g.points),t.isSeparated(e)))return!1}return m&&(M||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),m.start.set(0,0,0),m.end.set(0,0,0)),!0}function p(w,g,m,M,S,z,R,F,P,C,I){let L=R/(R-F);C.x=M+(S-M)*L,I.start.subVectors(g,w).multiplyScalar(L).add(w),L=R/(R-P),C.y=M+(z-M)*L,I.end.subVectors(m,w).multiplyScalar(L).add(w)}function f(w,g,m,M,S,z,R,F,P,C,I){if(S>0)p(w.c,w.a,w.b,M,g,m,P,R,F,C,I);else if(z>0)p(w.b,w.a,w.c,m,g,M,F,R,P,C,I);else if(F*P>0||R!=0)p(w.a,w.b,w.c,g,m,M,R,F,P,C,I);else if(F!=0)p(w.b,w.a,w.c,m,g,M,F,R,P,C,I);else if(P!=0)p(w.c,w.a,w.b,M,g,m,P,R,F,C,I);else return!0;return!1}function y(w,g,m,M){const S=g.degenerateSegment,z=w.plane.distanceToPoint(S.start),R=w.plane.distanceToPoint(S.end);return Ct(z)?Ct(R)?d(w,g,m,M):(m&&(m.start.copy(S.start),m.end.copy(S.start)),w.containsPoint(S.start)):Ct(R)?(m&&(m.start.copy(S.end),m.end.copy(S.end)),w.containsPoint(S.end)):w.plane.intersectLine(S,s)!=null?(m&&(m.start.copy(s),m.end.copy(s)),w.containsPoint(s)):!1}function N(w,g,m){const M=g.a;return Ct(w.plane.distanceToPoint(M))&&w.containsPoint(M)?(m&&(m.start.copy(M),m.end.copy(M)),!0):!1}function A(w,g,m){const M=w.degenerateSegment,S=g.a;return M.closestPointToPoint(S,!0,s),S.distanceToSquared(s)<ro?(m&&(m.start.copy(S),m.end.copy(S)),!0):!1}function x(w,g,m,M){if(w.isDegenerateIntoSegment)if(g.isDegenerateIntoSegment){const S=w.degenerateSegment,z=g.degenerateSegment,R=n,F=i;S.delta(R),z.delta(F);const P=s.subVectors(z.start,S.start),C=R.x*F.y-R.y*F.x;if(Ct(C))return!1;const I=(P.x*F.y-P.y*F.x)/C,L=-(R.x*P.y-R.y*P.x)/C;if(I<0||I>1||L<0||L>1)return!1;const D=S.start.z+R.z*I,k=z.start.z+F.z*L;return Ct(D-k)?(m&&(m.start.copy(S.start).addScaledVector(R,I),m.end.copy(S.start).addScaledVector(R,I)),!0):!1}else return g.isDegenerateIntoPoint?A(w,g,m):y(g,w,m,M);else{if(w.isDegenerateIntoPoint)return g.isDegenerateIntoPoint?g.a.distanceToSquared(w.a)<ro?(m&&(m.start.copy(w.a),m.end.copy(w.a)),!0):!1:g.isDegenerateIntoSegment?A(g,w,m):N(g,w,m);if(g.isDegenerateIntoPoint)return N(w,g,m);if(g.isDegenerateIntoSegment)return y(w,g,m,M)}}return function(g,m=null,M=!1){this.needsUpdate&&this.update(),g.isExtendedTriangle?g.needsUpdate&&g.update():(r.copy(g),r.update(),g=r);const S=x(this,g,m,M);if(S!==void 0)return S;const z=this.plane,R=g.plane;let F=R.distanceToPoint(this.a),P=R.distanceToPoint(this.b),C=R.distanceToPoint(this.c);Ct(F)&&(F=0),Ct(P)&&(P=0),Ct(C)&&(C=0);const I=F*P,L=F*C;if(I>0&&L>0)return!1;let D=z.distanceToPoint(g.a),k=z.distanceToPoint(g.b),ot=z.distanceToPoint(g.c);Ct(D)&&(D=0),Ct(k)&&(k=0),Ct(ot)&&(ot=0);const wt=D*k,At=D*ot;if(wt>0&&At>0)return!1;n.copy(z.normal),i.copy(R.normal);const de=n.cross(i);let pe=0,Bi=Math.abs(de.x);const mo=Math.abs(de.y);mo>Bi&&(Bi=mo,pe=1),Math.abs(de.z)>Bi&&(pe=2);const Qe=Ru[pe],pl=this.a[Qe],fl=this.b[Qe],ml=this.c[Qe],yl=g.a[Qe],gl=g.b[Qe],xl=g.c[Qe];if(f(this,pl,fl,ml,I,L,F,P,C,h,a))return d(this,g,m,M);if(f(g,yl,gl,xl,wt,At,D,k,ot,l,c))return d(this,g,m,M);if(h.y<h.x){const Ii=h.y;h.y=h.x,h.x=Ii,u.copy(a.start),a.start.copy(a.end),a.end.copy(u)}if(l.y<l.x){const Ii=l.y;l.y=l.x,l.x=Ii,u.copy(c.start),c.start.copy(c.end),c.end.copy(u)}return h.y<l.x||l.y<h.x?!1:(m&&(l.x>h.x?m.start.copy(c.start):m.start.copy(a.start),l.y<h.y?m.end.copy(c.end):m.end.copy(a.end)),!0)}})(),Vt.prototype.distanceToPoint=(function(){const r=new _;return function(e){return this.closestPointToPoint(e,r),e.distanceTo(r)}})(),Vt.prototype.distanceToTriangle=(function(){const r=new _,t=new _,e=["a","b","c"],s=new Jt,n=new Jt;return function(o,a=null,c=null){const u=a||c?s:null;if(this.intersectsTriangle(o,u))return(a||c)&&(a&&u.getCenter(a),c&&u.getCenter(c)),0;let h=1/0;for(let l=0;l<3;l++){let d;const p=e[l],f=o[p];this.closestPointToPoint(f,r),d=f.distanceToSquared(r),d<h&&(h=d,a&&a.copy(r),c&&c.copy(f));const y=this[p];o.closestPointToPoint(y,r),d=y.distanceToSquared(r),d<h&&(h=d,a&&a.copy(y),c&&c.copy(r))}for(let l=0;l<3;l++){const d=e[l],p=e[(l+1)%3];s.set(this[d],this[p]);for(let f=0;f<3;f++){const y=e[f],N=e[(f+1)%3];n.set(o[y],o[N]),gi(s,n,r,t);const A=r.distanceToSquared(t);A<h&&(h=A,a&&a.copy(r),c&&c.copy(t))}}return Math.sqrt(h)}})();class dt{constructor(t,e,s){this.isOrientedBox=!0,this.min=new _,this.max=new _,this.matrix=new nt,this.invMatrix=new nt,this.points=new Array(8).fill().map(()=>new _),this.satAxes=new Array(3).fill().map(()=>new _),this.satBounds=new Array(3).fill().map(()=>new Kt),this.alignedSatBounds=new Array(3).fill().map(()=>new Kt),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),s&&this.matrix.copy(s)}set(t,e,s){this.min.copy(t),this.max.copy(e),this.matrix.copy(s),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}dt.prototype.update=(function(){return function(){const t=this.matrix,e=this.min,s=this.max,n=this.points;for(let u=0;u<=1;u++)for(let h=0;h<=1;h++)for(let l=0;l<=1;l++){const d=1*u|2*h|4*l,p=n[d];p.x=u?s.x:e.x,p.y=h?s.y:e.y,p.z=l?s.z:e.z,p.applyMatrix4(t)}const i=this.satBounds,o=this.satAxes,a=n[0];for(let u=0;u<3;u++){const h=o[u],l=i[u],d=1<<u,p=n[d];h.subVectors(a,p),l.setFromPoints(h,n)}const c=this.alignedSatBounds;c[0].setFromPointsField(n,"x"),c[1].setFromPointsField(n,"y"),c[2].setFromPointsField(n,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),dt.prototype.intersectsBox=(function(){const r=new Kt;return function(e){this.needsUpdate&&this.update();const s=e.min,n=e.max,i=this.satBounds,o=this.satAxes,a=this.alignedSatBounds;if(r.min=s.x,r.max=n.x,a[0].isSeparated(r)||(r.min=s.y,r.max=n.y,a[1].isSeparated(r))||(r.min=s.z,r.max=n.z,a[2].isSeparated(r)))return!1;for(let c=0;c<3;c++){const u=o[c],h=i[c];if(r.setFromBox(u,e),h.isSeparated(r))return!1}return!0}})(),dt.prototype.intersectsTriangle=(function(){const r=new Vt,t=new Array(3),e=new Kt,s=new Kt,n=new _;return function(o){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(r.copy(o),r.update(),o=r);const a=this.satBounds,c=this.satAxes;t[0]=o.a,t[1]=o.b,t[2]=o.c;for(let d=0;d<3;d++){const p=a[d],f=c[d];if(e.setFromPoints(f,t),p.isSeparated(e))return!1}const u=o.satBounds,h=o.satAxes,l=this.points;for(let d=0;d<3;d++){const p=u[d],f=h[d];if(e.setFromPoints(f,l),p.isSeparated(e))return!1}for(let d=0;d<3;d++){const p=c[d];for(let f=0;f<4;f++){const y=h[f];if(n.crossVectors(p,y),e.setFromPoints(n,t),s.setFromPoints(n,l),e.isSeparated(s))return!1}}return!0}})(),dt.prototype.closestPointToPoint=(function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}})(),dt.prototype.distanceToPoint=(function(){const r=new _;return function(e){return this.closestPointToPoint(e,r),e.distanceTo(r)}})(),dt.prototype.distanceToBox=(function(){const r=["x","y","z"],t=new Array(12).fill().map(()=>new Jt),e=new Array(12).fill().map(()=>new Jt),s=new _,n=new _;return function(o,a=0,c=null,u=null){if(this.needsUpdate&&this.update(),this.intersectsBox(o))return(c||u)&&(o.getCenter(n),this.closestPointToPoint(n,s),o.closestPointToPoint(s,n),c&&c.copy(s),u&&u.copy(n)),0;const h=a*a,l=o.min,d=o.max,p=this.points;let f=1/0;for(let N=0;N<8;N++){const A=p[N];n.copy(A).clamp(l,d);const x=A.distanceToSquared(n);if(x<f&&(f=x,c&&c.copy(A),u&&u.copy(n),x<h))return Math.sqrt(x)}let y=0;for(let N=0;N<3;N++)for(let A=0;A<=1;A++)for(let x=0;x<=1;x++){const w=(N+1)%3,g=(N+2)%3,m=A<<w|x<<g,M=1<<N|A<<w|x<<g,S=p[m],z=p[M];t[y].set(S,z);const F=r[N],P=r[w],C=r[g],I=e[y],L=I.start,D=I.end;L[F]=l[F],L[P]=A?l[P]:d[P],L[C]=x?l[C]:d[P],D[F]=d[F],D[P]=A?l[P]:d[P],D[C]=x?l[C]:d[P],y++}for(let N=0;N<=1;N++)for(let A=0;A<=1;A++)for(let x=0;x<=1;x++){n.x=N?d.x:l.x,n.y=A?d.y:l.y,n.z=x?d.z:l.z,this.closestPointToPoint(n,s);const w=n.distanceToSquared(s);if(w<f&&(f=w,c&&c.copy(s),u&&u.copy(n),w<h))return Math.sqrt(w)}for(let N=0;N<12;N++){const A=t[N];for(let x=0;x<12;x++){const w=e[x];gi(A,w,s,n);const g=s.distanceToSquared(n);if(g<f&&(f=g,c&&c.copy(s),u&&u.copy(n),g<h))return Math.sqrt(g)}}return Math.sqrt(f)}})();class xi{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Bu extends xi{constructor(){super(()=>new Vt)}}const Ft=new Bu;class Iu{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=s=>{e&&t.push(e),e=s,this.float32Array=new Float32Array(s),this.uint16Array=new Uint16Array(s),this.uint32Array=new Uint32Array(s)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const X=new Iu;let he,qe;const $e=[],rn=new xi(()=>new ut);function Pu(r,t,e,s,n,i){he=rn.getPrimitive(),qe=rn.getPrimitive(),$e.push(he,qe),X.setBuffer(r._roots[t]);const o=Ti(0,r.geometry,e,s,n,i);X.clearBuffer(),rn.releasePrimitive(he),rn.releasePrimitive(qe),$e.pop(),$e.pop();const a=$e.length;return a>0&&(qe=$e[a-1],he=$e[a-2]),o}function Ti(r,t,e,s,n=null,i=0,o=0){const{float32Array:a,uint16Array:c,uint32Array:u}=X;let h=r*2;if(mt(h,c)){const d=Nt(r,u),p=zt(h,c);return J(r,a,he),s(d,p,!1,o,i+r,he)}else{let F=function(C){const{uint16Array:I,uint32Array:L}=X;let D=C*2;for(;!mt(D,I);)C=bt(C),D=C*2;return Nt(C,L)},P=function(C){const{uint16Array:I,uint32Array:L}=X;let D=C*2;for(;!mt(D,I);)C=Et(C,L),D=C*2;return Nt(C,L)+zt(D,I)};const d=bt(r),p=Et(r,u);let f=d,y=p,N,A,x,w;if(n&&(x=he,w=qe,J(f,a,x),J(y,a,w),N=n(x),A=n(w),A<N)){f=p,y=d;const C=N;N=A,A=C,x=w}x||(x=he,J(f,a,x));const g=mt(f*2,c),m=e(x,g,N,o+1,i+f);let M;if(m===Yr){const C=F(f),L=P(f)-C;M=s(C,L,!0,o+1,i+f,x)}else M=m&&Ti(f,t,e,s,n,i,o+1);if(M)return!0;w=qe,J(y,a,w);const S=mt(y*2,c),z=e(w,S,A,o+1,i+y);let R;if(z===Yr){const C=F(y),L=P(y)-C;R=s(C,L,!0,o+1,i+y,w)}else R=z&&Ti(y,t,e,s,n,i,o+1);return!!R}}const ws=new _,Ni=new _;function vu(r,t,e={},s=0,n=1/0){const i=s*s,o=n*n;let a=1/0,c=null;if(r.shapecast({boundsTraverseOrder:h=>(ws.copy(t).clamp(h.min,h.max),ws.distanceToSquared(t)),intersectsBounds:(h,l,d)=>d<a&&d<o,intersectsTriangle:(h,l)=>{h.closestPointToPoint(t,ws);const d=t.distanceToSquared(ws);return d<a&&(Ni.copy(ws),a=d,c=l),d<i}}),a===1/0)return null;const u=Math.sqrt(a);return e.point?e.point.copy(Ni):e.point=Ni.clone(),e.distance=u,e.faceIndex=c,e}const on=parseInt("169")>=169,Lu=parseInt("169")<=161,Te=new _,Ne=new _,we=new _,an=new Z,cn=new Z,hn=new Z,oo=new _,ao=new _,co=new _,As=new _;function Ou(r,t,e,s,n,i,o,a){let c;if(i===1?c=r.intersectTriangle(s,e,t,!0,n):c=r.intersectTriangle(t,e,s,i!==2,n),c===null)return null;const u=r.origin.distanceTo(n);return u<o||u>a?null:{distance:u,point:n.clone()}}function ho(r,t,e,s,n,i,o,a,c,u,h){Te.fromBufferAttribute(t,i),Ne.fromBufferAttribute(t,o),we.fromBufferAttribute(t,a);const l=Ou(r,Te,Ne,we,As,c,u,h);if(l){if(s){an.fromBufferAttribute(s,i),cn.fromBufferAttribute(s,o),hn.fromBufferAttribute(s,a),l.uv=new Z;const p=St.getInterpolation(As,Te,Ne,we,an,cn,hn,l.uv);on||(l.uv=p)}if(n){an.fromBufferAttribute(n,i),cn.fromBufferAttribute(n,o),hn.fromBufferAttribute(n,a),l.uv1=new Z;const p=St.getInterpolation(As,Te,Ne,we,an,cn,hn,l.uv1);on||(l.uv1=p),Lu&&(l.uv2=l.uv1)}if(e){oo.fromBufferAttribute(e,i),ao.fromBufferAttribute(e,o),co.fromBufferAttribute(e,a),l.normal=new _;const p=St.getInterpolation(As,Te,Ne,we,oo,ao,co,l.normal);l.normal.dot(r.direction)>0&&l.normal.multiplyScalar(-1),on||(l.normal=p)}const d={a:i,b:o,c:a,normal:new _,materialIndex:0};if(St.getNormal(Te,Ne,we,d.normal),l.face=d,l.faceIndex=i,on){const p=new _;St.getBarycoord(As,Te,Ne,we,p),l.barycoord=p}}return l}function uo(r){return r&&r.isMaterial?r.side:r}function un(r,t,e,s,n,i,o){const a=s*3;let c=a+0,u=a+1,h=a+2;const{index:l,groups:d}=r;r.index&&(c=l.getX(c),u=l.getX(u),h=l.getX(h));const{position:p,normal:f,uv:y,uv1:N}=r.attributes;if(Array.isArray(t)){const A=s*3;for(let x=0,w=d.length;x<w;x++){const{start:g,count:m,materialIndex:M}=d[x];if(A>=g&&A<g+m){const S=uo(t[M]),z=ho(e,p,f,y,N,c,u,h,S,i,o);if(z)if(z.faceIndex=s,z.face.materialIndex=M,n)n.push(z);else return z}}}else{const A=uo(t),x=ho(e,p,f,y,N,c,u,h,A,i,o);if(x)if(x.faceIndex=s,x.face.materialIndex=0,n)n.push(x);else return x}return null}function st(r,t,e,s){const n=r.a,i=r.b,o=r.c;let a=t,c=t+1,u=t+2;e&&(a=e.getX(a),c=e.getX(c),u=e.getX(u)),n.x=s.getX(a),n.y=s.getY(a),n.z=s.getZ(a),i.x=s.getX(c),i.y=s.getY(c),i.z=s.getZ(c),o.x=s.getX(u),o.y=s.getY(u),o.z=s.getZ(u)}function Du(r,t,e,s,n,i,o,a){const{geometry:c,_indirectBuffer:u}=r;for(let h=s,l=s+n;h<l;h++)un(c,t,e,h,i,o,a)}function Vu(r,t,e,s,n,i,o){const{geometry:a,_indirectBuffer:c}=r;let u=1/0,h=null;for(let l=s,d=s+n;l<d;l++){let p;p=un(a,t,e,l,null,i,o),p&&p.distance<u&&(h=p,u=p.distance)}return h}function Uu(r,t,e,s,n,i,o){const{geometry:a}=e,{index:c}=a,u=a.attributes.position;for(let h=r,l=t+r;h<l;h++){let d;if(d=h,st(o,d*3,c,u),o.needsUpdate=!0,s(o,d,n,i))return!0}return!1}function ku(r,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=r.geometry,s=e.index?e.index.array:null,n=e.attributes.position;let i,o,a,c,u=0;const h=r._roots;for(let d=0,p=h.length;d<p;d++)i=h[d],o=new Uint32Array(i),a=new Uint16Array(i),c=new Float32Array(i),l(0,u),u+=i.byteLength;function l(d,p,f=!1){const y=d*2;if(a[y+15]===tn){const A=o[d+6],x=a[y+14];let w=1/0,g=1/0,m=1/0,M=-1/0,S=-1/0,z=-1/0;for(let R=3*A,F=3*(A+x);R<F;R++){let P=s[R];const C=n.getX(P),I=n.getY(P),L=n.getZ(P);C<w&&(w=C),C>M&&(M=C),I<g&&(g=I),I>S&&(S=I),L<m&&(m=L),L>z&&(z=L)}return c[d+0]!==w||c[d+1]!==g||c[d+2]!==m||c[d+3]!==M||c[d+4]!==S||c[d+5]!==z?(c[d+0]=w,c[d+1]=g,c[d+2]=m,c[d+3]=M,c[d+4]=S,c[d+5]=z,!0):!1}else{const A=d+8,x=o[d+6],w=A+p,g=x+p;let m=f,M=!1,S=!1;t?m||(M=t.has(w),S=t.has(g),m=!M&&!S):(M=!0,S=!0);const z=m||M,R=m||S;let F=!1;z&&(F=l(A,p,m));let P=!1;R&&(P=l(x,p,m));const C=F||P;if(C)for(let I=0;I<3;I++){const L=A+I,D=x+I,k=c[L],ot=c[L+3],wt=c[D],At=c[D+3];c[d+I]=k<wt?k:wt,c[d+I+3]=ot>At?ot:At}return C}}}function ue(r,t,e,s,n){let i,o,a,c,u,h;const l=1/e.direction.x,d=1/e.direction.y,p=1/e.direction.z,f=e.origin.x,y=e.origin.y,N=e.origin.z;let A=t[r],x=t[r+3],w=t[r+1],g=t[r+3+1],m=t[r+2],M=t[r+3+2];return l>=0?(i=(A-f)*l,o=(x-f)*l):(i=(x-f)*l,o=(A-f)*l),d>=0?(a=(w-y)*d,c=(g-y)*d):(a=(g-y)*d,c=(w-y)*d),i>c||a>o||((a>i||isNaN(i))&&(i=a),(c<o||isNaN(o))&&(o=c),p>=0?(u=(m-N)*p,h=(M-N)*p):(u=(M-N)*p,h=(m-N)*p),i>h||u>o)?!1:((u>i||i!==i)&&(i=u),(h<o||o!==o)&&(o=h),i<=n&&o>=s)}function Hu(r,t,e,s,n,i,o,a){const{geometry:c,_indirectBuffer:u}=r;for(let h=s,l=s+n;h<l;h++){let d=u?u[h]:h;un(c,t,e,d,i,o,a)}}function qu(r,t,e,s,n,i,o){const{geometry:a,_indirectBuffer:c}=r;let u=1/0,h=null;for(let l=s,d=s+n;l<d;l++){let p;p=un(a,t,e,c?c[l]:l,null,i,o),p&&p.distance<u&&(h=p,u=p.distance)}return h}function $u(r,t,e,s,n,i,o){const{geometry:a}=e,{index:c}=a,u=a.attributes.position;for(let h=r,l=t+r;h<l;h++){let d;if(d=e.resolveTriangleIndex(h),st(o,d*3,c,u),o.needsUpdate=!0,s(o,d,n,i))return!0}return!1}function Wu(r,t,e,s,n,i,o){X.setBuffer(r._roots[t]),wi(0,r,e,s,n,i,o),X.clearBuffer()}function wi(r,t,e,s,n,i,o){const{float32Array:a,uint16Array:c,uint32Array:u}=X,h=r*2;if(mt(h,c)){const d=Nt(r,u),p=zt(h,c);Du(t,e,s,d,p,n,i,o)}else{const d=bt(r);ue(d,a,s,i,o)&&wi(d,t,e,s,n,i,o);const p=Et(r,u);ue(p,a,s,i,o)&&wi(p,t,e,s,n,i,o)}}const Gu=["x","y","z"];function Xu(r,t,e,s,n,i){X.setBuffer(r._roots[t]);const o=Ai(0,r,e,s,n,i);return X.clearBuffer(),o}function Ai(r,t,e,s,n,i){const{float32Array:o,uint16Array:a,uint32Array:c}=X;let u=r*2;if(mt(u,a)){const l=Nt(r,c),d=zt(u,a);return Vu(t,e,s,l,d,n,i)}else{const l=so(r,c),d=Gu[l],f=s.direction[d]>=0;let y,N;f?(y=bt(r),N=Et(r,c)):(y=Et(r,c),N=bt(r));const x=ue(y,o,s,n,i)?Ai(y,t,e,s,n,i):null;if(x){const m=x.point[d];if(f?m<=o[N+l]:m>=o[N+l+3])return x}const g=ue(N,o,s,n,i)?Ai(N,t,e,s,n,i):null;return x&&g?x.distance<=g.distance?x:g:x||g||null}}const ln=new ut,We=new Vt,Ge=new Vt,Ss=new nt,lo=new dt,dn=new dt;function Yu(r,t,e,s){X.setBuffer(r._roots[t]);const n=Si(0,r,e,s);return X.clearBuffer(),n}function Si(r,t,e,s,n=null){const{float32Array:i,uint16Array:o,uint32Array:a}=X;let c=r*2;if(n===null&&(e.boundingBox||e.computeBoundingBox(),lo.set(e.boundingBox.min,e.boundingBox.max,s),n=lo),mt(c,o)){const h=t.geometry,l=h.index,d=h.attributes.position,p=e.index,f=e.attributes.position,y=Nt(r,a),N=zt(c,o);if(Ss.copy(s).invert(),e.boundsTree)return J(r,i,dn),dn.matrix.copy(Ss),dn.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:x=>dn.intersectsBox(x),intersectsTriangle:x=>{x.a.applyMatrix4(s),x.b.applyMatrix4(s),x.c.applyMatrix4(s),x.needsUpdate=!0;for(let w=y*3,g=(N+y)*3;w<g;w+=3)if(st(Ge,w,l,d),Ge.needsUpdate=!0,x.intersectsTriangle(Ge))return!0;return!1}});{const A=He(e);for(let x=y*3,w=(N+y)*3;x<w;x+=3){st(We,x,l,d),We.a.applyMatrix4(Ss),We.b.applyMatrix4(Ss),We.c.applyMatrix4(Ss),We.needsUpdate=!0;for(let g=0,m=A*3;g<m;g+=3)if(st(Ge,g,p,f),Ge.needsUpdate=!0,We.intersectsTriangle(Ge))return!0}}}else{const h=r+8,l=a[r+6];return J(h,i,ln),!!(n.intersectsBox(ln)&&Si(h,t,e,s,n)||(J(l,i,ln),n.intersectsBox(ln)&&Si(l,t,e,s,n)))}}const pn=new nt,Mi=new dt,Ms=new dt,Zu=new _,Ju=new _,Qu=new _,ju=new _;function Ku(r,t,e,s={},n={},i=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Mi.set(t.boundingBox.min,t.boundingBox.max,e),Mi.needsUpdate=!0;const a=r.geometry,c=a.attributes.position,u=a.index,h=t.attributes.position,l=t.index,d=Ft.getPrimitive(),p=Ft.getPrimitive();let f=Zu,y=Ju,N=null,A=null;n&&(N=Qu,A=ju);let x=1/0,w=null,g=null;return pn.copy(e).invert(),Ms.matrix.copy(pn),r.shapecast({boundsTraverseOrder:m=>Mi.distanceToBox(m),intersectsBounds:(m,M,S)=>S<x&&S<o?(M&&(Ms.min.copy(m.min),Ms.max.copy(m.max),Ms.needsUpdate=!0),!0):!1,intersectsRange:(m,M)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:z=>Ms.distanceToBox(z),intersectsBounds:(z,R,F)=>F<x&&F<o,intersectsRange:(z,R)=>{for(let F=z,P=z+R;F<P;F++){st(p,3*F,l,h),p.a.applyMatrix4(e),p.b.applyMatrix4(e),p.c.applyMatrix4(e),p.needsUpdate=!0;for(let C=m,I=m+M;C<I;C++){st(d,3*C,u,c),d.needsUpdate=!0;const L=d.distanceToTriangle(p,f,N);if(L<x&&(y.copy(f),A&&A.copy(N),x=L,w=C,g=F),L<i)return!0}}}});{const S=He(t);for(let z=0,R=S;z<R;z++){st(p,3*z,l,h),p.a.applyMatrix4(e),p.b.applyMatrix4(e),p.c.applyMatrix4(e),p.needsUpdate=!0;for(let F=m,P=m+M;F<P;F++){st(d,3*F,u,c),d.needsUpdate=!0;const C=d.distanceToTriangle(p,f,N);if(C<x&&(y.copy(f),A&&A.copy(N),x=C,w=F,g=z),C<i)return!0}}}}}),Ft.releasePrimitive(d),Ft.releasePrimitive(p),x===1/0?null:(s.point?s.point.copy(y):s.point=y.clone(),s.distance=x,s.faceIndex=w,n&&(n.point?n.point.copy(A):n.point=A.clone(),n.point.applyMatrix4(pn),y.applyMatrix4(pn),n.distance=y.sub(n.point).length(),n.faceIndex=g),s)}function tl(r,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=r.geometry,s=e.index?e.index.array:null,n=e.attributes.position;let i,o,a,c,u=0;const h=r._roots;for(let d=0,p=h.length;d<p;d++)i=h[d],o=new Uint32Array(i),a=new Uint16Array(i),c=new Float32Array(i),l(0,u),u+=i.byteLength;function l(d,p,f=!1){const y=d*2;if(a[y+15]===tn){const A=o[d+6],x=a[y+14];let w=1/0,g=1/0,m=1/0,M=-1/0,S=-1/0,z=-1/0;for(let R=A,F=A+x;R<F;R++){const P=3*r.resolveTriangleIndex(R);for(let C=0;C<3;C++){let I=P+C;I=s?s[I]:I;const L=n.getX(I),D=n.getY(I),k=n.getZ(I);L<w&&(w=L),L>M&&(M=L),D<g&&(g=D),D>S&&(S=D),k<m&&(m=k),k>z&&(z=k)}}return c[d+0]!==w||c[d+1]!==g||c[d+2]!==m||c[d+3]!==M||c[d+4]!==S||c[d+5]!==z?(c[d+0]=w,c[d+1]=g,c[d+2]=m,c[d+3]=M,c[d+4]=S,c[d+5]=z,!0):!1}else{const A=d+8,x=o[d+6],w=A+p,g=x+p;let m=f,M=!1,S=!1;t?m||(M=t.has(w),S=t.has(g),m=!M&&!S):(M=!0,S=!0);const z=m||M,R=m||S;let F=!1;z&&(F=l(A,p,m));let P=!1;R&&(P=l(x,p,m));const C=F||P;if(C)for(let I=0;I<3;I++){const L=A+I,D=x+I,k=c[L],ot=c[L+3],wt=c[D],At=c[D+3];c[d+I]=k<wt?k:wt,c[d+I+3]=ot>At?ot:At}return C}}}function el(r,t,e,s,n,i,o){X.setBuffer(r._roots[t]),_i(0,r,e,s,n,i,o),X.clearBuffer()}function _i(r,t,e,s,n,i,o){const{float32Array:a,uint16Array:c,uint32Array:u}=X,h=r*2;if(mt(h,c)){const d=Nt(r,u),p=zt(h,c);Hu(t,e,s,d,p,n,i,o)}else{const d=bt(r);ue(d,a,s,i,o)&&_i(d,t,e,s,n,i,o);const p=Et(r,u);ue(p,a,s,i,o)&&_i(p,t,e,s,n,i,o)}}const sl=["x","y","z"];function nl(r,t,e,s,n,i){X.setBuffer(r._roots[t]);const o=zi(0,r,e,s,n,i);return X.clearBuffer(),o}function zi(r,t,e,s,n,i){const{float32Array:o,uint16Array:a,uint32Array:c}=X;let u=r*2;if(mt(u,a)){const l=Nt(r,c),d=zt(u,a);return qu(t,e,s,l,d,n,i)}else{const l=so(r,c),d=sl[l],f=s.direction[d]>=0;let y,N;f?(y=bt(r),N=Et(r,c)):(y=Et(r,c),N=bt(r));const x=ue(y,o,s,n,i)?zi(y,t,e,s,n,i):null;if(x){const m=x.point[d];if(f?m<=o[N+l]:m>=o[N+l+3])return x}const g=ue(N,o,s,n,i)?zi(N,t,e,s,n,i):null;return x&&g?x.distance<=g.distance?x:g:x||g||null}}const fn=new ut,Xe=new Vt,Ye=new Vt,_s=new nt,po=new dt,mn=new dt;function il(r,t,e,s){X.setBuffer(r._roots[t]);const n=bi(0,r,e,s);return X.clearBuffer(),n}function bi(r,t,e,s,n=null){const{float32Array:i,uint16Array:o,uint32Array:a}=X;let c=r*2;if(n===null&&(e.boundingBox||e.computeBoundingBox(),po.set(e.boundingBox.min,e.boundingBox.max,s),n=po),mt(c,o)){const h=t.geometry,l=h.index,d=h.attributes.position,p=e.index,f=e.attributes.position,y=Nt(r,a),N=zt(c,o);if(_s.copy(s).invert(),e.boundsTree)return J(r,i,mn),mn.matrix.copy(_s),mn.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:x=>mn.intersectsBox(x),intersectsTriangle:x=>{x.a.applyMatrix4(s),x.b.applyMatrix4(s),x.c.applyMatrix4(s),x.needsUpdate=!0;for(let w=y,g=N+y;w<g;w++)if(st(Ye,3*t.resolveTriangleIndex(w),l,d),Ye.needsUpdate=!0,x.intersectsTriangle(Ye))return!0;return!1}});{const A=He(e);for(let x=y,w=N+y;x<w;x++){const g=t.resolveTriangleIndex(x);st(Xe,3*g,l,d),Xe.a.applyMatrix4(_s),Xe.b.applyMatrix4(_s),Xe.c.applyMatrix4(_s),Xe.needsUpdate=!0;for(let m=0,M=A*3;m<M;m+=3)if(st(Ye,m,p,f),Ye.needsUpdate=!0,Xe.intersectsTriangle(Ye))return!0}}}else{const h=r+8,l=a[r+6];return J(h,i,fn),!!(n.intersectsBox(fn)&&bi(h,t,e,s,n)||(J(l,i,fn),n.intersectsBox(fn)&&bi(l,t,e,s,n)))}}const yn=new nt,Ei=new dt,zs=new dt,rl=new _,ol=new _,al=new _,cl=new _;function hl(r,t,e,s={},n={},i=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Ei.set(t.boundingBox.min,t.boundingBox.max,e),Ei.needsUpdate=!0;const a=r.geometry,c=a.attributes.position,u=a.index,h=t.attributes.position,l=t.index,d=Ft.getPrimitive(),p=Ft.getPrimitive();let f=rl,y=ol,N=null,A=null;n&&(N=al,A=cl);let x=1/0,w=null,g=null;return yn.copy(e).invert(),zs.matrix.copy(yn),r.shapecast({boundsTraverseOrder:m=>Ei.distanceToBox(m),intersectsBounds:(m,M,S)=>S<x&&S<o?(M&&(zs.min.copy(m.min),zs.max.copy(m.max),zs.needsUpdate=!0),!0):!1,intersectsRange:(m,M)=>{if(t.boundsTree){const S=t.boundsTree;return S.shapecast({boundsTraverseOrder:z=>zs.distanceToBox(z),intersectsBounds:(z,R,F)=>F<x&&F<o,intersectsRange:(z,R)=>{for(let F=z,P=z+R;F<P;F++){const C=S.resolveTriangleIndex(F);st(p,3*C,l,h),p.a.applyMatrix4(e),p.b.applyMatrix4(e),p.c.applyMatrix4(e),p.needsUpdate=!0;for(let I=m,L=m+M;I<L;I++){const D=r.resolveTriangleIndex(I);st(d,3*D,u,c),d.needsUpdate=!0;const k=d.distanceToTriangle(p,f,N);if(k<x&&(y.copy(f),A&&A.copy(N),x=k,w=I,g=F),k<i)return!0}}}})}else{const S=He(t);for(let z=0,R=S;z<R;z++){st(p,3*z,l,h),p.a.applyMatrix4(e),p.b.applyMatrix4(e),p.c.applyMatrix4(e),p.needsUpdate=!0;for(let F=m,P=m+M;F<P;F++){const C=r.resolveTriangleIndex(F);st(d,3*C,u,c),d.needsUpdate=!0;const I=d.distanceToTriangle(p,f,N);if(I<x&&(y.copy(f),A&&A.copy(N),x=I,w=F,g=z),I<i)return!0}}}}}),Ft.releasePrimitive(d),Ft.releasePrimitive(p),x===1/0?null:(s.point?s.point.copy(y):s.point=y.clone(),s.distance=x,s.faceIndex=w,n&&(n.point?n.point.copy(A):n.point=A.clone(),n.point.applyMatrix4(yn),y.applyMatrix4(yn),n.distance=y.sub(n.point).length(),n.faceIndex=g),s)}function ul(){return typeof SharedArrayBuffer<"u"}const bs=new X.constructor,gn=new X.constructor,le=new xi(()=>new ut),Ze=new ut,Je=new ut,Ci=new ut,Fi=new ut;let Ri=!1;function ll(r,t,e,s){if(Ri)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Ri=!0;const n=r._roots,i=t._roots;let o,a=0,c=0;const u=new nt().copy(e).invert();for(let h=0,l=n.length;h<l;h++){bs.setBuffer(n[h]),c=0;const d=le.getPrimitive();J(0,bs.float32Array,d),d.applyMatrix4(u);for(let p=0,f=i.length;p<f&&(gn.setBuffer(i[p]),o=Ut(0,0,e,u,s,a,c,0,0,d),gn.clearBuffer(),c+=i[p].byteLength,!o);p++);if(le.releasePrimitive(d),bs.clearBuffer(),a+=n[h].byteLength,o)break}return Ri=!1,o}function Ut(r,t,e,s,n,i=0,o=0,a=0,c=0,u=null,h=!1){let l,d;h?(l=gn,d=bs):(l=bs,d=gn);const p=l.float32Array,f=l.uint32Array,y=l.uint16Array,N=d.float32Array,A=d.uint32Array,x=d.uint16Array,w=r*2,g=t*2,m=mt(w,y),M=mt(g,x);let S=!1;if(M&&m)h?S=n(Nt(t,A),zt(t*2,x),Nt(r,f),zt(r*2,y),c,o+t,a,i+r):S=n(Nt(r,f),zt(r*2,y),Nt(t,A),zt(t*2,x),a,i+r,c,o+t);else if(M){const z=le.getPrimitive();J(t,N,z),z.applyMatrix4(e);const R=bt(r),F=Et(r,f);J(R,p,Ze),J(F,p,Je);const P=z.intersectsBox(Ze),C=z.intersectsBox(Je);S=P&&Ut(t,R,s,e,n,o,i,c,a+1,z,!h)||C&&Ut(t,F,s,e,n,o,i,c,a+1,z,!h),le.releasePrimitive(z)}else{const z=bt(t),R=Et(t,A);J(z,N,Ci),J(R,N,Fi);const F=u.intersectsBox(Ci),P=u.intersectsBox(Fi);if(F&&P)S=Ut(r,z,e,s,n,i,o,a,c+1,u,h)||Ut(r,R,e,s,n,i,o,a,c+1,u,h);else if(F)if(m)S=Ut(r,z,e,s,n,i,o,a,c+1,u,h);else{const C=le.getPrimitive();C.copy(Ci).applyMatrix4(e);const I=bt(r),L=Et(r,f);J(I,p,Ze),J(L,p,Je);const D=C.intersectsBox(Ze),k=C.intersectsBox(Je);S=D&&Ut(z,I,s,e,n,o,i,c,a+1,C,!h)||k&&Ut(z,L,s,e,n,o,i,c,a+1,C,!h),le.releasePrimitive(C)}else if(P)if(m)S=Ut(r,R,e,s,n,i,o,a,c+1,u,h);else{const C=le.getPrimitive();C.copy(Fi).applyMatrix4(e);const I=bt(r),L=Et(r,f);J(I,p,Ze),J(L,p,Je);const D=C.intersectsBox(Ze),k=C.intersectsBox(Je);S=D&&Ut(R,I,s,e,n,o,i,c,a+1,C,!h)||k&&Ut(R,L,s,e,n,o,i,c,a+1,C,!h),le.releasePrimitive(C)}}return S}const xn=new dt,fo=new ut,dl={strategy:Xr,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class Tn{static serialize(t,e={}){e={cloneBuffers:!0,...e};const s=t.geometry,n=t._roots,i=t._indirectBuffer,o=s.getIndex();let a;return e.cloneBuffers?a={roots:n.map(c=>c.slice()),index:o?o.array.slice():null,indirectBuffer:i?i.slice():null}:a={roots:n,index:o?o.array:null,indirectBuffer:i},a}static deserialize(t,e,s={}){s={setIndex:!0,indirect:!!t.indirectBuffer,...s};const{index:n,roots:i,indirectBuffer:o}=t,a=new Tn(e,{...s,[di]:!0});if(a._roots=i,a._indirectBuffer=o||null,s.setIndex){const c=e.getIndex();if(c===null){const u=new Ot(t.index,1,!1);e.setIndex(u)}else c.array!==n&&(c.array.set(n),c.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e=Object.assign({...dl,[di]:!1},e),e.useSharedArrayBuffer&&!ul())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[di]||(Eu(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new ut))),this.resolveTriangleIndex=e.indirect?s=>this._indirectBuffer[s]:s=>s}refit(t=null){return(this.indirect?tl:ku)(this,t)}traverse(t,e=0){const s=this._roots[e],n=new Uint32Array(s),i=new Uint16Array(s);o(0);function o(a,c=0){const u=a*2,h=i[u+15]===tn;if(h){const l=n[a+6],d=i[u+14];t(c,h,new Float32Array(s,a*4,6),l,d)}else{const l=a+xs/4,d=n[a+6],p=n[a+7];t(c,h,new Float32Array(s,a*4,6),p)||(o(l,c+1),o(d,c+1))}}}raycast(t,e=0,s=0,n=1/0){const i=this._roots,o=[],a=this.indirect?el:Wu;for(let c=0,u=i.length;c<u;c++)a(this,c,e,t,o,s,n);return o}raycastFirst(t,e=0,s=0,n=1/0){const i=this._roots;let o=null;const a=this.indirect?nl:Xu;for(let c=0,u=i.length;c<u;c++){const h=a(this,c,e,t,s,n);h!=null&&(o==null||h.distance<o.distance)&&(o=h)}return o}intersectsGeometry(t,e){let s=!1;const n=this._roots,i=this.indirect?il:Yu;for(let o=0,a=n.length;o<a&&(s=i(this,o,t,e),!s);o++);return s}shapecast(t){const e=Ft.getPrimitive(),s=this.indirect?$u:Uu;let{boundsTraverseOrder:n,intersectsBounds:i,intersectsRange:o,intersectsTriangle:a}=t;if(o&&a){const l=o;o=(d,p,f,y,N)=>l(d,p,f,y,N)?!0:s(d,p,this,a,f,y,e)}else o||(a?o=(l,d,p,f)=>s(l,d,this,a,p,f,e):o=(l,d,p)=>p);let c=!1,u=0;const h=this._roots;for(let l=0,d=h.length;l<d;l++){const p=h[l];if(c=Pu(this,l,i,o,n,u),c)break;u+=p.byteLength}return Ft.releasePrimitive(e),c}bvhcast(t,e,s){let{intersectsRanges:n,intersectsTriangles:i}=s;const o=Ft.getPrimitive(),a=this.geometry.index,c=this.geometry.attributes.position,u=this.indirect?f=>{const y=this.resolveTriangleIndex(f);st(o,y*3,a,c)}:f=>{st(o,f*3,a,c)},h=Ft.getPrimitive(),l=t.geometry.index,d=t.geometry.attributes.position,p=t.indirect?f=>{const y=t.resolveTriangleIndex(f);st(h,y*3,l,d)}:f=>{st(h,f*3,l,d)};if(i){const f=(y,N,A,x,w,g,m,M)=>{for(let S=A,z=A+x;S<z;S++){p(S),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let R=y,F=y+N;R<F;R++)if(u(R),o.needsUpdate=!0,i(o,h,R,S,w,g,m,M))return!0}return!1};if(n){const y=n;n=function(N,A,x,w,g,m,M,S){return y(N,A,x,w,g,m,M,S)?!0:f(N,A,x,w,g,m,M,S)}}else n=f}return ll(this,t,e,n)}intersectsBox(t,e){return xn.set(t.min,t.max,e),xn.needsUpdate=!0,this.shapecast({intersectsBounds:s=>xn.intersectsBox(s),intersectsTriangle:s=>xn.intersectsTriangle(s)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,s={},n={},i=0,o=1/0){return(this.indirect?hl:Ku)(this,t,e,s,n,i,o)}closestPointToPoint(t,e={},s=0,n=1/0){return vu(this,t,e,s,n)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(s=>{J(0,new Float32Array(s),fo),t.union(fo)}),t}}self.onmessage=({data:r})=>{let t=performance.now();function e(o){o=Math.min(o,1);const a=performance.now();a-t>=10&&o!==1&&(self.postMessage({error:null,serialized:null,position:null,progress:o}),t=a)}const{index:s,position:n,options:i}=r;try{const o=new Vn;if(o.setAttribute("position",new Ot(n,3,!1)),s&&o.setIndex(new Ot(s,1,!1)),i.includedProgressCallback&&(i.onProgress=e),i.groups){const h=i.groups;for(const l in h){const d=h[l];o.addGroup(d.start,d.count,d.materialIndex)}}const a=new Tn(o,i),c=Tn.serialize(a,{copyIndexBuffer:!1});let u=[n.buffer,...c.roots];c.index&&u.push(c.index.buffer),u=u.filter(h=>typeof SharedArrayBuffer>"u"||!(h instanceof SharedArrayBuffer)),a._indirectBuffer&&u.push(c.indirectBuffer.buffer),self.postMessage({error:null,serialized:c,position:n,progress:1},u)}catch(o){self.postMessage({error:o,serialized:null,position:null,progress:1})}}})();
|
|
20
|
+
`).removeFlowTab();return t.addFlowTab(),o}}const $e=(...r)=>v(new su(Oe(r,"int"))).append();let ys,gs;class et extends U{static get type(){return"ScreenNode"}constructor(t){super(),this.scope=t,this.isViewportNode=!0}getNodeType(){return this.scope===et.VIEWPORT?"vec4":"vec2"}getUpdateType(){let t=j.NONE;return(this.scope===et.SIZE||this.scope===et.VIEWPORT)&&(t=j.RENDER),this.updateType=t,t}update({renderer:t}){const e=t.getRenderTarget();this.scope===et.VIEWPORT?e!==null?gs.copy(e.viewport):(t.getViewport(gs),gs.multiplyScalar(t.getPixelRatio())):e!==null?(ys.width=e.width,ys.height=e.height):t.getDrawingBufferSize(ys)}setup(){const t=this.scope;let e=null;return t===et.SIZE?e=At(ys||(ys=new Z)):t===et.VIEWPORT?e=At(gs||(gs=new It)):e=V(Qs.div(qr)),e}generate(t){if(this.scope===et.COORDINATE){let e=t.getFragCoord();if(t.isFlipY()){const s=t.getNodeProperties(qr).outputNode.build(t);e=`${t.getType("vec2")}( ${e}.x, ${s}.y - ${e}.y )`}return e}return super.generate(t)}}et.COORDINATE="coordinate",et.VIEWPORT="viewport",et.SIZE="size",et.UV="uv";const ai=O(et,et.UV),qr=O(et,et.SIZE),Qs=O(et,et.COORDINATE),$r=O(et,et.VIEWPORT);$r.zw,$r.xy;const xs=new Z;class nu extends Zs{static get type(){return"ViewportTextureNode"}constructor(t=ai,e=null,s=null){s===null&&(s=new sa,s.minFilter=1008),super(s,t,e),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=j.FRAME}updateBefore(t){const e=t.renderer;e.getDrawingBufferSize(xs);const s=this.value;(s.image.width!==xs.width||s.image.height!==xs.height)&&(s.image.width=xs.width,s.image.height=xs.height,s.needsUpdate=!0);const n=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,e.copyFramebufferToTexture(s),s.generateMipmaps=n}clone(){const t=new this.constructor(this.uvNode,this.levelNode,this.value);return t.generateMipmaps=this.generateMipmaps,t}}let ci=null;class iu extends nu{static get type(){return"ViewportDepthTextureNode"}constructor(t=ai,e=null){ci===null&&(ci=new sr),super(t,e,ci)}}const ru=R(iu);class xt extends U{static get type(){return"ViewportDepthNode"}constructor(t,e=null){super("float"),this.scope=t,this.valueNode=e,this.isViewportDepthNode=!0}generate(t){const{scope:e}=this;return e===xt.DEPTH_BASE?t.getFragDepth():super.generate(t)}setup({camera:t}){const{scope:e}=this,s=this.valueNode;let n=null;if(e===xt.DEPTH_BASE)s!==null&&(n=Gr().assign(s));else if(e===xt.DEPTH)t.isPerspectiveCamera?n=ou(zt.z,fs,ps):n=js(zt.z,fs,ps);else if(e===xt.LINEAR_DEPTH)if(s!==null)if(t.isPerspectiveCamera){const i=Wr(s,fs,ps);n=js(i,fs,ps)}else n=s;else n=js(zt.z,fs,ps);return n}}xt.DEPTH_BASE="depthBase",xt.DEPTH="depth",xt.LINEAR_DEPTH="linearDepth";const js=(r,t,e)=>r.add(t).div(t.sub(e)),ou=(r,t,e)=>t.add(r).mul(e).div(e.sub(t).mul(r)),Wr=(r,t,e)=>t.mul(e).div(e.sub(t).mul(r).sub(e)),Gr=R(xt,xt.DEPTH_BASE),au=O(xt,xt.DEPTH);ru(),au.assign=r=>Gr(r);class Ts extends U{static get type(){return"ClippingNode"}constructor(t=Ts.DEFAULT){super(),this.scope=t}setup(t){super.setup(t);const e=t.clippingContext,{localClipIntersection:s,localClippingCount:n,globalClippingCount:i}=e,o=i+n,a=s?o-n:o;return this.scope===Ts.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(e.planes,o,a):this.setupDefault(e.planes,o,a)}setupAlphaToCoverage(t,e,s){return tt(()=>{const n=oi(t),i=ke("float","distanceToPlane"),o=ke("float","distanceToGradient"),a=ke("float","clipOpacity");a.assign(1);let c;if($e(s,({i:u})=>{c=n.element(u),i.assign(zt.dot(c.xyz).negate().add(c.w)),o.assign(i.fwidth().div(2)),a.mulAssign(si(o.negate(),o,i)),a.equal(0).discard()}),s<e){const u=ke("float","unionclipOpacity");u.assign(1),$e({start:s,end:e},({i:h})=>{c=n.element(h),i.assign(zt.dot(c.xyz).negate().add(c.w)),o.assign(i.fwidth().div(2)),u.mulAssign(si(o.negate(),o,i).oneMinus())}),a.mulAssign(u.oneMinus())}xr.a.mulAssign(a),xr.a.equal(0).discard()})()}setupDefault(t,e,s){return tt(()=>{const n=oi(t);let i;if($e(s,({i:o})=>{i=n.element(o),zt.dot(i.xyz).greaterThan(i.w).discard()}),s<e){const o=ke("bool","clipped");o.assign(!0),$e({start:s,end:e},({i:a})=>{i=n.element(a),o.assign(zt.dot(i.xyz).greaterThan(i.w).and(o))}),o.discard()}})()}}Ts.ALPHA_TO_COVERAGE="alphaToCoverage",Ts.DEFAULT="default",k(.04),q(1);const cu=tt(([r,t])=>{const e=r.toVar();e.assign($s(2,e).sub(1));const s=k(e,1).toVar();return Jn(t.equal(0),()=>{s.assign(s.zyx)}).ElseIf(t.equal(1),()=>{s.assign(s.xzy),s.xz.mulAssign(-1)}).ElseIf(t.equal(2),()=>{s.x.mulAssign(-1)}).ElseIf(t.equal(3),()=>{s.assign(s.zyx),s.xz.mulAssign(-1)}).ElseIf(t.equal(4),()=>{s.assign(s.xzy),s.xy.mulAssign(-1)}).ElseIf(t.equal(5),()=>{s.z.mulAssign(-1)}),s}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]});tt(({texture:r,uv:t})=>{const s=k().toVar();return Jn(t.x.lessThan(1e-4),()=>{s.assign(k(1,0,0))}).ElseIf(t.y.lessThan(1e-4),()=>{s.assign(k(0,1,0))}).ElseIf(t.z.lessThan(1e-4),()=>{s.assign(k(0,0,1))}).ElseIf(t.x.greaterThan(1-1e-4),()=>{s.assign(k(-1,0,0))}).ElseIf(t.y.greaterThan(1-1e-4),()=>{s.assign(k(0,-1,0))}).ElseIf(t.z.greaterThan(1-1e-4),()=>{s.assign(k(0,0,-1))}).Else(()=>{const i=r.uv(t.add(k(-.01,0,0))).r.sub(r.uv(t.add(k(.01,0,0))).r),o=r.uv(t.add(k(0,-.01,0))).r.sub(r.uv(t.add(k(0,.01,0))).r),a=r.uv(t.add(k(0,0,-.01))).r.sub(r.uv(t.add(k(0,0,.01))).r);s.assign(k(i,o,a))}),s.normalize()});const hi=cu(Ys(),ls("faceIndex")).normalize();k(hi.x,hi.y.negate(),hi.z);class Dt extends Ue{static get type(){return"TimerNode"}constructor(t=Dt.LOCAL,e=1,s=0){super(s),this.scope=t,this.scale=e,this.updateType=j.FRAME}update(t){const e=this.scope,s=this.scale;e===Dt.LOCAL?this.value+=t.deltaTime*s:e===Dt.DELTA?this.value=t.deltaTime*s:e===Dt.FRAME?this.value=t.frameId:this.value=t.time*s}serialize(t){super.serialize(t),t.scope=this.scope,t.scale=this.scale}deserialize(t){super.deserialize(t),this.scope=t.scope,this.scale=t.scale}}Dt.LOCAL="local",Dt.GLOBAL="global",Dt.DELTA="delta",Dt.FRAME="frame";const hu=(r,t=0)=>v(new Dt(Dt.LOCAL,r,t));class rt extends U{static get type(){return"OscNode"}constructor(t=rt.SINE,e=hu()){super(),this.method=t,this.timeNode=e}getNodeType(t){return this.timeNode.getNodeType(t)}setup(){const t=this.method,e=v(this.timeNode);let s=null;return t===rt.SINE?s=e.add(.75).mul(Math.PI*2).sin().mul(.5).add(.5):t===rt.SQUARE?s=e.fract().round():t===rt.TRIANGLE?s=e.add(.5).fract().mul(2).sub(1).abs():t===rt.SAWTOOTH&&(s=e.fract()),s}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}rt.SINE="sine",rt.SQUARE="square",rt.TRIANGLE="triangle",rt.SAWTOOTH="sawtooth",rt.SINE,rt.SQUARE,rt.TRIANGLE,rt.SAWTOOTH,new Un,new _,new _,new _,new nt,new _(0,0,-1),new It,new _,new _,new It,new Z,new Wi,ai.flipX();class qt extends U{static get type(){return"SceneNode"}constructor(t=qt.BACKGROUND_BLURRINESS,e=null){super(),this.scope=t,this.scene=e}setup(t){const e=this.scope,s=this.scene!==null?this.scene:t.scene;let n;return e===qt.BACKGROUND_BLURRINESS?n=xe("backgroundBlurriness","float",s):e===qt.BACKGROUND_INTENSITY?n=xe("backgroundIntensity","float",s):console.error("THREE.SceneNode: Unknown scope:",e),n}}qt.BACKGROUND_BLURRINESS="backgroundBlurriness",qt.BACKGROUND_INTENSITY="backgroundIntensity",qt.BACKGROUND_BLURRINESS,qt.BACKGROUND_INTENSITY;const uu=new Z;class lu extends Zs{static get type(){return"PassTextureNode"}constructor(t,e){super(e),this.passNode=t,this.setUpdateMatrix(!1)}setup(t){return t.object.isQuadMesh&&this.passNode.build(t),super.setup(t)}clone(){return new this.constructor(this.passNode,this.value)}}class Xr extends lu{static get type(){return"PassMultipleTextureNode"}constructor(t,e,s=!1){super(t,null),this.textureName=e,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(t){return this.updateTexture(),super.setup(t)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class Ks extends gt{static get type(){return"PassNode"}constructor(t,e,s,n={}){super("vec4"),this.scope=t,this.scene=e,this.camera=s,this.options=n,this._pixelRatio=1,this._width=1,this._height=1;const i=new sr;i.isRenderTargetTexture=!0,i.name="depth";const o=new Wi(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:1016,...n});o.texture.name="output",o.depthTexture=i,this.renderTarget=o,this.updateBeforeType=j.FRAME,this._textures={output:o.texture,depth:i},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=At(0),this._cameraFar=At(0),this._mrt=null,this.isPassNode=!0}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(t){let e=this._textures[t];return e===void 0&&(e=this.renderTarget.texture.clone(),e.isRenderTargetTexture=!0,e.name=t,this._textures[t]=e,this.renderTarget.textures.push(e)),e}getPreviousTexture(t){let e=this._previousTextures[t];return e===void 0&&(e=this.getTexture(t).clone(),e.isRenderTargetTexture=!0,this._previousTextures[t]=e),e}toggleTexture(t){const e=this._previousTextures[t];if(e!==void 0){const s=this._textures[t],n=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[n]=e,this._textures[t]=e,this._previousTextures[t]=s,this._textureNodes[t].updateTexture(),this._previousTextureNodes[t].updateTexture()}}getTextureNode(t="output"){let e=this._textureNodes[t];return e===void 0&&(this._textureNodes[t]=e=v(new Xr(this,t)),this._textureNodes[t].updateTexture()),e}getPreviousTextureNode(t="output"){let e=this._previousTextureNodes[t];return e===void 0&&(this._textureNodes[t]===void 0&&this.getTextureNode(t),this._previousTextureNodes[t]=e=v(new Xr(this,t,!0)),this._previousTextureNodes[t].updateTexture()),e}getViewZNode(t="depth"){let e=this._viewZNodes[t];if(e===void 0){const s=this._cameraNear,n=this._cameraFar;this._viewZNodes[t]=e=Wr(this.getTextureNode(t),s,n)}return e}getLinearDepthNode(t="depth"){let e=this._linearDepthNodes[t];if(e===void 0){const s=this._cameraNear,n=this._cameraFar,i=this.getViewZNode(t);this._linearDepthNodes[t]=e=js(i,s,n)}return e}setup({renderer:t}){return this.renderTarget.samples=this.options.samples===void 0?t.samples:this.options.samples,t.backend.isWebGLBackend===!0&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===Ks.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){const{renderer:e}=t,{scene:s,camera:n}=this;this._pixelRatio=e.getPixelRatio();const i=e.getSize(uu);this.setSize(i.width,i.height);const o=e.getRenderTarget(),a=e.getMRT();this._cameraNear.value=n.near,this._cameraFar.value=n.far;for(const c in this._previousTextures)this.toggleTexture(c);e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),e.render(s,n),e.setRenderTarget(o),e.setMRT(a)}setSize(t,e){this._width=t,this._height=e;const s=this._width*this._pixelRatio,n=this._height*this._pixelRatio;this.renderTarget.setSize(s,n)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}Ks.COLOR="color",Ks.DEPTH="depth",tt(({depthTexture:r,shadowCoord:t})=>ds(r,t.xy).compare(t.z)),tt(({depthTexture:r,shadowCoord:t,shadow:e})=>{const s=(m,T)=>ds(r,m).compare(T),n=xe("mapSize","vec2",e).setGroup(ye),i=xe("radius","float",e).setGroup(ye),o=V(1).div(n),a=o.x.negate().mul(i),c=o.y.negate().mul(i),u=o.x.mul(i),h=o.y.mul(i),l=a.div(2),d=c.div(2),f=u.div(2),p=h.div(2);return ge(s(t.xy.add(V(a,c)),t.z),s(t.xy.add(V(0,c)),t.z),s(t.xy.add(V(u,c)),t.z),s(t.xy.add(V(l,d)),t.z),s(t.xy.add(V(0,d)),t.z),s(t.xy.add(V(f,d)),t.z),s(t.xy.add(V(a,0)),t.z),s(t.xy.add(V(l,0)),t.z),s(t.xy,t.z),s(t.xy.add(V(f,0)),t.z),s(t.xy.add(V(u,0)),t.z),s(t.xy.add(V(l,p)),t.z),s(t.xy.add(V(0,p)),t.z),s(t.xy.add(V(f,p)),t.z),s(t.xy.add(V(a,h)),t.z),s(t.xy.add(V(0,h)),t.z),s(t.xy.add(V(u,h)),t.z)).mul(1/17)}),tt(({depthTexture:r,shadowCoord:t,shadow:e})=>{const s=(h,l)=>ds(r,h).compare(l),n=xe("mapSize","vec2",e).setGroup(ye),i=V(1).div(n),o=i.x,a=i.y,c=t.xy,u=jn(c.mul(n).add(.5));return c.subAssign(u.mul(i)),ge(s(c,t.z),s(c.add(V(o,0)),t.z),s(c.add(V(0,a)),t.z),s(c.add(i),t.z),ae(s(c.add(V(o.negate(),0)),t.z),s(c.add(V(o.mul(2),0)),t.z),u.x),ae(s(c.add(V(o.negate(),a)),t.z),s(c.add(V(o.mul(2),a)),t.z),u.x),ae(s(c.add(V(0,a.negate())),t.z),s(c.add(V(0,a.mul(2))),t.z),u.y),ae(s(c.add(V(o,a.negate())),t.z),s(c.add(V(o,a.mul(2))),t.z),u.y),ae(ae(s(c.add(V(o.negate(),a.negate())),t.z),s(c.add(V(o.mul(2),a.negate())),t.z),u.x),ae(s(c.add(V(o.negate(),a.mul(2))),t.z),s(c.add(V(o.mul(2),a.mul(2))),t.z),u.x),u.y)).mul(1/9)}),tt(({depthTexture:r,shadowCoord:t})=>{const e=q(1).toVar(),s=ds(r).uv(t.xy).rg,n=_r(t.z,s.x);return Jn(n.notEqual(q(1)),()=>{const i=t.z.sub(s.x),o=ti(0,s.y.mul(s.y));let a=o.div(o.add(i.mul(i)));a=Ws(qs(a,.3).div(.95-.3)),e.assign(Ws(ti(n,a)))}),e}),tt(({samples:r,radius:t,size:e,shadowPass:s})=>{const n=q(0).toVar(),i=q(0).toVar(),o=r.lessThanEqual(q(1)).select(q(0),q(2).div(r.sub(1))),a=r.lessThanEqual(q(1)).select(q(0),q(-1));$e({start:De(0),end:De(r),type:"int",condition:"<"},({i:u})=>{const h=a.add(q(u).mul(o)),l=s.uv(ge(Qs.xy,V(0,h).mul(t)).div(e)).x;n.addAssign(l),i.addAssign(l.mul(l))}),n.divAssign(r),i.divAssign(r);const c=Qn(i.sub(n.mul(n)));return V(n,c)}),tt(({samples:r,radius:t,size:e,shadowPass:s})=>{const n=q(0).toVar(),i=q(0).toVar(),o=r.lessThanEqual(q(1)).select(q(0),q(2).div(r.sub(1))),a=r.lessThanEqual(q(1)).select(q(0),q(-1));$e({start:De(0),end:De(r),type:"int",condition:"<"},({i:u})=>{const h=a.add(q(u).mul(o)),l=s.uv(ge(Qs.xy,V(h,0).mul(t)).div(e));n.addAssign(l.x),i.addAssign(ge(l.y.mul(l.y),l.x.mul(l.x)))}),n.divAssign(r),i.divAssign(r);const c=Qn(i.sub(n.mul(n)));return V(n,c)}),k(1.6605,-.1246,-.0182),k(-.5876,1.1329,-.1006),k(-.0728,-.0083,1.1187),k(.6274,.0691,.0164),k(.3293,.9195,.088),k(.0433,.0113,.8956);class du extends U{constructor(t){super(),this.scope=t}generate(t){const{scope:e}=this,{renderer:s}=t;s.backend.isWebGLBackend===!0?t.addFlowCode(` // ${e}Barrier
|
|
21
|
+
`):t.addLineFlowCode(`${e}Barrier()`,this)}}R(du);class $t extends gt{static get type(){return"AtomicFunctionNode"}constructor(t,e,s,n=null){super("uint"),this.method=t,this.pointerNode=e,this.valueNode=s,this.storeNode=n}getInputType(t){return this.pointerNode.getNodeType(t)}getNodeType(t){return this.getInputType(t)}generate(t){const e=this.method,s=this.getNodeType(t),n=this.getInputType(t),i=this.pointerNode,o=this.valueNode,a=[];a.push(`&${i.build(t,n)}`),a.push(o.build(t,n));const c=`${t.getMethod(e,s)}( ${a.join(", ")} )`;if(this.storeNode!==null){const u=this.storeNode.build(t,n);t.addLineFlowCode(`${u} = ${c}`,this)}else t.addLineFlowCode(c,this)}}if($t.ATOMIC_LOAD="atomicLoad",$t.ATOMIC_STORE="atomicStore",$t.ATOMIC_ADD="atomicAdd",$t.ATOMIC_SUB="atomicSub",$t.ATOMIC_MAX="atomicMax",$t.ATOMIC_MIN="atomicMin",$t.ATOMIC_AND="atomicAnd",$t.ATOMIC_OR="atomicOr",$t.ATOMIC_XOR="atomicXor",R($t),typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"169"}})),typeof window<"u"){try{self.location.href,window.__THREE__IMPORTS__||(window.__THREE__IMPORTS__=[]),window.__THREE__IMPORTS__.push({url:self.location.href,revision:"169"})}catch{}window.__THREE__?(console.warn("WARNING: Multiple instances of Three.js being imported. Existing: "+window.__THREE__+", new: 169"),console.warn(window.__THREE__IMPORTS__)):window.__THREE__="169"}const Yr=0,fu=1,pu=2,Zr=2,ui=1.25,Jr=1,mt=32,ot=mt/4,Qr=65535,mu=Math.pow(2,-24),li=Symbol("SKIP_GENERATION");function yu(r){return r.index?r.index.count:r.attributes.position.count}function Te(r){return yu(r)/3}function gu(r,t=ArrayBuffer){return r>65535?new Uint32Array(new t(4*r)):new Uint16Array(new t(2*r))}function xu(r,t){if(!r.index){const e=r.attributes.position.count,s=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=gu(e,s);r.setIndex(new Ot(n,1));for(let i=0;i<e;i++)n[i]=i}}function jr(r,t){const e=Te(r),s=t||r.drawRange,n=s.start/3,i=(s.start+s.count)/3,o=Math.max(0,n),a=Math.min(e,i)-o;return[{offset:Math.floor(o),count:Math.floor(a)}]}function Kr(r,t){if(!r.groups||!r.groups.length)return jr(r,t);const e=[],s=t||r.drawRange,n=s.start/3,i=(s.start+s.count)/3,o=Te(r),a=[];for(const h of r.groups){const{start:l,count:d}=h,f=l/3,p=isFinite(d)?d:o*3-l,m=(l+p)/3;f<i&&m>n&&(a.push({pos:Math.max(n,f),isStart:!0}),a.push({pos:Math.min(i,m),isStart:!1}))}a.sort((h,l)=>h.pos!==l.pos?h.pos-l.pos:h.type==="end"?-1:1);let c=0,u=null;for(const h of a){const l=h.pos;c!==0&&l!==u&&e.push({offset:u,count:l-u}),c+=h.isStart?1:-1,u=l}return e}function di(r,t,e,s,n){let i=1/0,o=1/0,a=1/0,c=-1/0,u=-1/0,h=-1/0,l=1/0,d=1/0,f=1/0,p=-1/0,m=-1/0,T=-1/0;const A=r.offset||0;for(let g=(t-A)*6,N=(t+e-A)*6;g<N;g+=6){const x=r[g+0],y=r[g+1],M=x-y,S=x+y;M<i&&(i=M),S>c&&(c=S),x<l&&(l=x),x>p&&(p=x);const z=r[g+2],B=r[g+3],b=z-B,I=z+B;b<o&&(o=b),I>u&&(u=I),z<d&&(d=z),z>m&&(m=z);const C=r[g+4],P=r[g+5],L=C-P,D=C+P;L<a&&(a=L),D>h&&(h=D),C<f&&(f=C),C>T&&(T=C)}s[0]=i,s[1]=o,s[2]=a,s[3]=c,s[4]=u,s[5]=h,n[0]=l,n[1]=d,n[2]=f,n[3]=p,n[4]=m,n[5]=T}function to(r,t,e=null,s=null,n=null){const i=r.attributes.position,o=r.index?r.index.array:null,a=i.normalized;if(n===null)n=new Float32Array(e*6),n.offset=t;else if(t<0||e+t>n.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const c=i.array,u=i.offset||0;let h=3;i.isInterleavedBufferAttribute&&(h=i.data.stride);const l=["getX","getY","getZ"],d=n.offset;for(let f=t,p=t+e;f<p;f++){const T=(s?s[f]:f)*3,A=(f-d)*6;let g=T+0,N=T+1,x=T+2;o&&(g=o[g],N=o[N],x=o[x]),a||(g=g*h+u,N=N*h+u,x=x*h+u);for(let y=0;y<3;y++){let M,S,z;a?(M=i[l[y]](g),S=i[l[y]](N),z=i[l[y]](x)):(M=c[g+y],S=c[N+y],z=c[x+y]);let B=M;S<B&&(B=S),z<B&&(B=z);let b=M;S>b&&(b=S),z>b&&(b=z);const I=(b-B)/2,C=y*2;n[A+C+0]=B+I,n[A+C+1]=I+(Math.abs(B)+I)*mu}}return n}function J(r,t,e){return e.min.x=t[r],e.min.y=t[r+1],e.min.z=t[r+2],e.max.x=t[r+3],e.max.y=t[r+4],e.max.z=t[r+5],e}function eo(r){let t=-1,e=-1/0;for(let s=0;s<3;s++){const n=r[s+3]-r[s];n>e&&(e=n,t=s)}return t}function so(r,t){t.set(r)}function no(r,t,e){let s,n;for(let i=0;i<3;i++){const o=i+3;s=r[i],n=t[i],e[i]=s<n?s:n,s=r[o],n=t[o],e[o]=s>n?s:n}}function tn(r,t,e){for(let s=0;s<3;s++){const n=t[r+2*s],i=t[r+2*s+1],o=n-i,a=n+i;o<e[s]&&(e[s]=o),a>e[s+3]&&(e[s+3]=a)}}function Ns(r){const t=r[3]-r[0],e=r[4]-r[1],s=r[5]-r[2];return 2*(t*e+e*s+s*t)}const jt=32,Tu=(r,t)=>r.candidate-t.candidate,ce=new Array(jt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),en=new Float32Array(6);function Nu(r,t,e,s,n,i){let o=-1,a=0;if(i===Yr)o=eo(t),o!==-1&&(a=(t[o]+t[o+3])/2);else if(i===fu)o=eo(r),o!==-1&&(a=wu(e,s,n,o));else if(i===pu){const c=Ns(r);let u=ui*n;const h=e.offset||0,l=(s-h)*6,d=(s+n-h)*6;for(let f=0;f<3;f++){const p=t[f],A=(t[f+3]-p)/jt;if(n<jt/4){const g=[...ce];g.length=n;let N=0;for(let y=l;y<d;y+=6,N++){const M=g[N];M.candidate=e[y+2*f],M.count=0;const{bounds:S,leftCacheBounds:z,rightCacheBounds:B}=M;for(let b=0;b<3;b++)B[b]=1/0,B[b+3]=-1/0,z[b]=1/0,z[b+3]=-1/0,S[b]=1/0,S[b+3]=-1/0;tn(y,e,S)}g.sort(Tu);let x=n;for(let y=0;y<x;y++){const M=g[y];for(;y+1<x&&g[y+1].candidate===M.candidate;)g.splice(y+1,1),x--}for(let y=l;y<d;y+=6){const M=e[y+2*f];for(let S=0;S<x;S++){const z=g[S];M>=z.candidate?tn(y,e,z.rightCacheBounds):(tn(y,e,z.leftCacheBounds),z.count++)}}for(let y=0;y<x;y++){const M=g[y],S=M.count,z=n-M.count,B=M.leftCacheBounds,b=M.rightCacheBounds;let I=0;S!==0&&(I=Ns(B)/c);let C=0;z!==0&&(C=Ns(b)/c);const P=Jr+ui*(I*S+C*z);P<u&&(o=f,u=P,a=M.candidate)}}else{for(let x=0;x<jt;x++){const y=ce[x];y.count=0,y.candidate=p+A+x*A;const M=y.bounds;for(let S=0;S<3;S++)M[S]=1/0,M[S+3]=-1/0}for(let x=l;x<d;x+=6){let S=~~((e[x+2*f]-p)/A);S>=jt&&(S=jt-1);const z=ce[S];z.count++,tn(x,e,z.bounds)}const g=ce[jt-1];so(g.bounds,g.rightCacheBounds);for(let x=jt-2;x>=0;x--){const y=ce[x],M=ce[x+1];no(y.bounds,M.rightCacheBounds,y.rightCacheBounds)}let N=0;for(let x=0;x<jt-1;x++){const y=ce[x],M=y.count,S=y.bounds,B=ce[x+1].rightCacheBounds;M!==0&&(N===0?so(S,en):no(S,en,en)),N+=M;let b=0,I=0;N!==0&&(b=Ns(en)/c);const C=n-N;C!==0&&(I=Ns(B)/c);const P=Jr+ui*(b*N+I*C);P<u&&(o=f,u=P,a=y.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${i} used.`);return{axis:o,pos:a}}function wu(r,t,e,s){let n=0;const i=r.offset;for(let o=t,a=t+e;o<a;o++)n+=r[(o-i)*6+s*2];return n/e}class fi{constructor(){this.boundingData=new Float32Array(6)}}function Au(r,t,e,s,n,i){let o=s,a=s+n-1;const c=i.pos,u=i.axis*2,h=e.offset||0;for(;;){for(;o<=a&&e[(o-h)*6+u]<c;)o++;for(;o<=a&&e[(a-h)*6+u]>=c;)a--;if(o<a){for(let l=0;l<3;l++){let d=t[o*3+l];t[o*3+l]=t[a*3+l],t[a*3+l]=d}for(let l=0;l<6;l++){const d=o-h,f=a-h,p=e[d*6+l];e[d*6+l]=e[f*6+l],e[f*6+l]=p}o++,a--}else return o}}function Su(r,t,e,s,n,i){let o=s,a=s+n-1;const c=i.pos,u=i.axis*2,h=e.offset||0;for(;;){for(;o<=a&&e[(o-h)*6+u]<c;)o++;for(;o<=a&&e[(a-h)*6+u]>=c;)a--;if(o<a){let l=r[o];r[o]=r[a],r[a]=l;for(let d=0;d<6;d++){const f=o-h,p=a-h,m=e[f*6+d];e[f*6+d]=e[p*6+d],e[p*6+d]=m}o++,a--}else return o}}let io,sn,pi,ro;const Mu=Math.pow(2,32);function mi(r){return"count"in r?1:1+mi(r.left)+mi(r.right)}function _u(r,t,e){return io=new Float32Array(e),sn=new Uint32Array(e),pi=new Uint16Array(e),ro=new Uint8Array(e),yi(r,t)}function yi(r,t){const e=r/4,s=r/2,n="count"in t,i=t.boundingData;for(let o=0;o<6;o++)io[e+o]=i[o];if(n)return t.buffer?(ro.set(new Uint8Array(t.buffer),r),r+t.buffer.byteLength):(sn[e+6]=t.offset,pi[s+14]=t.count,pi[s+15]=Qr,r+mt);{const{left:o,right:a,splitAxis:c}=t,u=r+mt;let h=yi(u,o);const l=r/mt,f=h/mt-l;if(f>Mu)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return sn[e+6]=f,sn[e+7]=c,yi(h,a)}}function zu(r,t,e){const n=(r.index?r.index.count:r.attributes.position.count)/3>2**16,i=e.reduce((h,l)=>h+l.count,0),o=n?4:2,a=t?new SharedArrayBuffer(i*o):new ArrayBuffer(i*o),c=n?new Uint32Array(a):new Uint16Array(a);let u=0;for(let h=0;h<e.length;h++){const{offset:l,count:d}=e[h];for(let f=0;f<d;f++)c[u+f]=l+f;u+=d}return c}function bu(r,t,e,s,n){const{maxDepth:i,verbose:o,maxLeafTris:a,strategy:c,onProgress:u,indirect:h}=n,l=r._indirectBuffer,d=r.geometry,f=d.index?d.index.array:null,p=h?Su:Au,m=Te(d),T=new Float32Array(6);let A=!1;const g=new fi;return di(t,e,s,g.boundingData,T),x(g,e,s,T),g;function N(y){u&&u(y/m)}function x(y,M,S,z=null,B=0){if(!A&&B>=i&&(A=!0,o&&(console.warn(`MeshBVH: Max depth of ${i} reached when generating BVH. Consider increasing maxDepth.`),console.warn(d))),S<=a||B>=i)return N(M+S),y.offset=M,y.count=S,y;const b=Nu(y.boundingData,z,t,M,S,c);if(b.axis===-1)return N(M+S),y.offset=M,y.count=S,y;const I=p(l,f,t,M,S,b);if(I===M||I===M+S)N(M+S),y.offset=M,y.count=S;else{y.splitAxis=b.axis;const C=new fi,P=M,L=I-M;y.left=C,di(t,P,L,C.boundingData,T),x(C,P,L,T,B+1);const D=new fi,W=I,Ft=S-L;y.right=D,di(t,W,Ft,D.boundingData,T),x(D,W,Ft,T,B+1)}return y}}function Eu(r,t){const e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=r.geometry;let n,i;if(t.indirect){const o=Kr(s,t.range),a=zu(s,t.useSharedArrayBuffer,o);r._indirectBuffer=a,n=to(s,0,a.length,a),i=[{offset:0,count:a.length}]}else{xu(s,t);const o=jr(s,t.range)[0];n=to(s,o.offset,o.count),i=Kr(s,t.range)}r._roots=i.map(o=>{const a=bu(r,n,o.offset,o.count,t),c=mi(a),u=new e(mt*c);return _u(0,a,u),u})}class Kt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let s=1/0,n=-1/0;for(let i=0,o=t.length;i<o;i++){const c=t[i][e];s=c<s?c:s,n=c>n?c:n}this.min=s,this.max=n}setFromPoints(t,e){let s=1/0,n=-1/0;for(let i=0,o=e.length;i<o;i++){const a=e[i],c=t.dot(a);s=c<s?c:s,n=c>n?c:n}this.min=s,this.max=n}isSeparated(t){return this.min>t.max||t.min>this.max}}Kt.prototype.setFromBox=(function(){const r=new _;return function(e,s){const n=s.min,i=s.max;let o=1/0,a=-1/0;for(let c=0;c<=1;c++)for(let u=0;u<=1;u++)for(let h=0;h<=1;h++){r.x=n.x*c+i.x*(1-c),r.y=n.y*u+i.y*(1-u),r.z=n.z*h+i.z*(1-h);const l=e.dot(r);o=Math.min(l,o),a=Math.max(l,a)}this.min=o,this.max=a}})();const Cu=(function(){const r=new _,t=new _,e=new _;return function(n,i,o){const a=n.start,c=r,u=i.start,h=t;e.subVectors(a,u),r.subVectors(n.end,n.start),t.subVectors(i.end,i.start);const l=e.dot(h),d=h.dot(c),f=h.dot(h),p=e.dot(c),T=c.dot(c)*f-d*d;let A,g;T!==0?A=(l*d-p*f)/T:A=0,g=(l+A*d)/f,o.x=A,o.y=g}})(),gi=(function(){const r=new Z,t=new _,e=new _;return function(n,i,o,a){Cu(n,i,r);let c=r.x,u=r.y;if(c>=0&&c<=1&&u>=0&&u<=1){n.at(c,o),i.at(u,a);return}else if(c>=0&&c<=1){u<0?i.at(0,a):i.at(1,a),n.closestPointToPoint(a,!0,o);return}else if(u>=0&&u<=1){c<0?n.at(0,o):n.at(1,o),i.closestPointToPoint(o,!0,a);return}else{let h;c<0?h=n.start:h=n.end;let l;u<0?l=i.start:l=i.end;const d=t,f=e;if(n.closestPointToPoint(l,!0,t),i.closestPointToPoint(h,!0,e),d.distanceToSquared(l)<=f.distanceToSquared(h)){o.copy(d),a.copy(l);return}else{o.copy(h),a.copy(f);return}}}})(),Fu=(function(){const r=new _,t=new _,e=new Un,s=new Jt;return function(i,o){const{radius:a,center:c}=i,{a:u,b:h,c:l}=o;if(s.start=u,s.end=h,s.closestPointToPoint(c,!0,r).distanceTo(c)<=a||(s.start=u,s.end=l,s.closestPointToPoint(c,!0,r).distanceTo(c)<=a)||(s.start=h,s.end=l,s.closestPointToPoint(c,!0,r).distanceTo(c)<=a))return!0;const m=o.getPlane(e);if(Math.abs(m.distanceToPoint(c))<=a){const A=m.projectPoint(c,t);if(o.containsPoint(A))return!0}return!1}})(),Bu=["x","y","z"],te=1e-15,oo=te*te;function bt(r){return Math.abs(r)<te}class Vt extends Mt{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new _),this.satBounds=new Array(4).fill().map(()=>new Kt),this.points=[this.a,this.b,this.c],this.plane=new Un,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new Jt,this.needsUpdate=!0}intersectsSphere(t){return Fu(t,this)}update(){const t=this.a,e=this.b,s=this.c,n=this.points,i=this.satAxes,o=this.satBounds,a=i[0],c=o[0];this.getNormal(a),c.setFromPoints(a,n);const u=i[1],h=o[1];u.subVectors(t,e),h.setFromPoints(u,n);const l=i[2],d=o[2];l.subVectors(e,s),d.setFromPoints(l,n);const f=i[3],p=o[3];f.subVectors(s,t),p.setFromPoints(f,n);const m=u.length(),T=l.length(),A=f.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,m<te?T<te||A<te?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(s)):T<te?A<te?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):A<te&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(s),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}Vt.prototype.closestPointToSegment=(function(){const r=new _,t=new _,e=new Jt;return function(n,i=null,o=null){const{start:a,end:c}=n,u=this.points;let h,l=1/0;for(let d=0;d<3;d++){const f=(d+1)%3;e.start.copy(u[d]),e.end.copy(u[f]),gi(e,n,r,t),h=r.distanceToSquared(t),h<l&&(l=h,i&&i.copy(r),o&&o.copy(t))}return this.closestPointToPoint(a,r),h=a.distanceToSquared(r),h<l&&(l=h,i&&i.copy(r),o&&o.copy(a)),this.closestPointToPoint(c,r),h=c.distanceToSquared(r),h<l&&(l=h,i&&i.copy(r),o&&o.copy(c)),Math.sqrt(l)}})(),Vt.prototype.intersectsTriangle=(function(){const r=new Vt,t=new Kt,e=new Kt,s=new _,n=new _,i=new _,o=new _,a=new Jt,c=new Jt,u=new _,h=new Z,l=new Z;function d(N,x,y,M){const S=s;!N.isDegenerateIntoPoint&&!N.isDegenerateIntoSegment?S.copy(N.plane.normal):S.copy(x.plane.normal);const z=N.satBounds,B=N.satAxes;for(let C=1;C<4;C++){const P=z[C],L=B[C];if(t.setFromPoints(L,x.points),P.isSeparated(t)||(o.copy(S).cross(L),t.setFromPoints(o,N.points),e.setFromPoints(o,x.points),t.isSeparated(e)))return!1}const b=x.satBounds,I=x.satAxes;for(let C=1;C<4;C++){const P=b[C],L=I[C];if(t.setFromPoints(L,N.points),P.isSeparated(t)||(o.crossVectors(S,L),t.setFromPoints(o,N.points),e.setFromPoints(o,x.points),t.isSeparated(e)))return!1}return y&&(M||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),y.start.set(0,0,0),y.end.set(0,0,0)),!0}function f(N,x,y,M,S,z,B,b,I,C,P){let L=B/(B-b);C.x=M+(S-M)*L,P.start.subVectors(x,N).multiplyScalar(L).add(N),L=B/(B-I),C.y=M+(z-M)*L,P.end.subVectors(y,N).multiplyScalar(L).add(N)}function p(N,x,y,M,S,z,B,b,I,C,P){if(S>0)f(N.c,N.a,N.b,M,x,y,I,B,b,C,P);else if(z>0)f(N.b,N.a,N.c,y,x,M,b,B,I,C,P);else if(b*I>0||B!=0)f(N.a,N.b,N.c,x,y,M,B,b,I,C,P);else if(b!=0)f(N.b,N.a,N.c,y,x,M,b,B,I,C,P);else if(I!=0)f(N.c,N.a,N.b,M,x,y,I,B,b,C,P);else return!0;return!1}function m(N,x,y,M){const S=x.degenerateSegment,z=N.plane.distanceToPoint(S.start),B=N.plane.distanceToPoint(S.end);return bt(z)?bt(B)?d(N,x,y,M):(y&&(y.start.copy(S.start),y.end.copy(S.start)),N.containsPoint(S.start)):bt(B)?(y&&(y.start.copy(S.end),y.end.copy(S.end)),N.containsPoint(S.end)):N.plane.intersectLine(S,s)!=null?(y&&(y.start.copy(s),y.end.copy(s)),N.containsPoint(s)):!1}function T(N,x,y){const M=x.a;return bt(N.plane.distanceToPoint(M))&&N.containsPoint(M)?(y&&(y.start.copy(M),y.end.copy(M)),!0):!1}function A(N,x,y){const M=N.degenerateSegment,S=x.a;return M.closestPointToPoint(S,!0,s),S.distanceToSquared(s)<oo?(y&&(y.start.copy(S),y.end.copy(S)),!0):!1}function g(N,x,y,M){if(N.isDegenerateIntoSegment)if(x.isDegenerateIntoSegment){const S=N.degenerateSegment,z=x.degenerateSegment,B=n,b=i;S.delta(B),z.delta(b);const I=s.subVectors(z.start,S.start),C=B.x*b.y-B.y*b.x;if(bt(C))return!1;const P=(I.x*b.y-I.y*b.x)/C,L=-(B.x*I.y-B.y*I.x)/C;if(P<0||P>1||L<0||L>1)return!1;const D=S.start.z+B.z*P,W=z.start.z+b.z*L;return bt(D-W)?(y&&(y.start.copy(S.start).addScaledVector(B,P),y.end.copy(S.start).addScaledVector(B,P)),!0):!1}else return x.isDegenerateIntoPoint?A(N,x,y):m(x,N,y,M);else{if(N.isDegenerateIntoPoint)return x.isDegenerateIntoPoint?x.a.distanceToSquared(N.a)<oo?(y&&(y.start.copy(N.a),y.end.copy(N.a)),!0):!1:x.isDegenerateIntoSegment?A(x,N,y):T(x,N,y);if(x.isDegenerateIntoPoint)return T(N,x,y);if(x.isDegenerateIntoSegment)return m(N,x,y,M)}}return function(x,y=null,M=!1){this.needsUpdate&&this.update(),x.isExtendedTriangle?x.needsUpdate&&x.update():(r.copy(x),r.update(),x=r);const S=g(this,x,y,M);if(S!==void 0)return S;const z=this.plane,B=x.plane;let b=B.distanceToPoint(this.a),I=B.distanceToPoint(this.b),C=B.distanceToPoint(this.c);bt(b)&&(b=0),bt(I)&&(I=0),bt(C)&&(C=0);const P=b*I,L=b*C;if(P>0&&L>0)return!1;let D=z.distanceToPoint(x.a),W=z.distanceToPoint(x.b),Ft=z.distanceToPoint(x.c);bt(D)&&(D=0),bt(W)&&(W=0),bt(Ft)&&(Ft=0);const Se=D*W,Me=D*Ft;if(Se>0&&Me>0)return!1;n.copy(z.normal),i.copy(B.normal);const de=n.cross(i);let fe=0,Ii=Math.abs(de.x);const yo=Math.abs(de.y);yo>Ii&&(Ii=yo,fe=1),Math.abs(de.z)>Ii&&(fe=2);const Ke=Bu[fe],fl=this.a[Ke],pl=this.b[Ke],ml=this.c[Ke],yl=x.a[Ke],gl=x.b[Ke],xl=x.c[Ke];if(p(this,fl,pl,ml,P,L,b,I,C,h,a))return d(this,x,y,M);if(p(x,yl,gl,xl,Se,Me,D,W,Ft,l,c))return d(this,x,y,M);if(h.y<h.x){const Pi=h.y;h.y=h.x,h.x=Pi,u.copy(a.start),a.start.copy(a.end),a.end.copy(u)}if(l.y<l.x){const Pi=l.y;l.y=l.x,l.x=Pi,u.copy(c.start),c.start.copy(c.end),c.end.copy(u)}return h.y<l.x||l.y<h.x?!1:(y&&(l.x>h.x?y.start.copy(c.start):y.start.copy(a.start),l.y<h.y?y.end.copy(c.end):y.end.copy(a.end)),!0)}})(),Vt.prototype.distanceToPoint=(function(){const r=new _;return function(e){return this.closestPointToPoint(e,r),e.distanceTo(r)}})(),Vt.prototype.distanceToTriangle=(function(){const r=new _,t=new _,e=["a","b","c"],s=new Jt,n=new Jt;return function(o,a=null,c=null){const u=a||c?s:null;if(this.intersectsTriangle(o,u))return(a||c)&&(a&&u.getCenter(a),c&&u.getCenter(c)),0;let h=1/0;for(let l=0;l<3;l++){let d;const f=e[l],p=o[f];this.closestPointToPoint(p,r),d=p.distanceToSquared(r),d<h&&(h=d,a&&a.copy(r),c&&c.copy(p));const m=this[f];o.closestPointToPoint(m,r),d=m.distanceToSquared(r),d<h&&(h=d,a&&a.copy(m),c&&c.copy(r))}for(let l=0;l<3;l++){const d=e[l],f=e[(l+1)%3];s.set(this[d],this[f]);for(let p=0;p<3;p++){const m=e[p],T=e[(p+1)%3];n.set(o[m],o[T]),gi(s,n,r,t);const A=r.distanceToSquared(t);A<h&&(h=A,a&&a.copy(r),c&&c.copy(t))}}return Math.sqrt(h)}})();class yt{constructor(t,e,s){this.isOrientedBox=!0,this.min=new _,this.max=new _,this.matrix=new nt,this.invMatrix=new nt,this.points=new Array(8).fill().map(()=>new _),this.satAxes=new Array(3).fill().map(()=>new _),this.satBounds=new Array(3).fill().map(()=>new Kt),this.alignedSatBounds=new Array(3).fill().map(()=>new Kt),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),s&&this.matrix.copy(s)}set(t,e,s){this.min.copy(t),this.max.copy(e),this.matrix.copy(s),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}yt.prototype.update=(function(){return function(){const t=this.matrix,e=this.min,s=this.max,n=this.points;for(let u=0;u<=1;u++)for(let h=0;h<=1;h++)for(let l=0;l<=1;l++){const d=1*u|2*h|4*l,f=n[d];f.x=u?s.x:e.x,f.y=h?s.y:e.y,f.z=l?s.z:e.z,f.applyMatrix4(t)}const i=this.satBounds,o=this.satAxes,a=n[0];for(let u=0;u<3;u++){const h=o[u],l=i[u],d=1<<u,f=n[d];h.subVectors(a,f),l.setFromPoints(h,n)}const c=this.alignedSatBounds;c[0].setFromPointsField(n,"x"),c[1].setFromPointsField(n,"y"),c[2].setFromPointsField(n,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),yt.prototype.intersectsBox=(function(){const r=new Kt;return function(e){this.needsUpdate&&this.update();const s=e.min,n=e.max,i=this.satBounds,o=this.satAxes,a=this.alignedSatBounds;if(r.min=s.x,r.max=n.x,a[0].isSeparated(r)||(r.min=s.y,r.max=n.y,a[1].isSeparated(r))||(r.min=s.z,r.max=n.z,a[2].isSeparated(r)))return!1;for(let c=0;c<3;c++){const u=o[c],h=i[c];if(r.setFromBox(u,e),h.isSeparated(r))return!1}return!0}})(),yt.prototype.intersectsTriangle=(function(){const r=new Vt,t=new Array(3),e=new Kt,s=new Kt,n=new _;return function(o){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(r.copy(o),r.update(),o=r);const a=this.satBounds,c=this.satAxes;t[0]=o.a,t[1]=o.b,t[2]=o.c;for(let d=0;d<3;d++){const f=a[d],p=c[d];if(e.setFromPoints(p,t),f.isSeparated(e))return!1}const u=o.satBounds,h=o.satAxes,l=this.points;for(let d=0;d<3;d++){const f=u[d],p=h[d];if(e.setFromPoints(p,l),f.isSeparated(e))return!1}for(let d=0;d<3;d++){const f=c[d];for(let p=0;p<4;p++){const m=h[p];if(n.crossVectors(f,m),e.setFromPoints(n,t),s.setFromPoints(n,l),e.isSeparated(s))return!1}}return!0}})(),yt.prototype.closestPointToPoint=(function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}})(),yt.prototype.distanceToPoint=(function(){const r=new _;return function(e){return this.closestPointToPoint(e,r),e.distanceTo(r)}})(),yt.prototype.distanceToBox=(function(){const r=["x","y","z"],t=new Array(12).fill().map(()=>new Jt),e=new Array(12).fill().map(()=>new Jt),s=new _,n=new _;return function(o,a=0,c=null,u=null){if(this.needsUpdate&&this.update(),this.intersectsBox(o))return(c||u)&&(o.getCenter(n),this.closestPointToPoint(n,s),o.closestPointToPoint(s,n),c&&c.copy(s),u&&u.copy(n)),0;const h=a*a,l=o.min,d=o.max,f=this.points;let p=1/0;for(let T=0;T<8;T++){const A=f[T];n.copy(A).clamp(l,d);const g=A.distanceToSquared(n);if(g<p&&(p=g,c&&c.copy(A),u&&u.copy(n),g<h))return Math.sqrt(g)}let m=0;for(let T=0;T<3;T++)for(let A=0;A<=1;A++)for(let g=0;g<=1;g++){const N=(T+1)%3,x=(T+2)%3,y=A<<N|g<<x,M=1<<T|A<<N|g<<x,S=f[y],z=f[M];t[m].set(S,z);const b=r[T],I=r[N],C=r[x],P=e[m],L=P.start,D=P.end;L[b]=l[b],L[I]=A?l[I]:d[I],L[C]=g?l[C]:d[I],D[b]=d[b],D[I]=A?l[I]:d[I],D[C]=g?l[C]:d[I],m++}for(let T=0;T<=1;T++)for(let A=0;A<=1;A++)for(let g=0;g<=1;g++){n.x=T?d.x:l.x,n.y=A?d.y:l.y,n.z=g?d.z:l.z,this.closestPointToPoint(n,s);const N=n.distanceToSquared(s);if(N<p&&(p=N,c&&c.copy(s),u&&u.copy(n),N<h))return Math.sqrt(N)}for(let T=0;T<12;T++){const A=t[T];for(let g=0;g<12;g++){const N=e[g];gi(A,N,s,n);const x=s.distanceToSquared(n);if(x<p&&(p=x,c&&c.copy(s),u&&u.copy(n),x<h))return Math.sqrt(x)}}return Math.sqrt(p)}})();class xi{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Ru extends xi{constructor(){super(()=>new Vt)}}const Et=new Ru;function at(r,t){return t[r+15]===Qr}function St(r,t){return t[r+6]}function Ct(r,t){return t[r+14]}function ct(r){return r+ot}function ht(r,t){const e=t[r+6];return r+e*ot}function Ti(r,t){return t[r+7]}function ud(r){return r}class Iu{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=s=>{e&&t.push(e),e=s,this.float32Array=new Float32Array(s),this.uint16Array=new Uint16Array(s),this.uint32Array=new Uint32Array(s)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const X=new Iu;let he,We;const Ge=[],nn=new xi(()=>new ft);function Pu(r,t,e,s,n,i){he=nn.getPrimitive(),We=nn.getPrimitive(),Ge.push(he,We),X.setBuffer(r._roots[t]);const o=Ni(0,r.geometry,e,s,n,i);X.clearBuffer(),nn.releasePrimitive(he),nn.releasePrimitive(We),Ge.pop(),Ge.pop();const a=Ge.length;return a>0&&(We=Ge[a-1],he=Ge[a-2]),o}function Ni(r,t,e,s,n=null,i=0,o=0){const{float32Array:a,uint16Array:c,uint32Array:u}=X;let h=r*2;if(at(h,c)){const d=St(r,u),f=Ct(h,c);return J(r,a,he),s(d,f,!1,o,i+r/ot,he)}else{let b=function(C){const{uint16Array:P,uint32Array:L}=X;let D=C*2;for(;!at(D,P);)C=ct(C),D=C*2;return St(C,L)},I=function(C){const{uint16Array:P,uint32Array:L}=X;let D=C*2;for(;!at(D,P);)C=ht(C,L),D=C*2;return St(C,L)+Ct(D,P)};const d=ct(r),f=ht(r,u);let p=d,m=f,T,A,g,N;if(n&&(g=he,N=We,J(p,a,g),J(m,a,N),T=n(g),A=n(N),A<T)){p=f,m=d;const C=T;T=A,A=C,g=N}g||(g=he,J(p,a,g));const x=at(p*2,c),y=e(g,x,T,o+1,i+p/ot);let M;if(y===Zr){const C=b(p),L=I(p)-C;M=s(C,L,!0,o+1,i+p/ot,g)}else M=y&&Ni(p,t,e,s,n,i,o+1);if(M)return!0;N=We,J(m,a,N);const S=at(m*2,c),z=e(N,S,A,o+1,i+m/ot);let B;if(z===Zr){const C=b(m),L=I(m)-C;B=s(C,L,!0,o+1,i+m/ot,N)}else B=z&&Ni(m,t,e,s,n,i,o+1);return!!B}}const ws=new _,wi=new _;function vu(r,t,e={},s=0,n=1/0){const i=s*s,o=n*n;let a=1/0,c=null;if(r.shapecast({boundsTraverseOrder:h=>(ws.copy(t).clamp(h.min,h.max),ws.distanceToSquared(t)),intersectsBounds:(h,l,d)=>d<a&&d<o,intersectsTriangle:(h,l)=>{h.closestPointToPoint(t,ws);const d=t.distanceToSquared(ws);return d<a&&(wi.copy(ws),a=d,c=l),d<i}}),a===1/0)return null;const u=Math.sqrt(a);return e.point?e.point.copy(wi):e.point=wi.clone(),e.distance=u,e.faceIndex=c,e}const rn=parseInt("169")>=169,Lu=parseInt("169")<=161,Ne=new _,we=new _,Ae=new _,on=new Z,an=new Z,cn=new Z,ao=new _,co=new _,ho=new _,As=new _;function Ou(r,t,e,s,n,i,o,a){let c;if(i===1?c=r.intersectTriangle(s,e,t,!0,n):c=r.intersectTriangle(t,e,s,i!==2,n),c===null)return null;const u=r.origin.distanceTo(n);return u<o||u>a?null:{distance:u,point:n.clone()}}function uo(r,t,e,s,n,i,o,a,c,u,h){Ne.fromBufferAttribute(t,i),we.fromBufferAttribute(t,o),Ae.fromBufferAttribute(t,a);const l=Ou(r,Ne,we,Ae,As,c,u,h);if(l){if(s){on.fromBufferAttribute(s,i),an.fromBufferAttribute(s,o),cn.fromBufferAttribute(s,a),l.uv=new Z;const f=Mt.getInterpolation(As,Ne,we,Ae,on,an,cn,l.uv);rn||(l.uv=f)}if(n){on.fromBufferAttribute(n,i),an.fromBufferAttribute(n,o),cn.fromBufferAttribute(n,a),l.uv1=new Z;const f=Mt.getInterpolation(As,Ne,we,Ae,on,an,cn,l.uv1);rn||(l.uv1=f),Lu&&(l.uv2=l.uv1)}if(e){ao.fromBufferAttribute(e,i),co.fromBufferAttribute(e,o),ho.fromBufferAttribute(e,a),l.normal=new _;const f=Mt.getInterpolation(As,Ne,we,Ae,ao,co,ho,l.normal);l.normal.dot(r.direction)>0&&l.normal.multiplyScalar(-1),rn||(l.normal=f)}const d={a:i,b:o,c:a,normal:new _,materialIndex:0};if(Mt.getNormal(Ne,we,Ae,d.normal),l.face=d,l.faceIndex=i,rn){const f=new _;Mt.getBarycoord(As,Ne,we,Ae,f),l.barycoord=f}}return l}function lo(r){return r&&r.isMaterial?r.side:r}function hn(r,t,e,s,n,i,o){const a=s*3;let c=a+0,u=a+1,h=a+2;const{index:l,groups:d}=r;r.index&&(c=l.getX(c),u=l.getX(u),h=l.getX(h));const{position:f,normal:p,uv:m,uv1:T}=r.attributes;if(Array.isArray(t)){const A=s*3;for(let g=0,N=d.length;g<N;g++){const{start:x,count:y,materialIndex:M}=d[g];if(A>=x&&A<x+y){const S=lo(t[M]),z=uo(e,f,p,m,T,c,u,h,S,i,o);if(z)if(z.faceIndex=s,z.face.materialIndex=M,n)n.push(z);else return z}}}else{const A=lo(t),g=uo(e,f,p,m,T,c,u,h,A,i,o);if(g)if(g.faceIndex=s,g.face.materialIndex=0,n)n.push(g);else return g}return null}function st(r,t,e,s){const n=r.a,i=r.b,o=r.c;let a=t,c=t+1,u=t+2;e&&(a=e.getX(a),c=e.getX(c),u=e.getX(u)),n.x=s.getX(a),n.y=s.getY(a),n.z=s.getZ(a),i.x=s.getX(c),i.y=s.getY(c),i.z=s.getZ(c),o.x=s.getX(u),o.y=s.getY(u),o.z=s.getZ(u)}function Du(r,t,e,s,n,i,o,a){const{geometry:c,_indirectBuffer:u}=r;for(let h=s,l=s+n;h<l;h++)hn(c,t,e,h,i,o,a)}function Vu(r,t,e,s,n,i,o){const{geometry:a,_indirectBuffer:c}=r;let u=1/0,h=null;for(let l=s,d=s+n;l<d;l++){let f;f=hn(a,t,e,l,null,i,o),f&&f.distance<u&&(h=f,u=f.distance)}return h}function Uu(r,t,e,s,n,i,o){const{geometry:a}=e,{index:c}=a,u=a.attributes.position;for(let h=r,l=t+r;h<l;h++){let d;if(d=h,st(o,d*3,c,u),o.needsUpdate=!0,s(o,d,n,i))return!0}return!1}function ku(r,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=r.geometry,s=e.index?e.index.array:null,n=e.attributes.position;let i,o,a,c,u=0;const h=r._roots;for(let d=0,f=h.length;d<f;d++)i=h[d],o=new Uint32Array(i),a=new Uint16Array(i),c=new Float32Array(i),l(0,u),u+=i.byteLength;function l(d,f,p=!1){const m=d*2;if(at(m,a)){const T=o[d+6],A=a[m+14];let g=1/0,N=1/0,x=1/0,y=-1/0,M=-1/0,S=-1/0;for(let z=3*T,B=3*(T+A);z<B;z++){let b=s[z];const I=n.getX(b),C=n.getY(b),P=n.getZ(b);I<g&&(g=I),I>y&&(y=I),C<N&&(N=C),C>M&&(M=C),P<x&&(x=P),P>S&&(S=P)}return c[d+0]!==g||c[d+1]!==N||c[d+2]!==x||c[d+3]!==y||c[d+4]!==M||c[d+5]!==S?(c[d+0]=g,c[d+1]=N,c[d+2]=x,c[d+3]=y,c[d+4]=M,c[d+5]=S,!0):!1}else{const T=ct(d),A=ht(d,o);let g=p,N=!1,x=!1;if(t){if(!g){const b=T/ot+f/mt,I=A/ot+f/mt;N=t.has(b),x=t.has(I),g=!N&&!x}}else N=!0,x=!0;const y=g||N,M=g||x;let S=!1;y&&(S=l(T,f,g));let z=!1;M&&(z=l(A,f,g));const B=S||z;if(B)for(let b=0;b<3;b++){const I=T+b,C=A+b,P=c[I],L=c[I+3],D=c[C],W=c[C+3];c[d+b]=P<D?P:D,c[d+b+3]=L>W?L:W}return B}}}function ue(r,t,e,s,n){let i,o,a,c,u,h;const l=1/e.direction.x,d=1/e.direction.y,f=1/e.direction.z,p=e.origin.x,m=e.origin.y,T=e.origin.z;let A=t[r],g=t[r+3],N=t[r+1],x=t[r+3+1],y=t[r+2],M=t[r+3+2];return l>=0?(i=(A-p)*l,o=(g-p)*l):(i=(g-p)*l,o=(A-p)*l),d>=0?(a=(N-m)*d,c=(x-m)*d):(a=(x-m)*d,c=(N-m)*d),i>c||a>o||((a>i||isNaN(i))&&(i=a),(c<o||isNaN(o))&&(o=c),f>=0?(u=(y-T)*f,h=(M-T)*f):(u=(M-T)*f,h=(y-T)*f),i>h||u>o)?!1:((u>i||i!==i)&&(i=u),(h<o||o!==o)&&(o=h),i<=n&&o>=s)}function Hu(r,t,e,s,n,i,o,a){const{geometry:c,_indirectBuffer:u}=r;for(let h=s,l=s+n;h<l;h++){let d=u?u[h]:h;hn(c,t,e,d,i,o,a)}}function qu(r,t,e,s,n,i,o){const{geometry:a,_indirectBuffer:c}=r;let u=1/0,h=null;for(let l=s,d=s+n;l<d;l++){let f;f=hn(a,t,e,c?c[l]:l,null,i,o),f&&f.distance<u&&(h=f,u=f.distance)}return h}function $u(r,t,e,s,n,i,o){const{geometry:a}=e,{index:c}=a,u=a.attributes.position;for(let h=r,l=t+r;h<l;h++){let d;if(d=e.resolveTriangleIndex(h),st(o,d*3,c,u),o.needsUpdate=!0,s(o,d,n,i))return!0}return!1}function Wu(r,t,e,s,n,i,o){X.setBuffer(r._roots[t]),Ai(0,r,e,s,n,i,o),X.clearBuffer()}function Ai(r,t,e,s,n,i,o){const{float32Array:a,uint16Array:c,uint32Array:u}=X,h=r*2;if(at(h,c)){const d=St(r,u),f=Ct(h,c);Du(t,e,s,d,f,n,i,o)}else{const d=ct(r);ue(d,a,s,i,o)&&Ai(d,t,e,s,n,i,o);const f=ht(r,u);ue(f,a,s,i,o)&&Ai(f,t,e,s,n,i,o)}}const Gu=["x","y","z"];function Xu(r,t,e,s,n,i){X.setBuffer(r._roots[t]);const o=Si(0,r,e,s,n,i);return X.clearBuffer(),o}function Si(r,t,e,s,n,i){const{float32Array:o,uint16Array:a,uint32Array:c}=X;let u=r*2;if(at(u,a)){const l=St(r,c),d=Ct(u,a);return Vu(t,e,s,l,d,n,i)}else{const l=Ti(r,c),d=Gu[l],p=s.direction[d]>=0;let m,T;p?(m=ct(r),T=ht(r,c)):(m=ht(r,c),T=ct(r));const g=ue(m,o,s,n,i)?Si(m,t,e,s,n,i):null;if(g){const y=g.point[d];if(p?y<=o[T+l]:y>=o[T+l+3])return g}const x=ue(T,o,s,n,i)?Si(T,t,e,s,n,i):null;return g&&x?g.distance<=x.distance?g:x:g||x||null}}const un=new ft,Xe=new Vt,Ye=new Vt,Ss=new nt,fo=new yt,ln=new yt;function Yu(r,t,e,s){X.setBuffer(r._roots[t]);const n=Mi(0,r,e,s);return X.clearBuffer(),n}function Mi(r,t,e,s,n=null){const{float32Array:i,uint16Array:o,uint32Array:a}=X;let c=r*2;if(n===null&&(e.boundingBox||e.computeBoundingBox(),fo.set(e.boundingBox.min,e.boundingBox.max,s),n=fo),at(c,o)){const h=t.geometry,l=h.index,d=h.attributes.position,f=e.index,p=e.attributes.position,m=St(r,a),T=Ct(c,o);if(Ss.copy(s).invert(),e.boundsTree)return J(r,i,ln),ln.matrix.copy(Ss),ln.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:g=>ln.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(s),g.b.applyMatrix4(s),g.c.applyMatrix4(s),g.needsUpdate=!0;for(let N=m*3,x=(T+m)*3;N<x;N+=3)if(st(Ye,N,l,d),Ye.needsUpdate=!0,g.intersectsTriangle(Ye))return!0;return!1}});{const A=Te(e);for(let g=m*3,N=(T+m)*3;g<N;g+=3){st(Xe,g,l,d),Xe.a.applyMatrix4(Ss),Xe.b.applyMatrix4(Ss),Xe.c.applyMatrix4(Ss),Xe.needsUpdate=!0;for(let x=0,y=A*3;x<y;x+=3)if(st(Ye,x,f,p),Ye.needsUpdate=!0,Xe.intersectsTriangle(Ye))return!0}}}else{const h=ct(r),l=ht(r,a);return J(h,i,un),!!(n.intersectsBox(un)&&Mi(h,t,e,s,n)||(J(l,i,un),n.intersectsBox(un)&&Mi(l,t,e,s,n)))}}const dn=new nt,_i=new yt,Ms=new yt,Zu=new _,Ju=new _,Qu=new _,ju=new _;function Ku(r,t,e,s={},n={},i=0,o=1/0){t.boundingBox||t.computeBoundingBox(),_i.set(t.boundingBox.min,t.boundingBox.max,e),_i.needsUpdate=!0;const a=r.geometry,c=a.attributes.position,u=a.index,h=t.attributes.position,l=t.index,d=Et.getPrimitive(),f=Et.getPrimitive();let p=Zu,m=Ju,T=null,A=null;n&&(T=Qu,A=ju);let g=1/0,N=null,x=null;return dn.copy(e).invert(),Ms.matrix.copy(dn),r.shapecast({boundsTraverseOrder:y=>_i.distanceToBox(y),intersectsBounds:(y,M,S)=>S<g&&S<o?(M&&(Ms.min.copy(y.min),Ms.max.copy(y.max),Ms.needsUpdate=!0),!0):!1,intersectsRange:(y,M)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:z=>Ms.distanceToBox(z),intersectsBounds:(z,B,b)=>b<g&&b<o,intersectsRange:(z,B)=>{for(let b=z,I=z+B;b<I;b++){st(f,3*b,l,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let C=y,P=y+M;C<P;C++){st(d,3*C,u,c),d.needsUpdate=!0;const L=d.distanceToTriangle(f,p,T);if(L<g&&(m.copy(p),A&&A.copy(T),g=L,N=C,x=b),L<i)return!0}}}});{const S=Te(t);for(let z=0,B=S;z<B;z++){st(f,3*z,l,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let b=y,I=y+M;b<I;b++){st(d,3*b,u,c),d.needsUpdate=!0;const C=d.distanceToTriangle(f,p,T);if(C<g&&(m.copy(p),A&&A.copy(T),g=C,N=b,x=z),C<i)return!0}}}}}),Et.releasePrimitive(d),Et.releasePrimitive(f),g===1/0?null:(s.point?s.point.copy(m):s.point=m.clone(),s.distance=g,s.faceIndex=N,n&&(n.point?n.point.copy(A):n.point=A.clone(),n.point.applyMatrix4(dn),m.applyMatrix4(dn),n.distance=m.sub(n.point).length(),n.faceIndex=x),s)}function tl(r,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=r.geometry,s=e.index?e.index.array:null,n=e.attributes.position;let i,o,a,c,u=0;const h=r._roots;for(let d=0,f=h.length;d<f;d++)i=h[d],o=new Uint32Array(i),a=new Uint16Array(i),c=new Float32Array(i),l(0,u),u+=i.byteLength;function l(d,f,p=!1){const m=d*2;if(at(m,a)){const T=o[d+6],A=a[m+14];let g=1/0,N=1/0,x=1/0,y=-1/0,M=-1/0,S=-1/0;for(let z=T,B=T+A;z<B;z++){const b=3*r.resolveTriangleIndex(z);for(let I=0;I<3;I++){let C=b+I;C=s?s[C]:C;const P=n.getX(C),L=n.getY(C),D=n.getZ(C);P<g&&(g=P),P>y&&(y=P),L<N&&(N=L),L>M&&(M=L),D<x&&(x=D),D>S&&(S=D)}}return c[d+0]!==g||c[d+1]!==N||c[d+2]!==x||c[d+3]!==y||c[d+4]!==M||c[d+5]!==S?(c[d+0]=g,c[d+1]=N,c[d+2]=x,c[d+3]=y,c[d+4]=M,c[d+5]=S,!0):!1}else{const T=ct(d),A=ht(d,o);let g=p,N=!1,x=!1;if(t){if(!g){const b=T/ot+f/mt,I=A/ot+f/mt;N=t.has(b),x=t.has(I),g=!N&&!x}}else N=!0,x=!0;const y=g||N,M=g||x;let S=!1;y&&(S=l(T,f,g));let z=!1;M&&(z=l(A,f,g));const B=S||z;if(B)for(let b=0;b<3;b++){const I=T+b,C=A+b,P=c[I],L=c[I+3],D=c[C],W=c[C+3];c[d+b]=P<D?P:D,c[d+b+3]=L>W?L:W}return B}}}function el(r,t,e,s,n,i,o){X.setBuffer(r._roots[t]),zi(0,r,e,s,n,i,o),X.clearBuffer()}function zi(r,t,e,s,n,i,o){const{float32Array:a,uint16Array:c,uint32Array:u}=X,h=r*2;if(at(h,c)){const d=St(r,u),f=Ct(h,c);Hu(t,e,s,d,f,n,i,o)}else{const d=ct(r);ue(d,a,s,i,o)&&zi(d,t,e,s,n,i,o);const f=ht(r,u);ue(f,a,s,i,o)&&zi(f,t,e,s,n,i,o)}}const sl=["x","y","z"];function nl(r,t,e,s,n,i){X.setBuffer(r._roots[t]);const o=bi(0,r,e,s,n,i);return X.clearBuffer(),o}function bi(r,t,e,s,n,i){const{float32Array:o,uint16Array:a,uint32Array:c}=X;let u=r*2;if(at(u,a)){const l=St(r,c),d=Ct(u,a);return qu(t,e,s,l,d,n,i)}else{const l=Ti(r,c),d=sl[l],p=s.direction[d]>=0;let m,T;p?(m=ct(r),T=ht(r,c)):(m=ht(r,c),T=ct(r));const g=ue(m,o,s,n,i)?bi(m,t,e,s,n,i):null;if(g){const y=g.point[d];if(p?y<=o[T+l]:y>=o[T+l+3])return g}const x=ue(T,o,s,n,i)?bi(T,t,e,s,n,i):null;return g&&x?g.distance<=x.distance?g:x:g||x||null}}const fn=new ft,Ze=new Vt,Je=new Vt,_s=new nt,po=new yt,pn=new yt;function il(r,t,e,s){X.setBuffer(r._roots[t]);const n=Ei(0,r,e,s);return X.clearBuffer(),n}function Ei(r,t,e,s,n=null){const{float32Array:i,uint16Array:o,uint32Array:a}=X;let c=r*2;if(n===null&&(e.boundingBox||e.computeBoundingBox(),po.set(e.boundingBox.min,e.boundingBox.max,s),n=po),at(c,o)){const h=t.geometry,l=h.index,d=h.attributes.position,f=e.index,p=e.attributes.position,m=St(r,a),T=Ct(c,o);if(_s.copy(s).invert(),e.boundsTree)return J(r,i,pn),pn.matrix.copy(_s),pn.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:g=>pn.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(s),g.b.applyMatrix4(s),g.c.applyMatrix4(s),g.needsUpdate=!0;for(let N=m,x=T+m;N<x;N++)if(st(Je,3*t.resolveTriangleIndex(N),l,d),Je.needsUpdate=!0,g.intersectsTriangle(Je))return!0;return!1}});{const A=Te(e);for(let g=m,N=T+m;g<N;g++){const x=t.resolveTriangleIndex(g);st(Ze,3*x,l,d),Ze.a.applyMatrix4(_s),Ze.b.applyMatrix4(_s),Ze.c.applyMatrix4(_s),Ze.needsUpdate=!0;for(let y=0,M=A*3;y<M;y+=3)if(st(Je,y,f,p),Je.needsUpdate=!0,Ze.intersectsTriangle(Je))return!0}}}else{const h=ct(r),l=ht(r,a);return J(h,i,fn),!!(n.intersectsBox(fn)&&Ei(h,t,e,s,n)||(J(l,i,fn),n.intersectsBox(fn)&&Ei(l,t,e,s,n)))}}const mn=new nt,Ci=new yt,zs=new yt,rl=new _,ol=new _,al=new _,cl=new _;function hl(r,t,e,s={},n={},i=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Ci.set(t.boundingBox.min,t.boundingBox.max,e),Ci.needsUpdate=!0;const a=r.geometry,c=a.attributes.position,u=a.index,h=t.attributes.position,l=t.index,d=Et.getPrimitive(),f=Et.getPrimitive();let p=rl,m=ol,T=null,A=null;n&&(T=al,A=cl);let g=1/0,N=null,x=null;return mn.copy(e).invert(),zs.matrix.copy(mn),r.shapecast({boundsTraverseOrder:y=>Ci.distanceToBox(y),intersectsBounds:(y,M,S)=>S<g&&S<o?(M&&(zs.min.copy(y.min),zs.max.copy(y.max),zs.needsUpdate=!0),!0):!1,intersectsRange:(y,M)=>{if(t.boundsTree){const S=t.boundsTree;return S.shapecast({boundsTraverseOrder:z=>zs.distanceToBox(z),intersectsBounds:(z,B,b)=>b<g&&b<o,intersectsRange:(z,B)=>{for(let b=z,I=z+B;b<I;b++){const C=S.resolveTriangleIndex(b);st(f,3*C,l,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let P=y,L=y+M;P<L;P++){const D=r.resolveTriangleIndex(P);st(d,3*D,u,c),d.needsUpdate=!0;const W=d.distanceToTriangle(f,p,T);if(W<g&&(m.copy(p),A&&A.copy(T),g=W,N=P,x=b),W<i)return!0}}}})}else{const S=Te(t);for(let z=0,B=S;z<B;z++){st(f,3*z,l,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let b=y,I=y+M;b<I;b++){const C=r.resolveTriangleIndex(b);st(d,3*C,u,c),d.needsUpdate=!0;const P=d.distanceToTriangle(f,p,T);if(P<g&&(m.copy(p),A&&A.copy(T),g=P,N=b,x=z),P<i)return!0}}}}}),Et.releasePrimitive(d),Et.releasePrimitive(f),g===1/0?null:(s.point?s.point.copy(m):s.point=m.clone(),s.distance=g,s.faceIndex=N,n&&(n.point?n.point.copy(A):n.point=A.clone(),n.point.applyMatrix4(mn),m.applyMatrix4(mn),n.distance=m.sub(n.point).length(),n.faceIndex=x),s)}function ul(){return typeof SharedArrayBuffer<"u"}const bs=new X.constructor,yn=new X.constructor,le=new xi(()=>new ft),Qe=new ft,je=new ft,Fi=new ft,Bi=new ft;let Ri=!1;function ll(r,t,e,s){if(Ri)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Ri=!0;const n=r._roots,i=t._roots;let o,a=0,c=0;const u=new nt().copy(e).invert();for(let h=0,l=n.length;h<l;h++){bs.setBuffer(n[h]),c=0;const d=le.getPrimitive();J(0,bs.float32Array,d),d.applyMatrix4(u);for(let f=0,p=i.length;f<p&&(yn.setBuffer(i[f]),o=Ut(0,0,e,u,s,a,c,0,0,d),yn.clearBuffer(),c+=i[f].byteLength/mt,!o);f++);if(le.releasePrimitive(d),bs.clearBuffer(),a+=n[h].byteLength/mt,o)break}return Ri=!1,o}function Ut(r,t,e,s,n,i=0,o=0,a=0,c=0,u=null,h=!1){let l,d;h?(l=yn,d=bs):(l=bs,d=yn);const f=l.float32Array,p=l.uint32Array,m=l.uint16Array,T=d.float32Array,A=d.uint32Array,g=d.uint16Array,N=r*2,x=t*2,y=at(N,m),M=at(x,g);let S=!1;if(M&&y)h?S=n(St(t,A),Ct(t*2,g),St(r,p),Ct(r*2,m),c,o+t/ot,a,i+r/ot):S=n(St(r,p),Ct(r*2,m),St(t,A),Ct(t*2,g),a,i+r/ot,c,o+t/ot);else if(M){const z=le.getPrimitive();J(t,T,z),z.applyMatrix4(e);const B=ct(r),b=ht(r,p);J(B,f,Qe),J(b,f,je);const I=z.intersectsBox(Qe),C=z.intersectsBox(je);S=I&&Ut(t,B,s,e,n,o,i,c,a+1,z,!h)||C&&Ut(t,b,s,e,n,o,i,c,a+1,z,!h),le.releasePrimitive(z)}else{const z=ct(t),B=ht(t,A);J(z,T,Fi),J(B,T,Bi);const b=u.intersectsBox(Fi),I=u.intersectsBox(Bi);if(b&&I)S=Ut(r,z,e,s,n,i,o,a,c+1,u,h)||Ut(r,B,e,s,n,i,o,a,c+1,u,h);else if(b)if(y)S=Ut(r,z,e,s,n,i,o,a,c+1,u,h);else{const C=le.getPrimitive();C.copy(Fi).applyMatrix4(e);const P=ct(r),L=ht(r,p);J(P,f,Qe),J(L,f,je);const D=C.intersectsBox(Qe),W=C.intersectsBox(je);S=D&&Ut(z,P,s,e,n,o,i,c,a+1,C,!h)||W&&Ut(z,L,s,e,n,o,i,c,a+1,C,!h),le.releasePrimitive(C)}else if(I)if(y)S=Ut(r,B,e,s,n,i,o,a,c+1,u,h);else{const C=le.getPrimitive();C.copy(Bi).applyMatrix4(e);const P=ct(r),L=ht(r,p);J(P,f,Qe),J(L,f,je);const D=C.intersectsBox(Qe),W=C.intersectsBox(je);S=D&&Ut(B,P,s,e,n,o,i,c,a+1,C,!h)||W&&Ut(B,L,s,e,n,o,i,c,a+1,C,!h),le.releasePrimitive(C)}}return S}const gn=new yt,mo=new ft,dl={strategy:Yr,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class xn{static serialize(t,e={}){e={cloneBuffers:!0,...e};const s=t.geometry,n=t._roots,i=t._indirectBuffer,o=s.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(a.roots=n.map(c=>c.slice()),a.index=o?o.array.slice():null,a.indirectBuffer=i?i.slice():null):(a.roots=n,a.index=o?o.array:null,a.indirectBuffer=i),a}static deserialize(t,e,s={}){s={setIndex:!0,indirect:!!t.indirectBuffer,...s};const{index:n,roots:i,indirectBuffer:o}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),c(i));const a=new xn(e,{...s,[li]:!0});if(a._roots=i,a._indirectBuffer=o||null,s.setIndex){const u=e.getIndex();if(u===null){const h=new Ot(t.index,1,!1);e.setIndex(h)}else u.array!==n&&(u.array.set(n),u.needsUpdate=!0)}return a;function c(u){for(let h=0;h<u.length;h++){const l=u[h],d=new Uint32Array(l),f=new Uint16Array(l);for(let p=0,m=l.byteLength/mt;p<m;p++){const T=ot*p,A=2*T;at(A,f)||(d[T+6]=d[T+6]/ot-p)}}}}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e=Object.assign({...dl,[li]:!1},e),e.useSharedArrayBuffer&&!ul())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[li]||(Eu(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new ft))),this.resolveTriangleIndex=e.indirect?s=>this._indirectBuffer[s]:s=>s}shiftTriangleOffsets(t){const e=this._indirectBuffer;if(e)for(let s=0,n=e.length;s<n;s++)e[s]+=t;else{const s=this._roots;for(let n=0;n<s.length;n++){const i=s[n],o=new Uint32Array(i),a=new Uint16Array(i),c=i.byteLength/mt;for(let u=0;u<c;u++){const h=ot*u,l=2*h;at(l,a)&&(o[h+6]+=t)}}}}refit(t=null){return(this.indirect?tl:ku)(this,t)}traverse(t,e=0){const s=this._roots[e],n=new Uint32Array(s),i=new Uint16Array(s);o(0);function o(a,c=0){const u=a*2,h=at(u,i);if(h){const l=n[a+6],d=i[u+14];t(c,h,new Float32Array(s,a*4,6),l,d)}else{const l=ct(a),d=ht(a,n),f=Ti(a,n);t(c,h,new Float32Array(s,a*4,6),f)||(o(l,c+1),o(d,c+1))}}}raycast(t,e=0,s=0,n=1/0){const i=this._roots,o=[],a=this.indirect?el:Wu;for(let c=0,u=i.length;c<u;c++)a(this,c,e,t,o,s,n);return o}raycastFirst(t,e=0,s=0,n=1/0){const i=this._roots;let o=null;const a=this.indirect?nl:Xu;for(let c=0,u=i.length;c<u;c++){const h=a(this,c,e,t,s,n);h!=null&&(o==null||h.distance<o.distance)&&(o=h)}return o}intersectsGeometry(t,e){let s=!1;const n=this._roots,i=this.indirect?il:Yu;for(let o=0,a=n.length;o<a&&(s=i(this,o,t,e),!s);o++);return s}shapecast(t){const e=Et.getPrimitive(),s=this.indirect?$u:Uu;let{boundsTraverseOrder:n,intersectsBounds:i,intersectsRange:o,intersectsTriangle:a}=t;if(o&&a){const l=o;o=(d,f,p,m,T)=>l(d,f,p,m,T)?!0:s(d,f,this,a,p,m,e)}else o||(a?o=(l,d,f,p)=>s(l,d,this,a,f,p,e):o=(l,d,f)=>f);let c=!1,u=0;const h=this._roots;for(let l=0,d=h.length;l<d;l++){const f=h[l];if(c=Pu(this,l,i,o,n,u),c)break;u+=f.byteLength/mt}return Et.releasePrimitive(e),c}bvhcast(t,e,s){let{intersectsRanges:n,intersectsTriangles:i}=s;const o=Et.getPrimitive(),a=this.geometry.index,c=this.geometry.attributes.position,u=this.indirect?p=>{const m=this.resolveTriangleIndex(p);st(o,m*3,a,c)}:p=>{st(o,p*3,a,c)},h=Et.getPrimitive(),l=t.geometry.index,d=t.geometry.attributes.position,f=t.indirect?p=>{const m=t.resolveTriangleIndex(p);st(h,m*3,l,d)}:p=>{st(h,p*3,l,d)};if(i){const p=(m,T,A,g,N,x,y,M)=>{for(let S=A,z=A+g;S<z;S++){f(S),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let B=m,b=m+T;B<b;B++)if(u(B),o.needsUpdate=!0,i(o,h,B,S,N,x,y,M))return!0}return!1};if(n){const m=n;n=function(T,A,g,N,x,y,M,S){return m(T,A,g,N,x,y,M,S)?!0:p(T,A,g,N,x,y,M,S)}}else n=p}return ll(this,t,e,n)}intersectsBox(t,e){return gn.set(t.min,t.max,e),gn.needsUpdate=!0,this.shapecast({intersectsBounds:s=>gn.intersectsBox(s),intersectsTriangle:s=>gn.intersectsTriangle(s)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,s={},n={},i=0,o=1/0){return(this.indirect?hl:Ku)(this,t,e,s,n,i,o)}closestPointToPoint(t,e={},s=0,n=1/0){return vu(this,t,e,s,n)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(s=>{J(0,new Float32Array(s),mo),t.union(mo)}),t}}self.onmessage=({data:r})=>{let t=performance.now();function e(o){o=Math.min(o,1);const a=performance.now();a-t>=10&&o!==1&&(self.postMessage({error:null,serialized:null,position:null,progress:o}),t=a)}const{index:s,position:n,options:i}=r;try{const o=new Dn;if(o.setAttribute("position",new Ot(n,3,!1)),s&&o.setIndex(new Ot(s,1,!1)),i.includedProgressCallback&&(i.onProgress=e),i.groups){const h=i.groups;for(const l in h){const d=h[l];o.addGroup(d.start,d.count,d.materialIndex)}}const a=new xn(o,i),c=xn.serialize(a,{copyIndexBuffer:!1});let u=[n.buffer,...c.roots];c.index&&u.push(c.index.buffer),u=u.filter(h=>typeof SharedArrayBuffer>"u"||!(h instanceof SharedArrayBuffer)),a._indirectBuffer&&u.push(c.indirectBuffer.buffer),self.postMessage({error:null,serialized:c,position:n,progress:1},u)}catch(o){self.postMessage({error:o,serialized:null,position:null,progress:1})}}})();
|