@volter/model-editor 0.5.66 → 0.5.67

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 (200) hide show
  1. package/dist/.vite/manifest.json +1022 -1006
  2. package/dist/assets/AudioViewer-DVXaSSYC.js +1 -0
  3. package/dist/assets/{BVHLoader-xUHWsz84.js → BVHLoader-msuIvJVn.js} +1 -1
  4. package/dist/assets/ColladaLoader-BpvxwqkB.js +3 -0
  5. package/dist/assets/EntityModelDocument-BtlQZcoU.js +1 -0
  6. package/dist/assets/EnvironmentAssetDocument-BH3zT9rt.js +1 -0
  7. package/dist/assets/FBXLoader-CsdO937F.js +1 -0
  8. package/dist/assets/{GameplaySessionTimeline-HJLZUV4Q.js → GameplaySessionTimeline-Dko95kB7.js} +10 -10
  9. package/dist/assets/ImageViewer-CZ_RMER2.js +1 -0
  10. package/dist/assets/{InspectorCanvasPreview-CLDhscy0.js → InspectorCanvasPreview-BLecDHpc.js} +1 -1
  11. package/dist/assets/InspectorObjectPreview-CSIWwJQE.js +1 -0
  12. package/dist/assets/JsonAssetDocument-CGYSeJyl.js +2 -0
  13. package/dist/assets/{LineSegments2-C8H20K8w.js → LineSegments2-BKEsgiC8.js} +2 -2
  14. package/dist/assets/LiveModuleDocument-CIvS-SUT.js +2 -0
  15. package/dist/assets/LutAssetDocument-BA70uU3w.js +1 -0
  16. package/dist/assets/{MTLLoader-C-rA0fNF.js → MTLLoader-DNh2pFDc.js} +2 -2
  17. package/dist/assets/ModelAssetDocument-D0lNEhOg.js +1 -0
  18. package/dist/assets/NonThreeAuthoringBootstrap-C0pCfkJ4.js +2 -0
  19. package/dist/assets/OBJLoader-DPi99VIm.js +5 -0
  20. package/dist/assets/Object3DDocumentToolbar-PGYkZEwr.js +1 -0
  21. package/dist/assets/Object3DPreview-BROKXSTC.js +2 -0
  22. package/dist/assets/OnlineAssetDetail-lEHnhdUS.js +1 -0
  23. package/dist/assets/OrbitControls-smIenN60.js +1 -0
  24. package/dist/assets/PLYLoader-Cx9Yc9xe.js +2 -0
  25. package/dist/assets/QuarksAssetDocument-C_8eG4KG.js +2 -0
  26. package/dist/assets/RectAreaLightUniformsLib-Iam8rS8R.js +1 -0
  27. package/dist/assets/STLLoader-BaJkM-k1.js +1 -0
  28. package/dist/assets/{ShaderAssetDocument-qlLeb2S3.js → ShaderAssetDocument-Gdp7OCfv.js} +5 -5
  29. package/dist/assets/SourceAssetViewer-l72u0hOa.js +1 -0
  30. package/dist/assets/StageHost-CdzuP0NS.js +1179 -0
  31. package/dist/assets/TDSLoader-BskhMiUy.js +1 -0
  32. package/dist/assets/ToolObject3DPreview-CU5klD6l.js +1 -0
  33. package/dist/assets/Toolbar-DI0LGx25.js +1 -0
  34. package/dist/assets/TransientHint-myZtSdd6.js +1 -0
  35. package/dist/assets/VideoViewer-z0JPXPKa.js +1 -0
  36. package/dist/assets/ViewportShadingMenu-CVU2bU_3.js +1 -0
  37. package/dist/assets/animation-mixers.service-DSIsxWG5.js +1 -0
  38. package/dist/assets/animation-timeline.utility-BEgDQC04.js +1 -0
  39. package/dist/assets/asset-editor-persistence-BtRQI8t6.js +1 -0
  40. package/dist/assets/bitmap-label-Ct4k6ehY.js +1 -0
  41. package/dist/assets/{blender-emscripten-engine-CEsWgnR7.js → blender-emscripten-engine-BeWFjMn-.js} +1 -1
  42. package/dist/assets/blender-node-editor.document-C_kpsARB.js +1 -0
  43. package/dist/assets/{blender-properties-tab-C5tUuCSv.js → blender-properties-tab-B_XBg6S8.js} +3 -3
  44. package/dist/assets/blender-runtime-host-CYhl4T9S.js +4 -0
  45. package/dist/assets/{blender-runtime-skin-DMq0XAvO.js → blender-runtime-skin-Bk6uXECD.js} +98 -51
  46. package/dist/assets/blender-runtime.document-CAPDRCvN.js +12 -0
  47. package/dist/assets/blender-timeline.document-CcEymQyL.js +1 -0
  48. package/dist/assets/blender-uv-editor.document-DSPvSEuE.js +1 -0
  49. package/dist/assets/blender-version.status-CEu7vCi3.js +1 -0
  50. package/dist/assets/{blender-wali-engine-D3iKpzn9.js → blender-wali-engine-da698rDf.js} +1 -1
  51. package/dist/assets/blender.command-BCb_c9lw.js +1 -0
  52. package/dist/assets/blender.keymap-_rF_vRX8.js +1 -0
  53. package/dist/assets/{blender.status-ujwGU6dU.js → blender.status-DrasQhJV.js} +1 -1
  54. package/dist/assets/{blender.style-CxfbTFcE.js → blender.style-DaIh9SiA.js} +1 -1
  55. package/dist/assets/{client-DNXj_opT.js → client-mkWk8S65.js} +1 -1
  56. package/dist/assets/content-bounds-_QWiKD5_.js +85 -0
  57. package/dist/assets/{hosted-asset-materialization-BXM49Qkc.js → hosted-asset-materialization-hUS3IhTD.js} +2 -2
  58. package/dist/assets/index-0Lm0Nf1M.css +1 -0
  59. package/dist/assets/{index-CJbYy-CF.js → index-7vd2obXq.js} +2 -2
  60. package/dist/assets/{index-DgapqSPi.js → index-BRLA7zdc.js} +1 -1
  61. package/dist/assets/{index-BtfYaG4D.js → index-CQG6JOSy.js} +18 -18
  62. package/dist/assets/{index-CanA16PU.js → index-CnvSS9lU.js} +1 -1
  63. package/dist/assets/{index-Bge9JUr6.js → index-DYNMP0kE.js} +1 -1
  64. package/dist/assets/index-Dm_h-T4x.js +1406 -0
  65. package/dist/assets/{index-gHZae-lw.js → index-Dz8qGBZc.js} +1 -1
  66. package/dist/assets/{index-BncK9THk.js → index-Fv4R0cYr.js} +1 -1
  67. package/dist/assets/{index-IEjydI9d.js → index-f-MQ14bP.js} +1 -1
  68. package/dist/assets/{index-D2LwEE0L.js → index-jib6KJY8.js} +6 -6
  69. package/dist/assets/{index-DUqP1RMl.js → index-ux8XhRyW.js} +1 -1
  70. package/dist/assets/{jsx-runtime-DPjLkJKQ.js → jsx-runtime-CAUTK36e.js} +1 -1
  71. package/dist/assets/layered-pick-CT4HlEpW.js +1 -0
  72. package/dist/assets/live-mixers-B-bwLZ7c.js +1 -0
  73. package/dist/assets/model-inspection-DDZE59vp.js +1 -0
  74. package/dist/assets/models.finder-Caf-3Yix.js +1 -0
  75. package/dist/assets/product-DbFrUS6F.js +1 -0
  76. package/dist/assets/properties-bone-constraints.inspector-DB3Rc_Hf.js +1 -0
  77. package/dist/assets/properties-bone.inspector-B7f7H_Co.js +1 -0
  78. package/dist/assets/properties-collection.inspector-JCtV3h3Y.js +1 -0
  79. package/dist/assets/properties-constraints.inspector-Cs8MwS-1.js +1 -0
  80. package/dist/assets/properties-data.inspector-DKGiHu8O.js +1 -0
  81. package/dist/assets/properties-material.inspector-Dc18RI13.js +1 -0
  82. package/dist/assets/properties-modifiers.inspector-DvGvXq2v.js +1 -0
  83. package/dist/assets/properties-object.inspector-Bl9nrytP.js +1 -0
  84. package/dist/assets/properties-output.inspector-B6QsU94n.js +1 -0
  85. package/dist/assets/properties-particles.inspector-B1dMnZSA.js +1 -0
  86. package/dist/assets/properties-physics.inspector-BwfNykfW.js +1 -0
  87. package/dist/assets/properties-render.inspector-KrL2EiTH.js +1 -0
  88. package/dist/assets/properties-scene.inspector-CewQnyRt.js +1 -0
  89. package/dist/assets/properties-texture.inspector-BITMzY-f.js +1 -0
  90. package/dist/assets/properties-view-layer.inspector-BpkDbmcb.js +1 -0
  91. package/dist/assets/properties-world.inspector-DLRH45Oj.js +1 -0
  92. package/dist/assets/{react-18-DyywM-Z2.js → react-18-D335xReo.js} +1 -1
  93. package/dist/assets/{react-story-board-B9V-j_Y5.js → react-story-board-CkaP4mEG.js} +1 -1
  94. package/dist/assets/{session-CsR0lApe.js → session-CTXsU1lK.js} +176 -1
  95. package/dist/assets/{spark.module-gG1EsWx8.js → spark.module-DMQ9J7rT.js} +11 -11
  96. package/dist/assets/stage-keyboard-BY7u9_MB.js +1 -0
  97. package/dist/assets/stage-overlay-set-DRFcVd27.js +1 -0
  98. package/dist/assets/stage-presence-markers-D2IpuOAY.js +1 -0
  99. package/dist/assets/stage-transform-tools-BGcIULoe.js +1 -0
  100. package/dist/assets/story-capture-RSWY8I8h.js +1 -0
  101. package/dist/assets/three-integration.service-0EyPpd5f.js +4 -0
  102. package/dist/assets/{three.module-ZILb6uB7.js → three.module-CrYDk-Xr.js} +1 -1
  103. package/dist/assets/transform-mode-request-Cz6fzydi.js +1 -0
  104. package/dist/assets/transport-strip-Co-ZDkf-.js +1 -0
  105. package/dist/assets/{vgai-shared-fontawesome-CFSkqz69.js → vgai-shared-fontawesome-2ZSGa7vM.js} +1 -1
  106. package/dist/assets/vgai-shared-jsx-dev-runtime-hkPLeIJV.js +1 -0
  107. package/dist/assets/vgai-shared-jsx-runtime-CUvvjEqj.js +1 -0
  108. package/dist/assets/{vgai-shared-react-dom-client-S0ozfl6_.js → vgai-shared-react-dom-client-CS681GK2.js} +1 -1
  109. package/dist/assets/{vgai-shared-three-DzfWDqlp.js → vgai-shared-three-CLJ0K3jQ.js} +1 -1
  110. package/dist/assets/viewport-door-BdL0u5rd.js +1 -0
  111. package/dist/assets/viewport-editor-controls-BYaAZ_Ku.js +1 -0
  112. package/dist/assets/viewport-surface-status-yS6CrXH7.js +24 -0
  113. package/dist/assets/{worker-B7zhIsFh.js → worker-CC9Ug5Ei.js} +1 -1
  114. package/dist/assets/world-documents-B5IWN-ng.js +3 -0
  115. package/dist/vgai-shared-react.json +4 -4
  116. package/dist/vgai-shared-three.json +1 -1
  117. package/dist-node/cli.js +248 -209
  118. package/dist-node/create.js +77 -77
  119. package/package.json +10 -10
  120. package/src/index.ts +1 -0
  121. package/dist/assets/AudioViewer-CRWsJVYN.js +0 -1
  122. package/dist/assets/ColladaLoader-Ccy_gHsu.js +0 -3
  123. package/dist/assets/EntityModelDocument-Dal8YnLK.js +0 -1
  124. package/dist/assets/EnvironmentAssetDocument-DFOFYX5v.js +0 -1
  125. package/dist/assets/FBXLoader-Dh0pOBW2.js +0 -1
  126. package/dist/assets/ImageViewer-BzqBpqL-.js +0 -1
  127. package/dist/assets/InspectorObjectPreview-BUZEp4xS.js +0 -1
  128. package/dist/assets/JsonAssetDocument-DCkqRS0N.js +0 -2
  129. package/dist/assets/LiveModuleDocument-CuOBVz3A.js +0 -2
  130. package/dist/assets/LutAssetDocument-IyEir1rq.js +0 -1
  131. package/dist/assets/ModelAssetDocument-DNStNyCc.js +0 -1
  132. package/dist/assets/NonThreeAuthoringBootstrap-BE15Wpmw.js +0 -2
  133. package/dist/assets/OBJLoader-CopWRneC.js +0 -5
  134. package/dist/assets/Object3DDocumentToolbar-5Dv_8caG.js +0 -1
  135. package/dist/assets/Object3DPreview-C09u9uQZ.js +0 -2
  136. package/dist/assets/OnlineAssetDetail-DOPUI1iu.js +0 -1
  137. package/dist/assets/OrbitControls-DrFzvAAB.js +0 -1
  138. package/dist/assets/PLYLoader-D_esTZ2f.js +0 -2
  139. package/dist/assets/QuarksAssetDocument-BbSJ970L.js +0 -2
  140. package/dist/assets/RectAreaLightUniformsLib-u1ciScuw.js +0 -1
  141. package/dist/assets/STLLoader-Cl5I0sAi.js +0 -1
  142. package/dist/assets/SourceAssetViewer-DwhuqbA4.js +0 -1
  143. package/dist/assets/StageHost-D-o8MsFS.js +0 -1122
  144. package/dist/assets/TDSLoader-KKBg8ef1.js +0 -1
  145. package/dist/assets/ToolObject3DPreview-ILbch3kN.js +0 -1
  146. package/dist/assets/Toolbar-DYJjJKTt.js +0 -1
  147. package/dist/assets/TransientHint-D94hsJSR.js +0 -1
  148. package/dist/assets/VideoViewer-Bx3FPbgE.js +0 -1
  149. package/dist/assets/ViewportShadingMenu-B3N6hSdN.js +0 -1
  150. package/dist/assets/animation-mixers.service-N9HxGOMf.js +0 -1
  151. package/dist/assets/asset-editor-persistence-DGD05u26.js +0 -1
  152. package/dist/assets/blender-node-editor.document-BT2M622g.js +0 -1
  153. package/dist/assets/blender-runtime-host-4ufXy47O.js +0 -4
  154. package/dist/assets/blender-runtime.document-DeFQQsF6.js +0 -8
  155. package/dist/assets/blender-timeline.document-BnlSdxy0.js +0 -1
  156. package/dist/assets/blender-uv-editor.document-UC-XeNn0.js +0 -1
  157. package/dist/assets/blender-version.status-BZP39oH7.js +0 -1
  158. package/dist/assets/blender.command-IGP5wuda.js +0 -1
  159. package/dist/assets/blender.keymap-GAQgeklK.js +0 -1
  160. package/dist/assets/browserAll-2r3AVaAO.js +0 -14
  161. package/dist/assets/canvas-preview-frames-CO60PDM7.js +0 -5
  162. package/dist/assets/index-B4bmKkgY.css +0 -1
  163. package/dist/assets/index-cpXNKgvz.js +0 -1498
  164. package/dist/assets/live-mixers-BRkRHd6g.js +0 -1
  165. package/dist/assets/material-preview.view-DqNcpd_b.js +0 -1
  166. package/dist/assets/model-inspection-JC6gbV8Q.js +0 -1
  167. package/dist/assets/models.finder-BplPGS4I.js +0 -1
  168. package/dist/assets/product-CfZaqLpw.js +0 -1
  169. package/dist/assets/properties-bone-constraints.inspector-Di8kNtAi.js +0 -1
  170. package/dist/assets/properties-bone.inspector-CqAIKNsE.js +0 -1
  171. package/dist/assets/properties-collection.inspector-DpHC_fXW.js +0 -1
  172. package/dist/assets/properties-constraints.inspector-C7G7NOZU.js +0 -1
  173. package/dist/assets/properties-data.inspector-D1sUUst6.js +0 -1
  174. package/dist/assets/properties-material.inspector-BUSjc8tl.js +0 -1
  175. package/dist/assets/properties-modifiers.inspector-Sq9bcfFz.js +0 -1
  176. package/dist/assets/properties-object.inspector-BzqiU_29.js +0 -1
  177. package/dist/assets/properties-output.inspector-BWpFqvfT.js +0 -1
  178. package/dist/assets/properties-particles.inspector-DO1KoaTz.js +0 -1
  179. package/dist/assets/properties-physics.inspector-BgkrTNSA.js +0 -1
  180. package/dist/assets/properties-render.inspector-BU5NOVoQ.js +0 -1
  181. package/dist/assets/properties-scene.inspector-DbMErJ48.js +0 -1
  182. package/dist/assets/properties-texture.inspector-toPpEwqp.js +0 -1
  183. package/dist/assets/properties-view-layer.inspector-COpx9iEK.js +0 -1
  184. package/dist/assets/properties-world.inspector-CxU0DrYX.js +0 -1
  185. package/dist/assets/react-three-rapier.esm-CN6t4A7c.js +0 -1
  186. package/dist/assets/stage-keyboard-CzlqI0nh.js +0 -1
  187. package/dist/assets/stage-overlay-set-DQeskS16.js +0 -1
  188. package/dist/assets/stage-presence-markers-S1lMOwIa.js +0 -1
  189. package/dist/assets/stage-transform-tools-Cqtv-ZQ1.js +0 -1
  190. package/dist/assets/story-capture-DmIUyEQn.js +0 -1
  191. package/dist/assets/story-mount-turn-2IYGgHob.js +0 -1
  192. package/dist/assets/story-pixi-preview-aw8xQhvF.js +0 -1
  193. package/dist/assets/story-three-preview-DDmMjlI8.js +0 -37
  194. package/dist/assets/transform-mode-request-DSPwviXs.js +0 -1
  195. package/dist/assets/vgai-shared-jsx-dev-runtime-DFDKL7fx.js +0 -1
  196. package/dist/assets/vgai-shared-jsx-runtime-DIqBpTut.js +0 -1
  197. package/dist/assets/viewport-pick-context-DkawXbEi.js +0 -1
  198. package/dist/assets/viewport-surface-status-DuININWe.js +0 -20
  199. package/dist/assets/webworkerAll-CqQUotBj.js +0 -101
  200. package/dist/assets/world-documents-DkBqH8VU.js +0 -3
@@ -1,1122 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/spark.module-gG1EsWx8.js","assets/three.module-ZILb6uB7.js","assets/index-cpXNKgvz.js","assets/index-DaQZGF7d.js","assets/_commonjsHelpers-D6-XlEtG.js","assets/index-D_NuPfjr.js","assets/jsx-runtime-DPjLkJKQ.js","assets/index-CtzuWnCS.js","assets/index-CinJrH5C.js","assets/index-D2LwEE0L.js","assets/client-DNXj_opT.js","assets/index-B4bmKkgY.css","assets/index-BtfYaG4D.js","assets/stage-transform-tools-Cqtv-ZQ1.js","assets/Toolbar-DYJjJKTt.js","assets/transform-mode-request-DSPwviXs.js","assets/viewport-surface-status-DuININWe.js","assets/live-mixers-BRkRHd6g.js","assets/model-inspection-JC6gbV8Q.js","assets/clip-planes-CnAI6DZn.js","assets/OrbitControls-DrFzvAAB.js","assets/LineSegments2-C8H20K8w.js","assets/viewport-pick-context-DkawXbEi.js","assets/editor-presentation-activity-C7SNSmTd.js","assets/stage-overlay-set-DQeskS16.js","assets/TransientHint-D94hsJSR.js","assets/ViewportShadingMenu-B3N6hSdN.js","assets/stage-keyboard-CzlqI0nh.js","assets/stage-presence-markers-S1lMOwIa.js"])))=>i.map(i=>d[i]);
2
- import{g as Ct,bn as Dt,bs as J,bk as To,bl as _c,eh as vc,bg as $e,ei as he,ej as zr,ek as an,el as wc,em as Vr,en as Oo,dC as Zi,aC as Yt,br as Qi,eo as Qn,ep as xc,eq as bc,er as Sc,es as Mc,et as Cc,d0 as Ar,a2 as ol,b2 as Pc,eu as zc,ev as Ac,ew as ko,ex as Io,ey as Ro,aV as Fo,t as Gt,ez as Ec,eA as Tc,eB as Lo,dk as Bo,a4 as al,cW as Oc,a$ as ri,eC as Er,eD as Ns,eE as kc,cK as Ic,eF as Rc,eG as ll,eH as Fc,eI as No,ar as Lc,eJ as Tr,eK as Bc,cF as cl,a9 as Fe,aa as Le,aI as xe,ap as Nc,T as ln,eL as Hc,a8 as Wi,bS as Dc,eM as Uc,eN as Vc,eO as jc,eP as Gc,eQ as Wc,eR as Xc,A as Jc,eS as hl,cq as Yc,cv as qc,eT as Ho,eU as Do,eV as Uo,w as Vo,eW as Zc,eX as Qc,a6 as jo,bW as Go,eY as $c,eZ as Wo,e_ as Kc,e$ as th,f0 as eh,e6 as ih,f1 as sh,f2 as Xo,f3 as nh,f4 as rh,e3 as oh,aX as ah,f5 as Jo,f6 as lh,f7 as ch,cJ as hh,f8 as dh,az as uh,f9 as ph,fa as fh}from"./index-cpXNKgvz.js";import{a as O}from"./jsx-runtime-DPjLkJKQ.js";import{a as dl,i as ct,V as mh,O as gh,b as yh,w as _h,c as vh,s as Yo}from"./viewport-surface-status-DuININWe.js";import{r as F}from"./index-DaQZGF7d.js";import"./index-CtzuWnCS.js";import{a as ul}from"./live-mixers-BRkRHd6g.js";import{b2 as pl,p as jr,e as Hs,L as Mn,a6 as wh,j as vt,a8 as ei,aZ as Gr,bJ as xh,l as fl,h as D,C as bh,V as w,Q as bt,aC as $t,aD as ii,aL as He,bK as Et,b3 as ft,ak as De,aK as es,k as T,bL as qe,ba as Qt,bM as Xi,m as be,aA as ml,d as Ci,i as Wr,aG as we,aH as Rt,aw as Sh,U as Zt,r as is,al as ve,bB as xn,bD as Mh,bN as Ch,aV as Ph,aJ as Ft,bf as Or,aP as gl,aO as Pi,bO as yl,bP as zh,bQ as Ah,B as pe,bn as Xr,bR as Eh,b9 as Th,bS as Oh,a_ as kh,b7 as Ih,bC as Rh,b8 as Fh,a$ as _l,b6 as vl,aa as Si,g as wl,f as Ln,bT as Lh,bU as Bh,ao as Nh,bV as Hh,aF as Dh,bW as Uh,bX as Vh,b as Wt,bY as Jr,a as Ht,bZ as xl,br as jh,b_ as Gh,bq as Wh,bp as Xh,A as bl,I as Yr,P as qo,M as $n,b$ as Jh,bm as Yh,c0 as qh,c1 as Zh,c2 as Qh,c3 as $h,be as Kh,bg as Zo,c4 as td,aM as ed,c5 as Qo,S as id,t as $o,_ as sd,b1 as nd,a7 as rd,bw as od,ab as Ko}from"./three.module-ZILb6uB7.js";import{c as ad,i as ld,a as cd,b as hd,d as dd}from"./model-inspection-JC6gbV8Q.js";import"./index-D2LwEE0L.js";import{E as ta,a as ea,f as ud}from"./clip-planes-CnAI6DZn.js";import{O as pd}from"./OrbitControls-DrFzvAAB.js";import{b as Cn,L as Pn,a as zn}from"./LineSegments2-C8H20K8w.js";import{s as ia,g as fd}from"./viewport-pick-context-DkawXbEi.js";import{s as md,i as Kn}from"./editor-presentation-activity-C7SNSmTd.js";const Sl=30;function Ml(o,t,e){return o<t?t:o>e?e:o}function gd(o,t){const e=o.animations;if(e.length===0)return null;const i=new pl(o);let s=e[0];if(!s)return null;const n=a=>{i.stopAllAction();const l=i.clipAction(a);l.paused=!0,l.play(),s=a};n(s);const r=t.attach({id:o.uuid,label:o.name||s.name||"Clip",range:()=>({start:0,end:s?.duration??0,fps:Sl}),seek:a=>{i.setTime(Ml(a,0,s?.duration??0))},clips:()=>e.map(a=>({id:a.name,label:a.name})),setClip:a=>{const l=e.find(c=>c.name===a);l&&n(l)}});return()=>{r(),i.stopAllAction(),i.uncacheRoot(o)}}function yd(o,t){const e=ul(o);if(!e)return null;const i=[...e.clips.entries()];let s=i[0]?.[1];if(!s)return null;const n=a=>{e.mixer.stopAllAction();const l=e.mixer.clipAction(a);l.paused=!0,l.play(),s=a};return t.attach({id:o.uuid,label:o.name||s.name||"Animation",range:()=>({start:0,end:s?.duration??0,fps:Sl}),seek:a=>{e.mixer.setTime(Ml(a,0,s?.duration??0))},clips:()=>i.map(([a,l])=>({id:a,label:l.name||a})),setClip:a=>{const l=e.clips.get(a);l&&n(l)}})}function sa(o,t){const e=new Map,i=()=>{const s=new Set;o.traverse(n=>{if(e.has(n.uuid)){s.add(n.uuid);return}const r=yd(n,t)??gd(n,t);r&&(e.set(n.uuid,r),s.add(n.uuid))});for(const[n,r]of[...e])s.has(n)||(r(),e.delete(n))};return i(),{refresh:i,dispose:()=>{for(const s of e.values())s();e.clear()}}}let Mi=0,kr=[];function _d(){Mi+=1}function vd(){if(Mi=Math.max(0,Mi-1),Mi===0){const o=kr;kr=[];for(const t of o)t()}}function wd(){return Mi>0}function xd(){return Mi===0?Promise.resolve():new Promise(o=>{kr.push(o)})}const Oe=()=>globalThis.performance?.now()??Date.now();function bd(o,t){return o.length===0?0:o[Math.min(o.length-1,Math.floor((o.length-1)*t))]??0}function Sd(o=!1){const t=new Set,e=[],i=new Map,s=new Map,n=new Map;let r=[],a=[],l=o,c=!1,d=!1,h=0,f=0,u=0;const p=[];let m=0,y=0,_={gpuMs:null,drawCalls:0,triangles:0,geometries:0,textures:0,renderPasses:null},v={enabled:l,recording:d,fps:0,cpuMs:0,p95Ms:0,p99Ms:0,frames:[],phases:[],systems:[],components:[],render:_};function S(){const x=e.at(-1),C=e.slice();let b;const M=P=>(b??=C.map(z=>z.intervalMs).filter(z=>z>0).sort((z,H)=>z-H),bd(b,P));v={enabled:l,recording:d,fps:x?.intervalMs?1e3/x.intervalMs:0,cpuMs:x?.cpuMs??0,get p95Ms(){return M(.95)},get p99Ms(){return M(.99)},frames:C,phases:x?.phases??[],systems:[...s].map(([P,z])=>({name:P,ms:z})).sort((P,z)=>z.ms-P.ms),components:[...n].map(([P,z])=>({name:P,ms:z})).sort((P,z)=>z.ms-P.ms),render:_};for(const P of t)P()}return{get enabled(){return l},set enabled(x){l!==x&&(l=x,x&&!c&&(u=0),S())},get telemetryEnabled(){return c},set telemetryEnabled(x){if(c===x)return;const C=!l&&!c;c=x,x&&C&&(u=0),S()},get recording(){return d},startRecording(){const x=!l&&!c;l=!0,x&&(u=0),d=!0,e.length=0,S()},stopRecording(){d=!1,S()},clear(){e.length=0,S()},beginFrame(){!l&&!c||(i.clear(),s.clear(),n.clear(),r=[],a=[],p.length=0,_={gpuMs:null,drawCalls:0,triangles:0,geometries:0,textures:0,renderPasses:null},f=Oe())},beginPhase(){l&&p.push(Oe())},endPhase(x){if(!l)return;const C=p.pop()??f,b=Oe()-C,M=i.get(x);i.set(x,{ms:(M?.ms??0)+b,startMs:M?.startMs??C-f}),d&&performance.measure(`vgai.phase.${x}`,{start:C,duration:b})},systemObserver:{beginSystem(){l&&(m=Oe())},endSystem(x,C,b){if(!l)return;const M=Oe(),P=`${x} / ${C} / ${b}`;s.set(P,(s.get(P)??0)+M-m),r.push({name:P,phase:C,startMs:m-f,ms:M-m})}},beginComponent(){d&&(y=Oe())},endComponent(x,C=""){if(!d)return;const b=Oe();n.set(x,(n.get(x)??0)+b-y),a.push({name:x,phase:C,startMs:y-f,ms:b-y})},reportRender(x){l&&(_={gpuMs:x.gpuMs??_.gpuMs,drawCalls:_.drawCalls+x.drawCalls,triangles:_.triangles+x.triangles,geometries:_.geometries+x.geometries,textures:_.textures+x.textures,renderPasses:x.renderPasses===void 0?_.renderPasses:(_.renderPasses??0)+x.renderPasses})},endFrame(){if(!l&&!c)return;const x=Oe(),C=u===0?0:f-u;u=f;const b={id:++h,timestamp:x,intervalMs:C,cpuMs:x-f,phases:[...i].map(([M,{ms:P,startMs:z}])=>({name:M,ms:P,startMs:z})).sort((M,P)=>P.ms-M.ms),systems:r.slice(),components:a.slice(),render:{..._}};e.push(b),e.length>600&&e.splice(0,e.length-600),d&&performance.measure("vgai.frame",{start:f,duration:b.cpuMs}),S()},subscribe(x){return t.add(x),()=>{t.delete(x)}},getSnapshot(){return v},exportJSON(){return JSON.stringify({version:2,capturedAt:new Date().toISOString(),frames:e},null,2)}}}const Cl=256;function Md(o){const t=Math.min(1,Math.max(0,o));return t<=.0031308?t*12.92:1.055*t**(1/2.4)-.055}function tr(o,t,e){const i=Math.hypot(o,t,e)||1;return[o/i,t/i,e/i]}function Cd(o=Cl){const t=document.createElement("canvas");t.width=o,t.height=o;const e=t.getContext("2d");if(!e)return t;const i=e.createImageData(o,o),s=tr(-.45,.62,.64),n=tr(.65,-.35,.5),r=tr(s[0],s[1],s[2]+1),a=[.7,.69,.68],l=[.34,.4,.52],c=[.85,.88,1];for(let d=0;d<o;d++)for(let h=0;h<o;h++){const f=(h+.5)/o/.5-1,u=1-(d+.5)/o/.5,p=f*f+u*u,m=p>1,y=m?1/Math.sqrt(p):1,_=f*y,v=u*y,S=m?0:Math.sqrt(Math.max(0,1-p)),x=Math.max(0,_*s[0]+v*s[1]+S*s[2]),C=Math.max(0,_*n[0]+v*n[1]+S*n[2]),b=Math.max(0,_*r[0]+v*r[1]+S*r[2])**42*.5,M=(1-S)**3.2*.4,P=(d*o+h)*4;for(let z=0;z<3;z++){const H=a[z]*(.16+.8*x)+l[z]*.3*C+c[z]*M+b;i.data[P+z]=Math.round(Md(H)*255)}i.data[P+3]=255}return e.putImageData(i,0,0),t}function Pd(o=Cl){const t=new jr(Cd(o));return t.colorSpace=Hs,t.minFilter=Mn,t.magFilter=Mn,t.generateMipmaps=!1,t.needsUpdate=!0,t}function zd(o){return o.color?.clone()??new D(12502993)}function er(o,t){return o[t]??null}class Ad{_derived=new Map;_normals=new wh;_matcap=null;_matcapTexture=null;_overdraw=new vt({color:16777215,transparent:!0,opacity:.08,depthTest:!1,depthWrite:!1,blending:Gr,side:ei,toneMapped:!1});render(t,e,i,s=()=>!0){if(e==="solid"){i();return}const n=[];t.traverse(r=>{const a=r;!a.isMesh||!a.material||!s(a)||(n.push({mesh:a,material:a.material}),a.material=Array.isArray(a.material)?a.material.map(l=>this._materialFor(l,e)):this._materialFor(a.material,e))});try{i()}finally{for(const{mesh:r,material:a}of n)r.material=a}}dispose(){for(const t of this._derived.values())t.clay.dispose(),t.unlit.dispose(),t.wireframe.dispose();this._derived.clear(),this._normals.dispose(),this._overdraw.dispose(),this._matcap?.dispose(),this._matcapTexture?.dispose(),this._matcap=null,this._matcapTexture=null}_materialFor(t,e){if(e==="normals")return this._normals;if(e==="overdraw")return this._overdraw;if(e==="matcap")return this._matcap||(this._matcapTexture=Pd(),this._matcap=new xh({matcap:this._matcapTexture,toneMapped:!1})),this._matcap;let i=this._derived.get(t);if(!i){const s={color:zd(t),map:er(t,"map"),alphaMap:er(t,"alphaMap"),alphaTest:t.alphaTest,opacity:t.opacity,transparent:t.transparent,side:t.side,depthTest:t.depthTest,depthWrite:t.depthWrite,vertexColors:!!t.vertexColors,fog:t.fog??!0};i={clay:new fl({color:11450048,roughness:.82,metalness:0,flatShading:!0,alphaMap:er(t,"alphaMap"),alphaTest:t.alphaTest,opacity:t.opacity,transparent:t.transparent,side:t.side,depthTest:t.depthTest,depthWrite:t.depthWrite}),unlit:new vt(s),wireframe:new vt({...s,wireframe:!0})},this._derived.set(t,i)}return i[e]}}function An(o){const t=Ct(o,"constraints");return Array.isArray(t)?t.filter(e=>!!e&&typeof e=="object"&&typeof e.getSnapshot=="function"&&!!e.config):[]}function ts(o){const t=Ct(o,"reflectionProbe");if(!t||typeof t!="object")return null;const e=t;return e.config&&typeof e.recapture=="function"&&typeof e.getSnapshot=="function"?t:null}function Ir(o){const t=Ct(o,"triggerVolume");if(!t||typeof t!="object")return null;const{radius:e}=t;return typeof e=="number"&&Number.isFinite(e)&&e>0?{radius:e}:null}const Je=new $t,Tt=new w,ke=new w,lt=new bt,na={X:new w(1,0,0),Y:new w(0,1,0),Z:new w(0,0,1)},ir={type:"change"},ra={type:"mouseDown",mode:null},oa={type:"mouseUp",mode:null},aa={type:"objectChange"};let sr=class extends bh{constructor(t,e=null){super(void 0,e);const i=new Rd(this);this._root=i;const s=new Fd;this._gizmo=s,i.add(s);const n=new Ld;this._plane=n,i.add(n);const r=this;function a(S,x){let C=x;Object.defineProperty(r,S,{get:function(){return C!==void 0?C:x},set:function(b){C!==b&&(C=b,n[S]=b,s[S]=b,r.dispatchEvent({type:S+"-changed",value:b}),r.dispatchEvent(ir))}}),r[S]=x,n[S]=x,s[S]=x}a("camera",t),a("object",void 0),a("enabled",!0),a("axis",null),a("mode","translate"),a("translationSnap",null),a("rotationSnap",null),a("scaleSnap",null),a("space","world"),a("size",1),a("dragging",!1),a("showX",!0),a("showY",!0),a("showZ",!0),a("minX",-1/0),a("maxX",1/0),a("minY",-1/0),a("maxY",1/0),a("minZ",-1/0),a("maxZ",1/0);const l=new w,c=new w,d=new bt,h=new bt,f=new w,u=new bt,p=new w,m=new w,y=new w,_=0,v=new w;a("worldPosition",l),a("worldPositionStart",c),a("worldQuaternion",d),a("worldQuaternionStart",h),a("cameraPosition",f),a("cameraQuaternion",u),a("pointStart",p),a("pointEnd",m),a("rotationAxis",y),a("rotationAngle",_),a("eye",v),this._offset=new w,this._startNorm=new w,this._endNorm=new w,this._cameraScale=new w,this._parentPosition=new w,this._parentQuaternion=new bt,this._parentQuaternionInv=new bt,this._parentScale=new w,this._worldScaleStart=new w,this._worldQuaternionInv=new bt,this._worldScale=new w,this._positionStart=new w,this._quaternionStart=new bt,this._scaleStart=new w,this._getPointer=Ed.bind(this),this._onPointerDown=Od.bind(this),this._onPointerHover=Td.bind(this),this._onPointerMove=kd.bind(this),this._onPointerUp=Id.bind(this),e!==null&&this.connect(e)}connect(t){super.connect(t),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="auto"}getHelper(){return this._root}pointerHover(t){if(this.object===void 0||this.dragging===!0)return;t!==null&&Je.setFromCamera(t,this.camera);const e=nr(this._gizmo.picker[this.mode],Je);e?this.axis=e.object.name:this.axis=null}pointerDown(t){if(!(this.object===void 0||this.dragging===!0||t!=null&&t.button!==0)&&this.axis!==null){t!==null&&Je.setFromCamera(t,this.camera);const e=nr(this._plane,Je,!0);e&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(e.point).sub(this.worldPositionStart)),this.dragging=!0,ra.mode=this.mode,this.dispatchEvent(ra)}}pointerMove(t){const e=this.axis,i=this.mode,s=this.object;let n=this.space;if(i==="scale"?n="local":(e==="E"||e==="XYZE"||e==="XYZ")&&(n="world"),s===void 0||e===null||this.dragging===!1||t!==null&&t.button!==-1)return;t!==null&&Je.setFromCamera(t,this.camera);const r=nr(this._plane,Je,!0);if(r){if(this.pointEnd.copy(r.point).sub(this.worldPositionStart),i==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),n==="local"&&e!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),e.indexOf("X")===-1&&(this._offset.x=0),e.indexOf("Y")===-1&&(this._offset.y=0),e.indexOf("Z")===-1&&(this._offset.z=0),n==="local"&&e!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),s.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(n==="local"&&(s.position.applyQuaternion(lt.copy(this._quaternionStart).invert()),e.search("X")!==-1&&(s.position.x=Math.round(s.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(s.position.y=Math.round(s.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(s.position.z=Math.round(s.position.z/this.translationSnap)*this.translationSnap),s.position.applyQuaternion(this._quaternionStart)),n==="world"&&(s.parent&&s.position.add(Tt.setFromMatrixPosition(s.parent.matrixWorld)),e.search("X")!==-1&&(s.position.x=Math.round(s.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(s.position.y=Math.round(s.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(s.position.z=Math.round(s.position.z/this.translationSnap)*this.translationSnap),s.parent&&s.position.sub(Tt.setFromMatrixPosition(s.parent.matrixWorld)))),s.position.x=Math.max(this.minX,Math.min(this.maxX,s.position.x)),s.position.y=Math.max(this.minY,Math.min(this.maxY,s.position.y)),s.position.z=Math.max(this.minZ,Math.min(this.maxZ,s.position.z));else if(i==="scale"){if(e.search("XYZ")!==-1){let a=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(a*=-1),ke.set(a,a,a)}else Tt.copy(this.pointStart),ke.copy(this.pointEnd),Tt.applyQuaternion(this._worldQuaternionInv),ke.applyQuaternion(this._worldQuaternionInv),ke.divide(Tt),e.search("X")===-1&&(ke.x=1),e.search("Y")===-1&&(ke.y=1),e.search("Z")===-1&&(ke.z=1);s.scale.copy(this._scaleStart).multiply(ke),this.scaleSnap&&(e.search("X")!==-1&&(s.scale.x=Math.round(s.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Y")!==-1&&(s.scale.y=Math.round(s.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Z")!==-1&&(s.scale.z=Math.round(s.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(i==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const a=20/this.worldPosition.distanceTo(Tt.setFromMatrixPosition(this.camera.matrixWorld));let l=!1;e==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(Tt.copy(this.rotationAxis).cross(this.eye))*a):(e==="X"||e==="Y"||e==="Z")&&(this.rotationAxis.copy(na[e]),Tt.copy(na[e]),n==="local"&&Tt.applyQuaternion(this.worldQuaternion),Tt.cross(this.eye),Tt.length()===0?l=!0:this.rotationAngle=this._offset.dot(Tt.normalize())*a),(e==="E"||l)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),n==="local"&&e!=="E"&&e!=="XYZE"?(s.quaternion.copy(this._quaternionStart),s.quaternion.multiply(lt.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),s.quaternion.copy(lt.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),s.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(ir),this.dispatchEvent(aa)}}pointerUp(t){t!==null&&t.button!==0||(this.dragging&&this.axis!==null&&(oa.mode=this.mode,this.dispatchEvent(oa)),this.dragging=!1,this.axis=null)}dispose(){this.disconnect(),this._root.dispose()}attach(t){return this.object=t,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this._root.visible=!1,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(ir),this.dispatchEvent(aa),this.pointStart.copy(this.pointEnd))}getRaycaster(){return Je}getMode(){return this.mode}setMode(t){this.mode=t}setTranslationSnap(t){this.translationSnap=t}setRotationSnap(t){this.rotationSnap=t}setScaleSnap(t){this.scaleSnap=t}setSize(t){this.size=t}setSpace(t){this.space=t}setColors(t,e,i,s){const n=this._gizmo.materialLib;n.xAxis.color.set(t),n.yAxis.color.set(e),n.zAxis.color.set(i),n.active.color.set(s),n.xAxisTransparent.color.set(t),n.yAxisTransparent.color.set(e),n.zAxisTransparent.color.set(i),n.activeTransparent.color.set(s),n.xAxis._color&&n.xAxis._color.set(t),n.yAxis._color&&n.yAxis._color.set(e),n.zAxis._color&&n.zAxis._color.set(i),n.active._color&&n.active._color.set(s),n.xAxisTransparent._color&&n.xAxisTransparent._color.set(t),n.yAxisTransparent._color&&n.yAxisTransparent._color.set(e),n.zAxisTransparent._color&&n.zAxisTransparent._color.set(i),n.activeTransparent._color&&n.activeTransparent._color.set(s)}};function Ed(o){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:o.button};{const t=this.domElement.getBoundingClientRect();return{x:(o.clientX-t.left)/t.width*2-1,y:-(o.clientY-t.top)/t.height*2+1,button:o.button}}}function Td(o){if(this.enabled)switch(o.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(o));break}}function Od(o){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(o.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(o)),this.pointerDown(this._getPointer(o)))}function kd(o){this.enabled&&this.pointerMove(this._getPointer(o))}function Id(o){this.enabled&&(this.domElement.releasePointerCapture(o.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(o)))}function nr(o,t,e){const i=t.intersectObject(o,!0);for(let s=0;s<i.length;s++)if(i[s].object.visible||e)return i[s];return!1}const cn=new ml,nt=new w(0,1,0),la=new w(0,0,0),ca=new Ci,hn=new bt,bn=new bt,ae=new w,ha=new Ci,$i=new w(1,0,0),Ye=new w(0,1,0),Ki=new w(0,0,1),dn=new w,Ji=new w,Yi=new w;class Rd extends ii{constructor(t){super(),this.isTransformControlsRoot=!0,this.controls=t,this.visible=!1}updateMatrixWorld(t){const e=this.controls;e.object!==void 0&&(e.object.updateMatrixWorld(),e.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):e.object.parent.matrixWorld.decompose(e._parentPosition,e._parentQuaternion,e._parentScale),e.object.matrixWorld.decompose(e.worldPosition,e.worldQuaternion,e._worldScale),e._parentQuaternionInv.copy(e._parentQuaternion).invert(),e._worldQuaternionInv.copy(e.worldQuaternion).invert()),e.camera.updateMatrixWorld(),e.camera.matrixWorld.decompose(e.cameraPosition,e.cameraQuaternion,e._cameraScale),e.camera.isOrthographicCamera?e.camera.getWorldDirection(e.eye).negate():e.eye.copy(e.cameraPosition).sub(e.worldPosition).normalize(),super.updateMatrixWorld(t)}dispose(){this.traverse(function(t){t.geometry&&t.geometry.dispose(),t.material&&t.material.dispose()})}}class Fd extends ii{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const t=new vt({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),e=new He({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),i=t.clone();i.opacity=.15;const s=e.clone();s.opacity=.5;const n=t.clone();n.color.setHex(16711680);const r=t.clone();r.color.setHex(65280);const a=t.clone();a.color.setHex(255);const l=t.clone();l.color.setHex(16711680),l.opacity=.5;const c=t.clone();c.color.setHex(65280),c.opacity=.5;const d=t.clone();d.color.setHex(255),d.opacity=.5;const h=t.clone();h.opacity=.25;const f=t.clone();f.color.setHex(16776960),f.opacity=.25;const u=t.clone();u.color.setHex(16776960);const p=t.clone();p.color.setHex(7895160),this.materialLib={xAxis:n,yAxis:r,zAxis:a,active:u,xAxisTransparent:l,yAxisTransparent:c,zAxisTransparent:d,activeTransparent:f};const m=new Et(0,.04,.1,12);m.translate(0,.05,0);const y=new ft(.08,.08,.08);y.translate(0,.04,0);const _=new De;_.setAttribute("position",new es([0,0,0,1,0,0],3));const v=new Et(.0075,.0075,.5,3);v.translate(0,.25,0);function S(Z,ut){const Y=new Xi(Z,.0075,3,64,ut*Math.PI*2);return Y.rotateY(Math.PI/2),Y.rotateX(Math.PI/2),Y}function x(){const Z=new De;return Z.setAttribute("position",new es([0,0,0,1,1,1],3)),Z}const C={X:[[new T(m,n),[.5,0,0],[0,0,-Math.PI/2]],[new T(m,n),[-.5,0,0],[0,0,Math.PI/2]],[new T(v,n),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new T(m,r),[0,.5,0]],[new T(m,r),[0,-.5,0],[Math.PI,0,0]],[new T(v,r)]],Z:[[new T(m,a),[0,0,.5],[Math.PI/2,0,0]],[new T(m,a),[0,0,-.5],[-Math.PI/2,0,0]],[new T(v,a),null,[Math.PI/2,0,0]]],XYZ:[[new T(new qe(.1,0),h),[0,0,0]]],XY:[[new T(new ft(.15,.15,.01),d),[.15,.15,0]]],YZ:[[new T(new ft(.15,.15,.01),l),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new T(new ft(.15,.15,.01),c),[.15,0,.15],[-Math.PI/2,0,0]]]},b={X:[[new T(new Et(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new T(new Et(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new T(new Et(.2,0,.6,4),i),[0,.3,0]],[new T(new Et(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new T(new Et(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new T(new Et(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new T(new qe(.2,0),i)]],XY:[[new T(new ft(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new T(new ft(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new T(new ft(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]]},M={START:[[new T(new qe(.01,2),s),null,null,null,"helper"]],END:[[new T(new qe(.01,2),s),null,null,null,"helper"]],DELTA:[[new Qt(x(),s),null,null,null,"helper"]],X:[[new Qt(_,s),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new Qt(_,s),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new Qt(_,s),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},P={XYZE:[[new T(S(.5,1),p),null,[0,Math.PI/2,0]]],X:[[new T(S(.5,.5),n)]],Y:[[new T(S(.5,.5),r),null,[0,0,-Math.PI/2]]],Z:[[new T(S(.5,.5),a),null,[0,Math.PI/2,0]]],E:[[new T(S(.75,1),f),null,[0,Math.PI/2,0]]]},z={AXIS:[[new Qt(_,s),[-1e3,0,0],null,[1e6,1,1],"helper"]]},H={XYZE:[[new T(new be(.25,10,8),i)]],X:[[new T(new Xi(.5,.1,4,24),i),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new T(new Xi(.5,.1,4,24),i),[0,0,0],[Math.PI/2,0,0]]],Z:[[new T(new Xi(.5,.1,4,24),i),[0,0,0],[0,0,-Math.PI/2]]],E:[[new T(new Xi(.75,.1,2,24),i)]]},G={X:[[new T(y,n),[.5,0,0],[0,0,-Math.PI/2]],[new T(v,n),[0,0,0],[0,0,-Math.PI/2]],[new T(y,n),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new T(y,r),[0,.5,0]],[new T(v,r)],[new T(y,r),[0,-.5,0],[0,0,Math.PI]]],Z:[[new T(y,a),[0,0,.5],[Math.PI/2,0,0]],[new T(v,a),[0,0,0],[Math.PI/2,0,0]],[new T(y,a),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new T(new ft(.15,.15,.01),d),[.15,.15,0]]],YZ:[[new T(new ft(.15,.15,.01),l),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new T(new ft(.15,.15,.01),c),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new T(new ft(.1,.1,.1),h)]]},ht={X:[[new T(new Et(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new T(new Et(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new T(new Et(.2,0,.6,4),i),[0,.3,0]],[new T(new Et(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new T(new Et(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new T(new Et(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new T(new ft(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new T(new ft(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new T(new ft(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new T(new ft(.2,.2,.2),i),[0,0,0]]]},rt={X:[[new Qt(_,s),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new Qt(_,s),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new Qt(_,s),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function ot(Z){const ut=new ii;for(const Y in Z)for(let pt=Z[Y].length;pt--;){const K=Z[Y][pt][0].clone(),mt=Z[Y][pt][1],gt=Z[Y][pt][2],zt=Z[Y][pt][3],Lt=Z[Y][pt][4];K.name=Y,K.tag=Lt,mt&&K.position.set(mt[0],mt[1],mt[2]),gt&&K.rotation.set(gt[0],gt[1],gt[2]),zt&&K.scale.set(zt[0],zt[1],zt[2]),K.updateMatrix();const kt=K.geometry.clone();kt.applyMatrix4(K.matrix),K.geometry=kt,K.renderOrder=1/0,K.position.set(0,0,0),K.rotation.set(0,0,0),K.scale.set(1,1,1),ut.add(K)}return ut}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=ot(C)),this.add(this.gizmo.rotate=ot(P)),this.add(this.gizmo.scale=ot(G)),this.add(this.picker.translate=ot(b)),this.add(this.picker.rotate=ot(H)),this.add(this.picker.scale=ot(ht)),this.add(this.helper.translate=ot(M)),this.add(this.helper.rotate=ot(z)),this.add(this.helper.scale=ot(rt)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(t){const i=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:bn;this.gizmo.translate.visible=this.mode==="translate",this.gizmo.rotate.visible=this.mode==="rotate",this.gizmo.scale.visible=this.mode==="scale",this.helper.translate.visible=this.mode==="translate",this.helper.rotate.visible=this.mode==="rotate",this.helper.scale.visible=this.mode==="scale";let s=[];s=s.concat(this.picker[this.mode].children),s=s.concat(this.gizmo[this.mode].children),s=s.concat(this.helper[this.mode].children);for(let n=0;n<s.length;n++){const r=s[n];r.visible=!0,r.rotation.set(0,0,0),r.position.copy(this.worldPosition);let a;if(this.camera.isOrthographicCamera?a=(this.camera.top-this.camera.bottom)/this.camera.zoom:a=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),r.scale.set(1,1,1).multiplyScalar(a*this.size/4),r.tag==="helper"){r.visible=!1,r.name==="AXIS"?(r.visible=!!this.axis,this.axis==="X"&&(lt.setFromEuler(cn.set(0,0,0)),r.quaternion.copy(i).multiply(lt),Math.abs(nt.copy($i).applyQuaternion(i).dot(this.eye))>.9&&(r.visible=!1)),this.axis==="Y"&&(lt.setFromEuler(cn.set(0,0,Math.PI/2)),r.quaternion.copy(i).multiply(lt),Math.abs(nt.copy(Ye).applyQuaternion(i).dot(this.eye))>.9&&(r.visible=!1)),this.axis==="Z"&&(lt.setFromEuler(cn.set(0,Math.PI/2,0)),r.quaternion.copy(i).multiply(lt),Math.abs(nt.copy(Ki).applyQuaternion(i).dot(this.eye))>.9&&(r.visible=!1)),this.axis==="XYZE"&&(lt.setFromEuler(cn.set(0,Math.PI/2,0)),nt.copy(this.rotationAxis),r.quaternion.setFromRotationMatrix(ca.lookAt(la,nt,Ye)),r.quaternion.multiply(lt),r.visible=this.dragging),this.axis==="E"&&(r.visible=!1)):r.name==="START"?(r.position.copy(this.worldPositionStart),r.visible=this.dragging):r.name==="END"?(r.position.copy(this.worldPosition),r.visible=this.dragging):r.name==="DELTA"?(r.position.copy(this.worldPositionStart),r.quaternion.copy(this.worldQuaternionStart),Tt.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),Tt.applyQuaternion(this.worldQuaternionStart.clone().invert()),r.scale.copy(Tt),r.visible=this.dragging):(r.quaternion.copy(i),this.dragging?r.position.copy(this.worldPositionStart):r.position.copy(this.worldPosition),this.axis&&(r.visible=this.axis.search(r.name)!==-1));continue}r.quaternion.copy(i),this.mode==="translate"||this.mode==="scale"?(r.name==="X"&&Math.abs(nt.copy($i).applyQuaternion(i).dot(this.eye))>.99&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name==="Y"&&Math.abs(nt.copy(Ye).applyQuaternion(i).dot(this.eye))>.99&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name==="Z"&&Math.abs(nt.copy(Ki).applyQuaternion(i).dot(this.eye))>.99&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name==="XY"&&Math.abs(nt.copy(Ki).applyQuaternion(i).dot(this.eye))<.2&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name==="YZ"&&Math.abs(nt.copy($i).applyQuaternion(i).dot(this.eye))<.2&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name==="XZ"&&Math.abs(nt.copy(Ye).applyQuaternion(i).dot(this.eye))<.2&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1)):this.mode==="rotate"&&(hn.copy(i),nt.copy(this.eye).applyQuaternion(lt.copy(i).invert()),r.name.search("E")!==-1&&r.quaternion.setFromRotationMatrix(ca.lookAt(this.eye,la,Ye)),r.name==="X"&&(lt.setFromAxisAngle($i,Math.atan2(-nt.y,nt.z)),lt.multiplyQuaternions(hn,lt),r.quaternion.copy(lt)),r.name==="Y"&&(lt.setFromAxisAngle(Ye,Math.atan2(nt.x,nt.z)),lt.multiplyQuaternions(hn,lt),r.quaternion.copy(lt)),r.name==="Z"&&(lt.setFromAxisAngle(Ki,Math.atan2(nt.y,nt.x)),lt.multiplyQuaternions(hn,lt),r.quaternion.copy(lt))),r.visible=r.visible&&(r.name.indexOf("X")===-1||this.showX),r.visible=r.visible&&(r.name.indexOf("Y")===-1||this.showY),r.visible=r.visible&&(r.name.indexOf("Z")===-1||this.showZ),r.visible=r.visible&&(r.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),r.material._color=r.material._color||r.material.color.clone(),r.material._opacity=r.material._opacity||r.material.opacity,r.material.color.copy(r.material._color),r.material.opacity=r.material._opacity,this.enabled&&this.axis&&(r.name===this.axis?(r.material.color.copy(this.materialLib.active.color),r.material.opacity=1):this.axis.split("").some(function(l){return r.name===l})&&(r.material.color.copy(this.materialLib.active.color),r.material.opacity=1))}super.updateMatrixWorld(t)}}class Ld extends T{constructor(){super(new Wr(1e5,1e5,2,2),new vt({visible:!1,wireframe:!0,side:ei,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(t){let e=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(e="local"),dn.copy($i).applyQuaternion(e==="local"?this.worldQuaternion:bn),Ji.copy(Ye).applyQuaternion(e==="local"?this.worldQuaternion:bn),Yi.copy(Ki).applyQuaternion(e==="local"?this.worldQuaternion:bn),nt.copy(Ji),this.mode){case"translate":case"scale":switch(this.axis){case"X":nt.copy(this.eye).cross(dn),ae.copy(dn).cross(nt);break;case"Y":nt.copy(this.eye).cross(Ji),ae.copy(Ji).cross(nt);break;case"Z":nt.copy(this.eye).cross(Yi),ae.copy(Yi).cross(nt);break;case"XY":ae.copy(Yi);break;case"YZ":ae.copy(dn);break;case"XZ":nt.copy(Yi),ae.copy(Ji);break;case"XYZ":case"E":ae.set(0,0,0);break}break;case"rotate":default:ae.set(0,0,0)}ae.length()===0?this.quaternion.copy(this.cameraQuaternion):(ha.lookAt(Tt.set(0,0,0),ae,nt),this.quaternion.setFromRotationMatrix(ha)),super.updateMatrixWorld(t)}}const At=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let da=1234567;const Pl=Math.PI/180,zl=180/Math.PI;function Bd(){const o=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(At[o&255]+At[o>>8&255]+At[o>>16&255]+At[o>>24&255]+"-"+At[t&255]+At[t>>8&255]+"-"+At[t>>16&15|64]+At[t>>24&255]+"-"+At[e&63|128]+At[e>>8&255]+"-"+At[e>>16&255]+At[e>>24&255]+At[i&255]+At[i>>8&255]+At[i>>16&255]+At[i>>24&255]).toLowerCase()}function de(o,t,e){return Math.max(t,Math.min(e,o))}function Al(o,t){return(o%t+t)%t}function Nd(o,t,e,i,s){return i+(o-t)*(s-i)/(e-t)}function Hd(o,t,e){return o!==t?(e-o)/(t-o):0}function El(o,t,e){return(1-e)*o+e*t}function Dd(o,t,e,i){return El(o,t,1-Math.exp(-e*i))}function Ud(o,t=1){return t-Math.abs(Al(o,t*2)-t)}function Vd(o,t,e){return o<=t?0:o>=e?1:(o=(o-t)/(e-t),o*o*(3-2*o))}function jd(o,t,e){return o<=t?0:o>=e?1:(o=(o-t)/(e-t),o*o*o*(o*(o*6-15)+10))}function Gd(o,t){return o+Math.floor(Math.random()*(t-o+1))}function Wd(o,t){return o+Math.random()*(t-o)}function Xd(o){return o*(.5-Math.random())}function Jd(o){o!==void 0&&(da=o);let t=da+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function Yd(o){return o*Pl}function qd(o){return o*zl}function Zd(o){return(o&o-1)===0&&o!==0}function Qd(o){return Math.pow(2,Math.ceil(Math.log(o)/Math.LN2))}function $d(o){return Math.pow(2,Math.floor(Math.log(o)/Math.LN2))}function Kd(o,t,e,i,s){const n=Math.cos,r=Math.sin,a=n(e/2),l=r(e/2),c=n((t+i)/2),d=r((t+i)/2),h=n((t-i)/2),f=r((t-i)/2),u=n((i-t)/2),p=r((i-t)/2);switch(s){case"XYX":o.set(a*d,l*h,l*f,a*c);break;case"YZY":o.set(l*f,a*d,l*h,a*c);break;case"ZXZ":o.set(l*h,l*f,a*d,a*c);break;case"XZX":o.set(a*d,l*p,l*u,a*c);break;case"YXY":o.set(l*u,a*d,l*p,a*c);break;case"ZYZ":o.set(l*p,l*u,a*d,a*c);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+s)}}function tu(o,t){switch(t.constructor){case Float32Array:return o;case Uint32Array:return o/4294967295;case Uint16Array:return o/65535;case Uint8Array:return o/255;case Int32Array:return Math.max(o/2147483647,-1);case Int16Array:return Math.max(o/32767,-1);case Int8Array:return Math.max(o/127,-1);default:throw new Error("Invalid component type.")}}function eu(o,t){switch(t.constructor){case Float32Array:return o;case Uint32Array:return Math.round(o*4294967295);case Uint16Array:return Math.round(o*65535);case Uint8Array:return Math.round(o*255);case Int32Array:return Math.round(o*2147483647);case Int16Array:return Math.round(o*32767);case Int8Array:return Math.round(o*127);default:throw new Error("Invalid component type.")}}const Ri={DEG2RAD:Pl,RAD2DEG:zl,generateUUID:Bd,clamp:de,euclideanModulo:Al,mapLinear:Nd,inverseLerp:Hd,lerp:El,damp:Dd,pingpong:Ud,smoothstep:Vd,smootherstep:jd,randInt:Gd,randFloat:Wd,randFloatSpread:Xd,seededRandom:Jd,degToRad:Yd,radToDeg:qd,isPowerOfTwo:Zd,ceilPowerOfTwo:Qd,floorPowerOfTwo:$d,setQuaternionFromProperEuler:Kd,normalize:eu,denormalize:tu};class Q{constructor(t=0,e=0,i=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,n,r,a){let l=i[s+0],c=i[s+1],d=i[s+2],h=i[s+3];const f=n[r+0],u=n[r+1],p=n[r+2],m=n[r+3];if(a===0){t[e+0]=l,t[e+1]=c,t[e+2]=d,t[e+3]=h;return}if(a===1){t[e+0]=f,t[e+1]=u,t[e+2]=p,t[e+3]=m;return}if(h!==m||l!==f||c!==u||d!==p){let y=1-a;const _=l*f+c*u+d*p+h*m,v=_>=0?1:-1,S=1-_*_;if(S>Number.EPSILON){const C=Math.sqrt(S),b=Math.atan2(C,_*v);y=Math.sin(y*b)/C,a=Math.sin(a*b)/C}const x=a*v;if(l=l*y+f*x,c=c*y+u*x,d=d*y+p*x,h=h*y+m*x,y===1-a){const C=1/Math.sqrt(l*l+c*c+d*d+h*h);l*=C,c*=C,d*=C,h*=C}}t[e]=l,t[e+1]=c,t[e+2]=d,t[e+3]=h}static multiplyQuaternionsFlat(t,e,i,s,n,r){const a=i[s],l=i[s+1],c=i[s+2],d=i[s+3],h=n[r],f=n[r+1],u=n[r+2],p=n[r+3];return t[e]=a*p+d*h+l*u-c*f,t[e+1]=l*p+d*f+c*h-a*u,t[e+2]=c*p+d*u+a*f-l*h,t[e+3]=d*p-a*h-l*f-c*u,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,i,s){return this._x=t,this._y=e,this._z=i,this._w=s,this._onChangeCallback(),this}clone(){return new Q(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const i=t._x,s=t._y,n=t._z,r=t._order,a=Math.cos,l=Math.sin,c=a(i/2),d=a(s/2),h=a(n/2),f=l(i/2),u=l(s/2),p=l(n/2);switch(r){case"XYZ":this._x=f*d*h+c*u*p,this._y=c*u*h-f*d*p,this._z=c*d*p+f*u*h,this._w=c*d*h-f*u*p;break;case"YXZ":this._x=f*d*h+c*u*p,this._y=c*u*h-f*d*p,this._z=c*d*p-f*u*h,this._w=c*d*h+f*u*p;break;case"ZXY":this._x=f*d*h-c*u*p,this._y=c*u*h+f*d*p,this._z=c*d*p+f*u*h,this._w=c*d*h-f*u*p;break;case"ZYX":this._x=f*d*h-c*u*p,this._y=c*u*h+f*d*p,this._z=c*d*p-f*u*h,this._w=c*d*h+f*u*p;break;case"YZX":this._x=f*d*h+c*u*p,this._y=c*u*h+f*d*p,this._z=c*d*p-f*u*h,this._w=c*d*h-f*u*p;break;case"XZY":this._x=f*d*h-c*u*p,this._y=c*u*h-f*d*p,this._z=c*d*p+f*u*h,this._w=c*d*h+f*u*p;break;default:console.warn("../math.Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,s=Math.sin(i);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],s=e[4],n=e[8],r=e[1],a=e[5],l=e[9],c=e[2],d=e[6],h=e[10],f=i+a+h;if(f>0){const u=.5/Math.sqrt(f+1);this._w=.25/u,this._x=(d-l)*u,this._y=(n-c)*u,this._z=(r-s)*u}else if(i>a&&i>h){const u=2*Math.sqrt(1+i-a-h);this._w=(d-l)/u,this._x=.25*u,this._y=(s+r)/u,this._z=(n+c)/u}else if(a>h){const u=2*Math.sqrt(1+a-i-h);this._w=(n-c)/u,this._x=(s+r)/u,this._y=.25*u,this._z=(l+d)/u}else{const u=2*Math.sqrt(1+h-i-a);this._w=(r-s)/u,this._x=(n+c)/u,this._y=(l+d)/u,this._z=.25*u}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<Number.EPSILON?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(de(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const s=Math.min(1,e/i);return this.slerp(t,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const i=t._x,s=t._y,n=t._z,r=t._w,a=e._x,l=e._y,c=e._z,d=e._w;return this._x=i*d+r*a+s*c-n*l,this._y=s*d+r*l+n*a-i*c,this._z=n*d+r*c+i*l-s*a,this._w=r*d-i*a-s*l-n*c,this._onChangeCallback(),this}slerp(t,e){if(e===0)return this;if(e===1)return this.copy(t);const i=this._x,s=this._y,n=this._z,r=this._w;let a=r*t._w+i*t._x+s*t._y+n*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=r,this._x=i,this._y=s,this._z=n,this;const l=1-a*a;if(l<=Number.EPSILON){const u=1-e;return this._w=u*r+e*this._w,this._x=u*i+e*this._x,this._y=u*s+e*this._y,this._z=u*n+e*this._z,this.normalize(),this}const c=Math.sqrt(l),d=Math.atan2(c,a),h=Math.sin((1-e)*d)/c,f=Math.sin(e*d)/c;return this._w=r*h+this._w*f,this._x=i*h+this._x*f,this._y=s*h+this._y*f,this._z=n*h+this._z*f,this._onChangeCallback(),this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),s=Math.sqrt(1-i),n=Math.sqrt(i);return this.set(s*Math.sin(t),s*Math.cos(t),n*Math.sin(e),n*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class R{constructor(t=0,e=0,i=0){this.isVector3=!0,R.prototype.isVector3=!0,this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(i=this.z),this.x=t,this.y=e,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new R(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(ua.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(ua.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6]*s,this.y=n[1]*e+n[4]*i+n[7]*s,this.z=n[2]*e+n[5]*i+n[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=t.elements,r=1/(n[3]*e+n[7]*i+n[11]*s+n[15]);return this.x=(n[0]*e+n[4]*i+n[8]*s+n[12])*r,this.y=(n[1]*e+n[5]*i+n[9]*s+n[13])*r,this.z=(n[2]*e+n[6]*i+n[10]*s+n[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,n=t.x,r=t.y,a=t.z,l=t.w,c=2*(r*s-a*i),d=2*(a*e-n*s),h=2*(n*i-r*e);return this.x=e+l*c+r*h-a*d,this.y=i+l*d+a*c-n*h,this.z=s+l*h+n*d-r*c,this}transformDirection(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[4]*i+n[8]*s,this.y=n[1]*e+n[5]*i+n[9]*s,this.z=n[2]*e+n[6]*i+n[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,s=t.y,n=t.z,r=e.x,a=e.y,l=e.z;return this.x=s*l-n*a,this.y=n*r-i*l,this.z=i*a-s*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return rr.copy(this).projectOnVector(t),this.sub(rr)}reflect(t){return this.sub(rr.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(de(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return e*e+i*i+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSphericalCoords(t,e,i){const s=Math.sin(e)*t;return this.x=s*Math.sin(i),this.y=Math.cos(e)*t,this.z=s*Math.cos(i),this}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this.z=Math.abs(this.z),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const rr=new R,ua=new Q,un=2e3,pa=2001;class te{constructor(t,e,i,s,n,r,a,l,c,d,h,f,u,p,m,y){this.isMatrix4=!0,te.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,l,c,d,h,f,u,p,m,y)}extractPosition(t){return console.warn("THREE.Matrix4: .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(t)}multiplyToArray(t,e,i){return console.error("THREE.Matrix4: .multiplyToArray() has been removed."),this}setRotationFromQuaternion(t){return this.makeRotationFromQuaternion(t)}set(t,e,i,s,n,r,a,l,c,d,h,f,u,p,m,y){const _=this.elements;return _[0]=t,_[4]=e,_[8]=i,_[12]=s,_[1]=n,_[5]=r,_[9]=a,_[13]=l,_[2]=c,_[6]=d,_[10]=h,_[14]=f,_[3]=u,_[7]=p,_[11]=m,_[15]=y,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 te().fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,i){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,i=t.elements,s=1/yi.setFromMatrixColumn(t,0).length(),n=1/yi.setFromMatrixColumn(t,1).length(),r=1/yi.setFromMatrixColumn(t,2).length();return e[0]=i[0]*s,e[1]=i[1]*s,e[2]=i[2]*s,e[3]=0,e[4]=i[4]*n,e[5]=i[5]*n,e[6]=i[6]*n,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,s=t.y,n=t.z,r=Math.cos(i),a=Math.sin(i),l=Math.cos(s),c=Math.sin(s),d=Math.cos(n),h=Math.sin(n);if(t.order==="XYZ"){const f=r*d,u=r*h,p=a*d,m=a*h;e[0]=l*d,e[4]=-l*h,e[8]=c,e[1]=u+p*c,e[5]=f-m*c,e[9]=-a*l,e[2]=m-f*c,e[6]=p+u*c,e[10]=r*l}else if(t.order==="YXZ"){const f=l*d,u=l*h,p=c*d,m=c*h;e[0]=f+m*a,e[4]=p*a-u,e[8]=r*c,e[1]=r*h,e[5]=r*d,e[9]=-a,e[2]=u*a-p,e[6]=m+f*a,e[10]=r*l}else if(t.order==="ZXY"){const f=l*d,u=l*h,p=c*d,m=c*h;e[0]=f-m*a,e[4]=-r*h,e[8]=p+u*a,e[1]=u+p*a,e[5]=r*d,e[9]=m-f*a,e[2]=-r*c,e[6]=a,e[10]=r*l}else if(t.order==="ZYX"){const f=r*d,u=r*h,p=a*d,m=a*h;e[0]=l*d,e[4]=p*c-u,e[8]=f*c+m,e[1]=l*h,e[5]=m*c+f,e[9]=u*c-p,e[2]=-c,e[6]=a*l,e[10]=r*l}else if(t.order==="YZX"){const f=r*l,u=r*c,p=a*l,m=a*c;e[0]=l*d,e[4]=m-f*h,e[8]=p*h+u,e[1]=h,e[5]=r*d,e[9]=-a*d,e[2]=-c*d,e[6]=u*h+p,e[10]=f-m*h}else if(t.order==="XZY"){const f=r*l,u=r*c,p=a*l,m=a*c;e[0]=l*d,e[4]=-h,e[8]=c*d,e[1]=f*h+m,e[5]=r*d,e[9]=u*h-p,e[2]=p*h-u,e[6]=a*d,e[10]=m*h+f}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(iu,t,su)}lookAt(t,e,i){const s=this.elements;return Nt.subVectors(t,e),Nt.lengthSq()===0&&(Nt.z=1),Nt.normalize(),Ie.crossVectors(i,Nt),Ie.lengthSq()===0&&(Math.abs(i.z)===1?Nt.x+=1e-4:Nt.z+=1e-4,Nt.normalize(),Ie.crossVectors(i,Nt)),Ie.normalize(),pn.crossVectors(Nt,Ie),s[0]=Ie.x,s[4]=pn.x,s[8]=Nt.x,s[1]=Ie.y,s[5]=pn.y,s[9]=Nt.y,s[2]=Ie.z,s[6]=pn.z,s[10]=Nt.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[4],l=i[8],c=i[12],d=i[1],h=i[5],f=i[9],u=i[13],p=i[2],m=i[6],y=i[10],_=i[14],v=i[3],S=i[7],x=i[11],C=i[15],b=s[0],M=s[4],P=s[8],z=s[12],H=s[1],G=s[5],ht=s[9],rt=s[13],ot=s[2],Z=s[6],ut=s[10],Y=s[14],pt=s[3],K=s[7],mt=s[11],gt=s[15];return n[0]=r*b+a*H+l*ot+c*pt,n[4]=r*M+a*G+l*Z+c*K,n[8]=r*P+a*ht+l*ut+c*mt,n[12]=r*z+a*rt+l*Y+c*gt,n[1]=d*b+h*H+f*ot+u*pt,n[5]=d*M+h*G+f*Z+u*K,n[9]=d*P+h*ht+f*ut+u*mt,n[13]=d*z+h*rt+f*Y+u*gt,n[2]=p*b+m*H+y*ot+_*pt,n[6]=p*M+m*G+y*Z+_*K,n[10]=p*P+m*ht+y*ut+_*mt,n[14]=p*z+m*rt+y*Y+_*gt,n[3]=v*b+S*H+x*ot+C*pt,n[7]=v*M+S*G+x*Z+C*K,n[11]=v*P+S*ht+x*ut+C*mt,n[15]=v*z+S*rt+x*Y+C*gt,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[4],s=t[8],n=t[12],r=t[1],a=t[5],l=t[9],c=t[13],d=t[2],h=t[6],f=t[10],u=t[14],p=t[3],m=t[7],y=t[11],_=t[15];return p*(+n*l*h-s*c*h-n*a*f+i*c*f+s*a*u-i*l*u)+m*(+e*l*u-e*c*f+n*r*f-s*r*u+s*c*d-n*l*d)+y*(+e*c*h-e*a*u-n*r*h+i*r*u+n*a*d-i*c*d)+_*(-s*a*d-e*l*h+e*a*f+s*r*h-i*r*f+i*l*d)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,i){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],l=t[6],c=t[7],d=t[8],h=t[9],f=t[10],u=t[11],p=t[12],m=t[13],y=t[14],_=t[15],v=h*y*c-m*f*c+m*l*u-a*y*u-h*l*_+a*f*_,S=p*f*c-d*y*c-p*l*u+r*y*u+d*l*_-r*f*_,x=d*m*c-p*h*c+p*a*u-r*m*u-d*a*_+r*h*_,C=p*h*l-d*m*l-p*a*f+r*m*f+d*a*y-r*h*y,b=e*v+i*S+s*x+n*C;if(b===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const M=1/b;return t[0]=v*M,t[1]=(m*f*n-h*y*n-m*s*u+i*y*u+h*s*_-i*f*_)*M,t[2]=(a*y*n-m*l*n+m*s*c-i*y*c-a*s*_+i*l*_)*M,t[3]=(h*l*n-a*f*n-h*s*c+i*f*c+a*s*u-i*l*u)*M,t[4]=S*M,t[5]=(d*y*n-p*f*n+p*s*u-e*y*u-d*s*_+e*f*_)*M,t[6]=(p*l*n-r*y*n-p*s*c+e*y*c+r*s*_-e*l*_)*M,t[7]=(r*f*n-d*l*n+d*s*c-e*f*c-r*s*u+e*l*u)*M,t[8]=x*M,t[9]=(p*h*n-d*m*n-p*i*u+e*m*u+d*i*_-e*h*_)*M,t[10]=(r*m*n-p*a*n+p*i*c-e*m*c-r*i*_+e*a*_)*M,t[11]=(d*a*n-r*h*n-d*i*c+e*h*c+r*i*u-e*a*u)*M,t[12]=C*M,t[13]=(d*m*s-p*h*s+p*i*f-e*m*f-d*i*y+e*h*y)*M,t[14]=(p*a*s-r*m*s-p*i*l+e*m*l+r*i*y-e*a*y)*M,t[15]=(r*h*s-d*a*s+d*i*l-e*h*l-r*i*f+e*a*f)*M,this}scale(t){const e=this.elements,i=t.x,s=t.y,n=t.z;return e[0]*=i,e[4]*=s,e[8]*=n,e[1]*=i,e[5]*=s,e[9]*=n,e[2]*=i,e[6]*=s,e[10]*=n,e[3]*=i,e[7]*=s,e[11]*=n,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,s))}makeTranslation(t,e,i){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),s=Math.sin(e),n=1-i,r=t.x,a=t.y,l=t.z,c=n*r,d=n*a;return this.set(c*r+i,c*a-s*l,c*l+s*a,0,c*a+s*l,d*a+i,d*l-s*r,0,c*l-s*a,d*l+s*r,n*l*l+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,s,n,r){return this.set(1,i,n,0,t,1,r,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,n=e._x,r=e._y,a=e._z,l=e._w,c=n+n,d=r+r,h=a+a,f=n*c,u=n*d,p=n*h,m=r*d,y=r*h,_=a*h,v=l*c,S=l*d,x=l*h,C=i.x,b=i.y,M=i.z;return s[0]=(1-(m+_))*C,s[1]=(u+x)*C,s[2]=(p-S)*C,s[3]=0,s[4]=(u-x)*b,s[5]=(1-(f+_))*b,s[6]=(y+v)*b,s[7]=0,s[8]=(p+S)*M,s[9]=(y-v)*M,s[10]=(1-(f+m))*M,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,i){const s=this.elements;let n=yi.set(s[0],s[1],s[2]).length();const r=yi.set(s[4],s[5],s[6]).length(),a=yi.set(s[8],s[9],s[10]).length();this.determinant()<0&&(n=-n),t.x=s[12],t.y=s[13],t.z=s[14],qt.copy(this);const c=1/n,d=1/r,h=1/a;return qt.elements[0]*=c,qt.elements[1]*=c,qt.elements[2]*=c,qt.elements[4]*=d,qt.elements[5]*=d,qt.elements[6]*=d,qt.elements[8]*=h,qt.elements[9]*=h,qt.elements[10]*=h,e.setFromRotationMatrix(qt),i.x=n,i.y=r,i.z=a,this}makePerspective(t,e,i,s,n,r,a=un){const l=this.elements,c=2*n/(e-t),d=2*n/(i-s),h=(e+t)/(e-t),f=(i+s)/(i-s);let u,p;if(a===un)u=-(r+n)/(r-n),p=-2*r*n/(r-n);else if(a===pa)u=-r/(r-n),p=-r*n/(r-n);else throw new Error("Matrix4.makePerspective(): Invalid coordinate system: "+a);return l[0]=c,l[4]=0,l[8]=h,l[12]=0,l[1]=0,l[5]=d,l[9]=f,l[13]=0,l[2]=0,l[6]=0,l[10]=u,l[14]=p,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(t,e,i,s,n,r,a=un){const l=this.elements,c=1/(e-t),d=1/(i-s),h=1/(r-n),f=(e+t)*c,u=(i+s)*d;let p,m;if(a===un)p=(r+n)*h,m=-2*h;else if(a===pa)p=n*h,m=-1*h;else throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return l[0]=2*c,l[4]=0,l[8]=0,l[12]=-f,l[1]=0,l[5]=2*d,l[9]=0,l[13]=-u,l[2]=0,l[6]=0,l[10]=m,l[14]=-p,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<16;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}}const yi=new R,qt=new te,iu=new R(0,0,0),su=new R(1,1,1),Ie=new R,pn=new R,Nt=new R,fa=new te,ma=new Q;class ss{constructor(t=0,e=0,i=0,s=ss.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=s}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,i,s=this._order){return this._x=t,this._y=e,this._z=i,this._order=s,this._onChangeCallback(),this}clone(){return new ss(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,i=!0){const s=t.elements,n=s[0],r=s[4],a=s[8],l=s[1],c=s[5],d=s[9],h=s[2],f=s[6],u=s[10];switch(e){case"XYZ":this._y=Math.asin(de(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-d,u),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(f,c),this._z=0);break;case"YXZ":this._x=Math.asin(-de(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(a,u),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-h,n),this._z=0);break;case"ZXY":this._x=Math.asin(de(f,-1,1)),Math.abs(f)<.9999999?(this._y=Math.atan2(-h,u),this._z=Math.atan2(-r,c)):(this._y=0,this._z=Math.atan2(l,n));break;case"ZYX":this._y=Math.asin(-de(h,-1,1)),Math.abs(h)<.9999999?(this._x=Math.atan2(f,u),this._z=Math.atan2(l,n)):(this._x=0,this._z=Math.atan2(-r,c));break;case"YZX":this._z=Math.asin(de(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-d,c),this._y=Math.atan2(-h,n)):(this._x=0,this._y=Math.atan2(a,u));break;case"XZY":this._z=Math.asin(-de(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(f,c),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-d,u),this._y=0);break;default:console.warn("../math.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return fa.makeRotationFromQuaternion(t),this.setFromRotationMatrix(fa,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return ma.setFromEuler(this),this.setFromQuaternion(ma,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(t){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}ss.DEFAULT_ORDER="XYZ";class zi{constructor(t=0,e=0){this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new zi(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,i=this.y,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6],this.y=s[1]*e+s[4]*i+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(de(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}rotateAround(t,e){const i=Math.cos(e),s=Math.sin(e),n=this.x-t.x,r=this.y-t.y;return this.x=n*i-r*s+t.x,this.y=n*s+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}zi.isVector2=!0;class Ut{constructor(t=0,e=0,i=0,s=1){Ut.prototype.isVector4=!0,this.x=t,this.y=e,this.z=i,this.w=s}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,i,s){return this.x=t,this.y=e,this.z=i,this.w=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new Ut(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*s+r[12]*n,this.y=r[1]*e+r[5]*i+r[9]*s+r[13]*n,this.z=r[2]*e+r[6]*i+r[10]*s+r[14]*n,this.w=r[3]*e+r[7]*i+r[11]*s+r[15]*n,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,i,s,n;const l=t.elements,c=l[0],d=l[4],h=l[8],f=l[1],u=l[5],p=l[9],m=l[2],y=l[6],_=l[10];if(Math.abs(d-f)<.01&&Math.abs(h-m)<.01&&Math.abs(p-y)<.01){if(Math.abs(d+f)<.1&&Math.abs(h+m)<.1&&Math.abs(p+y)<.1&&Math.abs(c+u+_-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const S=(c+1)/2,x=(u+1)/2,C=(_+1)/2,b=(d+f)/4,M=(h+m)/4,P=(p+y)/4;return S>x&&S>C?S<.01?(i=0,s=.707106781,n=.707106781):(i=Math.sqrt(S),s=b/i,n=M/i):x>C?x<.01?(i=.707106781,s=0,n=.707106781):(s=Math.sqrt(x),i=b/s,n=P/s):C<.01?(i=.707106781,s=.707106781,n=0):(n=Math.sqrt(C),i=M/n,s=P/n),this.set(i,s,n,e),this}let v=Math.sqrt((y-p)*(y-p)+(h-m)*(h-m)+(f-d)*(f-d));return Math.abs(v)<.001&&(v=1),this.x=(y-p)/v,this.y=(h-m)/v,this.z=(f-d)/v,this.w=Math.acos((c+u+_-1)/2),this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class fe{constructor(t,e,i,s,n,r,a,l,c){fe.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,l,c)}set(t,e,i,s,n,r,a,l,c){const d=this.elements;return d[0]=t,d[1]=s,d[2]=a,d[3]=e,d[4]=n,d[5]=l,d[6]=i,d[7]=r,d[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[3],l=i[6],c=i[1],d=i[4],h=i[7],f=i[2],u=i[5],p=i[8],m=s[0],y=s[3],_=s[6],v=s[1],S=s[4],x=s[7],C=s[2],b=s[5],M=s[8];return n[0]=r*m+a*v+l*C,n[3]=r*y+a*S+l*b,n[6]=r*_+a*x+l*M,n[1]=c*m+d*v+h*C,n[4]=c*y+d*S+h*b,n[7]=c*_+d*x+h*M,n[2]=f*m+u*v+p*C,n[5]=f*y+u*S+p*b,n[8]=f*_+u*x+p*M,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],l=t[6],c=t[7],d=t[8];return e*r*d-e*a*c-i*n*d+i*a*l+s*n*c-s*r*l}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],l=t[6],c=t[7],d=t[8],h=d*r-a*c,f=a*l-d*n,u=c*n-r*l,p=e*h+i*f+s*u;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/p;return t[0]=h*m,t[1]=(s*c-d*i)*m,t[2]=(a*i-s*r)*m,t[3]=f*m,t[4]=(d*e-s*l)*m,t[5]=(s*n-a*e)*m,t[6]=u*m,t[7]=(i*l-c*e)*m,t[8]=(r*e-i*n)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,i,s,n,r,a){const l=Math.cos(n),c=Math.sin(n);return this.set(i*l,i*c,-i*(l*r+c*a)+r+t,-s*c,s*l,-s*(-c*r+l*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(or.makeScale(t,e)),this}rotate(t){return this.premultiply(or.makeRotation(-t)),this}translate(t,e){return this.premultiply(or.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,i,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<9;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return new fe().fromArray(this.elements)}}const or=new fe;var Ot;(function(o){o[o.Random=0]="Random",o[o.Loop=1]="Loop",o[o.PingPong=2]="PingPong",o[o.Burst=3]="Burst"})(Ot||(Ot={}));function Fi(o,t,e,i){let s;switch(Ot.Random===o?t=Math.random():Ot.Burst===o&&i.isBursting&&(t=i.burstParticleIndex/i.burstParticleCount),e>0?s=Math.floor(t/e)*e:s=t,o){case Ot.Loop:s=s%1;break;case Ot.PingPong:s=Math.abs(s%2-1);break}return s}class Ze{constructor(t,e,i,s){this.p=[t,e,i,s]}genValue(t){const e=t*t,i=t*t*t,s=1-t,n=s*s,r=n*s;return this.p[0]*r+this.p[1]*n*t*3+this.p[2]*s*e*3+this.p[3]*i}derivativeCoefficients(t){const e=[];for(let i=t,s=i.length-1;s>0;s--){const n=[];for(let r=0;r<s;r++){const a=s*(i[r+1]-i[r]);n.push(a)}e.push(n),i=n}return e}getSlope(t){const e=this.derivativeCoefficients(this.p)[0],i=1-t,s=i*i,n=i*t*2,r=t*t;return s*e[0]+n*e[1]+r*e[2]}controlCurve(t,e){this.p[1]=t/3+this.p[0],this.p[2]=this.p[3]-e/3}hull(t){let e=this.p,i=[],s,n=0,r=0,a=0;const l=[];for(l[n++]=e[0],l[n++]=e[1],l[n++]=e[2],l[n++]=e[3];e.length>1;){for(i=[],r=0,a=e.length-1;r<a;r++)s=t*e[r]+(1-t)*e[r+1],l[n++]=s,i.push(s);e=i}return l}split(t){const e=this.hull(t);return{left:new Ze(e[0],e[4],e[7],e[9]),right:new Ze(e[9],e[8],e[6],e[3]),span:e}}clone(){return new Ze(this.p[0],this.p[1],this.p[2],this.p[3])}toJSON(){return{p0:this.p[0],p1:this.p[1],p2:this.p[2],p3:this.p[3]}}static fromJSON(t){return new Ze(t.p0,t.p1,t.p2,t.p3)}}const ns=o=>({r:o.x,g:o.y,b:o.z,a:o.w}),rs=o=>new Ut(o.r,o.g,o.b,o.a),nu=(o,t)=>{switch(t){case"Vector3":return new R(o.x,o.y,o.z);case"Vector4":return new Ut(o.x,o.y,o.z,o.w);case"Color":return new R(o.r,o.g,o.b);case"Number":return o;default:return o}},ru=(o,t)=>{switch(t){case"Vector3":return{x:o.x,y:o.y,z:o.z};case"Vector4":return{x:o.x,y:o.y,z:o.z,w:o.w};case"Color":return{r:o.x,g:o.y,b:o.z};case"Number":return o;default:return o}};class En{constructor(t,e){this.a=t,this.b=e,this.type="value"}startGen(t){}genColor(t,e){const i=Math.random();return e.copy(this.a).lerp(this.b,i)}toJSON(){return{type:"RandomColor",a:ns(this.a),b:ns(this.b)}}static fromJSON(t){return new En(rs(t.a),rs(t.b))}clone(){return new En(this.a.clone(),this.b.clone())}}class Ai{constructor(t,e){this.a=t,this.b=e,this.indexCount=-1,this.type="value"}startGen(t){this.indexCount=t.length,t.push(Math.random())}genColor(t,e){return this.indexCount===-1&&this.startGen(t),e.copy(this.a).lerp(this.b,t[this.indexCount])}toJSON(){return{type:"ColorRange",a:ns(this.a),b:ns(this.b)}}static fromJSON(t){return new Ai(rs(t.a),rs(t.b))}clone(){return new Ai(this.a.clone(),this.b.clone())}}class Ne{constructor(t,e){this.subType=e,this.type="function",this.keys=t}findKey(t){let e=0,i=0,s=this.keys.length-1;for(;i+1<s;)if(e=Math.floor((i+s)/2),t<this.getStartX(e))s=e-1;else if(t>this.getEndX(e))i=e+1;else return e;for(let n=i;n<=s;n++)if(t>=this.getStartX(n)&&t<=this.getEndX(n))return n;return-1}getStartX(t){return this.keys[t][1]}getEndX(t){return t+1<this.keys.length?this.keys[t+1][1]:1}genValue(t,e){const i=this.findKey(e);return this.subType==="Number"?i===-1?this.keys[0][0]:i+1>=this.keys.length?this.keys[this.keys.length-1][0]:(this.keys[i+1][0]-this.keys[i][0])*((e-this.getStartX(i))/(this.getEndX(i)-this.getStartX(i)))+this.keys[i][0]:i===-1?t.copy(this.keys[0][0]):i+1>=this.keys.length?t.copy(this.keys[this.keys.length-1][0]):t.copy(this.keys[i][0]).lerp(this.keys[i+1][0],(e-this.getStartX(i))/(this.getEndX(i)-this.getStartX(i)))}toJSON(){return this.keys[0][0].constructor.name,{type:"CLinearFunction",subType:this.subType,keys:this.keys.map(([t,e])=>({value:ru(t,this.subType),pos:e}))}}static fromJSON(t){return new Ne(t.keys.map(e=>[nu(e.value,t.subType),e.pos]),t.subType)}clone(){return this.subType==="Number"?new Ne(this.keys.map(([t,e])=>[t,e]),this.subType):new Ne(this.keys.map(([t,e])=>[t.clone(),e]),this.subType)}}const fn=new R;class Ke{constructor(t=[[new R(0,0,0),0],[new R(1,1,1),0]],e=[[1,0],[1,1]]){this.type="function",this.color=new Ne(t,"Color"),this.alpha=new Ne(e,"Number")}genColor(t,e,i){return this.color.genValue(fn,i),e.set(fn.x,fn.y,fn.z,this.alpha.genValue(1,i))}toJSON(){return{type:"Gradient",color:this.color.toJSON(),alpha:this.alpha.toJSON()}}static fromJSON(t){if(t.functions){const e=t.functions.map(i=>[Ai.fromJSON(i.function).a,i.start]);return t.functions.length>0&&e.push([Ai.fromJSON(t.functions[t.functions.length-1].function).b,1]),new Ke(e.map(i=>[new R(i[0].x,i[0].y,i[0].z),i[1]]),e.map(i=>[i[0].w,i[1]]))}else{const e=new Ke;return e.alpha=Ne.fromJSON(t.alpha),e.color=Ne.fromJSON(t.color),e}}clone(){const t=new Ke;return t.alpha=this.alpha.clone(),t.color=this.color.clone(),t}startGen(t){}}const ar=new Ut;class Tn{constructor(t,e){this.indexCount=0,this.type="function",this.gradient1=t,this.gradient2=e}startGen(t){this.indexCount=t.length,t.push(Math.random())}genColor(t,e,i){return this.gradient1.genColor(t,e,i),this.gradient2.genColor(t,ar,i),t&&t[this.indexCount]!==void 0?e.lerp(ar,t[this.indexCount]):e.lerp(ar,Math.random()),e}toJSON(){return{type:"RandomColorBetweenGradient",gradient1:this.gradient1.toJSON(),gradient2:this.gradient2.toJSON()}}static fromJSON(t){return new Tn(Ke.fromJSON(t.gradient1),Ke.fromJSON(t.gradient2))}clone(){return new Tn(this.gradient1.clone(),this.gradient2.clone())}}class Ei{constructor(t){this.color=t,this.type="value"}startGen(t){}genColor(t,e){return e.copy(this.color)}toJSON(){return{type:"ConstantColor",color:ns(this.color)}}static fromJSON(t){return new Ei(rs(t.color))}clone(){return new Ei(this.color.clone())}}function qr(o){switch(o.type){case"ConstantColor":return Ei.fromJSON(o);case"ColorRange":return Ai.fromJSON(o);case"RandomColor":return En.fromJSON(o);case"Gradient":return Ke.fromJSON(o);case"RandomColorBetweenGradient":return Tn.fromJSON(o);default:return new Ei(new Ut(1,1,1,1))}}class ${constructor(t){this.value=t,this.type="value"}startGen(t){}genValue(t){return this.value}toJSON(){return{type:"ConstantValue",value:this.value}}static fromJSON(t){return new $(t.value)}clone(){return new $(this.value)}}class si{constructor(t,e){this.a=t,this.b=e,this.indexCount=-1,this.type="value"}startGen(t){this.indexCount=t.length,t.push(Math.random())}genValue(t){return this.indexCount===-1&&this.startGen(t),Ri.lerp(this.a,this.b,t[this.indexCount])}toJSON(){return{type:"IntervalValue",a:this.a,b:this.b}}static fromJSON(t){return new si(t.a,t.b)}clone(){return new si(this.a,this.b)}}class ou{constructor(){this.functions=new Array}findFunction(t){let e=0,i=0,s=this.functions.length-1;for(;i+1<s;)if(e=Math.floor((i+s)/2),t<this.getStartX(e))s=e-1;else if(t>this.getEndX(e))i=e+1;else return e;for(let n=i;n<=s;n++)if(t>=this.functions[n][1]&&t<=this.getEndX(n))return n;return-1}getStartX(t){return this.functions[t][1]}setStartX(t,e){t>0&&(this.functions[t][1]=e)}getEndX(t){return t+1<this.functions.length?this.functions[t+1][1]:1}setEndX(t,e){t+1<this.functions.length&&(this.functions[t+1][1]=e)}insertFunction(t,e){const i=this.findFunction(t);this.functions.splice(i+1,0,[e,t])}removeFunction(t){return this.functions.splice(t,1)[0][0]}getFunction(t){return this.functions[t][0]}setFunction(t,e){this.functions[t][0]=e}get numOfFunctions(){return this.functions.length}}class os extends ou{constructor(t=[[new Ze(0,1/3,1/3*2,1),0]]){super(),this.type="function",this.functions=t}genValue(t,e=0){const i=this.findFunction(e);return i===-1?0:this.functions[i][0].genValue((e-this.getStartX(i))/(this.getEndX(i)-this.getStartX(i)))}toSVG(t,e){if(e<1)return"";let i=["M",0,this.functions[0][0].p[0]].join(" ");for(let s=1/e;s<=1;s+=1/e)i=[i,"L",s*t,this.genValue(void 0,s)].join(" ");return i}toJSON(){return{type:"PiecewiseBezier",functions:this.functions.map(([t,e])=>({function:t.toJSON(),start:e}))}}static fromJSON(t){return new os(t.functions.map(e=>[Ze.fromJSON(e.function),e.start]))}clone(){return new os(this.functions.map(([t,e])=>[t.clone(),e]))}startGen(t){}}function j(o){switch(o.type){case"ConstantValue":return $.fromJSON(o);case"IntervalValue":return si.fromJSON(o);case"PiecewiseBezier":return os.fromJSON(o);default:return new $(0)}}class as{constructor(){this.indexCount=0,this.type="rotation"}startGen(t){this.indexCount=t.length,t.push(new Q);let e,i,s,n,r,a;do e=Math.random()*2-1,i=Math.random()*2-1,s=e*e+i*i;while(s>1);do n=Math.random()*2-1,r=Math.random()*2-1,a=n*n+r*r;while(a>1);const l=Math.sqrt((1-s)/a);t[this.indexCount].set(e,i,l*n,l*r)}genValue(t,e,i,s){return this.indexCount===-1&&this.startGen(t),e.copy(t[this.indexCount]),e}toJSON(){return{type:"RandomQuat"}}static fromJSON(t){return new as}clone(){return new as}}class ls{constructor(t,e){this.axis=t,this.angle=e,this.type="rotation"}startGen(t){this.angle.startGen(t)}genValue(t,e,i,s){return e.setFromAxisAngle(this.axis,this.angle.genValue(t,s)*i)}toJSON(){return{type:"AxisAngle",axis:{x:this.axis.x,y:this.axis.y,z:this.axis.z},angle:this.angle.toJSON()}}static fromJSON(t){return new ls(new R(t.axis.x,t.axis.y,t.axis.z),j(t.angle))}clone(){return new ls(this.axis.clone(),this.angle.clone())}}class On{constructor(t,e,i,s){this.angleX=t,this.angleY=e,this.angleZ=i,this.type="rotation",this.eular=new ss(0,0,0,s)}startGen(t){this.angleX.startGen(t),this.angleY.startGen(t),this.angleZ.startGen(t)}genValue(t,e,i,s){return this.eular.set(this.angleX.genValue(t,s)*i,this.angleY.genValue(t,s)*i,this.angleZ.genValue(t,s)*i),e.setFromEuler(this.eular)}toJSON(){return{type:"Euler",angleX:this.angleX.toJSON(),angleY:this.angleY.toJSON(),angleZ:this.angleZ.toJSON(),eulerOrder:this.eular.order}}static fromJSON(t){return new On(j(t.angleX),j(t.angleY),j(t.angleZ),t.eulerOrder)}clone(){return new On(this.angleX,this.angleY,this.angleZ,this.eular.order)}}function Tl(o){switch(o.type){case"AxisAngle":return ls.fromJSON(o);case"Euler":return On.fromJSON(o);case"RandomQuat":return as.fromJSON(o);default:return new as}}class ni{constructor(t,e,i){this.x=t,this.y=e,this.z=i,this.type="vec3function"}startGen(t){this.x.startGen(t),this.y.startGen(t),this.z.startGen(t)}genValue(t,e,i){return e.set(this.x.genValue(t,i),this.y.genValue(t,i),this.z.genValue(t,i))}toJSON(){return{type:"Vector3Function",x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(t){return new ni(j(t.x),j(t.y),j(t.z))}clone(){return new ni(this.x,this.y,this.z)}}function au(o){switch(o.type){case"Vector3Function":return ni.fromJSON(o);default:return new ni(new $(0),new $(0),new $(0))}}function kn(o){switch(o.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return j(o);case"AxisAngle":case"RandomQuat":case"Euler":return Tl(o);case"Vector3Function":return au(o);default:return new $(0)}}class cs{constructor(t={}){this.type="cone",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.angle=t.angle??Math.PI/6,this.mode=t.mode??Ot.Random,this.spread=t.spread??0,this.speed=t.speed??new $(1),this.memory=[]}update(t,e){Ot.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=Fi(this.mode,this.currentValue,this.spread,e),s=Ri.lerp(1-this.thickness,1,Math.random()),n=i*this.arc,r=Math.sqrt(s),a=Math.sin(n),l=Math.cos(n);t.position.x=r*l,t.position.y=r*a,t.position.z=0;const c=this.angle*r;t.velocity.set(0,0,Math.cos(c)).addScaledVector(t.position,Math.sin(c)).multiplyScalar(t.startSpeed),t.position.multiplyScalar(this.radius)}toJSON(){return{type:"cone",radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(t){return new cs({radius:t.radius,arc:t.arc,thickness:t.thickness,angle:t.angle,mode:t.mode,speed:t.speed?j(t.speed):void 0,spread:t.spread})}clone(){return new cs({radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class hs{constructor(t={}){this.type="circle",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.mode=t.mode??Ot.Random,this.spread=t.spread??0,this.speed=t.speed??new $(1),this.memory=[]}update(t,e){this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e}initialize(t,e){const i=Fi(this.mode,this.currentValue,this.spread,e),s=Ri.lerp(1-this.thickness,1,Math.random()),n=i*this.arc;t.position.x=Math.cos(n),t.position.y=Math.sin(n),t.position.z=0,t.velocity.copy(t.position).multiplyScalar(t.startSpeed),t.position.multiplyScalar(this.radius*s)}toJSON(){return{type:"circle",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(t){return new hs({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?j(t.speed):void 0,spread:t.spread})}clone(){return new hs({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}function mn(o,t){return Math.floor(Math.random()*(t-o))+o}const Ds=new R(0,1,0),Us=new R(0,0,0),lu=new R(1,1,1),ga=new R(0,0,1);class ds{constructor(t={}){this.type="donut",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.donutRadius=t.donutRadius??this.radius*.2,this.mode=t.mode??Ot.Random,this.spread=t.spread??0,this.speed=t.speed??new $(1),this.memory=[],this._m1=new te}update(t,e){Ot.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=Fi(this.mode,this.currentValue,this.spread,e),s=Math.random(),n=Ri.lerp(1-this.thickness,1,Math.random()),r=i*this.arc,a=s*Math.PI*2,l=Math.sin(r),c=Math.cos(r);t.position.x=this.radius*c,t.position.y=this.radius*l,t.position.z=0,t.velocity.z=this.donutRadius*n*Math.sin(a),t.velocity.x=this.donutRadius*n*Math.cos(a)*c,t.velocity.y=this.donutRadius*n*Math.cos(a)*l,t.position.add(t.velocity),t.velocity.normalize().multiplyScalar(t.startSpeed),t.rotation instanceof Q&&(this._m1.lookAt(Us,t.velocity,Ds),t.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"donut",radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(t){return new ds({radius:t.radius,arc:t.arc,thickness:t.thickness,donutRadius:t.donutRadius,mode:t.mode,speed:t.speed?j(t.speed):void 0,spread:t.spread})}clone(){return new ds({radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class us{constructor(){this.type="point",this._m1=new te}update(t,e){}initialize(t){const e=Math.random(),i=Math.random(),s=e*Math.PI*2,n=Math.acos(2*i-1),r=Math.cbrt(Math.random()),a=Math.sin(s),l=Math.cos(s),c=Math.sin(n),d=Math.cos(n);t.velocity.x=r*c*l,t.velocity.y=r*c*a,t.velocity.z=r*d,t.velocity.multiplyScalar(t.startSpeed),t.position.setScalar(0),t.rotation instanceof Q&&(this._m1.lookAt(Us,t.position,Ds),t.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"point"}}static fromJSON(t){return new us}clone(){return new us}}class Ti{constructor(t={}){this.type="sphere",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.mode=t.mode??Ot.Random,this.spread=t.spread??0,this.speed=t.speed??new $(1),this.memory=[],this._m1=new te}update(t,e){Ot.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=Fi(this.mode,this.currentValue,this.spread,e),s=Math.random(),n=Ri.lerp(1-this.thickness,1,Math.random()),r=i*this.arc,a=Math.acos(2*s-1),l=Math.sin(r),c=Math.cos(r),d=Math.sin(a),h=Math.cos(a);t.position.x=d*c,t.position.y=d*l,t.position.z=h,t.velocity.copy(t.position).multiplyScalar(t.startSpeed),t.position.multiplyScalar(this.radius*n),t.rotation instanceof Q&&(this._m1.lookAt(Us,t.position,Ds),t.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"sphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(t){return new Ti({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?j(t.speed):void 0,spread:t.spread})}clone(){return new Ti({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class ps{constructor(t={}){this.type="hemisphere",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.mode=t.mode??Ot.Random,this.spread=t.spread??0,this.speed=t.speed??new $(1),this.memory=[],this._m1=new te}update(t,e){Ot.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=Fi(this.mode,this.currentValue,this.spread,e),s=Math.random(),n=Ri.lerp(1-this.thickness,1,Math.random()),r=i*this.arc,a=Math.acos(s),l=Math.sin(r),c=Math.cos(r),d=Math.sin(a),h=Math.cos(a);t.position.x=d*c,t.position.y=d*l,t.position.z=h,t.velocity.copy(t.position).multiplyScalar(t.startSpeed),t.position.multiplyScalar(this.radius*n),t.rotation instanceof Q&&(this._m1.lookAt(Us,t.position,Ds),t.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"hemisphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(t){return new ps({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?j(t.speed):void 0,spread:t.spread})}clone(){return new ps({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class fs{constructor(t={}){this.type="grid",this.width=t.width??1,this.height=t.height??1,this.column=t.column??10,this.row=t.row??10}initialize(t){const e=Math.floor(Math.random()*this.row),i=Math.floor(Math.random()*this.column);t.position.x=i*this.width/this.column-this.width/2,t.position.y=e*this.height/this.row-this.height/2,t.position.z=0,t.velocity.set(0,0,t.startSpeed)}toJSON(){return{type:"grid",width:this.width,height:this.height,column:this.column,row:this.row}}static fromJSON(t){return new fs(t)}clone(){return new fs({width:this.width,height:this.height,column:this.column,row:this.row})}update(t,e){}}class ms{constructor(t={}){this.type="rectangle",this.currentValue=0,this.width=t.width??10,this.height=t.height??10,this.thickness=t.thickness??1,this.mode=t.mode??Ot.Random,this.spread=t.spread??0,this.speed=t.speed??new $(1),this.memory=[],this._m1=new te}update(t,e){this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e}initialize(t,e){const i=Fi(this.mode,this.currentValue,this.spread,e),s=2*(this.width+this.height),n=i*s;let r,a;n<this.width?(r=n-this.width/2,a=-this.height/2):n<this.width+this.height?(r=this.width/2,a=n-this.width-this.height/2):n<2*this.width+this.height?(r=this.width/2-(n-this.width-this.height),a=this.height/2):(r=-this.width/2,a=this.height/2-(n-2*this.width-this.height));const l=Math.random(),c=1-this.thickness*l;t.position.x=r*c,t.position.y=a*c,t.position.z=0,t.velocity.x=r,t.velocity.y=a,t.velocity.z=0,t.velocity.normalize().multiplyScalar(t.startSpeed),t.rotation instanceof Q&&(this._m1.lookAt(Us,t.velocity,Ds),t.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"rectangle",width:this.width,height:this.height,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(t){return new ms({width:t.width,height:t.height,thickness:t.thickness,mode:t.mode,speed:t.speed?j(t.speed):void 0,spread:t.spread})}clone(){return new ms({width:this.width,height:this.height,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}const Rr={circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:hs,loadJSON:hs.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:cs,loadJSON:cs.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:ds,loadJSON:ds.fromJSON},point:{type:"point",params:[],constructor:us,loadJSON:us.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:Ti,loadJSON:Ti.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:ps,loadJSON:ps.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:fs,loadJSON:fs.fromJSON},rectangle:{type:"rectangle",params:[["width",["number"]],["height",["number"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:ms,loadJSON:ms.fromJSON}};function cu(o,t){return Rr[o.type].loadJSON(o,t)}class gs{constructor(t){this.color=t,this.type="ColorOverLife"}initialize(t){this.color.startGen(t.memory)}update(t,e){this.color.genColor(t.memory,t.color,t.age/t.life),t.color.x*=t.startColor.x,t.color.y*=t.startColor.y,t.color.z*=t.startColor.z,t.color.w*=t.startColor.w}frameUpdate(t){}toJSON(){return{type:this.type,color:this.color.toJSON()}}static fromJSON(t){return new gs(qr(t.color))}clone(){return new gs(this.color.clone())}reset(){}}class ys{constructor(t){this.angularVelocity=t,this.type="RotationOverLife"}initialize(t){typeof t.rotation=="number"&&this.angularVelocity.startGen(t.memory)}update(t,e){typeof t.rotation=="number"&&(t.rotation+=e*this.angularVelocity.genValue(t.memory,t.age/t.life))}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(t){return new ys(j(t.angularVelocity))}frameUpdate(t){}clone(){return new ys(this.angularVelocity.clone())}reset(){}}class _s{constructor(t){this.angularVelocity=t,this.type="Rotation3DOverLife",this.tempQuat=new Q,this.tempQuat2=new Q}initialize(t){t.rotation instanceof Q&&(t.angularVelocity=new Q,this.angularVelocity.startGen(t.memory))}update(t,e){t.rotation instanceof Q&&(this.angularVelocity.genValue(t.memory,this.tempQuat,e,t.age/t.life),t.rotation.multiply(this.tempQuat))}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(t){return new _s(Tl(t.angularVelocity))}frameUpdate(t){}clone(){return new _s(this.angularVelocity.clone())}reset(){}}class vs{initialize(t,e){this.ps=e,this.x.startGen(t.memory),this.y.startGen(t.memory),this.z.startGen(t.memory)}constructor(t,e,i){this.x=t,this.y=e,this.z=i,this.type="ForceOverLife",this._temp=new R,this._tempScale=new R,this._tempQ=new Q}update(t,e){this._temp.set(this.x.genValue(t.memory,t.age/t.life),this.y.genValue(t.memory,t.age/t.life),this.z.genValue(t.memory,t.age/t.life)),this.ps.worldSpace?t.velocity.addScaledVector(this._temp,e):(this._temp.multiply(this._tempScale).applyQuaternion(this._tempQ),t.velocity.addScaledVector(this._temp,e))}toJSON(){return{type:this.type,x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(t){return new vs(j(t.x),j(t.y),j(t.z))}frameUpdate(t){if(this.ps&&!this.ps.worldSpace){const e=this._temp,i=this._tempQ,s=this._tempScale;this.ps.emitter.matrixWorld.decompose(e,i,s),i.invert(),s.set(1/s.x,1/s.y,1/s.z)}}clone(){return new vs(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class ws{initialize(t){this.size.startGen(t.memory)}constructor(t){this.size=t,this.type="SizeOverLife"}update(t){this.size instanceof ni?this.size.genValue(t.memory,t.size,t.age/t.life).multiply(t.startSize):t.size.copy(t.startSize).multiplyScalar(this.size.genValue(t.memory,t.age/t.life))}toJSON(){return{type:this.type,size:this.size.toJSON()}}static fromJSON(t){return new ws(kn(t.size))}frameUpdate(t){}clone(){return new ws(this.size.clone())}reset(){}}class xs{initialize(t){this.speed.startGen(t.memory)}constructor(t){this.speed=t,this.type="SpeedOverLife"}update(t){t.speedModifier=this.speed.genValue(t.memory,t.age/t.life)}toJSON(){return{type:this.type,speed:this.speed.toJSON()}}static fromJSON(t){return new xs(j(t.speed))}frameUpdate(t){}clone(){return new xs(this.speed.clone())}reset(){}}class bs{constructor(t){this.frame=t,this.type="FrameOverLife"}initialize(t){this.frame.startGen(t.memory)}update(t,e){this.frame instanceof os&&(t.uvTile=this.frame.genValue(t.memory,t.age/t.life))}frameUpdate(t){}toJSON(){return{type:this.type,frame:this.frame.toJSON()}}static fromJSON(t){return new bs(j(t.frame))}clone(){return new bs(this.frame.clone())}reset(){}}class Ss{constructor(t,e=new R(0,1,0)){this.orbitSpeed=t,this.axis=e,this.type="OrbitOverLife",this.temp=new R,this.rotation=new Q}initialize(t){this.orbitSpeed.startGen(t.memory)}update(t,e){this.temp.copy(t.position).projectOnVector(this.axis),this.rotation.setFromAxisAngle(this.axis,this.orbitSpeed.genValue(t.memory,t.age/t.life)*e),t.position.sub(this.temp),t.position.applyQuaternion(this.rotation),t.position.add(this.temp)}frameUpdate(t){}toJSON(){return{type:this.type,orbitSpeed:this.orbitSpeed.toJSON(),axis:[this.axis.x,this.axis.y,this.axis.z]}}static fromJSON(t){return new Ss(j(t.orbitSpeed),t.axis?new R(t.axis[0],t.axis[1],t.axis[2]):void 0)}clone(){return new Ss(this.orbitSpeed.clone())}reset(){}}class lr{constructor(t){this.data=t,this.next=null,this.prev=null}hasPrev(){return this.prev!==null}hasNext(){return this.next!==null}}class hu{constructor(){this.length=0,this.head=this.tail=null}isEmpty(){return this.head===null}clear(){this.length=0,this.head=this.tail=null}front(){return this.head===null?null:this.head.data}back(){return this.tail===null?null:this.tail.data}dequeue(){if(this.head){const t=this.head.data;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,t}}pop(){if(this.tail){const t=this.tail.data;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,t}}queue(t){const e=new lr(t);this.tail||(this.tail=e),this.head&&(this.head.prev=e,e.next=this.head),this.head=e,this.length++}push(t){const e=new lr(t);this.head||(this.head=e),this.tail&&(this.tail.next=e,e.prev=this.tail),this.tail=e,this.length++}insertBefore(t,e){const i=new lr(e);i.next=t,i.prev=t.prev,i.prev!==null&&(i.prev.next=i),i.next.prev=i,t==this.head&&(this.head=i),this.length++}remove(t){if(this.head===null||this.tail===null)return;let e=this.head;for(t===this.head.data&&(this.head=this.head.next),t===this.tail.data&&(this.tail=this.tail.prev);e.next!==null&&e.data!==t;)e=e.next;e.data===t&&(e.prev!==null&&(e.prev.next=e.next),e.next!==null&&(e.next.prev=e.prev),this.length--)}*values(){let t=this.head;for(;t!==null;)yield t.data,t=t.next}}class du{constructor(){this.startSpeed=0,this.startColor=new Ut,this.startSize=new R(1,1,1),this.position=new R,this.velocity=new R,this.age=0,this.life=1,this.size=new R(1,1,1),this.speedModifier=1,this.rotation=0,this.color=new Ut,this.uvTile=0,this.memory=[]}get died(){return this.age>=this.life}reset(){this.memory.length=0}}class uu{constructor(t,e,i){this.position=t,this.size=e,this.color=i}}class Fr{constructor(){this.startSpeed=0,this.startColor=new Ut,this.startSize=new R(1,1,1),this.position=new R,this.velocity=new R,this.age=0,this.life=1,this.size=new R(1,1,1),this.length=100,this.speedModifier=1,this.color=new Ut,this.previous=new hu,this.uvTile=0,this.memory=[]}update(){for(this.age<=this.life?this.previous.push(new uu(this.position.clone(),this.size.x,this.color.clone())):this.previous.length>0&&this.previous.dequeue();this.previous.length>this.length;)this.previous.dequeue()}get died(){return this.age>=this.life}reset(){this.memory.length=0,this.previous.clear()}}class Ms{initialize(t){this.width.startGen(t.memory)}constructor(t){this.width=t,this.type="WidthOverLength"}update(t){if(t instanceof Fr){const e=t.previous.values();for(let i=0;i<t.previous.length;i++){const s=e.next();s.value.size=this.width.genValue(t.memory,(t.previous.length-i)/t.length)}}}frameUpdate(t){}toJSON(){return{type:this.type,width:this.width.toJSON()}}static fromJSON(t){return new Ms(j(t.width))}clone(){return new Ms(this.width.clone())}reset(){}}class Cs{constructor(t,e){this.direction=t,this.magnitude=e,this.type="ApplyForce",this.memory={data:[],dataCount:0},this.magnitudeValue=this.magnitude.genValue(this.memory)}initialize(t){}update(t,e){t.velocity.addScaledVector(this.direction,this.magnitudeValue*e)}frameUpdate(t){this.magnitudeValue=this.magnitude.genValue(this.memory)}toJSON(){return{type:this.type,direction:[this.direction.x,this.direction.y,this.direction.z],magnitude:this.magnitude.toJSON()}}static fromJSON(t){return new Cs(new R(t.direction[0],t.direction[1],t.direction[2]),j(t.magnitude??t.force))}clone(){return new Cs(this.direction.clone(),this.magnitude.clone())}reset(){}}class Ps{constructor(t,e){this.center=t,this.magnitude=e,this.type="GravityForce",this.temp=new R}initialize(t){}update(t,e){this.temp.copy(this.center).sub(t.position).normalize(),t.velocity.addScaledVector(this.temp,this.magnitude/t.position.distanceToSquared(this.center)*e)}frameUpdate(t){}toJSON(){return{type:this.type,center:[this.center.x,this.center.y,this.center.z],magnitude:this.magnitude}}static fromJSON(t){return new Ps(new R(t.center[0],t.center[1],t.center[2]),t.magnitude)}clone(){return new Ps(this.center.clone(),this.magnitude)}reset(){}}class zs{constructor(t){this.angle=t,this.type="ChangeEmitDirection",this._temp=new R,this._q=new Q,this.memory={data:[],dataCount:0}}initialize(t){const e=t.velocity.length();e!=0&&(t.velocity.normalize(),t.velocity.x===0&&t.velocity.y===0?this._temp.set(0,t.velocity.z,0):this._temp.set(-t.velocity.y,t.velocity.x,0),this.angle.startGen(this.memory),this._q.setFromAxisAngle(this._temp.normalize(),this.angle.genValue(this.memory)),this._temp.copy(t.velocity),t.velocity.applyQuaternion(this._q),this._q.setFromAxisAngle(this._temp,Math.random()*Math.PI*2),t.velocity.applyQuaternion(this._q),t.velocity.setLength(e))}update(t,e){}frameUpdate(t){}toJSON(){return{type:this.type,angle:this.angle.toJSON()}}static fromJSON(t){return new zs(j(t.angle))}clone(){return new zs(this.angle)}reset(){}}var xi;(function(o){o[o.Death=0]="Death",o[o.Birth=1]="Birth",o[o.Frame=2]="Frame"})(xi||(xi={}));class Oi{constructor(t,e,i,s=xi.Frame,n=1){this.particleSystem=t,this.useVelocityAsBasis=e,this.subParticleSystem=i,this.mode=s,this.emitProbability=n,this.type="EmitSubParticleSystem",this.q_=new Q,this.v_=new R,this.v2_=new R,this.subEmissions=new Array,this.subParticleSystem&&this.subParticleSystem.system&&(this.subParticleSystem.system.onlyUsedByOther=!0)}initialize(t){}update(t,e){this.mode===xi.Frame?this.emit(t,e):this.mode===xi.Birth&&t.age===0?this.emit(t,e):this.mode===xi.Death&&t.age+e>=t.life&&this.emit(t,e)}emit(t,e){if(!this.subParticleSystem||Math.random()>this.emitProbability)return;const i=new te;this.setMatrixFromParticle(i,t),this.subEmissions.push({burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:i,travelDistance:0,particle:t})}frameUpdate(t){if(this.subParticleSystem)for(let e=0;e<this.subEmissions.length;e++)if(this.subEmissions[e].time>=this.subParticleSystem.system.duration)this.subEmissions[e]=this.subEmissions[this.subEmissions.length-1],this.subEmissions.length=this.subEmissions.length-1,e--;else{const i=this.subEmissions[e];i.particle&&i.particle.age<i.particle.life?this.setMatrixFromParticle(i.matrix,i.particle):i.particle=void 0,this.subParticleSystem.system.emit(t,i,i.matrix)}}toJSON(){return{type:this.type,subParticleSystem:this.subParticleSystem?this.subParticleSystem.uuid:"",useVelocityAsBasis:this.useVelocityAsBasis,mode:this.mode,emitProbability:this.emitProbability}}static fromJSON(t,e){return new Oi(e,t.useVelocityAsBasis,t.subParticleSystem,t.mode,t.emitProbability)}clone(){return new Oi(this.particleSystem,this.useVelocityAsBasis,this.subParticleSystem,this.mode,this.emitProbability)}reset(){}setMatrixFromParticle(t,e){let i;if(e.rotation===void 0||this.useVelocityAsBasis)if(e.velocity.x===0&&e.velocity.y===0&&(e.velocity.z===1||e.velocity.z===0))t.set(1,0,0,e.position.x,0,1,0,e.position.y,0,0,1,e.position.z,0,0,0,1);else{this.v_.copy(ga).cross(e.velocity),this.v2_.copy(e.velocity).cross(this.v_);const s=this.v_.length(),n=this.v2_.length();t.set(this.v_.x/s,this.v2_.x/n,e.velocity.x,e.position.x,this.v_.y/s,this.v2_.y/n,e.velocity.y,e.position.y,this.v_.z/s,this.v2_.z/n,e.velocity.z,e.position.z,0,0,0,1)}else e.rotation instanceof Q?i=e.rotation:(this.q_.setFromAxisAngle(ga,e.rotation),i=this.q_),t.compose(e.position,i,lu);this.particleSystem.worldSpace||t.multiplyMatrices(this.particleSystem.emitter.matrixWorld,t)}}const pu=.5*(Math.sqrt(3)-1),qi=(3-Math.sqrt(3))/6,fu=1/3,le=1/6,mu=(Math.sqrt(5)-1)/4,Mt=(5-Math.sqrt(5))/20,xt=new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),yt=new Float32Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);class Ol{constructor(t=Math.random){const e=typeof t=="function"?t:yu(t);this.p=gu(e),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(let i=0;i<512;i++)this.perm[i]=this.p[i&255],this.permMod12[i]=this.perm[i]%12}noise2D(t,e){const i=this.permMod12,s=this.perm;let n=0,r=0,a=0;const l=(t+e)*pu,c=Math.floor(t+l),d=Math.floor(e+l),h=(c+d)*qi,f=c-h,u=d-h,p=t-f,m=e-u;let y,_;p>m?(y=1,_=0):(y=0,_=1);const v=p-y+qi,S=m-_+qi,x=p-1+2*qi,C=m-1+2*qi,b=c&255,M=d&255;let P=.5-p*p-m*m;if(P>=0){const G=i[b+s[M]]*3;P*=P,n=P*P*(xt[G]*p+xt[G+1]*m)}let z=.5-v*v-S*S;if(z>=0){const G=i[b+y+s[M+_]]*3;z*=z,r=z*z*(xt[G]*v+xt[G+1]*S)}let H=.5-x*x-C*C;if(H>=0){const G=i[b+1+s[M+1]]*3;H*=H,a=H*H*(xt[G]*x+xt[G+1]*C)}return 70*(n+r+a)}noise3D(t,e,i){const s=this.permMod12,n=this.perm;let r,a,l,c;const d=(t+e+i)*fu,h=Math.floor(t+d),f=Math.floor(e+d),u=Math.floor(i+d),p=(h+f+u)*le,m=h-p,y=f-p,_=u-p,v=t-m,S=e-y,x=i-_;let C,b,M,P,z,H;v>=S?S>=x?(C=1,b=0,M=0,P=1,z=1,H=0):v>=x?(C=1,b=0,M=0,P=1,z=0,H=1):(C=0,b=0,M=1,P=1,z=0,H=1):S<x?(C=0,b=0,M=1,P=0,z=1,H=1):v<x?(C=0,b=1,M=0,P=0,z=1,H=1):(C=0,b=1,M=0,P=1,z=1,H=0);const G=v-C+le,ht=S-b+le,rt=x-M+le,ot=v-P+2*le,Z=S-z+2*le,ut=x-H+2*le,Y=v-1+3*le,pt=S-1+3*le,K=x-1+3*le,mt=h&255,gt=f&255,zt=u&255;let Lt=.6-v*v-S*S-x*x;if(Lt<0)r=0;else{const B=s[mt+n[gt+n[zt]]]*3;Lt*=Lt,r=Lt*Lt*(xt[B]*v+xt[B+1]*S+xt[B+2]*x)}let kt=.6-G*G-ht*ht-rt*rt;if(kt<0)a=0;else{const B=s[mt+C+n[gt+b+n[zt+M]]]*3;kt*=kt,a=kt*kt*(xt[B]*G+xt[B+1]*ht+xt[B+2]*rt)}let q=.6-ot*ot-Z*Z-ut*ut;if(q<0)l=0;else{const B=s[mt+P+n[gt+z+n[zt+H]]]*3;q*=q,l=q*q*(xt[B]*ot+xt[B+1]*Z+xt[B+2]*ut)}let St=.6-Y*Y-pt*pt-K*K;if(St<0)c=0;else{const B=s[mt+1+n[gt+1+n[zt+1]]]*3;St*=St,c=St*St*(xt[B]*Y+xt[B+1]*pt+xt[B+2]*K)}return 32*(r+a+l+c)}noise4D(t,e,i,s){const n=this.perm;let r,a,l,c,d;const h=(t+e+i+s)*mu,f=Math.floor(t+h),u=Math.floor(e+h),p=Math.floor(i+h),m=Math.floor(s+h),y=(f+u+p+m)*Mt,_=f-y,v=u-y,S=p-y,x=m-y,C=t-_,b=e-v,M=i-S,P=s-x;let z=0,H=0,G=0,ht=0;C>b?z++:H++,C>M?z++:G++,C>P?z++:ht++,b>M?H++:G++,b>P?H++:ht++,M>P?G++:ht++;const rt=z>=3?1:0,ot=H>=3?1:0,Z=G>=3?1:0,ut=ht>=3?1:0,Y=z>=2?1:0,pt=H>=2?1:0,K=G>=2?1:0,mt=ht>=2?1:0,gt=z>=1?1:0,zt=H>=1?1:0,Lt=G>=1?1:0,kt=ht>=1?1:0,q=C-rt+Mt,St=b-ot+Mt,B=M-Z+Mt,ee=P-ut+Mt,Ve=C-Y+2*Mt,oi=b-pt+2*Mt,ie=M-K+2*Mt,je=P-mt+2*Mt,Ge=C-gt+3*Mt,ai=b-zt+3*Mt,We=M-Lt+3*Mt,li=P-kt+3*Mt,ci=C-1+4*Mt,hi=b-1+4*Mt,Se=M-1+4*Mt,di=P-1+4*Mt,Me=f&255,se=u&255,Xt=p&255,ne=m&255;let re=.6-C*C-b*b-M*M-P*P;if(re<0)r=0;else{const tt=n[Me+n[se+n[Xt+n[ne]]]]%32*4;re*=re,r=re*re*(yt[tt]*C+yt[tt+1]*b+yt[tt+2]*M+yt[tt+3]*P)}let oe=.6-q*q-St*St-B*B-ee*ee;if(oe<0)a=0;else{const tt=n[Me+rt+n[se+ot+n[Xt+Z+n[ne+ut]]]]%32*4;oe*=oe,a=oe*oe*(yt[tt]*q+yt[tt+1]*St+yt[tt+2]*B+yt[tt+3]*ee)}let me=.6-Ve*Ve-oi*oi-ie*ie-je*je;if(me<0)l=0;else{const tt=n[Me+Y+n[se+pt+n[Xt+K+n[ne+mt]]]]%32*4;me*=me,l=me*me*(yt[tt]*Ve+yt[tt+1]*oi+yt[tt+2]*ie+yt[tt+3]*je)}let _t=.6-Ge*Ge-ai*ai-We*We-li*li;if(_t<0)c=0;else{const tt=n[Me+gt+n[se+zt+n[Xt+Lt+n[ne+kt]]]]%32*4;_t*=_t,c=_t*_t*(yt[tt]*Ge+yt[tt+1]*ai+yt[tt+2]*We+yt[tt+3]*li)}let ge=.6-ci*ci-hi*hi-Se*Se-di*di;if(ge<0)d=0;else{const tt=n[Me+1+n[se+1+n[Xt+1+n[ne+1]]]]%32*4;ge*=ge,d=ge*ge*(yt[tt]*ci+yt[tt+1]*hi+yt[tt+2]*Se+yt[tt+3]*di)}return 27*(r+a+l+c+d)}}function gu(o){const t=new Uint8Array(256);for(let e=0;e<256;e++)t[e]=e;for(let e=0;e<255;e++){const i=e+~~(o()*(256-e)),s=t[e];t[e]=t[i],t[i]=s}return t}function yu(o){let t=0,e=0,i=0,s=1;const n=_u();return t=n(" "),e=n(" "),i=n(" "),t-=n(o),t<0&&(t+=1),e-=n(o),e<0&&(e+=1),i-=n(o),i<0&&(i+=1),function(){const r=2091639*t+s*23283064365386963e-26;return t=e,e=i,i=r-(s=r|0)}}function _u(){let o=4022871197;return function(t){t=t.toString();for(let e=0;e<t.length;e++){o+=t.charCodeAt(e);let i=.02519603282416938*o;o=i>>>0,i-=o,i*=o,o=i>>>0,i-=o,o+=i*4294967296}return(o>>>0)*23283064365386963e-26}}class As{constructor(t,e,i,s){this.scale=t,this.octaves=e,this.velocityMultiplier=i,this.timeScale=s,this.type="TurbulenceField",this.generator=new Ol,this.timeOffset=new R,this.temp=new R,this.temp2=new R,this.timeOffset.x=Math.random()/this.scale.x*this.timeScale.x,this.timeOffset.y=Math.random()/this.scale.y*this.timeScale.y,this.timeOffset.z=Math.random()/this.scale.z*this.timeScale.z}initialize(t){}update(t,e){const i=t.position.x/this.scale.x,s=t.position.y/this.scale.y,n=t.position.z/this.scale.z;this.temp.set(0,0,0);let r=1;for(let a=0;a<this.octaves;a++)this.temp2.set(this.generator.noise4D(i*r,s*r,n*r,this.timeOffset.x*r)/r,this.generator.noise4D(i*r,s*r,n*r,this.timeOffset.y*r)/r,this.generator.noise4D(i*r,s*r,n*r,this.timeOffset.z*r)/r),this.temp.add(this.temp2),r*=2;this.temp.multiply(this.velocityMultiplier),t.velocity.addScaledVector(this.temp,e)}toJSON(){return{type:this.type,scale:[this.scale.x,this.scale.y,this.scale.z],octaves:this.octaves,velocityMultiplier:[this.velocityMultiplier.x,this.velocityMultiplier.y,this.velocityMultiplier.z],timeScale:[this.timeScale.x,this.timeScale.y,this.timeScale.z]}}frameUpdate(t){this.timeOffset.x+=t*this.timeScale.x,this.timeOffset.y+=t*this.timeScale.y,this.timeOffset.z+=t*this.timeScale.z}static fromJSON(t){return new As(new R(t.scale[0],t.scale[1],t.scale[2]),t.octaves,new R(t.velocityMultiplier[0],t.velocityMultiplier[1],t.velocityMultiplier[2]),new R(t.timeScale[0],t.timeScale[1],t.timeScale[2]))}clone(){return new As(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const ce=[],cr=new R,hr=new Q;class Es{constructor(t,e,i=new $(1),s=new $(0)){if(this.frequency=t,this.power=e,this.positionAmount=i,this.rotationAmount=s,this.type="Noise",this.duration=0,ce.length===0)for(let n=0;n<100;n++)ce.push(new Ol)}initialize(t){t.lastPosNoise=new R,typeof t.rotation=="number"?t.lastRotNoise=0:t.lastRotNoise=new Q,t.generatorIndex=[mn(0,100),mn(0,100),mn(0,100),mn(0,100)],this.positionAmount.startGen(t.memory),this.rotationAmount.startGen(t.memory),this.frequency.startGen(t.memory),this.power.startGen(t.memory)}update(t,e){let i=this.frequency.genValue(t.memory,t.age/t.life),s=this.power.genValue(t.memory,t.age/t.life),n=this.positionAmount.genValue(t.memory,t.age/t.life),r=this.rotationAmount.genValue(t.memory,t.age/t.life);n>0&&t.lastPosNoise!==void 0&&(t.position.sub(t.lastPosNoise),cr.set(ce[t.generatorIndex[0]].noise2D(0,t.age*i)*s*n,ce[t.generatorIndex[1]].noise2D(0,t.age*i)*s*n,ce[t.generatorIndex[2]].noise2D(0,t.age*i)*s*n),t.position.add(cr),t.lastPosNoise.copy(cr)),r>0&&t.lastRotNoise!==void 0&&(typeof t.rotation=="number"?(t.rotation-=t.lastRotNoise,t.rotation+=ce[t.generatorIndex[3]].noise2D(0,t.age*i)*Math.PI*s*r):(t.lastRotNoise.invert(),t.rotation.multiply(t.lastRotNoise),hr.set(ce[t.generatorIndex[0]].noise2D(0,t.age*i)*s*r,ce[t.generatorIndex[1]].noise2D(0,t.age*i)*s*r,ce[t.generatorIndex[2]].noise2D(0,t.age*i)*s*r,ce[t.generatorIndex[3]].noise2D(0,t.age*i)*s*r).normalize(),t.rotation.multiply(hr),t.lastRotNoise.copy(hr)))}toJSON(){return{type:this.type,frequency:this.frequency.toJSON(),power:this.power.toJSON(),positionAmount:this.positionAmount.toJSON(),rotationAmount:this.rotationAmount.toJSON()}}frameUpdate(t){this.duration+=t}static fromJSON(t){return new Es(j(t.frequency),j(t.power),j(t.positionAmount),j(t.rotationAmount))}clone(){return new Es(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone())}reset(){}}class Ts{constructor(t,e){this.color=t,this.speedRange=e,this.type="ColorBySpeed"}initialize(t){this.color.startGen(t.memory)}update(t,e){const i=(t.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.color.genColor(t.memory,t.color,i),t.color.x*=t.startColor.x,t.color.y*=t.startColor.y,t.color.z*=t.startColor.z,t.color.w*=t.startColor.w}frameUpdate(t){}toJSON(){return{type:this.type,color:this.color.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(t){return new Ts(qr(t.color),si.fromJSON(t.speedRange))}clone(){return new Ts(this.color.clone(),this.speedRange.clone())}reset(){}}class Os{initialize(t){this.size.startGen(t.memory)}constructor(t,e){this.size=t,this.speedRange=e,this.type="SizeBySpeed"}update(t){const e=(t.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.size instanceof ni?this.size.genValue(t.memory,t.size,e).multiply(t.startSize):t.size.copy(t.startSize).multiplyScalar(this.size.genValue(t.memory,e))}toJSON(){return{type:this.type,size:this.size.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(t){return new Os(kn(t.size),si.fromJSON(t.speedRange))}frameUpdate(t){}clone(){return new Os(this.size.clone(),this.speedRange.clone())}reset(){}}class ks{constructor(t,e){this.angularVelocity=t,this.speedRange=e,this.type="RotationBySpeed",this.tempQuat=new Q}initialize(t){typeof t.rotation=="number"&&this.angularVelocity.startGen(t.memory)}update(t,e){if(typeof t.rotation=="number"){const i=(t.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);t.rotation+=e*this.angularVelocity.genValue(t.memory,i)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(t){return new ks(j(t.angularVelocity),si.fromJSON(t.speedRange))}frameUpdate(t){}clone(){return new ks(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class Is{initialize(t){this.speed.startGen(t.memory)}constructor(t,e){this.speed=t,this.dampen=e,this.type="LimitSpeedOverLife"}update(t,e){let i=t.velocity.length(),s=this.speed.genValue(t.memory,t.age/t.life);if(i>s){const n=(i-s)/i;t.velocity.multiplyScalar(1-n*this.dampen*e*20)}}toJSON(){return{type:this.type,speed:this.speed.toJSON(),dampen:this.dampen}}static fromJSON(t){return new Is(j(t.speed),t.dampen)}frameUpdate(t){}clone(){return new Is(this.speed.clone(),this.dampen)}reset(){}}const In={ApplyForce:{type:"ApplyForce",constructor:Cs,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:Cs.fromJSON},Noise:{type:"Noise",constructor:Es,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:Es.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:As,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:As.fromJSON},GravityForce:{type:"GravityForce",constructor:Ps,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:Ps.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:gs,params:[["color",["colorFunc"]]],loadJSON:gs.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:ys,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:ys.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:_s,params:[["angularVelocity",["rotationFunc"]]],loadJSON:_s.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:ws,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:ws.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:Ts,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:Ts.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:ks,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:ks.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:Os,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:Os.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:xs,params:[["speed",["value","valueFunc"]]],loadJSON:xs.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:bs,params:[["frame",["value","valueFunc"]]],loadJSON:bs.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:vs,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:vs.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:Ss,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:Ss.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:Ms,params:[["width",["value","valueFunc"]]],loadJSON:Ms.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:zs,params:[["angle",["value"]]],loadJSON:zs.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:Oi,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:Oi.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:Is,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:Is.fromJSON}};function vu(o,t){return In[o.type]?In[o.type].loadJSON(o,t):null}const wu=[];function xu(o){if(!wu.find(e=>e.id===o.id)){for(const e of o.emitterShapes)Rr[e.type]||(Rr[e.type]=e);for(const e of o.behaviors)In[e.type]||(In[e.type]=e)}}class Rs{get geometry(){return this._geometry}set geometry(t){if(this._geometry=t,t===void 0||typeof t=="string")return;const e=new Uh;this._triangleIndexToArea.length=0;let i=0;if(!t.getIndex())return;const s=t.getIndex().array,n=s.length/3;this._triangleIndexToArea.push(0);for(let r=0;r<n;r++)e.setFromAttributeAndIndices(t.getAttribute("position"),s[r*3],s[r*3+1],s[r*3+2]),i+=e.getArea(),this._triangleIndexToArea.push(i);t.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(t){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new w,this._tempB=new w,this._tempC=new w,t&&(this.geometry=t)}initialize(t){const e=this._geometry;if(!e||e.getIndex()===null){t.position.set(0,0,0),t.velocity.set(0,0,1).multiplyScalar(t.startSpeed);return}const i=this._triangleIndexToArea.length-1;let s=0,n=i;const r=Math.random()*this._triangleIndexToArea[i];for(;s+1<n;){const u=Math.floor((s+n)/2);r<this._triangleIndexToArea[u]?n=u:s=u}let a=Math.random(),l=Math.random();a+l>1&&(a=1-a,l=1-l);const c=e.getIndex().array[s*3],d=e.getIndex().array[s*3+1],h=e.getIndex().array[s*3+2],f=e.getAttribute("position");this._tempA.fromBufferAttribute(f,c),this._tempB.fromBufferAttribute(f,d),this._tempC.fromBufferAttribute(f,h),this._tempB.sub(this._tempA),this._tempC.sub(this._tempA),this._tempA.addScaledVector(this._tempB,a).addScaledVector(this._tempC,l),t.position.copy(this._tempA),this._tempA.copy(this._tempB).cross(this._tempC).normalize(),t.velocity.copy(this._tempA).normalize().multiplyScalar(t.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._geometry?this._geometry.uuid:""}}static fromJSON(t,e){return new Rs(e.geometries[t.geometry])}clone(){return new Rs(this._geometry)}update(t,e){}}const bu={id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:Rs,loadJSON:Rs.fromJSON}],behaviors:[]};var Su=`
3
- #ifdef SOFT_PARTICLES
4
-
5
- /* #ifdef LOGDEPTH
6
- float distSample = linearize_depth_log(sampleDepth, near, far);
7
- #else
8
- float distSample = ortho ? linearize_depth_ortho(sampleDepth, near, far) : linearize_depth(sampleDepth, near, far);
9
- #endif */
10
-
11
- vec2 p2 = projPosition.xy / projPosition.w;
12
-
13
- p2 = 0.5 * p2 + 0.5;
14
-
15
- float readDepth = texture2D(depthTexture, p2.xy).r;
16
- float viewDepth = linearize_depth(readDepth);
17
-
18
- float softParticlesFade = saturate(SOFT_INV_FADE_DISTANCE * ((viewDepth - SOFT_NEAR_FADE) - linearDepth));
19
-
20
- gl_FragColor *= softParticlesFade;
21
-
22
- //gl_FragColor = vec4(softParticlesFade , 0, 0, 1);
23
- #endif
24
- `,Mu=`
25
- #ifdef SOFT_PARTICLES
26
-
27
- uniform sampler2D depthTexture;
28
- uniform vec4 projParams;
29
- uniform vec2 softParams;
30
-
31
- varying vec4 projPosition;
32
- varying float linearDepth;
33
-
34
- #define SOFT_NEAR_FADE softParams.x
35
- #define SOFT_INV_FADE_DISTANCE softParams.y
36
-
37
- #define zNear projParams.x
38
- #define zFar projParams.y
39
-
40
- float linearize_depth(float d)
41
- {
42
- return (zFar * zNear) / (zFar - d * (zFar - zNear));
43
- }
44
-
45
- #endif
46
- `,Cu=`
47
- #ifdef SOFT_PARTICLES
48
- varying vec4 projPosition;
49
- varying float linearDepth;
50
- #endif
51
- `,Pu=`
52
- #ifdef SOFT_PARTICLES
53
- projPosition = gl_Position;
54
- linearDepth = -mvPosition.z;
55
- #endif
56
- `,zu=`
57
- #ifdef USE_MAP
58
- vec4 texelColor = texture2D( map, vUv);
59
- #ifdef TILE_BLEND
60
- texelColor = mix( texelColor, texture2D( map, vUvNext ), vUvBlend );
61
- #endif
62
- diffuseColor *= texelColor;
63
- #endif
64
- `,Au=`
65
- #if defined( USE_UV ) || defined( USE_ANISOTROPY )
66
-
67
- varying vec2 vUv;
68
- #ifdef TILE_BLEND
69
- varying vec2 vUvNext;
70
- varying float vUvBlend;
71
- #endif
72
-
73
- #endif
74
- #ifdef USE_MAP
75
-
76
- uniform mat3 mapTransform;
77
- varying vec2 vMapUv;
78
- #ifdef TILE_BLEND
79
- varying vec2 vMapUvNext;
80
- #endif
81
-
82
- #endif
83
- #ifdef USE_ALPHAMAP
84
-
85
- uniform mat3 alphaMapTransform;
86
- varying vec2 vAlphaMapUv;
87
-
88
- #endif
89
- #ifdef USE_LIGHTMAP
90
-
91
- uniform mat3 lightMapTransform;
92
- varying vec2 vLightMapUv;
93
-
94
- #endif
95
- #ifdef USE_AOMAP
96
-
97
- uniform mat3 aoMapTransform;
98
- varying vec2 vAoMapUv;
99
-
100
- #endif
101
- #ifdef USE_BUMPMAP
102
-
103
- uniform mat3 bumpMapTransform;
104
- varying vec2 vBumpMapUv;
105
-
106
- #endif
107
- #ifdef USE_NORMALMAP
108
-
109
- uniform mat3 normalMapTransform;
110
- varying vec2 vNormalMapUv;
111
-
112
- #endif
113
- #ifdef USE_DISPLACEMENTMAP
114
-
115
- uniform mat3 displacementMapTransform;
116
- varying vec2 vDisplacementMapUv;
117
-
118
- #endif
119
- #ifdef USE_EMISSIVEMAP
120
-
121
- uniform mat3 emissiveMapTransform;
122
- varying vec2 vEmissiveMapUv;
123
-
124
- #endif
125
- #ifdef USE_METALNESSMAP
126
-
127
- uniform mat3 metalnessMapTransform;
128
- varying vec2 vMetalnessMapUv;
129
-
130
- #endif
131
- #ifdef USE_ROUGHNESSMAP
132
-
133
- uniform mat3 roughnessMapTransform;
134
- varying vec2 vRoughnessMapUv;
135
-
136
- #endif
137
- #ifdef USE_ANISOTROPYMAP
138
-
139
- uniform mat3 anisotropyMapTransform;
140
- varying vec2 vAnisotropyMapUv;
141
-
142
- #endif
143
- #ifdef USE_CLEARCOATMAP
144
-
145
- uniform mat3 clearcoatMapTransform;
146
- varying vec2 vClearcoatMapUv;
147
-
148
- #endif
149
- #ifdef USE_CLEARCOAT_NORMALMAP
150
-
151
- uniform mat3 clearcoatNormalMapTransform;
152
- varying vec2 vClearcoatNormalMapUv;
153
-
154
- #endif
155
- #ifdef USE_CLEARCOAT_ROUGHNESSMAP
156
-
157
- uniform mat3 clearcoatRoughnessMapTransform;
158
- varying vec2 vClearcoatRoughnessMapUv;
159
-
160
- #endif
161
- #ifdef USE_SHEEN_COLORMAP
162
-
163
- uniform mat3 sheenColorMapTransform;
164
- varying vec2 vSheenColorMapUv;
165
-
166
- #endif
167
- #ifdef USE_SHEEN_ROUGHNESSMAP
168
-
169
- uniform mat3 sheenRoughnessMapTransform;
170
- varying vec2 vSheenRoughnessMapUv;
171
-
172
- #endif
173
- #ifdef USE_IRIDESCENCEMAP
174
-
175
- uniform mat3 iridescenceMapTransform;
176
- varying vec2 vIridescenceMapUv;
177
-
178
- #endif
179
- #ifdef USE_IRIDESCENCE_THICKNESSMAP
180
-
181
- uniform mat3 iridescenceThicknessMapTransform;
182
- varying vec2 vIridescenceThicknessMapUv;
183
-
184
- #endif
185
- #ifdef USE_SPECULARMAP
186
-
187
- uniform mat3 specularMapTransform;
188
- varying vec2 vSpecularMapUv;
189
-
190
- #endif
191
- #ifdef USE_SPECULAR_COLORMAP
192
-
193
- uniform mat3 specularColorMapTransform;
194
- varying vec2 vSpecularColorMapUv;
195
-
196
- #endif
197
- #ifdef USE_SPECULAR_INTENSITYMAP
198
-
199
- uniform mat3 specularIntensityMapTransform;
200
- varying vec2 vSpecularIntensityMapUv;
201
-
202
- #endif
203
- #ifdef USE_TRANSMISSIONMAP
204
-
205
- uniform mat3 transmissionMapTransform;
206
- varying vec2 vTransmissionMapUv;
207
-
208
- #endif
209
- #ifdef USE_THICKNESSMAP
210
-
211
- uniform mat3 thicknessMapTransform;
212
- varying vec2 vThicknessMapUv;
213
-
214
- #endif
215
- `,Eu=`
216
- #ifdef UV_TILE
217
- attribute float uvTile;
218
- uniform vec2 tileCount;
219
-
220
- mat3 makeTileTransform(float uvTile) {
221
- float col = mod(uvTile, tileCount.x);
222
- float row = (tileCount.y - floor(uvTile / tileCount.x) - 1.0);
223
-
224
- return mat3(
225
- 1.0 / tileCount.x, 0.0, 0.0,
226
- 0.0, 1.0 / tileCount.y, 0.0,
227
- col / tileCount.x, row / tileCount.y, 1.0);
228
- }
229
- #else
230
- mat3 makeTileTransform(float uvTile) {
231
- return mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
232
- }
233
- #endif
234
-
235
- #if defined( USE_UV ) || defined( USE_ANISOTROPY )
236
-
237
- varying vec2 vUv;
238
- #ifdef TILE_BLEND
239
- varying vec2 vUvNext;
240
- varying float vUvBlend;
241
- #endif
242
-
243
- #endif
244
- #ifdef USE_MAP
245
-
246
- uniform mat3 mapTransform;
247
- varying vec2 vMapUv;
248
- #ifdef TILE_BLEND
249
- varying vec2 vMapUvNext;
250
- #endif
251
-
252
- #endif
253
- #ifdef USE_ALPHAMAP
254
-
255
- uniform mat3 alphaMapTransform;
256
- varying vec2 vAlphaMapUv;
257
-
258
- #endif
259
- #ifdef USE_LIGHTMAP
260
-
261
- uniform mat3 lightMapTransform;
262
- varying vec2 vLightMapUv;
263
-
264
- #endif
265
- #ifdef USE_AOMAP
266
-
267
- uniform mat3 aoMapTransform;
268
- varying vec2 vAoMapUv;
269
-
270
- #endif
271
- #ifdef USE_BUMPMAP
272
-
273
- uniform mat3 bumpMapTransform;
274
- varying vec2 vBumpMapUv;
275
-
276
- #endif
277
- #ifdef USE_NORMALMAP
278
-
279
- uniform mat3 normalMapTransform;
280
- varying vec2 vNormalMapUv;
281
-
282
- #endif
283
- #ifdef USE_DISPLACEMENTMAP
284
-
285
- uniform mat3 displacementMapTransform;
286
- varying vec2 vDisplacementMapUv;
287
-
288
- #endif
289
- #ifdef USE_EMISSIVEMAP
290
-
291
- uniform mat3 emissiveMapTransform;
292
- varying vec2 vEmissiveMapUv;
293
-
294
- #endif
295
- #ifdef USE_METALNESSMAP
296
-
297
- uniform mat3 metalnessMapTransform;
298
- varying vec2 vMetalnessMapUv;
299
-
300
- #endif
301
- #ifdef USE_ROUGHNESSMAP
302
-
303
- uniform mat3 roughnessMapTransform;
304
- varying vec2 vRoughnessMapUv;
305
-
306
- #endif
307
- #ifdef USE_ANISOTROPYMAP
308
-
309
- uniform mat3 anisotropyMapTransform;
310
- varying vec2 vAnisotropyMapUv;
311
-
312
- #endif
313
- #ifdef USE_CLEARCOATMAP
314
-
315
- uniform mat3 clearcoatMapTransform;
316
- varying vec2 vClearcoatMapUv;
317
-
318
- #endif
319
- #ifdef USE_CLEARCOAT_NORMALMAP
320
-
321
- uniform mat3 clearcoatNormalMapTransform;
322
- varying vec2 vClearcoatNormalMapUv;
323
-
324
- #endif
325
- #ifdef USE_CLEARCOAT_ROUGHNESSMAP
326
-
327
- uniform mat3 clearcoatRoughnessMapTransform;
328
- varying vec2 vClearcoatRoughnessMapUv;
329
-
330
- #endif
331
- #ifdef USE_SHEEN_COLORMAP
332
-
333
- uniform mat3 sheenColorMapTransform;
334
- varying vec2 vSheenColorMapUv;
335
-
336
- #endif
337
- #ifdef USE_SHEEN_ROUGHNESSMAP
338
-
339
- uniform mat3 sheenRoughnessMapTransform;
340
- varying vec2 vSheenRoughnessMapUv;
341
-
342
- #endif
343
- #ifdef USE_IRIDESCENCEMAP
344
-
345
- uniform mat3 iridescenceMapTransform;
346
- varying vec2 vIridescenceMapUv;
347
-
348
- #endif
349
- #ifdef USE_IRIDESCENCE_THICKNESSMAP
350
-
351
- uniform mat3 iridescenceThicknessMapTransform;
352
- varying vec2 vIridescenceThicknessMapUv;
353
-
354
- #endif
355
- #ifdef USE_SPECULARMAP
356
-
357
- uniform mat3 specularMapTransform;
358
- varying vec2 vSpecularMapUv;
359
-
360
- #endif
361
- #ifdef USE_SPECULAR_COLORMAP
362
-
363
- uniform mat3 specularColorMapTransform;
364
- varying vec2 vSpecularColorMapUv;
365
-
366
- #endif
367
- #ifdef USE_SPECULAR_INTENSITYMAP
368
-
369
- uniform mat3 specularIntensityMapTransform;
370
- varying vec2 vSpecularIntensityMapUv;
371
-
372
- #endif
373
- #ifdef USE_TRANSMISSIONMAP
374
-
375
- uniform mat3 transmissionMapTransform;
376
- varying vec2 vTransmissionMapUv;
377
-
378
- #endif
379
- #ifdef USE_THICKNESSMAP
380
-
381
- uniform mat3 thicknessMapTransform;
382
- varying vec2 vThicknessMapUv;
383
-
384
- #endif
385
- `,Tu=`
386
- #ifdef UV_TILE
387
- mat3 tileTransform = makeTileTransform(floor(uvTile));
388
- #ifdef TILE_BLEND
389
- mat3 nextTileTransform = makeTileTransform(ceil(uvTile));
390
- vUvBlend = fract(uvTile);
391
- #endif
392
- #else
393
- mat3 tileTransform = makeTileTransform(0.0);
394
- #endif
395
-
396
- #if defined( USE_UV ) || defined( USE_ANISOTROPY )
397
-
398
- vUv = (tileTransform *vec3( uv, 1 )).xy;
399
- #if defined( TILE_BLEND ) && defined( UV_TILE )
400
- vUvNext = (nextTileTransform *vec3( uv, 1 )).xy;
401
- #endif
402
-
403
- #endif
404
- #ifdef USE_MAP
405
-
406
- vMapUv = ( tileTransform * (mapTransform * vec3( MAP_UV, 1 ) )).xy;
407
- #if defined( TILE_BLEND ) && defined( UV_TILE )
408
- vMapUvNext = (nextTileTransform * (mapTransform * vec3( MAP_UV, 1 ))).xy;
409
- #endif
410
-
411
- #endif
412
- #ifdef USE_ALPHAMAP
413
-
414
- vAlphaMapUv = ( tileTransform * (alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) )).xy;
415
-
416
- #endif
417
- #ifdef USE_LIGHTMAP
418
-
419
- vLightMapUv = ( tileTransform * (lightMapTransform * vec3( LIGHTMAP_UV, 1 ) )).xy;
420
-
421
- #endif
422
- #ifdef USE_AOMAP
423
-
424
- vAoMapUv = ( tileTransform * (aoMapTransform * vec3( AOMAP_UV, 1 ) )).xy;
425
-
426
- #endif
427
- #ifdef USE_BUMPMAP
428
-
429
- vBumpMapUv = ( tileTransform * (bumpMapTransform * vec3( BUMPMAP_UV, 1 ) )).xy;
430
-
431
- #endif
432
- #ifdef USE_NORMALMAP
433
-
434
- vNormalMapUv = ( tileTransform * (normalMapTransform * vec3( NORMALMAP_UV, 1 ) )).xy;
435
-
436
- #endif
437
- #ifdef USE_DISPLACEMENTMAP
438
-
439
- vDisplacementMapUv = ( tileTransform * (displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) )).xy;
440
-
441
- #endif
442
- #ifdef USE_EMISSIVEMAP
443
-
444
- vEmissiveMapUv = ( tileTransform * (emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) )).xy;
445
-
446
- #endif
447
- #ifdef USE_METALNESSMAP
448
-
449
- vMetalnessMapUv = ( tileTransform * (metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) )).xy;
450
-
451
- #endif
452
- #ifdef USE_ROUGHNESSMAP
453
-
454
- vRoughnessMapUv = ( tileTransform * (roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) )).xy;
455
-
456
- #endif
457
- #ifdef USE_ANISOTROPYMAP
458
-
459
- vAnisotropyMapUv = ( tileTransform * (anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) )).xy;
460
-
461
- #endif
462
- #ifdef USE_CLEARCOATMAP
463
-
464
- vClearcoatMapUv = ( tileTransform * (clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) )).xy;
465
-
466
- #endif
467
- #ifdef USE_CLEARCOAT_NORMALMAP
468
-
469
- vClearcoatNormalMapUv = ( tileTransform * (clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) )).xy;
470
-
471
- #endif
472
- #ifdef USE_CLEARCOAT_ROUGHNESSMAP
473
-
474
- vClearcoatRoughnessMapUv = ( tileTransform * (clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) )).xy;
475
-
476
- #endif
477
- #ifdef USE_IRIDESCENCEMAP
478
-
479
- vIridescenceMapUv = ( tileTransform * (iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) )).xy;
480
-
481
- #endif
482
- #ifdef USE_IRIDESCENCE_THICKNESSMAP
483
-
484
- vIridescenceThicknessMapUv = ( tileTransform * (iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) )).xy;
485
-
486
- #endif
487
- #ifdef USE_SHEEN_COLORMAP
488
-
489
- vSheenColorMapUv = ( tileTransform * (sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) )).xy;
490
-
491
- #endif
492
- #ifdef USE_SHEEN_ROUGHNESSMAP
493
-
494
- vSheenRoughnessMapUv = ( tileTransform * (sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) )).xy;
495
-
496
- #endif
497
- #ifdef USE_SPECULARMAP
498
-
499
- vSpecularMapUv = ( tileTransform * (specularMapTransform * vec3( SPECULARMAP_UV, 1 ) )).xy;
500
-
501
- #endif
502
- #ifdef USE_SPECULAR_COLORMAP
503
-
504
- vSpecularColorMapUv = ( tileTransform * (specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) )).xy;
505
-
506
- #endif
507
- #ifdef USE_SPECULAR_INTENSITYMAP
508
-
509
- vSpecularIntensityMapUv = ( tileTransform * (specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) )).xy;
510
-
511
- #endif
512
- #ifdef USE_TRANSMISSIONMAP
513
-
514
- vTransmissionMapUv = ( tileTransform * transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) )).xy;
515
-
516
- #endif
517
- #ifdef USE_THICKNESSMAP
518
-
519
- vThicknessMapUv = ( tileTransform * thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) )).xy;
520
-
521
- #endif
522
-
523
- `;const Re=Dh;function Ou(){Re.tile_pars_vertex=Eu,Re.tile_vertex=Tu,Re.tile_pars_fragment=Au,Re.tile_fragment=zu,Re.soft_pars_vertex=Cu,Re.soft_vertex=Pu,Re.soft_pars_fragment=Mu,Re.soft_fragment=Su}class ku extends ii{constructor(t){super(),this.type="ParticleEmitter",this.system=t}clone(){const t=this.system.clone();return t.emitter.copy(this,!0),t.emitter}dispose(){}extractFromCache(t){const e=[];for(const i in t){const s=t[i];delete s.metadata,e.push(s)}return e}toJSON(t,e={}){const i=this.children;this.children=this.children.filter(n=>n.type!=="ParticleSystemPreview");const s=super.toJSON(t);return this.children=i,this.system!==null&&(s.object.ps=this.system.toJSON(t,e)),s}}var k;(function(o){o[o.BillBoard=0]="BillBoard",o[o.StretchedBillBoard=1]="StretchedBillBoard",o[o.Mesh=2]="Mesh",o[o.Trail=3]="Trail",o[o.HorizontalBillBoard=4]="HorizontalBillBoard",o[o.VerticalBillBoard=5]="VerticalBillBoard"})(k||(k={}));class kl extends T{constructor(t){super(),this.type="VFXBatch",this.maxParticles=1e3,this.systems=new Set;const e=new xn;e.mask=t.layers.mask;const i=t.material.clone();i.defines={},Object.assign(i.defines,t.material.defines),this.settings={instancingGeometry:t.instancingGeometry,renderMode:t.renderMode,renderOrder:t.renderOrder,material:i,uTileCount:t.uTileCount,vTileCount:t.vTileCount,blendTiles:t.blendTiles,softParticles:t.softParticles,softNearFade:t.softNearFade,softFarFade:t.softFarFade,layers:e},this.frustumCulled=!1,this.renderOrder=this.settings.renderOrder}addSystem(t){this.systems.add(t)}removeSystem(t){this.systems.delete(t)}applyDepthTexture(t){const e=this.material.uniforms.depthTexture;e&&e.value!==t&&(e.value=t,this.material.needsUpdate=!0)}getVisibleSystems(){return Array.from(this.systems).filter(t=>t.emitter.visible)}}const Iu=new R(0,0,1),dr=new Q,Ru=new R,Fu=new R;new R;const ya=60,gn=new Wr(1,1,1,1);class Rn{set time(t){this.emissionState.time=t}get time(){return this.emissionState.time}get layers(){return this.rendererSettings.layers}get texture(){return this.rendererSettings.material.map}set texture(t){this.rendererSettings.material.map=t,this.neededToUpdateRender=!0}get material(){return this.rendererSettings.material}set material(t){this.rendererSettings.material=t,this.neededToUpdateRender=!0}get uTileCount(){return this.rendererSettings.uTileCount}set uTileCount(t){this.rendererSettings.uTileCount=t,this.neededToUpdateRender=!0}get vTileCount(){return this.rendererSettings.vTileCount}set vTileCount(t){this.rendererSettings.vTileCount=t,this.neededToUpdateRender=!0}get blendTiles(){return this.rendererSettings.blendTiles}set blendTiles(t){this.rendererSettings.blendTiles=t,this.neededToUpdateRender=!0}get softParticles(){return this.rendererSettings.softParticles}set softParticles(t){this.rendererSettings.softParticles=t,this.neededToUpdateRender=!0}get softNearFade(){return this.rendererSettings.softNearFade}set softNearFade(t){this.rendererSettings.softNearFade=t,this.neededToUpdateRender=!0}get softFarFade(){return this.rendererSettings.softFarFade}set softFarFade(t){this.rendererSettings.softFarFade=t,this.neededToUpdateRender=!0}get instancingGeometry(){return this.rendererSettings.instancingGeometry}set instancingGeometry(t){this.restart(),this.particles.length=0,this.rendererSettings.instancingGeometry=t,this.neededToUpdateRender=!0}get renderMode(){return this.rendererSettings.renderMode}set renderMode(t){if(this.rendererSettings.renderMode!==t){let e=!1;switch(this.rendererSettings.renderMode===k.Trail&&(e=!0),this.rendererSettings.renderMode===k.Mesh&&(this.startRotation=new $(0)),t){case k.Trail:this.rendererEmitterSettings={startLength:new $(30),followLocalOrigin:!1},e=!0;break;case k.Mesh:this.rendererEmitterSettings={geometry:gn},this.startRotation=new ls(new R(0,1,0),new $(0));break;case k.StretchedBillBoard:this.rendererEmitterSettings={speedFactor:0,lengthFactor:2},this.rendererSettings.instancingGeometry=gn;break;case k.BillBoard:case k.VerticalBillBoard:case k.HorizontalBillBoard:this.rendererEmitterSettings={},this.rendererSettings.instancingGeometry=gn;break}this.rendererSettings.renderMode=t,e&&(this.restart(),this.particles.length=0),this.neededToUpdateRender=!0}}get renderOrder(){return this.rendererSettings.renderOrder}set renderOrder(t){this.rendererSettings.renderOrder=t,this.neededToUpdateRender=!0}get blending(){return this.rendererSettings.material.blending}set blending(t){this.rendererSettings.material.blending=t,this.neededToUpdateRender=!0}constructor(t){if(this.temp=new R,this.travelDistance=0,this.normalMatrix=new fe,this.memory=[],this.listeners={},this.firstTimeUpdate=!0,this.autoDestroy=t.autoDestroy===void 0?!1:t.autoDestroy,this.duration=t.duration??1,this.looping=t.looping===void 0?!0:t.looping,this.prewarm=t.prewarm===void 0?!1:t.prewarm,this.startLife=t.startLife??new $(5),this.startSpeed=t.startSpeed??new $(0),this.startRotation=t.startRotation??new $(0),this.startSize=t.startSize??new $(1),this.startColor=t.startColor??new Ei(new Ut(1,1,1,1)),this.emissionOverTime=t.emissionOverTime??new $(10),this.emissionOverDistance=t.emissionOverDistance??new $(0),this.emissionBursts=t.emissionBursts??[],this.onlyUsedByOther=t.onlyUsedByOther??!1,this.emitterShape=t.shape??new Ti,this.behaviors=t.behaviors??new Array,this.worldSpace=t.worldSpace??!1,this.rendererEmitterSettings=t.rendererEmitterSettings??{},t.renderMode===k.StretchedBillBoard){const e=this.rendererEmitterSettings;t.speedFactor!==void 0&&(e.speedFactor=t.speedFactor),e.speedFactor=e.speedFactor??0,e.lengthFactor=e.lengthFactor??0}this.rendererSettings={instancingGeometry:t.instancingGeometry??gn,renderMode:t.renderMode??k.BillBoard,renderOrder:t.renderOrder??0,material:t.material,uTileCount:t.uTileCount??1,vTileCount:t.vTileCount??1,blendTiles:t.blendTiles??!1,softParticles:t.softParticles??!1,softNearFade:t.softNearFade??0,softFarFade:t.softFarFade??0,layers:t.layers??new xn},this.neededToUpdateRender=!0,this.particles=new Array,this.startTileIndex=t.startTileIndex||new $(0),this.emitter=new ku(this),this.paused=!1,this.particleNum=0,this.emissionState={isBursting:!1,burstParticleIndex:0,burstParticleCount:0,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,travelDistance:0},this.emissionBursts.forEach(e=>e.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory),this.emitEnded=!1,this.markForDestroy=!1,this.prewarmed=!1}pause(){this.paused=!0}play(){this.paused=!1}stop(){this.restart(),this.pause()}spawn(t,e,i){dr.setFromRotationMatrix(i);const s=Ru,n=dr,r=Fu;i.decompose(s,n,r);for(let a=0;a<t;a++){for(e.burstParticleIndex=a,this.particleNum++;this.particles.length<this.particleNum;)this.rendererSettings.renderMode===k.Trail?this.particles.push(new Fr):this.particles.push(new du);const l=this.particles[this.particleNum-1];if(l.reset(),l.speedModifier=1,this.startColor.startGen(l.memory),this.startColor.genColor(l.memory,l.startColor,this.emissionState.time),l.color.copy(l.startColor),this.startSpeed.startGen(l.memory),l.startSpeed=this.startSpeed.genValue(l.memory,e.time/this.duration),this.startLife.startGen(l.memory),l.life=this.startLife.genValue(l.memory,e.time/this.duration),l.age=0,this.startSize.startGen(l.memory),this.startSize.type==="vec3function")this.startSize.genValue(l.memory,l.startSize,e.time/this.duration);else{const c=this.startSize.genValue(l.memory,e.time/this.duration);l.startSize.set(c,c,c)}if(this.startTileIndex.startGen(l.memory),l.uvTile=this.startTileIndex.genValue(l.memory),l.size.copy(l.startSize),this.rendererSettings.renderMode===k.Mesh||this.rendererSettings.renderMode===k.BillBoard||this.rendererSettings.renderMode===k.VerticalBillBoard||this.rendererSettings.renderMode===k.HorizontalBillBoard||this.rendererSettings.renderMode===k.StretchedBillBoard){const c=l;this.startRotation.startGen(l.memory),this.rendererSettings.renderMode===k.Mesh?(c.rotation instanceof Q||(c.rotation=new Q),this.startRotation.type==="rotation"?this.startRotation.genValue(l.memory,c.rotation,1,e.time/this.duration):c.rotation.setFromAxisAngle(Iu,this.startRotation.genValue(c.memory,e.time/this.duration))):this.startRotation.type==="rotation"?c.rotation=0:c.rotation=this.startRotation.genValue(c.memory,e.time/this.duration)}else if(this.rendererSettings.renderMode===k.Trail){const c=l;this.rendererEmitterSettings.startLength.startGen(c.memory),c.length=this.rendererEmitterSettings.startLength.genValue(c.memory,e.time/this.duration)}if(this.emitterShape.initialize(l,e),this.rendererSettings.renderMode===k.Trail&&this.rendererEmitterSettings.followLocalOrigin){const c=l;c.localPosition=new R().copy(c.position)}this.worldSpace?(l.position.applyMatrix4(i),l.startSize.multiply(r).abs(),l.size.copy(l.startSize),l.velocity.multiply(r).applyMatrix3(this.normalMatrix),l.rotation&&l.rotation instanceof Q&&l.rotation.multiplyQuaternions(dr,l.rotation)):this.onlyUsedByOther&&(l.parentMatrix=i);for(let c=0;c<this.behaviors.length;c++)this.behaviors[c].initialize(l,this)}}endEmit(){this.emitEnded=!0,this.autoDestroy&&(this.markForDestroy=!0),this.fire({type:"emitEnd",particleSystem:this})}dispose(){this._renderer&&this._renderer.deleteSystem(this),this.emitter.dispose(),this.emitter.parent&&this.emitter.parent.remove(this.emitter),this.fire({type:"destroy",particleSystem:this})}restart(){this.memory.length=0,this.paused=!1,this.particleNum=0,this.emissionState.isBursting=!1,this.emissionState.burstIndex=0,this.emissionState.burstWaveIndex=0,this.emissionState.time=0,this.emissionState.waitEmiting=0,this.behaviors.forEach(t=>{t.reset()}),this.emitEnded=!1,this.markForDestroy=!1,this.prewarmed=!1,this.emissionBursts.forEach(t=>t.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory)}update(t){if(this.paused)return;let e=this.emitter;for(;e.parent;)e=e.parent;if(e.type!=="Scene"){this.dispose();return}if(this.firstTimeUpdate&&(this.firstTimeUpdate=!1,this.emitter.updateWorldMatrix(!0,!1)),this.emitEnded&&this.particleNum===0){this.markForDestroy&&this.emitter.parent&&this.dispose();return}if(this.looping&&this.prewarm&&!this.prewarmed){this.prewarmed=!0;for(let i=0;i<this.duration*ya;i++)this.update(1/ya)}t>.1&&(t=.1),this.neededToUpdateRender&&(this._renderer&&this._renderer.updateSystem(this),this.neededToUpdateRender=!1),this.onlyUsedByOther||this.emit(t,this.emissionState,this.emitter.matrixWorld),this.emitterShape.update(this,t);for(let i=0;i<this.behaviors.length;i++){this.behaviors[i].frameUpdate(t);for(let s=0;s<this.particleNum;s++)this.particles[s].died||this.behaviors[i].update(this.particles[s],t)}for(let i=0;i<this.particleNum;i++)this.rendererEmitterSettings.followLocalOrigin&&this.particles[i].localPosition?(this.particles[i].position.copy(this.particles[i].localPosition),this.particles[i].parentMatrix?this.particles[i].position.applyMatrix4(this.particles[i].parentMatrix):this.particles[i].position.applyMatrix4(this.emitter.matrixWorld)):this.particles[i].position.addScaledVector(this.particles[i].velocity,t*this.particles[i].speedModifier),this.particles[i].age+=t;if(this.rendererSettings.renderMode===k.Trail)for(let i=0;i<this.particleNum;i++)this.particles[i].update();for(let i=0;i<this.particleNum;i++){const s=this.particles[i];s.died&&(!(s instanceof Fr)||s.previous.length===0)&&(this.particles[i]=this.particles[this.particleNum-1],this.particles[this.particleNum-1]=s,this.particleNum--,i--,this.fire({type:"particleDied",particleSystem:this,particle:s}))}}emit(t,e,i){e.time>this.duration&&(this.looping?(e.time-=this.duration,e.burstIndex=0,this.behaviors.forEach(n=>{n.reset()})):!this.emitEnded&&!this.onlyUsedByOther&&this.endEmit()),this.normalMatrix.getNormalMatrix(i);const s=Math.ceil(e.waitEmiting);for(this.spawn(s,e,i),e.waitEmiting-=s;e.burstIndex<this.emissionBursts.length&&this.emissionBursts[e.burstIndex].time<=e.time;){if(Math.random()<this.emissionBursts[e.burstIndex].probability){const n=this.emissionBursts[e.burstIndex].count.genValue(this.memory,this.time);e.isBursting=!0,e.burstParticleCount=n,this.spawn(n,e,i),e.isBursting=!1}e.burstIndex++}if(!this.emitEnded&&(e.waitEmiting+=t*this.emissionOverTime.genValue(this.memory,e.time/this.duration),e.previousWorldPos!=null)){this.temp.set(i.elements[12],i.elements[13],i.elements[14]),e.travelDistance+=e.previousWorldPos.distanceTo(this.temp);const n=this.emissionOverDistance.genValue(this.memory,e.time/this.duration);if(e.travelDistance*n>0){const r=Math.floor(e.travelDistance*n);e.travelDistance-=r/n,e.waitEmiting+=r}}e.previousWorldPos===void 0&&(e.previousWorldPos=new R),e.previousWorldPos.set(i.elements[12],i.elements[13],i.elements[14]),e.time+=t}toJSON(t,e={}){if((t===void 0||typeof t=="string")&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}}),t.materials[this.rendererSettings.material.uuid]=this.rendererSettings.material.toJSON(t),e.useUrlForImage&&this.texture?.source!==void 0){const r=this.texture.source;t.images[r.uuid]={uuid:r.uuid,url:this.texture.image.url}}let s;this.renderMode===k.Trail?s={startLength:this.rendererEmitterSettings.startLength.toJSON(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===k.Mesh?s={}:this.renderMode===k.StretchedBillBoard?s={speedFactor:this.rendererEmitterSettings.speedFactor,lengthFactor:this.rendererEmitterSettings.lengthFactor}:s={};const n=this.rendererSettings.instancingGeometry;return t.geometries&&!t.geometries[n.uuid]&&(t.geometries[n.uuid]=n.toJSON()),{version:"3.0",autoDestroy:this.autoDestroy,looping:this.looping,prewarm:this.prewarm,duration:this.duration,shape:this.emitterShape.toJSON(),startLife:this.startLife.toJSON(),startSpeed:this.startSpeed.toJSON(),startRotation:this.startRotation.toJSON(),startSize:this.startSize.toJSON(),startColor:this.startColor.toJSON(),emissionOverTime:this.emissionOverTime.toJSON(),emissionOverDistance:this.emissionOverDistance.toJSON(),emissionBursts:this.emissionBursts.map(r=>({time:r.time,count:r.count.toJSON(),probability:r.probability,interval:r.interval,cycle:r.cycle})),onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:this.rendererSettings.instancingGeometry.uuid,renderOrder:this.renderOrder,renderMode:this.renderMode,rendererEmitterSettings:s,material:this.rendererSettings.material.uuid,layers:this.layers.mask,startTileIndex:this.startTileIndex.toJSON(),uTileCount:this.uTileCount,vTileCount:this.vTileCount,blendTiles:this.blendTiles,softParticles:this.rendererSettings.softParticles,softFarFade:this.rendererSettings.softFarFade,softNearFade:this.rendererSettings.softNearFade,behaviors:this.behaviors.map(r=>r.toJSON()),worldSpace:this.worldSpace}}static fromJSON(t,e,i){const s=cu(t.shape,e);let n;if(t.renderMode===k.Trail){const l=t.rendererEmitterSettings;n={startLength:l.startLength!=null?j(l.startLength):new $(30),followLocalOrigin:l.followLocalOrigin}}else t.renderMode===k.Mesh?n={}:t.renderMode===k.StretchedBillBoard?(n=t.rendererEmitterSettings,t.speedFactor!=null&&(n.speedFactor=t.speedFactor)):n={};const r=new xn;t.layers&&(r.mask=t.layers);const a=new Rn({autoDestroy:t.autoDestroy,looping:t.looping,prewarm:t.prewarm,duration:t.duration,shape:s,startLife:j(t.startLife),startSpeed:j(t.startSpeed),startRotation:kn(t.startRotation),startSize:kn(t.startSize),startColor:qr(t.startColor),emissionOverTime:j(t.emissionOverTime),emissionOverDistance:j(t.emissionOverDistance),emissionBursts:t.emissionBursts?.map(l=>({time:l.time,count:typeof l.count=="number"?new $(l.count):j(l.count),probability:l.probability??1,interval:l.interval??.1,cycle:l.cycle??1})),onlyUsedByOther:t.onlyUsedByOther,instancingGeometry:e.geometries[t.instancingGeometry],renderMode:t.renderMode,rendererEmitterSettings:n,renderOrder:t.renderOrder,layers:r,material:t.material?e.materials[t.material]:t.texture?new vt({map:e.textures[t.texture],transparent:t.transparent??!0,blending:t.blending,side:ei}):new vt({color:16777215,transparent:!0,blending:Gr,side:ei}),startTileIndex:typeof t.startTileIndex=="number"?new $(t.startTileIndex):j(t.startTileIndex),uTileCount:t.uTileCount,vTileCount:t.vTileCount,blendTiles:t.blendTiles,softParticles:t.softParticles,softFarFade:t.softFarFade,softNearFade:t.softNearFade,behaviors:[],worldSpace:t.worldSpace});return a.behaviors=t.behaviors.map(l=>{const c=vu(l,a);return c&&c.type==="EmitSubParticleSystem"&&(i[l.subParticleSystem]=c),c}).filter(l=>l!==null),a}addBehavior(t){this.behaviors.push(t)}getRendererSettings(){return this.rendererSettings}addEventListener(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)}removeAllEventListeners(t){this.listeners[t]&&(this.listeners[t]=[])}removeEventListener(t,e){if(this.listeners[t]){const i=this.listeners[t].indexOf(e);i!==-1&&this.listeners[t].splice(i,1)}}fire(t){this.listeners[t.type]&&this.listeners[t.type].forEach(e=>e(t))}clone(){const t=[];for(const n of this.emissionBursts){const r={};Object.assign(r,n),t.push(r)}const e=[];for(const n of this.behaviors)e.push(n.clone());let i;this.renderMode===k.Trail?i={startLength:this.rendererEmitterSettings.startLength.clone(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===k.StretchedBillBoard?i={lengthFactor:this.rendererEmitterSettings.lengthFactor,speedFactor:this.rendererEmitterSettings.speedFactor}:i={};const s=new xn;return s.mask=this.layers.mask,new Rn({autoDestroy:this.autoDestroy,looping:this.looping,duration:this.duration,shape:this.emitterShape.clone(),startLife:this.startLife.clone(),startSpeed:this.startSpeed.clone(),startRotation:this.startRotation.clone(),startSize:this.startSize.clone(),startColor:this.startColor.clone(),emissionOverTime:this.emissionOverTime.clone(),emissionOverDistance:this.emissionOverDistance.clone(),emissionBursts:t,onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:this.rendererSettings.instancingGeometry,renderMode:this.renderMode,renderOrder:this.renderOrder,rendererEmitterSettings:i,material:this.rendererSettings.material,startTileIndex:this.startTileIndex,uTileCount:this.uTileCount,vTileCount:this.vTileCount,blendTiles:this.blendTiles,softParticles:this.softParticles,softFarFade:this.softFarFade,softNearFade:this.softNearFade,behaviors:e,worldSpace:this.worldSpace,layers:s})}}var ur=`
524
-
525
- #include <common>
526
- #include <color_pars_fragment>
527
- #include <map_pars_fragment>
528
- #include <logdepthbuf_pars_fragment>
529
- #include <clipping_planes_pars_fragment>
530
- #include <alphatest_pars_fragment>
531
-
532
- #include <tile_pars_fragment>
533
- #include <soft_pars_fragment>
534
-
535
- void main() {
536
-
537
- #include <clipping_planes_fragment>
538
-
539
- vec3 outgoingLight = vec3( 0.0 );
540
- vec4 diffuseColor = vColor;
541
-
542
- #include <logdepthbuf_fragment>
543
-
544
- #include <tile_fragment>
545
- #include <alphatest_fragment>
546
-
547
- outgoingLight = diffuseColor.rgb;
548
-
549
- #ifdef USE_COLOR_AS_ALPHA
550
- gl_FragColor = vec4( outgoingLight, diffuseColor.r );
551
- #else
552
- gl_FragColor = vec4( outgoingLight, diffuseColor.a );
553
- #endif
554
-
555
- #include <soft_fragment>
556
- #include <tonemapping_fragment>
557
- }
558
- `,Zr=`
559
- #define STANDARD
560
-
561
- #ifdef PHYSICAL
562
- #define IOR
563
- #define USE_SPECULAR
564
- #endif
565
-
566
- uniform vec3 diffuse;
567
- uniform vec3 emissive;
568
- uniform float roughness;
569
- uniform float metalness;
570
- uniform float opacity;
571
-
572
- #ifdef IOR
573
- uniform float ior;
574
- #endif
575
-
576
- #ifdef USE_SPECULAR
577
- uniform float specularIntensity;
578
- uniform vec3 specularColor;
579
-
580
- #ifdef USE_SPECULAR_COLORMAP
581
- uniform sampler2D specularColorMap;
582
- #endif
583
-
584
- #ifdef USE_SPECULAR_INTENSITYMAP
585
- uniform sampler2D specularIntensityMap;
586
- #endif
587
- #endif
588
-
589
- #ifdef USE_CLEARCOAT
590
- uniform float clearcoat;
591
- uniform float clearcoatRoughness;
592
- #endif
593
-
594
- #ifdef USE_DISPERSION
595
- uniform float dispersion;
596
- #endif
597
-
598
- #ifdef USE_IRIDESCENCE
599
- uniform float iridescence;
600
- uniform float iridescenceIOR;
601
- uniform float iridescenceThicknessMinimum;
602
- uniform float iridescenceThicknessMaximum;
603
- #endif
604
-
605
- #ifdef USE_SHEEN
606
- uniform vec3 sheenColor;
607
- uniform float sheenRoughness;
608
-
609
- #ifdef USE_SHEEN_COLORMAP
610
- uniform sampler2D sheenColorMap;
611
- #endif
612
-
613
- #ifdef USE_SHEEN_ROUGHNESSMAP
614
- uniform sampler2D sheenRoughnessMap;
615
- #endif
616
- #endif
617
-
618
- #ifdef USE_ANISOTROPY
619
- uniform vec2 anisotropyVector;
620
-
621
- #ifdef USE_ANISOTROPYMAP
622
- uniform sampler2D anisotropyMap;
623
- #endif
624
- #endif
625
-
626
- varying vec3 vViewPosition;
627
-
628
- #include <common>
629
- #include <packing>
630
- #include <dithering_pars_fragment>
631
- #include <color_pars_fragment>
632
- #include <uv_pars_fragment>
633
- #include <map_pars_fragment>
634
- #include <alphamap_pars_fragment>
635
- #include <alphatest_pars_fragment>
636
- #include <alphahash_pars_fragment>
637
- #include <aomap_pars_fragment>
638
- #include <lightmap_pars_fragment>
639
- #include <emissivemap_pars_fragment>
640
- #include <iridescence_fragment>
641
- #include <cube_uv_reflection_fragment>
642
- #include <envmap_common_pars_fragment>
643
- #include <envmap_physical_pars_fragment>
644
- #include <fog_pars_fragment>
645
- #include <lights_pars_begin>
646
- #include <normal_pars_fragment>
647
- #include <lights_physical_pars_fragment>
648
- #include <transmission_pars_fragment>
649
- #include <shadowmap_pars_fragment>
650
- #include <bumpmap_pars_fragment>
651
- #include <normalmap_pars_fragment>
652
- #include <clearcoat_pars_fragment>
653
- #include <iridescence_pars_fragment>
654
- #include <roughnessmap_pars_fragment>
655
- #include <metalnessmap_pars_fragment>
656
- #include <logdepthbuf_pars_fragment>
657
- #include <clipping_planes_pars_fragment>
658
-
659
- void main() {
660
-
661
- vec4 diffuseColor = vec4( diffuse, opacity );
662
- #include <clipping_planes_fragment>
663
-
664
- ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
665
- vec3 totalEmissiveRadiance = emissive;
666
-
667
- #include <logdepthbuf_fragment>
668
- #include <map_fragment>
669
- #include <color_fragment>
670
- #include <alphamap_fragment>
671
- #include <alphatest_fragment>
672
- #include <alphahash_fragment>
673
- #include <roughnessmap_fragment>
674
- #include <metalnessmap_fragment>
675
- #include <normal_fragment_begin>
676
- #include <normal_fragment_maps>
677
- #include <clearcoat_normal_fragment_begin>
678
- #include <clearcoat_normal_fragment_maps>
679
- #include <emissivemap_fragment>
680
-
681
- // accumulation
682
- #include <lights_physical_fragment>
683
- #include <lights_fragment_begin>
684
- #include <lights_fragment_maps>
685
- #include <lights_fragment_end>
686
-
687
- // modulation
688
- #include <aomap_fragment>
689
-
690
- vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
691
- vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
692
-
693
- #include <transmission_fragment>
694
-
695
- vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
696
-
697
- #ifdef USE_SHEEN
698
-
699
- // Sheen energy compensation approximation calculation can be found at the end of
700
- // https://drive.google.com/file/d/1T0D1VSyR4AllqIJTQAraEIzjlb5h4FKH/view?usp=sharing
701
- float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );
702
-
703
- outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;
704
-
705
- #endif
706
-
707
- #ifdef USE_CLEARCOAT
708
-
709
- float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );
710
-
711
- vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
712
-
713
- outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;
714
-
715
- #endif
716
-
717
- #include <opaque_fragment>
718
- #include <tonemapping_fragment>
719
- #include <colorspace_fragment>
720
- #include <fog_fragment>
721
- #include <premultiplied_alpha_fragment>
722
- #include <dithering_fragment>
723
- }`,Lu=`
724
- #include <common>
725
- #include <color_pars_vertex>
726
- #include <logdepthbuf_pars_vertex>
727
- #include <clipping_planes_pars_vertex>
728
-
729
- #include <tile_pars_vertex>
730
- #include <soft_pars_vertex>
731
-
732
- attribute vec3 offset;
733
- attribute float rotation;
734
- attribute vec3 size;
735
-
736
- void main() {
737
-
738
- vec2 alignedPosition = position.xy * size.xy;
739
-
740
- vec2 rotatedPosition;
741
- rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
742
- rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
743
- #ifdef HORIZONTAL
744
- vec4 mvPosition = modelMatrix * vec4( offset, 1.0 );
745
- mvPosition.x += rotatedPosition.x;
746
- mvPosition.z -= rotatedPosition.y;
747
- mvPosition = viewMatrix * mvPosition;
748
- #elif defined(VERTICAL)
749
- vec4 mvPosition = modelMatrix * vec4( offset, 1.0 );
750
- mvPosition.y += rotatedPosition.y;
751
- mvPosition = viewMatrix * mvPosition;
752
- mvPosition.x += rotatedPosition.x;
753
- #else
754
- vec4 mvPosition = modelViewMatrix * vec4( offset, 1.0 );
755
- mvPosition.xy += rotatedPosition;
756
- #endif
757
-
758
- vColor = color;
759
-
760
- gl_Position = projectionMatrix * mvPosition;
761
-
762
- #include <logdepthbuf_vertex>
763
-
764
- #include <clipping_planes_vertex>
765
-
766
- #include <tile_vertex>
767
- #include <soft_vertex>
768
- }
769
- `,Bu=`
770
- #include <common>
771
- #include <color_pars_vertex>
772
- #include <logdepthbuf_pars_vertex>
773
- #include <clipping_planes_pars_vertex>
774
- #include <tile_pars_vertex>
775
- #include <soft_pars_vertex>
776
-
777
- attribute vec3 offset;
778
- attribute vec4 rotation;
779
- attribute vec3 size;
780
- // attribute vec4 color;
781
-
782
- void main() {
783
-
784
- float x2 = rotation.x + rotation.x, y2 = rotation.y + rotation.y, z2 = rotation.z + rotation.z;
785
- float xx = rotation.x * x2, xy = rotation.x * y2, xz = rotation.x * z2;
786
- float yy = rotation.y * y2, yz = rotation.y * z2, zz = rotation.z * z2;
787
- float wx = rotation.w * x2, wy = rotation.w * y2, wz = rotation.w * z2;
788
- float sx = size.x, sy = size.y, sz = size.z;
789
-
790
- mat4 matrix = mat4(( 1.0 - ( yy + zz ) ) * sx, ( xy + wz ) * sx, ( xz - wy ) * sx, 0.0, // 1. column
791
- ( xy - wz ) * sy, ( 1.0 - ( xx + zz ) ) * sy, ( yz + wx ) * sy, 0.0, // 2. column
792
- ( xz + wy ) * sz, ( yz - wx ) * sz, ( 1.0 - ( xx + yy ) ) * sz, 0.0, // 3. column
793
- offset.x, offset.y, offset.z, 1.0);
794
-
795
- vec4 mvPosition = modelViewMatrix * (matrix * vec4( position, 1.0 ));
796
-
797
- vColor = color;
798
-
799
- gl_Position = projectionMatrix * mvPosition;
800
-
801
- #include <logdepthbuf_vertex>
802
- #include <clipping_planes_vertex>
803
- #include <tile_vertex>
804
- #include <soft_vertex>
805
- }
806
- `,Qr=`
807
- #define STANDARD
808
- varying vec3 vViewPosition;
809
- #ifdef USE_TRANSMISSION
810
- varying vec3 vWorldPosition;
811
- #endif
812
- #include <common>
813
-
814
- attribute vec3 offset;
815
- attribute vec4 rotation;
816
- attribute vec3 size;
817
- #include <tile_pars_vertex>
818
- #include <displacementmap_pars_vertex>
819
- #include <color_pars_vertex>
820
- #include <fog_pars_vertex>
821
- #include <normal_pars_vertex>
822
- #include <morphtarget_pars_vertex>
823
- #include <skinning_pars_vertex>
824
- #include <shadowmap_pars_vertex>
825
- #include <logdepthbuf_pars_vertex>
826
- #include <clipping_planes_pars_vertex>
827
-
828
- void main() {
829
-
830
- #include <tile_vertex>
831
- float x2 = rotation.x + rotation.x, y2 = rotation.y + rotation.y, z2 = rotation.z + rotation.z;
832
- float xx = rotation.x * x2, xy = rotation.x * y2, xz = rotation.x * z2;
833
- float yy = rotation.y * y2, yz = rotation.y * z2, zz = rotation.z * z2;
834
- float wx = rotation.w * x2, wy = rotation.w * y2, wz = rotation.w * z2;
835
- float sx = size.x, sy = size.y, sz = size.z;
836
-
837
- mat4 particleMatrix = mat4(( 1.0 - ( yy + zz ) ) * sx, ( xy + wz ) * sx, ( xz - wy ) * sx, 0.0, // 1. column
838
- ( xy - wz ) * sy, ( 1.0 - ( xx + zz ) ) * sy, ( yz + wx ) * sy, 0.0, // 2. column
839
- ( xz + wy ) * sz, ( yz - wx ) * sz, ( 1.0 - ( xx + yy ) ) * sz, 0.0, // 3. column
840
- offset.x, offset.y, offset.z, 1.0);
841
-
842
- #include <color_vertex>
843
- #include <morphinstance_vertex>
844
- #include <morphcolor_vertex>
845
- #include <batching_vertex>
846
-
847
- #include <beginnormal_vertex>
848
- #include <morphnormal_vertex>
849
- #include <skinbase_vertex>
850
- #include <skinnormal_vertex>
851
-
852
- // replace defaultnormal_vertex
853
- vec3 transformedNormal = objectNormal;
854
- mat3 m = mat3( particleMatrix );
855
- transformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );
856
- transformedNormal = m * transformedNormal;
857
- transformedNormal = normalMatrix * transformedNormal;
858
- #ifdef FLIP_SIDED
859
- transformedNormal = - transformedNormal;
860
- #endif
861
- #ifdef USE_TANGENT
862
- vec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;
863
- #ifdef FLIP_SIDED
864
- transformedTangent = - transformedTangent;
865
- #endif
866
- #endif
867
-
868
- #include <normal_vertex>
869
- #include <begin_vertex>
870
- #include <morphtarget_vertex>
871
- #include <skinning_vertex>
872
- #include <displacementmap_vertex>
873
-
874
- // replace include <project_vertex>
875
- vec4 mvPosition = vec4( transformed, 1.0 );
876
- mvPosition = modelViewMatrix * (particleMatrix * mvPosition);
877
- gl_Position = projectionMatrix * mvPosition;
878
-
879
- #include <logdepthbuf_vertex>
880
- #include <clipping_planes_vertex>
881
-
882
- vViewPosition = - mvPosition.xyz;
883
-
884
- #include <worldpos_vertex>
885
- #include <shadowmap_vertex>
886
- #include <fog_vertex>
887
- #ifdef USE_TRANSMISSION
888
- vWorldPosition = worldPosition.xyz;
889
- #endif
890
- }
891
- `,Nu=`
892
- #include <common>
893
- #include <color_pars_vertex>
894
- #include <logdepthbuf_pars_vertex>
895
- #include <clipping_planes_pars_vertex>
896
-
897
- #include <tile_pars_vertex>
898
- #include <soft_pars_vertex>
899
-
900
- attribute vec3 offset;
901
- attribute float rotation;
902
- attribute vec3 size;
903
- attribute vec4 velocity;
904
-
905
- uniform float speedFactor;
906
-
907
- void main() {
908
- float lengthFactor = velocity.w;
909
- float avgSize = (size.x + size.y) * 0.5;
910
- #ifdef USE_SKEW
911
- vec4 mvPosition = modelViewMatrix * vec4( offset, 1.0 );
912
- vec3 viewVelocity = normalMatrix * velocity.xyz;
913
-
914
- vec3 scaledPos = vec3(position.xy * size.xy, position.z);
915
- float vlength = length(viewVelocity);
916
- vec3 projVelocity = dot(scaledPos, viewVelocity) * viewVelocity / vlength;
917
- mvPosition.xyz += scaledPos + projVelocity * (speedFactor / avgSize + lengthFactor / vlength);
918
- #else
919
- vec4 mvPosition = modelViewMatrix * vec4( offset, 1.0 );
920
- vec3 viewVelocity = normalMatrix * velocity.xyz;
921
- float vlength = length(viewVelocity);
922
- mvPosition.xyz += position.y * normalize(cross(mvPosition.xyz, viewVelocity)) * avgSize; // switch the cross to match unity implementation
923
- mvPosition.xyz -= (position.x + 0.5) * viewVelocity * (1.0 + lengthFactor / vlength) * avgSize; // minus position.x to match unity implementation
924
- #endif
925
- vColor = color;
926
- gl_Position = projectionMatrix * mvPosition;
927
- #include <logdepthbuf_vertex>
928
- #include <clipping_planes_vertex>
929
- #include <tile_vertex>
930
- #include <soft_vertex>
931
- }
932
- `;function Lr(o){return o===0?"uv":`uv${o}`}class Hu extends fl{constructor(t){super(t)}onBeforeCompile(t,e){super.onBeforeCompile(t,e),t.vertexShader=Qr,t.fragmentShader=Zr}}class Du extends Mh{constructor(t){super(t)}onBeforeCompile(t,e){super.onBeforeCompile(t,e),t.vertexShader=Qr,t.fragmentShader=Zr}}class Uu extends kl{constructor(t){super(t),this.vector_=new R,this.vector2_=new R,this.vector3_=new R,this.quaternion_=new Q,this.quaternion2_=new Q,this.quaternion3_=new Q,this.rotationMat_=new fe,this.rotationMat2_=new fe,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}buildExpandableBuffers(){this.offsetBuffer=new we(new Float32Array(this.maxParticles*3),3),this.offsetBuffer.setUsage(Rt),this.geometry.setAttribute("offset",this.offsetBuffer),this.colorBuffer=new we(new Float32Array(this.maxParticles*4),4),this.colorBuffer.setUsage(Rt),this.geometry.setAttribute("color",this.colorBuffer),this.settings.renderMode===k.Mesh?(this.rotationBuffer=new we(new Float32Array(this.maxParticles*4),4),this.rotationBuffer.setUsage(Rt),this.geometry.setAttribute("rotation",this.rotationBuffer)):(this.settings.renderMode===k.BillBoard||this.settings.renderMode===k.HorizontalBillBoard||this.settings.renderMode===k.VerticalBillBoard||this.settings.renderMode===k.StretchedBillBoard)&&(this.rotationBuffer=new we(new Float32Array(this.maxParticles),1),this.rotationBuffer.setUsage(Rt),this.geometry.setAttribute("rotation",this.rotationBuffer)),this.sizeBuffer=new we(new Float32Array(this.maxParticles*3),3),this.sizeBuffer.setUsage(Rt),this.geometry.setAttribute("size",this.sizeBuffer),this.uvTileBuffer=new we(new Float32Array(this.maxParticles),1),this.uvTileBuffer.setUsage(Rt),this.geometry.setAttribute("uvTile",this.uvTileBuffer),this.settings.renderMode===k.StretchedBillBoard&&(this.velocityBuffer=new we(new Float32Array(this.maxParticles*4),4),this.velocityBuffer.setUsage(Rt),this.geometry.setAttribute("velocity",this.velocityBuffer))}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new Sh,this.geometry.setIndex(this.settings.instancingGeometry.getIndex()),this.settings.instancingGeometry.hasAttribute("normal")&&this.geometry.setAttribute("normal",this.settings.instancingGeometry.getAttribute("normal")),this.geometry.setAttribute("position",this.settings.instancingGeometry.getAttribute("position")),this.settings.instancingGeometry.hasAttribute("uv")&&this.geometry.setAttribute("uv",this.settings.instancingGeometry.getAttribute("uv")),this.buildExpandableBuffers()}expandBuffers(t){for(;t>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const t={},e={};this.settings.material.type!=="MeshStandardMaterial"&&this.settings.material.type!=="MeshPhysicalMaterial"&&(t.map=new Zt(this.settings.material.map)),this.settings.material.alphaTest&&(e.USE_ALPHATEST="",t.alphaTest=new Zt(this.settings.material.alphaTest)),e.USE_UV="";const i=this.settings.uTileCount,s=this.settings.vTileCount;(i>1||s>1)&&(e.UV_TILE="",t.tileCount=new Zt(new zi(i,s))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(e.USE_COLOR_AS_ALPHA=""),this.settings.material.normalMap&&(e.USE_NORMALMAP="",e.NORMALMAP_UV=Lr(this.settings.material.normalMap.channel),t.normalMapTransform=new Zt(new fe().copy(this.settings.material.normalMap.matrix))),this.settings.material.map&&(e.USE_MAP="",this.settings.blendTiles&&(e.TILE_BLEND=""),e.MAP_UV=Lr(this.settings.material.map.channel),t.mapTransform=new Zt(new fe().copy(this.settings.material.map.matrix))),e.USE_COLOR_ALPHA="";let n;if(this.settings.softParticles){e.SOFT_PARTICLES="";const a=this.settings.softNearFade,l=1/(this.settings.softFarFade-this.settings.softNearFade);t.softParams=new Zt(new zi(a,l)),t.depthTexture=new Zt(null);const c=t.projParams=new Zt(new Ut);n=(d,h,f)=>{c.value.set(f.near,f.far,0,0)}}let r=!1;if(this.settings.renderMode===k.BillBoard||this.settings.renderMode===k.VerticalBillBoard||this.settings.renderMode===k.HorizontalBillBoard||this.settings.renderMode===k.Mesh){let a,l;this.settings.renderMode===k.Mesh?this.settings.material.type==="MeshStandardMaterial"||this.settings.material.type==="MeshPhysicalMaterial"?(e.USE_COLOR="",a=Qr,l=Zr,r=!0):(a=Bu,l=ur):(a=Lu,l=ur),this.settings.renderMode===k.VerticalBillBoard?e.VERTICAL="":this.settings.renderMode===k.HorizontalBillBoard&&(e.HORIZONTAL="");let c=!1;this.settings.renderMode===k.Mesh&&(this.settings.material.type==="MeshStandardMaterial"?(this.material=new Hu({}),this.material.copy(this.settings.material),this.material.uniforms=t,this.material.defines=e,c=!0):this.settings.material.type==="MeshPhysicalMaterial"&&(this.material=new Du({}),this.material.copy(this.settings.material),this.material.uniforms=t,this.material.defines=e,c=!0)),c||(this.material=new is({uniforms:t,defines:e,vertexShader:a,fragmentShader:l,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,blending:this.settings.material.blending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha,side:this.settings.material.side,alphaTest:this.settings.material.alphaTest,depthTest:this.settings.material.depthTest,lights:r}))}else if(this.settings.renderMode===k.StretchedBillBoard)t.speedFactor=new Zt(1),this.material=new is({uniforms:t,defines:e,vertexShader:Nu,fragmentShader:ur,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,blending:this.settings.material.blending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha,side:this.settings.material.side,alphaTest:this.settings.material.alphaTest,depthTest:this.settings.material.depthTest});else throw new Error("render mode unavailable");this.material&&n&&(this.material.onBeforeRender=n)}update(){let t=0,e=0;const i=this.getVisibleSystems();for(const s of i)e+=s.particleNum;e>this.maxParticles&&this.expandBuffers(e);for(const s of i){s.emitter.updateMatrixWorld&&(s.emitter.updateWorldMatrix(!0,!1),s.emitter.updateMatrixWorld(!0));const n=s.particles,r=s.particleNum,a=this.quaternion2_,l=this.vector2_,c=this.vector3_;s.emitter.matrixWorld.decompose(l,a,c),this.rotationMat_.setFromMatrix4(s.emitter.matrixWorld);for(let d=0;d<r;d++,t++){const h=n[d];if(this.settings.renderMode===k.Mesh){let u;if(s.worldSpace)u=h.rotation;else{let p;h.parentMatrix?p=this.quaternion3_.setFromRotationMatrix(h.parentMatrix):p=a,u=this.quaternion_,u.copy(p).multiply(h.rotation)}this.rotationBuffer.setXYZW(t,u.x,u.y,u.z,u.w)}else(this.settings.renderMode===k.StretchedBillBoard||this.settings.renderMode===k.VerticalBillBoard||this.settings.renderMode===k.HorizontalBillBoard||this.settings.renderMode===k.BillBoard)&&this.rotationBuffer.setX(t,h.rotation);let f;if(s.worldSpace?f=h.position:(f=this.vector_,h.parentMatrix?f.copy(h.position).applyMatrix4(h.parentMatrix):f.copy(h.position).applyMatrix4(s.emitter.matrixWorld)),this.offsetBuffer.setXYZ(t,f.x,f.y,f.z),this.colorBuffer.setXYZW(t,h.color.x,h.color.y,h.color.z,h.color.w),s.worldSpace?this.sizeBuffer.setXYZ(t,h.size.x,h.size.y,h.size.z):h.parentMatrix?this.sizeBuffer.setXYZ(t,h.size.x,h.size.y,h.size.z):this.sizeBuffer.setXYZ(t,h.size.x*Math.abs(c.x),h.size.y*Math.abs(c.y),h.size.z*Math.abs(c.z)),this.uvTileBuffer.setX(t,h.uvTile),this.settings.renderMode===k.StretchedBillBoard&&this.velocityBuffer){let u=s.rendererEmitterSettings.speedFactor;u===0&&(u=.001);const p=s.rendererEmitterSettings.lengthFactor;let m;s.worldSpace?m=h.velocity:(m=this.vector_,h.parentMatrix?(this.rotationMat2_.setFromMatrix4(h.parentMatrix),m.copy(h.velocity).applyMatrix3(this.rotationMat2_)):m.copy(h.velocity).applyMatrix3(this.rotationMat_)),this.velocityBuffer.setXYZW(t,m.x*u,m.y*u,m.z*u,p)}}}this.geometry.instanceCount=t,t>0&&(this.offsetBuffer.clearUpdateRanges(),this.offsetBuffer.addUpdateRange(0,t*3),this.offsetBuffer.needsUpdate=!0,this.sizeBuffer.clearUpdateRanges(),this.sizeBuffer.addUpdateRange(0,t*3),this.sizeBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,t*4),this.colorBuffer.needsUpdate=!0,this.uvTileBuffer.clearUpdateRanges(),this.uvTileBuffer.addUpdateRange(0,t),this.uvTileBuffer.needsUpdate=!0,this.settings.renderMode===k.StretchedBillBoard&&this.velocityBuffer&&(this.velocityBuffer.clearUpdateRanges(),this.velocityBuffer.addUpdateRange(0,t*4),this.velocityBuffer.needsUpdate=!0),this.settings.renderMode===k.Mesh?(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,t*4),this.rotationBuffer.needsUpdate=!0):(this.settings.renderMode===k.StretchedBillBoard||this.settings.renderMode===k.HorizontalBillBoard||this.settings.renderMode===k.VerticalBillBoard||this.settings.renderMode===k.BillBoard)&&(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,t),this.rotationBuffer.needsUpdate=!0))}dispose(){this.geometry.dispose()}}var Vu=`
933
-
934
- #include <common>
935
- #include <tile_pars_fragment>
936
- #include <map_pars_fragment>
937
- #include <fog_pars_fragment>
938
- #include <logdepthbuf_pars_fragment>
939
- #include <clipping_planes_pars_fragment>
940
-
941
- uniform sampler2D alphaMap;
942
- uniform float useAlphaMap;
943
- uniform float visibility;
944
- uniform float alphaTest;
945
-
946
- varying vec4 vColor;
947
-
948
- void main() {
949
- #include <clipping_planes_fragment>
950
- #include <logdepthbuf_fragment>
951
-
952
- vec4 diffuseColor = vColor;
953
-
954
- #ifdef USE_MAP
955
- #include <tile_fragment>
956
- #ifndef USE_COLOR_AS_ALPHA
957
- #endif
958
- #endif
959
- if( useAlphaMap == 1. ) diffuseColor.a *= texture2D( alphaMap, vUv).a;
960
- if( diffuseColor.a < alphaTest ) discard;
961
- gl_FragColor = diffuseColor;
962
-
963
- #include <fog_fragment>
964
- #include <tonemapping_fragment>
965
- }`,ju=`
966
- #include <common>
967
- #include <tile_pars_vertex>
968
- #include <color_pars_vertex>
969
- #include <clipping_planes_pars_vertex>
970
- #include <logdepthbuf_pars_vertex>
971
- #include <fog_pars_vertex>
972
-
973
- attribute vec3 previous;
974
- attribute vec3 next;
975
- attribute float side;
976
- attribute float width;
977
-
978
- uniform vec2 resolution;
979
- uniform float lineWidth;
980
- uniform float sizeAttenuation;
981
-
982
- vec2 fix(vec4 i, float aspect) {
983
- vec2 res = i.xy / i.w;
984
- res.x *= aspect;
985
- return res;
986
- }
987
-
988
- void main() {
989
-
990
- #include <tile_vertex>
991
-
992
- float aspect = resolution.x / resolution.y;
993
-
994
- vColor = color;
995
-
996
- mat4 m = projectionMatrix * modelViewMatrix;
997
- vec4 finalPosition = m * vec4( position, 1.0 );
998
- vec4 prevPos = m * vec4( previous, 1.0 );
999
- vec4 nextPos = m * vec4( next, 1.0 );
1000
-
1001
- vec2 currentP = fix( finalPosition, aspect );
1002
- vec2 prevP = fix( prevPos, aspect );
1003
- vec2 nextP = fix( nextPos, aspect );
1004
-
1005
- float w = lineWidth * width;
1006
-
1007
- vec2 dir;
1008
- if( nextP == currentP ) dir = normalize( currentP - prevP );
1009
- else if( prevP == currentP ) dir = normalize( nextP - currentP );
1010
- else {
1011
- vec2 dir1 = normalize( currentP - prevP );
1012
- vec2 dir2 = normalize( nextP - currentP );
1013
- dir = normalize( dir1 + dir2 );
1014
-
1015
- vec2 perp = vec2( -dir1.y, dir1.x );
1016
- vec2 miter = vec2( -dir.y, dir.x );
1017
- //w = clamp( w / dot( miter, perp ), 0., 4., * lineWidth * width );
1018
-
1019
- }
1020
-
1021
- //vec2 normal = ( cross( vec3( dir, 0. ) vec3( 0., 0., 1. ) ) ).xy;
1022
- vec4 normal = vec4( -dir.y, dir.x, 0., 1. );
1023
- normal.xy *= .5 * w;
1024
- normal *= projectionMatrix;
1025
- if( sizeAttenuation == 0. ) {
1026
- normal.xy *= finalPosition.w;
1027
- normal.xy /= ( vec4( resolution, 0., 1. ) * projectionMatrix ).xy;
1028
- }
1029
-
1030
- finalPosition.xy += normal.xy * side;
1031
-
1032
- gl_Position = finalPosition;
1033
-
1034
- #include <logdepthbuf_vertex>
1035
- #include <clipping_planes_vertex>
1036
-
1037
- vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
1038
-
1039
- #include <fog_vertex>
1040
- }`;class Gu extends kl{constructor(t){super(t),this.vector_=new R,this.vector2_=new R,this.vector3_=new R,this.quaternion_=new Q,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new De,this.indexBuffer=new ve(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(Rt),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new ve(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(Rt),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new ve(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(Rt),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new ve(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(Rt),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new ve(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(Rt),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new ve(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(Rt),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new ve(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(Rt),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new ve(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(Rt),this.geometry.setAttribute("color",this.colorBuffer)}expandBuffers(t){for(;t>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const t={lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},resolution:{value:new zi(1,1)},sizeAttenuation:{value:1},visibility:{value:1},alphaTest:{value:0}},e={};if(e.USE_UV="",e.USE_COLOR_ALPHA="",this.settings.material.map&&(e.USE_MAP="",e.MAP_UV=Lr(this.settings.material.map.channel),t.map=new Zt(this.settings.material.map),t.mapTransform=new Zt(new fe().copy(this.settings.material.map.matrix))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(e.USE_COLOR_AS_ALPHA=""),this.settings.renderMode===k.Trail)this.material=new is({uniforms:t,defines:e,vertexShader:ju,fragmentShader:Vu,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||Gr,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha});else throw new Error("render mode unavailable")}update(){let t=0,e=0,i=0;const s=this.getVisibleSystems();for(const n of s)for(let r=0;r<n.particleNum;r++)i+=n.particles[r].previous.length*2;i>this.maxParticles&&this.expandBuffers(i);for(const n of s){n.emitter.updateMatrixWorld&&(n.emitter.updateWorldMatrix(!0,!1),n.emitter.updateMatrixWorld(!0));const r=this.quaternion_,a=this.vector2_,l=this.vector3_;n.emitter.matrixWorld.decompose(a,r,l);const c=n.particles,d=n.particleNum,h=this.settings.uTileCount,f=this.settings.vTileCount,u=1/h,p=1/f;for(let m=0;m<d;m++){const y=c[m],_=y.uvTile%f,v=Math.floor(y.uvTile/f+.001),S=y.previous.values();let x=S.next(),C=x.value,b=C;x.done||(x=S.next());let M;x.value!==void 0?M=x.value:M=b;for(let P=0;P<y.previous.length;P++,t+=2){if(this.positionBuffer.setXYZ(t,b.position.x,b.position.y,b.position.z),this.positionBuffer.setXYZ(t+1,b.position.x,b.position.y,b.position.z),n.worldSpace?(this.positionBuffer.setXYZ(t,b.position.x,b.position.y,b.position.z),this.positionBuffer.setXYZ(t+1,b.position.x,b.position.y,b.position.z)):(y.parentMatrix?this.vector_.copy(b.position).applyMatrix4(y.parentMatrix):this.vector_.copy(b.position).applyMatrix4(n.emitter.matrixWorld),this.positionBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.positionBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),n.worldSpace?(this.previousBuffer.setXYZ(t,C.position.x,C.position.y,C.position.z),this.previousBuffer.setXYZ(t+1,C.position.x,C.position.y,C.position.z)):(y.parentMatrix?this.vector_.copy(C.position).applyMatrix4(y.parentMatrix):this.vector_.copy(C.position).applyMatrix4(n.emitter.matrixWorld),this.previousBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.previousBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),n.worldSpace?(this.nextBuffer.setXYZ(t,M.position.x,M.position.y,M.position.z),this.nextBuffer.setXYZ(t+1,M.position.x,M.position.y,M.position.z)):(y.parentMatrix?this.vector_.copy(M.position).applyMatrix4(y.parentMatrix):this.vector_.copy(M.position).applyMatrix4(n.emitter.matrixWorld),this.nextBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.nextBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),this.sideBuffer.setX(t,1),this.sideBuffer.setX(t+1,-1),n.worldSpace)this.widthBuffer.setX(t,b.size),this.widthBuffer.setX(t+1,b.size);else if(y.parentMatrix)this.widthBuffer.setX(t,b.size),this.widthBuffer.setX(t+1,b.size);else{const z=(Math.abs(l.x)+Math.abs(l.y)+Math.abs(l.z))/3;this.widthBuffer.setX(t,b.size*z),this.widthBuffer.setX(t+1,b.size*z)}this.uvBuffer.setXY(t,(P/y.previous.length+_)*u,(f-v-1)*p),this.uvBuffer.setXY(t+1,(P/y.previous.length+_)*u,(f-v)*p),this.colorBuffer.setXYZW(t,b.color.x,b.color.y,b.color.z,b.color.w),this.colorBuffer.setXYZW(t+1,b.color.x,b.color.y,b.color.z,b.color.w),P+1<y.previous.length&&(this.indexBuffer.setX(e*3,t),this.indexBuffer.setX(e*3+1,t+1),this.indexBuffer.setX(e*3+2,t+2),e++,this.indexBuffer.setX(e*3,t+2),this.indexBuffer.setX(e*3+1,t+1),this.indexBuffer.setX(e*3+2,t+3),e++),C=b,b=M,x.done||(x=S.next(),x.value!==void 0&&(M=x.value))}}}this.positionBuffer.clearUpdateRanges(),this.positionBuffer.addUpdateRange(0,t*3),this.positionBuffer.needsUpdate=!0,this.previousBuffer.clearUpdateRanges(),this.previousBuffer.addUpdateRange(0,t*3),this.previousBuffer.needsUpdate=!0,this.nextBuffer.clearUpdateRanges(),this.nextBuffer.addUpdateRange(0,t*3),this.nextBuffer.needsUpdate=!0,this.sideBuffer.clearUpdateRanges(),this.sideBuffer.addUpdateRange(0,t),this.sideBuffer.needsUpdate=!0,this.widthBuffer.clearUpdateRanges(),this.widthBuffer.addUpdateRange(0,t),this.widthBuffer.needsUpdate=!0,this.uvBuffer.clearUpdateRanges(),this.uvBuffer.addUpdateRange(0,t*2),this.uvBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,t*4),this.colorBuffer.needsUpdate=!0,this.indexBuffer.clearUpdateRanges(),this.indexBuffer.addUpdateRange(0,e*3),this.indexBuffer.needsUpdate=!0,this.geometry.setDrawRange(0,e*3)}dispose(){this.geometry.dispose()}}class $r extends ii{constructor(){super(),this.batches=[],this.systemToBatchIndex=new Map,this.type="BatchedRenderer",this.depthTexture=null}static equals(t,e){return t.material.side===e.material.side&&t.material.blending===e.material.blending&&t.material.blendSrc===e.material.blendSrc&&t.material.blendDst===e.material.blendDst&&t.material.blendEquation===e.material.blendEquation&&t.material.premultipliedAlpha===e.material.premultipliedAlpha&&t.material.transparent===e.material.transparent&&t.material.depthTest===e.material.depthTest&&t.material.type===e.material.type&&t.material.alphaTest===e.material.alphaTest&&t.material.map===e.material.map&&t.renderMode===e.renderMode&&t.blendTiles===e.blendTiles&&t.softParticles===e.softParticles&&t.softFarFade===e.softFarFade&&t.softNearFade===e.softNearFade&&t.uTileCount===e.uTileCount&&t.vTileCount===e.vTileCount&&t.instancingGeometry===e.instancingGeometry&&t.renderOrder===e.renderOrder&&t.layers.mask===e.layers.mask}addSystem(t){t._renderer=this;const e=t.getRendererSettings();for(let s=0;s<this.batches.length;s++)if($r.equals(this.batches[s].settings,e)){this.batches[s].addSystem(t),this.systemToBatchIndex.set(t,s);return}let i;switch(e.renderMode){case k.Trail:i=new Gu(e);break;case k.Mesh:case k.BillBoard:case k.VerticalBillBoard:case k.HorizontalBillBoard:case k.StretchedBillBoard:i=new Uu(e);break}this.depthTexture&&i.applyDepthTexture(this.depthTexture),i.addSystem(t),this.batches.push(i),this.systemToBatchIndex.set(t,this.batches.length-1),this.add(i)}deleteSystem(t){const e=this.systemToBatchIndex.get(t);e!=null&&(this.batches[e].removeSystem(t),this.systemToBatchIndex.delete(t))}setDepthTexture(t){this.depthTexture=t;for(const e of this.batches)e.applyDepthTexture(t)}updateSystem(t){this.deleteSystem(t),this.addSystem(t)}update(t){this.systemToBatchIndex.forEach((e,i)=>{i.update(t)});for(let e=0;e<this.batches.length;e++)this.batches[e].update()}}class Kr extends Ft{constructor(){super(),this.type="QuarksPrefab",this.animationData=[],this.isPlaying=!1,this.currentTime=-1e-5,this.timeScale=1,this.duration=0,this._mixers=new Map,this._tempAnimationJSON=[],this._clock=new Nh(!0)}registerBatchedRenderer(t){this._batchedRenderer=t}getOrCreateMixer(t){if(!this._mixers.has(t)){const e=new pl(t);this._mixers.set(t,e)}return this._mixers.get(t)}addThreeAnimation(t,e,i=0,s=e.duration,n=!1){const r=this.getOrCreateMixer(t),a=r.clipAction(e);n||(a.setLoop(Hh,1),a.clampWhenFinished=!0);const l={startTime:i,duration:s,type:"three",loop:n,target:t,clip:e,mixer:r,action:a};return this.animationData.push(l),this.updateDuration(),l}addParticleSystemAnimation(t,e=0,i=0,s=!1){i<=0&&(i=t.system.duration);const n={startTime:e,duration:i,type:"ps",loop:s,target:t};return this.animationData.push(n),this.pause(),this.updateDuration(),n}removeAnimation(t){this.animationData.splice(t,1),this.updateDuration()}play(){this.isPlaying||(this.isPlaying=!0)}pause(){this.isPlaying&&(this.isPlaying=!1,this.animationData.forEach(t=>{t.target&&(t.type==="ps"&&!t.target.system.paused?t.target.system.pause():t.type==="three"&&t.action&&t.action.isRunning()&&(t.action.paused=!0))}))}stop(){this.pause(),this.currentTime=-1e-5,this.animationData.forEach(t=>{t.type==="ps"&&t.target?t.target.system.stop():t.type==="three"&&t.mixer&&t.action&&t.action.reset()})}update(t){if(!this.isPlaying)return;const e=t!==void 0?t:this._clock.getDelta();this.currentTime+=e*this.timeScale,this.currentTime>this.duration&&this.stop();const i=new Set;this.animationData.forEach(s=>{const{startTime:n,duration:r,type:a,loop:l,target:c,action:d,mixer:h}=s,f=n+r,u=this.currentTime>=n,p=this.currentTime>f,m=Math.abs(this.currentTime-n)<e;a==="three"&&d&&h?u&&!p?(m?(d.reset(),d.play()):d.paused&&(d.paused=!1,d.play()),this.currentTime-n,i.add(h)):p&&(d.paused=!0):a==="ps"&&c&&(u&&!p?m&&s.target.system.restart():p&&s.target.system.endEmit())}),i.forEach(s=>{s.update(e)})}setTime(t){const e=this.currentTime;this.currentTime=t,this.animationData.forEach(i=>{const{startTime:s,duration:n,type:r,target:a,action:l,mixer:c}=i;if(r==="three"&&l&&c){if(l.reset(),t>=s&&t<s+n){const d=t-s;l.time=d,l.play(),c.update(0),l.paused=!this.isPlaying}}else r==="ps"&&a&&(t>=s&&t<s+n?(e<s||e>=s+n)&&a.system.restart():a.system.endEmit())})}getDuration(){return this.duration}updateDuration(){let t=0;this.animationData.forEach(e=>{const i=e.startTime+e.duration;i>t&&(t=i)}),this.duration=t}resolveReferences(t){this._tempAnimationJSON.forEach(e=>{let i;if(t.traverse(s=>{s.uuid===e.targetUUID&&(i=s)}),i)if(e.type==="three"&&e.clipUUID){let s;i.animations&&(s=i.animations.find(n=>n.uuid===e.clipUUID)),s&&this.addThreeAnimation(i,s,e.startTime,e.duration,e.loop)}else e.type==="ps"&&this.addParticleSystemAnimation(i,e.startTime,e.duration,e.loop)}),this.updateDuration(),this._tempAnimationJSON=[]}toJSON(){const t=super.toJSON();return t.object.animationData=this.animationData.map(e=>({startTime:e.startTime,duration:e.duration,type:e.type,targetUUID:e.target.uuid,clipUUID:e.clip?.uuid,loop:e.loop})),t}static fromJSON(t){const e=new Kr;return t.animationData&&(e._tempAnimationJSON=t.animationData),e}}class Im extends Ch{constructor(t){super(t)}linkReference(t){const e={};t.traverse(function(i){e[i.uuid]=i}),t.traverse(function(i){if(i.type==="ParticleEmitter"){const s=i.system;s.emitterShape;for(let n=0;n<s.behaviors.length;n++)s.behaviors[n]instanceof Oi&&(s.behaviors[n].subParticleSystem=e[s.behaviors[n].subParticleSystem])}})}parse(t,e){const i=super.parse(t,e);return this.linkReference(i),i}parseObject(t,e,i,s,n){let r;function a(p){return e[p]===void 0&&console.warn("THREE.ObjectLoader: Undefined geometry",p),e[p]}function l(p){if(p!==void 0){if(Array.isArray(p)){const m=[];for(let y=0,_=p.length;y<_;y++){const v=p[y];i[v]===void 0&&console.warn("THREE.ObjectLoader: Undefined material",v),m.push(i[v])}return m}return i[p]===void 0&&console.warn("THREE.ObjectLoader: Undefined material",p),i[p]}}function c(p){return s[p]===void 0&&console.warn("THREE.ObjectLoader: Undefined texture",p),s[p]}let d,h;const f={textures:s,geometries:e,materials:i},u={};switch(t.type){case"QuarksPrefab":r=Kr.fromJSON(t);break;case"ParticleEmitter":r=Rn.fromJSON(t.ps,f,u).emitter;break;case"Scene":r=new Ln,t.background!==void 0&&(Number.isInteger(t.background)?r.background=new D(t.background):r.background=c(t.background)),t.environment!==void 0&&(r.environment=c(t.environment)),t.fog!==void 0&&(t.fog.type==="Fog"?r.fog=new Lh(t.fog.color,t.fog.near,t.fog.far):t.fog.type==="FogExp2"&&(r.fog=new Bh(t.fog.color,t.fog.density)),t.fog.name!==""&&(r.fog.name=t.fog.name)),t.backgroundBlurriness!==void 0&&(r.backgroundBlurriness=t.backgroundBlurriness),t.backgroundIntensity!==void 0&&(r.backgroundIntensity=t.backgroundIntensity),t.backgroundRotation!==void 0&&r.backgroundRotation.fromArray(t.backgroundRotation),t.environmentIntensity!==void 0&&(r.environmentIntensity=t.environmentIntensity),t.environmentRotation!==void 0&&r.environmentRotation.fromArray(t.environmentRotation);break;case"PerspectiveCamera":r=new wl(t.fov,t.aspect,t.near,t.far),t.focus!==void 0&&(r.focus=t.focus),t.zoom!==void 0&&(r.zoom=t.zoom),t.filmGauge!==void 0&&(r.filmGauge=t.filmGauge),t.filmOffset!==void 0&&(r.filmOffset=t.filmOffset),t.view!==void 0&&(r.view=Object.assign({},t.view));break;case"OrthographicCamera":r=new Si(t.left,t.right,t.top,t.bottom,t.near,t.far),t.zoom!==void 0&&(r.zoom=t.zoom),t.view!==void 0&&(r.view=Object.assign({},t.view));break;case"AmbientLight":r=new vl(t.color,t.intensity);break;case"DirectionalLight":r=new _l(t.color,t.intensity);break;case"PointLight":r=new Fh(t.color,t.intensity,t.distance,t.decay);break;case"RectAreaLight":r=new Rh(t.color,t.intensity,t.width,t.height);break;case"SpotLight":r=new Ih(t.color,t.intensity,t.distance,t.angle,t.penumbra,t.decay);break;case"HemisphereLight":r=new kh(t.color,t.groundColor,t.intensity);break;case"LightProbe":r=new Oh().fromJSON(t);break;case"SkinnedMesh":d=a(t.geometry),h=l(t.material),r=new Th(d,h),t.bindMode!==void 0&&(r.bindMode=t.bindMode),t.bindMatrix!==void 0&&r.bindMatrix.fromArray(t.bindMatrix),t.skeleton!==void 0&&(r.skeleton=t.skeleton);break;case"Mesh":d=a(t.geometry),h=l(t.material),r=new T(d,h);break;case"InstancedMesh":{d=a(t.geometry),h=l(t.material);const p=t.count,m=t.instanceMatrix,y=t.instanceColor;r=new Eh(d,h,p),r.instanceMatrix=new we(new Float32Array(m.array),16),y!==void 0&&(r.instanceColor=new we(new Float32Array(y.array),y.itemSize));break}case"BatchedMesh":d=a(t.geometry),h=l(t.material),r=new Ah(t.maxGeometryCount,t.maxVertexCount,t.maxIndexCount,h),r.geometry=d,r.perObjectFrustumCulled=t.perObjectFrustumCulled,r.sortObjects=t.sortObjects,r._drawRanges=t.drawRanges,r._reservedRanges=t.reservedRanges,r._visibility=t.visibility,r._active=t.active,r._bounds=t.bounds.map(p=>{const m=new pe;m.min.fromArray(p.boxMin),m.max.fromArray(p.boxMax);const y=new Xr;return y.radius=p.sphereRadius,y.center.fromArray(p.sphereCenter),{boxInitialized:p.boxInitialized,box:m,sphereInitialized:p.sphereInitialized,sphere:y}}),r._maxGeometryCount=t.maxGeometryCount,r._maxVertexCount=t.maxVertexCount,r._maxIndexCount=t.maxIndexCount,r._geometryInitialized=t.geometryInitialized,r._geometryCount=t.geometryCount,r._matricesTexture=c(t.matricesTexture.uuid);break;case"LOD":r=new zh;break;case"Line":r=new Qt(a(t.geometry),l(t.material));break;case"LineLoop":r=new yl(a(t.geometry),l(t.material));break;case"LineSegments":r=new Pi(a(t.geometry),l(t.material));break;case"PointCloud":case"Points":r=new gl(a(t.geometry),l(t.material));break;case"Sprite":r=new Or(l(t.material));break;case"Group":r=new Ft;break;case"Bone":r=new Ph;break;default:r=new ii}if(r.uuid=t.uuid,t.name!==void 0&&(r.name=t.name),t.matrix!==void 0?(r.matrix.fromArray(t.matrix),t.matrixAutoUpdate!==void 0&&(r.matrixAutoUpdate=t.matrixAutoUpdate),r.matrixAutoUpdate&&(r.matrix.decompose(r.position,r.quaternion,r.scale),isNaN(r.quaternion.x)&&r.quaternion.set(0,0,0,1))):(t.position!==void 0&&r.position.fromArray(t.position),t.rotation!==void 0&&r.rotation.fromArray(t.rotation),t.quaternion!==void 0&&r.quaternion.fromArray(t.quaternion),t.scale!==void 0&&r.scale.fromArray(t.scale)),t.up!==void 0&&r.up.fromArray(t.up),t.castShadow!==void 0&&(r.castShadow=t.castShadow),t.receiveShadow!==void 0&&(r.receiveShadow=t.receiveShadow),t.shadow&&(t.shadow.bias!==void 0&&(r.shadow.bias=t.shadow.bias),t.shadow.normalBias!==void 0&&(r.normalBias=t.shadow.normalBias),t.shadow.radius!==void 0&&(r.radius=t.shadow.radius),t.shadow.mapSize!==void 0&&r.mapSize.fromArray(t.shadow.mapSize),t.shadow.camera!==void 0&&(r.camera=this.parseObject(t.shadow.camera))),t.visible!==void 0&&(r.visible=t.visible),t.frustumCulled!==void 0&&(r.frustumCulled=t.frustumCulled),t.renderOrder!==void 0&&(r.renderOrder=t.renderOrder),t.userData!==void 0&&(r.userData=t.userData),t.layers!==void 0&&(r.layers.mask=t.layers),t.children!==void 0){const p=t.children;for(let m=0;m<p.length;m++)r.add(this.parseObject(p[m],e,i,s,n))}if(t.animations!==void 0){const p=t.animations;for(let m=0;m<p.length;m++){const y=p[m];r.animations.push(n[y])}}if(t.type==="LOD"){t.autoUpdate!==void 0&&(r.autoUpdate=t.autoUpdate);const p=t.levels;for(let m=0;m<p.length;m++){const y=p[m],_=r.getObjectByProperty("uuid",y.object);_!==void 0&&r.addLevel(_,y.distance)}}else t.type==="QuarksPrefab"&&r.resolveReferences(r);return r}}Ou();xu(bu);console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const pr=new D(4441855),yn=new D(16758858),_n=new D(14185983),Wu=new D(16731496),_a=new D(16777215);function fr(o){return new Qt(new De,new He({color:o,depthTest:!1,depthWrite:!1,transparent:!0,toneMapped:!1}))}function mr(o,t){return new T(o,new vt({color:t,depthTest:!1,depthWrite:!1,transparent:!0,toneMapped:!1}))}function gr(o,t){if(o.visible=t.length>1,!o.visible)return;let e=o.geometry.getAttribute("position");(!e||e.count!==t.length)&&(e=new es(t.length*3,3),o.geometry.setAttribute("position",e));for(let i=0;i<t.length;i++)e.setXYZ(i,t[i].x,t[i].y,t[i].z);e.needsUpdate=!0,o.geometry.computeBoundingSphere()}class Xu extends Ft{constructor(t){super(),this.source=t,this.name="Constraint Helper",this.renderOrder=999,Dt(this,"editorHelper",!0),Dt(this,"editorHelperType","constraints"),this.layers.set(J),this.refreshStructure()}selected=!1;hoveredControl=null;selectedObjects=new Set;visuals=[];setSelected(t){this.selected=t}setSelectedObjects(t){this.selectedObjects=t}controlMeshes(){return this.visuals.flatMap(t=>[t.targetHit,t.poleHit].filter(e=>e.visible))}presents(t){return t===this.source?!0:this.visuals.some(e=>{const i=e.mark.getSnapshot();return t===i.target||t===i.pole})}controlFor(t){for(const e of this.visuals){const i=e.mark.getSnapshot();if((t===e.target||t===e.targetHit)&&i.target)return{kind:"target",label:i.target.name||`${e.mark.config.label} target`,object:i.target,mesh:e.target};if((t===e.pole||t===e.poleHit)&&i.pole)return{kind:"pole",label:i.pole.name||`${e.mark.config.label} pole`,object:i.pole,mesh:e.pole}}return null}setHoveredControl(t){this.hoveredControl=t}update(t){this.refreshStructure();for(const e of this.visuals)this.updateVisual(e,t)}dispose(){this.clearVisuals(),this.removeFromParent()}refreshStructure(){const t=An(this.source);t.length===this.visuals.length&&t.every((i,s)=>{const n=i.getSnapshot(),r=n.chain.length>0?n.chain.length:n.constrained?1:0;return this.visuals[s]?.mark===i&&this.visuals[s]?.positions.length===r})||(this.clearVisuals(),this.visuals=t.map(i=>this.makeVisual(i)))}makeVisual(t){const e=t.getSnapshot(),i=e.chain.length>0?e.chain:e.constrained?[e.constrained]:[],s=fr(pr),n=fr(yn),r=fr(_n),a=i.map(()=>mr(new be(.035,10,7),pr)),l=mr(new qe(.085),yn),c=mr(new Vh(.075),_n),d=new vt({transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,colorWrite:!1}),h=new T(new be(.16,10,7),d),f=new T(new be(.15,10,7),d.clone());for(const u of[s,n,r,...a,l,c,h,f])u.renderOrder=this.renderOrder,u.layers.set(J),this.add(u);return{mark:t,chain:s,targetLine:n,poleLine:r,joints:a,target:l,pole:c,targetHit:h,poleHit:f,positions:i.map(()=>new w),targetPosition:new w,polePosition:new w}}updateVisual(t,e){const i=t.mark.getSnapshot(),s=i.chain.length>0?i.chain:i.constrained?[i.constrained]:[];for(let f=0;f<s.length;f++)s[f].getWorldPosition(t.positions[f]);gr(t.chain,t.positions);for(let f=0;f<t.joints.length;f++){const u=t.joints[f],p=t.positions[f];u.visible=!!p,p&&(u.position.copy(p),u.scale.setScalar(this.handleScale(e,p)))}const n=t.positions.at(-1),r=i.target?.getWorldPosition(t.targetPosition)??null,a=i.pole?.getWorldPosition(t.polePosition)??null;gr(t.targetLine,n&&r?[n,r]:[]),gr(t.poleLine,t.positions[0]&&a?[t.positions[0],a]:[]),t.target.visible=r!==null,r&&(t.target.position.copy(r),t.target.scale.setScalar(this.handleScale(e,r)*(this.hoveredControl===t.target?1.22:1))),t.targetHit.visible=r!==null,r&&(t.targetHit.position.copy(r),t.targetHit.scale.copy(t.target.scale)),t.pole.visible=a!==null,a&&(t.pole.position.copy(a),t.pole.scale.setScalar(this.handleScale(e,a)*(this.hoveredControl===t.pole?1.22:1))),t.poleHit.visible=a!==null,a&&(t.poleHit.position.copy(a),t.poleHit.scale.copy(t.pole.scale));const l=i.status==="error"||i.status==="unresolved",c=this.selected?1:.52;for(const f of[t.chain,...t.joints]){const u=f.material;u.color.copy(l?Wu:pr),u.opacity=c}const d=this.hoveredControl===t.target||i.target!==null&&this.selectedObjects.has(i.target),h=this.hoveredControl===t.pole||i.pole!==null&&this.selectedObjects.has(i.pole);t.target.material.color.copy(d?_a:yn),t.pole.material.color.copy(h?_a:_n),t.targetLine.material.color.copy(yn),t.poleLine.material.color.copy(_n),t.targetLine.material.opacity=c,t.poleLine.material.opacity=c,t.target.material.opacity=d?1:c,t.pole.material.opacity=h?1:c}handleScale(t,e){return Wt.clamp(t.position.distanceTo(e)/8,.65,4)}clearVisuals(){for(const t of[...this.children]){t.removeFromParent();const e=t;e.geometry.dispose();const i=Array.isArray(e.material)?e.material:[e.material];for(const s of i)s.dispose()}this.visuals=[],this.hoveredControl=null}}const Ju=5742335;function Il(o,t,e){return o<<16|t<<8|e}function va(o){const t=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(o.trim())?.[1];if(t){const s=t.length===3?[...t].map(n=>`${n}${n}`).join(""):t;return Number.parseInt(s.slice(0,6),16)}const e=/^rgba?\(\s*(\d+(?:\.\d+)?)\s*(?:,\s*|\s+)(\d+(?:\.\d+)?)\s*(?:,\s*|\s+)(\d+(?:\.\d+)?)/i.exec(o.trim());if(!e)return null;const i=e.slice(1,4).map(s=>Math.round(Number(s)));return i.some(s=>s<0||s>255)?null:Il(i[0],i[1],i[2])}function Fs(o){const t=va(o);if(t!==null||typeof document>"u")return t;if(typeof CSS<"u"&&!CSS.supports("color",o))return null;const e=document.createElement("canvas").getContext("2d");return e?(e.fillStyle="#010203",e.fillStyle=o,va(String(e.fillStyle))):null}function Ue(o){return typeof document>"u"?null:o?.closest(`.${To}`)??document.querySelector(`.${To}`)}function wa(o){const t=Math.round((o>>16&255)*.42),e=Math.round((o>>8&255)*.42),i=Math.round((o&255)*.42);return Il(t,e,i)}function Pt(o,t){return o&&typeof getComputedStyle<"u"?getComputedStyle(o).getPropertyValue(t).trim():""}const Rl={"--vgai-viewport-background":"--vscode-vgai-viewport-background","--vgai-viewport-grid":"--vscode-vgai-viewport-grid","--vgai-viewport-axis-x":"--vscode-vgai-viewport-axisX","--vgai-viewport-axis-y":"--vscode-vgai-viewport-axisY","--vgai-viewport-axis-z":"--vscode-vgai-viewport-axisZ","--vgai-viewport-selection":"--vscode-vgai-viewport-selection","--vgai-viewport-active":"--vscode-vgai-viewport-active","--vgai-viewport-wire":"--vscode-vgai-viewport-wire","--vgai-gizmo-x":"--vscode-vgai-gizmo-x","--vgai-gizmo-y":"--vscode-vgai-gizmo-y","--vgai-gizmo-z":"--vscode-vgai-gizmo-z","--vgai-gizmo-navigation-x":"--vscode-vgai-gizmo-navigationX","--vgai-gizmo-navigation-y":"--vscode-vgai-gizmo-navigationY","--vgai-gizmo-navigation-z":"--vscode-vgai-gizmo-navigationZ","--vgai-gizmo-hover":"--vscode-vgai-gizmo-hover","--vgai-gizmo-drag":"--vscode-vgai-gizmo-drag"};function Ls(o,t){const e=Rl[t];return(e?Pt(o,e):"")||Pt(o,t)}function ue(o){const t=Ue(o),e=Ls(t,"--vgai-viewport-selection")||Pt(t,"--vgai-accent"),i=Fs(e||_c.color.accent.default)??Ju,s=Fs(Ls(t,"--vgai-viewport-active")),n=Pt(t,"--vgai-viewport-outline-style"),r=Number.parseFloat(Pt(t,"--vgai-viewport-outline-width")),a=Pt(t,"--vgai-viewport-outline-hidden");return{visible:i,hidden:wa(i),...s===null?{}:{active:{visible:s,hidden:wa(s)}},...n===""&&a===""&&!Number.isFinite(r)?{}:{outline:{style:n==="crisp"?"crisp":"soft",width:Number.isFinite(r)&&r>0?r:null,hidden:a!=="false"}}}}function Fl(o){return Bs(o).background!==null}function Yu(o){const t=Bs(o).background;if(t===null)return!1;const e=t>>16&255,i=t>>8&255,s=t&255;return(.2126*e+.7152*i+.0722*s)/255>.5}function Bs(o){const t=Ue(o),e=i=>{const s=Ls(t,i);return s?Fs(s):null};return{background:e("--vgai-viewport-background"),grid:e("--vgai-viewport-grid"),axisX:e("--vgai-viewport-axis-x"),axisY:e("--vgai-viewport-axis-y"),axisZ:e("--vgai-viewport-axis-z"),axisLineWidth:(()=>{const i=Pt(t,"--vgai-viewport-axis-line-width"),s=i?Number.parseFloat(i):Number.NaN;return Number.isFinite(s)?s:null})(),active:e("--vgai-viewport-active")}}function xa(o){const t=Ue(o),e=n=>{const r=Ls(t,n);return r?Fs(r):null},i=n=>{const r=Pt(t,n);if(!r)return null;const a=Number.parseFloat(r);return Number.isFinite(a)?a:null},s=n=>{const r=e(`${n}-x`),a=e(`${n}-y`),l=e(`${n}-z`);return r!==null&&a!==null&&l!==null?[r,a,l]:null};return{axes:s("--vgai-gizmo"),navigation:s("--vgai-gizmo-navigation"),hover:e("--vgai-gizmo-hover"),drag:e("--vgai-gizmo-drag"),opacity:i("--vgai-viewport-gizmo-opacity"),arrowLength:i("--vgai-viewport-gizmo-arrow-length"),arrowHead:i("--vgai-viewport-gizmo-arrow-head"),ringWidth:i("--vgai-viewport-gizmo-ring-width"),navigationSize:i("--vgai-viewport-navigation-size"),navigationForm:(n=>n==="cones"||n==="triad"?n:"balls")(Pt(t,"--vgai-viewport-navigation-gizmo")),navigationCorner:Pt(t,"--vgai-viewport-navigation-corner")==="bottom-left"?"bottom-left":"top-right",highlightSaturation:i("--vgai-viewport-gizmo-highlight-saturation"),highlightValue:i("--vgai-viewport-gizmo-highlight-value")}}function ba(o){const t=Pt(Ue(o),"--vgai-viewport-gizmo-size");if(!t)return null;const e=Number.parseFloat(t);return Number.isFinite(e)&&e>0?e:null}function qu(o){const t=Ue(o),e=(s,n)=>{const r=Number.parseFloat(Pt(t,s)??"");return Number.isFinite(r)&&r>0?r:n},i=e("--vgai-viewport-grid-line-width",1);return{lineWidth:i,majorWidth:e("--vgai-viewport-grid-major-width",i),majorContrast:e("--vgai-viewport-grid-major-contrast",1)}}function Sa(o){const t=Ue(o),e=Ls(t,"--vgai-viewport-wire"),i=Number.parseFloat(Pt(t,"--vgai-viewport-wire-opacity"));return{color:e?Fs(e):null,opacity:Number.isFinite(i)?i:null}}function Ma(o){const t=Ue(o),e=Number.parseFloat(Pt(t,"--vgai-viewport-selection-box-width"));return{edges:Pt(t,"--vgai-viewport-selection-box")==="edges",frame:Pt(t,"--vgai-viewport-selection-box-frame")==="object"?"object":"world",lineWidth:Number.isFinite(e)&&e>0?e:null}}function Bn(o,t){t();const e=Ue(o);if(!e||typeof MutationObserver>"u")return()=>{};const i=new MutationObserver(t);i.observe(e,{attributes:!0,attributeFilter:["style"]});const s=Zu(e,t);return()=>{i.disconnect(),s()}}const vn=new Set;let _i=null,yr="";function Zu(o,t){const e=()=>Object.values(Rl).map(i=>Pt(o,i)).join("|");return vn.add(t),!_i&&typeof document<"u"&&document.head&&(yr=e(),_i=new MutationObserver(()=>{const i=e();if(i!==yr){yr=i;for(const s of[...vn])s()}}),_i.observe(document.head,{childList:!0,subtree:!0,characterData:!0})),()=>{vn.delete(t),vn.size===0&&_i&&(_i.disconnect(),_i=null)}}const Qu=new D(4892927),$u=new D(7718143),Ku=new D(16758858),tp=new D(16777215);class ep extends Ft{constructor(t){super(),this.source=t,this.name="Reflection Probe Helper",this.matrixAutoUpdate=!1,this.renderOrder=998,Dt(this,"editorHelper",!0),Dt(this,"editorHelperType","reflection-probes"),this.layers.set(J),this.refresh(!0)}signature="";selected=!1;setSelected(t){this.selected!==t&&(this.selected=t,this.refresh(!0))}update(){this.refresh(!1),this.source.updateWorldMatrix(!0,!1),this.matrix.copy(this.source.matrixWorld),this.matrixWorldNeedsUpdate=!0}dispose(){this.clearVisuals(),this.removeFromParent()}refresh(t){const e=ts(this.source);if(!e)return;const i=e.config,s=JSON.stringify(i);if(!t&&s===this.signature)return;this.signature=s,this.clearVisuals();const n=this.selected?$u:Qu,r=this.selected?1:.62,a=Math.max(0,i.blendDistance);if(i.shape==="sphere"){const c=Math.max(.01,i.radius);this.addWire(new be(c,24,16),n,r),a>0&&c-a>.01&&this.addWire(new be(c-a,20,12),n,this.selected?.55:.28)}else{const[c,d,h]=i.size.map(u=>Math.max(.01,u));this.addWire(new ft(c,d,h),n,r);const f=[c-a*2,d-a*2,h-a*2];a>0&&f.every(u=>u>.01)&&this.addWire(new ft(f[0],f[1],f[2]),n,this.selected?.55:.28)}if(i.parallaxProjection){const[c,d,h]=i.parallaxSize.map(u=>Math.max(.01,u));this.addWire(new ft(c,d,h),Ku,this.selected?.9:.45).position.fromArray(i.parallaxOffset)}this.addWire(new qe(this.selected?.16:.11),tp,this.selected?1:.72).position.fromArray(i.captureOffset),this.traverse(c=>c.layers.set(J))}addWire(t,e,i){const s=new Jr(t);t.dispose();const n=new He({color:e,depthTest:!1,transparent:!0,opacity:i,toneMapped:!1}),r=new Pi(s,n);return r.renderOrder=this.renderOrder,this.add(r),r}clearVisuals(){for(const t of[...this.children]){t.removeFromParent();const e=t;e.geometry?.dispose();const i=Array.isArray(e.material)?e.material:[e.material];for(const s of i)s?.dispose()}}}const ip={maxOutlierFraction:.1,minGapFraction:.2,minSampleSize:8,maxPasses:8},sp=10,np=.01,rp=["x","y","z"];function Ca(o,t){const e=new pe;for(const i of t)e.union(o[i]);return e}function op(o,t,e){let i=null;for(const s of rp)for(const n of["min","max"]){const r=[];for(const l of t)r.push({i:l,v:o[l][n][s]});r.sort((l,c)=>n==="min"?l.v-c.v:c.v-l.v);const a=Math.min(e,r.length-1);for(let l=0;l<a;l++){const c=Math.abs(r[l+1].v-r[l].v);i&&c<=i.gap||(i={gap:c,discard:r.slice(0,l+1).map(d=>d.i)})}}return i}function Pa(o,t={}){const e={...ip,...t},i=o.filter(d=>!d.isEmpty()),s=i.map((d,h)=>h),n=Ca(i,s);if(i.length<e.minSampleSize)return n;let r=Math.floor(i.length*e.maxOutlierFraction);if(r<1)return n;const a=new Set(s);let l=n;const c=new w;for(let d=0;d<e.maxPasses&&r>0;d++){const h=l.getSize(c).length();if(!(h>0))break;const f=op(i,a,r);if(!f||f.gap<=e.minGapFraction*h)break;for(const u of f.discard)a.delete(u);r-=f.discard.length,l=Ca(i,a)}return l.isEmpty()?n:l}function ap(o,t){const e=o.getWorldDirection(new w),i=new w().setFromMatrixPosition(o.matrixWorld);if(!Number.isFinite(i.lengthSq())||e.lengthSq()===0)return null;if(t.isEmpty())return{position:i,target:i.clone().addScaledVector(e,sp)};const s=t.getBoundingSphere(new Xr),n=s.center.clone().sub(i).dot(e);return n>s.radius*np?{position:i,target:i.clone().addScaledVector(e,n)}:null}const lp=[[0,0],[-.6,.6],[.6,.6],[-.6,-.6],[.6,-.6],[0,.6],[0,-.6],[-.6,0],[.6,0]],cp=.02,za=new $t,Aa=new Ht;function hp(o){for(let t=o;t;t=t.parent)if(!t.visible)return!1;return!0}function dp(o,t,e){if(!(e>0)||t.length===0)return!0;const i=e*cp;for(const[s,n]of lp){Aa.set(s,n),za.setFromCamera(Aa,o);const a=za.intersectObjects(t,!0).find(l=>hp(l.object));if(!a||a.distance>i)return!0}return!1}const to=new WeakMap,Ll=new be(1,12,8);function ki(o){return new w(o[0],o[1],o[2])}function Vs(o){const t={color:o.color,transparent:!0,opacity:o.opacity??.68,depthTest:!1};return o.dashed?new xl({...t,dashSize:.18,gapSize:.12}):new He(t)}function Kt(o,t,e,i=!1){const s=i&&t.length>0?[...t,t[0]]:[...t],n=new Qt(new De().setFromPoints(s),e);n.renderOrder=997,n.layers.set(J),e instanceof xl&&n.computeLineDistances(),o.add(n)}function Sn(o,t,e,i,s=64){const n=[];for(let r=0;r<s;r++){const a=r/s*Math.PI*2;n.push(o.clone().addScaledVector(e,Math.cos(a)*t).addScaledVector(i,Math.sin(a)*t))}return n}function up(o){const t=new Ft,e=ki(o.center),i=Vs(o);return Kt(t,Sn(e,o.radius,new w(1,0,0),new w(0,1,0)),i,!0),Kt(t,Sn(e,o.radius,new w(1,0,0),new w(0,0,1)),i,!0),Kt(t,Sn(e,o.radius,new w(0,1,0),new w(0,0,1)),i,!0),t}function pp(o){const t=new Ft;return Kt(t,o.points.map(ki),Vs(o)),t}function fp(o){const t=new Ft,e=ki(o.origin),i=ki(o.direction).normalize(),s=Math.abs(i.y)<.9?new w(0,1,0):new w(1,0,0),n=new w().crossVectors(s,i).normalize(),r=new w().crossVectors(i,n).normalize(),a=Wt.degToRad(Math.max(0,Math.min(360,o.angle))/2),l=Vs(o),c=[];for(let d=0;d<64;d++){const h=d/64*Math.PI*2,f=n.clone().multiplyScalar(Math.cos(h)).addScaledVector(r,Math.sin(h));c.push(e.clone().addScaledVector(i,Math.cos(a)*o.length).addScaledVector(f,Math.sin(a)*o.length))}Kt(t,c,l,!0);for(const d of[0,16,32,48])Kt(t,[e,c[d]],l);return t}function mp(o,t,e){return o.applyQuaternion(new bt(...e)).add(new w(...t))}function gp(o){const t=new Ft,e=Vs(o),[i,s,n]=o.halfExtents,r=[[-i,-s,-n],[i,-s,-n],[i,s,-n],[-i,s,-n],[-i,-s,n],[i,-s,n],[i,s,n],[-i,s,n]].map(([a,l,c])=>mp(new w(a,l,c),o.center,o.rotation));for(const[a,l]of[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]])Kt(t,[r[a],r[l]],e);return t}function yp(o){const t=new Ft,e=Vs(o),i=new bt(...o.rotation),s=ki(o.center),n=a=>a.applyQuaternion(i).add(s),r=(a,l,c)=>Sn(new w(0,a,0),o.radius,l,c).map(n);Kt(t,r(o.halfHeight,new w(1,0,0),new w(0,0,1)),e,!0),Kt(t,r(-o.halfHeight,new w(1,0,0),new w(0,0,1)),e,!0);for(const[a,l]of[[o.radius,0],[-o.radius,0],[0,o.radius],[0,-o.radius]])Kt(t,[n(new w(a,-o.halfHeight,l)),n(new w(a,o.halfHeight,l))],e);for(const a of["x","z"]){const l=[];for(let c=0;c<=32;c++){const d=c/32*Math.PI,h=new w(0,o.halfHeight+Math.sin(d)*o.radius,0);h[a]=Math.cos(d)*o.radius,l.push(n(h))}for(let c=0;c<=32;c++){const d=Math.PI+c/32*Math.PI,h=new w(0,-o.halfHeight+Math.sin(d)*o.radius,0);h[a]=Math.cos(d)*o.radius,l.push(n(h))}Kt(t,l,e)}return t}function _p(o){const t=o.kind==="line"?pp(o):o.kind==="sphere"?up(o):o.kind==="cone"?fp(o):o.kind==="box"?gp(o):yp(o);return t.layers.set(J),t.traverse(e=>e.layers.set(J)),t}function vp(o,t){const e=new vt({color:t.color,depthTest:!1,transparent:!0,opacity:t.writable?.92:.35}),i=new T(Ll,e);return Object.defineProperty(i,"isSpatialHandleMesh",{value:!0}),i.position.copy(ki(t.position)),i.renderOrder=998,i.layers.set(J),to.set(i,{nodeId:o,handle:t}),i}function wp(o,t){const e=[],i=[];for(const s of t){for(const n of s.guides)e.push(_p(n));for(const n of s.handles){const r=vp(o,n);e.push(r),i.push(r)}}return{roots:e,handles:i}}function Ea(o){return to.get(o)??null}function _r(o,t){const e=to.get(o);o.material.color.set(t&&e?.handle.writable?"#ffffff":e?.handle.color??"#ffffff")}function Ta(o,t){const e=o.position.distanceTo(t.position);o.scale.setScalar(Math.max(.025,e*.012))}function xp(o,t,e){const i=o,s=i.geometry;s&&s!==Ll&&!t.has(s)&&(s.dispose(),t.add(s));const n=Array.isArray(i.material)?i.material:i.material?[i.material]:[];for(const r of n)e.has(r)||(r.dispose(),e.add(r))}function Oa(o){const t=new Set,e=new Set;for(const i of o)i.removeFromParent(),i.traverse(s=>xp(s,t,e))}function ti(o,t,e,i=1.15){if(o.isEmpty())return 3;const s=e.clone().normalize(),n=Math.abs(s.dot(t.up))>.999?new w(0,0,1):t.up,r=new w().crossVectors(n,s).normalize(),a=new w().crossVectors(s,r).normalize(),l=o.getCenter(new w);let c=0,d=0,h=0;for(const m of[o.min.x,o.max.x])for(const y of[o.min.y,o.max.y])for(const _ of[o.min.z,o.max.z]){const v=new w(m,y,_).sub(l);h=Math.max(h,Math.abs(v.dot(r))),d=Math.max(d,Math.abs(v.dot(a))),c=Math.max(c,Math.abs(v.dot(s)))}const f=Wt.degToRad(t.fov*.5),u=Math.atan(Math.tan(f)*Math.max(t.aspect,.01)),p=Math.max(d/Math.tan(f),h/Math.tan(u));return Math.max(p*i+c,t.near*4,.01)}const bp=3,Sp=.05,Mp=.03,Cp=.6,Pp=.15,zp=.08,Ap=3,Ep=.45,Bl=.001,Tp=24,Op=6,kp=[[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]];function Ip(o){const t=Wt.clamp(o*Pp,zp,Ap);return Math.max(Math.min(t,o*Ep),Bl)}function vr(o){return Wt.clamp(o*Sp,Mp,Cp)}function Rp(o,t,e=!1){const{min:i,max:s}=o,n=d=>e?Math.max(d/2,Bl):Ip(d),r=n(s.x-i.x),a=n(s.y-i.y),l=n(s.z-i.z);let c=0;for(const[d,h,f]of kp){const u=d===0?i.x:s.x,p=h===0?i.y:s.y,m=f===0?i.z:s.z,y=d===0?r:-r,_=h===0?a:-a,v=f===0?l:-l;t[c++]=u,t[c++]=p,t[c++]=m,t[c++]=u+y,t[c++]=p,t[c++]=m,t[c++]=u,t[c++]=p,t[c++]=m,t[c++]=u,t[c++]=p+_,t[c++]=m,t[c++]=u,t[c++]=p,t[c++]=m,t[c++]=u,t[c++]=p,t[c++]=m+v}}class wr extends Cn{entityObject;_fixedSize;_edges;_objectFrame;_toObject=new Ci;_point=new w;_axisX=new w;_axisY=new w;_axisZ=new w;_scale=new w;_positions=new Float32Array(Tp*Op);_box=new pe;_worldPos=new w;_fixedExtent=new w;_standoff=new w;_lastRootMatrix=new Float32Array(16);_requiresContinuousBounds;constructor(t,e){const i=new Pn,s=new zn({color:e.color,linewidth:e.lineWidth??bp,worldUnits:!1,alphaToCoverage:!0,toneMapped:!1,depthTest:!1,depthWrite:!1});super(i,s),this.entityObject=t,this._fixedSize=e.fixedSize,this._edges=e.edges===!0,this._objectFrame=e.frame==="object";let n=!1;t.traverse(r=>{const a=r;(r.isSkinnedMesh||Array.isArray(a.morphTargetInfluences)&&a.morphTargetInfluences.length>0||ul(r)!==null)&&(n=!0)}),this._requiresContinuousBounds=n,this.renderOrder=1,this.frustumCulled=!1,i.setPositions(this._positions),this.update()}setColor(t){this.material.color.setHex(t)}updateIfNeeded(){this.entityObject.updateWorldMatrix(!0,!1);const t=this.entityObject.matrixWorld.elements;let e=!1;for(let i=0;i<t.length;i++)if(t[i]!==this._lastRootMatrix[i]){e=!0;break}(e||this._requiresContinuousBounds)&&this.update()}update(){this.entityObject.updateWorldMatrix(!0,!1);const t=this._objectFrame&&this._fixedSize===void 0&&Math.abs(this.entityObject.matrixWorld.determinant())>1e-30;this.entityObject.matrixWorld.extractBasis(this._axisX,this._axisY,this._axisZ);const e=t?this._scale.set(this._axisX.length(),this._axisY.length(),this._axisZ.length()):this._scale.set(1,1,1);if(this._fixedSize!==void 0)this.entityObject.getWorldPosition(this._worldPos),this._fixedExtent.setScalar(this._fixedSize),this._box.setFromCenterAndSize(this._worldPos,this._fixedExtent);else if(t?(this._toObject.copy(this.entityObject.matrixWorld).invert(),vc(this.entityObject,this._toObject,this._box)):$e(this.entityObject,this._box),this._box.isEmpty())return;if(this._box.getSize(this._standoff).multiply(e),this._standoff.set(vr(this._standoff.x),vr(this._standoff.y),vr(this._standoff.z)).divide(e),this._box.expandByVector(this._standoff),Rp(this._box,this._positions,this._edges),t){const s=this.entityObject.matrixWorld;for(let n=0;n<this._positions.length;n+=3)this._point.set(this._positions[n],this._positions[n+1],this._positions[n+2]).applyMatrix4(s),this._positions[n]=this._point.x,this._positions[n+1]=this._point.y,this._positions[n+2]=this._point.z}const i=this.geometry.getAttribute("instanceStart");i&&(i.data.needsUpdate=!0),this._lastRootMatrix.set(this.entityObject.matrixWorld.elements)}dispose(){this.geometry.dispose(),this.material.dispose()}}function Fp({BlendFunction:o,KernelSize:t,OutlineEffect:e},i,s,n){const r=new e(i,s,{blendFunction:o.ALPHA,visibleEdgeColor:n.visible,hiddenEdgeColor:n.hidden,edgeStrength:5,pulseSpeed:0,blur:!0,kernelSize:t.MEDIUM,resolutionScale:.5,xRay:!0});r.selectionLayer=zr,s.layers.disable(zr);const a=r.getFragmentShader(),l="vec3 color=edge.x*visibleEdgeColor+edge.y*hiddenEdgeColor;";a.includes(l)&&(r.setFragmentShader(a.replace("uniform float edgeStrength;","uniform float edgeStrength;uniform float vgaiCrisp;").replace(l,`${l}if(vgaiCrisp>0.5){float vgaiSum=edge.x+edge.y;if(vgaiSum>0.0)color/=vgaiSum;edge=min(edge,vec2(1.0));}`)),r.uniforms.set("vgaiCrisp",{value:0}));const c=r.update.bind(r);return r.update=(d,h,f)=>{const u=r.camera,p=u.layers.isEnabled(J);u.layers.disable(J);try{c(d,h,f)}finally{p&&u.layers.enable(J)}},Ii.set(r,{colors:n,roots:0}),Nn(r),r}const Br=new WeakMap;function Lp(o,t,e,i,s){const n=Br.get(t)?.pop();return n?(n.mainScene=e,n.mainCamera=i,i.layers.disable(zr),Ii.set(n,{colors:s,roots:0}),Nn(n),n):Fp(o,e,i,s)}function Bp(o,t,e){t.selection.clear(),e?.setEffects([]);const i=Br.get(o)??[];i.includes(t)||i.push(t),Br.set(o,i)}const Ii=new WeakMap;function Nn(o){const t=Ii.get(o);if(!t)return;const e=t.roots===1&&t.colors.active?t.colors.active:t.colors;o.visibleEdgeColor.setHex(e.visible),o.hiddenEdgeColor.setHex(e.hidden);const i=t.colors.outline,s=i?.style==="crisp",n=i?.width??2;o.resolution.scale=s?1:.5,o.blurPass.enabled=!0,o.blurPass.kernelSize=s?n<=2?0:n<=4?1:n<=6?2:3:2,o.edgeStrength=s?8:5;const r=o.uniforms.get("vgaiCrisp");r&&(r.value=s?1:0),o.xRay=i?.hidden??!0}function Np(o,t){Ii.set(o,{colors:t,roots:Ii.get(o)?.roots??0}),Nn(o)}function Hp(o){return o.isBone?!1:o.isMesh||o.isLine||o.isPoints||o.isSprite}function Nl(o){const t=[],e=new Set;for(const i of o)i.isBone||i.traverse(s=>{e.has(s)||he(s)||!Hp(s)||(e.add(s),t.push(s))});return t}function ka(o,t){const e=[...t],i=e.filter(r=>!r.isBone).length,s=Ii.get(o);s&&s.roots!==i&&(s.roots=i,Nn(o));const n=Nl(e);o.selection.size===n.length&&n.every(r=>o.selection.has(r))||o.selection.set(n)}function Ia(o,t){const e=new D(o);if(!t||t.toneMapping===jh)return e;const i=t.toneMappingExposure||1;if(t.toneMapping===Gh)return e.multiplyScalar(1/i);if(t.toneMapping===Wh)return Dp(e,i);if(t.toneMapping===Xh)return Up(e,i);if(t.toneMapping!==bl)return e;const s=[[.59719,.35458,.04823],[.076,.90834,.01566],[.0284,.13383,.83777]],n=[[1.60475,-.53108,-.07367],[-.10208,1.10813,-.00605],[-.00327,-.07276,1.07602]],r=h=>(h*(h+.0245786)-90537e-9)/(h*(.983729*h+.432951)+.238081),a=h=>{let f=0,u=64;for(let p=0;p<60;p++){const m=(f+u)/2;r(m)<h?f=m:u=m}return(f+u)/2},c=bi(Fn(n),[e.r,e.g,e.b]).map(h=>h<=0?0:a(Math.min(h,.999))),d=bi(Fn(s),c).map(h=>Math.max(0,h)*(.6/i));return new D().setRGB(d[0],d[1],d[2],Yr)}function Dp(o,t){const e=[[.6274,.3293,.0433],[.0691,.9195,.0113],[.0164,.088,.8956]],i=[[1.6605,-.5876,-.0728],[-.1246,1.1329,-.0083],[-.0182,-.1006,1.1187]],s=[[.856627153315983,.0951212405381588,.0482516061458583],[.137318972929847,.761241990602591,.101439036467562],[.11189821299995,.0767994186031903,.811302368396859]],n=[[1.1271005818144368,-.11060664309660323,-.016493938717834573],[-.1413297634984383,1.157823702216272,-.016493938717834257],[-.14132976349843826,-.11060664309660294,1.2519364065950405]],r=-12.47393,a=4.026069,l=p=>{const m=p*p,y=m*m;return 15.5*y*m-40.14*y*p+31.96*y-6.868*m*p+.4298*m+.1191*p-.00232},c=p=>{let m=0,y=1;for(let _=0;_<60;_++){const v=(m+y)/2;l(v)<p?m=v:y=v}return(m+y)/2},d=bi(e,[o.r,o.g,o.b]),f=bi(Fn(n),d.map(p=>Math.max(0,p)**(1/2.2))).map(p=>2**(c(p)*(a-r)+r)),u=bi(i,bi(Fn(s),f)).map(p=>Math.max(0,p)/t);return new D().setRGB(u[0],u[1],u[2],Yr)}function bi(o,t){return[o[0][0]*t[0]+o[0][1]*t[1]+o[0][2]*t[2],o[1][0]*t[0]+o[1][1]*t[1]+o[1][2]*t[2],o[2][0]*t[0]+o[2][1]*t[1]+o[2][2]*t[2]]}function Fn(o){const[[t,e,i],[s,n,r],[a,l,c]]=o,d=n*c-r*l,h=-(s*c-r*a),f=s*l-n*a,u=t*d+e*h+i*f;return[[d/u,-(e*c-i*l)/u,(e*r-i*n)/u],[h/u,(t*c-i*a)/u,-(t*r-i*s)/u],[f/u,-(t*l-e*a)/u,(t*n-e*s)/u]]}function Up(o,t){const e=r=>(r*(.88*r+.06)+.002)/(r*(.88*r+.6)+.06)-.03333333333333333,i=e(1),s=r=>e(r)/i,n=r=>{if(r<=0)return 0;let a=0,l=1;for(let c=0;c<60;c++){const d=(a+l)/2;s(d)<r?a=d:l=d}return(a+l)/2};return new D().setRGB(n(Math.min(o.r,.999))/t,n(Math.min(o.g,.999))/t,n(Math.min(o.b,.999))/t,Yr)}const Vp=new D(5231045),jp=new D(10481896),Ra=64,Gp=.6;class Wp extends Ft{constructor(t){super(),this.source=t,this.name="Trigger Volume Helper",this.matrixAutoUpdate=!1,this.renderOrder=998,Dt(this,"editorHelper",!0),Dt(this,"editorHelperType","trigger-volumes"),this.layers.set(J),this.refresh(!0)}signature="";selected=!1;setSelected(t){this.selected!==t&&(this.selected=t,this.refresh(!0))}update(){this.refresh(!1),this.source.updateWorldMatrix(!0,!1),this.matrix.copy(this.source.matrixWorld),this.matrixWorldNeedsUpdate=!0}dispose(){this.clearVisuals(),this.removeFromParent()}refresh(t){const e=Ir(this.source);if(!e)return;const i=e.radius,s=String(i);if(!t&&s===this.signature)return;this.signature=s,this.clearVisuals();const n=this.selected?jp:Vp,r=this.selected?1:.62,a=[];for(let u=0;u<Ra;u+=1){const p=u/Ra*Math.PI*2;a.push(Math.cos(p)*i,0,Math.sin(p)*i)}const l=new De;l.setAttribute("position",new es(a,3));const c=new yl(l,this.lineMaterial(n,r));c.renderOrder=this.renderOrder,this.add(c);const d=[];for(const[u,p]of[[i,0],[-i,0],[0,i],[0,-i]])d.push(u,0,p,u,Gp,p);const h=new De;h.setAttribute("position",new es(d,3));const f=new Pi(h,this.lineMaterial(n,r));f.renderOrder=this.renderOrder,this.add(f),this.traverse(u=>u.layers.set(J))}lineMaterial(t,e){return new He({color:t,depthTest:!1,transparent:!0,opacity:e,toneMapped:!1})}clearVisuals(){for(const t of[...this.children]){t.removeFromParent();const e=t;e.geometry?.dispose();const i=Array.isArray(e.material)?e.material:[e.material];for(const s of i)s?.dispose()}}}function Xp(o){const t=new Set(o.values()),e=[];for(const i of t){let s=i.parent,n=!1;for(;s!==null;){if(t.has(s)){n=!0;break}s=s.parent}n||e.push(i)}return e}function Jp(o,t){const e=new Set;for(const i of t){const s=o.get(i);s&&e.add(s)}return[...e].filter(i=>{for(let s=i.parent;s!==null;s=s.parent)if(e.has(s))return!1;return!0})}const wn=.5,Yp=1e3,qp=new w(0,1,0),Zp=new w(0,0,1),xr=new Xr,Qp=new w,Fa=new w,br=new bt,La=new w,$p=1e-8,Kp=[new w(1,0,0),new w(-1,0,0),new w(0,1,0),new w(0,-1,0),new w(0,0,1),new w(0,0,-1)],tf=[[.96,.2,.32],[.53,.84,.01],[.16,.55,.96]],Ba=[[0,1],[1,1],[2,1]],ef=[[0,1],[2,1],[1,-1]],sf=[[0,1],[2,1],[1,1]],Na=["X","Y","Z"],nf=62.6;function Ha(o){const t=Number.isFinite(o)&&o>.01?o:1,e=Wt.degToRad(nf/2),i=t>=1?Math.atan(Math.tan(e)/t):e;return Wt.radToDeg(i*2)}function rf(o){const t=Math.max(o.r,o.g,o.b),e=Math.min(o.r,o.g,o.b),i=t-e;let s=0;return i>0&&(t===o.r?s=((o.g-o.b)/i+6)%6:t===o.g?s=(o.b-o.r)/i+2:s=(o.r-o.g)/i+4,s/=6),{h:s,s:t===0?0:i/t,v:t}}function of(o,t,e,i){const s=Math.floor(o*6),n=o*6-s,r=e*(1-t),a=e*(1-n*t),l=e*(1-(1-n)*t),[c,d,h]=[[e,l,r],[a,e,r],[r,e,l],[r,a,e],[l,r,e],[e,r,a]][(s%6+6)%6];return i.setRGB(c,d,h)}const Da=[new D(16070225),new D(7316507),new D(3048419)],af=.356,lf=7.5/17.5;function cf(o,t){const i=document.createElement("canvas");i.width=32,i.height=32;const s=i.getContext("2d");s&&(s.fillStyle=`#${o.getHexString()}`,s.font=`bold ${Math.round(32*.8)}px system-ui, -apple-system, sans-serif`,s.textAlign="center",s.textBaseline="middle",s.fillText(t,32/2,32/2+1));const n=new jr(i);return n.generateMipmaps=!1,n.minFilter=Mn,n.colorSpace=Hs,n}function hf(o,t){const i=document.createElement("canvas");i.width=32,i.height=32;const s=i.getContext("2d");if(s){const r=`#${o.getHexString()}`,a=32/2-1;if(t===null){const l=Hr/Nr*32;s.beginPath(),s.arc(32/2,32/2,a,0,Math.PI*2),s.fillStyle=r,s.globalAlpha=.35,s.fill(),s.globalAlpha=1,s.beginPath(),s.arc(32/2,32/2,a-l/2,0,Math.PI*2),s.lineWidth=l,s.strokeStyle=r,s.stroke()}else{s.beginPath(),s.arc(32/2,32/2,a,0,Math.PI*2),s.fillStyle=r,s.fill();const l=o.clone().multiplyScalar(af);s.fillStyle=`#${l.getHexString()}`;const c=lf*(2*a);s.font=`bold ${Math.round(c/.72)}px system-ui, -apple-system, sans-serif`,s.textAlign="center",s.textBaseline="middle",s.fillText(t,32/2,32/2+2)}}const n=new jr(i);return n.colorSpace=Hs,n.generateMipmaps=!1,n.minFilter=Mn,n}const df=new w(.8187,.4458,.3617),Qe=90,uf=32,Nr=15,pf=2.75,Hr=2,ff=74.5,Hl=73.5,mf=8.5+ff/2-Qe/2,Dl=38+Hl/2-Qe/2,gf=Dl+Qe/2+Hl/2+16-14.5,Ul=`
1041
- float vgaiGrazingFade(vec3 worldPosition, vec3 eye, vec3 planeNormal, float amount) {
1042
- vec3 toEye = eye - worldPosition;
1043
- float toEyeLength = max(length(toEye), 1e-6);
1044
- float graze = 1.0 - abs(dot(toEye / toEyeLength, planeNormal));
1045
- graze *= graze;
1046
- return mix(1.0, 1.0 - graze * graze, amount);
1047
- }
1048
- `,Vl=200,Dr=2,Ur=Vl*2/Dr;function Ua(o){const t=[];for(let e=0;e<Ur;e++){const i=-Vl+e*Dr,s=i+Dr;o===0?t.push(i,.001,0,s,.001,0):o===2?t.push(0,.001,i,0,.001,s):t.push(0,i,0,0,s,0)}return t}function yf(o,t){o.onBeforeCompile=e=>{e.uniforms.uGrazingFade=t,e.vertexShader=e.vertexShader.replace("void main() {",`varying vec3 vAxisWorld;
1049
- void main() {`).replace("vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );",`vAxisWorld = ( modelMatrix * vec4( position.y < 0.5 ? instanceStart : instanceEnd, 1.0 ) ).xyz;
1050
- vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );`),e.fragmentShader=e.fragmentShader.replace("void main() {",`varying vec3 vAxisWorld;
1051
- uniform float uGrazingFade;
1052
- ${Ul}
1053
- void main() {`).replace("gl_FragColor = vec4( diffuseColor.rgb, alpha );","gl_FragColor = vec4( diffuseColor.rgb, alpha * vgaiGrazingFade( vAxisWorld, cameraPosition, vec3( 0.0, 1.0, 0.0 ), uGrazingFade ) );")},o.customProgramCacheKey=()=>"vgai-axis-grazing-fade"}function _f(o){const t=new Wr(o,o);t.rotateX(-Math.PI/2);const e=new is({uniforms:{uColor:{value:new D(10066329)},uMajorColor:{value:new D(10066329)},uOpacity:{value:1},uLineWidth:{value:1},uMajorWidth:{value:1},uMajorEvery:{value:10},uFadeStart:{value:o/2*.55},uFadeEnd:{value:o/2},uGrazingFade:{value:0}},vertexShader:`
1054
- varying vec3 vWorld;
1055
- void main() {
1056
- vWorld = (modelMatrix * vec4(position, 1.0)).xyz;
1057
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
1058
- }
1059
- `,fragmentShader:`
1060
- uniform vec3 uColor;
1061
- uniform vec3 uMajorColor;
1062
- uniform float uOpacity;
1063
- uniform float uLineWidth;
1064
- uniform float uMajorWidth;
1065
- uniform float uMajorEvery;
1066
- uniform float uFadeStart;
1067
- uniform float uFadeEnd;
1068
- uniform float uGrazingFade;
1069
- varying vec3 vWorld;
1070
- ${Ul}
1071
- // Coverage of a line WIDTH device pixels across, with a one-pixel
1072
- // anti-aliased edge — so its core is FULL, the way Blender's is. The
1073
- // earlier form (1 - distance/width) was a triangle with no plateau:
1074
- // whether a line reached its own colour depended on where the nearest
1075
- // fragment centre happened to fall, and the measured peak wandered
1076
- // between 0.67 and 1 of it.
1077
- float gridLine(vec2 coord, float width) {
1078
- vec2 d = max(fwidth(coord), vec2(1e-6));
1079
- vec2 dist = abs(fract(coord - 0.5) - 0.5) / d;
1080
- vec2 cov = clamp(width * 0.5 - dist + 0.5, 0.0, 1.0);
1081
- return max(cov.x, cov.y);
1082
- }
1083
- void main() {
1084
- vec2 p = vWorld.xz;
1085
- vec2 pixelsPerMetre = 1.0 / max(fwidth(p), vec2(1e-6));
1086
- float minorVisible = smoothstep(4.0, 14.0, min(pixelsPerMetre.x, pixelsPerMetre.y));
1087
- // Both levels reach FULL strength in their own colour, as Blender's
1088
- // do: the 1 m line is measured at exactly the palette's grid colour
1089
- // and the 10 m line brighter than it (see uMajorColor). The minor
1090
- // level's only attenuation is its own drop-out as cells shrink.
1091
- float minor = gridLine(p, uLineWidth) * minorVisible;
1092
- // The 10 m level is WIDER as well as brighter, which is what lets it
1093
- // reach full coverage — and so its full colour. Measured across one
1094
- // scanline of modeling-object-none.png at device resolution: the 1 m
1095
- // line is 4 px at half rise and plateaus at 83, the 10 m line is 6 px
1096
- // and plateaus at 101. At one shared width ours drew a 10 m line that
1097
- // never exceeded 0.75 coverage and so measured 91, not 102.
1098
- float major = gridLine(p / uMajorEvery, uMajorWidth);
1099
- float line = max(minor, major);
1100
- float fade = 1.0 - smoothstep(uFadeStart, uFadeEnd, length(p));
1101
- // The floor's DEPTH, beside the band that ends its finite extent:
1102
- // Blender's own grazing-angle profile, transcribed from its frames
1103
- // (see GRAZING_FADE_GLSL above). Without it this lattice reads the
1104
- // same ink at the front of the frame and at the horizon.
1105
- fade *= vgaiGrazingFade(vWorld, cameraPosition, vec3(0.0, 1.0, 0.0), uGrazingFade);
1106
- float alpha = line * fade * uOpacity;
1107
- if (alpha <= 0.002) discard;
1108
- // WHICH level a fragment belongs to is the major's SHARE of the
1109
- // coverage being drawn, never a comparison of the two and never the
1110
- // major's raw coverage. Every 10 m line is also a 1 m line, so there
1111
- // the two are equal: a step() between them compares values equal to
1112
- // within rounding and flips per fragment (photographed with the major
1113
- // forced white: the 10 m lines came out DOTTED), and mixing by the raw
1114
- // coverage dilutes the colour by the line's own anti-aliasing (the
1115
- // same lines then measured 91 where Blender's is 102). As a share it
1116
- // is exactly 1 wherever the major draws — core and skirt alike, and in
1117
- // the far field where the minor has dropped out — and 0 on a 1 m line.
1118
- float majorShare = clamp(major / max(line, 1e-6), 0.0, 1.0);
1119
- gl_FragColor = vec4(mix(uColor, uMajorColor, majorShare), alpha);
1120
- #include <colorspace_fragment>
1121
- }
1122
- `,transparent:!0,depthWrite:!1,side:ei}),i=new T(t,e);return i.name="editor-floor-grid",i}class eo{setTransformMode(t){this._store.setTransformMode(t)}camera;orthographicCamera;orbitControls;transformControls;_auxRotateControls;_auxScaleControls;_activeGizmo;raycaster=(()=>{const t=new $t;return t.layers.enableAll(),t})();grid;_boxHelpers=new Map;_selectionMarks={outline:!0,wire:!1,box:!1};_unsubscribeSelectionTheme=()=>{};_constraintHelpers=new Map;_constraintControlRaycaster=(()=>{const t=new $t;return t.layers.enableAll(),t})();_hoveredConstraintControl=null;_constraintControlPointerSession=!1;_reflectionProbeHelpers=new Map;_triggerVolumeHelpers=new Map;_cameraHelpers=new Map;_lightHelpers=new Map;_audioHelpers=new Map;_spatialHandleRoots=[];_spatialHandleMeshes=[];_spatialHandleRaycaster=(()=>{const t=new $t;return t.layers.enableAll(),t})();_activeSpatialHandle=null;_hoveredSpatialHandle=null;_spatialHandleDragPlane=new qo;_spatialHandleDragOffset=new w;_spatialHandleDragPoint=new w;_orbitEnabledBeforeHandleDrag=!0;_transformEnabledBeforeHandleDrag=!0;_gizmoHelper;_editorAmbient;_editorDirLight;_lightRig;_scene;_contentBoundsBox=new pe;_contentBoundsAt=0;_renderer;_sparkRenderer=null;_sparkRendererLoading=!1;_sparkRendererFailed=!1;_lastSparkDiscoveryAt=Number.NEGATIVE_INFINITY;_disposed=!1;_editorObjects=[];_presentation=null;_axisLines=null;_verticalAxisLine=null;_axesWanted=!1;_stageAxes="floor";_lookAxisHexes=[null,null,null];_lookGridHex=null;_lookBackgroundHex=null;_lookToneMapping=null;_lookExposure=null;_lookGizmoSizePx=null;_stageAxisFrame=Ba;_appliedAxisSigns=[1,1,1];_gizmoLook={axes:null,navigation:null,hover:null,drag:null,opacity:null,arrowLength:null,arrowHead:null,ringWidth:null,navigationSize:null,navigationForm:"balls",navigationCorner:"top-right",highlightSaturation:null,highlightValue:null};_stageBoxSelect=null;_transformHandles={scale:!0,viewRotate:!0,freeMove:!0};_appliedArrow={length:1.2,head:1};_appliedRingWidth=1;_store;_objectMap=new Map;_canvas;_interactionElement;_onInteractionPointerUp;_onInteractionDblClick;_authoring;_pick;_standaloneAuthoring;_publishPickContext;_onlineAssetResolver;_onProjectionChange;_pointerDownPos=new Ht;_skipNextSync=!1;_marqueeActive=!1;_pointerSessionActive=!1;_marqueeDiv=null;_pointerDownButton=-1;_altDragOrbit=!1;_vcScene=new Ln;_vcCamera;_vcClickTargets=[];_vcBalls=[];_vcStalks=[];_vcSolids=[];_vcSize=Qe;_navigation="interactive";_marksLook="";_presentationGrid=!0;_vcMarginRight=mf;_vcMarginTop=Dl;_chromeInsetPx=0;_vcDir=new w;_previewClearColor=new D;_cameraView=null;_projection="perspective";_pendingProjection=null;_viewportAspect=1;_orthographicHeight=10;_cameraViewMode=null;_orbitEnabledBeforeCameraView=!0;_orbitTargetBeforeCameraView=new w;_lastGizmoObjectMap=null;_lastGizmoSig="";_lastGizmoEpoch=-1;_threejsToolContextActive=!1;_threeSurfaceShowing=!1;_vcRaycaster=new $t;_dropOverlay=null;_groundPlane=new qo(new w(0,1,0),0);_dragStartPos=new w;_dragStartQuat=new bt;_dragStartScale=new w;_attachedAuthoringId=null;_otherDragObjects=[];_allDragObjects=[];_preservedChildObjects=[];_activeTransformEditIds=[];_pivotDummy=new ii;_dummyIsPresentationAnchor=!1;_pivotPos=new w;_surfaceSnapRaycaster=new $t;_surfaceSnapIndicator;_vertexSnapTargets=[];_vertexSnapIndicator;_vertexSnapThreshold=20;batchedRenderer;_helpers=new Map;_snapAnimating=!1;_snapStartTime=0;_snapDuration=400;_snapQ1=new bt;_snapQ2=new bt;_snapDist=0;_flyActive=!1;_snapHold=!1;_flyKeys=new Set;_flySpeed=5;_flyEuler=new ml(0,0,0,"YXZ");_rightMouseDown=!1;constructor(t,e,i,s=t,n={}){this._canvas=t,this._interactionElement=s,this._scene=e,this._renderer=n.renderer,this._store=i,this._authoring=n.authoring??(()=>an().activeAuthoring(this._store)),this._pick=n.pick,this._standaloneAuthoring=n.authoring!==void 0,this._publishPickContext=n.publishPickContext??!0,this._chromeInsetPx=n.chromeInsetPx??0,this._onlineAssetResolver=n.onlineAssetResolver,this._onProjectionChange=n.onProjectionChange,this.camera=new wl(Ha(t.clientWidth/Math.max(1,t.clientHeight)),t.clientWidth/t.clientHeight,ta,ea),this.camera.position.copy(df).multiplyScalar(17.32),this.camera.lookAt(0,0,0),this.camera.layers.enableAll(),this._viewportAspect=t.clientWidth/Math.max(1,t.clientHeight),this.orthographicCamera=new Si(-5,5,5,-5,ta,ea),this.orthographicCamera.layers.enableAll(),this._syncOrthographicFromPerspective(),this.grid=_f(400),this.grid.layers.set(J),e.add(this.grid);const r=new Pn;r.setPositions(Ua(0)),r.setColors(new Array(Ur*2*3).fill(1)),this._axisLines=new Cn(r,new zn({vertexColors:!0,linewidth:2,transparent:!0,opacity:1,depthWrite:!1,toneMapped:!1})),yf(this._axisLines.material,this.grid.material.uniforms.uGrazingFade),this._axisLines.visible=!1,this._axisLines.layers.set(J),e.add(this._axisLines),this._unsubscribeSelectionTheme=Bn(t,()=>{ct();const l=JSON.stringify([ue(t),Ma(t),Sa(t)]);l!==this._marksLook&&(this._marksLook=l,this._boxHelpers.size>0&&this._syncBoxHelpers()),this._gizmoLook=xa(t),this._applyViewportLook(Bs(t)),this._applyGridLines(qu(t)),this._lookGizmoSizePx=ba(t),this._applyGizmoSize(),this._applyGizmoArrows(),this._readLookStage(t)}),this._lightRig=n?.lightRig!==!1,this._editorAmbient=new vl(16777215,.5),this._editorAmbient.layers.set(J),e.add(this._editorAmbient),this._editorDirLight=new _l(16777215,1),this._editorDirLight.position.set(10,20,10),this._editorDirLight.layers.set(J),e.add(this._editorDirLight),this._editorAmbient.visible=this._lightRig,this._editorDirLight.visible=this._lightRig,this.batchedRenderer=new $r,this.batchedRenderer.layers.set(J),e.add(this.batchedRenderer),s.addEventListener("wheel",this._onTrackpadWheel,{passive:!1}),this.orbitControls=new pd(this.camera,s),this.orbitControls.enableDamping=!0,this.orbitControls.dampingFactor=.1,this.orbitControls.mouseButtons={LEFT:-1,MIDDLE:$n.PAN,RIGHT:$n.ROTATE},this.transformControls=new sr(this.camera,t),this._auxScaleControls=new sr(this.camera,t),this._auxScaleControls.setMode("scale"),this._auxRotateControls=new sr(this.camera,t),this._auxRotateControls.setMode("rotate"),this._activeGizmo=this.transformControls;const a=l=>{l.getRaycaster().layers.enableAll(),l.addEventListener("dragging-changed",c=>{const d=c.value;if(d?_d():vd(),this.orbitControls.enabled=!d,d){this._activeGizmo=l;for(const m of this._allGizmos())m!==l&&(m.enabled=!1);const h=l.object,f=l.mode==="translate"?"position":l.mode==="rotate"?"rotation":"scale",u=m=>this._authoring().transforms?.editability?.(m,f).writable??!0,p=this._attachedAuthoringId??(h&&this._authoringIdForObject(h))??"";if(h){if(this._dragStartPos.copy(h.position),this._dragStartQuat.copy(h.quaternion),this._dragStartScale.copy(h.scale),this._otherDragObjects=[],this._allDragObjects=[],this._pivotPos.copy(h.position),h===this._pivotDummy?null:this._authoringIdForObject(h))for(const v of this._store.selectedEntityIds){if(v===p||!u(v))continue;const S=this._objectForAuthoringId(v);S&&this._otherDragObjects.push({id:v,obj:S,startPos:S.position.clone(),startQuat:S.quaternion.clone(),startScale:S.scale.clone()})}else for(const v of this._store.selectedEntityIds){if(!u(v))continue;const S=this._objectForAuthoringId(v);S&&this._allDragObjects.push({id:v,obj:S,startPos:S.position.clone(),startQuat:S.quaternion.clone(),startScale:S.scale.clone()})}const y=h===this._pivotDummy?this._allDragObjects.map(({id:v})=>v):[p,...this._otherDragObjects.map(({id:v})=>v)];this._preservedChildObjects=this._preparePreservedChildren(y.filter(Boolean)),this._activeTransformEditIds=[...new Set([...y.filter(Boolean),...this._preservedChildObjects.map(({id:v})=>v)])];const _=this._authoring();for(const v of this._activeTransformEditIds)ko(_,v)}}else this._surfaceSnapIndicator.visible=!1,this._vertexSnapIndicator.visible=!1,this.syncFromStore()}),l.addEventListener("objectChange",()=>{const c=l.object;if(!c)return;const d=l.mode,h=this._store.pivotMode==="individual-origins"||this._dummyIsPresentationAnchor,u=this._allDragObjects.length>0?this._allDragObjects:this._otherDragObjects;if(u.length>0){if(d==="translate"){const p=c.position.clone().sub(this._dragStartPos);for(const{obj:m,startPos:y}of u)m.position.copy(y).add(p)}else if(d==="rotate"){const p=c.quaternion.clone().multiply(this._dragStartQuat.clone().invert());if(h)for(const{obj:m,startQuat:y}of u)m.quaternion.copy(p).multiply(y);else for(const{obj:m,startPos:y,startQuat:_}of u){const v=y.clone().sub(this._pivotPos);v.applyQuaternion(p),m.position.copy(this._pivotPos).add(v),m.quaternion.copy(p).multiply(_)}}else if(d==="scale"){const p=new w(this._dragStartScale.x!==0?c.scale.x/this._dragStartScale.x:1,this._dragStartScale.y!==0?c.scale.y/this._dragStartScale.y:1,this._dragStartScale.z!==0?c.scale.z/this._dragStartScale.z:1);if(h)for(const{obj:m,startScale:y}of u)m.scale.copy(y).multiply(p);else for(const{obj:m,startPos:y,startScale:_}of u){const v=y.clone().sub(this._pivotPos);v.multiply(p),m.position.copy(this._pivotPos).add(v),m.scale.copy(_).multiply(p)}}}d==="translate"&&this._store.vertexSnapActive&&this._vertexSnapTargets.length>0?this._applyVertexSnap(c,u):d==="translate"&&this._store.snapToSurface&&this._applySurfaceSnap(c,u),this._restorePreservedChildren();for(const p of this._boxHelpers.values())"update"in p&&p.update();this._flushGizmoToStoreLive()}),l.addEventListener("mouseUp",()=>{this._flushGizmoToStore()})};a(this.transformControls),a(this._auxRotateControls),a(this._auxScaleControls),this._gizmoHelper=this.transformControls.getHelper(),this._gizmoHelper.traverse(l=>l.layers.set(J)),e.add(this._gizmoHelper);for(const l of[this._auxRotateControls,this._auxScaleControls]){const c=l.getHelper();c.traverse(d=>d.layers.set(J)),c.visible=!1,e.add(c)}this._pivotDummy.layers.set(J),e.add(this._pivotDummy),this._surfaceSnapIndicator=new T(new Jh(.08,.12,16),new vt({color:65416,side:ei,depthTest:!1})),this._surfaceSnapIndicator.rotation.x=-Math.PI/2,this._surfaceSnapIndicator.visible=!1,this._surfaceSnapIndicator.renderOrder=999,this._surfaceSnapIndicator.layers.set(J),e.add(this._surfaceSnapIndicator),this._vertexSnapIndicator=new T(new be(1,8,8),new vt({color:65450,depthTest:!1})),this._vertexSnapIndicator.visible=!1,this._vertexSnapIndicator.renderOrder=999,this._vertexSnapIndicator.layers.set(J),e.add(this._vertexSnapIndicator),this._gizmoLook=xa(t),this._rebuildAxisLines();for(const l of this._allGizmos())this._installGizmoHighlight(l);this._patchGizmo(this._gizmoHelper),this._patchGizmo(this._auxRotateControls.getHelper()),this._patchGizmo(this._auxScaleControls.getHelper()),this._dropNegativeAxisHandles(this._gizmoHelper,["translate","scale"]),this._dropNegativeAxisHandles(this._auxScaleControls.getHelper(),["scale"]),this._patchCombinedScaleGizmo(this._auxScaleControls.getHelper()),this._applyGizmoArrows(),this._lookGizmoSizePx=ba(t),this._applyGizmoSize(),this._applyGizmoAxisFrame(),this._vcCamera=new Si(-1.5,1.5,1.5,-1.5,.1,10),this._initOrientationGizmo(),window.addEventListener("keydown",this._onFlyKeyDown),window.addEventListener("keyup",this._onFlyKeyUp),s.addEventListener("pointerdown",this._onFlyPointerDown),s.addEventListener("pointerup",this._onFlyPointerUp),s.addEventListener("pointermove",this._onFlyPointerMove),s.addEventListener("wheel",this._onFlyWheel,{passive:!1}),t.addEventListener("pointerdown",this._onAltOrbitStart,{capture:!0}),window.addEventListener("pointerup",this._onAltOrbitRelease,{capture:!0}),window.addEventListener("pointercancel",this._onAltOrbitRelease,{capture:!0}),window.addEventListener("keydown",this._onSnapHoldKey),window.addEventListener("keyup",this._onSnapHoldKey),t.addEventListener("pointerdown",this._onPointerDown),s.addEventListener("pointermove",this._onPointerMove),this._onInteractionPointerUp=l=>{(l.target===t||l.target===s||this._pointerSessionActive)&&this._onPointerUp(l)},s.addEventListener("pointerup",this._onInteractionPointerUp),this._onInteractionDblClick=l=>{(l.target===t||l.target===s)&&this._onDoubleClick(l)},s.addEventListener("dblclick",this._onInteractionDblClick),t.addEventListener("dragover",this._onDragOver),t.addEventListener("dragleave",this._onDragLeave),t.addEventListener("drop",this._onDrop),this._editorObjects=[this.grid,...this._axisLines?[this._axisLines]:[],this._editorAmbient,this._editorDirLight,this.batchedRenderer,this._gizmoHelper,this._auxRotateControls.getHelper(),this._auxScaleControls.getHelper(),this._pivotDummy,this._surfaceSnapIndicator,this._vertexSnapIndicator],this._publishPickContext&&this._installPickContext(this.camera)}setScene(t){if(t===this._scene)return;for(const i of this._editorObjects)i.removeFromParent(),t.add(i);for(const i of this._boxHelpers.values())i.removeFromParent(),t.add(i);for(const i of this._constraintHelpers.values())i.removeFromParent(),t.add(i);for(const i of this._reflectionProbeHelpers.values())i.removeFromParent(),t.add(i);for(const i of this._triggerVolumeHelpers.values())i.removeFromParent(),t.add(i);for(const{helper:i}of this._cameraHelpers.values())i.removeFromParent(),t.add(i);for(const i of this._spatialHandleRoots)i.removeFromParent(),t.add(i);this._scene=t,this._contentBoundsAt=0;const e=this._lightRig&&!this._store.isAdoptedSceneActive&&this._presentation===null;this._editorAmbient.visible=e,this._editorDirLight.visible=e}get currentScene(){return this._scene}get renderCamera(){return this._cameraView??this.freeCamera}get freeCamera(){return this._projection==="orthographic"?this.orthographicCamera:this.camera}get projection(){return this._projection}_installPickContext(t){this._publishPickContext&&ia({camera:t,canvas:this._canvas,editorControls:{activate:(e,i)=>this._selectConstraintControlAt({clientX:e,clientY:i},!1),hover:(e,i)=>this._hoverConstraintControlAt({clientX:e,clientY:i}),clearHover:()=>this._clearConstraintControlHover()}})}setProjection(t){if(this._cameraView){this._pendingProjection=t;return}if(this._projection===t)return;t==="orthographic"?this._syncOrthographicFromPerspective():this._syncPerspectiveFromOrthographic(),this._projection=t;const e=this.freeCamera;this.orbitControls.object=e;for(const i of this._allGizmos())i.camera=e;this._applyGizmoSize(),this.orbitControls.update(),this._installPickContext(e),this._onProjectionChange?.(t)}_syncOrthographicFromPerspective(t=!1){const e=Math.max(.01,this.camera.position.distanceTo(this.orbitControls?.target??new w));t||(this._orthographicHeight=2*e*Math.tan(Wt.degToRad(this.camera.fov*.5))),this.orthographicCamera.position.copy(this.camera.position),this.orthographicCamera.quaternion.copy(this.camera.quaternion),this.orthographicCamera.up.copy(this.camera.up),this.orthographicCamera.zoom=1,this._applyOrthographicFrustum(),this.orthographicCamera.updateMatrixWorld(!0)}_syncPerspectiveFromOrthographic(){const e=this._orthographicHeight/Math.max(this.orthographicCamera.zoom,.01)/(2*Math.tan(Wt.degToRad(this.camera.fov*.5))),i=this.orthographicCamera.position.clone().sub(this.orbitControls.target).normalize();this.camera.position.copy(this.orbitControls.target).add(i.multiplyScalar(e)),this.camera.quaternion.copy(this.orthographicCamera.quaternion),this.camera.up.copy(this.orthographicCamera.up),this.camera.updateMatrixWorld(!0)}_applyOrthographicFrustum(){const t=this._orthographicHeight*.5,e=t*this._viewportAspect;this.orthographicCamera.left=-e,this.orthographicCamera.right=e,this.orthographicCamera.top=t,this.orthographicCamera.bottom=-t,this.orthographicCamera.updateProjectionMatrix()}get cameraViewMode(){return this._cameraViewMode}setCameraView(t,e){if(this.clearCameraView(),this._cameraView=t,this._cameraViewMode=e,this._orbitEnabledBeforeCameraView=this.orbitControls.enabled,this._orbitTargetBeforeCameraView.copy(this.orbitControls.target),e==="pilot"){const i=t.getWorldPosition(new w),s=t.getWorldDirection(new w),n=Math.max(1,this.freeCamera.position.distanceTo(this.orbitControls.target));this.orbitControls.object=t,this.orbitControls.target.copy(i).add(s.multiplyScalar(n)),this.orbitControls.enabled=!0,this.orbitControls.update()}else this.orbitControls.enabled=!1;this._publishPickContext&&this._installPickContext(t)}clearCameraView(){if(!this._cameraView)return;this._flyActive&&this._exitFlyMode(),this.orbitControls.object=this.freeCamera,this.orbitControls.target.copy(this._orbitTargetBeforeCameraView),this.orbitControls.enabled=this._orbitEnabledBeforeCameraView,this.orbitControls.update(),this._cameraView=null,this._cameraViewMode=null;const t=this._pendingProjection;this._pendingProjection=null,t&&t!==this._projection&&this.setProjection(t),this._publishPickContext&&this._installPickContext(this.freeCamera)}get objectMap(){return this._objectMap}set objectMap(t){this._objectMap=t}attach(t){const e=this._objectForAuthoringId(t);e&&(this._attachedAuthoringId=t,this._attachGizmosTo(e))}detach(){this._attachedAuthoringId=null,this._detachGizmos()}_objectForAuthoringId(t){const e=this._authoring();return e.hierarchy.node(t)===null?null:wc(e,this._objectMap,t)}_authoringIdForObject(t){return this._authoring().hierarchy.idForObject3D?.(t)??Vr(t)??null}_hasBoundableGeometry(t){return Nl([t]).length>0}_makeDiagnosticBounds(t){if(this._hasBoundableGeometry(t))return new Oo(t,ue(this._canvas).visible);const e=new ft(wn,wn,wn),i=new Jr(e);e.dispose();const s=new He({color:new D(ue(this._canvas).visible),toneMapped:!1}),n=new Pi(i,s);return t.getWorldPosition(n.position),n.isBoxHelper=!0,n._entityObj=t,n}_syncBoxHelpers(){for(const e of this._boxHelpers.values())this._scene.remove(e),e.geometry.dispose(),e.material.dispose();this._boxHelpers.clear();const t=(e,i)=>{i.layers.set(J),this._scene.add(i),this._boxHelpers.set(e,i)};if(this._store.showHelpers&&this._store.helperVisibility.bounds)for(const e of this._objectMap.keys()){const i=this._objectForAuthoringId(e);i&&t(`bounds:${e}`,this._makeDiagnosticBounds(i))}for(const e of this._store.selectedEntityIds){const i=this._objectForAuthoringId(e);if(!i)continue;const s=this._hasBoundableGeometry(i);if(s&&this._selectionMarks.wire){let n=0;i.traverse(r=>{const a=r;if(!a.isMesh||!a.geometry||he(a))return;const l=Sa(this._canvas),c=new Pi(new Yh(a.geometry),new He({color:l.color??ue(this._canvas).visible,transparent:!0,opacity:l.opacity??.5,depthTest:!0}));c.matrixAutoUpdate=!1,c._wireOf=a,t(`wire:${e}:${n++}`,c)})}if(!(s&&!this._selectionMarks.box)){if(s){const n=Ma(this._canvas);t(`selection:${e}`,new wr(i,{color:ue(this._canvas).visible,edges:n.edges,frame:n.frame,...n.lineWidth===null?{}:{lineWidth:n.lineWidth}}));continue}this._standaloneAuthoring&&i.isBone||[...this._constraintHelpers.values()].some(n=>n.presents(i))||t(`selection:${e}`,new wr(i,{fixedSize:wn,color:ue(this._canvas).visible}))}}}_syncReflectionProbeHelpers(t=null){if(t===null){const e=new Map,i=new Set;for(const[s,n]of this._objectMap)!n||i.has(n)||!ts(n)||(i.add(n),e.set(s,n));for(const[s,n]of this._reflectionProbeHelpers)e.get(s)!==n.source&&(n.dispose(),this._reflectionProbeHelpers.delete(s));for(const[s,n]of e)this._ensureReflectionProbeHelper(s,n)}else{let e=!1;for(const i of t){const s=this._objectMap.get(i),n=s&&ts(s)?s:null,r=this._reflectionProbeHelpers.get(i);r&&r.source!==n&&(n===null&&(e=!0),r.dispose(),this._reflectionProbeHelpers.delete(i)),n&&![...this._reflectionProbeHelpers.values()].some(a=>a.source===n)&&this._ensureReflectionProbeHelper(i,n)}if(e){this._syncReflectionProbeHelpers();return}}for(const[e,i]of this._reflectionProbeHelpers)i.setSelected(this._store.selectedEntityIds.has(e)),i.visible=this._threejsToolContextActive&&this._store.showHelpers&&this._store.helperVisibility.reflectionProbes,i.update()}_ensureReflectionProbeHelper(t,e){if(this._reflectionProbeHelpers.has(t))return;const i=new ep(e);this._reflectionProbeHelpers.set(t,i),this._scene.add(i)}_syncTriggerVolumeHelpers(t=null){if(t===null){const i=new Map,s=new Set;for(const[n,r]of this._objectMap)!r||s.has(r)||!Ir(r)||(s.add(r),i.set(n,r));for(const[n,r]of this._triggerVolumeHelpers)i.get(n)!==r.source&&this._disposeTriggerVolumeHelper(n,r);for(const[n,r]of i)this._ensureTriggerVolumeHelper(n,r)}else{let i=!1;for(const s of t){const n=this._objectMap.get(s),r=n&&Ir(n)?n:null,a=this._triggerVolumeHelpers.get(s);a&&a.source!==r&&(r===null&&(i=!0),this._disposeTriggerVolumeHelper(s,a)),r&&![...this._triggerVolumeHelpers.values()].some(l=>l.source===r)&&this._ensureTriggerVolumeHelper(s,r)}if(i){this._syncTriggerVolumeHelpers();return}}const e=this._threeSurfaceShowing&&this._store.showHelpers&&this._store.helperVisibility.triggerVolumes;for(const[i,s]of this._triggerVolumeHelpers)s.setSelected(this._store.selectedEntityIds.has(i)),s.visible=e,s.update()}_ensureTriggerVolumeHelper(t,e){if(this._triggerVolumeHelpers.has(t))return;const i=new Wp(e);this._triggerVolumeHelpers.set(t,i),this._scene.add(i)}_disposeTriggerVolumeHelper(t,e){e.dispose(),this._triggerVolumeHelpers.delete(t)}_syncConstraintHelpers(t=null){if(t===null){const i=new Map,s=new Set;for(const[n,r]of this._objectMap)!r||s.has(r)||An(r).length===0||(s.add(r),i.set(n,r));for(const[n,r]of this._constraintHelpers)i.get(n)!==r.source&&(this._disposeConstraintHelper(r),this._constraintHelpers.delete(n));for(const[n,r]of i)this._ensureConstraintHelper(n,r)}else{let i=!1;for(const s of t){const n=this._objectMap.get(s),r=n&&An(n).length>0?n:null,a=this._constraintHelpers.get(s);a&&a.source!==r&&(r===null&&(i=!0),this._disposeConstraintHelper(a),this._constraintHelpers.delete(s)),r&&![...this._constraintHelpers.values()].some(l=>l.source===r)&&this._ensureConstraintHelper(s,r)}if(i){this._syncConstraintHelpers();return}}const e=new Set;for(const i of this._store.selectedEntityIds){const s=this._objectForAuthoringId(i);s&&e.add(s)}for(const[i,s]of this._constraintHelpers)s.setSelected(this._store.selectedEntityIds.has(i)),s.setSelectedObjects(e),s.visible=this._threejsToolContextActive&&this._store.showHelpers&&this._store.helperVisibility.constraints,s.update(this.camera)}_ensureConstraintHelper(t,e){if(this._constraintHelpers.has(t))return;const i=new Xu(e);this._constraintHelpers.set(t,i),this._scene.add(i)}_disposeConstraintHelper(t){this._hoveredConstraintControl?.helper===t&&(this._hoveredConstraintControl=null),t.dispose()}_raycastConstraintControl(t){const e=[];for(const r of this._constraintHelpers.values())r.visible&&e.push(...r.controlMeshes());if(e.length===0)return null;const i=this._canvas.getBoundingClientRect(),s=new Ht((t.clientX-i.left)/i.width*2-1,-((t.clientY-i.top)/i.height)*2+1);this._constraintControlRaycaster.setFromCamera(s,this.renderCamera);const n=this._constraintControlRaycaster.intersectObjects(e,!1)[0]?.object;if(!n)return null;for(const r of this._constraintHelpers.values()){const a=r.controlFor(n);if(a)return{helper:r,control:a}}return null}_updateConstraintControlHover(t){if(t.buttons&1)return this._constraintControlPointerSession;const e=this._hoverConstraintControlAt(t);return e?(this._hoveredSpatialHandle&&(_r(this._hoveredSpatialHandle,!1),this._hoveredSpatialHandle=null),this._canvas.style.cursor=e,!0):(this._canvas.style.cursor="",!1)}_hoverConstraintControlAt(t){const e=this._raycastConstraintControl(t),i=this._hoveredConstraintControl;return e?(i?.mesh!==e.control.mesh&&(i&&i.helper.setHoveredControl(null),e.helper.setHoveredControl(e.control.mesh),this._hoveredConstraintControl={helper:e.helper,mesh:e.control.mesh}),this._authoringIdForObject(e.control.object)?"pointer":"not-allowed"):(this._clearConstraintControlHover(),null)}_clearConstraintControlHover(){this._hoveredConstraintControl?.helper.setHoveredControl(null),this._hoveredConstraintControl=null}_selectConstraintControlAt(t,e=!0){const i=this._raycastConstraintControl(t);if(!i)return!1;this._constraintControlPointerSession=e;const s=this._authoringIdForObject(i.control.object);if(s){const n=this._authoring();Zi(n,[s],{intent:"exact"})||this._store.select(s),Yt(`${i.control.label} selected — move it with the gizmo.`)}else Yt(`${i.control.label} is a runtime-only constraint control.`);return!0}_syncCameraHelpers(t=null){if(t===null){const i=new Map;for(const[s,n]of this._objectMap){const r=this._nativeCamera(n);r&&i.set(s,r)}for(const[s,n]of this._cameraHelpers)i.get(s)!==n.source&&this._disposeCameraHelper(s,n);for(const[s,n]of i)this._ensureCameraHelper(s,n)}else{let i=!1;for(const s of t){const n=this._objectMap.get(s),r=n?this._nativeCamera(n):null,a=this._cameraHelpers.get(s);a&&a.source!==r&&(r===null&&(i=!0),this._disposeCameraHelper(s,a)),r&&![...this._cameraHelpers.values()].some(l=>l.source===r)&&this._ensureCameraHelper(s,r)}if(i){this._syncCameraHelpers();return}}const e=this._threeSurfaceShowing&&this._store.showHelpers&&this._store.helperVisibility.cameras;for(const i of this._cameraHelpers.values())i.helper.visible=e,i.helper.update()}_syncLightHelpers(t=null){if(t===null){const i=new Map;for(const[s,n]of this._objectMap){const r=this._nativeLight(n);r&&i.set(s,r)}for(const[s,n]of this._lightHelpers)i.get(s)!==n.source&&this._disposeLightHelper(s,n);for(const[s,n]of i)this._ensureLightHelper(s,n)}else{let i=!1;for(const s of t){const n=this._objectMap.get(s),r=n?this._nativeLight(n):null,a=this._lightHelpers.get(s);a&&a.source!==r&&(r===null&&(i=!0),this._disposeLightHelper(s,a)),r&&![...this._lightHelpers.values()].some(l=>l.source===r)&&this._ensureLightHelper(s,r)}if(i){this._syncLightHelpers();return}}const e=this._threeSurfaceShowing&&this._store.showHelpers&&this._store.helperVisibility.lights;for(const i of this._lightHelpers.values())i.helper.visible=e,i.helper.update?.()}_nativeLight(t){return t.isLight?t:null}_disposeLightHelper(t,e){e.helper.removeFromParent(),e.helper.dispose?.(),this._lightHelpers.delete(t)}_ensureLightHelper(t,e){if(this._lightHelpers.has(t))return;const i=.5;let s=null;const n=e;try{n.isDirectionalLight?s=new qh(e,i):n.isPointLight?s=new Zh(e,i):n.isSpotLight?s=new Qh(e):n.isHemisphereLight&&(s=new $h(e,i))}catch{s=null}s&&(s.name=`Light helper: ${e.name||t}`,s.userData.editorOnly=!0,s.traverse(r=>r.layers.set(J)),s.layers.set(J),this._lightHelpers.set(t,{source:e,helper:s}),this._scene.add(s))}_syncAudioHelpers(t=null){if(t===null){const i=new Map;for(const[s,n]of this._objectMap){const r=this._nativeAudio(n);r&&i.set(s,r)}for(const[s,n]of this._audioHelpers)i.get(s)!==n.source&&this._disposeAudioHelper(s,n);for(const[s,n]of i)this._ensureAudioHelper(s,n)}else for(const i of t){const s=this._objectMap.get(i),n=s?this._nativeAudio(s):null,r=this._audioHelpers.get(i);r&&r.source!==n&&this._disposeAudioHelper(i,r),n&&![...this._audioHelpers.values()].some(a=>a.source===n)&&this._ensureAudioHelper(i,n)}const e=this._threeSurfaceShowing&&this._store.showHelpers&&this._store.helperVisibility.audio;for(const i of this._audioHelpers.values())i.helper.visible=e}_nativeAudio(t){const e=t.type;return e==="Audio"||e==="PositionalAudio"||e==="AudioListener"?t:null}_ensureAudioHelper(t,e){if(this._audioHelpers.has(t))return;const i=new Ft,s=e.type==="AudioListener"?8377599:16763274,n=new T(new qe(.16),new vt({color:s,wireframe:!0,depthTest:!1}));i.add(n),i.name=`Audio helper: ${e.name||t}`,i.userData.editorOnly=!0,i.traverse(r=>r.layers.set(J)),i.layers.set(J),e.add(i),this._audioHelpers.set(t,{source:e,helper:i})}_disposeAudioHelper(t,e){e.helper.traverse(i=>{const s=i;s.geometry?.dispose?.(),s.material?.dispose?.()}),e.helper.removeFromParent(),this._audioHelpers.delete(t)}_disposeCameraHelper(t,e){e.helper.removeFromParent(),e.helper.dispose(),this._cameraHelpers.delete(t)}_ensureCameraHelper(t,e){if(this._cameraHelpers.has(t))return;let i;try{i=new Kh(e)}catch(s){this._refuseCameraOverlay(t,e,s);return}i.name=`Camera frustum: ${e.name||t}`,i.userData.editorOnly=!0,i.layers.set(J),this._cameraHelpers.set(t,{source:e,helper:i}),this._scene.add(i)}_refusedCameraOverlays=new Set;_refuseCameraOverlay(t,e,i){this._refusedCameraOverlays.has(t)||(this._refusedCameraOverlays.add(t),Qi.warn(`Helpers → Cameras draws no frustum for "${e.name||e.type}": ${i instanceof Error?i.message:String(i)}. This world's camera was constructed by the GAME's own copy of three, and \`THREE.CameraHelper\` is the editor's class reading fields off it that that revision does not define. Every other camera capability (framing, selection, inspection) is unaffected. It closes when the game resolves \`three\` to the host's instance — a bare, un-rewritten \`import 'three'\` in its own source.`,"authoring"))}_nativeCamera(t){if(t.isCamera)return t;const e=Ct(t,"_camera");return e?.isCamera?e:null}_syncSpatialHandles(){Oa(this._spatialHandleRoots),this._spatialHandleRoots=[],this._spatialHandleMeshes=[],this._hoveredSpatialHandle=null;const t=Qn(this._authoring());if(!t||!this._threejsToolContextActive||!this._store.showHelpers)return;const e=this._store.helperVisibility;for(const i of this._store.selectedEntityIds){const s=t.layers(i).filter(r=>r.category in e?e[r.category]:!0),n=wp(i,s);for(const r of n.handles)Ta(r,this.renderCamera);for(const r of n.roots)this._scene.add(r);this._spatialHandleRoots.push(...n.roots),this._spatialHandleMeshes.push(...n.handles)}}_raycastSpatialHandle(t){if(this._spatialHandleMeshes.length===0)return null;const e=this._canvas.getBoundingClientRect(),i=new Ht((t.clientX-e.left)/e.width*2-1,-((t.clientY-e.top)/e.height)*2+1);return this._spatialHandleRaycaster.setFromCamera(i,this.renderCamera),this._spatialHandleRaycaster.intersectObjects(this._spatialHandleMeshes,!1)[0]?.object??null}_spatialHandleWorldPoint(t){const e=this._canvas.getBoundingClientRect(),i=new Ht((t.clientX-e.left)/e.width*2-1,-((t.clientY-e.top)/e.height)*2+1);this._spatialHandleRaycaster.setFromCamera(i,this.renderCamera);const s=new w;return this._spatialHandleRaycaster.ray.intersectPlane(this._spatialHandleDragPlane,s)?s.add(this._spatialHandleDragOffset):null}_finishSpatialHandleDrag(t){const e=this._activeSpatialHandle;this._activeSpatialHandle=null,this.orbitControls.enabled=this._orbitEnabledBeforeHandleDrag,this.transformControls.enabled=this._transformEnabledBeforeHandleDrag,this.syncFromStore(),this._canvas.style.cursor="",t&&e&&Qn(this._authoring())?.commit(e.nodeId,e.handle.id,[this._spatialHandleDragPoint.x,this._spatialHandleDragPoint.y,this._spatialHandleDragPoint.z])}_updateSpatialHandleDrag(t){const e=this._activeSpatialHandle;if(!e)return!1;const i=this._spatialHandleWorldPoint(t);return i&&(this._spatialHandleDragPoint.copy(i),Qn(this._authoring())?.preview(e.nodeId,e.handle.id,[i.x,i.y,i.z]),this._syncSpatialHandles(),this._canvas.style.cursor="grabbing"),!0}_updateSpatialHandleHover(t){if(t.buttons&1||this._spatialHandleMeshes.length===0)return;const e=this._raycastSpatialHandle(t);if(e===this._hoveredSpatialHandle)return;if(this._hoveredSpatialHandle&&_r(this._hoveredSpatialHandle,!1),this._hoveredSpatialHandle=e,!e){this._canvas.style.cursor="";return}_r(e,!0);const i=Ea(e);this._canvas.style.cursor=i?.handle.writable?"grab":"not-allowed"}_updateEditorHandleInteraction(t){return this._updateSpatialHandleDrag(t)||this._updateConstraintControlHover(t)}_previewInfrastructure(){return[this.grid,...this._axisLines?[this._axisLines]:[],this._gizmoHelper,this._auxRotateControls.getHelper(),this._auxScaleControls.getHelper(),...this._boxHelpers.values(),...this._constraintHelpers.values(),...this._reflectionProbeHelpers.values(),...this._triggerVolumeHelpers.values(),...[...this._cameraHelpers.values()].map(({helper:t})=>t),...this._spatialHandleRoots]}_suspendPreviewInfrastructure(){const t=this._previewInfrastructure().map(e=>[e,e.visible]);for(const[e]of t)e.visible=!1;return()=>{for(const[e,i]of t)e.visible=i}}_allGizmos(){return[this.transformControls,this._auxRotateControls,this._auxScaleControls]}_anyGizmoDragging(){return this._allGizmos().some(t=>t.dragging)}_attachGizmosTo(t){this.transformControls.attach(t),this._auxRotateControls.attach(t),this._auxScaleControls.attach(t)}_detachGizmos(){for(const t of this._allGizmos())t.detach()}syncFromStore(){this._gizmoHelper.traverse(b=>b.layers.set(J));const t=this._store.transformMode,i=t==="combined"||t==="select"?"translate":t;this.transformControls.mode!==i&&this.transformControls.setMode(i),this._applySnapToGizmos();for(const b of this._allGizmos())b.setSpace(this._store.transformSpace);const s=an(),n=this._authoring(),r=s.toolOwner(n,this._store.selectedEntityIds);this._threejsToolContextActive=(this._standaloneAuthoring||s.toolOwnerPainted(this._store,r))&&r?.kind==="three";const a=this._standaloneAuthoring||s.threeSurfaceShowing(this._store,n);this._threeSurfaceShowing=a,this.grid.visible=this._presentationGrid&&a,this._axisLines&&(this._axisLines.visible=this.grid.visible&&this._axesWanted);const l=this._store.helperVisibility,c=this._standaloneAuthoring?null:s.threeViewportRootId(this._store),d=c!==null&&Oc(c);d&&s.applyRootHiddenVisibility(this._objectMap,c),d&&s.suppressRootEnvironment(this._scene);const h=this._store.gizmoEpoch,f=`${this._store.showHelpers}|${JSON.stringify(l)}|${c??""}|${d}|${this._threejsToolContextActive}`,u=this._objectMap!==this._lastGizmoObjectMap,p=f!==this._lastGizmoSig,m=u?null:this._store.ingestObjectMapMembershipChangesSince(this._lastGizmoEpoch),y=u||p||m===null?null:m.changedIds,_=y===null||y.size>0;if(this._lastGizmoObjectMap=this._objectMap,this._lastGizmoSig=f,this._lastGizmoEpoch=h,_){s.applyRootHiddenVisibility(this._objectMap,c);const b=y===null?Xp(this._objectMap):Jp(this._objectMap,y);for(const M of b)M.traverse(P=>{if(Ct(P,"editorIcon")){P.visible=this._store.showHelpers;return}if(!Ct(P,"editorHelper"))return;const z=Ct(P,"editorHelperType");if(z==="skeletons"){P.visible=this._store.showHelpers&&(l.skeletons||!!Ct(P,"skeletonEnabled"));return}z&&z in l?P.visible=this._store.showHelpers&&l[z]:P.visible=this._store.showHelpers});for(const[M,P]of this._helpers)P.visible=this._store.showHelpers&&(!(M in l)||l[M]);this._syncCameraHelpers(y),this._syncLightHelpers(y)}this._syncAudioHelpers(y),this._syncReflectionProbeHelpers(y),this._syncTriggerVolumeHelpers(y),this._syncConstraintHelpers(y);const v=this._threejsToolContextActive&&n.capabilities.transform&&t!=="select"?this._store.selectedEntityId:null,S=t==="translate"||t==="combined"?"position":t==="rotate"?"rotation":"scale",C=v?t==="combined"?(b=>["position","rotation","scale"].some(M=>n.transforms?.editability?.(b,M).writable??!0))(v):n.transforms?.editability?.(v,S).writable??!0:!1;if(v&&C){if(!this._anyGizmoDragging())if(this._store.pivotMode==="median-point"&&this._store.selectedEntityIds.size>1){const b=new w;let M=0;for(const P of this._store.selectedEntityIds){if(!(n.transforms?.editability?.(P,S).writable??!0))continue;const z=this._objectForAuthoringId(P);z&&(b.add(z.getWorldPosition(Qp)),M++)}M>0&&b.divideScalar(M),this._pivotDummy.position.copy(b),this._pivotDummy.quaternion.identity(),this._pivotDummy.scale.set(1,1,1),this._attachedAuthoringId=null,this._dummyIsPresentationAnchor=!1,this._attachGizmosTo(this._pivotDummy)}else{const b=this._objectForAuthoringId(v),M=Ct(b,"pivot"),P=M&&(M[0]!==0||M[1]!==0||M[2]!==0),z=P?null:this._centreAnchorFor(b);if(z&&b)this._pivotDummy.position.copy(z),this._pivotDummy.quaternion.copy(b.getWorldQuaternion(br)),this._pivotDummy.scale.copy(b.getWorldScale(La)),this._attachedAuthoringId=v,this._dummyIsPresentationAnchor=!0,this._attachGizmosTo(this._pivotDummy);else if(P&&b){const H=new w(M[0],M[1],M[2]);H.applyQuaternion(b.getWorldQuaternion(br)),this._pivotDummy.position.copy(b.getWorldPosition(Fa)).add(H),this._pivotDummy.quaternion.copy(br),this._pivotDummy.scale.copy(b.getWorldScale(La)),this._attachedAuthoringId=v,this._dummyIsPresentationAnchor=!1,this._attachGizmosTo(this._pivotDummy)}else this._dummyIsPresentationAnchor=!1,this.attach(v)}}else this.detach();this._syncBoxHelpers(),this._syncSpatialHandles(),this._syncCombinedGizmoHalves()}_applySnapToGizmos(){const t=this._store.snapEnabled||this._snapHold,e=this._store.snapValues;for(const i of this._allGizmos())i.setTranslationSnap(t?e.translate:null),i.setRotationSnap(t?Wt.degToRad(e.rotate):null),i.setScaleSnap(t?e.scale:null)}_onAltOrbitStart=t=>{t.altKey&&t.button===0&&(this._altDragOrbit=!0,this.orbitControls.mouseButtons.LEFT=$n.ROTATE)};_onAltOrbitRelease=()=>{this._altDragOrbit&&(this._altDragOrbit=!1,this.orbitControls.mouseButtons.LEFT=-1)};_onSnapHoldKey=t=>{const e=t.ctrlKey||t.metaKey;if(e!==this._snapHold&&(this._snapHold=e,this._applySnapToGizmos(),e&&this._anyGizmoDragging()&&!this._store.snapEnabled)){const{translate:i,rotate:s,scale:n}=this._store.snapValues;Yt(`Snapping while held: ${i} units · ${s}° · ×${n}`)}};_syncCombinedGizmoHalves(){if(this._anyGizmoDragging())return;const t=this._store.transformMode==="combined",e=this._attachedAuthoringId,i=this._authoring().transforms?.editability,s=c=>e===null||(i?.(e,c).writable??!0),n=t&&this._auxRotateControls.object!==void 0&&s("rotation"),r=t&&this._transformHandles.scale&&this._auxScaleControls.object!==void 0&&s("scale");this._auxRotateControls.enabled=n,this._auxScaleControls.enabled=r;const a=this._auxRotateControls.getHelper(),l=this._auxScaleControls.getHelper();a.visible=n,l.visible=r;for(const c of[a,l])c.traverse(d=>d.layers.set(J));this.transformControls.enabled=!0}moveGizmosTo(t){const e=this._gizmoObjects();for(const i of e)t.add(i)}restoreGizmos(){const t=this._gizmoObjects();for(const e of t)this._scene.add(e)}_gizmoObjects(){return[this.grid,...this._axisLines?[this._axisLines]:[],this._editorAmbient,this._editorDirLight,this.batchedRenderer,this._gizmoHelper,this._auxRotateControls.getHelper(),this._auxScaleControls.getHelper(),this._pivotDummy,this._surfaceSnapIndicator,...[...this._cameraHelpers.values()].map(({helper:t})=>t),...this._spatialHandleRoots]}_contentBounds(t=!1){const e=performance.now(),i=this._contentBoundsAt===0||e-this._contentBoundsAt>Yp;if(t||i){this._contentBoundsBox.makeEmpty();for(const s of this._scene.children)he(s)||xc(this._contentBoundsBox,s);this._contentBoundsAt=e}return this._contentBoundsBox}_measureContentBounds(){const t=[];for(const e of this._scene.children)he(e)||bc(e,t);this._contentBoundsBox.makeEmpty();for(const e of t)this._contentBoundsBox.union(e);return this._contentBoundsAt=performance.now(),t}_updateClipPlanes(){const t=this._contentBounds();let e=0,i=0;t.isEmpty()||(t.getBoundingSphere(xr),e=this.freeCamera.position.distanceTo(xr.center),i=xr.radius);const{near:s,far:n}=ud(e,i);s===this.camera.near&&n===this.camera.far||(this.camera.near=s,this.camera.far=n,this.camera.updateProjectionMatrix(),this.orthographicCamera.near=s,this.orthographicCamera.far=n,this.orthographicCamera.updateProjectionMatrix())}seedFromGameCamera(t){const e=Pa(this._measureContentBounds()),i=ap(t,e);if(!i)return!1;const s=this.camera.position.clone(),n=this.orbitControls.target.clone();this.camera.position.copy(i.position),this.orbitControls.target.copy(i.target),this.camera.lookAt(this.orbitControls.target),this.camera.updateMatrixWorld(!0);const r=this._scene.children.filter(a=>!he(a));return dp(this.camera,r,i.position.distanceTo(i.target))?(this._updateClipPlanes(),this.orbitControls.update(),!0):(this.camera.position.copy(s),this.orbitControls.target.copy(n),this.camera.lookAt(this.orbitControls.target),this.camera.updateMatrixWorld(!0),!1)}focusOnScene(){const t=Pa(this._measureContentBounds());if(t.isEmpty())return!1;const e=t.getCenter(new w),i=this.camera.position.clone().sub(this.orbitControls.target).normalize(),s=ti(t,this.camera,i);return Number.isFinite(s)?(this.camera.position.copy(e).add(i.multiplyScalar(s)),this.orbitControls.target.copy(e),this._orthographicHeight=Math.max(t.getSize(new w).y,t.getSize(new w).x/this._viewportAspect)*1.15,this._syncOrthographicFromPerspective(!0),this._updateClipPlanes(),!0):!1}focusOn(t){const e=this._contentOrProbeBounds(t),i=e.getCenter(new w),s=this.camera.position.clone().sub(this.orbitControls.target).normalize(),n=ti(e,this.camera,s);this.camera.position.copy(i).add(s.multiplyScalar(n)),this.orbitControls.target.copy(i);const r=e.getSize(new w);this._orthographicHeight=Math.max(r.y,r.x/this._viewportAspect,.01)*1.15,this._syncOrthographicFromPerspective(!0)}activateVertexSnap(){this._vertexSnapTargets=this._collectVertices(this._store.selectedEntityIds)}deactivateVertexSnap(){this._vertexSnapTargets=[],this._vertexSnapIndicator.visible=!1}focusOnMultiple(t){if(t.length===0)return;if(t.length===1){this.focusOn(t[0]);return}const e=new pe;for(const a of t)e.union(this._contentOrProbeBounds(a));const i=e.getCenter(new w),s=this.camera.position.clone().sub(this.orbitControls.target).normalize(),n=ti(e,this.camera,s);this.camera.position.copy(i).add(s.multiplyScalar(n)),this.orbitControls.target.copy(i);const r=e.getSize(new w);this._orthographicHeight=Math.max(r.y,r.x/this._viewportAspect,.01)*1.15,this._syncOrthographicFromPerspective(!0)}_centreAnchorFor(t){const e=this._store.gizmoAnchor;if(!t||e==="pivot"||e==="auto"&&Sc(t)===0)return null;const i=$e(t);if(i.isEmpty()||e==="auto"&&!Mc(t,i)?.worldAnchored)return null;const s=i.getCenter(new w);return t.updateWorldMatrix(!0,!1),s.distanceToSquared(t.getWorldPosition(Fa))<$p?null:s}_contentOrProbeBounds(t){const e=ts(t);if(!e)return $e(t);const i=e.config,[s,n,r]=i.size,a=i.shape==="sphere"?new w(1,1,1).multiplyScalar(Math.max(.01,i.radius)):new w(Math.max(.01,s),Math.max(.01,n),Math.max(.01,r)).multiplyScalar(.5);return t.updateWorldMatrix(!0,!1),new pe(a.clone().negate(),a).applyMatrix4(t.matrixWorld)}setHelper(t,e){ct();const i=this._helpers.get(t);if(i&&(this._scene.remove(i),this._helpers.delete(t)),!e)return;Dt(e,"editorHelper",!0),Dt(e,"editorHelperType",t);const s=this._store.helperVisibility;e.visible=this._store.showHelpers&&(!(t in s)||s[t]),this._scene.add(e),this._helpers.set(t,e)}setViewPreset(t){this._projection==="orthographic"&&this.setProjection("perspective");const e=this.orbitControls.target.clone(),i=this.camera.position.distanceTo(e),s=new w;switch(t){case"top":s.set(0,1,0);break;case"front":s.set(0,0,1);break;case"right":s.set(1,0,0);break;case"perspective":s.set(1,1,1).normalize();break}this.camera.position.copy(e).add(s.multiplyScalar(i)),this.camera.lookAt(e),t!=="perspective"&&this.setProjection("orthographic"),this.orbitControls.update()}setPose(t,e,i){this.setProjection("perspective"),this.camera.position.set(t.x,t.y,t.z),this.orbitControls.target.set(e.x,e.y,e.z),this.camera.lookAt(this.orbitControls.target),i!==void 0&&(this.camera.fov=i,this.camera.updateProjectionMatrix()),this.orbitControls.update()}resize(t,e){this._viewportAspect=Math.max(1,t)/Math.max(1,e),this.camera.aspect=this._viewportAspect,this.camera.fov=Ha(this._viewportAspect),this.camera.updateProjectionMatrix(),this._applyOrthographicFrustum(),this._applyGizmoSize()}update(t=0){this._ensureSparkRenderer(),this._syncLookBackground();const e=this.transformControls.object;if(e&&e!==this._pivotDummy&&!e.parent&&(this._detachGizmos(),this.syncFromStore()),this._updateFlyCamera(t),this.orbitControls.update(),this._snapAnimating){const i=performance.now()-this._snapStartTime;let s=Math.min(i/this._snapDuration,1);s=s<.5?4*s*s*s:1-(-2*s+2)**3/2;const n=new bt().slerpQuaternions(this._snapQ1,this._snapQ2,s),r=new w(0,0,1).applyQuaternion(n);this.freeCamera.position.copy(this.orbitControls.target).add(r.multiplyScalar(this._snapDist)),this.freeCamera.lookAt(this.orbitControls.target),s>=1&&(this._snapAnimating=!1)}this._presentation&&(this._presentation.rig.resolveSource({light:this._store.isAdoptedSceneActive}),this._presentation.rig.update(this.camera));for(const i of this._boxHelpers.values()){const s=i._wireOf;if(s){i.matrix.copy(s.matrixWorld),i.matrixWorldNeedsUpdate=!0;continue}if(i instanceof wr){i.updateIfNeeded();continue}const n=i;n._entityObj?n._entityObj.getWorldPosition(i.position):i instanceof Oo&&i.update()}for(const i of this._constraintHelpers.values())i.update(this.camera);for(const i of this._reflectionProbeHelpers.values())i.update();for(const i of this._triggerVolumeHelpers.values())i.update();for(const{helper:i}of this._cameraHelpers.values())i.update();for(const i of this._spatialHandleMeshes)Ta(i,this.renderCamera);this._enforceLodForcedLevels(),this._updateClipPlanes()}_enforceLodForcedLevels(){const t=new Set(this._objectMap.values());for(const[e,i]of this._store.lodForcedLevels){const s=this._objectMap.get(e),n=s?Cc(s,a=>t.has(a)):null;if(!n||n.levels.length===0)continue;n.autoUpdate=!1;const r=Math.min(Math.max(i,0),n.levels.length-1);for(let a=0;a<n.levels.length;a++)n.levels[a].object.visible=a===r}}renderWithInfrastructure(t){const e=this._sparkRenderer,i=this._cameraView?this._suspendPreviewInfrastructure():null;e&&this._scene.add(e);try{t()}finally{e?.removeFromParent(),i?.()}}renderViewCube(t){if(!this._threeSurfaceShowing||this._navigation==="hidden"||this._cameraView)return;const e=t.domElement.clientWidth,i=t.domElement.clientHeight,s=this._vcSize,n=this._vcDir.subVectors(this.freeCamera.position,this.orbitControls.target).normalize();this._vcCamera.position.copy(n.multiplyScalar(4)),this._vcCamera.up.copy(this.freeCamera.up),this._vcCamera.lookAt(0,0,0),this._syncOrientationGizmoDepth();const r=this._vcOrigin(e,i,this._chromeInsetPx),a=r.left,l=i-s-r.top,c=t.autoClear;try{t.setScissorTest(!0),t.setViewport(a,l,s,s),t.setScissor(a,l,s,s),t.clear(!1,!0,!1),t.autoClear=!1,t.render(this._vcScene,this._vcCamera)}finally{t.autoClear=c,t.setScissorTest(!1),t.setViewport(0,0,e,i)}}renderCameraPreview(t,e,i){if(!e||!i||this._cameraView)return;const s=t.domElement.clientWidth,n=t.domElement.clientHeight,r=t.domElement.getBoundingClientRect(),a=i.getBoundingClientRect(),l=Math.round(a.left-r.left),c=Math.round(r.bottom-a.bottom),d=Math.max(1,Math.round(a.width)),h=Math.max(1,Math.round(a.height));if(l>=s||c>=n||l+d<=0||c+h<=0)return;const f=this._suspendPreviewInfrastructure(),u=t.getClearColor(this._previewClearColor),p=t.getClearAlpha();try{t.setScissorTest(!0),t.setViewport(l,c,d,h),t.setScissor(l,c,d,h),t.setClearColor(1118740,1),t.clear(),t.render(this._scene,e)}finally{t.setScissorTest(!1),t.setViewport(0,0,s,n),t.setClearColor(u,p),f()}}get isFlying(){return this._flyActive}_inputDisconnected=!1;disconnectInput(){if(!this._inputDisconnected){this._inputDisconnected=!0,this._publishPickContext&&ia(null),window.removeEventListener("keydown",this._onFlyKeyDown),window.removeEventListener("keyup",this._onFlyKeyUp),this._interactionElement.removeEventListener("pointerdown",this._onFlyPointerDown),this._canvas.removeEventListener("pointerdown",this._onAltOrbitStart,{capture:!0}),window.removeEventListener("pointerup",this._onAltOrbitRelease,{capture:!0}),window.removeEventListener("pointercancel",this._onAltOrbitRelease,{capture:!0}),window.removeEventListener("keydown",this._onSnapHoldKey),window.removeEventListener("keyup",this._onSnapHoldKey),this._interactionElement.removeEventListener("pointerup",this._onFlyPointerUp),this._interactionElement.removeEventListener("pointermove",this._onFlyPointerMove),this._interactionElement.removeEventListener("wheel",this._onFlyWheel),this._interactionElement.removeEventListener("wheel",this._onTrackpadWheel),this._canvas.removeEventListener("pointerdown",this._onPointerDown),this._interactionElement.removeEventListener("pointermove",this._onPointerMove),this._onInteractionPointerUp&&this._interactionElement.removeEventListener("pointerup",this._onInteractionPointerUp),this._onInteractionDblClick&&this._interactionElement.removeEventListener("dblclick",this._onInteractionDblClick),this._canvas.removeEventListener("dragover",this._onDragOver),this._canvas.removeEventListener("dragleave",this._onDragLeave),this._canvas.removeEventListener("drop",this._onDrop),this.orbitControls.dispose();for(const t of this._allGizmos())t.dispose()}}_applyViewportLook(t){this._lookGridHex=t.grid??10066329;const e=this.grid.material.uniforms.uGrazingFade;if(e&&(e.value=t.background!==null?1:0),this._paintLookGrid(),this._lookAxisHexes=[t.axisX,t.axisY,t.axisZ],this._axisLines&&(this._axisLines.material.linewidth=t.axisLineWidth??2),this._verticalAxisLine&&(this._verticalAxisLine.material.linewidth=t.axisLineWidth??2),this._rebuildAxisLines(),t.background!==null){const i=this._scene.background,s=i===null||i instanceof D&&[this._lookBackgroundHex,t.background].includes(i.getHex());this._lookBackgroundHex=t.background,s&&this._paintLookBackground()}else this._lookBackgroundHex=null}bindPresentation(t,e){this._presentation?.stop();const i=new dl(this._scene),s=i.roots();this._editorObjects.push(...s),Ar(t,e);const n=()=>{const l=al(t);this._renderer&&i.apply(l,this._renderer,void 0,{tone:!1,sky:!1,floor:!1}),this.setStageFunction(l.world,l.interaction),this.setSelectionMarks(l.overlays.selection),this.setGridMajorEvery(l.overlays.grid.majorEvery),this.setAxisLines(l.overlays.axes),this.setNavigation(l.overlays.navigation),this.setGridVisible(l.overlays.grid.visible),ct()},r=ol(n),a={rig:i,stop:()=>{r(),i.dispose(),this._editorObjects=this._editorObjects.filter(c=>!s.includes(c)),this._presentation===a&&(this._presentation=null);const l=this._lightRig&&!this._store.isAdoptedSceneActive;this._editorAmbient.visible=l,this._editorDirLight.visible=l}};return this._presentation=a,this._editorAmbient.visible=!1,this._editorDirLight.visible=!1,n(),a.stop}setSelectionMarks(t){const e=this._selectionMarks;e.outline===t.outline&&e.wire===t.wire&&e.box===t.box||(this._selectionMarks={outline:t.outline,wire:t.wire,box:t.box},this._syncBoxHelpers())}setGridMajorEvery(t){const e=this.grid.material.uniforms.uMajorEvery;e&&Number.isFinite(t)&&t>=1&&(e.value=t)}_gridMajorContrast=1;_applyGridLines(t){const e=this.grid.material.uniforms;e.uLineWidth&&(e.uLineWidth.value=t.lineWidth),e.uMajorWidth&&(e.uMajorWidth.value=t.majorWidth),this._gridMajorContrast=t.majorContrast,this._paintLookGrid()}_paintLookGrid(){const t=this._lookGridHex;if(t===null)return;const e=this._lookBackgroundHex??4144959,i=a=>{const l=t>>a&255,c=e>>a&255;return Math.round(Math.min(255,Math.max(0,c+(l-c)*this._gridMajorContrast)))},s=i(16)<<16|i(8)<<8|i(0),n=Ia(t,this._renderer),r=Ia(s,this._renderer);this.grid.material.uniforms.uColor?.value?.copy(n),this.grid.material.uniforms.uMajorColor?.value?.copy(r)}_rebuildAxisLines(){const t=this._axisLines;if(!t)return;const e=this._stageAxisFrame,i=this._stageAxes,s=[0,1,2].filter(l=>{const c=e[l][0];return i==="floor"?l!==1:["x","y","z"].some((d,h)=>h===c&&i[d])});if(this._axesWanted=s.length>0,t.visible=this.grid.visible&&this._axesWanted,!this._axesWanted)return;const n=l=>{const c=[],d=[];for(const f of l){const u=e[f][0],p=this._lookAxisHexes[u],m=p==null?this._gizmoAxisColor(u):new D(p);c.push(...Ua(f));for(let y=0;y<Ur*2;y++)d.push(m.r,m.g,m.b)}const h=new Pn;return h.setPositions(c),h.setColors(d),h},r=s.filter(l=>l!==1),a=s.includes(1);if(t.material.visible=r.length>0,r.length>0&&(t.geometry.dispose(),t.geometry=n(r)),a&&!this._verticalAxisLine){const l=t.material;this._verticalAxisLine=new Cn(n([1]),new zn({vertexColors:!0,linewidth:l.linewidth,transparent:!0,opacity:1,depthWrite:!1,toneMapped:!1})),this._verticalAxisLine.layers.set(J),t.add(this._verticalAxisLine)}else a&&this._verticalAxisLine&&(this._verticalAxisLine.geometry.dispose(),this._verticalAxisLine.geometry=n([1]));this._verticalAxisLine&&(this._verticalAxisLine.visible=a)}setAxisLines(t){t===this._stageAxes||typeof t=="object"&&typeof this._stageAxes=="object"&&t.x===this._stageAxes.x&&t.y===this._stageAxes.y&&t.z===this._stageAxes.z||(this._stageAxes=typeof t=="object"?{x:t.x,y:t.y,z:t.z}:t,this._rebuildAxisLines())}_paintLookBackground(){if(this._lookBackgroundHex===null)return;const t=this._scene.background;t instanceof D&&t.getHex()===this._lookBackgroundHex||(this._scene.background=new D(this._lookBackgroundHex))}_syncLookBackground(){this._renderer&&(this._renderer.toneMapping===this._lookToneMapping&&this._renderer.toneMappingExposure===this._lookExposure||(this._paintLookGrid(),this._lookToneMapping=this._renderer.toneMapping,this._lookExposure=this._renderer.toneMappingExposure))}dispose(){this._disposed=!0,this._unsubscribeSelectionTheme(),this._verticalAxisLine&&(this._verticalAxisLine.geometry.dispose(),this._verticalAxisLine.material.dispose(),this._verticalAxisLine=null),this._axisLines&&(this._scene.remove(this._axisLines),this._axisLines.geometry.dispose(),this._axisLines.material.dispose(),this._axisLines=null),this.clearCameraView(),this._sparkRenderer&&(this._scene.remove(this._sparkRenderer),Pc(this._sparkRenderer),this._sparkRenderer=null),this.disconnectInput(),this._hideDropOverlay();for(const t of this._helpers.values())this._scene.remove(t);this._helpers.clear();for(const t of this._boxHelpers.values())this._scene.remove(t),t.geometry.dispose(),t.material.dispose();this._boxHelpers.clear();for(const t of this._reflectionProbeHelpers.values())t.dispose();this._reflectionProbeHelpers.clear();for(const t of this._triggerVolumeHelpers.values())t.dispose();this._triggerVolumeHelpers.clear();for(const t of this._constraintHelpers.values())t.dispose();this._constraintHelpers.clear();for(const{helper:t}of this._cameraHelpers.values())t.dispose();this._cameraHelpers.clear(),Oa(this._spatialHandleRoots),this._spatialHandleRoots=[],this._spatialHandleMeshes=[]}_ensureSparkRenderer(){if(!this._renderer||this._sparkRenderer||this._sparkRendererLoading||this._sparkRendererFailed)return;const t=performance.now();zc(this._lastSparkDiscoveryAt,t)&&(this._lastSparkDiscoveryAt=t,Ac(this._scene)&&(this._sparkRendererLoading=!0,ri(async()=>{const{SparkRenderer:e}=await import("./spark.module-gG1EsWx8.js");return{SparkRenderer:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(({SparkRenderer:e})=>{if(this._disposed||!this._renderer)return;const i=new e({renderer:this._renderer,enableLod:!1});i.traverse(s=>Dt(s,"engineInternal",!0)),this._sparkRenderer=i,ct()}).catch(e=>{this._sparkRendererFailed=!0,console.error("Failed to install SparkRenderer in the editor viewport.",e)}).finally(()=>{this._sparkRendererLoading=!1})))}_buildOrientationGizmo(){if(this._vcScene!==void 0){for(const t of[...this._vcScene.children]){this._vcScene.remove(t);const e=t;e.isSprite||e.geometry?.dispose();const i=e.material;i?.map?.dispose(),i?.dispose()}this._vcBalls.length=0,this._vcStalks.length=0,this._vcSolids.length=0,this._vcClickTargets.length=0,this._initOrientationGizmo()}}_initOrientationGizmo(){const t=this._gizmoLook.navigationForm;if(t!=="balls"){this._initNavigationForm(t);return}const e=Qe/3,i=Nr/e,s=uf/e,n=Hr/e/2,r=[new w(1,0,0),new w(0,1,0),new w(0,0,1)],a=new be(i*.6,8,8),l=new vt({visible:!1});for(let c=0;c<3;c++){const[d,h]=this._stageAxisFrame[c],f=this._gizmoLook.navigation??this._gizmoLook.axes,u=f===null?Da[d]:new D(f[d]),p=Na[d],m=r[c].clone().multiplyScalar(h),y=new T(new Et(n,n,s,8),new vt({color:u,transparent:!0,depthTest:!1}));y.position.copy(m).multiplyScalar(s/2),y.quaternion.setFromUnitVectors(new w(0,1,0),m),this._vcScene.add(y),this._vcStalks.push({mesh:y,direction:m.clone()});for(const _ of[1,-1]){const v=m.clone().multiplyScalar(_),S=new Or(new Zo({map:hf(u,_>0?p:null),transparent:!0,depthTest:!1}));S.position.copy(v).multiplyScalar(s),S.scale.setScalar(i),this._vcScene.add(S),this._vcBalls.push({sprite:S,direction:v.clone(),positive:_>0});const x=new T(a,l);x.position.copy(S.position),Dt(x,"vcDirIdx",c*2+(h*_>0?0:1)),this._vcScene.add(x),this._vcClickTargets.push(x)}}}_initNavigationForm(t){const e=Qe/3,i=new w(0,1,0),s=[new w(1,0,0),new w(0,1,0),new w(0,0,1)],n=this._gizmoLook.navigation??this._gizmoLook.axes,r=(a,l,c,d)=>{const h=new Or(new Zo({map:cf(a,l),transparent:!0,depthTest:!1}));h.position.copy(c),h.scale.setScalar(d/e),h.renderOrder=200,this._vcScene.add(h)};for(let a=0;a<3;a++){const[l,c]=this._stageAxisFrame[a],d=n===null?Da[l]:new D(n[l]),h=Na[l],f=s[a].clone().multiplyScalar(c);if(t==="triad"){const u=this._gizmoLook.navigationSize??1,p=24*u/e,m=Hr*Math.sqrt(u)/e/2,y=new T(new Et(m,m,p,6),new vt({color:d,transparent:!0,depthTest:!1}));y.position.copy(f).multiplyScalar(p/2),y.quaternion.setFromUnitVectors(i,f),this._vcScene.add(y),this._vcSolids.push({mesh:y,direction:f.clone()}),r(d,h,f.clone().multiplyScalar(p+7*u/e),12*u);continue}for(const u of[1,-1]){const p=f.clone().multiplyScalar(u),m=new T(new td(6/e,15/e,20),new vt({color:u>0?d:new D(14277081),transparent:!0,depthTest:!1}));m.position.copy(p).multiplyScalar(19/e),m.quaternion.setFromUnitVectors(i,p.clone().negate()),Dt(m,"vcDirIdx",a*2+(c*u>0?0:1)),this._vcScene.add(m),this._vcSolids.push({mesh:m,direction:p.clone()}),this._vcClickTargets.push(m),u>0&&r(d,h.toLowerCase(),p.clone().multiplyScalar(34/e),12)}}if(t==="cones"){const a=new T(new ft(11/e,11/e,11/e),new vt({color:12434877,transparent:!0,depthTest:!1}));a.renderOrder=50,this._vcScene.add(a)}}_syncOrientationGizmoDepth(){const t=Qe/3,e=this._vcDir.copy(this._vcCamera.position).normalize();for(const{sprite:i,direction:s,positive:n}of this._vcBalls){const r=(s.dot(e)+1)/2,a=i.material;a.opacity=n?1:.56+r*.44,i.scale.setScalar((Nr+pf*r)/t),i.renderOrder=10+Math.round(r*100)}for(const{mesh:i,direction:s}of this._vcStalks){const n=(s.dot(e)+1)/2;i.material.opacity=.35+n*.65,i.renderOrder=Math.round(n*100)}for(const{mesh:i,direction:s}of this._vcSolids)i.renderOrder=Math.round((s.dot(e)+1)/2*100)}_isOverViewCube(t,e){if(this._navigation!=="interactive"||this._gizmoLook.navigationForm==="triad")return!1;const i=this._canvas.getBoundingClientRect(),s=t-i.left,n=e-i.top,{left:r,top:a}=this._vcOrigin(i.width,i.height,this._chromeInsetPx);return s>=r&&s<=r+this._vcSize&&n>=a&&n<=a+this._vcSize}_vcOrigin(t,e,i){return this._gizmoLook.navigationCorner==="bottom-left"?{left:4+i,top:e-this._vcSize-48-i}:{left:t-this._vcSize-this._vcMarginRight-i,top:this._vcMarginTop+i}}setGridVisible(t){t!==this._presentationGrid&&(this._presentationGrid=t,this._applyGridVisibility())}_applyGridVisibility(){this.grid.visible=this._presentationGrid&&this._threeSurfaceShowing,this._axisLines&&(this._axisLines.visible=this.grid.visible&&this._axesWanted),ct()}setNavigation(t){t!==this._navigation&&(this._navigation=t,ct())}_handleViewCubeClick(t){if(!this._isOverViewCube(t.clientX,t.clientY))return!1;const e=this._canvas.getBoundingClientRect(),i=t.clientX-e.left,s=t.clientY-e.top,{left:n,top:r}=this._vcOrigin(e.width,e.height,this._chromeInsetPx),a=(i-n)/this._vcSize*2-1,l=-((s-r)/this._vcSize*2-1);this._vcRaycaster.setFromCamera(new Ht(a,l),this._vcCamera);const c=this._vcRaycaster.intersectObjects(this._vcClickTargets);if(c.length===0)return!0;const d=Ct(c[0].object,"vcDirIdx"),h=Kp[d],f=new w().subVectors(this.freeCamera.position,this.orbitControls.target).normalize();return this._snapDist=this.freeCamera.position.distanceTo(this.orbitControls.target),this._snapQ1.setFromUnitVectors(new w(0,0,1),f),this._snapQ2.setFromUnitVectors(new w(0,0,1),h),this._snapStartTime=performance.now(),this._snapAnimating=!0,!0}_flushGizmoToStoreLive(){this._skipNextSync=!0;const t=this._authoring(),e=(s,n)=>{s&&Io(t,s,{position:n.position.toArray(),rotation:n.quaternion.toArray(),scale:n.scale.toArray()})},i=this._activeGizmo.object;i&&i!==this._pivotDummy&&e(this._attachedAuthoringId??this._authoringIdForObject(i),i);for(const{id:s,obj:n}of this._otherDragObjects)e(s,n);for(const{id:s,obj:n}of this._allDragObjects)e(s,n);for(const{id:s,obj:n}of this._preservedChildObjects)e(s,n)}_preparePreservedChildren(t){if(!this._store.preserveChildrenTransform)return[];const e=this._authoring(),i=new Set(t),s=new Map;for(const n of i){const r=this._preservedChildrenForParent(e,n,i,s);if(typeof r=="string")return Yt(r),[];for(const a of r)s.set(a.id,a)}return[...s.values()]}_preservedChildrenForParent(t,e,i,s){const n=[];for(const r of t.hierarchy.node(e)?.childIds??[]){if(i.has(r)||s.has(r))continue;const a=this._objectForAuthoringId(r);if(!a?.parent)continue;const l=this._unwritableTransformChannel(t,r);if(l){const c=t.hierarchy.node(r)?.label??r;return`Preserve Children Transform needs writable ${l} on ${c}. The parent will transform normally.`}a.updateWorldMatrix(!0,!1),n.push({id:r,obj:a,worldMatrix:a.matrixWorld.clone()})}return n}_unwritableTransformChannel(t,e){return["position","rotation","scale"].find(i=>!(t.transforms?.editability?.(e,i).writable??!1))}_restorePreservedChildren(){const t=new Ci;for(const e of this._preservedChildObjects){const i=e.obj.parent;i&&(i.updateWorldMatrix(!0,!1),t.copy(i.matrixWorld).invert().multiply(e.worldMatrix),t.decompose(e.obj.position,e.obj.quaternion,e.obj.scale),e.obj.updateMatrix(),e.obj.updateWorldMatrix(!1,!0))}}_belongsToRoots(t,e){let i=t;for(;i;){if(e.has(i))return!0;i=i.parent}return!1}_floorSnapPosition(t,e){t.updateWorldMatrix(!0,!0);const i=$e(t);if(i.isEmpty())return null;const s=Math.min((i.max.x-i.min.x)*.1,.05),n=Math.min((i.max.z-i.min.z)*.1,.05),r=[[(i.min.x+i.max.x)/2,(i.min.z+i.max.z)/2],[i.min.x+s,i.min.z+n],[i.max.x-s,i.min.z+n],[i.min.x+s,i.max.z-n],[i.max.x-s,i.max.z-n]],a=new $t;a.layers.enableAll();const l=i.min.y+Math.max((i.max.y-i.min.y)*.001,.001);let c=Number.NEGATIVE_INFINITY;for(const[f,u]of r){a.set(new w(f,l,u),new w(0,-1,0));const p=a.intersectObjects(this._scene.children,!0).find(m=>!this._belongsToRoots(m.object,e)&&!he(m.object)&&m.point.y<=l);p&&(c=Math.max(c,p.point.y))}if(!Number.isFinite(c))return null;const d=c-i.min.y;if(Math.abs(d)<1e-6)return null;const h=t.getWorldPosition(new w);return h.y+=d,t.parent?(t.parent.updateWorldMatrix(!0,!1),t.parent.worldToLocal(h)):h}snapSelectionToFloor(){const t=this._authoring(),e=t.transforms;if(!e){Yt("This document does not expose writable transforms.");return}const i=[...this._store.selectedEntityIds].map(l=>({id:l,obj:this._objectForAuthoringId(l)})).filter(l=>!!l.obj&&(e.editability?.(l.id,"position").writable??!0)),s=new Set(i.map(({obj:l})=>l)),n=i.filter(({obj:l})=>{let c=l.parent;for(;c;){if(s.has(c))return!1;c=c.parent}return!0});if(n.length===0){Yt("Select an object with a writable position first.");return}const r=new Set(n.map(({obj:l})=>l)),a=[];for(const l of n){const c=this._floorSnapPosition(l.obj,r);c&&a.push({...l,position:c})}if(a.length===0){Yt("No solid scene surface was found beneath the selection.");return}for(const{id:l}of a)ko(t,l);for(const{obj:l,position:c}of a)l.position.copy(c);this._skipNextSync=!0;for(const{id:l,obj:c}of a)Io(t,l,{position:c.position.toArray(),rotation:c.quaternion.toArray(),scale:c.scale.toArray()});for(const{id:l}of a)Ro(t,l);this.syncFromStore()}_applySurfaceSnap(t,e){const i=new Set,s=this._attachedAuthoringId??this._authoringIdForObject(t);s&&i.add(s);for(const{id:c}of e)i.add(c);const n=[];for(const[c,d]of this._objectMap)i.has(c)||n.push(d);if(n.push(this.grid),n.length===0){this._surfaceSnapIndicator.visible=!1;return}const r=t.position.clone();r.y+=50,this._surfaceSnapRaycaster.set(r,new w(0,-1,0)),this._surfaceSnapRaycaster.far=200;const l=this._surfaceSnapRaycaster.intersectObjects(n,!0).find(c=>c.object===this.grid||!he(c.object));if(l){const c=l.point,d=c.y,h=d-t.position.y;t.position.y=d;for(const{obj:u}of e)u.position.y+=h;this._surfaceSnapIndicator.position.copy(c),this._surfaceSnapIndicator.position.y+=.01;const f=l.face?.normal;if(f){const u=f.clone().transformDirection(l.object.matrixWorld);this._surfaceSnapIndicator.quaternion.setFromUnitVectors(new w(0,1,0),u)}this._surfaceSnapIndicator.visible=!0}else this._surfaceSnapIndicator.visible=!1}_collectVertices(t){const e=[];for(const[s,n]of this._objectMap)t.has(s)||n.traverse(r=>{if(he(r))return;const a=r;if(!a.isMesh||!a.geometry)return;const l=a.geometry.getAttribute("position");if(!l)return;const c=Math.min(l.count,1e3),d=a.matrixWorld;for(let h=0;h<c;h++){const f=new w(l.getX(h),l.getY(h),l.getZ(h));f.applyMatrix4(d),e.push(f)}});return e}_applyVertexSnap(t,e){const i=t.position,s=i.clone().project(this.renderCamera),n=this._canvas.getBoundingClientRect(),r=(s.x+1)/2*n.width,a=(-s.y+1)/2*n.height;let l=this._vertexSnapThreshold,c=null;for(const d of this._vertexSnapTargets){const h=d.clone().project(this.renderCamera);if(h.z>1)continue;const f=(h.x+1)/2*n.width,u=(-h.y+1)/2*n.height,p=r-f,m=a-u,y=Math.sqrt(p*p+m*m);y<l&&(l=y,c=d)}if(c){const d=c.clone().sub(i);t.position.copy(c);for(const{obj:f}of e)f.position.add(d);this._vertexSnapIndicator.position.copy(c),this._vertexSnapIndicator.visible=!0;const h=c.distanceTo(this.renderCamera.position);this._vertexSnapIndicator.scale.setScalar(h*.008)}else this._vertexSnapIndicator.visible=!1}_flushGizmoToStore(){this._flushGizmoToStoreLive();const t=this._activeTransformEditIds;this._activeTransformEditIds=[],this._otherDragObjects=[],this._allDragObjects=[],this._preservedChildObjects=[];const e=this._authoring();for(const i of t)Ro(e,i)}consumeSkipSync(){return this._skipNextSync?(this._skipNextSync=!1,!0):!1}_applyGizmoSize(){if(this.transformControls===void 0)return;const t=this._lookGizmoSizePx,e=Math.max(1,this._canvas.clientHeight),i=t===null?null:2*t,s=i===null?1:this.freeCamera instanceof Si?4*i/e:i/(.2375*e);for(const n of this._allGizmos())n.size=s}_dropNegativeAxisHandles(t,e){const i=t.children.find(n=>n.isTransformControlsGizmo);if(!i)return;const s={X:new w(1,0,0),Y:new w(0,1,0),Z:new w(0,0,1)};for(const n of e)for(const r of[i.gizmo[n],i.picker[n]])if(r)for(const a of[...r.children]){const l=s[a.name];if(l===void 0)continue;const c=a;if(!c.geometry)continue;c.geometry.computeBoundingBox();const d=c.geometry.boundingBox;d&&d.getCenter(new w).dot(l)<0&&r.remove(a)}}_axisColorMap(){const t=n=>this._gizmoAxisColor(this._stageAxisFrame[n][0]),e=t(0),i=t(1),s=t(2);return{X:e,Y:i,Z:s,XY:s,YZ:e,XZ:i}}_readLookStage(t){this._applyGizmoAxisFrame(),this._buildOrientationGizmo()}setStageFunction(t,e){this._stageBoxSelect=e.boxSelect;const i=e.transformHandles;(i.scale!==this._transformHandles.scale||i.viewRotate!==this._transformHandles.viewRotate||i.freeMove!==this._transformHandles.freeMove)&&(this._transformHandles={scale:i.scale,viewRotate:i.viewRotate,freeMove:i.freeMove},this._syncCombinedGizmoHalves(),ct());const s=t.upAxis==="z"?t.handedness==="left"?sf:ef:Ba;s!==this._stageAxisFrame&&(this._stageAxisFrame=s,this._applyGizmoAxisFrame(),this._buildOrientationGizmo(),this._rebuildAxisLines())}_applyGizmoAxisFrame(){if(this.transformControls===void 0)return;const t=this._stageAxisFrame.map(([,a])=>a),e=[0,1,2].map(a=>t[a]===this._appliedAxisSigns[a]?1:-1),i=e.some(a=>a===-1),s=this._axisColorMap(),n={X:this._gizmoAxisColor(0),Y:this._gizmoAxisColor(1),Z:this._gizmoAxisColor(2),XY:this._gizmoAxisColor(2),YZ:this._gizmoAxisColor(0),XZ:this._gizmoAxisColor(1)},r=(a,l,c,d,h)=>{a&&a.traverse(f=>{const u=f;c&&u.geometry&&u.geometry.scale(e[0],e[1],e[2]),d&&u.material&&!Array.isArray(u.material)&&!u.userData.vgaiOwnMaterial&&(u.material=u.material.clone(),u.userData.vgaiOwnMaterial=!0);const p=u.material;if(!p||Array.isArray(p))return;c&&(p.side=ei);const m=l[f.name];if(m&&p.color){if(h){const y=p.userData.vgaiBaseOpacity??=p.opacity;p.opacity=y*(this._gizmoLook.opacity??1),p._opacity=void 0}p.color.copy(m),p._color=void 0}})};for(const a of this._allGizmos()){const l=a.getHelper().children.find(c=>c.isTransformControlsGizmo);if(l)for(const c of["gizmo","picker","helper"]){const d=c==="gizmo";r(l[c]?.translate,s,i,!1,d),r(l[c]?.rotate,s,!1,!1,d),r(l[c]?.scale,n,!1,!0,d)}}i&&(this._appliedAxisSigns=t)}_gizmoAxisColor(t){const e=this._gizmoLook.axes;return e===null?new D().setRGB(...tf[t],Hs):new D(e[t])}_installGizmoHighlight(t){const e=t.getHelper().children.find(s=>s.isTransformControlsGizmo);if(!e)return;const i=e.updateMatrixWorld.bind(e);e.updateMatrixWorld=s=>{i(s);const n=this._store.transformMode==="combined",r=e.mode==="translate"&&!this._transformHandles.freeMove?"XYZ":n&&e.mode==="rotate"&&!this._transformHandles.viewRotate?"E":null;if(r!==null)for(const d of[e.gizmo,e.picker])for(const h of d[e.mode]?.children??[])h.name===r&&(h.visible=!1);const a=this._gizmoLook,l=e.axis;if(!e.enabled||!l||a.hover===null&&a.axes===null&&a.highlightSaturation===null&&a.highlightValue===null)return;const c=e.dragging?a.drag??a.hover:a.hover;for(const d of e.gizmo[e.mode]?.children??[]){if(d.name!==l&&!l.split("").some(y=>d.name===y))continue;const h=d.material;if(!h||Array.isArray(h)||!h.color)continue;if(c!==null){h.color.setHex(c);continue}const f=(h._color??h.color).clone().convertLinearToSRGB(),u=rf(f),p=u.s*(a.highlightSaturation??1),m=a.highlightValue??u.v;of(u.h,p,m,h.color).convertSRGBToLinear()}}}_applyGizmoArrows(){if(this.transformControls===void 0)return;this._applyGizmoRings();const t={length:this._gizmoLook.arrowLength??1.2,head:this._gizmoLook.arrowHead??1},e=this._appliedArrow;if(t.length===e.length&&t.head===e.head)return;const i=.5,s=.1,n=f=>i*f.length-s*f.head;if(n(t)<=.05)return;const r=n(t)/n(e),a=t.head/e.head,l=t.length/e.length,c=this.transformControls.getHelper().children.find(f=>f.isTransformControlsGizmo);if(!c)return;const d={X:0,Y:1,Z:2},h=(f,u)=>[0,1,2].map(p=>p===f?u:1);for(const f of c.gizmo.translate?.children??[]){const u=d[f.name],p=f.geometry;if(u===void 0||!p)continue;if(!(p.parameters?.radiusTop===0)){p.scale(...h(u,r));continue}p.computeBoundingBox();const _=p.boundingBox,v=[_.min.x,_.min.y,_.min.z][u],S=[_.max.x,_.max.y,_.max.z][u],x=Math.abs(v)<Math.abs(S)?v:S,C=[0,0,0];C[u]=-x,p.translate(...C),p.scale(a,a,a),C[u]=x*r,p.translate(...C)}for(const f of c.picker.translate?.children??[]){const u=d[f.name],p=f.geometry;u===void 0||!p||p.scale(...h(u,l))}this._appliedArrow=t}_applyGizmoRings(){const t=this._gizmoLook.ringWidth??1;if(t<=0||t===this._appliedRingWidth)return;const e=t/this._appliedRingWidth,i=new w,s=new w,n=new w;for(const r of[this.transformControls,this._auxRotateControls]){const a=r.getHelper().children.find(l=>l.isTransformControlsGizmo);for(const l of a?.gizmo.rotate?.children??[]){const c=l.geometry;if(!["X","Y","Z"].includes(l.name)||!c||c.type!=="TorusGeometry")continue;const d=c.parameters.radius;c.computeBoundingBox(),c.boundingBox.getSize(n);const h=n.x<=n.y&&n.x<=n.z?0:n.y<=n.z?1:2,f=c.getAttribute("position");for(let u=0;u<f.count;u++)i.fromBufferAttribute(f,u),s.copy(i).setComponent(h,0),s.lengthSq()!==0&&(s.setLength(d),i.sub(s).multiplyScalar(e).add(s),f.setXYZ(u,i.x,i.y,i.z));f.needsUpdate=!0,c.computeBoundingSphere()}}this._appliedRingWidth=t}_patchGizmo(t){const e=this._axisColorMap(),i={XY:[-.075,-.075,0],YZ:[0,-.075,-.075],XZ:[-.075,0,-.075]};t.traverse(s=>{const n=s,r=e[s.name];if(r&&n.material){const l=n.material;l.color&&l.color.copy(r)}const a=i[s.name];a&&n.geometry&&n.geometry.translate(a[0],a[1],a[2])})}_patchCombinedScaleGizmo(t){const i=t.children.find(a=>a.isTransformControlsGizmo);if(!i)return;const s={X:new w(1,0,0),Y:new w(0,1,0),Z:new w(0,0,1)},n=.54+.55,r=.3;for(const[a,l]of[[i.gizmo.scale,!1],[i.picker.scale,!0]])if(a)for(const c of[...a.children]){const d=c,h=s[c.name],f=h!==void 0&&d.geometry?.type==="CylinderGeometry"&&d.geometry.parameters.radiusTop<.05;if(h===void 0||f){a.remove(c);continue}d.geometry.computeBoundingBox();const u=d.geometry.boundingBox;if(!u)continue;const p=Math.sign(u.getCenter(new w).dot(h))||1;if(l){const y=h.clone().multiplyScalar(p*n);d.geometry.dispose(),d.geometry=new ft(r,r,r).translate(y.x,y.y,y.z);continue}const m=h.clone().multiplyScalar(p*.55);d.geometry.translate(m.x,m.y,m.z)}}_projectToScreen(t){const e=new w;t.getWorldPosition(e),e.project(this.renderCamera);const i=this._canvas.getBoundingClientRect();return new Ht((e.x+1)/2*i.width+i.left,(-e.y+1)/2*i.height+i.top)}static _FLY_KEYS=new Set(["w","a","s","d","q","e"]);_enterFlyMode(){this._flyActive||this._cameraViewMode!=="view"&&(this._flyActive=!0,this._snapAnimating=!1,this.orbitControls.enabled=!1,this._flyEuler.setFromQuaternion(this.renderCamera.quaternion,"YXZ"),this.orbitControls.dispatchEvent({type:"start"}),this._canvas.requestPointerLock?.())}_exitFlyMode(){if(!this._flyActive)return;this._flyActive=!1,this._flyKeys.clear(),this.orbitControls.enabled=this._cameraViewMode!=="view",document.exitPointerLock();const t=this.renderCamera,e=new w(0,0,-1).applyQuaternion(t.quaternion),i=t.position.distanceTo(this.orbitControls.target);this.orbitControls.target.copy(t.position).add(e.multiplyScalar(Math.max(i,5))),this.orbitControls.dispatchEvent({type:"end"})}_updateFlyCamera(t){if(!this._flyActive||this._flyKeys.size===0)return;const e=this.renderCamera,i=this._flySpeed*(this._flyKeys.has("shift")?3:1),s=new w(0,0,-1).applyQuaternion(e.quaternion),n=new w(1,0,0).applyQuaternion(e.quaternion),r=new w;this._flyKeys.has("w")&&r.add(s),this._flyKeys.has("s")&&r.sub(s),this._flyKeys.has("d")&&r.add(n),this._flyKeys.has("a")&&r.sub(n),this._flyKeys.has("e")&&(r.y+=1),this._flyKeys.has("q")&&(r.y-=1),r.lengthSq()>0&&(r.normalize().multiplyScalar(i*t),e.position.add(r),this.orbitControls.dispatchEvent({type:"change"}))}_onFlyKeyDown=t=>{if(!this._rightMouseDown||t.target instanceof HTMLInputElement||t.target instanceof HTMLTextAreaElement||t.target instanceof HTMLSelectElement)return;const e=t.key.toLowerCase();if(e==="shift"){this._flyKeys.add("shift");return}eo._FLY_KEYS.has(e)&&(t.preventDefault(),t.stopPropagation(),this._flyKeys.add(e),this._flyActive||this._enterFlyMode())};_onFlyKeyUp=t=>{const e=t.key.toLowerCase();if(e==="shift"){this._flyKeys.delete("shift");return}this._flyKeys.delete(e)};_onFlyPointerDown=t=>{t.button===2&&(this._rightMouseDown=!0)};_onFlyPointerUp=t=>{t.button===2&&(this._rightMouseDown=!1,this._flyActive&&this._exitFlyMode())};_onFlyPointerMove=t=>{if(!this._flyActive)return;const e=.002;this._flyEuler.y-=t.movementX*e,this._flyEuler.x-=t.movementY*e,this._flyEuler.x=Math.max(-Math.PI/2+.01,Math.min(Math.PI/2-.01,this._flyEuler.x)),this.renderCamera.quaternion.setFromEuler(this._flyEuler),this.orbitControls.dispatchEvent({type:"change"})};_onTrackpadWheel=t=>{if(this._flyActive||!this.orbitControls.enabled||t.ctrlKey||Math.abs(t.deltaX)<.5&&!t.shiftKey)return;t.preventDefault(),t.stopImmediatePropagation();const e=this._interactionElement.clientHeight||1,i=this.camera.position.distanceTo(this.orbitControls.target),s=2*Math.tan(this.camera.fov/2*Math.PI/180)*i/e,n=t.deltaMode===1?16:1,r=d=>Math.sign(d)*Math.min(Math.abs(d*n),30),a=new w().setFromMatrixColumn(this.camera.matrix,0),l=new w().setFromMatrixColumn(this.camera.matrix,1),c=a.multiplyScalar(r(t.deltaX)*s).add(l.multiplyScalar(-r(t.deltaY)*s));this.camera.position.add(c),this.orbitControls.target.add(c),this.orbitControls.update()};_onFlyWheel=t=>{if(!this._flyActive)return;t.preventDefault();const e=t.deltaY>0?.85:1.18;this._flySpeed=Math.max(.5,Math.min(100,this._flySpeed*e))};_onPointerDown=t=>{if(this._pointerDownPos.set(t.clientX,t.clientY),this._pointerDownButton=t.button,this._marqueeActive=!1,this._pointerSessionActive=!0,this._constraintControlPointerSession=!1,t.button===0&&!t.altKey){if(this._selectConstraintControlAt(t))return;const e=this._raycastSpatialHandle(t),i=e?Ea(e):null;if(e&&i?.handle.writable){t.stopPropagation(),this._activeSpatialHandle=i,this._spatialHandleDragPoint.copy(e.position),this._orbitEnabledBeforeHandleDrag=this.orbitControls.enabled,this._transformEnabledBeforeHandleDrag=this.transformControls.enabled,this.orbitControls.enabled=!1;for(const r of this._allGizmos())r.enabled=!1;const s=this.renderCamera.getWorldDirection(new w);this._spatialHandleDragPlane.setFromNormalAndCoplanarPoint(s,e.position),this._spatialHandleDragOffset.set(0,0,0);const n=this._spatialHandleWorldPoint(t);n&&this._spatialHandleDragOffset.subVectors(e.position,n),this._canvas.style.cursor="grabbing"}}};_onPointerMove=t=>{if(this._updateEditorHandleInteraction(t)||(this._updateSpatialHandleHover(t),!this._pointerSessionActive)||!(t.buttons&1)||this._pointerDownButton!==0||this._anyGizmoDragging()||this._altDragOrbit)return;const e=t.clientX-this._pointerDownPos.x,i=t.clientY-this._pointerDownPos.y;if(!this._marqueeActive&&Math.sqrt(e*e+i*i)>5){if(this._isOverViewCube(this._pointerDownPos.x,this._pointerDownPos.y))return;this._marqueeActive=!0,this.orbitControls.enabled=!1,this._marqueeDiv||(this._marqueeDiv=document.createElement("div"),Object.assign(this._marqueeDiv.style,{position:"fixed",border:`1px solid ${Gt.accent.default}`,background:Gt.accent.muted,pointerEvents:"none",zIndex:Fo.sticky}),(document.getElementById("editor-chrome-root")??document.body).appendChild(this._marqueeDiv))}if(this._marqueeActive&&this._marqueeDiv){const s=Math.min(this._pointerDownPos.x,t.clientX),n=Math.min(this._pointerDownPos.y,t.clientY),r=Math.abs(t.clientX-this._pointerDownPos.x),a=Math.abs(t.clientY-this._pointerDownPos.y);Object.assign(this._marqueeDiv.style,{left:`${s}px`,top:`${n}px`,width:`${r}px`,height:`${a}px`,display:"block"})}};_onPointerUp=t=>{if(!this._pointerSessionActive)return;if(this._pointerSessionActive=!1,this._activeSpatialHandle){this._finishSpatialHandleDrag(!0);return}if(this._constraintControlPointerSession){this._constraintControlPointerSession=!1;return}if(this._marqueeActive){this._marqueeActive=!1,this.orbitControls.enabled=!0,this._marqueeDiv&&(this._marqueeDiv.style.display="none");const r=Math.min(this._pointerDownPos.x,t.clientX),a=Math.max(this._pointerDownPos.x,t.clientX),l=Math.min(this._pointerDownPos.y,t.clientY),c=Math.max(this._pointerDownPos.y,t.clientY),d=[],h=new w,f=new pe;for(const[u,p]of this._objectMap){if(!p.visible||p.isCamera===!0)continue;if(f.setFromObject(p),f.isEmpty()){const M=this._projectToScreen(p);M.x>=r&&M.x<=a&&M.y>=l&&M.y<=c&&d.push(u);continue}const m=this._stageBoxSelect==="touch",y=this._canvas.getBoundingClientRect();let _=!0,v=Number.POSITIVE_INFINITY,S=Number.NEGATIVE_INFINITY,x=Number.POSITIVE_INFINITY,C=Number.NEGATIVE_INFINITY;for(let M=0;M<8;M++){if(h.set(M&1?f.max.x:f.min.x,M&2?f.max.y:f.min.y,M&4?f.max.z:f.min.z),h.project(this.camera),h.z<-1||h.z>1){if(_=!1,!m)break;continue}const P=y.left+(h.x+1)*y.width/2,z=y.top+(1-h.y)*y.height/2;(P<r||P>a||z<l||z>c)&&(_=!1),v=Math.min(v,P),S=Math.max(S,P),x=Math.min(x,z),C=Math.max(C,z)}const b=v<=S&&S>=r&&v<=a&&C>=l&&x<=c;(m?b:_)&&d.push(u)}if(t.shiftKey)for(const u of d)this._store.addToSelection(u);else Zi(this._authoring(),d);return}if(t.button!==0)return;const e=t.clientX-this._pointerDownPos.x,i=t.clientY-this._pointerDownPos.y;if(Math.sqrt(e*e+i*i)>5||this._anyGizmoDragging()||this._threejsToolContextActive&&this._handleViewCubeClick(t))return;const s=t.shiftKey&&(t.metaKey||t.ctrlKey),n=Ec(this._scopeAuthoring(),()=>this._pickAt(t.clientX,t.clientY,s?"deep":"normal"));s?Zi(this._authoring(),n?[n]:[]):t.shiftKey&&n?this._store.toggleSelection(n):(t.metaKey||t.ctrlKey)&&n?this._store.toggleSelection(n):Zi(this._authoring(),n?[n]:[])};_scopeAuthoring(){return this._standaloneAuthoring?this._authoring():an().panelAuthoring(this._store)}_pickAt(t,e,i){return this._pick?this._pick(t,e):an().pick(this._store,t,e,i)}_onDoubleClick=t=>{if(t.button!==0||this._anyGizmoDragging()||this._marqueeActive||this._threejsToolContextActive&&this._isOverViewCube(t.clientX,t.clientY))return;const e=this._pickAt(t.clientX,t.clientY,"normal");e&&Tc(this._scopeAuthoring(),e,()=>this._pickAt(t.clientX,t.clientY,"normal"))};_raycastGroundPlane(t){const e=this._canvas.getBoundingClientRect(),i=new Ht((t.clientX-e.left)/e.width*2-1,-((t.clientY-e.top)/e.height)*2+1);this.raycaster.setFromCamera(i,this.renderCamera);const s=Lo("three");this._groundPlane.set(s.up==="z"?Zp:qp,-s.groundHeight);const n=new w;return this.raycaster.ray.intersectPlane(this._groundPlane,n)}_showDropOverlay(){if(this._dropOverlay)return;const t=document.createElement("div");Object.assign(t.style,{position:"fixed",inset:"0",pointerEvents:"none",border:`2px dashed ${Gt.accent.default}`,background:Gt.accent.muted,zIndex:Fo.base}),(document.getElementById("editor-chrome-root")??document.body).appendChild(t),this._dropOverlay=t}_hideDropOverlay(){this._dropOverlay&&(this._dropOverlay.remove(),this._dropOverlay=null)}_onDragOver=t=>{t.dataTransfer?.types.includes("application/x-editor-asset")&&(t.preventDefault(),t.dataTransfer.dropEffect="copy",this._showDropOverlay())};_onDragLeave=t=>{this._hideDropOverlay()};_onDrop=t=>{this._hideDropOverlay();const e=t.dataTransfer?.getData("application/x-editor-asset");if(!e)return;t.preventDefault();let i;try{i=JSON.parse(e)}catch{return}const s=Lo("three"),n=this._raycastGroundPlane(t),r=h=>Math.round(h*100)/100,a=s.up==="z"?[r(n?.x??0),r(n?.y??0),s.groundHeight]:[r(n?.x??0),s.groundHeight,r(n?.z??0)],l=this._authoring(),c=l.assetDrop,d=i.component??{kind:"file",name:i.name};if(!c){Qi.warn(`Dropped “${i.name}” was not placed: this document does not accept dropped assets.`,"editor");return}if(i.online){const h=i.online,f=this._onlineAssetResolver;if(!f){Qi.warn(`Dropped “${i.name}” was not placed: this viewport has no online-asset resolver installed.`,"editor");return}Yt(`Downloading ${h.name} from the library…`),f(h).then(u=>{u?(Yt(`${h.name} downloaded — placing it.`),Bo(l,"",u,{position:a})):Yt(`Could not download ${h.name} — see the Console.`)}).catch(()=>{Yt(`Could not download ${h.name} — see the Console.`),Qi.error(`Could not download ${h.name}.`,"asset")});return}Bo(l,"",i.path,{position:a,item:d})}}class vf extends Ft{constructor(t,e){super(),this.bones=t;const i=new Set;for(const a of t){const l=a.parent;l?.isBone&&this.addSegment(l,a,i);for(const c of a.children)c.isBone&&this.addSegment(a,c,i)}this.linePositions=new Float32Array(Math.max(this.segments.length*6,6));const s=new Pn;s.setPositions(this.linePositions),this.lineMaterial=new zn({color:e,linewidth:5,worldUnits:!1,depthTest:!1,depthWrite:!1,toneMapped:!1,alphaToCoverage:!0}),this.lines=new Cn(s,this.lineMaterial),this.lines.onBeforeRender=a=>{a.getSize(this.lineMaterial.resolution)},this.lines.frustumCulled=!1,this.lines.renderOrder=1001,this.add(this.lines),this.pointPositions=new Float32Array(Math.max(t.length*3,3));const n=new De;n.setAttribute("position",new ve(this.pointPositions,3));const r=new ed({color:e,size:11,sizeAttenuation:!1,depthTest:!1,depthWrite:!1,toneMapped:!1});this.points=new gl(n,r),this.points.frustumCulled=!1,this.points.renderOrder=1002,this.add(this.points),this.name="__object3d_document_bone_selection",Er(this,"editorHelper",!0),this.traverse(a=>a.layers.set(J)),this.update()}segments=[];linePositions;pointPositions;lines;lineMaterial;points;worldPosition=new w;setColor(t){this.lineMaterial.color.setHex(t),this.points.material.color.setHex(t)}update(){let t=0;for(const[s,n]of this.segments)s.getWorldPosition(this.worldPosition),this.linePositions.set(this.worldPosition.toArray(),t),n.getWorldPosition(this.worldPosition),this.linePositions.set(this.worldPosition.toArray(),t+3),t+=6;const e=this.lines.geometry.getAttribute("instanceStart");e&&(e.data.needsUpdate=!0),t=0;for(const s of this.bones)s.getWorldPosition(this.worldPosition),this.pointPositions.set(this.worldPosition.toArray(),t),t+=3;const i=this.points.geometry.getAttribute("position");i&&(i.needsUpdate=!0)}dispose(){this.lines.geometry.dispose(),this.lineMaterial.dispose(),this.points.geometry.dispose(),this.points.material.dispose()}addSegment(t,e,i){const s=`${t.uuid}:${e.uuid}`;i.has(s)||(i.add(s),this.segments.push([t,e]))}}const wf="skeletons",Sr=new D(58879),Mr=new D(16756736);function xf(o){const t=o.geometry.getAttribute("color");for(let i=0;i<t.count;i+=2)t.setXYZ(i,Sr.r,Sr.g,Sr.b),i+1<t.count&&t.setXYZ(i+1,Mr.r,Mr.g,Mr.b);t.needsUpdate=!0,o.renderOrder=999;const e=o.material;e.depthTest=!1,e.depthWrite=!1,e.toneMapped=!1,Er(o,"editorHelper",!0),Er(o,"editorHelperType",wf),o.traverse(i=>i.layers.set(J))}const Va=o=>!Ns(o),bf=1,Sf=700,Mf=.001,Cf=Math.PI-.001,Pf=o=>o<.5?4*o*o*o:1-(-2*o+2)**3/2,zf=o=>o;function vi(o,t){return typeof o=="number"&&Number.isFinite(o)?o:t}const ja={mode:"solid",background:"neutral",projection:"perspective",skeleton:!1,bounds:!1};class Af{constructor(t,e,i,s,n,r,a=new D(2106410),l=null){this.documentId=t,this.root=e,this.scene=i,this.renderer=s,this.viewport=n,this.authoring=r,this.neutralBackground=a,this.frameBox=l,this.unsubscribeSelectionTheme=Bn(s.domElement,this.syncSelectionTheme),n.orbitControls.addEventListener("start",this.cancelLookForHuman)}profiler=Sd();shading=new Ad;helpers=[];skeletonHelper=null;boundsHelper=null;boneSelectionHighlight=null;boneSelectionSignature="";composer=null;composerLoading=!1;disposed=!1;sceneRenderPass=null;selectionOutline=null;selectionOutlinePass=null;selectedObjects=[];renderWidth=1;renderHeight=1;orthographicCamera=new Si;captureAspect=null;cameraOverride=null;beforeRender=null;state=ja;version=0;listeners=new Set;unsubscribeSelectionTheme=()=>{};flight=null;flightPose=new w;topologyOverlay=null;topologyFollowers=[];replaceContent(t,e){ct(),this.selectionOutline?.selection.clear(),this.selectedObjects=[],this.boneSelectionSignature="",this.clearBoneSelectionHighlight(),this.clearSkeletonHelper(),this.clearBoundsHelper(),this.clearTopologyOverlay(),this.root=t,this.authoring=e,this.state.mode==="wireframe"&&this.buildTopologyOverlay(),this.state.bounds&&(this.boundsHelper=new Qo(t,16757844),this.addHelper(this.boundsHelper,"bounds")),this.syncSelectionPresentation(),this.refreshSkeletonHelper(),this.notify()}cancelLookForHuman=()=>{this.settleFlight("human")};syncSelectionTheme=()=>{const t=ue(this.renderer.domElement).visible;this.selectionOutline&&Np(this.selectionOutline,ue(this.renderer.domElement)),this.boneSelectionHighlight?.setColor(t)};subscribe=t=>(this.listeners.add(t),()=>this.listeners.delete(t));getSnapshot=()=>this.version;presentation(){return this.state}resolveFrameBounds(){const t=this.authoring?.selection?.get()??[];if(t.length>0){const e=new pe;let i=!1;for(const s of t){const n=this.authoring?.hierarchy.object3D?.(s);if(!n)continue;const r=$e(n);r.isEmpty()||(e.union(r),i=!0)}if(i)return e}return this.frameBox&&!this.frameBox.isEmpty()?this.frameBox:$e(this.root)}frame(t=1){const e=this.resolveFrameBounds();if(e.isEmpty()){let a=0,l=0;return this.root.traverse(c=>{const d=c.geometry;d&&(a+=1,l+=d.getAttribute("position")?.count??0)}),Qi.warn(`frame: nothing to frame — root "${this.root.name}" (${this.root.children.length} children, ${a} meshes, ${l} positions), selection ${JSON.stringify(this.authoring?.selection?.get()??[])}, frameBox ${this.frameBox?this.frameBox.isEmpty()?"empty":"set":"none"}`,"document"),!1}this.settleFlight("superseded");const i=e.getCenter(new w),s=this.viewport.camera.position.clone().sub(this.viewport.orbitControls.target).normalize();s.lengthSq()===0&&s.set(.8,.5,-1).normalize();const n=Math.min(10,Math.max(.1,vi(t,1))),r=ti(e,this.viewport.camera,s)*n;return this.viewport.setPose(i.clone().addScaledVector(s,r),i),!0}orbit(t){return this.launchFlight(vi(t.azimuth,0),vi(t.elevation,0),Math.min(60,Math.max(0,vi(t.duration,.6))),Pf)}turntable(t){const e=vi(t.revolutions,1);return this.launchFlight(e*Math.PI*2,0,Math.min(60,Math.max(0,vi(t.seconds,6))),zf)}looking(){return this.flight!==null}launchFlight(t,e,i,s){this.settleFlight("superseded");const n=this.viewport.camera,r=this.viewport.orbitControls.target.clone(),a=new id().setFromVector3(n.position.clone().sub(r)),l=a.radius>1e-4?a.radius:Math.max(this.resolveFrameBounds().getSize(new w).length(),1),c={pivot:r,radius:l,startTheta:a.theta,startPhi:a.phi,deltaTheta:t,deltaPhi:-e,duration:i,ease:s,elapsed:0,theta:a.theta,phi:a.phi,settle:null};this.flight=c;const d=new Promise(h=>{c.settle=h});return this.applyFlightPose(c,0),i<=0&&this.settleFlight(null),d}applyFlightPose(t,e){const i=t.ease(e);t.theta=t.startTheta+t.deltaTheta*i,t.phi=Math.min(Cf,Math.max(Mf,t.startPhi+t.deltaPhi*i));const s=this.viewport.camera;s.position.setFromSphericalCoords(t.radius,t.phi,t.theta).add(t.pivot),this.viewport.orbitControls.target.copy(t.pivot),s.lookAt(t.pivot),s.updateMatrixWorld(),this.flightPose.copy(s.position)}advanceLook(t){const e=this.flight;if(!e)return;const i=Math.max(1e-4,e.radius*.001);if(this.viewport.camera.position.distanceToSquared(this.flightPose)>i*i){this.settleFlight("human");return}t>0&&Number.isFinite(t)&&(e.elapsed+=t);const s=e.duration<=0?1:Math.min(1,e.elapsed/e.duration);this.applyFlightPose(e,s),s>=1&&this.settleFlight(null)}settleFlight(t){const e=this.flight;if(!e)return;this.flight=null;const i={completed:t===null,azimuth:e.theta,elevation:Math.PI/2-e.phi,seconds:Math.min(e.elapsed,e.duration)};e.settle?.(t===null?i:{...i,cancelledBy:t})}select(t){ct(),this.authoring&&Zi(this.authoring,[...t])}selection(){return[...this.authoring?.selection?.get()??[]]}idForObject(t){return this.authoring?.hierarchy.idForObject3D?.(t)??null}syncSelectionPresentation(){ct();const t=(this.authoring?.selection?.get()??[]).map(s=>this.authoring?.hierarchy.object3D?.(s)??null).filter(s=>s!==null);this.selectedObjects=t,this.selectionOutline&&(ka(this.selectionOutline,this.selectionOutlineWanted?t:[]),this.syncComposerOutput());const e=t.filter(s=>!!s.isBone),i=e.map(s=>s.uuid).join("\0");i!==this.boneSelectionSignature&&(this.boneSelectionSignature=i,this.clearBoneSelectionHighlight(),e.length>0&&(this.boneSelectionHighlight=new vf(e,ue(this.renderer.domElement).visible),this.scene.add(this.boneSelectionHighlight)),this.refreshSkeletonHelper())}frameSelection(){return this.frameIds(this.authoring?.selection?.get()??[])}frameIds(t){this.settleFlight("superseded");const e=t.map(i=>this.authoring?.hierarchy.object3D?.(i)??null).filter(i=>i!==null);return e.length===0?!1:e.every(i=>i.isBone)?(this.frameBones(e),!0):(this.viewport.focusOnMultiple(e),!0)}setViewPreset(t){ct(),this.settleFlight("superseded");const e=this.resolveFrameBounds();if(e.isEmpty())return;const i=e.getCenter(new w),s=ad(t),n=ti(e,this.viewport.camera,s),r=i.clone().addScaledVector(s,n);this.viewport.camera.up.set(0,t==="top"?0:1,t==="top"?-1:0),this.viewport.setPose(r,i),this.setProjection(t==="isometric"?"perspective":"orthographic")}setCameraPose(t,e,i){ct(),this.settleFlight("superseded"),this.viewport.setPose(t,e,i)}cameraPose(){return{position:this.viewport.camera.position.toArray(),target:this.viewport.orbitControls.target.toArray(),fov:this.viewport.camera.fov}}camera(){return this.cameraOverride?this.cameraOverride:this.state.projection==="perspective"?this.viewport.camera:(this.syncOrthographicCamera(),this.orthographicCamera)}projection(){return this.state.projection}setProjection(t){ct(),this.state.projection!==t&&(this.state={...this.state,projection:t},this.notify())}setMode(t){ct(),this.state.mode!==t&&(this.clearDiagnosticPresentation(),this.state={...this.state,mode:t},t==="uv"?this.scene.overrideMaterial=new is({vertexShader:"varying vec2 vUv; void main(){ vUv=uv; gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0); }",fragmentShader:"varying vec2 vUv; void main(){ gl_FragColor=vec4(vUv,0.0,1.0); }"}):t==="vertex-colors"?this.scene.overrideMaterial=new vt({vertexColors:!0}):t==="wireframe"&&this.buildTopologyOverlay(),this.notify())}buildTopologyOverlay(){const t=new Ft,e=[];this.root.updateMatrixWorld(!0),this.root.traverse(i=>{const s=i;if(!s.isMesh||!s.geometry)return;const n=new Pi(new Jr(s.geometry,bf),new He({color:1119773,toneMapped:!1,transparent:!0,opacity:.85,depthTest:!1,depthWrite:!1}));n.matrixAutoUpdate=!1,n.matrixWorldAutoUpdate=!1,n.matrixWorld.copy(s.matrixWorld),n.frustumCulled=!1,n.renderOrder=2,t.add(n),e.push({line:n,source:s})}),e.length!==0&&(this.topologyOverlay=t,this.topologyFollowers=e,this.addHelper(t,"topology"))}syncTopologyOverlay(){this.topologyFollowers.some(({source:t})=>t.parent===null)&&(this.clearTopologyOverlay(),this.buildTopologyOverlay());for(const{line:t,source:e}of this.topologyFollowers)t.matrixWorld.copy(e.matrixWorld),t.visible=e.visible}clearTopologyOverlay(){for(const{line:i}of this.topologyFollowers.splice(0))i.geometry.dispose(),i.material.dispose();const t=this.topologyOverlay;if(this.topologyOverlay=null,!t)return;t.removeFromParent();const e=this.helpers.indexOf(t);e>=0&&this.helpers.splice(e,1)}setBounds(t){ct(),this.state.bounds!==t&&(this.state={...this.state,bounds:t},t?(this.boundsHelper=new Qo(this.root,16757844),this.addHelper(this.boundsHelper,"bounds")):this.clearBoundsHelper(),this.notify())}setSkeleton(t){ct(),this.state.skeleton!==t&&(this.state={...this.state,skeleton:t},this.refreshSkeletonHelper(),this.notify())}neutralBackgroundTexture(){return this.neutralBackground}setNeutralBackground(t){ct();const e=this.scene.background,i=this.neutralBackground,s=e===i||e instanceof D&&i instanceof D&&e.equals(i);this.neutralBackground=t,s&&(this.scene.background=t)}setBackground(t){ct(),this.state.background!==t&&(this.scene.background=t==="transparent"?null:this.neutralBackground,this.state={...this.state,background:t},this.notify())}resetPresentation(){ct(),kc(this.documentId),this.clearDiagnosticPresentation(),this.state=ja,this.refreshSkeletonHelper(),this.clearBoundsHelper(),this.scene.background=this.neutralBackground,this.viewport.camera.up.set(0,1,0),this.frame(),this.notify()}setBeforeRender(t){this.beforeRender=t}presentedFrameWaiters=[];presentsFrames=!1;setPresentsFrames(t){this.presentsFrames=t,t||this.resolvePresentedFrame(null)}requestPresentedFrame(){return this.presentsFrames?new Promise(t=>{let e=!1;const i=s=>{e||(e=!0,t(s))};this.presentedFrameWaiters.push(i),ct(),setTimeout(()=>i(null),Sf)}):Promise.resolve(null)}needsFrame(){return this.flight!==null||this.presentedFrameWaiters.length>0}servePresentedFrame(){if(this.presentedFrameWaiters.length===0)return;const t=this.renderer.domElement,e=document.createElement("canvas");e.width=Math.max(1,t.width),e.height=Math.max(1,t.height);const i=e.getContext("2d");if(!i){this.resolvePresentedFrame(null);return}i.drawImage(t,0,0),this.resolvePresentedFrame(e)}resolvePresentedFrame(t){const e=this.presentedFrameWaiters;this.presentedFrameWaiters=[];for(const i of e)i(t)}render(t){this.beforeRender?.(),this.boneSelectionHighlight?.update();const e=this.camera(),i=this.state.mode;if(this.boundsHelper?.update(),i==="uv"||i==="vertex-colors"){t(e);return}if(i==="wireframe"&&this.topologyOverlay){this.syncTopologyOverlay(),this.shading.render(this.scene,"clay",()=>t(e),Va);return}this.shading.render(this.scene,i,()=>t(e),Va)}renderViewport(t=0){this.advanceLook(t),this.ensureComposer(),this.render(e=>{const i=this.composer;if(!i){this.renderer.render(this.scene,e);return}i.setMainScene(this.scene),i.setMainCamera(e),i.render(t)})}resize(t,e){ct(),this.renderWidth=Math.max(1,t),this.renderHeight=Math.max(1,e),this.composer?.setSize(this.renderWidth,this.renderHeight)}renderCapture(t,e){this.render(i=>{if(!e){t(i);return}const s=this.scene.background,n=this.renderer.getClearColor(new D),r=this.renderer.getClearAlpha();try{this.scene.background=null,this.renderer.setClearColor(0,0),t(i)}finally{this.scene.background=s,this.renderer.setClearColor(n,r)}})}captureImage(t=512){const e=typeof t=="number"?t:t.width,i=typeof t=="number"?t:t.height;if(!Number.isFinite(e)||e<1||!Number.isFinite(i)||i<1)return null;const s=Math.min(2048,Math.round(e)),n=Math.min(2048,Math.round(i)),r=s*2,a=n*2,l=new $o(r,a,{type:sd}),c=new $o(r,a),d=this.renderer.getRenderTarget(),h=this.renderer.getPixelRatio(),f=this.viewport.camera,u=f.aspect;try{this.captureAspect=s/n;const p=typeof t=="number"?void 0:t.camera;p?this.cameraOverride=p:(f.aspect=s/n,f.updateProjectionMatrix()),this.renderer.setPixelRatio(1),this.renderer.setRenderTarget(l),this.renderCapture(b=>this.renderSolidForCapture(b,l,r,a),typeof t!="number"&&t.transparent===!0),Ic(typeof t!="number"&&t.transparent===!0).render(this.renderer,c,l,0,!1);const m=r*4,y=new Uint8Array(m*a);this.renderer.readRenderTargetPixels(c,0,0,r,a,y);const _=document.createElement("canvas");_.width=r,_.height=a;const v=_.getContext("2d");if(!v)return null;const S=v.createImageData(r,a);for(let b=0;b<a;b++){const M=(a-1-b)*m,P=b*m;S.data.set(y.subarray(M,M+m),P)}v.putImageData(S,0,0);const x=document.createElement("canvas");x.width=s,x.height=n;const C=x.getContext("2d");return C?(C.drawImage(_,0,0,s,n),x.toDataURL("image/png")):null}finally{this.captureAspect=null,this.cameraOverride=null,f.aspect=u,f.updateProjectionMatrix(),this.renderer.setRenderTarget(d),this.renderer.setPixelRatio(h),c.dispose(),l.dispose()}}dispose(){this.disposed=!0,this.settleFlight("closed"),this.viewport.orbitControls.removeEventListener("start",this.cancelLookForHuman),this.unsubscribeSelectionTheme(),this.clearDiagnosticPresentation(),this.clearBoneSelectionHighlight(),this.clearBoundsHelper(),this.clearSkeletonHelper(),this.selectionOutline&&Bp(this.renderer,this.selectionOutline,this.selectionOutlinePass),this.composer?.dispose(),this.sceneRenderPass=null,this.selectionOutline=null,this.selectionOutlinePass=null,this.composer=null,this.shading.dispose(),this.listeners.clear()}addHelper(t,e){t.name=`__object3d_document_${e}`,Dt(t,"editorHelper",!0),this.scene.add(t),this.helpers.push(t)}get selectionOutlineEnabled(){return this.selectionOutlineWanted}set selectionOutlineEnabled(t){t!==this.selectionOutlineWanted&&(this.selectionOutlineWanted=t,t?this.syncSelectionPresentation():(this.selectionOutline?.selection.clear(),this.syncComposerOutput()))}selectionOutlineWanted=!0;ensureComposer(){this.selectionOutlineWanted&&(this.composer||this.composerLoading||this.disposed||(this.composerLoading=!0,ri(()=>import("./index-BtfYaG4D.js"),__vite__mapDeps([12,1])).then(t=>{if(this.composerLoading=!1,this.disposed||this.composer)return;const e=this.camera(),i=new t.EffectComposer(this.renderer);this.sceneRenderPass=new t.RenderPass(this.scene,e),i.addPass(this.sceneRenderPass),this.selectionOutline=Lp(t,this.renderer,this.scene,e,ue(this.renderer.domElement)),this.syncSelectionTheme(),ka(this.selectionOutline,this.selectedObjects),this.selectionOutlinePass=new t.EffectPass(e,this.selectionOutline),i.addPass(this.selectionOutlinePass),this.composer=i,this.syncComposerOutput(),i.setSize(this.renderWidth,this.renderHeight),ct()}).catch(()=>{this.composerLoading=!1})))}renderSolidForCapture(t,e,i,s){const n=this.composer,r=(this.selectionOutline?.selection.size??0)>0;if(!n||!r||!this.sceneRenderPass||!this.selectionOutlinePass){this.renderer.render(this.scene,t);return}const a=this.renderWidth,l=this.renderHeight;try{this.sceneRenderPass.renderToScreen=!1,this.selectionOutlinePass.renderToScreen=!1,n.setSize(i,s,!1),this.sceneRenderPass.render(this.renderer,n.inputBuffer,n.outputBuffer,0),this.selectionOutlinePass.render(this.renderer,n.inputBuffer,e,0)}finally{n.setSize(a,l,!1),this.syncComposerOutput(),this.renderer.setRenderTarget(e)}}syncComposerOutput(){const t=(this.selectionOutline?.selection.size??0)>0;this.sceneRenderPass&&(this.sceneRenderPass.renderToScreen=!t),this.selectionOutlinePass&&(this.selectionOutlinePass.enabled=t,this.selectionOutlinePass.renderToScreen=t)}refreshSkeletonHelper(){const t=this.state.skeleton||this.boneSelectionHighlight!==null;t&&!this.skeletonHelper?(this.skeletonHelper=new nd(this.root),xf(this.skeletonHelper),this.scene.add(this.skeletonHelper)):t||this.clearSkeletonHelper()}clearSkeletonHelper(){this.skeletonHelper&&(this.skeletonHelper.removeFromParent(),this.skeletonHelper.dispose(),this.skeletonHelper=null)}clearBoneSelectionHighlight(){this.boneSelectionHighlight&&(this.boneSelectionHighlight.removeFromParent(),this.boneSelectionHighlight.dispose(),this.boneSelectionHighlight=null)}clearBoundsHelper(){if(!this.boundsHelper)return;const t=this.boundsHelper;this.boundsHelper=null;const e=this.helpers.indexOf(t);e>=0&&this.helpers.splice(e,1),t.removeFromParent(),t.geometry.dispose(),Array.isArray(t.material)?t.material.forEach(i=>{i.dispose()}):t.material.dispose()}frameBones(t){const e=new pe,i=new w;for(const l of t){e.expandByPoint(l.getWorldPosition(i)),l.parent?.isBone&&e.expandByPoint(l.parent.getWorldPosition(i));for(const c of l.children)c.isBone&&e.expandByPoint(c.getWorldPosition(i))}const s=e.getCenter(new w),n=Math.max(e.getSize(new w).length(),.2);e.expandByScalar(n*.35);const r=this.viewport.camera.position.clone().sub(this.viewport.orbitControls.target).normalize(),a=ti(e,this.viewport.camera,r);this.viewport.setPose(s.clone().addScaledVector(r,a),s)}syncOrthographicCamera(){const t=this.viewport.camera,e=this.viewport.orbitControls.target,i=Math.max(t.position.distanceTo(e),.001),s=Math.max(i*Math.tan(Wt.degToRad(t.fov)/2),.001),n=Math.max(this.renderer.domElement.clientWidth,1),r=Math.max(this.renderer.domElement.clientHeight,1),a=this.captureAspect??n/r;this.orthographicCamera.left=-s*a,this.orthographicCamera.right=s*a,this.orthographicCamera.top=s,this.orthographicCamera.bottom=-s,this.orthographicCamera.near=t.near,this.orthographicCamera.far=t.far,this.orthographicCamera.position.copy(t.position),this.orthographicCamera.quaternion.copy(t.quaternion),this.orthographicCamera.up.copy(t.up),this.orthographicCamera.layers.mask=t.layers.mask,this.orthographicCamera.updateProjectionMatrix(),this.orthographicCamera.updateMatrixWorld(!0)}clearDiagnosticPresentation(){this.clearTopologyOverlay(),this.scene.overrideMaterial?.dispose(),this.scene.overrideMaterial=null;for(const t of this.helpers.splice(0)){t.removeFromParent();const e=t;e.geometry?.dispose();const i=e.material;Array.isArray(i)?i.forEach(s=>{s.dispose()}):i?.dispose()}}notify(){this.version++;for(const t of this.listeners)t()}}class Ef{constructor(t){this.options=t}active=null;settling=!1;idleWaiters=new Set;begin(t){if(this.active||this.settling)return!1;try{const e=this.options.begin(t);return e?(this.active={pointerId:t.pointerId,gesture:e},!0):!1}catch(e){return this.options.reportError(e),!1}}update(t){if(!(!this.active||this.active.pointerId!==t.pointerId))try{this.active.gesture.update(t)}catch(e){this.cancelWithError(e)}}async commit(t){const e=this.take(t.pointerId);if(!e)return!1;this.settling=!0;try{return await e.commit(t),await this.options.persist(e.label),!0}catch(i){try{await e.cancel()}catch(s){return this.options.reportError({operationError:i,rollbackError:s}),!1}return this.options.reportError(i),!1}finally{this.settling=!1;for(const i of this.idleWaiters)i();this.idleWaiters.clear()}}async cancel(t){const e=this.take(t);if(!e)return!1;this.settling=!0;try{return await e.cancel(),!0}catch(i){return this.options.reportError(i),!1}finally{this.settling=!1;for(const i of this.idleWaiters)i();this.idleWaiters.clear()}}async settle(){this.active&&await this.cancel(),this.settling&&await new Promise(t=>this.idleWaiters.add(t))}hasActiveGesture(){return this.active!==null}take(t){if(!this.active||t!==void 0&&this.active.pointerId!==t)return null;const e=this.active.gesture;return this.active=null,e}async cancelWithError(t){const e=this.take();if(e){this.settling=!0;try{await e.cancel(),this.options.reportError(t)}catch(i){this.options.reportError({operationError:t,rollbackError:i})}finally{this.settling=!1;for(const i of this.idleWaiters)i();this.idleWaiters.clear()}}}}function Be(o){const t=Ct(o,"authoringSubject");return t&&typeof t.label=="string"&&typeof t.kind=="string"?t:null}function Ga(o){return o.depthWrite===!1&&o.side===rd}function Tf(o){const t=o.material;return t?Array.isArray(t)?t.length>0&&t.every(Ga):Ga(t):!1}function jl(o,t,e,i=()=>!1,s){const n=fd();if(!n)return[];const r=n.canvas.getBoundingClientRect();if(r.width<=0||r.height<=0||!Number.isFinite(t)||!Number.isFinite(e)||t<r.left||e<r.top||t>=r.left+r.width||e>=r.top+r.height)return[];const a=new Ht((t-r.left)/r.width*2-1,-((e-r.top)/r.height)*2+1),l=new $t;l.layers.enableAll(),l.setFromCamera(a,n.camera);const c=new Set(s?.objects??o.objectMap.values()),d=[...c].filter(p=>{for(let m=p.parent;m;m=m.parent)if(c.has(m))return!1;return!0});for(const p of d)p.traverse(m=>{const y=m;y.isSkinnedMesh&&(y.boundingBox=null,y.boundingSphere=null)});const h=l.intersectObjects(d,!0),f=[],u=new Set;for(const p of h){if(he(p.object)||Tf(p.object))continue;let m=p.object,y=null;if(s)for(;m&&y===null;)y=s.idForObject3D(m),m=m.parent;else{const _=Rc(m);y=_?Vr(_)??null:null}y!==null&&!i(y)&&!u.has(y)&&(u.add(y),f.push(y))}return Of(f,d,h.length,t,e),f}function Of(o,t,e,i,s){o.length>0||i===0&&s===0||console.info(`[viewport-pick] click selected nothing (candidates ${t.length}, rayHits ${e}, resolvedIds 0)`)}function kf(o,t,e,i=()=>!1,s){return jl(o,t,e,i,s)[0]??null}const Wa={count:0,meshes:0,lights:0,instancedMeshes:0,instances:0};let Xa=0;function If(o){let t=0,e=0;for(const i of o.values()){const s=i.object;s.isInstancedMesh&&(t++,e+=typeof s.count=="number"?s.count:0)}return{instancedMeshes:t,instances:e}}function Gl(o){let t=0,e=0;for(const i of o.values()){const s=i.object;s.isLight?e++:s.isMesh&&t++}return{count:o.size,meshes:t,lights:e,...If(o)}}function Rf(o,t){const e=new Map,i=[],s=t.skip??Ns;t.begin?.(o);const n=(r,a,l,c)=>{if(s(r))return;const d=t.identify(r,{path:a,ownerId:l,ownedByAncestor:c});d!==null&&(ll(r,d),e.set(d,{object:r,id:d,parentId:l,childIds:[]}),l===null?i.push(d):e.get(l)?.childIds.push(d));const h=c||d!==null;r.children.forEach((f,u)=>{n(f,[...a,u],d??l,h)}),t.leave?.(r,d)};return o.children.forEach((r,a)=>{n(r,[a],null,!1)}),{nodes:e,rootIds:i,stats:Gl(e)}}const Ff="r3f:";function Lf(o,t){return`${Ff}${o}:${t}`}function Bf(o){return{project:t=>Rf(t,{skip:e=>!!Ct(e,"editorHelper")||e.isSkeletonHelper===!0,identify:(e,i)=>`source-object:${o}:${i.path.join(".")}`})}}function Nf(o){const t=Be(o);return t?t.kind:An(o).length>0?"constraint-owner":ts(o)?"reflection-probe":o.isSkinnedMesh?"skinned-mesh":o.isBone?"bone":o.isLight?"light":o.isCamera?"camera":o.type==="Audio"||o.type==="PositionalAudio"||o.type==="AudioListener"?"audio":o.isMesh?"mesh":o.children.length>0?"group":"object"}function Hf(o,t){for(let e=o.parent;e!==null;e=e.parent)if(e===t)return!0;return!1}function Ja(o,t){if(o===t)return!0;for(let e=o.parent;e!==null;e=e.parent)if(e===t)return!0;return!1}class Df{constructor(t,e={}){this.identity=t,this.options=e}nodesById=new Map;objectsById=new Map;idsByObjectIndex=new Map;roots=[];walkStats=Wa;project(t){if(!t)return this.nodesById=new Map,this.objectsById=new Map,this.idsByObjectIndex=new Map,this.roots=[],this.walkStats=Wa,this.walkStats;const{nodes:e,rootIds:i,stats:s}=this.identity.project(t);return this.nodesById=e,this.objectsById=new Map([...e].map(([n,r])=>[n,r.object])),this.idsByObjectIndex=new Map([...e].map(([n,r])=>[r.object,n])),this.roots=i,this.walkStats=s,s}projectSubtrees(t,e){const i=this.identity.incremental;if(t===null||i?.kind!=="live-oid")return null;const s=e.filter((_,v)=>e.indexOf(_)===v&&!e.some(S=>S!==_&&Hf(_,S))),n=this.roots,r=new Set,a=new Set,l=new Set;for(const _ of s)_.traverse(v=>{const S=this.idsByObjectIndex.get(v);if(S===void 0)return;const x=this.nodesById.get(S);x?.parentId!==null&&x?.parentId!==void 0&&l.add(x.parentId),r.add(S),this.nodesById.delete(S),this.objectsById.delete(S),this.idsByObjectIndex.delete(v)});const c=Ns,d=(_,v)=>{const S=this.objectsById.get(_);return S===void 0||S===v},h=(_,v)=>{const S=Vr(_);if(S!==void 0&&d(S,_))return S;const x=Fc(_);if(x!==void 0){const C=Lf(i.worldId,x);let b=0,M=No(C,b);for(;!d(M,_);)M=No(C,++b);return M}if(!v||Ct(_,"authoringRoot")===!0){let C=`live:${i.worldId}:${Xa++}`;for(;!d(C,_);)C=`live:${i.worldId}:${Xa++}`;return C}return null},f=(_,v,S)=>{if(c(_))return;const x=h(_,S);x!==null&&(ll(_,x),this.nodesById.set(x,{object:_,id:x,parentId:v,childIds:[]}),this.objectsById.set(x,_),this.idsByObjectIndex.set(_,x),a.add(x),v!==null&&l.add(v));const C=x??v,b=S||x!==null;for(const M of _.children)f(M,C,b)};for(const _ of s){if(!Ja(_,t))continue;let v=_.parent,S=null;for(;v!==null&&v!==t;){const x=this.idsByObjectIndex.get(v);if(x!==void 0){S=x;break}v=v.parent}f(_,S,S!==null)}const u=_=>{const v=[],S=x=>{if(c(x))return;const C=this.idsByObjectIndex.get(x);if(C!==void 0){v.push(C);return}for(const b of x.children)S(b)};for(const x of _.children)S(x);return v};for(const _ of l){const v=this.nodesById.get(_);v!==void 0&&v.childIds.splice(0,v.childIds.length,...u(v.object))}for(const _ of a){const v=this.nodesById.get(_);v!==void 0&&v.childIds.splice(0,v.childIds.length,...u(v.object))}const p=u(t),m=this.roots.filter(_=>{const v=this.objectsById.get(_);return v!==void 0&&!Ja(v,t)&&!r.has(_)});this.roots=[...p,...m],this.walkStats=Gl(this.nodesById);const y=n.length!==this.roots.length||n.some((_,v)=>_!==this.roots[v]);return{removedIds:r,addedIds:a,changedParentIds:l,rootsChanged:y}}get nodes(){return this.nodesById}get objects(){return this.objectsById}get idsByObject(){return this.idsByObjectIndex}get rootIds(){return this.roots}get stats(){return this.walkStats}node(t){return this.nodesById.get(t)??null}rootNodes(){return this.roots.map(t=>this.nodesById.get(t)).filter(t=>t!==void 0)}objectOf(t){return this.objectsById.get(t)??null}idOf(t){return this.idsByObjectIndex.get(t)??null}childIdsOf(t){const e=[];for(const i of t){const s=this.idsByObjectIndex.get(i);s!==void 0&&e.push(s)}return e}objectMapSnapshot(){return new Map(this.objectsById)}pick(t,e,i,s){return kf(t,e,i,s,this.pickProjection())}candidates(t,e,i,s){return jl(t,e,i,s,this.pickProjection())}pickProjection(){if(this.options.pickScope!=="store-object-map")return{objects:this.objectsById.values(),idForObject3D:t=>this.idOf(t)}}}const Ya=new w,qa=new bt,Za=new w;function Uf(o){return o.matrixAutoUpdate===!1?(o.matrix.decompose(Ya,qa,Za),{position:Ya.toArray(),quaternion:qa.toArray(),scale:Za.toArray()}):{position:o.position.toArray(),quaternion:o.quaternion.toArray(),scale:o.scale.toArray()}}function Vf(o,t){return o.length===t.length&&o.every((e,i)=>e===t[i])}class jf{constructor(t){this.options=t,this.selected=[...t.initial]}adopted=[];selected;current(){const t=[...this.options.store.selectedEntityIds].filter(this.options.owns);return Vf(t,this.adopted)||(this.adopted=t,this.selected=t,this.options.onChange?.(t)),[...this.selected]}publish(t){this.selected=[...t];const e=this.selected.filter(this.options.owns);this.adopted=e,this.options.onChange?.(e),this.options.store.selectMultiple(e)}}function Gf(o){if(!o)return{position:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]};const t=Uf(o);return{position:t.position,rotation:t.quaternion,scale:t.scale}}function Cr(o){return o.type==="Object3D"&&o.name===""&&Be(o)===null&&o.userData.oid===void 0&&Ct(o,"authoringInstance")===void 0&&Ct(o,"authoringRoot")!==!0&&Ct(o,"vgaiComponentRoot")===void 0}class Wf{constructor(t){this.options=t,this.rootIdSet=new Set(t.rootIds)}rootIdSet;childObjects(t){return t.children.flatMap(e=>Ns(e)?[]:Cr(e)?this.childObjects(e):[e])}childIds(t){return this.options.projector.childIdsOf(this.childObjects(t))}rootObjects(){return this.options.rootIds.flatMap(t=>{const e=this.options.projector.objectOf(t);return e?Cr(e)?this.childObjects(e):[e]:[]})}rootIds(){return this.options.projector.childIdsOf(this.rootObjects())}parentId(t){const{projector:e,scene:i,documentNodeId:s}=this.options,n=e.idOf(t);if(n!==null&&this.rootIdSet.has(n))return s;let r=t.parent;for(;r&&r!==i&&Cr(r);)r=r.parent;return r&&r!==i?e.idOf(r)??s:s}node(t){const e=Be(t);return{id:this.options.projector.idOf(t),label:e?.label||t.name||t.type||"Object3D",role:"entity",kind:Nf(t),...e?.typeLabel?{typeLabel:e.typeLabel}:{},parentId:this.parentId(t),childIds:this.childIds(t)}}}const Qa=new WeakMap;function Xf(o){let t=!1;if(o.traverse(s=>{Ct(s,"gaussianSplat")&&(t=!0)}),t)return"Gaussian splat";const e=ld(o),i=cd(o);return{static:"Static model",animated:"Animated model",rigged:"Rigged model",skinned:"Skinned model"}[hd(e,i)]}function $a(o){const t=o.material;return Array.isArray(t)?t[0]??null:t??null}function Ka(o){return o?.color??null}class io{constructor(t,e,i){if(this.store=t,this.scene=e,this.options=i,this.provenance=i.provenance??(i.documentKind==="asset"?{source:"document",label:"derived asset",detail:"Loaded from an ordinary project asset. Edit its source or import recipe."}:{source:"source-code",label:"source",detail:"Instantiated from project TypeScript. Edit source or exposed parameters, then rebuild."}),this.documentNodeId=`object3d-document:${i.documentId}`,this.projector=new Df(Bf(i.documentId)),this.indexGraph(),i.hierarchyRoots&&new Set(i.hierarchyRoots).size!==i.hierarchyRoots.length)throw new Error(`Object3D document "${i.title}" declared the same hierarchy root twice.`);const s=new Set(i.hierarchyRoots??[]);for(const n of s){let r=n.parent;for(;r&&r!==e;){if(s.has(r))throw new Error(`Object3D document "${i.title}" declared nested hierarchy roots; roots must be non-overlapping.`);r=r.parent}}this.hierarchyRootIds=i.hierarchyRoots?i.hierarchyRoots.map(n=>{const r=this.idByObject.get(n);if(!r)throw new Error(`Object3D document "${i.title}" declared a hierarchy root outside its native graph.`);return r}):[...this.projector.rootIds],this.view=new Wf({projector:this.projector,scene:e,documentNodeId:this.documentNodeId,rootIds:this.hierarchyRootIds}),this.selectionState=new jf({store:t,owns:n=>this.byId.has(n),initial:[this.documentNodeId],onChange:n=>this.syncMarkedSelection(n)})}documentNodeId;projector;hierarchyRootIds;view;selectionState;markedSelection=new Set;capabilities={transform:!1,inspectorFields:!0,persist:!1};provenance;disposed=!1;dispose(){if(!this.disposed){this.disposed=!0;for(const t of this.watchedForStructure)t.removeEventListener("childadded",this.onStructureChanged),t.removeEventListener("childremoved",this.onStructureChanged);this.watchedForStructure=[]}}watchedForStructure=[];structureReindexQueued=!1;onStructureChanged=t=>{Ns(t.child)||this.scheduleStructureReindex()};indexGraph(){this.projector.project(this.scene),this.watchStructure()}watchStructure(){const t=i=>i;for(const i of this.watchedForStructure)t(i).removeEventListener("childadded",this.onStructureChanged),t(i).removeEventListener("childremoved",this.onStructureChanged);this.watchedForStructure=[];const e=i=>{t(i).addEventListener("childadded",this.onStructureChanged),t(i).addEventListener("childremoved",this.onStructureChanged),this.watchedForStructure.push(i)};e(this.scene);for(const[,i]of this.byId)e(i)}scheduleStructureReindex(){this.disposed||this.structureReindexQueued||(this.structureReindexQueued=!0,queueMicrotask(()=>{if(this.structureReindexQueued=!1,this.disposed||(this.indexGraph(),this.store.scene!==this.scene))return;const t=this.store.objectMap;t.clear();for(const[i,s]of this.byId)t.set(i,s);const e=[...this.store.selectedEntityIds].filter(i=>i===this.documentNodeId||this.byId.has(i));e.length!==this.store.selectedEntityIds.size&&this.store.selectMultiple(e),this.store.notifyIngestObjectMapEdit()}))}get byId(){return this.projector.objects}get idByObject(){return this.projector.idsByObject}documentTypeLabel(){if(this.options.documentKind!=="asset")return;const t=this.scene.children.find(s=>this.idByObject.has(s))??null;if(!t)return;const e=Qa.get(t);if(e!==void 0)return e;const i=Xf(t);return Qa.set(t,i),i}hierarchy={roots:()=>[this.hierarchy.node(this.documentNodeId)],node:t=>{if(t===this.documentNodeId){const i=this.documentTypeLabel();return{id:t,label:this.options.title,secondaryLabel:this.options.sourcePath,role:"document",kind:this.options.documentKind==="asset"?"model-asset":"three-source",...i?{typeLabel:i}:{},parentId:null,childIds:this.view.rootIds()}}const e=this.byId.get(t);return e?this.view.node(e):null},object3D:t=>this.byId.get(t)??null,idForObject3D:t=>this.idByObject.get(t)??null};selection={get:()=>this.selectionState.current(),set:t=>this.selectionState.publish(t.filter(e=>e===this.documentNodeId||this.byId.has(e)))};static READ_ONLY_REASON="This document shows what the module builds; its properties are read-only here. Edit the module.";readOnly=()=>({writable:!1,reason:io.READ_ONLY_REASON});transforms={get:t=>Gf(this.byId.get(t)??null),beginEdit:()=>{},apply:()=>{},endEdit:()=>{}};inspector={properties:t=>{if(t===this.documentNodeId)return this.options.audit===!1?[]:[{path:"name",label:"Name",type:"string",readonly:!0},{path:"source.path",label:"Source",type:"string",readonly:!0}];const e=this.byId.get(t);if(!e)return[];const i=Be(e);if(i?.fields)return i.fields().map(({value:l,...c})=>c);const s=[{path:"name",label:"Name",type:"string",readonly:!0},{path:"visible",label:"Visible",type:"boolean",readonly:!0},{path:"object.type",label:"Native type",type:"string",readonly:!0}],n=e;if(n.isMesh&&n.geometry){const l=n.geometry.getAttribute("position");s.push({path:"mesh.vertices",label:"Vertices",type:"number",readonly:!0,group:"Mesh"}),l&&s.push({path:"mesh.triangles",label:"Triangles",type:"number",readonly:!0,group:"Mesh"})}const r=$a(e);r&&(s.push({path:"material.type",label:"Material",type:"string",readonly:!0,group:"Material"}),Ka(r)&&s.push({path:"material.color",label:"Color",type:"color",readonly:!0,group:"Material"}));const a=e;return a.isSkinnedMesh&&a.skeleton&&s.push({path:"skin.bones",label:"Bones",type:"number",readonly:!0,group:"Skin"}),s},get:(t,e)=>{if(t===this.documentNodeId)return e==="name"?this.options.title:e==="source.path"?this.options.sourcePath:void 0;const i=this.byId.get(t);if(!i)return;const n=Be(i)?.fields?.().find(l=>l.path===e);if(n)return n.value();if(e==="name")return i.name||i.type;if(e==="visible")return i.visible;if(e==="object.type")return i.type;const r=i;if(e==="mesh.vertices")return r.geometry?.getAttribute("position")?.count??0;if(e==="mesh.triangles"){const l=r.geometry;return(l?.index?.count??l?.getAttribute("position")?.count??0)/3}const a=$a(i);if(e==="material.type")return a?.type;if(e==="material.color"){const l=Ka(a);return l?`#${l.getHexString()}`:void 0}if(e==="skin.bones")return i.skeleton?.bones.length??0},set:()=>{},editability:()=>this.readOnly()};subscribe(t){return this.store.subscribe(t)}get documentId(){return this.documentNodeId}get documentRootObject(){const t=this.hierarchy.node(this.documentNodeId)?.childIds[0];return t?this.byId.get(t)??null:null}syncMarkedSelection(t){const e=new Set(t.map(i=>this.byId.get(i)??null).filter(i=>i!==null).filter(i=>Be(i)?.selectionChanged!==void 0));for(const i of this.markedSelection)e.has(i)||Be(i)?.selectionChanged?.(!1);for(const i of e)this.markedSelection.has(i)||Be(i)?.selectionChanged?.(!0);this.markedSelection=e}}class Jf{constructor(t,e){this.frame=t,this.releaseRenderer=e,this.unsubscribeActivity=md(()=>this.syncActivity())}rafId=0;running=!1;disposed=!1;active=!1;unsubscribeActivity;get isDisposed(){return this.disposed}get isRunning(){return this.running}setActive(t){this.disposed||(this.active=t,this.syncActivity())}syncActivity(){this.active&&Kn()?this.start():this.stop()}redraw(){this.running&&!this.disposed&&Kn()&&this.guardedFrame(performance.now())}dispose(){this.stop(),!this.disposed&&(this.disposed=!0,this.unsubscribeActivity(),this.releaseRenderer())}start(){this.disposed||this.running||(this.running=!0,this.guardedFrame(performance.now(),!0),!(!this.running||this.disposed)&&(this.rafId=requestAnimationFrame(this.tick)))}lastFrameFailure=null;guardedFrame(t,e=!1){try{this.frame(t,e),this.lastFrameFailure=null}catch(i){const s=i instanceof Error?i.message:String(i);s!==this.lastFrameFailure&&(this.lastFrameFailure=s,console.error("[document renderer] a frame threw; the loop continues:",i))}}stop(){this.running=!1,this.rafId!==0&&(cancelAnimationFrame(this.rafId),this.rafId=0)}tick=t=>{if(!(!this.running||this.disposed)){if(!Kn()){this.stop();return}this.guardedFrame(t),!(!this.running||this.disposed)&&(this.rafId=requestAnimationFrame(this.tick))}}}const Yf=new Set(["solid","clay","unlit","wireframe","normals","overdraw"]);function qf(o,t){return{read:()=>{const e=o.cameraPose;if(!e)return null;const{position:i,target:s}=e;return{camera:{position:{x:i.x,y:i.y,z:i.z},target:{x:s.x,y:s.y,z:s.z},...e.fov?{fov:e.fov}:{}},diagnostic:o.shadingMode,grid:Lc(t)}},setDiagnostic:e=>Yf.has(e)?(o.setShadingMode(e),!0):!1,setCamera:e=>typeof e!="string"?(o.setCameraPose(e.position,e.target,e.fov),!0):e==="isometric"?!1:(o.setViewPreset(e),!0),frame:e=>e==="document"?!1:(o.focusOnSelection(),!0)}}function Zf(o){const t=Tr();return t?Bc(cl(t,o)):"none"}const Qf=F.lazy(()=>ri(()=>import("./stage-transform-tools-Cqtv-ZQ1.js"),__vite__mapDeps([13,6,4,2,3,5,7,8,9,10,1,11,14,15,16,17,18,19,20,21,22,23])).then(o=>({default:o.ThreeStageTransformTools}))),$f=F.lazy(()=>ri(()=>import("./stage-transform-tools-Cqtv-ZQ1.js"),__vite__mapDeps([13,6,4,2,3,5,7,8,9,10,1,11,14,15,16,17,18,19,20,21,22,23])).then(o=>({default:o.ThreeStageTransformControls})));function tl(o){return{transformTools:()=>Zf(o),TransformTools:Qf,TransformControls:$f}}class Kf{constructor(t,e,i){this.create=t,this.isOpen=e,this.subscribe=i}states=new Map;generations=new WeakMap;unsubscribe=null;claim(t){const e=this.states.get(t)??[];let i=e.find(s=>!s.inUse);return i||(i=this.create(t),e.push(i),this.states.set(t,e)),i.inUse=!0,this.generations.set(i,this.generation(i)+1),this.unsubscribe??=this.subscribe(()=>this.discardClosed()),i}generation(t){return this.generations.get(t)??0}release(t,e=this.generation(t)){this.generation(t)===e&&(t.inUse=!1,queueMicrotask(()=>this.discardClosed()))}retain(t,e,i){if(!this.isOpen(t.documentId)||!this.states.get(t.documentId)?.includes(t)||this.generation(t)!==i){e.dispose();return}const s=t.source;t.source=e,s!==e&&s?.dispose()}discardClosed(){const t=[];for(const[i,s]of this.states){if(this.isOpen(i))continue;const n=s.filter(r=>r.inUse);t.push(...s.filter(r=>!r.inUse)),n.length?this.states.set(i,n):this.states.delete(i)}this.states.size===0&&(this.unsubscribe?.(),this.unsubscribe=null);const e=[];for(const i of t){const s=i.source;i.source=null;try{s?.dispose()}catch(n){e.push(n)}}if(e.length)throw new AggregateError(e,"Retained document cleanup failed")}}const tm=F.lazy(async()=>({default:(await ri(()=>import("./stage-overlay-set-DQeskS16.js"),__vite__mapDeps([24,6,4,3,5,2,7,8,9,10,1,11,25,26]))).StageOverlaySet}));function em(o){return O.jsx(F.Suspense,{fallback:null,children:O.jsx(tm,{...o})})}const im=[.25,.5,1,2];function sm(o,t){const e=Math.round(o*t);return`${o.toFixed(2)}s · f${e}`}function nm({transport:o}){const t=F.useSyncExternalStore(F.useCallback(h=>o?o.subscribe(h):()=>{},[o]),F.useCallback(()=>o?.snapshot()??null,[o]));if(!o||!t||t.activeSubject===null)return null;const e=t.driver==="world",i=t.playbackState==="playing",{start:s,end:n,fps:r,loop:a}=t.range,l=t.subjects.find(h=>h.id===t.activeSubject),c=t.subjects.length>1?t.subjects:null,d=o.activeClips();return O.jsxs("section",{"aria-label":"Transport","data-testid":"stage-transport-strip",style:{display:"flex",alignItems:"center",gap:"var(--vgai-space-2)",padding:"var(--vgai-space-1) var(--vgai-space-3)",borderTop:`var(--vgai-stroke-resting) solid ${Gt.boundary.default}`,background:Gt.surface.raised},children:[O.jsx(Fe,{size:"compact","aria-label":i?"Pause":"Play",disabled:e,onClick:()=>i?o.pause():o.play(),children:O.jsx(Le,{icon:i?xe.transport.pause:xe.transport.play})}),O.jsx(Fe,{size:"compact","aria-label":"Stop",disabled:e,onClick:()=>o.stop(),children:O.jsx(Le,{icon:xe.transport.stop})}),O.jsx(Nc,{"aria-label":"Playhead",type:"range",min:s,max:n,step:1/r,value:t.time,disabled:e,onChange:h=>o.seek(Number(h.target.value)),style:{flex:1}}),O.jsx(ln,{as:"span",variant:"caption",children:sm(t.time,r)}),c?O.jsx("select",{"aria-label":"Subject",value:t.activeSubject,disabled:e,onChange:h=>o.setActiveSubject(h.target.value),children:c.map(h=>O.jsx("option",{value:h.id,children:h.label},h.id))}):null,d?O.jsx("select",{"aria-label":"Clip",disabled:e,onChange:h=>o.setActiveClip(h.target.value),children:d.map(h=>O.jsx("option",{value:h.id,children:h.label},h.id))}):null,O.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"var(--vgai-space-1)"},children:[O.jsx("input",{type:"checkbox",checked:a,disabled:e,onChange:h=>o.setLoop(h.target.checked)}),O.jsx(ln,{as:"span",variant:"caption",children:"Loop"})]}),O.jsx("select",{"aria-label":"Speed",value:String(t.timeScale),disabled:e,onChange:h=>o.setTimeScale(Number(h.target.value)),children:im.map(h=>O.jsxs("option",{value:String(h),children:[h,"×"]},h))}),e?O.jsx(ln,{as:"span",variant:"caption",children:"The world is driving time (Play); pause the game to scrub"}):l?O.jsx(ln,{as:"span",variant:"caption",children:l.label}):null]})}const rm=gf;function el(o){return Bn(null,o)}const om=()=>()=>{},il=()=>0,am=5,lm=58;function cm({viewport:o,session:t,store:e,projection:i,displayName:s,objectName:n,statistics:r}){F.useSyncExternalStore(e.subscribe,e.getShellSnapshot??e.getSnapshot),F.useSyncExternalStore(t?.subscribe??om,t?.getSnapshot??il,t?.getSnapshot??il);const a=F.useSyncExternalStore(el,Fl),l=F.useSyncExternalStore(el,Yu),c=a&&!l?Gt.content.onAccent:Gt.content.primary;if(!o)return null;const d=dd(o.camera.position.clone().sub(o.orbitControls.target))??"User",h=t?.projection()??i,f=`${d} ${h==="perspective"?"Perspective":"Orthographic"}`,u=e.selectedEntityId,p=(u===null?null:n(u))||null,m=p===null||p===s?s:`${s} | ${p}`,y=v=>{const S=o.renderCamera;if(S instanceof Si){S.zoom=Math.max(.01,S.zoom/v),S.updateProjectionMatrix();return}const x=o.orbitControls.target;o.camera.position.sub(x).multiplyScalar(v).add(x),o.orbitControls.update()},_=v=>{v.preventDefault();const S=v.currentTarget;S.setPointerCapture(v.pointerId);let x=v.clientX,C=v.clientY;const b=new w,M=new w,P=H=>{const G=H.clientX-x,ht=H.clientY-C;x=H.clientX,C=H.clientY;const rt=o.camera,ot=o.orbitControls.target,Z=rt.position.distanceTo(ot),ut=Math.max(1,S.ownerDocument.defaultView?.innerHeight??1),Y=2*Z*Math.tan(Wt.degToRad(rt.fov/2))/ut;b.setFromMatrixColumn(rt.matrixWorld,0).multiplyScalar(-G*Y),M.setFromMatrixColumn(rt.matrixWorld,1).multiplyScalar(ht*Y),rt.position.add(b).add(M),ot.add(b).add(M),o.orbitControls.update()},z=()=>{S.removeEventListener("pointermove",P),S.removeEventListener("pointerup",z),S.removeEventListener("pointercancel",z)};S.addEventListener("pointermove",P),S.addEventListener("pointerup",z),S.addEventListener("pointercancel",z)};return O.jsxs(O.Fragment,{children:[O.jsxs("div",{"data-testid":"viewport-view-text","aria-hidden":"true",style:{position:"absolute",top:"var(--vgai-space-3)",left:"calc(var(--vgai-space-4) + var(--vgai-control-comfortable-height) * 2 + var(--vgai-space-4))",display:"flex",flexDirection:"column",gap:"var(--vgai-space-1)",fontSize:"var(--vgai-font-sm)",color:c,textShadow:"var(--vgai-content-text-shadow, none)",pointerEvents:"none",userSelect:"none"},children:[O.jsx("span",{children:f}),O.jsx("span",{children:m}),r&&r.length>0?O.jsx("div",{"data-testid":"viewport-statistics",style:{display:"grid",gridTemplateColumns:`${lm}px auto`,rowGap:"var(--vgai-space-1)",marginTop:Hc[am]},children:r.map(v=>O.jsxs(F.Fragment,{children:[O.jsx("span",{children:v.label}),O.jsx("span",{children:v.value})]},v.id))}):null]}),O.jsxs("div",{"data-testid":"viewport-navigation",role:"toolbar","aria-label":"Navigation","aria-orientation":"vertical",className:"vgai-chrome-island vgai-viewport-navigation",style:{position:"absolute",top:rm,right:"var(--vgai-space-6)",display:"flex",flexDirection:"column",gap:"var(--vgai-space-1)",padding:"var(--vgai-space-1) 0",borderRadius:"var(--vgai-radius-full)",background:"var(--vgai-island-surface, var(--vgai-surface-overlay))",pointerEvents:"auto"},children:[O.jsx(Wi,{text:"Zoom in",children:O.jsx(Fe,{size:"comfortable","aria-label":"Zoom in",onClick:()=>y(.8),children:O.jsx(Le,{size:"2xl",icon:xe.viewport.zoomIn})})}),O.jsx(Wi,{text:"Zoom out",children:O.jsx(Fe,{size:"comfortable","aria-label":"Zoom out",onClick:()=>y(1.25),children:O.jsx(Le,{size:"2xl",icon:xe.viewport.zoomOut})})}),O.jsx(Wi,{text:"Pan (drag)",children:O.jsx(Fe,{size:"comfortable","aria-label":"Pan the view",onPointerDown:_,children:O.jsx(Le,{size:"2xl",icon:xe.viewport.pan})})}),O.jsx(Wi,{text:"Frame all",children:O.jsx(Fe,{size:"comfortable","aria-label":"Frame all",onClick:()=>{t?.frame()||o.focusOn(o.orbitControls.object)},children:O.jsx(Le,{size:"2xl",icon:xe.viewport.frame})})}),O.jsx(Wi,{text:h==="perspective"?"Orthographic":"Perspective",children:O.jsx(Fe,{size:"comfortable","aria-label":"Toggle perspective and orthographic","aria-pressed":h==="orthographic",onClick:()=>{const v=h==="perspective"?"orthographic":"perspective";t?t.setProjection(v):o.setProjection(v)},children:O.jsx(Le,{size:"2xl",icon:xe.viewport.projection})})})]})]})}const hm=F.lazy(async()=>({default:(await ri(()=>import("./stage-keyboard-CzlqI0nh.js"),__vite__mapDeps([27,3,4,5,2,6,7,8,9,10,1,11,15]))).StageKeyboardBinding})),dm=o=>{const t=o.split(":");return(t[0]==="document"?t[1]:t[0])??o},sl=()=>uh(),Pr=12;function nl(o){if(!o)return null;const t=new pe(new w(o.min[0],o.min[1],o.min[2]),new w(o.max[0],o.max[1],o.max[2]));return t.isEmpty()?null:t}const um=500;function pm(o){return Bn(null,o)}let fm=0;const wi=new Kf(o=>({documentId:o,store:new hl,inUse:!1,source:null,camera:null,presentation:null,transport:null,contentSeconds:0,transportAdvances:0}),o=>Yc().some(t=>t.descriptor.id===o),qc);function mm({canvasHostRef:o}){return O.jsx("div",{ref:o,style:{position:"absolute",inset:0}})}function gm(o,t,e,i,s){if(t==="inspector-preview"){const l=hh();return l.canvas.setAttribute("aria-label",`${e} authoring viewport`),o.appendChild(l.canvas),{canvas:l.canvas,renderer:l.renderer,lease:l}}const n=dh(i.width,i.height,s),{canvas:r,renderer:a}=n;return r.setAttribute("aria-label",`${e} authoring viewport`),o.appendChild(r),{canvas:r,renderer:a,lease:n}}class rl{constructor(t,e,i){this.lane=t,this.surface=e,this.store=i??new hl,this.transport=new ch(this.store)}scene=new Ln;store;cleanups=[];rendererSession=new Jf((t,e)=>this.frame?.(t,e),()=>{});viewport=null;session=null;dressing=null;presentationRig=null;applyPresentation=null;backdropOverridden=!1;documentStudio=null;contentLights=[];contentHas={light:!1,"directional-light":!1};darkened=[];darkenContentLights(){for(const e of this.contentLights)e.visible&&(e.visible=!1,this.darkened.push(e));if(this.darkened.length===0)return 0;const t=this.darkened.length;return this.scene.onAfterRender=()=>{for(const e of this.darkened)e.visible=!0;this.darkened=[],this.scene.onAfterRender=()=>{}},t}defaultEnvironment=null;defaultBackground=null;adapter=null;content=null;frame=null;syncHostScene=null;presence=null;initialized=!1;contentSeconds=0;transportAdvances=0;users=0;closed=!1;released=!1;get isClosed(){return this.closed}transport;borrow(){this.users++;let t=!1;return()=>{t||(t=!0,this.users--,this.releaseIfClosed())}}close(){this.closed=!0,this.frame=null,this.syncHostScene=null,this.session?.setBeforeRender(null),this.session?.setPresentsFrames(!1),this.rendererSession.setActive(!1),this.content?.dispose(),this.transport.dispose(),this.releaseIfClosed()}releaseIfClosed(){if(!this.closed||this.users!==0||this.released)return;this.released=!0;const{lease:t,renderer:e,canvas:i}=this.surface;for(const s of[...this.cleanups.splice(0),()=>this.session?.dispose(),()=>this.viewport?.dispose(),()=>this.rendererSession.dispose(),()=>this.dressing?.dispose(),...t?[()=>t.release()]:[()=>e.dispose(),()=>e.forceContextLoss(),()=>i.remove()]])try{s()}catch(n){console.error("Object3D document cleanup failed.",n)}}}function Wl({documentId:o,sourcePath:t,build:e,displayName:i="Source Object3D",background:s,cameraDirection:n,persistence:r,documentSource:a,authoring:l,interaction:c,selectionOutline:d=!0,active:h=!0,audit:f=!0,chromeless:u=!1,modelSource:p,assetType:m,sourceAuthoring:y,dressing:_,rendererLane:v="own",onOpenNode:S,frameBounds:x,openingFrameBounds:C,openingFit:b,stageKind:M,statistics:P,content:z}){const H=M??dm(o);F.useEffect(()=>{if(!u)return Dc(o)},[o,u]);const G=Uc(Vc()),ht=G??Tr(),rt=ht?cl(ht,o,u?"embedded":"document"):null,ot=F.useSyncExternalStore(pm,Fl),Z=rt!==null&&jc(rt,ot),ut=F.useRef(Z);ut.current=Z;const Y=rt!==null&&Gc(rt),pt=F.useRef(Y);pt.current=Y;const K=rt!==null&&Wc(rt),mt=F.useRef(K);mt.current=K;const gt=Xc(),zt=F.useRef(gt);zt.current=gt;const Lt=F.useRef(null),kt=F.useRef(null),q=F.useRef(null),St=F.useRef(null);(!St.current||St.current.documentId!==o)&&(St.current&&wi.release(St.current),St.current=wi.claim(o)),F.useEffect(()=>{const W=St.current,Ce=wi.generation(W);return()=>wi.release(W,Ce)},[o]);const B=St.current,ee=z?.kind==="world-root",Ve=h||ee,oi=F.useRef(z?.kind==="world-root"?z.load:null);oi.current=z?.kind==="world-root"?z.load:null;const[ie,je]=F.useState(Ve);F.useEffect(()=>je(Ve),[Ve]);const Ge=F.useRef(d);F.useEffect(()=>{Ge.current=d;const W=q.current?.session;W&&(W.selectionOutlineEnabled=v!=="inspector-preview"&&d),q.current?.applyPresentation?.()},[d,v]);const ai=F.useRef(Promise.resolve()),We=F.useRef(!1);F.useEffect(()=>{if(ie)return Xt.current=!1,tt("building"),()=>{const W=q.current;if(W&&!ee){We.current=!Se.current;const Ce=W.store.cameraPose;B.camera=Ce&&W.viewport?{...Ce,up:W.viewport.camera.up.clone()}:null,B.presentation=W.session?.presentation()??null,B.transport=W.transport.snapshot(),B.contentSeconds=W.contentSeconds,B.transportAdvances=W.transportAdvances}re.current=null,oe.current=null,ne.current=null,se.current=null,W?.close(),q.current=null}},[o,v,B,ie,ee]);const li=F.useRef(S);li.current=S;const ci=F.useRef(x);ci.current=x;const hi=F.useRef(C);hi.current=C;const Se=F.useRef(h);Se.current=h;const di=F.useRef(h),Me=F.useRef({build:e,sourcePath:t});F.useEffect(()=>{const W=Me.current;Me.current={build:e,sourcePath:t},!(W.build===e&&W.sourcePath===t)&&!ie&&B.source&&(B.source.dispose(),B.source=null)},[e,B,t,ie]);const se=F.useRef(null),Xt=F.useRef(!1),ne=F.useRef(null),re=F.useRef(null),oe=F.useRef(null),[me,_t]=F.useState(null),[ge,tt]=F.useState("building"),[so,Xl]=F.useState(null),[Jl,Yl]=F.useState("mounting"),[ql,Zl]=F.useState([]),no=F.useRef(null),[ro,Ql]=F.useState("perspective"),[$l,oo]=F.useState(null),js=F.useRef(null);js.current=$l;const Hn=n?.[0],Dn=n?.[1],Un=n?.[2],Li=p?.kind,Vn=p?.kind==="project-file"?p.path:void 0,Gs=p?.kind==="entity"?p.entityId:void 0,ao=_?.environment,lo=_?.background,co=_?.keyLight,jn=_?.grid,Bi=_?.viewLocked,Gn=_?.toneMapping;h&&ph(o),F.useEffect(()=>{let W=!1;if(!ie)return;const Ce=async Pe=>{const at=Lt.current,Ni=kt.current;if(!at||!Ni||q.current)return;const U=zt.current;if(!U){_t("The world root needs the editor shell above it; this host has none.");return}const Hi=await Pe();if(W||q.current)return;Xl(()=>Hi),Ho();const g=new rl("own",Hi.mountWorldRootSurface(Ni,at,i),Tr()??void 0);q.current=g,g.cleanups.push(Do(o,g.store)),g.cleanups.push(Uo(o,g.transport)),g.cleanups.push(lh(o,{...qf(g.store,o),...tl(o)}));const Vt=Hi.installWorldRootStage({store:g.store,documentId:o,container:at,canvas:g.surface.canvas,renderer:g.surface.renderer,stats:U,cameraPreview:()=>no.current,onMountStatus:Yl,onRootIds:Zl,runFrame:ze=>Wo(o,ze)});g.viewport=Vt.viewport,g.frame=Vt.frame,g.content={scene:Vt.scene,settle:()=>Promise.resolve(),dispose:async()=>Vt.dispose()};const et=sa(Vt.scene,g.transport);let Bt=0;g.cleanups.push(()=>et.dispose()),g.cleanups.push(g.store.subscribe(()=>{if(g.store.playState!=="stopped")return;const ze=performance.now();ze-Bt<um||(Bt=ze,et.refresh())})),g.cleanups.push(Xo({camera:Vt.viewport.camera,orbit:Vt.viewport.orbitControls,scene:Vt.scene},Vt.present,Vt.setHelper,{documentId:o})),se.current=g.rendererSession,g.initialized=!0,Jo(),tt("ready"),g.rendererSession.setActive(!0)},tc=async()=>{for(await q.current?.content?.settle();wd();)await xd();if(W)return;const Pe=oi.current;if(Pe)return Ce(Pe);const at=Lt.current,Ni=kt.current;if(!at||!Ni)return;if(!e||t===void 0){_t("This stage shows `build` content and was given no `build()`/`sourcePath`.");return}let U;const Hi=wi.generation(B);try{U=B.source??e(),B.source=null}catch(It){_t(It instanceof Error?It.message:String(It));return}try{q.current||(Ho(),q.current=new rl(v,gm(Ni,v,i,{width:Math.max(1,at.clientWidth),height:Math.max(1,at.clientHeight)},()=>{je(!1),window.setTimeout(()=>{Se.current&&je(!0)},0)}),B.store),q.current.contentSeconds=B.contentSeconds,q.current.transportAdvances=B.transportAdvances)}catch(It){throw U.dispose(),It}const g=q.current,Vt=g.borrow(),{renderer:et,canvas:Bt,lease:ze}=g.surface,it=g.store;u||(g.cleanups.push(Do(o,it)),g.cleanups.push(Uo(o,g.transport)));const Xs=Vo();Xs&&it.attachHistory(Xs);const uo=v==="inspector-preview",ui=ut.current,po=pt.current,fo=mt.current,st=new Ln,Js=U.root.parent;st.add(U.root),U.animations&&(U.root.animations=[...U.animations]);const Xn={root:U.root,animations:U.root.animations};let Di=null,Ui=null,pi=null,Ae=null,jt=null,Ys=null,qs=null,Zs=null,Qs=null,$s=null,Jn=null,mo=null,go=null,yo=!1,Ks=!1,tn=null;const Yn={scene:st,settle:()=>jt?.settle()??Promise.resolve(),dispose:()=>{if(tn)return tn;Ks=!0;const It=We.current;return We.current=!1,Ys&&at.removeEventListener("pointerdown",Ys,!0),qs&&at.removeEventListener("pointermove",qs,!0),Zs&&at.removeEventListener("pointerup",Zs,!0),Qs&&at.removeEventListener("pointercancel",Qs,!0),$s&&window.removeEventListener("keydown",$s),Jn?.(),Jn=null,tn=(async()=>{await jt?.settle();const Vi=[];for(const ye of[()=>Ae?.dispose(),()=>Ui?.dispose?.(),()=>Di?.dispose(),()=>st.removeFromParent(),()=>{It?wi.retain(B,U,Hi):U.dispose()},Vt])try{ye()}catch(en){Vi.push(en)}Vi.length&&console.error("Object3D source cleanup failed.",...Vi)})(),tn}};try{const It=async E=>{try{const L=Xn;if(a&&!r){if(!L)throw new Error("Project history is unavailable; the edit was not saved.");const A=Vo();if(!A)throw new Error("Project history is unavailable; the edit was not saved.");const I=a.serialize(L);if(I===null)return _t(null),!1;const X=await sl().replaceSource(A,{file:a.path,source:I,label:E??a.label??`Edit ${i}`});return _t(null),X}if(!r)throw new Error("This Asset Lab document has no persistence binding.");if(!pi||!L)throw new Error("Project history is unavailable; the edit was not saved.");const{persisted:N}=await(await pi).commit(L,E);return _t(null),N}catch(L){throw _t(L instanceof Error?L.message:JSON.stringify(L)),L}};Di=new io(it,st,{documentId:o,title:i,sourcePath:t,documentKind:fo?"asset":"source",audit:f,...U.hierarchyRoots?{hierarchyRoots:U.hierarchyRoots}:{},...Li==="project-file"&&Vn?{modelSource:{kind:Li,path:Vn}}:Li==="entity"&&Gs?{modelSource:{kind:Li,entityId:Gs}}:{}});const Vi={documentId:o,sourcePath:t,root:U.root,animations:U.root.animations,scene:st,defaultAdapter:Di,commit:It};Ui=l?.(Vi)??null,!Ui&&y&&(Ui=y({store:it,scene:st,...U.hierarchyRoots?{hierarchyRoots:U.hierarchyRoots}:{}}),Di.dispose()),pi=r&&Xs?sl().openPersistence({binding:r,document:Xn,history:Xs}):null,pi&&pi.catch(E=>{!Ks&&q.current?.content===Yn&&_t(E instanceof Error?E.message:JSON.stringify(E))});const ye=Ui?.adapter??Di;if(!g.dressing){et.outputColorSpace=Hs,et.toneMapping=Gn??bl,et.shadowMap.enabled=!0,et.shadowMap.type=od,et.info.autoReset=!1,et.setPixelRatio(Math.min(window.devicePixelRatio,2)),ui&&et.setClearColor(0,0);const E=ao===!1?null:ze&&"environment"in ze?ze.environment():Zc(et),L=Bs(Bt);g.dressing=yh(g.scene,{environment:E,background:!ui&&s===void 0&&lo!==!1,keyLight:!1,grid:jn===!0,content:U.root}),!ui&&s!==void 0?g.scene.background=new D(s):!ui&&L.background!==null&&(g.scene.background=new D(L.background)),g.defaultEnvironment=g.scene.environment,g.defaultBackground=g.scene.background;{const N=new dl(g.scene,ct);g.presentationRig=N,Ar(o,H);const A=()=>{const I=al(o);N.apply(I,et,Gn),g.viewport?.setStageFunction(I.world,I.interaction),g.viewport?.setSelectionMarks(I.overlays.selection),g.viewport?.setGridMajorEvery(I.overlays.grid.majorEvery),g.viewport?.setAxisLines(I.overlays.axes),g.viewport?.setNavigation(I.overlays.navigation),g.viewport?.setGridVisible(I.overlays.grid.visible),g.session&&(g.session.selectionOutlineEnabled=!uo&&Ge.current&&I.overlays.selection.outline),ct()};g.applyPresentation=A,A(),g.cleanups.push(ol(A)),g.cleanups.push(Qc(()=>{N.forgetFailedImages(),A()})),g.cleanups.push(()=>{N.dispose(),g.presentationRig===N&&(g.presentationRig=null)})}g.cleanups.push(()=>{g.defaultBackground instanceof Ko&&g.defaultBackground!==g.dressing?.backgroundTexture&&g.defaultBackground.dispose()})}const en=(E,L)=>{const N=g.adapter,A=g.viewport;if(!N||!A)return null;const I=Bt.getBoundingClientRect(),X=new Ht((E-I.left)/Math.max(I.width,1)*2-1,-((L-I.top)/Math.max(I.height,1))*2+1),wt=new $t;wt.layers.enableAll(),wt.setFromCamera(X,g.session?.camera()??A.camera);for(const Te of wt.intersectObjects([...it.objectMap.values()],!0)){if(he(Te.object))continue;let _e=Te.object;for(;_e;){const on=N.hierarchy.idForObject3D?.(_e);if(on)return on;_e=_e.parent}}return null};if(!g.viewport){g.viewport=new eo(Bt,g.scene,it,at,{renderer:et,authoring:()=>g.adapter??ye,pick:en,publishPickContext:!1,onProjectionChange:Ql,chromeInsetPx:u||po?0:Pr,lightRig:!1}),jn===!0&&g.viewport.grid.removeFromParent();const E=L=>{const N=en(L.clientX,L.clientY),A=N?g.adapter?.hierarchy.object3D?.(N):null;A&&li.current?.(A)};at.addEventListener("dblclick",E),g.cleanups.push(()=>at.removeEventListener("dblclick",E))}const V=g.viewport;if(Bi){const E=V.camera;g.scene.add(E);const L=new Ft;L.name="vgai:document-studio",L.add(Bi),E.add(L),g.documentStudio=L,g.cleanups.push(()=>{Bi.removeFromParent(),L.removeFromParent(),g.documentStudio===L&&(g.documentStudio=null),E.removeFromParent()})}if(c){const E=new Ft;E.name="__object3d_document_overlay",Dt(E,"editorHelper",!0),st.add(E),Ae=c.setup({root:U.root,scene:st,renderer:et,overlay:E,camera:()=>g.session?.camera()??V.camera,writable:r!==void 0||a!==void 0});const L=A=>{const I=Bt.getBoundingClientRect(),X=new Ht((A.clientX-I.left)/Math.max(I.width,1)*2-1,-((A.clientY-I.top)/Math.max(I.height,1))*2+1),wt=new $t;return wt.layers.enableAll(),wt.setFromCamera(X,g.session?.camera()??V.camera),{pointerId:A.pointerId,button:A.button,buttons:A.buttons,clientX:A.clientX,clientY:A.clientY,altKey:A.altKey,ctrlKey:A.ctrlKey,metaKey:A.metaKey,shiftKey:A.shiftKey,ray:wt.ray.clone(),hits:wt.intersectObjects([U.root,E],!0)}};jt=new Ef({begin:A=>{if(!r&&!a)throw new Error("This Asset Lab document has no persistence binding; project gestures are read-only.");return Ae.begin(A)},persist:async A=>{await It(A)},reportError:A=>_t(A instanceof Error?A.message:JSON.stringify(A))});const N=A=>{A.preventDefault(),A.stopPropagation()};Ys=A=>{A.target instanceof Element&&A.target.closest('[role="alert"], [role="toolbar"]')!==null||jt?.begin(L(A))&&(N(A),A.isTrusted&&Bt.setPointerCapture?.(A.pointerId))},qs=A=>{jt?.hasActiveGesture()&&(N(A),jt.update(L(A)))},Zs=A=>{jt?.hasActiveGesture()&&(N(A),Bt.hasPointerCapture?.(A.pointerId)&&Bt.releasePointerCapture?.(A.pointerId),jt.commit(L(A)))},Qs=A=>{jt?.hasActiveGesture()&&(N(A),jt.cancel(A.pointerId))},$s=A=>{A.key!=="Escape"||!jt?.hasActiveGesture()||(A.preventDefault(),jt.cancel())},mo=()=>{at.addEventListener("pointerdown",Ys,!0),at.addEventListener("pointermove",qs,!0),at.addEventListener("pointerup",Zs,!0),at.addEventListener("pointercancel",Qs,!0),window.addEventListener("keydown",$s)}}const Xe=g.content,_o=[...it.selectedEntityIds],ji=g.adapter,ic=new Map(it.objectMap),fi=g.session?.root,sc=g.frame,nc=g.syncHostScene,rc=re.current,oc=oe.current,ac=ne.current,vo=g.session?.neutralBackgroundTexture(),lc=g.dressing.lights.map(E=>E.visible),cc=g.cleanups.length,hc=g.initialized;if(go=()=>{st.removeFromParent(),Js&&Js.add(U.root),Xe&&g.scene.add(Xe.scene),g.adapter=ji,g.content=Xe,g.frame=sc,g.syncHostScene=nc,g.initialized=hc;for(const E of g.cleanups.splice(cc))E();!fi&&g.session&&(g.session.dispose(),g.session=null),it.objectMap.clear();for(const[E,L]of ic)it.objectMap.set(E,L);Xe&&it.bindScene(Xe.scene,et,V.batchedRenderer,V.camera),fi&&ji&&g.session?.replaceContent(fi,ji),re.current=rc,oe.current=oc,ne.current=ac,js.current=ji,oo(ji),vo!==void 0&&g.session?.setNeutralBackground(vo),g.dressing?.lights.forEach((E,L)=>{E.visible=lc[L]??!0}),fi&&(g.dressing?.frameContent(fi),g.presentationRig?.placeFloor(fi)),it.selectMultiple(_o),it.notifyIngestObjectMapEdit()},Xe?.scene.removeFromParent(),g.scene.add(st),g.adapter=ye,g.content=Yn,it.bindScene(st,et,V.batchedRenderer,V.camera),it.setOrbitTarget(V.orbitControls.target),it.objectMap.clear(),st.traverse(E=>{const L=ye.hierarchy.idForObject3D?.(E);L&&it.objectMap.set(L,E)}),g.session)g.session.replaceContent(U.root,ye);else{const E=nl(ci.current),L=nl(hi.current)??E;if(L||V.focusOn(U.root),Hn!==void 0&&Dn!==void 0&&Un!==void 0){const N=L??$e(U.root),A=N.getCenter(new w),I=new w(Hn,Dn,Un).normalize(),X=ti(N,V.camera,I)*Math.min(10,Math.max(.1,b??1));V.camera.position.copy(A).add(I.multiplyScalar(X)),V.orbitControls.target.copy(A)}if(g.session=new Af(o,U.root,g.scene,et,V,ye,ui?null:s===void 0?g.dressing.backgroundTexture:new D(s),E),g.session.selectionOutlineEnabled=!uo&&Ge.current,g.applyPresentation?.(),!ui&&s===void 0&&g.dressing.backgroundTexture){const N=g.session;g.cleanups.push(_h(()=>{const A=Bs(Bt).background,I=g.defaultBackground;g.defaultBackground=A!==null?new D(A):vh(),N.neutralBackgroundTexture()===I&&N.setNeutralBackground(g.defaultBackground),I instanceof Ko&&I!==g.dressing?.backgroundTexture&&I.dispose()}))}}const Gi=B.camera;Gi&&(V.camera.up.copy(Gi.up),V.setProjection(ro),V.setPose(Gi.position,Gi.target,Gi.fov||void 0),B.camera=null);const dt=g.session;re.current=Xn,oe.current=pi,ne.current=Ae,js.current=ye,oo(ye),Ar(o,H,Bi?{all:{lighting:{source:"studio",studioPreset:jo.id,auto:null}}}:co===!1?{all:{lighting:{source:"scene"}}}:null);const sn=[];U.root.traverse(E=>{E.isLight&&sn.push(E)});const dc={light:sn.length>0,"directional-light":sn.some(E=>E.isDirectionalLight)};g.contentLights=sn,g.contentHas=dc,g.dressing.frameContent(U.root),g.presentationRig?.placeFloor(U.root),g.cleanups.push(it.subscribe(()=>g.presentationRig?.placeFloor(U.root))),it.selectMultiple(_o.filter(E=>it.objectMap.has(E))),it.notifyIngestObjectMapEdit(),dt.syncSelectionPresentation(),mo?.(),_t(null),u||Go(o);let nn=st.background;dt.setNeutralBackground(nn??g.defaultBackground);const mi=B.presentation;mi&&(dt.setMode(mi.mode),dt.setBackground(mi.background),dt.setProjection(mi.projection),dt.setSkeleton(mi.skeleton),dt.setBounds(mi.bounds),B.presentation=null);const uc=()=>{g.scene.environment=st.environment??g.defaultEnvironment,g.scene.fog=st.fog,g.scene.environmentIntensity=st.environmentIntensity,g.scene.environmentRotation.copy(st.environmentRotation),g.scene.backgroundIntensity=st.backgroundIntensity,g.scene.backgroundBlurriness=st.backgroundBlurriness,g.scene.backgroundRotation.copy(st.backgroundRotation);const E=g.presentationRig;if(E){const L=E.resolveSource({...g.contentHas,environment:st.environment!==null}),N=E.environment();N&&(g.scene.environment=N.texture??g.defaultEnvironment,g.scene.environmentIntensity=N.intensity,g.scene.environmentRotation.set(0,N.rotation,0));const A=E.backdrop();A!=="keep"?(g.scene.background=A.value,g.scene.backgroundBlurriness=A.blur,g.scene.backgroundIntensity=A.intensity,g.scene.backgroundRotation.set(0,A.rotation,0),g.backdropOverridden=!0):g.backdropOverridden&&(g.scene.background=dt.neutralBackgroundTexture(),g.scene.backgroundBlurriness=st.backgroundBlurriness,g.scene.backgroundIntensity=st.backgroundIntensity,g.backdropOverridden=!1);const I=L==="studio"&&E.presetId()===jo.id;g.documentStudio&&(g.documentStudio.visible=I);const X=L==="studio"&&!I||L==="preview"&&!E.sceneLightsShown()?g.darkenContentLights():0;E.update(dt.camera()),$c(o,{source:L,presetId:E.presetId(),presetLights:E.lightsVisible(),documentStudio:g.documentStudio?g.documentStudio.visible:null,contentLights:g.contentLights.length,contentLightsDarkened:X,environmentIntensity:g.scene.environmentIntensity,environmentImage:E.imageReport().shown,environmentImagePending:E.imageReport().pending,toneMapping:String(et.toneMapping)})}nn!==st.background&&(nn=st.background,dt.setNeutralBackground(nn??g.defaultBackground))};g.syncHostScene=uc,dt.setBeforeRender(()=>g.syncHostScene?.()),dt.setPresentsFrames(!0);const pc=E=>{Ks||!(E>0)||!Number.isFinite(E)||(g.contentSeconds+=E,g.transportAdvances++,U.update?.(E))},fc=sa(U.root,g.transport);g.cleanups.push(()=>fc.dispose());const Ee=B.transport;Ee&&(Ee.activeSubject&&g.transport.setActiveSubject(Ee.activeSubject),g.transport.setLoop(Ee.range.loop),g.transport.setTimeScale(Ee.timeScale),g.transport.seek(Ee.time),Ee.playbackState==="playing"?g.transport.play():Ee.playbackState==="paused"&&g.transport.pause(),B.transport=null);let qn=performance.now();const wo=typeof U.onChange=="function";let Zn=!0;const rn=()=>{Zn=!0};if(wo){const E=U.onChange(rn),L=it.subscribe(rn),N=["pointerdown","pointermove","pointerup","pointerleave","wheel","keydown","keyup"];for(const A of N)at.addEventListener(A,rn,{capture:!0,passive:!0});Jn=()=>{E(),L();for(const A of N)at.removeEventListener(A,rn,{capture:!0})}}let xo=-1;const bo=new Ci,So=new Ci,Mo=new Ht,Co=new Ht;let Po,zo=null,Ao=Number.NaN;const mc=E=>{if(!wo||Zn||E>0||Yo()!==xo||dt.needsFrame()||g.presence?.live()||Ae?.prepareFrame||Ae?.update||(V.batchedRenderer.batches?.length??0)>0)return!0;const L=dt.camera();return L.updateMatrixWorld(),et.getDrawingBufferSize(Co),!L.matrixWorld.equals(bo)||!L.projectionMatrix.equals(So)||!Co.equals(Mo)||g.scene.background!==Po||et.toneMapping!==zo||et.toneMappingExposure!==Ao},gc=()=>{Zn=!1,xo=Yo();const E=dt.camera();bo.copy(E.matrixWorld),So.copy(E.projectionMatrix),et.getDrawingBufferSize(Mo),Po=g.scene.background,zo=et.toneMapping,Ao=et.toneMappingExposure},yc=(E,L)=>{if(Ks||!et||!V)return;const N=et,A=V,I=dt?.profiler;I?.beginFrame(),L&&(qn=E);const X=Math.min((E-qn)/1e3,.1);qn=E,I?.beginPhase();const wt=g.transport.tick(X);if(wt>0&&pc(wt),Ae?.prepareFrame?.(X),Ae?.update?.(X),I?.endPhase("animation"),I?.beginPhase(),g.presence?.syncMarkers(X),V.update(X),u||Wo(o,X),V.batchedRenderer.update(X),I?.endPhase("editor"),!L&&!mc(wt)){I?.endFrame();return}I?.beginPhase(),N.info.reset();const Te=!Xt.current&&Kc()===o;Te&&th(o);const _e=Te?Date.now():0,on=g.scene.overrideMaterial,Eo=dt.presentation().mode;Eo!=="uv"&&Eo!=="vertex-colors"&&(g.scene.overrideMaterial=st.overrideMaterial);try{A.renderWithInfrastructure(()=>{dt.renderViewport(X),A.renderViewCube(N)})}finally{g.scene.overrideMaterial=on}dt.servePresentedFrame(),gc(),Xt.current||(Xt.current=!0,Te&&eh("first-render",Date.now()-_e),ih(o),tt("ready")),I?.reportRender({gpuMs:null,drawCalls:N.info.render.calls,triangles:N.info.render.triangles,geometries:N.info.memory.geometries,textures:N.info.memory.textures}),I?.endPhase("render"),I?.endFrame();const Jt=zt.current;if(Jt&&G&&sh(G)===it){const gi=dt.cameraPose();Jt.frameTime=X*1e3,Jt.fps=X>0?1/X:0,Jt.drawCalls=N.info.render.calls,Jt.triangles=N.info.render.triangles,Jt.cameraPosition.x=gi.position[0],Jt.cameraPosition.y=gi.position[1],Jt.cameraPosition.z=gi.position[2],Jt.cameraTarget.x=gi.target[0],Jt.cameraTarget.y=gi.target[1],Jt.cameraTarget.z=gi.target[2]}};if(g.frame=yc,se.current=g.rendererSession,!g.initialized){u||(g.cleanups.push(Xo({camera:V.camera,orbit:V.orbitControls,scene:g.scene},()=>null,(I,X)=>V.setHelper(I,X),{documentId:o})),ri(()=>import("./stage-presence-markers-S1lMOwIa.js"),__vite__mapDeps([28,6,4,3,5,7,8,2,9,10,1,11])).then(I=>{if(g.isClosed||q.current!==g||g.presence)return;const X=I.bindStagePresenceMarkers({scene:g.scene,store:it,documentId:o,container:at,canvas:Bt,viewport:V,readVisibleCameraPose:()=>{const wt=g.session?.camera()??V.renderCamera,Te=wt.getWorldPosition(new w),_e=wt.fov;return{position:Te,target:V.orbitControls.target,fov:typeof _e=="number"?_e:0}}});g.presence=X,g.cleanups.push(()=>X.dispose())}),g.cleanups.push(nh(dt,tl(o))),g.cleanups.push(rh({id:o,label:i,kind:fo?"asset":"source",profiler:dt.profiler}))),!u&&!po&&g.cleanups.push(oh(o,()=>({adapter:g.adapter,nodeId:g.adapter?.selection?.get()[0]??null})));const E=u?`${o}#chromeless-${++fm}`:o;g.cleanups.push(ah({id:E,label:i,contentClock:()=>g.contentSeconds,transportAdvances:()=>g.transportAdvances})),g.cleanups.push(it.onViewportAction(I=>{switch(I.type){case"focus-selection":case"focus-scene":!g.session?.frame()&&g.session?.root&&V.focusOn(g.session.root);break;case"focus-entity":{const X=g.adapter?.hierarchy.object3D?.(I.id)??null;X&&V.focusOn(X);break}case"snap-selection-to-floor":V.snapSelectionToFloor();break;case"set-view-preset":V.setViewPreset(I.preset);break;case"set-camera-pose":V.setPose(I.position,I.target,I.fov);break}}));let L="";g.cleanups.push(it.subscribe(()=>{V.objectMap=it.objectMap,V.syncFromStore(),g.session?.syncSelectionPresentation();const I=(g.adapter?.selection?.get()??[]).join("\0");I!==L&&(L=I,u||Go(o))}));const N=()=>{const I=Math.max(1,at.clientWidth),X=Math.max(1,at.clientHeight),wt=et.getPixelRatio();(Bt.width!==Math.floor(I*wt)||Bt.height!==Math.floor(X*wt))&&et.setSize(I,X,!1),V.resize(I,X),g.session?.resize(I,X),g.rendererSession.redraw()},A=new ResizeObserver(N);A.observe(at),g.cleanups.push(()=>A.disconnect()),N(),g.initialized=!0,Jo()}V.objectMap=it.objectMap,V.syncFromStore(),g.rendererSession.setActive(Se.current),g.rendererSession.redraw(),yo=!0,Xe?.dispose()}catch(It){if(!yo)try{go?.()}finally{Js&&U.root.parent===st&&Js.add(U.root),Yn.dispose()}console.error(`[object3d document] ${i}: source update failed`,It),_t(It instanceof Error?It.message:String(It))}},ec=ai.current.then(tc);return ai.current=ec.catch(Pe=>{W||_t(Pe instanceof Error?Pe.message:String(Pe))}),()=>{W=!0}},[l,s,e,Hn,Dn,Un,i,o,Z,lo,ao,jn,co,Bi,Gn,u,Gs,Li,Vn,c,r,a,v,B,ie,y,t,ee]),F.useEffect(()=>{const W=se.current,Ce=h&&!di.current;di.current=h,W&&(Ce&&(Xt.current=!1,fh(o)),W.setActive(h||ee))},[h,o,ee]);const Ws=q.current,Wn=ge==="ready"&&Ws?.viewport?{store:Ws.store,viewport:Ws.viewport,canvas:Ws.surface.canvas}:null,Kl=F.useCallback(()=>{const W=js.current;return W?{adapter:W,nodeId:W.selection?.get()[0]??W.hierarchy.roots()[0]?.id??null}:null},[]),ho=O.jsx("div",{"data-testid":"tool-object3d-authoring","data-vgai-chromeless":u||void 0,className:Z?"vgai-object3d-studio-stage":void 0,style:{position:u||Y?"relative":"absolute",...u?{width:"100%",height:"100%"}:Y?{flex:1,minHeight:0}:{inset:-Pr},overflow:"hidden",background:Z?void 0:Gt.surface.raised,pointerEvents:"auto"},children:O.jsxs("div",{ref:Lt,style:{position:"absolute",inset:0,minHeight:0,overflow:"hidden"},children:[O.jsx(mm,{canvasHostRef:kt}),h&&Wn&&!u?O.jsx(F.Suspense,{fallback:null,children:O.jsx(hm,{stage:Wn})}):null,G&&!u?O.jsx(em,{store:G,documentId:o,stage:Wn,active:h,chrome:"document"}):null,G&&so?O.jsx(so.Overlays,{store:G,documentId:o,cameraPreviewRef:no,mountStatus:Jl,rootIds:ql}):null,me&&O.jsx("div",{role:"alert",style:{position:"absolute",insetInline:0,top:0,display:"flex",justifyContent:"center",padding:"var(--vgai-space-3)",pointerEvents:"none"},children:O.jsxs("div",{className:"vgai-chrome-island",style:{display:"flex",alignItems:"center",gap:"var(--vgai-space-3)",maxWidth:"80%",padding:"var(--vgai-space-2) var(--vgai-space-3)",borderRadius:"var(--vgai-radius-md)",border:`var(--vgai-stroke-resting) solid ${Gt.semantic.danger}`,background:Gt.surface.raised,color:Gt.semantic.danger,pointerEvents:"auto"},children:[O.jsx("span",{children:me}),O.jsx(Fe,{size:"compact","aria-label":"Dismiss",onClick:()=>_t(null),"data-testid":"object3d-document-error-dismiss",children:O.jsx(Le,{icon:xe.action.close})})]})}),!me&&ge==="building"&&O.jsx(mh,{testId:"object3d-document-status",children:gh}),O.jsx("div",{style:{position:"absolute",inset:u||Y?0:Pr,pointerEvents:"none"},children:!u&&ge==="ready"&&q.current&&O.jsx(cm,{viewport:q.current.viewport,session:q.current.session,store:q.current.store,projection:ro,displayName:i,...P?{statistics:P}:{},objectName:W=>q.current?.adapter?.hierarchy.object3D?.(W)?.name??q.current?.store.objectMap.get(W)?.name??null})})]})});return Y?O.jsx(Jc,{documentId:o,active:h,type:m??(Gs?"entity":"model"),title:i,status:t,selection:Kl,fill:!0,children:O.jsxs("div",{className:"vgai-object3d-asset-workspace",children:[ho,O.jsx(nm,{transport:q.current?.transport??null})]})}):ho}function ym(o){return O.jsx(Wl,{...o})}const Rm=Object.freeze(Object.defineProperty({__proto__:null,Object3DDocumentViewport:Wl,ToolObject3DAuthoring:ym},Symbol.toStringTag,{value:"Module"}));export{qr as C,kn as G,Wl as O,Im as Q,Rm as S,j as V,Zf as t};