dreamcontext 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/README.md +2 -1
  2. package/agents/sleep-product.md +19 -2
  3. package/agents/sleep-state.md +43 -22
  4. package/agents/sleep-tasks.md +38 -0
  5. package/dist/agents/sleep-product.md +19 -2
  6. package/dist/agents/sleep-state.md +43 -22
  7. package/dist/agents/sleep-tasks.md +38 -0
  8. package/dist/dashboard/assets/{BrainCanvas3D-LLqVeXtb.js → BrainCanvas3D-Bb8WCKrn.js} +21 -21
  9. package/dist/dashboard/assets/{_baseUniq-DW0uA0ty.js → _baseUniq-BatmaIH2.js} +1 -1
  10. package/dist/dashboard/assets/ar-SA-G6X2FPQ2-D5ja_wjH.js +10 -0
  11. package/dist/dashboard/assets/{arc-fVUGtlbL.js → arc-DqjLlF-x.js} +1 -1
  12. package/dist/dashboard/assets/{architectureDiagram-Q4EWVU46-Dz2PKBsS.js → architectureDiagram-Q4EWVU46-u9hbL6uu.js} +1 -1
  13. package/dist/dashboard/assets/az-AZ-76LH7QW2-CCrmRwql.js +1 -0
  14. package/dist/dashboard/assets/bg-BG-XCXSNQG7-ByFwPOzm.js +5 -0
  15. package/dist/dashboard/assets/{blockDiagram-DXYQGD6D-ByWKxzhL.js → blockDiagram-DXYQGD6D-dX-e3JNh.js} +1 -1
  16. package/dist/dashboard/assets/bn-BD-2XOGV67Q-CqnEIuTG.js +5 -0
  17. package/dist/dashboard/assets/{c4Diagram-AHTNJAMY-dpHsVM3D.js → c4Diagram-AHTNJAMY-DAT2Y4Ei.js} +1 -1
  18. package/dist/dashboard/assets/ca-ES-6MX7JW3Y-DxUow-Oi.js +8 -0
  19. package/dist/dashboard/assets/channel-JlaJkLX7.js +1 -0
  20. package/dist/dashboard/assets/{chunk-4BX2VUAB-HEXb6Yg5.js → chunk-4BX2VUAB-ng6_uP1b.js} +1 -1
  21. package/dist/dashboard/assets/{chunk-4TB4RGXK-DeVy5g6H.js → chunk-4TB4RGXK-JyQRd6F4.js} +1 -1
  22. package/dist/dashboard/assets/{chunk-55IACEB6-DGy3ZgDZ.js → chunk-55IACEB6-WENWKOcW.js} +1 -1
  23. package/dist/dashboard/assets/{chunk-EDXVE4YY-CYJehjz4.js → chunk-EDXVE4YY-BupZpcZ0.js} +1 -1
  24. package/dist/dashboard/assets/{chunk-FMBD7UC4-DKTOmvgZ.js → chunk-FMBD7UC4-6-Dp_BQr.js} +1 -1
  25. package/dist/dashboard/assets/{chunk-OYMX7WX6-mmtWyiDA.js → chunk-OYMX7WX6-CRMXMXMR.js} +1 -1
  26. package/dist/dashboard/assets/{chunk-QZHKN3VN-DSdV0iwY.js → chunk-QZHKN3VN-CdV3chea.js} +1 -1
  27. package/dist/dashboard/assets/{chunk-YZCP3GAM-DbY-KoDn.js → chunk-YZCP3GAM-DGd7UTQr.js} +1 -1
  28. package/dist/dashboard/assets/classDiagram-6PBFFD2Q-BBVZgLT7.js +1 -0
  29. package/dist/dashboard/assets/classDiagram-v2-HSJHXN6E-BBVZgLT7.js +1 -0
  30. package/dist/dashboard/assets/clone-DSjY5D8g.js +1 -0
  31. package/dist/dashboard/assets/{cose-bilkent-S5V4N54A-p0t1DY88.js → cose-bilkent-S5V4N54A-86wk8_0k.js} +1 -1
  32. package/dist/dashboard/assets/cs-CZ-2BRQDIVT-Vsx90G3k.js +11 -0
  33. package/dist/dashboard/assets/da-DK-5WZEPLOC-BqlSmIrC.js +5 -0
  34. package/dist/dashboard/assets/{dagre-KV5264BT-DYE0WzHM.js → dagre-KV5264BT-BsnIu1de.js} +1 -1
  35. package/dist/dashboard/assets/de-DE-XR44H4JA-D1X2JmBd.js +8 -0
  36. package/dist/dashboard/assets/{diagram-5BDNPKRD-D9EiQCOP.js → diagram-5BDNPKRD-BfKZpkO_.js} +1 -1
  37. package/dist/dashboard/assets/{diagram-G4DWMVQ6-poDXSAfu.js → diagram-G4DWMVQ6-BGEdOZis.js} +1 -1
  38. package/dist/dashboard/assets/{diagram-MMDJMWI5-CHZ7wgN1.js → diagram-MMDJMWI5-4PK6U-9k.js} +1 -1
  39. package/dist/dashboard/assets/{diagram-TYMM5635-DVk6fYG7.js → diagram-TYMM5635-Co4XFxnB.js} +1 -1
  40. package/dist/dashboard/assets/directory-open-01563666-DWU9wJ6I.js +1 -0
  41. package/dist/dashboard/assets/directory-open-4ed118d0-CunoC1EB.js +1 -0
  42. package/dist/dashboard/assets/el-GR-BZB4AONW-JfJ7Iw6d.js +10 -0
  43. package/dist/dashboard/assets/{erDiagram-SMLLAGMA-D2sqkGin.js → erDiagram-SMLLAGMA-tggQbGeM.js} +1 -1
  44. package/dist/dashboard/assets/es-ES-U4NZUMDT-CrTG5SH1.js +9 -0
  45. package/dist/dashboard/assets/eu-ES-A7QVB2H4-CLi-f2S4.js +11 -0
  46. package/dist/dashboard/assets/extends-CF3RwP-h.js +1 -0
  47. package/dist/dashboard/assets/fa-IR-HGAKTJCU-B78t-ifl.js +8 -0
  48. package/dist/dashboard/assets/fi-FI-Z5N7JZ37-BiYGo0tM.js +6 -0
  49. package/dist/dashboard/assets/file-open-002ab408-DIuFHtCF.js +1 -0
  50. package/dist/dashboard/assets/file-open-7c801643-684qeFg4.js +1 -0
  51. package/dist/dashboard/assets/file-save-3189631c-C1wFhQhH.js +1 -0
  52. package/dist/dashboard/assets/file-save-745eba88-Bb9F9Kg7.js +1 -0
  53. package/dist/dashboard/assets/{flowDiagram-DWJPFMVM-DrMlKBYA.js → flowDiagram-DWJPFMVM-DfOOuTHa.js} +1 -1
  54. package/dist/dashboard/assets/fr-FR-RHASNOE6-CHuvxlm9.js +9 -0
  55. package/dist/dashboard/assets/{ganttDiagram-T4ZO3ILL-Cf4FbEFp.js → ganttDiagram-T4ZO3ILL-CqRBfUlO.js} +1 -1
  56. package/dist/dashboard/assets/{gitGraphDiagram-UUTBAWPF-BsbOq1C9.js → gitGraphDiagram-UUTBAWPF-DCooi0ou.js} +1 -1
  57. package/dist/dashboard/assets/gl-ES-HMX3MZ6V-DloFVgGH.js +10 -0
  58. package/dist/dashboard/assets/{graph-CUxxgCtS.js → graph-CbTgvSod.js} +1 -1
  59. package/dist/dashboard/assets/he-IL-6SHJWFNN-sKyHtCj5.js +10 -0
  60. package/dist/dashboard/assets/hi-IN-IWLTKZ5I-BDBktoGz.js +4 -0
  61. package/dist/dashboard/assets/hu-HU-A5ZG7DT2-CI0m6WdK.js +7 -0
  62. package/dist/dashboard/assets/id-ID-SAP4L64H-o3oCWYJ1.js +10 -0
  63. package/dist/dashboard/assets/image-blob-reduce.esm-D6s-rqMO.js +7 -0
  64. package/dist/dashboard/assets/index-BMwAG0PF.css +1 -0
  65. package/dist/dashboard/assets/index-BzUItYQF.js +19 -0
  66. package/dist/dashboard/assets/index-CIMJcxbn.js +480 -0
  67. package/dist/dashboard/assets/{infoDiagram-42DDH7IO-DTkMnZiD.js → infoDiagram-42DDH7IO-DvXAiIKM.js} +1 -1
  68. package/dist/dashboard/assets/{ishikawaDiagram-UXIWVN3A-CahQ348K.js → ishikawaDiagram-UXIWVN3A-B3k3F-SR.js} +1 -1
  69. package/dist/dashboard/assets/it-IT-JPQ66NNP-B69FvIBl.js +11 -0
  70. package/dist/dashboard/assets/ja-JP-DBVTYXUO-09Dz5R3w.js +8 -0
  71. package/dist/dashboard/assets/{journeyDiagram-VCZTEJTY-BDY2Nslc.js → journeyDiagram-VCZTEJTY-3sYlQlzX.js} +1 -1
  72. package/dist/dashboard/assets/kaa-6HZHGXH3-SFvv5G_m.js +1 -0
  73. package/dist/dashboard/assets/kab-KAB-ZGHBKWFO-Cj4UcDfk.js +8 -0
  74. package/dist/dashboard/assets/{kanban-definition-6JOO6SKY-CgrwoTjI.js → kanban-definition-6JOO6SKY-cGLqpTJv.js} +1 -1
  75. package/dist/dashboard/assets/kk-KZ-P5N5QNE5-BVT_-IeJ.js +1 -0
  76. package/dist/dashboard/assets/km-KH-HSX4SM5Z-BpH_zneK.js +11 -0
  77. package/dist/dashboard/assets/ko-KR-MTYHY66A-BWtVfnIt.js +9 -0
  78. package/dist/dashboard/assets/ku-TR-6OUDTVRD-DKg1sGxW.js +9 -0
  79. package/dist/dashboard/assets/{layout-IaUxkFkm.js → layout-gKZamora.js} +1 -1
  80. package/dist/dashboard/assets/{linear-shc0iNFn.js → linear-DOSQ02II.js} +1 -1
  81. package/dist/dashboard/assets/lt-LT-XHIRWOB4-DFICvEvq.js +3 -0
  82. package/dist/dashboard/assets/lv-LV-5QDEKY6T-CeIp3POy.js +7 -0
  83. package/dist/dashboard/assets/min-BD9nuOyV.js +1 -0
  84. package/dist/dashboard/assets/{mindmap-definition-QFDTVHPH-GmO0JRtA.js → mindmap-definition-QFDTVHPH-DNg9-qbI.js} +7 -7
  85. package/dist/dashboard/assets/mr-IN-CRQNXWMA-CMiofriy.js +13 -0
  86. package/dist/dashboard/assets/my-MM-5M5IBNSE-WhbW1bUQ.js +1 -0
  87. package/dist/dashboard/assets/nb-NO-T6EIAALU-kvj3GRtN.js +10 -0
  88. package/dist/dashboard/assets/nl-NL-IS3SIHDZ-BdYOVmBV.js +8 -0
  89. package/dist/dashboard/assets/nn-NO-6E72VCQL-BAI1MQoO.js +8 -0
  90. package/dist/dashboard/assets/oc-FR-POXYY2M6-ChavJGTr.js +8 -0
  91. package/dist/dashboard/assets/pa-IN-N4M65BXN-AWmvLRaa.js +4 -0
  92. package/dist/dashboard/assets/percentages-BXMCSKIN-QYboYPU4.js +215 -0
  93. package/dist/dashboard/assets/pica-DzAIGpll.js +7 -0
  94. package/dist/dashboard/assets/{pieDiagram-DEJITSTG-Bfm_toYA.js → pieDiagram-DEJITSTG-C4ZFpuC0.js} +1 -1
  95. package/dist/dashboard/assets/pl-PL-T2D74RX3-C06LuJit.js +9 -0
  96. package/dist/dashboard/assets/pt-BR-5N22H2LF-DP-AXG39.js +9 -0
  97. package/dist/dashboard/assets/pt-PT-UZXXM6DQ-T-2COPG-.js +9 -0
  98. package/dist/dashboard/assets/{quadrantDiagram-34T5L4WZ-DIjTM3lm.js → quadrantDiagram-34T5L4WZ-yvEQRUmq.js} +1 -1
  99. package/dist/dashboard/assets/{requirementDiagram-MS252O5E-B9AEoGYh.js → requirementDiagram-MS252O5E-BkjbZkw1.js} +1 -1
  100. package/dist/dashboard/assets/ro-RO-JPDTUUEW-V8ShMmhj.js +11 -0
  101. package/dist/dashboard/assets/roundRect-0PYZxl1G.js +1 -0
  102. package/dist/dashboard/assets/ru-RU-B4JR7IUQ-Bk5QWjQg.js +9 -0
  103. package/dist/dashboard/assets/{sankeyDiagram-XADWPNL6-C_O5XLXm.js → sankeyDiagram-XADWPNL6-_6wZr0Q4.js} +1 -1
  104. package/dist/dashboard/assets/{sequenceDiagram-FGHM5R23-CHSxSvmJ.js → sequenceDiagram-FGHM5R23-B03MUCIO.js} +1 -1
  105. package/dist/dashboard/assets/si-LK-N5RQ5JYF-DrLyNjX_.js +1 -0
  106. package/dist/dashboard/assets/sk-SK-C5VTKIMK-MG2XJDav.js +6 -0
  107. package/dist/dashboard/assets/sl-SI-NN7IZMDC-DyF2jYcb.js +6 -0
  108. package/dist/dashboard/assets/{stateDiagram-FHFEXIEX-B0URrhHw.js → stateDiagram-FHFEXIEX-DW9W8hRb.js} +1 -1
  109. package/dist/dashboard/assets/stateDiagram-v2-QKLJ7IA2-DGLHFCvB.js +1 -0
  110. package/dist/dashboard/assets/subset-shared.chunk-DxnLkUkc.js +84 -0
  111. package/dist/dashboard/assets/subset-worker.chunk-BCGTROg4.js +1 -0
  112. package/dist/dashboard/assets/sv-SE-XGPEYMSR-BJOlh7Ta.js +10 -0
  113. package/dist/dashboard/assets/ta-IN-2NMHFXQM-DbvdzD_M.js +9 -0
  114. package/dist/dashboard/assets/th-TH-HPSO5L25-BZoStbWu.js +2 -0
  115. package/dist/dashboard/assets/{timeline-definition-GMOUNBTQ-CycU2gVC.js → timeline-definition-GMOUNBTQ-Cq3P6C9q.js} +1 -1
  116. package/dist/dashboard/assets/tr-TR-DEFEU3FU-D0q3dp6Y.js +7 -0
  117. package/dist/dashboard/assets/uk-UA-QMV73CPH-KQC76_Jh.js +6 -0
  118. package/dist/dashboard/assets/{vennDiagram-DHZGUBPP-DcU2536G.js → vennDiagram-DHZGUBPP-BO3azTdL.js} +1 -1
  119. package/dist/dashboard/assets/vi-VN-M7AON7JQ-BsyXHyOP.js +5 -0
  120. package/dist/dashboard/assets/{wardley-RL74JXVD-BWqqaX3S.js → wardley-RL74JXVD-BjaWFGf-.js} +1 -1
  121. package/dist/dashboard/assets/{wardleyDiagram-NUSXRM2D-CUnIHJgd.js → wardleyDiagram-NUSXRM2D-D0Ghwhzw.js} +1 -1
  122. package/dist/dashboard/assets/{xychartDiagram-5P7HB3ND-b9fcOYTj.js → xychartDiagram-5P7HB3ND-D1QYeAFg.js} +1 -1
  123. package/dist/dashboard/assets/zh-CN-LNUGB5OW-Cg54ea9D.js +10 -0
  124. package/dist/dashboard/assets/zh-HK-E62DVLB3-N7JXSzdg.js +1 -0
  125. package/dist/dashboard/assets/zh-TW-RAJ6MFWO-CTX6fzNp.js +9 -0
  126. package/dist/dashboard/index.html +2 -2
  127. package/dist/index.js +2519 -1270
  128. package/dist/skill-packs/excalidraw/SKILL.md +82 -3
  129. package/dist/skill-packs/video-watching/SKILL.md +54 -13
  130. package/dist/skill-packs/video-watching/scripts/build_frame_index.py +61 -10
  131. package/dist/skill-packs/video-watching/scripts/transcribe.sh +147 -54
  132. package/dist/templates/init/data-structures/default.md +26 -24
  133. package/package.json +1 -1
  134. package/skill/SKILL.md +48 -12
  135. package/skill-packs/excalidraw/SKILL.md +82 -3
  136. package/skill-packs/video-watching/SKILL.md +54 -13
  137. package/skill-packs/video-watching/scripts/build_frame_index.py +61 -10
  138. package/skill-packs/video-watching/scripts/transcribe.sh +147 -54
  139. package/dist/dashboard/assets/channel-zrLwggBX.js +0 -1
  140. package/dist/dashboard/assets/classDiagram-6PBFFD2Q-BvejNiwH.js +0 -1
  141. package/dist/dashboard/assets/classDiagram-v2-HSJHXN6E-BvejNiwH.js +0 -1
  142. package/dist/dashboard/assets/clone-BFVdml6g.js +0 -1
  143. package/dist/dashboard/assets/index-CqSkXBSu.css +0 -1
  144. package/dist/dashboard/assets/index-flRpQtDj.js +0 -476
  145. package/dist/dashboard/assets/min-BIL7YgTN.js +0 -1
  146. package/dist/dashboard/assets/stateDiagram-v2-QKLJ7IA2-FdAb9MBo.js +0 -1
  147. package/dist/skill-packs/video-watching/scripts/gap_fill.py +0 -45
  148. package/skill-packs/video-watching/scripts/gap_fill.py +0 -45
@@ -1,12 +1,12 @@
1
- import{bs as jc,bt as I0,aM as pS,bu as xt,bv as Ip,bw as mS,bx as gS,by as _S,bz as xS,bA as yS,bp as vS,bq as bS,bB as B0,aC as SS,bC as TS,bD as MS,bE as ES,bF as xg,bG as yg,bH as AS,bI as k,bJ as $s,bK as wS,bL as RS,bM as CS,bN as NS}from"./index-flRpQtDj.js";function PS(r){var e=jc(.1),t,n,i;typeof r!="function"&&(r=jc(r==null?0:+r));function s(a){for(var l=0,c=t.length,u;l<c;++l)u=t[l],u.vz+=(i[l]-u.z)*n[l]*a}function o(){if(t){var a,l=t.length;for(n=new Array(l),i=new Array(l),a=0;a<l;++a)n[a]=isNaN(i[a]=+r(t[a],a,t))?0:+e(t[a],a,t)}}return s.initialize=function(a){t=a,o()},s.strength=function(a){return arguments.length?(e=typeof a=="function"?a:jc(+a),o(),s):e},s.z=function(a){return arguments.length?(r=typeof a=="function"?a:jc(+a),o(),s):r},s}/**
1
+ import{bt as jc,bu as I0,aH as pS,bv as xt,bw as Ip,bx as mS,by as gS,bz as _S,bA as xS,bB as yS,bq as vS,br as bS,bC as B0,aC as SS,bD as TS,bE as MS,bF as ES,bG as xg,bH as yg,bI as AS,bJ as k,bK as $s,bL as wS,bM as RS,bN as CS,bO as NS}from"./index-CIMJcxbn.js";import{_ as Bi}from"./extends-CF3RwP-h.js";function PS(r){var e=jc(.1),t,n,i;typeof r!="function"&&(r=jc(r==null?0:+r));function s(a){for(var l=0,c=t.length,u;l<c;++l)u=t[l],u.vz+=(i[l]-u.z)*n[l]*a}function o(){if(t){var a,l=t.length;for(n=new Array(l),i=new Array(l),a=0;a<l;++a)n[a]=isNaN(i[a]=+r(t[a],a,t))?0:+e(t[a],a,t)}}return s.initialize=function(a){t=a,o()},s.strength=function(a){return arguments.length?(e=typeof a=="function"?a:jc(+a),o(),s):e},s.z=function(a){return arguments.length?(r=typeof a=="function"?a:jc(+a),o(),s):r},s}/**
2
2
  * @license
3
3
  * Copyright 2010-2026 Three.js Authors
4
4
  * SPDX-License-Identifier: MIT
5
- */const Mo="184",Un={ROTATE:0,DOLLY:1,PAN:2},$r={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},O0=0,Jf=1,k0=2,DS=0,fa=1,G0=2,_r=3,ri=0,Lt=1,Nn=2,Pn=0,ti=1,_s=2,xs=3,ys=4,co=5,V0=6,Xn=100,Bp=101,Op=102,z0=103,H0=104,Gr=200,kp=201,Gp=202,Vp=203,oc=204,ac=205,zp=206,Hp=207,Wp=208,$p=209,Xp=210,LS=211,US=212,FS=213,IS=214,lc=0,cc=1,uc=2,Ds=3,hc=4,dc=5,fc=6,pc=7,Nc=0,W0=1,$0=2,Fn=0,qp=1,jp=2,Yp=3,Kp=4,X0=5,Zp=6,Qp=7,Jp=300,Ki=301,Sr=302,pa=303,ma=304,mo=306,go=1e3,ci=1001,_o=1002,Mt=1003,em=1004,Xr=1005,Nt=1006,ga=1007,ui=1008,Xt=1009,Ts=1010,Ms=1011,Ui=1012,Sn=1013,Ct=1014,Qt=1015,tn=1016,Pc=1017,Dc=1018,di=1020,Lc=35902,Uc=35899,Fh=1021,nl=1022,ln=1023,Dn=1026,qn=1027,il=1028,Eo=1029,In=1030,Ao=1031,q0=1032,rl=1033,Es=33776,As=33777,ws=33778,Rs=33779,mc=35840,gc=35841,_c=35842,xc=35843,Ma=36196,Ea=37492,Aa=37496,wa=37488,Ra=37489,Ls=37490,Ca=37491,Na=37808,Pa=37809,Da=37810,La=37811,Ua=37812,Fa=37813,Ia=37814,Ba=37815,Oa=37816,ka=37817,Ga=37818,Va=37819,za=37820,Ha=37821,Wa=36492,ep=36494,tp=36495,$a=36283,Xa=36284,Us=36285,qa=36286,BS=3200,ji=0,j0=1,ai="",ei="srgb",yc="srgb-linear",ja="linear",Pe="srgb",ld="",Y0="rg",OS="ga",kS=0,eo=7680,GS=7681,VS=7682,zS=7683,HS=34055,WS=34056,$S=5386,XS=512,qS=513,jS=514,YS=515,KS=516,ZS=517,QS=518,np=519,tm=512,Ih=513,nm=514,Os=515,vc=516,im=517,Zr=518,rm=519,Ya=35044,mh=35048,vg="300 es",ii=2e3,Tr=2001,xr={COMPUTE:"compute",RENDER:"render"},wo={TEXTURE_COMPARE:"depthTextureCompare"};function JS(r){for(let e=r.length-1;e>=0;--e)if(r[e]>=65535)return!0;return!1}function gh(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}function bc(r){return document.createElementNS("http://www.w3.org/1999/xhtml",r)}function K0(){const r=bc("canvas");return r.style.display="block",r}const bg={};function Sc(...r){const e="THREE."+r.shift();console.log(e,...r)}function Z0(r){const e=r[0];if(typeof e=="string"&&e.startsWith("TSL:")){const t=r[1];t&&t.isStackTrace?r[0]+=" "+t.getLocation():r[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return r}function ae(...r){r=Z0(r);const e="THREE."+r.shift();{const t=r[0];t&&t.isStackTrace?console.warn(t.getError(e)):console.warn(e,...r)}}function ce(...r){r=Z0(r);const e="THREE."+r.shift();{const t=r[0];t&&t.isStackTrace?console.error(t.getError(e)):console.error(e,...r)}}function Kt(...r){const e=r.join(" ");e in bg||(bg[e]=!0,ae(...r))}function Q0(){return typeof self<"u"&&typeof self.scheduler<"u"&&typeof self.scheduler.yield<"u"?self.scheduler.yield():new Promise(r=>{requestAnimationFrame(r)})}function eT(r,e,t){return new Promise(function(n,i){function s(){switch(r.clientWaitSync(e,r.SYNC_FLUSH_COMMANDS_BIT,0)){case r.WAIT_FAILED:i();break;case r.TIMEOUT_EXPIRED:setTimeout(s,t);break;default:n()}}setTimeout(s,t)})}const sm={[lc]:cc,[uc]:fc,[hc]:pc,[Ds]:dc,[cc]:lc,[fc]:uc,[pc]:hc,[dc]:Ds};class Vi{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});const n=this._listeners;n[e]===void 0&&(n[e]=[]),n[e].indexOf(t)===-1&&n[e].push(t)}hasEventListener(e,t){const n=this._listeners;return n===void 0?!1:n[e]!==void 0&&n[e].indexOf(t)!==-1}removeEventListener(e,t){const n=this._listeners;if(n===void 0)return;const i=n[e];if(i!==void 0){const s=i.indexOf(t);s!==-1&&i.splice(s,1)}}dispatchEvent(e){const t=this._listeners;if(t===void 0)return;const n=t[e.type];if(n!==void 0){e.target=this;const i=n.slice(0);for(let s=0,o=i.length;s<o;s++)i[s].call(this,e);e.target=null}}}const Vn=["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 Sg=1234567;const ql=Math.PI/180,xo=180/Math.PI;function qr(){const r=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,n=Math.random()*4294967295|0;return(Vn[r&255]+Vn[r>>8&255]+Vn[r>>16&255]+Vn[r>>24&255]+"-"+Vn[e&255]+Vn[e>>8&255]+"-"+Vn[e>>16&15|64]+Vn[e>>24&255]+"-"+Vn[t&63|128]+Vn[t>>8&255]+"-"+Vn[t>>16&255]+Vn[t>>24&255]+Vn[n&255]+Vn[n>>8&255]+Vn[n>>16&255]+Vn[n>>24&255]).toLowerCase()}function ct(r,e,t){return Math.max(e,Math.min(t,r))}function om(r,e){return(r%e+e)%e}function tT(r,e,t,n,i){return n+(r-e)*(i-n)/(t-e)}function nT(r,e,t){return r!==e?(t-r)/(e-r):0}function jl(r,e,t){return(1-t)*r+t*e}function iT(r,e,t,n){return jl(r,e,1-Math.exp(-t*n))}function rT(r,e=1){return e-Math.abs(om(r,e*2)-e)}function sT(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*(3-2*r))}function oT(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*r*(r*(r*6-15)+10))}function aT(r,e){return r+Math.floor(Math.random()*(e-r+1))}function lT(r,e){return r+Math.random()*(e-r)}function cT(r){return r*(.5-Math.random())}function uT(r){r!==void 0&&(Sg=r);let e=Sg+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function hT(r){return r*ql}function dT(r){return r*xo}function fT(r){return(r&r-1)===0&&r!==0}function pT(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function mT(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function gT(r,e,t,n,i){const s=Math.cos,o=Math.sin,a=s(t/2),l=o(t/2),c=s((e+n)/2),u=o((e+n)/2),h=s((e-n)/2),d=o((e-n)/2),f=s((n-e)/2),p=o((n-e)/2);switch(i){case"XYX":r.set(a*u,l*h,l*d,a*c);break;case"YZY":r.set(l*d,a*u,l*h,a*c);break;case"ZXZ":r.set(l*h,l*d,a*u,a*c);break;case"XZX":r.set(a*u,l*p,l*f,a*c);break;case"YXY":r.set(l*f,a*u,l*p,a*c);break;case"ZYZ":r.set(l*p,l*f,a*u,a*c);break;default:ae("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function ni(r,e){switch(e.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 lt(r,e){switch(e.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 _h={DEG2RAD:ql,RAD2DEG:xo,generateUUID:qr,clamp:ct,euclideanModulo:om,mapLinear:tT,inverseLerp:nT,lerp:jl,damp:iT,pingpong:rT,smoothstep:sT,smootherstep:oT,randInt:aT,randFloat:lT,randFloatSpread:cT,seededRandom:uT,degToRad:hT,radToDeg:dT,isPowerOfTwo:fT,ceilPowerOfTwo:pT,floorPowerOfTwo:mT,setQuaternionFromProperEuler:gT,normalize:lt,denormalize:ni},sg=class sg{constructor(e=0,t=0){this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,n=this.y,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6],this.y=i[1]*t+i[4]*n+i[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=ct(this.x,e.x,t.x),this.y=ct(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=ct(this.x,e,t),this.y=ct(this.y,e,t),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(ct(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const n=this.dot(e)/t;return Math.acos(ct(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y;return t*t+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const n=Math.cos(t),i=Math.sin(t),s=this.x-e.x,o=this.y-e.y;return this.x=s*n-o*i+e.x,this.y=s*i+o*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}};sg.prototype.isVector2=!0;let pe=sg;class Oi{constructor(e=0,t=0,n=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=i}static slerpFlat(e,t,n,i,s,o,a){let l=n[i+0],c=n[i+1],u=n[i+2],h=n[i+3],d=s[o+0],f=s[o+1],p=s[o+2],g=s[o+3];if(h!==g||l!==d||c!==f||u!==p){let m=l*d+c*f+u*p+h*g;m<0&&(d=-d,f=-f,p=-p,g=-g,m=-m);let _=1-a;if(m<.9995){const x=Math.acos(m),y=Math.sin(x);_=Math.sin(_*x)/y,a=Math.sin(a*x)/y,l=l*_+d*a,c=c*_+f*a,u=u*_+p*a,h=h*_+g*a}else{l=l*_+d*a,c=c*_+f*a,u=u*_+p*a,h=h*_+g*a;const x=1/Math.sqrt(l*l+c*c+u*u+h*h);l*=x,c*=x,u*=x,h*=x}}e[t]=l,e[t+1]=c,e[t+2]=u,e[t+3]=h}static multiplyQuaternionsFlat(e,t,n,i,s,o){const a=n[i],l=n[i+1],c=n[i+2],u=n[i+3],h=s[o],d=s[o+1],f=s[o+2],p=s[o+3];return e[t]=a*p+u*h+l*f-c*d,e[t+1]=l*p+u*d+c*h-a*f,e[t+2]=c*p+u*f+a*d-l*h,e[t+3]=u*p-a*h-l*d-c*f,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,n,i){return this._x=e,this._y=t,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const n=e._x,i=e._y,s=e._z,o=e._order,a=Math.cos,l=Math.sin,c=a(n/2),u=a(i/2),h=a(s/2),d=l(n/2),f=l(i/2),p=l(s/2);switch(o){case"XYZ":this._x=d*u*h+c*f*p,this._y=c*f*h-d*u*p,this._z=c*u*p+d*f*h,this._w=c*u*h-d*f*p;break;case"YXZ":this._x=d*u*h+c*f*p,this._y=c*f*h-d*u*p,this._z=c*u*p-d*f*h,this._w=c*u*h+d*f*p;break;case"ZXY":this._x=d*u*h-c*f*p,this._y=c*f*h+d*u*p,this._z=c*u*p+d*f*h,this._w=c*u*h-d*f*p;break;case"ZYX":this._x=d*u*h-c*f*p,this._y=c*f*h+d*u*p,this._z=c*u*p-d*f*h,this._w=c*u*h+d*f*p;break;case"YZX":this._x=d*u*h+c*f*p,this._y=c*f*h+d*u*p,this._z=c*u*p-d*f*h,this._w=c*u*h-d*f*p;break;case"XZY":this._x=d*u*h-c*f*p,this._y=c*f*h-d*u*p,this._z=c*u*p+d*f*h,this._w=c*u*h+d*f*p;break;default:ae("Quaternion: .setFromEuler() encountered an unknown order: "+o)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const n=t/2,i=Math.sin(n);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,n=t[0],i=t[4],s=t[8],o=t[1],a=t[5],l=t[9],c=t[2],u=t[6],h=t[10],d=n+a+h;if(d>0){const f=.5/Math.sqrt(d+1);this._w=.25/f,this._x=(u-l)*f,this._y=(s-c)*f,this._z=(o-i)*f}else if(n>a&&n>h){const f=2*Math.sqrt(1+n-a-h);this._w=(u-l)/f,this._x=.25*f,this._y=(i+o)/f,this._z=(s+c)/f}else if(a>h){const f=2*Math.sqrt(1+a-n-h);this._w=(s-c)/f,this._x=(i+o)/f,this._y=.25*f,this._z=(l+u)/f}else{const f=2*Math.sqrt(1+h-n-a);this._w=(o-i)/f,this._x=(s+c)/f,this._y=(l+u)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<1e-8?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(ct(this.dot(e),-1,1)))}rotateTowards(e,t){const n=this.angleTo(e);if(n===0)return this;const i=Math.min(1,t/n);return this.slerp(e,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const n=e._x,i=e._y,s=e._z,o=e._w,a=t._x,l=t._y,c=t._z,u=t._w;return this._x=n*u+o*a+i*c-s*l,this._y=i*u+o*l+s*a-n*c,this._z=s*u+o*c+n*l-i*a,this._w=o*u-n*a-i*l-s*c,this._onChangeCallback(),this}slerp(e,t){let n=e._x,i=e._y,s=e._z,o=e._w,a=this.dot(e);a<0&&(n=-n,i=-i,s=-s,o=-o,a=-a);let l=1-t;if(a<.9995){const c=Math.acos(a),u=Math.sin(c);l=Math.sin(l*c)/u,t=Math.sin(t*c)/u,this._x=this._x*l+n*t,this._y=this._y*l+i*t,this._z=this._z*l+s*t,this._w=this._w*l+o*t,this._onChangeCallback()}else this._x=this._x*l+n*t,this._y=this._y*l+i*t,this._z=this._z*l+s*t,this._w=this._w*l+o*t,this.normalize();return this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),s=Math.sqrt(n);return this.set(i*Math.sin(e),i*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}const og=class og{constructor(e=0,t=0,n=0){this.x=e,this.y=t,this.z=n}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Tg.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Tg.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[3]*n+s[6]*i,this.y=s[1]*t+s[4]*n+s[7]*i,this.z=s[2]*t+s[5]*n+s[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,n=this.y,i=this.z,s=e.elements,o=1/(s[3]*t+s[7]*n+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*n+s[8]*i+s[12])*o,this.y=(s[1]*t+s[5]*n+s[9]*i+s[13])*o,this.z=(s[2]*t+s[6]*n+s[10]*i+s[14])*o,this}applyQuaternion(e){const t=this.x,n=this.y,i=this.z,s=e.x,o=e.y,a=e.z,l=e.w,c=2*(o*i-a*n),u=2*(a*t-s*i),h=2*(s*n-o*t);return this.x=t+l*c+o*h-a*u,this.y=n+l*u+a*c-s*h,this.z=i+l*h+s*u-o*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[4]*n+s[8]*i,this.y=s[1]*t+s[5]*n+s[9]*i,this.z=s[2]*t+s[6]*n+s[10]*i,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=ct(this.x,e.x,t.x),this.y=ct(this.y,e.y,t.y),this.z=ct(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=ct(this.x,e,t),this.y=ct(this.y,e,t),this.z=ct(this.z,e,t),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(ct(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const n=e.x,i=e.y,s=e.z,o=t.x,a=t.y,l=t.z;return this.x=i*l-s*a,this.y=s*o-n*l,this.z=n*a-i*o,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return cd.copy(this).projectOnVector(e),this.sub(cd)}reflect(e){return this.sub(cd.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const n=this.dot(e)/t;return Math.acos(ct(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y,i=this.z-e.z;return t*t+n*n+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,n){const i=Math.sin(t)*e;return this.x=i*Math.sin(n),this.y=Math.cos(t)*e,this.z=i*Math.cos(n),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),n=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=i,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,n=Math.sqrt(1-t*t);return this.x=n*Math.cos(e),this.y=t,this.z=n*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}};og.prototype.isVector3=!0;let P=og;const cd=new P,Tg=new Oi,ag=class ag{constructor(e,t,n,i,s,o,a,l,c){this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,n,i,s,o,a,l,c)}set(e,t,n,i,s,o,a,l,c){const u=this.elements;return u[0]=e,u[1]=i,u[2]=a,u[3]=t,u[4]=s,u[5]=l,u[6]=n,u[7]=o,u[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,i=t.elements,s=this.elements,o=n[0],a=n[3],l=n[6],c=n[1],u=n[4],h=n[7],d=n[2],f=n[5],p=n[8],g=i[0],m=i[3],_=i[6],x=i[1],y=i[4],b=i[7],M=i[2],S=i[5],E=i[8];return s[0]=o*g+a*x+l*M,s[3]=o*m+a*y+l*S,s[6]=o*_+a*b+l*E,s[1]=c*g+u*x+h*M,s[4]=c*m+u*y+h*S,s[7]=c*_+u*b+h*E,s[2]=d*g+f*x+p*M,s[5]=d*m+f*y+p*S,s[8]=d*_+f*b+p*E,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],u=e[8];return t*o*u-t*a*c-n*s*u+n*a*l+i*s*c-i*o*l}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],u=e[8],h=u*o-a*c,d=a*l-u*s,f=c*s-o*l,p=t*h+n*d+i*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const g=1/p;return e[0]=h*g,e[1]=(i*c-u*n)*g,e[2]=(a*n-i*o)*g,e[3]=d*g,e[4]=(u*t-i*l)*g,e[5]=(i*s-a*t)*g,e[6]=f*g,e[7]=(n*l-c*t)*g,e[8]=(o*t-n*s)*g,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,n,i,s,o,a){const l=Math.cos(s),c=Math.sin(s);return this.set(n*l,n*c,-n*(l*o+c*a)+o+e,-i*c,i*l,-i*(-c*o+l*a)+a+t,0,0,1),this}scale(e,t){return this.premultiply(ud.makeScale(e,t)),this}rotate(e){return this.premultiply(ud.makeRotation(-e)),this}translate(e,t){return this.premultiply(ud.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,n,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,n=e.elements;for(let i=0;i<9;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new this.constructor().fromArray(this.elements)}};ag.prototype.isMatrix3=!0;let Je=ag;const ud=new Je,Mg=new Je().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Eg=new Je().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function _T(){const r={enabled:!0,workingColorSpace:yc,spaces:{},convert:function(i,s,o){return this.enabled===!1||s===o||!s||!o||(this.spaces[s].transfer===Pe&&(i.r=jr(i.r),i.g=jr(i.g),i.b=jr(i.b)),this.spaces[s].primaries!==this.spaces[o].primaries&&(i.applyMatrix3(this.spaces[s].toXYZ),i.applyMatrix3(this.spaces[o].fromXYZ)),this.spaces[o].transfer===Pe&&(i.r=_a(i.r),i.g=_a(i.g),i.b=_a(i.b))),i},workingToColorSpace:function(i,s){return this.convert(i,this.workingColorSpace,s)},colorSpaceToWorking:function(i,s){return this.convert(i,s,this.workingColorSpace)},getPrimaries:function(i){return this.spaces[i].primaries},getTransfer:function(i){return i===ai?ja:this.spaces[i].transfer},getToneMappingMode:function(i){return this.spaces[i].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(i,s=this.workingColorSpace){return i.fromArray(this.spaces[s].luminanceCoefficients)},define:function(i){Object.assign(this.spaces,i)},_getMatrix:function(i,s,o){return i.copy(this.spaces[s].toXYZ).multiply(this.spaces[o].fromXYZ)},_getDrawingBufferColorSpace:function(i){return this.spaces[i].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(i=this.workingColorSpace){return this.spaces[i].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(i,s){return Kt("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),r.workingToColorSpace(i,s)},toWorkingColorSpace:function(i,s){return Kt("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),r.colorSpaceToWorking(i,s)}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],n=[.3127,.329];return r.define({[yc]:{primaries:e,whitePoint:n,transfer:ja,toXYZ:Mg,fromXYZ:Eg,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:ei},outputColorSpaceConfig:{drawingBufferColorSpace:ei}},[ei]:{primaries:e,whitePoint:n,transfer:Pe,toXYZ:Mg,fromXYZ:Eg,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:ei}}}),r}const Ye=_T();function jr(r){return r<.04045?r*.0773993808:Math.pow(r*.9478672986+.0521327014,2.4)}function _a(r){return r<.0031308?r*12.92:1.055*Math.pow(r,.41666)-.055}let Io;class xT{static getDataURL(e,t="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let n;if(e instanceof HTMLCanvasElement)n=e;else{Io===void 0&&(Io=bc("canvas")),Io.width=e.width,Io.height=e.height;const i=Io.getContext("2d");e instanceof ImageData?i.putImageData(e,0,0):i.drawImage(e,0,0,e.width,e.height),n=Io}return n.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const t=bc("canvas");t.width=e.width,t.height=e.height;const n=t.getContext("2d");n.drawImage(e,0,0,e.width,e.height);const i=n.getImageData(0,0,e.width,e.height),s=i.data;for(let o=0;o<s.length;o++)s[o]=jr(s[o]/255)*255;return n.putImageData(i,0,0),t}else if(e.data){const t=e.data.slice(0);for(let n=0;n<t.length;n++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[n]=Math.floor(jr(t[n]/255)*255):t[n]=jr(t[n]);return{data:t,width:e.width,height:e.height}}else return ae("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}}let yT=0;class am{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:yT++}),this.uuid=qr(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){const t=this.data;return typeof HTMLVideoElement<"u"&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):typeof VideoFrame<"u"&&t instanceof VideoFrame?e.set(t.displayWidth,t.displayHeight,0):t!==null?e.set(t.width,t.height,t.depth||0):e.set(0,0,0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];const n={uuid:this.uuid,url:""},i=this.data;if(i!==null){let s;if(Array.isArray(i)){s=[];for(let o=0,a=i.length;o<a;o++)i[o].isDataTexture?s.push(hd(i[o].image)):s.push(hd(i[o]))}else s=hd(i);n.url=s}return t||(e.images[this.uuid]=n),n}}function hd(r){return typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&r instanceof ImageBitmap?xT.getDataURL(r):r.data?{data:Array.from(r.data),width:r.width,height:r.height,type:r.data.constructor.name}:(ae("Texture: Unable to serialize Texture."),{})}let vT=0;const dd=new P;class fn extends Vi{constructor(e=fn.DEFAULT_IMAGE,t=fn.DEFAULT_MAPPING,n=ci,i=ci,s=Nt,o=ui,a=ln,l=Xt,c=fn.DEFAULT_ANISOTROPY,u=ai){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:vT++}),this.uuid=qr(),this.name="",this.source=new am(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=n,this.wrapT=i,this.magFilter=s,this.minFilter=o,this.anisotropy=c,this.format=a,this.internalFormat=null,this.type=l,this.offset=new pe(0,0),this.repeat=new pe(1,1),this.center=new pe(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Je,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=u,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(e&&e.depth&&e.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(dd).x}get height(){return this.source.getSize(dd).y}get depth(){return this.source.getSize(dd).z}get image(){return this.source.data}set image(e){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.normalized=e.normalized,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(const t in e){const n=e[t];if(n===void 0){ae(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}const i=this[t];if(i===void 0){ae(`Texture.setValues(): property '${t}' does not exist.`);continue}i&&n&&i.isVector2&&n.isVector2||i&&n&&i.isVector3&&n.isVector3||i&&n&&i.isMatrix3&&n.isMatrix3?i.copy(n):this[t]=n}}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];const n={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,normalized:this.normalized,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),t||(e.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==Jp)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case go:e.x=e.x-Math.floor(e.x);break;case ci:e.x=e.x<0?0:1;break;case _o:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case go:e.y=e.y-Math.floor(e.y);break;case ci:e.y=e.y<0?0:1;break;case _o:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}}fn.DEFAULT_IMAGE=null;fn.DEFAULT_MAPPING=Jp;fn.DEFAULT_ANISOTROPY=1;const lg=class lg{constructor(e=0,t=0,n=0,i=1){this.x=e,this.y=t,this.z=n,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,n,i){return this.x=e,this.y=t,this.z=n,this.w=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,n=this.y,i=this.z,s=this.w,o=e.elements;return this.x=o[0]*t+o[4]*n+o[8]*i+o[12]*s,this.y=o[1]*t+o[5]*n+o[9]*i+o[13]*s,this.z=o[2]*t+o[6]*n+o[10]*i+o[14]*s,this.w=o[3]*t+o[7]*n+o[11]*i+o[15]*s,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,n,i,s;const l=e.elements,c=l[0],u=l[4],h=l[8],d=l[1],f=l[5],p=l[9],g=l[2],m=l[6],_=l[10];if(Math.abs(u-d)<.01&&Math.abs(h-g)<.01&&Math.abs(p-m)<.01){if(Math.abs(u+d)<.1&&Math.abs(h+g)<.1&&Math.abs(p+m)<.1&&Math.abs(c+f+_-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const y=(c+1)/2,b=(f+1)/2,M=(_+1)/2,S=(u+d)/4,E=(h+g)/4,v=(p+m)/4;return y>b&&y>M?y<.01?(n=0,i=.707106781,s=.707106781):(n=Math.sqrt(y),i=S/n,s=E/n):b>M?b<.01?(n=.707106781,i=0,s=.707106781):(i=Math.sqrt(b),n=S/i,s=v/i):M<.01?(n=.707106781,i=.707106781,s=0):(s=Math.sqrt(M),n=E/s,i=v/s),this.set(n,i,s,t),this}let x=Math.sqrt((m-p)*(m-p)+(h-g)*(h-g)+(d-u)*(d-u));return Math.abs(x)<.001&&(x=1),this.x=(m-p)/x,this.y=(h-g)/x,this.z=(d-u)/x,this.w=Math.acos((c+f+_-1)/2),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=ct(this.x,e.x,t.x),this.y=ct(this.y,e.y,t.y),this.z=ct(this.z,e.z,t.z),this.w=ct(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=ct(this.x,e,t),this.y=ct(this.y,e,t),this.z=ct(this.z,e,t),this.w=ct(this.w,e,t),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(ct(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}};lg.prototype.isVector4=!0;let rt=lg;class ks extends Vi{constructor(e=1,t=1,n={}){super(),n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Nt,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1},n),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=n.depth,this.scissor=new rt(0,0,e,t),this.scissorTest=!1,this.viewport=new rt(0,0,e,t),this.textures=[];const i={width:e,height:t,depth:n.depth},s=new fn(i),o=n.count;for(let a=0;a<o;a++)this.textures[a]=s.clone(),this.textures[a].isRenderTargetTexture=!0,this.textures[a].renderTarget=this;this._setTextureOptions(n),this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.resolveDepthBuffer=n.resolveDepthBuffer,this.resolveStencilBuffer=n.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=n.depthTexture,this.samples=n.samples,this.multiview=n.multiview}_setTextureOptions(e={}){const t={minFilter:Nt,generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let n=0;n<this.textures.length;n++)this.textures[n].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),e!==null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,n=1){if(this.width!==e||this.height!==t||this.depth!==n){this.width=e,this.height=t,this.depth=n;for(let i=0,s=this.textures.length;i<s;i++)this.textures[i].image.width=e,this.textures[i].image.height=t,this.textures[i].image.depth=n,this.textures[i].isData3DTexture!==!0&&(this.textures[i].isArrayTexture=this.textures[i].image.depth>1);this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,n=e.textures.length;t<n;t++){this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0,this.textures[t].renderTarget=this;const i=Object.assign({},e.textures[t].image);this.textures[t].source=new am(i)}return this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this.multiview=e.multiview,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Yi extends ks{constructor(e=1,t=1,n={}){super(e,t,n),this.isWebGLRenderTarget=!0}}class lm extends fn{constructor(e=null,t=1,n=1,i=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:n,depth:i},this.magFilter=Mt,this.minFilter=Mt,this.wrapR=ci,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}}class bT extends fn{constructor(e=null,t=1,n=1,i=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:n,depth:i},this.magFilter=Mt,this.minFilter=Mt,this.wrapR=ci,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const Uh=class Uh{constructor(e,t,n,i,s,o,a,l,c,u,h,d,f,p,g,m){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,n,i,s,o,a,l,c,u,h,d,f,p,g,m)}set(e,t,n,i,s,o,a,l,c,u,h,d,f,p,g,m){const _=this.elements;return _[0]=e,_[4]=t,_[8]=n,_[12]=i,_[1]=s,_[5]=o,_[9]=a,_[13]=l,_[2]=c,_[6]=u,_[10]=h,_[14]=d,_[3]=f,_[7]=p,_[11]=g,_[15]=m,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 Uh().fromArray(this.elements)}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){const t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,n){return this.determinant()===0?(e.set(1,0,0),t.set(0,1,0),n.set(0,0,1),this):(e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this)}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){if(e.determinant()===0)return this.identity();const t=this.elements,n=e.elements,i=1/Bo.setFromMatrixColumn(e,0).length(),s=1/Bo.setFromMatrixColumn(e,1).length(),o=1/Bo.setFromMatrixColumn(e,2).length();return t[0]=n[0]*i,t[1]=n[1]*i,t[2]=n[2]*i,t[3]=0,t[4]=n[4]*s,t[5]=n[5]*s,t[6]=n[6]*s,t[7]=0,t[8]=n[8]*o,t[9]=n[9]*o,t[10]=n[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,n=e.x,i=e.y,s=e.z,o=Math.cos(n),a=Math.sin(n),l=Math.cos(i),c=Math.sin(i),u=Math.cos(s),h=Math.sin(s);if(e.order==="XYZ"){const d=o*u,f=o*h,p=a*u,g=a*h;t[0]=l*u,t[4]=-l*h,t[8]=c,t[1]=f+p*c,t[5]=d-g*c,t[9]=-a*l,t[2]=g-d*c,t[6]=p+f*c,t[10]=o*l}else if(e.order==="YXZ"){const d=l*u,f=l*h,p=c*u,g=c*h;t[0]=d+g*a,t[4]=p*a-f,t[8]=o*c,t[1]=o*h,t[5]=o*u,t[9]=-a,t[2]=f*a-p,t[6]=g+d*a,t[10]=o*l}else if(e.order==="ZXY"){const d=l*u,f=l*h,p=c*u,g=c*h;t[0]=d-g*a,t[4]=-o*h,t[8]=p+f*a,t[1]=f+p*a,t[5]=o*u,t[9]=g-d*a,t[2]=-o*c,t[6]=a,t[10]=o*l}else if(e.order==="ZYX"){const d=o*u,f=o*h,p=a*u,g=a*h;t[0]=l*u,t[4]=p*c-f,t[8]=d*c+g,t[1]=l*h,t[5]=g*c+d,t[9]=f*c-p,t[2]=-c,t[6]=a*l,t[10]=o*l}else if(e.order==="YZX"){const d=o*l,f=o*c,p=a*l,g=a*c;t[0]=l*u,t[4]=g-d*h,t[8]=p*h+f,t[1]=h,t[5]=o*u,t[9]=-a*u,t[2]=-c*u,t[6]=f*h+p,t[10]=d-g*h}else if(e.order==="XZY"){const d=o*l,f=o*c,p=a*l,g=a*c;t[0]=l*u,t[4]=-h,t[8]=c*u,t[1]=d*h+g,t[5]=o*u,t[9]=f*h-p,t[2]=p*h-f,t[6]=a*u,t[10]=g*h+d}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(ST,e,TT)}lookAt(e,t,n){const i=this.elements;return _i.subVectors(e,t),_i.lengthSq()===0&&(_i.z=1),_i.normalize(),rs.crossVectors(n,_i),rs.lengthSq()===0&&(Math.abs(n.z)===1?_i.x+=1e-4:_i.z+=1e-4,_i.normalize(),rs.crossVectors(n,_i)),rs.normalize(),Yc.crossVectors(_i,rs),i[0]=rs.x,i[4]=Yc.x,i[8]=_i.x,i[1]=rs.y,i[5]=Yc.y,i[9]=_i.y,i[2]=rs.z,i[6]=Yc.z,i[10]=_i.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,i=t.elements,s=this.elements,o=n[0],a=n[4],l=n[8],c=n[12],u=n[1],h=n[5],d=n[9],f=n[13],p=n[2],g=n[6],m=n[10],_=n[14],x=n[3],y=n[7],b=n[11],M=n[15],S=i[0],E=i[4],v=i[8],w=i[12],N=i[1],C=i[5],F=i[9],V=i[13],z=i[2],U=i[6],B=i[10],D=i[14],X=i[3],K=i[7],fe=i[11],Z=i[15];return s[0]=o*S+a*N+l*z+c*X,s[4]=o*E+a*C+l*U+c*K,s[8]=o*v+a*F+l*B+c*fe,s[12]=o*w+a*V+l*D+c*Z,s[1]=u*S+h*N+d*z+f*X,s[5]=u*E+h*C+d*U+f*K,s[9]=u*v+h*F+d*B+f*fe,s[13]=u*w+h*V+d*D+f*Z,s[2]=p*S+g*N+m*z+_*X,s[6]=p*E+g*C+m*U+_*K,s[10]=p*v+g*F+m*B+_*fe,s[14]=p*w+g*V+m*D+_*Z,s[3]=x*S+y*N+b*z+M*X,s[7]=x*E+y*C+b*U+M*K,s[11]=x*v+y*F+b*B+M*fe,s[15]=x*w+y*V+b*D+M*Z,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],n=e[4],i=e[8],s=e[12],o=e[1],a=e[5],l=e[9],c=e[13],u=e[2],h=e[6],d=e[10],f=e[14],p=e[3],g=e[7],m=e[11],_=e[15],x=l*f-c*d,y=a*f-c*h,b=a*d-l*h,M=o*f-c*u,S=o*d-l*u,E=o*h-a*u;return t*(g*x-m*y+_*b)-n*(p*x-m*M+_*S)+i*(p*y-g*M+_*E)-s*(p*b-g*S+m*E)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,n){const i=this.elements;return e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=t,i[14]=n),this}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],u=e[8],h=e[9],d=e[10],f=e[11],p=e[12],g=e[13],m=e[14],_=e[15],x=t*a-n*o,y=t*l-i*o,b=t*c-s*o,M=n*l-i*a,S=n*c-s*a,E=i*c-s*l,v=u*g-h*p,w=u*m-d*p,N=u*_-f*p,C=h*m-d*g,F=h*_-f*g,V=d*_-f*m,z=x*V-y*F+b*C+M*N-S*w+E*v;if(z===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const U=1/z;return e[0]=(a*V-l*F+c*C)*U,e[1]=(i*F-n*V-s*C)*U,e[2]=(g*E-m*S+_*M)*U,e[3]=(d*S-h*E-f*M)*U,e[4]=(l*N-o*V-c*w)*U,e[5]=(t*V-i*N+s*w)*U,e[6]=(m*b-p*E-_*y)*U,e[7]=(u*E-d*b+f*y)*U,e[8]=(o*F-a*N+c*v)*U,e[9]=(n*N-t*F-s*v)*U,e[10]=(p*S-g*b+_*x)*U,e[11]=(h*b-u*S-f*x)*U,e[12]=(a*w-o*C-l*v)*U,e[13]=(t*C-n*w+i*v)*U,e[14]=(g*y-p*M-m*x)*U,e[15]=(u*M-h*y+d*x)*U,this}scale(e){const t=this.elements,n=e.x,i=e.y,s=e.z;return t[0]*=n,t[4]*=i,t[8]*=s,t[1]*=n,t[5]*=i,t[9]*=s,t[2]*=n,t[6]*=i,t[10]*=s,t[3]*=n,t[7]*=i,t[11]*=s,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,i))}makeTranslation(e,t,n){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const n=Math.cos(t),i=Math.sin(t),s=1-n,o=e.x,a=e.y,l=e.z,c=s*o,u=s*a;return this.set(c*o+n,c*a-i*l,c*l+i*a,0,c*a+i*l,u*a+n,u*l-i*o,0,c*l-i*a,u*l+i*o,s*l*l+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,i,s,o){return this.set(1,n,s,0,e,1,o,0,t,i,1,0,0,0,0,1),this}compose(e,t,n){const i=this.elements,s=t._x,o=t._y,a=t._z,l=t._w,c=s+s,u=o+o,h=a+a,d=s*c,f=s*u,p=s*h,g=o*u,m=o*h,_=a*h,x=l*c,y=l*u,b=l*h,M=n.x,S=n.y,E=n.z;return i[0]=(1-(g+_))*M,i[1]=(f+b)*M,i[2]=(p-y)*M,i[3]=0,i[4]=(f-b)*S,i[5]=(1-(d+_))*S,i[6]=(m+x)*S,i[7]=0,i[8]=(p+y)*E,i[9]=(m-x)*E,i[10]=(1-(d+g))*E,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,n){const i=this.elements;e.x=i[12],e.y=i[13],e.z=i[14];const s=this.determinant();if(s===0)return n.set(1,1,1),t.identity(),this;let o=Bo.set(i[0],i[1],i[2]).length();const a=Bo.set(i[4],i[5],i[6]).length(),l=Bo.set(i[8],i[9],i[10]).length();s<0&&(o=-o),zi.copy(this);const c=1/o,u=1/a,h=1/l;return zi.elements[0]*=c,zi.elements[1]*=c,zi.elements[2]*=c,zi.elements[4]*=u,zi.elements[5]*=u,zi.elements[6]*=u,zi.elements[8]*=h,zi.elements[9]*=h,zi.elements[10]*=h,t.setFromRotationMatrix(zi),n.x=o,n.y=a,n.z=l,this}makePerspective(e,t,n,i,s,o,a=ii,l=!1){const c=this.elements,u=2*s/(t-e),h=2*s/(n-i),d=(t+e)/(t-e),f=(n+i)/(n-i);let p,g;if(l)p=s/(o-s),g=o*s/(o-s);else if(a===ii)p=-(o+s)/(o-s),g=-2*o*s/(o-s);else if(a===Tr)p=-o/(o-s),g=-o*s/(o-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=u,c[4]=0,c[8]=d,c[12]=0,c[1]=0,c[5]=h,c[9]=f,c[13]=0,c[2]=0,c[6]=0,c[10]=p,c[14]=g,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,n,i,s,o,a=ii,l=!1){const c=this.elements,u=2/(t-e),h=2/(n-i),d=-(t+e)/(t-e),f=-(n+i)/(n-i);let p,g;if(l)p=1/(o-s),g=o/(o-s);else if(a===ii)p=-2/(o-s),g=-(o+s)/(o-s);else if(a===Tr)p=-1/(o-s),g=-s/(o-s);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=u,c[4]=0,c[8]=0,c[12]=d,c[1]=0,c[5]=h,c[9]=0,c[13]=f,c[2]=0,c[6]=0,c[10]=p,c[14]=g,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){const t=this.elements,n=e.elements;for(let i=0;i<16;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}};Uh.prototype.isMatrix4=!0;let pt=Uh;const Bo=new P,zi=new pt,ST=new P(0,0,0),TT=new P(1,1,1),rs=new P,Yc=new P,_i=new P,Ag=new pt,wg=new Oi;class Mr{constructor(e=0,t=0,n=0,i=Mr.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=n,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,n,i=this._order){return this._x=e,this._y=t,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,n=!0){const i=e.elements,s=i[0],o=i[4],a=i[8],l=i[1],c=i[5],u=i[9],h=i[2],d=i[6],f=i[10];switch(t){case"XYZ":this._y=Math.asin(ct(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-u,f),this._z=Math.atan2(-o,s)):(this._x=Math.atan2(d,c),this._z=0);break;case"YXZ":this._x=Math.asin(-ct(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(a,f),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-h,s),this._z=0);break;case"ZXY":this._x=Math.asin(ct(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-h,f),this._z=Math.atan2(-o,c)):(this._y=0,this._z=Math.atan2(l,s));break;case"ZYX":this._y=Math.asin(-ct(h,-1,1)),Math.abs(h)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(l,s)):(this._x=0,this._z=Math.atan2(-o,c));break;case"YZX":this._z=Math.asin(ct(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-u,c),this._y=Math.atan2(-h,s)):(this._x=0,this._y=Math.atan2(a,f));break;case"XZY":this._z=Math.asin(-ct(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(d,c),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-u,f),this._y=0);break;default:ae("Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return Ag.makeRotationFromQuaternion(e),this.setFromRotationMatrix(Ag,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return wg.setFromEuler(this),this.setFromQuaternion(wg,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Mr.DEFAULT_ORDER="XYZ";class cm{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!==0}}let MT=0;const Rg=new P,Oo=new Oi,Pr=new pt,Kc=new P,xl=new P,ET=new P,AT=new Oi,Cg=new P(1,0,0),Ng=new P(0,1,0),Pg=new P(0,0,1),Dg={type:"added"},wT={type:"removed"},ko={type:"childadded",child:null},fd={type:"childremoved",child:null};class pn extends Vi{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:MT++}),this.uuid=qr(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=pn.DEFAULT_UP.clone();const e=new P,t=new Mr,n=new Oi,i=new P(1,1,1);function s(){n.setFromEuler(t,!1)}function o(){t.setFromQuaternion(n,void 0,!1)}t._onChange(s),n._onChange(o),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:n},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new pt},normalMatrix:{value:new Je}}),this.matrix=new pt,this.matrixWorld=new pt,this.matrixAutoUpdate=pn.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=pn.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new cm,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return Oo.setFromAxisAngle(e,t),this.quaternion.multiply(Oo),this}rotateOnWorldAxis(e,t){return Oo.setFromAxisAngle(e,t),this.quaternion.premultiply(Oo),this}rotateX(e){return this.rotateOnAxis(Cg,e)}rotateY(e){return this.rotateOnAxis(Ng,e)}rotateZ(e){return this.rotateOnAxis(Pg,e)}translateOnAxis(e,t){return Rg.copy(e).applyQuaternion(this.quaternion),this.position.add(Rg.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(Cg,e)}translateY(e){return this.translateOnAxis(Ng,e)}translateZ(e){return this.translateOnAxis(Pg,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(Pr.copy(this.matrixWorld).invert())}lookAt(e,t,n){e.isVector3?Kc.copy(e):Kc.set(e,t,n);const i=this.parent;this.updateWorldMatrix(!0,!1),xl.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Pr.lookAt(xl,Kc,this.up):Pr.lookAt(Kc,xl,this.up),this.quaternion.setFromRotationMatrix(Pr),i&&(Pr.extractRotation(i.matrixWorld),Oo.setFromRotationMatrix(Pr),this.quaternion.premultiply(Oo.invert()))}add(e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return e===this?(ce("Object3D.add: object can't be added as a child of itself.",e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(Dg),ko.child=e,this.dispatchEvent(ko),ko.child=null):ce("Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let n=0;n<arguments.length;n++)this.remove(arguments[n]);return this}const t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(wT),fd.child=e,this.dispatchEvent(fd),fd.child=null),this}removeFromParent(){const e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),Pr.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),Pr.multiply(e.parent.matrixWorld)),e.applyMatrix4(Pr),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(Dg),ko.child=e,this.dispatchEvent(ko),ko.child=null,this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let n=0,i=this.children.length;n<i;n++){const o=this.children[n].getObjectByProperty(e,t);if(o!==void 0)return o}}getObjectsByProperty(e,t,n=[]){this[e]===t&&n.push(this);const i=this.children;for(let s=0,o=i.length;s<o;s++)i[s].getObjectsByProperty(e,t,n);return n}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(xl,e,ET),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(xl,AT,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);const t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);const t=this.children;for(let n=0,i=t.length;n<i;n++)t[n].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);const t=this.children;for(let n=0,i=t.length;n<i;n++)t[n].traverseVisible(e)}traverseAncestors(e){const t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const e=this.pivot;if(e!==null){const t=e.x,n=e.y,i=e.z,s=this.matrix.elements;s[12]+=t-s[0]*t-s[4]*n-s[8]*i,s[13]+=n-s[1]*t-s[5]*n-s[9]*i,s[14]+=i-s[2]*t-s[6]*n-s[10]*i}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);const t=this.children;for(let n=0,i=t.length;n<i;n++)t[n].updateMatrixWorld(e)}updateWorldMatrix(e,t){const n=this.parent;if(e===!0&&n!==null&&n.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)),t===!0){const i=this.children;for(let s=0,o=i.length;s<o;s++)i[s].updateWorldMatrix(!1,!0)}}toJSON(e){const t=e===void 0||typeof e=="string",n={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const i={};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.castShadow===!0&&(i.castShadow=!0),this.receiveShadow===!0&&(i.receiveShadow=!0),this.visible===!1&&(i.visible=!1),this.frustumCulled===!1&&(i.frustumCulled=!1),this.renderOrder!==0&&(i.renderOrder=this.renderOrder),this.static!==!1&&(i.static=this.static),Object.keys(this.userData).length>0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),this.pivot!==null&&(i.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(i.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(i.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(i.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(a=>({...a})),i.availableInstanceIds=this._availableInstanceIds.slice(),i.availableGeometryIds=this._availableGeometryIds.slice(),i.nextIndexStart=this._nextIndexStart,i.nextVertexStart=this._nextVertexStart,i.geometryCount=this._geometryCount,i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.matricesTexture=this._matricesTexture.toJSON(e),i.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(i.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(i.boundingBox=this.boundingBox.toJSON()));function s(a,l){return a[l.uuid]===void 0&&(a[l.uuid]=l.toJSON(e)),l.uuid}if(this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=s(e.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const l=a.shapes;if(Array.isArray(l))for(let c=0,u=l.length;c<u;c++){const h=l[c];s(e.shapes,h)}else s(e.shapes,l)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(e.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let l=0,c=this.material.length;l<c;l++)a.push(s(e.materials,this.material[l]));i.material=a}else i.material=s(e.materials,this.material);if(this.children.length>0){i.children=[];for(let a=0;a<this.children.length;a++)i.children.push(this.children[a].toJSON(e).object)}if(this.animations.length>0){i.animations=[];for(let a=0;a<this.animations.length;a++){const l=this.animations[a];i.animations.push(s(e.animations,l))}}if(t){const a=o(e.geometries),l=o(e.materials),c=o(e.textures),u=o(e.images),h=o(e.shapes),d=o(e.skeletons),f=o(e.animations),p=o(e.nodes);a.length>0&&(n.geometries=a),l.length>0&&(n.materials=l),c.length>0&&(n.textures=c),u.length>0&&(n.images=u),h.length>0&&(n.shapes=h),d.length>0&&(n.skeletons=d),f.length>0&&(n.animations=f),p.length>0&&(n.nodes=p)}return n.object=i,n;function o(a){const l=[];for(const c in a){const u=a[c];delete u.metadata,l.push(u)}return l}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.pivot=e.pivot!==null?e.pivot.clone():null,this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.static=e.static,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let n=0;n<e.children.length;n++){const i=e.children[n];this.add(i.clone())}return this}}pn.DEFAULT_UP=new P(0,1,0);pn.DEFAULT_MATRIX_AUTO_UPDATE=!0;pn.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class ua extends pn{constructor(){super(),this.isGroup=!0,this.type="Group"}}const RT={type:"move"};class oh{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new ua,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new ua,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new P,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new P),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new ua,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new P,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new P,this._grip.eventsEnabled=!1),this._grip}dispatchEvent(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){const t=this._hand;if(t)for(const n of e.hand.values())this._getHandJoint(t,n)}return this.dispatchEvent({type:"connected",data:e}),this}disconnect(e){return this.dispatchEvent({type:"disconnected",data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,n){let i=null,s=null,o=null;const a=this._targetRay,l=this._grip,c=this._hand;if(e&&t.session.visibilityState!=="visible-blurred"){if(c&&e.hand){o=!0;for(const g of e.hand.values()){const m=t.getJointPose(g,n),_=this._getHandJoint(c,g);m!==null&&(_.matrix.fromArray(m.transform.matrix),_.matrix.decompose(_.position,_.rotation,_.scale),_.matrixWorldNeedsUpdate=!0,_.jointRadius=m.radius),_.visible=m!==null}const u=c.joints["index-finger-tip"],h=c.joints["thumb-tip"],d=u.position.distanceTo(h.position),f=.02,p=.005;c.inputState.pinching&&d>f+p?(c.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!c.inputState.pinching&&d<=f-p&&(c.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else l!==null&&e.gripSpace&&(s=t.getPose(e.gripSpace,n),s!==null&&(l.matrix.fromArray(s.transform.matrix),l.matrix.decompose(l.position,l.rotation,l.scale),l.matrixWorldNeedsUpdate=!0,s.linearVelocity?(l.hasLinearVelocity=!0,l.linearVelocity.copy(s.linearVelocity)):l.hasLinearVelocity=!1,s.angularVelocity?(l.hasAngularVelocity=!0,l.angularVelocity.copy(s.angularVelocity)):l.hasAngularVelocity=!1,l.eventsEnabled&&l.dispatchEvent({type:"gripUpdated",data:e,target:this})));a!==null&&(i=t.getPose(e.targetRaySpace,n),i===null&&s!==null&&(i=s),i!==null&&(a.matrix.fromArray(i.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,i.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(i.linearVelocity)):a.hasLinearVelocity=!1,i.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(i.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(RT)))}return a!==null&&(a.visible=i!==null),l!==null&&(l.visible=s!==null),c!==null&&(c.visible=o!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){const n=new ua;n.matrixAutoUpdate=!1,n.visible=!1,e.joints[t.jointName]=n,e.add(n)}return e.joints[t.jointName]}}const J0={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},ss={h:0,s:0,l:0},Zc={h:0,s:0,l:0};function pd(r,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?r+(e-r)*6*t:t<1/2?e:t<2/3?r+(e-r)*6*(2/3-t):r}class We{constructor(e,t,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,n)}set(e,t,n){if(t===void 0&&n===void 0){const i=e;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(e,t,n);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=ei){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Ye.colorSpaceToWorking(this,t),this}setRGB(e,t,n,i=Ye.workingColorSpace){return this.r=e,this.g=t,this.b=n,Ye.colorSpaceToWorking(this,i),this}setHSL(e,t,n,i=Ye.workingColorSpace){if(e=om(e,1),t=ct(t,0,1),n=ct(n,0,1),t===0)this.r=this.g=this.b=n;else{const s=n<=.5?n*(1+t):n+t-n*t,o=2*n-s;this.r=pd(o,s,e+1/3),this.g=pd(o,s,e),this.b=pd(o,s,e-1/3)}return Ye.colorSpaceToWorking(this,i),this}setStyle(e,t=ei){function n(s){s!==void 0&&parseFloat(s)<1&&ae("Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(e)){let s;const o=i[1],a=i[2];switch(o){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,t);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,t);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,t);break;default:ae("Color: Unknown color model "+e)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(e)){const s=i[1],o=s.length;if(o===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,t);if(o===6)return this.setHex(parseInt(s,16),t);ae("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=ei){const n=J0[e.toLowerCase()];return n!==void 0?this.setHex(n,t):ae("Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=jr(e.r),this.g=jr(e.g),this.b=jr(e.b),this}copyLinearToSRGB(e){return this.r=_a(e.r),this.g=_a(e.g),this.b=_a(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=ei){return Ye.workingToColorSpace(zn.copy(this),e),Math.round(ct(zn.r*255,0,255))*65536+Math.round(ct(zn.g*255,0,255))*256+Math.round(ct(zn.b*255,0,255))}getHexString(e=ei){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=Ye.workingColorSpace){Ye.workingToColorSpace(zn.copy(this),t);const n=zn.r,i=zn.g,s=zn.b,o=Math.max(n,i,s),a=Math.min(n,i,s);let l,c;const u=(a+o)/2;if(a===o)l=0,c=0;else{const h=o-a;switch(c=u<=.5?h/(o+a):h/(2-o-a),o){case n:l=(i-s)/h+(i<s?6:0);break;case i:l=(s-n)/h+2;break;case s:l=(n-i)/h+4;break}l/=6}return e.h=l,e.s=c,e.l=u,e}getRGB(e,t=Ye.workingColorSpace){return Ye.workingToColorSpace(zn.copy(this),t),e.r=zn.r,e.g=zn.g,e.b=zn.b,e}getStyle(e=ei){Ye.workingToColorSpace(zn.copy(this),e);const t=zn.r,n=zn.g,i=zn.b;return e!==ei?`color(${e} ${t.toFixed(3)} ${n.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(t*255)},${Math.round(n*255)},${Math.round(i*255)})`}offsetHSL(e,t,n){return this.getHSL(ss),this.setHSL(ss.h+e,ss.s+t,ss.l+n)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,n){return this.r=e.r+(t.r-e.r)*n,this.g=e.g+(t.g-e.g)*n,this.b=e.b+(t.b-e.b)*n,this}lerpHSL(e,t){this.getHSL(ss),e.getHSL(Zc);const n=jl(ss.h,Zc.h,t),i=jl(ss.s,Zc.s,t),s=jl(ss.l,Zc.l,t);return this.setHSL(n,i,s),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){const t=this.r,n=this.g,i=this.b,s=e.elements;return this.r=s[0]*t+s[3]*n+s[6]*i,this.g=s[1]*t+s[4]*n+s[7]*i,this.b=s[2]*t+s[5]*n+s[8]*i,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const zn=new We;We.NAMES=J0;class um{constructor(e,t=1,n=1e3){this.isFog=!0,this.name="",this.color=new We(e),this.near=t,this.far=n}clone(){return new um(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class hm extends pn{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new Mr,this.environmentIntensity=1,this.environmentRotation=new Mr,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}}const Hi=new P,Dr=new P,md=new P,Lr=new P,Go=new P,Vo=new P,Lg=new P,gd=new P,_d=new P,xd=new P,yd=new rt,vd=new rt,bd=new rt;class Pi{constructor(e=new P,t=new P,n=new P){this.a=e,this.b=t,this.c=n}static getNormal(e,t,n,i){i.subVectors(n,t),Hi.subVectors(e,t),i.cross(Hi);const s=i.lengthSq();return s>0?i.multiplyScalar(1/Math.sqrt(s)):i.set(0,0,0)}static getBarycoord(e,t,n,i,s){Hi.subVectors(i,t),Dr.subVectors(n,t),md.subVectors(e,t);const o=Hi.dot(Hi),a=Hi.dot(Dr),l=Hi.dot(md),c=Dr.dot(Dr),u=Dr.dot(md),h=o*c-a*a;if(h===0)return s.set(0,0,0),null;const d=1/h,f=(c*l-a*u)*d,p=(o*u-a*l)*d;return s.set(1-f-p,p,f)}static containsPoint(e,t,n,i){return this.getBarycoord(e,t,n,i,Lr)===null?!1:Lr.x>=0&&Lr.y>=0&&Lr.x+Lr.y<=1}static getInterpolation(e,t,n,i,s,o,a,l){return this.getBarycoord(e,t,n,i,Lr)===null?(l.x=0,l.y=0,"z"in l&&(l.z=0),"w"in l&&(l.w=0),null):(l.setScalar(0),l.addScaledVector(s,Lr.x),l.addScaledVector(o,Lr.y),l.addScaledVector(a,Lr.z),l)}static getInterpolatedAttribute(e,t,n,i,s,o){return yd.setScalar(0),vd.setScalar(0),bd.setScalar(0),yd.fromBufferAttribute(e,t),vd.fromBufferAttribute(e,n),bd.fromBufferAttribute(e,i),o.setScalar(0),o.addScaledVector(yd,s.x),o.addScaledVector(vd,s.y),o.addScaledVector(bd,s.z),o}static isFrontFacing(e,t,n,i){return Hi.subVectors(n,t),Dr.subVectors(e,t),Hi.cross(Dr).dot(i)<0}set(e,t,n){return this.a.copy(e),this.b.copy(t),this.c.copy(n),this}setFromPointsAndIndices(e,t,n,i){return this.a.copy(e[t]),this.b.copy(e[n]),this.c.copy(e[i]),this}setFromAttributeAndIndices(e,t,n,i){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,n),this.c.fromBufferAttribute(e,i),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return Hi.subVectors(this.c,this.b),Dr.subVectors(this.a,this.b),Hi.cross(Dr).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return Pi.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return Pi.getBarycoord(e,this.a,this.b,this.c,t)}getInterpolation(e,t,n,i,s){return Pi.getInterpolation(e,this.a,this.b,this.c,t,n,i,s)}containsPoint(e){return Pi.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return Pi.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){const n=this.a,i=this.b,s=this.c;let o,a;Go.subVectors(i,n),Vo.subVectors(s,n),gd.subVectors(e,n);const l=Go.dot(gd),c=Vo.dot(gd);if(l<=0&&c<=0)return t.copy(n);_d.subVectors(e,i);const u=Go.dot(_d),h=Vo.dot(_d);if(u>=0&&h<=u)return t.copy(i);const d=l*h-u*c;if(d<=0&&l>=0&&u<=0)return o=l/(l-u),t.copy(n).addScaledVector(Go,o);xd.subVectors(e,s);const f=Go.dot(xd),p=Vo.dot(xd);if(p>=0&&f<=p)return t.copy(s);const g=f*c-l*p;if(g<=0&&c>=0&&p<=0)return a=c/(c-p),t.copy(n).addScaledVector(Vo,a);const m=u*p-f*h;if(m<=0&&h-u>=0&&f-p>=0)return Lg.subVectors(s,i),a=(h-u)/(h-u+(f-p)),t.copy(i).addScaledVector(Lg,a);const _=1/(m+g+d);return o=g*_,a=d*_,t.copy(n).addScaledVector(Go,o).addScaledVector(Vo,a)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}}class Ro{constructor(e=new P(1/0,1/0,1/0),t=new P(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t+=3)this.expandByPoint(Wi.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,n=e.count;t<n;t++)this.expandByPoint(Wi.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){const n=Wi.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(n),this.max.copy(e).add(n),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);const n=e.geometry;if(n!==void 0){const s=n.getAttribute("position");if(t===!0&&s!==void 0&&e.isInstancedMesh!==!0)for(let o=0,a=s.count;o<a;o++)e.isMesh===!0?e.getVertexPosition(o,Wi):Wi.fromBufferAttribute(s,o),Wi.applyMatrix4(e.matrixWorld),this.expandByPoint(Wi);else e.boundingBox!==void 0?(e.boundingBox===null&&e.computeBoundingBox(),Qc.copy(e.boundingBox)):(n.boundingBox===null&&n.computeBoundingBox(),Qc.copy(n.boundingBox)),Qc.applyMatrix4(e.matrixWorld),this.union(Qc)}const i=e.children;for(let s=0,o=i.length;s<o;s++)this.expandByObject(i[s],t);return this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,Wi),Wi.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,n;return e.normal.x>0?(t=e.normal.x*this.min.x,n=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,n=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,n+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,n+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,n+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,n+=e.normal.z*this.min.z),t<=-e.constant&&n>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(yl),Jc.subVectors(this.max,yl),zo.subVectors(e.a,yl),Ho.subVectors(e.b,yl),Wo.subVectors(e.c,yl),os.subVectors(Ho,zo),as.subVectors(Wo,Ho),Xs.subVectors(zo,Wo);let t=[0,-os.z,os.y,0,-as.z,as.y,0,-Xs.z,Xs.y,os.z,0,-os.x,as.z,0,-as.x,Xs.z,0,-Xs.x,-os.y,os.x,0,-as.y,as.x,0,-Xs.y,Xs.x,0];return!Sd(t,zo,Ho,Wo,Jc)||(t=[1,0,0,0,1,0,0,0,1],!Sd(t,zo,Ho,Wo,Jc))?!1:(eu.crossVectors(os,as),t=[eu.x,eu.y,eu.z],Sd(t,zo,Ho,Wo,Jc))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Wi).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Wi).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(Ur[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Ur[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Ur[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Ur[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Ur[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Ur[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Ur[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Ur[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Ur),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}}const Ur=[new P,new P,new P,new P,new P,new P,new P,new P],Wi=new P,Qc=new Ro,zo=new P,Ho=new P,Wo=new P,os=new P,as=new P,Xs=new P,yl=new P,Jc=new P,eu=new P,qs=new P;function Sd(r,e,t,n,i){for(let s=0,o=r.length-3;s<=o;s+=3){qs.fromArray(r,s);const a=i.x*Math.abs(qs.x)+i.y*Math.abs(qs.y)+i.z*Math.abs(qs.z),l=e.dot(qs),c=t.dot(qs),u=n.dot(qs);if(Math.max(-Math.max(l,c,u),Math.min(l,c,u))>a)return!1}return!0}const Vr=CT();function CT(){const r=new ArrayBuffer(4),e=new Float32Array(r),t=new Uint32Array(r),n=new Uint32Array(512),i=new Uint32Array(512);for(let l=0;l<256;++l){const c=l-127;c<-27?(n[l]=0,n[l|256]=32768,i[l]=24,i[l|256]=24):c<-14?(n[l]=1024>>-c-14,n[l|256]=1024>>-c-14|32768,i[l]=-c-1,i[l|256]=-c-1):c<=15?(n[l]=c+15<<10,n[l|256]=c+15<<10|32768,i[l]=13,i[l|256]=13):c<128?(n[l]=31744,n[l|256]=64512,i[l]=24,i[l|256]=24):(n[l]=31744,n[l|256]=64512,i[l]=13,i[l|256]=13)}const s=new Uint32Array(2048),o=new Uint32Array(64),a=new Uint32Array(64);for(let l=1;l<1024;++l){let c=l<<13,u=0;for(;(c&8388608)===0;)c<<=1,u-=8388608;c&=-8388609,u+=947912704,s[l]=c|u}for(let l=1024;l<2048;++l)s[l]=939524096+(l-1024<<13);for(let l=1;l<31;++l)o[l]=l<<23;o[31]=1199570944,o[32]=2147483648;for(let l=33;l<63;++l)o[l]=2147483648+(l-32<<23);o[63]=3347054592;for(let l=1;l<64;++l)l!==32&&(a[l]=1024);return{floatView:e,uint32View:t,baseTable:n,shiftTable:i,mantissaTable:s,exponentTable:o,offsetTable:a}}function xi(r){Math.abs(r)>65504&&ae("DataUtils.toHalfFloat(): Value out of range."),r=ct(r,-65504,65504),Vr.floatView[0]=r;const e=Vr.uint32View[0],t=e>>23&511;return Vr.baseTable[t]+((e&8388607)>>Vr.shiftTable[t])}function tu(r){const e=r>>10;return Vr.uint32View[0]=Vr.mantissaTable[Vr.offsetTable[e]+(r&1023)]+Vr.exponentTable[e],Vr.floatView[0]}const gn=new P,nu=new pe;let NT=0;class Bn extends Vi{constructor(e,t,n=!1){if(super(),Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:NT++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=n,this.usage=Ya,this.updateRanges=[],this.gpuType=Qt,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,n){e*=this.itemSize,n*=t.itemSize;for(let i=0,s=this.itemSize;i<s;i++)this.array[e+i]=t.array[n+i];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,n=this.count;t<n;t++)nu.fromBufferAttribute(this,t),nu.applyMatrix3(e),this.setXY(t,nu.x,nu.y);else if(this.itemSize===3)for(let t=0,n=this.count;t<n;t++)gn.fromBufferAttribute(this,t),gn.applyMatrix3(e),this.setXYZ(t,gn.x,gn.y,gn.z);return this}applyMatrix4(e){for(let t=0,n=this.count;t<n;t++)gn.fromBufferAttribute(this,t),gn.applyMatrix4(e),this.setXYZ(t,gn.x,gn.y,gn.z);return this}applyNormalMatrix(e){for(let t=0,n=this.count;t<n;t++)gn.fromBufferAttribute(this,t),gn.applyNormalMatrix(e),this.setXYZ(t,gn.x,gn.y,gn.z);return this}transformDirection(e){for(let t=0,n=this.count;t<n;t++)gn.fromBufferAttribute(this,t),gn.transformDirection(e),this.setXYZ(t,gn.x,gn.y,gn.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let n=this.array[e*this.itemSize+t];return this.normalized&&(n=ni(n,this.array)),n}setComponent(e,t,n){return this.normalized&&(n=lt(n,this.array)),this.array[e*this.itemSize+t]=n,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=ni(t,this.array)),t}setX(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=ni(t,this.array)),t}setY(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=ni(t,this.array)),t}setZ(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=ni(t,this.array)),t}setW(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,n){return e*=this.itemSize,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array)),this.array[e+0]=t,this.array[e+1]=n,this}setXYZ(e,t,n,i){return e*=this.itemSize,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array),i=lt(i,this.array)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=i,this}setXYZW(e,t,n,i,s){return e*=this.itemSize,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array),i=lt(i,this.array),s=lt(s,this.array)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=i,this.array[e+3]=s,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(e.name=this.name),this.usage!==Ya&&(e.usage=this.usage),e}dispose(){this.dispatchEvent({type:"dispose"})}}class dm extends Bn{constructor(e,t,n){super(new Uint16Array(e),t,n)}}class fm extends Bn{constructor(e,t,n){super(new Uint32Array(e),t,n)}}class ey extends Bn{constructor(e,t,n){super(new Uint16Array(e),t,n),this.isFloat16BufferAttribute=!0}getX(e){let t=tu(this.array[e*this.itemSize]);return this.normalized&&(t=ni(t,this.array)),t}setX(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize]=xi(t),this}getY(e){let t=tu(this.array[e*this.itemSize+1]);return this.normalized&&(t=ni(t,this.array)),t}setY(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize+1]=xi(t),this}getZ(e){let t=tu(this.array[e*this.itemSize+2]);return this.normalized&&(t=ni(t,this.array)),t}setZ(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize+2]=xi(t),this}getW(e){let t=tu(this.array[e*this.itemSize+3]);return this.normalized&&(t=ni(t,this.array)),t}setW(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize+3]=xi(t),this}setXY(e,t,n){return e*=this.itemSize,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array)),this.array[e+0]=xi(t),this.array[e+1]=xi(n),this}setXYZ(e,t,n,i){return e*=this.itemSize,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array),i=lt(i,this.array)),this.array[e+0]=xi(t),this.array[e+1]=xi(n),this.array[e+2]=xi(i),this}setXYZW(e,t,n,i,s){return e*=this.itemSize,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array),i=lt(i,this.array),s=lt(s,this.array)),this.array[e+0]=xi(t),this.array[e+1]=xi(n),this.array[e+2]=xi(i),this.array[e+3]=xi(s),this}}class sn extends Bn{constructor(e,t,n){super(new Float32Array(e),t,n)}}const PT=new Ro,vl=new P,Td=new P;class Fc{constructor(e=new P,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){const n=this.center;t!==void 0?n.copy(t):PT.setFromPoints(e).getCenter(n);let i=0;for(let s=0,o=e.length;s<o;s++)i=Math.max(i,n.distanceToSquared(e[s]));return this.radius=Math.sqrt(i),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){const t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){const n=this.center.distanceToSquared(e);return t.copy(e),n>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;vl.subVectors(e,this.center);const t=vl.lengthSq();if(t>this.radius*this.radius){const n=Math.sqrt(t),i=(n-this.radius)*.5;this.center.addScaledVector(vl,i/n),this.radius+=i}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(Td.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(vl.copy(e.center).add(Td)),this.expandByPoint(vl.copy(e.center).sub(Td))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}}let DT=0;const wi=new pt,Md=new pn,$o=new P,yi=new Ro,bl=new Ro,wn=new P;class An extends Vi{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:DT++}),this.uuid=qr(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(JS(e)?fm:dm)(e,1):this.index=e,this}setIndirect(e,t=0){return this.indirect=e,this.indirectOffset=t,this}getIndirect(){return this.indirect}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,n=0){this.groups.push({start:e,count:t,materialIndex:n})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){const t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);const n=this.attributes.normal;if(n!==void 0){const s=new Je().getNormalMatrix(e);n.applyNormalMatrix(s),n.needsUpdate=!0}const i=this.attributes.tangent;return i!==void 0&&(i.transformDirection(e),i.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(e){return wi.makeRotationFromQuaternion(e),this.applyMatrix4(wi),this}rotateX(e){return wi.makeRotationX(e),this.applyMatrix4(wi),this}rotateY(e){return wi.makeRotationY(e),this.applyMatrix4(wi),this}rotateZ(e){return wi.makeRotationZ(e),this.applyMatrix4(wi),this}translate(e,t,n){return wi.makeTranslation(e,t,n),this.applyMatrix4(wi),this}scale(e,t,n){return wi.makeScale(e,t,n),this.applyMatrix4(wi),this}lookAt(e){return Md.lookAt(e),Md.updateMatrix(),this.applyMatrix4(Md.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter($o).negate(),this.translate($o.x,$o.y,$o.z),this}setFromPoints(e){const t=this.getAttribute("position");if(t===void 0){const n=[];for(let i=0,s=e.length;i<s;i++){const o=e[i];n.push(o.x,o.y,o.z||0)}this.setAttribute("position",new sn(n,3))}else{const n=Math.min(e.length,t.count);for(let i=0;i<n;i++){const s=e[i];t.setXYZ(i,s.x,s.y,s.z||0)}e.length>t.count&&ae("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Ro);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){ce("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new P(-1/0,-1/0,-1/0),new P(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let n=0,i=t.length;n<i;n++){const s=t[n];yi.setFromBufferAttribute(s),this.morphTargetsRelative?(wn.addVectors(this.boundingBox.min,yi.min),this.boundingBox.expandByPoint(wn),wn.addVectors(this.boundingBox.max,yi.max),this.boundingBox.expandByPoint(wn)):(this.boundingBox.expandByPoint(yi.min),this.boundingBox.expandByPoint(yi.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&ce('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 Fc);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){ce("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new P,1/0);return}if(e){const n=this.boundingSphere.center;if(yi.setFromBufferAttribute(e),t)for(let s=0,o=t.length;s<o;s++){const a=t[s];bl.setFromBufferAttribute(a),this.morphTargetsRelative?(wn.addVectors(yi.min,bl.min),yi.expandByPoint(wn),wn.addVectors(yi.max,bl.max),yi.expandByPoint(wn)):(yi.expandByPoint(bl.min),yi.expandByPoint(bl.max))}yi.getCenter(n);let i=0;for(let s=0,o=e.count;s<o;s++)wn.fromBufferAttribute(e,s),i=Math.max(i,n.distanceToSquared(wn));if(t)for(let s=0,o=t.length;s<o;s++){const a=t[s],l=this.morphTargetsRelative;for(let c=0,u=a.count;c<u;c++)wn.fromBufferAttribute(a,c),l&&($o.fromBufferAttribute(e,c),wn.add($o)),i=Math.max(i,n.distanceToSquared(wn))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&ce('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){ce("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const n=t.position,i=t.normal,s=t.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new Bn(new Float32Array(4*n.count),4));const o=this.getAttribute("tangent"),a=[],l=[];for(let v=0;v<n.count;v++)a[v]=new P,l[v]=new P;const c=new P,u=new P,h=new P,d=new pe,f=new pe,p=new pe,g=new P,m=new P;function _(v,w,N){c.fromBufferAttribute(n,v),u.fromBufferAttribute(n,w),h.fromBufferAttribute(n,N),d.fromBufferAttribute(s,v),f.fromBufferAttribute(s,w),p.fromBufferAttribute(s,N),u.sub(c),h.sub(c),f.sub(d),p.sub(d);const C=1/(f.x*p.y-p.x*f.y);isFinite(C)&&(g.copy(u).multiplyScalar(p.y).addScaledVector(h,-f.y).multiplyScalar(C),m.copy(h).multiplyScalar(f.x).addScaledVector(u,-p.x).multiplyScalar(C),a[v].add(g),a[w].add(g),a[N].add(g),l[v].add(m),l[w].add(m),l[N].add(m))}let x=this.groups;x.length===0&&(x=[{start:0,count:e.count}]);for(let v=0,w=x.length;v<w;++v){const N=x[v],C=N.start,F=N.count;for(let V=C,z=C+F;V<z;V+=3)_(e.getX(V+0),e.getX(V+1),e.getX(V+2))}const y=new P,b=new P,M=new P,S=new P;function E(v){M.fromBufferAttribute(i,v),S.copy(M);const w=a[v];y.copy(w),y.sub(M.multiplyScalar(M.dot(w))).normalize(),b.crossVectors(S,w);const C=b.dot(l[v])<0?-1:1;o.setXYZW(v,y.x,y.y,y.z,C)}for(let v=0,w=x.length;v<w;++v){const N=x[v],C=N.start,F=N.count;for(let V=C,z=C+F;V<z;V+=3)E(e.getX(V+0)),E(e.getX(V+1)),E(e.getX(V+2))}}computeVertexNormals(){const e=this.index,t=this.getAttribute("position");if(t!==void 0){let n=this.getAttribute("normal");if(n===void 0)n=new Bn(new Float32Array(t.count*3),3),this.setAttribute("normal",n);else for(let d=0,f=n.count;d<f;d++)n.setXYZ(d,0,0,0);const i=new P,s=new P,o=new P,a=new P,l=new P,c=new P,u=new P,h=new P;if(e)for(let d=0,f=e.count;d<f;d+=3){const p=e.getX(d+0),g=e.getX(d+1),m=e.getX(d+2);i.fromBufferAttribute(t,p),s.fromBufferAttribute(t,g),o.fromBufferAttribute(t,m),u.subVectors(o,s),h.subVectors(i,s),u.cross(h),a.fromBufferAttribute(n,p),l.fromBufferAttribute(n,g),c.fromBufferAttribute(n,m),a.add(u),l.add(u),c.add(u),n.setXYZ(p,a.x,a.y,a.z),n.setXYZ(g,l.x,l.y,l.z),n.setXYZ(m,c.x,c.y,c.z)}else for(let d=0,f=t.count;d<f;d+=3)i.fromBufferAttribute(t,d+0),s.fromBufferAttribute(t,d+1),o.fromBufferAttribute(t,d+2),u.subVectors(o,s),h.subVectors(i,s),u.cross(h),n.setXYZ(d+0,u.x,u.y,u.z),n.setXYZ(d+1,u.x,u.y,u.z),n.setXYZ(d+2,u.x,u.y,u.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){const e=this.attributes.normal;for(let t=0,n=e.count;t<n;t++)wn.fromBufferAttribute(e,t),wn.normalize(),e.setXYZ(t,wn.x,wn.y,wn.z)}toNonIndexed(){function e(a,l){const c=a.array,u=a.itemSize,h=a.normalized,d=new c.constructor(l.length*u);let f=0,p=0;for(let g=0,m=l.length;g<m;g++){a.isInterleavedBufferAttribute?f=l[g]*a.data.stride+a.offset:f=l[g]*u;for(let _=0;_<u;_++)d[p++]=c[f++]}return new Bn(d,u,h)}if(this.index===null)return ae("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const t=new An,n=this.index.array,i=this.attributes;for(const a in i){const l=i[a],c=e(l,n);t.setAttribute(a,c)}const s=this.morphAttributes;for(const a in s){const l=[],c=s[a];for(let u=0,h=c.length;u<h;u++){const d=c[u],f=e(d,n);l.push(f)}t.morphAttributes[a]=l}t.morphTargetsRelative=this.morphTargetsRelative;const o=this.groups;for(let a=0,l=o.length;a<l;a++){const c=o[a];t.addGroup(c.start,c.count,c.materialIndex)}return t}toJSON(){const e={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(e.uuid=this.uuid,e.type=this.type,this.name!==""&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0){const l=this.parameters;for(const c in l)l[c]!==void 0&&(e[c]=l[c]);return e}e.data={attributes:{}};const t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});const n=this.attributes;for(const l in n){const c=n[l];e.data.attributes[l]=c.toJSON(e.data)}const i={};let s=!1;for(const l in this.morphAttributes){const c=this.morphAttributes[l],u=[];for(let h=0,d=c.length;h<d;h++){const f=c[h];u.push(f.toJSON(e.data))}u.length>0&&(i[l]=u,s=!0)}s&&(e.data.morphAttributes=i,e.data.morphTargetsRelative=this.morphTargetsRelative);const o=this.groups;o.length>0&&(e.data.groups=JSON.parse(JSON.stringify(o)));const a=this.boundingSphere;return a!==null&&(e.data.boundingSphere=a.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const t={};this.name=e.name;const n=e.index;n!==null&&this.setIndex(n.clone());const i=e.attributes;for(const c in i){const u=i[c];this.setAttribute(c,u.clone(t))}const s=e.morphAttributes;for(const c in s){const u=[],h=s[c];for(let d=0,f=h.length;d<f;d++)u.push(h[d].clone(t));this.morphAttributes[c]=u}this.morphTargetsRelative=e.morphTargetsRelative;const o=e.groups;for(let c=0,u=o.length;c<u;c++){const h=o[c];this.addGroup(h.start,h.count,h.materialIndex)}const a=e.boundingBox;a!==null&&(this.boundingBox=a.clone());const l=e.boundingSphere;return l!==null&&(this.boundingSphere=l.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}class pm{constructor(e,t){this.isInterleavedBuffer=!0,this.array=e,this.stride=t,this.count=e!==void 0?e.length/t:0,this.usage=Ya,this.updateRanges=[],this.version=0,this.uuid=qr()}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.array=new e.array.constructor(e.array),this.count=e.count,this.stride=e.stride,this.usage=e.usage,this}copyAt(e,t,n){e*=this.stride,n*=t.stride;for(let i=0,s=this.stride;i<s;i++)this.array[e+i]=t.array[n+i];return this}set(e,t=0){return this.array.set(e,t),this}clone(e){e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=qr()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const t=new this.array.constructor(e.arrayBuffers[this.array.buffer._uuid]),n=new this.constructor(t,this.stride);return n.setUsage(this.usage),n}onUpload(e){return this.onUploadCallback=e,this}toJSON(e){return e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=qr()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.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 Zn=new P;class Tc{constructor(e,t,n,i=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=e,this.itemSize=t,this.offset=n,this.normalized=i}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(e){this.data.needsUpdate=e}applyMatrix4(e){for(let t=0,n=this.data.count;t<n;t++)Zn.fromBufferAttribute(this,t),Zn.applyMatrix4(e),this.setXYZ(t,Zn.x,Zn.y,Zn.z);return this}applyNormalMatrix(e){for(let t=0,n=this.count;t<n;t++)Zn.fromBufferAttribute(this,t),Zn.applyNormalMatrix(e),this.setXYZ(t,Zn.x,Zn.y,Zn.z);return this}transformDirection(e){for(let t=0,n=this.count;t<n;t++)Zn.fromBufferAttribute(this,t),Zn.transformDirection(e),this.setXYZ(t,Zn.x,Zn.y,Zn.z);return this}getComponent(e,t){let n=this.array[e*this.data.stride+this.offset+t];return this.normalized&&(n=ni(n,this.array)),n}setComponent(e,t,n){return this.normalized&&(n=lt(n,this.array)),this.data.array[e*this.data.stride+this.offset+t]=n,this}setX(e,t){return this.normalized&&(t=lt(t,this.array)),this.data.array[e*this.data.stride+this.offset]=t,this}setY(e,t){return this.normalized&&(t=lt(t,this.array)),this.data.array[e*this.data.stride+this.offset+1]=t,this}setZ(e,t){return this.normalized&&(t=lt(t,this.array)),this.data.array[e*this.data.stride+this.offset+2]=t,this}setW(e,t){return this.normalized&&(t=lt(t,this.array)),this.data.array[e*this.data.stride+this.offset+3]=t,this}getX(e){let t=this.data.array[e*this.data.stride+this.offset];return this.normalized&&(t=ni(t,this.array)),t}getY(e){let t=this.data.array[e*this.data.stride+this.offset+1];return this.normalized&&(t=ni(t,this.array)),t}getZ(e){let t=this.data.array[e*this.data.stride+this.offset+2];return this.normalized&&(t=ni(t,this.array)),t}getW(e){let t=this.data.array[e*this.data.stride+this.offset+3];return this.normalized&&(t=ni(t,this.array)),t}setXY(e,t,n){return e=e*this.data.stride+this.offset,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=n,this}setXYZ(e,t,n,i){return e=e*this.data.stride+this.offset,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array),i=lt(i,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=n,this.data.array[e+2]=i,this}setXYZW(e,t,n,i,s){return e=e*this.data.stride+this.offset,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array),i=lt(i,this.array),s=lt(s,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=n,this.data.array[e+2]=i,this.data.array[e+3]=s,this}clone(e){if(e===void 0){Sc("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let n=0;n<this.count;n++){const i=n*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[i+s])}return new Bn(new this.array.constructor(t),this.itemSize,this.normalized)}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.clone(e)),new Tc(e.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(e){if(e===void 0){Sc("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let n=0;n<this.count;n++){const i=n*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[i+s])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.toJSON(e)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}let LT=0;class Yn extends Vi{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:LT++}),this.uuid=qr(),this.name="",this.type="Material",this.blending=ti,this.side=ri,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=oc,this.blendDst=ac,this.blendEquation=Xn,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new We(0,0,0),this.blendAlpha=0,this.depthFunc=Ds,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=np,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=eo,this.stencilZFail=eo,this.stencilZPass=eo,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(const t in e){const n=e[t];if(n===void 0){ae(`Material: parameter '${t}' has value of undefined.`);continue}const i=this[t];if(i===void 0){ae(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}i&&i.isColor?i.set(n):i&&i.isVector3&&n&&n.isVector3?i.copy(n):this[t]=n}}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});const n={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),this.roughness!==void 0&&(n.roughness=this.roughness),this.metalness!==void 0&&(n.metalness=this.metalness),this.sheen!==void 0&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(n.shininess=this.shininess),this.clearcoat!==void 0&&(n.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(n.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(n.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(n.dispersion=this.dispersion),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(n.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(e).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(e).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(e).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(e).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(e).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(n.combine=this.combine)),this.envMapRotation!==void 0&&(n.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(n.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(n.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.shadowSide!==null&&(n.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==ti&&(n.blending=this.blending),this.side!==ri&&(n.side=this.side),this.vertexColors===!0&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),this.transparent===!0&&(n.transparent=!0),this.blendSrc!==oc&&(n.blendSrc=this.blendSrc),this.blendDst!==ac&&(n.blendDst=this.blendDst),this.blendEquation!==Xn&&(n.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(n.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(n.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(n.blendAlpha=this.blendAlpha),this.depthFunc!==Ds&&(n.depthFunc=this.depthFunc),this.depthTest===!1&&(n.depthTest=this.depthTest),this.depthWrite===!1&&(n.depthWrite=this.depthWrite),this.colorWrite===!1&&(n.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(n.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==np&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==eo&&(n.stencilFail=this.stencilFail),this.stencilZFail!==eo&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==eo&&(n.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(n.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(n.rotation=this.rotation),this.polygonOffset===!0&&(n.polygonOffset=!0),this.polygonOffsetFactor!==0&&(n.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(n.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(n.linewidth=this.linewidth),this.dashSize!==void 0&&(n.dashSize=this.dashSize),this.gapSize!==void 0&&(n.gapSize=this.gapSize),this.scale!==void 0&&(n.scale=this.scale),this.dithering===!0&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),this.alphaHash===!0&&(n.alphaHash=!0),this.alphaToCoverage===!0&&(n.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(n.premultipliedAlpha=!0),this.forceSinglePass===!0&&(n.forceSinglePass=!0),this.allowOverride===!1&&(n.allowOverride=!1),this.wireframe===!0&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(n.flatShading=!0),this.visible===!1&&(n.visible=!1),this.toneMapped===!1&&(n.toneMapped=!1),this.fog===!1&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData);function i(s){const o=[];for(const a in s){const l=s[a];delete l.metadata,o.push(l)}return o}if(t){const s=i(e.textures),o=i(e.images);s.length>0&&(n.textures=s),o.length>0&&(n.images=o)}return n}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const t=e.clippingPlanes;let n=null;if(t!==null){const i=t.length;n=new Array(i);for(let s=0;s!==i;++s)n[s]=t[s].clone()}return this.clippingPlanes=n,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.allowOverride=e.allowOverride,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}}class mm extends Yn{constructor(e){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new We(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}let Xo;const Sl=new P,qo=new P,jo=new P,Yo=new pe,Tl=new pe,ty=new pt,iu=new P,Ml=new P,ru=new P,Ug=new pe,Ed=new pe,Fg=new pe;class UT extends pn{constructor(e=new mm){if(super(),this.isSprite=!0,this.type="Sprite",Xo===void 0){Xo=new An;const t=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),n=new pm(t,5);Xo.setIndex([0,1,2,0,2,3]),Xo.setAttribute("position",new Tc(n,3,0,!1)),Xo.setAttribute("uv",new Tc(n,2,3,!1))}this.geometry=Xo,this.material=e,this.center=new pe(.5,.5),this.count=1}raycast(e,t){e.camera===null&&ce('Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),qo.setFromMatrixScale(this.matrixWorld),ty.copy(e.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(e.camera.matrixWorldInverse,this.matrixWorld),jo.setFromMatrixPosition(this.modelViewMatrix),e.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&qo.multiplyScalar(-jo.z);const n=this.material.rotation;let i,s;n!==0&&(s=Math.cos(n),i=Math.sin(n));const o=this.center;su(iu.set(-.5,-.5,0),jo,o,qo,i,s),su(Ml.set(.5,-.5,0),jo,o,qo,i,s),su(ru.set(.5,.5,0),jo,o,qo,i,s),Ug.set(0,0),Ed.set(1,0),Fg.set(1,1);let a=e.ray.intersectTriangle(iu,Ml,ru,!1,Sl);if(a===null&&(su(Ml.set(-.5,.5,0),jo,o,qo,i,s),Ed.set(0,1),a=e.ray.intersectTriangle(iu,ru,Ml,!1,Sl),a===null))return;const l=e.ray.origin.distanceTo(Sl);l<e.near||l>e.far||t.push({distance:l,point:Sl.clone(),uv:Pi.getInterpolation(Sl,iu,Ml,ru,Ug,Ed,Fg,new pe),face:null,object:this})}copy(e,t){return super.copy(e,t),e.center!==void 0&&this.center.copy(e.center),this.material=e.material,this}}function su(r,e,t,n,i,s){Yo.subVectors(r,t).addScalar(.5).multiply(n),i!==void 0?(Tl.x=s*Yo.x-i*Yo.y,Tl.y=i*Yo.x+s*Yo.y):Tl.copy(Yo),r.copy(e),r.x+=Tl.x,r.y+=Tl.y,r.applyMatrix4(ty)}const Fr=new P,Ad=new P,ou=new P,ls=new P,wd=new P,au=new P,Rd=new P;class Bh{constructor(e=new P,t=new P(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,Fr)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);const n=t.dot(this.direction);return n<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const t=Fr.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(Fr.copy(this.origin).addScaledVector(this.direction,t),Fr.distanceToSquared(e))}distanceSqToSegment(e,t,n,i){Ad.copy(e).add(t).multiplyScalar(.5),ou.copy(t).sub(e).normalize(),ls.copy(this.origin).sub(Ad);const s=e.distanceTo(t)*.5,o=-this.direction.dot(ou),a=ls.dot(this.direction),l=-ls.dot(ou),c=ls.lengthSq(),u=Math.abs(1-o*o);let h,d,f,p;if(u>0)if(h=o*l-a,d=o*a-l,p=s*u,h>=0)if(d>=-p)if(d<=p){const g=1/u;h*=g,d*=g,f=h*(h+o*d+2*a)+d*(o*h+d+2*l)+c}else d=s,h=Math.max(0,-(o*d+a)),f=-h*h+d*(d+2*l)+c;else d=-s,h=Math.max(0,-(o*d+a)),f=-h*h+d*(d+2*l)+c;else d<=-p?(h=Math.max(0,-(-o*s+a)),d=h>0?-s:Math.min(Math.max(-s,-l),s),f=-h*h+d*(d+2*l)+c):d<=p?(h=0,d=Math.min(Math.max(-s,-l),s),f=d*(d+2*l)+c):(h=Math.max(0,-(o*s+a)),d=h>0?s:Math.min(Math.max(-s,-l),s),f=-h*h+d*(d+2*l)+c);else d=o>0?-s:s,h=Math.max(0,-(o*d+a)),f=-h*h+d*(d+2*l)+c;return n&&n.copy(this.origin).addScaledVector(this.direction,h),i&&i.copy(Ad).addScaledVector(ou,d),f}intersectSphere(e,t){Fr.subVectors(e.center,this.origin);const n=Fr.dot(this.direction),i=Fr.dot(Fr)-n*n,s=e.radius*e.radius;if(i>s)return null;const o=Math.sqrt(s-i),a=n-o,l=n+o;return l<0?null:a<0?this.at(l,t):this.at(a,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;const n=-(this.origin.dot(e.normal)+e.constant)/t;return n>=0?n:null}intersectPlane(e,t){const n=this.distanceToPlane(e);return n===null?null:this.at(n,t)}intersectsPlane(e){const t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let n,i,s,o,a,l;const c=1/this.direction.x,u=1/this.direction.y,h=1/this.direction.z,d=this.origin;return c>=0?(n=(e.min.x-d.x)*c,i=(e.max.x-d.x)*c):(n=(e.max.x-d.x)*c,i=(e.min.x-d.x)*c),u>=0?(s=(e.min.y-d.y)*u,o=(e.max.y-d.y)*u):(s=(e.max.y-d.y)*u,o=(e.min.y-d.y)*u),n>o||s>i||((s>n||isNaN(n))&&(n=s),(o<i||isNaN(i))&&(i=o),h>=0?(a=(e.min.z-d.z)*h,l=(e.max.z-d.z)*h):(a=(e.max.z-d.z)*h,l=(e.min.z-d.z)*h),n>l||a>i)||((a>n||n!==n)&&(n=a),(l<i||i!==i)&&(i=l),i<0)?null:this.at(n>=0?n:i,t)}intersectsBox(e){return this.intersectBox(e,Fr)!==null}intersectTriangle(e,t,n,i,s){wd.subVectors(t,e),au.subVectors(n,e),Rd.crossVectors(wd,au);let o=this.direction.dot(Rd),a;if(o>0){if(i)return null;a=1}else if(o<0)a=-1,o=-o;else return null;ls.subVectors(this.origin,e);const l=a*this.direction.dot(au.crossVectors(ls,au));if(l<0)return null;const c=a*this.direction.dot(wd.cross(ls));if(c<0||l+c>o)return null;const u=-a*ls.dot(Rd);return u<0?null:this.at(u/o,s)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class pr extends Yn{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new We(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Mr,this.combine=Nc,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}const Ig=new pt,js=new Bh,lu=new Fc,Bg=new P,cu=new P,uu=new P,hu=new P,Cd=new P,du=new P,Og=new P,fu=new P;class _n extends pn{constructor(e=new An,t=new pr){super(),this.isMesh=!0,this.type="Mesh",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){const t=this.geometry.morphAttributes,n=Object.keys(t);if(n.length>0){const i=t[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=i.length;s<o;s++){const a=i[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}getVertexPosition(e,t){const n=this.geometry,i=n.attributes.position,s=n.morphAttributes.position,o=n.morphTargetsRelative;t.fromBufferAttribute(i,e);const a=this.morphTargetInfluences;if(s&&a){du.set(0,0,0);for(let l=0,c=s.length;l<c;l++){const u=a[l],h=s[l];u!==0&&(Cd.fromBufferAttribute(h,e),o?du.addScaledVector(Cd,u):du.addScaledVector(Cd.sub(t),u))}t.add(du)}return t}raycast(e,t){const n=this.geometry,i=this.material,s=this.matrixWorld;i!==void 0&&(n.boundingSphere===null&&n.computeBoundingSphere(),lu.copy(n.boundingSphere),lu.applyMatrix4(s),js.copy(e.ray).recast(e.near),!(lu.containsPoint(js.origin)===!1&&(js.intersectSphere(lu,Bg)===null||js.origin.distanceToSquared(Bg)>(e.far-e.near)**2))&&(Ig.copy(s).invert(),js.copy(e.ray).applyMatrix4(Ig),!(n.boundingBox!==null&&js.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(e,t,js)))}_computeIntersections(e,t,n){let i;const s=this.geometry,o=this.material,a=s.index,l=s.attributes.position,c=s.attributes.uv,u=s.attributes.uv1,h=s.attributes.normal,d=s.groups,f=s.drawRange;if(a!==null)if(Array.isArray(o))for(let p=0,g=d.length;p<g;p++){const m=d[p],_=o[m.materialIndex],x=Math.max(m.start,f.start),y=Math.min(a.count,Math.min(m.start+m.count,f.start+f.count));for(let b=x,M=y;b<M;b+=3){const S=a.getX(b),E=a.getX(b+1),v=a.getX(b+2);i=pu(this,_,e,n,c,u,h,S,E,v),i&&(i.faceIndex=Math.floor(b/3),i.face.materialIndex=m.materialIndex,t.push(i))}}else{const p=Math.max(0,f.start),g=Math.min(a.count,f.start+f.count);for(let m=p,_=g;m<_;m+=3){const x=a.getX(m),y=a.getX(m+1),b=a.getX(m+2);i=pu(this,o,e,n,c,u,h,x,y,b),i&&(i.faceIndex=Math.floor(m/3),t.push(i))}}else if(l!==void 0)if(Array.isArray(o))for(let p=0,g=d.length;p<g;p++){const m=d[p],_=o[m.materialIndex],x=Math.max(m.start,f.start),y=Math.min(l.count,Math.min(m.start+m.count,f.start+f.count));for(let b=x,M=y;b<M;b+=3){const S=b,E=b+1,v=b+2;i=pu(this,_,e,n,c,u,h,S,E,v),i&&(i.faceIndex=Math.floor(b/3),i.face.materialIndex=m.materialIndex,t.push(i))}}else{const p=Math.max(0,f.start),g=Math.min(l.count,f.start+f.count);for(let m=p,_=g;m<_;m+=3){const x=m,y=m+1,b=m+2;i=pu(this,o,e,n,c,u,h,x,y,b),i&&(i.faceIndex=Math.floor(m/3),t.push(i))}}}}function FT(r,e,t,n,i,s,o,a){let l;if(e.side===Lt?l=n.intersectTriangle(o,s,i,!0,a):l=n.intersectTriangle(i,s,o,e.side===ri,a),l===null)return null;fu.copy(a),fu.applyMatrix4(r.matrixWorld);const c=t.ray.origin.distanceTo(fu);return c<t.near||c>t.far?null:{distance:c,point:fu.clone(),object:r}}function pu(r,e,t,n,i,s,o,a,l,c){r.getVertexPosition(a,cu),r.getVertexPosition(l,uu),r.getVertexPosition(c,hu);const u=FT(r,e,t,n,cu,uu,hu,Og);if(u){const h=new P;Pi.getBarycoord(Og,cu,uu,hu,h),i&&(u.uv=Pi.getInterpolatedAttribute(i,a,l,c,h,new pe)),s&&(u.uv1=Pi.getInterpolatedAttribute(s,a,l,c,h,new pe)),o&&(u.normal=Pi.getInterpolatedAttribute(o,a,l,c,h,new P),u.normal.dot(n.direction)>0&&u.normal.multiplyScalar(-1));const d={a,b:l,c,normal:new P,materialIndex:0};Pi.getNormal(cu,uu,hu,d.normal),u.face=d,u.barycoord=h}return u}class gm extends fn{constructor(e=null,t=1,n=1,i,s,o,a,l,c=Mt,u=Mt,h,d){super(null,o,a,l,c,u,i,s,h,d),this.isDataTexture=!0,this.image={data:e,width:t,height:n},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class IT extends Bn{constructor(e,t,n,i=1){super(e,t,n),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=i}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}toJSON(){const e=super.toJSON();return e.meshPerAttribute=this.meshPerAttribute,e.isInstancedBufferAttribute=!0,e}}const Nd=new P,BT=new P,OT=new Je;class ur{constructor(e=new P(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,n,i){return this.normal.set(e,t,n),this.constant=i,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,n){const i=Nd.subVectors(n,t).cross(BT.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(i,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){const e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t,n=!0){const i=e.delta(Nd),s=this.normal.dot(i);if(s===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;const o=-(e.start.dot(this.normal)+this.constant)/s;return n===!0&&(o<0||o>1)?null:t.copy(e.start).addScaledVector(i,o)}intersectsLine(e){const t=this.distanceToPoint(e.start),n=this.distanceToPoint(e.end);return t<0&&n>0||n<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){const n=t||OT.getNormalMatrix(e),i=this.coplanarPoint(Nd).applyMatrix4(e),s=this.normal.applyMatrix3(n).normalize();return this.constant=-i.dot(s),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}}const Ys=new Fc,kT=new pe(.5,.5),mu=new P;class Ic{constructor(e=new ur,t=new ur,n=new ur,i=new ur,s=new ur,o=new ur){this.planes=[e,t,n,i,s,o]}set(e,t,n,i,s,o){const a=this.planes;return a[0].copy(e),a[1].copy(t),a[2].copy(n),a[3].copy(i),a[4].copy(s),a[5].copy(o),this}copy(e){const t=this.planes;for(let n=0;n<6;n++)t[n].copy(e.planes[n]);return this}setFromProjectionMatrix(e,t=ii,n=!1){const i=this.planes,s=e.elements,o=s[0],a=s[1],l=s[2],c=s[3],u=s[4],h=s[5],d=s[6],f=s[7],p=s[8],g=s[9],m=s[10],_=s[11],x=s[12],y=s[13],b=s[14],M=s[15];if(i[0].setComponents(c-o,f-u,_-p,M-x).normalize(),i[1].setComponents(c+o,f+u,_+p,M+x).normalize(),i[2].setComponents(c+a,f+h,_+g,M+y).normalize(),i[3].setComponents(c-a,f-h,_-g,M-y).normalize(),n)i[4].setComponents(l,d,m,b).normalize(),i[5].setComponents(c-l,f-d,_-m,M-b).normalize();else if(i[4].setComponents(c-l,f-d,_-m,M-b).normalize(),t===ii)i[5].setComponents(c+l,f+d,_+m,M+b).normalize();else if(t===Tr)i[5].setComponents(l,d,m,b).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),Ys.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{const t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),Ys.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(Ys)}intersectsSprite(e){Ys.center.set(0,0,0);const t=kT.distanceTo(e.center);return Ys.radius=.7071067811865476+t,Ys.applyMatrix4(e.matrixWorld),this.intersectsSphere(Ys)}intersectsSphere(e){const t=this.planes,n=e.center,i=-e.radius;for(let s=0;s<6;s++)if(t[s].distanceToPoint(n)<i)return!1;return!0}intersectsBox(e){const t=this.planes;for(let n=0;n<6;n++){const i=t[n];if(mu.x=i.normal.x>0?e.max.x:e.min.x,mu.y=i.normal.y>0?e.max.y:e.min.y,mu.z=i.normal.z>0?e.max.z:e.min.z,i.distanceToPoint(mu)<0)return!1}return!0}containsPoint(e){const t=this.planes;for(let n=0;n<6;n++)if(t[n].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}const Ji=new pt,er=new Ic;class _m{constructor(){this.coordinateSystem=ii}intersectsObject(e,t){if(!t.isArrayCamera||t.cameras.length===0)return!1;for(let n=0;n<t.cameras.length;n++){const i=t.cameras[n];if(Ji.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),er.setFromProjectionMatrix(Ji,i.coordinateSystem,i.reversedDepth),er.intersectsObject(e))return!0}return!1}intersectsSprite(e,t){if(!t||!t.cameras||t.cameras.length===0)return!1;for(let n=0;n<t.cameras.length;n++){const i=t.cameras[n];if(Ji.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),er.setFromProjectionMatrix(Ji,i.coordinateSystem,i.reversedDepth),er.intersectsSprite(e))return!0}return!1}intersectsSphere(e,t){if(!t||!t.cameras||t.cameras.length===0)return!1;for(let n=0;n<t.cameras.length;n++){const i=t.cameras[n];if(Ji.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),er.setFromProjectionMatrix(Ji,i.coordinateSystem,i.reversedDepth),er.intersectsSphere(e))return!0}return!1}intersectsBox(e,t){if(!t||!t.cameras||t.cameras.length===0)return!1;for(let n=0;n<t.cameras.length;n++){const i=t.cameras[n];if(Ji.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),er.setFromProjectionMatrix(Ji,i.coordinateSystem,i.reversedDepth),er.intersectsBox(e))return!0}return!1}containsPoint(e,t){if(!t||!t.cameras||t.cameras.length===0)return!1;for(let n=0;n<t.cameras.length;n++){const i=t.cameras[n];if(Ji.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),er.setFromProjectionMatrix(Ji,i.coordinateSystem,i.reversedDepth),er.containsPoint(e))return!0}return!1}clone(){return new _m}}class Oh extends Yn{constructor(e){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new We(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.fog=e.fog,this}}const xh=new P,yh=new P,kg=new pt,El=new Bh,gu=new Fc,Pd=new P,Gg=new P;class GT extends pn{constructor(e=new An,t=new Oh){super(),this.isLine=!0,this.type="Line",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}computeLineDistances(){const e=this.geometry;if(e.index===null){const t=e.attributes.position,n=[0];for(let i=1,s=t.count;i<s;i++)xh.fromBufferAttribute(t,i-1),yh.fromBufferAttribute(t,i),n[i]=n[i-1],n[i]+=xh.distanceTo(yh);e.setAttribute("lineDistance",new sn(n,1))}else ae("Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(e,t){const n=this.geometry,i=this.matrixWorld,s=e.params.Line.threshold,o=n.drawRange;if(n.boundingSphere===null&&n.computeBoundingSphere(),gu.copy(n.boundingSphere),gu.applyMatrix4(i),gu.radius+=s,e.ray.intersectsSphere(gu)===!1)return;kg.copy(i).invert(),El.copy(e.ray).applyMatrix4(kg);const a=s/((this.scale.x+this.scale.y+this.scale.z)/3),l=a*a,c=this.isLineSegments?2:1,u=n.index,d=n.attributes.position;if(u!==null){const f=Math.max(0,o.start),p=Math.min(u.count,o.start+o.count);for(let g=f,m=p-1;g<m;g+=c){const _=u.getX(g),x=u.getX(g+1),y=_u(this,e,El,l,_,x,g);y&&t.push(y)}if(this.isLineLoop){const g=u.getX(p-1),m=u.getX(f),_=_u(this,e,El,l,g,m,p-1);_&&t.push(_)}}else{const f=Math.max(0,o.start),p=Math.min(d.count,o.start+o.count);for(let g=f,m=p-1;g<m;g+=c){const _=_u(this,e,El,l,g,g+1,g);_&&t.push(_)}if(this.isLineLoop){const g=_u(this,e,El,l,p-1,f,p-1);g&&t.push(g)}}}updateMorphTargets(){const t=this.geometry.morphAttributes,n=Object.keys(t);if(n.length>0){const i=t[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=i.length;s<o;s++){const a=i[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}}function _u(r,e,t,n,i,s,o){const a=r.geometry.attributes.position;if(xh.fromBufferAttribute(a,i),yh.fromBufferAttribute(a,s),t.distanceSqToSegment(xh,yh,Pd,Gg)>n)return;Pd.applyMatrix4(r.matrixWorld);const c=e.ray.origin.distanceTo(Pd);if(!(c<e.near||c>e.far))return{distance:c,point:Gg.clone().applyMatrix4(r.matrixWorld),index:o,face:null,faceIndex:null,barycoord:null,object:r}}class VT extends Yn{constructor(e){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new We(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.size=e.size,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}class ny extends fn{constructor(e,t){super({width:e,height:t}),this.isFramebufferTexture=!0,this.magFilter=Mt,this.minFilter=Mt,this.generateMipmaps=!1,this.needsUpdate=!0}}class sl extends fn{constructor(e=[],t=Ki,n,i,s,o,a,l,c,u){super(e,t,n,i,s,o,a,l,c,u),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}}class zT extends fn{constructor(e,t,n,i,s,o,a,l,c){super(e,t,n,i,s,o,a,l,c),this.isCanvasTexture=!0,this.needsUpdate=!0}}class jn extends fn{constructor(e,t,n=Ct,i,s,o,a=Mt,l=Mt,c,u=Dn,h=1){if(u!==Dn&&u!==qn)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const d={width:e,height:t,depth:h};super(d,i,s,o,a,l,u,n,c),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new am(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){const t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}}class iy extends jn{constructor(e,t=Ct,n=Ki,i,s,o=Mt,a=Mt,l,c=Dn){const u={width:e,height:e,depth:1},h=[u,u,u,u,u,u];super(e,e,t,n,i,s,o,a,l,c),this.image=h,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(e){this.image=e}}class ry extends fn{constructor(e=null){super(),this.sourceTexture=e,this.isExternalTexture=!0}copy(e){return super.copy(e),this.sourceTexture=e.sourceTexture,this}}class Co extends An{constructor(e=1,t=1,n=1,i=1,s=1,o=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:n,widthSegments:i,heightSegments:s,depthSegments:o};const a=this;i=Math.floor(i),s=Math.floor(s),o=Math.floor(o);const l=[],c=[],u=[],h=[];let d=0,f=0;p("z","y","x",-1,-1,n,t,e,o,s,0),p("z","y","x",1,-1,n,t,-e,o,s,1),p("x","z","y",1,1,e,n,t,i,o,2),p("x","z","y",1,-1,e,n,-t,i,o,3),p("x","y","z",1,-1,e,t,n,i,s,4),p("x","y","z",-1,-1,e,t,-n,i,s,5),this.setIndex(l),this.setAttribute("position",new sn(c,3)),this.setAttribute("normal",new sn(u,3)),this.setAttribute("uv",new sn(h,2));function p(g,m,_,x,y,b,M,S,E,v,w){const N=b/E,C=M/v,F=b/2,V=M/2,z=S/2,U=E+1,B=v+1;let D=0,X=0;const K=new P;for(let fe=0;fe<B;fe++){const Z=fe*C-V;for(let oe=0;oe<U;oe++){const Ee=oe*N-F;K[g]=Ee*x,K[m]=Z*y,K[_]=z,c.push(K.x,K.y,K.z),K[g]=0,K[m]=0,K[_]=S>0?1:-1,u.push(K.x,K.y,K.z),h.push(oe/E),h.push(1-fe/v),D+=1}}for(let fe=0;fe<v;fe++)for(let Z=0;Z<E;Z++){const oe=d+Z+U*fe,Ee=d+Z+U*(fe+1),ze=d+(Z+1)+U*(fe+1),$=d+(Z+1)+U*fe;l.push(oe,Ee,$),l.push(Ee,ze,$),X+=6}a.addGroup(f,X,w),f+=X,d+=D}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Co(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}}class Bc extends An{constructor(e=1,t=1,n=1,i=32,s=1,o=!1,a=0,l=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:e,radiusBottom:t,height:n,radialSegments:i,heightSegments:s,openEnded:o,thetaStart:a,thetaLength:l};const c=this;i=Math.floor(i),s=Math.floor(s);const u=[],h=[],d=[],f=[];let p=0;const g=[],m=n/2;let _=0;x(),o===!1&&(e>0&&y(!0),t>0&&y(!1)),this.setIndex(u),this.setAttribute("position",new sn(h,3)),this.setAttribute("normal",new sn(d,3)),this.setAttribute("uv",new sn(f,2));function x(){const b=new P,M=new P;let S=0;const E=(t-e)/n;for(let v=0;v<=s;v++){const w=[],N=v/s,C=N*(t-e)+e;for(let F=0;F<=i;F++){const V=F/i,z=V*l+a,U=Math.sin(z),B=Math.cos(z);M.x=C*U,M.y=-N*n+m,M.z=C*B,h.push(M.x,M.y,M.z),b.set(U,E,B).normalize(),d.push(b.x,b.y,b.z),f.push(V,1-N),w.push(p++)}g.push(w)}for(let v=0;v<i;v++)for(let w=0;w<s;w++){const N=g[w][v],C=g[w+1][v],F=g[w+1][v+1],V=g[w][v+1];(e>0||w!==0)&&(u.push(N,C,V),S+=3),(t>0||w!==s-1)&&(u.push(C,F,V),S+=3)}c.addGroup(_,S,0),_+=S}function y(b){const M=p,S=new pe,E=new P;let v=0;const w=b===!0?e:t,N=b===!0?1:-1;for(let F=1;F<=i;F++)h.push(0,m*N,0),d.push(0,N,0),f.push(.5,.5),p++;const C=p;for(let F=0;F<=i;F++){const z=F/i*l+a,U=Math.cos(z),B=Math.sin(z);E.x=w*B,E.y=m*N,E.z=w*U,h.push(E.x,E.y,E.z),d.push(0,N,0),S.x=U*.5+.5,S.y=B*.5*N+.5,f.push(S.x,S.y),p++}for(let F=0;F<i;F++){const V=M+F,z=C+F;b===!0?u.push(z,z+1,V):u.push(z+1,z,V),v+=3}c.addGroup(_,v,b===!0?1:2),_+=v}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Bc(e.radiusTop,e.radiusBottom,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class xm extends Bc{constructor(e=1,t=1,n=32,i=1,s=!1,o=0,a=Math.PI*2){super(0,e,t,n,i,s,o,a),this.type="ConeGeometry",this.parameters={radius:e,height:t,radialSegments:n,heightSegments:i,openEnded:s,thetaStart:o,thetaLength:a}}static fromJSON(e){return new xm(e.radius,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class Jr{constructor(){this.type="Curve",this.arcLengthDivisions=200,this.needsUpdate=!1,this.cacheArcLengths=null}getPoint(){ae("Curve: .getPoint() not implemented.")}getPointAt(e,t){const n=this.getUtoTmapping(e);return this.getPoint(n,t)}getPoints(e=5){const t=[];for(let n=0;n<=e;n++)t.push(this.getPoint(n/e));return t}getSpacedPoints(e=5){const t=[];for(let n=0;n<=e;n++)t.push(this.getPointAt(n/e));return t}getLength(){const e=this.getLengths();return e[e.length-1]}getLengths(e=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const t=[];let n,i=this.getPoint(0),s=0;t.push(0);for(let o=1;o<=e;o++)n=this.getPoint(o/e),s+=n.distanceTo(i),t.push(s),i=n;return this.cacheArcLengths=t,t}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(e,t=null){const n=this.getLengths();let i=0;const s=n.length;let o;t?o=t:o=e*n[s-1];let a=0,l=s-1,c;for(;a<=l;)if(i=Math.floor(a+(l-a)/2),c=n[i]-o,c<0)a=i+1;else if(c>0)l=i-1;else{l=i;break}if(i=l,n[i]===o)return i/(s-1);const u=n[i],d=n[i+1]-u,f=(o-u)/d;return(i+f)/(s-1)}getTangent(e,t){let i=e-1e-4,s=e+1e-4;i<0&&(i=0),s>1&&(s=1);const o=this.getPoint(i),a=this.getPoint(s),l=t||(o.isVector2?new pe:new P);return l.copy(a).sub(o).normalize(),l}getTangentAt(e,t){const n=this.getUtoTmapping(e);return this.getTangent(n,t)}computeFrenetFrames(e,t=!1){const n=new P,i=[],s=[],o=[],a=new P,l=new pt;for(let f=0;f<=e;f++){const p=f/e;i[f]=this.getTangentAt(p,new P)}s[0]=new P,o[0]=new P;let c=Number.MAX_VALUE;const u=Math.abs(i[0].x),h=Math.abs(i[0].y),d=Math.abs(i[0].z);u<=c&&(c=u,n.set(1,0,0)),h<=c&&(c=h,n.set(0,1,0)),d<=c&&n.set(0,0,1),a.crossVectors(i[0],n).normalize(),s[0].crossVectors(i[0],a),o[0].crossVectors(i[0],s[0]);for(let f=1;f<=e;f++){if(s[f]=s[f-1].clone(),o[f]=o[f-1].clone(),a.crossVectors(i[f-1],i[f]),a.length()>Number.EPSILON){a.normalize();const p=Math.acos(ct(i[f-1].dot(i[f]),-1,1));s[f].applyMatrix4(l.makeRotationAxis(a,p))}o[f].crossVectors(i[f],s[f])}if(t===!0){let f=Math.acos(ct(s[0].dot(s[e]),-1,1));f/=e,i[0].dot(a.crossVectors(s[0],s[e]))>0&&(f=-f);for(let p=1;p<=e;p++)s[p].applyMatrix4(l.makeRotationAxis(i[p],f*p)),o[p].crossVectors(i[p],s[p])}return{tangents:i,normals:s,binormals:o}}clone(){return new this.constructor().copy(this)}copy(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}toJSON(){const e={metadata:{version:4.7,type:"Curve",generator:"Curve.toJSON"}};return e.arcLengthDivisions=this.arcLengthDivisions,e.type=this.type,e}fromJSON(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}}class sy extends Jr{constructor(e=0,t=0,n=1,i=1,s=0,o=Math.PI*2,a=!1,l=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=e,this.aY=t,this.xRadius=n,this.yRadius=i,this.aStartAngle=s,this.aEndAngle=o,this.aClockwise=a,this.aRotation=l}getPoint(e,t=new pe){const n=t,i=Math.PI*2;let s=this.aEndAngle-this.aStartAngle;const o=Math.abs(s)<Number.EPSILON;for(;s<0;)s+=i;for(;s>i;)s-=i;s<Number.EPSILON&&(o?s=0:s=i),this.aClockwise===!0&&!o&&(s===i?s=-i:s=s-i);const a=this.aStartAngle+e*s;let l=this.aX+this.xRadius*Math.cos(a),c=this.aY+this.yRadius*Math.sin(a);if(this.aRotation!==0){const u=Math.cos(this.aRotation),h=Math.sin(this.aRotation),d=l-this.aX,f=c-this.aY;l=d*u-f*h+this.aX,c=d*h+f*u+this.aY}return n.set(l,c)}copy(e){return super.copy(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}toJSON(){const e=super.toJSON();return e.aX=this.aX,e.aY=this.aY,e.xRadius=this.xRadius,e.yRadius=this.yRadius,e.aStartAngle=this.aStartAngle,e.aEndAngle=this.aEndAngle,e.aClockwise=this.aClockwise,e.aRotation=this.aRotation,e}fromJSON(e){return super.fromJSON(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}}class HT extends sy{constructor(e,t,n,i,s,o){super(e,t,n,n,i,s,o),this.isArcCurve=!0,this.type="ArcCurve"}}function ym(){let r=0,e=0,t=0,n=0;function i(s,o,a,l){r=s,e=a,t=-3*s+3*o-2*a-l,n=2*s-2*o+a+l}return{initCatmullRom:function(s,o,a,l,c){i(o,a,c*(a-s),c*(l-o))},initNonuniformCatmullRom:function(s,o,a,l,c,u,h){let d=(o-s)/c-(a-s)/(c+u)+(a-o)/u,f=(a-o)/u-(l-o)/(u+h)+(l-a)/h;d*=u,f*=u,i(o,a,d,f)},calc:function(s){const o=s*s,a=o*s;return r+e*s+t*o+n*a}}}const Vg=new P,zg=new P,Dd=new ym,Ld=new ym,Ud=new ym;class WT extends Jr{constructor(e=[],t=!1,n="centripetal",i=.5){super(),this.isCatmullRomCurve3=!0,this.type="CatmullRomCurve3",this.points=e,this.closed=t,this.curveType=n,this.tension=i}getPoint(e,t=new P){const n=t,i=this.points,s=i.length,o=(s-(this.closed?0:1))*e;let a=Math.floor(o),l=o-a;this.closed?a+=a>0?0:(Math.floor(Math.abs(a)/s)+1)*s:l===0&&a===s-1&&(a=s-2,l=1);let c,u;this.closed||a>0?c=i[(a-1)%s]:(zg.subVectors(i[0],i[1]).add(i[0]),c=zg);const h=i[a%s],d=i[(a+1)%s];if(this.closed||a+2<s?u=i[(a+2)%s]:(Vg.subVectors(i[s-1],i[s-2]).add(i[s-1]),u=Vg),this.curveType==="centripetal"||this.curveType==="chordal"){const f=this.curveType==="chordal"?.5:.25;let p=Math.pow(c.distanceToSquared(h),f),g=Math.pow(h.distanceToSquared(d),f),m=Math.pow(d.distanceToSquared(u),f);g<1e-4&&(g=1),p<1e-4&&(p=g),m<1e-4&&(m=g),Dd.initNonuniformCatmullRom(c.x,h.x,d.x,u.x,p,g,m),Ld.initNonuniformCatmullRom(c.y,h.y,d.y,u.y,p,g,m),Ud.initNonuniformCatmullRom(c.z,h.z,d.z,u.z,p,g,m)}else this.curveType==="catmullrom"&&(Dd.initCatmullRom(c.x,h.x,d.x,u.x,this.tension),Ld.initCatmullRom(c.y,h.y,d.y,u.y,this.tension),Ud.initCatmullRom(c.z,h.z,d.z,u.z,this.tension));return n.set(Dd.calc(l),Ld.calc(l),Ud.calc(l)),n}copy(e){super.copy(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){const i=e.points[t];this.points.push(i.clone())}return this.closed=e.closed,this.curveType=e.curveType,this.tension=e.tension,this}toJSON(){const e=super.toJSON();e.points=[];for(let t=0,n=this.points.length;t<n;t++){const i=this.points[t];e.points.push(i.toArray())}return e.closed=this.closed,e.curveType=this.curveType,e.tension=this.tension,e}fromJSON(e){super.fromJSON(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){const i=e.points[t];this.points.push(new P().fromArray(i))}return this.closed=e.closed,this.curveType=e.curveType,this.tension=e.tension,this}}function Hg(r,e,t,n,i){const s=(n-e)*.5,o=(i-t)*.5,a=r*r,l=r*a;return(2*t-2*n+s+o)*l+(-3*t+3*n-2*s-o)*a+s*r+t}function $T(r,e){const t=1-r;return t*t*e}function XT(r,e){return 2*(1-r)*r*e}function qT(r,e){return r*r*e}function Yl(r,e,t,n){return $T(r,e)+XT(r,t)+qT(r,n)}function jT(r,e){const t=1-r;return t*t*t*e}function YT(r,e){const t=1-r;return 3*t*t*r*e}function KT(r,e){return 3*(1-r)*r*r*e}function ZT(r,e){return r*r*r*e}function Kl(r,e,t,n,i){return jT(r,e)+YT(r,t)+KT(r,n)+ZT(r,i)}class QT extends Jr{constructor(e=new pe,t=new pe,n=new pe,i=new pe){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=e,this.v1=t,this.v2=n,this.v3=i}getPoint(e,t=new pe){const n=t,i=this.v0,s=this.v1,o=this.v2,a=this.v3;return n.set(Kl(e,i.x,s.x,o.x,a.x),Kl(e,i.y,s.y,o.y,a.y)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e.v3=this.v3.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this.v3.fromArray(e.v3),this}}class oy extends Jr{constructor(e=new P,t=new P,n=new P,i=new P){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=e,this.v1=t,this.v2=n,this.v3=i}getPoint(e,t=new P){const n=t,i=this.v0,s=this.v1,o=this.v2,a=this.v3;return n.set(Kl(e,i.x,s.x,o.x,a.x),Kl(e,i.y,s.y,o.y,a.y),Kl(e,i.z,s.z,o.z,a.z)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e.v3=this.v3.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this.v3.fromArray(e.v3),this}}class JT extends Jr{constructor(e=new pe,t=new pe){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=e,this.v2=t}getPoint(e,t=new pe){const n=t;return e===1?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(e).add(this.v1)),n}getPointAt(e,t){return this.getPoint(e,t)}getTangent(e,t=new pe){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t){return this.getTangent(e,t)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class eM extends Jr{constructor(e=new P,t=new P){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=e,this.v2=t}getPoint(e,t=new P){const n=t;return e===1?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(e).add(this.v1)),n}getPointAt(e,t){return this.getPoint(e,t)}getTangent(e,t=new P){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t){return this.getTangent(e,t)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class tM extends Jr{constructor(e=new pe,t=new pe,n=new pe){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=e,this.v1=t,this.v2=n}getPoint(e,t=new pe){const n=t,i=this.v0,s=this.v1,o=this.v2;return n.set(Yl(e,i.x,s.x,o.x),Yl(e,i.y,s.y,o.y)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class vm extends Jr{constructor(e=new P,t=new P,n=new P){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=e,this.v1=t,this.v2=n}getPoint(e,t=new P){const n=t,i=this.v0,s=this.v1,o=this.v2;return n.set(Yl(e,i.x,s.x,o.x),Yl(e,i.y,s.y,o.y),Yl(e,i.z,s.z,o.z)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class nM extends Jr{constructor(e=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=e}getPoint(e,t=new pe){const n=t,i=this.points,s=(i.length-1)*e,o=Math.floor(s),a=s-o,l=i[o===0?o:o-1],c=i[o],u=i[o>i.length-2?i.length-1:o+1],h=i[o>i.length-3?i.length-1:o+2];return n.set(Hg(a,l.x,c.x,u.x,h.x),Hg(a,l.y,c.y,u.y,h.y)),n}copy(e){super.copy(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){const i=e.points[t];this.points.push(i.clone())}return this}toJSON(){const e=super.toJSON();e.points=[];for(let t=0,n=this.points.length;t<n;t++){const i=this.points[t];e.points.push(i.toArray())}return e}fromJSON(e){super.fromJSON(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){const i=e.points[t];this.points.push(new pe().fromArray(i))}return this}}var iM=Object.freeze({__proto__:null,ArcCurve:HT,CatmullRomCurve3:WT,CubicBezierCurve:QT,CubicBezierCurve3:oy,EllipseCurve:sy,LineCurve:JT,LineCurve3:eM,QuadraticBezierCurve:tM,QuadraticBezierCurve3:vm,SplineCurve:nM});class Oc extends An{constructor(e=1,t=1,n=1,i=1){super(),this.type="PlaneGeometry",this.parameters={width:e,height:t,widthSegments:n,heightSegments:i};const s=e/2,o=t/2,a=Math.floor(n),l=Math.floor(i),c=a+1,u=l+1,h=e/a,d=t/l,f=[],p=[],g=[],m=[];for(let _=0;_<u;_++){const x=_*d-o;for(let y=0;y<c;y++){const b=y*h-s;p.push(b,-x,0),g.push(0,0,1),m.push(y/a),m.push(1-_/l)}}for(let _=0;_<l;_++)for(let x=0;x<a;x++){const y=x+c*_,b=x+c*(_+1),M=x+1+c*(_+1),S=x+1+c*_;f.push(y,b,S),f.push(b,M,S)}this.setIndex(f),this.setAttribute("position",new sn(p,3)),this.setAttribute("normal",new sn(g,3)),this.setAttribute("uv",new sn(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Oc(e.width,e.height,e.widthSegments,e.heightSegments)}}class kc extends An{constructor(e=1,t=32,n=16,i=0,s=Math.PI*2,o=0,a=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:e,widthSegments:t,heightSegments:n,phiStart:i,phiLength:s,thetaStart:o,thetaLength:a},t=Math.max(3,Math.floor(t)),n=Math.max(2,Math.floor(n));const l=Math.min(o+a,Math.PI);let c=0;const u=[],h=new P,d=new P,f=[],p=[],g=[],m=[];for(let _=0;_<=n;_++){const x=[],y=_/n;let b=0;_===0&&o===0?b=.5/t:_===n&&l===Math.PI&&(b=-.5/t);for(let M=0;M<=t;M++){const S=M/t;h.x=-e*Math.cos(i+S*s)*Math.sin(o+y*a),h.y=e*Math.cos(o+y*a),h.z=e*Math.sin(i+S*s)*Math.sin(o+y*a),p.push(h.x,h.y,h.z),d.copy(h).normalize(),g.push(d.x,d.y,d.z),m.push(S+b,1-y),x.push(c++)}u.push(x)}for(let _=0;_<n;_++)for(let x=0;x<t;x++){const y=u[_][x+1],b=u[_][x],M=u[_+1][x],S=u[_+1][x+1];(_!==0||o>0)&&f.push(y,b,S),(_!==n-1||l<Math.PI)&&f.push(b,M,S)}this.setIndex(f),this.setAttribute("position",new sn(p,3)),this.setAttribute("normal",new sn(g,3)),this.setAttribute("uv",new sn(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new kc(e.radius,e.widthSegments,e.heightSegments,e.phiStart,e.phiLength,e.thetaStart,e.thetaLength)}}class bm extends An{constructor(e=new vm(new P(-1,-1,0),new P(-1,1,0),new P(1,1,0)),t=64,n=1,i=8,s=!1){super(),this.type="TubeGeometry",this.parameters={path:e,tubularSegments:t,radius:n,radialSegments:i,closed:s};const o=e.computeFrenetFrames(t,s);this.tangents=o.tangents,this.normals=o.normals,this.binormals=o.binormals;const a=new P,l=new P,c=new pe;let u=new P;const h=[],d=[],f=[],p=[];g(),this.setIndex(p),this.setAttribute("position",new sn(h,3)),this.setAttribute("normal",new sn(d,3)),this.setAttribute("uv",new sn(f,2));function g(){for(let y=0;y<t;y++)m(y);m(s===!1?t:0),x(),_()}function m(y){u=e.getPointAt(y/t,u);const b=o.normals[y],M=o.binormals[y];for(let S=0;S<=i;S++){const E=S/i*Math.PI*2,v=Math.sin(E),w=-Math.cos(E);l.x=w*b.x+v*M.x,l.y=w*b.y+v*M.y,l.z=w*b.z+v*M.z,l.normalize(),d.push(l.x,l.y,l.z),a.x=u.x+n*l.x,a.y=u.y+n*l.y,a.z=u.z+n*l.z,h.push(a.x,a.y,a.z)}}function _(){for(let y=1;y<=t;y++)for(let b=1;b<=i;b++){const M=(i+1)*(y-1)+(b-1),S=(i+1)*y+(b-1),E=(i+1)*y+b,v=(i+1)*(y-1)+b;p.push(M,S,v),p.push(S,E,v)}}function x(){for(let y=0;y<=t;y++)for(let b=0;b<=i;b++)c.x=y/t,c.y=b/i,f.push(c.x,c.y)}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){const e=super.toJSON();return e.path=this.parameters.path.toJSON(),e}static fromJSON(e){return new bm(new iM[e.path.type]().fromJSON(e.path),e.tubularSegments,e.radius,e.radialSegments,e.closed)}}class rM extends Yn{constructor(e){super(),this.isShadowMaterial=!0,this.type="ShadowMaterial",this.color=new We(0),this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.fog=e.fog,this}}function Ka(r){const e={};for(const t in r){e[t]={};for(const n in r[t]){const i=r[t][n];if(Wg(i))i.isRenderTargetTexture?(ae("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),e[t][n]=null):e[t][n]=i.clone();else if(Array.isArray(i))if(Wg(i[0])){const s=[];for(let o=0,a=i.length;o<a;o++)s[o]=i[o].clone();e[t][n]=s}else e[t][n]=i.slice();else e[t][n]=i}}return e}function Qn(r){const e={};for(let t=0;t<r.length;t++){const n=Ka(r[t]);for(const i in n)e[i]=n[i]}return e}function Wg(r){return r&&(r.isColor||r.isMatrix3||r.isMatrix4||r.isVector2||r.isVector3||r.isVector4||r.isTexture||r.isQuaternion)}function sM(r){const e=[];for(let t=0;t<r.length;t++)e.push(r[t].clone());return e}function ay(r){const e=r.getRenderTarget();return e===null?r.outputColorSpace:e.isXRRenderTarget===!0?e.texture.colorSpace:Ye.workingColorSpace}const ly={clone:Ka,merge:Qn};var oM=`void main() {
5
+ */const Mo="184",Un={ROTATE:0,DOLLY:1,PAN:2},$r={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},O0=0,Jf=1,k0=2,DS=0,fa=1,G0=2,_r=3,ri=0,Lt=1,Nn=2,Pn=0,ti=1,_s=2,xs=3,ys=4,co=5,V0=6,Xn=100,Bp=101,Op=102,z0=103,H0=104,Gr=200,kp=201,Gp=202,Vp=203,oc=204,ac=205,zp=206,Hp=207,Wp=208,$p=209,Xp=210,LS=211,US=212,FS=213,IS=214,lc=0,cc=1,uc=2,Ds=3,hc=4,dc=5,fc=6,pc=7,Nc=0,W0=1,$0=2,Fn=0,qp=1,jp=2,Yp=3,Kp=4,X0=5,Zp=6,Qp=7,Jp=300,Ki=301,Sr=302,pa=303,ma=304,mo=306,go=1e3,ci=1001,_o=1002,Mt=1003,em=1004,Xr=1005,Nt=1006,ga=1007,ui=1008,Xt=1009,Ts=1010,Ms=1011,Li=1012,Sn=1013,Ct=1014,Qt=1015,tn=1016,Pc=1017,Dc=1018,di=1020,Lc=35902,Uc=35899,Fh=1021,nl=1022,ln=1023,Dn=1026,qn=1027,il=1028,Eo=1029,In=1030,Ao=1031,q0=1032,rl=1033,Es=33776,As=33777,ws=33778,Rs=33779,mc=35840,gc=35841,_c=35842,xc=35843,Ma=36196,Ea=37492,Aa=37496,wa=37488,Ra=37489,Ls=37490,Ca=37491,Na=37808,Pa=37809,Da=37810,La=37811,Ua=37812,Fa=37813,Ia=37814,Ba=37815,Oa=37816,ka=37817,Ga=37818,Va=37819,za=37820,Ha=37821,Wa=36492,ep=36494,tp=36495,$a=36283,Xa=36284,Us=36285,qa=36286,BS=3200,ji=0,j0=1,ai="",ei="srgb",yc="srgb-linear",ja="linear",Pe="srgb",ld="",Y0="rg",OS="ga",kS=0,eo=7680,GS=7681,VS=7682,zS=7683,HS=34055,WS=34056,$S=5386,XS=512,qS=513,jS=514,YS=515,KS=516,ZS=517,QS=518,np=519,tm=512,Ih=513,nm=514,Os=515,vc=516,im=517,Zr=518,rm=519,Ya=35044,mh=35048,vg="300 es",ii=2e3,Tr=2001,xr={COMPUTE:"compute",RENDER:"render"},wo={TEXTURE_COMPARE:"depthTextureCompare"};function JS(r){for(let e=r.length-1;e>=0;--e)if(r[e]>=65535)return!0;return!1}function gh(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}function bc(r){return document.createElementNS("http://www.w3.org/1999/xhtml",r)}function K0(){const r=bc("canvas");return r.style.display="block",r}const bg={};function Sc(...r){const e="THREE."+r.shift();console.log(e,...r)}function Z0(r){const e=r[0];if(typeof e=="string"&&e.startsWith("TSL:")){const t=r[1];t&&t.isStackTrace?r[0]+=" "+t.getLocation():r[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return r}function ae(...r){r=Z0(r);const e="THREE."+r.shift();{const t=r[0];t&&t.isStackTrace?console.warn(t.getError(e)):console.warn(e,...r)}}function ce(...r){r=Z0(r);const e="THREE."+r.shift();{const t=r[0];t&&t.isStackTrace?console.error(t.getError(e)):console.error(e,...r)}}function Kt(...r){const e=r.join(" ");e in bg||(bg[e]=!0,ae(...r))}function Q0(){return typeof self<"u"&&typeof self.scheduler<"u"&&typeof self.scheduler.yield<"u"?self.scheduler.yield():new Promise(r=>{requestAnimationFrame(r)})}function eT(r,e,t){return new Promise(function(n,i){function s(){switch(r.clientWaitSync(e,r.SYNC_FLUSH_COMMANDS_BIT,0)){case r.WAIT_FAILED:i();break;case r.TIMEOUT_EXPIRED:setTimeout(s,t);break;default:n()}}setTimeout(s,t)})}const sm={[lc]:cc,[uc]:fc,[hc]:pc,[Ds]:dc,[cc]:lc,[fc]:uc,[pc]:hc,[dc]:Ds};class Vi{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});const n=this._listeners;n[e]===void 0&&(n[e]=[]),n[e].indexOf(t)===-1&&n[e].push(t)}hasEventListener(e,t){const n=this._listeners;return n===void 0?!1:n[e]!==void 0&&n[e].indexOf(t)!==-1}removeEventListener(e,t){const n=this._listeners;if(n===void 0)return;const i=n[e];if(i!==void 0){const s=i.indexOf(t);s!==-1&&i.splice(s,1)}}dispatchEvent(e){const t=this._listeners;if(t===void 0)return;const n=t[e.type];if(n!==void 0){e.target=this;const i=n.slice(0);for(let s=0,o=i.length;s<o;s++)i[s].call(this,e);e.target=null}}}const Vn=["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 Sg=1234567;const ql=Math.PI/180,xo=180/Math.PI;function qr(){const r=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,n=Math.random()*4294967295|0;return(Vn[r&255]+Vn[r>>8&255]+Vn[r>>16&255]+Vn[r>>24&255]+"-"+Vn[e&255]+Vn[e>>8&255]+"-"+Vn[e>>16&15|64]+Vn[e>>24&255]+"-"+Vn[t&63|128]+Vn[t>>8&255]+"-"+Vn[t>>16&255]+Vn[t>>24&255]+Vn[n&255]+Vn[n>>8&255]+Vn[n>>16&255]+Vn[n>>24&255]).toLowerCase()}function ct(r,e,t){return Math.max(e,Math.min(t,r))}function om(r,e){return(r%e+e)%e}function tT(r,e,t,n,i){return n+(r-e)*(i-n)/(t-e)}function nT(r,e,t){return r!==e?(t-r)/(e-r):0}function jl(r,e,t){return(1-t)*r+t*e}function iT(r,e,t,n){return jl(r,e,1-Math.exp(-t*n))}function rT(r,e=1){return e-Math.abs(om(r,e*2)-e)}function sT(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*(3-2*r))}function oT(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*r*(r*(r*6-15)+10))}function aT(r,e){return r+Math.floor(Math.random()*(e-r+1))}function lT(r,e){return r+Math.random()*(e-r)}function cT(r){return r*(.5-Math.random())}function uT(r){r!==void 0&&(Sg=r);let e=Sg+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function hT(r){return r*ql}function dT(r){return r*xo}function fT(r){return(r&r-1)===0&&r!==0}function pT(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function mT(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function gT(r,e,t,n,i){const s=Math.cos,o=Math.sin,a=s(t/2),l=o(t/2),c=s((e+n)/2),u=o((e+n)/2),h=s((e-n)/2),d=o((e-n)/2),f=s((n-e)/2),p=o((n-e)/2);switch(i){case"XYX":r.set(a*u,l*h,l*d,a*c);break;case"YZY":r.set(l*d,a*u,l*h,a*c);break;case"ZXZ":r.set(l*h,l*d,a*u,a*c);break;case"XZX":r.set(a*u,l*p,l*f,a*c);break;case"YXY":r.set(l*f,a*u,l*p,a*c);break;case"ZYZ":r.set(l*p,l*f,a*u,a*c);break;default:ae("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function ni(r,e){switch(e.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 lt(r,e){switch(e.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 _h={DEG2RAD:ql,RAD2DEG:xo,generateUUID:qr,clamp:ct,euclideanModulo:om,mapLinear:tT,inverseLerp:nT,lerp:jl,damp:iT,pingpong:rT,smoothstep:sT,smootherstep:oT,randInt:aT,randFloat:lT,randFloatSpread:cT,seededRandom:uT,degToRad:hT,radToDeg:dT,isPowerOfTwo:fT,ceilPowerOfTwo:pT,floorPowerOfTwo:mT,setQuaternionFromProperEuler:gT,normalize:lt,denormalize:ni},sg=class sg{constructor(e=0,t=0){this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,n=this.y,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6],this.y=i[1]*t+i[4]*n+i[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=ct(this.x,e.x,t.x),this.y=ct(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=ct(this.x,e,t),this.y=ct(this.y,e,t),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(ct(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const n=this.dot(e)/t;return Math.acos(ct(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y;return t*t+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const n=Math.cos(t),i=Math.sin(t),s=this.x-e.x,o=this.y-e.y;return this.x=s*n-o*i+e.x,this.y=s*i+o*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}};sg.prototype.isVector2=!0;let pe=sg;class Oi{constructor(e=0,t=0,n=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=i}static slerpFlat(e,t,n,i,s,o,a){let l=n[i+0],c=n[i+1],u=n[i+2],h=n[i+3],d=s[o+0],f=s[o+1],p=s[o+2],g=s[o+3];if(h!==g||l!==d||c!==f||u!==p){let m=l*d+c*f+u*p+h*g;m<0&&(d=-d,f=-f,p=-p,g=-g,m=-m);let _=1-a;if(m<.9995){const x=Math.acos(m),y=Math.sin(x);_=Math.sin(_*x)/y,a=Math.sin(a*x)/y,l=l*_+d*a,c=c*_+f*a,u=u*_+p*a,h=h*_+g*a}else{l=l*_+d*a,c=c*_+f*a,u=u*_+p*a,h=h*_+g*a;const x=1/Math.sqrt(l*l+c*c+u*u+h*h);l*=x,c*=x,u*=x,h*=x}}e[t]=l,e[t+1]=c,e[t+2]=u,e[t+3]=h}static multiplyQuaternionsFlat(e,t,n,i,s,o){const a=n[i],l=n[i+1],c=n[i+2],u=n[i+3],h=s[o],d=s[o+1],f=s[o+2],p=s[o+3];return e[t]=a*p+u*h+l*f-c*d,e[t+1]=l*p+u*d+c*h-a*f,e[t+2]=c*p+u*f+a*d-l*h,e[t+3]=u*p-a*h-l*d-c*f,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,n,i){return this._x=e,this._y=t,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const n=e._x,i=e._y,s=e._z,o=e._order,a=Math.cos,l=Math.sin,c=a(n/2),u=a(i/2),h=a(s/2),d=l(n/2),f=l(i/2),p=l(s/2);switch(o){case"XYZ":this._x=d*u*h+c*f*p,this._y=c*f*h-d*u*p,this._z=c*u*p+d*f*h,this._w=c*u*h-d*f*p;break;case"YXZ":this._x=d*u*h+c*f*p,this._y=c*f*h-d*u*p,this._z=c*u*p-d*f*h,this._w=c*u*h+d*f*p;break;case"ZXY":this._x=d*u*h-c*f*p,this._y=c*f*h+d*u*p,this._z=c*u*p+d*f*h,this._w=c*u*h-d*f*p;break;case"ZYX":this._x=d*u*h-c*f*p,this._y=c*f*h+d*u*p,this._z=c*u*p-d*f*h,this._w=c*u*h+d*f*p;break;case"YZX":this._x=d*u*h+c*f*p,this._y=c*f*h+d*u*p,this._z=c*u*p-d*f*h,this._w=c*u*h-d*f*p;break;case"XZY":this._x=d*u*h-c*f*p,this._y=c*f*h-d*u*p,this._z=c*u*p+d*f*h,this._w=c*u*h+d*f*p;break;default:ae("Quaternion: .setFromEuler() encountered an unknown order: "+o)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const n=t/2,i=Math.sin(n);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,n=t[0],i=t[4],s=t[8],o=t[1],a=t[5],l=t[9],c=t[2],u=t[6],h=t[10],d=n+a+h;if(d>0){const f=.5/Math.sqrt(d+1);this._w=.25/f,this._x=(u-l)*f,this._y=(s-c)*f,this._z=(o-i)*f}else if(n>a&&n>h){const f=2*Math.sqrt(1+n-a-h);this._w=(u-l)/f,this._x=.25*f,this._y=(i+o)/f,this._z=(s+c)/f}else if(a>h){const f=2*Math.sqrt(1+a-n-h);this._w=(s-c)/f,this._x=(i+o)/f,this._y=.25*f,this._z=(l+u)/f}else{const f=2*Math.sqrt(1+h-n-a);this._w=(o-i)/f,this._x=(s+c)/f,this._y=(l+u)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<1e-8?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(ct(this.dot(e),-1,1)))}rotateTowards(e,t){const n=this.angleTo(e);if(n===0)return this;const i=Math.min(1,t/n);return this.slerp(e,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const n=e._x,i=e._y,s=e._z,o=e._w,a=t._x,l=t._y,c=t._z,u=t._w;return this._x=n*u+o*a+i*c-s*l,this._y=i*u+o*l+s*a-n*c,this._z=s*u+o*c+n*l-i*a,this._w=o*u-n*a-i*l-s*c,this._onChangeCallback(),this}slerp(e,t){let n=e._x,i=e._y,s=e._z,o=e._w,a=this.dot(e);a<0&&(n=-n,i=-i,s=-s,o=-o,a=-a);let l=1-t;if(a<.9995){const c=Math.acos(a),u=Math.sin(c);l=Math.sin(l*c)/u,t=Math.sin(t*c)/u,this._x=this._x*l+n*t,this._y=this._y*l+i*t,this._z=this._z*l+s*t,this._w=this._w*l+o*t,this._onChangeCallback()}else this._x=this._x*l+n*t,this._y=this._y*l+i*t,this._z=this._z*l+s*t,this._w=this._w*l+o*t,this.normalize();return this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),s=Math.sqrt(n);return this.set(i*Math.sin(e),i*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}const og=class og{constructor(e=0,t=0,n=0){this.x=e,this.y=t,this.z=n}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Tg.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Tg.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[3]*n+s[6]*i,this.y=s[1]*t+s[4]*n+s[7]*i,this.z=s[2]*t+s[5]*n+s[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,n=this.y,i=this.z,s=e.elements,o=1/(s[3]*t+s[7]*n+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*n+s[8]*i+s[12])*o,this.y=(s[1]*t+s[5]*n+s[9]*i+s[13])*o,this.z=(s[2]*t+s[6]*n+s[10]*i+s[14])*o,this}applyQuaternion(e){const t=this.x,n=this.y,i=this.z,s=e.x,o=e.y,a=e.z,l=e.w,c=2*(o*i-a*n),u=2*(a*t-s*i),h=2*(s*n-o*t);return this.x=t+l*c+o*h-a*u,this.y=n+l*u+a*c-s*h,this.z=i+l*h+s*u-o*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[4]*n+s[8]*i,this.y=s[1]*t+s[5]*n+s[9]*i,this.z=s[2]*t+s[6]*n+s[10]*i,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=ct(this.x,e.x,t.x),this.y=ct(this.y,e.y,t.y),this.z=ct(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=ct(this.x,e,t),this.y=ct(this.y,e,t),this.z=ct(this.z,e,t),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(ct(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const n=e.x,i=e.y,s=e.z,o=t.x,a=t.y,l=t.z;return this.x=i*l-s*a,this.y=s*o-n*l,this.z=n*a-i*o,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return cd.copy(this).projectOnVector(e),this.sub(cd)}reflect(e){return this.sub(cd.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const n=this.dot(e)/t;return Math.acos(ct(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y,i=this.z-e.z;return t*t+n*n+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,n){const i=Math.sin(t)*e;return this.x=i*Math.sin(n),this.y=Math.cos(t)*e,this.z=i*Math.cos(n),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),n=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=i,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,n=Math.sqrt(1-t*t);return this.x=n*Math.cos(e),this.y=t,this.z=n*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}};og.prototype.isVector3=!0;let P=og;const cd=new P,Tg=new Oi,ag=class ag{constructor(e,t,n,i,s,o,a,l,c){this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,n,i,s,o,a,l,c)}set(e,t,n,i,s,o,a,l,c){const u=this.elements;return u[0]=e,u[1]=i,u[2]=a,u[3]=t,u[4]=s,u[5]=l,u[6]=n,u[7]=o,u[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,i=t.elements,s=this.elements,o=n[0],a=n[3],l=n[6],c=n[1],u=n[4],h=n[7],d=n[2],f=n[5],p=n[8],g=i[0],m=i[3],_=i[6],x=i[1],y=i[4],b=i[7],M=i[2],S=i[5],E=i[8];return s[0]=o*g+a*x+l*M,s[3]=o*m+a*y+l*S,s[6]=o*_+a*b+l*E,s[1]=c*g+u*x+h*M,s[4]=c*m+u*y+h*S,s[7]=c*_+u*b+h*E,s[2]=d*g+f*x+p*M,s[5]=d*m+f*y+p*S,s[8]=d*_+f*b+p*E,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],u=e[8];return t*o*u-t*a*c-n*s*u+n*a*l+i*s*c-i*o*l}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],u=e[8],h=u*o-a*c,d=a*l-u*s,f=c*s-o*l,p=t*h+n*d+i*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const g=1/p;return e[0]=h*g,e[1]=(i*c-u*n)*g,e[2]=(a*n-i*o)*g,e[3]=d*g,e[4]=(u*t-i*l)*g,e[5]=(i*s-a*t)*g,e[6]=f*g,e[7]=(n*l-c*t)*g,e[8]=(o*t-n*s)*g,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,n,i,s,o,a){const l=Math.cos(s),c=Math.sin(s);return this.set(n*l,n*c,-n*(l*o+c*a)+o+e,-i*c,i*l,-i*(-c*o+l*a)+a+t,0,0,1),this}scale(e,t){return this.premultiply(ud.makeScale(e,t)),this}rotate(e){return this.premultiply(ud.makeRotation(-e)),this}translate(e,t){return this.premultiply(ud.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,n,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,n=e.elements;for(let i=0;i<9;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new this.constructor().fromArray(this.elements)}};ag.prototype.isMatrix3=!0;let Je=ag;const ud=new Je,Mg=new Je().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Eg=new Je().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function _T(){const r={enabled:!0,workingColorSpace:yc,spaces:{},convert:function(i,s,o){return this.enabled===!1||s===o||!s||!o||(this.spaces[s].transfer===Pe&&(i.r=jr(i.r),i.g=jr(i.g),i.b=jr(i.b)),this.spaces[s].primaries!==this.spaces[o].primaries&&(i.applyMatrix3(this.spaces[s].toXYZ),i.applyMatrix3(this.spaces[o].fromXYZ)),this.spaces[o].transfer===Pe&&(i.r=_a(i.r),i.g=_a(i.g),i.b=_a(i.b))),i},workingToColorSpace:function(i,s){return this.convert(i,this.workingColorSpace,s)},colorSpaceToWorking:function(i,s){return this.convert(i,s,this.workingColorSpace)},getPrimaries:function(i){return this.spaces[i].primaries},getTransfer:function(i){return i===ai?ja:this.spaces[i].transfer},getToneMappingMode:function(i){return this.spaces[i].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(i,s=this.workingColorSpace){return i.fromArray(this.spaces[s].luminanceCoefficients)},define:function(i){Object.assign(this.spaces,i)},_getMatrix:function(i,s,o){return i.copy(this.spaces[s].toXYZ).multiply(this.spaces[o].fromXYZ)},_getDrawingBufferColorSpace:function(i){return this.spaces[i].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(i=this.workingColorSpace){return this.spaces[i].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(i,s){return Kt("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),r.workingToColorSpace(i,s)},toWorkingColorSpace:function(i,s){return Kt("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),r.colorSpaceToWorking(i,s)}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],n=[.3127,.329];return r.define({[yc]:{primaries:e,whitePoint:n,transfer:ja,toXYZ:Mg,fromXYZ:Eg,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:ei},outputColorSpaceConfig:{drawingBufferColorSpace:ei}},[ei]:{primaries:e,whitePoint:n,transfer:Pe,toXYZ:Mg,fromXYZ:Eg,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:ei}}}),r}const Ye=_T();function jr(r){return r<.04045?r*.0773993808:Math.pow(r*.9478672986+.0521327014,2.4)}function _a(r){return r<.0031308?r*12.92:1.055*Math.pow(r,.41666)-.055}let Io;class xT{static getDataURL(e,t="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let n;if(e instanceof HTMLCanvasElement)n=e;else{Io===void 0&&(Io=bc("canvas")),Io.width=e.width,Io.height=e.height;const i=Io.getContext("2d");e instanceof ImageData?i.putImageData(e,0,0):i.drawImage(e,0,0,e.width,e.height),n=Io}return n.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const t=bc("canvas");t.width=e.width,t.height=e.height;const n=t.getContext("2d");n.drawImage(e,0,0,e.width,e.height);const i=n.getImageData(0,0,e.width,e.height),s=i.data;for(let o=0;o<s.length;o++)s[o]=jr(s[o]/255)*255;return n.putImageData(i,0,0),t}else if(e.data){const t=e.data.slice(0);for(let n=0;n<t.length;n++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[n]=Math.floor(jr(t[n]/255)*255):t[n]=jr(t[n]);return{data:t,width:e.width,height:e.height}}else return ae("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}}let yT=0;class am{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:yT++}),this.uuid=qr(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){const t=this.data;return typeof HTMLVideoElement<"u"&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):typeof VideoFrame<"u"&&t instanceof VideoFrame?e.set(t.displayWidth,t.displayHeight,0):t!==null?e.set(t.width,t.height,t.depth||0):e.set(0,0,0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];const n={uuid:this.uuid,url:""},i=this.data;if(i!==null){let s;if(Array.isArray(i)){s=[];for(let o=0,a=i.length;o<a;o++)i[o].isDataTexture?s.push(hd(i[o].image)):s.push(hd(i[o]))}else s=hd(i);n.url=s}return t||(e.images[this.uuid]=n),n}}function hd(r){return typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&r instanceof ImageBitmap?xT.getDataURL(r):r.data?{data:Array.from(r.data),width:r.width,height:r.height,type:r.data.constructor.name}:(ae("Texture: Unable to serialize Texture."),{})}let vT=0;const dd=new P;class fn extends Vi{constructor(e=fn.DEFAULT_IMAGE,t=fn.DEFAULT_MAPPING,n=ci,i=ci,s=Nt,o=ui,a=ln,l=Xt,c=fn.DEFAULT_ANISOTROPY,u=ai){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:vT++}),this.uuid=qr(),this.name="",this.source=new am(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=n,this.wrapT=i,this.magFilter=s,this.minFilter=o,this.anisotropy=c,this.format=a,this.internalFormat=null,this.type=l,this.offset=new pe(0,0),this.repeat=new pe(1,1),this.center=new pe(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Je,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=u,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(e&&e.depth&&e.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(dd).x}get height(){return this.source.getSize(dd).y}get depth(){return this.source.getSize(dd).z}get image(){return this.source.data}set image(e){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.normalized=e.normalized,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(const t in e){const n=e[t];if(n===void 0){ae(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}const i=this[t];if(i===void 0){ae(`Texture.setValues(): property '${t}' does not exist.`);continue}i&&n&&i.isVector2&&n.isVector2||i&&n&&i.isVector3&&n.isVector3||i&&n&&i.isMatrix3&&n.isMatrix3?i.copy(n):this[t]=n}}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];const n={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,normalized:this.normalized,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),t||(e.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==Jp)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case go:e.x=e.x-Math.floor(e.x);break;case ci:e.x=e.x<0?0:1;break;case _o:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case go:e.y=e.y-Math.floor(e.y);break;case ci:e.y=e.y<0?0:1;break;case _o:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}}fn.DEFAULT_IMAGE=null;fn.DEFAULT_MAPPING=Jp;fn.DEFAULT_ANISOTROPY=1;const lg=class lg{constructor(e=0,t=0,n=0,i=1){this.x=e,this.y=t,this.z=n,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,n,i){return this.x=e,this.y=t,this.z=n,this.w=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,n=this.y,i=this.z,s=this.w,o=e.elements;return this.x=o[0]*t+o[4]*n+o[8]*i+o[12]*s,this.y=o[1]*t+o[5]*n+o[9]*i+o[13]*s,this.z=o[2]*t+o[6]*n+o[10]*i+o[14]*s,this.w=o[3]*t+o[7]*n+o[11]*i+o[15]*s,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,n,i,s;const l=e.elements,c=l[0],u=l[4],h=l[8],d=l[1],f=l[5],p=l[9],g=l[2],m=l[6],_=l[10];if(Math.abs(u-d)<.01&&Math.abs(h-g)<.01&&Math.abs(p-m)<.01){if(Math.abs(u+d)<.1&&Math.abs(h+g)<.1&&Math.abs(p+m)<.1&&Math.abs(c+f+_-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const y=(c+1)/2,b=(f+1)/2,M=(_+1)/2,S=(u+d)/4,E=(h+g)/4,v=(p+m)/4;return y>b&&y>M?y<.01?(n=0,i=.707106781,s=.707106781):(n=Math.sqrt(y),i=S/n,s=E/n):b>M?b<.01?(n=.707106781,i=0,s=.707106781):(i=Math.sqrt(b),n=S/i,s=v/i):M<.01?(n=.707106781,i=.707106781,s=0):(s=Math.sqrt(M),n=E/s,i=v/s),this.set(n,i,s,t),this}let x=Math.sqrt((m-p)*(m-p)+(h-g)*(h-g)+(d-u)*(d-u));return Math.abs(x)<.001&&(x=1),this.x=(m-p)/x,this.y=(h-g)/x,this.z=(d-u)/x,this.w=Math.acos((c+f+_-1)/2),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=ct(this.x,e.x,t.x),this.y=ct(this.y,e.y,t.y),this.z=ct(this.z,e.z,t.z),this.w=ct(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=ct(this.x,e,t),this.y=ct(this.y,e,t),this.z=ct(this.z,e,t),this.w=ct(this.w,e,t),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(ct(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}};lg.prototype.isVector4=!0;let rt=lg;class ks extends Vi{constructor(e=1,t=1,n={}){super(),n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Nt,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1},n),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=n.depth,this.scissor=new rt(0,0,e,t),this.scissorTest=!1,this.viewport=new rt(0,0,e,t),this.textures=[];const i={width:e,height:t,depth:n.depth},s=new fn(i),o=n.count;for(let a=0;a<o;a++)this.textures[a]=s.clone(),this.textures[a].isRenderTargetTexture=!0,this.textures[a].renderTarget=this;this._setTextureOptions(n),this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.resolveDepthBuffer=n.resolveDepthBuffer,this.resolveStencilBuffer=n.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=n.depthTexture,this.samples=n.samples,this.multiview=n.multiview}_setTextureOptions(e={}){const t={minFilter:Nt,generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let n=0;n<this.textures.length;n++)this.textures[n].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),e!==null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,n=1){if(this.width!==e||this.height!==t||this.depth!==n){this.width=e,this.height=t,this.depth=n;for(let i=0,s=this.textures.length;i<s;i++)this.textures[i].image.width=e,this.textures[i].image.height=t,this.textures[i].image.depth=n,this.textures[i].isData3DTexture!==!0&&(this.textures[i].isArrayTexture=this.textures[i].image.depth>1);this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,n=e.textures.length;t<n;t++){this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0,this.textures[t].renderTarget=this;const i=Object.assign({},e.textures[t].image);this.textures[t].source=new am(i)}return this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this.multiview=e.multiview,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Yi extends ks{constructor(e=1,t=1,n={}){super(e,t,n),this.isWebGLRenderTarget=!0}}class lm extends fn{constructor(e=null,t=1,n=1,i=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:n,depth:i},this.magFilter=Mt,this.minFilter=Mt,this.wrapR=ci,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}}class bT extends fn{constructor(e=null,t=1,n=1,i=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:n,depth:i},this.magFilter=Mt,this.minFilter=Mt,this.wrapR=ci,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const Uh=class Uh{constructor(e,t,n,i,s,o,a,l,c,u,h,d,f,p,g,m){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,n,i,s,o,a,l,c,u,h,d,f,p,g,m)}set(e,t,n,i,s,o,a,l,c,u,h,d,f,p,g,m){const _=this.elements;return _[0]=e,_[4]=t,_[8]=n,_[12]=i,_[1]=s,_[5]=o,_[9]=a,_[13]=l,_[2]=c,_[6]=u,_[10]=h,_[14]=d,_[3]=f,_[7]=p,_[11]=g,_[15]=m,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 Uh().fromArray(this.elements)}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){const t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,n){return this.determinant()===0?(e.set(1,0,0),t.set(0,1,0),n.set(0,0,1),this):(e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this)}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){if(e.determinant()===0)return this.identity();const t=this.elements,n=e.elements,i=1/Bo.setFromMatrixColumn(e,0).length(),s=1/Bo.setFromMatrixColumn(e,1).length(),o=1/Bo.setFromMatrixColumn(e,2).length();return t[0]=n[0]*i,t[1]=n[1]*i,t[2]=n[2]*i,t[3]=0,t[4]=n[4]*s,t[5]=n[5]*s,t[6]=n[6]*s,t[7]=0,t[8]=n[8]*o,t[9]=n[9]*o,t[10]=n[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,n=e.x,i=e.y,s=e.z,o=Math.cos(n),a=Math.sin(n),l=Math.cos(i),c=Math.sin(i),u=Math.cos(s),h=Math.sin(s);if(e.order==="XYZ"){const d=o*u,f=o*h,p=a*u,g=a*h;t[0]=l*u,t[4]=-l*h,t[8]=c,t[1]=f+p*c,t[5]=d-g*c,t[9]=-a*l,t[2]=g-d*c,t[6]=p+f*c,t[10]=o*l}else if(e.order==="YXZ"){const d=l*u,f=l*h,p=c*u,g=c*h;t[0]=d+g*a,t[4]=p*a-f,t[8]=o*c,t[1]=o*h,t[5]=o*u,t[9]=-a,t[2]=f*a-p,t[6]=g+d*a,t[10]=o*l}else if(e.order==="ZXY"){const d=l*u,f=l*h,p=c*u,g=c*h;t[0]=d-g*a,t[4]=-o*h,t[8]=p+f*a,t[1]=f+p*a,t[5]=o*u,t[9]=g-d*a,t[2]=-o*c,t[6]=a,t[10]=o*l}else if(e.order==="ZYX"){const d=o*u,f=o*h,p=a*u,g=a*h;t[0]=l*u,t[4]=p*c-f,t[8]=d*c+g,t[1]=l*h,t[5]=g*c+d,t[9]=f*c-p,t[2]=-c,t[6]=a*l,t[10]=o*l}else if(e.order==="YZX"){const d=o*l,f=o*c,p=a*l,g=a*c;t[0]=l*u,t[4]=g-d*h,t[8]=p*h+f,t[1]=h,t[5]=o*u,t[9]=-a*u,t[2]=-c*u,t[6]=f*h+p,t[10]=d-g*h}else if(e.order==="XZY"){const d=o*l,f=o*c,p=a*l,g=a*c;t[0]=l*u,t[4]=-h,t[8]=c*u,t[1]=d*h+g,t[5]=o*u,t[9]=f*h-p,t[2]=p*h-f,t[6]=a*u,t[10]=g*h+d}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(ST,e,TT)}lookAt(e,t,n){const i=this.elements;return gi.subVectors(e,t),gi.lengthSq()===0&&(gi.z=1),gi.normalize(),rs.crossVectors(n,gi),rs.lengthSq()===0&&(Math.abs(n.z)===1?gi.x+=1e-4:gi.z+=1e-4,gi.normalize(),rs.crossVectors(n,gi)),rs.normalize(),Yc.crossVectors(gi,rs),i[0]=rs.x,i[4]=Yc.x,i[8]=gi.x,i[1]=rs.y,i[5]=Yc.y,i[9]=gi.y,i[2]=rs.z,i[6]=Yc.z,i[10]=gi.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,i=t.elements,s=this.elements,o=n[0],a=n[4],l=n[8],c=n[12],u=n[1],h=n[5],d=n[9],f=n[13],p=n[2],g=n[6],m=n[10],_=n[14],x=n[3],y=n[7],b=n[11],M=n[15],S=i[0],E=i[4],v=i[8],w=i[12],N=i[1],C=i[5],F=i[9],V=i[13],z=i[2],U=i[6],B=i[10],D=i[14],X=i[3],K=i[7],fe=i[11],Z=i[15];return s[0]=o*S+a*N+l*z+c*X,s[4]=o*E+a*C+l*U+c*K,s[8]=o*v+a*F+l*B+c*fe,s[12]=o*w+a*V+l*D+c*Z,s[1]=u*S+h*N+d*z+f*X,s[5]=u*E+h*C+d*U+f*K,s[9]=u*v+h*F+d*B+f*fe,s[13]=u*w+h*V+d*D+f*Z,s[2]=p*S+g*N+m*z+_*X,s[6]=p*E+g*C+m*U+_*K,s[10]=p*v+g*F+m*B+_*fe,s[14]=p*w+g*V+m*D+_*Z,s[3]=x*S+y*N+b*z+M*X,s[7]=x*E+y*C+b*U+M*K,s[11]=x*v+y*F+b*B+M*fe,s[15]=x*w+y*V+b*D+M*Z,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],n=e[4],i=e[8],s=e[12],o=e[1],a=e[5],l=e[9],c=e[13],u=e[2],h=e[6],d=e[10],f=e[14],p=e[3],g=e[7],m=e[11],_=e[15],x=l*f-c*d,y=a*f-c*h,b=a*d-l*h,M=o*f-c*u,S=o*d-l*u,E=o*h-a*u;return t*(g*x-m*y+_*b)-n*(p*x-m*M+_*S)+i*(p*y-g*M+_*E)-s*(p*b-g*S+m*E)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,n){const i=this.elements;return e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=t,i[14]=n),this}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],u=e[8],h=e[9],d=e[10],f=e[11],p=e[12],g=e[13],m=e[14],_=e[15],x=t*a-n*o,y=t*l-i*o,b=t*c-s*o,M=n*l-i*a,S=n*c-s*a,E=i*c-s*l,v=u*g-h*p,w=u*m-d*p,N=u*_-f*p,C=h*m-d*g,F=h*_-f*g,V=d*_-f*m,z=x*V-y*F+b*C+M*N-S*w+E*v;if(z===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const U=1/z;return e[0]=(a*V-l*F+c*C)*U,e[1]=(i*F-n*V-s*C)*U,e[2]=(g*E-m*S+_*M)*U,e[3]=(d*S-h*E-f*M)*U,e[4]=(l*N-o*V-c*w)*U,e[5]=(t*V-i*N+s*w)*U,e[6]=(m*b-p*E-_*y)*U,e[7]=(u*E-d*b+f*y)*U,e[8]=(o*F-a*N+c*v)*U,e[9]=(n*N-t*F-s*v)*U,e[10]=(p*S-g*b+_*x)*U,e[11]=(h*b-u*S-f*x)*U,e[12]=(a*w-o*C-l*v)*U,e[13]=(t*C-n*w+i*v)*U,e[14]=(g*y-p*M-m*x)*U,e[15]=(u*M-h*y+d*x)*U,this}scale(e){const t=this.elements,n=e.x,i=e.y,s=e.z;return t[0]*=n,t[4]*=i,t[8]*=s,t[1]*=n,t[5]*=i,t[9]*=s,t[2]*=n,t[6]*=i,t[10]*=s,t[3]*=n,t[7]*=i,t[11]*=s,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,i))}makeTranslation(e,t,n){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const n=Math.cos(t),i=Math.sin(t),s=1-n,o=e.x,a=e.y,l=e.z,c=s*o,u=s*a;return this.set(c*o+n,c*a-i*l,c*l+i*a,0,c*a+i*l,u*a+n,u*l-i*o,0,c*l-i*a,u*l+i*o,s*l*l+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,i,s,o){return this.set(1,n,s,0,e,1,o,0,t,i,1,0,0,0,0,1),this}compose(e,t,n){const i=this.elements,s=t._x,o=t._y,a=t._z,l=t._w,c=s+s,u=o+o,h=a+a,d=s*c,f=s*u,p=s*h,g=o*u,m=o*h,_=a*h,x=l*c,y=l*u,b=l*h,M=n.x,S=n.y,E=n.z;return i[0]=(1-(g+_))*M,i[1]=(f+b)*M,i[2]=(p-y)*M,i[3]=0,i[4]=(f-b)*S,i[5]=(1-(d+_))*S,i[6]=(m+x)*S,i[7]=0,i[8]=(p+y)*E,i[9]=(m-x)*E,i[10]=(1-(d+g))*E,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,n){const i=this.elements;e.x=i[12],e.y=i[13],e.z=i[14];const s=this.determinant();if(s===0)return n.set(1,1,1),t.identity(),this;let o=Bo.set(i[0],i[1],i[2]).length();const a=Bo.set(i[4],i[5],i[6]).length(),l=Bo.set(i[8],i[9],i[10]).length();s<0&&(o=-o),zi.copy(this);const c=1/o,u=1/a,h=1/l;return zi.elements[0]*=c,zi.elements[1]*=c,zi.elements[2]*=c,zi.elements[4]*=u,zi.elements[5]*=u,zi.elements[6]*=u,zi.elements[8]*=h,zi.elements[9]*=h,zi.elements[10]*=h,t.setFromRotationMatrix(zi),n.x=o,n.y=a,n.z=l,this}makePerspective(e,t,n,i,s,o,a=ii,l=!1){const c=this.elements,u=2*s/(t-e),h=2*s/(n-i),d=(t+e)/(t-e),f=(n+i)/(n-i);let p,g;if(l)p=s/(o-s),g=o*s/(o-s);else if(a===ii)p=-(o+s)/(o-s),g=-2*o*s/(o-s);else if(a===Tr)p=-o/(o-s),g=-o*s/(o-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=u,c[4]=0,c[8]=d,c[12]=0,c[1]=0,c[5]=h,c[9]=f,c[13]=0,c[2]=0,c[6]=0,c[10]=p,c[14]=g,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,n,i,s,o,a=ii,l=!1){const c=this.elements,u=2/(t-e),h=2/(n-i),d=-(t+e)/(t-e),f=-(n+i)/(n-i);let p,g;if(l)p=1/(o-s),g=o/(o-s);else if(a===ii)p=-2/(o-s),g=-(o+s)/(o-s);else if(a===Tr)p=-1/(o-s),g=-s/(o-s);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=u,c[4]=0,c[8]=0,c[12]=d,c[1]=0,c[5]=h,c[9]=0,c[13]=f,c[2]=0,c[6]=0,c[10]=p,c[14]=g,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){const t=this.elements,n=e.elements;for(let i=0;i<16;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}};Uh.prototype.isMatrix4=!0;let pt=Uh;const Bo=new P,zi=new pt,ST=new P(0,0,0),TT=new P(1,1,1),rs=new P,Yc=new P,gi=new P,Ag=new pt,wg=new Oi;class Mr{constructor(e=0,t=0,n=0,i=Mr.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=n,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,n,i=this._order){return this._x=e,this._y=t,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,n=!0){const i=e.elements,s=i[0],o=i[4],a=i[8],l=i[1],c=i[5],u=i[9],h=i[2],d=i[6],f=i[10];switch(t){case"XYZ":this._y=Math.asin(ct(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-u,f),this._z=Math.atan2(-o,s)):(this._x=Math.atan2(d,c),this._z=0);break;case"YXZ":this._x=Math.asin(-ct(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(a,f),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-h,s),this._z=0);break;case"ZXY":this._x=Math.asin(ct(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-h,f),this._z=Math.atan2(-o,c)):(this._y=0,this._z=Math.atan2(l,s));break;case"ZYX":this._y=Math.asin(-ct(h,-1,1)),Math.abs(h)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(l,s)):(this._x=0,this._z=Math.atan2(-o,c));break;case"YZX":this._z=Math.asin(ct(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-u,c),this._y=Math.atan2(-h,s)):(this._x=0,this._y=Math.atan2(a,f));break;case"XZY":this._z=Math.asin(-ct(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(d,c),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-u,f),this._y=0);break;default:ae("Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return Ag.makeRotationFromQuaternion(e),this.setFromRotationMatrix(Ag,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return wg.setFromEuler(this),this.setFromQuaternion(wg,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Mr.DEFAULT_ORDER="XYZ";class cm{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!==0}}let MT=0;const Rg=new P,Oo=new Oi,Pr=new pt,Kc=new P,xl=new P,ET=new P,AT=new Oi,Cg=new P(1,0,0),Ng=new P(0,1,0),Pg=new P(0,0,1),Dg={type:"added"},wT={type:"removed"},ko={type:"childadded",child:null},fd={type:"childremoved",child:null};class pn extends Vi{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:MT++}),this.uuid=qr(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=pn.DEFAULT_UP.clone();const e=new P,t=new Mr,n=new Oi,i=new P(1,1,1);function s(){n.setFromEuler(t,!1)}function o(){t.setFromQuaternion(n,void 0,!1)}t._onChange(s),n._onChange(o),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:n},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new pt},normalMatrix:{value:new Je}}),this.matrix=new pt,this.matrixWorld=new pt,this.matrixAutoUpdate=pn.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=pn.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new cm,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return Oo.setFromAxisAngle(e,t),this.quaternion.multiply(Oo),this}rotateOnWorldAxis(e,t){return Oo.setFromAxisAngle(e,t),this.quaternion.premultiply(Oo),this}rotateX(e){return this.rotateOnAxis(Cg,e)}rotateY(e){return this.rotateOnAxis(Ng,e)}rotateZ(e){return this.rotateOnAxis(Pg,e)}translateOnAxis(e,t){return Rg.copy(e).applyQuaternion(this.quaternion),this.position.add(Rg.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(Cg,e)}translateY(e){return this.translateOnAxis(Ng,e)}translateZ(e){return this.translateOnAxis(Pg,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(Pr.copy(this.matrixWorld).invert())}lookAt(e,t,n){e.isVector3?Kc.copy(e):Kc.set(e,t,n);const i=this.parent;this.updateWorldMatrix(!0,!1),xl.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Pr.lookAt(xl,Kc,this.up):Pr.lookAt(Kc,xl,this.up),this.quaternion.setFromRotationMatrix(Pr),i&&(Pr.extractRotation(i.matrixWorld),Oo.setFromRotationMatrix(Pr),this.quaternion.premultiply(Oo.invert()))}add(e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return e===this?(ce("Object3D.add: object can't be added as a child of itself.",e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(Dg),ko.child=e,this.dispatchEvent(ko),ko.child=null):ce("Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let n=0;n<arguments.length;n++)this.remove(arguments[n]);return this}const t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(wT),fd.child=e,this.dispatchEvent(fd),fd.child=null),this}removeFromParent(){const e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),Pr.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),Pr.multiply(e.parent.matrixWorld)),e.applyMatrix4(Pr),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(Dg),ko.child=e,this.dispatchEvent(ko),ko.child=null,this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let n=0,i=this.children.length;n<i;n++){const o=this.children[n].getObjectByProperty(e,t);if(o!==void 0)return o}}getObjectsByProperty(e,t,n=[]){this[e]===t&&n.push(this);const i=this.children;for(let s=0,o=i.length;s<o;s++)i[s].getObjectsByProperty(e,t,n);return n}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(xl,e,ET),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(xl,AT,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);const t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);const t=this.children;for(let n=0,i=t.length;n<i;n++)t[n].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);const t=this.children;for(let n=0,i=t.length;n<i;n++)t[n].traverseVisible(e)}traverseAncestors(e){const t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const e=this.pivot;if(e!==null){const t=e.x,n=e.y,i=e.z,s=this.matrix.elements;s[12]+=t-s[0]*t-s[4]*n-s[8]*i,s[13]+=n-s[1]*t-s[5]*n-s[9]*i,s[14]+=i-s[2]*t-s[6]*n-s[10]*i}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);const t=this.children;for(let n=0,i=t.length;n<i;n++)t[n].updateMatrixWorld(e)}updateWorldMatrix(e,t){const n=this.parent;if(e===!0&&n!==null&&n.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)),t===!0){const i=this.children;for(let s=0,o=i.length;s<o;s++)i[s].updateWorldMatrix(!1,!0)}}toJSON(e){const t=e===void 0||typeof e=="string",n={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const i={};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.castShadow===!0&&(i.castShadow=!0),this.receiveShadow===!0&&(i.receiveShadow=!0),this.visible===!1&&(i.visible=!1),this.frustumCulled===!1&&(i.frustumCulled=!1),this.renderOrder!==0&&(i.renderOrder=this.renderOrder),this.static!==!1&&(i.static=this.static),Object.keys(this.userData).length>0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),this.pivot!==null&&(i.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(i.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(i.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(i.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(a=>({...a})),i.availableInstanceIds=this._availableInstanceIds.slice(),i.availableGeometryIds=this._availableGeometryIds.slice(),i.nextIndexStart=this._nextIndexStart,i.nextVertexStart=this._nextVertexStart,i.geometryCount=this._geometryCount,i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.matricesTexture=this._matricesTexture.toJSON(e),i.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(i.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(i.boundingBox=this.boundingBox.toJSON()));function s(a,l){return a[l.uuid]===void 0&&(a[l.uuid]=l.toJSON(e)),l.uuid}if(this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=s(e.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const l=a.shapes;if(Array.isArray(l))for(let c=0,u=l.length;c<u;c++){const h=l[c];s(e.shapes,h)}else s(e.shapes,l)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(e.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let l=0,c=this.material.length;l<c;l++)a.push(s(e.materials,this.material[l]));i.material=a}else i.material=s(e.materials,this.material);if(this.children.length>0){i.children=[];for(let a=0;a<this.children.length;a++)i.children.push(this.children[a].toJSON(e).object)}if(this.animations.length>0){i.animations=[];for(let a=0;a<this.animations.length;a++){const l=this.animations[a];i.animations.push(s(e.animations,l))}}if(t){const a=o(e.geometries),l=o(e.materials),c=o(e.textures),u=o(e.images),h=o(e.shapes),d=o(e.skeletons),f=o(e.animations),p=o(e.nodes);a.length>0&&(n.geometries=a),l.length>0&&(n.materials=l),c.length>0&&(n.textures=c),u.length>0&&(n.images=u),h.length>0&&(n.shapes=h),d.length>0&&(n.skeletons=d),f.length>0&&(n.animations=f),p.length>0&&(n.nodes=p)}return n.object=i,n;function o(a){const l=[];for(const c in a){const u=a[c];delete u.metadata,l.push(u)}return l}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.pivot=e.pivot!==null?e.pivot.clone():null,this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.static=e.static,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let n=0;n<e.children.length;n++){const i=e.children[n];this.add(i.clone())}return this}}pn.DEFAULT_UP=new P(0,1,0);pn.DEFAULT_MATRIX_AUTO_UPDATE=!0;pn.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class ua extends pn{constructor(){super(),this.isGroup=!0,this.type="Group"}}const RT={type:"move"};class oh{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new ua,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new ua,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new P,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new P),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new ua,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new P,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new P,this._grip.eventsEnabled=!1),this._grip}dispatchEvent(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){const t=this._hand;if(t)for(const n of e.hand.values())this._getHandJoint(t,n)}return this.dispatchEvent({type:"connected",data:e}),this}disconnect(e){return this.dispatchEvent({type:"disconnected",data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,n){let i=null,s=null,o=null;const a=this._targetRay,l=this._grip,c=this._hand;if(e&&t.session.visibilityState!=="visible-blurred"){if(c&&e.hand){o=!0;for(const g of e.hand.values()){const m=t.getJointPose(g,n),_=this._getHandJoint(c,g);m!==null&&(_.matrix.fromArray(m.transform.matrix),_.matrix.decompose(_.position,_.rotation,_.scale),_.matrixWorldNeedsUpdate=!0,_.jointRadius=m.radius),_.visible=m!==null}const u=c.joints["index-finger-tip"],h=c.joints["thumb-tip"],d=u.position.distanceTo(h.position),f=.02,p=.005;c.inputState.pinching&&d>f+p?(c.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!c.inputState.pinching&&d<=f-p&&(c.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else l!==null&&e.gripSpace&&(s=t.getPose(e.gripSpace,n),s!==null&&(l.matrix.fromArray(s.transform.matrix),l.matrix.decompose(l.position,l.rotation,l.scale),l.matrixWorldNeedsUpdate=!0,s.linearVelocity?(l.hasLinearVelocity=!0,l.linearVelocity.copy(s.linearVelocity)):l.hasLinearVelocity=!1,s.angularVelocity?(l.hasAngularVelocity=!0,l.angularVelocity.copy(s.angularVelocity)):l.hasAngularVelocity=!1,l.eventsEnabled&&l.dispatchEvent({type:"gripUpdated",data:e,target:this})));a!==null&&(i=t.getPose(e.targetRaySpace,n),i===null&&s!==null&&(i=s),i!==null&&(a.matrix.fromArray(i.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,i.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(i.linearVelocity)):a.hasLinearVelocity=!1,i.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(i.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(RT)))}return a!==null&&(a.visible=i!==null),l!==null&&(l.visible=s!==null),c!==null&&(c.visible=o!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){const n=new ua;n.matrixAutoUpdate=!1,n.visible=!1,e.joints[t.jointName]=n,e.add(n)}return e.joints[t.jointName]}}const J0={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},ss={h:0,s:0,l:0},Zc={h:0,s:0,l:0};function pd(r,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?r+(e-r)*6*t:t<1/2?e:t<2/3?r+(e-r)*6*(2/3-t):r}class We{constructor(e,t,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,n)}set(e,t,n){if(t===void 0&&n===void 0){const i=e;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(e,t,n);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=ei){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Ye.colorSpaceToWorking(this,t),this}setRGB(e,t,n,i=Ye.workingColorSpace){return this.r=e,this.g=t,this.b=n,Ye.colorSpaceToWorking(this,i),this}setHSL(e,t,n,i=Ye.workingColorSpace){if(e=om(e,1),t=ct(t,0,1),n=ct(n,0,1),t===0)this.r=this.g=this.b=n;else{const s=n<=.5?n*(1+t):n+t-n*t,o=2*n-s;this.r=pd(o,s,e+1/3),this.g=pd(o,s,e),this.b=pd(o,s,e-1/3)}return Ye.colorSpaceToWorking(this,i),this}setStyle(e,t=ei){function n(s){s!==void 0&&parseFloat(s)<1&&ae("Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(e)){let s;const o=i[1],a=i[2];switch(o){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,t);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,t);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,t);break;default:ae("Color: Unknown color model "+e)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(e)){const s=i[1],o=s.length;if(o===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,t);if(o===6)return this.setHex(parseInt(s,16),t);ae("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=ei){const n=J0[e.toLowerCase()];return n!==void 0?this.setHex(n,t):ae("Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=jr(e.r),this.g=jr(e.g),this.b=jr(e.b),this}copyLinearToSRGB(e){return this.r=_a(e.r),this.g=_a(e.g),this.b=_a(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=ei){return Ye.workingToColorSpace(zn.copy(this),e),Math.round(ct(zn.r*255,0,255))*65536+Math.round(ct(zn.g*255,0,255))*256+Math.round(ct(zn.b*255,0,255))}getHexString(e=ei){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=Ye.workingColorSpace){Ye.workingToColorSpace(zn.copy(this),t);const n=zn.r,i=zn.g,s=zn.b,o=Math.max(n,i,s),a=Math.min(n,i,s);let l,c;const u=(a+o)/2;if(a===o)l=0,c=0;else{const h=o-a;switch(c=u<=.5?h/(o+a):h/(2-o-a),o){case n:l=(i-s)/h+(i<s?6:0);break;case i:l=(s-n)/h+2;break;case s:l=(n-i)/h+4;break}l/=6}return e.h=l,e.s=c,e.l=u,e}getRGB(e,t=Ye.workingColorSpace){return Ye.workingToColorSpace(zn.copy(this),t),e.r=zn.r,e.g=zn.g,e.b=zn.b,e}getStyle(e=ei){Ye.workingToColorSpace(zn.copy(this),e);const t=zn.r,n=zn.g,i=zn.b;return e!==ei?`color(${e} ${t.toFixed(3)} ${n.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(t*255)},${Math.round(n*255)},${Math.round(i*255)})`}offsetHSL(e,t,n){return this.getHSL(ss),this.setHSL(ss.h+e,ss.s+t,ss.l+n)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,n){return this.r=e.r+(t.r-e.r)*n,this.g=e.g+(t.g-e.g)*n,this.b=e.b+(t.b-e.b)*n,this}lerpHSL(e,t){this.getHSL(ss),e.getHSL(Zc);const n=jl(ss.h,Zc.h,t),i=jl(ss.s,Zc.s,t),s=jl(ss.l,Zc.l,t);return this.setHSL(n,i,s),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){const t=this.r,n=this.g,i=this.b,s=e.elements;return this.r=s[0]*t+s[3]*n+s[6]*i,this.g=s[1]*t+s[4]*n+s[7]*i,this.b=s[2]*t+s[5]*n+s[8]*i,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const zn=new We;We.NAMES=J0;class um{constructor(e,t=1,n=1e3){this.isFog=!0,this.name="",this.color=new We(e),this.near=t,this.far=n}clone(){return new um(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class hm extends pn{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new Mr,this.environmentIntensity=1,this.environmentRotation=new Mr,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}}const Hi=new P,Dr=new P,md=new P,Lr=new P,Go=new P,Vo=new P,Lg=new P,gd=new P,_d=new P,xd=new P,yd=new rt,vd=new rt,bd=new rt;class Ni{constructor(e=new P,t=new P,n=new P){this.a=e,this.b=t,this.c=n}static getNormal(e,t,n,i){i.subVectors(n,t),Hi.subVectors(e,t),i.cross(Hi);const s=i.lengthSq();return s>0?i.multiplyScalar(1/Math.sqrt(s)):i.set(0,0,0)}static getBarycoord(e,t,n,i,s){Hi.subVectors(i,t),Dr.subVectors(n,t),md.subVectors(e,t);const o=Hi.dot(Hi),a=Hi.dot(Dr),l=Hi.dot(md),c=Dr.dot(Dr),u=Dr.dot(md),h=o*c-a*a;if(h===0)return s.set(0,0,0),null;const d=1/h,f=(c*l-a*u)*d,p=(o*u-a*l)*d;return s.set(1-f-p,p,f)}static containsPoint(e,t,n,i){return this.getBarycoord(e,t,n,i,Lr)===null?!1:Lr.x>=0&&Lr.y>=0&&Lr.x+Lr.y<=1}static getInterpolation(e,t,n,i,s,o,a,l){return this.getBarycoord(e,t,n,i,Lr)===null?(l.x=0,l.y=0,"z"in l&&(l.z=0),"w"in l&&(l.w=0),null):(l.setScalar(0),l.addScaledVector(s,Lr.x),l.addScaledVector(o,Lr.y),l.addScaledVector(a,Lr.z),l)}static getInterpolatedAttribute(e,t,n,i,s,o){return yd.setScalar(0),vd.setScalar(0),bd.setScalar(0),yd.fromBufferAttribute(e,t),vd.fromBufferAttribute(e,n),bd.fromBufferAttribute(e,i),o.setScalar(0),o.addScaledVector(yd,s.x),o.addScaledVector(vd,s.y),o.addScaledVector(bd,s.z),o}static isFrontFacing(e,t,n,i){return Hi.subVectors(n,t),Dr.subVectors(e,t),Hi.cross(Dr).dot(i)<0}set(e,t,n){return this.a.copy(e),this.b.copy(t),this.c.copy(n),this}setFromPointsAndIndices(e,t,n,i){return this.a.copy(e[t]),this.b.copy(e[n]),this.c.copy(e[i]),this}setFromAttributeAndIndices(e,t,n,i){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,n),this.c.fromBufferAttribute(e,i),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return Hi.subVectors(this.c,this.b),Dr.subVectors(this.a,this.b),Hi.cross(Dr).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return Ni.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return Ni.getBarycoord(e,this.a,this.b,this.c,t)}getInterpolation(e,t,n,i,s){return Ni.getInterpolation(e,this.a,this.b,this.c,t,n,i,s)}containsPoint(e){return Ni.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return Ni.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){const n=this.a,i=this.b,s=this.c;let o,a;Go.subVectors(i,n),Vo.subVectors(s,n),gd.subVectors(e,n);const l=Go.dot(gd),c=Vo.dot(gd);if(l<=0&&c<=0)return t.copy(n);_d.subVectors(e,i);const u=Go.dot(_d),h=Vo.dot(_d);if(u>=0&&h<=u)return t.copy(i);const d=l*h-u*c;if(d<=0&&l>=0&&u<=0)return o=l/(l-u),t.copy(n).addScaledVector(Go,o);xd.subVectors(e,s);const f=Go.dot(xd),p=Vo.dot(xd);if(p>=0&&f<=p)return t.copy(s);const g=f*c-l*p;if(g<=0&&c>=0&&p<=0)return a=c/(c-p),t.copy(n).addScaledVector(Vo,a);const m=u*p-f*h;if(m<=0&&h-u>=0&&f-p>=0)return Lg.subVectors(s,i),a=(h-u)/(h-u+(f-p)),t.copy(i).addScaledVector(Lg,a);const _=1/(m+g+d);return o=g*_,a=d*_,t.copy(n).addScaledVector(Go,o).addScaledVector(Vo,a)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}}class Ro{constructor(e=new P(1/0,1/0,1/0),t=new P(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t+=3)this.expandByPoint(Wi.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,n=e.count;t<n;t++)this.expandByPoint(Wi.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){const n=Wi.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(n),this.max.copy(e).add(n),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);const n=e.geometry;if(n!==void 0){const s=n.getAttribute("position");if(t===!0&&s!==void 0&&e.isInstancedMesh!==!0)for(let o=0,a=s.count;o<a;o++)e.isMesh===!0?e.getVertexPosition(o,Wi):Wi.fromBufferAttribute(s,o),Wi.applyMatrix4(e.matrixWorld),this.expandByPoint(Wi);else e.boundingBox!==void 0?(e.boundingBox===null&&e.computeBoundingBox(),Qc.copy(e.boundingBox)):(n.boundingBox===null&&n.computeBoundingBox(),Qc.copy(n.boundingBox)),Qc.applyMatrix4(e.matrixWorld),this.union(Qc)}const i=e.children;for(let s=0,o=i.length;s<o;s++)this.expandByObject(i[s],t);return this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,Wi),Wi.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,n;return e.normal.x>0?(t=e.normal.x*this.min.x,n=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,n=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,n+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,n+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,n+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,n+=e.normal.z*this.min.z),t<=-e.constant&&n>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(yl),Jc.subVectors(this.max,yl),zo.subVectors(e.a,yl),Ho.subVectors(e.b,yl),Wo.subVectors(e.c,yl),os.subVectors(Ho,zo),as.subVectors(Wo,Ho),Xs.subVectors(zo,Wo);let t=[0,-os.z,os.y,0,-as.z,as.y,0,-Xs.z,Xs.y,os.z,0,-os.x,as.z,0,-as.x,Xs.z,0,-Xs.x,-os.y,os.x,0,-as.y,as.x,0,-Xs.y,Xs.x,0];return!Sd(t,zo,Ho,Wo,Jc)||(t=[1,0,0,0,1,0,0,0,1],!Sd(t,zo,Ho,Wo,Jc))?!1:(eu.crossVectors(os,as),t=[eu.x,eu.y,eu.z],Sd(t,zo,Ho,Wo,Jc))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Wi).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Wi).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(Ur[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Ur[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Ur[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Ur[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Ur[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Ur[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Ur[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Ur[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Ur),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}}const Ur=[new P,new P,new P,new P,new P,new P,new P,new P],Wi=new P,Qc=new Ro,zo=new P,Ho=new P,Wo=new P,os=new P,as=new P,Xs=new P,yl=new P,Jc=new P,eu=new P,qs=new P;function Sd(r,e,t,n,i){for(let s=0,o=r.length-3;s<=o;s+=3){qs.fromArray(r,s);const a=i.x*Math.abs(qs.x)+i.y*Math.abs(qs.y)+i.z*Math.abs(qs.z),l=e.dot(qs),c=t.dot(qs),u=n.dot(qs);if(Math.max(-Math.max(l,c,u),Math.min(l,c,u))>a)return!1}return!0}const Vr=CT();function CT(){const r=new ArrayBuffer(4),e=new Float32Array(r),t=new Uint32Array(r),n=new Uint32Array(512),i=new Uint32Array(512);for(let l=0;l<256;++l){const c=l-127;c<-27?(n[l]=0,n[l|256]=32768,i[l]=24,i[l|256]=24):c<-14?(n[l]=1024>>-c-14,n[l|256]=1024>>-c-14|32768,i[l]=-c-1,i[l|256]=-c-1):c<=15?(n[l]=c+15<<10,n[l|256]=c+15<<10|32768,i[l]=13,i[l|256]=13):c<128?(n[l]=31744,n[l|256]=64512,i[l]=24,i[l|256]=24):(n[l]=31744,n[l|256]=64512,i[l]=13,i[l|256]=13)}const s=new Uint32Array(2048),o=new Uint32Array(64),a=new Uint32Array(64);for(let l=1;l<1024;++l){let c=l<<13,u=0;for(;(c&8388608)===0;)c<<=1,u-=8388608;c&=-8388609,u+=947912704,s[l]=c|u}for(let l=1024;l<2048;++l)s[l]=939524096+(l-1024<<13);for(let l=1;l<31;++l)o[l]=l<<23;o[31]=1199570944,o[32]=2147483648;for(let l=33;l<63;++l)o[l]=2147483648+(l-32<<23);o[63]=3347054592;for(let l=1;l<64;++l)l!==32&&(a[l]=1024);return{floatView:e,uint32View:t,baseTable:n,shiftTable:i,mantissaTable:s,exponentTable:o,offsetTable:a}}function _i(r){Math.abs(r)>65504&&ae("DataUtils.toHalfFloat(): Value out of range."),r=ct(r,-65504,65504),Vr.floatView[0]=r;const e=Vr.uint32View[0],t=e>>23&511;return Vr.baseTable[t]+((e&8388607)>>Vr.shiftTable[t])}function tu(r){const e=r>>10;return Vr.uint32View[0]=Vr.mantissaTable[Vr.offsetTable[e]+(r&1023)]+Vr.exponentTable[e],Vr.floatView[0]}const gn=new P,nu=new pe;let NT=0;class Bn extends Vi{constructor(e,t,n=!1){if(super(),Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:NT++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=n,this.usage=Ya,this.updateRanges=[],this.gpuType=Qt,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,n){e*=this.itemSize,n*=t.itemSize;for(let i=0,s=this.itemSize;i<s;i++)this.array[e+i]=t.array[n+i];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,n=this.count;t<n;t++)nu.fromBufferAttribute(this,t),nu.applyMatrix3(e),this.setXY(t,nu.x,nu.y);else if(this.itemSize===3)for(let t=0,n=this.count;t<n;t++)gn.fromBufferAttribute(this,t),gn.applyMatrix3(e),this.setXYZ(t,gn.x,gn.y,gn.z);return this}applyMatrix4(e){for(let t=0,n=this.count;t<n;t++)gn.fromBufferAttribute(this,t),gn.applyMatrix4(e),this.setXYZ(t,gn.x,gn.y,gn.z);return this}applyNormalMatrix(e){for(let t=0,n=this.count;t<n;t++)gn.fromBufferAttribute(this,t),gn.applyNormalMatrix(e),this.setXYZ(t,gn.x,gn.y,gn.z);return this}transformDirection(e){for(let t=0,n=this.count;t<n;t++)gn.fromBufferAttribute(this,t),gn.transformDirection(e),this.setXYZ(t,gn.x,gn.y,gn.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let n=this.array[e*this.itemSize+t];return this.normalized&&(n=ni(n,this.array)),n}setComponent(e,t,n){return this.normalized&&(n=lt(n,this.array)),this.array[e*this.itemSize+t]=n,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=ni(t,this.array)),t}setX(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=ni(t,this.array)),t}setY(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=ni(t,this.array)),t}setZ(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=ni(t,this.array)),t}setW(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,n){return e*=this.itemSize,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array)),this.array[e+0]=t,this.array[e+1]=n,this}setXYZ(e,t,n,i){return e*=this.itemSize,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array),i=lt(i,this.array)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=i,this}setXYZW(e,t,n,i,s){return e*=this.itemSize,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array),i=lt(i,this.array),s=lt(s,this.array)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=i,this.array[e+3]=s,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(e.name=this.name),this.usage!==Ya&&(e.usage=this.usage),e}dispose(){this.dispatchEvent({type:"dispose"})}}class dm extends Bn{constructor(e,t,n){super(new Uint16Array(e),t,n)}}class fm extends Bn{constructor(e,t,n){super(new Uint32Array(e),t,n)}}class ey extends Bn{constructor(e,t,n){super(new Uint16Array(e),t,n),this.isFloat16BufferAttribute=!0}getX(e){let t=tu(this.array[e*this.itemSize]);return this.normalized&&(t=ni(t,this.array)),t}setX(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize]=_i(t),this}getY(e){let t=tu(this.array[e*this.itemSize+1]);return this.normalized&&(t=ni(t,this.array)),t}setY(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize+1]=_i(t),this}getZ(e){let t=tu(this.array[e*this.itemSize+2]);return this.normalized&&(t=ni(t,this.array)),t}setZ(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize+2]=_i(t),this}getW(e){let t=tu(this.array[e*this.itemSize+3]);return this.normalized&&(t=ni(t,this.array)),t}setW(e,t){return this.normalized&&(t=lt(t,this.array)),this.array[e*this.itemSize+3]=_i(t),this}setXY(e,t,n){return e*=this.itemSize,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array)),this.array[e+0]=_i(t),this.array[e+1]=_i(n),this}setXYZ(e,t,n,i){return e*=this.itemSize,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array),i=lt(i,this.array)),this.array[e+0]=_i(t),this.array[e+1]=_i(n),this.array[e+2]=_i(i),this}setXYZW(e,t,n,i,s){return e*=this.itemSize,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array),i=lt(i,this.array),s=lt(s,this.array)),this.array[e+0]=_i(t),this.array[e+1]=_i(n),this.array[e+2]=_i(i),this.array[e+3]=_i(s),this}}class sn extends Bn{constructor(e,t,n){super(new Float32Array(e),t,n)}}const PT=new Ro,vl=new P,Td=new P;class Fc{constructor(e=new P,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){const n=this.center;t!==void 0?n.copy(t):PT.setFromPoints(e).getCenter(n);let i=0;for(let s=0,o=e.length;s<o;s++)i=Math.max(i,n.distanceToSquared(e[s]));return this.radius=Math.sqrt(i),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){const t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){const n=this.center.distanceToSquared(e);return t.copy(e),n>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;vl.subVectors(e,this.center);const t=vl.lengthSq();if(t>this.radius*this.radius){const n=Math.sqrt(t),i=(n-this.radius)*.5;this.center.addScaledVector(vl,i/n),this.radius+=i}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(Td.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(vl.copy(e.center).add(Td)),this.expandByPoint(vl.copy(e.center).sub(Td))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}}let DT=0;const Ai=new pt,Md=new pn,$o=new P,xi=new Ro,bl=new Ro,wn=new P;class An extends Vi{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:DT++}),this.uuid=qr(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(JS(e)?fm:dm)(e,1):this.index=e,this}setIndirect(e,t=0){return this.indirect=e,this.indirectOffset=t,this}getIndirect(){return this.indirect}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,n=0){this.groups.push({start:e,count:t,materialIndex:n})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){const t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);const n=this.attributes.normal;if(n!==void 0){const s=new Je().getNormalMatrix(e);n.applyNormalMatrix(s),n.needsUpdate=!0}const i=this.attributes.tangent;return i!==void 0&&(i.transformDirection(e),i.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(e){return Ai.makeRotationFromQuaternion(e),this.applyMatrix4(Ai),this}rotateX(e){return Ai.makeRotationX(e),this.applyMatrix4(Ai),this}rotateY(e){return Ai.makeRotationY(e),this.applyMatrix4(Ai),this}rotateZ(e){return Ai.makeRotationZ(e),this.applyMatrix4(Ai),this}translate(e,t,n){return Ai.makeTranslation(e,t,n),this.applyMatrix4(Ai),this}scale(e,t,n){return Ai.makeScale(e,t,n),this.applyMatrix4(Ai),this}lookAt(e){return Md.lookAt(e),Md.updateMatrix(),this.applyMatrix4(Md.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter($o).negate(),this.translate($o.x,$o.y,$o.z),this}setFromPoints(e){const t=this.getAttribute("position");if(t===void 0){const n=[];for(let i=0,s=e.length;i<s;i++){const o=e[i];n.push(o.x,o.y,o.z||0)}this.setAttribute("position",new sn(n,3))}else{const n=Math.min(e.length,t.count);for(let i=0;i<n;i++){const s=e[i];t.setXYZ(i,s.x,s.y,s.z||0)}e.length>t.count&&ae("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Ro);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){ce("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new P(-1/0,-1/0,-1/0),new P(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let n=0,i=t.length;n<i;n++){const s=t[n];xi.setFromBufferAttribute(s),this.morphTargetsRelative?(wn.addVectors(this.boundingBox.min,xi.min),this.boundingBox.expandByPoint(wn),wn.addVectors(this.boundingBox.max,xi.max),this.boundingBox.expandByPoint(wn)):(this.boundingBox.expandByPoint(xi.min),this.boundingBox.expandByPoint(xi.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&ce('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 Fc);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){ce("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new P,1/0);return}if(e){const n=this.boundingSphere.center;if(xi.setFromBufferAttribute(e),t)for(let s=0,o=t.length;s<o;s++){const a=t[s];bl.setFromBufferAttribute(a),this.morphTargetsRelative?(wn.addVectors(xi.min,bl.min),xi.expandByPoint(wn),wn.addVectors(xi.max,bl.max),xi.expandByPoint(wn)):(xi.expandByPoint(bl.min),xi.expandByPoint(bl.max))}xi.getCenter(n);let i=0;for(let s=0,o=e.count;s<o;s++)wn.fromBufferAttribute(e,s),i=Math.max(i,n.distanceToSquared(wn));if(t)for(let s=0,o=t.length;s<o;s++){const a=t[s],l=this.morphTargetsRelative;for(let c=0,u=a.count;c<u;c++)wn.fromBufferAttribute(a,c),l&&($o.fromBufferAttribute(e,c),wn.add($o)),i=Math.max(i,n.distanceToSquared(wn))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&ce('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){ce("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const n=t.position,i=t.normal,s=t.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new Bn(new Float32Array(4*n.count),4));const o=this.getAttribute("tangent"),a=[],l=[];for(let v=0;v<n.count;v++)a[v]=new P,l[v]=new P;const c=new P,u=new P,h=new P,d=new pe,f=new pe,p=new pe,g=new P,m=new P;function _(v,w,N){c.fromBufferAttribute(n,v),u.fromBufferAttribute(n,w),h.fromBufferAttribute(n,N),d.fromBufferAttribute(s,v),f.fromBufferAttribute(s,w),p.fromBufferAttribute(s,N),u.sub(c),h.sub(c),f.sub(d),p.sub(d);const C=1/(f.x*p.y-p.x*f.y);isFinite(C)&&(g.copy(u).multiplyScalar(p.y).addScaledVector(h,-f.y).multiplyScalar(C),m.copy(h).multiplyScalar(f.x).addScaledVector(u,-p.x).multiplyScalar(C),a[v].add(g),a[w].add(g),a[N].add(g),l[v].add(m),l[w].add(m),l[N].add(m))}let x=this.groups;x.length===0&&(x=[{start:0,count:e.count}]);for(let v=0,w=x.length;v<w;++v){const N=x[v],C=N.start,F=N.count;for(let V=C,z=C+F;V<z;V+=3)_(e.getX(V+0),e.getX(V+1),e.getX(V+2))}const y=new P,b=new P,M=new P,S=new P;function E(v){M.fromBufferAttribute(i,v),S.copy(M);const w=a[v];y.copy(w),y.sub(M.multiplyScalar(M.dot(w))).normalize(),b.crossVectors(S,w);const C=b.dot(l[v])<0?-1:1;o.setXYZW(v,y.x,y.y,y.z,C)}for(let v=0,w=x.length;v<w;++v){const N=x[v],C=N.start,F=N.count;for(let V=C,z=C+F;V<z;V+=3)E(e.getX(V+0)),E(e.getX(V+1)),E(e.getX(V+2))}}computeVertexNormals(){const e=this.index,t=this.getAttribute("position");if(t!==void 0){let n=this.getAttribute("normal");if(n===void 0)n=new Bn(new Float32Array(t.count*3),3),this.setAttribute("normal",n);else for(let d=0,f=n.count;d<f;d++)n.setXYZ(d,0,0,0);const i=new P,s=new P,o=new P,a=new P,l=new P,c=new P,u=new P,h=new P;if(e)for(let d=0,f=e.count;d<f;d+=3){const p=e.getX(d+0),g=e.getX(d+1),m=e.getX(d+2);i.fromBufferAttribute(t,p),s.fromBufferAttribute(t,g),o.fromBufferAttribute(t,m),u.subVectors(o,s),h.subVectors(i,s),u.cross(h),a.fromBufferAttribute(n,p),l.fromBufferAttribute(n,g),c.fromBufferAttribute(n,m),a.add(u),l.add(u),c.add(u),n.setXYZ(p,a.x,a.y,a.z),n.setXYZ(g,l.x,l.y,l.z),n.setXYZ(m,c.x,c.y,c.z)}else for(let d=0,f=t.count;d<f;d+=3)i.fromBufferAttribute(t,d+0),s.fromBufferAttribute(t,d+1),o.fromBufferAttribute(t,d+2),u.subVectors(o,s),h.subVectors(i,s),u.cross(h),n.setXYZ(d+0,u.x,u.y,u.z),n.setXYZ(d+1,u.x,u.y,u.z),n.setXYZ(d+2,u.x,u.y,u.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){const e=this.attributes.normal;for(let t=0,n=e.count;t<n;t++)wn.fromBufferAttribute(e,t),wn.normalize(),e.setXYZ(t,wn.x,wn.y,wn.z)}toNonIndexed(){function e(a,l){const c=a.array,u=a.itemSize,h=a.normalized,d=new c.constructor(l.length*u);let f=0,p=0;for(let g=0,m=l.length;g<m;g++){a.isInterleavedBufferAttribute?f=l[g]*a.data.stride+a.offset:f=l[g]*u;for(let _=0;_<u;_++)d[p++]=c[f++]}return new Bn(d,u,h)}if(this.index===null)return ae("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const t=new An,n=this.index.array,i=this.attributes;for(const a in i){const l=i[a],c=e(l,n);t.setAttribute(a,c)}const s=this.morphAttributes;for(const a in s){const l=[],c=s[a];for(let u=0,h=c.length;u<h;u++){const d=c[u],f=e(d,n);l.push(f)}t.morphAttributes[a]=l}t.morphTargetsRelative=this.morphTargetsRelative;const o=this.groups;for(let a=0,l=o.length;a<l;a++){const c=o[a];t.addGroup(c.start,c.count,c.materialIndex)}return t}toJSON(){const e={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(e.uuid=this.uuid,e.type=this.type,this.name!==""&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0){const l=this.parameters;for(const c in l)l[c]!==void 0&&(e[c]=l[c]);return e}e.data={attributes:{}};const t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});const n=this.attributes;for(const l in n){const c=n[l];e.data.attributes[l]=c.toJSON(e.data)}const i={};let s=!1;for(const l in this.morphAttributes){const c=this.morphAttributes[l],u=[];for(let h=0,d=c.length;h<d;h++){const f=c[h];u.push(f.toJSON(e.data))}u.length>0&&(i[l]=u,s=!0)}s&&(e.data.morphAttributes=i,e.data.morphTargetsRelative=this.morphTargetsRelative);const o=this.groups;o.length>0&&(e.data.groups=JSON.parse(JSON.stringify(o)));const a=this.boundingSphere;return a!==null&&(e.data.boundingSphere=a.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const t={};this.name=e.name;const n=e.index;n!==null&&this.setIndex(n.clone());const i=e.attributes;for(const c in i){const u=i[c];this.setAttribute(c,u.clone(t))}const s=e.morphAttributes;for(const c in s){const u=[],h=s[c];for(let d=0,f=h.length;d<f;d++)u.push(h[d].clone(t));this.morphAttributes[c]=u}this.morphTargetsRelative=e.morphTargetsRelative;const o=e.groups;for(let c=0,u=o.length;c<u;c++){const h=o[c];this.addGroup(h.start,h.count,h.materialIndex)}const a=e.boundingBox;a!==null&&(this.boundingBox=a.clone());const l=e.boundingSphere;return l!==null&&(this.boundingSphere=l.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}class pm{constructor(e,t){this.isInterleavedBuffer=!0,this.array=e,this.stride=t,this.count=e!==void 0?e.length/t:0,this.usage=Ya,this.updateRanges=[],this.version=0,this.uuid=qr()}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.array=new e.array.constructor(e.array),this.count=e.count,this.stride=e.stride,this.usage=e.usage,this}copyAt(e,t,n){e*=this.stride,n*=t.stride;for(let i=0,s=this.stride;i<s;i++)this.array[e+i]=t.array[n+i];return this}set(e,t=0){return this.array.set(e,t),this}clone(e){e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=qr()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const t=new this.array.constructor(e.arrayBuffers[this.array.buffer._uuid]),n=new this.constructor(t,this.stride);return n.setUsage(this.usage),n}onUpload(e){return this.onUploadCallback=e,this}toJSON(e){return e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=qr()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.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 Zn=new P;class Tc{constructor(e,t,n,i=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=e,this.itemSize=t,this.offset=n,this.normalized=i}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(e){this.data.needsUpdate=e}applyMatrix4(e){for(let t=0,n=this.data.count;t<n;t++)Zn.fromBufferAttribute(this,t),Zn.applyMatrix4(e),this.setXYZ(t,Zn.x,Zn.y,Zn.z);return this}applyNormalMatrix(e){for(let t=0,n=this.count;t<n;t++)Zn.fromBufferAttribute(this,t),Zn.applyNormalMatrix(e),this.setXYZ(t,Zn.x,Zn.y,Zn.z);return this}transformDirection(e){for(let t=0,n=this.count;t<n;t++)Zn.fromBufferAttribute(this,t),Zn.transformDirection(e),this.setXYZ(t,Zn.x,Zn.y,Zn.z);return this}getComponent(e,t){let n=this.array[e*this.data.stride+this.offset+t];return this.normalized&&(n=ni(n,this.array)),n}setComponent(e,t,n){return this.normalized&&(n=lt(n,this.array)),this.data.array[e*this.data.stride+this.offset+t]=n,this}setX(e,t){return this.normalized&&(t=lt(t,this.array)),this.data.array[e*this.data.stride+this.offset]=t,this}setY(e,t){return this.normalized&&(t=lt(t,this.array)),this.data.array[e*this.data.stride+this.offset+1]=t,this}setZ(e,t){return this.normalized&&(t=lt(t,this.array)),this.data.array[e*this.data.stride+this.offset+2]=t,this}setW(e,t){return this.normalized&&(t=lt(t,this.array)),this.data.array[e*this.data.stride+this.offset+3]=t,this}getX(e){let t=this.data.array[e*this.data.stride+this.offset];return this.normalized&&(t=ni(t,this.array)),t}getY(e){let t=this.data.array[e*this.data.stride+this.offset+1];return this.normalized&&(t=ni(t,this.array)),t}getZ(e){let t=this.data.array[e*this.data.stride+this.offset+2];return this.normalized&&(t=ni(t,this.array)),t}getW(e){let t=this.data.array[e*this.data.stride+this.offset+3];return this.normalized&&(t=ni(t,this.array)),t}setXY(e,t,n){return e=e*this.data.stride+this.offset,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=n,this}setXYZ(e,t,n,i){return e=e*this.data.stride+this.offset,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array),i=lt(i,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=n,this.data.array[e+2]=i,this}setXYZW(e,t,n,i,s){return e=e*this.data.stride+this.offset,this.normalized&&(t=lt(t,this.array),n=lt(n,this.array),i=lt(i,this.array),s=lt(s,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=n,this.data.array[e+2]=i,this.data.array[e+3]=s,this}clone(e){if(e===void 0){Sc("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let n=0;n<this.count;n++){const i=n*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[i+s])}return new Bn(new this.array.constructor(t),this.itemSize,this.normalized)}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.clone(e)),new Tc(e.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(e){if(e===void 0){Sc("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let n=0;n<this.count;n++){const i=n*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[i+s])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.toJSON(e)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}let LT=0;class Yn extends Vi{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:LT++}),this.uuid=qr(),this.name="",this.type="Material",this.blending=ti,this.side=ri,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=oc,this.blendDst=ac,this.blendEquation=Xn,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new We(0,0,0),this.blendAlpha=0,this.depthFunc=Ds,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=np,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=eo,this.stencilZFail=eo,this.stencilZPass=eo,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(const t in e){const n=e[t];if(n===void 0){ae(`Material: parameter '${t}' has value of undefined.`);continue}const i=this[t];if(i===void 0){ae(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}i&&i.isColor?i.set(n):i&&i.isVector3&&n&&n.isVector3?i.copy(n):this[t]=n}}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});const n={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),this.roughness!==void 0&&(n.roughness=this.roughness),this.metalness!==void 0&&(n.metalness=this.metalness),this.sheen!==void 0&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(n.shininess=this.shininess),this.clearcoat!==void 0&&(n.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(n.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(n.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(n.dispersion=this.dispersion),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(n.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(e).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(e).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(e).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(e).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(e).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(n.combine=this.combine)),this.envMapRotation!==void 0&&(n.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(n.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(n.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.shadowSide!==null&&(n.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==ti&&(n.blending=this.blending),this.side!==ri&&(n.side=this.side),this.vertexColors===!0&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),this.transparent===!0&&(n.transparent=!0),this.blendSrc!==oc&&(n.blendSrc=this.blendSrc),this.blendDst!==ac&&(n.blendDst=this.blendDst),this.blendEquation!==Xn&&(n.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(n.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(n.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(n.blendAlpha=this.blendAlpha),this.depthFunc!==Ds&&(n.depthFunc=this.depthFunc),this.depthTest===!1&&(n.depthTest=this.depthTest),this.depthWrite===!1&&(n.depthWrite=this.depthWrite),this.colorWrite===!1&&(n.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(n.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==np&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==eo&&(n.stencilFail=this.stencilFail),this.stencilZFail!==eo&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==eo&&(n.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(n.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(n.rotation=this.rotation),this.polygonOffset===!0&&(n.polygonOffset=!0),this.polygonOffsetFactor!==0&&(n.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(n.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(n.linewidth=this.linewidth),this.dashSize!==void 0&&(n.dashSize=this.dashSize),this.gapSize!==void 0&&(n.gapSize=this.gapSize),this.scale!==void 0&&(n.scale=this.scale),this.dithering===!0&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),this.alphaHash===!0&&(n.alphaHash=!0),this.alphaToCoverage===!0&&(n.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(n.premultipliedAlpha=!0),this.forceSinglePass===!0&&(n.forceSinglePass=!0),this.allowOverride===!1&&(n.allowOverride=!1),this.wireframe===!0&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(n.flatShading=!0),this.visible===!1&&(n.visible=!1),this.toneMapped===!1&&(n.toneMapped=!1),this.fog===!1&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData);function i(s){const o=[];for(const a in s){const l=s[a];delete l.metadata,o.push(l)}return o}if(t){const s=i(e.textures),o=i(e.images);s.length>0&&(n.textures=s),o.length>0&&(n.images=o)}return n}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const t=e.clippingPlanes;let n=null;if(t!==null){const i=t.length;n=new Array(i);for(let s=0;s!==i;++s)n[s]=t[s].clone()}return this.clippingPlanes=n,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.allowOverride=e.allowOverride,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}}class mm extends Yn{constructor(e){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new We(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}let Xo;const Sl=new P,qo=new P,jo=new P,Yo=new pe,Tl=new pe,ty=new pt,iu=new P,Ml=new P,ru=new P,Ug=new pe,Ed=new pe,Fg=new pe;class UT extends pn{constructor(e=new mm){if(super(),this.isSprite=!0,this.type="Sprite",Xo===void 0){Xo=new An;const t=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),n=new pm(t,5);Xo.setIndex([0,1,2,0,2,3]),Xo.setAttribute("position",new Tc(n,3,0,!1)),Xo.setAttribute("uv",new Tc(n,2,3,!1))}this.geometry=Xo,this.material=e,this.center=new pe(.5,.5),this.count=1}raycast(e,t){e.camera===null&&ce('Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),qo.setFromMatrixScale(this.matrixWorld),ty.copy(e.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(e.camera.matrixWorldInverse,this.matrixWorld),jo.setFromMatrixPosition(this.modelViewMatrix),e.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&qo.multiplyScalar(-jo.z);const n=this.material.rotation;let i,s;n!==0&&(s=Math.cos(n),i=Math.sin(n));const o=this.center;su(iu.set(-.5,-.5,0),jo,o,qo,i,s),su(Ml.set(.5,-.5,0),jo,o,qo,i,s),su(ru.set(.5,.5,0),jo,o,qo,i,s),Ug.set(0,0),Ed.set(1,0),Fg.set(1,1);let a=e.ray.intersectTriangle(iu,Ml,ru,!1,Sl);if(a===null&&(su(Ml.set(-.5,.5,0),jo,o,qo,i,s),Ed.set(0,1),a=e.ray.intersectTriangle(iu,ru,Ml,!1,Sl),a===null))return;const l=e.ray.origin.distanceTo(Sl);l<e.near||l>e.far||t.push({distance:l,point:Sl.clone(),uv:Ni.getInterpolation(Sl,iu,Ml,ru,Ug,Ed,Fg,new pe),face:null,object:this})}copy(e,t){return super.copy(e,t),e.center!==void 0&&this.center.copy(e.center),this.material=e.material,this}}function su(r,e,t,n,i,s){Yo.subVectors(r,t).addScalar(.5).multiply(n),i!==void 0?(Tl.x=s*Yo.x-i*Yo.y,Tl.y=i*Yo.x+s*Yo.y):Tl.copy(Yo),r.copy(e),r.x+=Tl.x,r.y+=Tl.y,r.applyMatrix4(ty)}const Fr=new P,Ad=new P,ou=new P,ls=new P,wd=new P,au=new P,Rd=new P;class Bh{constructor(e=new P,t=new P(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,Fr)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);const n=t.dot(this.direction);return n<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const t=Fr.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(Fr.copy(this.origin).addScaledVector(this.direction,t),Fr.distanceToSquared(e))}distanceSqToSegment(e,t,n,i){Ad.copy(e).add(t).multiplyScalar(.5),ou.copy(t).sub(e).normalize(),ls.copy(this.origin).sub(Ad);const s=e.distanceTo(t)*.5,o=-this.direction.dot(ou),a=ls.dot(this.direction),l=-ls.dot(ou),c=ls.lengthSq(),u=Math.abs(1-o*o);let h,d,f,p;if(u>0)if(h=o*l-a,d=o*a-l,p=s*u,h>=0)if(d>=-p)if(d<=p){const g=1/u;h*=g,d*=g,f=h*(h+o*d+2*a)+d*(o*h+d+2*l)+c}else d=s,h=Math.max(0,-(o*d+a)),f=-h*h+d*(d+2*l)+c;else d=-s,h=Math.max(0,-(o*d+a)),f=-h*h+d*(d+2*l)+c;else d<=-p?(h=Math.max(0,-(-o*s+a)),d=h>0?-s:Math.min(Math.max(-s,-l),s),f=-h*h+d*(d+2*l)+c):d<=p?(h=0,d=Math.min(Math.max(-s,-l),s),f=d*(d+2*l)+c):(h=Math.max(0,-(o*s+a)),d=h>0?s:Math.min(Math.max(-s,-l),s),f=-h*h+d*(d+2*l)+c);else d=o>0?-s:s,h=Math.max(0,-(o*d+a)),f=-h*h+d*(d+2*l)+c;return n&&n.copy(this.origin).addScaledVector(this.direction,h),i&&i.copy(Ad).addScaledVector(ou,d),f}intersectSphere(e,t){Fr.subVectors(e.center,this.origin);const n=Fr.dot(this.direction),i=Fr.dot(Fr)-n*n,s=e.radius*e.radius;if(i>s)return null;const o=Math.sqrt(s-i),a=n-o,l=n+o;return l<0?null:a<0?this.at(l,t):this.at(a,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;const n=-(this.origin.dot(e.normal)+e.constant)/t;return n>=0?n:null}intersectPlane(e,t){const n=this.distanceToPlane(e);return n===null?null:this.at(n,t)}intersectsPlane(e){const t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let n,i,s,o,a,l;const c=1/this.direction.x,u=1/this.direction.y,h=1/this.direction.z,d=this.origin;return c>=0?(n=(e.min.x-d.x)*c,i=(e.max.x-d.x)*c):(n=(e.max.x-d.x)*c,i=(e.min.x-d.x)*c),u>=0?(s=(e.min.y-d.y)*u,o=(e.max.y-d.y)*u):(s=(e.max.y-d.y)*u,o=(e.min.y-d.y)*u),n>o||s>i||((s>n||isNaN(n))&&(n=s),(o<i||isNaN(i))&&(i=o),h>=0?(a=(e.min.z-d.z)*h,l=(e.max.z-d.z)*h):(a=(e.max.z-d.z)*h,l=(e.min.z-d.z)*h),n>l||a>i)||((a>n||n!==n)&&(n=a),(l<i||i!==i)&&(i=l),i<0)?null:this.at(n>=0?n:i,t)}intersectsBox(e){return this.intersectBox(e,Fr)!==null}intersectTriangle(e,t,n,i,s){wd.subVectors(t,e),au.subVectors(n,e),Rd.crossVectors(wd,au);let o=this.direction.dot(Rd),a;if(o>0){if(i)return null;a=1}else if(o<0)a=-1,o=-o;else return null;ls.subVectors(this.origin,e);const l=a*this.direction.dot(au.crossVectors(ls,au));if(l<0)return null;const c=a*this.direction.dot(wd.cross(ls));if(c<0||l+c>o)return null;const u=-a*ls.dot(Rd);return u<0?null:this.at(u/o,s)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class pr extends Yn{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new We(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Mr,this.combine=Nc,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}const Ig=new pt,js=new Bh,lu=new Fc,Bg=new P,cu=new P,uu=new P,hu=new P,Cd=new P,du=new P,Og=new P,fu=new P;class _n extends pn{constructor(e=new An,t=new pr){super(),this.isMesh=!0,this.type="Mesh",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){const t=this.geometry.morphAttributes,n=Object.keys(t);if(n.length>0){const i=t[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=i.length;s<o;s++){const a=i[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}getVertexPosition(e,t){const n=this.geometry,i=n.attributes.position,s=n.morphAttributes.position,o=n.morphTargetsRelative;t.fromBufferAttribute(i,e);const a=this.morphTargetInfluences;if(s&&a){du.set(0,0,0);for(let l=0,c=s.length;l<c;l++){const u=a[l],h=s[l];u!==0&&(Cd.fromBufferAttribute(h,e),o?du.addScaledVector(Cd,u):du.addScaledVector(Cd.sub(t),u))}t.add(du)}return t}raycast(e,t){const n=this.geometry,i=this.material,s=this.matrixWorld;i!==void 0&&(n.boundingSphere===null&&n.computeBoundingSphere(),lu.copy(n.boundingSphere),lu.applyMatrix4(s),js.copy(e.ray).recast(e.near),!(lu.containsPoint(js.origin)===!1&&(js.intersectSphere(lu,Bg)===null||js.origin.distanceToSquared(Bg)>(e.far-e.near)**2))&&(Ig.copy(s).invert(),js.copy(e.ray).applyMatrix4(Ig),!(n.boundingBox!==null&&js.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(e,t,js)))}_computeIntersections(e,t,n){let i;const s=this.geometry,o=this.material,a=s.index,l=s.attributes.position,c=s.attributes.uv,u=s.attributes.uv1,h=s.attributes.normal,d=s.groups,f=s.drawRange;if(a!==null)if(Array.isArray(o))for(let p=0,g=d.length;p<g;p++){const m=d[p],_=o[m.materialIndex],x=Math.max(m.start,f.start),y=Math.min(a.count,Math.min(m.start+m.count,f.start+f.count));for(let b=x,M=y;b<M;b+=3){const S=a.getX(b),E=a.getX(b+1),v=a.getX(b+2);i=pu(this,_,e,n,c,u,h,S,E,v),i&&(i.faceIndex=Math.floor(b/3),i.face.materialIndex=m.materialIndex,t.push(i))}}else{const p=Math.max(0,f.start),g=Math.min(a.count,f.start+f.count);for(let m=p,_=g;m<_;m+=3){const x=a.getX(m),y=a.getX(m+1),b=a.getX(m+2);i=pu(this,o,e,n,c,u,h,x,y,b),i&&(i.faceIndex=Math.floor(m/3),t.push(i))}}else if(l!==void 0)if(Array.isArray(o))for(let p=0,g=d.length;p<g;p++){const m=d[p],_=o[m.materialIndex],x=Math.max(m.start,f.start),y=Math.min(l.count,Math.min(m.start+m.count,f.start+f.count));for(let b=x,M=y;b<M;b+=3){const S=b,E=b+1,v=b+2;i=pu(this,_,e,n,c,u,h,S,E,v),i&&(i.faceIndex=Math.floor(b/3),i.face.materialIndex=m.materialIndex,t.push(i))}}else{const p=Math.max(0,f.start),g=Math.min(l.count,f.start+f.count);for(let m=p,_=g;m<_;m+=3){const x=m,y=m+1,b=m+2;i=pu(this,o,e,n,c,u,h,x,y,b),i&&(i.faceIndex=Math.floor(m/3),t.push(i))}}}}function FT(r,e,t,n,i,s,o,a){let l;if(e.side===Lt?l=n.intersectTriangle(o,s,i,!0,a):l=n.intersectTriangle(i,s,o,e.side===ri,a),l===null)return null;fu.copy(a),fu.applyMatrix4(r.matrixWorld);const c=t.ray.origin.distanceTo(fu);return c<t.near||c>t.far?null:{distance:c,point:fu.clone(),object:r}}function pu(r,e,t,n,i,s,o,a,l,c){r.getVertexPosition(a,cu),r.getVertexPosition(l,uu),r.getVertexPosition(c,hu);const u=FT(r,e,t,n,cu,uu,hu,Og);if(u){const h=new P;Ni.getBarycoord(Og,cu,uu,hu,h),i&&(u.uv=Ni.getInterpolatedAttribute(i,a,l,c,h,new pe)),s&&(u.uv1=Ni.getInterpolatedAttribute(s,a,l,c,h,new pe)),o&&(u.normal=Ni.getInterpolatedAttribute(o,a,l,c,h,new P),u.normal.dot(n.direction)>0&&u.normal.multiplyScalar(-1));const d={a,b:l,c,normal:new P,materialIndex:0};Ni.getNormal(cu,uu,hu,d.normal),u.face=d,u.barycoord=h}return u}class gm extends fn{constructor(e=null,t=1,n=1,i,s,o,a,l,c=Mt,u=Mt,h,d){super(null,o,a,l,c,u,i,s,h,d),this.isDataTexture=!0,this.image={data:e,width:t,height:n},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class IT extends Bn{constructor(e,t,n,i=1){super(e,t,n),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=i}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}toJSON(){const e=super.toJSON();return e.meshPerAttribute=this.meshPerAttribute,e.isInstancedBufferAttribute=!0,e}}const Nd=new P,BT=new P,OT=new Je;class ur{constructor(e=new P(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,n,i){return this.normal.set(e,t,n),this.constant=i,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,n){const i=Nd.subVectors(n,t).cross(BT.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(i,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){const e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t,n=!0){const i=e.delta(Nd),s=this.normal.dot(i);if(s===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;const o=-(e.start.dot(this.normal)+this.constant)/s;return n===!0&&(o<0||o>1)?null:t.copy(e.start).addScaledVector(i,o)}intersectsLine(e){const t=this.distanceToPoint(e.start),n=this.distanceToPoint(e.end);return t<0&&n>0||n<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){const n=t||OT.getNormalMatrix(e),i=this.coplanarPoint(Nd).applyMatrix4(e),s=this.normal.applyMatrix3(n).normalize();return this.constant=-i.dot(s),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}}const Ys=new Fc,kT=new pe(.5,.5),mu=new P;class Ic{constructor(e=new ur,t=new ur,n=new ur,i=new ur,s=new ur,o=new ur){this.planes=[e,t,n,i,s,o]}set(e,t,n,i,s,o){const a=this.planes;return a[0].copy(e),a[1].copy(t),a[2].copy(n),a[3].copy(i),a[4].copy(s),a[5].copy(o),this}copy(e){const t=this.planes;for(let n=0;n<6;n++)t[n].copy(e.planes[n]);return this}setFromProjectionMatrix(e,t=ii,n=!1){const i=this.planes,s=e.elements,o=s[0],a=s[1],l=s[2],c=s[3],u=s[4],h=s[5],d=s[6],f=s[7],p=s[8],g=s[9],m=s[10],_=s[11],x=s[12],y=s[13],b=s[14],M=s[15];if(i[0].setComponents(c-o,f-u,_-p,M-x).normalize(),i[1].setComponents(c+o,f+u,_+p,M+x).normalize(),i[2].setComponents(c+a,f+h,_+g,M+y).normalize(),i[3].setComponents(c-a,f-h,_-g,M-y).normalize(),n)i[4].setComponents(l,d,m,b).normalize(),i[5].setComponents(c-l,f-d,_-m,M-b).normalize();else if(i[4].setComponents(c-l,f-d,_-m,M-b).normalize(),t===ii)i[5].setComponents(c+l,f+d,_+m,M+b).normalize();else if(t===Tr)i[5].setComponents(l,d,m,b).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),Ys.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{const t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),Ys.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(Ys)}intersectsSprite(e){Ys.center.set(0,0,0);const t=kT.distanceTo(e.center);return Ys.radius=.7071067811865476+t,Ys.applyMatrix4(e.matrixWorld),this.intersectsSphere(Ys)}intersectsSphere(e){const t=this.planes,n=e.center,i=-e.radius;for(let s=0;s<6;s++)if(t[s].distanceToPoint(n)<i)return!1;return!0}intersectsBox(e){const t=this.planes;for(let n=0;n<6;n++){const i=t[n];if(mu.x=i.normal.x>0?e.max.x:e.min.x,mu.y=i.normal.y>0?e.max.y:e.min.y,mu.z=i.normal.z>0?e.max.z:e.min.z,i.distanceToPoint(mu)<0)return!1}return!0}containsPoint(e){const t=this.planes;for(let n=0;n<6;n++)if(t[n].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}const Ji=new pt,er=new Ic;class _m{constructor(){this.coordinateSystem=ii}intersectsObject(e,t){if(!t.isArrayCamera||t.cameras.length===0)return!1;for(let n=0;n<t.cameras.length;n++){const i=t.cameras[n];if(Ji.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),er.setFromProjectionMatrix(Ji,i.coordinateSystem,i.reversedDepth),er.intersectsObject(e))return!0}return!1}intersectsSprite(e,t){if(!t||!t.cameras||t.cameras.length===0)return!1;for(let n=0;n<t.cameras.length;n++){const i=t.cameras[n];if(Ji.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),er.setFromProjectionMatrix(Ji,i.coordinateSystem,i.reversedDepth),er.intersectsSprite(e))return!0}return!1}intersectsSphere(e,t){if(!t||!t.cameras||t.cameras.length===0)return!1;for(let n=0;n<t.cameras.length;n++){const i=t.cameras[n];if(Ji.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),er.setFromProjectionMatrix(Ji,i.coordinateSystem,i.reversedDepth),er.intersectsSphere(e))return!0}return!1}intersectsBox(e,t){if(!t||!t.cameras||t.cameras.length===0)return!1;for(let n=0;n<t.cameras.length;n++){const i=t.cameras[n];if(Ji.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),er.setFromProjectionMatrix(Ji,i.coordinateSystem,i.reversedDepth),er.intersectsBox(e))return!0}return!1}containsPoint(e,t){if(!t||!t.cameras||t.cameras.length===0)return!1;for(let n=0;n<t.cameras.length;n++){const i=t.cameras[n];if(Ji.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),er.setFromProjectionMatrix(Ji,i.coordinateSystem,i.reversedDepth),er.containsPoint(e))return!0}return!1}clone(){return new _m}}class Oh extends Yn{constructor(e){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new We(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.fog=e.fog,this}}const xh=new P,yh=new P,kg=new pt,El=new Bh,gu=new Fc,Pd=new P,Gg=new P;class GT extends pn{constructor(e=new An,t=new Oh){super(),this.isLine=!0,this.type="Line",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}computeLineDistances(){const e=this.geometry;if(e.index===null){const t=e.attributes.position,n=[0];for(let i=1,s=t.count;i<s;i++)xh.fromBufferAttribute(t,i-1),yh.fromBufferAttribute(t,i),n[i]=n[i-1],n[i]+=xh.distanceTo(yh);e.setAttribute("lineDistance",new sn(n,1))}else ae("Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(e,t){const n=this.geometry,i=this.matrixWorld,s=e.params.Line.threshold,o=n.drawRange;if(n.boundingSphere===null&&n.computeBoundingSphere(),gu.copy(n.boundingSphere),gu.applyMatrix4(i),gu.radius+=s,e.ray.intersectsSphere(gu)===!1)return;kg.copy(i).invert(),El.copy(e.ray).applyMatrix4(kg);const a=s/((this.scale.x+this.scale.y+this.scale.z)/3),l=a*a,c=this.isLineSegments?2:1,u=n.index,d=n.attributes.position;if(u!==null){const f=Math.max(0,o.start),p=Math.min(u.count,o.start+o.count);for(let g=f,m=p-1;g<m;g+=c){const _=u.getX(g),x=u.getX(g+1),y=_u(this,e,El,l,_,x,g);y&&t.push(y)}if(this.isLineLoop){const g=u.getX(p-1),m=u.getX(f),_=_u(this,e,El,l,g,m,p-1);_&&t.push(_)}}else{const f=Math.max(0,o.start),p=Math.min(d.count,o.start+o.count);for(let g=f,m=p-1;g<m;g+=c){const _=_u(this,e,El,l,g,g+1,g);_&&t.push(_)}if(this.isLineLoop){const g=_u(this,e,El,l,p-1,f,p-1);g&&t.push(g)}}}updateMorphTargets(){const t=this.geometry.morphAttributes,n=Object.keys(t);if(n.length>0){const i=t[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=i.length;s<o;s++){const a=i[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}}function _u(r,e,t,n,i,s,o){const a=r.geometry.attributes.position;if(xh.fromBufferAttribute(a,i),yh.fromBufferAttribute(a,s),t.distanceSqToSegment(xh,yh,Pd,Gg)>n)return;Pd.applyMatrix4(r.matrixWorld);const c=e.ray.origin.distanceTo(Pd);if(!(c<e.near||c>e.far))return{distance:c,point:Gg.clone().applyMatrix4(r.matrixWorld),index:o,face:null,faceIndex:null,barycoord:null,object:r}}class VT extends Yn{constructor(e){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new We(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.size=e.size,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}class ny extends fn{constructor(e,t){super({width:e,height:t}),this.isFramebufferTexture=!0,this.magFilter=Mt,this.minFilter=Mt,this.generateMipmaps=!1,this.needsUpdate=!0}}class sl extends fn{constructor(e=[],t=Ki,n,i,s,o,a,l,c,u){super(e,t,n,i,s,o,a,l,c,u),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}}class zT extends fn{constructor(e,t,n,i,s,o,a,l,c){super(e,t,n,i,s,o,a,l,c),this.isCanvasTexture=!0,this.needsUpdate=!0}}class jn extends fn{constructor(e,t,n=Ct,i,s,o,a=Mt,l=Mt,c,u=Dn,h=1){if(u!==Dn&&u!==qn)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const d={width:e,height:t,depth:h};super(d,i,s,o,a,l,u,n,c),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new am(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){const t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}}class iy extends jn{constructor(e,t=Ct,n=Ki,i,s,o=Mt,a=Mt,l,c=Dn){const u={width:e,height:e,depth:1},h=[u,u,u,u,u,u];super(e,e,t,n,i,s,o,a,l,c),this.image=h,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(e){this.image=e}}class ry extends fn{constructor(e=null){super(),this.sourceTexture=e,this.isExternalTexture=!0}copy(e){return super.copy(e),this.sourceTexture=e.sourceTexture,this}}class Co extends An{constructor(e=1,t=1,n=1,i=1,s=1,o=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:n,widthSegments:i,heightSegments:s,depthSegments:o};const a=this;i=Math.floor(i),s=Math.floor(s),o=Math.floor(o);const l=[],c=[],u=[],h=[];let d=0,f=0;p("z","y","x",-1,-1,n,t,e,o,s,0),p("z","y","x",1,-1,n,t,-e,o,s,1),p("x","z","y",1,1,e,n,t,i,o,2),p("x","z","y",1,-1,e,n,-t,i,o,3),p("x","y","z",1,-1,e,t,n,i,s,4),p("x","y","z",-1,-1,e,t,-n,i,s,5),this.setIndex(l),this.setAttribute("position",new sn(c,3)),this.setAttribute("normal",new sn(u,3)),this.setAttribute("uv",new sn(h,2));function p(g,m,_,x,y,b,M,S,E,v,w){const N=b/E,C=M/v,F=b/2,V=M/2,z=S/2,U=E+1,B=v+1;let D=0,X=0;const K=new P;for(let fe=0;fe<B;fe++){const Z=fe*C-V;for(let oe=0;oe<U;oe++){const Ee=oe*N-F;K[g]=Ee*x,K[m]=Z*y,K[_]=z,c.push(K.x,K.y,K.z),K[g]=0,K[m]=0,K[_]=S>0?1:-1,u.push(K.x,K.y,K.z),h.push(oe/E),h.push(1-fe/v),D+=1}}for(let fe=0;fe<v;fe++)for(let Z=0;Z<E;Z++){const oe=d+Z+U*fe,Ee=d+Z+U*(fe+1),ze=d+(Z+1)+U*(fe+1),$=d+(Z+1)+U*fe;l.push(oe,Ee,$),l.push(Ee,ze,$),X+=6}a.addGroup(f,X,w),f+=X,d+=D}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Co(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}}class Bc extends An{constructor(e=1,t=1,n=1,i=32,s=1,o=!1,a=0,l=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:e,radiusBottom:t,height:n,radialSegments:i,heightSegments:s,openEnded:o,thetaStart:a,thetaLength:l};const c=this;i=Math.floor(i),s=Math.floor(s);const u=[],h=[],d=[],f=[];let p=0;const g=[],m=n/2;let _=0;x(),o===!1&&(e>0&&y(!0),t>0&&y(!1)),this.setIndex(u),this.setAttribute("position",new sn(h,3)),this.setAttribute("normal",new sn(d,3)),this.setAttribute("uv",new sn(f,2));function x(){const b=new P,M=new P;let S=0;const E=(t-e)/n;for(let v=0;v<=s;v++){const w=[],N=v/s,C=N*(t-e)+e;for(let F=0;F<=i;F++){const V=F/i,z=V*l+a,U=Math.sin(z),B=Math.cos(z);M.x=C*U,M.y=-N*n+m,M.z=C*B,h.push(M.x,M.y,M.z),b.set(U,E,B).normalize(),d.push(b.x,b.y,b.z),f.push(V,1-N),w.push(p++)}g.push(w)}for(let v=0;v<i;v++)for(let w=0;w<s;w++){const N=g[w][v],C=g[w+1][v],F=g[w+1][v+1],V=g[w][v+1];(e>0||w!==0)&&(u.push(N,C,V),S+=3),(t>0||w!==s-1)&&(u.push(C,F,V),S+=3)}c.addGroup(_,S,0),_+=S}function y(b){const M=p,S=new pe,E=new P;let v=0;const w=b===!0?e:t,N=b===!0?1:-1;for(let F=1;F<=i;F++)h.push(0,m*N,0),d.push(0,N,0),f.push(.5,.5),p++;const C=p;for(let F=0;F<=i;F++){const z=F/i*l+a,U=Math.cos(z),B=Math.sin(z);E.x=w*B,E.y=m*N,E.z=w*U,h.push(E.x,E.y,E.z),d.push(0,N,0),S.x=U*.5+.5,S.y=B*.5*N+.5,f.push(S.x,S.y),p++}for(let F=0;F<i;F++){const V=M+F,z=C+F;b===!0?u.push(z,z+1,V):u.push(z+1,z,V),v+=3}c.addGroup(_,v,b===!0?1:2),_+=v}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Bc(e.radiusTop,e.radiusBottom,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class xm extends Bc{constructor(e=1,t=1,n=32,i=1,s=!1,o=0,a=Math.PI*2){super(0,e,t,n,i,s,o,a),this.type="ConeGeometry",this.parameters={radius:e,height:t,radialSegments:n,heightSegments:i,openEnded:s,thetaStart:o,thetaLength:a}}static fromJSON(e){return new xm(e.radius,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class Jr{constructor(){this.type="Curve",this.arcLengthDivisions=200,this.needsUpdate=!1,this.cacheArcLengths=null}getPoint(){ae("Curve: .getPoint() not implemented.")}getPointAt(e,t){const n=this.getUtoTmapping(e);return this.getPoint(n,t)}getPoints(e=5){const t=[];for(let n=0;n<=e;n++)t.push(this.getPoint(n/e));return t}getSpacedPoints(e=5){const t=[];for(let n=0;n<=e;n++)t.push(this.getPointAt(n/e));return t}getLength(){const e=this.getLengths();return e[e.length-1]}getLengths(e=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const t=[];let n,i=this.getPoint(0),s=0;t.push(0);for(let o=1;o<=e;o++)n=this.getPoint(o/e),s+=n.distanceTo(i),t.push(s),i=n;return this.cacheArcLengths=t,t}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(e,t=null){const n=this.getLengths();let i=0;const s=n.length;let o;t?o=t:o=e*n[s-1];let a=0,l=s-1,c;for(;a<=l;)if(i=Math.floor(a+(l-a)/2),c=n[i]-o,c<0)a=i+1;else if(c>0)l=i-1;else{l=i;break}if(i=l,n[i]===o)return i/(s-1);const u=n[i],d=n[i+1]-u,f=(o-u)/d;return(i+f)/(s-1)}getTangent(e,t){let i=e-1e-4,s=e+1e-4;i<0&&(i=0),s>1&&(s=1);const o=this.getPoint(i),a=this.getPoint(s),l=t||(o.isVector2?new pe:new P);return l.copy(a).sub(o).normalize(),l}getTangentAt(e,t){const n=this.getUtoTmapping(e);return this.getTangent(n,t)}computeFrenetFrames(e,t=!1){const n=new P,i=[],s=[],o=[],a=new P,l=new pt;for(let f=0;f<=e;f++){const p=f/e;i[f]=this.getTangentAt(p,new P)}s[0]=new P,o[0]=new P;let c=Number.MAX_VALUE;const u=Math.abs(i[0].x),h=Math.abs(i[0].y),d=Math.abs(i[0].z);u<=c&&(c=u,n.set(1,0,0)),h<=c&&(c=h,n.set(0,1,0)),d<=c&&n.set(0,0,1),a.crossVectors(i[0],n).normalize(),s[0].crossVectors(i[0],a),o[0].crossVectors(i[0],s[0]);for(let f=1;f<=e;f++){if(s[f]=s[f-1].clone(),o[f]=o[f-1].clone(),a.crossVectors(i[f-1],i[f]),a.length()>Number.EPSILON){a.normalize();const p=Math.acos(ct(i[f-1].dot(i[f]),-1,1));s[f].applyMatrix4(l.makeRotationAxis(a,p))}o[f].crossVectors(i[f],s[f])}if(t===!0){let f=Math.acos(ct(s[0].dot(s[e]),-1,1));f/=e,i[0].dot(a.crossVectors(s[0],s[e]))>0&&(f=-f);for(let p=1;p<=e;p++)s[p].applyMatrix4(l.makeRotationAxis(i[p],f*p)),o[p].crossVectors(i[p],s[p])}return{tangents:i,normals:s,binormals:o}}clone(){return new this.constructor().copy(this)}copy(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}toJSON(){const e={metadata:{version:4.7,type:"Curve",generator:"Curve.toJSON"}};return e.arcLengthDivisions=this.arcLengthDivisions,e.type=this.type,e}fromJSON(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}}class sy extends Jr{constructor(e=0,t=0,n=1,i=1,s=0,o=Math.PI*2,a=!1,l=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=e,this.aY=t,this.xRadius=n,this.yRadius=i,this.aStartAngle=s,this.aEndAngle=o,this.aClockwise=a,this.aRotation=l}getPoint(e,t=new pe){const n=t,i=Math.PI*2;let s=this.aEndAngle-this.aStartAngle;const o=Math.abs(s)<Number.EPSILON;for(;s<0;)s+=i;for(;s>i;)s-=i;s<Number.EPSILON&&(o?s=0:s=i),this.aClockwise===!0&&!o&&(s===i?s=-i:s=s-i);const a=this.aStartAngle+e*s;let l=this.aX+this.xRadius*Math.cos(a),c=this.aY+this.yRadius*Math.sin(a);if(this.aRotation!==0){const u=Math.cos(this.aRotation),h=Math.sin(this.aRotation),d=l-this.aX,f=c-this.aY;l=d*u-f*h+this.aX,c=d*h+f*u+this.aY}return n.set(l,c)}copy(e){return super.copy(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}toJSON(){const e=super.toJSON();return e.aX=this.aX,e.aY=this.aY,e.xRadius=this.xRadius,e.yRadius=this.yRadius,e.aStartAngle=this.aStartAngle,e.aEndAngle=this.aEndAngle,e.aClockwise=this.aClockwise,e.aRotation=this.aRotation,e}fromJSON(e){return super.fromJSON(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}}class HT extends sy{constructor(e,t,n,i,s,o){super(e,t,n,n,i,s,o),this.isArcCurve=!0,this.type="ArcCurve"}}function ym(){let r=0,e=0,t=0,n=0;function i(s,o,a,l){r=s,e=a,t=-3*s+3*o-2*a-l,n=2*s-2*o+a+l}return{initCatmullRom:function(s,o,a,l,c){i(o,a,c*(a-s),c*(l-o))},initNonuniformCatmullRom:function(s,o,a,l,c,u,h){let d=(o-s)/c-(a-s)/(c+u)+(a-o)/u,f=(a-o)/u-(l-o)/(u+h)+(l-a)/h;d*=u,f*=u,i(o,a,d,f)},calc:function(s){const o=s*s,a=o*s;return r+e*s+t*o+n*a}}}const Vg=new P,zg=new P,Dd=new ym,Ld=new ym,Ud=new ym;class WT extends Jr{constructor(e=[],t=!1,n="centripetal",i=.5){super(),this.isCatmullRomCurve3=!0,this.type="CatmullRomCurve3",this.points=e,this.closed=t,this.curveType=n,this.tension=i}getPoint(e,t=new P){const n=t,i=this.points,s=i.length,o=(s-(this.closed?0:1))*e;let a=Math.floor(o),l=o-a;this.closed?a+=a>0?0:(Math.floor(Math.abs(a)/s)+1)*s:l===0&&a===s-1&&(a=s-2,l=1);let c,u;this.closed||a>0?c=i[(a-1)%s]:(zg.subVectors(i[0],i[1]).add(i[0]),c=zg);const h=i[a%s],d=i[(a+1)%s];if(this.closed||a+2<s?u=i[(a+2)%s]:(Vg.subVectors(i[s-1],i[s-2]).add(i[s-1]),u=Vg),this.curveType==="centripetal"||this.curveType==="chordal"){const f=this.curveType==="chordal"?.5:.25;let p=Math.pow(c.distanceToSquared(h),f),g=Math.pow(h.distanceToSquared(d),f),m=Math.pow(d.distanceToSquared(u),f);g<1e-4&&(g=1),p<1e-4&&(p=g),m<1e-4&&(m=g),Dd.initNonuniformCatmullRom(c.x,h.x,d.x,u.x,p,g,m),Ld.initNonuniformCatmullRom(c.y,h.y,d.y,u.y,p,g,m),Ud.initNonuniformCatmullRom(c.z,h.z,d.z,u.z,p,g,m)}else this.curveType==="catmullrom"&&(Dd.initCatmullRom(c.x,h.x,d.x,u.x,this.tension),Ld.initCatmullRom(c.y,h.y,d.y,u.y,this.tension),Ud.initCatmullRom(c.z,h.z,d.z,u.z,this.tension));return n.set(Dd.calc(l),Ld.calc(l),Ud.calc(l)),n}copy(e){super.copy(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){const i=e.points[t];this.points.push(i.clone())}return this.closed=e.closed,this.curveType=e.curveType,this.tension=e.tension,this}toJSON(){const e=super.toJSON();e.points=[];for(let t=0,n=this.points.length;t<n;t++){const i=this.points[t];e.points.push(i.toArray())}return e.closed=this.closed,e.curveType=this.curveType,e.tension=this.tension,e}fromJSON(e){super.fromJSON(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){const i=e.points[t];this.points.push(new P().fromArray(i))}return this.closed=e.closed,this.curveType=e.curveType,this.tension=e.tension,this}}function Hg(r,e,t,n,i){const s=(n-e)*.5,o=(i-t)*.5,a=r*r,l=r*a;return(2*t-2*n+s+o)*l+(-3*t+3*n-2*s-o)*a+s*r+t}function $T(r,e){const t=1-r;return t*t*e}function XT(r,e){return 2*(1-r)*r*e}function qT(r,e){return r*r*e}function Yl(r,e,t,n){return $T(r,e)+XT(r,t)+qT(r,n)}function jT(r,e){const t=1-r;return t*t*t*e}function YT(r,e){const t=1-r;return 3*t*t*r*e}function KT(r,e){return 3*(1-r)*r*r*e}function ZT(r,e){return r*r*r*e}function Kl(r,e,t,n,i){return jT(r,e)+YT(r,t)+KT(r,n)+ZT(r,i)}class QT extends Jr{constructor(e=new pe,t=new pe,n=new pe,i=new pe){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=e,this.v1=t,this.v2=n,this.v3=i}getPoint(e,t=new pe){const n=t,i=this.v0,s=this.v1,o=this.v2,a=this.v3;return n.set(Kl(e,i.x,s.x,o.x,a.x),Kl(e,i.y,s.y,o.y,a.y)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e.v3=this.v3.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this.v3.fromArray(e.v3),this}}class oy extends Jr{constructor(e=new P,t=new P,n=new P,i=new P){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=e,this.v1=t,this.v2=n,this.v3=i}getPoint(e,t=new P){const n=t,i=this.v0,s=this.v1,o=this.v2,a=this.v3;return n.set(Kl(e,i.x,s.x,o.x,a.x),Kl(e,i.y,s.y,o.y,a.y),Kl(e,i.z,s.z,o.z,a.z)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e.v3=this.v3.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this.v3.fromArray(e.v3),this}}class JT extends Jr{constructor(e=new pe,t=new pe){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=e,this.v2=t}getPoint(e,t=new pe){const n=t;return e===1?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(e).add(this.v1)),n}getPointAt(e,t){return this.getPoint(e,t)}getTangent(e,t=new pe){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t){return this.getTangent(e,t)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class eM extends Jr{constructor(e=new P,t=new P){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=e,this.v2=t}getPoint(e,t=new P){const n=t;return e===1?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(e).add(this.v1)),n}getPointAt(e,t){return this.getPoint(e,t)}getTangent(e,t=new P){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t){return this.getTangent(e,t)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class tM extends Jr{constructor(e=new pe,t=new pe,n=new pe){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=e,this.v1=t,this.v2=n}getPoint(e,t=new pe){const n=t,i=this.v0,s=this.v1,o=this.v2;return n.set(Yl(e,i.x,s.x,o.x),Yl(e,i.y,s.y,o.y)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class vm extends Jr{constructor(e=new P,t=new P,n=new P){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=e,this.v1=t,this.v2=n}getPoint(e,t=new P){const n=t,i=this.v0,s=this.v1,o=this.v2;return n.set(Yl(e,i.x,s.x,o.x),Yl(e,i.y,s.y,o.y),Yl(e,i.z,s.z,o.z)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class nM extends Jr{constructor(e=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=e}getPoint(e,t=new pe){const n=t,i=this.points,s=(i.length-1)*e,o=Math.floor(s),a=s-o,l=i[o===0?o:o-1],c=i[o],u=i[o>i.length-2?i.length-1:o+1],h=i[o>i.length-3?i.length-1:o+2];return n.set(Hg(a,l.x,c.x,u.x,h.x),Hg(a,l.y,c.y,u.y,h.y)),n}copy(e){super.copy(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){const i=e.points[t];this.points.push(i.clone())}return this}toJSON(){const e=super.toJSON();e.points=[];for(let t=0,n=this.points.length;t<n;t++){const i=this.points[t];e.points.push(i.toArray())}return e}fromJSON(e){super.fromJSON(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){const i=e.points[t];this.points.push(new pe().fromArray(i))}return this}}var iM=Object.freeze({__proto__:null,ArcCurve:HT,CatmullRomCurve3:WT,CubicBezierCurve:QT,CubicBezierCurve3:oy,EllipseCurve:sy,LineCurve:JT,LineCurve3:eM,QuadraticBezierCurve:tM,QuadraticBezierCurve3:vm,SplineCurve:nM});class Oc extends An{constructor(e=1,t=1,n=1,i=1){super(),this.type="PlaneGeometry",this.parameters={width:e,height:t,widthSegments:n,heightSegments:i};const s=e/2,o=t/2,a=Math.floor(n),l=Math.floor(i),c=a+1,u=l+1,h=e/a,d=t/l,f=[],p=[],g=[],m=[];for(let _=0;_<u;_++){const x=_*d-o;for(let y=0;y<c;y++){const b=y*h-s;p.push(b,-x,0),g.push(0,0,1),m.push(y/a),m.push(1-_/l)}}for(let _=0;_<l;_++)for(let x=0;x<a;x++){const y=x+c*_,b=x+c*(_+1),M=x+1+c*(_+1),S=x+1+c*_;f.push(y,b,S),f.push(b,M,S)}this.setIndex(f),this.setAttribute("position",new sn(p,3)),this.setAttribute("normal",new sn(g,3)),this.setAttribute("uv",new sn(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Oc(e.width,e.height,e.widthSegments,e.heightSegments)}}class kc extends An{constructor(e=1,t=32,n=16,i=0,s=Math.PI*2,o=0,a=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:e,widthSegments:t,heightSegments:n,phiStart:i,phiLength:s,thetaStart:o,thetaLength:a},t=Math.max(3,Math.floor(t)),n=Math.max(2,Math.floor(n));const l=Math.min(o+a,Math.PI);let c=0;const u=[],h=new P,d=new P,f=[],p=[],g=[],m=[];for(let _=0;_<=n;_++){const x=[],y=_/n;let b=0;_===0&&o===0?b=.5/t:_===n&&l===Math.PI&&(b=-.5/t);for(let M=0;M<=t;M++){const S=M/t;h.x=-e*Math.cos(i+S*s)*Math.sin(o+y*a),h.y=e*Math.cos(o+y*a),h.z=e*Math.sin(i+S*s)*Math.sin(o+y*a),p.push(h.x,h.y,h.z),d.copy(h).normalize(),g.push(d.x,d.y,d.z),m.push(S+b,1-y),x.push(c++)}u.push(x)}for(let _=0;_<n;_++)for(let x=0;x<t;x++){const y=u[_][x+1],b=u[_][x],M=u[_+1][x],S=u[_+1][x+1];(_!==0||o>0)&&f.push(y,b,S),(_!==n-1||l<Math.PI)&&f.push(b,M,S)}this.setIndex(f),this.setAttribute("position",new sn(p,3)),this.setAttribute("normal",new sn(g,3)),this.setAttribute("uv",new sn(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new kc(e.radius,e.widthSegments,e.heightSegments,e.phiStart,e.phiLength,e.thetaStart,e.thetaLength)}}class bm extends An{constructor(e=new vm(new P(-1,-1,0),new P(-1,1,0),new P(1,1,0)),t=64,n=1,i=8,s=!1){super(),this.type="TubeGeometry",this.parameters={path:e,tubularSegments:t,radius:n,radialSegments:i,closed:s};const o=e.computeFrenetFrames(t,s);this.tangents=o.tangents,this.normals=o.normals,this.binormals=o.binormals;const a=new P,l=new P,c=new pe;let u=new P;const h=[],d=[],f=[],p=[];g(),this.setIndex(p),this.setAttribute("position",new sn(h,3)),this.setAttribute("normal",new sn(d,3)),this.setAttribute("uv",new sn(f,2));function g(){for(let y=0;y<t;y++)m(y);m(s===!1?t:0),x(),_()}function m(y){u=e.getPointAt(y/t,u);const b=o.normals[y],M=o.binormals[y];for(let S=0;S<=i;S++){const E=S/i*Math.PI*2,v=Math.sin(E),w=-Math.cos(E);l.x=w*b.x+v*M.x,l.y=w*b.y+v*M.y,l.z=w*b.z+v*M.z,l.normalize(),d.push(l.x,l.y,l.z),a.x=u.x+n*l.x,a.y=u.y+n*l.y,a.z=u.z+n*l.z,h.push(a.x,a.y,a.z)}}function _(){for(let y=1;y<=t;y++)for(let b=1;b<=i;b++){const M=(i+1)*(y-1)+(b-1),S=(i+1)*y+(b-1),E=(i+1)*y+b,v=(i+1)*(y-1)+b;p.push(M,S,v),p.push(S,E,v)}}function x(){for(let y=0;y<=t;y++)for(let b=0;b<=i;b++)c.x=y/t,c.y=b/i,f.push(c.x,c.y)}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){const e=super.toJSON();return e.path=this.parameters.path.toJSON(),e}static fromJSON(e){return new bm(new iM[e.path.type]().fromJSON(e.path),e.tubularSegments,e.radius,e.radialSegments,e.closed)}}class rM extends Yn{constructor(e){super(),this.isShadowMaterial=!0,this.type="ShadowMaterial",this.color=new We(0),this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.fog=e.fog,this}}function Ka(r){const e={};for(const t in r){e[t]={};for(const n in r[t]){const i=r[t][n];if(Wg(i))i.isRenderTargetTexture?(ae("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),e[t][n]=null):e[t][n]=i.clone();else if(Array.isArray(i))if(Wg(i[0])){const s=[];for(let o=0,a=i.length;o<a;o++)s[o]=i[o].clone();e[t][n]=s}else e[t][n]=i.slice();else e[t][n]=i}}return e}function Qn(r){const e={};for(let t=0;t<r.length;t++){const n=Ka(r[t]);for(const i in n)e[i]=n[i]}return e}function Wg(r){return r&&(r.isColor||r.isMatrix3||r.isMatrix4||r.isVector2||r.isVector3||r.isVector4||r.isTexture||r.isQuaternion)}function sM(r){const e=[];for(let t=0;t<r.length;t++)e.push(r[t].clone());return e}function ay(r){const e=r.getRenderTarget();return e===null?r.outputColorSpace:e.isXRRenderTarget===!0?e.texture.colorSpace:Ye.workingColorSpace}const ly={clone:Ka,merge:Qn};var oM=`void main() {
6
6
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
7
7
  }`,aM=`void main() {
8
8
  gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
9
- }`;class ki extends Yn{constructor(e){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=oM,this.fragmentShader=aM,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,e!==void 0&&this.setValues(e)}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=Ka(e.uniforms),this.uniformsGroups=sM(e.uniformsGroups),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.fog=e.fog,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this.defaultAttributeValues=Object.assign({},e.defaultAttributeValues),this.index0AttributeName=e.index0AttributeName,this.uniformsNeedUpdate=e.uniformsNeedUpdate,this}toJSON(e){const t=super.toJSON(e);t.glslVersion=this.glslVersion,t.uniforms={};for(const i in this.uniforms){const o=this.uniforms[i].value;o&&o.isTexture?t.uniforms[i]={type:"t",value:o.toJSON(e).uuid}:o&&o.isColor?t.uniforms[i]={type:"c",value:o.getHex()}:o&&o.isVector2?t.uniforms[i]={type:"v2",value:o.toArray()}:o&&o.isVector3?t.uniforms[i]={type:"v3",value:o.toArray()}:o&&o.isVector4?t.uniforms[i]={type:"v4",value:o.toArray()}:o&&o.isMatrix3?t.uniforms[i]={type:"m3",value:o.toArray()}:o&&o.isMatrix4?t.uniforms[i]={type:"m4",value:o.toArray()}:t.uniforms[i]={value:o}}Object.keys(this.defines).length>0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;const n={};for(const i in this.extensions)this.extensions[i]===!0&&(n[i]=!0);return Object.keys(n).length>0&&(t.extensions=n),t}}class lM extends ki{constructor(e){super(e),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class cy extends Yn{constructor(e){super(),this.isMeshStandardMaterial=!0,this.type="MeshStandardMaterial",this.defines={STANDARD:""},this.color=new We(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new We(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ji,this.normalScale=new pe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Mr,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={STANDARD:""},this.color.copy(e.color),this.roughness=e.roughness,this.metalness=e.metalness,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.roughnessMap=e.roughnessMap,this.metalnessMap=e.metalnessMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.envMapIntensity=e.envMapIntensity,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class cM extends cy{constructor(e){super(),this.isMeshPhysicalMaterial=!0,this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.anisotropyRotation=0,this.anisotropyMap=null,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new pe(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return ct(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(t){this.ior=(1+.4*t)/(1-.4*t)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessRange=[100,400],this.iridescenceThicknessMap=null,this.sheenColor=new We(0),this.sheenColorMap=null,this.sheenRoughness=1,this.sheenRoughnessMap=null,this.transmissionMap=null,this.thickness=0,this.thicknessMap=null,this.attenuationDistance=1/0,this.attenuationColor=new We(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new We(1,1,1),this.specularColorMap=null,this._anisotropy=0,this._clearcoat=0,this._dispersion=0,this._iridescence=0,this._sheen=0,this._transmission=0,this.setValues(e)}get anisotropy(){return this._anisotropy}set anisotropy(e){this._anisotropy>0!=e>0&&this.version++,this._anisotropy=e}get clearcoat(){return this._clearcoat}set clearcoat(e){this._clearcoat>0!=e>0&&this.version++,this._clearcoat=e}get iridescence(){return this._iridescence}set iridescence(e){this._iridescence>0!=e>0&&this.version++,this._iridescence=e}get dispersion(){return this._dispersion}set dispersion(e){this._dispersion>0!=e>0&&this.version++,this._dispersion=e}get sheen(){return this._sheen}set sheen(e){this._sheen>0!=e>0&&this.version++,this._sheen=e}get transmission(){return this._transmission}set transmission(e){this._transmission>0!=e>0&&this.version++,this._transmission=e}copy(e){return super.copy(e),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=e.anisotropy,this.anisotropyRotation=e.anisotropyRotation,this.anisotropyMap=e.anisotropyMap,this.clearcoat=e.clearcoat,this.clearcoatMap=e.clearcoatMap,this.clearcoatRoughness=e.clearcoatRoughness,this.clearcoatRoughnessMap=e.clearcoatRoughnessMap,this.clearcoatNormalMap=e.clearcoatNormalMap,this.clearcoatNormalScale.copy(e.clearcoatNormalScale),this.dispersion=e.dispersion,this.ior=e.ior,this.iridescence=e.iridescence,this.iridescenceMap=e.iridescenceMap,this.iridescenceIOR=e.iridescenceIOR,this.iridescenceThicknessRange=[...e.iridescenceThicknessRange],this.iridescenceThicknessMap=e.iridescenceThicknessMap,this.sheen=e.sheen,this.sheenColor.copy(e.sheenColor),this.sheenColorMap=e.sheenColorMap,this.sheenRoughness=e.sheenRoughness,this.sheenRoughnessMap=e.sheenRoughnessMap,this.transmission=e.transmission,this.transmissionMap=e.transmissionMap,this.thickness=e.thickness,this.thicknessMap=e.thicknessMap,this.attenuationDistance=e.attenuationDistance,this.attenuationColor.copy(e.attenuationColor),this.specularIntensity=e.specularIntensity,this.specularIntensityMap=e.specularIntensityMap,this.specularColor.copy(e.specularColor),this.specularColorMap=e.specularColorMap,this}}class uM extends Yn{constructor(e){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new We(16777215),this.specular=new We(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new We(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ji,this.normalScale=new pe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Mr,this.combine=Nc,this.reflectivity=1,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.specular.copy(e.specular),this.shininess=e.shininess,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.envMapIntensity=e.envMapIntensity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class hM extends Yn{constructor(e){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new We(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new We(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ji,this.normalScale=new pe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.gradientMap=e.gradientMap,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}class dM extends Yn{constructor(e){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ji,this.normalScale=new pe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(e)}copy(e){return super.copy(e),this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this}}class uy extends Yn{constructor(e){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new We(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new We(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ji,this.normalScale=new pe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Mr,this.combine=Nc,this.reflectivity=1,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.envMapIntensity=e.envMapIntensity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class fM extends Yn{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=BS,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}}class pM extends Yn{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}}class mM extends Yn{constructor(e){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new We(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ji,this.normalScale=new pe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={MATCAP:""},this.color.copy(e.color),this.matcap=e.matcap,this.map=e.map,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this.fog=e.fog,this}}class gM extends Oh{constructor(e){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(e)}copy(e){return super.copy(e),this.scale=e.scale,this.dashSize=e.dashSize,this.gapSize=e.gapSize,this}}const Fd={enabled:!1,files:{},add:function(r,e){this.enabled!==!1&&($g(r)||(this.files[r]=e))},get:function(r){if(this.enabled!==!1&&!$g(r))return this.files[r]},remove:function(r){delete this.files[r]},clear:function(){this.files={}}};function $g(r){try{const e=r.slice(r.indexOf(":")+1);return new URL(e).protocol==="blob:"}catch{return!1}}class _M{constructor(e,t,n){const i=this;let s=!1,o=0,a=0,l;const c=[];this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=n,this._abortController=null,this.itemStart=function(u){a++,s===!1&&i.onStart!==void 0&&i.onStart(u,o,a),s=!0},this.itemEnd=function(u){o++,i.onProgress!==void 0&&i.onProgress(u,o,a),o===a&&(s=!1,i.onLoad!==void 0&&i.onLoad())},this.itemError=function(u){i.onError!==void 0&&i.onError(u)},this.resolveURL=function(u){return l?l(u):u},this.setURLModifier=function(u){return l=u,this},this.addHandler=function(u,h){return c.push(u,h),this},this.removeHandler=function(u){const h=c.indexOf(u);return h!==-1&&c.splice(h,2),this},this.getHandler=function(u){for(let h=0,d=c.length;h<d;h+=2){const f=c[h],p=c[h+1];if(f.global&&(f.lastIndex=0),f.test(u))return p}return null},this.abort=function(){return this.abortController.abort(),this._abortController=null,this}}get abortController(){return this._abortController||(this._abortController=new AbortController),this._abortController}}const xM=new _M;class Sm{constructor(e){this.manager=e!==void 0?e:xM,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}load(){}loadAsync(e,t){const n=this;return new Promise(function(i,s){n.load(e,i,t,s)})}parse(){}setCrossOrigin(e){return this.crossOrigin=e,this}setWithCredentials(e){return this.withCredentials=e,this}setPath(e){return this.path=e,this}setResourcePath(e){return this.resourcePath=e,this}setRequestHeader(e){return this.requestHeader=e,this}abort(){return this}}Sm.DEFAULT_MATERIAL_NAME="__DEFAULT";const Ko=new WeakMap;class yM extends Sm{constructor(e){super(e)}load(e,t,n,i){this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);const s=this,o=Fd.get(`image:${e}`);if(o!==void 0){if(o.complete===!0)s.manager.itemStart(e),setTimeout(function(){t&&t(o),s.manager.itemEnd(e)},0);else{let h=Ko.get(o);h===void 0&&(h=[],Ko.set(o,h)),h.push({onLoad:t,onError:i})}return o}const a=bc("img");function l(){u(),t&&t(this);const h=Ko.get(this)||[];for(let d=0;d<h.length;d++){const f=h[d];f.onLoad&&f.onLoad(this)}Ko.delete(this),s.manager.itemEnd(e)}function c(h){u(),i&&i(h),Fd.remove(`image:${e}`);const d=Ko.get(this)||[];for(let f=0;f<d.length;f++){const p=d[f];p.onError&&p.onError(h)}Ko.delete(this),s.manager.itemError(e),s.manager.itemEnd(e)}function u(){a.removeEventListener("load",l,!1),a.removeEventListener("error",c,!1)}return a.addEventListener("load",l,!1),a.addEventListener("error",c,!1),e.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(a.crossOrigin=this.crossOrigin),Fd.add(`image:${e}`,a),s.manager.itemStart(e),a.src=e,a}}class vM extends Sm{constructor(e){super(e)}load(e,t,n,i){const s=new fn,o=new yM(this.manager);return o.setCrossOrigin(this.crossOrigin),o.setPath(this.path),o.load(e,function(a){s.image=a,s.needsUpdate=!0,t!==void 0&&t(s)},n,i),s}}class No extends pn{constructor(e,t=1){super(),this.isLight=!0,this.type="Light",this.color=new We(e),this.intensity=t}dispose(){this.dispatchEvent({type:"dispose"})}copy(e,t){return super.copy(e,t),this.color.copy(e.color),this.intensity=e.intensity,this}toJSON(e){const t=super.toJSON(e);return t.object.color=this.color.getHex(),t.object.intensity=this.intensity,t}}class bM extends No{constructor(e,t,n){super(e,n),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(pn.DEFAULT_UP),this.updateMatrix(),this.groundColor=new We(t)}copy(e,t){return super.copy(e,t),this.groundColor.copy(e.groundColor),this}toJSON(e){const t=super.toJSON(e);return t.object.groundColor=this.groundColor.getHex(),t}}const Id=new pt,Xg=new P,qg=new P;class Tm{constructor(e){this.camera=e,this.intensity=1,this.bias=0,this.biasNode=null,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new pe(512,512),this.mapType=Xt,this.map=null,this.mapPass=null,this.matrix=new pt,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new Ic,this._frameExtents=new pe(1,1),this._viewportCount=1,this._viewports=[new rt(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(e){const t=this.camera,n=this.matrix;Xg.setFromMatrixPosition(e.matrixWorld),t.position.copy(Xg),qg.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(qg),t.updateMatrixWorld(),Id.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Id,t.coordinateSystem,t.reversedDepth),t.coordinateSystem===Tr||t.reversedDepth?n.set(.5,0,0,.5,0,.5,0,.5,0,0,1,0,0,0,0,1):n.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),n.multiply(Id)}getViewport(e){return this._viewports[e]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(e){return this.camera=e.camera.clone(),this.intensity=e.intensity,this.bias=e.bias,this.radius=e.radius,this.autoUpdate=e.autoUpdate,this.needsUpdate=e.needsUpdate,this.normalBias=e.normalBias,this.blurSamples=e.blurSamples,this.mapSize.copy(e.mapSize),this.biasNode=e.biasNode,this}clone(){return new this.constructor().copy(this)}toJSON(){const e={};return this.intensity!==1&&(e.intensity=this.intensity),this.bias!==0&&(e.bias=this.bias),this.normalBias!==0&&(e.normalBias=this.normalBias),this.radius!==1&&(e.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(e.mapSize=this.mapSize.toArray()),e.camera=this.camera.toJSON(!1).object,delete e.camera.matrix,e}}const xu=new P,yu=new Oi,tr=new P;class hy extends pn{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new pt,this.projectionMatrix=new pt,this.projectionMatrixInverse=new pt,this.coordinateSystem=ii,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorld.decompose(xu,yu,tr),tr.x===1&&tr.y===1&&tr.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(xu,yu,tr.set(1,1,1)).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorld.decompose(xu,yu,tr),tr.x===1&&tr.y===1&&tr.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(xu,yu,tr.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}}const cs=new P,jg=new pe,Yg=new pe;class Cn extends hy{constructor(e=50,t=1,n=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=n,this.far=i,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){const t=.5*this.getFilmHeight()/e;this.fov=xo*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){const e=Math.tan(ql*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return xo*2*Math.atan(Math.tan(ql*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(e,t,n){cs.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(cs.x,cs.y).multiplyScalar(-e/cs.z),cs.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(cs.x,cs.y).multiplyScalar(-e/cs.z)}getViewSize(e,t){return this.getViewBounds(e,jg,Yg),t.subVectors(Yg,jg)}setViewOffset(e,t,n,i,s,o){this.aspect=e/t,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=i,this.view.width=s,this.view.height=o,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=this.near;let t=e*Math.tan(ql*.5*this.fov)/this.zoom,n=2*t,i=this.aspect*n,s=-.5*i;const o=this.view;if(this.view!==null&&this.view.enabled){const l=o.fullWidth,c=o.fullHeight;s+=o.offsetX*i/l,t-=o.offsetY*n/c,i*=o.width/l,n*=o.height/c}const a=this.filmOffset;a!==0&&(s+=e*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+i,t,t-n,e,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}}class SM extends Tm{constructor(){super(new Cn(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1,this.aspect=1}updateMatrices(e){const t=this.camera,n=xo*2*e.angle*this.focus,i=this.mapSize.width/this.mapSize.height*this.aspect,s=e.distance||t.far;(n!==t.fov||i!==t.aspect||s!==t.far)&&(t.fov=n,t.aspect=i,t.far=s,t.updateProjectionMatrix()),super.updateMatrices(e)}copy(e){return super.copy(e),this.focus=e.focus,this}}class Mm extends No{constructor(e,t,n=0,i=Math.PI/3,s=0,o=2){super(e,t),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(pn.DEFAULT_UP),this.updateMatrix(),this.target=new pn,this.distance=n,this.angle=i,this.penumbra=s,this.decay=o,this.map=null,this.shadow=new SM}get power(){return this.intensity*Math.PI}set power(e){this.intensity=e/Math.PI}dispose(){super.dispose(),this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.angle=e.angle,this.penumbra=e.penumbra,this.decay=e.decay,this.target=e.target.clone(),this.map=e.map,this.shadow=e.shadow.clone(),this}toJSON(e){const t=super.toJSON(e);return t.object.distance=this.distance,t.object.angle=this.angle,t.object.decay=this.decay,t.object.penumbra=this.penumbra,t.object.target=this.target.uuid,this.map&&this.map.isTexture&&(t.object.map=this.map.toJSON(e).uuid),t.object.shadow=this.shadow.toJSON(),t}}class TM extends Tm{constructor(){super(new Cn(90,1,.5,500)),this.isPointLightShadow=!0}}class MM extends No{constructor(e,t,n=0,i=2){super(e,t),this.isPointLight=!0,this.type="PointLight",this.distance=n,this.decay=i,this.shadow=new TM}get power(){return this.intensity*4*Math.PI}set power(e){this.intensity=e/(4*Math.PI)}dispose(){super.dispose(),this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.decay=e.decay,this.shadow=e.shadow.clone(),this}toJSON(e){const t=super.toJSON(e);return t.object.distance=this.distance,t.object.decay=this.decay,t.object.shadow=this.shadow.toJSON(),t}}class ol extends hy{constructor(e=-1,t=1,n=1,i=-1,s=.1,o=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=n,this.bottom=i,this.near=s,this.far=o,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,n,i,s,o){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=i,this.view.width=s,this.view.height=o,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,i=(this.top+this.bottom)/2;let s=n-e,o=n+e,a=i+t,l=i-t;if(this.view!==null&&this.view.enabled){const c=(this.right-this.left)/this.view.fullWidth/this.zoom,u=(this.top-this.bottom)/this.view.fullHeight/this.zoom;s+=c*this.view.offsetX,o=s+c*this.view.width,a-=u*this.view.offsetY,l=a-u*this.view.height}this.projectionMatrix.makeOrthographic(s,o,a,l,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}}class EM extends Tm{constructor(){super(new ol(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class dy extends No{constructor(e,t){super(e,t),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(pn.DEFAULT_UP),this.updateMatrix(),this.target=new pn,this.shadow=new EM}dispose(){super.dispose(),this.shadow.dispose()}copy(e){return super.copy(e),this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}toJSON(e){const t=super.toJSON(e);return t.object.shadow=this.shadow.toJSON(),t.object.target=this.target.uuid,t}}class fy extends No{constructor(e,t){super(e,t),this.isAmbientLight=!0,this.type="AmbientLight"}}class AM extends No{constructor(e,t,n=10,i=10){super(e,t),this.isRectAreaLight=!0,this.type="RectAreaLight",this.width=n,this.height=i}get power(){return this.intensity*this.width*this.height*Math.PI}set power(e){this.intensity=e/(this.width*this.height*Math.PI)}copy(e){return super.copy(e),this.width=e.width,this.height=e.height,this}toJSON(e){const t=super.toJSON(e);return t.object.width=this.width,t.object.height=this.height,t}}class wM{constructor(){this.isSphericalHarmonics3=!0,this.coefficients=[];for(let e=0;e<9;e++)this.coefficients.push(new P)}set(e){for(let t=0;t<9;t++)this.coefficients[t].copy(e[t]);return this}zero(){for(let e=0;e<9;e++)this.coefficients[e].set(0,0,0);return this}getAt(e,t){const n=e.x,i=e.y,s=e.z,o=this.coefficients;return t.copy(o[0]).multiplyScalar(.282095),t.addScaledVector(o[1],.488603*i),t.addScaledVector(o[2],.488603*s),t.addScaledVector(o[3],.488603*n),t.addScaledVector(o[4],1.092548*(n*i)),t.addScaledVector(o[5],1.092548*(i*s)),t.addScaledVector(o[6],.315392*(3*s*s-1)),t.addScaledVector(o[7],1.092548*(n*s)),t.addScaledVector(o[8],.546274*(n*n-i*i)),t}getIrradianceAt(e,t){const n=e.x,i=e.y,s=e.z,o=this.coefficients;return t.copy(o[0]).multiplyScalar(.886227),t.addScaledVector(o[1],2*.511664*i),t.addScaledVector(o[2],2*.511664*s),t.addScaledVector(o[3],2*.511664*n),t.addScaledVector(o[4],2*.429043*n*i),t.addScaledVector(o[5],2*.429043*i*s),t.addScaledVector(o[6],.743125*s*s-.247708),t.addScaledVector(o[7],2*.429043*n*s),t.addScaledVector(o[8],.429043*(n*n-i*i)),t}add(e){for(let t=0;t<9;t++)this.coefficients[t].add(e.coefficients[t]);return this}addScaledSH(e,t){for(let n=0;n<9;n++)this.coefficients[n].addScaledVector(e.coefficients[n],t);return this}scale(e){for(let t=0;t<9;t++)this.coefficients[t].multiplyScalar(e);return this}lerp(e,t){for(let n=0;n<9;n++)this.coefficients[n].lerp(e.coefficients[n],t);return this}equals(e){for(let t=0;t<9;t++)if(!this.coefficients[t].equals(e.coefficients[t]))return!1;return!0}copy(e){return this.set(e.coefficients)}clone(){return new this.constructor().copy(this)}fromArray(e,t=0){const n=this.coefficients;for(let i=0;i<9;i++)n[i].fromArray(e,t+i*3);return this}toArray(e=[],t=0){const n=this.coefficients;for(let i=0;i<9;i++)n[i].toArray(e,t+i*3);return e}static getBasisAt(e,t){const n=e.x,i=e.y,s=e.z;t[0]=.282095,t[1]=.488603*i,t[2]=.488603*s,t[3]=.488603*n,t[4]=1.092548*n*i,t[5]=1.092548*i*s,t[6]=.315392*(3*s*s-1),t[7]=1.092548*n*s,t[8]=.546274*(n*n-i*i)}}class RM extends No{constructor(e=new wM,t=1){super(void 0,t),this.isLightProbe=!0,this.sh=e}copy(e){return super.copy(e),this.sh.copy(e.sh),this}toJSON(e){const t=super.toJSON(e);return t.object.sh=this.sh.toArray(),t}}const Zo=-90,Qo=1;class py extends pn{constructor(e,t,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Cn(Zo,Qo,e,t);i.layers=this.layers,this.add(i);const s=new Cn(Zo,Qo,e,t);s.layers=this.layers,this.add(s);const o=new Cn(Zo,Qo,e,t);o.layers=this.layers,this.add(o);const a=new Cn(Zo,Qo,e,t);a.layers=this.layers,this.add(a);const l=new Cn(Zo,Qo,e,t);l.layers=this.layers,this.add(l);const c=new Cn(Zo,Qo,e,t);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){const e=this.coordinateSystem,t=this.children.concat(),[n,i,s,o,a,l]=t;for(const c of t)this.remove(c);if(e===ii)n.up.set(0,1,0),n.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),s.up.set(0,0,-1),s.lookAt(0,1,0),o.up.set(0,0,1),o.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),l.up.set(0,1,0),l.lookAt(0,0,-1);else if(e===Tr)n.up.set(0,-1,0),n.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),s.up.set(0,0,1),s.lookAt(0,1,0),o.up.set(0,0,-1),o.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),l.up.set(0,-1,0),l.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+e);for(const c of t)this.add(c),c.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();const{renderTarget:n,activeMipmapLevel:i}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());const[s,o,a,l,c,u]=this.children,h=e.getRenderTarget(),d=e.getActiveCubeFace(),f=e.getActiveMipmapLevel(),p=e.xr.enabled;e.xr.enabled=!1;const g=n.texture.generateMipmaps;n.texture.generateMipmaps=!1;let m=!1;e.isWebGLRenderer===!0?m=e.state.buffers.depth.getReversed():m=e.reversedDepthBuffer,e.setRenderTarget(n,0,i),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,s),e.setRenderTarget(n,1,i),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,o),e.setRenderTarget(n,2,i),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,a),e.setRenderTarget(n,3,i),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,l),e.setRenderTarget(n,4,i),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,c),n.texture.generateMipmaps=g,e.setRenderTarget(n,5,i),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,u),e.setRenderTarget(h,d,f),e.xr.enabled=p,n.texture.needsPMREMUpdate=!0}}class my extends Cn{constructor(e=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=e}}class gy{constructor(){this._previousTime=0,this._currentTime=0,this._startTime=performance.now(),this._delta=0,this._elapsed=0,this._timescale=1,this._document=null,this._pageVisibilityHandler=null}connect(e){this._document=e,e.hidden!==void 0&&(this._pageVisibilityHandler=CM.bind(this),e.addEventListener("visibilitychange",this._pageVisibilityHandler,!1))}disconnect(){this._pageVisibilityHandler!==null&&(this._document.removeEventListener("visibilitychange",this._pageVisibilityHandler),this._pageVisibilityHandler=null),this._document=null}getDelta(){return this._delta/1e3}getElapsed(){return this._elapsed/1e3}getTimescale(){return this._timescale}setTimescale(e){return this._timescale=e,this}reset(){return this._currentTime=performance.now()-this._startTime,this}dispose(){this.disconnect()}update(e){return this._pageVisibilityHandler!==null&&this._document.hidden===!0?this._delta=0:(this._previousTime=this._currentTime,this._currentTime=(e!==void 0?e:performance.now())-this._startTime,this._delta=(this._currentTime-this._previousTime)*this._timescale,this._elapsed+=this._delta),this}}function CM(){this._document.hidden===!1&&this.reset()}class NM extends pm{constructor(e,t,n=1){super(e,t),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=n}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}clone(e){const t=super.clone(e);return t.meshPerAttribute=this.meshPerAttribute,t}toJSON(e){const t=super.toJSON(e);return t.isInstancedInterleavedBuffer=!0,t.meshPerAttribute=this.meshPerAttribute,t}}const Kg=new pt;class _y{constructor(e,t,n=0,i=1/0){this.ray=new Bh(e,t),this.near=n,this.far=i,this.camera=null,this.layers=new cm,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(e,t){this.ray.set(e,t)}setFromCamera(e,t){t.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(e.x,e.y,.5).unproject(t).sub(this.ray.origin).normalize(),this.camera=t):t.isOrthographicCamera?(this.ray.origin.set(e.x,e.y,(t.near+t.far)/(t.near-t.far)).unproject(t),this.ray.direction.set(0,0,-1).transformDirection(t.matrixWorld),this.camera=t):ce("Raycaster: Unsupported camera type: "+t.type)}setFromXRController(e){return Kg.identity().extractRotation(e.matrixWorld),this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(Kg),this}intersectObject(e,t=!0,n=[]){return ip(e,this,n,t),n.sort(Zg),n}intersectObjects(e,t=!0,n=[]){for(let i=0,s=e.length;i<s;i++)ip(e[i],this,n,t);return n.sort(Zg),n}}function Zg(r,e){return r.distance-e.distance}function ip(r,e,t,n){let i=!0;if(r.layers.test(e.layers)&&r.raycast(e,t)===!1&&(i=!1),i===!0&&n===!0){const s=r.children;for(let o=0,a=s.length;o<a;o++)ip(s[o],e,t,!0)}}class Qg{constructor(e=1,t=0,n=0){this.radius=e,this.phi=t,this.theta=n}set(e,t,n){return this.radius=e,this.phi=t,this.theta=n,this}copy(e){return this.radius=e.radius,this.phi=e.phi,this.theta=e.theta,this}makeSafe(){return this.phi=ct(this.phi,1e-6,Math.PI-1e-6),this}setFromVector3(e){return this.setFromCartesianCoords(e.x,e.y,e.z)}setFromCartesianCoords(e,t,n){return this.radius=Math.sqrt(e*e+t*t+n*n),this.radius===0?(this.theta=0,this.phi=0):(this.theta=Math.atan2(e,n),this.phi=Math.acos(ct(t/this.radius,-1,1))),this}clone(){return new this.constructor().copy(this)}}const cg=class cg{constructor(e,t,n,i){this.elements=[1,0,0,1],e!==void 0&&this.set(e,t,n,i)}identity(){return this.set(1,0,0,1),this}fromArray(e,t=0){for(let n=0;n<4;n++)this.elements[n]=e[n+t];return this}set(e,t,n,i){const s=this.elements;return s[0]=e,s[2]=t,s[1]=n,s[3]=i,this}};cg.prototype.isMatrix2=!0;let vh=cg;class kh extends Vi{constructor(e,t=null){super(),this.object=e,this.domElement=t,this.enabled=!0,this.state=-1,this.keys={},this.mouseButtons={LEFT:null,MIDDLE:null,RIGHT:null},this.touches={ONE:null,TWO:null}}connect(e){if(e===void 0){ae("Controls: connect() now requires an element.");return}this.domElement!==null&&this.disconnect(),this.domElement=e}disconnect(){}dispose(){}update(){}}function rp(r,e,t,n){const i=PM(n);switch(t){case Fh:return r*e;case il:return r*e/i.components*i.byteLength;case Eo:return r*e/i.components*i.byteLength;case In:return r*e*2/i.components*i.byteLength;case Ao:return r*e*2/i.components*i.byteLength;case nl:return r*e*3/i.components*i.byteLength;case ln:return r*e*4/i.components*i.byteLength;case rl:return r*e*4/i.components*i.byteLength;case Es:case As:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*8;case ws:case Rs:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*16;case gc:case xc:return Math.max(r,16)*Math.max(e,8)/4;case mc:case _c:return Math.max(r,8)*Math.max(e,8)/2;case Ma:case Ea:case wa:case Ra:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*8;case Aa:case Ls:case Ca:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*16;case Na:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*16;case Pa:return Math.floor((r+4)/5)*Math.floor((e+3)/4)*16;case Da:return Math.floor((r+4)/5)*Math.floor((e+4)/5)*16;case La:return Math.floor((r+5)/6)*Math.floor((e+4)/5)*16;case Ua:return Math.floor((r+5)/6)*Math.floor((e+5)/6)*16;case Fa:return Math.floor((r+7)/8)*Math.floor((e+4)/5)*16;case Ia:return Math.floor((r+7)/8)*Math.floor((e+5)/6)*16;case Ba:return Math.floor((r+7)/8)*Math.floor((e+7)/8)*16;case Oa:return Math.floor((r+9)/10)*Math.floor((e+4)/5)*16;case ka:return Math.floor((r+9)/10)*Math.floor((e+5)/6)*16;case Ga:return Math.floor((r+9)/10)*Math.floor((e+7)/8)*16;case Va:return Math.floor((r+9)/10)*Math.floor((e+9)/10)*16;case za:return Math.floor((r+11)/12)*Math.floor((e+9)/10)*16;case Ha:return Math.floor((r+11)/12)*Math.floor((e+11)/12)*16;case Wa:case ep:case tp:return Math.ceil(r/4)*Math.ceil(e/4)*16;case $a:case Xa:return Math.ceil(r/4)*Math.ceil(e/4)*8;case Us:case qa:return Math.ceil(r/4)*Math.ceil(e/4)*16}throw new Error(`Unable to determine texture byte length for ${t} format.`)}function PM(r){switch(r){case Xt:case Ts:return{byteLength:1,components:1};case Ui:case Ms:case tn:return{byteLength:2,components:1};case Pc:case Dc:return{byteLength:2,components:4};case Ct:case Sn:case Qt:return{byteLength:4,components:1};case Lc:case Uc:return{byteLength:4,components:3}}throw new Error(`Unknown texture type ${r}.`)}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:Mo}}));typeof window<"u"&&(window.__THREE__?ae("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=Mo);/**
9
+ }`;class ki extends Yn{constructor(e){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=oM,this.fragmentShader=aM,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,e!==void 0&&this.setValues(e)}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=Ka(e.uniforms),this.uniformsGroups=sM(e.uniformsGroups),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.fog=e.fog,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this.defaultAttributeValues=Object.assign({},e.defaultAttributeValues),this.index0AttributeName=e.index0AttributeName,this.uniformsNeedUpdate=e.uniformsNeedUpdate,this}toJSON(e){const t=super.toJSON(e);t.glslVersion=this.glslVersion,t.uniforms={};for(const i in this.uniforms){const o=this.uniforms[i].value;o&&o.isTexture?t.uniforms[i]={type:"t",value:o.toJSON(e).uuid}:o&&o.isColor?t.uniforms[i]={type:"c",value:o.getHex()}:o&&o.isVector2?t.uniforms[i]={type:"v2",value:o.toArray()}:o&&o.isVector3?t.uniforms[i]={type:"v3",value:o.toArray()}:o&&o.isVector4?t.uniforms[i]={type:"v4",value:o.toArray()}:o&&o.isMatrix3?t.uniforms[i]={type:"m3",value:o.toArray()}:o&&o.isMatrix4?t.uniforms[i]={type:"m4",value:o.toArray()}:t.uniforms[i]={value:o}}Object.keys(this.defines).length>0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;const n={};for(const i in this.extensions)this.extensions[i]===!0&&(n[i]=!0);return Object.keys(n).length>0&&(t.extensions=n),t}}class lM extends ki{constructor(e){super(e),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class cy extends Yn{constructor(e){super(),this.isMeshStandardMaterial=!0,this.type="MeshStandardMaterial",this.defines={STANDARD:""},this.color=new We(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new We(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ji,this.normalScale=new pe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Mr,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={STANDARD:""},this.color.copy(e.color),this.roughness=e.roughness,this.metalness=e.metalness,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.roughnessMap=e.roughnessMap,this.metalnessMap=e.metalnessMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.envMapIntensity=e.envMapIntensity,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class cM extends cy{constructor(e){super(),this.isMeshPhysicalMaterial=!0,this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.anisotropyRotation=0,this.anisotropyMap=null,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new pe(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return ct(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(t){this.ior=(1+.4*t)/(1-.4*t)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessRange=[100,400],this.iridescenceThicknessMap=null,this.sheenColor=new We(0),this.sheenColorMap=null,this.sheenRoughness=1,this.sheenRoughnessMap=null,this.transmissionMap=null,this.thickness=0,this.thicknessMap=null,this.attenuationDistance=1/0,this.attenuationColor=new We(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new We(1,1,1),this.specularColorMap=null,this._anisotropy=0,this._clearcoat=0,this._dispersion=0,this._iridescence=0,this._sheen=0,this._transmission=0,this.setValues(e)}get anisotropy(){return this._anisotropy}set anisotropy(e){this._anisotropy>0!=e>0&&this.version++,this._anisotropy=e}get clearcoat(){return this._clearcoat}set clearcoat(e){this._clearcoat>0!=e>0&&this.version++,this._clearcoat=e}get iridescence(){return this._iridescence}set iridescence(e){this._iridescence>0!=e>0&&this.version++,this._iridescence=e}get dispersion(){return this._dispersion}set dispersion(e){this._dispersion>0!=e>0&&this.version++,this._dispersion=e}get sheen(){return this._sheen}set sheen(e){this._sheen>0!=e>0&&this.version++,this._sheen=e}get transmission(){return this._transmission}set transmission(e){this._transmission>0!=e>0&&this.version++,this._transmission=e}copy(e){return super.copy(e),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=e.anisotropy,this.anisotropyRotation=e.anisotropyRotation,this.anisotropyMap=e.anisotropyMap,this.clearcoat=e.clearcoat,this.clearcoatMap=e.clearcoatMap,this.clearcoatRoughness=e.clearcoatRoughness,this.clearcoatRoughnessMap=e.clearcoatRoughnessMap,this.clearcoatNormalMap=e.clearcoatNormalMap,this.clearcoatNormalScale.copy(e.clearcoatNormalScale),this.dispersion=e.dispersion,this.ior=e.ior,this.iridescence=e.iridescence,this.iridescenceMap=e.iridescenceMap,this.iridescenceIOR=e.iridescenceIOR,this.iridescenceThicknessRange=[...e.iridescenceThicknessRange],this.iridescenceThicknessMap=e.iridescenceThicknessMap,this.sheen=e.sheen,this.sheenColor.copy(e.sheenColor),this.sheenColorMap=e.sheenColorMap,this.sheenRoughness=e.sheenRoughness,this.sheenRoughnessMap=e.sheenRoughnessMap,this.transmission=e.transmission,this.transmissionMap=e.transmissionMap,this.thickness=e.thickness,this.thicknessMap=e.thicknessMap,this.attenuationDistance=e.attenuationDistance,this.attenuationColor.copy(e.attenuationColor),this.specularIntensity=e.specularIntensity,this.specularIntensityMap=e.specularIntensityMap,this.specularColor.copy(e.specularColor),this.specularColorMap=e.specularColorMap,this}}class uM extends Yn{constructor(e){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new We(16777215),this.specular=new We(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new We(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ji,this.normalScale=new pe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Mr,this.combine=Nc,this.reflectivity=1,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.specular.copy(e.specular),this.shininess=e.shininess,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.envMapIntensity=e.envMapIntensity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class hM extends Yn{constructor(e){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new We(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new We(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ji,this.normalScale=new pe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.gradientMap=e.gradientMap,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}class dM extends Yn{constructor(e){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ji,this.normalScale=new pe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(e)}copy(e){return super.copy(e),this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this}}class uy extends Yn{constructor(e){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new We(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new We(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ji,this.normalScale=new pe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Mr,this.combine=Nc,this.reflectivity=1,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.envMapIntensity=e.envMapIntensity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}class fM extends Yn{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=BS,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}}class pM extends Yn{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}}class mM extends Yn{constructor(e){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new We(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ji,this.normalScale=new pe(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={MATCAP:""},this.color.copy(e.color),this.matcap=e.matcap,this.map=e.map,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this.fog=e.fog,this}}class gM extends Oh{constructor(e){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(e)}copy(e){return super.copy(e),this.scale=e.scale,this.dashSize=e.dashSize,this.gapSize=e.gapSize,this}}const Fd={enabled:!1,files:{},add:function(r,e){this.enabled!==!1&&($g(r)||(this.files[r]=e))},get:function(r){if(this.enabled!==!1&&!$g(r))return this.files[r]},remove:function(r){delete this.files[r]},clear:function(){this.files={}}};function $g(r){try{const e=r.slice(r.indexOf(":")+1);return new URL(e).protocol==="blob:"}catch{return!1}}class _M{constructor(e,t,n){const i=this;let s=!1,o=0,a=0,l;const c=[];this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=n,this._abortController=null,this.itemStart=function(u){a++,s===!1&&i.onStart!==void 0&&i.onStart(u,o,a),s=!0},this.itemEnd=function(u){o++,i.onProgress!==void 0&&i.onProgress(u,o,a),o===a&&(s=!1,i.onLoad!==void 0&&i.onLoad())},this.itemError=function(u){i.onError!==void 0&&i.onError(u)},this.resolveURL=function(u){return l?l(u):u},this.setURLModifier=function(u){return l=u,this},this.addHandler=function(u,h){return c.push(u,h),this},this.removeHandler=function(u){const h=c.indexOf(u);return h!==-1&&c.splice(h,2),this},this.getHandler=function(u){for(let h=0,d=c.length;h<d;h+=2){const f=c[h],p=c[h+1];if(f.global&&(f.lastIndex=0),f.test(u))return p}return null},this.abort=function(){return this.abortController.abort(),this._abortController=null,this}}get abortController(){return this._abortController||(this._abortController=new AbortController),this._abortController}}const xM=new _M;class Sm{constructor(e){this.manager=e!==void 0?e:xM,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}load(){}loadAsync(e,t){const n=this;return new Promise(function(i,s){n.load(e,i,t,s)})}parse(){}setCrossOrigin(e){return this.crossOrigin=e,this}setWithCredentials(e){return this.withCredentials=e,this}setPath(e){return this.path=e,this}setResourcePath(e){return this.resourcePath=e,this}setRequestHeader(e){return this.requestHeader=e,this}abort(){return this}}Sm.DEFAULT_MATERIAL_NAME="__DEFAULT";const Ko=new WeakMap;class yM extends Sm{constructor(e){super(e)}load(e,t,n,i){this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);const s=this,o=Fd.get(`image:${e}`);if(o!==void 0){if(o.complete===!0)s.manager.itemStart(e),setTimeout(function(){t&&t(o),s.manager.itemEnd(e)},0);else{let h=Ko.get(o);h===void 0&&(h=[],Ko.set(o,h)),h.push({onLoad:t,onError:i})}return o}const a=bc("img");function l(){u(),t&&t(this);const h=Ko.get(this)||[];for(let d=0;d<h.length;d++){const f=h[d];f.onLoad&&f.onLoad(this)}Ko.delete(this),s.manager.itemEnd(e)}function c(h){u(),i&&i(h),Fd.remove(`image:${e}`);const d=Ko.get(this)||[];for(let f=0;f<d.length;f++){const p=d[f];p.onError&&p.onError(h)}Ko.delete(this),s.manager.itemError(e),s.manager.itemEnd(e)}function u(){a.removeEventListener("load",l,!1),a.removeEventListener("error",c,!1)}return a.addEventListener("load",l,!1),a.addEventListener("error",c,!1),e.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(a.crossOrigin=this.crossOrigin),Fd.add(`image:${e}`,a),s.manager.itemStart(e),a.src=e,a}}class vM extends Sm{constructor(e){super(e)}load(e,t,n,i){const s=new fn,o=new yM(this.manager);return o.setCrossOrigin(this.crossOrigin),o.setPath(this.path),o.load(e,function(a){s.image=a,s.needsUpdate=!0,t!==void 0&&t(s)},n,i),s}}class No extends pn{constructor(e,t=1){super(),this.isLight=!0,this.type="Light",this.color=new We(e),this.intensity=t}dispose(){this.dispatchEvent({type:"dispose"})}copy(e,t){return super.copy(e,t),this.color.copy(e.color),this.intensity=e.intensity,this}toJSON(e){const t=super.toJSON(e);return t.object.color=this.color.getHex(),t.object.intensity=this.intensity,t}}class bM extends No{constructor(e,t,n){super(e,n),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(pn.DEFAULT_UP),this.updateMatrix(),this.groundColor=new We(t)}copy(e,t){return super.copy(e,t),this.groundColor.copy(e.groundColor),this}toJSON(e){const t=super.toJSON(e);return t.object.groundColor=this.groundColor.getHex(),t}}const Id=new pt,Xg=new P,qg=new P;class Tm{constructor(e){this.camera=e,this.intensity=1,this.bias=0,this.biasNode=null,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new pe(512,512),this.mapType=Xt,this.map=null,this.mapPass=null,this.matrix=new pt,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new Ic,this._frameExtents=new pe(1,1),this._viewportCount=1,this._viewports=[new rt(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(e){const t=this.camera,n=this.matrix;Xg.setFromMatrixPosition(e.matrixWorld),t.position.copy(Xg),qg.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(qg),t.updateMatrixWorld(),Id.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Id,t.coordinateSystem,t.reversedDepth),t.coordinateSystem===Tr||t.reversedDepth?n.set(.5,0,0,.5,0,.5,0,.5,0,0,1,0,0,0,0,1):n.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),n.multiply(Id)}getViewport(e){return this._viewports[e]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(e){return this.camera=e.camera.clone(),this.intensity=e.intensity,this.bias=e.bias,this.radius=e.radius,this.autoUpdate=e.autoUpdate,this.needsUpdate=e.needsUpdate,this.normalBias=e.normalBias,this.blurSamples=e.blurSamples,this.mapSize.copy(e.mapSize),this.biasNode=e.biasNode,this}clone(){return new this.constructor().copy(this)}toJSON(){const e={};return this.intensity!==1&&(e.intensity=this.intensity),this.bias!==0&&(e.bias=this.bias),this.normalBias!==0&&(e.normalBias=this.normalBias),this.radius!==1&&(e.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(e.mapSize=this.mapSize.toArray()),e.camera=this.camera.toJSON(!1).object,delete e.camera.matrix,e}}const xu=new P,yu=new Oi,tr=new P;class hy extends pn{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new pt,this.projectionMatrix=new pt,this.projectionMatrixInverse=new pt,this.coordinateSystem=ii,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorld.decompose(xu,yu,tr),tr.x===1&&tr.y===1&&tr.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(xu,yu,tr.set(1,1,1)).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorld.decompose(xu,yu,tr),tr.x===1&&tr.y===1&&tr.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(xu,yu,tr.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}}const cs=new P,jg=new pe,Yg=new pe;class Cn extends hy{constructor(e=50,t=1,n=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=n,this.far=i,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){const t=.5*this.getFilmHeight()/e;this.fov=xo*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){const e=Math.tan(ql*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return xo*2*Math.atan(Math.tan(ql*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(e,t,n){cs.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(cs.x,cs.y).multiplyScalar(-e/cs.z),cs.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(cs.x,cs.y).multiplyScalar(-e/cs.z)}getViewSize(e,t){return this.getViewBounds(e,jg,Yg),t.subVectors(Yg,jg)}setViewOffset(e,t,n,i,s,o){this.aspect=e/t,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=i,this.view.width=s,this.view.height=o,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=this.near;let t=e*Math.tan(ql*.5*this.fov)/this.zoom,n=2*t,i=this.aspect*n,s=-.5*i;const o=this.view;if(this.view!==null&&this.view.enabled){const l=o.fullWidth,c=o.fullHeight;s+=o.offsetX*i/l,t-=o.offsetY*n/c,i*=o.width/l,n*=o.height/c}const a=this.filmOffset;a!==0&&(s+=e*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+i,t,t-n,e,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}}class SM extends Tm{constructor(){super(new Cn(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1,this.aspect=1}updateMatrices(e){const t=this.camera,n=xo*2*e.angle*this.focus,i=this.mapSize.width/this.mapSize.height*this.aspect,s=e.distance||t.far;(n!==t.fov||i!==t.aspect||s!==t.far)&&(t.fov=n,t.aspect=i,t.far=s,t.updateProjectionMatrix()),super.updateMatrices(e)}copy(e){return super.copy(e),this.focus=e.focus,this}}class Mm extends No{constructor(e,t,n=0,i=Math.PI/3,s=0,o=2){super(e,t),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(pn.DEFAULT_UP),this.updateMatrix(),this.target=new pn,this.distance=n,this.angle=i,this.penumbra=s,this.decay=o,this.map=null,this.shadow=new SM}get power(){return this.intensity*Math.PI}set power(e){this.intensity=e/Math.PI}dispose(){super.dispose(),this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.angle=e.angle,this.penumbra=e.penumbra,this.decay=e.decay,this.target=e.target.clone(),this.map=e.map,this.shadow=e.shadow.clone(),this}toJSON(e){const t=super.toJSON(e);return t.object.distance=this.distance,t.object.angle=this.angle,t.object.decay=this.decay,t.object.penumbra=this.penumbra,t.object.target=this.target.uuid,this.map&&this.map.isTexture&&(t.object.map=this.map.toJSON(e).uuid),t.object.shadow=this.shadow.toJSON(),t}}class TM extends Tm{constructor(){super(new Cn(90,1,.5,500)),this.isPointLightShadow=!0}}class MM extends No{constructor(e,t,n=0,i=2){super(e,t),this.isPointLight=!0,this.type="PointLight",this.distance=n,this.decay=i,this.shadow=new TM}get power(){return this.intensity*4*Math.PI}set power(e){this.intensity=e/(4*Math.PI)}dispose(){super.dispose(),this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.decay=e.decay,this.shadow=e.shadow.clone(),this}toJSON(e){const t=super.toJSON(e);return t.object.distance=this.distance,t.object.decay=this.decay,t.object.shadow=this.shadow.toJSON(),t}}class ol extends hy{constructor(e=-1,t=1,n=1,i=-1,s=.1,o=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=n,this.bottom=i,this.near=s,this.far=o,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,n,i,s,o){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=i,this.view.width=s,this.view.height=o,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,i=(this.top+this.bottom)/2;let s=n-e,o=n+e,a=i+t,l=i-t;if(this.view!==null&&this.view.enabled){const c=(this.right-this.left)/this.view.fullWidth/this.zoom,u=(this.top-this.bottom)/this.view.fullHeight/this.zoom;s+=c*this.view.offsetX,o=s+c*this.view.width,a-=u*this.view.offsetY,l=a-u*this.view.height}this.projectionMatrix.makeOrthographic(s,o,a,l,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}}class EM extends Tm{constructor(){super(new ol(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class dy extends No{constructor(e,t){super(e,t),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(pn.DEFAULT_UP),this.updateMatrix(),this.target=new pn,this.shadow=new EM}dispose(){super.dispose(),this.shadow.dispose()}copy(e){return super.copy(e),this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}toJSON(e){const t=super.toJSON(e);return t.object.shadow=this.shadow.toJSON(),t.object.target=this.target.uuid,t}}class fy extends No{constructor(e,t){super(e,t),this.isAmbientLight=!0,this.type="AmbientLight"}}class AM extends No{constructor(e,t,n=10,i=10){super(e,t),this.isRectAreaLight=!0,this.type="RectAreaLight",this.width=n,this.height=i}get power(){return this.intensity*this.width*this.height*Math.PI}set power(e){this.intensity=e/(this.width*this.height*Math.PI)}copy(e){return super.copy(e),this.width=e.width,this.height=e.height,this}toJSON(e){const t=super.toJSON(e);return t.object.width=this.width,t.object.height=this.height,t}}class wM{constructor(){this.isSphericalHarmonics3=!0,this.coefficients=[];for(let e=0;e<9;e++)this.coefficients.push(new P)}set(e){for(let t=0;t<9;t++)this.coefficients[t].copy(e[t]);return this}zero(){for(let e=0;e<9;e++)this.coefficients[e].set(0,0,0);return this}getAt(e,t){const n=e.x,i=e.y,s=e.z,o=this.coefficients;return t.copy(o[0]).multiplyScalar(.282095),t.addScaledVector(o[1],.488603*i),t.addScaledVector(o[2],.488603*s),t.addScaledVector(o[3],.488603*n),t.addScaledVector(o[4],1.092548*(n*i)),t.addScaledVector(o[5],1.092548*(i*s)),t.addScaledVector(o[6],.315392*(3*s*s-1)),t.addScaledVector(o[7],1.092548*(n*s)),t.addScaledVector(o[8],.546274*(n*n-i*i)),t}getIrradianceAt(e,t){const n=e.x,i=e.y,s=e.z,o=this.coefficients;return t.copy(o[0]).multiplyScalar(.886227),t.addScaledVector(o[1],2*.511664*i),t.addScaledVector(o[2],2*.511664*s),t.addScaledVector(o[3],2*.511664*n),t.addScaledVector(o[4],2*.429043*n*i),t.addScaledVector(o[5],2*.429043*i*s),t.addScaledVector(o[6],.743125*s*s-.247708),t.addScaledVector(o[7],2*.429043*n*s),t.addScaledVector(o[8],.429043*(n*n-i*i)),t}add(e){for(let t=0;t<9;t++)this.coefficients[t].add(e.coefficients[t]);return this}addScaledSH(e,t){for(let n=0;n<9;n++)this.coefficients[n].addScaledVector(e.coefficients[n],t);return this}scale(e){for(let t=0;t<9;t++)this.coefficients[t].multiplyScalar(e);return this}lerp(e,t){for(let n=0;n<9;n++)this.coefficients[n].lerp(e.coefficients[n],t);return this}equals(e){for(let t=0;t<9;t++)if(!this.coefficients[t].equals(e.coefficients[t]))return!1;return!0}copy(e){return this.set(e.coefficients)}clone(){return new this.constructor().copy(this)}fromArray(e,t=0){const n=this.coefficients;for(let i=0;i<9;i++)n[i].fromArray(e,t+i*3);return this}toArray(e=[],t=0){const n=this.coefficients;for(let i=0;i<9;i++)n[i].toArray(e,t+i*3);return e}static getBasisAt(e,t){const n=e.x,i=e.y,s=e.z;t[0]=.282095,t[1]=.488603*i,t[2]=.488603*s,t[3]=.488603*n,t[4]=1.092548*n*i,t[5]=1.092548*i*s,t[6]=.315392*(3*s*s-1),t[7]=1.092548*n*s,t[8]=.546274*(n*n-i*i)}}class RM extends No{constructor(e=new wM,t=1){super(void 0,t),this.isLightProbe=!0,this.sh=e}copy(e){return super.copy(e),this.sh.copy(e.sh),this}toJSON(e){const t=super.toJSON(e);return t.object.sh=this.sh.toArray(),t}}const Zo=-90,Qo=1;class py extends pn{constructor(e,t,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Cn(Zo,Qo,e,t);i.layers=this.layers,this.add(i);const s=new Cn(Zo,Qo,e,t);s.layers=this.layers,this.add(s);const o=new Cn(Zo,Qo,e,t);o.layers=this.layers,this.add(o);const a=new Cn(Zo,Qo,e,t);a.layers=this.layers,this.add(a);const l=new Cn(Zo,Qo,e,t);l.layers=this.layers,this.add(l);const c=new Cn(Zo,Qo,e,t);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){const e=this.coordinateSystem,t=this.children.concat(),[n,i,s,o,a,l]=t;for(const c of t)this.remove(c);if(e===ii)n.up.set(0,1,0),n.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),s.up.set(0,0,-1),s.lookAt(0,1,0),o.up.set(0,0,1),o.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),l.up.set(0,1,0),l.lookAt(0,0,-1);else if(e===Tr)n.up.set(0,-1,0),n.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),s.up.set(0,0,1),s.lookAt(0,1,0),o.up.set(0,0,-1),o.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),l.up.set(0,-1,0),l.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+e);for(const c of t)this.add(c),c.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();const{renderTarget:n,activeMipmapLevel:i}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());const[s,o,a,l,c,u]=this.children,h=e.getRenderTarget(),d=e.getActiveCubeFace(),f=e.getActiveMipmapLevel(),p=e.xr.enabled;e.xr.enabled=!1;const g=n.texture.generateMipmaps;n.texture.generateMipmaps=!1;let m=!1;e.isWebGLRenderer===!0?m=e.state.buffers.depth.getReversed():m=e.reversedDepthBuffer,e.setRenderTarget(n,0,i),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,s),e.setRenderTarget(n,1,i),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,o),e.setRenderTarget(n,2,i),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,a),e.setRenderTarget(n,3,i),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,l),e.setRenderTarget(n,4,i),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,c),n.texture.generateMipmaps=g,e.setRenderTarget(n,5,i),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,u),e.setRenderTarget(h,d,f),e.xr.enabled=p,n.texture.needsPMREMUpdate=!0}}class my extends Cn{constructor(e=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=e}}class gy{constructor(){this._previousTime=0,this._currentTime=0,this._startTime=performance.now(),this._delta=0,this._elapsed=0,this._timescale=1,this._document=null,this._pageVisibilityHandler=null}connect(e){this._document=e,e.hidden!==void 0&&(this._pageVisibilityHandler=CM.bind(this),e.addEventListener("visibilitychange",this._pageVisibilityHandler,!1))}disconnect(){this._pageVisibilityHandler!==null&&(this._document.removeEventListener("visibilitychange",this._pageVisibilityHandler),this._pageVisibilityHandler=null),this._document=null}getDelta(){return this._delta/1e3}getElapsed(){return this._elapsed/1e3}getTimescale(){return this._timescale}setTimescale(e){return this._timescale=e,this}reset(){return this._currentTime=performance.now()-this._startTime,this}dispose(){this.disconnect()}update(e){return this._pageVisibilityHandler!==null&&this._document.hidden===!0?this._delta=0:(this._previousTime=this._currentTime,this._currentTime=(e!==void 0?e:performance.now())-this._startTime,this._delta=(this._currentTime-this._previousTime)*this._timescale,this._elapsed+=this._delta),this}}function CM(){this._document.hidden===!1&&this.reset()}class NM extends pm{constructor(e,t,n=1){super(e,t),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=n}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}clone(e){const t=super.clone(e);return t.meshPerAttribute=this.meshPerAttribute,t}toJSON(e){const t=super.toJSON(e);return t.isInstancedInterleavedBuffer=!0,t.meshPerAttribute=this.meshPerAttribute,t}}const Kg=new pt;class _y{constructor(e,t,n=0,i=1/0){this.ray=new Bh(e,t),this.near=n,this.far=i,this.camera=null,this.layers=new cm,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(e,t){this.ray.set(e,t)}setFromCamera(e,t){t.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(e.x,e.y,.5).unproject(t).sub(this.ray.origin).normalize(),this.camera=t):t.isOrthographicCamera?(this.ray.origin.set(e.x,e.y,(t.near+t.far)/(t.near-t.far)).unproject(t),this.ray.direction.set(0,0,-1).transformDirection(t.matrixWorld),this.camera=t):ce("Raycaster: Unsupported camera type: "+t.type)}setFromXRController(e){return Kg.identity().extractRotation(e.matrixWorld),this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(Kg),this}intersectObject(e,t=!0,n=[]){return ip(e,this,n,t),n.sort(Zg),n}intersectObjects(e,t=!0,n=[]){for(let i=0,s=e.length;i<s;i++)ip(e[i],this,n,t);return n.sort(Zg),n}}function Zg(r,e){return r.distance-e.distance}function ip(r,e,t,n){let i=!0;if(r.layers.test(e.layers)&&r.raycast(e,t)===!1&&(i=!1),i===!0&&n===!0){const s=r.children;for(let o=0,a=s.length;o<a;o++)ip(s[o],e,t,!0)}}class Qg{constructor(e=1,t=0,n=0){this.radius=e,this.phi=t,this.theta=n}set(e,t,n){return this.radius=e,this.phi=t,this.theta=n,this}copy(e){return this.radius=e.radius,this.phi=e.phi,this.theta=e.theta,this}makeSafe(){return this.phi=ct(this.phi,1e-6,Math.PI-1e-6),this}setFromVector3(e){return this.setFromCartesianCoords(e.x,e.y,e.z)}setFromCartesianCoords(e,t,n){return this.radius=Math.sqrt(e*e+t*t+n*n),this.radius===0?(this.theta=0,this.phi=0):(this.theta=Math.atan2(e,n),this.phi=Math.acos(ct(t/this.radius,-1,1))),this}clone(){return new this.constructor().copy(this)}}const cg=class cg{constructor(e,t,n,i){this.elements=[1,0,0,1],e!==void 0&&this.set(e,t,n,i)}identity(){return this.set(1,0,0,1),this}fromArray(e,t=0){for(let n=0;n<4;n++)this.elements[n]=e[n+t];return this}set(e,t,n,i){const s=this.elements;return s[0]=e,s[2]=t,s[1]=n,s[3]=i,this}};cg.prototype.isMatrix2=!0;let vh=cg;class kh extends Vi{constructor(e,t=null){super(),this.object=e,this.domElement=t,this.enabled=!0,this.state=-1,this.keys={},this.mouseButtons={LEFT:null,MIDDLE:null,RIGHT:null},this.touches={ONE:null,TWO:null}}connect(e){if(e===void 0){ae("Controls: connect() now requires an element.");return}this.domElement!==null&&this.disconnect(),this.domElement=e}disconnect(){}dispose(){}update(){}}function rp(r,e,t,n){const i=PM(n);switch(t){case Fh:return r*e;case il:return r*e/i.components*i.byteLength;case Eo:return r*e/i.components*i.byteLength;case In:return r*e*2/i.components*i.byteLength;case Ao:return r*e*2/i.components*i.byteLength;case nl:return r*e*3/i.components*i.byteLength;case ln:return r*e*4/i.components*i.byteLength;case rl:return r*e*4/i.components*i.byteLength;case Es:case As:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*8;case ws:case Rs:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*16;case gc:case xc:return Math.max(r,16)*Math.max(e,8)/4;case mc:case _c:return Math.max(r,8)*Math.max(e,8)/2;case Ma:case Ea:case wa:case Ra:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*8;case Aa:case Ls:case Ca:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*16;case Na:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*16;case Pa:return Math.floor((r+4)/5)*Math.floor((e+3)/4)*16;case Da:return Math.floor((r+4)/5)*Math.floor((e+4)/5)*16;case La:return Math.floor((r+5)/6)*Math.floor((e+4)/5)*16;case Ua:return Math.floor((r+5)/6)*Math.floor((e+5)/6)*16;case Fa:return Math.floor((r+7)/8)*Math.floor((e+4)/5)*16;case Ia:return Math.floor((r+7)/8)*Math.floor((e+5)/6)*16;case Ba:return Math.floor((r+7)/8)*Math.floor((e+7)/8)*16;case Oa:return Math.floor((r+9)/10)*Math.floor((e+4)/5)*16;case ka:return Math.floor((r+9)/10)*Math.floor((e+5)/6)*16;case Ga:return Math.floor((r+9)/10)*Math.floor((e+7)/8)*16;case Va:return Math.floor((r+9)/10)*Math.floor((e+9)/10)*16;case za:return Math.floor((r+11)/12)*Math.floor((e+9)/10)*16;case Ha:return Math.floor((r+11)/12)*Math.floor((e+11)/12)*16;case Wa:case ep:case tp:return Math.ceil(r/4)*Math.ceil(e/4)*16;case $a:case Xa:return Math.ceil(r/4)*Math.ceil(e/4)*8;case Us:case qa:return Math.ceil(r/4)*Math.ceil(e/4)*16}throw new Error(`Unable to determine texture byte length for ${t} format.`)}function PM(r){switch(r){case Xt:case Ts:return{byteLength:1,components:1};case Li:case Ms:case tn:return{byteLength:2,components:1};case Pc:case Dc:return{byteLength:2,components:4};case Ct:case Sn:case Qt:return{byteLength:4,components:1};case Lc:case Uc:return{byteLength:4,components:3}}throw new Error(`Unknown texture type ${r}.`)}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:Mo}}));typeof window<"u"&&(window.__THREE__?ae("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=Mo);/**
10
10
  * @license
11
11
  * Copyright 2010-2026 Three.js Authors
12
12
  * SPDX-License-Identifier: MIT
@@ -4058,7 +4058,7 @@ Material Type: `+C.type+`
4058
4058
 
4059
4059
  Program Info Log: `+U+`
4060
4060
  `+fe+`
4061
- `+Z)}else U!==""?ae("WebGLProgram: Program Info Log:",U):(B===""||D==="")&&(K=!1);K&&(C.diagnostics={runnable:X,programLog:U,vertexShader:{log:B,prefix:m},fragmentShader:{log:D,prefix:_}})}i.deleteShader(M),i.deleteShader(S),v=new ah(i,g),w=LR(i,g)}let v;this.getUniforms=function(){return v===void 0&&E(this),v};let w;this.getAttributes=function(){return w===void 0&&E(this),w};let N=t.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return N===!1&&(N=i.getProgramParameter(g,TR)),N},this.destroy=function(){n.releaseStatesOfProgram(this),i.deleteProgram(g),this.program=void 0},this.type=t.shaderType,this.name=t.shaderName,this.id=MR++,this.cacheKey=e,this.usedTimes=1,this.program=g,this.vertexShader=M,this.fragmentShader=S,this}let YR=0;class KR{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e){const t=e.vertexShader,n=e.fragmentShader,i=this._getShaderStage(t),s=this._getShaderStage(n),o=this._getShaderCacheForMaterial(e);return o.has(i)===!1&&(o.add(i),i.usedTimes++),o.has(s)===!1&&(o.add(s),s.usedTimes++),this}remove(e){const t=this.materialCache.get(e);for(const n of t)n.usedTimes--,n.usedTimes===0&&this.shaderCache.delete(n.code);return this.materialCache.delete(e),this}getVertexShaderID(e){return this._getShaderStage(e.vertexShader).id}getFragmentShaderID(e){return this._getShaderStage(e.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){const t=this.materialCache;let n=t.get(e);return n===void 0&&(n=new Set,t.set(e,n)),n}_getShaderStage(e){const t=this.shaderCache;let n=t.get(e);return n===void 0&&(n=new ZR(e),t.set(e,n)),n}}class ZR{constructor(e){this.id=YR++,this.code=e,this.usedTimes=0}}function QR(r){return r===In||r===Ls||r===Us}function JR(r,e,t,n,i,s){const o=new cm,a=new KR,l=new Set,c=[],u=new Map,h=n.logarithmicDepthBuffer;let d=n.precision;const f={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distance",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function p(v){return l.add(v),v===0?"uv":`uv${v}`}function g(v,w,N,C,F,V){const z=C.fog,U=F.geometry,B=v.isMeshStandardMaterial||v.isMeshLambertMaterial||v.isMeshPhongMaterial?C.environment:null,D=v.isMeshStandardMaterial||v.isMeshLambertMaterial&&!v.envMap||v.isMeshPhongMaterial&&!v.envMap,X=e.get(v.envMap||B,D),K=X&&X.mapping===mo?X.image.height:null,fe=f[v.type];v.precision!==null&&(d=n.getMaxPrecision(v.precision),d!==v.precision&&ae("WebGLProgram.getParameters:",v.precision,"not supported, using",d,"instead."));const Z=U.morphAttributes.position||U.morphAttributes.normal||U.morphAttributes.color,oe=Z!==void 0?Z.length:0;let Ee=0;U.morphAttributes.position!==void 0&&(Ee=1),U.morphAttributes.normal!==void 0&&(Ee=2),U.morphAttributes.color!==void 0&&(Ee=3);let ze,$,I,ne;if(fe){const ot=hr[fe];ze=ot.vertexShader,$=ot.fragmentShader}else ze=v.vertexShader,$=v.fragmentShader,a.update(v),I=a.getVertexShaderID(v),ne=a.getFragmentShaderID(v);const ue=r.getRenderTarget(),_e=r.state.buffers.depth.getReversed(),Ue=F.isInstancedMesh===!0,Ae=F.isBatchedMesh===!0,dt=!!v.map,tt=!!v.matcap,gt=!!X,At=!!v.aoMap,nt=!!v.lightMap,Bt=!!v.bumpMap,Ut=!!v.normalMap,mi=!!v.displacementMap,H=!!v.emissiveMap,vn=!!v.metalnessMap,yt=!!v.roughnessMap,qt=v.anisotropy>0,Re=v.clearcoat>0,on=v.dispersion>0,R=v.iridescence>0,T=v.sheen>0,q=v.transmission>0,he=qt&&!!v.anisotropyMap,ge=Re&&!!v.clearcoatMap,xe=Re&&!!v.clearcoatNormalMap,Me=Re&&!!v.clearcoatRoughnessMap,se=R&&!!v.iridescenceMap,de=R&&!!v.iridescenceThicknessMap,Le=T&&!!v.sheenColorMap,Be=T&&!!v.sheenRoughnessMap,Se=!!v.specularMap,ye=!!v.specularColorMap,it=!!v.specularIntensityMap,ut=q&&!!v.transmissionMap,Tt=q&&!!v.thicknessMap,O=!!v.gradientMap,ve=!!v.alphaMap,le=v.alphaTest>0,Fe=!!v.alphaHash,Te=!!v.extensions;let me=Fn;v.toneMapped&&(ue===null||ue.isXRRenderTarget===!0)&&(me=r.toneMapping);const $e={shaderID:fe,shaderType:v.type,shaderName:v.name,vertexShader:ze,fragmentShader:$,defines:v.defines,customVertexShaderID:I,customFragmentShaderID:ne,isRawShaderMaterial:v.isRawShaderMaterial===!0,glslVersion:v.glslVersion,precision:d,batching:Ae,batchingColor:Ae&&F._colorsTexture!==null,instancing:Ue,instancingColor:Ue&&F.instanceColor!==null,instancingMorph:Ue&&F.morphTexture!==null,outputColorSpace:ue===null?r.outputColorSpace:ue.isXRRenderTarget===!0?ue.texture.colorSpace:Ye.workingColorSpace,alphaToCoverage:!!v.alphaToCoverage,map:dt,matcap:tt,envMap:gt,envMapMode:gt&&X.mapping,envMapCubeUVHeight:K,aoMap:At,lightMap:nt,bumpMap:Bt,normalMap:Ut,displacementMap:mi,emissiveMap:H,normalMapObjectSpace:Ut&&v.normalMapType===j0,normalMapTangentSpace:Ut&&v.normalMapType===ji,packedNormalMap:Ut&&v.normalMapType===ji&&QR(v.normalMap.format),metalnessMap:vn,roughnessMap:yt,anisotropy:qt,anisotropyMap:he,clearcoat:Re,clearcoatMap:ge,clearcoatNormalMap:xe,clearcoatRoughnessMap:Me,dispersion:on,iridescence:R,iridescenceMap:se,iridescenceThicknessMap:de,sheen:T,sheenColorMap:Le,sheenRoughnessMap:Be,specularMap:Se,specularColorMap:ye,specularIntensityMap:it,transmission:q,transmissionMap:ut,thicknessMap:Tt,gradientMap:O,opaque:v.transparent===!1&&v.blending===ti&&v.alphaToCoverage===!1,alphaMap:ve,alphaTest:le,alphaHash:Fe,combine:v.combine,mapUv:dt&&p(v.map.channel),aoMapUv:At&&p(v.aoMap.channel),lightMapUv:nt&&p(v.lightMap.channel),bumpMapUv:Bt&&p(v.bumpMap.channel),normalMapUv:Ut&&p(v.normalMap.channel),displacementMapUv:mi&&p(v.displacementMap.channel),emissiveMapUv:H&&p(v.emissiveMap.channel),metalnessMapUv:vn&&p(v.metalnessMap.channel),roughnessMapUv:yt&&p(v.roughnessMap.channel),anisotropyMapUv:he&&p(v.anisotropyMap.channel),clearcoatMapUv:ge&&p(v.clearcoatMap.channel),clearcoatNormalMapUv:xe&&p(v.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:Me&&p(v.clearcoatRoughnessMap.channel),iridescenceMapUv:se&&p(v.iridescenceMap.channel),iridescenceThicknessMapUv:de&&p(v.iridescenceThicknessMap.channel),sheenColorMapUv:Le&&p(v.sheenColorMap.channel),sheenRoughnessMapUv:Be&&p(v.sheenRoughnessMap.channel),specularMapUv:Se&&p(v.specularMap.channel),specularColorMapUv:ye&&p(v.specularColorMap.channel),specularIntensityMapUv:it&&p(v.specularIntensityMap.channel),transmissionMapUv:ut&&p(v.transmissionMap.channel),thicknessMapUv:Tt&&p(v.thicknessMap.channel),alphaMapUv:ve&&p(v.alphaMap.channel),vertexTangents:!!U.attributes.tangent&&(Ut||qt),vertexNormals:!!U.attributes.normal,vertexColors:v.vertexColors,vertexAlphas:v.vertexColors===!0&&!!U.attributes.color&&U.attributes.color.itemSize===4,pointsUvs:F.isPoints===!0&&!!U.attributes.uv&&(dt||ve),fog:!!z,useFog:v.fog===!0,fogExp2:!!z&&z.isFogExp2,flatShading:v.wireframe===!1&&(v.flatShading===!0||U.attributes.normal===void 0&&Ut===!1&&(v.isMeshLambertMaterial||v.isMeshPhongMaterial||v.isMeshStandardMaterial||v.isMeshPhysicalMaterial)),sizeAttenuation:v.sizeAttenuation===!0,logarithmicDepthBuffer:h,reversedDepthBuffer:_e,skinning:F.isSkinnedMesh===!0,morphTargets:U.morphAttributes.position!==void 0,morphNormals:U.morphAttributes.normal!==void 0,morphColors:U.morphAttributes.color!==void 0,morphTargetsCount:oe,morphTextureStride:Ee,numDirLights:w.directional.length,numPointLights:w.point.length,numSpotLights:w.spot.length,numSpotLightMaps:w.spotLightMap.length,numRectAreaLights:w.rectArea.length,numHemiLights:w.hemi.length,numDirLightShadows:w.directionalShadowMap.length,numPointLightShadows:w.pointShadowMap.length,numSpotLightShadows:w.spotShadowMap.length,numSpotLightShadowsWithMaps:w.numSpotLightShadowsWithMaps,numLightProbes:w.numLightProbes,numLightProbeGrids:V.length,numClippingPlanes:s.numPlanes,numClipIntersection:s.numIntersection,dithering:v.dithering,shadowMapEnabled:r.shadowMap.enabled&&N.length>0,shadowMapType:r.shadowMap.type,toneMapping:me,decodeVideoTexture:dt&&v.map.isVideoTexture===!0&&Ye.getTransfer(v.map.colorSpace)===Pe,decodeVideoTextureEmissive:H&&v.emissiveMap.isVideoTexture===!0&&Ye.getTransfer(v.emissiveMap.colorSpace)===Pe,premultipliedAlpha:v.premultipliedAlpha,doubleSided:v.side===Nn,flipSided:v.side===Lt,useDepthPacking:v.depthPacking>=0,depthPacking:v.depthPacking||0,index0AttributeName:v.index0AttributeName,extensionClipCullDistance:Te&&v.extensions.clipCullDistance===!0&&t.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(Te&&v.extensions.multiDraw===!0||Ae)&&t.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:t.has("KHR_parallel_shader_compile"),customProgramCacheKey:v.customProgramCacheKey()};return $e.vertexUv1s=l.has(1),$e.vertexUv2s=l.has(2),$e.vertexUv3s=l.has(3),l.clear(),$e}function m(v){const w=[];if(v.shaderID?w.push(v.shaderID):(w.push(v.customVertexShaderID),w.push(v.customFragmentShaderID)),v.defines!==void 0)for(const N in v.defines)w.push(N),w.push(v.defines[N]);return v.isRawShaderMaterial===!1&&(_(w,v),x(w,v),w.push(r.outputColorSpace)),w.push(v.customProgramCacheKey),w.join()}function _(v,w){v.push(w.precision),v.push(w.outputColorSpace),v.push(w.envMapMode),v.push(w.envMapCubeUVHeight),v.push(w.mapUv),v.push(w.alphaMapUv),v.push(w.lightMapUv),v.push(w.aoMapUv),v.push(w.bumpMapUv),v.push(w.normalMapUv),v.push(w.displacementMapUv),v.push(w.emissiveMapUv),v.push(w.metalnessMapUv),v.push(w.roughnessMapUv),v.push(w.anisotropyMapUv),v.push(w.clearcoatMapUv),v.push(w.clearcoatNormalMapUv),v.push(w.clearcoatRoughnessMapUv),v.push(w.iridescenceMapUv),v.push(w.iridescenceThicknessMapUv),v.push(w.sheenColorMapUv),v.push(w.sheenRoughnessMapUv),v.push(w.specularMapUv),v.push(w.specularColorMapUv),v.push(w.specularIntensityMapUv),v.push(w.transmissionMapUv),v.push(w.thicknessMapUv),v.push(w.combine),v.push(w.fogExp2),v.push(w.sizeAttenuation),v.push(w.morphTargetsCount),v.push(w.morphAttributeCount),v.push(w.numDirLights),v.push(w.numPointLights),v.push(w.numSpotLights),v.push(w.numSpotLightMaps),v.push(w.numHemiLights),v.push(w.numRectAreaLights),v.push(w.numDirLightShadows),v.push(w.numPointLightShadows),v.push(w.numSpotLightShadows),v.push(w.numSpotLightShadowsWithMaps),v.push(w.numLightProbes),v.push(w.shadowMapType),v.push(w.toneMapping),v.push(w.numClippingPlanes),v.push(w.numClipIntersection),v.push(w.depthPacking)}function x(v,w){o.disableAll(),w.instancing&&o.enable(0),w.instancingColor&&o.enable(1),w.instancingMorph&&o.enable(2),w.matcap&&o.enable(3),w.envMap&&o.enable(4),w.normalMapObjectSpace&&o.enable(5),w.normalMapTangentSpace&&o.enable(6),w.clearcoat&&o.enable(7),w.iridescence&&o.enable(8),w.alphaTest&&o.enable(9),w.vertexColors&&o.enable(10),w.vertexAlphas&&o.enable(11),w.vertexUv1s&&o.enable(12),w.vertexUv2s&&o.enable(13),w.vertexUv3s&&o.enable(14),w.vertexTangents&&o.enable(15),w.anisotropy&&o.enable(16),w.alphaHash&&o.enable(17),w.batching&&o.enable(18),w.dispersion&&o.enable(19),w.batchingColor&&o.enable(20),w.gradientMap&&o.enable(21),w.packedNormalMap&&o.enable(22),w.vertexNormals&&o.enable(23),v.push(o.mask),o.disableAll(),w.fog&&o.enable(0),w.useFog&&o.enable(1),w.flatShading&&o.enable(2),w.logarithmicDepthBuffer&&o.enable(3),w.reversedDepthBuffer&&o.enable(4),w.skinning&&o.enable(5),w.morphTargets&&o.enable(6),w.morphNormals&&o.enable(7),w.morphColors&&o.enable(8),w.premultipliedAlpha&&o.enable(9),w.shadowMapEnabled&&o.enable(10),w.doubleSided&&o.enable(11),w.flipSided&&o.enable(12),w.useDepthPacking&&o.enable(13),w.dithering&&o.enable(14),w.transmission&&o.enable(15),w.sheen&&o.enable(16),w.opaque&&o.enable(17),w.pointsUvs&&o.enable(18),w.decodeVideoTexture&&o.enable(19),w.decodeVideoTextureEmissive&&o.enable(20),w.alphaToCoverage&&o.enable(21),w.numLightProbeGrids>0&&o.enable(22),v.push(o.mask)}function y(v){const w=f[v.type];let N;if(w){const C=hr[w];N=ly.clone(C.uniforms)}else N=v.uniforms;return N}function b(v,w){let N=u.get(w);return N!==void 0?++N.usedTimes:(N=new jR(r,w,v,i),c.push(N),u.set(w,N)),N}function M(v){if(--v.usedTimes===0){const w=c.indexOf(v);c[w]=c[c.length-1],c.pop(),u.delete(v.cacheKey),v.destroy()}}function S(v){a.remove(v)}function E(){a.dispose()}return{getParameters:g,getProgramCacheKey:m,getUniforms:y,acquireProgram:b,releaseProgram:M,releaseShaderCache:S,programs:c,dispose:E}}function eC(){let r=new WeakMap;function e(o){return r.has(o)}function t(o){let a=r.get(o);return a===void 0&&(a={},r.set(o,a)),a}function n(o){r.delete(o)}function i(o,a,l){r.get(o)[a]=l}function s(){r=new WeakMap}return{has:e,get:t,remove:n,update:i,dispose:s}}function tC(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.material.id!==e.material.id?r.material.id-e.material.id:r.materialVariant!==e.materialVariant?r.materialVariant-e.materialVariant:r.z!==e.z?r.z-e.z:r.id-e.id}function x_(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.z!==e.z?e.z-r.z:r.id-e.id}function y_(){const r=[];let e=0;const t=[],n=[],i=[];function s(){e=0,t.length=0,n.length=0,i.length=0}function o(d){let f=0;return d.isInstancedMesh&&(f+=2),d.isSkinnedMesh&&(f+=1),f}function a(d,f,p,g,m,_){let x=r[e];return x===void 0?(x={id:d.id,object:d,geometry:f,material:p,materialVariant:o(d),groupOrder:g,renderOrder:d.renderOrder,z:m,group:_},r[e]=x):(x.id=d.id,x.object=d,x.geometry=f,x.material=p,x.materialVariant=o(d),x.groupOrder=g,x.renderOrder=d.renderOrder,x.z=m,x.group=_),e++,x}function l(d,f,p,g,m,_){const x=a(d,f,p,g,m,_);p.transmission>0?n.push(x):p.transparent===!0?i.push(x):t.push(x)}function c(d,f,p,g,m,_){const x=a(d,f,p,g,m,_);p.transmission>0?n.unshift(x):p.transparent===!0?i.unshift(x):t.unshift(x)}function u(d,f){t.length>1&&t.sort(d||tC),n.length>1&&n.sort(f||x_),i.length>1&&i.sort(f||x_)}function h(){for(let d=e,f=r.length;d<f;d++){const p=r[d];if(p.id===null)break;p.id=null,p.object=null,p.geometry=null,p.material=null,p.group=null}}return{opaque:t,transmissive:n,transparent:i,init:s,push:l,unshift:c,finish:h,sort:u}}function nC(){let r=new WeakMap;function e(n,i){const s=r.get(n);let o;return s===void 0?(o=new y_,r.set(n,[o])):i>=s.length?(o=new y_,s.push(o)):o=s[i],o}function t(){r=new WeakMap}return{get:e,dispose:t}}function iC(){const r={};return{get:function(e){if(r[e.id]!==void 0)return r[e.id];let t;switch(e.type){case"DirectionalLight":t={direction:new P,color:new We};break;case"SpotLight":t={position:new P,direction:new P,color:new We,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":t={position:new P,color:new We,distance:0,decay:0};break;case"HemisphereLight":t={direction:new P,skyColor:new We,groundColor:new We};break;case"RectAreaLight":t={color:new We,position:new P,halfWidth:new P,halfHeight:new P};break}return r[e.id]=t,t}}}function rC(){const r={};return{get:function(e){if(r[e.id]!==void 0)return r[e.id];let t;switch(e.type){case"DirectionalLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new pe};break;case"SpotLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new pe};break;case"PointLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new pe,shadowCameraNear:1,shadowCameraFar:1e3};break}return r[e.id]=t,t}}}let sC=0;function oC(r,e){return(e.castShadow?2:0)-(r.castShadow?2:0)+(e.map?1:0)-(r.map?1:0)}function aC(r){const e=new iC,t=rC(),n={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let c=0;c<9;c++)n.probe.push(new P);const i=new P,s=new pt,o=new pt;function a(c){let u=0,h=0,d=0;for(let w=0;w<9;w++)n.probe[w].set(0,0,0);let f=0,p=0,g=0,m=0,_=0,x=0,y=0,b=0,M=0,S=0,E=0;c.sort(oC);for(let w=0,N=c.length;w<N;w++){const C=c[w],F=C.color,V=C.intensity,z=C.distance;let U=null;if(C.shadow&&C.shadow.map&&(C.shadow.map.texture.format===In?U=C.shadow.map.texture:U=C.shadow.map.depthTexture||C.shadow.map.texture),C.isAmbientLight)u+=F.r*V,h+=F.g*V,d+=F.b*V;else if(C.isLightProbe){for(let B=0;B<9;B++)n.probe[B].addScaledVector(C.sh.coefficients[B],V);E++}else if(C.isDirectionalLight){const B=e.get(C);if(B.color.copy(C.color).multiplyScalar(C.intensity),C.castShadow){const D=C.shadow,X=t.get(C);X.shadowIntensity=D.intensity,X.shadowBias=D.bias,X.shadowNormalBias=D.normalBias,X.shadowRadius=D.radius,X.shadowMapSize=D.mapSize,n.directionalShadow[f]=X,n.directionalShadowMap[f]=U,n.directionalShadowMatrix[f]=C.shadow.matrix,x++}n.directional[f]=B,f++}else if(C.isSpotLight){const B=e.get(C);B.position.setFromMatrixPosition(C.matrixWorld),B.color.copy(F).multiplyScalar(V),B.distance=z,B.coneCos=Math.cos(C.angle),B.penumbraCos=Math.cos(C.angle*(1-C.penumbra)),B.decay=C.decay,n.spot[g]=B;const D=C.shadow;if(C.map&&(n.spotLightMap[M]=C.map,M++,D.updateMatrices(C),C.castShadow&&S++),n.spotLightMatrix[g]=D.matrix,C.castShadow){const X=t.get(C);X.shadowIntensity=D.intensity,X.shadowBias=D.bias,X.shadowNormalBias=D.normalBias,X.shadowRadius=D.radius,X.shadowMapSize=D.mapSize,n.spotShadow[g]=X,n.spotShadowMap[g]=U,b++}g++}else if(C.isRectAreaLight){const B=e.get(C);B.color.copy(F).multiplyScalar(V),B.halfWidth.set(C.width*.5,0,0),B.halfHeight.set(0,C.height*.5,0),n.rectArea[m]=B,m++}else if(C.isPointLight){const B=e.get(C);if(B.color.copy(C.color).multiplyScalar(C.intensity),B.distance=C.distance,B.decay=C.decay,C.castShadow){const D=C.shadow,X=t.get(C);X.shadowIntensity=D.intensity,X.shadowBias=D.bias,X.shadowNormalBias=D.normalBias,X.shadowRadius=D.radius,X.shadowMapSize=D.mapSize,X.shadowCameraNear=D.camera.near,X.shadowCameraFar=D.camera.far,n.pointShadow[p]=X,n.pointShadowMap[p]=U,n.pointShadowMatrix[p]=C.shadow.matrix,y++}n.point[p]=B,p++}else if(C.isHemisphereLight){const B=e.get(C);B.skyColor.copy(C.color).multiplyScalar(V),B.groundColor.copy(C.groundColor).multiplyScalar(V),n.hemi[_]=B,_++}}m>0&&(r.has("OES_texture_float_linear")===!0?(n.rectAreaLTC1=Ce.LTC_FLOAT_1,n.rectAreaLTC2=Ce.LTC_FLOAT_2):(n.rectAreaLTC1=Ce.LTC_HALF_1,n.rectAreaLTC2=Ce.LTC_HALF_2)),n.ambient[0]=u,n.ambient[1]=h,n.ambient[2]=d;const v=n.hash;(v.directionalLength!==f||v.pointLength!==p||v.spotLength!==g||v.rectAreaLength!==m||v.hemiLength!==_||v.numDirectionalShadows!==x||v.numPointShadows!==y||v.numSpotShadows!==b||v.numSpotMaps!==M||v.numLightProbes!==E)&&(n.directional.length=f,n.spot.length=g,n.rectArea.length=m,n.point.length=p,n.hemi.length=_,n.directionalShadow.length=x,n.directionalShadowMap.length=x,n.pointShadow.length=y,n.pointShadowMap.length=y,n.spotShadow.length=b,n.spotShadowMap.length=b,n.directionalShadowMatrix.length=x,n.pointShadowMatrix.length=y,n.spotLightMatrix.length=b+M-S,n.spotLightMap.length=M,n.numSpotLightShadowsWithMaps=S,n.numLightProbes=E,v.directionalLength=f,v.pointLength=p,v.spotLength=g,v.rectAreaLength=m,v.hemiLength=_,v.numDirectionalShadows=x,v.numPointShadows=y,v.numSpotShadows=b,v.numSpotMaps=M,v.numLightProbes=E,n.version=sC++)}function l(c,u){let h=0,d=0,f=0,p=0,g=0;const m=u.matrixWorldInverse;for(let _=0,x=c.length;_<x;_++){const y=c[_];if(y.isDirectionalLight){const b=n.directional[h];b.direction.setFromMatrixPosition(y.matrixWorld),i.setFromMatrixPosition(y.target.matrixWorld),b.direction.sub(i),b.direction.transformDirection(m),h++}else if(y.isSpotLight){const b=n.spot[f];b.position.setFromMatrixPosition(y.matrixWorld),b.position.applyMatrix4(m),b.direction.setFromMatrixPosition(y.matrixWorld),i.setFromMatrixPosition(y.target.matrixWorld),b.direction.sub(i),b.direction.transformDirection(m),f++}else if(y.isRectAreaLight){const b=n.rectArea[p];b.position.setFromMatrixPosition(y.matrixWorld),b.position.applyMatrix4(m),o.identity(),s.copy(y.matrixWorld),s.premultiply(m),o.extractRotation(s),b.halfWidth.set(y.width*.5,0,0),b.halfHeight.set(0,y.height*.5,0),b.halfWidth.applyMatrix4(o),b.halfHeight.applyMatrix4(o),p++}else if(y.isPointLight){const b=n.point[d];b.position.setFromMatrixPosition(y.matrixWorld),b.position.applyMatrix4(m),d++}else if(y.isHemisphereLight){const b=n.hemi[g];b.direction.setFromMatrixPosition(y.matrixWorld),b.direction.transformDirection(m),g++}}}return{setup:a,setupView:l,state:n}}function v_(r){const e=new aC(r),t=[],n=[],i=[];function s(d){h.camera=d,t.length=0,n.length=0,i.length=0}function o(d){t.push(d)}function a(d){n.push(d)}function l(d){i.push(d)}function c(){e.setup(t)}function u(d){e.setupView(t,d)}const h={lightsArray:t,shadowsArray:n,lightProbeGridArray:i,camera:null,lights:e,transmissionRenderTarget:{},textureUnits:0};return{init:s,state:h,setupLights:c,setupLightsView:u,pushLight:o,pushShadow:a,pushLightProbeGrid:l}}function lC(r){let e=new WeakMap;function t(i,s=0){const o=e.get(i);let a;return o===void 0?(a=new v_(r),e.set(i,[a])):s>=o.length?(a=new v_(r),o.push(a)):a=o[s],a}function n(){e=new WeakMap}return{get:t,dispose:n}}const cC=`void main() {
4061
+ `+Z)}else U!==""?ae("WebGLProgram: Program Info Log:",U):(B===""||D==="")&&(K=!1);K&&(C.diagnostics={runnable:X,programLog:U,vertexShader:{log:B,prefix:m},fragmentShader:{log:D,prefix:_}})}i.deleteShader(M),i.deleteShader(S),v=new ah(i,g),w=LR(i,g)}let v;this.getUniforms=function(){return v===void 0&&E(this),v};let w;this.getAttributes=function(){return w===void 0&&E(this),w};let N=t.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return N===!1&&(N=i.getProgramParameter(g,TR)),N},this.destroy=function(){n.releaseStatesOfProgram(this),i.deleteProgram(g),this.program=void 0},this.type=t.shaderType,this.name=t.shaderName,this.id=MR++,this.cacheKey=e,this.usedTimes=1,this.program=g,this.vertexShader=M,this.fragmentShader=S,this}let YR=0;class KR{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e){const t=e.vertexShader,n=e.fragmentShader,i=this._getShaderStage(t),s=this._getShaderStage(n),o=this._getShaderCacheForMaterial(e);return o.has(i)===!1&&(o.add(i),i.usedTimes++),o.has(s)===!1&&(o.add(s),s.usedTimes++),this}remove(e){const t=this.materialCache.get(e);for(const n of t)n.usedTimes--,n.usedTimes===0&&this.shaderCache.delete(n.code);return this.materialCache.delete(e),this}getVertexShaderID(e){return this._getShaderStage(e.vertexShader).id}getFragmentShaderID(e){return this._getShaderStage(e.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){const t=this.materialCache;let n=t.get(e);return n===void 0&&(n=new Set,t.set(e,n)),n}_getShaderStage(e){const t=this.shaderCache;let n=t.get(e);return n===void 0&&(n=new ZR(e),t.set(e,n)),n}}class ZR{constructor(e){this.id=YR++,this.code=e,this.usedTimes=0}}function QR(r){return r===In||r===Ls||r===Us}function JR(r,e,t,n,i,s){const o=new cm,a=new KR,l=new Set,c=[],u=new Map,h=n.logarithmicDepthBuffer;let d=n.precision;const f={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distance",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function p(v){return l.add(v),v===0?"uv":`uv${v}`}function g(v,w,N,C,F,V){const z=C.fog,U=F.geometry,B=v.isMeshStandardMaterial||v.isMeshLambertMaterial||v.isMeshPhongMaterial?C.environment:null,D=v.isMeshStandardMaterial||v.isMeshLambertMaterial&&!v.envMap||v.isMeshPhongMaterial&&!v.envMap,X=e.get(v.envMap||B,D),K=X&&X.mapping===mo?X.image.height:null,fe=f[v.type];v.precision!==null&&(d=n.getMaxPrecision(v.precision),d!==v.precision&&ae("WebGLProgram.getParameters:",v.precision,"not supported, using",d,"instead."));const Z=U.morphAttributes.position||U.morphAttributes.normal||U.morphAttributes.color,oe=Z!==void 0?Z.length:0;let Ee=0;U.morphAttributes.position!==void 0&&(Ee=1),U.morphAttributes.normal!==void 0&&(Ee=2),U.morphAttributes.color!==void 0&&(Ee=3);let ze,$,I,ne;if(fe){const ot=hr[fe];ze=ot.vertexShader,$=ot.fragmentShader}else ze=v.vertexShader,$=v.fragmentShader,a.update(v),I=a.getVertexShaderID(v),ne=a.getFragmentShaderID(v);const ue=r.getRenderTarget(),_e=r.state.buffers.depth.getReversed(),Ue=F.isInstancedMesh===!0,Ae=F.isBatchedMesh===!0,dt=!!v.map,tt=!!v.matcap,gt=!!X,At=!!v.aoMap,nt=!!v.lightMap,Bt=!!v.bumpMap,Ut=!!v.normalMap,pi=!!v.displacementMap,H=!!v.emissiveMap,vn=!!v.metalnessMap,yt=!!v.roughnessMap,qt=v.anisotropy>0,Re=v.clearcoat>0,on=v.dispersion>0,R=v.iridescence>0,T=v.sheen>0,q=v.transmission>0,he=qt&&!!v.anisotropyMap,ge=Re&&!!v.clearcoatMap,xe=Re&&!!v.clearcoatNormalMap,Me=Re&&!!v.clearcoatRoughnessMap,se=R&&!!v.iridescenceMap,de=R&&!!v.iridescenceThicknessMap,Le=T&&!!v.sheenColorMap,Be=T&&!!v.sheenRoughnessMap,Se=!!v.specularMap,ye=!!v.specularColorMap,it=!!v.specularIntensityMap,ut=q&&!!v.transmissionMap,Tt=q&&!!v.thicknessMap,O=!!v.gradientMap,ve=!!v.alphaMap,le=v.alphaTest>0,Fe=!!v.alphaHash,Te=!!v.extensions;let me=Fn;v.toneMapped&&(ue===null||ue.isXRRenderTarget===!0)&&(me=r.toneMapping);const $e={shaderID:fe,shaderType:v.type,shaderName:v.name,vertexShader:ze,fragmentShader:$,defines:v.defines,customVertexShaderID:I,customFragmentShaderID:ne,isRawShaderMaterial:v.isRawShaderMaterial===!0,glslVersion:v.glslVersion,precision:d,batching:Ae,batchingColor:Ae&&F._colorsTexture!==null,instancing:Ue,instancingColor:Ue&&F.instanceColor!==null,instancingMorph:Ue&&F.morphTexture!==null,outputColorSpace:ue===null?r.outputColorSpace:ue.isXRRenderTarget===!0?ue.texture.colorSpace:Ye.workingColorSpace,alphaToCoverage:!!v.alphaToCoverage,map:dt,matcap:tt,envMap:gt,envMapMode:gt&&X.mapping,envMapCubeUVHeight:K,aoMap:At,lightMap:nt,bumpMap:Bt,normalMap:Ut,displacementMap:pi,emissiveMap:H,normalMapObjectSpace:Ut&&v.normalMapType===j0,normalMapTangentSpace:Ut&&v.normalMapType===ji,packedNormalMap:Ut&&v.normalMapType===ji&&QR(v.normalMap.format),metalnessMap:vn,roughnessMap:yt,anisotropy:qt,anisotropyMap:he,clearcoat:Re,clearcoatMap:ge,clearcoatNormalMap:xe,clearcoatRoughnessMap:Me,dispersion:on,iridescence:R,iridescenceMap:se,iridescenceThicknessMap:de,sheen:T,sheenColorMap:Le,sheenRoughnessMap:Be,specularMap:Se,specularColorMap:ye,specularIntensityMap:it,transmission:q,transmissionMap:ut,thicknessMap:Tt,gradientMap:O,opaque:v.transparent===!1&&v.blending===ti&&v.alphaToCoverage===!1,alphaMap:ve,alphaTest:le,alphaHash:Fe,combine:v.combine,mapUv:dt&&p(v.map.channel),aoMapUv:At&&p(v.aoMap.channel),lightMapUv:nt&&p(v.lightMap.channel),bumpMapUv:Bt&&p(v.bumpMap.channel),normalMapUv:Ut&&p(v.normalMap.channel),displacementMapUv:pi&&p(v.displacementMap.channel),emissiveMapUv:H&&p(v.emissiveMap.channel),metalnessMapUv:vn&&p(v.metalnessMap.channel),roughnessMapUv:yt&&p(v.roughnessMap.channel),anisotropyMapUv:he&&p(v.anisotropyMap.channel),clearcoatMapUv:ge&&p(v.clearcoatMap.channel),clearcoatNormalMapUv:xe&&p(v.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:Me&&p(v.clearcoatRoughnessMap.channel),iridescenceMapUv:se&&p(v.iridescenceMap.channel),iridescenceThicknessMapUv:de&&p(v.iridescenceThicknessMap.channel),sheenColorMapUv:Le&&p(v.sheenColorMap.channel),sheenRoughnessMapUv:Be&&p(v.sheenRoughnessMap.channel),specularMapUv:Se&&p(v.specularMap.channel),specularColorMapUv:ye&&p(v.specularColorMap.channel),specularIntensityMapUv:it&&p(v.specularIntensityMap.channel),transmissionMapUv:ut&&p(v.transmissionMap.channel),thicknessMapUv:Tt&&p(v.thicknessMap.channel),alphaMapUv:ve&&p(v.alphaMap.channel),vertexTangents:!!U.attributes.tangent&&(Ut||qt),vertexNormals:!!U.attributes.normal,vertexColors:v.vertexColors,vertexAlphas:v.vertexColors===!0&&!!U.attributes.color&&U.attributes.color.itemSize===4,pointsUvs:F.isPoints===!0&&!!U.attributes.uv&&(dt||ve),fog:!!z,useFog:v.fog===!0,fogExp2:!!z&&z.isFogExp2,flatShading:v.wireframe===!1&&(v.flatShading===!0||U.attributes.normal===void 0&&Ut===!1&&(v.isMeshLambertMaterial||v.isMeshPhongMaterial||v.isMeshStandardMaterial||v.isMeshPhysicalMaterial)),sizeAttenuation:v.sizeAttenuation===!0,logarithmicDepthBuffer:h,reversedDepthBuffer:_e,skinning:F.isSkinnedMesh===!0,morphTargets:U.morphAttributes.position!==void 0,morphNormals:U.morphAttributes.normal!==void 0,morphColors:U.morphAttributes.color!==void 0,morphTargetsCount:oe,morphTextureStride:Ee,numDirLights:w.directional.length,numPointLights:w.point.length,numSpotLights:w.spot.length,numSpotLightMaps:w.spotLightMap.length,numRectAreaLights:w.rectArea.length,numHemiLights:w.hemi.length,numDirLightShadows:w.directionalShadowMap.length,numPointLightShadows:w.pointShadowMap.length,numSpotLightShadows:w.spotShadowMap.length,numSpotLightShadowsWithMaps:w.numSpotLightShadowsWithMaps,numLightProbes:w.numLightProbes,numLightProbeGrids:V.length,numClippingPlanes:s.numPlanes,numClipIntersection:s.numIntersection,dithering:v.dithering,shadowMapEnabled:r.shadowMap.enabled&&N.length>0,shadowMapType:r.shadowMap.type,toneMapping:me,decodeVideoTexture:dt&&v.map.isVideoTexture===!0&&Ye.getTransfer(v.map.colorSpace)===Pe,decodeVideoTextureEmissive:H&&v.emissiveMap.isVideoTexture===!0&&Ye.getTransfer(v.emissiveMap.colorSpace)===Pe,premultipliedAlpha:v.premultipliedAlpha,doubleSided:v.side===Nn,flipSided:v.side===Lt,useDepthPacking:v.depthPacking>=0,depthPacking:v.depthPacking||0,index0AttributeName:v.index0AttributeName,extensionClipCullDistance:Te&&v.extensions.clipCullDistance===!0&&t.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(Te&&v.extensions.multiDraw===!0||Ae)&&t.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:t.has("KHR_parallel_shader_compile"),customProgramCacheKey:v.customProgramCacheKey()};return $e.vertexUv1s=l.has(1),$e.vertexUv2s=l.has(2),$e.vertexUv3s=l.has(3),l.clear(),$e}function m(v){const w=[];if(v.shaderID?w.push(v.shaderID):(w.push(v.customVertexShaderID),w.push(v.customFragmentShaderID)),v.defines!==void 0)for(const N in v.defines)w.push(N),w.push(v.defines[N]);return v.isRawShaderMaterial===!1&&(_(w,v),x(w,v),w.push(r.outputColorSpace)),w.push(v.customProgramCacheKey),w.join()}function _(v,w){v.push(w.precision),v.push(w.outputColorSpace),v.push(w.envMapMode),v.push(w.envMapCubeUVHeight),v.push(w.mapUv),v.push(w.alphaMapUv),v.push(w.lightMapUv),v.push(w.aoMapUv),v.push(w.bumpMapUv),v.push(w.normalMapUv),v.push(w.displacementMapUv),v.push(w.emissiveMapUv),v.push(w.metalnessMapUv),v.push(w.roughnessMapUv),v.push(w.anisotropyMapUv),v.push(w.clearcoatMapUv),v.push(w.clearcoatNormalMapUv),v.push(w.clearcoatRoughnessMapUv),v.push(w.iridescenceMapUv),v.push(w.iridescenceThicknessMapUv),v.push(w.sheenColorMapUv),v.push(w.sheenRoughnessMapUv),v.push(w.specularMapUv),v.push(w.specularColorMapUv),v.push(w.specularIntensityMapUv),v.push(w.transmissionMapUv),v.push(w.thicknessMapUv),v.push(w.combine),v.push(w.fogExp2),v.push(w.sizeAttenuation),v.push(w.morphTargetsCount),v.push(w.morphAttributeCount),v.push(w.numDirLights),v.push(w.numPointLights),v.push(w.numSpotLights),v.push(w.numSpotLightMaps),v.push(w.numHemiLights),v.push(w.numRectAreaLights),v.push(w.numDirLightShadows),v.push(w.numPointLightShadows),v.push(w.numSpotLightShadows),v.push(w.numSpotLightShadowsWithMaps),v.push(w.numLightProbes),v.push(w.shadowMapType),v.push(w.toneMapping),v.push(w.numClippingPlanes),v.push(w.numClipIntersection),v.push(w.depthPacking)}function x(v,w){o.disableAll(),w.instancing&&o.enable(0),w.instancingColor&&o.enable(1),w.instancingMorph&&o.enable(2),w.matcap&&o.enable(3),w.envMap&&o.enable(4),w.normalMapObjectSpace&&o.enable(5),w.normalMapTangentSpace&&o.enable(6),w.clearcoat&&o.enable(7),w.iridescence&&o.enable(8),w.alphaTest&&o.enable(9),w.vertexColors&&o.enable(10),w.vertexAlphas&&o.enable(11),w.vertexUv1s&&o.enable(12),w.vertexUv2s&&o.enable(13),w.vertexUv3s&&o.enable(14),w.vertexTangents&&o.enable(15),w.anisotropy&&o.enable(16),w.alphaHash&&o.enable(17),w.batching&&o.enable(18),w.dispersion&&o.enable(19),w.batchingColor&&o.enable(20),w.gradientMap&&o.enable(21),w.packedNormalMap&&o.enable(22),w.vertexNormals&&o.enable(23),v.push(o.mask),o.disableAll(),w.fog&&o.enable(0),w.useFog&&o.enable(1),w.flatShading&&o.enable(2),w.logarithmicDepthBuffer&&o.enable(3),w.reversedDepthBuffer&&o.enable(4),w.skinning&&o.enable(5),w.morphTargets&&o.enable(6),w.morphNormals&&o.enable(7),w.morphColors&&o.enable(8),w.premultipliedAlpha&&o.enable(9),w.shadowMapEnabled&&o.enable(10),w.doubleSided&&o.enable(11),w.flipSided&&o.enable(12),w.useDepthPacking&&o.enable(13),w.dithering&&o.enable(14),w.transmission&&o.enable(15),w.sheen&&o.enable(16),w.opaque&&o.enable(17),w.pointsUvs&&o.enable(18),w.decodeVideoTexture&&o.enable(19),w.decodeVideoTextureEmissive&&o.enable(20),w.alphaToCoverage&&o.enable(21),w.numLightProbeGrids>0&&o.enable(22),v.push(o.mask)}function y(v){const w=f[v.type];let N;if(w){const C=hr[w];N=ly.clone(C.uniforms)}else N=v.uniforms;return N}function b(v,w){let N=u.get(w);return N!==void 0?++N.usedTimes:(N=new jR(r,w,v,i),c.push(N),u.set(w,N)),N}function M(v){if(--v.usedTimes===0){const w=c.indexOf(v);c[w]=c[c.length-1],c.pop(),u.delete(v.cacheKey),v.destroy()}}function S(v){a.remove(v)}function E(){a.dispose()}return{getParameters:g,getProgramCacheKey:m,getUniforms:y,acquireProgram:b,releaseProgram:M,releaseShaderCache:S,programs:c,dispose:E}}function eC(){let r=new WeakMap;function e(o){return r.has(o)}function t(o){let a=r.get(o);return a===void 0&&(a={},r.set(o,a)),a}function n(o){r.delete(o)}function i(o,a,l){r.get(o)[a]=l}function s(){r=new WeakMap}return{has:e,get:t,remove:n,update:i,dispose:s}}function tC(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.material.id!==e.material.id?r.material.id-e.material.id:r.materialVariant!==e.materialVariant?r.materialVariant-e.materialVariant:r.z!==e.z?r.z-e.z:r.id-e.id}function x_(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.z!==e.z?e.z-r.z:r.id-e.id}function y_(){const r=[];let e=0;const t=[],n=[],i=[];function s(){e=0,t.length=0,n.length=0,i.length=0}function o(d){let f=0;return d.isInstancedMesh&&(f+=2),d.isSkinnedMesh&&(f+=1),f}function a(d,f,p,g,m,_){let x=r[e];return x===void 0?(x={id:d.id,object:d,geometry:f,material:p,materialVariant:o(d),groupOrder:g,renderOrder:d.renderOrder,z:m,group:_},r[e]=x):(x.id=d.id,x.object=d,x.geometry=f,x.material=p,x.materialVariant=o(d),x.groupOrder=g,x.renderOrder=d.renderOrder,x.z=m,x.group=_),e++,x}function l(d,f,p,g,m,_){const x=a(d,f,p,g,m,_);p.transmission>0?n.push(x):p.transparent===!0?i.push(x):t.push(x)}function c(d,f,p,g,m,_){const x=a(d,f,p,g,m,_);p.transmission>0?n.unshift(x):p.transparent===!0?i.unshift(x):t.unshift(x)}function u(d,f){t.length>1&&t.sort(d||tC),n.length>1&&n.sort(f||x_),i.length>1&&i.sort(f||x_)}function h(){for(let d=e,f=r.length;d<f;d++){const p=r[d];if(p.id===null)break;p.id=null,p.object=null,p.geometry=null,p.material=null,p.group=null}}return{opaque:t,transmissive:n,transparent:i,init:s,push:l,unshift:c,finish:h,sort:u}}function nC(){let r=new WeakMap;function e(n,i){const s=r.get(n);let o;return s===void 0?(o=new y_,r.set(n,[o])):i>=s.length?(o=new y_,s.push(o)):o=s[i],o}function t(){r=new WeakMap}return{get:e,dispose:t}}function iC(){const r={};return{get:function(e){if(r[e.id]!==void 0)return r[e.id];let t;switch(e.type){case"DirectionalLight":t={direction:new P,color:new We};break;case"SpotLight":t={position:new P,direction:new P,color:new We,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":t={position:new P,color:new We,distance:0,decay:0};break;case"HemisphereLight":t={direction:new P,skyColor:new We,groundColor:new We};break;case"RectAreaLight":t={color:new We,position:new P,halfWidth:new P,halfHeight:new P};break}return r[e.id]=t,t}}}function rC(){const r={};return{get:function(e){if(r[e.id]!==void 0)return r[e.id];let t;switch(e.type){case"DirectionalLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new pe};break;case"SpotLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new pe};break;case"PointLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new pe,shadowCameraNear:1,shadowCameraFar:1e3};break}return r[e.id]=t,t}}}let sC=0;function oC(r,e){return(e.castShadow?2:0)-(r.castShadow?2:0)+(e.map?1:0)-(r.map?1:0)}function aC(r){const e=new iC,t=rC(),n={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let c=0;c<9;c++)n.probe.push(new P);const i=new P,s=new pt,o=new pt;function a(c){let u=0,h=0,d=0;for(let w=0;w<9;w++)n.probe[w].set(0,0,0);let f=0,p=0,g=0,m=0,_=0,x=0,y=0,b=0,M=0,S=0,E=0;c.sort(oC);for(let w=0,N=c.length;w<N;w++){const C=c[w],F=C.color,V=C.intensity,z=C.distance;let U=null;if(C.shadow&&C.shadow.map&&(C.shadow.map.texture.format===In?U=C.shadow.map.texture:U=C.shadow.map.depthTexture||C.shadow.map.texture),C.isAmbientLight)u+=F.r*V,h+=F.g*V,d+=F.b*V;else if(C.isLightProbe){for(let B=0;B<9;B++)n.probe[B].addScaledVector(C.sh.coefficients[B],V);E++}else if(C.isDirectionalLight){const B=e.get(C);if(B.color.copy(C.color).multiplyScalar(C.intensity),C.castShadow){const D=C.shadow,X=t.get(C);X.shadowIntensity=D.intensity,X.shadowBias=D.bias,X.shadowNormalBias=D.normalBias,X.shadowRadius=D.radius,X.shadowMapSize=D.mapSize,n.directionalShadow[f]=X,n.directionalShadowMap[f]=U,n.directionalShadowMatrix[f]=C.shadow.matrix,x++}n.directional[f]=B,f++}else if(C.isSpotLight){const B=e.get(C);B.position.setFromMatrixPosition(C.matrixWorld),B.color.copy(F).multiplyScalar(V),B.distance=z,B.coneCos=Math.cos(C.angle),B.penumbraCos=Math.cos(C.angle*(1-C.penumbra)),B.decay=C.decay,n.spot[g]=B;const D=C.shadow;if(C.map&&(n.spotLightMap[M]=C.map,M++,D.updateMatrices(C),C.castShadow&&S++),n.spotLightMatrix[g]=D.matrix,C.castShadow){const X=t.get(C);X.shadowIntensity=D.intensity,X.shadowBias=D.bias,X.shadowNormalBias=D.normalBias,X.shadowRadius=D.radius,X.shadowMapSize=D.mapSize,n.spotShadow[g]=X,n.spotShadowMap[g]=U,b++}g++}else if(C.isRectAreaLight){const B=e.get(C);B.color.copy(F).multiplyScalar(V),B.halfWidth.set(C.width*.5,0,0),B.halfHeight.set(0,C.height*.5,0),n.rectArea[m]=B,m++}else if(C.isPointLight){const B=e.get(C);if(B.color.copy(C.color).multiplyScalar(C.intensity),B.distance=C.distance,B.decay=C.decay,C.castShadow){const D=C.shadow,X=t.get(C);X.shadowIntensity=D.intensity,X.shadowBias=D.bias,X.shadowNormalBias=D.normalBias,X.shadowRadius=D.radius,X.shadowMapSize=D.mapSize,X.shadowCameraNear=D.camera.near,X.shadowCameraFar=D.camera.far,n.pointShadow[p]=X,n.pointShadowMap[p]=U,n.pointShadowMatrix[p]=C.shadow.matrix,y++}n.point[p]=B,p++}else if(C.isHemisphereLight){const B=e.get(C);B.skyColor.copy(C.color).multiplyScalar(V),B.groundColor.copy(C.groundColor).multiplyScalar(V),n.hemi[_]=B,_++}}m>0&&(r.has("OES_texture_float_linear")===!0?(n.rectAreaLTC1=Ce.LTC_FLOAT_1,n.rectAreaLTC2=Ce.LTC_FLOAT_2):(n.rectAreaLTC1=Ce.LTC_HALF_1,n.rectAreaLTC2=Ce.LTC_HALF_2)),n.ambient[0]=u,n.ambient[1]=h,n.ambient[2]=d;const v=n.hash;(v.directionalLength!==f||v.pointLength!==p||v.spotLength!==g||v.rectAreaLength!==m||v.hemiLength!==_||v.numDirectionalShadows!==x||v.numPointShadows!==y||v.numSpotShadows!==b||v.numSpotMaps!==M||v.numLightProbes!==E)&&(n.directional.length=f,n.spot.length=g,n.rectArea.length=m,n.point.length=p,n.hemi.length=_,n.directionalShadow.length=x,n.directionalShadowMap.length=x,n.pointShadow.length=y,n.pointShadowMap.length=y,n.spotShadow.length=b,n.spotShadowMap.length=b,n.directionalShadowMatrix.length=x,n.pointShadowMatrix.length=y,n.spotLightMatrix.length=b+M-S,n.spotLightMap.length=M,n.numSpotLightShadowsWithMaps=S,n.numLightProbes=E,v.directionalLength=f,v.pointLength=p,v.spotLength=g,v.rectAreaLength=m,v.hemiLength=_,v.numDirectionalShadows=x,v.numPointShadows=y,v.numSpotShadows=b,v.numSpotMaps=M,v.numLightProbes=E,n.version=sC++)}function l(c,u){let h=0,d=0,f=0,p=0,g=0;const m=u.matrixWorldInverse;for(let _=0,x=c.length;_<x;_++){const y=c[_];if(y.isDirectionalLight){const b=n.directional[h];b.direction.setFromMatrixPosition(y.matrixWorld),i.setFromMatrixPosition(y.target.matrixWorld),b.direction.sub(i),b.direction.transformDirection(m),h++}else if(y.isSpotLight){const b=n.spot[f];b.position.setFromMatrixPosition(y.matrixWorld),b.position.applyMatrix4(m),b.direction.setFromMatrixPosition(y.matrixWorld),i.setFromMatrixPosition(y.target.matrixWorld),b.direction.sub(i),b.direction.transformDirection(m),f++}else if(y.isRectAreaLight){const b=n.rectArea[p];b.position.setFromMatrixPosition(y.matrixWorld),b.position.applyMatrix4(m),o.identity(),s.copy(y.matrixWorld),s.premultiply(m),o.extractRotation(s),b.halfWidth.set(y.width*.5,0,0),b.halfHeight.set(0,y.height*.5,0),b.halfWidth.applyMatrix4(o),b.halfHeight.applyMatrix4(o),p++}else if(y.isPointLight){const b=n.point[d];b.position.setFromMatrixPosition(y.matrixWorld),b.position.applyMatrix4(m),d++}else if(y.isHemisphereLight){const b=n.hemi[g];b.direction.setFromMatrixPosition(y.matrixWorld),b.direction.transformDirection(m),g++}}}return{setup:a,setupView:l,state:n}}function v_(r){const e=new aC(r),t=[],n=[],i=[];function s(d){h.camera=d,t.length=0,n.length=0,i.length=0}function o(d){t.push(d)}function a(d){n.push(d)}function l(d){i.push(d)}function c(){e.setup(t)}function u(d){e.setupView(t,d)}const h={lightsArray:t,shadowsArray:n,lightProbeGridArray:i,camera:null,lights:e,transmissionRenderTarget:{},textureUnits:0};return{init:s,state:h,setupLights:c,setupLightsView:u,pushLight:o,pushShadow:a,pushLightProbeGrid:l}}function lC(r){let e=new WeakMap;function t(i,s=0){const o=e.get(i);let a;return o===void 0?(a=new v_(r),e.set(i,[a])):s>=o.length?(a=new v_(r),o.push(a)):a=o[s],a}function n(){e=new WeakMap}return{get:t,dispose:n}}const cC=`void main() {
4062
4062
  gl_Position = vec4( position, 1.0 );
4063
4063
  }`,uC=`uniform sampler2D shadow_pass;
4064
4064
  uniform vec2 resolution;
@@ -4085,7 +4085,7 @@ void main() {
4085
4085
  squared_mean = squared_mean / samples;
4086
4086
  float std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );
4087
4087
  gl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );
4088
- }`,hC=[new P(1,0,0),new P(-1,0,0),new P(0,1,0),new P(0,-1,0),new P(0,0,1),new P(0,0,-1)],dC=[new P(0,-1,0),new P(0,-1,0),new P(0,0,1),new P(0,0,-1),new P(0,-1,0),new P(0,-1,0)],b_=new pt,wl=new P,zd=new P;function fC(r,e,t){let n=new Ic;const i=new pe,s=new pe,o=new rt,a=new fM,l=new pM,c={},u=t.maxTextureSize,h={[ri]:Lt,[Lt]:ri,[Nn]:Nn},d=new ki({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new pe},radius:{value:4}},vertexShader:cC,fragmentShader:uC}),f=d.clone();f.defines.HORIZONTAL_PASS=1;const p=new An;p.setAttribute("position",new Bn(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const g=new _n(p,d),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=fa;let _=this.type;this.render=function(S,E,v){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||S.length===0)return;this.type===G0&&(ae("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=fa);const w=r.getRenderTarget(),N=r.getActiveCubeFace(),C=r.getActiveMipmapLevel(),F=r.state;F.setBlending(Pn),F.buffers.depth.getReversed()===!0?F.buffers.color.setClear(0,0,0,0):F.buffers.color.setClear(1,1,1,1),F.buffers.depth.setTest(!0),F.setScissorTest(!1);const V=_!==this.type;V&&E.traverse(function(z){z.material&&(Array.isArray(z.material)?z.material.forEach(U=>U.needsUpdate=!0):z.material.needsUpdate=!0)});for(let z=0,U=S.length;z<U;z++){const B=S[z],D=B.shadow;if(D===void 0){ae("WebGLShadowMap:",B,"has no shadow.");continue}if(D.autoUpdate===!1&&D.needsUpdate===!1)continue;i.copy(D.mapSize);const X=D.getFrameExtents();i.multiply(X),s.copy(D.mapSize),(i.x>u||i.y>u)&&(i.x>u&&(s.x=Math.floor(u/X.x),i.x=s.x*X.x,D.mapSize.x=s.x),i.y>u&&(s.y=Math.floor(u/X.y),i.y=s.y*X.y,D.mapSize.y=s.y));const K=r.state.buffers.depth.getReversed();if(D.camera._reversedDepth=K,D.map===null||V===!0){if(D.map!==null&&(D.map.depthTexture!==null&&(D.map.depthTexture.dispose(),D.map.depthTexture=null),D.map.dispose()),this.type===_r){if(B.isPointLight){ae("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}D.map=new Yi(i.x,i.y,{format:In,type:tn,minFilter:Nt,magFilter:Nt,generateMipmaps:!1}),D.map.texture.name=B.name+".shadowMap",D.map.depthTexture=new jn(i.x,i.y,Qt),D.map.depthTexture.name=B.name+".shadowMapDepth",D.map.depthTexture.format=Dn,D.map.depthTexture.compareFunction=null,D.map.depthTexture.minFilter=Mt,D.map.depthTexture.magFilter=Mt}else B.isPointLight?(D.map=new vy(i.x),D.map.depthTexture=new iy(i.x,Ct)):(D.map=new Yi(i.x,i.y),D.map.depthTexture=new jn(i.x,i.y,Ct)),D.map.depthTexture.name=B.name+".shadowMap",D.map.depthTexture.format=Dn,this.type===fa?(D.map.depthTexture.compareFunction=K?Zr:Os,D.map.depthTexture.minFilter=Nt,D.map.depthTexture.magFilter=Nt):(D.map.depthTexture.compareFunction=null,D.map.depthTexture.minFilter=Mt,D.map.depthTexture.magFilter=Mt);D.camera.updateProjectionMatrix()}const fe=D.map.isWebGLCubeRenderTarget?6:1;for(let Z=0;Z<fe;Z++){if(D.map.isWebGLCubeRenderTarget)r.setRenderTarget(D.map,Z),r.clear();else{Z===0&&(r.setRenderTarget(D.map),r.clear());const oe=D.getViewport(Z);o.set(s.x*oe.x,s.y*oe.y,s.x*oe.z,s.y*oe.w),F.viewport(o)}if(B.isPointLight){const oe=D.camera,Ee=D.matrix,ze=B.distance||oe.far;ze!==oe.far&&(oe.far=ze,oe.updateProjectionMatrix()),wl.setFromMatrixPosition(B.matrixWorld),oe.position.copy(wl),zd.copy(oe.position),zd.add(hC[Z]),oe.up.copy(dC[Z]),oe.lookAt(zd),oe.updateMatrixWorld(),Ee.makeTranslation(-wl.x,-wl.y,-wl.z),b_.multiplyMatrices(oe.projectionMatrix,oe.matrixWorldInverse),D._frustum.setFromProjectionMatrix(b_,oe.coordinateSystem,oe.reversedDepth)}else D.updateMatrices(B);n=D.getFrustum(),b(E,v,D.camera,B,this.type)}D.isPointLightShadow!==!0&&this.type===_r&&x(D,v),D.needsUpdate=!1}_=this.type,m.needsUpdate=!1,r.setRenderTarget(w,N,C)};function x(S,E){const v=e.update(g);d.defines.VSM_SAMPLES!==S.blurSamples&&(d.defines.VSM_SAMPLES=S.blurSamples,f.defines.VSM_SAMPLES=S.blurSamples,d.needsUpdate=!0,f.needsUpdate=!0),S.mapPass===null&&(S.mapPass=new Yi(i.x,i.y,{format:In,type:tn})),d.uniforms.shadow_pass.value=S.map.depthTexture,d.uniforms.resolution.value=S.mapSize,d.uniforms.radius.value=S.radius,r.setRenderTarget(S.mapPass),r.clear(),r.renderBufferDirect(E,null,v,d,g,null),f.uniforms.shadow_pass.value=S.mapPass.texture,f.uniforms.resolution.value=S.mapSize,f.uniforms.radius.value=S.radius,r.setRenderTarget(S.map),r.clear(),r.renderBufferDirect(E,null,v,f,g,null)}function y(S,E,v,w){let N=null;const C=v.isPointLight===!0?S.customDistanceMaterial:S.customDepthMaterial;if(C!==void 0)N=C;else if(N=v.isPointLight===!0?l:a,r.localClippingEnabled&&E.clipShadows===!0&&Array.isArray(E.clippingPlanes)&&E.clippingPlanes.length!==0||E.displacementMap&&E.displacementScale!==0||E.alphaMap&&E.alphaTest>0||E.map&&E.alphaTest>0||E.alphaToCoverage===!0){const F=N.uuid,V=E.uuid;let z=c[F];z===void 0&&(z={},c[F]=z);let U=z[V];U===void 0&&(U=N.clone(),z[V]=U,E.addEventListener("dispose",M)),N=U}if(N.visible=E.visible,N.wireframe=E.wireframe,w===_r?N.side=E.shadowSide!==null?E.shadowSide:E.side:N.side=E.shadowSide!==null?E.shadowSide:h[E.side],N.alphaMap=E.alphaMap,N.alphaTest=E.alphaToCoverage===!0?.5:E.alphaTest,N.map=E.map,N.clipShadows=E.clipShadows,N.clippingPlanes=E.clippingPlanes,N.clipIntersection=E.clipIntersection,N.displacementMap=E.displacementMap,N.displacementScale=E.displacementScale,N.displacementBias=E.displacementBias,N.wireframeLinewidth=E.wireframeLinewidth,N.linewidth=E.linewidth,v.isPointLight===!0&&N.isMeshDistanceMaterial===!0){const F=r.properties.get(N);F.light=v}return N}function b(S,E,v,w,N){if(S.visible===!1)return;if(S.layers.test(E.layers)&&(S.isMesh||S.isLine||S.isPoints)&&(S.castShadow||S.receiveShadow&&N===_r)&&(!S.frustumCulled||n.intersectsObject(S))){S.modelViewMatrix.multiplyMatrices(v.matrixWorldInverse,S.matrixWorld);const V=e.update(S),z=S.material;if(Array.isArray(z)){const U=V.groups;for(let B=0,D=U.length;B<D;B++){const X=U[B],K=z[X.materialIndex];if(K&&K.visible){const fe=y(S,K,w,N);S.onBeforeShadow(r,S,E,v,V,fe,X),r.renderBufferDirect(v,null,V,fe,S,X),S.onAfterShadow(r,S,E,v,V,fe,X)}}}else if(z.visible){const U=y(S,z,w,N);S.onBeforeShadow(r,S,E,v,V,U,null),r.renderBufferDirect(v,null,V,U,S,null),S.onAfterShadow(r,S,E,v,V,U,null)}}const F=S.children;for(let V=0,z=F.length;V<z;V++)b(F[V],E,v,w,N)}function M(S){S.target.removeEventListener("dispose",M);for(const v in c){const w=c[v],N=S.target.uuid;N in w&&(w[N].dispose(),delete w[N])}}}function pC(r,e){function t(){let O=!1;const ve=new rt;let le=null;const Fe=new rt(0,0,0,0);return{setMask:function(Te){le!==Te&&!O&&(r.colorMask(Te,Te,Te,Te),le=Te)},setLocked:function(Te){O=Te},setClear:function(Te,me,$e,ot,cn){cn===!0&&(Te*=ot,me*=ot,$e*=ot),ve.set(Te,me,$e,ot),Fe.equals(ve)===!1&&(r.clearColor(Te,me,$e,ot),Fe.copy(ve))},reset:function(){O=!1,le=null,Fe.set(-1,0,0,0)}}}function n(){let O=!1,ve=!1,le=null,Fe=null,Te=null;return{setReversed:function(me){if(ve!==me){const $e=e.get("EXT_clip_control");me?$e.clipControlEXT($e.LOWER_LEFT_EXT,$e.ZERO_TO_ONE_EXT):$e.clipControlEXT($e.LOWER_LEFT_EXT,$e.NEGATIVE_ONE_TO_ONE_EXT),ve=me;const ot=Te;Te=null,this.setClear(ot)}},getReversed:function(){return ve},setTest:function(me){me?ue(r.DEPTH_TEST):_e(r.DEPTH_TEST)},setMask:function(me){le!==me&&!O&&(r.depthMask(me),le=me)},setFunc:function(me){if(ve&&(me=sm[me]),Fe!==me){switch(me){case lc:r.depthFunc(r.NEVER);break;case cc:r.depthFunc(r.ALWAYS);break;case uc:r.depthFunc(r.LESS);break;case Ds:r.depthFunc(r.LEQUAL);break;case hc:r.depthFunc(r.EQUAL);break;case dc:r.depthFunc(r.GEQUAL);break;case fc:r.depthFunc(r.GREATER);break;case pc:r.depthFunc(r.NOTEQUAL);break;default:r.depthFunc(r.LEQUAL)}Fe=me}},setLocked:function(me){O=me},setClear:function(me){Te!==me&&(Te=me,ve&&(me=1-me),r.clearDepth(me))},reset:function(){O=!1,le=null,Fe=null,Te=null,ve=!1}}}function i(){let O=!1,ve=null,le=null,Fe=null,Te=null,me=null,$e=null,ot=null,cn=null;return{setTest:function(Ot){O||(Ot?ue(r.STENCIL_TEST):_e(r.STENCIL_TEST))},setMask:function(Ot){ve!==Ot&&!O&&(r.stencilMask(Ot),ve=Ot)},setFunc:function(Ot,Nr,Zi){(le!==Ot||Fe!==Nr||Te!==Zi)&&(r.stencilFunc(Ot,Nr,Zi),le=Ot,Fe=Nr,Te=Zi)},setOp:function(Ot,Nr,Zi){(me!==Ot||$e!==Nr||ot!==Zi)&&(r.stencilOp(Ot,Nr,Zi),me=Ot,$e=Nr,ot=Zi)},setLocked:function(Ot){O=Ot},setClear:function(Ot){cn!==Ot&&(r.clearStencil(Ot),cn=Ot)},reset:function(){O=!1,ve=null,le=null,Fe=null,Te=null,me=null,$e=null,ot=null,cn=null}}}const s=new t,o=new n,a=new i,l=new WeakMap,c=new WeakMap;let u={},h={},d={},f=new WeakMap,p=[],g=null,m=!1,_=null,x=null,y=null,b=null,M=null,S=null,E=null,v=new We(0,0,0),w=0,N=!1,C=null,F=null,V=null,z=null,U=null;const B=r.getParameter(r.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let D=!1,X=0;const K=r.getParameter(r.VERSION);K.indexOf("WebGL")!==-1?(X=parseFloat(/^WebGL (\d)/.exec(K)[1]),D=X>=1):K.indexOf("OpenGL ES")!==-1&&(X=parseFloat(/^OpenGL ES (\d)/.exec(K)[1]),D=X>=2);let fe=null,Z={};const oe=r.getParameter(r.SCISSOR_BOX),Ee=r.getParameter(r.VIEWPORT),ze=new rt().fromArray(oe),$=new rt().fromArray(Ee);function I(O,ve,le,Fe){const Te=new Uint8Array(4),me=r.createTexture();r.bindTexture(O,me),r.texParameteri(O,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(O,r.TEXTURE_MAG_FILTER,r.NEAREST);for(let $e=0;$e<le;$e++)O===r.TEXTURE_3D||O===r.TEXTURE_2D_ARRAY?r.texImage3D(ve,0,r.RGBA,1,1,Fe,0,r.RGBA,r.UNSIGNED_BYTE,Te):r.texImage2D(ve+$e,0,r.RGBA,1,1,0,r.RGBA,r.UNSIGNED_BYTE,Te);return me}const ne={};ne[r.TEXTURE_2D]=I(r.TEXTURE_2D,r.TEXTURE_2D,1),ne[r.TEXTURE_CUBE_MAP]=I(r.TEXTURE_CUBE_MAP,r.TEXTURE_CUBE_MAP_POSITIVE_X,6),ne[r.TEXTURE_2D_ARRAY]=I(r.TEXTURE_2D_ARRAY,r.TEXTURE_2D_ARRAY,1,1),ne[r.TEXTURE_3D]=I(r.TEXTURE_3D,r.TEXTURE_3D,1,1),s.setClear(0,0,0,1),o.setClear(1),a.setClear(0),ue(r.DEPTH_TEST),o.setFunc(Ds),Bt(!1),Ut(Jf),ue(r.CULL_FACE),At(Pn);function ue(O){u[O]!==!0&&(r.enable(O),u[O]=!0)}function _e(O){u[O]!==!1&&(r.disable(O),u[O]=!1)}function Ue(O,ve){return d[O]!==ve?(r.bindFramebuffer(O,ve),d[O]=ve,O===r.DRAW_FRAMEBUFFER&&(d[r.FRAMEBUFFER]=ve),O===r.FRAMEBUFFER&&(d[r.DRAW_FRAMEBUFFER]=ve),!0):!1}function Ae(O,ve){let le=p,Fe=!1;if(O){le=f.get(ve),le===void 0&&(le=[],f.set(ve,le));const Te=O.textures;if(le.length!==Te.length||le[0]!==r.COLOR_ATTACHMENT0){for(let me=0,$e=Te.length;me<$e;me++)le[me]=r.COLOR_ATTACHMENT0+me;le.length=Te.length,Fe=!0}}else le[0]!==r.BACK&&(le[0]=r.BACK,Fe=!0);Fe&&r.drawBuffers(le)}function dt(O){return g!==O?(r.useProgram(O),g=O,!0):!1}const tt={[Xn]:r.FUNC_ADD,[Bp]:r.FUNC_SUBTRACT,[Op]:r.FUNC_REVERSE_SUBTRACT};tt[z0]=r.MIN,tt[H0]=r.MAX;const gt={[Gr]:r.ZERO,[kp]:r.ONE,[Gp]:r.SRC_COLOR,[oc]:r.SRC_ALPHA,[Xp]:r.SRC_ALPHA_SATURATE,[Wp]:r.DST_COLOR,[zp]:r.DST_ALPHA,[Vp]:r.ONE_MINUS_SRC_COLOR,[ac]:r.ONE_MINUS_SRC_ALPHA,[$p]:r.ONE_MINUS_DST_COLOR,[Hp]:r.ONE_MINUS_DST_ALPHA,[LS]:r.CONSTANT_COLOR,[US]:r.ONE_MINUS_CONSTANT_COLOR,[FS]:r.CONSTANT_ALPHA,[IS]:r.ONE_MINUS_CONSTANT_ALPHA};function At(O,ve,le,Fe,Te,me,$e,ot,cn,Ot){if(O===Pn){m===!0&&(_e(r.BLEND),m=!1);return}if(m===!1&&(ue(r.BLEND),m=!0),O!==co){if(O!==_||Ot!==N){if((x!==Xn||M!==Xn)&&(r.blendEquation(r.FUNC_ADD),x=Xn,M=Xn),Ot)switch(O){case ti:r.blendFuncSeparate(r.ONE,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case _s:r.blendFunc(r.ONE,r.ONE);break;case xs:r.blendFuncSeparate(r.ZERO,r.ONE_MINUS_SRC_COLOR,r.ZERO,r.ONE);break;case ys:r.blendFuncSeparate(r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ZERO,r.ONE);break;default:ce("WebGLState: Invalid blending: ",O);break}else switch(O){case ti:r.blendFuncSeparate(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case _s:r.blendFuncSeparate(r.SRC_ALPHA,r.ONE,r.ONE,r.ONE);break;case xs:ce("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case ys:ce("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:ce("WebGLState: Invalid blending: ",O);break}y=null,b=null,S=null,E=null,v.set(0,0,0),w=0,_=O,N=Ot}return}Te=Te||ve,me=me||le,$e=$e||Fe,(ve!==x||Te!==M)&&(r.blendEquationSeparate(tt[ve],tt[Te]),x=ve,M=Te),(le!==y||Fe!==b||me!==S||$e!==E)&&(r.blendFuncSeparate(gt[le],gt[Fe],gt[me],gt[$e]),y=le,b=Fe,S=me,E=$e),(ot.equals(v)===!1||cn!==w)&&(r.blendColor(ot.r,ot.g,ot.b,cn),v.copy(ot),w=cn),_=O,N=!1}function nt(O,ve){O.side===Nn?_e(r.CULL_FACE):ue(r.CULL_FACE);let le=O.side===Lt;ve&&(le=!le),Bt(le),O.blending===ti&&O.transparent===!1?At(Pn):At(O.blending,O.blendEquation,O.blendSrc,O.blendDst,O.blendEquationAlpha,O.blendSrcAlpha,O.blendDstAlpha,O.blendColor,O.blendAlpha,O.premultipliedAlpha),o.setFunc(O.depthFunc),o.setTest(O.depthTest),o.setMask(O.depthWrite),s.setMask(O.colorWrite);const Fe=O.stencilWrite;a.setTest(Fe),Fe&&(a.setMask(O.stencilWriteMask),a.setFunc(O.stencilFunc,O.stencilRef,O.stencilFuncMask),a.setOp(O.stencilFail,O.stencilZFail,O.stencilZPass)),H(O.polygonOffset,O.polygonOffsetFactor,O.polygonOffsetUnits),O.alphaToCoverage===!0?ue(r.SAMPLE_ALPHA_TO_COVERAGE):_e(r.SAMPLE_ALPHA_TO_COVERAGE)}function Bt(O){C!==O&&(O?r.frontFace(r.CW):r.frontFace(r.CCW),C=O)}function Ut(O){O!==O0?(ue(r.CULL_FACE),O!==F&&(O===Jf?r.cullFace(r.BACK):O===k0?r.cullFace(r.FRONT):r.cullFace(r.FRONT_AND_BACK))):_e(r.CULL_FACE),F=O}function mi(O){O!==V&&(D&&r.lineWidth(O),V=O)}function H(O,ve,le){O?(ue(r.POLYGON_OFFSET_FILL),(z!==ve||U!==le)&&(z=ve,U=le,o.getReversed()&&(ve=-ve),r.polygonOffset(ve,le))):_e(r.POLYGON_OFFSET_FILL)}function vn(O){O?ue(r.SCISSOR_TEST):_e(r.SCISSOR_TEST)}function yt(O){O===void 0&&(O=r.TEXTURE0+B-1),fe!==O&&(r.activeTexture(O),fe=O)}function qt(O,ve,le){le===void 0&&(fe===null?le=r.TEXTURE0+B-1:le=fe);let Fe=Z[le];Fe===void 0&&(Fe={type:void 0,texture:void 0},Z[le]=Fe),(Fe.type!==O||Fe.texture!==ve)&&(fe!==le&&(r.activeTexture(le),fe=le),r.bindTexture(O,ve||ne[O]),Fe.type=O,Fe.texture=ve)}function Re(){const O=Z[fe];O!==void 0&&O.type!==void 0&&(r.bindTexture(O.type,null),O.type=void 0,O.texture=void 0)}function on(){try{r.compressedTexImage2D(...arguments)}catch(O){ce("WebGLState:",O)}}function R(){try{r.compressedTexImage3D(...arguments)}catch(O){ce("WebGLState:",O)}}function T(){try{r.texSubImage2D(...arguments)}catch(O){ce("WebGLState:",O)}}function q(){try{r.texSubImage3D(...arguments)}catch(O){ce("WebGLState:",O)}}function he(){try{r.compressedTexSubImage2D(...arguments)}catch(O){ce("WebGLState:",O)}}function ge(){try{r.compressedTexSubImage3D(...arguments)}catch(O){ce("WebGLState:",O)}}function xe(){try{r.texStorage2D(...arguments)}catch(O){ce("WebGLState:",O)}}function Me(){try{r.texStorage3D(...arguments)}catch(O){ce("WebGLState:",O)}}function se(){try{r.texImage2D(...arguments)}catch(O){ce("WebGLState:",O)}}function de(){try{r.texImage3D(...arguments)}catch(O){ce("WebGLState:",O)}}function Le(O){return h[O]!==void 0?h[O]:r.getParameter(O)}function Be(O,ve){h[O]!==ve&&(r.pixelStorei(O,ve),h[O]=ve)}function Se(O){ze.equals(O)===!1&&(r.scissor(O.x,O.y,O.z,O.w),ze.copy(O))}function ye(O){$.equals(O)===!1&&(r.viewport(O.x,O.y,O.z,O.w),$.copy(O))}function it(O,ve){let le=c.get(ve);le===void 0&&(le=new WeakMap,c.set(ve,le));let Fe=le.get(O);Fe===void 0&&(Fe=r.getUniformBlockIndex(ve,O.name),le.set(O,Fe))}function ut(O,ve){const Fe=c.get(ve).get(O);l.get(ve)!==Fe&&(r.uniformBlockBinding(ve,Fe,O.__bindingPointIndex),l.set(ve,Fe))}function Tt(){r.disable(r.BLEND),r.disable(r.CULL_FACE),r.disable(r.DEPTH_TEST),r.disable(r.POLYGON_OFFSET_FILL),r.disable(r.SCISSOR_TEST),r.disable(r.STENCIL_TEST),r.disable(r.SAMPLE_ALPHA_TO_COVERAGE),r.blendEquation(r.FUNC_ADD),r.blendFunc(r.ONE,r.ZERO),r.blendFuncSeparate(r.ONE,r.ZERO,r.ONE,r.ZERO),r.blendColor(0,0,0,0),r.colorMask(!0,!0,!0,!0),r.clearColor(0,0,0,0),r.depthMask(!0),r.depthFunc(r.LESS),o.setReversed(!1),r.clearDepth(1),r.stencilMask(4294967295),r.stencilFunc(r.ALWAYS,0,4294967295),r.stencilOp(r.KEEP,r.KEEP,r.KEEP),r.clearStencil(0),r.cullFace(r.BACK),r.frontFace(r.CCW),r.polygonOffset(0,0),r.activeTexture(r.TEXTURE0),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,null),r.bindFramebuffer(r.READ_FRAMEBUFFER,null),r.useProgram(null),r.lineWidth(1),r.scissor(0,0,r.canvas.width,r.canvas.height),r.viewport(0,0,r.canvas.width,r.canvas.height),r.pixelStorei(r.PACK_ALIGNMENT,4),r.pixelStorei(r.UNPACK_ALIGNMENT,4),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,r.BROWSER_DEFAULT_WEBGL),r.pixelStorei(r.PACK_ROW_LENGTH,0),r.pixelStorei(r.PACK_SKIP_PIXELS,0),r.pixelStorei(r.PACK_SKIP_ROWS,0),r.pixelStorei(r.UNPACK_ROW_LENGTH,0),r.pixelStorei(r.UNPACK_IMAGE_HEIGHT,0),r.pixelStorei(r.UNPACK_SKIP_PIXELS,0),r.pixelStorei(r.UNPACK_SKIP_ROWS,0),r.pixelStorei(r.UNPACK_SKIP_IMAGES,0),u={},h={},fe=null,Z={},d={},f=new WeakMap,p=[],g=null,m=!1,_=null,x=null,y=null,b=null,M=null,S=null,E=null,v=new We(0,0,0),w=0,N=!1,C=null,F=null,V=null,z=null,U=null,ze.set(0,0,r.canvas.width,r.canvas.height),$.set(0,0,r.canvas.width,r.canvas.height),s.reset(),o.reset(),a.reset()}return{buffers:{color:s,depth:o,stencil:a},enable:ue,disable:_e,bindFramebuffer:Ue,drawBuffers:Ae,useProgram:dt,setBlending:At,setMaterial:nt,setFlipSided:Bt,setCullFace:Ut,setLineWidth:mi,setPolygonOffset:H,setScissorTest:vn,activeTexture:yt,bindTexture:qt,unbindTexture:Re,compressedTexImage2D:on,compressedTexImage3D:R,texImage2D:se,texImage3D:de,pixelStorei:Be,getParameter:Le,updateUBOMapping:it,uniformBlockBinding:ut,texStorage2D:xe,texStorage3D:Me,texSubImage2D:T,texSubImage3D:q,compressedTexSubImage2D:he,compressedTexSubImage3D:ge,scissor:Se,viewport:ye,reset:Tt}}function mC(r,e,t,n,i,s,o){const a=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,l=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),c=new pe,u=new WeakMap,h=new Set;let d;const f=new WeakMap;let p=!1;try{p=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function g(R,T){return p?new OffscreenCanvas(R,T):bc("canvas")}function m(R,T,q){let he=1;const ge=on(R);if((ge.width>q||ge.height>q)&&(he=q/Math.max(ge.width,ge.height)),he<1)if(typeof HTMLImageElement<"u"&&R instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&R instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&R instanceof ImageBitmap||typeof VideoFrame<"u"&&R instanceof VideoFrame){const xe=Math.floor(he*ge.width),Me=Math.floor(he*ge.height);d===void 0&&(d=g(xe,Me));const se=T?g(xe,Me):d;return se.width=xe,se.height=Me,se.getContext("2d").drawImage(R,0,0,xe,Me),ae("WebGLRenderer: Texture has been resized from ("+ge.width+"x"+ge.height+") to ("+xe+"x"+Me+")."),se}else return"data"in R&&ae("WebGLRenderer: Image in DataTexture is too big ("+ge.width+"x"+ge.height+")."),R;return R}function _(R){return R.generateMipmaps}function x(R){r.generateMipmap(R)}function y(R){return R.isWebGLCubeRenderTarget?r.TEXTURE_CUBE_MAP:R.isWebGL3DRenderTarget?r.TEXTURE_3D:R.isWebGLArrayRenderTarget||R.isCompressedArrayTexture?r.TEXTURE_2D_ARRAY:r.TEXTURE_2D}function b(R,T,q,he,ge,xe=!1){if(R!==null){if(r[R]!==void 0)return r[R];ae("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+R+"'")}let Me;he&&(Me=e.get("EXT_texture_norm16"),Me||ae("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let se=T;if(T===r.RED&&(q===r.FLOAT&&(se=r.R32F),q===r.HALF_FLOAT&&(se=r.R16F),q===r.UNSIGNED_BYTE&&(se=r.R8),q===r.UNSIGNED_SHORT&&Me&&(se=Me.R16_EXT),q===r.SHORT&&Me&&(se=Me.R16_SNORM_EXT)),T===r.RED_INTEGER&&(q===r.UNSIGNED_BYTE&&(se=r.R8UI),q===r.UNSIGNED_SHORT&&(se=r.R16UI),q===r.UNSIGNED_INT&&(se=r.R32UI),q===r.BYTE&&(se=r.R8I),q===r.SHORT&&(se=r.R16I),q===r.INT&&(se=r.R32I)),T===r.RG&&(q===r.FLOAT&&(se=r.RG32F),q===r.HALF_FLOAT&&(se=r.RG16F),q===r.UNSIGNED_BYTE&&(se=r.RG8),q===r.UNSIGNED_SHORT&&Me&&(se=Me.RG16_EXT),q===r.SHORT&&Me&&(se=Me.RG16_SNORM_EXT)),T===r.RG_INTEGER&&(q===r.UNSIGNED_BYTE&&(se=r.RG8UI),q===r.UNSIGNED_SHORT&&(se=r.RG16UI),q===r.UNSIGNED_INT&&(se=r.RG32UI),q===r.BYTE&&(se=r.RG8I),q===r.SHORT&&(se=r.RG16I),q===r.INT&&(se=r.RG32I)),T===r.RGB_INTEGER&&(q===r.UNSIGNED_BYTE&&(se=r.RGB8UI),q===r.UNSIGNED_SHORT&&(se=r.RGB16UI),q===r.UNSIGNED_INT&&(se=r.RGB32UI),q===r.BYTE&&(se=r.RGB8I),q===r.SHORT&&(se=r.RGB16I),q===r.INT&&(se=r.RGB32I)),T===r.RGBA_INTEGER&&(q===r.UNSIGNED_BYTE&&(se=r.RGBA8UI),q===r.UNSIGNED_SHORT&&(se=r.RGBA16UI),q===r.UNSIGNED_INT&&(se=r.RGBA32UI),q===r.BYTE&&(se=r.RGBA8I),q===r.SHORT&&(se=r.RGBA16I),q===r.INT&&(se=r.RGBA32I)),T===r.RGB&&(q===r.UNSIGNED_SHORT&&Me&&(se=Me.RGB16_EXT),q===r.SHORT&&Me&&(se=Me.RGB16_SNORM_EXT),q===r.UNSIGNED_INT_5_9_9_9_REV&&(se=r.RGB9_E5),q===r.UNSIGNED_INT_10F_11F_11F_REV&&(se=r.R11F_G11F_B10F)),T===r.RGBA){const de=xe?ja:Ye.getTransfer(ge);q===r.FLOAT&&(se=r.RGBA32F),q===r.HALF_FLOAT&&(se=r.RGBA16F),q===r.UNSIGNED_BYTE&&(se=de===Pe?r.SRGB8_ALPHA8:r.RGBA8),q===r.UNSIGNED_SHORT&&Me&&(se=Me.RGBA16_EXT),q===r.SHORT&&Me&&(se=Me.RGBA16_SNORM_EXT),q===r.UNSIGNED_SHORT_4_4_4_4&&(se=r.RGBA4),q===r.UNSIGNED_SHORT_5_5_5_1&&(se=r.RGB5_A1)}return(se===r.R16F||se===r.R32F||se===r.RG16F||se===r.RG32F||se===r.RGBA16F||se===r.RGBA32F)&&e.get("EXT_color_buffer_float"),se}function M(R,T){let q;return R?T===null||T===Ct||T===di?q=r.DEPTH24_STENCIL8:T===Qt?q=r.DEPTH32F_STENCIL8:T===Ui&&(q=r.DEPTH24_STENCIL8,ae("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):T===null||T===Ct||T===di?q=r.DEPTH_COMPONENT24:T===Qt?q=r.DEPTH_COMPONENT32F:T===Ui&&(q=r.DEPTH_COMPONENT16),q}function S(R,T){return _(R)===!0||R.isFramebufferTexture&&R.minFilter!==Mt&&R.minFilter!==Nt?Math.log2(Math.max(T.width,T.height))+1:R.mipmaps!==void 0&&R.mipmaps.length>0?R.mipmaps.length:R.isCompressedTexture&&Array.isArray(R.image)?T.mipmaps.length:1}function E(R){const T=R.target;T.removeEventListener("dispose",E),w(T),T.isVideoTexture&&u.delete(T),T.isHTMLTexture&&h.delete(T)}function v(R){const T=R.target;T.removeEventListener("dispose",v),C(T)}function w(R){const T=n.get(R);if(T.__webglInit===void 0)return;const q=R.source,he=f.get(q);if(he){const ge=he[T.__cacheKey];ge.usedTimes--,ge.usedTimes===0&&N(R),Object.keys(he).length===0&&f.delete(q)}n.remove(R)}function N(R){const T=n.get(R);r.deleteTexture(T.__webglTexture);const q=R.source,he=f.get(q);delete he[T.__cacheKey],o.memory.textures--}function C(R){const T=n.get(R);if(R.depthTexture&&(R.depthTexture.dispose(),n.remove(R.depthTexture)),R.isWebGLCubeRenderTarget)for(let he=0;he<6;he++){if(Array.isArray(T.__webglFramebuffer[he]))for(let ge=0;ge<T.__webglFramebuffer[he].length;ge++)r.deleteFramebuffer(T.__webglFramebuffer[he][ge]);else r.deleteFramebuffer(T.__webglFramebuffer[he]);T.__webglDepthbuffer&&r.deleteRenderbuffer(T.__webglDepthbuffer[he])}else{if(Array.isArray(T.__webglFramebuffer))for(let he=0;he<T.__webglFramebuffer.length;he++)r.deleteFramebuffer(T.__webglFramebuffer[he]);else r.deleteFramebuffer(T.__webglFramebuffer);if(T.__webglDepthbuffer&&r.deleteRenderbuffer(T.__webglDepthbuffer),T.__webglMultisampledFramebuffer&&r.deleteFramebuffer(T.__webglMultisampledFramebuffer),T.__webglColorRenderbuffer)for(let he=0;he<T.__webglColorRenderbuffer.length;he++)T.__webglColorRenderbuffer[he]&&r.deleteRenderbuffer(T.__webglColorRenderbuffer[he]);T.__webglDepthRenderbuffer&&r.deleteRenderbuffer(T.__webglDepthRenderbuffer)}const q=R.textures;for(let he=0,ge=q.length;he<ge;he++){const xe=n.get(q[he]);xe.__webglTexture&&(r.deleteTexture(xe.__webglTexture),o.memory.textures--),n.remove(q[he])}n.remove(R)}let F=0;function V(){F=0}function z(){return F}function U(R){F=R}function B(){const R=F;return R>=i.maxTextures&&ae("WebGLTextures: Trying to use "+R+" texture units while this GPU supports only "+i.maxTextures),F+=1,R}function D(R){const T=[];return T.push(R.wrapS),T.push(R.wrapT),T.push(R.wrapR||0),T.push(R.magFilter),T.push(R.minFilter),T.push(R.anisotropy),T.push(R.internalFormat),T.push(R.format),T.push(R.type),T.push(R.generateMipmaps),T.push(R.premultiplyAlpha),T.push(R.flipY),T.push(R.unpackAlignment),T.push(R.colorSpace),T.join()}function X(R,T){const q=n.get(R);if(R.isVideoTexture&&qt(R),R.isRenderTargetTexture===!1&&R.isExternalTexture!==!0&&R.version>0&&q.__version!==R.version){const he=R.image;if(he===null)ae("WebGLRenderer: Texture marked for update but no image data found.");else if(he.complete===!1)ae("WebGLRenderer: Texture marked for update but image is incomplete");else{_e(q,R,T);return}}else R.isExternalTexture&&(q.__webglTexture=R.sourceTexture?R.sourceTexture:null);t.bindTexture(r.TEXTURE_2D,q.__webglTexture,r.TEXTURE0+T)}function K(R,T){const q=n.get(R);if(R.isRenderTargetTexture===!1&&R.version>0&&q.__version!==R.version){_e(q,R,T);return}else R.isExternalTexture&&(q.__webglTexture=R.sourceTexture?R.sourceTexture:null);t.bindTexture(r.TEXTURE_2D_ARRAY,q.__webglTexture,r.TEXTURE0+T)}function fe(R,T){const q=n.get(R);if(R.isRenderTargetTexture===!1&&R.version>0&&q.__version!==R.version){_e(q,R,T);return}t.bindTexture(r.TEXTURE_3D,q.__webglTexture,r.TEXTURE0+T)}function Z(R,T){const q=n.get(R);if(R.isCubeDepthTexture!==!0&&R.version>0&&q.__version!==R.version){Ue(q,R,T);return}t.bindTexture(r.TEXTURE_CUBE_MAP,q.__webglTexture,r.TEXTURE0+T)}const oe={[go]:r.REPEAT,[ci]:r.CLAMP_TO_EDGE,[_o]:r.MIRRORED_REPEAT},Ee={[Mt]:r.NEAREST,[em]:r.NEAREST_MIPMAP_NEAREST,[Xr]:r.NEAREST_MIPMAP_LINEAR,[Nt]:r.LINEAR,[ga]:r.LINEAR_MIPMAP_NEAREST,[ui]:r.LINEAR_MIPMAP_LINEAR},ze={[tm]:r.NEVER,[rm]:r.ALWAYS,[Ih]:r.LESS,[Os]:r.LEQUAL,[nm]:r.EQUAL,[Zr]:r.GEQUAL,[vc]:r.GREATER,[im]:r.NOTEQUAL};function $(R,T){if(T.type===Qt&&e.has("OES_texture_float_linear")===!1&&(T.magFilter===Nt||T.magFilter===ga||T.magFilter===Xr||T.magFilter===ui||T.minFilter===Nt||T.minFilter===ga||T.minFilter===Xr||T.minFilter===ui)&&ae("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),r.texParameteri(R,r.TEXTURE_WRAP_S,oe[T.wrapS]),r.texParameteri(R,r.TEXTURE_WRAP_T,oe[T.wrapT]),(R===r.TEXTURE_3D||R===r.TEXTURE_2D_ARRAY)&&r.texParameteri(R,r.TEXTURE_WRAP_R,oe[T.wrapR]),r.texParameteri(R,r.TEXTURE_MAG_FILTER,Ee[T.magFilter]),r.texParameteri(R,r.TEXTURE_MIN_FILTER,Ee[T.minFilter]),T.compareFunction&&(r.texParameteri(R,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(R,r.TEXTURE_COMPARE_FUNC,ze[T.compareFunction])),e.has("EXT_texture_filter_anisotropic")===!0){if(T.magFilter===Mt||T.minFilter!==Xr&&T.minFilter!==ui||T.type===Qt&&e.has("OES_texture_float_linear")===!1)return;if(T.anisotropy>1||n.get(T).__currentAnisotropy){const q=e.get("EXT_texture_filter_anisotropic");r.texParameterf(R,q.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(T.anisotropy,i.getMaxAnisotropy())),n.get(T).__currentAnisotropy=T.anisotropy}}}function I(R,T){let q=!1;R.__webglInit===void 0&&(R.__webglInit=!0,T.addEventListener("dispose",E));const he=T.source;let ge=f.get(he);ge===void 0&&(ge={},f.set(he,ge));const xe=D(T);if(xe!==R.__cacheKey){ge[xe]===void 0&&(ge[xe]={texture:r.createTexture(),usedTimes:0},o.memory.textures++,q=!0),ge[xe].usedTimes++;const Me=ge[R.__cacheKey];Me!==void 0&&(ge[R.__cacheKey].usedTimes--,Me.usedTimes===0&&N(T)),R.__cacheKey=xe,R.__webglTexture=ge[xe].texture}return q}function ne(R,T,q){return Math.floor(Math.floor(R/q)/T)}function ue(R,T,q,he){const xe=R.updateRanges;if(xe.length===0)t.texSubImage2D(r.TEXTURE_2D,0,0,0,T.width,T.height,q,he,T.data);else{xe.sort((Be,Se)=>Be.start-Se.start);let Me=0;for(let Be=1;Be<xe.length;Be++){const Se=xe[Me],ye=xe[Be],it=Se.start+Se.count,ut=ne(ye.start,T.width,4),Tt=ne(Se.start,T.width,4);ye.start<=it+1&&ut===Tt&&ne(ye.start+ye.count-1,T.width,4)===ut?Se.count=Math.max(Se.count,ye.start+ye.count-Se.start):(++Me,xe[Me]=ye)}xe.length=Me+1;const se=t.getParameter(r.UNPACK_ROW_LENGTH),de=t.getParameter(r.UNPACK_SKIP_PIXELS),Le=t.getParameter(r.UNPACK_SKIP_ROWS);t.pixelStorei(r.UNPACK_ROW_LENGTH,T.width);for(let Be=0,Se=xe.length;Be<Se;Be++){const ye=xe[Be],it=Math.floor(ye.start/4),ut=Math.ceil(ye.count/4),Tt=it%T.width,O=Math.floor(it/T.width),ve=ut,le=1;t.pixelStorei(r.UNPACK_SKIP_PIXELS,Tt),t.pixelStorei(r.UNPACK_SKIP_ROWS,O),t.texSubImage2D(r.TEXTURE_2D,0,Tt,O,ve,le,q,he,T.data)}R.clearUpdateRanges(),t.pixelStorei(r.UNPACK_ROW_LENGTH,se),t.pixelStorei(r.UNPACK_SKIP_PIXELS,de),t.pixelStorei(r.UNPACK_SKIP_ROWS,Le)}}function _e(R,T,q){let he=r.TEXTURE_2D;(T.isDataArrayTexture||T.isCompressedArrayTexture)&&(he=r.TEXTURE_2D_ARRAY),T.isData3DTexture&&(he=r.TEXTURE_3D);const ge=I(R,T),xe=T.source;t.bindTexture(he,R.__webglTexture,r.TEXTURE0+q);const Me=n.get(xe);if(xe.version!==Me.__version||ge===!0){if(t.activeTexture(r.TEXTURE0+q),(typeof ImageBitmap<"u"&&T.image instanceof ImageBitmap)===!1){const le=Ye.getPrimaries(Ye.workingColorSpace),Fe=T.colorSpace===ai?null:Ye.getPrimaries(T.colorSpace),Te=T.colorSpace===ai||le===Fe?r.NONE:r.BROWSER_DEFAULT_WEBGL;t.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,T.flipY),t.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,T.premultiplyAlpha),t.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,Te)}t.pixelStorei(r.UNPACK_ALIGNMENT,T.unpackAlignment);let de=m(T.image,!1,i.maxTextureSize);de=Re(T,de);const Le=s.convert(T.format,T.colorSpace),Be=s.convert(T.type);let Se=b(T.internalFormat,Le,Be,T.normalized,T.colorSpace,T.isVideoTexture);$(he,T);let ye;const it=T.mipmaps,ut=T.isVideoTexture!==!0,Tt=Me.__version===void 0||ge===!0,O=xe.dataReady,ve=S(T,de);if(T.isDepthTexture)Se=M(T.format===qn,T.type),Tt&&(ut?t.texStorage2D(r.TEXTURE_2D,1,Se,de.width,de.height):t.texImage2D(r.TEXTURE_2D,0,Se,de.width,de.height,0,Le,Be,null));else if(T.isDataTexture)if(it.length>0){ut&&Tt&&t.texStorage2D(r.TEXTURE_2D,ve,Se,it[0].width,it[0].height);for(let le=0,Fe=it.length;le<Fe;le++)ye=it[le],ut?O&&t.texSubImage2D(r.TEXTURE_2D,le,0,0,ye.width,ye.height,Le,Be,ye.data):t.texImage2D(r.TEXTURE_2D,le,Se,ye.width,ye.height,0,Le,Be,ye.data);T.generateMipmaps=!1}else ut?(Tt&&t.texStorage2D(r.TEXTURE_2D,ve,Se,de.width,de.height),O&&ue(T,de,Le,Be)):t.texImage2D(r.TEXTURE_2D,0,Se,de.width,de.height,0,Le,Be,de.data);else if(T.isCompressedTexture)if(T.isCompressedArrayTexture){ut&&Tt&&t.texStorage3D(r.TEXTURE_2D_ARRAY,ve,Se,it[0].width,it[0].height,de.depth);for(let le=0,Fe=it.length;le<Fe;le++)if(ye=it[le],T.format!==ln)if(Le!==null)if(ut){if(O)if(T.layerUpdates.size>0){const Te=rp(ye.width,ye.height,T.format,T.type);for(const me of T.layerUpdates){const $e=ye.data.subarray(me*Te/ye.data.BYTES_PER_ELEMENT,(me+1)*Te/ye.data.BYTES_PER_ELEMENT);t.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,le,0,0,me,ye.width,ye.height,1,Le,$e)}T.clearLayerUpdates()}else t.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,le,0,0,0,ye.width,ye.height,de.depth,Le,ye.data)}else t.compressedTexImage3D(r.TEXTURE_2D_ARRAY,le,Se,ye.width,ye.height,de.depth,0,ye.data,0,0);else ae("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else ut?O&&t.texSubImage3D(r.TEXTURE_2D_ARRAY,le,0,0,0,ye.width,ye.height,de.depth,Le,Be,ye.data):t.texImage3D(r.TEXTURE_2D_ARRAY,le,Se,ye.width,ye.height,de.depth,0,Le,Be,ye.data)}else{ut&&Tt&&t.texStorage2D(r.TEXTURE_2D,ve,Se,it[0].width,it[0].height);for(let le=0,Fe=it.length;le<Fe;le++)ye=it[le],T.format!==ln?Le!==null?ut?O&&t.compressedTexSubImage2D(r.TEXTURE_2D,le,0,0,ye.width,ye.height,Le,ye.data):t.compressedTexImage2D(r.TEXTURE_2D,le,Se,ye.width,ye.height,0,ye.data):ae("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):ut?O&&t.texSubImage2D(r.TEXTURE_2D,le,0,0,ye.width,ye.height,Le,Be,ye.data):t.texImage2D(r.TEXTURE_2D,le,Se,ye.width,ye.height,0,Le,Be,ye.data)}else if(T.isDataArrayTexture)if(ut){if(Tt&&t.texStorage3D(r.TEXTURE_2D_ARRAY,ve,Se,de.width,de.height,de.depth),O)if(T.layerUpdates.size>0){const le=rp(de.width,de.height,T.format,T.type);for(const Fe of T.layerUpdates){const Te=de.data.subarray(Fe*le/de.data.BYTES_PER_ELEMENT,(Fe+1)*le/de.data.BYTES_PER_ELEMENT);t.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,Fe,de.width,de.height,1,Le,Be,Te)}T.clearLayerUpdates()}else t.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,0,de.width,de.height,de.depth,Le,Be,de.data)}else t.texImage3D(r.TEXTURE_2D_ARRAY,0,Se,de.width,de.height,de.depth,0,Le,Be,de.data);else if(T.isData3DTexture)ut?(Tt&&t.texStorage3D(r.TEXTURE_3D,ve,Se,de.width,de.height,de.depth),O&&t.texSubImage3D(r.TEXTURE_3D,0,0,0,0,de.width,de.height,de.depth,Le,Be,de.data)):t.texImage3D(r.TEXTURE_3D,0,Se,de.width,de.height,de.depth,0,Le,Be,de.data);else if(T.isFramebufferTexture){if(Tt)if(ut)t.texStorage2D(r.TEXTURE_2D,ve,Se,de.width,de.height);else{let le=de.width,Fe=de.height;for(let Te=0;Te<ve;Te++)t.texImage2D(r.TEXTURE_2D,Te,Se,le,Fe,0,Le,Be,null),le>>=1,Fe>>=1}}else if(T.isHTMLTexture){if("texElementImage2D"in r){const le=r.canvas;if(le.hasAttribute("layoutsubtree")||le.setAttribute("layoutsubtree","true"),de.parentNode!==le){le.appendChild(de),h.add(T),le.onpaint=ot=>{const cn=ot.changedElements;for(const Ot of h)cn.includes(Ot.image)&&(Ot.needsUpdate=!0)},le.requestPaint();return}const Fe=0,Te=r.RGBA,me=r.RGBA,$e=r.UNSIGNED_BYTE;r.texElementImage2D(r.TEXTURE_2D,Fe,Te,me,$e,de),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE)}}else if(it.length>0){if(ut&&Tt){const le=on(it[0]);t.texStorage2D(r.TEXTURE_2D,ve,Se,le.width,le.height)}for(let le=0,Fe=it.length;le<Fe;le++)ye=it[le],ut?O&&t.texSubImage2D(r.TEXTURE_2D,le,0,0,Le,Be,ye):t.texImage2D(r.TEXTURE_2D,le,Se,Le,Be,ye);T.generateMipmaps=!1}else if(ut){if(Tt){const le=on(de);t.texStorage2D(r.TEXTURE_2D,ve,Se,le.width,le.height)}O&&t.texSubImage2D(r.TEXTURE_2D,0,0,0,Le,Be,de)}else t.texImage2D(r.TEXTURE_2D,0,Se,Le,Be,de);_(T)&&x(he),Me.__version=xe.version,T.onUpdate&&T.onUpdate(T)}R.__version=T.version}function Ue(R,T,q){if(T.image.length!==6)return;const he=I(R,T),ge=T.source;t.bindTexture(r.TEXTURE_CUBE_MAP,R.__webglTexture,r.TEXTURE0+q);const xe=n.get(ge);if(ge.version!==xe.__version||he===!0){t.activeTexture(r.TEXTURE0+q);const Me=Ye.getPrimaries(Ye.workingColorSpace),se=T.colorSpace===ai?null:Ye.getPrimaries(T.colorSpace),de=T.colorSpace===ai||Me===se?r.NONE:r.BROWSER_DEFAULT_WEBGL;t.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,T.flipY),t.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,T.premultiplyAlpha),t.pixelStorei(r.UNPACK_ALIGNMENT,T.unpackAlignment),t.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,de);const Le=T.isCompressedTexture||T.image[0].isCompressedTexture,Be=T.image[0]&&T.image[0].isDataTexture,Se=[];for(let me=0;me<6;me++)!Le&&!Be?Se[me]=m(T.image[me],!0,i.maxCubemapSize):Se[me]=Be?T.image[me].image:T.image[me],Se[me]=Re(T,Se[me]);const ye=Se[0],it=s.convert(T.format,T.colorSpace),ut=s.convert(T.type),Tt=b(T.internalFormat,it,ut,T.normalized,T.colorSpace),O=T.isVideoTexture!==!0,ve=xe.__version===void 0||he===!0,le=ge.dataReady;let Fe=S(T,ye);$(r.TEXTURE_CUBE_MAP,T);let Te;if(Le){O&&ve&&t.texStorage2D(r.TEXTURE_CUBE_MAP,Fe,Tt,ye.width,ye.height);for(let me=0;me<6;me++){Te=Se[me].mipmaps;for(let $e=0;$e<Te.length;$e++){const ot=Te[$e];T.format!==ln?it!==null?O?le&&t.compressedTexSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e,0,0,ot.width,ot.height,it,ot.data):t.compressedTexImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e,Tt,ot.width,ot.height,0,ot.data):ae("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):O?le&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e,0,0,ot.width,ot.height,it,ut,ot.data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e,Tt,ot.width,ot.height,0,it,ut,ot.data)}}}else{if(Te=T.mipmaps,O&&ve){Te.length>0&&Fe++;const me=on(Se[0]);t.texStorage2D(r.TEXTURE_CUBE_MAP,Fe,Tt,me.width,me.height)}for(let me=0;me<6;me++)if(Be){O?le&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,0,0,0,Se[me].width,Se[me].height,it,ut,Se[me].data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,0,Tt,Se[me].width,Se[me].height,0,it,ut,Se[me].data);for(let $e=0;$e<Te.length;$e++){const cn=Te[$e].image[me].image;O?le&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e+1,0,0,cn.width,cn.height,it,ut,cn.data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e+1,Tt,cn.width,cn.height,0,it,ut,cn.data)}}else{O?le&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,0,0,0,it,ut,Se[me]):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,0,Tt,it,ut,Se[me]);for(let $e=0;$e<Te.length;$e++){const ot=Te[$e];O?le&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e+1,0,0,it,ut,ot.image[me]):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e+1,Tt,it,ut,ot.image[me])}}}_(T)&&x(r.TEXTURE_CUBE_MAP),xe.__version=ge.version,T.onUpdate&&T.onUpdate(T)}R.__version=T.version}function Ae(R,T,q,he,ge,xe){const Me=s.convert(q.format,q.colorSpace),se=s.convert(q.type),de=b(q.internalFormat,Me,se,q.normalized,q.colorSpace),Le=n.get(T),Be=n.get(q);if(Be.__renderTarget=T,!Le.__hasExternalTextures){const Se=Math.max(1,T.width>>xe),ye=Math.max(1,T.height>>xe);ge===r.TEXTURE_3D||ge===r.TEXTURE_2D_ARRAY?t.texImage3D(ge,xe,de,Se,ye,T.depth,0,Me,se,null):t.texImage2D(ge,xe,de,Se,ye,0,Me,se,null)}t.bindFramebuffer(r.FRAMEBUFFER,R),yt(T)?a.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,he,ge,Be.__webglTexture,0,vn(T)):(ge===r.TEXTURE_2D||ge>=r.TEXTURE_CUBE_MAP_POSITIVE_X&&ge<=r.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&r.framebufferTexture2D(r.FRAMEBUFFER,he,ge,Be.__webglTexture,xe),t.bindFramebuffer(r.FRAMEBUFFER,null)}function dt(R,T,q){if(r.bindRenderbuffer(r.RENDERBUFFER,R),T.depthBuffer){const he=T.depthTexture,ge=he&&he.isDepthTexture?he.type:null,xe=M(T.stencilBuffer,ge),Me=T.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;yt(T)?a.renderbufferStorageMultisampleEXT(r.RENDERBUFFER,vn(T),xe,T.width,T.height):q?r.renderbufferStorageMultisample(r.RENDERBUFFER,vn(T),xe,T.width,T.height):r.renderbufferStorage(r.RENDERBUFFER,xe,T.width,T.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,Me,r.RENDERBUFFER,R)}else{const he=T.textures;for(let ge=0;ge<he.length;ge++){const xe=he[ge],Me=s.convert(xe.format,xe.colorSpace),se=s.convert(xe.type),de=b(xe.internalFormat,Me,se,xe.normalized,xe.colorSpace);yt(T)?a.renderbufferStorageMultisampleEXT(r.RENDERBUFFER,vn(T),de,T.width,T.height):q?r.renderbufferStorageMultisample(r.RENDERBUFFER,vn(T),de,T.width,T.height):r.renderbufferStorage(r.RENDERBUFFER,de,T.width,T.height)}}r.bindRenderbuffer(r.RENDERBUFFER,null)}function tt(R,T,q){const he=T.isWebGLCubeRenderTarget===!0;if(t.bindFramebuffer(r.FRAMEBUFFER,R),!(T.depthTexture&&T.depthTexture.isDepthTexture))throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");const ge=n.get(T.depthTexture);if(ge.__renderTarget=T,(!ge.__webglTexture||T.depthTexture.image.width!==T.width||T.depthTexture.image.height!==T.height)&&(T.depthTexture.image.width=T.width,T.depthTexture.image.height=T.height,T.depthTexture.needsUpdate=!0),he){if(ge.__webglInit===void 0&&(ge.__webglInit=!0,T.depthTexture.addEventListener("dispose",E)),ge.__webglTexture===void 0){ge.__webglTexture=r.createTexture(),t.bindTexture(r.TEXTURE_CUBE_MAP,ge.__webglTexture),$(r.TEXTURE_CUBE_MAP,T.depthTexture);const Le=s.convert(T.depthTexture.format),Be=s.convert(T.depthTexture.type);let Se;T.depthTexture.format===Dn?Se=r.DEPTH_COMPONENT24:T.depthTexture.format===qn&&(Se=r.DEPTH24_STENCIL8);for(let ye=0;ye<6;ye++)r.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+ye,0,Se,T.width,T.height,0,Le,Be,null)}}else X(T.depthTexture,0);const xe=ge.__webglTexture,Me=vn(T),se=he?r.TEXTURE_CUBE_MAP_POSITIVE_X+q:r.TEXTURE_2D,de=T.depthTexture.format===qn?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;if(T.depthTexture.format===Dn)yt(T)?a.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,de,se,xe,0,Me):r.framebufferTexture2D(r.FRAMEBUFFER,de,se,xe,0);else if(T.depthTexture.format===qn)yt(T)?a.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,de,se,xe,0,Me):r.framebufferTexture2D(r.FRAMEBUFFER,de,se,xe,0);else throw new Error("Unknown depthTexture format")}function gt(R){const T=n.get(R),q=R.isWebGLCubeRenderTarget===!0;if(T.__boundDepthTexture!==R.depthTexture){const he=R.depthTexture;if(T.__depthDisposeCallback&&T.__depthDisposeCallback(),he){const ge=()=>{delete T.__boundDepthTexture,delete T.__depthDisposeCallback,he.removeEventListener("dispose",ge)};he.addEventListener("dispose",ge),T.__depthDisposeCallback=ge}T.__boundDepthTexture=he}if(R.depthTexture&&!T.__autoAllocateDepthBuffer)if(q)for(let he=0;he<6;he++)tt(T.__webglFramebuffer[he],R,he);else{const he=R.texture.mipmaps;he&&he.length>0?tt(T.__webglFramebuffer[0],R,0):tt(T.__webglFramebuffer,R,0)}else if(q){T.__webglDepthbuffer=[];for(let he=0;he<6;he++)if(t.bindFramebuffer(r.FRAMEBUFFER,T.__webglFramebuffer[he]),T.__webglDepthbuffer[he]===void 0)T.__webglDepthbuffer[he]=r.createRenderbuffer(),dt(T.__webglDepthbuffer[he],R,!1);else{const ge=R.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,xe=T.__webglDepthbuffer[he];r.bindRenderbuffer(r.RENDERBUFFER,xe),r.framebufferRenderbuffer(r.FRAMEBUFFER,ge,r.RENDERBUFFER,xe)}}else{const he=R.texture.mipmaps;if(he&&he.length>0?t.bindFramebuffer(r.FRAMEBUFFER,T.__webglFramebuffer[0]):t.bindFramebuffer(r.FRAMEBUFFER,T.__webglFramebuffer),T.__webglDepthbuffer===void 0)T.__webglDepthbuffer=r.createRenderbuffer(),dt(T.__webglDepthbuffer,R,!1);else{const ge=R.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,xe=T.__webglDepthbuffer;r.bindRenderbuffer(r.RENDERBUFFER,xe),r.framebufferRenderbuffer(r.FRAMEBUFFER,ge,r.RENDERBUFFER,xe)}}t.bindFramebuffer(r.FRAMEBUFFER,null)}function At(R,T,q){const he=n.get(R);T!==void 0&&Ae(he.__webglFramebuffer,R,R.texture,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,0),q!==void 0&&gt(R)}function nt(R){const T=R.texture,q=n.get(R),he=n.get(T);R.addEventListener("dispose",v);const ge=R.textures,xe=R.isWebGLCubeRenderTarget===!0,Me=ge.length>1;if(Me||(he.__webglTexture===void 0&&(he.__webglTexture=r.createTexture()),he.__version=T.version,o.memory.textures++),xe){q.__webglFramebuffer=[];for(let se=0;se<6;se++)if(T.mipmaps&&T.mipmaps.length>0){q.__webglFramebuffer[se]=[];for(let de=0;de<T.mipmaps.length;de++)q.__webglFramebuffer[se][de]=r.createFramebuffer()}else q.__webglFramebuffer[se]=r.createFramebuffer()}else{if(T.mipmaps&&T.mipmaps.length>0){q.__webglFramebuffer=[];for(let se=0;se<T.mipmaps.length;se++)q.__webglFramebuffer[se]=r.createFramebuffer()}else q.__webglFramebuffer=r.createFramebuffer();if(Me)for(let se=0,de=ge.length;se<de;se++){const Le=n.get(ge[se]);Le.__webglTexture===void 0&&(Le.__webglTexture=r.createTexture(),o.memory.textures++)}if(R.samples>0&&yt(R)===!1){q.__webglMultisampledFramebuffer=r.createFramebuffer(),q.__webglColorRenderbuffer=[],t.bindFramebuffer(r.FRAMEBUFFER,q.__webglMultisampledFramebuffer);for(let se=0;se<ge.length;se++){const de=ge[se];q.__webglColorRenderbuffer[se]=r.createRenderbuffer(),r.bindRenderbuffer(r.RENDERBUFFER,q.__webglColorRenderbuffer[se]);const Le=s.convert(de.format,de.colorSpace),Be=s.convert(de.type),Se=b(de.internalFormat,Le,Be,de.normalized,de.colorSpace,R.isXRRenderTarget===!0),ye=vn(R);r.renderbufferStorageMultisample(r.RENDERBUFFER,ye,Se,R.width,R.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+se,r.RENDERBUFFER,q.__webglColorRenderbuffer[se])}r.bindRenderbuffer(r.RENDERBUFFER,null),R.depthBuffer&&(q.__webglDepthRenderbuffer=r.createRenderbuffer(),dt(q.__webglDepthRenderbuffer,R,!0)),t.bindFramebuffer(r.FRAMEBUFFER,null)}}if(xe){t.bindTexture(r.TEXTURE_CUBE_MAP,he.__webglTexture),$(r.TEXTURE_CUBE_MAP,T);for(let se=0;se<6;se++)if(T.mipmaps&&T.mipmaps.length>0)for(let de=0;de<T.mipmaps.length;de++)Ae(q.__webglFramebuffer[se][de],R,T,r.COLOR_ATTACHMENT0,r.TEXTURE_CUBE_MAP_POSITIVE_X+se,de);else Ae(q.__webglFramebuffer[se],R,T,r.COLOR_ATTACHMENT0,r.TEXTURE_CUBE_MAP_POSITIVE_X+se,0);_(T)&&x(r.TEXTURE_CUBE_MAP),t.unbindTexture()}else if(Me){for(let se=0,de=ge.length;se<de;se++){const Le=ge[se],Be=n.get(Le);let Se=r.TEXTURE_2D;(R.isWebGL3DRenderTarget||R.isWebGLArrayRenderTarget)&&(Se=R.isWebGL3DRenderTarget?r.TEXTURE_3D:r.TEXTURE_2D_ARRAY),t.bindTexture(Se,Be.__webglTexture),$(Se,Le),Ae(q.__webglFramebuffer,R,Le,r.COLOR_ATTACHMENT0+se,Se,0),_(Le)&&x(Se)}t.unbindTexture()}else{let se=r.TEXTURE_2D;if((R.isWebGL3DRenderTarget||R.isWebGLArrayRenderTarget)&&(se=R.isWebGL3DRenderTarget?r.TEXTURE_3D:r.TEXTURE_2D_ARRAY),t.bindTexture(se,he.__webglTexture),$(se,T),T.mipmaps&&T.mipmaps.length>0)for(let de=0;de<T.mipmaps.length;de++)Ae(q.__webglFramebuffer[de],R,T,r.COLOR_ATTACHMENT0,se,de);else Ae(q.__webglFramebuffer,R,T,r.COLOR_ATTACHMENT0,se,0);_(T)&&x(se),t.unbindTexture()}R.depthBuffer&&gt(R)}function Bt(R){const T=R.textures;for(let q=0,he=T.length;q<he;q++){const ge=T[q];if(_(ge)){const xe=y(R),Me=n.get(ge).__webglTexture;t.bindTexture(xe,Me),x(xe),t.unbindTexture()}}}const Ut=[],mi=[];function H(R){if(R.samples>0){if(yt(R)===!1){const T=R.textures,q=R.width,he=R.height;let ge=r.COLOR_BUFFER_BIT;const xe=R.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,Me=n.get(R),se=T.length>1;if(se)for(let Le=0;Le<T.length;Le++)t.bindFramebuffer(r.FRAMEBUFFER,Me.__webglMultisampledFramebuffer),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+Le,r.RENDERBUFFER,null),t.bindFramebuffer(r.FRAMEBUFFER,Me.__webglFramebuffer),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0+Le,r.TEXTURE_2D,null,0);t.bindFramebuffer(r.READ_FRAMEBUFFER,Me.__webglMultisampledFramebuffer);const de=R.texture.mipmaps;de&&de.length>0?t.bindFramebuffer(r.DRAW_FRAMEBUFFER,Me.__webglFramebuffer[0]):t.bindFramebuffer(r.DRAW_FRAMEBUFFER,Me.__webglFramebuffer);for(let Le=0;Le<T.length;Le++){if(R.resolveDepthBuffer&&(R.depthBuffer&&(ge|=r.DEPTH_BUFFER_BIT),R.stencilBuffer&&R.resolveStencilBuffer&&(ge|=r.STENCIL_BUFFER_BIT)),se){r.framebufferRenderbuffer(r.READ_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.RENDERBUFFER,Me.__webglColorRenderbuffer[Le]);const Be=n.get(T[Le]).__webglTexture;r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,Be,0)}r.blitFramebuffer(0,0,q,he,0,0,q,he,ge,r.NEAREST),l===!0&&(Ut.length=0,mi.length=0,Ut.push(r.COLOR_ATTACHMENT0+Le),R.depthBuffer&&R.resolveDepthBuffer===!1&&(Ut.push(xe),mi.push(xe),r.invalidateFramebuffer(r.DRAW_FRAMEBUFFER,mi)),r.invalidateFramebuffer(r.READ_FRAMEBUFFER,Ut))}if(t.bindFramebuffer(r.READ_FRAMEBUFFER,null),t.bindFramebuffer(r.DRAW_FRAMEBUFFER,null),se)for(let Le=0;Le<T.length;Le++){t.bindFramebuffer(r.FRAMEBUFFER,Me.__webglMultisampledFramebuffer),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+Le,r.RENDERBUFFER,Me.__webglColorRenderbuffer[Le]);const Be=n.get(T[Le]).__webglTexture;t.bindFramebuffer(r.FRAMEBUFFER,Me.__webglFramebuffer),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0+Le,r.TEXTURE_2D,Be,0)}t.bindFramebuffer(r.DRAW_FRAMEBUFFER,Me.__webglMultisampledFramebuffer)}else if(R.depthBuffer&&R.resolveDepthBuffer===!1&&l){const T=R.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;r.invalidateFramebuffer(r.DRAW_FRAMEBUFFER,[T])}}}function vn(R){return Math.min(i.maxSamples,R.samples)}function yt(R){const T=n.get(R);return R.samples>0&&e.has("WEBGL_multisampled_render_to_texture")===!0&&T.__useRenderToTexture!==!1}function qt(R){const T=o.render.frame;u.get(R)!==T&&(u.set(R,T),R.update())}function Re(R,T){const q=R.colorSpace,he=R.format,ge=R.type;return R.isCompressedTexture===!0||R.isVideoTexture===!0||q!==yc&&q!==ai&&(Ye.getTransfer(q)===Pe?(he!==ln||ge!==Xt)&&ae("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):ce("WebGLTextures: Unsupported texture color space:",q)),T}function on(R){return typeof HTMLImageElement<"u"&&R instanceof HTMLImageElement?(c.width=R.naturalWidth||R.width,c.height=R.naturalHeight||R.height):typeof VideoFrame<"u"&&R instanceof VideoFrame?(c.width=R.displayWidth,c.height=R.displayHeight):(c.width=R.width,c.height=R.height),c}this.allocateTextureUnit=B,this.resetTextureUnits=V,this.getTextureUnits=z,this.setTextureUnits=U,this.setTexture2D=X,this.setTexture2DArray=K,this.setTexture3D=fe,this.setTextureCube=Z,this.rebindTextures=At,this.setupRenderTarget=nt,this.updateRenderTargetMipmap=Bt,this.updateMultisampleRenderTarget=H,this.setupDepthRenderbuffer=gt,this.setupFrameBufferTexture=Ae,this.useMultisampledRTT=yt,this.isReversedDepthBuffer=function(){return t.buffers.depth.getReversed()}}function gC(r,e){function t(n,i=ai){let s;const o=Ye.getTransfer(i);if(n===Xt)return r.UNSIGNED_BYTE;if(n===Pc)return r.UNSIGNED_SHORT_4_4_4_4;if(n===Dc)return r.UNSIGNED_SHORT_5_5_5_1;if(n===Lc)return r.UNSIGNED_INT_5_9_9_9_REV;if(n===Uc)return r.UNSIGNED_INT_10F_11F_11F_REV;if(n===Ts)return r.BYTE;if(n===Ms)return r.SHORT;if(n===Ui)return r.UNSIGNED_SHORT;if(n===Sn)return r.INT;if(n===Ct)return r.UNSIGNED_INT;if(n===Qt)return r.FLOAT;if(n===tn)return r.HALF_FLOAT;if(n===Fh)return r.ALPHA;if(n===nl)return r.RGB;if(n===ln)return r.RGBA;if(n===Dn)return r.DEPTH_COMPONENT;if(n===qn)return r.DEPTH_STENCIL;if(n===il)return r.RED;if(n===Eo)return r.RED_INTEGER;if(n===In)return r.RG;if(n===Ao)return r.RG_INTEGER;if(n===rl)return r.RGBA_INTEGER;if(n===Es||n===As||n===ws||n===Rs)if(o===Pe)if(s=e.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(n===Es)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(n===As)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(n===ws)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(n===Rs)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=e.get("WEBGL_compressed_texture_s3tc"),s!==null){if(n===Es)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(n===As)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(n===ws)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(n===Rs)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(n===mc||n===gc||n===_c||n===xc)if(s=e.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(n===mc)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(n===gc)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(n===_c)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(n===xc)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(n===Ma||n===Ea||n===Aa||n===wa||n===Ra||n===Ls||n===Ca)if(s=e.get("WEBGL_compressed_texture_etc"),s!==null){if(n===Ma||n===Ea)return o===Pe?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(n===Aa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(n===wa)return s.COMPRESSED_R11_EAC;if(n===Ra)return s.COMPRESSED_SIGNED_R11_EAC;if(n===Ls)return s.COMPRESSED_RG11_EAC;if(n===Ca)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(n===Na||n===Pa||n===Da||n===La||n===Ua||n===Fa||n===Ia||n===Ba||n===Oa||n===ka||n===Ga||n===Va||n===za||n===Ha)if(s=e.get("WEBGL_compressed_texture_astc"),s!==null){if(n===Na)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(n===Pa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(n===Da)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(n===La)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(n===Ua)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(n===Fa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(n===Ia)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(n===Ba)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(n===Oa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(n===ka)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(n===Ga)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(n===Va)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(n===za)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(n===Ha)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(n===Wa||n===ep||n===tp)if(s=e.get("EXT_texture_compression_bptc"),s!==null){if(n===Wa)return o===Pe?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(n===ep)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(n===tp)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(n===$a||n===Xa||n===Us||n===qa)if(s=e.get("EXT_texture_compression_rgtc"),s!==null){if(n===$a)return s.COMPRESSED_RED_RGTC1_EXT;if(n===Xa)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(n===Us)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(n===qa)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return n===di?r.UNSIGNED_INT_24_8:r[n]!==void 0?r[n]:null}return{convert:t}}const _C=`
4088
+ }`,hC=[new P(1,0,0),new P(-1,0,0),new P(0,1,0),new P(0,-1,0),new P(0,0,1),new P(0,0,-1)],dC=[new P(0,-1,0),new P(0,-1,0),new P(0,0,1),new P(0,0,-1),new P(0,-1,0),new P(0,-1,0)],b_=new pt,wl=new P,zd=new P;function fC(r,e,t){let n=new Ic;const i=new pe,s=new pe,o=new rt,a=new fM,l=new pM,c={},u=t.maxTextureSize,h={[ri]:Lt,[Lt]:ri,[Nn]:Nn},d=new ki({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new pe},radius:{value:4}},vertexShader:cC,fragmentShader:uC}),f=d.clone();f.defines.HORIZONTAL_PASS=1;const p=new An;p.setAttribute("position",new Bn(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const g=new _n(p,d),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=fa;let _=this.type;this.render=function(S,E,v){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||S.length===0)return;this.type===G0&&(ae("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=fa);const w=r.getRenderTarget(),N=r.getActiveCubeFace(),C=r.getActiveMipmapLevel(),F=r.state;F.setBlending(Pn),F.buffers.depth.getReversed()===!0?F.buffers.color.setClear(0,0,0,0):F.buffers.color.setClear(1,1,1,1),F.buffers.depth.setTest(!0),F.setScissorTest(!1);const V=_!==this.type;V&&E.traverse(function(z){z.material&&(Array.isArray(z.material)?z.material.forEach(U=>U.needsUpdate=!0):z.material.needsUpdate=!0)});for(let z=0,U=S.length;z<U;z++){const B=S[z],D=B.shadow;if(D===void 0){ae("WebGLShadowMap:",B,"has no shadow.");continue}if(D.autoUpdate===!1&&D.needsUpdate===!1)continue;i.copy(D.mapSize);const X=D.getFrameExtents();i.multiply(X),s.copy(D.mapSize),(i.x>u||i.y>u)&&(i.x>u&&(s.x=Math.floor(u/X.x),i.x=s.x*X.x,D.mapSize.x=s.x),i.y>u&&(s.y=Math.floor(u/X.y),i.y=s.y*X.y,D.mapSize.y=s.y));const K=r.state.buffers.depth.getReversed();if(D.camera._reversedDepth=K,D.map===null||V===!0){if(D.map!==null&&(D.map.depthTexture!==null&&(D.map.depthTexture.dispose(),D.map.depthTexture=null),D.map.dispose()),this.type===_r){if(B.isPointLight){ae("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}D.map=new Yi(i.x,i.y,{format:In,type:tn,minFilter:Nt,magFilter:Nt,generateMipmaps:!1}),D.map.texture.name=B.name+".shadowMap",D.map.depthTexture=new jn(i.x,i.y,Qt),D.map.depthTexture.name=B.name+".shadowMapDepth",D.map.depthTexture.format=Dn,D.map.depthTexture.compareFunction=null,D.map.depthTexture.minFilter=Mt,D.map.depthTexture.magFilter=Mt}else B.isPointLight?(D.map=new vy(i.x),D.map.depthTexture=new iy(i.x,Ct)):(D.map=new Yi(i.x,i.y),D.map.depthTexture=new jn(i.x,i.y,Ct)),D.map.depthTexture.name=B.name+".shadowMap",D.map.depthTexture.format=Dn,this.type===fa?(D.map.depthTexture.compareFunction=K?Zr:Os,D.map.depthTexture.minFilter=Nt,D.map.depthTexture.magFilter=Nt):(D.map.depthTexture.compareFunction=null,D.map.depthTexture.minFilter=Mt,D.map.depthTexture.magFilter=Mt);D.camera.updateProjectionMatrix()}const fe=D.map.isWebGLCubeRenderTarget?6:1;for(let Z=0;Z<fe;Z++){if(D.map.isWebGLCubeRenderTarget)r.setRenderTarget(D.map,Z),r.clear();else{Z===0&&(r.setRenderTarget(D.map),r.clear());const oe=D.getViewport(Z);o.set(s.x*oe.x,s.y*oe.y,s.x*oe.z,s.y*oe.w),F.viewport(o)}if(B.isPointLight){const oe=D.camera,Ee=D.matrix,ze=B.distance||oe.far;ze!==oe.far&&(oe.far=ze,oe.updateProjectionMatrix()),wl.setFromMatrixPosition(B.matrixWorld),oe.position.copy(wl),zd.copy(oe.position),zd.add(hC[Z]),oe.up.copy(dC[Z]),oe.lookAt(zd),oe.updateMatrixWorld(),Ee.makeTranslation(-wl.x,-wl.y,-wl.z),b_.multiplyMatrices(oe.projectionMatrix,oe.matrixWorldInverse),D._frustum.setFromProjectionMatrix(b_,oe.coordinateSystem,oe.reversedDepth)}else D.updateMatrices(B);n=D.getFrustum(),b(E,v,D.camera,B,this.type)}D.isPointLightShadow!==!0&&this.type===_r&&x(D,v),D.needsUpdate=!1}_=this.type,m.needsUpdate=!1,r.setRenderTarget(w,N,C)};function x(S,E){const v=e.update(g);d.defines.VSM_SAMPLES!==S.blurSamples&&(d.defines.VSM_SAMPLES=S.blurSamples,f.defines.VSM_SAMPLES=S.blurSamples,d.needsUpdate=!0,f.needsUpdate=!0),S.mapPass===null&&(S.mapPass=new Yi(i.x,i.y,{format:In,type:tn})),d.uniforms.shadow_pass.value=S.map.depthTexture,d.uniforms.resolution.value=S.mapSize,d.uniforms.radius.value=S.radius,r.setRenderTarget(S.mapPass),r.clear(),r.renderBufferDirect(E,null,v,d,g,null),f.uniforms.shadow_pass.value=S.mapPass.texture,f.uniforms.resolution.value=S.mapSize,f.uniforms.radius.value=S.radius,r.setRenderTarget(S.map),r.clear(),r.renderBufferDirect(E,null,v,f,g,null)}function y(S,E,v,w){let N=null;const C=v.isPointLight===!0?S.customDistanceMaterial:S.customDepthMaterial;if(C!==void 0)N=C;else if(N=v.isPointLight===!0?l:a,r.localClippingEnabled&&E.clipShadows===!0&&Array.isArray(E.clippingPlanes)&&E.clippingPlanes.length!==0||E.displacementMap&&E.displacementScale!==0||E.alphaMap&&E.alphaTest>0||E.map&&E.alphaTest>0||E.alphaToCoverage===!0){const F=N.uuid,V=E.uuid;let z=c[F];z===void 0&&(z={},c[F]=z);let U=z[V];U===void 0&&(U=N.clone(),z[V]=U,E.addEventListener("dispose",M)),N=U}if(N.visible=E.visible,N.wireframe=E.wireframe,w===_r?N.side=E.shadowSide!==null?E.shadowSide:E.side:N.side=E.shadowSide!==null?E.shadowSide:h[E.side],N.alphaMap=E.alphaMap,N.alphaTest=E.alphaToCoverage===!0?.5:E.alphaTest,N.map=E.map,N.clipShadows=E.clipShadows,N.clippingPlanes=E.clippingPlanes,N.clipIntersection=E.clipIntersection,N.displacementMap=E.displacementMap,N.displacementScale=E.displacementScale,N.displacementBias=E.displacementBias,N.wireframeLinewidth=E.wireframeLinewidth,N.linewidth=E.linewidth,v.isPointLight===!0&&N.isMeshDistanceMaterial===!0){const F=r.properties.get(N);F.light=v}return N}function b(S,E,v,w,N){if(S.visible===!1)return;if(S.layers.test(E.layers)&&(S.isMesh||S.isLine||S.isPoints)&&(S.castShadow||S.receiveShadow&&N===_r)&&(!S.frustumCulled||n.intersectsObject(S))){S.modelViewMatrix.multiplyMatrices(v.matrixWorldInverse,S.matrixWorld);const V=e.update(S),z=S.material;if(Array.isArray(z)){const U=V.groups;for(let B=0,D=U.length;B<D;B++){const X=U[B],K=z[X.materialIndex];if(K&&K.visible){const fe=y(S,K,w,N);S.onBeforeShadow(r,S,E,v,V,fe,X),r.renderBufferDirect(v,null,V,fe,S,X),S.onAfterShadow(r,S,E,v,V,fe,X)}}}else if(z.visible){const U=y(S,z,w,N);S.onBeforeShadow(r,S,E,v,V,U,null),r.renderBufferDirect(v,null,V,U,S,null),S.onAfterShadow(r,S,E,v,V,U,null)}}const F=S.children;for(let V=0,z=F.length;V<z;V++)b(F[V],E,v,w,N)}function M(S){S.target.removeEventListener("dispose",M);for(const v in c){const w=c[v],N=S.target.uuid;N in w&&(w[N].dispose(),delete w[N])}}}function pC(r,e){function t(){let O=!1;const ve=new rt;let le=null;const Fe=new rt(0,0,0,0);return{setMask:function(Te){le!==Te&&!O&&(r.colorMask(Te,Te,Te,Te),le=Te)},setLocked:function(Te){O=Te},setClear:function(Te,me,$e,ot,cn){cn===!0&&(Te*=ot,me*=ot,$e*=ot),ve.set(Te,me,$e,ot),Fe.equals(ve)===!1&&(r.clearColor(Te,me,$e,ot),Fe.copy(ve))},reset:function(){O=!1,le=null,Fe.set(-1,0,0,0)}}}function n(){let O=!1,ve=!1,le=null,Fe=null,Te=null;return{setReversed:function(me){if(ve!==me){const $e=e.get("EXT_clip_control");me?$e.clipControlEXT($e.LOWER_LEFT_EXT,$e.ZERO_TO_ONE_EXT):$e.clipControlEXT($e.LOWER_LEFT_EXT,$e.NEGATIVE_ONE_TO_ONE_EXT),ve=me;const ot=Te;Te=null,this.setClear(ot)}},getReversed:function(){return ve},setTest:function(me){me?ue(r.DEPTH_TEST):_e(r.DEPTH_TEST)},setMask:function(me){le!==me&&!O&&(r.depthMask(me),le=me)},setFunc:function(me){if(ve&&(me=sm[me]),Fe!==me){switch(me){case lc:r.depthFunc(r.NEVER);break;case cc:r.depthFunc(r.ALWAYS);break;case uc:r.depthFunc(r.LESS);break;case Ds:r.depthFunc(r.LEQUAL);break;case hc:r.depthFunc(r.EQUAL);break;case dc:r.depthFunc(r.GEQUAL);break;case fc:r.depthFunc(r.GREATER);break;case pc:r.depthFunc(r.NOTEQUAL);break;default:r.depthFunc(r.LEQUAL)}Fe=me}},setLocked:function(me){O=me},setClear:function(me){Te!==me&&(Te=me,ve&&(me=1-me),r.clearDepth(me))},reset:function(){O=!1,le=null,Fe=null,Te=null,ve=!1}}}function i(){let O=!1,ve=null,le=null,Fe=null,Te=null,me=null,$e=null,ot=null,cn=null;return{setTest:function(Ot){O||(Ot?ue(r.STENCIL_TEST):_e(r.STENCIL_TEST))},setMask:function(Ot){ve!==Ot&&!O&&(r.stencilMask(Ot),ve=Ot)},setFunc:function(Ot,Nr,Zi){(le!==Ot||Fe!==Nr||Te!==Zi)&&(r.stencilFunc(Ot,Nr,Zi),le=Ot,Fe=Nr,Te=Zi)},setOp:function(Ot,Nr,Zi){(me!==Ot||$e!==Nr||ot!==Zi)&&(r.stencilOp(Ot,Nr,Zi),me=Ot,$e=Nr,ot=Zi)},setLocked:function(Ot){O=Ot},setClear:function(Ot){cn!==Ot&&(r.clearStencil(Ot),cn=Ot)},reset:function(){O=!1,ve=null,le=null,Fe=null,Te=null,me=null,$e=null,ot=null,cn=null}}}const s=new t,o=new n,a=new i,l=new WeakMap,c=new WeakMap;let u={},h={},d={},f=new WeakMap,p=[],g=null,m=!1,_=null,x=null,y=null,b=null,M=null,S=null,E=null,v=new We(0,0,0),w=0,N=!1,C=null,F=null,V=null,z=null,U=null;const B=r.getParameter(r.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let D=!1,X=0;const K=r.getParameter(r.VERSION);K.indexOf("WebGL")!==-1?(X=parseFloat(/^WebGL (\d)/.exec(K)[1]),D=X>=1):K.indexOf("OpenGL ES")!==-1&&(X=parseFloat(/^OpenGL ES (\d)/.exec(K)[1]),D=X>=2);let fe=null,Z={};const oe=r.getParameter(r.SCISSOR_BOX),Ee=r.getParameter(r.VIEWPORT),ze=new rt().fromArray(oe),$=new rt().fromArray(Ee);function I(O,ve,le,Fe){const Te=new Uint8Array(4),me=r.createTexture();r.bindTexture(O,me),r.texParameteri(O,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(O,r.TEXTURE_MAG_FILTER,r.NEAREST);for(let $e=0;$e<le;$e++)O===r.TEXTURE_3D||O===r.TEXTURE_2D_ARRAY?r.texImage3D(ve,0,r.RGBA,1,1,Fe,0,r.RGBA,r.UNSIGNED_BYTE,Te):r.texImage2D(ve+$e,0,r.RGBA,1,1,0,r.RGBA,r.UNSIGNED_BYTE,Te);return me}const ne={};ne[r.TEXTURE_2D]=I(r.TEXTURE_2D,r.TEXTURE_2D,1),ne[r.TEXTURE_CUBE_MAP]=I(r.TEXTURE_CUBE_MAP,r.TEXTURE_CUBE_MAP_POSITIVE_X,6),ne[r.TEXTURE_2D_ARRAY]=I(r.TEXTURE_2D_ARRAY,r.TEXTURE_2D_ARRAY,1,1),ne[r.TEXTURE_3D]=I(r.TEXTURE_3D,r.TEXTURE_3D,1,1),s.setClear(0,0,0,1),o.setClear(1),a.setClear(0),ue(r.DEPTH_TEST),o.setFunc(Ds),Bt(!1),Ut(Jf),ue(r.CULL_FACE),At(Pn);function ue(O){u[O]!==!0&&(r.enable(O),u[O]=!0)}function _e(O){u[O]!==!1&&(r.disable(O),u[O]=!1)}function Ue(O,ve){return d[O]!==ve?(r.bindFramebuffer(O,ve),d[O]=ve,O===r.DRAW_FRAMEBUFFER&&(d[r.FRAMEBUFFER]=ve),O===r.FRAMEBUFFER&&(d[r.DRAW_FRAMEBUFFER]=ve),!0):!1}function Ae(O,ve){let le=p,Fe=!1;if(O){le=f.get(ve),le===void 0&&(le=[],f.set(ve,le));const Te=O.textures;if(le.length!==Te.length||le[0]!==r.COLOR_ATTACHMENT0){for(let me=0,$e=Te.length;me<$e;me++)le[me]=r.COLOR_ATTACHMENT0+me;le.length=Te.length,Fe=!0}}else le[0]!==r.BACK&&(le[0]=r.BACK,Fe=!0);Fe&&r.drawBuffers(le)}function dt(O){return g!==O?(r.useProgram(O),g=O,!0):!1}const tt={[Xn]:r.FUNC_ADD,[Bp]:r.FUNC_SUBTRACT,[Op]:r.FUNC_REVERSE_SUBTRACT};tt[z0]=r.MIN,tt[H0]=r.MAX;const gt={[Gr]:r.ZERO,[kp]:r.ONE,[Gp]:r.SRC_COLOR,[oc]:r.SRC_ALPHA,[Xp]:r.SRC_ALPHA_SATURATE,[Wp]:r.DST_COLOR,[zp]:r.DST_ALPHA,[Vp]:r.ONE_MINUS_SRC_COLOR,[ac]:r.ONE_MINUS_SRC_ALPHA,[$p]:r.ONE_MINUS_DST_COLOR,[Hp]:r.ONE_MINUS_DST_ALPHA,[LS]:r.CONSTANT_COLOR,[US]:r.ONE_MINUS_CONSTANT_COLOR,[FS]:r.CONSTANT_ALPHA,[IS]:r.ONE_MINUS_CONSTANT_ALPHA};function At(O,ve,le,Fe,Te,me,$e,ot,cn,Ot){if(O===Pn){m===!0&&(_e(r.BLEND),m=!1);return}if(m===!1&&(ue(r.BLEND),m=!0),O!==co){if(O!==_||Ot!==N){if((x!==Xn||M!==Xn)&&(r.blendEquation(r.FUNC_ADD),x=Xn,M=Xn),Ot)switch(O){case ti:r.blendFuncSeparate(r.ONE,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case _s:r.blendFunc(r.ONE,r.ONE);break;case xs:r.blendFuncSeparate(r.ZERO,r.ONE_MINUS_SRC_COLOR,r.ZERO,r.ONE);break;case ys:r.blendFuncSeparate(r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ZERO,r.ONE);break;default:ce("WebGLState: Invalid blending: ",O);break}else switch(O){case ti:r.blendFuncSeparate(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case _s:r.blendFuncSeparate(r.SRC_ALPHA,r.ONE,r.ONE,r.ONE);break;case xs:ce("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case ys:ce("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:ce("WebGLState: Invalid blending: ",O);break}y=null,b=null,S=null,E=null,v.set(0,0,0),w=0,_=O,N=Ot}return}Te=Te||ve,me=me||le,$e=$e||Fe,(ve!==x||Te!==M)&&(r.blendEquationSeparate(tt[ve],tt[Te]),x=ve,M=Te),(le!==y||Fe!==b||me!==S||$e!==E)&&(r.blendFuncSeparate(gt[le],gt[Fe],gt[me],gt[$e]),y=le,b=Fe,S=me,E=$e),(ot.equals(v)===!1||cn!==w)&&(r.blendColor(ot.r,ot.g,ot.b,cn),v.copy(ot),w=cn),_=O,N=!1}function nt(O,ve){O.side===Nn?_e(r.CULL_FACE):ue(r.CULL_FACE);let le=O.side===Lt;ve&&(le=!le),Bt(le),O.blending===ti&&O.transparent===!1?At(Pn):At(O.blending,O.blendEquation,O.blendSrc,O.blendDst,O.blendEquationAlpha,O.blendSrcAlpha,O.blendDstAlpha,O.blendColor,O.blendAlpha,O.premultipliedAlpha),o.setFunc(O.depthFunc),o.setTest(O.depthTest),o.setMask(O.depthWrite),s.setMask(O.colorWrite);const Fe=O.stencilWrite;a.setTest(Fe),Fe&&(a.setMask(O.stencilWriteMask),a.setFunc(O.stencilFunc,O.stencilRef,O.stencilFuncMask),a.setOp(O.stencilFail,O.stencilZFail,O.stencilZPass)),H(O.polygonOffset,O.polygonOffsetFactor,O.polygonOffsetUnits),O.alphaToCoverage===!0?ue(r.SAMPLE_ALPHA_TO_COVERAGE):_e(r.SAMPLE_ALPHA_TO_COVERAGE)}function Bt(O){C!==O&&(O?r.frontFace(r.CW):r.frontFace(r.CCW),C=O)}function Ut(O){O!==O0?(ue(r.CULL_FACE),O!==F&&(O===Jf?r.cullFace(r.BACK):O===k0?r.cullFace(r.FRONT):r.cullFace(r.FRONT_AND_BACK))):_e(r.CULL_FACE),F=O}function pi(O){O!==V&&(D&&r.lineWidth(O),V=O)}function H(O,ve,le){O?(ue(r.POLYGON_OFFSET_FILL),(z!==ve||U!==le)&&(z=ve,U=le,o.getReversed()&&(ve=-ve),r.polygonOffset(ve,le))):_e(r.POLYGON_OFFSET_FILL)}function vn(O){O?ue(r.SCISSOR_TEST):_e(r.SCISSOR_TEST)}function yt(O){O===void 0&&(O=r.TEXTURE0+B-1),fe!==O&&(r.activeTexture(O),fe=O)}function qt(O,ve,le){le===void 0&&(fe===null?le=r.TEXTURE0+B-1:le=fe);let Fe=Z[le];Fe===void 0&&(Fe={type:void 0,texture:void 0},Z[le]=Fe),(Fe.type!==O||Fe.texture!==ve)&&(fe!==le&&(r.activeTexture(le),fe=le),r.bindTexture(O,ve||ne[O]),Fe.type=O,Fe.texture=ve)}function Re(){const O=Z[fe];O!==void 0&&O.type!==void 0&&(r.bindTexture(O.type,null),O.type=void 0,O.texture=void 0)}function on(){try{r.compressedTexImage2D(...arguments)}catch(O){ce("WebGLState:",O)}}function R(){try{r.compressedTexImage3D(...arguments)}catch(O){ce("WebGLState:",O)}}function T(){try{r.texSubImage2D(...arguments)}catch(O){ce("WebGLState:",O)}}function q(){try{r.texSubImage3D(...arguments)}catch(O){ce("WebGLState:",O)}}function he(){try{r.compressedTexSubImage2D(...arguments)}catch(O){ce("WebGLState:",O)}}function ge(){try{r.compressedTexSubImage3D(...arguments)}catch(O){ce("WebGLState:",O)}}function xe(){try{r.texStorage2D(...arguments)}catch(O){ce("WebGLState:",O)}}function Me(){try{r.texStorage3D(...arguments)}catch(O){ce("WebGLState:",O)}}function se(){try{r.texImage2D(...arguments)}catch(O){ce("WebGLState:",O)}}function de(){try{r.texImage3D(...arguments)}catch(O){ce("WebGLState:",O)}}function Le(O){return h[O]!==void 0?h[O]:r.getParameter(O)}function Be(O,ve){h[O]!==ve&&(r.pixelStorei(O,ve),h[O]=ve)}function Se(O){ze.equals(O)===!1&&(r.scissor(O.x,O.y,O.z,O.w),ze.copy(O))}function ye(O){$.equals(O)===!1&&(r.viewport(O.x,O.y,O.z,O.w),$.copy(O))}function it(O,ve){let le=c.get(ve);le===void 0&&(le=new WeakMap,c.set(ve,le));let Fe=le.get(O);Fe===void 0&&(Fe=r.getUniformBlockIndex(ve,O.name),le.set(O,Fe))}function ut(O,ve){const Fe=c.get(ve).get(O);l.get(ve)!==Fe&&(r.uniformBlockBinding(ve,Fe,O.__bindingPointIndex),l.set(ve,Fe))}function Tt(){r.disable(r.BLEND),r.disable(r.CULL_FACE),r.disable(r.DEPTH_TEST),r.disable(r.POLYGON_OFFSET_FILL),r.disable(r.SCISSOR_TEST),r.disable(r.STENCIL_TEST),r.disable(r.SAMPLE_ALPHA_TO_COVERAGE),r.blendEquation(r.FUNC_ADD),r.blendFunc(r.ONE,r.ZERO),r.blendFuncSeparate(r.ONE,r.ZERO,r.ONE,r.ZERO),r.blendColor(0,0,0,0),r.colorMask(!0,!0,!0,!0),r.clearColor(0,0,0,0),r.depthMask(!0),r.depthFunc(r.LESS),o.setReversed(!1),r.clearDepth(1),r.stencilMask(4294967295),r.stencilFunc(r.ALWAYS,0,4294967295),r.stencilOp(r.KEEP,r.KEEP,r.KEEP),r.clearStencil(0),r.cullFace(r.BACK),r.frontFace(r.CCW),r.polygonOffset(0,0),r.activeTexture(r.TEXTURE0),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,null),r.bindFramebuffer(r.READ_FRAMEBUFFER,null),r.useProgram(null),r.lineWidth(1),r.scissor(0,0,r.canvas.width,r.canvas.height),r.viewport(0,0,r.canvas.width,r.canvas.height),r.pixelStorei(r.PACK_ALIGNMENT,4),r.pixelStorei(r.UNPACK_ALIGNMENT,4),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,r.BROWSER_DEFAULT_WEBGL),r.pixelStorei(r.PACK_ROW_LENGTH,0),r.pixelStorei(r.PACK_SKIP_PIXELS,0),r.pixelStorei(r.PACK_SKIP_ROWS,0),r.pixelStorei(r.UNPACK_ROW_LENGTH,0),r.pixelStorei(r.UNPACK_IMAGE_HEIGHT,0),r.pixelStorei(r.UNPACK_SKIP_PIXELS,0),r.pixelStorei(r.UNPACK_SKIP_ROWS,0),r.pixelStorei(r.UNPACK_SKIP_IMAGES,0),u={},h={},fe=null,Z={},d={},f=new WeakMap,p=[],g=null,m=!1,_=null,x=null,y=null,b=null,M=null,S=null,E=null,v=new We(0,0,0),w=0,N=!1,C=null,F=null,V=null,z=null,U=null,ze.set(0,0,r.canvas.width,r.canvas.height),$.set(0,0,r.canvas.width,r.canvas.height),s.reset(),o.reset(),a.reset()}return{buffers:{color:s,depth:o,stencil:a},enable:ue,disable:_e,bindFramebuffer:Ue,drawBuffers:Ae,useProgram:dt,setBlending:At,setMaterial:nt,setFlipSided:Bt,setCullFace:Ut,setLineWidth:pi,setPolygonOffset:H,setScissorTest:vn,activeTexture:yt,bindTexture:qt,unbindTexture:Re,compressedTexImage2D:on,compressedTexImage3D:R,texImage2D:se,texImage3D:de,pixelStorei:Be,getParameter:Le,updateUBOMapping:it,uniformBlockBinding:ut,texStorage2D:xe,texStorage3D:Me,texSubImage2D:T,texSubImage3D:q,compressedTexSubImage2D:he,compressedTexSubImage3D:ge,scissor:Se,viewport:ye,reset:Tt}}function mC(r,e,t,n,i,s,o){const a=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,l=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),c=new pe,u=new WeakMap,h=new Set;let d;const f=new WeakMap;let p=!1;try{p=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function g(R,T){return p?new OffscreenCanvas(R,T):bc("canvas")}function m(R,T,q){let he=1;const ge=on(R);if((ge.width>q||ge.height>q)&&(he=q/Math.max(ge.width,ge.height)),he<1)if(typeof HTMLImageElement<"u"&&R instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&R instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&R instanceof ImageBitmap||typeof VideoFrame<"u"&&R instanceof VideoFrame){const xe=Math.floor(he*ge.width),Me=Math.floor(he*ge.height);d===void 0&&(d=g(xe,Me));const se=T?g(xe,Me):d;return se.width=xe,se.height=Me,se.getContext("2d").drawImage(R,0,0,xe,Me),ae("WebGLRenderer: Texture has been resized from ("+ge.width+"x"+ge.height+") to ("+xe+"x"+Me+")."),se}else return"data"in R&&ae("WebGLRenderer: Image in DataTexture is too big ("+ge.width+"x"+ge.height+")."),R;return R}function _(R){return R.generateMipmaps}function x(R){r.generateMipmap(R)}function y(R){return R.isWebGLCubeRenderTarget?r.TEXTURE_CUBE_MAP:R.isWebGL3DRenderTarget?r.TEXTURE_3D:R.isWebGLArrayRenderTarget||R.isCompressedArrayTexture?r.TEXTURE_2D_ARRAY:r.TEXTURE_2D}function b(R,T,q,he,ge,xe=!1){if(R!==null){if(r[R]!==void 0)return r[R];ae("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+R+"'")}let Me;he&&(Me=e.get("EXT_texture_norm16"),Me||ae("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let se=T;if(T===r.RED&&(q===r.FLOAT&&(se=r.R32F),q===r.HALF_FLOAT&&(se=r.R16F),q===r.UNSIGNED_BYTE&&(se=r.R8),q===r.UNSIGNED_SHORT&&Me&&(se=Me.R16_EXT),q===r.SHORT&&Me&&(se=Me.R16_SNORM_EXT)),T===r.RED_INTEGER&&(q===r.UNSIGNED_BYTE&&(se=r.R8UI),q===r.UNSIGNED_SHORT&&(se=r.R16UI),q===r.UNSIGNED_INT&&(se=r.R32UI),q===r.BYTE&&(se=r.R8I),q===r.SHORT&&(se=r.R16I),q===r.INT&&(se=r.R32I)),T===r.RG&&(q===r.FLOAT&&(se=r.RG32F),q===r.HALF_FLOAT&&(se=r.RG16F),q===r.UNSIGNED_BYTE&&(se=r.RG8),q===r.UNSIGNED_SHORT&&Me&&(se=Me.RG16_EXT),q===r.SHORT&&Me&&(se=Me.RG16_SNORM_EXT)),T===r.RG_INTEGER&&(q===r.UNSIGNED_BYTE&&(se=r.RG8UI),q===r.UNSIGNED_SHORT&&(se=r.RG16UI),q===r.UNSIGNED_INT&&(se=r.RG32UI),q===r.BYTE&&(se=r.RG8I),q===r.SHORT&&(se=r.RG16I),q===r.INT&&(se=r.RG32I)),T===r.RGB_INTEGER&&(q===r.UNSIGNED_BYTE&&(se=r.RGB8UI),q===r.UNSIGNED_SHORT&&(se=r.RGB16UI),q===r.UNSIGNED_INT&&(se=r.RGB32UI),q===r.BYTE&&(se=r.RGB8I),q===r.SHORT&&(se=r.RGB16I),q===r.INT&&(se=r.RGB32I)),T===r.RGBA_INTEGER&&(q===r.UNSIGNED_BYTE&&(se=r.RGBA8UI),q===r.UNSIGNED_SHORT&&(se=r.RGBA16UI),q===r.UNSIGNED_INT&&(se=r.RGBA32UI),q===r.BYTE&&(se=r.RGBA8I),q===r.SHORT&&(se=r.RGBA16I),q===r.INT&&(se=r.RGBA32I)),T===r.RGB&&(q===r.UNSIGNED_SHORT&&Me&&(se=Me.RGB16_EXT),q===r.SHORT&&Me&&(se=Me.RGB16_SNORM_EXT),q===r.UNSIGNED_INT_5_9_9_9_REV&&(se=r.RGB9_E5),q===r.UNSIGNED_INT_10F_11F_11F_REV&&(se=r.R11F_G11F_B10F)),T===r.RGBA){const de=xe?ja:Ye.getTransfer(ge);q===r.FLOAT&&(se=r.RGBA32F),q===r.HALF_FLOAT&&(se=r.RGBA16F),q===r.UNSIGNED_BYTE&&(se=de===Pe?r.SRGB8_ALPHA8:r.RGBA8),q===r.UNSIGNED_SHORT&&Me&&(se=Me.RGBA16_EXT),q===r.SHORT&&Me&&(se=Me.RGBA16_SNORM_EXT),q===r.UNSIGNED_SHORT_4_4_4_4&&(se=r.RGBA4),q===r.UNSIGNED_SHORT_5_5_5_1&&(se=r.RGB5_A1)}return(se===r.R16F||se===r.R32F||se===r.RG16F||se===r.RG32F||se===r.RGBA16F||se===r.RGBA32F)&&e.get("EXT_color_buffer_float"),se}function M(R,T){let q;return R?T===null||T===Ct||T===di?q=r.DEPTH24_STENCIL8:T===Qt?q=r.DEPTH32F_STENCIL8:T===Li&&(q=r.DEPTH24_STENCIL8,ae("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):T===null||T===Ct||T===di?q=r.DEPTH_COMPONENT24:T===Qt?q=r.DEPTH_COMPONENT32F:T===Li&&(q=r.DEPTH_COMPONENT16),q}function S(R,T){return _(R)===!0||R.isFramebufferTexture&&R.minFilter!==Mt&&R.minFilter!==Nt?Math.log2(Math.max(T.width,T.height))+1:R.mipmaps!==void 0&&R.mipmaps.length>0?R.mipmaps.length:R.isCompressedTexture&&Array.isArray(R.image)?T.mipmaps.length:1}function E(R){const T=R.target;T.removeEventListener("dispose",E),w(T),T.isVideoTexture&&u.delete(T),T.isHTMLTexture&&h.delete(T)}function v(R){const T=R.target;T.removeEventListener("dispose",v),C(T)}function w(R){const T=n.get(R);if(T.__webglInit===void 0)return;const q=R.source,he=f.get(q);if(he){const ge=he[T.__cacheKey];ge.usedTimes--,ge.usedTimes===0&&N(R),Object.keys(he).length===0&&f.delete(q)}n.remove(R)}function N(R){const T=n.get(R);r.deleteTexture(T.__webglTexture);const q=R.source,he=f.get(q);delete he[T.__cacheKey],o.memory.textures--}function C(R){const T=n.get(R);if(R.depthTexture&&(R.depthTexture.dispose(),n.remove(R.depthTexture)),R.isWebGLCubeRenderTarget)for(let he=0;he<6;he++){if(Array.isArray(T.__webglFramebuffer[he]))for(let ge=0;ge<T.__webglFramebuffer[he].length;ge++)r.deleteFramebuffer(T.__webglFramebuffer[he][ge]);else r.deleteFramebuffer(T.__webglFramebuffer[he]);T.__webglDepthbuffer&&r.deleteRenderbuffer(T.__webglDepthbuffer[he])}else{if(Array.isArray(T.__webglFramebuffer))for(let he=0;he<T.__webglFramebuffer.length;he++)r.deleteFramebuffer(T.__webglFramebuffer[he]);else r.deleteFramebuffer(T.__webglFramebuffer);if(T.__webglDepthbuffer&&r.deleteRenderbuffer(T.__webglDepthbuffer),T.__webglMultisampledFramebuffer&&r.deleteFramebuffer(T.__webglMultisampledFramebuffer),T.__webglColorRenderbuffer)for(let he=0;he<T.__webglColorRenderbuffer.length;he++)T.__webglColorRenderbuffer[he]&&r.deleteRenderbuffer(T.__webglColorRenderbuffer[he]);T.__webglDepthRenderbuffer&&r.deleteRenderbuffer(T.__webglDepthRenderbuffer)}const q=R.textures;for(let he=0,ge=q.length;he<ge;he++){const xe=n.get(q[he]);xe.__webglTexture&&(r.deleteTexture(xe.__webglTexture),o.memory.textures--),n.remove(q[he])}n.remove(R)}let F=0;function V(){F=0}function z(){return F}function U(R){F=R}function B(){const R=F;return R>=i.maxTextures&&ae("WebGLTextures: Trying to use "+R+" texture units while this GPU supports only "+i.maxTextures),F+=1,R}function D(R){const T=[];return T.push(R.wrapS),T.push(R.wrapT),T.push(R.wrapR||0),T.push(R.magFilter),T.push(R.minFilter),T.push(R.anisotropy),T.push(R.internalFormat),T.push(R.format),T.push(R.type),T.push(R.generateMipmaps),T.push(R.premultiplyAlpha),T.push(R.flipY),T.push(R.unpackAlignment),T.push(R.colorSpace),T.join()}function X(R,T){const q=n.get(R);if(R.isVideoTexture&&qt(R),R.isRenderTargetTexture===!1&&R.isExternalTexture!==!0&&R.version>0&&q.__version!==R.version){const he=R.image;if(he===null)ae("WebGLRenderer: Texture marked for update but no image data found.");else if(he.complete===!1)ae("WebGLRenderer: Texture marked for update but image is incomplete");else{_e(q,R,T);return}}else R.isExternalTexture&&(q.__webglTexture=R.sourceTexture?R.sourceTexture:null);t.bindTexture(r.TEXTURE_2D,q.__webglTexture,r.TEXTURE0+T)}function K(R,T){const q=n.get(R);if(R.isRenderTargetTexture===!1&&R.version>0&&q.__version!==R.version){_e(q,R,T);return}else R.isExternalTexture&&(q.__webglTexture=R.sourceTexture?R.sourceTexture:null);t.bindTexture(r.TEXTURE_2D_ARRAY,q.__webglTexture,r.TEXTURE0+T)}function fe(R,T){const q=n.get(R);if(R.isRenderTargetTexture===!1&&R.version>0&&q.__version!==R.version){_e(q,R,T);return}t.bindTexture(r.TEXTURE_3D,q.__webglTexture,r.TEXTURE0+T)}function Z(R,T){const q=n.get(R);if(R.isCubeDepthTexture!==!0&&R.version>0&&q.__version!==R.version){Ue(q,R,T);return}t.bindTexture(r.TEXTURE_CUBE_MAP,q.__webglTexture,r.TEXTURE0+T)}const oe={[go]:r.REPEAT,[ci]:r.CLAMP_TO_EDGE,[_o]:r.MIRRORED_REPEAT},Ee={[Mt]:r.NEAREST,[em]:r.NEAREST_MIPMAP_NEAREST,[Xr]:r.NEAREST_MIPMAP_LINEAR,[Nt]:r.LINEAR,[ga]:r.LINEAR_MIPMAP_NEAREST,[ui]:r.LINEAR_MIPMAP_LINEAR},ze={[tm]:r.NEVER,[rm]:r.ALWAYS,[Ih]:r.LESS,[Os]:r.LEQUAL,[nm]:r.EQUAL,[Zr]:r.GEQUAL,[vc]:r.GREATER,[im]:r.NOTEQUAL};function $(R,T){if(T.type===Qt&&e.has("OES_texture_float_linear")===!1&&(T.magFilter===Nt||T.magFilter===ga||T.magFilter===Xr||T.magFilter===ui||T.minFilter===Nt||T.minFilter===ga||T.minFilter===Xr||T.minFilter===ui)&&ae("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),r.texParameteri(R,r.TEXTURE_WRAP_S,oe[T.wrapS]),r.texParameteri(R,r.TEXTURE_WRAP_T,oe[T.wrapT]),(R===r.TEXTURE_3D||R===r.TEXTURE_2D_ARRAY)&&r.texParameteri(R,r.TEXTURE_WRAP_R,oe[T.wrapR]),r.texParameteri(R,r.TEXTURE_MAG_FILTER,Ee[T.magFilter]),r.texParameteri(R,r.TEXTURE_MIN_FILTER,Ee[T.minFilter]),T.compareFunction&&(r.texParameteri(R,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(R,r.TEXTURE_COMPARE_FUNC,ze[T.compareFunction])),e.has("EXT_texture_filter_anisotropic")===!0){if(T.magFilter===Mt||T.minFilter!==Xr&&T.minFilter!==ui||T.type===Qt&&e.has("OES_texture_float_linear")===!1)return;if(T.anisotropy>1||n.get(T).__currentAnisotropy){const q=e.get("EXT_texture_filter_anisotropic");r.texParameterf(R,q.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(T.anisotropy,i.getMaxAnisotropy())),n.get(T).__currentAnisotropy=T.anisotropy}}}function I(R,T){let q=!1;R.__webglInit===void 0&&(R.__webglInit=!0,T.addEventListener("dispose",E));const he=T.source;let ge=f.get(he);ge===void 0&&(ge={},f.set(he,ge));const xe=D(T);if(xe!==R.__cacheKey){ge[xe]===void 0&&(ge[xe]={texture:r.createTexture(),usedTimes:0},o.memory.textures++,q=!0),ge[xe].usedTimes++;const Me=ge[R.__cacheKey];Me!==void 0&&(ge[R.__cacheKey].usedTimes--,Me.usedTimes===0&&N(T)),R.__cacheKey=xe,R.__webglTexture=ge[xe].texture}return q}function ne(R,T,q){return Math.floor(Math.floor(R/q)/T)}function ue(R,T,q,he){const xe=R.updateRanges;if(xe.length===0)t.texSubImage2D(r.TEXTURE_2D,0,0,0,T.width,T.height,q,he,T.data);else{xe.sort((Be,Se)=>Be.start-Se.start);let Me=0;for(let Be=1;Be<xe.length;Be++){const Se=xe[Me],ye=xe[Be],it=Se.start+Se.count,ut=ne(ye.start,T.width,4),Tt=ne(Se.start,T.width,4);ye.start<=it+1&&ut===Tt&&ne(ye.start+ye.count-1,T.width,4)===ut?Se.count=Math.max(Se.count,ye.start+ye.count-Se.start):(++Me,xe[Me]=ye)}xe.length=Me+1;const se=t.getParameter(r.UNPACK_ROW_LENGTH),de=t.getParameter(r.UNPACK_SKIP_PIXELS),Le=t.getParameter(r.UNPACK_SKIP_ROWS);t.pixelStorei(r.UNPACK_ROW_LENGTH,T.width);for(let Be=0,Se=xe.length;Be<Se;Be++){const ye=xe[Be],it=Math.floor(ye.start/4),ut=Math.ceil(ye.count/4),Tt=it%T.width,O=Math.floor(it/T.width),ve=ut,le=1;t.pixelStorei(r.UNPACK_SKIP_PIXELS,Tt),t.pixelStorei(r.UNPACK_SKIP_ROWS,O),t.texSubImage2D(r.TEXTURE_2D,0,Tt,O,ve,le,q,he,T.data)}R.clearUpdateRanges(),t.pixelStorei(r.UNPACK_ROW_LENGTH,se),t.pixelStorei(r.UNPACK_SKIP_PIXELS,de),t.pixelStorei(r.UNPACK_SKIP_ROWS,Le)}}function _e(R,T,q){let he=r.TEXTURE_2D;(T.isDataArrayTexture||T.isCompressedArrayTexture)&&(he=r.TEXTURE_2D_ARRAY),T.isData3DTexture&&(he=r.TEXTURE_3D);const ge=I(R,T),xe=T.source;t.bindTexture(he,R.__webglTexture,r.TEXTURE0+q);const Me=n.get(xe);if(xe.version!==Me.__version||ge===!0){if(t.activeTexture(r.TEXTURE0+q),(typeof ImageBitmap<"u"&&T.image instanceof ImageBitmap)===!1){const le=Ye.getPrimaries(Ye.workingColorSpace),Fe=T.colorSpace===ai?null:Ye.getPrimaries(T.colorSpace),Te=T.colorSpace===ai||le===Fe?r.NONE:r.BROWSER_DEFAULT_WEBGL;t.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,T.flipY),t.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,T.premultiplyAlpha),t.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,Te)}t.pixelStorei(r.UNPACK_ALIGNMENT,T.unpackAlignment);let de=m(T.image,!1,i.maxTextureSize);de=Re(T,de);const Le=s.convert(T.format,T.colorSpace),Be=s.convert(T.type);let Se=b(T.internalFormat,Le,Be,T.normalized,T.colorSpace,T.isVideoTexture);$(he,T);let ye;const it=T.mipmaps,ut=T.isVideoTexture!==!0,Tt=Me.__version===void 0||ge===!0,O=xe.dataReady,ve=S(T,de);if(T.isDepthTexture)Se=M(T.format===qn,T.type),Tt&&(ut?t.texStorage2D(r.TEXTURE_2D,1,Se,de.width,de.height):t.texImage2D(r.TEXTURE_2D,0,Se,de.width,de.height,0,Le,Be,null));else if(T.isDataTexture)if(it.length>0){ut&&Tt&&t.texStorage2D(r.TEXTURE_2D,ve,Se,it[0].width,it[0].height);for(let le=0,Fe=it.length;le<Fe;le++)ye=it[le],ut?O&&t.texSubImage2D(r.TEXTURE_2D,le,0,0,ye.width,ye.height,Le,Be,ye.data):t.texImage2D(r.TEXTURE_2D,le,Se,ye.width,ye.height,0,Le,Be,ye.data);T.generateMipmaps=!1}else ut?(Tt&&t.texStorage2D(r.TEXTURE_2D,ve,Se,de.width,de.height),O&&ue(T,de,Le,Be)):t.texImage2D(r.TEXTURE_2D,0,Se,de.width,de.height,0,Le,Be,de.data);else if(T.isCompressedTexture)if(T.isCompressedArrayTexture){ut&&Tt&&t.texStorage3D(r.TEXTURE_2D_ARRAY,ve,Se,it[0].width,it[0].height,de.depth);for(let le=0,Fe=it.length;le<Fe;le++)if(ye=it[le],T.format!==ln)if(Le!==null)if(ut){if(O)if(T.layerUpdates.size>0){const Te=rp(ye.width,ye.height,T.format,T.type);for(const me of T.layerUpdates){const $e=ye.data.subarray(me*Te/ye.data.BYTES_PER_ELEMENT,(me+1)*Te/ye.data.BYTES_PER_ELEMENT);t.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,le,0,0,me,ye.width,ye.height,1,Le,$e)}T.clearLayerUpdates()}else t.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,le,0,0,0,ye.width,ye.height,de.depth,Le,ye.data)}else t.compressedTexImage3D(r.TEXTURE_2D_ARRAY,le,Se,ye.width,ye.height,de.depth,0,ye.data,0,0);else ae("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else ut?O&&t.texSubImage3D(r.TEXTURE_2D_ARRAY,le,0,0,0,ye.width,ye.height,de.depth,Le,Be,ye.data):t.texImage3D(r.TEXTURE_2D_ARRAY,le,Se,ye.width,ye.height,de.depth,0,Le,Be,ye.data)}else{ut&&Tt&&t.texStorage2D(r.TEXTURE_2D,ve,Se,it[0].width,it[0].height);for(let le=0,Fe=it.length;le<Fe;le++)ye=it[le],T.format!==ln?Le!==null?ut?O&&t.compressedTexSubImage2D(r.TEXTURE_2D,le,0,0,ye.width,ye.height,Le,ye.data):t.compressedTexImage2D(r.TEXTURE_2D,le,Se,ye.width,ye.height,0,ye.data):ae("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):ut?O&&t.texSubImage2D(r.TEXTURE_2D,le,0,0,ye.width,ye.height,Le,Be,ye.data):t.texImage2D(r.TEXTURE_2D,le,Se,ye.width,ye.height,0,Le,Be,ye.data)}else if(T.isDataArrayTexture)if(ut){if(Tt&&t.texStorage3D(r.TEXTURE_2D_ARRAY,ve,Se,de.width,de.height,de.depth),O)if(T.layerUpdates.size>0){const le=rp(de.width,de.height,T.format,T.type);for(const Fe of T.layerUpdates){const Te=de.data.subarray(Fe*le/de.data.BYTES_PER_ELEMENT,(Fe+1)*le/de.data.BYTES_PER_ELEMENT);t.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,Fe,de.width,de.height,1,Le,Be,Te)}T.clearLayerUpdates()}else t.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,0,de.width,de.height,de.depth,Le,Be,de.data)}else t.texImage3D(r.TEXTURE_2D_ARRAY,0,Se,de.width,de.height,de.depth,0,Le,Be,de.data);else if(T.isData3DTexture)ut?(Tt&&t.texStorage3D(r.TEXTURE_3D,ve,Se,de.width,de.height,de.depth),O&&t.texSubImage3D(r.TEXTURE_3D,0,0,0,0,de.width,de.height,de.depth,Le,Be,de.data)):t.texImage3D(r.TEXTURE_3D,0,Se,de.width,de.height,de.depth,0,Le,Be,de.data);else if(T.isFramebufferTexture){if(Tt)if(ut)t.texStorage2D(r.TEXTURE_2D,ve,Se,de.width,de.height);else{let le=de.width,Fe=de.height;for(let Te=0;Te<ve;Te++)t.texImage2D(r.TEXTURE_2D,Te,Se,le,Fe,0,Le,Be,null),le>>=1,Fe>>=1}}else if(T.isHTMLTexture){if("texElementImage2D"in r){const le=r.canvas;if(le.hasAttribute("layoutsubtree")||le.setAttribute("layoutsubtree","true"),de.parentNode!==le){le.appendChild(de),h.add(T),le.onpaint=ot=>{const cn=ot.changedElements;for(const Ot of h)cn.includes(Ot.image)&&(Ot.needsUpdate=!0)},le.requestPaint();return}const Fe=0,Te=r.RGBA,me=r.RGBA,$e=r.UNSIGNED_BYTE;r.texElementImage2D(r.TEXTURE_2D,Fe,Te,me,$e,de),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE)}}else if(it.length>0){if(ut&&Tt){const le=on(it[0]);t.texStorage2D(r.TEXTURE_2D,ve,Se,le.width,le.height)}for(let le=0,Fe=it.length;le<Fe;le++)ye=it[le],ut?O&&t.texSubImage2D(r.TEXTURE_2D,le,0,0,Le,Be,ye):t.texImage2D(r.TEXTURE_2D,le,Se,Le,Be,ye);T.generateMipmaps=!1}else if(ut){if(Tt){const le=on(de);t.texStorage2D(r.TEXTURE_2D,ve,Se,le.width,le.height)}O&&t.texSubImage2D(r.TEXTURE_2D,0,0,0,Le,Be,de)}else t.texImage2D(r.TEXTURE_2D,0,Se,Le,Be,de);_(T)&&x(he),Me.__version=xe.version,T.onUpdate&&T.onUpdate(T)}R.__version=T.version}function Ue(R,T,q){if(T.image.length!==6)return;const he=I(R,T),ge=T.source;t.bindTexture(r.TEXTURE_CUBE_MAP,R.__webglTexture,r.TEXTURE0+q);const xe=n.get(ge);if(ge.version!==xe.__version||he===!0){t.activeTexture(r.TEXTURE0+q);const Me=Ye.getPrimaries(Ye.workingColorSpace),se=T.colorSpace===ai?null:Ye.getPrimaries(T.colorSpace),de=T.colorSpace===ai||Me===se?r.NONE:r.BROWSER_DEFAULT_WEBGL;t.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,T.flipY),t.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,T.premultiplyAlpha),t.pixelStorei(r.UNPACK_ALIGNMENT,T.unpackAlignment),t.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,de);const Le=T.isCompressedTexture||T.image[0].isCompressedTexture,Be=T.image[0]&&T.image[0].isDataTexture,Se=[];for(let me=0;me<6;me++)!Le&&!Be?Se[me]=m(T.image[me],!0,i.maxCubemapSize):Se[me]=Be?T.image[me].image:T.image[me],Se[me]=Re(T,Se[me]);const ye=Se[0],it=s.convert(T.format,T.colorSpace),ut=s.convert(T.type),Tt=b(T.internalFormat,it,ut,T.normalized,T.colorSpace),O=T.isVideoTexture!==!0,ve=xe.__version===void 0||he===!0,le=ge.dataReady;let Fe=S(T,ye);$(r.TEXTURE_CUBE_MAP,T);let Te;if(Le){O&&ve&&t.texStorage2D(r.TEXTURE_CUBE_MAP,Fe,Tt,ye.width,ye.height);for(let me=0;me<6;me++){Te=Se[me].mipmaps;for(let $e=0;$e<Te.length;$e++){const ot=Te[$e];T.format!==ln?it!==null?O?le&&t.compressedTexSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e,0,0,ot.width,ot.height,it,ot.data):t.compressedTexImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e,Tt,ot.width,ot.height,0,ot.data):ae("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):O?le&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e,0,0,ot.width,ot.height,it,ut,ot.data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e,Tt,ot.width,ot.height,0,it,ut,ot.data)}}}else{if(Te=T.mipmaps,O&&ve){Te.length>0&&Fe++;const me=on(Se[0]);t.texStorage2D(r.TEXTURE_CUBE_MAP,Fe,Tt,me.width,me.height)}for(let me=0;me<6;me++)if(Be){O?le&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,0,0,0,Se[me].width,Se[me].height,it,ut,Se[me].data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,0,Tt,Se[me].width,Se[me].height,0,it,ut,Se[me].data);for(let $e=0;$e<Te.length;$e++){const cn=Te[$e].image[me].image;O?le&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e+1,0,0,cn.width,cn.height,it,ut,cn.data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e+1,Tt,cn.width,cn.height,0,it,ut,cn.data)}}else{O?le&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,0,0,0,it,ut,Se[me]):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,0,Tt,it,ut,Se[me]);for(let $e=0;$e<Te.length;$e++){const ot=Te[$e];O?le&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e+1,0,0,it,ut,ot.image[me]):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+me,$e+1,Tt,it,ut,ot.image[me])}}}_(T)&&x(r.TEXTURE_CUBE_MAP),xe.__version=ge.version,T.onUpdate&&T.onUpdate(T)}R.__version=T.version}function Ae(R,T,q,he,ge,xe){const Me=s.convert(q.format,q.colorSpace),se=s.convert(q.type),de=b(q.internalFormat,Me,se,q.normalized,q.colorSpace),Le=n.get(T),Be=n.get(q);if(Be.__renderTarget=T,!Le.__hasExternalTextures){const Se=Math.max(1,T.width>>xe),ye=Math.max(1,T.height>>xe);ge===r.TEXTURE_3D||ge===r.TEXTURE_2D_ARRAY?t.texImage3D(ge,xe,de,Se,ye,T.depth,0,Me,se,null):t.texImage2D(ge,xe,de,Se,ye,0,Me,se,null)}t.bindFramebuffer(r.FRAMEBUFFER,R),yt(T)?a.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,he,ge,Be.__webglTexture,0,vn(T)):(ge===r.TEXTURE_2D||ge>=r.TEXTURE_CUBE_MAP_POSITIVE_X&&ge<=r.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&r.framebufferTexture2D(r.FRAMEBUFFER,he,ge,Be.__webglTexture,xe),t.bindFramebuffer(r.FRAMEBUFFER,null)}function dt(R,T,q){if(r.bindRenderbuffer(r.RENDERBUFFER,R),T.depthBuffer){const he=T.depthTexture,ge=he&&he.isDepthTexture?he.type:null,xe=M(T.stencilBuffer,ge),Me=T.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;yt(T)?a.renderbufferStorageMultisampleEXT(r.RENDERBUFFER,vn(T),xe,T.width,T.height):q?r.renderbufferStorageMultisample(r.RENDERBUFFER,vn(T),xe,T.width,T.height):r.renderbufferStorage(r.RENDERBUFFER,xe,T.width,T.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,Me,r.RENDERBUFFER,R)}else{const he=T.textures;for(let ge=0;ge<he.length;ge++){const xe=he[ge],Me=s.convert(xe.format,xe.colorSpace),se=s.convert(xe.type),de=b(xe.internalFormat,Me,se,xe.normalized,xe.colorSpace);yt(T)?a.renderbufferStorageMultisampleEXT(r.RENDERBUFFER,vn(T),de,T.width,T.height):q?r.renderbufferStorageMultisample(r.RENDERBUFFER,vn(T),de,T.width,T.height):r.renderbufferStorage(r.RENDERBUFFER,de,T.width,T.height)}}r.bindRenderbuffer(r.RENDERBUFFER,null)}function tt(R,T,q){const he=T.isWebGLCubeRenderTarget===!0;if(t.bindFramebuffer(r.FRAMEBUFFER,R),!(T.depthTexture&&T.depthTexture.isDepthTexture))throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");const ge=n.get(T.depthTexture);if(ge.__renderTarget=T,(!ge.__webglTexture||T.depthTexture.image.width!==T.width||T.depthTexture.image.height!==T.height)&&(T.depthTexture.image.width=T.width,T.depthTexture.image.height=T.height,T.depthTexture.needsUpdate=!0),he){if(ge.__webglInit===void 0&&(ge.__webglInit=!0,T.depthTexture.addEventListener("dispose",E)),ge.__webglTexture===void 0){ge.__webglTexture=r.createTexture(),t.bindTexture(r.TEXTURE_CUBE_MAP,ge.__webglTexture),$(r.TEXTURE_CUBE_MAP,T.depthTexture);const Le=s.convert(T.depthTexture.format),Be=s.convert(T.depthTexture.type);let Se;T.depthTexture.format===Dn?Se=r.DEPTH_COMPONENT24:T.depthTexture.format===qn&&(Se=r.DEPTH24_STENCIL8);for(let ye=0;ye<6;ye++)r.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+ye,0,Se,T.width,T.height,0,Le,Be,null)}}else X(T.depthTexture,0);const xe=ge.__webglTexture,Me=vn(T),se=he?r.TEXTURE_CUBE_MAP_POSITIVE_X+q:r.TEXTURE_2D,de=T.depthTexture.format===qn?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;if(T.depthTexture.format===Dn)yt(T)?a.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,de,se,xe,0,Me):r.framebufferTexture2D(r.FRAMEBUFFER,de,se,xe,0);else if(T.depthTexture.format===qn)yt(T)?a.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,de,se,xe,0,Me):r.framebufferTexture2D(r.FRAMEBUFFER,de,se,xe,0);else throw new Error("Unknown depthTexture format")}function gt(R){const T=n.get(R),q=R.isWebGLCubeRenderTarget===!0;if(T.__boundDepthTexture!==R.depthTexture){const he=R.depthTexture;if(T.__depthDisposeCallback&&T.__depthDisposeCallback(),he){const ge=()=>{delete T.__boundDepthTexture,delete T.__depthDisposeCallback,he.removeEventListener("dispose",ge)};he.addEventListener("dispose",ge),T.__depthDisposeCallback=ge}T.__boundDepthTexture=he}if(R.depthTexture&&!T.__autoAllocateDepthBuffer)if(q)for(let he=0;he<6;he++)tt(T.__webglFramebuffer[he],R,he);else{const he=R.texture.mipmaps;he&&he.length>0?tt(T.__webglFramebuffer[0],R,0):tt(T.__webglFramebuffer,R,0)}else if(q){T.__webglDepthbuffer=[];for(let he=0;he<6;he++)if(t.bindFramebuffer(r.FRAMEBUFFER,T.__webglFramebuffer[he]),T.__webglDepthbuffer[he]===void 0)T.__webglDepthbuffer[he]=r.createRenderbuffer(),dt(T.__webglDepthbuffer[he],R,!1);else{const ge=R.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,xe=T.__webglDepthbuffer[he];r.bindRenderbuffer(r.RENDERBUFFER,xe),r.framebufferRenderbuffer(r.FRAMEBUFFER,ge,r.RENDERBUFFER,xe)}}else{const he=R.texture.mipmaps;if(he&&he.length>0?t.bindFramebuffer(r.FRAMEBUFFER,T.__webglFramebuffer[0]):t.bindFramebuffer(r.FRAMEBUFFER,T.__webglFramebuffer),T.__webglDepthbuffer===void 0)T.__webglDepthbuffer=r.createRenderbuffer(),dt(T.__webglDepthbuffer,R,!1);else{const ge=R.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,xe=T.__webglDepthbuffer;r.bindRenderbuffer(r.RENDERBUFFER,xe),r.framebufferRenderbuffer(r.FRAMEBUFFER,ge,r.RENDERBUFFER,xe)}}t.bindFramebuffer(r.FRAMEBUFFER,null)}function At(R,T,q){const he=n.get(R);T!==void 0&&Ae(he.__webglFramebuffer,R,R.texture,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,0),q!==void 0&&gt(R)}function nt(R){const T=R.texture,q=n.get(R),he=n.get(T);R.addEventListener("dispose",v);const ge=R.textures,xe=R.isWebGLCubeRenderTarget===!0,Me=ge.length>1;if(Me||(he.__webglTexture===void 0&&(he.__webglTexture=r.createTexture()),he.__version=T.version,o.memory.textures++),xe){q.__webglFramebuffer=[];for(let se=0;se<6;se++)if(T.mipmaps&&T.mipmaps.length>0){q.__webglFramebuffer[se]=[];for(let de=0;de<T.mipmaps.length;de++)q.__webglFramebuffer[se][de]=r.createFramebuffer()}else q.__webglFramebuffer[se]=r.createFramebuffer()}else{if(T.mipmaps&&T.mipmaps.length>0){q.__webglFramebuffer=[];for(let se=0;se<T.mipmaps.length;se++)q.__webglFramebuffer[se]=r.createFramebuffer()}else q.__webglFramebuffer=r.createFramebuffer();if(Me)for(let se=0,de=ge.length;se<de;se++){const Le=n.get(ge[se]);Le.__webglTexture===void 0&&(Le.__webglTexture=r.createTexture(),o.memory.textures++)}if(R.samples>0&&yt(R)===!1){q.__webglMultisampledFramebuffer=r.createFramebuffer(),q.__webglColorRenderbuffer=[],t.bindFramebuffer(r.FRAMEBUFFER,q.__webglMultisampledFramebuffer);for(let se=0;se<ge.length;se++){const de=ge[se];q.__webglColorRenderbuffer[se]=r.createRenderbuffer(),r.bindRenderbuffer(r.RENDERBUFFER,q.__webglColorRenderbuffer[se]);const Le=s.convert(de.format,de.colorSpace),Be=s.convert(de.type),Se=b(de.internalFormat,Le,Be,de.normalized,de.colorSpace,R.isXRRenderTarget===!0),ye=vn(R);r.renderbufferStorageMultisample(r.RENDERBUFFER,ye,Se,R.width,R.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+se,r.RENDERBUFFER,q.__webglColorRenderbuffer[se])}r.bindRenderbuffer(r.RENDERBUFFER,null),R.depthBuffer&&(q.__webglDepthRenderbuffer=r.createRenderbuffer(),dt(q.__webglDepthRenderbuffer,R,!0)),t.bindFramebuffer(r.FRAMEBUFFER,null)}}if(xe){t.bindTexture(r.TEXTURE_CUBE_MAP,he.__webglTexture),$(r.TEXTURE_CUBE_MAP,T);for(let se=0;se<6;se++)if(T.mipmaps&&T.mipmaps.length>0)for(let de=0;de<T.mipmaps.length;de++)Ae(q.__webglFramebuffer[se][de],R,T,r.COLOR_ATTACHMENT0,r.TEXTURE_CUBE_MAP_POSITIVE_X+se,de);else Ae(q.__webglFramebuffer[se],R,T,r.COLOR_ATTACHMENT0,r.TEXTURE_CUBE_MAP_POSITIVE_X+se,0);_(T)&&x(r.TEXTURE_CUBE_MAP),t.unbindTexture()}else if(Me){for(let se=0,de=ge.length;se<de;se++){const Le=ge[se],Be=n.get(Le);let Se=r.TEXTURE_2D;(R.isWebGL3DRenderTarget||R.isWebGLArrayRenderTarget)&&(Se=R.isWebGL3DRenderTarget?r.TEXTURE_3D:r.TEXTURE_2D_ARRAY),t.bindTexture(Se,Be.__webglTexture),$(Se,Le),Ae(q.__webglFramebuffer,R,Le,r.COLOR_ATTACHMENT0+se,Se,0),_(Le)&&x(Se)}t.unbindTexture()}else{let se=r.TEXTURE_2D;if((R.isWebGL3DRenderTarget||R.isWebGLArrayRenderTarget)&&(se=R.isWebGL3DRenderTarget?r.TEXTURE_3D:r.TEXTURE_2D_ARRAY),t.bindTexture(se,he.__webglTexture),$(se,T),T.mipmaps&&T.mipmaps.length>0)for(let de=0;de<T.mipmaps.length;de++)Ae(q.__webglFramebuffer[de],R,T,r.COLOR_ATTACHMENT0,se,de);else Ae(q.__webglFramebuffer,R,T,r.COLOR_ATTACHMENT0,se,0);_(T)&&x(se),t.unbindTexture()}R.depthBuffer&&gt(R)}function Bt(R){const T=R.textures;for(let q=0,he=T.length;q<he;q++){const ge=T[q];if(_(ge)){const xe=y(R),Me=n.get(ge).__webglTexture;t.bindTexture(xe,Me),x(xe),t.unbindTexture()}}}const Ut=[],pi=[];function H(R){if(R.samples>0){if(yt(R)===!1){const T=R.textures,q=R.width,he=R.height;let ge=r.COLOR_BUFFER_BIT;const xe=R.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,Me=n.get(R),se=T.length>1;if(se)for(let Le=0;Le<T.length;Le++)t.bindFramebuffer(r.FRAMEBUFFER,Me.__webglMultisampledFramebuffer),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+Le,r.RENDERBUFFER,null),t.bindFramebuffer(r.FRAMEBUFFER,Me.__webglFramebuffer),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0+Le,r.TEXTURE_2D,null,0);t.bindFramebuffer(r.READ_FRAMEBUFFER,Me.__webglMultisampledFramebuffer);const de=R.texture.mipmaps;de&&de.length>0?t.bindFramebuffer(r.DRAW_FRAMEBUFFER,Me.__webglFramebuffer[0]):t.bindFramebuffer(r.DRAW_FRAMEBUFFER,Me.__webglFramebuffer);for(let Le=0;Le<T.length;Le++){if(R.resolveDepthBuffer&&(R.depthBuffer&&(ge|=r.DEPTH_BUFFER_BIT),R.stencilBuffer&&R.resolveStencilBuffer&&(ge|=r.STENCIL_BUFFER_BIT)),se){r.framebufferRenderbuffer(r.READ_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.RENDERBUFFER,Me.__webglColorRenderbuffer[Le]);const Be=n.get(T[Le]).__webglTexture;r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,Be,0)}r.blitFramebuffer(0,0,q,he,0,0,q,he,ge,r.NEAREST),l===!0&&(Ut.length=0,pi.length=0,Ut.push(r.COLOR_ATTACHMENT0+Le),R.depthBuffer&&R.resolveDepthBuffer===!1&&(Ut.push(xe),pi.push(xe),r.invalidateFramebuffer(r.DRAW_FRAMEBUFFER,pi)),r.invalidateFramebuffer(r.READ_FRAMEBUFFER,Ut))}if(t.bindFramebuffer(r.READ_FRAMEBUFFER,null),t.bindFramebuffer(r.DRAW_FRAMEBUFFER,null),se)for(let Le=0;Le<T.length;Le++){t.bindFramebuffer(r.FRAMEBUFFER,Me.__webglMultisampledFramebuffer),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+Le,r.RENDERBUFFER,Me.__webglColorRenderbuffer[Le]);const Be=n.get(T[Le]).__webglTexture;t.bindFramebuffer(r.FRAMEBUFFER,Me.__webglFramebuffer),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0+Le,r.TEXTURE_2D,Be,0)}t.bindFramebuffer(r.DRAW_FRAMEBUFFER,Me.__webglMultisampledFramebuffer)}else if(R.depthBuffer&&R.resolveDepthBuffer===!1&&l){const T=R.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;r.invalidateFramebuffer(r.DRAW_FRAMEBUFFER,[T])}}}function vn(R){return Math.min(i.maxSamples,R.samples)}function yt(R){const T=n.get(R);return R.samples>0&&e.has("WEBGL_multisampled_render_to_texture")===!0&&T.__useRenderToTexture!==!1}function qt(R){const T=o.render.frame;u.get(R)!==T&&(u.set(R,T),R.update())}function Re(R,T){const q=R.colorSpace,he=R.format,ge=R.type;return R.isCompressedTexture===!0||R.isVideoTexture===!0||q!==yc&&q!==ai&&(Ye.getTransfer(q)===Pe?(he!==ln||ge!==Xt)&&ae("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):ce("WebGLTextures: Unsupported texture color space:",q)),T}function on(R){return typeof HTMLImageElement<"u"&&R instanceof HTMLImageElement?(c.width=R.naturalWidth||R.width,c.height=R.naturalHeight||R.height):typeof VideoFrame<"u"&&R instanceof VideoFrame?(c.width=R.displayWidth,c.height=R.displayHeight):(c.width=R.width,c.height=R.height),c}this.allocateTextureUnit=B,this.resetTextureUnits=V,this.getTextureUnits=z,this.setTextureUnits=U,this.setTexture2D=X,this.setTexture2DArray=K,this.setTexture3D=fe,this.setTextureCube=Z,this.rebindTextures=At,this.setupRenderTarget=nt,this.updateRenderTargetMipmap=Bt,this.updateMultisampleRenderTarget=H,this.setupDepthRenderbuffer=gt,this.setupFrameBufferTexture=Ae,this.useMultisampledRTT=yt,this.isReversedDepthBuffer=function(){return t.buffers.depth.getReversed()}}function gC(r,e){function t(n,i=ai){let s;const o=Ye.getTransfer(i);if(n===Xt)return r.UNSIGNED_BYTE;if(n===Pc)return r.UNSIGNED_SHORT_4_4_4_4;if(n===Dc)return r.UNSIGNED_SHORT_5_5_5_1;if(n===Lc)return r.UNSIGNED_INT_5_9_9_9_REV;if(n===Uc)return r.UNSIGNED_INT_10F_11F_11F_REV;if(n===Ts)return r.BYTE;if(n===Ms)return r.SHORT;if(n===Li)return r.UNSIGNED_SHORT;if(n===Sn)return r.INT;if(n===Ct)return r.UNSIGNED_INT;if(n===Qt)return r.FLOAT;if(n===tn)return r.HALF_FLOAT;if(n===Fh)return r.ALPHA;if(n===nl)return r.RGB;if(n===ln)return r.RGBA;if(n===Dn)return r.DEPTH_COMPONENT;if(n===qn)return r.DEPTH_STENCIL;if(n===il)return r.RED;if(n===Eo)return r.RED_INTEGER;if(n===In)return r.RG;if(n===Ao)return r.RG_INTEGER;if(n===rl)return r.RGBA_INTEGER;if(n===Es||n===As||n===ws||n===Rs)if(o===Pe)if(s=e.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(n===Es)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(n===As)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(n===ws)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(n===Rs)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=e.get("WEBGL_compressed_texture_s3tc"),s!==null){if(n===Es)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(n===As)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(n===ws)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(n===Rs)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(n===mc||n===gc||n===_c||n===xc)if(s=e.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(n===mc)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(n===gc)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(n===_c)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(n===xc)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(n===Ma||n===Ea||n===Aa||n===wa||n===Ra||n===Ls||n===Ca)if(s=e.get("WEBGL_compressed_texture_etc"),s!==null){if(n===Ma||n===Ea)return o===Pe?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(n===Aa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(n===wa)return s.COMPRESSED_R11_EAC;if(n===Ra)return s.COMPRESSED_SIGNED_R11_EAC;if(n===Ls)return s.COMPRESSED_RG11_EAC;if(n===Ca)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(n===Na||n===Pa||n===Da||n===La||n===Ua||n===Fa||n===Ia||n===Ba||n===Oa||n===ka||n===Ga||n===Va||n===za||n===Ha)if(s=e.get("WEBGL_compressed_texture_astc"),s!==null){if(n===Na)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(n===Pa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(n===Da)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(n===La)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(n===Ua)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(n===Fa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(n===Ia)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(n===Ba)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(n===Oa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(n===ka)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(n===Ga)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(n===Va)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(n===za)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(n===Ha)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(n===Wa||n===ep||n===tp)if(s=e.get("EXT_texture_compression_bptc"),s!==null){if(n===Wa)return o===Pe?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(n===ep)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(n===tp)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(n===$a||n===Xa||n===Us||n===qa)if(s=e.get("EXT_texture_compression_rgtc"),s!==null){if(n===$a)return s.COMPRESSED_RED_RGTC1_EXT;if(n===Xa)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(n===Us)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(n===qa)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return n===di?r.UNSIGNED_INT_24_8:r[n]!==void 0?r[n]:null}return{convert:t}}const _C=`
4089
4089
  void main() {
4090
4090
 
4091
4091
  gl_Position = vec4( position, 1.0 );
@@ -4109,7 +4109,7 @@ void main() {
4109
4109
 
4110
4110
  }
4111
4111
 
4112
- }`;class yC{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){const n=new ry(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=n}}getMesh(e){if(this.texture!==null&&this.mesh===null){const t=e.cameras[0].viewport,n=new ki({vertexShader:_C,fragmentShader:xC,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new _n(new Oc(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class vC extends Vi{constructor(e,t){super();const n=this;let i=null,s=1,o=null,a="local-floor",l=1,c=null,u=null,h=null,d=null,f=null,p=null;const g=typeof XRWebGLBinding<"u",m=new yC,_={},x=t.getContextAttributes();let y=null,b=null;const M=[],S=[],E=new pe;let v=null;const w=new Cn;w.viewport=new rt;const N=new Cn;N.viewport=new rt;const C=[w,N],F=new my;let V=null,z=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(I){let ne=M[I];return ne===void 0&&(ne=new oh,M[I]=ne),ne.getTargetRaySpace()},this.getControllerGrip=function(I){let ne=M[I];return ne===void 0&&(ne=new oh,M[I]=ne),ne.getGripSpace()},this.getHand=function(I){let ne=M[I];return ne===void 0&&(ne=new oh,M[I]=ne),ne.getHandSpace()};function U(I){const ne=S.indexOf(I.inputSource);if(ne===-1)return;const ue=M[ne];ue!==void 0&&(ue.update(I.inputSource,I.frame,c||o),ue.dispatchEvent({type:I.type,data:I.inputSource}))}function B(){i.removeEventListener("select",U),i.removeEventListener("selectstart",U),i.removeEventListener("selectend",U),i.removeEventListener("squeeze",U),i.removeEventListener("squeezestart",U),i.removeEventListener("squeezeend",U),i.removeEventListener("end",B),i.removeEventListener("inputsourceschange",D);for(let I=0;I<M.length;I++){const ne=S[I];ne!==null&&(S[I]=null,M[I].disconnect(ne))}V=null,z=null,m.reset();for(const I in _)delete _[I];e.setRenderTarget(y),f=null,d=null,h=null,i=null,b=null,$.stop(),n.isPresenting=!1,e.setPixelRatio(v),e.setSize(E.width,E.height,!1),n.dispatchEvent({type:"sessionend"})}this.setFramebufferScaleFactor=function(I){s=I,n.isPresenting===!0&&ae("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(I){a=I,n.isPresenting===!0&&ae("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return c||o},this.setReferenceSpace=function(I){c=I},this.getBaseLayer=function(){return d!==null?d:f},this.getBinding=function(){return h===null&&g&&(h=new XRWebGLBinding(i,t)),h},this.getFrame=function(){return p},this.getSession=function(){return i},this.setSession=async function(I){if(i=I,i!==null){if(y=e.getRenderTarget(),i.addEventListener("select",U),i.addEventListener("selectstart",U),i.addEventListener("selectend",U),i.addEventListener("squeeze",U),i.addEventListener("squeezestart",U),i.addEventListener("squeezeend",U),i.addEventListener("end",B),i.addEventListener("inputsourceschange",D),x.xrCompatible!==!0&&await t.makeXRCompatible(),v=e.getPixelRatio(),e.getSize(E),g&&"createProjectionLayer"in XRWebGLBinding.prototype){let ue=null,_e=null,Ue=null;x.depth&&(Ue=x.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,ue=x.stencil?qn:Dn,_e=x.stencil?di:Ct);const Ae={colorFormat:t.RGBA8,depthFormat:Ue,scaleFactor:s};h=this.getBinding(),d=h.createProjectionLayer(Ae),i.updateRenderState({layers:[d]}),e.setPixelRatio(1),e.setSize(d.textureWidth,d.textureHeight,!1),b=new Yi(d.textureWidth,d.textureHeight,{format:ln,type:Xt,depthTexture:new jn(d.textureWidth,d.textureHeight,_e,void 0,void 0,void 0,void 0,void 0,void 0,ue),stencilBuffer:x.stencil,colorSpace:e.outputColorSpace,samples:x.antialias?4:0,resolveDepthBuffer:d.ignoreDepthValues===!1,resolveStencilBuffer:d.ignoreDepthValues===!1})}else{const ue={antialias:x.antialias,alpha:!0,depth:x.depth,stencil:x.stencil,framebufferScaleFactor:s};f=new XRWebGLLayer(i,t,ue),i.updateRenderState({baseLayer:f}),e.setPixelRatio(1),e.setSize(f.framebufferWidth,f.framebufferHeight,!1),b=new Yi(f.framebufferWidth,f.framebufferHeight,{format:ln,type:Xt,colorSpace:e.outputColorSpace,stencilBuffer:x.stencil,resolveDepthBuffer:f.ignoreDepthValues===!1,resolveStencilBuffer:f.ignoreDepthValues===!1})}b.isXRRenderTarget=!0,this.setFoveation(l),c=null,o=await i.requestReferenceSpace(a),$.setContext(i),$.start(),n.isPresenting=!0,n.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(i!==null)return i.environmentBlendMode},this.getDepthTexture=function(){return m.getDepthTexture()};function D(I){for(let ne=0;ne<I.removed.length;ne++){const ue=I.removed[ne],_e=S.indexOf(ue);_e>=0&&(S[_e]=null,M[_e].disconnect(ue))}for(let ne=0;ne<I.added.length;ne++){const ue=I.added[ne];let _e=S.indexOf(ue);if(_e===-1){for(let Ae=0;Ae<M.length;Ae++)if(Ae>=S.length){S.push(ue),_e=Ae;break}else if(S[Ae]===null){S[Ae]=ue,_e=Ae;break}if(_e===-1)break}const Ue=M[_e];Ue&&Ue.connect(ue)}}const X=new P,K=new P;function fe(I,ne,ue){X.setFromMatrixPosition(ne.matrixWorld),K.setFromMatrixPosition(ue.matrixWorld);const _e=X.distanceTo(K),Ue=ne.projectionMatrix.elements,Ae=ue.projectionMatrix.elements,dt=Ue[14]/(Ue[10]-1),tt=Ue[14]/(Ue[10]+1),gt=(Ue[9]+1)/Ue[5],At=(Ue[9]-1)/Ue[5],nt=(Ue[8]-1)/Ue[0],Bt=(Ae[8]+1)/Ae[0],Ut=dt*nt,mi=dt*Bt,H=_e/(-nt+Bt),vn=H*-nt;if(ne.matrixWorld.decompose(I.position,I.quaternion,I.scale),I.translateX(vn),I.translateZ(H),I.matrixWorld.compose(I.position,I.quaternion,I.scale),I.matrixWorldInverse.copy(I.matrixWorld).invert(),Ue[10]===-1)I.projectionMatrix.copy(ne.projectionMatrix),I.projectionMatrixInverse.copy(ne.projectionMatrixInverse);else{const yt=dt+H,qt=tt+H,Re=Ut-vn,on=mi+(_e-vn),R=gt*tt/qt*yt,T=At*tt/qt*yt;I.projectionMatrix.makePerspective(Re,on,R,T,yt,qt),I.projectionMatrixInverse.copy(I.projectionMatrix).invert()}}function Z(I,ne){ne===null?I.matrixWorld.copy(I.matrix):I.matrixWorld.multiplyMatrices(ne.matrixWorld,I.matrix),I.matrixWorldInverse.copy(I.matrixWorld).invert()}this.updateCamera=function(I){if(i===null)return;let ne=I.near,ue=I.far;m.texture!==null&&(m.depthNear>0&&(ne=m.depthNear),m.depthFar>0&&(ue=m.depthFar)),F.near=N.near=w.near=ne,F.far=N.far=w.far=ue,(V!==F.near||z!==F.far)&&(i.updateRenderState({depthNear:F.near,depthFar:F.far}),V=F.near,z=F.far),F.layers.mask=I.layers.mask|6,w.layers.mask=F.layers.mask&-5,N.layers.mask=F.layers.mask&-3;const _e=I.parent,Ue=F.cameras;Z(F,_e);for(let Ae=0;Ae<Ue.length;Ae++)Z(Ue[Ae],_e);Ue.length===2?fe(F,w,N):F.projectionMatrix.copy(w.projectionMatrix),oe(I,F,_e)};function oe(I,ne,ue){ue===null?I.matrix.copy(ne.matrixWorld):(I.matrix.copy(ue.matrixWorld),I.matrix.invert(),I.matrix.multiply(ne.matrixWorld)),I.matrix.decompose(I.position,I.quaternion,I.scale),I.updateMatrixWorld(!0),I.projectionMatrix.copy(ne.projectionMatrix),I.projectionMatrixInverse.copy(ne.projectionMatrixInverse),I.isPerspectiveCamera&&(I.fov=xo*2*Math.atan(1/I.projectionMatrix.elements[5]),I.zoom=1)}this.getCamera=function(){return F},this.getFoveation=function(){if(!(d===null&&f===null))return l},this.setFoveation=function(I){l=I,d!==null&&(d.fixedFoveation=I),f!==null&&f.fixedFoveation!==void 0&&(f.fixedFoveation=I)},this.hasDepthSensing=function(){return m.texture!==null},this.getDepthSensingMesh=function(){return m.getMesh(F)},this.getCameraTexture=function(I){return _[I]};let Ee=null;function ze(I,ne){if(u=ne.getViewerPose(c||o),p=ne,u!==null){const ue=u.views;f!==null&&(e.setRenderTargetFramebuffer(b,f.framebuffer),e.setRenderTarget(b));let _e=!1;ue.length!==F.cameras.length&&(F.cameras.length=0,_e=!0);for(let tt=0;tt<ue.length;tt++){const gt=ue[tt];let At=null;if(f!==null)At=f.getViewport(gt);else{const Bt=h.getViewSubImage(d,gt);At=Bt.viewport,tt===0&&(e.setRenderTargetTextures(b,Bt.colorTexture,Bt.depthStencilTexture),e.setRenderTarget(b))}let nt=C[tt];nt===void 0&&(nt=new Cn,nt.layers.enable(tt),nt.viewport=new rt,C[tt]=nt),nt.matrix.fromArray(gt.transform.matrix),nt.matrix.decompose(nt.position,nt.quaternion,nt.scale),nt.projectionMatrix.fromArray(gt.projectionMatrix),nt.projectionMatrixInverse.copy(nt.projectionMatrix).invert(),nt.viewport.set(At.x,At.y,At.width,At.height),tt===0&&(F.matrix.copy(nt.matrix),F.matrix.decompose(F.position,F.quaternion,F.scale)),_e===!0&&F.cameras.push(nt)}const Ue=i.enabledFeatures;if(Ue&&Ue.includes("depth-sensing")&&i.depthUsage=="gpu-optimized"&&g){h=n.getBinding();const tt=h.getDepthInformation(ue[0]);tt&&tt.isValid&&tt.texture&&m.init(tt,i.renderState)}if(Ue&&Ue.includes("camera-access")&&g){e.state.unbindTexture(),h=n.getBinding();for(let tt=0;tt<ue.length;tt++){const gt=ue[tt].camera;if(gt){let At=_[gt];At||(At=new ry,_[gt]=At);const nt=h.getCameraImage(gt);At.sourceTexture=nt}}}}for(let ue=0;ue<M.length;ue++){const _e=S[ue],Ue=M[ue];_e!==null&&Ue!==void 0&&Ue.update(_e,ne,c||o)}Ee&&Ee(I,ne),ne.detectedPlanes&&n.dispatchEvent({type:"planesdetected",data:ne}),p=null}const $=new xy;$.setAnimationLoop(ze),this.setAnimationLoop=function(I){Ee=I},this.dispose=function(){}}}const bC=new pt,Ey=new Je;Ey.set(-1,0,0,0,1,0,0,0,1);function SC(r,e){function t(m,_){m.matrixAutoUpdate===!0&&m.updateMatrix(),_.value.copy(m.matrix)}function n(m,_){_.color.getRGB(m.fogColor.value,ay(r)),_.isFog?(m.fogNear.value=_.near,m.fogFar.value=_.far):_.isFogExp2&&(m.fogDensity.value=_.density)}function i(m,_,x,y,b){_.isNodeMaterial?_.uniformsNeedUpdate=!1:_.isMeshBasicMaterial?s(m,_):_.isMeshLambertMaterial?(s(m,_),_.envMap&&(m.envMapIntensity.value=_.envMapIntensity)):_.isMeshToonMaterial?(s(m,_),h(m,_)):_.isMeshPhongMaterial?(s(m,_),u(m,_),_.envMap&&(m.envMapIntensity.value=_.envMapIntensity)):_.isMeshStandardMaterial?(s(m,_),d(m,_),_.isMeshPhysicalMaterial&&f(m,_,b)):_.isMeshMatcapMaterial?(s(m,_),p(m,_)):_.isMeshDepthMaterial?s(m,_):_.isMeshDistanceMaterial?(s(m,_),g(m,_)):_.isMeshNormalMaterial?s(m,_):_.isLineBasicMaterial?(o(m,_),_.isLineDashedMaterial&&a(m,_)):_.isPointsMaterial?l(m,_,x,y):_.isSpriteMaterial?c(m,_):_.isShadowMaterial?(m.color.value.copy(_.color),m.opacity.value=_.opacity):_.isShaderMaterial&&(_.uniformsNeedUpdate=!1)}function s(m,_){m.opacity.value=_.opacity,_.color&&m.diffuse.value.copy(_.color),_.emissive&&m.emissive.value.copy(_.emissive).multiplyScalar(_.emissiveIntensity),_.map&&(m.map.value=_.map,t(_.map,m.mapTransform)),_.alphaMap&&(m.alphaMap.value=_.alphaMap,t(_.alphaMap,m.alphaMapTransform)),_.bumpMap&&(m.bumpMap.value=_.bumpMap,t(_.bumpMap,m.bumpMapTransform),m.bumpScale.value=_.bumpScale,_.side===Lt&&(m.bumpScale.value*=-1)),_.normalMap&&(m.normalMap.value=_.normalMap,t(_.normalMap,m.normalMapTransform),m.normalScale.value.copy(_.normalScale),_.side===Lt&&m.normalScale.value.negate()),_.displacementMap&&(m.displacementMap.value=_.displacementMap,t(_.displacementMap,m.displacementMapTransform),m.displacementScale.value=_.displacementScale,m.displacementBias.value=_.displacementBias),_.emissiveMap&&(m.emissiveMap.value=_.emissiveMap,t(_.emissiveMap,m.emissiveMapTransform)),_.specularMap&&(m.specularMap.value=_.specularMap,t(_.specularMap,m.specularMapTransform)),_.alphaTest>0&&(m.alphaTest.value=_.alphaTest);const x=e.get(_),y=x.envMap,b=x.envMapRotation;y&&(m.envMap.value=y,m.envMapRotation.value.setFromMatrix4(bC.makeRotationFromEuler(b)).transpose(),y.isCubeTexture&&y.isRenderTargetTexture===!1&&m.envMapRotation.value.premultiply(Ey),m.reflectivity.value=_.reflectivity,m.ior.value=_.ior,m.refractionRatio.value=_.refractionRatio),_.lightMap&&(m.lightMap.value=_.lightMap,m.lightMapIntensity.value=_.lightMapIntensity,t(_.lightMap,m.lightMapTransform)),_.aoMap&&(m.aoMap.value=_.aoMap,m.aoMapIntensity.value=_.aoMapIntensity,t(_.aoMap,m.aoMapTransform))}function o(m,_){m.diffuse.value.copy(_.color),m.opacity.value=_.opacity,_.map&&(m.map.value=_.map,t(_.map,m.mapTransform))}function a(m,_){m.dashSize.value=_.dashSize,m.totalSize.value=_.dashSize+_.gapSize,m.scale.value=_.scale}function l(m,_,x,y){m.diffuse.value.copy(_.color),m.opacity.value=_.opacity,m.size.value=_.size*x,m.scale.value=y*.5,_.map&&(m.map.value=_.map,t(_.map,m.uvTransform)),_.alphaMap&&(m.alphaMap.value=_.alphaMap,t(_.alphaMap,m.alphaMapTransform)),_.alphaTest>0&&(m.alphaTest.value=_.alphaTest)}function c(m,_){m.diffuse.value.copy(_.color),m.opacity.value=_.opacity,m.rotation.value=_.rotation,_.map&&(m.map.value=_.map,t(_.map,m.mapTransform)),_.alphaMap&&(m.alphaMap.value=_.alphaMap,t(_.alphaMap,m.alphaMapTransform)),_.alphaTest>0&&(m.alphaTest.value=_.alphaTest)}function u(m,_){m.specular.value.copy(_.specular),m.shininess.value=Math.max(_.shininess,1e-4)}function h(m,_){_.gradientMap&&(m.gradientMap.value=_.gradientMap)}function d(m,_){m.metalness.value=_.metalness,_.metalnessMap&&(m.metalnessMap.value=_.metalnessMap,t(_.metalnessMap,m.metalnessMapTransform)),m.roughness.value=_.roughness,_.roughnessMap&&(m.roughnessMap.value=_.roughnessMap,t(_.roughnessMap,m.roughnessMapTransform)),_.envMap&&(m.envMapIntensity.value=_.envMapIntensity)}function f(m,_,x){m.ior.value=_.ior,_.sheen>0&&(m.sheenColor.value.copy(_.sheenColor).multiplyScalar(_.sheen),m.sheenRoughness.value=_.sheenRoughness,_.sheenColorMap&&(m.sheenColorMap.value=_.sheenColorMap,t(_.sheenColorMap,m.sheenColorMapTransform)),_.sheenRoughnessMap&&(m.sheenRoughnessMap.value=_.sheenRoughnessMap,t(_.sheenRoughnessMap,m.sheenRoughnessMapTransform))),_.clearcoat>0&&(m.clearcoat.value=_.clearcoat,m.clearcoatRoughness.value=_.clearcoatRoughness,_.clearcoatMap&&(m.clearcoatMap.value=_.clearcoatMap,t(_.clearcoatMap,m.clearcoatMapTransform)),_.clearcoatRoughnessMap&&(m.clearcoatRoughnessMap.value=_.clearcoatRoughnessMap,t(_.clearcoatRoughnessMap,m.clearcoatRoughnessMapTransform)),_.clearcoatNormalMap&&(m.clearcoatNormalMap.value=_.clearcoatNormalMap,t(_.clearcoatNormalMap,m.clearcoatNormalMapTransform),m.clearcoatNormalScale.value.copy(_.clearcoatNormalScale),_.side===Lt&&m.clearcoatNormalScale.value.negate())),_.dispersion>0&&(m.dispersion.value=_.dispersion),_.iridescence>0&&(m.iridescence.value=_.iridescence,m.iridescenceIOR.value=_.iridescenceIOR,m.iridescenceThicknessMinimum.value=_.iridescenceThicknessRange[0],m.iridescenceThicknessMaximum.value=_.iridescenceThicknessRange[1],_.iridescenceMap&&(m.iridescenceMap.value=_.iridescenceMap,t(_.iridescenceMap,m.iridescenceMapTransform)),_.iridescenceThicknessMap&&(m.iridescenceThicknessMap.value=_.iridescenceThicknessMap,t(_.iridescenceThicknessMap,m.iridescenceThicknessMapTransform))),_.transmission>0&&(m.transmission.value=_.transmission,m.transmissionSamplerMap.value=x.texture,m.transmissionSamplerSize.value.set(x.width,x.height),_.transmissionMap&&(m.transmissionMap.value=_.transmissionMap,t(_.transmissionMap,m.transmissionMapTransform)),m.thickness.value=_.thickness,_.thicknessMap&&(m.thicknessMap.value=_.thicknessMap,t(_.thicknessMap,m.thicknessMapTransform)),m.attenuationDistance.value=_.attenuationDistance,m.attenuationColor.value.copy(_.attenuationColor)),_.anisotropy>0&&(m.anisotropyVector.value.set(_.anisotropy*Math.cos(_.anisotropyRotation),_.anisotropy*Math.sin(_.anisotropyRotation)),_.anisotropyMap&&(m.anisotropyMap.value=_.anisotropyMap,t(_.anisotropyMap,m.anisotropyMapTransform))),m.specularIntensity.value=_.specularIntensity,m.specularColor.value.copy(_.specularColor),_.specularColorMap&&(m.specularColorMap.value=_.specularColorMap,t(_.specularColorMap,m.specularColorMapTransform)),_.specularIntensityMap&&(m.specularIntensityMap.value=_.specularIntensityMap,t(_.specularIntensityMap,m.specularIntensityMapTransform))}function p(m,_){_.matcap&&(m.matcap.value=_.matcap)}function g(m,_){const x=e.get(_).light;m.referencePosition.value.setFromMatrixPosition(x.matrixWorld),m.nearDistance.value=x.shadow.camera.near,m.farDistance.value=x.shadow.camera.far}return{refreshFogUniforms:n,refreshMaterialUniforms:i}}function TC(r,e,t,n){let i={},s={},o=[];const a=r.getParameter(r.MAX_UNIFORM_BUFFER_BINDINGS);function l(x,y){const b=y.program;n.uniformBlockBinding(x,b)}function c(x,y){let b=i[x.id];b===void 0&&(p(x),b=u(x),i[x.id]=b,x.addEventListener("dispose",m));const M=y.program;n.updateUBOMapping(x,M);const S=e.render.frame;s[x.id]!==S&&(d(x),s[x.id]=S)}function u(x){const y=h();x.__bindingPointIndex=y;const b=r.createBuffer(),M=x.__size,S=x.usage;return r.bindBuffer(r.UNIFORM_BUFFER,b),r.bufferData(r.UNIFORM_BUFFER,M,S),r.bindBuffer(r.UNIFORM_BUFFER,null),r.bindBufferBase(r.UNIFORM_BUFFER,y,b),b}function h(){for(let x=0;x<a;x++)if(o.indexOf(x)===-1)return o.push(x),x;return ce("WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}function d(x){const y=i[x.id],b=x.uniforms,M=x.__cache;r.bindBuffer(r.UNIFORM_BUFFER,y);for(let S=0,E=b.length;S<E;S++){const v=Array.isArray(b[S])?b[S]:[b[S]];for(let w=0,N=v.length;w<N;w++){const C=v[w];if(f(C,S,w,M)===!0){const F=C.__offset,V=Array.isArray(C.value)?C.value:[C.value];let z=0;for(let U=0;U<V.length;U++){const B=V[U],D=g(B);typeof B=="number"||typeof B=="boolean"?(C.__data[0]=B,r.bufferSubData(r.UNIFORM_BUFFER,F+z,C.__data)):B.isMatrix3?(C.__data[0]=B.elements[0],C.__data[1]=B.elements[1],C.__data[2]=B.elements[2],C.__data[3]=0,C.__data[4]=B.elements[3],C.__data[5]=B.elements[4],C.__data[6]=B.elements[5],C.__data[7]=0,C.__data[8]=B.elements[6],C.__data[9]=B.elements[7],C.__data[10]=B.elements[8],C.__data[11]=0):ArrayBuffer.isView(B)?C.__data.set(new B.constructor(B.buffer,B.byteOffset,C.__data.length)):(B.toArray(C.__data,z),z+=D.storage/Float32Array.BYTES_PER_ELEMENT)}r.bufferSubData(r.UNIFORM_BUFFER,F,C.__data)}}}r.bindBuffer(r.UNIFORM_BUFFER,null)}function f(x,y,b,M){const S=x.value,E=y+"_"+b;if(M[E]===void 0)return typeof S=="number"||typeof S=="boolean"?M[E]=S:ArrayBuffer.isView(S)?M[E]=S.slice():M[E]=S.clone(),!0;{const v=M[E];if(typeof S=="number"||typeof S=="boolean"){if(v!==S)return M[E]=S,!0}else{if(ArrayBuffer.isView(S))return!0;if(v.equals(S)===!1)return v.copy(S),!0}}return!1}function p(x){const y=x.uniforms;let b=0;const M=16;for(let E=0,v=y.length;E<v;E++){const w=Array.isArray(y[E])?y[E]:[y[E]];for(let N=0,C=w.length;N<C;N++){const F=w[N],V=Array.isArray(F.value)?F.value:[F.value];for(let z=0,U=V.length;z<U;z++){const B=V[z],D=g(B),X=b%M,K=X%D.boundary,fe=X+K;b+=K,fe!==0&&M-fe<D.storage&&(b+=M-fe),F.__data=new Float32Array(D.storage/Float32Array.BYTES_PER_ELEMENT),F.__offset=b,b+=D.storage}}}const S=b%M;return S>0&&(b+=M-S),x.__size=b,x.__cache={},this}function g(x){const y={boundary:0,storage:0};return typeof x=="number"||typeof x=="boolean"?(y.boundary=4,y.storage=4):x.isVector2?(y.boundary=8,y.storage=8):x.isVector3||x.isColor?(y.boundary=16,y.storage=12):x.isVector4?(y.boundary=16,y.storage=16):x.isMatrix3?(y.boundary=48,y.storage=48):x.isMatrix4?(y.boundary=64,y.storage=64):x.isTexture?ae("WebGLRenderer: Texture samplers can not be part of an uniforms group."):ArrayBuffer.isView(x)?(y.boundary=16,y.storage=x.byteLength):ae("WebGLRenderer: Unsupported uniform value type.",x),y}function m(x){const y=x.target;y.removeEventListener("dispose",m);const b=o.indexOf(y.__bindingPointIndex);o.splice(b,1),r.deleteBuffer(i[y.id]),delete i[y.id],delete s[y.id]}function _(){for(const x in i)r.deleteBuffer(i[x]);o=[],i={},s={}}return{bind:l,update:c,dispose:_}}const MC=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]);let nr=null;function EC(){return nr===null&&(nr=new gm(MC,16,16,In,tn),nr.name="DFG_LUT",nr.minFilter=Nt,nr.magFilter=Nt,nr.wrapS=ci,nr.wrapT=ci,nr.generateMipmaps=!1,nr.needsUpdate=!0),nr}class AC{constructor(e={}){const{canvas:t=K0(),context:n=null,depth:i=!0,stencil:s=!1,alpha:o=!1,antialias:a=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:c=!1,powerPreference:u="default",failIfMajorPerformanceCaveat:h=!1,reversedDepthBuffer:d=!1,outputBufferType:f=Xt}=e;this.isWebGLRenderer=!0;let p;if(n!==null){if(typeof WebGLRenderingContext<"u"&&n instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");p=n.getContextAttributes().alpha}else p=o;const g=f,m=new Set([rl,Ao,Eo]),_=new Set([Xt,Ct,Ui,di,Pc,Dc]),x=new Uint32Array(4),y=new Int32Array(4),b=new P;let M=null,S=null;const E=[],v=[];let w=null;this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=Fn,this.toneMappingExposure=1,this.transmissionResolutionScale=1;const N=this;let C=!1,F=null;this._outputColorSpace=ei;let V=0,z=0,U=null,B=-1,D=null;const X=new rt,K=new rt;let fe=null;const Z=new We(0);let oe=0,Ee=t.width,ze=t.height,$=1,I=null,ne=null;const ue=new rt(0,0,Ee,ze),_e=new rt(0,0,Ee,ze);let Ue=!1;const Ae=new Ic;let dt=!1,tt=!1;const gt=new pt,At=new P,nt=new rt,Bt={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let Ut=!1;function mi(){return U===null?$:1}let H=n;function vn(A,W){return t.getContext(A,W)}try{const A={alpha:!0,depth:i,stencil:s,antialias:a,premultipliedAlpha:l,preserveDrawingBuffer:c,powerPreference:u,failIfMajorPerformanceCaveat:h};if("setAttribute"in t&&t.setAttribute("data-engine",`three.js r${Mo}`),t.addEventListener("webglcontextlost",me,!1),t.addEventListener("webglcontextrestored",$e,!1),t.addEventListener("webglcontextcreationerror",ot,!1),H===null){const W="webgl2";if(H=vn(W,A),H===null)throw vn(W)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}}catch(A){throw ce("WebGLRenderer: "+A.message),A}let yt,qt,Re,on,R,T,q,he,ge,xe,Me,se,de,Le,Be,Se,ye,it,ut,Tt,O,ve,le;function Fe(){yt=new Ew(H),yt.init(),O=new gC(H,yt),qt=new _w(H,yt,e,O),Re=new pC(H,yt),qt.reversedDepthBuffer&&d&&Re.buffers.depth.setReversed(!0),on=new Rw(H),R=new eC,T=new mC(H,yt,Re,R,qt,O,on),q=new Mw(N),he=new DM(H),ve=new mw(H,he),ge=new Aw(H,he,on,ve),xe=new Nw(H,ge,he,ve,on),it=new Cw(H,qt,T),Be=new xw(R),Me=new JR(N,q,yt,qt,ve,Be),se=new SC(N,R),de=new nC,Le=new lC(yt),ye=new pw(N,q,Re,xe,p,l),Se=new fC(N,xe,qt),le=new TC(H,on,qt,Re),ut=new gw(H,yt,on),Tt=new ww(H,yt,on),on.programs=Me.programs,N.capabilities=qt,N.extensions=yt,N.properties=R,N.renderLists=de,N.shadowMap=Se,N.state=Re,N.info=on}Fe(),g!==Xt&&(w=new Dw(g,t.width,t.height,i,s));const Te=new vC(N,H);this.xr=Te,this.getContext=function(){return H},this.getContextAttributes=function(){return H.getContextAttributes()},this.forceContextLoss=function(){const A=yt.get("WEBGL_lose_context");A&&A.loseContext()},this.forceContextRestore=function(){const A=yt.get("WEBGL_lose_context");A&&A.restoreContext()},this.getPixelRatio=function(){return $},this.setPixelRatio=function(A){A!==void 0&&($=A,this.setSize(Ee,ze,!1))},this.getSize=function(A){return A.set(Ee,ze)},this.setSize=function(A,W,Q=!0){if(Te.isPresenting){ae("WebGLRenderer: Can't change size while VR device is presenting.");return}Ee=A,ze=W,t.width=Math.floor(A*$),t.height=Math.floor(W*$),Q===!0&&(t.style.width=A+"px",t.style.height=W+"px"),w!==null&&w.setSize(t.width,t.height),this.setViewport(0,0,A,W)},this.getDrawingBufferSize=function(A){return A.set(Ee*$,ze*$).floor()},this.setDrawingBufferSize=function(A,W,Q){Ee=A,ze=W,$=Q,t.width=Math.floor(A*Q),t.height=Math.floor(W*Q),this.setViewport(0,0,A,W)},this.setEffects=function(A){if(g===Xt){ce("THREE.WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.");return}if(A){for(let W=0;W<A.length;W++)if(A[W].isOutputPass===!0){ae("THREE.WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.");break}}w.setEffects(A||[])},this.getCurrentViewport=function(A){return A.copy(X)},this.getViewport=function(A){return A.copy(ue)},this.setViewport=function(A,W,Q,j){A.isVector4?ue.set(A.x,A.y,A.z,A.w):ue.set(A,W,Q,j),Re.viewport(X.copy(ue).multiplyScalar($).round())},this.getScissor=function(A){return A.copy(_e)},this.setScissor=function(A,W,Q,j){A.isVector4?_e.set(A.x,A.y,A.z,A.w):_e.set(A,W,Q,j),Re.scissor(K.copy(_e).multiplyScalar($).round())},this.getScissorTest=function(){return Ue},this.setScissorTest=function(A){Re.setScissorTest(Ue=A)},this.setOpaqueSort=function(A){I=A},this.setTransparentSort=function(A){ne=A},this.getClearColor=function(A){return A.copy(ye.getClearColor())},this.setClearColor=function(){ye.setClearColor(...arguments)},this.getClearAlpha=function(){return ye.getClearAlpha()},this.setClearAlpha=function(){ye.setClearAlpha(...arguments)},this.clear=function(A=!0,W=!0,Q=!0){let j=0;if(A){let Y=!1;if(U!==null){const De=U.texture.format;Y=m.has(De)}if(Y){const De=U.texture.type,Oe=_.has(De),Ne=ye.getClearColor(),He=ye.getClearAlpha(),Xe=Ne.r,at=Ne.g,ft=Ne.b;Oe?(x[0]=Xe,x[1]=at,x[2]=ft,x[3]=He,H.clearBufferuiv(H.COLOR,0,x)):(y[0]=Xe,y[1]=at,y[2]=ft,y[3]=He,H.clearBufferiv(H.COLOR,0,y))}else j|=H.COLOR_BUFFER_BIT}W&&(j|=H.DEPTH_BUFFER_BIT,this.state.buffers.depth.setMask(!0)),Q&&(j|=H.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),j!==0&&H.clear(j)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.setNodesHandler=function(A){A.setRenderer(this),F=A},this.dispose=function(){t.removeEventListener("webglcontextlost",me,!1),t.removeEventListener("webglcontextrestored",$e,!1),t.removeEventListener("webglcontextcreationerror",ot,!1),ye.dispose(),de.dispose(),Le.dispose(),R.dispose(),q.dispose(),xe.dispose(),ve.dispose(),le.dispose(),Me.dispose(),Te.dispose(),Te.removeEventListener("sessionstart",ug),Te.removeEventListener("sessionend",hg),Ws.stop()};function me(A){A.preventDefault(),Sc("WebGLRenderer: Context Lost."),C=!0}function $e(){Sc("WebGLRenderer: Context Restored."),C=!1;const A=on.autoReset,W=Se.enabled,Q=Se.autoUpdate,j=Se.needsUpdate,Y=Se.type;Fe(),on.autoReset=A,Se.enabled=W,Se.autoUpdate=Q,Se.needsUpdate=j,Se.type=Y}function ot(A){ce("WebGLRenderer: A WebGL context could not be created. Reason: ",A.statusMessage)}function cn(A){const W=A.target;W.removeEventListener("dispose",cn),Ot(W)}function Ot(A){Nr(A),R.remove(A)}function Nr(A){const W=R.get(A).programs;W!==void 0&&(W.forEach(function(Q){Me.releaseProgram(Q)}),A.isShaderMaterial&&Me.releaseShaderCache(A))}this.renderBufferDirect=function(A,W,Q,j,Y,De){W===null&&(W=Bt);const Oe=Y.isMesh&&Y.matrixWorld.determinant()<0,Ne=lS(A,W,Q,j,Y);Re.setMaterial(j,Oe);let He=Q.index,Xe=1;if(j.wireframe===!0){if(He=ge.getWireframeAttribute(Q),He===void 0)return;Xe=2}const at=Q.drawRange,ft=Q.attributes.position;let je=at.start*Xe,kt=(at.start+at.count)*Xe;De!==null&&(je=Math.max(je,De.start*Xe),kt=Math.min(kt,(De.start+De.count)*Xe)),He!==null?(je=Math.max(je,0),kt=Math.min(kt,He.count)):ft!=null&&(je=Math.max(je,0),kt=Math.min(kt,ft.count));const un=kt-je;if(un<0||un===1/0)return;ve.setup(Y,j,Ne,Q,He);let an,zt=ut;if(He!==null&&(an=he.get(He),zt=Tt,zt.setIndex(an)),Y.isMesh)j.wireframe===!0?(Re.setLineWidth(j.wireframeLinewidth*mi()),zt.setMode(H.LINES)):zt.setMode(H.TRIANGLES);else if(Y.isLine){let Gn=j.linewidth;Gn===void 0&&(Gn=1),Re.setLineWidth(Gn*mi()),Y.isLineSegments?zt.setMode(H.LINES):Y.isLineLoop?zt.setMode(H.LINE_LOOP):zt.setMode(H.LINE_STRIP)}else Y.isPoints?zt.setMode(H.POINTS):Y.isSprite&&zt.setMode(H.TRIANGLES);if(Y.isBatchedMesh)if(yt.get("WEBGL_multi_draw"))zt.renderMultiDraw(Y._multiDrawStarts,Y._multiDrawCounts,Y._multiDrawCount);else{const Gn=Y._multiDrawStarts,Ie=Y._multiDrawCounts,gi=Y._multiDrawCount,St=He?he.get(He).bytesPerElement:1,Ai=R.get(j).currentProgram.getUniforms();for(let Qi=0;Qi<gi;Qi++)Ai.setValue(H,"_gl_DrawID",Qi),zt.render(Gn[Qi]/St,Ie[Qi])}else if(Y.isInstancedMesh)zt.renderInstances(je,un,Y.count);else if(Q.isInstancedBufferGeometry){const Gn=Q._maxInstanceCount!==void 0?Q._maxInstanceCount:1/0,Ie=Math.min(Q.instanceCount,Gn);zt.renderInstances(je,un,Ie)}else zt.render(je,un)};function Zi(A,W,Q){A.transparent===!0&&A.side===Nn&&A.forceSinglePass===!1?(A.side=Lt,A.needsUpdate=!0,qc(A,W,Q),A.side=ri,A.needsUpdate=!0,qc(A,W,Q),A.side=Nn):qc(A,W,Q)}this.compile=function(A,W,Q=null){Q===null&&(Q=A),S=Le.get(Q),S.init(W),v.push(S),Q.traverseVisible(function(Y){Y.isLight&&Y.layers.test(W.layers)&&(S.pushLight(Y),Y.castShadow&&S.pushShadow(Y))}),A!==Q&&A.traverseVisible(function(Y){Y.isLight&&Y.layers.test(W.layers)&&(S.pushLight(Y),Y.castShadow&&S.pushShadow(Y))}),S.setupLights();const j=new Set;return A.traverse(function(Y){if(!(Y.isMesh||Y.isPoints||Y.isLine||Y.isSprite))return;const De=Y.material;if(De)if(Array.isArray(De))for(let Oe=0;Oe<De.length;Oe++){const Ne=De[Oe];Zi(Ne,Q,Y),j.add(Ne)}else Zi(De,Q,Y),j.add(De)}),S=v.pop(),j},this.compileAsync=function(A,W,Q=null){const j=this.compile(A,W,Q);return new Promise(Y=>{function De(){if(j.forEach(function(Oe){R.get(Oe).currentProgram.isReady()&&j.delete(Oe)}),j.size===0){Y(A);return}setTimeout(De,10)}yt.get("KHR_parallel_shader_compile")!==null?De():setTimeout(De,10)})};let od=null;function oS(A){od&&od(A)}function ug(){Ws.stop()}function hg(){Ws.start()}const Ws=new xy;Ws.setAnimationLoop(oS),typeof self<"u"&&Ws.setContext(self),this.setAnimationLoop=function(A){od=A,Te.setAnimationLoop(A),A===null?Ws.stop():Ws.start()},Te.addEventListener("sessionstart",ug),Te.addEventListener("sessionend",hg),this.render=function(A,W){if(W!==void 0&&W.isCamera!==!0){ce("WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(C===!0)return;F!==null&&F.renderStart(A,W);const Q=Te.enabled===!0&&Te.isPresenting===!0,j=w!==null&&(U===null||Q)&&w.begin(N,U);if(A.matrixWorldAutoUpdate===!0&&A.updateMatrixWorld(),W.parent===null&&W.matrixWorldAutoUpdate===!0&&W.updateMatrixWorld(),Te.enabled===!0&&Te.isPresenting===!0&&(w===null||w.isCompositing()===!1)&&(Te.cameraAutoUpdate===!0&&Te.updateCamera(W),W=Te.getCamera()),A.isScene===!0&&A.onBeforeRender(N,A,W,U),S=Le.get(A,v.length),S.init(W),S.state.textureUnits=T.getTextureUnits(),v.push(S),gt.multiplyMatrices(W.projectionMatrix,W.matrixWorldInverse),Ae.setFromProjectionMatrix(gt,ii,W.reversedDepth),tt=this.localClippingEnabled,dt=Be.init(this.clippingPlanes,tt),M=de.get(A,E.length),M.init(),E.push(M),Te.enabled===!0&&Te.isPresenting===!0){const Oe=N.xr.getDepthSensingMesh();Oe!==null&&ad(Oe,W,-1/0,N.sortObjects)}ad(A,W,0,N.sortObjects),M.finish(),N.sortObjects===!0&&M.sort(I,ne),Ut=Te.enabled===!1||Te.isPresenting===!1||Te.hasDepthSensing()===!1,Ut&&ye.addToRenderList(M,A),this.info.render.frame++,dt===!0&&Be.beginShadows();const Y=S.state.shadowsArray;if(Se.render(Y,A,W),dt===!0&&Be.endShadows(),this.info.autoReset===!0&&this.info.reset(),(j&&w.hasRenderPass())===!1){const Oe=M.opaque,Ne=M.transmissive;if(S.setupLights(),W.isArrayCamera){const He=W.cameras;if(Ne.length>0)for(let Xe=0,at=He.length;Xe<at;Xe++){const ft=He[Xe];fg(Oe,Ne,A,ft)}Ut&&ye.render(A);for(let Xe=0,at=He.length;Xe<at;Xe++){const ft=He[Xe];dg(M,A,ft,ft.viewport)}}else Ne.length>0&&fg(Oe,Ne,A,W),Ut&&ye.render(A),dg(M,A,W)}U!==null&&z===0&&(T.updateMultisampleRenderTarget(U),T.updateRenderTargetMipmap(U)),j&&w.end(N),A.isScene===!0&&A.onAfterRender(N,A,W),ve.resetDefaultState(),B=-1,D=null,v.pop(),v.length>0?(S=v[v.length-1],T.setTextureUnits(S.state.textureUnits),dt===!0&&Be.setGlobalState(N.clippingPlanes,S.state.camera)):S=null,E.pop(),E.length>0?M=E[E.length-1]:M=null,F!==null&&F.renderEnd()};function ad(A,W,Q,j){if(A.visible===!1)return;if(A.layers.test(W.layers)){if(A.isGroup)Q=A.renderOrder;else if(A.isLOD)A.autoUpdate===!0&&A.update(W);else if(A.isLightProbeGrid)S.pushLightProbeGrid(A);else if(A.isLight)S.pushLight(A),A.castShadow&&S.pushShadow(A);else if(A.isSprite){if(!A.frustumCulled||Ae.intersectsSprite(A)){j&&nt.setFromMatrixPosition(A.matrixWorld).applyMatrix4(gt);const Oe=xe.update(A),Ne=A.material;Ne.visible&&M.push(A,Oe,Ne,Q,nt.z,null)}}else if((A.isMesh||A.isLine||A.isPoints)&&(!A.frustumCulled||Ae.intersectsObject(A))){const Oe=xe.update(A),Ne=A.material;if(j&&(A.boundingSphere!==void 0?(A.boundingSphere===null&&A.computeBoundingSphere(),nt.copy(A.boundingSphere.center)):(Oe.boundingSphere===null&&Oe.computeBoundingSphere(),nt.copy(Oe.boundingSphere.center)),nt.applyMatrix4(A.matrixWorld).applyMatrix4(gt)),Array.isArray(Ne)){const He=Oe.groups;for(let Xe=0,at=He.length;Xe<at;Xe++){const ft=He[Xe],je=Ne[ft.materialIndex];je&&je.visible&&M.push(A,Oe,je,Q,nt.z,ft)}}else Ne.visible&&M.push(A,Oe,Ne,Q,nt.z,null)}}const De=A.children;for(let Oe=0,Ne=De.length;Oe<Ne;Oe++)ad(De[Oe],W,Q,j)}function dg(A,W,Q,j){const{opaque:Y,transmissive:De,transparent:Oe}=A;S.setupLightsView(Q),dt===!0&&Be.setGlobalState(N.clippingPlanes,Q),j&&Re.viewport(X.copy(j)),Y.length>0&&Xc(Y,W,Q),De.length>0&&Xc(De,W,Q),Oe.length>0&&Xc(Oe,W,Q),Re.buffers.depth.setTest(!0),Re.buffers.depth.setMask(!0),Re.buffers.color.setMask(!0),Re.setPolygonOffset(!1)}function fg(A,W,Q,j){if((Q.isScene===!0?Q.overrideMaterial:null)!==null)return;if(S.state.transmissionRenderTarget[j.id]===void 0){const je=yt.has("EXT_color_buffer_half_float")||yt.has("EXT_color_buffer_float");S.state.transmissionRenderTarget[j.id]=new Yi(1,1,{generateMipmaps:!0,type:je?tn:Xt,minFilter:ui,samples:Math.max(4,qt.samples),stencilBuffer:s,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:Ye.workingColorSpace})}const De=S.state.transmissionRenderTarget[j.id],Oe=j.viewport||X;De.setSize(Oe.z*N.transmissionResolutionScale,Oe.w*N.transmissionResolutionScale);const Ne=N.getRenderTarget(),He=N.getActiveCubeFace(),Xe=N.getActiveMipmapLevel();N.setRenderTarget(De),N.getClearColor(Z),oe=N.getClearAlpha(),oe<1&&N.setClearColor(16777215,.5),N.clear(),Ut&&ye.render(Q);const at=N.toneMapping;N.toneMapping=Fn;const ft=j.viewport;if(j.viewport!==void 0&&(j.viewport=void 0),S.setupLightsView(j),dt===!0&&Be.setGlobalState(N.clippingPlanes,j),Xc(A,Q,j),T.updateMultisampleRenderTarget(De),T.updateRenderTargetMipmap(De),yt.has("WEBGL_multisampled_render_to_texture")===!1){let je=!1;for(let kt=0,un=W.length;kt<un;kt++){const an=W[kt],{object:zt,geometry:Gn,material:Ie,group:gi}=an;if(Ie.side===Nn&&zt.layers.test(j.layers)){const St=Ie.side;Ie.side=Lt,Ie.needsUpdate=!0,pg(zt,Q,j,Gn,Ie,gi),Ie.side=St,Ie.needsUpdate=!0,je=!0}}je===!0&&(T.updateMultisampleRenderTarget(De),T.updateRenderTargetMipmap(De))}N.setRenderTarget(Ne,He,Xe),N.setClearColor(Z,oe),ft!==void 0&&(j.viewport=ft),N.toneMapping=at}function Xc(A,W,Q){const j=W.isScene===!0?W.overrideMaterial:null;for(let Y=0,De=A.length;Y<De;Y++){const Oe=A[Y],{object:Ne,geometry:He,group:Xe}=Oe;let at=Oe.material;at.allowOverride===!0&&j!==null&&(at=j),Ne.layers.test(Q.layers)&&pg(Ne,W,Q,He,at,Xe)}}function pg(A,W,Q,j,Y,De){A.onBeforeRender(N,W,Q,j,Y,De),A.modelViewMatrix.multiplyMatrices(Q.matrixWorldInverse,A.matrixWorld),A.normalMatrix.getNormalMatrix(A.modelViewMatrix),Y.onBeforeRender(N,W,Q,j,A,De),Y.transparent===!0&&Y.side===Nn&&Y.forceSinglePass===!1?(Y.side=Lt,Y.needsUpdate=!0,N.renderBufferDirect(Q,W,j,Y,A,De),Y.side=ri,Y.needsUpdate=!0,N.renderBufferDirect(Q,W,j,Y,A,De),Y.side=Nn):N.renderBufferDirect(Q,W,j,Y,A,De),A.onAfterRender(N,W,Q,j,Y,De)}function qc(A,W,Q){W.isScene!==!0&&(W=Bt);const j=R.get(A),Y=S.state.lights,De=S.state.shadowsArray,Oe=Y.state.version,Ne=Me.getParameters(A,Y.state,De,W,Q,S.state.lightProbeGridArray),He=Me.getProgramCacheKey(Ne);let Xe=j.programs;j.environment=A.isMeshStandardMaterial||A.isMeshLambertMaterial||A.isMeshPhongMaterial?W.environment:null,j.fog=W.fog;const at=A.isMeshStandardMaterial||A.isMeshLambertMaterial&&!A.envMap||A.isMeshPhongMaterial&&!A.envMap;j.envMap=q.get(A.envMap||j.environment,at),j.envMapRotation=j.environment!==null&&A.envMap===null?W.environmentRotation:A.envMapRotation,Xe===void 0&&(A.addEventListener("dispose",cn),Xe=new Map,j.programs=Xe);let ft=Xe.get(He);if(ft!==void 0){if(j.currentProgram===ft&&j.lightsStateVersion===Oe)return gg(A,Ne),ft}else Ne.uniforms=Me.getUniforms(A),F!==null&&A.isNodeMaterial&&F.build(A,Q,Ne),A.onBeforeCompile(Ne,N),ft=Me.acquireProgram(Ne,He),Xe.set(He,ft),j.uniforms=Ne.uniforms;const je=j.uniforms;return(!A.isShaderMaterial&&!A.isRawShaderMaterial||A.clipping===!0)&&(je.clippingPlanes=Be.uniform),gg(A,Ne),j.needsLights=uS(A),j.lightsStateVersion=Oe,j.needsLights&&(je.ambientLightColor.value=Y.state.ambient,je.lightProbe.value=Y.state.probe,je.directionalLights.value=Y.state.directional,je.directionalLightShadows.value=Y.state.directionalShadow,je.spotLights.value=Y.state.spot,je.spotLightShadows.value=Y.state.spotShadow,je.rectAreaLights.value=Y.state.rectArea,je.ltc_1.value=Y.state.rectAreaLTC1,je.ltc_2.value=Y.state.rectAreaLTC2,je.pointLights.value=Y.state.point,je.pointLightShadows.value=Y.state.pointShadow,je.hemisphereLights.value=Y.state.hemi,je.directionalShadowMatrix.value=Y.state.directionalShadowMatrix,je.spotLightMatrix.value=Y.state.spotLightMatrix,je.spotLightMap.value=Y.state.spotLightMap,je.pointShadowMatrix.value=Y.state.pointShadowMatrix),j.lightProbeGrid=S.state.lightProbeGridArray.length>0,j.currentProgram=ft,j.uniformsList=null,ft}function mg(A){if(A.uniformsList===null){const W=A.currentProgram.getUniforms();A.uniformsList=ah.seqWithValue(W.seq,A.uniforms)}return A.uniformsList}function gg(A,W){const Q=R.get(A);Q.outputColorSpace=W.outputColorSpace,Q.batching=W.batching,Q.batchingColor=W.batchingColor,Q.instancing=W.instancing,Q.instancingColor=W.instancingColor,Q.instancingMorph=W.instancingMorph,Q.skinning=W.skinning,Q.morphTargets=W.morphTargets,Q.morphNormals=W.morphNormals,Q.morphColors=W.morphColors,Q.morphTargetsCount=W.morphTargetsCount,Q.numClippingPlanes=W.numClippingPlanes,Q.numIntersection=W.numClipIntersection,Q.vertexAlphas=W.vertexAlphas,Q.vertexTangents=W.vertexTangents,Q.toneMapping=W.toneMapping}function aS(A,W){if(A.length===0)return null;if(A.length===1)return A[0].texture!==null?A[0]:null;b.setFromMatrixPosition(W.matrixWorld);for(let Q=0,j=A.length;Q<j;Q++){const Y=A[Q];if(Y.texture!==null&&Y.boundingBox.containsPoint(b))return Y}return null}function lS(A,W,Q,j,Y){W.isScene!==!0&&(W=Bt),T.resetTextureUnits();const De=W.fog,Oe=j.isMeshStandardMaterial||j.isMeshLambertMaterial||j.isMeshPhongMaterial?W.environment:null,Ne=U===null?N.outputColorSpace:U.isXRRenderTarget===!0?U.texture.colorSpace:Ye.workingColorSpace,He=j.isMeshStandardMaterial||j.isMeshLambertMaterial&&!j.envMap||j.isMeshPhongMaterial&&!j.envMap,Xe=q.get(j.envMap||Oe,He),at=j.vertexColors===!0&&!!Q.attributes.color&&Q.attributes.color.itemSize===4,ft=!!Q.attributes.tangent&&(!!j.normalMap||j.anisotropy>0),je=!!Q.morphAttributes.position,kt=!!Q.morphAttributes.normal,un=!!Q.morphAttributes.color;let an=Fn;j.toneMapped&&(U===null||U.isXRRenderTarget===!0)&&(an=N.toneMapping);const zt=Q.morphAttributes.position||Q.morphAttributes.normal||Q.morphAttributes.color,Gn=zt!==void 0?zt.length:0,Ie=R.get(j),gi=S.state.lights;if(dt===!0&&(tt===!0||A!==D)){const jt=A===D&&j.id===B;Be.setState(j,A,jt)}let St=!1;j.version===Ie.__version?(Ie.needsLights&&Ie.lightsStateVersion!==gi.state.version||Ie.outputColorSpace!==Ne||Y.isBatchedMesh&&Ie.batching===!1||!Y.isBatchedMesh&&Ie.batching===!0||Y.isBatchedMesh&&Ie.batchingColor===!0&&Y.colorTexture===null||Y.isBatchedMesh&&Ie.batchingColor===!1&&Y.colorTexture!==null||Y.isInstancedMesh&&Ie.instancing===!1||!Y.isInstancedMesh&&Ie.instancing===!0||Y.isSkinnedMesh&&Ie.skinning===!1||!Y.isSkinnedMesh&&Ie.skinning===!0||Y.isInstancedMesh&&Ie.instancingColor===!0&&Y.instanceColor===null||Y.isInstancedMesh&&Ie.instancingColor===!1&&Y.instanceColor!==null||Y.isInstancedMesh&&Ie.instancingMorph===!0&&Y.morphTexture===null||Y.isInstancedMesh&&Ie.instancingMorph===!1&&Y.morphTexture!==null||Ie.envMap!==Xe||j.fog===!0&&Ie.fog!==De||Ie.numClippingPlanes!==void 0&&(Ie.numClippingPlanes!==Be.numPlanes||Ie.numIntersection!==Be.numIntersection)||Ie.vertexAlphas!==at||Ie.vertexTangents!==ft||Ie.morphTargets!==je||Ie.morphNormals!==kt||Ie.morphColors!==un||Ie.toneMapping!==an||Ie.morphTargetsCount!==Gn||!!Ie.lightProbeGrid!=S.state.lightProbeGridArray.length>0)&&(St=!0):(St=!0,Ie.__version=j.version);let Ai=Ie.currentProgram;St===!0&&(Ai=qc(j,W,Y),F&&j.isNodeMaterial&&F.onUpdateProgram(j,Ai,Ie));let Qi=!1,ts=!1,Uo=!1;const Ht=Ai.getUniforms(),hn=Ie.uniforms;if(Re.useProgram(Ai.program)&&(Qi=!0,ts=!0,Uo=!0),j.id!==B&&(B=j.id,ts=!0),Ie.needsLights){const jt=aS(S.state.lightProbeGridArray,Y);Ie.lightProbeGrid!==jt&&(Ie.lightProbeGrid=jt,ts=!0)}if(Qi||D!==A){Re.buffers.depth.getReversed()&&A.reversedDepth!==!0&&(A._reversedDepth=!0,A.updateProjectionMatrix()),Ht.setValue(H,"projectionMatrix",A.projectionMatrix),Ht.setValue(H,"viewMatrix",A.matrixWorldInverse);const is=Ht.map.cameraPosition;is!==void 0&&is.setValue(H,At.setFromMatrixPosition(A.matrixWorld)),qt.logarithmicDepthBuffer&&Ht.setValue(H,"logDepthBufFC",2/(Math.log(A.far+1)/Math.LN2)),(j.isMeshPhongMaterial||j.isMeshToonMaterial||j.isMeshLambertMaterial||j.isMeshBasicMaterial||j.isMeshStandardMaterial||j.isShaderMaterial)&&Ht.setValue(H,"isOrthographic",A.isOrthographicCamera===!0),D!==A&&(D=A,ts=!0,Uo=!0)}if(Ie.needsLights&&(gi.state.directionalShadowMap.length>0&&Ht.setValue(H,"directionalShadowMap",gi.state.directionalShadowMap,T),gi.state.spotShadowMap.length>0&&Ht.setValue(H,"spotShadowMap",gi.state.spotShadowMap,T),gi.state.pointShadowMap.length>0&&Ht.setValue(H,"pointShadowMap",gi.state.pointShadowMap,T)),Y.isSkinnedMesh){Ht.setOptional(H,Y,"bindMatrix"),Ht.setOptional(H,Y,"bindMatrixInverse");const jt=Y.skeleton;jt&&(jt.boneTexture===null&&jt.computeBoneTexture(),Ht.setValue(H,"boneTexture",jt.boneTexture,T))}Y.isBatchedMesh&&(Ht.setOptional(H,Y,"batchingTexture"),Ht.setValue(H,"batchingTexture",Y._matricesTexture,T),Ht.setOptional(H,Y,"batchingIdTexture"),Ht.setValue(H,"batchingIdTexture",Y._indirectTexture,T),Ht.setOptional(H,Y,"batchingColorTexture"),Y._colorsTexture!==null&&Ht.setValue(H,"batchingColorTexture",Y._colorsTexture,T));const ns=Q.morphAttributes;if((ns.position!==void 0||ns.normal!==void 0||ns.color!==void 0)&&it.update(Y,Q,Ai),(ts||Ie.receiveShadow!==Y.receiveShadow)&&(Ie.receiveShadow=Y.receiveShadow,Ht.setValue(H,"receiveShadow",Y.receiveShadow)),(j.isMeshStandardMaterial||j.isMeshLambertMaterial||j.isMeshPhongMaterial)&&j.envMap===null&&W.environment!==null&&(hn.envMapIntensity.value=W.environmentIntensity),hn.dfgLUT!==void 0&&(hn.dfgLUT.value=EC()),ts){if(Ht.setValue(H,"toneMappingExposure",N.toneMappingExposure),Ie.needsLights&&cS(hn,Uo),De&&j.fog===!0&&se.refreshFogUniforms(hn,De),se.refreshMaterialUniforms(hn,j,$,ze,S.state.transmissionRenderTarget[A.id]),Ie.needsLights&&Ie.lightProbeGrid){const jt=Ie.lightProbeGrid;hn.probesSH.value=jt.texture,hn.probesMin.value.copy(jt.boundingBox.min),hn.probesMax.value.copy(jt.boundingBox.max),hn.probesResolution.value.copy(jt.resolution)}ah.upload(H,mg(Ie),hn,T)}if(j.isShaderMaterial&&j.uniformsNeedUpdate===!0&&(ah.upload(H,mg(Ie),hn,T),j.uniformsNeedUpdate=!1),j.isSpriteMaterial&&Ht.setValue(H,"center",Y.center),Ht.setValue(H,"modelViewMatrix",Y.modelViewMatrix),Ht.setValue(H,"normalMatrix",Y.normalMatrix),Ht.setValue(H,"modelMatrix",Y.matrixWorld),j.uniformsGroups!==void 0){const jt=j.uniformsGroups;for(let is=0,Fo=jt.length;is<Fo;is++){const _g=jt[is];le.update(_g,Ai),le.bind(_g,Ai)}}return Ai}function cS(A,W){A.ambientLightColor.needsUpdate=W,A.lightProbe.needsUpdate=W,A.directionalLights.needsUpdate=W,A.directionalLightShadows.needsUpdate=W,A.pointLights.needsUpdate=W,A.pointLightShadows.needsUpdate=W,A.spotLights.needsUpdate=W,A.spotLightShadows.needsUpdate=W,A.rectAreaLights.needsUpdate=W,A.hemisphereLights.needsUpdate=W}function uS(A){return A.isMeshLambertMaterial||A.isMeshToonMaterial||A.isMeshPhongMaterial||A.isMeshStandardMaterial||A.isShadowMaterial||A.isShaderMaterial&&A.lights===!0}this.getActiveCubeFace=function(){return V},this.getActiveMipmapLevel=function(){return z},this.getRenderTarget=function(){return U},this.setRenderTargetTextures=function(A,W,Q){const j=R.get(A);j.__autoAllocateDepthBuffer=A.resolveDepthBuffer===!1,j.__autoAllocateDepthBuffer===!1&&(j.__useRenderToTexture=!1),R.get(A.texture).__webglTexture=W,R.get(A.depthTexture).__webglTexture=j.__autoAllocateDepthBuffer?void 0:Q,j.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(A,W){const Q=R.get(A);Q.__webglFramebuffer=W,Q.__useDefaultFramebuffer=W===void 0};const hS=H.createFramebuffer();this.setRenderTarget=function(A,W=0,Q=0){U=A,V=W,z=Q;let j=null,Y=!1,De=!1;if(A){const Ne=R.get(A);if(Ne.__useDefaultFramebuffer!==void 0){Re.bindFramebuffer(H.FRAMEBUFFER,Ne.__webglFramebuffer),X.copy(A.viewport),K.copy(A.scissor),fe=A.scissorTest,Re.viewport(X),Re.scissor(K),Re.setScissorTest(fe),B=-1;return}else if(Ne.__webglFramebuffer===void 0)T.setupRenderTarget(A);else if(Ne.__hasExternalTextures)T.rebindTextures(A,R.get(A.texture).__webglTexture,R.get(A.depthTexture).__webglTexture);else if(A.depthBuffer){const at=A.depthTexture;if(Ne.__boundDepthTexture!==at){if(at!==null&&R.has(at)&&(A.width!==at.image.width||A.height!==at.image.height))throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");T.setupDepthRenderbuffer(A)}}const He=A.texture;(He.isData3DTexture||He.isDataArrayTexture||He.isCompressedArrayTexture)&&(De=!0);const Xe=R.get(A).__webglFramebuffer;A.isWebGLCubeRenderTarget?(Array.isArray(Xe[W])?j=Xe[W][Q]:j=Xe[W],Y=!0):A.samples>0&&T.useMultisampledRTT(A)===!1?j=R.get(A).__webglMultisampledFramebuffer:Array.isArray(Xe)?j=Xe[Q]:j=Xe,X.copy(A.viewport),K.copy(A.scissor),fe=A.scissorTest}else X.copy(ue).multiplyScalar($).floor(),K.copy(_e).multiplyScalar($).floor(),fe=Ue;if(Q!==0&&(j=hS),Re.bindFramebuffer(H.FRAMEBUFFER,j)&&Re.drawBuffers(A,j),Re.viewport(X),Re.scissor(K),Re.setScissorTest(fe),Y){const Ne=R.get(A.texture);H.framebufferTexture2D(H.FRAMEBUFFER,H.COLOR_ATTACHMENT0,H.TEXTURE_CUBE_MAP_POSITIVE_X+W,Ne.__webglTexture,Q)}else if(De){const Ne=W;for(let He=0;He<A.textures.length;He++){const Xe=R.get(A.textures[He]);H.framebufferTextureLayer(H.FRAMEBUFFER,H.COLOR_ATTACHMENT0+He,Xe.__webglTexture,Q,Ne)}}else if(A!==null&&Q!==0){const Ne=R.get(A.texture);H.framebufferTexture2D(H.FRAMEBUFFER,H.COLOR_ATTACHMENT0,H.TEXTURE_2D,Ne.__webglTexture,Q)}B=-1},this.readRenderTargetPixels=function(A,W,Q,j,Y,De,Oe,Ne=0){if(!(A&&A.isWebGLRenderTarget)){ce("WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let He=R.get(A).__webglFramebuffer;if(A.isWebGLCubeRenderTarget&&Oe!==void 0&&(He=He[Oe]),He){Re.bindFramebuffer(H.FRAMEBUFFER,He);try{const Xe=A.textures[Ne],at=Xe.format,ft=Xe.type;if(A.textures.length>1&&H.readBuffer(H.COLOR_ATTACHMENT0+Ne),!qt.textureFormatReadable(at)){ce("WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!qt.textureTypeReadable(ft)){ce("WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}W>=0&&W<=A.width-j&&Q>=0&&Q<=A.height-Y&&H.readPixels(W,Q,j,Y,O.convert(at),O.convert(ft),De)}finally{const Xe=U!==null?R.get(U).__webglFramebuffer:null;Re.bindFramebuffer(H.FRAMEBUFFER,Xe)}}},this.readRenderTargetPixelsAsync=async function(A,W,Q,j,Y,De,Oe,Ne=0){if(!(A&&A.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let He=R.get(A).__webglFramebuffer;if(A.isWebGLCubeRenderTarget&&Oe!==void 0&&(He=He[Oe]),He)if(W>=0&&W<=A.width-j&&Q>=0&&Q<=A.height-Y){Re.bindFramebuffer(H.FRAMEBUFFER,He);const Xe=A.textures[Ne],at=Xe.format,ft=Xe.type;if(A.textures.length>1&&H.readBuffer(H.COLOR_ATTACHMENT0+Ne),!qt.textureFormatReadable(at))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!qt.textureTypeReadable(ft))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");const je=H.createBuffer();H.bindBuffer(H.PIXEL_PACK_BUFFER,je),H.bufferData(H.PIXEL_PACK_BUFFER,De.byteLength,H.STREAM_READ),H.readPixels(W,Q,j,Y,O.convert(at),O.convert(ft),0);const kt=U!==null?R.get(U).__webglFramebuffer:null;Re.bindFramebuffer(H.FRAMEBUFFER,kt);const un=H.fenceSync(H.SYNC_GPU_COMMANDS_COMPLETE,0);return H.flush(),await eT(H,un,4),H.bindBuffer(H.PIXEL_PACK_BUFFER,je),H.getBufferSubData(H.PIXEL_PACK_BUFFER,0,De),H.deleteBuffer(je),H.deleteSync(un),De}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")},this.copyFramebufferToTexture=function(A,W=null,Q=0){const j=Math.pow(2,-Q),Y=Math.floor(A.image.width*j),De=Math.floor(A.image.height*j),Oe=W!==null?W.x:0,Ne=W!==null?W.y:0;T.setTexture2D(A,0),H.copyTexSubImage2D(H.TEXTURE_2D,Q,0,0,Oe,Ne,Y,De),Re.unbindTexture()};const dS=H.createFramebuffer(),fS=H.createFramebuffer();this.copyTextureToTexture=function(A,W,Q=null,j=null,Y=0,De=0){let Oe,Ne,He,Xe,at,ft,je,kt,un;const an=A.isCompressedTexture?A.mipmaps[De]:A.image;if(Q!==null)Oe=Q.max.x-Q.min.x,Ne=Q.max.y-Q.min.y,He=Q.isBox3?Q.max.z-Q.min.z:1,Xe=Q.min.x,at=Q.min.y,ft=Q.isBox3?Q.min.z:0;else{const hn=Math.pow(2,-Y);Oe=Math.floor(an.width*hn),Ne=Math.floor(an.height*hn),A.isDataArrayTexture?He=an.depth:A.isData3DTexture?He=Math.floor(an.depth*hn):He=1,Xe=0,at=0,ft=0}j!==null?(je=j.x,kt=j.y,un=j.z):(je=0,kt=0,un=0);const zt=O.convert(W.format),Gn=O.convert(W.type);let Ie;W.isData3DTexture?(T.setTexture3D(W,0),Ie=H.TEXTURE_3D):W.isDataArrayTexture||W.isCompressedArrayTexture?(T.setTexture2DArray(W,0),Ie=H.TEXTURE_2D_ARRAY):(T.setTexture2D(W,0),Ie=H.TEXTURE_2D),Re.activeTexture(H.TEXTURE0),Re.pixelStorei(H.UNPACK_FLIP_Y_WEBGL,W.flipY),Re.pixelStorei(H.UNPACK_PREMULTIPLY_ALPHA_WEBGL,W.premultiplyAlpha),Re.pixelStorei(H.UNPACK_ALIGNMENT,W.unpackAlignment);const gi=Re.getParameter(H.UNPACK_ROW_LENGTH),St=Re.getParameter(H.UNPACK_IMAGE_HEIGHT),Ai=Re.getParameter(H.UNPACK_SKIP_PIXELS),Qi=Re.getParameter(H.UNPACK_SKIP_ROWS),ts=Re.getParameter(H.UNPACK_SKIP_IMAGES);Re.pixelStorei(H.UNPACK_ROW_LENGTH,an.width),Re.pixelStorei(H.UNPACK_IMAGE_HEIGHT,an.height),Re.pixelStorei(H.UNPACK_SKIP_PIXELS,Xe),Re.pixelStorei(H.UNPACK_SKIP_ROWS,at),Re.pixelStorei(H.UNPACK_SKIP_IMAGES,ft);const Uo=A.isDataArrayTexture||A.isData3DTexture,Ht=W.isDataArrayTexture||W.isData3DTexture;if(A.isDepthTexture){const hn=R.get(A),ns=R.get(W),jt=R.get(hn.__renderTarget),is=R.get(ns.__renderTarget);Re.bindFramebuffer(H.READ_FRAMEBUFFER,jt.__webglFramebuffer),Re.bindFramebuffer(H.DRAW_FRAMEBUFFER,is.__webglFramebuffer);for(let Fo=0;Fo<He;Fo++)Uo&&(H.framebufferTextureLayer(H.READ_FRAMEBUFFER,H.COLOR_ATTACHMENT0,R.get(A).__webglTexture,Y,ft+Fo),H.framebufferTextureLayer(H.DRAW_FRAMEBUFFER,H.COLOR_ATTACHMENT0,R.get(W).__webglTexture,De,un+Fo)),H.blitFramebuffer(Xe,at,Oe,Ne,je,kt,Oe,Ne,H.DEPTH_BUFFER_BIT,H.NEAREST);Re.bindFramebuffer(H.READ_FRAMEBUFFER,null),Re.bindFramebuffer(H.DRAW_FRAMEBUFFER,null)}else if(Y!==0||A.isRenderTargetTexture||R.has(A)){const hn=R.get(A),ns=R.get(W);Re.bindFramebuffer(H.READ_FRAMEBUFFER,dS),Re.bindFramebuffer(H.DRAW_FRAMEBUFFER,fS);for(let jt=0;jt<He;jt++)Uo?H.framebufferTextureLayer(H.READ_FRAMEBUFFER,H.COLOR_ATTACHMENT0,hn.__webglTexture,Y,ft+jt):H.framebufferTexture2D(H.READ_FRAMEBUFFER,H.COLOR_ATTACHMENT0,H.TEXTURE_2D,hn.__webglTexture,Y),Ht?H.framebufferTextureLayer(H.DRAW_FRAMEBUFFER,H.COLOR_ATTACHMENT0,ns.__webglTexture,De,un+jt):H.framebufferTexture2D(H.DRAW_FRAMEBUFFER,H.COLOR_ATTACHMENT0,H.TEXTURE_2D,ns.__webglTexture,De),Y!==0?H.blitFramebuffer(Xe,at,Oe,Ne,je,kt,Oe,Ne,H.COLOR_BUFFER_BIT,H.NEAREST):Ht?H.copyTexSubImage3D(Ie,De,je,kt,un+jt,Xe,at,Oe,Ne):H.copyTexSubImage2D(Ie,De,je,kt,Xe,at,Oe,Ne);Re.bindFramebuffer(H.READ_FRAMEBUFFER,null),Re.bindFramebuffer(H.DRAW_FRAMEBUFFER,null)}else Ht?A.isDataTexture||A.isData3DTexture?H.texSubImage3D(Ie,De,je,kt,un,Oe,Ne,He,zt,Gn,an.data):W.isCompressedArrayTexture?H.compressedTexSubImage3D(Ie,De,je,kt,un,Oe,Ne,He,zt,an.data):H.texSubImage3D(Ie,De,je,kt,un,Oe,Ne,He,zt,Gn,an):A.isDataTexture?H.texSubImage2D(H.TEXTURE_2D,De,je,kt,Oe,Ne,zt,Gn,an.data):A.isCompressedTexture?H.compressedTexSubImage2D(H.TEXTURE_2D,De,je,kt,an.width,an.height,zt,an.data):H.texSubImage2D(H.TEXTURE_2D,De,je,kt,Oe,Ne,zt,Gn,an);Re.pixelStorei(H.UNPACK_ROW_LENGTH,gi),Re.pixelStorei(H.UNPACK_IMAGE_HEIGHT,St),Re.pixelStorei(H.UNPACK_SKIP_PIXELS,Ai),Re.pixelStorei(H.UNPACK_SKIP_ROWS,Qi),Re.pixelStorei(H.UNPACK_SKIP_IMAGES,ts),De===0&&W.generateMipmaps&&H.generateMipmap(Ie),Re.unbindTexture()},this.initRenderTarget=function(A){R.get(A).__webglFramebuffer===void 0&&T.setupRenderTarget(A)},this.initTexture=function(A){A.isCubeTexture?T.setTextureCube(A,0):A.isData3DTexture?T.setTexture3D(A,0):A.isDataArrayTexture||A.isCompressedArrayTexture?T.setTexture2DArray(A,0):T.setTexture2D(A,0),Re.unbindTexture()},this.resetState=function(){V=0,z=0,U=null,Re.reset(),ve.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return ii}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;const t=this.getContext();t.drawingBufferColorSpace=Ye._getDrawingBufferColorSpace(e),t.unpackColorSpace=Ye._getUnpackColorSpace()}}const xa=new ur,zr=new pe,Ay=new P,Hd=new pe,lh=new pe,bh=new P,ap=new P,wy=new pt,Ry=new P,Cy=new P;let $n=null,lr=null;const Hr=[],Cs={NONE:-1,PAN:0,ROTATE:1};class wC extends kh{constructor(e,t,n=null){super(t,n),this.objects=e,this.recursive=!0,this.transformGroup=!1,this.rotateSpeed=1,this.raycaster=new _y,this.mouseButtons={LEFT:Un.PAN,MIDDLE:Un.PAN,RIGHT:Un.ROTATE},this.touches={ONE:$r.PAN},this._onPointerMove=RC.bind(this),this._onPointerDown=CC.bind(this),this._onPointerCancel=NC.bind(this),this._onContextMenu=PC.bind(this),n!==null&&this.connect(n)}connect(e){super.connect(e),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointerup",this._onPointerCancel),this.domElement.addEventListener("pointerleave",this._onPointerCancel),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointerup",this._onPointerCancel),this.domElement.removeEventListener("pointerleave",this._onPointerCancel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="",this.domElement.style.cursor=""}dispose(){this.disconnect()}_updatePointer(e){const t=this.domElement.getBoundingClientRect();zr.x=(e.clientX-t.left)/t.width*2-1,zr.y=-(e.clientY-t.top)/t.height*2+1}_updateState(e){let t;if(e.pointerType==="touch")t=this.touches.ONE;else switch(e.button){case 0:t=this.mouseButtons.LEFT;break;case 1:t=this.mouseButtons.MIDDLE;break;case 2:t=this.mouseButtons.RIGHT;break;default:t=null}switch(t){case Un.PAN:case $r.PAN:this.state=Cs.PAN;break;case Un.ROTATE:case $r.ROTATE:this.state=Cs.ROTATE;break;default:this.state=Cs.NONE}}}function RC(r){const e=this.object,t=this.domElement,n=this.raycaster;if(this.enabled!==!1){if(this._updatePointer(r),n.setFromCamera(zr,e),$n)this.state===Cs.PAN?n.ray.intersectPlane(xa,bh)&&($n.position.copy(bh.sub(Ay).applyMatrix4(wy)),this.dispatchEvent({type:"drag",object:$n})):this.state===Cs.ROTATE&&(Hd.subVectors(zr,lh).multiplyScalar(this.rotateSpeed),$n.rotateOnWorldAxis(Ry,Hd.x),$n.rotateOnWorldAxis(Cy.normalize(),-Hd.y),this.dispatchEvent({type:"drag",object:$n})),lh.copy(zr);else if(r.pointerType==="mouse"||r.pointerType==="pen")if(Hr.length=0,n.setFromCamera(zr,e),n.intersectObjects(this.objects,this.recursive,Hr),Hr.length>0){const i=Hr[0].object;xa.setFromNormalAndCoplanarPoint(e.getWorldDirection(xa.normal),ap.setFromMatrixPosition(i.matrixWorld)),lr!==i&&lr!==null&&(this.dispatchEvent({type:"hoveroff",object:lr}),t.style.cursor="auto",lr=null),lr!==i&&(this.dispatchEvent({type:"hoveron",object:i}),t.style.cursor="pointer",lr=i)}else lr!==null&&(this.dispatchEvent({type:"hoveroff",object:lr}),t.style.cursor="auto",lr=null);lh.copy(zr)}}function CC(r){const e=this.object,t=this.domElement,n=this.raycaster;this.enabled!==!1&&(this._updatePointer(r),this._updateState(r),Hr.length=0,n.setFromCamera(zr,e),n.intersectObjects(this.objects,this.recursive,Hr),Hr.length>0&&(this.transformGroup===!0?$n=Ny(Hr[0].object):$n=Hr[0].object,xa.setFromNormalAndCoplanarPoint(e.getWorldDirection(xa.normal),ap.setFromMatrixPosition($n.matrixWorld)),n.ray.intersectPlane(xa,bh)&&(this.state===Cs.PAN?(wy.copy($n.parent.matrixWorld).invert(),Ay.copy(bh).sub(ap.setFromMatrixPosition($n.matrixWorld)),t.style.cursor="move",this.dispatchEvent({type:"dragstart",object:$n})):this.state===Cs.ROTATE&&(Ry.set(0,1,0).applyQuaternion(e.quaternion).normalize(),Cy.set(1,0,0).applyQuaternion(e.quaternion).normalize(),t.style.cursor="move",this.dispatchEvent({type:"dragstart",object:$n})))),lh.copy(zr))}function NC(){this.enabled!==!1&&($n&&(this.dispatchEvent({type:"dragend",object:$n}),$n=null),this.domElement.style.cursor=lr?"pointer":"auto",this.state=Cs.NONE)}function PC(r){this.enabled!==!1&&r.preventDefault()}function Ny(r,e=null){return r.isGroup&&(e=r),r.parent===null?e:Ny(r.parent,e)}function DC(r){UC(r);const e=LC(r);return r.on=e.on,r.off=e.off,r.fire=e.fire,r}function LC(r){let e=Object.create(null);return{on:function(t,n,i){if(typeof n!="function")throw new Error("callback is expected to be a function");let s=e[t];return s||(s=e[t]=[]),s.push({callback:n,ctx:i}),r},off:function(t,n){if(typeof t>"u")return e=Object.create(null),r;if(e[t])if(typeof n!="function")delete e[t];else{const o=e[t];for(let a=0;a<o.length;++a)o[a].callback===n&&o.splice(a,1)}return r},fire:function(t){const n=e[t];if(!n)return r;let i;arguments.length>1&&(i=Array.prototype.slice.call(arguments,1));for(let s=0;s<n.length;++s){const o=n[s];o.callback.apply(o.ctx,i)}return r}}}function UC(r){if(!r)throw new Error("Eventify cannot use falsy object as events subject");const e=["on","fire","off"];for(let t=0;t<e.length;++t)if(r.hasOwnProperty(e[t]))throw new Error("Subject cannot be eventified, since it already has property '"+e[t]+"'")}function FC(r){if(r=r||{},"uniqueLinkId"in r&&(console.warn("ngraph.graph: Starting from version 0.14 `uniqueLinkId` is deprecated.\nUse `multigraph` option instead\n",`
4112
+ }`;class yC{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){const n=new ry(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=n}}getMesh(e){if(this.texture!==null&&this.mesh===null){const t=e.cameras[0].viewport,n=new ki({vertexShader:_C,fragmentShader:xC,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new _n(new Oc(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class vC extends Vi{constructor(e,t){super();const n=this;let i=null,s=1,o=null,a="local-floor",l=1,c=null,u=null,h=null,d=null,f=null,p=null;const g=typeof XRWebGLBinding<"u",m=new yC,_={},x=t.getContextAttributes();let y=null,b=null;const M=[],S=[],E=new pe;let v=null;const w=new Cn;w.viewport=new rt;const N=new Cn;N.viewport=new rt;const C=[w,N],F=new my;let V=null,z=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(I){let ne=M[I];return ne===void 0&&(ne=new oh,M[I]=ne),ne.getTargetRaySpace()},this.getControllerGrip=function(I){let ne=M[I];return ne===void 0&&(ne=new oh,M[I]=ne),ne.getGripSpace()},this.getHand=function(I){let ne=M[I];return ne===void 0&&(ne=new oh,M[I]=ne),ne.getHandSpace()};function U(I){const ne=S.indexOf(I.inputSource);if(ne===-1)return;const ue=M[ne];ue!==void 0&&(ue.update(I.inputSource,I.frame,c||o),ue.dispatchEvent({type:I.type,data:I.inputSource}))}function B(){i.removeEventListener("select",U),i.removeEventListener("selectstart",U),i.removeEventListener("selectend",U),i.removeEventListener("squeeze",U),i.removeEventListener("squeezestart",U),i.removeEventListener("squeezeend",U),i.removeEventListener("end",B),i.removeEventListener("inputsourceschange",D);for(let I=0;I<M.length;I++){const ne=S[I];ne!==null&&(S[I]=null,M[I].disconnect(ne))}V=null,z=null,m.reset();for(const I in _)delete _[I];e.setRenderTarget(y),f=null,d=null,h=null,i=null,b=null,$.stop(),n.isPresenting=!1,e.setPixelRatio(v),e.setSize(E.width,E.height,!1),n.dispatchEvent({type:"sessionend"})}this.setFramebufferScaleFactor=function(I){s=I,n.isPresenting===!0&&ae("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(I){a=I,n.isPresenting===!0&&ae("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return c||o},this.setReferenceSpace=function(I){c=I},this.getBaseLayer=function(){return d!==null?d:f},this.getBinding=function(){return h===null&&g&&(h=new XRWebGLBinding(i,t)),h},this.getFrame=function(){return p},this.getSession=function(){return i},this.setSession=async function(I){if(i=I,i!==null){if(y=e.getRenderTarget(),i.addEventListener("select",U),i.addEventListener("selectstart",U),i.addEventListener("selectend",U),i.addEventListener("squeeze",U),i.addEventListener("squeezestart",U),i.addEventListener("squeezeend",U),i.addEventListener("end",B),i.addEventListener("inputsourceschange",D),x.xrCompatible!==!0&&await t.makeXRCompatible(),v=e.getPixelRatio(),e.getSize(E),g&&"createProjectionLayer"in XRWebGLBinding.prototype){let ue=null,_e=null,Ue=null;x.depth&&(Ue=x.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,ue=x.stencil?qn:Dn,_e=x.stencil?di:Ct);const Ae={colorFormat:t.RGBA8,depthFormat:Ue,scaleFactor:s};h=this.getBinding(),d=h.createProjectionLayer(Ae),i.updateRenderState({layers:[d]}),e.setPixelRatio(1),e.setSize(d.textureWidth,d.textureHeight,!1),b=new Yi(d.textureWidth,d.textureHeight,{format:ln,type:Xt,depthTexture:new jn(d.textureWidth,d.textureHeight,_e,void 0,void 0,void 0,void 0,void 0,void 0,ue),stencilBuffer:x.stencil,colorSpace:e.outputColorSpace,samples:x.antialias?4:0,resolveDepthBuffer:d.ignoreDepthValues===!1,resolveStencilBuffer:d.ignoreDepthValues===!1})}else{const ue={antialias:x.antialias,alpha:!0,depth:x.depth,stencil:x.stencil,framebufferScaleFactor:s};f=new XRWebGLLayer(i,t,ue),i.updateRenderState({baseLayer:f}),e.setPixelRatio(1),e.setSize(f.framebufferWidth,f.framebufferHeight,!1),b=new Yi(f.framebufferWidth,f.framebufferHeight,{format:ln,type:Xt,colorSpace:e.outputColorSpace,stencilBuffer:x.stencil,resolveDepthBuffer:f.ignoreDepthValues===!1,resolveStencilBuffer:f.ignoreDepthValues===!1})}b.isXRRenderTarget=!0,this.setFoveation(l),c=null,o=await i.requestReferenceSpace(a),$.setContext(i),$.start(),n.isPresenting=!0,n.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(i!==null)return i.environmentBlendMode},this.getDepthTexture=function(){return m.getDepthTexture()};function D(I){for(let ne=0;ne<I.removed.length;ne++){const ue=I.removed[ne],_e=S.indexOf(ue);_e>=0&&(S[_e]=null,M[_e].disconnect(ue))}for(let ne=0;ne<I.added.length;ne++){const ue=I.added[ne];let _e=S.indexOf(ue);if(_e===-1){for(let Ae=0;Ae<M.length;Ae++)if(Ae>=S.length){S.push(ue),_e=Ae;break}else if(S[Ae]===null){S[Ae]=ue,_e=Ae;break}if(_e===-1)break}const Ue=M[_e];Ue&&Ue.connect(ue)}}const X=new P,K=new P;function fe(I,ne,ue){X.setFromMatrixPosition(ne.matrixWorld),K.setFromMatrixPosition(ue.matrixWorld);const _e=X.distanceTo(K),Ue=ne.projectionMatrix.elements,Ae=ue.projectionMatrix.elements,dt=Ue[14]/(Ue[10]-1),tt=Ue[14]/(Ue[10]+1),gt=(Ue[9]+1)/Ue[5],At=(Ue[9]-1)/Ue[5],nt=(Ue[8]-1)/Ue[0],Bt=(Ae[8]+1)/Ae[0],Ut=dt*nt,pi=dt*Bt,H=_e/(-nt+Bt),vn=H*-nt;if(ne.matrixWorld.decompose(I.position,I.quaternion,I.scale),I.translateX(vn),I.translateZ(H),I.matrixWorld.compose(I.position,I.quaternion,I.scale),I.matrixWorldInverse.copy(I.matrixWorld).invert(),Ue[10]===-1)I.projectionMatrix.copy(ne.projectionMatrix),I.projectionMatrixInverse.copy(ne.projectionMatrixInverse);else{const yt=dt+H,qt=tt+H,Re=Ut-vn,on=pi+(_e-vn),R=gt*tt/qt*yt,T=At*tt/qt*yt;I.projectionMatrix.makePerspective(Re,on,R,T,yt,qt),I.projectionMatrixInverse.copy(I.projectionMatrix).invert()}}function Z(I,ne){ne===null?I.matrixWorld.copy(I.matrix):I.matrixWorld.multiplyMatrices(ne.matrixWorld,I.matrix),I.matrixWorldInverse.copy(I.matrixWorld).invert()}this.updateCamera=function(I){if(i===null)return;let ne=I.near,ue=I.far;m.texture!==null&&(m.depthNear>0&&(ne=m.depthNear),m.depthFar>0&&(ue=m.depthFar)),F.near=N.near=w.near=ne,F.far=N.far=w.far=ue,(V!==F.near||z!==F.far)&&(i.updateRenderState({depthNear:F.near,depthFar:F.far}),V=F.near,z=F.far),F.layers.mask=I.layers.mask|6,w.layers.mask=F.layers.mask&-5,N.layers.mask=F.layers.mask&-3;const _e=I.parent,Ue=F.cameras;Z(F,_e);for(let Ae=0;Ae<Ue.length;Ae++)Z(Ue[Ae],_e);Ue.length===2?fe(F,w,N):F.projectionMatrix.copy(w.projectionMatrix),oe(I,F,_e)};function oe(I,ne,ue){ue===null?I.matrix.copy(ne.matrixWorld):(I.matrix.copy(ue.matrixWorld),I.matrix.invert(),I.matrix.multiply(ne.matrixWorld)),I.matrix.decompose(I.position,I.quaternion,I.scale),I.updateMatrixWorld(!0),I.projectionMatrix.copy(ne.projectionMatrix),I.projectionMatrixInverse.copy(ne.projectionMatrixInverse),I.isPerspectiveCamera&&(I.fov=xo*2*Math.atan(1/I.projectionMatrix.elements[5]),I.zoom=1)}this.getCamera=function(){return F},this.getFoveation=function(){if(!(d===null&&f===null))return l},this.setFoveation=function(I){l=I,d!==null&&(d.fixedFoveation=I),f!==null&&f.fixedFoveation!==void 0&&(f.fixedFoveation=I)},this.hasDepthSensing=function(){return m.texture!==null},this.getDepthSensingMesh=function(){return m.getMesh(F)},this.getCameraTexture=function(I){return _[I]};let Ee=null;function ze(I,ne){if(u=ne.getViewerPose(c||o),p=ne,u!==null){const ue=u.views;f!==null&&(e.setRenderTargetFramebuffer(b,f.framebuffer),e.setRenderTarget(b));let _e=!1;ue.length!==F.cameras.length&&(F.cameras.length=0,_e=!0);for(let tt=0;tt<ue.length;tt++){const gt=ue[tt];let At=null;if(f!==null)At=f.getViewport(gt);else{const Bt=h.getViewSubImage(d,gt);At=Bt.viewport,tt===0&&(e.setRenderTargetTextures(b,Bt.colorTexture,Bt.depthStencilTexture),e.setRenderTarget(b))}let nt=C[tt];nt===void 0&&(nt=new Cn,nt.layers.enable(tt),nt.viewport=new rt,C[tt]=nt),nt.matrix.fromArray(gt.transform.matrix),nt.matrix.decompose(nt.position,nt.quaternion,nt.scale),nt.projectionMatrix.fromArray(gt.projectionMatrix),nt.projectionMatrixInverse.copy(nt.projectionMatrix).invert(),nt.viewport.set(At.x,At.y,At.width,At.height),tt===0&&(F.matrix.copy(nt.matrix),F.matrix.decompose(F.position,F.quaternion,F.scale)),_e===!0&&F.cameras.push(nt)}const Ue=i.enabledFeatures;if(Ue&&Ue.includes("depth-sensing")&&i.depthUsage=="gpu-optimized"&&g){h=n.getBinding();const tt=h.getDepthInformation(ue[0]);tt&&tt.isValid&&tt.texture&&m.init(tt,i.renderState)}if(Ue&&Ue.includes("camera-access")&&g){e.state.unbindTexture(),h=n.getBinding();for(let tt=0;tt<ue.length;tt++){const gt=ue[tt].camera;if(gt){let At=_[gt];At||(At=new ry,_[gt]=At);const nt=h.getCameraImage(gt);At.sourceTexture=nt}}}}for(let ue=0;ue<M.length;ue++){const _e=S[ue],Ue=M[ue];_e!==null&&Ue!==void 0&&Ue.update(_e,ne,c||o)}Ee&&Ee(I,ne),ne.detectedPlanes&&n.dispatchEvent({type:"planesdetected",data:ne}),p=null}const $=new xy;$.setAnimationLoop(ze),this.setAnimationLoop=function(I){Ee=I},this.dispose=function(){}}}const bC=new pt,Ey=new Je;Ey.set(-1,0,0,0,1,0,0,0,1);function SC(r,e){function t(m,_){m.matrixAutoUpdate===!0&&m.updateMatrix(),_.value.copy(m.matrix)}function n(m,_){_.color.getRGB(m.fogColor.value,ay(r)),_.isFog?(m.fogNear.value=_.near,m.fogFar.value=_.far):_.isFogExp2&&(m.fogDensity.value=_.density)}function i(m,_,x,y,b){_.isNodeMaterial?_.uniformsNeedUpdate=!1:_.isMeshBasicMaterial?s(m,_):_.isMeshLambertMaterial?(s(m,_),_.envMap&&(m.envMapIntensity.value=_.envMapIntensity)):_.isMeshToonMaterial?(s(m,_),h(m,_)):_.isMeshPhongMaterial?(s(m,_),u(m,_),_.envMap&&(m.envMapIntensity.value=_.envMapIntensity)):_.isMeshStandardMaterial?(s(m,_),d(m,_),_.isMeshPhysicalMaterial&&f(m,_,b)):_.isMeshMatcapMaterial?(s(m,_),p(m,_)):_.isMeshDepthMaterial?s(m,_):_.isMeshDistanceMaterial?(s(m,_),g(m,_)):_.isMeshNormalMaterial?s(m,_):_.isLineBasicMaterial?(o(m,_),_.isLineDashedMaterial&&a(m,_)):_.isPointsMaterial?l(m,_,x,y):_.isSpriteMaterial?c(m,_):_.isShadowMaterial?(m.color.value.copy(_.color),m.opacity.value=_.opacity):_.isShaderMaterial&&(_.uniformsNeedUpdate=!1)}function s(m,_){m.opacity.value=_.opacity,_.color&&m.diffuse.value.copy(_.color),_.emissive&&m.emissive.value.copy(_.emissive).multiplyScalar(_.emissiveIntensity),_.map&&(m.map.value=_.map,t(_.map,m.mapTransform)),_.alphaMap&&(m.alphaMap.value=_.alphaMap,t(_.alphaMap,m.alphaMapTransform)),_.bumpMap&&(m.bumpMap.value=_.bumpMap,t(_.bumpMap,m.bumpMapTransform),m.bumpScale.value=_.bumpScale,_.side===Lt&&(m.bumpScale.value*=-1)),_.normalMap&&(m.normalMap.value=_.normalMap,t(_.normalMap,m.normalMapTransform),m.normalScale.value.copy(_.normalScale),_.side===Lt&&m.normalScale.value.negate()),_.displacementMap&&(m.displacementMap.value=_.displacementMap,t(_.displacementMap,m.displacementMapTransform),m.displacementScale.value=_.displacementScale,m.displacementBias.value=_.displacementBias),_.emissiveMap&&(m.emissiveMap.value=_.emissiveMap,t(_.emissiveMap,m.emissiveMapTransform)),_.specularMap&&(m.specularMap.value=_.specularMap,t(_.specularMap,m.specularMapTransform)),_.alphaTest>0&&(m.alphaTest.value=_.alphaTest);const x=e.get(_),y=x.envMap,b=x.envMapRotation;y&&(m.envMap.value=y,m.envMapRotation.value.setFromMatrix4(bC.makeRotationFromEuler(b)).transpose(),y.isCubeTexture&&y.isRenderTargetTexture===!1&&m.envMapRotation.value.premultiply(Ey),m.reflectivity.value=_.reflectivity,m.ior.value=_.ior,m.refractionRatio.value=_.refractionRatio),_.lightMap&&(m.lightMap.value=_.lightMap,m.lightMapIntensity.value=_.lightMapIntensity,t(_.lightMap,m.lightMapTransform)),_.aoMap&&(m.aoMap.value=_.aoMap,m.aoMapIntensity.value=_.aoMapIntensity,t(_.aoMap,m.aoMapTransform))}function o(m,_){m.diffuse.value.copy(_.color),m.opacity.value=_.opacity,_.map&&(m.map.value=_.map,t(_.map,m.mapTransform))}function a(m,_){m.dashSize.value=_.dashSize,m.totalSize.value=_.dashSize+_.gapSize,m.scale.value=_.scale}function l(m,_,x,y){m.diffuse.value.copy(_.color),m.opacity.value=_.opacity,m.size.value=_.size*x,m.scale.value=y*.5,_.map&&(m.map.value=_.map,t(_.map,m.uvTransform)),_.alphaMap&&(m.alphaMap.value=_.alphaMap,t(_.alphaMap,m.alphaMapTransform)),_.alphaTest>0&&(m.alphaTest.value=_.alphaTest)}function c(m,_){m.diffuse.value.copy(_.color),m.opacity.value=_.opacity,m.rotation.value=_.rotation,_.map&&(m.map.value=_.map,t(_.map,m.mapTransform)),_.alphaMap&&(m.alphaMap.value=_.alphaMap,t(_.alphaMap,m.alphaMapTransform)),_.alphaTest>0&&(m.alphaTest.value=_.alphaTest)}function u(m,_){m.specular.value.copy(_.specular),m.shininess.value=Math.max(_.shininess,1e-4)}function h(m,_){_.gradientMap&&(m.gradientMap.value=_.gradientMap)}function d(m,_){m.metalness.value=_.metalness,_.metalnessMap&&(m.metalnessMap.value=_.metalnessMap,t(_.metalnessMap,m.metalnessMapTransform)),m.roughness.value=_.roughness,_.roughnessMap&&(m.roughnessMap.value=_.roughnessMap,t(_.roughnessMap,m.roughnessMapTransform)),_.envMap&&(m.envMapIntensity.value=_.envMapIntensity)}function f(m,_,x){m.ior.value=_.ior,_.sheen>0&&(m.sheenColor.value.copy(_.sheenColor).multiplyScalar(_.sheen),m.sheenRoughness.value=_.sheenRoughness,_.sheenColorMap&&(m.sheenColorMap.value=_.sheenColorMap,t(_.sheenColorMap,m.sheenColorMapTransform)),_.sheenRoughnessMap&&(m.sheenRoughnessMap.value=_.sheenRoughnessMap,t(_.sheenRoughnessMap,m.sheenRoughnessMapTransform))),_.clearcoat>0&&(m.clearcoat.value=_.clearcoat,m.clearcoatRoughness.value=_.clearcoatRoughness,_.clearcoatMap&&(m.clearcoatMap.value=_.clearcoatMap,t(_.clearcoatMap,m.clearcoatMapTransform)),_.clearcoatRoughnessMap&&(m.clearcoatRoughnessMap.value=_.clearcoatRoughnessMap,t(_.clearcoatRoughnessMap,m.clearcoatRoughnessMapTransform)),_.clearcoatNormalMap&&(m.clearcoatNormalMap.value=_.clearcoatNormalMap,t(_.clearcoatNormalMap,m.clearcoatNormalMapTransform),m.clearcoatNormalScale.value.copy(_.clearcoatNormalScale),_.side===Lt&&m.clearcoatNormalScale.value.negate())),_.dispersion>0&&(m.dispersion.value=_.dispersion),_.iridescence>0&&(m.iridescence.value=_.iridescence,m.iridescenceIOR.value=_.iridescenceIOR,m.iridescenceThicknessMinimum.value=_.iridescenceThicknessRange[0],m.iridescenceThicknessMaximum.value=_.iridescenceThicknessRange[1],_.iridescenceMap&&(m.iridescenceMap.value=_.iridescenceMap,t(_.iridescenceMap,m.iridescenceMapTransform)),_.iridescenceThicknessMap&&(m.iridescenceThicknessMap.value=_.iridescenceThicknessMap,t(_.iridescenceThicknessMap,m.iridescenceThicknessMapTransform))),_.transmission>0&&(m.transmission.value=_.transmission,m.transmissionSamplerMap.value=x.texture,m.transmissionSamplerSize.value.set(x.width,x.height),_.transmissionMap&&(m.transmissionMap.value=_.transmissionMap,t(_.transmissionMap,m.transmissionMapTransform)),m.thickness.value=_.thickness,_.thicknessMap&&(m.thicknessMap.value=_.thicknessMap,t(_.thicknessMap,m.thicknessMapTransform)),m.attenuationDistance.value=_.attenuationDistance,m.attenuationColor.value.copy(_.attenuationColor)),_.anisotropy>0&&(m.anisotropyVector.value.set(_.anisotropy*Math.cos(_.anisotropyRotation),_.anisotropy*Math.sin(_.anisotropyRotation)),_.anisotropyMap&&(m.anisotropyMap.value=_.anisotropyMap,t(_.anisotropyMap,m.anisotropyMapTransform))),m.specularIntensity.value=_.specularIntensity,m.specularColor.value.copy(_.specularColor),_.specularColorMap&&(m.specularColorMap.value=_.specularColorMap,t(_.specularColorMap,m.specularColorMapTransform)),_.specularIntensityMap&&(m.specularIntensityMap.value=_.specularIntensityMap,t(_.specularIntensityMap,m.specularIntensityMapTransform))}function p(m,_){_.matcap&&(m.matcap.value=_.matcap)}function g(m,_){const x=e.get(_).light;m.referencePosition.value.setFromMatrixPosition(x.matrixWorld),m.nearDistance.value=x.shadow.camera.near,m.farDistance.value=x.shadow.camera.far}return{refreshFogUniforms:n,refreshMaterialUniforms:i}}function TC(r,e,t,n){let i={},s={},o=[];const a=r.getParameter(r.MAX_UNIFORM_BUFFER_BINDINGS);function l(x,y){const b=y.program;n.uniformBlockBinding(x,b)}function c(x,y){let b=i[x.id];b===void 0&&(p(x),b=u(x),i[x.id]=b,x.addEventListener("dispose",m));const M=y.program;n.updateUBOMapping(x,M);const S=e.render.frame;s[x.id]!==S&&(d(x),s[x.id]=S)}function u(x){const y=h();x.__bindingPointIndex=y;const b=r.createBuffer(),M=x.__size,S=x.usage;return r.bindBuffer(r.UNIFORM_BUFFER,b),r.bufferData(r.UNIFORM_BUFFER,M,S),r.bindBuffer(r.UNIFORM_BUFFER,null),r.bindBufferBase(r.UNIFORM_BUFFER,y,b),b}function h(){for(let x=0;x<a;x++)if(o.indexOf(x)===-1)return o.push(x),x;return ce("WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}function d(x){const y=i[x.id],b=x.uniforms,M=x.__cache;r.bindBuffer(r.UNIFORM_BUFFER,y);for(let S=0,E=b.length;S<E;S++){const v=Array.isArray(b[S])?b[S]:[b[S]];for(let w=0,N=v.length;w<N;w++){const C=v[w];if(f(C,S,w,M)===!0){const F=C.__offset,V=Array.isArray(C.value)?C.value:[C.value];let z=0;for(let U=0;U<V.length;U++){const B=V[U],D=g(B);typeof B=="number"||typeof B=="boolean"?(C.__data[0]=B,r.bufferSubData(r.UNIFORM_BUFFER,F+z,C.__data)):B.isMatrix3?(C.__data[0]=B.elements[0],C.__data[1]=B.elements[1],C.__data[2]=B.elements[2],C.__data[3]=0,C.__data[4]=B.elements[3],C.__data[5]=B.elements[4],C.__data[6]=B.elements[5],C.__data[7]=0,C.__data[8]=B.elements[6],C.__data[9]=B.elements[7],C.__data[10]=B.elements[8],C.__data[11]=0):ArrayBuffer.isView(B)?C.__data.set(new B.constructor(B.buffer,B.byteOffset,C.__data.length)):(B.toArray(C.__data,z),z+=D.storage/Float32Array.BYTES_PER_ELEMENT)}r.bufferSubData(r.UNIFORM_BUFFER,F,C.__data)}}}r.bindBuffer(r.UNIFORM_BUFFER,null)}function f(x,y,b,M){const S=x.value,E=y+"_"+b;if(M[E]===void 0)return typeof S=="number"||typeof S=="boolean"?M[E]=S:ArrayBuffer.isView(S)?M[E]=S.slice():M[E]=S.clone(),!0;{const v=M[E];if(typeof S=="number"||typeof S=="boolean"){if(v!==S)return M[E]=S,!0}else{if(ArrayBuffer.isView(S))return!0;if(v.equals(S)===!1)return v.copy(S),!0}}return!1}function p(x){const y=x.uniforms;let b=0;const M=16;for(let E=0,v=y.length;E<v;E++){const w=Array.isArray(y[E])?y[E]:[y[E]];for(let N=0,C=w.length;N<C;N++){const F=w[N],V=Array.isArray(F.value)?F.value:[F.value];for(let z=0,U=V.length;z<U;z++){const B=V[z],D=g(B),X=b%M,K=X%D.boundary,fe=X+K;b+=K,fe!==0&&M-fe<D.storage&&(b+=M-fe),F.__data=new Float32Array(D.storage/Float32Array.BYTES_PER_ELEMENT),F.__offset=b,b+=D.storage}}}const S=b%M;return S>0&&(b+=M-S),x.__size=b,x.__cache={},this}function g(x){const y={boundary:0,storage:0};return typeof x=="number"||typeof x=="boolean"?(y.boundary=4,y.storage=4):x.isVector2?(y.boundary=8,y.storage=8):x.isVector3||x.isColor?(y.boundary=16,y.storage=12):x.isVector4?(y.boundary=16,y.storage=16):x.isMatrix3?(y.boundary=48,y.storage=48):x.isMatrix4?(y.boundary=64,y.storage=64):x.isTexture?ae("WebGLRenderer: Texture samplers can not be part of an uniforms group."):ArrayBuffer.isView(x)?(y.boundary=16,y.storage=x.byteLength):ae("WebGLRenderer: Unsupported uniform value type.",x),y}function m(x){const y=x.target;y.removeEventListener("dispose",m);const b=o.indexOf(y.__bindingPointIndex);o.splice(b,1),r.deleteBuffer(i[y.id]),delete i[y.id],delete s[y.id]}function _(){for(const x in i)r.deleteBuffer(i[x]);o=[],i={},s={}}return{bind:l,update:c,dispose:_}}const MC=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]);let nr=null;function EC(){return nr===null&&(nr=new gm(MC,16,16,In,tn),nr.name="DFG_LUT",nr.minFilter=Nt,nr.magFilter=Nt,nr.wrapS=ci,nr.wrapT=ci,nr.generateMipmaps=!1,nr.needsUpdate=!0),nr}class AC{constructor(e={}){const{canvas:t=K0(),context:n=null,depth:i=!0,stencil:s=!1,alpha:o=!1,antialias:a=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:c=!1,powerPreference:u="default",failIfMajorPerformanceCaveat:h=!1,reversedDepthBuffer:d=!1,outputBufferType:f=Xt}=e;this.isWebGLRenderer=!0;let p;if(n!==null){if(typeof WebGLRenderingContext<"u"&&n instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");p=n.getContextAttributes().alpha}else p=o;const g=f,m=new Set([rl,Ao,Eo]),_=new Set([Xt,Ct,Li,di,Pc,Dc]),x=new Uint32Array(4),y=new Int32Array(4),b=new P;let M=null,S=null;const E=[],v=[];let w=null;this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=Fn,this.toneMappingExposure=1,this.transmissionResolutionScale=1;const N=this;let C=!1,F=null;this._outputColorSpace=ei;let V=0,z=0,U=null,B=-1,D=null;const X=new rt,K=new rt;let fe=null;const Z=new We(0);let oe=0,Ee=t.width,ze=t.height,$=1,I=null,ne=null;const ue=new rt(0,0,Ee,ze),_e=new rt(0,0,Ee,ze);let Ue=!1;const Ae=new Ic;let dt=!1,tt=!1;const gt=new pt,At=new P,nt=new rt,Bt={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let Ut=!1;function pi(){return U===null?$:1}let H=n;function vn(A,W){return t.getContext(A,W)}try{const A={alpha:!0,depth:i,stencil:s,antialias:a,premultipliedAlpha:l,preserveDrawingBuffer:c,powerPreference:u,failIfMajorPerformanceCaveat:h};if("setAttribute"in t&&t.setAttribute("data-engine",`three.js r${Mo}`),t.addEventListener("webglcontextlost",me,!1),t.addEventListener("webglcontextrestored",$e,!1),t.addEventListener("webglcontextcreationerror",ot,!1),H===null){const W="webgl2";if(H=vn(W,A),H===null)throw vn(W)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}}catch(A){throw ce("WebGLRenderer: "+A.message),A}let yt,qt,Re,on,R,T,q,he,ge,xe,Me,se,de,Le,Be,Se,ye,it,ut,Tt,O,ve,le;function Fe(){yt=new Ew(H),yt.init(),O=new gC(H,yt),qt=new _w(H,yt,e,O),Re=new pC(H,yt),qt.reversedDepthBuffer&&d&&Re.buffers.depth.setReversed(!0),on=new Rw(H),R=new eC,T=new mC(H,yt,Re,R,qt,O,on),q=new Mw(N),he=new DM(H),ve=new mw(H,he),ge=new Aw(H,he,on,ve),xe=new Nw(H,ge,he,ve,on),it=new Cw(H,qt,T),Be=new xw(R),Me=new JR(N,q,yt,qt,ve,Be),se=new SC(N,R),de=new nC,Le=new lC(yt),ye=new pw(N,q,Re,xe,p,l),Se=new fC(N,xe,qt),le=new TC(H,on,qt,Re),ut=new gw(H,yt,on),Tt=new ww(H,yt,on),on.programs=Me.programs,N.capabilities=qt,N.extensions=yt,N.properties=R,N.renderLists=de,N.shadowMap=Se,N.state=Re,N.info=on}Fe(),g!==Xt&&(w=new Dw(g,t.width,t.height,i,s));const Te=new vC(N,H);this.xr=Te,this.getContext=function(){return H},this.getContextAttributes=function(){return H.getContextAttributes()},this.forceContextLoss=function(){const A=yt.get("WEBGL_lose_context");A&&A.loseContext()},this.forceContextRestore=function(){const A=yt.get("WEBGL_lose_context");A&&A.restoreContext()},this.getPixelRatio=function(){return $},this.setPixelRatio=function(A){A!==void 0&&($=A,this.setSize(Ee,ze,!1))},this.getSize=function(A){return A.set(Ee,ze)},this.setSize=function(A,W,Q=!0){if(Te.isPresenting){ae("WebGLRenderer: Can't change size while VR device is presenting.");return}Ee=A,ze=W,t.width=Math.floor(A*$),t.height=Math.floor(W*$),Q===!0&&(t.style.width=A+"px",t.style.height=W+"px"),w!==null&&w.setSize(t.width,t.height),this.setViewport(0,0,A,W)},this.getDrawingBufferSize=function(A){return A.set(Ee*$,ze*$).floor()},this.setDrawingBufferSize=function(A,W,Q){Ee=A,ze=W,$=Q,t.width=Math.floor(A*Q),t.height=Math.floor(W*Q),this.setViewport(0,0,A,W)},this.setEffects=function(A){if(g===Xt){ce("THREE.WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.");return}if(A){for(let W=0;W<A.length;W++)if(A[W].isOutputPass===!0){ae("THREE.WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.");break}}w.setEffects(A||[])},this.getCurrentViewport=function(A){return A.copy(X)},this.getViewport=function(A){return A.copy(ue)},this.setViewport=function(A,W,Q,j){A.isVector4?ue.set(A.x,A.y,A.z,A.w):ue.set(A,W,Q,j),Re.viewport(X.copy(ue).multiplyScalar($).round())},this.getScissor=function(A){return A.copy(_e)},this.setScissor=function(A,W,Q,j){A.isVector4?_e.set(A.x,A.y,A.z,A.w):_e.set(A,W,Q,j),Re.scissor(K.copy(_e).multiplyScalar($).round())},this.getScissorTest=function(){return Ue},this.setScissorTest=function(A){Re.setScissorTest(Ue=A)},this.setOpaqueSort=function(A){I=A},this.setTransparentSort=function(A){ne=A},this.getClearColor=function(A){return A.copy(ye.getClearColor())},this.setClearColor=function(){ye.setClearColor(...arguments)},this.getClearAlpha=function(){return ye.getClearAlpha()},this.setClearAlpha=function(){ye.setClearAlpha(...arguments)},this.clear=function(A=!0,W=!0,Q=!0){let j=0;if(A){let Y=!1;if(U!==null){const De=U.texture.format;Y=m.has(De)}if(Y){const De=U.texture.type,Oe=_.has(De),Ne=ye.getClearColor(),He=ye.getClearAlpha(),Xe=Ne.r,at=Ne.g,ft=Ne.b;Oe?(x[0]=Xe,x[1]=at,x[2]=ft,x[3]=He,H.clearBufferuiv(H.COLOR,0,x)):(y[0]=Xe,y[1]=at,y[2]=ft,y[3]=He,H.clearBufferiv(H.COLOR,0,y))}else j|=H.COLOR_BUFFER_BIT}W&&(j|=H.DEPTH_BUFFER_BIT,this.state.buffers.depth.setMask(!0)),Q&&(j|=H.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),j!==0&&H.clear(j)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.setNodesHandler=function(A){A.setRenderer(this),F=A},this.dispose=function(){t.removeEventListener("webglcontextlost",me,!1),t.removeEventListener("webglcontextrestored",$e,!1),t.removeEventListener("webglcontextcreationerror",ot,!1),ye.dispose(),de.dispose(),Le.dispose(),R.dispose(),q.dispose(),xe.dispose(),ve.dispose(),le.dispose(),Me.dispose(),Te.dispose(),Te.removeEventListener("sessionstart",ug),Te.removeEventListener("sessionend",hg),Ws.stop()};function me(A){A.preventDefault(),Sc("WebGLRenderer: Context Lost."),C=!0}function $e(){Sc("WebGLRenderer: Context Restored."),C=!1;const A=on.autoReset,W=Se.enabled,Q=Se.autoUpdate,j=Se.needsUpdate,Y=Se.type;Fe(),on.autoReset=A,Se.enabled=W,Se.autoUpdate=Q,Se.needsUpdate=j,Se.type=Y}function ot(A){ce("WebGLRenderer: A WebGL context could not be created. Reason: ",A.statusMessage)}function cn(A){const W=A.target;W.removeEventListener("dispose",cn),Ot(W)}function Ot(A){Nr(A),R.remove(A)}function Nr(A){const W=R.get(A).programs;W!==void 0&&(W.forEach(function(Q){Me.releaseProgram(Q)}),A.isShaderMaterial&&Me.releaseShaderCache(A))}this.renderBufferDirect=function(A,W,Q,j,Y,De){W===null&&(W=Bt);const Oe=Y.isMesh&&Y.matrixWorld.determinant()<0,Ne=lS(A,W,Q,j,Y);Re.setMaterial(j,Oe);let He=Q.index,Xe=1;if(j.wireframe===!0){if(He=ge.getWireframeAttribute(Q),He===void 0)return;Xe=2}const at=Q.drawRange,ft=Q.attributes.position;let je=at.start*Xe,kt=(at.start+at.count)*Xe;De!==null&&(je=Math.max(je,De.start*Xe),kt=Math.min(kt,(De.start+De.count)*Xe)),He!==null?(je=Math.max(je,0),kt=Math.min(kt,He.count)):ft!=null&&(je=Math.max(je,0),kt=Math.min(kt,ft.count));const un=kt-je;if(un<0||un===1/0)return;ve.setup(Y,j,Ne,Q,He);let an,zt=ut;if(He!==null&&(an=he.get(He),zt=Tt,zt.setIndex(an)),Y.isMesh)j.wireframe===!0?(Re.setLineWidth(j.wireframeLinewidth*pi()),zt.setMode(H.LINES)):zt.setMode(H.TRIANGLES);else if(Y.isLine){let Gn=j.linewidth;Gn===void 0&&(Gn=1),Re.setLineWidth(Gn*pi()),Y.isLineSegments?zt.setMode(H.LINES):Y.isLineLoop?zt.setMode(H.LINE_LOOP):zt.setMode(H.LINE_STRIP)}else Y.isPoints?zt.setMode(H.POINTS):Y.isSprite&&zt.setMode(H.TRIANGLES);if(Y.isBatchedMesh)if(yt.get("WEBGL_multi_draw"))zt.renderMultiDraw(Y._multiDrawStarts,Y._multiDrawCounts,Y._multiDrawCount);else{const Gn=Y._multiDrawStarts,Ie=Y._multiDrawCounts,mi=Y._multiDrawCount,St=He?he.get(He).bytesPerElement:1,Ei=R.get(j).currentProgram.getUniforms();for(let Qi=0;Qi<mi;Qi++)Ei.setValue(H,"_gl_DrawID",Qi),zt.render(Gn[Qi]/St,Ie[Qi])}else if(Y.isInstancedMesh)zt.renderInstances(je,un,Y.count);else if(Q.isInstancedBufferGeometry){const Gn=Q._maxInstanceCount!==void 0?Q._maxInstanceCount:1/0,Ie=Math.min(Q.instanceCount,Gn);zt.renderInstances(je,un,Ie)}else zt.render(je,un)};function Zi(A,W,Q){A.transparent===!0&&A.side===Nn&&A.forceSinglePass===!1?(A.side=Lt,A.needsUpdate=!0,qc(A,W,Q),A.side=ri,A.needsUpdate=!0,qc(A,W,Q),A.side=Nn):qc(A,W,Q)}this.compile=function(A,W,Q=null){Q===null&&(Q=A),S=Le.get(Q),S.init(W),v.push(S),Q.traverseVisible(function(Y){Y.isLight&&Y.layers.test(W.layers)&&(S.pushLight(Y),Y.castShadow&&S.pushShadow(Y))}),A!==Q&&A.traverseVisible(function(Y){Y.isLight&&Y.layers.test(W.layers)&&(S.pushLight(Y),Y.castShadow&&S.pushShadow(Y))}),S.setupLights();const j=new Set;return A.traverse(function(Y){if(!(Y.isMesh||Y.isPoints||Y.isLine||Y.isSprite))return;const De=Y.material;if(De)if(Array.isArray(De))for(let Oe=0;Oe<De.length;Oe++){const Ne=De[Oe];Zi(Ne,Q,Y),j.add(Ne)}else Zi(De,Q,Y),j.add(De)}),S=v.pop(),j},this.compileAsync=function(A,W,Q=null){const j=this.compile(A,W,Q);return new Promise(Y=>{function De(){if(j.forEach(function(Oe){R.get(Oe).currentProgram.isReady()&&j.delete(Oe)}),j.size===0){Y(A);return}setTimeout(De,10)}yt.get("KHR_parallel_shader_compile")!==null?De():setTimeout(De,10)})};let od=null;function oS(A){od&&od(A)}function ug(){Ws.stop()}function hg(){Ws.start()}const Ws=new xy;Ws.setAnimationLoop(oS),typeof self<"u"&&Ws.setContext(self),this.setAnimationLoop=function(A){od=A,Te.setAnimationLoop(A),A===null?Ws.stop():Ws.start()},Te.addEventListener("sessionstart",ug),Te.addEventListener("sessionend",hg),this.render=function(A,W){if(W!==void 0&&W.isCamera!==!0){ce("WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(C===!0)return;F!==null&&F.renderStart(A,W);const Q=Te.enabled===!0&&Te.isPresenting===!0,j=w!==null&&(U===null||Q)&&w.begin(N,U);if(A.matrixWorldAutoUpdate===!0&&A.updateMatrixWorld(),W.parent===null&&W.matrixWorldAutoUpdate===!0&&W.updateMatrixWorld(),Te.enabled===!0&&Te.isPresenting===!0&&(w===null||w.isCompositing()===!1)&&(Te.cameraAutoUpdate===!0&&Te.updateCamera(W),W=Te.getCamera()),A.isScene===!0&&A.onBeforeRender(N,A,W,U),S=Le.get(A,v.length),S.init(W),S.state.textureUnits=T.getTextureUnits(),v.push(S),gt.multiplyMatrices(W.projectionMatrix,W.matrixWorldInverse),Ae.setFromProjectionMatrix(gt,ii,W.reversedDepth),tt=this.localClippingEnabled,dt=Be.init(this.clippingPlanes,tt),M=de.get(A,E.length),M.init(),E.push(M),Te.enabled===!0&&Te.isPresenting===!0){const Oe=N.xr.getDepthSensingMesh();Oe!==null&&ad(Oe,W,-1/0,N.sortObjects)}ad(A,W,0,N.sortObjects),M.finish(),N.sortObjects===!0&&M.sort(I,ne),Ut=Te.enabled===!1||Te.isPresenting===!1||Te.hasDepthSensing()===!1,Ut&&ye.addToRenderList(M,A),this.info.render.frame++,dt===!0&&Be.beginShadows();const Y=S.state.shadowsArray;if(Se.render(Y,A,W),dt===!0&&Be.endShadows(),this.info.autoReset===!0&&this.info.reset(),(j&&w.hasRenderPass())===!1){const Oe=M.opaque,Ne=M.transmissive;if(S.setupLights(),W.isArrayCamera){const He=W.cameras;if(Ne.length>0)for(let Xe=0,at=He.length;Xe<at;Xe++){const ft=He[Xe];fg(Oe,Ne,A,ft)}Ut&&ye.render(A);for(let Xe=0,at=He.length;Xe<at;Xe++){const ft=He[Xe];dg(M,A,ft,ft.viewport)}}else Ne.length>0&&fg(Oe,Ne,A,W),Ut&&ye.render(A),dg(M,A,W)}U!==null&&z===0&&(T.updateMultisampleRenderTarget(U),T.updateRenderTargetMipmap(U)),j&&w.end(N),A.isScene===!0&&A.onAfterRender(N,A,W),ve.resetDefaultState(),B=-1,D=null,v.pop(),v.length>0?(S=v[v.length-1],T.setTextureUnits(S.state.textureUnits),dt===!0&&Be.setGlobalState(N.clippingPlanes,S.state.camera)):S=null,E.pop(),E.length>0?M=E[E.length-1]:M=null,F!==null&&F.renderEnd()};function ad(A,W,Q,j){if(A.visible===!1)return;if(A.layers.test(W.layers)){if(A.isGroup)Q=A.renderOrder;else if(A.isLOD)A.autoUpdate===!0&&A.update(W);else if(A.isLightProbeGrid)S.pushLightProbeGrid(A);else if(A.isLight)S.pushLight(A),A.castShadow&&S.pushShadow(A);else if(A.isSprite){if(!A.frustumCulled||Ae.intersectsSprite(A)){j&&nt.setFromMatrixPosition(A.matrixWorld).applyMatrix4(gt);const Oe=xe.update(A),Ne=A.material;Ne.visible&&M.push(A,Oe,Ne,Q,nt.z,null)}}else if((A.isMesh||A.isLine||A.isPoints)&&(!A.frustumCulled||Ae.intersectsObject(A))){const Oe=xe.update(A),Ne=A.material;if(j&&(A.boundingSphere!==void 0?(A.boundingSphere===null&&A.computeBoundingSphere(),nt.copy(A.boundingSphere.center)):(Oe.boundingSphere===null&&Oe.computeBoundingSphere(),nt.copy(Oe.boundingSphere.center)),nt.applyMatrix4(A.matrixWorld).applyMatrix4(gt)),Array.isArray(Ne)){const He=Oe.groups;for(let Xe=0,at=He.length;Xe<at;Xe++){const ft=He[Xe],je=Ne[ft.materialIndex];je&&je.visible&&M.push(A,Oe,je,Q,nt.z,ft)}}else Ne.visible&&M.push(A,Oe,Ne,Q,nt.z,null)}}const De=A.children;for(let Oe=0,Ne=De.length;Oe<Ne;Oe++)ad(De[Oe],W,Q,j)}function dg(A,W,Q,j){const{opaque:Y,transmissive:De,transparent:Oe}=A;S.setupLightsView(Q),dt===!0&&Be.setGlobalState(N.clippingPlanes,Q),j&&Re.viewport(X.copy(j)),Y.length>0&&Xc(Y,W,Q),De.length>0&&Xc(De,W,Q),Oe.length>0&&Xc(Oe,W,Q),Re.buffers.depth.setTest(!0),Re.buffers.depth.setMask(!0),Re.buffers.color.setMask(!0),Re.setPolygonOffset(!1)}function fg(A,W,Q,j){if((Q.isScene===!0?Q.overrideMaterial:null)!==null)return;if(S.state.transmissionRenderTarget[j.id]===void 0){const je=yt.has("EXT_color_buffer_half_float")||yt.has("EXT_color_buffer_float");S.state.transmissionRenderTarget[j.id]=new Yi(1,1,{generateMipmaps:!0,type:je?tn:Xt,minFilter:ui,samples:Math.max(4,qt.samples),stencilBuffer:s,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:Ye.workingColorSpace})}const De=S.state.transmissionRenderTarget[j.id],Oe=j.viewport||X;De.setSize(Oe.z*N.transmissionResolutionScale,Oe.w*N.transmissionResolutionScale);const Ne=N.getRenderTarget(),He=N.getActiveCubeFace(),Xe=N.getActiveMipmapLevel();N.setRenderTarget(De),N.getClearColor(Z),oe=N.getClearAlpha(),oe<1&&N.setClearColor(16777215,.5),N.clear(),Ut&&ye.render(Q);const at=N.toneMapping;N.toneMapping=Fn;const ft=j.viewport;if(j.viewport!==void 0&&(j.viewport=void 0),S.setupLightsView(j),dt===!0&&Be.setGlobalState(N.clippingPlanes,j),Xc(A,Q,j),T.updateMultisampleRenderTarget(De),T.updateRenderTargetMipmap(De),yt.has("WEBGL_multisampled_render_to_texture")===!1){let je=!1;for(let kt=0,un=W.length;kt<un;kt++){const an=W[kt],{object:zt,geometry:Gn,material:Ie,group:mi}=an;if(Ie.side===Nn&&zt.layers.test(j.layers)){const St=Ie.side;Ie.side=Lt,Ie.needsUpdate=!0,pg(zt,Q,j,Gn,Ie,mi),Ie.side=St,Ie.needsUpdate=!0,je=!0}}je===!0&&(T.updateMultisampleRenderTarget(De),T.updateRenderTargetMipmap(De))}N.setRenderTarget(Ne,He,Xe),N.setClearColor(Z,oe),ft!==void 0&&(j.viewport=ft),N.toneMapping=at}function Xc(A,W,Q){const j=W.isScene===!0?W.overrideMaterial:null;for(let Y=0,De=A.length;Y<De;Y++){const Oe=A[Y],{object:Ne,geometry:He,group:Xe}=Oe;let at=Oe.material;at.allowOverride===!0&&j!==null&&(at=j),Ne.layers.test(Q.layers)&&pg(Ne,W,Q,He,at,Xe)}}function pg(A,W,Q,j,Y,De){A.onBeforeRender(N,W,Q,j,Y,De),A.modelViewMatrix.multiplyMatrices(Q.matrixWorldInverse,A.matrixWorld),A.normalMatrix.getNormalMatrix(A.modelViewMatrix),Y.onBeforeRender(N,W,Q,j,A,De),Y.transparent===!0&&Y.side===Nn&&Y.forceSinglePass===!1?(Y.side=Lt,Y.needsUpdate=!0,N.renderBufferDirect(Q,W,j,Y,A,De),Y.side=ri,Y.needsUpdate=!0,N.renderBufferDirect(Q,W,j,Y,A,De),Y.side=Nn):N.renderBufferDirect(Q,W,j,Y,A,De),A.onAfterRender(N,W,Q,j,Y,De)}function qc(A,W,Q){W.isScene!==!0&&(W=Bt);const j=R.get(A),Y=S.state.lights,De=S.state.shadowsArray,Oe=Y.state.version,Ne=Me.getParameters(A,Y.state,De,W,Q,S.state.lightProbeGridArray),He=Me.getProgramCacheKey(Ne);let Xe=j.programs;j.environment=A.isMeshStandardMaterial||A.isMeshLambertMaterial||A.isMeshPhongMaterial?W.environment:null,j.fog=W.fog;const at=A.isMeshStandardMaterial||A.isMeshLambertMaterial&&!A.envMap||A.isMeshPhongMaterial&&!A.envMap;j.envMap=q.get(A.envMap||j.environment,at),j.envMapRotation=j.environment!==null&&A.envMap===null?W.environmentRotation:A.envMapRotation,Xe===void 0&&(A.addEventListener("dispose",cn),Xe=new Map,j.programs=Xe);let ft=Xe.get(He);if(ft!==void 0){if(j.currentProgram===ft&&j.lightsStateVersion===Oe)return gg(A,Ne),ft}else Ne.uniforms=Me.getUniforms(A),F!==null&&A.isNodeMaterial&&F.build(A,Q,Ne),A.onBeforeCompile(Ne,N),ft=Me.acquireProgram(Ne,He),Xe.set(He,ft),j.uniforms=Ne.uniforms;const je=j.uniforms;return(!A.isShaderMaterial&&!A.isRawShaderMaterial||A.clipping===!0)&&(je.clippingPlanes=Be.uniform),gg(A,Ne),j.needsLights=uS(A),j.lightsStateVersion=Oe,j.needsLights&&(je.ambientLightColor.value=Y.state.ambient,je.lightProbe.value=Y.state.probe,je.directionalLights.value=Y.state.directional,je.directionalLightShadows.value=Y.state.directionalShadow,je.spotLights.value=Y.state.spot,je.spotLightShadows.value=Y.state.spotShadow,je.rectAreaLights.value=Y.state.rectArea,je.ltc_1.value=Y.state.rectAreaLTC1,je.ltc_2.value=Y.state.rectAreaLTC2,je.pointLights.value=Y.state.point,je.pointLightShadows.value=Y.state.pointShadow,je.hemisphereLights.value=Y.state.hemi,je.directionalShadowMatrix.value=Y.state.directionalShadowMatrix,je.spotLightMatrix.value=Y.state.spotLightMatrix,je.spotLightMap.value=Y.state.spotLightMap,je.pointShadowMatrix.value=Y.state.pointShadowMatrix),j.lightProbeGrid=S.state.lightProbeGridArray.length>0,j.currentProgram=ft,j.uniformsList=null,ft}function mg(A){if(A.uniformsList===null){const W=A.currentProgram.getUniforms();A.uniformsList=ah.seqWithValue(W.seq,A.uniforms)}return A.uniformsList}function gg(A,W){const Q=R.get(A);Q.outputColorSpace=W.outputColorSpace,Q.batching=W.batching,Q.batchingColor=W.batchingColor,Q.instancing=W.instancing,Q.instancingColor=W.instancingColor,Q.instancingMorph=W.instancingMorph,Q.skinning=W.skinning,Q.morphTargets=W.morphTargets,Q.morphNormals=W.morphNormals,Q.morphColors=W.morphColors,Q.morphTargetsCount=W.morphTargetsCount,Q.numClippingPlanes=W.numClippingPlanes,Q.numIntersection=W.numClipIntersection,Q.vertexAlphas=W.vertexAlphas,Q.vertexTangents=W.vertexTangents,Q.toneMapping=W.toneMapping}function aS(A,W){if(A.length===0)return null;if(A.length===1)return A[0].texture!==null?A[0]:null;b.setFromMatrixPosition(W.matrixWorld);for(let Q=0,j=A.length;Q<j;Q++){const Y=A[Q];if(Y.texture!==null&&Y.boundingBox.containsPoint(b))return Y}return null}function lS(A,W,Q,j,Y){W.isScene!==!0&&(W=Bt),T.resetTextureUnits();const De=W.fog,Oe=j.isMeshStandardMaterial||j.isMeshLambertMaterial||j.isMeshPhongMaterial?W.environment:null,Ne=U===null?N.outputColorSpace:U.isXRRenderTarget===!0?U.texture.colorSpace:Ye.workingColorSpace,He=j.isMeshStandardMaterial||j.isMeshLambertMaterial&&!j.envMap||j.isMeshPhongMaterial&&!j.envMap,Xe=q.get(j.envMap||Oe,He),at=j.vertexColors===!0&&!!Q.attributes.color&&Q.attributes.color.itemSize===4,ft=!!Q.attributes.tangent&&(!!j.normalMap||j.anisotropy>0),je=!!Q.morphAttributes.position,kt=!!Q.morphAttributes.normal,un=!!Q.morphAttributes.color;let an=Fn;j.toneMapped&&(U===null||U.isXRRenderTarget===!0)&&(an=N.toneMapping);const zt=Q.morphAttributes.position||Q.morphAttributes.normal||Q.morphAttributes.color,Gn=zt!==void 0?zt.length:0,Ie=R.get(j),mi=S.state.lights;if(dt===!0&&(tt===!0||A!==D)){const jt=A===D&&j.id===B;Be.setState(j,A,jt)}let St=!1;j.version===Ie.__version?(Ie.needsLights&&Ie.lightsStateVersion!==mi.state.version||Ie.outputColorSpace!==Ne||Y.isBatchedMesh&&Ie.batching===!1||!Y.isBatchedMesh&&Ie.batching===!0||Y.isBatchedMesh&&Ie.batchingColor===!0&&Y.colorTexture===null||Y.isBatchedMesh&&Ie.batchingColor===!1&&Y.colorTexture!==null||Y.isInstancedMesh&&Ie.instancing===!1||!Y.isInstancedMesh&&Ie.instancing===!0||Y.isSkinnedMesh&&Ie.skinning===!1||!Y.isSkinnedMesh&&Ie.skinning===!0||Y.isInstancedMesh&&Ie.instancingColor===!0&&Y.instanceColor===null||Y.isInstancedMesh&&Ie.instancingColor===!1&&Y.instanceColor!==null||Y.isInstancedMesh&&Ie.instancingMorph===!0&&Y.morphTexture===null||Y.isInstancedMesh&&Ie.instancingMorph===!1&&Y.morphTexture!==null||Ie.envMap!==Xe||j.fog===!0&&Ie.fog!==De||Ie.numClippingPlanes!==void 0&&(Ie.numClippingPlanes!==Be.numPlanes||Ie.numIntersection!==Be.numIntersection)||Ie.vertexAlphas!==at||Ie.vertexTangents!==ft||Ie.morphTargets!==je||Ie.morphNormals!==kt||Ie.morphColors!==un||Ie.toneMapping!==an||Ie.morphTargetsCount!==Gn||!!Ie.lightProbeGrid!=S.state.lightProbeGridArray.length>0)&&(St=!0):(St=!0,Ie.__version=j.version);let Ei=Ie.currentProgram;St===!0&&(Ei=qc(j,W,Y),F&&j.isNodeMaterial&&F.onUpdateProgram(j,Ei,Ie));let Qi=!1,ts=!1,Uo=!1;const Ht=Ei.getUniforms(),hn=Ie.uniforms;if(Re.useProgram(Ei.program)&&(Qi=!0,ts=!0,Uo=!0),j.id!==B&&(B=j.id,ts=!0),Ie.needsLights){const jt=aS(S.state.lightProbeGridArray,Y);Ie.lightProbeGrid!==jt&&(Ie.lightProbeGrid=jt,ts=!0)}if(Qi||D!==A){Re.buffers.depth.getReversed()&&A.reversedDepth!==!0&&(A._reversedDepth=!0,A.updateProjectionMatrix()),Ht.setValue(H,"projectionMatrix",A.projectionMatrix),Ht.setValue(H,"viewMatrix",A.matrixWorldInverse);const is=Ht.map.cameraPosition;is!==void 0&&is.setValue(H,At.setFromMatrixPosition(A.matrixWorld)),qt.logarithmicDepthBuffer&&Ht.setValue(H,"logDepthBufFC",2/(Math.log(A.far+1)/Math.LN2)),(j.isMeshPhongMaterial||j.isMeshToonMaterial||j.isMeshLambertMaterial||j.isMeshBasicMaterial||j.isMeshStandardMaterial||j.isShaderMaterial)&&Ht.setValue(H,"isOrthographic",A.isOrthographicCamera===!0),D!==A&&(D=A,ts=!0,Uo=!0)}if(Ie.needsLights&&(mi.state.directionalShadowMap.length>0&&Ht.setValue(H,"directionalShadowMap",mi.state.directionalShadowMap,T),mi.state.spotShadowMap.length>0&&Ht.setValue(H,"spotShadowMap",mi.state.spotShadowMap,T),mi.state.pointShadowMap.length>0&&Ht.setValue(H,"pointShadowMap",mi.state.pointShadowMap,T)),Y.isSkinnedMesh){Ht.setOptional(H,Y,"bindMatrix"),Ht.setOptional(H,Y,"bindMatrixInverse");const jt=Y.skeleton;jt&&(jt.boneTexture===null&&jt.computeBoneTexture(),Ht.setValue(H,"boneTexture",jt.boneTexture,T))}Y.isBatchedMesh&&(Ht.setOptional(H,Y,"batchingTexture"),Ht.setValue(H,"batchingTexture",Y._matricesTexture,T),Ht.setOptional(H,Y,"batchingIdTexture"),Ht.setValue(H,"batchingIdTexture",Y._indirectTexture,T),Ht.setOptional(H,Y,"batchingColorTexture"),Y._colorsTexture!==null&&Ht.setValue(H,"batchingColorTexture",Y._colorsTexture,T));const ns=Q.morphAttributes;if((ns.position!==void 0||ns.normal!==void 0||ns.color!==void 0)&&it.update(Y,Q,Ei),(ts||Ie.receiveShadow!==Y.receiveShadow)&&(Ie.receiveShadow=Y.receiveShadow,Ht.setValue(H,"receiveShadow",Y.receiveShadow)),(j.isMeshStandardMaterial||j.isMeshLambertMaterial||j.isMeshPhongMaterial)&&j.envMap===null&&W.environment!==null&&(hn.envMapIntensity.value=W.environmentIntensity),hn.dfgLUT!==void 0&&(hn.dfgLUT.value=EC()),ts){if(Ht.setValue(H,"toneMappingExposure",N.toneMappingExposure),Ie.needsLights&&cS(hn,Uo),De&&j.fog===!0&&se.refreshFogUniforms(hn,De),se.refreshMaterialUniforms(hn,j,$,ze,S.state.transmissionRenderTarget[A.id]),Ie.needsLights&&Ie.lightProbeGrid){const jt=Ie.lightProbeGrid;hn.probesSH.value=jt.texture,hn.probesMin.value.copy(jt.boundingBox.min),hn.probesMax.value.copy(jt.boundingBox.max),hn.probesResolution.value.copy(jt.resolution)}ah.upload(H,mg(Ie),hn,T)}if(j.isShaderMaterial&&j.uniformsNeedUpdate===!0&&(ah.upload(H,mg(Ie),hn,T),j.uniformsNeedUpdate=!1),j.isSpriteMaterial&&Ht.setValue(H,"center",Y.center),Ht.setValue(H,"modelViewMatrix",Y.modelViewMatrix),Ht.setValue(H,"normalMatrix",Y.normalMatrix),Ht.setValue(H,"modelMatrix",Y.matrixWorld),j.uniformsGroups!==void 0){const jt=j.uniformsGroups;for(let is=0,Fo=jt.length;is<Fo;is++){const _g=jt[is];le.update(_g,Ei),le.bind(_g,Ei)}}return Ei}function cS(A,W){A.ambientLightColor.needsUpdate=W,A.lightProbe.needsUpdate=W,A.directionalLights.needsUpdate=W,A.directionalLightShadows.needsUpdate=W,A.pointLights.needsUpdate=W,A.pointLightShadows.needsUpdate=W,A.spotLights.needsUpdate=W,A.spotLightShadows.needsUpdate=W,A.rectAreaLights.needsUpdate=W,A.hemisphereLights.needsUpdate=W}function uS(A){return A.isMeshLambertMaterial||A.isMeshToonMaterial||A.isMeshPhongMaterial||A.isMeshStandardMaterial||A.isShadowMaterial||A.isShaderMaterial&&A.lights===!0}this.getActiveCubeFace=function(){return V},this.getActiveMipmapLevel=function(){return z},this.getRenderTarget=function(){return U},this.setRenderTargetTextures=function(A,W,Q){const j=R.get(A);j.__autoAllocateDepthBuffer=A.resolveDepthBuffer===!1,j.__autoAllocateDepthBuffer===!1&&(j.__useRenderToTexture=!1),R.get(A.texture).__webglTexture=W,R.get(A.depthTexture).__webglTexture=j.__autoAllocateDepthBuffer?void 0:Q,j.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(A,W){const Q=R.get(A);Q.__webglFramebuffer=W,Q.__useDefaultFramebuffer=W===void 0};const hS=H.createFramebuffer();this.setRenderTarget=function(A,W=0,Q=0){U=A,V=W,z=Q;let j=null,Y=!1,De=!1;if(A){const Ne=R.get(A);if(Ne.__useDefaultFramebuffer!==void 0){Re.bindFramebuffer(H.FRAMEBUFFER,Ne.__webglFramebuffer),X.copy(A.viewport),K.copy(A.scissor),fe=A.scissorTest,Re.viewport(X),Re.scissor(K),Re.setScissorTest(fe),B=-1;return}else if(Ne.__webglFramebuffer===void 0)T.setupRenderTarget(A);else if(Ne.__hasExternalTextures)T.rebindTextures(A,R.get(A.texture).__webglTexture,R.get(A.depthTexture).__webglTexture);else if(A.depthBuffer){const at=A.depthTexture;if(Ne.__boundDepthTexture!==at){if(at!==null&&R.has(at)&&(A.width!==at.image.width||A.height!==at.image.height))throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");T.setupDepthRenderbuffer(A)}}const He=A.texture;(He.isData3DTexture||He.isDataArrayTexture||He.isCompressedArrayTexture)&&(De=!0);const Xe=R.get(A).__webglFramebuffer;A.isWebGLCubeRenderTarget?(Array.isArray(Xe[W])?j=Xe[W][Q]:j=Xe[W],Y=!0):A.samples>0&&T.useMultisampledRTT(A)===!1?j=R.get(A).__webglMultisampledFramebuffer:Array.isArray(Xe)?j=Xe[Q]:j=Xe,X.copy(A.viewport),K.copy(A.scissor),fe=A.scissorTest}else X.copy(ue).multiplyScalar($).floor(),K.copy(_e).multiplyScalar($).floor(),fe=Ue;if(Q!==0&&(j=hS),Re.bindFramebuffer(H.FRAMEBUFFER,j)&&Re.drawBuffers(A,j),Re.viewport(X),Re.scissor(K),Re.setScissorTest(fe),Y){const Ne=R.get(A.texture);H.framebufferTexture2D(H.FRAMEBUFFER,H.COLOR_ATTACHMENT0,H.TEXTURE_CUBE_MAP_POSITIVE_X+W,Ne.__webglTexture,Q)}else if(De){const Ne=W;for(let He=0;He<A.textures.length;He++){const Xe=R.get(A.textures[He]);H.framebufferTextureLayer(H.FRAMEBUFFER,H.COLOR_ATTACHMENT0+He,Xe.__webglTexture,Q,Ne)}}else if(A!==null&&Q!==0){const Ne=R.get(A.texture);H.framebufferTexture2D(H.FRAMEBUFFER,H.COLOR_ATTACHMENT0,H.TEXTURE_2D,Ne.__webglTexture,Q)}B=-1},this.readRenderTargetPixels=function(A,W,Q,j,Y,De,Oe,Ne=0){if(!(A&&A.isWebGLRenderTarget)){ce("WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let He=R.get(A).__webglFramebuffer;if(A.isWebGLCubeRenderTarget&&Oe!==void 0&&(He=He[Oe]),He){Re.bindFramebuffer(H.FRAMEBUFFER,He);try{const Xe=A.textures[Ne],at=Xe.format,ft=Xe.type;if(A.textures.length>1&&H.readBuffer(H.COLOR_ATTACHMENT0+Ne),!qt.textureFormatReadable(at)){ce("WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!qt.textureTypeReadable(ft)){ce("WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}W>=0&&W<=A.width-j&&Q>=0&&Q<=A.height-Y&&H.readPixels(W,Q,j,Y,O.convert(at),O.convert(ft),De)}finally{const Xe=U!==null?R.get(U).__webglFramebuffer:null;Re.bindFramebuffer(H.FRAMEBUFFER,Xe)}}},this.readRenderTargetPixelsAsync=async function(A,W,Q,j,Y,De,Oe,Ne=0){if(!(A&&A.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let He=R.get(A).__webglFramebuffer;if(A.isWebGLCubeRenderTarget&&Oe!==void 0&&(He=He[Oe]),He)if(W>=0&&W<=A.width-j&&Q>=0&&Q<=A.height-Y){Re.bindFramebuffer(H.FRAMEBUFFER,He);const Xe=A.textures[Ne],at=Xe.format,ft=Xe.type;if(A.textures.length>1&&H.readBuffer(H.COLOR_ATTACHMENT0+Ne),!qt.textureFormatReadable(at))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!qt.textureTypeReadable(ft))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");const je=H.createBuffer();H.bindBuffer(H.PIXEL_PACK_BUFFER,je),H.bufferData(H.PIXEL_PACK_BUFFER,De.byteLength,H.STREAM_READ),H.readPixels(W,Q,j,Y,O.convert(at),O.convert(ft),0);const kt=U!==null?R.get(U).__webglFramebuffer:null;Re.bindFramebuffer(H.FRAMEBUFFER,kt);const un=H.fenceSync(H.SYNC_GPU_COMMANDS_COMPLETE,0);return H.flush(),await eT(H,un,4),H.bindBuffer(H.PIXEL_PACK_BUFFER,je),H.getBufferSubData(H.PIXEL_PACK_BUFFER,0,De),H.deleteBuffer(je),H.deleteSync(un),De}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")},this.copyFramebufferToTexture=function(A,W=null,Q=0){const j=Math.pow(2,-Q),Y=Math.floor(A.image.width*j),De=Math.floor(A.image.height*j),Oe=W!==null?W.x:0,Ne=W!==null?W.y:0;T.setTexture2D(A,0),H.copyTexSubImage2D(H.TEXTURE_2D,Q,0,0,Oe,Ne,Y,De),Re.unbindTexture()};const dS=H.createFramebuffer(),fS=H.createFramebuffer();this.copyTextureToTexture=function(A,W,Q=null,j=null,Y=0,De=0){let Oe,Ne,He,Xe,at,ft,je,kt,un;const an=A.isCompressedTexture?A.mipmaps[De]:A.image;if(Q!==null)Oe=Q.max.x-Q.min.x,Ne=Q.max.y-Q.min.y,He=Q.isBox3?Q.max.z-Q.min.z:1,Xe=Q.min.x,at=Q.min.y,ft=Q.isBox3?Q.min.z:0;else{const hn=Math.pow(2,-Y);Oe=Math.floor(an.width*hn),Ne=Math.floor(an.height*hn),A.isDataArrayTexture?He=an.depth:A.isData3DTexture?He=Math.floor(an.depth*hn):He=1,Xe=0,at=0,ft=0}j!==null?(je=j.x,kt=j.y,un=j.z):(je=0,kt=0,un=0);const zt=O.convert(W.format),Gn=O.convert(W.type);let Ie;W.isData3DTexture?(T.setTexture3D(W,0),Ie=H.TEXTURE_3D):W.isDataArrayTexture||W.isCompressedArrayTexture?(T.setTexture2DArray(W,0),Ie=H.TEXTURE_2D_ARRAY):(T.setTexture2D(W,0),Ie=H.TEXTURE_2D),Re.activeTexture(H.TEXTURE0),Re.pixelStorei(H.UNPACK_FLIP_Y_WEBGL,W.flipY),Re.pixelStorei(H.UNPACK_PREMULTIPLY_ALPHA_WEBGL,W.premultiplyAlpha),Re.pixelStorei(H.UNPACK_ALIGNMENT,W.unpackAlignment);const mi=Re.getParameter(H.UNPACK_ROW_LENGTH),St=Re.getParameter(H.UNPACK_IMAGE_HEIGHT),Ei=Re.getParameter(H.UNPACK_SKIP_PIXELS),Qi=Re.getParameter(H.UNPACK_SKIP_ROWS),ts=Re.getParameter(H.UNPACK_SKIP_IMAGES);Re.pixelStorei(H.UNPACK_ROW_LENGTH,an.width),Re.pixelStorei(H.UNPACK_IMAGE_HEIGHT,an.height),Re.pixelStorei(H.UNPACK_SKIP_PIXELS,Xe),Re.pixelStorei(H.UNPACK_SKIP_ROWS,at),Re.pixelStorei(H.UNPACK_SKIP_IMAGES,ft);const Uo=A.isDataArrayTexture||A.isData3DTexture,Ht=W.isDataArrayTexture||W.isData3DTexture;if(A.isDepthTexture){const hn=R.get(A),ns=R.get(W),jt=R.get(hn.__renderTarget),is=R.get(ns.__renderTarget);Re.bindFramebuffer(H.READ_FRAMEBUFFER,jt.__webglFramebuffer),Re.bindFramebuffer(H.DRAW_FRAMEBUFFER,is.__webglFramebuffer);for(let Fo=0;Fo<He;Fo++)Uo&&(H.framebufferTextureLayer(H.READ_FRAMEBUFFER,H.COLOR_ATTACHMENT0,R.get(A).__webglTexture,Y,ft+Fo),H.framebufferTextureLayer(H.DRAW_FRAMEBUFFER,H.COLOR_ATTACHMENT0,R.get(W).__webglTexture,De,un+Fo)),H.blitFramebuffer(Xe,at,Oe,Ne,je,kt,Oe,Ne,H.DEPTH_BUFFER_BIT,H.NEAREST);Re.bindFramebuffer(H.READ_FRAMEBUFFER,null),Re.bindFramebuffer(H.DRAW_FRAMEBUFFER,null)}else if(Y!==0||A.isRenderTargetTexture||R.has(A)){const hn=R.get(A),ns=R.get(W);Re.bindFramebuffer(H.READ_FRAMEBUFFER,dS),Re.bindFramebuffer(H.DRAW_FRAMEBUFFER,fS);for(let jt=0;jt<He;jt++)Uo?H.framebufferTextureLayer(H.READ_FRAMEBUFFER,H.COLOR_ATTACHMENT0,hn.__webglTexture,Y,ft+jt):H.framebufferTexture2D(H.READ_FRAMEBUFFER,H.COLOR_ATTACHMENT0,H.TEXTURE_2D,hn.__webglTexture,Y),Ht?H.framebufferTextureLayer(H.DRAW_FRAMEBUFFER,H.COLOR_ATTACHMENT0,ns.__webglTexture,De,un+jt):H.framebufferTexture2D(H.DRAW_FRAMEBUFFER,H.COLOR_ATTACHMENT0,H.TEXTURE_2D,ns.__webglTexture,De),Y!==0?H.blitFramebuffer(Xe,at,Oe,Ne,je,kt,Oe,Ne,H.COLOR_BUFFER_BIT,H.NEAREST):Ht?H.copyTexSubImage3D(Ie,De,je,kt,un+jt,Xe,at,Oe,Ne):H.copyTexSubImage2D(Ie,De,je,kt,Xe,at,Oe,Ne);Re.bindFramebuffer(H.READ_FRAMEBUFFER,null),Re.bindFramebuffer(H.DRAW_FRAMEBUFFER,null)}else Ht?A.isDataTexture||A.isData3DTexture?H.texSubImage3D(Ie,De,je,kt,un,Oe,Ne,He,zt,Gn,an.data):W.isCompressedArrayTexture?H.compressedTexSubImage3D(Ie,De,je,kt,un,Oe,Ne,He,zt,an.data):H.texSubImage3D(Ie,De,je,kt,un,Oe,Ne,He,zt,Gn,an):A.isDataTexture?H.texSubImage2D(H.TEXTURE_2D,De,je,kt,Oe,Ne,zt,Gn,an.data):A.isCompressedTexture?H.compressedTexSubImage2D(H.TEXTURE_2D,De,je,kt,an.width,an.height,zt,an.data):H.texSubImage2D(H.TEXTURE_2D,De,je,kt,Oe,Ne,zt,Gn,an);Re.pixelStorei(H.UNPACK_ROW_LENGTH,mi),Re.pixelStorei(H.UNPACK_IMAGE_HEIGHT,St),Re.pixelStorei(H.UNPACK_SKIP_PIXELS,Ei),Re.pixelStorei(H.UNPACK_SKIP_ROWS,Qi),Re.pixelStorei(H.UNPACK_SKIP_IMAGES,ts),De===0&&W.generateMipmaps&&H.generateMipmap(Ie),Re.unbindTexture()},this.initRenderTarget=function(A){R.get(A).__webglFramebuffer===void 0&&T.setupRenderTarget(A)},this.initTexture=function(A){A.isCubeTexture?T.setTextureCube(A,0):A.isData3DTexture?T.setTexture3D(A,0):A.isDataArrayTexture||A.isCompressedArrayTexture?T.setTexture2DArray(A,0):T.setTexture2D(A,0),Re.unbindTexture()},this.resetState=function(){V=0,z=0,U=null,Re.reset(),ve.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return ii}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;const t=this.getContext();t.drawingBufferColorSpace=Ye._getDrawingBufferColorSpace(e),t.unpackColorSpace=Ye._getUnpackColorSpace()}}const xa=new ur,zr=new pe,Ay=new P,Hd=new pe,lh=new pe,bh=new P,ap=new P,wy=new pt,Ry=new P,Cy=new P;let $n=null,lr=null;const Hr=[],Cs={NONE:-1,PAN:0,ROTATE:1};class wC extends kh{constructor(e,t,n=null){super(t,n),this.objects=e,this.recursive=!0,this.transformGroup=!1,this.rotateSpeed=1,this.raycaster=new _y,this.mouseButtons={LEFT:Un.PAN,MIDDLE:Un.PAN,RIGHT:Un.ROTATE},this.touches={ONE:$r.PAN},this._onPointerMove=RC.bind(this),this._onPointerDown=CC.bind(this),this._onPointerCancel=NC.bind(this),this._onContextMenu=PC.bind(this),n!==null&&this.connect(n)}connect(e){super.connect(e),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointerup",this._onPointerCancel),this.domElement.addEventListener("pointerleave",this._onPointerCancel),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointerup",this._onPointerCancel),this.domElement.removeEventListener("pointerleave",this._onPointerCancel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="",this.domElement.style.cursor=""}dispose(){this.disconnect()}_updatePointer(e){const t=this.domElement.getBoundingClientRect();zr.x=(e.clientX-t.left)/t.width*2-1,zr.y=-(e.clientY-t.top)/t.height*2+1}_updateState(e){let t;if(e.pointerType==="touch")t=this.touches.ONE;else switch(e.button){case 0:t=this.mouseButtons.LEFT;break;case 1:t=this.mouseButtons.MIDDLE;break;case 2:t=this.mouseButtons.RIGHT;break;default:t=null}switch(t){case Un.PAN:case $r.PAN:this.state=Cs.PAN;break;case Un.ROTATE:case $r.ROTATE:this.state=Cs.ROTATE;break;default:this.state=Cs.NONE}}}function RC(r){const e=this.object,t=this.domElement,n=this.raycaster;if(this.enabled!==!1){if(this._updatePointer(r),n.setFromCamera(zr,e),$n)this.state===Cs.PAN?n.ray.intersectPlane(xa,bh)&&($n.position.copy(bh.sub(Ay).applyMatrix4(wy)),this.dispatchEvent({type:"drag",object:$n})):this.state===Cs.ROTATE&&(Hd.subVectors(zr,lh).multiplyScalar(this.rotateSpeed),$n.rotateOnWorldAxis(Ry,Hd.x),$n.rotateOnWorldAxis(Cy.normalize(),-Hd.y),this.dispatchEvent({type:"drag",object:$n})),lh.copy(zr);else if(r.pointerType==="mouse"||r.pointerType==="pen")if(Hr.length=0,n.setFromCamera(zr,e),n.intersectObjects(this.objects,this.recursive,Hr),Hr.length>0){const i=Hr[0].object;xa.setFromNormalAndCoplanarPoint(e.getWorldDirection(xa.normal),ap.setFromMatrixPosition(i.matrixWorld)),lr!==i&&lr!==null&&(this.dispatchEvent({type:"hoveroff",object:lr}),t.style.cursor="auto",lr=null),lr!==i&&(this.dispatchEvent({type:"hoveron",object:i}),t.style.cursor="pointer",lr=i)}else lr!==null&&(this.dispatchEvent({type:"hoveroff",object:lr}),t.style.cursor="auto",lr=null);lh.copy(zr)}}function CC(r){const e=this.object,t=this.domElement,n=this.raycaster;this.enabled!==!1&&(this._updatePointer(r),this._updateState(r),Hr.length=0,n.setFromCamera(zr,e),n.intersectObjects(this.objects,this.recursive,Hr),Hr.length>0&&(this.transformGroup===!0?$n=Ny(Hr[0].object):$n=Hr[0].object,xa.setFromNormalAndCoplanarPoint(e.getWorldDirection(xa.normal),ap.setFromMatrixPosition($n.matrixWorld)),n.ray.intersectPlane(xa,bh)&&(this.state===Cs.PAN?(wy.copy($n.parent.matrixWorld).invert(),Ay.copy(bh).sub(ap.setFromMatrixPosition($n.matrixWorld)),t.style.cursor="move",this.dispatchEvent({type:"dragstart",object:$n})):this.state===Cs.ROTATE&&(Ry.set(0,1,0).applyQuaternion(e.quaternion).normalize(),Cy.set(1,0,0).applyQuaternion(e.quaternion).normalize(),t.style.cursor="move",this.dispatchEvent({type:"dragstart",object:$n})))),lh.copy(zr))}function NC(){this.enabled!==!1&&($n&&(this.dispatchEvent({type:"dragend",object:$n}),$n=null),this.domElement.style.cursor=lr?"pointer":"auto",this.state=Cs.NONE)}function PC(r){this.enabled!==!1&&r.preventDefault()}function Ny(r,e=null){return r.isGroup&&(e=r),r.parent===null?e:Ny(r.parent,e)}function DC(r){UC(r);const e=LC(r);return r.on=e.on,r.off=e.off,r.fire=e.fire,r}function LC(r){let e=Object.create(null);return{on:function(t,n,i){if(typeof n!="function")throw new Error("callback is expected to be a function");let s=e[t];return s||(s=e[t]=[]),s.push({callback:n,ctx:i}),r},off:function(t,n){if(typeof t>"u")return e=Object.create(null),r;if(e[t])if(typeof n!="function")delete e[t];else{const o=e[t];for(let a=0;a<o.length;++a)o[a].callback===n&&o.splice(a,1)}return r},fire:function(t){const n=e[t];if(!n)return r;let i;arguments.length>1&&(i=Array.prototype.slice.call(arguments,1));for(let s=0;s<n.length;++s){const o=n[s];o.callback.apply(o.ctx,i)}return r}}}function UC(r){if(!r)throw new Error("Eventify cannot use falsy object as events subject");const e=["on","fire","off"];for(let t=0;t<e.length;++t)if(r.hasOwnProperty(e[t]))throw new Error("Subject cannot be eventified, since it already has property '"+e[t]+"'")}function FC(r){if(r=r||{},"uniqueLinkId"in r&&(console.warn("ngraph.graph: Starting from version 0.14 `uniqueLinkId` is deprecated.\nUse `multigraph` option instead\n",`
4113
4113
  `,`Note: there is also change in default behavior: From now on each graph
4114
4114
  is considered to be not a multigraph by default (each edge is unique).`),r.multigraph=r.uniqueLinkId),r.multigraph===void 0&&(r.multigraph=!1),typeof Map!="function")throw new Error("ngraph.graph requires `Map` to be defined. Please polyfill it before using ngraph");var e=new Map,t=new Map,n={},i=0,s=r.multigraph?b:y,o=[],a=D,l=D,c=D,u=D,h={version:20,addNode:g,addLink:x,removeLink:v,removeNode:_,getNode:m,getNodeCount:M,getLinkCount:S,getEdgeCount:S,getLinksCount:S,getNodesCount:M,getLinks:E,forEachNode:fe,forEachLinkedNode:z,forEachLink:V,beginUpdate:c,endUpdate:u,clear:F,hasLink:N,hasNode:m,getLink:N,getLinkById:C};return DC(h),d(),h;function d(){var Z=h.on;h.on=oe;function oe(){return h.beginUpdate=c=X,h.endUpdate=u=K,a=f,l=p,h.on=Z,Z.apply(h,arguments)}}function f(Z,oe){o.push({link:Z,changeType:oe})}function p(Z,oe){o.push({node:Z,changeType:oe})}function g(Z,oe){if(Z===void 0)throw new Error("Invalid node identifier");c();var Ee=m(Z);return Ee?(Ee.data=oe,l(Ee,"update")):(Ee=new IC(Z,oe),l(Ee,"add")),e.set(Z,Ee),u(),Ee}function m(Z){return e.get(Z)}function _(Z){var oe=m(Z);if(!oe)return!1;c();var Ee=oe.links;return Ee&&(Ee.forEach(w),oe.links=null),e.delete(Z),l(oe,"remove"),u(),!0}function x(Z,oe,Ee){c();var ze=m(Z)||g(Z),$=m(oe)||g(oe),I=s(Z,oe,Ee),ne=t.has(I.id);return t.set(I.id,I),S_(ze,I),Z!==oe&&S_($,I),a(I,ne?"update":"add"),u(),I}function y(Z,oe,Ee){var ze=Su(Z,oe),$=t.get(ze);return $?($.data=Ee,$):new T_(Z,oe,Ee,ze)}function b(Z,oe,Ee){var ze=Su(Z,oe),$=n.hasOwnProperty(ze);if($||N(Z,oe)){$||(n[ze]=0);var I="@"+ ++n[ze];ze=Su(Z+I,oe+I)}return new T_(Z,oe,Ee,ze)}function M(){return e.size}function S(){return t.size}function E(Z){var oe=m(Z);return oe?oe.links:null}function v(Z,oe){return oe!==void 0&&(Z=N(Z,oe)),w(Z)}function w(Z){if(!Z||!t.get(Z.id))return!1;c(),t.delete(Z.id);var oe=m(Z.fromId),Ee=m(Z.toId);return oe&&oe.links.delete(Z),Ee&&Ee.links.delete(Z),a(Z,"remove"),u(),!0}function N(Z,oe){if(!(Z===void 0||oe===void 0))return t.get(Su(Z,oe))}function C(Z){if(Z!==void 0)return t.get(Z)}function F(){c(),fe(function(Z){_(Z.id)}),u()}function V(Z){if(typeof Z=="function")for(var oe=t.values(),Ee=oe.next();!Ee.done;){if(Z(Ee.value))return!0;Ee=oe.next()}}function z(Z,oe,Ee){var ze=m(Z);if(ze&&ze.links&&typeof oe=="function")return Ee?B(ze.links,Z,oe):U(ze.links,Z,oe)}function U(Z,oe,Ee){for(var ze,$=Z.values(),I=$.next();!I.done;){var ne=I.value,ue=ne.fromId===oe?ne.toId:ne.fromId;if(ze=Ee(e.get(ue),ne),ze)return!0;I=$.next()}}function B(Z,oe,Ee){for(var ze,$=Z.values(),I=$.next();!I.done;){var ne=I.value;if(ne.fromId===oe&&(ze=Ee(e.get(ne.toId),ne),ze))return!0;I=$.next()}}function D(){}function X(){i+=1}function K(){i-=1,i===0&&o.length>0&&(h.fire("changed",o),o.length=0)}function fe(Z){if(typeof Z!="function")throw new Error("Function is expected to iterate over graph nodes. You passed "+Z);for(var oe=e.values(),Ee=oe.next();!Ee.done;){if(Z(Ee.value))return!0;Ee=oe.next()}}}function IC(r,e){this.id=r,this.links=null,this.data=e}function S_(r,e){r.links?r.links.add(e):r.links=new Set([e])}function T_(r,e,t,n){this.fromId=r,this.toId=e,this.data=t,this.id=n}function Su(r,e){return r.toString()+"👉 "+e.toString()}var Tu={exports:{}},ea={exports:{}},Wd,M_;function Py(){return M_||(M_=1,Wd=function(e){return e===0?"x":e===1?"y":e===2?"z":"c"+(e+1)}),Wd}var $d,E_;function ll(){if(E_)return $d;E_=1;const r=Py();return $d=function(t){return n;function n(i,s){let o=s&&s.indent||0,a=s&&s.join!==void 0?s.join:`
4115
4115
  `,l=Array(o+1).join(" "),c=[];for(let u=0;u<t;++u){let h=r(u),d=u===0?"":l;c.push(d+i.replace(/{var}/g,h))}return c.join(a)}},$d}var A_;function BC(){if(A_)return ea.exports;A_=1;const r=ll();ea.exports=e,ea.exports.generateCreateBodyFunctionBody=t,ea.exports.getVectorCode=i,ea.exports.getBodyCode=n;function e(s,o){let a=t(s,o),{Body:l}=new Function(a)();return l}function t(s,o){return`
@@ -4621,7 +4621,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
4621
4621
  */const CN=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","aoMapIntensity","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveIntensity","emissiveMap","envMap","envMapIntensity","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","lightMapIntensity","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"],rf=new WeakMap,W_=new WeakMap,$_=new WeakMap;class NN{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=e.object.isSkinnedMesh===!0,this.refreshUniforms=CN,this.renderId=0}firstInitialization(e){return this.renderObjects.has(e)===!1?(this.getRenderObjectData(e),!0):!1}needsVelocity(e){const t=e.getMRT();return t!==null&&t.has("velocity")}getRenderObjectData(e){let t=this.renderObjects.get(e);if(t===void 0){const{geometry:n,object:i}=e;if(t={geometryId:n.id,worldMatrix:i.matrixWorld.clone()},i.center&&(t.center=i.center.clone()),i.morphTargetInfluences&&(t.morphTargetInfluences=i.morphTargetInfluences.slice()),e.bundle!==null&&(t.version=e.bundle.version),e.material.transmission>0){const{width:s,height:o}=e.context;t.bufferWidth=s,t.bufferHeight=o}t.lights=this.getLightsData(e.lightsNode.getLights()),this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const n in e){const i=e[n];t[n]={id:i.id,version:i.version}}return t}containsNode(e){const t=e.material;for(const n in t)if(t[n]&&t[n].isNode)return!0;return!!(e.context.modelViewMatrix||e.context.modelNormalViewMatrix||e.context.getAO||e.context.getShadow)}getGeometryData(e){let t=$_.get(e);return t===void 0&&(t={_renderId:-1,_equal:!1,attributes:this.getAttributesData(e.attributes),indexId:e.index?e.index.id:null,indexVersion:e.index?e.index.version:null,drawRange:{start:e.drawRange.start,count:e.drawRange.count}},$_.set(e,t)),t}getMaterialData(e){let t=W_.get(e);if(t===void 0){t={_renderId:-1,_equal:!1};for(const n of this.refreshUniforms){const i=e[n];i!=null&&(typeof i=="object"&&i.clone!==void 0?i.isTexture===!0?t[n]={id:i.id,version:i.version}:t[n]=i.clone():t[n]=i)}W_.set(e,t)}return t}equals(e,t,n){const{object:i,material:s,geometry:o}=e,a=this.getRenderObjectData(e);if(a.worldMatrix.equals(i.matrixWorld)!==!0)return a.worldMatrix.copy(i.matrixWorld),!1;const l=this.getMaterialData(e.material);if(l._renderId!==n){l._renderId=n;for(const u in l){const h=l[u],d=s[u];if(u!=="_renderId"&&u!=="_equal"){if(h.equals!==void 0){if(h.equals(d)===!1)return h.copy(d),l._equal=!1,!1}else if(d.isTexture===!0){if(h.id!==d.id||h.version!==d.version)return h.id=d.id,h.version=d.version,l._equal=!1,!1}else if(h!==d)return l[u]=d,l._equal=!1,!1}}if(l.transmission>0){const{width:u,height:h}=e.context;if(a.bufferWidth!==u||a.bufferHeight!==h)return a.bufferWidth=u,a.bufferHeight=h,l._equal=!1,!1}l._equal=!0}else if(l._equal===!1)return!1;if(a.geometryId!==o.id)return a.geometryId=o.id,!1;const c=this.getGeometryData(e.geometry);if(c._renderId!==n){c._renderId=n;const u=o.attributes,h=c.attributes;let d=0,f=0;for(const y in u)d++;for(const y in h){f++;const b=h[y],M=u[y];if(M===void 0)return delete h[y],c._equal=!1,!1;if(b.id!==M.id||b.version!==M.version)return b.id=M.id,b.version=M.version,c._equal=!1,!1}if(f!==d)return c.attributes=this.getAttributesData(u),c._equal=!1,!1;const p=o.index,g=c.indexId,m=c.indexVersion,_=p?p.id:null,x=p?p.version:null;if(g!==_||m!==x)return c.indexId=_,c.indexVersion=x,c._equal=!1,!1;if(c.drawRange.start!==o.drawRange.start||c.drawRange.count!==o.drawRange.count)return c.drawRange.start=o.drawRange.start,c.drawRange.count=o.drawRange.count,c._equal=!1,!1;c._equal=!0}else if(c._equal===!1)return!1;if(a.morphTargetInfluences){let u=!1;for(let h=0;h<a.morphTargetInfluences.length;h++)a.morphTargetInfluences[h]!==i.morphTargetInfluences[h]&&(a.morphTargetInfluences[h]=i.morphTargetInfluences[h],u=!0);if(u)return!1}if(a.lights){for(let u=0;u<t.length;u++)if(a.lights[u].map!==t[u].map)return!1}return a.center&&a.center.equals(i.center)===!1?(a.center.copy(i.center),!0):(e.bundle!==null&&(a.version=e.bundle.version),!0)}getLightsData(e){const t=[];for(const n of e)n.isSpotLight===!0&&n.map!==null&&t.push({map:n.map.version});return t}getLights(e,t){if(rf.has(e)){const i=rf.get(e);if(i.renderId===t)return i.lightsData}const n=this.getLightsData(e.getLights());return rf.set(e,{renderId:t,lightsData:n}),n}needsRefresh(e,t){if(this.hasNode||this.hasAnimation||this.firstInitialization(e)||this.needsVelocity(t.renderer))return!0;const{renderId:n}=t;if(this.renderId!==n)return this.renderId=n,!0;const i=e.object.static===!0,s=e.bundle!==null&&e.bundle.static===!0&&this.getRenderObjectData(e).version===e.bundle.version;if(i||s)return!1;const o=this.getLights(e.lightsNode,n);return this.equals(e,o,n)!==!0}}const PN=[/^StackTrace\.js$/,/^TSLCore\.js$/,/^.*Node\.js$/,/^three\.webgpu.*\.js$/];function DN(r){const e=/(?:at\s+(.+?)\s+\()?(?:(.+?)@)?([^@\s()]+):(\d+):(\d+)/;return r.split(`
4622
4622
  `).map(t=>{const n=t.match(e);if(!n)return null;const i=n[1]||n[2]||"",s=n[3].split("?")[0],o=parseInt(n[4],10),a=parseInt(n[5],10),l=s.split("/").pop();return{fn:i,file:l,line:o,column:a}}).filter(t=>t&&!PN.some(n=>n.test(t.file)))}class Kn{constructor(e=null){this.isStackTrace=!0,this.stack=DN(e||new Error().stack)}getLocation(){if(this.stack.length===0)return"[Unknown location]";const e=this.stack[0],t=e.fn;return`${t?`"${t}()" at `:""}"${e.file}:${e.line}"`}getError(e){if(this.stack.length===0)return e;const t=this.stack.map(n=>{const i=`${n.file}:${n.line}:${n.column}`;return n.fn?` at ${n.fn} (${i})`:` at ${i}`}).join(`
4623
4623
  `);return`${e}
4624
- ${t}`}}function wm(r,e=0){let t=3735928559^e,n=1103547991^e;if(Array.isArray(r))for(let i=0,s;i<r.length;i++)s=r[i],t=Math.imul(t^s,2654435761),n=Math.imul(n^s,1597334677);else for(let i=0,s;i<r.length;i++)s=r.charCodeAt(i),t=Math.imul(t^s,2654435761),n=Math.imul(n^s,1597334677);return t=Math.imul(t^t>>>16,2246822507),t^=Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507),n^=Math.imul(t^t>>>13,3266489909),4294967296*(2097151&n)+(t>>>0)}const cl=r=>wm(r),Gc=r=>wm(r),Ql=(...r)=>wm(r),LN=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),X_=new WeakMap;function Wy(r){return LN.get(r)}function Sh(r){if(r==null)return null;const e=typeof r;return r.isNode===!0?"node":e==="number"?"float":e==="boolean"?"bool":e==="string"?"string":e==="function"?"shader":r.isVector2===!0?"vec2":r.isVector3===!0?"vec3":r.isVector4===!0?"vec4":r.isMatrix2===!0?"mat2":r.isMatrix3===!0?"mat3":r.isMatrix4===!0?"mat4":r.isColor===!0?"color":r instanceof ArrayBuffer?"ArrayBuffer":null}function Rm(r,...e){const t=r?r.slice(-4):void 0;return e.length===1&&(t==="vec2"?e=[e[0],e[0]]:t==="vec3"?e=[e[0],e[0],e[0]]:t==="vec4"&&(e=[e[0],e[0],e[0],e[0]])),r==="color"?new We(...e):t==="vec2"?new pe(...e):t==="vec3"?new P(...e):t==="vec4"?new rt(...e):t==="mat2"?new vh(...e):t==="mat3"?new Je(...e):t==="mat4"?new pt(...e):r==="bool"?e[0]||!1:r==="float"||r==="int"||r==="uint"?e[0]||0:r==="string"?e[0]||"":r==="ArrayBuffer"?FN(e[0]):null}function $y(r){let e=X_.get(r);return e===void 0&&(e={},X_.set(r,e)),e}function UN(r){let e="";const t=new Uint8Array(r);for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return btoa(e)}function FN(r){return Uint8Array.from(atob(r),e=>e.charCodeAt(0)).buffer}const Pu={VERTEX:"vertex"},Ze={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Fi={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},IN=["fragment","vertex"],sf=["setup","analyze","generate"],of=[...IN,"compute"],ul=["x","y","z","w"],BN={analyze:"setup",generate:"analyze"};let ON=0;class Ve extends Vi{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=Ze.NONE,this.updateBeforeType=Ze.NONE,this.updateAfterType=Ze.NONE,this.version=0,this.name="",this.global=!1,this.parents=!1,this.isNode=!0,this._beforeNodes=null,this._cacheKey=null,this._uuid=null,this._cacheKeyVersion=0,this.id=ON++,this.stackTrace=null,Ve.captureStackTrace===!0&&(this.stackTrace=new Kn)}set needsUpdate(e){e===!0&&this.version++}get uuid(){return this._uuid===null&&(this._uuid=_h.generateUUID()),this._uuid}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this),this}onFrameUpdate(e){return this.onUpdate(e,Ze.FRAME)}onRenderUpdate(e){return this.onUpdate(e,Ze.RENDER)}onObjectUpdate(e){return this.onUpdate(e,Ze.OBJECT)}onReference(e){return this.updateReference=e.bind(this),this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of this._getChildren())yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}_getChildren(e=new Set){const t=[];e.add(this);for(const n of Object.getOwnPropertyNames(this)){const i=this[n];if(!(n.startsWith("_")===!0||e.has(i))){if(Array.isArray(i)===!0)for(let s=0;s<i.length;s++){const o=i[s];o&&o.isNode===!0&&t.push({property:n,index:s,childNode:o})}else if(i&&i.isNode===!0)t.push({property:n,childNode:i});else if(i&&Object.getPrototypeOf(i)===Object.prototype)for(const s in i){if(s.startsWith("_")===!0)continue;const o=i[s];o&&o.isNode===!0&&t.push({property:n,index:s,childNode:o})}}}return t}getCacheKey(e=!1,t=null){if(e=e||this.version!==this._cacheKeyVersion,e===!0||this._cacheKey===null){t===null&&(t=new Set);const n=[];for(const{property:i,childNode:s}of this._getChildren(t))n.push(cl(i.slice(0,-4)),s.getCacheKey(e,t));this._cacheKey=Ql(Gc(n),this.customCacheKey()),this._cacheKeyVersion=this.version}return this._cacheKey}customCacheKey(){return this.id}getScope(){return this}getHash(){return String(this.id)}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getMemberType(){return"void"}getNodeType(e,t=null){const n=e.getDataFromNode(this);let i;return t!==null?(n.typeFromOutput=n.typeFromOutput||{},i=n.typeFromOutput[t],i===void 0&&(i=this.generateNodeType(e,t),n.typeFromOutput[t]=i)):(i=n.type,i===void 0&&(i=this.generateNodeType(e),n.type=i)),i}generateNodeType(e,t=null){const n=e.getNodeProperties(this);return n.outputNode?n.outputNode.getNodeType(e,t):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}getArrayCount(){return null}setup(e){const t=e.getNodeProperties(this);let n=0;for(const i of this.getChildren())t["node"+n++]=i;return t.outputNode||null}analyze(e,t=null){const n=e.increaseUsage(this);if(this.parents===!0){const i=e.getDataFromNode(this,"any");i.stages=i.stages||{},i.stages[e.shaderStage]=i.stages[e.shaderStage]||[],i.stages[e.shaderStage].push(t)}if(n===1){const i=e.getNodeProperties(this);for(const s of Object.values(i))s&&s.isNode===!0&&s.build(e,this)}}generate(e,t){const{outputNode:n}=e.getNodeProperties(this);if(n&&n.isNode===!0)return n.build(e,t)}updateBefore(){ae("Abstract function.")}updateAfter(){ae("Abstract function.")}update(){ae("Abstract function.")}before(e){return this._beforeNodes===null&&(this._beforeNodes=[]),this._beforeNodes.push(e),this}build(e,t=null){const n=this.getShared(e);if(this!==n)return n.build(e,t);if(this._beforeNodes!==null){const l=this._beforeNodes;this._beforeNodes=null;for(const c of l)c.build(e,t);this._beforeNodes=l}const i=e.getDataFromNode(this);i.buildStages=i.buildStages||{},i.buildStages[e.buildStage]=!0;const s=BN[e.buildStage];if(s&&i.buildStages[s]!==!0){const l=e.getBuildStage();e.setBuildStage(s),this.build(e),e.setBuildStage(l)}e.addChain(this);let o=null;const a=e.getBuildStage();if(a==="setup"){e.addNode(this),this.updateReference(e);const l=e.getNodeProperties(this);if(l.initialized!==!0){l.initialized=!0,l.outputNode=this.setup(e)||l.outputNode||null;for(const c of Object.values(l))if(c&&c.isNode===!0){if(c.parents===!0){const u=e.getNodeProperties(c);u.parents=u.parents||[],u.parents.push(this)}c.build(e)}e.addSequentialNode(this)}o=l.outputNode}else if(a==="analyze")this.analyze(e,t);else if(a==="generate"){if(this.generate.length<2){const c=this.getNodeType(e),u=e.getDataFromNode(this);o=u.snippet,o===void 0?u.generated===void 0?(u.generated=!0,o=this.generate(e)||"",u.snippet=o):(ae("Node: Recursion detected.",this),o="/* Recursion detected. */"):u.flowCodes!==void 0&&e.context.nodeBlock!==void 0&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),o=e.format(o,c,t)}else o=this.generate(e,t)||"";o===""&&t!==null&&t!=="void"&&t!=="OutputType"&&(ce(`TSL: Invalid generated code, expected a "${t}".`),o=e.generateConst(t))}return e.removeChain(this),o}getSerializeChildren(){return this._getChildren()}serialize(e){const t=this.getSerializeChildren(),n={};for(const{property:i,index:s,childNode:o}of t)s!==void 0?(n[i]===void 0&&(n[i]=Number.isInteger(s)?[]:{}),n[i][s]=o.toJSON(e.meta).uuid):n[i]=o.toJSON(e.meta).uuid;Object.keys(n).length>0&&(e.inputNodes=n)}deserialize(e){if(e.inputNodes!==void 0){const t=e.meta.nodes;for(const n in e.inputNodes)if(Array.isArray(e.inputNodes[n])){const i=[];for(const s of e.inputNodes[n])i.push(t[s]);this[n]=i}else if(typeof e.inputNodes[n]=="object"){const i={};for(const s in e.inputNodes[n]){const o=e.inputNodes[n][s];i[s]=t[o]}this[n]=i}else{const i=e.inputNodes[n];this[n]=t[i]}}}toJSON(e){const{uuid:t,type:n}=this,i=e===void 0||typeof e=="string";i&&(e={textures:{},images:{},nodes:{}});let s=e.nodes[t];s===void 0&&(s={uuid:t,type:n,meta:e,metadata:{version:4.7,type:"Node",generator:"Node.toJSON"}},i!==!0&&(e.nodes[s.uuid]=s),this.serialize(s),delete s.meta);function o(a){const l=[];for(const c in a){const u=a[c];delete u.metadata,l.push(u)}return l}if(i){const a=o(e.textures),l=o(e.images),c=o(e.nodes);a.length>0&&(s.textures=a),l.length>0&&(s.images=l),c.length>0&&(s.nodes=c)}return s}}Ve.captureStackTrace=!1;class hl extends Ve{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}generateNodeType(e){return this.node.getElementType(e)}getMemberType(e,t){return this.node.getMemberType(e,t)}generate(e){const t=this.indexNode.getNodeType(e),n=this.node.build(e),i=this.indexNode.build(e,!e.isVector(t)&&e.isInteger(t)?t:"uint");return`${n}[ ${i} ]`}}class Xy extends Ve{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}generateNodeType(e){const t=this.node.getNodeType(e);let n=null;for(const i of this.convertTo.split("|"))(n===null||e.getTypeLength(t)===e.getTypeLength(i))&&(n=i);return n}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const n=this.node,i=this.getNodeType(e),s=n.build(e,i);return e.format(s,i,t)}}class xn extends Ve{static get type(){return"TempNode"}constructor(e=null){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if(e.getBuildStage()==="generate"){const i=e.getVectorType(this.getNodeType(e,t)),s=e.getDataFromNode(this);if(s.propertyName!==void 0)return e.format(s.propertyName,i,t);if(i!=="void"&&t!=="void"&&this.hasDependencies(e)){const o=super.build(e,i),a=e.getVarFromNode(this,null,i),l=e.getPropertyName(a);return e.addLineFlowCode(`${l} = ${o}`,this),s.snippet=o,s.propertyName=l,e.format(s.propertyName,i,t)}}return super.build(e,t)}}class kN extends xn{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}generateNodeType(e){return this.nodeType!==null?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce((t,n)=>t+e.getTypeLength(n.getNodeType(e)),0))}generate(e,t){const n=this.getNodeType(e),i=e.getTypeLength(n),s=this.nodes,o=e.getComponentType(n),a=[];let l=0;for(const u of s){if(l>=i){ce(`TSL: Length of parameters exceeds maximum length of function '${n}()' type.`,this.stackTrace);break}let h=u.getNodeType(e),d=e.getTypeLength(h),f;if(l+d>i&&(ce(`TSL: Length of '${n}()' data exceeds maximum length of output type.`,this.stackTrace),d=i-l,h=e.getTypeFromLength(d)),l+=d,f=u.build(e,h),e.getComponentType(h)!==o){const g=e.getTypeFromLength(d,o);f=e.format(f,h,g)}a.push(f)}const c=`${e.getType(n)}( ${a.join(", ")} )`;return e.format(c,n,t)}}const GN=ul.join("");class VN extends Ve{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(ul.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}generateNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}getScope(){return this.node.getScope()}generate(e,t){const n=this.node,i=e.getTypeLength(n.getNodeType(e));let s=null;if(i>1){let o=null;this.getVectorLength()>=i&&(o=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const l=n.build(e,o);this.components.length===i&&this.components===GN.slice(0,this.components.length)?s=e.format(l,o,t):s=e.format(`${l}.${this.components}`,this.getNodeType(e),t)}else s=n.build(e,t);return s}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class zN extends xn{static get type(){return"SetNode"}constructor(e,t,n){super(),this.sourceNode=e,this.components=t,this.targetNode=n}generateNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:n,targetNode:i}=this,s=this.getNodeType(e),o=e.getComponentType(i.getNodeType(e)),a=e.getTypeFromLength(n.length,o),l=i.build(e,a),c=t.build(e,s),u=e.getTypeLength(s),h=[];for(let d=0;d<u;d++){const f=ul[d];f===n[0]?(h.push(l),d+=n.length-1):h.push(c+"."+f)}return`${e.getType(s)}( ${h.join(", ")} )`}}class HN extends xn{static get type(){return"FlipNode"}constructor(e,t){super(),this.sourceNode=e,this.components=t}generateNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{components:t,sourceNode:n}=this,i=this.getNodeType(e),s=n.build(e),o=e.getVarFromNode(this),a=e.getPropertyName(o);e.addLineFlowCode(a+" = "+s,this);const l=e.getTypeLength(i),c=[];let u=0;for(let h=0;h<l;h++){const d=ul[h];d===t[u]?(c.push("1.0 - "+(a+"."+d)),u++):c.push(a+"."+d)}return`${e.getType(i)}( ${c.join(", ")} )`}}class Cm extends Ve{static get type(){return"InputNode"}constructor(e,t=null){super(t),this.isInputNode=!0,this.value=e,this.precision=null}generateNodeType(){return this.nodeType===null?Sh(this.value):this.nodeType}getInputType(e){return this.getNodeType(e)}setPrecision(e){return this.precision=e,this}serialize(e){super.serialize(e),e.value=this.value,this.value&&this.value.toArray&&(e.value=this.value.toArray()),e.valueType=Sh(this.value),e.nodeType=this.nodeType,e.valueType==="ArrayBuffer"&&(e.value=UN(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?Rm(e.valueType,...e.value):e.value,this.precision=e.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(e.value))}generate(){ae("Abstract function.")}}const q_=/float|u?int/;class Rr extends Cm{static get type(){return"ConstNode"}constructor(e,t=null){super(e,t),this.isConstNode=!0}generateConst(e){return e.generateConst(this.getNodeType(e),this.value)}generate(e,t){const n=this.getNodeType(e);return q_.test(n)&&q_.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),n,t)}}class WN extends Ve{static get type(){return"MemberNode"}constructor(e,t){super(),this.structNode=e,this.property=t,this.isMemberNode=!0}hasMember(e){return this.structNode.isMemberNode&&this.structNode.hasMember(e)===!1?!1:this.structNode.getMemberType(e,this.property)!=="void"}generateNodeType(e){return this.hasMember(e)===!1?"float":this.structNode.getMemberType(e,this.property)}getMemberType(e,t){if(this.hasMember(e)===!1)return"float";const n=this.getNodeType(e);return e.getStructTypeNode(n).getMemberType(e,t)}generate(e){if(this.hasMember(e)===!1){ae(`TSL: Member "${this.property}" does not exist in struct.`,this.stackTrace);const n=this.getNodeType(e);return e.generateConst(n)}return this.structNode.build(e)+"."+this.property}}let yo=null;const fp=new Map;function ee(r,e){if(fp.has(r)){ae(`TSL: Redefinition of method chaining '${r}'.`);return}if(typeof e!="function")throw new Error(`THREE.TSL: Node element ${r} is not a function`);fp.set(r,e),r!=="assign"&&(Ve.prototype[r]=function(...t){return this.isStackNode?this.addToStack(e(...t)):e(this,...t)},Ve.prototype[r+"Assign"]=function(...t){return this.isStackNode?this.assign(t[0],e(...t)):this.assign(e(this,...t))})}const $N=r=>r.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),j_=r=>$N(r).split("").sort().join("");Ve.prototype.assign=function(...r){if(this.isStackNode!==!0)return yo!==null?yo.assign(this,...r):ce("TSL: No stack defined for assign operation. Make sure the assign is inside a Fn().",new Kn),this;{const e=fp.get("assign");return this.addToStack(e(...r))}};Ve.prototype.toVarIntent=function(){return this};Ve.prototype.get=function(r){return new WN(this,r)};const Jl={};function Du(r,e,t){Jl[r]=Jl[e]=Jl[t]={get(){this._cache=this._cache||{};let o=this._cache[r];return o===void 0&&(o=new VN(this,r),this._cache[r]=o),o},set(o){this[r].assign(Ge(o))}};const n=r.toUpperCase(),i=e.toUpperCase(),s=t.toUpperCase();Ve.prototype["set"+n]=Ve.prototype["set"+i]=Ve.prototype["set"+s]=function(o){const a=j_(r);return new zN(this,a,Ge(o))},Ve.prototype["flip"+n]=Ve.prototype["flip"+i]=Ve.prototype["flip"+s]=function(){const o=j_(r);return new HN(this,o)}}const ir=["x","y","z","w"],rr=["r","g","b","a"],sr=["s","t","p","q"];for(let r=0;r<4;r++){let e=ir[r],t=rr[r],n=sr[r];Du(e,t,n);for(let i=0;i<4;i++){e=ir[r]+ir[i],t=rr[r]+rr[i],n=sr[r]+sr[i],Du(e,t,n);for(let s=0;s<4;s++){e=ir[r]+ir[i]+ir[s],t=rr[r]+rr[i]+rr[s],n=sr[r]+sr[i]+sr[s],Du(e,t,n);for(let o=0;o<4;o++)e=ir[r]+ir[i]+ir[s]+ir[o],t=rr[r]+rr[i]+rr[s]+rr[o],n=sr[r]+sr[i]+sr[s]+sr[o],Du(e,t,n)}}}for(let r=0;r<32;r++)Jl[r]={get(){this._cache=this._cache||{};let e=this._cache[r];return e===void 0&&(e=new hl(this,new Rr(r,"uint")),this._cache[r]=e),e},set(e){this[r].assign(Ge(e))}};Object.defineProperties(Ve.prototype,Jl);const Y_=new WeakMap,XN=function(r,e=null){const t=Sh(r);return t==="node"?r:e===null&&(t==="float"||t==="boolean")||t&&t!=="shader"&&t!=="string"?Ge(pp(r,e)):t==="shader"?r.isFn?r:re(r):r},qN=function(r,e=null){for(const t in r)r[t]=Ge(r[t],e);return r},jN=function(r,e=null){const t=r.length;for(let n=0;n<t;n++)r[n]=Ge(r[n],e);return r},qy=function(r,e=null,t=null,n=null){function i(u){return n!==null?(u=Ge(Object.assign(u,n)),n.intent===!0&&(u=u.toVarIntent())):u=Ge(u),u}let s,o=e,a,l;function c(u){let h;return o?h=/[a-z]/i.test(o)?o+"()":o:h=r.type,a!==void 0&&u.length<a?(ce(`TSL: "${h}" parameter length is less than minimum required.`,new Kn),u.concat(new Array(a-u.length).fill(0))):l!==void 0&&u.length>l?(ce(`TSL: "${h}" parameter length exceeds limit.`,new Kn),u.slice(0,l)):u}return e===null?s=(...u)=>i(new r(...ya(c(u)))):t!==null?(t=Ge(t),s=(...u)=>i(new r(e,...ya(c(u)),t))):s=(...u)=>i(new r(e,...ya(c(u)))),s.setParameterLength=(...u)=>(u.length===1?a=l=u[0]:u.length===2&&([a,l]=u),s),s.setName=u=>(o=u,s),s},YN=function(r,...e){return new r(...ya(e))};class KN extends Ve{constructor(e,t){super(),this.shaderNode=e,this.rawInputs=t,this.isShaderCallNodeInternal=!0}generateNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}getElementType(e){return this.getOutputNode(e).getElementType(e)}getMemberType(e,t){return this.getOutputNode(e).getMemberType(e,t)}call(e){const{shaderNode:t,rawInputs:n}=this,i=e.getNodeProperties(t),s=e.getClosestSubBuild(t.subBuilds)||"",o=s||"default";if(i[o])return i[o];const a=e.subBuildFn,l=e.fnCall;e.subBuildFn=s,e.fnCall=this;let c=null;if(t.layout){let u=Y_.get(e.constructor);u===void 0&&(u=new WeakMap,Y_.set(e.constructor,u));let h=u.get(t);h===void 0&&(h=Ge(e.buildFunctionNode(t)),u.set(t,h)),e.addInclude(h);const d=n?ZN(n):null;c=Ge(h.call(d))}else{const u=new Proxy(e,{get:(g,m,_)=>{let x;return Symbol.iterator===m?x=function*(){yield void 0}:x=Reflect.get(g,m,_),x}}),h=n?QN(n):null,d=Array.isArray(n)?n.length>0:n!==null,f=t.jsFunc,p=d||f.length>1?f(h,u):f(u);c=Ge(p)}return e.subBuildFn=a,e.fnCall=l,t.once&&(i[o]=c),c}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}getOutputNode(e){const t=e.getNodeProperties(this),n=e.getSubBuildOutput(this);return t[n]=t[n]||this.setupOutput(e),t[n].subBuild=e.getClosestSubBuild(this),t[n]}build(e,t=null){let n=null;const i=e.getBuildStage(),s=e.getNodeProperties(this),o=e.getSubBuildOutput(this),a=this.getOutputNode(e),l=e.fnCall;if(e.fnCall=this,i==="setup"){const c=e.getSubBuildProperty("initialized",this);if(s[c]!==!0&&(s[c]=!0,s[o]=this.getOutputNode(e),s[o].build(e),this.shaderNode.subBuilds))for(const u of e.chaining){const h=e.getDataFromNode(u,"any");h.subBuilds=h.subBuilds||new Set;for(const d of this.shaderNode.subBuilds)h.subBuilds.add(d)}n=s[o]}else i==="analyze"?a.build(e,t):i==="generate"&&(n=a.build(e,t)||"");return e.fnCall=l,n}}function ZN(r){let e;return Lm(r),r[0]&&(r[0].isNode||Object.getPrototypeOf(r[0])!==Object.prototype)?e=[...r]:e=r[0],e}function QN(r){let e=0;return Lm(r),new Proxy(r,{get:(t,n,i)=>{let s;if(n==="length")return s=r.length,s;if(Symbol.iterator===n)s=function*(){for(const o of r)yield Ge(o)};else{if(r.length>0)if(Object.getPrototypeOf(r[0])===Object.prototype){const o=r[0];o[n]===void 0?s=o[e++]:s=Reflect.get(o,n,i)}else r[0]instanceof Ve&&(r[n]===void 0?s=r[e++]:s=Reflect.get(r,n,i));else s=Reflect.get(t,n,i);s=Ge(s)}return s}})}class JN extends Ve{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}getLayout(){return this.layout}call(e=null){return new KN(this,e)}setup(){return this.call()}}const e1=[!1,!0],t1=[0,1,2,3],n1=[-1,-2],jy=[.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],Nm=new Map;for(const r of e1)Nm.set(r,new Rr(r));const Pm=new Map;for(const r of t1)Pm.set(r,new Rr(r,"uint"));const Dm=new Map([...Pm].map(r=>new Rr(r.value,"int")));for(const r of n1)Dm.set(r,new Rr(r,"int"));const Hh=new Map([...Dm].map(r=>new Rr(r.value)));for(const r of jy)Hh.set(r,new Rr(r));for(const r of jy)Hh.set(-r,new Rr(-r));const Wh={bool:Nm,uint:Pm,ints:Dm,float:Hh},K_=new Map([...Nm,...Hh]),pp=(r,e)=>K_.has(r)?K_.get(r):r.isNode===!0?r:new Rr(r,e),yn=function(r,e=null){return(...t)=>{for(const i of t)if(i===void 0)return ce(`TSL: Invalid parameter for the type "${r}".`,new Kn),new Rr(0,r);if((t.length===0||!["bool","float","int","uint"].includes(r)&&t.every(i=>{const s=typeof i;return s!=="object"&&s!=="function"}))&&(t=[Rm(r,...t)]),t.length===1&&e!==null&&e.has(t[0]))return Lu(e.get(t[0]));if(t.length===1){const i=pp(t[0],r);return i.nodeType===r?Lu(i):Lu(new Xy(i,r))}const n=t.map(i=>pp(i));return Lu(new kN(n,r))}};function mp(r){return r&&r.isNode&&r.traverse(e=>{e.isConstNode&&(r=e.value)}),!!r}const i1=r=>r!=null?r.nodeType||r.convertTo||(typeof r=="string"?r:null):null;function Wl(r,e){return new JN(r,e)}const Ge=(r,e=null)=>XN(r,e),Lu=(r,e=null)=>Ge(r,e).toVarIntent(),Lm=(r,e=null)=>new qN(r,e),ya=(r,e=null)=>new jN(r,e),It=(r,e=null,t=null,n=null)=>new qy(r,e,t,n),be=(r,...e)=>new YN(r,...e),we=(r,e=null,t=null,n={})=>new qy(r,e,t,{...n,intent:!0});let r1=0;class s1 extends Ve{constructor(e,t=null){super();let n=null;t!==null&&(typeof t=="object"?n=t.return:(typeof t=="string"?n=t:ce("TSL: Invalid layout type.",new Kn),t=null)),this.shaderNode=new Wl(e,n),t!==null&&this.setLayout(t),this.isFn=!0}setLayout(e){const t=this.shaderNode.nodeType;if(typeof e.inputs!="object"){const n={name:"fn"+r1++,type:t,inputs:[]};for(const i in e)i!=="return"&&n.inputs.push({name:i,type:e[i]});e=n}return this.shaderNode.setLayout(e),this}generateNodeType(e){return this.shaderNode.getNodeType(e)||"float"}call(...e){const t=this.shaderNode.call(e);return this.shaderNode.nodeType==="void"&&t.toStack(),t.toVarIntent()}once(e=null){return this.shaderNode.once=!0,this.shaderNode.subBuilds=e,this}generate(e){const t=this.getNodeType(e);return ce('TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".',this.stackTrace),e.generateConst(t)}}function re(r,e=null){const t=new s1(r,e);return new Proxy(()=>{},{apply(n,i,s){return t.call(...s)},get(n,i,s){return Reflect.get(t,i,s)},set(n,i,s,o){return Reflect.set(t,i,s,o)}})}const Th=r=>{yo=r},Yy=()=>yo,Ft=(...r)=>yo.If(...r);function Ky(r){return yo&&yo.addToStack(r),r}ee("toStack",Ky);const o1=new yn("color"),J=new yn("float",Wh.float),Zt=new yn("int",Wh.ints),mt=new yn("uint",Wh.uint),$h=new yn("bool",Wh.bool),ke=new yn("vec2"),dr=new yn("ivec2"),Zy=new yn("uvec2"),a1=new yn("bvec2"),te=new yn("vec3"),Qy=new yn("ivec3"),Jy=new yn("uvec3"),l1=new yn("bvec3"),et=new yn("vec4"),ev=new yn("ivec4"),tv=new yn("uvec4"),c1=new yn("bvec4"),Um=new yn("mat2"),On=new yn("mat3"),uo=new yn("mat4");ee("toColor",o1);ee("toFloat",J);ee("toInt",Zt);ee("toUint",mt);ee("toBool",$h);ee("toVec2",ke);ee("toIVec2",dr);ee("toUVec2",Zy);ee("toBVec2",a1);ee("toVec3",te);ee("toIVec3",Qy);ee("toUVec3",Jy);ee("toBVec3",l1);ee("toVec4",et);ee("toIVec4",ev);ee("toUVec4",tv);ee("toBVec4",c1);ee("toMat2",Um);ee("toMat3",On);ee("toMat4",uo);const u1=It(hl).setParameterLength(2),h1=(r,e)=>new Xy(Ge(r),e);ee("element",u1);ee("convert",h1);ee("append",r=>(ae("TSL: .append() has been renamed to .toStack().",new Kn),Ky(r)));class Et extends Ve{static get type(){return"PropertyNode"}constructor(e,t=null,n=!1){super(e),this.name=t,this.varying=n,this.isPropertyNode=!0,this.global=!0}customCacheKey(){return cl(this.type+":"+(this.name||"")+":"+(this.varying?"1":"0"))}getHash(e){return this.name||super.getHash(e)}generate(e){let t;return this.varying===!0?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const Ns=(r,e)=>new Et(r,e),Mh=(r,e)=>new Et(r,e,!0),Pt=be(Et,"vec4","DiffuseColor"),ca=be(Et,"vec3","DiffuseContribution"),Z_=be(Et,"vec3","EmissiveColor"),Wr=be(Et,"float","Roughness"),bs=be(Et,"float","Metalness"),gp=be(Et,"float","Clearcoat"),ec=be(Et,"float","ClearcoatRoughness"),Ci=be(Et,"vec3","Sheen"),ro=be(Et,"float","SheenRoughness"),Fm=be(Et,"float","Iridescence"),_p=be(Et,"float","IridescenceIOR"),xp=be(Et,"float","IridescenceThickness"),yp=be(Et,"float","AlphaT"),to=be(Et,"float","Anisotropy"),ch=be(Et,"vec3","AnisotropyT"),va=be(Et,"vec3","AnisotropyB"),vo=be(Et,"color","SpecularColor"),ha=be(Et,"color","SpecularColorBlended"),da=be(Et,"float","SpecularF90"),vp=be(Et,"float","Shininess"),tc=be(Et,"vec4","Output"),af=be(Et,"float","dashSize"),Q_=be(Et,"float","gapSize"),uh=be(Et,"float","IOR"),bp=be(Et,"float","Transmission"),nv=be(Et,"float","Thickness"),iv=be(Et,"float","AttenuationDistance"),rv=be(Et,"color","AttenuationColor"),sv=be(Et,"float","Dispersion");class ov extends Ve{static get type(){return"UniformGroupNode"}constructor(e,t=!1,n=1,i=null){super("string"),this.name=e,this.shared=t,this.order=n,this.updateType=i,this.isUniformGroup=!0}update(){this.needsUpdate=!0}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const d1=(r,e=1,t=null)=>new ov(r,!1,e,t),Im=(r,e=0,t=null)=>new ov(r,!0,e,t);Ze.FRAME;const Ke=Im("render",0,Ze.RENDER),f1=d1("object",1,Ze.OBJECT);class Vc extends Cm{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=f1}setName(e){return this.name=e,this}label(e){return ae('TSL: "label()" has been deprecated. Use "setName()" instead.',new Kn),this.setName(e)}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){return e=e.bind(this),super.onUpdate(n=>{const i=e(n,this);i!==void 0&&(this.value=i)},t)}getInputType(e){let t=super.getInputType(e);return t==="bool"&&(t="uint"),t}generate(e,t){const n=this.getNodeType(e),i=this.getUniformHash(e);let s=e.getNodeFromHash(i);s===void 0&&(e.setHashNode(this,i),s=this);const o=s.getInputType(e),a=e.getUniformFromNode(s,o,e.shaderStage,this.name||e.context.nodeName),l=e.getPropertyName(a);e.context.nodeName!==void 0&&delete e.context.nodeName;let c=l;if(n==="bool"){const u=e.getDataFromNode(this);let h=u.propertyName;if(h===void 0){const d=e.getVarFromNode(this,null,"bool");h=e.getPropertyName(d),u.propertyName=h,c=e.format(l,o,n),e.addLineFlowCode(`${h} = ${c}`,this)}c=h}return e.format(c,n,t)}}const qe=(r,e)=>{const t=i1(e||r);if(t===r&&(r=Rm(t)),r&&r.isNode===!0){let n=r.value;r.traverse(i=>{i.isConstNode===!0&&(n=i.value)}),r=n}return new Vc(r,t)};class J_ extends xn{static get type(){return"ArrayNode"}constructor(e,t,n=null){super(e),this.count=t,this.values=n,this.isArrayNode=!0}getArrayCount(){return this.count}generateNodeType(e){return this.nodeType===null?this.values[0].getNodeType(e):this.nodeType}getElementType(e){return this.getNodeType(e)}getMemberType(e,t){return this.nodeType===null?this.values[0].getMemberType(e,t):super.getMemberType(e,t)}generate(e){const t=this.getNodeType(e);return e.generateArray(t,this.count,this.values)}}const p1=(...r)=>{let e;if(r.length===1){const t=r[0];e=new J_(null,t.length,t)}else{const t=r[0],n=r[1];e=new J_(t,n)}return Ge(e)};ee("toArray",(r,e)=>p1(Array(e).fill(r)));class m1 extends xn{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t,this.isAssignNode=!0}hasDependencies(){return!1}generateNodeType(e,t){return t!=="void"?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(e.isAvailable("swizzleAssign")===!1&&t.isSplitNode&&t.components.length>1){const n=e.getTypeLength(t.node.getNodeType(e));return ul.join("").slice(0,n)!==t.components}return!1}setup(e){const{targetNode:t,sourceNode:n}=this,i=t.getScope(),s=e.getDataFromNode(i);s.assign=!0;const o=e.getNodeProperties(this);o.sourceNode=n,o.targetNode=t.context({assign:!0})}generate(e,t){const{targetNode:n,sourceNode:i}=e.getNodeProperties(this),s=this.needsSplitAssign(e),o=n.build(e),a=n.getNodeType(e),l=i.build(e,a),c=i.getNodeType(e),u=e.getDataFromNode(this);let h;if(u.initialized===!0)t!=="void"&&(h=o);else if(s){const d=e.getVarFromNode(this,null,a),f=e.getPropertyName(d);e.addLineFlowCode(`${f} = ${l}`,this);const p=n.node,m=p.node.context({assign:!0}).build(e);for(let _=0;_<p.components.length;_++){const x=p.components[_];e.addLineFlowCode(`${m}.${x} = ${f}[ ${_} ]`,this)}t!=="void"&&(h=o)}else h=`${o} = ${l}`,(t==="void"||c==="void")&&(e.addLineFlowCode(h,this),t!=="void"&&(h=o));return u.initialized=!0,e.format(h,a,t)}}const g1=It(m1).setParameterLength(2);ee("assign",g1);class _1 extends xn{static get type(){return"FunctionCallNode"}constructor(e=null,t={}){super(),this.functionNode=e,this.parameters=t}setParameters(e){return this.parameters=e,this}getParameters(){return this.parameters}generateNodeType(e){return this.functionNode.getNodeType(e)}getMemberType(e,t){return this.functionNode.getMemberType(e,t)}generate(e){const t=[],n=this.functionNode,i=n.getInputs(e),s=this.parameters,o=(l,c)=>{const u=c.type,h=u==="pointer";let d;return h?d="&"+l.build(e):d=l.build(e,u),d};if(Array.isArray(s)){if(s.length>i.length)ce("TSL: The number of provided parameters exceeds the expected number of inputs in 'Fn()'."),s.length=i.length;else if(s.length<i.length)for(ce("TSL: The number of provided parameters is less than the expected number of inputs in 'Fn()'.");s.length<i.length;)s.push(J(0));for(let l=0;l<s.length;l++)t.push(o(s[l],i[l]))}else for(const l of i){const c=s[l.name];c!==void 0?t.push(o(c,l)):(ce(`TSL: Input '${l.name}' not found in 'Fn()'.`),t.push(o(J(0),l)))}return`${n.build(e,"property")}( ${t.join(", ")} )`}}const x1=(r,...e)=>(e=e.length>1||e[0]&&e[0].isNode===!0?ya(e):Lm(e[0]),new _1(Ge(r),e));ee("call",x1);const y1={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"};class rn extends xn{static get type(){return"OperatorNode"}constructor(e,t,n,...i){if(super(),i.length>0){let s=new rn(e,t,n);for(let o=0;o<i.length-1;o++)s=new rn(e,s,i[o]);t=s,n=i[i.length-1]}this.op=e,this.aNode=t,this.bNode=n,this.isOperatorNode=!0}getOperatorMethod(e,t){return e.getMethod(y1[this.op],t)}generateNodeType(e,t=null){const n=this.op,i=this.aNode,s=this.bNode,o=i.getNodeType(e),a=s?s.getNodeType(e):null;if(o==="void"||a==="void")return t||"void";if(n==="%")return o;if(n==="~"||n==="&"||n==="|"||n==="^"||n===">>"||n==="<<")return e.getIntegerType(o);if(n==="!"||n==="&&"||n==="||"||n==="^^")return"bool";if(n==="=="||n==="!="||n==="<"||n===">"||n==="<="||n===">="){const l=Math.max(e.getTypeLength(o),e.getTypeLength(a));return l>1?`bvec${l}`:"bool"}else{if(e.isMatrix(o)){if(a==="float")return o;if(e.isVector(a))return e.getVectorFromMatrix(o);if(e.isMatrix(a))return o}else if(e.isMatrix(a)){if(o==="float")return a;if(e.isVector(o))return e.getVectorFromMatrix(a)}return e.getTypeLength(a)>e.getTypeLength(o)?a:o}}generate(e,t){const n=this.op,{aNode:i,bNode:s}=this,o=this.getNodeType(e,t);let a=null,l=null;o!=="void"?(a=i.getNodeType(e),l=s?s.getNodeType(e):null,n==="<"||n===">"||n==="<="||n===">="||n==="=="||n==="!="?e.isVector(a)?l=a:e.isVector(l)?a=l:a!==l&&(a=l="float"):n===">>"||n==="<<"?(a=o,l=e.changeComponentType(l,"uint")):n==="%"?(a=o,l=e.isInteger(a)&&e.isInteger(l)?l:a):e.isMatrix(a)?l==="float"?l="float":e.isVector(l)?l=e.getVectorFromMatrix(a):e.isMatrix(l)||(a=l=o):e.isMatrix(l)?a==="float"?a="float":e.isVector(a)?a=e.getVectorFromMatrix(l):a=l=o:a=l=o):a=l=o;const c=i.build(e,a),u=s?s.build(e,l):null,h=e.getFunctionOperator(n);if(t!=="void"){const d=e.renderer.coordinateSystem===ii;if(n==="=="||n==="!="||n==="<"||n===">"||n==="<="||n===">=")return d?e.isVector(a)?e.format(`${this.getOperatorMethod(e,t)}( ${c}, ${u} )`,o,t):e.format(`( ${c} ${n} ${u} )`,o,t):e.format(`( ${c} ${n} ${u} )`,o,t);if(n==="%")return e.isInteger(l)?e.format(`( ${c} % ${u} )`,o,t):e.format(`${this.getOperatorMethod(e,o)}( ${c}, ${u} )`,o,t);if(n==="!"||n==="~")return e.format(`(${n}${c})`,a,t);if(h)return e.format(`${h}( ${c}, ${u} )`,o,t);if(e.isMatrix(a)&&l==="float")return e.format(`( ${u} ${n} ${c} )`,o,t);if(a==="float"&&e.isMatrix(l))return e.format(`${c} ${n} ${u}`,o,t);{let f=`( ${c} ${n} ${u} )`;return!d&&o==="bool"&&e.isVector(a)&&e.isVector(l)&&(f=`all${f}`),e.format(f,o,t)}}else if(a!=="void")return h?e.format(`${h}( ${c}, ${u} )`,o,t):e.isMatrix(a)&&l==="float"?e.format(`${u} ${n} ${c}`,o,t):e.format(`${c} ${n} ${u}`,o,t)}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const fi=we(rn,"+").setParameterLength(2,1/0).setName("add"),oi=we(rn,"-").setParameterLength(2,1/0).setName("sub"),st=we(rn,"*").setParameterLength(2,1/0).setName("mul"),Er=we(rn,"/").setParameterLength(2,1/0).setName("div"),Bm=we(rn,"%").setParameterLength(2).setName("mod"),v1=we(rn,"==").setParameterLength(2).setName("equal"),b1=we(rn,"!=").setParameterLength(2).setName("notEqual"),S1=we(rn,"<").setParameterLength(2).setName("lessThan"),T1=we(rn,">").setParameterLength(2).setName("greaterThan"),M1=we(rn,"<=").setParameterLength(2).setName("lessThanEqual"),E1=we(rn,">=").setParameterLength(2).setName("greaterThanEqual"),A1=we(rn,"&&").setParameterLength(2,1/0).setName("and"),w1=we(rn,"||").setParameterLength(2,1/0).setName("or"),R1=we(rn,"!").setParameterLength(1).setName("not"),C1=we(rn,"^^").setParameterLength(2).setName("xor"),N1=we(rn,"&").setParameterLength(2).setName("bitAnd"),P1=we(rn,"~").setParameterLength(1).setName("bitNot"),D1=we(rn,"|").setParameterLength(2).setName("bitOr"),L1=we(rn,"^").setParameterLength(2).setName("bitXor"),U1=we(rn,"<<").setParameterLength(2).setName("shiftLeft"),F1=we(rn,">>").setParameterLength(2).setName("shiftRight"),I1=re(([r])=>(r.addAssign(1),r)),B1=re(([r])=>(r.subAssign(1),r)),O1=re(([r])=>{const e=Zt(r).toConst();return r.addAssign(1),e}),k1=re(([r])=>{const e=Zt(r).toConst();return r.subAssign(1),e});ee("add",fi);ee("sub",oi);ee("mul",st);ee("div",Er);ee("mod",Bm);ee("equal",v1);ee("notEqual",b1);ee("lessThan",S1);ee("greaterThan",T1);ee("lessThanEqual",M1);ee("greaterThanEqual",E1);ee("and",A1);ee("or",w1);ee("not",R1);ee("xor",C1);ee("bitAnd",N1);ee("bitNot",P1);ee("bitOr",D1);ee("bitXor",L1);ee("shiftLeft",U1);ee("shiftRight",F1);ee("incrementBefore",I1);ee("decrementBefore",B1);ee("increment",O1);ee("decrement",k1);const G1=(r,e)=>(ae('TSL: "modInt()" is deprecated. Use "mod( int( ... ) )" instead.',new Kn),Bm(Zt(r),Zt(e)));ee("modInt",G1);class G extends xn{static get type(){return"MathNode"}constructor(e,t,n=null,i=null){if(super(),(e===G.MAX||e===G.MIN)&&arguments.length>3){let s=new G(e,t,n);for(let o=2;o<arguments.length-1;o++)s=new G(e,s,arguments[o]);t=s,n=arguments[arguments.length-1],i=null}this.method=e,this.aNode=t,this.bNode=n,this.cNode=i,this.isMathNode=!0}getInputType(e){const t=this.aNode.getNodeType(e),n=this.bNode?this.bNode.getNodeType(e):null,i=this.cNode?this.cNode.getNodeType(e):null,s=e.isMatrix(t)?0:e.getTypeLength(t),o=e.isMatrix(n)?0:e.getTypeLength(n),a=e.isMatrix(i)?0:e.getTypeLength(i);return s>o&&s>a?t:o>a?n:a>s?i:t}generateNodeType(e){const t=this.method;return t===G.LENGTH||t===G.DISTANCE||t===G.DOT?"float":t===G.CROSS?"vec3":t===G.ALL||t===G.ANY?"bool":t===G.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):this.getInputType(e)}setup(e){const{aNode:t,bNode:n,method:i}=this;let s=null;if(i===G.ONE_MINUS)s=oi(1,t);else if(i===G.RECIPROCAL)s=Er(1,t);else if(i===G.DIFFERENCE)s=Si(oi(t,n));else if(i===G.TRANSFORM_DIRECTION){let o=t,a=n;e.isMatrix(o.getNodeType(e))?a=et(te(a),0):o=et(te(o),0);const l=st(o,a).xyz;s=br(l)}return s!==null?s:super.setup(e)}generate(e,t){if(e.getNodeProperties(this).outputNode)return super.generate(e,t);let i=this.method;const s=this.getNodeType(e),o=this.getInputType(e),a=this.aNode,l=this.bNode,c=this.cNode,u=e.renderer.coordinateSystem;if(i===G.NEGATE)return e.format("( - "+a.build(e,o)+" )",s,t);{const h=[];return i===G.CROSS?h.push(a.build(e,s),l.build(e,s)):u===ii&&i===G.STEP?h.push(a.build(e,e.getTypeLength(a.getNodeType(e))===1?"float":o),l.build(e,o)):u===ii&&(i===G.MIN||i===G.MAX)?h.push(a.build(e,o),l.build(e,e.getTypeLength(l.getNodeType(e))===1?"float":o)):i===G.REFRACT?h.push(a.build(e,o),l.build(e,o),c.build(e,"float")):i===G.MIX?h.push(a.build(e,o),l.build(e,o),c.build(e,e.getTypeLength(c.getNodeType(e))===1?"float":o)):(u===Tr&&i===G.ATAN&&l!==null&&(i="atan2"),e.shaderStage!=="fragment"&&(i===G.DFDX||i===G.DFDY)&&(ae(`TSL: '${i}' is not supported in the ${e.shaderStage} stage.`,this.stackTrace),i="/*"+i+"*/"),h.push(a.build(e,o)),l!==null&&h.push(l.build(e,o)),c!==null&&h.push(c.build(e,o))),e.format(`${e.getMethod(i,s)}( ${h.join(", ")} )`,s,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}G.ALL="all";G.ANY="any";G.RADIANS="radians";G.DEGREES="degrees";G.EXP="exp";G.EXP2="exp2";G.LOG="log";G.LOG2="log2";G.SQRT="sqrt";G.INVERSE_SQRT="inversesqrt";G.FLOOR="floor";G.CEIL="ceil";G.NORMALIZE="normalize";G.FRACT="fract";G.SIN="sin";G.SINH="sinh";G.COS="cos";G.COSH="cosh";G.TAN="tan";G.TANH="tanh";G.ASIN="asin";G.ASINH="asinh";G.ACOS="acos";G.ACOSH="acosh";G.ATAN="atan";G.ATANH="atanh";G.ABS="abs";G.SIGN="sign";G.LENGTH="length";G.NEGATE="negate";G.ONE_MINUS="oneMinus";G.DFDX="dFdx";G.DFDY="dFdy";G.ROUND="round";G.RECIPROCAL="reciprocal";G.TRUNC="trunc";G.FWIDTH="fwidth";G.TRANSPOSE="transpose";G.DETERMINANT="determinant";G.INVERSE="inverse";G.EQUALS="equals";G.MIN="min";G.MAX="max";G.STEP="step";G.REFLECT="reflect";G.DISTANCE="distance";G.DIFFERENCE="difference";G.DOT="dot";G.CROSS="cross";G.POW="pow";G.TRANSFORM_DIRECTION="transformDirection";G.MIX="mix";G.CLAMP="clamp";G.REFRACT="refract";G.SMOOTHSTEP="smoothstep";G.FACEFORWARD="faceforward";const Om=J(1e-6),V1=J(Math.PI),z1=we(G,G.ALL).setParameterLength(1),H1=we(G,G.ANY).setParameterLength(1),W1=we(G,G.RADIANS).setParameterLength(1),$1=we(G,G.DEGREES).setParameterLength(1),av=we(G,G.EXP).setParameterLength(1),Mc=we(G,G.EXP2).setParameterLength(1),lv=we(G,G.LOG).setParameterLength(1),Yr=we(G,G.LOG2).setParameterLength(1),Ps=we(G,G.SQRT).setParameterLength(1),X1=we(G,G.INVERSE_SQRT).setParameterLength(1),ho=we(G,G.FLOOR).setParameterLength(1),km=we(G,G.CEIL).setParameterLength(1),br=we(G,G.NORMALIZE).setParameterLength(1),Ar=we(G,G.FRACT).setParameterLength(1),bi=we(G,G.SIN).setParameterLength(1),q1=we(G,G.SINH).setParameterLength(1),fr=we(G,G.COS).setParameterLength(1),j1=we(G,G.COSH).setParameterLength(1),Y1=we(G,G.TAN).setParameterLength(1),K1=we(G,G.TANH).setParameterLength(1),Z1=we(G,G.ASIN).setParameterLength(1),Q1=we(G,G.ASINH).setParameterLength(1),cv=we(G,G.ACOS).setParameterLength(1),J1=we(G,G.ACOSH).setParameterLength(1),eP=we(G,G.ATAN).setParameterLength(1,2),tP=we(G,G.ATANH).setParameterLength(1),Si=we(G,G.ABS).setParameterLength(1),uv=we(G,G.SIGN).setParameterLength(1),Kr=we(G,G.LENGTH).setParameterLength(1),hv=we(G,G.NEGATE).setParameterLength(1),nP=we(G,G.ONE_MINUS).setParameterLength(1),dv=we(G,G.DFDX).setParameterLength(1),fv=we(G,G.DFDY).setParameterLength(1),iP=we(G,G.ROUND).setParameterLength(1),rP=we(G,G.RECIPROCAL).setParameterLength(1),sP=we(G,G.TRUNC).setParameterLength(1),pv=we(G,G.FWIDTH).setParameterLength(1),oP=we(G,G.TRANSPOSE).setParameterLength(1),aP=we(G,G.DETERMINANT).setParameterLength(1),lP=we(G,G.INVERSE).setParameterLength(1),Qa=we(G,G.MIN).setParameterLength(2,1/0),kn=we(G,G.MAX).setParameterLength(2,1/0),Ec=we(G,G.STEP).setParameterLength(2),cP=we(G,G.REFLECT).setParameterLength(2),uP=we(G,G.DISTANCE).setParameterLength(2),hP=we(G,G.DIFFERENCE).setParameterLength(2),bo=we(G,G.DOT).setParameterLength(2),So=we(G,G.CROSS).setParameterLength(2),Xh=we(G,G.POW).setParameterLength(2),mv=r=>st(r,r),dP=r=>st(r,r,r),gv=r=>st(r,r,r,r),fP=we(G,G.TRANSFORM_DIRECTION).setParameterLength(2),pP=r=>st(uv(r),Xh(Si(r),1/3)),_v=r=>bo(r,r),Dt=we(G,G.MIX).setParameterLength(3),Fs=(r,e=0,t=1)=>new G(G.CLAMP,Ge(r),Ge(e),Ge(t)),Gm=r=>Fs(r),xv=we(G,G.REFRACT).setParameterLength(3),Qr=we(G,G.SMOOTHSTEP).setParameterLength(3),mP=we(G,G.FACEFORWARD).setParameterLength(3),gP=re(([r])=>{const n=43758.5453,i=bo(r.xy,ke(12.9898,78.233)),s=Bm(i,V1);return Ar(bi(s).mul(n))}),_P=(r,e,t)=>Dt(e,t,r),xP=(r,e,t)=>Qr(e,t,r),yP=(r,e)=>Ec(e,r);ee("all",z1);ee("any",H1);ee("radians",W1);ee("degrees",$1);ee("exp",av);ee("exp2",Mc);ee("log",lv);ee("log2",Yr);ee("sqrt",Ps);ee("inverseSqrt",X1);ee("floor",ho);ee("ceil",km);ee("normalize",br);ee("fract",Ar);ee("sin",bi);ee("sinh",q1);ee("cos",fr);ee("cosh",j1);ee("tan",Y1);ee("tanh",K1);ee("asin",Z1);ee("asinh",Q1);ee("acos",cv);ee("acosh",J1);ee("atan",eP);ee("atanh",tP);ee("abs",Si);ee("sign",uv);ee("length",Kr);ee("lengthSq",_v);ee("negate",hv);ee("oneMinus",nP);ee("dFdx",dv);ee("dFdy",fv);ee("round",iP);ee("reciprocal",rP);ee("trunc",sP);ee("fwidth",pv);ee("min",Qa);ee("max",kn);ee("step",yP);ee("reflect",cP);ee("distance",uP);ee("dot",bo);ee("cross",So);ee("pow",Xh);ee("pow2",mv);ee("pow3",dP);ee("pow4",gv);ee("transformDirection",fP);ee("mix",_P);ee("clamp",Fs);ee("refract",xv);ee("smoothstep",xP);ee("faceForward",mP);ee("difference",hP);ee("saturate",Gm);ee("cbrt",pP);ee("transpose",oP);ee("determinant",aP);ee("inverse",lP);ee("rand",gP);class vP extends Ve{static get type(){return"ConditionalNode"}constructor(e,t,n=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=n}generateNodeType(e){const{ifNode:t,elseNode:n}=e.getNodeProperties(this);if(t===void 0)return e.flowBuildStage(this,"setup"),this.getNodeType(e);const i=t.getNodeType(e);if(n!==null){const s=n.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(i))return s}return i}setup(e){const t=this.condNode,n=this.ifNode.isolate(),i=this.elseNode?this.elseNode.isolate():null,s=e.context.nodeBlock;e.getDataFromNode(n).parentNodeBlock=s,i!==null&&(e.getDataFromNode(i).parentNodeBlock=s);const o=e.context.uniformFlow,a=e.getNodeProperties(this);a.condNode=t,a.ifNode=o?n:n.context({nodeBlock:n}),a.elseNode=i?o?i:i.context({nodeBlock:i}):null}generate(e,t){const n=this.getNodeType(e),i=e.getDataFromNode(this);if(i.nodeProperty!==void 0)return i.nodeProperty;const{condNode:s,ifNode:o,elseNode:a}=e.getNodeProperties(this),l=e.currentFunctionNode,c=t!=="void",u=c?Ns(n).build(e):"";i.nodeProperty=u;const h=s.build(e,"bool");if(e.context.uniformFlow&&a!==null){const p=o.build(e,n),g=a.build(e,n),m=e.getTernary(h,p,g);return e.format(m,n,t)}e.addFlowCode(`
4624
+ ${t}`}}function wm(r,e=0){let t=3735928559^e,n=1103547991^e;if(Array.isArray(r))for(let i=0,s;i<r.length;i++)s=r[i],t=Math.imul(t^s,2654435761),n=Math.imul(n^s,1597334677);else for(let i=0,s;i<r.length;i++)s=r.charCodeAt(i),t=Math.imul(t^s,2654435761),n=Math.imul(n^s,1597334677);return t=Math.imul(t^t>>>16,2246822507),t^=Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507),n^=Math.imul(t^t>>>13,3266489909),4294967296*(2097151&n)+(t>>>0)}const cl=r=>wm(r),Gc=r=>wm(r),Ql=(...r)=>wm(r),LN=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),X_=new WeakMap;function Wy(r){return LN.get(r)}function Sh(r){if(r==null)return null;const e=typeof r;return r.isNode===!0?"node":e==="number"?"float":e==="boolean"?"bool":e==="string"?"string":e==="function"?"shader":r.isVector2===!0?"vec2":r.isVector3===!0?"vec3":r.isVector4===!0?"vec4":r.isMatrix2===!0?"mat2":r.isMatrix3===!0?"mat3":r.isMatrix4===!0?"mat4":r.isColor===!0?"color":r instanceof ArrayBuffer?"ArrayBuffer":null}function Rm(r,...e){const t=r?r.slice(-4):void 0;return e.length===1&&(t==="vec2"?e=[e[0],e[0]]:t==="vec3"?e=[e[0],e[0],e[0]]:t==="vec4"&&(e=[e[0],e[0],e[0],e[0]])),r==="color"?new We(...e):t==="vec2"?new pe(...e):t==="vec3"?new P(...e):t==="vec4"?new rt(...e):t==="mat2"?new vh(...e):t==="mat3"?new Je(...e):t==="mat4"?new pt(...e):r==="bool"?e[0]||!1:r==="float"||r==="int"||r==="uint"?e[0]||0:r==="string"?e[0]||"":r==="ArrayBuffer"?FN(e[0]):null}function $y(r){let e=X_.get(r);return e===void 0&&(e={},X_.set(r,e)),e}function UN(r){let e="";const t=new Uint8Array(r);for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return btoa(e)}function FN(r){return Uint8Array.from(atob(r),e=>e.charCodeAt(0)).buffer}const Pu={VERTEX:"vertex"},Ze={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Ui={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},IN=["fragment","vertex"],sf=["setup","analyze","generate"],of=[...IN,"compute"],ul=["x","y","z","w"],BN={analyze:"setup",generate:"analyze"};let ON=0;class Ve extends Vi{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=Ze.NONE,this.updateBeforeType=Ze.NONE,this.updateAfterType=Ze.NONE,this.version=0,this.name="",this.global=!1,this.parents=!1,this.isNode=!0,this._beforeNodes=null,this._cacheKey=null,this._uuid=null,this._cacheKeyVersion=0,this.id=ON++,this.stackTrace=null,Ve.captureStackTrace===!0&&(this.stackTrace=new Kn)}set needsUpdate(e){e===!0&&this.version++}get uuid(){return this._uuid===null&&(this._uuid=_h.generateUUID()),this._uuid}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this),this}onFrameUpdate(e){return this.onUpdate(e,Ze.FRAME)}onRenderUpdate(e){return this.onUpdate(e,Ze.RENDER)}onObjectUpdate(e){return this.onUpdate(e,Ze.OBJECT)}onReference(e){return this.updateReference=e.bind(this),this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of this._getChildren())yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}_getChildren(e=new Set){const t=[];e.add(this);for(const n of Object.getOwnPropertyNames(this)){const i=this[n];if(!(n.startsWith("_")===!0||e.has(i))){if(Array.isArray(i)===!0)for(let s=0;s<i.length;s++){const o=i[s];o&&o.isNode===!0&&t.push({property:n,index:s,childNode:o})}else if(i&&i.isNode===!0)t.push({property:n,childNode:i});else if(i&&Object.getPrototypeOf(i)===Object.prototype)for(const s in i){if(s.startsWith("_")===!0)continue;const o=i[s];o&&o.isNode===!0&&t.push({property:n,index:s,childNode:o})}}}return t}getCacheKey(e=!1,t=null){if(e=e||this.version!==this._cacheKeyVersion,e===!0||this._cacheKey===null){t===null&&(t=new Set);const n=[];for(const{property:i,childNode:s}of this._getChildren(t))n.push(cl(i.slice(0,-4)),s.getCacheKey(e,t));this._cacheKey=Ql(Gc(n),this.customCacheKey()),this._cacheKeyVersion=this.version}return this._cacheKey}customCacheKey(){return this.id}getScope(){return this}getHash(){return String(this.id)}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getMemberType(){return"void"}getNodeType(e,t=null){const n=e.getDataFromNode(this);let i;return t!==null?(n.typeFromOutput=n.typeFromOutput||{},i=n.typeFromOutput[t],i===void 0&&(i=this.generateNodeType(e,t),n.typeFromOutput[t]=i)):(i=n.type,i===void 0&&(i=this.generateNodeType(e),n.type=i)),i}generateNodeType(e,t=null){const n=e.getNodeProperties(this);return n.outputNode?n.outputNode.getNodeType(e,t):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}getArrayCount(){return null}setup(e){const t=e.getNodeProperties(this);let n=0;for(const i of this.getChildren())t["node"+n++]=i;return t.outputNode||null}analyze(e,t=null){const n=e.increaseUsage(this);if(this.parents===!0){const i=e.getDataFromNode(this,"any");i.stages=i.stages||{},i.stages[e.shaderStage]=i.stages[e.shaderStage]||[],i.stages[e.shaderStage].push(t)}if(n===1){const i=e.getNodeProperties(this);for(const s of Object.values(i))s&&s.isNode===!0&&s.build(e,this)}}generate(e,t){const{outputNode:n}=e.getNodeProperties(this);if(n&&n.isNode===!0)return n.build(e,t)}updateBefore(){ae("Abstract function.")}updateAfter(){ae("Abstract function.")}update(){ae("Abstract function.")}before(e){return this._beforeNodes===null&&(this._beforeNodes=[]),this._beforeNodes.push(e),this}build(e,t=null){const n=this.getShared(e);if(this!==n)return n.build(e,t);if(this._beforeNodes!==null){const l=this._beforeNodes;this._beforeNodes=null;for(const c of l)c.build(e,t);this._beforeNodes=l}const i=e.getDataFromNode(this);i.buildStages=i.buildStages||{},i.buildStages[e.buildStage]=!0;const s=BN[e.buildStage];if(s&&i.buildStages[s]!==!0){const l=e.getBuildStage();e.setBuildStage(s),this.build(e),e.setBuildStage(l)}e.addChain(this);let o=null;const a=e.getBuildStage();if(a==="setup"){e.addNode(this),this.updateReference(e);const l=e.getNodeProperties(this);if(l.initialized!==!0){l.initialized=!0,l.outputNode=this.setup(e)||l.outputNode||null;for(const c of Object.values(l))if(c&&c.isNode===!0){if(c.parents===!0){const u=e.getNodeProperties(c);u.parents=u.parents||[],u.parents.push(this)}c.build(e)}e.addSequentialNode(this)}o=l.outputNode}else if(a==="analyze")this.analyze(e,t);else if(a==="generate"){if(this.generate.length<2){const c=this.getNodeType(e),u=e.getDataFromNode(this);o=u.snippet,o===void 0?u.generated===void 0?(u.generated=!0,o=this.generate(e)||"",u.snippet=o):(ae("Node: Recursion detected.",this),o="/* Recursion detected. */"):u.flowCodes!==void 0&&e.context.nodeBlock!==void 0&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),o=e.format(o,c,t)}else o=this.generate(e,t)||"";o===""&&t!==null&&t!=="void"&&t!=="OutputType"&&(ce(`TSL: Invalid generated code, expected a "${t}".`),o=e.generateConst(t))}return e.removeChain(this),o}getSerializeChildren(){return this._getChildren()}serialize(e){const t=this.getSerializeChildren(),n={};for(const{property:i,index:s,childNode:o}of t)s!==void 0?(n[i]===void 0&&(n[i]=Number.isInteger(s)?[]:{}),n[i][s]=o.toJSON(e.meta).uuid):n[i]=o.toJSON(e.meta).uuid;Object.keys(n).length>0&&(e.inputNodes=n)}deserialize(e){if(e.inputNodes!==void 0){const t=e.meta.nodes;for(const n in e.inputNodes)if(Array.isArray(e.inputNodes[n])){const i=[];for(const s of e.inputNodes[n])i.push(t[s]);this[n]=i}else if(typeof e.inputNodes[n]=="object"){const i={};for(const s in e.inputNodes[n]){const o=e.inputNodes[n][s];i[s]=t[o]}this[n]=i}else{const i=e.inputNodes[n];this[n]=t[i]}}}toJSON(e){const{uuid:t,type:n}=this,i=e===void 0||typeof e=="string";i&&(e={textures:{},images:{},nodes:{}});let s=e.nodes[t];s===void 0&&(s={uuid:t,type:n,meta:e,metadata:{version:4.7,type:"Node",generator:"Node.toJSON"}},i!==!0&&(e.nodes[s.uuid]=s),this.serialize(s),delete s.meta);function o(a){const l=[];for(const c in a){const u=a[c];delete u.metadata,l.push(u)}return l}if(i){const a=o(e.textures),l=o(e.images),c=o(e.nodes);a.length>0&&(s.textures=a),l.length>0&&(s.images=l),c.length>0&&(s.nodes=c)}return s}}Ve.captureStackTrace=!1;class hl extends Ve{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}generateNodeType(e){return this.node.getElementType(e)}getMemberType(e,t){return this.node.getMemberType(e,t)}generate(e){const t=this.indexNode.getNodeType(e),n=this.node.build(e),i=this.indexNode.build(e,!e.isVector(t)&&e.isInteger(t)?t:"uint");return`${n}[ ${i} ]`}}class Xy extends Ve{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}generateNodeType(e){const t=this.node.getNodeType(e);let n=null;for(const i of this.convertTo.split("|"))(n===null||e.getTypeLength(t)===e.getTypeLength(i))&&(n=i);return n}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const n=this.node,i=this.getNodeType(e),s=n.build(e,i);return e.format(s,i,t)}}class xn extends Ve{static get type(){return"TempNode"}constructor(e=null){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if(e.getBuildStage()==="generate"){const i=e.getVectorType(this.getNodeType(e,t)),s=e.getDataFromNode(this);if(s.propertyName!==void 0)return e.format(s.propertyName,i,t);if(i!=="void"&&t!=="void"&&this.hasDependencies(e)){const o=super.build(e,i),a=e.getVarFromNode(this,null,i),l=e.getPropertyName(a);return e.addLineFlowCode(`${l} = ${o}`,this),s.snippet=o,s.propertyName=l,e.format(s.propertyName,i,t)}}return super.build(e,t)}}class kN extends xn{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}generateNodeType(e){return this.nodeType!==null?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce((t,n)=>t+e.getTypeLength(n.getNodeType(e)),0))}generate(e,t){const n=this.getNodeType(e),i=e.getTypeLength(n),s=this.nodes,o=e.getComponentType(n),a=[];let l=0;for(const u of s){if(l>=i){ce(`TSL: Length of parameters exceeds maximum length of function '${n}()' type.`,this.stackTrace);break}let h=u.getNodeType(e),d=e.getTypeLength(h),f;if(l+d>i&&(ce(`TSL: Length of '${n}()' data exceeds maximum length of output type.`,this.stackTrace),d=i-l,h=e.getTypeFromLength(d)),l+=d,f=u.build(e,h),e.getComponentType(h)!==o){const g=e.getTypeFromLength(d,o);f=e.format(f,h,g)}a.push(f)}const c=`${e.getType(n)}( ${a.join(", ")} )`;return e.format(c,n,t)}}const GN=ul.join("");class VN extends Ve{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(ul.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}generateNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}getScope(){return this.node.getScope()}generate(e,t){const n=this.node,i=e.getTypeLength(n.getNodeType(e));let s=null;if(i>1){let o=null;this.getVectorLength()>=i&&(o=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const l=n.build(e,o);this.components.length===i&&this.components===GN.slice(0,this.components.length)?s=e.format(l,o,t):s=e.format(`${l}.${this.components}`,this.getNodeType(e),t)}else s=n.build(e,t);return s}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class zN extends xn{static get type(){return"SetNode"}constructor(e,t,n){super(),this.sourceNode=e,this.components=t,this.targetNode=n}generateNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:n,targetNode:i}=this,s=this.getNodeType(e),o=e.getComponentType(i.getNodeType(e)),a=e.getTypeFromLength(n.length,o),l=i.build(e,a),c=t.build(e,s),u=e.getTypeLength(s),h=[];for(let d=0;d<u;d++){const f=ul[d];f===n[0]?(h.push(l),d+=n.length-1):h.push(c+"."+f)}return`${e.getType(s)}( ${h.join(", ")} )`}}class HN extends xn{static get type(){return"FlipNode"}constructor(e,t){super(),this.sourceNode=e,this.components=t}generateNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{components:t,sourceNode:n}=this,i=this.getNodeType(e),s=n.build(e),o=e.getVarFromNode(this),a=e.getPropertyName(o);e.addLineFlowCode(a+" = "+s,this);const l=e.getTypeLength(i),c=[];let u=0;for(let h=0;h<l;h++){const d=ul[h];d===t[u]?(c.push("1.0 - "+(a+"."+d)),u++):c.push(a+"."+d)}return`${e.getType(i)}( ${c.join(", ")} )`}}class Cm extends Ve{static get type(){return"InputNode"}constructor(e,t=null){super(t),this.isInputNode=!0,this.value=e,this.precision=null}generateNodeType(){return this.nodeType===null?Sh(this.value):this.nodeType}getInputType(e){return this.getNodeType(e)}setPrecision(e){return this.precision=e,this}serialize(e){super.serialize(e),e.value=this.value,this.value&&this.value.toArray&&(e.value=this.value.toArray()),e.valueType=Sh(this.value),e.nodeType=this.nodeType,e.valueType==="ArrayBuffer"&&(e.value=UN(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?Rm(e.valueType,...e.value):e.value,this.precision=e.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(e.value))}generate(){ae("Abstract function.")}}const q_=/float|u?int/;class Rr extends Cm{static get type(){return"ConstNode"}constructor(e,t=null){super(e,t),this.isConstNode=!0}generateConst(e){return e.generateConst(this.getNodeType(e),this.value)}generate(e,t){const n=this.getNodeType(e);return q_.test(n)&&q_.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),n,t)}}class WN extends Ve{static get type(){return"MemberNode"}constructor(e,t){super(),this.structNode=e,this.property=t,this.isMemberNode=!0}hasMember(e){return this.structNode.isMemberNode&&this.structNode.hasMember(e)===!1?!1:this.structNode.getMemberType(e,this.property)!=="void"}generateNodeType(e){return this.hasMember(e)===!1?"float":this.structNode.getMemberType(e,this.property)}getMemberType(e,t){if(this.hasMember(e)===!1)return"float";const n=this.getNodeType(e);return e.getStructTypeNode(n).getMemberType(e,t)}generate(e){if(this.hasMember(e)===!1){ae(`TSL: Member "${this.property}" does not exist in struct.`,this.stackTrace);const n=this.getNodeType(e);return e.generateConst(n)}return this.structNode.build(e)+"."+this.property}}let yo=null;const fp=new Map;function ee(r,e){if(fp.has(r)){ae(`TSL: Redefinition of method chaining '${r}'.`);return}if(typeof e!="function")throw new Error(`THREE.TSL: Node element ${r} is not a function`);fp.set(r,e),r!=="assign"&&(Ve.prototype[r]=function(...t){return this.isStackNode?this.addToStack(e(...t)):e(this,...t)},Ve.prototype[r+"Assign"]=function(...t){return this.isStackNode?this.assign(t[0],e(...t)):this.assign(e(this,...t))})}const $N=r=>r.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),j_=r=>$N(r).split("").sort().join("");Ve.prototype.assign=function(...r){if(this.isStackNode!==!0)return yo!==null?yo.assign(this,...r):ce("TSL: No stack defined for assign operation. Make sure the assign is inside a Fn().",new Kn),this;{const e=fp.get("assign");return this.addToStack(e(...r))}};Ve.prototype.toVarIntent=function(){return this};Ve.prototype.get=function(r){return new WN(this,r)};const Jl={};function Du(r,e,t){Jl[r]=Jl[e]=Jl[t]={get(){this._cache=this._cache||{};let o=this._cache[r];return o===void 0&&(o=new VN(this,r),this._cache[r]=o),o},set(o){this[r].assign(Ge(o))}};const n=r.toUpperCase(),i=e.toUpperCase(),s=t.toUpperCase();Ve.prototype["set"+n]=Ve.prototype["set"+i]=Ve.prototype["set"+s]=function(o){const a=j_(r);return new zN(this,a,Ge(o))},Ve.prototype["flip"+n]=Ve.prototype["flip"+i]=Ve.prototype["flip"+s]=function(){const o=j_(r);return new HN(this,o)}}const ir=["x","y","z","w"],rr=["r","g","b","a"],sr=["s","t","p","q"];for(let r=0;r<4;r++){let e=ir[r],t=rr[r],n=sr[r];Du(e,t,n);for(let i=0;i<4;i++){e=ir[r]+ir[i],t=rr[r]+rr[i],n=sr[r]+sr[i],Du(e,t,n);for(let s=0;s<4;s++){e=ir[r]+ir[i]+ir[s],t=rr[r]+rr[i]+rr[s],n=sr[r]+sr[i]+sr[s],Du(e,t,n);for(let o=0;o<4;o++)e=ir[r]+ir[i]+ir[s]+ir[o],t=rr[r]+rr[i]+rr[s]+rr[o],n=sr[r]+sr[i]+sr[s]+sr[o],Du(e,t,n)}}}for(let r=0;r<32;r++)Jl[r]={get(){this._cache=this._cache||{};let e=this._cache[r];return e===void 0&&(e=new hl(this,new Rr(r,"uint")),this._cache[r]=e),e},set(e){this[r].assign(Ge(e))}};Object.defineProperties(Ve.prototype,Jl);const Y_=new WeakMap,XN=function(r,e=null){const t=Sh(r);return t==="node"?r:e===null&&(t==="float"||t==="boolean")||t&&t!=="shader"&&t!=="string"?Ge(pp(r,e)):t==="shader"?r.isFn?r:re(r):r},qN=function(r,e=null){for(const t in r)r[t]=Ge(r[t],e);return r},jN=function(r,e=null){const t=r.length;for(let n=0;n<t;n++)r[n]=Ge(r[n],e);return r},qy=function(r,e=null,t=null,n=null){function i(u){return n!==null?(u=Ge(Object.assign(u,n)),n.intent===!0&&(u=u.toVarIntent())):u=Ge(u),u}let s,o=e,a,l;function c(u){let h;return o?h=/[a-z]/i.test(o)?o+"()":o:h=r.type,a!==void 0&&u.length<a?(ce(`TSL: "${h}" parameter length is less than minimum required.`,new Kn),u.concat(new Array(a-u.length).fill(0))):l!==void 0&&u.length>l?(ce(`TSL: "${h}" parameter length exceeds limit.`,new Kn),u.slice(0,l)):u}return e===null?s=(...u)=>i(new r(...ya(c(u)))):t!==null?(t=Ge(t),s=(...u)=>i(new r(e,...ya(c(u)),t))):s=(...u)=>i(new r(e,...ya(c(u)))),s.setParameterLength=(...u)=>(u.length===1?a=l=u[0]:u.length===2&&([a,l]=u),s),s.setName=u=>(o=u,s),s},YN=function(r,...e){return new r(...ya(e))};class KN extends Ve{constructor(e,t){super(),this.shaderNode=e,this.rawInputs=t,this.isShaderCallNodeInternal=!0}generateNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}getElementType(e){return this.getOutputNode(e).getElementType(e)}getMemberType(e,t){return this.getOutputNode(e).getMemberType(e,t)}call(e){const{shaderNode:t,rawInputs:n}=this,i=e.getNodeProperties(t),s=e.getClosestSubBuild(t.subBuilds)||"",o=s||"default";if(i[o])return i[o];const a=e.subBuildFn,l=e.fnCall;e.subBuildFn=s,e.fnCall=this;let c=null;if(t.layout){let u=Y_.get(e.constructor);u===void 0&&(u=new WeakMap,Y_.set(e.constructor,u));let h=u.get(t);h===void 0&&(h=Ge(e.buildFunctionNode(t)),u.set(t,h)),e.addInclude(h);const d=n?ZN(n):null;c=Ge(h.call(d))}else{const u=new Proxy(e,{get:(g,m,_)=>{let x;return Symbol.iterator===m?x=function*(){yield void 0}:x=Reflect.get(g,m,_),x}}),h=n?QN(n):null,d=Array.isArray(n)?n.length>0:n!==null,f=t.jsFunc,p=d||f.length>1?f(h,u):f(u);c=Ge(p)}return e.subBuildFn=a,e.fnCall=l,t.once&&(i[o]=c),c}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}getOutputNode(e){const t=e.getNodeProperties(this),n=e.getSubBuildOutput(this);return t[n]=t[n]||this.setupOutput(e),t[n].subBuild=e.getClosestSubBuild(this),t[n]}build(e,t=null){let n=null;const i=e.getBuildStage(),s=e.getNodeProperties(this),o=e.getSubBuildOutput(this),a=this.getOutputNode(e),l=e.fnCall;if(e.fnCall=this,i==="setup"){const c=e.getSubBuildProperty("initialized",this);if(s[c]!==!0&&(s[c]=!0,s[o]=this.getOutputNode(e),s[o].build(e),this.shaderNode.subBuilds))for(const u of e.chaining){const h=e.getDataFromNode(u,"any");h.subBuilds=h.subBuilds||new Set;for(const d of this.shaderNode.subBuilds)h.subBuilds.add(d)}n=s[o]}else i==="analyze"?a.build(e,t):i==="generate"&&(n=a.build(e,t)||"");return e.fnCall=l,n}}function ZN(r){let e;return Lm(r),r[0]&&(r[0].isNode||Object.getPrototypeOf(r[0])!==Object.prototype)?e=[...r]:e=r[0],e}function QN(r){let e=0;return Lm(r),new Proxy(r,{get:(t,n,i)=>{let s;if(n==="length")return s=r.length,s;if(Symbol.iterator===n)s=function*(){for(const o of r)yield Ge(o)};else{if(r.length>0)if(Object.getPrototypeOf(r[0])===Object.prototype){const o=r[0];o[n]===void 0?s=o[e++]:s=Reflect.get(o,n,i)}else r[0]instanceof Ve&&(r[n]===void 0?s=r[e++]:s=Reflect.get(r,n,i));else s=Reflect.get(t,n,i);s=Ge(s)}return s}})}class JN extends Ve{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}getLayout(){return this.layout}call(e=null){return new KN(this,e)}setup(){return this.call()}}const e1=[!1,!0],t1=[0,1,2,3],n1=[-1,-2],jy=[.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],Nm=new Map;for(const r of e1)Nm.set(r,new Rr(r));const Pm=new Map;for(const r of t1)Pm.set(r,new Rr(r,"uint"));const Dm=new Map([...Pm].map(r=>new Rr(r.value,"int")));for(const r of n1)Dm.set(r,new Rr(r,"int"));const Hh=new Map([...Dm].map(r=>new Rr(r.value)));for(const r of jy)Hh.set(r,new Rr(r));for(const r of jy)Hh.set(-r,new Rr(-r));const Wh={bool:Nm,uint:Pm,ints:Dm,float:Hh},K_=new Map([...Nm,...Hh]),pp=(r,e)=>K_.has(r)?K_.get(r):r.isNode===!0?r:new Rr(r,e),yn=function(r,e=null){return(...t)=>{for(const i of t)if(i===void 0)return ce(`TSL: Invalid parameter for the type "${r}".`,new Kn),new Rr(0,r);if((t.length===0||!["bool","float","int","uint"].includes(r)&&t.every(i=>{const s=typeof i;return s!=="object"&&s!=="function"}))&&(t=[Rm(r,...t)]),t.length===1&&e!==null&&e.has(t[0]))return Lu(e.get(t[0]));if(t.length===1){const i=pp(t[0],r);return i.nodeType===r?Lu(i):Lu(new Xy(i,r))}const n=t.map(i=>pp(i));return Lu(new kN(n,r))}};function mp(r){return r&&r.isNode&&r.traverse(e=>{e.isConstNode&&(r=e.value)}),!!r}const i1=r=>r!=null?r.nodeType||r.convertTo||(typeof r=="string"?r:null):null;function Wl(r,e){return new JN(r,e)}const Ge=(r,e=null)=>XN(r,e),Lu=(r,e=null)=>Ge(r,e).toVarIntent(),Lm=(r,e=null)=>new qN(r,e),ya=(r,e=null)=>new jN(r,e),It=(r,e=null,t=null,n=null)=>new qy(r,e,t,n),be=(r,...e)=>new YN(r,...e),we=(r,e=null,t=null,n={})=>new qy(r,e,t,{...n,intent:!0});let r1=0;class s1 extends Ve{constructor(e,t=null){super();let n=null;t!==null&&(typeof t=="object"?n=t.return:(typeof t=="string"?n=t:ce("TSL: Invalid layout type.",new Kn),t=null)),this.shaderNode=new Wl(e,n),t!==null&&this.setLayout(t),this.isFn=!0}setLayout(e){const t=this.shaderNode.nodeType;if(typeof e.inputs!="object"){const n={name:"fn"+r1++,type:t,inputs:[]};for(const i in e)i!=="return"&&n.inputs.push({name:i,type:e[i]});e=n}return this.shaderNode.setLayout(e),this}generateNodeType(e){return this.shaderNode.getNodeType(e)||"float"}call(...e){const t=this.shaderNode.call(e);return this.shaderNode.nodeType==="void"&&t.toStack(),t.toVarIntent()}once(e=null){return this.shaderNode.once=!0,this.shaderNode.subBuilds=e,this}generate(e){const t=this.getNodeType(e);return ce('TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".',this.stackTrace),e.generateConst(t)}}function re(r,e=null){const t=new s1(r,e);return new Proxy(()=>{},{apply(n,i,s){return t.call(...s)},get(n,i,s){return Reflect.get(t,i,s)},set(n,i,s,o){return Reflect.set(t,i,s,o)}})}const Th=r=>{yo=r},Yy=()=>yo,Ft=(...r)=>yo.If(...r);function Ky(r){return yo&&yo.addToStack(r),r}ee("toStack",Ky);const o1=new yn("color"),J=new yn("float",Wh.float),Zt=new yn("int",Wh.ints),mt=new yn("uint",Wh.uint),$h=new yn("bool",Wh.bool),ke=new yn("vec2"),dr=new yn("ivec2"),Zy=new yn("uvec2"),a1=new yn("bvec2"),te=new yn("vec3"),Qy=new yn("ivec3"),Jy=new yn("uvec3"),l1=new yn("bvec3"),et=new yn("vec4"),ev=new yn("ivec4"),tv=new yn("uvec4"),c1=new yn("bvec4"),Um=new yn("mat2"),On=new yn("mat3"),uo=new yn("mat4");ee("toColor",o1);ee("toFloat",J);ee("toInt",Zt);ee("toUint",mt);ee("toBool",$h);ee("toVec2",ke);ee("toIVec2",dr);ee("toUVec2",Zy);ee("toBVec2",a1);ee("toVec3",te);ee("toIVec3",Qy);ee("toUVec3",Jy);ee("toBVec3",l1);ee("toVec4",et);ee("toIVec4",ev);ee("toUVec4",tv);ee("toBVec4",c1);ee("toMat2",Um);ee("toMat3",On);ee("toMat4",uo);const u1=It(hl).setParameterLength(2),h1=(r,e)=>new Xy(Ge(r),e);ee("element",u1);ee("convert",h1);ee("append",r=>(ae("TSL: .append() has been renamed to .toStack().",new Kn),Ky(r)));class Et extends Ve{static get type(){return"PropertyNode"}constructor(e,t=null,n=!1){super(e),this.name=t,this.varying=n,this.isPropertyNode=!0,this.global=!0}customCacheKey(){return cl(this.type+":"+(this.name||"")+":"+(this.varying?"1":"0"))}getHash(e){return this.name||super.getHash(e)}generate(e){let t;return this.varying===!0?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const Ns=(r,e)=>new Et(r,e),Mh=(r,e)=>new Et(r,e,!0),Pt=be(Et,"vec4","DiffuseColor"),ca=be(Et,"vec3","DiffuseContribution"),Z_=be(Et,"vec3","EmissiveColor"),Wr=be(Et,"float","Roughness"),bs=be(Et,"float","Metalness"),gp=be(Et,"float","Clearcoat"),ec=be(Et,"float","ClearcoatRoughness"),Ri=be(Et,"vec3","Sheen"),ro=be(Et,"float","SheenRoughness"),Fm=be(Et,"float","Iridescence"),_p=be(Et,"float","IridescenceIOR"),xp=be(Et,"float","IridescenceThickness"),yp=be(Et,"float","AlphaT"),to=be(Et,"float","Anisotropy"),ch=be(Et,"vec3","AnisotropyT"),va=be(Et,"vec3","AnisotropyB"),vo=be(Et,"color","SpecularColor"),ha=be(Et,"color","SpecularColorBlended"),da=be(Et,"float","SpecularF90"),vp=be(Et,"float","Shininess"),tc=be(Et,"vec4","Output"),af=be(Et,"float","dashSize"),Q_=be(Et,"float","gapSize"),uh=be(Et,"float","IOR"),bp=be(Et,"float","Transmission"),nv=be(Et,"float","Thickness"),iv=be(Et,"float","AttenuationDistance"),rv=be(Et,"color","AttenuationColor"),sv=be(Et,"float","Dispersion");class ov extends Ve{static get type(){return"UniformGroupNode"}constructor(e,t=!1,n=1,i=null){super("string"),this.name=e,this.shared=t,this.order=n,this.updateType=i,this.isUniformGroup=!0}update(){this.needsUpdate=!0}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const d1=(r,e=1,t=null)=>new ov(r,!1,e,t),Im=(r,e=0,t=null)=>new ov(r,!0,e,t);Ze.FRAME;const Ke=Im("render",0,Ze.RENDER),f1=d1("object",1,Ze.OBJECT);class Vc extends Cm{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=f1}setName(e){return this.name=e,this}label(e){return ae('TSL: "label()" has been deprecated. Use "setName()" instead.',new Kn),this.setName(e)}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){return e=e.bind(this),super.onUpdate(n=>{const i=e(n,this);i!==void 0&&(this.value=i)},t)}getInputType(e){let t=super.getInputType(e);return t==="bool"&&(t="uint"),t}generate(e,t){const n=this.getNodeType(e),i=this.getUniformHash(e);let s=e.getNodeFromHash(i);s===void 0&&(e.setHashNode(this,i),s=this);const o=s.getInputType(e),a=e.getUniformFromNode(s,o,e.shaderStage,this.name||e.context.nodeName),l=e.getPropertyName(a);e.context.nodeName!==void 0&&delete e.context.nodeName;let c=l;if(n==="bool"){const u=e.getDataFromNode(this);let h=u.propertyName;if(h===void 0){const d=e.getVarFromNode(this,null,"bool");h=e.getPropertyName(d),u.propertyName=h,c=e.format(l,o,n),e.addLineFlowCode(`${h} = ${c}`,this)}c=h}return e.format(c,n,t)}}const qe=(r,e)=>{const t=i1(e||r);if(t===r&&(r=Rm(t)),r&&r.isNode===!0){let n=r.value;r.traverse(i=>{i.isConstNode===!0&&(n=i.value)}),r=n}return new Vc(r,t)};class J_ extends xn{static get type(){return"ArrayNode"}constructor(e,t,n=null){super(e),this.count=t,this.values=n,this.isArrayNode=!0}getArrayCount(){return this.count}generateNodeType(e){return this.nodeType===null?this.values[0].getNodeType(e):this.nodeType}getElementType(e){return this.getNodeType(e)}getMemberType(e,t){return this.nodeType===null?this.values[0].getMemberType(e,t):super.getMemberType(e,t)}generate(e){const t=this.getNodeType(e);return e.generateArray(t,this.count,this.values)}}const p1=(...r)=>{let e;if(r.length===1){const t=r[0];e=new J_(null,t.length,t)}else{const t=r[0],n=r[1];e=new J_(t,n)}return Ge(e)};ee("toArray",(r,e)=>p1(Array(e).fill(r)));class m1 extends xn{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t,this.isAssignNode=!0}hasDependencies(){return!1}generateNodeType(e,t){return t!=="void"?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(e.isAvailable("swizzleAssign")===!1&&t.isSplitNode&&t.components.length>1){const n=e.getTypeLength(t.node.getNodeType(e));return ul.join("").slice(0,n)!==t.components}return!1}setup(e){const{targetNode:t,sourceNode:n}=this,i=t.getScope(),s=e.getDataFromNode(i);s.assign=!0;const o=e.getNodeProperties(this);o.sourceNode=n,o.targetNode=t.context({assign:!0})}generate(e,t){const{targetNode:n,sourceNode:i}=e.getNodeProperties(this),s=this.needsSplitAssign(e),o=n.build(e),a=n.getNodeType(e),l=i.build(e,a),c=i.getNodeType(e),u=e.getDataFromNode(this);let h;if(u.initialized===!0)t!=="void"&&(h=o);else if(s){const d=e.getVarFromNode(this,null,a),f=e.getPropertyName(d);e.addLineFlowCode(`${f} = ${l}`,this);const p=n.node,m=p.node.context({assign:!0}).build(e);for(let _=0;_<p.components.length;_++){const x=p.components[_];e.addLineFlowCode(`${m}.${x} = ${f}[ ${_} ]`,this)}t!=="void"&&(h=o)}else h=`${o} = ${l}`,(t==="void"||c==="void")&&(e.addLineFlowCode(h,this),t!=="void"&&(h=o));return u.initialized=!0,e.format(h,a,t)}}const g1=It(m1).setParameterLength(2);ee("assign",g1);class _1 extends xn{static get type(){return"FunctionCallNode"}constructor(e=null,t={}){super(),this.functionNode=e,this.parameters=t}setParameters(e){return this.parameters=e,this}getParameters(){return this.parameters}generateNodeType(e){return this.functionNode.getNodeType(e)}getMemberType(e,t){return this.functionNode.getMemberType(e,t)}generate(e){const t=[],n=this.functionNode,i=n.getInputs(e),s=this.parameters,o=(l,c)=>{const u=c.type,h=u==="pointer";let d;return h?d="&"+l.build(e):d=l.build(e,u),d};if(Array.isArray(s)){if(s.length>i.length)ce("TSL: The number of provided parameters exceeds the expected number of inputs in 'Fn()'."),s.length=i.length;else if(s.length<i.length)for(ce("TSL: The number of provided parameters is less than the expected number of inputs in 'Fn()'.");s.length<i.length;)s.push(J(0));for(let l=0;l<s.length;l++)t.push(o(s[l],i[l]))}else for(const l of i){const c=s[l.name];c!==void 0?t.push(o(c,l)):(ce(`TSL: Input '${l.name}' not found in 'Fn()'.`),t.push(o(J(0),l)))}return`${n.build(e,"property")}( ${t.join(", ")} )`}}const x1=(r,...e)=>(e=e.length>1||e[0]&&e[0].isNode===!0?ya(e):Lm(e[0]),new _1(Ge(r),e));ee("call",x1);const y1={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"};class rn extends xn{static get type(){return"OperatorNode"}constructor(e,t,n,...i){if(super(),i.length>0){let s=new rn(e,t,n);for(let o=0;o<i.length-1;o++)s=new rn(e,s,i[o]);t=s,n=i[i.length-1]}this.op=e,this.aNode=t,this.bNode=n,this.isOperatorNode=!0}getOperatorMethod(e,t){return e.getMethod(y1[this.op],t)}generateNodeType(e,t=null){const n=this.op,i=this.aNode,s=this.bNode,o=i.getNodeType(e),a=s?s.getNodeType(e):null;if(o==="void"||a==="void")return t||"void";if(n==="%")return o;if(n==="~"||n==="&"||n==="|"||n==="^"||n===">>"||n==="<<")return e.getIntegerType(o);if(n==="!"||n==="&&"||n==="||"||n==="^^")return"bool";if(n==="=="||n==="!="||n==="<"||n===">"||n==="<="||n===">="){const l=Math.max(e.getTypeLength(o),e.getTypeLength(a));return l>1?`bvec${l}`:"bool"}else{if(e.isMatrix(o)){if(a==="float")return o;if(e.isVector(a))return e.getVectorFromMatrix(o);if(e.isMatrix(a))return o}else if(e.isMatrix(a)){if(o==="float")return a;if(e.isVector(o))return e.getVectorFromMatrix(a)}return e.getTypeLength(a)>e.getTypeLength(o)?a:o}}generate(e,t){const n=this.op,{aNode:i,bNode:s}=this,o=this.getNodeType(e,t);let a=null,l=null;o!=="void"?(a=i.getNodeType(e),l=s?s.getNodeType(e):null,n==="<"||n===">"||n==="<="||n===">="||n==="=="||n==="!="?e.isVector(a)?l=a:e.isVector(l)?a=l:a!==l&&(a=l="float"):n===">>"||n==="<<"?(a=o,l=e.changeComponentType(l,"uint")):n==="%"?(a=o,l=e.isInteger(a)&&e.isInteger(l)?l:a):e.isMatrix(a)?l==="float"?l="float":e.isVector(l)?l=e.getVectorFromMatrix(a):e.isMatrix(l)||(a=l=o):e.isMatrix(l)?a==="float"?a="float":e.isVector(a)?a=e.getVectorFromMatrix(l):a=l=o:a=l=o):a=l=o;const c=i.build(e,a),u=s?s.build(e,l):null,h=e.getFunctionOperator(n);if(t!=="void"){const d=e.renderer.coordinateSystem===ii;if(n==="=="||n==="!="||n==="<"||n===">"||n==="<="||n===">=")return d?e.isVector(a)?e.format(`${this.getOperatorMethod(e,t)}( ${c}, ${u} )`,o,t):e.format(`( ${c} ${n} ${u} )`,o,t):e.format(`( ${c} ${n} ${u} )`,o,t);if(n==="%")return e.isInteger(l)?e.format(`( ${c} % ${u} )`,o,t):e.format(`${this.getOperatorMethod(e,o)}( ${c}, ${u} )`,o,t);if(n==="!"||n==="~")return e.format(`(${n}${c})`,a,t);if(h)return e.format(`${h}( ${c}, ${u} )`,o,t);if(e.isMatrix(a)&&l==="float")return e.format(`( ${u} ${n} ${c} )`,o,t);if(a==="float"&&e.isMatrix(l))return e.format(`${c} ${n} ${u}`,o,t);{let f=`( ${c} ${n} ${u} )`;return!d&&o==="bool"&&e.isVector(a)&&e.isVector(l)&&(f=`all${f}`),e.format(f,o,t)}}else if(a!=="void")return h?e.format(`${h}( ${c}, ${u} )`,o,t):e.isMatrix(a)&&l==="float"?e.format(`${u} ${n} ${c}`,o,t):e.format(`${c} ${n} ${u}`,o,t)}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const fi=we(rn,"+").setParameterLength(2,1/0).setName("add"),oi=we(rn,"-").setParameterLength(2,1/0).setName("sub"),st=we(rn,"*").setParameterLength(2,1/0).setName("mul"),Er=we(rn,"/").setParameterLength(2,1/0).setName("div"),Bm=we(rn,"%").setParameterLength(2).setName("mod"),v1=we(rn,"==").setParameterLength(2).setName("equal"),b1=we(rn,"!=").setParameterLength(2).setName("notEqual"),S1=we(rn,"<").setParameterLength(2).setName("lessThan"),T1=we(rn,">").setParameterLength(2).setName("greaterThan"),M1=we(rn,"<=").setParameterLength(2).setName("lessThanEqual"),E1=we(rn,">=").setParameterLength(2).setName("greaterThanEqual"),A1=we(rn,"&&").setParameterLength(2,1/0).setName("and"),w1=we(rn,"||").setParameterLength(2,1/0).setName("or"),R1=we(rn,"!").setParameterLength(1).setName("not"),C1=we(rn,"^^").setParameterLength(2).setName("xor"),N1=we(rn,"&").setParameterLength(2).setName("bitAnd"),P1=we(rn,"~").setParameterLength(1).setName("bitNot"),D1=we(rn,"|").setParameterLength(2).setName("bitOr"),L1=we(rn,"^").setParameterLength(2).setName("bitXor"),U1=we(rn,"<<").setParameterLength(2).setName("shiftLeft"),F1=we(rn,">>").setParameterLength(2).setName("shiftRight"),I1=re(([r])=>(r.addAssign(1),r)),B1=re(([r])=>(r.subAssign(1),r)),O1=re(([r])=>{const e=Zt(r).toConst();return r.addAssign(1),e}),k1=re(([r])=>{const e=Zt(r).toConst();return r.subAssign(1),e});ee("add",fi);ee("sub",oi);ee("mul",st);ee("div",Er);ee("mod",Bm);ee("equal",v1);ee("notEqual",b1);ee("lessThan",S1);ee("greaterThan",T1);ee("lessThanEqual",M1);ee("greaterThanEqual",E1);ee("and",A1);ee("or",w1);ee("not",R1);ee("xor",C1);ee("bitAnd",N1);ee("bitNot",P1);ee("bitOr",D1);ee("bitXor",L1);ee("shiftLeft",U1);ee("shiftRight",F1);ee("incrementBefore",I1);ee("decrementBefore",B1);ee("increment",O1);ee("decrement",k1);const G1=(r,e)=>(ae('TSL: "modInt()" is deprecated. Use "mod( int( ... ) )" instead.',new Kn),Bm(Zt(r),Zt(e)));ee("modInt",G1);class G extends xn{static get type(){return"MathNode"}constructor(e,t,n=null,i=null){if(super(),(e===G.MAX||e===G.MIN)&&arguments.length>3){let s=new G(e,t,n);for(let o=2;o<arguments.length-1;o++)s=new G(e,s,arguments[o]);t=s,n=arguments[arguments.length-1],i=null}this.method=e,this.aNode=t,this.bNode=n,this.cNode=i,this.isMathNode=!0}getInputType(e){const t=this.aNode.getNodeType(e),n=this.bNode?this.bNode.getNodeType(e):null,i=this.cNode?this.cNode.getNodeType(e):null,s=e.isMatrix(t)?0:e.getTypeLength(t),o=e.isMatrix(n)?0:e.getTypeLength(n),a=e.isMatrix(i)?0:e.getTypeLength(i);return s>o&&s>a?t:o>a?n:a>s?i:t}generateNodeType(e){const t=this.method;return t===G.LENGTH||t===G.DISTANCE||t===G.DOT?"float":t===G.CROSS?"vec3":t===G.ALL||t===G.ANY?"bool":t===G.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):this.getInputType(e)}setup(e){const{aNode:t,bNode:n,method:i}=this;let s=null;if(i===G.ONE_MINUS)s=oi(1,t);else if(i===G.RECIPROCAL)s=Er(1,t);else if(i===G.DIFFERENCE)s=bi(oi(t,n));else if(i===G.TRANSFORM_DIRECTION){let o=t,a=n;e.isMatrix(o.getNodeType(e))?a=et(te(a),0):o=et(te(o),0);const l=st(o,a).xyz;s=br(l)}return s!==null?s:super.setup(e)}generate(e,t){if(e.getNodeProperties(this).outputNode)return super.generate(e,t);let i=this.method;const s=this.getNodeType(e),o=this.getInputType(e),a=this.aNode,l=this.bNode,c=this.cNode,u=e.renderer.coordinateSystem;if(i===G.NEGATE)return e.format("( - "+a.build(e,o)+" )",s,t);{const h=[];return i===G.CROSS?h.push(a.build(e,s),l.build(e,s)):u===ii&&i===G.STEP?h.push(a.build(e,e.getTypeLength(a.getNodeType(e))===1?"float":o),l.build(e,o)):u===ii&&(i===G.MIN||i===G.MAX)?h.push(a.build(e,o),l.build(e,e.getTypeLength(l.getNodeType(e))===1?"float":o)):i===G.REFRACT?h.push(a.build(e,o),l.build(e,o),c.build(e,"float")):i===G.MIX?h.push(a.build(e,o),l.build(e,o),c.build(e,e.getTypeLength(c.getNodeType(e))===1?"float":o)):(u===Tr&&i===G.ATAN&&l!==null&&(i="atan2"),e.shaderStage!=="fragment"&&(i===G.DFDX||i===G.DFDY)&&(ae(`TSL: '${i}' is not supported in the ${e.shaderStage} stage.`,this.stackTrace),i="/*"+i+"*/"),h.push(a.build(e,o)),l!==null&&h.push(l.build(e,o)),c!==null&&h.push(c.build(e,o))),e.format(`${e.getMethod(i,s)}( ${h.join(", ")} )`,s,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}G.ALL="all";G.ANY="any";G.RADIANS="radians";G.DEGREES="degrees";G.EXP="exp";G.EXP2="exp2";G.LOG="log";G.LOG2="log2";G.SQRT="sqrt";G.INVERSE_SQRT="inversesqrt";G.FLOOR="floor";G.CEIL="ceil";G.NORMALIZE="normalize";G.FRACT="fract";G.SIN="sin";G.SINH="sinh";G.COS="cos";G.COSH="cosh";G.TAN="tan";G.TANH="tanh";G.ASIN="asin";G.ASINH="asinh";G.ACOS="acos";G.ACOSH="acosh";G.ATAN="atan";G.ATANH="atanh";G.ABS="abs";G.SIGN="sign";G.LENGTH="length";G.NEGATE="negate";G.ONE_MINUS="oneMinus";G.DFDX="dFdx";G.DFDY="dFdy";G.ROUND="round";G.RECIPROCAL="reciprocal";G.TRUNC="trunc";G.FWIDTH="fwidth";G.TRANSPOSE="transpose";G.DETERMINANT="determinant";G.INVERSE="inverse";G.EQUALS="equals";G.MIN="min";G.MAX="max";G.STEP="step";G.REFLECT="reflect";G.DISTANCE="distance";G.DIFFERENCE="difference";G.DOT="dot";G.CROSS="cross";G.POW="pow";G.TRANSFORM_DIRECTION="transformDirection";G.MIX="mix";G.CLAMP="clamp";G.REFRACT="refract";G.SMOOTHSTEP="smoothstep";G.FACEFORWARD="faceforward";const Om=J(1e-6),V1=J(Math.PI),z1=we(G,G.ALL).setParameterLength(1),H1=we(G,G.ANY).setParameterLength(1),W1=we(G,G.RADIANS).setParameterLength(1),$1=we(G,G.DEGREES).setParameterLength(1),av=we(G,G.EXP).setParameterLength(1),Mc=we(G,G.EXP2).setParameterLength(1),lv=we(G,G.LOG).setParameterLength(1),Yr=we(G,G.LOG2).setParameterLength(1),Ps=we(G,G.SQRT).setParameterLength(1),X1=we(G,G.INVERSE_SQRT).setParameterLength(1),ho=we(G,G.FLOOR).setParameterLength(1),km=we(G,G.CEIL).setParameterLength(1),br=we(G,G.NORMALIZE).setParameterLength(1),Ar=we(G,G.FRACT).setParameterLength(1),vi=we(G,G.SIN).setParameterLength(1),q1=we(G,G.SINH).setParameterLength(1),fr=we(G,G.COS).setParameterLength(1),j1=we(G,G.COSH).setParameterLength(1),Y1=we(G,G.TAN).setParameterLength(1),K1=we(G,G.TANH).setParameterLength(1),Z1=we(G,G.ASIN).setParameterLength(1),Q1=we(G,G.ASINH).setParameterLength(1),cv=we(G,G.ACOS).setParameterLength(1),J1=we(G,G.ACOSH).setParameterLength(1),eP=we(G,G.ATAN).setParameterLength(1,2),tP=we(G,G.ATANH).setParameterLength(1),bi=we(G,G.ABS).setParameterLength(1),uv=we(G,G.SIGN).setParameterLength(1),Kr=we(G,G.LENGTH).setParameterLength(1),hv=we(G,G.NEGATE).setParameterLength(1),nP=we(G,G.ONE_MINUS).setParameterLength(1),dv=we(G,G.DFDX).setParameterLength(1),fv=we(G,G.DFDY).setParameterLength(1),iP=we(G,G.ROUND).setParameterLength(1),rP=we(G,G.RECIPROCAL).setParameterLength(1),sP=we(G,G.TRUNC).setParameterLength(1),pv=we(G,G.FWIDTH).setParameterLength(1),oP=we(G,G.TRANSPOSE).setParameterLength(1),aP=we(G,G.DETERMINANT).setParameterLength(1),lP=we(G,G.INVERSE).setParameterLength(1),Qa=we(G,G.MIN).setParameterLength(2,1/0),kn=we(G,G.MAX).setParameterLength(2,1/0),Ec=we(G,G.STEP).setParameterLength(2),cP=we(G,G.REFLECT).setParameterLength(2),uP=we(G,G.DISTANCE).setParameterLength(2),hP=we(G,G.DIFFERENCE).setParameterLength(2),bo=we(G,G.DOT).setParameterLength(2),So=we(G,G.CROSS).setParameterLength(2),Xh=we(G,G.POW).setParameterLength(2),mv=r=>st(r,r),dP=r=>st(r,r,r),gv=r=>st(r,r,r,r),fP=we(G,G.TRANSFORM_DIRECTION).setParameterLength(2),pP=r=>st(uv(r),Xh(bi(r),1/3)),_v=r=>bo(r,r),Dt=we(G,G.MIX).setParameterLength(3),Fs=(r,e=0,t=1)=>new G(G.CLAMP,Ge(r),Ge(e),Ge(t)),Gm=r=>Fs(r),xv=we(G,G.REFRACT).setParameterLength(3),Qr=we(G,G.SMOOTHSTEP).setParameterLength(3),mP=we(G,G.FACEFORWARD).setParameterLength(3),gP=re(([r])=>{const n=43758.5453,i=bo(r.xy,ke(12.9898,78.233)),s=Bm(i,V1);return Ar(vi(s).mul(n))}),_P=(r,e,t)=>Dt(e,t,r),xP=(r,e,t)=>Qr(e,t,r),yP=(r,e)=>Ec(e,r);ee("all",z1);ee("any",H1);ee("radians",W1);ee("degrees",$1);ee("exp",av);ee("exp2",Mc);ee("log",lv);ee("log2",Yr);ee("sqrt",Ps);ee("inverseSqrt",X1);ee("floor",ho);ee("ceil",km);ee("normalize",br);ee("fract",Ar);ee("sin",vi);ee("sinh",q1);ee("cos",fr);ee("cosh",j1);ee("tan",Y1);ee("tanh",K1);ee("asin",Z1);ee("asinh",Q1);ee("acos",cv);ee("acosh",J1);ee("atan",eP);ee("atanh",tP);ee("abs",bi);ee("sign",uv);ee("length",Kr);ee("lengthSq",_v);ee("negate",hv);ee("oneMinus",nP);ee("dFdx",dv);ee("dFdy",fv);ee("round",iP);ee("reciprocal",rP);ee("trunc",sP);ee("fwidth",pv);ee("min",Qa);ee("max",kn);ee("step",yP);ee("reflect",cP);ee("distance",uP);ee("dot",bo);ee("cross",So);ee("pow",Xh);ee("pow2",mv);ee("pow3",dP);ee("pow4",gv);ee("transformDirection",fP);ee("mix",_P);ee("clamp",Fs);ee("refract",xv);ee("smoothstep",xP);ee("faceForward",mP);ee("difference",hP);ee("saturate",Gm);ee("cbrt",pP);ee("transpose",oP);ee("determinant",aP);ee("inverse",lP);ee("rand",gP);class vP extends Ve{static get type(){return"ConditionalNode"}constructor(e,t,n=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=n}generateNodeType(e){const{ifNode:t,elseNode:n}=e.getNodeProperties(this);if(t===void 0)return e.flowBuildStage(this,"setup"),this.getNodeType(e);const i=t.getNodeType(e);if(n!==null){const s=n.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(i))return s}return i}setup(e){const t=this.condNode,n=this.ifNode.isolate(),i=this.elseNode?this.elseNode.isolate():null,s=e.context.nodeBlock;e.getDataFromNode(n).parentNodeBlock=s,i!==null&&(e.getDataFromNode(i).parentNodeBlock=s);const o=e.context.uniformFlow,a=e.getNodeProperties(this);a.condNode=t,a.ifNode=o?n:n.context({nodeBlock:n}),a.elseNode=i?o?i:i.context({nodeBlock:i}):null}generate(e,t){const n=this.getNodeType(e),i=e.getDataFromNode(this);if(i.nodeProperty!==void 0)return i.nodeProperty;const{condNode:s,ifNode:o,elseNode:a}=e.getNodeProperties(this),l=e.currentFunctionNode,c=t!=="void",u=c?Ns(n).build(e):"";i.nodeProperty=u;const h=s.build(e,"bool");if(e.context.uniformFlow&&a!==null){const p=o.build(e,n),g=a.build(e,n),m=e.getTernary(h,p,g);return e.format(m,n,t)}e.addFlowCode(`
4625
4625
  ${e.tab}if ( ${h} ) {
4626
4626
 
4627
4627
  `).addFlowTab();let f=o.build(e,n);if(f&&(c?f=u+" = "+f+";":(f="return "+f+";",l===null&&(ae("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),f="// "+f))),e.removeFlowTab().addFlowCode(e.tab+" "+f+`
@@ -4634,27 +4634,27 @@ ${e.tab}if ( ${h} ) {
4634
4634
 
4635
4635
  `)}else e.addFlowCode(`
4636
4636
 
4637
- `);return e.format(u,n,t)}}const Mi=It(vP).setParameterLength(2,3);ee("select",Mi);class yv extends Ve{static get type(){return"ContextNode"}constructor(e=null,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}generateNodeType(e){return this.node.getNodeType(e)}getFlowContextData(){const e=[];return this.traverse(t=>{t.isContextNode===!0&&e.push(t.value)}),Object.assign({},...e)}getMemberType(e,t){return this.node.getMemberType(e,t)}analyze(e){const t=e.addContext(this.value);this.node.build(e),e.setContext(t)}setup(e){const t=e.addContext(this.value);this.node.build(e),e.setContext(t)}generate(e,t){const n=e.addContext(this.value),i=this.node.build(e,t);return e.setContext(n),i}}const Po=(r=null,e={})=>{let t=r;return(t===null||t.isNode!==!0)&&(e=t||e,t=null),new yv(t,e)},bP=r=>Po(r,{uniformFlow:!0}),vv=(r,e)=>Po(r,{nodeName:e});function SP(r,e,t=null){return Po(t,{getShadow:({light:n,shadowColorNode:i})=>e===n?i.mul(r):i})}function TP(r,e=null){return Po(e,{getAO:(t,{material:n})=>n.transparent===!0?t:t!==null?t.mul(r):r})}function MP(r,e){return ae('TSL: "label()" has been deprecated. Use "setName()" instead.'),vv(r,e)}ee("context",Po);ee("label",MP);ee("uniformFlow",bP);ee("setName",vv);ee("builtinShadowContext",(r,e,t)=>SP(e,t,r));ee("builtinAOContext",(r,e)=>TP(e,r));class hh extends Ve{static get type(){return"VarNode"}constructor(e,t=null,n=!1){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0,this.readOnly=n,this.parents=!0,this.intent=!1}setIntent(e){return this.intent=e,this}isIntent(e){return e.getDataFromNode(this).forceDeclaration===!0?!1:this.intent}getIntent(){return this.intent}getMemberType(e,t){return this.node.getMemberType(e,t)}getElementType(e){return this.node.getElementType(e)}generateNodeType(e){return this.node.getNodeType(e)}getArrayCount(e){return this.node.getArrayCount(e)}isAssign(e){return e.getDataFromNode(this).assign}build(...e){const t=e[0];if(this._hasStack(t)===!1&&t.buildStage==="setup"&&(t.context.nodeLoop||t.context.nodeBlock)){let n=!1;if(this.node.isShaderCallNodeInternal&&this.node.shaderNode.getLayout()===null&&t.fnCall&&t.fnCall.shaderNode&&t.getDataFromNode(this.node.shaderNode).hasLoop){const o=t.getDataFromNode(this);o.forceDeclaration=!0,n=!0}const i=t.getBaseStack();n?i.addToStackBefore(this):i.addToStack(this)}return this.isIntent(t)&&this.isAssign(t)!==!0?this.node.build(...e):super.build(...e)}generate(e){const{node:t,name:n,readOnly:i}=this,{renderer:s}=e,o=s.backend.isWebGPUBackend===!0;let a=!1,l=!1;i&&(a=e.isDeterministic(t),l=o?i:a);const c=this.getNodeType(e);if(c=="void")return this.isIntent(e)!==!0&&ce('TSL: ".toVar()" can not be used with void type.',this.stackTrace),t.build(e);const u=e.getVectorType(c),h=t.build(e,u),d=e.getVarFromNode(this,n,u,void 0,l),f=e.getPropertyName(d);let p=f;if(l)if(o)p=a?`const ${f}`:`let ${f}`;else{const g=t.getArrayCount(e);p=`const ${e.getVar(d.type,f,g)}`}return e.addLineFlowCode(`${p} = ${h}`,this),f}_hasStack(e){return e.getDataFromNode(this).stack!==void 0}}const Vm=It(hh),EP=(r,e=null)=>Vm(r,e).toStack(),AP=(r,e=null)=>Vm(r,e,!0).toStack(),wP=r=>Vm(r).setIntent(!0).toStack();ee("toVar",EP);ee("toConst",AP);ee("toVarIntent",wP);class RP extends Ve{static get type(){return"SubBuild"}constructor(e,t,n=null){super(n),this.node=e,this.name=t,this.isSubBuildNode=!0}generateNodeType(e){if(this.nodeType!==null)return this.nodeType;e.addSubBuild(this.name);const t=this.node.getNodeType(e);return e.removeSubBuild(),t}build(e,...t){e.addSubBuild(this.name);const n=this.node.build(e,...t);return e.removeSubBuild(),n}}const ba=(r,e,t=null)=>new RP(Ge(r),e,t);class CP extends Ve{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=ba(e,"VERTEX"),this.name=t,this.isVaryingNode=!0,this.interpolationType=null,this.interpolationSampling=null,this.global=!0}setInterpolation(e,t=null){return this.interpolationType=e,this.interpolationSampling=t,this}getHash(e){return this.name||super.getHash(e)}generateNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let n=t.varying;if(n===void 0){const i=this.name,s=this.getNodeType(e),o=this.interpolationType,a=this.interpolationSampling;t.varying=n=e.getVaryingFromNode(this,i,s,o,a),t.node=ba(this.node,"VERTEX")}return n.needsInterpolation||(n.needsInterpolation=e.shaderStage==="fragment"),n}setup(e){this.setupVarying(e),e.flowNodeFromShaderStage(Pu.VERTEX,this.node)}analyze(e){this.setupVarying(e),e.flowNodeFromShaderStage(Pu.VERTEX,this.node)}generate(e){const t=e.getSubBuildProperty("property",e.currentStack),n=e.getNodeProperties(this),i=this.setupVarying(e);if(n[t]===void 0){const s=this.getNodeType(e),o=e.getPropertyName(i,Pu.VERTEX);e.flowNodeFromShaderStage(Pu.VERTEX,n.node,s,o),n[t]=o}return e.getPropertyName(i)}}const Do=It(CP).setParameterLength(1,2),NP=r=>Do(r);ee("toVarying",Do);ee("toVertexStage",NP);const PP=re(([r])=>{const e=r.mul(.9478672986).add(.0521327014).pow(2.4),t=r.mul(.0773993808),n=r.lessThanEqual(.04045);return Dt(e,t,n)}).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),DP=re(([r])=>{const e=r.pow(.41666).mul(1.055).sub(.055),t=r.mul(12.92),n=r.lessThanEqual(.0031308);return Dt(e,t,n)}).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),zm="WorkingColorSpace",LP="OutputColorSpace";class bv extends xn{static get type(){return"ColorSpaceNode"}constructor(e,t,n){super("vec4"),this.colorNode=e,this.source=t,this.target=n}resolveColorSpace(e,t){return t===zm?Ye.workingColorSpace:t===LP?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,n=this.resolveColorSpace(e,this.source),i=this.resolveColorSpace(e,this.target);let s=t;return Ye.enabled===!1||n===i||!n||!i||(Ye.getTransfer(n)===Pe&&(s=et(PP(s.rgb),s.a)),Ye.getPrimaries(n)!==Ye.getPrimaries(i)&&(s=et(On(Ye._getMatrix(new Je,n,i)).mul(s.rgb),s.a)),Ye.getTransfer(i)===Pe&&(s=et(DP(s.rgb),s.a))),s}}const UP=(r,e)=>new bv(Ge(r),zm,e),Hm=(r,e)=>new bv(Ge(r),e,zm);ee("workingToColorSpace",UP);ee("colorSpaceToWorking",Hm);let FP=class extends hl{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}generateNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),n=this.referenceNode.getNodeType(),i=this.getNodeType();return e.format(t,n,i)}};class Sv extends Ve{static get type(){return"ReferenceBaseNode"}constructor(e,t,n=null,i=null){super(),this.property=e,this.uniformType=t,this.object=n,this.count=i,this.properties=e.split("."),this.reference=n,this.node=null,this.group=null,this.updateType=Ze.OBJECT}setGroup(e){return this.group=e,this}element(e){return new FP(this,Ge(e))}setNodeType(e){const t=qe(null,e);this.group!==null&&t.setGroup(this.group),this.node=t}generateNodeType(e){return this.node===null&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let n=e[t[0]];for(let i=1;i<t.length;i++)n=n[t[i]];return n}updateReference(e){return this.reference=this.object!==null?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);const e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}const IP=(r,e,t)=>new Sv(r,e,t);class BP extends Sv{static get type(){return"RendererReferenceNode"}constructor(e,t,n=null){super(e,t,n),this.renderer=n,this.setGroup(Ke)}updateReference(e){return this.reference=this.renderer!==null?this.renderer:e.renderer,this.reference}}const OP=(r,e,t=null)=>new BP(r,e,t);class kP extends xn{static get type(){return"ToneMappingNode"}constructor(e,t=VP,n=null){super("vec3"),this._toneMapping=e,this.exposureNode=t,this.colorNode=n}customCacheKey(){return Ql(this._toneMapping)}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup(e){const t=this.colorNode||e.context.color,n=this._toneMapping;if(n===Fn)return t;let i=null;const s=e.renderer.library.getToneMappingFunction(n);return s!==null?i=et(s(t.rgb,this.exposureNode),t.a):(ce("ToneMappingNode: Unsupported Tone Mapping configuration.",n),i=t),i}}const GP=(r,e,t)=>new kP(r,Ge(e),Ge(t)),VP=OP("toneMappingExposure","float");ee("toneMapping",(r,e,t)=>GP(e,t,r));const ex=new WeakMap;function tx(r,e){let t=ex.get(r);return t===void 0&&(t=new pm(r,e),ex.set(r,t)),t}class us extends Cm{static get type(){return"BufferAttributeNode"}constructor(e,t=null,n=0,i=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=n,this.bufferOffset=i,this.usage=Ya,this.instanced=!1,this.attribute=null,this.global=!0,e&&e.isBufferAttribute===!0&&e.itemSize<=4&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){let t;if(this.bufferStride===0&&this.bufferOffset===0){let n=e.globalCache.getData(this.value);n===void 0&&(n={node:this},e.globalCache.setData(this.value,n)),t=n.node.id}else t=this.id;return String(t)}generateNodeType(e){return this.bufferType===null&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(this.attribute!==null)return;const t=this.getNodeType(e),n=e.getTypeLength(t),i=this.value,s=this.bufferStride||n,o=this.bufferOffset;let a;i.isInterleavedBuffer===!0?a=i:i.isBufferAttribute===!0?a=tx(i.array,s):a=tx(i,s);const l=new Tc(a,n,o);a.setUsage(this.usage),this.attribute=l,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),n=e.getBufferAttributeFromNode(this,t),i=e.getPropertyName(n);let s=null;return e.shaderStage==="vertex"||e.shaderStage==="compute"?(this.name=i,s=i):s=Do(this).build(e,t),s}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&this.attribute.isBufferAttribute===!0&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}function Wm(r,e=null,t=0,n=0,i=Ya,s=!1){return e==="mat3"||e===null&&r.itemSize===9?On(new us(r,"vec3",9,0).setUsage(i).setInstanced(s),new us(r,"vec3",9,3).setUsage(i).setInstanced(s),new us(r,"vec3",9,6).setUsage(i).setInstanced(s)):e==="mat4"||e===null&&r.itemSize===16?uo(new us(r,"vec4",16,0).setUsage(i).setInstanced(s),new us(r,"vec4",16,4).setUsage(i).setInstanced(s),new us(r,"vec4",16,8).setUsage(i).setInstanced(s),new us(r,"vec4",16,12).setUsage(i).setInstanced(s)):new us(r,e,t,n).setUsage(i)}const Tv=(r,e=null,t=0,n=0)=>Wm(r,e,t,n),nx=(r,e=null,t=0,n=0)=>Wm(r,e,t,n,Ya,!0),ix=(r,e=null,t=0,n=0)=>Wm(r,e,t,n,mh,!0);ee("toAttribute",r=>Tv(r.value));class en extends Ve{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isIndexNode=!0}generate(e){const t=this.getNodeType(e),n=this.scope;let i;if(n===en.VERTEX)i=e.getVertexIndex();else if(n===en.INSTANCE)i=e.getInstanceIndex();else if(n===en.DRAW)i=e.getDrawIndex();else if(n===en.INVOCATION_LOCAL)i=e.getInvocationLocalIndex();else if(n===en.INVOCATION_SUBGROUP)i=e.getInvocationSubgroupIndex();else if(n===en.SUBGROUP)i=e.getSubgroupIndex();else throw new Error("THREE.IndexNode: Unknown scope: "+n);let s;return e.shaderStage==="vertex"||e.shaderStage==="compute"?s=i:s=Do(this).build(e,t),s}}en.VERTEX="vertex";en.INSTANCE="instance";en.SUBGROUP="subgroup";en.INVOCATION_LOCAL="invocationLocal";en.INVOCATION_SUBGROUP="invocationSubgroup";en.DRAW="draw";const zP=be(en,en.VERTEX),Sa=be(en,en.INSTANCE);en.SUBGROUP;en.INVOCATION_SUBGROUP;en.INVOCATION_LOCAL;const HP=be(en,en.DRAW);class WP extends Ve{static get type(){return"ComputeNode"}constructor(e,t){super("void"),this.isComputeNode=!0,this.computeNode=e,this.workgroupSize=t,this.count=null,this.dispatchSize=null,this.version=1,this.name="",this.updateBeforeType=Ze.OBJECT,this.onInitFunction=null,this.countNode=null}dispose(){this.dispatchEvent({type:"dispose"})}setName(e){return this.name=e,this}label(e){return ae('TSL: "label()" has been deprecated. Use "setName()" instead.',new Kn),this.setName(e)}onInit(e){return this.onInitFunction=e,this}updateBefore({renderer:e}){e.compute(this)}setup(e){this.count!==null&&this.countNode===null&&(this.countNode=qe(this.count,"uint").onObjectUpdate(()=>this.count));const t=this.computeNode.build(e);if(t){const n=e.getNodeProperties(this);n.outputComputeNode=t.outputNode,t.outputNode=null}return t}generate(e,t){const{shaderStage:n}=e;if(n==="compute"){const i=this.computeNode.build(e,"void");if(i!==""&&e.addLineFlowCode(i,this),this.count!==null&&e.allowEarlyReturns===!0){const s=this.countNode.build(e,"uint"),o=Sa.build(e,"uint");e.flow.code=`${e.tab}if ( ${o} >= ${s} ) { return; }
4637
+ `);return e.format(u,n,t)}}const Ti=It(vP).setParameterLength(2,3);ee("select",Ti);class yv extends Ve{static get type(){return"ContextNode"}constructor(e=null,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}generateNodeType(e){return this.node.getNodeType(e)}getFlowContextData(){const e=[];return this.traverse(t=>{t.isContextNode===!0&&e.push(t.value)}),Object.assign({},...e)}getMemberType(e,t){return this.node.getMemberType(e,t)}analyze(e){const t=e.addContext(this.value);this.node.build(e),e.setContext(t)}setup(e){const t=e.addContext(this.value);this.node.build(e),e.setContext(t)}generate(e,t){const n=e.addContext(this.value),i=this.node.build(e,t);return e.setContext(n),i}}const Po=(r=null,e={})=>{let t=r;return(t===null||t.isNode!==!0)&&(e=t||e,t=null),new yv(t,e)},bP=r=>Po(r,{uniformFlow:!0}),vv=(r,e)=>Po(r,{nodeName:e});function SP(r,e,t=null){return Po(t,{getShadow:({light:n,shadowColorNode:i})=>e===n?i.mul(r):i})}function TP(r,e=null){return Po(e,{getAO:(t,{material:n})=>n.transparent===!0?t:t!==null?t.mul(r):r})}function MP(r,e){return ae('TSL: "label()" has been deprecated. Use "setName()" instead.'),vv(r,e)}ee("context",Po);ee("label",MP);ee("uniformFlow",bP);ee("setName",vv);ee("builtinShadowContext",(r,e,t)=>SP(e,t,r));ee("builtinAOContext",(r,e)=>TP(e,r));class hh extends Ve{static get type(){return"VarNode"}constructor(e,t=null,n=!1){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0,this.readOnly=n,this.parents=!0,this.intent=!1}setIntent(e){return this.intent=e,this}isIntent(e){return e.getDataFromNode(this).forceDeclaration===!0?!1:this.intent}getIntent(){return this.intent}getMemberType(e,t){return this.node.getMemberType(e,t)}getElementType(e){return this.node.getElementType(e)}generateNodeType(e){return this.node.getNodeType(e)}getArrayCount(e){return this.node.getArrayCount(e)}isAssign(e){return e.getDataFromNode(this).assign}build(...e){const t=e[0];if(this._hasStack(t)===!1&&t.buildStage==="setup"&&(t.context.nodeLoop||t.context.nodeBlock)){let n=!1;if(this.node.isShaderCallNodeInternal&&this.node.shaderNode.getLayout()===null&&t.fnCall&&t.fnCall.shaderNode&&t.getDataFromNode(this.node.shaderNode).hasLoop){const o=t.getDataFromNode(this);o.forceDeclaration=!0,n=!0}const i=t.getBaseStack();n?i.addToStackBefore(this):i.addToStack(this)}return this.isIntent(t)&&this.isAssign(t)!==!0?this.node.build(...e):super.build(...e)}generate(e){const{node:t,name:n,readOnly:i}=this,{renderer:s}=e,o=s.backend.isWebGPUBackend===!0;let a=!1,l=!1;i&&(a=e.isDeterministic(t),l=o?i:a);const c=this.getNodeType(e);if(c=="void")return this.isIntent(e)!==!0&&ce('TSL: ".toVar()" can not be used with void type.',this.stackTrace),t.build(e);const u=e.getVectorType(c),h=t.build(e,u),d=e.getVarFromNode(this,n,u,void 0,l),f=e.getPropertyName(d);let p=f;if(l)if(o)p=a?`const ${f}`:`let ${f}`;else{const g=t.getArrayCount(e);p=`const ${e.getVar(d.type,f,g)}`}return e.addLineFlowCode(`${p} = ${h}`,this),f}_hasStack(e){return e.getDataFromNode(this).stack!==void 0}}const Vm=It(hh),EP=(r,e=null)=>Vm(r,e).toStack(),AP=(r,e=null)=>Vm(r,e,!0).toStack(),wP=r=>Vm(r).setIntent(!0).toStack();ee("toVar",EP);ee("toConst",AP);ee("toVarIntent",wP);class RP extends Ve{static get type(){return"SubBuild"}constructor(e,t,n=null){super(n),this.node=e,this.name=t,this.isSubBuildNode=!0}generateNodeType(e){if(this.nodeType!==null)return this.nodeType;e.addSubBuild(this.name);const t=this.node.getNodeType(e);return e.removeSubBuild(),t}build(e,...t){e.addSubBuild(this.name);const n=this.node.build(e,...t);return e.removeSubBuild(),n}}const ba=(r,e,t=null)=>new RP(Ge(r),e,t);class CP extends Ve{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=ba(e,"VERTEX"),this.name=t,this.isVaryingNode=!0,this.interpolationType=null,this.interpolationSampling=null,this.global=!0}setInterpolation(e,t=null){return this.interpolationType=e,this.interpolationSampling=t,this}getHash(e){return this.name||super.getHash(e)}generateNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let n=t.varying;if(n===void 0){const i=this.name,s=this.getNodeType(e),o=this.interpolationType,a=this.interpolationSampling;t.varying=n=e.getVaryingFromNode(this,i,s,o,a),t.node=ba(this.node,"VERTEX")}return n.needsInterpolation||(n.needsInterpolation=e.shaderStage==="fragment"),n}setup(e){this.setupVarying(e),e.flowNodeFromShaderStage(Pu.VERTEX,this.node)}analyze(e){this.setupVarying(e),e.flowNodeFromShaderStage(Pu.VERTEX,this.node)}generate(e){const t=e.getSubBuildProperty("property",e.currentStack),n=e.getNodeProperties(this),i=this.setupVarying(e);if(n[t]===void 0){const s=this.getNodeType(e),o=e.getPropertyName(i,Pu.VERTEX);e.flowNodeFromShaderStage(Pu.VERTEX,n.node,s,o),n[t]=o}return e.getPropertyName(i)}}const Do=It(CP).setParameterLength(1,2),NP=r=>Do(r);ee("toVarying",Do);ee("toVertexStage",NP);const PP=re(([r])=>{const e=r.mul(.9478672986).add(.0521327014).pow(2.4),t=r.mul(.0773993808),n=r.lessThanEqual(.04045);return Dt(e,t,n)}).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),DP=re(([r])=>{const e=r.pow(.41666).mul(1.055).sub(.055),t=r.mul(12.92),n=r.lessThanEqual(.0031308);return Dt(e,t,n)}).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),zm="WorkingColorSpace",LP="OutputColorSpace";class bv extends xn{static get type(){return"ColorSpaceNode"}constructor(e,t,n){super("vec4"),this.colorNode=e,this.source=t,this.target=n}resolveColorSpace(e,t){return t===zm?Ye.workingColorSpace:t===LP?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,n=this.resolveColorSpace(e,this.source),i=this.resolveColorSpace(e,this.target);let s=t;return Ye.enabled===!1||n===i||!n||!i||(Ye.getTransfer(n)===Pe&&(s=et(PP(s.rgb),s.a)),Ye.getPrimaries(n)!==Ye.getPrimaries(i)&&(s=et(On(Ye._getMatrix(new Je,n,i)).mul(s.rgb),s.a)),Ye.getTransfer(i)===Pe&&(s=et(DP(s.rgb),s.a))),s}}const UP=(r,e)=>new bv(Ge(r),zm,e),Hm=(r,e)=>new bv(Ge(r),e,zm);ee("workingToColorSpace",UP);ee("colorSpaceToWorking",Hm);let FP=class extends hl{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}generateNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),n=this.referenceNode.getNodeType(),i=this.getNodeType();return e.format(t,n,i)}};class Sv extends Ve{static get type(){return"ReferenceBaseNode"}constructor(e,t,n=null,i=null){super(),this.property=e,this.uniformType=t,this.object=n,this.count=i,this.properties=e.split("."),this.reference=n,this.node=null,this.group=null,this.updateType=Ze.OBJECT}setGroup(e){return this.group=e,this}element(e){return new FP(this,Ge(e))}setNodeType(e){const t=qe(null,e);this.group!==null&&t.setGroup(this.group),this.node=t}generateNodeType(e){return this.node===null&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let n=e[t[0]];for(let i=1;i<t.length;i++)n=n[t[i]];return n}updateReference(e){return this.reference=this.object!==null?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);const e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}const IP=(r,e,t)=>new Sv(r,e,t);class BP extends Sv{static get type(){return"RendererReferenceNode"}constructor(e,t,n=null){super(e,t,n),this.renderer=n,this.setGroup(Ke)}updateReference(e){return this.reference=this.renderer!==null?this.renderer:e.renderer,this.reference}}const OP=(r,e,t=null)=>new BP(r,e,t);class kP extends xn{static get type(){return"ToneMappingNode"}constructor(e,t=VP,n=null){super("vec3"),this._toneMapping=e,this.exposureNode=t,this.colorNode=n}customCacheKey(){return Ql(this._toneMapping)}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup(e){const t=this.colorNode||e.context.color,n=this._toneMapping;if(n===Fn)return t;let i=null;const s=e.renderer.library.getToneMappingFunction(n);return s!==null?i=et(s(t.rgb,this.exposureNode),t.a):(ce("ToneMappingNode: Unsupported Tone Mapping configuration.",n),i=t),i}}const GP=(r,e,t)=>new kP(r,Ge(e),Ge(t)),VP=OP("toneMappingExposure","float");ee("toneMapping",(r,e,t)=>GP(e,t,r));const ex=new WeakMap;function tx(r,e){let t=ex.get(r);return t===void 0&&(t=new pm(r,e),ex.set(r,t)),t}class us extends Cm{static get type(){return"BufferAttributeNode"}constructor(e,t=null,n=0,i=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=n,this.bufferOffset=i,this.usage=Ya,this.instanced=!1,this.attribute=null,this.global=!0,e&&e.isBufferAttribute===!0&&e.itemSize<=4&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){let t;if(this.bufferStride===0&&this.bufferOffset===0){let n=e.globalCache.getData(this.value);n===void 0&&(n={node:this},e.globalCache.setData(this.value,n)),t=n.node.id}else t=this.id;return String(t)}generateNodeType(e){return this.bufferType===null&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(this.attribute!==null)return;const t=this.getNodeType(e),n=e.getTypeLength(t),i=this.value,s=this.bufferStride||n,o=this.bufferOffset;let a;i.isInterleavedBuffer===!0?a=i:i.isBufferAttribute===!0?a=tx(i.array,s):a=tx(i,s);const l=new Tc(a,n,o);a.setUsage(this.usage),this.attribute=l,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),n=e.getBufferAttributeFromNode(this,t),i=e.getPropertyName(n);let s=null;return e.shaderStage==="vertex"||e.shaderStage==="compute"?(this.name=i,s=i):s=Do(this).build(e,t),s}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&this.attribute.isBufferAttribute===!0&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}function Wm(r,e=null,t=0,n=0,i=Ya,s=!1){return e==="mat3"||e===null&&r.itemSize===9?On(new us(r,"vec3",9,0).setUsage(i).setInstanced(s),new us(r,"vec3",9,3).setUsage(i).setInstanced(s),new us(r,"vec3",9,6).setUsage(i).setInstanced(s)):e==="mat4"||e===null&&r.itemSize===16?uo(new us(r,"vec4",16,0).setUsage(i).setInstanced(s),new us(r,"vec4",16,4).setUsage(i).setInstanced(s),new us(r,"vec4",16,8).setUsage(i).setInstanced(s),new us(r,"vec4",16,12).setUsage(i).setInstanced(s)):new us(r,e,t,n).setUsage(i)}const Tv=(r,e=null,t=0,n=0)=>Wm(r,e,t,n),nx=(r,e=null,t=0,n=0)=>Wm(r,e,t,n,Ya,!0),ix=(r,e=null,t=0,n=0)=>Wm(r,e,t,n,mh,!0);ee("toAttribute",r=>Tv(r.value));class en extends Ve{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isIndexNode=!0}generate(e){const t=this.getNodeType(e),n=this.scope;let i;if(n===en.VERTEX)i=e.getVertexIndex();else if(n===en.INSTANCE)i=e.getInstanceIndex();else if(n===en.DRAW)i=e.getDrawIndex();else if(n===en.INVOCATION_LOCAL)i=e.getInvocationLocalIndex();else if(n===en.INVOCATION_SUBGROUP)i=e.getInvocationSubgroupIndex();else if(n===en.SUBGROUP)i=e.getSubgroupIndex();else throw new Error("THREE.IndexNode: Unknown scope: "+n);let s;return e.shaderStage==="vertex"||e.shaderStage==="compute"?s=i:s=Do(this).build(e,t),s}}en.VERTEX="vertex";en.INSTANCE="instance";en.SUBGROUP="subgroup";en.INVOCATION_LOCAL="invocationLocal";en.INVOCATION_SUBGROUP="invocationSubgroup";en.DRAW="draw";const zP=be(en,en.VERTEX),Sa=be(en,en.INSTANCE);en.SUBGROUP;en.INVOCATION_SUBGROUP;en.INVOCATION_LOCAL;const HP=be(en,en.DRAW);class WP extends Ve{static get type(){return"ComputeNode"}constructor(e,t){super("void"),this.isComputeNode=!0,this.computeNode=e,this.workgroupSize=t,this.count=null,this.dispatchSize=null,this.version=1,this.name="",this.updateBeforeType=Ze.OBJECT,this.onInitFunction=null,this.countNode=null}dispose(){this.dispatchEvent({type:"dispose"})}setName(e){return this.name=e,this}label(e){return ae('TSL: "label()" has been deprecated. Use "setName()" instead.',new Kn),this.setName(e)}onInit(e){return this.onInitFunction=e,this}updateBefore({renderer:e}){e.compute(this)}setup(e){this.count!==null&&this.countNode===null&&(this.countNode=qe(this.count,"uint").onObjectUpdate(()=>this.count));const t=this.computeNode.build(e);if(t){const n=e.getNodeProperties(this);n.outputComputeNode=t.outputNode,t.outputNode=null}return t}generate(e,t){const{shaderStage:n}=e;if(n==="compute"){const i=this.computeNode.build(e,"void");if(i!==""&&e.addLineFlowCode(i,this),this.count!==null&&e.allowEarlyReturns===!0){const s=this.countNode.build(e,"uint"),o=Sa.build(e,"uint");e.flow.code=`${e.tab}if ( ${o} >= ${s} ) { return; }
4638
4638
 
4639
- ${e.flow.code}`}}else{const s=e.getNodeProperties(this).outputComputeNode;if(s)return s.build(e,t)}}}const Mv=(r,e=[64])=>{(e.length===0||e.length>3)&&ce("TSL: compute() workgroupSize must have 1, 2, or 3 elements",new Kn);for(let t=0;t<e.length;t++){const n=e[t];(typeof n!="number"||n<=0||!Number.isInteger(n))&&ce(`TSL: compute() workgroupSize element at index [ ${t} ] must be a positive integer`,new Kn)}for(;e.length<3;)e.push(1);return new WP(Ge(r),e)},$P=(r,e,t)=>{const n=Mv(r,t);return typeof e=="number"?n.count=e:n.dispatchSize=e,n};ee("compute",$P);ee("computeKernel",Mv);class XP extends Ve{static get type(){return"IsolateNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isIsolateNode=!0}generateNodeType(e){const t=e.getCache(),n=e.getCacheFromNode(this,this.parent);e.setCache(n);const i=this.node.getNodeType(e);return e.setCache(t),i}build(e,...t){const n=e.getCache(),i=e.getCacheFromNode(this,this.parent);e.setCache(i);const s=this.node.build(e,...t);return e.setCache(n),s}setParent(e){return this.parent=e,this}getParent(){return this.parent}}const nc=r=>new XP(Ge(r));function qP(r,e=!0){return ae('TSL: "cache()" has been deprecated. Use "isolate()" instead.'),nc(r).setParent(e)}ee("cache",qP);ee("isolate",nc);class jP extends Ve{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}generateNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return t!==""&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const YP=It(jP).setParameterLength(2);ee("bypass",YP);const Ev=re(([r,e,t,n=J(0),i=J(1),s=$h(!1)])=>{let o=r.sub(e).div(t.sub(e));return mp(s)&&(o=o.clamp()),o.mul(i.sub(n)).add(n)});function KP(r,e,t,n=J(0),i=J(1)){return Ev(r,e,t,n,i,!0)}ee("remap",Ev);ee("remapClamp",KP);class dh extends Ve{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const n=this.getNodeType(e),i=this.snippet;if(n==="void")e.addLineFlowCode(i,this);else return e.format(i,n,t)}}const mr=It(dh).setParameterLength(1,2),ZP=r=>(r?Mi(r,mr("discard")):mr("discard")).toStack();ee("discard",ZP);class QP extends xn{static get type(){return"RenderOutputNode"}constructor(e,t,n){super("vec4"),this.colorNode=e,this._toneMapping=t,this.outputColorSpace=n,this.isRenderOutputNode=!0}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup({context:e}){let t=this.colorNode||e.color;const n=(this._toneMapping!==null?this._toneMapping:e.toneMapping)||Fn,i=(this.outputColorSpace!==null?this.outputColorSpace:e.outputColorSpace)||ai;return n!==Fn&&(t=t.toneMapping(n)),i!==ai&&i!==Ye.workingColorSpace&&(t=t.workingToColorSpace(i)),t}}const Av=(r,e=null,t=null)=>new QP(Ge(r),e,t);ee("renderOutput",Av);class JP extends xn{static get type(){return"DebugNode"}constructor(e,t=null){super(),this.node=e,this.callback=t}generateNodeType(e){return this.node.getNodeType(e)}setup(e){return this.node.build(e)}analyze(e){return this.node.build(e)}generate(e){const t=this.callback,n=this.node.build(e);if(t!==null)t(e,n);else{const i="--- TSL debug - "+e.shaderStage+" shader ---",s="-".repeat(i.length);let o="";o+="// #"+i+`#
4639
+ ${e.flow.code}`}}else{const s=e.getNodeProperties(this).outputComputeNode;if(s)return s.build(e,t)}}}const Mv=(r,e=[64])=>{(e.length===0||e.length>3)&&ce("TSL: compute() workgroupSize must have 1, 2, or 3 elements",new Kn);for(let t=0;t<e.length;t++){const n=e[t];(typeof n!="number"||n<=0||!Number.isInteger(n))&&ce(`TSL: compute() workgroupSize element at index [ ${t} ] must be a positive integer`,new Kn)}for(;e.length<3;)e.push(1);return new WP(Ge(r),e)},$P=(r,e,t)=>{const n=Mv(r,t);return typeof e=="number"?n.count=e:n.dispatchSize=e,n};ee("compute",$P);ee("computeKernel",Mv);class XP extends Ve{static get type(){return"IsolateNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isIsolateNode=!0}generateNodeType(e){const t=e.getCache(),n=e.getCacheFromNode(this,this.parent);e.setCache(n);const i=this.node.getNodeType(e);return e.setCache(t),i}build(e,...t){const n=e.getCache(),i=e.getCacheFromNode(this,this.parent);e.setCache(i);const s=this.node.build(e,...t);return e.setCache(n),s}setParent(e){return this.parent=e,this}getParent(){return this.parent}}const nc=r=>new XP(Ge(r));function qP(r,e=!0){return ae('TSL: "cache()" has been deprecated. Use "isolate()" instead.'),nc(r).setParent(e)}ee("cache",qP);ee("isolate",nc);class jP extends Ve{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}generateNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return t!==""&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const YP=It(jP).setParameterLength(2);ee("bypass",YP);const Ev=re(([r,e,t,n=J(0),i=J(1),s=$h(!1)])=>{let o=r.sub(e).div(t.sub(e));return mp(s)&&(o=o.clamp()),o.mul(i.sub(n)).add(n)});function KP(r,e,t,n=J(0),i=J(1)){return Ev(r,e,t,n,i,!0)}ee("remap",Ev);ee("remapClamp",KP);class dh extends Ve{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const n=this.getNodeType(e),i=this.snippet;if(n==="void")e.addLineFlowCode(i,this);else return e.format(i,n,t)}}const mr=It(dh).setParameterLength(1,2),ZP=r=>(r?Ti(r,mr("discard")):mr("discard")).toStack();ee("discard",ZP);class QP extends xn{static get type(){return"RenderOutputNode"}constructor(e,t,n){super("vec4"),this.colorNode=e,this._toneMapping=t,this.outputColorSpace=n,this.isRenderOutputNode=!0}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup({context:e}){let t=this.colorNode||e.color;const n=(this._toneMapping!==null?this._toneMapping:e.toneMapping)||Fn,i=(this.outputColorSpace!==null?this.outputColorSpace:e.outputColorSpace)||ai;return n!==Fn&&(t=t.toneMapping(n)),i!==ai&&i!==Ye.workingColorSpace&&(t=t.workingToColorSpace(i)),t}}const Av=(r,e=null,t=null)=>new QP(Ge(r),e,t);ee("renderOutput",Av);class JP extends xn{static get type(){return"DebugNode"}constructor(e,t=null){super(),this.node=e,this.callback=t}generateNodeType(e){return this.node.getNodeType(e)}setup(e){return this.node.build(e)}analyze(e){return this.node.build(e)}generate(e){const t=this.callback,n=this.node.build(e);if(t!==null)t(e,n);else{const i="--- TSL debug - "+e.shaderStage+" shader ---",s="-".repeat(i.length);let o="";o+="// #"+i+`#
4640
4640
  `,o+=e.flow.code.replace(/^\t/mg,"")+`
4641
4641
  `,o+="/* ... */ "+n+` /* ... */
4642
4642
  `,o+="// #"+s+`#
4643
- `,Sc(o)}return n}}const eD=(r,e=null)=>new JP(Ge(r),e).toStack();ee("debug",eD);class wv extends Vi{constructor(){super(),this._renderer=null,this.currentFrame=null}get nodeFrame(){return this._renderer._nodes.nodeFrame}setRenderer(e){return this._renderer=e,this}getRenderer(){return this._renderer}init(){}begin(){}finish(){}inspect(){}computeAsync(){}beginCompute(){}finishCompute(){}beginRender(){}finishRender(){}copyTextureToTexture(){}copyFramebufferToTexture(){}}class tD extends Ve{static get type(){return"InspectorNode"}constructor(e,t="",n=null){super(),this.node=e,this.name=t,this.callback=n,this.updateType=Ze.FRAME,this.isInspectorNode=!0}getName(){return this.name||this.node.name}update(e){e.renderer.inspector.inspect(this)}generateNodeType(e){return this.node.getNodeType(e)}setup(e){let t=this.node;return e.context.inspector===!0&&this.callback!==null&&(t=this.callback(t)),e.renderer.backend.isWebGPUBackend!==!0&&e.renderer.inspector.constructor!==wv&&Kt('TSL: ".toInspector()" is only available with WebGPU.'),t}}function nD(r,e="",t=null){return r=Ge(r),r.before(new tD(r,e,t))}ee("toInspector",nD);class Rv extends Ve{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}generateNodeType(e){let t=this.nodeType;if(t===null){const n=this.getAttributeName(e);if(e.hasGeometryAttribute(n)){const i=e.geometry.getAttribute(n);t=e.getTypeFromAttribute(i)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),n=this.getNodeType(e);if(e.hasGeometryAttribute(t)===!0){const s=e.geometry.getAttribute(t),o=e.getTypeFromAttribute(s),a=e.getAttribute(t,o);return e.shaderStage==="vertex"?e.format(a.name,o,n):Do(this).build(e,n)}else return ae(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(n)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const Is=(r,e=null)=>new Rv(r,e),dl=(r=0)=>Is("uv"+(r>0?r:""),"vec2");class iD extends Ve{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const n=this.textureNode.build(e,"property"),i=this.levelNode===null?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${n}, ${i} )`,this.getNodeType(e),t)}}const Ta=It(iD).setParameterLength(1,2);class rD extends Vc{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=Ze.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,n=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(n&&n.width!==void 0){const{width:i,height:s}=n;this.value=Math.log2(Math.max(i,s))}}}const sD=It(rD).setParameterLength(1);class oD extends Error{constructor(e,t=null){super(e),this.name="NodeError",this.stackTrace=t}}const Cv=new fn;class zc extends Vc{static get type(){return"TextureNode"}constructor(e=Cv,t=null,n=null,i=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=n,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.offsetNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=Ze.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this._flipYUniform=null,this.setUpdateMatrix(t===null)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}generateNodeType(){return this.value.isDepthTexture===!0?"float":this.value.type===Ct?"uvec4":this.value.type===Sn?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return dl(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return this._matrixUniform===null&&(this._matrixUniform=qe(this.value.matrix)),this._matrixUniform.mul(te(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this}setupUV(e,t){return e.isFlipY()&&(this._flipYUniform===null&&(this._flipYUniform=qe(!1)),t=t.toVar(),this.sampler?t=this._flipYUniform.select(t.flipY(),t):t=this._flipYUniform.select(t.setY(Zt(Ta(this,this.levelNode).y).sub(t.y).sub(1)),t)),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;const n=this.value;if(!n||n.isTexture!==!0)throw new oD("THREE.TSL: `texture( value )` function expects a valid instance of THREE.Texture().",this.stackTrace);const i=re(()=>{let l=this.uvNode;return(l===null||e.context.forceUVContext===!0)&&e.context.getUV&&(l=e.context.getUV(this,e)),l||(l=this.getDefaultUV()),this.updateMatrix===!0&&(l=this.getTransformedUV(l)),l=this.setupUV(e,l),this.updateType=this._matrixUniform!==null||this._flipYUniform!==null?Ze.OBJECT:Ze.NONE,l})();let s=this.levelNode;s===null&&e.context.getTextureLevel&&(s=e.context.getTextureLevel(this));let o=null,a=null;if(this.compareNode!==null)if(e.renderer.hasCompatibility(wo.TEXTURE_COMPARE))o=this.compareNode;else{const l=n.compareFunction;l===null||l===Ih||l===Os||l===vc||l===Zr?a=this.compareNode:(o=this.compareNode,Kt('TSL: Only "LessCompare", "LessEqualCompare", "GreaterCompare" and "GreaterEqualCompare" are supported for depth texture comparison fallback.'))}t.uvNode=i,t.levelNode=s,t.biasNode=this.biasNode,t.compareNode=o,t.compareStepNode=a,t.gradNode=this.gradNode,t.depthNode=this.depthNode,t.offsetNode=this.offsetNode}generateUV(e,t){return t.build(e,this.sampler===!0?"vec2":"ivec2")}generateOffset(e,t){return t.build(e,"ivec2")}generateSnippet(e,t,n,i,s,o,a,l,c){const u=this.value;let h;return s?h=e.generateTextureBias(u,t,n,s,o,c):l?h=e.generateTextureGrad(u,t,n,l,o,c):a?h=e.generateTextureCompare(u,t,n,a,o,c):this.sampler===!1?h=e.generateTextureLoad(u,t,n,i,o,c):i?h=e.generateTextureLevel(u,t,n,i,o,c):h=e.generateTexture(u,t,n,o,c),h}generate(e,t){const n=this.value,i=e.getNodeProperties(this),s=super.generate(e,"property");if(/^sampler/.test(t))return s+"_sampler";if(e.isReference(t))return s;{const o=e.getDataFromNode(this),a=this.getNodeType(e);let l=o.propertyName;if(l===void 0){const{uvNode:u,levelNode:h,biasNode:d,compareNode:f,compareStepNode:p,depthNode:g,gradNode:m,offsetNode:_}=i,x=this.generateUV(e,u),y=h?h.build(e,"float"):null,b=d?d.build(e,"float"):null,M=g?g.build(e,"int"):null,S=f?f.build(e,"float"):null,E=p?p.build(e,"float"):null,v=m?[m[0].build(e,"vec2"),m[1].build(e,"vec2")]:null,w=_?this.generateOffset(e,_):null;let N=M;N===null&&n.isArrayTexture&&this.isTexture3DNode!==!0&&(N="0");const C=e.getVarFromNode(this);l=e.getPropertyName(C);let F=this.generateSnippet(e,s,x,y,b,N,S,v,w);if(E!==null){const V=n.compareFunction;V===vc||V===Zr?F=Ec(mr(F,a),mr(E,"float")).build(e,a):F=Ec(mr(E,"float"),mr(F,a)).build(e,a)}e.addLineFlowCode(`${l} = ${F}`,this),o.snippet=F,o.propertyName=l}let c=l;return e.needsToWorkingColorSpace(n)&&(c=Hm(mr(c,a),n.colorSpace).setup(e).build(e,a)),e.format(c,a,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}sample(e){const t=this.clone();return t.uvNode=Ge(e),t.referenceNode=this.getBase(),Ge(t)}load(e){return this.sample(e).setSampler(!1)}blur(e){const t=this.clone();t.biasNode=Ge(e).mul(sD(t)),t.referenceNode=this.getBase();const n=t.value;return t.generateMipmaps===!1&&(n&&n.generateMipmaps===!1||n.minFilter===Mt||n.magFilter===Mt)&&(ae("TSL: texture().blur() requires mipmaps and sampling. Use .generateMipmaps=true and .minFilter/.magFilter=THREE.LinearFilter in the Texture."),t.biasNode=null),Ge(t)}level(e){const t=this.clone();return t.levelNode=Ge(e),t.referenceNode=this.getBase(),Ge(t)}size(e){return Ta(this,e)}bias(e){const t=this.clone();return t.biasNode=Ge(e),t.referenceNode=this.getBase(),Ge(t)}getBase(){return this.referenceNode?this.referenceNode.getBase():this}compare(e){const t=this.clone();return t.compareNode=Ge(e),t.referenceNode=this.getBase(),Ge(t)}grad(e,t){const n=this.clone();return n.gradNode=[Ge(e),Ge(t)],n.referenceNode=this.getBase(),Ge(n)}depth(e){const t=this.clone();return t.depthNode=Ge(e),t.referenceNode=this.getBase(),Ge(t)}offset(e){const t=this.clone();return t.offsetNode=Ge(e),t.referenceNode=this.getBase(),Ge(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;t!==null&&(t.value=e.matrix),e.matrixAutoUpdate===!0&&e.updateMatrix();const n=this._flipYUniform;n!==null&&(n.value=e.image instanceof ImageBitmap&&e.flipY===!0||e.isRenderTargetTexture===!0||e.isFramebufferTexture===!0||e.isDepthTexture===!0)}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.offsetNode=this.offsetNode,e}}const aD=It(zc).setParameterLength(1,4).setName("texture"),Vt=(r=Cv,e=null,t=null,n=null)=>{let i;return r&&r.isTextureNode===!0?(i=Ge(r.clone()),i.referenceNode=r.getBase(),e!==null&&(i.uvNode=Ge(e)),t!==null&&(i.levelNode=Ge(t)),n!==null&&(i.biasNode=Ge(n))):i=aD(r,e,t,n),i},Ni=(...r)=>Vt(...r).setSampler(!1);class $m extends Vc{static get type(){return"BufferNode"}constructor(e,t,n=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=n,this.updateRanges=[]}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const Nv=(r,e,t)=>new $m(r,e,t);class lD extends hl{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),n=this.getNodeType(e),i=this.node.getPaddedType();return e.format(t,i,n)}}class cD extends $m{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null),this.array=e,this.elementType=t===null?Sh(e[0]):t,this.paddedType=this.getPaddedType(),this.updateType=Ze.RENDER,this.isArrayBufferNode=!0}generateNodeType(){return this.paddedType}getElementType(){return this.elementType}getPaddedType(){const e=this.elementType;let t="vec4";return e==="mat2"?t="mat2":/mat/.test(e)===!0?t="mat4":e.charAt(0)==="i"?t="ivec4":e.charAt(0)==="u"&&(t="uvec4"),t}update(){const{array:e,value:t}=this,n=this.elementType;if(n==="float"||n==="int"||n==="uint")for(let i=0;i<e.length;i++){const s=i*4;t[s]=e[i]}else if(n==="color")for(let i=0;i<e.length;i++){const s=i*4,o=e[i];t[s]=o.r,t[s+1]=o.g,t[s+2]=o.b||0}else if(n==="mat2")for(let i=0;i<e.length;i++){const s=i*4,o=e[i];t[s]=o.elements[0],t[s+1]=o.elements[1],t[s+2]=o.elements[2],t[s+3]=o.elements[3]}else if(n==="mat3")for(let i=0;i<e.length;i++){const s=i*16,o=e[i];t[s]=o.elements[0],t[s+1]=o.elements[1],t[s+2]=o.elements[2],t[s+4]=o.elements[3],t[s+5]=o.elements[4],t[s+6]=o.elements[5],t[s+8]=o.elements[6],t[s+9]=o.elements[7],t[s+10]=o.elements[8],t[s+15]=1}else if(n==="mat4")for(let i=0;i<e.length;i++){const s=i*16,o=e[i];for(let a=0;a<o.elements.length;a++)t[s+a]=o.elements[a]}else for(let i=0;i<e.length;i++){const s=i*4,o=e[i];t[s]=o.x,t[s+1]=o.y,t[s+2]=o.z||0,t[s+3]=o.w||0}}setup(e){const t=this.array.length,n=this.elementType;let i=Float32Array;const s=this.paddedType,o=e.getTypeLength(s);return n.charAt(0)==="i"&&(i=Int32Array),n.charAt(0)==="u"&&(i=Uint32Array),this.value=new i(t*o),this.bufferCount=t,this.bufferType=s,this.update(),super.setup(e)}element(e){return new lD(this,Ge(e))}}const Di=(r,e)=>new cD(r,e);class uD extends Ve{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}}const fl=It(uD).setParameterLength(1);let Dl,Ll;class Wt extends Ve{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this._output=null,this.isViewportNode=!0}generateNodeType(){return this.scope===Wt.DPR?"float":this.scope===Wt.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=Ze.NONE;return(this.scope===Wt.SIZE||this.scope===Wt.VIEWPORT||this.scope===Wt.DPR)&&(e=Ze.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Wt.VIEWPORT?t!==null?Ll.copy(t.viewport):(e.getViewport(Ll),Ll.multiplyScalar(e.getPixelRatio())):this.scope===Wt.DPR?this._output.value=e.getPixelRatio():t!==null?(Dl.width=t.width,Dl.height=t.height):e.getDrawingBufferSize(Dl)}setup(){const e=this.scope;let t=null;return e===Wt.SIZE?t=qe(Dl||(Dl=new pe)):e===Wt.VIEWPORT?t=qe(Ll||(Ll=new rt)):e===Wt.DPR?t=qe(1):t=ke(pl.div(Sp)),this._output=t,t}generate(e){if(this.scope===Wt.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const n=e.getNodeProperties(Sp).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${n}.y - ${t}.y )`}return t}return super.generate(e)}}Wt.COORDINATE="coordinate";Wt.VIEWPORT="viewport";Wt.SIZE="size";Wt.UV="uv";Wt.DPR="dpr";const hD=be(Wt,Wt.DPR),fo=be(Wt,Wt.UV),Sp=be(Wt,Wt.SIZE),pl=be(Wt,Wt.COORDINATE),Pv=be(Wt,Wt.VIEWPORT),dD=Pv.zw;Pv.xy;let lf=null,Uu=null,cf=null,Fu=null,uf=null,Iu=null,hf=null,Bu=null;const qh=qe(0,"uint").setName("u_cameraIndex").setGroup(Im("cameraIndex")).toVarying("v_cameraIndex"),so=qe("float").setName("cameraNear").setGroup(Ke).onRenderUpdate(({camera:r})=>r.near),oo=qe("float").setName("cameraFar").setGroup(Ke).onRenderUpdate(({camera:r})=>r.far),ic=re(({camera:r})=>{let e;if(r.isArrayCamera&&r.cameras.length>0){const t=[];for(const n of r.cameras)t.push(n.projectionMatrix);Uu===null?Uu=Di(t).setGroup(Ke).setName("cameraProjectionMatrices"):Uu.array=t,e=Uu.element(r.isMultiViewCamera?fl("gl_ViewID_OVR"):qh).toConst("cameraProjectionMatrix")}else lf===null&&(lf=qe(r.projectionMatrix).setName("cameraProjectionMatrix").setGroup(Ke).onRenderUpdate(({camera:t})=>t.projectionMatrix)),e=lf;return e}).once()(),fD=re(({camera:r})=>{let e;if(r.isArrayCamera&&r.cameras.length>0){const t=[];for(const n of r.cameras)t.push(n.projectionMatrixInverse);Fu===null?Fu=Di(t).setGroup(Ke).setName("cameraProjectionMatricesInverse"):Fu.array=t,e=Fu.element(r.isMultiViewCamera?fl("gl_ViewID_OVR"):qh).toConst("cameraProjectionMatrixInverse")}else cf===null&&(cf=qe(r.projectionMatrixInverse).setName("cameraProjectionMatrixInverse").setGroup(Ke).onRenderUpdate(({camera:t})=>t.projectionMatrixInverse)),e=cf;return e}).once()(),es=re(({camera:r})=>{let e;if(r.isArrayCamera&&r.cameras.length>0){const t=[];for(const n of r.cameras)t.push(n.matrixWorldInverse);Iu===null?Iu=Di(t).setGroup(Ke).setName("cameraViewMatrices"):Iu.array=t,e=Iu.element(r.isMultiViewCamera?fl("gl_ViewID_OVR"):qh).toConst("cameraViewMatrix")}else uf===null&&(uf=qe(r.matrixWorldInverse).setName("cameraViewMatrix").setGroup(Ke).onRenderUpdate(({camera:t})=>t.matrixWorldInverse)),e=uf;return e}).once()(),pD=re(({camera:r})=>{let e;if(r.isArrayCamera&&r.cameras.length>0){const t=[];for(let n=0,i=r.cameras.length;n<i;n++)t.push(new P);Bu===null?Bu=Di(t).setGroup(Ke).setName("cameraPositions").onRenderUpdate(({camera:n},i)=>{const s=n.cameras,o=i.array;for(let a=0,l=s.length;a<l;a++)o[a].setFromMatrixPosition(s[a].matrixWorld)}):Bu.array=t,e=Bu.element(r.isMultiViewCamera?fl("gl_ViewID_OVR"):qh).toConst("cameraPosition")}else hf===null&&(hf=qe(new P).setName("cameraPosition").setGroup(Ke).onRenderUpdate(({camera:t},n)=>n.value.setFromMatrixPosition(t.matrixWorld))),e=hf;return e}).once()(),rx=new Fc;class Yt extends Ve{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=Ze.OBJECT,this.uniformNode=new Vc(null)}generateNodeType(){const e=this.scope;if(e===Yt.WORLD_MATRIX)return"mat4";if(e===Yt.POSITION||e===Yt.VIEW_POSITION||e===Yt.DIRECTION||e===Yt.SCALE)return"vec3";if(e===Yt.RADIUS)return"float"}update(e){const t=this.object3d,n=this.uniformNode,i=this.scope;if(i===Yt.WORLD_MATRIX)n.value=t.matrixWorld;else if(i===Yt.POSITION)n.value=n.value||new P,n.value.setFromMatrixPosition(t.matrixWorld);else if(i===Yt.SCALE)n.value=n.value||new P,n.value.setFromMatrixScale(t.matrixWorld);else if(i===Yt.DIRECTION)n.value=n.value||new P,t.getWorldDirection(n.value);else if(i===Yt.VIEW_POSITION){const s=e.camera;n.value=n.value||new P,n.value.setFromMatrixPosition(t.matrixWorld),n.value.applyMatrix4(s.matrixWorldInverse)}else if(i===Yt.RADIUS){const s=e.object.geometry;s.boundingSphere===null&&s.computeBoundingSphere(),rx.copy(s.boundingSphere).applyMatrix4(t.matrixWorld),n.value=rx.radius}}generate(e){const t=this.scope;return t===Yt.WORLD_MATRIX?this.uniformNode.nodeType="mat4":t===Yt.POSITION||t===Yt.VIEW_POSITION||t===Yt.DIRECTION||t===Yt.SCALE?this.uniformNode.nodeType="vec3":t===Yt.RADIUS&&(this.uniformNode.nodeType="float"),this.uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}Yt.WORLD_MATRIX="worldMatrix";Yt.POSITION="position";Yt.SCALE="scale";Yt.VIEW_POSITION="viewPosition";Yt.DIRECTION="direction";Yt.RADIUS="radius";class Gi extends Yt{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}Gi.DIRECTION;const To=be(Gi,Gi.WORLD_MATRIX);Gi.POSITION;Gi.SCALE;Gi.VIEW_POSITION;Gi.RADIUS;const mD=qe(new Je).onObjectUpdate(({object:r},e)=>e.value.getNormalMatrix(r.matrixWorld)),Hc=re(r=>r.context.modelViewMatrix||gD).once()().toVar("modelViewMatrix"),gD=es.mul(To),sx=re(r=>(r.context.isHighPrecisionModelViewMatrix=!0,qe("mat4").onObjectUpdate(({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))).once()().toVar("highpModelViewMatrix"),ox=re(r=>{const e=r.context.isHighPrecisionModelViewMatrix;return qe("mat3").onObjectUpdate(({object:t,camera:n})=>(e!==!0&&t.modelViewMatrix.multiplyMatrices(n.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix)))}).once()().toVar("highpModelNormalViewMatrix"),_D=re(r=>r.shaderStage!=="fragment"?(Kt("TSL: `clipSpace` is only available in fragment stage."),et()):r.context.clipSpace.toVarying("v_clipSpace")).once()(),jh=Is("position","vec3"),Tn=jh.toVarying("positionLocal"),Eh=jh.toVarying("positionPrevious"),Ja=re(r=>To.mul(Tn).xyz.toVarying(r.getSubBuildProperty("v_positionWorld")),"vec3").once(["POSITION"])(),Dv=re(()=>Tn.transformDirection(To).toVarying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),"vec3").once(["POSITION"])(),dn=re(r=>{if(r.shaderStage==="fragment"&&r.material.vertexNode){const e=fD.mul(_D);return e.xyz.div(e.w).toVar("positionView")}return r.context.setupPositionView().toVarying("v_positionView")},"vec3").once(["POSITION","VERTEX"])(),$t=re(r=>{let e;return r.camera.isOrthographicCamera?e=te(0,0,1):e=dn.negate().toVarying("v_positionViewDirection").normalize(),e.toVar("positionViewDirection")},"vec3").once(["POSITION"])();class xD extends Ve{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){if(e.shaderStage!=="fragment")return"true";const{material:t}=e;return t.side===Lt?"false":e.getFrontFacing()}}const yD=be(xD),Lv=J(yD).mul(2).sub(1),Wc=re(([r],{material:e})=>{const t=e.side;return t===Lt?r=r.mul(-1):t===Nn&&(r=r.mul(Lv)),r}),Uv=Is("normal","vec3"),wr=re(r=>r.geometry.hasAttribute("normal")===!1?(ae('TSL: Vertex attribute "normal" not found on geometry.'),te(0,1,0)):Uv,"vec3").once()().toVar("normalLocal"),vD=dn.dFdx().cross(dn.dFdy()).normalize().toVar("normalFlat"),Ac=re(r=>{let e;return r.isFlatShading()?e=vD:e=Fv(wr).toVarying("v_normalViewGeometry").normalize(),e},"vec3").once()().toVar("normalViewGeometry"),bD=re(r=>{let e=Ac.transformDirection(es);return r.isFlatShading()!==!0&&(e=e.toVarying("v_normalWorldGeometry")),e.normalize().toVar("normalWorldGeometry")},"vec3").once()(),vt=re(r=>{let e;return r.subBuildFn==="NORMAL"||r.subBuildFn==="VERTEX"?(e=Ac,r.isFlatShading()!==!0&&(e=Wc(e))):e=r.context.setupNormal().context({getUV:null,getTextureLevel:null}),e},"vec3").once(["NORMAL","VERTEX"])().toVar("normalView"),ml=vt.transformDirection(es).toVar("normalWorld"),ao=re(({subBuildFn:r,context:e})=>{let t;return r==="NORMAL"||r==="VERTEX"?t=vt:t=e.setupClearcoatNormal().context({getUV:null,getTextureLevel:null}),t},"vec3").once(["NORMAL","VERTEX"])().toVar("clearcoatNormalView"),SD=re(([r,e=To])=>{const t=On(e),n=r.div(te(t[0].dot(t[0]),t[1].dot(t[1]),t[2].dot(t[2])));return t.mul(n).xyz}),Fv=re(([r],e)=>{const t=e.context.modelNormalViewMatrix;if(t)return t.transformDirection(r);const n=mD.mul(r);return es.transformDirection(n)});re(()=>(ae('TSL: "transformedNormalView" is deprecated. Use "normalView" instead.'),vt)).once(["NORMAL","VERTEX"])();re(()=>(ae('TSL: "transformedNormalWorld" is deprecated. Use "normalWorld" instead.'),ml)).once(["NORMAL","VERTEX"])();re(()=>(ae('TSL: "transformedClearcoatNormalView" is deprecated. Use "clearcoatNormalView" instead.'),ao)).once(["NORMAL","VERTEX"])();const df=new pt,TD=qe(0).onReference(({material:r})=>r).onObjectUpdate(({material:r})=>r.refractionRatio),ff=qe(1).onReference(({material:r})=>r).onObjectUpdate(function({material:r,scene:e}){return r.envMap?r.envMapIntensity:e.environmentIntensity}),Iv=qe(new pt).onReference(function(r){return r.material}).onObjectUpdate(function({material:r,scene:e}){const t=e.environment!==null&&r.envMap===null?e.environmentRotation:r.envMapRotation;return t?df.makeRotationFromEuler(t).transpose():df.identity(),df}),MD=$t.negate().reflect(vt),ED=$t.negate().refract(vt,TD),AD=MD.transformDirection(es).toVar("reflectVector"),wD=ED.transformDirection(es).toVar("reflectVector"),RD=new sl;class CD extends zc{static get type(){return"CubeTextureNode"}constructor(e,t=null,n=null,i=null){super(e,t,n,i),this.isCubeTextureNode=!0}getInputType(){return this.value.isDepthTexture===!0?"cubeDepthTexture":"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===Ki?AD:e.mapping===Sr?wD:(ce('CubeTextureNode: Mapping "%s" not supported.',e.mapping),te(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const n=this.value;return n.isDepthTexture===!0?e.renderer.coordinateSystem===Tr?te(t.x,t.y.negate(),t.z):t:(t=Iv.mul(t),(e.renderer.coordinateSystem===Tr||!n.isRenderTargetTexture)&&(t=te(t.x.negate(),t.yz)),t)}generateUV(e,t){return t.build(e,this.sampler===!0?"vec3":"ivec3")}}const ND=It(CD).setParameterLength(1,4).setName("cubeTexture"),li=(r=RD,e=null,t=null,n=null)=>{let i;return r&&r.isCubeTextureNode===!0?(i=Ge(r.clone()),i.referenceNode=r,e!==null&&(i.uvNode=Ge(e)),t!==null&&(i.levelNode=Ge(t)),n!==null&&(i.biasNode=Ge(n))):i=ND(r,e,t,n),i};class PD extends hl{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}generateNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),n=this.referenceNode.getNodeType(e),i=this.getNodeType(e);return e.format(t,n,i)}}class Xm extends Ve{static get type(){return"ReferenceNode"}constructor(e,t,n=null,i=null){super(),this.property=e,this.uniformType=t,this.object=n,this.count=i,this.properties=e.split("."),this.reference=n,this.node=null,this.group=null,this.name=null,this.updateType=Ze.OBJECT}element(e){return new PD(this,Ge(e))}setGroup(e){return this.group=e,this}setName(e){return this.name=e,this}label(e){return ae('TSL: "label()" has been deprecated. Use "setName()" instead.'),this.setName(e)}setNodeType(e){let t=null;this.count!==null?t=Nv(null,e,this.count):Array.isArray(this.getValueFromReference())?t=Di(null,e):e==="texture"?t=Vt(null):e==="cubeTexture"?t=li(null):t=qe(null,e),this.group!==null&&t.setGroup(this.group),this.name!==null&&t.setName(this.name),this.node=t}generateNodeType(e){return this.node===null&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let n=e[t[0]];for(let i=1;i<t.length;i++)n=n[t[i]];return n}updateReference(e){return this.reference=this.object!==null?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);const e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}const Jt=(r,e,t)=>new Xm(r,e,t),ax=(r,e,t,n)=>new Xm(r,e,n,t);class DD extends Xm{static get type(){return"MaterialReferenceNode"}constructor(e,t,n=null){super(e,t,n),this.material=n,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=this.material!==null?this.material:e.material,this.reference}}const ms=(r,e,t=null)=>new DD(r,e,t),Bv=dl(),LD=dn.dFdx(),UD=dn.dFdy(),Ov=Bv.dFdx(),kv=Bv.dFdy(),Gv=vt,Vv=UD.cross(Gv),zv=Gv.cross(LD),Tp=Vv.mul(Ov.x).add(zv.mul(kv.x)),Mp=Vv.mul(Ov.y).add(zv.mul(kv.y)),lx=Tp.dot(Tp).max(Mp.dot(Mp)),Hv=lx.equal(0).select(0,lx.inverseSqrt()),FD=Tp.mul(Hv).toVar("tangentViewFrame"),ID=Mp.mul(Hv).toVar("bitangentViewFrame"),Wv=Is("tangent","vec4"),Ah=Wv.xyz.toVar("tangentLocal"),$v=re(r=>{let e;return r.subBuildFn==="VERTEX"||r.geometry.hasAttribute("tangent")?e=Hc.mul(et(Ah,0)).xyz.toVarying("v_tangentView").normalize():e=FD,r.isFlatShading()!==!0&&(e=Wc(e)),e},"vec3").once(["NORMAL","VERTEX"])().toVar("tangentView"),BD=re(([r,e],t)=>{let n=r.mul(Wv.w).xyz;return t.subBuildFn==="NORMAL"&&t.isFlatShading()!==!0&&(n=n.toVarying(e)),n}).once(["NORMAL"]),OD=re(r=>{let e;return r.subBuildFn==="VERTEX"||r.geometry.hasAttribute("tangent")?e=BD(vt.cross($v),"v_bitangentView").normalize():e=ID,r.isFlatShading()!==!0&&(e=Wc(e)),e},"vec3").once(["NORMAL","VERTEX"])().toVar("bitangentView"),$l=On($v,OD,vt).toVar("TBNViewMatrix"),kD=re(()=>{let r=va.cross($t);return r=r.cross(va).normalize(),r=Dt(r,vt,to.mul(Wr.oneMinus()).oneMinus().pow2().pow2()).normalize(),r}).once()(),GD=r=>Ge(r).mul(.5).add(.5),cx=r=>te(r,Ps(Gm(J(1).sub(bo(r,r)))));class VD extends xn{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=ji,this.unpackNormalMode=ld}setup(e){const{normalMapType:t,scaleNode:n,unpackNormalMode:i}=this;let s=this.node.mul(2).sub(1);if(t===ji?i===Y0?s=cx(s.xy):i===OS?s=cx(s.yw):i!==ld&&ce(`THREE.NodeMaterial: Unexpected unpack normal mode: ${i}`):i!==ld&&ce(`THREE.NodeMaterial: Normal map type '${t}' is not compatible with unpack normal mode '${i}'`),n!==null){let a=n;e.isFlatShading()===!0&&(a=Wc(a)),s=te(s.xy.mul(a),s.z)}let o=null;return t===j0?o=Fv(s):t===ji?o=$l.mul(s).normalize():(ce(`NodeMaterial: Unsupported normal map type: ${t}`),o=vt),o}}const ux=It(VD).setParameterLength(1,2),zD=re(({textureNode:r,bumpScale:e})=>{const t=i=>r.isolate().context({getUV:s=>i(s.uvNode||dl()),forceUVContext:!0}),n=J(t(i=>i));return ke(J(t(i=>i.add(i.dFdx()))).sub(n),J(t(i=>i.add(i.dFdy()))).sub(n)).mul(e)}),HD=re(r=>{const{surf_pos:e,surf_norm:t,dHdxy:n}=r,i=e.dFdx().normalize(),s=e.dFdy().normalize(),o=t,a=s.cross(o),l=o.cross(i),c=i.dot(a).mul(Lv),u=c.sign().mul(n.x.mul(a).add(n.y.mul(l)));return c.abs().mul(t).sub(u).normalize()});class WD extends xn{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=this.scaleNode!==null?this.scaleNode:1,t=zD({textureNode:this.textureNode,bumpScale:e});return HD({surf_pos:dn,surf_norm:vt,dHdxy:t})}}const $D=It(WD).setParameterLength(1,2),hx=new Map;class ie extends Ve{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let n=hx.get(e);return n===void 0&&(n=ms(e,t),hx.set(e,n)),n}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache(e==="map"?"map":e+"Map","texture")}setup(e){const t=e.context.material,n=this.scope;let i=null;if(n===ie.COLOR){const s=t.color!==void 0?this.getColor(n):te();t.map&&t.map.isTexture===!0?i=s.mul(this.getTexture("map")):i=s}else if(n===ie.OPACITY){const s=this.getFloat(n);t.alphaMap&&t.alphaMap.isTexture===!0?i=s.mul(this.getTexture("alpha")):i=s}else if(n===ie.SPECULAR_STRENGTH)t.specularMap&&t.specularMap.isTexture===!0?i=this.getTexture("specular").r:i=J(1);else if(n===ie.SPECULAR_INTENSITY){const s=this.getFloat(n);t.specularIntensityMap&&t.specularIntensityMap.isTexture===!0?i=s.mul(this.getTexture(n).a):i=s}else if(n===ie.SPECULAR_COLOR){const s=this.getColor(n);t.specularColorMap&&t.specularColorMap.isTexture===!0?i=s.mul(this.getTexture(n).rgb):i=s}else if(n===ie.ROUGHNESS){const s=this.getFloat(n);t.roughnessMap&&t.roughnessMap.isTexture===!0?i=s.mul(this.getTexture(n).g):i=s}else if(n===ie.METALNESS){const s=this.getFloat(n);t.metalnessMap&&t.metalnessMap.isTexture===!0?i=s.mul(this.getTexture(n).b):i=s}else if(n===ie.EMISSIVE){const s=this.getFloat("emissiveIntensity"),o=this.getColor(n).mul(s);t.emissiveMap&&t.emissiveMap.isTexture===!0?i=o.mul(this.getTexture(n)):i=o}else if(n===ie.NORMAL)t.normalMap?(i=ux(this.getTexture("normal"),this.getCache("normalScale","vec2")),i.normalMapType=t.normalMapType,(t.normalMap.format==In||t.normalMap.format==Us||t.normalMap.format==Ls)&&(i.unpackNormalMode=Y0)):t.bumpMap?i=$D(this.getTexture("bump").r,this.getFloat("bumpScale")):i=vt;else if(n===ie.CLEARCOAT){const s=this.getFloat(n);t.clearcoatMap&&t.clearcoatMap.isTexture===!0?i=s.mul(this.getTexture(n).r):i=s}else if(n===ie.CLEARCOAT_ROUGHNESS){const s=this.getFloat(n);t.clearcoatRoughnessMap&&t.clearcoatRoughnessMap.isTexture===!0?i=s.mul(this.getTexture(n).r):i=s}else if(n===ie.CLEARCOAT_NORMAL)t.clearcoatNormalMap?i=ux(this.getTexture(n),this.getCache(n+"Scale","vec2")):i=vt;else if(n===ie.SHEEN){const s=this.getColor("sheenColor").mul(this.getFloat("sheen"));t.sheenColorMap&&t.sheenColorMap.isTexture===!0?i=s.mul(this.getTexture("sheenColor").rgb):i=s}else if(n===ie.SHEEN_ROUGHNESS){const s=this.getFloat(n);t.sheenRoughnessMap&&t.sheenRoughnessMap.isTexture===!0?i=s.mul(this.getTexture(n).a):i=s,i=i.clamp(1e-4,1)}else if(n===ie.ANISOTROPY)if(t.anisotropyMap&&t.anisotropyMap.isTexture===!0){const s=this.getTexture(n);i=Um(Ul.x,Ul.y,Ul.y.negate(),Ul.x).mul(s.rg.mul(2).sub(ke(1)).normalize().mul(s.b))}else i=Ul;else if(n===ie.IRIDESCENCE_THICKNESS){const s=Jt("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const o=Jt("0","float",t.iridescenceThicknessRange);i=s.sub(o).mul(this.getTexture(n).g).add(o)}else i=s}else if(n===ie.TRANSMISSION){const s=this.getFloat(n);t.transmissionMap?i=s.mul(this.getTexture(n).r):i=s}else if(n===ie.THICKNESS){const s=this.getFloat(n);t.thicknessMap?i=s.mul(this.getTexture(n).g):i=s}else if(n===ie.IOR)i=this.getFloat(n);else if(n===ie.LIGHT_MAP)i=this.getTexture(n).rgb.mul(this.getFloat("lightMapIntensity"));else if(n===ie.AO)i=this.getTexture(n).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else if(n===ie.LINE_DASH_OFFSET)i=t.dashOffset?this.getFloat(n):J(0);else{const s=this.getNodeType(e);i=this.getCache(n,s)}return i}}ie.ALPHA_TEST="alphaTest";ie.COLOR="color";ie.OPACITY="opacity";ie.SHININESS="shininess";ie.SPECULAR="specular";ie.SPECULAR_STRENGTH="specularStrength";ie.SPECULAR_INTENSITY="specularIntensity";ie.SPECULAR_COLOR="specularColor";ie.REFLECTIVITY="reflectivity";ie.ROUGHNESS="roughness";ie.METALNESS="metalness";ie.NORMAL="normal";ie.CLEARCOAT="clearcoat";ie.CLEARCOAT_ROUGHNESS="clearcoatRoughness";ie.CLEARCOAT_NORMAL="clearcoatNormal";ie.EMISSIVE="emissive";ie.ROTATION="rotation";ie.SHEEN="sheen";ie.SHEEN_ROUGHNESS="sheenRoughness";ie.ANISOTROPY="anisotropy";ie.IRIDESCENCE="iridescence";ie.IRIDESCENCE_IOR="iridescenceIOR";ie.IRIDESCENCE_THICKNESS="iridescenceThickness";ie.IOR="ior";ie.TRANSMISSION="transmission";ie.THICKNESS="thickness";ie.ATTENUATION_DISTANCE="attenuationDistance";ie.ATTENUATION_COLOR="attenuationColor";ie.LINE_SCALE="scale";ie.LINE_DASH_SIZE="dashSize";ie.LINE_GAP_SIZE="gapSize";ie.LINE_WIDTH="linewidth";ie.LINE_DASH_OFFSET="dashOffset";ie.POINT_SIZE="size";ie.DISPERSION="dispersion";ie.LIGHT_MAP="light";ie.AO="ao";const XD=be(ie,ie.ALPHA_TEST),qD=be(ie,ie.COLOR),jD=be(ie,ie.SHININESS),YD=be(ie,ie.EMISSIVE),Xv=be(ie,ie.OPACITY),KD=be(ie,ie.SPECULAR),dx=be(ie,ie.SPECULAR_INTENSITY),ZD=be(ie,ie.SPECULAR_COLOR),fh=be(ie,ie.SPECULAR_STRENGTH),pf=be(ie,ie.REFLECTIVITY),QD=be(ie,ie.ROUGHNESS),JD=be(ie,ie.METALNESS),eL=be(ie,ie.NORMAL),tL=be(ie,ie.CLEARCOAT),nL=be(ie,ie.CLEARCOAT_ROUGHNESS),iL=be(ie,ie.CLEARCOAT_NORMAL),rL=be(ie,ie.ROTATION),sL=be(ie,ie.SHEEN),oL=be(ie,ie.SHEEN_ROUGHNESS),aL=be(ie,ie.ANISOTROPY),lL=be(ie,ie.IRIDESCENCE),cL=be(ie,ie.IRIDESCENCE_IOR),uL=be(ie,ie.IRIDESCENCE_THICKNESS),hL=be(ie,ie.TRANSMISSION),dL=be(ie,ie.THICKNESS),fL=be(ie,ie.IOR),pL=be(ie,ie.ATTENUATION_DISTANCE),mL=be(ie,ie.ATTENUATION_COLOR),gL=be(ie,ie.LINE_SCALE),_L=be(ie,ie.LINE_DASH_SIZE),xL=be(ie,ie.LINE_GAP_SIZE);ie.LINE_WIDTH;const yL=be(ie,ie.LINE_DASH_OFFSET),vL=be(ie,ie.POINT_SIZE),bL=be(ie,ie.DISPERSION),qv=be(ie,ie.LIGHT_MAP),SL=be(ie,ie.AO),Ul=qe(new pe).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))}),TL=re(r=>r.context.setupModelViewProjection(),"vec4").once()().toVarying("v_modelViewProjection");class ML extends hl{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}getMemberType(e,t){const n=this.storageBufferNode.structTypeNode;return n?n.getMemberType(e,t):"void"}setup(e){return e.isAvailable("storageBuffer")===!1&&this.node.isPBO===!0&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let n;const i=e.context.assign;if(e.isAvailable("storageBuffer")===!1?this.node.isPBO===!0&&i!==!0&&(this.node.value.isInstancedBufferAttribute||e.shaderStage!=="compute")?n=e.generatePBO(this):n=this.node.build(e):n=super.generate(e),i!==!0){const s=this.getNodeType(e);n=e.format(n,s,t)}return n}}const EL=It(ML).setParameterLength(2);class AL extends $m{static get type(){return"StorageBufferNode"}constructor(e,t=null,n=0){let i,s=null;t&&t.isStruct?(i="struct",s=t.layout,(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(n=e.count)):t===null&&(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)?(i=Wy(e.itemSize),n=e.count):i=t,super(e,i,n),this.isStorageBufferNode=!0,this.structTypeNode=s,this.access=Fi.READ_WRITE,this.isAtomic=!1,this.isPBO=!1,this._attribute=null,this._varying=null,this.global=!0,e.isStorageBufferAttribute!==!0&&e.isStorageInstancedBufferAttribute!==!0&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){let t;if(this.bufferCount===0){let n=e.globalCache.getData(this.value);n===void 0&&(n={node:this},e.globalCache.setData(this.value,n)),t=n.node.id}else t=this.id;return String(t)}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return EL(this,e)}setPBO(e){return this.isPBO=e,this}getPBO(){return this.isPBO}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(Fi.READ_ONLY)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return this._attribute===null&&(this._attribute=Tv(this.value),this._varying=Do(this._attribute)),{attribute:this._attribute,varying:this._varying}}generateNodeType(e){if(this.structTypeNode!==null)return this.structTypeNode.getNodeType(e);if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generateNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}getMemberType(e,t){return this.structTypeNode!==null?this.structTypeNode.getMemberType(e,t):"void"}generate(e){if(this.structTypeNode!==null&&this.structTypeNode.build(e),e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:n}=this.getAttributeData(),i=n.build(e);return e.registerTransform(i,t),i}}const fx=(r,e=null,t=0)=>new AL(r,e,t);class wL extends Ve{static get type(){return"InstanceNode"}constructor(e,t,n=null){super("void"),this.count=e,this.instanceMatrix=t,this.instanceColor=n,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=Ze.FRAME,this.buffer=null,this.bufferColor=null,this.previousInstanceMatrixNode=null}get isStorageMatrix(){const{instanceMatrix:e}=this;return e&&e.isStorageInstancedBufferAttribute===!0}get isStorageColor(){const{instanceColor:e}=this;return e&&e.isStorageInstancedBufferAttribute===!0}setup(e){let{instanceMatrixNode:t,instanceColorNode:n}=this;t===null&&(t=this._createInstanceMatrixNode(!0,e),this.instanceMatrixNode=t);const{instanceColor:i,isStorageColor:s}=this;if(i&&n===null){if(s)n=fx(i,"vec3",Math.max(i.count,1)).element(Sa);else{const a=new IT(i.array,3),l=i.usage===mh?ix:nx;this.bufferColor=a,n=te(l(a,"vec3",3,0))}this.instanceColorNode=n}const o=t.mul(Tn).xyz;if(Tn.assign(o),e.needsPreviousData()&&Eh.assign(this.getPreviousInstancedPosition(e)),e.hasGeometryAttribute("normal")){const a=SD(wr,t);wr.assign(a)}this.instanceColorNode!==null&&Mh("vec3","vInstanceColor").assign(this.instanceColorNode)}update(e){this.buffer!==null&&this.isStorageMatrix!==!0&&(this.buffer.clearUpdateRanges(),this.buffer.updateRanges.push(...this.instanceMatrix.updateRanges),this.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMatrix.version)),this.instanceColor&&this.bufferColor!==null&&this.isStorageColor!==!0&&(this.bufferColor.clearUpdateRanges(),this.bufferColor.updateRanges.push(...this.instanceColor.updateRanges),this.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceColor.version)),this.previousInstanceMatrixNode!==null&&e.object.previousInstanceMatrix.array.set(this.instanceMatrix.array)}getPreviousInstancedPosition(e){const t=e.object;return this.previousInstanceMatrixNode===null&&(t.previousInstanceMatrix=this.instanceMatrix.clone(),this.previousInstanceMatrixNode=this._createInstanceMatrixNode(!1,e)),this.previousInstanceMatrixNode.mul(Eh).xyz}_createInstanceMatrixNode(e,t){let n;const{instanceMatrix:i}=this,{count:s}=i;if(this.isStorageMatrix)n=fx(i,"mat4",Math.max(s,1)).element(Sa);else if(s*16*4<=t.getUniformBufferLimit())n=Nv(i.array,"mat4",Math.max(s,1)).element(Sa);else{const a=new NM(i.array,16,1);e===!0&&(this.buffer=a);const l=i.usage===mh?ix:nx,c=[l(a,"vec4",16,0),l(a,"vec4",16,4),l(a,"vec4",16,8),l(a,"vec4",16,12)];n=uo(...c)}return n}}class RL extends wL{static get type(){return"InstancedMeshNode"}constructor(e){const{count:t,instanceMatrix:n,instanceColor:i}=e;super(t,n,i),this.instancedMesh=e}}const CL=It(RL).setParameterLength(1);class NL extends Ve{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){this.batchingIdNode===null&&(e.getDrawIndex()===null?this.batchingIdNode=Sa:this.batchingIdNode=HP);const n=re(([p])=>{const g=Zt(Ta(Ni(this.batchMesh._indirectTexture),0).x).toConst(),m=Zt(p).mod(g).toConst(),_=Zt(p).div(g).toConst();return Ni(this.batchMesh._indirectTexture,dr(m,_)).x}).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]})(Zt(this.batchingIdNode)),i=this.batchMesh._matricesTexture,s=Zt(Ta(Ni(i),0).x).toConst(),o=J(n).mul(4).toInt().toConst(),a=o.mod(s).toConst(),l=o.div(s).toConst(),c=uo(Ni(i,dr(a,l)),Ni(i,dr(a.add(1),l)),Ni(i,dr(a.add(2),l)),Ni(i,dr(a.add(3),l))),u=this.batchMesh._colorsTexture;if(u!==null){const g=re(([m])=>{const _=Zt(Ta(Ni(u),0).x).toConst(),x=m,y=x.mod(_).toConst(),b=x.div(_).toConst();return Ni(u,dr(y,b)).rgb}).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]})(n);Mh("vec3","vBatchColor").assign(g)}const h=On(c);Tn.assign(c.mul(Tn));const d=wr.div(te(h[0].dot(h[0]),h[1].dot(h[1]),h[2].dot(h[2]))),f=h.mul(d).xyz;wr.assign(f),e.hasGeometryAttribute("tangent")&&Ah.mulAssign(h)}}const PL=It(NL).setParameterLength(1),px=new WeakMap;class DL extends Ve{static get type(){return"SkinningNode"}constructor(e){super("void"),this.skinnedMesh=e,this.updateType=Ze.OBJECT,this.skinIndexNode=Is("skinIndex","uvec4"),this.skinWeightNode=Is("skinWeight","vec4"),this.bindMatrixNode=Jt("bindMatrix","mat4"),this.bindMatrixInverseNode=Jt("bindMatrixInverse","mat4"),this.boneMatricesNode=ax("skeleton.boneMatrices","mat4",e.skeleton.bones.length),this.positionNode=Tn,this.toPositionNode=Tn,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=this.positionNode){const{skinIndexNode:n,skinWeightNode:i,bindMatrixNode:s,bindMatrixInverseNode:o}=this,a=e.element(n.x),l=e.element(n.y),c=e.element(n.z),u=e.element(n.w),h=s.mul(t),d=fi(a.mul(i.x).mul(h),l.mul(i.y).mul(h),c.mul(i.z).mul(h),u.mul(i.w).mul(h));return o.mul(d).xyz}getSkinnedNormalAndTangent(e=this.boneMatricesNode,t=wr,n=Ah){const{skinIndexNode:i,skinWeightNode:s,bindMatrixNode:o,bindMatrixInverseNode:a}=this,l=e.element(i.x),c=e.element(i.y),u=e.element(i.z),h=e.element(i.w);let d=fi(s.x.mul(l),s.y.mul(c),s.z.mul(u),s.w.mul(h));d=a.mul(d).mul(o);const f=d.transformDirection(t).xyz,p=d.transformDirection(n).xyz;return{skinNormal:f,skinTangent:p}}getPreviousSkinnedPosition(e){const t=e.object;return this.previousBoneMatricesNode===null&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=ax("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Eh)}setup(e){e.needsPreviousData()&&Eh.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(this.toPositionNode&&this.toPositionNode.assign(t),e.hasGeometryAttribute("normal")){const{skinNormal:n,skinTangent:i}=this.getSkinnedNormalAndTangent();wr.assign(n),e.hasGeometryAttribute("tangent")&&Ah.assign(i)}return t}generate(e,t){if(t!=="void")return super.generate(e,t)}update(e){const t=e.object&&e.object.skeleton?e.object.skeleton:this.skinnedMesh.skeleton;px.get(t)!==e.frameId&&(px.set(t,e.frameId),this.previousBoneMatricesNode!==null&&(t.previousBoneMatrices===null&&(t.previousBoneMatrices=new Float32Array(t.boneMatrices)),t.previousBoneMatrices.set(t.boneMatrices)),t.update())}}const LL=r=>new DL(r);class UL extends Ve{static get type(){return"LoopNode"}constructor(e=[]){super("void"),this.params=e}getVarName(e){return String.fromCharCode(105+e)}getProperties(e){const t=e.getNodeProperties(this);if(t.stackNode!==void 0)return t;const n={};for(let a=0,l=this.params.length-1;a<l;a++){const c=this.params[a],u=c.isNode!==!0&&c.name||this.getVarName(a),h=c.isNode!==!0&&c.type||"int";n[u]=mr(u,h)}const i=e.addStack(),s=this.params[this.params.length-1](n);t.returnsNode=s.context({nodeLoop:s}),t.stackNode=i;const o=this.params[0];if(o.isNode!==!0&&typeof o.update=="function"){const a=re(this.params[0].update)(n);t.updateNode=a.context({nodeLoop:a})}return e.removeStack(),t}setup(e){if(this.getProperties(e),e.fnCall){const t=e.getDataFromNode(e.fnCall.shaderNode);t.hasLoop=!0}}generate(e){const t=this.getProperties(e),n=this.params,i=t.stackNode;for(let o=0,a=n.length-1;o<a;o++){const l=n[o];let c=!1,u=null,h=null,d=null,f=null,p=null,g=null;l.isNode?l.getNodeType(e)==="bool"?(c=!0,f="bool",h=l.build(e,f)):(f="int",d=this.getVarName(o),u="0",h=l.build(e,f),p="<"):(f=l.type||"int",d=l.name||this.getVarName(o),u=l.start,h=l.end,p=l.condition,g=l.update,typeof u=="number"?u=e.generateConst(f,u):u&&u.isNode&&(u=u.build(e,f)),typeof h=="number"?h=e.generateConst(f,h):h&&h.isNode&&(h=h.build(e,f)),u!==void 0&&h===void 0?(u=u+" - 1",h="0",p=">="):h!==void 0&&u===void 0&&(u="0",p="<"),p===void 0&&(Number(u)>Number(h)?p=">=":p="<"));let m;if(c)m=`while ( ${h} )`;else{const _={start:u,end:h},x=_.start,y=_.end;let b;const M=()=>p.includes("<")?"+=":"-=";if(g!=null)switch(typeof g){case"function":b=e.flowStagesNode(t.updateNode,"void").code.replace(/\t|;/g,"");break;case"number":b=d+" "+M()+" "+e.generateConst(f,g);break;case"string":b=d+" "+g;break;default:g.isNode?b=d+" "+M()+" "+g.build(e):(ce("TSL: 'Loop( { update: ... } )' is not a function, string or number.",this.stackTrace),b="break /* invalid update */")}else f==="int"||f==="uint"?g=p.includes("<")?"++":"--":g=M()+" 1.",b=d+" "+g;const S=e.getVar(f,d)+" = "+x,E=d+" "+p+" "+y;m=`for ( ${S}; ${E}; ${b} )`}e.addFlowCode((o===0?`
4643
+ `,Sc(o)}return n}}const eD=(r,e=null)=>new JP(Ge(r),e).toStack();ee("debug",eD);class wv extends Vi{constructor(){super(),this._renderer=null,this.currentFrame=null}get nodeFrame(){return this._renderer._nodes.nodeFrame}setRenderer(e){return this._renderer=e,this}getRenderer(){return this._renderer}init(){}begin(){}finish(){}inspect(){}computeAsync(){}beginCompute(){}finishCompute(){}beginRender(){}finishRender(){}copyTextureToTexture(){}copyFramebufferToTexture(){}}class tD extends Ve{static get type(){return"InspectorNode"}constructor(e,t="",n=null){super(),this.node=e,this.name=t,this.callback=n,this.updateType=Ze.FRAME,this.isInspectorNode=!0}getName(){return this.name||this.node.name}update(e){e.renderer.inspector.inspect(this)}generateNodeType(e){return this.node.getNodeType(e)}setup(e){let t=this.node;return e.context.inspector===!0&&this.callback!==null&&(t=this.callback(t)),e.renderer.backend.isWebGPUBackend!==!0&&e.renderer.inspector.constructor!==wv&&Kt('TSL: ".toInspector()" is only available with WebGPU.'),t}}function nD(r,e="",t=null){return r=Ge(r),r.before(new tD(r,e,t))}ee("toInspector",nD);class Rv extends Ve{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}generateNodeType(e){let t=this.nodeType;if(t===null){const n=this.getAttributeName(e);if(e.hasGeometryAttribute(n)){const i=e.geometry.getAttribute(n);t=e.getTypeFromAttribute(i)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),n=this.getNodeType(e);if(e.hasGeometryAttribute(t)===!0){const s=e.geometry.getAttribute(t),o=e.getTypeFromAttribute(s),a=e.getAttribute(t,o);return e.shaderStage==="vertex"?e.format(a.name,o,n):Do(this).build(e,n)}else return ae(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(n)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const Is=(r,e=null)=>new Rv(r,e),dl=(r=0)=>Is("uv"+(r>0?r:""),"vec2");class iD extends Ve{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const n=this.textureNode.build(e,"property"),i=this.levelNode===null?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${n}, ${i} )`,this.getNodeType(e),t)}}const Ta=It(iD).setParameterLength(1,2);class rD extends Vc{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=Ze.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,n=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(n&&n.width!==void 0){const{width:i,height:s}=n;this.value=Math.log2(Math.max(i,s))}}}const sD=It(rD).setParameterLength(1);class oD extends Error{constructor(e,t=null){super(e),this.name="NodeError",this.stackTrace=t}}const Cv=new fn;class zc extends Vc{static get type(){return"TextureNode"}constructor(e=Cv,t=null,n=null,i=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=n,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.offsetNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=Ze.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this._flipYUniform=null,this.setUpdateMatrix(t===null)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}generateNodeType(){return this.value.isDepthTexture===!0?"float":this.value.type===Ct?"uvec4":this.value.type===Sn?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return dl(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return this._matrixUniform===null&&(this._matrixUniform=qe(this.value.matrix)),this._matrixUniform.mul(te(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this}setupUV(e,t){return e.isFlipY()&&(this._flipYUniform===null&&(this._flipYUniform=qe(!1)),t=t.toVar(),this.sampler?t=this._flipYUniform.select(t.flipY(),t):t=this._flipYUniform.select(t.setY(Zt(Ta(this,this.levelNode).y).sub(t.y).sub(1)),t)),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;const n=this.value;if(!n||n.isTexture!==!0)throw new oD("THREE.TSL: `texture( value )` function expects a valid instance of THREE.Texture().",this.stackTrace);const i=re(()=>{let l=this.uvNode;return(l===null||e.context.forceUVContext===!0)&&e.context.getUV&&(l=e.context.getUV(this,e)),l||(l=this.getDefaultUV()),this.updateMatrix===!0&&(l=this.getTransformedUV(l)),l=this.setupUV(e,l),this.updateType=this._matrixUniform!==null||this._flipYUniform!==null?Ze.OBJECT:Ze.NONE,l})();let s=this.levelNode;s===null&&e.context.getTextureLevel&&(s=e.context.getTextureLevel(this));let o=null,a=null;if(this.compareNode!==null)if(e.renderer.hasCompatibility(wo.TEXTURE_COMPARE))o=this.compareNode;else{const l=n.compareFunction;l===null||l===Ih||l===Os||l===vc||l===Zr?a=this.compareNode:(o=this.compareNode,Kt('TSL: Only "LessCompare", "LessEqualCompare", "GreaterCompare" and "GreaterEqualCompare" are supported for depth texture comparison fallback.'))}t.uvNode=i,t.levelNode=s,t.biasNode=this.biasNode,t.compareNode=o,t.compareStepNode=a,t.gradNode=this.gradNode,t.depthNode=this.depthNode,t.offsetNode=this.offsetNode}generateUV(e,t){return t.build(e,this.sampler===!0?"vec2":"ivec2")}generateOffset(e,t){return t.build(e,"ivec2")}generateSnippet(e,t,n,i,s,o,a,l,c){const u=this.value;let h;return s?h=e.generateTextureBias(u,t,n,s,o,c):l?h=e.generateTextureGrad(u,t,n,l,o,c):a?h=e.generateTextureCompare(u,t,n,a,o,c):this.sampler===!1?h=e.generateTextureLoad(u,t,n,i,o,c):i?h=e.generateTextureLevel(u,t,n,i,o,c):h=e.generateTexture(u,t,n,o,c),h}generate(e,t){const n=this.value,i=e.getNodeProperties(this),s=super.generate(e,"property");if(/^sampler/.test(t))return s+"_sampler";if(e.isReference(t))return s;{const o=e.getDataFromNode(this),a=this.getNodeType(e);let l=o.propertyName;if(l===void 0){const{uvNode:u,levelNode:h,biasNode:d,compareNode:f,compareStepNode:p,depthNode:g,gradNode:m,offsetNode:_}=i,x=this.generateUV(e,u),y=h?h.build(e,"float"):null,b=d?d.build(e,"float"):null,M=g?g.build(e,"int"):null,S=f?f.build(e,"float"):null,E=p?p.build(e,"float"):null,v=m?[m[0].build(e,"vec2"),m[1].build(e,"vec2")]:null,w=_?this.generateOffset(e,_):null;let N=M;N===null&&n.isArrayTexture&&this.isTexture3DNode!==!0&&(N="0");const C=e.getVarFromNode(this);l=e.getPropertyName(C);let F=this.generateSnippet(e,s,x,y,b,N,S,v,w);if(E!==null){const V=n.compareFunction;V===vc||V===Zr?F=Ec(mr(F,a),mr(E,"float")).build(e,a):F=Ec(mr(E,"float"),mr(F,a)).build(e,a)}e.addLineFlowCode(`${l} = ${F}`,this),o.snippet=F,o.propertyName=l}let c=l;return e.needsToWorkingColorSpace(n)&&(c=Hm(mr(c,a),n.colorSpace).setup(e).build(e,a)),e.format(c,a,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}sample(e){const t=this.clone();return t.uvNode=Ge(e),t.referenceNode=this.getBase(),Ge(t)}load(e){return this.sample(e).setSampler(!1)}blur(e){const t=this.clone();t.biasNode=Ge(e).mul(sD(t)),t.referenceNode=this.getBase();const n=t.value;return t.generateMipmaps===!1&&(n&&n.generateMipmaps===!1||n.minFilter===Mt||n.magFilter===Mt)&&(ae("TSL: texture().blur() requires mipmaps and sampling. Use .generateMipmaps=true and .minFilter/.magFilter=THREE.LinearFilter in the Texture."),t.biasNode=null),Ge(t)}level(e){const t=this.clone();return t.levelNode=Ge(e),t.referenceNode=this.getBase(),Ge(t)}size(e){return Ta(this,e)}bias(e){const t=this.clone();return t.biasNode=Ge(e),t.referenceNode=this.getBase(),Ge(t)}getBase(){return this.referenceNode?this.referenceNode.getBase():this}compare(e){const t=this.clone();return t.compareNode=Ge(e),t.referenceNode=this.getBase(),Ge(t)}grad(e,t){const n=this.clone();return n.gradNode=[Ge(e),Ge(t)],n.referenceNode=this.getBase(),Ge(n)}depth(e){const t=this.clone();return t.depthNode=Ge(e),t.referenceNode=this.getBase(),Ge(t)}offset(e){const t=this.clone();return t.offsetNode=Ge(e),t.referenceNode=this.getBase(),Ge(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;t!==null&&(t.value=e.matrix),e.matrixAutoUpdate===!0&&e.updateMatrix();const n=this._flipYUniform;n!==null&&(n.value=e.image instanceof ImageBitmap&&e.flipY===!0||e.isRenderTargetTexture===!0||e.isFramebufferTexture===!0||e.isDepthTexture===!0)}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.offsetNode=this.offsetNode,e}}const aD=It(zc).setParameterLength(1,4).setName("texture"),Vt=(r=Cv,e=null,t=null,n=null)=>{let i;return r&&r.isTextureNode===!0?(i=Ge(r.clone()),i.referenceNode=r.getBase(),e!==null&&(i.uvNode=Ge(e)),t!==null&&(i.levelNode=Ge(t)),n!==null&&(i.biasNode=Ge(n))):i=aD(r,e,t,n),i},Ci=(...r)=>Vt(...r).setSampler(!1);class $m extends Vc{static get type(){return"BufferNode"}constructor(e,t,n=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=n,this.updateRanges=[]}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const Nv=(r,e,t)=>new $m(r,e,t);class lD extends hl{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),n=this.getNodeType(e),i=this.node.getPaddedType();return e.format(t,i,n)}}class cD extends $m{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null),this.array=e,this.elementType=t===null?Sh(e[0]):t,this.paddedType=this.getPaddedType(),this.updateType=Ze.RENDER,this.isArrayBufferNode=!0}generateNodeType(){return this.paddedType}getElementType(){return this.elementType}getPaddedType(){const e=this.elementType;let t="vec4";return e==="mat2"?t="mat2":/mat/.test(e)===!0?t="mat4":e.charAt(0)==="i"?t="ivec4":e.charAt(0)==="u"&&(t="uvec4"),t}update(){const{array:e,value:t}=this,n=this.elementType;if(n==="float"||n==="int"||n==="uint")for(let i=0;i<e.length;i++){const s=i*4;t[s]=e[i]}else if(n==="color")for(let i=0;i<e.length;i++){const s=i*4,o=e[i];t[s]=o.r,t[s+1]=o.g,t[s+2]=o.b||0}else if(n==="mat2")for(let i=0;i<e.length;i++){const s=i*4,o=e[i];t[s]=o.elements[0],t[s+1]=o.elements[1],t[s+2]=o.elements[2],t[s+3]=o.elements[3]}else if(n==="mat3")for(let i=0;i<e.length;i++){const s=i*16,o=e[i];t[s]=o.elements[0],t[s+1]=o.elements[1],t[s+2]=o.elements[2],t[s+4]=o.elements[3],t[s+5]=o.elements[4],t[s+6]=o.elements[5],t[s+8]=o.elements[6],t[s+9]=o.elements[7],t[s+10]=o.elements[8],t[s+15]=1}else if(n==="mat4")for(let i=0;i<e.length;i++){const s=i*16,o=e[i];for(let a=0;a<o.elements.length;a++)t[s+a]=o.elements[a]}else for(let i=0;i<e.length;i++){const s=i*4,o=e[i];t[s]=o.x,t[s+1]=o.y,t[s+2]=o.z||0,t[s+3]=o.w||0}}setup(e){const t=this.array.length,n=this.elementType;let i=Float32Array;const s=this.paddedType,o=e.getTypeLength(s);return n.charAt(0)==="i"&&(i=Int32Array),n.charAt(0)==="u"&&(i=Uint32Array),this.value=new i(t*o),this.bufferCount=t,this.bufferType=s,this.update(),super.setup(e)}element(e){return new lD(this,Ge(e))}}const Pi=(r,e)=>new cD(r,e);class uD extends Ve{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}}const fl=It(uD).setParameterLength(1);let Dl,Ll;class Wt extends Ve{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this._output=null,this.isViewportNode=!0}generateNodeType(){return this.scope===Wt.DPR?"float":this.scope===Wt.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=Ze.NONE;return(this.scope===Wt.SIZE||this.scope===Wt.VIEWPORT||this.scope===Wt.DPR)&&(e=Ze.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Wt.VIEWPORT?t!==null?Ll.copy(t.viewport):(e.getViewport(Ll),Ll.multiplyScalar(e.getPixelRatio())):this.scope===Wt.DPR?this._output.value=e.getPixelRatio():t!==null?(Dl.width=t.width,Dl.height=t.height):e.getDrawingBufferSize(Dl)}setup(){const e=this.scope;let t=null;return e===Wt.SIZE?t=qe(Dl||(Dl=new pe)):e===Wt.VIEWPORT?t=qe(Ll||(Ll=new rt)):e===Wt.DPR?t=qe(1):t=ke(pl.div(Sp)),this._output=t,t}generate(e){if(this.scope===Wt.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const n=e.getNodeProperties(Sp).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${n}.y - ${t}.y )`}return t}return super.generate(e)}}Wt.COORDINATE="coordinate";Wt.VIEWPORT="viewport";Wt.SIZE="size";Wt.UV="uv";Wt.DPR="dpr";const hD=be(Wt,Wt.DPR),fo=be(Wt,Wt.UV),Sp=be(Wt,Wt.SIZE),pl=be(Wt,Wt.COORDINATE),Pv=be(Wt,Wt.VIEWPORT),dD=Pv.zw;Pv.xy;let lf=null,Uu=null,cf=null,Fu=null,uf=null,Iu=null,hf=null,Bu=null;const qh=qe(0,"uint").setName("u_cameraIndex").setGroup(Im("cameraIndex")).toVarying("v_cameraIndex"),so=qe("float").setName("cameraNear").setGroup(Ke).onRenderUpdate(({camera:r})=>r.near),oo=qe("float").setName("cameraFar").setGroup(Ke).onRenderUpdate(({camera:r})=>r.far),ic=re(({camera:r})=>{let e;if(r.isArrayCamera&&r.cameras.length>0){const t=[];for(const n of r.cameras)t.push(n.projectionMatrix);Uu===null?Uu=Pi(t).setGroup(Ke).setName("cameraProjectionMatrices"):Uu.array=t,e=Uu.element(r.isMultiViewCamera?fl("gl_ViewID_OVR"):qh).toConst("cameraProjectionMatrix")}else lf===null&&(lf=qe(r.projectionMatrix).setName("cameraProjectionMatrix").setGroup(Ke).onRenderUpdate(({camera:t})=>t.projectionMatrix)),e=lf;return e}).once()(),fD=re(({camera:r})=>{let e;if(r.isArrayCamera&&r.cameras.length>0){const t=[];for(const n of r.cameras)t.push(n.projectionMatrixInverse);Fu===null?Fu=Pi(t).setGroup(Ke).setName("cameraProjectionMatricesInverse"):Fu.array=t,e=Fu.element(r.isMultiViewCamera?fl("gl_ViewID_OVR"):qh).toConst("cameraProjectionMatrixInverse")}else cf===null&&(cf=qe(r.projectionMatrixInverse).setName("cameraProjectionMatrixInverse").setGroup(Ke).onRenderUpdate(({camera:t})=>t.projectionMatrixInverse)),e=cf;return e}).once()(),es=re(({camera:r})=>{let e;if(r.isArrayCamera&&r.cameras.length>0){const t=[];for(const n of r.cameras)t.push(n.matrixWorldInverse);Iu===null?Iu=Pi(t).setGroup(Ke).setName("cameraViewMatrices"):Iu.array=t,e=Iu.element(r.isMultiViewCamera?fl("gl_ViewID_OVR"):qh).toConst("cameraViewMatrix")}else uf===null&&(uf=qe(r.matrixWorldInverse).setName("cameraViewMatrix").setGroup(Ke).onRenderUpdate(({camera:t})=>t.matrixWorldInverse)),e=uf;return e}).once()(),pD=re(({camera:r})=>{let e;if(r.isArrayCamera&&r.cameras.length>0){const t=[];for(let n=0,i=r.cameras.length;n<i;n++)t.push(new P);Bu===null?Bu=Pi(t).setGroup(Ke).setName("cameraPositions").onRenderUpdate(({camera:n},i)=>{const s=n.cameras,o=i.array;for(let a=0,l=s.length;a<l;a++)o[a].setFromMatrixPosition(s[a].matrixWorld)}):Bu.array=t,e=Bu.element(r.isMultiViewCamera?fl("gl_ViewID_OVR"):qh).toConst("cameraPosition")}else hf===null&&(hf=qe(new P).setName("cameraPosition").setGroup(Ke).onRenderUpdate(({camera:t},n)=>n.value.setFromMatrixPosition(t.matrixWorld))),e=hf;return e}).once()(),rx=new Fc;class Yt extends Ve{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=Ze.OBJECT,this.uniformNode=new Vc(null)}generateNodeType(){const e=this.scope;if(e===Yt.WORLD_MATRIX)return"mat4";if(e===Yt.POSITION||e===Yt.VIEW_POSITION||e===Yt.DIRECTION||e===Yt.SCALE)return"vec3";if(e===Yt.RADIUS)return"float"}update(e){const t=this.object3d,n=this.uniformNode,i=this.scope;if(i===Yt.WORLD_MATRIX)n.value=t.matrixWorld;else if(i===Yt.POSITION)n.value=n.value||new P,n.value.setFromMatrixPosition(t.matrixWorld);else if(i===Yt.SCALE)n.value=n.value||new P,n.value.setFromMatrixScale(t.matrixWorld);else if(i===Yt.DIRECTION)n.value=n.value||new P,t.getWorldDirection(n.value);else if(i===Yt.VIEW_POSITION){const s=e.camera;n.value=n.value||new P,n.value.setFromMatrixPosition(t.matrixWorld),n.value.applyMatrix4(s.matrixWorldInverse)}else if(i===Yt.RADIUS){const s=e.object.geometry;s.boundingSphere===null&&s.computeBoundingSphere(),rx.copy(s.boundingSphere).applyMatrix4(t.matrixWorld),n.value=rx.radius}}generate(e){const t=this.scope;return t===Yt.WORLD_MATRIX?this.uniformNode.nodeType="mat4":t===Yt.POSITION||t===Yt.VIEW_POSITION||t===Yt.DIRECTION||t===Yt.SCALE?this.uniformNode.nodeType="vec3":t===Yt.RADIUS&&(this.uniformNode.nodeType="float"),this.uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}Yt.WORLD_MATRIX="worldMatrix";Yt.POSITION="position";Yt.SCALE="scale";Yt.VIEW_POSITION="viewPosition";Yt.DIRECTION="direction";Yt.RADIUS="radius";class Gi extends Yt{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}Gi.DIRECTION;const To=be(Gi,Gi.WORLD_MATRIX);Gi.POSITION;Gi.SCALE;Gi.VIEW_POSITION;Gi.RADIUS;const mD=qe(new Je).onObjectUpdate(({object:r},e)=>e.value.getNormalMatrix(r.matrixWorld)),Hc=re(r=>r.context.modelViewMatrix||gD).once()().toVar("modelViewMatrix"),gD=es.mul(To),sx=re(r=>(r.context.isHighPrecisionModelViewMatrix=!0,qe("mat4").onObjectUpdate(({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))).once()().toVar("highpModelViewMatrix"),ox=re(r=>{const e=r.context.isHighPrecisionModelViewMatrix;return qe("mat3").onObjectUpdate(({object:t,camera:n})=>(e!==!0&&t.modelViewMatrix.multiplyMatrices(n.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix)))}).once()().toVar("highpModelNormalViewMatrix"),_D=re(r=>r.shaderStage!=="fragment"?(Kt("TSL: `clipSpace` is only available in fragment stage."),et()):r.context.clipSpace.toVarying("v_clipSpace")).once()(),jh=Is("position","vec3"),Tn=jh.toVarying("positionLocal"),Eh=jh.toVarying("positionPrevious"),Ja=re(r=>To.mul(Tn).xyz.toVarying(r.getSubBuildProperty("v_positionWorld")),"vec3").once(["POSITION"])(),Dv=re(()=>Tn.transformDirection(To).toVarying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),"vec3").once(["POSITION"])(),dn=re(r=>{if(r.shaderStage==="fragment"&&r.material.vertexNode){const e=fD.mul(_D);return e.xyz.div(e.w).toVar("positionView")}return r.context.setupPositionView().toVarying("v_positionView")},"vec3").once(["POSITION","VERTEX"])(),$t=re(r=>{let e;return r.camera.isOrthographicCamera?e=te(0,0,1):e=dn.negate().toVarying("v_positionViewDirection").normalize(),e.toVar("positionViewDirection")},"vec3").once(["POSITION"])();class xD extends Ve{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){if(e.shaderStage!=="fragment")return"true";const{material:t}=e;return t.side===Lt?"false":e.getFrontFacing()}}const yD=be(xD),Lv=J(yD).mul(2).sub(1),Wc=re(([r],{material:e})=>{const t=e.side;return t===Lt?r=r.mul(-1):t===Nn&&(r=r.mul(Lv)),r}),Uv=Is("normal","vec3"),wr=re(r=>r.geometry.hasAttribute("normal")===!1?(ae('TSL: Vertex attribute "normal" not found on geometry.'),te(0,1,0)):Uv,"vec3").once()().toVar("normalLocal"),vD=dn.dFdx().cross(dn.dFdy()).normalize().toVar("normalFlat"),Ac=re(r=>{let e;return r.isFlatShading()?e=vD:e=Fv(wr).toVarying("v_normalViewGeometry").normalize(),e},"vec3").once()().toVar("normalViewGeometry"),bD=re(r=>{let e=Ac.transformDirection(es);return r.isFlatShading()!==!0&&(e=e.toVarying("v_normalWorldGeometry")),e.normalize().toVar("normalWorldGeometry")},"vec3").once()(),vt=re(r=>{let e;return r.subBuildFn==="NORMAL"||r.subBuildFn==="VERTEX"?(e=Ac,r.isFlatShading()!==!0&&(e=Wc(e))):e=r.context.setupNormal().context({getUV:null,getTextureLevel:null}),e},"vec3").once(["NORMAL","VERTEX"])().toVar("normalView"),ml=vt.transformDirection(es).toVar("normalWorld"),ao=re(({subBuildFn:r,context:e})=>{let t;return r==="NORMAL"||r==="VERTEX"?t=vt:t=e.setupClearcoatNormal().context({getUV:null,getTextureLevel:null}),t},"vec3").once(["NORMAL","VERTEX"])().toVar("clearcoatNormalView"),SD=re(([r,e=To])=>{const t=On(e),n=r.div(te(t[0].dot(t[0]),t[1].dot(t[1]),t[2].dot(t[2])));return t.mul(n).xyz}),Fv=re(([r],e)=>{const t=e.context.modelNormalViewMatrix;if(t)return t.transformDirection(r);const n=mD.mul(r);return es.transformDirection(n)});re(()=>(ae('TSL: "transformedNormalView" is deprecated. Use "normalView" instead.'),vt)).once(["NORMAL","VERTEX"])();re(()=>(ae('TSL: "transformedNormalWorld" is deprecated. Use "normalWorld" instead.'),ml)).once(["NORMAL","VERTEX"])();re(()=>(ae('TSL: "transformedClearcoatNormalView" is deprecated. Use "clearcoatNormalView" instead.'),ao)).once(["NORMAL","VERTEX"])();const df=new pt,TD=qe(0).onReference(({material:r})=>r).onObjectUpdate(({material:r})=>r.refractionRatio),ff=qe(1).onReference(({material:r})=>r).onObjectUpdate(function({material:r,scene:e}){return r.envMap?r.envMapIntensity:e.environmentIntensity}),Iv=qe(new pt).onReference(function(r){return r.material}).onObjectUpdate(function({material:r,scene:e}){const t=e.environment!==null&&r.envMap===null?e.environmentRotation:r.envMapRotation;return t?df.makeRotationFromEuler(t).transpose():df.identity(),df}),MD=$t.negate().reflect(vt),ED=$t.negate().refract(vt,TD),AD=MD.transformDirection(es).toVar("reflectVector"),wD=ED.transformDirection(es).toVar("reflectVector"),RD=new sl;class CD extends zc{static get type(){return"CubeTextureNode"}constructor(e,t=null,n=null,i=null){super(e,t,n,i),this.isCubeTextureNode=!0}getInputType(){return this.value.isDepthTexture===!0?"cubeDepthTexture":"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===Ki?AD:e.mapping===Sr?wD:(ce('CubeTextureNode: Mapping "%s" not supported.',e.mapping),te(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const n=this.value;return n.isDepthTexture===!0?e.renderer.coordinateSystem===Tr?te(t.x,t.y.negate(),t.z):t:(t=Iv.mul(t),(e.renderer.coordinateSystem===Tr||!n.isRenderTargetTexture)&&(t=te(t.x.negate(),t.yz)),t)}generateUV(e,t){return t.build(e,this.sampler===!0?"vec3":"ivec3")}}const ND=It(CD).setParameterLength(1,4).setName("cubeTexture"),li=(r=RD,e=null,t=null,n=null)=>{let i;return r&&r.isCubeTextureNode===!0?(i=Ge(r.clone()),i.referenceNode=r,e!==null&&(i.uvNode=Ge(e)),t!==null&&(i.levelNode=Ge(t)),n!==null&&(i.biasNode=Ge(n))):i=ND(r,e,t,n),i};class PD extends hl{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}generateNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),n=this.referenceNode.getNodeType(e),i=this.getNodeType(e);return e.format(t,n,i)}}class Xm extends Ve{static get type(){return"ReferenceNode"}constructor(e,t,n=null,i=null){super(),this.property=e,this.uniformType=t,this.object=n,this.count=i,this.properties=e.split("."),this.reference=n,this.node=null,this.group=null,this.name=null,this.updateType=Ze.OBJECT}element(e){return new PD(this,Ge(e))}setGroup(e){return this.group=e,this}setName(e){return this.name=e,this}label(e){return ae('TSL: "label()" has been deprecated. Use "setName()" instead.'),this.setName(e)}setNodeType(e){let t=null;this.count!==null?t=Nv(null,e,this.count):Array.isArray(this.getValueFromReference())?t=Pi(null,e):e==="texture"?t=Vt(null):e==="cubeTexture"?t=li(null):t=qe(null,e),this.group!==null&&t.setGroup(this.group),this.name!==null&&t.setName(this.name),this.node=t}generateNodeType(e){return this.node===null&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let n=e[t[0]];for(let i=1;i<t.length;i++)n=n[t[i]];return n}updateReference(e){return this.reference=this.object!==null?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);const e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}const Jt=(r,e,t)=>new Xm(r,e,t),ax=(r,e,t,n)=>new Xm(r,e,n,t);class DD extends Xm{static get type(){return"MaterialReferenceNode"}constructor(e,t,n=null){super(e,t,n),this.material=n,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=this.material!==null?this.material:e.material,this.reference}}const ms=(r,e,t=null)=>new DD(r,e,t),Bv=dl(),LD=dn.dFdx(),UD=dn.dFdy(),Ov=Bv.dFdx(),kv=Bv.dFdy(),Gv=vt,Vv=UD.cross(Gv),zv=Gv.cross(LD),Tp=Vv.mul(Ov.x).add(zv.mul(kv.x)),Mp=Vv.mul(Ov.y).add(zv.mul(kv.y)),lx=Tp.dot(Tp).max(Mp.dot(Mp)),Hv=lx.equal(0).select(0,lx.inverseSqrt()),FD=Tp.mul(Hv).toVar("tangentViewFrame"),ID=Mp.mul(Hv).toVar("bitangentViewFrame"),Wv=Is("tangent","vec4"),Ah=Wv.xyz.toVar("tangentLocal"),$v=re(r=>{let e;return r.subBuildFn==="VERTEX"||r.geometry.hasAttribute("tangent")?e=Hc.mul(et(Ah,0)).xyz.toVarying("v_tangentView").normalize():e=FD,r.isFlatShading()!==!0&&(e=Wc(e)),e},"vec3").once(["NORMAL","VERTEX"])().toVar("tangentView"),BD=re(([r,e],t)=>{let n=r.mul(Wv.w).xyz;return t.subBuildFn==="NORMAL"&&t.isFlatShading()!==!0&&(n=n.toVarying(e)),n}).once(["NORMAL"]),OD=re(r=>{let e;return r.subBuildFn==="VERTEX"||r.geometry.hasAttribute("tangent")?e=BD(vt.cross($v),"v_bitangentView").normalize():e=ID,r.isFlatShading()!==!0&&(e=Wc(e)),e},"vec3").once(["NORMAL","VERTEX"])().toVar("bitangentView"),$l=On($v,OD,vt).toVar("TBNViewMatrix"),kD=re(()=>{let r=va.cross($t);return r=r.cross(va).normalize(),r=Dt(r,vt,to.mul(Wr.oneMinus()).oneMinus().pow2().pow2()).normalize(),r}).once()(),GD=r=>Ge(r).mul(.5).add(.5),cx=r=>te(r,Ps(Gm(J(1).sub(bo(r,r)))));class VD extends xn{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=ji,this.unpackNormalMode=ld}setup(e){const{normalMapType:t,scaleNode:n,unpackNormalMode:i}=this;let s=this.node.mul(2).sub(1);if(t===ji?i===Y0?s=cx(s.xy):i===OS?s=cx(s.yw):i!==ld&&ce(`THREE.NodeMaterial: Unexpected unpack normal mode: ${i}`):i!==ld&&ce(`THREE.NodeMaterial: Normal map type '${t}' is not compatible with unpack normal mode '${i}'`),n!==null){let a=n;e.isFlatShading()===!0&&(a=Wc(a)),s=te(s.xy.mul(a),s.z)}let o=null;return t===j0?o=Fv(s):t===ji?o=$l.mul(s).normalize():(ce(`NodeMaterial: Unsupported normal map type: ${t}`),o=vt),o}}const ux=It(VD).setParameterLength(1,2),zD=re(({textureNode:r,bumpScale:e})=>{const t=i=>r.isolate().context({getUV:s=>i(s.uvNode||dl()),forceUVContext:!0}),n=J(t(i=>i));return ke(J(t(i=>i.add(i.dFdx()))).sub(n),J(t(i=>i.add(i.dFdy()))).sub(n)).mul(e)}),HD=re(r=>{const{surf_pos:e,surf_norm:t,dHdxy:n}=r,i=e.dFdx().normalize(),s=e.dFdy().normalize(),o=t,a=s.cross(o),l=o.cross(i),c=i.dot(a).mul(Lv),u=c.sign().mul(n.x.mul(a).add(n.y.mul(l)));return c.abs().mul(t).sub(u).normalize()});class WD extends xn{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=this.scaleNode!==null?this.scaleNode:1,t=zD({textureNode:this.textureNode,bumpScale:e});return HD({surf_pos:dn,surf_norm:vt,dHdxy:t})}}const $D=It(WD).setParameterLength(1,2),hx=new Map;class ie extends Ve{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let n=hx.get(e);return n===void 0&&(n=ms(e,t),hx.set(e,n)),n}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache(e==="map"?"map":e+"Map","texture")}setup(e){const t=e.context.material,n=this.scope;let i=null;if(n===ie.COLOR){const s=t.color!==void 0?this.getColor(n):te();t.map&&t.map.isTexture===!0?i=s.mul(this.getTexture("map")):i=s}else if(n===ie.OPACITY){const s=this.getFloat(n);t.alphaMap&&t.alphaMap.isTexture===!0?i=s.mul(this.getTexture("alpha")):i=s}else if(n===ie.SPECULAR_STRENGTH)t.specularMap&&t.specularMap.isTexture===!0?i=this.getTexture("specular").r:i=J(1);else if(n===ie.SPECULAR_INTENSITY){const s=this.getFloat(n);t.specularIntensityMap&&t.specularIntensityMap.isTexture===!0?i=s.mul(this.getTexture(n).a):i=s}else if(n===ie.SPECULAR_COLOR){const s=this.getColor(n);t.specularColorMap&&t.specularColorMap.isTexture===!0?i=s.mul(this.getTexture(n).rgb):i=s}else if(n===ie.ROUGHNESS){const s=this.getFloat(n);t.roughnessMap&&t.roughnessMap.isTexture===!0?i=s.mul(this.getTexture(n).g):i=s}else if(n===ie.METALNESS){const s=this.getFloat(n);t.metalnessMap&&t.metalnessMap.isTexture===!0?i=s.mul(this.getTexture(n).b):i=s}else if(n===ie.EMISSIVE){const s=this.getFloat("emissiveIntensity"),o=this.getColor(n).mul(s);t.emissiveMap&&t.emissiveMap.isTexture===!0?i=o.mul(this.getTexture(n)):i=o}else if(n===ie.NORMAL)t.normalMap?(i=ux(this.getTexture("normal"),this.getCache("normalScale","vec2")),i.normalMapType=t.normalMapType,(t.normalMap.format==In||t.normalMap.format==Us||t.normalMap.format==Ls)&&(i.unpackNormalMode=Y0)):t.bumpMap?i=$D(this.getTexture("bump").r,this.getFloat("bumpScale")):i=vt;else if(n===ie.CLEARCOAT){const s=this.getFloat(n);t.clearcoatMap&&t.clearcoatMap.isTexture===!0?i=s.mul(this.getTexture(n).r):i=s}else if(n===ie.CLEARCOAT_ROUGHNESS){const s=this.getFloat(n);t.clearcoatRoughnessMap&&t.clearcoatRoughnessMap.isTexture===!0?i=s.mul(this.getTexture(n).r):i=s}else if(n===ie.CLEARCOAT_NORMAL)t.clearcoatNormalMap?i=ux(this.getTexture(n),this.getCache(n+"Scale","vec2")):i=vt;else if(n===ie.SHEEN){const s=this.getColor("sheenColor").mul(this.getFloat("sheen"));t.sheenColorMap&&t.sheenColorMap.isTexture===!0?i=s.mul(this.getTexture("sheenColor").rgb):i=s}else if(n===ie.SHEEN_ROUGHNESS){const s=this.getFloat(n);t.sheenRoughnessMap&&t.sheenRoughnessMap.isTexture===!0?i=s.mul(this.getTexture(n).a):i=s,i=i.clamp(1e-4,1)}else if(n===ie.ANISOTROPY)if(t.anisotropyMap&&t.anisotropyMap.isTexture===!0){const s=this.getTexture(n);i=Um(Ul.x,Ul.y,Ul.y.negate(),Ul.x).mul(s.rg.mul(2).sub(ke(1)).normalize().mul(s.b))}else i=Ul;else if(n===ie.IRIDESCENCE_THICKNESS){const s=Jt("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const o=Jt("0","float",t.iridescenceThicknessRange);i=s.sub(o).mul(this.getTexture(n).g).add(o)}else i=s}else if(n===ie.TRANSMISSION){const s=this.getFloat(n);t.transmissionMap?i=s.mul(this.getTexture(n).r):i=s}else if(n===ie.THICKNESS){const s=this.getFloat(n);t.thicknessMap?i=s.mul(this.getTexture(n).g):i=s}else if(n===ie.IOR)i=this.getFloat(n);else if(n===ie.LIGHT_MAP)i=this.getTexture(n).rgb.mul(this.getFloat("lightMapIntensity"));else if(n===ie.AO)i=this.getTexture(n).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else if(n===ie.LINE_DASH_OFFSET)i=t.dashOffset?this.getFloat(n):J(0);else{const s=this.getNodeType(e);i=this.getCache(n,s)}return i}}ie.ALPHA_TEST="alphaTest";ie.COLOR="color";ie.OPACITY="opacity";ie.SHININESS="shininess";ie.SPECULAR="specular";ie.SPECULAR_STRENGTH="specularStrength";ie.SPECULAR_INTENSITY="specularIntensity";ie.SPECULAR_COLOR="specularColor";ie.REFLECTIVITY="reflectivity";ie.ROUGHNESS="roughness";ie.METALNESS="metalness";ie.NORMAL="normal";ie.CLEARCOAT="clearcoat";ie.CLEARCOAT_ROUGHNESS="clearcoatRoughness";ie.CLEARCOAT_NORMAL="clearcoatNormal";ie.EMISSIVE="emissive";ie.ROTATION="rotation";ie.SHEEN="sheen";ie.SHEEN_ROUGHNESS="sheenRoughness";ie.ANISOTROPY="anisotropy";ie.IRIDESCENCE="iridescence";ie.IRIDESCENCE_IOR="iridescenceIOR";ie.IRIDESCENCE_THICKNESS="iridescenceThickness";ie.IOR="ior";ie.TRANSMISSION="transmission";ie.THICKNESS="thickness";ie.ATTENUATION_DISTANCE="attenuationDistance";ie.ATTENUATION_COLOR="attenuationColor";ie.LINE_SCALE="scale";ie.LINE_DASH_SIZE="dashSize";ie.LINE_GAP_SIZE="gapSize";ie.LINE_WIDTH="linewidth";ie.LINE_DASH_OFFSET="dashOffset";ie.POINT_SIZE="size";ie.DISPERSION="dispersion";ie.LIGHT_MAP="light";ie.AO="ao";const XD=be(ie,ie.ALPHA_TEST),qD=be(ie,ie.COLOR),jD=be(ie,ie.SHININESS),YD=be(ie,ie.EMISSIVE),Xv=be(ie,ie.OPACITY),KD=be(ie,ie.SPECULAR),dx=be(ie,ie.SPECULAR_INTENSITY),ZD=be(ie,ie.SPECULAR_COLOR),fh=be(ie,ie.SPECULAR_STRENGTH),pf=be(ie,ie.REFLECTIVITY),QD=be(ie,ie.ROUGHNESS),JD=be(ie,ie.METALNESS),eL=be(ie,ie.NORMAL),tL=be(ie,ie.CLEARCOAT),nL=be(ie,ie.CLEARCOAT_ROUGHNESS),iL=be(ie,ie.CLEARCOAT_NORMAL),rL=be(ie,ie.ROTATION),sL=be(ie,ie.SHEEN),oL=be(ie,ie.SHEEN_ROUGHNESS),aL=be(ie,ie.ANISOTROPY),lL=be(ie,ie.IRIDESCENCE),cL=be(ie,ie.IRIDESCENCE_IOR),uL=be(ie,ie.IRIDESCENCE_THICKNESS),hL=be(ie,ie.TRANSMISSION),dL=be(ie,ie.THICKNESS),fL=be(ie,ie.IOR),pL=be(ie,ie.ATTENUATION_DISTANCE),mL=be(ie,ie.ATTENUATION_COLOR),gL=be(ie,ie.LINE_SCALE),_L=be(ie,ie.LINE_DASH_SIZE),xL=be(ie,ie.LINE_GAP_SIZE);ie.LINE_WIDTH;const yL=be(ie,ie.LINE_DASH_OFFSET),vL=be(ie,ie.POINT_SIZE),bL=be(ie,ie.DISPERSION),qv=be(ie,ie.LIGHT_MAP),SL=be(ie,ie.AO),Ul=qe(new pe).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))}),TL=re(r=>r.context.setupModelViewProjection(),"vec4").once()().toVarying("v_modelViewProjection");class ML extends hl{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}getMemberType(e,t){const n=this.storageBufferNode.structTypeNode;return n?n.getMemberType(e,t):"void"}setup(e){return e.isAvailable("storageBuffer")===!1&&this.node.isPBO===!0&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let n;const i=e.context.assign;if(e.isAvailable("storageBuffer")===!1?this.node.isPBO===!0&&i!==!0&&(this.node.value.isInstancedBufferAttribute||e.shaderStage!=="compute")?n=e.generatePBO(this):n=this.node.build(e):n=super.generate(e),i!==!0){const s=this.getNodeType(e);n=e.format(n,s,t)}return n}}const EL=It(ML).setParameterLength(2);class AL extends $m{static get type(){return"StorageBufferNode"}constructor(e,t=null,n=0){let i,s=null;t&&t.isStruct?(i="struct",s=t.layout,(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(n=e.count)):t===null&&(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)?(i=Wy(e.itemSize),n=e.count):i=t,super(e,i,n),this.isStorageBufferNode=!0,this.structTypeNode=s,this.access=Ui.READ_WRITE,this.isAtomic=!1,this.isPBO=!1,this._attribute=null,this._varying=null,this.global=!0,e.isStorageBufferAttribute!==!0&&e.isStorageInstancedBufferAttribute!==!0&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){let t;if(this.bufferCount===0){let n=e.globalCache.getData(this.value);n===void 0&&(n={node:this},e.globalCache.setData(this.value,n)),t=n.node.id}else t=this.id;return String(t)}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return EL(this,e)}setPBO(e){return this.isPBO=e,this}getPBO(){return this.isPBO}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(Ui.READ_ONLY)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return this._attribute===null&&(this._attribute=Tv(this.value),this._varying=Do(this._attribute)),{attribute:this._attribute,varying:this._varying}}generateNodeType(e){if(this.structTypeNode!==null)return this.structTypeNode.getNodeType(e);if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generateNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}getMemberType(e,t){return this.structTypeNode!==null?this.structTypeNode.getMemberType(e,t):"void"}generate(e){if(this.structTypeNode!==null&&this.structTypeNode.build(e),e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:n}=this.getAttributeData(),i=n.build(e);return e.registerTransform(i,t),i}}const fx=(r,e=null,t=0)=>new AL(r,e,t);class wL extends Ve{static get type(){return"InstanceNode"}constructor(e,t,n=null){super("void"),this.count=e,this.instanceMatrix=t,this.instanceColor=n,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=Ze.FRAME,this.buffer=null,this.bufferColor=null,this.previousInstanceMatrixNode=null}get isStorageMatrix(){const{instanceMatrix:e}=this;return e&&e.isStorageInstancedBufferAttribute===!0}get isStorageColor(){const{instanceColor:e}=this;return e&&e.isStorageInstancedBufferAttribute===!0}setup(e){let{instanceMatrixNode:t,instanceColorNode:n}=this;t===null&&(t=this._createInstanceMatrixNode(!0,e),this.instanceMatrixNode=t);const{instanceColor:i,isStorageColor:s}=this;if(i&&n===null){if(s)n=fx(i,"vec3",Math.max(i.count,1)).element(Sa);else{const a=new IT(i.array,3),l=i.usage===mh?ix:nx;this.bufferColor=a,n=te(l(a,"vec3",3,0))}this.instanceColorNode=n}const o=t.mul(Tn).xyz;if(Tn.assign(o),e.needsPreviousData()&&Eh.assign(this.getPreviousInstancedPosition(e)),e.hasGeometryAttribute("normal")){const a=SD(wr,t);wr.assign(a)}this.instanceColorNode!==null&&Mh("vec3","vInstanceColor").assign(this.instanceColorNode)}update(e){this.buffer!==null&&this.isStorageMatrix!==!0&&(this.buffer.clearUpdateRanges(),this.buffer.updateRanges.push(...this.instanceMatrix.updateRanges),this.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMatrix.version)),this.instanceColor&&this.bufferColor!==null&&this.isStorageColor!==!0&&(this.bufferColor.clearUpdateRanges(),this.bufferColor.updateRanges.push(...this.instanceColor.updateRanges),this.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceColor.version)),this.previousInstanceMatrixNode!==null&&e.object.previousInstanceMatrix.array.set(this.instanceMatrix.array)}getPreviousInstancedPosition(e){const t=e.object;return this.previousInstanceMatrixNode===null&&(t.previousInstanceMatrix=this.instanceMatrix.clone(),this.previousInstanceMatrixNode=this._createInstanceMatrixNode(!1,e)),this.previousInstanceMatrixNode.mul(Eh).xyz}_createInstanceMatrixNode(e,t){let n;const{instanceMatrix:i}=this,{count:s}=i;if(this.isStorageMatrix)n=fx(i,"mat4",Math.max(s,1)).element(Sa);else if(s*16*4<=t.getUniformBufferLimit())n=Nv(i.array,"mat4",Math.max(s,1)).element(Sa);else{const a=new NM(i.array,16,1);e===!0&&(this.buffer=a);const l=i.usage===mh?ix:nx,c=[l(a,"vec4",16,0),l(a,"vec4",16,4),l(a,"vec4",16,8),l(a,"vec4",16,12)];n=uo(...c)}return n}}class RL extends wL{static get type(){return"InstancedMeshNode"}constructor(e){const{count:t,instanceMatrix:n,instanceColor:i}=e;super(t,n,i),this.instancedMesh=e}}const CL=It(RL).setParameterLength(1);class NL extends Ve{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){this.batchingIdNode===null&&(e.getDrawIndex()===null?this.batchingIdNode=Sa:this.batchingIdNode=HP);const n=re(([p])=>{const g=Zt(Ta(Ci(this.batchMesh._indirectTexture),0).x).toConst(),m=Zt(p).mod(g).toConst(),_=Zt(p).div(g).toConst();return Ci(this.batchMesh._indirectTexture,dr(m,_)).x}).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]})(Zt(this.batchingIdNode)),i=this.batchMesh._matricesTexture,s=Zt(Ta(Ci(i),0).x).toConst(),o=J(n).mul(4).toInt().toConst(),a=o.mod(s).toConst(),l=o.div(s).toConst(),c=uo(Ci(i,dr(a,l)),Ci(i,dr(a.add(1),l)),Ci(i,dr(a.add(2),l)),Ci(i,dr(a.add(3),l))),u=this.batchMesh._colorsTexture;if(u!==null){const g=re(([m])=>{const _=Zt(Ta(Ci(u),0).x).toConst(),x=m,y=x.mod(_).toConst(),b=x.div(_).toConst();return Ci(u,dr(y,b)).rgb}).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]})(n);Mh("vec3","vBatchColor").assign(g)}const h=On(c);Tn.assign(c.mul(Tn));const d=wr.div(te(h[0].dot(h[0]),h[1].dot(h[1]),h[2].dot(h[2]))),f=h.mul(d).xyz;wr.assign(f),e.hasGeometryAttribute("tangent")&&Ah.mulAssign(h)}}const PL=It(NL).setParameterLength(1),px=new WeakMap;class DL extends Ve{static get type(){return"SkinningNode"}constructor(e){super("void"),this.skinnedMesh=e,this.updateType=Ze.OBJECT,this.skinIndexNode=Is("skinIndex","uvec4"),this.skinWeightNode=Is("skinWeight","vec4"),this.bindMatrixNode=Jt("bindMatrix","mat4"),this.bindMatrixInverseNode=Jt("bindMatrixInverse","mat4"),this.boneMatricesNode=ax("skeleton.boneMatrices","mat4",e.skeleton.bones.length),this.positionNode=Tn,this.toPositionNode=Tn,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=this.positionNode){const{skinIndexNode:n,skinWeightNode:i,bindMatrixNode:s,bindMatrixInverseNode:o}=this,a=e.element(n.x),l=e.element(n.y),c=e.element(n.z),u=e.element(n.w),h=s.mul(t),d=fi(a.mul(i.x).mul(h),l.mul(i.y).mul(h),c.mul(i.z).mul(h),u.mul(i.w).mul(h));return o.mul(d).xyz}getSkinnedNormalAndTangent(e=this.boneMatricesNode,t=wr,n=Ah){const{skinIndexNode:i,skinWeightNode:s,bindMatrixNode:o,bindMatrixInverseNode:a}=this,l=e.element(i.x),c=e.element(i.y),u=e.element(i.z),h=e.element(i.w);let d=fi(s.x.mul(l),s.y.mul(c),s.z.mul(u),s.w.mul(h));d=a.mul(d).mul(o);const f=d.transformDirection(t).xyz,p=d.transformDirection(n).xyz;return{skinNormal:f,skinTangent:p}}getPreviousSkinnedPosition(e){const t=e.object;return this.previousBoneMatricesNode===null&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=ax("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Eh)}setup(e){e.needsPreviousData()&&Eh.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(this.toPositionNode&&this.toPositionNode.assign(t),e.hasGeometryAttribute("normal")){const{skinNormal:n,skinTangent:i}=this.getSkinnedNormalAndTangent();wr.assign(n),e.hasGeometryAttribute("tangent")&&Ah.assign(i)}return t}generate(e,t){if(t!=="void")return super.generate(e,t)}update(e){const t=e.object&&e.object.skeleton?e.object.skeleton:this.skinnedMesh.skeleton;px.get(t)!==e.frameId&&(px.set(t,e.frameId),this.previousBoneMatricesNode!==null&&(t.previousBoneMatrices===null&&(t.previousBoneMatrices=new Float32Array(t.boneMatrices)),t.previousBoneMatrices.set(t.boneMatrices)),t.update())}}const LL=r=>new DL(r);class UL extends Ve{static get type(){return"LoopNode"}constructor(e=[]){super("void"),this.params=e}getVarName(e){return String.fromCharCode(105+e)}getProperties(e){const t=e.getNodeProperties(this);if(t.stackNode!==void 0)return t;const n={};for(let a=0,l=this.params.length-1;a<l;a++){const c=this.params[a],u=c.isNode!==!0&&c.name||this.getVarName(a),h=c.isNode!==!0&&c.type||"int";n[u]=mr(u,h)}const i=e.addStack(),s=this.params[this.params.length-1](n);t.returnsNode=s.context({nodeLoop:s}),t.stackNode=i;const o=this.params[0];if(o.isNode!==!0&&typeof o.update=="function"){const a=re(this.params[0].update)(n);t.updateNode=a.context({nodeLoop:a})}return e.removeStack(),t}setup(e){if(this.getProperties(e),e.fnCall){const t=e.getDataFromNode(e.fnCall.shaderNode);t.hasLoop=!0}}generate(e){const t=this.getProperties(e),n=this.params,i=t.stackNode;for(let o=0,a=n.length-1;o<a;o++){const l=n[o];let c=!1,u=null,h=null,d=null,f=null,p=null,g=null;l.isNode?l.getNodeType(e)==="bool"?(c=!0,f="bool",h=l.build(e,f)):(f="int",d=this.getVarName(o),u="0",h=l.build(e,f),p="<"):(f=l.type||"int",d=l.name||this.getVarName(o),u=l.start,h=l.end,p=l.condition,g=l.update,typeof u=="number"?u=e.generateConst(f,u):u&&u.isNode&&(u=u.build(e,f)),typeof h=="number"?h=e.generateConst(f,h):h&&h.isNode&&(h=h.build(e,f)),u!==void 0&&h===void 0?(u=u+" - 1",h="0",p=">="):h!==void 0&&u===void 0&&(u="0",p="<"),p===void 0&&(Number(u)>Number(h)?p=">=":p="<"));let m;if(c)m=`while ( ${h} )`;else{const _={start:u,end:h},x=_.start,y=_.end;let b;const M=()=>p.includes("<")?"+=":"-=";if(g!=null)switch(typeof g){case"function":b=e.flowStagesNode(t.updateNode,"void").code.replace(/\t|;/g,"");break;case"number":b=d+" "+M()+" "+e.generateConst(f,g);break;case"string":b=d+" "+g;break;default:g.isNode?b=d+" "+M()+" "+g.build(e):(ce("TSL: 'Loop( { update: ... } )' is not a function, string or number.",this.stackTrace),b="break /* invalid update */")}else f==="int"||f==="uint"?g=p.includes("<")?"++":"--":g=M()+" 1.",b=d+" "+g;const S=e.getVar(f,d)+" = "+x,E=d+" "+p+" "+y;m=`for ( ${S}; ${E}; ${b} )`}e.addFlowCode((o===0?`
4644
4644
  `:"")+e.tab+m+` {
4645
4645
 
4646
4646
  `).addFlowTab()}const s=i.build(e,"void");t.returnsNode.build(e,"void"),e.removeFlowTab().addFlowCode(`
4647
4647
  `+e.tab+s);for(let o=0,a=this.params.length-1;o<a;o++)e.addFlowCode((o===0?"":e.tab)+`}
4648
4648
 
4649
- `).removeFlowTab();e.addFlowTab()}}const Li=(...r)=>new UL(ya(r,"int")).toStack(),FL=()=>mr("break").toStack(),mf=new WeakMap,vi=new rt,mx=re(({bufferMap:r,influence:e,stride:t,width:n,depth:i,offset:s})=>{const o=Zt(zP).mul(t).add(s),a=o.div(n),l=o.sub(a.mul(n));return Ni(r,dr(l,a)).depth(i).xyz.mul(e)});function IL(r){const e=r.morphAttributes.position!==void 0,t=r.morphAttributes.normal!==void 0,n=r.morphAttributes.color!==void 0,i=r.morphAttributes.position||r.morphAttributes.normal||r.morphAttributes.color,s=i!==void 0?i.length:0;let o=mf.get(r);if(o===void 0||o.count!==s){let _=function(){g.dispose(),mf.delete(r),r.removeEventListener("dispose",_)};o!==void 0&&o.texture.dispose();const a=r.morphAttributes.position||[],l=r.morphAttributes.normal||[],c=r.morphAttributes.color||[];let u=0;e===!0&&(u=1),t===!0&&(u=2),n===!0&&(u=3);let h=r.attributes.position.count*u,d=1;const f=4096;h>f&&(d=Math.ceil(h/f),h=f);const p=new Float32Array(h*d*4*s),g=new lm(p,h,d,s);g.type=Qt,g.needsUpdate=!0;const m=u*4;for(let x=0;x<s;x++){const y=a[x],b=l[x],M=c[x],S=h*d*4*x;for(let E=0;E<y.count;E++){const v=E*m;e===!0&&(vi.fromBufferAttribute(y,E),p[S+v+0]=vi.x,p[S+v+1]=vi.y,p[S+v+2]=vi.z,p[S+v+3]=0),t===!0&&(vi.fromBufferAttribute(b,E),p[S+v+4]=vi.x,p[S+v+5]=vi.y,p[S+v+6]=vi.z,p[S+v+7]=0),n===!0&&(vi.fromBufferAttribute(M,E),p[S+v+8]=vi.x,p[S+v+9]=vi.y,p[S+v+10]=vi.z,p[S+v+11]=M.itemSize===4?vi.w:1)}}o={count:s,texture:g,stride:u,size:new pe(h,d)},mf.set(r,o),r.addEventListener("dispose",_)}return o}class BL extends Ve{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=qe(1),this.updateType=Ze.OBJECT}setup(e){const{geometry:t}=e,n=t.morphAttributes.position!==void 0,i=t.hasAttribute("normal")&&t.morphAttributes.normal!==void 0,s=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,o=s!==void 0?s.length:0,{texture:a,stride:l,size:c}=IL(t);n===!0&&Tn.mulAssign(this.morphBaseInfluence),i===!0&&wr.mulAssign(this.morphBaseInfluence);const u=Zt(c.width);Li(o,({i:h})=>{const d=J(0).toVar();this.mesh.count>1&&this.mesh.morphTexture!==null&&this.mesh.morphTexture!==void 0?d.assign(Ni(this.mesh.morphTexture,dr(Zt(h).add(1),Zt(Sa))).r):d.assign(Jt("morphTargetInfluences","float").element(h).toVar()),Ft(d.notEqual(0),()=>{n===!0&&Tn.addAssign(mx({bufferMap:a,influence:d,stride:l,width:u,depth:h,offset:Zt(0)})),i===!0&&wr.addAssign(mx({bufferMap:a,influence:d,stride:l,width:u,depth:h,offset:Zt(1)}))})})}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce((t,n)=>t+n,0)}}const OL=It(BL).setParameterLength(1);class gl extends Ve{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}}class kL extends gl{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class GL extends yv{static get type(){return"LightingContextNode"}constructor(e,t=null,n=null,i=null){super(e),this.lightingModel=t,this.backdropNode=n,this.backdropAlphaNode=i,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,n=te().toVar("directDiffuse"),i=te().toVar("directSpecular"),s=te().toVar("indirectDiffuse"),o=te().toVar("indirectSpecular"),a={directDiffuse:n,directSpecular:i,indirectDiffuse:s,indirectSpecular:o};return{radiance:te().toVar("radiance"),irradiance:te().toVar("irradiance"),iblIrradiance:te().toVar("iblIrradiance"),ambientOcclusion:J(1).toVar("ambientOcclusion"),reflectedLight:a,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const VL=It(GL);class zL extends gl{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}const Ks=new pe;class jv extends zc{static get type(){return"ViewportTextureNode"}constructor(e=fo,t=null,n=null){let i=null;n===null?(i=new ny,i.minFilter=ui,n=i):i=n,super(n,e,t),this.generateMipmaps=!1,this.defaultFramebuffer=i,this.isOutputTextureNode=!0,this.updateBeforeType=Ze.RENDER,this._cacheTextures=new WeakMap}getTextureForReference(e=null){let t,n;if(this.referenceNode?(t=this.referenceNode.defaultFramebuffer,n=this.referenceNode._cacheTextures):(t=this.defaultFramebuffer,n=this._cacheTextures),e===null)return t;if(n.has(e)===!1){const i=t.clone();n.set(e,i)}return n.get(e)}updateReference(e){const t=e.renderer,n=t.getRenderTarget(),i=t.getCanvasTarget(),s=n||i;return this.value=this.getTextureForReference(s),this.value}updateBefore(e){const t=e.renderer,n=t.getRenderTarget(),i=t.getCanvasTarget(),s=n||i;s===null?t.getDrawingBufferSize(Ks):s.getDrawingBufferSize?s.getDrawingBufferSize(Ks):Ks.set(s.width,s.height);const o=this.getTextureForReference(s);(o.image.width!==Ks.width||o.image.height!==Ks.height)&&(o.image.width=Ks.width,o.image.height=Ks.height,o.needsUpdate=!0);const a=o.generateMipmaps;o.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(o),o.generateMipmaps=a}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Yv=It(jv,null,null,{generateMipmaps:!0}).setParameterLength(0,3),HL=Yv(),WL=(r=fo,e=null)=>HL.sample(r,e);let gf=null;class $L extends jv{static get type(){return"ViewportDepthTextureNode"}constructor(e=fo,t=null,n=null){n===null&&(gf===null&&(gf=new jn),n=gf),super(e,t,n)}}const XL=It($L).setParameterLength(0,3);class hi extends Ve{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===hi.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,n=this.valueNode;let i=null;if(t===hi.DEPTH_BASE)n!==null&&(i=Jv().assign(n));else if(t===hi.DEPTH)e.isPerspectiveCamera?i=Kv(dn.z,so,oo):i=rc(dn.z,so,oo);else if(t===hi.LINEAR_DEPTH)if(n!==null)if(e.isPerspectiveCamera){const s=Zv(n,so,oo);i=rc(s,so,oo)}else i=n;else i=rc(dn.z,so,oo);return i}}hi.DEPTH_BASE="depthBase";hi.DEPTH="depth";hi.LINEAR_DEPTH="linearDepth";const rc=(r,e,t)=>r.add(e).div(e.sub(t)),Kv=(r,e,t)=>e.add(r).mul(t).div(t.sub(e).mul(r)),qL=(r,e,t)=>e.mul(r.add(t)).div(r.mul(e.sub(t))),Zv=re(([r,e,t],n)=>n.renderer.reversedDepthBuffer===!0?e.mul(t).div(e.sub(t).mul(r).sub(e)):e.mul(t).div(t.sub(e).mul(r).sub(t))),Qv=(r,e,t)=>{e=e.max(1e-6).toVar();const n=Yr(r.negate().div(e)),i=Yr(t.div(e));return n.div(i)},Jv=It(hi,hi.DEPTH_BASE),eb=be(hi,hi.DEPTH),jL=It(hi,hi.LINEAR_DEPTH).setParameterLength(0,1);XL();eb.assign=r=>Jv(r);class Bi extends Ve{static get type(){return"ClippingNode"}constructor(e=Bi.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:n,unionPlanes:i}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===Bi.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(n,i):this.scope===Bi.HARDWARE?this.setupHardwareClipping(i,e):this.setupDefault(n,i)}setupAlphaToCoverage(e,t){return re(()=>{const n=J().toVar("distanceToPlane"),i=J().toVar("distanceToGradient"),s=J(1).toVar("clipOpacity"),o=t.length;if(this.hardwareClipping===!1&&o>0){const l=Di(t).setGroup(Ke);Li(o,({i:c})=>{const u=l.element(c);n.assign(dn.dot(u.xyz).negate().add(u.w)),i.assign(n.fwidth().div(2)),s.mulAssign(Qr(i.negate(),i,n))})}const a=e.length;if(a>0){const l=Di(e).setGroup(Ke),c=J(1).toVar("intersectionClipOpacity");Li(a,({i:u})=>{const h=l.element(u);n.assign(dn.dot(h.xyz).negate().add(h.w)),i.assign(n.fwidth().div(2)),c.mulAssign(Qr(i.negate(),i,n).oneMinus())}),s.mulAssign(c.oneMinus())}Pt.a.mulAssign(s),Pt.a.equal(0).discard()})()}setupDefault(e,t){return re(()=>{const n=t.length;if(this.hardwareClipping===!1&&n>0){const s=Di(t).setGroup(Ke);Li(n,({i:o})=>{const a=s.element(o);dn.dot(a.xyz).greaterThan(a.w).discard()})}const i=e.length;if(i>0){const s=Di(e).setGroup(Ke),o=$h(!0).toVar("clipped");Li(i,({i:a})=>{const l=s.element(a);o.assign(dn.dot(l.xyz).greaterThan(l.w).and(o))}),o.discard()}})()}setupHardwareClipping(e,t){const n=e.length;return t.enableHardwareClipping(n),re(()=>{const i=Di(e).setGroup(Ke),s=fl(t.getClipDistance());Li(n,({i:o})=>{const a=i.element(o),l=dn.dot(a.xyz).sub(a.w).negate();s.element(o).assign(l)})})()}}Bi.ALPHA_TO_COVERAGE="alphaToCoverage";Bi.DEFAULT="default";Bi.HARDWARE="hardware";const YL=()=>new Bi,KL=()=>new Bi(Bi.ALPHA_TO_COVERAGE),ZL=()=>new Bi(Bi.HARDWARE),QL=.05,gx=re(([r])=>Ar(st(1e4,bi(st(17,r.x).add(st(.1,r.y)))).mul(fi(.1,Si(bi(st(13,r.y).add(r.x))))))),_x=re(([r])=>gx(ke(gx(r.xy),r.z))),JL=re(([r])=>{const e=kn(Kr(dv(r.xyz)),Kr(fv(r.xyz))),t=J(1).div(J(QL).mul(e)).toVar("pixScale"),n=ke(Mc(ho(Yr(t))),Mc(km(Yr(t)))),i=ke(_x(ho(n.x.mul(r.xyz))),_x(ho(n.y.mul(r.xyz)))),s=Ar(Yr(t)),o=fi(st(s.oneMinus(),i.x),st(s,i.y)),a=Qa(s,s.oneMinus()),l=te(o.mul(o).div(st(2,a).mul(oi(1,a))),o.sub(st(.5,a)).div(oi(1,a)),oi(1,oi(1,o).mul(oi(1,o)).div(st(2,a).mul(oi(1,a))))),c=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(l.x,l.y),l.z);return Fs(c,1e-6,1)}).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]});class eU extends Rv{static get type(){return"VertexColorNode"}constructor(e){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e),n=e.hasGeometryAttribute(t);let i;return n===!0?i=super.generate(e):i=e.generateConst(this.nodeType,new rt(1,1,1,1)),i}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const tU=(r=0)=>new eU(r),nU=re(([r])=>et(r.rgb.mul(r.a),r.a),{color:"vec4",return:"vec4"});class mn extends Yn{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.maskNode=null,this.maskShadowNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.receivedShadowPositionNode=null,this.castShadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null,this.contextNode=null}_getNodeChildren(){const e=[];for(const t of Object.getOwnPropertyNames(this)){if(t.startsWith("_")===!0)continue;const n=this[t];n&&n.isNode===!0&&e.push({property:t,childNode:n})}return e}customProgramCacheKey(){const e=[];for(const{property:t,childNode:n}of this._getNodeChildren())e.push(cl(t.slice(0,-4)),n.getCacheKey());return this.type+Gc(e)}build(e){this.setup(e)}setupObserver(e){return new NN(e)}setup(e){e.context.setupNormal=()=>ba(this.setupNormal(e),"NORMAL","vec3"),e.context.setupPositionView=()=>this.setupPositionView(e),e.context.setupModelViewProjection=()=>this.setupModelViewProjection(e);const t=e.renderer,n=t.getRenderTarget();e.addStack();const i=this.setupVertex(e),s=ba(this.vertexNode||i,"VERTEX");e.context.clipSpace=s,e.stack.outputNode=s,this.setupHardwareClipping(e),this.geometryNode!==null&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();let o;const a=this.setupClipping(e);if((this.depthWrite===!0||this.depthTest===!0)&&(n!==null?n.depthBuffer===!0&&this.setupDepth(e):t.depth===!0&&this.setupDepth(e)),this.fragmentNode===null){this.setupDiffuseColor(e),this.setupVariants(e);const l=this.setupLighting(e);a!==null&&e.stack.addToStack(a);const c=et(l,Pt.a).max(0);o=this.setupOutput(e,c),tc.assign(o);const u=this.outputNode!==null;if(u&&(o=this.outputNode),e.context.getOutput&&(o=e.context.getOutput(o,e)),n!==null){const h=t.getMRT(),d=this.mrtNode;h!==null?(u&&tc.assign(o),o=h,d!==null&&(o=h.merge(d))):d!==null&&(o=d)}}else{let l=this.fragmentNode;l.isOutputStructNode!==!0&&(l=et(l)),o=this.setupOutput(e,l)}e.stack.outputNode=o,e.addFlow("fragment",e.removeStack()),e.observer=this.setupObserver(e)}setupClipping(e){if(e.clippingContext===null)return null;const{unionPlanes:t,intersectionPlanes:n}=e.clippingContext;let i=null;if(t.length>0||n.length>0){const s=e.renderer.currentSamples;this.alphaToCoverage&&s>1?i=KL():e.stack.addToStack(YL())}return i}setupHardwareClipping(e){if(this.hardwareClipping=!1,e.clippingContext===null)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.addToStack(ZL()),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:n}=e;let i=this.depthNode;if(i===null){const s=t.getMRT();s&&s.has("depth")?i=s.get("depth"):t.logarithmicDepthBuffer===!0&&(n.isPerspectiveCamera?i=Qv(dn.z,so,oo):i=rc(dn.z,so,oo))}i!==null&&eb.assign(i).toStack()}setupPositionView(){return Hc.mul(Tn).xyz}setupModelViewProjection(){return ic.mul(dn)}setupVertex(e){return e.addStack(),this.setupPosition(e),e.context.position=e.removeStack(),TL}setupPosition(e){const{object:t,geometry:n}=e;if((n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color)&&OL(t).toStack(),t.isSkinnedMesh===!0&&LL(t).toStack(),this.displacementMap){const i=ms("displacementMap","texture"),s=ms("displacementScale","float"),o=ms("displacementBias","float");Tn.addAssign(wr.normalize().mul(i.x.mul(s).add(o)))}return t.isBatchedMesh&&PL(t).toStack(),t.isInstancedMesh&&t.instanceMatrix&&t.instanceMatrix.isInstancedBufferAttribute===!0&&CL(t).toStack(),this.positionNode!==null&&Tn.assign(ba(this.positionNode,"POSITION","vec3")),Tn}setupDiffuseColor(e){const{object:t,geometry:n}=e;this.maskNode!==null&&$h(this.maskNode).not().discard();let i=this.colorNode?et(this.colorNode):qD;this.vertexColors===!0&&n.hasAttribute("color")&&(i=i.mul(tU())),t.instanceColor&&(i=Mh("vec3","vInstanceColor").mul(i)),t.isBatchedMesh&&t._colorsTexture&&(i=Mh("vec3","vBatchColor").mul(i)),Pt.assign(i);const s=this.opacityNode?J(this.opacityNode):Xv;Pt.a.assign(Pt.a.mul(s));let o=null;(this.alphaTestNode!==null||this.alphaTest>0)&&(o=this.alphaTestNode!==null?J(this.alphaTestNode):XD,this.alphaToCoverage===!0?(Pt.a=Qr(o,o.add(pv(Pt.a)),Pt.a),Pt.a.lessThanEqual(0).discard()):Pt.a.lessThanEqual(o).discard()),this.alphaHash===!0&&Pt.a.lessThan(JL(Tn)).discard(),e.isOpaque()&&Pt.a.assign(1)}setupVariants(){}setupOutgoingLight(){return this.lights===!0?te(0):Pt.rgb}setupNormal(){return this.normalNode?te(this.normalNode):eL}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?ms("envMap","cubeTexture"):ms("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new zL(qv)),t}setupLights(e){const t=[],n=this.setupEnvironment(e);n&&n.isLightingNode&&t.push(n);const i=this.setupLightMap(e);i&&i.isLightingNode&&t.push(i);let s=this.aoNode;s===null&&e.material.aoMap&&(s=SL),e.context.getAO&&(s=e.context.getAO(s,e)),s&&t.push(new kL(s));let o=this.lightsNode||e.lightsNode;return t.length>0&&(o=e.renderer.lighting.createNode([...o.getLights(),...t])),o}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:n,backdropAlphaNode:i,emissiveNode:s}=this,a=this.lights===!0||this.lightsNode!==null?this.setupLights(e):null;let l=this.setupOutgoingLight(e);if(a&&a.getScope().hasLights){const c=this.setupLightingModel(e)||null;l=VL(a,c,n,i)}else n!==null&&(l=te(i!==null?Dt(l,n,i):n));return(s&&s.isNode===!0||t.emissive&&t.emissive.isColor===!0)&&(Z_.assign(te(s||YD)),l=l.add(Z_)),l}setupFog(e,t){const n=e.fogNode;return n&&(tc.assign(t),t=et(n.toVar())),t}setupPremultipliedAlpha(e,t){return nU(t)}setupOutput(e,t){return this.fog===!0&&(t=this.setupFog(e,t)),this.premultipliedAlpha===!0&&(t=this.setupPremultipliedAlpha(e,t)),t}setDefaultValues(e){for(const n in e){const i=e[n];this[n]===void 0&&(this[n]=i,i&&i.clone&&(this[n]=i.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const n in t)Object.getOwnPropertyDescriptor(this.constructor.prototype,n)===void 0&&t[n].get!==void 0&&Object.defineProperty(this.constructor.prototype,n,t[n])}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{},nodes:{}});const n=Yn.prototype.toJSON.call(this,e);n.inputNodes={};for(const{property:s,childNode:o}of this._getNodeChildren())n.inputNodes[s]=o.toJSON(e).uuid;function i(s){const o=[];for(const a in s){const l=s[a];delete l.metadata,o.push(l)}return o}if(t){const s=i(e.textures),o=i(e.images),a=i(e.nodes);s.length>0&&(n.textures=s),o.length>0&&(n.images=o),a.length>0&&(n.nodes=a)}return n}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.aoNode=e.aoNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.maskNode=e.maskNode,this.maskShadowNode=e.maskShadowNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.receivedShadowPositionNode=e.receivedShadowPositionNode,this.castShadowPositionNode=e.castShadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,this.contextNode=e.contextNode,super.copy(e)}}const iU=new Oh;class rU extends mn{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.setDefaultValues(iU),this.setValues(e)}}const sU=new gM;class oU extends mn{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.setDefaultValues(sU),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?J(this.offsetNode):yL,t=this.dashScaleNode?J(this.dashScaleNode):gL,n=this.dashSizeNode?J(this.dashSizeNode):_L,i=this.gapSizeNode?J(this.gapSizeNode):xL;af.assign(n),Q_.assign(i);const s=Do(Is("lineDistance").mul(t));(e?s.add(e):s).mod(af.add(Q_)).greaterThan(af).discard()}}const aU=new dM;class lU extends mn{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(aU),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?J(this.opacityNode):Xv;Pt.assign(Hm(et(GD(vt),e),ei))}}const tb=re(([r=Dv])=>{const e=r.z.atan(r.x).mul(1/(Math.PI*2)).add(.5),t=r.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return ke(e,t)});class nb extends ks{constructor(e=1,t={}){super(e,e,t),this.isCubeRenderTarget=!0;const n={width:e,height:e,depth:1},i=[n,n,n,n,n,n];this.texture=new sl(i),this._setTextureOptions(t),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(e,t){const n=t.minFilter,i=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const s=new Co(5,5,5),o=tb(Dv),a=new mn;a.colorNode=Vt(t,o,0),a.side=Lt,a.blending=Pn;const l=new _n(s,a),c=new hm;c.add(l),t.minFilter===ui&&(t.minFilter=Nt);const u=new py(1,10,this),h=e.getMRT();return e.setMRT(null),u.update(e,c),e.setMRT(h),t.minFilter=n,t.generateMipmaps=i,l.geometry.dispose(),l.material.dispose(),this}clear(e,t=!0,n=!0,i=!0){const s=e.getRenderTarget();for(let o=0;o<6;o++)e.setRenderTarget(this,o),e.clear(t,n,i);e.setRenderTarget(s)}}const sc=new WeakMap;class cU extends xn{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=li(null);const t=new sl;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=Ze.RENDER}updateBefore(e){const{renderer:t,material:n}=e,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){const s=i.isTextureNode?i.value:n[i.property];if(s&&s.isTexture){const o=s.mapping;if(o===pa||o===ma){if(sc.has(s)){const a=sc.get(s);xx(a,s.mapping),this._cubeTexture=a}else{const a=s.image;if(uU(a)){const l=new nb(a.height);l.fromEquirectangularTexture(t,s),xx(l.texture,s.mapping),this._cubeTexture=l.texture,sc.set(s,l.texture),s.addEventListener("dispose",ib)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function uU(r){return r==null?!1:r.height>0}function ib(r){const e=r.target;e.removeEventListener("dispose",ib);const t=sc.get(e);t!==void 0&&(sc.delete(e),t.dispose())}function xx(r,e){e===pa?r.mapping=Ki:e===ma&&(r.mapping=Sr)}const rb=It(cU).setParameterLength(1);class qm extends gl{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=rb(this.envNode)}}class hU extends gl{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=J(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Yh{start(e){e.lightsNode.setupLights(e,e.lightsNode.getLightNodes(e)),this.indirect(e)}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class sb extends Yh{constructor(){super()}indirect({context:e}){const t=e.ambientOcclusion,n=e.reflectedLight,i=e.irradianceLightMap;n.indirectDiffuse.assign(et(0)),i?n.indirectDiffuse.addAssign(i):n.indirectDiffuse.addAssign(et(1,1,1,0)),n.indirectDiffuse.mulAssign(t),n.indirectDiffuse.mulAssign(Pt.rgb)}finish(e){const{material:t,context:n}=e,i=n.outgoingLight,s=e.context.environment;if(s)switch(t.combine){case Nc:i.rgb.assign(Dt(i.rgb,i.rgb.mul(s.rgb),fh.mul(pf)));break;case W0:i.rgb.assign(Dt(i.rgb,s.rgb,fh.mul(pf)));break;case $0:i.rgb.addAssign(s.rgb.mul(fh.mul(pf)));break;default:ae("BasicLightingModel: Unsupported .combine value:",t.combine);break}}}const dU=new pr;class fU extends mn{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(dU),this.setValues(e)}setupNormal(){return Wc(Ac)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new qm(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new hU(qv)),t}setupOutgoingLight(){return Pt.rgb}setupLightingModel(){return new sb}}const wc=re(({f0:r,f90:e,dotVH:t})=>{const n=t.mul(-5.55473).sub(6.98316).mul(t).exp2();return r.mul(n.oneMinus()).add(e.mul(n))}),el=re(r=>r.diffuseColor.mul(1/Math.PI)),pU=()=>J(.25),mU=re(({dotNH:r})=>vp.mul(J(.5)).add(1).mul(J(1/Math.PI)).mul(r.pow(vp))),gU=re(({lightDirection:r})=>{const e=r.add($t).normalize(),t=vt.dot(e).clamp(),n=$t.dot(e).clamp(),i=wc({f0:vo,f90:1,dotVH:n}),s=pU(),o=mU({dotNH:t});return i.mul(s).mul(o)});class ob extends sb{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:n}){const s=vt.dot(e).clamp().mul(t);n.directDiffuse.addAssign(s.mul(el({diffuseColor:Pt.rgb}))),this.specular===!0&&n.directSpecular.addAssign(s.mul(gU({lightDirection:e})).mul(fh))}indirect(e){const{ambientOcclusion:t,irradiance:n,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(n.mul(el({diffuseColor:Pt}))),i.indirectDiffuse.mulAssign(t)}}const _U=new uy;class xU extends mn{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(_U),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new qm(t):null}setupLightingModel(){return new ob(!1)}}const yU=new uM;class vU extends mn{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(yU),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new qm(t):null}setupLightingModel(){return new ob}setupVariants(){const e=(this.shininessNode?J(this.shininessNode):jD).max(1e-4);vp.assign(e);const t=this.specularNode||KD;vo.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const bU=re(r=>{if(r.geometry.hasAttribute("normal")===!1)return J(0);const e=Ac.dFdx().abs().max(Ac.dFdy().abs());return e.x.max(e.y).max(e.z)}),ab=re(r=>{const{roughness:e}=r,t=bU();let n=e.max(.0525);return n=n.add(t),n=n.min(1),n}),SU=re(({alpha:r,dotNL:e,dotNV:t})=>{const n=r.pow2(),i=e.mul(n.add(n.oneMinus().mul(t.pow2())).sqrt()),s=t.mul(n.add(n.oneMinus().mul(e.pow2())).sqrt());return Er(.5,i.add(s).max(Om))}).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),TU=re(({alphaT:r,alphaB:e,dotTV:t,dotBV:n,dotTL:i,dotBL:s,dotNV:o,dotNL:a})=>{const l=a.mul(te(r.mul(t),e.mul(n),o).length()),c=o.mul(te(r.mul(i),e.mul(s),a).length());return Er(.5,l.add(c).max(Om))}).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),MU=re(({alpha:r,dotNH:e})=>{const t=r.pow2(),n=e.pow2().mul(t.oneMinus()).oneMinus();return t.div(n.pow2()).mul(1/Math.PI)}).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),EU=J(1/Math.PI),AU=re(({alphaT:r,alphaB:e,dotNH:t,dotTH:n,dotBH:i})=>{const s=r.mul(e),o=te(e.mul(n),r.mul(i),s.mul(t)),a=o.dot(o),l=s.div(a);return EU.mul(s.mul(l.pow2()))}).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),lb=re(({lightDirection:r,f0:e,f90:t,roughness:n,f:i,normalView:s=vt,USE_IRIDESCENCE:o,USE_ANISOTROPY:a})=>{const l=n.pow2(),c=r.add($t).normalize(),u=s.dot(r).clamp(),h=s.dot($t).clamp(),d=s.dot(c).clamp(),f=$t.dot(c).clamp();let p=wc({f0:e,f90:t,dotVH:f}),g,m;if(mp(o)&&(p=Fm.mix(p,i)),mp(a)){const _=ch.dot(r),x=ch.dot($t),y=ch.dot(c),b=va.dot(r),M=va.dot($t),S=va.dot(c);g=TU({alphaT:yp,alphaB:l,dotTV:x,dotBV:M,dotTL:_,dotBL:b,dotNV:h,dotNL:u}),m=AU({alphaT:yp,alphaB:l,dotNH:d,dotTH:y,dotBH:S})}else g=SU({alpha:l,dotNL:u,dotNV:h}),m=MU({alpha:l,dotNH:d});return p.mul(g).mul(m)}),wU=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]);let or=null;const wh=re(({roughness:r,dotNV:e})=>{or===null&&(or=new gm(wU,16,16,In,tn),or.name="DFG_LUT",or.minFilter=Nt,or.magFilter=Nt,or.wrapS=ci,or.wrapT=ci,or.generateMipmaps=!1,or.needsUpdate=!0);const t=ke(r,e);return Vt(or,t).rg}),RU=re(({lightDirection:r,f0:e,f90:t,roughness:n,f:i,USE_IRIDESCENCE:s,USE_ANISOTROPY:o})=>{const a=lb({lightDirection:r,f0:e,f90:t,roughness:n,f:i,USE_IRIDESCENCE:s,USE_ANISOTROPY:o}),l=vt.dot(r).clamp(),c=vt.dot($t).clamp(),u=wh({roughness:n,dotNV:c}),h=wh({roughness:n,dotNV:l}),d=e.mul(u.x).add(t.mul(u.y)),f=e.mul(h.x).add(t.mul(h.y)),p=u.x.add(u.y),g=h.x.add(h.y),m=J(1).sub(p),_=J(1).sub(g),x=e.add(e.oneMinus().mul(.047619)),y=d.mul(f).mul(x).div(J(1).sub(m.mul(_).mul(x).mul(x)).add(Om)),b=m.mul(_),M=y.mul(b);return a.add(M)}),cb=re(r=>{const{dotNV:e,specularColor:t,specularF90:n,roughness:i}=r,s=wh({dotNV:e,roughness:i});return t.mul(s.x).add(n.mul(s.y))}),yx=re(({f:r,f90:e,dotVH:t})=>{const n=t.oneMinus().saturate(),i=n.mul(n),s=n.mul(i,i).clamp(0,.9999);return r.sub(te(e).mul(s)).div(s.oneMinus())}).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),CU=re(({roughness:r,dotNH:e})=>{const t=r.pow2(),n=J(1).div(t),s=e.pow2().oneMinus().max(.0078125);return J(2).add(n).mul(s.pow(n.mul(.5))).div(2*Math.PI)}).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),NU=re(({dotNV:r,dotNL:e})=>J(1).div(J(4).mul(e.add(r).sub(e.mul(r))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),PU=re(({lightDirection:r})=>{const e=r.add($t).normalize(),t=vt.dot(r).clamp(),n=vt.dot($t).clamp(),i=vt.dot(e).clamp(),s=CU({roughness:ro,dotNH:i}),o=NU({dotNV:n,dotNL:t});return Ci.mul(s).mul(o)}),vx=re(({N:r,V:e,roughness:t})=>{const s=.0078125,o=r.dot(e).saturate(),a=ke(t,o.oneMinus().sqrt());return a.assign(a.mul(.984375).add(s)),a}).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),DU=re(({f:r})=>{const e=r.length();return kn(e.mul(e).add(r.z).div(e.add(1)),0)}).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),Ou=re(({v1:r,v2:e})=>{const t=r.dot(e),n=t.abs().toVar(),i=n.mul(.0145206).add(.4965155).mul(n).add(.8543985).toVar(),s=n.add(4.1616724).mul(n).add(3.417594).toVar(),o=i.div(s),a=t.greaterThan(0).select(o,kn(t.mul(t).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return r.cross(e).mul(a)}).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),_f=re(({N:r,V:e,P:t,mInv:n,p0:i,p1:s,p2:o,p3:a})=>{const l=s.sub(i).toVar(),c=a.sub(i).toVar(),u=l.cross(c),h=te().toVar();return Ft(u.dot(t.sub(i)).greaterThanEqual(0),()=>{const d=e.sub(r.mul(e.dot(r))).normalize(),f=r.cross(d).negate(),p=n.mul(On(d,f,r).transpose()).toVar(),g=p.mul(i.sub(t)).normalize().toVar(),m=p.mul(s.sub(t)).normalize().toVar(),_=p.mul(o.sub(t)).normalize().toVar(),x=p.mul(a.sub(t)).normalize().toVar(),y=te(0).toVar();y.addAssign(Ou({v1:g,v2:m})),y.addAssign(Ou({v1:m,v2:_})),y.addAssign(Ou({v1:_,v2:x})),y.addAssign(Ou({v1:x,v2:g})),h.assign(te(DU({f:y})))}),h}).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),Kh=1/6,ub=r=>st(Kh,st(r,st(r,r.negate().add(3)).sub(3)).add(1)),Ep=r=>st(Kh,st(r,st(r,st(3,r).sub(6))).add(4)),hb=r=>st(Kh,st(r,st(r,st(-3,r).add(3)).add(3)).add(1)),Ap=r=>st(Kh,Xh(r,3)),bx=r=>ub(r).add(Ep(r)),Sx=r=>hb(r).add(Ap(r)),Tx=r=>fi(-1,Ep(r).div(ub(r).add(Ep(r)))),Mx=r=>fi(1,Ap(r).div(hb(r).add(Ap(r)))),Ex=(r,e,t)=>{const n=r.uvNode,i=st(n,e.zw).add(.5),s=ho(i),o=Ar(i),a=bx(o.x),l=Sx(o.x),c=Tx(o.x),u=Mx(o.x),h=Tx(o.y),d=Mx(o.y),f=ke(s.x.add(c),s.y.add(h)).sub(.5).mul(e.xy),p=ke(s.x.add(u),s.y.add(h)).sub(.5).mul(e.xy),g=ke(s.x.add(c),s.y.add(d)).sub(.5).mul(e.xy),m=ke(s.x.add(u),s.y.add(d)).sub(.5).mul(e.xy),_=bx(o.y).mul(fi(a.mul(r.sample(f).level(t)),l.mul(r.sample(p).level(t)))),x=Sx(o.y).mul(fi(a.mul(r.sample(g).level(t)),l.mul(r.sample(m).level(t))));return _.add(x)},LU=re(([r,e])=>{const t=ke(r.size(Zt(e))),n=ke(r.size(Zt(e.add(1)))),i=Er(1,t),s=Er(1,n),o=Ex(r,et(i,t),ho(e)),a=Ex(r,et(s,n),km(e));return Ar(e).mix(o,a)}),Ax=re(([r,e,t,n,i])=>{const s=te(xv(e.negate(),br(r),Er(1,n))),o=te(Kr(i[0].xyz),Kr(i[1].xyz),Kr(i[2].xyz));return br(s).mul(t.mul(o))}).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),UU=re(([r,e])=>r.mul(Fs(e.mul(2).sub(2),0,1))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),FU=Yv(),IU=WL(),wx=re(([r,e,t],{material:n})=>{const s=(n.side===Lt?FU:IU).sample(r),o=Yr(Sp.x).mul(UU(e,t));return LU(s,o)}),Rx=re(([r,e,t])=>(Ft(t.notEqual(0),()=>{const n=lv(e).negate().div(t);return av(n.negate().mul(r))}),te(1))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),BU=re(([r,e,t,n,i,s,o,a,l,c,u,h,d,f,p])=>{let g,m;if(p){g=et().toVar(),m=te().toVar();const M=u.sub(1).mul(p.mul(.025)),S=te(u.sub(M),u,u.add(M));Li({start:0,end:3},({i:E})=>{const v=S.element(E),w=Ax(r,e,h,v,a),N=o.add(w),C=c.mul(l.mul(et(N,1))),F=ke(C.xy.div(C.w)).toVar();F.addAssign(1),F.divAssign(2),F.assign(ke(F.x,F.y.oneMinus()));const V=wx(F,t,v);g.element(E).assign(V.element(E)),g.a.addAssign(V.a),m.element(E).assign(n.element(E).mul(Rx(Kr(w),d,f).element(E)))}),g.a.divAssign(3)}else{const M=Ax(r,e,h,u,a),S=o.add(M),E=c.mul(l.mul(et(S,1))),v=ke(E.xy.div(E.w)).toVar();v.addAssign(1),v.divAssign(2),v.assign(ke(v.x,v.y.oneMinus())),g=wx(v,t,u),m=n.mul(Rx(Kr(M),d,f))}const _=m.rgb.mul(g.rgb),x=r.dot(e).clamp(),y=te(cb({dotNV:x,specularColor:i,specularF90:s,roughness:t})),b=m.r.add(m.g,m.b).div(3);return et(y.oneMinus().mul(_),g.a.oneMinus().mul(b).oneMinus())}),OU=On(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),kU=r=>{const e=r.sqrt();return te(1).add(e).div(te(1).sub(e))},Cx=(r,e)=>r.sub(e).div(r.add(e)).pow2(),GU=(r,e)=>{const t=r.mul(2*Math.PI*1e-9),n=te(54856e-17,44201e-17,52481e-17),i=te(1681e3,1795300,2208400),s=te(43278e5,93046e5,66121e5),o=J(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(t.mul(2239900).add(e.x).cos()).mul(t.pow2().mul(-45282e5).exp());let a=n.mul(s.mul(2*Math.PI).sqrt()).mul(i.mul(t).add(e).cos()).mul(t.pow2().negate().mul(s).exp());return a=te(a.x.add(o),a.y,a.z).div(10685e-11),OU.mul(a)},Nx=re(({outsideIOR:r,eta2:e,cosTheta1:t,thinFilmThickness:n,baseF0:i})=>{const s=Dt(r,e,Qr(0,.03,n)),a=r.div(s).pow2().mul(t.pow2().oneMinus()).oneMinus();Ft(a.lessThan(0),()=>te(1));const l=a.sqrt(),c=Cx(s,r),u=wc({f0:c,f90:1,dotVH:t}),h=u.oneMinus(),d=s.lessThan(r).select(Math.PI,0),f=J(Math.PI).sub(d),p=kU(i.clamp(0,.9999)),g=Cx(p,s.toVec3()),m=wc({f0:g,f90:1,dotVH:l}),_=te(p.x.lessThan(s).select(Math.PI,0),p.y.lessThan(s).select(Math.PI,0),p.z.lessThan(s).select(Math.PI,0)),x=s.mul(n,l,2),y=te(f).add(_),b=u.mul(m).clamp(1e-5,.9999),M=b.sqrt(),S=h.pow2().mul(m).div(te(1).sub(b)),v=u.add(S).toVar(),w=S.sub(h).toVar();return Li({start:1,end:2,condition:"<=",name:"m"},({m:N})=>{w.mulAssign(M);const C=GU(J(N).mul(x),J(N).mul(y)).mul(2);v.addAssign(w.mul(C))}),v.max(te(0))}).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),Fl=re(({normal:r,viewDir:e,roughness:t})=>{const n=r.dot(e).saturate(),i=t.mul(t),s=t.add(.1).reciprocal(),o=J(-1.9362).add(t.mul(1.0678)).add(i.mul(.4573)).sub(s.mul(.8469)),a=J(-.6014).add(t.mul(.5538)).sub(i.mul(.467)).sub(s.mul(.1255));return o.mul(n).add(a).exp().saturate()}),Il=te(.04),ku=J(1);class db extends Yh{constructor(e=!1,t=!1,n=!1,i=!1,s=!1,o=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=n,this.anisotropy=i,this.transmission=s,this.dispersion=o,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null,this.iridescenceF0Dielectric=null,this.iridescenceF0Metallic=null}start(e){if(this.clearcoat===!0&&(this.clearcoatRadiance=te().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=te().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=te().toVar("clearcoatSpecularIndirect")),this.sheen===!0&&(this.sheenSpecularDirect=te().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=te().toVar("sheenSpecularIndirect")),this.iridescence===!0){const t=vt.dot($t).clamp(),n=Nx({outsideIOR:J(1),eta2:_p,cosTheta1:t,thinFilmThickness:xp,baseF0:vo}),i=Nx({outsideIOR:J(1),eta2:_p,cosTheta1:t,thinFilmThickness:xp,baseF0:Pt.rgb});this.iridescenceFresnel=Dt(n,i,bs),this.iridescenceF0Dielectric=yx({f:n,f90:1,dotVH:t}),this.iridescenceF0Metallic=yx({f:i,f90:1,dotVH:t}),this.iridescenceF0=Dt(this.iridescenceF0Dielectric,this.iridescenceF0Metallic,bs)}if(this.transmission===!0){const t=Ja,n=pD.sub(Ja).normalize(),i=ml,s=e.context;s.backdrop=BU(i,n,Wr,ca,ha,da,t,To,es,ic,uh,nv,rv,iv,this.dispersion?sv:null),s.backdropAlpha=bp,Pt.a.mulAssign(Dt(1,s.backdrop.a,bp))}super.start(e)}computeMultiscattering(e,t,n,i,s=null){const o=vt.dot($t).clamp(),a=wh({roughness:Wr,dotNV:o}),l=s?Fm.mix(i,s):i,c=l.mul(a.x).add(n.mul(a.y)),h=a.x.add(a.y).oneMinus(),d=l.add(l.oneMinus().mul(.047619)),f=c.mul(d).div(h.mul(d).oneMinus());e.addAssign(c),t.addAssign(f.mul(h))}direct({lightDirection:e,lightColor:t,reflectedLight:n}){const s=vt.dot(e).clamp().mul(t).toVar();if(this.sheen===!0){this.sheenSpecularDirect.addAssign(s.mul(PU({lightDirection:e})));const o=Fl({normal:vt,viewDir:$t,roughness:ro}),a=Fl({normal:vt,viewDir:e,roughness:ro}),l=Ci.r.max(Ci.g).max(Ci.b).mul(o.max(a)).oneMinus();s.mulAssign(l)}if(this.clearcoat===!0){const a=ao.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(a.mul(lb({lightDirection:e,f0:Il,f90:ku,roughness:ec,normalView:ao})))}n.directDiffuse.addAssign(s.mul(el({diffuseColor:ca}))),n.directSpecular.addAssign(s.mul(RU({lightDirection:e,f0:ha,f90:1,roughness:Wr,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:n,halfHeight:i,reflectedLight:s,ltc_1:o,ltc_2:a}){const l=t.add(n).sub(i),c=t.sub(n).sub(i),u=t.sub(n).add(i),h=t.add(n).add(i),d=vt,f=$t,p=dn.toVar(),g=vx({N:d,V:f,roughness:Wr}),m=o.sample(g).toVar(),_=a.sample(g).toVar(),x=On(te(m.x,0,m.y),te(0,1,0),te(m.z,0,m.w)).toVar(),y=ha.mul(_.x).add(da.sub(ha).mul(_.y)).toVar();if(s.directSpecular.addAssign(e.mul(y).mul(_f({N:d,V:f,P:p,mInv:x,p0:l,p1:c,p2:u,p3:h}))),s.directDiffuse.addAssign(e.mul(ca).mul(_f({N:d,V:f,P:p,mInv:On(1,0,0,0,1,0,0,0,1),p0:l,p1:c,p2:u,p3:h}))),this.clearcoat===!0){const b=ao,M=vx({N:b,V:f,roughness:ec}),S=o.sample(M),E=a.sample(M),v=On(te(S.x,0,S.y),te(0,1,0),te(S.z,0,S.w)),w=Il.mul(E.x).add(ku.sub(Il).mul(E.y));this.clearcoatSpecularDirect.addAssign(e.mul(w).mul(_f({N:b,V:f,P:p,mInv:v,p0:l,p1:c,p2:u,p3:h})))}}indirect(e){this.indirectDiffuse(e),this.indirectSpecular(e),this.ambientOcclusion(e)}indirectDiffuse(e){const{irradiance:t,reflectedLight:n}=e.context,i=t.mul(el({diffuseColor:ca})).toVar();if(this.sheen===!0){const s=Fl({normal:vt,viewDir:$t,roughness:ro}),o=Ci.r.max(Ci.g).max(Ci.b).mul(s).oneMinus();i.mulAssign(o)}n.indirectDiffuse.addAssign(i)}indirectSpecular(e){const{radiance:t,iblIrradiance:n,reflectedLight:i}=e.context;if(this.sheen===!0&&this.sheenSpecularIndirect.addAssign(n.mul(Ci,Fl({normal:vt,viewDir:$t,roughness:ro}))),this.clearcoat===!0){const m=ao.dot($t).clamp(),_=cb({dotNV:m,specularColor:Il,specularF90:ku,roughness:ec});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(_))}const s=te().toVar("singleScatteringDielectric"),o=te().toVar("multiScatteringDielectric"),a=te().toVar("singleScatteringMetallic"),l=te().toVar("multiScatteringMetallic");this.computeMultiscattering(s,o,da,vo,this.iridescenceF0Dielectric),this.computeMultiscattering(a,l,da,Pt.rgb,this.iridescenceF0Metallic);const c=Dt(s,a,bs),u=Dt(o,l,bs),h=s.add(o),d=ca.mul(h.oneMinus()),f=n.mul(1/Math.PI),p=t.mul(c).add(u.mul(f)).toVar(),g=d.mul(f).toVar();if(this.sheen===!0){const m=Fl({normal:vt,viewDir:$t,roughness:ro}),_=Ci.r.max(Ci.g).max(Ci.b).mul(m).oneMinus();p.mulAssign(_),g.mulAssign(_)}i.indirectSpecular.addAssign(p),i.indirectDiffuse.addAssign(g)}ambientOcclusion(e){const{ambientOcclusion:t,reflectedLight:n}=e.context,s=vt.dot($t).clamp().add(t),o=Wr.mul(-16).oneMinus().negate().exp2(),a=t.sub(s.pow(o).oneMinus()).clamp();this.clearcoat===!0&&this.clearcoatSpecularIndirect.mulAssign(t),this.sheen===!0&&this.sheenSpecularIndirect.mulAssign(t),n.indirectDiffuse.mulAssign(t),n.indirectSpecular.mulAssign(a)}finish({context:e}){const{outgoingLight:t}=e;if(this.clearcoat===!0){const n=ao.dot($t).clamp(),i=wc({dotVH:n,f0:Il,f90:ku}),s=t.mul(gp.mul(i).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(gp));t.assign(s)}if(this.sheen===!0){const n=t.add(this.sheenSpecularDirect,this.sheenSpecularIndirect.mul(1/Math.PI));t.assign(n)}}}const Px=J(1),wp=J(-2),Gu=J(.8),xf=J(-1),Vu=J(.4),yf=J(2),zu=J(.305),vf=J(3),Dx=J(.21),VU=J(4),Lx=J(4),zU=J(16),HU=re(([r])=>{const e=te(Si(r)).toVar(),t=J(-1).toVar();return Ft(e.x.greaterThan(e.z),()=>{Ft(e.x.greaterThan(e.y),()=>{t.assign(Mi(r.x.greaterThan(0),0,3))}).Else(()=>{t.assign(Mi(r.y.greaterThan(0),1,4))})}).Else(()=>{Ft(e.z.greaterThan(e.y),()=>{t.assign(Mi(r.z.greaterThan(0),2,5))}).Else(()=>{t.assign(Mi(r.y.greaterThan(0),1,4))})}),t}).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),WU=re(([r,e])=>{const t=ke().toVar();return Ft(e.equal(0),()=>{t.assign(ke(r.z,r.y).div(Si(r.x)))}).ElseIf(e.equal(1),()=>{t.assign(ke(r.x.negate(),r.z.negate()).div(Si(r.y)))}).ElseIf(e.equal(2),()=>{t.assign(ke(r.x.negate(),r.y).div(Si(r.z)))}).ElseIf(e.equal(3),()=>{t.assign(ke(r.z.negate(),r.y).div(Si(r.x)))}).ElseIf(e.equal(4),()=>{t.assign(ke(r.x.negate(),r.z).div(Si(r.y)))}).Else(()=>{t.assign(ke(r.x,r.y).div(Si(r.z)))}),st(.5,t.add(1))}).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),$U=re(([r])=>{const e=J(0).toVar();return Ft(r.greaterThanEqual(Gu),()=>{e.assign(Px.sub(r).mul(xf.sub(wp)).div(Px.sub(Gu)).add(wp))}).ElseIf(r.greaterThanEqual(Vu),()=>{e.assign(Gu.sub(r).mul(yf.sub(xf)).div(Gu.sub(Vu)).add(xf))}).ElseIf(r.greaterThanEqual(zu),()=>{e.assign(Vu.sub(r).mul(vf.sub(yf)).div(Vu.sub(zu)).add(yf))}).ElseIf(r.greaterThanEqual(Dx),()=>{e.assign(zu.sub(r).mul(VU.sub(vf)).div(zu.sub(Dx)).add(vf))}).Else(()=>{e.assign(J(-2).mul(Yr(st(1.16,r))))}),e}).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),XU=re(([r,e])=>{const t=r.toVar();t.assign(st(2,t).sub(1));const n=te(t,1).toVar();return Ft(e.equal(0),()=>{n.assign(n.zyx)}).ElseIf(e.equal(1),()=>{n.assign(n.xzy),n.xz.mulAssign(-1)}).ElseIf(e.equal(2),()=>{n.x.mulAssign(-1)}).ElseIf(e.equal(3),()=>{n.assign(n.zyx),n.xz.mulAssign(-1)}).ElseIf(e.equal(4),()=>{n.assign(n.xzy),n.xy.mulAssign(-1)}).ElseIf(e.equal(5),()=>{n.z.mulAssign(-1)}),n}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),qU=re(([r,e,t,n,i,s])=>{const o=J(t),a=te(e),l=Fs($U(o),wp,s),c=Ar(l),u=ho(l),h=te(Rc(r,a,u,n,i,s)).toVar();return Ft(c.notEqual(0),()=>{const d=te(Rc(r,a,u.add(1),n,i,s)).toVar();h.assign(Dt(h,d,c))}),h}),Rc=re(([r,e,t,n,i,s])=>{const o=J(t).toVar(),a=te(e),l=J(HU(a)).toVar(),c=J(kn(Lx.sub(o),0)).toVar();o.assign(kn(o,Lx));const u=J(Mc(o)).toVar(),h=ke(WU(a,l).mul(u.sub(2)).add(1)).toVar();return Ft(l.greaterThan(2),()=>{h.y.addAssign(u),l.subAssign(3)}),h.x.addAssign(l.mul(u)),h.x.addAssign(c.mul(st(3,zU))),h.y.addAssign(st(4,Mc(s).sub(u))),h.x.mulAssign(n),h.y.mulAssign(i),r.sample(h).grad(ke(),ke())}),bf=re(({envMap:r,mipInt:e,outputDirection:t,theta:n,axis:i,CUBEUV_TEXEL_WIDTH:s,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const l=fr(n),c=t.mul(l).add(i.cross(t).mul(bi(n))).add(i.mul(i.dot(t).mul(l.oneMinus())));return Rc(r,c,e,s,o,a)}),jU=re(({n:r,latitudinal:e,poleAxis:t,outputDirection:n,weights:i,samples:s,dTheta:o,mipInt:a,envMap:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h})=>{const d=te(Mi(e,t,So(t,n))).toVar();Ft(d.equal(te(0)),()=>{d.assign(te(n.z,0,n.x.negate()))}),d.assign(br(d));const f=te().toVar();return f.addAssign(i.element(0).mul(bf({theta:0,axis:d,outputDirection:n,mipInt:a,envMap:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h}))),Li({start:Zt(1),end:r},({i:p})=>{Ft(p.greaterThanEqual(s),()=>{FL()});const g=J(o.mul(J(p))).toVar();f.addAssign(i.element(p).mul(bf({theta:g.mul(-1),axis:d,outputDirection:n,mipInt:a,envMap:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h}))),f.addAssign(i.element(p).mul(bf({theta:g,axis:d,outputDirection:n,mipInt:a,envMap:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h})))}),et(f,1)}),YU=re(([r])=>{const e=mt(r).toVar();return e.assign(e.shiftLeft(mt(16)).bitOr(e.shiftRight(mt(16)))),e.assign(e.bitAnd(mt(1431655765)).shiftLeft(mt(1)).bitOr(e.bitAnd(mt(2863311530)).shiftRight(mt(1)))),e.assign(e.bitAnd(mt(858993459)).shiftLeft(mt(2)).bitOr(e.bitAnd(mt(3435973836)).shiftRight(mt(2)))),e.assign(e.bitAnd(mt(252645135)).shiftLeft(mt(4)).bitOr(e.bitAnd(mt(4042322160)).shiftRight(mt(4)))),e.assign(e.bitAnd(mt(16711935)).shiftLeft(mt(8)).bitOr(e.bitAnd(mt(4278255360)).shiftRight(mt(8)))),J(e).mul(23283064365386963e-26)}),KU=re(([r,e])=>ke(J(r).div(J(e)),YU(r))),ZU=re(([r,e,t])=>{const n=t.mul(t).toConst(),i=te(1,0,0).toConst(),s=So(e,i).toConst(),o=Ps(r.x).toConst(),a=st(2,3.14159265359).mul(r.y).toConst(),l=o.mul(fr(a)).toConst(),c=o.mul(bi(a)).toVar(),u=st(.5,e.z.add(1)).toConst();c.assign(u.oneMinus().mul(Ps(l.mul(l).oneMinus())).add(u.mul(c)));const h=i.mul(l).add(s.mul(c)).add(e.mul(Ps(kn(0,l.mul(l).add(c.mul(c)).oneMinus()))));return br(te(n.mul(h.x),n.mul(h.y),kn(0,h.z)))}),QU=re(({roughness:r,mipInt:e,envMap:t,N_immutable:n,GGX_SAMPLES:i,CUBEUV_TEXEL_WIDTH:s,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const l=te(n).toVar(),c=te(0).toVar(),u=J(0).toVar();return Ft(r.lessThan(.001),()=>{c.assign(Rc(t,l,e,s,o,a))}).Else(()=>{const h=Mi(Si(l.z).lessThan(.999),te(0,0,1),te(1,0,0)),d=br(So(h,l)).toVar(),f=So(l,d).toVar();Li({start:mt(0),end:i},({i:p})=>{const g=KU(p,i),m=ZU(g,te(0,0,1),r),_=br(d.mul(m.x).add(f.mul(m.y)).add(l.mul(m.z))),x=br(_.mul(bo(l,_).mul(2)).sub(l)),y=kn(bo(l,x),0);Ft(y.greaterThan(0),()=>{const b=Rc(t,x,e,s,o,a);c.addAssign(b.mul(y)),u.addAssign(y)})}),Ft(u.greaterThan(0),()=>{c.assign(c.div(u))})}),et(c,1)}),Ss=4,Ux=[.125,.215,.35,.446,.526,.582],lo=20,JU=512,Bl=new ol(-1,1,1,-1,0,1),eF=new Cn(90,1),Fx=new We;let Sf=null,Tf=0,Mf=0;const tF=new P,Rh=new WeakMap,nF=[3,1,5,0,4,2],Ef=XU(dl(),Is("faceIndex")).normalize(),Zh=te(Ef.x,Ef.y,Ef.z);class iF{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._ggxMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}get _hasInitialized(){return this._renderer.hasInitialized()}fromScene(e,t=0,n=.1,i=100,s={}){const{size:o=256,position:a=tF,renderTarget:l=null}=s;if(this._setSize(o),this._hasInitialized===!1){ae('PMREMGenerator: ".fromScene()" called before the backend is initialized. Try using "await renderer.init()" instead.');const u=l||this._allocateTarget();return s.renderTarget=u,this.fromSceneAsync(e,t,n,i,s),u}Sf=this._renderer.getRenderTarget(),Tf=this._renderer.getActiveCubeFace(),Mf=this._renderer.getActiveMipmapLevel();const c=l||this._allocateTarget();return c.depthBuffer=!0,this._init(c),this._sceneToCubeUV(e,n,i,c,a),t>0&&this._blur(c,0,0,t),this._applyPMREM(c),this._cleanup(c),c}async fromSceneAsync(e,t=0,n=.1,i=100,s={}){return Kt('PMREMGenerator: ".fromSceneAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this.fromScene(e,t,n,i,s)}fromEquirectangular(e,t=null){if(this._hasInitialized===!1){ae('PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Try using "await renderer.init()" instead.'),this._setSizeFromTexture(e);const n=t||this._allocateTarget();return this.fromEquirectangularAsync(e,n),n}return this._fromTexture(e,t)}async fromEquirectangularAsync(e,t=null){return Kt('PMREMGenerator: ".fromEquirectangularAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}fromCubemap(e,t=null){if(this._hasInitialized===!1){ae("PMREMGenerator: .fromCubemap() called before the backend is initialized. Try using .fromCubemapAsync() instead."),this._setSizeFromTexture(e);const n=t||this._allocateTarget();return this.fromCubemapAsync(e,t),n}return this._fromTexture(e,t)}async fromCubemapAsync(e,t=null){return Kt('PMREMGenerator: ".fromCubemapAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}async compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=Bx(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=Ox(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSizeFromTexture(e){e.mapping===Ki||e.mapping===Sr?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4)}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodMeshes.length;e++)this._lodMeshes[e].geometry.dispose()}_cleanup(e){this._renderer.setRenderTarget(Sf,Tf,Mf),e.scissorTest=!1,this._setViewport(e,0,0,e.width,e.height)}_fromTexture(e,t){this._setSizeFromTexture(e),Sf=this._renderer.getRenderTarget(),Tf=this._renderer.getActiveCubeFace(),Mf=this._renderer.getActiveMipmapLevel();const n=t||this._allocateTarget();return this._init(n),this._textureToCubeUV(e,n),this._applyPMREM(n),this._cleanup(n),n}_allocateTarget(){const e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize;return Ix(e,t)}_init(e){if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e.width||this._pingPongRenderTarget.height!==e.height){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=Ix(e.width,e.height);const{_lodMax:t}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=rF(t)),this._blurMaterial=sF(t,e.width,e.height),this._ggxMaterial=oF(t,e.width,e.height)}}async _compileMaterial(e){const t=new _n(new An,e);await this._renderer.compile(t,Bl)}_sceneToCubeUV(e,t,n,i,s){const o=eF;o.near=t,o.far=n;const a=[1,1,1,1,-1,1],l=[1,-1,1,-1,1,-1],c=this._renderer,u=c.autoClear;c.getClearColor(Fx),c.autoClear=!1,this._backgroundBox===null&&(this._backgroundBox=new _n(new Co,new pr({name:"PMREM.Background",side:Lt,depthWrite:!1,depthTest:!1})));const h=this._backgroundBox,d=h.material;let f=!1;const p=e.background;p?p.isColor&&(d.color.copy(p),e.background=null,f=!0):(d.color.copy(Fx),f=!0),c.setRenderTarget(i),c.clear(),f&&c.render(h,o);for(let g=0;g<6;g++){const m=g%3;m===0?(o.up.set(0,a[g],0),o.position.set(s.x,s.y,s.z),o.lookAt(s.x+l[g],s.y,s.z)):m===1?(o.up.set(0,0,a[g]),o.position.set(s.x,s.y,s.z),o.lookAt(s.x,s.y+l[g],s.z)):(o.up.set(0,a[g],0),o.position.set(s.x,s.y,s.z),o.lookAt(s.x,s.y,s.z+l[g]));const _=this._cubeSize;this._setViewport(i,m*_,g>2?_:0,_,_),c.render(e,o)}c.autoClear=u,e.background=p}_textureToCubeUV(e,t){const n=this._renderer,i=e.mapping===Ki||e.mapping===Sr;i?this._cubemapMaterial===null&&(this._cubemapMaterial=Bx(e)):this._equirectMaterial===null&&(this._equirectMaterial=Ox(e));const s=i?this._cubemapMaterial:this._equirectMaterial;s.fragmentNode.value=e;const o=this._lodMeshes[0];o.material=s;const a=this._cubeSize;this._setViewport(t,0,0,3*a,2*a),n.setRenderTarget(t),n.render(o,Bl)}_applyPMREM(e){const t=this._renderer,n=t.autoClear;t.autoClear=!1;const i=this._lodMeshes.length;for(let s=1;s<i;s++)this._applyGGXFilter(e,s-1,s);t.autoClear=n}_applyGGXFilter(e,t,n){const i=this._renderer,s=this._pingPongRenderTarget,o=this._ggxMaterial,a=this._lodMeshes[n];a.material=o;const l=Rh.get(o),c=n/(this._lodMeshes.length-1),u=t/(this._lodMeshes.length-1),h=Math.sqrt(c*c-u*u),d=0+c*1.25,f=h*d,{_lodMax:p}=this,g=this._sizeLods[n],m=3*g*(n>p-Ss?n-p+Ss:0),_=4*(this._cubeSize-g);e.texture.frame=(e.texture.frame||0)+1,l.envMap.value=e.texture,l.roughness.value=f,l.mipInt.value=p-t,this._setViewport(s,m,_,3*g,2*g),i.setRenderTarget(s),i.render(a,Bl),s.texture.frame=(s.texture.frame||0)+1,l.envMap.value=s.texture,l.roughness.value=0,l.mipInt.value=p-n,this._setViewport(e,m,_,3*g,2*g),i.setRenderTarget(e),i.render(a,Bl)}_blur(e,t,n,i,s){const o=this._pingPongRenderTarget;this._halfBlur(e,o,t,n,i,"latitudinal",s),this._halfBlur(o,e,n,n,i,"longitudinal",s)}_halfBlur(e,t,n,i,s,o,a){const l=this._renderer,c=this._blurMaterial;o!=="latitudinal"&&o!=="longitudinal"&&ce("blur direction must be either latitudinal or longitudinal!");const u=3,h=this._lodMeshes[i];h.material=c;const d=Rh.get(c),f=this._sizeLods[n]-1,p=isFinite(s)?Math.PI/(2*f):2*Math.PI/(2*lo-1),g=s/p,m=isFinite(s)?1+Math.floor(u*g):lo;m>lo&&ae(`sigmaRadians, ${s}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${lo}`);const _=[];let x=0;for(let E=0;E<lo;++E){const v=E/g,w=Math.exp(-v*v/2);_.push(w),E===0?x+=w:E<m&&(x+=2*w)}for(let E=0;E<_.length;E++)_[E]=_[E]/x;e.texture.frame=(e.texture.frame||0)+1,d.envMap.value=e.texture,d.samples.value=m,d.weights.array=_,d.latitudinal.value=o==="latitudinal"?1:0,a&&(d.poleAxis.value=a);const{_lodMax:y}=this;d.dTheta.value=p,d.mipInt.value=y-n;const b=this._sizeLods[i],M=3*b*(i>y-Ss?i-y+Ss:0),S=4*(this._cubeSize-b);this._setViewport(t,M,S,3*b,2*b),l.setRenderTarget(t),l.render(h,Bl)}_setViewport(e,t,n,i,s){this._renderer.isWebGLRenderer?(e.viewport.set(t,e.height-s-n,i,s),e.scissor.set(t,e.height-s-n,i,s)):(e.viewport.set(t,n,i,s),e.scissor.set(t,n,i,s))}}function rF(r){const e=[],t=[],n=[];let i=r;const s=r-Ss+1+Ux.length;for(let o=0;o<s;o++){const a=Math.pow(2,i);e.push(a);let l=1/a;o>r-Ss?l=Ux[o-r+Ss-1]:o===0&&(l=0),t.push(l);const c=1/(a-2),u=-c,h=1+c,d=[u,u,h,u,h,h,u,u,h,h,u,h],f=6,p=6,g=3,m=2,_=1,x=new Float32Array(g*p*f),y=new Float32Array(m*p*f),b=new Float32Array(_*p*f);for(let S=0;S<f;S++){const E=S%3*2/3-1,v=S>2?0:-1,w=[E,v,0,E+2/3,v,0,E+2/3,v+1,0,E,v,0,E+2/3,v+1,0,E,v+1,0],N=nF[S];x.set(w,g*p*N),y.set(d,m*p*N);const C=[N,N,N,N,N,N];b.set(C,_*p*N)}const M=new An;M.setAttribute("position",new Bn(x,g)),M.setAttribute("uv",new Bn(y,m)),M.setAttribute("faceIndex",new Bn(b,_)),n.push(new _n(M,null)),i>Ss&&i--}return{lodMeshes:n,sizeLods:e,sigmas:t}}function Ix(r,e){const t={magFilter:Nt,minFilter:Nt,generateMipmaps:!1,type:tn,format:ln,colorSpace:yc},n=new ks(r,e,t);return n.texture.mapping=mo,n.texture.name="PMREM.cubeUv",n.texture.isPMREMTexture=!0,n.scissorTest=!0,n}function Qh(r){const e=new mn;return e.depthTest=!1,e.depthWrite=!1,e.blending=Pn,e.name=`PMREM_${r}`,e}function sF(r,e,t){const n=Di(new Array(lo).fill(0)),i=qe(new P(0,1,0)),s=qe(0),o=J(lo),a=qe(0),l=qe(1),c=Vt(),u=qe(0),h=J(1/e),d=J(1/t),f=J(r),p={n:o,latitudinal:a,weights:n,poleAxis:i,outputDirection:Zh,dTheta:s,samples:l,envMap:c,mipInt:u,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:f},g=Qh("blur");return g.fragmentNode=jU({...p,latitudinal:a.equal(1)}),Rh.set(g,p),g}function oF(r,e,t){const n=Vt(),i=qe(0),s=qe(0),o=J(1/e),a=J(1/t),l=J(r),c={envMap:n,roughness:i,mipInt:s,CUBEUV_TEXEL_WIDTH:o,CUBEUV_TEXEL_HEIGHT:a,CUBEUV_MAX_MIP:l},u=Qh("ggx");return u.fragmentNode=QU({...c,N_immutable:Zh,GGX_SAMPLES:mt(JU)}),Rh.set(u,c),u}function Bx(r){const e=Qh("cubemap");return e.fragmentNode=li(r,Zh),e}function Ox(r){const e=Qh("equirect");return e.fragmentNode=Vt(r,tb(Zh),0),e}const kx=new WeakMap;function aF(r){const e=Math.log2(r)-2,t=1/r;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:t,maxMip:e}}function lF(r,e,t){const n=cF(e);let i=n.get(r);if((i!==void 0?i.pmremVersion:-1)!==r.pmremVersion){const o=r.image;if(r.isCubeTexture)if(hF(o))i=t.fromCubemap(r,i);else return null;else if(dF(o))i=t.fromEquirectangular(r,i);else return null;i.pmremVersion=r.pmremVersion,n.set(r,i)}return i.texture}function cF(r){let e=kx.get(r);return e===void 0&&(e=new WeakMap,kx.set(r,e)),e}class uF extends xn{static get type(){return"PMREMNode"}constructor(e,t=null,n=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=n,this._generator=null;const i=new fn;i.isRenderTargetTexture=!0,this._texture=Vt(i),this._width=qe(0),this._height=qe(0),this._maxMip=qe(0),this.updateBeforeType=Ze.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=aF(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(e){let t=this._pmrem;const n=t?t.pmremVersion:-1,i=this._value;n!==i.pmremVersion&&(i.isPMREMTexture===!0?t=i:t=lF(i,e.renderer,this._generator),t!==null&&(this._pmrem=t,this.updateFromTexture(t)))}setup(e){this._generator===null&&(this._generator=new iF(e.renderer)),this.updateBefore(e);let t=this.uvNode;t===null&&e.context.getUV&&(t=e.context.getUV(this,e)),t=Iv.mul(te(t.x,t.y.negate(),t.z));let n=this.levelNode;return n===null&&e.context.getTextureLevel&&(n=e.context.getTextureLevel(this)),qU(this._texture,t,n,this._width,this._height,this._maxMip)}dispose(){super.dispose(),this._generator!==null&&this._generator.dispose()}}function hF(r){if(r==null)return!1;let e=0;const t=6;for(let n=0;n<t;n++)r[n]!==void 0&&e++;return e===t}function dF(r){return r==null?!1:r.height>0}const fb=It(uF).setParameterLength(1,3),Gx=new WeakMap;class fF extends gl{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let n=this.envNode;if(n.isTextureNode||n.isMaterialReferenceNode){const h=n.isTextureNode?n.value:t[n.property],d=this._getPMREMNodeCache(e.renderer);let f=d.get(h);f===void 0&&(f=fb(h),d.set(h,f)),n=f}const s=t.useAnisotropy===!0||t.anisotropy>0?kD:vt,o=n.context(Vx(Wr,s)).mul(ff),a=n.context(pF(ml)).mul(Math.PI).mul(ff),l=nc(o),c=nc(a);e.context.radiance.addAssign(l),e.context.iblIrradiance.addAssign(c);const u=e.context.lightingModel.clearcoatRadiance;if(u){const h=n.context(Vx(ec,ao)).mul(ff),d=nc(h);u.addAssign(d)}}_getPMREMNodeCache(e){let t=Gx.get(e);return t===void 0&&(t=new WeakMap,Gx.set(e,t)),t}}const Vx=(r,e)=>{let t=null;return{getUV:()=>(t===null&&(t=$t.negate().reflect(e),t=gv(r).mix(t,e).normalize(),t=t.transformDirection(es)),t),getTextureLevel:()=>r}},pF=r=>({getUV:()=>r,getTextureLevel:()=>J(1)}),mF=new cy;class pb extends mn{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(mF),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t===null&&e.environmentNode&&(t=e.environmentNode),t?new fF(t):null}setupLightingModel(){return new db}setupSpecular(){const e=Dt(te(.04),Pt.rgb,bs);vo.assign(te(.04)),ha.assign(e),da.assign(1)}setupVariants(){const e=this.metalnessNode?J(this.metalnessNode):JD;bs.assign(e);let t=this.roughnessNode?J(this.roughnessNode):QD;t=ab({roughness:t}),Wr.assign(t),this.setupSpecular(),ca.assign(Pt.rgb.mul(e.oneMinus()))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const gF=new cM;class _F extends pb{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(gF),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||this.clearcoatNode!==null}get useIridescence(){return this.iridescence>0||this.iridescenceNode!==null}get useSheen(){return this.sheen>0||this.sheenNode!==null}get useAnisotropy(){return this.anisotropy>0||this.anisotropyNode!==null}get useTransmission(){return this.transmission>0||this.transmissionNode!==null}get useDispersion(){return this.dispersion>0||this.dispersionNode!==null}setupSpecular(){const e=this.iorNode?J(this.iorNode):fL;uh.assign(e),vo.assign(Qa(mv(uh.sub(1).div(uh.add(1))).mul(ZD),te(1)).mul(dx)),ha.assign(Dt(vo,Pt.rgb,bs)),da.assign(Dt(dx,1,bs))}setupLightingModel(){return new db(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const t=this.clearcoatNode?J(this.clearcoatNode):tL,n=this.clearcoatRoughnessNode?J(this.clearcoatRoughnessNode):nL;gp.assign(t),ec.assign(ab({roughness:n}))}if(this.useSheen){const t=this.sheenNode?te(this.sheenNode):sL,n=this.sheenRoughnessNode?J(this.sheenRoughnessNode):oL;Ci.assign(t),ro.assign(n)}if(this.useIridescence){const t=this.iridescenceNode?J(this.iridescenceNode):lL,n=this.iridescenceIORNode?J(this.iridescenceIORNode):cL,i=this.iridescenceThicknessNode?J(this.iridescenceThicknessNode):uL;Fm.assign(t),_p.assign(n),xp.assign(i)}if(this.useAnisotropy){const t=(this.anisotropyNode?ke(this.anisotropyNode):aL).toVar();to.assign(t.length()),Ft(to.equal(0),()=>{t.assign(ke(1,0))}).Else(()=>{t.divAssign(ke(to)),to.assign(to.saturate())}),yp.assign(to.pow2().mix(Wr.pow2(),1)),ch.assign($l[0].mul(t.x).add($l[1].mul(t.y))),va.assign($l[1].mul(t.x).sub($l[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?J(this.transmissionNode):hL,n=this.thicknessNode?J(this.thicknessNode):dL,i=this.attenuationDistanceNode?J(this.attenuationDistanceNode):pL,s=this.attenuationColorNode?te(this.attenuationColorNode):mL;if(bp.assign(t),nv.assign(n),iv.assign(i),rv.assign(s),this.useDispersion){const o=this.dispersionNode?J(this.dispersionNode):bL;sv.assign(o)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?te(this.clearcoatNormalNode):iL}setup(e){e.context.setupClearcoatNormal=()=>ba(this.setupClearcoatNormal(e),"NORMAL","vec3"),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.iorNode=e.iorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}const xF=re(({normal:r,lightDirection:e,builder:t})=>{const n=r.dot(e),i=ke(n.mul(.5).add(.5),0);if(t.material.gradientMap){const s=ms("gradientMap","texture").context({getUV:()=>i});return te(s.r)}else{const s=i.fwidth().mul(.5);return Dt(te(.7),te(1),Qr(J(.7).sub(s.x),J(.7).add(s.x),i.x))}});class yF extends Yh{direct({lightDirection:e,lightColor:t,reflectedLight:n},i){const s=xF({normal:Uv,lightDirection:e,builder:i}).mul(t);n.directDiffuse.addAssign(s.mul(el({diffuseColor:Pt.rgb})))}indirect(e){const{ambientOcclusion:t,irradiance:n,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(n.mul(el({diffuseColor:Pt}))),i.indirectDiffuse.mulAssign(t)}}const vF=new hM;class bF extends mn{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(vF),this.setValues(e)}setupLightingModel(){return new yF}}const SF=re(()=>{const r=te($t.z,0,$t.x.negate()).normalize(),e=$t.cross(r);return ke(r.dot(vt),e.dot(vt)).mul(.495).add(.5)}).once(["NORMAL","VERTEX"])().toVar("matcapUV"),TF=new mM;class MF extends mn{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(TF),this.setValues(e)}setupVariants(e){const t=SF;let n;e.material.matcap?n=ms("matcap","texture").context({getUV:()=>t}):n=te(Dt(.2,.8,t.y)),Pt.rgb.mulAssign(n.rgb)}}class EF extends xn{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}generateNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:n}=this;if(this.getNodeType(e)==="vec2"){const s=t.cos(),o=t.sin();return Um(s,o,o.negate(),s).mul(n)}else{const s=t,o=uo(et(1,0,0,0),et(0,fr(s.x),bi(s.x).negate(),0),et(0,bi(s.x),fr(s.x),0),et(0,0,0,1)),a=uo(et(fr(s.y),0,bi(s.y),0),et(0,1,0,0),et(bi(s.y).negate(),0,fr(s.y),0),et(0,0,0,1)),l=uo(et(fr(s.z),bi(s.z).negate(),0,0),et(bi(s.z),fr(s.z),0,0),et(0,0,1,0),et(0,0,0,1));return o.mul(a).mul(l).mul(et(n,1)).xyz}}}const mb=It(EF).setParameterLength(2),AF=new mm;class gb extends mn{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.transparent=!0,this.setDefaultValues(AF),this.setValues(e)}setupPositionView(e){const{object:t,camera:n}=e,{positionNode:i,rotationNode:s,scaleNode:o,sizeAttenuation:a}=this,l=Hc.mul(te(i||0));let c=ke(To[0].xyz.length(),To[1].xyz.length());o!==null&&(c=c.mul(ke(o))),n.isPerspectiveCamera&&a===!1&&(c=c.mul(l.z.negate()));let u=jh.xy;if(t.center&&t.center.isVector2===!0){const f=IP("center","vec2",t);u=u.sub(f.sub(.5))}u=u.mul(c);const h=J(s||rL),d=mb(u,h);return et(l.xy.add(d),l.zw)}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}const wF=new VT,RF=new pe;class CF extends gb{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.sizeNode=null,this.isPointsNodeMaterial=!0,this.setDefaultValues(wF),this.setValues(e)}setupPositionView(){const{positionNode:e}=this;return Hc.mul(te(e||Tn)).xyz}setupVertexSprite(e){const{material:t,camera:n}=e,{rotationNode:i,scaleNode:s,sizeNode:o,sizeAttenuation:a}=this;let l=super.setupVertex(e);if(t.isNodeMaterial!==!0)return l;let c=o!==null?ke(o):vL;c=c.mul(hD),n.isPerspectiveCamera&&a===!0&&(c=c.mul(NF.div(dn.z.negate()))),s&&s.isNode&&(c=c.mul(ke(s)));let u=jh.xy;if(i&&i.isNode){const h=J(i);u=mb(u,h)}return u=u.mul(c),u=u.div(dD.div(2)),u=u.mul(l.w),l=l.add(et(u,0,0)),l}setupVertex(e){return e.object.isPoints?super.setupVertex(e):this.setupVertexSprite(e)}get alphaToCoverage(){return this._useAlphaToCoverage}set alphaToCoverage(e){this._useAlphaToCoverage!==e&&(this._useAlphaToCoverage=e,this.needsUpdate=!0)}}const NF=qe(1).onFrameUpdate(function({renderer:r}){const e=r.getSize(RF);this.value=.5*e.y});class PF extends Yh{constructor(){super(),this.shadowNode=J(1).toVar("shadowMask")}direct({lightNode:e}){e.shadowNode!==null&&this.shadowNode.mulAssign(e.shadowNode)}finish({context:e}){Pt.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(Pt.rgb)}}const DF=new rM;class LF extends mn{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.transparent=!0,this.setDefaultValues(DF),this.setValues(e)}setupLightingModel(){return new PF}}Ns("vec3");Ns("vec3");Ns("vec3");class UF{constructor(e,t,n){this.renderer=e,this.nodes=t,this.info=n,this._context=typeof self<"u"?self:null,this._animationLoop=null,this._requestId=null}start(){const e=(t,n)=>{this._requestId=this._context.requestAnimationFrame(e),this.info.autoReset===!0&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,this.renderer._inspector.begin(),this._animationLoop!==null&&this._animationLoop(t,n),this.renderer._inspector.finish()};e()}stop(){this._context!==null&&this._context.cancelAnimationFrame(this._requestId),this._requestId=null}getAnimationLoop(){return this._animationLoop}setAnimationLoop(e){this._animationLoop=e}getContext(){return this._context}setContext(e){this._context=e}dispose(){this.stop()}}class Bs{constructor(){this.weakMaps={}}_getWeakMap(e){const t=e.length;let n=this.weakMaps[t];return n===void 0&&(n=new WeakMap,this.weakMaps[t]=n),n}get(e){let t=this._getWeakMap(e);for(let n=0;n<e.length-1;n++)if(t=t.get(e[n]),t===void 0)return;return t.get(e[e.length-1])}set(e,t){let n=this._getWeakMap(e);for(let i=0;i<e.length-1;i++){const s=e[i];n.has(s)===!1&&n.set(s,new WeakMap),n=n.get(s)}return n.set(e[e.length-1],t),this}delete(e){let t=this._getWeakMap(e);for(let n=0;n<e.length-1;n++)if(t=t.get(e[n]),t===void 0)return!1;return t.delete(e[e.length-1])}}let FF=0;function IF(r){const e=Object.keys(r);let t=Object.getPrototypeOf(r);for(;t;){const n=Object.getOwnPropertyDescriptors(t);for(const i in n)if(n[i]!==void 0){const s=n[i];s&&typeof s.get=="function"&&e.push(i)}t=Object.getPrototypeOf(t)}return e}class BF{constructor(e,t,n,i,s,o,a,l,c,u){this.id=FF++,this._nodes=e,this._geometries=t,this.renderer=n,this.object=i,this.material=s,this.scene=o,this.camera=a,this.lightsNode=l,this.context=c,this.geometry=i.geometry,this.version=s.version,this.drawRange=null,this.attributes=null,this.attributesId=null,this.pipeline=null,this.group=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.clippingContext=u,this.clippingContextCacheKey=u!==null?u.cacheKey:"",this.initialNodesCacheKey=this.getDynamicCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=null,this._monitor=null,this.onDispose=null,this.isRenderObject=!0,this.onMaterialDispose=()=>{this.dispose()},this.onGeometryDispose=()=>{this.attributes=null,this.attributesId=null},this.material.addEventListener("dispose",this.onMaterialDispose),this.geometry.addEventListener("dispose",this.onGeometryDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return this.clippingContext===null||this.clippingContext.cacheKey===this.clippingContextCacheKey?!1:(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return this.material.hardwareClipping===!0?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().observer)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getBindingGroup(e){for(const t of this.getBindings())if(t.name===e)return t}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getIndirectOffset(){return this._geometries.getIndirectOffset(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null,this.attributesId=null}getAttributes(){if(this.attributes!==null)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,n=[],i=new Set,s={};for(const o of e){let a;if(o.node&&o.node.attribute?a=o.node.attribute:(a=t.getAttribute(o.name),s[o.name]=a.id),a===void 0)continue;n.push(a);const l=a.isInterleavedBufferAttribute?a.data:a;i.add(l)}return this.attributes=n,this.attributesId=s,this.vertexBuffers=Array.from(i.values()),n}getVertexBuffers(){return this.vertexBuffers===null&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:n,group:i,drawRange:s}=this,o=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),a=this.getIndex(),l=a!==null;let c=1;if(n.isInstancedBufferGeometry===!0?c=n.instanceCount:e.count!==void 0&&(c=Math.max(0,e.count)),c===0)return null;if(o.instanceCount=c,e.isBatchedMesh===!0)return o;let u=1;t.wireframe===!0&&!e.isPoints&&!e.isLineSegments&&!e.isLine&&!e.isLineLoop&&(u=2);let h=s.start*u,d=(s.start+s.count)*u;i!==null&&(h=Math.max(h,i.start*u),d=Math.min(d,(i.start+i.count)*u));const f=n.attributes.position;let p=1/0;l?p=a.count:f!=null&&(p=f.count),h=Math.max(h,0),d=Math.min(d,p);const g=d-h;return g<0||g===1/0?null:(o.vertexCount=g,o.firstVertex=h,o)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const n of Object.keys(e.attributes).sort()){const i=e.attributes[n];t+=n+",",i.data&&(t+=i.data.stride+","),i.offset&&(t+=i.offset+","),i.itemSize&&(t+=i.itemSize+","),i.normalized&&(t+="n,")}for(const n of Object.keys(e.morphAttributes).sort()){const i=e.morphAttributes[n];t+="morph-"+n+",";for(let s=0,o=i.length;s<o;s++){const a=i[s];t+=a.id+","}}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t,renderer:n}=this;let i=t.customProgramCacheKey();for(const s of IF(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(s))continue;const o=t[s];let a;if(o!==null){const l=typeof o;l==="number"?a=o!==0?"1":"0":l==="object"?(a="{",o.isTexture&&(a+=o.mapping,n.backend.isWebGPUBackend===!0&&(a+=o.magFilter,a+=o.minFilter,a+=o.wrapS,a+=o.wrapT,a+=o.wrapR)),a+="}"):a=String(o)}else a=String(o);i+=a+","}return i+=this.clippingContextCacheKey+",",e.geometry&&(i+=this.getGeometryCacheKey()),e.skeleton&&(i+=e.skeleton.bones.length+","),e.isBatchedMesh&&(i+=e._matricesTexture.uuid+",",e._colorsTexture!==null&&(i+=e._colorsTexture.uuid+",")),(e.isInstancedMesh||e.count>1||Array.isArray(e.morphTargetInfluences))&&(i+=e.uuid+","),i+=this.context.id+",",i+=e.receiveShadow+",",cl(i)}get needsGeometryUpdate(){if(this.geometry.id!==this.object.geometry.id)return!0;if(this.attributes!==null){const e=this.attributesId;for(const t in e){const n=this.geometry.getAttribute(t);if(n===void 0||e[t]!==n.id)return!0}}return!1}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=0;return this.material.isShadowPassMaterial!==!0&&(e=this._nodes.getCacheKey(this.scene,this.lightsNode)),this.camera.isArrayCamera&&(e=Ql(e,this.camera.cameras.length)),this.object.receiveShadow&&(e=Ql(e,1)),e=Ql(e,this.renderer.contextNode.id,this.renderer.contextNode.version),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.geometry.removeEventListener("dispose",this.onGeometryDispose),this.onDispose()}}const ar=[];class OF{constructor(e,t,n,i,s,o){this.renderer=e,this.nodes=t,this.geometries=n,this.pipelines=i,this.bindings=s,this.info=o,this.chainMaps={}}get(e,t,n,i,s,o,a,l){const c=this.getChainMap(l);ar[0]=e,ar[1]=t,ar[2]=o,ar[3]=s;let u=c.get(ar);return u===void 0?(u=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,n,i,s,o,a,l),c.set(ar,u)):(u.camera=i,u.updateClipping(a),u.needsGeometryUpdate&&u.setGeometry(e.geometry),(u.version!==t.version||u.needsUpdate)&&(u.initialCacheKey!==u.getCacheKey()?(u.dispose(),u=this.get(e,t,n,i,s,o,a,l)):u.version=t.version)),ar[0]=null,ar[1]=null,ar[2]=null,ar[3]=null,u}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Bs)}dispose(){this.chainMaps={}}createRenderObject(e,t,n,i,s,o,a,l,c,u,h){const d=this.getChainMap(h),f=new BF(e,t,n,i,s,o,a,l,c,u);return f.onDispose=()=>{this.pipelines.delete(f),this.bindings.deleteForRender(f),this.nodes.delete(f),d.delete(f.getChainArray())},f}}class Gs{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}delete(e){let t=null;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Ii={VERTEX:1,INDEX:2,STORAGE:3,INDIRECT:4},gs=16,kF=211,GF=212;class VF extends Gs{constructor(e,t){super(),this.backend=e,this.info=t}delete(e){const t=super.delete(e);return t!==null&&(this.backend.destroyAttribute(e),this.info.destroyAttribute(e)),t}update(e,t){const n=this.get(e);if(n.version===void 0)t===Ii.VERTEX?(this.backend.createAttribute(e),this.info.createAttribute(e)):t===Ii.INDEX?(this.backend.createIndexAttribute(e),this.info.createIndexAttribute(e)):t===Ii.STORAGE?(this.backend.createStorageAttribute(e),this.info.createStorageAttribute(e)):t===Ii.INDIRECT&&(this.backend.createIndirectStorageAttribute(e),this.info.createIndirectStorageAttribute(e)),n.version=this._getBufferAttribute(e).version;else{const i=this._getBufferAttribute(e);(n.version<i.version||i.usage===mh)&&(this.backend.updateAttribute(e),n.version=i.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}function _b(r){return r.index!==null?r.index.version:r.attributes.position.version}function xb(r){return r.index!==null?r.index.id:r.attributes.position.id}function zx(r){const e=[],t=r.index,n=r.attributes.position;if(t!==null){const s=t.array;for(let o=0,a=s.length;o<a;o+=3){const l=s[o+0],c=s[o+1],u=s[o+2];e.push(l,c,c,u,u,l)}}else{const s=n.array;for(let o=0,a=s.length/3-1;o<a;o+=3){const l=o+0,c=o+1,u=o+2;e.push(l,c,c,u,u,l)}}const i=new(n.count>=65535?fm:dm)(e,1);return i.version=_b(r),i.__id=xb(r),i}class zF extends Gs{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap,this._geometryDisposeListeners=new Map}has(e){const t=e.geometry;return super.has(t)&&this.get(t).initialized===!0}updateForRender(e){this.has(e)===!1&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry,n=this.get(t);n.initialized=!0,this.info.memory.geometries++;const i=()=>{this.info.memory.geometries--;const s=t.index,o=e.getAttributes();s!==null&&this.attributes.delete(s);for(const l of o)this.attributes.delete(l);const a=this.wireframes.get(t);a!==void 0&&this.attributes.delete(a),t.removeEventListener("dispose",i),this._geometryDisposeListeners.delete(t)};t.addEventListener("dispose",i),this._geometryDisposeListeners.set(t,i)}updateAttributes(e){const t=e.getAttributes();for(const s of t)s.isStorageBufferAttribute||s.isStorageInstancedBufferAttribute?this.updateAttribute(s,Ii.STORAGE):this.updateAttribute(s,Ii.VERTEX);const n=this.getIndex(e);n!==null&&this.updateAttribute(n,Ii.INDEX);const i=e.geometry.indirect;i!==null&&this.updateAttribute(i,Ii.INDIRECT)}updateAttribute(e,t){const n=this.info.render.calls;e.isInterleavedBufferAttribute?this.attributeCall.get(e)===void 0?(this.attributes.update(e,t),this.attributeCall.set(e,n)):this.attributeCall.get(e.data)!==n&&(this.attributes.update(e,t),this.attributeCall.set(e.data,n),this.attributeCall.set(e,n)):this.attributeCall.get(e)!==n&&(this.attributes.update(e,t),this.attributeCall.set(e,n))}getIndirect(e){return e.geometry.indirect}getIndirectOffset(e){return e.geometry.indirectOffset}getIndex(e){const{geometry:t,material:n}=e;let i=t.index;if(n.wireframe===!0){const s=this.wireframes;let o=s.get(t);o===void 0?(o=zx(t),s.set(t,o)):(o.version!==_b(t)||o.__id!==xb(t))&&(this.attributes.delete(o),o=zx(t),s.set(t,o)),i=o}return i}dispose(){for(const[e,t]of this._geometryDisposeListeners.entries())e.removeEventListener("dispose",t);this._geometryDisposeListeners.clear()}}class HF{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0},this.compute={calls:0,frameCalls:0,timestamp:0},this.memory={geometries:0,textures:0,attributes:0,indexAttributes:0,storageAttributes:0,indirectStorageAttributes:0,readbackBuffers:0,programs:0,renderTargets:0,total:0,texturesSize:0,attributesSize:0,indexAttributesSize:0,storageAttributesSize:0,indirectStorageAttributesSize:0,readbackBuffersSize:0,programsSize:0},this.memoryMap=new Map}update(e,t,n){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=n*(t/3):e.isPoints?this.render.points+=n*t:e.isLineSegments?this.render.lines+=n*(t/2):e.isLine?this.render.lines+=n*(t-1):ce("WebGPUInfo: Unknown object type.")}reset(){this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0;for(const e in this.memory)this.memory[e]=0;this.memoryMap.clear()}createTexture(e){const t=this._getTextureMemorySize(e);this.memoryMap.set(e,t),this.memory.textures++,this.memory.total+=t,this.memory.texturesSize+=t}destroyTexture(e){const t=this.memoryMap.get(e)||0;this.memoryMap.delete(e),this.memory.textures--,this.memory.total-=t,this.memory.texturesSize-=t}_createAttribute(e,t){const n=this._getAttributeMemorySize(e);this.memoryMap.set(e,{size:n,type:t}),this.memory[t]++,this.memory.total+=n,this.memory[t+"Size"]+=n}createAttribute(e){this._createAttribute(e,"attributes")}createIndexAttribute(e){this._createAttribute(e,"indexAttributes")}createStorageAttribute(e){this._createAttribute(e,"storageAttributes")}createIndirectStorageAttribute(e){this._createAttribute(e,"indirectStorageAttributes")}destroyAttribute(e){const t=this.memoryMap.get(e);t&&(this.memoryMap.delete(e),this.memory[t.type]--,this.memory.total-=t.size,this.memory[t.type+"Size"]-=t.size)}createReadbackBuffer(e){const t=e.maxByteLength;this.memoryMap.set(e,{size:t,type:"readbackBuffers"}),this.memory.readbackBuffers++,this.memory.total+=t,this.memory.readbackBuffersSize+=t}destroyReadbackBuffer(e){const{size:t}=this.memoryMap.get(e);this.memoryMap.delete(e),this.memory.readbackBuffers--,this.memory.total-=t,this.memory.readbackBuffersSize-=t}createProgram(e){const t=e.code.length;this.memoryMap.set(e,t),this.memory.programs++,this.memory.total+=t,this.memory.programsSize+=t}destroyProgram(e){const t=this.memoryMap.get(e)||0;this.memoryMap.delete(e),this.memory.programs--,this.memory.total-=t,this.memory.programsSize-=t}_getTextureMemorySize(e){if(e.isCompressedTexture)return 1;let t=1;e.type===Ts||e.type===Xt?t=1:e.type===Ms||e.type===Ui||e.type===tn?t=2:(e.type===Sn||e.type===Ct||e.type===Qt)&&(t=4);let n=4;e.format===Fh||e.format===il||e.format===Eo||e.format===Dn||e.format===qn?n=1:e.format===In||e.format===Ao?n=2:(e.format===nl||e.format===q0)&&(n=3);let i=t*n;e.type===Pc||e.type===Dc?i=2:(e.type===di||e.type===Lc||e.type===Uc)&&(i=4);const s=e.width||1,o=e.height||1,a=e.isCubeTexture?6:e.depth||1;let l=s*o*a*i;const c=e.mipmaps;if(c&&c.length>0){let u=0;for(let h=0;h<c.length;h++){const d=c[h];if(d.data)u+=d.data.byteLength;else{const f=d.width||Math.max(1,s>>h),p=d.height||Math.max(1,o>>h);u+=f*p*a*i}}l+=u}else e.generateMipmaps&&(l=l*1.333);return Math.round(l)}_getAttributeMemorySize(e){return e.isInterleavedBufferAttribute&&(e=e.data),e.array?e.array.byteLength:e.count&&e.itemSize?e.count*e.itemSize*4:0}}class yb{constructor(e){this.cacheKey=e,this.usedTimes=0}}class WF extends yb{constructor(e,t,n){super(e),this.vertexProgram=t,this.fragmentProgram=n}}class $F extends yb{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let XF=0;class Af{constructor(e,t,n,i=null,s=null){this.id=XF++,this.code=e,this.stage=t,this.name=n,this.transforms=i,this.attributes=s,this.usedTimes=0}}class qF extends Gs{constructor(e,t,n){super(),this.backend=e,this.nodes=t,this.info=n,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:n}=this,i=this.get(e);if(this._needsComputeUpdate(e)){const s=i.pipeline;s&&(s.usedTimes--,s.computeProgram.usedTimes--);const o=this.nodes.getForCompute(e);let a=this.programs.compute.get(o.computeShader);a===void 0&&(s&&s.computeProgram.usedTimes===0&&this._releaseProgram(s.computeProgram),a=new Af(o.computeShader,"compute",e.name,o.transforms,o.nodeAttributes),this.programs.compute.set(o.computeShader,a),n.createProgram(a),this.info.createProgram(a));const l=this._getComputeCacheKey(e,a);let c=this.caches.get(l);c===void 0&&(s&&s.usedTimes===0&&this._releasePipeline(s),c=this._getComputePipeline(e,a,l,t)),c.usedTimes++,a.usedTimes++,i.version=e.version,i.pipeline=c}return i.pipeline}getForRender(e,t=null){const{backend:n}=this,i=this.get(e);if(this._needsRenderUpdate(e)){const s=i.pipeline;s&&(s.usedTimes--,s.vertexProgram.usedTimes--,s.fragmentProgram.usedTimes--);const o=e.getNodeBuilderState(),a=e.material?e.material.name:"";let l=this.programs.vertex.get(o.vertexShader);l===void 0&&(s&&s.vertexProgram.usedTimes===0&&this._releaseProgram(s.vertexProgram),l=new Af(o.vertexShader,"vertex",a),this.programs.vertex.set(o.vertexShader,l),n.createProgram(l),this.info.createProgram(l));let c=this.programs.fragment.get(o.fragmentShader);c===void 0&&(s&&s.fragmentProgram.usedTimes===0&&this._releaseProgram(s.fragmentProgram),c=new Af(o.fragmentShader,"fragment",a),this.programs.fragment.set(o.fragmentShader,c),n.createProgram(c),this.info.createProgram(c));const u=this._getRenderCacheKey(e,l,c);let h=this.caches.get(u);h===void 0?(s&&s.usedTimes===0&&this._releasePipeline(s),h=this._getRenderPipeline(e,l,c,u,t)):e.pipeline=h,h.usedTimes++,l.usedTimes++,c.usedTimes++,i.pipeline=h}return i.pipeline}isReady(e){const n=this.get(e).pipeline;if(n===void 0)return!1;const i=this.backend.get(n);return i.pipeline!==void 0&&i.pipeline!==null}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,t.usedTimes===0&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,t.computeProgram.usedTimes===0&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,t.vertexProgram.usedTimes===0&&this._releaseProgram(t.vertexProgram),t.fragmentProgram.usedTimes===0&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,n,i){n=n||this._getComputeCacheKey(e,t);let s=this.caches.get(n);return s===void 0&&(s=new $F(n,t),this.caches.set(n,s),this.backend.createComputePipeline(s,i)),s}_getRenderPipeline(e,t,n,i,s){i=i||this._getRenderCacheKey(e,t,n);let o=this.caches.get(i);return o===void 0&&(o=new WF(i,t,n),this.caches.set(i,o),e.pipeline=o,this.backend.createRenderPipeline(e,s)),o}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,n){return t.id+","+n.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,n=e.stage;this.programs[n].delete(t),this.info.destroyProgram(e)}_needsComputeUpdate(e){const t=this.get(e);return t.pipeline===void 0||t.version!==e.version}_needsRenderUpdate(e){return this.get(e).pipeline===void 0||this.backend.needsRenderUpdate(e)}}class jF extends Gs{constructor(e,t,n,i,s,o){super(),this.backend=e,this.textures=n,this.pipelines=s,this.attributes=i,this.nodes=t,this.info=o,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const n of t){const i=this.get(n);i.bindGroup===void 0&&(this._init(n),this.backend.createBindings(n,t,0),i.bindGroup=n)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const n of t){const i=this.get(n);i.bindGroup===void 0&&(this._init(n),this.backend.createBindings(n,t,0),i.bindGroup=n)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}deleteForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const n of t)this.backend.deleteBindGroupData(n),this.delete(n)}deleteForRender(e){const t=e.getBindings();for(const n of t)this.backend.deleteBindGroupData(n),this.delete(n)}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isSampler)this.textures.updateSampler(t.texture);else if(t.isStorageBuffer){const n=t.attribute,i=n.isIndirectStorageBufferAttribute?Ii.INDIRECT:Ii.STORAGE;this.attributes.update(n,i)}}_update(e,t){const{backend:n}=this;let i=!1,s=!0,o=0,a=0;for(const l of e.bindings)if(this.nodes.updateGroup(l)!==!1){if(l.isStorageBuffer){const u=l.attribute,h=u.isIndirectStorageBufferAttribute?Ii.INDIRECT:Ii.STORAGE,d=n.get(l);this.attributes.update(u,h),d.attribute!==u&&(d.attribute=u,i=!0)}if(l.isUniformBuffer)l.update()&&n.updateBinding(l);else if(l.isSampledTexture){const u=l.update(),h=l.texture,d=this.textures.get(h);if(u&&(this.textures.updateTexture(h),l.generation!==d.generation&&(l.generation=d.generation,i=!0),d.bindGroups.add(e)),n.get(h).externalTexture!==void 0||d.isDefaultTexture?s=!1:(o=o*10+h.id,a+=h.version),h.isStorageTexture===!0&&h.mipmapsAutoUpdate===!0){const p=this.get(h);l.store===!0?p.needsMipmap=!0:this.textures.needsMipmaps(h)&&p.needsMipmap===!0&&(this.backend.generateMipmaps(h),p.needsMipmap=!1)}}else if(l.isSampler&&l.update()){const h=this.textures.updateSampler(l.texture);l.samplerKey!==h&&(l.samplerKey=h,i=!0)}l.isBuffer&&l.updateRanges.length>0&&l.clearUpdateRanges()}i===!0&&this.backend.updateBindings(e,t,s?o:0,a)}}function YF(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.z!==e.z?r.z-e.z:r.id-e.id}function Hx(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.z!==e.z?e.z-r.z:r.id-e.id}function Wx(r){return(r.transmission>0||r.transmissionNode&&r.transmissionNode.isNode)&&r.side===Nn&&r.forceSinglePass===!1}class KF{constructor(e,t,n){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,n),this.lightsArray=[],this.scene=t,this.camera=n,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,n,i,s,o,a){let l=this.renderItems[this.renderItemsIndex];return l===void 0?(l={id:e.id,object:e,geometry:t,material:n,groupOrder:i,renderOrder:e.renderOrder,z:s,group:o,clippingContext:a},this.renderItems[this.renderItemsIndex]=l):(l.id=e.id,l.object=e,l.geometry=t,l.material=n,l.groupOrder=i,l.renderOrder=e.renderOrder,l.z=s,l.group=o,l.clippingContext=a),this.renderItemsIndex++,l}push(e,t,n,i,s,o,a){const l=this.getNextRenderItem(e,t,n,i,s,o,a);e.occlusionTest===!0&&this.occlusionQueryCount++,n.transparent===!0||n.transmission>0||n.transmissionNode&&n.transmissionNode.isNode||n.backdropNode&&n.backdropNode.isNode?(Wx(n)&&this.transparentDoublePass.push(l),this.transparent.push(l)):this.opaque.push(l)}unshift(e,t,n,i,s,o,a){const l=this.getNextRenderItem(e,t,n,i,s,o,a);n.transparent===!0||n.transmission>0||n.transmissionNode&&n.transmissionNode.isNode||n.backdropNode&&n.backdropNode.isNode?(Wx(n)&&this.transparentDoublePass.unshift(l),this.transparent.unshift(l)):this.opaque.unshift(l)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||YF),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||Hx),this.transparent.length>1&&this.transparent.sort(t||Hx)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){const n=this.renderItems[e];if(n.id===null)break;n.id=null,n.object=null,n.geometry=null,n.material=null,n.groupOrder=null,n.renderOrder=null,n.z=null,n.group=null,n.clippingContext=null}}}const ra=[];class ZF{constructor(e){this.lighting=e,this.lists=new Bs}get(e,t){const n=this.lists;ra[0]=e,ra[1]=t;let i=n.get(ra);return i===void 0&&(i=new KF(this.lighting,e,t),n.set(ra,i)),ra[0]=null,ra[1]=null,i}dispose(){this.lists=new Bs}}let QF=0;class JF{constructor(){this.id=QF++,this.mrt=null,this.color=!0,this.clearColor=!0,this.clearColorValue={r:0,g:0,b:0,a:1},this.depth=!0,this.clearDepth=!0,this.clearDepthValue=1,this.stencil=!1,this.clearStencil=!0,this.clearStencilValue=1,this.viewport=!1,this.viewportValue=new rt,this.scissor=!1,this.scissorValue=new rt,this.renderTarget=null,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.activeMipmapLevel=0,this.sampleCount=1,this.width=0,this.height=0,this.occlusionQueryCount=0,this.clippingContext=null,this.camera=null,this.isRenderContext=!0}getCacheKey(){return vb(this)}}function vb(r){const{textures:e,activeCubeFace:t,activeMipmapLevel:n}=r,i=[t,n];for(const s of e)i.push(s.id);return Gc(i)}class eI{constructor(e){this.renderer=e,this._renderContexts={}}get(e=null,t=null,n=0){let i;if(e===null)i="default";else{const l=e.texture.format,c=e.texture.type;i=`${e.textures.length}:${l}:${c}:${e.samples}:${e.depthBuffer}:${e.stencilBuffer}`}const s=t!==null?t.id:"default",o=i+"-"+s+"-"+n;let a=this._renderContexts[o];return a===void 0&&(a=new JF,a.mrt=t,this._renderContexts[o]=a),e!==null&&(a.sampleCount=e.samples===0?1:e.samples),a.clearDepthValue=this.renderer.getClearDepth(),a.clearStencilValue=this.renderer.getClearStencil(),a}dispose(){this._renderContexts={}}}const tI=new P;class nI extends Gs{constructor(e,t,n){super(),this.renderer=e,this.backend=t,this.info=n,this._htmlTextures=new Set}updateRenderTarget(e,t=0){const n=this.get(e),i=e.samples===0?1:e.samples,s=n.depthTextureMips||(n.depthTextureMips={}),o=e.textures,a=this.getSize(o[0]),l=a.width>>t,c=a.height>>t;let u=e.depthTexture||s[t];const h=e.depthBuffer===!0||e.stencilBuffer===!0;let d=!1;u===void 0&&h&&(u=new jn,u.format=e.stencilBuffer?qn:Dn,u.type=e.stencilBuffer?di:Ct,u.image.width=l,u.image.height=c,u.image.depth=a.depth,u.renderTarget=e,u.isArrayTexture=e.multiview===!0&&a.depth>1,s[t]=u),(n.width!==a.width||a.height!==n.height)&&(d=!0,u&&(u.needsUpdate=!0,u.image.width=l,u.image.height=c,u.image.depth=u.isArrayTexture?u.image.depth:1)),n.width=a.width,n.height=a.height,n.textures=o,n.depthTexture=u||null,n.depth=e.depthBuffer,n.stencil=e.stencilBuffer,n.renderTarget=e,n.sampleCount!==i&&(d=!0,u&&(u.needsUpdate=!0),n.sampleCount=i);const f={sampleCount:i};if(e.isXRRenderTarget!==!0){for(let p=0;p<o.length;p++){const g=o[p];d&&(g.needsUpdate=!0),this.updateTexture(g,f)}u&&this.updateTexture(u,f)}n.initialized!==!0&&(n.initialized=!0,this.info.memory.renderTargets++,n.onDispose=()=>{this._destroyRenderTarget(e)},e.addEventListener("dispose",n.onDispose))}updateTexture(e,t={}){const n=this.get(e);if(n.initialized===!0&&n.version===e.version)return;const i=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,s=this.backend;if(i&&n.initialized===!0&&s.destroyTexture(e),e.isFramebufferTexture){const c=this.renderer.getRenderTarget();c?e.type=c.texture.type:e.type=Xt}if(e.isHTMLTexture&&e.image){const c=this.renderer.domElement;if("requestPaint"in c){if(c.hasAttribute("layoutsubtree")||c.setAttribute("layoutsubtree","true"),e.image.parentNode!==c&&c.appendChild(e.image),this._htmlTextures.size===0){const u=this._htmlTextures;c.onpaint=h=>{const d=h&&h.changedElements;for(const f of u)(!d||d.includes(f.image))&&(f.needsUpdate=!0)}}this._htmlTextures.add(e)}}const{width:o,height:a,depth:l}=this.getSize(e);if(t.width=o,t.height=a,t.depth=l,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,o,a):1,e.isCubeTexture&&e.mipmaps.length>0&&t.levels++,i||e.isStorageTexture===!0||e.isExternalTexture===!0)s.createTexture(e,t),n.generation=e.version;else if(e.version>0){const c=e.image;if(c===void 0)ae("Renderer: Texture marked for update but image is undefined.");else if(c.complete===!1)ae("Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const h=[];for(const d of e.images)h.push(d);t.images=h}else t.image=c;(n.isDefaultTexture===void 0||n.isDefaultTexture===!0)&&(s.createTexture(e,t),n.isDefaultTexture=!1,n.generation=e.version),e.source.dataReady===!0&&s.updateTexture(e,t);const u=e.isStorageTexture===!0&&e.mipmapsAutoUpdate===!1;t.needsMipmaps&&e.mipmaps.length===0&&!u&&s.generateMipmaps(e),e.onUpdate&&e.onUpdate(e)}}else s.createDefaultTexture(e),n.isDefaultTexture=!0,n.generation=e.version;n.initialized!==!0&&(n.initialized=!0,n.generation=e.version,n.bindGroups=new Set,this.info.createTexture(e),e.isVideoTexture&&Ye.enabled===!0&&Ye.getTransfer(e.colorSpace)!==Pe&&ae("WebGPURenderer: Video textures must use a color space with a sRGB transfer function, e.g. SRGBColorSpace."),n.onDispose=()=>{this._destroyTexture(e)},e.addEventListener("dispose",n.onDispose)),n.version=e.version}updateSampler(e){return this.backend.updateSampler(e)}getSize(e,t=tI){let n=e.images?e.images[0]:e.image;return n?(n.image!==void 0&&(n=n.image),e.isHTMLTexture?(t.width=n.offsetWidth||1,t.height=n.offsetHeight||1,t.depth=1):typeof HTMLVideoElement<"u"&&n instanceof HTMLVideoElement?(t.width=n.videoWidth||1,t.height=n.videoHeight||1,t.depth=1):typeof VideoFrame<"u"&&n instanceof VideoFrame?(t.width=n.displayWidth||1,t.height=n.displayHeight||1,t.depth=1):(t.width=n.width||1,t.height=n.height||1,t.depth=e.isCubeTexture?6:n.depth||1)):t.width=t.height=t.depth=1,t}getMipLevels(e,t,n){let i;return e.mipmaps.length>0?i=e.mipmaps.length:e.isCompressedTexture===!0?i=1:i=Math.floor(Math.log2(Math.max(t,n)))+1,i}needsMipmaps(e){return e.generateMipmaps===!0||e.mipmaps.length>0}_destroyRenderTarget(e){if(this.has(e)===!0){const t=this.get(e),n=t.textures,i=t.depthTexture;e.removeEventListener("dispose",t.onDispose);for(let s=0;s<n.length;s++)this._destroyTexture(n[s]);i&&this._destroyTexture(i),this.delete(e),this.backend.delete(e),this.info.memory.renderTargets--}}_destroyTexture(e){if(this.has(e)===!0){const t=this.get(e);e.removeEventListener("dispose",t.onDispose);const n=t.isDefaultTexture;if(this.backend.destroyTexture(e,n),t.bindGroups)for(const i of t.bindGroups){const s=this.backend.get(i);s.groups=void 0,s.versions=void 0}this._htmlTextures.delete(e),this.delete(e),this.info.destroyTexture(e)}}}class jm extends We{constructor(e,t,n,i=1){super(e,t,n),this.a=i}set(e,t,n,i=1){return this.a=i,super.set(e,t,n)}copy(e){return e.a!==void 0&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class iI extends Et{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getMemberType(e,t){const n=this.getNodeType(e),i=e.getStructTypeNode(n);let s;return i!==null?s=i.getMemberType(e,t):(ce(`TSL: Member "${t}" not found in struct "${n}".`,new Kn),s="float"),s}getHash(){return String(this.id)}generate(){return this.name}}class rI extends Ve{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this._expressionNode=null,this._currentNode=null,this.isStackNode=!0}getElementType(e){return this.hasOutput(e)?this.outputNode.getElementType(e):"void"}generateNodeType(e){return this.hasOutput(e)?this.outputNode.getNodeType(e):"void"}getMemberType(e,t){return this.hasOutput(e)?this.outputNode.getMemberType(e,t):"void"}addToStack(e,t=this.nodes.length){return e.isNode!==!0?(ce("TSL: Invalid node added to stack.",new Kn),this):(this.nodes.splice(t,0,e),this)}addToStackBefore(e){const t=this._currentNode?this.nodes.indexOf(this._currentNode):0;return this.addToStack(e,t)}If(e,t){const n=new Wl(t);return this._currentCond=Mi(e,n),this.addToStack(this._currentCond)}ElseIf(e,t){const n=new Wl(t),i=Mi(e,n);return this._currentCond.elseNode=i,this._currentCond=i,this}Else(e){return this._currentCond.elseNode=new Wl(e),this}Switch(e){return this._expressionNode=Ge(e),this}Case(...e){const t=[];if(e.length>=2)for(let a=0;a<e.length-1;a++)t.push(this._expressionNode.equal(Ge(e[a])));else ce("TSL: Invalid parameter length. Case() requires at least two parameters.",new Kn);const n=e[e.length-1],i=new Wl(n);let s=t[0];for(let a=1;a<t.length;a++)s=s.or(t[a]);const o=Mi(s,i);return this._currentCond===null?(this._currentCond=o,this.addToStack(this._currentCond)):(this._currentCond.elseNode=o,this._currentCond=o,this)}Default(e){return this.Else(e),this}setup(e){const t=e.getNodeProperties(this);let n=0;for(const i of this.getChildren())i.isVarNode&&i.isIntent(e)&&i.isAssign(e)!==!0||(t["node"+n++]=i);return t.outputNode||null}hasOutput(e){return this.outputNode&&this.outputNode.isNode&&this.outputNode.getNodeType(e)!=="void"}build(e,...t){const n=Yy(),i=e.buildStage;Th(this),e.setActiveStack(this);const s=c=>{if(this._currentNode=c,!(c.isVarNode&&c.isIntent(e)&&c.isAssign(e)!==!0)){if(i==="setup")c.build(e);else if(i==="analyze")c.build(e,this);else if(i==="generate"){const u=e.getDataFromNode(c,"any").stages,h=u&&u[e.shaderStage];if(c.isVarNode&&h&&h.length===1&&h[0]&&h[0].isStackNode)return;c.build(e,"void")}}},o=[...this.nodes];for(const c of o)s(c);this._currentNode=null;const a=this.nodes.filter(c=>o.indexOf(c)===-1);for(const c of a)s(c);let l;return this.hasOutput(e)?l=this.outputNode.build(e,...t):l=super.build(e,...t),Th(n),e.removeActiveStack(this),l}}const wf=It(rI).setParameterLength(0,1);class bb extends xn{static get type(){return"BitcastNode"}constructor(e,t,n=null){super(),this.valueNode=e,this.conversionType=t,this.inputType=n,this.isBitcastNode=!0}generateNodeType(e){if(this.inputType!==null){const t=this.valueNode.getNodeType(e),n=e.getTypeLength(t);return e.getTypeFromLength(n,this.conversionType)}return this.conversionType}generate(e){const t=this.getNodeType(e);let n="";if(this.inputType!==null){const i=this.valueNode.getNodeType(e);n=e.getTypeLength(i)===1?this.inputType:e.changeComponentType(i,this.inputType)}else n=this.valueNode.getNodeType(e);return`${e.getBitcastMethod(t,n)}( ${this.valueNode.build(e,n)} )`}}const sI=we(bb).setParameterLength(2),oI=r=>new bb(r,"uint","float"),Hu={};class po extends G{static get type(){return"BitcountNode"}constructor(e,t){super(e,t),this.isBitcountNode=!0}_resolveElementType(e,t,n){n==="int"?t.assign(sI(e,"uint")):t.assign(e)}_returnDataNode(e){switch(e){case"uint":return mt;case"int":return Zt;case"uvec2":return Zy;case"uvec3":return Jy;case"uvec4":return tv;case"ivec2":return dr;case"ivec3":return Qy;case"ivec4":return ev}}_createTrailingZerosBaseLayout(e,t){const n=this._returnDataNode(t);return re(([s])=>{const o=mt(0);this._resolveElementType(s,o,t);const a=J(o.bitAnd(hv(o))),c=oI(a).shiftRight(23).sub(127);return n(c)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createLeadingZerosBaseLayout(e,t){const n=this._returnDataNode(t);return re(([s])=>{Ft(s.equal(mt(0)),()=>mt(32));const o=mt(0),a=mt(0);return this._resolveElementType(s,o,t),Ft(o.shiftRight(16).equal(0),()=>{a.addAssign(16),o.shiftLeftAssign(16)}),Ft(o.shiftRight(24).equal(0),()=>{a.addAssign(8),o.shiftLeftAssign(8)}),Ft(o.shiftRight(28).equal(0),()=>{a.addAssign(4),o.shiftLeftAssign(4)}),Ft(o.shiftRight(30).equal(0),()=>{a.addAssign(2),o.shiftLeftAssign(2)}),Ft(o.shiftRight(31).equal(0),()=>{a.addAssign(1)}),n(a)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createOneBitsBaseLayout(e,t){const n=this._returnDataNode(t);return re(([s])=>{const o=mt(0);this._resolveElementType(s,o,t),o.assign(o.sub(o.shiftRight(mt(1)).bitAnd(mt(1431655765)))),o.assign(o.bitAnd(mt(858993459)).add(o.shiftRight(mt(2)).bitAnd(mt(858993459))));const a=o.add(o.shiftRight(mt(4))).bitAnd(mt(252645135)).mul(mt(16843009)).shiftRight(mt(24));return n(a)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createMainLayout(e,t,n,i){const s=this._returnDataNode(t);return re(([a])=>{if(n===1)return s(i(a));{const l=s(0),c=["x","y","z","w"];for(let u=0;u<n;u++){const h=c[u];l[h].assign(i(a[h]))}return l}}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}setup(e){const{method:t,aNode:n}=this,{renderer:i}=e;if(i.backend.isWebGPUBackend)return super.setup(e);const s=this.getInputType(e),o=e.getElementType(s),a=e.getTypeLength(s),l=`${t}_base_${o}`,c=`${t}_${s}`;let u=Hu[l];if(u===void 0){switch(t){case po.COUNT_LEADING_ZEROS:{u=this._createLeadingZerosBaseLayout(l,o);break}case po.COUNT_TRAILING_ZEROS:{u=this._createTrailingZerosBaseLayout(l,o);break}case po.COUNT_ONE_BITS:{u=this._createOneBitsBaseLayout(l,o);break}}Hu[l]=u}let h=Hu[c];return h===void 0&&(h=this._createMainLayout(c,s,a,u),Hu[c]=h),re(()=>h(n))()}}po.COUNT_TRAILING_ZEROS="countTrailingZeros";po.COUNT_LEADING_ZEROS="countLeadingZeros";po.COUNT_ONE_BITS="countOneBits";new pt;const aI=new ks;fo.flipX();aI.depthTexture=new jn(1,1);const Rf=new ol(-1,1,1,-1,0,1);class lI extends An{constructor(e=!1){super();const t=e===!1?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new sn([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new sn(t,2))}}const cI=new lI;class Sb extends _n{constructor(e=null){super(cI,e),this.camera=Rf,this.isQuadMesh=!0}async renderAsync(e){Kt('QuadMesh: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await e.init(),e.render(this,Rf)}render(e){e.render(this,Rf)}}const Tb=re(([r])=>Ar(J(52.9829189).mul(Ar(bo(r,ke(.06711056,.00583715)))))).setLayout({name:"interleavedGradientNoise",type:"float",inputs:[{name:"position",type:"vec2"}]}),gr=re(([r,e,t])=>{const n=J(2.399963229728653),i=Ps(J(r).add(.5).div(J(e))),s=J(r).mul(n).add(t);return ke(fr(s),bi(s)).mul(i)}).setLayout({name:"vogelDiskSample",type:"vec2",inputs:[{name:"sampleIndex",type:"int"},{name:"samplesCount",type:"int"},{name:"phi",type:"float"}]});class Ti extends Ve{static get type(){return"EventNode"}constructor(e,t){super("void"),this.eventType=e,this.callback=t,e===Ti.OBJECT?this.updateType=Ze.OBJECT:e===Ti.MATERIAL?this.updateType=Ze.RENDER:e===Ti.FRAME?this.updateType=Ze.FRAME:e===Ti.BEFORE_OBJECT?this.updateBeforeType=Ze.OBJECT:e===Ti.BEFORE_MATERIAL?this.updateBeforeType=Ze.RENDER:e===Ti.BEFORE_FRAME&&(this.updateBeforeType=Ze.FRAME)}update(e){this.callback(e)}updateBefore(e){this.callback(e)}}Ti.OBJECT="object";Ti.MATERIAL="material";Ti.FRAME="frame";Ti.BEFORE_OBJECT="beforeObject";Ti.BEFORE_MATERIAL="beforeMaterial";Ti.BEFORE_FRAME="beforeFrame";const Cf=new pt,uI=qe(0).setGroup(Ke).onRenderUpdate(({scene:r})=>r.backgroundBlurriness),$x=qe(1).setGroup(Ke).onRenderUpdate(({scene:r})=>r.backgroundIntensity),hI=qe(new pt).setGroup(Ke).onRenderUpdate(({scene:r})=>{const e=r.background;return e!==null&&e.isTexture&&e.mapping!==Jp?Cf.makeRotationFromEuler(r.backgroundRotation).transpose():Cf.identity(),Cf});re(({texture:r,uv:e})=>{const n=te().toVar();return Ft(e.x.lessThan(1e-4),()=>{n.assign(te(1,0,0))}).ElseIf(e.y.lessThan(1e-4),()=>{n.assign(te(0,1,0))}).ElseIf(e.z.lessThan(1e-4),()=>{n.assign(te(0,0,1))}).ElseIf(e.x.greaterThan(1-1e-4),()=>{n.assign(te(-1,0,0))}).ElseIf(e.y.greaterThan(1-1e-4),()=>{n.assign(te(0,-1,0))}).ElseIf(e.z.greaterThan(1-1e-4),()=>{n.assign(te(0,0,-1))}).Else(()=>{const s=r.sample(e.add(te(-.01,0,0))).r.sub(r.sample(e.add(te(.01,0,0))).r),o=r.sample(e.add(te(0,-.01,0))).r.sub(r.sample(e.add(te(0,.01,0))).r),a=r.sample(e.add(te(0,0,-.01))).r.sub(r.sample(e.add(te(0,0,.01))).r);n.assign(te(s,o,a))}),n.normalize()});re(([r,e])=>r.mul(e).floor().div(e));const Wu=new pe;class dI extends zc{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.isPassTextureNode=!0,this.setUpdateMatrix(!1)}setup(e){const t=e.getNodeProperties(this);return t.passNode=this.passNode,super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class Xx extends dI{static get type(){return"PassMultipleTextureNode"}constructor(e,t,n=!1){super(e,null),this.textureName=t,this.previousTexture=n,this.isPassMultipleTextureNode=!0}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){const e=new this.constructor(this.passNode,this.textureName,this.previousTexture);return e.uvNode=this.uvNode,e.levelNode=this.levelNode,e.biasNode=this.biasNode,e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.offsetNode=this.offsetNode,e}}class Jh extends xn{static get type(){return"PassNode"}constructor(e,t,n,i={}){super("vec4"),this.scope=e,this.scene=t,this.camera=n,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;const s=new jn;s.isRenderTargetTexture=!0,s.name="depth";const o=new ks(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:tn,...i});o.texture.name="output",o.depthTexture=s,this.renderTarget=o,this.overrideMaterial=null,this.transparent=!0,this.opaque=!0,this.contextNode=null,this._contextNodeCache=null,this._textures={output:o.texture,depth:s},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=qe(0),this._cameraFar=qe(0),this._mrt=null,this._layers=null,this._resolutionScale=1,this._viewport=null,this._scissor=null,this.isPassNode=!0,this.updateBeforeType=Ze.FRAME,this.global=!0}setResolutionScale(e){return this._resolutionScale=e,this}getResolutionScale(){return this._resolutionScale}setResolution(e){return ae("PassNode: .setResolution() is deprecated. Use .setResolutionScale() instead."),this.setResolutionScale(e)}getResolution(){return ae("PassNode: .getResolution() is deprecated. Use .getResolutionScale() instead."),this.getResolutionScale()}setLayers(e){return this._layers=e,this}getLayers(){return this._layers}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getTexture(e){let t=this._textures[e];return t===void 0&&(t=this.renderTarget.texture.clone(),t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)),t}getPreviousTexture(e){let t=this._previousTextures[e];return t===void 0&&(t=this.getTexture(e).clone(),this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(t!==void 0){const n=this._textures[e],i=this.renderTarget.textures.indexOf(n);this.renderTarget.textures[i]=t,this._textures[e]=t,this._previousTextures[e]=n,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return t===void 0&&(t=new Xx(this,e),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return t===void 0&&(this._textureNodes[e]===void 0&&this.getTextureNode(e),t=new Xx(this,e,!0),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(t===void 0){const n=this._cameraNear,i=this._cameraFar;this._viewZNodes[e]=t=Zv(this.getTextureNode(e),n,i)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(t===void 0){const n=this._cameraNear,i=this._cameraFar,s=this.getViewZNode(e);this._linearDepthNodes[e]=t=rc(s,n,i)}return t}async compileAsync(e){const t=e.getRenderTarget(),n=e.getMRT();e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),await e.compileAsync(this.scene,this.camera),e.setRenderTarget(t),e.setMRT(n)}setup({renderer:e}){return this.renderTarget.samples=this.options.samples===void 0?e.samples:this.options.samples,this.renderTarget.texture.type=e.getOutputBufferType(),e.reversedDepthBuffer===!0&&(this.renderTarget.depthTexture.type=Qt),this.scope===Jh.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:n}=this;let i,s;const o=t.getOutputRenderTarget();o&&o.isXRRenderTarget===!0?(s=1,i=t.xr.getCamera(),t.xr.updateCamera(i),Wu.set(o.width,o.height)):(i=this.camera,s=t.getPixelRatio(),t.getSize(Wu)),this._pixelRatio=s,this.setSize(Wu.width,Wu.height);const a=t.getRenderTarget(),l=t.getMRT(),c=t.autoClear,u=t.transparent,h=t.opaque,d=i.layers.mask,f=t.contextNode,p=n.overrideMaterial;this._cameraNear.value=i.near,this._cameraFar.value=i.far,this._layers!==null&&(i.layers.mask=this._layers.mask);for(const m in this._previousTextures)this.toggleTexture(m);this.overrideMaterial!==null&&(n.overrideMaterial=this.overrideMaterial),t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.autoClear=!0,t.transparent=this.transparent,t.opaque=this.opaque,this.contextNode!==null&&((this._contextNodeCache===null||this._contextNodeCache.version!==this.version)&&(this._contextNodeCache={version:this.version,context:Po({...t.contextNode.getFlowContextData(),...this.contextNode.getFlowContextData()})}),t.contextNode=this._contextNodeCache.context);const g=n.name;n.name=this.name?this.name:n.name,t.render(n,i),n.name=g,n.overrideMaterial=p,t.setRenderTarget(a),t.setMRT(l),t.autoClear=c,t.transparent=u,t.opaque=h,t.contextNode=f,i.layers.mask=d}setSize(e,t){this._width=e,this._height=t;const n=Math.floor(this._width*this._pixelRatio*this._resolutionScale),i=Math.floor(this._height*this._pixelRatio*this._resolutionScale);this.renderTarget.setSize(n,i),this._scissor!==null?(this.renderTarget.scissor.copy(this._scissor).multiplyScalar(this._pixelRatio*this._resolutionScale).floor(),this.renderTarget.scissorTest=!0):this.renderTarget.scissorTest=!1,this._viewport!==null&&this.renderTarget.viewport.copy(this._viewport).multiplyScalar(this._pixelRatio*this._resolutionScale).floor()}setScissor(e,t,n,i){e===null?this._scissor=null:(this._scissor===null&&(this._scissor=new rt),e.isVector4?this._scissor.copy(e):this._scissor.set(e,t,n,i))}setViewport(e,t,n,i){e===null?this._viewport=null:(this._viewport===null&&(this._viewport=new rt),e.isVector4?this._viewport.copy(e):this._viewport.set(e,t,n,i))}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}Jh.COLOR="color";Jh.DEPTH="depth";const fI=re(([r,e])=>r.mul(e).clamp()).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),pI=re(([r,e])=>(r=r.mul(e),r.div(r.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),mI=re(([r,e])=>{r=r.mul(e),r=r.sub(.004).max(0);const t=r.mul(r.mul(6.2).add(.5)),n=r.mul(r.mul(6.2).add(1.7)).add(.06);return t.div(n).pow(2.2)}).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),gI=re(([r])=>{const e=r.mul(r.add(.0245786)).sub(90537e-9),t=r.mul(r.add(.432951).mul(.983729)).add(.238081);return e.div(t)}),_I=re(([r,e])=>{const t=On(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),n=On(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return r=r.mul(e).div(.6),r=t.mul(r),r=gI(r),r=n.mul(r),r.clamp()}).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),xI=On(te(1.6605,-.1246,-.0182),te(-.5876,1.1329,-.1006),te(-.0728,-.0083,1.1187)),yI=On(te(.6274,.0691,.0164),te(.3293,.9195,.088),te(.0433,.0113,.8956)),vI=re(([r])=>{const e=te(r).toVar(),t=te(e.mul(e)).toVar(),n=te(t.mul(t)).toVar();return J(15.5).mul(n.mul(t)).sub(st(40.14,n.mul(e))).add(st(31.96,n).sub(st(6.868,t.mul(e))).add(st(.4298,t).add(st(.1191,e).sub(.00232))))}),bI=re(([r,e])=>{const t=te(r).toVar(),n=On(te(.856627153315983,.137318972929847,.11189821299995),te(.0951212405381588,.761241990602591,.0767994186031903),te(.0482516061458583,.101439036467562,.811302368396859)),i=On(te(1.1271005818144368,-.1413297634984383,-.14132976349843826),te(-.11060664309660323,1.157823702216272,-.11060664309660294),te(-.016493938717834573,-.016493938717834257,1.2519364065950405)),s=J(-12.47393),o=J(4.026069);return t.mulAssign(e),t.assign(yI.mul(t)),t.assign(n.mul(t)),t.assign(kn(t,1e-10)),t.assign(Yr(t)),t.assign(t.sub(s).div(o.sub(s))),t.assign(Fs(t,0,1)),t.assign(vI(t)),t.assign(i.mul(t)),t.assign(Xh(kn(te(0),t),te(2.2))),t.assign(xI.mul(t)),t.assign(Fs(t,0,1)),t}).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),SI=re(([r,e])=>{const t=J(.76),n=J(.15);r=r.mul(e);const i=Qa(r.r,Qa(r.g,r.b)),s=Mi(i.lessThan(.08),i.sub(st(6.25,i.mul(i))),.04);r.subAssign(s);const o=kn(r.r,kn(r.g,r.b));Ft(o.lessThan(t),()=>r);const a=oi(1,t),l=oi(1,a.mul(a).div(o.add(a.sub(t))));r.mulAssign(l.div(o));const c=oi(1,Er(1,n.mul(o.sub(l)).add(1)));return Dt(r,te(l),c)}).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class Rn extends Ve{static get type(){return"CodeNode"}constructor(e="",t=[],n=""){super("code"),this.isCodeNode=!0,this.global=!0,this.code=e,this.includes=t,this.language=n}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const i of t)i.build(e);const n=e.getCodeFromNode(this,this.getNodeType(e));return n.code=this.code,n.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}class TI extends Rn{static get type(){return"FunctionNode"}constructor(e="",t=[],n=""){super(e,t,n)}generateNodeType(e){return this.getNodeFunction(e).type}getMemberType(e,t){const n=this.getNodeType(e);return e.getStructTypeNode(n).getMemberType(e,t)}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let n=t.nodeFunction;return n===void 0&&(n=e.parser.parseFunction(this.code),t.nodeFunction=n),n}generate(e,t){super.generate(e);const n=this.getNodeFunction(e),i=n.name,s=n.type,o=e.getCodeFromNode(this,s);i!==""&&(o.name=i);const a=e.getPropertyName(o),l=this.getNodeFunction(e).getCode(a);return o.code=l+`
4649
+ `).removeFlowTab();e.addFlowTab()}}const Di=(...r)=>new UL(ya(r,"int")).toStack(),FL=()=>mr("break").toStack(),mf=new WeakMap,yi=new rt,mx=re(({bufferMap:r,influence:e,stride:t,width:n,depth:i,offset:s})=>{const o=Zt(zP).mul(t).add(s),a=o.div(n),l=o.sub(a.mul(n));return Ci(r,dr(l,a)).depth(i).xyz.mul(e)});function IL(r){const e=r.morphAttributes.position!==void 0,t=r.morphAttributes.normal!==void 0,n=r.morphAttributes.color!==void 0,i=r.morphAttributes.position||r.morphAttributes.normal||r.morphAttributes.color,s=i!==void 0?i.length:0;let o=mf.get(r);if(o===void 0||o.count!==s){let _=function(){g.dispose(),mf.delete(r),r.removeEventListener("dispose",_)};o!==void 0&&o.texture.dispose();const a=r.morphAttributes.position||[],l=r.morphAttributes.normal||[],c=r.morphAttributes.color||[];let u=0;e===!0&&(u=1),t===!0&&(u=2),n===!0&&(u=3);let h=r.attributes.position.count*u,d=1;const f=4096;h>f&&(d=Math.ceil(h/f),h=f);const p=new Float32Array(h*d*4*s),g=new lm(p,h,d,s);g.type=Qt,g.needsUpdate=!0;const m=u*4;for(let x=0;x<s;x++){const y=a[x],b=l[x],M=c[x],S=h*d*4*x;for(let E=0;E<y.count;E++){const v=E*m;e===!0&&(yi.fromBufferAttribute(y,E),p[S+v+0]=yi.x,p[S+v+1]=yi.y,p[S+v+2]=yi.z,p[S+v+3]=0),t===!0&&(yi.fromBufferAttribute(b,E),p[S+v+4]=yi.x,p[S+v+5]=yi.y,p[S+v+6]=yi.z,p[S+v+7]=0),n===!0&&(yi.fromBufferAttribute(M,E),p[S+v+8]=yi.x,p[S+v+9]=yi.y,p[S+v+10]=yi.z,p[S+v+11]=M.itemSize===4?yi.w:1)}}o={count:s,texture:g,stride:u,size:new pe(h,d)},mf.set(r,o),r.addEventListener("dispose",_)}return o}class BL extends Ve{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=qe(1),this.updateType=Ze.OBJECT}setup(e){const{geometry:t}=e,n=t.morphAttributes.position!==void 0,i=t.hasAttribute("normal")&&t.morphAttributes.normal!==void 0,s=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,o=s!==void 0?s.length:0,{texture:a,stride:l,size:c}=IL(t);n===!0&&Tn.mulAssign(this.morphBaseInfluence),i===!0&&wr.mulAssign(this.morphBaseInfluence);const u=Zt(c.width);Di(o,({i:h})=>{const d=J(0).toVar();this.mesh.count>1&&this.mesh.morphTexture!==null&&this.mesh.morphTexture!==void 0?d.assign(Ci(this.mesh.morphTexture,dr(Zt(h).add(1),Zt(Sa))).r):d.assign(Jt("morphTargetInfluences","float").element(h).toVar()),Ft(d.notEqual(0),()=>{n===!0&&Tn.addAssign(mx({bufferMap:a,influence:d,stride:l,width:u,depth:h,offset:Zt(0)})),i===!0&&wr.addAssign(mx({bufferMap:a,influence:d,stride:l,width:u,depth:h,offset:Zt(1)}))})})}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce((t,n)=>t+n,0)}}const OL=It(BL).setParameterLength(1);class gl extends Ve{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}}class kL extends gl{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class GL extends yv{static get type(){return"LightingContextNode"}constructor(e,t=null,n=null,i=null){super(e),this.lightingModel=t,this.backdropNode=n,this.backdropAlphaNode=i,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,n=te().toVar("directDiffuse"),i=te().toVar("directSpecular"),s=te().toVar("indirectDiffuse"),o=te().toVar("indirectSpecular"),a={directDiffuse:n,directSpecular:i,indirectDiffuse:s,indirectSpecular:o};return{radiance:te().toVar("radiance"),irradiance:te().toVar("irradiance"),iblIrradiance:te().toVar("iblIrradiance"),ambientOcclusion:J(1).toVar("ambientOcclusion"),reflectedLight:a,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const VL=It(GL);class zL extends gl{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}const Ks=new pe;class jv extends zc{static get type(){return"ViewportTextureNode"}constructor(e=fo,t=null,n=null){let i=null;n===null?(i=new ny,i.minFilter=ui,n=i):i=n,super(n,e,t),this.generateMipmaps=!1,this.defaultFramebuffer=i,this.isOutputTextureNode=!0,this.updateBeforeType=Ze.RENDER,this._cacheTextures=new WeakMap}getTextureForReference(e=null){let t,n;if(this.referenceNode?(t=this.referenceNode.defaultFramebuffer,n=this.referenceNode._cacheTextures):(t=this.defaultFramebuffer,n=this._cacheTextures),e===null)return t;if(n.has(e)===!1){const i=t.clone();n.set(e,i)}return n.get(e)}updateReference(e){const t=e.renderer,n=t.getRenderTarget(),i=t.getCanvasTarget(),s=n||i;return this.value=this.getTextureForReference(s),this.value}updateBefore(e){const t=e.renderer,n=t.getRenderTarget(),i=t.getCanvasTarget(),s=n||i;s===null?t.getDrawingBufferSize(Ks):s.getDrawingBufferSize?s.getDrawingBufferSize(Ks):Ks.set(s.width,s.height);const o=this.getTextureForReference(s);(o.image.width!==Ks.width||o.image.height!==Ks.height)&&(o.image.width=Ks.width,o.image.height=Ks.height,o.needsUpdate=!0);const a=o.generateMipmaps;o.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(o),o.generateMipmaps=a}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Yv=It(jv,null,null,{generateMipmaps:!0}).setParameterLength(0,3),HL=Yv(),WL=(r=fo,e=null)=>HL.sample(r,e);let gf=null;class $L extends jv{static get type(){return"ViewportDepthTextureNode"}constructor(e=fo,t=null,n=null){n===null&&(gf===null&&(gf=new jn),n=gf),super(e,t,n)}}const XL=It($L).setParameterLength(0,3);class hi extends Ve{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===hi.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,n=this.valueNode;let i=null;if(t===hi.DEPTH_BASE)n!==null&&(i=Jv().assign(n));else if(t===hi.DEPTH)e.isPerspectiveCamera?i=Kv(dn.z,so,oo):i=rc(dn.z,so,oo);else if(t===hi.LINEAR_DEPTH)if(n!==null)if(e.isPerspectiveCamera){const s=Zv(n,so,oo);i=rc(s,so,oo)}else i=n;else i=rc(dn.z,so,oo);return i}}hi.DEPTH_BASE="depthBase";hi.DEPTH="depth";hi.LINEAR_DEPTH="linearDepth";const rc=(r,e,t)=>r.add(e).div(e.sub(t)),Kv=(r,e,t)=>e.add(r).mul(t).div(t.sub(e).mul(r)),qL=(r,e,t)=>e.mul(r.add(t)).div(r.mul(e.sub(t))),Zv=re(([r,e,t],n)=>n.renderer.reversedDepthBuffer===!0?e.mul(t).div(e.sub(t).mul(r).sub(e)):e.mul(t).div(t.sub(e).mul(r).sub(t))),Qv=(r,e,t)=>{e=e.max(1e-6).toVar();const n=Yr(r.negate().div(e)),i=Yr(t.div(e));return n.div(i)},Jv=It(hi,hi.DEPTH_BASE),eb=be(hi,hi.DEPTH),jL=It(hi,hi.LINEAR_DEPTH).setParameterLength(0,1);XL();eb.assign=r=>Jv(r);class Ii extends Ve{static get type(){return"ClippingNode"}constructor(e=Ii.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:n,unionPlanes:i}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===Ii.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(n,i):this.scope===Ii.HARDWARE?this.setupHardwareClipping(i,e):this.setupDefault(n,i)}setupAlphaToCoverage(e,t){return re(()=>{const n=J().toVar("distanceToPlane"),i=J().toVar("distanceToGradient"),s=J(1).toVar("clipOpacity"),o=t.length;if(this.hardwareClipping===!1&&o>0){const l=Pi(t).setGroup(Ke);Di(o,({i:c})=>{const u=l.element(c);n.assign(dn.dot(u.xyz).negate().add(u.w)),i.assign(n.fwidth().div(2)),s.mulAssign(Qr(i.negate(),i,n))})}const a=e.length;if(a>0){const l=Pi(e).setGroup(Ke),c=J(1).toVar("intersectionClipOpacity");Di(a,({i:u})=>{const h=l.element(u);n.assign(dn.dot(h.xyz).negate().add(h.w)),i.assign(n.fwidth().div(2)),c.mulAssign(Qr(i.negate(),i,n).oneMinus())}),s.mulAssign(c.oneMinus())}Pt.a.mulAssign(s),Pt.a.equal(0).discard()})()}setupDefault(e,t){return re(()=>{const n=t.length;if(this.hardwareClipping===!1&&n>0){const s=Pi(t).setGroup(Ke);Di(n,({i:o})=>{const a=s.element(o);dn.dot(a.xyz).greaterThan(a.w).discard()})}const i=e.length;if(i>0){const s=Pi(e).setGroup(Ke),o=$h(!0).toVar("clipped");Di(i,({i:a})=>{const l=s.element(a);o.assign(dn.dot(l.xyz).greaterThan(l.w).and(o))}),o.discard()}})()}setupHardwareClipping(e,t){const n=e.length;return t.enableHardwareClipping(n),re(()=>{const i=Pi(e).setGroup(Ke),s=fl(t.getClipDistance());Di(n,({i:o})=>{const a=i.element(o),l=dn.dot(a.xyz).sub(a.w).negate();s.element(o).assign(l)})})()}}Ii.ALPHA_TO_COVERAGE="alphaToCoverage";Ii.DEFAULT="default";Ii.HARDWARE="hardware";const YL=()=>new Ii,KL=()=>new Ii(Ii.ALPHA_TO_COVERAGE),ZL=()=>new Ii(Ii.HARDWARE),QL=.05,gx=re(([r])=>Ar(st(1e4,vi(st(17,r.x).add(st(.1,r.y)))).mul(fi(.1,bi(vi(st(13,r.y).add(r.x))))))),_x=re(([r])=>gx(ke(gx(r.xy),r.z))),JL=re(([r])=>{const e=kn(Kr(dv(r.xyz)),Kr(fv(r.xyz))),t=J(1).div(J(QL).mul(e)).toVar("pixScale"),n=ke(Mc(ho(Yr(t))),Mc(km(Yr(t)))),i=ke(_x(ho(n.x.mul(r.xyz))),_x(ho(n.y.mul(r.xyz)))),s=Ar(Yr(t)),o=fi(st(s.oneMinus(),i.x),st(s,i.y)),a=Qa(s,s.oneMinus()),l=te(o.mul(o).div(st(2,a).mul(oi(1,a))),o.sub(st(.5,a)).div(oi(1,a)),oi(1,oi(1,o).mul(oi(1,o)).div(st(2,a).mul(oi(1,a))))),c=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(l.x,l.y),l.z);return Fs(c,1e-6,1)}).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]});class eU extends Rv{static get type(){return"VertexColorNode"}constructor(e){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e),n=e.hasGeometryAttribute(t);let i;return n===!0?i=super.generate(e):i=e.generateConst(this.nodeType,new rt(1,1,1,1)),i}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const tU=(r=0)=>new eU(r),nU=re(([r])=>et(r.rgb.mul(r.a),r.a),{color:"vec4",return:"vec4"});class mn extends Yn{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.maskNode=null,this.maskShadowNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.receivedShadowPositionNode=null,this.castShadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null,this.contextNode=null}_getNodeChildren(){const e=[];for(const t of Object.getOwnPropertyNames(this)){if(t.startsWith("_")===!0)continue;const n=this[t];n&&n.isNode===!0&&e.push({property:t,childNode:n})}return e}customProgramCacheKey(){const e=[];for(const{property:t,childNode:n}of this._getNodeChildren())e.push(cl(t.slice(0,-4)),n.getCacheKey());return this.type+Gc(e)}build(e){this.setup(e)}setupObserver(e){return new NN(e)}setup(e){e.context.setupNormal=()=>ba(this.setupNormal(e),"NORMAL","vec3"),e.context.setupPositionView=()=>this.setupPositionView(e),e.context.setupModelViewProjection=()=>this.setupModelViewProjection(e);const t=e.renderer,n=t.getRenderTarget();e.addStack();const i=this.setupVertex(e),s=ba(this.vertexNode||i,"VERTEX");e.context.clipSpace=s,e.stack.outputNode=s,this.setupHardwareClipping(e),this.geometryNode!==null&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();let o;const a=this.setupClipping(e);if((this.depthWrite===!0||this.depthTest===!0)&&(n!==null?n.depthBuffer===!0&&this.setupDepth(e):t.depth===!0&&this.setupDepth(e)),this.fragmentNode===null){this.setupDiffuseColor(e),this.setupVariants(e);const l=this.setupLighting(e);a!==null&&e.stack.addToStack(a);const c=et(l,Pt.a).max(0);o=this.setupOutput(e,c),tc.assign(o);const u=this.outputNode!==null;if(u&&(o=this.outputNode),e.context.getOutput&&(o=e.context.getOutput(o,e)),n!==null){const h=t.getMRT(),d=this.mrtNode;h!==null?(u&&tc.assign(o),o=h,d!==null&&(o=h.merge(d))):d!==null&&(o=d)}}else{let l=this.fragmentNode;l.isOutputStructNode!==!0&&(l=et(l)),o=this.setupOutput(e,l)}e.stack.outputNode=o,e.addFlow("fragment",e.removeStack()),e.observer=this.setupObserver(e)}setupClipping(e){if(e.clippingContext===null)return null;const{unionPlanes:t,intersectionPlanes:n}=e.clippingContext;let i=null;if(t.length>0||n.length>0){const s=e.renderer.currentSamples;this.alphaToCoverage&&s>1?i=KL():e.stack.addToStack(YL())}return i}setupHardwareClipping(e){if(this.hardwareClipping=!1,e.clippingContext===null)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.addToStack(ZL()),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:n}=e;let i=this.depthNode;if(i===null){const s=t.getMRT();s&&s.has("depth")?i=s.get("depth"):t.logarithmicDepthBuffer===!0&&(n.isPerspectiveCamera?i=Qv(dn.z,so,oo):i=rc(dn.z,so,oo))}i!==null&&eb.assign(i).toStack()}setupPositionView(){return Hc.mul(Tn).xyz}setupModelViewProjection(){return ic.mul(dn)}setupVertex(e){return e.addStack(),this.setupPosition(e),e.context.position=e.removeStack(),TL}setupPosition(e){const{object:t,geometry:n}=e;if((n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color)&&OL(t).toStack(),t.isSkinnedMesh===!0&&LL(t).toStack(),this.displacementMap){const i=ms("displacementMap","texture"),s=ms("displacementScale","float"),o=ms("displacementBias","float");Tn.addAssign(wr.normalize().mul(i.x.mul(s).add(o)))}return t.isBatchedMesh&&PL(t).toStack(),t.isInstancedMesh&&t.instanceMatrix&&t.instanceMatrix.isInstancedBufferAttribute===!0&&CL(t).toStack(),this.positionNode!==null&&Tn.assign(ba(this.positionNode,"POSITION","vec3")),Tn}setupDiffuseColor(e){const{object:t,geometry:n}=e;this.maskNode!==null&&$h(this.maskNode).not().discard();let i=this.colorNode?et(this.colorNode):qD;this.vertexColors===!0&&n.hasAttribute("color")&&(i=i.mul(tU())),t.instanceColor&&(i=Mh("vec3","vInstanceColor").mul(i)),t.isBatchedMesh&&t._colorsTexture&&(i=Mh("vec3","vBatchColor").mul(i)),Pt.assign(i);const s=this.opacityNode?J(this.opacityNode):Xv;Pt.a.assign(Pt.a.mul(s));let o=null;(this.alphaTestNode!==null||this.alphaTest>0)&&(o=this.alphaTestNode!==null?J(this.alphaTestNode):XD,this.alphaToCoverage===!0?(Pt.a=Qr(o,o.add(pv(Pt.a)),Pt.a),Pt.a.lessThanEqual(0).discard()):Pt.a.lessThanEqual(o).discard()),this.alphaHash===!0&&Pt.a.lessThan(JL(Tn)).discard(),e.isOpaque()&&Pt.a.assign(1)}setupVariants(){}setupOutgoingLight(){return this.lights===!0?te(0):Pt.rgb}setupNormal(){return this.normalNode?te(this.normalNode):eL}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?ms("envMap","cubeTexture"):ms("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new zL(qv)),t}setupLights(e){const t=[],n=this.setupEnvironment(e);n&&n.isLightingNode&&t.push(n);const i=this.setupLightMap(e);i&&i.isLightingNode&&t.push(i);let s=this.aoNode;s===null&&e.material.aoMap&&(s=SL),e.context.getAO&&(s=e.context.getAO(s,e)),s&&t.push(new kL(s));let o=this.lightsNode||e.lightsNode;return t.length>0&&(o=e.renderer.lighting.createNode([...o.getLights(),...t])),o}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:n,backdropAlphaNode:i,emissiveNode:s}=this,a=this.lights===!0||this.lightsNode!==null?this.setupLights(e):null;let l=this.setupOutgoingLight(e);if(a&&a.getScope().hasLights){const c=this.setupLightingModel(e)||null;l=VL(a,c,n,i)}else n!==null&&(l=te(i!==null?Dt(l,n,i):n));return(s&&s.isNode===!0||t.emissive&&t.emissive.isColor===!0)&&(Z_.assign(te(s||YD)),l=l.add(Z_)),l}setupFog(e,t){const n=e.fogNode;return n&&(tc.assign(t),t=et(n.toVar())),t}setupPremultipliedAlpha(e,t){return nU(t)}setupOutput(e,t){return this.fog===!0&&(t=this.setupFog(e,t)),this.premultipliedAlpha===!0&&(t=this.setupPremultipliedAlpha(e,t)),t}setDefaultValues(e){for(const n in e){const i=e[n];this[n]===void 0&&(this[n]=i,i&&i.clone&&(this[n]=i.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const n in t)Object.getOwnPropertyDescriptor(this.constructor.prototype,n)===void 0&&t[n].get!==void 0&&Object.defineProperty(this.constructor.prototype,n,t[n])}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{},nodes:{}});const n=Yn.prototype.toJSON.call(this,e);n.inputNodes={};for(const{property:s,childNode:o}of this._getNodeChildren())n.inputNodes[s]=o.toJSON(e).uuid;function i(s){const o=[];for(const a in s){const l=s[a];delete l.metadata,o.push(l)}return o}if(t){const s=i(e.textures),o=i(e.images),a=i(e.nodes);s.length>0&&(n.textures=s),o.length>0&&(n.images=o),a.length>0&&(n.nodes=a)}return n}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.aoNode=e.aoNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.maskNode=e.maskNode,this.maskShadowNode=e.maskShadowNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.receivedShadowPositionNode=e.receivedShadowPositionNode,this.castShadowPositionNode=e.castShadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,this.contextNode=e.contextNode,super.copy(e)}}const iU=new Oh;class rU extends mn{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.setDefaultValues(iU),this.setValues(e)}}const sU=new gM;class oU extends mn{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.setDefaultValues(sU),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?J(this.offsetNode):yL,t=this.dashScaleNode?J(this.dashScaleNode):gL,n=this.dashSizeNode?J(this.dashSizeNode):_L,i=this.gapSizeNode?J(this.gapSizeNode):xL;af.assign(n),Q_.assign(i);const s=Do(Is("lineDistance").mul(t));(e?s.add(e):s).mod(af.add(Q_)).greaterThan(af).discard()}}const aU=new dM;class lU extends mn{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(aU),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?J(this.opacityNode):Xv;Pt.assign(Hm(et(GD(vt),e),ei))}}const tb=re(([r=Dv])=>{const e=r.z.atan(r.x).mul(1/(Math.PI*2)).add(.5),t=r.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return ke(e,t)});class nb extends ks{constructor(e=1,t={}){super(e,e,t),this.isCubeRenderTarget=!0;const n={width:e,height:e,depth:1},i=[n,n,n,n,n,n];this.texture=new sl(i),this._setTextureOptions(t),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(e,t){const n=t.minFilter,i=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const s=new Co(5,5,5),o=tb(Dv),a=new mn;a.colorNode=Vt(t,o,0),a.side=Lt,a.blending=Pn;const l=new _n(s,a),c=new hm;c.add(l),t.minFilter===ui&&(t.minFilter=Nt);const u=new py(1,10,this),h=e.getMRT();return e.setMRT(null),u.update(e,c),e.setMRT(h),t.minFilter=n,t.generateMipmaps=i,l.geometry.dispose(),l.material.dispose(),this}clear(e,t=!0,n=!0,i=!0){const s=e.getRenderTarget();for(let o=0;o<6;o++)e.setRenderTarget(this,o),e.clear(t,n,i);e.setRenderTarget(s)}}const sc=new WeakMap;class cU extends xn{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=li(null);const t=new sl;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=Ze.RENDER}updateBefore(e){const{renderer:t,material:n}=e,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){const s=i.isTextureNode?i.value:n[i.property];if(s&&s.isTexture){const o=s.mapping;if(o===pa||o===ma){if(sc.has(s)){const a=sc.get(s);xx(a,s.mapping),this._cubeTexture=a}else{const a=s.image;if(uU(a)){const l=new nb(a.height);l.fromEquirectangularTexture(t,s),xx(l.texture,s.mapping),this._cubeTexture=l.texture,sc.set(s,l.texture),s.addEventListener("dispose",ib)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function uU(r){return r==null?!1:r.height>0}function ib(r){const e=r.target;e.removeEventListener("dispose",ib);const t=sc.get(e);t!==void 0&&(sc.delete(e),t.dispose())}function xx(r,e){e===pa?r.mapping=Ki:e===ma&&(r.mapping=Sr)}const rb=It(cU).setParameterLength(1);class qm extends gl{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=rb(this.envNode)}}class hU extends gl{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=J(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Yh{start(e){e.lightsNode.setupLights(e,e.lightsNode.getLightNodes(e)),this.indirect(e)}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class sb extends Yh{constructor(){super()}indirect({context:e}){const t=e.ambientOcclusion,n=e.reflectedLight,i=e.irradianceLightMap;n.indirectDiffuse.assign(et(0)),i?n.indirectDiffuse.addAssign(i):n.indirectDiffuse.addAssign(et(1,1,1,0)),n.indirectDiffuse.mulAssign(t),n.indirectDiffuse.mulAssign(Pt.rgb)}finish(e){const{material:t,context:n}=e,i=n.outgoingLight,s=e.context.environment;if(s)switch(t.combine){case Nc:i.rgb.assign(Dt(i.rgb,i.rgb.mul(s.rgb),fh.mul(pf)));break;case W0:i.rgb.assign(Dt(i.rgb,s.rgb,fh.mul(pf)));break;case $0:i.rgb.addAssign(s.rgb.mul(fh.mul(pf)));break;default:ae("BasicLightingModel: Unsupported .combine value:",t.combine);break}}}const dU=new pr;class fU extends mn{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(dU),this.setValues(e)}setupNormal(){return Wc(Ac)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new qm(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new hU(qv)),t}setupOutgoingLight(){return Pt.rgb}setupLightingModel(){return new sb}}const wc=re(({f0:r,f90:e,dotVH:t})=>{const n=t.mul(-5.55473).sub(6.98316).mul(t).exp2();return r.mul(n.oneMinus()).add(e.mul(n))}),el=re(r=>r.diffuseColor.mul(1/Math.PI)),pU=()=>J(.25),mU=re(({dotNH:r})=>vp.mul(J(.5)).add(1).mul(J(1/Math.PI)).mul(r.pow(vp))),gU=re(({lightDirection:r})=>{const e=r.add($t).normalize(),t=vt.dot(e).clamp(),n=$t.dot(e).clamp(),i=wc({f0:vo,f90:1,dotVH:n}),s=pU(),o=mU({dotNH:t});return i.mul(s).mul(o)});class ob extends sb{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:n}){const s=vt.dot(e).clamp().mul(t);n.directDiffuse.addAssign(s.mul(el({diffuseColor:Pt.rgb}))),this.specular===!0&&n.directSpecular.addAssign(s.mul(gU({lightDirection:e})).mul(fh))}indirect(e){const{ambientOcclusion:t,irradiance:n,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(n.mul(el({diffuseColor:Pt}))),i.indirectDiffuse.mulAssign(t)}}const _U=new uy;class xU extends mn{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(_U),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new qm(t):null}setupLightingModel(){return new ob(!1)}}const yU=new uM;class vU extends mn{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(yU),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new qm(t):null}setupLightingModel(){return new ob}setupVariants(){const e=(this.shininessNode?J(this.shininessNode):jD).max(1e-4);vp.assign(e);const t=this.specularNode||KD;vo.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const bU=re(r=>{if(r.geometry.hasAttribute("normal")===!1)return J(0);const e=Ac.dFdx().abs().max(Ac.dFdy().abs());return e.x.max(e.y).max(e.z)}),ab=re(r=>{const{roughness:e}=r,t=bU();let n=e.max(.0525);return n=n.add(t),n=n.min(1),n}),SU=re(({alpha:r,dotNL:e,dotNV:t})=>{const n=r.pow2(),i=e.mul(n.add(n.oneMinus().mul(t.pow2())).sqrt()),s=t.mul(n.add(n.oneMinus().mul(e.pow2())).sqrt());return Er(.5,i.add(s).max(Om))}).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),TU=re(({alphaT:r,alphaB:e,dotTV:t,dotBV:n,dotTL:i,dotBL:s,dotNV:o,dotNL:a})=>{const l=a.mul(te(r.mul(t),e.mul(n),o).length()),c=o.mul(te(r.mul(i),e.mul(s),a).length());return Er(.5,l.add(c).max(Om))}).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),MU=re(({alpha:r,dotNH:e})=>{const t=r.pow2(),n=e.pow2().mul(t.oneMinus()).oneMinus();return t.div(n.pow2()).mul(1/Math.PI)}).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),EU=J(1/Math.PI),AU=re(({alphaT:r,alphaB:e,dotNH:t,dotTH:n,dotBH:i})=>{const s=r.mul(e),o=te(e.mul(n),r.mul(i),s.mul(t)),a=o.dot(o),l=s.div(a);return EU.mul(s.mul(l.pow2()))}).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),lb=re(({lightDirection:r,f0:e,f90:t,roughness:n,f:i,normalView:s=vt,USE_IRIDESCENCE:o,USE_ANISOTROPY:a})=>{const l=n.pow2(),c=r.add($t).normalize(),u=s.dot(r).clamp(),h=s.dot($t).clamp(),d=s.dot(c).clamp(),f=$t.dot(c).clamp();let p=wc({f0:e,f90:t,dotVH:f}),g,m;if(mp(o)&&(p=Fm.mix(p,i)),mp(a)){const _=ch.dot(r),x=ch.dot($t),y=ch.dot(c),b=va.dot(r),M=va.dot($t),S=va.dot(c);g=TU({alphaT:yp,alphaB:l,dotTV:x,dotBV:M,dotTL:_,dotBL:b,dotNV:h,dotNL:u}),m=AU({alphaT:yp,alphaB:l,dotNH:d,dotTH:y,dotBH:S})}else g=SU({alpha:l,dotNL:u,dotNV:h}),m=MU({alpha:l,dotNH:d});return p.mul(g).mul(m)}),wU=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]);let or=null;const wh=re(({roughness:r,dotNV:e})=>{or===null&&(or=new gm(wU,16,16,In,tn),or.name="DFG_LUT",or.minFilter=Nt,or.magFilter=Nt,or.wrapS=ci,or.wrapT=ci,or.generateMipmaps=!1,or.needsUpdate=!0);const t=ke(r,e);return Vt(or,t).rg}),RU=re(({lightDirection:r,f0:e,f90:t,roughness:n,f:i,USE_IRIDESCENCE:s,USE_ANISOTROPY:o})=>{const a=lb({lightDirection:r,f0:e,f90:t,roughness:n,f:i,USE_IRIDESCENCE:s,USE_ANISOTROPY:o}),l=vt.dot(r).clamp(),c=vt.dot($t).clamp(),u=wh({roughness:n,dotNV:c}),h=wh({roughness:n,dotNV:l}),d=e.mul(u.x).add(t.mul(u.y)),f=e.mul(h.x).add(t.mul(h.y)),p=u.x.add(u.y),g=h.x.add(h.y),m=J(1).sub(p),_=J(1).sub(g),x=e.add(e.oneMinus().mul(.047619)),y=d.mul(f).mul(x).div(J(1).sub(m.mul(_).mul(x).mul(x)).add(Om)),b=m.mul(_),M=y.mul(b);return a.add(M)}),cb=re(r=>{const{dotNV:e,specularColor:t,specularF90:n,roughness:i}=r,s=wh({dotNV:e,roughness:i});return t.mul(s.x).add(n.mul(s.y))}),yx=re(({f:r,f90:e,dotVH:t})=>{const n=t.oneMinus().saturate(),i=n.mul(n),s=n.mul(i,i).clamp(0,.9999);return r.sub(te(e).mul(s)).div(s.oneMinus())}).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),CU=re(({roughness:r,dotNH:e})=>{const t=r.pow2(),n=J(1).div(t),s=e.pow2().oneMinus().max(.0078125);return J(2).add(n).mul(s.pow(n.mul(.5))).div(2*Math.PI)}).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),NU=re(({dotNV:r,dotNL:e})=>J(1).div(J(4).mul(e.add(r).sub(e.mul(r))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),PU=re(({lightDirection:r})=>{const e=r.add($t).normalize(),t=vt.dot(r).clamp(),n=vt.dot($t).clamp(),i=vt.dot(e).clamp(),s=CU({roughness:ro,dotNH:i}),o=NU({dotNV:n,dotNL:t});return Ri.mul(s).mul(o)}),vx=re(({N:r,V:e,roughness:t})=>{const s=.0078125,o=r.dot(e).saturate(),a=ke(t,o.oneMinus().sqrt());return a.assign(a.mul(.984375).add(s)),a}).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),DU=re(({f:r})=>{const e=r.length();return kn(e.mul(e).add(r.z).div(e.add(1)),0)}).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),Ou=re(({v1:r,v2:e})=>{const t=r.dot(e),n=t.abs().toVar(),i=n.mul(.0145206).add(.4965155).mul(n).add(.8543985).toVar(),s=n.add(4.1616724).mul(n).add(3.417594).toVar(),o=i.div(s),a=t.greaterThan(0).select(o,kn(t.mul(t).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return r.cross(e).mul(a)}).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),_f=re(({N:r,V:e,P:t,mInv:n,p0:i,p1:s,p2:o,p3:a})=>{const l=s.sub(i).toVar(),c=a.sub(i).toVar(),u=l.cross(c),h=te().toVar();return Ft(u.dot(t.sub(i)).greaterThanEqual(0),()=>{const d=e.sub(r.mul(e.dot(r))).normalize(),f=r.cross(d).negate(),p=n.mul(On(d,f,r).transpose()).toVar(),g=p.mul(i.sub(t)).normalize().toVar(),m=p.mul(s.sub(t)).normalize().toVar(),_=p.mul(o.sub(t)).normalize().toVar(),x=p.mul(a.sub(t)).normalize().toVar(),y=te(0).toVar();y.addAssign(Ou({v1:g,v2:m})),y.addAssign(Ou({v1:m,v2:_})),y.addAssign(Ou({v1:_,v2:x})),y.addAssign(Ou({v1:x,v2:g})),h.assign(te(DU({f:y})))}),h}).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),Kh=1/6,ub=r=>st(Kh,st(r,st(r,r.negate().add(3)).sub(3)).add(1)),Ep=r=>st(Kh,st(r,st(r,st(3,r).sub(6))).add(4)),hb=r=>st(Kh,st(r,st(r,st(-3,r).add(3)).add(3)).add(1)),Ap=r=>st(Kh,Xh(r,3)),bx=r=>ub(r).add(Ep(r)),Sx=r=>hb(r).add(Ap(r)),Tx=r=>fi(-1,Ep(r).div(ub(r).add(Ep(r)))),Mx=r=>fi(1,Ap(r).div(hb(r).add(Ap(r)))),Ex=(r,e,t)=>{const n=r.uvNode,i=st(n,e.zw).add(.5),s=ho(i),o=Ar(i),a=bx(o.x),l=Sx(o.x),c=Tx(o.x),u=Mx(o.x),h=Tx(o.y),d=Mx(o.y),f=ke(s.x.add(c),s.y.add(h)).sub(.5).mul(e.xy),p=ke(s.x.add(u),s.y.add(h)).sub(.5).mul(e.xy),g=ke(s.x.add(c),s.y.add(d)).sub(.5).mul(e.xy),m=ke(s.x.add(u),s.y.add(d)).sub(.5).mul(e.xy),_=bx(o.y).mul(fi(a.mul(r.sample(f).level(t)),l.mul(r.sample(p).level(t)))),x=Sx(o.y).mul(fi(a.mul(r.sample(g).level(t)),l.mul(r.sample(m).level(t))));return _.add(x)},LU=re(([r,e])=>{const t=ke(r.size(Zt(e))),n=ke(r.size(Zt(e.add(1)))),i=Er(1,t),s=Er(1,n),o=Ex(r,et(i,t),ho(e)),a=Ex(r,et(s,n),km(e));return Ar(e).mix(o,a)}),Ax=re(([r,e,t,n,i])=>{const s=te(xv(e.negate(),br(r),Er(1,n))),o=te(Kr(i[0].xyz),Kr(i[1].xyz),Kr(i[2].xyz));return br(s).mul(t.mul(o))}).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),UU=re(([r,e])=>r.mul(Fs(e.mul(2).sub(2),0,1))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),FU=Yv(),IU=WL(),wx=re(([r,e,t],{material:n})=>{const s=(n.side===Lt?FU:IU).sample(r),o=Yr(Sp.x).mul(UU(e,t));return LU(s,o)}),Rx=re(([r,e,t])=>(Ft(t.notEqual(0),()=>{const n=lv(e).negate().div(t);return av(n.negate().mul(r))}),te(1))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),BU=re(([r,e,t,n,i,s,o,a,l,c,u,h,d,f,p])=>{let g,m;if(p){g=et().toVar(),m=te().toVar();const M=u.sub(1).mul(p.mul(.025)),S=te(u.sub(M),u,u.add(M));Di({start:0,end:3},({i:E})=>{const v=S.element(E),w=Ax(r,e,h,v,a),N=o.add(w),C=c.mul(l.mul(et(N,1))),F=ke(C.xy.div(C.w)).toVar();F.addAssign(1),F.divAssign(2),F.assign(ke(F.x,F.y.oneMinus()));const V=wx(F,t,v);g.element(E).assign(V.element(E)),g.a.addAssign(V.a),m.element(E).assign(n.element(E).mul(Rx(Kr(w),d,f).element(E)))}),g.a.divAssign(3)}else{const M=Ax(r,e,h,u,a),S=o.add(M),E=c.mul(l.mul(et(S,1))),v=ke(E.xy.div(E.w)).toVar();v.addAssign(1),v.divAssign(2),v.assign(ke(v.x,v.y.oneMinus())),g=wx(v,t,u),m=n.mul(Rx(Kr(M),d,f))}const _=m.rgb.mul(g.rgb),x=r.dot(e).clamp(),y=te(cb({dotNV:x,specularColor:i,specularF90:s,roughness:t})),b=m.r.add(m.g,m.b).div(3);return et(y.oneMinus().mul(_),g.a.oneMinus().mul(b).oneMinus())}),OU=On(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),kU=r=>{const e=r.sqrt();return te(1).add(e).div(te(1).sub(e))},Cx=(r,e)=>r.sub(e).div(r.add(e)).pow2(),GU=(r,e)=>{const t=r.mul(2*Math.PI*1e-9),n=te(54856e-17,44201e-17,52481e-17),i=te(1681e3,1795300,2208400),s=te(43278e5,93046e5,66121e5),o=J(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(t.mul(2239900).add(e.x).cos()).mul(t.pow2().mul(-45282e5).exp());let a=n.mul(s.mul(2*Math.PI).sqrt()).mul(i.mul(t).add(e).cos()).mul(t.pow2().negate().mul(s).exp());return a=te(a.x.add(o),a.y,a.z).div(10685e-11),OU.mul(a)},Nx=re(({outsideIOR:r,eta2:e,cosTheta1:t,thinFilmThickness:n,baseF0:i})=>{const s=Dt(r,e,Qr(0,.03,n)),a=r.div(s).pow2().mul(t.pow2().oneMinus()).oneMinus();Ft(a.lessThan(0),()=>te(1));const l=a.sqrt(),c=Cx(s,r),u=wc({f0:c,f90:1,dotVH:t}),h=u.oneMinus(),d=s.lessThan(r).select(Math.PI,0),f=J(Math.PI).sub(d),p=kU(i.clamp(0,.9999)),g=Cx(p,s.toVec3()),m=wc({f0:g,f90:1,dotVH:l}),_=te(p.x.lessThan(s).select(Math.PI,0),p.y.lessThan(s).select(Math.PI,0),p.z.lessThan(s).select(Math.PI,0)),x=s.mul(n,l,2),y=te(f).add(_),b=u.mul(m).clamp(1e-5,.9999),M=b.sqrt(),S=h.pow2().mul(m).div(te(1).sub(b)),v=u.add(S).toVar(),w=S.sub(h).toVar();return Di({start:1,end:2,condition:"<=",name:"m"},({m:N})=>{w.mulAssign(M);const C=GU(J(N).mul(x),J(N).mul(y)).mul(2);v.addAssign(w.mul(C))}),v.max(te(0))}).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),Fl=re(({normal:r,viewDir:e,roughness:t})=>{const n=r.dot(e).saturate(),i=t.mul(t),s=t.add(.1).reciprocal(),o=J(-1.9362).add(t.mul(1.0678)).add(i.mul(.4573)).sub(s.mul(.8469)),a=J(-.6014).add(t.mul(.5538)).sub(i.mul(.467)).sub(s.mul(.1255));return o.mul(n).add(a).exp().saturate()}),Il=te(.04),ku=J(1);class db extends Yh{constructor(e=!1,t=!1,n=!1,i=!1,s=!1,o=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=n,this.anisotropy=i,this.transmission=s,this.dispersion=o,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null,this.iridescenceF0Dielectric=null,this.iridescenceF0Metallic=null}start(e){if(this.clearcoat===!0&&(this.clearcoatRadiance=te().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=te().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=te().toVar("clearcoatSpecularIndirect")),this.sheen===!0&&(this.sheenSpecularDirect=te().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=te().toVar("sheenSpecularIndirect")),this.iridescence===!0){const t=vt.dot($t).clamp(),n=Nx({outsideIOR:J(1),eta2:_p,cosTheta1:t,thinFilmThickness:xp,baseF0:vo}),i=Nx({outsideIOR:J(1),eta2:_p,cosTheta1:t,thinFilmThickness:xp,baseF0:Pt.rgb});this.iridescenceFresnel=Dt(n,i,bs),this.iridescenceF0Dielectric=yx({f:n,f90:1,dotVH:t}),this.iridescenceF0Metallic=yx({f:i,f90:1,dotVH:t}),this.iridescenceF0=Dt(this.iridescenceF0Dielectric,this.iridescenceF0Metallic,bs)}if(this.transmission===!0){const t=Ja,n=pD.sub(Ja).normalize(),i=ml,s=e.context;s.backdrop=BU(i,n,Wr,ca,ha,da,t,To,es,ic,uh,nv,rv,iv,this.dispersion?sv:null),s.backdropAlpha=bp,Pt.a.mulAssign(Dt(1,s.backdrop.a,bp))}super.start(e)}computeMultiscattering(e,t,n,i,s=null){const o=vt.dot($t).clamp(),a=wh({roughness:Wr,dotNV:o}),l=s?Fm.mix(i,s):i,c=l.mul(a.x).add(n.mul(a.y)),h=a.x.add(a.y).oneMinus(),d=l.add(l.oneMinus().mul(.047619)),f=c.mul(d).div(h.mul(d).oneMinus());e.addAssign(c),t.addAssign(f.mul(h))}direct({lightDirection:e,lightColor:t,reflectedLight:n}){const s=vt.dot(e).clamp().mul(t).toVar();if(this.sheen===!0){this.sheenSpecularDirect.addAssign(s.mul(PU({lightDirection:e})));const o=Fl({normal:vt,viewDir:$t,roughness:ro}),a=Fl({normal:vt,viewDir:e,roughness:ro}),l=Ri.r.max(Ri.g).max(Ri.b).mul(o.max(a)).oneMinus();s.mulAssign(l)}if(this.clearcoat===!0){const a=ao.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(a.mul(lb({lightDirection:e,f0:Il,f90:ku,roughness:ec,normalView:ao})))}n.directDiffuse.addAssign(s.mul(el({diffuseColor:ca}))),n.directSpecular.addAssign(s.mul(RU({lightDirection:e,f0:ha,f90:1,roughness:Wr,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:n,halfHeight:i,reflectedLight:s,ltc_1:o,ltc_2:a}){const l=t.add(n).sub(i),c=t.sub(n).sub(i),u=t.sub(n).add(i),h=t.add(n).add(i),d=vt,f=$t,p=dn.toVar(),g=vx({N:d,V:f,roughness:Wr}),m=o.sample(g).toVar(),_=a.sample(g).toVar(),x=On(te(m.x,0,m.y),te(0,1,0),te(m.z,0,m.w)).toVar(),y=ha.mul(_.x).add(da.sub(ha).mul(_.y)).toVar();if(s.directSpecular.addAssign(e.mul(y).mul(_f({N:d,V:f,P:p,mInv:x,p0:l,p1:c,p2:u,p3:h}))),s.directDiffuse.addAssign(e.mul(ca).mul(_f({N:d,V:f,P:p,mInv:On(1,0,0,0,1,0,0,0,1),p0:l,p1:c,p2:u,p3:h}))),this.clearcoat===!0){const b=ao,M=vx({N:b,V:f,roughness:ec}),S=o.sample(M),E=a.sample(M),v=On(te(S.x,0,S.y),te(0,1,0),te(S.z,0,S.w)),w=Il.mul(E.x).add(ku.sub(Il).mul(E.y));this.clearcoatSpecularDirect.addAssign(e.mul(w).mul(_f({N:b,V:f,P:p,mInv:v,p0:l,p1:c,p2:u,p3:h})))}}indirect(e){this.indirectDiffuse(e),this.indirectSpecular(e),this.ambientOcclusion(e)}indirectDiffuse(e){const{irradiance:t,reflectedLight:n}=e.context,i=t.mul(el({diffuseColor:ca})).toVar();if(this.sheen===!0){const s=Fl({normal:vt,viewDir:$t,roughness:ro}),o=Ri.r.max(Ri.g).max(Ri.b).mul(s).oneMinus();i.mulAssign(o)}n.indirectDiffuse.addAssign(i)}indirectSpecular(e){const{radiance:t,iblIrradiance:n,reflectedLight:i}=e.context;if(this.sheen===!0&&this.sheenSpecularIndirect.addAssign(n.mul(Ri,Fl({normal:vt,viewDir:$t,roughness:ro}))),this.clearcoat===!0){const m=ao.dot($t).clamp(),_=cb({dotNV:m,specularColor:Il,specularF90:ku,roughness:ec});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(_))}const s=te().toVar("singleScatteringDielectric"),o=te().toVar("multiScatteringDielectric"),a=te().toVar("singleScatteringMetallic"),l=te().toVar("multiScatteringMetallic");this.computeMultiscattering(s,o,da,vo,this.iridescenceF0Dielectric),this.computeMultiscattering(a,l,da,Pt.rgb,this.iridescenceF0Metallic);const c=Dt(s,a,bs),u=Dt(o,l,bs),h=s.add(o),d=ca.mul(h.oneMinus()),f=n.mul(1/Math.PI),p=t.mul(c).add(u.mul(f)).toVar(),g=d.mul(f).toVar();if(this.sheen===!0){const m=Fl({normal:vt,viewDir:$t,roughness:ro}),_=Ri.r.max(Ri.g).max(Ri.b).mul(m).oneMinus();p.mulAssign(_),g.mulAssign(_)}i.indirectSpecular.addAssign(p),i.indirectDiffuse.addAssign(g)}ambientOcclusion(e){const{ambientOcclusion:t,reflectedLight:n}=e.context,s=vt.dot($t).clamp().add(t),o=Wr.mul(-16).oneMinus().negate().exp2(),a=t.sub(s.pow(o).oneMinus()).clamp();this.clearcoat===!0&&this.clearcoatSpecularIndirect.mulAssign(t),this.sheen===!0&&this.sheenSpecularIndirect.mulAssign(t),n.indirectDiffuse.mulAssign(t),n.indirectSpecular.mulAssign(a)}finish({context:e}){const{outgoingLight:t}=e;if(this.clearcoat===!0){const n=ao.dot($t).clamp(),i=wc({dotVH:n,f0:Il,f90:ku}),s=t.mul(gp.mul(i).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(gp));t.assign(s)}if(this.sheen===!0){const n=t.add(this.sheenSpecularDirect,this.sheenSpecularIndirect.mul(1/Math.PI));t.assign(n)}}}const Px=J(1),wp=J(-2),Gu=J(.8),xf=J(-1),Vu=J(.4),yf=J(2),zu=J(.305),vf=J(3),Dx=J(.21),VU=J(4),Lx=J(4),zU=J(16),HU=re(([r])=>{const e=te(bi(r)).toVar(),t=J(-1).toVar();return Ft(e.x.greaterThan(e.z),()=>{Ft(e.x.greaterThan(e.y),()=>{t.assign(Ti(r.x.greaterThan(0),0,3))}).Else(()=>{t.assign(Ti(r.y.greaterThan(0),1,4))})}).Else(()=>{Ft(e.z.greaterThan(e.y),()=>{t.assign(Ti(r.z.greaterThan(0),2,5))}).Else(()=>{t.assign(Ti(r.y.greaterThan(0),1,4))})}),t}).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),WU=re(([r,e])=>{const t=ke().toVar();return Ft(e.equal(0),()=>{t.assign(ke(r.z,r.y).div(bi(r.x)))}).ElseIf(e.equal(1),()=>{t.assign(ke(r.x.negate(),r.z.negate()).div(bi(r.y)))}).ElseIf(e.equal(2),()=>{t.assign(ke(r.x.negate(),r.y).div(bi(r.z)))}).ElseIf(e.equal(3),()=>{t.assign(ke(r.z.negate(),r.y).div(bi(r.x)))}).ElseIf(e.equal(4),()=>{t.assign(ke(r.x.negate(),r.z).div(bi(r.y)))}).Else(()=>{t.assign(ke(r.x,r.y).div(bi(r.z)))}),st(.5,t.add(1))}).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),$U=re(([r])=>{const e=J(0).toVar();return Ft(r.greaterThanEqual(Gu),()=>{e.assign(Px.sub(r).mul(xf.sub(wp)).div(Px.sub(Gu)).add(wp))}).ElseIf(r.greaterThanEqual(Vu),()=>{e.assign(Gu.sub(r).mul(yf.sub(xf)).div(Gu.sub(Vu)).add(xf))}).ElseIf(r.greaterThanEqual(zu),()=>{e.assign(Vu.sub(r).mul(vf.sub(yf)).div(Vu.sub(zu)).add(yf))}).ElseIf(r.greaterThanEqual(Dx),()=>{e.assign(zu.sub(r).mul(VU.sub(vf)).div(zu.sub(Dx)).add(vf))}).Else(()=>{e.assign(J(-2).mul(Yr(st(1.16,r))))}),e}).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),XU=re(([r,e])=>{const t=r.toVar();t.assign(st(2,t).sub(1));const n=te(t,1).toVar();return Ft(e.equal(0),()=>{n.assign(n.zyx)}).ElseIf(e.equal(1),()=>{n.assign(n.xzy),n.xz.mulAssign(-1)}).ElseIf(e.equal(2),()=>{n.x.mulAssign(-1)}).ElseIf(e.equal(3),()=>{n.assign(n.zyx),n.xz.mulAssign(-1)}).ElseIf(e.equal(4),()=>{n.assign(n.xzy),n.xy.mulAssign(-1)}).ElseIf(e.equal(5),()=>{n.z.mulAssign(-1)}),n}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),qU=re(([r,e,t,n,i,s])=>{const o=J(t),a=te(e),l=Fs($U(o),wp,s),c=Ar(l),u=ho(l),h=te(Rc(r,a,u,n,i,s)).toVar();return Ft(c.notEqual(0),()=>{const d=te(Rc(r,a,u.add(1),n,i,s)).toVar();h.assign(Dt(h,d,c))}),h}),Rc=re(([r,e,t,n,i,s])=>{const o=J(t).toVar(),a=te(e),l=J(HU(a)).toVar(),c=J(kn(Lx.sub(o),0)).toVar();o.assign(kn(o,Lx));const u=J(Mc(o)).toVar(),h=ke(WU(a,l).mul(u.sub(2)).add(1)).toVar();return Ft(l.greaterThan(2),()=>{h.y.addAssign(u),l.subAssign(3)}),h.x.addAssign(l.mul(u)),h.x.addAssign(c.mul(st(3,zU))),h.y.addAssign(st(4,Mc(s).sub(u))),h.x.mulAssign(n),h.y.mulAssign(i),r.sample(h).grad(ke(),ke())}),bf=re(({envMap:r,mipInt:e,outputDirection:t,theta:n,axis:i,CUBEUV_TEXEL_WIDTH:s,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const l=fr(n),c=t.mul(l).add(i.cross(t).mul(vi(n))).add(i.mul(i.dot(t).mul(l.oneMinus())));return Rc(r,c,e,s,o,a)}),jU=re(({n:r,latitudinal:e,poleAxis:t,outputDirection:n,weights:i,samples:s,dTheta:o,mipInt:a,envMap:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h})=>{const d=te(Ti(e,t,So(t,n))).toVar();Ft(d.equal(te(0)),()=>{d.assign(te(n.z,0,n.x.negate()))}),d.assign(br(d));const f=te().toVar();return f.addAssign(i.element(0).mul(bf({theta:0,axis:d,outputDirection:n,mipInt:a,envMap:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h}))),Di({start:Zt(1),end:r},({i:p})=>{Ft(p.greaterThanEqual(s),()=>{FL()});const g=J(o.mul(J(p))).toVar();f.addAssign(i.element(p).mul(bf({theta:g.mul(-1),axis:d,outputDirection:n,mipInt:a,envMap:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h}))),f.addAssign(i.element(p).mul(bf({theta:g,axis:d,outputDirection:n,mipInt:a,envMap:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h})))}),et(f,1)}),YU=re(([r])=>{const e=mt(r).toVar();return e.assign(e.shiftLeft(mt(16)).bitOr(e.shiftRight(mt(16)))),e.assign(e.bitAnd(mt(1431655765)).shiftLeft(mt(1)).bitOr(e.bitAnd(mt(2863311530)).shiftRight(mt(1)))),e.assign(e.bitAnd(mt(858993459)).shiftLeft(mt(2)).bitOr(e.bitAnd(mt(3435973836)).shiftRight(mt(2)))),e.assign(e.bitAnd(mt(252645135)).shiftLeft(mt(4)).bitOr(e.bitAnd(mt(4042322160)).shiftRight(mt(4)))),e.assign(e.bitAnd(mt(16711935)).shiftLeft(mt(8)).bitOr(e.bitAnd(mt(4278255360)).shiftRight(mt(8)))),J(e).mul(23283064365386963e-26)}),KU=re(([r,e])=>ke(J(r).div(J(e)),YU(r))),ZU=re(([r,e,t])=>{const n=t.mul(t).toConst(),i=te(1,0,0).toConst(),s=So(e,i).toConst(),o=Ps(r.x).toConst(),a=st(2,3.14159265359).mul(r.y).toConst(),l=o.mul(fr(a)).toConst(),c=o.mul(vi(a)).toVar(),u=st(.5,e.z.add(1)).toConst();c.assign(u.oneMinus().mul(Ps(l.mul(l).oneMinus())).add(u.mul(c)));const h=i.mul(l).add(s.mul(c)).add(e.mul(Ps(kn(0,l.mul(l).add(c.mul(c)).oneMinus()))));return br(te(n.mul(h.x),n.mul(h.y),kn(0,h.z)))}),QU=re(({roughness:r,mipInt:e,envMap:t,N_immutable:n,GGX_SAMPLES:i,CUBEUV_TEXEL_WIDTH:s,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const l=te(n).toVar(),c=te(0).toVar(),u=J(0).toVar();return Ft(r.lessThan(.001),()=>{c.assign(Rc(t,l,e,s,o,a))}).Else(()=>{const h=Ti(bi(l.z).lessThan(.999),te(0,0,1),te(1,0,0)),d=br(So(h,l)).toVar(),f=So(l,d).toVar();Di({start:mt(0),end:i},({i:p})=>{const g=KU(p,i),m=ZU(g,te(0,0,1),r),_=br(d.mul(m.x).add(f.mul(m.y)).add(l.mul(m.z))),x=br(_.mul(bo(l,_).mul(2)).sub(l)),y=kn(bo(l,x),0);Ft(y.greaterThan(0),()=>{const b=Rc(t,x,e,s,o,a);c.addAssign(b.mul(y)),u.addAssign(y)})}),Ft(u.greaterThan(0),()=>{c.assign(c.div(u))})}),et(c,1)}),Ss=4,Ux=[.125,.215,.35,.446,.526,.582],lo=20,JU=512,Bl=new ol(-1,1,1,-1,0,1),eF=new Cn(90,1),Fx=new We;let Sf=null,Tf=0,Mf=0;const tF=new P,Rh=new WeakMap,nF=[3,1,5,0,4,2],Ef=XU(dl(),Is("faceIndex")).normalize(),Zh=te(Ef.x,Ef.y,Ef.z);class iF{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._ggxMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}get _hasInitialized(){return this._renderer.hasInitialized()}fromScene(e,t=0,n=.1,i=100,s={}){const{size:o=256,position:a=tF,renderTarget:l=null}=s;if(this._setSize(o),this._hasInitialized===!1){ae('PMREMGenerator: ".fromScene()" called before the backend is initialized. Try using "await renderer.init()" instead.');const u=l||this._allocateTarget();return s.renderTarget=u,this.fromSceneAsync(e,t,n,i,s),u}Sf=this._renderer.getRenderTarget(),Tf=this._renderer.getActiveCubeFace(),Mf=this._renderer.getActiveMipmapLevel();const c=l||this._allocateTarget();return c.depthBuffer=!0,this._init(c),this._sceneToCubeUV(e,n,i,c,a),t>0&&this._blur(c,0,0,t),this._applyPMREM(c),this._cleanup(c),c}async fromSceneAsync(e,t=0,n=.1,i=100,s={}){return Kt('PMREMGenerator: ".fromSceneAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this.fromScene(e,t,n,i,s)}fromEquirectangular(e,t=null){if(this._hasInitialized===!1){ae('PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Try using "await renderer.init()" instead.'),this._setSizeFromTexture(e);const n=t||this._allocateTarget();return this.fromEquirectangularAsync(e,n),n}return this._fromTexture(e,t)}async fromEquirectangularAsync(e,t=null){return Kt('PMREMGenerator: ".fromEquirectangularAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}fromCubemap(e,t=null){if(this._hasInitialized===!1){ae("PMREMGenerator: .fromCubemap() called before the backend is initialized. Try using .fromCubemapAsync() instead."),this._setSizeFromTexture(e);const n=t||this._allocateTarget();return this.fromCubemapAsync(e,t),n}return this._fromTexture(e,t)}async fromCubemapAsync(e,t=null){return Kt('PMREMGenerator: ".fromCubemapAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}async compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=Bx(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=Ox(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSizeFromTexture(e){e.mapping===Ki||e.mapping===Sr?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4)}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodMeshes.length;e++)this._lodMeshes[e].geometry.dispose()}_cleanup(e){this._renderer.setRenderTarget(Sf,Tf,Mf),e.scissorTest=!1,this._setViewport(e,0,0,e.width,e.height)}_fromTexture(e,t){this._setSizeFromTexture(e),Sf=this._renderer.getRenderTarget(),Tf=this._renderer.getActiveCubeFace(),Mf=this._renderer.getActiveMipmapLevel();const n=t||this._allocateTarget();return this._init(n),this._textureToCubeUV(e,n),this._applyPMREM(n),this._cleanup(n),n}_allocateTarget(){const e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize;return Ix(e,t)}_init(e){if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e.width||this._pingPongRenderTarget.height!==e.height){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=Ix(e.width,e.height);const{_lodMax:t}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=rF(t)),this._blurMaterial=sF(t,e.width,e.height),this._ggxMaterial=oF(t,e.width,e.height)}}async _compileMaterial(e){const t=new _n(new An,e);await this._renderer.compile(t,Bl)}_sceneToCubeUV(e,t,n,i,s){const o=eF;o.near=t,o.far=n;const a=[1,1,1,1,-1,1],l=[1,-1,1,-1,1,-1],c=this._renderer,u=c.autoClear;c.getClearColor(Fx),c.autoClear=!1,this._backgroundBox===null&&(this._backgroundBox=new _n(new Co,new pr({name:"PMREM.Background",side:Lt,depthWrite:!1,depthTest:!1})));const h=this._backgroundBox,d=h.material;let f=!1;const p=e.background;p?p.isColor&&(d.color.copy(p),e.background=null,f=!0):(d.color.copy(Fx),f=!0),c.setRenderTarget(i),c.clear(),f&&c.render(h,o);for(let g=0;g<6;g++){const m=g%3;m===0?(o.up.set(0,a[g],0),o.position.set(s.x,s.y,s.z),o.lookAt(s.x+l[g],s.y,s.z)):m===1?(o.up.set(0,0,a[g]),o.position.set(s.x,s.y,s.z),o.lookAt(s.x,s.y+l[g],s.z)):(o.up.set(0,a[g],0),o.position.set(s.x,s.y,s.z),o.lookAt(s.x,s.y,s.z+l[g]));const _=this._cubeSize;this._setViewport(i,m*_,g>2?_:0,_,_),c.render(e,o)}c.autoClear=u,e.background=p}_textureToCubeUV(e,t){const n=this._renderer,i=e.mapping===Ki||e.mapping===Sr;i?this._cubemapMaterial===null&&(this._cubemapMaterial=Bx(e)):this._equirectMaterial===null&&(this._equirectMaterial=Ox(e));const s=i?this._cubemapMaterial:this._equirectMaterial;s.fragmentNode.value=e;const o=this._lodMeshes[0];o.material=s;const a=this._cubeSize;this._setViewport(t,0,0,3*a,2*a),n.setRenderTarget(t),n.render(o,Bl)}_applyPMREM(e){const t=this._renderer,n=t.autoClear;t.autoClear=!1;const i=this._lodMeshes.length;for(let s=1;s<i;s++)this._applyGGXFilter(e,s-1,s);t.autoClear=n}_applyGGXFilter(e,t,n){const i=this._renderer,s=this._pingPongRenderTarget,o=this._ggxMaterial,a=this._lodMeshes[n];a.material=o;const l=Rh.get(o),c=n/(this._lodMeshes.length-1),u=t/(this._lodMeshes.length-1),h=Math.sqrt(c*c-u*u),d=0+c*1.25,f=h*d,{_lodMax:p}=this,g=this._sizeLods[n],m=3*g*(n>p-Ss?n-p+Ss:0),_=4*(this._cubeSize-g);e.texture.frame=(e.texture.frame||0)+1,l.envMap.value=e.texture,l.roughness.value=f,l.mipInt.value=p-t,this._setViewport(s,m,_,3*g,2*g),i.setRenderTarget(s),i.render(a,Bl),s.texture.frame=(s.texture.frame||0)+1,l.envMap.value=s.texture,l.roughness.value=0,l.mipInt.value=p-n,this._setViewport(e,m,_,3*g,2*g),i.setRenderTarget(e),i.render(a,Bl)}_blur(e,t,n,i,s){const o=this._pingPongRenderTarget;this._halfBlur(e,o,t,n,i,"latitudinal",s),this._halfBlur(o,e,n,n,i,"longitudinal",s)}_halfBlur(e,t,n,i,s,o,a){const l=this._renderer,c=this._blurMaterial;o!=="latitudinal"&&o!=="longitudinal"&&ce("blur direction must be either latitudinal or longitudinal!");const u=3,h=this._lodMeshes[i];h.material=c;const d=Rh.get(c),f=this._sizeLods[n]-1,p=isFinite(s)?Math.PI/(2*f):2*Math.PI/(2*lo-1),g=s/p,m=isFinite(s)?1+Math.floor(u*g):lo;m>lo&&ae(`sigmaRadians, ${s}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${lo}`);const _=[];let x=0;for(let E=0;E<lo;++E){const v=E/g,w=Math.exp(-v*v/2);_.push(w),E===0?x+=w:E<m&&(x+=2*w)}for(let E=0;E<_.length;E++)_[E]=_[E]/x;e.texture.frame=(e.texture.frame||0)+1,d.envMap.value=e.texture,d.samples.value=m,d.weights.array=_,d.latitudinal.value=o==="latitudinal"?1:0,a&&(d.poleAxis.value=a);const{_lodMax:y}=this;d.dTheta.value=p,d.mipInt.value=y-n;const b=this._sizeLods[i],M=3*b*(i>y-Ss?i-y+Ss:0),S=4*(this._cubeSize-b);this._setViewport(t,M,S,3*b,2*b),l.setRenderTarget(t),l.render(h,Bl)}_setViewport(e,t,n,i,s){this._renderer.isWebGLRenderer?(e.viewport.set(t,e.height-s-n,i,s),e.scissor.set(t,e.height-s-n,i,s)):(e.viewport.set(t,n,i,s),e.scissor.set(t,n,i,s))}}function rF(r){const e=[],t=[],n=[];let i=r;const s=r-Ss+1+Ux.length;for(let o=0;o<s;o++){const a=Math.pow(2,i);e.push(a);let l=1/a;o>r-Ss?l=Ux[o-r+Ss-1]:o===0&&(l=0),t.push(l);const c=1/(a-2),u=-c,h=1+c,d=[u,u,h,u,h,h,u,u,h,h,u,h],f=6,p=6,g=3,m=2,_=1,x=new Float32Array(g*p*f),y=new Float32Array(m*p*f),b=new Float32Array(_*p*f);for(let S=0;S<f;S++){const E=S%3*2/3-1,v=S>2?0:-1,w=[E,v,0,E+2/3,v,0,E+2/3,v+1,0,E,v,0,E+2/3,v+1,0,E,v+1,0],N=nF[S];x.set(w,g*p*N),y.set(d,m*p*N);const C=[N,N,N,N,N,N];b.set(C,_*p*N)}const M=new An;M.setAttribute("position",new Bn(x,g)),M.setAttribute("uv",new Bn(y,m)),M.setAttribute("faceIndex",new Bn(b,_)),n.push(new _n(M,null)),i>Ss&&i--}return{lodMeshes:n,sizeLods:e,sigmas:t}}function Ix(r,e){const t={magFilter:Nt,minFilter:Nt,generateMipmaps:!1,type:tn,format:ln,colorSpace:yc},n=new ks(r,e,t);return n.texture.mapping=mo,n.texture.name="PMREM.cubeUv",n.texture.isPMREMTexture=!0,n.scissorTest=!0,n}function Qh(r){const e=new mn;return e.depthTest=!1,e.depthWrite=!1,e.blending=Pn,e.name=`PMREM_${r}`,e}function sF(r,e,t){const n=Pi(new Array(lo).fill(0)),i=qe(new P(0,1,0)),s=qe(0),o=J(lo),a=qe(0),l=qe(1),c=Vt(),u=qe(0),h=J(1/e),d=J(1/t),f=J(r),p={n:o,latitudinal:a,weights:n,poleAxis:i,outputDirection:Zh,dTheta:s,samples:l,envMap:c,mipInt:u,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:f},g=Qh("blur");return g.fragmentNode=jU({...p,latitudinal:a.equal(1)}),Rh.set(g,p),g}function oF(r,e,t){const n=Vt(),i=qe(0),s=qe(0),o=J(1/e),a=J(1/t),l=J(r),c={envMap:n,roughness:i,mipInt:s,CUBEUV_TEXEL_WIDTH:o,CUBEUV_TEXEL_HEIGHT:a,CUBEUV_MAX_MIP:l},u=Qh("ggx");return u.fragmentNode=QU({...c,N_immutable:Zh,GGX_SAMPLES:mt(JU)}),Rh.set(u,c),u}function Bx(r){const e=Qh("cubemap");return e.fragmentNode=li(r,Zh),e}function Ox(r){const e=Qh("equirect");return e.fragmentNode=Vt(r,tb(Zh),0),e}const kx=new WeakMap;function aF(r){const e=Math.log2(r)-2,t=1/r;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:t,maxMip:e}}function lF(r,e,t){const n=cF(e);let i=n.get(r);if((i!==void 0?i.pmremVersion:-1)!==r.pmremVersion){const o=r.image;if(r.isCubeTexture)if(hF(o))i=t.fromCubemap(r,i);else return null;else if(dF(o))i=t.fromEquirectangular(r,i);else return null;i.pmremVersion=r.pmremVersion,n.set(r,i)}return i.texture}function cF(r){let e=kx.get(r);return e===void 0&&(e=new WeakMap,kx.set(r,e)),e}class uF extends xn{static get type(){return"PMREMNode"}constructor(e,t=null,n=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=n,this._generator=null;const i=new fn;i.isRenderTargetTexture=!0,this._texture=Vt(i),this._width=qe(0),this._height=qe(0),this._maxMip=qe(0),this.updateBeforeType=Ze.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=aF(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(e){let t=this._pmrem;const n=t?t.pmremVersion:-1,i=this._value;n!==i.pmremVersion&&(i.isPMREMTexture===!0?t=i:t=lF(i,e.renderer,this._generator),t!==null&&(this._pmrem=t,this.updateFromTexture(t)))}setup(e){this._generator===null&&(this._generator=new iF(e.renderer)),this.updateBefore(e);let t=this.uvNode;t===null&&e.context.getUV&&(t=e.context.getUV(this,e)),t=Iv.mul(te(t.x,t.y.negate(),t.z));let n=this.levelNode;return n===null&&e.context.getTextureLevel&&(n=e.context.getTextureLevel(this)),qU(this._texture,t,n,this._width,this._height,this._maxMip)}dispose(){super.dispose(),this._generator!==null&&this._generator.dispose()}}function hF(r){if(r==null)return!1;let e=0;const t=6;for(let n=0;n<t;n++)r[n]!==void 0&&e++;return e===t}function dF(r){return r==null?!1:r.height>0}const fb=It(uF).setParameterLength(1,3),Gx=new WeakMap;class fF extends gl{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let n=this.envNode;if(n.isTextureNode||n.isMaterialReferenceNode){const h=n.isTextureNode?n.value:t[n.property],d=this._getPMREMNodeCache(e.renderer);let f=d.get(h);f===void 0&&(f=fb(h),d.set(h,f)),n=f}const s=t.useAnisotropy===!0||t.anisotropy>0?kD:vt,o=n.context(Vx(Wr,s)).mul(ff),a=n.context(pF(ml)).mul(Math.PI).mul(ff),l=nc(o),c=nc(a);e.context.radiance.addAssign(l),e.context.iblIrradiance.addAssign(c);const u=e.context.lightingModel.clearcoatRadiance;if(u){const h=n.context(Vx(ec,ao)).mul(ff),d=nc(h);u.addAssign(d)}}_getPMREMNodeCache(e){let t=Gx.get(e);return t===void 0&&(t=new WeakMap,Gx.set(e,t)),t}}const Vx=(r,e)=>{let t=null;return{getUV:()=>(t===null&&(t=$t.negate().reflect(e),t=gv(r).mix(t,e).normalize(),t=t.transformDirection(es)),t),getTextureLevel:()=>r}},pF=r=>({getUV:()=>r,getTextureLevel:()=>J(1)}),mF=new cy;class pb extends mn{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(mF),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t===null&&e.environmentNode&&(t=e.environmentNode),t?new fF(t):null}setupLightingModel(){return new db}setupSpecular(){const e=Dt(te(.04),Pt.rgb,bs);vo.assign(te(.04)),ha.assign(e),da.assign(1)}setupVariants(){const e=this.metalnessNode?J(this.metalnessNode):JD;bs.assign(e);let t=this.roughnessNode?J(this.roughnessNode):QD;t=ab({roughness:t}),Wr.assign(t),this.setupSpecular(),ca.assign(Pt.rgb.mul(e.oneMinus()))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const gF=new cM;class _F extends pb{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(gF),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||this.clearcoatNode!==null}get useIridescence(){return this.iridescence>0||this.iridescenceNode!==null}get useSheen(){return this.sheen>0||this.sheenNode!==null}get useAnisotropy(){return this.anisotropy>0||this.anisotropyNode!==null}get useTransmission(){return this.transmission>0||this.transmissionNode!==null}get useDispersion(){return this.dispersion>0||this.dispersionNode!==null}setupSpecular(){const e=this.iorNode?J(this.iorNode):fL;uh.assign(e),vo.assign(Qa(mv(uh.sub(1).div(uh.add(1))).mul(ZD),te(1)).mul(dx)),ha.assign(Dt(vo,Pt.rgb,bs)),da.assign(Dt(dx,1,bs))}setupLightingModel(){return new db(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const t=this.clearcoatNode?J(this.clearcoatNode):tL,n=this.clearcoatRoughnessNode?J(this.clearcoatRoughnessNode):nL;gp.assign(t),ec.assign(ab({roughness:n}))}if(this.useSheen){const t=this.sheenNode?te(this.sheenNode):sL,n=this.sheenRoughnessNode?J(this.sheenRoughnessNode):oL;Ri.assign(t),ro.assign(n)}if(this.useIridescence){const t=this.iridescenceNode?J(this.iridescenceNode):lL,n=this.iridescenceIORNode?J(this.iridescenceIORNode):cL,i=this.iridescenceThicknessNode?J(this.iridescenceThicknessNode):uL;Fm.assign(t),_p.assign(n),xp.assign(i)}if(this.useAnisotropy){const t=(this.anisotropyNode?ke(this.anisotropyNode):aL).toVar();to.assign(t.length()),Ft(to.equal(0),()=>{t.assign(ke(1,0))}).Else(()=>{t.divAssign(ke(to)),to.assign(to.saturate())}),yp.assign(to.pow2().mix(Wr.pow2(),1)),ch.assign($l[0].mul(t.x).add($l[1].mul(t.y))),va.assign($l[1].mul(t.x).sub($l[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?J(this.transmissionNode):hL,n=this.thicknessNode?J(this.thicknessNode):dL,i=this.attenuationDistanceNode?J(this.attenuationDistanceNode):pL,s=this.attenuationColorNode?te(this.attenuationColorNode):mL;if(bp.assign(t),nv.assign(n),iv.assign(i),rv.assign(s),this.useDispersion){const o=this.dispersionNode?J(this.dispersionNode):bL;sv.assign(o)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?te(this.clearcoatNormalNode):iL}setup(e){e.context.setupClearcoatNormal=()=>ba(this.setupClearcoatNormal(e),"NORMAL","vec3"),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.iorNode=e.iorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}const xF=re(({normal:r,lightDirection:e,builder:t})=>{const n=r.dot(e),i=ke(n.mul(.5).add(.5),0);if(t.material.gradientMap){const s=ms("gradientMap","texture").context({getUV:()=>i});return te(s.r)}else{const s=i.fwidth().mul(.5);return Dt(te(.7),te(1),Qr(J(.7).sub(s.x),J(.7).add(s.x),i.x))}});class yF extends Yh{direct({lightDirection:e,lightColor:t,reflectedLight:n},i){const s=xF({normal:Uv,lightDirection:e,builder:i}).mul(t);n.directDiffuse.addAssign(s.mul(el({diffuseColor:Pt.rgb})))}indirect(e){const{ambientOcclusion:t,irradiance:n,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(n.mul(el({diffuseColor:Pt}))),i.indirectDiffuse.mulAssign(t)}}const vF=new hM;class bF extends mn{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(vF),this.setValues(e)}setupLightingModel(){return new yF}}const SF=re(()=>{const r=te($t.z,0,$t.x.negate()).normalize(),e=$t.cross(r);return ke(r.dot(vt),e.dot(vt)).mul(.495).add(.5)}).once(["NORMAL","VERTEX"])().toVar("matcapUV"),TF=new mM;class MF extends mn{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(TF),this.setValues(e)}setupVariants(e){const t=SF;let n;e.material.matcap?n=ms("matcap","texture").context({getUV:()=>t}):n=te(Dt(.2,.8,t.y)),Pt.rgb.mulAssign(n.rgb)}}class EF extends xn{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}generateNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:n}=this;if(this.getNodeType(e)==="vec2"){const s=t.cos(),o=t.sin();return Um(s,o,o.negate(),s).mul(n)}else{const s=t,o=uo(et(1,0,0,0),et(0,fr(s.x),vi(s.x).negate(),0),et(0,vi(s.x),fr(s.x),0),et(0,0,0,1)),a=uo(et(fr(s.y),0,vi(s.y),0),et(0,1,0,0),et(vi(s.y).negate(),0,fr(s.y),0),et(0,0,0,1)),l=uo(et(fr(s.z),vi(s.z).negate(),0,0),et(vi(s.z),fr(s.z),0,0),et(0,0,1,0),et(0,0,0,1));return o.mul(a).mul(l).mul(et(n,1)).xyz}}}const mb=It(EF).setParameterLength(2),AF=new mm;class gb extends mn{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.transparent=!0,this.setDefaultValues(AF),this.setValues(e)}setupPositionView(e){const{object:t,camera:n}=e,{positionNode:i,rotationNode:s,scaleNode:o,sizeAttenuation:a}=this,l=Hc.mul(te(i||0));let c=ke(To[0].xyz.length(),To[1].xyz.length());o!==null&&(c=c.mul(ke(o))),n.isPerspectiveCamera&&a===!1&&(c=c.mul(l.z.negate()));let u=jh.xy;if(t.center&&t.center.isVector2===!0){const f=IP("center","vec2",t);u=u.sub(f.sub(.5))}u=u.mul(c);const h=J(s||rL),d=mb(u,h);return et(l.xy.add(d),l.zw)}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}const wF=new VT,RF=new pe;class CF extends gb{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.sizeNode=null,this.isPointsNodeMaterial=!0,this.setDefaultValues(wF),this.setValues(e)}setupPositionView(){const{positionNode:e}=this;return Hc.mul(te(e||Tn)).xyz}setupVertexSprite(e){const{material:t,camera:n}=e,{rotationNode:i,scaleNode:s,sizeNode:o,sizeAttenuation:a}=this;let l=super.setupVertex(e);if(t.isNodeMaterial!==!0)return l;let c=o!==null?ke(o):vL;c=c.mul(hD),n.isPerspectiveCamera&&a===!0&&(c=c.mul(NF.div(dn.z.negate()))),s&&s.isNode&&(c=c.mul(ke(s)));let u=jh.xy;if(i&&i.isNode){const h=J(i);u=mb(u,h)}return u=u.mul(c),u=u.div(dD.div(2)),u=u.mul(l.w),l=l.add(et(u,0,0)),l}setupVertex(e){return e.object.isPoints?super.setupVertex(e):this.setupVertexSprite(e)}get alphaToCoverage(){return this._useAlphaToCoverage}set alphaToCoverage(e){this._useAlphaToCoverage!==e&&(this._useAlphaToCoverage=e,this.needsUpdate=!0)}}const NF=qe(1).onFrameUpdate(function({renderer:r}){const e=r.getSize(RF);this.value=.5*e.y});class PF extends Yh{constructor(){super(),this.shadowNode=J(1).toVar("shadowMask")}direct({lightNode:e}){e.shadowNode!==null&&this.shadowNode.mulAssign(e.shadowNode)}finish({context:e}){Pt.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(Pt.rgb)}}const DF=new rM;class LF extends mn{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.transparent=!0,this.setDefaultValues(DF),this.setValues(e)}setupLightingModel(){return new PF}}Ns("vec3");Ns("vec3");Ns("vec3");class UF{constructor(e,t,n){this.renderer=e,this.nodes=t,this.info=n,this._context=typeof self<"u"?self:null,this._animationLoop=null,this._requestId=null}start(){const e=(t,n)=>{this._requestId=this._context.requestAnimationFrame(e),this.info.autoReset===!0&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,this.renderer._inspector.begin(),this._animationLoop!==null&&this._animationLoop(t,n),this.renderer._inspector.finish()};e()}stop(){this._context!==null&&this._context.cancelAnimationFrame(this._requestId),this._requestId=null}getAnimationLoop(){return this._animationLoop}setAnimationLoop(e){this._animationLoop=e}getContext(){return this._context}setContext(e){this._context=e}dispose(){this.stop()}}class Bs{constructor(){this.weakMaps={}}_getWeakMap(e){const t=e.length;let n=this.weakMaps[t];return n===void 0&&(n=new WeakMap,this.weakMaps[t]=n),n}get(e){let t=this._getWeakMap(e);for(let n=0;n<e.length-1;n++)if(t=t.get(e[n]),t===void 0)return;return t.get(e[e.length-1])}set(e,t){let n=this._getWeakMap(e);for(let i=0;i<e.length-1;i++){const s=e[i];n.has(s)===!1&&n.set(s,new WeakMap),n=n.get(s)}return n.set(e[e.length-1],t),this}delete(e){let t=this._getWeakMap(e);for(let n=0;n<e.length-1;n++)if(t=t.get(e[n]),t===void 0)return!1;return t.delete(e[e.length-1])}}let FF=0;function IF(r){const e=Object.keys(r);let t=Object.getPrototypeOf(r);for(;t;){const n=Object.getOwnPropertyDescriptors(t);for(const i in n)if(n[i]!==void 0){const s=n[i];s&&typeof s.get=="function"&&e.push(i)}t=Object.getPrototypeOf(t)}return e}class BF{constructor(e,t,n,i,s,o,a,l,c,u){this.id=FF++,this._nodes=e,this._geometries=t,this.renderer=n,this.object=i,this.material=s,this.scene=o,this.camera=a,this.lightsNode=l,this.context=c,this.geometry=i.geometry,this.version=s.version,this.drawRange=null,this.attributes=null,this.attributesId=null,this.pipeline=null,this.group=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.clippingContext=u,this.clippingContextCacheKey=u!==null?u.cacheKey:"",this.initialNodesCacheKey=this.getDynamicCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=null,this._monitor=null,this.onDispose=null,this.isRenderObject=!0,this.onMaterialDispose=()=>{this.dispose()},this.onGeometryDispose=()=>{this.attributes=null,this.attributesId=null},this.material.addEventListener("dispose",this.onMaterialDispose),this.geometry.addEventListener("dispose",this.onGeometryDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return this.clippingContext===null||this.clippingContext.cacheKey===this.clippingContextCacheKey?!1:(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return this.material.hardwareClipping===!0?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().observer)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getBindingGroup(e){for(const t of this.getBindings())if(t.name===e)return t}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getIndirectOffset(){return this._geometries.getIndirectOffset(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null,this.attributesId=null}getAttributes(){if(this.attributes!==null)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,n=[],i=new Set,s={};for(const o of e){let a;if(o.node&&o.node.attribute?a=o.node.attribute:(a=t.getAttribute(o.name),s[o.name]=a.id),a===void 0)continue;n.push(a);const l=a.isInterleavedBufferAttribute?a.data:a;i.add(l)}return this.attributes=n,this.attributesId=s,this.vertexBuffers=Array.from(i.values()),n}getVertexBuffers(){return this.vertexBuffers===null&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:n,group:i,drawRange:s}=this,o=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),a=this.getIndex(),l=a!==null;let c=1;if(n.isInstancedBufferGeometry===!0?c=n.instanceCount:e.count!==void 0&&(c=Math.max(0,e.count)),c===0)return null;if(o.instanceCount=c,e.isBatchedMesh===!0)return o;let u=1;t.wireframe===!0&&!e.isPoints&&!e.isLineSegments&&!e.isLine&&!e.isLineLoop&&(u=2);let h=s.start*u,d=(s.start+s.count)*u;i!==null&&(h=Math.max(h,i.start*u),d=Math.min(d,(i.start+i.count)*u));const f=n.attributes.position;let p=1/0;l?p=a.count:f!=null&&(p=f.count),h=Math.max(h,0),d=Math.min(d,p);const g=d-h;return g<0||g===1/0?null:(o.vertexCount=g,o.firstVertex=h,o)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const n of Object.keys(e.attributes).sort()){const i=e.attributes[n];t+=n+",",i.data&&(t+=i.data.stride+","),i.offset&&(t+=i.offset+","),i.itemSize&&(t+=i.itemSize+","),i.normalized&&(t+="n,")}for(const n of Object.keys(e.morphAttributes).sort()){const i=e.morphAttributes[n];t+="morph-"+n+",";for(let s=0,o=i.length;s<o;s++){const a=i[s];t+=a.id+","}}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t,renderer:n}=this;let i=t.customProgramCacheKey();for(const s of IF(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(s))continue;const o=t[s];let a;if(o!==null){const l=typeof o;l==="number"?a=o!==0?"1":"0":l==="object"?(a="{",o.isTexture&&(a+=o.mapping,n.backend.isWebGPUBackend===!0&&(a+=o.magFilter,a+=o.minFilter,a+=o.wrapS,a+=o.wrapT,a+=o.wrapR)),a+="}"):a=String(o)}else a=String(o);i+=a+","}return i+=this.clippingContextCacheKey+",",e.geometry&&(i+=this.getGeometryCacheKey()),e.skeleton&&(i+=e.skeleton.bones.length+","),e.isBatchedMesh&&(i+=e._matricesTexture.uuid+",",e._colorsTexture!==null&&(i+=e._colorsTexture.uuid+",")),(e.isInstancedMesh||e.count>1||Array.isArray(e.morphTargetInfluences))&&(i+=e.uuid+","),i+=this.context.id+",",i+=e.receiveShadow+",",cl(i)}get needsGeometryUpdate(){if(this.geometry.id!==this.object.geometry.id)return!0;if(this.attributes!==null){const e=this.attributesId;for(const t in e){const n=this.geometry.getAttribute(t);if(n===void 0||e[t]!==n.id)return!0}}return!1}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=0;return this.material.isShadowPassMaterial!==!0&&(e=this._nodes.getCacheKey(this.scene,this.lightsNode)),this.camera.isArrayCamera&&(e=Ql(e,this.camera.cameras.length)),this.object.receiveShadow&&(e=Ql(e,1)),e=Ql(e,this.renderer.contextNode.id,this.renderer.contextNode.version),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.geometry.removeEventListener("dispose",this.onGeometryDispose),this.onDispose()}}const ar=[];class OF{constructor(e,t,n,i,s,o){this.renderer=e,this.nodes=t,this.geometries=n,this.pipelines=i,this.bindings=s,this.info=o,this.chainMaps={}}get(e,t,n,i,s,o,a,l){const c=this.getChainMap(l);ar[0]=e,ar[1]=t,ar[2]=o,ar[3]=s;let u=c.get(ar);return u===void 0?(u=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,n,i,s,o,a,l),c.set(ar,u)):(u.camera=i,u.updateClipping(a),u.needsGeometryUpdate&&u.setGeometry(e.geometry),(u.version!==t.version||u.needsUpdate)&&(u.initialCacheKey!==u.getCacheKey()?(u.dispose(),u=this.get(e,t,n,i,s,o,a,l)):u.version=t.version)),ar[0]=null,ar[1]=null,ar[2]=null,ar[3]=null,u}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Bs)}dispose(){this.chainMaps={}}createRenderObject(e,t,n,i,s,o,a,l,c,u,h){const d=this.getChainMap(h),f=new BF(e,t,n,i,s,o,a,l,c,u);return f.onDispose=()=>{this.pipelines.delete(f),this.bindings.deleteForRender(f),this.nodes.delete(f),d.delete(f.getChainArray())},f}}class Gs{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}delete(e){let t=null;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Fi={VERTEX:1,INDEX:2,STORAGE:3,INDIRECT:4},gs=16,kF=211,GF=212;class VF extends Gs{constructor(e,t){super(),this.backend=e,this.info=t}delete(e){const t=super.delete(e);return t!==null&&(this.backend.destroyAttribute(e),this.info.destroyAttribute(e)),t}update(e,t){const n=this.get(e);if(n.version===void 0)t===Fi.VERTEX?(this.backend.createAttribute(e),this.info.createAttribute(e)):t===Fi.INDEX?(this.backend.createIndexAttribute(e),this.info.createIndexAttribute(e)):t===Fi.STORAGE?(this.backend.createStorageAttribute(e),this.info.createStorageAttribute(e)):t===Fi.INDIRECT&&(this.backend.createIndirectStorageAttribute(e),this.info.createIndirectStorageAttribute(e)),n.version=this._getBufferAttribute(e).version;else{const i=this._getBufferAttribute(e);(n.version<i.version||i.usage===mh)&&(this.backend.updateAttribute(e),n.version=i.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}function _b(r){return r.index!==null?r.index.version:r.attributes.position.version}function xb(r){return r.index!==null?r.index.id:r.attributes.position.id}function zx(r){const e=[],t=r.index,n=r.attributes.position;if(t!==null){const s=t.array;for(let o=0,a=s.length;o<a;o+=3){const l=s[o+0],c=s[o+1],u=s[o+2];e.push(l,c,c,u,u,l)}}else{const s=n.array;for(let o=0,a=s.length/3-1;o<a;o+=3){const l=o+0,c=o+1,u=o+2;e.push(l,c,c,u,u,l)}}const i=new(n.count>=65535?fm:dm)(e,1);return i.version=_b(r),i.__id=xb(r),i}class zF extends Gs{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap,this._geometryDisposeListeners=new Map}has(e){const t=e.geometry;return super.has(t)&&this.get(t).initialized===!0}updateForRender(e){this.has(e)===!1&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry,n=this.get(t);n.initialized=!0,this.info.memory.geometries++;const i=()=>{this.info.memory.geometries--;const s=t.index,o=e.getAttributes();s!==null&&this.attributes.delete(s);for(const l of o)this.attributes.delete(l);const a=this.wireframes.get(t);a!==void 0&&this.attributes.delete(a),t.removeEventListener("dispose",i),this._geometryDisposeListeners.delete(t)};t.addEventListener("dispose",i),this._geometryDisposeListeners.set(t,i)}updateAttributes(e){const t=e.getAttributes();for(const s of t)s.isStorageBufferAttribute||s.isStorageInstancedBufferAttribute?this.updateAttribute(s,Fi.STORAGE):this.updateAttribute(s,Fi.VERTEX);const n=this.getIndex(e);n!==null&&this.updateAttribute(n,Fi.INDEX);const i=e.geometry.indirect;i!==null&&this.updateAttribute(i,Fi.INDIRECT)}updateAttribute(e,t){const n=this.info.render.calls;e.isInterleavedBufferAttribute?this.attributeCall.get(e)===void 0?(this.attributes.update(e,t),this.attributeCall.set(e,n)):this.attributeCall.get(e.data)!==n&&(this.attributes.update(e,t),this.attributeCall.set(e.data,n),this.attributeCall.set(e,n)):this.attributeCall.get(e)!==n&&(this.attributes.update(e,t),this.attributeCall.set(e,n))}getIndirect(e){return e.geometry.indirect}getIndirectOffset(e){return e.geometry.indirectOffset}getIndex(e){const{geometry:t,material:n}=e;let i=t.index;if(n.wireframe===!0){const s=this.wireframes;let o=s.get(t);o===void 0?(o=zx(t),s.set(t,o)):(o.version!==_b(t)||o.__id!==xb(t))&&(this.attributes.delete(o),o=zx(t),s.set(t,o)),i=o}return i}dispose(){for(const[e,t]of this._geometryDisposeListeners.entries())e.removeEventListener("dispose",t);this._geometryDisposeListeners.clear()}}class HF{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0},this.compute={calls:0,frameCalls:0,timestamp:0},this.memory={geometries:0,textures:0,attributes:0,indexAttributes:0,storageAttributes:0,indirectStorageAttributes:0,readbackBuffers:0,programs:0,renderTargets:0,total:0,texturesSize:0,attributesSize:0,indexAttributesSize:0,storageAttributesSize:0,indirectStorageAttributesSize:0,readbackBuffersSize:0,programsSize:0},this.memoryMap=new Map}update(e,t,n){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=n*(t/3):e.isPoints?this.render.points+=n*t:e.isLineSegments?this.render.lines+=n*(t/2):e.isLine?this.render.lines+=n*(t-1):ce("WebGPUInfo: Unknown object type.")}reset(){this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0;for(const e in this.memory)this.memory[e]=0;this.memoryMap.clear()}createTexture(e){const t=this._getTextureMemorySize(e);this.memoryMap.set(e,t),this.memory.textures++,this.memory.total+=t,this.memory.texturesSize+=t}destroyTexture(e){const t=this.memoryMap.get(e)||0;this.memoryMap.delete(e),this.memory.textures--,this.memory.total-=t,this.memory.texturesSize-=t}_createAttribute(e,t){const n=this._getAttributeMemorySize(e);this.memoryMap.set(e,{size:n,type:t}),this.memory[t]++,this.memory.total+=n,this.memory[t+"Size"]+=n}createAttribute(e){this._createAttribute(e,"attributes")}createIndexAttribute(e){this._createAttribute(e,"indexAttributes")}createStorageAttribute(e){this._createAttribute(e,"storageAttributes")}createIndirectStorageAttribute(e){this._createAttribute(e,"indirectStorageAttributes")}destroyAttribute(e){const t=this.memoryMap.get(e);t&&(this.memoryMap.delete(e),this.memory[t.type]--,this.memory.total-=t.size,this.memory[t.type+"Size"]-=t.size)}createReadbackBuffer(e){const t=e.maxByteLength;this.memoryMap.set(e,{size:t,type:"readbackBuffers"}),this.memory.readbackBuffers++,this.memory.total+=t,this.memory.readbackBuffersSize+=t}destroyReadbackBuffer(e){const{size:t}=this.memoryMap.get(e);this.memoryMap.delete(e),this.memory.readbackBuffers--,this.memory.total-=t,this.memory.readbackBuffersSize-=t}createProgram(e){const t=e.code.length;this.memoryMap.set(e,t),this.memory.programs++,this.memory.total+=t,this.memory.programsSize+=t}destroyProgram(e){const t=this.memoryMap.get(e)||0;this.memoryMap.delete(e),this.memory.programs--,this.memory.total-=t,this.memory.programsSize-=t}_getTextureMemorySize(e){if(e.isCompressedTexture)return 1;let t=1;e.type===Ts||e.type===Xt?t=1:e.type===Ms||e.type===Li||e.type===tn?t=2:(e.type===Sn||e.type===Ct||e.type===Qt)&&(t=4);let n=4;e.format===Fh||e.format===il||e.format===Eo||e.format===Dn||e.format===qn?n=1:e.format===In||e.format===Ao?n=2:(e.format===nl||e.format===q0)&&(n=3);let i=t*n;e.type===Pc||e.type===Dc?i=2:(e.type===di||e.type===Lc||e.type===Uc)&&(i=4);const s=e.width||1,o=e.height||1,a=e.isCubeTexture?6:e.depth||1;let l=s*o*a*i;const c=e.mipmaps;if(c&&c.length>0){let u=0;for(let h=0;h<c.length;h++){const d=c[h];if(d.data)u+=d.data.byteLength;else{const f=d.width||Math.max(1,s>>h),p=d.height||Math.max(1,o>>h);u+=f*p*a*i}}l+=u}else e.generateMipmaps&&(l=l*1.333);return Math.round(l)}_getAttributeMemorySize(e){return e.isInterleavedBufferAttribute&&(e=e.data),e.array?e.array.byteLength:e.count&&e.itemSize?e.count*e.itemSize*4:0}}class yb{constructor(e){this.cacheKey=e,this.usedTimes=0}}class WF extends yb{constructor(e,t,n){super(e),this.vertexProgram=t,this.fragmentProgram=n}}class $F extends yb{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let XF=0;class Af{constructor(e,t,n,i=null,s=null){this.id=XF++,this.code=e,this.stage=t,this.name=n,this.transforms=i,this.attributes=s,this.usedTimes=0}}class qF extends Gs{constructor(e,t,n){super(),this.backend=e,this.nodes=t,this.info=n,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:n}=this,i=this.get(e);if(this._needsComputeUpdate(e)){const s=i.pipeline;s&&(s.usedTimes--,s.computeProgram.usedTimes--);const o=this.nodes.getForCompute(e);let a=this.programs.compute.get(o.computeShader);a===void 0&&(s&&s.computeProgram.usedTimes===0&&this._releaseProgram(s.computeProgram),a=new Af(o.computeShader,"compute",e.name,o.transforms,o.nodeAttributes),this.programs.compute.set(o.computeShader,a),n.createProgram(a),this.info.createProgram(a));const l=this._getComputeCacheKey(e,a);let c=this.caches.get(l);c===void 0&&(s&&s.usedTimes===0&&this._releasePipeline(s),c=this._getComputePipeline(e,a,l,t)),c.usedTimes++,a.usedTimes++,i.version=e.version,i.pipeline=c}return i.pipeline}getForRender(e,t=null){const{backend:n}=this,i=this.get(e);if(this._needsRenderUpdate(e)){const s=i.pipeline;s&&(s.usedTimes--,s.vertexProgram.usedTimes--,s.fragmentProgram.usedTimes--);const o=e.getNodeBuilderState(),a=e.material?e.material.name:"";let l=this.programs.vertex.get(o.vertexShader);l===void 0&&(s&&s.vertexProgram.usedTimes===0&&this._releaseProgram(s.vertexProgram),l=new Af(o.vertexShader,"vertex",a),this.programs.vertex.set(o.vertexShader,l),n.createProgram(l),this.info.createProgram(l));let c=this.programs.fragment.get(o.fragmentShader);c===void 0&&(s&&s.fragmentProgram.usedTimes===0&&this._releaseProgram(s.fragmentProgram),c=new Af(o.fragmentShader,"fragment",a),this.programs.fragment.set(o.fragmentShader,c),n.createProgram(c),this.info.createProgram(c));const u=this._getRenderCacheKey(e,l,c);let h=this.caches.get(u);h===void 0?(s&&s.usedTimes===0&&this._releasePipeline(s),h=this._getRenderPipeline(e,l,c,u,t)):e.pipeline=h,h.usedTimes++,l.usedTimes++,c.usedTimes++,i.pipeline=h}return i.pipeline}isReady(e){const n=this.get(e).pipeline;if(n===void 0)return!1;const i=this.backend.get(n);return i.pipeline!==void 0&&i.pipeline!==null}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,t.usedTimes===0&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,t.computeProgram.usedTimes===0&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,t.vertexProgram.usedTimes===0&&this._releaseProgram(t.vertexProgram),t.fragmentProgram.usedTimes===0&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,n,i){n=n||this._getComputeCacheKey(e,t);let s=this.caches.get(n);return s===void 0&&(s=new $F(n,t),this.caches.set(n,s),this.backend.createComputePipeline(s,i)),s}_getRenderPipeline(e,t,n,i,s){i=i||this._getRenderCacheKey(e,t,n);let o=this.caches.get(i);return o===void 0&&(o=new WF(i,t,n),this.caches.set(i,o),e.pipeline=o,this.backend.createRenderPipeline(e,s)),o}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,n){return t.id+","+n.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,n=e.stage;this.programs[n].delete(t),this.info.destroyProgram(e)}_needsComputeUpdate(e){const t=this.get(e);return t.pipeline===void 0||t.version!==e.version}_needsRenderUpdate(e){return this.get(e).pipeline===void 0||this.backend.needsRenderUpdate(e)}}class jF extends Gs{constructor(e,t,n,i,s,o){super(),this.backend=e,this.textures=n,this.pipelines=s,this.attributes=i,this.nodes=t,this.info=o,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const n of t){const i=this.get(n);i.bindGroup===void 0&&(this._init(n),this.backend.createBindings(n,t,0),i.bindGroup=n)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const n of t){const i=this.get(n);i.bindGroup===void 0&&(this._init(n),this.backend.createBindings(n,t,0),i.bindGroup=n)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}deleteForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const n of t)this.backend.deleteBindGroupData(n),this.delete(n)}deleteForRender(e){const t=e.getBindings();for(const n of t)this.backend.deleteBindGroupData(n),this.delete(n)}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isSampler)this.textures.updateSampler(t.texture);else if(t.isStorageBuffer){const n=t.attribute,i=n.isIndirectStorageBufferAttribute?Fi.INDIRECT:Fi.STORAGE;this.attributes.update(n,i)}}_update(e,t){const{backend:n}=this;let i=!1,s=!0,o=0,a=0;for(const l of e.bindings)if(this.nodes.updateGroup(l)!==!1){if(l.isStorageBuffer){const u=l.attribute,h=u.isIndirectStorageBufferAttribute?Fi.INDIRECT:Fi.STORAGE,d=n.get(l);this.attributes.update(u,h),d.attribute!==u&&(d.attribute=u,i=!0)}if(l.isUniformBuffer)l.update()&&n.updateBinding(l);else if(l.isSampledTexture){const u=l.update(),h=l.texture,d=this.textures.get(h);if(u&&(this.textures.updateTexture(h),l.generation!==d.generation&&(l.generation=d.generation,i=!0),d.bindGroups.add(e)),n.get(h).externalTexture!==void 0||d.isDefaultTexture?s=!1:(o=o*10+h.id,a+=h.version),h.isStorageTexture===!0&&h.mipmapsAutoUpdate===!0){const p=this.get(h);l.store===!0?p.needsMipmap=!0:this.textures.needsMipmaps(h)&&p.needsMipmap===!0&&(this.backend.generateMipmaps(h),p.needsMipmap=!1)}}else if(l.isSampler&&l.update()){const h=this.textures.updateSampler(l.texture);l.samplerKey!==h&&(l.samplerKey=h,i=!0)}l.isBuffer&&l.updateRanges.length>0&&l.clearUpdateRanges()}i===!0&&this.backend.updateBindings(e,t,s?o:0,a)}}function YF(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.z!==e.z?r.z-e.z:r.id-e.id}function Hx(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.z!==e.z?e.z-r.z:r.id-e.id}function Wx(r){return(r.transmission>0||r.transmissionNode&&r.transmissionNode.isNode)&&r.side===Nn&&r.forceSinglePass===!1}class KF{constructor(e,t,n){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,n),this.lightsArray=[],this.scene=t,this.camera=n,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,n,i,s,o,a){let l=this.renderItems[this.renderItemsIndex];return l===void 0?(l={id:e.id,object:e,geometry:t,material:n,groupOrder:i,renderOrder:e.renderOrder,z:s,group:o,clippingContext:a},this.renderItems[this.renderItemsIndex]=l):(l.id=e.id,l.object=e,l.geometry=t,l.material=n,l.groupOrder=i,l.renderOrder=e.renderOrder,l.z=s,l.group=o,l.clippingContext=a),this.renderItemsIndex++,l}push(e,t,n,i,s,o,a){const l=this.getNextRenderItem(e,t,n,i,s,o,a);e.occlusionTest===!0&&this.occlusionQueryCount++,n.transparent===!0||n.transmission>0||n.transmissionNode&&n.transmissionNode.isNode||n.backdropNode&&n.backdropNode.isNode?(Wx(n)&&this.transparentDoublePass.push(l),this.transparent.push(l)):this.opaque.push(l)}unshift(e,t,n,i,s,o,a){const l=this.getNextRenderItem(e,t,n,i,s,o,a);n.transparent===!0||n.transmission>0||n.transmissionNode&&n.transmissionNode.isNode||n.backdropNode&&n.backdropNode.isNode?(Wx(n)&&this.transparentDoublePass.unshift(l),this.transparent.unshift(l)):this.opaque.unshift(l)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||YF),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||Hx),this.transparent.length>1&&this.transparent.sort(t||Hx)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){const n=this.renderItems[e];if(n.id===null)break;n.id=null,n.object=null,n.geometry=null,n.material=null,n.groupOrder=null,n.renderOrder=null,n.z=null,n.group=null,n.clippingContext=null}}}const ra=[];class ZF{constructor(e){this.lighting=e,this.lists=new Bs}get(e,t){const n=this.lists;ra[0]=e,ra[1]=t;let i=n.get(ra);return i===void 0&&(i=new KF(this.lighting,e,t),n.set(ra,i)),ra[0]=null,ra[1]=null,i}dispose(){this.lists=new Bs}}let QF=0;class JF{constructor(){this.id=QF++,this.mrt=null,this.color=!0,this.clearColor=!0,this.clearColorValue={r:0,g:0,b:0,a:1},this.depth=!0,this.clearDepth=!0,this.clearDepthValue=1,this.stencil=!1,this.clearStencil=!0,this.clearStencilValue=1,this.viewport=!1,this.viewportValue=new rt,this.scissor=!1,this.scissorValue=new rt,this.renderTarget=null,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.activeMipmapLevel=0,this.sampleCount=1,this.width=0,this.height=0,this.occlusionQueryCount=0,this.clippingContext=null,this.camera=null,this.isRenderContext=!0}getCacheKey(){return vb(this)}}function vb(r){const{textures:e,activeCubeFace:t,activeMipmapLevel:n}=r,i=[t,n];for(const s of e)i.push(s.id);return Gc(i)}class eI{constructor(e){this.renderer=e,this._renderContexts={}}get(e=null,t=null,n=0){let i;if(e===null)i="default";else{const l=e.texture.format,c=e.texture.type;i=`${e.textures.length}:${l}:${c}:${e.samples}:${e.depthBuffer}:${e.stencilBuffer}`}const s=t!==null?t.id:"default",o=i+"-"+s+"-"+n;let a=this._renderContexts[o];return a===void 0&&(a=new JF,a.mrt=t,this._renderContexts[o]=a),e!==null&&(a.sampleCount=e.samples===0?1:e.samples),a.clearDepthValue=this.renderer.getClearDepth(),a.clearStencilValue=this.renderer.getClearStencil(),a}dispose(){this._renderContexts={}}}const tI=new P;class nI extends Gs{constructor(e,t,n){super(),this.renderer=e,this.backend=t,this.info=n,this._htmlTextures=new Set}updateRenderTarget(e,t=0){const n=this.get(e),i=e.samples===0?1:e.samples,s=n.depthTextureMips||(n.depthTextureMips={}),o=e.textures,a=this.getSize(o[0]),l=a.width>>t,c=a.height>>t;let u=e.depthTexture||s[t];const h=e.depthBuffer===!0||e.stencilBuffer===!0;let d=!1;u===void 0&&h&&(u=new jn,u.format=e.stencilBuffer?qn:Dn,u.type=e.stencilBuffer?di:Ct,u.image.width=l,u.image.height=c,u.image.depth=a.depth,u.renderTarget=e,u.isArrayTexture=e.multiview===!0&&a.depth>1,s[t]=u),(n.width!==a.width||a.height!==n.height)&&(d=!0,u&&(u.needsUpdate=!0,u.image.width=l,u.image.height=c,u.image.depth=u.isArrayTexture?u.image.depth:1)),n.width=a.width,n.height=a.height,n.textures=o,n.depthTexture=u||null,n.depth=e.depthBuffer,n.stencil=e.stencilBuffer,n.renderTarget=e,n.sampleCount!==i&&(d=!0,u&&(u.needsUpdate=!0),n.sampleCount=i);const f={sampleCount:i};if(e.isXRRenderTarget!==!0){for(let p=0;p<o.length;p++){const g=o[p];d&&(g.needsUpdate=!0),this.updateTexture(g,f)}u&&this.updateTexture(u,f)}n.initialized!==!0&&(n.initialized=!0,this.info.memory.renderTargets++,n.onDispose=()=>{this._destroyRenderTarget(e)},e.addEventListener("dispose",n.onDispose))}updateTexture(e,t={}){const n=this.get(e);if(n.initialized===!0&&n.version===e.version)return;const i=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,s=this.backend;if(i&&n.initialized===!0&&s.destroyTexture(e),e.isFramebufferTexture){const c=this.renderer.getRenderTarget();c?e.type=c.texture.type:e.type=Xt}if(e.isHTMLTexture&&e.image){const c=this.renderer.domElement;if("requestPaint"in c){if(c.hasAttribute("layoutsubtree")||c.setAttribute("layoutsubtree","true"),e.image.parentNode!==c&&c.appendChild(e.image),this._htmlTextures.size===0){const u=this._htmlTextures;c.onpaint=h=>{const d=h&&h.changedElements;for(const f of u)(!d||d.includes(f.image))&&(f.needsUpdate=!0)}}this._htmlTextures.add(e)}}const{width:o,height:a,depth:l}=this.getSize(e);if(t.width=o,t.height=a,t.depth=l,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,o,a):1,e.isCubeTexture&&e.mipmaps.length>0&&t.levels++,i||e.isStorageTexture===!0||e.isExternalTexture===!0)s.createTexture(e,t),n.generation=e.version;else if(e.version>0){const c=e.image;if(c===void 0)ae("Renderer: Texture marked for update but image is undefined.");else if(c.complete===!1)ae("Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const h=[];for(const d of e.images)h.push(d);t.images=h}else t.image=c;(n.isDefaultTexture===void 0||n.isDefaultTexture===!0)&&(s.createTexture(e,t),n.isDefaultTexture=!1,n.generation=e.version),e.source.dataReady===!0&&s.updateTexture(e,t);const u=e.isStorageTexture===!0&&e.mipmapsAutoUpdate===!1;t.needsMipmaps&&e.mipmaps.length===0&&!u&&s.generateMipmaps(e),e.onUpdate&&e.onUpdate(e)}}else s.createDefaultTexture(e),n.isDefaultTexture=!0,n.generation=e.version;n.initialized!==!0&&(n.initialized=!0,n.generation=e.version,n.bindGroups=new Set,this.info.createTexture(e),e.isVideoTexture&&Ye.enabled===!0&&Ye.getTransfer(e.colorSpace)!==Pe&&ae("WebGPURenderer: Video textures must use a color space with a sRGB transfer function, e.g. SRGBColorSpace."),n.onDispose=()=>{this._destroyTexture(e)},e.addEventListener("dispose",n.onDispose)),n.version=e.version}updateSampler(e){return this.backend.updateSampler(e)}getSize(e,t=tI){let n=e.images?e.images[0]:e.image;return n?(n.image!==void 0&&(n=n.image),e.isHTMLTexture?(t.width=n.offsetWidth||1,t.height=n.offsetHeight||1,t.depth=1):typeof HTMLVideoElement<"u"&&n instanceof HTMLVideoElement?(t.width=n.videoWidth||1,t.height=n.videoHeight||1,t.depth=1):typeof VideoFrame<"u"&&n instanceof VideoFrame?(t.width=n.displayWidth||1,t.height=n.displayHeight||1,t.depth=1):(t.width=n.width||1,t.height=n.height||1,t.depth=e.isCubeTexture?6:n.depth||1)):t.width=t.height=t.depth=1,t}getMipLevels(e,t,n){let i;return e.mipmaps.length>0?i=e.mipmaps.length:e.isCompressedTexture===!0?i=1:i=Math.floor(Math.log2(Math.max(t,n)))+1,i}needsMipmaps(e){return e.generateMipmaps===!0||e.mipmaps.length>0}_destroyRenderTarget(e){if(this.has(e)===!0){const t=this.get(e),n=t.textures,i=t.depthTexture;e.removeEventListener("dispose",t.onDispose);for(let s=0;s<n.length;s++)this._destroyTexture(n[s]);i&&this._destroyTexture(i),this.delete(e),this.backend.delete(e),this.info.memory.renderTargets--}}_destroyTexture(e){if(this.has(e)===!0){const t=this.get(e);e.removeEventListener("dispose",t.onDispose);const n=t.isDefaultTexture;if(this.backend.destroyTexture(e,n),t.bindGroups)for(const i of t.bindGroups){const s=this.backend.get(i);s.groups=void 0,s.versions=void 0}this._htmlTextures.delete(e),this.delete(e),this.info.destroyTexture(e)}}}class jm extends We{constructor(e,t,n,i=1){super(e,t,n),this.a=i}set(e,t,n,i=1){return this.a=i,super.set(e,t,n)}copy(e){return e.a!==void 0&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class iI extends Et{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getMemberType(e,t){const n=this.getNodeType(e),i=e.getStructTypeNode(n);let s;return i!==null?s=i.getMemberType(e,t):(ce(`TSL: Member "${t}" not found in struct "${n}".`,new Kn),s="float"),s}getHash(){return String(this.id)}generate(){return this.name}}class rI extends Ve{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this._expressionNode=null,this._currentNode=null,this.isStackNode=!0}getElementType(e){return this.hasOutput(e)?this.outputNode.getElementType(e):"void"}generateNodeType(e){return this.hasOutput(e)?this.outputNode.getNodeType(e):"void"}getMemberType(e,t){return this.hasOutput(e)?this.outputNode.getMemberType(e,t):"void"}addToStack(e,t=this.nodes.length){return e.isNode!==!0?(ce("TSL: Invalid node added to stack.",new Kn),this):(this.nodes.splice(t,0,e),this)}addToStackBefore(e){const t=this._currentNode?this.nodes.indexOf(this._currentNode):0;return this.addToStack(e,t)}If(e,t){const n=new Wl(t);return this._currentCond=Ti(e,n),this.addToStack(this._currentCond)}ElseIf(e,t){const n=new Wl(t),i=Ti(e,n);return this._currentCond.elseNode=i,this._currentCond=i,this}Else(e){return this._currentCond.elseNode=new Wl(e),this}Switch(e){return this._expressionNode=Ge(e),this}Case(...e){const t=[];if(e.length>=2)for(let a=0;a<e.length-1;a++)t.push(this._expressionNode.equal(Ge(e[a])));else ce("TSL: Invalid parameter length. Case() requires at least two parameters.",new Kn);const n=e[e.length-1],i=new Wl(n);let s=t[0];for(let a=1;a<t.length;a++)s=s.or(t[a]);const o=Ti(s,i);return this._currentCond===null?(this._currentCond=o,this.addToStack(this._currentCond)):(this._currentCond.elseNode=o,this._currentCond=o,this)}Default(e){return this.Else(e),this}setup(e){const t=e.getNodeProperties(this);let n=0;for(const i of this.getChildren())i.isVarNode&&i.isIntent(e)&&i.isAssign(e)!==!0||(t["node"+n++]=i);return t.outputNode||null}hasOutput(e){return this.outputNode&&this.outputNode.isNode&&this.outputNode.getNodeType(e)!=="void"}build(e,...t){const n=Yy(),i=e.buildStage;Th(this),e.setActiveStack(this);const s=c=>{if(this._currentNode=c,!(c.isVarNode&&c.isIntent(e)&&c.isAssign(e)!==!0)){if(i==="setup")c.build(e);else if(i==="analyze")c.build(e,this);else if(i==="generate"){const u=e.getDataFromNode(c,"any").stages,h=u&&u[e.shaderStage];if(c.isVarNode&&h&&h.length===1&&h[0]&&h[0].isStackNode)return;c.build(e,"void")}}},o=[...this.nodes];for(const c of o)s(c);this._currentNode=null;const a=this.nodes.filter(c=>o.indexOf(c)===-1);for(const c of a)s(c);let l;return this.hasOutput(e)?l=this.outputNode.build(e,...t):l=super.build(e,...t),Th(n),e.removeActiveStack(this),l}}const wf=It(rI).setParameterLength(0,1);class bb extends xn{static get type(){return"BitcastNode"}constructor(e,t,n=null){super(),this.valueNode=e,this.conversionType=t,this.inputType=n,this.isBitcastNode=!0}generateNodeType(e){if(this.inputType!==null){const t=this.valueNode.getNodeType(e),n=e.getTypeLength(t);return e.getTypeFromLength(n,this.conversionType)}return this.conversionType}generate(e){const t=this.getNodeType(e);let n="";if(this.inputType!==null){const i=this.valueNode.getNodeType(e);n=e.getTypeLength(i)===1?this.inputType:e.changeComponentType(i,this.inputType)}else n=this.valueNode.getNodeType(e);return`${e.getBitcastMethod(t,n)}( ${this.valueNode.build(e,n)} )`}}const sI=we(bb).setParameterLength(2),oI=r=>new bb(r,"uint","float"),Hu={};class po extends G{static get type(){return"BitcountNode"}constructor(e,t){super(e,t),this.isBitcountNode=!0}_resolveElementType(e,t,n){n==="int"?t.assign(sI(e,"uint")):t.assign(e)}_returnDataNode(e){switch(e){case"uint":return mt;case"int":return Zt;case"uvec2":return Zy;case"uvec3":return Jy;case"uvec4":return tv;case"ivec2":return dr;case"ivec3":return Qy;case"ivec4":return ev}}_createTrailingZerosBaseLayout(e,t){const n=this._returnDataNode(t);return re(([s])=>{const o=mt(0);this._resolveElementType(s,o,t);const a=J(o.bitAnd(hv(o))),c=oI(a).shiftRight(23).sub(127);return n(c)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createLeadingZerosBaseLayout(e,t){const n=this._returnDataNode(t);return re(([s])=>{Ft(s.equal(mt(0)),()=>mt(32));const o=mt(0),a=mt(0);return this._resolveElementType(s,o,t),Ft(o.shiftRight(16).equal(0),()=>{a.addAssign(16),o.shiftLeftAssign(16)}),Ft(o.shiftRight(24).equal(0),()=>{a.addAssign(8),o.shiftLeftAssign(8)}),Ft(o.shiftRight(28).equal(0),()=>{a.addAssign(4),o.shiftLeftAssign(4)}),Ft(o.shiftRight(30).equal(0),()=>{a.addAssign(2),o.shiftLeftAssign(2)}),Ft(o.shiftRight(31).equal(0),()=>{a.addAssign(1)}),n(a)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createOneBitsBaseLayout(e,t){const n=this._returnDataNode(t);return re(([s])=>{const o=mt(0);this._resolveElementType(s,o,t),o.assign(o.sub(o.shiftRight(mt(1)).bitAnd(mt(1431655765)))),o.assign(o.bitAnd(mt(858993459)).add(o.shiftRight(mt(2)).bitAnd(mt(858993459))));const a=o.add(o.shiftRight(mt(4))).bitAnd(mt(252645135)).mul(mt(16843009)).shiftRight(mt(24));return n(a)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createMainLayout(e,t,n,i){const s=this._returnDataNode(t);return re(([a])=>{if(n===1)return s(i(a));{const l=s(0),c=["x","y","z","w"];for(let u=0;u<n;u++){const h=c[u];l[h].assign(i(a[h]))}return l}}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}setup(e){const{method:t,aNode:n}=this,{renderer:i}=e;if(i.backend.isWebGPUBackend)return super.setup(e);const s=this.getInputType(e),o=e.getElementType(s),a=e.getTypeLength(s),l=`${t}_base_${o}`,c=`${t}_${s}`;let u=Hu[l];if(u===void 0){switch(t){case po.COUNT_LEADING_ZEROS:{u=this._createLeadingZerosBaseLayout(l,o);break}case po.COUNT_TRAILING_ZEROS:{u=this._createTrailingZerosBaseLayout(l,o);break}case po.COUNT_ONE_BITS:{u=this._createOneBitsBaseLayout(l,o);break}}Hu[l]=u}let h=Hu[c];return h===void 0&&(h=this._createMainLayout(c,s,a,u),Hu[c]=h),re(()=>h(n))()}}po.COUNT_TRAILING_ZEROS="countTrailingZeros";po.COUNT_LEADING_ZEROS="countLeadingZeros";po.COUNT_ONE_BITS="countOneBits";new pt;const aI=new ks;fo.flipX();aI.depthTexture=new jn(1,1);const Rf=new ol(-1,1,1,-1,0,1);class lI extends An{constructor(e=!1){super();const t=e===!1?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new sn([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new sn(t,2))}}const cI=new lI;class Sb extends _n{constructor(e=null){super(cI,e),this.camera=Rf,this.isQuadMesh=!0}async renderAsync(e){Kt('QuadMesh: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await e.init(),e.render(this,Rf)}render(e){e.render(this,Rf)}}const Tb=re(([r])=>Ar(J(52.9829189).mul(Ar(bo(r,ke(.06711056,.00583715)))))).setLayout({name:"interleavedGradientNoise",type:"float",inputs:[{name:"position",type:"vec2"}]}),gr=re(([r,e,t])=>{const n=J(2.399963229728653),i=Ps(J(r).add(.5).div(J(e))),s=J(r).mul(n).add(t);return ke(fr(s),vi(s)).mul(i)}).setLayout({name:"vogelDiskSample",type:"vec2",inputs:[{name:"sampleIndex",type:"int"},{name:"samplesCount",type:"int"},{name:"phi",type:"float"}]});class Si extends Ve{static get type(){return"EventNode"}constructor(e,t){super("void"),this.eventType=e,this.callback=t,e===Si.OBJECT?this.updateType=Ze.OBJECT:e===Si.MATERIAL?this.updateType=Ze.RENDER:e===Si.FRAME?this.updateType=Ze.FRAME:e===Si.BEFORE_OBJECT?this.updateBeforeType=Ze.OBJECT:e===Si.BEFORE_MATERIAL?this.updateBeforeType=Ze.RENDER:e===Si.BEFORE_FRAME&&(this.updateBeforeType=Ze.FRAME)}update(e){this.callback(e)}updateBefore(e){this.callback(e)}}Si.OBJECT="object";Si.MATERIAL="material";Si.FRAME="frame";Si.BEFORE_OBJECT="beforeObject";Si.BEFORE_MATERIAL="beforeMaterial";Si.BEFORE_FRAME="beforeFrame";const Cf=new pt,uI=qe(0).setGroup(Ke).onRenderUpdate(({scene:r})=>r.backgroundBlurriness),$x=qe(1).setGroup(Ke).onRenderUpdate(({scene:r})=>r.backgroundIntensity),hI=qe(new pt).setGroup(Ke).onRenderUpdate(({scene:r})=>{const e=r.background;return e!==null&&e.isTexture&&e.mapping!==Jp?Cf.makeRotationFromEuler(r.backgroundRotation).transpose():Cf.identity(),Cf});re(({texture:r,uv:e})=>{const n=te().toVar();return Ft(e.x.lessThan(1e-4),()=>{n.assign(te(1,0,0))}).ElseIf(e.y.lessThan(1e-4),()=>{n.assign(te(0,1,0))}).ElseIf(e.z.lessThan(1e-4),()=>{n.assign(te(0,0,1))}).ElseIf(e.x.greaterThan(1-1e-4),()=>{n.assign(te(-1,0,0))}).ElseIf(e.y.greaterThan(1-1e-4),()=>{n.assign(te(0,-1,0))}).ElseIf(e.z.greaterThan(1-1e-4),()=>{n.assign(te(0,0,-1))}).Else(()=>{const s=r.sample(e.add(te(-.01,0,0))).r.sub(r.sample(e.add(te(.01,0,0))).r),o=r.sample(e.add(te(0,-.01,0))).r.sub(r.sample(e.add(te(0,.01,0))).r),a=r.sample(e.add(te(0,0,-.01))).r.sub(r.sample(e.add(te(0,0,.01))).r);n.assign(te(s,o,a))}),n.normalize()});re(([r,e])=>r.mul(e).floor().div(e));const Wu=new pe;class dI extends zc{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.isPassTextureNode=!0,this.setUpdateMatrix(!1)}setup(e){const t=e.getNodeProperties(this);return t.passNode=this.passNode,super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class Xx extends dI{static get type(){return"PassMultipleTextureNode"}constructor(e,t,n=!1){super(e,null),this.textureName=t,this.previousTexture=n,this.isPassMultipleTextureNode=!0}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){const e=new this.constructor(this.passNode,this.textureName,this.previousTexture);return e.uvNode=this.uvNode,e.levelNode=this.levelNode,e.biasNode=this.biasNode,e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.offsetNode=this.offsetNode,e}}class Jh extends xn{static get type(){return"PassNode"}constructor(e,t,n,i={}){super("vec4"),this.scope=e,this.scene=t,this.camera=n,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;const s=new jn;s.isRenderTargetTexture=!0,s.name="depth";const o=new ks(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:tn,...i});o.texture.name="output",o.depthTexture=s,this.renderTarget=o,this.overrideMaterial=null,this.transparent=!0,this.opaque=!0,this.contextNode=null,this._contextNodeCache=null,this._textures={output:o.texture,depth:s},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=qe(0),this._cameraFar=qe(0),this._mrt=null,this._layers=null,this._resolutionScale=1,this._viewport=null,this._scissor=null,this.isPassNode=!0,this.updateBeforeType=Ze.FRAME,this.global=!0}setResolutionScale(e){return this._resolutionScale=e,this}getResolutionScale(){return this._resolutionScale}setResolution(e){return ae("PassNode: .setResolution() is deprecated. Use .setResolutionScale() instead."),this.setResolutionScale(e)}getResolution(){return ae("PassNode: .getResolution() is deprecated. Use .getResolutionScale() instead."),this.getResolutionScale()}setLayers(e){return this._layers=e,this}getLayers(){return this._layers}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getTexture(e){let t=this._textures[e];return t===void 0&&(t=this.renderTarget.texture.clone(),t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)),t}getPreviousTexture(e){let t=this._previousTextures[e];return t===void 0&&(t=this.getTexture(e).clone(),this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(t!==void 0){const n=this._textures[e],i=this.renderTarget.textures.indexOf(n);this.renderTarget.textures[i]=t,this._textures[e]=t,this._previousTextures[e]=n,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return t===void 0&&(t=new Xx(this,e),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return t===void 0&&(this._textureNodes[e]===void 0&&this.getTextureNode(e),t=new Xx(this,e,!0),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(t===void 0){const n=this._cameraNear,i=this._cameraFar;this._viewZNodes[e]=t=Zv(this.getTextureNode(e),n,i)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(t===void 0){const n=this._cameraNear,i=this._cameraFar,s=this.getViewZNode(e);this._linearDepthNodes[e]=t=rc(s,n,i)}return t}async compileAsync(e){const t=e.getRenderTarget(),n=e.getMRT();e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),await e.compileAsync(this.scene,this.camera),e.setRenderTarget(t),e.setMRT(n)}setup({renderer:e}){return this.renderTarget.samples=this.options.samples===void 0?e.samples:this.options.samples,this.renderTarget.texture.type=e.getOutputBufferType(),e.reversedDepthBuffer===!0&&(this.renderTarget.depthTexture.type=Qt),this.scope===Jh.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:n}=this;let i,s;const o=t.getOutputRenderTarget();o&&o.isXRRenderTarget===!0?(s=1,i=t.xr.getCamera(),t.xr.updateCamera(i),Wu.set(o.width,o.height)):(i=this.camera,s=t.getPixelRatio(),t.getSize(Wu)),this._pixelRatio=s,this.setSize(Wu.width,Wu.height);const a=t.getRenderTarget(),l=t.getMRT(),c=t.autoClear,u=t.transparent,h=t.opaque,d=i.layers.mask,f=t.contextNode,p=n.overrideMaterial;this._cameraNear.value=i.near,this._cameraFar.value=i.far,this._layers!==null&&(i.layers.mask=this._layers.mask);for(const m in this._previousTextures)this.toggleTexture(m);this.overrideMaterial!==null&&(n.overrideMaterial=this.overrideMaterial),t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.autoClear=!0,t.transparent=this.transparent,t.opaque=this.opaque,this.contextNode!==null&&((this._contextNodeCache===null||this._contextNodeCache.version!==this.version)&&(this._contextNodeCache={version:this.version,context:Po({...t.contextNode.getFlowContextData(),...this.contextNode.getFlowContextData()})}),t.contextNode=this._contextNodeCache.context);const g=n.name;n.name=this.name?this.name:n.name,t.render(n,i),n.name=g,n.overrideMaterial=p,t.setRenderTarget(a),t.setMRT(l),t.autoClear=c,t.transparent=u,t.opaque=h,t.contextNode=f,i.layers.mask=d}setSize(e,t){this._width=e,this._height=t;const n=Math.floor(this._width*this._pixelRatio*this._resolutionScale),i=Math.floor(this._height*this._pixelRatio*this._resolutionScale);this.renderTarget.setSize(n,i),this._scissor!==null?(this.renderTarget.scissor.copy(this._scissor).multiplyScalar(this._pixelRatio*this._resolutionScale).floor(),this.renderTarget.scissorTest=!0):this.renderTarget.scissorTest=!1,this._viewport!==null&&this.renderTarget.viewport.copy(this._viewport).multiplyScalar(this._pixelRatio*this._resolutionScale).floor()}setScissor(e,t,n,i){e===null?this._scissor=null:(this._scissor===null&&(this._scissor=new rt),e.isVector4?this._scissor.copy(e):this._scissor.set(e,t,n,i))}setViewport(e,t,n,i){e===null?this._viewport=null:(this._viewport===null&&(this._viewport=new rt),e.isVector4?this._viewport.copy(e):this._viewport.set(e,t,n,i))}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}Jh.COLOR="color";Jh.DEPTH="depth";const fI=re(([r,e])=>r.mul(e).clamp()).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),pI=re(([r,e])=>(r=r.mul(e),r.div(r.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),mI=re(([r,e])=>{r=r.mul(e),r=r.sub(.004).max(0);const t=r.mul(r.mul(6.2).add(.5)),n=r.mul(r.mul(6.2).add(1.7)).add(.06);return t.div(n).pow(2.2)}).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),gI=re(([r])=>{const e=r.mul(r.add(.0245786)).sub(90537e-9),t=r.mul(r.add(.432951).mul(.983729)).add(.238081);return e.div(t)}),_I=re(([r,e])=>{const t=On(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),n=On(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return r=r.mul(e).div(.6),r=t.mul(r),r=gI(r),r=n.mul(r),r.clamp()}).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),xI=On(te(1.6605,-.1246,-.0182),te(-.5876,1.1329,-.1006),te(-.0728,-.0083,1.1187)),yI=On(te(.6274,.0691,.0164),te(.3293,.9195,.088),te(.0433,.0113,.8956)),vI=re(([r])=>{const e=te(r).toVar(),t=te(e.mul(e)).toVar(),n=te(t.mul(t)).toVar();return J(15.5).mul(n.mul(t)).sub(st(40.14,n.mul(e))).add(st(31.96,n).sub(st(6.868,t.mul(e))).add(st(.4298,t).add(st(.1191,e).sub(.00232))))}),bI=re(([r,e])=>{const t=te(r).toVar(),n=On(te(.856627153315983,.137318972929847,.11189821299995),te(.0951212405381588,.761241990602591,.0767994186031903),te(.0482516061458583,.101439036467562,.811302368396859)),i=On(te(1.1271005818144368,-.1413297634984383,-.14132976349843826),te(-.11060664309660323,1.157823702216272,-.11060664309660294),te(-.016493938717834573,-.016493938717834257,1.2519364065950405)),s=J(-12.47393),o=J(4.026069);return t.mulAssign(e),t.assign(yI.mul(t)),t.assign(n.mul(t)),t.assign(kn(t,1e-10)),t.assign(Yr(t)),t.assign(t.sub(s).div(o.sub(s))),t.assign(Fs(t,0,1)),t.assign(vI(t)),t.assign(i.mul(t)),t.assign(Xh(kn(te(0),t),te(2.2))),t.assign(xI.mul(t)),t.assign(Fs(t,0,1)),t}).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),SI=re(([r,e])=>{const t=J(.76),n=J(.15);r=r.mul(e);const i=Qa(r.r,Qa(r.g,r.b)),s=Ti(i.lessThan(.08),i.sub(st(6.25,i.mul(i))),.04);r.subAssign(s);const o=kn(r.r,kn(r.g,r.b));Ft(o.lessThan(t),()=>r);const a=oi(1,t),l=oi(1,a.mul(a).div(o.add(a.sub(t))));r.mulAssign(l.div(o));const c=oi(1,Er(1,n.mul(o.sub(l)).add(1)));return Dt(r,te(l),c)}).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class Rn extends Ve{static get type(){return"CodeNode"}constructor(e="",t=[],n=""){super("code"),this.isCodeNode=!0,this.global=!0,this.code=e,this.includes=t,this.language=n}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const i of t)i.build(e);const n=e.getCodeFromNode(this,this.getNodeType(e));return n.code=this.code,n.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}class TI extends Rn{static get type(){return"FunctionNode"}constructor(e="",t=[],n=""){super(e,t,n)}generateNodeType(e){return this.getNodeFunction(e).type}getMemberType(e,t){const n=this.getNodeType(e);return e.getStructTypeNode(n).getMemberType(e,t)}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let n=t.nodeFunction;return n===void 0&&(n=e.parser.parseFunction(this.code),t.nodeFunction=n),n}generate(e,t){super.generate(e);const n=this.getNodeFunction(e),i=n.name,s=n.type,o=e.getCodeFromNode(this,s);i!==""&&(o.name=i);const a=e.getPropertyName(o),l=this.getNodeFunction(e).getCode(a);return o.code=l+`
4650
4650
  `,t==="property"?a:e.format(`${a}()`,s,t)}}function Ym(r){let e;const t=r.context.getViewZ;return t!==void 0&&(e=t(this)),(e||dn.z).negate()}const MI=re(([r,e],t)=>{const n=Ym(t);return Qr(r,e,n)}),EI=re(([r],e)=>{const t=Ym(e);return r.mul(r,t,t).negate().exp().oneMinus()});re(([r,e],t)=>{const n=Ym(t),s=e.sub(Ja.y).max(0).toConst().mul(n).toConst();return r.mul(r,s,s).negate().exp().oneMinus()});const qx=re(([r,e])=>et(e.toFloat().mix(tc.rgb,r.toVec3()),tc.a));class AI extends Ve{constructor(e){super(),this.scope=e,this.isBarrierNode=!0}setup(e){e.allowEarlyReturns=!1,e.allowGlobalVariables=!1}generate(e){const{scope:t}=this,{renderer:n}=e;n.backend.isWebGLBackend===!0?e.addFlowCode(` // ${t}Barrier
4651
- `):e.addLineFlowCode(`${t}Barrier()`,this)}}It(AI);class Cr extends Ve{static get type(){return"AtomicFunctionNode"}constructor(e,t,n){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=n,this.parents=!0}getInputType(e){return this.pointerNode.getNodeType(e)}generateNodeType(e){return this.getInputType(e)}generate(e){const t=e.getNodeProperties(this),n=t.parents,i=this.method,s=this.getNodeType(e),o=this.getInputType(e),a=this.pointerNode,l=this.valueNode,c=[];c.push(`&${a.build(e,o)}`),l!==null&&c.push(l.build(e,o));const u=`${e.getMethod(i,s)}( ${c.join(", ")} )`;if(n?n.length===1&&n[0].isStackNode===!0:!1)e.addLineFlowCode(u,this);else return t.constNode===void 0&&(t.constNode=mr(u,s).toConst()),t.constNode.build(e)}}Cr.ATOMIC_LOAD="atomicLoad";Cr.ATOMIC_STORE="atomicStore";Cr.ATOMIC_ADD="atomicAdd";Cr.ATOMIC_SUB="atomicSub";Cr.ATOMIC_MAX="atomicMax";Cr.ATOMIC_MIN="atomicMin";Cr.ATOMIC_AND="atomicAnd";Cr.ATOMIC_OR="atomicOr";Cr.ATOMIC_XOR="atomicXor";It(Cr);class bt extends xn{static get type(){return"SubgroupFunctionNode"}constructor(e,t=null,n=null){super(),this.method=e,this.aNode=t,this.bNode=n}getInputType(e){const t=this.aNode?this.aNode.getNodeType(e):null,n=this.bNode?this.bNode.getNodeType(e):null,i=e.isMatrix(t)?0:e.getTypeLength(t),s=e.isMatrix(n)?0:e.getTypeLength(n);return i>s?t:n}generateNodeType(e){const t=this.method;return t===bt.SUBGROUP_ELECT?"bool":t===bt.SUBGROUP_BALLOT?"uvec4":this.getInputType(e)}generate(e,t){const n=this.method,i=this.getNodeType(e),s=this.getInputType(e),o=this.aNode,a=this.bNode,l=[];if(n===bt.SUBGROUP_BROADCAST||n===bt.SUBGROUP_SHUFFLE||n===bt.QUAD_BROADCAST){const u=a.getNodeType(e);l.push(o.build(e,i),a.build(e,u==="float"?"int":i))}else n===bt.SUBGROUP_SHUFFLE_XOR||n===bt.SUBGROUP_SHUFFLE_DOWN||n===bt.SUBGROUP_SHUFFLE_UP?l.push(o.build(e,i),a.build(e,"uint")):(o!==null&&l.push(o.build(e,s)),a!==null&&l.push(a.build(e,s)));const c=l.length===0?"()":`( ${l.join(", ")} )`;return e.format(`${e.getMethod(n,i)}${c}`,i,t)}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}bt.SUBGROUP_ELECT="subgroupElect";bt.SUBGROUP_BALLOT="subgroupBallot";bt.SUBGROUP_ADD="subgroupAdd";bt.SUBGROUP_INCLUSIVE_ADD="subgroupInclusiveAdd";bt.SUBGROUP_EXCLUSIVE_AND="subgroupExclusiveAdd";bt.SUBGROUP_MUL="subgroupMul";bt.SUBGROUP_INCLUSIVE_MUL="subgroupInclusiveMul";bt.SUBGROUP_EXCLUSIVE_MUL="subgroupExclusiveMul";bt.SUBGROUP_AND="subgroupAnd";bt.SUBGROUP_OR="subgroupOr";bt.SUBGROUP_XOR="subgroupXor";bt.SUBGROUP_MIN="subgroupMin";bt.SUBGROUP_MAX="subgroupMax";bt.SUBGROUP_ALL="subgroupAll";bt.SUBGROUP_ANY="subgroupAny";bt.SUBGROUP_BROADCAST_FIRST="subgroupBroadcastFirst";bt.QUAD_SWAP_X="quadSwapX";bt.QUAD_SWAP_Y="quadSwapY";bt.QUAD_SWAP_DIAGONAL="quadSwapDiagonal";bt.SUBGROUP_BROADCAST="subgroupBroadcast";bt.SUBGROUP_SHUFFLE="subgroupShuffle";bt.SUBGROUP_SHUFFLE_XOR="subgroupShuffleXor";bt.SUBGROUP_SHUFFLE_UP="subgroupShuffleUp";bt.SUBGROUP_SHUFFLE_DOWN="subgroupShuffleDown";bt.QUAD_BROADCAST="quadBroadcast";let $u;function ed(r){$u=$u||new WeakMap;let e=$u.get(r);return e===void 0&&$u.set(r,e={}),e}function Km(r){const e=ed(r);return e.shadowMatrix||(e.shadowMatrix=qe("mat4").setGroup(Ke).onRenderUpdate(t=>((r.castShadow!==!0||t.renderer.shadowMap.enabled===!1)&&(r.shadow.camera.coordinateSystem!==t.camera.coordinateSystem&&(r.shadow.camera.coordinateSystem=t.camera.coordinateSystem,r.shadow.camera.updateProjectionMatrix()),r.shadow.updateMatrices(r)),r.shadow.matrix)))}function wI(r,e=Ja){const t=Km(r).mul(e);return t.xyz.div(t.w)}function Mb(r){const e=ed(r);return e.position||(e.position=qe(new P).setGroup(Ke).onRenderUpdate((t,n)=>n.value.setFromMatrixPosition(r.matrixWorld)))}function RI(r){const e=ed(r);return e.targetPosition||(e.targetPosition=qe(new P).setGroup(Ke).onRenderUpdate((t,n)=>n.value.setFromMatrixPosition(r.target.matrixWorld)))}function Eb(r){const e=ed(r);return e.viewPosition||(e.viewPosition=qe(new P).setGroup(Ke).onRenderUpdate(({camera:t},n)=>{n.value=n.value||new P,n.value.setFromMatrixPosition(r.matrixWorld),n.value.applyMatrix4(t.matrixWorldInverse)}))}const Ab=r=>es.transformDirection(Mb(r).sub(RI(r))),CI=r=>r.sort((e,t)=>e.id-t.id),NI=(r,e)=>{for(const t of e)if(t.isAnalyticLightNode&&t.light.id===r)return t;return null},Nf=new WeakMap,Ol=[];class wb extends Ve{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Ns("vec3","totalDiffuse"),this.totalSpecularNode=Ns("vec3","totalSpecular"),this.outgoingLightNode=Ns("vec3","outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}customCacheKey(){const e=this._lights;for(let n=0;n<e.length;n++){const i=e[n];if(Ol.push(i.id),Ol.push(i.castShadow?1:0),i.isSpotLight===!0){const s=i.map!==null?i.map.id:-1,o=i.colorNode?i.colorNode.getCacheKey():-1;Ol.push(s,o)}}const t=Gc(Ol);return Ol.length=0,t}getHash(e){if(this._lightNodesHash===null){this._lightNodes===null&&this.setupLightsNode(e);const t=[];for(const n of this._lightNodes)t.push(n.getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getNodeProperties(this);for(const n of t.nodes)n.build(e);t.outputNode.build(e)}setupLightsNode(e){const t=[],n=this._lightNodes,i=CI(this._lights),s=e.renderer.library;for(const o of i)if(o.isNode)t.push(Ge(o));else{let a=null;if(n!==null&&(a=NI(o.id,n)),a===null){const l=s.getLightNodeClass(o.constructor);if(l===null){ae(`LightsNode.setupNodeLights: Light node not found for ${o.constructor.name}`);continue}Nf.has(o)===!1&&Nf.set(o,new l(o)),a=Nf.get(o)}t.push(a)}this._lightNodes=t}setupDirectLight(e,t,n){const{lightingModel:i,reflectedLight:s}=e.context;i.direct({...n,lightNode:t,reflectedLight:s},e)}setupDirectRectAreaLight(e,t,n){const{lightingModel:i,reflectedLight:s}=e.context;i.directRectArea({...n,lightNode:t,reflectedLight:s},e)}setupLights(e,t){for(const n of t)n.build(e)}getLightNodes(e){return this._lightNodes===null&&this.setupLightsNode(e),this._lightNodes}setup(e){const t=e.lightsNode;e.lightsNode=this;let n=this.outgoingLightNode;const i=e.context,s=i.lightingModel,o=e.getNodeProperties(this);if(s){const{totalDiffuseNode:a,totalSpecularNode:l}=this;i.outgoingLight=n;const c=e.addStack();o.nodes=c.nodes,s.start(e);const{backdrop:u,backdropAlpha:h}=i,{directDiffuse:d,directSpecular:f,indirectDiffuse:p,indirectSpecular:g}=i.reflectedLight;let m=d.add(p);u!==null&&(h!==null?m=te(h.mix(m,u)):m=te(u)),a.assign(m),l.assign(f.add(g)),n.assign(a.add(l)),s.finish(e),n=n.bypass(e.removeStack())}else o.nodes=[];return e.lightsNode=t,n}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}class PI extends Ve{static get type(){return"ShadowBaseNode"}constructor(e){super(),this.light=e,this.updateBeforeType=Ze.RENDER,this.isShadowBaseNode=!0}setupShadowPosition({context:e,material:t}){Rb.assign(t.receivedShadowPositionNode||e.shadowPositionWorld||Ja)}}const Rb=Ns("vec3","shadowPositionWorld");function DI(r,e={}){return e.toneMapping=r.toneMapping,e.toneMappingExposure=r.toneMappingExposure,e.outputColorSpace=r.outputColorSpace,e.renderTarget=r.getRenderTarget(),e.activeCubeFace=r.getActiveCubeFace(),e.activeMipmapLevel=r.getActiveMipmapLevel(),e.renderObjectFunction=r.getRenderObjectFunction(),e.pixelRatio=r.getPixelRatio(),e.mrt=r.getMRT(),e.clearColor=r.getClearColor(e.clearColor||new We),e.clearAlpha=r.getClearAlpha(),e.autoClear=r.autoClear,e.scissorTest=r.getScissorTest(),e}function LI(r,e){return e=DI(r,e),r.setMRT(null),r.setRenderObjectFunction(null),r.setClearColor(0,1),r.autoClear=!0,e}function UI(r,e){r.toneMapping=e.toneMapping,r.toneMappingExposure=e.toneMappingExposure,r.outputColorSpace=e.outputColorSpace,r.setRenderTarget(e.renderTarget,e.activeCubeFace,e.activeMipmapLevel),r.setRenderObjectFunction(e.renderObjectFunction),r.setPixelRatio(e.pixelRatio),r.setMRT(e.mrt),r.setClearColor(e.clearColor,e.clearAlpha),r.autoClear=e.autoClear,r.setScissorTest(e.scissorTest)}function FI(r,e={}){return e.background=r.background,e.backgroundNode=r.backgroundNode,e.overrideMaterial=r.overrideMaterial,e}function II(r,e){return e=FI(r,e),r.background=null,r.backgroundNode=null,r.overrideMaterial=null,e}function BI(r,e){r.background=e.background,r.backgroundNode=e.backgroundNode,r.overrideMaterial=e.overrideMaterial}function OI(r,e,t){return t=LI(r,t),t=II(e,t),t}function kI(r,e,t){UI(r,t),BI(e,t)}const Ch=new WeakMap,GI=re(({depthTexture:r,shadowCoord:e,depthLayer:t})=>{let n=Vt(r,e.xy).setName("t_basic");return r.isArrayTexture&&(n=n.depth(t)),n.compare(e.z)}),VI=re(({depthTexture:r,shadowCoord:e,shadow:t,depthLayer:n})=>{const i=(u,h)=>{let d=Vt(r,u);return r.isArrayTexture&&(d=d.depth(n)),d.compare(h)},s=Jt("mapSize","vec2",t).setGroup(Ke),o=Jt("radius","float",t).setGroup(Ke),a=ke(1).div(s),l=o.mul(a.x),c=Tb(pl.xy).mul(6.28318530718);return fi(i(e.xy.add(gr(0,5,c).mul(l)),e.z),i(e.xy.add(gr(1,5,c).mul(l)),e.z),i(e.xy.add(gr(2,5,c).mul(l)),e.z),i(e.xy.add(gr(3,5,c).mul(l)),e.z),i(e.xy.add(gr(4,5,c).mul(l)),e.z)).mul(1/5)}),zI=re(({depthTexture:r,shadowCoord:e,shadow:t,depthLayer:n})=>{const i=(h,d)=>{let f=Vt(r,h);return r.isArrayTexture&&(f=f.depth(n)),f.compare(d)},s=Jt("mapSize","vec2",t).setGroup(Ke),o=ke(1).div(s),a=o.x,l=o.y,c=e.xy,u=Ar(c.mul(s).add(.5));return c.subAssign(u.mul(o)),fi(i(c,e.z),i(c.add(ke(a,0)),e.z),i(c.add(ke(0,l)),e.z),i(c.add(o),e.z),Dt(i(c.add(ke(a.negate(),0)),e.z),i(c.add(ke(a.mul(2),0)),e.z),u.x),Dt(i(c.add(ke(a.negate(),l)),e.z),i(c.add(ke(a.mul(2),l)),e.z),u.x),Dt(i(c.add(ke(0,l.negate())),e.z),i(c.add(ke(0,l.mul(2))),e.z),u.y),Dt(i(c.add(ke(a,l.negate())),e.z),i(c.add(ke(a,l.mul(2))),e.z),u.y),Dt(Dt(i(c.add(ke(a.negate(),l.negate())),e.z),i(c.add(ke(a.mul(2),l.negate())),e.z),u.x),Dt(i(c.add(ke(a.negate(),l.mul(2))),e.z),i(c.add(ke(a.mul(2),l.mul(2))),e.z),u.x),u.y)).mul(1/9)}),HI=re(({depthTexture:r,shadowCoord:e,depthLayer:t},n)=>{let i=Vt(r).sample(e.xy);r.isArrayTexture&&(i=i.depth(t)),i=i.rg;const s=i.x,o=kn(1e-7,i.y.mul(i.y)),a=n.renderer.reversedDepthBuffer?Ec(s,e.z):Ec(e.z,s),l=J(1).toVar();return Ft(a.notEqual(1),()=>{const c=e.z.sub(s);let u=o.div(o.add(c.mul(c)));u=Fs(oi(u,.3).div(.65)),l.assign(kn(a,u))}),l}),WI=r=>{let e=Ch.get(r);return e===void 0&&(e=new mn,e.colorNode=et(0,0,0,1),e.isShadowPassMaterial=!0,e.name="ShadowMaterial",e.blending=Pn,e.fog=!1,Ch.set(r,e)),e},$I=r=>{const e=Ch.get(r);e!==void 0&&(e.dispose(),Ch.delete(r))},jx=new Bs,sa=[],XI=(r,e,t,n)=>{sa[0]=r,sa[1]=e;let i=jx.get(sa);return(i===void 0||i.shadowType!==t||i.useVelocity!==n)&&(i=(s,o,a,l,c,u,...h)=>{(s.castShadow===!0||s.receiveShadow&&t===_r)&&(n&&($y(s).useVelocity=!0),s.onBeforeShadow(r,s,a,e.camera,l,o.overrideMaterial,u),r.renderObject(s,o,a,l,c,u,...h),s.onAfterShadow(r,s,a,e.camera,l,o.overrideMaterial,u))},i.shadowType=t,i.useVelocity=n,jx.set(sa,i)),sa[0]=null,sa[1]=null,i},qI=re(({samples:r,radius:e,size:t,shadowPass:n,depthLayer:i})=>{const s=J(0).toVar("meanVertical"),o=J(0).toVar("squareMeanVertical"),a=r.lessThanEqual(J(1)).select(J(0),J(2).div(r.sub(1))),l=r.lessThanEqual(J(1)).select(J(0),J(-1));Li({start:Zt(0),end:Zt(r),type:"int",condition:"<"},({i:u})=>{const h=l.add(J(u).mul(a));let d=n.sample(fi(pl.xy,ke(0,h).mul(e)).div(t));n.value.isArrayTexture&&(d=d.depth(i)),d=d.x,s.addAssign(d),o.addAssign(d.mul(d))}),s.divAssign(r),o.divAssign(r);const c=Ps(o.sub(s.mul(s)).max(0));return ke(s,c)}),jI=re(({samples:r,radius:e,size:t,shadowPass:n,depthLayer:i})=>{const s=J(0).toVar("meanHorizontal"),o=J(0).toVar("squareMeanHorizontal"),a=r.lessThanEqual(J(1)).select(J(0),J(2).div(r.sub(1))),l=r.lessThanEqual(J(1)).select(J(0),J(-1));Li({start:Zt(0),end:Zt(r),type:"int",condition:"<"},({i:u})=>{const h=l.add(J(u).mul(a));let d=n.sample(fi(pl.xy,ke(h,0).mul(e)).div(t));n.value.isArrayTexture&&(d=d.depth(i)),s.addAssign(d.x),o.addAssign(fi(d.y.mul(d.y),d.x.mul(d.x)))}),s.divAssign(r),o.divAssign(r);const c=Ps(o.sub(s.mul(s)).max(0));return ke(s,c)}),YI=[GI,VI,zI,HI];let Pf;const Xu=new Sb;class Cb extends PI{static get type(){return"ShadowNode"}constructor(e,t=null){super(e),this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this._node=null,this._currentShadowType=null,this._cameraFrameId=new WeakMap,this.isShadowNode=!0,this.depthLayer=0}setupShadowFilter(e,{filterFn:t,depthTexture:n,shadowCoord:i,shadow:s,depthLayer:o}){const a=i.x.greaterThanEqual(0).and(i.x.lessThanEqual(1)).and(i.y.greaterThanEqual(0)).and(i.y.lessThanEqual(1)).and(i.z.lessThanEqual(1)),l=t({depthTexture:n,shadowCoord:i,shadow:s,depthLayer:o});return a.select(l,J(1))}setupShadowCoord(e,t){const{shadow:n}=this,{renderer:i}=e,s=n.biasNode||Jt("bias","float",n).setGroup(Ke);let o=t,a;if(n.camera.isOrthographicCamera||i.logarithmicDepthBuffer!==!0)o=o.xyz.div(o.w),a=o.z;else{const l=o.w;o=o.xy.div(l);const c=Jt("near","float",n.camera).setGroup(Ke),u=Jt("far","float",n.camera).setGroup(Ke);a=Qv(l.negate(),c,u)}return o=te(o.x,o.y.oneMinus(),i.reversedDepthBuffer?a.sub(s):a.add(s)),o}getShadowFilterFn(e){return YI[e]}setupRenderTarget(e,t){const n=new jn(e.mapSize.width,e.mapSize.height);n.name="ShadowDepthTexture",n.compareFunction=t.renderer.reversedDepthBuffer?Zr:Os;const i=t.createRenderTarget(e.mapSize.width,e.mapSize.height);return i.texture.name="ShadowMap",i.texture.type=e.mapType,i.depthTexture=n,{shadowMap:i,depthTexture:n}}setupShadow(e){const{renderer:t,camera:n}=e,{light:i,shadow:s}=this,{depthTexture:o,shadowMap:a}=this.setupRenderTarget(s,e),l=t.shadowMap.type,c=t.hasCompatibility(wo.TEXTURE_COMPARE);if((l===fa||l===G0)&&c?(o.minFilter=Nt,o.magFilter=Nt):(o.minFilter=Mt,o.magFilter=Mt),s.camera.coordinateSystem=n.coordinateSystem,s.camera.updateProjectionMatrix(),l===_r&&s.isPointLightShadow!==!0){o.compareFunction=null,a.depth>1?(a._vsmShadowMapVertical||(a._vsmShadowMapVertical=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:In,type:tn,depth:a.depth,depthBuffer:!1}),a._vsmShadowMapVertical.texture.name="VSMVertical"),this.vsmShadowMapVertical=a._vsmShadowMapVertical,a._vsmShadowMapHorizontal||(a._vsmShadowMapHorizontal=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:In,type:tn,depth:a.depth,depthBuffer:!1}),a._vsmShadowMapHorizontal.texture.name="VSMHorizontal"),this.vsmShadowMapHorizontal=a._vsmShadowMapHorizontal):(this.vsmShadowMapVertical=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:In,type:tn,depthBuffer:!1}),this.vsmShadowMapHorizontal=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:In,type:tn,depthBuffer:!1}));let S=Vt(o);o.isArrayTexture&&(S=S.depth(this.depthLayer));let E=Vt(this.vsmShadowMapVertical.texture);o.isArrayTexture&&(E=E.depth(this.depthLayer));const v=Jt("blurSamples","float",s).setGroup(Ke),w=Jt("radius","float",s).setGroup(Ke),N=Jt("mapSize","vec2",s).setGroup(Ke);let C=this.vsmMaterialVertical||(this.vsmMaterialVertical=new mn);C.fragmentNode=qI({samples:v,radius:w,size:N,shadowPass:S,depthLayer:this.depthLayer}).context(e.getSharedContext()),C.name="VSMVertical",C=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new mn),C.fragmentNode=jI({samples:v,radius:w,size:N,shadowPass:E,depthLayer:this.depthLayer}).context(e.getSharedContext()),C.name="VSMHorizontal"}const u=Jt("intensity","float",s).setGroup(Ke),h=Jt("normalBias","float",s).setGroup(Ke),d=Km(i),f=ml.mul(h);let p;!t.highPrecision||e.material.receivedShadowPositionNode||e.context.shadowPositionWorld?p=d.mul(Rb.add(f)):p=qe("mat4").onObjectUpdate(({object:E},v)=>v.value.multiplyMatrices(d.value,E.matrixWorld)).mul(Tn).add(d.mul(et(f,0)));const g=this.setupShadowCoord(e,p),m=s.filterNode||this.getShadowFilterFn(t.shadowMap.type)||null;if(m===null)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const _=l===_r&&s.isPointLightShadow!==!0?this.vsmShadowMapHorizontal.texture:o,x=this.setupShadowFilter(e,{filterFn:m,shadowTexture:a.texture,depthTexture:_,shadowCoord:g,shadow:s,depthLayer:this.depthLayer});let y;t.shadowMap.transmitted===!0&&(a.texture.isCubeTexture?y=li(a.texture,g.xyz):(y=Vt(a.texture,g),o.isArrayTexture&&(y=y.depth(this.depthLayer))));let b;y?b=Dt(1,x.rgb.mix(y,1),u.mul(y.a)).toVar():b=Dt(1,x,u).toVar(),this.shadowMap=a,this.shadow.map=a;const M=`${this.light.type} Shadow [ ${this.light.name||"ID: "+this.light.id} ]`;return y&&b.toInspector(`${M} / Color`,()=>this.shadowMap.texture.isCubeTexture?li(this.shadowMap.texture):Vt(this.shadowMap.texture)),b.toInspector(`${M} / Depth`,()=>this.shadowMap.texture.isCubeTexture?li(this.shadowMap.texture).r.oneMinus():Ni(this.shadowMap.depthTexture,dl().mul(Ta(Vt(this.shadowMap.depthTexture)))).r.oneMinus())}setup(e){if(e.renderer.shadowMap.enabled!==!1)return re(()=>{const t=e.renderer.shadowMap.type;this._currentShadowType!==t&&(this._reset(),this._node=null);let n=this._node;return this.setupShadowPosition(e),n===null&&(this._node=n=this.setupShadow(e),this._currentShadowType=t),e.material.receivedShadowNode&&(n=e.material.receivedShadowNode(n)),n})()}renderShadow(e){const{shadow:t,shadowMap:n,light:i}=this,{renderer:s,scene:o}=e;t.updateMatrices(i),n.setSize(t.mapSize.width,t.mapSize.height,n.depth);const a=o.name;o.name=`Shadow Map [ ${i.name||"ID: "+i.id} ]`,s.render(o,t.camera),o.name=a}updateShadow(e){const{shadowMap:t,light:n,shadow:i}=this,{renderer:s,scene:o,camera:a}=e,l=s.shadowMap.type,c=t.depthTexture.version;this._depthVersionCached=c;const u=i.camera.layers.mask;(i.camera.layers.mask&4294967294)===0&&(i.camera.layers.mask=a.layers.mask);const h=s.getRenderObjectFunction(),d=s.getMRT(),f=d?d.has("velocity"):!1;Pf=OI(s,o,Pf),o.overrideMaterial=WI(n),s.setRenderObjectFunction(XI(s,i,l,f)),s.setClearColor(0,0),s.setRenderTarget(t),this.renderShadow(e),s.setRenderObjectFunction(h),l===_r&&i.isPointLightShadow!==!0&&this.vsmPass(s),i.camera.layers.mask=u,kI(s,o,Pf)}vsmPass(e){const{shadow:t}=this,n=this.shadowMap.depth;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height,n),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height,n),e.setRenderTarget(this.vsmShadowMapVertical),Xu.material=this.vsmMaterialVertical,Xu.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),Xu.material=this.vsmMaterialHorizontal,Xu.render(e)}dispose(){this._reset(),super.dispose()}_reset(){this._currentShadowType=null,$I(this.light),this.shadowMap&&(this.shadowMap.dispose(),this.shadowMap=null),this.vsmShadowMapVertical!==null&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),this.vsmShadowMapHorizontal!==null&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null)}updateBefore(e){const{shadow:t}=this;let n=t.needsUpdate||t.autoUpdate;n&&(this._cameraFrameId[e.camera]===e.frameId&&(n=!1),this._cameraFrameId[e.camera]=e.frameId),n&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const KI=(r,e)=>new Cb(r,e),ZI=new We,Yx=new pt,kl=new P,Df=new P,QI=[new P(1,0,0),new P(-1,0,0),new P(0,-1,0),new P(0,1,0),new P(0,0,1),new P(0,0,-1)],JI=[new P(0,-1,0),new P(0,-1,0),new P(0,0,-1),new P(0,0,1),new P(0,-1,0),new P(0,-1,0)],e2=[new P(1,0,0),new P(-1,0,0),new P(0,1,0),new P(0,-1,0),new P(0,0,1),new P(0,0,-1)],t2=[new P(0,-1,0),new P(0,-1,0),new P(0,0,1),new P(0,0,-1),new P(0,-1,0),new P(0,-1,0)],n2=re(({depthTexture:r,bd3D:e,dp:t})=>li(r,e).compare(t)),i2=re(({depthTexture:r,bd3D:e,dp:t,shadow:n})=>{const i=Jt("radius","float",n).setGroup(Ke),s=Jt("mapSize","vec2",n).setGroup(Ke),o=i.div(s.x),a=Si(e),l=br(So(e,a.x.greaterThan(a.z).select(te(0,1,0),te(1,0,0)))),c=So(e,l),u=Tb(pl.xy).mul(6.28318530718),h=gr(0,5,u),d=gr(1,5,u),f=gr(2,5,u),p=gr(3,5,u),g=gr(4,5,u);return li(r,e.add(l.mul(h.x).add(c.mul(h.y)).mul(o))).compare(t).add(li(r,e.add(l.mul(d.x).add(c.mul(d.y)).mul(o))).compare(t)).add(li(r,e.add(l.mul(f.x).add(c.mul(f.y)).mul(o))).compare(t)).add(li(r,e.add(l.mul(p.x).add(c.mul(p.y)).mul(o))).compare(t)).add(li(r,e.add(l.mul(g.x).add(c.mul(g.y)).mul(o))).compare(t)).mul(1/5)}),r2=re(({filterFn:r,depthTexture:e,shadowCoord:t,shadow:n},i)=>{const s=t.xyz.toConst(),o=s.abs().toConst(),a=o.x.max(o.y).max(o.z),l=qe("float").setGroup(Ke).onRenderUpdate(()=>n.camera.near),c=qe("float").setGroup(Ke).onRenderUpdate(()=>n.camera.far),u=Jt("bias","float",n).setGroup(Ke),h=J(1).toVar();return Ft(a.sub(c).lessThanEqual(0).and(a.sub(l).greaterThanEqual(0)),()=>{let d;i.renderer.reversedDepthBuffer?(d=qL(a.negate(),l,c),d.subAssign(u)):(d=Kv(a.negate(),l,c),d.addAssign(u));const f=s.normalize();h.assign(r({depthTexture:e,bd3D:f,dp:d,shadow:n}))}),h});class s2 extends Cb{static get type(){return"PointShadowNode"}constructor(e,t=null){super(e,t)}getShadowFilterFn(e){return e===DS?n2:i2}setupShadowCoord(e,t){return t}setupShadowFilter(e,{filterFn:t,depthTexture:n,shadowCoord:i,shadow:s}){return r2({filterFn:t,depthTexture:n,shadowCoord:i,shadow:s})}setupRenderTarget(e,t){const n=new iy(e.mapSize.width);n.name="PointShadowDepthTexture",n.compareFunction=t.renderer.reversedDepthBuffer?Zr:Os;const i=t.createCubeRenderTarget(e.mapSize.width);return i.texture.name="PointShadowMap",i.depthTexture=n,{shadowMap:i,depthTexture:n}}renderShadow(e){const{shadow:t,shadowMap:n,light:i}=this,{renderer:s,scene:o}=e,a=t.camera,l=t.matrix,c=s.coordinateSystem===Tr,u=c?QI:e2,h=c?JI:t2;n.setSize(t.mapSize.width,t.mapSize.width);const d=s.autoClear,f=s.getClearColor(ZI),p=s.getClearAlpha();s.autoClear=!1,s.setClearColor(t.clearColor,t.clearAlpha);for(let g=0;g<6;g++){s.setRenderTarget(n,g),s.clear();const m=i.distance||a.far;m!==a.far&&(a.far=m,a.updateProjectionMatrix()),kl.setFromMatrixPosition(i.matrixWorld),a.position.copy(kl),Df.copy(a.position),Df.add(u[g]),a.up.copy(h[g]),a.lookAt(Df),a.updateMatrixWorld(),l.makeTranslation(-kl.x,-kl.y,-kl.z),Yx.multiplyMatrices(a.projectionMatrix,a.matrixWorldInverse),t._frustum.setFromProjectionMatrix(Yx,a.coordinateSystem,a.reversedDepth);const _=o.name;o.name=`Point Light Shadow [ ${i.name||"ID: "+i.id} ] - Face ${g+1}`,s.render(o,a),o.name=_}s.autoClear=d,s.setClearColor(f,p)}}const o2=(r,e)=>new s2(r,e);class Lo extends gl{static get type(){return"AnalyticLightNode"}constructor(e=null){super(),this.light=e,this.color=new We,this.colorNode=e&&e.colorNode||qe(this.color).setGroup(Ke),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0,this.updateType=Ze.FRAME,e&&e.shadow&&(this._shadowDisposeListener=()=>{this.disposeShadow()},e.addEventListener("dispose",this._shadowDisposeListener))}dispose(){this._shadowDisposeListener&&this.light.removeEventListener("dispose",this._shadowDisposeListener),super.dispose()}disposeShadow(){this.shadowNode!==null&&(this.shadowNode.dispose(),this.shadowNode=null),this.shadowColorNode=null,this.baseColorNode!==null&&(this.colorNode=this.baseColorNode,this.baseColorNode=null)}getHash(){return this.light.uuid}getLightVector(e){return Eb(this.light).sub(e.context.positionView||dn)}setupDirect(){}setupDirectRectArea(){}setupShadowNode(){return KI(this.light)}setupShadow(e){const{renderer:t}=e;if(t.shadowMap.enabled===!1)return;let n=this.shadowColorNode;if(n===null){const i=this.light.shadow.shadowNode;let s;i!==void 0?s=Ge(i):s=this.setupShadowNode(),this.shadowNode=s,this.shadowColorNode=n=this.colorNode.mul(s),this.baseColorNode=this.colorNode}e.context.getShadow&&(n=e.context.getShadow(this,e)),this.colorNode=n}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):this.shadowNode!==null&&(this.shadowNode.dispose(),this.shadowNode=null,this.shadowColorNode=null);const t=this.setupDirect(e),n=this.setupDirectRectArea(e);t&&e.lightsNode.setupDirectLight(e,this,t),n&&e.lightsNode.setupDirectRectAreaLight(e,this,n)}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const Nb=re(({lightDistance:r,cutoffDistance:e,decayExponent:t})=>{const n=r.pow(t).max(.01).reciprocal();return e.greaterThan(0).select(n.mul(r.div(e).pow4().oneMinus().clamp().pow2()),n)}),a2=({color:r,lightVector:e,cutoffDistance:t,decayExponent:n})=>{const i=e.normalize(),s=e.length(),o=Nb({lightDistance:s,cutoffDistance:t,decayExponent:n}),a=r.mul(o);return{lightDirection:i,lightColor:a}};class l2 extends Lo{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=qe(0).setGroup(Ke),this.decayExponentNode=qe(2).setGroup(Ke)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setupShadowNode(){return o2(this.light)}setupDirect(e){return a2({color:this.colorNode,lightVector:this.getLightVector(e),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode})}}re(([r=dl()],{renderer:e,material:t})=>{const n=_v(r.mul(2).sub(1));let i;if(t.alphaToCoverage&&e.currentSamples>0){const s=J(n.fwidth()).toVar();i=Qr(s.oneMinus(),s.add(1),n).oneMinus()}else i=Mi(n.greaterThan(1),0,1);return i});const c2=re(([r,e])=>{const t=r.x,n=r.y,i=r.z;let s=e.element(0).mul(.886227);return s=s.add(e.element(1).mul(2*.511664).mul(n)),s=s.add(e.element(2).mul(2*.511664).mul(i)),s=s.add(e.element(3).mul(2*.511664).mul(t)),s=s.add(e.element(4).mul(2*.429043).mul(t).mul(n)),s=s.add(e.element(5).mul(2*.429043).mul(n).mul(i)),s=s.add(e.element(6).mul(i.mul(i).mul(.743125).sub(.247708))),s=s.add(e.element(7).mul(2*.429043).mul(t).mul(i)),s=s.add(e.element(8).mul(.429043).mul(st(t,t).sub(st(n,n)))),s}),$i=new jm;class u2 extends Gs{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,n){const i=this.renderer,s=this.nodes.getBackgroundNode(e)||e.background;let o=!1;if(s===null)i._clearColor.getRGB($i),$i.a=i._clearColor.a;else if(s.isColor===!0)s.getRGB($i),$i.a=1,o=!0;else if(s.isNode===!0){const l=this.get(e),c=s;$i.copy(i._clearColor);let u=l.backgroundMesh;if(u===void 0){let y=function(){s.removeEventListener("dispose",y),u.material.dispose(),u.geometry.dispose()};const d=et(c).mul($x).context({getUV:()=>hI.mul(bD),getTextureLevel:()=>uI}),f=ic.element(3).element(3).equal(1),p=Er(1,ic.element(1).element(1)).mul(3),g=f.select(Tn.mul(p),Tn),m=Hc.mul(et(g,0));let _=ic.mul(et(m.xyz,1));_=_.setZ(_.w);const x=new mn;x.name="Background.material",x.side=Lt,x.depthTest=!1,x.depthWrite=!1,x.allowOverride=!1,x.fog=!1,x.lights=!1,x.vertexNode=_,x.colorNode=d,l.backgroundMeshNode=d,l.backgroundMesh=u=new _n(new kc(1,32,32),x),u.frustumCulled=!1,u.name="Background.mesh",s.addEventListener("dispose",y)}const h=c.getCacheKey();l.backgroundCacheKey!==h&&(l.backgroundMeshNode.node=et(c).mul($x),l.backgroundMeshNode.needsUpdate=!0,u.material.needsUpdate=!0,l.backgroundCacheKey=h),t.unshift(u,u.geometry,u.material,0,0,null,null)}else ce("Renderer: Unsupported background configuration.",s);const a=i.xr.getEnvironmentBlendMode();if(a==="additive"?$i.set(0,0,0,1):a==="alpha-blend"&&$i.set(0,0,0,0),i.autoClear===!0||o===!0){const l=n.clearColorValue;l.r=$i.r,l.g=$i.g,l.b=$i.b,l.a=$i.a,(i.backend.isWebGLBackend===!0||i.alpha===!0)&&(l.r*=l.a,l.g*=l.a,l.b*=l.a),n.depthClearValue=i.getClearDepth(),n.stencilClearValue=i.getClearStencil(),n.clearColor=i.autoClearColor===!0,n.clearDepth=i.autoClearDepth===!0,n.clearStencil=i.autoClearStencil===!0}else n.clearColor=!1,n.clearDepth=!1,n.clearStencil=!1}}let h2=0;class Rp{constructor(e="",t=[]){this.name=e,this.bindings=t,this.id=h2++}}class d2{constructor(e,t,n,i,s,o,a,l,c,u=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=n,this.transforms=u,this.nodeAttributes=i,this.bindings=s,this.updateNodes=o,this.updateBeforeNodes=a,this.updateAfterNodes=l,this.observer=c,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings)if(t.bindings[0].groupNode.shared!==!0){const i=new Rp(t.name,[]);e.push(i);for(const s of t.bindings)i.bindings.push(s.clone())}else e.push(t);return e}}class Kx{constructor(e,t,n=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=n}}class f2{constructor(e,t,n){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=n}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class Pb{constructor(e,t,n=!1,i=null){this.isNodeVar=!0,this.name=e,this.type=t,this.readOnly=n,this.count=i}}class p2 extends Pb{constructor(e,t,n=null,i=null){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0,this.interpolationType=n,this.interpolationSampling=i}}class m2{constructor(e,t,n=""){this.name=e,this.type=t,this.code=n,Object.defineProperty(this,"isNodeCode",{value:!0})}}let g2=0;class Lf{constructor(e=null){this.id=g2++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return t===void 0&&this.parent!==null&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class _2{constructor(e,t){this.name=e,this.members=t,this.output=!1}}class Vs{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0,this.index=-1}setValue(e){this.value=e}getValue(){return this.value}}class x2 extends Vs{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class y2 extends Vs{constructor(e,t=new pe){super(e,t),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class v2 extends Vs{constructor(e,t=new P){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class b2 extends Vs{constructor(e,t=new rt){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class S2 extends Vs{constructor(e,t=new We){super(e,t),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class T2 extends Vs{constructor(e,t=new vh){super(e,t),this.isMatrix2Uniform=!0,this.boundary=8,this.itemSize=4}}class M2 extends Vs{constructor(e,t=new Je){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class E2 extends Vs{constructor(e,t=new pt){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class A2 extends x2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class w2 extends y2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class R2 extends v2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class C2 extends b2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class N2 extends S2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class P2 extends T2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class D2 extends M2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class L2 extends E2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}let U2=0;const Zx=new WeakMap,F2=new WeakMap,I2=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),qu=r=>/e/g.test(r)?String(r).replace(/\+/g,""):(r=Number(r),r+(r%1?"":".0"));class Db{constructor(e,t,n){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=n,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.observer=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.types={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.declarations={},this.flow={code:""},this.chaining=[],this.stack=wf(),this.stacks=[],this.tab=" ",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new Lf,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.subBuildLayers=[],this.activeStacks=[],this.subBuildFn=null,this.fnCall=null,Object.defineProperty(this,"id",{value:U2++})}isFlatShading(){return this.material.flatShading===!0||this.geometry.hasAttribute("normal")===!1}isOpaque(){const e=this.material;return e.transparent===!1&&e.blending===ti&&e.alphaToCoverage===!1}createRenderTarget(e,t,n){return new ks(e,t,n)}createCubeRenderTarget(e,t){return new nb(e,t)}includes(e){return this.nodes.includes(e)}getOutputStructName(){}_getBindGroup(e,t){const n=t[0].groupNode;let i=n.shared;if(i)for(let o=1;o<t.length;o++)n!==t[o].groupNode&&(i=!1);let s;if(i){let o="";for(const u of t)if(u.isNodeUniformsGroup){u.uniforms.sort((h,d)=>h.nodeUniform.node.id-d.nodeUniform.node.id);for(const h of u.uniforms)o+=h.nodeUniform.node.id}else o+=u.nodeUniform.id;const a=this.renderer._currentRenderContext||this.renderer;let l=Zx.get(a);l===void 0&&(l=new Map,Zx.set(a,l));const c=cl(o);s=l.get(c),s===void 0&&(s=new Rp(e,t),l.set(c,s))}else s=new Rp(e,t);return s}getBindGroupArray(e,t){const n=this.bindings[t];let i=n[e];return i===void 0&&(this.bindingsIndexes[e]===void 0&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),n[e]=i=[]),i}getBindings(){let e=this.bindGroups;if(e===null){const t={},n=this.bindings;for(const i of of)for(const s in n[i]){const o=n[i][s],a=t[s]||(t[s]=[]);for(const l of o)a.includes(l)===!1&&a.push(l)}e=[];for(const i in t){const s=t[i],o=this._getBindGroup(i,s);e.push(o)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort((t,n)=>t.bindings[0].groupNode.order-n.bindings[0].groupNode.order);for(let t=0;t<e.length;t++){const n=e[t];this.bindingsIndexes[n.name].group=t}}setHashNode(e,t){this.hashNodes[t]=e}addNode(e){this.nodes.includes(e)===!1&&(this.nodes.push(e),this.setHashNode(e,e.getHash(this)))}addSequentialNode(e){const t=e.getUpdateBeforeType(),n=e.getUpdateAfterType();(t!==Ze.NONE||n!==Ze.NONE)&&this.sequentialNodes.includes(e)===!1&&this.sequentialNodes.push(e)}buildUpdateNodes(){for(const e of this.nodes)e.getUpdateType()!==Ze.NONE&&this.updateNodes.push(e);for(const e of this.sequentialNodes){const t=e.getUpdateBeforeType(),n=e.getUpdateAfterType();t!==Ze.NONE&&this.updateBeforeNodes.push(e),n!==Ze.NONE&&this.updateAfterNodes.push(e)}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(e){return e.magFilter===Nt||e.magFilter===ga||e.magFilter===Xr||e.magFilter===ui||e.minFilter===Nt||e.minFilter===ga||e.minFilter===Xr||e.minFilter===ui}getUniformBufferLimit(){return this.renderer.backend.capabilities.getUniformBufferLimit()}addChain(e){this.chaining.push(e)}removeChain(e){if(this.chaining.pop()!==e)throw new Error("NodeBuilder: Invalid node chaining!")}getMethod(e){return e}getTernary(){return null}getNodeFromHash(e){return this.hashNodes[e]}addFlow(e,t){return this.flowNodes[e].push(t),t}setContext(e){this.context=e}getContext(){return this.context}addContext(e){const t=this.getContext();return this.setContext({...this.context,...e}),t}getSharedContext(){const e={...this.context};return delete e.material,delete e.getUV,delete e.getOutput,delete e.getTextureLevel,delete e.getAO,delete e.getShadow,e}setCache(e){this.cache=e}getCache(){return this.cache}getCacheFromNode(e,t=!0){const n=this.getDataFromNode(e);return n.cache===void 0&&(n.cache=new Lf(t?this.getCache():null)),n.cache}isAvailable(){return!1}getVertexIndex(){ae("Abstract function.")}getInstanceIndex(){ae("Abstract function.")}getDrawIndex(){ae("Abstract function.")}getFrontFacing(){ae("Abstract function.")}getFragCoord(){ae("Abstract function.")}isFlipY(){return!1}increaseUsage(e){const t=this.getDataFromNode(e);return t.usageCount=t.usageCount===void 0?1:t.usageCount+1,t.usageCount}generateTexture(){ae("Abstract function.")}generateTextureLod(){ae("Abstract function.")}generateArrayDeclaration(e,t){return this.getType(e)+"[ "+t+" ]"}generateArray(e,t,n=null){let i=this.generateArrayDeclaration(e,t)+"( ";for(let s=0;s<t;s++){const o=n?n[s]:null;o!==null?i+=o.build(this,e):i+=this.generateConst(e),s<t-1&&(i+=", ")}return i+=" )",i}generateStruct(e,t,n=null){const i=[];for(const s of t){const{name:o,type:a}=s;n&&n[o]&&n[o].isNode?i.push(n[o].build(this,a)):i.push(this.generateConst(a))}return e+"( "+i.join(", ")+" )"}generateConst(e,t=null){if(t===null&&(e==="float"||e==="int"||e==="uint"?t=0:e==="bool"?t=!1:e==="color"?t=new We:e==="vec2"||e==="uvec2"||e==="ivec2"?t=new pe:e==="vec3"||e==="uvec3"||e==="ivec3"?t=new P:(e==="vec4"||e==="uvec4"||e==="ivec4")&&(t=new rt)),e==="float")return qu(t);if(e==="int")return`${Math.round(t)}`;if(e==="uint")return t>=0?`${Math.round(t)}u`:"0u";if(e==="bool")return t?"true":"false";if(e==="color")return`${this.getType("vec3")}( ${qu(t.r)}, ${qu(t.g)}, ${qu(t.b)} )`;const n=this.getTypeLength(e),i=this.getComponentType(e),s=o=>this.generateConst(i,o);if(n===2)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)} )`;if(n===3)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)}, ${s(t.z)} )`;if(n===4&&e!=="mat2")return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)}, ${s(t.z)}, ${s(t.w)} )`;if(n>=4&&t&&(t.isMatrix2||t.isMatrix3||t.isMatrix4))return`${this.getType(e)}( ${t.elements.map(s).join(", ")} )`;if(n>4)return`${this.getType(e)}()`;throw new Error(`NodeBuilder: Type '${e}' not found in generate constant attempt.`)}getType(e){return e==="color"?"vec3":e}hasGeometryAttribute(e){return this.geometry&&this.geometry.getAttribute(e)!==void 0}getAttribute(e,t){const n=this.attributes;for(const s of n)if(s.name===e)return s;const i=new Kx(e,t);return this.registerDeclaration(i),n.push(i),i}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return e==="void"||e==="property"||e==="sampler"||e==="samplerComparison"||e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="depthTexture"||e==="texture3D"}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===Sn)return"int";if(t===Ct)return"uint"}return"float"}getElementType(e){return e==="mat2"?"vec2":e==="mat3"?"vec3":e==="mat4"?"vec4":this.getComponentType(e)}getComponentType(e){if(e=this.getVectorType(e),e==="float"||e==="bool"||e==="int"||e==="uint")return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return t===null?null:t[1]==="b"?"bool":t[1]==="i"?"int":t[1]==="u"?"uint":"float"}getVectorType(e){return e==="color"?"vec3":e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="texture3D"?"vec4":e}getTypeFromLength(e,t="float"){if(e===1)return t;let n=Wy(e);const i=t==="float"?"":t[0];return/mat2/.test(t)===!0&&(n=n.replace("vec","mat")),i+n}getTypeFromArray(e){return I2.get(e.constructor)}isInteger(e){return/int|uint|(i|u)vec/.test(e)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const n=t.array,i=e.itemSize,s=e.normalized;let o;return!(e instanceof ey)&&s!==!0&&(o=this.getTypeFromArray(n)),this.getTypeFromLength(i,o)}getTypeLength(e){const t=this.getVectorType(e),n=/vec([2-4])/.exec(t);return n!==null?Number(n[1]):t==="float"||t==="bool"||t==="int"||t==="uint"?1:/mat2/.test(e)===!0?4:/mat3/.test(e)===!0?9:/mat4/.test(e)===!0?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return t==="int"||t==="uint"?e:this.changeComponentType(e,"int")}setActiveStack(e){this.activeStacks.push(e)}removeActiveStack(e){if(this.activeStacks[this.activeStacks.length-1]===e)this.activeStacks.pop();else throw new Error("NodeBuilder: Invalid active stack removal.")}getActiveStack(){return this.activeStacks[this.activeStacks.length-1]}getBaseStack(){return this.activeStacks[0]}addStack(){this.stack=wf(this.stack);const e=Yy();return this.stacks.push(e),Th(this.stack),this.stack}removeStack(){const e=this.stack;for(const t of e.nodes){const n=this.getDataFromNode(t);n.stack=e}return this.stack=e.parent,Th(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,n=null){n=n===null?e.isGlobal(this)?this.globalCache:this.cache:n;let i=n.getData(e);i===void 0&&(i={},n.setData(e,i)),i[t]===void 0&&(i[t]={});let s=i[t];const o=i.any?i.any.subBuilds:null,a=this.getClosestSubBuild(o);return a&&(s.subBuildsCache===void 0&&(s.subBuildsCache={}),s=s.subBuildsCache[a]||(s.subBuildsCache[a]={}),s.subBuilds=o),s}getNodeProperties(e,t="any"){const n=this.getDataFromNode(e,t);return n.properties||(n.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const n=this.getDataFromNode(e,"vertex");let i=n.bufferAttribute;if(i===void 0){const s=this.uniforms.index++;i=new Kx("nodeAttribute"+s,t,e),this.bufferAttributes.push(i),n.bufferAttribute=i}return i}getStructTypeNode(e,t=this.shaderStage){return this.types[t][e]||null}getStructTypeFromNode(e,t,n=null,i=this.shaderStage){const s=this.getDataFromNode(e,i,this.globalCache);let o=s.structType;if(o===void 0){const a=this.structs.index++;n===null&&(n="StructType"+a),o=new _2(n,t),this.structs[i].push(o),this.types[i][n]=e,s.structType=o}return o}getOutputStructTypeFromNode(e,t){const n=this.getStructTypeFromNode(e,t,"OutputType","fragment");return n.output=!0,n}getUniformFromNode(e,t,n=this.shaderStage,i=null){const s=this.getDataFromNode(e,n,this.globalCache);let o=s.uniform;if(o===void 0){const a=this.uniforms.index++;o=new f2(i||"nodeUniform"+a,t,e),this.uniforms[n].push(o),this.registerDeclaration(o),s.uniform=o}return o}getVarFromNode(e,t=null,n=e.getNodeType(this),i=this.shaderStage,s=!1){const o=this.getDataFromNode(e,i),a=this.getSubBuildProperty("variable",o.subBuilds);let l=o[a];if(l===void 0){const c=s?"_const":"_var",u=this.vars[i]||(this.vars[i]=[]),h=this.vars[c]||(this.vars[c]=0);t===null&&(t=(s?"nodeConst":"nodeVar")+h,this.vars[c]++),a!=="variable"&&(t=this.getSubBuildProperty(t,o.subBuilds));const d=e.getArrayCount(this);l=new Pb(t,n,s,d),s||u.push(l),this.registerDeclaration(l),o[a]=l}return l}isDeterministic(e){if(e.isMathNode)return this.isDeterministic(e.aNode)&&(e.bNode?this.isDeterministic(e.bNode):!0)&&(e.cNode?this.isDeterministic(e.cNode):!0);if(e.isOperatorNode)return this.isDeterministic(e.aNode)&&(e.bNode?this.isDeterministic(e.bNode):!0);if(e.isArrayNode){if(e.values!==null){for(const t of e.values)if(!this.isDeterministic(t))return!1}return!0}else if(e.isConstNode)return!0;return!1}getVaryingFromNode(e,t=null,n=e.getNodeType(this),i=null,s=null){const o=this.getDataFromNode(e,"any"),a=this.getSubBuildProperty("varying",o.subBuilds);let l=o[a];if(l===void 0){const c=this.varyings,u=c.length;t===null&&(t="nodeVarying"+u),a!=="varying"&&(t=this.getSubBuildProperty(t,o.subBuilds)),l=new p2(t,n,i,s),c.push(l),this.registerDeclaration(l),o[a]=l}return l}registerDeclaration(e){const t=this.shaderStage,n=this.declarations[t]||(this.declarations[t]={}),i=this.getPropertyName(e);let s=1,o=i;for(;n[o]!==void 0;)o=i+"_"+s++;s>1&&(e.name=o,ae(`TSL: Declaration name '${i}' of '${e.type}' already in use. Renamed to '${o}'.`)),n[o]=e}getCodeFromNode(e,t,n=this.shaderStage){const i=this.getDataFromNode(e);let s=i.code;if(s===void 0){const o=this.codes[n]||(this.codes[n]=[]),a=o.length;s=new m2("nodeCode"+a,t),o.push(s),i.code=s}return s}addFlowCodeHierarchy(e,t){const{flowCodes:n,flowCodeBlock:i}=this.getDataFromNode(e);let s=!0,o=t;for(;o;){if(i.get(o)===!0){s=!1;break}o=this.getDataFromNode(o).parentNodeBlock}if(s)for(const a of n)this.addLineFlowCode(a)}addLineFlowCodeBlock(e,t,n){const i=this.getDataFromNode(e),s=i.flowCodes||(i.flowCodes=[]),o=i.flowCodeBlock||(i.flowCodeBlock=new WeakMap);s.push(t),o.set(n,!0)}addLineFlowCode(e,t=null){return e===""?this:(t!==null&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e=e+`;
4651
+ `):e.addLineFlowCode(`${t}Barrier()`,this)}}It(AI);class Cr extends Ve{static get type(){return"AtomicFunctionNode"}constructor(e,t,n){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=n,this.parents=!0}getInputType(e){return this.pointerNode.getNodeType(e)}generateNodeType(e){return this.getInputType(e)}generate(e){const t=e.getNodeProperties(this),n=t.parents,i=this.method,s=this.getNodeType(e),o=this.getInputType(e),a=this.pointerNode,l=this.valueNode,c=[];c.push(`&${a.build(e,o)}`),l!==null&&c.push(l.build(e,o));const u=`${e.getMethod(i,s)}( ${c.join(", ")} )`;if(n?n.length===1&&n[0].isStackNode===!0:!1)e.addLineFlowCode(u,this);else return t.constNode===void 0&&(t.constNode=mr(u,s).toConst()),t.constNode.build(e)}}Cr.ATOMIC_LOAD="atomicLoad";Cr.ATOMIC_STORE="atomicStore";Cr.ATOMIC_ADD="atomicAdd";Cr.ATOMIC_SUB="atomicSub";Cr.ATOMIC_MAX="atomicMax";Cr.ATOMIC_MIN="atomicMin";Cr.ATOMIC_AND="atomicAnd";Cr.ATOMIC_OR="atomicOr";Cr.ATOMIC_XOR="atomicXor";It(Cr);class bt extends xn{static get type(){return"SubgroupFunctionNode"}constructor(e,t=null,n=null){super(),this.method=e,this.aNode=t,this.bNode=n}getInputType(e){const t=this.aNode?this.aNode.getNodeType(e):null,n=this.bNode?this.bNode.getNodeType(e):null,i=e.isMatrix(t)?0:e.getTypeLength(t),s=e.isMatrix(n)?0:e.getTypeLength(n);return i>s?t:n}generateNodeType(e){const t=this.method;return t===bt.SUBGROUP_ELECT?"bool":t===bt.SUBGROUP_BALLOT?"uvec4":this.getInputType(e)}generate(e,t){const n=this.method,i=this.getNodeType(e),s=this.getInputType(e),o=this.aNode,a=this.bNode,l=[];if(n===bt.SUBGROUP_BROADCAST||n===bt.SUBGROUP_SHUFFLE||n===bt.QUAD_BROADCAST){const u=a.getNodeType(e);l.push(o.build(e,i),a.build(e,u==="float"?"int":i))}else n===bt.SUBGROUP_SHUFFLE_XOR||n===bt.SUBGROUP_SHUFFLE_DOWN||n===bt.SUBGROUP_SHUFFLE_UP?l.push(o.build(e,i),a.build(e,"uint")):(o!==null&&l.push(o.build(e,s)),a!==null&&l.push(a.build(e,s)));const c=l.length===0?"()":`( ${l.join(", ")} )`;return e.format(`${e.getMethod(n,i)}${c}`,i,t)}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}bt.SUBGROUP_ELECT="subgroupElect";bt.SUBGROUP_BALLOT="subgroupBallot";bt.SUBGROUP_ADD="subgroupAdd";bt.SUBGROUP_INCLUSIVE_ADD="subgroupInclusiveAdd";bt.SUBGROUP_EXCLUSIVE_AND="subgroupExclusiveAdd";bt.SUBGROUP_MUL="subgroupMul";bt.SUBGROUP_INCLUSIVE_MUL="subgroupInclusiveMul";bt.SUBGROUP_EXCLUSIVE_MUL="subgroupExclusiveMul";bt.SUBGROUP_AND="subgroupAnd";bt.SUBGROUP_OR="subgroupOr";bt.SUBGROUP_XOR="subgroupXor";bt.SUBGROUP_MIN="subgroupMin";bt.SUBGROUP_MAX="subgroupMax";bt.SUBGROUP_ALL="subgroupAll";bt.SUBGROUP_ANY="subgroupAny";bt.SUBGROUP_BROADCAST_FIRST="subgroupBroadcastFirst";bt.QUAD_SWAP_X="quadSwapX";bt.QUAD_SWAP_Y="quadSwapY";bt.QUAD_SWAP_DIAGONAL="quadSwapDiagonal";bt.SUBGROUP_BROADCAST="subgroupBroadcast";bt.SUBGROUP_SHUFFLE="subgroupShuffle";bt.SUBGROUP_SHUFFLE_XOR="subgroupShuffleXor";bt.SUBGROUP_SHUFFLE_UP="subgroupShuffleUp";bt.SUBGROUP_SHUFFLE_DOWN="subgroupShuffleDown";bt.QUAD_BROADCAST="quadBroadcast";let $u;function ed(r){$u=$u||new WeakMap;let e=$u.get(r);return e===void 0&&$u.set(r,e={}),e}function Km(r){const e=ed(r);return e.shadowMatrix||(e.shadowMatrix=qe("mat4").setGroup(Ke).onRenderUpdate(t=>((r.castShadow!==!0||t.renderer.shadowMap.enabled===!1)&&(r.shadow.camera.coordinateSystem!==t.camera.coordinateSystem&&(r.shadow.camera.coordinateSystem=t.camera.coordinateSystem,r.shadow.camera.updateProjectionMatrix()),r.shadow.updateMatrices(r)),r.shadow.matrix)))}function wI(r,e=Ja){const t=Km(r).mul(e);return t.xyz.div(t.w)}function Mb(r){const e=ed(r);return e.position||(e.position=qe(new P).setGroup(Ke).onRenderUpdate((t,n)=>n.value.setFromMatrixPosition(r.matrixWorld)))}function RI(r){const e=ed(r);return e.targetPosition||(e.targetPosition=qe(new P).setGroup(Ke).onRenderUpdate((t,n)=>n.value.setFromMatrixPosition(r.target.matrixWorld)))}function Eb(r){const e=ed(r);return e.viewPosition||(e.viewPosition=qe(new P).setGroup(Ke).onRenderUpdate(({camera:t},n)=>{n.value=n.value||new P,n.value.setFromMatrixPosition(r.matrixWorld),n.value.applyMatrix4(t.matrixWorldInverse)}))}const Ab=r=>es.transformDirection(Mb(r).sub(RI(r))),CI=r=>r.sort((e,t)=>e.id-t.id),NI=(r,e)=>{for(const t of e)if(t.isAnalyticLightNode&&t.light.id===r)return t;return null},Nf=new WeakMap,Ol=[];class wb extends Ve{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Ns("vec3","totalDiffuse"),this.totalSpecularNode=Ns("vec3","totalSpecular"),this.outgoingLightNode=Ns("vec3","outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}customCacheKey(){const e=this._lights;for(let n=0;n<e.length;n++){const i=e[n];if(Ol.push(i.id),Ol.push(i.castShadow?1:0),i.isSpotLight===!0){const s=i.map!==null?i.map.id:-1,o=i.colorNode?i.colorNode.getCacheKey():-1;Ol.push(s,o)}}const t=Gc(Ol);return Ol.length=0,t}getHash(e){if(this._lightNodesHash===null){this._lightNodes===null&&this.setupLightsNode(e);const t=[];for(const n of this._lightNodes)t.push(n.getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getNodeProperties(this);for(const n of t.nodes)n.build(e);t.outputNode.build(e)}setupLightsNode(e){const t=[],n=this._lightNodes,i=CI(this._lights),s=e.renderer.library;for(const o of i)if(o.isNode)t.push(Ge(o));else{let a=null;if(n!==null&&(a=NI(o.id,n)),a===null){const l=s.getLightNodeClass(o.constructor);if(l===null){ae(`LightsNode.setupNodeLights: Light node not found for ${o.constructor.name}`);continue}Nf.has(o)===!1&&Nf.set(o,new l(o)),a=Nf.get(o)}t.push(a)}this._lightNodes=t}setupDirectLight(e,t,n){const{lightingModel:i,reflectedLight:s}=e.context;i.direct({...n,lightNode:t,reflectedLight:s},e)}setupDirectRectAreaLight(e,t,n){const{lightingModel:i,reflectedLight:s}=e.context;i.directRectArea({...n,lightNode:t,reflectedLight:s},e)}setupLights(e,t){for(const n of t)n.build(e)}getLightNodes(e){return this._lightNodes===null&&this.setupLightsNode(e),this._lightNodes}setup(e){const t=e.lightsNode;e.lightsNode=this;let n=this.outgoingLightNode;const i=e.context,s=i.lightingModel,o=e.getNodeProperties(this);if(s){const{totalDiffuseNode:a,totalSpecularNode:l}=this;i.outgoingLight=n;const c=e.addStack();o.nodes=c.nodes,s.start(e);const{backdrop:u,backdropAlpha:h}=i,{directDiffuse:d,directSpecular:f,indirectDiffuse:p,indirectSpecular:g}=i.reflectedLight;let m=d.add(p);u!==null&&(h!==null?m=te(h.mix(m,u)):m=te(u)),a.assign(m),l.assign(f.add(g)),n.assign(a.add(l)),s.finish(e),n=n.bypass(e.removeStack())}else o.nodes=[];return e.lightsNode=t,n}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}class PI extends Ve{static get type(){return"ShadowBaseNode"}constructor(e){super(),this.light=e,this.updateBeforeType=Ze.RENDER,this.isShadowBaseNode=!0}setupShadowPosition({context:e,material:t}){Rb.assign(t.receivedShadowPositionNode||e.shadowPositionWorld||Ja)}}const Rb=Ns("vec3","shadowPositionWorld");function DI(r,e={}){return e.toneMapping=r.toneMapping,e.toneMappingExposure=r.toneMappingExposure,e.outputColorSpace=r.outputColorSpace,e.renderTarget=r.getRenderTarget(),e.activeCubeFace=r.getActiveCubeFace(),e.activeMipmapLevel=r.getActiveMipmapLevel(),e.renderObjectFunction=r.getRenderObjectFunction(),e.pixelRatio=r.getPixelRatio(),e.mrt=r.getMRT(),e.clearColor=r.getClearColor(e.clearColor||new We),e.clearAlpha=r.getClearAlpha(),e.autoClear=r.autoClear,e.scissorTest=r.getScissorTest(),e}function LI(r,e){return e=DI(r,e),r.setMRT(null),r.setRenderObjectFunction(null),r.setClearColor(0,1),r.autoClear=!0,e}function UI(r,e){r.toneMapping=e.toneMapping,r.toneMappingExposure=e.toneMappingExposure,r.outputColorSpace=e.outputColorSpace,r.setRenderTarget(e.renderTarget,e.activeCubeFace,e.activeMipmapLevel),r.setRenderObjectFunction(e.renderObjectFunction),r.setPixelRatio(e.pixelRatio),r.setMRT(e.mrt),r.setClearColor(e.clearColor,e.clearAlpha),r.autoClear=e.autoClear,r.setScissorTest(e.scissorTest)}function FI(r,e={}){return e.background=r.background,e.backgroundNode=r.backgroundNode,e.overrideMaterial=r.overrideMaterial,e}function II(r,e){return e=FI(r,e),r.background=null,r.backgroundNode=null,r.overrideMaterial=null,e}function BI(r,e){r.background=e.background,r.backgroundNode=e.backgroundNode,r.overrideMaterial=e.overrideMaterial}function OI(r,e,t){return t=LI(r,t),t=II(e,t),t}function kI(r,e,t){UI(r,t),BI(e,t)}const Ch=new WeakMap,GI=re(({depthTexture:r,shadowCoord:e,depthLayer:t})=>{let n=Vt(r,e.xy).setName("t_basic");return r.isArrayTexture&&(n=n.depth(t)),n.compare(e.z)}),VI=re(({depthTexture:r,shadowCoord:e,shadow:t,depthLayer:n})=>{const i=(u,h)=>{let d=Vt(r,u);return r.isArrayTexture&&(d=d.depth(n)),d.compare(h)},s=Jt("mapSize","vec2",t).setGroup(Ke),o=Jt("radius","float",t).setGroup(Ke),a=ke(1).div(s),l=o.mul(a.x),c=Tb(pl.xy).mul(6.28318530718);return fi(i(e.xy.add(gr(0,5,c).mul(l)),e.z),i(e.xy.add(gr(1,5,c).mul(l)),e.z),i(e.xy.add(gr(2,5,c).mul(l)),e.z),i(e.xy.add(gr(3,5,c).mul(l)),e.z),i(e.xy.add(gr(4,5,c).mul(l)),e.z)).mul(1/5)}),zI=re(({depthTexture:r,shadowCoord:e,shadow:t,depthLayer:n})=>{const i=(h,d)=>{let f=Vt(r,h);return r.isArrayTexture&&(f=f.depth(n)),f.compare(d)},s=Jt("mapSize","vec2",t).setGroup(Ke),o=ke(1).div(s),a=o.x,l=o.y,c=e.xy,u=Ar(c.mul(s).add(.5));return c.subAssign(u.mul(o)),fi(i(c,e.z),i(c.add(ke(a,0)),e.z),i(c.add(ke(0,l)),e.z),i(c.add(o),e.z),Dt(i(c.add(ke(a.negate(),0)),e.z),i(c.add(ke(a.mul(2),0)),e.z),u.x),Dt(i(c.add(ke(a.negate(),l)),e.z),i(c.add(ke(a.mul(2),l)),e.z),u.x),Dt(i(c.add(ke(0,l.negate())),e.z),i(c.add(ke(0,l.mul(2))),e.z),u.y),Dt(i(c.add(ke(a,l.negate())),e.z),i(c.add(ke(a,l.mul(2))),e.z),u.y),Dt(Dt(i(c.add(ke(a.negate(),l.negate())),e.z),i(c.add(ke(a.mul(2),l.negate())),e.z),u.x),Dt(i(c.add(ke(a.negate(),l.mul(2))),e.z),i(c.add(ke(a.mul(2),l.mul(2))),e.z),u.x),u.y)).mul(1/9)}),HI=re(({depthTexture:r,shadowCoord:e,depthLayer:t},n)=>{let i=Vt(r).sample(e.xy);r.isArrayTexture&&(i=i.depth(t)),i=i.rg;const s=i.x,o=kn(1e-7,i.y.mul(i.y)),a=n.renderer.reversedDepthBuffer?Ec(s,e.z):Ec(e.z,s),l=J(1).toVar();return Ft(a.notEqual(1),()=>{const c=e.z.sub(s);let u=o.div(o.add(c.mul(c)));u=Fs(oi(u,.3).div(.65)),l.assign(kn(a,u))}),l}),WI=r=>{let e=Ch.get(r);return e===void 0&&(e=new mn,e.colorNode=et(0,0,0,1),e.isShadowPassMaterial=!0,e.name="ShadowMaterial",e.blending=Pn,e.fog=!1,Ch.set(r,e)),e},$I=r=>{const e=Ch.get(r);e!==void 0&&(e.dispose(),Ch.delete(r))},jx=new Bs,sa=[],XI=(r,e,t,n)=>{sa[0]=r,sa[1]=e;let i=jx.get(sa);return(i===void 0||i.shadowType!==t||i.useVelocity!==n)&&(i=(s,o,a,l,c,u,...h)=>{(s.castShadow===!0||s.receiveShadow&&t===_r)&&(n&&($y(s).useVelocity=!0),s.onBeforeShadow(r,s,a,e.camera,l,o.overrideMaterial,u),r.renderObject(s,o,a,l,c,u,...h),s.onAfterShadow(r,s,a,e.camera,l,o.overrideMaterial,u))},i.shadowType=t,i.useVelocity=n,jx.set(sa,i)),sa[0]=null,sa[1]=null,i},qI=re(({samples:r,radius:e,size:t,shadowPass:n,depthLayer:i})=>{const s=J(0).toVar("meanVertical"),o=J(0).toVar("squareMeanVertical"),a=r.lessThanEqual(J(1)).select(J(0),J(2).div(r.sub(1))),l=r.lessThanEqual(J(1)).select(J(0),J(-1));Di({start:Zt(0),end:Zt(r),type:"int",condition:"<"},({i:u})=>{const h=l.add(J(u).mul(a));let d=n.sample(fi(pl.xy,ke(0,h).mul(e)).div(t));n.value.isArrayTexture&&(d=d.depth(i)),d=d.x,s.addAssign(d),o.addAssign(d.mul(d))}),s.divAssign(r),o.divAssign(r);const c=Ps(o.sub(s.mul(s)).max(0));return ke(s,c)}),jI=re(({samples:r,radius:e,size:t,shadowPass:n,depthLayer:i})=>{const s=J(0).toVar("meanHorizontal"),o=J(0).toVar("squareMeanHorizontal"),a=r.lessThanEqual(J(1)).select(J(0),J(2).div(r.sub(1))),l=r.lessThanEqual(J(1)).select(J(0),J(-1));Di({start:Zt(0),end:Zt(r),type:"int",condition:"<"},({i:u})=>{const h=l.add(J(u).mul(a));let d=n.sample(fi(pl.xy,ke(h,0).mul(e)).div(t));n.value.isArrayTexture&&(d=d.depth(i)),s.addAssign(d.x),o.addAssign(fi(d.y.mul(d.y),d.x.mul(d.x)))}),s.divAssign(r),o.divAssign(r);const c=Ps(o.sub(s.mul(s)).max(0));return ke(s,c)}),YI=[GI,VI,zI,HI];let Pf;const Xu=new Sb;class Cb extends PI{static get type(){return"ShadowNode"}constructor(e,t=null){super(e),this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this._node=null,this._currentShadowType=null,this._cameraFrameId=new WeakMap,this.isShadowNode=!0,this.depthLayer=0}setupShadowFilter(e,{filterFn:t,depthTexture:n,shadowCoord:i,shadow:s,depthLayer:o}){const a=i.x.greaterThanEqual(0).and(i.x.lessThanEqual(1)).and(i.y.greaterThanEqual(0)).and(i.y.lessThanEqual(1)).and(i.z.lessThanEqual(1)),l=t({depthTexture:n,shadowCoord:i,shadow:s,depthLayer:o});return a.select(l,J(1))}setupShadowCoord(e,t){const{shadow:n}=this,{renderer:i}=e,s=n.biasNode||Jt("bias","float",n).setGroup(Ke);let o=t,a;if(n.camera.isOrthographicCamera||i.logarithmicDepthBuffer!==!0)o=o.xyz.div(o.w),a=o.z;else{const l=o.w;o=o.xy.div(l);const c=Jt("near","float",n.camera).setGroup(Ke),u=Jt("far","float",n.camera).setGroup(Ke);a=Qv(l.negate(),c,u)}return o=te(o.x,o.y.oneMinus(),i.reversedDepthBuffer?a.sub(s):a.add(s)),o}getShadowFilterFn(e){return YI[e]}setupRenderTarget(e,t){const n=new jn(e.mapSize.width,e.mapSize.height);n.name="ShadowDepthTexture",n.compareFunction=t.renderer.reversedDepthBuffer?Zr:Os;const i=t.createRenderTarget(e.mapSize.width,e.mapSize.height);return i.texture.name="ShadowMap",i.texture.type=e.mapType,i.depthTexture=n,{shadowMap:i,depthTexture:n}}setupShadow(e){const{renderer:t,camera:n}=e,{light:i,shadow:s}=this,{depthTexture:o,shadowMap:a}=this.setupRenderTarget(s,e),l=t.shadowMap.type,c=t.hasCompatibility(wo.TEXTURE_COMPARE);if((l===fa||l===G0)&&c?(o.minFilter=Nt,o.magFilter=Nt):(o.minFilter=Mt,o.magFilter=Mt),s.camera.coordinateSystem=n.coordinateSystem,s.camera.updateProjectionMatrix(),l===_r&&s.isPointLightShadow!==!0){o.compareFunction=null,a.depth>1?(a._vsmShadowMapVertical||(a._vsmShadowMapVertical=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:In,type:tn,depth:a.depth,depthBuffer:!1}),a._vsmShadowMapVertical.texture.name="VSMVertical"),this.vsmShadowMapVertical=a._vsmShadowMapVertical,a._vsmShadowMapHorizontal||(a._vsmShadowMapHorizontal=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:In,type:tn,depth:a.depth,depthBuffer:!1}),a._vsmShadowMapHorizontal.texture.name="VSMHorizontal"),this.vsmShadowMapHorizontal=a._vsmShadowMapHorizontal):(this.vsmShadowMapVertical=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:In,type:tn,depthBuffer:!1}),this.vsmShadowMapHorizontal=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:In,type:tn,depthBuffer:!1}));let S=Vt(o);o.isArrayTexture&&(S=S.depth(this.depthLayer));let E=Vt(this.vsmShadowMapVertical.texture);o.isArrayTexture&&(E=E.depth(this.depthLayer));const v=Jt("blurSamples","float",s).setGroup(Ke),w=Jt("radius","float",s).setGroup(Ke),N=Jt("mapSize","vec2",s).setGroup(Ke);let C=this.vsmMaterialVertical||(this.vsmMaterialVertical=new mn);C.fragmentNode=qI({samples:v,radius:w,size:N,shadowPass:S,depthLayer:this.depthLayer}).context(e.getSharedContext()),C.name="VSMVertical",C=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new mn),C.fragmentNode=jI({samples:v,radius:w,size:N,shadowPass:E,depthLayer:this.depthLayer}).context(e.getSharedContext()),C.name="VSMHorizontal"}const u=Jt("intensity","float",s).setGroup(Ke),h=Jt("normalBias","float",s).setGroup(Ke),d=Km(i),f=ml.mul(h);let p;!t.highPrecision||e.material.receivedShadowPositionNode||e.context.shadowPositionWorld?p=d.mul(Rb.add(f)):p=qe("mat4").onObjectUpdate(({object:E},v)=>v.value.multiplyMatrices(d.value,E.matrixWorld)).mul(Tn).add(d.mul(et(f,0)));const g=this.setupShadowCoord(e,p),m=s.filterNode||this.getShadowFilterFn(t.shadowMap.type)||null;if(m===null)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const _=l===_r&&s.isPointLightShadow!==!0?this.vsmShadowMapHorizontal.texture:o,x=this.setupShadowFilter(e,{filterFn:m,shadowTexture:a.texture,depthTexture:_,shadowCoord:g,shadow:s,depthLayer:this.depthLayer});let y;t.shadowMap.transmitted===!0&&(a.texture.isCubeTexture?y=li(a.texture,g.xyz):(y=Vt(a.texture,g),o.isArrayTexture&&(y=y.depth(this.depthLayer))));let b;y?b=Dt(1,x.rgb.mix(y,1),u.mul(y.a)).toVar():b=Dt(1,x,u).toVar(),this.shadowMap=a,this.shadow.map=a;const M=`${this.light.type} Shadow [ ${this.light.name||"ID: "+this.light.id} ]`;return y&&b.toInspector(`${M} / Color`,()=>this.shadowMap.texture.isCubeTexture?li(this.shadowMap.texture):Vt(this.shadowMap.texture)),b.toInspector(`${M} / Depth`,()=>this.shadowMap.texture.isCubeTexture?li(this.shadowMap.texture).r.oneMinus():Ci(this.shadowMap.depthTexture,dl().mul(Ta(Vt(this.shadowMap.depthTexture)))).r.oneMinus())}setup(e){if(e.renderer.shadowMap.enabled!==!1)return re(()=>{const t=e.renderer.shadowMap.type;this._currentShadowType!==t&&(this._reset(),this._node=null);let n=this._node;return this.setupShadowPosition(e),n===null&&(this._node=n=this.setupShadow(e),this._currentShadowType=t),e.material.receivedShadowNode&&(n=e.material.receivedShadowNode(n)),n})()}renderShadow(e){const{shadow:t,shadowMap:n,light:i}=this,{renderer:s,scene:o}=e;t.updateMatrices(i),n.setSize(t.mapSize.width,t.mapSize.height,n.depth);const a=o.name;o.name=`Shadow Map [ ${i.name||"ID: "+i.id} ]`,s.render(o,t.camera),o.name=a}updateShadow(e){const{shadowMap:t,light:n,shadow:i}=this,{renderer:s,scene:o,camera:a}=e,l=s.shadowMap.type,c=t.depthTexture.version;this._depthVersionCached=c;const u=i.camera.layers.mask;(i.camera.layers.mask&4294967294)===0&&(i.camera.layers.mask=a.layers.mask);const h=s.getRenderObjectFunction(),d=s.getMRT(),f=d?d.has("velocity"):!1;Pf=OI(s,o,Pf),o.overrideMaterial=WI(n),s.setRenderObjectFunction(XI(s,i,l,f)),s.setClearColor(0,0),s.setRenderTarget(t),this.renderShadow(e),s.setRenderObjectFunction(h),l===_r&&i.isPointLightShadow!==!0&&this.vsmPass(s),i.camera.layers.mask=u,kI(s,o,Pf)}vsmPass(e){const{shadow:t}=this,n=this.shadowMap.depth;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height,n),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height,n),e.setRenderTarget(this.vsmShadowMapVertical),Xu.material=this.vsmMaterialVertical,Xu.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),Xu.material=this.vsmMaterialHorizontal,Xu.render(e)}dispose(){this._reset(),super.dispose()}_reset(){this._currentShadowType=null,$I(this.light),this.shadowMap&&(this.shadowMap.dispose(),this.shadowMap=null),this.vsmShadowMapVertical!==null&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),this.vsmShadowMapHorizontal!==null&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null)}updateBefore(e){const{shadow:t}=this;let n=t.needsUpdate||t.autoUpdate;n&&(this._cameraFrameId[e.camera]===e.frameId&&(n=!1),this._cameraFrameId[e.camera]=e.frameId),n&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const KI=(r,e)=>new Cb(r,e),ZI=new We,Yx=new pt,kl=new P,Df=new P,QI=[new P(1,0,0),new P(-1,0,0),new P(0,-1,0),new P(0,1,0),new P(0,0,1),new P(0,0,-1)],JI=[new P(0,-1,0),new P(0,-1,0),new P(0,0,-1),new P(0,0,1),new P(0,-1,0),new P(0,-1,0)],e2=[new P(1,0,0),new P(-1,0,0),new P(0,1,0),new P(0,-1,0),new P(0,0,1),new P(0,0,-1)],t2=[new P(0,-1,0),new P(0,-1,0),new P(0,0,1),new P(0,0,-1),new P(0,-1,0),new P(0,-1,0)],n2=re(({depthTexture:r,bd3D:e,dp:t})=>li(r,e).compare(t)),i2=re(({depthTexture:r,bd3D:e,dp:t,shadow:n})=>{const i=Jt("radius","float",n).setGroup(Ke),s=Jt("mapSize","vec2",n).setGroup(Ke),o=i.div(s.x),a=bi(e),l=br(So(e,a.x.greaterThan(a.z).select(te(0,1,0),te(1,0,0)))),c=So(e,l),u=Tb(pl.xy).mul(6.28318530718),h=gr(0,5,u),d=gr(1,5,u),f=gr(2,5,u),p=gr(3,5,u),g=gr(4,5,u);return li(r,e.add(l.mul(h.x).add(c.mul(h.y)).mul(o))).compare(t).add(li(r,e.add(l.mul(d.x).add(c.mul(d.y)).mul(o))).compare(t)).add(li(r,e.add(l.mul(f.x).add(c.mul(f.y)).mul(o))).compare(t)).add(li(r,e.add(l.mul(p.x).add(c.mul(p.y)).mul(o))).compare(t)).add(li(r,e.add(l.mul(g.x).add(c.mul(g.y)).mul(o))).compare(t)).mul(1/5)}),r2=re(({filterFn:r,depthTexture:e,shadowCoord:t,shadow:n},i)=>{const s=t.xyz.toConst(),o=s.abs().toConst(),a=o.x.max(o.y).max(o.z),l=qe("float").setGroup(Ke).onRenderUpdate(()=>n.camera.near),c=qe("float").setGroup(Ke).onRenderUpdate(()=>n.camera.far),u=Jt("bias","float",n).setGroup(Ke),h=J(1).toVar();return Ft(a.sub(c).lessThanEqual(0).and(a.sub(l).greaterThanEqual(0)),()=>{let d;i.renderer.reversedDepthBuffer?(d=qL(a.negate(),l,c),d.subAssign(u)):(d=Kv(a.negate(),l,c),d.addAssign(u));const f=s.normalize();h.assign(r({depthTexture:e,bd3D:f,dp:d,shadow:n}))}),h});class s2 extends Cb{static get type(){return"PointShadowNode"}constructor(e,t=null){super(e,t)}getShadowFilterFn(e){return e===DS?n2:i2}setupShadowCoord(e,t){return t}setupShadowFilter(e,{filterFn:t,depthTexture:n,shadowCoord:i,shadow:s}){return r2({filterFn:t,depthTexture:n,shadowCoord:i,shadow:s})}setupRenderTarget(e,t){const n=new iy(e.mapSize.width);n.name="PointShadowDepthTexture",n.compareFunction=t.renderer.reversedDepthBuffer?Zr:Os;const i=t.createCubeRenderTarget(e.mapSize.width);return i.texture.name="PointShadowMap",i.depthTexture=n,{shadowMap:i,depthTexture:n}}renderShadow(e){const{shadow:t,shadowMap:n,light:i}=this,{renderer:s,scene:o}=e,a=t.camera,l=t.matrix,c=s.coordinateSystem===Tr,u=c?QI:e2,h=c?JI:t2;n.setSize(t.mapSize.width,t.mapSize.width);const d=s.autoClear,f=s.getClearColor(ZI),p=s.getClearAlpha();s.autoClear=!1,s.setClearColor(t.clearColor,t.clearAlpha);for(let g=0;g<6;g++){s.setRenderTarget(n,g),s.clear();const m=i.distance||a.far;m!==a.far&&(a.far=m,a.updateProjectionMatrix()),kl.setFromMatrixPosition(i.matrixWorld),a.position.copy(kl),Df.copy(a.position),Df.add(u[g]),a.up.copy(h[g]),a.lookAt(Df),a.updateMatrixWorld(),l.makeTranslation(-kl.x,-kl.y,-kl.z),Yx.multiplyMatrices(a.projectionMatrix,a.matrixWorldInverse),t._frustum.setFromProjectionMatrix(Yx,a.coordinateSystem,a.reversedDepth);const _=o.name;o.name=`Point Light Shadow [ ${i.name||"ID: "+i.id} ] - Face ${g+1}`,s.render(o,a),o.name=_}s.autoClear=d,s.setClearColor(f,p)}}const o2=(r,e)=>new s2(r,e);class Lo extends gl{static get type(){return"AnalyticLightNode"}constructor(e=null){super(),this.light=e,this.color=new We,this.colorNode=e&&e.colorNode||qe(this.color).setGroup(Ke),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0,this.updateType=Ze.FRAME,e&&e.shadow&&(this._shadowDisposeListener=()=>{this.disposeShadow()},e.addEventListener("dispose",this._shadowDisposeListener))}dispose(){this._shadowDisposeListener&&this.light.removeEventListener("dispose",this._shadowDisposeListener),super.dispose()}disposeShadow(){this.shadowNode!==null&&(this.shadowNode.dispose(),this.shadowNode=null),this.shadowColorNode=null,this.baseColorNode!==null&&(this.colorNode=this.baseColorNode,this.baseColorNode=null)}getHash(){return this.light.uuid}getLightVector(e){return Eb(this.light).sub(e.context.positionView||dn)}setupDirect(){}setupDirectRectArea(){}setupShadowNode(){return KI(this.light)}setupShadow(e){const{renderer:t}=e;if(t.shadowMap.enabled===!1)return;let n=this.shadowColorNode;if(n===null){const i=this.light.shadow.shadowNode;let s;i!==void 0?s=Ge(i):s=this.setupShadowNode(),this.shadowNode=s,this.shadowColorNode=n=this.colorNode.mul(s),this.baseColorNode=this.colorNode}e.context.getShadow&&(n=e.context.getShadow(this,e)),this.colorNode=n}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):this.shadowNode!==null&&(this.shadowNode.dispose(),this.shadowNode=null,this.shadowColorNode=null);const t=this.setupDirect(e),n=this.setupDirectRectArea(e);t&&e.lightsNode.setupDirectLight(e,this,t),n&&e.lightsNode.setupDirectRectAreaLight(e,this,n)}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const Nb=re(({lightDistance:r,cutoffDistance:e,decayExponent:t})=>{const n=r.pow(t).max(.01).reciprocal();return e.greaterThan(0).select(n.mul(r.div(e).pow4().oneMinus().clamp().pow2()),n)}),a2=({color:r,lightVector:e,cutoffDistance:t,decayExponent:n})=>{const i=e.normalize(),s=e.length(),o=Nb({lightDistance:s,cutoffDistance:t,decayExponent:n}),a=r.mul(o);return{lightDirection:i,lightColor:a}};class l2 extends Lo{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=qe(0).setGroup(Ke),this.decayExponentNode=qe(2).setGroup(Ke)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setupShadowNode(){return o2(this.light)}setupDirect(e){return a2({color:this.colorNode,lightVector:this.getLightVector(e),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode})}}re(([r=dl()],{renderer:e,material:t})=>{const n=_v(r.mul(2).sub(1));let i;if(t.alphaToCoverage&&e.currentSamples>0){const s=J(n.fwidth()).toVar();i=Qr(s.oneMinus(),s.add(1),n).oneMinus()}else i=Ti(n.greaterThan(1),0,1);return i});const c2=re(([r,e])=>{const t=r.x,n=r.y,i=r.z;let s=e.element(0).mul(.886227);return s=s.add(e.element(1).mul(2*.511664).mul(n)),s=s.add(e.element(2).mul(2*.511664).mul(i)),s=s.add(e.element(3).mul(2*.511664).mul(t)),s=s.add(e.element(4).mul(2*.429043).mul(t).mul(n)),s=s.add(e.element(5).mul(2*.429043).mul(n).mul(i)),s=s.add(e.element(6).mul(i.mul(i).mul(.743125).sub(.247708))),s=s.add(e.element(7).mul(2*.429043).mul(t).mul(i)),s=s.add(e.element(8).mul(.429043).mul(st(t,t).sub(st(n,n)))),s}),$i=new jm;class u2 extends Gs{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,n){const i=this.renderer,s=this.nodes.getBackgroundNode(e)||e.background;let o=!1;if(s===null)i._clearColor.getRGB($i),$i.a=i._clearColor.a;else if(s.isColor===!0)s.getRGB($i),$i.a=1,o=!0;else if(s.isNode===!0){const l=this.get(e),c=s;$i.copy(i._clearColor);let u=l.backgroundMesh;if(u===void 0){let y=function(){s.removeEventListener("dispose",y),u.material.dispose(),u.geometry.dispose()};const d=et(c).mul($x).context({getUV:()=>hI.mul(bD),getTextureLevel:()=>uI}),f=ic.element(3).element(3).equal(1),p=Er(1,ic.element(1).element(1)).mul(3),g=f.select(Tn.mul(p),Tn),m=Hc.mul(et(g,0));let _=ic.mul(et(m.xyz,1));_=_.setZ(_.w);const x=new mn;x.name="Background.material",x.side=Lt,x.depthTest=!1,x.depthWrite=!1,x.allowOverride=!1,x.fog=!1,x.lights=!1,x.vertexNode=_,x.colorNode=d,l.backgroundMeshNode=d,l.backgroundMesh=u=new _n(new kc(1,32,32),x),u.frustumCulled=!1,u.name="Background.mesh",s.addEventListener("dispose",y)}const h=c.getCacheKey();l.backgroundCacheKey!==h&&(l.backgroundMeshNode.node=et(c).mul($x),l.backgroundMeshNode.needsUpdate=!0,u.material.needsUpdate=!0,l.backgroundCacheKey=h),t.unshift(u,u.geometry,u.material,0,0,null,null)}else ce("Renderer: Unsupported background configuration.",s);const a=i.xr.getEnvironmentBlendMode();if(a==="additive"?$i.set(0,0,0,1):a==="alpha-blend"&&$i.set(0,0,0,0),i.autoClear===!0||o===!0){const l=n.clearColorValue;l.r=$i.r,l.g=$i.g,l.b=$i.b,l.a=$i.a,(i.backend.isWebGLBackend===!0||i.alpha===!0)&&(l.r*=l.a,l.g*=l.a,l.b*=l.a),n.depthClearValue=i.getClearDepth(),n.stencilClearValue=i.getClearStencil(),n.clearColor=i.autoClearColor===!0,n.clearDepth=i.autoClearDepth===!0,n.clearStencil=i.autoClearStencil===!0}else n.clearColor=!1,n.clearDepth=!1,n.clearStencil=!1}}let h2=0;class Rp{constructor(e="",t=[]){this.name=e,this.bindings=t,this.id=h2++}}class d2{constructor(e,t,n,i,s,o,a,l,c,u=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=n,this.transforms=u,this.nodeAttributes=i,this.bindings=s,this.updateNodes=o,this.updateBeforeNodes=a,this.updateAfterNodes=l,this.observer=c,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings)if(t.bindings[0].groupNode.shared!==!0){const i=new Rp(t.name,[]);e.push(i);for(const s of t.bindings)i.bindings.push(s.clone())}else e.push(t);return e}}class Kx{constructor(e,t,n=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=n}}class f2{constructor(e,t,n){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=n}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class Pb{constructor(e,t,n=!1,i=null){this.isNodeVar=!0,this.name=e,this.type=t,this.readOnly=n,this.count=i}}class p2 extends Pb{constructor(e,t,n=null,i=null){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0,this.interpolationType=n,this.interpolationSampling=i}}class m2{constructor(e,t,n=""){this.name=e,this.type=t,this.code=n,Object.defineProperty(this,"isNodeCode",{value:!0})}}let g2=0;class Lf{constructor(e=null){this.id=g2++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return t===void 0&&this.parent!==null&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class _2{constructor(e,t){this.name=e,this.members=t,this.output=!1}}class Vs{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0,this.index=-1}setValue(e){this.value=e}getValue(){return this.value}}class x2 extends Vs{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class y2 extends Vs{constructor(e,t=new pe){super(e,t),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class v2 extends Vs{constructor(e,t=new P){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class b2 extends Vs{constructor(e,t=new rt){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class S2 extends Vs{constructor(e,t=new We){super(e,t),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class T2 extends Vs{constructor(e,t=new vh){super(e,t),this.isMatrix2Uniform=!0,this.boundary=8,this.itemSize=4}}class M2 extends Vs{constructor(e,t=new Je){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class E2 extends Vs{constructor(e,t=new pt){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class A2 extends x2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class w2 extends y2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class R2 extends v2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class C2 extends b2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class N2 extends S2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class P2 extends T2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class D2 extends M2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class L2 extends E2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}let U2=0;const Zx=new WeakMap,F2=new WeakMap,I2=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),qu=r=>/e/g.test(r)?String(r).replace(/\+/g,""):(r=Number(r),r+(r%1?"":".0"));class Db{constructor(e,t,n){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=n,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.observer=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.types={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.declarations={},this.flow={code:""},this.chaining=[],this.stack=wf(),this.stacks=[],this.tab=" ",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new Lf,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.subBuildLayers=[],this.activeStacks=[],this.subBuildFn=null,this.fnCall=null,Object.defineProperty(this,"id",{value:U2++})}isFlatShading(){return this.material.flatShading===!0||this.geometry.hasAttribute("normal")===!1}isOpaque(){const e=this.material;return e.transparent===!1&&e.blending===ti&&e.alphaToCoverage===!1}createRenderTarget(e,t,n){return new ks(e,t,n)}createCubeRenderTarget(e,t){return new nb(e,t)}includes(e){return this.nodes.includes(e)}getOutputStructName(){}_getBindGroup(e,t){const n=t[0].groupNode;let i=n.shared;if(i)for(let o=1;o<t.length;o++)n!==t[o].groupNode&&(i=!1);let s;if(i){let o="";for(const u of t)if(u.isNodeUniformsGroup){u.uniforms.sort((h,d)=>h.nodeUniform.node.id-d.nodeUniform.node.id);for(const h of u.uniforms)o+=h.nodeUniform.node.id}else o+=u.nodeUniform.id;const a=this.renderer._currentRenderContext||this.renderer;let l=Zx.get(a);l===void 0&&(l=new Map,Zx.set(a,l));const c=cl(o);s=l.get(c),s===void 0&&(s=new Rp(e,t),l.set(c,s))}else s=new Rp(e,t);return s}getBindGroupArray(e,t){const n=this.bindings[t];let i=n[e];return i===void 0&&(this.bindingsIndexes[e]===void 0&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),n[e]=i=[]),i}getBindings(){let e=this.bindGroups;if(e===null){const t={},n=this.bindings;for(const i of of)for(const s in n[i]){const o=n[i][s],a=t[s]||(t[s]=[]);for(const l of o)a.includes(l)===!1&&a.push(l)}e=[];for(const i in t){const s=t[i],o=this._getBindGroup(i,s);e.push(o)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort((t,n)=>t.bindings[0].groupNode.order-n.bindings[0].groupNode.order);for(let t=0;t<e.length;t++){const n=e[t];this.bindingsIndexes[n.name].group=t}}setHashNode(e,t){this.hashNodes[t]=e}addNode(e){this.nodes.includes(e)===!1&&(this.nodes.push(e),this.setHashNode(e,e.getHash(this)))}addSequentialNode(e){const t=e.getUpdateBeforeType(),n=e.getUpdateAfterType();(t!==Ze.NONE||n!==Ze.NONE)&&this.sequentialNodes.includes(e)===!1&&this.sequentialNodes.push(e)}buildUpdateNodes(){for(const e of this.nodes)e.getUpdateType()!==Ze.NONE&&this.updateNodes.push(e);for(const e of this.sequentialNodes){const t=e.getUpdateBeforeType(),n=e.getUpdateAfterType();t!==Ze.NONE&&this.updateBeforeNodes.push(e),n!==Ze.NONE&&this.updateAfterNodes.push(e)}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(e){return e.magFilter===Nt||e.magFilter===ga||e.magFilter===Xr||e.magFilter===ui||e.minFilter===Nt||e.minFilter===ga||e.minFilter===Xr||e.minFilter===ui}getUniformBufferLimit(){return this.renderer.backend.capabilities.getUniformBufferLimit()}addChain(e){this.chaining.push(e)}removeChain(e){if(this.chaining.pop()!==e)throw new Error("NodeBuilder: Invalid node chaining!")}getMethod(e){return e}getTernary(){return null}getNodeFromHash(e){return this.hashNodes[e]}addFlow(e,t){return this.flowNodes[e].push(t),t}setContext(e){this.context=e}getContext(){return this.context}addContext(e){const t=this.getContext();return this.setContext({...this.context,...e}),t}getSharedContext(){const e={...this.context};return delete e.material,delete e.getUV,delete e.getOutput,delete e.getTextureLevel,delete e.getAO,delete e.getShadow,e}setCache(e){this.cache=e}getCache(){return this.cache}getCacheFromNode(e,t=!0){const n=this.getDataFromNode(e);return n.cache===void 0&&(n.cache=new Lf(t?this.getCache():null)),n.cache}isAvailable(){return!1}getVertexIndex(){ae("Abstract function.")}getInstanceIndex(){ae("Abstract function.")}getDrawIndex(){ae("Abstract function.")}getFrontFacing(){ae("Abstract function.")}getFragCoord(){ae("Abstract function.")}isFlipY(){return!1}increaseUsage(e){const t=this.getDataFromNode(e);return t.usageCount=t.usageCount===void 0?1:t.usageCount+1,t.usageCount}generateTexture(){ae("Abstract function.")}generateTextureLod(){ae("Abstract function.")}generateArrayDeclaration(e,t){return this.getType(e)+"[ "+t+" ]"}generateArray(e,t,n=null){let i=this.generateArrayDeclaration(e,t)+"( ";for(let s=0;s<t;s++){const o=n?n[s]:null;o!==null?i+=o.build(this,e):i+=this.generateConst(e),s<t-1&&(i+=", ")}return i+=" )",i}generateStruct(e,t,n=null){const i=[];for(const s of t){const{name:o,type:a}=s;n&&n[o]&&n[o].isNode?i.push(n[o].build(this,a)):i.push(this.generateConst(a))}return e+"( "+i.join(", ")+" )"}generateConst(e,t=null){if(t===null&&(e==="float"||e==="int"||e==="uint"?t=0:e==="bool"?t=!1:e==="color"?t=new We:e==="vec2"||e==="uvec2"||e==="ivec2"?t=new pe:e==="vec3"||e==="uvec3"||e==="ivec3"?t=new P:(e==="vec4"||e==="uvec4"||e==="ivec4")&&(t=new rt)),e==="float")return qu(t);if(e==="int")return`${Math.round(t)}`;if(e==="uint")return t>=0?`${Math.round(t)}u`:"0u";if(e==="bool")return t?"true":"false";if(e==="color")return`${this.getType("vec3")}( ${qu(t.r)}, ${qu(t.g)}, ${qu(t.b)} )`;const n=this.getTypeLength(e),i=this.getComponentType(e),s=o=>this.generateConst(i,o);if(n===2)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)} )`;if(n===3)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)}, ${s(t.z)} )`;if(n===4&&e!=="mat2")return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)}, ${s(t.z)}, ${s(t.w)} )`;if(n>=4&&t&&(t.isMatrix2||t.isMatrix3||t.isMatrix4))return`${this.getType(e)}( ${t.elements.map(s).join(", ")} )`;if(n>4)return`${this.getType(e)}()`;throw new Error(`NodeBuilder: Type '${e}' not found in generate constant attempt.`)}getType(e){return e==="color"?"vec3":e}hasGeometryAttribute(e){return this.geometry&&this.geometry.getAttribute(e)!==void 0}getAttribute(e,t){const n=this.attributes;for(const s of n)if(s.name===e)return s;const i=new Kx(e,t);return this.registerDeclaration(i),n.push(i),i}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return e==="void"||e==="property"||e==="sampler"||e==="samplerComparison"||e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="depthTexture"||e==="texture3D"}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===Sn)return"int";if(t===Ct)return"uint"}return"float"}getElementType(e){return e==="mat2"?"vec2":e==="mat3"?"vec3":e==="mat4"?"vec4":this.getComponentType(e)}getComponentType(e){if(e=this.getVectorType(e),e==="float"||e==="bool"||e==="int"||e==="uint")return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return t===null?null:t[1]==="b"?"bool":t[1]==="i"?"int":t[1]==="u"?"uint":"float"}getVectorType(e){return e==="color"?"vec3":e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="texture3D"?"vec4":e}getTypeFromLength(e,t="float"){if(e===1)return t;let n=Wy(e);const i=t==="float"?"":t[0];return/mat2/.test(t)===!0&&(n=n.replace("vec","mat")),i+n}getTypeFromArray(e){return I2.get(e.constructor)}isInteger(e){return/int|uint|(i|u)vec/.test(e)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const n=t.array,i=e.itemSize,s=e.normalized;let o;return!(e instanceof ey)&&s!==!0&&(o=this.getTypeFromArray(n)),this.getTypeFromLength(i,o)}getTypeLength(e){const t=this.getVectorType(e),n=/vec([2-4])/.exec(t);return n!==null?Number(n[1]):t==="float"||t==="bool"||t==="int"||t==="uint"?1:/mat2/.test(e)===!0?4:/mat3/.test(e)===!0?9:/mat4/.test(e)===!0?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return t==="int"||t==="uint"?e:this.changeComponentType(e,"int")}setActiveStack(e){this.activeStacks.push(e)}removeActiveStack(e){if(this.activeStacks[this.activeStacks.length-1]===e)this.activeStacks.pop();else throw new Error("NodeBuilder: Invalid active stack removal.")}getActiveStack(){return this.activeStacks[this.activeStacks.length-1]}getBaseStack(){return this.activeStacks[0]}addStack(){this.stack=wf(this.stack);const e=Yy();return this.stacks.push(e),Th(this.stack),this.stack}removeStack(){const e=this.stack;for(const t of e.nodes){const n=this.getDataFromNode(t);n.stack=e}return this.stack=e.parent,Th(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,n=null){n=n===null?e.isGlobal(this)?this.globalCache:this.cache:n;let i=n.getData(e);i===void 0&&(i={},n.setData(e,i)),i[t]===void 0&&(i[t]={});let s=i[t];const o=i.any?i.any.subBuilds:null,a=this.getClosestSubBuild(o);return a&&(s.subBuildsCache===void 0&&(s.subBuildsCache={}),s=s.subBuildsCache[a]||(s.subBuildsCache[a]={}),s.subBuilds=o),s}getNodeProperties(e,t="any"){const n=this.getDataFromNode(e,t);return n.properties||(n.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const n=this.getDataFromNode(e,"vertex");let i=n.bufferAttribute;if(i===void 0){const s=this.uniforms.index++;i=new Kx("nodeAttribute"+s,t,e),this.bufferAttributes.push(i),n.bufferAttribute=i}return i}getStructTypeNode(e,t=this.shaderStage){return this.types[t][e]||null}getStructTypeFromNode(e,t,n=null,i=this.shaderStage){const s=this.getDataFromNode(e,i,this.globalCache);let o=s.structType;if(o===void 0){const a=this.structs.index++;n===null&&(n="StructType"+a),o=new _2(n,t),this.structs[i].push(o),this.types[i][n]=e,s.structType=o}return o}getOutputStructTypeFromNode(e,t){const n=this.getStructTypeFromNode(e,t,"OutputType","fragment");return n.output=!0,n}getUniformFromNode(e,t,n=this.shaderStage,i=null){const s=this.getDataFromNode(e,n,this.globalCache);let o=s.uniform;if(o===void 0){const a=this.uniforms.index++;o=new f2(i||"nodeUniform"+a,t,e),this.uniforms[n].push(o),this.registerDeclaration(o),s.uniform=o}return o}getVarFromNode(e,t=null,n=e.getNodeType(this),i=this.shaderStage,s=!1){const o=this.getDataFromNode(e,i),a=this.getSubBuildProperty("variable",o.subBuilds);let l=o[a];if(l===void 0){const c=s?"_const":"_var",u=this.vars[i]||(this.vars[i]=[]),h=this.vars[c]||(this.vars[c]=0);t===null&&(t=(s?"nodeConst":"nodeVar")+h,this.vars[c]++),a!=="variable"&&(t=this.getSubBuildProperty(t,o.subBuilds));const d=e.getArrayCount(this);l=new Pb(t,n,s,d),s||u.push(l),this.registerDeclaration(l),o[a]=l}return l}isDeterministic(e){if(e.isMathNode)return this.isDeterministic(e.aNode)&&(e.bNode?this.isDeterministic(e.bNode):!0)&&(e.cNode?this.isDeterministic(e.cNode):!0);if(e.isOperatorNode)return this.isDeterministic(e.aNode)&&(e.bNode?this.isDeterministic(e.bNode):!0);if(e.isArrayNode){if(e.values!==null){for(const t of e.values)if(!this.isDeterministic(t))return!1}return!0}else if(e.isConstNode)return!0;return!1}getVaryingFromNode(e,t=null,n=e.getNodeType(this),i=null,s=null){const o=this.getDataFromNode(e,"any"),a=this.getSubBuildProperty("varying",o.subBuilds);let l=o[a];if(l===void 0){const c=this.varyings,u=c.length;t===null&&(t="nodeVarying"+u),a!=="varying"&&(t=this.getSubBuildProperty(t,o.subBuilds)),l=new p2(t,n,i,s),c.push(l),this.registerDeclaration(l),o[a]=l}return l}registerDeclaration(e){const t=this.shaderStage,n=this.declarations[t]||(this.declarations[t]={}),i=this.getPropertyName(e);let s=1,o=i;for(;n[o]!==void 0;)o=i+"_"+s++;s>1&&(e.name=o,ae(`TSL: Declaration name '${i}' of '${e.type}' already in use. Renamed to '${o}'.`)),n[o]=e}getCodeFromNode(e,t,n=this.shaderStage){const i=this.getDataFromNode(e);let s=i.code;if(s===void 0){const o=this.codes[n]||(this.codes[n]=[]),a=o.length;s=new m2("nodeCode"+a,t),o.push(s),i.code=s}return s}addFlowCodeHierarchy(e,t){const{flowCodes:n,flowCodeBlock:i}=this.getDataFromNode(e);let s=!0,o=t;for(;o;){if(i.get(o)===!0){s=!1;break}o=this.getDataFromNode(o).parentNodeBlock}if(s)for(const a of n)this.addLineFlowCode(a)}addLineFlowCodeBlock(e,t,n){const i=this.getDataFromNode(e),s=i.flowCodes||(i.flowCodes=[]),o=i.flowCodeBlock||(i.flowCodeBlock=new WeakMap);s.push(t),o.set(n,!0)}addLineFlowCode(e,t=null){return e===""?this:(t!==null&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e=e+`;
4652
4652
  `),this.flow.code+=e,this)}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+=" ",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),n=this.flowChildNode(e,t);return this.flowsData.set(e,n),n}addInclude(e){this.currentFunctionNode!==null&&this.currentFunctionNode.includes.push(e)}buildFunctionNode(e){const t=new TI,n=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=n,t}flowShaderNode(e){const t=e.layout,n={[Symbol.iterator](){let o=0;const a=Object.values(this);return{next:()=>({value:a[o],done:o++>=a.length})}}};for(const o of t.inputs)n[o.name]=new iI(o.type,o.name);e.layout=null;const i=e.call(n),s=this.flowStagesNode(i,t.type);return e.layout=t,s}flowBuildStage(e,t,n=null){const i=this.getBuildStage();this.setBuildStage(t);const s=e.build(this,n);return this.setBuildStage(i),s}flowStagesNode(e,t=null){const n=this.flow,i=this.vars,s=this.declarations,o=this.cache,a=this.buildStage,l=this.stack,c={code:""};this.flow=c,this.vars={},this.declarations={},this.cache=new Lf,this.stack=wf();for(const u of sf)this.setBuildStage(u),c.result=e.build(this,t);return c.vars=this.getVars(this.shaderStage),this.flow=n,this.vars=i,this.declarations=s,this.cache=o,this.stack=l,this.setBuildStage(a),c}getFunctionOperator(){return null}buildFunctionCode(){ae("Abstract function.")}flowChildNode(e,t=null){const n=this.flow,i={code:""};return this.flow=i,i.result=e.build(this,t),this.flow=n,i}flowNodeFromShaderStage(e,t,n=null,i=null){const s=this.tab,o=this.cache,a=this.shaderStage,l=this.context;this.setShaderStage(e);const c={...this.context};delete c.nodeBlock,this.cache=this.globalCache,this.tab=" ",this.context=c;let u=null;if(this.buildStage==="generate"){const h=this.flowChildNode(t,n);i!==null&&(h.code+=`${this.tab+i} = ${h.result};
4653
4653
  `),this.flowCode[e]=this.flowCode[e]+h.code,u=h}else u=t.build(this);return this.setShaderStage(a),this.cache=o,this.tab=s,this.context=l,u}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){ae("Abstract function.")}getVaryings(){ae("Abstract function.")}getVar(e,t,n=null){return`${n!==null?this.generateArrayDeclaration(e,n):this.getType(e)} ${t}`}getVars(e,t=!1){const n=[],i=this.vars[e];if(i!==void 0)for(const s of i)n.push(`${this.getVar(s.type,s.name,s.count)};`);return n.join(t?`
4654
4654
  `:`
4655
4655
  `)}getUniforms(){ae("Abstract function.")}getCodes(e){const t=this.codes[e];let n="";if(t!==void 0)for(const i of t)n+=i.code+`
4656
4656
  `;return n}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){ae("Abstract function.")}get subBuild(){return this.subBuildLayers[this.subBuildLayers.length-1]||null}addSubBuild(e){this.subBuildLayers.push(e)}removeSubBuild(){return this.subBuildLayers.pop()}getClosestSubBuild(e){let t;if(e&&e.isNode?e.isShaderCallNodeInternal?t=e.shaderNode.subBuilds:e.isStackNode?t=[e.subBuild]:t=this.getDataFromNode(e,"any").subBuilds:e instanceof Set?t=[...e]:t=e,!t)return null;const n=this.subBuildLayers;for(let i=t.length-1;i>=0;i--){const s=t[i];if(n.includes(s))return s}return null}getSubBuildOutput(e){return this.getSubBuildProperty("outputNode",e)}getSubBuildProperty(e="",t=null){let n;t!==null?n=this.getClosestSubBuild(t):n=this.subBuildFn;let i;return n?i=e?n+"_"+e:n:i=e,i}prebuild(){const{object:e,renderer:t,material:n}=this;if(t.contextNode.isContextNode===!0?this.context={...this.context,...t.contextNode.getFlowContextData()}:ce('NodeBuilder: "renderer.contextNode" must be an instance of `context()`.'),n&&n.contextNode&&(n.contextNode.isContextNode===!0?this.context={...this.context,...n.contextNode.getFlowContextData()}:ce('NodeBuilder: "material.contextNode" must be an instance of `context()`.')),n!==null){let i=t.library.fromMaterial(n);i===null&&(ce(`NodeBuilder: Material "${n.type}" is not compatible.`),i=new mn),i.build(this)}else this.addFlow("compute",e)}build(){this.prebuild();for(const e of sf){this.setBuildStage(e),this.context.position&&this.context.position.isNode&&this.flowNodeFromShaderStage("vertex",this.context.position);for(const t of of){this.setShaderStage(t);const n=this.flowNodes[t];for(const i of n)e==="generate"?this.flowNode(i):i.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}async buildAsync(){this.prebuild();for(const e of sf){this.setBuildStage(e),this.context.position&&this.context.position.isNode&&this.flowNodeFromShaderStage("vertex",this.context.position);for(const t of of){this.setShaderStage(t);const n=this.flowNodes[t];for(const i of n)e==="generate"?this.flowNode(i):i.build(this);await Q0()}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getSharedDataFromNode(e){let t=F2.get(e);return t===void 0&&(t={}),t}getNodeUniform(e,t){const n=this.getSharedDataFromNode(e);let i=n.cache;if(i===void 0){if(t==="float"||t==="int"||t==="uint")i=new A2(e);else if(t==="vec2"||t==="ivec2"||t==="uvec2")i=new w2(e);else if(t==="vec3"||t==="ivec3"||t==="uvec3")i=new R2(e);else if(t==="vec4"||t==="ivec4"||t==="uvec4")i=new C2(e);else if(t==="color")i=new N2(e);else if(t==="mat2")i=new P2(e);else if(t==="mat3")i=new D2(e);else if(t==="mat4")i=new L2(e);else throw new Error(`Uniform "${t}" not implemented.`);n.cache=i}return i}format(e,t,n){if(t=this.getVectorType(t),n=this.getVectorType(n),t===n||n===null||this.isReference(n))return e;const i=this.getTypeLength(t),s=this.getTypeLength(n);return i===16&&s===9?`${this.getType(n)}( ${e}[ 0 ].xyz, ${e}[ 1 ].xyz, ${e}[ 2 ].xyz )`:i===9&&s===4?`${this.getType(n)}( ${e}[ 0 ].xy, ${e}[ 1 ].xy )`:i>4||s>4||s===0?e:i===s?`${this.getType(n)}( ${e} )`:i>s?(e=n==="bool"?`all( ${e} )`:`${e}.${"xyz".slice(0,s)}`,this.format(e,this.getTypeFromLength(s,this.getComponentType(t)),n)):s===4&&i>1?`${this.getType(n)}( ${this.format(e,t,"vec3")}, 1.0 )`:i===2?`${this.getType(n)}( ${this.format(e,t,"vec2")}, 0.0 )`:(i===1&&s>1&&t!==this.getComponentType(n)&&(e=`${this.getType(this.getComponentType(n))}( ${e} )`),`${this.getType(n)}( ${e} )`)}getSignature(){return`// Three.js r${Mo} - Node System
4657
- `}needsPreviousData(){const e=this.renderer.getMRT();return e&&e.has("velocity")||$y(this.object).useVelocity===!0}}class Qx{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let n=e.get(t);return n===void 0&&(n={renderId:0,frameId:0},e.set(t,n)),n}updateBeforeNode(e){const t=e.getUpdateBeforeType(),n=e.updateReference(this);if(t===Ze.FRAME){const i=this._getMaps(this.updateBeforeMap,n);if(i.frameId!==this.frameId){const s=i.frameId;i.frameId=this.frameId,e.updateBefore(this)===!1&&(i.frameId=s)}}else if(t===Ze.RENDER){const i=this._getMaps(this.updateBeforeMap,n);if(i.renderId!==this.renderId){const s=i.renderId;i.renderId=this.renderId,e.updateBefore(this)===!1&&(i.renderId=s)}}else t===Ze.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),n=e.updateReference(this);if(t===Ze.FRAME){const i=this._getMaps(this.updateAfterMap,n);i.frameId!==this.frameId&&e.updateAfter(this)!==!1&&(i.frameId=this.frameId)}else if(t===Ze.RENDER){const i=this._getMaps(this.updateAfterMap,n);i.renderId!==this.renderId&&e.updateAfter(this)!==!1&&(i.renderId=this.renderId)}else t===Ze.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),n=e.updateReference(this);if(t===Ze.FRAME){const i=this._getMaps(this.updateMap,n);i.frameId!==this.frameId&&e.update(this)!==!1&&(i.frameId=this.frameId)}else if(t===Ze.RENDER){const i=this._getMaps(this.updateMap,n);i.renderId!==this.renderId&&e.update(this)!==!1&&(i.renderId=this.renderId)}else t===Ze.OBJECT&&e.update(this)}update(){this.frameId++,this.lastTime===void 0&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class Zm{constructor(e,t,n=null,i="",s=!1){this.type=e,this.name=t,this.count=n,this.qualifier=i,this.isConst=s}}Zm.isNodeFunctionInput=!0;class B2 extends Lo{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class O2 extends Lo{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setupDirect(){const e=this.colorNode;return{lightDirection:Ab(this.light),lightColor:e}}}class k2 extends Lo{static get type(){return"HemisphereLightNode"}constructor(e=null){super(e),this.lightPositionNode=Mb(e),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=qe(new We).setGroup(Ke)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:n,lightDirectionNode:i}=this,o=ml.dot(i).mul(.5).add(.5),a=Dt(n,t,o);e.context.irradiance.addAssign(a)}}class Qm extends Lo{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=qe(0).setGroup(Ke),this.penumbraCosNode=qe(0).setGroup(Ke),this.cutoffDistanceNode=qe(0).setGroup(Ke),this.decayExponentNode=qe(0).setGroup(Ke),this.colorNode=qe(this.color).setGroup(Ke)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e,t){const{coneCosNode:n,penumbraCosNode:i}=this;return Qr(n,i,t)}getLightCoord(e){const t=e.getNodeProperties(this);let n=t.projectionUV;return n===void 0&&(n=wI(this.light,e.context.positionWorld),t.projectionUV=n),n}setupDirect(e){const{colorNode:t,cutoffDistanceNode:n,decayExponentNode:i,light:s}=this,o=this.getLightVector(e),a=o.normalize(),l=a.dot(Ab(s)),c=this.getSpotAttenuation(e,l),u=o.length(),h=Nb({lightDistance:u,cutoffDistance:n,decayExponent:i});let d=t.mul(c).mul(h),f,p;return s.colorNode?(p=this.getLightCoord(e),f=s.colorNode(p)):s.map&&(p=this.getLightCoord(e),f=Vt(s.map,p.xy).onRenderUpdate(()=>s.map)),f&&(d=p.mul(2).sub(1).abs().lessThan(1).all().select(d.mul(f),d)),{lightColor:d,lightDirection:a}}}class G2 extends Qm{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e,t){const n=this.light.iesMap;let i=null;if(n&&n.isTexture===!0){const s=t.acos().mul(1/Math.PI);i=Vt(n,ke(s,0),0).r}else i=super.getSpotAttenuation(t);return i}}class V2 extends Lo{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let n=0;n<9;n++)t.push(new P);this.lightProbe=Di(t)}update(e){const{light:t}=this;super.update(e);for(let n=0;n<9;n++)this.lightProbe.array[n].copy(t.sh.coefficients[n]).multiplyScalar(t.intensity)}setup(e){const t=c2(ml,this.lightProbe);e.context.irradiance.addAssign(t)}}const z2=re(([r,e])=>{const t=r.abs().sub(e);return Kr(kn(t,0)).add(Qa(kn(t.x,t.y),0))});class H2 extends Qm{static get type(){return"ProjectorLightNode"}update(e){super.update(e);const t=this.light;if(this.penumbraCosNode.value=Math.min(Math.cos(t.angle*(1-t.penumbra)),.99999),t.aspect===null){let n=1;t.map!==null&&(n=t.map.width/t.map.height),t.shadow.aspect=n}else t.shadow.aspect=t.aspect}getSpotAttenuation(e){const t=J(0),n=this.penumbraCosNode,i=Km(this.light).mul(e.context.positionWorld||Ja);return Ft(i.w.greaterThan(0),()=>{const s=i.xyz.div(i.w),o=z2(s.xy.sub(ke(.5)),ke(.5)),a=Er(-1,oi(1,cv(n)).sub(1));t.assign(Gm(o.mul(-2).mul(a)))}),t}}const Uf=new pt,ju=new pt;let Gl=null;class W2 extends Lo{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=qe(new P).setGroup(Ke),this.halfWidth=qe(new P).setGroup(Ke),this.updateType=Ze.RENDER}update(e){super.update(e);const{light:t}=this,n=e.camera.matrixWorldInverse;ju.identity(),Uf.copy(t.matrixWorld),Uf.premultiply(n),ju.extractRotation(Uf),this.halfWidth.value.set(t.width*.5,0,0),this.halfHeight.value.set(0,t.height*.5,0),this.halfWidth.value.applyMatrix4(ju),this.halfHeight.value.applyMatrix4(ju)}setupDirectRectArea(e){let t,n;e.isAvailable("float32Filterable")?(t=Vt(Gl.LTC_FLOAT_1),n=Vt(Gl.LTC_FLOAT_2)):(t=Vt(Gl.LTC_HALF_1),n=Vt(Gl.LTC_HALF_2));const{colorNode:i,light:s}=this,o=Eb(s);return{lightColor:i,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,ltc_1:t,ltc_2:n}}static setLTC(e){Gl=e}}class Lb{parseFunction(){ae("Abstract function.")}}class Jm{constructor(e,t,n="",i=""){this.type=e,this.inputs=t,this.name=n,this.precision=i}getCode(){ae("Abstract function.")}}Jm.isNodeFunction=!0;const $2=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,X2=/[a-z_0-9]+/ig,Jx="#pragma main",q2=r=>{r=r.trim();const e=r.indexOf(Jx),t=e!==-1?r.slice(e+Jx.length):r,n=t.match($2);if(n!==null&&n.length===5){const i=n[4],s=[];let o=null;for(;(o=X2.exec(i))!==null;)s.push(o);const a=[];let l=0;for(;l<s.length;){const p=s[l][0]==="const";p===!0&&l++;let g=s[l][0];g==="in"||g==="out"||g==="inout"?l++:g="";const m=s[l++][0];let _=Number.parseInt(s[l][0]);Number.isNaN(_)===!1?l++:_=null;const x=s[l++][0];a.push(new Zm(m,x,_,g,p))}const c=t.substring(n[0].length),u=n[3]!==void 0?n[3]:"",h=n[2],d=n[1]!==void 0?n[1]:"",f=e!==-1?r.slice(0,e):"";return{type:h,inputs:a,name:u,precision:d,inputsCode:i,blockCode:c,headerCode:f}}else throw new Error("FunctionNode: Function is not a GLSL code.")};class j2 extends Jm{constructor(e){const{type:t,inputs:n,name:i,precision:s,inputsCode:o,blockCode:a,headerCode:l}=q2(e);super(t,n,i,s),this.inputsCode=o,this.blockCode=a,this.headerCode=l}getCode(e=this.name){let t;const n=this.blockCode;if(n!==""){const{type:i,inputsCode:s,headerCode:o,precision:a}=this;let l=`${i} ${e} ( ${s.trim()} )`;a!==""&&(l=`${a} ${l}`),t=o+l+n}else t="";return t}}class Y2 extends Lb{parseFunction(e){return new j2(e)}}const Ri=[],hs=[];class K2 extends Gs{constructor(e,t){super(),this.renderer=e,this.backend=t,this.nodeFrame=new Qx,this.nodeBuilderCache=new Map,this.callHashCache=new Bs,this.groupsData=new Bs,this._buildQueue=[],this._buildInProgress=!1,this.cacheLib={}}updateGroup(e){const t=e.groupNode;Ri[0]=t,Ri[1]=e;let n=this.groupsData.get(Ri);return n===void 0&&this.groupsData.set(Ri,n={}),Ri[0]=null,Ri[1]=null,n.version!==t.version?(n.version=t.version,!0):!1}getForRenderCacheKey(e){return e.initialCacheKey}_createNodeBuilder(e,t){const n=this.backend.createNodeBuilder(e.object,this.renderer);return n.scene=e.scene,n.material=t,n.camera=e.camera,n.context.material=t,n.lightsNode=e.lightsNode,n.environmentNode=this.getEnvironmentNode(e.scene),n.fogNode=this.getFogNode(e.scene),n.clippingContext=e.clippingContext,this.renderer.getOutputRenderTarget()&&this.renderer.getOutputRenderTarget().multiview&&n.enableMultiview(),n}getForRender(e,t=!1){const n=this.get(e);let i=n.nodeBuilderState;if(i===void 0){const{nodeBuilderCache:s}=this,o=this.getForRenderCacheKey(e);if(i=s.get(o),i===void 0){const a=async()=>{let l=this._createNodeBuilder(e,e.material);try{t?await l.buildAsync():l.build()}catch(c){l=this._createNodeBuilder(e,new mn),t?await l.buildAsync():l.build(),ce("TSL: "+c)}return l};if(t)return a().then(l=>(i=this._createNodeBuilderState(l),s.set(o,i),i.usedTimes++,n.nodeBuilderState=i,i));{let l=this._createNodeBuilder(e,e.material);try{l.build()}catch(c){l=this._createNodeBuilder(e,new mn),l.build();let u=c.stackTrace;!u&&c.stack&&(u=new Kn(c.stack)),ce("TSL: "+c,u)}i=this._createNodeBuilderState(l),s.set(o,i)}}i.usedTimes++,n.nodeBuilderState=i}return i}getForRenderAsync(e){const t=this.getForRender(e,!0);return t.then?t:Promise.resolve(t)}getForRenderDeferred(e){const t=this.get(e);if(t.nodeBuilderState!==void 0)return t.nodeBuilderState;const n=this.getForRenderCacheKey(e),i=this.nodeBuilderCache.get(n);return i!==void 0?(i.usedTimes++,t.nodeBuilderState=i,i):(t.pendingBuild!==!0&&(t.pendingBuild=!0,this._buildQueue.push(()=>this.getForRenderAsync(e).then(()=>{t.pendingBuild=!1})),this._processBuildQueue()),null)}_processBuildQueue(){if(this._buildInProgress||this._buildQueue.length===0)return;this._buildInProgress=!0,this._buildQueue.shift()().then(()=>{this._buildInProgress=!1,this._processBuildQueue()})}delete(e){if(e.isRenderObject){const t=this.get(e).nodeBuilderState;t!==void 0&&(t.usedTimes--,t.usedTimes===0&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(e)))}return super.delete(e)}getForCompute(e){const t=this.get(e);let n=t.nodeBuilderState;if(n===void 0){const i=this.backend.createNodeBuilder(e,this.renderer);i.build(),n=this._createNodeBuilderState(i),t.nodeBuilderState=n}return n}_createNodeBuilderState(e){return new d2(e.vertexShader,e.fragmentShader,e.computeShader,e.getAttributesArray(),e.getBindings(),e.updateNodes,e.updateBeforeNodes,e.updateAfterNodes,e.observer,e.transforms)}getEnvironmentNode(e){this.updateEnvironment(e);let t=null;if(e.environmentNode&&e.environmentNode.isNode)t=e.environmentNode;else{const n=this.get(e);n.environmentNode&&(t=n.environmentNode)}return t}getBackgroundNode(e){this.updateBackground(e);let t=null;if(e.backgroundNode&&e.backgroundNode.isNode)t=e.backgroundNode;else{const n=this.get(e);n.backgroundNode&&(t=n.backgroundNode)}return t}getFogNode(e){return this.updateFog(e),e.fogNode||this.get(e).fogNode||null}getCacheKey(e,t){Ri[0]=e,Ri[1]=t;const n=this.renderer.info.calls,i=this.callHashCache.get(Ri)||{};if(i.callId!==n){const s=this.getEnvironmentNode(e),o=this.getFogNode(e);t&&hs.push(t.getCacheKey(!0)),s&&hs.push(s.getCacheKey()),o&&hs.push(o.getCacheKey()),hs.push(this.renderer.getOutputRenderTarget()&&this.renderer.getOutputRenderTarget().multiview?1:0),hs.push(this.renderer.shadowMap.enabled?1:0),hs.push(this.renderer.shadowMap.type),i.callId=n,i.cacheKey=Gc(hs),this.callHashCache.set(Ri,i),hs.length=0}return Ri[0]=null,Ri[1]=null,i.cacheKey}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(e){const t=this.get(e),n=e.background;if(n){const i=e.backgroundBlurriness===0&&t.backgroundBlurriness>0||e.backgroundBlurriness>0&&t.backgroundBlurriness===0;if(t.background!==n||i){const s=this.getCacheNode("background",n,()=>{if(n.isCubeTexture===!0||n.mapping===pa||n.mapping===ma||n.mapping===mo){if(e.backgroundBlurriness>0||n.mapping===mo)return fb(n);{let o;return n.isCubeTexture===!0?o=li(n):o=Vt(n),rb(o)}}else{if(n.isTexture===!0)return Vt(n,fo.flipY()).setUpdateMatrix(!0);n.isColor!==!0&&ce("WebGPUNodes: Unsupported background configuration.",n)}},i);t.backgroundNode=s,t.background=n,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}getCacheNode(e,t,n,i=!1){const s=this.cacheLib[e]||(this.cacheLib[e]=new WeakMap);let o=s.get(t);return(o===void 0||i)&&(o=n(),s.set(t,o)),o}updateFog(e){const t=this.get(e),n=e.fog;if(n){if(t.fog!==n){const i=this.getCacheNode("fog",n,()=>{if(n.isFogExp2){const s=Jt("color","color",n).setGroup(Ke),o=Jt("density","float",n).setGroup(Ke);return qx(s,EI(o))}else if(n.isFog){const s=Jt("color","color",n).setGroup(Ke),o=Jt("near","float",n).setGroup(Ke),a=Jt("far","float",n).setGroup(Ke);return qx(s,MI(o,a))}else ce("Renderer: Unsupported fog configuration.",n)});t.fogNode=i,t.fog=n}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),n=e.environment;if(n){if(t.environment!==n){const i=this.getCacheNode("environment",n,()=>{if(n.isCubeTexture===!0)return li(n);if(n.isTexture===!0)return Vt(n);ce("Nodes: Unsupported environment configuration.",n)});t.environmentNode=i,t.environment=n}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,n=null,i=null,s=null){const o=this.nodeFrame;return o.renderer=e,o.scene=t,o.object=n,o.camera=i,o.material=s,o}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace+","+e.xr.isPresenting}getOutputNode(e){const t=this.renderer;return e.isArrayTexture?Vt(e,fo).depth(fl("gl_ViewID_OVR")).renderOutput(t.toneMapping,t.currentColorSpace):Vt(e,fo).renderOutput(t.toneMapping,t.currentColorSpace)}updateBefore(e){const t=e.getNodeBuilderState();for(const n of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(n)}updateAfter(e){const t=e.getNodeBuilderState();for(const n of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(n)}updateForCompute(e){const t=this.getNodeFrame(),n=this.getForCompute(e);for(const i of n.updateNodes)t.updateNode(i)}updateForRender(e){const t=this.getNodeFrameForRender(e),n=e.getNodeBuilderState();for(const i of n.updateNodes)t.updateNode(i)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new Qx,this.nodeBuilderCache=new Map,this.cacheLib={}}}const Ff=new ur;class Nh{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",this.shadowPass=!1,this.viewNormalMatrix=new Je,this.clippingGroupContexts=new WeakMap,this.intersectionPlanes=[],this.unionPlanes=[],this.parentVersion=null,e!==null&&(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix)}projectPlanes(e,t,n){const i=e.length;for(let s=0;s<i;s++){Ff.copy(e[s]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);const o=t[n+s],a=Ff.normal;o.x=-a.x,o.y=-a.y,o.z=-a.z,o.w=Ff.constant}}updateGlobal(e,t){this.shadowPass=e.overrideMaterial!==null&&e.overrideMaterial.isShadowPassMaterial,this.viewMatrix=t.matrixWorldInverse,this.viewNormalMatrix.getNormalMatrix(this.viewMatrix)}update(e,t){let n=!1;e.version!==this.parentVersion&&(this.intersectionPlanes=Array.from(e.intersectionPlanes),this.unionPlanes=Array.from(e.unionPlanes),this.parentVersion=e.version),this.clipIntersection!==t.clipIntersection&&(this.clipIntersection=t.clipIntersection,this.clipIntersection?this.unionPlanes.length=e.unionPlanes.length:this.intersectionPlanes.length=e.intersectionPlanes.length);const i=t.clippingPlanes,s=i.length;let o,a;if(this.clipIntersection?(o=this.intersectionPlanes,a=e.intersectionPlanes.length):(o=this.unionPlanes,a=e.unionPlanes.length),o.length!==a+s){o.length=a+s;for(let l=0;l<s;l++)o[a+l]=new rt;n=!0}this.projectPlanes(i,o,a),n&&(this.version++,this.cacheKey=`${this.intersectionPlanes.length}:${this.unionPlanes.length}`)}getGroupContext(e){if(this.shadowPass&&!e.clipShadows)return this;let t=this.clippingGroupContexts.get(e);return t===void 0&&(t=new Nh(this),this.clippingGroupContexts.set(e,t)),t.update(this,e),t}get unionClippingCount(){return this.unionPlanes.length}}class Z2{constructor(e,t,n){this.bundleGroup=e,this.camera=t,this.renderContext=n}}const ds=[];class Q2{constructor(){this.bundles=new Bs}get(e,t,n){const i=this.bundles;ds[0]=e,ds[1]=t,ds[2]=n;let s=i.get(ds);return s===void 0&&(s=new Z2(e,t,n),i.set(ds,s)),ds[0]=null,ds[1]=null,ds[2]=null,s}dispose(){this.bundles=new Bs}}class Ub{constructor(){this.lightNodes=new WeakMap,this.materialNodes=new Map,this.toneMappingNodes=new Map}fromMaterial(e){if(e.isNodeMaterial)return e;let t=null;const n=this.getMaterialNodeClass(e.type);if(n!==null){t=new n;for(const i in e)t[i]=e[i]}return t}addToneMapping(e,t){this.addType(e,t,this.toneMappingNodes)}getToneMappingFunction(e){return this.toneMappingNodes.get(e)||null}getMaterialNodeClass(e){return this.materialNodes.get(e)||null}addMaterial(e,t){this.addType(e,t,this.materialNodes)}getLightNodeClass(e){return this.lightNodes.get(e)||null}addLight(e,t){this.addClass(e,t,this.lightNodes)}addType(e,t,n){if(n.has(t)){ae(`Redefinition of node ${t}`);return}if(typeof e!="function")throw new Error(`Node class ${e.name} is not a class.`);if(typeof t=="function"||typeof t=="object")throw new Error(`Base class ${t} is not a class.`);n.set(t,e)}addClass(e,t,n){if(n.has(t)){ae(`Redefinition of node ${t.name}`);return}if(typeof e!="function")throw new Error(`Node class ${e.name} is not a class.`);if(typeof t!="function")throw new Error(`Base class ${t.name} is not a class.`);n.set(t,e)}}const J2=new wb,e0=new WeakMap;class eB{createNode(e=[]){return new wb().setLights(e)}getNode(e){if(e.isQuadMesh)return J2;let t=e0.get(e);return t===void 0&&(t=this.createNode(),e0.set(e,t)),t}}class Xl extends ks{constructor(e=1,t=1,n={}){super(e,t,n),this.isXRRenderTarget=!0,this._hasExternalTextures=!1,this._autoAllocateDepthBuffer=!0,this._isOpaqueFramebuffer=!1}copy(e){return super.copy(e),this._hasExternalTextures=e._hasExternalTextures,this._autoAllocateDepthBuffer=e._autoAllocateDepthBuffer,this._isOpaqueFramebuffer=e._isOpaqueFramebuffer,this}}const t0=new P,n0=new P,i0=new WeakMap;class tB extends Vi{constructor(e,t=!1){super(),this.enabled=!1,this.isPresenting=!1,this.cameraAutoUpdate=!0,this._renderer=e,this._cameraL=new Cn,this._cameraL.viewport=new rt,this._cameraR=new Cn,this._cameraR.viewport=new rt,this._cameras=[this._cameraL,this._cameraR],this._cameraXR=new my,this._currentDepthNear=null,this._currentDepthFar=null,this._controllers=[],this._controllerInputSources=[],this._xrRenderTarget=null,this._layers=[],this._sessionUsesLayers=!1,this._supportsGlBinding=typeof XRWebGLBinding<"u",this._createXRLayer=aB.bind(this),this._gl=null,this._currentAnimationContext=null,this._currentAnimationLoop=null,this._currentPixelRatio=null,this._currentSize=new pe,this._onSessionEvent=rB.bind(this),this._onSessionEnd=sB.bind(this),this._onInputSourcesChange=oB.bind(this),this._onAnimationFrame=lB.bind(this),this._referenceSpace=null,this._referenceSpaceType="local-floor",this._customReferenceSpace=null,this._framebufferScaleFactor=1,this._foveation=1,this._session=null,this._glBaseLayer=null,this._glBinding=null,this._glProjLayer=null,this._xrFrame=null,this._supportsLayers=this._supportsGlBinding&&"createProjectionLayer"in XRWebGLBinding.prototype,this._useMultiviewIfPossible=t,this._useMultiview=!1}getController(e){return this._getController(e).getTargetRaySpace()}getControllerGrip(e){return this._getController(e).getGripSpace()}getHand(e){return this._getController(e).getHandSpace()}getFoveation(){if(!(this._glProjLayer===null&&this._glBaseLayer===null))return this._foveation}setFoveation(e){this._foveation=e,this._glProjLayer!==null&&(this._glProjLayer.fixedFoveation=e),this._glBaseLayer!==null&&this._glBaseLayer.fixedFoveation!==void 0&&(this._glBaseLayer.fixedFoveation=e)}getFramebufferScaleFactor(){return this._framebufferScaleFactor}setFramebufferScaleFactor(e){this._framebufferScaleFactor=e,this.isPresenting===!0&&ae("XRManager: Cannot change framebuffer scale while presenting.")}getReferenceSpaceType(){return this._referenceSpaceType}setReferenceSpaceType(e){this._referenceSpaceType=e,this.isPresenting===!0&&ae("XRManager: Cannot change reference space type while presenting.")}getReferenceSpace(){return this._customReferenceSpace||this._referenceSpace}setReferenceSpace(e){this._customReferenceSpace=e}getCamera(){return this._cameraXR}getEnvironmentBlendMode(){if(this._session!==null)return this._session.environmentBlendMode}getBinding(){return this._glBinding===null&&this._supportsGlBinding&&(this._glBinding=new XRWebGLBinding(this._session,this._gl)),this._glBinding}getFrame(){return this._xrFrame}useMultiview(){return this._useMultiview}createQuadLayer(e,t,n,i,s,o,a,l={}){const c=new Oc(e,t),u=new Xl(s,o,{format:ln,type:Xt,depthTexture:new jn(s,o,l.stencil?di:Ct,void 0,void 0,void 0,void 0,void 0,void 0,l.stencil?qn:Dn),stencilBuffer:l.stencil,resolveDepthBuffer:!1,resolveStencilBuffer:!1});u._autoAllocateDepthBuffer=!0;const h=new pr({color:16777215,side:ri});h.map=u.texture,h.map.offset.y=1,h.map.repeat.y=-1;const d=new _n(c,h);d.position.copy(n),d.quaternion.copy(i);const f={type:"quad",width:e,height:t,translation:n,quaternion:i,pixelwidth:s,pixelheight:o,plane:d,material:h,rendercall:a,renderTarget:u};if(this._layers.push(f),this._session!==null){f.plane.material=new pr({color:16777215,side:ri}),f.plane.material.blending=co,f.plane.material.blendEquation=Xn,f.plane.material.blendSrc=Gr,f.plane.material.blendDst=Gr,f.xrlayer=this._createXRLayer(f);const p=this._session.renderState.layers;p.unshift(f.xrlayer),this._session.updateRenderState({layers:p})}else u.isXRRenderTarget=!1;return d}createCylinderLayer(e,t,n,i,s,o,a,l,c={}){const u=new Bc(e,e,e*t/n,64,64,!0,Math.PI-t/2,t),h=new Xl(o,a,{format:ln,type:Xt,depthTexture:new jn(o,a,c.stencil?di:Ct,void 0,void 0,void 0,void 0,void 0,void 0,c.stencil?qn:Dn),stencilBuffer:c.stencil,resolveDepthBuffer:!1,resolveStencilBuffer:!1});h._autoAllocateDepthBuffer=!0;const d=new pr({color:16777215,side:Lt});d.map=h.texture,d.map.offset.y=1,d.map.repeat.y=-1;const f=new _n(u,d);f.position.copy(i),f.quaternion.copy(s);const p={type:"cylinder",radius:e,centralAngle:t,aspectratio:n,translation:i,quaternion:s,pixelwidth:o,pixelheight:a,plane:f,material:d,rendercall:l,renderTarget:h};if(this._layers.push(p),this._session!==null){p.plane.material=new pr({color:16777215,side:Lt}),p.plane.material.blending=co,p.plane.material.blendEquation=Xn,p.plane.material.blendSrc=Gr,p.plane.material.blendDst=Gr,p.xrlayer=this._createXRLayer(p);const g=this._session.renderState.layers;g.unshift(p.xrlayer),this._session.updateRenderState({layers:g})}else h.isXRRenderTarget=!1;return f}renderLayers(){const e=new P,t=new Oi,n=this._renderer,i=this.isPresenting;this.isPresenting=!1;const s=new pe;n.getSize(s);const o=n.getRenderTarget();for(const a of this._layers){a.renderTarget.isXRRenderTarget=this._session!==null,a.renderTarget._hasExternalTextures=a.renderTarget.isXRRenderTarget;const l=n.contextNode;let c;if(a.renderTarget.isXRRenderTarget&&this._sessionUsesLayers){a.xrlayer.transform=new XRRigidTransform(a.plane.getWorldPosition(e),a.plane.getWorldQuaternion(t));const u=this._glBinding.getSubImage(a.xrlayer,this._xrFrame);n.backend.setXRRenderTargetTextures(a.renderTarget,u.colorTexture,void 0),n._setXRLayerSize(a.renderTarget.width,a.renderTarget.height),c=i0.get(l),c===void 0&&(c=l.context({getOutput:h=>Av(h,n.toneMapping,n.outputColorSpace)}),i0.set(l,c))}else c=l;n.contextNode=c,n.setRenderTarget(a.renderTarget),a.rendercall(),n.contextNode=l}n.setRenderTarget(o),n._setXRLayerSize(s.x,s.y),this.isPresenting=i}getSession(){return this._session}async setSession(e){const t=this._renderer,n=t.backend;this._gl=t.getContext();const i=this._gl,s=i.getContextAttributes();if(this._session=e,e!==null){if(n.isWebGPUBackend===!0)throw new Error('THREE.XRManager: XR is currently not supported with a WebGPU backend. Use WebGL by passing "{ forceWebGL: true }" to the constructor of the renderer.');if(e.addEventListener("select",this._onSessionEvent),e.addEventListener("selectstart",this._onSessionEvent),e.addEventListener("selectend",this._onSessionEvent),e.addEventListener("squeeze",this._onSessionEvent),e.addEventListener("squeezestart",this._onSessionEvent),e.addEventListener("squeezeend",this._onSessionEvent),e.addEventListener("end",this._onSessionEnd),e.addEventListener("inputsourceschange",this._onInputSourcesChange),await n.makeXRCompatible(),this._currentPixelRatio=t.getPixelRatio(),t.getSize(this._currentSize),this._currentAnimationContext=t._animation.getContext(),this._currentAnimationLoop=t._animation.getAnimationLoop(),t._animation.stop(),this._supportsLayers===!0){let o=null,a=null,l=null;t.depth&&(l=t.stencil?i.DEPTH24_STENCIL8:i.DEPTH_COMPONENT24,o=t.stencil?qn:Dn,a=t.stencil?di:Ct);const c={colorFormat:i.RGBA8,depthFormat:l,scaleFactor:this._framebufferScaleFactor,clearOnAccess:!1};this._useMultiviewIfPossible&&t.hasFeature("OVR_multiview2")&&(c.textureType="texture-array",this._useMultiview=!0),this._glBinding=this.getBinding();const u=this._glBinding.createProjectionLayer(c),h=[u];this._glProjLayer=u,t.setPixelRatio(1),t._setXRLayerSize(u.textureWidth,u.textureHeight);const d=this._useMultiview?2:1,f=new jn(u.textureWidth,u.textureHeight,a,void 0,void 0,void 0,void 0,void 0,void 0,o,d);if(this._xrRenderTarget=new Xl(u.textureWidth,u.textureHeight,{format:ln,type:Xt,colorSpace:t.outputColorSpace,depthTexture:f,stencilBuffer:t.stencil,samples:s.antialias?4:0,resolveDepthBuffer:u.ignoreDepthValues===!1,resolveStencilBuffer:u.ignoreDepthValues===!1,depth:this._useMultiview?2:1,multiview:this._useMultiview}),this._xrRenderTarget._hasExternalTextures=!0,this._xrRenderTarget.depth=this._useMultiview?2:1,this._sessionUsesLayers=e.enabledFeatures.includes("layers"),this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType()),this._sessionUsesLayers)for(const p of this._layers)p.plane.material=new pr({color:16777215,side:p.type==="cylinder"?Lt:ri}),p.plane.material.blending=co,p.plane.material.blendEquation=Xn,p.plane.material.blendSrc=Gr,p.plane.material.blendDst=Gr,p.xrlayer=this._createXRLayer(p),h.unshift(p.xrlayer);e.updateRenderState({layers:h})}else{const o={antialias:t.currentSamples>0,alpha:!0,depth:t.depth,stencil:t.stencil,framebufferScaleFactor:this.getFramebufferScaleFactor()},a=new XRWebGLLayer(e,i,o);this._glBaseLayer=a,e.updateRenderState({baseLayer:a}),t.setPixelRatio(1),t._setXRLayerSize(a.framebufferWidth,a.framebufferHeight),this._xrRenderTarget=new Xl(a.framebufferWidth,a.framebufferHeight,{format:ln,type:Xt,colorSpace:t.outputColorSpace,stencilBuffer:t.stencil,resolveDepthBuffer:a.ignoreDepthValues===!1,resolveStencilBuffer:a.ignoreDepthValues===!1}),this._xrRenderTarget._isOpaqueFramebuffer=!0,this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType())}this.setFoveation(this.getFoveation()),t._animation.setAnimationLoop(this._onAnimationFrame),t._animation.setContext(e),t._animation.start(),this.isPresenting=!0,this.dispatchEvent({type:"sessionstart"})}}updateCamera(e){const t=this._session;if(t===null)return;const n=e.near,i=e.far,s=this._cameraXR,o=this._cameraL,a=this._cameraR;s.near=a.near=o.near=n,s.far=a.far=o.far=i,s.isMultiViewCamera=this._useMultiview,(this._currentDepthNear!==s.near||this._currentDepthFar!==s.far)&&(t.updateRenderState({depthNear:s.near,depthFar:s.far}),this._currentDepthNear=s.near,this._currentDepthFar=s.far),s.layers.mask=e.layers.mask|6,o.layers.mask=s.layers.mask&-5,a.layers.mask=s.layers.mask&-3;const l=e.parent,c=s.cameras;r0(s,l);for(let u=0;u<c.length;u++)r0(c[u],l);c.length===2?nB(s,o,a):s.projectionMatrix.copy(o.projectionMatrix),iB(e,s,l)}_getController(e){let t=this._controllers[e];return t===void 0&&(t=new oh,this._controllers[e]=t),t}}function nB(r,e,t){t0.setFromMatrixPosition(e.matrixWorld),n0.setFromMatrixPosition(t.matrixWorld);const n=t0.distanceTo(n0),i=e.projectionMatrix.elements,s=t.projectionMatrix.elements,o=i[14]/(i[10]-1),a=i[14]/(i[10]+1),l=(i[9]+1)/i[5],c=(i[9]-1)/i[5],u=(i[8]-1)/i[0],h=(s[8]+1)/s[0],d=o*u,f=o*h,p=n/(-u+h),g=p*-u;if(e.matrixWorld.decompose(r.position,r.quaternion,r.scale),r.translateX(g),r.translateZ(p),r.matrixWorld.compose(r.position,r.quaternion,r.scale),r.matrixWorldInverse.copy(r.matrixWorld).invert(),i[10]===-1)r.projectionMatrix.copy(e.projectionMatrix),r.projectionMatrixInverse.copy(e.projectionMatrixInverse);else{const m=o+p,_=a+p,x=d-g,y=f+(n-g),b=l*a/_*m,M=c*a/_*m;r.projectionMatrix.makePerspective(x,y,b,M,m,_),r.projectionMatrixInverse.copy(r.projectionMatrix).invert()}}function r0(r,e){e===null?r.matrixWorld.copy(r.matrix):r.matrixWorld.multiplyMatrices(e.matrixWorld,r.matrix),r.matrixWorldInverse.copy(r.matrixWorld).invert()}function iB(r,e,t){t===null?r.matrix.copy(e.matrixWorld):(r.matrix.copy(t.matrixWorld),r.matrix.invert(),r.matrix.multiply(e.matrixWorld)),r.matrix.decompose(r.position,r.quaternion,r.scale),r.updateMatrixWorld(!0),r.projectionMatrix.copy(e.projectionMatrix),r.projectionMatrixInverse.copy(e.projectionMatrixInverse),r.isPerspectiveCamera&&(r.fov=xo*2*Math.atan(1/r.projectionMatrix.elements[5]),r.zoom=1)}function rB(r){const e=this._controllerInputSources.indexOf(r.inputSource);if(e===-1)return;const t=this._controllers[e];if(t!==void 0){const n=this.getReferenceSpace();t.update(r.inputSource,r.frame,n),t.dispatchEvent({type:r.type,data:r.inputSource})}}function sB(){const r=this._session,e=this._renderer;r.removeEventListener("select",this._onSessionEvent),r.removeEventListener("selectstart",this._onSessionEvent),r.removeEventListener("selectend",this._onSessionEvent),r.removeEventListener("squeeze",this._onSessionEvent),r.removeEventListener("squeezestart",this._onSessionEvent),r.removeEventListener("squeezeend",this._onSessionEvent),r.removeEventListener("end",this._onSessionEnd),r.removeEventListener("inputsourceschange",this._onInputSourcesChange);for(let t=0;t<this._controllers.length;t++){const n=this._controllerInputSources[t];n!==null&&(this._controllerInputSources[t]=null,this._controllers[t].disconnect(n))}if(this._currentDepthNear=null,this._currentDepthFar=null,e._resetXRState(),this._session=null,this._xrRenderTarget=null,this._glBinding=null,this._glBaseLayer=null,this._glProjLayer=null,this._sessionUsesLayers===!0)for(const t of this._layers)t.renderTarget=new Xl(t.pixelwidth,t.pixelheight,{format:ln,type:Xt,depthTexture:new jn(t.pixelwidth,t.pixelheight,t.stencilBuffer?di:Ct,void 0,void 0,void 0,void 0,void 0,void 0,t.stencilBuffer?qn:Dn),stencilBuffer:t.stencilBuffer,resolveDepthBuffer:!1,resolveStencilBuffer:!1}),t.renderTarget.isXRRenderTarget=!1,t.plane.material=t.material,t.material.map=t.renderTarget.texture,t.material.map.offset.y=1,t.material.map.repeat.y=-1,delete t.xrlayer;this.isPresenting=!1,this._useMultiview=!1,e._animation.stop(),e._animation.setAnimationLoop(this._currentAnimationLoop),e._animation.setContext(this._currentAnimationContext),e._animation.start(),e.setPixelRatio(this._currentPixelRatio),e.setSize(this._currentSize.width,this._currentSize.height,!1),this.dispatchEvent({type:"sessionend"})}function oB(r){const e=this._controllers,t=this._controllerInputSources;for(let n=0;n<r.removed.length;n++){const i=r.removed[n],s=t.indexOf(i);s>=0&&(t[s]=null,e[s].disconnect(i))}for(let n=0;n<r.added.length;n++){const i=r.added[n];let s=t.indexOf(i);if(s===-1){for(let a=0;a<e.length;a++)if(a>=t.length){t.push(i),s=a;break}else if(t[a]===null){t[a]=i,s=a;break}if(s===-1)break}const o=e[s];o&&o.connect(i)}}function aB(r){return r.type==="quad"?this._glBinding.createQuadLayer({transform:new XRRigidTransform(r.translation,r.quaternion),width:r.width/2,height:r.height/2,space:this._referenceSpace,viewPixelWidth:r.pixelwidth,viewPixelHeight:r.pixelheight,clearOnAccess:!1}):this._glBinding.createCylinderLayer({transform:new XRRigidTransform(r.translation,r.quaternion),radius:r.radius,centralAngle:r.centralAngle,aspectRatio:r.aspectRatio,space:this._referenceSpace,viewPixelWidth:r.pixelwidth,viewPixelHeight:r.pixelheight,clearOnAccess:!1})}function lB(r,e){if(e===void 0)return;const t=this._cameraXR,n=this._renderer,i=n.backend,s=this._glBaseLayer,o=this.getReferenceSpace(),a=e.getViewerPose(o);if(this._xrFrame=e,a!==null){const l=a.views;this._glBaseLayer!==null&&i.setXRTarget(s.framebuffer);let c=!1;l.length!==t.cameras.length&&(t.cameras.length=0,c=!0);for(let u=0;u<l.length;u++){const h=l[u];let d;if(this._supportsLayers===!0){const p=this._glBinding.getViewSubImage(this._glProjLayer,h);d=p.viewport,u===0&&i.setXRRenderTargetTextures(this._xrRenderTarget,p.colorTexture,this._glProjLayer.ignoreDepthValues&&!this._useMultiview?void 0:p.depthStencilTexture)}else d=s.getViewport(h);let f=this._cameras[u];f===void 0&&(f=new Cn,f.layers.enable(u),f.viewport=new rt,this._cameras[u]=f),f.matrix.fromArray(h.transform.matrix),f.matrix.decompose(f.position,f.quaternion,f.scale),f.projectionMatrix.fromArray(h.projectionMatrix),f.projectionMatrixInverse.copy(f.projectionMatrix).invert(),f.viewport.set(d.x,d.y,d.width,d.height),u===0&&(t.matrix.copy(f.matrix),t.matrix.decompose(t.position,t.quaternion,t.scale)),c===!0&&t.cameras.push(f)}n.setOutputRenderTarget(this._xrRenderTarget)}for(let l=0;l<this._controllers.length;l++){const c=this._controllerInputSources[l],u=this._controllers[l];c!==null&&u!==void 0&&u.update(c,e,o)}this._currentAnimationLoop&&this._currentAnimationLoop(r,e),e.detectedPlanes&&this.dispatchEvent({type:"planesdetected",data:e}),this._xrFrame=null}class cB extends Vi{constructor(e){super(),this.domElement=e,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new rt(0,0,this._width,this._height),this._scissor=new rt(0,0,this._width,this._height),this._scissorTest=!1,this.colorTexture=new ny,this.depthTexture=new jn}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,n){this.xr&&this.xr.isPresenting||(this._width=e,this._height=t,this._pixelRatio=n,this.domElement.width=Math.floor(e*n),this.domElement.height=Math.floor(t*n),this.setViewport(0,0,e,t),this._dispatchResize())}setSize(e,t,n=!0){this.xr&&this.xr.isPresenting||(this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),n===!0&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._dispatchResize())}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,n,i){const s=this._scissor;e.isVector4?s.copy(e):s.set(e,t,n,i)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,n,i,s=0,o=1){const a=this._viewport;e.isVector4?a.copy(e):a.set(e,t,n,i),a.minDepth=s,a.maxDepth=o}_dispatchResize(){this.dispatchEvent({type:"resize"})}dispose(){this.dispatchEvent({type:"dispose"})}}const s0=new hm,oa=new pe,If=new rt,Bf=new Ic,Of=new _m,Yu=new pt,Br=new rt,uB={[ri]:Lt,[Lt]:ri,[Nn]:Nn};class hB{constructor(e,t={}){this.isRenderer=!0;const{logarithmicDepthBuffer:n=!1,reversedDepthBuffer:i=!1,alpha:s=!0,depth:o=!0,stencil:a=!1,antialias:l=!1,samples:c=0,getFallback:u=null,outputBufferType:h=tn,multiview:d=!1}=t;this.backend=e,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=s,this.logarithmicDepthBuffer=n,this.reversedDepthBuffer=i,this.outputColorSpace=ei,this.toneMapping=Fn,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=o,this.stencil=a,this.info=new HF,this.contextNode=Po(),this.library=new Ub,this.lighting=new eB,this._samples=c||l===!0?4:0,this._onCanvasTargetResize=this._onCanvasTargetResize.bind(this),this._canvasTarget=new cB(e.getDomElement()),this._canvasTarget.addEventListener("resize",this._onCanvasTargetResize),this._canvasTarget.isDefaultCanvasTarget=!0,this._inspector=new wv,this._inspector.setRenderer(this),this._getFallback=u,this._attributes=null,this._geometries=null,this._nodes=null,this._animation=null,this._bindings=null,this._objects=null,this._pipelines=null,this._bundles=null,this._renderLists=null,this._renderContexts=null,this._textures=null,this._background=null,this._quadCache=new Map,this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTargets=new Map;const f=this.alpha===!0?0:1;this._clearColor=new jm(0,0,0,f),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._outputRenderTarget=null,this._mrt=null,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._isDeviceLost=!1,this.onDeviceLost=this._onDeviceLost,this._outputBufferType=h,this._cacheShadowNodes=new WeakMap,this._initialized=!1,this._callDepth=-1,this._initPromise=null,this._compilationPromises=null,this.transparent=!0,this.opaque=!0,this.shadowMap={enabled:!1,transmitted:!1,type:fa},this.xr=new tB(this,d),this.debug={checkShaderErrors:!0,onShaderError:null,getShaderAsync:async(p,g,m)=>{await this.compileAsync(p,g);const _=this._renderLists.get(p,g),x=this._renderContexts.get(this._renderTarget,this._mrt),y=p.overrideMaterial||m.material,b=this._objects.get(m,y,p,g,_.lightsNode,x,x.clippingContext),{fragmentShader:M,vertexShader:S}=b.getNodeBuilderState();return{fragmentShader:M,vertexShader:S}}}}async init(){return this._initPromise!==null?this._initPromise:(this._initPromise=new Promise(async(e,t)=>{let n=this.backend;try{await n.init(this)}catch(i){if(this._getFallback!==null)try{this.backend=n=this._getFallback(i),await n.init(this)}catch(s){t(s);return}else{t(i);return}}this._nodes=new K2(this,n),this._animation=new UF(this,this._nodes,this.info),this._attributes=new VF(n,this.info),this._background=new u2(this,this._nodes),this._geometries=new zF(this._attributes,this.info),this._textures=new nI(this,n,this.info),this._pipelines=new qF(n,this._nodes,this.info),this._bindings=new jF(n,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new OF(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new ZF(this.lighting),this._bundles=new Q2,this._renderContexts=new eI(this),this._animation.start(),this._initialized=!0,this._inspector.init(),e(this)}),this._initPromise)}get domElement(){return this._canvasTarget.domElement}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,n=null){if(this._isDeviceLost===!0)return;this._initialized===!1&&await this.init();const i=this._nodes.nodeFrame,s=i.renderId,o=this._currentRenderContext,a=this._currentRenderObjectFunction,l=this._handleObjectFunction,c=this._compilationPromises;n===null&&(n=e);const u=e.isScene===!0?e:n.isScene===!0?n:s0,d=this.needsFrameBufferTarget&&this._renderTarget===null?this._getFrameBufferTarget():this._renderTarget||this._outputRenderTarget,f=this._renderContexts.get(d,this._mrt),p=this._activeMipmapLevel,g=[];this._currentRenderContext=f,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=g,i.renderId++,i.update(),f.depth=this.depth,f.stencil=this.stencil,f.clippingContext||(f.clippingContext=new Nh),f.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,d);const m=this._renderLists.get(u,t);if(m.begin(),this._projectObject(e,t,0,m,f.clippingContext),n!==e&&n.traverseVisible(function(M){M.isLight&&M.layers.test(t.layers)&&m.pushLight(M)}),m.finish(),d!==null){this._textures.updateRenderTarget(d,p);const M=this._textures.get(d);f.textures=M.textures,f.depthTexture=M.depthTexture}else f.textures=null,f.depthTexture=null;n!==e?this._background.update(n,m,f):this._background.update(u,m,f);const _=m.opaque,x=m.transparent,y=m.transparentDoublePass,b=m.lightsNode;this.opaque===!0&&_.length>0&&this._renderObjects(_,t,u,b),this.transparent===!0&&x.length>0&&this._renderTransparents(x,y,t,u,b),i.renderId=s,this._currentRenderContext=o,this._currentRenderObjectFunction=a,this._handleObjectFunction=l,this._compilationPromises=c;for(const M of g){const S=this._objects.get(M.object,M.material,M.scene,M.camera,M.lightsNode,M.renderContext,M.clippingContext,M.passId);S.drawRange=M.object.geometry.drawRange,S.group=M.group,this._geometries.updateForRender(S),await this._nodes.getForRenderAsync(S),this._nodes.updateBefore(S),this._nodes.updateForRender(S),this._bindings.updateForRender(S);const E=[];this._pipelines.getForRender(S,E),E.length>0&&await Promise.all(E),this._nodes.updateAfter(S),await Q0()}}async renderAsync(e,t){Kt('Renderer: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.render(e,t)}async waitForGPU(){ce("Renderer: waitForGPU() has been removed. Read https://github.com/mrdoob/three.js/issues/32012 for more information.")}set inspector(e){this._inspector!==null&&this._inspector.setRenderer(null),this._inspector=e,this._inspector.setRenderer(this)}get inspector(){return this._inspector}set highPrecision(e){const t=this.contextNode.value;e===!0?(t.modelViewMatrix=sx,t.modelNormalViewMatrix=ox):this.highPrecision&&(delete t.modelViewMatrix,delete t.modelNormalViewMatrix)}get highPrecision(){const e=this.contextNode.value;return e.modelViewMatrix===sx&&e.modelNormalViewMatrix===ox}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getOutputBufferType(){return this._outputBufferType}getColorBufferType(){return Kt('Renderer: ".getColorBufferType()" has been renamed to ".getOutputBufferType()".'),this.getOutputBufferType()}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:
4657
+ `}needsPreviousData(){const e=this.renderer.getMRT();return e&&e.has("velocity")||$y(this.object).useVelocity===!0}}class Qx{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let n=e.get(t);return n===void 0&&(n={renderId:0,frameId:0},e.set(t,n)),n}updateBeforeNode(e){const t=e.getUpdateBeforeType(),n=e.updateReference(this);if(t===Ze.FRAME){const i=this._getMaps(this.updateBeforeMap,n);if(i.frameId!==this.frameId){const s=i.frameId;i.frameId=this.frameId,e.updateBefore(this)===!1&&(i.frameId=s)}}else if(t===Ze.RENDER){const i=this._getMaps(this.updateBeforeMap,n);if(i.renderId!==this.renderId){const s=i.renderId;i.renderId=this.renderId,e.updateBefore(this)===!1&&(i.renderId=s)}}else t===Ze.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),n=e.updateReference(this);if(t===Ze.FRAME){const i=this._getMaps(this.updateAfterMap,n);i.frameId!==this.frameId&&e.updateAfter(this)!==!1&&(i.frameId=this.frameId)}else if(t===Ze.RENDER){const i=this._getMaps(this.updateAfterMap,n);i.renderId!==this.renderId&&e.updateAfter(this)!==!1&&(i.renderId=this.renderId)}else t===Ze.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),n=e.updateReference(this);if(t===Ze.FRAME){const i=this._getMaps(this.updateMap,n);i.frameId!==this.frameId&&e.update(this)!==!1&&(i.frameId=this.frameId)}else if(t===Ze.RENDER){const i=this._getMaps(this.updateMap,n);i.renderId!==this.renderId&&e.update(this)!==!1&&(i.renderId=this.renderId)}else t===Ze.OBJECT&&e.update(this)}update(){this.frameId++,this.lastTime===void 0&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class Zm{constructor(e,t,n=null,i="",s=!1){this.type=e,this.name=t,this.count=n,this.qualifier=i,this.isConst=s}}Zm.isNodeFunctionInput=!0;class B2 extends Lo{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class O2 extends Lo{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setupDirect(){const e=this.colorNode;return{lightDirection:Ab(this.light),lightColor:e}}}class k2 extends Lo{static get type(){return"HemisphereLightNode"}constructor(e=null){super(e),this.lightPositionNode=Mb(e),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=qe(new We).setGroup(Ke)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:n,lightDirectionNode:i}=this,o=ml.dot(i).mul(.5).add(.5),a=Dt(n,t,o);e.context.irradiance.addAssign(a)}}class Qm extends Lo{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=qe(0).setGroup(Ke),this.penumbraCosNode=qe(0).setGroup(Ke),this.cutoffDistanceNode=qe(0).setGroup(Ke),this.decayExponentNode=qe(0).setGroup(Ke),this.colorNode=qe(this.color).setGroup(Ke)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e,t){const{coneCosNode:n,penumbraCosNode:i}=this;return Qr(n,i,t)}getLightCoord(e){const t=e.getNodeProperties(this);let n=t.projectionUV;return n===void 0&&(n=wI(this.light,e.context.positionWorld),t.projectionUV=n),n}setupDirect(e){const{colorNode:t,cutoffDistanceNode:n,decayExponentNode:i,light:s}=this,o=this.getLightVector(e),a=o.normalize(),l=a.dot(Ab(s)),c=this.getSpotAttenuation(e,l),u=o.length(),h=Nb({lightDistance:u,cutoffDistance:n,decayExponent:i});let d=t.mul(c).mul(h),f,p;return s.colorNode?(p=this.getLightCoord(e),f=s.colorNode(p)):s.map&&(p=this.getLightCoord(e),f=Vt(s.map,p.xy).onRenderUpdate(()=>s.map)),f&&(d=p.mul(2).sub(1).abs().lessThan(1).all().select(d.mul(f),d)),{lightColor:d,lightDirection:a}}}class G2 extends Qm{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e,t){const n=this.light.iesMap;let i=null;if(n&&n.isTexture===!0){const s=t.acos().mul(1/Math.PI);i=Vt(n,ke(s,0),0).r}else i=super.getSpotAttenuation(t);return i}}class V2 extends Lo{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let n=0;n<9;n++)t.push(new P);this.lightProbe=Pi(t)}update(e){const{light:t}=this;super.update(e);for(let n=0;n<9;n++)this.lightProbe.array[n].copy(t.sh.coefficients[n]).multiplyScalar(t.intensity)}setup(e){const t=c2(ml,this.lightProbe);e.context.irradiance.addAssign(t)}}const z2=re(([r,e])=>{const t=r.abs().sub(e);return Kr(kn(t,0)).add(Qa(kn(t.x,t.y),0))});class H2 extends Qm{static get type(){return"ProjectorLightNode"}update(e){super.update(e);const t=this.light;if(this.penumbraCosNode.value=Math.min(Math.cos(t.angle*(1-t.penumbra)),.99999),t.aspect===null){let n=1;t.map!==null&&(n=t.map.width/t.map.height),t.shadow.aspect=n}else t.shadow.aspect=t.aspect}getSpotAttenuation(e){const t=J(0),n=this.penumbraCosNode,i=Km(this.light).mul(e.context.positionWorld||Ja);return Ft(i.w.greaterThan(0),()=>{const s=i.xyz.div(i.w),o=z2(s.xy.sub(ke(.5)),ke(.5)),a=Er(-1,oi(1,cv(n)).sub(1));t.assign(Gm(o.mul(-2).mul(a)))}),t}}const Uf=new pt,ju=new pt;let Gl=null;class W2 extends Lo{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=qe(new P).setGroup(Ke),this.halfWidth=qe(new P).setGroup(Ke),this.updateType=Ze.RENDER}update(e){super.update(e);const{light:t}=this,n=e.camera.matrixWorldInverse;ju.identity(),Uf.copy(t.matrixWorld),Uf.premultiply(n),ju.extractRotation(Uf),this.halfWidth.value.set(t.width*.5,0,0),this.halfHeight.value.set(0,t.height*.5,0),this.halfWidth.value.applyMatrix4(ju),this.halfHeight.value.applyMatrix4(ju)}setupDirectRectArea(e){let t,n;e.isAvailable("float32Filterable")?(t=Vt(Gl.LTC_FLOAT_1),n=Vt(Gl.LTC_FLOAT_2)):(t=Vt(Gl.LTC_HALF_1),n=Vt(Gl.LTC_HALF_2));const{colorNode:i,light:s}=this,o=Eb(s);return{lightColor:i,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,ltc_1:t,ltc_2:n}}static setLTC(e){Gl=e}}class Lb{parseFunction(){ae("Abstract function.")}}class Jm{constructor(e,t,n="",i=""){this.type=e,this.inputs=t,this.name=n,this.precision=i}getCode(){ae("Abstract function.")}}Jm.isNodeFunction=!0;const $2=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,X2=/[a-z_0-9]+/ig,Jx="#pragma main",q2=r=>{r=r.trim();const e=r.indexOf(Jx),t=e!==-1?r.slice(e+Jx.length):r,n=t.match($2);if(n!==null&&n.length===5){const i=n[4],s=[];let o=null;for(;(o=X2.exec(i))!==null;)s.push(o);const a=[];let l=0;for(;l<s.length;){const p=s[l][0]==="const";p===!0&&l++;let g=s[l][0];g==="in"||g==="out"||g==="inout"?l++:g="";const m=s[l++][0];let _=Number.parseInt(s[l][0]);Number.isNaN(_)===!1?l++:_=null;const x=s[l++][0];a.push(new Zm(m,x,_,g,p))}const c=t.substring(n[0].length),u=n[3]!==void 0?n[3]:"",h=n[2],d=n[1]!==void 0?n[1]:"",f=e!==-1?r.slice(0,e):"";return{type:h,inputs:a,name:u,precision:d,inputsCode:i,blockCode:c,headerCode:f}}else throw new Error("FunctionNode: Function is not a GLSL code.")};class j2 extends Jm{constructor(e){const{type:t,inputs:n,name:i,precision:s,inputsCode:o,blockCode:a,headerCode:l}=q2(e);super(t,n,i,s),this.inputsCode=o,this.blockCode=a,this.headerCode=l}getCode(e=this.name){let t;const n=this.blockCode;if(n!==""){const{type:i,inputsCode:s,headerCode:o,precision:a}=this;let l=`${i} ${e} ( ${s.trim()} )`;a!==""&&(l=`${a} ${l}`),t=o+l+n}else t="";return t}}class Y2 extends Lb{parseFunction(e){return new j2(e)}}const wi=[],hs=[];class K2 extends Gs{constructor(e,t){super(),this.renderer=e,this.backend=t,this.nodeFrame=new Qx,this.nodeBuilderCache=new Map,this.callHashCache=new Bs,this.groupsData=new Bs,this._buildQueue=[],this._buildInProgress=!1,this.cacheLib={}}updateGroup(e){const t=e.groupNode;wi[0]=t,wi[1]=e;let n=this.groupsData.get(wi);return n===void 0&&this.groupsData.set(wi,n={}),wi[0]=null,wi[1]=null,n.version!==t.version?(n.version=t.version,!0):!1}getForRenderCacheKey(e){return e.initialCacheKey}_createNodeBuilder(e,t){const n=this.backend.createNodeBuilder(e.object,this.renderer);return n.scene=e.scene,n.material=t,n.camera=e.camera,n.context.material=t,n.lightsNode=e.lightsNode,n.environmentNode=this.getEnvironmentNode(e.scene),n.fogNode=this.getFogNode(e.scene),n.clippingContext=e.clippingContext,this.renderer.getOutputRenderTarget()&&this.renderer.getOutputRenderTarget().multiview&&n.enableMultiview(),n}getForRender(e,t=!1){const n=this.get(e);let i=n.nodeBuilderState;if(i===void 0){const{nodeBuilderCache:s}=this,o=this.getForRenderCacheKey(e);if(i=s.get(o),i===void 0){const a=async()=>{let l=this._createNodeBuilder(e,e.material);try{t?await l.buildAsync():l.build()}catch(c){l=this._createNodeBuilder(e,new mn),t?await l.buildAsync():l.build(),ce("TSL: "+c)}return l};if(t)return a().then(l=>(i=this._createNodeBuilderState(l),s.set(o,i),i.usedTimes++,n.nodeBuilderState=i,i));{let l=this._createNodeBuilder(e,e.material);try{l.build()}catch(c){l=this._createNodeBuilder(e,new mn),l.build();let u=c.stackTrace;!u&&c.stack&&(u=new Kn(c.stack)),ce("TSL: "+c,u)}i=this._createNodeBuilderState(l),s.set(o,i)}}i.usedTimes++,n.nodeBuilderState=i}return i}getForRenderAsync(e){const t=this.getForRender(e,!0);return t.then?t:Promise.resolve(t)}getForRenderDeferred(e){const t=this.get(e);if(t.nodeBuilderState!==void 0)return t.nodeBuilderState;const n=this.getForRenderCacheKey(e),i=this.nodeBuilderCache.get(n);return i!==void 0?(i.usedTimes++,t.nodeBuilderState=i,i):(t.pendingBuild!==!0&&(t.pendingBuild=!0,this._buildQueue.push(()=>this.getForRenderAsync(e).then(()=>{t.pendingBuild=!1})),this._processBuildQueue()),null)}_processBuildQueue(){if(this._buildInProgress||this._buildQueue.length===0)return;this._buildInProgress=!0,this._buildQueue.shift()().then(()=>{this._buildInProgress=!1,this._processBuildQueue()})}delete(e){if(e.isRenderObject){const t=this.get(e).nodeBuilderState;t!==void 0&&(t.usedTimes--,t.usedTimes===0&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(e)))}return super.delete(e)}getForCompute(e){const t=this.get(e);let n=t.nodeBuilderState;if(n===void 0){const i=this.backend.createNodeBuilder(e,this.renderer);i.build(),n=this._createNodeBuilderState(i),t.nodeBuilderState=n}return n}_createNodeBuilderState(e){return new d2(e.vertexShader,e.fragmentShader,e.computeShader,e.getAttributesArray(),e.getBindings(),e.updateNodes,e.updateBeforeNodes,e.updateAfterNodes,e.observer,e.transforms)}getEnvironmentNode(e){this.updateEnvironment(e);let t=null;if(e.environmentNode&&e.environmentNode.isNode)t=e.environmentNode;else{const n=this.get(e);n.environmentNode&&(t=n.environmentNode)}return t}getBackgroundNode(e){this.updateBackground(e);let t=null;if(e.backgroundNode&&e.backgroundNode.isNode)t=e.backgroundNode;else{const n=this.get(e);n.backgroundNode&&(t=n.backgroundNode)}return t}getFogNode(e){return this.updateFog(e),e.fogNode||this.get(e).fogNode||null}getCacheKey(e,t){wi[0]=e,wi[1]=t;const n=this.renderer.info.calls,i=this.callHashCache.get(wi)||{};if(i.callId!==n){const s=this.getEnvironmentNode(e),o=this.getFogNode(e);t&&hs.push(t.getCacheKey(!0)),s&&hs.push(s.getCacheKey()),o&&hs.push(o.getCacheKey()),hs.push(this.renderer.getOutputRenderTarget()&&this.renderer.getOutputRenderTarget().multiview?1:0),hs.push(this.renderer.shadowMap.enabled?1:0),hs.push(this.renderer.shadowMap.type),i.callId=n,i.cacheKey=Gc(hs),this.callHashCache.set(wi,i),hs.length=0}return wi[0]=null,wi[1]=null,i.cacheKey}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(e){const t=this.get(e),n=e.background;if(n){const i=e.backgroundBlurriness===0&&t.backgroundBlurriness>0||e.backgroundBlurriness>0&&t.backgroundBlurriness===0;if(t.background!==n||i){const s=this.getCacheNode("background",n,()=>{if(n.isCubeTexture===!0||n.mapping===pa||n.mapping===ma||n.mapping===mo){if(e.backgroundBlurriness>0||n.mapping===mo)return fb(n);{let o;return n.isCubeTexture===!0?o=li(n):o=Vt(n),rb(o)}}else{if(n.isTexture===!0)return Vt(n,fo.flipY()).setUpdateMatrix(!0);n.isColor!==!0&&ce("WebGPUNodes: Unsupported background configuration.",n)}},i);t.backgroundNode=s,t.background=n,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}getCacheNode(e,t,n,i=!1){const s=this.cacheLib[e]||(this.cacheLib[e]=new WeakMap);let o=s.get(t);return(o===void 0||i)&&(o=n(),s.set(t,o)),o}updateFog(e){const t=this.get(e),n=e.fog;if(n){if(t.fog!==n){const i=this.getCacheNode("fog",n,()=>{if(n.isFogExp2){const s=Jt("color","color",n).setGroup(Ke),o=Jt("density","float",n).setGroup(Ke);return qx(s,EI(o))}else if(n.isFog){const s=Jt("color","color",n).setGroup(Ke),o=Jt("near","float",n).setGroup(Ke),a=Jt("far","float",n).setGroup(Ke);return qx(s,MI(o,a))}else ce("Renderer: Unsupported fog configuration.",n)});t.fogNode=i,t.fog=n}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),n=e.environment;if(n){if(t.environment!==n){const i=this.getCacheNode("environment",n,()=>{if(n.isCubeTexture===!0)return li(n);if(n.isTexture===!0)return Vt(n);ce("Nodes: Unsupported environment configuration.",n)});t.environmentNode=i,t.environment=n}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,n=null,i=null,s=null){const o=this.nodeFrame;return o.renderer=e,o.scene=t,o.object=n,o.camera=i,o.material=s,o}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace+","+e.xr.isPresenting}getOutputNode(e){const t=this.renderer;return e.isArrayTexture?Vt(e,fo).depth(fl("gl_ViewID_OVR")).renderOutput(t.toneMapping,t.currentColorSpace):Vt(e,fo).renderOutput(t.toneMapping,t.currentColorSpace)}updateBefore(e){const t=e.getNodeBuilderState();for(const n of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(n)}updateAfter(e){const t=e.getNodeBuilderState();for(const n of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(n)}updateForCompute(e){const t=this.getNodeFrame(),n=this.getForCompute(e);for(const i of n.updateNodes)t.updateNode(i)}updateForRender(e){const t=this.getNodeFrameForRender(e),n=e.getNodeBuilderState();for(const i of n.updateNodes)t.updateNode(i)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new Qx,this.nodeBuilderCache=new Map,this.cacheLib={}}}const Ff=new ur;class Nh{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",this.shadowPass=!1,this.viewNormalMatrix=new Je,this.clippingGroupContexts=new WeakMap,this.intersectionPlanes=[],this.unionPlanes=[],this.parentVersion=null,e!==null&&(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix)}projectPlanes(e,t,n){const i=e.length;for(let s=0;s<i;s++){Ff.copy(e[s]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);const o=t[n+s],a=Ff.normal;o.x=-a.x,o.y=-a.y,o.z=-a.z,o.w=Ff.constant}}updateGlobal(e,t){this.shadowPass=e.overrideMaterial!==null&&e.overrideMaterial.isShadowPassMaterial,this.viewMatrix=t.matrixWorldInverse,this.viewNormalMatrix.getNormalMatrix(this.viewMatrix)}update(e,t){let n=!1;e.version!==this.parentVersion&&(this.intersectionPlanes=Array.from(e.intersectionPlanes),this.unionPlanes=Array.from(e.unionPlanes),this.parentVersion=e.version),this.clipIntersection!==t.clipIntersection&&(this.clipIntersection=t.clipIntersection,this.clipIntersection?this.unionPlanes.length=e.unionPlanes.length:this.intersectionPlanes.length=e.intersectionPlanes.length);const i=t.clippingPlanes,s=i.length;let o,a;if(this.clipIntersection?(o=this.intersectionPlanes,a=e.intersectionPlanes.length):(o=this.unionPlanes,a=e.unionPlanes.length),o.length!==a+s){o.length=a+s;for(let l=0;l<s;l++)o[a+l]=new rt;n=!0}this.projectPlanes(i,o,a),n&&(this.version++,this.cacheKey=`${this.intersectionPlanes.length}:${this.unionPlanes.length}`)}getGroupContext(e){if(this.shadowPass&&!e.clipShadows)return this;let t=this.clippingGroupContexts.get(e);return t===void 0&&(t=new Nh(this),this.clippingGroupContexts.set(e,t)),t.update(this,e),t}get unionClippingCount(){return this.unionPlanes.length}}class Z2{constructor(e,t,n){this.bundleGroup=e,this.camera=t,this.renderContext=n}}const ds=[];class Q2{constructor(){this.bundles=new Bs}get(e,t,n){const i=this.bundles;ds[0]=e,ds[1]=t,ds[2]=n;let s=i.get(ds);return s===void 0&&(s=new Z2(e,t,n),i.set(ds,s)),ds[0]=null,ds[1]=null,ds[2]=null,s}dispose(){this.bundles=new Bs}}class Ub{constructor(){this.lightNodes=new WeakMap,this.materialNodes=new Map,this.toneMappingNodes=new Map}fromMaterial(e){if(e.isNodeMaterial)return e;let t=null;const n=this.getMaterialNodeClass(e.type);if(n!==null){t=new n;for(const i in e)t[i]=e[i]}return t}addToneMapping(e,t){this.addType(e,t,this.toneMappingNodes)}getToneMappingFunction(e){return this.toneMappingNodes.get(e)||null}getMaterialNodeClass(e){return this.materialNodes.get(e)||null}addMaterial(e,t){this.addType(e,t,this.materialNodes)}getLightNodeClass(e){return this.lightNodes.get(e)||null}addLight(e,t){this.addClass(e,t,this.lightNodes)}addType(e,t,n){if(n.has(t)){ae(`Redefinition of node ${t}`);return}if(typeof e!="function")throw new Error(`Node class ${e.name} is not a class.`);if(typeof t=="function"||typeof t=="object")throw new Error(`Base class ${t} is not a class.`);n.set(t,e)}addClass(e,t,n){if(n.has(t)){ae(`Redefinition of node ${t.name}`);return}if(typeof e!="function")throw new Error(`Node class ${e.name} is not a class.`);if(typeof t!="function")throw new Error(`Base class ${t.name} is not a class.`);n.set(t,e)}}const J2=new wb,e0=new WeakMap;class eB{createNode(e=[]){return new wb().setLights(e)}getNode(e){if(e.isQuadMesh)return J2;let t=e0.get(e);return t===void 0&&(t=this.createNode(),e0.set(e,t)),t}}class Xl extends ks{constructor(e=1,t=1,n={}){super(e,t,n),this.isXRRenderTarget=!0,this._hasExternalTextures=!1,this._autoAllocateDepthBuffer=!0,this._isOpaqueFramebuffer=!1}copy(e){return super.copy(e),this._hasExternalTextures=e._hasExternalTextures,this._autoAllocateDepthBuffer=e._autoAllocateDepthBuffer,this._isOpaqueFramebuffer=e._isOpaqueFramebuffer,this}}const t0=new P,n0=new P,i0=new WeakMap;class tB extends Vi{constructor(e,t=!1){super(),this.enabled=!1,this.isPresenting=!1,this.cameraAutoUpdate=!0,this._renderer=e,this._cameraL=new Cn,this._cameraL.viewport=new rt,this._cameraR=new Cn,this._cameraR.viewport=new rt,this._cameras=[this._cameraL,this._cameraR],this._cameraXR=new my,this._currentDepthNear=null,this._currentDepthFar=null,this._controllers=[],this._controllerInputSources=[],this._xrRenderTarget=null,this._layers=[],this._sessionUsesLayers=!1,this._supportsGlBinding=typeof XRWebGLBinding<"u",this._createXRLayer=aB.bind(this),this._gl=null,this._currentAnimationContext=null,this._currentAnimationLoop=null,this._currentPixelRatio=null,this._currentSize=new pe,this._onSessionEvent=rB.bind(this),this._onSessionEnd=sB.bind(this),this._onInputSourcesChange=oB.bind(this),this._onAnimationFrame=lB.bind(this),this._referenceSpace=null,this._referenceSpaceType="local-floor",this._customReferenceSpace=null,this._framebufferScaleFactor=1,this._foveation=1,this._session=null,this._glBaseLayer=null,this._glBinding=null,this._glProjLayer=null,this._xrFrame=null,this._supportsLayers=this._supportsGlBinding&&"createProjectionLayer"in XRWebGLBinding.prototype,this._useMultiviewIfPossible=t,this._useMultiview=!1}getController(e){return this._getController(e).getTargetRaySpace()}getControllerGrip(e){return this._getController(e).getGripSpace()}getHand(e){return this._getController(e).getHandSpace()}getFoveation(){if(!(this._glProjLayer===null&&this._glBaseLayer===null))return this._foveation}setFoveation(e){this._foveation=e,this._glProjLayer!==null&&(this._glProjLayer.fixedFoveation=e),this._glBaseLayer!==null&&this._glBaseLayer.fixedFoveation!==void 0&&(this._glBaseLayer.fixedFoveation=e)}getFramebufferScaleFactor(){return this._framebufferScaleFactor}setFramebufferScaleFactor(e){this._framebufferScaleFactor=e,this.isPresenting===!0&&ae("XRManager: Cannot change framebuffer scale while presenting.")}getReferenceSpaceType(){return this._referenceSpaceType}setReferenceSpaceType(e){this._referenceSpaceType=e,this.isPresenting===!0&&ae("XRManager: Cannot change reference space type while presenting.")}getReferenceSpace(){return this._customReferenceSpace||this._referenceSpace}setReferenceSpace(e){this._customReferenceSpace=e}getCamera(){return this._cameraXR}getEnvironmentBlendMode(){if(this._session!==null)return this._session.environmentBlendMode}getBinding(){return this._glBinding===null&&this._supportsGlBinding&&(this._glBinding=new XRWebGLBinding(this._session,this._gl)),this._glBinding}getFrame(){return this._xrFrame}useMultiview(){return this._useMultiview}createQuadLayer(e,t,n,i,s,o,a,l={}){const c=new Oc(e,t),u=new Xl(s,o,{format:ln,type:Xt,depthTexture:new jn(s,o,l.stencil?di:Ct,void 0,void 0,void 0,void 0,void 0,void 0,l.stencil?qn:Dn),stencilBuffer:l.stencil,resolveDepthBuffer:!1,resolveStencilBuffer:!1});u._autoAllocateDepthBuffer=!0;const h=new pr({color:16777215,side:ri});h.map=u.texture,h.map.offset.y=1,h.map.repeat.y=-1;const d=new _n(c,h);d.position.copy(n),d.quaternion.copy(i);const f={type:"quad",width:e,height:t,translation:n,quaternion:i,pixelwidth:s,pixelheight:o,plane:d,material:h,rendercall:a,renderTarget:u};if(this._layers.push(f),this._session!==null){f.plane.material=new pr({color:16777215,side:ri}),f.plane.material.blending=co,f.plane.material.blendEquation=Xn,f.plane.material.blendSrc=Gr,f.plane.material.blendDst=Gr,f.xrlayer=this._createXRLayer(f);const p=this._session.renderState.layers;p.unshift(f.xrlayer),this._session.updateRenderState({layers:p})}else u.isXRRenderTarget=!1;return d}createCylinderLayer(e,t,n,i,s,o,a,l,c={}){const u=new Bc(e,e,e*t/n,64,64,!0,Math.PI-t/2,t),h=new Xl(o,a,{format:ln,type:Xt,depthTexture:new jn(o,a,c.stencil?di:Ct,void 0,void 0,void 0,void 0,void 0,void 0,c.stencil?qn:Dn),stencilBuffer:c.stencil,resolveDepthBuffer:!1,resolveStencilBuffer:!1});h._autoAllocateDepthBuffer=!0;const d=new pr({color:16777215,side:Lt});d.map=h.texture,d.map.offset.y=1,d.map.repeat.y=-1;const f=new _n(u,d);f.position.copy(i),f.quaternion.copy(s);const p={type:"cylinder",radius:e,centralAngle:t,aspectratio:n,translation:i,quaternion:s,pixelwidth:o,pixelheight:a,plane:f,material:d,rendercall:l,renderTarget:h};if(this._layers.push(p),this._session!==null){p.plane.material=new pr({color:16777215,side:Lt}),p.plane.material.blending=co,p.plane.material.blendEquation=Xn,p.plane.material.blendSrc=Gr,p.plane.material.blendDst=Gr,p.xrlayer=this._createXRLayer(p);const g=this._session.renderState.layers;g.unshift(p.xrlayer),this._session.updateRenderState({layers:g})}else h.isXRRenderTarget=!1;return f}renderLayers(){const e=new P,t=new Oi,n=this._renderer,i=this.isPresenting;this.isPresenting=!1;const s=new pe;n.getSize(s);const o=n.getRenderTarget();for(const a of this._layers){a.renderTarget.isXRRenderTarget=this._session!==null,a.renderTarget._hasExternalTextures=a.renderTarget.isXRRenderTarget;const l=n.contextNode;let c;if(a.renderTarget.isXRRenderTarget&&this._sessionUsesLayers){a.xrlayer.transform=new XRRigidTransform(a.plane.getWorldPosition(e),a.plane.getWorldQuaternion(t));const u=this._glBinding.getSubImage(a.xrlayer,this._xrFrame);n.backend.setXRRenderTargetTextures(a.renderTarget,u.colorTexture,void 0),n._setXRLayerSize(a.renderTarget.width,a.renderTarget.height),c=i0.get(l),c===void 0&&(c=l.context({getOutput:h=>Av(h,n.toneMapping,n.outputColorSpace)}),i0.set(l,c))}else c=l;n.contextNode=c,n.setRenderTarget(a.renderTarget),a.rendercall(),n.contextNode=l}n.setRenderTarget(o),n._setXRLayerSize(s.x,s.y),this.isPresenting=i}getSession(){return this._session}async setSession(e){const t=this._renderer,n=t.backend;this._gl=t.getContext();const i=this._gl,s=i.getContextAttributes();if(this._session=e,e!==null){if(n.isWebGPUBackend===!0)throw new Error('THREE.XRManager: XR is currently not supported with a WebGPU backend. Use WebGL by passing "{ forceWebGL: true }" to the constructor of the renderer.');if(e.addEventListener("select",this._onSessionEvent),e.addEventListener("selectstart",this._onSessionEvent),e.addEventListener("selectend",this._onSessionEvent),e.addEventListener("squeeze",this._onSessionEvent),e.addEventListener("squeezestart",this._onSessionEvent),e.addEventListener("squeezeend",this._onSessionEvent),e.addEventListener("end",this._onSessionEnd),e.addEventListener("inputsourceschange",this._onInputSourcesChange),await n.makeXRCompatible(),this._currentPixelRatio=t.getPixelRatio(),t.getSize(this._currentSize),this._currentAnimationContext=t._animation.getContext(),this._currentAnimationLoop=t._animation.getAnimationLoop(),t._animation.stop(),this._supportsLayers===!0){let o=null,a=null,l=null;t.depth&&(l=t.stencil?i.DEPTH24_STENCIL8:i.DEPTH_COMPONENT24,o=t.stencil?qn:Dn,a=t.stencil?di:Ct);const c={colorFormat:i.RGBA8,depthFormat:l,scaleFactor:this._framebufferScaleFactor,clearOnAccess:!1};this._useMultiviewIfPossible&&t.hasFeature("OVR_multiview2")&&(c.textureType="texture-array",this._useMultiview=!0),this._glBinding=this.getBinding();const u=this._glBinding.createProjectionLayer(c),h=[u];this._glProjLayer=u,t.setPixelRatio(1),t._setXRLayerSize(u.textureWidth,u.textureHeight);const d=this._useMultiview?2:1,f=new jn(u.textureWidth,u.textureHeight,a,void 0,void 0,void 0,void 0,void 0,void 0,o,d);if(this._xrRenderTarget=new Xl(u.textureWidth,u.textureHeight,{format:ln,type:Xt,colorSpace:t.outputColorSpace,depthTexture:f,stencilBuffer:t.stencil,samples:s.antialias?4:0,resolveDepthBuffer:u.ignoreDepthValues===!1,resolveStencilBuffer:u.ignoreDepthValues===!1,depth:this._useMultiview?2:1,multiview:this._useMultiview}),this._xrRenderTarget._hasExternalTextures=!0,this._xrRenderTarget.depth=this._useMultiview?2:1,this._sessionUsesLayers=e.enabledFeatures.includes("layers"),this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType()),this._sessionUsesLayers)for(const p of this._layers)p.plane.material=new pr({color:16777215,side:p.type==="cylinder"?Lt:ri}),p.plane.material.blending=co,p.plane.material.blendEquation=Xn,p.plane.material.blendSrc=Gr,p.plane.material.blendDst=Gr,p.xrlayer=this._createXRLayer(p),h.unshift(p.xrlayer);e.updateRenderState({layers:h})}else{const o={antialias:t.currentSamples>0,alpha:!0,depth:t.depth,stencil:t.stencil,framebufferScaleFactor:this.getFramebufferScaleFactor()},a=new XRWebGLLayer(e,i,o);this._glBaseLayer=a,e.updateRenderState({baseLayer:a}),t.setPixelRatio(1),t._setXRLayerSize(a.framebufferWidth,a.framebufferHeight),this._xrRenderTarget=new Xl(a.framebufferWidth,a.framebufferHeight,{format:ln,type:Xt,colorSpace:t.outputColorSpace,stencilBuffer:t.stencil,resolveDepthBuffer:a.ignoreDepthValues===!1,resolveStencilBuffer:a.ignoreDepthValues===!1}),this._xrRenderTarget._isOpaqueFramebuffer=!0,this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType())}this.setFoveation(this.getFoveation()),t._animation.setAnimationLoop(this._onAnimationFrame),t._animation.setContext(e),t._animation.start(),this.isPresenting=!0,this.dispatchEvent({type:"sessionstart"})}}updateCamera(e){const t=this._session;if(t===null)return;const n=e.near,i=e.far,s=this._cameraXR,o=this._cameraL,a=this._cameraR;s.near=a.near=o.near=n,s.far=a.far=o.far=i,s.isMultiViewCamera=this._useMultiview,(this._currentDepthNear!==s.near||this._currentDepthFar!==s.far)&&(t.updateRenderState({depthNear:s.near,depthFar:s.far}),this._currentDepthNear=s.near,this._currentDepthFar=s.far),s.layers.mask=e.layers.mask|6,o.layers.mask=s.layers.mask&-5,a.layers.mask=s.layers.mask&-3;const l=e.parent,c=s.cameras;r0(s,l);for(let u=0;u<c.length;u++)r0(c[u],l);c.length===2?nB(s,o,a):s.projectionMatrix.copy(o.projectionMatrix),iB(e,s,l)}_getController(e){let t=this._controllers[e];return t===void 0&&(t=new oh,this._controllers[e]=t),t}}function nB(r,e,t){t0.setFromMatrixPosition(e.matrixWorld),n0.setFromMatrixPosition(t.matrixWorld);const n=t0.distanceTo(n0),i=e.projectionMatrix.elements,s=t.projectionMatrix.elements,o=i[14]/(i[10]-1),a=i[14]/(i[10]+1),l=(i[9]+1)/i[5],c=(i[9]-1)/i[5],u=(i[8]-1)/i[0],h=(s[8]+1)/s[0],d=o*u,f=o*h,p=n/(-u+h),g=p*-u;if(e.matrixWorld.decompose(r.position,r.quaternion,r.scale),r.translateX(g),r.translateZ(p),r.matrixWorld.compose(r.position,r.quaternion,r.scale),r.matrixWorldInverse.copy(r.matrixWorld).invert(),i[10]===-1)r.projectionMatrix.copy(e.projectionMatrix),r.projectionMatrixInverse.copy(e.projectionMatrixInverse);else{const m=o+p,_=a+p,x=d-g,y=f+(n-g),b=l*a/_*m,M=c*a/_*m;r.projectionMatrix.makePerspective(x,y,b,M,m,_),r.projectionMatrixInverse.copy(r.projectionMatrix).invert()}}function r0(r,e){e===null?r.matrixWorld.copy(r.matrix):r.matrixWorld.multiplyMatrices(e.matrixWorld,r.matrix),r.matrixWorldInverse.copy(r.matrixWorld).invert()}function iB(r,e,t){t===null?r.matrix.copy(e.matrixWorld):(r.matrix.copy(t.matrixWorld),r.matrix.invert(),r.matrix.multiply(e.matrixWorld)),r.matrix.decompose(r.position,r.quaternion,r.scale),r.updateMatrixWorld(!0),r.projectionMatrix.copy(e.projectionMatrix),r.projectionMatrixInverse.copy(e.projectionMatrixInverse),r.isPerspectiveCamera&&(r.fov=xo*2*Math.atan(1/r.projectionMatrix.elements[5]),r.zoom=1)}function rB(r){const e=this._controllerInputSources.indexOf(r.inputSource);if(e===-1)return;const t=this._controllers[e];if(t!==void 0){const n=this.getReferenceSpace();t.update(r.inputSource,r.frame,n),t.dispatchEvent({type:r.type,data:r.inputSource})}}function sB(){const r=this._session,e=this._renderer;r.removeEventListener("select",this._onSessionEvent),r.removeEventListener("selectstart",this._onSessionEvent),r.removeEventListener("selectend",this._onSessionEvent),r.removeEventListener("squeeze",this._onSessionEvent),r.removeEventListener("squeezestart",this._onSessionEvent),r.removeEventListener("squeezeend",this._onSessionEvent),r.removeEventListener("end",this._onSessionEnd),r.removeEventListener("inputsourceschange",this._onInputSourcesChange);for(let t=0;t<this._controllers.length;t++){const n=this._controllerInputSources[t];n!==null&&(this._controllerInputSources[t]=null,this._controllers[t].disconnect(n))}if(this._currentDepthNear=null,this._currentDepthFar=null,e._resetXRState(),this._session=null,this._xrRenderTarget=null,this._glBinding=null,this._glBaseLayer=null,this._glProjLayer=null,this._sessionUsesLayers===!0)for(const t of this._layers)t.renderTarget=new Xl(t.pixelwidth,t.pixelheight,{format:ln,type:Xt,depthTexture:new jn(t.pixelwidth,t.pixelheight,t.stencilBuffer?di:Ct,void 0,void 0,void 0,void 0,void 0,void 0,t.stencilBuffer?qn:Dn),stencilBuffer:t.stencilBuffer,resolveDepthBuffer:!1,resolveStencilBuffer:!1}),t.renderTarget.isXRRenderTarget=!1,t.plane.material=t.material,t.material.map=t.renderTarget.texture,t.material.map.offset.y=1,t.material.map.repeat.y=-1,delete t.xrlayer;this.isPresenting=!1,this._useMultiview=!1,e._animation.stop(),e._animation.setAnimationLoop(this._currentAnimationLoop),e._animation.setContext(this._currentAnimationContext),e._animation.start(),e.setPixelRatio(this._currentPixelRatio),e.setSize(this._currentSize.width,this._currentSize.height,!1),this.dispatchEvent({type:"sessionend"})}function oB(r){const e=this._controllers,t=this._controllerInputSources;for(let n=0;n<r.removed.length;n++){const i=r.removed[n],s=t.indexOf(i);s>=0&&(t[s]=null,e[s].disconnect(i))}for(let n=0;n<r.added.length;n++){const i=r.added[n];let s=t.indexOf(i);if(s===-1){for(let a=0;a<e.length;a++)if(a>=t.length){t.push(i),s=a;break}else if(t[a]===null){t[a]=i,s=a;break}if(s===-1)break}const o=e[s];o&&o.connect(i)}}function aB(r){return r.type==="quad"?this._glBinding.createQuadLayer({transform:new XRRigidTransform(r.translation,r.quaternion),width:r.width/2,height:r.height/2,space:this._referenceSpace,viewPixelWidth:r.pixelwidth,viewPixelHeight:r.pixelheight,clearOnAccess:!1}):this._glBinding.createCylinderLayer({transform:new XRRigidTransform(r.translation,r.quaternion),radius:r.radius,centralAngle:r.centralAngle,aspectRatio:r.aspectRatio,space:this._referenceSpace,viewPixelWidth:r.pixelwidth,viewPixelHeight:r.pixelheight,clearOnAccess:!1})}function lB(r,e){if(e===void 0)return;const t=this._cameraXR,n=this._renderer,i=n.backend,s=this._glBaseLayer,o=this.getReferenceSpace(),a=e.getViewerPose(o);if(this._xrFrame=e,a!==null){const l=a.views;this._glBaseLayer!==null&&i.setXRTarget(s.framebuffer);let c=!1;l.length!==t.cameras.length&&(t.cameras.length=0,c=!0);for(let u=0;u<l.length;u++){const h=l[u];let d;if(this._supportsLayers===!0){const p=this._glBinding.getViewSubImage(this._glProjLayer,h);d=p.viewport,u===0&&i.setXRRenderTargetTextures(this._xrRenderTarget,p.colorTexture,this._glProjLayer.ignoreDepthValues&&!this._useMultiview?void 0:p.depthStencilTexture)}else d=s.getViewport(h);let f=this._cameras[u];f===void 0&&(f=new Cn,f.layers.enable(u),f.viewport=new rt,this._cameras[u]=f),f.matrix.fromArray(h.transform.matrix),f.matrix.decompose(f.position,f.quaternion,f.scale),f.projectionMatrix.fromArray(h.projectionMatrix),f.projectionMatrixInverse.copy(f.projectionMatrix).invert(),f.viewport.set(d.x,d.y,d.width,d.height),u===0&&(t.matrix.copy(f.matrix),t.matrix.decompose(t.position,t.quaternion,t.scale)),c===!0&&t.cameras.push(f)}n.setOutputRenderTarget(this._xrRenderTarget)}for(let l=0;l<this._controllers.length;l++){const c=this._controllerInputSources[l],u=this._controllers[l];c!==null&&u!==void 0&&u.update(c,e,o)}this._currentAnimationLoop&&this._currentAnimationLoop(r,e),e.detectedPlanes&&this.dispatchEvent({type:"planesdetected",data:e}),this._xrFrame=null}class cB extends Vi{constructor(e){super(),this.domElement=e,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new rt(0,0,this._width,this._height),this._scissor=new rt(0,0,this._width,this._height),this._scissorTest=!1,this.colorTexture=new ny,this.depthTexture=new jn}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,n){this.xr&&this.xr.isPresenting||(this._width=e,this._height=t,this._pixelRatio=n,this.domElement.width=Math.floor(e*n),this.domElement.height=Math.floor(t*n),this.setViewport(0,0,e,t),this._dispatchResize())}setSize(e,t,n=!0){this.xr&&this.xr.isPresenting||(this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),n===!0&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._dispatchResize())}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,n,i){const s=this._scissor;e.isVector4?s.copy(e):s.set(e,t,n,i)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,n,i,s=0,o=1){const a=this._viewport;e.isVector4?a.copy(e):a.set(e,t,n,i),a.minDepth=s,a.maxDepth=o}_dispatchResize(){this.dispatchEvent({type:"resize"})}dispose(){this.dispatchEvent({type:"dispose"})}}const s0=new hm,oa=new pe,If=new rt,Bf=new Ic,Of=new _m,Yu=new pt,Br=new rt,uB={[ri]:Lt,[Lt]:ri,[Nn]:Nn};class hB{constructor(e,t={}){this.isRenderer=!0;const{logarithmicDepthBuffer:n=!1,reversedDepthBuffer:i=!1,alpha:s=!0,depth:o=!0,stencil:a=!1,antialias:l=!1,samples:c=0,getFallback:u=null,outputBufferType:h=tn,multiview:d=!1}=t;this.backend=e,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=s,this.logarithmicDepthBuffer=n,this.reversedDepthBuffer=i,this.outputColorSpace=ei,this.toneMapping=Fn,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=o,this.stencil=a,this.info=new HF,this.contextNode=Po(),this.library=new Ub,this.lighting=new eB,this._samples=c||l===!0?4:0,this._onCanvasTargetResize=this._onCanvasTargetResize.bind(this),this._canvasTarget=new cB(e.getDomElement()),this._canvasTarget.addEventListener("resize",this._onCanvasTargetResize),this._canvasTarget.isDefaultCanvasTarget=!0,this._inspector=new wv,this._inspector.setRenderer(this),this._getFallback=u,this._attributes=null,this._geometries=null,this._nodes=null,this._animation=null,this._bindings=null,this._objects=null,this._pipelines=null,this._bundles=null,this._renderLists=null,this._renderContexts=null,this._textures=null,this._background=null,this._quadCache=new Map,this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTargets=new Map;const f=this.alpha===!0?0:1;this._clearColor=new jm(0,0,0,f),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._outputRenderTarget=null,this._mrt=null,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._isDeviceLost=!1,this.onDeviceLost=this._onDeviceLost,this._outputBufferType=h,this._cacheShadowNodes=new WeakMap,this._initialized=!1,this._callDepth=-1,this._initPromise=null,this._compilationPromises=null,this.transparent=!0,this.opaque=!0,this.shadowMap={enabled:!1,transmitted:!1,type:fa},this.xr=new tB(this,d),this.debug={checkShaderErrors:!0,onShaderError:null,getShaderAsync:async(p,g,m)=>{await this.compileAsync(p,g);const _=this._renderLists.get(p,g),x=this._renderContexts.get(this._renderTarget,this._mrt),y=p.overrideMaterial||m.material,b=this._objects.get(m,y,p,g,_.lightsNode,x,x.clippingContext),{fragmentShader:M,vertexShader:S}=b.getNodeBuilderState();return{fragmentShader:M,vertexShader:S}}}}async init(){return this._initPromise!==null?this._initPromise:(this._initPromise=new Promise(async(e,t)=>{let n=this.backend;try{await n.init(this)}catch(i){if(this._getFallback!==null)try{this.backend=n=this._getFallback(i),await n.init(this)}catch(s){t(s);return}else{t(i);return}}this._nodes=new K2(this,n),this._animation=new UF(this,this._nodes,this.info),this._attributes=new VF(n,this.info),this._background=new u2(this,this._nodes),this._geometries=new zF(this._attributes,this.info),this._textures=new nI(this,n,this.info),this._pipelines=new qF(n,this._nodes,this.info),this._bindings=new jF(n,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new OF(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new ZF(this.lighting),this._bundles=new Q2,this._renderContexts=new eI(this),this._animation.start(),this._initialized=!0,this._inspector.init(),e(this)}),this._initPromise)}get domElement(){return this._canvasTarget.domElement}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,n=null){if(this._isDeviceLost===!0)return;this._initialized===!1&&await this.init();const i=this._nodes.nodeFrame,s=i.renderId,o=this._currentRenderContext,a=this._currentRenderObjectFunction,l=this._handleObjectFunction,c=this._compilationPromises;n===null&&(n=e);const u=e.isScene===!0?e:n.isScene===!0?n:s0,d=this.needsFrameBufferTarget&&this._renderTarget===null?this._getFrameBufferTarget():this._renderTarget||this._outputRenderTarget,f=this._renderContexts.get(d,this._mrt),p=this._activeMipmapLevel,g=[];this._currentRenderContext=f,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=g,i.renderId++,i.update(),f.depth=this.depth,f.stencil=this.stencil,f.clippingContext||(f.clippingContext=new Nh),f.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,d);const m=this._renderLists.get(u,t);if(m.begin(),this._projectObject(e,t,0,m,f.clippingContext),n!==e&&n.traverseVisible(function(M){M.isLight&&M.layers.test(t.layers)&&m.pushLight(M)}),m.finish(),d!==null){this._textures.updateRenderTarget(d,p);const M=this._textures.get(d);f.textures=M.textures,f.depthTexture=M.depthTexture}else f.textures=null,f.depthTexture=null;n!==e?this._background.update(n,m,f):this._background.update(u,m,f);const _=m.opaque,x=m.transparent,y=m.transparentDoublePass,b=m.lightsNode;this.opaque===!0&&_.length>0&&this._renderObjects(_,t,u,b),this.transparent===!0&&x.length>0&&this._renderTransparents(x,y,t,u,b),i.renderId=s,this._currentRenderContext=o,this._currentRenderObjectFunction=a,this._handleObjectFunction=l,this._compilationPromises=c;for(const M of g){const S=this._objects.get(M.object,M.material,M.scene,M.camera,M.lightsNode,M.renderContext,M.clippingContext,M.passId);S.drawRange=M.object.geometry.drawRange,S.group=M.group,this._geometries.updateForRender(S),await this._nodes.getForRenderAsync(S),this._nodes.updateBefore(S),this._nodes.updateForRender(S),this._bindings.updateForRender(S);const E=[];this._pipelines.getForRender(S,E),E.length>0&&await Promise.all(E),this._nodes.updateAfter(S),await Q0()}}async renderAsync(e,t){Kt('Renderer: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.render(e,t)}async waitForGPU(){ce("Renderer: waitForGPU() has been removed. Read https://github.com/mrdoob/three.js/issues/32012 for more information.")}set inspector(e){this._inspector!==null&&this._inspector.setRenderer(null),this._inspector=e,this._inspector.setRenderer(this)}get inspector(){return this._inspector}set highPrecision(e){const t=this.contextNode.value;e===!0?(t.modelViewMatrix=sx,t.modelNormalViewMatrix=ox):this.highPrecision&&(delete t.modelViewMatrix,delete t.modelNormalViewMatrix)}get highPrecision(){const e=this.contextNode.value;return e.modelViewMatrix===sx&&e.modelNormalViewMatrix===ox}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getOutputBufferType(){return this._outputBufferType}getColorBufferType(){return Kt('Renderer: ".getColorBufferType()" has been renamed to ".getOutputBufferType()".'),this.getOutputBufferType()}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:
4658
4658
 
4659
4659
  Message: ${e.message}`;e.reason&&(t+=`
4660
4660
  Reason: ${e.reason}`),ce(t),this._isDeviceLost=!0}_renderBundle(e,t,n){const{bundleGroup:i,camera:s,renderList:o}=e,a=this._currentRenderContext,l=this._bundles.get(i,s,a),c=this.backend.get(l),u=i.version!==c.version;if(u||c.bundleGPU===void 0){this.backend.beginBundle(a),(c.renderObjects===void 0||u)&&(c.renderObjects=[]),this._currentRenderBundle=l;const{transparentDoublePass:d,transparent:f,opaque:p}=o;this.opaque===!0&&p.length>0&&this._renderObjects(p,s,t,n),this.transparent===!0&&f.length>0&&this._renderTransparents(f,d,s,t,n),this._currentRenderBundle=null,this.backend.finishBundle(a,l),c.version=i.version}else{const{renderObjects:d}=c;for(let f=0,p=d.length;f<p;f++){const g=d[f];this._nodes.needsRefresh(g)&&(this._nodes.updateBefore(g),this._nodes.updateForRender(g),this._bindings.updateForRender(g),this._nodes.updateAfter(g))}}this.backend.addBundle(a,l)}render(e,t){if(this._initialized===!1)throw new Error('Renderer: .render() called before the backend is initialized. Use "await renderer.init();" before rendering.');this._renderScene(e,t)}get initialized(){return this._initialized}_getFrameBufferTarget(){const{currentToneMapping:e,currentColorSpace:t}=this,n=e!==Fn,i=t!==Ye.workingColorSpace;if(n===!1&&i===!1)return null;const{width:s,height:o}=this.getDrawingBufferSize(oa),{depth:a,stencil:l}=this,c=this._outputRenderTarget||this._canvasTarget;let u=this._frameBufferTargets.get(c);if(u===void 0){u=new ks(s,o,{depthBuffer:a,stencilBuffer:l,type:this._outputBufferType,format:ln,colorSpace:Ye.workingColorSpace,generateMipmaps:!1,minFilter:Nt,magFilter:Nt,samples:this.samples}),u.isPostProcessingRenderTarget=!0;const m=()=>{c.removeEventListener("dispose",m),u.dispose(),this._frameBufferTargets.delete(c)};c.addEventListener("dispose",m),this._frameBufferTargets.set(c,u)}const h=this.getOutputRenderTarget();u.depthBuffer=a,u.stencilBuffer=l,h!==null?u.setSize(h.width,h.height,h.depth):u.setSize(s,o,1);const d=this._outputRenderTarget?this._outputRenderTarget.viewport:c._viewport,f=this._outputRenderTarget?this._outputRenderTarget.scissor:c._scissor,p=this._outputRenderTarget?1:c._pixelRatio,g=this._outputRenderTarget?this._outputRenderTarget.scissorTest:c._scissorTest;return u.viewport.copy(d),u.scissor.copy(f),u.viewport.multiplyScalar(p),u.scissor.multiplyScalar(p),u.scissorTest=g,u.multiview=h!==null?h.multiview:!1,u.resolveDepthBuffer=h!==null?h.resolveDepthBuffer:!0,u._autoAllocateDepthBuffer=h!==null?h._autoAllocateDepthBuffer:!1,u}_renderScene(e,t,n=!0){if(this._isDeviceLost===!0)return;const i=n?this._getFrameBufferTarget():null,s=this._nodes.nodeFrame,o=s.renderId,a=this._currentRenderContext,l=this._currentRenderObjectFunction,c=this._handleObjectFunction;this._callDepth++;const u=e.isScene===!0?e:s0,h=this._renderTarget||this._outputRenderTarget,d=this._activeCubeFace,f=this._activeMipmapLevel;let p;if(i!==null?(p=i,this.setRenderTarget(p)):p=h,p!==null&&p.depthBuffer===!0){const z=this._textures.get(p);z.depthInitialized!==!0&&((this.autoClear===!1||this.autoClear===!0&&this.autoClearDepth===!1)&&this.clearDepth(),z.depthInitialized=!0)}const g=this._renderContexts.get(p,this._mrt,this._callDepth);this._currentRenderContext=g,this._currentRenderObjectFunction=this._renderObjectFunction||this.renderObject,this._handleObjectFunction=this._renderObjectDirect,this.info.calls++,this.info.render.calls++,this.info.render.frameCalls++,s.renderId=this.info.calls,this.backend.updateTimeStampUID(g),this.inspector.beginRender(this.backend.getTimestampUID(g),e,t,p);const m=this.xr;if(m.isPresenting===!1){let z=!1;if(this.reversedDepthBuffer===!0&&t.reversedDepth!==!0){if(t._reversedDepth=!0,t.isArrayCamera)for(const B of t.cameras)B._reversedDepth=!0;z=!0}const U=this.coordinateSystem;if(t.coordinateSystem!==U){if(t.coordinateSystem=U,t.isArrayCamera)for(const B of t.cameras)B.coordinateSystem=U;z=!0}if(z===!0&&(t.updateProjectionMatrix(),t.isArrayCamera))for(const B of t.cameras)B.updateProjectionMatrix()}e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t.parent===null&&t.matrixWorldAutoUpdate===!0&&t.updateMatrixWorld(),m.enabled===!0&&m.isPresenting===!0&&(m.cameraAutoUpdate===!0&&m.updateCamera(t),t=m.getCamera());const _=this._canvasTarget;let x=_._viewport,y=_._scissor,b=_._pixelRatio;p!==null&&(x=p.viewport,y=p.scissor,b=1),this.getDrawingBufferSize(oa),If.set(0,0,oa.width,oa.height);const M=x.minDepth===void 0?0:x.minDepth,S=x.maxDepth===void 0?1:x.maxDepth;g.viewportValue.copy(x).multiplyScalar(b).floor(),g.viewportValue.width>>=f,g.viewportValue.height>>=f,g.viewportValue.minDepth=M,g.viewportValue.maxDepth=S,g.viewport=g.viewportValue.equals(If)===!1,g.scissorValue.copy(y).multiplyScalar(b).floor(),g.scissor=_._scissorTest&&g.scissorValue.equals(If)===!1,g.scissorValue.width>>=f,g.scissorValue.height>>=f,g.clippingContext||(g.clippingContext=new Nh),g.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,p);const E=t.isArrayCamera?Of:Bf;t.isArrayCamera||(Yu.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),E.setFromProjectionMatrix(Yu,t.coordinateSystem,t.reversedDepth));const v=this._renderLists.get(e,t);if(v.begin(),this._projectObject(e,t,0,v,g.clippingContext),v.finish(),this.sortObjects===!0&&v.sort(this._opaqueSort,this._transparentSort),p!==null){this._textures.updateRenderTarget(p,f);const z=this._textures.get(p);g.textures=z.textures,g.depthTexture=z.depthTexture,g.width=z.width,g.height=z.height,g.renderTarget=p,g.depth=p.depthBuffer,g.stencil=p.stencilBuffer}else g.textures=null,g.depthTexture=null,g.width=oa.width,g.height=oa.height,g.depth=this.depth,g.stencil=this.stencil;g.width>>=f,g.height>>=f,g.activeCubeFace=d,g.activeMipmapLevel=f,g.occlusionQueryCount=v.occlusionQueryCount,g.scissorValue.max(Br.set(0,0,0,0)),g.scissorValue.x+g.scissorValue.width>g.width&&(g.scissorValue.width=Math.max(g.width-g.scissorValue.x,0)),g.scissorValue.y+g.scissorValue.height>g.height&&(g.scissorValue.height=Math.max(g.height-g.scissorValue.y,0)),this._background.update(u,v,g),g.camera=t,this.backend.beginRender(g);const{bundles:w,lightsNode:N,transparentDoublePass:C,transparent:F,opaque:V}=v;return w.length>0&&this._renderBundles(w,u,N),this.opaque===!0&&V.length>0&&this._renderObjects(V,t,u,N),this.transparent===!0&&F.length>0&&this._renderTransparents(F,C,t,u,N),this.backend.finishRender(g),s.renderId=o,this._currentRenderContext=a,this._currentRenderObjectFunction=l,this._handleObjectFunction=c,this._callDepth--,i!==null&&(this.setRenderTarget(h,d,f),this._renderOutput(p)),u.onAfterRender(this,e,t,p),this.inspector.finishRender(this.backend.getTimestampUID(g)),g}_setXRLayerSize(e,t){this._canvasTarget._width=e,this._canvasTarget._height=t,this.setViewport(0,0,e,t)}_renderOutput(e){const t=this._nodes.getOutputCacheKey();let n=this._quadCache.get(e.texture),i;if(n===void 0){i=new Sb(new mn),i.name="Output Color Transform",i.material.name="outputColorTransform",i.material.fragmentNode=this._nodes.getOutputNode(e.texture),n={quad:i,cacheKey:t},this._quadCache.set(e.texture,n);const a=()=>{i.material.dispose(),this._quadCache.delete(e.texture),e.texture.removeEventListener("dispose",a)};e.texture.addEventListener("dispose",a)}else i=n.quad,n.cacheKey!==t&&(i.material.fragmentNode=this._nodes.getOutputNode(e.texture),i.material.needsUpdate=!0,n.cacheKey=t);const s=this.autoClear,o=this.xr.enabled;this.autoClear=!1,this.xr.enabled=!1,this._renderScene(i,i.camera,!1),this.autoClear=s,this.xr.enabled=o}getMaxAnisotropy(){return this.backend.capabilities.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){this._initialized===!1&&await this.init(),this._animation.setAnimationLoop(e)}getAnimationLoop(){return this._animation.getAnimationLoop()}async getArrayBufferAsync(e,t=null,n=0,i=-1){if(t!==null&&t.isReadbackBuffer&&this.info.memoryMap.has(t)===!1){this.info.createReadbackBuffer(t);const s=()=>{t.removeEventListener("dispose",s),this.info.destroyReadbackBuffer(t)};t.addEventListener("dispose",s)}if(n%4!==0||i>0&&i%4!==0)throw new Error('THREE.Renderer: "getArrayBufferAsync()" offset and count must be a multiple of 4.');return await this.backend.getArrayBufferAsync(e,t,n,i)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._canvasTarget.getPixelRatio()}getDrawingBufferSize(e){return this._canvasTarget.getDrawingBufferSize(e)}getSize(e){return this._canvasTarget.getSize(e)}setPixelRatio(e=1){this._canvasTarget.setPixelRatio(e)}setDrawingBufferSize(e,t,n){this.xr&&this.xr.isPresenting||this._canvasTarget.setDrawingBufferSize(e,t,n)}setSize(e,t,n=!0){this.xr&&this.xr.isPresenting||this._canvasTarget.setSize(e,t,n)}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){return this._canvasTarget.getScissor(e)}setScissor(e,t,n,i){this._canvasTarget.setScissor(e,t,n,i)}getScissorTest(){return this._canvasTarget.getScissorTest()}setScissorTest(e){this._canvasTarget.setScissorTest(e),this.backend.setScissorTest(e)}getViewport(e){return this._canvasTarget.getViewport(e)}setViewport(e,t,n,i,s=0,o=1){this._canvasTarget.setViewport(e,t,n,i,s,o)}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this.reversedDepthBuffer===!0?1-this._clearDepth:this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,n=!0){if(this._initialized===!1)throw new Error('Renderer: .clear() called before the backend is initialized. Use "await renderer.init();" before before using this method.');const i=this._renderTarget||this._getFrameBufferTarget();let s=null;if(i!==null){this._textures.updateRenderTarget(i);const o=this._textures.get(i);s=this._renderContexts.get(i,null,-1),s.textures=o.textures,s.depthTexture=o.depthTexture,s.width=o.width,s.height=o.height,s.renderTarget=i,s.depth=i.depthBuffer,s.stencil=i.stencilBuffer;const a=this.backend.getClearColor();s.clearColorValue.r=a.r,s.clearColorValue.g=a.g,s.clearColorValue.b=a.b,s.clearColorValue.a=a.a,s.clearDepthValue=this.getClearDepth(),s.clearStencilValue=this.getClearStencil(),s.activeCubeFace=this.getActiveCubeFace(),s.activeMipmapLevel=this.getActiveMipmapLevel(),i.depthBuffer===!0&&(o.depthInitialized=!0)}this.backend.clear(e,t,n,s),i!==null&&this._renderTarget===null&&this._renderOutput(i)}clearColor(){this.clear(!0,!1,!1)}clearDepth(){this.clear(!1,!0,!1)}clearStencil(){this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,n=!0){Kt('Renderer: "clearAsync()" has been deprecated. Use "clear()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.clear(e,t,n)}async clearColorAsync(){Kt('Renderer: "clearColorAsync()" has been deprecated. Use "clearColor()" and "await renderer.init();" when creating the renderer.'),this.clear(!0,!1,!1)}async clearDepthAsync(){Kt('Renderer: "clearDepthAsync()" has been deprecated. Use "clearDepth()" and "await renderer.init();" when creating the renderer.'),this.clear(!1,!0,!1)}async clearStencilAsync(){Kt('Renderer: "clearStencilAsync()" has been deprecated. Use "clearStencil()" and "await renderer.init();" when creating the renderer.'),this.clear(!1,!1,!0)}get needsFrameBufferTarget(){const e=this.currentToneMapping!==Fn,t=this.currentColorSpace!==Ye.workingColorSpace;return e||t}get samples(){return this._samples}get currentSamples(){let e=this._samples;return this._renderTarget!==null?e=this._renderTarget.samples:this.needsFrameBufferTarget&&(e=0),e}get currentToneMapping(){return this.isOutputTarget?this.toneMapping:Fn}get currentColorSpace(){return this.isOutputTarget?this.outputColorSpace:Ye.workingColorSpace}get isOutputTarget(){return this._renderTarget===this._outputRenderTarget||this._renderTarget===null}dispose(){if(this._initialized===!0){this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._geometries.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose();for(const e of this._frameBufferTargets.keys())e.dispose();Object.values(this.backend.timestampQueryPool).forEach(e=>{e!==null&&e.dispose()})}this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,n=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=n}getRenderTarget(){return this._renderTarget}setOutputRenderTarget(e){this._outputRenderTarget=e}getOutputRenderTarget(){return this._outputRenderTarget}setCanvasTarget(e){this._canvasTarget.removeEventListener("resize",this._onCanvasTargetResize),this._canvasTarget=e,this._canvasTarget.addEventListener("resize",this._onCanvasTargetResize)}getCanvasTarget(){return this._canvasTarget}_resetXRState(){this.backend.setXRTarget(null),this.setOutputRenderTarget(null),this.setRenderTarget(null);for(const e of this._frameBufferTargets.keys())e.dispose()}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e,t=null){if(this._isDeviceLost===!0)return;if(this._initialized===!1)return ae("Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e,t);const n=this._nodes.nodeFrame,i=n.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,n.renderId=this.info.calls,this.backend.updateTimeStampUID(e),this.inspector.beginCompute(this.backend.getTimestampUID(e),e);const s=this.backend,o=this._pipelines,a=this._bindings,l=this._nodes,c=Array.isArray(e)?e:[e];if(c[0]===void 0||c[0].isComputeNode!==!0)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");s.beginCompute(e);for(const u of c){if(o.has(u)===!1){const f=()=>{u.removeEventListener("dispose",f),o.delete(u),a.deleteForCompute(u),l.delete(u)};u.addEventListener("dispose",f);const p=u.onInitFunction;p!==null&&p.call(u,{renderer:this})}l.updateForCompute(u),a.updateForCompute(u);const h=a.getForCompute(u),d=o.getForCompute(u,h);s.compute(e,u,h,d,t)}s.finishCompute(e),n.renderId=i,this.inspector.finishCompute(this.backend.getTimestampUID(e))}async computeAsync(e,t=null){this._initialized===!1&&await this.init(),this.compute(e,t)}async hasFeatureAsync(e){return Kt('Renderer: "hasFeatureAsync()" has been deprecated. Use "hasFeature()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.hasFeature(e)}async resolveTimestampsAsync(e="render"){return this._initialized===!1&&await this.init(),this.backend.resolveTimestampsAsync(e)}hasFeature(e){if(this._initialized===!1)throw new Error('Renderer: .hasFeature() called before the backend is initialized. Use "await renderer.init();" before before using this method.');return this.backend.hasFeature(e)}hasInitialized(){return this._initialized}async initTextureAsync(e){Kt('Renderer: "initTextureAsync()" has been deprecated. Use "initTexture()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.initTexture(e)}initTexture(e){if(this._initialized===!1)throw new Error('Renderer: .initTexture() called before the backend is initialized. Use "await renderer.init();" before before using this method.');this._textures.updateTexture(e)}initRenderTarget(e){if(this._initialized===!1)throw new Error('Renderer: .initRenderTarget() called before the backend is initialized. Use "await renderer.init();" before before using this method.');this._textures.updateRenderTarget(e);const t=this._textures.get(e),n=this._renderContexts.get(e);n.textures=t.textures,n.depthTexture=t.depthTexture,n.width=t.width,n.height=t.height,n.renderTarget=e,n.depth=e.depthBuffer,n.stencil=e.stencilBuffer,this.backend.initRenderTarget(n)}copyFramebufferToTexture(e,t=null){if(t!==null)if(t.isVector2)t=Br.set(t.x,t.y,e.image.width,e.image.height).floor();else if(t.isVector4)t=Br.copy(t).floor();else{ce("Renderer.copyFramebufferToTexture: Invalid rectangle.");return}else t=Br.set(0,0,e.image.width,e.image.height);let n=this._currentRenderContext,i;n!==null?i=n.renderTarget:(i=this._renderTarget||this._getFrameBufferTarget(),i!==null&&(this._textures.updateRenderTarget(i),n=this._textures.get(i))),this._textures.updateTexture(e,{renderTarget:i}),this.backend.copyFramebufferToTexture(e,n,t),this._inspector.copyFramebufferToTexture(e)}copyTextureToTexture(e,t,n=null,i=null,s=0,o=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,n,i,s,o),this._inspector.copyTextureToTexture(e,t)}async readRenderTargetPixelsAsync(e,t,n,i,s,o=0,a=0){return this.backend.copyTextureToBuffer(e.textures[o],t,n,i,s,a)}_projectObject(e,t,n,i,s){if(e.visible===!1)return;if(e.layers.test(t.layers)){if(e.isGroup)n=e.renderOrder,e.isClippingGroup&&e.enabled&&(s=s.getGroupContext(e));else if(e.isLOD)e.autoUpdate===!0&&e.update(t);else if(e.isLight)i.pushLight(e);else if(e.isSprite){const l=t.isArrayCamera?Of:Bf;if(!e.frustumCulled||l.intersectsSprite(e,t)){this.sortObjects===!0&&Br.setFromMatrixPosition(e.matrixWorld).applyMatrix4(Yu);const{geometry:c,material:u}=e;u.visible&&i.push(e,c,u,n,Br.z,null,s)}}else if(e.isLineLoop)ce("Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if(e.isMesh||e.isLine||e.isPoints){const l=t.isArrayCamera?Of:Bf;if(!e.frustumCulled||l.intersectsObject(e,t)){const{geometry:c,material:u}=e;if(this.sortObjects===!0&&(c.boundingSphere===null&&c.computeBoundingSphere(),Br.copy(c.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(Yu)),Array.isArray(u)){const h=c.groups;for(let d=0,f=h.length;d<f;d++){const p=h[d],g=u[p.materialIndex];g&&g.visible&&i.push(e,c,g,n,Br.z,p,s)}}else u.visible&&i.push(e,c,u,n,Br.z,null,s)}}}if(e.isBundleGroup===!0&&this.backend.beginBundle!==void 0){const l=i;i=this._renderLists.get(e,t),i.begin(),l.pushBundle({bundleGroup:e,camera:t,renderList:i}),i.finish()}const a=e.children;for(let l=0,c=a.length;l<c;l++)this._projectObject(a[l],t,n,i,s)}_renderBundles(e,t,n){for(const i of e)this._renderBundle(i,t,n)}_renderTransparents(e,t,n,i,s){if(t.length>0){for(const{material:o}of t)o.side=Lt;this._renderObjects(t,n,i,s,"backSide");for(const{material:o}of t)o.side=ri;this._renderObjects(e,n,i,s);for(const{material:o}of t)o.side=Nn}else this._renderObjects(e,n,i,s)}_renderObjects(e,t,n,i,s=null){for(let o=0,a=e.length;o<a;o++){const{object:l,geometry:c,material:u,group:h,clippingContext:d}=e[o];this._currentRenderObjectFunction(l,n,t,c,u,h,i,d,s)}}_getShadowNodes(e){const t=e.version;let n=this._cacheShadowNodes.get(e);if(n===void 0||n.version!==t){const i=e.map!==null,s=e.colorNode&&e.colorNode.isNode,o=e.castShadowNode&&e.castShadowNode.isNode,a=e.maskShadowNode&&e.maskShadowNode.isNode||e.maskNode&&e.maskNode.isNode;let l=null,c=null,u=null;if(i||s||o||a){let h,d;if(o?(h=e.castShadowNode.rgb,d=e.castShadowNode.a,this.shadowMap.transmitted!==!0&&Kt("Renderer: `shadowMap.transmitted` needs to be set to `true` when using `material.castShadowNode`.")):(h=te(0),d=J(1)),i&&(d=d.mul(Jt("map","texture",e).a)),s&&(d=d.mul(e.colorNode.a)),c=et(h,d),a){const f=e.maskShadowNode||e.maskNode;c=re(([p])=>(f.not().discard(),p))(c)}}e.depthNode&&e.depthNode.isNode&&(u=e.depthNode),e.castShadowPositionNode&&e.castShadowPositionNode.isNode?l=e.castShadowPositionNode:e.positionNode&&e.positionNode.isNode&&(l=e.positionNode),n={version:t,colorNode:c,depthNode:u,positionNode:l},this._cacheShadowNodes.set(e,n)}return n}renderObject(e,t,n,i,s,o,a,l=null,c=null){let u=!1,h,d,f,p;if(e.onBeforeRender(this,t,n,i,s,o),s.allowOverride===!0&&t.overrideMaterial!==null){const g=t.overrideMaterial;if(u=!0,h=g.isNodeMaterial?g.colorNode:null,d=g.isNodeMaterial?g.depthNode:null,f=g.isNodeMaterial?g.positionNode:null,p=t.overrideMaterial.side,s.positionNode&&s.positionNode.isNode&&(g.positionNode=s.positionNode),g.alphaTest=s.alphaTest,g.alphaMap=s.alphaMap,g.transparent=s.transparent||s.transmission>0||s.transmissionNode&&s.transmissionNode.isNode||s.backdropNode&&s.backdropNode.isNode,g.isShadowPassMaterial){const{colorNode:m,depthNode:_,positionNode:x}=this._getShadowNodes(s);this.shadowMap.type===_r?g.side=s.shadowSide!==null?s.shadowSide:s.side:g.side=s.shadowSide!==null?s.shadowSide:uB[s.side],m!==null&&(g.colorNode=m),_!==null&&(g.depthNode=_),x!==null&&(g.positionNode=x)}s=g}s.transparent===!0&&s.side===Nn&&s.forceSinglePass===!1?(s.side=Lt,this._handleObjectFunction(e,s,t,n,a,o,l,"backSide"),s.side=ri,this._handleObjectFunction(e,s,t,n,a,o,l,c),s.side=Nn):this._handleObjectFunction(e,s,t,n,a,o,l,c),u&&(t.overrideMaterial.colorNode=h,t.overrideMaterial.depthNode=d,t.overrideMaterial.positionNode=f,t.overrideMaterial.side=p),e.onAfterRender(this,t,n,i,s,o)}hasCompatibility(e){if(this._initialized===!1)throw new Error('Renderer: .hasCompatibility() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this.backend.hasCompatibility(e)}_renderObjectDirect(e,t,n,i,s,o,a,l){const c=this._objects.get(e,t,n,i,s,this._currentRenderContext,a,l);c.drawRange=e.geometry.drawRange,c.group=o,this._currentRenderBundle!==null&&(this.backend.get(this._currentRenderBundle).renderObjects.push(c),c.bundle=this._currentRenderBundle.bundleGroup);const u=this._nodes.needsRefresh(c);u&&(this._nodes.updateBefore(c),this._geometries.updateForRender(c),this._nodes.updateForRender(c),this._bindings.updateForRender(c)),this._pipelines.updateForRender(c),this._pipelines.isReady(c)&&(this.backend.draw(c,this.info),u&&this._nodes.updateAfter(c))}_createObjectPipeline(e,t,n,i,s,o,a,l){if(this._compilationPromises!==null){this._compilationPromises.push({object:e,material:t,scene:n,camera:i,lightsNode:s,group:o,clippingContext:a,passId:l,renderContext:this._currentRenderContext});return}const c=this._objects.get(e,t,n,i,s,this._currentRenderContext,a,l);c.drawRange=e.geometry.drawRange,c.group=o,this._nodes.updateBefore(c),this._geometries.updateForRender(c),this._nodes.updateForRender(c),this._bindings.updateForRender(c),this._pipelines.getForRender(c,this._compilationPromises),this._nodes.updateAfter(c)}_onCanvasTargetResize(){this._initialized&&this.backend.updateSize()}get compile(){return this.compileAsync}}class Fb{constructor(e=""){this.name=e,this.visibility=0}setVisibility(e){this.visibility|=e}getVisibility(){return this.visibility}clone(){return Object.assign(new this.constructor,this)}}function dB(r){return r+(gs-r%gs)%gs}class Ib extends Fb{constructor(e,t=null){super(e),this.isBuffer=!0,this.bytesPerElement=Float32Array.BYTES_PER_ELEMENT,this._buffer=t,this._updateRanges=[]}get updateRanges(){return this._updateRanges}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}get byteLength(){return dB(this._buffer.byteLength)}get buffer(){return this._buffer}update(){return!0}}class Bb extends Ib{constructor(e,t=null){super(e,t),this.isUniformBuffer=!0}}let fB=0;class Ob extends Bb{constructor(e,t){super("UniformBuffer_"+fB++,e?e.value:null),this.nodeUniform=e,this.groupNode=t,this.isNodeUniformBuffer=!0}set updateRanges(e){this.nodeUniform.updateRanges=e}get updateRanges(){return this.nodeUniform.updateRanges}addUpdateRange(e,t){this.nodeUniform.addUpdateRange(e,t)}clearUpdateRanges(){this.nodeUniform.clearUpdateRanges()}get buffer(){return this.nodeUniform.value}}class pB extends Bb{constructor(e){super(e),this.isUniformsGroup=!0,this._values=null,this.uniforms=[],this._updateRangeCache=new Map}addUniformUpdateRange(e){const t=e.index;if(this._updateRangeCache.has(t)!==!0){const n=this.updateRanges,i=e.offset,s=e.itemSize,o={start:i,count:s};n.push(o),this._updateRangeCache.set(t,o)}}clearUpdateRanges(){this._updateRangeCache.clear(),super.clearUpdateRanges()}addUniform(e){return this.uniforms.push(e),this}removeUniform(e){const t=this.uniforms.indexOf(e);return t!==-1&&this.uniforms.splice(t,1),this}get values(){return this._values===null&&(this._values=Array.from(this.buffer)),this._values}get buffer(){let e=this._buffer;if(e===null){const t=this.byteLength;e=new Float32Array(new ArrayBuffer(t)),this._buffer=e}return e}get byteLength(){const e=this.bytesPerElement;let t=0;for(let n=0,i=this.uniforms.length;n<i;n++){const s=this.uniforms[n],o=s.boundary,a=s.itemSize*e,l=t%gs,c=l%o,u=l+c;t+=c,u!==0&&gs-u<a&&(t+=gs-u),s.offset=t/e,s.index=n,t+=a}return Math.ceil(t/gs)*gs}update(){let e=!1;for(const t of this.uniforms)this.updateByType(t)===!0&&(e=!0);return e}updateByType(e){if(e.isNumberUniform)return this.updateNumber(e);if(e.isVector2Uniform)return this.updateVector2(e);if(e.isVector3Uniform)return this.updateVector3(e);if(e.isVector4Uniform)return this.updateVector4(e);if(e.isColorUniform)return this.updateColor(e);if(e.isMatrix3Uniform)return this.updateMatrix3(e);if(e.isMatrix4Uniform)return this.updateMatrix4(e);ce("WebGPUUniformsGroup: Unsupported uniform type.",e)}updateNumber(e){let t=!1;const n=this.values,i=e.getValue(),s=e.offset,o=e.getType();if(n[s]!==i){const a=this._getBufferForType(o);a[s]=n[s]=i,t=!0,this.addUniformUpdateRange(e)}return t}updateVector2(e){let t=!1;const n=this.values,i=e.getValue(),s=e.offset,o=e.getType();if(n[s+0]!==i.x||n[s+1]!==i.y){const a=this._getBufferForType(o);a[s+0]=n[s+0]=i.x,a[s+1]=n[s+1]=i.y,t=!0,this.addUniformUpdateRange(e)}return t}updateVector3(e){let t=!1;const n=this.values,i=e.getValue(),s=e.offset,o=e.getType();if(n[s+0]!==i.x||n[s+1]!==i.y||n[s+2]!==i.z){const a=this._getBufferForType(o);a[s+0]=n[s+0]=i.x,a[s+1]=n[s+1]=i.y,a[s+2]=n[s+2]=i.z,t=!0,this.addUniformUpdateRange(e)}return t}updateVector4(e){let t=!1;const n=this.values,i=e.getValue(),s=e.offset,o=e.getType();if(n[s+0]!==i.x||n[s+1]!==i.y||n[s+2]!==i.z||n[s+3]!==i.w){const a=this._getBufferForType(o);a[s+0]=n[s+0]=i.x,a[s+1]=n[s+1]=i.y,a[s+2]=n[s+2]=i.z,a[s+3]=n[s+3]=i.w,t=!0,this.addUniformUpdateRange(e)}return t}updateColor(e){let t=!1;const n=this.values,i=e.getValue(),s=e.offset;if(n[s+0]!==i.r||n[s+1]!==i.g||n[s+2]!==i.b){const o=this.buffer;o[s+0]=n[s+0]=i.r,o[s+1]=n[s+1]=i.g,o[s+2]=n[s+2]=i.b,t=!0,this.addUniformUpdateRange(e)}return t}updateMatrix3(e){let t=!1;const n=this.values,i=e.getValue().elements,s=e.offset;if(n[s+0]!==i[0]||n[s+1]!==i[1]||n[s+2]!==i[2]||n[s+4]!==i[3]||n[s+5]!==i[4]||n[s+6]!==i[5]||n[s+8]!==i[6]||n[s+9]!==i[7]||n[s+10]!==i[8]){const o=this.buffer;o[s+0]=n[s+0]=i[0],o[s+1]=n[s+1]=i[1],o[s+2]=n[s+2]=i[2],o[s+4]=n[s+4]=i[3],o[s+5]=n[s+5]=i[4],o[s+6]=n[s+6]=i[5],o[s+8]=n[s+8]=i[6],o[s+9]=n[s+9]=i[7],o[s+10]=n[s+10]=i[8],t=!0,this.addUniformUpdateRange(e)}return t}updateMatrix4(e){let t=!1;const n=this.values,i=e.getValue().elements,s=e.offset;return gB(n,i,s)===!1&&(this.buffer.set(i,s),mB(n,i,s),t=!0,this.addUniformUpdateRange(e)),t}_getBufferForType(e){return e==="int"||e==="ivec2"||e==="ivec3"||e==="ivec4"?new Int32Array(this.buffer.buffer):e==="uint"||e==="uvec2"||e==="uvec3"||e==="uvec4"?new Uint32Array(this.buffer.buffer):this.buffer}}function mB(r,e,t){for(let n=0,i=e.length;n<i;n++)r[t+n]=e[n]}function gB(r,e,t){for(let n=0,i=e.length;n<i;n++)if(r[t+n]!==e[n])return!1;return!0}let _B=0;class kb extends pB{constructor(e,t){super(e),this.id=_B++,this.groupNode=t,this.isNodeUniformsGroup=!0}}class Gb extends Fb{constructor(e,t){super(e),this._texture=null,this._onTextureDispose=()=>{this.generation=null,this.version=-1},this.texture=t,this.version=t?t.version:-1,this.generation=null,this.samplerKey="",this.isSampler=!0}set texture(e){this._texture!==e&&(this._texture&&this._texture.removeEventListener("dispose",this._onTextureDispose),this._texture=e,this.generation=null,this.version=-1,this._texture&&this._texture.addEventListener("dispose",this._onTextureDispose))}get texture(){return this._texture}update(){const{texture:e,version:t}=this;return t!==e.version?(this.version=e.version,!0):!1}clone(){const e=super.clone();return e._texture=null,e._onTextureDispose=()=>{e.generation=null,e.version=-1},e.texture=this.texture,e}}let xB=0;class yB extends Gb{constructor(e,t){super(e,t),this.id=xB++,this.store=!1,this.mipLevel=0,this.isSampledTexture=!0}}class td extends yB{constructor(e,t,n,i=null){super(e,t?t.value:null),this.textureNode=t,this.groupNode=n,this.access=i}update(){const{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}}class Vb extends td{constructor(e,t,n,i=null){super(e,t,n,i),this.isSampledCubeTexture=!0}}class Cp extends td{constructor(e,t,n,i=null){super(e,t,n,i),this.isSampledTexture3D=!0}}const o0={bitcast_int_uint:new Rn("uint tsl_bitcast_int_to_uint ( int x ) { return floatBitsToUint( intBitsToFloat ( x ) ); }"),bitcast_uint_int:new Rn("uint tsl_bitcast_uint_to_int ( uint x ) { return floatBitsToInt( uintBitsToFloat ( x ) ); }")},vB={textureDimensions:"textureSize",equals:"equal",bitcast_float_int:"floatBitsToInt",bitcast_int_float:"intBitsToFloat",bitcast_uint_float:"uintBitsToFloat",bitcast_float_uint:"floatBitsToUint",bitcast_uint_int:"tsl_bitcast_uint_to_int",bitcast_int_uint:"tsl_bitcast_int_to_uint",floatpack_snorm_2x16:"packSnorm2x16",floatpack_unorm_2x16:"packUnorm2x16",floatpack_float16_2x16:"packHalf2x16",floatunpack_snorm_2x16:"unpackSnorm2x16",floatunpack_unorm_2x16:"unpackUnorm2x16",floatunpack_float16_2x16:"unpackHalf2x16"},a0={low:"lowp",medium:"mediump",high:"highp"},l0={swizzleAssign:!0,storageBuffer:!1},c0={perspective:"smooth",linear:"noperspective"},u0={centroid:"centroid"},h0=`
@@ -4685,7 +4685,7 @@ precision highp samplerCubeShadow;
4685
4685
  ${n.code}
4686
4686
  return ${n.result};
4687
4687
 
4688
- }`}setupPBO(e){const t=e.value;if(t.pbo===void 0){const n=t.array,i=t.count*t.itemSize,{itemSize:s}=t,o=t.array.constructor.name.toLowerCase().includes("int");let a=o?Eo:il;s===2?a=o?Ao:In:s===3?a=o?q0:nl:s===4&&(a=o?rl:ln);const l={Float32Array:Qt,Uint8Array:Xt,Uint16Array:Ui,Uint32Array:Ct,Int8Array:Ts,Int16Array:Ms,Int32Array:Sn,Uint8ClampedArray:Xt},c=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(i/s))));let u=Math.ceil(i/s/c);c*u*s<i&&u++;const h=c*u*s,d=new n.constructor(h);d.set(n,0),t.array=d;const f=new gm(t.array,c,u,a,l[t.array.constructor.name]||Qt);f.needsUpdate=!0,f.isPBOTexture=!0;const p=new zc(f,null,null);p.setPrecision("high"),t.pboNode=p,t.pbo=p.value,this.getUniformFromNode(t.pboNode,"texture",this.shaderStage,this.context.nodeName)}}getPropertyName(e,t=this.shaderStage){return e.isNodeUniform&&e.node.isTextureNode!==!0&&e.node.isBufferNode!==!0?e.name:super.getPropertyName(e,t)}generatePBO(e){const{node:t,indexNode:n}=e,i=t.value;if(this.renderer.backend.has(i)){const u=this.renderer.backend.get(i);u.pbo=i.pbo}const s=this.getUniformFromNode(i.pboNode,"texture",this.shaderStage,this.context.nodeName),o=this.getPropertyName(s);this.increaseUsage(n);const a=n.build(this,"uint"),l=this.getDataFromNode(e);let c=l.propertyName;if(c===void 0){const u=this.getVarFromNode(e);c=this.getPropertyName(u);const h=this.getDataFromNode(t);let d=h.propertySizeName;d===void 0&&(d=c+"Size",this.getVarFromNode(t,d,"uint"),this.addLineFlowCode(`${d} = uint( textureSize( ${o}, 0 ).x )`,e),h.propertySizeName=d);const{itemSize:f}=i,p="."+ul.join("").slice(0,f),g=`ivec2(${a} % ${d}, ${a} / ${d})`,m=this.generateTextureLoad(null,o,g,"0",null,null);let _="vec4";i.pbo.type===Ct?_="uvec4":i.pbo.type===Sn&&(_="ivec4"),this.addLineFlowCode(`${c} = ${_}(${m})${p}`,e),l.propertyName=c}return c}generateTextureLoad(e,t,n,i,s,o){i===null&&(i="0");let a;return s?o?a=`texelFetchOffset( ${t}, ivec3( ${n}, ${s} ), int( ${i} ), ${o} )`:a=`texelFetch( ${t}, ivec3( ${n}, ${s} ), int( ${i} ) )`:o?a=`texelFetchOffset( ${t}, ${n}, int( ${i} ), ${o} )`:a=`texelFetch( ${t}, ${n}, int( ${i} ) )`,e!==null&&e.isDepthTexture&&(a+=".x"),a}generateTexture(e,t,n,i,s){return i&&(n=`vec3( ${n}, ${i} )`),e.isDepthTexture?s?`textureOffset( ${t}, ${n}, ${s} ).x`:`texture( ${t}, ${n} ).x`:s?`textureOffset( ${t}, ${n}, ${s} )`:`texture( ${t}, ${n} )`}generateTextureLevel(e,t,n,i,s,o){return s&&(n=`vec3( ${n}, ${s} )`),o?`textureLodOffset( ${t}, ${n}, ${i}, ${o} )`:`textureLod( ${t}, ${n}, ${i} )`}generateTextureBias(e,t,n,i,s,o){return s&&(n=`vec3( ${n}, ${s} )`),o?`textureOffset( ${t}, ${n}, ${o}, ${i} )`:`texture( ${t}, ${n}, ${i} )`}generateTextureGrad(e,t,n,i,s,o){return s&&(n=`vec3( ${n}, ${s} )`),o?`textureGradOffset( ${t}, ${n}, ${i[0]}, ${i[1]}, ${o} )`:`textureGrad( ${t}, ${n}, ${i[0]}, ${i[1]} )`}generateTextureCompare(e,t,n,i,s,o,a=this.shaderStage){if(a==="fragment")return e.isCubeTexture?`texture( ${t}, vec4( ${n}, ${i} ) )`:s?o?`textureOffset( ${t}, vec4( ${n}, ${s}, ${i} ), ${o} )`:`texture( ${t}, vec4( ${n}, ${s}, ${i} ) )`:o?`textureOffset( ${t}, vec3( ${n}, ${i} ), ${o} )`:`texture( ${t}, vec3( ${n}, ${i} ) )`;ce(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${a} shader.`)}getUniforms(e){const t=this.uniforms[e],n=[],i={};for(const o of t){let a=null,l=!1;if(o.type==="texture"||o.type==="texture3D"){const c=o.node.value;let u="";(c.isDataTexture===!0||c.isData3DTexture===!0)&&(c.type===Ct?u="u":c.type===Sn&&(u="i")),o.type==="texture3D"&&c.isArrayTexture===!1?a=`${u}sampler3D ${o.name};`:c.compareFunction?c.isArrayTexture===!0?a=`sampler2DArrayShadow ${o.name};`:a=`sampler2DShadow ${o.name};`:c.isArrayTexture===!0||c.isDataArrayTexture===!0||c.isCompressedArrayTexture===!0?a=`${u}sampler2DArray ${o.name};`:a=`${u}sampler2D ${o.name};`}else if(o.type==="cubeTexture")a=`samplerCube ${o.name};`;else if(o.type==="cubeDepthTexture")o.node.value.compareFunction?a=`samplerCubeShadow ${o.name};`:a=`samplerCube ${o.name};`;else if(o.type==="buffer"){const c=o.node,u=this.getType(c.bufferType),h=c.bufferCount,d=h>0?h:"";a=`${c.name} {
4688
+ }`}setupPBO(e){const t=e.value;if(t.pbo===void 0){const n=t.array,i=t.count*t.itemSize,{itemSize:s}=t,o=t.array.constructor.name.toLowerCase().includes("int");let a=o?Eo:il;s===2?a=o?Ao:In:s===3?a=o?q0:nl:s===4&&(a=o?rl:ln);const l={Float32Array:Qt,Uint8Array:Xt,Uint16Array:Li,Uint32Array:Ct,Int8Array:Ts,Int16Array:Ms,Int32Array:Sn,Uint8ClampedArray:Xt},c=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(i/s))));let u=Math.ceil(i/s/c);c*u*s<i&&u++;const h=c*u*s,d=new n.constructor(h);d.set(n,0),t.array=d;const f=new gm(t.array,c,u,a,l[t.array.constructor.name]||Qt);f.needsUpdate=!0,f.isPBOTexture=!0;const p=new zc(f,null,null);p.setPrecision("high"),t.pboNode=p,t.pbo=p.value,this.getUniformFromNode(t.pboNode,"texture",this.shaderStage,this.context.nodeName)}}getPropertyName(e,t=this.shaderStage){return e.isNodeUniform&&e.node.isTextureNode!==!0&&e.node.isBufferNode!==!0?e.name:super.getPropertyName(e,t)}generatePBO(e){const{node:t,indexNode:n}=e,i=t.value;if(this.renderer.backend.has(i)){const u=this.renderer.backend.get(i);u.pbo=i.pbo}const s=this.getUniformFromNode(i.pboNode,"texture",this.shaderStage,this.context.nodeName),o=this.getPropertyName(s);this.increaseUsage(n);const a=n.build(this,"uint"),l=this.getDataFromNode(e);let c=l.propertyName;if(c===void 0){const u=this.getVarFromNode(e);c=this.getPropertyName(u);const h=this.getDataFromNode(t);let d=h.propertySizeName;d===void 0&&(d=c+"Size",this.getVarFromNode(t,d,"uint"),this.addLineFlowCode(`${d} = uint( textureSize( ${o}, 0 ).x )`,e),h.propertySizeName=d);const{itemSize:f}=i,p="."+ul.join("").slice(0,f),g=`ivec2(${a} % ${d}, ${a} / ${d})`,m=this.generateTextureLoad(null,o,g,"0",null,null);let _="vec4";i.pbo.type===Ct?_="uvec4":i.pbo.type===Sn&&(_="ivec4"),this.addLineFlowCode(`${c} = ${_}(${m})${p}`,e),l.propertyName=c}return c}generateTextureLoad(e,t,n,i,s,o){i===null&&(i="0");let a;return s?o?a=`texelFetchOffset( ${t}, ivec3( ${n}, ${s} ), int( ${i} ), ${o} )`:a=`texelFetch( ${t}, ivec3( ${n}, ${s} ), int( ${i} ) )`:o?a=`texelFetchOffset( ${t}, ${n}, int( ${i} ), ${o} )`:a=`texelFetch( ${t}, ${n}, int( ${i} ) )`,e!==null&&e.isDepthTexture&&(a+=".x"),a}generateTexture(e,t,n,i,s){return i&&(n=`vec3( ${n}, ${i} )`),e.isDepthTexture?s?`textureOffset( ${t}, ${n}, ${s} ).x`:`texture( ${t}, ${n} ).x`:s?`textureOffset( ${t}, ${n}, ${s} )`:`texture( ${t}, ${n} )`}generateTextureLevel(e,t,n,i,s,o){return s&&(n=`vec3( ${n}, ${s} )`),o?`textureLodOffset( ${t}, ${n}, ${i}, ${o} )`:`textureLod( ${t}, ${n}, ${i} )`}generateTextureBias(e,t,n,i,s,o){return s&&(n=`vec3( ${n}, ${s} )`),o?`textureOffset( ${t}, ${n}, ${o}, ${i} )`:`texture( ${t}, ${n}, ${i} )`}generateTextureGrad(e,t,n,i,s,o){return s&&(n=`vec3( ${n}, ${s} )`),o?`textureGradOffset( ${t}, ${n}, ${i[0]}, ${i[1]}, ${o} )`:`textureGrad( ${t}, ${n}, ${i[0]}, ${i[1]} )`}generateTextureCompare(e,t,n,i,s,o,a=this.shaderStage){if(a==="fragment")return e.isCubeTexture?`texture( ${t}, vec4( ${n}, ${i} ) )`:s?o?`textureOffset( ${t}, vec4( ${n}, ${s}, ${i} ), ${o} )`:`texture( ${t}, vec4( ${n}, ${s}, ${i} ) )`:o?`textureOffset( ${t}, vec3( ${n}, ${i} ), ${o} )`:`texture( ${t}, vec3( ${n}, ${i} ) )`;ce(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${a} shader.`)}getUniforms(e){const t=this.uniforms[e],n=[],i={};for(const o of t){let a=null,l=!1;if(o.type==="texture"||o.type==="texture3D"){const c=o.node.value;let u="";(c.isDataTexture===!0||c.isData3DTexture===!0)&&(c.type===Ct?u="u":c.type===Sn&&(u="i")),o.type==="texture3D"&&c.isArrayTexture===!1?a=`${u}sampler3D ${o.name};`:c.compareFunction?c.isArrayTexture===!0?a=`sampler2DArrayShadow ${o.name};`:a=`sampler2DShadow ${o.name};`:c.isArrayTexture===!0||c.isDataArrayTexture===!0||c.isCompressedArrayTexture===!0?a=`${u}sampler2DArray ${o.name};`:a=`${u}sampler2D ${o.name};`}else if(o.type==="cubeTexture")a=`samplerCube ${o.name};`;else if(o.type==="cubeDepthTexture")o.node.value.compareFunction?a=`samplerCubeShadow ${o.name};`:a=`samplerCube ${o.name};`;else if(o.type==="buffer"){const c=o.node,u=this.getType(c.bufferType),h=c.bufferCount,d=h>0?h:"";a=`${c.name} {
4689
4689
  ${u} ${o.name}[${d}];
4690
4690
  };
4691
4691
  `}else{const c=o.groupNode.name;if(i[c]===void 0){const u=this.uniformGroups[c];if(u!==void 0){const h=[];for(const d of u.uniforms){const f=d.getType(),p=this.getVectorType(f),g=d.nodeUniform.node.precision;let m=`${p} ${d.name};`;g!==null&&(m=a0[g]+" "+m),h.push(" "+m)}i[c]=h}}l=!0}if(!l){const c=o.node.precision;c!==null&&(a=a0[c]+" "+a),a="uniform "+a,n.push(a)}}let s="";for(const o in i){const a=i[o];s+=this._getGLSLUniformStruct(o,a.join(`
@@ -4787,7 +4787,7 @@ void main() {
4787
4787
  `,a===s&&t!=="compute"&&(n+=`// result
4788
4788
  `,t==="vertex"?(n+="gl_Position = ",n+=`${l.result};`):t==="fragment"&&(a.outputNode.isOutputStructNode||(n+="fragColor = ",n+=`${l.result};`)))}const o=e[t];if(o.extensions=this.getExtensions(t),o.uniforms=this.getUniforms(t),o.attributes=this.getAttributes(t),o.varyings=this.getVaryings(t),o.vars=this.getVars(t,!0),o.structs=this.getStructs(t),o.codes=this.getCodes(t),o.transforms=this.getTransforms(t),o.flow=n,t==="vertex"){const a=this.renderer.backend.extensions;this.object.isBatchedMesh&&a.has("WEBGL_multi_draw")===!1&&(o.uniforms+=`
4789
4789
  uniform uint nodeUniformDrawId;
4790
- `)}}this.material!==null?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,n,i=null){const s=super.getUniformFromNode(e,t,n,i),o=this.getDataFromNode(e,n,this.globalCache);let a=o.uniformGPU;if(a===void 0){const l=e.groupNode,c=l.name,u=this.getBindGroupArray(c,n);if(t==="texture")a=new td(s.name,s.node,l),u.push(a);else if(t==="cubeTexture"||t==="cubeDepthTexture")a=new Vb(s.name,s.node,l),u.push(a);else if(t==="texture3D")a=new Cp(s.name,s.node,l),u.push(a);else if(t==="buffer"){s.name=`buffer${e.id}`;const h=this.getSharedDataFromNode(e);let d=h.buffer;d===void 0&&(e.name=`NodeBuffer_${e.id}`,d=new Ob(e,l),d.name=e.name,h.buffer=d),u.push(d),a=d}else{let h=this.uniformGroups[c];h===void 0?(h=new kb(c,l),this.uniformGroups[c]=h,u.push(h)):u.indexOf(h)===-1&&u.push(h),a=this.getNodeUniform(s,t);const d=a.name;h.uniforms.some(p=>p.name===d)||h.addUniform(a)}o.uniformGPU=a}return s}}let kf=null,aa=null;class zb{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null,this.timestampQueryPool={[xr.RENDER]:null,[xr.COMPUTE]:null},this.trackTimestamp=e.trackTimestamp===!0}async init(e){this.renderer=e}get coordinateSystem(){}beginRender(){}finishRender(){}beginCompute(){}finishCompute(){}draw(){}compute(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}updateBinding(){}createRenderPipeline(){}createComputePipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}updateSampler(){}createDefaultTexture(){}createTexture(){}updateTexture(){}generateMipmaps(){}destroyTexture(){}async copyTextureToBuffer(){}copyTextureToTexture(){}copyFramebufferToTexture(){}createAttribute(){}createIndexAttribute(){}createStorageAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}updateViewport(){}updateTimeStampUID(e){const t=this.get(e),n=this.renderer.info.frame;let i;e.isComputeNode===!0?i="c:"+this.renderer.info.compute.frameCalls:i="r:"+this.renderer.info.render.frameCalls,t.timestampUID=i+":"+e.id+":f"+n}getTimestampUID(e){return this.get(e).timestampUID}getTimestampFrames(e){const t=this.timestampQueryPool[e];return t?t.getTimestampFrames():[]}_getQueryPool(e){const t=e.startsWith("c:")?xr.COMPUTE:xr.RENDER;return this.timestampQueryPool[t]}getTimestamp(e){return this._getQueryPool(e).getTimestamp(e)}hasTimestamp(e){return this._getQueryPool(e).hasTimestamp(e)}isOccluded(){}async resolveTimestampsAsync(e="render"){if(!this.trackTimestamp){Kt("WebGPURenderer: Timestamp tracking is disabled.");return}const t=this.timestampQueryPool[e];if(!t)return;const n=await t.resolveQueriesAsync();return this.renderer.info[e].timestamp=n,n}async getArrayBufferAsync(){}async hasFeatureAsync(){}hasFeature(){}getDrawingBufferSize(){return kf=kf||new pe,this.renderer.getDrawingBufferSize(kf)}setScissorTest(){}getClearColor(){const e=this.renderer;return aa=aa||new jm,e.getClearColor(aa),aa.getRGB(aa),aa}getDomElement(){let e=this.domElement;return e===null&&(e=this.parameters.canvas!==void 0?this.parameters.canvas:K0(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${Mo} webgpu`),this.domElement=e),e}hasCompatibility(){return!1}initRenderTarget(){}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}deleteBindGroupData(){}dispose(){}}let SB=0;class TB{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[this.activeBufferIndex^1]}switchBuffers(){this.activeBufferIndex^=1}}class MB{constructor(e){this.backend=e}createAttribute(e,t){const n=this.backend,{gl:i}=n,s=e.array,o=e.usage||i.STATIC_DRAW,a=e.isInterleavedBufferAttribute?e.data:e,l=n.get(a);let c=l.bufferGPU;c===void 0&&(c=this._createBuffer(i,t,s,o),l.bufferGPU=c,l.bufferType=t,l.version=a.version);let u;if(s instanceof Float32Array)u=i.FLOAT;else if(typeof Float16Array<"u"&&s instanceof Float16Array)u=i.HALF_FLOAT;else if(s instanceof Uint16Array)e.isFloat16BufferAttribute?u=i.HALF_FLOAT:u=i.UNSIGNED_SHORT;else if(s instanceof Int16Array)u=i.SHORT;else if(s instanceof Uint32Array)u=i.UNSIGNED_INT;else if(s instanceof Int32Array)u=i.INT;else if(s instanceof Int8Array)u=i.BYTE;else if(s instanceof Uint8Array)u=i.UNSIGNED_BYTE;else if(s instanceof Uint8ClampedArray)u=i.UNSIGNED_BYTE;else throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+s);let h={bufferGPU:c,bufferType:t,type:u,byteLength:s.byteLength,bytesPerElement:s.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===i.INT||u===i.UNSIGNED_INT||e.gpuType===Sn,id:SB++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const d=this._createBuffer(i,t,s,o);h=new TB(h,d)}n.set(e,h)}updateAttribute(e){const t=this.backend,{gl:n}=t,i=e.array,s=e.isInterleavedBufferAttribute?e.data:e,o=t.get(s),a=o.bufferType,l=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(n.bindBuffer(a,o.bufferGPU),l.length===0)n.bufferSubData(a,0,i);else{for(let c=0,u=l.length;c<u;c++){const h=l[c];n.bufferSubData(a,h.start*i.BYTES_PER_ELEMENT,i,h.start,h.count)}s.clearUpdateRanges()}n.bindBuffer(a,null),o.version=s.version}destroyAttribute(e){const t=this.backend,{gl:n}=t;e.isInterleavedBufferAttribute&&t.delete(e.data);const i=t.get(e);n.deleteBuffer(i.bufferGPU),t.delete(e)}async getArrayBufferAsync(e,t=null,n=0,i=-1){const s=this.backend,{gl:o}=s,a=e.isInterleavedBufferAttribute?e.data:e,l=s.get(a),{bufferGPU:c}=l,u=i===-1?l.byteLength-n:i;let h;if(t===null)h=new Uint8Array(new ArrayBuffer(u));else if(t.isReadbackBuffer){if(t._mapped===!0)throw new Error("WebGPURenderer: ReadbackBuffer must be released before being used again.");const d=()=>{t.buffer=null,t._mapped=!1,t.removeEventListener("release",d),t.removeEventListener("dispose",d)};t.addEventListener("release",d),t.addEventListener("dispose",d),h=new Uint8Array(new ArrayBuffer(u)),t.buffer=h.buffer}else h=new Uint8Array(t);return o.bindBuffer(o.COPY_READ_BUFFER,c),o.getBufferSubData(o.COPY_READ_BUFFER,n,h),o.bindBuffer(o.COPY_READ_BUFFER,null),o.bindBuffer(o.COPY_WRITE_BUFFER,null),t&&t.isReadbackBuffer?t:h.buffer}_createBuffer(e,t,n,i){const s=e.createBuffer();return e.bindBuffer(t,s),e.bufferData(t,n,i),e.bindBuffer(t,null),s}}let Vl,Or;class EB{constructor(e){this.backend=e,this.gl=this.backend.gl,this.enabled={},this.parameters={},this.currentFlipSided=null,this.currentCullFace=null,this.currentProgram=null,this.currentBlendingEnabled=!1,this.currentBlending=null,this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentPremultipledAlpha=null,this.currentPolygonOffsetFactor=null,this.currentPolygonOffsetUnits=null,this.currentColorMask=null,this.currentDepthReversed=!1,this.currentDepthFunc=null,this.currentDepthMask=null,this.currentStencilFunc=null,this.currentStencilRef=null,this.currentStencilFuncMask=null,this.currentStencilFail=null,this.currentStencilZFail=null,this.currentStencilZPass=null,this.currentStencilMask=null,this.currentLineWidth=null,this.currentClippingPlanes=0,this.currentVAO=null,this.currentIndex=null,this.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.currentTextureSlot=null,this.currentBoundTextures={},this.currentBoundBufferBases={},this._init()}_init(){const e=this.gl;Vl={[Xn]:e.FUNC_ADD,[Bp]:e.FUNC_SUBTRACT,[Op]:e.FUNC_REVERSE_SUBTRACT},Or={[Gr]:e.ZERO,[kp]:e.ONE,[Gp]:e.SRC_COLOR,[oc]:e.SRC_ALPHA,[Xp]:e.SRC_ALPHA_SATURATE,[Wp]:e.DST_COLOR,[zp]:e.DST_ALPHA,[Vp]:e.ONE_MINUS_SRC_COLOR,[ac]:e.ONE_MINUS_SRC_ALPHA,[$p]:e.ONE_MINUS_DST_COLOR,[Hp]:e.ONE_MINUS_DST_ALPHA};const t=e.getParameter(e.SCISSOR_BOX),n=e.getParameter(e.VIEWPORT);this.currentScissor=new rt().fromArray(t),this.currentViewport=new rt().fromArray(n),this._tempVec4=new rt}enable(e){const{enabled:t}=this;t[e]!==!0&&(this.gl.enable(e),t[e]=!0)}disable(e){const{enabled:t}=this;t[e]!==!1&&(this.gl.disable(e),t[e]=!1)}setFlipSided(e){if(this.currentFlipSided!==e){const{gl:t}=this;e?t.frontFace(t.CW):t.frontFace(t.CCW),this.currentFlipSided=e}}setCullFace(e){const{gl:t}=this;e!==O0?(this.enable(t.CULL_FACE),e!==this.currentCullFace&&(e===Jf?t.cullFace(t.BACK):e===k0?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):this.disable(t.CULL_FACE),this.currentCullFace=e}setLineWidth(e){const{currentLineWidth:t,gl:n}=this;e!==t&&(n.lineWidth(e),this.currentLineWidth=e)}setMRTBlending(e,t,n){const i=this.gl,s=this.backend.drawBuffersIndexedExt;if(!s){Kt("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets.");return}for(let o=0;o<e.length;o++){const a=e[o];let l=null;if(t!==null){const c=t.getBlendMode(a.name);c.blending===V0?l=n:c.blending!==Pn&&(l=c)}else l=n;l!==null?this._setMRTBlendingIndex(o,l):s.blendFuncSeparateiOES(o,i.ONE,i.ZERO,i.ONE,i.ZERO)}}_setMRTBlendingIndex(e,t){const{gl:n}=this,i=this.backend.drawBuffersIndexedExt,s=t.blending,o=t.blendSrc,a=t.blendDst,l=t.blendEquation,c=t.premultipliedAlpha;if(s===co){const u=t.blendSrcAlpha!==null?t.blendSrcAlpha:o,h=t.blendDstAlpha!==null?t.blendDstAlpha:a,d=t.blendEquationAlpha!==null?t.blendEquationAlpha:l;i.blendEquationSeparateiOES(e,Vl[l],Vl[d]),i.blendFuncSeparateiOES(e,Or[o],Or[a],Or[u],Or[h])}else if(i.blendEquationSeparateiOES(e,n.FUNC_ADD,n.FUNC_ADD),c)switch(s){case ti:i.blendFuncSeparateiOES(e,n.ONE,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA);break;case _s:i.blendFuncSeparateiOES(e,n.ONE,n.ONE,n.ONE,n.ONE);break;case xs:i.blendFuncSeparateiOES(e,n.ZERO,n.ONE_MINUS_SRC_COLOR,n.ZERO,n.ONE);break;case ys:i.blendFuncSeparateiOES(e,n.DST_COLOR,n.ONE_MINUS_SRC_ALPHA,n.ZERO,n.ONE);break;default:i.blendFuncSeparateiOES(e,n.ONE,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA);break}else switch(s){case ti:i.blendFuncSeparateiOES(e,n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA);break;case _s:i.blendFuncSeparateiOES(e,n.SRC_ALPHA,n.ONE,n.ONE,n.ONE);break;case xs:i.blendFuncSeparateiOES(e,n.ZERO,n.ONE_MINUS_SRC_COLOR,n.ZERO,n.ONE);break;case ys:i.blendFuncSeparateiOES(e,n.DST_COLOR,n.ONE_MINUS_SRC_ALPHA,n.ZERO,n.ONE);break;default:i.blendFuncSeparateiOES(e,n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA);break}}setBlending(e,t,n,i,s,o,a,l){const{gl:c}=this;if(e===Pn){this.currentBlendingEnabled===!0&&(this.disable(c.BLEND),this.currentBlendingEnabled=!1);return}if(this.currentBlendingEnabled===!1&&(this.enable(c.BLEND),this.currentBlendingEnabled=!0),e!==co){if(e!==this.currentBlending||l!==this.currentPremultipledAlpha){if((this.currentBlendEquation!==Xn||this.currentBlendEquationAlpha!==Xn)&&(c.blendEquation(c.FUNC_ADD),this.currentBlendEquation=Xn,this.currentBlendEquationAlpha=Xn),l)switch(e){case ti:c.blendFuncSeparate(c.ONE,c.ONE_MINUS_SRC_ALPHA,c.ONE,c.ONE_MINUS_SRC_ALPHA);break;case _s:c.blendFunc(c.ONE,c.ONE);break;case xs:c.blendFuncSeparate(c.ZERO,c.ONE_MINUS_SRC_COLOR,c.ZERO,c.ONE);break;case ys:c.blendFuncSeparate(c.DST_COLOR,c.ONE_MINUS_SRC_ALPHA,c.ZERO,c.ONE);break;default:ce("WebGLState: Invalid blending: ",e);break}else switch(e){case ti:c.blendFuncSeparate(c.SRC_ALPHA,c.ONE_MINUS_SRC_ALPHA,c.ONE,c.ONE_MINUS_SRC_ALPHA);break;case _s:c.blendFuncSeparate(c.SRC_ALPHA,c.ONE,c.ONE,c.ONE);break;case xs:ce("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case ys:ce("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:ce("WebGLState: Invalid blending: ",e);break}this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlending=e,this.currentPremultipledAlpha=l}return}s=s||t,o=o||n,a=a||i,(t!==this.currentBlendEquation||s!==this.currentBlendEquationAlpha)&&(c.blendEquationSeparate(Vl[t],Vl[s]),this.currentBlendEquation=t,this.currentBlendEquationAlpha=s),(n!==this.currentBlendSrc||i!==this.currentBlendDst||o!==this.currentBlendSrcAlpha||a!==this.currentBlendDstAlpha)&&(c.blendFuncSeparate(Or[n],Or[i],Or[o],Or[a]),this.currentBlendSrc=n,this.currentBlendDst=i,this.currentBlendSrcAlpha=o,this.currentBlendDstAlpha=a),this.currentBlending=e,this.currentPremultipledAlpha=!1}setColorMask(e){this.currentColorMask!==e&&(this.gl.colorMask(e,e,e,e),this.currentColorMask=e)}setDepthTest(e){const{gl:t}=this;e?this.enable(t.DEPTH_TEST):this.disable(t.DEPTH_TEST)}setReversedDepth(e){if(this.currentDepthReversed!==e){const t=this.backend.extensions.get("EXT_clip_control");e?t.clipControlEXT(t.LOWER_LEFT_EXT,t.ZERO_TO_ONE_EXT):t.clipControlEXT(t.LOWER_LEFT_EXT,t.NEGATIVE_ONE_TO_ONE_EXT),this.currentDepthReversed=e}}setDepthMask(e){this.currentDepthMask!==e&&(this.gl.depthMask(e),this.currentDepthMask=e)}setDepthFunc(e){if(this.currentDepthReversed&&(e=sm[e]),this.currentDepthFunc!==e){const{gl:t}=this;switch(e){case lc:t.depthFunc(t.NEVER);break;case cc:t.depthFunc(t.ALWAYS);break;case uc:t.depthFunc(t.LESS);break;case Ds:t.depthFunc(t.LEQUAL);break;case hc:t.depthFunc(t.EQUAL);break;case dc:t.depthFunc(t.GEQUAL);break;case fc:t.depthFunc(t.GREATER);break;case pc:t.depthFunc(t.NOTEQUAL);break;default:t.depthFunc(t.LEQUAL)}this.currentDepthFunc=e}}scissor(e,t,n,i){const s=this._tempVec4.set(e,t,n,i);if(this.currentScissor.equals(s)===!1){const{gl:o}=this;o.scissor(s.x,s.y,s.z,s.w),this.currentScissor.copy(s)}}viewport(e,t,n,i){const s=this._tempVec4.set(e,t,n,i);if(this.currentViewport.equals(s)===!1){const{gl:o}=this;o.viewport(s.x,s.y,s.z,s.w),this.currentViewport.copy(s)}}setScissorTest(e){const t=this.gl;e?this.enable(t.SCISSOR_TEST):this.disable(t.SCISSOR_TEST)}setStencilTest(e){const{gl:t}=this;e?this.enable(t.STENCIL_TEST):this.disable(t.STENCIL_TEST)}setStencilMask(e){this.currentStencilMask!==e&&(this.gl.stencilMask(e),this.currentStencilMask=e)}setStencilFunc(e,t,n){(this.currentStencilFunc!==e||this.currentStencilRef!==t||this.currentStencilFuncMask!==n)&&(this.gl.stencilFunc(e,t,n),this.currentStencilFunc=e,this.currentStencilRef=t,this.currentStencilFuncMask=n)}setStencilOp(e,t,n){(this.currentStencilFail!==e||this.currentStencilZFail!==t||this.currentStencilZPass!==n)&&(this.gl.stencilOp(e,t,n),this.currentStencilFail=e,this.currentStencilZFail=t,this.currentStencilZPass=n)}setMaterial(e,t,n){const{gl:i}=this;e.side===Nn?this.disable(i.CULL_FACE):this.enable(i.CULL_FACE);let s=e.side===Lt;t&&(s=!s),this.setFlipSided(s),e.blending===ti&&e.transparent===!1?this.setBlending(Pn):this.setBlending(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.premultipliedAlpha),this.setDepthFunc(e.depthFunc),this.setDepthTest(e.depthTest),this.setDepthMask(e.depthWrite),this.setColorMask(e.colorWrite);const o=e.stencilWrite;if(this.setStencilTest(o),o&&(this.setStencilMask(e.stencilWriteMask),this.setStencilFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),this.setStencilOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),this.setPolygonOffset(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),e.alphaToCoverage===!0&&this.backend.renderer.currentSamples>0?this.enable(i.SAMPLE_ALPHA_TO_COVERAGE):this.disable(i.SAMPLE_ALPHA_TO_COVERAGE),n>0&&this.currentClippingPlanes!==n)for(let l=0;l<8;l++)l<n?this.enable(12288+l):this.disable(12288+l)}setPolygonOffset(e,t,n){const{gl:i}=this;e?(this.enable(i.POLYGON_OFFSET_FILL),(this.currentPolygonOffsetFactor!==t||this.currentPolygonOffsetUnits!==n)&&(i.polygonOffset(t,n),this.currentPolygonOffsetFactor=t,this.currentPolygonOffsetUnits=n)):this.disable(i.POLYGON_OFFSET_FILL)}useProgram(e){return this.currentProgram!==e?(this.gl.useProgram(e),this.currentProgram=e,!0):!1}setVertexState(e,t=null){const n=this.gl;return this.currentVAO!==e||this.currentIndex!==t?(n.bindVertexArray(e),t!==null&&n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,t),this.currentVAO=e,this.currentIndex=t,!0):!1}resetVertexState(){const e=this.gl;e.bindVertexArray(null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),this.currentVAO=null,this.currentIndex=null}bindFramebuffer(e,t){const{gl:n,currentBoundFramebuffers:i}=this;return i[e]!==t?(n.bindFramebuffer(e,t),i[e]=t,e===n.DRAW_FRAMEBUFFER&&(i[n.FRAMEBUFFER]=t),e===n.FRAMEBUFFER&&(i[n.DRAW_FRAMEBUFFER]=t),!0):!1}drawBuffers(e,t){const{gl:n}=this;let i=[],s=!1;if(e.textures!==null){i=this.currentDrawbuffers.get(t),i===void 0&&(i=[],this.currentDrawbuffers.set(t,i));const o=e.textures;if(i.length!==o.length||i[0]!==n.COLOR_ATTACHMENT0){for(let a=0,l=o.length;a<l;a++)i[a]=n.COLOR_ATTACHMENT0+a;i.length=o.length,s=!0}}else i[0]!==n.BACK&&(i[0]=n.BACK,s=!0);s&&n.drawBuffers(i)}activeTexture(e){const{gl:t,currentTextureSlot:n,maxTextures:i}=this;e===void 0&&(e=t.TEXTURE0+i-1),n!==e&&(t.activeTexture(e),this.currentTextureSlot=e)}bindTexture(e,t,n){const{gl:i,currentTextureSlot:s,currentBoundTextures:o,maxTextures:a}=this;n===void 0&&(s===null?n=i.TEXTURE0+a-1:n=s);let l=o[n];l===void 0&&(l={type:void 0,texture:void 0},o[n]=l),(l.type!==e||l.texture!==t)&&(s!==n&&(i.activeTexture(n),this.currentTextureSlot=n),i.bindTexture(e,t),l.type=e,l.texture=t)}bindBufferBase(e,t,n){const{gl:i}=this,s=`${e}-${t}`;return this.currentBoundBufferBases[s]!==n?(i.bindBufferBase(e,t,n),this.currentBoundBufferBases[s]=n,!0):!1}unbindTexture(){const{gl:e,currentTextureSlot:t,currentBoundTextures:n}=this,i=n[t];i!==void 0&&i.type!==void 0&&(e.bindTexture(i.type,null),i.type=void 0,i.texture=void 0)}getParameter(e){const{gl:t,parameters:n}=this;return n[e]!==void 0?n[e]:t.getParameter(e)}pixelStorei(e,t){const{gl:n,parameters:i}=this;i[e]!==t&&(n.pixelStorei(e,t),i[e]=t)}}class AB{constructor(e){this.backend=e,this.gl=this.backend.gl,this.extensions=e.extensions}convert(e,t=ai){const{gl:n,extensions:i}=this;let s;const o=Ye.getTransfer(t);if(e===Xt)return n.UNSIGNED_BYTE;if(e===Pc)return n.UNSIGNED_SHORT_4_4_4_4;if(e===Dc)return n.UNSIGNED_SHORT_5_5_5_1;if(e===Lc)return n.UNSIGNED_INT_5_9_9_9_REV;if(e===Uc)return n.UNSIGNED_INT_10F_11F_11F_REV;if(e===Ts)return n.BYTE;if(e===Ms)return n.SHORT;if(e===Ui)return n.UNSIGNED_SHORT;if(e===Sn)return n.INT;if(e===Ct)return n.UNSIGNED_INT;if(e===Qt)return n.FLOAT;if(e===tn)return n.HALF_FLOAT;if(e===Fh)return n.ALPHA;if(e===nl)return n.RGB;if(e===ln)return n.RGBA;if(e===Dn)return n.DEPTH_COMPONENT;if(e===qn)return n.DEPTH_STENCIL;if(e===il)return n.RED;if(e===Eo)return n.RED_INTEGER;if(e===In)return n.RG;if(e===Ao)return n.RG_INTEGER;if(e===rl)return n.RGBA_INTEGER;if(e===Es||e===As||e===ws||e===Rs)if(o===Pe)if(s=i.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(e===Es)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(e===As)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(e===ws)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(e===Rs)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=i.get("WEBGL_compressed_texture_s3tc"),s!==null){if(e===Es)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(e===As)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(e===ws)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(e===Rs)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(e===mc||e===gc||e===_c||e===xc)if(s=i.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(e===mc)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(e===gc)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(e===_c)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(e===xc)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(e===Ma||e===Ea||e===Aa||e===wa||e===Ra||e===Ls||e===Ca)if(s=i.get("WEBGL_compressed_texture_etc"),s!==null){if(e===Ma||e===Ea)return o===Pe?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(e===Aa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(e===wa)return s.COMPRESSED_R11_EAC;if(e===Ra)return s.COMPRESSED_SIGNED_R11_EAC;if(e===Ls)return s.COMPRESSED_RG11_EAC;if(e===Ca)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(e===Na||e===Pa||e===Da||e===La||e===Ua||e===Fa||e===Ia||e===Ba||e===Oa||e===ka||e===Ga||e===Va||e===za||e===Ha)if(s=i.get("WEBGL_compressed_texture_astc"),s!==null){if(e===Na)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(e===Pa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(e===Da)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(e===La)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(e===Ua)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(e===Fa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(e===Ia)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(e===Ba)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(e===Oa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(e===ka)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(e===Ga)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(e===Va)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(e===za)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(e===Ha)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(e===Wa)if(s=i.get("EXT_texture_compression_bptc"),s!==null){if(e===Wa)return o===Pe?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT}else return null;if(e===$a||e===Xa||e===Us||e===qa)if(s=i.get("EXT_texture_compression_rgtc"),s!==null){if(e===$a)return s.COMPRESSED_RED_RGTC1_EXT;if(e===Xa)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(e===Us)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(e===qa)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return e===di?n.UNSIGNED_INT_24_8:n[e]!==void 0?n[e]:null}_clientWaitAsync(){const{gl:e}=this,t=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),new Promise((n,i)=>{function s(){const o=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(o===e.WAIT_FAILED){e.deleteSync(t),i();return}if(o===e.TIMEOUT_EXPIRED){requestAnimationFrame(s);return}e.deleteSync(t),n()}s()})}}let d0=!1,Ku,Gf,f0;class wB{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},this._srcFramebuffer=null,this._dstFramebuffer=null,d0===!1&&(this._init(),d0=!0)}_init(){const e=this.gl;Ku={[go]:e.REPEAT,[ci]:e.CLAMP_TO_EDGE,[_o]:e.MIRRORED_REPEAT},Gf={[Mt]:e.NEAREST,[em]:e.NEAREST_MIPMAP_NEAREST,[Xr]:e.NEAREST_MIPMAP_LINEAR,[Nt]:e.LINEAR,[ga]:e.LINEAR_MIPMAP_NEAREST,[ui]:e.LINEAR_MIPMAP_LINEAR},f0={[tm]:e.NEVER,[rm]:e.ALWAYS,[Ih]:e.LESS,[Os]:e.LEQUAL,[nm]:e.EQUAL,[Zr]:e.GEQUAL,[vc]:e.GREATER,[im]:e.NOTEQUAL}}getGLTextureType(e){const{gl:t}=this;let n;return e.isCubeTexture===!0?n=t.TEXTURE_CUBE_MAP:e.isArrayTexture===!0||e.isDataArrayTexture===!0||e.isCompressedArrayTexture===!0?n=t.TEXTURE_2D_ARRAY:e.isData3DTexture===!0?n=t.TEXTURE_3D:n=t.TEXTURE_2D,n}getInternalFormat(e,t,n,i,s,o=!1){const{gl:a,extensions:l}=this;if(e!==null){if(a[e]!==void 0)return a[e];ae("WebGLBackend: Attempt to use non-existing WebGL internal format '"+e+"'")}let c=null;i&&(c=l.get("EXT_texture_norm16"),c||ae("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let u=t;if(t===a.RED&&(n===a.FLOAT&&(u=a.R32F),n===a.HALF_FLOAT&&(u=a.R16F),n===a.UNSIGNED_BYTE&&(u=a.R8),n===a.BYTE&&(u=a.R8_SNORM),n===a.UNSIGNED_SHORT&&c&&(u=c.R16_EXT),n===a.SHORT&&c&&(u=c.R16_SNORM_EXT)),t===a.RED_INTEGER&&(n===a.UNSIGNED_BYTE&&(u=a.R8UI),n===a.UNSIGNED_SHORT&&(u=a.R16UI),n===a.UNSIGNED_INT&&(u=a.R32UI),n===a.BYTE&&(u=a.R8I),n===a.SHORT&&(u=a.R16I),n===a.INT&&(u=a.R32I)),t===a.RG&&(n===a.FLOAT&&(u=a.RG32F),n===a.HALF_FLOAT&&(u=a.RG16F),n===a.UNSIGNED_BYTE&&(u=a.RG8),n===a.BYTE&&(u=a.RG8_SNORM),n===a.UNSIGNED_SHORT&&c&&(u=c.RG16_EXT),n===a.SHORT&&c&&(u=c.RG16_SNORM_EXT)),t===a.RG_INTEGER&&(n===a.UNSIGNED_BYTE&&(u=a.RG8UI),n===a.UNSIGNED_SHORT&&(u=a.RG16UI),n===a.UNSIGNED_INT&&(u=a.RG32UI),n===a.BYTE&&(u=a.RG8I),n===a.SHORT&&(u=a.RG16I),n===a.INT&&(u=a.RG32I)),t===a.RGB){const h=o?ja:Ye.getTransfer(s);n===a.FLOAT&&(u=a.RGB32F),n===a.HALF_FLOAT&&(u=a.RGB16F),n===a.UNSIGNED_BYTE&&(u=h===Pe?a.SRGB8:a.RGB8),n===a.BYTE&&(u=a.RGB8_SNORM),n===a.UNSIGNED_SHORT&&c&&(u=c.RGB16_EXT),n===a.SHORT&&c&&(u=c.RGB16_SNORM_EXT),n===a.UNSIGNED_SHORT_5_6_5&&(u=a.RGB565),n===a.UNSIGNED_SHORT_5_5_5_1&&(u=a.RGB5_A1),n===a.UNSIGNED_SHORT_4_4_4_4&&(u=a.RGB4),n===a.UNSIGNED_INT_5_9_9_9_REV&&(u=a.RGB9_E5),n===a.UNSIGNED_INT_10F_11F_11F_REV&&(u=a.R11F_G11F_B10F)}if(t===a.RGB_INTEGER&&(n===a.UNSIGNED_BYTE&&(u=a.RGB8UI),n===a.UNSIGNED_SHORT&&(u=a.RGB16UI),n===a.UNSIGNED_INT&&(u=a.RGB32UI),n===a.BYTE&&(u=a.RGB8I),n===a.SHORT&&(u=a.RGB16I),n===a.INT&&(u=a.RGB32I)),t===a.RGBA){const h=o?ja:Ye.getTransfer(s);n===a.FLOAT&&(u=a.RGBA32F),n===a.HALF_FLOAT&&(u=a.RGBA16F),n===a.UNSIGNED_BYTE&&(u=h===Pe?a.SRGB8_ALPHA8:a.RGBA8),n===a.BYTE&&(u=a.RGBA8_SNORM),n===a.UNSIGNED_SHORT&&c&&(u=c.RGBA16_EXT),n===a.SHORT&&c&&(u=c.RGBA16_SNORM_EXT),n===a.UNSIGNED_SHORT_4_4_4_4&&(u=a.RGBA4),n===a.UNSIGNED_SHORT_5_5_5_1&&(u=a.RGB5_A1)}return t===a.RGBA_INTEGER&&(n===a.UNSIGNED_BYTE&&(u=a.RGBA8UI),n===a.UNSIGNED_SHORT&&(u=a.RGBA16UI),n===a.UNSIGNED_INT&&(u=a.RGBA32UI),n===a.BYTE&&(u=a.RGBA8I),n===a.SHORT&&(u=a.RGBA16I),n===a.INT&&(u=a.RGBA32I)),t===a.DEPTH_COMPONENT&&(n===a.UNSIGNED_SHORT&&(u=a.DEPTH_COMPONENT16),n===a.UNSIGNED_INT&&(u=a.DEPTH_COMPONENT24),n===a.FLOAT&&(u=a.DEPTH_COMPONENT32F)),t===a.DEPTH_STENCIL&&n===a.UNSIGNED_INT_24_8&&(u=a.DEPTH24_STENCIL8),(u===a.R16F||u===a.R32F||u===a.RG16F||u===a.RG32F||u===a.RGBA16F||u===a.RGBA32F)&&l.get("EXT_color_buffer_float"),u}setTextureParameters(e,t){const{gl:n,extensions:i,backend:s}=this,{state:o}=this.backend,a=Ye.getPrimaries(Ye.workingColorSpace),l=t.colorSpace===ai?null:Ye.getPrimaries(t.colorSpace),c=t.colorSpace===ai||a===l?n.NONE:n.BROWSER_DEFAULT_WEBGL;o.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,t.flipY),o.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),o.pixelStorei(n.UNPACK_ALIGNMENT,t.unpackAlignment),o.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,c),n.texParameteri(e,n.TEXTURE_WRAP_S,Ku[t.wrapS]),n.texParameteri(e,n.TEXTURE_WRAP_T,Ku[t.wrapT]),(e===n.TEXTURE_3D||e===n.TEXTURE_2D_ARRAY)&&(t.isArrayTexture||n.texParameteri(e,n.TEXTURE_WRAP_R,Ku[t.wrapR])),n.texParameteri(e,n.TEXTURE_MAG_FILTER,Gf[t.magFilter]);const u=t.mipmaps!==void 0&&t.mipmaps.length>0,h=t.minFilter===Nt&&u?ui:t.minFilter;if(n.texParameteri(e,n.TEXTURE_MIN_FILTER,Gf[h]),t.compareFunction&&(n.texParameteri(e,n.TEXTURE_COMPARE_MODE,n.COMPARE_REF_TO_TEXTURE),n.texParameteri(e,n.TEXTURE_COMPARE_FUNC,f0[t.compareFunction])),i.has("EXT_texture_filter_anisotropic")===!0){if(t.magFilter===Mt||t.minFilter!==Xr&&t.minFilter!==ui||t.type===Qt&&i.has("OES_texture_float_linear")===!1)return;if(t.anisotropy>1){const d=i.get("EXT_texture_filter_anisotropic");n.texParameterf(e,d.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,s.capabilities.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:n,defaultTextures:i}=this,s=this.getGLTextureType(e);let o=i[s];o===void 0&&(o=t.createTexture(),n.state.bindTexture(s,o),t.texParameteri(s,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(s,t.TEXTURE_MAG_FILTER,t.NEAREST),i[s]=o),n.set(e,{textureGPU:o,glTextureType:s})}createTexture(e,t){const{gl:n,backend:i}=this,{levels:s,width:o,height:a,depth:l}=t,c=i.utils.convert(e.format,e.colorSpace),u=i.utils.convert(e.type),h=this.getInternalFormat(e.internalFormat,c,u,e.normalized,e.colorSpace,e.isVideoTexture),d=n.createTexture(),f=this.getGLTextureType(e);i.state.bindTexture(f,d),this.setTextureParameters(f,e),e.isArrayTexture||e.isDataArrayTexture||e.isCompressedArrayTexture?n.texStorage3D(n.TEXTURE_2D_ARRAY,s,h,o,a,l):e.isData3DTexture?n.texStorage3D(n.TEXTURE_3D,s,h,o,a,l):e.isVideoTexture||n.texStorage2D(f,s,h,o,a),i.set(e,{textureGPU:d,glTextureType:f,glFormat:c,glType:u,glInternalFormat:h})}copyBufferToTexture(e,t){const{gl:n,backend:i}=this,{state:s}=i,{textureGPU:o,glTextureType:a,glFormat:l,glType:c}=i.get(t),{width:u,height:h}=t.source.data;n.bindBuffer(n.PIXEL_UNPACK_BUFFER,e),i.state.bindTexture(a,o),s.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),n.texSubImage2D(a,0,0,0,u,h,l,c,0),n.bindBuffer(n.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(e,t){const{gl:n}=this,{width:i,height:s}=t,{textureGPU:o,glTextureType:a,glFormat:l,glType:c,glInternalFormat:u}=this.backend.get(e);if(!(e.isRenderTargetTexture||o===void 0))if(this.backend.state.bindTexture(a,o),this.setTextureParameters(a,e),e.isCompressedTexture){const h=e.mipmaps,d=t.image;for(let f=0;f<h.length;f++){const p=h[f];e.isCompressedArrayTexture?e.format!==n.RGBA?l!==null?n.compressedTexSubImage3D(n.TEXTURE_2D_ARRAY,f,0,0,0,p.width,p.height,d.depth,l,p.data):ae("WebGLBackend: Attempt to load unsupported compressed texture format in .uploadTexture()"):n.texSubImage3D(n.TEXTURE_2D_ARRAY,f,0,0,0,p.width,p.height,d.depth,l,c,p.data):l!==null?n.compressedTexSubImage2D(n.TEXTURE_2D,f,0,0,p.width,p.height,l,p.data):ae("WebGLBackend: Unsupported compressed texture format")}}else if(e.isCubeTexture){const h=t.images,d=e.mipmaps;for(let f=0;f<6;f++){const p=Zu(h[f]);n.texSubImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+f,0,0,0,i,s,l,c,p);for(let g=0;g<d.length;g++){const m=d[g],_=Zu(m.images[f]);n.texSubImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+f,g+1,0,0,_.width,_.height,l,c,_)}}}else if(e.isDataArrayTexture||e.isArrayTexture){const h=t.image;if(e.layerUpdates.size>0){const d=rp(h.width,h.height,e.format,e.type);for(const f of e.layerUpdates){const p=h.data.subarray(f*d/h.data.BYTES_PER_ELEMENT,(f+1)*d/h.data.BYTES_PER_ELEMENT);n.texSubImage3D(n.TEXTURE_2D_ARRAY,0,0,0,f,h.width,h.height,1,l,c,p)}e.clearLayerUpdates()}else n.texSubImage3D(n.TEXTURE_2D_ARRAY,0,0,0,0,h.width,h.height,h.depth,l,c,h.data)}else if(e.isData3DTexture){const h=t.image;n.texSubImage3D(n.TEXTURE_3D,0,0,0,0,h.width,h.height,h.depth,l,c,h.data)}else if(e.isVideoTexture)e.update(),n.texImage2D(a,0,u,l,c,t.image);else if(e.isHTMLTexture)typeof n.texElementImage2D=="function"&&n.texElementImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t.image);else{const h=e.mipmaps;if(h.length>0)for(let d=0,f=h.length;d<f;d++){const p=h[d],g=Zu(p);n.texSubImage2D(a,d,0,0,p.width,p.height,l,c,g)}else{const d=Zu(t.image);n.texSubImage2D(a,0,0,0,i,s,l,c,d)}}}generateMipmaps(e){const{gl:t,backend:n}=this,{textureGPU:i,glTextureType:s}=n.get(e);n.state.bindTexture(s,i),t.generateMipmap(s)}deallocateRenderBuffers(e){const{gl:t,backend:n}=this;if(e){const i=n.get(e);if(i.renderBufferStorageSetup=void 0,i.framebuffers){for(const s in i.framebuffers)t.deleteFramebuffer(i.framebuffers[s]);delete i.framebuffers}if(i.depthRenderbuffer&&(t.deleteRenderbuffer(i.depthRenderbuffer),delete i.depthRenderbuffer),i.stencilRenderbuffer&&(t.deleteRenderbuffer(i.stencilRenderbuffer),delete i.stencilRenderbuffer),i.msaaFrameBuffer&&(t.deleteFramebuffer(i.msaaFrameBuffer),delete i.msaaFrameBuffer),i.msaaRenderbuffers){for(let s=0;s<i.msaaRenderbuffers.length;s++)t.deleteRenderbuffer(i.msaaRenderbuffers[s]);delete i.msaaRenderbuffers}}}destroyTexture(e,t=!1){const{gl:n,backend:i}=this,{textureGPU:s,renderTarget:o}=i.get(e);this.deallocateRenderBuffers(o),t===!1&&n.deleteTexture(s),i.delete(e)}copyTextureToTexture(e,t,n=null,i=null,s=0,o=0){const{gl:a,backend:l}=this,{state:c}=this.backend,{textureGPU:u,glTextureType:h,glType:d,glFormat:f}=l.get(t);c.bindTexture(h,u);let p,g,m,_,x,y,b,M,S;const E=e.isCompressedTexture?e.mipmaps[o]:e.image;if(n!==null)p=n.max.x-n.min.x,g=n.max.y-n.min.y,m=n.isBox3?n.max.z-n.min.z:1,_=n.min.x,x=n.min.y,y=n.isBox3?n.min.z:0;else{const U=Math.pow(2,-s);p=Math.floor(E.width*U),g=Math.floor(E.height*U),e.isDataArrayTexture||e.isArrayTexture?m=E.depth:e.isData3DTexture?m=Math.floor(E.depth*U):m=1,_=0,x=0,y=0}i!==null?(b=i.x,M=i.y,S=i.z):(b=0,M=0,S=0),c.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,t.flipY),c.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),c.pixelStorei(a.UNPACK_ALIGNMENT,t.unpackAlignment);const v=c.getParameter(a.UNPACK_ROW_LENGTH),w=c.getParameter(a.UNPACK_IMAGE_HEIGHT),N=c.getParameter(a.UNPACK_SKIP_PIXELS),C=c.getParameter(a.UNPACK_SKIP_ROWS),F=c.getParameter(a.UNPACK_SKIP_IMAGES);c.pixelStorei(a.UNPACK_ROW_LENGTH,E.width),c.pixelStorei(a.UNPACK_IMAGE_HEIGHT,E.height),c.pixelStorei(a.UNPACK_SKIP_PIXELS,_),c.pixelStorei(a.UNPACK_SKIP_ROWS,x),c.pixelStorei(a.UNPACK_SKIP_IMAGES,y);const V=e.isDataArrayTexture||e.isData3DTexture||t.isArrayTexture,z=t.isDataArrayTexture||t.isData3DTexture||t.isArrayTexture;if(e.isDepthTexture){const U=l.get(e),B=l.get(t),D=l.get(U.renderTarget),X=l.get(B.renderTarget),K=D.framebuffers[U.cacheKey],fe=X.framebuffers[B.cacheKey];c.bindFramebuffer(a.READ_FRAMEBUFFER,K),c.bindFramebuffer(a.DRAW_FRAMEBUFFER,fe);for(let Z=0;Z<m;Z++)V&&(a.framebufferTextureLayer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,U.textureGPU,s,y+Z),a.framebufferTextureLayer(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,u,o,S+Z)),a.blitFramebuffer(_,x,p,g,b,M,p,g,a.DEPTH_BUFFER_BIT,a.NEAREST);c.bindFramebuffer(a.READ_FRAMEBUFFER,null),c.bindFramebuffer(a.DRAW_FRAMEBUFFER,null)}else if(s!==0||e.isRenderTargetTexture||l.has(e)){const U=l.get(e);this._srcFramebuffer===null&&(this._srcFramebuffer=a.createFramebuffer()),this._dstFramebuffer===null&&(this._dstFramebuffer=a.createFramebuffer()),c.bindFramebuffer(a.READ_FRAMEBUFFER,this._srcFramebuffer),c.bindFramebuffer(a.DRAW_FRAMEBUFFER,this._dstFramebuffer);for(let B=0;B<m;B++)V?a.framebufferTextureLayer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,U.textureGPU,s,y+B):a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,U.textureGPU,s),z?a.framebufferTextureLayer(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,u,o,S+B):a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,u,o),s!==0?a.blitFramebuffer(_,x,p,g,b,M,p,g,a.COLOR_BUFFER_BIT,a.NEAREST):z?a.copyTexSubImage3D(h,o,b,M,S+B,_,x,p,g):a.copyTexSubImage2D(h,o,b,M,_,x,p,g);c.bindFramebuffer(a.READ_FRAMEBUFFER,null),c.bindFramebuffer(a.DRAW_FRAMEBUFFER,null)}else z?e.isDataTexture||e.isData3DTexture?a.texSubImage3D(h,o,b,M,S,p,g,m,f,d,E.data):t.isCompressedArrayTexture?a.compressedTexSubImage3D(h,o,b,M,S,p,g,m,f,E.data):a.texSubImage3D(h,o,b,M,S,p,g,m,f,d,E):e.isDataTexture?a.texSubImage2D(a.TEXTURE_2D,o,b,M,p,g,f,d,E.data):e.isCompressedTexture?a.compressedTexSubImage2D(a.TEXTURE_2D,o,b,M,E.width,E.height,f,E.data):a.texSubImage2D(a.TEXTURE_2D,o,b,M,p,g,f,d,E);c.pixelStorei(a.UNPACK_ROW_LENGTH,v),c.pixelStorei(a.UNPACK_IMAGE_HEIGHT,w),c.pixelStorei(a.UNPACK_SKIP_PIXELS,N),c.pixelStorei(a.UNPACK_SKIP_ROWS,C),c.pixelStorei(a.UNPACK_SKIP_IMAGES,F),o===0&&t.generateMipmaps&&a.generateMipmap(h),c.unbindTexture()}copyFramebufferToTexture(e,t,n){const{gl:i}=this,{state:s}=this.backend,{textureGPU:o}=this.backend.get(e),{x:a,y:l,z:c,w:u}=n,h=e.isDepthTexture===!0||t.renderTarget&&t.renderTarget.samples>0,d=t.renderTarget?t.renderTarget.height:this.backend.getDrawingBufferSize().y;if(h){const f=a!==0||l!==0;let p,g;if(e.isDepthTexture===!0?(p=i.DEPTH_BUFFER_BIT,g=i.DEPTH_ATTACHMENT,t.stencil&&(p|=i.STENCIL_BUFFER_BIT)):(p=i.COLOR_BUFFER_BIT,g=i.COLOR_ATTACHMENT0),f){const m=this.backend.get(t.renderTarget),_=m.framebuffers[t.getCacheKey()],x=m.msaaFrameBuffer;s.bindFramebuffer(i.DRAW_FRAMEBUFFER,_),s.bindFramebuffer(i.READ_FRAMEBUFFER,x);const y=d-l-u;i.blitFramebuffer(a,y,a+c,y+u,a,y,a+c,y+u,p,i.NEAREST),s.bindFramebuffer(i.READ_FRAMEBUFFER,_),s.bindTexture(i.TEXTURE_2D,o),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,y,c,u),s.unbindTexture()}else{const m=i.createFramebuffer();s.bindFramebuffer(i.DRAW_FRAMEBUFFER,m),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,g,i.TEXTURE_2D,o,0),i.blitFramebuffer(0,0,c,u,0,0,c,u,p,i.NEAREST),i.deleteFramebuffer(m)}}else s.bindTexture(i.TEXTURE_2D,o),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,d-u-l,c,u),s.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t,n,i=!1){const{gl:s}=this,o=t.renderTarget,{depthTexture:a,depthBuffer:l,stencilBuffer:c,width:u,height:h}=o;if(s.bindRenderbuffer(s.RENDERBUFFER,e),l&&!c){let d=s.DEPTH_COMPONENT24;i===!0?this.extensions.get("WEBGL_multisampled_render_to_texture").renderbufferStorageMultisampleEXT(s.RENDERBUFFER,o.samples,d,u,h):n>0?(a&&a.isDepthTexture&&a.type===s.FLOAT&&(d=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,n,d,u,h)):s.renderbufferStorage(s.RENDERBUFFER,d,u,h),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else l&&c&&(n>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,n,s.DEPTH24_STENCIL8,u,h):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,h),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e));s.bindRenderbuffer(s.RENDERBUFFER,null)}async copyTextureToBuffer(e,t,n,i,s,o){const{backend:a,gl:l}=this,{textureGPU:c,glFormat:u,glType:h}=this.backend.get(e),d=l.createFramebuffer();a.state.bindFramebuffer(l.READ_FRAMEBUFFER,d);const f=e.isCubeTexture?l.TEXTURE_CUBE_MAP_POSITIVE_X+o:l.TEXTURE_2D;l.framebufferTexture2D(l.READ_FRAMEBUFFER,l.COLOR_ATTACHMENT0,f,c,0);const p=this._getTypedArrayType(h),g=this._getBytesPerTexel(h,u),_=i*s*g,x=l.createBuffer();l.bindBuffer(l.PIXEL_PACK_BUFFER,x),l.bufferData(l.PIXEL_PACK_BUFFER,_,l.STREAM_READ),l.readPixels(t,n,i,s,u,h,0),l.bindBuffer(l.PIXEL_PACK_BUFFER,null),await a.utils._clientWaitAsync();const y=new p(_/p.BYTES_PER_ELEMENT);return l.bindBuffer(l.PIXEL_PACK_BUFFER,x),l.getBufferSubData(l.PIXEL_PACK_BUFFER,0,y),l.bindBuffer(l.PIXEL_PACK_BUFFER,null),a.state.bindFramebuffer(l.READ_FRAMEBUFFER,null),l.deleteFramebuffer(d),y}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4||e===t.UNSIGNED_SHORT_5_5_5_1||e===t.UNSIGNED_SHORT_5_6_5||e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:n}=this;let i=0;if(e===n.UNSIGNED_BYTE&&(i=1),(e===n.UNSIGNED_SHORT_4_4_4_4||e===n.UNSIGNED_SHORT_5_5_5_1||e===n.UNSIGNED_SHORT_5_6_5||e===n.UNSIGNED_SHORT||e===n.HALF_FLOAT)&&(i=2),(e===n.UNSIGNED_INT||e===n.FLOAT)&&(i=4),t===n.RGBA)return i*4;if(t===n.RGB)return i*3;if(t===n.ALPHA)return i}dispose(){const{gl:e}=this;this._srcFramebuffer!==null&&e.deleteFramebuffer(this._srcFramebuffer),this._dstFramebuffer!==null&&e.deleteFramebuffer(this._dstFramebuffer)}}function Zu(r){return r.isDataTexture?r.image.data:typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&r instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&r instanceof OffscreenCanvas?r:r.data}class RB{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return t===void 0&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class CB{constructor(e){this.backend=e,this.maxAnisotropy=null,this.maxUniformBlockSize=null}getMaxAnisotropy(){if(this.maxAnisotropy!==null)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(t.has("EXT_texture_filter_anisotropic")===!0){const n=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}getUniformBufferLimit(){if(this.maxUniformBlockSize!==null)return this.maxUniformBlockSize;const e=this.backend.gl;return this.maxUniformBlockSize=e.getParameter(e.MAX_UNIFORM_BLOCK_SIZE),this.maxUniformBlockSize}}const p0={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-s3tc",EXT_texture_compression_bptc:"texture-compression-bc",EXT_disjoint_timer_query_webgl2:"timestamp-query",OVR_multiview2:"OVR_multiview2"};class NB{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:n,mode:i,object:s,type:o,info:a,index:l}=this;l!==0?n.drawElements(i,t,o,e):n.drawArrays(i,e,t),a.update(s,t,1)}renderInstances(e,t,n){const{gl:i,mode:s,type:o,index:a,object:l,info:c}=this;n!==0&&(a!==0?i.drawElementsInstanced(s,t,o,e,n):i.drawArraysInstanced(s,e,t,n),c.update(l,t,n))}renderMultiDraw(e,t,n){const{extensions:i,mode:s,object:o,info:a}=this;if(n===0)return;const l=i.get("WEBGL_multi_draw");if(l===null)for(let c=0;c<n;c++)this.render(e[c],t[c]);else{this.index!==0?l.multiDrawElementsWEBGL(s,t,0,this.type,e,0,n):l.multiDrawArraysWEBGL(s,e,0,t,0,n);let c=0;for(let u=0;u<n;u++)c+=t[u];a.update(o,c,1)}}}class Hb{constructor(e=256){this.trackTimestamp=!0,this.maxQueries=e,this.currentQueryIndex=0,this.queryOffsets=new Map,this.isDisposed=!1,this.lastValue=0,this.frames=[],this.pendingResolve=!1,this.timestamps=new Map}getTimestampFrames(){return this.frames}getTimestamp(e){let t=this.timestamps.get(e);return t===void 0&&(ae(`TimestampQueryPool: No timestamp available for uid ${e}.`),t=0),t}hasTimestamp(e){return this.timestamps.has(e)}allocateQueriesForContext(){}async resolveQueriesAsync(){}dispose(){}}class PB extends Hb{constructor(e,t,n=2048){if(super(n),this.gl=e,this.type=t,this.ext=e.getExtension("EXT_disjoint_timer_query_webgl2")||e.getExtension("EXT_disjoint_timer_query"),!this.ext){ae("EXT_disjoint_timer_query not supported; timestamps will be disabled."),this.trackTimestamp=!1;return}this.queries=[];for(let i=0;i<this.maxQueries;i++)this.queries.push(e.createQuery());this.activeQuery=null,this.queryStates=new Map}allocateQueriesForContext(e){if(!this.trackTimestamp)return null;if(this.currentQueryIndex+2>this.maxQueries)return Kt(`WebGLTimestampQueryPool [${this.type}]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${this.type.toUpperCase()} ).`),null;const t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryStates.set(t,"inactive"),this.queryOffsets.set(e,t),t}beginQuery(e){if(!this.trackTimestamp||this.isDisposed)return;const t=this.queryOffsets.get(e);if(t==null||this.activeQuery!==null)return;const n=this.queries[t];if(n)try{this.queryStates.get(t)==="inactive"&&(this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT,n),this.activeQuery=t,this.queryStates.set(t,"started"))}catch(i){ce("Error in beginQuery:",i),this.activeQuery=null,this.queryStates.set(t,"inactive")}}endQuery(e){if(!this.trackTimestamp||this.isDisposed)return;const t=this.queryOffsets.get(e);if(t!=null&&this.activeQuery===t)try{this.gl.endQuery(this.ext.TIME_ELAPSED_EXT),this.queryStates.set(t,"ended"),this.activeQuery=null}catch(n){ce("Error in endQuery:",n),this.queryStates.set(t,"inactive"),this.activeQuery=null}}async resolveQueriesAsync(){if(!this.trackTimestamp||this.pendingResolve)return this.lastValue;this.pendingResolve=!0;try{const e=new Map;for(const[s,o]of this.queryOffsets)if(this.queryStates.get(o)==="ended"){const l=this.queries[o];e.set(s,this.resolveQuery(l))}if(e.size===0)return this.lastValue;const t={},n=[];for(const[s,o]of e){const a=s.match(/^(.*):f(\d+)$/),l=parseInt(a[2]);n.includes(l)===!1&&n.push(l),t[l]===void 0&&(t[l]=0);const c=await o;this.timestamps.set(s,c),t[l]+=c}const i=t[n[n.length-1]];return this.lastValue=i,this.frames=n,this.currentQueryIndex=0,this.queryOffsets.clear(),this.queryStates.clear(),this.activeQuery=null,i}catch(e){return ce("Error resolving queries:",e),this.lastValue}finally{this.pendingResolve=!1}}async resolveQuery(e){return new Promise(t=>{if(this.isDisposed){t(this.lastValue);return}let n,i=!1;const s=()=>{n&&(clearTimeout(n),n=null)},o=l=>{i||(i=!0,s(),t(l))},a=()=>{if(this.isDisposed){o(this.lastValue);return}try{if(this.gl.getParameter(this.ext.GPU_DISJOINT_EXT)){o(this.lastValue);return}if(!this.gl.getQueryParameter(e,this.gl.QUERY_RESULT_AVAILABLE)){n=setTimeout(a,1);return}const u=this.gl.getQueryParameter(e,this.gl.QUERY_RESULT);t(Number(u)/1e6)}catch(l){ce("Error checking query:",l),t(this.lastValue)}};a()})}dispose(){if(!this.isDisposed&&(this.isDisposed=!0,!!this.trackTimestamp)){for(const e of this.queries)this.gl.deleteQuery(e);this.queries=[],this.queryStates.clear(),this.queryOffsets.clear(),this.lastValue=0,this.activeQuery=null}}}class m0 extends zb{constructor(e={}){super(e),this.isWebGLBackend=!0,this.attributeUtils=null,this.extensions=null,this.capabilities=null,this.textureUtils=null,this.bufferRenderer=null,this.gl=null,this.state=null,this.utils=null,this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.disjoint=null,this.parallel=null,this._currentContext=null,this._knownBindings=new WeakSet,this._supportsInvalidateFramebuffer=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),this._xrFramebuffer=null}init(e){super.init(e);const t=this.parameters,n={antialias:e.currentSamples>0,alpha:!0,depth:e.depth,stencil:e.stencil},i=t.context!==void 0?t.context:e.domElement.getContext("webgl2",n);function s(o){o.preventDefault();const a={api:"WebGL",message:o.statusMessage||"Unknown reason",reason:null,originalEvent:o};e.onDeviceLost(a)}this._onContextLost=s,e.domElement.addEventListener("webglcontextlost",s,!1),this.gl=i,this.extensions=new RB(this),this.capabilities=new CB(this),this.attributeUtils=new MB(this),this.textureUtils=new wB(this),this.bufferRenderer=new NB(this),this.state=new EB(this),this.utils=new AB(this),this.extensions.get("EXT_color_buffer_float"),this.extensions.get("WEBGL_clip_cull_distance"),this.extensions.get("OES_texture_float_linear"),this.extensions.get("EXT_color_buffer_half_float"),this.extensions.get("WEBGL_multisampled_render_to_texture"),this.extensions.get("WEBGL_render_shared_exponent"),this.extensions.get("WEBGL_multi_draw"),this.extensions.get("OVR_multiview2"),this.extensions.get("EXT_clip_control"),this.disjoint=this.extensions.get("EXT_disjoint_timer_query_webgl2"),this.parallel=this.extensions.get("KHR_parallel_shader_compile"),this.drawBuffersIndexedExt=this.extensions.get("OES_draw_buffers_indexed"),t.reversedDepthBuffer&&(this.extensions.has("EXT_clip_control")?e.reversedDepthBuffer=!0:(ae("WebGPURenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer."),e.reversedDepthBuffer=!1)),e.reversedDepthBuffer&&this.state.setReversedDepth(!0)}get coordinateSystem(){return ii}async getArrayBufferAsync(e,t=null,n=0,i=-1){return await this.attributeUtils.getArrayBufferAsync(e,t,n,i)}async makeXRCompatible(){this.gl.getContextAttributes().xrCompatible!==!0&&await this.gl.makeXRCompatible()}setXRTarget(e){this._xrFramebuffer=e}setXRRenderTargetTextures(e,t,n=null){const i=this.gl;if(this.set(e.texture,{textureGPU:t,glInternalFormat:i.RGBA8}),n!==null){const s=e.stencilBuffer?i.DEPTH24_STENCIL8:i.DEPTH_COMPONENT24;this.set(e.depthTexture,{textureGPU:n,glInternalFormat:s}),this.extensions.has("WEBGL_multisampled_render_to_texture")===!0&&e._autoAllocateDepthBuffer===!0&&e.multiview===!1&&ae("WebGLBackend: Render-to-texture extension was disabled because an external texture was provided"),e._autoAllocateDepthBuffer=!1}}initTimestampQuery(e,t){if(!this.disjoint||!this.trackTimestamp)return;this.timestampQueryPool[e]||(this.timestampQueryPool[e]=new PB(this.gl,e,2048));const n=this.timestampQueryPool[e];n.allocateQueriesForContext(t)!==null&&n.beginQuery(t)}prepareTimestampBuffer(e,t){if(!this.disjoint||!this.trackTimestamp)return;this.timestampQueryPool[e].endQuery(t)}getContext(){return this.gl}beginRender(e){const{state:t}=this,n=this.get(e);if(e.viewport)this.updateViewport(e);else{const{width:s,height:o}=this.getDrawingBufferSize();t.viewport(0,0,s,o)}if(e.scissor)this.updateScissor(e);else{const{width:s,height:o}=this.getDrawingBufferSize();t.scissor(0,0,s,o)}this.initTimestampQuery(xr.RENDER,this.getTimestampUID(e)),n.previousContext=this._currentContext,this._currentContext=e,this._setFramebuffer(e),this.clear(e.clearColor,e.clearDepth,e.clearStencil,e,!1);const i=e.occlusionQueryCount;i>0&&(n.currentOcclusionQueries=n.occlusionQueries,n.currentOcclusionQueryObjects=n.occlusionQueryObjects,n.lastOcclusionObject=null,n.occlusionQueries=new Array(i),n.occlusionQueryObjects=new Array(i),n.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:n}=this,i=this.get(e),s=i.previousContext;n.resetVertexState();const o=e.occlusionQueryCount;o>0&&(o>i.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const a=e.textures;if(a!==null)for(let l=0;l<a.length;l++){const c=a[l];c.generateMipmaps&&this.generateMipmaps(c)}if(this._currentContext=s,this._resolveRenderTarget(e),s!==null){if(this._setFramebuffer(s),s.viewport)this.updateViewport(s);else{const{width:l,height:c}=this.getDrawingBufferSize();n.viewport(0,0,l,c)}if(s.scissor)this.updateScissor(s);else{const{width:l,height:c}=this.getDrawingBufferSize();n.scissor(0,0,l,c)}}this.prepareTimestampBuffer(xr.RENDER,this.getTimestampUID(e))}resolveOccludedAsync(e){const t=this.get(e),{currentOcclusionQueries:n,currentOcclusionQueryObjects:i}=t;if(n&&i){const s=new WeakSet,{gl:o}=this;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueries=null;const a=()=>{let l=0;for(let c=0;c<n.length;c++){const u=n[c];u!==null&&o.getQueryParameter(u,o.QUERY_RESULT_AVAILABLE)&&(o.getQueryParameter(u,o.QUERY_RESULT)===0&&s.add(i[c]),n[c]=null,o.deleteQuery(u),l++)}l<n.length?requestAnimationFrame(a):t.occluded=s};a()}}isOccluded(e,t){const n=this.get(e);return n.occluded&&n.occluded.has(t)}updateViewport(e){const{state:t}=this,{x:n,y:i,width:s,height:o}=e.viewportValue;t.viewport(n,e.height-o-i,s,o)}updateScissor(e){const{state:t}=this,{x:n,y:i,width:s,height:o}=e.scissorValue;t.scissor(n,e.height-o-i,s,o)}setScissorTest(e){this.state.setScissorTest(e)}getClearColor(){const e=super.getClearColor();return e.r*=e.a,e.g*=e.a,e.b*=e.a,e}clear(e,t,n,i=null,s=!0,o=!0){const{gl:a,renderer:l}=this;i===null&&(i={textures:null,clearColorValue:this.getClearColor()});let c=0;if(e&&(c|=a.COLOR_BUFFER_BIT),t&&(c|=a.DEPTH_BUFFER_BIT),n&&(c|=a.STENCIL_BUFFER_BIT),c!==0){let u;i.clearColorValue?u=i.clearColorValue:u=this.getClearColor();const h=l.getClearDepth(),d=l.getClearStencil();if(t&&this.state.setDepthMask(!0),i.textures===null)a.clearColor(u.r,u.g,u.b,u.a),a.clear(c);else{if(s&&this._setFramebuffer(i),e)for(let f=0;f<i.textures.length;f++)f===0?a.clearBufferfv(a.COLOR,f,[u.r,u.g,u.b,u.a]):a.clearBufferfv(a.COLOR,f,[0,0,0,1]);t&&n?a.clearBufferfi(a.DEPTH_STENCIL,0,h,d):t?a.clearBufferfv(a.DEPTH,0,[h]):n&&a.clearBufferiv(a.STENCIL,0,[d]),s&&o&&this._resolveRenderTarget(i)}}}beginCompute(e){const{state:t,gl:n}=this;t.bindFramebuffer(n.FRAMEBUFFER,null),this.initTimestampQuery(xr.COMPUTE,this.getTimestampUID(e))}compute(e,t,n,i,s=null){const{state:o,gl:a}=this;this.discard===!1&&(o.enable(a.RASTERIZER_DISCARD),this.discard=!0);const{programGPU:l,transformBuffers:c,attributes:u}=this.get(i),h=this._getVaoKey(u),d=this.vaoCache[h];d===void 0?this.vaoCache[h]=this._createVao(u):o.setVertexState(d),o.useProgram(l),this._bindUniforms(n);const f=this._getTransformFeedback(c);a.bindTransformFeedback(a.TRANSFORM_FEEDBACK,f),a.beginTransformFeedback(a.POINTS),s=s!==null?s:t.count,Array.isArray(s)?(Kt("WebGLBackend.compute(): The count parameter must be a single number, not an array."),s=s[0]):s&&typeof s=="object"&&s.isIndirectStorageBufferAttribute&&(Kt("WebGLBackend.compute(): The count parameter must be a single number, not IndirectStorageBufferAttribute"),s=t.count),u[0].isStorageInstancedBufferAttribute?a.drawArraysInstanced(a.POINTS,0,1,s):a.drawArrays(a.POINTS,0,s),a.endTransformFeedback(),a.bindTransformFeedback(a.TRANSFORM_FEEDBACK,null);for(let p=0;p<c.length;p++){const g=c[p];g.pbo&&this.has(g.pbo)&&this.textureUtils.copyBufferToTexture(g.transformBuffer,g.pbo),g.switchBuffers()}}finishCompute(e){const{state:t,gl:n}=this;this.discard=!1,t.disable(n.RASTERIZER_DISCARD),this.prepareTimestampBuffer(xr.COMPUTE,this.getTimestampUID(e)),this._currentContext&&this._setFramebuffer(this._currentContext)}_isRenderCameraDepthArray(e){return e.depthTexture&&e.depthTexture.isArrayTexture&&e.camera.isArrayCamera}_draw(e,t,n,i,s,o){if(e.isBatchedMesh)if(this.hasFeature("WEBGL_multi_draw")===!1){const{gl:a}=this,l=a.getUniformLocation(o,"nodeUniformDrawId"),c=e._multiDrawStarts,u=e._multiDrawCounts,h=e._multiDrawCount;for(let d=0;d<h;d++)a.uniform1ui(l,d),t.render(c[d],u[d])}else t.renderMultiDraw(e._multiDrawStarts,e._multiDrawCounts,e._multiDrawCount);else s>1?t.renderInstances(n,i,s):t.render(n,i)}draw(e){const{object:t,pipeline:n,material:i,context:s,hardwareClippingPlanes:o}=e,{programGPU:a}=this.get(n),{gl:l,state:c}=this,u=this.get(s),h=e.getDrawParameters();if(h===null)return;this._bindUniforms(e.getBindings());const d=t.isMesh&&t.matrixWorld.determinant()<0;c.setMaterial(i,d,o),s.mrt!==null&&s.textures!==null&&c.setMRTBlending(s.textures,s.mrt,i),c.useProgram(a);const f=e.getAttributes(),p=this.get(f);let g=p.vaoGPU;if(g===void 0){const E=this._getVaoKey(f);g=this.vaoCache[E],g===void 0&&(g=this._createVao(f),this.vaoCache[E]=g,p.vaoGPU=g)}const m=e.getIndex(),_=m!==null?this.get(m).bufferGPU:null;c.setVertexState(g,_);const x=u.lastOcclusionObject;if(x!==t&&x!==void 0){if(x!==null&&x.occlusionTest===!0&&(l.endQuery(l.ANY_SAMPLES_PASSED),u.occlusionQueryIndex++),t.occlusionTest===!0){const E=l.createQuery();l.beginQuery(l.ANY_SAMPLES_PASSED,E),u.occlusionQueries[u.occlusionQueryIndex]=E,u.occlusionQueryObjects[u.occlusionQueryIndex]=t}u.lastOcclusionObject=t}const y=this.bufferRenderer;t.isPoints?y.mode=l.POINTS:t.isLineSegments?y.mode=l.LINES:t.isLine?y.mode=l.LINE_STRIP:t.isLineLoop?y.mode=l.LINE_LOOP:i.wireframe===!0?(c.setLineWidth(i.wireframeLinewidth*this.renderer.getPixelRatio()),y.mode=l.LINES):y.mode=l.TRIANGLES;const{vertexCount:b,instanceCount:M}=h;let{firstVertex:S}=h;if(y.object=t,m!==null){S*=m.array.BYTES_PER_ELEMENT;const E=this.get(m);y.index=m.count,y.type=E.type}else y.index=0;if(e.camera.isArrayCamera===!0&&e.camera.cameras.length>0&&e.camera.isMultiViewCamera===!1){const E=this.get(e.camera),v=e.camera.cameras,w=e.getBindingGroup("cameraIndex").bindings[0];if(E.indexesGPU===void 0||E.indexesGPU.length!==v.length){const U=new Uint32Array([0,0,0,0]),B=[];for(let D=0,X=v.length;D<X;D++){const K=l.createBuffer();U[0]=D,l.bindBuffer(l.UNIFORM_BUFFER,K),l.bufferData(l.UNIFORM_BUFFER,U,l.STATIC_DRAW),B.push(K)}E.indexesGPU=B}let N=0;e:for(const U of e.getBindings())for(const B of U.bindings){if(B===w)break e;(B.isUniformsGroup||B.isUniformBuffer)&&N++}const C=this.renderer.getPixelRatio(),F=this._currentContext.renderTarget,V=this._isRenderCameraDepthArray(this._currentContext),z=this._currentContext.activeCubeFace;if(V){const U=this.get(F.depthTexture);if(U.clearedRenderId!==this.renderer._nodes.nodeFrame.renderId){U.clearedRenderId=this.renderer._nodes.nodeFrame.renderId;const{stencilBuffer:B}=F;for(let D=0,X=v.length;D<X;D++)this.renderer._activeCubeFace=D,this._currentContext.activeCubeFace=D,this._setFramebuffer(this._currentContext),this.clear(!1,!0,B,this._currentContext,!1,!1);this.renderer._activeCubeFace=z,this._currentContext.activeCubeFace=z}}for(let U=0,B=v.length;U<B;U++){const D=v[U];if(t.layers.test(D.layers)){V&&(this.renderer._activeCubeFace=U,this._currentContext.activeCubeFace=U,this._setFramebuffer(this._currentContext));const X=D.viewport;if(X!==void 0){const K=X.x*C,fe=X.y*C,Z=X.width*C,oe=X.height*C;c.viewport(Math.floor(K),Math.floor(e.context.height-oe-fe),Math.floor(Z),Math.floor(oe))}c.bindBufferBase(l.UNIFORM_BUFFER,N,E.indexesGPU[U]),this._draw(t,y,S,b,M,a)}this._currentContext.activeCubeFace=z,this.renderer._activeCubeFace=z}}else this._draw(t,y,S,b,M,a)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e,t=!1){this.textureUtils.destroyTexture(e,t)}async copyTextureToBuffer(e,t,n,i,s,o){return this.textureUtils.copyTextureToBuffer(e,t,n,i,s,o)}updateSampler(){return""}createNodeBuilder(e,t){return new bB(e,t)}createProgram(e){const t=this.gl,{stage:n,code:i}=e,s=n==="fragment"?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(s,i),t.compileShader(s),this.set(e,{shaderGPU:s})}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){const n=this.gl,i=e.pipeline,{fragmentProgram:s,vertexProgram:o}=i,a=n.createProgram(),l=this.get(s).shaderGPU,c=this.get(o).shaderGPU;if(n.attachShader(a,l),n.attachShader(a,c),n.linkProgram(a),this.set(i,{programGPU:a,fragmentShader:l,vertexShader:c}),t!==null&&this.parallel){const u=new Promise(h=>{const d=this.parallel,f=()=>{n.getProgramParameter(a,d.COMPLETION_STATUS_KHR)?(this._completeCompile(e,i),h()):requestAnimationFrame(f)};f()});t.push(u);return}this._completeCompile(e,i)}_handleSource(e,t){const n=e.split(`
4790
+ `)}}this.material!==null?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,n,i=null){const s=super.getUniformFromNode(e,t,n,i),o=this.getDataFromNode(e,n,this.globalCache);let a=o.uniformGPU;if(a===void 0){const l=e.groupNode,c=l.name,u=this.getBindGroupArray(c,n);if(t==="texture")a=new td(s.name,s.node,l),u.push(a);else if(t==="cubeTexture"||t==="cubeDepthTexture")a=new Vb(s.name,s.node,l),u.push(a);else if(t==="texture3D")a=new Cp(s.name,s.node,l),u.push(a);else if(t==="buffer"){s.name=`buffer${e.id}`;const h=this.getSharedDataFromNode(e);let d=h.buffer;d===void 0&&(e.name=`NodeBuffer_${e.id}`,d=new Ob(e,l),d.name=e.name,h.buffer=d),u.push(d),a=d}else{let h=this.uniformGroups[c];h===void 0?(h=new kb(c,l),this.uniformGroups[c]=h,u.push(h)):u.indexOf(h)===-1&&u.push(h),a=this.getNodeUniform(s,t);const d=a.name;h.uniforms.some(p=>p.name===d)||h.addUniform(a)}o.uniformGPU=a}return s}}let kf=null,aa=null;class zb{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null,this.timestampQueryPool={[xr.RENDER]:null,[xr.COMPUTE]:null},this.trackTimestamp=e.trackTimestamp===!0}async init(e){this.renderer=e}get coordinateSystem(){}beginRender(){}finishRender(){}beginCompute(){}finishCompute(){}draw(){}compute(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}updateBinding(){}createRenderPipeline(){}createComputePipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}updateSampler(){}createDefaultTexture(){}createTexture(){}updateTexture(){}generateMipmaps(){}destroyTexture(){}async copyTextureToBuffer(){}copyTextureToTexture(){}copyFramebufferToTexture(){}createAttribute(){}createIndexAttribute(){}createStorageAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}updateViewport(){}updateTimeStampUID(e){const t=this.get(e),n=this.renderer.info.frame;let i;e.isComputeNode===!0?i="c:"+this.renderer.info.compute.frameCalls:i="r:"+this.renderer.info.render.frameCalls,t.timestampUID=i+":"+e.id+":f"+n}getTimestampUID(e){return this.get(e).timestampUID}getTimestampFrames(e){const t=this.timestampQueryPool[e];return t?t.getTimestampFrames():[]}_getQueryPool(e){const t=e.startsWith("c:")?xr.COMPUTE:xr.RENDER;return this.timestampQueryPool[t]}getTimestamp(e){return this._getQueryPool(e).getTimestamp(e)}hasTimestamp(e){return this._getQueryPool(e).hasTimestamp(e)}isOccluded(){}async resolveTimestampsAsync(e="render"){if(!this.trackTimestamp){Kt("WebGPURenderer: Timestamp tracking is disabled.");return}const t=this.timestampQueryPool[e];if(!t)return;const n=await t.resolveQueriesAsync();return this.renderer.info[e].timestamp=n,n}async getArrayBufferAsync(){}async hasFeatureAsync(){}hasFeature(){}getDrawingBufferSize(){return kf=kf||new pe,this.renderer.getDrawingBufferSize(kf)}setScissorTest(){}getClearColor(){const e=this.renderer;return aa=aa||new jm,e.getClearColor(aa),aa.getRGB(aa),aa}getDomElement(){let e=this.domElement;return e===null&&(e=this.parameters.canvas!==void 0?this.parameters.canvas:K0(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${Mo} webgpu`),this.domElement=e),e}hasCompatibility(){return!1}initRenderTarget(){}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}deleteBindGroupData(){}dispose(){}}let SB=0;class TB{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[this.activeBufferIndex^1]}switchBuffers(){this.activeBufferIndex^=1}}class MB{constructor(e){this.backend=e}createAttribute(e,t){const n=this.backend,{gl:i}=n,s=e.array,o=e.usage||i.STATIC_DRAW,a=e.isInterleavedBufferAttribute?e.data:e,l=n.get(a);let c=l.bufferGPU;c===void 0&&(c=this._createBuffer(i,t,s,o),l.bufferGPU=c,l.bufferType=t,l.version=a.version);let u;if(s instanceof Float32Array)u=i.FLOAT;else if(typeof Float16Array<"u"&&s instanceof Float16Array)u=i.HALF_FLOAT;else if(s instanceof Uint16Array)e.isFloat16BufferAttribute?u=i.HALF_FLOAT:u=i.UNSIGNED_SHORT;else if(s instanceof Int16Array)u=i.SHORT;else if(s instanceof Uint32Array)u=i.UNSIGNED_INT;else if(s instanceof Int32Array)u=i.INT;else if(s instanceof Int8Array)u=i.BYTE;else if(s instanceof Uint8Array)u=i.UNSIGNED_BYTE;else if(s instanceof Uint8ClampedArray)u=i.UNSIGNED_BYTE;else throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+s);let h={bufferGPU:c,bufferType:t,type:u,byteLength:s.byteLength,bytesPerElement:s.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===i.INT||u===i.UNSIGNED_INT||e.gpuType===Sn,id:SB++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const d=this._createBuffer(i,t,s,o);h=new TB(h,d)}n.set(e,h)}updateAttribute(e){const t=this.backend,{gl:n}=t,i=e.array,s=e.isInterleavedBufferAttribute?e.data:e,o=t.get(s),a=o.bufferType,l=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(n.bindBuffer(a,o.bufferGPU),l.length===0)n.bufferSubData(a,0,i);else{for(let c=0,u=l.length;c<u;c++){const h=l[c];n.bufferSubData(a,h.start*i.BYTES_PER_ELEMENT,i,h.start,h.count)}s.clearUpdateRanges()}n.bindBuffer(a,null),o.version=s.version}destroyAttribute(e){const t=this.backend,{gl:n}=t;e.isInterleavedBufferAttribute&&t.delete(e.data);const i=t.get(e);n.deleteBuffer(i.bufferGPU),t.delete(e)}async getArrayBufferAsync(e,t=null,n=0,i=-1){const s=this.backend,{gl:o}=s,a=e.isInterleavedBufferAttribute?e.data:e,l=s.get(a),{bufferGPU:c}=l,u=i===-1?l.byteLength-n:i;let h;if(t===null)h=new Uint8Array(new ArrayBuffer(u));else if(t.isReadbackBuffer){if(t._mapped===!0)throw new Error("WebGPURenderer: ReadbackBuffer must be released before being used again.");const d=()=>{t.buffer=null,t._mapped=!1,t.removeEventListener("release",d),t.removeEventListener("dispose",d)};t.addEventListener("release",d),t.addEventListener("dispose",d),h=new Uint8Array(new ArrayBuffer(u)),t.buffer=h.buffer}else h=new Uint8Array(t);return o.bindBuffer(o.COPY_READ_BUFFER,c),o.getBufferSubData(o.COPY_READ_BUFFER,n,h),o.bindBuffer(o.COPY_READ_BUFFER,null),o.bindBuffer(o.COPY_WRITE_BUFFER,null),t&&t.isReadbackBuffer?t:h.buffer}_createBuffer(e,t,n,i){const s=e.createBuffer();return e.bindBuffer(t,s),e.bufferData(t,n,i),e.bindBuffer(t,null),s}}let Vl,Or;class EB{constructor(e){this.backend=e,this.gl=this.backend.gl,this.enabled={},this.parameters={},this.currentFlipSided=null,this.currentCullFace=null,this.currentProgram=null,this.currentBlendingEnabled=!1,this.currentBlending=null,this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentPremultipledAlpha=null,this.currentPolygonOffsetFactor=null,this.currentPolygonOffsetUnits=null,this.currentColorMask=null,this.currentDepthReversed=!1,this.currentDepthFunc=null,this.currentDepthMask=null,this.currentStencilFunc=null,this.currentStencilRef=null,this.currentStencilFuncMask=null,this.currentStencilFail=null,this.currentStencilZFail=null,this.currentStencilZPass=null,this.currentStencilMask=null,this.currentLineWidth=null,this.currentClippingPlanes=0,this.currentVAO=null,this.currentIndex=null,this.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.currentTextureSlot=null,this.currentBoundTextures={},this.currentBoundBufferBases={},this._init()}_init(){const e=this.gl;Vl={[Xn]:e.FUNC_ADD,[Bp]:e.FUNC_SUBTRACT,[Op]:e.FUNC_REVERSE_SUBTRACT},Or={[Gr]:e.ZERO,[kp]:e.ONE,[Gp]:e.SRC_COLOR,[oc]:e.SRC_ALPHA,[Xp]:e.SRC_ALPHA_SATURATE,[Wp]:e.DST_COLOR,[zp]:e.DST_ALPHA,[Vp]:e.ONE_MINUS_SRC_COLOR,[ac]:e.ONE_MINUS_SRC_ALPHA,[$p]:e.ONE_MINUS_DST_COLOR,[Hp]:e.ONE_MINUS_DST_ALPHA};const t=e.getParameter(e.SCISSOR_BOX),n=e.getParameter(e.VIEWPORT);this.currentScissor=new rt().fromArray(t),this.currentViewport=new rt().fromArray(n),this._tempVec4=new rt}enable(e){const{enabled:t}=this;t[e]!==!0&&(this.gl.enable(e),t[e]=!0)}disable(e){const{enabled:t}=this;t[e]!==!1&&(this.gl.disable(e),t[e]=!1)}setFlipSided(e){if(this.currentFlipSided!==e){const{gl:t}=this;e?t.frontFace(t.CW):t.frontFace(t.CCW),this.currentFlipSided=e}}setCullFace(e){const{gl:t}=this;e!==O0?(this.enable(t.CULL_FACE),e!==this.currentCullFace&&(e===Jf?t.cullFace(t.BACK):e===k0?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):this.disable(t.CULL_FACE),this.currentCullFace=e}setLineWidth(e){const{currentLineWidth:t,gl:n}=this;e!==t&&(n.lineWidth(e),this.currentLineWidth=e)}setMRTBlending(e,t,n){const i=this.gl,s=this.backend.drawBuffersIndexedExt;if(!s){Kt("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets.");return}for(let o=0;o<e.length;o++){const a=e[o];let l=null;if(t!==null){const c=t.getBlendMode(a.name);c.blending===V0?l=n:c.blending!==Pn&&(l=c)}else l=n;l!==null?this._setMRTBlendingIndex(o,l):s.blendFuncSeparateiOES(o,i.ONE,i.ZERO,i.ONE,i.ZERO)}}_setMRTBlendingIndex(e,t){const{gl:n}=this,i=this.backend.drawBuffersIndexedExt,s=t.blending,o=t.blendSrc,a=t.blendDst,l=t.blendEquation,c=t.premultipliedAlpha;if(s===co){const u=t.blendSrcAlpha!==null?t.blendSrcAlpha:o,h=t.blendDstAlpha!==null?t.blendDstAlpha:a,d=t.blendEquationAlpha!==null?t.blendEquationAlpha:l;i.blendEquationSeparateiOES(e,Vl[l],Vl[d]),i.blendFuncSeparateiOES(e,Or[o],Or[a],Or[u],Or[h])}else if(i.blendEquationSeparateiOES(e,n.FUNC_ADD,n.FUNC_ADD),c)switch(s){case ti:i.blendFuncSeparateiOES(e,n.ONE,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA);break;case _s:i.blendFuncSeparateiOES(e,n.ONE,n.ONE,n.ONE,n.ONE);break;case xs:i.blendFuncSeparateiOES(e,n.ZERO,n.ONE_MINUS_SRC_COLOR,n.ZERO,n.ONE);break;case ys:i.blendFuncSeparateiOES(e,n.DST_COLOR,n.ONE_MINUS_SRC_ALPHA,n.ZERO,n.ONE);break;default:i.blendFuncSeparateiOES(e,n.ONE,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA);break}else switch(s){case ti:i.blendFuncSeparateiOES(e,n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA);break;case _s:i.blendFuncSeparateiOES(e,n.SRC_ALPHA,n.ONE,n.ONE,n.ONE);break;case xs:i.blendFuncSeparateiOES(e,n.ZERO,n.ONE_MINUS_SRC_COLOR,n.ZERO,n.ONE);break;case ys:i.blendFuncSeparateiOES(e,n.DST_COLOR,n.ONE_MINUS_SRC_ALPHA,n.ZERO,n.ONE);break;default:i.blendFuncSeparateiOES(e,n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA);break}}setBlending(e,t,n,i,s,o,a,l){const{gl:c}=this;if(e===Pn){this.currentBlendingEnabled===!0&&(this.disable(c.BLEND),this.currentBlendingEnabled=!1);return}if(this.currentBlendingEnabled===!1&&(this.enable(c.BLEND),this.currentBlendingEnabled=!0),e!==co){if(e!==this.currentBlending||l!==this.currentPremultipledAlpha){if((this.currentBlendEquation!==Xn||this.currentBlendEquationAlpha!==Xn)&&(c.blendEquation(c.FUNC_ADD),this.currentBlendEquation=Xn,this.currentBlendEquationAlpha=Xn),l)switch(e){case ti:c.blendFuncSeparate(c.ONE,c.ONE_MINUS_SRC_ALPHA,c.ONE,c.ONE_MINUS_SRC_ALPHA);break;case _s:c.blendFunc(c.ONE,c.ONE);break;case xs:c.blendFuncSeparate(c.ZERO,c.ONE_MINUS_SRC_COLOR,c.ZERO,c.ONE);break;case ys:c.blendFuncSeparate(c.DST_COLOR,c.ONE_MINUS_SRC_ALPHA,c.ZERO,c.ONE);break;default:ce("WebGLState: Invalid blending: ",e);break}else switch(e){case ti:c.blendFuncSeparate(c.SRC_ALPHA,c.ONE_MINUS_SRC_ALPHA,c.ONE,c.ONE_MINUS_SRC_ALPHA);break;case _s:c.blendFuncSeparate(c.SRC_ALPHA,c.ONE,c.ONE,c.ONE);break;case xs:ce("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case ys:ce("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:ce("WebGLState: Invalid blending: ",e);break}this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlending=e,this.currentPremultipledAlpha=l}return}s=s||t,o=o||n,a=a||i,(t!==this.currentBlendEquation||s!==this.currentBlendEquationAlpha)&&(c.blendEquationSeparate(Vl[t],Vl[s]),this.currentBlendEquation=t,this.currentBlendEquationAlpha=s),(n!==this.currentBlendSrc||i!==this.currentBlendDst||o!==this.currentBlendSrcAlpha||a!==this.currentBlendDstAlpha)&&(c.blendFuncSeparate(Or[n],Or[i],Or[o],Or[a]),this.currentBlendSrc=n,this.currentBlendDst=i,this.currentBlendSrcAlpha=o,this.currentBlendDstAlpha=a),this.currentBlending=e,this.currentPremultipledAlpha=!1}setColorMask(e){this.currentColorMask!==e&&(this.gl.colorMask(e,e,e,e),this.currentColorMask=e)}setDepthTest(e){const{gl:t}=this;e?this.enable(t.DEPTH_TEST):this.disable(t.DEPTH_TEST)}setReversedDepth(e){if(this.currentDepthReversed!==e){const t=this.backend.extensions.get("EXT_clip_control");e?t.clipControlEXT(t.LOWER_LEFT_EXT,t.ZERO_TO_ONE_EXT):t.clipControlEXT(t.LOWER_LEFT_EXT,t.NEGATIVE_ONE_TO_ONE_EXT),this.currentDepthReversed=e}}setDepthMask(e){this.currentDepthMask!==e&&(this.gl.depthMask(e),this.currentDepthMask=e)}setDepthFunc(e){if(this.currentDepthReversed&&(e=sm[e]),this.currentDepthFunc!==e){const{gl:t}=this;switch(e){case lc:t.depthFunc(t.NEVER);break;case cc:t.depthFunc(t.ALWAYS);break;case uc:t.depthFunc(t.LESS);break;case Ds:t.depthFunc(t.LEQUAL);break;case hc:t.depthFunc(t.EQUAL);break;case dc:t.depthFunc(t.GEQUAL);break;case fc:t.depthFunc(t.GREATER);break;case pc:t.depthFunc(t.NOTEQUAL);break;default:t.depthFunc(t.LEQUAL)}this.currentDepthFunc=e}}scissor(e,t,n,i){const s=this._tempVec4.set(e,t,n,i);if(this.currentScissor.equals(s)===!1){const{gl:o}=this;o.scissor(s.x,s.y,s.z,s.w),this.currentScissor.copy(s)}}viewport(e,t,n,i){const s=this._tempVec4.set(e,t,n,i);if(this.currentViewport.equals(s)===!1){const{gl:o}=this;o.viewport(s.x,s.y,s.z,s.w),this.currentViewport.copy(s)}}setScissorTest(e){const t=this.gl;e?this.enable(t.SCISSOR_TEST):this.disable(t.SCISSOR_TEST)}setStencilTest(e){const{gl:t}=this;e?this.enable(t.STENCIL_TEST):this.disable(t.STENCIL_TEST)}setStencilMask(e){this.currentStencilMask!==e&&(this.gl.stencilMask(e),this.currentStencilMask=e)}setStencilFunc(e,t,n){(this.currentStencilFunc!==e||this.currentStencilRef!==t||this.currentStencilFuncMask!==n)&&(this.gl.stencilFunc(e,t,n),this.currentStencilFunc=e,this.currentStencilRef=t,this.currentStencilFuncMask=n)}setStencilOp(e,t,n){(this.currentStencilFail!==e||this.currentStencilZFail!==t||this.currentStencilZPass!==n)&&(this.gl.stencilOp(e,t,n),this.currentStencilFail=e,this.currentStencilZFail=t,this.currentStencilZPass=n)}setMaterial(e,t,n){const{gl:i}=this;e.side===Nn?this.disable(i.CULL_FACE):this.enable(i.CULL_FACE);let s=e.side===Lt;t&&(s=!s),this.setFlipSided(s),e.blending===ti&&e.transparent===!1?this.setBlending(Pn):this.setBlending(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.premultipliedAlpha),this.setDepthFunc(e.depthFunc),this.setDepthTest(e.depthTest),this.setDepthMask(e.depthWrite),this.setColorMask(e.colorWrite);const o=e.stencilWrite;if(this.setStencilTest(o),o&&(this.setStencilMask(e.stencilWriteMask),this.setStencilFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),this.setStencilOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),this.setPolygonOffset(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),e.alphaToCoverage===!0&&this.backend.renderer.currentSamples>0?this.enable(i.SAMPLE_ALPHA_TO_COVERAGE):this.disable(i.SAMPLE_ALPHA_TO_COVERAGE),n>0&&this.currentClippingPlanes!==n)for(let l=0;l<8;l++)l<n?this.enable(12288+l):this.disable(12288+l)}setPolygonOffset(e,t,n){const{gl:i}=this;e?(this.enable(i.POLYGON_OFFSET_FILL),(this.currentPolygonOffsetFactor!==t||this.currentPolygonOffsetUnits!==n)&&(i.polygonOffset(t,n),this.currentPolygonOffsetFactor=t,this.currentPolygonOffsetUnits=n)):this.disable(i.POLYGON_OFFSET_FILL)}useProgram(e){return this.currentProgram!==e?(this.gl.useProgram(e),this.currentProgram=e,!0):!1}setVertexState(e,t=null){const n=this.gl;return this.currentVAO!==e||this.currentIndex!==t?(n.bindVertexArray(e),t!==null&&n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,t),this.currentVAO=e,this.currentIndex=t,!0):!1}resetVertexState(){const e=this.gl;e.bindVertexArray(null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),this.currentVAO=null,this.currentIndex=null}bindFramebuffer(e,t){const{gl:n,currentBoundFramebuffers:i}=this;return i[e]!==t?(n.bindFramebuffer(e,t),i[e]=t,e===n.DRAW_FRAMEBUFFER&&(i[n.FRAMEBUFFER]=t),e===n.FRAMEBUFFER&&(i[n.DRAW_FRAMEBUFFER]=t),!0):!1}drawBuffers(e,t){const{gl:n}=this;let i=[],s=!1;if(e.textures!==null){i=this.currentDrawbuffers.get(t),i===void 0&&(i=[],this.currentDrawbuffers.set(t,i));const o=e.textures;if(i.length!==o.length||i[0]!==n.COLOR_ATTACHMENT0){for(let a=0,l=o.length;a<l;a++)i[a]=n.COLOR_ATTACHMENT0+a;i.length=o.length,s=!0}}else i[0]!==n.BACK&&(i[0]=n.BACK,s=!0);s&&n.drawBuffers(i)}activeTexture(e){const{gl:t,currentTextureSlot:n,maxTextures:i}=this;e===void 0&&(e=t.TEXTURE0+i-1),n!==e&&(t.activeTexture(e),this.currentTextureSlot=e)}bindTexture(e,t,n){const{gl:i,currentTextureSlot:s,currentBoundTextures:o,maxTextures:a}=this;n===void 0&&(s===null?n=i.TEXTURE0+a-1:n=s);let l=o[n];l===void 0&&(l={type:void 0,texture:void 0},o[n]=l),(l.type!==e||l.texture!==t)&&(s!==n&&(i.activeTexture(n),this.currentTextureSlot=n),i.bindTexture(e,t),l.type=e,l.texture=t)}bindBufferBase(e,t,n){const{gl:i}=this,s=`${e}-${t}`;return this.currentBoundBufferBases[s]!==n?(i.bindBufferBase(e,t,n),this.currentBoundBufferBases[s]=n,!0):!1}unbindTexture(){const{gl:e,currentTextureSlot:t,currentBoundTextures:n}=this,i=n[t];i!==void 0&&i.type!==void 0&&(e.bindTexture(i.type,null),i.type=void 0,i.texture=void 0)}getParameter(e){const{gl:t,parameters:n}=this;return n[e]!==void 0?n[e]:t.getParameter(e)}pixelStorei(e,t){const{gl:n,parameters:i}=this;i[e]!==t&&(n.pixelStorei(e,t),i[e]=t)}}class AB{constructor(e){this.backend=e,this.gl=this.backend.gl,this.extensions=e.extensions}convert(e,t=ai){const{gl:n,extensions:i}=this;let s;const o=Ye.getTransfer(t);if(e===Xt)return n.UNSIGNED_BYTE;if(e===Pc)return n.UNSIGNED_SHORT_4_4_4_4;if(e===Dc)return n.UNSIGNED_SHORT_5_5_5_1;if(e===Lc)return n.UNSIGNED_INT_5_9_9_9_REV;if(e===Uc)return n.UNSIGNED_INT_10F_11F_11F_REV;if(e===Ts)return n.BYTE;if(e===Ms)return n.SHORT;if(e===Li)return n.UNSIGNED_SHORT;if(e===Sn)return n.INT;if(e===Ct)return n.UNSIGNED_INT;if(e===Qt)return n.FLOAT;if(e===tn)return n.HALF_FLOAT;if(e===Fh)return n.ALPHA;if(e===nl)return n.RGB;if(e===ln)return n.RGBA;if(e===Dn)return n.DEPTH_COMPONENT;if(e===qn)return n.DEPTH_STENCIL;if(e===il)return n.RED;if(e===Eo)return n.RED_INTEGER;if(e===In)return n.RG;if(e===Ao)return n.RG_INTEGER;if(e===rl)return n.RGBA_INTEGER;if(e===Es||e===As||e===ws||e===Rs)if(o===Pe)if(s=i.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(e===Es)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(e===As)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(e===ws)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(e===Rs)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=i.get("WEBGL_compressed_texture_s3tc"),s!==null){if(e===Es)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(e===As)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(e===ws)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(e===Rs)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(e===mc||e===gc||e===_c||e===xc)if(s=i.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(e===mc)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(e===gc)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(e===_c)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(e===xc)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(e===Ma||e===Ea||e===Aa||e===wa||e===Ra||e===Ls||e===Ca)if(s=i.get("WEBGL_compressed_texture_etc"),s!==null){if(e===Ma||e===Ea)return o===Pe?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(e===Aa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(e===wa)return s.COMPRESSED_R11_EAC;if(e===Ra)return s.COMPRESSED_SIGNED_R11_EAC;if(e===Ls)return s.COMPRESSED_RG11_EAC;if(e===Ca)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(e===Na||e===Pa||e===Da||e===La||e===Ua||e===Fa||e===Ia||e===Ba||e===Oa||e===ka||e===Ga||e===Va||e===za||e===Ha)if(s=i.get("WEBGL_compressed_texture_astc"),s!==null){if(e===Na)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(e===Pa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(e===Da)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(e===La)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(e===Ua)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(e===Fa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(e===Ia)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(e===Ba)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(e===Oa)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(e===ka)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(e===Ga)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(e===Va)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(e===za)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(e===Ha)return o===Pe?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(e===Wa)if(s=i.get("EXT_texture_compression_bptc"),s!==null){if(e===Wa)return o===Pe?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT}else return null;if(e===$a||e===Xa||e===Us||e===qa)if(s=i.get("EXT_texture_compression_rgtc"),s!==null){if(e===$a)return s.COMPRESSED_RED_RGTC1_EXT;if(e===Xa)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(e===Us)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(e===qa)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return e===di?n.UNSIGNED_INT_24_8:n[e]!==void 0?n[e]:null}_clientWaitAsync(){const{gl:e}=this,t=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),new Promise((n,i)=>{function s(){const o=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(o===e.WAIT_FAILED){e.deleteSync(t),i();return}if(o===e.TIMEOUT_EXPIRED){requestAnimationFrame(s);return}e.deleteSync(t),n()}s()})}}let d0=!1,Ku,Gf,f0;class wB{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},this._srcFramebuffer=null,this._dstFramebuffer=null,d0===!1&&(this._init(),d0=!0)}_init(){const e=this.gl;Ku={[go]:e.REPEAT,[ci]:e.CLAMP_TO_EDGE,[_o]:e.MIRRORED_REPEAT},Gf={[Mt]:e.NEAREST,[em]:e.NEAREST_MIPMAP_NEAREST,[Xr]:e.NEAREST_MIPMAP_LINEAR,[Nt]:e.LINEAR,[ga]:e.LINEAR_MIPMAP_NEAREST,[ui]:e.LINEAR_MIPMAP_LINEAR},f0={[tm]:e.NEVER,[rm]:e.ALWAYS,[Ih]:e.LESS,[Os]:e.LEQUAL,[nm]:e.EQUAL,[Zr]:e.GEQUAL,[vc]:e.GREATER,[im]:e.NOTEQUAL}}getGLTextureType(e){const{gl:t}=this;let n;return e.isCubeTexture===!0?n=t.TEXTURE_CUBE_MAP:e.isArrayTexture===!0||e.isDataArrayTexture===!0||e.isCompressedArrayTexture===!0?n=t.TEXTURE_2D_ARRAY:e.isData3DTexture===!0?n=t.TEXTURE_3D:n=t.TEXTURE_2D,n}getInternalFormat(e,t,n,i,s,o=!1){const{gl:a,extensions:l}=this;if(e!==null){if(a[e]!==void 0)return a[e];ae("WebGLBackend: Attempt to use non-existing WebGL internal format '"+e+"'")}let c=null;i&&(c=l.get("EXT_texture_norm16"),c||ae("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let u=t;if(t===a.RED&&(n===a.FLOAT&&(u=a.R32F),n===a.HALF_FLOAT&&(u=a.R16F),n===a.UNSIGNED_BYTE&&(u=a.R8),n===a.BYTE&&(u=a.R8_SNORM),n===a.UNSIGNED_SHORT&&c&&(u=c.R16_EXT),n===a.SHORT&&c&&(u=c.R16_SNORM_EXT)),t===a.RED_INTEGER&&(n===a.UNSIGNED_BYTE&&(u=a.R8UI),n===a.UNSIGNED_SHORT&&(u=a.R16UI),n===a.UNSIGNED_INT&&(u=a.R32UI),n===a.BYTE&&(u=a.R8I),n===a.SHORT&&(u=a.R16I),n===a.INT&&(u=a.R32I)),t===a.RG&&(n===a.FLOAT&&(u=a.RG32F),n===a.HALF_FLOAT&&(u=a.RG16F),n===a.UNSIGNED_BYTE&&(u=a.RG8),n===a.BYTE&&(u=a.RG8_SNORM),n===a.UNSIGNED_SHORT&&c&&(u=c.RG16_EXT),n===a.SHORT&&c&&(u=c.RG16_SNORM_EXT)),t===a.RG_INTEGER&&(n===a.UNSIGNED_BYTE&&(u=a.RG8UI),n===a.UNSIGNED_SHORT&&(u=a.RG16UI),n===a.UNSIGNED_INT&&(u=a.RG32UI),n===a.BYTE&&(u=a.RG8I),n===a.SHORT&&(u=a.RG16I),n===a.INT&&(u=a.RG32I)),t===a.RGB){const h=o?ja:Ye.getTransfer(s);n===a.FLOAT&&(u=a.RGB32F),n===a.HALF_FLOAT&&(u=a.RGB16F),n===a.UNSIGNED_BYTE&&(u=h===Pe?a.SRGB8:a.RGB8),n===a.BYTE&&(u=a.RGB8_SNORM),n===a.UNSIGNED_SHORT&&c&&(u=c.RGB16_EXT),n===a.SHORT&&c&&(u=c.RGB16_SNORM_EXT),n===a.UNSIGNED_SHORT_5_6_5&&(u=a.RGB565),n===a.UNSIGNED_SHORT_5_5_5_1&&(u=a.RGB5_A1),n===a.UNSIGNED_SHORT_4_4_4_4&&(u=a.RGB4),n===a.UNSIGNED_INT_5_9_9_9_REV&&(u=a.RGB9_E5),n===a.UNSIGNED_INT_10F_11F_11F_REV&&(u=a.R11F_G11F_B10F)}if(t===a.RGB_INTEGER&&(n===a.UNSIGNED_BYTE&&(u=a.RGB8UI),n===a.UNSIGNED_SHORT&&(u=a.RGB16UI),n===a.UNSIGNED_INT&&(u=a.RGB32UI),n===a.BYTE&&(u=a.RGB8I),n===a.SHORT&&(u=a.RGB16I),n===a.INT&&(u=a.RGB32I)),t===a.RGBA){const h=o?ja:Ye.getTransfer(s);n===a.FLOAT&&(u=a.RGBA32F),n===a.HALF_FLOAT&&(u=a.RGBA16F),n===a.UNSIGNED_BYTE&&(u=h===Pe?a.SRGB8_ALPHA8:a.RGBA8),n===a.BYTE&&(u=a.RGBA8_SNORM),n===a.UNSIGNED_SHORT&&c&&(u=c.RGBA16_EXT),n===a.SHORT&&c&&(u=c.RGBA16_SNORM_EXT),n===a.UNSIGNED_SHORT_4_4_4_4&&(u=a.RGBA4),n===a.UNSIGNED_SHORT_5_5_5_1&&(u=a.RGB5_A1)}return t===a.RGBA_INTEGER&&(n===a.UNSIGNED_BYTE&&(u=a.RGBA8UI),n===a.UNSIGNED_SHORT&&(u=a.RGBA16UI),n===a.UNSIGNED_INT&&(u=a.RGBA32UI),n===a.BYTE&&(u=a.RGBA8I),n===a.SHORT&&(u=a.RGBA16I),n===a.INT&&(u=a.RGBA32I)),t===a.DEPTH_COMPONENT&&(n===a.UNSIGNED_SHORT&&(u=a.DEPTH_COMPONENT16),n===a.UNSIGNED_INT&&(u=a.DEPTH_COMPONENT24),n===a.FLOAT&&(u=a.DEPTH_COMPONENT32F)),t===a.DEPTH_STENCIL&&n===a.UNSIGNED_INT_24_8&&(u=a.DEPTH24_STENCIL8),(u===a.R16F||u===a.R32F||u===a.RG16F||u===a.RG32F||u===a.RGBA16F||u===a.RGBA32F)&&l.get("EXT_color_buffer_float"),u}setTextureParameters(e,t){const{gl:n,extensions:i,backend:s}=this,{state:o}=this.backend,a=Ye.getPrimaries(Ye.workingColorSpace),l=t.colorSpace===ai?null:Ye.getPrimaries(t.colorSpace),c=t.colorSpace===ai||a===l?n.NONE:n.BROWSER_DEFAULT_WEBGL;o.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,t.flipY),o.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),o.pixelStorei(n.UNPACK_ALIGNMENT,t.unpackAlignment),o.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,c),n.texParameteri(e,n.TEXTURE_WRAP_S,Ku[t.wrapS]),n.texParameteri(e,n.TEXTURE_WRAP_T,Ku[t.wrapT]),(e===n.TEXTURE_3D||e===n.TEXTURE_2D_ARRAY)&&(t.isArrayTexture||n.texParameteri(e,n.TEXTURE_WRAP_R,Ku[t.wrapR])),n.texParameteri(e,n.TEXTURE_MAG_FILTER,Gf[t.magFilter]);const u=t.mipmaps!==void 0&&t.mipmaps.length>0,h=t.minFilter===Nt&&u?ui:t.minFilter;if(n.texParameteri(e,n.TEXTURE_MIN_FILTER,Gf[h]),t.compareFunction&&(n.texParameteri(e,n.TEXTURE_COMPARE_MODE,n.COMPARE_REF_TO_TEXTURE),n.texParameteri(e,n.TEXTURE_COMPARE_FUNC,f0[t.compareFunction])),i.has("EXT_texture_filter_anisotropic")===!0){if(t.magFilter===Mt||t.minFilter!==Xr&&t.minFilter!==ui||t.type===Qt&&i.has("OES_texture_float_linear")===!1)return;if(t.anisotropy>1){const d=i.get("EXT_texture_filter_anisotropic");n.texParameterf(e,d.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,s.capabilities.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:n,defaultTextures:i}=this,s=this.getGLTextureType(e);let o=i[s];o===void 0&&(o=t.createTexture(),n.state.bindTexture(s,o),t.texParameteri(s,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(s,t.TEXTURE_MAG_FILTER,t.NEAREST),i[s]=o),n.set(e,{textureGPU:o,glTextureType:s})}createTexture(e,t){const{gl:n,backend:i}=this,{levels:s,width:o,height:a,depth:l}=t,c=i.utils.convert(e.format,e.colorSpace),u=i.utils.convert(e.type),h=this.getInternalFormat(e.internalFormat,c,u,e.normalized,e.colorSpace,e.isVideoTexture),d=n.createTexture(),f=this.getGLTextureType(e);i.state.bindTexture(f,d),this.setTextureParameters(f,e),e.isArrayTexture||e.isDataArrayTexture||e.isCompressedArrayTexture?n.texStorage3D(n.TEXTURE_2D_ARRAY,s,h,o,a,l):e.isData3DTexture?n.texStorage3D(n.TEXTURE_3D,s,h,o,a,l):e.isVideoTexture||n.texStorage2D(f,s,h,o,a),i.set(e,{textureGPU:d,glTextureType:f,glFormat:c,glType:u,glInternalFormat:h})}copyBufferToTexture(e,t){const{gl:n,backend:i}=this,{state:s}=i,{textureGPU:o,glTextureType:a,glFormat:l,glType:c}=i.get(t),{width:u,height:h}=t.source.data;n.bindBuffer(n.PIXEL_UNPACK_BUFFER,e),i.state.bindTexture(a,o),s.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),n.texSubImage2D(a,0,0,0,u,h,l,c,0),n.bindBuffer(n.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(e,t){const{gl:n}=this,{width:i,height:s}=t,{textureGPU:o,glTextureType:a,glFormat:l,glType:c,glInternalFormat:u}=this.backend.get(e);if(!(e.isRenderTargetTexture||o===void 0))if(this.backend.state.bindTexture(a,o),this.setTextureParameters(a,e),e.isCompressedTexture){const h=e.mipmaps,d=t.image;for(let f=0;f<h.length;f++){const p=h[f];e.isCompressedArrayTexture?e.format!==n.RGBA?l!==null?n.compressedTexSubImage3D(n.TEXTURE_2D_ARRAY,f,0,0,0,p.width,p.height,d.depth,l,p.data):ae("WebGLBackend: Attempt to load unsupported compressed texture format in .uploadTexture()"):n.texSubImage3D(n.TEXTURE_2D_ARRAY,f,0,0,0,p.width,p.height,d.depth,l,c,p.data):l!==null?n.compressedTexSubImage2D(n.TEXTURE_2D,f,0,0,p.width,p.height,l,p.data):ae("WebGLBackend: Unsupported compressed texture format")}}else if(e.isCubeTexture){const h=t.images,d=e.mipmaps;for(let f=0;f<6;f++){const p=Zu(h[f]);n.texSubImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+f,0,0,0,i,s,l,c,p);for(let g=0;g<d.length;g++){const m=d[g],_=Zu(m.images[f]);n.texSubImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+f,g+1,0,0,_.width,_.height,l,c,_)}}}else if(e.isDataArrayTexture||e.isArrayTexture){const h=t.image;if(e.layerUpdates.size>0){const d=rp(h.width,h.height,e.format,e.type);for(const f of e.layerUpdates){const p=h.data.subarray(f*d/h.data.BYTES_PER_ELEMENT,(f+1)*d/h.data.BYTES_PER_ELEMENT);n.texSubImage3D(n.TEXTURE_2D_ARRAY,0,0,0,f,h.width,h.height,1,l,c,p)}e.clearLayerUpdates()}else n.texSubImage3D(n.TEXTURE_2D_ARRAY,0,0,0,0,h.width,h.height,h.depth,l,c,h.data)}else if(e.isData3DTexture){const h=t.image;n.texSubImage3D(n.TEXTURE_3D,0,0,0,0,h.width,h.height,h.depth,l,c,h.data)}else if(e.isVideoTexture)e.update(),n.texImage2D(a,0,u,l,c,t.image);else if(e.isHTMLTexture)typeof n.texElementImage2D=="function"&&n.texElementImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t.image);else{const h=e.mipmaps;if(h.length>0)for(let d=0,f=h.length;d<f;d++){const p=h[d],g=Zu(p);n.texSubImage2D(a,d,0,0,p.width,p.height,l,c,g)}else{const d=Zu(t.image);n.texSubImage2D(a,0,0,0,i,s,l,c,d)}}}generateMipmaps(e){const{gl:t,backend:n}=this,{textureGPU:i,glTextureType:s}=n.get(e);n.state.bindTexture(s,i),t.generateMipmap(s)}deallocateRenderBuffers(e){const{gl:t,backend:n}=this;if(e){const i=n.get(e);if(i.renderBufferStorageSetup=void 0,i.framebuffers){for(const s in i.framebuffers)t.deleteFramebuffer(i.framebuffers[s]);delete i.framebuffers}if(i.depthRenderbuffer&&(t.deleteRenderbuffer(i.depthRenderbuffer),delete i.depthRenderbuffer),i.stencilRenderbuffer&&(t.deleteRenderbuffer(i.stencilRenderbuffer),delete i.stencilRenderbuffer),i.msaaFrameBuffer&&(t.deleteFramebuffer(i.msaaFrameBuffer),delete i.msaaFrameBuffer),i.msaaRenderbuffers){for(let s=0;s<i.msaaRenderbuffers.length;s++)t.deleteRenderbuffer(i.msaaRenderbuffers[s]);delete i.msaaRenderbuffers}}}destroyTexture(e,t=!1){const{gl:n,backend:i}=this,{textureGPU:s,renderTarget:o}=i.get(e);this.deallocateRenderBuffers(o),t===!1&&n.deleteTexture(s),i.delete(e)}copyTextureToTexture(e,t,n=null,i=null,s=0,o=0){const{gl:a,backend:l}=this,{state:c}=this.backend,{textureGPU:u,glTextureType:h,glType:d,glFormat:f}=l.get(t);c.bindTexture(h,u);let p,g,m,_,x,y,b,M,S;const E=e.isCompressedTexture?e.mipmaps[o]:e.image;if(n!==null)p=n.max.x-n.min.x,g=n.max.y-n.min.y,m=n.isBox3?n.max.z-n.min.z:1,_=n.min.x,x=n.min.y,y=n.isBox3?n.min.z:0;else{const U=Math.pow(2,-s);p=Math.floor(E.width*U),g=Math.floor(E.height*U),e.isDataArrayTexture||e.isArrayTexture?m=E.depth:e.isData3DTexture?m=Math.floor(E.depth*U):m=1,_=0,x=0,y=0}i!==null?(b=i.x,M=i.y,S=i.z):(b=0,M=0,S=0),c.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,t.flipY),c.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),c.pixelStorei(a.UNPACK_ALIGNMENT,t.unpackAlignment);const v=c.getParameter(a.UNPACK_ROW_LENGTH),w=c.getParameter(a.UNPACK_IMAGE_HEIGHT),N=c.getParameter(a.UNPACK_SKIP_PIXELS),C=c.getParameter(a.UNPACK_SKIP_ROWS),F=c.getParameter(a.UNPACK_SKIP_IMAGES);c.pixelStorei(a.UNPACK_ROW_LENGTH,E.width),c.pixelStorei(a.UNPACK_IMAGE_HEIGHT,E.height),c.pixelStorei(a.UNPACK_SKIP_PIXELS,_),c.pixelStorei(a.UNPACK_SKIP_ROWS,x),c.pixelStorei(a.UNPACK_SKIP_IMAGES,y);const V=e.isDataArrayTexture||e.isData3DTexture||t.isArrayTexture,z=t.isDataArrayTexture||t.isData3DTexture||t.isArrayTexture;if(e.isDepthTexture){const U=l.get(e),B=l.get(t),D=l.get(U.renderTarget),X=l.get(B.renderTarget),K=D.framebuffers[U.cacheKey],fe=X.framebuffers[B.cacheKey];c.bindFramebuffer(a.READ_FRAMEBUFFER,K),c.bindFramebuffer(a.DRAW_FRAMEBUFFER,fe);for(let Z=0;Z<m;Z++)V&&(a.framebufferTextureLayer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,U.textureGPU,s,y+Z),a.framebufferTextureLayer(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,u,o,S+Z)),a.blitFramebuffer(_,x,p,g,b,M,p,g,a.DEPTH_BUFFER_BIT,a.NEAREST);c.bindFramebuffer(a.READ_FRAMEBUFFER,null),c.bindFramebuffer(a.DRAW_FRAMEBUFFER,null)}else if(s!==0||e.isRenderTargetTexture||l.has(e)){const U=l.get(e);this._srcFramebuffer===null&&(this._srcFramebuffer=a.createFramebuffer()),this._dstFramebuffer===null&&(this._dstFramebuffer=a.createFramebuffer()),c.bindFramebuffer(a.READ_FRAMEBUFFER,this._srcFramebuffer),c.bindFramebuffer(a.DRAW_FRAMEBUFFER,this._dstFramebuffer);for(let B=0;B<m;B++)V?a.framebufferTextureLayer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,U.textureGPU,s,y+B):a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,U.textureGPU,s),z?a.framebufferTextureLayer(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,u,o,S+B):a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,u,o),s!==0?a.blitFramebuffer(_,x,p,g,b,M,p,g,a.COLOR_BUFFER_BIT,a.NEAREST):z?a.copyTexSubImage3D(h,o,b,M,S+B,_,x,p,g):a.copyTexSubImage2D(h,o,b,M,_,x,p,g);c.bindFramebuffer(a.READ_FRAMEBUFFER,null),c.bindFramebuffer(a.DRAW_FRAMEBUFFER,null)}else z?e.isDataTexture||e.isData3DTexture?a.texSubImage3D(h,o,b,M,S,p,g,m,f,d,E.data):t.isCompressedArrayTexture?a.compressedTexSubImage3D(h,o,b,M,S,p,g,m,f,E.data):a.texSubImage3D(h,o,b,M,S,p,g,m,f,d,E):e.isDataTexture?a.texSubImage2D(a.TEXTURE_2D,o,b,M,p,g,f,d,E.data):e.isCompressedTexture?a.compressedTexSubImage2D(a.TEXTURE_2D,o,b,M,E.width,E.height,f,E.data):a.texSubImage2D(a.TEXTURE_2D,o,b,M,p,g,f,d,E);c.pixelStorei(a.UNPACK_ROW_LENGTH,v),c.pixelStorei(a.UNPACK_IMAGE_HEIGHT,w),c.pixelStorei(a.UNPACK_SKIP_PIXELS,N),c.pixelStorei(a.UNPACK_SKIP_ROWS,C),c.pixelStorei(a.UNPACK_SKIP_IMAGES,F),o===0&&t.generateMipmaps&&a.generateMipmap(h),c.unbindTexture()}copyFramebufferToTexture(e,t,n){const{gl:i}=this,{state:s}=this.backend,{textureGPU:o}=this.backend.get(e),{x:a,y:l,z:c,w:u}=n,h=e.isDepthTexture===!0||t.renderTarget&&t.renderTarget.samples>0,d=t.renderTarget?t.renderTarget.height:this.backend.getDrawingBufferSize().y;if(h){const f=a!==0||l!==0;let p,g;if(e.isDepthTexture===!0?(p=i.DEPTH_BUFFER_BIT,g=i.DEPTH_ATTACHMENT,t.stencil&&(p|=i.STENCIL_BUFFER_BIT)):(p=i.COLOR_BUFFER_BIT,g=i.COLOR_ATTACHMENT0),f){const m=this.backend.get(t.renderTarget),_=m.framebuffers[t.getCacheKey()],x=m.msaaFrameBuffer;s.bindFramebuffer(i.DRAW_FRAMEBUFFER,_),s.bindFramebuffer(i.READ_FRAMEBUFFER,x);const y=d-l-u;i.blitFramebuffer(a,y,a+c,y+u,a,y,a+c,y+u,p,i.NEAREST),s.bindFramebuffer(i.READ_FRAMEBUFFER,_),s.bindTexture(i.TEXTURE_2D,o),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,y,c,u),s.unbindTexture()}else{const m=i.createFramebuffer();s.bindFramebuffer(i.DRAW_FRAMEBUFFER,m),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,g,i.TEXTURE_2D,o,0),i.blitFramebuffer(0,0,c,u,0,0,c,u,p,i.NEAREST),i.deleteFramebuffer(m)}}else s.bindTexture(i.TEXTURE_2D,o),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,d-u-l,c,u),s.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t,n,i=!1){const{gl:s}=this,o=t.renderTarget,{depthTexture:a,depthBuffer:l,stencilBuffer:c,width:u,height:h}=o;if(s.bindRenderbuffer(s.RENDERBUFFER,e),l&&!c){let d=s.DEPTH_COMPONENT24;i===!0?this.extensions.get("WEBGL_multisampled_render_to_texture").renderbufferStorageMultisampleEXT(s.RENDERBUFFER,o.samples,d,u,h):n>0?(a&&a.isDepthTexture&&a.type===s.FLOAT&&(d=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,n,d,u,h)):s.renderbufferStorage(s.RENDERBUFFER,d,u,h),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else l&&c&&(n>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,n,s.DEPTH24_STENCIL8,u,h):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,h),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e));s.bindRenderbuffer(s.RENDERBUFFER,null)}async copyTextureToBuffer(e,t,n,i,s,o){const{backend:a,gl:l}=this,{textureGPU:c,glFormat:u,glType:h}=this.backend.get(e),d=l.createFramebuffer();a.state.bindFramebuffer(l.READ_FRAMEBUFFER,d);const f=e.isCubeTexture?l.TEXTURE_CUBE_MAP_POSITIVE_X+o:l.TEXTURE_2D;l.framebufferTexture2D(l.READ_FRAMEBUFFER,l.COLOR_ATTACHMENT0,f,c,0);const p=this._getTypedArrayType(h),g=this._getBytesPerTexel(h,u),_=i*s*g,x=l.createBuffer();l.bindBuffer(l.PIXEL_PACK_BUFFER,x),l.bufferData(l.PIXEL_PACK_BUFFER,_,l.STREAM_READ),l.readPixels(t,n,i,s,u,h,0),l.bindBuffer(l.PIXEL_PACK_BUFFER,null),await a.utils._clientWaitAsync();const y=new p(_/p.BYTES_PER_ELEMENT);return l.bindBuffer(l.PIXEL_PACK_BUFFER,x),l.getBufferSubData(l.PIXEL_PACK_BUFFER,0,y),l.bindBuffer(l.PIXEL_PACK_BUFFER,null),a.state.bindFramebuffer(l.READ_FRAMEBUFFER,null),l.deleteFramebuffer(d),y}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4||e===t.UNSIGNED_SHORT_5_5_5_1||e===t.UNSIGNED_SHORT_5_6_5||e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:n}=this;let i=0;if(e===n.UNSIGNED_BYTE&&(i=1),(e===n.UNSIGNED_SHORT_4_4_4_4||e===n.UNSIGNED_SHORT_5_5_5_1||e===n.UNSIGNED_SHORT_5_6_5||e===n.UNSIGNED_SHORT||e===n.HALF_FLOAT)&&(i=2),(e===n.UNSIGNED_INT||e===n.FLOAT)&&(i=4),t===n.RGBA)return i*4;if(t===n.RGB)return i*3;if(t===n.ALPHA)return i}dispose(){const{gl:e}=this;this._srcFramebuffer!==null&&e.deleteFramebuffer(this._srcFramebuffer),this._dstFramebuffer!==null&&e.deleteFramebuffer(this._dstFramebuffer)}}function Zu(r){return r.isDataTexture?r.image.data:typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&r instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&r instanceof OffscreenCanvas?r:r.data}class RB{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return t===void 0&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class CB{constructor(e){this.backend=e,this.maxAnisotropy=null,this.maxUniformBlockSize=null}getMaxAnisotropy(){if(this.maxAnisotropy!==null)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(t.has("EXT_texture_filter_anisotropic")===!0){const n=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}getUniformBufferLimit(){if(this.maxUniformBlockSize!==null)return this.maxUniformBlockSize;const e=this.backend.gl;return this.maxUniformBlockSize=e.getParameter(e.MAX_UNIFORM_BLOCK_SIZE),this.maxUniformBlockSize}}const p0={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-s3tc",EXT_texture_compression_bptc:"texture-compression-bc",EXT_disjoint_timer_query_webgl2:"timestamp-query",OVR_multiview2:"OVR_multiview2"};class NB{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:n,mode:i,object:s,type:o,info:a,index:l}=this;l!==0?n.drawElements(i,t,o,e):n.drawArrays(i,e,t),a.update(s,t,1)}renderInstances(e,t,n){const{gl:i,mode:s,type:o,index:a,object:l,info:c}=this;n!==0&&(a!==0?i.drawElementsInstanced(s,t,o,e,n):i.drawArraysInstanced(s,e,t,n),c.update(l,t,n))}renderMultiDraw(e,t,n){const{extensions:i,mode:s,object:o,info:a}=this;if(n===0)return;const l=i.get("WEBGL_multi_draw");if(l===null)for(let c=0;c<n;c++)this.render(e[c],t[c]);else{this.index!==0?l.multiDrawElementsWEBGL(s,t,0,this.type,e,0,n):l.multiDrawArraysWEBGL(s,e,0,t,0,n);let c=0;for(let u=0;u<n;u++)c+=t[u];a.update(o,c,1)}}}class Hb{constructor(e=256){this.trackTimestamp=!0,this.maxQueries=e,this.currentQueryIndex=0,this.queryOffsets=new Map,this.isDisposed=!1,this.lastValue=0,this.frames=[],this.pendingResolve=!1,this.timestamps=new Map}getTimestampFrames(){return this.frames}getTimestamp(e){let t=this.timestamps.get(e);return t===void 0&&(ae(`TimestampQueryPool: No timestamp available for uid ${e}.`),t=0),t}hasTimestamp(e){return this.timestamps.has(e)}allocateQueriesForContext(){}async resolveQueriesAsync(){}dispose(){}}class PB extends Hb{constructor(e,t,n=2048){if(super(n),this.gl=e,this.type=t,this.ext=e.getExtension("EXT_disjoint_timer_query_webgl2")||e.getExtension("EXT_disjoint_timer_query"),!this.ext){ae("EXT_disjoint_timer_query not supported; timestamps will be disabled."),this.trackTimestamp=!1;return}this.queries=[];for(let i=0;i<this.maxQueries;i++)this.queries.push(e.createQuery());this.activeQuery=null,this.queryStates=new Map}allocateQueriesForContext(e){if(!this.trackTimestamp)return null;if(this.currentQueryIndex+2>this.maxQueries)return Kt(`WebGLTimestampQueryPool [${this.type}]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${this.type.toUpperCase()} ).`),null;const t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryStates.set(t,"inactive"),this.queryOffsets.set(e,t),t}beginQuery(e){if(!this.trackTimestamp||this.isDisposed)return;const t=this.queryOffsets.get(e);if(t==null||this.activeQuery!==null)return;const n=this.queries[t];if(n)try{this.queryStates.get(t)==="inactive"&&(this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT,n),this.activeQuery=t,this.queryStates.set(t,"started"))}catch(i){ce("Error in beginQuery:",i),this.activeQuery=null,this.queryStates.set(t,"inactive")}}endQuery(e){if(!this.trackTimestamp||this.isDisposed)return;const t=this.queryOffsets.get(e);if(t!=null&&this.activeQuery===t)try{this.gl.endQuery(this.ext.TIME_ELAPSED_EXT),this.queryStates.set(t,"ended"),this.activeQuery=null}catch(n){ce("Error in endQuery:",n),this.queryStates.set(t,"inactive"),this.activeQuery=null}}async resolveQueriesAsync(){if(!this.trackTimestamp||this.pendingResolve)return this.lastValue;this.pendingResolve=!0;try{const e=new Map;for(const[s,o]of this.queryOffsets)if(this.queryStates.get(o)==="ended"){const l=this.queries[o];e.set(s,this.resolveQuery(l))}if(e.size===0)return this.lastValue;const t={},n=[];for(const[s,o]of e){const a=s.match(/^(.*):f(\d+)$/),l=parseInt(a[2]);n.includes(l)===!1&&n.push(l),t[l]===void 0&&(t[l]=0);const c=await o;this.timestamps.set(s,c),t[l]+=c}const i=t[n[n.length-1]];return this.lastValue=i,this.frames=n,this.currentQueryIndex=0,this.queryOffsets.clear(),this.queryStates.clear(),this.activeQuery=null,i}catch(e){return ce("Error resolving queries:",e),this.lastValue}finally{this.pendingResolve=!1}}async resolveQuery(e){return new Promise(t=>{if(this.isDisposed){t(this.lastValue);return}let n,i=!1;const s=()=>{n&&(clearTimeout(n),n=null)},o=l=>{i||(i=!0,s(),t(l))},a=()=>{if(this.isDisposed){o(this.lastValue);return}try{if(this.gl.getParameter(this.ext.GPU_DISJOINT_EXT)){o(this.lastValue);return}if(!this.gl.getQueryParameter(e,this.gl.QUERY_RESULT_AVAILABLE)){n=setTimeout(a,1);return}const u=this.gl.getQueryParameter(e,this.gl.QUERY_RESULT);t(Number(u)/1e6)}catch(l){ce("Error checking query:",l),t(this.lastValue)}};a()})}dispose(){if(!this.isDisposed&&(this.isDisposed=!0,!!this.trackTimestamp)){for(const e of this.queries)this.gl.deleteQuery(e);this.queries=[],this.queryStates.clear(),this.queryOffsets.clear(),this.lastValue=0,this.activeQuery=null}}}class m0 extends zb{constructor(e={}){super(e),this.isWebGLBackend=!0,this.attributeUtils=null,this.extensions=null,this.capabilities=null,this.textureUtils=null,this.bufferRenderer=null,this.gl=null,this.state=null,this.utils=null,this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.disjoint=null,this.parallel=null,this._currentContext=null,this._knownBindings=new WeakSet,this._supportsInvalidateFramebuffer=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),this._xrFramebuffer=null}init(e){super.init(e);const t=this.parameters,n={antialias:e.currentSamples>0,alpha:!0,depth:e.depth,stencil:e.stencil},i=t.context!==void 0?t.context:e.domElement.getContext("webgl2",n);function s(o){o.preventDefault();const a={api:"WebGL",message:o.statusMessage||"Unknown reason",reason:null,originalEvent:o};e.onDeviceLost(a)}this._onContextLost=s,e.domElement.addEventListener("webglcontextlost",s,!1),this.gl=i,this.extensions=new RB(this),this.capabilities=new CB(this),this.attributeUtils=new MB(this),this.textureUtils=new wB(this),this.bufferRenderer=new NB(this),this.state=new EB(this),this.utils=new AB(this),this.extensions.get("EXT_color_buffer_float"),this.extensions.get("WEBGL_clip_cull_distance"),this.extensions.get("OES_texture_float_linear"),this.extensions.get("EXT_color_buffer_half_float"),this.extensions.get("WEBGL_multisampled_render_to_texture"),this.extensions.get("WEBGL_render_shared_exponent"),this.extensions.get("WEBGL_multi_draw"),this.extensions.get("OVR_multiview2"),this.extensions.get("EXT_clip_control"),this.disjoint=this.extensions.get("EXT_disjoint_timer_query_webgl2"),this.parallel=this.extensions.get("KHR_parallel_shader_compile"),this.drawBuffersIndexedExt=this.extensions.get("OES_draw_buffers_indexed"),t.reversedDepthBuffer&&(this.extensions.has("EXT_clip_control")?e.reversedDepthBuffer=!0:(ae("WebGPURenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer."),e.reversedDepthBuffer=!1)),e.reversedDepthBuffer&&this.state.setReversedDepth(!0)}get coordinateSystem(){return ii}async getArrayBufferAsync(e,t=null,n=0,i=-1){return await this.attributeUtils.getArrayBufferAsync(e,t,n,i)}async makeXRCompatible(){this.gl.getContextAttributes().xrCompatible!==!0&&await this.gl.makeXRCompatible()}setXRTarget(e){this._xrFramebuffer=e}setXRRenderTargetTextures(e,t,n=null){const i=this.gl;if(this.set(e.texture,{textureGPU:t,glInternalFormat:i.RGBA8}),n!==null){const s=e.stencilBuffer?i.DEPTH24_STENCIL8:i.DEPTH_COMPONENT24;this.set(e.depthTexture,{textureGPU:n,glInternalFormat:s}),this.extensions.has("WEBGL_multisampled_render_to_texture")===!0&&e._autoAllocateDepthBuffer===!0&&e.multiview===!1&&ae("WebGLBackend: Render-to-texture extension was disabled because an external texture was provided"),e._autoAllocateDepthBuffer=!1}}initTimestampQuery(e,t){if(!this.disjoint||!this.trackTimestamp)return;this.timestampQueryPool[e]||(this.timestampQueryPool[e]=new PB(this.gl,e,2048));const n=this.timestampQueryPool[e];n.allocateQueriesForContext(t)!==null&&n.beginQuery(t)}prepareTimestampBuffer(e,t){if(!this.disjoint||!this.trackTimestamp)return;this.timestampQueryPool[e].endQuery(t)}getContext(){return this.gl}beginRender(e){const{state:t}=this,n=this.get(e);if(e.viewport)this.updateViewport(e);else{const{width:s,height:o}=this.getDrawingBufferSize();t.viewport(0,0,s,o)}if(e.scissor)this.updateScissor(e);else{const{width:s,height:o}=this.getDrawingBufferSize();t.scissor(0,0,s,o)}this.initTimestampQuery(xr.RENDER,this.getTimestampUID(e)),n.previousContext=this._currentContext,this._currentContext=e,this._setFramebuffer(e),this.clear(e.clearColor,e.clearDepth,e.clearStencil,e,!1);const i=e.occlusionQueryCount;i>0&&(n.currentOcclusionQueries=n.occlusionQueries,n.currentOcclusionQueryObjects=n.occlusionQueryObjects,n.lastOcclusionObject=null,n.occlusionQueries=new Array(i),n.occlusionQueryObjects=new Array(i),n.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:n}=this,i=this.get(e),s=i.previousContext;n.resetVertexState();const o=e.occlusionQueryCount;o>0&&(o>i.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const a=e.textures;if(a!==null)for(let l=0;l<a.length;l++){const c=a[l];c.generateMipmaps&&this.generateMipmaps(c)}if(this._currentContext=s,this._resolveRenderTarget(e),s!==null){if(this._setFramebuffer(s),s.viewport)this.updateViewport(s);else{const{width:l,height:c}=this.getDrawingBufferSize();n.viewport(0,0,l,c)}if(s.scissor)this.updateScissor(s);else{const{width:l,height:c}=this.getDrawingBufferSize();n.scissor(0,0,l,c)}}this.prepareTimestampBuffer(xr.RENDER,this.getTimestampUID(e))}resolveOccludedAsync(e){const t=this.get(e),{currentOcclusionQueries:n,currentOcclusionQueryObjects:i}=t;if(n&&i){const s=new WeakSet,{gl:o}=this;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueries=null;const a=()=>{let l=0;for(let c=0;c<n.length;c++){const u=n[c];u!==null&&o.getQueryParameter(u,o.QUERY_RESULT_AVAILABLE)&&(o.getQueryParameter(u,o.QUERY_RESULT)===0&&s.add(i[c]),n[c]=null,o.deleteQuery(u),l++)}l<n.length?requestAnimationFrame(a):t.occluded=s};a()}}isOccluded(e,t){const n=this.get(e);return n.occluded&&n.occluded.has(t)}updateViewport(e){const{state:t}=this,{x:n,y:i,width:s,height:o}=e.viewportValue;t.viewport(n,e.height-o-i,s,o)}updateScissor(e){const{state:t}=this,{x:n,y:i,width:s,height:o}=e.scissorValue;t.scissor(n,e.height-o-i,s,o)}setScissorTest(e){this.state.setScissorTest(e)}getClearColor(){const e=super.getClearColor();return e.r*=e.a,e.g*=e.a,e.b*=e.a,e}clear(e,t,n,i=null,s=!0,o=!0){const{gl:a,renderer:l}=this;i===null&&(i={textures:null,clearColorValue:this.getClearColor()});let c=0;if(e&&(c|=a.COLOR_BUFFER_BIT),t&&(c|=a.DEPTH_BUFFER_BIT),n&&(c|=a.STENCIL_BUFFER_BIT),c!==0){let u;i.clearColorValue?u=i.clearColorValue:u=this.getClearColor();const h=l.getClearDepth(),d=l.getClearStencil();if(t&&this.state.setDepthMask(!0),i.textures===null)a.clearColor(u.r,u.g,u.b,u.a),a.clear(c);else{if(s&&this._setFramebuffer(i),e)for(let f=0;f<i.textures.length;f++)f===0?a.clearBufferfv(a.COLOR,f,[u.r,u.g,u.b,u.a]):a.clearBufferfv(a.COLOR,f,[0,0,0,1]);t&&n?a.clearBufferfi(a.DEPTH_STENCIL,0,h,d):t?a.clearBufferfv(a.DEPTH,0,[h]):n&&a.clearBufferiv(a.STENCIL,0,[d]),s&&o&&this._resolveRenderTarget(i)}}}beginCompute(e){const{state:t,gl:n}=this;t.bindFramebuffer(n.FRAMEBUFFER,null),this.initTimestampQuery(xr.COMPUTE,this.getTimestampUID(e))}compute(e,t,n,i,s=null){const{state:o,gl:a}=this;this.discard===!1&&(o.enable(a.RASTERIZER_DISCARD),this.discard=!0);const{programGPU:l,transformBuffers:c,attributes:u}=this.get(i),h=this._getVaoKey(u),d=this.vaoCache[h];d===void 0?this.vaoCache[h]=this._createVao(u):o.setVertexState(d),o.useProgram(l),this._bindUniforms(n);const f=this._getTransformFeedback(c);a.bindTransformFeedback(a.TRANSFORM_FEEDBACK,f),a.beginTransformFeedback(a.POINTS),s=s!==null?s:t.count,Array.isArray(s)?(Kt("WebGLBackend.compute(): The count parameter must be a single number, not an array."),s=s[0]):s&&typeof s=="object"&&s.isIndirectStorageBufferAttribute&&(Kt("WebGLBackend.compute(): The count parameter must be a single number, not IndirectStorageBufferAttribute"),s=t.count),u[0].isStorageInstancedBufferAttribute?a.drawArraysInstanced(a.POINTS,0,1,s):a.drawArrays(a.POINTS,0,s),a.endTransformFeedback(),a.bindTransformFeedback(a.TRANSFORM_FEEDBACK,null);for(let p=0;p<c.length;p++){const g=c[p];g.pbo&&this.has(g.pbo)&&this.textureUtils.copyBufferToTexture(g.transformBuffer,g.pbo),g.switchBuffers()}}finishCompute(e){const{state:t,gl:n}=this;this.discard=!1,t.disable(n.RASTERIZER_DISCARD),this.prepareTimestampBuffer(xr.COMPUTE,this.getTimestampUID(e)),this._currentContext&&this._setFramebuffer(this._currentContext)}_isRenderCameraDepthArray(e){return e.depthTexture&&e.depthTexture.isArrayTexture&&e.camera.isArrayCamera}_draw(e,t,n,i,s,o){if(e.isBatchedMesh)if(this.hasFeature("WEBGL_multi_draw")===!1){const{gl:a}=this,l=a.getUniformLocation(o,"nodeUniformDrawId"),c=e._multiDrawStarts,u=e._multiDrawCounts,h=e._multiDrawCount;for(let d=0;d<h;d++)a.uniform1ui(l,d),t.render(c[d],u[d])}else t.renderMultiDraw(e._multiDrawStarts,e._multiDrawCounts,e._multiDrawCount);else s>1?t.renderInstances(n,i,s):t.render(n,i)}draw(e){const{object:t,pipeline:n,material:i,context:s,hardwareClippingPlanes:o}=e,{programGPU:a}=this.get(n),{gl:l,state:c}=this,u=this.get(s),h=e.getDrawParameters();if(h===null)return;this._bindUniforms(e.getBindings());const d=t.isMesh&&t.matrixWorld.determinant()<0;c.setMaterial(i,d,o),s.mrt!==null&&s.textures!==null&&c.setMRTBlending(s.textures,s.mrt,i),c.useProgram(a);const f=e.getAttributes(),p=this.get(f);let g=p.vaoGPU;if(g===void 0){const E=this._getVaoKey(f);g=this.vaoCache[E],g===void 0&&(g=this._createVao(f),this.vaoCache[E]=g,p.vaoGPU=g)}const m=e.getIndex(),_=m!==null?this.get(m).bufferGPU:null;c.setVertexState(g,_);const x=u.lastOcclusionObject;if(x!==t&&x!==void 0){if(x!==null&&x.occlusionTest===!0&&(l.endQuery(l.ANY_SAMPLES_PASSED),u.occlusionQueryIndex++),t.occlusionTest===!0){const E=l.createQuery();l.beginQuery(l.ANY_SAMPLES_PASSED,E),u.occlusionQueries[u.occlusionQueryIndex]=E,u.occlusionQueryObjects[u.occlusionQueryIndex]=t}u.lastOcclusionObject=t}const y=this.bufferRenderer;t.isPoints?y.mode=l.POINTS:t.isLineSegments?y.mode=l.LINES:t.isLine?y.mode=l.LINE_STRIP:t.isLineLoop?y.mode=l.LINE_LOOP:i.wireframe===!0?(c.setLineWidth(i.wireframeLinewidth*this.renderer.getPixelRatio()),y.mode=l.LINES):y.mode=l.TRIANGLES;const{vertexCount:b,instanceCount:M}=h;let{firstVertex:S}=h;if(y.object=t,m!==null){S*=m.array.BYTES_PER_ELEMENT;const E=this.get(m);y.index=m.count,y.type=E.type}else y.index=0;if(e.camera.isArrayCamera===!0&&e.camera.cameras.length>0&&e.camera.isMultiViewCamera===!1){const E=this.get(e.camera),v=e.camera.cameras,w=e.getBindingGroup("cameraIndex").bindings[0];if(E.indexesGPU===void 0||E.indexesGPU.length!==v.length){const U=new Uint32Array([0,0,0,0]),B=[];for(let D=0,X=v.length;D<X;D++){const K=l.createBuffer();U[0]=D,l.bindBuffer(l.UNIFORM_BUFFER,K),l.bufferData(l.UNIFORM_BUFFER,U,l.STATIC_DRAW),B.push(K)}E.indexesGPU=B}let N=0;e:for(const U of e.getBindings())for(const B of U.bindings){if(B===w)break e;(B.isUniformsGroup||B.isUniformBuffer)&&N++}const C=this.renderer.getPixelRatio(),F=this._currentContext.renderTarget,V=this._isRenderCameraDepthArray(this._currentContext),z=this._currentContext.activeCubeFace;if(V){const U=this.get(F.depthTexture);if(U.clearedRenderId!==this.renderer._nodes.nodeFrame.renderId){U.clearedRenderId=this.renderer._nodes.nodeFrame.renderId;const{stencilBuffer:B}=F;for(let D=0,X=v.length;D<X;D++)this.renderer._activeCubeFace=D,this._currentContext.activeCubeFace=D,this._setFramebuffer(this._currentContext),this.clear(!1,!0,B,this._currentContext,!1,!1);this.renderer._activeCubeFace=z,this._currentContext.activeCubeFace=z}}for(let U=0,B=v.length;U<B;U++){const D=v[U];if(t.layers.test(D.layers)){V&&(this.renderer._activeCubeFace=U,this._currentContext.activeCubeFace=U,this._setFramebuffer(this._currentContext));const X=D.viewport;if(X!==void 0){const K=X.x*C,fe=X.y*C,Z=X.width*C,oe=X.height*C;c.viewport(Math.floor(K),Math.floor(e.context.height-oe-fe),Math.floor(Z),Math.floor(oe))}c.bindBufferBase(l.UNIFORM_BUFFER,N,E.indexesGPU[U]),this._draw(t,y,S,b,M,a)}this._currentContext.activeCubeFace=z,this.renderer._activeCubeFace=z}}else this._draw(t,y,S,b,M,a)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e,t=!1){this.textureUtils.destroyTexture(e,t)}async copyTextureToBuffer(e,t,n,i,s,o){return this.textureUtils.copyTextureToBuffer(e,t,n,i,s,o)}updateSampler(){return""}createNodeBuilder(e,t){return new bB(e,t)}createProgram(e){const t=this.gl,{stage:n,code:i}=e,s=n==="fragment"?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(s,i),t.compileShader(s),this.set(e,{shaderGPU:s})}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){const n=this.gl,i=e.pipeline,{fragmentProgram:s,vertexProgram:o}=i,a=n.createProgram(),l=this.get(s).shaderGPU,c=this.get(o).shaderGPU;if(n.attachShader(a,l),n.attachShader(a,c),n.linkProgram(a),this.set(i,{programGPU:a,fragmentShader:l,vertexShader:c}),t!==null&&this.parallel){const u=new Promise(h=>{const d=this.parallel,f=()=>{n.getProgramParameter(a,d.COMPLETION_STATUS_KHR)?(this._completeCompile(e,i),h()):requestAnimationFrame(f)};f()});t.push(u);return}this._completeCompile(e,i)}_handleSource(e,t){const n=e.split(`
4791
4791
  `),i=[],s=Math.max(t-6,0),o=Math.min(t+6,n.length);for(let a=s;a<o;a++){const l=a+1;i.push(`${l===t?">":" "} ${l}: ${n[a]}`)}return i.join(`
4792
4792
  `)}_getShaderErrors(e,t,n){const i=e.getShaderParameter(t,e.COMPILE_STATUS),o=(e.getShaderInfoLog(t)||"").trim();if(i&&o==="")return"";const a=/ERROR: 0:(\d+)/.exec(o);if(a){const l=parseInt(a[1]);return n.toUpperCase()+`
4793
4793
 
@@ -4799,7 +4799,7 @@ Program Info Log: `+o+`
4799
4799
  `+a+`
4800
4800
  `+l)}else o!==""&&ae("WebGLProgram: Program Info Log:",o)}}_completeCompile(e,t){const{state:n,gl:i}=this,s=this.get(t),{programGPU:o,fragmentShader:a,vertexShader:l}=s;i.getProgramParameter(o,i.LINK_STATUS)===!1&&this._logProgramError(o,a,l),n.useProgram(o);const c=e.getBindings();this._setupBindings(c,o),this.set(t,{programGPU:o,pipeline:o})}createComputePipeline(e,t){const{state:n,gl:i}=this,s={stage:"fragment",code:`#version 300 es
4801
4801
  precision highp float;
4802
- void main() {}`};this.createProgram(s);const{computeProgram:o}=e,a=i.createProgram(),l=this.get(s).shaderGPU,c=this.get(o).shaderGPU,u=o.transforms,h=[],d=[];for(let m=0;m<u.length;m++){const _=u[m];h.push(_.varyingName),d.push(_.attributeNode)}i.attachShader(a,l),i.attachShader(a,c),i.transformFeedbackVaryings(a,h,i.SEPARATE_ATTRIBS),i.linkProgram(a),i.getProgramParameter(a,i.LINK_STATUS)===!1&&this._logProgramError(a,l,c),n.useProgram(a),this._setupBindings(t,a);const f=o.attributes,p=[],g=[];for(let m=0;m<f.length;m++){const _=f[m].node.attribute;p.push(_),this.has(_)||this.attributeUtils.createAttribute(_,i.ARRAY_BUFFER)}for(let m=0;m<d.length;m++){const _=d[m].attribute;this.has(_)||this.attributeUtils.createAttribute(_,i.ARRAY_BUFFER);const x=this.get(_);g.push(x)}this.set(e,{programGPU:a,transformBuffers:g,attributes:p})}createBindings(e,t){if(this._knownBindings.has(t)===!1){this._knownBindings.add(t);let n=0,i=0;for(const s of t){this.set(s,{textures:i,uniformBuffers:n});for(const o of s.bindings)o.isUniformBuffer&&n++,o.isSampledTexture&&i++}}this.updateBindings(e,t)}updateBindings(e){const{gl:t}=this;for(const n of e.bindings){const i=this.get(n);if(n.isUniformsGroup||n.isUniformBuffer){const s=n.buffer;let{bufferGPU:o}=this.get(s);o===void 0?(o=t.createBuffer(),t.bindBuffer(t.UNIFORM_BUFFER,o),t.bufferData(t.UNIFORM_BUFFER,s.byteLength,t.DYNAMIC_DRAW),this.set(s,{bufferGPU:o})):t.bindBuffer(t.UNIFORM_BUFFER,o);const a=n.updateRanges;if(t.bindBuffer(t.UNIFORM_BUFFER,o),a.length===0)t.bufferData(t.UNIFORM_BUFFER,s,t.DYNAMIC_DRAW);else{const l=gh(s),c=l?1:s.BYTES_PER_ELEMENT;for(let u=0,h=a.length;u<h;u++){const d=a[u],f=d.start*c,p=d.count*c,g=f*(l?s.BYTES_PER_ELEMENT:1);t.bufferSubData(t.UNIFORM_BUFFER,g,s,f,p)}}i.bufferGPU=o,this.set(n,i)}else if(n.isSampledTexture){const{textureGPU:s,glTextureType:o}=this.get(n.texture);i.textureGPU=s,i.glTextureType=o,this.set(n,i)}}}updateBinding(e){const t=this.gl;if(e.isUniformsGroup||e.isUniformBuffer){const i=this.get(e).bufferGPU,s=e.buffer,o=e.updateRanges;if(t.bindBuffer(t.UNIFORM_BUFFER,i),o.length===0)t.bufferData(t.UNIFORM_BUFFER,s,t.DYNAMIC_DRAW);else{const a=gh(s),l=a?1:s.BYTES_PER_ELEMENT;for(let c=0,u=o.length;c<u;c++){const h=o[c],d=h.start*l,f=h.count*l,p=d*(a?s.BYTES_PER_ELEMENT:1);t.bufferSubData(t.UNIFORM_BUFFER,p,s,d,f)}}}}createIndexAttribute(e){const t=this.gl;this.attributeUtils.createAttribute(e,t.ELEMENT_ARRAY_BUFFER)}createAttribute(e){if(this.has(e))return;const t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}createStorageAttribute(e){if(this.has(e))return;const t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}hasFeature(e){const t=Object.keys(p0).filter(i=>p0[i]===e),n=this.extensions;for(let i=0;i<t.length;i++)if(n.has(t[i]))return!0;return!1}copyTextureToTexture(e,t,n=null,i=null,s=0,o=0){this.textureUtils.copyTextureToTexture(e,t,n,i,s,o)}copyFramebufferToTexture(e,t,n){this.textureUtils.copyFramebufferToTexture(e,t,n)}hasCompatibility(e){return e===wo.TEXTURE_COMPARE?!0:super.hasCompatibility(e)}initRenderTarget(e){const{gl:t,state:n}=this;this._setFramebuffer(e),n.bindFramebuffer(t.FRAMEBUFFER,null)}_setFramebuffer(e){const{gl:t,state:n}=this;let i=null;if(e.textures!==null){const s=e.renderTarget,o=this.get(s),{samples:a,depthBuffer:l,stencilBuffer:c}=s,u=s.isCubeRenderTarget===!0,h=s.isRenderTarget3D===!0,d=s.depth>1,f=s.isXRRenderTarget===!0,p=f===!0&&s._hasExternalTextures===!0;let g=o.msaaFrameBuffer,m=o.depthRenderbuffer;const _=this.extensions.get("WEBGL_multisampled_render_to_texture"),x=this.extensions.get("OVR_multiview2"),y=this._useMultisampledExtension(s),b=vb(e);let M;if(u?(o.cubeFramebuffers||(o.cubeFramebuffers={}),M=o.cubeFramebuffers[b]):f&&p===!1?M=this._xrFramebuffer:(o.framebuffers||(o.framebuffers={}),M=o.framebuffers[b]),M===void 0){M=t.createFramebuffer(),n.bindFramebuffer(t.FRAMEBUFFER,M);const S=e.textures,E=[];if(u){o.cubeFramebuffers[b]=M;const{textureGPU:w}=this.get(S[0]),N=this.renderer._activeCubeFace,C=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+N,w,C)}else{o.framebuffers[b]=M;for(let w=0;w<S.length;w++){const N=S[w],C=this.get(N);C.renderTarget=e.renderTarget,C.cacheKey=b;const F=t.COLOR_ATTACHMENT0+w;if(s.multiview)x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,F,C.textureGPU,0,a,0,2);else if(h||d){const V=this.renderer._activeCubeFace,z=this.renderer._activeMipmapLevel;t.framebufferTextureLayer(t.FRAMEBUFFER,F,C.textureGPU,z,V)}else if(y)_.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,F,t.TEXTURE_2D,C.textureGPU,0,a);else{const V=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,F,t.TEXTURE_2D,C.textureGPU,V)}}}const v=c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(s._autoAllocateDepthBuffer===!0){const w=t.createRenderbuffer();this.textureUtils.setupRenderBufferStorage(w,e,0,y),o.xrDepthRenderbuffer=w,E.push(c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT),t.bindRenderbuffer(t.RENDERBUFFER,w),t.framebufferRenderbuffer(t.FRAMEBUFFER,v,t.RENDERBUFFER,w)}else if(e.depthTexture!==null){E.push(c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT);const w=this.get(e.depthTexture);if(w.renderTarget=e.renderTarget,w.cacheKey=b,s.multiview)x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,v,w.textureGPU,0,a,0,2);else if(p&&y)_.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,v,t.TEXTURE_2D,w.textureGPU,0,a);else if(e.depthTexture.isArrayTexture){const N=this.renderer._activeCubeFace;t.framebufferTextureLayer(t.FRAMEBUFFER,v,w.textureGPU,0,N)}else if(e.depthTexture.isCubeTexture){const N=this.renderer._activeCubeFace;t.framebufferTexture2D(t.FRAMEBUFFER,v,t.TEXTURE_CUBE_MAP_POSITIVE_X+N,w.textureGPU,0)}else t.framebufferTexture2D(t.FRAMEBUFFER,v,t.TEXTURE_2D,w.textureGPU,0)}o.depthInvalidationArray=E}else{if(this._isRenderCameraDepthArray(e)){n.bindFramebuffer(t.FRAMEBUFFER,M);const E=this.renderer._activeCubeFace,v=this.get(e.depthTexture),w=c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;t.framebufferTextureLayer(t.FRAMEBUFFER,w,v.textureGPU,0,E)}if((f||y||s.multiview)&&s._isOpaqueFramebuffer!==!0){n.bindFramebuffer(t.FRAMEBUFFER,M);const E=this.get(e.textures[0]);s.multiview?x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,E.textureGPU,0,a,0,2):y?_.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,E.textureGPU,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,E.textureGPU,0);const v=c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(s._autoAllocateDepthBuffer===!0){const w=o.xrDepthRenderbuffer;t.bindRenderbuffer(t.RENDERBUFFER,w),t.framebufferRenderbuffer(t.FRAMEBUFFER,v,t.RENDERBUFFER,w)}else{const w=this.get(e.depthTexture);s.multiview?x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,v,w.textureGPU,0,a,0,2):y?_.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,v,t.TEXTURE_2D,w.textureGPU,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,v,t.TEXTURE_2D,w.textureGPU,0)}}}if(a>0&&y===!1&&!s.multiview){if(g===void 0){const S=[];g=t.createFramebuffer(),n.bindFramebuffer(t.FRAMEBUFFER,g);const E=[],v=e.textures;for(let w=0;w<v.length;w++){E[w]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,E[w]),S.push(t.COLOR_ATTACHMENT0+w);const N=e.textures[w],C=this.get(N);t.renderbufferStorageMultisample(t.RENDERBUFFER,a,C.glInternalFormat,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+w,t.RENDERBUFFER,E[w])}if(t.bindRenderbuffer(t.RENDERBUFFER,null),o.msaaFrameBuffer=g,o.msaaRenderbuffers=E,l&&m===void 0){m=t.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(m,e,a),o.depthRenderbuffer=m;const w=c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;S.push(w)}o.invalidationArray=S}i=o.msaaFrameBuffer}else i=M;n.drawBuffers(e,M)}n.bindFramebuffer(t.FRAMEBUFFER,i)}_getVaoKey(e){let t="";for(let n=0;n<e.length;n++){const i=this.get(e[n]);t+=":"+i.id}return t}_createVao(e){const{gl:t}=this,n=t.createVertexArray();t.bindVertexArray(n);for(let i=0;i<e.length;i++){const s=e[i],o=this.get(s);t.bindBuffer(t.ARRAY_BUFFER,o.bufferGPU),t.enableVertexAttribArray(i);let a,l;s.isInterleavedBufferAttribute===!0?(a=s.data.stride*o.bytesPerElement,l=s.offset*o.bytesPerElement):(a=0,l=0),o.isInteger?t.vertexAttribIPointer(i,s.itemSize,o.type,a,l):t.vertexAttribPointer(i,s.itemSize,o.type,s.normalized,a,l),s.isInstancedBufferAttribute&&!s.isInterleavedBufferAttribute?t.vertexAttribDivisor(i,s.meshPerAttribute):s.isInterleavedBufferAttribute&&s.data.isInstancedInterleavedBuffer&&t.vertexAttribDivisor(i,s.data.meshPerAttribute)}return t.bindBuffer(t.ARRAY_BUFFER,null),n}_getTransformFeedback(e){let t="";for(let s=0;s<e.length;s++)t+=":"+e[s].id;let n=this.transformFeedbackCache[t];if(n!==void 0)return n;const{gl:i}=this;n=i.createTransformFeedback(),i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,n);for(let s=0;s<e.length;s++){const o=e[s];i.bindBufferBase(i.TRANSFORM_FEEDBACK_BUFFER,s,o.transformBuffer)}return i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[t]=n,n}_setupBindings(e,t){const n=this.gl;let i=0,s=0;for(const o of e)for(const a of o.bindings)if(a.isUniformsGroup||a.isUniformBuffer){const l=i++,c=n.getUniformBlockIndex(t,a.name);n.uniformBlockBinding(t,c,l)}else if(a.isSampledTexture){const l=s++,c=n.getUniformLocation(t,a.name);n.uniform1i(c,l)}}_bindUniforms(e){const{gl:t,state:n}=this;let i=0,s=0;for(const o of e)for(const a of o.bindings){const l=this.get(a);if(a.isUniformsGroup||a.isUniformBuffer){const c=i++;n.bindBufferBase(t.UNIFORM_BUFFER,c,l.bufferGPU)}else if(a.isSampledTexture){const c=s++;n.bindTexture(l.glTextureType,l.textureGPU,t.TEXTURE0+c)}}}_resolveRenderTarget(e){const{gl:t,state:n}=this,i=e.renderTarget;if(e.textures!==null&&i){const s=this.get(i);if(i.samples>0&&this._useMultisampledExtension(i)===!1){const o=s.framebuffers[e.getCacheKey()];let a=t.COLOR_BUFFER_BIT;i.resolveDepthBuffer&&(i.depthBuffer&&(a|=t.DEPTH_BUFFER_BIT),i.stencilBuffer&&i.resolveStencilBuffer&&(a|=t.STENCIL_BUFFER_BIT));const l=s.msaaFrameBuffer,c=s.msaaRenderbuffers,u=e.textures,h=u.length>1;if(n.bindFramebuffer(t.READ_FRAMEBUFFER,l),n.bindFramebuffer(t.DRAW_FRAMEBUFFER,o),h)for(let d=0;d<u.length;d++)t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0+d,t.RENDERBUFFER,null),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+d,t.TEXTURE_2D,null,0);for(let d=0;d<u.length;d++){if(h){const{textureGPU:f}=this.get(u[d]);t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,c[d]),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,f,0)}if(e.scissor){const{x:f,y:p,width:g,height:m}=e.scissorValue,_=e.height-m-p;t.blitFramebuffer(f,_,f+g,_+m,f,_,f+g,_+m,a,t.NEAREST)}else t.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,a,t.NEAREST)}if(h)for(let d=0;d<u.length;d++){const{textureGPU:f}=this.get(u[d]);t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0+d,t.RENDERBUFFER,c[d]),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+d,t.TEXTURE_2D,f,0)}this._supportsInvalidateFramebuffer===!0&&t.invalidateFramebuffer(t.READ_FRAMEBUFFER,s.invalidationArray)}else if(i.resolveDepthBuffer===!1&&s.framebuffers){const o=s.framebuffers[e.getCacheKey()];n.bindFramebuffer(t.DRAW_FRAMEBUFFER,o),t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,s.depthInvalidationArray)}}}_useMultisampledExtension(e){return e.multiview===!0?!0:e.samples>0&&this.extensions.has("WEBGL_multisampled_render_to_texture")===!0&&e._autoAllocateDepthBuffer!==!1}dispose(){this.textureUtils!==null&&this.textureUtils.dispose();const e=this.extensions.get("WEBGL_lose_context");e&&e.loseContext(),this.renderer.domElement.removeEventListener("webglcontextlost",this._onContextLost)}}const Qu={PointList:"point-list",LineList:"line-list",LineStrip:"line-strip",TriangleList:"triangle-list"},yr=typeof self<"u"&&self.GPUShaderStage?self.GPUShaderStage:{VERTEX:1,FRAGMENT:2,COMPUTE:4},Ln={Never:"never",Less:"less",Equal:"equal",LessEqual:"less-equal",Greater:"greater",NotEqual:"not-equal",GreaterEqual:"greater-equal",Always:"always"},Jn={Store:"store"},wt={Load:"load",Clear:"clear"},g0={CCW:"ccw",CW:"cw"},_0={None:"none",Back:"back"},Ph={Uint16:"uint16",Uint32:"uint32"},L={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R16Unorm:"r16unorm",R16Snorm:"r16snorm",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RG16Unorm:"rg16unorm",RG16Snorm:"rg16snorm",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10UFloat:"rg11b10ufloat",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA16Unorm:"rgba16unorm",RGBA16Snorm:"rgba16snorm",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-unorm-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},Vf={ClampToEdge:"clamp-to-edge",Repeat:"repeat",MirrorRepeat:"mirror-repeat"},cr={Linear:"linear",Nearest:"nearest"},_t={Zero:"zero",One:"one",Src:"src",OneMinusSrc:"one-minus-src",SrcAlpha:"src-alpha",OneMinusSrcAlpha:"one-minus-src-alpha",Dst:"dst",OneMinusDst:"one-minus-dst",DstAlpha:"dst-alpha",OneMinusDstAlpha:"one-minus-dst-alpha",SrcAlphaSaturated:"src-alpha-saturated",Constant:"constant",OneMinusConstant:"one-minus-constant"},Zs={Add:"add",Subtract:"subtract",ReverseSubtract:"reverse-subtract",Min:"min",Max:"max"},x0={None:0,All:15},fs={Keep:"keep",Zero:"zero",Replace:"replace",Invert:"invert",IncrementClamp:"increment-clamp",DecrementClamp:"decrement-clamp",IncrementWrap:"increment-wrap",DecrementWrap:"decrement-wrap"},zf={Storage:"storage",ReadOnlyStorage:"read-only-storage"},Hf={WriteOnly:"write-only",ReadOnly:"read-only",ReadWrite:"read-write"},y0={NonFiltering:"non-filtering",Comparison:"comparison"},Qs={Float:"float",UnfilterableFloat:"unfilterable-float",Depth:"depth",SInt:"sint",UInt:"uint"},v0={TwoD:"2d",ThreeD:"3d"},Wn={TwoD:"2d",TwoDArray:"2d-array",Cube:"cube",ThreeD:"3d"},DB={All:"all"},Ju={Vertex:"vertex",Instance:"instance"},Dh={CoreFeaturesAndLimits:"core-features-and-limits",DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionBCSliced3D:"texture-compression-bc-sliced-3d",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TextureCompressionASTCSliced3D:"texture-compression-astc-sliced-3d",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",Float32Blendable:"float32-blendable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups",TextureFormatsTier1:"texture-formats-tier1",TextureFormatsTier2:"texture-formats-tier2"},b0={"texture-compression-s3tc":"texture-compression-bc","texture-compression-etc1":"texture-compression-etc2"};class LB extends Gb{constructor(e,t,n){super(e,t?t.value:null),this.textureNode=t,this.groupNode=n}update(){const{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}}class UB extends Ib{constructor(e,t){super(e,t?t.array:null),this._attribute=t,this.isStorageBuffer=!0}get attribute(){return this._attribute}}let FB=0;class IB extends UB{constructor(e,t){super("StorageBuffer_"+FB++,e?e.value:null),this.nodeUniform=e,this.access=e?e.access:Fi.READ_WRITE,this.groupNode=t}get attribute(){return this.nodeUniform.value}get buffer(){return this.nodeUniform.value.array}}class BB extends Gs{constructor(e){super(),this.device=e;const t=`
4802
+ void main() {}`};this.createProgram(s);const{computeProgram:o}=e,a=i.createProgram(),l=this.get(s).shaderGPU,c=this.get(o).shaderGPU,u=o.transforms,h=[],d=[];for(let m=0;m<u.length;m++){const _=u[m];h.push(_.varyingName),d.push(_.attributeNode)}i.attachShader(a,l),i.attachShader(a,c),i.transformFeedbackVaryings(a,h,i.SEPARATE_ATTRIBS),i.linkProgram(a),i.getProgramParameter(a,i.LINK_STATUS)===!1&&this._logProgramError(a,l,c),n.useProgram(a),this._setupBindings(t,a);const f=o.attributes,p=[],g=[];for(let m=0;m<f.length;m++){const _=f[m].node.attribute;p.push(_),this.has(_)||this.attributeUtils.createAttribute(_,i.ARRAY_BUFFER)}for(let m=0;m<d.length;m++){const _=d[m].attribute;this.has(_)||this.attributeUtils.createAttribute(_,i.ARRAY_BUFFER);const x=this.get(_);g.push(x)}this.set(e,{programGPU:a,transformBuffers:g,attributes:p})}createBindings(e,t){if(this._knownBindings.has(t)===!1){this._knownBindings.add(t);let n=0,i=0;for(const s of t){this.set(s,{textures:i,uniformBuffers:n});for(const o of s.bindings)o.isUniformBuffer&&n++,o.isSampledTexture&&i++}}this.updateBindings(e,t)}updateBindings(e){const{gl:t}=this;for(const n of e.bindings){const i=this.get(n);if(n.isUniformsGroup||n.isUniformBuffer){const s=n.buffer;let{bufferGPU:o}=this.get(s);o===void 0?(o=t.createBuffer(),t.bindBuffer(t.UNIFORM_BUFFER,o),t.bufferData(t.UNIFORM_BUFFER,s.byteLength,t.DYNAMIC_DRAW),this.set(s,{bufferGPU:o})):t.bindBuffer(t.UNIFORM_BUFFER,o);const a=n.updateRanges;if(t.bindBuffer(t.UNIFORM_BUFFER,o),a.length===0)t.bufferData(t.UNIFORM_BUFFER,s,t.DYNAMIC_DRAW);else{const l=gh(s),c=l?1:s.BYTES_PER_ELEMENT;for(let u=0,h=a.length;u<h;u++){const d=a[u],f=d.start*c,p=d.count*c,g=f*(l?s.BYTES_PER_ELEMENT:1);t.bufferSubData(t.UNIFORM_BUFFER,g,s,f,p)}}i.bufferGPU=o,this.set(n,i)}else if(n.isSampledTexture){const{textureGPU:s,glTextureType:o}=this.get(n.texture);i.textureGPU=s,i.glTextureType=o,this.set(n,i)}}}updateBinding(e){const t=this.gl;if(e.isUniformsGroup||e.isUniformBuffer){const i=this.get(e).bufferGPU,s=e.buffer,o=e.updateRanges;if(t.bindBuffer(t.UNIFORM_BUFFER,i),o.length===0)t.bufferData(t.UNIFORM_BUFFER,s,t.DYNAMIC_DRAW);else{const a=gh(s),l=a?1:s.BYTES_PER_ELEMENT;for(let c=0,u=o.length;c<u;c++){const h=o[c],d=h.start*l,f=h.count*l,p=d*(a?s.BYTES_PER_ELEMENT:1);t.bufferSubData(t.UNIFORM_BUFFER,p,s,d,f)}}}}createIndexAttribute(e){const t=this.gl;this.attributeUtils.createAttribute(e,t.ELEMENT_ARRAY_BUFFER)}createAttribute(e){if(this.has(e))return;const t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}createStorageAttribute(e){if(this.has(e))return;const t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}hasFeature(e){const t=Object.keys(p0).filter(i=>p0[i]===e),n=this.extensions;for(let i=0;i<t.length;i++)if(n.has(t[i]))return!0;return!1}copyTextureToTexture(e,t,n=null,i=null,s=0,o=0){this.textureUtils.copyTextureToTexture(e,t,n,i,s,o)}copyFramebufferToTexture(e,t,n){this.textureUtils.copyFramebufferToTexture(e,t,n)}hasCompatibility(e){return e===wo.TEXTURE_COMPARE?!0:super.hasCompatibility(e)}initRenderTarget(e){const{gl:t,state:n}=this;this._setFramebuffer(e),n.bindFramebuffer(t.FRAMEBUFFER,null)}_setFramebuffer(e){const{gl:t,state:n}=this;let i=null;if(e.textures!==null){const s=e.renderTarget,o=this.get(s),{samples:a,depthBuffer:l,stencilBuffer:c}=s,u=s.isCubeRenderTarget===!0,h=s.isRenderTarget3D===!0,d=s.depth>1,f=s.isXRRenderTarget===!0,p=f===!0&&s._hasExternalTextures===!0;let g=o.msaaFrameBuffer,m=o.depthRenderbuffer;const _=this.extensions.get("WEBGL_multisampled_render_to_texture"),x=this.extensions.get("OVR_multiview2"),y=this._useMultisampledExtension(s),b=vb(e);let M;if(u?(o.cubeFramebuffers||(o.cubeFramebuffers={}),M=o.cubeFramebuffers[b]):f&&p===!1?M=this._xrFramebuffer:(o.framebuffers||(o.framebuffers={}),M=o.framebuffers[b]),M===void 0){M=t.createFramebuffer(),n.bindFramebuffer(t.FRAMEBUFFER,M);const S=e.textures,E=[];if(u){o.cubeFramebuffers[b]=M;const{textureGPU:w}=this.get(S[0]),N=this.renderer._activeCubeFace,C=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+N,w,C)}else{o.framebuffers[b]=M;for(let w=0;w<S.length;w++){const N=S[w],C=this.get(N);C.renderTarget=e.renderTarget,C.cacheKey=b;const F=t.COLOR_ATTACHMENT0+w;if(s.multiview)x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,F,C.textureGPU,0,a,0,2);else if(h||d){const V=this.renderer._activeCubeFace,z=this.renderer._activeMipmapLevel;t.framebufferTextureLayer(t.FRAMEBUFFER,F,C.textureGPU,z,V)}else if(y)_.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,F,t.TEXTURE_2D,C.textureGPU,0,a);else{const V=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,F,t.TEXTURE_2D,C.textureGPU,V)}}}const v=c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(s._autoAllocateDepthBuffer===!0){const w=t.createRenderbuffer();this.textureUtils.setupRenderBufferStorage(w,e,0,y),o.xrDepthRenderbuffer=w,E.push(c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT),t.bindRenderbuffer(t.RENDERBUFFER,w),t.framebufferRenderbuffer(t.FRAMEBUFFER,v,t.RENDERBUFFER,w)}else if(e.depthTexture!==null){E.push(c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT);const w=this.get(e.depthTexture);if(w.renderTarget=e.renderTarget,w.cacheKey=b,s.multiview)x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,v,w.textureGPU,0,a,0,2);else if(p&&y)_.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,v,t.TEXTURE_2D,w.textureGPU,0,a);else if(e.depthTexture.isArrayTexture){const N=this.renderer._activeCubeFace;t.framebufferTextureLayer(t.FRAMEBUFFER,v,w.textureGPU,0,N)}else if(e.depthTexture.isCubeTexture){const N=this.renderer._activeCubeFace;t.framebufferTexture2D(t.FRAMEBUFFER,v,t.TEXTURE_CUBE_MAP_POSITIVE_X+N,w.textureGPU,0)}else t.framebufferTexture2D(t.FRAMEBUFFER,v,t.TEXTURE_2D,w.textureGPU,0)}o.depthInvalidationArray=E}else{if(this._isRenderCameraDepthArray(e)){n.bindFramebuffer(t.FRAMEBUFFER,M);const E=this.renderer._activeCubeFace,v=this.get(e.depthTexture),w=c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;t.framebufferTextureLayer(t.FRAMEBUFFER,w,v.textureGPU,0,E)}if((f||y||s.multiview)&&s._isOpaqueFramebuffer!==!0){n.bindFramebuffer(t.FRAMEBUFFER,M);const E=this.get(e.textures[0]);s.multiview?x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,E.textureGPU,0,a,0,2):y?_.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,E.textureGPU,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,E.textureGPU,0);const v=c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(s._autoAllocateDepthBuffer===!0){const w=o.xrDepthRenderbuffer;t.bindRenderbuffer(t.RENDERBUFFER,w),t.framebufferRenderbuffer(t.FRAMEBUFFER,v,t.RENDERBUFFER,w)}else{const w=this.get(e.depthTexture);s.multiview?x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,v,w.textureGPU,0,a,0,2):y?_.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,v,t.TEXTURE_2D,w.textureGPU,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,v,t.TEXTURE_2D,w.textureGPU,0)}}}if(a>0&&y===!1&&!s.multiview){if(g===void 0){const S=[];g=t.createFramebuffer(),n.bindFramebuffer(t.FRAMEBUFFER,g);const E=[],v=e.textures;for(let w=0;w<v.length;w++){E[w]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,E[w]),S.push(t.COLOR_ATTACHMENT0+w);const N=e.textures[w],C=this.get(N);t.renderbufferStorageMultisample(t.RENDERBUFFER,a,C.glInternalFormat,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+w,t.RENDERBUFFER,E[w])}if(t.bindRenderbuffer(t.RENDERBUFFER,null),o.msaaFrameBuffer=g,o.msaaRenderbuffers=E,l&&m===void 0){m=t.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(m,e,a),o.depthRenderbuffer=m;const w=c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;S.push(w)}o.invalidationArray=S}i=o.msaaFrameBuffer}else i=M;n.drawBuffers(e,M)}n.bindFramebuffer(t.FRAMEBUFFER,i)}_getVaoKey(e){let t="";for(let n=0;n<e.length;n++){const i=this.get(e[n]);t+=":"+i.id}return t}_createVao(e){const{gl:t}=this,n=t.createVertexArray();t.bindVertexArray(n);for(let i=0;i<e.length;i++){const s=e[i],o=this.get(s);t.bindBuffer(t.ARRAY_BUFFER,o.bufferGPU),t.enableVertexAttribArray(i);let a,l;s.isInterleavedBufferAttribute===!0?(a=s.data.stride*o.bytesPerElement,l=s.offset*o.bytesPerElement):(a=0,l=0),o.isInteger?t.vertexAttribIPointer(i,s.itemSize,o.type,a,l):t.vertexAttribPointer(i,s.itemSize,o.type,s.normalized,a,l),s.isInstancedBufferAttribute&&!s.isInterleavedBufferAttribute?t.vertexAttribDivisor(i,s.meshPerAttribute):s.isInterleavedBufferAttribute&&s.data.isInstancedInterleavedBuffer&&t.vertexAttribDivisor(i,s.data.meshPerAttribute)}return t.bindBuffer(t.ARRAY_BUFFER,null),n}_getTransformFeedback(e){let t="";for(let s=0;s<e.length;s++)t+=":"+e[s].id;let n=this.transformFeedbackCache[t];if(n!==void 0)return n;const{gl:i}=this;n=i.createTransformFeedback(),i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,n);for(let s=0;s<e.length;s++){const o=e[s];i.bindBufferBase(i.TRANSFORM_FEEDBACK_BUFFER,s,o.transformBuffer)}return i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[t]=n,n}_setupBindings(e,t){const n=this.gl;let i=0,s=0;for(const o of e)for(const a of o.bindings)if(a.isUniformsGroup||a.isUniformBuffer){const l=i++,c=n.getUniformBlockIndex(t,a.name);n.uniformBlockBinding(t,c,l)}else if(a.isSampledTexture){const l=s++,c=n.getUniformLocation(t,a.name);n.uniform1i(c,l)}}_bindUniforms(e){const{gl:t,state:n}=this;let i=0,s=0;for(const o of e)for(const a of o.bindings){const l=this.get(a);if(a.isUniformsGroup||a.isUniformBuffer){const c=i++;n.bindBufferBase(t.UNIFORM_BUFFER,c,l.bufferGPU)}else if(a.isSampledTexture){const c=s++;n.bindTexture(l.glTextureType,l.textureGPU,t.TEXTURE0+c)}}}_resolveRenderTarget(e){const{gl:t,state:n}=this,i=e.renderTarget;if(e.textures!==null&&i){const s=this.get(i);if(i.samples>0&&this._useMultisampledExtension(i)===!1){const o=s.framebuffers[e.getCacheKey()];let a=t.COLOR_BUFFER_BIT;i.resolveDepthBuffer&&(i.depthBuffer&&(a|=t.DEPTH_BUFFER_BIT),i.stencilBuffer&&i.resolveStencilBuffer&&(a|=t.STENCIL_BUFFER_BIT));const l=s.msaaFrameBuffer,c=s.msaaRenderbuffers,u=e.textures,h=u.length>1;if(n.bindFramebuffer(t.READ_FRAMEBUFFER,l),n.bindFramebuffer(t.DRAW_FRAMEBUFFER,o),h)for(let d=0;d<u.length;d++)t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0+d,t.RENDERBUFFER,null),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+d,t.TEXTURE_2D,null,0);for(let d=0;d<u.length;d++){if(h){const{textureGPU:f}=this.get(u[d]);t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,c[d]),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,f,0)}if(e.scissor){const{x:f,y:p,width:g,height:m}=e.scissorValue,_=e.height-m-p;t.blitFramebuffer(f,_,f+g,_+m,f,_,f+g,_+m,a,t.NEAREST)}else t.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,a,t.NEAREST)}if(h)for(let d=0;d<u.length;d++){const{textureGPU:f}=this.get(u[d]);t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0+d,t.RENDERBUFFER,c[d]),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+d,t.TEXTURE_2D,f,0)}this._supportsInvalidateFramebuffer===!0&&t.invalidateFramebuffer(t.READ_FRAMEBUFFER,s.invalidationArray)}else if(i.resolveDepthBuffer===!1&&s.framebuffers){const o=s.framebuffers[e.getCacheKey()];n.bindFramebuffer(t.DRAW_FRAMEBUFFER,o),t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,s.depthInvalidationArray)}}}_useMultisampledExtension(e){return e.multiview===!0?!0:e.samples>0&&this.extensions.has("WEBGL_multisampled_render_to_texture")===!0&&e._autoAllocateDepthBuffer!==!1}dispose(){this.textureUtils!==null&&this.textureUtils.dispose();const e=this.extensions.get("WEBGL_lose_context");e&&e.loseContext(),this.renderer.domElement.removeEventListener("webglcontextlost",this._onContextLost)}}const Qu={PointList:"point-list",LineList:"line-list",LineStrip:"line-strip",TriangleList:"triangle-list"},yr=typeof self<"u"&&self.GPUShaderStage?self.GPUShaderStage:{VERTEX:1,FRAGMENT:2,COMPUTE:4},Ln={Never:"never",Less:"less",Equal:"equal",LessEqual:"less-equal",Greater:"greater",NotEqual:"not-equal",GreaterEqual:"greater-equal",Always:"always"},Jn={Store:"store"},wt={Load:"load",Clear:"clear"},g0={CCW:"ccw",CW:"cw"},_0={None:"none",Back:"back"},Ph={Uint16:"uint16",Uint32:"uint32"},L={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R16Unorm:"r16unorm",R16Snorm:"r16snorm",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RG16Unorm:"rg16unorm",RG16Snorm:"rg16snorm",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10UFloat:"rg11b10ufloat",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA16Unorm:"rgba16unorm",RGBA16Snorm:"rgba16snorm",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-unorm-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},Vf={ClampToEdge:"clamp-to-edge",Repeat:"repeat",MirrorRepeat:"mirror-repeat"},cr={Linear:"linear",Nearest:"nearest"},_t={Zero:"zero",One:"one",Src:"src",OneMinusSrc:"one-minus-src",SrcAlpha:"src-alpha",OneMinusSrcAlpha:"one-minus-src-alpha",Dst:"dst",OneMinusDst:"one-minus-dst",DstAlpha:"dst-alpha",OneMinusDstAlpha:"one-minus-dst-alpha",SrcAlphaSaturated:"src-alpha-saturated",Constant:"constant",OneMinusConstant:"one-minus-constant"},Zs={Add:"add",Subtract:"subtract",ReverseSubtract:"reverse-subtract",Min:"min",Max:"max"},x0={None:0,All:15},fs={Keep:"keep",Zero:"zero",Replace:"replace",Invert:"invert",IncrementClamp:"increment-clamp",DecrementClamp:"decrement-clamp",IncrementWrap:"increment-wrap",DecrementWrap:"decrement-wrap"},zf={Storage:"storage",ReadOnlyStorage:"read-only-storage"},Hf={WriteOnly:"write-only",ReadOnly:"read-only",ReadWrite:"read-write"},y0={NonFiltering:"non-filtering",Comparison:"comparison"},Qs={Float:"float",UnfilterableFloat:"unfilterable-float",Depth:"depth",SInt:"sint",UInt:"uint"},v0={TwoD:"2d",ThreeD:"3d"},Wn={TwoD:"2d",TwoDArray:"2d-array",Cube:"cube",ThreeD:"3d"},DB={All:"all"},Ju={Vertex:"vertex",Instance:"instance"},Dh={CoreFeaturesAndLimits:"core-features-and-limits",DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionBCSliced3D:"texture-compression-bc-sliced-3d",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TextureCompressionASTCSliced3D:"texture-compression-astc-sliced-3d",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",Float32Blendable:"float32-blendable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups",TextureFormatsTier1:"texture-formats-tier1",TextureFormatsTier2:"texture-formats-tier2"},b0={"texture-compression-s3tc":"texture-compression-bc","texture-compression-etc1":"texture-compression-etc2"};class LB extends Gb{constructor(e,t,n){super(e,t?t.value:null),this.textureNode=t,this.groupNode=n}update(){const{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}}class UB extends Ib{constructor(e,t){super(e,t?t.array:null),this._attribute=t,this.isStorageBuffer=!0}get attribute(){return this._attribute}}let FB=0;class IB extends UB{constructor(e,t){super("StorageBuffer_"+FB++,e?e.value:null),this.nodeUniform=e,this.access=e?e.access:Ui.READ_WRITE,this.groupNode=t}get attribute(){return this.nodeUniform.value}get buffer(){return this.nodeUniform.value.array}}class BB extends Gs{constructor(e){super(),this.device=e;const t=`
4803
4803
  struct VarysStruct {
4804
4804
  @builtin( position ) Position: vec4f,
4805
4805
  @location( 0 ) vTex : vec2f,
@@ -4873,7 +4873,7 @@ fn main_cube( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> {
4873
4873
  return textureSample( imgCube, imgSampler, faceMat[ Varys.vBaseArrayLayer ] * vec3f( fract( Varys.vTex ), 1 ) );
4874
4874
 
4875
4875
  }
4876
- `;this.mipmapSampler=e.createSampler({minFilter:cr.Linear}),this.flipYSampler=e.createSampler({minFilter:cr.Nearest}),this.flipUniformBuffer=e.createBuffer({size:4,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),e.queue.writeBuffer(this.flipUniformBuffer,0,new Uint32Array([1])),this.noFlipUniformBuffer=e.createBuffer({size:4,usage:GPUBufferUsage.UNIFORM}),this.transferPipelines={},this.mipmapShaderModule=e.createShaderModule({label:"mipmap",code:t})}getTransferPipeline(e,t){t=t||"2d-array";const n=`${e}-${t}`;let i=this.transferPipelines[n];return i===void 0&&(i=this.device.createRenderPipeline({label:`mipmap-${e}-${t}`,vertex:{module:this.mipmapShaderModule},fragment:{module:this.mipmapShaderModule,entryPoint:`main_${t.replace("-","_")}`,targets:[{format:e}]},layout:"auto"}),this.transferPipelines[n]=i),i}flipY(e,t,n=0){const i=t.format,{width:s,height:o}=t.size,a=this.device.createTexture({size:{width:s,height:o},format:i,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=this.getTransferPipeline(i,e.textureBindingViewDimension),c=this.getTransferPipeline(i,a.textureBindingViewDimension),u=this.device.createCommandEncoder({}),h=(d,f,p,g,m,_)=>{const x=d.getBindGroupLayout(0),y=this.device.createBindGroup({layout:x,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:f.createView({dimension:f.textureBindingViewDimension||"2d-array",baseMipLevel:0,mipLevelCount:1})},{binding:2,resource:{buffer:_?this.flipUniformBuffer:this.noFlipUniformBuffer}}]}),b=u.beginRenderPass({colorAttachments:[{view:g.createView({dimension:"2d",baseMipLevel:0,mipLevelCount:1,baseArrayLayer:m,arrayLayerCount:1}),loadOp:wt.Clear,storeOp:Jn.Store}]});b.setPipeline(d),b.setBindGroup(0,y),b.draw(3,1,0,p),b.end()};h(l,e,n,a,0,!1),h(c,a,0,e,n,!0),this.device.queue.submit([u.finish()]),a.destroy()}generateMipmaps(e,t=null){const n=this.get(e),i=n.layers||this._mipmapCreateBundles(e),s=t||this.device.createCommandEncoder({label:"mipmapEncoder"});this._mipmapRunBundles(s,i),t===null&&this.device.queue.submit([s.finish()]),n.layers=i}_mipmapCreateBundles(e){const t=e.textureBindingViewDimension||"2d-array",n=this.getTransferPipeline(e.format,t),i=n.getBindGroupLayout(0),s=[];for(let o=1;o<e.mipLevelCount;o++)for(let a=0;a<e.depthOrArrayLayers;a++){const l=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:this.mipmapSampler},{binding:1,resource:e.createView({dimension:t,baseMipLevel:o-1,mipLevelCount:1})},{binding:2,resource:{buffer:this.noFlipUniformBuffer}}]}),c={colorAttachments:[{view:e.createView({dimension:"2d",baseMipLevel:o,mipLevelCount:1,baseArrayLayer:a,arrayLayerCount:1}),loadOp:wt.Clear,storeOp:Jn.Store}]},u=this.device.createRenderBundleEncoder({colorFormats:[e.format]});u.setPipeline(n),u.setBindGroup(0,l),u.draw(3,1,0,a),s.push({renderBundles:[u.finish()],passDescriptor:c})}return s}_mipmapRunBundles(e,t){const n=t.length;for(let i=0;i<n;i++){const s=t[i],o=e.beginRenderPass(s.passDescriptor);o.executeBundles(s.renderBundles),o.end()}}}const OB={[tm]:"never",[Ih]:"less",[nm]:"equal",[Os]:"less-equal",[vc]:"greater",[Zr]:"greater-equal",[rm]:"always",[im]:"not-equal"},kB=[0,1,3,2,4,5];class GB{constructor(e){this.backend=e,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this._samplerCache=new Map}updateSampler(e){const t=this.backend,n=e.minFilter+"-"+e.magFilter+"-"+e.wrapS+"-"+e.wrapT+"-"+(e.wrapR||"0")+"-"+e.anisotropy+"-"+(e.compareFunction||0);let i=this._samplerCache.get(n);if(i===void 0){const o={addressModeU:this._convertAddressMode(e.wrapS),addressModeV:this._convertAddressMode(e.wrapT),addressModeW:this._convertAddressMode(e.wrapR),magFilter:this._convertFilterMode(e.magFilter),minFilter:this._convertFilterMode(e.minFilter),mipmapFilter:this._convertFilterMode(e.minFilter),maxAnisotropy:1};e.isDepthTexture&&e.compareFunction===null&&(o.magFilter=cr.Nearest,o.minFilter=cr.Nearest,o.mipmapFilter=cr.Nearest),o.magFilter===cr.Linear&&o.minFilter===cr.Linear&&o.mipmapFilter===cr.Linear&&(o.maxAnisotropy=e.anisotropy),e.isDepthTexture&&e.compareFunction!==null&&t.hasCompatibility(wo.TEXTURE_COMPARE)&&(o.compare=OB[e.compareFunction]),i={sampler:t.device.createSampler(o),usedTimes:0},this._samplerCache.set(n,i)}const s=t.get(e);if(s.sampler!==i.sampler){if(s.sampler!==void 0){const o=this._samplerCache.get(s.samplerKey);o.usedTimes--,o.usedTimes===0&&this._samplerCache.delete(s.samplerKey)}s.samplerKey=n,s.sampler=i.sampler,i.usedTimes++}return n}createDefaultTexture(e){let t;const n=Np(e,this.backend.device);e.isCubeTexture?t=this._getDefaultCubeTextureGPU(n):t=this._getDefaultTextureGPU(n),this.backend.get(e).texture=t}createTexture(e,t={}){const n=this.backend,i=n.get(e);if(i.initialized)throw new Error("WebGPUTextureUtils: Texture already initialized.");if(e.isExternalTexture){i.texture=e.sourceTexture,i.initialized=!0;return}t.needsMipmaps===void 0&&(t.needsMipmaps=!1),t.levels===void 0&&(t.levels=1),t.depth===void 0&&(t.depth=1);const{width:s,height:o,depth:a,levels:l}=t;e.isFramebufferTexture&&(t.renderTarget?t.format=this.backend.utils.getCurrentColorFormat(t.renderTarget):t.format=this.backend.utils.getPreferredCanvasFormat());const c=this._getDimension(e),u=e.internalFormat||t.format||Np(e,n.device);i.format=u;const{samples:h,primarySamples:d,isMSAA:f}=n.utils.getTextureSampleData(e);let p=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;e.isStorageTexture===!0&&(p|=GPUTextureUsage.STORAGE_BINDING),e.isCompressedTexture!==!0&&e.isCompressedArrayTexture!==!0&&u!==L.RGB9E5UFloat&&(p|=GPUTextureUsage.RENDER_ATTACHMENT);const g={label:e.name,size:{width:s,height:o,depthOrArrayLayers:a},mipLevelCount:l,sampleCount:d,dimension:c,format:u,usage:p};if(u===void 0){ae("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(e);return}e.isCubeTexture&&(g.textureBindingViewDimension=Wn.Cube);try{i.texture=n.device.createTexture(g)}catch{ae("WebGPURenderer: Failed to create texture with descriptor:",g),this.createDefaultTexture(e);return}if(f){const m=Object.assign({},g);m.label=m.label+"-msaa",m.sampleCount=h,m.mipLevelCount=1,i.msaaTexture=n.device.createTexture(m)}i.initialized=!0,i.textureDescriptorGPU=g}destroyTexture(e,t=!1){const n=this.backend,i=n.get(e);i.texture!==void 0&&t===!1&&i.texture.destroy(),i.msaaTexture!==void 0&&i.msaaTexture.destroy(),n.delete(e)}generateMipmaps(e,t=null){const n=this.backend.get(e);this._generateMipmaps(n.texture,t)}getColorBuffer(){const e=this.backend,t=e.renderer.getCanvasTarget(),{width:n,height:i}=e.getDrawingBufferSize(),s=e.renderer.currentSamples,o=t.colorTexture,a=e.get(o);if(o.width===n&&o.height===i&&o.samples===s)return a.texture;let l=a.texture;return l&&l.destroy(),l=e.device.createTexture({label:"colorBuffer",size:{width:n,height:i,depthOrArrayLayers:1},sampleCount:e.utils.getSampleCount(e.renderer.currentSamples),format:e.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),o.source.width=n,o.source.height=i,o.samples=s,a.texture=l,l}getDepthBuffer(e=!0,t=!1){const n=this.backend,i=n.renderer.getCanvasTarget(),{width:s,height:o}=n.getDrawingBufferSize(),a=n.renderer.currentSamples,l=i.depthTexture;if(l.width===s&&l.height===o&&l.samples===a&&l.depth===e&&l.stencil===t)return n.get(l).texture;const c=n.get(l).texture;let u,h;if(t?(u=qn,h=n.renderer.reversedDepthBuffer===!0?Qt:di):e&&(u=Dn,h=n.renderer.reversedDepthBuffer===!0?Qt:Ct),c!==void 0){if(l.image.width===s&&l.image.height===o&&l.format===u&&l.type===h&&l.samples===a)return c;this.destroyTexture(l)}return l.name="depthBuffer",l.format=u,l.type=h,l.image.width=s,l.image.height=o,l.samples=a,this.createTexture(l,{width:s,height:o}),n.get(l).texture}updateTexture(e,t){const n=this.backend.get(e),i=e.mipmaps,{textureDescriptorGPU:s}=n;if(!(e.isRenderTargetTexture||s===void 0)){if(e.isDataTexture)if(i.length>0)for(let o=0,a=i.length;o<a;o++){const l=i[o];this._copyBufferToTexture(l,n.texture,s,0,e.flipY,0,o)}else this._copyBufferToTexture(t.image,n.texture,s,0,e.flipY);else if(e.isArrayTexture||e.isDataArrayTexture||e.isData3DTexture)if(e.layerUpdates&&e.layerUpdates.size>0){for(const o of e.layerUpdates)this._copyBufferToTexture(t.image,n.texture,s,o,e.flipY,o);e.clearLayerUpdates()}else for(let o=0;o<t.image.depth;o++)this._copyBufferToTexture(t.image,n.texture,s,o,e.flipY,o);else if(e.isCompressedTexture||e.isCompressedArrayTexture)this._copyCompressedBufferToTexture(e.mipmaps,n.texture,s);else if(e.isCubeTexture)this._copyCubeMapToTexture(e,n.texture,s);else if(e.isHTMLTexture){const o=this.backend.device,a=this.backend.renderer.domElement,l=e.image;if(typeof o.queue.copyElementImageToTexture!="function")return;if(!n.hasPaintCallback){n.hasPaintCallback=!0,a.requestPaint();return}const c=s.size.width,u=s.size.height;o.queue.copyElementImageToTexture(l,c,u,{texture:n.texture}),e.flipY&&this._flipY(n.texture,s)}else if(i.length>0)for(let o=0,a=i.length;o<a;o++){const l=i[o];this._copyImageToTexture(l,n.texture,s,0,e.flipY,e.premultiplyAlpha,o)}else this._copyImageToTexture(t.image,n.texture,s,0,e.flipY,e.premultiplyAlpha);n.version=e.version}}async copyTextureToBuffer(e,t,n,i,s,o){const a=this.backend.device,l=this.backend.get(e),c=l.texture,u=l.textureDescriptorGPU.format,h=this._getBytesPerTexel(u);let d=i*h;d=Math.ceil(d/256)*256;const f=a.createBuffer({size:(s-1)*d+i*h,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),p=a.createCommandEncoder();p.copyTextureToBuffer({texture:c,origin:{x:t,y:n,z:o}},{buffer:f,bytesPerRow:d},{width:i,height:s});const g=this._getTypedArrayType(u);a.queue.submit([p.finish()]),await f.mapAsync(GPUMapMode.READ);const m=f.getMappedRange().slice();return f.destroy(),new g(m)}dispose(){this._samplerCache.clear()}_getDefaultTextureGPU(e){let t=this.defaultTexture[e];if(t===void 0){const n=new fn;n.minFilter=Mt,n.magFilter=Mt,this.createTexture(n,{width:1,height:1,format:e}),this.defaultTexture[e]=t=n}return this.backend.get(t).texture}_getDefaultCubeTextureGPU(e){let t=this.defaultCubeTexture[e];if(t===void 0){const n=new sl;n.minFilter=Mt,n.magFilter=Mt,this.createTexture(n,{width:1,height:1,depth:6}),this.defaultCubeTexture[e]=t=n}return this.backend.get(t).texture}_copyCubeMapToTexture(e,t,n){const i=e.images,s=e.mipmaps;for(let o=0;o<6;o++){const a=i[o],l=e.flipY===!0?kB[o]:o;a.isDataTexture?this._copyBufferToTexture(a.image,t,n,l,e.flipY):this._copyImageToTexture(a,t,n,l,e.flipY,e.premultiplyAlpha);for(let c=0;c<s.length;c++){const h=s[c].images[o];h.isDataTexture?this._copyBufferToTexture(h.image,t,n,l,e.flipY,0,c+1):this._copyImageToTexture(h,t,n,l,e.flipY,e.premultiplyAlpha,c+1)}}}_copyImageToTexture(e,t,n,i,s,o,a=0){const l=this.backend.device,c=a>0?e.width:n.size.width,u=a>0?e.height:n.size.height;try{l.queue.copyExternalImageToTexture({source:e,flipY:s},{texture:t,mipLevel:a,origin:{x:0,y:0,z:i},premultipliedAlpha:o},{width:c,height:u,depthOrArrayLayers:1})}catch{}}_getPassUtils(){let e=this._passUtils;return e===null&&(this._passUtils=e=new BB(this.backend.device)),e}_generateMipmaps(e,t=null){this._getPassUtils().generateMipmaps(e,t)}_flipY(e,t,n=0){this._getPassUtils().flipY(e,t,n)}_copyBufferToTexture(e,t,n,i,s,o=0,a=0){const l=this.backend.device,c=e.data,u=this._getBytesPerTexel(n.format),h=e.width*u;l.queue.writeTexture({texture:t,mipLevel:a,origin:{x:0,y:0,z:i}},c,{offset:e.width*e.height*u*o,bytesPerRow:h},{width:e.width,height:e.height,depthOrArrayLayers:1}),s===!0&&this._flipY(t,n,i)}_copyCompressedBufferToTexture(e,t,n){const i=this.backend.device,s=this._getBlockData(n.format),o=n.size.depthOrArrayLayers>1;for(let a=0;a<e.length;a++){const l=e[a],c=l.width,u=l.height,h=o?n.size.depthOrArrayLayers:1,d=Math.ceil(c/s.width)*s.byteLength,f=d*Math.ceil(u/s.height);for(let p=0;p<h;p++)i.queue.writeTexture({texture:t,mipLevel:a,origin:{x:0,y:0,z:p}},l.data,{offset:p*f,bytesPerRow:d,rowsPerImage:Math.ceil(u/s.height)},{width:Math.ceil(c/s.width)*s.width,height:Math.ceil(u/s.height)*s.height,depthOrArrayLayers:1})}}_getBlockData(e){if(e===L.BC1RGBAUnorm||e===L.BC1RGBAUnormSRGB)return{byteLength:8,width:4,height:4};if(e===L.BC2RGBAUnorm||e===L.BC2RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===L.BC3RGBAUnorm||e===L.BC3RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===L.BC4RUnorm||e===L.BC4RSnorm)return{byteLength:8,width:4,height:4};if(e===L.BC5RGUnorm||e===L.BC5RGSnorm)return{byteLength:16,width:4,height:4};if(e===L.BC6HRGBUFloat||e===L.BC6HRGBFloat)return{byteLength:16,width:4,height:4};if(e===L.BC7RGBAUnorm||e===L.BC7RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===L.ETC2RGB8Unorm||e===L.ETC2RGB8UnormSRGB)return{byteLength:8,width:4,height:4};if(e===L.ETC2RGB8A1Unorm||e===L.ETC2RGB8A1UnormSRGB)return{byteLength:8,width:4,height:4};if(e===L.ETC2RGBA8Unorm||e===L.ETC2RGBA8UnormSRGB)return{byteLength:16,width:4,height:4};if(e===L.EACR11Unorm)return{byteLength:8,width:4,height:4};if(e===L.EACR11Snorm)return{byteLength:8,width:4,height:4};if(e===L.EACRG11Unorm)return{byteLength:16,width:4,height:4};if(e===L.EACRG11Snorm)return{byteLength:16,width:4,height:4};if(e===L.ASTC4x4Unorm||e===L.ASTC4x4UnormSRGB)return{byteLength:16,width:4,height:4};if(e===L.ASTC5x4Unorm||e===L.ASTC5x4UnormSRGB)return{byteLength:16,width:5,height:4};if(e===L.ASTC5x5Unorm||e===L.ASTC5x5UnormSRGB)return{byteLength:16,width:5,height:5};if(e===L.ASTC6x5Unorm||e===L.ASTC6x5UnormSRGB)return{byteLength:16,width:6,height:5};if(e===L.ASTC6x6Unorm||e===L.ASTC6x6UnormSRGB)return{byteLength:16,width:6,height:6};if(e===L.ASTC8x5Unorm||e===L.ASTC8x5UnormSRGB)return{byteLength:16,width:8,height:5};if(e===L.ASTC8x6Unorm||e===L.ASTC8x6UnormSRGB)return{byteLength:16,width:8,height:6};if(e===L.ASTC8x8Unorm||e===L.ASTC8x8UnormSRGB)return{byteLength:16,width:8,height:8};if(e===L.ASTC10x5Unorm||e===L.ASTC10x5UnormSRGB)return{byteLength:16,width:10,height:5};if(e===L.ASTC10x6Unorm||e===L.ASTC10x6UnormSRGB)return{byteLength:16,width:10,height:6};if(e===L.ASTC10x8Unorm||e===L.ASTC10x8UnormSRGB)return{byteLength:16,width:10,height:8};if(e===L.ASTC10x10Unorm||e===L.ASTC10x10UnormSRGB)return{byteLength:16,width:10,height:10};if(e===L.ASTC12x10Unorm||e===L.ASTC12x10UnormSRGB)return{byteLength:16,width:12,height:10};if(e===L.ASTC12x12Unorm||e===L.ASTC12x12UnormSRGB)return{byteLength:16,width:12,height:12}}_convertAddressMode(e){let t=Vf.ClampToEdge;return e===go?t=Vf.Repeat:e===_o&&(t=Vf.MirrorRepeat),t}_convertFilterMode(e){let t=cr.Linear;return(e===Mt||e===em||e===Xr)&&(t=cr.Nearest),t}_getBytesPerTexel(e){if(e===L.R8Unorm||e===L.R8Snorm||e===L.R8Uint||e===L.R8Sint)return 1;if(e===L.R16Uint||e===L.R16Sint||e===L.R16Float||e===L.RG8Unorm||e===L.RG8Snorm||e===L.RG8Uint||e===L.RG8Sint||e===L.R16Unorm||e===L.R16Snorm)return 2;if(e===L.R32Uint||e===L.R32Sint||e===L.R32Float||e===L.RG16Uint||e===L.RG16Sint||e===L.RG16Float||e===L.RGBA8Unorm||e===L.RGBA8UnormSRGB||e===L.RGBA8Snorm||e===L.RGBA8Uint||e===L.RGBA8Sint||e===L.BGRA8Unorm||e===L.BGRA8UnormSRGB||e===L.RG16Unorm||e===L.RG16Snorm||e===L.RGB9E5UFloat||e===L.RGB10A2Unorm||e===L.RG11B10UFloat||e===L.Depth32Float||e===L.Depth24Plus||e===L.Depth24PlusStencil8||e===L.Depth32FloatStencil8)return 4;if(e===L.RG32Uint||e===L.RG32Sint||e===L.RG32Float||e===L.RGBA16Uint||e===L.RGBA16Sint||e===L.RGBA16Float||e===L.RGBA16Unorm||e===L.RGBA16Snorm)return 8;if(e===L.RGBA32Uint||e===L.RGBA32Sint||e===L.RGBA32Float)return 16}_getTypedArrayType(e){if(e===L.R8Uint)return Uint8Array;if(e===L.R8Sint)return Int8Array;if(e===L.R8Unorm)return Uint8Array;if(e===L.R8Snorm)return Int8Array;if(e===L.RG8Uint)return Uint8Array;if(e===L.RG8Sint)return Int8Array;if(e===L.RG8Unorm)return Uint8Array;if(e===L.RG8Snorm)return Int8Array;if(e===L.RGBA8Uint)return Uint8Array;if(e===L.RGBA8Sint)return Int8Array;if(e===L.RGBA8Unorm||e===L.RGBA8UnormSRGB)return Uint8Array;if(e===L.RGBA8Snorm)return Int8Array;if(e===L.R16Uint)return Uint16Array;if(e===L.R16Sint)return Int16Array;if(e===L.RG16Uint)return Uint16Array;if(e===L.RG16Sint)return Int16Array;if(e===L.RGBA16Uint)return Uint16Array;if(e===L.RGBA16Sint)return Int16Array;if(e===L.R16Float||e===L.RG16Float||e===L.RGBA16Float||e===L.R16Unorm)return Uint16Array;if(e===L.R16Snorm)return Int16Array;if(e===L.RG16Unorm)return Uint16Array;if(e===L.RG16Snorm)return Int16Array;if(e===L.RGBA16Unorm)return Uint16Array;if(e===L.RGBA16Snorm)return Int16Array;if(e===L.R32Uint)return Uint32Array;if(e===L.R32Sint)return Int32Array;if(e===L.R32Float)return Float32Array;if(e===L.RG32Uint)return Uint32Array;if(e===L.RG32Sint)return Int32Array;if(e===L.RG32Float)return Float32Array;if(e===L.RGBA32Uint)return Uint32Array;if(e===L.RGBA32Sint)return Int32Array;if(e===L.RGBA32Float)return Float32Array;if(e===L.BGRA8Unorm||e===L.BGRA8UnormSRGB)return Uint8Array;if(e===L.RGB10A2Unorm||e===L.RGB9E5UFloat||e===L.RG11B10UFloat)return Uint32Array;if(e===L.Depth32Float)return Float32Array;if(e===L.Depth24Plus||e===L.Depth24PlusStencil8)return Uint32Array;if(e===L.Depth32FloatStencil8)return Float32Array}_getDimension(e){let t;return e.is3DTexture||e.isData3DTexture?t=v0.ThreeD:t=v0.TwoD,t}}function Np(r,e){const t=r.format,n=r.type,i=r.normalized,s=r.colorSpace,o=Ye.getTransfer(s);let a,l=!1;if(i&&(l=e.features.has(Dh.TextureFormatsTier1),l===!1&&ae("WebGPURenderer: Unable to use normalized textures without texture-formats-tier1 feature.")),r.isCompressedTexture===!0||r.isCompressedArrayTexture===!0)switch(t){case Es:case As:a=o===Pe?L.BC1RGBAUnormSRGB:L.BC1RGBAUnorm;break;case ws:a=o===Pe?L.BC2RGBAUnormSRGB:L.BC2RGBAUnorm;break;case Rs:a=o===Pe?L.BC3RGBAUnormSRGB:L.BC3RGBAUnorm;break;case $a:a=L.BC4RUnorm;break;case Xa:a=L.BC4RSnorm;break;case Us:a=L.BC5RGUnorm;break;case qa:a=L.BC5RGSnorm;break;case Wa:a=o===Pe?L.BC7RGBAUnormSRGB:L.BC7RGBAUnorm;break;case Ea:case Ma:a=o===Pe?L.ETC2RGB8UnormSRGB:L.ETC2RGB8Unorm;break;case Aa:a=o===Pe?L.ETC2RGBA8UnormSRGB:L.ETC2RGBA8Unorm;break;case wa:a=L.EACR11Unorm;break;case Ra:a=L.EACR11Snorm;break;case Ls:a=L.EACRG11Unorm;break;case Ca:a=L.EACRG11Snorm;break;case Na:a=o===Pe?L.ASTC4x4UnormSRGB:L.ASTC4x4Unorm;break;case Pa:a=o===Pe?L.ASTC5x4UnormSRGB:L.ASTC5x4Unorm;break;case Da:a=o===Pe?L.ASTC5x5UnormSRGB:L.ASTC5x5Unorm;break;case La:a=o===Pe?L.ASTC6x5UnormSRGB:L.ASTC6x5Unorm;break;case Ua:a=o===Pe?L.ASTC6x6UnormSRGB:L.ASTC6x6Unorm;break;case Fa:a=o===Pe?L.ASTC8x5UnormSRGB:L.ASTC8x5Unorm;break;case Ia:a=o===Pe?L.ASTC8x6UnormSRGB:L.ASTC8x6Unorm;break;case Ba:a=o===Pe?L.ASTC8x8UnormSRGB:L.ASTC8x8Unorm;break;case Oa:a=o===Pe?L.ASTC10x5UnormSRGB:L.ASTC10x5Unorm;break;case ka:a=o===Pe?L.ASTC10x6UnormSRGB:L.ASTC10x6Unorm;break;case Ga:a=o===Pe?L.ASTC10x8UnormSRGB:L.ASTC10x8Unorm;break;case Va:a=o===Pe?L.ASTC10x10UnormSRGB:L.ASTC10x10Unorm;break;case za:a=o===Pe?L.ASTC12x10UnormSRGB:L.ASTC12x10Unorm;break;case Ha:a=o===Pe?L.ASTC12x12UnormSRGB:L.ASTC12x12Unorm;break;case ln:a=o===Pe?L.RGBA8UnormSRGB:L.RGBA8Unorm;break;default:ce("WebGPURenderer: Unsupported texture format.",t)}else switch(t){case ln:switch(n){case Ts:a=L.RGBA8Snorm;break;case Ms:a=l?L.RGBA16Snorm:L.RGBA16Sint;break;case Ui:a=l?L.RGBA16Unorm:L.RGBA16Uint;break;case Ct:a=L.RGBA32Uint;break;case Sn:a=L.RGBA32Sint;break;case Xt:a=o===Pe?L.RGBA8UnormSRGB:L.RGBA8Unorm;break;case tn:a=L.RGBA16Float;break;case Qt:a=L.RGBA32Float;break;default:ce("WebGPURenderer: Unsupported texture type with RGBAFormat.",n)}break;case nl:switch(n){case Lc:a=L.RGB9E5UFloat;break;case Uc:a=L.RG11B10UFloat;break;default:ce("WebGPURenderer: Unsupported texture type with RGBFormat.",n)}break;case il:switch(n){case Ts:a=L.R8Snorm;break;case Ms:a=l?L.R16Snorm:L.R16Sint;break;case Ui:a=l?L.R16Unorm:L.R16Uint;break;case Ct:a=L.R32Uint;break;case Sn:a=L.R32Sint;break;case Xt:a=L.R8Unorm;break;case tn:a=L.R16Float;break;case Qt:a=L.R32Float;break;default:ce("WebGPURenderer: Unsupported texture type with RedFormat.",n)}break;case In:switch(n){case Ts:a=L.RG8Snorm;break;case Ms:a=l?L.RG16Snorm:L.RG16Sint;break;case Ui:a=l?L.RG16Unorm:L.RG16Uint;break;case Ct:a=L.RG32Uint;break;case Sn:a=L.RG32Sint;break;case Xt:a=L.RG8Unorm;break;case tn:a=L.RG16Float;break;case Qt:a=L.RG32Float;break;default:ce("WebGPURenderer: Unsupported texture type with RGFormat.",n)}break;case Dn:switch(n){case Ui:a=L.Depth16Unorm;break;case Ct:a=L.Depth24Plus;break;case Qt:a=L.Depth32Float;break;default:ce("WebGPURenderer: Unsupported texture type with DepthFormat.",n)}break;case qn:switch(n){case di:a=L.Depth24PlusStencil8;break;case Qt:e&&e.features.has(Dh.Depth32FloatStencil8)===!1&&ce('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),a=L.Depth32FloatStencil8;break;default:ce("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",n)}break;case Eo:switch(n){case Sn:a=L.R32Sint;break;case Ct:a=L.R32Uint;break;default:ce("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",n)}break;case Ao:switch(n){case Sn:a=L.RG32Sint;break;case Ct:a=L.RG32Uint;break;default:ce("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",n)}break;case rl:switch(n){case Sn:a=L.RGBA32Sint;break;case Ct:a=L.RGBA32Uint;break;default:ce("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",n)}break;default:ce("WebGPURenderer: Unsupported texture format.",t)}return a}const VB=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,zB=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/ig,S0={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2<f32>":"vec2","vec2<i32>":"ivec2","vec2<u32>":"uvec2","vec2<bool>":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3<f32>":"vec3","vec3<i32>":"ivec3","vec3<u32>":"uvec3","vec3<bool>":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4<f32>":"vec4","vec4<i32>":"ivec4","vec4<u32>":"uvec4","vec4<bool>":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2<f32>":"mat2",mat2x2f:"mat2","mat3x3<f32>":"mat3",mat3x3f:"mat3","mat4x4<f32>":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_depth_2d_array:"depthTexture",texture_depth_multisampled_2d:"depthTexture",texture_depth_cube:"depthTexture",texture_depth_cube_array:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"},HB=r=>{r=r.trim();const e=r.match(VB);if(e!==null&&e.length===4){const t=e[2],n=[];let i=null;for(;(i=zB.exec(t))!==null;)n.push({name:i[1],type:i[2]});const s=[];for(let u=0;u<n.length;u++){const{name:h,type:d}=n[u];let f=d;f.startsWith("ptr")?f="pointer":(f.startsWith("texture")&&(f=d.split("<")[0]),f=S0[f]),s.push(new Zm(f,h))}const o=r.substring(e[0].length),a=e[3]||"void",l=e[1]!==void 0?e[1]:"";return{type:S0[a]||a,inputs:s,name:l,inputsCode:t,blockCode:o,outputType:a}}else throw new Error("FunctionNode: Function is not a WGSL code.")};class WB extends Jm{constructor(e){const{type:t,inputs:n,name:i,inputsCode:s,blockCode:o,outputType:a}=HB(e);super(t,n,i),this.inputsCode=s,this.blockCode=o,this.outputType=a}getCode(e=this.name){const t=this.outputType!=="void"?"-> "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class $B extends Lb{parseFunction(e){return new WB(e)}}const XB={[Fi.READ_ONLY]:"read",[Fi.WRITE_ONLY]:"write",[Fi.READ_WRITE]:"read_write"},T0={[go]:"repeat",[ci]:"clamp",[_o]:"mirror"},Wf={vertex:yr.VERTEX,fragment:yr.FRAGMENT,compute:yr.COMPUTE},M0={instance:!0,swizzleAssign:!1,storageBuffer:!0},qB={"^^":"tsl_xor"},jB={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3<f32>",vec2:"vec2<f32>",ivec2:"vec2<i32>",uvec2:"vec2<u32>",bvec2:"vec2<bool>",vec3:"vec3<f32>",ivec3:"vec3<i32>",uvec3:"vec3<u32>",bvec3:"vec3<bool>",vec4:"vec4<f32>",ivec4:"vec4<i32>",uvec4:"vec4<u32>",bvec4:"vec4<bool>",mat2:"mat2x2<f32>",mat3:"mat3x3<f32>",mat4:"mat4x4<f32>"},E0={},zl={tsl_xor:new Rn("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new Rn("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new Rn("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new Rn("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new Rn("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new Rn("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new Rn("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new Rn("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new Rn("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new Rn("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new Rn("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new Rn("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),biquadraticTexture:new Rn(`
4876
+ `;this.mipmapSampler=e.createSampler({minFilter:cr.Linear}),this.flipYSampler=e.createSampler({minFilter:cr.Nearest}),this.flipUniformBuffer=e.createBuffer({size:4,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),e.queue.writeBuffer(this.flipUniformBuffer,0,new Uint32Array([1])),this.noFlipUniformBuffer=e.createBuffer({size:4,usage:GPUBufferUsage.UNIFORM}),this.transferPipelines={},this.mipmapShaderModule=e.createShaderModule({label:"mipmap",code:t})}getTransferPipeline(e,t){t=t||"2d-array";const n=`${e}-${t}`;let i=this.transferPipelines[n];return i===void 0&&(i=this.device.createRenderPipeline({label:`mipmap-${e}-${t}`,vertex:{module:this.mipmapShaderModule},fragment:{module:this.mipmapShaderModule,entryPoint:`main_${t.replace("-","_")}`,targets:[{format:e}]},layout:"auto"}),this.transferPipelines[n]=i),i}flipY(e,t,n=0){const i=t.format,{width:s,height:o}=t.size,a=this.device.createTexture({size:{width:s,height:o},format:i,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=this.getTransferPipeline(i,e.textureBindingViewDimension),c=this.getTransferPipeline(i,a.textureBindingViewDimension),u=this.device.createCommandEncoder({}),h=(d,f,p,g,m,_)=>{const x=d.getBindGroupLayout(0),y=this.device.createBindGroup({layout:x,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:f.createView({dimension:f.textureBindingViewDimension||"2d-array",baseMipLevel:0,mipLevelCount:1})},{binding:2,resource:{buffer:_?this.flipUniformBuffer:this.noFlipUniformBuffer}}]}),b=u.beginRenderPass({colorAttachments:[{view:g.createView({dimension:"2d",baseMipLevel:0,mipLevelCount:1,baseArrayLayer:m,arrayLayerCount:1}),loadOp:wt.Clear,storeOp:Jn.Store}]});b.setPipeline(d),b.setBindGroup(0,y),b.draw(3,1,0,p),b.end()};h(l,e,n,a,0,!1),h(c,a,0,e,n,!0),this.device.queue.submit([u.finish()]),a.destroy()}generateMipmaps(e,t=null){const n=this.get(e),i=n.layers||this._mipmapCreateBundles(e),s=t||this.device.createCommandEncoder({label:"mipmapEncoder"});this._mipmapRunBundles(s,i),t===null&&this.device.queue.submit([s.finish()]),n.layers=i}_mipmapCreateBundles(e){const t=e.textureBindingViewDimension||"2d-array",n=this.getTransferPipeline(e.format,t),i=n.getBindGroupLayout(0),s=[];for(let o=1;o<e.mipLevelCount;o++)for(let a=0;a<e.depthOrArrayLayers;a++){const l=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:this.mipmapSampler},{binding:1,resource:e.createView({dimension:t,baseMipLevel:o-1,mipLevelCount:1})},{binding:2,resource:{buffer:this.noFlipUniformBuffer}}]}),c={colorAttachments:[{view:e.createView({dimension:"2d",baseMipLevel:o,mipLevelCount:1,baseArrayLayer:a,arrayLayerCount:1}),loadOp:wt.Clear,storeOp:Jn.Store}]},u=this.device.createRenderBundleEncoder({colorFormats:[e.format]});u.setPipeline(n),u.setBindGroup(0,l),u.draw(3,1,0,a),s.push({renderBundles:[u.finish()],passDescriptor:c})}return s}_mipmapRunBundles(e,t){const n=t.length;for(let i=0;i<n;i++){const s=t[i],o=e.beginRenderPass(s.passDescriptor);o.executeBundles(s.renderBundles),o.end()}}}const OB={[tm]:"never",[Ih]:"less",[nm]:"equal",[Os]:"less-equal",[vc]:"greater",[Zr]:"greater-equal",[rm]:"always",[im]:"not-equal"},kB=[0,1,3,2,4,5];class GB{constructor(e){this.backend=e,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this._samplerCache=new Map}updateSampler(e){const t=this.backend,n=e.minFilter+"-"+e.magFilter+"-"+e.wrapS+"-"+e.wrapT+"-"+(e.wrapR||"0")+"-"+e.anisotropy+"-"+(e.compareFunction||0);let i=this._samplerCache.get(n);if(i===void 0){const o={addressModeU:this._convertAddressMode(e.wrapS),addressModeV:this._convertAddressMode(e.wrapT),addressModeW:this._convertAddressMode(e.wrapR),magFilter:this._convertFilterMode(e.magFilter),minFilter:this._convertFilterMode(e.minFilter),mipmapFilter:this._convertFilterMode(e.minFilter),maxAnisotropy:1};e.isDepthTexture&&e.compareFunction===null&&(o.magFilter=cr.Nearest,o.minFilter=cr.Nearest,o.mipmapFilter=cr.Nearest),o.magFilter===cr.Linear&&o.minFilter===cr.Linear&&o.mipmapFilter===cr.Linear&&(o.maxAnisotropy=e.anisotropy),e.isDepthTexture&&e.compareFunction!==null&&t.hasCompatibility(wo.TEXTURE_COMPARE)&&(o.compare=OB[e.compareFunction]),i={sampler:t.device.createSampler(o),usedTimes:0},this._samplerCache.set(n,i)}const s=t.get(e);if(s.sampler!==i.sampler){if(s.sampler!==void 0){const o=this._samplerCache.get(s.samplerKey);o.usedTimes--,o.usedTimes===0&&this._samplerCache.delete(s.samplerKey)}s.samplerKey=n,s.sampler=i.sampler,i.usedTimes++}return n}createDefaultTexture(e){let t;const n=Np(e,this.backend.device);e.isCubeTexture?t=this._getDefaultCubeTextureGPU(n):t=this._getDefaultTextureGPU(n),this.backend.get(e).texture=t}createTexture(e,t={}){const n=this.backend,i=n.get(e);if(i.initialized)throw new Error("WebGPUTextureUtils: Texture already initialized.");if(e.isExternalTexture){i.texture=e.sourceTexture,i.initialized=!0;return}t.needsMipmaps===void 0&&(t.needsMipmaps=!1),t.levels===void 0&&(t.levels=1),t.depth===void 0&&(t.depth=1);const{width:s,height:o,depth:a,levels:l}=t;e.isFramebufferTexture&&(t.renderTarget?t.format=this.backend.utils.getCurrentColorFormat(t.renderTarget):t.format=this.backend.utils.getPreferredCanvasFormat());const c=this._getDimension(e),u=e.internalFormat||t.format||Np(e,n.device);i.format=u;const{samples:h,primarySamples:d,isMSAA:f}=n.utils.getTextureSampleData(e);let p=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;e.isStorageTexture===!0&&(p|=GPUTextureUsage.STORAGE_BINDING),e.isCompressedTexture!==!0&&e.isCompressedArrayTexture!==!0&&u!==L.RGB9E5UFloat&&(p|=GPUTextureUsage.RENDER_ATTACHMENT);const g={label:e.name,size:{width:s,height:o,depthOrArrayLayers:a},mipLevelCount:l,sampleCount:d,dimension:c,format:u,usage:p};if(u===void 0){ae("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(e);return}e.isCubeTexture&&(g.textureBindingViewDimension=Wn.Cube);try{i.texture=n.device.createTexture(g)}catch{ae("WebGPURenderer: Failed to create texture with descriptor:",g),this.createDefaultTexture(e);return}if(f){const m=Object.assign({},g);m.label=m.label+"-msaa",m.sampleCount=h,m.mipLevelCount=1,i.msaaTexture=n.device.createTexture(m)}i.initialized=!0,i.textureDescriptorGPU=g}destroyTexture(e,t=!1){const n=this.backend,i=n.get(e);i.texture!==void 0&&t===!1&&i.texture.destroy(),i.msaaTexture!==void 0&&i.msaaTexture.destroy(),n.delete(e)}generateMipmaps(e,t=null){const n=this.backend.get(e);this._generateMipmaps(n.texture,t)}getColorBuffer(){const e=this.backend,t=e.renderer.getCanvasTarget(),{width:n,height:i}=e.getDrawingBufferSize(),s=e.renderer.currentSamples,o=t.colorTexture,a=e.get(o);if(o.width===n&&o.height===i&&o.samples===s)return a.texture;let l=a.texture;return l&&l.destroy(),l=e.device.createTexture({label:"colorBuffer",size:{width:n,height:i,depthOrArrayLayers:1},sampleCount:e.utils.getSampleCount(e.renderer.currentSamples),format:e.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),o.source.width=n,o.source.height=i,o.samples=s,a.texture=l,l}getDepthBuffer(e=!0,t=!1){const n=this.backend,i=n.renderer.getCanvasTarget(),{width:s,height:o}=n.getDrawingBufferSize(),a=n.renderer.currentSamples,l=i.depthTexture;if(l.width===s&&l.height===o&&l.samples===a&&l.depth===e&&l.stencil===t)return n.get(l).texture;const c=n.get(l).texture;let u,h;if(t?(u=qn,h=n.renderer.reversedDepthBuffer===!0?Qt:di):e&&(u=Dn,h=n.renderer.reversedDepthBuffer===!0?Qt:Ct),c!==void 0){if(l.image.width===s&&l.image.height===o&&l.format===u&&l.type===h&&l.samples===a)return c;this.destroyTexture(l)}return l.name="depthBuffer",l.format=u,l.type=h,l.image.width=s,l.image.height=o,l.samples=a,this.createTexture(l,{width:s,height:o}),n.get(l).texture}updateTexture(e,t){const n=this.backend.get(e),i=e.mipmaps,{textureDescriptorGPU:s}=n;if(!(e.isRenderTargetTexture||s===void 0)){if(e.isDataTexture)if(i.length>0)for(let o=0,a=i.length;o<a;o++){const l=i[o];this._copyBufferToTexture(l,n.texture,s,0,e.flipY,0,o)}else this._copyBufferToTexture(t.image,n.texture,s,0,e.flipY);else if(e.isArrayTexture||e.isDataArrayTexture||e.isData3DTexture)if(e.layerUpdates&&e.layerUpdates.size>0){for(const o of e.layerUpdates)this._copyBufferToTexture(t.image,n.texture,s,o,e.flipY,o);e.clearLayerUpdates()}else for(let o=0;o<t.image.depth;o++)this._copyBufferToTexture(t.image,n.texture,s,o,e.flipY,o);else if(e.isCompressedTexture||e.isCompressedArrayTexture)this._copyCompressedBufferToTexture(e.mipmaps,n.texture,s);else if(e.isCubeTexture)this._copyCubeMapToTexture(e,n.texture,s);else if(e.isHTMLTexture){const o=this.backend.device,a=this.backend.renderer.domElement,l=e.image;if(typeof o.queue.copyElementImageToTexture!="function")return;if(!n.hasPaintCallback){n.hasPaintCallback=!0,a.requestPaint();return}const c=s.size.width,u=s.size.height;o.queue.copyElementImageToTexture(l,c,u,{texture:n.texture}),e.flipY&&this._flipY(n.texture,s)}else if(i.length>0)for(let o=0,a=i.length;o<a;o++){const l=i[o];this._copyImageToTexture(l,n.texture,s,0,e.flipY,e.premultiplyAlpha,o)}else this._copyImageToTexture(t.image,n.texture,s,0,e.flipY,e.premultiplyAlpha);n.version=e.version}}async copyTextureToBuffer(e,t,n,i,s,o){const a=this.backend.device,l=this.backend.get(e),c=l.texture,u=l.textureDescriptorGPU.format,h=this._getBytesPerTexel(u);let d=i*h;d=Math.ceil(d/256)*256;const f=a.createBuffer({size:(s-1)*d+i*h,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),p=a.createCommandEncoder();p.copyTextureToBuffer({texture:c,origin:{x:t,y:n,z:o}},{buffer:f,bytesPerRow:d},{width:i,height:s});const g=this._getTypedArrayType(u);a.queue.submit([p.finish()]),await f.mapAsync(GPUMapMode.READ);const m=f.getMappedRange().slice();return f.destroy(),new g(m)}dispose(){this._samplerCache.clear()}_getDefaultTextureGPU(e){let t=this.defaultTexture[e];if(t===void 0){const n=new fn;n.minFilter=Mt,n.magFilter=Mt,this.createTexture(n,{width:1,height:1,format:e}),this.defaultTexture[e]=t=n}return this.backend.get(t).texture}_getDefaultCubeTextureGPU(e){let t=this.defaultCubeTexture[e];if(t===void 0){const n=new sl;n.minFilter=Mt,n.magFilter=Mt,this.createTexture(n,{width:1,height:1,depth:6}),this.defaultCubeTexture[e]=t=n}return this.backend.get(t).texture}_copyCubeMapToTexture(e,t,n){const i=e.images,s=e.mipmaps;for(let o=0;o<6;o++){const a=i[o],l=e.flipY===!0?kB[o]:o;a.isDataTexture?this._copyBufferToTexture(a.image,t,n,l,e.flipY):this._copyImageToTexture(a,t,n,l,e.flipY,e.premultiplyAlpha);for(let c=0;c<s.length;c++){const h=s[c].images[o];h.isDataTexture?this._copyBufferToTexture(h.image,t,n,l,e.flipY,0,c+1):this._copyImageToTexture(h,t,n,l,e.flipY,e.premultiplyAlpha,c+1)}}}_copyImageToTexture(e,t,n,i,s,o,a=0){const l=this.backend.device,c=a>0?e.width:n.size.width,u=a>0?e.height:n.size.height;try{l.queue.copyExternalImageToTexture({source:e,flipY:s},{texture:t,mipLevel:a,origin:{x:0,y:0,z:i},premultipliedAlpha:o},{width:c,height:u,depthOrArrayLayers:1})}catch{}}_getPassUtils(){let e=this._passUtils;return e===null&&(this._passUtils=e=new BB(this.backend.device)),e}_generateMipmaps(e,t=null){this._getPassUtils().generateMipmaps(e,t)}_flipY(e,t,n=0){this._getPassUtils().flipY(e,t,n)}_copyBufferToTexture(e,t,n,i,s,o=0,a=0){const l=this.backend.device,c=e.data,u=this._getBytesPerTexel(n.format),h=e.width*u;l.queue.writeTexture({texture:t,mipLevel:a,origin:{x:0,y:0,z:i}},c,{offset:e.width*e.height*u*o,bytesPerRow:h},{width:e.width,height:e.height,depthOrArrayLayers:1}),s===!0&&this._flipY(t,n,i)}_copyCompressedBufferToTexture(e,t,n){const i=this.backend.device,s=this._getBlockData(n.format),o=n.size.depthOrArrayLayers>1;for(let a=0;a<e.length;a++){const l=e[a],c=l.width,u=l.height,h=o?n.size.depthOrArrayLayers:1,d=Math.ceil(c/s.width)*s.byteLength,f=d*Math.ceil(u/s.height);for(let p=0;p<h;p++)i.queue.writeTexture({texture:t,mipLevel:a,origin:{x:0,y:0,z:p}},l.data,{offset:p*f,bytesPerRow:d,rowsPerImage:Math.ceil(u/s.height)},{width:Math.ceil(c/s.width)*s.width,height:Math.ceil(u/s.height)*s.height,depthOrArrayLayers:1})}}_getBlockData(e){if(e===L.BC1RGBAUnorm||e===L.BC1RGBAUnormSRGB)return{byteLength:8,width:4,height:4};if(e===L.BC2RGBAUnorm||e===L.BC2RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===L.BC3RGBAUnorm||e===L.BC3RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===L.BC4RUnorm||e===L.BC4RSnorm)return{byteLength:8,width:4,height:4};if(e===L.BC5RGUnorm||e===L.BC5RGSnorm)return{byteLength:16,width:4,height:4};if(e===L.BC6HRGBUFloat||e===L.BC6HRGBFloat)return{byteLength:16,width:4,height:4};if(e===L.BC7RGBAUnorm||e===L.BC7RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===L.ETC2RGB8Unorm||e===L.ETC2RGB8UnormSRGB)return{byteLength:8,width:4,height:4};if(e===L.ETC2RGB8A1Unorm||e===L.ETC2RGB8A1UnormSRGB)return{byteLength:8,width:4,height:4};if(e===L.ETC2RGBA8Unorm||e===L.ETC2RGBA8UnormSRGB)return{byteLength:16,width:4,height:4};if(e===L.EACR11Unorm)return{byteLength:8,width:4,height:4};if(e===L.EACR11Snorm)return{byteLength:8,width:4,height:4};if(e===L.EACRG11Unorm)return{byteLength:16,width:4,height:4};if(e===L.EACRG11Snorm)return{byteLength:16,width:4,height:4};if(e===L.ASTC4x4Unorm||e===L.ASTC4x4UnormSRGB)return{byteLength:16,width:4,height:4};if(e===L.ASTC5x4Unorm||e===L.ASTC5x4UnormSRGB)return{byteLength:16,width:5,height:4};if(e===L.ASTC5x5Unorm||e===L.ASTC5x5UnormSRGB)return{byteLength:16,width:5,height:5};if(e===L.ASTC6x5Unorm||e===L.ASTC6x5UnormSRGB)return{byteLength:16,width:6,height:5};if(e===L.ASTC6x6Unorm||e===L.ASTC6x6UnormSRGB)return{byteLength:16,width:6,height:6};if(e===L.ASTC8x5Unorm||e===L.ASTC8x5UnormSRGB)return{byteLength:16,width:8,height:5};if(e===L.ASTC8x6Unorm||e===L.ASTC8x6UnormSRGB)return{byteLength:16,width:8,height:6};if(e===L.ASTC8x8Unorm||e===L.ASTC8x8UnormSRGB)return{byteLength:16,width:8,height:8};if(e===L.ASTC10x5Unorm||e===L.ASTC10x5UnormSRGB)return{byteLength:16,width:10,height:5};if(e===L.ASTC10x6Unorm||e===L.ASTC10x6UnormSRGB)return{byteLength:16,width:10,height:6};if(e===L.ASTC10x8Unorm||e===L.ASTC10x8UnormSRGB)return{byteLength:16,width:10,height:8};if(e===L.ASTC10x10Unorm||e===L.ASTC10x10UnormSRGB)return{byteLength:16,width:10,height:10};if(e===L.ASTC12x10Unorm||e===L.ASTC12x10UnormSRGB)return{byteLength:16,width:12,height:10};if(e===L.ASTC12x12Unorm||e===L.ASTC12x12UnormSRGB)return{byteLength:16,width:12,height:12}}_convertAddressMode(e){let t=Vf.ClampToEdge;return e===go?t=Vf.Repeat:e===_o&&(t=Vf.MirrorRepeat),t}_convertFilterMode(e){let t=cr.Linear;return(e===Mt||e===em||e===Xr)&&(t=cr.Nearest),t}_getBytesPerTexel(e){if(e===L.R8Unorm||e===L.R8Snorm||e===L.R8Uint||e===L.R8Sint)return 1;if(e===L.R16Uint||e===L.R16Sint||e===L.R16Float||e===L.RG8Unorm||e===L.RG8Snorm||e===L.RG8Uint||e===L.RG8Sint||e===L.R16Unorm||e===L.R16Snorm)return 2;if(e===L.R32Uint||e===L.R32Sint||e===L.R32Float||e===L.RG16Uint||e===L.RG16Sint||e===L.RG16Float||e===L.RGBA8Unorm||e===L.RGBA8UnormSRGB||e===L.RGBA8Snorm||e===L.RGBA8Uint||e===L.RGBA8Sint||e===L.BGRA8Unorm||e===L.BGRA8UnormSRGB||e===L.RG16Unorm||e===L.RG16Snorm||e===L.RGB9E5UFloat||e===L.RGB10A2Unorm||e===L.RG11B10UFloat||e===L.Depth32Float||e===L.Depth24Plus||e===L.Depth24PlusStencil8||e===L.Depth32FloatStencil8)return 4;if(e===L.RG32Uint||e===L.RG32Sint||e===L.RG32Float||e===L.RGBA16Uint||e===L.RGBA16Sint||e===L.RGBA16Float||e===L.RGBA16Unorm||e===L.RGBA16Snorm)return 8;if(e===L.RGBA32Uint||e===L.RGBA32Sint||e===L.RGBA32Float)return 16}_getTypedArrayType(e){if(e===L.R8Uint)return Uint8Array;if(e===L.R8Sint)return Int8Array;if(e===L.R8Unorm)return Uint8Array;if(e===L.R8Snorm)return Int8Array;if(e===L.RG8Uint)return Uint8Array;if(e===L.RG8Sint)return Int8Array;if(e===L.RG8Unorm)return Uint8Array;if(e===L.RG8Snorm)return Int8Array;if(e===L.RGBA8Uint)return Uint8Array;if(e===L.RGBA8Sint)return Int8Array;if(e===L.RGBA8Unorm||e===L.RGBA8UnormSRGB)return Uint8Array;if(e===L.RGBA8Snorm)return Int8Array;if(e===L.R16Uint)return Uint16Array;if(e===L.R16Sint)return Int16Array;if(e===L.RG16Uint)return Uint16Array;if(e===L.RG16Sint)return Int16Array;if(e===L.RGBA16Uint)return Uint16Array;if(e===L.RGBA16Sint)return Int16Array;if(e===L.R16Float||e===L.RG16Float||e===L.RGBA16Float||e===L.R16Unorm)return Uint16Array;if(e===L.R16Snorm)return Int16Array;if(e===L.RG16Unorm)return Uint16Array;if(e===L.RG16Snorm)return Int16Array;if(e===L.RGBA16Unorm)return Uint16Array;if(e===L.RGBA16Snorm)return Int16Array;if(e===L.R32Uint)return Uint32Array;if(e===L.R32Sint)return Int32Array;if(e===L.R32Float)return Float32Array;if(e===L.RG32Uint)return Uint32Array;if(e===L.RG32Sint)return Int32Array;if(e===L.RG32Float)return Float32Array;if(e===L.RGBA32Uint)return Uint32Array;if(e===L.RGBA32Sint)return Int32Array;if(e===L.RGBA32Float)return Float32Array;if(e===L.BGRA8Unorm||e===L.BGRA8UnormSRGB)return Uint8Array;if(e===L.RGB10A2Unorm||e===L.RGB9E5UFloat||e===L.RG11B10UFloat)return Uint32Array;if(e===L.Depth32Float)return Float32Array;if(e===L.Depth24Plus||e===L.Depth24PlusStencil8)return Uint32Array;if(e===L.Depth32FloatStencil8)return Float32Array}_getDimension(e){let t;return e.is3DTexture||e.isData3DTexture?t=v0.ThreeD:t=v0.TwoD,t}}function Np(r,e){const t=r.format,n=r.type,i=r.normalized,s=r.colorSpace,o=Ye.getTransfer(s);let a,l=!1;if(i&&(l=e.features.has(Dh.TextureFormatsTier1),l===!1&&ae("WebGPURenderer: Unable to use normalized textures without texture-formats-tier1 feature.")),r.isCompressedTexture===!0||r.isCompressedArrayTexture===!0)switch(t){case Es:case As:a=o===Pe?L.BC1RGBAUnormSRGB:L.BC1RGBAUnorm;break;case ws:a=o===Pe?L.BC2RGBAUnormSRGB:L.BC2RGBAUnorm;break;case Rs:a=o===Pe?L.BC3RGBAUnormSRGB:L.BC3RGBAUnorm;break;case $a:a=L.BC4RUnorm;break;case Xa:a=L.BC4RSnorm;break;case Us:a=L.BC5RGUnorm;break;case qa:a=L.BC5RGSnorm;break;case Wa:a=o===Pe?L.BC7RGBAUnormSRGB:L.BC7RGBAUnorm;break;case Ea:case Ma:a=o===Pe?L.ETC2RGB8UnormSRGB:L.ETC2RGB8Unorm;break;case Aa:a=o===Pe?L.ETC2RGBA8UnormSRGB:L.ETC2RGBA8Unorm;break;case wa:a=L.EACR11Unorm;break;case Ra:a=L.EACR11Snorm;break;case Ls:a=L.EACRG11Unorm;break;case Ca:a=L.EACRG11Snorm;break;case Na:a=o===Pe?L.ASTC4x4UnormSRGB:L.ASTC4x4Unorm;break;case Pa:a=o===Pe?L.ASTC5x4UnormSRGB:L.ASTC5x4Unorm;break;case Da:a=o===Pe?L.ASTC5x5UnormSRGB:L.ASTC5x5Unorm;break;case La:a=o===Pe?L.ASTC6x5UnormSRGB:L.ASTC6x5Unorm;break;case Ua:a=o===Pe?L.ASTC6x6UnormSRGB:L.ASTC6x6Unorm;break;case Fa:a=o===Pe?L.ASTC8x5UnormSRGB:L.ASTC8x5Unorm;break;case Ia:a=o===Pe?L.ASTC8x6UnormSRGB:L.ASTC8x6Unorm;break;case Ba:a=o===Pe?L.ASTC8x8UnormSRGB:L.ASTC8x8Unorm;break;case Oa:a=o===Pe?L.ASTC10x5UnormSRGB:L.ASTC10x5Unorm;break;case ka:a=o===Pe?L.ASTC10x6UnormSRGB:L.ASTC10x6Unorm;break;case Ga:a=o===Pe?L.ASTC10x8UnormSRGB:L.ASTC10x8Unorm;break;case Va:a=o===Pe?L.ASTC10x10UnormSRGB:L.ASTC10x10Unorm;break;case za:a=o===Pe?L.ASTC12x10UnormSRGB:L.ASTC12x10Unorm;break;case Ha:a=o===Pe?L.ASTC12x12UnormSRGB:L.ASTC12x12Unorm;break;case ln:a=o===Pe?L.RGBA8UnormSRGB:L.RGBA8Unorm;break;default:ce("WebGPURenderer: Unsupported texture format.",t)}else switch(t){case ln:switch(n){case Ts:a=L.RGBA8Snorm;break;case Ms:a=l?L.RGBA16Snorm:L.RGBA16Sint;break;case Li:a=l?L.RGBA16Unorm:L.RGBA16Uint;break;case Ct:a=L.RGBA32Uint;break;case Sn:a=L.RGBA32Sint;break;case Xt:a=o===Pe?L.RGBA8UnormSRGB:L.RGBA8Unorm;break;case tn:a=L.RGBA16Float;break;case Qt:a=L.RGBA32Float;break;default:ce("WebGPURenderer: Unsupported texture type with RGBAFormat.",n)}break;case nl:switch(n){case Lc:a=L.RGB9E5UFloat;break;case Uc:a=L.RG11B10UFloat;break;default:ce("WebGPURenderer: Unsupported texture type with RGBFormat.",n)}break;case il:switch(n){case Ts:a=L.R8Snorm;break;case Ms:a=l?L.R16Snorm:L.R16Sint;break;case Li:a=l?L.R16Unorm:L.R16Uint;break;case Ct:a=L.R32Uint;break;case Sn:a=L.R32Sint;break;case Xt:a=L.R8Unorm;break;case tn:a=L.R16Float;break;case Qt:a=L.R32Float;break;default:ce("WebGPURenderer: Unsupported texture type with RedFormat.",n)}break;case In:switch(n){case Ts:a=L.RG8Snorm;break;case Ms:a=l?L.RG16Snorm:L.RG16Sint;break;case Li:a=l?L.RG16Unorm:L.RG16Uint;break;case Ct:a=L.RG32Uint;break;case Sn:a=L.RG32Sint;break;case Xt:a=L.RG8Unorm;break;case tn:a=L.RG16Float;break;case Qt:a=L.RG32Float;break;default:ce("WebGPURenderer: Unsupported texture type with RGFormat.",n)}break;case Dn:switch(n){case Li:a=L.Depth16Unorm;break;case Ct:a=L.Depth24Plus;break;case Qt:a=L.Depth32Float;break;default:ce("WebGPURenderer: Unsupported texture type with DepthFormat.",n)}break;case qn:switch(n){case di:a=L.Depth24PlusStencil8;break;case Qt:e&&e.features.has(Dh.Depth32FloatStencil8)===!1&&ce('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),a=L.Depth32FloatStencil8;break;default:ce("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",n)}break;case Eo:switch(n){case Sn:a=L.R32Sint;break;case Ct:a=L.R32Uint;break;default:ce("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",n)}break;case Ao:switch(n){case Sn:a=L.RG32Sint;break;case Ct:a=L.RG32Uint;break;default:ce("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",n)}break;case rl:switch(n){case Sn:a=L.RGBA32Sint;break;case Ct:a=L.RGBA32Uint;break;default:ce("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",n)}break;default:ce("WebGPURenderer: Unsupported texture format.",t)}return a}const VB=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,zB=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/ig,S0={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2<f32>":"vec2","vec2<i32>":"ivec2","vec2<u32>":"uvec2","vec2<bool>":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3<f32>":"vec3","vec3<i32>":"ivec3","vec3<u32>":"uvec3","vec3<bool>":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4<f32>":"vec4","vec4<i32>":"ivec4","vec4<u32>":"uvec4","vec4<bool>":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2<f32>":"mat2",mat2x2f:"mat2","mat3x3<f32>":"mat3",mat3x3f:"mat3","mat4x4<f32>":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_depth_2d_array:"depthTexture",texture_depth_multisampled_2d:"depthTexture",texture_depth_cube:"depthTexture",texture_depth_cube_array:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"},HB=r=>{r=r.trim();const e=r.match(VB);if(e!==null&&e.length===4){const t=e[2],n=[];let i=null;for(;(i=zB.exec(t))!==null;)n.push({name:i[1],type:i[2]});const s=[];for(let u=0;u<n.length;u++){const{name:h,type:d}=n[u];let f=d;f.startsWith("ptr")?f="pointer":(f.startsWith("texture")&&(f=d.split("<")[0]),f=S0[f]),s.push(new Zm(f,h))}const o=r.substring(e[0].length),a=e[3]||"void",l=e[1]!==void 0?e[1]:"";return{type:S0[a]||a,inputs:s,name:l,inputsCode:t,blockCode:o,outputType:a}}else throw new Error("FunctionNode: Function is not a WGSL code.")};class WB extends Jm{constructor(e){const{type:t,inputs:n,name:i,inputsCode:s,blockCode:o,outputType:a}=HB(e);super(t,n,i),this.inputsCode=s,this.blockCode=o,this.outputType=a}getCode(e=this.name){const t=this.outputType!=="void"?"-> "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class $B extends Lb{parseFunction(e){return new WB(e)}}const XB={[Ui.READ_ONLY]:"read",[Ui.WRITE_ONLY]:"write",[Ui.READ_WRITE]:"read_write"},T0={[go]:"repeat",[ci]:"clamp",[_o]:"mirror"},Wf={vertex:yr.VERTEX,fragment:yr.FRAGMENT,compute:yr.COMPUTE},M0={instance:!0,swizzleAssign:!1,storageBuffer:!0},qB={"^^":"tsl_xor"},jB={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3<f32>",vec2:"vec2<f32>",ivec2:"vec2<i32>",uvec2:"vec2<u32>",bvec2:"vec2<bool>",vec3:"vec3<f32>",ivec3:"vec3<i32>",uvec3:"vec3<u32>",bvec3:"vec3<bool>",vec4:"vec4<f32>",ivec4:"vec4<i32>",uvec4:"vec4<u32>",bvec4:"vec4<bool>",mat2:"mat2x2<f32>",mat3:"mat3x3<f32>",mat4:"mat4x4<f32>"},E0={},zl={tsl_xor:new Rn("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new Rn("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new Rn("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new Rn("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new Rn("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new Rn("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new Rn("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new Rn("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new Rn("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new Rn("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new Rn("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new Rn("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),biquadraticTexture:new Rn(`
4877
4877
  fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f {
4878
4878
 
4879
4879
  let res = vec2f( iRes );
@@ -4927,7 +4927,7 @@ fn tsl_biquadraticTexture_array( map : texture_2d_array<f32>, coord : vec2f, iRe
4927
4927
  );
4928
4928
 
4929
4929
  }
4930
- `,E0[t]=n=new Rn(o,i)}return n.build(this),t}generateArrayDeclaration(e,t){return`array< ${this.getType(e)}, ${t} >`}generateTextureDimension(e,t,n){const i=this.getDataFromNode(e,this.shaderStage,this.cache);i.dimensionsSnippet===void 0&&(i.dimensionsSnippet={});let s=i.dimensionsSnippet[n];if(i.dimensionsSnippet[n]===void 0){let o,a;const{primarySamples:l}=this.renderer.backend.utils.getTextureSampleData(e),c=l>1;e.is3DTexture||e.isData3DTexture?a="vec3<u32>":a="vec2<u32>",c||e.isStorageTexture?o=t:o=`${t}${n?`, u32( ${n} )`:""}`,s=new hh(new dh(`textureDimensions( ${o} )`,a)),i.dimensionsSnippet[n]=s,(e.isArrayTexture||e.isDataArrayTexture||e.is3DTexture||e.isData3DTexture)&&(i.arrayLayerCount=new hh(new dh(`textureNumLayers(${t})`,"u32"))),e.isTextureCube&&(i.cubeFaceCount=new hh(new dh("6u","u32")))}return s.build(this)}generateFilteredTexture(e,t,n,i,s="0u",o){const a=this.generateWrapFunction(e),l=this.generateTextureDimension(e,t,s);return i&&(n=`${n} + vec2<f32>(${i}) / ${l}`),o?(this._include("biquadraticTextureArray"),`tsl_biquadraticTexture_array( ${t}, ${a}( ${n} ), ${l}, u32( ${o} ), u32( ${s} ) )`):(this._include("biquadraticTexture"),`tsl_biquadraticTexture( ${t}, ${a}( ${n} ), ${l}, u32( ${s} ) )`)}generateTextureLod(e,t,n,i,s,o="0u"){if(e.isCubeTexture===!0){s&&(n=`${n} + vec3<f32>(${s})`);const f=e.isDepthTexture?"u32":"f32";return`textureSampleLevel( ${t}, ${t}_sampler, ${n}, ${f}( ${o} ) )`}const a=this.generateWrapFunction(e),l=this.generateTextureDimension(e,t,o),c=e.is3DTexture||e.isData3DTexture?"vec3":"vec2",u=c==="vec3"?"vec3<u32>( 1, 1, 1 )":"vec2<u32>( 1, 1 )";s&&(n=`${n} + ${c}<f32>(${s}) / ${c}<f32>( ${l} )`);const h=`${c}<f32>( 0 )`,d=`${c}<f32>( ${l} - ${u} )`;return n=`${c}<u32>( clamp( floor( ${a}( ${n} ) * ${c}<f32>( ${l} ) ), ${h}, ${d} ) )`,this.generateTextureLoad(e,t,n,o,i,null)}generateStorageTextureLoad(e,t,n,i,s,o){o&&(n=`${n} + ${o}`);let a;return s?a=`textureLoad( ${t}, ${n}, ${s} )`:a=`textureLoad( ${t}, ${n} )`,a}generateTextureLoad(e,t,n,i,s,o){i===null&&(i="0u"),o&&(n=`${n} + ${o}`);let a;return s?a=`textureLoad( ${t}, ${n}, ${s}, u32( ${i} ) )`:(a=`textureLoad( ${t}, ${n}, u32( ${i} ) )`,this.renderer.backend.compatibilityMode&&e.isDepthTexture&&(a+=".x")),a}generateTextureStore(e,t,n,i,s){let o;return i?o=`textureStore( ${t}, ${n}, ${i}, ${s} )`:o=`textureStore( ${t}, ${n}, ${s} )`,o}isSampleCompare(e){return e.isDepthTexture===!0&&e.compareFunction!==null&&this.renderer.hasCompatibility(wo.TEXTURE_COMPARE)}isUnfilterable(e){return this.getComponentTypeFromTexture(e)!=="float"||!this.isAvailable("float32Filterable")&&e.type===Qt||this.isSampleCompare(e)===!1&&e.minFilter===Mt&&e.magFilter===Mt||this.renderer.backend.utils.getTextureSampleData(e).primarySamples>1}generateTexture(e,t,n,i,s,o=this.shaderStage){let a=null;return this.isUnfilterable(e)?a=this.generateTextureLod(e,t,n,i,s,"0",o):a=this._generateTextureSample(e,t,n,i,s,o),a}generateTextureGrad(e,t,n,i,s,o,a=this.shaderStage){if(a==="fragment")return s?o?`textureSampleGrad( ${t}, ${t}_sampler, ${n}, ${s}, ${i[0]}, ${i[1]}, ${o} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${n}, ${s}, ${i[0]}, ${i[1]} )`:o?`textureSampleGrad( ${t}, ${t}_sampler, ${n}, ${i[0]}, ${i[1]}, ${o} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${n}, ${i[0]}, ${i[1]} )`;ce(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${a} shader.`)}generateTextureCompare(e,t,n,i,s,o,a=this.shaderStage){if(a==="fragment")return e.isDepthTexture===!0&&e.isArrayTexture===!0?o?`textureSampleCompare( ${t}, ${t}_sampler, ${n}, ${s}, ${i}, ${o} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${n}, ${s}, ${i} )`:o?`textureSampleCompare( ${t}, ${t}_sampler, ${n}, ${i}, ${o} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${n}, ${i} )`;ce(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${a} shader.`)}generateTextureLevel(e,t,n,i,s,o){return this.isUnfilterable(e)===!1?s?o?`textureSampleLevel( ${t}, ${t}_sampler, ${n}, ${s}, ${i}, ${o} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${n}, ${s}, ${i} )`:o?`textureSampleLevel( ${t}, ${t}_sampler, ${n}, ${i}, ${o} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${n}, ${i} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,n,o,i,s):this.generateTextureLod(e,t,n,s,o,i)}generateTextureBias(e,t,n,i,s,o,a=this.shaderStage){if(a==="fragment")return s?o?`textureSampleBias( ${t}, ${t}_sampler, ${n}, ${s}, ${i}, ${o} )`:`textureSampleBias( ${t}, ${t}_sampler, ${n}, ${s}, ${i} )`:o?`textureSampleBias( ${t}, ${t}_sampler, ${n}, ${i}, ${o} )`:`textureSampleBias( ${t}, ${t}_sampler, ${n}, ${i} )`;ce(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${a} shader.`)}getPropertyName(e,t=this.shaderStage){if(e.isNodeVarying===!0&&e.needsInterpolation===!0){if(t==="vertex")return`varyings.${e.name}`}else if(e.isNodeUniform===!0){const n=e.name,i=e.type;return i==="texture"||i==="cubeTexture"||i==="cubeDepthTexture"||i==="storageTexture"||i==="texture3D"?n:i==="buffer"||i==="storageBuffer"||i==="indirectStorageBuffer"?this.isCustomStruct(e)?n:n+".value":e.groupNode.name+"."+n}return super.getPropertyName(e)}getOutputStructName(){return"output"}getFunctionOperator(e){const t=qB[e];return t!==void 0?(this._include(t),t):null}getNodeAccess(e,t){return t!=="compute"?e.isAtomic===!0?(ae("WebGPURenderer: Atomic operations are only supported in compute shaders."),Fi.READ_WRITE):Fi.READ_ONLY:e.access}getStorageAccess(e,t){return XB[this.getNodeAccess(e,t)]}getUniformFromNode(e,t,n,i=null){const s=super.getUniformFromNode(e,t,n,i),o=this.getDataFromNode(e,n,this.globalCache);if(o.uniformGPU===void 0){let a;const l=e.groupNode,c=l.name,u=this.getBindGroupArray(c,n);if(t==="texture"||t==="cubeTexture"||t==="cubeDepthTexture"||t==="storageTexture"||t==="texture3D"){let h=null;const d=this.getNodeAccess(e,n);if(t==="texture"||t==="storageTexture"?e.value.is3DTexture===!0?h=new Cp(s.name,s.node,l,d):h=new td(s.name,s.node,l,d):t==="cubeTexture"||t==="cubeDepthTexture"?h=new Vb(s.name,s.node,l,d):t==="texture3D"&&(h=new Cp(s.name,s.node,l,d)),h.store=e.isStorageTextureNode===!0,h.mipLevel=h.store?e.mipLevel:0,h.setVisibility(Wf[n]),e.value.isCubeTexture===!0||this.isUnfilterable(e.value)===!1&&h.store===!1){const p=new LB(`${s.name}_sampler`,s.node,l);p.setVisibility(Wf[n]),u.push(p,h),a=[p,h]}else u.push(h),a=[h]}else if(t==="buffer"||t==="storageBuffer"||t==="indirectStorageBuffer"){const h=this.getSharedDataFromNode(e);let d=h.buffer;if(d===void 0){const f=t==="buffer"?Ob:IB;d=new f(e,l),h.buffer=d}d.setVisibility(d.getVisibility()|Wf[n]),u.push(d),a=d,s.name=i||"NodeBuffer_"+s.id}else{let h=this.uniformGroups[c];h===void 0&&(h=new kb(c,l),h.setVisibility(yr.VERTEX|yr.FRAGMENT|yr.COMPUTE),this.uniformGroups[c]=h),u.indexOf(h)===-1&&u.push(h),a=this.getNodeUniform(s,t);const d=a.name;h.uniforms.some(p=>p.name===d)||h.addUniform(a)}o.uniformGPU=a}return s}getBuiltin(e,t,n,i=this.shaderStage){const s=this.builtins[i]||(this.builtins[i]=new Map);return s.has(e)===!1&&s.set(e,{name:e,property:t,type:n}),t}hasBuiltin(e,t=this.shaderStage){return this.builtins[t]!==void 0&&this.builtins[t].has(e)}getVertexIndex(){return this.shaderStage==="vertex"?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,n=this.flowShaderNode(e),i=[];for(const o of t.inputs)i.push(o.name+" : "+this.getType(o.type));let s=`fn ${t.name}( ${i.join(", ")} ) -> ${this.getType(t.type)} {
4930
+ `,E0[t]=n=new Rn(o,i)}return n.build(this),t}generateArrayDeclaration(e,t){return`array< ${this.getType(e)}, ${t} >`}generateTextureDimension(e,t,n){const i=this.getDataFromNode(e,this.shaderStage,this.cache);i.dimensionsSnippet===void 0&&(i.dimensionsSnippet={});let s=i.dimensionsSnippet[n];if(i.dimensionsSnippet[n]===void 0){let o,a;const{primarySamples:l}=this.renderer.backend.utils.getTextureSampleData(e),c=l>1;e.is3DTexture||e.isData3DTexture?a="vec3<u32>":a="vec2<u32>",c||e.isStorageTexture?o=t:o=`${t}${n?`, u32( ${n} )`:""}`,s=new hh(new dh(`textureDimensions( ${o} )`,a)),i.dimensionsSnippet[n]=s,(e.isArrayTexture||e.isDataArrayTexture||e.is3DTexture||e.isData3DTexture)&&(i.arrayLayerCount=new hh(new dh(`textureNumLayers(${t})`,"u32"))),e.isTextureCube&&(i.cubeFaceCount=new hh(new dh("6u","u32")))}return s.build(this)}generateFilteredTexture(e,t,n,i,s="0u",o){const a=this.generateWrapFunction(e),l=this.generateTextureDimension(e,t,s);return i&&(n=`${n} + vec2<f32>(${i}) / ${l}`),o?(this._include("biquadraticTextureArray"),`tsl_biquadraticTexture_array( ${t}, ${a}( ${n} ), ${l}, u32( ${o} ), u32( ${s} ) )`):(this._include("biquadraticTexture"),`tsl_biquadraticTexture( ${t}, ${a}( ${n} ), ${l}, u32( ${s} ) )`)}generateTextureLod(e,t,n,i,s,o="0u"){if(e.isCubeTexture===!0){s&&(n=`${n} + vec3<f32>(${s})`);const f=e.isDepthTexture?"u32":"f32";return`textureSampleLevel( ${t}, ${t}_sampler, ${n}, ${f}( ${o} ) )`}const a=this.generateWrapFunction(e),l=this.generateTextureDimension(e,t,o),c=e.is3DTexture||e.isData3DTexture?"vec3":"vec2",u=c==="vec3"?"vec3<u32>( 1, 1, 1 )":"vec2<u32>( 1, 1 )";s&&(n=`${n} + ${c}<f32>(${s}) / ${c}<f32>( ${l} )`);const h=`${c}<f32>( 0 )`,d=`${c}<f32>( ${l} - ${u} )`;return n=`${c}<u32>( clamp( floor( ${a}( ${n} ) * ${c}<f32>( ${l} ) ), ${h}, ${d} ) )`,this.generateTextureLoad(e,t,n,o,i,null)}generateStorageTextureLoad(e,t,n,i,s,o){o&&(n=`${n} + ${o}`);let a;return s?a=`textureLoad( ${t}, ${n}, ${s} )`:a=`textureLoad( ${t}, ${n} )`,a}generateTextureLoad(e,t,n,i,s,o){i===null&&(i="0u"),o&&(n=`${n} + ${o}`);let a;return s?a=`textureLoad( ${t}, ${n}, ${s}, u32( ${i} ) )`:(a=`textureLoad( ${t}, ${n}, u32( ${i} ) )`,this.renderer.backend.compatibilityMode&&e.isDepthTexture&&(a+=".x")),a}generateTextureStore(e,t,n,i,s){let o;return i?o=`textureStore( ${t}, ${n}, ${i}, ${s} )`:o=`textureStore( ${t}, ${n}, ${s} )`,o}isSampleCompare(e){return e.isDepthTexture===!0&&e.compareFunction!==null&&this.renderer.hasCompatibility(wo.TEXTURE_COMPARE)}isUnfilterable(e){return this.getComponentTypeFromTexture(e)!=="float"||!this.isAvailable("float32Filterable")&&e.type===Qt||this.isSampleCompare(e)===!1&&e.minFilter===Mt&&e.magFilter===Mt||this.renderer.backend.utils.getTextureSampleData(e).primarySamples>1}generateTexture(e,t,n,i,s,o=this.shaderStage){let a=null;return this.isUnfilterable(e)?a=this.generateTextureLod(e,t,n,i,s,"0",o):a=this._generateTextureSample(e,t,n,i,s,o),a}generateTextureGrad(e,t,n,i,s,o,a=this.shaderStage){if(a==="fragment")return s?o?`textureSampleGrad( ${t}, ${t}_sampler, ${n}, ${s}, ${i[0]}, ${i[1]}, ${o} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${n}, ${s}, ${i[0]}, ${i[1]} )`:o?`textureSampleGrad( ${t}, ${t}_sampler, ${n}, ${i[0]}, ${i[1]}, ${o} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${n}, ${i[0]}, ${i[1]} )`;ce(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${a} shader.`)}generateTextureCompare(e,t,n,i,s,o,a=this.shaderStage){if(a==="fragment")return e.isDepthTexture===!0&&e.isArrayTexture===!0?o?`textureSampleCompare( ${t}, ${t}_sampler, ${n}, ${s}, ${i}, ${o} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${n}, ${s}, ${i} )`:o?`textureSampleCompare( ${t}, ${t}_sampler, ${n}, ${i}, ${o} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${n}, ${i} )`;ce(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${a} shader.`)}generateTextureLevel(e,t,n,i,s,o){return this.isUnfilterable(e)===!1?s?o?`textureSampleLevel( ${t}, ${t}_sampler, ${n}, ${s}, ${i}, ${o} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${n}, ${s}, ${i} )`:o?`textureSampleLevel( ${t}, ${t}_sampler, ${n}, ${i}, ${o} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${n}, ${i} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,n,o,i,s):this.generateTextureLod(e,t,n,s,o,i)}generateTextureBias(e,t,n,i,s,o,a=this.shaderStage){if(a==="fragment")return s?o?`textureSampleBias( ${t}, ${t}_sampler, ${n}, ${s}, ${i}, ${o} )`:`textureSampleBias( ${t}, ${t}_sampler, ${n}, ${s}, ${i} )`:o?`textureSampleBias( ${t}, ${t}_sampler, ${n}, ${i}, ${o} )`:`textureSampleBias( ${t}, ${t}_sampler, ${n}, ${i} )`;ce(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${a} shader.`)}getPropertyName(e,t=this.shaderStage){if(e.isNodeVarying===!0&&e.needsInterpolation===!0){if(t==="vertex")return`varyings.${e.name}`}else if(e.isNodeUniform===!0){const n=e.name,i=e.type;return i==="texture"||i==="cubeTexture"||i==="cubeDepthTexture"||i==="storageTexture"||i==="texture3D"?n:i==="buffer"||i==="storageBuffer"||i==="indirectStorageBuffer"?this.isCustomStruct(e)?n:n+".value":e.groupNode.name+"."+n}return super.getPropertyName(e)}getOutputStructName(){return"output"}getFunctionOperator(e){const t=qB[e];return t!==void 0?(this._include(t),t):null}getNodeAccess(e,t){return t!=="compute"?e.isAtomic===!0?(ae("WebGPURenderer: Atomic operations are only supported in compute shaders."),Ui.READ_WRITE):Ui.READ_ONLY:e.access}getStorageAccess(e,t){return XB[this.getNodeAccess(e,t)]}getUniformFromNode(e,t,n,i=null){const s=super.getUniformFromNode(e,t,n,i),o=this.getDataFromNode(e,n,this.globalCache);if(o.uniformGPU===void 0){let a;const l=e.groupNode,c=l.name,u=this.getBindGroupArray(c,n);if(t==="texture"||t==="cubeTexture"||t==="cubeDepthTexture"||t==="storageTexture"||t==="texture3D"){let h=null;const d=this.getNodeAccess(e,n);if(t==="texture"||t==="storageTexture"?e.value.is3DTexture===!0?h=new Cp(s.name,s.node,l,d):h=new td(s.name,s.node,l,d):t==="cubeTexture"||t==="cubeDepthTexture"?h=new Vb(s.name,s.node,l,d):t==="texture3D"&&(h=new Cp(s.name,s.node,l,d)),h.store=e.isStorageTextureNode===!0,h.mipLevel=h.store?e.mipLevel:0,h.setVisibility(Wf[n]),e.value.isCubeTexture===!0||this.isUnfilterable(e.value)===!1&&h.store===!1){const p=new LB(`${s.name}_sampler`,s.node,l);p.setVisibility(Wf[n]),u.push(p,h),a=[p,h]}else u.push(h),a=[h]}else if(t==="buffer"||t==="storageBuffer"||t==="indirectStorageBuffer"){const h=this.getSharedDataFromNode(e);let d=h.buffer;if(d===void 0){const f=t==="buffer"?Ob:IB;d=new f(e,l),h.buffer=d}d.setVisibility(d.getVisibility()|Wf[n]),u.push(d),a=d,s.name=i||"NodeBuffer_"+s.id}else{let h=this.uniformGroups[c];h===void 0&&(h=new kb(c,l),h.setVisibility(yr.VERTEX|yr.FRAGMENT|yr.COMPUTE),this.uniformGroups[c]=h),u.indexOf(h)===-1&&u.push(h),a=this.getNodeUniform(s,t);const d=a.name;h.uniforms.some(p=>p.name===d)||h.addUniform(a)}o.uniformGPU=a}return s}getBuiltin(e,t,n,i=this.shaderStage){const s=this.builtins[i]||(this.builtins[i]=new Map);return s.has(e)===!1&&s.set(e,{name:e,property:t,type:n}),t}hasBuiltin(e,t=this.shaderStage){return this.builtins[t]!==void 0&&this.builtins[t].has(e)}getVertexIndex(){return this.shaderStage==="vertex"?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,n=this.flowShaderNode(e),i=[];for(const o of t.inputs)i.push(o.name+" : "+this.getType(o.type));let s=`fn ${t.name}( ${i.join(", ")} ) -> ${this.getType(t.type)} {
4931
4931
  ${n.vars}
4932
4932
  ${n.code}
4933
4933
  `;return n.result&&(s+=` return ${n.result};
@@ -5056,7 +5056,7 @@ struct ${e} {
5056
5056
  ${t}
5057
5057
  };`}_getWGSLStructBinding(e,t,n,i=0,s=0){const o=e+"Struct";return`${this._getWGSLStruct(o,t)}
5058
5058
  @binding( ${i} ) @group( ${s} )
5059
- var<${n}> ${e} : ${o};`}}class ZB{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return e.depth&&(e.depthTexture!==null?t=this.getTextureFormatGPU(e.depthTexture):e.stencil?this.backend.renderer.reversedDepthBuffer===!0?t=L.Depth32FloatStencil8:t=L.Depth24PlusStencil8:this.backend.renderer.reversedDepthBuffer===!0?t=L.Depth32Float:t=L.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getTextureSampleData(e){let t;if(e.isFramebufferTexture)t=1;else if(e.isDepthTexture&&!e.renderTarget){const s=this.backend.renderer,o=s.getRenderTarget();t=o?o.samples:s.currentSamples}else e.renderTarget&&(t=e.renderTarget.samples);t=t||1;const n=t>1&&e.renderTarget!==null&&e.isDepthTexture!==!0&&e.isFramebufferTexture!==!0;return{samples:t,primarySamples:n?1:t,isMSAA:n}}getCurrentColorFormat(e){let t;return e.textures!==null?t=this.getTextureFormatGPU(e.textures[0]):t=this.getPreferredCanvasFormat(),t}getCurrentColorFormats(e){return e.textures!==null?e.textures.map(t=>this.getTextureFormatGPU(t)):[this.getPreferredCanvasFormat()]}getCurrentColorSpace(e){return e.textures!==null?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){if(e.isPoints)return Qu.PointList;if(e.isLineSegments||e.isMesh&&t.wireframe===!0)return Qu.LineList;if(e.isLine)return Qu.LineStrip;if(e.isMesh)return Qu.TriangleList}getSampleCount(e){return e>=4?4:1}getSampleCountRenderContext(e){return e.textures!==null?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.currentSamples)}getPreferredCanvasFormat(){const t=this.backend.parameters.outputType;if(t===void 0)return navigator.gpu.getPreferredCanvasFormat();if(t===Xt)return L.BGRA8Unorm;if(t===tn)return L.RGBA16Float;throw new Error("Unsupported output buffer type.")}}const $b=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]);typeof Float16Array<"u"&&$b.set(Float16Array,["float16"]);const QB=new Map([[ey,["float16"]]]),JB=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class e3{constructor(e){this.backend=e}createAttribute(e,t){const n=this._getBufferAttribute(e),i=this.backend,s=i.get(n);let o=s.buffer;if(o===void 0){const a=i.device;let l=n.array;if(e.normalized===!1){if(l.constructor===Int16Array||l.constructor===Int8Array)l=new Int32Array(l);else if((l.constructor===Uint16Array||l.constructor===Uint8Array)&&(l=new Uint32Array(l),t&GPUBufferUsage.INDEX))for(let h=0;h<l.length;h++)l[h]===65535&&(l[h]=4294967295)}if(n.array=l,(n.isStorageBufferAttribute||n.isStorageInstancedBufferAttribute)&&n.itemSize===3){l=new l.constructor(n.count*4);for(let h=0;h<n.count;h++)l.set(n.array.subarray(h*3,h*3+3),h*4);n.itemSize=4,n.array=l,s._force3to4BytesAlignment=!0}const c=l.byteLength,u=c+(4-c%4)%4;o=a.createBuffer({label:n.name,size:u,usage:t,mappedAtCreation:!0}),new l.constructor(o.getMappedRange()).set(l),o.unmap(),s.buffer=o}}updateAttribute(e){const t=this._getBufferAttribute(e),n=this.backend,i=n.device,s=n.get(t),o=n.get(t).buffer;let a=t.array;if(s._force3to4BytesAlignment===!0){a=new a.constructor(t.count*4);for(let c=0;c<t.count;c++)a.set(t.array.subarray(c*3,c*3+3),c*4);t.array=a}const l=t.updateRanges;if(l.length===0)i.queue.writeBuffer(o,0,a,0);else{const c=gh(a),u=c?1:a.BYTES_PER_ELEMENT;for(let h=0,d=l.length;h<d;h++){const f=l[h];let p,g;if(s._force3to4BytesAlignment===!0){const _=Math.floor(f.start/3),x=Math.ceil(f.count/3);p=_*4*u,g=x*4*u}else p=f.start*u,g=f.count*u;const m=p*(c?a.BYTES_PER_ELEMENT:1);i.queue.writeBuffer(o,m,a,p,g)}t.clearUpdateRanges()}}createShaderVertexBuffers(e){const t=e.getAttributes(),n=new Map;for(let i=0;i<t.length;i++){const s=t[i],o=s.array.BYTES_PER_ELEMENT,a=this._getBufferAttribute(s);let l=n.get(a);if(l===void 0){let h,d;s.isInterleavedBufferAttribute===!0?(h=s.data.stride*o,d=s.data.isInstancedInterleavedBuffer?Ju.Instance:Ju.Vertex):(h=s.itemSize*o,d=s.isInstancedBufferAttribute?Ju.Instance:Ju.Vertex),s.normalized===!1&&(s.array.constructor===Int16Array||s.array.constructor===Uint16Array)&&(h=4),l={arrayStride:h,attributes:[],stepMode:d},n.set(a,l)}const c=this._getVertexFormat(s),u=s.isInterleavedBufferAttribute===!0?s.offset*o:0;l.attributes.push({shaderLocation:i,offset:u,format:c})}return Array.from(n.values())}destroyAttribute(e){const t=this.backend;t.get(this._getBufferAttribute(e)).buffer.destroy(),t.delete(e)}async getArrayBufferAsync(e,t=null,n=0,i=-1){const s=this.backend,o=s.device,l=s.get(this._getBufferAttribute(e)).buffer,c=i===-1?l.size-n:i;let u;if(t!==null&&t.isReadbackBuffer){const f=s.get(t);if(t._mapped===!0)throw new Error("WebGPURenderer: ReadbackBuffer must be released before being used again.");if(t._mapped=!0,f.readBufferGPU===void 0){u=o.createBuffer({label:`${t.name}_readback`,size:t.maxByteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});const p=()=>{t.buffer=null,t._mapped=!1,u.unmap()},g=()=>{t.buffer=null,t._mapped=!1,u.destroy(),s.delete(t),t.removeEventListener("release",p),t.removeEventListener("dispose",g)};t.addEventListener("release",p),t.addEventListener("dispose",g),f.readBufferGPU=u}else u=f.readBufferGPU}else u=o.createBuffer({label:`${e.name}_readback`,size:c,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});const h=o.createCommandEncoder({label:`readback_encoder_${e.name}`});h.copyBufferToBuffer(l,n,u,0,c);const d=h.finish();if(o.queue.submit([d]),await u.mapAsync(GPUMapMode.READ,0,c),t===null){const p=u.getMappedRange(0,c).slice();return u.destroy(),p}else{if(t.isReadbackBuffer)return t.buffer=u.getMappedRange(0,c),t;{const f=u.getMappedRange(0,c);return new Uint8Array(t).set(new Uint8Array(f)),u.destroy(),t}}}_getVertexFormat(e){const{itemSize:t,normalized:n}=e,i=e.array.constructor,s=e.constructor;let o;if(t===1)o=JB.get(i);else{const l=(QB.get(s)||$b.get(i))[n?1:0];if(l){const c=i.BYTES_PER_ELEMENT*t,h=Math.floor((c+3)/4)*4/i.BYTES_PER_ELEMENT;if(h%1)throw new Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");o=`${l}x${h}`}}return o||ce("WebGPUAttributeUtils: Vertex format not supported yet."),o}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}class t3{constructor(e){this.layoutGPU=e,this.usedTimes=0}}class n3{constructor(e){this.backend=e,this._bindGroupLayoutCache=new Map}createBindingsLayout(e){const t=this.backend,n=t.device,i=t.get(e);if(i.layout)return i.layout.layoutGPU;const s=this._createLayoutEntries(e),o=cl(JSON.stringify(s));let a=this._bindGroupLayoutCache.get(o);return a===void 0&&(a=new t3(n.createBindGroupLayout({entries:s})),this._bindGroupLayoutCache.set(o,a)),a.usedTimes++,i.layout=a,i.layoutKey=o,a.layoutGPU}createBindings(e,t,n,i=0){const{backend:s}=this,o=s.get(e),a=this.createBindingsLayout(e);let l;n>0&&(o.groups===void 0&&(o.groups=[],o.versions=[]),o.versions[n]===i&&(l=o.groups[n])),l===void 0&&(l=this.createBindGroup(e,a),n>0&&(o.groups[n]=l,o.versions[n]=i)),o.group=l}updateBinding(e){const t=this.backend,n=t.device,i=e.buffer,s=t.get(e).buffer,o=e.updateRanges;if(o.length===0)n.queue.writeBuffer(s,0,i,0);else{const a=gh(i),l=a?1:i.BYTES_PER_ELEMENT;for(let c=0,u=o.length;c<u;c++){const h=o[c],d=h.start*l,f=h.count*l,p=d*(a?i.BYTES_PER_ELEMENT:1);n.queue.writeBuffer(s,p,i,d,f)}}}createBindGroupIndex(e,t){const i=this.backend.device,s=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,o=e[0],a=i.createBuffer({label:"bindingCameraIndex_"+o,size:16,usage:s});i.queue.writeBuffer(a,0,e,0);const l=[{binding:0,resource:{buffer:a}}];return i.createBindGroup({label:"bindGroupCameraIndex_"+o,layout:t,entries:l})}createBindGroup(e,t){const n=this.backend,i=n.device;let s=0;const o=[];for(const a of e.bindings){if(a.isUniformBuffer){const l=n.get(a);if(l.buffer===void 0){const c=a.byteLength,u=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,h=[];a.visibility&yr.VERTEX&&h.push("vertex"),a.visibility&yr.FRAGMENT&&h.push("fragment"),a.visibility&yr.COMPUTE&&h.push("compute");const d=`(${h.join(",")})`,f=i.createBuffer({label:`bindingBuffer${a.id}_${a.name}_${d}`,size:c,usage:u});l.buffer=f}o.push({binding:s,resource:{buffer:l.buffer}})}else if(a.isStorageBuffer){const l=n.get(a.attribute).buffer;o.push({binding:s,resource:{buffer:l}})}else if(a.isSampledTexture){const l=n.get(a.texture);let c;if(l.externalTexture!==void 0)c=i.importExternalTexture({source:l.externalTexture});else{const u=a.store?1:l.texture.mipLevelCount,h=a.store?a.mipLevel:0;let d=`view-${l.texture.width}-${l.texture.height}`;if(l.texture.depthOrArrayLayers>1&&(d+=`-${l.texture.depthOrArrayLayers}`),d+=`-${u}-${h}`,c=l[d],c===void 0){const f=DB.All;let p;a.isSampledCubeTexture?p=Wn.Cube:a.isSampledTexture3D?p=Wn.ThreeD:a.texture.isArrayTexture||a.texture.isDataArrayTexture||a.texture.isCompressedArrayTexture?p=Wn.TwoDArray:p=Wn.TwoD,c=l[d]=l.texture.createView({aspect:f,dimension:p,mipLevelCount:u,baseMipLevel:h})}}o.push({binding:s,resource:c})}else if(a.isSampler){const l=n.get(a.texture);o.push({binding:s,resource:l.sampler})}s++}return i.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:o})}_createLayoutEntries(e){const t=[];let n=0;for(const i of e.bindings){const s=this.backend,o={binding:n,visibility:i.visibility};if(i.isUniformBuffer||i.isStorageBuffer){const a={};i.isStorageBuffer&&(i.visibility&yr.COMPUTE&&(i.access===Fi.READ_WRITE||i.access===Fi.WRITE_ONLY)?a.type=zf.Storage:a.type=zf.ReadOnlyStorage),o.buffer=a}else if(i.isSampledTexture&&i.store){const a={};a.format=this.backend.get(i.texture).texture.format;const l=i.access;l===Fi.READ_WRITE?a.access=Hf.ReadWrite:l===Fi.WRITE_ONLY?a.access=Hf.WriteOnly:a.access=Hf.ReadOnly,i.texture.isArrayTexture?a.viewDimension=Wn.TwoDArray:i.texture.is3DTexture&&(a.viewDimension=Wn.ThreeD),o.storageTexture=a}else if(i.isSampledTexture){const a={},{primarySamples:l}=s.utils.getTextureSampleData(i.texture);if(l>1&&(a.multisampled=!0,i.texture.isDepthTexture||(a.sampleType=Qs.UnfilterableFloat)),i.texture.isDepthTexture)s.compatibilityMode&&i.texture.compareFunction===null?a.sampleType=Qs.UnfilterableFloat:a.sampleType=Qs.Depth;else if(i.texture.isDataTexture||i.texture.isDataArrayTexture||i.texture.isData3DTexture||i.texture.isStorageTexture){const c=i.texture.type;c===Sn?a.sampleType=Qs.SInt:c===Ct?a.sampleType=Qs.UInt:c===Qt&&(this.backend.hasFeature("float32-filterable")?a.sampleType=Qs.Float:a.sampleType=Qs.UnfilterableFloat)}i.isSampledCubeTexture?a.viewDimension=Wn.Cube:i.texture.isArrayTexture||i.texture.isDataArrayTexture||i.texture.isCompressedArrayTexture?a.viewDimension=Wn.TwoDArray:i.isSampledTexture3D&&(a.viewDimension=Wn.ThreeD),o.texture=a}else if(i.isSampler){const a={};i.texture.isDepthTexture&&(i.texture.compareFunction!==null&&s.hasCompatibility(wo.TEXTURE_COMPARE)?a.type=y0.Comparison:a.type=y0.NonFiltering),o.sampler=a}else ce(`WebGPUBindingUtils: Unsupported binding "${i}".`);t.push(o),n++}return t}deleteBindGroupData(e){const{backend:t}=this,n=t.get(e);n.layout&&(n.layout.usedTimes--,n.layout.usedTimes===0&&this._bindGroupLayoutCache.delete(n.layoutKey),n.layout=void 0,n.layoutKey=void 0)}dispose(){this._bindGroupLayoutCache.clear()}}class i3{constructor(e){this.backend=e}getMaxAnisotropy(){return 16}getUniformBufferLimit(){return this.backend.device.limits.maxUniformBufferBindingSize}}class r3{constructor(e){this.backend=e,this._activePipelines=new WeakMap}setPipeline(e,t){this._activePipelines.get(e)!==t&&(e.setPipeline(t),this._activePipelines.set(e,t))}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:n,material:i,geometry:s,pipeline:o}=e,{vertexProgram:a,fragmentProgram:l}=o,c=this.backend,u=c.device,h=c.utils,d=c.get(o),f=[];for(const V of e.getBindings()){const z=c.get(V),{layoutGPU:U}=z.layout;f.push(U)}const p=c.attributeUtils.createShaderVertexBuffers(e);let g;i.blending!==Pn&&(i.blending!==ti||i.transparent!==!1)&&(g=this._getBlending(i));let m={};i.stencilWrite===!0&&(m={compare:this._getStencilCompare(i),failOp:this._getStencilOperation(i.stencilFail),depthFailOp:this._getStencilOperation(i.stencilZFail),passOp:this._getStencilOperation(i.stencilZPass)});const _=this._getColorWriteMask(i),x=[];if(e.context.textures!==null){const V=e.context.textures,z=e.context.mrt;for(let U=0;U<V.length;U++){const B=V[U],D=h.getTextureFormatGPU(B);let X;if(z!==null)if(this.backend.compatibilityMode!==!0){const K=z.getBlendMode(B.name);K.blending===V0?X=g:K.blending!==Pn&&(X=this._getBlending(K))}else Kt("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets."),X=g;else X=g;x.push({format:D,blend:X,writeMask:_})}}else{const V=h.getCurrentColorFormat(e.context);x.push({format:V,blend:g,writeMask:_})}const y=c.get(a).module,b=c.get(l).module,M=this._getPrimitiveState(n,s,i),S=this._getDepthCompare(i),E=h.getCurrentDepthStencilFormat(e.context),v=this._getSampleCount(e.context),w={label:`renderPipeline_${i.name||i.type}_${i.id}`,vertex:Object.assign({},y,{buffers:p}),fragment:Object.assign({},b,{targets:x}),primitive:M,multisample:{count:v,alphaToCoverageEnabled:i.alphaToCoverage&&v>1},layout:u.createPipelineLayout({bindGroupLayouts:f})},N={},C=e.context.depth,F=e.context.stencil;if((C===!0||F===!0)&&(C===!0&&(N.format=E,N.depthWriteEnabled=i.depthWrite,N.depthCompare=S),F===!0&&(N.stencilFront=m,N.stencilBack=m,N.stencilReadMask=i.stencilFuncMask,N.stencilWriteMask=i.stencilWriteMask),i.polygonOffset===!0&&(N.depthBias=i.polygonOffsetUnits,N.depthBiasSlopeScale=i.polygonOffsetFactor,N.depthBiasClamp=0),w.depthStencil=N),u.pushErrorScope("validation"),t===null)d.pipeline=u.createRenderPipeline(w),u.popErrorScope().then(V=>{V!==null&&(d.error=!0,ce(V.message))});else{const V=new Promise(async z=>{try{d.pipeline=await u.createRenderPipelineAsync(w)}catch{}const U=await u.popErrorScope();U!==null&&(d.error=!0,ce(U.message)),z()});t.push(V)}}createBundleEncoder(e,t="renderBundleEncoder"){const n=this.backend,{utils:i,device:s}=n,o=i.getCurrentDepthStencilFormat(e),a=i.getCurrentColorFormats(e),l=this._getSampleCount(e),c={label:t,colorFormats:a,depthStencilFormat:o,sampleCount:l};return s.createRenderBundleEncoder(c)}createComputePipeline(e,t){const n=this.backend,i=n.device,s=n.get(e.computeProgram).module,o=n.get(e),a=[];for(const l of t){const c=n.get(l),{layoutGPU:u}=c.layout;a.push(u)}o.pipeline=i.createComputePipeline({compute:s,layout:i.createPipelineLayout({bindGroupLayouts:a})})}_getBlending(e){let t,n;const i=e.blending,s=e.blendSrc,o=e.blendDst,a=e.blendEquation;if(i===co){const l=e.blendSrcAlpha!==null?e.blendSrcAlpha:s,c=e.blendDstAlpha!==null?e.blendDstAlpha:o,u=e.blendEquationAlpha!==null?e.blendEquationAlpha:a;t={srcFactor:this._getBlendFactor(s),dstFactor:this._getBlendFactor(o),operation:this._getBlendOperation(a)},n={srcFactor:this._getBlendFactor(l),dstFactor:this._getBlendFactor(c),operation:this._getBlendOperation(u)}}else{const l=e.premultipliedAlpha,c=(u,h,d,f)=>{t={srcFactor:u,dstFactor:h,operation:Zs.Add},n={srcFactor:d,dstFactor:f,operation:Zs.Add}};if(l)switch(i){case ti:c(_t.One,_t.OneMinusSrcAlpha,_t.One,_t.OneMinusSrcAlpha);break;case _s:c(_t.One,_t.One,_t.One,_t.One);break;case xs:c(_t.Zero,_t.OneMinusSrc,_t.Zero,_t.One);break;case ys:c(_t.Dst,_t.OneMinusSrcAlpha,_t.Zero,_t.One);break}else switch(i){case ti:c(_t.SrcAlpha,_t.OneMinusSrcAlpha,_t.One,_t.OneMinusSrcAlpha);break;case _s:c(_t.SrcAlpha,_t.One,_t.One,_t.One);break;case xs:ce(`WebGPURenderer: "SubtractiveBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`);break;case ys:ce(`WebGPURenderer: "MultiplyBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`);break}}if(t!==void 0&&n!==void 0)return{color:t,alpha:n};ce("WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(e){let t;switch(e){case Gr:t=_t.Zero;break;case kp:t=_t.One;break;case Gp:t=_t.Src;break;case Vp:t=_t.OneMinusSrc;break;case oc:t=_t.SrcAlpha;break;case ac:t=_t.OneMinusSrcAlpha;break;case Wp:t=_t.Dst;break;case $p:t=_t.OneMinusDst;break;case zp:t=_t.DstAlpha;break;case Hp:t=_t.OneMinusDstAlpha;break;case Xp:t=_t.SrcAlphaSaturated;break;case kF:t=_t.Constant;break;case GF:t=_t.OneMinusConstant;break;default:ce("WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const n=e.stencilFunc;switch(n){case XS:t=Ln.Never;break;case np:t=Ln.Always;break;case qS:t=Ln.Less;break;case YS:t=Ln.LessEqual;break;case jS:t=Ln.Equal;break;case QS:t=Ln.GreaterEqual;break;case KS:t=Ln.Greater;break;case ZS:t=Ln.NotEqual;break;default:ce("WebGPURenderer: Invalid stencil function.",n)}return t}_getStencilOperation(e){let t;switch(e){case eo:t=fs.Keep;break;case kS:t=fs.Zero;break;case GS:t=fs.Replace;break;case $S:t=fs.Invert;break;case VS:t=fs.IncrementClamp;break;case zS:t=fs.DecrementClamp;break;case HS:t=fs.IncrementWrap;break;case WS:t=fs.DecrementWrap;break;default:ce("WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Xn:t=Zs.Add;break;case Bp:t=Zs.Subtract;break;case Op:t=Zs.ReverseSubtract;break;case z0:t=Zs.Min;break;case H0:t=Zs.Max;break;default:ce("WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,n){const i={},s=this.backend.utils;i.topology=s.getPrimitiveTopology(e,n),t.index!==null&&e.isLine===!0&&e.isLineSegments!==!0&&(i.stripIndexFormat=t.index.array instanceof Uint16Array?Ph.Uint16:Ph.Uint32);let o=n.side===Lt;return e.isMesh&&e.matrixWorld.determinant()<0&&(o=!o),i.frontFace=o===!0?g0.CW:g0.CCW,i.cullMode=n.side===Nn?_0.None:_0.Back,i}_getColorWriteMask(e){return e.colorWrite===!0?x0.All:x0.None}_getDepthCompare(e){let t;if(e.depthTest===!1)t=Ln.Always;else{const n=this.backend.parameters.reversedDepthBuffer?sm[e.depthFunc]:e.depthFunc;switch(n){case lc:t=Ln.Never;break;case cc:t=Ln.Always;break;case uc:t=Ln.Less;break;case Ds:t=Ln.LessEqual;break;case hc:t=Ln.Equal;break;case dc:t=Ln.GreaterEqual;break;case fc:t=Ln.Greater;break;case pc:t=Ln.NotEqual;break;default:ce("WebGPUPipelineUtils: Invalid depth function.",n)}}return t}}class s3 extends Hb{constructor(e,t,n=2048){super(n),this.device=e,this.type=t,this.querySet=this.device.createQuerySet({type:"timestamp",count:this.maxQueries,label:`queryset_global_timestamp_${t}`});const i=this.maxQueries*8;this.resolveBuffer=this.device.createBuffer({label:`buffer_timestamp_resolve_${t}`,size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.resultBuffer=this.device.createBuffer({label:`buffer_timestamp_result_${t}`,size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ})}allocateQueriesForContext(e){if(!this.trackTimestamp||this.isDisposed)return null;if(this.currentQueryIndex+2>this.maxQueries)return Kt(`WebGPUTimestampQueryPool [${this.type}]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${this.type.toUpperCase()} ).`),null;const t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryOffsets.set(e,t),t}async resolveQueriesAsync(){if(!this.trackTimestamp||this.currentQueryIndex===0||this.isDisposed)return this.lastValue;if(this.pendingResolve)return this.pendingResolve;this.pendingResolve=this._resolveQueries();try{return await this.pendingResolve}finally{this.pendingResolve=null}}async _resolveQueries(){if(this.isDisposed)return this.lastValue;try{if(this.resultBuffer.mapState!=="unmapped")return this.lastValue;const e=new Map(this.queryOffsets),t=this.currentQueryIndex,n=t*8;this.currentQueryIndex=0,this.queryOffsets.clear();const i=this.device.createCommandEncoder();i.resolveQuerySet(this.querySet,0,t,this.resolveBuffer,0),i.copyBufferToBuffer(this.resolveBuffer,0,this.resultBuffer,0,n);const s=i.finish();if(this.device.queue.submit([s]),this.resultBuffer.mapState!=="unmapped")return this.lastValue;if(await this.resultBuffer.mapAsync(GPUMapMode.READ,0,n),this.isDisposed)return this.resultBuffer.mapState==="mapped"&&this.resultBuffer.unmap(),this.lastValue;const o=new BigUint64Array(this.resultBuffer.getMappedRange(0,n)),a={},l=[];for(const[u,h]of e){const d=u.match(/^(.*):f(\d+)$/),f=parseInt(d[2]);l.includes(f)===!1&&l.push(f),a[f]===void 0&&(a[f]=0);const p=o[h],g=o[h+1],m=Number(g-p)/1e6;this.timestamps.set(u,m),a[f]+=m}const c=a[l[l.length-1]];return this.resultBuffer.unmap(),this.lastValue=c,this.frames=l,c}catch(e){return ce("Error resolving queries:",e),this.resultBuffer.mapState==="mapped"&&this.resultBuffer.unmap(),this.lastValue}}async dispose(){if(!this.isDisposed){if(this.isDisposed=!0,this.pendingResolve)try{await this.pendingResolve}catch(e){ce("Error waiting for pending resolve:",e)}if(this.resultBuffer&&this.resultBuffer.mapState==="mapped")try{this.resultBuffer.unmap()}catch(e){ce("Error unmapping buffer:",e)}this.querySet&&(this.querySet.destroy(),this.querySet=null),this.resolveBuffer&&(this.resolveBuffer.destroy(),this.resolveBuffer=null),this.resultBuffer&&(this.resultBuffer.destroy(),this.resultBuffer=null),this.queryOffsets.clear(),this.pendingResolve=null}}}const Xi={r:0,g:0,b:0,a:1};class o3 extends zb{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=e.alpha===void 0?!0:e.alpha,this.parameters.requiredLimits=e.requiredLimits===void 0?{}:e.requiredLimits,this.compatibilityMode=null,this.device=null,this.defaultRenderPassdescriptor=null,this.utils=new ZB(this),this.attributeUtils=new e3(this),this.bindingUtils=new n3(this),this.capabilities=new i3(this),this.pipelineUtils=new r3(this),this.textureUtils=new GB(this),this.occludedResolveCache=new Map;const t=typeof navigator>"u"?!0:/Android/.test(navigator.userAgent)===!1;this._compatibility={[wo.TEXTURE_COMPARE]:t}}async init(e){await super.init(e);const t=this.parameters;let n;if(t.device===void 0){const i={powerPreference:t.powerPreference,featureLevel:"compatibility"},s=typeof navigator<"u"?await navigator.gpu.requestAdapter(i):null;if(s===null)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const o=Object.values(Dh),a=[];for(const c of o)s.features.has(c)&&a.push(c);const l={requiredFeatures:a,requiredLimits:t.requiredLimits};n=await s.requestDevice(l)}else n=t.device;this.compatibilityMode=!n.features.has("core-features-and-limits"),this.compatibilityMode&&(e._samples=0),n.lost.then(i=>{if(i.reason==="destroyed")return;const s={api:"WebGPU",message:i.message||"Unknown reason",reason:i.reason||null,originalEvent:i};e.onDeviceLost(s)}),this.device=n,this.trackTimestamp=this.trackTimestamp&&this.hasFeature(Dh.TimestampQuery),this.updateSize()}get context(){const e=this.renderer.getCanvasTarget(),t=this.get(e);let n=t.context;if(n===void 0){const i=this.parameters;e.isDefaultCanvasTarget===!0&&i.context!==void 0?n=i.context:n=e.domElement.getContext("webgpu"),"setAttribute"in e.domElement&&e.domElement.setAttribute("data-engine",`three.js r${Mo} webgpu`);const s=i.alpha?"premultiplied":"opaque",o=i.outputType===tn?"extended":"standard";n.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:s,toneMapping:{mode:o}}),t.context=n}return n}get coordinateSystem(){return Tr}async getArrayBufferAsync(e,t=null,n=0,i=-1){return await this.attributeUtils.getArrayBufferAsync(e,t,n,i)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){const e=this.renderer,t=e.getCanvasTarget(),n=this.get(t),i=e.currentSamples;let s=n.descriptor;if(s===void 0||n.samples!==i){s={colorAttachments:[{view:null}]},(e.depth===!0||e.stencil===!0)&&(s.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView()});const a=s.colorAttachments[0];i>0?a.view=this.textureUtils.getColorBuffer().createView():a.resolveTarget=void 0,n.descriptor=s,n.samples=i}const o=s.colorAttachments[0];return i>0?o.resolveTarget=this.context.getCurrentTexture().createView():o.view=this.context.getCurrentTexture().createView(),s}_isRenderCameraDepthArray(e){return e.depthTexture&&e.depthTexture.image.depth>1&&e.camera.isArrayCamera}_getRenderPassDescriptor(e,t={}){const n=e.renderTarget,i=this.get(n);let s=i.descriptors;(s===void 0||i.width!==n.width||i.height!==n.height||i.samples!==n.samples)&&(s={},i.descriptors=s);const o=e.getCacheKey();let a=s[o];if(a===void 0){const c=e.textures,u=[];let h;const d=this._isRenderCameraDepthArray(e);for(let f=0;f<c.length;f++){const p=this.get(c[f]),g={label:`colorAttachment_${f}`,baseMipLevel:e.activeMipmapLevel,mipLevelCount:1,baseArrayLayer:e.activeCubeFace,arrayLayerCount:1,dimension:Wn.TwoD};if(n.isRenderTarget3D)h=e.activeCubeFace,g.baseArrayLayer=0,g.dimension=Wn.ThreeD,g.depthOrArrayLayers=c[f].image.depth;else if(n.isRenderTarget&&c[f].image.depth>1)if(d===!0){const m=e.camera.cameras;for(let _=0;_<m.length;_++){const x={...g,baseArrayLayer:_,arrayLayerCount:1,dimension:Wn.TwoD},y=p.texture.createView(x);u.push({view:y,resolveTarget:void 0,depthSlice:void 0})}}else g.dimension=Wn.TwoDArray,g.depthOrArrayLayers=c[f].image.depth;if(d!==!0){const m=p.texture.createView(g);let _,x;p.msaaTexture!==void 0?(_=p.msaaTexture.createView(),x=m):(_=m,x=void 0),u.push({view:_,resolveTarget:x,depthSlice:h})}}if(a={textureViews:u},e.depth){const f=this.get(e.depthTexture),p={};(e.depthTexture.isArrayTexture||e.depthTexture.isCubeTexture)&&(p.dimension=Wn.TwoD,p.arrayLayerCount=1,p.baseArrayLayer=e.activeCubeFace),a.depthStencilView=f.texture.createView(p)}s[o]=a,i.width=n.width,i.height=n.height,i.samples=n.samples,i.activeMipmapLevel=e.activeMipmapLevel,i.activeCubeFace=e.activeCubeFace}const l={colorAttachments:[]};for(let c=0;c<a.textureViews.length;c++){const u=a.textureViews[c];let h={r:0,g:0,b:0,a:1};c===0&&t.clearValue&&(h=t.clearValue),l.colorAttachments.push({view:u.view,depthSlice:u.depthSlice,resolveTarget:u.resolveTarget,loadOp:t.loadOp||wt.Load,storeOp:t.storeOp||Jn.Store,clearValue:h})}return a.depthStencilView&&(l.depthStencilAttachment={view:a.depthStencilView}),l}beginRender(e){const t=this.get(e),n=this.device,i=e.occlusionQueryCount;let s;i>0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,s=n.createQuerySet({type:"occlusion",count:i,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=s,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(i),t.lastOcclusionObject=null);let o;e.textures===null?o=this._getDefaultRenderPassDescriptor():o=this._getRenderPassDescriptor(e,{loadOp:wt.Load}),this.initTimestampQuery(xr.RENDER,this.getTimestampUID(e),o),o.occlusionQuerySet=s;const a=o.depthStencilAttachment;if(e.textures!==null){const c=o.colorAttachments;for(let u=0;u<c.length;u++){const h=c[u];e.clearColor?(u===0?h.clearValue=e.clearColorValue:(Xi.r=0,Xi.g=0,Xi.b=0,Xi.a=1,h.clearValue=Xi),h.loadOp=wt.Clear):h.loadOp=wt.Load,h.storeOp=Jn.Store}}else{const c=o.colorAttachments[0];e.clearColor?(c.clearValue=e.clearColorValue,c.loadOp=wt.Clear):c.loadOp=wt.Load,c.storeOp=Jn.Store}e.depth&&(e.clearDepth?(a.depthClearValue=e.clearDepthValue,a.depthLoadOp=wt.Clear):a.depthLoadOp=wt.Load,a.depthStoreOp=Jn.Store),e.stencil&&(e.clearStencil?(a.stencilClearValue=e.clearStencilValue,a.stencilLoadOp=wt.Clear):a.stencilLoadOp=wt.Load,a.stencilStoreOp=Jn.Store);const l=n.createCommandEncoder({label:"renderContext_"+e.id});if(this._isRenderCameraDepthArray(e)===!0){const c=e.camera.cameras;!t.layerDescriptors||t.layerDescriptors.length!==c.length?this._createDepthLayerDescriptors(e,t,o,c):this._updateDepthLayerDescriptors(e,t,c),t.bundleEncoders=[],t.bundleSets=[];for(let u=0;u<c.length;u++){const h=this.pipelineUtils.createBundleEncoder(e,"renderBundleArrayCamera_"+u),d={attributes:{},bindingGroups:[],pipeline:null,index:null};t.bundleEncoders.push(h),t.bundleSets.push(d)}t.currentPass=null}else{const c=l.beginRenderPass(o);t.currentPass=c,e.viewport&&this.updateViewport(e),e.scissor&&this.updateScissor(e)}t.descriptor=o,t.encoder=l,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.renderBundles=[]}_createDepthLayerDescriptors(e,t,n,i){const s=n.depthStencilAttachment;t.layerDescriptors=[];const o=this.get(e.depthTexture);o.viewCache||(o.viewCache=[]);for(let a=0;a<i.length;a++){const l={...n,colorAttachments:[{...n.colorAttachments[0],view:n.colorAttachments[a].view}]};if(n.depthStencilAttachment){const c=a;o.viewCache[c]||(o.viewCache[c]=o.texture.createView({dimension:Wn.TwoD,baseArrayLayer:a,arrayLayerCount:1})),l.depthStencilAttachment={view:o.viewCache[c],depthLoadOp:s.depthLoadOp||wt.Clear,depthStoreOp:s.depthStoreOp||Jn.Store,depthClearValue:s.depthClearValue||1},e.stencil&&(l.depthStencilAttachment.stencilLoadOp=s.stencilLoadOp,l.depthStencilAttachment.stencilStoreOp=s.stencilStoreOp,l.depthStencilAttachment.stencilClearValue=s.stencilClearValue)}else l.depthStencilAttachment={...s};t.layerDescriptors.push(l)}}_updateDepthLayerDescriptors(e,t,n){for(let i=0;i<n.length;i++){const s=t.layerDescriptors[i];if(s.depthStencilAttachment){const o=s.depthStencilAttachment;e.depth&&(e.clearDepth?(o.depthClearValue=e.clearDepthValue,o.depthLoadOp=wt.Clear):o.depthLoadOp=wt.Load),e.stencil&&(e.clearStencil?(o.stencilClearValue=e.clearStencilValue,o.stencilLoadOp=wt.Clear):o.stencilLoadOp=wt.Load)}}}finishRender(e){const t=this.get(e),n=e.occlusionQueryCount;t.renderBundles.length>0&&t.currentPass.executeBundles(t.renderBundles),n>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery();const i=t.encoder;if(this._isRenderCameraDepthArray(e)===!0){const s=[];for(let o=0;o<t.bundleEncoders.length;o++){const a=t.bundleEncoders[o];s.push(a.finish())}for(let o=0;o<t.layerDescriptors.length;o++)if(o<s.length){const a=t.layerDescriptors[o],l=i.beginRenderPass(a);if(e.viewport){const{x:c,y:u,width:h,height:d,minDepth:f,maxDepth:p}=e.viewportValue;l.setViewport(c,u,h,d,f,p)}if(e.scissor){const{x:c,y:u,width:h,height:d}=e.scissorValue;l.setScissorRect(c,u,h,d)}l.executeBundles([s[o]]),l.end()}}else t.currentPass&&t.currentPass.end();if(n>0){const s=n*8;let o=this.occludedResolveCache.get(s);o===void 0&&(o=this.device.createBuffer({size:s,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(s,o));const a=this.device.createBuffer({size:s,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,n,o,0),t.encoder.copyBufferToBuffer(o,0,a,0,s),t.occlusionQueryBuffer=a,this.resolveOccludedAsync(e)}if(this.device.queue.submit([t.encoder.finish()]),e.textures!==null){const s=e.textures;for(let o=0;o<s.length;o++){const a=s[o];a.generateMipmaps===!0&&this.textureUtils.generateMipmaps(a)}}}isOccluded(e,t){const n=this.get(e);return n.occluded&&n.occluded.has(t)}async resolveOccludedAsync(e){const t=this.get(e),{currentOcclusionQueryBuffer:n,currentOcclusionQueryObjects:i}=t;if(n&&i){const s=new WeakSet;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueryBuffer=null,await n.mapAsync(GPUMapMode.READ);const o=n.getMappedRange(),a=new BigUint64Array(o);for(let l=0;l<i.length;l++)a[l]===BigInt(0)&&s.add(i[l]);n.destroy(),t.occluded=s}}updateViewport(e){const{currentPass:t}=this.get(e),{x:n,y:i,width:s,height:o,minDepth:a,maxDepth:l}=e.viewportValue;t.setViewport(n,i,s,o,a,l)}updateScissor(e){const{currentPass:t}=this.get(e),{x:n,y:i,width:s,height:o}=e.scissorValue;t.setScissorRect(n,i,s,o)}getClearColor(){const e=super.getClearColor();return this.renderer.alpha===!0&&(e.r*=e.a,e.g*=e.a,e.b*=e.a),e}clear(e,t,n,i=null){const s=this.device,o=this.renderer;let a=[],l,c,u;if(e){const f=this.getClearColor();Xi.r=f.r,Xi.g=f.g,Xi.b=f.b,Xi.a=f.a}if(i===null){c=o.depth,u=o.stencil;const f=this._getDefaultRenderPassDescriptor();if(e){a=f.colorAttachments;const p=a[0];p.clearValue=Xi,p.loadOp=wt.Clear,p.storeOp=Jn.Store}(c||u)&&(l=f.depthStencilAttachment)}else{c=i.depth,u=i.stencil;const f={loadOp:e?wt.Clear:wt.Load,clearValue:e?Xi:void 0};c&&(f.depthLoadOp=t?wt.Clear:wt.Load,f.depthClearValue=t?o.getClearDepth():void 0,f.depthStoreOp=Jn.Store),u&&(f.stencilLoadOp=n?wt.Clear:wt.Load,f.stencilClearValue=n?o.getClearStencil():void 0,f.stencilStoreOp=Jn.Store);const p=this._getRenderPassDescriptor(i,f);a=p.colorAttachments,l=p.depthStencilAttachment}c&&l&&(t?(l.depthLoadOp=wt.Clear,l.depthClearValue=o.getClearDepth(),l.depthStoreOp=Jn.Store):(l.depthLoadOp=wt.Load,l.depthStoreOp=Jn.Store)),u&&l&&(n?(l.stencilLoadOp=wt.Clear,l.stencilClearValue=o.getClearStencil(),l.stencilStoreOp=Jn.Store):(l.stencilLoadOp=wt.Load,l.stencilStoreOp=Jn.Store));const h=s.createCommandEncoder({label:"clear"});h.beginRenderPass({colorAttachments:a,depthStencilAttachment:l}).end(),s.queue.submit([h.finish()])}beginCompute(e){const t=this.get(e),n={label:"computeGroup_"+e.id};this.initTimestampQuery(xr.COMPUTE,this.getTimestampUID(e),n),t.cmdEncoderGPU=this.device.createCommandEncoder({label:"computeGroup_"+e.id}),t.passEncoderGPU=t.cmdEncoderGPU.beginComputePass(n)}compute(e,t,n,i,s=null){const o=this.get(t),{passEncoderGPU:a}=this.get(e),l=this.get(i).pipeline;this.pipelineUtils.setPipeline(a,l);for(let c=0,u=n.length;c<u;c++){const h=n[c],d=this.get(h);a.setBindGroup(c,d.group)}if(s===null&&(s=t.dispatchSize||t.count),s&&s.isIndirectStorageBufferAttribute){const c=this.get(s).buffer;a.dispatchWorkgroupsIndirect(c,0);return}if(typeof s=="number"){const c=s;if(o.dispatchSize===void 0||o.count!==c){o.dispatchSize=[0,1,1],o.count=c;const u=t.workgroupSize;let h=u[0];for(let p=1;p<u.length;p++)h*=u[p];const d=Math.ceil(c/h),f=this.device.limits.maxComputeWorkgroupsPerDimension;s=[d,1,1],d>f&&(s[0]=Math.min(d,f),s[1]=Math.ceil(d/f)),o.dispatchSize=s}s=o.dispatchSize}a.dispatchWorkgroups(s[0],s[1]||1,s[2]||1)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.device.queue.submit([t.cmdEncoderGPU.finish()])}_draw(e,t,n,i,s,o,a,l,c){const{object:u,material:h,context:d}=e,f=e.getIndex(),p=f!==null;this.pipelineUtils.setPipeline(l,i),c.pipeline=i;const g=c.bindingGroups;for(let m=0,_=s.length;m<_;m++){const x=s[m],y=this.get(x);g[m]!==x.id&&(l.setBindGroup(m,y.group),g[m]=x.id)}if(p===!0&&c.index!==f){const m=this.get(f).buffer,_=f.array instanceof Uint16Array?Ph.Uint16:Ph.Uint32;l.setIndexBuffer(m,_),c.index=f}for(let m=0,_=o.length;m<_;m++){const x=o[m];if(c.attributes[m]!==x){const y=this.get(x).buffer;l.setVertexBuffer(m,y),c.attributes[m]=x}}if(d.stencil===!0&&h.stencilWrite===!0&&n.currentStencilRef!==h.stencilRef&&(l.setStencilReference(h.stencilRef),n.currentStencilRef=h.stencilRef),u.isBatchedMesh===!0){const m=u._multiDrawStarts,_=u._multiDrawCounts,x=u._multiDrawCount;let y=p===!0?f.array.BYTES_PER_ELEMENT:1;h.wireframe&&(y=u.geometry.attributes.position.count>65535?4:2);for(let b=0;b<x;b++)p===!0?l.drawIndexed(_[b],1,m[b]/y,0,b):l.draw(_[b],1,m[b],b),t.update(u,_[b],1)}else if(p===!0){const{vertexCount:m,instanceCount:_,firstVertex:x}=a,y=e.getIndirect();if(y!==null){const b=this.get(y).buffer,M=e.getIndirectOffset(),S=Array.isArray(M)?M:[M];for(let E=0;E<S.length;E++)l.drawIndexedIndirect(b,S[E])}else l.drawIndexed(m,_,x,0,0);t.update(u,m,_)}else{const{vertexCount:m,instanceCount:_,firstVertex:x}=a,y=e.getIndirect();if(y!==null){const b=this.get(y).buffer,M=e.getIndirectOffset(),S=Array.isArray(M)?M:[M];for(let E=0;E<S.length;E++)l.drawIndirect(b,S[E])}else l.draw(m,_,x,0);t.update(u,m,_)}}draw(e,t){const{object:n,context:i,pipeline:s}=e,o=this.get(i),a=this.get(s),l=a.pipeline;if(a.error===!0)return;const c=e.getDrawParameters();if(c===null)return;const u=e.getBindings(),h=e.getVertexBuffers();if(e.camera.isArrayCamera&&e.camera.cameras.length>0){const d=this.get(e.camera),f=e.camera.cameras,p=e.getBindingGroup("cameraIndex");if(d.indexesGPU===void 0||d.indexesGPU.length!==f.length){const m=this.get(p),_=[],x=new Uint32Array([0,0,0,0]);for(let y=0,b=f.length;y<b;y++){x[0]=y;const{layoutGPU:M}=m.layout,S=this.bindingUtils.createBindGroupIndex(x,M);_.push(S)}d.indexesGPU=_}const g=this.renderer.getPixelRatio();for(let m=0,_=f.length;m<_;m++){const x=f[m];if(n.layers.test(x.layers)){const y=x.viewport;let b=o.currentPass,M=o.currentSets;if(o.bundleEncoders){const S=o.bundleEncoders[m],E=o.bundleSets[m];b=S,M=E}if(y&&b.setViewport(Math.floor(y.x*g),Math.floor(y.y*g),Math.floor(y.width*g),Math.floor(y.height*g),i.viewportValue.minDepth,i.viewportValue.maxDepth),p&&d.indexesGPU){const S=u.indexOf(p);b.setBindGroup(S,d.indexesGPU[m]),M.bindingGroups[S]=p.id}this._draw(e,t,o,l,u,h,c,b,M)}}}else if(o.currentPass){if(o.occlusionQuerySet!==void 0){const d=o.lastOcclusionObject;d!==n&&(d!==null&&d.occlusionTest===!0&&(o.currentPass.endOcclusionQuery(),o.occlusionQueryIndex++),n.occlusionTest===!0&&(o.currentPass.beginOcclusionQuery(o.occlusionQueryIndex),o.occlusionQueryObjects[o.occlusionQueryIndex]=n),o.lastOcclusionObject=n)}this._draw(e,t,o,l,u,h,c,o.currentPass,o.currentSets)}}needsRenderUpdate(e){const t=this.get(e),{object:n,material:i}=e,s=this.utils,o=s.getSampleCountRenderContext(e.context),a=s.getCurrentColorSpace(e.context),l=s.getCurrentColorFormat(e.context),c=s.getCurrentDepthStencilFormat(e.context),u=s.getPrimitiveTopology(n,i);let h=!1;return(t.material!==i||t.materialVersion!==i.version||t.transparent!==i.transparent||t.blending!==i.blending||t.premultipliedAlpha!==i.premultipliedAlpha||t.blendSrc!==i.blendSrc||t.blendDst!==i.blendDst||t.blendEquation!==i.blendEquation||t.blendSrcAlpha!==i.blendSrcAlpha||t.blendDstAlpha!==i.blendDstAlpha||t.blendEquationAlpha!==i.blendEquationAlpha||t.colorWrite!==i.colorWrite||t.depthWrite!==i.depthWrite||t.depthTest!==i.depthTest||t.depthFunc!==i.depthFunc||t.stencilWrite!==i.stencilWrite||t.stencilFunc!==i.stencilFunc||t.stencilFail!==i.stencilFail||t.stencilZFail!==i.stencilZFail||t.stencilZPass!==i.stencilZPass||t.stencilFuncMask!==i.stencilFuncMask||t.stencilWriteMask!==i.stencilWriteMask||t.side!==i.side||t.alphaToCoverage!==i.alphaToCoverage||t.sampleCount!==o||t.colorSpace!==a||t.colorFormat!==l||t.depthStencilFormat!==c||t.primitiveTopology!==u||t.clippingContextCacheKey!==e.clippingContextCacheKey)&&(t.material=i,t.materialVersion=i.version,t.transparent=i.transparent,t.blending=i.blending,t.premultipliedAlpha=i.premultipliedAlpha,t.blendSrc=i.blendSrc,t.blendDst=i.blendDst,t.blendEquation=i.blendEquation,t.blendSrcAlpha=i.blendSrcAlpha,t.blendDstAlpha=i.blendDstAlpha,t.blendEquationAlpha=i.blendEquationAlpha,t.colorWrite=i.colorWrite,t.depthWrite=i.depthWrite,t.depthTest=i.depthTest,t.depthFunc=i.depthFunc,t.stencilWrite=i.stencilWrite,t.stencilFunc=i.stencilFunc,t.stencilFail=i.stencilFail,t.stencilZFail=i.stencilZFail,t.stencilZPass=i.stencilZPass,t.stencilFuncMask=i.stencilFuncMask,t.stencilWriteMask=i.stencilWriteMask,t.side=i.side,t.alphaToCoverage=i.alphaToCoverage,t.sampleCount=o,t.colorSpace=a,t.colorFormat=l,t.depthStencilFormat=c,t.primitiveTopology=u,t.clippingContextCacheKey=e.clippingContextCacheKey,h=!0),h}getRenderCacheKey(e){const{object:t,material:n}=e,i=this.utils,s=e.context,o=t.isMesh&&t.matrixWorld.determinant()<0;return[n.transparent,n.blending,n.premultipliedAlpha,n.blendSrc,n.blendDst,n.blendEquation,n.blendSrcAlpha,n.blendDstAlpha,n.blendEquationAlpha,n.colorWrite,n.depthWrite,n.depthTest,n.depthFunc,n.stencilWrite,n.stencilFunc,n.stencilFail,n.stencilZFail,n.stencilZPass,n.stencilFuncMask,n.stencilWriteMask,n.side,o,i.getSampleCountRenderContext(s),i.getCurrentColorSpace(s),i.getCurrentColorFormat(s),i.getCurrentDepthStencilFormat(s),i.getPrimitiveTopology(t,n),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}updateSampler(e){return this.textureUtils.updateSampler(e)}createDefaultTexture(e){return this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e,t=!1){this.textureUtils.destroyTexture(e,t)}async copyTextureToBuffer(e,t,n,i,s,o){return this.textureUtils.copyTextureToBuffer(e,t,n,i,s,o)}initTimestampQuery(e,t,n){if(!this.trackTimestamp)return;this.timestampQueryPool[e]||(this.timestampQueryPool[e]=new s3(this.device,e,2048));const i=this.timestampQueryPool[e],s=i.allocateQueriesForContext(t);n.timestampWrites={querySet:i.querySet,beginningOfPassWriteIndex:s,endOfPassWriteIndex:s+1}}createNodeBuilder(e,t){return new KB(e,t)}createProgram(e){const t=this.get(e);t.module={module:this.device.createShaderModule({code:e.code,label:e.stage+(e.name!==""?`_${e.name}`:"")}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const n=this.get(e),s=n.currentPass.finish();this.get(t).bundleGPU=s,n.currentSets=n._currentSets,n.currentPass=n._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,n,i){this.bindingUtils.createBindings(e,t,n,i)}updateBindings(e,t,n,i){this.bindingUtils.createBindings(e,t,n,i)}updateBinding(e){this.bindingUtils.updateBinding(e)}deleteBindGroupData(e){this.bindingUtils.deleteBindGroupData(e)}createIndexAttribute(e){let t=GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST;(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(t|=GPUBufferUsage.STORAGE),this.attributeUtils.createAttribute(e,t)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.delete(this.renderer.getCanvasTarget())}hasFeature(e){return b0[e]!==void 0&&(e=b0[e]),this.device.features.has(e)}copyTextureToTexture(e,t,n=null,i=null,s=0,o=0){let a=0,l=0,c=0,u=0,h=0,d=0,f=e.image.width,p=e.image.height,g=1;n!==null&&(n.isBox3===!0?(u=n.min.x,h=n.min.y,d=n.min.z,f=n.max.x-n.min.x,p=n.max.y-n.min.y,g=n.max.z-n.min.z):(u=n.min.x,h=n.min.y,f=n.max.x-n.min.x,p=n.max.y-n.min.y,g=1)),i!==null&&(a=i.x,l=i.y,c=i.z||0);const m=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),_=this.get(e).texture,x=this.get(t).texture;m.copyTextureToTexture({texture:_,mipLevel:s,origin:{x:u,y:h,z:d}},{texture:x,mipLevel:o,origin:{x:a,y:l,z:c}},[f,p,g]),this.device.queue.submit([m.finish()]),o===0&&t.generateMipmaps&&this.textureUtils.generateMipmaps(t)}copyFramebufferToTexture(e,t,n){const i=this.get(t);let s=null;t.renderTarget?e.isDepthTexture?s=this.get(t.depthTexture).texture:s=this.get(t.textures[0]).texture:e.isDepthTexture?s=this.textureUtils.getDepthBuffer(t.depth,t.stencil):s=this.context.getCurrentTexture();const o=this.get(e).texture;if(s.format!==o.format){ce("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",s.format,o.format);return}let a;if(i.currentPass?(i.currentPass.end(),a=i.encoder):a=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),a.copyTextureToTexture({texture:s,origin:[n.x,n.y,0]},{texture:o},[n.z,n.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e,a),i.currentPass){const{descriptor:l}=i;for(let c=0;c<l.colorAttachments.length;c++)l.colorAttachments[c].loadOp=wt.Load;t.depth&&(l.depthStencilAttachment.depthLoadOp=wt.Load),t.stencil&&(l.depthStencilAttachment.stencilLoadOp=wt.Load),i.currentPass=a.beginRenderPass(l),i.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.viewport&&this.updateViewport(t),t.scissor&&this.updateScissor(t)}else this.device.queue.submit([a.finish()])}hasCompatibility(e){return this._compatibility[e]!==void 0?this._compatibility[e]:super.hasCompatibility(e)}dispose(){if(this.bindingUtils.dispose(),this.textureUtils.dispose(),this.occludedResolveCache){for(const e of this.occludedResolveCache.values())e.destroy();this.occludedResolveCache.clear()}if(this.timestampQueryPool)for(const e of Object.values(this.timestampQueryPool))e!==null&&e.dispose();this.parameters.device===void 0&&this.device!==null&&this.device.destroy()}}class a3 extends Mm{constructor(e,t,n,i,s,o){super(e,t,n,i,s,o),this.iesMap=null}copy(e,t){return super.copy(e,t),this.iesMap=e.iesMap,this}}class l3 extends Mm{constructor(e,t,n,i,s,o){super(e,t,n,i,s,o),this.aspect=null}copy(e,t){return super.copy(e,t),this.aspect=e.aspect,this}}class c3 extends Ub{constructor(){super(),this.addMaterial(vU,"MeshPhongMaterial"),this.addMaterial(pb,"MeshStandardMaterial"),this.addMaterial(_F,"MeshPhysicalMaterial"),this.addMaterial(bF,"MeshToonMaterial"),this.addMaterial(fU,"MeshBasicMaterial"),this.addMaterial(xU,"MeshLambertMaterial"),this.addMaterial(lU,"MeshNormalMaterial"),this.addMaterial(MF,"MeshMatcapMaterial"),this.addMaterial(rU,"LineBasicMaterial"),this.addMaterial(oU,"LineDashedMaterial"),this.addMaterial(CF,"PointsMaterial"),this.addMaterial(gb,"SpriteMaterial"),this.addMaterial(LF,"ShadowMaterial"),this.addLight(l2,MM),this.addLight(O2,dy),this.addLight(W2,AM),this.addLight(Qm,Mm),this.addLight(B2,fy),this.addLight(k2,bM),this.addLight(V2,RM),this.addLight(G2,a3),this.addLight(H2,l3),this.addToneMapping(fI,qp),this.addToneMapping(pI,jp),this.addToneMapping(mI,Yp),this.addToneMapping(_I,Kp),this.addToneMapping(bI,Zp),this.addToneMapping(SI,Qp)}}class u3 extends hB{constructor(e={}){let t;e.forceWebGL?t=m0:(t=o3,e.getFallback=()=>(ae("WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new m0(e)));const n=new t(e);super(n,e),this.library=new c3,this.isWebGPURenderer=!0,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}}const $f={type:"change"},eg={type:"start"},tg={type:"end"},A0=1e-6,Rt={NONE:-1,ROTATE:0,ZOOM:1,PAN:2,TOUCH_ROTATE:3,TOUCH_ZOOM_PAN:4},eh=new pe,ps=new pe,h3=new P,th=new P,Xf=new P,la=new Oi,w0=new P,nh=new P,qf=new P,ih=new P;class d3 extends kh{constructor(e,t=null){super(e,t),this.screen={left:0,top:0,width:0,height:0},this.rotateSpeed=1,this.zoomSpeed=1.2,this.panSpeed=.3,this.noRotate=!1,this.noZoom=!1,this.noPan=!1,this.staticMoving=!1,this.dynamicDampingFactor=.2,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.keys=["KeyA","KeyS","KeyD"],this.mouseButtons={LEFT:Un.ROTATE,MIDDLE:Un.DOLLY,RIGHT:Un.PAN},this.target=new P,this.state=Rt.NONE,this.keyState=Rt.NONE,this._lastPosition=new P,this._lastZoom=1,this._touchZoomDistanceStart=0,this._touchZoomDistanceEnd=0,this._lastAngle=0,this._eye=new P,this._movePrev=new pe,this._moveCurr=new pe,this._lastAxis=new P,this._zoomStart=new pe,this._zoomEnd=new pe,this._panStart=new pe,this._panEnd=new pe,this._pointers=[],this._pointerPositions={},this._onPointerMove=p3.bind(this),this._onPointerDown=f3.bind(this),this._onPointerUp=m3.bind(this),this._onPointerCancel=g3.bind(this),this._onContextMenu=T3.bind(this),this._onMouseWheel=S3.bind(this),this._onKeyDown=x3.bind(this),this._onKeyUp=_3.bind(this),this._onTouchStart=M3.bind(this),this._onTouchMove=E3.bind(this),this._onTouchEnd=A3.bind(this),this._onMouseDown=y3.bind(this),this._onMouseMove=v3.bind(this),this._onMouseUp=b3.bind(this),this._target0=this.target.clone(),this._position0=this.object.position.clone(),this._up0=this.object.up.clone(),this._zoom0=this.object.zoom,t!==null&&(this.connect(t),this.handleResize()),this.update()}connect(e){super.connect(e),window.addEventListener("keydown",this._onKeyDown),window.addEventListener("keyup",this._onKeyUp),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerCancel),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="none"}disconnect(){window.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("keyup",this._onKeyUp),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerCancel),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction=""}dispose(){this.disconnect()}handleResize(){const e=this.domElement.getBoundingClientRect(),t=this.domElement.ownerDocument.documentElement;this.screen.left=e.left+window.pageXOffset-t.clientLeft,this.screen.top=e.top+window.pageYOffset-t.clientTop,this.screen.width=e.width,this.screen.height=e.height}update(){this._eye.subVectors(this.object.position,this.target),this.noRotate||this._rotateCamera(),this.noZoom||this._zoomCamera(),this.noPan||this._panCamera(),this.object.position.addVectors(this.target,this._eye),this.object.isPerspectiveCamera?(this._checkDistances(),this.object.lookAt(this.target),this._lastPosition.distanceToSquared(this.object.position)>A0&&(this.dispatchEvent($f),this._lastPosition.copy(this.object.position))):this.object.isOrthographicCamera?(this.object.lookAt(this.target),(this._lastPosition.distanceToSquared(this.object.position)>A0||this._lastZoom!==this.object.zoom)&&(this.dispatchEvent($f),this._lastPosition.copy(this.object.position),this._lastZoom=this.object.zoom)):console.warn("THREE.TrackballControls: Unsupported camera type.")}reset(){this.state=Rt.NONE,this.keyState=Rt.NONE,this.target.copy(this._target0),this.object.position.copy(this._position0),this.object.up.copy(this._up0),this.object.zoom=this._zoom0,this.object.updateProjectionMatrix(),this._eye.subVectors(this.object.position,this.target),this.object.lookAt(this.target),this.dispatchEvent($f),this._lastPosition.copy(this.object.position),this._lastZoom=this.object.zoom}_panCamera(){if(ps.copy(this._panEnd).sub(this._panStart),ps.lengthSq()){if(this.object.isOrthographicCamera){const e=(this.object.right-this.object.left)/this.object.zoom/this.domElement.clientWidth,t=(this.object.top-this.object.bottom)/this.object.zoom/this.domElement.clientWidth;ps.x*=e,ps.y*=t}ps.multiplyScalar(this._eye.length()*this.panSpeed),th.copy(this._eye).cross(this.object.up).setLength(ps.x),th.add(h3.copy(this.object.up).setLength(ps.y)),this.object.position.add(th),this.target.add(th),this.staticMoving?this._panStart.copy(this._panEnd):this._panStart.add(ps.subVectors(this._panEnd,this._panStart).multiplyScalar(this.dynamicDampingFactor))}}_rotateCamera(){ih.set(this._moveCurr.x-this._movePrev.x,this._moveCurr.y-this._movePrev.y,0);let e=ih.length();e?(this._eye.copy(this.object.position).sub(this.target),w0.copy(this._eye).normalize(),nh.copy(this.object.up).normalize(),qf.crossVectors(nh,w0).normalize(),nh.setLength(this._moveCurr.y-this._movePrev.y),qf.setLength(this._moveCurr.x-this._movePrev.x),ih.copy(nh.add(qf)),Xf.crossVectors(ih,this._eye).normalize(),e*=this.rotateSpeed,la.setFromAxisAngle(Xf,e),this._eye.applyQuaternion(la),this.object.up.applyQuaternion(la),this._lastAxis.copy(Xf),this._lastAngle=e):!this.staticMoving&&this._lastAngle&&(this._lastAngle*=Math.sqrt(1-this.dynamicDampingFactor),this._eye.copy(this.object.position).sub(this.target),la.setFromAxisAngle(this._lastAxis,this._lastAngle),this._eye.applyQuaternion(la),this.object.up.applyQuaternion(la)),this._movePrev.copy(this._moveCurr)}_zoomCamera(){let e;this.state===Rt.TOUCH_ZOOM_PAN?(e=this._touchZoomDistanceStart/this._touchZoomDistanceEnd,this._touchZoomDistanceStart=this._touchZoomDistanceEnd,this.object.isPerspectiveCamera?this._eye.multiplyScalar(e):this.object.isOrthographicCamera?(this.object.zoom=_h.clamp(this.object.zoom/e,this.minZoom,this.maxZoom),this._lastZoom!==this.object.zoom&&this.object.updateProjectionMatrix()):console.warn("THREE.TrackballControls: Unsupported camera type")):(e=1+(this._zoomEnd.y-this._zoomStart.y)*this.zoomSpeed,e!==1&&e>0&&(this.object.isPerspectiveCamera?this._eye.multiplyScalar(e):this.object.isOrthographicCamera?(this.object.zoom=_h.clamp(this.object.zoom/e,this.minZoom,this.maxZoom),this._lastZoom!==this.object.zoom&&this.object.updateProjectionMatrix()):console.warn("THREE.TrackballControls: Unsupported camera type")),this.staticMoving?this._zoomStart.copy(this._zoomEnd):this._zoomStart.y+=(this._zoomEnd.y-this._zoomStart.y)*this.dynamicDampingFactor)}_getMouseOnScreen(e,t){return eh.set((e-this.screen.left)/this.screen.width,(t-this.screen.top)/this.screen.height),eh}_getMouseOnCircle(e,t){return eh.set((e-this.screen.width*.5-this.screen.left)/(this.screen.width*.5),(this.screen.height+2*(this.screen.top-t))/this.screen.width),eh}_addPointer(e){this._pointers.push(e)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t].pointerId==e.pointerId){this._pointers.splice(t,1);return}}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new pe,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0].pointerId?this._pointers[1]:this._pointers[0];return this._pointerPositions[t.pointerId]}_checkDistances(){(!this.noZoom||!this.noPan)&&(this._eye.lengthSq()>this.maxDistance*this.maxDistance&&(this.object.position.addVectors(this.target,this._eye.setLength(this.maxDistance)),this._zoomStart.copy(this._zoomEnd)),this._eye.lengthSq()<this.minDistance*this.minDistance&&(this.object.position.addVectors(this.target,this._eye.setLength(this.minDistance)),this._zoomStart.copy(this._zoomEnd)))}}function f3(r){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(r.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),this._addPointer(r),r.pointerType==="touch"?this._onTouchStart(r):this._onMouseDown(r))}function p3(r){this.enabled!==!1&&(r.pointerType==="touch"?this._onTouchMove(r):this._onMouseMove(r))}function m3(r){this.enabled!==!1&&(r.pointerType==="touch"?this._onTouchEnd(r):this._onMouseUp(),this._removePointer(r),this._pointers.length===0&&(this.domElement.releasePointerCapture(r.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp)))}function g3(r){this._removePointer(r)}function _3(){this.enabled!==!1&&(this.keyState=Rt.NONE,window.addEventListener("keydown",this._onKeyDown))}function x3(r){this.enabled!==!1&&(window.removeEventListener("keydown",this._onKeyDown),this.keyState===Rt.NONE&&(r.code===this.keys[Rt.ROTATE]&&!this.noRotate?this.keyState=Rt.ROTATE:r.code===this.keys[Rt.ZOOM]&&!this.noZoom?this.keyState=Rt.ZOOM:r.code===this.keys[Rt.PAN]&&!this.noPan&&(this.keyState=Rt.PAN)))}function y3(r){let e;switch(r.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case Un.DOLLY:this.state=Rt.ZOOM;break;case Un.ROTATE:this.state=Rt.ROTATE;break;case Un.PAN:this.state=Rt.PAN;break;default:this.state=Rt.NONE}const t=this.keyState!==Rt.NONE?this.keyState:this.state;t===Rt.ROTATE&&!this.noRotate?(this._moveCurr.copy(this._getMouseOnCircle(r.pageX,r.pageY)),this._movePrev.copy(this._moveCurr)):t===Rt.ZOOM&&!this.noZoom?(this._zoomStart.copy(this._getMouseOnScreen(r.pageX,r.pageY)),this._zoomEnd.copy(this._zoomStart)):t===Rt.PAN&&!this.noPan&&(this._panStart.copy(this._getMouseOnScreen(r.pageX,r.pageY)),this._panEnd.copy(this._panStart)),this.dispatchEvent(eg)}function v3(r){const e=this.keyState!==Rt.NONE?this.keyState:this.state;e===Rt.ROTATE&&!this.noRotate?(this._movePrev.copy(this._moveCurr),this._moveCurr.copy(this._getMouseOnCircle(r.pageX,r.pageY))):e===Rt.ZOOM&&!this.noZoom?this._zoomEnd.copy(this._getMouseOnScreen(r.pageX,r.pageY)):e===Rt.PAN&&!this.noPan&&this._panEnd.copy(this._getMouseOnScreen(r.pageX,r.pageY))}function b3(){this.state=Rt.NONE,this.dispatchEvent(tg)}function S3(r){if(this.enabled!==!1&&this.noZoom!==!0){switch(r.preventDefault(),r.deltaMode){case 2:this._zoomStart.y-=r.deltaY*.025;break;case 1:this._zoomStart.y-=r.deltaY*.01;break;default:this._zoomStart.y-=r.deltaY*25e-5;break}this.dispatchEvent(eg),this.dispatchEvent(tg)}}function T3(r){this.enabled!==!1&&r.preventDefault()}function M3(r){switch(this._trackPointer(r),this._pointers.length){case 1:this.state=Rt.TOUCH_ROTATE,this._moveCurr.copy(this._getMouseOnCircle(this._pointers[0].pageX,this._pointers[0].pageY)),this._movePrev.copy(this._moveCurr);break;default:this.state=Rt.TOUCH_ZOOM_PAN;const e=this._pointers[0].pageX-this._pointers[1].pageX,t=this._pointers[0].pageY-this._pointers[1].pageY;this._touchZoomDistanceEnd=this._touchZoomDistanceStart=Math.sqrt(e*e+t*t);const n=(this._pointers[0].pageX+this._pointers[1].pageX)/2,i=(this._pointers[0].pageY+this._pointers[1].pageY)/2;this._panStart.copy(this._getMouseOnScreen(n,i)),this._panEnd.copy(this._panStart);break}this.dispatchEvent(eg)}function E3(r){switch(this._trackPointer(r),this._pointers.length){case 1:this._movePrev.copy(this._moveCurr),this._moveCurr.copy(this._getMouseOnCircle(r.pageX,r.pageY));break;default:const e=this._getSecondPointerPosition(r),t=r.pageX-e.x,n=r.pageY-e.y;this._touchZoomDistanceEnd=Math.sqrt(t*t+n*n);const i=(r.pageX+e.x)/2,s=(r.pageY+e.y)/2;this._panEnd.copy(this._getMouseOnScreen(i,s));break}}function A3(r){switch(this._pointers.length){case 0:this.state=Rt.NONE;break;case 1:this.state=Rt.TOUCH_ROTATE,this._moveCurr.copy(this._getMouseOnCircle(r.pageX,r.pageY)),this._movePrev.copy(this._moveCurr);break;case 2:this.state=Rt.TOUCH_ZOOM_PAN;for(let e=0;e<this._pointers.length;e++)if(this._pointers[e].pointerId!==r.pointerId){const t=this._pointerPositions[this._pointers[e].pointerId];this._moveCurr.copy(this._getMouseOnCircle(t.x,t.y)),this._movePrev.copy(this._moveCurr);break}break}this.dispatchEvent(tg)}const R0={type:"change"},ng={type:"start"},Xb={type:"end"},rh=new Bh,C0=new ur,w3=Math.cos(70*_h.DEG2RAD),bn=new P,si=2*Math.PI,Gt={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},jf=1e-6;class R3 extends kh{constructor(e,t=null){super(e,t),this.state=Gt.NONE,this.target=new P,this.cursor=new P,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:Un.ROTATE,MIDDLE:Un.DOLLY,RIGHT:Un.PAN},this.touches={ONE:$r.ROTATE,TWO:$r.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle="auto",this._domElementKeyEvents=null,this._lastPosition=new P,this._lastQuaternion=new Oi,this._lastTargetPosition=new P,this._quat=new Oi().setFromUnitVectors(e.up,new P(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new Qg,this._sphericalDelta=new Qg,this._scale=1,this._panOffset=new P,this._rotateStart=new pe,this._rotateEnd=new pe,this._rotateDelta=new pe,this._panStart=new pe,this._panEnd=new pe,this._panDelta=new pe,this._dollyStart=new pe,this._dollyEnd=new pe,this._dollyDelta=new pe,this._dollyDirection=new P,this._mouse=new pe,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=N3.bind(this),this._onPointerDown=C3.bind(this),this._onPointerUp=P3.bind(this),this._onContextMenu=O3.bind(this),this._onMouseWheel=U3.bind(this),this._onKeyDown=F3.bind(this),this._onTouchStart=I3.bind(this),this._onTouchMove=B3.bind(this),this._onMouseDown=D3.bind(this),this._onMouseMove=L3.bind(this),this._interceptControlDown=k3.bind(this),this._interceptControlUp=G3.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}set cursorStyle(e){this._cursorStyle=e,e==="grab"?this.domElement.style.cursor="grab":this.domElement.style.cursor="auto"}get cursorStyle(){return this._cursorStyle}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction=""}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(R0),this.update(),this.state=Gt.NONE}pan(e,t){this._pan(e,t),this.update()}dollyIn(e){this._dollyIn(e),this.update()}dollyOut(e){this._dollyOut(e),this.update()}rotateLeft(e){this._rotateLeft(e),this.update()}rotateUp(e){this._rotateUp(e),this.update()}update(e=null){const t=this.object.position;bn.copy(t).sub(this.target),bn.applyQuaternion(this._quat),this._spherical.setFromVector3(bn),this.autoRotate&&this.state===Gt.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let n=this.minAzimuthAngle,i=this.maxAzimuthAngle;isFinite(n)&&isFinite(i)&&(n<-Math.PI?n+=si:n>Math.PI&&(n-=si),i<-Math.PI?i+=si:i>Math.PI&&(i-=si),n<=i?this._spherical.theta=Math.max(n,Math.min(i,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+i)/2?Math.max(n,this._spherical.theta):Math.min(i,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let s=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const o=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),s=o!=this._spherical.radius}if(bn.setFromSpherical(this._spherical),bn.applyQuaternion(this._quatInverse),t.copy(this.target).add(bn),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let o=null;if(this.object.isPerspectiveCamera){const a=bn.length();o=this._clampDistance(a*this._scale);const l=a-o;this.object.position.addScaledVector(this._dollyDirection,l),this.object.updateMatrixWorld(),s=!!l}else if(this.object.isOrthographicCamera){const a=new P(this._mouse.x,this._mouse.y,0);a.unproject(this.object);const l=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),s=l!==this.object.zoom;const c=new P(this._mouse.x,this._mouse.y,0);c.unproject(this.object),this.object.position.sub(c).add(a),this.object.updateMatrixWorld(),o=bn.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;o!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(o).add(this.object.position):(rh.origin.copy(this.object.position),rh.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(rh.direction))<w3?this.object.lookAt(this.target):(C0.setFromNormalAndCoplanarPoint(this.object.up,this.target),rh.intersectPlane(C0,this.target))))}else if(this.object.isOrthographicCamera){const o=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),o!==this.object.zoom&&(this.object.updateProjectionMatrix(),s=!0)}return this._scale=1,this._performCursorZoom=!1,s||this._lastPosition.distanceToSquared(this.object.position)>jf||8*(1-this._lastQuaternion.dot(this.object.quaternion))>jf||this._lastTargetPosition.distanceToSquared(this.target)>jf?(this.dispatchEvent(R0),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?si/60*this.autoRotateSpeed*e:si/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){bn.setFromMatrixColumn(t,0),bn.multiplyScalar(-e),this._panOffset.add(bn)}_panUp(e,t){this.screenSpacePanning===!0?bn.setFromMatrixColumn(t,1):(bn.setFromMatrixColumn(t,0),bn.crossVectors(this.object.up,bn)),bn.multiplyScalar(e),this._panOffset.add(bn)}_pan(e,t){const n=this.domElement;if(this.object.isPerspectiveCamera){const i=this.object.position;bn.copy(i).sub(this.target);let s=bn.length();s*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*s/n.clientHeight,this.object.matrix),this._panUp(2*t*s/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const n=this.domElement.getBoundingClientRect(),i=e-n.left,s=t-n.top,o=n.width,a=n.height;this._mouse.x=i/o*2-1,this._mouse.y=-(s/a)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(si*this._rotateDelta.x/t.clientHeight),this._rotateUp(si*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(si*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-si*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(si*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-si*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._rotateStart.set(n,i)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._panStart.set(n,i)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,i=e.pageY-t.y,s=Math.sqrt(n*n+i*i);this._dollyStart.set(0,s)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const n=this._getSecondPointerPosition(e),i=.5*(e.pageX+n.x),s=.5*(e.pageY+n.y);this._rotateEnd.set(i,s)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(si*this._rotateDelta.x/t.clientHeight),this._rotateUp(si*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._panEnd.set(n,i)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,i=e.pageY-t.y,s=Math.sqrt(n*n+i*i);this._dollyEnd.set(0,s),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const o=(e.pageX+t.x)*.5,a=(e.pageY+t.y)*.5;this._updateZoomParameters(o,a)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new pe,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}}function C3(r){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(r.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(r)&&(this._addPointer(r),r.pointerType==="touch"?this._onTouchStart(r):this._onMouseDown(r),this._cursorStyle==="grab"&&(this.domElement.style.cursor="grabbing")))}function N3(r){this.enabled!==!1&&(r.pointerType==="touch"?this._onTouchMove(r):this._onMouseMove(r))}function P3(r){switch(this._removePointer(r),this._pointers.length){case 0:this.domElement.releasePointerCapture(r.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(Xb),this.state=Gt.NONE,this._cursorStyle==="grab"&&(this.domElement.style.cursor="grab");break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function D3(r){let e;switch(r.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case Un.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(r),this.state=Gt.DOLLY;break;case Un.ROTATE:if(r.ctrlKey||r.metaKey||r.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(r),this.state=Gt.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(r),this.state=Gt.ROTATE}break;case Un.PAN:if(r.ctrlKey||r.metaKey||r.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(r),this.state=Gt.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(r),this.state=Gt.PAN}break;default:this.state=Gt.NONE}this.state!==Gt.NONE&&this.dispatchEvent(ng)}function L3(r){switch(this.state){case Gt.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(r);break;case Gt.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(r);break;case Gt.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(r);break}}function U3(r){this.enabled===!1||this.enableZoom===!1||this.state!==Gt.NONE||(r.preventDefault(),this.dispatchEvent(ng),this._handleMouseWheel(this._customWheelEvent(r)),this.dispatchEvent(Xb))}function F3(r){this.enabled!==!1&&this._handleKeyDown(r)}function I3(r){switch(this._trackPointer(r),this._pointers.length){case 1:switch(this.touches.ONE){case $r.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(r),this.state=Gt.TOUCH_ROTATE;break;case $r.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(r),this.state=Gt.TOUCH_PAN;break;default:this.state=Gt.NONE}break;case 2:switch(this.touches.TWO){case $r.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(r),this.state=Gt.TOUCH_DOLLY_PAN;break;case $r.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(r),this.state=Gt.TOUCH_DOLLY_ROTATE;break;default:this.state=Gt.NONE}break;default:this.state=Gt.NONE}this.state!==Gt.NONE&&this.dispatchEvent(ng)}function B3(r){switch(this._trackPointer(r),this.state){case Gt.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(r),this.update();break;case Gt.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(r),this.update();break;case Gt.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(r),this.update();break;case Gt.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(r),this.update();break;default:this.state=Gt.NONE}}function O3(r){this.enabled!==!1&&r.preventDefault()}function k3(r){r.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function G3(r){r.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}const V3={type:"change"},N0=1e-6,P0=new Oi;class z3 extends kh{constructor(e,t=null){super(e,t),this.movementSpeed=1,this.rollSpeed=.005,this.dragToLook=!1,this.autoForward=!1,this._moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0},this._moveVector=new P(0,0,0),this._rotationVector=new P(0,0,0),this._lastQuaternion=new Oi,this._lastPosition=new P,this._status=0,this._onKeyDown=H3.bind(this),this._onKeyUp=W3.bind(this),this._onPointerMove=X3.bind(this),this._onPointerDown=$3.bind(this),this._onPointerUp=q3.bind(this),this._onPointerCancel=j3.bind(this),this._onContextMenu=Y3.bind(this),t!==null&&this.connect(t)}connect(e){super.connect(e),window.addEventListener("keydown",this._onKeyDown),window.addEventListener("keyup",this._onKeyUp),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.addEventListener("pointercancel",this._onPointerCancel),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="none"}disconnect(){window.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("keyup",this._onKeyUp),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerCancel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction=""}dispose(){this.disconnect()}update(e){if(this.enabled===!1)return;const t=this.object,n=e*this.movementSpeed,i=e*this.rollSpeed;t.translateX(this._moveVector.x*n),t.translateY(this._moveVector.y*n),t.translateZ(this._moveVector.z*n),P0.set(this._rotationVector.x*i,this._rotationVector.y*i,this._rotationVector.z*i,1).normalize(),t.quaternion.multiply(P0),(this._lastPosition.distanceToSquared(t.position)>N0||8*(1-this._lastQuaternion.dot(t.quaternion))>N0)&&(this.dispatchEvent(V3),this._lastQuaternion.copy(t.quaternion),this._lastPosition.copy(t.position))}_updateMovementVector(){const e=this._moveState.forward||this.autoForward&&!this._moveState.back?1:0;this._moveVector.x=-this._moveState.left+this._moveState.right,this._moveVector.y=-this._moveState.down+this._moveState.up,this._moveVector.z=-e+this._moveState.back}_updateRotationVector(){this._rotationVector.x=-this._moveState.pitchDown+this._moveState.pitchUp,this._rotationVector.y=-this._moveState.yawRight+this._moveState.yawLeft,this._rotationVector.z=-this._moveState.rollRight+this._moveState.rollLeft}_getContainerDimensions(){return this.domElement!=document?{size:[this.domElement.offsetWidth,this.domElement.offsetHeight],offset:[this.domElement.offsetLeft,this.domElement.offsetTop]}:{size:[window.innerWidth,window.innerHeight],offset:[0,0]}}}function H3(r){if(!(r.altKey||this.enabled===!1)){switch(r.code){case"ShiftLeft":case"ShiftRight":this.movementSpeedMultiplier=.1;break;case"KeyW":this._moveState.forward=1;break;case"KeyS":this._moveState.back=1;break;case"KeyA":this._moveState.left=1;break;case"KeyD":this._moveState.right=1;break;case"KeyR":this._moveState.up=1;break;case"KeyF":this._moveState.down=1;break;case"ArrowUp":this._moveState.pitchUp=1;break;case"ArrowDown":this._moveState.pitchDown=1;break;case"ArrowLeft":this._moveState.yawLeft=1;break;case"ArrowRight":this._moveState.yawRight=1;break;case"KeyQ":this._moveState.rollLeft=1;break;case"KeyE":this._moveState.rollRight=1;break}this._updateMovementVector(),this._updateRotationVector()}}function W3(r){if(this.enabled!==!1){switch(r.code){case"ShiftLeft":case"ShiftRight":this.movementSpeedMultiplier=1;break;case"KeyW":this._moveState.forward=0;break;case"KeyS":this._moveState.back=0;break;case"KeyA":this._moveState.left=0;break;case"KeyD":this._moveState.right=0;break;case"KeyR":this._moveState.up=0;break;case"KeyF":this._moveState.down=0;break;case"ArrowUp":this._moveState.pitchUp=0;break;case"ArrowDown":this._moveState.pitchDown=0;break;case"ArrowLeft":this._moveState.yawLeft=0;break;case"ArrowRight":this._moveState.yawRight=0;break;case"KeyQ":this._moveState.rollLeft=0;break;case"KeyE":this._moveState.rollRight=0;break}this._updateMovementVector(),this._updateRotationVector()}}function $3(r){if(this.enabled!==!1)if(this.dragToLook)this._status++;else{switch(r.button){case 0:this._moveState.forward=1;break;case 2:this._moveState.back=1;break}this._updateMovementVector()}}function X3(r){if(this.enabled!==!1&&(!this.dragToLook||this._status>0)){const e=this._getContainerDimensions(),t=e.size[0]/2,n=e.size[1]/2;this._moveState.yawLeft=-(r.pageX-e.offset[0]-t)/t,this._moveState.pitchDown=(r.pageY-e.offset[1]-n)/n,this._updateRotationVector()}}function q3(r){if(this.enabled!==!1){if(this.dragToLook)this._status--,this._moveState.yawLeft=this._moveState.pitchDown=0;else{switch(r.button){case 0:this._moveState.forward=0;break;case 2:this._moveState.back=0;break}this._updateMovementVector()}this._updateRotationVector()}}function j3(){this.enabled!==!1&&(this.dragToLook?(this._status=0,this._moveState.yawLeft=this._moveState.pitchDown=0):(this._moveState.forward=0,this._moveState.back=0,this._updateMovementVector()),this._updateRotationVector())}function Y3(r){this.enabled!==!1&&r.preventDefault()}const K3={name:"CopyShader",uniforms:{tDiffuse:{value:null},opacity:{value:1}},vertexShader:`
5059
+ var<${n}> ${e} : ${o};`}}class ZB{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return e.depth&&(e.depthTexture!==null?t=this.getTextureFormatGPU(e.depthTexture):e.stencil?this.backend.renderer.reversedDepthBuffer===!0?t=L.Depth32FloatStencil8:t=L.Depth24PlusStencil8:this.backend.renderer.reversedDepthBuffer===!0?t=L.Depth32Float:t=L.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getTextureSampleData(e){let t;if(e.isFramebufferTexture)t=1;else if(e.isDepthTexture&&!e.renderTarget){const s=this.backend.renderer,o=s.getRenderTarget();t=o?o.samples:s.currentSamples}else e.renderTarget&&(t=e.renderTarget.samples);t=t||1;const n=t>1&&e.renderTarget!==null&&e.isDepthTexture!==!0&&e.isFramebufferTexture!==!0;return{samples:t,primarySamples:n?1:t,isMSAA:n}}getCurrentColorFormat(e){let t;return e.textures!==null?t=this.getTextureFormatGPU(e.textures[0]):t=this.getPreferredCanvasFormat(),t}getCurrentColorFormats(e){return e.textures!==null?e.textures.map(t=>this.getTextureFormatGPU(t)):[this.getPreferredCanvasFormat()]}getCurrentColorSpace(e){return e.textures!==null?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){if(e.isPoints)return Qu.PointList;if(e.isLineSegments||e.isMesh&&t.wireframe===!0)return Qu.LineList;if(e.isLine)return Qu.LineStrip;if(e.isMesh)return Qu.TriangleList}getSampleCount(e){return e>=4?4:1}getSampleCountRenderContext(e){return e.textures!==null?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.currentSamples)}getPreferredCanvasFormat(){const t=this.backend.parameters.outputType;if(t===void 0)return navigator.gpu.getPreferredCanvasFormat();if(t===Xt)return L.BGRA8Unorm;if(t===tn)return L.RGBA16Float;throw new Error("Unsupported output buffer type.")}}const $b=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]);typeof Float16Array<"u"&&$b.set(Float16Array,["float16"]);const QB=new Map([[ey,["float16"]]]),JB=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class e3{constructor(e){this.backend=e}createAttribute(e,t){const n=this._getBufferAttribute(e),i=this.backend,s=i.get(n);let o=s.buffer;if(o===void 0){const a=i.device;let l=n.array;if(e.normalized===!1){if(l.constructor===Int16Array||l.constructor===Int8Array)l=new Int32Array(l);else if((l.constructor===Uint16Array||l.constructor===Uint8Array)&&(l=new Uint32Array(l),t&GPUBufferUsage.INDEX))for(let h=0;h<l.length;h++)l[h]===65535&&(l[h]=4294967295)}if(n.array=l,(n.isStorageBufferAttribute||n.isStorageInstancedBufferAttribute)&&n.itemSize===3){l=new l.constructor(n.count*4);for(let h=0;h<n.count;h++)l.set(n.array.subarray(h*3,h*3+3),h*4);n.itemSize=4,n.array=l,s._force3to4BytesAlignment=!0}const c=l.byteLength,u=c+(4-c%4)%4;o=a.createBuffer({label:n.name,size:u,usage:t,mappedAtCreation:!0}),new l.constructor(o.getMappedRange()).set(l),o.unmap(),s.buffer=o}}updateAttribute(e){const t=this._getBufferAttribute(e),n=this.backend,i=n.device,s=n.get(t),o=n.get(t).buffer;let a=t.array;if(s._force3to4BytesAlignment===!0){a=new a.constructor(t.count*4);for(let c=0;c<t.count;c++)a.set(t.array.subarray(c*3,c*3+3),c*4);t.array=a}const l=t.updateRanges;if(l.length===0)i.queue.writeBuffer(o,0,a,0);else{const c=gh(a),u=c?1:a.BYTES_PER_ELEMENT;for(let h=0,d=l.length;h<d;h++){const f=l[h];let p,g;if(s._force3to4BytesAlignment===!0){const _=Math.floor(f.start/3),x=Math.ceil(f.count/3);p=_*4*u,g=x*4*u}else p=f.start*u,g=f.count*u;const m=p*(c?a.BYTES_PER_ELEMENT:1);i.queue.writeBuffer(o,m,a,p,g)}t.clearUpdateRanges()}}createShaderVertexBuffers(e){const t=e.getAttributes(),n=new Map;for(let i=0;i<t.length;i++){const s=t[i],o=s.array.BYTES_PER_ELEMENT,a=this._getBufferAttribute(s);let l=n.get(a);if(l===void 0){let h,d;s.isInterleavedBufferAttribute===!0?(h=s.data.stride*o,d=s.data.isInstancedInterleavedBuffer?Ju.Instance:Ju.Vertex):(h=s.itemSize*o,d=s.isInstancedBufferAttribute?Ju.Instance:Ju.Vertex),s.normalized===!1&&(s.array.constructor===Int16Array||s.array.constructor===Uint16Array)&&(h=4),l={arrayStride:h,attributes:[],stepMode:d},n.set(a,l)}const c=this._getVertexFormat(s),u=s.isInterleavedBufferAttribute===!0?s.offset*o:0;l.attributes.push({shaderLocation:i,offset:u,format:c})}return Array.from(n.values())}destroyAttribute(e){const t=this.backend;t.get(this._getBufferAttribute(e)).buffer.destroy(),t.delete(e)}async getArrayBufferAsync(e,t=null,n=0,i=-1){const s=this.backend,o=s.device,l=s.get(this._getBufferAttribute(e)).buffer,c=i===-1?l.size-n:i;let u;if(t!==null&&t.isReadbackBuffer){const f=s.get(t);if(t._mapped===!0)throw new Error("WebGPURenderer: ReadbackBuffer must be released before being used again.");if(t._mapped=!0,f.readBufferGPU===void 0){u=o.createBuffer({label:`${t.name}_readback`,size:t.maxByteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});const p=()=>{t.buffer=null,t._mapped=!1,u.unmap()},g=()=>{t.buffer=null,t._mapped=!1,u.destroy(),s.delete(t),t.removeEventListener("release",p),t.removeEventListener("dispose",g)};t.addEventListener("release",p),t.addEventListener("dispose",g),f.readBufferGPU=u}else u=f.readBufferGPU}else u=o.createBuffer({label:`${e.name}_readback`,size:c,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});const h=o.createCommandEncoder({label:`readback_encoder_${e.name}`});h.copyBufferToBuffer(l,n,u,0,c);const d=h.finish();if(o.queue.submit([d]),await u.mapAsync(GPUMapMode.READ,0,c),t===null){const p=u.getMappedRange(0,c).slice();return u.destroy(),p}else{if(t.isReadbackBuffer)return t.buffer=u.getMappedRange(0,c),t;{const f=u.getMappedRange(0,c);return new Uint8Array(t).set(new Uint8Array(f)),u.destroy(),t}}}_getVertexFormat(e){const{itemSize:t,normalized:n}=e,i=e.array.constructor,s=e.constructor;let o;if(t===1)o=JB.get(i);else{const l=(QB.get(s)||$b.get(i))[n?1:0];if(l){const c=i.BYTES_PER_ELEMENT*t,h=Math.floor((c+3)/4)*4/i.BYTES_PER_ELEMENT;if(h%1)throw new Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");o=`${l}x${h}`}}return o||ce("WebGPUAttributeUtils: Vertex format not supported yet."),o}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}class t3{constructor(e){this.layoutGPU=e,this.usedTimes=0}}class n3{constructor(e){this.backend=e,this._bindGroupLayoutCache=new Map}createBindingsLayout(e){const t=this.backend,n=t.device,i=t.get(e);if(i.layout)return i.layout.layoutGPU;const s=this._createLayoutEntries(e),o=cl(JSON.stringify(s));let a=this._bindGroupLayoutCache.get(o);return a===void 0&&(a=new t3(n.createBindGroupLayout({entries:s})),this._bindGroupLayoutCache.set(o,a)),a.usedTimes++,i.layout=a,i.layoutKey=o,a.layoutGPU}createBindings(e,t,n,i=0){const{backend:s}=this,o=s.get(e),a=this.createBindingsLayout(e);let l;n>0&&(o.groups===void 0&&(o.groups=[],o.versions=[]),o.versions[n]===i&&(l=o.groups[n])),l===void 0&&(l=this.createBindGroup(e,a),n>0&&(o.groups[n]=l,o.versions[n]=i)),o.group=l}updateBinding(e){const t=this.backend,n=t.device,i=e.buffer,s=t.get(e).buffer,o=e.updateRanges;if(o.length===0)n.queue.writeBuffer(s,0,i,0);else{const a=gh(i),l=a?1:i.BYTES_PER_ELEMENT;for(let c=0,u=o.length;c<u;c++){const h=o[c],d=h.start*l,f=h.count*l,p=d*(a?i.BYTES_PER_ELEMENT:1);n.queue.writeBuffer(s,p,i,d,f)}}}createBindGroupIndex(e,t){const i=this.backend.device,s=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,o=e[0],a=i.createBuffer({label:"bindingCameraIndex_"+o,size:16,usage:s});i.queue.writeBuffer(a,0,e,0);const l=[{binding:0,resource:{buffer:a}}];return i.createBindGroup({label:"bindGroupCameraIndex_"+o,layout:t,entries:l})}createBindGroup(e,t){const n=this.backend,i=n.device;let s=0;const o=[];for(const a of e.bindings){if(a.isUniformBuffer){const l=n.get(a);if(l.buffer===void 0){const c=a.byteLength,u=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,h=[];a.visibility&yr.VERTEX&&h.push("vertex"),a.visibility&yr.FRAGMENT&&h.push("fragment"),a.visibility&yr.COMPUTE&&h.push("compute");const d=`(${h.join(",")})`,f=i.createBuffer({label:`bindingBuffer${a.id}_${a.name}_${d}`,size:c,usage:u});l.buffer=f}o.push({binding:s,resource:{buffer:l.buffer}})}else if(a.isStorageBuffer){const l=n.get(a.attribute).buffer;o.push({binding:s,resource:{buffer:l}})}else if(a.isSampledTexture){const l=n.get(a.texture);let c;if(l.externalTexture!==void 0)c=i.importExternalTexture({source:l.externalTexture});else{const u=a.store?1:l.texture.mipLevelCount,h=a.store?a.mipLevel:0;let d=`view-${l.texture.width}-${l.texture.height}`;if(l.texture.depthOrArrayLayers>1&&(d+=`-${l.texture.depthOrArrayLayers}`),d+=`-${u}-${h}`,c=l[d],c===void 0){const f=DB.All;let p;a.isSampledCubeTexture?p=Wn.Cube:a.isSampledTexture3D?p=Wn.ThreeD:a.texture.isArrayTexture||a.texture.isDataArrayTexture||a.texture.isCompressedArrayTexture?p=Wn.TwoDArray:p=Wn.TwoD,c=l[d]=l.texture.createView({aspect:f,dimension:p,mipLevelCount:u,baseMipLevel:h})}}o.push({binding:s,resource:c})}else if(a.isSampler){const l=n.get(a.texture);o.push({binding:s,resource:l.sampler})}s++}return i.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:o})}_createLayoutEntries(e){const t=[];let n=0;for(const i of e.bindings){const s=this.backend,o={binding:n,visibility:i.visibility};if(i.isUniformBuffer||i.isStorageBuffer){const a={};i.isStorageBuffer&&(i.visibility&yr.COMPUTE&&(i.access===Ui.READ_WRITE||i.access===Ui.WRITE_ONLY)?a.type=zf.Storage:a.type=zf.ReadOnlyStorage),o.buffer=a}else if(i.isSampledTexture&&i.store){const a={};a.format=this.backend.get(i.texture).texture.format;const l=i.access;l===Ui.READ_WRITE?a.access=Hf.ReadWrite:l===Ui.WRITE_ONLY?a.access=Hf.WriteOnly:a.access=Hf.ReadOnly,i.texture.isArrayTexture?a.viewDimension=Wn.TwoDArray:i.texture.is3DTexture&&(a.viewDimension=Wn.ThreeD),o.storageTexture=a}else if(i.isSampledTexture){const a={},{primarySamples:l}=s.utils.getTextureSampleData(i.texture);if(l>1&&(a.multisampled=!0,i.texture.isDepthTexture||(a.sampleType=Qs.UnfilterableFloat)),i.texture.isDepthTexture)s.compatibilityMode&&i.texture.compareFunction===null?a.sampleType=Qs.UnfilterableFloat:a.sampleType=Qs.Depth;else if(i.texture.isDataTexture||i.texture.isDataArrayTexture||i.texture.isData3DTexture||i.texture.isStorageTexture){const c=i.texture.type;c===Sn?a.sampleType=Qs.SInt:c===Ct?a.sampleType=Qs.UInt:c===Qt&&(this.backend.hasFeature("float32-filterable")?a.sampleType=Qs.Float:a.sampleType=Qs.UnfilterableFloat)}i.isSampledCubeTexture?a.viewDimension=Wn.Cube:i.texture.isArrayTexture||i.texture.isDataArrayTexture||i.texture.isCompressedArrayTexture?a.viewDimension=Wn.TwoDArray:i.isSampledTexture3D&&(a.viewDimension=Wn.ThreeD),o.texture=a}else if(i.isSampler){const a={};i.texture.isDepthTexture&&(i.texture.compareFunction!==null&&s.hasCompatibility(wo.TEXTURE_COMPARE)?a.type=y0.Comparison:a.type=y0.NonFiltering),o.sampler=a}else ce(`WebGPUBindingUtils: Unsupported binding "${i}".`);t.push(o),n++}return t}deleteBindGroupData(e){const{backend:t}=this,n=t.get(e);n.layout&&(n.layout.usedTimes--,n.layout.usedTimes===0&&this._bindGroupLayoutCache.delete(n.layoutKey),n.layout=void 0,n.layoutKey=void 0)}dispose(){this._bindGroupLayoutCache.clear()}}class i3{constructor(e){this.backend=e}getMaxAnisotropy(){return 16}getUniformBufferLimit(){return this.backend.device.limits.maxUniformBufferBindingSize}}class r3{constructor(e){this.backend=e,this._activePipelines=new WeakMap}setPipeline(e,t){this._activePipelines.get(e)!==t&&(e.setPipeline(t),this._activePipelines.set(e,t))}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:n,material:i,geometry:s,pipeline:o}=e,{vertexProgram:a,fragmentProgram:l}=o,c=this.backend,u=c.device,h=c.utils,d=c.get(o),f=[];for(const V of e.getBindings()){const z=c.get(V),{layoutGPU:U}=z.layout;f.push(U)}const p=c.attributeUtils.createShaderVertexBuffers(e);let g;i.blending!==Pn&&(i.blending!==ti||i.transparent!==!1)&&(g=this._getBlending(i));let m={};i.stencilWrite===!0&&(m={compare:this._getStencilCompare(i),failOp:this._getStencilOperation(i.stencilFail),depthFailOp:this._getStencilOperation(i.stencilZFail),passOp:this._getStencilOperation(i.stencilZPass)});const _=this._getColorWriteMask(i),x=[];if(e.context.textures!==null){const V=e.context.textures,z=e.context.mrt;for(let U=0;U<V.length;U++){const B=V[U],D=h.getTextureFormatGPU(B);let X;if(z!==null)if(this.backend.compatibilityMode!==!0){const K=z.getBlendMode(B.name);K.blending===V0?X=g:K.blending!==Pn&&(X=this._getBlending(K))}else Kt("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets."),X=g;else X=g;x.push({format:D,blend:X,writeMask:_})}}else{const V=h.getCurrentColorFormat(e.context);x.push({format:V,blend:g,writeMask:_})}const y=c.get(a).module,b=c.get(l).module,M=this._getPrimitiveState(n,s,i),S=this._getDepthCompare(i),E=h.getCurrentDepthStencilFormat(e.context),v=this._getSampleCount(e.context),w={label:`renderPipeline_${i.name||i.type}_${i.id}`,vertex:Object.assign({},y,{buffers:p}),fragment:Object.assign({},b,{targets:x}),primitive:M,multisample:{count:v,alphaToCoverageEnabled:i.alphaToCoverage&&v>1},layout:u.createPipelineLayout({bindGroupLayouts:f})},N={},C=e.context.depth,F=e.context.stencil;if((C===!0||F===!0)&&(C===!0&&(N.format=E,N.depthWriteEnabled=i.depthWrite,N.depthCompare=S),F===!0&&(N.stencilFront=m,N.stencilBack=m,N.stencilReadMask=i.stencilFuncMask,N.stencilWriteMask=i.stencilWriteMask),i.polygonOffset===!0&&(N.depthBias=i.polygonOffsetUnits,N.depthBiasSlopeScale=i.polygonOffsetFactor,N.depthBiasClamp=0),w.depthStencil=N),u.pushErrorScope("validation"),t===null)d.pipeline=u.createRenderPipeline(w),u.popErrorScope().then(V=>{V!==null&&(d.error=!0,ce(V.message))});else{const V=new Promise(async z=>{try{d.pipeline=await u.createRenderPipelineAsync(w)}catch{}const U=await u.popErrorScope();U!==null&&(d.error=!0,ce(U.message)),z()});t.push(V)}}createBundleEncoder(e,t="renderBundleEncoder"){const n=this.backend,{utils:i,device:s}=n,o=i.getCurrentDepthStencilFormat(e),a=i.getCurrentColorFormats(e),l=this._getSampleCount(e),c={label:t,colorFormats:a,depthStencilFormat:o,sampleCount:l};return s.createRenderBundleEncoder(c)}createComputePipeline(e,t){const n=this.backend,i=n.device,s=n.get(e.computeProgram).module,o=n.get(e),a=[];for(const l of t){const c=n.get(l),{layoutGPU:u}=c.layout;a.push(u)}o.pipeline=i.createComputePipeline({compute:s,layout:i.createPipelineLayout({bindGroupLayouts:a})})}_getBlending(e){let t,n;const i=e.blending,s=e.blendSrc,o=e.blendDst,a=e.blendEquation;if(i===co){const l=e.blendSrcAlpha!==null?e.blendSrcAlpha:s,c=e.blendDstAlpha!==null?e.blendDstAlpha:o,u=e.blendEquationAlpha!==null?e.blendEquationAlpha:a;t={srcFactor:this._getBlendFactor(s),dstFactor:this._getBlendFactor(o),operation:this._getBlendOperation(a)},n={srcFactor:this._getBlendFactor(l),dstFactor:this._getBlendFactor(c),operation:this._getBlendOperation(u)}}else{const l=e.premultipliedAlpha,c=(u,h,d,f)=>{t={srcFactor:u,dstFactor:h,operation:Zs.Add},n={srcFactor:d,dstFactor:f,operation:Zs.Add}};if(l)switch(i){case ti:c(_t.One,_t.OneMinusSrcAlpha,_t.One,_t.OneMinusSrcAlpha);break;case _s:c(_t.One,_t.One,_t.One,_t.One);break;case xs:c(_t.Zero,_t.OneMinusSrc,_t.Zero,_t.One);break;case ys:c(_t.Dst,_t.OneMinusSrcAlpha,_t.Zero,_t.One);break}else switch(i){case ti:c(_t.SrcAlpha,_t.OneMinusSrcAlpha,_t.One,_t.OneMinusSrcAlpha);break;case _s:c(_t.SrcAlpha,_t.One,_t.One,_t.One);break;case xs:ce(`WebGPURenderer: "SubtractiveBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`);break;case ys:ce(`WebGPURenderer: "MultiplyBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`);break}}if(t!==void 0&&n!==void 0)return{color:t,alpha:n};ce("WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(e){let t;switch(e){case Gr:t=_t.Zero;break;case kp:t=_t.One;break;case Gp:t=_t.Src;break;case Vp:t=_t.OneMinusSrc;break;case oc:t=_t.SrcAlpha;break;case ac:t=_t.OneMinusSrcAlpha;break;case Wp:t=_t.Dst;break;case $p:t=_t.OneMinusDst;break;case zp:t=_t.DstAlpha;break;case Hp:t=_t.OneMinusDstAlpha;break;case Xp:t=_t.SrcAlphaSaturated;break;case kF:t=_t.Constant;break;case GF:t=_t.OneMinusConstant;break;default:ce("WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const n=e.stencilFunc;switch(n){case XS:t=Ln.Never;break;case np:t=Ln.Always;break;case qS:t=Ln.Less;break;case YS:t=Ln.LessEqual;break;case jS:t=Ln.Equal;break;case QS:t=Ln.GreaterEqual;break;case KS:t=Ln.Greater;break;case ZS:t=Ln.NotEqual;break;default:ce("WebGPURenderer: Invalid stencil function.",n)}return t}_getStencilOperation(e){let t;switch(e){case eo:t=fs.Keep;break;case kS:t=fs.Zero;break;case GS:t=fs.Replace;break;case $S:t=fs.Invert;break;case VS:t=fs.IncrementClamp;break;case zS:t=fs.DecrementClamp;break;case HS:t=fs.IncrementWrap;break;case WS:t=fs.DecrementWrap;break;default:ce("WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Xn:t=Zs.Add;break;case Bp:t=Zs.Subtract;break;case Op:t=Zs.ReverseSubtract;break;case z0:t=Zs.Min;break;case H0:t=Zs.Max;break;default:ce("WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,n){const i={},s=this.backend.utils;i.topology=s.getPrimitiveTopology(e,n),t.index!==null&&e.isLine===!0&&e.isLineSegments!==!0&&(i.stripIndexFormat=t.index.array instanceof Uint16Array?Ph.Uint16:Ph.Uint32);let o=n.side===Lt;return e.isMesh&&e.matrixWorld.determinant()<0&&(o=!o),i.frontFace=o===!0?g0.CW:g0.CCW,i.cullMode=n.side===Nn?_0.None:_0.Back,i}_getColorWriteMask(e){return e.colorWrite===!0?x0.All:x0.None}_getDepthCompare(e){let t;if(e.depthTest===!1)t=Ln.Always;else{const n=this.backend.parameters.reversedDepthBuffer?sm[e.depthFunc]:e.depthFunc;switch(n){case lc:t=Ln.Never;break;case cc:t=Ln.Always;break;case uc:t=Ln.Less;break;case Ds:t=Ln.LessEqual;break;case hc:t=Ln.Equal;break;case dc:t=Ln.GreaterEqual;break;case fc:t=Ln.Greater;break;case pc:t=Ln.NotEqual;break;default:ce("WebGPUPipelineUtils: Invalid depth function.",n)}}return t}}class s3 extends Hb{constructor(e,t,n=2048){super(n),this.device=e,this.type=t,this.querySet=this.device.createQuerySet({type:"timestamp",count:this.maxQueries,label:`queryset_global_timestamp_${t}`});const i=this.maxQueries*8;this.resolveBuffer=this.device.createBuffer({label:`buffer_timestamp_resolve_${t}`,size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.resultBuffer=this.device.createBuffer({label:`buffer_timestamp_result_${t}`,size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ})}allocateQueriesForContext(e){if(!this.trackTimestamp||this.isDisposed)return null;if(this.currentQueryIndex+2>this.maxQueries)return Kt(`WebGPUTimestampQueryPool [${this.type}]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${this.type.toUpperCase()} ).`),null;const t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryOffsets.set(e,t),t}async resolveQueriesAsync(){if(!this.trackTimestamp||this.currentQueryIndex===0||this.isDisposed)return this.lastValue;if(this.pendingResolve)return this.pendingResolve;this.pendingResolve=this._resolveQueries();try{return await this.pendingResolve}finally{this.pendingResolve=null}}async _resolveQueries(){if(this.isDisposed)return this.lastValue;try{if(this.resultBuffer.mapState!=="unmapped")return this.lastValue;const e=new Map(this.queryOffsets),t=this.currentQueryIndex,n=t*8;this.currentQueryIndex=0,this.queryOffsets.clear();const i=this.device.createCommandEncoder();i.resolveQuerySet(this.querySet,0,t,this.resolveBuffer,0),i.copyBufferToBuffer(this.resolveBuffer,0,this.resultBuffer,0,n);const s=i.finish();if(this.device.queue.submit([s]),this.resultBuffer.mapState!=="unmapped")return this.lastValue;if(await this.resultBuffer.mapAsync(GPUMapMode.READ,0,n),this.isDisposed)return this.resultBuffer.mapState==="mapped"&&this.resultBuffer.unmap(),this.lastValue;const o=new BigUint64Array(this.resultBuffer.getMappedRange(0,n)),a={},l=[];for(const[u,h]of e){const d=u.match(/^(.*):f(\d+)$/),f=parseInt(d[2]);l.includes(f)===!1&&l.push(f),a[f]===void 0&&(a[f]=0);const p=o[h],g=o[h+1],m=Number(g-p)/1e6;this.timestamps.set(u,m),a[f]+=m}const c=a[l[l.length-1]];return this.resultBuffer.unmap(),this.lastValue=c,this.frames=l,c}catch(e){return ce("Error resolving queries:",e),this.resultBuffer.mapState==="mapped"&&this.resultBuffer.unmap(),this.lastValue}}async dispose(){if(!this.isDisposed){if(this.isDisposed=!0,this.pendingResolve)try{await this.pendingResolve}catch(e){ce("Error waiting for pending resolve:",e)}if(this.resultBuffer&&this.resultBuffer.mapState==="mapped")try{this.resultBuffer.unmap()}catch(e){ce("Error unmapping buffer:",e)}this.querySet&&(this.querySet.destroy(),this.querySet=null),this.resolveBuffer&&(this.resolveBuffer.destroy(),this.resolveBuffer=null),this.resultBuffer&&(this.resultBuffer.destroy(),this.resultBuffer=null),this.queryOffsets.clear(),this.pendingResolve=null}}}const Xi={r:0,g:0,b:0,a:1};class o3 extends zb{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=e.alpha===void 0?!0:e.alpha,this.parameters.requiredLimits=e.requiredLimits===void 0?{}:e.requiredLimits,this.compatibilityMode=null,this.device=null,this.defaultRenderPassdescriptor=null,this.utils=new ZB(this),this.attributeUtils=new e3(this),this.bindingUtils=new n3(this),this.capabilities=new i3(this),this.pipelineUtils=new r3(this),this.textureUtils=new GB(this),this.occludedResolveCache=new Map;const t=typeof navigator>"u"?!0:/Android/.test(navigator.userAgent)===!1;this._compatibility={[wo.TEXTURE_COMPARE]:t}}async init(e){await super.init(e);const t=this.parameters;let n;if(t.device===void 0){const i={powerPreference:t.powerPreference,featureLevel:"compatibility"},s=typeof navigator<"u"?await navigator.gpu.requestAdapter(i):null;if(s===null)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const o=Object.values(Dh),a=[];for(const c of o)s.features.has(c)&&a.push(c);const l={requiredFeatures:a,requiredLimits:t.requiredLimits};n=await s.requestDevice(l)}else n=t.device;this.compatibilityMode=!n.features.has("core-features-and-limits"),this.compatibilityMode&&(e._samples=0),n.lost.then(i=>{if(i.reason==="destroyed")return;const s={api:"WebGPU",message:i.message||"Unknown reason",reason:i.reason||null,originalEvent:i};e.onDeviceLost(s)}),this.device=n,this.trackTimestamp=this.trackTimestamp&&this.hasFeature(Dh.TimestampQuery),this.updateSize()}get context(){const e=this.renderer.getCanvasTarget(),t=this.get(e);let n=t.context;if(n===void 0){const i=this.parameters;e.isDefaultCanvasTarget===!0&&i.context!==void 0?n=i.context:n=e.domElement.getContext("webgpu"),"setAttribute"in e.domElement&&e.domElement.setAttribute("data-engine",`three.js r${Mo} webgpu`);const s=i.alpha?"premultiplied":"opaque",o=i.outputType===tn?"extended":"standard";n.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:s,toneMapping:{mode:o}}),t.context=n}return n}get coordinateSystem(){return Tr}async getArrayBufferAsync(e,t=null,n=0,i=-1){return await this.attributeUtils.getArrayBufferAsync(e,t,n,i)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){const e=this.renderer,t=e.getCanvasTarget(),n=this.get(t),i=e.currentSamples;let s=n.descriptor;if(s===void 0||n.samples!==i){s={colorAttachments:[{view:null}]},(e.depth===!0||e.stencil===!0)&&(s.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView()});const a=s.colorAttachments[0];i>0?a.view=this.textureUtils.getColorBuffer().createView():a.resolveTarget=void 0,n.descriptor=s,n.samples=i}const o=s.colorAttachments[0];return i>0?o.resolveTarget=this.context.getCurrentTexture().createView():o.view=this.context.getCurrentTexture().createView(),s}_isRenderCameraDepthArray(e){return e.depthTexture&&e.depthTexture.image.depth>1&&e.camera.isArrayCamera}_getRenderPassDescriptor(e,t={}){const n=e.renderTarget,i=this.get(n);let s=i.descriptors;(s===void 0||i.width!==n.width||i.height!==n.height||i.samples!==n.samples)&&(s={},i.descriptors=s);const o=e.getCacheKey();let a=s[o];if(a===void 0){const c=e.textures,u=[];let h;const d=this._isRenderCameraDepthArray(e);for(let f=0;f<c.length;f++){const p=this.get(c[f]),g={label:`colorAttachment_${f}`,baseMipLevel:e.activeMipmapLevel,mipLevelCount:1,baseArrayLayer:e.activeCubeFace,arrayLayerCount:1,dimension:Wn.TwoD};if(n.isRenderTarget3D)h=e.activeCubeFace,g.baseArrayLayer=0,g.dimension=Wn.ThreeD,g.depthOrArrayLayers=c[f].image.depth;else if(n.isRenderTarget&&c[f].image.depth>1)if(d===!0){const m=e.camera.cameras;for(let _=0;_<m.length;_++){const x={...g,baseArrayLayer:_,arrayLayerCount:1,dimension:Wn.TwoD},y=p.texture.createView(x);u.push({view:y,resolveTarget:void 0,depthSlice:void 0})}}else g.dimension=Wn.TwoDArray,g.depthOrArrayLayers=c[f].image.depth;if(d!==!0){const m=p.texture.createView(g);let _,x;p.msaaTexture!==void 0?(_=p.msaaTexture.createView(),x=m):(_=m,x=void 0),u.push({view:_,resolveTarget:x,depthSlice:h})}}if(a={textureViews:u},e.depth){const f=this.get(e.depthTexture),p={};(e.depthTexture.isArrayTexture||e.depthTexture.isCubeTexture)&&(p.dimension=Wn.TwoD,p.arrayLayerCount=1,p.baseArrayLayer=e.activeCubeFace),a.depthStencilView=f.texture.createView(p)}s[o]=a,i.width=n.width,i.height=n.height,i.samples=n.samples,i.activeMipmapLevel=e.activeMipmapLevel,i.activeCubeFace=e.activeCubeFace}const l={colorAttachments:[]};for(let c=0;c<a.textureViews.length;c++){const u=a.textureViews[c];let h={r:0,g:0,b:0,a:1};c===0&&t.clearValue&&(h=t.clearValue),l.colorAttachments.push({view:u.view,depthSlice:u.depthSlice,resolveTarget:u.resolveTarget,loadOp:t.loadOp||wt.Load,storeOp:t.storeOp||Jn.Store,clearValue:h})}return a.depthStencilView&&(l.depthStencilAttachment={view:a.depthStencilView}),l}beginRender(e){const t=this.get(e),n=this.device,i=e.occlusionQueryCount;let s;i>0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,s=n.createQuerySet({type:"occlusion",count:i,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=s,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(i),t.lastOcclusionObject=null);let o;e.textures===null?o=this._getDefaultRenderPassDescriptor():o=this._getRenderPassDescriptor(e,{loadOp:wt.Load}),this.initTimestampQuery(xr.RENDER,this.getTimestampUID(e),o),o.occlusionQuerySet=s;const a=o.depthStencilAttachment;if(e.textures!==null){const c=o.colorAttachments;for(let u=0;u<c.length;u++){const h=c[u];e.clearColor?(u===0?h.clearValue=e.clearColorValue:(Xi.r=0,Xi.g=0,Xi.b=0,Xi.a=1,h.clearValue=Xi),h.loadOp=wt.Clear):h.loadOp=wt.Load,h.storeOp=Jn.Store}}else{const c=o.colorAttachments[0];e.clearColor?(c.clearValue=e.clearColorValue,c.loadOp=wt.Clear):c.loadOp=wt.Load,c.storeOp=Jn.Store}e.depth&&(e.clearDepth?(a.depthClearValue=e.clearDepthValue,a.depthLoadOp=wt.Clear):a.depthLoadOp=wt.Load,a.depthStoreOp=Jn.Store),e.stencil&&(e.clearStencil?(a.stencilClearValue=e.clearStencilValue,a.stencilLoadOp=wt.Clear):a.stencilLoadOp=wt.Load,a.stencilStoreOp=Jn.Store);const l=n.createCommandEncoder({label:"renderContext_"+e.id});if(this._isRenderCameraDepthArray(e)===!0){const c=e.camera.cameras;!t.layerDescriptors||t.layerDescriptors.length!==c.length?this._createDepthLayerDescriptors(e,t,o,c):this._updateDepthLayerDescriptors(e,t,c),t.bundleEncoders=[],t.bundleSets=[];for(let u=0;u<c.length;u++){const h=this.pipelineUtils.createBundleEncoder(e,"renderBundleArrayCamera_"+u),d={attributes:{},bindingGroups:[],pipeline:null,index:null};t.bundleEncoders.push(h),t.bundleSets.push(d)}t.currentPass=null}else{const c=l.beginRenderPass(o);t.currentPass=c,e.viewport&&this.updateViewport(e),e.scissor&&this.updateScissor(e)}t.descriptor=o,t.encoder=l,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.renderBundles=[]}_createDepthLayerDescriptors(e,t,n,i){const s=n.depthStencilAttachment;t.layerDescriptors=[];const o=this.get(e.depthTexture);o.viewCache||(o.viewCache=[]);for(let a=0;a<i.length;a++){const l={...n,colorAttachments:[{...n.colorAttachments[0],view:n.colorAttachments[a].view}]};if(n.depthStencilAttachment){const c=a;o.viewCache[c]||(o.viewCache[c]=o.texture.createView({dimension:Wn.TwoD,baseArrayLayer:a,arrayLayerCount:1})),l.depthStencilAttachment={view:o.viewCache[c],depthLoadOp:s.depthLoadOp||wt.Clear,depthStoreOp:s.depthStoreOp||Jn.Store,depthClearValue:s.depthClearValue||1},e.stencil&&(l.depthStencilAttachment.stencilLoadOp=s.stencilLoadOp,l.depthStencilAttachment.stencilStoreOp=s.stencilStoreOp,l.depthStencilAttachment.stencilClearValue=s.stencilClearValue)}else l.depthStencilAttachment={...s};t.layerDescriptors.push(l)}}_updateDepthLayerDescriptors(e,t,n){for(let i=0;i<n.length;i++){const s=t.layerDescriptors[i];if(s.depthStencilAttachment){const o=s.depthStencilAttachment;e.depth&&(e.clearDepth?(o.depthClearValue=e.clearDepthValue,o.depthLoadOp=wt.Clear):o.depthLoadOp=wt.Load),e.stencil&&(e.clearStencil?(o.stencilClearValue=e.clearStencilValue,o.stencilLoadOp=wt.Clear):o.stencilLoadOp=wt.Load)}}}finishRender(e){const t=this.get(e),n=e.occlusionQueryCount;t.renderBundles.length>0&&t.currentPass.executeBundles(t.renderBundles),n>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery();const i=t.encoder;if(this._isRenderCameraDepthArray(e)===!0){const s=[];for(let o=0;o<t.bundleEncoders.length;o++){const a=t.bundleEncoders[o];s.push(a.finish())}for(let o=0;o<t.layerDescriptors.length;o++)if(o<s.length){const a=t.layerDescriptors[o],l=i.beginRenderPass(a);if(e.viewport){const{x:c,y:u,width:h,height:d,minDepth:f,maxDepth:p}=e.viewportValue;l.setViewport(c,u,h,d,f,p)}if(e.scissor){const{x:c,y:u,width:h,height:d}=e.scissorValue;l.setScissorRect(c,u,h,d)}l.executeBundles([s[o]]),l.end()}}else t.currentPass&&t.currentPass.end();if(n>0){const s=n*8;let o=this.occludedResolveCache.get(s);o===void 0&&(o=this.device.createBuffer({size:s,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(s,o));const a=this.device.createBuffer({size:s,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,n,o,0),t.encoder.copyBufferToBuffer(o,0,a,0,s),t.occlusionQueryBuffer=a,this.resolveOccludedAsync(e)}if(this.device.queue.submit([t.encoder.finish()]),e.textures!==null){const s=e.textures;for(let o=0;o<s.length;o++){const a=s[o];a.generateMipmaps===!0&&this.textureUtils.generateMipmaps(a)}}}isOccluded(e,t){const n=this.get(e);return n.occluded&&n.occluded.has(t)}async resolveOccludedAsync(e){const t=this.get(e),{currentOcclusionQueryBuffer:n,currentOcclusionQueryObjects:i}=t;if(n&&i){const s=new WeakSet;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueryBuffer=null,await n.mapAsync(GPUMapMode.READ);const o=n.getMappedRange(),a=new BigUint64Array(o);for(let l=0;l<i.length;l++)a[l]===BigInt(0)&&s.add(i[l]);n.destroy(),t.occluded=s}}updateViewport(e){const{currentPass:t}=this.get(e),{x:n,y:i,width:s,height:o,minDepth:a,maxDepth:l}=e.viewportValue;t.setViewport(n,i,s,o,a,l)}updateScissor(e){const{currentPass:t}=this.get(e),{x:n,y:i,width:s,height:o}=e.scissorValue;t.setScissorRect(n,i,s,o)}getClearColor(){const e=super.getClearColor();return this.renderer.alpha===!0&&(e.r*=e.a,e.g*=e.a,e.b*=e.a),e}clear(e,t,n,i=null){const s=this.device,o=this.renderer;let a=[],l,c,u;if(e){const f=this.getClearColor();Xi.r=f.r,Xi.g=f.g,Xi.b=f.b,Xi.a=f.a}if(i===null){c=o.depth,u=o.stencil;const f=this._getDefaultRenderPassDescriptor();if(e){a=f.colorAttachments;const p=a[0];p.clearValue=Xi,p.loadOp=wt.Clear,p.storeOp=Jn.Store}(c||u)&&(l=f.depthStencilAttachment)}else{c=i.depth,u=i.stencil;const f={loadOp:e?wt.Clear:wt.Load,clearValue:e?Xi:void 0};c&&(f.depthLoadOp=t?wt.Clear:wt.Load,f.depthClearValue=t?o.getClearDepth():void 0,f.depthStoreOp=Jn.Store),u&&(f.stencilLoadOp=n?wt.Clear:wt.Load,f.stencilClearValue=n?o.getClearStencil():void 0,f.stencilStoreOp=Jn.Store);const p=this._getRenderPassDescriptor(i,f);a=p.colorAttachments,l=p.depthStencilAttachment}c&&l&&(t?(l.depthLoadOp=wt.Clear,l.depthClearValue=o.getClearDepth(),l.depthStoreOp=Jn.Store):(l.depthLoadOp=wt.Load,l.depthStoreOp=Jn.Store)),u&&l&&(n?(l.stencilLoadOp=wt.Clear,l.stencilClearValue=o.getClearStencil(),l.stencilStoreOp=Jn.Store):(l.stencilLoadOp=wt.Load,l.stencilStoreOp=Jn.Store));const h=s.createCommandEncoder({label:"clear"});h.beginRenderPass({colorAttachments:a,depthStencilAttachment:l}).end(),s.queue.submit([h.finish()])}beginCompute(e){const t=this.get(e),n={label:"computeGroup_"+e.id};this.initTimestampQuery(xr.COMPUTE,this.getTimestampUID(e),n),t.cmdEncoderGPU=this.device.createCommandEncoder({label:"computeGroup_"+e.id}),t.passEncoderGPU=t.cmdEncoderGPU.beginComputePass(n)}compute(e,t,n,i,s=null){const o=this.get(t),{passEncoderGPU:a}=this.get(e),l=this.get(i).pipeline;this.pipelineUtils.setPipeline(a,l);for(let c=0,u=n.length;c<u;c++){const h=n[c],d=this.get(h);a.setBindGroup(c,d.group)}if(s===null&&(s=t.dispatchSize||t.count),s&&s.isIndirectStorageBufferAttribute){const c=this.get(s).buffer;a.dispatchWorkgroupsIndirect(c,0);return}if(typeof s=="number"){const c=s;if(o.dispatchSize===void 0||o.count!==c){o.dispatchSize=[0,1,1],o.count=c;const u=t.workgroupSize;let h=u[0];for(let p=1;p<u.length;p++)h*=u[p];const d=Math.ceil(c/h),f=this.device.limits.maxComputeWorkgroupsPerDimension;s=[d,1,1],d>f&&(s[0]=Math.min(d,f),s[1]=Math.ceil(d/f)),o.dispatchSize=s}s=o.dispatchSize}a.dispatchWorkgroups(s[0],s[1]||1,s[2]||1)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.device.queue.submit([t.cmdEncoderGPU.finish()])}_draw(e,t,n,i,s,o,a,l,c){const{object:u,material:h,context:d}=e,f=e.getIndex(),p=f!==null;this.pipelineUtils.setPipeline(l,i),c.pipeline=i;const g=c.bindingGroups;for(let m=0,_=s.length;m<_;m++){const x=s[m],y=this.get(x);g[m]!==x.id&&(l.setBindGroup(m,y.group),g[m]=x.id)}if(p===!0&&c.index!==f){const m=this.get(f).buffer,_=f.array instanceof Uint16Array?Ph.Uint16:Ph.Uint32;l.setIndexBuffer(m,_),c.index=f}for(let m=0,_=o.length;m<_;m++){const x=o[m];if(c.attributes[m]!==x){const y=this.get(x).buffer;l.setVertexBuffer(m,y),c.attributes[m]=x}}if(d.stencil===!0&&h.stencilWrite===!0&&n.currentStencilRef!==h.stencilRef&&(l.setStencilReference(h.stencilRef),n.currentStencilRef=h.stencilRef),u.isBatchedMesh===!0){const m=u._multiDrawStarts,_=u._multiDrawCounts,x=u._multiDrawCount;let y=p===!0?f.array.BYTES_PER_ELEMENT:1;h.wireframe&&(y=u.geometry.attributes.position.count>65535?4:2);for(let b=0;b<x;b++)p===!0?l.drawIndexed(_[b],1,m[b]/y,0,b):l.draw(_[b],1,m[b],b),t.update(u,_[b],1)}else if(p===!0){const{vertexCount:m,instanceCount:_,firstVertex:x}=a,y=e.getIndirect();if(y!==null){const b=this.get(y).buffer,M=e.getIndirectOffset(),S=Array.isArray(M)?M:[M];for(let E=0;E<S.length;E++)l.drawIndexedIndirect(b,S[E])}else l.drawIndexed(m,_,x,0,0);t.update(u,m,_)}else{const{vertexCount:m,instanceCount:_,firstVertex:x}=a,y=e.getIndirect();if(y!==null){const b=this.get(y).buffer,M=e.getIndirectOffset(),S=Array.isArray(M)?M:[M];for(let E=0;E<S.length;E++)l.drawIndirect(b,S[E])}else l.draw(m,_,x,0);t.update(u,m,_)}}draw(e,t){const{object:n,context:i,pipeline:s}=e,o=this.get(i),a=this.get(s),l=a.pipeline;if(a.error===!0)return;const c=e.getDrawParameters();if(c===null)return;const u=e.getBindings(),h=e.getVertexBuffers();if(e.camera.isArrayCamera&&e.camera.cameras.length>0){const d=this.get(e.camera),f=e.camera.cameras,p=e.getBindingGroup("cameraIndex");if(d.indexesGPU===void 0||d.indexesGPU.length!==f.length){const m=this.get(p),_=[],x=new Uint32Array([0,0,0,0]);for(let y=0,b=f.length;y<b;y++){x[0]=y;const{layoutGPU:M}=m.layout,S=this.bindingUtils.createBindGroupIndex(x,M);_.push(S)}d.indexesGPU=_}const g=this.renderer.getPixelRatio();for(let m=0,_=f.length;m<_;m++){const x=f[m];if(n.layers.test(x.layers)){const y=x.viewport;let b=o.currentPass,M=o.currentSets;if(o.bundleEncoders){const S=o.bundleEncoders[m],E=o.bundleSets[m];b=S,M=E}if(y&&b.setViewport(Math.floor(y.x*g),Math.floor(y.y*g),Math.floor(y.width*g),Math.floor(y.height*g),i.viewportValue.minDepth,i.viewportValue.maxDepth),p&&d.indexesGPU){const S=u.indexOf(p);b.setBindGroup(S,d.indexesGPU[m]),M.bindingGroups[S]=p.id}this._draw(e,t,o,l,u,h,c,b,M)}}}else if(o.currentPass){if(o.occlusionQuerySet!==void 0){const d=o.lastOcclusionObject;d!==n&&(d!==null&&d.occlusionTest===!0&&(o.currentPass.endOcclusionQuery(),o.occlusionQueryIndex++),n.occlusionTest===!0&&(o.currentPass.beginOcclusionQuery(o.occlusionQueryIndex),o.occlusionQueryObjects[o.occlusionQueryIndex]=n),o.lastOcclusionObject=n)}this._draw(e,t,o,l,u,h,c,o.currentPass,o.currentSets)}}needsRenderUpdate(e){const t=this.get(e),{object:n,material:i}=e,s=this.utils,o=s.getSampleCountRenderContext(e.context),a=s.getCurrentColorSpace(e.context),l=s.getCurrentColorFormat(e.context),c=s.getCurrentDepthStencilFormat(e.context),u=s.getPrimitiveTopology(n,i);let h=!1;return(t.material!==i||t.materialVersion!==i.version||t.transparent!==i.transparent||t.blending!==i.blending||t.premultipliedAlpha!==i.premultipliedAlpha||t.blendSrc!==i.blendSrc||t.blendDst!==i.blendDst||t.blendEquation!==i.blendEquation||t.blendSrcAlpha!==i.blendSrcAlpha||t.blendDstAlpha!==i.blendDstAlpha||t.blendEquationAlpha!==i.blendEquationAlpha||t.colorWrite!==i.colorWrite||t.depthWrite!==i.depthWrite||t.depthTest!==i.depthTest||t.depthFunc!==i.depthFunc||t.stencilWrite!==i.stencilWrite||t.stencilFunc!==i.stencilFunc||t.stencilFail!==i.stencilFail||t.stencilZFail!==i.stencilZFail||t.stencilZPass!==i.stencilZPass||t.stencilFuncMask!==i.stencilFuncMask||t.stencilWriteMask!==i.stencilWriteMask||t.side!==i.side||t.alphaToCoverage!==i.alphaToCoverage||t.sampleCount!==o||t.colorSpace!==a||t.colorFormat!==l||t.depthStencilFormat!==c||t.primitiveTopology!==u||t.clippingContextCacheKey!==e.clippingContextCacheKey)&&(t.material=i,t.materialVersion=i.version,t.transparent=i.transparent,t.blending=i.blending,t.premultipliedAlpha=i.premultipliedAlpha,t.blendSrc=i.blendSrc,t.blendDst=i.blendDst,t.blendEquation=i.blendEquation,t.blendSrcAlpha=i.blendSrcAlpha,t.blendDstAlpha=i.blendDstAlpha,t.blendEquationAlpha=i.blendEquationAlpha,t.colorWrite=i.colorWrite,t.depthWrite=i.depthWrite,t.depthTest=i.depthTest,t.depthFunc=i.depthFunc,t.stencilWrite=i.stencilWrite,t.stencilFunc=i.stencilFunc,t.stencilFail=i.stencilFail,t.stencilZFail=i.stencilZFail,t.stencilZPass=i.stencilZPass,t.stencilFuncMask=i.stencilFuncMask,t.stencilWriteMask=i.stencilWriteMask,t.side=i.side,t.alphaToCoverage=i.alphaToCoverage,t.sampleCount=o,t.colorSpace=a,t.colorFormat=l,t.depthStencilFormat=c,t.primitiveTopology=u,t.clippingContextCacheKey=e.clippingContextCacheKey,h=!0),h}getRenderCacheKey(e){const{object:t,material:n}=e,i=this.utils,s=e.context,o=t.isMesh&&t.matrixWorld.determinant()<0;return[n.transparent,n.blending,n.premultipliedAlpha,n.blendSrc,n.blendDst,n.blendEquation,n.blendSrcAlpha,n.blendDstAlpha,n.blendEquationAlpha,n.colorWrite,n.depthWrite,n.depthTest,n.depthFunc,n.stencilWrite,n.stencilFunc,n.stencilFail,n.stencilZFail,n.stencilZPass,n.stencilFuncMask,n.stencilWriteMask,n.side,o,i.getSampleCountRenderContext(s),i.getCurrentColorSpace(s),i.getCurrentColorFormat(s),i.getCurrentDepthStencilFormat(s),i.getPrimitiveTopology(t,n),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}updateSampler(e){return this.textureUtils.updateSampler(e)}createDefaultTexture(e){return this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e,t=!1){this.textureUtils.destroyTexture(e,t)}async copyTextureToBuffer(e,t,n,i,s,o){return this.textureUtils.copyTextureToBuffer(e,t,n,i,s,o)}initTimestampQuery(e,t,n){if(!this.trackTimestamp)return;this.timestampQueryPool[e]||(this.timestampQueryPool[e]=new s3(this.device,e,2048));const i=this.timestampQueryPool[e],s=i.allocateQueriesForContext(t);n.timestampWrites={querySet:i.querySet,beginningOfPassWriteIndex:s,endOfPassWriteIndex:s+1}}createNodeBuilder(e,t){return new KB(e,t)}createProgram(e){const t=this.get(e);t.module={module:this.device.createShaderModule({code:e.code,label:e.stage+(e.name!==""?`_${e.name}`:"")}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const n=this.get(e),s=n.currentPass.finish();this.get(t).bundleGPU=s,n.currentSets=n._currentSets,n.currentPass=n._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,n,i){this.bindingUtils.createBindings(e,t,n,i)}updateBindings(e,t,n,i){this.bindingUtils.createBindings(e,t,n,i)}updateBinding(e){this.bindingUtils.updateBinding(e)}deleteBindGroupData(e){this.bindingUtils.deleteBindGroupData(e)}createIndexAttribute(e){let t=GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST;(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(t|=GPUBufferUsage.STORAGE),this.attributeUtils.createAttribute(e,t)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.delete(this.renderer.getCanvasTarget())}hasFeature(e){return b0[e]!==void 0&&(e=b0[e]),this.device.features.has(e)}copyTextureToTexture(e,t,n=null,i=null,s=0,o=0){let a=0,l=0,c=0,u=0,h=0,d=0,f=e.image.width,p=e.image.height,g=1;n!==null&&(n.isBox3===!0?(u=n.min.x,h=n.min.y,d=n.min.z,f=n.max.x-n.min.x,p=n.max.y-n.min.y,g=n.max.z-n.min.z):(u=n.min.x,h=n.min.y,f=n.max.x-n.min.x,p=n.max.y-n.min.y,g=1)),i!==null&&(a=i.x,l=i.y,c=i.z||0);const m=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),_=this.get(e).texture,x=this.get(t).texture;m.copyTextureToTexture({texture:_,mipLevel:s,origin:{x:u,y:h,z:d}},{texture:x,mipLevel:o,origin:{x:a,y:l,z:c}},[f,p,g]),this.device.queue.submit([m.finish()]),o===0&&t.generateMipmaps&&this.textureUtils.generateMipmaps(t)}copyFramebufferToTexture(e,t,n){const i=this.get(t);let s=null;t.renderTarget?e.isDepthTexture?s=this.get(t.depthTexture).texture:s=this.get(t.textures[0]).texture:e.isDepthTexture?s=this.textureUtils.getDepthBuffer(t.depth,t.stencil):s=this.context.getCurrentTexture();const o=this.get(e).texture;if(s.format!==o.format){ce("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",s.format,o.format);return}let a;if(i.currentPass?(i.currentPass.end(),a=i.encoder):a=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),a.copyTextureToTexture({texture:s,origin:[n.x,n.y,0]},{texture:o},[n.z,n.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e,a),i.currentPass){const{descriptor:l}=i;for(let c=0;c<l.colorAttachments.length;c++)l.colorAttachments[c].loadOp=wt.Load;t.depth&&(l.depthStencilAttachment.depthLoadOp=wt.Load),t.stencil&&(l.depthStencilAttachment.stencilLoadOp=wt.Load),i.currentPass=a.beginRenderPass(l),i.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.viewport&&this.updateViewport(t),t.scissor&&this.updateScissor(t)}else this.device.queue.submit([a.finish()])}hasCompatibility(e){return this._compatibility[e]!==void 0?this._compatibility[e]:super.hasCompatibility(e)}dispose(){if(this.bindingUtils.dispose(),this.textureUtils.dispose(),this.occludedResolveCache){for(const e of this.occludedResolveCache.values())e.destroy();this.occludedResolveCache.clear()}if(this.timestampQueryPool)for(const e of Object.values(this.timestampQueryPool))e!==null&&e.dispose();this.parameters.device===void 0&&this.device!==null&&this.device.destroy()}}class a3 extends Mm{constructor(e,t,n,i,s,o){super(e,t,n,i,s,o),this.iesMap=null}copy(e,t){return super.copy(e,t),this.iesMap=e.iesMap,this}}class l3 extends Mm{constructor(e,t,n,i,s,o){super(e,t,n,i,s,o),this.aspect=null}copy(e,t){return super.copy(e,t),this.aspect=e.aspect,this}}class c3 extends Ub{constructor(){super(),this.addMaterial(vU,"MeshPhongMaterial"),this.addMaterial(pb,"MeshStandardMaterial"),this.addMaterial(_F,"MeshPhysicalMaterial"),this.addMaterial(bF,"MeshToonMaterial"),this.addMaterial(fU,"MeshBasicMaterial"),this.addMaterial(xU,"MeshLambertMaterial"),this.addMaterial(lU,"MeshNormalMaterial"),this.addMaterial(MF,"MeshMatcapMaterial"),this.addMaterial(rU,"LineBasicMaterial"),this.addMaterial(oU,"LineDashedMaterial"),this.addMaterial(CF,"PointsMaterial"),this.addMaterial(gb,"SpriteMaterial"),this.addMaterial(LF,"ShadowMaterial"),this.addLight(l2,MM),this.addLight(O2,dy),this.addLight(W2,AM),this.addLight(Qm,Mm),this.addLight(B2,fy),this.addLight(k2,bM),this.addLight(V2,RM),this.addLight(G2,a3),this.addLight(H2,l3),this.addToneMapping(fI,qp),this.addToneMapping(pI,jp),this.addToneMapping(mI,Yp),this.addToneMapping(_I,Kp),this.addToneMapping(bI,Zp),this.addToneMapping(SI,Qp)}}class u3 extends hB{constructor(e={}){let t;e.forceWebGL?t=m0:(t=o3,e.getFallback=()=>(ae("WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new m0(e)));const n=new t(e);super(n,e),this.library=new c3,this.isWebGPURenderer=!0,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}}const $f={type:"change"},eg={type:"start"},tg={type:"end"},A0=1e-6,Rt={NONE:-1,ROTATE:0,ZOOM:1,PAN:2,TOUCH_ROTATE:3,TOUCH_ZOOM_PAN:4},eh=new pe,ps=new pe,h3=new P,th=new P,Xf=new P,la=new Oi,w0=new P,nh=new P,qf=new P,ih=new P;class d3 extends kh{constructor(e,t=null){super(e,t),this.screen={left:0,top:0,width:0,height:0},this.rotateSpeed=1,this.zoomSpeed=1.2,this.panSpeed=.3,this.noRotate=!1,this.noZoom=!1,this.noPan=!1,this.staticMoving=!1,this.dynamicDampingFactor=.2,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.keys=["KeyA","KeyS","KeyD"],this.mouseButtons={LEFT:Un.ROTATE,MIDDLE:Un.DOLLY,RIGHT:Un.PAN},this.target=new P,this.state=Rt.NONE,this.keyState=Rt.NONE,this._lastPosition=new P,this._lastZoom=1,this._touchZoomDistanceStart=0,this._touchZoomDistanceEnd=0,this._lastAngle=0,this._eye=new P,this._movePrev=new pe,this._moveCurr=new pe,this._lastAxis=new P,this._zoomStart=new pe,this._zoomEnd=new pe,this._panStart=new pe,this._panEnd=new pe,this._pointers=[],this._pointerPositions={},this._onPointerMove=p3.bind(this),this._onPointerDown=f3.bind(this),this._onPointerUp=m3.bind(this),this._onPointerCancel=g3.bind(this),this._onContextMenu=T3.bind(this),this._onMouseWheel=S3.bind(this),this._onKeyDown=x3.bind(this),this._onKeyUp=_3.bind(this),this._onTouchStart=M3.bind(this),this._onTouchMove=E3.bind(this),this._onTouchEnd=A3.bind(this),this._onMouseDown=y3.bind(this),this._onMouseMove=v3.bind(this),this._onMouseUp=b3.bind(this),this._target0=this.target.clone(),this._position0=this.object.position.clone(),this._up0=this.object.up.clone(),this._zoom0=this.object.zoom,t!==null&&(this.connect(t),this.handleResize()),this.update()}connect(e){super.connect(e),window.addEventListener("keydown",this._onKeyDown),window.addEventListener("keyup",this._onKeyUp),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerCancel),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="none"}disconnect(){window.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("keyup",this._onKeyUp),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerCancel),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction=""}dispose(){this.disconnect()}handleResize(){const e=this.domElement.getBoundingClientRect(),t=this.domElement.ownerDocument.documentElement;this.screen.left=e.left+window.pageXOffset-t.clientLeft,this.screen.top=e.top+window.pageYOffset-t.clientTop,this.screen.width=e.width,this.screen.height=e.height}update(){this._eye.subVectors(this.object.position,this.target),this.noRotate||this._rotateCamera(),this.noZoom||this._zoomCamera(),this.noPan||this._panCamera(),this.object.position.addVectors(this.target,this._eye),this.object.isPerspectiveCamera?(this._checkDistances(),this.object.lookAt(this.target),this._lastPosition.distanceToSquared(this.object.position)>A0&&(this.dispatchEvent($f),this._lastPosition.copy(this.object.position))):this.object.isOrthographicCamera?(this.object.lookAt(this.target),(this._lastPosition.distanceToSquared(this.object.position)>A0||this._lastZoom!==this.object.zoom)&&(this.dispatchEvent($f),this._lastPosition.copy(this.object.position),this._lastZoom=this.object.zoom)):console.warn("THREE.TrackballControls: Unsupported camera type.")}reset(){this.state=Rt.NONE,this.keyState=Rt.NONE,this.target.copy(this._target0),this.object.position.copy(this._position0),this.object.up.copy(this._up0),this.object.zoom=this._zoom0,this.object.updateProjectionMatrix(),this._eye.subVectors(this.object.position,this.target),this.object.lookAt(this.target),this.dispatchEvent($f),this._lastPosition.copy(this.object.position),this._lastZoom=this.object.zoom}_panCamera(){if(ps.copy(this._panEnd).sub(this._panStart),ps.lengthSq()){if(this.object.isOrthographicCamera){const e=(this.object.right-this.object.left)/this.object.zoom/this.domElement.clientWidth,t=(this.object.top-this.object.bottom)/this.object.zoom/this.domElement.clientWidth;ps.x*=e,ps.y*=t}ps.multiplyScalar(this._eye.length()*this.panSpeed),th.copy(this._eye).cross(this.object.up).setLength(ps.x),th.add(h3.copy(this.object.up).setLength(ps.y)),this.object.position.add(th),this.target.add(th),this.staticMoving?this._panStart.copy(this._panEnd):this._panStart.add(ps.subVectors(this._panEnd,this._panStart).multiplyScalar(this.dynamicDampingFactor))}}_rotateCamera(){ih.set(this._moveCurr.x-this._movePrev.x,this._moveCurr.y-this._movePrev.y,0);let e=ih.length();e?(this._eye.copy(this.object.position).sub(this.target),w0.copy(this._eye).normalize(),nh.copy(this.object.up).normalize(),qf.crossVectors(nh,w0).normalize(),nh.setLength(this._moveCurr.y-this._movePrev.y),qf.setLength(this._moveCurr.x-this._movePrev.x),ih.copy(nh.add(qf)),Xf.crossVectors(ih,this._eye).normalize(),e*=this.rotateSpeed,la.setFromAxisAngle(Xf,e),this._eye.applyQuaternion(la),this.object.up.applyQuaternion(la),this._lastAxis.copy(Xf),this._lastAngle=e):!this.staticMoving&&this._lastAngle&&(this._lastAngle*=Math.sqrt(1-this.dynamicDampingFactor),this._eye.copy(this.object.position).sub(this.target),la.setFromAxisAngle(this._lastAxis,this._lastAngle),this._eye.applyQuaternion(la),this.object.up.applyQuaternion(la)),this._movePrev.copy(this._moveCurr)}_zoomCamera(){let e;this.state===Rt.TOUCH_ZOOM_PAN?(e=this._touchZoomDistanceStart/this._touchZoomDistanceEnd,this._touchZoomDistanceStart=this._touchZoomDistanceEnd,this.object.isPerspectiveCamera?this._eye.multiplyScalar(e):this.object.isOrthographicCamera?(this.object.zoom=_h.clamp(this.object.zoom/e,this.minZoom,this.maxZoom),this._lastZoom!==this.object.zoom&&this.object.updateProjectionMatrix()):console.warn("THREE.TrackballControls: Unsupported camera type")):(e=1+(this._zoomEnd.y-this._zoomStart.y)*this.zoomSpeed,e!==1&&e>0&&(this.object.isPerspectiveCamera?this._eye.multiplyScalar(e):this.object.isOrthographicCamera?(this.object.zoom=_h.clamp(this.object.zoom/e,this.minZoom,this.maxZoom),this._lastZoom!==this.object.zoom&&this.object.updateProjectionMatrix()):console.warn("THREE.TrackballControls: Unsupported camera type")),this.staticMoving?this._zoomStart.copy(this._zoomEnd):this._zoomStart.y+=(this._zoomEnd.y-this._zoomStart.y)*this.dynamicDampingFactor)}_getMouseOnScreen(e,t){return eh.set((e-this.screen.left)/this.screen.width,(t-this.screen.top)/this.screen.height),eh}_getMouseOnCircle(e,t){return eh.set((e-this.screen.width*.5-this.screen.left)/(this.screen.width*.5),(this.screen.height+2*(this.screen.top-t))/this.screen.width),eh}_addPointer(e){this._pointers.push(e)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t].pointerId==e.pointerId){this._pointers.splice(t,1);return}}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new pe,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0].pointerId?this._pointers[1]:this._pointers[0];return this._pointerPositions[t.pointerId]}_checkDistances(){(!this.noZoom||!this.noPan)&&(this._eye.lengthSq()>this.maxDistance*this.maxDistance&&(this.object.position.addVectors(this.target,this._eye.setLength(this.maxDistance)),this._zoomStart.copy(this._zoomEnd)),this._eye.lengthSq()<this.minDistance*this.minDistance&&(this.object.position.addVectors(this.target,this._eye.setLength(this.minDistance)),this._zoomStart.copy(this._zoomEnd)))}}function f3(r){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(r.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),this._addPointer(r),r.pointerType==="touch"?this._onTouchStart(r):this._onMouseDown(r))}function p3(r){this.enabled!==!1&&(r.pointerType==="touch"?this._onTouchMove(r):this._onMouseMove(r))}function m3(r){this.enabled!==!1&&(r.pointerType==="touch"?this._onTouchEnd(r):this._onMouseUp(),this._removePointer(r),this._pointers.length===0&&(this.domElement.releasePointerCapture(r.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp)))}function g3(r){this._removePointer(r)}function _3(){this.enabled!==!1&&(this.keyState=Rt.NONE,window.addEventListener("keydown",this._onKeyDown))}function x3(r){this.enabled!==!1&&(window.removeEventListener("keydown",this._onKeyDown),this.keyState===Rt.NONE&&(r.code===this.keys[Rt.ROTATE]&&!this.noRotate?this.keyState=Rt.ROTATE:r.code===this.keys[Rt.ZOOM]&&!this.noZoom?this.keyState=Rt.ZOOM:r.code===this.keys[Rt.PAN]&&!this.noPan&&(this.keyState=Rt.PAN)))}function y3(r){let e;switch(r.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case Un.DOLLY:this.state=Rt.ZOOM;break;case Un.ROTATE:this.state=Rt.ROTATE;break;case Un.PAN:this.state=Rt.PAN;break;default:this.state=Rt.NONE}const t=this.keyState!==Rt.NONE?this.keyState:this.state;t===Rt.ROTATE&&!this.noRotate?(this._moveCurr.copy(this._getMouseOnCircle(r.pageX,r.pageY)),this._movePrev.copy(this._moveCurr)):t===Rt.ZOOM&&!this.noZoom?(this._zoomStart.copy(this._getMouseOnScreen(r.pageX,r.pageY)),this._zoomEnd.copy(this._zoomStart)):t===Rt.PAN&&!this.noPan&&(this._panStart.copy(this._getMouseOnScreen(r.pageX,r.pageY)),this._panEnd.copy(this._panStart)),this.dispatchEvent(eg)}function v3(r){const e=this.keyState!==Rt.NONE?this.keyState:this.state;e===Rt.ROTATE&&!this.noRotate?(this._movePrev.copy(this._moveCurr),this._moveCurr.copy(this._getMouseOnCircle(r.pageX,r.pageY))):e===Rt.ZOOM&&!this.noZoom?this._zoomEnd.copy(this._getMouseOnScreen(r.pageX,r.pageY)):e===Rt.PAN&&!this.noPan&&this._panEnd.copy(this._getMouseOnScreen(r.pageX,r.pageY))}function b3(){this.state=Rt.NONE,this.dispatchEvent(tg)}function S3(r){if(this.enabled!==!1&&this.noZoom!==!0){switch(r.preventDefault(),r.deltaMode){case 2:this._zoomStart.y-=r.deltaY*.025;break;case 1:this._zoomStart.y-=r.deltaY*.01;break;default:this._zoomStart.y-=r.deltaY*25e-5;break}this.dispatchEvent(eg),this.dispatchEvent(tg)}}function T3(r){this.enabled!==!1&&r.preventDefault()}function M3(r){switch(this._trackPointer(r),this._pointers.length){case 1:this.state=Rt.TOUCH_ROTATE,this._moveCurr.copy(this._getMouseOnCircle(this._pointers[0].pageX,this._pointers[0].pageY)),this._movePrev.copy(this._moveCurr);break;default:this.state=Rt.TOUCH_ZOOM_PAN;const e=this._pointers[0].pageX-this._pointers[1].pageX,t=this._pointers[0].pageY-this._pointers[1].pageY;this._touchZoomDistanceEnd=this._touchZoomDistanceStart=Math.sqrt(e*e+t*t);const n=(this._pointers[0].pageX+this._pointers[1].pageX)/2,i=(this._pointers[0].pageY+this._pointers[1].pageY)/2;this._panStart.copy(this._getMouseOnScreen(n,i)),this._panEnd.copy(this._panStart);break}this.dispatchEvent(eg)}function E3(r){switch(this._trackPointer(r),this._pointers.length){case 1:this._movePrev.copy(this._moveCurr),this._moveCurr.copy(this._getMouseOnCircle(r.pageX,r.pageY));break;default:const e=this._getSecondPointerPosition(r),t=r.pageX-e.x,n=r.pageY-e.y;this._touchZoomDistanceEnd=Math.sqrt(t*t+n*n);const i=(r.pageX+e.x)/2,s=(r.pageY+e.y)/2;this._panEnd.copy(this._getMouseOnScreen(i,s));break}}function A3(r){switch(this._pointers.length){case 0:this.state=Rt.NONE;break;case 1:this.state=Rt.TOUCH_ROTATE,this._moveCurr.copy(this._getMouseOnCircle(r.pageX,r.pageY)),this._movePrev.copy(this._moveCurr);break;case 2:this.state=Rt.TOUCH_ZOOM_PAN;for(let e=0;e<this._pointers.length;e++)if(this._pointers[e].pointerId!==r.pointerId){const t=this._pointerPositions[this._pointers[e].pointerId];this._moveCurr.copy(this._getMouseOnCircle(t.x,t.y)),this._movePrev.copy(this._moveCurr);break}break}this.dispatchEvent(tg)}const R0={type:"change"},ng={type:"start"},Xb={type:"end"},rh=new Bh,C0=new ur,w3=Math.cos(70*_h.DEG2RAD),bn=new P,si=2*Math.PI,Gt={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},jf=1e-6;class R3 extends kh{constructor(e,t=null){super(e,t),this.state=Gt.NONE,this.target=new P,this.cursor=new P,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:Un.ROTATE,MIDDLE:Un.DOLLY,RIGHT:Un.PAN},this.touches={ONE:$r.ROTATE,TWO:$r.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle="auto",this._domElementKeyEvents=null,this._lastPosition=new P,this._lastQuaternion=new Oi,this._lastTargetPosition=new P,this._quat=new Oi().setFromUnitVectors(e.up,new P(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new Qg,this._sphericalDelta=new Qg,this._scale=1,this._panOffset=new P,this._rotateStart=new pe,this._rotateEnd=new pe,this._rotateDelta=new pe,this._panStart=new pe,this._panEnd=new pe,this._panDelta=new pe,this._dollyStart=new pe,this._dollyEnd=new pe,this._dollyDelta=new pe,this._dollyDirection=new P,this._mouse=new pe,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=N3.bind(this),this._onPointerDown=C3.bind(this),this._onPointerUp=P3.bind(this),this._onContextMenu=O3.bind(this),this._onMouseWheel=U3.bind(this),this._onKeyDown=F3.bind(this),this._onTouchStart=I3.bind(this),this._onTouchMove=B3.bind(this),this._onMouseDown=D3.bind(this),this._onMouseMove=L3.bind(this),this._interceptControlDown=k3.bind(this),this._interceptControlUp=G3.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}set cursorStyle(e){this._cursorStyle=e,e==="grab"?this.domElement.style.cursor="grab":this.domElement.style.cursor="auto"}get cursorStyle(){return this._cursorStyle}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction=""}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(R0),this.update(),this.state=Gt.NONE}pan(e,t){this._pan(e,t),this.update()}dollyIn(e){this._dollyIn(e),this.update()}dollyOut(e){this._dollyOut(e),this.update()}rotateLeft(e){this._rotateLeft(e),this.update()}rotateUp(e){this._rotateUp(e),this.update()}update(e=null){const t=this.object.position;bn.copy(t).sub(this.target),bn.applyQuaternion(this._quat),this._spherical.setFromVector3(bn),this.autoRotate&&this.state===Gt.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let n=this.minAzimuthAngle,i=this.maxAzimuthAngle;isFinite(n)&&isFinite(i)&&(n<-Math.PI?n+=si:n>Math.PI&&(n-=si),i<-Math.PI?i+=si:i>Math.PI&&(i-=si),n<=i?this._spherical.theta=Math.max(n,Math.min(i,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+i)/2?Math.max(n,this._spherical.theta):Math.min(i,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let s=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const o=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),s=o!=this._spherical.radius}if(bn.setFromSpherical(this._spherical),bn.applyQuaternion(this._quatInverse),t.copy(this.target).add(bn),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let o=null;if(this.object.isPerspectiveCamera){const a=bn.length();o=this._clampDistance(a*this._scale);const l=a-o;this.object.position.addScaledVector(this._dollyDirection,l),this.object.updateMatrixWorld(),s=!!l}else if(this.object.isOrthographicCamera){const a=new P(this._mouse.x,this._mouse.y,0);a.unproject(this.object);const l=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),s=l!==this.object.zoom;const c=new P(this._mouse.x,this._mouse.y,0);c.unproject(this.object),this.object.position.sub(c).add(a),this.object.updateMatrixWorld(),o=bn.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;o!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(o).add(this.object.position):(rh.origin.copy(this.object.position),rh.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(rh.direction))<w3?this.object.lookAt(this.target):(C0.setFromNormalAndCoplanarPoint(this.object.up,this.target),rh.intersectPlane(C0,this.target))))}else if(this.object.isOrthographicCamera){const o=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),o!==this.object.zoom&&(this.object.updateProjectionMatrix(),s=!0)}return this._scale=1,this._performCursorZoom=!1,s||this._lastPosition.distanceToSquared(this.object.position)>jf||8*(1-this._lastQuaternion.dot(this.object.quaternion))>jf||this._lastTargetPosition.distanceToSquared(this.target)>jf?(this.dispatchEvent(R0),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?si/60*this.autoRotateSpeed*e:si/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){bn.setFromMatrixColumn(t,0),bn.multiplyScalar(-e),this._panOffset.add(bn)}_panUp(e,t){this.screenSpacePanning===!0?bn.setFromMatrixColumn(t,1):(bn.setFromMatrixColumn(t,0),bn.crossVectors(this.object.up,bn)),bn.multiplyScalar(e),this._panOffset.add(bn)}_pan(e,t){const n=this.domElement;if(this.object.isPerspectiveCamera){const i=this.object.position;bn.copy(i).sub(this.target);let s=bn.length();s*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*s/n.clientHeight,this.object.matrix),this._panUp(2*t*s/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const n=this.domElement.getBoundingClientRect(),i=e-n.left,s=t-n.top,o=n.width,a=n.height;this._mouse.x=i/o*2-1,this._mouse.y=-(s/a)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(si*this._rotateDelta.x/t.clientHeight),this._rotateUp(si*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(si*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-si*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(si*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-si*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._rotateStart.set(n,i)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._panStart.set(n,i)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,i=e.pageY-t.y,s=Math.sqrt(n*n+i*i);this._dollyStart.set(0,s)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const n=this._getSecondPointerPosition(e),i=.5*(e.pageX+n.x),s=.5*(e.pageY+n.y);this._rotateEnd.set(i,s)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(si*this._rotateDelta.x/t.clientHeight),this._rotateUp(si*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._panEnd.set(n,i)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,i=e.pageY-t.y,s=Math.sqrt(n*n+i*i);this._dollyEnd.set(0,s),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const o=(e.pageX+t.x)*.5,a=(e.pageY+t.y)*.5;this._updateZoomParameters(o,a)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new pe,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}}function C3(r){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(r.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(r)&&(this._addPointer(r),r.pointerType==="touch"?this._onTouchStart(r):this._onMouseDown(r),this._cursorStyle==="grab"&&(this.domElement.style.cursor="grabbing")))}function N3(r){this.enabled!==!1&&(r.pointerType==="touch"?this._onTouchMove(r):this._onMouseMove(r))}function P3(r){switch(this._removePointer(r),this._pointers.length){case 0:this.domElement.releasePointerCapture(r.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(Xb),this.state=Gt.NONE,this._cursorStyle==="grab"&&(this.domElement.style.cursor="grab");break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function D3(r){let e;switch(r.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case Un.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(r),this.state=Gt.DOLLY;break;case Un.ROTATE:if(r.ctrlKey||r.metaKey||r.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(r),this.state=Gt.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(r),this.state=Gt.ROTATE}break;case Un.PAN:if(r.ctrlKey||r.metaKey||r.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(r),this.state=Gt.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(r),this.state=Gt.PAN}break;default:this.state=Gt.NONE}this.state!==Gt.NONE&&this.dispatchEvent(ng)}function L3(r){switch(this.state){case Gt.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(r);break;case Gt.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(r);break;case Gt.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(r);break}}function U3(r){this.enabled===!1||this.enableZoom===!1||this.state!==Gt.NONE||(r.preventDefault(),this.dispatchEvent(ng),this._handleMouseWheel(this._customWheelEvent(r)),this.dispatchEvent(Xb))}function F3(r){this.enabled!==!1&&this._handleKeyDown(r)}function I3(r){switch(this._trackPointer(r),this._pointers.length){case 1:switch(this.touches.ONE){case $r.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(r),this.state=Gt.TOUCH_ROTATE;break;case $r.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(r),this.state=Gt.TOUCH_PAN;break;default:this.state=Gt.NONE}break;case 2:switch(this.touches.TWO){case $r.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(r),this.state=Gt.TOUCH_DOLLY_PAN;break;case $r.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(r),this.state=Gt.TOUCH_DOLLY_ROTATE;break;default:this.state=Gt.NONE}break;default:this.state=Gt.NONE}this.state!==Gt.NONE&&this.dispatchEvent(ng)}function B3(r){switch(this._trackPointer(r),this.state){case Gt.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(r),this.update();break;case Gt.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(r),this.update();break;case Gt.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(r),this.update();break;case Gt.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(r),this.update();break;default:this.state=Gt.NONE}}function O3(r){this.enabled!==!1&&r.preventDefault()}function k3(r){r.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function G3(r){r.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}const V3={type:"change"},N0=1e-6,P0=new Oi;class z3 extends kh{constructor(e,t=null){super(e,t),this.movementSpeed=1,this.rollSpeed=.005,this.dragToLook=!1,this.autoForward=!1,this._moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0},this._moveVector=new P(0,0,0),this._rotationVector=new P(0,0,0),this._lastQuaternion=new Oi,this._lastPosition=new P,this._status=0,this._onKeyDown=H3.bind(this),this._onKeyUp=W3.bind(this),this._onPointerMove=X3.bind(this),this._onPointerDown=$3.bind(this),this._onPointerUp=q3.bind(this),this._onPointerCancel=j3.bind(this),this._onContextMenu=Y3.bind(this),t!==null&&this.connect(t)}connect(e){super.connect(e),window.addEventListener("keydown",this._onKeyDown),window.addEventListener("keyup",this._onKeyUp),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.addEventListener("pointercancel",this._onPointerCancel),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="none"}disconnect(){window.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("keyup",this._onKeyUp),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerCancel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction=""}dispose(){this.disconnect()}update(e){if(this.enabled===!1)return;const t=this.object,n=e*this.movementSpeed,i=e*this.rollSpeed;t.translateX(this._moveVector.x*n),t.translateY(this._moveVector.y*n),t.translateZ(this._moveVector.z*n),P0.set(this._rotationVector.x*i,this._rotationVector.y*i,this._rotationVector.z*i,1).normalize(),t.quaternion.multiply(P0),(this._lastPosition.distanceToSquared(t.position)>N0||8*(1-this._lastQuaternion.dot(t.quaternion))>N0)&&(this.dispatchEvent(V3),this._lastQuaternion.copy(t.quaternion),this._lastPosition.copy(t.position))}_updateMovementVector(){const e=this._moveState.forward||this.autoForward&&!this._moveState.back?1:0;this._moveVector.x=-this._moveState.left+this._moveState.right,this._moveVector.y=-this._moveState.down+this._moveState.up,this._moveVector.z=-e+this._moveState.back}_updateRotationVector(){this._rotationVector.x=-this._moveState.pitchDown+this._moveState.pitchUp,this._rotationVector.y=-this._moveState.yawRight+this._moveState.yawLeft,this._rotationVector.z=-this._moveState.rollRight+this._moveState.rollLeft}_getContainerDimensions(){return this.domElement!=document?{size:[this.domElement.offsetWidth,this.domElement.offsetHeight],offset:[this.domElement.offsetLeft,this.domElement.offsetTop]}:{size:[window.innerWidth,window.innerHeight],offset:[0,0]}}}function H3(r){if(!(r.altKey||this.enabled===!1)){switch(r.code){case"ShiftLeft":case"ShiftRight":this.movementSpeedMultiplier=.1;break;case"KeyW":this._moveState.forward=1;break;case"KeyS":this._moveState.back=1;break;case"KeyA":this._moveState.left=1;break;case"KeyD":this._moveState.right=1;break;case"KeyR":this._moveState.up=1;break;case"KeyF":this._moveState.down=1;break;case"ArrowUp":this._moveState.pitchUp=1;break;case"ArrowDown":this._moveState.pitchDown=1;break;case"ArrowLeft":this._moveState.yawLeft=1;break;case"ArrowRight":this._moveState.yawRight=1;break;case"KeyQ":this._moveState.rollLeft=1;break;case"KeyE":this._moveState.rollRight=1;break}this._updateMovementVector(),this._updateRotationVector()}}function W3(r){if(this.enabled!==!1){switch(r.code){case"ShiftLeft":case"ShiftRight":this.movementSpeedMultiplier=1;break;case"KeyW":this._moveState.forward=0;break;case"KeyS":this._moveState.back=0;break;case"KeyA":this._moveState.left=0;break;case"KeyD":this._moveState.right=0;break;case"KeyR":this._moveState.up=0;break;case"KeyF":this._moveState.down=0;break;case"ArrowUp":this._moveState.pitchUp=0;break;case"ArrowDown":this._moveState.pitchDown=0;break;case"ArrowLeft":this._moveState.yawLeft=0;break;case"ArrowRight":this._moveState.yawRight=0;break;case"KeyQ":this._moveState.rollLeft=0;break;case"KeyE":this._moveState.rollRight=0;break}this._updateMovementVector(),this._updateRotationVector()}}function $3(r){if(this.enabled!==!1)if(this.dragToLook)this._status++;else{switch(r.button){case 0:this._moveState.forward=1;break;case 2:this._moveState.back=1;break}this._updateMovementVector()}}function X3(r){if(this.enabled!==!1&&(!this.dragToLook||this._status>0)){const e=this._getContainerDimensions(),t=e.size[0]/2,n=e.size[1]/2;this._moveState.yawLeft=-(r.pageX-e.offset[0]-t)/t,this._moveState.pitchDown=(r.pageY-e.offset[1]-n)/n,this._updateRotationVector()}}function q3(r){if(this.enabled!==!1){if(this.dragToLook)this._status--,this._moveState.yawLeft=this._moveState.pitchDown=0;else{switch(r.button){case 0:this._moveState.forward=0;break;case 2:this._moveState.back=0;break}this._updateMovementVector()}this._updateRotationVector()}}function j3(){this.enabled!==!1&&(this.dragToLook?(this._status=0,this._moveState.yawLeft=this._moveState.pitchDown=0):(this._moveState.forward=0,this._moveState.back=0,this._updateMovementVector()),this._updateRotationVector())}function Y3(r){this.enabled!==!1&&r.preventDefault()}const K3={name:"CopyShader",uniforms:{tDiffuse:{value:null},opacity:{value:1}},vertexShader:`
5060
5060
 
5061
5061
  varying vec2 vUv;
5062
5062
 
@@ -5079,7 +5079,7 @@ var<${n}> ${e} : ${o};`}}class ZB{constructor(e){this.backend=e}getCurrentDepthS
5079
5079
  gl_FragColor = opacity * texel;
5080
5080
 
5081
5081
 
5082
- }`};class nd{constructor(){this.isPass=!0,this.enabled=!0,this.needsSwap=!0,this.clear=!1,this.renderToScreen=!1}setSize(){}render(){console.error("THREE.Pass: .render() must be implemented in derived pass.")}dispose(){}}const Z3=new ol(-1,1,1,-1,0,1);class Q3 extends An{constructor(){super(),this.setAttribute("position",new sn([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new sn([0,2,0,0,2,0],2))}}const J3=new Q3;class eO{constructor(e){this._mesh=new _n(J3,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,Z3)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}}class tO extends nd{constructor(e,t="tDiffuse"){super(),this.textureID=t,this.uniforms=null,this.material=null,e instanceof ki?(this.uniforms=e.uniforms,this.material=e):e&&(this.uniforms=ly.clone(e.uniforms),this.material=new ki({name:e.name!==void 0?e.name:"unspecified",defines:Object.assign({},e.defines),uniforms:this.uniforms,vertexShader:e.vertexShader,fragmentShader:e.fragmentShader})),this._fsQuad=new eO(this.material)}render(e,t,n){this.uniforms[this.textureID]&&(this.uniforms[this.textureID].value=n.texture),this._fsQuad.material=this.material,this.renderToScreen?(e.setRenderTarget(null),this._fsQuad.render(e)):(e.setRenderTarget(t),this.clear&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),this._fsQuad.render(e))}dispose(){this.material.dispose(),this._fsQuad.dispose()}}class D0 extends nd{constructor(e,t){super(),this.scene=e,this.camera=t,this.clear=!0,this.needsSwap=!1,this.inverse=!1}render(e,t,n){const i=e.getContext(),s=e.state;s.buffers.color.setMask(!1),s.buffers.depth.setMask(!1),s.buffers.color.setLocked(!0),s.buffers.depth.setLocked(!0);let o,a;this.inverse?(o=0,a=1):(o=1,a=0),s.buffers.stencil.setTest(!0),s.buffers.stencil.setOp(i.REPLACE,i.REPLACE,i.REPLACE),s.buffers.stencil.setFunc(i.ALWAYS,o,4294967295),s.buffers.stencil.setClear(a),s.buffers.stencil.setLocked(!0),e.setRenderTarget(n),this.clear&&e.clear(),e.render(this.scene,this.camera),e.setRenderTarget(t),this.clear&&e.clear(),e.render(this.scene,this.camera),s.buffers.color.setLocked(!1),s.buffers.depth.setLocked(!1),s.buffers.color.setMask(!0),s.buffers.depth.setMask(!0),s.buffers.stencil.setLocked(!1),s.buffers.stencil.setFunc(i.EQUAL,1,4294967295),s.buffers.stencil.setOp(i.KEEP,i.KEEP,i.KEEP),s.buffers.stencil.setLocked(!0)}}class nO extends nd{constructor(){super(),this.needsSwap=!1}render(e){e.state.buffers.stencil.setLocked(!1),e.state.buffers.stencil.setTest(!1)}}class iO{constructor(e,t){if(this.renderer=e,this._pixelRatio=e.getPixelRatio(),t===void 0){const n=e.getSize(new pe);this._width=n.width,this._height=n.height,t=new Yi(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:tn}),t.texture.name="EffectComposer.rt1"}else this._width=t.width,this._height=t.height;this.renderTarget1=t,this.renderTarget2=t.clone(),this.renderTarget2.texture.name="EffectComposer.rt2",this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2,this.renderToScreen=!0,this.passes=[],this.copyPass=new tO(K3),this.copyPass.material.blending=Pn,this.timer=new gy}swapBuffers(){const e=this.readBuffer;this.readBuffer=this.writeBuffer,this.writeBuffer=e}addPass(e){this.passes.push(e),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}insertPass(e,t){this.passes.splice(t,0,e),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}removePass(e){const t=this.passes.indexOf(e);t!==-1&&this.passes.splice(t,1)}isLastEnabledPass(e){for(let t=e+1;t<this.passes.length;t++)if(this.passes[t].enabled)return!1;return!0}render(e){this.timer.update(),e===void 0&&(e=this.timer.getDelta());const t=this.renderer.getRenderTarget();let n=!1;for(let i=0,s=this.passes.length;i<s;i++){const o=this.passes[i];if(o.enabled!==!1){if(o.renderToScreen=this.renderToScreen&&this.isLastEnabledPass(i),o.render(this.renderer,this.writeBuffer,this.readBuffer,e,n),o.needsSwap){if(n){const a=this.renderer.getContext(),l=this.renderer.state.buffers.stencil;l.setFunc(a.NOTEQUAL,1,4294967295),this.copyPass.render(this.renderer,this.writeBuffer,this.readBuffer,e),l.setFunc(a.EQUAL,1,4294967295)}this.swapBuffers()}D0!==void 0&&(o instanceof D0?n=!0:o instanceof nO&&(n=!1))}}this.renderer.setRenderTarget(t)}reset(e){if(e===void 0){const t=this.renderer.getSize(new pe);this._pixelRatio=this.renderer.getPixelRatio(),this._width=t.width,this._height=t.height,e=this.renderTarget1.clone(),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.renderTarget1=e,this.renderTarget2=e.clone(),this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2}setSize(e,t){this._width=e,this._height=t;const n=this._width*this._pixelRatio,i=this._height*this._pixelRatio;this.renderTarget1.setSize(n,i),this.renderTarget2.setSize(n,i);for(let s=0;s<this.passes.length;s++)this.passes[s].setSize(n,i)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.copyPass.dispose()}}class rO extends nd{constructor(e,t,n=null,i=null,s=null){super(),this.scene=e,this.camera=t,this.overrideMaterial=n,this.clearColor=i,this.clearAlpha=s,this.clear=!0,this.clearDepth=!1,this.needsSwap=!1,this.isRenderPass=!0,this._oldClearColor=new We}render(e,t,n){const i=e.autoClear;e.autoClear=!1;let s,o;this.overrideMaterial!==null&&(o=this.scene.overrideMaterial,this.scene.overrideMaterial=this.overrideMaterial),this.clearColor!==null&&(e.getClearColor(this._oldClearColor),e.setClearColor(this.clearColor,e.getClearAlpha())),this.clearAlpha!==null&&(s=e.getClearAlpha(),e.setClearAlpha(this.clearAlpha)),this.clearDepth==!0&&e.clearDepth(),e.setRenderTarget(this.renderToScreen?null:n),this.clear===!0&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),e.render(this.scene,this.camera),this.clearColor!==null&&e.setClearColor(this._oldClearColor),this.clearAlpha!==null&&e.setClearAlpha(s),this.overrideMaterial!==null&&(this.scene.overrideMaterial=o),e.autoClear=i}}function pi(){return pi=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)({}).hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r},pi.apply(null,arguments)}function sO(r){if(r===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function Cc(r,e){return Cc=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},Cc(r,e)}function oO(r,e){r.prototype=Object.create(e.prototype),r.prototype.constructor=r,Cc(r,e)}function Pp(r){return Pp=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Pp(r)}function aO(r){try{return Function.toString.call(r).indexOf("[native code]")!==-1}catch{return typeof r=="function"}}function qb(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(qb=function(){return!!r})()}function lO(r,e,t){if(qb())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var i=new(r.bind.apply(r,n));return t&&Cc(i,t.prototype),i}function Dp(r){var e=typeof Map=="function"?new Map:void 0;return Dp=function(n){if(n===null||!aO(n))return n;if(typeof n!="function")throw new TypeError("Super expression must either be null or a function");if(e!==void 0){if(e.has(n))return e.get(n);e.set(n,i)}function i(){return lO(n,arguments,Pp(this).constructor)}return i.prototype=Object.create(n.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),Cc(i,n)},Dp(r)}var vr=(function(r){oO(e,r);function e(t){var n;return n=r.call(this,"An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#"+t+" for more information.")||this,sO(n)}return e})(Dp(Error));function Yf(r){return Math.round(r*255)}function cO(r,e,t){return Yf(r)+","+Yf(e)+","+Yf(t)}function Lh(r,e,t,n){if(n===void 0&&(n=cO),e===0)return n(t,t,t);var i=(r%360+360)%360/60,s=(1-Math.abs(2*t-1))*e,o=s*(1-Math.abs(i%2-1)),a=0,l=0,c=0;i>=0&&i<1?(a=s,l=o):i>=1&&i<2?(a=o,l=s):i>=2&&i<3?(l=s,c=o):i>=3&&i<4?(l=o,c=s):i>=4&&i<5?(a=o,c=s):i>=5&&i<6&&(a=s,c=o);var u=t-s/2,h=a+u,d=l+u,f=c+u;return n(h,d,f)}var L0={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"00ffff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"0000ff",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"00ffff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"ff00ff",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"639",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"};function uO(r){if(typeof r!="string")return r;var e=r.toLowerCase();return L0[e]?"#"+L0[e]:r}var hO=/^#[a-fA-F0-9]{6}$/,dO=/^#[a-fA-F0-9]{8}$/,fO=/^#[a-fA-F0-9]{3}$/,pO=/^#[a-fA-F0-9]{4}$/,Kf=/^rgb\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*\)$/i,mO=/^rgb(?:a)?\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i,gO=/^hsl\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*\)$/i,_O=/^hsl(?:a)?\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i;function tl(r){if(typeof r!="string")throw new vr(3);var e=uO(r);if(e.match(hO))return{red:parseInt(""+e[1]+e[2],16),green:parseInt(""+e[3]+e[4],16),blue:parseInt(""+e[5]+e[6],16)};if(e.match(dO)){var t=parseFloat((parseInt(""+e[7]+e[8],16)/255).toFixed(2));return{red:parseInt(""+e[1]+e[2],16),green:parseInt(""+e[3]+e[4],16),blue:parseInt(""+e[5]+e[6],16),alpha:t}}if(e.match(fO))return{red:parseInt(""+e[1]+e[1],16),green:parseInt(""+e[2]+e[2],16),blue:parseInt(""+e[3]+e[3],16)};if(e.match(pO)){var n=parseFloat((parseInt(""+e[4]+e[4],16)/255).toFixed(2));return{red:parseInt(""+e[1]+e[1],16),green:parseInt(""+e[2]+e[2],16),blue:parseInt(""+e[3]+e[3],16),alpha:n}}var i=Kf.exec(e);if(i)return{red:parseInt(""+i[1],10),green:parseInt(""+i[2],10),blue:parseInt(""+i[3],10)};var s=mO.exec(e.substring(0,50));if(s)return{red:parseInt(""+s[1],10),green:parseInt(""+s[2],10),blue:parseInt(""+s[3],10),alpha:parseFloat(""+s[4])>1?parseFloat(""+s[4])/100:parseFloat(""+s[4])};var o=gO.exec(e);if(o){var a=parseInt(""+o[1],10),l=parseInt(""+o[2],10)/100,c=parseInt(""+o[3],10)/100,u="rgb("+Lh(a,l,c)+")",h=Kf.exec(u);if(!h)throw new vr(4,e,u);return{red:parseInt(""+h[1],10),green:parseInt(""+h[2],10),blue:parseInt(""+h[3],10)}}var d=_O.exec(e.substring(0,50));if(d){var f=parseInt(""+d[1],10),p=parseInt(""+d[2],10)/100,g=parseInt(""+d[3],10)/100,m="rgb("+Lh(f,p,g)+")",_=Kf.exec(m);if(!_)throw new vr(4,e,m);return{red:parseInt(""+_[1],10),green:parseInt(""+_[2],10),blue:parseInt(""+_[3],10),alpha:parseFloat(""+d[4])>1?parseFloat(""+d[4])/100:parseFloat(""+d[4])}}throw new vr(5)}function xO(r){var e=r.red/255,t=r.green/255,n=r.blue/255,i=Math.max(e,t,n),s=Math.min(e,t,n),o=(i+s)/2;if(i===s)return r.alpha!==void 0?{hue:0,saturation:0,lightness:o,alpha:r.alpha}:{hue:0,saturation:0,lightness:o};var a,l=i-s,c=o>.5?l/(2-i-s):l/(i+s);switch(i){case e:a=(t-n)/l+(t<n?6:0);break;case t:a=(n-e)/l+2;break;default:a=(e-t)/l+4;break}return a*=60,r.alpha!==void 0?{hue:a,saturation:c,lightness:o,alpha:r.alpha}:{hue:a,saturation:c,lightness:o}}function zs(r){return xO(tl(r))}var yO=function(e){return e.length===7&&e[1]===e[2]&&e[3]===e[4]&&e[5]===e[6]?"#"+e[1]+e[3]+e[5]:e},Lp=yO;function no(r){var e=r.toString(16);return e.length===1?"0"+e:e}function Zf(r){return no(Math.round(r*255))}function vO(r,e,t){return Lp("#"+Zf(r)+Zf(e)+Zf(t))}function jb(r,e,t){return Lh(r,e,t,vO)}function bO(r,e,t){if(typeof r=="object"&&e===void 0&&t===void 0)return jb(r.hue,r.saturation,r.lightness);throw new vr(1)}function SO(r,e,t,n){if(typeof r=="object"&&e===void 0&&t===void 0&&n===void 0)return r.alpha>=1?jb(r.hue,r.saturation,r.lightness):"rgba("+Lh(r.hue,r.saturation,r.lightness)+","+r.alpha+")";throw new vr(2)}function Yb(r,e,t){if(typeof r=="number"&&typeof e=="number"&&typeof t=="number")return Lp("#"+no(r)+no(e)+no(t));if(typeof r=="object"&&e===void 0&&t===void 0)return Lp("#"+no(r.red)+no(r.green)+no(r.blue));throw new vr(6)}function id(r,e,t,n){if(typeof r=="object"&&e===void 0&&t===void 0&&n===void 0)return r.alpha>=1?Yb(r.red,r.green,r.blue):"rgba("+r.red+","+r.green+","+r.blue+","+r.alpha+")";throw new vr(7)}var TO=function(e){return typeof e.red=="number"&&typeof e.green=="number"&&typeof e.blue=="number"&&(typeof e.alpha!="number"||typeof e.alpha>"u")},MO=function(e){return typeof e.red=="number"&&typeof e.green=="number"&&typeof e.blue=="number"&&typeof e.alpha=="number"},EO=function(e){return typeof e.hue=="number"&&typeof e.saturation=="number"&&typeof e.lightness=="number"&&(typeof e.alpha!="number"||typeof e.alpha>"u")},AO=function(e){return typeof e.hue=="number"&&typeof e.saturation=="number"&&typeof e.lightness=="number"&&typeof e.alpha=="number"};function Hs(r){if(typeof r!="object")throw new vr(8);if(MO(r))return id(r);if(TO(r))return Yb(r);if(AO(r))return SO(r);if(EO(r))return bO(r);throw new vr(8)}function Kb(r,e,t){return function(){var i=t.concat(Array.prototype.slice.call(arguments));return i.length>=e?r.apply(this,i):Kb(r,e,i)}}function Ei(r){return Kb(r,r.length,[])}function wO(r,e){if(e==="transparent")return e;var t=zs(e);return Hs(pi({},t,{hue:t.hue+parseFloat(r)}))}Ei(wO);function _l(r,e,t){return Math.max(r,Math.min(e,t))}function RO(r,e){if(e==="transparent")return e;var t=zs(e);return Hs(pi({},t,{lightness:_l(0,1,t.lightness-parseFloat(r))}))}Ei(RO);function CO(r,e){if(e==="transparent")return e;var t=zs(e);return Hs(pi({},t,{saturation:_l(0,1,t.saturation-parseFloat(r))}))}Ei(CO);function NO(r,e){if(e==="transparent")return e;var t=zs(e);return Hs(pi({},t,{lightness:_l(0,1,t.lightness+parseFloat(r))}))}Ei(NO);function PO(r,e,t){if(e==="transparent")return t;if(t==="transparent")return e;if(r===0)return t;var n=tl(e),i=pi({},n,{alpha:typeof n.alpha=="number"?n.alpha:1}),s=tl(t),o=pi({},s,{alpha:typeof s.alpha=="number"?s.alpha:1}),a=i.alpha-o.alpha,l=parseFloat(r)*2-1,c=l*a===-1?l:l+a,u=1+l*a,h=(c/u+1)/2,d=1-h,f={red:Math.floor(i.red*h+o.red*d),green:Math.floor(i.green*h+o.green*d),blue:Math.floor(i.blue*h+o.blue*d),alpha:i.alpha*parseFloat(r)+o.alpha*(1-parseFloat(r))};return id(f)}var DO=Ei(PO),Zb=DO;function LO(r,e){if(e==="transparent")return e;var t=tl(e),n=typeof t.alpha=="number"?t.alpha:1,i=pi({},t,{alpha:_l(0,1,(n*100+parseFloat(r)*100)/100)});return id(i)}var UO=Ei(LO),FO=UO;function IO(r,e){if(e==="transparent")return e;var t=zs(e);return Hs(pi({},t,{saturation:_l(0,1,t.saturation+parseFloat(r))}))}Ei(IO);function BO(r,e){return e==="transparent"?e:Hs(pi({},zs(e),{hue:parseFloat(r)}))}Ei(BO);function OO(r,e){return e==="transparent"?e:Hs(pi({},zs(e),{lightness:parseFloat(r)}))}Ei(OO);function kO(r,e){return e==="transparent"?e:Hs(pi({},zs(e),{saturation:parseFloat(r)}))}Ei(kO);function GO(r,e){return e==="transparent"?e:Zb(parseFloat(r),"rgb(0, 0, 0)",e)}Ei(GO);function VO(r,e){return e==="transparent"?e:Zb(parseFloat(r),"rgb(255, 255, 255)",e)}Ei(VO);function zO(r,e){if(e==="transparent")return e;var t=tl(e),n=typeof t.alpha=="number"?t.alpha:1,i=pi({},t,{alpha:_l(0,1,+(n*100-parseFloat(r)*100).toFixed(2)/100)});return id(i)}Ei(zO);function HO(r,e){e===void 0&&(e={});var t=e.insertAt;if(!(typeof document>"u")){var n=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css",t==="top"&&n.firstChild?n.insertBefore(i,n.firstChild):n.appendChild(i),i.styleSheet?i.styleSheet.cssText=r:i.appendChild(document.createTextNode(r))}}var WO=`.scene-nav-info {
5082
+ }`};class nd{constructor(){this.isPass=!0,this.enabled=!0,this.needsSwap=!0,this.clear=!1,this.renderToScreen=!1}setSize(){}render(){console.error("THREE.Pass: .render() must be implemented in derived pass.")}dispose(){}}const Z3=new ol(-1,1,1,-1,0,1);class Q3 extends An{constructor(){super(),this.setAttribute("position",new sn([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new sn([0,2,0,0,2,0],2))}}const J3=new Q3;class eO{constructor(e){this._mesh=new _n(J3,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,Z3)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}}class tO extends nd{constructor(e,t="tDiffuse"){super(),this.textureID=t,this.uniforms=null,this.material=null,e instanceof ki?(this.uniforms=e.uniforms,this.material=e):e&&(this.uniforms=ly.clone(e.uniforms),this.material=new ki({name:e.name!==void 0?e.name:"unspecified",defines:Object.assign({},e.defines),uniforms:this.uniforms,vertexShader:e.vertexShader,fragmentShader:e.fragmentShader})),this._fsQuad=new eO(this.material)}render(e,t,n){this.uniforms[this.textureID]&&(this.uniforms[this.textureID].value=n.texture),this._fsQuad.material=this.material,this.renderToScreen?(e.setRenderTarget(null),this._fsQuad.render(e)):(e.setRenderTarget(t),this.clear&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),this._fsQuad.render(e))}dispose(){this.material.dispose(),this._fsQuad.dispose()}}class D0 extends nd{constructor(e,t){super(),this.scene=e,this.camera=t,this.clear=!0,this.needsSwap=!1,this.inverse=!1}render(e,t,n){const i=e.getContext(),s=e.state;s.buffers.color.setMask(!1),s.buffers.depth.setMask(!1),s.buffers.color.setLocked(!0),s.buffers.depth.setLocked(!0);let o,a;this.inverse?(o=0,a=1):(o=1,a=0),s.buffers.stencil.setTest(!0),s.buffers.stencil.setOp(i.REPLACE,i.REPLACE,i.REPLACE),s.buffers.stencil.setFunc(i.ALWAYS,o,4294967295),s.buffers.stencil.setClear(a),s.buffers.stencil.setLocked(!0),e.setRenderTarget(n),this.clear&&e.clear(),e.render(this.scene,this.camera),e.setRenderTarget(t),this.clear&&e.clear(),e.render(this.scene,this.camera),s.buffers.color.setLocked(!1),s.buffers.depth.setLocked(!1),s.buffers.color.setMask(!0),s.buffers.depth.setMask(!0),s.buffers.stencil.setLocked(!1),s.buffers.stencil.setFunc(i.EQUAL,1,4294967295),s.buffers.stencil.setOp(i.KEEP,i.KEEP,i.KEEP),s.buffers.stencil.setLocked(!0)}}class nO extends nd{constructor(){super(),this.needsSwap=!1}render(e){e.state.buffers.stencil.setLocked(!1),e.state.buffers.stencil.setTest(!1)}}class iO{constructor(e,t){if(this.renderer=e,this._pixelRatio=e.getPixelRatio(),t===void 0){const n=e.getSize(new pe);this._width=n.width,this._height=n.height,t=new Yi(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:tn}),t.texture.name="EffectComposer.rt1"}else this._width=t.width,this._height=t.height;this.renderTarget1=t,this.renderTarget2=t.clone(),this.renderTarget2.texture.name="EffectComposer.rt2",this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2,this.renderToScreen=!0,this.passes=[],this.copyPass=new tO(K3),this.copyPass.material.blending=Pn,this.timer=new gy}swapBuffers(){const e=this.readBuffer;this.readBuffer=this.writeBuffer,this.writeBuffer=e}addPass(e){this.passes.push(e),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}insertPass(e,t){this.passes.splice(t,0,e),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}removePass(e){const t=this.passes.indexOf(e);t!==-1&&this.passes.splice(t,1)}isLastEnabledPass(e){for(let t=e+1;t<this.passes.length;t++)if(this.passes[t].enabled)return!1;return!0}render(e){this.timer.update(),e===void 0&&(e=this.timer.getDelta());const t=this.renderer.getRenderTarget();let n=!1;for(let i=0,s=this.passes.length;i<s;i++){const o=this.passes[i];if(o.enabled!==!1){if(o.renderToScreen=this.renderToScreen&&this.isLastEnabledPass(i),o.render(this.renderer,this.writeBuffer,this.readBuffer,e,n),o.needsSwap){if(n){const a=this.renderer.getContext(),l=this.renderer.state.buffers.stencil;l.setFunc(a.NOTEQUAL,1,4294967295),this.copyPass.render(this.renderer,this.writeBuffer,this.readBuffer,e),l.setFunc(a.EQUAL,1,4294967295)}this.swapBuffers()}D0!==void 0&&(o instanceof D0?n=!0:o instanceof nO&&(n=!1))}}this.renderer.setRenderTarget(t)}reset(e){if(e===void 0){const t=this.renderer.getSize(new pe);this._pixelRatio=this.renderer.getPixelRatio(),this._width=t.width,this._height=t.height,e=this.renderTarget1.clone(),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.renderTarget1=e,this.renderTarget2=e.clone(),this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2}setSize(e,t){this._width=e,this._height=t;const n=this._width*this._pixelRatio,i=this._height*this._pixelRatio;this.renderTarget1.setSize(n,i),this.renderTarget2.setSize(n,i);for(let s=0;s<this.passes.length;s++)this.passes[s].setSize(n,i)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.copyPass.dispose()}}class rO extends nd{constructor(e,t,n=null,i=null,s=null){super(),this.scene=e,this.camera=t,this.overrideMaterial=n,this.clearColor=i,this.clearAlpha=s,this.clear=!0,this.clearDepth=!1,this.needsSwap=!1,this.isRenderPass=!0,this._oldClearColor=new We}render(e,t,n){const i=e.autoClear;e.autoClear=!1;let s,o;this.overrideMaterial!==null&&(o=this.scene.overrideMaterial,this.scene.overrideMaterial=this.overrideMaterial),this.clearColor!==null&&(e.getClearColor(this._oldClearColor),e.setClearColor(this.clearColor,e.getClearAlpha())),this.clearAlpha!==null&&(s=e.getClearAlpha(),e.setClearAlpha(this.clearAlpha)),this.clearDepth==!0&&e.clearDepth(),e.setRenderTarget(this.renderToScreen?null:n),this.clear===!0&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),e.render(this.scene,this.camera),this.clearColor!==null&&e.setClearColor(this._oldClearColor),this.clearAlpha!==null&&e.setClearAlpha(s),this.overrideMaterial!==null&&(this.scene.overrideMaterial=o),e.autoClear=i}}function sO(r){if(r===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function Cc(r,e){return Cc=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},Cc(r,e)}function oO(r,e){r.prototype=Object.create(e.prototype),r.prototype.constructor=r,Cc(r,e)}function Pp(r){return Pp=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Pp(r)}function aO(r){try{return Function.toString.call(r).indexOf("[native code]")!==-1}catch{return typeof r=="function"}}function qb(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(qb=function(){return!!r})()}function lO(r,e,t){if(qb())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var i=new(r.bind.apply(r,n));return t&&Cc(i,t.prototype),i}function Dp(r){var e=typeof Map=="function"?new Map:void 0;return Dp=function(n){if(n===null||!aO(n))return n;if(typeof n!="function")throw new TypeError("Super expression must either be null or a function");if(e!==void 0){if(e.has(n))return e.get(n);e.set(n,i)}function i(){return lO(n,arguments,Pp(this).constructor)}return i.prototype=Object.create(n.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),Cc(i,n)},Dp(r)}var vr=(function(r){oO(e,r);function e(t){var n;return n=r.call(this,"An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#"+t+" for more information.")||this,sO(n)}return e})(Dp(Error));function Yf(r){return Math.round(r*255)}function cO(r,e,t){return Yf(r)+","+Yf(e)+","+Yf(t)}function Lh(r,e,t,n){if(n===void 0&&(n=cO),e===0)return n(t,t,t);var i=(r%360+360)%360/60,s=(1-Math.abs(2*t-1))*e,o=s*(1-Math.abs(i%2-1)),a=0,l=0,c=0;i>=0&&i<1?(a=s,l=o):i>=1&&i<2?(a=o,l=s):i>=2&&i<3?(l=s,c=o):i>=3&&i<4?(l=o,c=s):i>=4&&i<5?(a=o,c=s):i>=5&&i<6&&(a=s,c=o);var u=t-s/2,h=a+u,d=l+u,f=c+u;return n(h,d,f)}var L0={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"00ffff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"0000ff",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"00ffff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"ff00ff",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"639",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"};function uO(r){if(typeof r!="string")return r;var e=r.toLowerCase();return L0[e]?"#"+L0[e]:r}var hO=/^#[a-fA-F0-9]{6}$/,dO=/^#[a-fA-F0-9]{8}$/,fO=/^#[a-fA-F0-9]{3}$/,pO=/^#[a-fA-F0-9]{4}$/,Kf=/^rgb\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*\)$/i,mO=/^rgb(?:a)?\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i,gO=/^hsl\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*\)$/i,_O=/^hsl(?:a)?\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i;function tl(r){if(typeof r!="string")throw new vr(3);var e=uO(r);if(e.match(hO))return{red:parseInt(""+e[1]+e[2],16),green:parseInt(""+e[3]+e[4],16),blue:parseInt(""+e[5]+e[6],16)};if(e.match(dO)){var t=parseFloat((parseInt(""+e[7]+e[8],16)/255).toFixed(2));return{red:parseInt(""+e[1]+e[2],16),green:parseInt(""+e[3]+e[4],16),blue:parseInt(""+e[5]+e[6],16),alpha:t}}if(e.match(fO))return{red:parseInt(""+e[1]+e[1],16),green:parseInt(""+e[2]+e[2],16),blue:parseInt(""+e[3]+e[3],16)};if(e.match(pO)){var n=parseFloat((parseInt(""+e[4]+e[4],16)/255).toFixed(2));return{red:parseInt(""+e[1]+e[1],16),green:parseInt(""+e[2]+e[2],16),blue:parseInt(""+e[3]+e[3],16),alpha:n}}var i=Kf.exec(e);if(i)return{red:parseInt(""+i[1],10),green:parseInt(""+i[2],10),blue:parseInt(""+i[3],10)};var s=mO.exec(e.substring(0,50));if(s)return{red:parseInt(""+s[1],10),green:parseInt(""+s[2],10),blue:parseInt(""+s[3],10),alpha:parseFloat(""+s[4])>1?parseFloat(""+s[4])/100:parseFloat(""+s[4])};var o=gO.exec(e);if(o){var a=parseInt(""+o[1],10),l=parseInt(""+o[2],10)/100,c=parseInt(""+o[3],10)/100,u="rgb("+Lh(a,l,c)+")",h=Kf.exec(u);if(!h)throw new vr(4,e,u);return{red:parseInt(""+h[1],10),green:parseInt(""+h[2],10),blue:parseInt(""+h[3],10)}}var d=_O.exec(e.substring(0,50));if(d){var f=parseInt(""+d[1],10),p=parseInt(""+d[2],10)/100,g=parseInt(""+d[3],10)/100,m="rgb("+Lh(f,p,g)+")",_=Kf.exec(m);if(!_)throw new vr(4,e,m);return{red:parseInt(""+_[1],10),green:parseInt(""+_[2],10),blue:parseInt(""+_[3],10),alpha:parseFloat(""+d[4])>1?parseFloat(""+d[4])/100:parseFloat(""+d[4])}}throw new vr(5)}function xO(r){var e=r.red/255,t=r.green/255,n=r.blue/255,i=Math.max(e,t,n),s=Math.min(e,t,n),o=(i+s)/2;if(i===s)return r.alpha!==void 0?{hue:0,saturation:0,lightness:o,alpha:r.alpha}:{hue:0,saturation:0,lightness:o};var a,l=i-s,c=o>.5?l/(2-i-s):l/(i+s);switch(i){case e:a=(t-n)/l+(t<n?6:0);break;case t:a=(n-e)/l+2;break;default:a=(e-t)/l+4;break}return a*=60,r.alpha!==void 0?{hue:a,saturation:c,lightness:o,alpha:r.alpha}:{hue:a,saturation:c,lightness:o}}function zs(r){return xO(tl(r))}var yO=function(e){return e.length===7&&e[1]===e[2]&&e[3]===e[4]&&e[5]===e[6]?"#"+e[1]+e[3]+e[5]:e},Lp=yO;function no(r){var e=r.toString(16);return e.length===1?"0"+e:e}function Zf(r){return no(Math.round(r*255))}function vO(r,e,t){return Lp("#"+Zf(r)+Zf(e)+Zf(t))}function jb(r,e,t){return Lh(r,e,t,vO)}function bO(r,e,t){if(typeof r=="object"&&e===void 0&&t===void 0)return jb(r.hue,r.saturation,r.lightness);throw new vr(1)}function SO(r,e,t,n){if(typeof r=="object"&&e===void 0&&t===void 0&&n===void 0)return r.alpha>=1?jb(r.hue,r.saturation,r.lightness):"rgba("+Lh(r.hue,r.saturation,r.lightness)+","+r.alpha+")";throw new vr(2)}function Yb(r,e,t){if(typeof r=="number"&&typeof e=="number"&&typeof t=="number")return Lp("#"+no(r)+no(e)+no(t));if(typeof r=="object"&&e===void 0&&t===void 0)return Lp("#"+no(r.red)+no(r.green)+no(r.blue));throw new vr(6)}function id(r,e,t,n){if(typeof r=="object"&&e===void 0&&t===void 0&&n===void 0)return r.alpha>=1?Yb(r.red,r.green,r.blue):"rgba("+r.red+","+r.green+","+r.blue+","+r.alpha+")";throw new vr(7)}var TO=function(e){return typeof e.red=="number"&&typeof e.green=="number"&&typeof e.blue=="number"&&(typeof e.alpha!="number"||typeof e.alpha>"u")},MO=function(e){return typeof e.red=="number"&&typeof e.green=="number"&&typeof e.blue=="number"&&typeof e.alpha=="number"},EO=function(e){return typeof e.hue=="number"&&typeof e.saturation=="number"&&typeof e.lightness=="number"&&(typeof e.alpha!="number"||typeof e.alpha>"u")},AO=function(e){return typeof e.hue=="number"&&typeof e.saturation=="number"&&typeof e.lightness=="number"&&typeof e.alpha=="number"};function Hs(r){if(typeof r!="object")throw new vr(8);if(MO(r))return id(r);if(TO(r))return Yb(r);if(AO(r))return SO(r);if(EO(r))return bO(r);throw new vr(8)}function Kb(r,e,t){return function(){var i=t.concat(Array.prototype.slice.call(arguments));return i.length>=e?r.apply(this,i):Kb(r,e,i)}}function Mi(r){return Kb(r,r.length,[])}function wO(r,e){if(e==="transparent")return e;var t=zs(e);return Hs(Bi({},t,{hue:t.hue+parseFloat(r)}))}Mi(wO);function _l(r,e,t){return Math.max(r,Math.min(e,t))}function RO(r,e){if(e==="transparent")return e;var t=zs(e);return Hs(Bi({},t,{lightness:_l(0,1,t.lightness-parseFloat(r))}))}Mi(RO);function CO(r,e){if(e==="transparent")return e;var t=zs(e);return Hs(Bi({},t,{saturation:_l(0,1,t.saturation-parseFloat(r))}))}Mi(CO);function NO(r,e){if(e==="transparent")return e;var t=zs(e);return Hs(Bi({},t,{lightness:_l(0,1,t.lightness+parseFloat(r))}))}Mi(NO);function PO(r,e,t){if(e==="transparent")return t;if(t==="transparent")return e;if(r===0)return t;var n=tl(e),i=Bi({},n,{alpha:typeof n.alpha=="number"?n.alpha:1}),s=tl(t),o=Bi({},s,{alpha:typeof s.alpha=="number"?s.alpha:1}),a=i.alpha-o.alpha,l=parseFloat(r)*2-1,c=l*a===-1?l:l+a,u=1+l*a,h=(c/u+1)/2,d=1-h,f={red:Math.floor(i.red*h+o.red*d),green:Math.floor(i.green*h+o.green*d),blue:Math.floor(i.blue*h+o.blue*d),alpha:i.alpha*parseFloat(r)+o.alpha*(1-parseFloat(r))};return id(f)}var DO=Mi(PO),Zb=DO;function LO(r,e){if(e==="transparent")return e;var t=tl(e),n=typeof t.alpha=="number"?t.alpha:1,i=Bi({},t,{alpha:_l(0,1,(n*100+parseFloat(r)*100)/100)});return id(i)}var UO=Mi(LO),FO=UO;function IO(r,e){if(e==="transparent")return e;var t=zs(e);return Hs(Bi({},t,{saturation:_l(0,1,t.saturation+parseFloat(r))}))}Mi(IO);function BO(r,e){return e==="transparent"?e:Hs(Bi({},zs(e),{hue:parseFloat(r)}))}Mi(BO);function OO(r,e){return e==="transparent"?e:Hs(Bi({},zs(e),{lightness:parseFloat(r)}))}Mi(OO);function kO(r,e){return e==="transparent"?e:Hs(Bi({},zs(e),{saturation:parseFloat(r)}))}Mi(kO);function GO(r,e){return e==="transparent"?e:Zb(parseFloat(r),"rgb(0, 0, 0)",e)}Mi(GO);function VO(r,e){return e==="transparent"?e:Zb(parseFloat(r),"rgb(255, 255, 255)",e)}Mi(VO);function zO(r,e){if(e==="transparent")return e;var t=tl(e),n=typeof t.alpha=="number"?t.alpha:1,i=Bi({},t,{alpha:_l(0,1,+(n*100-parseFloat(r)*100).toFixed(2)/100)});return id(i)}Mi(zO);function HO(r,e){e===void 0&&(e={});var t=e.insertAt;if(!(typeof document>"u")){var n=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css",t==="top"&&n.firstChild?n.insertBefore(i,n.firstChild):n.appendChild(i),i.styleSheet?i.styleSheet.cssText=r:i.appendChild(document.createTextNode(r))}}var WO=`.scene-nav-info {
5083
5083
  position: absolute;
5084
5084
  bottom: 5px;
5085
5085
  width: 100%;
@@ -5123,4 +5123,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
5123
5123
  cursor: -moz-grabbing;
5124
5124
  cursor: -webkit-grabbing;
5125
5125
  }`;nk(ik);function Fp(r,e){(e==null||e>r.length)&&(e=r.length);for(var t=0,n=Array(e);t<e;t++)n[t]=r[t];return n}function rk(r){if(Array.isArray(r))return Fp(r)}function $c(r,e,t){return(e=lk(e))in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function sk(r){if(typeof Symbol<"u"&&r[Symbol.iterator]!=null||r["@@iterator"]!=null)return Array.from(r)}function ok(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
5126
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function U0(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(r,i).enumerable})),t.push.apply(t,n)}return t}function sh(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?U0(Object(t),!0).forEach(function(n){$c(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):U0(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}function rd(r){return rk(r)||sk(r)||ck(r)||ok()}function ak(r,e){if(typeof r!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var n=t.call(r,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function lk(r){var e=ak(r,"string");return typeof e=="symbol"?e:e+""}function ck(r,e){if(r){if(typeof r=="string")return Fp(r,e);var t={}.toString.call(r).slice(8,-1);return t==="Object"&&r.constructor&&(t=r.constructor.name),t==="Map"||t==="Set"?Array.from(r):t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?Fp(r,e):void 0}}function nS(r,e){var t=new e;return t._destructor&&t._destructor(),{linkProp:function(i){return{default:t[i](),onChange:function(o,a){a[r][i](o)},triggerUpdate:!1}},linkMethod:function(i){return function(s){for(var o=s[r],a=arguments.length,l=new Array(a>1?a-1:0),c=1;c<a;c++)l[c-1]=arguments[c];var u=o[i].apply(o,l);return u===o?this:u}}}}var Qf=window.THREE?window.THREE:{AmbientLight:fy,DirectionalLight:dy,REVISION:Mo},uk=170,iS=nS("forceGraph",Hy),hk=Object.assign.apply(Object,rd(["jsonUrl","graphData","numDimensions","dagMode","dagLevelDistance","dagNodeFilter","onDagError","nodeRelSize","nodeId","nodeVal","nodeResolution","nodeColor","nodeAutoColorBy","nodeOpacity","nodeVisibility","nodeThreeObject","nodeThreeObjectExtend","nodePositionUpdate","linkSource","linkTarget","linkVisibility","linkColor","linkAutoColorBy","linkOpacity","linkWidth","linkResolution","linkCurvature","linkCurveRotation","linkMaterial","linkThreeObject","linkThreeObjectExtend","linkPositionUpdate","linkDirectionalArrowLength","linkDirectionalArrowColor","linkDirectionalArrowRelPos","linkDirectionalArrowResolution","linkDirectionalParticles","linkDirectionalParticleSpeed","linkDirectionalParticleOffset","linkDirectionalParticleWidth","linkDirectionalParticleColor","linkDirectionalParticleResolution","linkDirectionalParticleThreeObject","forceEngine","d3AlphaDecay","d3VelocityDecay","d3AlphaMin","ngraphPhysics","warmupTicks","cooldownTicks","cooldownTime","onEngineTick","onEngineStop"].map(function(r){return $c({},r,iS.linkProp(r))}))),dk=Object.assign.apply(Object,rd(["refresh","getGraphBbox","d3Force","d3ReheatSimulation","emitParticle"].map(function(r){return $c({},r,iS.linkMethod(r))}))),ph=nS("renderObjs",tS),fk=Object.assign.apply(Object,rd(["width","height","backgroundColor","showNavInfo","enablePointerInteraction"].map(function(r){return $c({},r,ph.linkProp(r))}))),pk=Object.assign.apply(Object,rd(["lights","cameraPosition","postProcessingComposer"].map(function(r){return $c({},r,ph.linkMethod(r))})).concat([{graph2ScreenCoords:ph.linkMethod("getScreenCoords"),screen2GraphCoords:ph.linkMethod("getSceneCoords")}])),mk=Ip({props:sh(sh({nodeLabel:{default:"name",triggerUpdate:!1},linkLabel:{default:"name",triggerUpdate:!1},linkHoverPrecision:{default:1,onChange:function(e,t){return t.renderObjs.lineHoverPrecision(e)},triggerUpdate:!1},enableNavigationControls:{default:!0,onChange:function(e,t){var n=t.renderObjs.controls();n&&(n.enabled=e,e&&n.domElement&&n.domElement.dispatchEvent(new PointerEvent("pointerup")))},triggerUpdate:!1},enableNodeDrag:{default:!0,triggerUpdate:!1},onNodeDrag:{default:function(){},triggerUpdate:!1},onNodeDragEnd:{default:function(){},triggerUpdate:!1},onNodeClick:{triggerUpdate:!1},onNodeRightClick:{triggerUpdate:!1},onNodeHover:{triggerUpdate:!1},onLinkClick:{triggerUpdate:!1},onLinkRightClick:{triggerUpdate:!1},onLinkHover:{triggerUpdate:!1},onBackgroundClick:{triggerUpdate:!1},onBackgroundRightClick:{triggerUpdate:!1},showPointerCursor:{default:!0,triggerUpdate:!1}},hk),fk),methods:sh(sh({zoomToFit:function(e,t,n){for(var i,s=arguments.length,o=new Array(s>3?s-3:0),a=3;a<s;a++)o[a-3]=arguments[a];return e.renderObjs.fitToBbox((i=e.forceGraph).getGraphBbox.apply(i,o),t,n),this},pauseAnimation:function(e){return e.animationFrameRequestId!==null&&(cancelAnimationFrame(e.animationFrameRequestId),e.animationFrameRequestId=null),this},resumeAnimation:function(e){return e.animationFrameRequestId===null&&this._animationCycle(),this},_animationCycle:function(e){e.enablePointerInteraction&&(this.renderer().domElement.style.cursor=null),e.forceGraph.tickFrame(),e.renderObjs.tick(),e.animationFrameRequestId=requestAnimationFrame(this._animationCycle)},scene:function(e){return e.renderObjs.scene()},camera:function(e){return e.renderObjs.camera()},renderer:function(e){return e.renderObjs.renderer()},controls:function(e){return e.renderObjs.controls()},_destructor:function(e){var t,n;this.pauseAnimation(),this.graphData({nodes:[],links:[]}),(t=(n=e.forceGraph)._destructor)===null||t===void 0||t.call(n),e.renderObjs._destructor()}},dk),pk),stateInit:function(e){var t=e.controlType,n=e.rendererConfig,i=e.extraRenderers,s=new Hy;return{forceGraph:s,renderObjs:tS({controlType:t,rendererConfig:n,extraRenderers:i}).objects([s]).lights([new Qf.AmbientLight(13421772,Math.PI),new Qf.DirectionalLight(16777215,.6*Math.PI)])}},init:function(e,t){e.innerHTML="",e.appendChild(t.container=document.createElement("div")),t.container.style.position="relative";var n=document.createElement("div");t.container.appendChild(n),t.renderObjs(n);var i=t.renderObjs.camera(),s=t.renderObjs.renderer(),o=t.renderObjs.controls();o.enabled=!!t.enableNavigationControls,t.lastSetCameraZ=i.position.z;var a;t.container.appendChild(a=document.createElement("div")),a.className="graph-info-msg",a.textContent="",t.forceGraph.onLoading(function(){a.textContent="Loading..."}).onFinishLoading(function(){a.textContent=""}).onUpdate(function(){t.graphData=t.forceGraph.graphData(),i.position.x===0&&i.position.y===0&&i.position.z===t.lastSetCameraZ&&t.graphData.nodes.length&&(i.lookAt(t.forceGraph.position),t.lastSetCameraZ=i.position.z=Math.cbrt(t.graphData.nodes.length)*uk)}).onFinishUpdate(function(){if(t._dragControls){var l=t.graphData.nodes.find(function(u){return u.__initialFixedPos&&!u.__disposeControlsAfterDrag});l?l.__disposeControlsAfterDrag=!0:t._dragControls.dispose(),t._dragControls=void 0}if(t.enableNodeDrag&&t.enablePointerInteraction&&t.forceEngine==="d3"){var c=t._dragControls=new wC(t.graphData.nodes.map(function(u){return u.__threeObj}).filter(function(u){return u}),i,s.domElement);c.addEventListener("dragstart",function(u){var h=kr(u.object);if(h){o.enabled=!1,u.object.__initialPos=u.object.position.clone(),u.object.__prevPos=u.object.position.clone();var d=h.__data;!d.__initialFixedPos&&(d.__initialFixedPos={fx:d.fx,fy:d.fy,fz:d.fz}),!d.__initialPos&&(d.__initialPos={x:d.x,y:d.y,z:d.z}),["x","y","z"].forEach(function(f){return d["f".concat(f)]=d[f]}),s.domElement.classList.add("grabbable")}}),c.addEventListener("drag",function(u){var h=kr(u.object);if(h){if(!u.object.hasOwnProperty("__graphObjType")){var d=u.object.__initialPos,f=u.object.__prevPos,p=u.object.position;h.position.add(p.clone().sub(f)),f.copy(p),p.copy(d)}var g=h.__data,m=h.position,_={x:m.x-g.x,y:m.y-g.y,z:m.z-g.z};["x","y","z"].forEach(function(x){return g["f".concat(x)]=g[x]=m[x]}),t.forceGraph.d3AlphaTarget(.3).resetCountdown(),g.__dragged=!0,t.onNodeDrag(g,_)}}),c.addEventListener("dragend",function(u){var h=kr(u.object);if(h){delete u.object.__initialPos,delete u.object.__prevPos;var d=h.__data;d.__disposeControlsAfterDrag&&(c.dispose(),delete d.__disposeControlsAfterDrag);var f=d.__initialFixedPos,p=d.__initialPos,g={x:p.x-d.x,y:p.y-d.y,z:p.z-d.z};if(f&&(["x","y","z"].forEach(function(_){var x="f".concat(_);f[x]===void 0&&delete d[x]}),delete d.__initialFixedPos,delete d.__initialPos,d.__dragged&&(delete d.__dragged,t.onNodeDragEnd(d,g))),t.forceGraph.d3AlphaTarget(0).resetCountdown(),t.enableNavigationControls){var m;o.enabled=!0,o._status&&((m=o._onPointerCancel)===null||m===void 0||m.call(o)),o.domElement&&o.domElement.ownerDocument&&o.domElement.ownerDocument.dispatchEvent(new PointerEvent("pointerup",{pointerType:"touch"}))}s.domElement.classList.remove("grabbable")}})}}),Qf.REVISION<155&&(t.renderObjs.renderer().useLegacyLights=!1),t.renderObjs.hoverOrderComparator(function(l,c){var u=kr(l);if(!u)return 1;var h=kr(c);if(!h)return-1;var d=function(p){return p.__graphObjType==="node"};return d(h)-d(u)}).tooltipContent(function(l){var c=kr(l);return c&&xt(t["".concat(c.__graphObjType,"Label")])(c.__data)||""}).hoverDuringDrag(!1).onHover(function(l){var c=kr(l);if(c!==t.hoverObj){var u=t.hoverObj?t.hoverObj.__graphObjType:null,h=t.hoverObj?t.hoverObj.__data:null,d=c?c.__graphObjType:null,f=c?c.__data:null;if(u&&u!==d){var p=t["on".concat(u==="node"?"Node":"Link","Hover")];p&&p(null,h)}if(d){var g=t["on".concat(d==="node"?"Node":"Link","Hover")];g&&g(f,u===d?h:null)}s.domElement.classList[(c&&t["on".concat(d==="node"?"Node":"Link","Click")]||!c&&t.onBackgroundClick)&&xt(t.showPointerCursor)(f)?"add":"remove"]("clickable"),t.hoverObj=c}}).clickAfterDrag(!1).onClick(function(l,c){var u=kr(l);if(u){var h=t["on".concat(u.__graphObjType==="node"?"Node":"Link","Click")];h&&h(u.__data,c)}else t.onBackgroundClick&&t.onBackgroundClick(c)}).onRightClick(function(l,c){var u=kr(l);if(u){var h=t["on".concat(u.__graphObjType==="node"?"Node":"Link","RightClick")];h&&h(u.__data,c)}else t.onBackgroundRightClick&&t.onBackgroundRightClick(c)}),this._animationCycle()}});function kr(r){for(var e=r;e&&!e.hasOwnProperty("__graphObjType");)e=e.parent;return e}const sd={width:k.number,height:k.number,graphData:k.shape({nodes:k.arrayOf(k.object).isRequired,links:k.arrayOf(k.object).isRequired}),backgroundColor:k.string,nodeRelSize:k.number,nodeId:k.string,nodeLabel:k.oneOfType([k.string,k.func]),nodeVal:k.oneOfType([k.number,k.string,k.func]),nodeVisibility:k.oneOfType([k.bool,k.string,k.func]),nodeColor:k.oneOfType([k.string,k.func]),nodeAutoColorBy:k.oneOfType([k.string,k.func]),onNodeHover:k.func,onNodeClick:k.func,linkSource:k.string,linkTarget:k.string,linkLabel:k.oneOfType([k.string,k.func]),linkVisibility:k.oneOfType([k.bool,k.string,k.func]),linkColor:k.oneOfType([k.string,k.func]),linkAutoColorBy:k.oneOfType([k.string,k.func]),linkWidth:k.oneOfType([k.number,k.string,k.func]),linkCurvature:k.oneOfType([k.number,k.string,k.func]),linkDirectionalArrowLength:k.oneOfType([k.number,k.string,k.func]),linkDirectionalArrowColor:k.oneOfType([k.string,k.func]),linkDirectionalArrowRelPos:k.oneOfType([k.number,k.string,k.func]),linkDirectionalParticles:k.oneOfType([k.number,k.string,k.func]),linkDirectionalParticleSpeed:k.oneOfType([k.number,k.string,k.func]),linkDirectionalParticleOffset:k.oneOfType([k.number,k.string,k.func]),linkDirectionalParticleWidth:k.oneOfType([k.number,k.string,k.func]),linkDirectionalParticleColor:k.oneOfType([k.string,k.func]),onLinkHover:k.func,onLinkClick:k.func,dagMode:k.oneOf(["td","bu","lr","rl","zin","zout","radialin","radialout"]),dagLevelDistance:k.number,dagNodeFilter:k.func,onDagError:k.func,d3AlphaMin:k.number,d3AlphaDecay:k.number,d3VelocityDecay:k.number,warmupTicks:k.number,cooldownTicks:k.number,cooldownTime:k.number,onEngineTick:k.func,onEngineStop:k.func,getGraphBbox:k.func},rS={zoomToFit:k.func,onNodeRightClick:k.func,onNodeDrag:k.func,onNodeDragEnd:k.func,onLinkRightClick:k.func,linkHoverPrecision:k.number,onBackgroundClick:k.func,onBackgroundRightClick:k.func,showPointerCursor:k.oneOfType([k.bool,k.func]),enablePointerInteraction:k.bool,enableNodeDrag:k.bool},ig={showNavInfo:k.bool,nodeOpacity:k.number,nodeResolution:k.number,nodeThreeObject:k.oneOfType([k.object,k.string,k.func]),nodeThreeObjectExtend:k.oneOfType([k.bool,k.string,k.func]),nodePositionUpdate:k.func,linkOpacity:k.number,linkResolution:k.number,linkCurveRotation:k.oneOfType([k.number,k.string,k.func]),linkMaterial:k.oneOfType([k.object,k.string,k.func]),linkThreeObject:k.oneOfType([k.object,k.string,k.func]),linkThreeObjectExtend:k.oneOfType([k.bool,k.string,k.func]),linkPositionUpdate:k.func,linkDirectionalArrowResolution:k.number,linkDirectionalParticleResolution:k.number,linkDirectionalParticleThreeObject:k.oneOfType([k.object,k.string,k.func]),forceEngine:k.oneOf(["d3","ngraph"]),ngraphPhysics:k.object,numDimensions:k.oneOf([1,2,3])};Object.assign({},sd,rS,{linkLineDash:k.oneOfType([k.arrayOf(k.number),k.string,k.func]),nodeCanvasObjectMode:k.oneOfType([k.string,k.func]),nodeCanvasObject:k.func,nodePointerAreaPaint:k.func,linkCanvasObjectMode:k.oneOfType([k.string,k.func]),linkCanvasObject:k.func,linkPointerAreaPaint:k.func,linkDirectionalParticleCanvasObject:k.func,autoPauseRedraw:k.bool,minZoom:k.number,maxZoom:k.number,enableZoomInteraction:k.oneOfType([k.bool,k.func]),enablePanInteraction:k.oneOfType([k.bool,k.func]),onZoom:k.func,onZoomEnd:k.func,onRenderFramePre:k.func,onRenderFramePost:k.func});const gk=Object.assign({},sd,rS,ig,{enableNavigationControls:k.bool,controlType:k.oneOf(["trackball","orbit","fly"]),rendererConfig:k.object,extraRenderers:k.arrayOf(k.shape({render:k.func.isRequired}))});Object.assign({},sd,ig,{nodeDesc:k.oneOfType([k.string,k.func]),linkDesc:k.oneOfType([k.string,k.func])});Object.assign({},sd,ig,{markerAttrs:k.object,yOffset:k.number,glScale:k.number});const rg=AS(mk,{methodNames:["emitParticle","d3Force","d3ReheatSimulation","stopAnimation","pauseAnimation","resumeAnimation","cameraPosition","zoomToFit","getGraphBbox","screen2GraphCoords","graph2ScreenCoords","postProcessingComposer","lights","scene","camera","renderer","controls","refresh"],initPropNames:["controlType","rendererConfig","extraRenderers"]});rg.displayName="ForceGraph3D";rg.propTypes=gk;function F0(r,e){return Math.cbrt(Math.max(.1,sS(r,e)))*4}function sS(r,e){const t=r.group==="soul"?8:r.group==="user"||r.group==="memory"?6:r.group==="tag"?3:4,n=r.__inDegree??0;return(t+Math.min(14,n*1.2))*e}function _k(r,e,t){const o=document.createElement("canvas").getContext("2d");o.font="600 22px -apple-system, BlinkMacSystemFont, 'Visby CF', sans-serif";const a=Math.ceil(o.measureText(r).width),l=(a+12)*t,c=30*t,u=document.createElement("canvas");u.width=l,u.height=c;const h=u.getContext("2d");h.scale(t,t),h.font="600 22px -apple-system, BlinkMacSystemFont, 'Visby CF', sans-serif",h.textAlign="left",h.textBaseline="middle",h.fillStyle=e,h.fillText(r,6,22/2+4);const d=new zT(u);d.minFilter=Nt,d.magFilter=Nt,d.anisotropy=4,d.needsUpdate=!0;const f=new mm({map:d,transparent:!0,depthWrite:!1,depthTest:!0,fog:!0}),p=new UT(f),g=.18;return p.scale.set((a+12)*g,30*g,1),p}function bk({graphData:r,width:e,height:t,isDark:n,nodeColor:i,linkColor:s,linkWidth:o,showArrows:a,forces:l,nodeSizeScale:c,isDimmed:u,neighborsById:h,onNodeClick:d,onNodeHover:f,onBackgroundClick:p}){const g=$s.useRef(void 0),m=$s.useRef(!1),_=$s.useMemo(()=>typeof window<"u"?Math.min(2,window.devicePixelRatio||1):1,[]);$s.useEffect(()=>{m.current=!1},[r.nodes.length]),$s.useEffect(()=>{var E,v,w,N,C,F,V,z,U,B;const y=g.current;if(!y)return;const b=(E=y.d3Force)==null?void 0:E.call(y,"charge");b!=null&&b.strength&&b.strength(l.repelStrength),b!=null&&b.distanceMax&&b.distanceMax(520);const M=(v=y.d3Force)==null?void 0:v.call(y,"link");M&&((w=M.strength)==null||w.call(M,l.linkStrength),(N=M.distance)==null||N.call(M,l.linkDistance));const S=(C=y.d3Force)==null?void 0:C.call(y,"center");S!=null&&S.strength&&S.strength(l.centerStrength),(F=y.d3Force)==null||F.call(y,"collide",wS().radius(D=>F0(D,c)+4).strength(.9).iterations(2)),(V=y.d3Force)==null||V.call(y,"x",RS(0).strength(l.centerStrength*.35)),(z=y.d3Force)==null||z.call(y,"y",CS(0).strength(l.centerStrength*.35)),(U=y.d3Force)==null||U.call(y,"z",PS(0).strength(l.centerStrength*.35)),(B=y.d3ReheatSimulation)==null||B.call(y)},[l,c,r]),$s.useEffect(()=>{if(!r.nodes.length)return;const y=[];return[900,1800,2800].forEach(b=>{y.push(setTimeout(()=>{var S;if(m.current)return;const M=g.current;M&&((S=M.zoomToFit)==null||S.call(M,700,80),b>=2800&&(m.current=!0))},b))}),()=>y.forEach(clearTimeout)},[r.nodes.length]),$s.useEffect(()=>{var S;const y=g.current;if(!y)return;const b=(S=y.scene)==null?void 0:S.call(y);if(!b)return;const M=n?855312:16250874;b.fog=new um(M,900,4200)},[n,r.nodes.length]);const x=y=>{var ne,ue;d(y);const b=g.current;if(!b)return;const M=h.get(y.id)??new Set,S=new Set([y.id,...M]),E=r.nodes.filter(_e=>S.has(_e.id)&&typeof _e.x=="number"&&typeof _e.y=="number"&&typeof _e.z=="number");if(E.length===0)return;let v=1/0,w=1/0,N=1/0,C=-1/0,F=-1/0,V=-1/0;for(const _e of E){const Ue=_e.x,Ae=_e.y,dt=_e.z;Ue<v&&(v=Ue),Ae<w&&(w=Ae),dt<N&&(N=dt),Ue>C&&(C=Ue),Ae>F&&(F=Ae),dt>V&&(V=dt)}const z=(v+C)/2,U=(w+F)/2,B=(N+V)/2,D=Math.max(C-v,F-w,V-N)/2,X=50,K=90,Z=D/Math.tan(X*Math.PI/360)*2.2,oe=Math.max(K,Z),Ee=(ne=b.camera)==null?void 0:ne.call(b);let ze=0,$=0,I=1;if(Ee){ze=Ee.position.x-z,$=Ee.position.y-U,I=Ee.position.z-B;const _e=Math.hypot(ze,$,I)||1;ze/=_e,$/=_e,I/=_e}(ue=b.cameraPosition)==null||ue.call(b,{x:z+ze*oe,y:U+$*oe,z:B+I*oe},{x:z,y:U,z:B},900)};return NS.jsx(rg,{ref:g,graphData:r,width:e,height:t,backgroundColor:n?"#0d0d10":"#f7f7fa",showNavInfo:!1,nodeId:"id",nodeLabel:y=>y.label,nodeColor:y=>i(y),nodeVal:y=>sS(y,c),nodeRelSize:4,nodeOpacity:.92,nodeResolution:16,linkColor:y=>s(y),linkWidth:y=>o(y),linkOpacity:.55,linkDirectionalArrowLength:y=>a?3.5:0,linkDirectionalArrowRelPos:.94,linkDirectionalArrowColor:()=>n?"rgba(180, 185, 200, 0.7)":"rgba(60, 65, 80, 0.7)",onNodeClick:y=>x(y),onNodeHover:y=>f(y),onBackgroundClick:p,cooldownTicks:180,d3AlphaDecay:.025,d3VelocityDecay:.3,enableNodeDrag:!0,enableNavigationControls:!0,controlType:"orbit",nodeThreeObjectExtend:!0,nodeThreeObject:y=>{const b=i(y),S=u(y.id)?n?"rgba(200, 210, 225, 0.35)":"rgba(60, 65, 80, 0.35)":n?"#eaf0fa":"#141826",E=_k(y.label,S,_),v=F0(y,c);return E.position.set(0,-(v+5),0),E.userData.baseColor=b,E}})}export{bk as BrainCanvas3D};
5126
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function U0(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(r,i).enumerable})),t.push.apply(t,n)}return t}function sh(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?U0(Object(t),!0).forEach(function(n){$c(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):U0(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}function rd(r){return rk(r)||sk(r)||ck(r)||ok()}function ak(r,e){if(typeof r!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var n=t.call(r,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function lk(r){var e=ak(r,"string");return typeof e=="symbol"?e:e+""}function ck(r,e){if(r){if(typeof r=="string")return Fp(r,e);var t={}.toString.call(r).slice(8,-1);return t==="Object"&&r.constructor&&(t=r.constructor.name),t==="Map"||t==="Set"?Array.from(r):t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?Fp(r,e):void 0}}function nS(r,e){var t=new e;return t._destructor&&t._destructor(),{linkProp:function(i){return{default:t[i](),onChange:function(o,a){a[r][i](o)},triggerUpdate:!1}},linkMethod:function(i){return function(s){for(var o=s[r],a=arguments.length,l=new Array(a>1?a-1:0),c=1;c<a;c++)l[c-1]=arguments[c];var u=o[i].apply(o,l);return u===o?this:u}}}}var Qf=window.THREE?window.THREE:{AmbientLight:fy,DirectionalLight:dy,REVISION:Mo},uk=170,iS=nS("forceGraph",Hy),hk=Object.assign.apply(Object,rd(["jsonUrl","graphData","numDimensions","dagMode","dagLevelDistance","dagNodeFilter","onDagError","nodeRelSize","nodeId","nodeVal","nodeResolution","nodeColor","nodeAutoColorBy","nodeOpacity","nodeVisibility","nodeThreeObject","nodeThreeObjectExtend","nodePositionUpdate","linkSource","linkTarget","linkVisibility","linkColor","linkAutoColorBy","linkOpacity","linkWidth","linkResolution","linkCurvature","linkCurveRotation","linkMaterial","linkThreeObject","linkThreeObjectExtend","linkPositionUpdate","linkDirectionalArrowLength","linkDirectionalArrowColor","linkDirectionalArrowRelPos","linkDirectionalArrowResolution","linkDirectionalParticles","linkDirectionalParticleSpeed","linkDirectionalParticleOffset","linkDirectionalParticleWidth","linkDirectionalParticleColor","linkDirectionalParticleResolution","linkDirectionalParticleThreeObject","forceEngine","d3AlphaDecay","d3VelocityDecay","d3AlphaMin","ngraphPhysics","warmupTicks","cooldownTicks","cooldownTime","onEngineTick","onEngineStop"].map(function(r){return $c({},r,iS.linkProp(r))}))),dk=Object.assign.apply(Object,rd(["refresh","getGraphBbox","d3Force","d3ReheatSimulation","emitParticle"].map(function(r){return $c({},r,iS.linkMethod(r))}))),ph=nS("renderObjs",tS),fk=Object.assign.apply(Object,rd(["width","height","backgroundColor","showNavInfo","enablePointerInteraction"].map(function(r){return $c({},r,ph.linkProp(r))}))),pk=Object.assign.apply(Object,rd(["lights","cameraPosition","postProcessingComposer"].map(function(r){return $c({},r,ph.linkMethod(r))})).concat([{graph2ScreenCoords:ph.linkMethod("getScreenCoords"),screen2GraphCoords:ph.linkMethod("getSceneCoords")}])),mk=Ip({props:sh(sh({nodeLabel:{default:"name",triggerUpdate:!1},linkLabel:{default:"name",triggerUpdate:!1},linkHoverPrecision:{default:1,onChange:function(e,t){return t.renderObjs.lineHoverPrecision(e)},triggerUpdate:!1},enableNavigationControls:{default:!0,onChange:function(e,t){var n=t.renderObjs.controls();n&&(n.enabled=e,e&&n.domElement&&n.domElement.dispatchEvent(new PointerEvent("pointerup")))},triggerUpdate:!1},enableNodeDrag:{default:!0,triggerUpdate:!1},onNodeDrag:{default:function(){},triggerUpdate:!1},onNodeDragEnd:{default:function(){},triggerUpdate:!1},onNodeClick:{triggerUpdate:!1},onNodeRightClick:{triggerUpdate:!1},onNodeHover:{triggerUpdate:!1},onLinkClick:{triggerUpdate:!1},onLinkRightClick:{triggerUpdate:!1},onLinkHover:{triggerUpdate:!1},onBackgroundClick:{triggerUpdate:!1},onBackgroundRightClick:{triggerUpdate:!1},showPointerCursor:{default:!0,triggerUpdate:!1}},hk),fk),methods:sh(sh({zoomToFit:function(e,t,n){for(var i,s=arguments.length,o=new Array(s>3?s-3:0),a=3;a<s;a++)o[a-3]=arguments[a];return e.renderObjs.fitToBbox((i=e.forceGraph).getGraphBbox.apply(i,o),t,n),this},pauseAnimation:function(e){return e.animationFrameRequestId!==null&&(cancelAnimationFrame(e.animationFrameRequestId),e.animationFrameRequestId=null),this},resumeAnimation:function(e){return e.animationFrameRequestId===null&&this._animationCycle(),this},_animationCycle:function(e){e.enablePointerInteraction&&(this.renderer().domElement.style.cursor=null),e.forceGraph.tickFrame(),e.renderObjs.tick(),e.animationFrameRequestId=requestAnimationFrame(this._animationCycle)},scene:function(e){return e.renderObjs.scene()},camera:function(e){return e.renderObjs.camera()},renderer:function(e){return e.renderObjs.renderer()},controls:function(e){return e.renderObjs.controls()},_destructor:function(e){var t,n;this.pauseAnimation(),this.graphData({nodes:[],links:[]}),(t=(n=e.forceGraph)._destructor)===null||t===void 0||t.call(n),e.renderObjs._destructor()}},dk),pk),stateInit:function(e){var t=e.controlType,n=e.rendererConfig,i=e.extraRenderers,s=new Hy;return{forceGraph:s,renderObjs:tS({controlType:t,rendererConfig:n,extraRenderers:i}).objects([s]).lights([new Qf.AmbientLight(13421772,Math.PI),new Qf.DirectionalLight(16777215,.6*Math.PI)])}},init:function(e,t){e.innerHTML="",e.appendChild(t.container=document.createElement("div")),t.container.style.position="relative";var n=document.createElement("div");t.container.appendChild(n),t.renderObjs(n);var i=t.renderObjs.camera(),s=t.renderObjs.renderer(),o=t.renderObjs.controls();o.enabled=!!t.enableNavigationControls,t.lastSetCameraZ=i.position.z;var a;t.container.appendChild(a=document.createElement("div")),a.className="graph-info-msg",a.textContent="",t.forceGraph.onLoading(function(){a.textContent="Loading..."}).onFinishLoading(function(){a.textContent=""}).onUpdate(function(){t.graphData=t.forceGraph.graphData(),i.position.x===0&&i.position.y===0&&i.position.z===t.lastSetCameraZ&&t.graphData.nodes.length&&(i.lookAt(t.forceGraph.position),t.lastSetCameraZ=i.position.z=Math.cbrt(t.graphData.nodes.length)*uk)}).onFinishUpdate(function(){if(t._dragControls){var l=t.graphData.nodes.find(function(u){return u.__initialFixedPos&&!u.__disposeControlsAfterDrag});l?l.__disposeControlsAfterDrag=!0:t._dragControls.dispose(),t._dragControls=void 0}if(t.enableNodeDrag&&t.enablePointerInteraction&&t.forceEngine==="d3"){var c=t._dragControls=new wC(t.graphData.nodes.map(function(u){return u.__threeObj}).filter(function(u){return u}),i,s.domElement);c.addEventListener("dragstart",function(u){var h=kr(u.object);if(h){o.enabled=!1,u.object.__initialPos=u.object.position.clone(),u.object.__prevPos=u.object.position.clone();var d=h.__data;!d.__initialFixedPos&&(d.__initialFixedPos={fx:d.fx,fy:d.fy,fz:d.fz}),!d.__initialPos&&(d.__initialPos={x:d.x,y:d.y,z:d.z}),["x","y","z"].forEach(function(f){return d["f".concat(f)]=d[f]}),s.domElement.classList.add("grabbable")}}),c.addEventListener("drag",function(u){var h=kr(u.object);if(h){if(!u.object.hasOwnProperty("__graphObjType")){var d=u.object.__initialPos,f=u.object.__prevPos,p=u.object.position;h.position.add(p.clone().sub(f)),f.copy(p),p.copy(d)}var g=h.__data,m=h.position,_={x:m.x-g.x,y:m.y-g.y,z:m.z-g.z};["x","y","z"].forEach(function(x){return g["f".concat(x)]=g[x]=m[x]}),t.forceGraph.d3AlphaTarget(.3).resetCountdown(),g.__dragged=!0,t.onNodeDrag(g,_)}}),c.addEventListener("dragend",function(u){var h=kr(u.object);if(h){delete u.object.__initialPos,delete u.object.__prevPos;var d=h.__data;d.__disposeControlsAfterDrag&&(c.dispose(),delete d.__disposeControlsAfterDrag);var f=d.__initialFixedPos,p=d.__initialPos,g={x:p.x-d.x,y:p.y-d.y,z:p.z-d.z};if(f&&(["x","y","z"].forEach(function(_){var x="f".concat(_);f[x]===void 0&&delete d[x]}),delete d.__initialFixedPos,delete d.__initialPos,d.__dragged&&(delete d.__dragged,t.onNodeDragEnd(d,g))),t.forceGraph.d3AlphaTarget(0).resetCountdown(),t.enableNavigationControls){var m;o.enabled=!0,o._status&&((m=o._onPointerCancel)===null||m===void 0||m.call(o)),o.domElement&&o.domElement.ownerDocument&&o.domElement.ownerDocument.dispatchEvent(new PointerEvent("pointerup",{pointerType:"touch"}))}s.domElement.classList.remove("grabbable")}})}}),Qf.REVISION<155&&(t.renderObjs.renderer().useLegacyLights=!1),t.renderObjs.hoverOrderComparator(function(l,c){var u=kr(l);if(!u)return 1;var h=kr(c);if(!h)return-1;var d=function(p){return p.__graphObjType==="node"};return d(h)-d(u)}).tooltipContent(function(l){var c=kr(l);return c&&xt(t["".concat(c.__graphObjType,"Label")])(c.__data)||""}).hoverDuringDrag(!1).onHover(function(l){var c=kr(l);if(c!==t.hoverObj){var u=t.hoverObj?t.hoverObj.__graphObjType:null,h=t.hoverObj?t.hoverObj.__data:null,d=c?c.__graphObjType:null,f=c?c.__data:null;if(u&&u!==d){var p=t["on".concat(u==="node"?"Node":"Link","Hover")];p&&p(null,h)}if(d){var g=t["on".concat(d==="node"?"Node":"Link","Hover")];g&&g(f,u===d?h:null)}s.domElement.classList[(c&&t["on".concat(d==="node"?"Node":"Link","Click")]||!c&&t.onBackgroundClick)&&xt(t.showPointerCursor)(f)?"add":"remove"]("clickable"),t.hoverObj=c}}).clickAfterDrag(!1).onClick(function(l,c){var u=kr(l);if(u){var h=t["on".concat(u.__graphObjType==="node"?"Node":"Link","Click")];h&&h(u.__data,c)}else t.onBackgroundClick&&t.onBackgroundClick(c)}).onRightClick(function(l,c){var u=kr(l);if(u){var h=t["on".concat(u.__graphObjType==="node"?"Node":"Link","RightClick")];h&&h(u.__data,c)}else t.onBackgroundRightClick&&t.onBackgroundRightClick(c)}),this._animationCycle()}});function kr(r){for(var e=r;e&&!e.hasOwnProperty("__graphObjType");)e=e.parent;return e}const sd={width:k.number,height:k.number,graphData:k.shape({nodes:k.arrayOf(k.object).isRequired,links:k.arrayOf(k.object).isRequired}),backgroundColor:k.string,nodeRelSize:k.number,nodeId:k.string,nodeLabel:k.oneOfType([k.string,k.func]),nodeVal:k.oneOfType([k.number,k.string,k.func]),nodeVisibility:k.oneOfType([k.bool,k.string,k.func]),nodeColor:k.oneOfType([k.string,k.func]),nodeAutoColorBy:k.oneOfType([k.string,k.func]),onNodeHover:k.func,onNodeClick:k.func,linkSource:k.string,linkTarget:k.string,linkLabel:k.oneOfType([k.string,k.func]),linkVisibility:k.oneOfType([k.bool,k.string,k.func]),linkColor:k.oneOfType([k.string,k.func]),linkAutoColorBy:k.oneOfType([k.string,k.func]),linkWidth:k.oneOfType([k.number,k.string,k.func]),linkCurvature:k.oneOfType([k.number,k.string,k.func]),linkDirectionalArrowLength:k.oneOfType([k.number,k.string,k.func]),linkDirectionalArrowColor:k.oneOfType([k.string,k.func]),linkDirectionalArrowRelPos:k.oneOfType([k.number,k.string,k.func]),linkDirectionalParticles:k.oneOfType([k.number,k.string,k.func]),linkDirectionalParticleSpeed:k.oneOfType([k.number,k.string,k.func]),linkDirectionalParticleOffset:k.oneOfType([k.number,k.string,k.func]),linkDirectionalParticleWidth:k.oneOfType([k.number,k.string,k.func]),linkDirectionalParticleColor:k.oneOfType([k.string,k.func]),onLinkHover:k.func,onLinkClick:k.func,dagMode:k.oneOf(["td","bu","lr","rl","zin","zout","radialin","radialout"]),dagLevelDistance:k.number,dagNodeFilter:k.func,onDagError:k.func,d3AlphaMin:k.number,d3AlphaDecay:k.number,d3VelocityDecay:k.number,warmupTicks:k.number,cooldownTicks:k.number,cooldownTime:k.number,onEngineTick:k.func,onEngineStop:k.func,getGraphBbox:k.func},rS={zoomToFit:k.func,onNodeRightClick:k.func,onNodeDrag:k.func,onNodeDragEnd:k.func,onLinkRightClick:k.func,linkHoverPrecision:k.number,onBackgroundClick:k.func,onBackgroundRightClick:k.func,showPointerCursor:k.oneOfType([k.bool,k.func]),enablePointerInteraction:k.bool,enableNodeDrag:k.bool},ig={showNavInfo:k.bool,nodeOpacity:k.number,nodeResolution:k.number,nodeThreeObject:k.oneOfType([k.object,k.string,k.func]),nodeThreeObjectExtend:k.oneOfType([k.bool,k.string,k.func]),nodePositionUpdate:k.func,linkOpacity:k.number,linkResolution:k.number,linkCurveRotation:k.oneOfType([k.number,k.string,k.func]),linkMaterial:k.oneOfType([k.object,k.string,k.func]),linkThreeObject:k.oneOfType([k.object,k.string,k.func]),linkThreeObjectExtend:k.oneOfType([k.bool,k.string,k.func]),linkPositionUpdate:k.func,linkDirectionalArrowResolution:k.number,linkDirectionalParticleResolution:k.number,linkDirectionalParticleThreeObject:k.oneOfType([k.object,k.string,k.func]),forceEngine:k.oneOf(["d3","ngraph"]),ngraphPhysics:k.object,numDimensions:k.oneOf([1,2,3])};Object.assign({},sd,rS,{linkLineDash:k.oneOfType([k.arrayOf(k.number),k.string,k.func]),nodeCanvasObjectMode:k.oneOfType([k.string,k.func]),nodeCanvasObject:k.func,nodePointerAreaPaint:k.func,linkCanvasObjectMode:k.oneOfType([k.string,k.func]),linkCanvasObject:k.func,linkPointerAreaPaint:k.func,linkDirectionalParticleCanvasObject:k.func,autoPauseRedraw:k.bool,minZoom:k.number,maxZoom:k.number,enableZoomInteraction:k.oneOfType([k.bool,k.func]),enablePanInteraction:k.oneOfType([k.bool,k.func]),onZoom:k.func,onZoomEnd:k.func,onRenderFramePre:k.func,onRenderFramePost:k.func});const gk=Object.assign({},sd,rS,ig,{enableNavigationControls:k.bool,controlType:k.oneOf(["trackball","orbit","fly"]),rendererConfig:k.object,extraRenderers:k.arrayOf(k.shape({render:k.func.isRequired}))});Object.assign({},sd,ig,{nodeDesc:k.oneOfType([k.string,k.func]),linkDesc:k.oneOfType([k.string,k.func])});Object.assign({},sd,ig,{markerAttrs:k.object,yOffset:k.number,glScale:k.number});const rg=AS(mk,{methodNames:["emitParticle","d3Force","d3ReheatSimulation","stopAnimation","pauseAnimation","resumeAnimation","cameraPosition","zoomToFit","getGraphBbox","screen2GraphCoords","graph2ScreenCoords","postProcessingComposer","lights","scene","camera","renderer","controls","refresh"],initPropNames:["controlType","rendererConfig","extraRenderers"]});rg.displayName="ForceGraph3D";rg.propTypes=gk;function F0(r,e){return Math.cbrt(Math.max(.1,sS(r,e)))*4}function sS(r,e){const t=r.group==="soul"?8:r.group==="user"||r.group==="memory"?6:r.group==="tag"?3:4,n=r.__inDegree??0;return(t+Math.min(14,n*1.2))*e}function _k(r,e,t){const o=document.createElement("canvas").getContext("2d");o.font="600 22px -apple-system, BlinkMacSystemFont, 'Visby CF', sans-serif";const a=Math.ceil(o.measureText(r).width),l=(a+12)*t,c=30*t,u=document.createElement("canvas");u.width=l,u.height=c;const h=u.getContext("2d");h.scale(t,t),h.font="600 22px -apple-system, BlinkMacSystemFont, 'Visby CF', sans-serif",h.textAlign="left",h.textBaseline="middle",h.fillStyle=e,h.fillText(r,6,22/2+4);const d=new zT(u);d.minFilter=Nt,d.magFilter=Nt,d.anisotropy=4,d.needsUpdate=!0;const f=new mm({map:d,transparent:!0,depthWrite:!1,depthTest:!0,fog:!0}),p=new UT(f),g=.18;return p.scale.set((a+12)*g,30*g,1),p}function Sk({graphData:r,width:e,height:t,isDark:n,nodeColor:i,linkColor:s,linkWidth:o,showArrows:a,forces:l,nodeSizeScale:c,isDimmed:u,neighborsById:h,onNodeClick:d,onNodeHover:f,onBackgroundClick:p}){const g=$s.useRef(void 0),m=$s.useRef(!1),_=$s.useMemo(()=>typeof window<"u"?Math.min(2,window.devicePixelRatio||1):1,[]);$s.useEffect(()=>{m.current=!1},[r.nodes.length]),$s.useEffect(()=>{var E,v,w,N,C,F,V,z,U,B;const y=g.current;if(!y)return;const b=(E=y.d3Force)==null?void 0:E.call(y,"charge");b!=null&&b.strength&&b.strength(l.repelStrength),b!=null&&b.distanceMax&&b.distanceMax(520);const M=(v=y.d3Force)==null?void 0:v.call(y,"link");M&&((w=M.strength)==null||w.call(M,l.linkStrength),(N=M.distance)==null||N.call(M,l.linkDistance));const S=(C=y.d3Force)==null?void 0:C.call(y,"center");S!=null&&S.strength&&S.strength(l.centerStrength),(F=y.d3Force)==null||F.call(y,"collide",wS().radius(D=>F0(D,c)+4).strength(.9).iterations(2)),(V=y.d3Force)==null||V.call(y,"x",RS(0).strength(l.centerStrength*.35)),(z=y.d3Force)==null||z.call(y,"y",CS(0).strength(l.centerStrength*.35)),(U=y.d3Force)==null||U.call(y,"z",PS(0).strength(l.centerStrength*.35)),(B=y.d3ReheatSimulation)==null||B.call(y)},[l,c,r]),$s.useEffect(()=>{if(!r.nodes.length)return;const y=[];return[900,1800,2800].forEach(b=>{y.push(setTimeout(()=>{var S;if(m.current)return;const M=g.current;M&&((S=M.zoomToFit)==null||S.call(M,700,80),b>=2800&&(m.current=!0))},b))}),()=>y.forEach(clearTimeout)},[r.nodes.length]),$s.useEffect(()=>{var S;const y=g.current;if(!y)return;const b=(S=y.scene)==null?void 0:S.call(y);if(!b)return;const M=n?855312:16250874;b.fog=new um(M,900,4200)},[n,r.nodes.length]);const x=y=>{var ne,ue;d(y);const b=g.current;if(!b)return;const M=h.get(y.id)??new Set,S=new Set([y.id,...M]),E=r.nodes.filter(_e=>S.has(_e.id)&&typeof _e.x=="number"&&typeof _e.y=="number"&&typeof _e.z=="number");if(E.length===0)return;let v=1/0,w=1/0,N=1/0,C=-1/0,F=-1/0,V=-1/0;for(const _e of E){const Ue=_e.x,Ae=_e.y,dt=_e.z;Ue<v&&(v=Ue),Ae<w&&(w=Ae),dt<N&&(N=dt),Ue>C&&(C=Ue),Ae>F&&(F=Ae),dt>V&&(V=dt)}const z=(v+C)/2,U=(w+F)/2,B=(N+V)/2,D=Math.max(C-v,F-w,V-N)/2,X=50,K=90,Z=D/Math.tan(X*Math.PI/360)*2.2,oe=Math.max(K,Z),Ee=(ne=b.camera)==null?void 0:ne.call(b);let ze=0,$=0,I=1;if(Ee){ze=Ee.position.x-z,$=Ee.position.y-U,I=Ee.position.z-B;const _e=Math.hypot(ze,$,I)||1;ze/=_e,$/=_e,I/=_e}(ue=b.cameraPosition)==null||ue.call(b,{x:z+ze*oe,y:U+$*oe,z:B+I*oe},{x:z,y:U,z:B},900)};return NS.jsx(rg,{ref:g,graphData:r,width:e,height:t,backgroundColor:n?"#0d0d10":"#f7f7fa",showNavInfo:!1,nodeId:"id",nodeLabel:y=>y.label,nodeColor:y=>i(y),nodeVal:y=>sS(y,c),nodeRelSize:4,nodeOpacity:.92,nodeResolution:16,linkColor:y=>s(y),linkWidth:y=>o(y),linkOpacity:.55,linkDirectionalArrowLength:y=>a?3.5:0,linkDirectionalArrowRelPos:.94,linkDirectionalArrowColor:()=>n?"rgba(180, 185, 200, 0.7)":"rgba(60, 65, 80, 0.7)",onNodeClick:y=>x(y),onNodeHover:y=>f(y),onBackgroundClick:p,cooldownTicks:180,d3AlphaDecay:.025,d3VelocityDecay:.3,enableNodeDrag:!0,enableNavigationControls:!0,controlType:"orbit",nodeThreeObjectExtend:!0,nodeThreeObject:y=>{const b=i(y),S=u(y.id)?n?"rgba(200, 210, 225, 0.35)":"rgba(60, 65, 80, 0.35)":n?"#eaf0fa":"#141826",E=_k(y.label,S,_),v=F0(y,c);return E.position.set(0,-(v+5),0),E.userData.baseColor=b,E}})}export{Sk as BrainCanvas3D};