@needle-tools/engine 4.3.0-alpha → 4.3.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/needle-engine.bundle.js +1467 -222
  3. package/dist/needle-engine.bundle.light.js +1467 -222
  4. package/dist/needle-engine.bundle.light.min.js +32 -32
  5. package/dist/needle-engine.bundle.light.umd.cjs +3 -3
  6. package/dist/needle-engine.bundle.min.js +3 -3
  7. package/dist/needle-engine.bundle.umd.cjs +3 -3
  8. package/dist/needle-engine.light.d.ts +9 -9
  9. package/lib/engine/engine_types.d.ts +162 -17
  10. package/lib/engine-components/Animator.d.ts +129 -21
  11. package/lib/engine-components/Animator.js +115 -21
  12. package/lib/engine-components/Animator.js.map +1 -1
  13. package/lib/engine-components/AnimatorController.d.ts +161 -32
  14. package/lib/engine-components/AnimatorController.js +176 -29
  15. package/lib/engine-components/AnimatorController.js.map +1 -1
  16. package/lib/engine-components/AudioListener.d.ts +16 -5
  17. package/lib/engine-components/AudioListener.js +16 -5
  18. package/lib/engine-components/AudioListener.js.map +1 -1
  19. package/lib/engine-components/AudioSource.d.ts +120 -28
  20. package/lib/engine-components/AudioSource.js +120 -37
  21. package/lib/engine-components/AudioSource.js.map +1 -1
  22. package/lib/engine-components/AvatarLoader.d.ts +61 -0
  23. package/lib/engine-components/AvatarLoader.js +61 -1
  24. package/lib/engine-components/AvatarLoader.js.map +1 -1
  25. package/lib/engine-components/AxesHelper.d.ts +19 -1
  26. package/lib/engine-components/AxesHelper.js +19 -1
  27. package/lib/engine-components/AxesHelper.js.map +1 -1
  28. package/lib/engine-components/BoxHelperComponent.d.ts +26 -0
  29. package/lib/engine-components/BoxHelperComponent.js +26 -0
  30. package/lib/engine-components/BoxHelperComponent.js.map +1 -1
  31. package/lib/engine-components/Camera.d.ts +126 -37
  32. package/lib/engine-components/Camera.js +139 -37
  33. package/lib/engine-components/Camera.js.map +1 -1
  34. package/lib/engine-components/CameraUtils.js +20 -0
  35. package/lib/engine-components/CameraUtils.js.map +1 -1
  36. package/lib/engine-components/Collider.d.ts +95 -21
  37. package/lib/engine-components/Collider.js +100 -23
  38. package/lib/engine-components/Collider.js.map +1 -1
  39. package/lib/engine-components/Component.d.ts +554 -106
  40. package/lib/engine-components/Component.js +352 -81
  41. package/lib/engine-components/Component.js.map +1 -1
  42. package/lib/engine-components/DragControls.d.ts +95 -21
  43. package/lib/engine-components/DragControls.js +126 -32
  44. package/lib/engine-components/DragControls.js.map +1 -1
  45. package/lib/engine-components/DropListener.d.ts +99 -16
  46. package/lib/engine-components/DropListener.js +119 -14
  47. package/lib/engine-components/DropListener.js.map +1 -1
  48. package/lib/engine-components/Light.d.ts +102 -5
  49. package/lib/engine-components/Light.js +102 -44
  50. package/lib/engine-components/Light.js.map +1 -1
  51. package/lib/engine-components/NeedleMenu.d.ts +28 -11
  52. package/lib/engine-components/NeedleMenu.js +28 -11
  53. package/lib/engine-components/NeedleMenu.js.map +1 -1
  54. package/lib/engine-components/Networking.d.ts +37 -5
  55. package/lib/engine-components/Networking.js +37 -5
  56. package/lib/engine-components/Networking.js.map +1 -1
  57. package/lib/engine-components/SceneSwitcher.js +44 -0
  58. package/lib/engine-components/SceneSwitcher.js.map +1 -1
  59. package/lib/engine-components/SpatialTrigger.d.ts +66 -1
  60. package/lib/engine-components/SpatialTrigger.js +74 -2
  61. package/lib/engine-components/SpatialTrigger.js.map +1 -1
  62. package/lib/engine-components/SpectatorCamera.d.ts +66 -4
  63. package/lib/engine-components/SpectatorCamera.js +132 -6
  64. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  65. package/lib/engine-components/SyncedTransform.d.ts +45 -6
  66. package/lib/engine-components/SyncedTransform.js +45 -6
  67. package/lib/engine-components/SyncedTransform.js.map +1 -1
  68. package/lib/engine-components/TransformGizmo.d.ts +49 -3
  69. package/lib/engine-components/TransformGizmo.js +49 -3
  70. package/lib/engine-components/TransformGizmo.js.map +1 -1
  71. package/lib/engine-components/webxr/WebXR.d.ts +131 -22
  72. package/lib/engine-components/webxr/WebXR.js +132 -23
  73. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  74. package/lib/engine-components-experimental/networking/PlayerSync.d.ts +82 -9
  75. package/lib/engine-components-experimental/networking/PlayerSync.js +76 -11
  76. package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
  77. package/package.json +1 -1
  78. package/src/engine/engine_types.ts +179 -18
  79. package/src/engine-components/Animator.ts +142 -22
  80. package/src/engine-components/AnimatorController.ts +184 -34
  81. package/src/engine-components/AudioListener.ts +16 -5
  82. package/src/engine-components/AudioSource.ts +126 -37
  83. package/src/engine-components/AvatarLoader.ts +61 -2
  84. package/src/engine-components/AxesHelper.ts +21 -1
  85. package/src/engine-components/BoxHelperComponent.ts +26 -0
  86. package/src/engine-components/Camera.ts +147 -41
  87. package/src/engine-components/CameraUtils.ts +20 -0
  88. package/src/engine-components/Collider.ts +102 -27
  89. package/src/engine-components/Component.ts +605 -129
  90. package/src/engine-components/DragControls.ts +134 -38
  91. package/src/engine-components/DropListener.ts +143 -23
  92. package/src/engine-components/Light.ts +105 -44
  93. package/src/engine-components/NeedleMenu.ts +29 -11
  94. package/src/engine-components/Networking.ts +37 -6
  95. package/src/engine-components/SceneSwitcher.ts +48 -1
  96. package/src/engine-components/SpatialTrigger.ts +80 -3
  97. package/src/engine-components/SpectatorCamera.ts +136 -18
  98. package/src/engine-components/SyncedTransform.ts +50 -7
  99. package/src/engine-components/TransformGizmo.ts +49 -4
  100. package/src/engine-components/webxr/WebXR.ts +144 -27
  101. package/src/engine-components-experimental/networking/PlayerSync.ts +85 -13
@@ -130,7 +130,7 @@ Open this page to get the console: `+t.toString())}const s=exports.DeviceUtiliti
130
130
  #__vconsole .vc-mask {
131
131
  overflow: hidden;
132
132
  }
133
- `,mi==null||mi.prepend(i),s===!0&&jm()<=0&&ov(),console.log("🌵 Debug console has loaded")}},t.onerror=()=>{console.warn("🌵 Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),gl=!1,Ht=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function yS(){if(!globalThis.VConsole)return;const s=new VConsole.VConsolePlugin("needle-console","🌵 Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+s._id+" iframe");return s.on("renderTab",function(e){const i=globalThis["needle:codegen_files"];if(!i||i.length===0)return;let n=globalThis["needle:codegen_files"][0];const o=n.indexOf("?");o>-1&&(n=n.substring(0,o));const l=location.protocol+"//"+location.host+location.pathname+"/"+n,c=encodeURIComponent(l);s.fullUrl="https://viewer.needle.tools?inspect&file="+c;var d='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';e(d)}),s.on("show",function(){const e=t();e&&e.src!==s.fullUrl&&(e.src=s.fullUrl)}),s.on("hide",function(){const e=t();e&&(e.src="")}),s.on("addTopBar",function(e){var i=new Array;i.push({name:"Open in new window ↗",onClick:function(n){window.open(s.fullUrl,"_blank"),Ht==null||Ht.hide()}}),i.push({name:"Reload",onClick:function(n){const o=t();o&&(o.src=s.fullUrl)}}),i.push({name:"Fullscreen",onClick:function(n){const o=t();o.requestFullscreen?o.requestFullscreen():o.webkitRequestFullscreen instanceof Function&&o.webkitRequestFullscreen()}}),e(i)}),s}function bS(){const s=document.querySelector("#__vconsole .vc-switch");return s||null}function vS(){const s=document.querySelector("#__vconsole");return s||null}const lv=S("debugdefines");yo('if(!globalThis[""4.3.0-alpha""]) globalThis[""4.3.0-alpha""] = "0.0.0";');yo('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";');yo('if(!globalThis[""Fri Feb 28 2025 13:27:32 GMT+0100 (Central European Standard Time)""]) globalThis[""Fri Feb 28 2025 13:27:32 GMT+0100 (Central European Standard Time)""] = "unknown";');yo('if(!globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""]) globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""] = "unknown";');yo('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.3.0-alpha";');yo('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";');yo('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Fri Feb 28 2025 13:27:32 GMT+0100 (Central European Standard Time)";');yo('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9";');const ln="4.3.0-alpha",Su="undefined",Gm="Fri Feb 28 2025 13:27:32 GMT+0100 (Central European Standard Time)";lv&&console.log(`Engine version: ${ln} (generator: ${Su})
133
+ `,mi==null||mi.prepend(i),s===!0&&jm()<=0&&ov(),console.log("🌵 Debug console has loaded")}},t.onerror=()=>{console.warn("🌵 Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),gl=!1,Ht=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function yS(){if(!globalThis.VConsole)return;const s=new VConsole.VConsolePlugin("needle-console","🌵 Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+s._id+" iframe");return s.on("renderTab",function(e){const i=globalThis["needle:codegen_files"];if(!i||i.length===0)return;let n=globalThis["needle:codegen_files"][0];const o=n.indexOf("?");o>-1&&(n=n.substring(0,o));const l=location.protocol+"//"+location.host+location.pathname+"/"+n,c=encodeURIComponent(l);s.fullUrl="https://viewer.needle.tools?inspect&file="+c;var d='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';e(d)}),s.on("show",function(){const e=t();e&&e.src!==s.fullUrl&&(e.src=s.fullUrl)}),s.on("hide",function(){const e=t();e&&(e.src="")}),s.on("addTopBar",function(e){var i=new Array;i.push({name:"Open in new window ↗",onClick:function(n){window.open(s.fullUrl,"_blank"),Ht==null||Ht.hide()}}),i.push({name:"Reload",onClick:function(n){const o=t();o&&(o.src=s.fullUrl)}}),i.push({name:"Fullscreen",onClick:function(n){const o=t();o.requestFullscreen?o.requestFullscreen():o.webkitRequestFullscreen instanceof Function&&o.webkitRequestFullscreen()}}),e(i)}),s}function bS(){const s=document.querySelector("#__vconsole .vc-switch");return s||null}function vS(){const s=document.querySelector("#__vconsole");return s||null}const lv=S("debugdefines");yo('if(!globalThis[""4.3.0-alpha.1""]) globalThis[""4.3.0-alpha.1""] = "0.0.0";');yo('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";');yo('if(!globalThis[""Mon Mar 03 2025 10:04:15 GMT+0100 (Central European Standard Time)""]) globalThis[""Mon Mar 03 2025 10:04:15 GMT+0100 (Central European Standard Time)""] = "unknown";');yo('if(!globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""]) globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""] = "unknown";');yo('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.3.0-alpha.1";');yo('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";');yo('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Mon Mar 03 2025 10:04:15 GMT+0100 (Central European Standard Time)";');yo('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9";');const ln="4.3.0-alpha.1",Su="undefined",Gm="Mon Mar 03 2025 10:04:15 GMT+0100 (Central European Standard Time)";lv&&console.log(`Engine version: ${ln} (generator: ${Su})
134
134
  Project built at ${Gm}`);const Zl="npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9",vs="needle_isActiveInHierarchy",qo="builtin_components",Jl="needle_editor_guid";function yo(s){try{(0,eval)(s)}catch(t){lv&&console.error(t)}}const wS='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 160 187.74"><defs><linearGradient id="a" x1="89.64" y1="184.81" x2="90.48" y2="21.85" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#62d399"/><stop offset=".51" stop-color="#acd842"/><stop offset=".9" stop-color="#d7db0a"/></linearGradient><linearGradient id="b" x1="69.68" y1="178.9" x2="68.08" y2="16.77" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#0ba398"/><stop offset=".5" stop-color="#4ca352"/><stop offset="1" stop-color="#76a30a"/></linearGradient><linearGradient id="c" x1="36.6" y1="152.17" x2="34.7" y2="84.19" gradientUnits="userSpaceOnUse"><stop offset=".19" stop-color="#36a382"/><stop offset=".54" stop-color="#49a459"/><stop offset="1" stop-color="#76a30b"/></linearGradient><linearGradient id="d" x1="15.82" y1="153.24" x2="18" y2="90.86" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#267880"/><stop offset=".51" stop-color="#457a5c"/><stop offset="1" stop-color="#717516"/></linearGradient><linearGradient id="e" x1="135.08" y1="135.43" x2="148.93" y2="63.47" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#b0d939"/><stop offset="1" stop-color="#eadb04"/></linearGradient><linearGradient id="f" x1="-4163.25" y1="2285.12" x2="-4160.81" y2="2215.34" gradientTransform="rotate(20 4088.49 13316.712)" gradientUnits="userSpaceOnUse"><stop offset=".17" stop-color="#74af52"/><stop offset=".48" stop-color="#99be32"/><stop offset="1" stop-color="#c0c40a"/></linearGradient><symbol id="g" viewBox="0 0 160 187.74"><path style="fill:url(#a)" d="M79.32 36.98v150.76L95 174.54l6.59-156.31-22.27 18.75z"/><path style="fill:url(#b)" d="M79.32 36.98 57.05 18.23l6.59 156.31 15.68 13.2V36.98z"/><path style="fill:url(#c)" d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33z"/><path style="fill:url(#d)" d="M25.19 104.83 0 90.24l16.97 53.86 16.85 9.77-8.63-49.04z"/><path style="fill:#9c3" d="M43.86 82.5 18.69 67.98 0 90.24l25.18 14.59L43.86 82.5z"/><path style="fill:url(#e)" d="m134.82 78.69-9.97 56.5 15.58-9.04L160 64.1l-25.18 14.59z"/><path style="fill:url(#f)" d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5z"/><path style="fill:#ffe113" d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33L160 64.1z"/><path style="fill:#f3e600" d="M101.59 18.23 79.32 0 57.05 18.23l22.27 18.75 22.27-18.75z"/></symbol></defs><use width="160" height="187.74" xlink:href="#g"/></svg>',xS=btoa(wS),SS="data:image/svg+xml;base64,"+xS,CS=SS,PS=`<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'> <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" version="1.1" viewBox="0 0 1014 282" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m665.95 132.73v44.88l-10.56-8.4c-0.8-0.64-1.2-1.44-1.2-2.4v-32.4c0-6.48-4.12-9.72-12.36-9.72-2.16 0-4.18 0.4-6.06 1.2s-3.54 1.8-4.98 3-2.56 2.5-3.36 3.9-1.2 2.7-1.2 3.9v40.92l-10.68-8.4c-0.72-0.64-1.08-1.44-1.08-2.4v-53.76l10.92 8.52c0.32 0.24 0.56 0.44 0.72 0.6s0.36 0.32 0.6 0.48c0.96-1.2 2.14-2.28 3.54-3.24s2.92-1.76 4.56-2.4 3.34-1.14 5.1-1.5 3.44-0.54 5.04-0.54c1.44 0 2.92 0.04 4.44 0.12s2.84 0.28 3.96 0.6c4.56 1.12 7.8 3.12 9.72 6s2.88 6.56 2.88 11.04z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m732.38 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m795.93 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m858.57 97.21c0.64 0.48 0.96 1.16 0.96 2.04v74.88c-0.08 1.04-0.12 2.12-0.12 3.24-1.84-1.52-3.56-2.92-5.16-4.2-1.36-1.12-2.66-2.18-3.9-3.18s-2.06-1.66-2.46-1.98c-1.76 2.48-4.26 4.44-7.5 5.88s-7.02 2.16-11.34 2.16c-3.84 0-7.4-0.7-10.68-2.1s-6.14-3.44-8.58-6.12-4.34-5.94-5.7-9.78-2.04-8.16-2.04-12.96c0-4.32 0.78-8.34 2.34-12.06s3.6-6.92 6.12-9.6 5.38-4.78 8.58-6.3 6.48-2.28 9.84-2.28c2.56 0 4.82 0.22 6.78 0.66s3.68 1.06 5.16 1.86 2.78 1.74 3.9 2.82 2.16 2.22 3.12 3.42v-35.04l10.68 8.64zm-27.96 67.92c3.6 0 6.52-0.68 8.76-2.04s3.98-3.06 5.22-5.1 2.1-4.22 2.58-6.54 0.72-4.44 0.72-6.36v-1.2c0-1.12-0.22-2.7-0.66-4.74s-1.28-4.06-2.52-6.06-3-3.7-5.28-5.1-5.22-2.02-8.82-1.86c-3.44 0-6.26 0.74-8.46 2.22s-3.96 3.26-5.28 5.34-2.24 4.2-2.76 6.36-0.78 3.92-0.78 5.28c0 1.84 0.24 3.92 0.72 6.24s1.36 4.48 2.64 6.48 3.04 3.68 5.28 5.04 5.12 2.04 8.64 2.04z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m882.81 97.09c0.64 0.48 0.96 1.12 0.96 1.92l-0.12 41.04v37.08l-10.56-8.4c-0.72-0.64-1.08-1.44-1.08-2.4v-77.88l10.8 8.64z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m950.36 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.8559 0 0 .7642 45.348 36.475)"> <g transform="translate(2.7114)"> <path d="m3.935 173.02c-0.331 0-0.497-0.402-0.497-1.207v-51.002c0-0.738 0.138-1.107 0.414-1.107h1.781c0.277 0 0.415 0.335 0.415 1.006v5.935c0 0.336 0.027 0.553 0.083 0.654 0.055 0.101 0.151-0.017 0.289-0.352 0.912-1.744 1.754-3.236 2.527-4.477 0.773-1.24 1.554-2.179 2.341-2.816s1.65-0.956 2.588-0.956c1.685 0 3.011 0.922 3.977 2.766 0.967 1.845 1.602 3.84 1.905 5.986 0.056 0.268 0.139 0.369 0.249 0.302s0.221-0.235 0.331-0.503c0.939-1.811 1.802-3.353 2.589-4.628 0.787-1.274 1.581-2.246 2.382-2.917s1.671-1.006 2.61-1.006c2.016 0 3.569 1.392 4.66 4.175 1.09 2.783 1.636 6.421 1.636 10.915v37.925c0 0.871-0.18 1.307-0.539 1.307h-1.739c-0.138 0-0.249-0.1-0.332-0.301-0.083-0.202-0.124-0.503-0.124-0.906v-36.315c0-3.555-0.338-6.321-1.015-8.3-0.676-1.978-1.76-2.967-3.251-2.967-0.884 0-1.726 0.386-2.527 1.157s-1.519 1.727-2.154 2.867-1.201 2.213-1.699 3.219c-0.248 0.469-0.421 0.905-0.517 1.308-0.097 0.402-0.145 0.972-0.145 1.71v37.221c0 0.871-0.166 1.307-0.497 1.307h-1.74c-0.166 0-0.29-0.1-0.373-0.301-0.083-0.202-0.124-0.503-0.124-0.906v-36.315c0-3.555-0.332-6.321-0.994-8.3-0.663-1.978-1.754-2.967-3.273-2.967-1.242 0-2.375 0.704-3.396 2.112-1.022 1.409-2.223 3.555-3.604 6.439v39.031c0 0.805-0.18 1.207-0.539 1.207h-1.698z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m53.642 166.28c-1.077 2.549-2.237 4.477-3.479 5.785-1.243 1.307-2.61 1.961-4.101 1.961-2.154 0-3.853-1.324-5.095-3.973-1.243-2.649-1.864-6.187-1.864-10.613 0-3.488 0.4-6.489 1.201-9.004s1.988-4.51 3.562-5.985c1.574-1.476 3.521-2.414 5.841-2.817l3.686-0.704c0.221-0.067 0.394-0.218 0.518-0.453 0.124-0.234 0.187-0.587 0.187-1.056v-2.917c0-3.89-0.504-6.975-1.512-9.255s-2.354-3.42-4.039-3.42c-1.298 0-2.472 0.72-3.521 2.162s-2.002 3.572-2.858 6.388c-0.083 0.268-0.159 0.453-0.228 0.554-0.069 0.1-0.172 0.083-0.311-0.051l-1.698-1.71c-0.083-0.134-0.138-0.285-0.166-0.453-0.027-0.167 0.014-0.452 0.125-0.855 0.856-3.353 2.009-6.052 3.459-8.098 1.449-2.045 3.224-3.068 5.322-3.068 1.74 0 3.211 0.687 4.412 2.062s2.112 3.37 2.734 5.986c0.621 2.615 0.932 5.7 0.932 9.255v35.712c0 0.536-0.035 0.888-0.104 1.056s-0.2 0.251-0.393 0.251h-1.533c-0.166 0-0.29-0.117-0.373-0.352-0.083-0.234-0.124-0.553-0.124-0.955l-0.083-5.231c-0.055-0.939-0.221-1.006-0.497-0.202zm0.456-19.314c0-1.14-0.194-1.643-0.58-1.509l-3.107 0.603c-1.436 0.202-2.686 0.638-3.749 1.308-1.063 0.671-1.953 1.543-2.671 2.616s-1.257 2.33-1.616 3.772-0.538 3.102-0.538 4.98c0 3.152 0.455 5.616 1.367 7.393 0.911 1.778 2.14 2.666 3.686 2.666 0.939 0 1.85-0.419 2.734-1.257s1.671-1.895 2.361-3.169c0.663-1.408 1.181-2.85 1.553-4.326 0.373-1.475 0.56-2.883 0.56-4.225v-8.852z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m79.034 173.02c-0.166 0-0.297-0.117-0.394-0.352-0.096-0.234-0.145-0.553-0.145-0.955v-4.628c0-0.536-0.041-0.838-0.124-0.905s-0.207 0.1-0.373 0.503c-0.276 0.67-0.69 1.593-1.242 2.766-0.553 1.174-1.271 2.23-2.154 3.169-0.884 0.939-1.961 1.408-3.231 1.408-1.74 0-3.314-0.989-4.722-2.967-1.409-1.979-2.534-4.963-3.376-8.953-0.843-3.991-1.264-8.937-1.264-14.838 0-5.701 0.415-10.68 1.243-14.939s1.988-7.595 3.479-10.009c1.492-2.415 3.204-3.622 5.137-3.622 1.436 0 2.616 0.57 3.541 1.71 0.926 1.14 1.719 2.381 2.382 3.722 0.249 0.47 0.414 0.637 0.497 0.503s0.125-0.536 0.125-1.207v-23.841c0-0.805 0.151-1.208 0.455-1.208h1.864c0.276 0 0.414 0.369 0.414 1.107v72.128c0 0.537-0.041 0.905-0.124 1.107-0.083 0.201-0.235 0.301-0.455 0.301h-1.533zm-0.621-42.049c-0.939-2.213-1.885-3.94-2.838-5.181s-2.009-1.861-3.169-1.861c-1.463 0-2.768 0.889-3.914 2.666s-2.044 4.376-2.693 7.796-0.973 7.578-0.973 12.474c0 5.097 0.338 9.272 1.015 12.524 0.676 3.253 1.567 5.651 2.672 7.193 1.104 1.543 2.305 2.314 3.603 2.314 1.188 0 2.258-0.704 3.211-2.113 0.952-1.408 1.705-3.118 2.257-5.13s0.829-3.957 0.829-5.835v-24.847z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m89.514 149.38c0 3.42 0.345 6.606 1.035 9.557 0.691 2.951 1.609 5.315 2.755 7.092s2.437 2.666 3.873 2.666c1.519 0 2.837-0.738 3.956-2.213 1.118-1.476 2.064-3.655 2.837-6.539 0.083-0.336 0.166-0.52 0.249-0.554 0.083-0.033 0.179 0.017 0.29 0.151l1.408 1.912c0.221 0.268 0.235 0.67 0.041 1.207-0.69 2.548-1.47 4.661-2.34 6.337-0.87 1.677-1.857 2.935-2.962 3.773-1.104 0.838-2.319 1.257-3.645 1.257-2.043 0-3.838-1.14-5.385-3.42-1.546-2.28-2.761-5.482-3.645-9.607-0.884-4.124-1.325-8.836-1.325-14.134 0-5.901 0.455-10.931 1.367-15.089 0.911-4.158 2.14-7.377 3.686-9.658 1.547-2.28 3.3-3.42 5.261-3.42 1.988 0 3.714 1.073 5.178 3.219 1.463 2.146 2.595 5.231 3.396 9.255s1.201 8.886 1.201 14.587c0 0.469-0.02 0.939-0.062 1.408-0.041 0.469-0.214 0.704-0.517 0.704h-16.362c-0.083 0-0.152 0.151-0.207 0.453-0.056 0.302-0.083 0.654-0.083 1.056zm13.752-6.237c0.304 0 0.497-0.1 0.58-0.302 0.083-0.201 0.124-0.57 0.124-1.106 0-3.219-0.283-6.187-0.849-8.903s-1.367-4.896-2.402-6.539c-1.036-1.643-2.272-2.464-3.708-2.464-1.629 0-2.996 0.955-4.101 2.867-1.104 1.911-1.94 4.342-2.506 7.293s-0.849 6.002-0.849 9.154h13.711z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m148.54 119.7c0.165 0 0.283 0.117 0.352 0.352s0.076 0.52 0.02 0.855l-6.254 50.902c-0.028 0.47-0.104 0.788-0.228 0.956s-0.297 0.251-0.518 0.251h-1.615c-0.442 0-0.718-0.402-0.829-1.207l-5.26-40.138c-0.111-0.604-0.201-0.905-0.27-0.905s-0.131 0.301-0.186 0.905l-5.012 40.138c-0.028 0.47-0.097 0.788-0.207 0.956-0.111 0.168-0.277 0.251-0.497 0.251h-1.74c-0.442 0-0.718-0.402-0.829-1.207l-6.503-50.801c-0.055-0.403-0.048-0.721 0.021-0.956s0.2-0.352 0.393-0.352h1.823c0.166 0 0.297 0.067 0.393 0.201 0.097 0.134 0.159 0.403 0.187 0.805l5.302 41.848c0.083 0.671 0.179 0.989 0.29 0.956 0.11-0.034 0.207-0.386 0.29-1.056l5.219-41.949c0.055-0.268 0.124-0.47 0.207-0.604s0.193-0.201 0.331-0.201h1.533c0.138 0 0.262 0.067 0.373 0.201 0.11 0.134 0.179 0.403 0.207 0.805l5.468 41.848c0.083 0.671 0.179 0.989 0.29 0.956 0.11-0.034 0.207-0.386 0.29-1.056l5.053-41.849c0.055-0.335 0.138-0.57 0.249-0.704 0.11-0.134 0.234-0.201 0.373-0.201h1.284z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m156.49 171.51c0 0.604-0.042 1.006-0.125 1.208-0.082 0.201-0.262 0.301-0.538 0.301h-1.533c-0.221 0-0.366-0.083-0.435-0.251s-0.103-0.486-0.103-0.956v-50.902c0-0.805 0.152-1.207 0.456-1.207h1.822c0.304 0 0.456 0.402 0.456 1.207v50.6zm0.165-63.979c0 1.207-0.207 1.811-0.621 1.811h-1.905c-0.221 0-0.366-0.135-0.435-0.403s-0.104-0.67-0.104-1.207v-7.847c0-1.006 0.18-1.509 0.539-1.509h1.988c0.359 0 0.538 0.47 0.538 1.409v7.746z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m168.3 124.83c-0.221 0-0.331 0.269-0.331 0.805v33.801c0 3.42 0.221 5.667 0.663 6.74 0.441 1.073 1.09 1.609 1.946 1.609h3.024c0.138 0 0.242 0.084 0.311 0.252 0.069 0.167 0.103 0.419 0.103 0.754v2.716c0 0.537-0.138 0.906-0.414 1.107-0.248 0.067-0.614 0.134-1.098 0.201-0.483 0.067-0.959 0.118-1.429 0.151-0.469 0.034-0.828 0.05-1.077 0.05-1.712 0-2.934-0.955-3.665-2.867-0.732-1.911-1.098-5.013-1.098-9.305v-35.108c0-0.604-0.124-0.906-0.373-0.906h-3.521c-0.248 0-0.373-0.268-0.373-0.804v-3.521c0-0.537 0.111-0.805 0.332-0.805h3.686c0.166 0 0.263-0.268 0.29-0.805l0.415-16.095c0-0.805 0.124-1.207 0.372-1.207h1.492c0.303 0 0.455 0.436 0.455 1.307v15.995c0 0.537 0.097 0.805 0.29 0.805h5.468c0.221 0 0.331 0.268 0.331 0.805v3.521c0 0.536-0.124 0.804-0.373 0.804h-5.426z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m179.4 173.02c-0.331 0-0.497-0.402-0.497-1.207v-72.329c0-0.738 0.138-1.107 0.414-1.107h1.782c0.276 0 0.414 0.336 0.414 1.006v27.162c0 0.335 0.034 0.536 0.103 0.603s0.159-0.033 0.27-0.302c0.994-1.81 1.898-3.319 2.713-4.526 0.814-1.208 1.629-2.113 2.444-2.717 0.814-0.603 1.691-0.905 2.63-0.905 2.182 0 3.839 1.375 4.971 4.125 1.132 2.749 1.698 6.404 1.698 10.965v37.925c0 0.871-0.166 1.307-0.497 1.307h-1.74c-0.165 0-0.29-0.1-0.373-0.301-0.082-0.202-0.124-0.503-0.124-0.906v-36.315c0-3.555-0.366-6.321-1.097-8.3-0.732-1.978-1.899-2.967-3.501-2.967-0.883 0-1.705 0.318-2.464 0.956-0.76 0.637-1.526 1.576-2.299 2.816-0.773 1.241-1.643 2.834-2.61 4.779v39.031c0 0.805-0.179 1.207-0.538 1.207h-1.699z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> </g> <g transform="matrix(.80638 0 0 .80638 452.53 65.421)" fill-rule="nonzero"> <path d="m79.32 36.98v150.76l15.68-13.2 6.59-156.31-22.27 18.75z" fill="url(#f)"/> <path d="m79.32 36.98-22.27-18.75 6.59 156.31 15.68 13.2v-150.76z" fill="url(#e)"/> <path d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33z" fill="url(#d)"/> <path d="m25.19 104.83-25.19-14.59 16.97 53.86 16.85 9.77-8.63-49.04z" fill="url(#c)"/> <path d="M43.86,82.5L18.69,67.98L0,90.24L25.18,104.83L43.86,82.5Z" fill="#9c3"/> <path d="m134.82 78.69-9.97 56.5 15.58-9.04 19.57-62.05-25.18 14.59z" fill="url(#b)"/> <path d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5z" fill="url(#a)"/> <path d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33 25.19-14.59z" fill="#ffe113"/> <path d="M101.59,18.23L79.32,0L57.05,18.23L79.32,36.98L101.59,18.23Z" fill="#f3e600"/> </g> <defs> <linearGradient id="f" x2="1" gradientTransform="matrix(.84 -162.96 162.96 .84 89.64 184.81)" gradientUnits="userSpaceOnUse"><stop stop-color="#62d399" offset="0"/><stop stop-color="#acd842" offset=".51"/><stop stop-color="#d7db0a" offset=".9"/><stop stop-color="#d7db0a" offset="1"/></linearGradient> <linearGradient id="e" x2="1" gradientTransform="matrix(-1.6,-162.13,162.13,-1.6,69.68,178.9)" gradientUnits="userSpaceOnUse"><stop stop-color="#0ba398" offset="0"/><stop stop-color="#4ca352" offset=".5"/><stop stop-color="#76a30a" offset="1"/></linearGradient> <linearGradient id="d" x2="1" gradientTransform="matrix(-1.9,-67.98,67.98,-1.9,36.6,152.17)" gradientUnits="userSpaceOnUse"><stop stop-color="#36a382" offset="0"/><stop stop-color="#36a382" offset=".19"/><stop stop-color="#49a459" offset=".54"/><stop stop-color="#76a30b" offset="1"/></linearGradient> <linearGradient id="c" x2="1" gradientTransform="matrix(2.18,-62.38,62.38,2.18,15.82,153.24)" gradientUnits="userSpaceOnUse"><stop stop-color="#267880" offset="0"/><stop stop-color="#457a5c" offset=".51"/><stop stop-color="#717516" offset="1"/></linearGradient> <linearGradient id="b" x2="1" gradientTransform="matrix(13.85,-71.96,71.96,13.85,135.08,135.43)" gradientUnits="userSpaceOnUse"><stop stop-color="#b0d939" offset="0"/><stop stop-color="#eadb04" offset="1"/></linearGradient> <linearGradient id="a" x2="1" gradientTransform="matrix(26.159 -64.737 64.737 26.159 107.42 128.14)" gradientUnits="userSpaceOnUse"><stop stop-color="#74af52" offset="0"/><stop stop-color="#74af52" offset=".17"/><stop stop-color="#99be32" offset=".48"/><stop stop-color="#c0c40a" offset="1"/></linearGradient> </defs> </svg>`;btoa(PS);const OS='<svg viewBox="0 0 509 154" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M665.95 132.73v44.88l-10.56-8.4c-.8-.64-1.2-1.44-1.2-2.4v-32.4c0-6.48-4.12-9.72-12.36-9.72-2.16 0-4.18.4-6.06 1.2-1.88.8-3.54 1.8-4.98 3-1.44 1.2-2.56 2.5-3.36 3.9-.8 1.4-1.2 2.7-1.2 3.9v40.92l-10.68-8.4c-.72-.64-1.08-1.44-1.08-2.4v-53.76l10.92 8.52c.32.24.56.44.72.6.16.16.36.32.6.48.96-1.2 2.14-2.28 3.54-3.24 1.4-.96 2.92-1.76 4.56-2.4 1.64-.64 3.34-1.14 5.1-1.5 1.76-.36 3.44-.54 5.04-.54 1.44 0 2.92.04 4.44.12 1.52.08 2.84.28 3.96.6 4.56 1.12 7.8 3.12 9.72 6 1.92 2.88 2.88 6.56 2.88 11.04ZM732.38 146.05c0 .88.02 1.5.06 1.86.04.36-.02.98-.18 1.86h-7.08c-2.08 0-4.44-.02-7.08-.06-2.64-.04-5.36-.06-8.16-.06h-22.08c0 2.88.56 5.36 1.68 7.44 1.12 2.08 2.6 3.8 4.44 5.16 1.84 1.36 3.94 2.36 6.3 3 2.36.64 4.74.96 7.14.96 3.04 0 5.9-.76 8.58-2.28 2.68-1.52 4.94-3.52 6.78-6 .64.56 1.54 1.48 2.7 2.76 1.16 1.28 2.94 3.2 5.34 5.76-2.8 3.36-6.22 6.02-10.26 7.98-4.04 1.96-8.42 2.94-13.14 2.94-4.72 0-8.92-.64-12.84-1.92-3.92-1.28-7.32-3.24-10.2-5.88-2.88-2.64-5.12-5.98-6.72-10.02-1.6-4.04-2.4-8.82-2.4-14.34 0-4.96.66-9.42 1.98-13.38 1.32-3.96 3.22-7.32 5.7-10.08s5.44-4.9 8.88-6.42c3.44-1.52 7.32-2.28 11.64-2.28 5.76 0 10.52.88 14.28 2.64 3.76 1.76 6.72 4.16 8.88 7.2 2.16 3.04 3.66 6.54 4.5 10.5.84 3.96 1.26 8.18 1.26 12.66Zm-29.4-22.8c-2.16.16-4.16.72-6 1.68-1.84.96-3.42 2.2-4.74 3.72-1.32 1.52-2.36 3.28-3.12 5.28-.76 2-1.14 4.12-1.14 6.36h33.12c0-2-.22-4.06-.66-6.18-.44-2.12-1.3-4.02-2.58-5.7-1.28-1.68-3.1-3.02-5.46-4.02-2.36-1-5.5-1.38-9.42-1.14ZM795.93 146.05c0 .88.02 1.5.06 1.86.04.36-.02.98-.18 1.86h-7.08c-2.08 0-4.44-.02-7.08-.06-2.64-.04-5.36-.06-8.16-.06h-22.08c0 2.88.56 5.36 1.68 7.44 1.12 2.08 2.6 3.8 4.44 5.16 1.84 1.36 3.94 2.36 6.3 3 2.36.64 4.74.96 7.14.96 3.04 0 5.9-.76 8.58-2.28 2.68-1.52 4.94-3.52 6.78-6 .64.56 1.54 1.48 2.7 2.76 1.16 1.28 2.94 3.2 5.34 5.76-2.8 3.36-6.22 6.02-10.26 7.98-4.04 1.96-8.42 2.94-13.14 2.94-4.72 0-8.92-.64-12.84-1.92-3.92-1.28-7.32-3.24-10.2-5.88-2.88-2.64-5.12-5.98-6.72-10.02-1.6-4.04-2.4-8.82-2.4-14.34 0-4.96.66-9.42 1.98-13.38 1.32-3.96 3.22-7.32 5.7-10.08s5.44-4.9 8.88-6.42c3.44-1.52 7.32-2.28 11.64-2.28 5.76 0 10.52.88 14.28 2.64 3.76 1.76 6.72 4.16 8.88 7.2 2.16 3.04 3.66 6.54 4.5 10.5.84 3.96 1.26 8.18 1.26 12.66Zm-29.4-22.8c-2.16.16-4.16.72-6 1.68-1.84.96-3.42 2.2-4.74 3.72-1.32 1.52-2.36 3.28-3.12 5.28-.76 2-1.14 4.12-1.14 6.36h33.12c0-2-.22-4.06-.66-6.18-.44-2.12-1.3-4.02-2.58-5.7-1.28-1.68-3.1-3.02-5.46-4.02-2.36-1-5.5-1.38-9.42-1.14ZM858.57 97.21c.64.48.96 1.16.96 2.04v74.88c-.08 1.04-.12 2.12-.12 3.24-1.84-1.52-3.56-2.92-5.16-4.2-1.36-1.12-2.66-2.18-3.9-3.18-1.24-1-2.06-1.66-2.46-1.98-1.76 2.48-4.26 4.44-7.5 5.88-3.24 1.44-7.02 2.16-11.34 2.16-3.84 0-7.4-.7-10.68-2.1-3.28-1.4-6.14-3.44-8.58-6.12-2.44-2.68-4.34-5.94-5.7-9.78-1.36-3.84-2.04-8.16-2.04-12.96 0-4.32.78-8.34 2.34-12.06 1.56-3.72 3.6-6.92 6.12-9.6 2.52-2.68 5.38-4.78 8.58-6.3 3.2-1.52 6.48-2.28 9.84-2.28 2.56 0 4.82.22 6.78.66 1.96.44 3.68 1.06 5.16 1.86s2.78 1.74 3.9 2.82a35.92 35.92 0 0 1 3.12 3.42V88.57l10.68 8.64Zm-27.96 67.92c3.6 0 6.52-.68 8.76-2.04 2.24-1.36 3.98-3.06 5.22-5.1a20.5 20.5 0 0 0 2.58-6.54c.48-2.32.72-4.44.72-6.36v-1.2c0-1.12-.22-2.7-.66-4.74-.44-2.04-1.28-4.06-2.52-6.06s-3-3.7-5.28-5.1c-2.28-1.4-5.22-2.02-8.82-1.86-3.44 0-6.26.74-8.46 2.22-2.2 1.48-3.96 3.26-5.28 5.34-1.32 2.08-2.24 4.2-2.76 6.36-.52 2.16-.78 3.92-.78 5.28 0 1.84.24 3.92.72 6.24.48 2.32 1.36 4.48 2.64 6.48s3.04 3.68 5.28 5.04c2.24 1.36 5.12 2.04 8.64 2.04ZM882.81 97.09c.64.48.96 1.12.96 1.92l-.12 41.04v37.08l-10.56-8.4c-.72-.64-1.08-1.44-1.08-2.4V88.45l10.8 8.64ZM950.36 146.05c0 .88.02 1.5.06 1.86.04.36-.02.98-.18 1.86h-7.08c-2.08 0-4.44-.02-7.08-.06-2.64-.04-5.36-.06-8.16-.06h-22.08c0 2.88.56 5.36 1.68 7.44 1.12 2.08 2.6 3.8 4.44 5.16 1.84 1.36 3.94 2.36 6.3 3 2.36.64 4.74.96 7.14.96 3.04 0 5.9-.76 8.58-2.28 2.68-1.52 4.94-3.52 6.78-6 .64.56 1.54 1.48 2.7 2.76 1.16 1.28 2.94 3.2 5.34 5.76-2.8 3.36-6.22 6.02-10.26 7.98-4.04 1.96-8.42 2.94-13.14 2.94-4.72 0-8.92-.64-12.84-1.92-3.92-1.28-7.32-3.24-10.2-5.88-2.88-2.64-5.12-5.98-6.72-10.02-1.6-4.04-2.4-8.82-2.4-14.34 0-4.96.66-9.42 1.98-13.38 1.32-3.96 3.22-7.32 5.7-10.08s5.44-4.9 8.88-6.42c3.44-1.52 7.32-2.28 11.64-2.28 5.76 0 10.52.88 14.28 2.64 3.76 1.76 6.72 4.16 8.88 7.2 2.16 3.04 3.66 6.54 4.5 10.5.84 3.96 1.26 8.18 1.26 12.66Zm-29.4-22.8c-2.16.16-4.16.72-6 1.68-1.84.96-3.42 2.2-4.74 3.72-1.32 1.52-2.36 3.28-3.12 5.28-.76 2-1.14 4.12-1.14 6.36h33.12c0-2-.22-4.06-.66-6.18-.44-2.12-1.3-4.02-2.58-5.7-1.28-1.68-3.1-3.02-5.46-4.02-2.36-1-5.5-1.38-9.42-1.14Z" style="fill-rule:nonzero" transform="translate(-452.406 -63.709) scale(1.00797)"/><path d="M79.32 36.98v150.76L95 174.54l6.59-156.31-22.27 18.75Z" style="fill:url(#a);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M79.32 36.98 57.05 18.23l6.59 156.31 15.68 13.2V36.98Z" style="fill:url(#b);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33Z" style="fill:url(#c);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M25.19 104.83 0 90.24l16.97 53.86 16.85 9.77-8.63-49.04Z" style="fill:url(#d);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M43.86 82.5 18.69 67.98 0 90.24l25.18 14.59L43.86 82.5Z" style="fill:#9c3;fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m134.82 78.69-9.97 56.5 15.58-9.04L160 64.1l-25.18 14.59Z" style="fill:url(#e);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5Z" style="fill:url(#f);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33L160 64.1Z" style="fill:#ffe113;fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M101.59 18.23 79.32 0 57.05 18.23l22.27 18.75 22.27-18.75Z" style="fill:#f3e600;fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><defs><linearGradient id="a" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(.84 -162.96 162.96 .84 89.64 184.81)"><stop offset="0" style="stop-color:#62d399;stop-opacity:1"/><stop offset=".51" style="stop-color:#acd842;stop-opacity:1"/><stop offset=".9" style="stop-color:#d7db0a;stop-opacity:1"/><stop offset="1" style="stop-color:#d7db0a;stop-opacity:1"/></linearGradient><linearGradient id="b" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-90.565 123.412 54.953) scale(162.14)"><stop offset="0" style="stop-color:#0ba398;stop-opacity:1"/><stop offset=".5" style="stop-color:#4ca352;stop-opacity:1"/><stop offset="1" style="stop-color:#76a30a;stop-opacity:1"/></linearGradient><linearGradient id="c" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="scale(-68) rotate(88.4 .881 -1.396)"><stop offset="0" style="stop-color:#36a382;stop-opacity:1"/><stop offset=".19" style="stop-color:#36a382;stop-opacity:1"/><stop offset=".54" style="stop-color:#49a459;stop-opacity:1"/><stop offset="1" style="stop-color:#76a30b;stop-opacity:1"/></linearGradient><linearGradient id="d" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-88 87.255 68.431) scale(62.42)"><stop offset="0" style="stop-color:#267880;stop-opacity:1"/><stop offset=".51" style="stop-color:#457a5c;stop-opacity:1"/><stop offset="1" style="stop-color:#717516;stop-opacity:1"/></linearGradient><linearGradient id="e" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-79.1 149.53 -14.065) scale(73.28)"><stop offset="0" style="stop-color:#b0d939;stop-opacity:1"/><stop offset="1" style="stop-color:#eadb04;stop-opacity:1"/></linearGradient><linearGradient id="f" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-67.997 148.705 -15.558) scale(69.8226)"><stop offset="0" style="stop-color:#74af52;stop-opacity:1"/><stop offset=".17" style="stop-color:#74af52;stop-opacity:1"/><stop offset=".48" style="stop-color:#99be32;stop-opacity:1"/><stop offset="1" style="stop-color:#c0c40a;stop-opacity:1"/></linearGradient></defs></svg>',MS=btoa(OS),RS="data:image/svg+xml;charset=utf-8;base64,"+MS,kS=RS,TS=S("debugpatch");function Cu(s,t,e,i){const n=TS===t;if(!e&&!i)return;const o=t+"___needle";AS(s,t,e,i);const a=Object.getOwnPropertyDescriptor(s,t),l=s[t];n&&console.log("Patch",s.constructor.name,t,a,l),a?(n&&console.log("Apply patch with existing descriptor",s.constructor.name,t,a),typeof a.value=="function"&&(s[t]=$_(a.value,s,t))):(n&&console.log("Create patch with new property",s.constructor.name,t,a),Object.defineProperty(s,t,{set:function(c){if(typeof c=="function")this[o]=$_(c,s,t);else{const d=this[o];cv(s,t,this,d,c),this[o]=c,hv(s,t,this,d,c)}},get:function(){const c=this[o];return typeof c=="function"&&c[o]?c[o]:c}}))}function ES(s,t,e){const i=qm(s,t);if(i)for(let n=i.length-1;n>=0;n--){const o=i[n];o.prefix===e&&(o.prefix=null),o.postfix===e&&(o.postfix=null),!o.prefix&&!o.postfix&&i.splice(n,1)}}const V_=Symbol("Needle:Patches:WrappedFunction");function $_(s,t,e){if(s[V_])return s;const i=function(...n){cv(t,e,this,...n);const o=s.apply(this,n);return hv(t,e,this,o,...n),o};return i[V_]=!0,i}const yd="Needle:Patches";function Xp(){return globalThis[yd]||(globalThis[yd]=new WeakMap),globalThis[yd]}function qm(s,t){const e=Xp().get(s);return e?e.get(t):null}function AS(s,t,e,i){let n=Xp().get(s);n||(n=new Map,Xp().set(s,n));let o=n.get(t);o||(o=[],n.set(t,o)),o.push({prefix:e,postfix:i})}function cv(s,t,e,...i){var o;if(!e)return;const n=qm(s,t);if(n)for(const a of n)(o=a.prefix)==null||o.call(e,...i)}function hv(s,t,e,i,...n){var a;if(!e)return;const o=qm(s,t);if(o)for(const l of o)(a=l.postfix)==null||a.call(e,i,...n)}const La=[];function Pu(s){La.indexOf(s)===-1&&La.push(s)}function DS(s){const t=La.indexOf(s);t!==-1&&La.splice(t,1)}const Ia=[];function Xm(s){Ia.indexOf(s)===-1&&Ia.push(s)}function LS(s){const t=Ia.indexOf(s);t!==-1&&Ia.splice(t,1)}function dv(s){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-start",{detail:s}));for(let t=0;t<La.length;t++)La[t](s)}function uv(s){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-end",{detail:s}));for(let t=0;t<Ia.length;t++)Ia[t](s)}const Je=S("debuginput");var Ou=(s=>(s.Mouse="mouse",s.Touch="touch",s.Controller="controller",s.Hand="hand",s))(Ou||{}),Te=(s=>(s.PointerDown="pointerdown",s.PointerUp="pointerup",s.PointerMove="pointermove",s.KeyDown="keydown",s.KeyUp="keyup",s.KeyPressed="keypress",s))(Te||{});class ls extends PointerEvent{constructor(e,i,n){super(e,n);r(this,"clientZ");r(this,"deviceIndex");r(this,"origin");r(this,"source");r(this,"mode");r(this,"_ray");r(this,"space");r(this,"isClick",!1);r(this,"isDoubleClick",!1);r(this,"_used",!1);r(this,"_pointerid");r(this,"_pointerType");r(this,"_type");r(this,"metadata",{});r(this,"intersections",new Array);r(this,"_immediatePropagationStopped",!1);r(this,"_propagationStopped",!1);this.clientZ=n.clientZ,this._pointerid=n.pointerId,this._pointerType=n.pointerType,this._type=e,this.deviceIndex=n.deviceIndex,this.origin=n.origin,this.source=i,this.mode=n.mode,this._ray=n.ray,this.space=n.device}get isSpatial(){return this.mode!="screen"}get ray(){return this._ray||(this._ray=new h.Ray(this.space.worldPosition.clone(),this.space.worldForward.clone())),this._ray}set ray(e){this._ray=e}get hasRay(){return this._ray!==void 0}get used(){return this._used}use(){this._used=!0}get pointerId(){return this._pointerid}get pointerType(){return this._pointerType}get type(){return this._type}get immediatePropagationStopped(){return this._immediatePropagationStopped}get propagationStopped(){return this._immediatePropagationStopped||this._propagationStopped}stopImmediatePropagation(){var e;this._immediatePropagationStopped=!0,super.stopImmediatePropagation(),(e=this.source)==null||e.stopImmediatePropagation()}stopPropagation(){var e;this._propagationStopped=!0,super.stopPropagation(),(e=this.source)==null||e.stopPropagation(),Je&&console.warn("Stop propagation...",this.pointerId,this.pointerType)}}class Ll extends KeyboardEvent{constructor(e,i,n){super(e,n);r(this,"source");this.source=i}stopImmediatePropagation(){var e;super.stopImmediatePropagation(),(e=this.source)==null||e.stopImmediatePropagation()}}class IS{constructor(t){r(this,"key");r(this,"keyType");r(this,"source");this.key=t.key,this.keyType=t.type,this.source=t}}var _i=(s=>(s[s.Early=-100]="Early",s[s.Default=0]="Default",s[s.Late=100]="Late",s))(_i||{});class fv{constructor(t){r(this,"_eventListeners",{});r(this,"_doubleClickTimeThreshold",.2);r(this,"_longPressTimeThreshold",1);r(this,"_setCursorTypes",[]);r(this,"context");r(this,"_pointerDown",[!1]);r(this,"_pointerUp",[!1]);r(this,"_pointerClick",[!1]);r(this,"_pointerDoubleClick",[!1]);r(this,"_pointerPressed",[!1]);r(this,"_pointerPositions",[new h.Vector2]);r(this,"_pointerPositionsLastFrame",[new h.Vector2]);r(this,"_pointerPositionsDelta",[new h.Vector2]);r(this,"_pointerPositionsRC",[new h.Vector2]);r(this,"_pointerPositionDown",[new h.Vector3]);r(this,"_pointerDownTime",[]);r(this,"_pointerUpTime",[]);r(this,"_pointerUpTimestamp",[]);r(this,"_pointerIds",[]);r(this,"_pointerTypes",[""]);r(this,"_mouseWheelChanged",[!1]);r(this,"_mouseWheelDeltaY",[0]);r(this,"_pointerEvent",[]);r(this,"_pointerEventsPressed",[]);r(this,"_pointerSpace",[]);r(this,"_pressedStack",new Map);r(this,"_htmlEventSource");r(this,"onLostFocus",()=>{for(const t in this.keysPressed)this.keysPressed[t].pressed=!1});r(this,"_receivedPointerMoveEventsThisFrame",new Array);r(this,"onEndOfFrame",()=>{this._receivedPointerMoveEventsThisFrame.length=0;for(let t=0;t<this._pointerUp.length;t++)this._pointerUp[t]=!1;for(let t=0;t<this._pointerDown.length;t++)this._pointerDown[t]=!1;for(let t=0;t<this._pointerClick.length;t++)this._pointerClick[t]=!1;for(let t=0;t<this._pointerDoubleClick.length;t++)this._pointerDoubleClick[t]=!1;for(const t of this._pointerPositionsDelta)t.set(0,0);for(let t=0;t<this._mouseWheelChanged.length;t++)this._mouseWheelChanged[t]=!1;for(let t=0;t<this._mouseWheelDeltaY.length;t++)this._mouseWheelDeltaY[t]=0});r(this,"onContextMenu",t=>{this.canReceiveInput(t)!==!1&&t instanceof PointerEvent&&t.pointerType});r(this,"keysPressed",{});r(this,"onKeyDown",t=>{if(Je&&console.log(`key down ${t.code}, ${this.context.application.hasFocus}`,t),!this.context.application.hasFocus)return;const e=this.keysPressed[t.code];if(e&&e.pressed)return;this.keysPressed[t.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:t.key,code:t.code};const i=new Ll("keydown",t,t);this.onDispatchEvent(i)});r(this,"onKeyPressed",t=>{if(!this.context.application.hasFocus)return;const e=this.keysPressed[t.code];if(!e)return;e.pressed=!0,e.frame=this.context.time.frameCount+1;const i=new Ll("keypress",t,t);this.onDispatchEvent(i)});r(this,"onKeyUp",t=>{if(!this.context.application.hasFocus)return;const e=this.keysPressed[t.code];if(!e)return;e.pressed=!1,e.frame=this.context.time.frameCount+1;const i=new Ll("keyup",t,t);this.onDispatchEvent(i)});r(this,"onWheelWindow",t=>{document.pointerLockElement&&this.onMouseWheel(t)});r(this,"onMouseWheel",t=>{if(this.canReceiveInput(t)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const e=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=e+t.deltaY});r(this,"onPointerDown",t=>{if(this.context.isInAR||this.canReceiveInput(t)===!1)return;t.target instanceof HTMLElement&&t.target.setPointerCapture(t.pointerId);const e=this.getPointerId(t);Je&&Ee(`pointer down #${e}, identifier:${t.pointerId}`);const i=this.getAndUpdateSpatialObjectForScreenPosition(e,t.clientX,t.clientY),n=new ls("pointerdown",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:e,button:t.button,clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType,buttonName:this.getButtonName(t),device:i,pressure:t.pressure});this.onDown(n)});r(this,"onPointerMove",t=>{if(this.context.isInAR||this._receivedPointerMoveEventsThisFrame.includes(t.pointerId))return;this._receivedPointerMoveEventsThisFrame.push(t.pointerId);let e=t.button;t.pointerType==="mouse"&&(e=this.getFirstPressedButtonForPointer(0)??0);const i=this.getPointerId(t,e);e===-1&&(e=i);const n=this.getAndUpdateSpatialObjectForScreenPosition(i,t.clientX,t.clientY),o=new ls("pointermove",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:i,button:e,clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType,buttonName:this.getButtonName(t),device:n,pressure:t.pressure});this.onMove(o)});r(this,"onPointerCancel",t=>{this.context.isInAR||(Je&&console.log("Pointer cancel",t),this.onPointerUp(t))});r(this,"onPointerUp",t=>{if(this.context.isInAR)return;t.target instanceof HTMLElement&&t.target.releasePointerCapture(t.pointerId);const e=this.getPointerId(t),i=new ls("pointerup",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:e,button:t.button,clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType,buttonName:this.getButtonName(t),device:this.getAndUpdateSpatialObjectForScreenPosition(e,t.clientX,t.clientY),pressure:t.pressure});this.onUp(i),this._pointerIds[e]=-1,Je&&console.log("ID="+e,"PointerId="+t.pointerId,"ALL:",[...this._pointerIds])});r(this,"onTouchStart",t=>{if(this.context.isInAR)for(let e=0;e<t.changedTouches.length;e++){const i=t.changedTouches[e],n=this.getPointerIndex(i.identifier),o=this.getAndUpdateSpatialObjectForScreenPosition(n,i.clientX,i.clientY),a=new ls("pointerdown",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:n,button:0,clientX:i.clientX,clientY:i.clientY,pointerType:"touch",buttonName:"unknown",device:o,pressure:i.force});this.onDown(a)}});r(this,"onTouchMove",t=>{if(this.context.isInAR)for(let e=0;e<t.changedTouches.length;e++){const i=t.changedTouches[e],n=this.getPointerIndex(i.identifier),o=this.getAndUpdateSpatialObjectForScreenPosition(n,i.clientX,i.clientY),a=new ls("pointermove",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:n,button:0,clientX:i.clientX,clientY:i.clientY,pointerType:"touch",buttonName:"unknown",device:o,pressure:i.force});this.onMove(a)}});r(this,"onTouchEnd",t=>{if(this.context.isInAR)for(let e=0;e<t.changedTouches.length;e++){const i=t.changedTouches[e],n=this.getPointerIndex(i.identifier),o=new ls("pointerup",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:n,button:0,clientX:i.clientX,clientY:i.clientY,pointerType:"touch",buttonName:"unknown",device:this.getAndUpdateSpatialObjectForScreenPosition(n,i.clientX,i.clientY),pressure:i.force});this.onUp(o),this._pointerIds[n]=-1}});r(this,"tempNearPlaneVector",new h.Vector3);r(this,"tempFarPlaneVector",new h.Vector3);r(this,"tempLookMatrix",new h.Matrix4);this.context=t,this.context.post_render_callbacks.push(this.onEndOfFrame)}addEventListener(t,e,i){if(this._eventListeners[t]||(this._eventListeners[t]=[]),!e||typeof e!="function"){console.error("Invalid call to addEventListener: callback is required and must be a function!");return}i?i={...i}:i={};let n=0;(i==null?void 0:i.queue)!=null&&(n=i.queue);const o=this._eventListeners[t],a=o.find(l=>l.priority===n);a?a.listeners.push({callback:e,options:i}):(o.push({priority:n,listeners:[{callback:e,options:i}]}),o.sort((l,c)=>l.priority-c.priority))}removeEventListener(t,e,i){if(!this._eventListeners[t]||!e)return;const n=this._eventListeners[t];if((i==null?void 0:i.queue)!=null){const o=n.find(l=>l.priority===i.queue);if(!o)return;const a=o.listeners.findIndex(l=>l.callback===e);a>=0&&o.listeners.splice(a,1)}else for(const o of n){const a=o.listeners.findIndex(l=>l.callback===e);a>=0&&o.listeners.splice(a,1)}}dispatchEvent(t){var i,n,o,a;let e=!1;if(t instanceof Ll){const l=this._eventListeners[t.type];if(l)for(const c of l)for(let d=0;d<c.listeners.length;d++){const u=c.listeners[d];if((n=(i=u.options)==null?void 0:i.signal)!=null&&n.aborted){c.listeners.splice(d,1),d--;continue}u.options.once&&(c.listeners.splice(d,1),d--),u.callback(t)}}if(t instanceof ls){const l=this._eventListeners[t.type];if(l)for(const c of l){if(e)break;for(let d=0;d<c.listeners.length;d++){const u=c.listeners[d];if((a=(o=u.options)==null?void 0:o.signal)!=null&&a.aborted){c.listeners.splice(d,1),d--;continue}if(t.immediatePropagationStopped){e=!0,Je&&console.log("immediatePropagationStopped",t.type);break}else t.propagationStopped&&(e=!0,Je&&console.log("propagationStopped",t.type));u.options.once&&(c.listeners.splice(d,1),d--),u.callback(t)}}}}get mousePosition(){return this._pointerPositions[0]}get mousePositionRC(){return this._pointerPositionsRC[0]}get mouseDown(){return this._pointerDown[0]}get mouseUp(){return this._pointerUp[0]}get mouseClick(){return this._pointerClick[0]}get mouseDoubleClick(){return this._pointerDoubleClick[0]}get mousePressed(){return this._pointerPressed[0]}get mouseWheelChanged(){return this.getMouseWheelChanged(0)}get click(){return this._pointerClick[0]}get doubleClick(){return this._pointerDoubleClick[0]}setCursorPointer(){this.setCursor("pointer")}setCursorNormal(){this.unsetCursor("pointer")}setCursor(t){this._setCursorTypes.push(t),this._setCursorTypes.length>10&&this._setCursorTypes.shift(),this.updateCursor()}unsetCursor(t){for(let e=this._setCursorTypes.length-1;e>=0;e--)if(this._setCursorTypes[e]===t){this._setCursorTypes.splice(e,1),this.updateCursor();break}}updateCursor(){var t;((t=this._setCursorTypes)==null?void 0:t.length)==0?this.context.domElement.style.cursor="default":this.context.domElement.style.cursor=this._setCursorTypes[this._setCursorTypes.length-1]}getIsPointerIdInUse(t){for(const e of this._pointerEventsPressed)if(e.pointerId===t&&e.used)return!0;return!1}getPointerPressedCount(){let t=0;for(let e=0;e<this._pointerPressed.length;e++)this._pointerPressed[e]&&t++;return t}getPointerPosition(t){return t>=this._pointerPositions.length?null:this._pointerPositions[t]}getPointerPositionLastFrame(t){return t>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[t]}getPointerPositionDelta(t){return t>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[t]}getPointerPositionRC(t){return t>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[t]}getPointerDown(t){return t>=this._pointerDown.length?!1:this._pointerDown[t]}getPointerUp(t){return t>=this._pointerUp.length?!1:this._pointerUp[t]}getPointerPressed(t){return t>=this._pointerPressed.length?!1:this._pointerPressed[t]}getPointerClicked(t){return t>=this._pointerClick.length?!1:this._pointerClick[t]}getPointerDoubleClicked(t){return t>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[t]}getPointerDownTime(t){return t>=this._pointerDownTime.length?-1:this._pointerDownTime[t]}getPointerUpTime(t){return t>=this._pointerUpTime.length?-1:this._pointerUpTime[t]}getPointerLongPress(t){return t>=this._pointerDownTime.length?!1:this.getPointerPressed(t)&&this.context.time.time-this._pointerDownTime[t]>this._longPressTimeThreshold}getIsMouse(t){return t<0||t>=this._pointerTypes.length?!1:this._pointerTypes[t]==="mouse"}getIsTouch(t){return t<0||t>=this._pointerTypes.length?!1:this._pointerTypes[t]==="touch"}getTouchesPressedCount(){let t=0;for(let e=0;e<this._pointerPressed.length;e++)this._pointerPressed[e]&&this.getIsTouch(e)&&t++;return t}getMouseWheelChanged(t=0){return t>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[t]}getMouseWheelDeltaY(t=0){return t>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[t]}getPointerEvent(t){if(!(t>=this._pointerEvent.length))return this._pointerEvent[t]??void 0}*foreachPointerId(t){for(let e=0;e<this._pointerTypes.length;e++)if(this._pointerIsActive(e)){if(t!==void 0){const i=this._pointerTypes[e];if(Array.isArray(t)){let n=!1;for(const o of t)if(i===o){n=!0;break}if(!n)continue}else if(t!==i)continue}yield e}}*foreachTouchId(){for(let t=0;t<this._pointerTypes.length;t++)this._pointerTypes[t]==="touch"&&this._pointerIsActive[t]&&(yield t)}_pointerIsActive(t){return t<0?!1:this._pointerPressed[t]||this._pointerDown[t]||this._pointerUp[t]}onDownButton(t,e){let i=this._pressedStack.get(t);i||(i=[],this._pressedStack.set(t,i)),i.push(e)}onReleaseButton(t,e){const i=this._pressedStack.get(t);if(!i)return;const n=i.indexOf(e);n>=0&&i.splice(n,1)}getFirstPressedButtonForPointer(t){const e=this._pressedStack.get(t);if(e)return e[0]}getLatestPressedButtonForPointer(t){const e=this._pressedStack.get(t);if(e)return e[e.length-1]}getKeyDown(){for(const t in this.keysPressed){const e=this.keysPressed[t];if(e.startFrame===this.context.time.frameCount)return e.key}return null}getKeyPressed(){for(const t in this.keysPressed){const e=this.keysPressed[t];if(e.pressed)return e.key}return null}isKeyDown(t){var i;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(t);if(e!==null){for(const n of e)if(this.isKeyDown(n))return!0;return!1}return((i=this.keysPressed[t])==null?void 0:i.startFrame)===this.context.time.frameCount&&this.keysPressed[t].pressed}isKeyUp(t){var i;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(t);if(e!==null){for(const n of e)if(this.isKeyUp(n))return!0;return!1}return((i=this.keysPressed[t])==null?void 0:i.frame)===this.context.time.frameCount&&!this.keysPressed[t].pressed}isKeyPressed(t){var i;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(t);if(e!==null){for(const n of e)if(this.isKeyPressed(n))return!0;return!1}return(i=this.keysPressed[t])==null?void 0:i.pressed}getCodeForCommonKeyName(t){if(t.length===1){if(t>="0"&&t<="9")return["Digit"+t];if(t>="a"&&t<="z")return["Key"+t.toUpperCase()];if(t==" ")return["Space"]}switch(t){case"shift":case"Shift":return["ShiftLeft","ShiftRight"];case"control":case"Control":return["ControlLeft","ControlRight"];case"alt":case"Alt":return["AltLeft","AltRight"]}return null}createInputEvent(t){switch(t.type){case"pointerdown":Je&&Ee("Create Pointer down"),this.onDownButton(t.deviceIndex,t.button),this.onDown(t);break;case"pointermove":Je&&Ee("Create Pointer move"),this.onMove(t);break;case"pointerup":Je&&Ee("Create Pointer up"),this.onUp(t),this.onReleaseButton(t.deviceIndex,t.button);break}}convertScreenspaceToRaycastSpace(t){return t.x=(t.x-this.context.domX)/this.context.domWidth*2-1,t.y=-((t.y-this.context.domY)/this.context.domHeight)*2+1,t}bindEvents(){this.unbindEvents(),this._htmlEventSource=this.context.renderer.domElement,window.addEventListener("contextmenu",this.onContextMenu),this._htmlEventSource.addEventListener("pointerdown",this.onPointerDown,{passive:!0}),window.addEventListener("pointermove",this.onPointerMove,{passive:!0,capture:!0}),window.addEventListener("pointerup",this.onPointerUp,{passive:!0}),window.addEventListener("pointercancel",this.onPointerCancel,{passive:!0}),window.addEventListener("touchstart",this.onTouchStart,{passive:!0}),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchEnd,{passive:!0}),this._htmlEventSource.addEventListener("wheel",this.onMouseWheel,{passive:!0}),window.addEventListener("wheel",this.onWheelWindow,{passive:!0}),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keypress",this.onKeyPressed,!1),window.addEventListener("keyup",this.onKeyUp,!1),window.addEventListener("blur",this.onLostFocus)}unbindEvents(){var t,e;window.removeEventListener("contextmenu",this.onContextMenu),(t=this._htmlEventSource)==null||t.removeEventListener("pointerdown",this.onPointerDown),window.removeEventListener("pointermove",this.onPointerMove),window.removeEventListener("pointerup",this.onPointerUp),window.removeEventListener("pointercancel",this.onPointerCancel),window.removeEventListener("touchstart",this.onTouchStart),window.removeEventListener("touchmove",this.onTouchMove),window.removeEventListener("touchend",this.onTouchEnd),(e=this._htmlEventSource)==null||e.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("wheel",this.onWheelWindow,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}dispose(){const t=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);t>=0&&this.context.post_render_callbacks.splice(t,1),this.unbindEvents()}canReceiveInput(t){var e;return t.target===((e=this.context.renderer)==null?void 0:e.domElement)||t.target===this.context.domElement||this.context.isInAR||this.context.isInAR&&t.target===document.body&&exports.DeviceUtilities.isMozillaXR()?!0:(Je&&console.warn("CanReceiveInput:False for",t.target),!1)}getPointerId(t,e){return t.pointerType==="mouse"?0+(e??t.button):this.getPointerIndex(t.pointerId)}getButtonName(t){const e=t.button;if(t.pointerType==="mouse")switch(e){case 0:return"left";case 1:return"middle";case 2:return"right"}return"unknown"}getAndUpdateSpatialObjectForScreenPosition(t,e,i){let n=this._pointerSpace[t];n||(n=new h.Object3D,this._pointerSpace[t]=n),this._pointerSpace[t]=n;const o=this.context.mainCamera;if(o){const a=this.tempNearPlaneVector.set(e,i,-1);this.convertScreenspaceToRaycastSpace(a);const l=this.tempFarPlaneVector.set(a.x,a.y,1);a.unproject(o),l.unproject(o);const c=o.worldUp||V(0,1,0).applyQuaternion(ye(o));this.tempLookMatrix.lookAt(l,a,c),n.position.set(a.x,a.y,a.z),n.quaternion.setFromRotationMatrix(this.tempLookMatrix)}return n}isInRect(t){if(this.context.isInXR)return!0;const e=this.context.domElement.getBoundingClientRect(),i=t.clientX,n=t.clientY,o=i>=e.x&&i<=e.right&&n>=e.y&&n<=e.bottom;return Je&&!o&&console.log("Not in rect",e,i,n),o}onDown(t){const e=t.pointerId;if(this.getPointerPressed(e)&&console.warn(`Received pointerDown for pointerId that is already pressed: ${e}`,Je?t:""),Je&&console.log(t.pointerType,"DOWN",e),!!this.isInRect(t)){for(this.setPointerState(e,this._pointerPressed,!0),this.setPointerState(e,this._pointerDown,!0),this.setPointerStateT(e,this._pointerEvent,t.source);e>=this._pointerTypes.length;)this._pointerTypes.push(t.pointerType);for(this._pointerTypes[e]=t.pointerType;e>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new h.Vector3);for(this._pointerPositionDown[e].set(t.clientX,t.clientY,t.clientZ??0);e>=this._pointerPositions.length;)this._pointerPositions.push(new h.Vector2);this._pointerPositions[e].set(t.clientX,t.clientY),e>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[e]=this.context.time.realtimeSinceStartup,this.updatePointerPosition(t),this._pointerEventsPressed.push(t),this.onDispatchEvent(t)}}onMove(t){const e=t.pointerId,i=this.getPointerPressed(e);i===!1&&!this.isInRect(t)||t.pointerType==="touch"&&!i||(this.updatePointerPosition(t),this.setPointerStateT(e,this._pointerEvent,t.source),this.onDispatchEvent(t))}onUp(t){const e=t.pointerId;if(!this.getPointerPressed(e)){Je&&console.log(t.pointerType,"UP",e,"was not down");return}Je&&console.log(t.pointerType,"UP",e),this.setPointerState(e,this._pointerPressed,!1),this.setPointerStateT(e,this._pointerEvent,t.source),this.setPointerState(e,this._pointerUp,!0),this.updatePointerPosition(t);for(let c=this._pointerEventsPressed.length-1;c>=0;c--)if(this._pointerEventsPressed[c].pointerId===e){this._pointerEventsPressed.splice(c,1);break}if(!this._pointerPositionDown[e]){Je&&me("Received pointer up event without matching down event for button: "+e),console.warn("Received pointer up event without matching down event for button: "+e);return}const n=this._pointerUpTime[e],o=this._pointerDownTime[e],a=this.context.time.realtimeSinceStartup,l=a-o;if(e>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),this._pointerUpTime[e]=a,l<1){let c=t.clientX-this._pointerPositionDown[e].x,d=t.clientY-this._pointerPositionDown[e].y,u=0;if(t.isSpatial&&t.clientZ!=null&&(u=t.clientZ-this._pointerPositionDown[e].z,c*=200,d*=200,u*=200),Math.abs(c)<5&&Math.abs(d)<5&&Math.abs(u)<5){this.setPointerState(e,this._pointerClick,!0),t.isClick=!0;const f=a-n;Je&&console.log("CLICK",e,c,d,u,f),f<this._doubleClickTimeThreshold&&f>0&&(this.setPointerState(e,this._pointerDoubleClick,!0),t.isDoubleClick=!0)}}this.onDispatchEvent(t)}updatePointerPosition(t){const e=t.pointerId;for(;e>=this._pointerPositions.length;)this._pointerPositions.push(new h.Vector2);for(;e>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new h.Vector2);for(;e>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new h.Vector2);const i=this._pointerPositionsLastFrame[e];i.copy(this._pointerPositions[e]);const n=this._pointerPositionsDelta[e];let o=t.clientX-i.x,a=t.clientY-i.y;if(t.source instanceof MouseEvent||t.source instanceof TouchEvent){const u=t.source;o===0&&u.movementX!==0&&(o=u.movementX||0),a===0&&u.movementY!==0&&(a=u.movementY||0)}n.x+=o,n.y+=a,this._pointerPositions[e].x=t.clientX,this._pointerPositions[e].y=t.clientY;const l=t.clientX,c=t.clientY;for(;e>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new h.Vector2);const d=this._pointerPositionsRC[e];d.set(l,c),this.convertScreenspaceToRaycastSpace(d)}getPointerIndex(t){let e=-1;for(let i=0;i<this._pointerIds.length;i++){if(this._pointerIds[i]===t)return i;e===-1&&this._pointerIds[i]===-1&&(e=i)}return e!==-1?(this._pointerIds[e]=t,e):(Je&&console.log("PUSH pointerId:",t),this._pointerIds.push(t),this._pointerIds.length-1)}setPointerState(t,e,i){e[t]=i}setPointerStateT(t,e,i){return e[t]=i,i}onDispatchEvent(t){const e=Q.Current;try{Q.Current=this.context,this.dispatchEvent(t)}finally{Q.Current=e}}}const xa=new h.Matrix4().makeRotationY(Math.PI),Bi=new h.Quaternion().setFromAxisAngle(new h.Vector3(0,1,0),Math.PI),jS=S("debugwebxr");class BS{constructor(){r(this,"priority",-1e5);r(this,"gameObject");if(this.gameObject=new h.Object3D,this.gameObject.name="Implicit XR Rig",jS){const t=tg(16733661);t.position.y+=.5,this.gameObject.add(t)}}isXRRig(){return!0}get isActive(){return this.gameObject.visible}}const Zn=S("debugwebxr"),Bh=S("debugcustomgesture"),FS="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",US="generic-trigger",zS=new h.Quaternion().setFromEuler(new h.Euler(h.MathUtils.degToRad(0),h.MathUtils.degToRad(-90),h.MathUtils.degToRad(-90))),NS=new h.Vector3(.04,-.04,0);class Qm{constructor(t,e,i){r(this,"xr");r(this,"inputSource");r(this,"index",0);r(this,"emitEvents",!0);r(this,"_connected",!0);r(this,"_isTracking",!1);r(this,"__gamepad");r(this,"__hand");r(this,"__side");r(this,"_hitTestSource");r(this,"_hasSelectEvent",!1);r(this,"_isMxInk",!1);r(this,"_isMetaQuestTouchController",!1);r(this,"_handJointPoses",new Map);r(this,"_gripMatrix",new h.Matrix4);r(this,"_gripPosition",new h.Vector3);r(this,"_gripQuaternion",new h.Quaternion);r(this,"_linearVelocity",new h.Vector3);r(this,"_rayPositionRaw",new h.Vector3);r(this,"_rayRotationRaw",new h.Quaternion);r(this,"_rayMatrix",new h.Matrix4);r(this,"_rayPosition",new h.Vector3);r(this,"_rayQuaternion",new h.Quaternion);r(this,"_gripWorldPosition",new h.Vector3);r(this,"_gripWorldQuaternion",new h.Quaternion);r(this,"_rayWorldPosition",new h.Vector3);r(this,"_rayWorldQuaternion",new h.Quaternion);r(this,"_pinchPosition",new h.Vector3);r(this,"_ray");r(this,"_hand_wristDotUp");r(this,"_object");r(this,"_gripSpaceObject");r(this,"_raySpaceObject");r(this,"model",null);r(this,"_debugAxesHelper",new h.AxesHelper(.15));r(this,"_debugGripAxesHelper",new h.AxesHelper(.07));r(this,"_debugRayAxesHelper",new h.AxesHelper(.07));r(this,"_hitTestSourcePromise",null);r(this,"onPointerHits",t=>{});r(this,"_needleGamepadButtons",{});r(this,"_buttonMap",new Map);r(this,"_motioncontroller");r(this,"_layout");r(this,"getMotionController");r(this,"emitPointerDownEvent",!0);r(this,"emitPointerUpEvent",!0);r(this,"emitPointerMoveEvent",!0);r(this,"pointerMoveDistanceThreshold",.03);r(this,"pointerMoveAngleThreshold",.05);r(this,"_selectButtonIndex");r(this,"_squeezeButtonIndex");r(this,"onSelectStart",t=>{var n,o,a,l;if(!this.emitPointerDownEvent||this.inputSource!==t.inputSource)return;this.onUpdateFrame(t.frame),this._hasSelectEvent=!0;const e=(n=this._layout)==null?void 0:n.selectComponentId,i=(l=(a=(o=this._layout)==null?void 0:o.components[e])==null?void 0:a.gamepadIndices)==null?void 0:l.button;i!==void 0&&(this._selectButtonIndex=i),!Bh&&(Zn&&N.DrawDirection(this.rayWorldPosition,V(0,.01,1).applyQuaternion(this.rayWorldQuaternion),16711680,10),this.emitPointerEvent(Te.PointerDown,this._selectButtonIndex||0,"xr-standard-trigger",!0,t))});r(this,"onSelectEnd",t=>{this.emitPointerUpEvent&&(Bh||this.inputSource===t.inputSource&&this.emitPointerEvent(Te.PointerUp,this._selectButtonIndex||0,"xr-standard-trigger",!0,t))});r(this,"onSequeezeStart",t=>{var e,i,n;this.emitPointerDownEvent&&this.inputSource===t.inputSource&&(this._squeezeButtonIndex=(n=(i=(e=this._layout)==null?void 0:e.components["xr-standard-squeeze"])==null?void 0:i.gamepadIndices)==null?void 0:n.button,this._squeezeButtonIndex!==void 0&&(Zn&&N.DrawDirection(this.rayWorldPosition,V(0,.01,1).applyQuaternion(this.rayWorldQuaternion),255,10),this.emitPointerEvent(Te.PointerDown,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,t)))});r(this,"onSequeezeEnd",t=>{this.emitPointerUpEvent&&this.inputSource===t.inputSource&&this._squeezeButtonIndex!==void 0&&this.emitPointerEvent(Te.PointerUp,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,t)});r(this,"states",{});r(this,"_didMoveLastFrame",!1);r(this,"_lastPointerMovePosition",new h.Vector3);r(this,"_lastPointerMoveQuaternion",new h.Quaternion);r(this,"pointerInit");this.xr=t,this.inputSource=e,this.index=i,this._object=new h.Object3D,this._object.name=`NeedleXRController_${i}`,Zn&&(this._object.add(this._debugAxesHelper),this._gripSpaceObject=new h.Object3D,this._raySpaceObject=new h.Object3D,this._gripSpaceObject.name=`NeedleXRController_${i}_gripSpace`,this._raySpaceObject.name=`NeedleXRController_${i}_raySpace`,this._gripSpaceObject.add(this._debugGripAxesHelper),this._raySpaceObject.add(this._debugRayAxesHelper),this.xr.context.scene.add(this._gripSpaceObject),this.xr.context.scene.add(this._raySpaceObject)),this.xr.context.scene.add(this._object),this._ray=new h.Ray,this.pointerInit={origin:this,pointerType:this.hand?"hand":"controller",deviceIndex:this.index,pointerId:-1,mode:this.inputSource.targetRayMode,ray:this._ray,device:this._object,buttonName:"none"},this.initialize(),this.subscribeEvents()}get context(){return this.xr.context}get connected(){return this._connected}get isTracking(){return this._isTracking}get gamepad(){return this.__gamepad??(this.__gamepad=this.inputSource.gamepad)}get isHand(){return this.hand!=null}get hand(){return this.__hand??(this.__hand=this.inputSource.hand)}get handObject(){return this.context.renderer.xr.getHand(this.index)}get profiles(){return this.inputSource.profiles}get layout(){return this._layout}get targetRayMode(){return this.inputSource.targetRayMode}get targetRaySpace(){return this.inputSource.targetRaySpace}get gripSpace(){return this.inputSource.gripSpace}get side(){return this.__side??(this.__side=this.inputSource.handedness)}get isRight(){return this.side==="right"}get isLeft(){return this.side==="left"}get isStylus(){return this._isMxInk}getHitTestSource(){return this._hitTestSource||this._requestHitTestSource(),this._hitTestSource}get hasHitTestSource(){return this._hitTestSource}cancelHitTestSource(){this._hitTestSource&&(this._hitTestSource.cancel(),this._hitTestSource=void 0)}get hasSelectEvent(){return this._hasSelectEvent}getHitTest(){return this.xr.getHitTest(this)}getHandJointPose(t,e){var n;if(e=e||this.xr.frame,!this.hand||!(e!=null&&e.getJointPose)||!this.xr.referenceSpace)return null;let i=(n=this._handJointPoses)==null?void 0:n.get(t);return i||(i=e.getJointPose(t,this.xr.referenceSpace),i&&this._handJointPoses.set(t,i),i)}get gripPosition(){return V(this._gripPosition)}get gripQuaternion(){return on(this._gripQuaternion)}get gripMatrix(){return this._gripMatrix}get gripLinearVelocity(){return V(this._linearVelocity).applyQuaternion(Bi)}get rayPosition(){return V(this._rayPosition)}get rayQuaternion(){return on(this._rayQuaternion)}get gripWorldPosition(){return V(this._gripWorldPosition)}get gripWorldQuaternion(){return on(this._gripWorldQuaternion)}get rayWorldPosition(){return V(this._rayWorldPosition)}updateRayWorldPosition(){var e;const t=(e=this.xr.context.mainCamera)==null?void 0:e.parent;this._rayWorldPosition.copy(this._rayPositionRaw),t&&this._rayWorldPosition.applyMatrix4(t.matrixWorld)}get rayWorldQuaternion(){return on(this._rayWorldQuaternion)}get pinchPosition(){return V(this._pinchPosition)}updateRayWorldQuaternion(){var i;const t=(i=this.xr.context.mainCamera)==null?void 0:i.parent,e=t?ye(t):void 0;this._rayWorldQuaternion.copy(this._rayRotationRaw).multiply(Bi),e&&this._rayWorldQuaternion.premultiply(e)}get ray(){return this._ray.origin.copy(this.rayWorldPosition),this._ray.direction.copy(V(0,0,1).applyQuaternion(this.rayWorldQuaternion)),this._ray}get handWristDotUp(){var e;if(this._hand_wristDotUp!==void 0)return this._hand_wristDotUp;const t=(e=this.handObject)==null?void 0:e.joints.wrist;if(t){const i=V(0,1,0).applyQuaternion(t.quaternion),n=V(0,1,0).dot(i);return this._hand_wristDotUp=n}}get isHandUpsideDown(){return this.handWristDotUp!==void 0?this.handWristDotUp<-.7:!1}get isTeleportGesture(){var t;return this.isHandUpsideDown&&((t=this.getGesture("pinch"))==null?void 0:t.isDown)}get object(){return this._object}async getModelUrl(){var t;return(t=this.getMotionController)==null?void 0:t.then(e=>(e==null?void 0:e.assetUrl)||null)}_requestHitTestSource(){var t;return this._hitTestSourcePromise?this._hitTestSourcePromise:this.xr.mode==="immersive-ar"&&this.inputSource.targetRayMode==="tracked-pointer"&&this.xr.session.requestHitTestSourceForTransientInput?this._hitTestSourcePromise=((t=this.xr.session.requestHitTestSourceForTransientInput({profile:this.inputSource.profiles[0],offsetRay:new XRRay}))==null?void 0:t.then(e=>(this._hitTestSourcePromise=null,this.connected?this._hitTestSource=e:(e.cancel(),null))))??null:null}onUpdate(t){performance.mark("NeedleXRController onUpdate start"),this.onUpdateFrame(t),this.updateInputEvents(),this.onUpdateMove(),performance.mark("NeedleXRController onUpdate end"),performance.measure("NeedleXRController onUpdate","NeedleXRController onUpdate start","NeedleXRController onUpdate end")}onRenderDebug(){var o;N.DrawSphere(this.rayWorldPosition,.003),N.DrawDirection(this.rayWorldPosition,V(0,0,10).applyQuaternion(this.rayWorldQuaternion));const e=(this.inputSource.gripSpace?this.gripWorldPosition:this.object.worldPosition).sub(this.object.worldForward.multiplyScalar(.1)),i=this.inputSource.profiles.join(`
135
135
  `);let n=`Controller[${this.index}] (${this.inputSource.targetRayMode}, ${this.side})
136
136
  C:${this.connected?"x":"-"} T:${this.isTracking?"x":"-"} Hand:${this.inputSource.hand?"x":"-"} Pen: ${this._isMxInk?"x":"-"}`;if(this.inputSource.hand&&(n+=`
@@ -922,7 +922,7 @@ Using the assigned clip instead:`,this.clip),t=this.clip);let e=!this.sound||t&&
922
922
  Audio:`,a.getAudioTracks(),`
923
923
  Video:`,a.getVideoTracks()),this._stream=a,n==="incoming"){const l=new z0(e,a,this);this.dispatchEvent(l)}}),i.on("close",()=>{this.dispatchEvent(new bg(e,n))})}get stream(){return this._stream}close(){this._isDisposed||(this._isDisposed=!0,this.call.close(),Ln(this._stream))}get isOpen(){var e;return((e=this.call.peerConnection)==null?void 0:e.connectionState)==="connected"}get isOpening(){var e;return((e=this.call.peerConnection)==null?void 0:e.connectionState)==="connecting"}get isClosed(){return!this.isOpen||this._isDisposed}}function Uy(s){return s=s.replace("a=fmtp:111 minptime=10;useinbandfec=1","a=fmtp:111 ptime=5;useinbandfec=1;stereo=1;maxplaybackrate=48000;maxaveragebitrat=128000;sprop-stereo=1"),s}const ba=class extends h.EventDispatcher{constructor(e,i){super();r(this,"updateCalls",()=>{var e;for(let i=this._incomingCalls.length-1;i>=0;i--){const n=this._incomingCalls[i];n.isClosed&&!n.isOpening&&this._incomingCalls.splice(i,1)}for(let i=this._outgoingCalls.length-1;i>=0;i--){const n=this._outgoingCalls[i];let o=!1;n.isClosed&&!n.isOpening&&((e=n.stream)!=null&&e.active?He&&console.warn("!!! Stream is still active, don't remove call",n.userId,"Your id: "+this.context.connection.connectionId):(He&&console.warn("!!! Remove closed call",n.userId),o=!0)),this.context.connection.userIsInRoom(n.userId)===!1&&(He&&console.warn("!!! User is not in room anymore, remove call",n.userId),o=!0),o&&(n.close(),this._outgoingCalls.splice(i,1))}});r(this,"id");r(this,"context");r(this,"_incomingCalls",[]);r(this,"_outgoingCalls",[]);r(this,"_peer");r(this,"_enabled",!1);r(this,"_enabledPeer",!1);r(this,"onConnectRoomFn",this.onConnectRoom.bind(this));r(this,"onPeerConnect",e=>{if(He&&console.log("PEER opened as",e),e===null){console.error("Peer connection failed",e);return}this.context.connection.send("peer-user-connected",new DP(this,e))});r(this,"onPeerClose",()=>{He&&console.log("PEER closed"),this.updateCalls()});r(this,"onPeerDisconnected",()=>{He&&console.log("PEER disconnected"),this.updateCalls()});r(this,"onPeerError",e=>{He&&console.error("PEER error",e)});r(this,"onPeerReceivingCall",e=>{e.answer(void 0,{sdpTransform:i=>Uy(i)}),this.registerCall(e,"incoming",null)});this.context=e,this.id=i,this.setupPeer(),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia}static getOrCreate(e,i){if(ba.instances.has(i))return ba.instances.get(i);const n=new ba(e,i);return ba.instances.set(i,n),n}getMyPeerId(){if(this.context.connection.connectionId)return this.getPeerIdFromUserId(this.context.connection.connectionId)}getPeerIdFromUserId(e){return this.id+"-"+e}getUserIdFromPeerId(e){return e.substring(this.id.length+1)}makeCall(e,i){var a;if(!(i!=null&&i.id)){He?console.warn("Can not make a call: mediastream has no id or is undefined"):console.debug("Can not make a call: mediastream has no id or is undefined");return}const n={metadata:{userId:this.context.connection.connectionId,streamId:i.id},sdpTransform:l=>Uy(l)},o=(a=this._peer)==null?void 0:a.call(e,i,n);if(o){const l=this.registerCall(o,"outgoing",i);return He&&console.warn(`📞 CALL ${e}`,`
924
924
  Outgoing:`,this._outgoingCalls,`
925
- Incoming:`,this._incomingCalls),l}else He&&console.error("Failed to make call",e,i,this._peer)}closeAll(){for(const e of this._incomingCalls)e.close();for(const e of this._outgoingCalls)e.close();this.updateCalls()}get peer(){return this._peer}get incomingCalls(){return this._incomingCalls}enable(){this._enabled||(this._enabled=!0,this.context.connection.beginListen(Z.JoinedRoom,this.onConnectRoomFn),this.subscribePeerEvents())}disable(){this._enabled&&(this._enabled=!1,this.context.connection.stopListen(Z.JoinedRoom,this.onConnectRoomFn),this.unsubscribePeerEvents())}onConnectRoom(){this.setupPeer()}setupPeer(){if(this.context.connection.connectionId&&!this._enabledPeer){if(this._enabledPeer=!0,!this._peer){const e=this.getMyPeerId();e?this._peer=_v(e):console.error("Failed to setup peerjs because we dont have a connection id",this.context.connection.connectionId)}this._enabled&&this.subscribePeerEvents()}}subscribePeerEvents(){this._peer&&(this._peer.on("open",this.onPeerConnect),this._peer.on("close",this.onPeerClose),this._peer.on("call",this.onPeerReceivingCall),this._peer.on("disconnected",this.onPeerDisconnected),this._peer.on("error",this.onPeerError))}unsubscribePeerEvents(){this._peer&&(this._peer.off("open",this.onPeerConnect),this._peer.off("close",this.onPeerClose),this._peer.off("call",this.onPeerReceivingCall),this._peer.off("disconnected",this.onPeerDisconnected),this._peer.off("error",this.onPeerError))}registerCall(e,i,n){const o=e.metadata;(!o||!o.userId)&&console.error("Missing call metadata",e);const a=o.userId;i==="incoming"&&He?console.warn("← Receive call from",e.metadata,e.connectionId):He&&console.warn("→ Make call to",e.metadata);const l=i==="incoming"?this._incomingCalls:this._outgoingCalls,c=new LP(a,e,i,n);return l.push(c),e.on("error",d=>{console.error("Call error",d)}),e.on("close",()=>{He&&console.log("Call ended",e.metadata);const d=l.indexOf(c);d!==-1&&l.splice(d,1),c.close(),this.dispatchEvent(new bg(a,i))}),c.addEventListener("call-ended",d=>{this.dispatchEvent(d)}),i==="incoming"&&(c.addEventListener("receive-stream",d=>{this.dispatchEvent(d)}),e.on("stream",()=>{He&&console.log("Received stream for call",e.metadata);let d=0;const u=setInterval(()=>{const f=d===0;!c.isOpen&&f&&(He&&console.warn("Close call because stream is not active",e.metadata),d+=1,clearInterval(u),c.close())},2e3)})),c}};let cr=ba;r(cr,"instances",new Map);class nh extends h.EventDispatcher{constructor(e,i){super();r(this,"context");r(this,"peer");r(this,"_sendingStreams",new Map);r(this,"debug",!1);r(this,"_enabled",!1);r(this,"_tickIntervalId");r(this,"tick",()=>{this.updateSendingCalls()});r(this,"onJoinedRoom",e=>{this._sendingStreams.size>0&&(this.debug&&console.warn(`${e!=null&&e.userId?`User ${e.userId}`:"You"} joined room`,e,this._sendingStreams.size),this.updateSendingCalls())});r(this,"onLeftRoom",e=>{this.debug&&console.warn(`${(e==null?void 0:e.userId)||"You"} left room`,e),this.stopCallsToUsersThatAreNotInTheRoomAnymore(),this.peer.closeAll()});r(this,"onCallStreamReceived",e=>{this.debug&&console.log("Call with "+e.userId+" started"),this.dispatchEvent({type:"receive-stream",target:this,stream:e.stream,userId:e.userId}),this.debug&&this.debugLogCurrentState()});r(this,"onCallEnded",e=>{this.debug&&console.log("Call with "+e.userId+" ended"),this.dispatchEvent(e),this.debug&&this.debugLogCurrentState()});r(this,"onUserConnected",e=>{if(this.peer.id===e.guid){this.debug&&console.log("PEER USER CONNECTED",e.guid,e,this._sendingStreams.size);const i=this._sendingStreams.keys().next().value;this.peer.makeCall(e.peerId,i)}else He&&console.log("Unknown user connected",e.guid,e.peerId)});r(this,"onUserLeft",e=>{this.debug&&console.log("User left room: "+e.userId),this.stopCallsToUsersThatAreNotInTheRoomAnymore()});if(j0(e)){const n=e;e=n.context,i=cr.getOrCreate(n.context,n.guid)}else typeof i=="string"&&(i=cr.getOrCreate(e,i));if(e){if(!(e instanceof Q))throw new Error("Failed to create NetworkedStreams because context is not an instance of Context")}else throw new Error("Failed to create NetworkedStreams because context is undefined");if(!i)throw new Error("Failed to create NetworkedStreams because peer is undefined");this.context=e,this.peer=i,He&&(this.debug=!0)}static create(e,i){const n=cr.getOrCreate(e.context,i||e.context.connection.connectionId||e.guid);return new nh(e.context,n)}startSendingStream(e){this._sendingStreams.has(e)?console.warn("Received start sending stream with stream that is already being sent"):(this._sendingStreams.set(e,[]),this.updateSendingCalls())}stopSendingStream(e){if(e){const i=this._sendingStreams.get(e);if(i){for(const n of i)n.close();i.length=0}this._sendingStreams.delete(e),i&&this.debug&&this.debugLogCurrentState()}this.updateSendingCalls()}get enabled(){return this._enabled}enable(){this._enabled||(this._enabled=!0,this.peer.enable(),this.peer.addEventListener("receive-stream",this.onCallStreamReceived),this.peer.addEventListener("call-ended",this.onCallEnded),this.context.connection.beginListen("peer-user-connected",this.onUserConnected),this.context.connection.beginListen(Z.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(Z.UserJoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(Z.UserLeftRoom,this.onUserLeft),this.context.connection.beginListen(Z.LeftRoom,this.onLeftRoom),this._tickIntervalId=setInterval(this.tick,5e3))}disable(){this._enabled&&(this._enabled=!1,this.peer.disable(),this.peer.removeEventListener("receive-stream",this.onCallStreamReceived),this.peer.removeEventListener("call-ended",this.onCallEnded),this.context.connection.stopListen("peer-user-connected",this.onUserConnected),this.context.connection.stopListen(Z.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(Z.UserJoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(Z.UserLeftRoom,this.onUserLeft),this.context.connection.stopListen(Z.LeftRoom,this.onLeftRoom),this._tickIntervalId!=null&&(clearInterval(this._tickIntervalId),this._tickIntervalId=void 0))}updateSendingCalls(){const e=this.context.connection.connectionId;for(const i of this._sendingStreams.keys()){const n=this._sendingStreams.get(i)||[];for(const o of this.context.connection.usersInRoom()){if(o===e)continue;const a=this.peer.getPeerIdFromUserId(o);if(n.find(c=>{var d;return c.peerId===a&&c.direction==="outgoing"&&!c.isClosed&&((d=c.stream)==null?void 0:d.active)}))He&&console.debug("Already have a call with user "+o+" / peer "+a);else{const c=this.peer.makeCall(a,i);c&&n.push(c)}}this._sendingStreams.set(i,n)}this.stopCallsToUsersThatAreNotInTheRoomAnymore()}stopCallsToUsersThatAreNotInTheRoomAnymore(){for(const e of this._sendingStreams.keys()){const i=this._sendingStreams.get(e);if(i)for(let n=i.length-1;n>=0;n--){const o=i[n];this.context.connection.userIsInRoom(o.userId)?He&&(this.context.connection.connectionId===o.userId?console.warn(`You are still in the room [${n}] ${o.userId}`):console.log(`User is still in room [${n}] ${o.userId}`)):(He&&console.log(`Remove call ${[n]} to user that is not in room anymore ${o.userId}`),o.close(),i.splice(n,1))}}this.peer.updateCalls(),this.debug&&this.debugLogCurrentState()}debugLogCurrentState(){console.warn(`You (${this.context.connection.connectionId}) are currently sending ${this._sendingStreams.size} and receiving ${this.peer.incomingCalls.length} calls (${this.peer.incomingCalls.map(e=>e.userId).join(", ")})`,this.peer.incomingCalls)}}function Ln(s){if(s&&s instanceof MediaStream)for(const t of s.getTracks())t.stop()}var IP=Object.defineProperty,jP=Object.getOwnPropertyDescriptor,vg=(s,t,e,i)=>{for(var n=i>1?void 0:i?jP(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&IP(t,e,n),n};const BP="noVoip",FP=S("debugvoip");class xo extends D{constructor(){super(...arguments);r(this,"autoConnect",!0);r(this,"runInBackground",!0);r(this,"createMenuButton",!0);r(this,"debug",!1);r(this,"_net");r(this,"_menubutton");r(this,"_allowSending",!0);r(this,"_outputStream",null);r(this,"onJoinedRoom",async()=>{this.debug&&console.log("VOIP: Joined room"),await un(300),this.autoConnect&&!this.isSending&&this._allowSending&&this.connect()});r(this,"onLeftRoom",()=>{this.debug&&console.log("VOIP: Left room"),this.disconnect();for(const e of this._incomingStreams.values())Ln(e.srcObject);this._incomingStreams.clear()});r(this,"_incomingStreams",new Map);r(this,"onReceiveStream",e=>{const i=e.target.userId,n=e.stream;let o=this._incomingStreams.get(i);o||(o=new Audio,this._incomingStreams.set(i,o)),o.srcObject=n,o.setAttribute("autoplay","true"),cn.registerWaitForInteraction(()=>{o==null||o.play().catch(a=>{console.error("VOIP: Failed to play audio",a)})})});r(this,"onStreamEnded",e=>{const i=this._incomingStreams.get(e.userId);Ln(i==null?void 0:i.srcObject),this._incomingStreams.delete(e.userId)});r(this,"onEnabledChanged",()=>{for(const e of this._incomingStreams){const i=e[1];i.muted=!this.enabled}});r(this,"onVisibilityChanged",()=>{if(this.runInBackground)return;const i=!(document.visibilityState==="visible");this.setMuted(i);for(const n of this._incomingStreams){const o=n[1];o.muted=i}})}awake(){FP&&(this.debug=!0),this.debug&&(console.log("VOIP debugging: press 'v' to toggle mute or 'c' to toggle connect/disconnect"),window.addEventListener("keydown",async e=>{switch(e.key.toLowerCase()){case"v":console.log("MUTE?",!this.isMuted),this.setMuted(!this.isMuted);break;case"c":this.isSending?this.disconnect():this.connect();break}}),window.addEventListener("blur",()=>{console.log("VOIP: MUTE ON BLUR"),this.setMuted(!0)}),window.addEventListener("focus",()=>{console.log("VOIP: UNMUTE ON FOCUS"),this.setMuted(!1)}))}onEnable(){this._net||(this._net=nh.create(this)),this.debug&&(this._net.debug=!0),this._net.addEventListener(Dn.StreamReceived,this.onReceiveStream),this._net.addEventListener(Dn.StreamEnded,this.onStreamEnded),this._net.enable(),this.autoConnect&&this.context.connection.isConnected&&this.connect(),this.context.connection.beginListen(Z.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(Z.LeftRoom,this.onLeftRoom),this.onEnabledChanged(),this.updateButton(),window.addEventListener("visibilitychange",this.onVisibilityChanged)}onDisable(){var e;this._net&&(this._net.stopSendingStream(this._outputStream),this._net.removeEventListener(Dn.StreamReceived,this.onReceiveStream),this._net.removeEventListener(Dn.StreamEnded,this.onStreamEnded),(e=this._net)==null||e.disable()),this.context.connection.stopListen(Z.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(Z.LeftRoom,this.onLeftRoom),this.onEnabledChanged(),this.updateButton(),window.removeEventListener("visibilitychange",this.onVisibilityChanged)}onDestroy(){var e;(e=this._menubutton)==null||e.remove(),this._menubutton=void 0}get isSending(){return this._outputStream!=null&&this._outputStream.active}async connect(e){var i,n;if(!this._net)return console.error("Cannot connect to voice chat - NetworkedStreams not initialized. Make sure the component is enabled before calling this method."),!1;if(this.context.connection.isConnected){if(!await exports.DeviceUtilities.microphonePermissionsGranted())return console.error("Cannot connect to voice chat - microphone permissions not granted"),this.updateButton(),!1}else return console.error("Cannot connect to voice chat - not connected to server"),this.updateButton(),!1;return this._allowSending=!0,(i=this._net)==null||i.stopSendingStream(this._outputStream),Ln(this._outputStream),this._outputStream=await this.getAudioStream(e),this._outputStream?(this.debug&&console.log("VOIP: Got audio stream"),(n=this._net)==null||n.startSendingStream(this._outputStream),this.updateButton(),!0):(this.updateButton(),await exports.DeviceUtilities.microphonePermissionsGranted()?console.error("VOIP: Could not get audio stream - please make sure to connect an audio device and grant microphone permissions"):Gc("Microphone permissions not granted: Please grant microphone permissions to use voice chat"),(this.debug||B())&&console.log("VOIP: Failed to get audio stream"),!1)}disconnect(e){var i;e!=null&&e.remember&&(this._allowSending=!1),(i=this._net)==null||i.stopSendingStream(this._outputStream),Ln(this._outputStream),this._outputStream=null,this.updateButton()}setMuted(e){var n;const i=(n=this._outputStream)==null?void 0:n.getAudioTracks();if(i)for(const o of i)o.enabled=!e}get isMuted(){var i;if(this._outputStream===null)return!1;const e=(i=this._outputStream)==null?void 0:i.getAudioTracks();if(e){for(const n of e)if(!n.enabled)return!0}return!1}async updateButton(){var e;if(this.createMenuButton){if(this._menubutton||(this._menubutton=document.createElement("button"),this._menubutton.addEventListener("click",()=>{this.isSending?this.disconnect({remember:!0}):this.connect(),exports.DeviceUtilities.microphonePermissionsGranted().then(i=>{i||me("<strong>Microphone permissions not granted</strong>. Please allow your browser to use the microphone to be able to talk. Click on the button on the left side of your browser's address bar to allow microphone permissions.")})})),this._menubutton){this.context.menu.appendChild(this._menubutton),this.activeAndEnabled?this._menubutton.style.display="":this._menubutton.style.display="none",this._menubutton.title=this.isSending?"Click to disable your microphone":"Click to enable your microphone";let i=(this.isSending,""),n=this.isSending?"mic":"mic_off";await exports.DeviceUtilities.microphonePermissionsGranted()||(i="No Permission",n="mic_off",this._menubutton.title="Microphone permissions not granted. Please allow your browser to use the microphone to be able to talk. This can usually be done in the addressbar of the webpage."),this._menubutton.innerText=i,this._menubutton.prepend(bt(n)),this.context.connection.isConnected==!1?this._menubutton.setAttribute("disabled",""):this._menubutton.removeAttribute("disabled")}}else this.activeAndEnabled||(e=this._menubutton)==null||e.remove()}getFrequency(e){return this.unsupported_getfrequency||(this.unsupported_getfrequency=!0,B()&&me("VOIP: getFrequency is currently not supported"),console.warn("VOIP: getFrequency is currently not supported")),null}async getAudioStream(e){if(!navigator.mediaDevices.getUserMedia)return console.error("No getDisplayMedia support"),null;const i=async o=>await navigator.mediaDevices.getUserMedia({audio:o??!0,video:!1}).catch(a=>(console.warn("VOIP failed getting audio stream",a),null)),n=await i(e);if(!n)return null;if(exports.DeviceUtilities.isiOS()&&(e==null?void 0:e.deviceId)===void 0){const a=(await navigator.mediaDevices.enumerateDevices()).find(l=>(l.kind==="audioinput"||l.kind==="audiooutput")&&!l.label.includes("iPhone"));if(a){const l=Object.assign({},e);return l.deviceId=a.deviceId,await i(l)}}return n}}vg([p()],xo.prototype,"autoConnect",2);vg([p()],xo.prototype,"runInBackground",2);vg([p()],xo.prototype,"createMenuButton",2);var UP=Object.defineProperty,zP=Object.getOwnPropertyDescriptor,V0=(s,t,e,i)=>{for(var n=i>1?void 0:i?zP(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&UP(t,e,n),n};const NP=S("debugmouth");class sh extends D{constructor(){super(...arguments);r(this,"idle",[]);r(this,"talking",[]);r(this,"marker",null);r(this,"voip",null);r(this,"lastMouthChangeTime",0);r(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=C.findObjectOfType(xo,this.context),this.marker||(this.marker=C.getComponentInParent(this.gameObject,it))},3e3)}update(){var n;if(!this.voip||this.context.time.frameCount%10!==0)return;let e=((n=this.marker)==null?void 0:n.connectionId)??null;if(!e){NP&&(e=null);return}const i=this.voip.getFrequency(e)??0;this.updateLips(i)}updateLips(e){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&e>30){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.talking.length);this.setMouthShapeActive(this.talking,i)}else if(this.idle.length>0&&this.context.time.time-this.lastMouthChangeTime>.5){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.idle.length);this.setMouthShapeActive(this.idle,i)}}}setMouthShapeActive(e,i){if(e){e!=this.idle?this.idle.map(n=>n.visible=!1):this.talking.map(n=>n.visible=!1);for(let n=0;n<e.length;n++){const o=e[n];o&&(o.visible=n===i)}}}}V0([p(h.Object3D)],sh.prototype,"idle",2);V0([p(h.Object3D)],sh.prototype,"talking",2);class wg extends D{constructor(){super(...arguments);r(this,"voip",null);r(this,"marker",null);r(this,"_startPosition",null)}awake(){this.voip=C.findObjectOfType(xo,this.context),this.marker=C.getComponentInParent(this.gameObject,it)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const e=this.marker.connectionId,i=this.voip.getFrequency(e);if(i==null)return;this._startPosition||(this._startPosition=this.gameObject.position.clone());const n=i/100;this.gameObject.position.y=this._startPosition.y+n*.07}}var VP=Object.defineProperty,$P=Object.getOwnPropertyDescriptor,WP=(s,t,e,i)=>{for(var n=i>1?void 0:i?$P(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&VP(t,e,n),n};const ca=S("debugxrflags"),$0=S("disablexrflags");$0&&console.warn("XRFlags are disabled");var Tn=(s=>(s[s.Never=0]="Never",s[s.Browser=1]="Browser",s[s.AR=2]="AR",s[s.VR=4]="VR",s[s.FirstPerson=8]="FirstPerson",s[s.ThirdPerson=16]="ThirdPerson",s[s.All=4294967295]="All",s))(Tn||{});const C_=class{constructor(){r(this,"Mask",17)}Has(t){return(this.Mask&t)!==0}Set(t){ca&&console.warn("Set XR flag state to",t),this.Mask=t,yi.Apply()}Enable(t){this.Mask|=t,yi.Apply()}Disable(t){this.Mask&=~t,yi.Apply()}Toggle(t){this.Mask^=t,yi.Apply()}EnableAll(){this.Mask=-1,yi.Apply()}DisableAll(){this.Mask=0,yi.Apply()}};let vt=C_;r(vt,"Global",new C_);var Tl;const ss=(Tl=class extends D{constructor(){super(...arguments);r(this,"visibleIn")}static Apply(){for(const t of this.registry)t.UpdateVisible(vt.Global)}awake(){ss.registry.push(this)}onEnable(){ss.firstApply?this.UpdateVisible(vt.Global):(ss.firstApply=!0,ss.Apply())}onDestroy(){const t=ss.registry.indexOf(this);t>=0&&ss.registry.splice(t,1)}get isOn(){return this.gameObject.visible}UpdateVisible(t=null){if($0)return;let e;const i=t;if(i&&typeof i=="number"&&(console.assert(typeof i=="number","XRFlag.UpdateVisible: state must be a number",i),ca&&console.log(i),ss.buffer.Mask=i,t=ss.buffer),t instanceof vt?(ca&&console.warn(this.name,"use passed in mask",t.Mask,this.visibleIn),e=t.Has(this.visibleIn)):(ca&&console.log(this.name,"use global mask"),vt.Global.Has(this.visibleIn)),e!==void 0)if(e)ca&&console.log(this.name,"is visible",this.gameObject.uuid),C.setActive(this.gameObject,!0);else{if(ca&&console.log(this.name,"is not visible",this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}},r(Tl,"registry",[]),r(Tl,"firstApply"),r(Tl,"buffer",new vt),Tl);let yi=ss;WP([p()],yi.prototype,"visibleIn",2);var HP=Object.defineProperty,GP=Object.getOwnPropertyDescriptor,Nu=(s,t,e,i)=>{for(var n=i>1?void 0:i?GP(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&HP(t,e,n),n};class kr extends D{constructor(){super(...arguments);r(this,"eyes",[]);r(this,"lastBlinkTime",0);r(this,"blinkLength",0);r(this,"eyesOpen",!0);r(this,"state",null)}awake(){this.state=C.getComponentInParent(this.gameObject,yi)}update(){if(!this.gameObject||!this.gameObject.visible||!this.eyes||!Array.isArray(this.eyes)||this.eyes.length===0)return;if(this.context.time.time-this.lastBlinkTime>this.blinkLength){if(this.lastBlinkTime=this.context.time.time,this.state&&!this.state.isOn||!this.activeAndEnabled)return;if(this.eyesOpen=!this.eyesOpen,this.blinkLength=Math.random(),this.eyesOpen?(this.blinkLength*=3,this.blinkLength+=.5,Math.random()<.1&&(this.blinkLength=.1+Math.random()*.2)):(this.blinkLength*=Math.random()*.2,this.blinkLength+=.1),Math.random()<.1&&(this.blinkLength*=3),this.blinkLength=Math.max(.2,this.blinkLength),this.blinkLength=Math.min(3,this.blinkLength),this.eyes)for(const i of this.eyes)i&&(i.visible=this.eyesOpen)}}}Nu([p(h.Object3D)],kr.prototype,"eyes",2);Nu([p()],kr.prototype,"lastBlinkTime",2);Nu([p()],kr.prototype,"blinkLength",2);Nu([p()],kr.prototype,"eyesOpen",2);var qP=Object.defineProperty,XP=Object.getOwnPropertyDescriptor,xg=(s,t,e,i)=>{for(var n=i>1?void 0:i?XP(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&qP(t,e,n),n},Mp;const W0=(Mp=class extends D{constructor(){super(...arguments);r(this,"head",null);r(this,"eyes",null);r(this,"target",null);r(this,"brain",null);r(this,"vec",new h.Vector3);r(this,"currentTargetPoint",new h.Vector3)}awake(){this.brain||(this.brain=C.getComponentInParent(this.gameObject,Rc)),this.brain||(this.brain=C.addComponent(this.gameObject,Rc)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const t=this.target;if(t&&this.head){const e=this.eyes;if(e){const i=K(t);this.currentTargetPoint.lerp(i,this.context.time.deltaTime/.1);const n=K(this.head),o=this.vec.copy(this.currentTargetPoint).sub(n).normalize();if(o.length()<.1)return;const a=W0.forward;if(a.set(0,0,1),a.applyQuaternion(ye(this.head)),a.dot(o)>.45)for(let c=0;c<e.length;c++)e[c].lookAt(this.currentTargetPoint)}}}},r(Mp,"forward",new h.Vector3(0,0,1)),Mp);let Wa=W0;xg([p(h.Object3D)],Wa.prototype,"head",2);xg([p(h.Object3D)],Wa.prototype,"eyes",2);xg([p(h.Object3D)],Wa.prototype,"target",2);const wl=S("debugavatar");class Vu{constructor(t,e,i,n){r(this,"root");r(this,"head");r(this,"leftHand");r(this,"rigthHand");var o;this.root=t,this.head=e,this.leftHand=i,this.rigthHand=n,(o=this.root)==null||o.traverse(a=>a.layers.set(2))}get isValid(){return this.head!==null&&this.head!==void 0}}class Sg{constructor(){r(this,"avatarRegistryUrl",null)}async getOrCreateNewAvatarInstance(t,e){if(!e)return console.error("Can not create avatar: failed to provide id or root object"),null;let i=null;if(typeof e=="string"){if(i=await this.loadAvatar(t,e),!i){const o=new pn;i=C.instantiate(Aa(e,t.scene),o)}}else i=e;if(!i)return null;const n=this.findAvatar(i);return n.isValid?(wl&&console.log("[Custom Avatar] valid config",e,wl?n:""),n):(console.warn("[Custom Avatar] config isn't valid",e,wl?n:""),null)}async loadAvatar(t,e){if(console.assert(e!=null&&typeof e=="string","Avatar id must not be null"),e.length<=0||!e)return null;if(wl&&console.log("[Custom Avatar] "+e+", loading..."),e.endsWith(".glb")||(e+=".glb"),this.avatarRegistryUrl===null){const n=await fetch("./"+e);let o=null;if(n.ok){const l=await n.blob();l&&(o=await l.arrayBuffer())}if(!o)return null;const a=await dn().parseSync(t,o,null,0);return(a==null?void 0:a.scene)??null}const i=new Y.GLTFLoader;return Lu(i,t),new Promise((n,o)=>{const a=this.avatarRegistryUrl+"/"+e;i.load(a,async l=>{await dn().createBuiltinComponents(t,a,l,null,void 0),n(l.scene)},l=>{wl&&console.log("[Custom Avatar] "+l.loaded/l.total*100+"% loaded of "+l.total/1024+"kB")},l=>{console.error("[Custom Avatar] Error when loading: "+l),n(null)})})}cacheModel(t,e){}findAvatar(t){const e=t;let i=e;i.children.length==1&&(i=t.children[0]);let n=this.findAvatarPart(i,["head"]);const o=this.findAvatarPart(i,["left","hand"]),a=this.findAvatarPart(i,["right","hand"]);if(!n){n=e;const c=new h.Vector3;new h.Box3().setFromObject(n).getSize(c);const d=Math.max(c.x,c.y,c.z);console.warn("[Custom Avatar] Normalizing head scale, it's too big: "+d+" meters! Should be < 0.3m"),d>.3&&n.scale.multiplyScalar(1/d*.3)}return new Vu(e,n,o,a)}findAvatarPart(t,e){const i=t.name.toLowerCase();let n=!0;for(const o of e){if(!n)break;i.indexOf(o)===-1&&(n=!1)}if(n)return t;if(t.children)for(const o of t.children){const a=this.findAvatarPart(o,e);if(a)return a}return null}handleCustomAvatarErrors(t){if(!t.ok)throw Error(t.statusText);return t}}var QP=Object.defineProperty,YP=Object.getOwnPropertyDescriptor,Cg=(s,t,e,i)=>{for(var n=i>1?void 0:i?YP(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&QP(t,e,n),n};class Ha extends D{constructor(){super(...arguments);r(this,"length",1);r(this,"depthTest",!0);r(this,"isGizmo",!1);r(this,"_axes",null)}onEnable(){if(this.isGizmo&&!Qc)return;this._axes||(this._axes=new h.AxesHelper(this.length)),this._axes.layers.disableAll(),this._axes.layers.set(this.layer),this.gameObject.add(this._axes);const e=this._axes.material;e&&e.depthTest!==void 0&&(e.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}Cg([p()],Ha.prototype,"length",2);Cg([p()],Ha.prototype,"depthTest",2);Cg([p()],Ha.prototype,"isGizmo",2);class Pg extends D{constructor(){super(...arguments);r(this,"from");r(this,"to");r(this,"hint");r(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;const e=K(this.to).clone(),i=K(this.from).clone(),n=e.distanceTo(i),o=e.clone();o.sub(i);const a=i.clone();a.add(e),a.multiplyScalar(.5);const l=K(this.hint).clone();l.sub(a);const c=new h.Vector3;c.crossVectors(l,o),c.crossVectors(o,c),c.normalize();const d=n*.5,u=Math.max(this.desiredDistance,d),f=Math.sqrt(u*u-d*d),m=c.clone();m.multiplyScalar(f),m.add(a),nt(this.gameObject,m);const g=a.clone();g.sub(c),this.gameObject.lookAt(g)}}const KP=S("gizmos"),ZP=S("debugboxhelper"),nn=class extends D{constructor(){super(...arguments);r(this,"box",null);r(this,"_lastMatrixUpdateFrame",-1);r(this,"_helper",null);r(this,"_color",null)}isInBox(e){var n;if(!e)return;if(this.box||(this.box=new h.Box3),oi([e],void 0,void 0,nn.testBox),nn.testBox.isEmpty()){const o=K(e,nn._position);nn.testBox.setFromCenterAndSize(o,nn._emptyObjectSize)}this.updateBox();const i=(n=this.box)==null?void 0:n.intersectsBox(nn.testBox);return i&&ZP&&N.DrawWireBox3(nn.testBox,16711680,5),i}intersects(e){return e?this.updateBox(!1).intersectsBox(e):!1}updateBox(e=!1){if(this.box||(this.box=new h.Box3),e||this.context.time.frameCount!=this._lastMatrixUpdateFrame){const i=this._lastMatrixUpdateFrame<0;this._lastMatrixUpdateFrame=this.context.time.frameCount;const n=i,o=K(this.gameObject,nn._position,n),a=Ne(this.gameObject,nn._size);this.box.setFromCenterAndSize(o,a)}return this.box}awake(){this._helper=null,this._color=null,this.box=null}showHelper(e=null,i=!1){var n;if(!(!KP&&!i)){if(this._helper){e&&((n=this._color)==null||n.set(e)),this.gameObject.add(this._helper);return}this._helper=tg(e),this.gameObject.add(this._helper)}}};let ni=nn;r(ni,"testBox",new h.Box3),r(ni,"_position",new h.Vector3),r(ni,"_size",new h.Vector3(.01,.01,.01)),r(ni,"_emptyObjectSize",new h.Vector3(.01,.01,.01));var JP=Object.defineProperty,eO=Object.getOwnPropertyDescriptor,ri=(s,t,e,i)=>{for(var n=i>1?void 0:i?eO(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&JP(t,e,n),n};class ai extends D{constructor(){super(...arguments);r(this,"attachedRigidbody",null);r(this,"isTrigger",!1);r(this,"sharedMaterial");r(this,"membership",[0]);r(this,"filter");r(this,"updateProperties",()=>{var e;(e=this.context.physics.engine)==null||e.updateProperties(this)})}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ue))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ue))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ue))}onDisable(){var e;(e=this.context.physics.engine)==null||e.removeBody(this)}get body(){var e;return(e=this.context.physics.engine)==null?void 0:e.getBody(this)}updatePhysicsMaterial(){var e;(e=this.context.physics.engine)==null||e.updatePhysicsMaterial(this)}}ri([p(ue)],ai.prototype,"attachedRigidbody",2);ri([p()],ai.prototype,"isTrigger",2);ri([p()],ai.prototype,"sharedMaterial",2);ri([p()],ai.prototype,"membership",2);ri([p()],ai.prototype,"filter",2);class Ga extends ai{constructor(){super(...arguments);r(this,"radius",.5);r(this,"center",new h.Vector3(0,0,0))}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addSphereCollider(this),wu(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),Im(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}ri([Pt(),p()],Ga.prototype,"radius",2);ri([p(h.Vector3)],Ga.prototype,"center",2);const H0=class extends ai{constructor(){super(...arguments);r(this,"size",new h.Vector3(1,1,1));r(this,"center",new h.Vector3(0,0,0))}static add(t,e){const i=xi(t,H0);return i.autoFit(),(e==null?void 0:e.rigidbody)===!0&&xi(t,ue,{isKinematic:!1}),i}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addBoxCollider(this,this.size),wu(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),Im(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}autoFit(t){const e=this.gameObject,i=e.position.clone(),n=e.quaternion.clone(),o=e.scale.clone(),a=e.parent;e.position.set(0,0,0),e.quaternion.set(0,0,0,1),e.scale.set(1,1,1),e.parent=null,e.updateMatrix();const l=oi([e]);e.position.copy(i),e.quaternion.copy(n),e.scale.copy(o),e.parent=a,(t==null?void 0:t.debug)===!0&&N.DrawWireBox3(l,16768256,20),this.size=l.getSize(new h.Vector3)||new h.Vector3(1,1,1),this.center=l.getCenter(new h.Vector3)||new h.Vector3(0,0,0),this.size.length()<=0&&this.size.set(.01,.01,.01)}};let qa=H0;ri([Pt(),p(h.Vector3)],qa.prototype,"size",2);ri([p(h.Vector3)],qa.prototype,"center",2);class So extends ai{constructor(){super(...arguments);r(this,"sharedMesh");r(this,"convex",!1)}onEnable(){var i,n,o;if(super.onEnable(),!this.context.physics.engine)return;(i=this.sharedMesh)!=null&&i.isMesh||(this.gameObject instanceof h.Mesh||this.gameObject instanceof h.Group)&&(this.sharedMesh=this.gameObject);const e=0;if((n=this.sharedMesh)!=null&&n.isMesh)this.context.physics.engine.addMeshCollider(this,this.sharedMesh,this.convex),re.NEEDLE_progressive.assignMeshLOD(this.sharedMesh,e).then(a=>{a&&this.activeAndEnabled&&this.context.physics.engine&&this.sharedMesh&&(this.context.physics.engine.removeBody(this),this.sharedMesh.geometry=a,this.context.physics.engine.addMeshCollider(this,this.sharedMesh,this.convex))});else{const a=this.sharedMesh;if(a!=null&&a.isGroup){console.warn(`MeshCollider mesh is a group "${((o=this.sharedMesh)==null?void 0:o.name)||this.gameObject.name}", adding all children as colliders. This is currently not fully supported (colliders can not be removed from world again)`,this);const l=new Array;for(const c in a.children){const d=a.children[c];d.isMesh&&(this.context.physics.engine.addMeshCollider(this,d,this.convex),l.push(re.NEEDLE_progressive.assignMeshLOD(d,e)))}Promise.all(l).then(c=>{var u,f;if(c.some(m=>m)==!1)return;(u=this.context.physics.engine)==null||u.removeBody(this);const d=new h.Mesh;for(const m of c)m&&this.activeAndEnabled&&(d.geometry=m,(f=this.context.physics.engine)==null||f.addMeshCollider(this,d,this.convex))})}else console.warn("A MeshCollider mesh is assigned, but it's neither a Mesh nor a Group. Please report a bug!",this,this.sharedMesh)}}}ri([p(h.Mesh)],So.prototype,"sharedMesh",2);ri([p()],So.prototype,"convex",2);class Ss extends ai{constructor(){super(...arguments);r(this,"center",new h.Vector3(0,0,0));r(this,"radius",.5);r(this,"height",2)}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addCapsuleCollider(this,this.height,this.radius)}}ri([p(h.Vector3)],Ss.prototype,"center",2);ri([p()],Ss.prototype,"radius",2);ri([p()],Ss.prototype,"height",2);var tO=Object.defineProperty,iO=Object.getOwnPropertyDescriptor,Os=(s,t,e,i)=>{for(var n=i>1?void 0:i?iO(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&tO(t,e,n),n};const zy=S("debugcharactercontroller");class Tr extends D{constructor(){super(...arguments);r(this,"center",new h.Vector3(0,0,0));r(this,"radius",.5);r(this,"height",2);r(this,"_rigidbody",null);r(this,"_activeGroundCollisions");r(this,"_contactVelocity",new h.Vector3)}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(ue),this._rigidbody||(this._rigidbody=this.gameObject.addComponent(ue)),this.rigidbody)}awake(){this._activeGroundCollisions=new Set}onEnable(){const e=this.rigidbody;let i=this.gameObject.getComponent(Ss);i||(i=this.gameObject.addComponent(Ss)),i.center.copy(this.center),i.radius=this.radius,i.height=this.height;const n=new h.Vector3(0,0,1),o=new h.Vector3(1,0,0),a=new h.Vector3(0,1,0),l=this.gameObject.getWorldDirection(new h.Vector3);l.y=0;const c=o.dot(l)<0?-1:1,d=n.angleTo(l)*c;this.gameObject.setRotationFromAxisAngle(a,d),e.lockRotationX=!0,e.lockRotationY=!0,e.lockRotationZ=!0}move(e){this.gameObject.position.add(e)}onCollisionEnter(e){(e.contacts.length==0||e.contacts.some(i=>i.normal.y>.2))&&(this._activeGroundCollisions.add(e),zy&&console.log(`Collision(${this._activeGroundCollisions.size}): ${e.contacts.map(i=>i.normal.y.toFixed(2)).join(", ")} - ${this.isGrounded}`))}onCollisionExit(e){this._activeGroundCollisions.delete(e),zy&&console.log(`Collision(${this._activeGroundCollisions.size}) - ${this.isGrounded}`)}get isGrounded(){return this._activeGroundCollisions.size>0}get contactVelocity(){var e;this._contactVelocity.set(0,0,0);for(const i of this._activeGroundCollisions){const n=(e=this.context.physics.engine)==null?void 0:e.getLinearVelocity(i.collider);n&&(this._contactVelocity.x+=n.x,this._contactVelocity.y+=n.y,this._contactVelocity.z+=n.z)}return this._contactVelocity}}Os([p(h.Vector3)],Tr.prototype,"center",2);Os([p()],Tr.prototype,"radius",2);Os([p()],Tr.prototype,"height",2);class Ms extends D{constructor(){super(...arguments);r(this,"controller");r(this,"movementSpeed",2);r(this,"rotationSpeed",2);r(this,"jumpForce",1);r(this,"doubleJumpForce",2);r(this,"animator");r(this,"lookForward",!0);r(this,"lookInput",new h.Vector2(0,0));r(this,"moveInput",new h.Vector2(0,0));r(this,"jumpInput",!1);r(this,"_currentSpeed",new h.Vector3(0,0,0));r(this,"_currentAngularSpeed",new h.Vector3(0,0,0));r(this,"_temp",new h.Vector3(0,0,0));r(this,"_jumpCount",0);r(this,"_currentRotation");r(this,"_raycastOptions",new zn)}awake(){this._currentRotation=new h.Quaternion}update(){const e=this.context.input;e.isKeyPressed("KeyW")?this.moveInput.y+=1:e.isKeyPressed("KeyS")&&(this.moveInput.y-=1),e.isKeyPressed("KeyD")?this.lookInput.x+=1:e.isKeyPressed("KeyA")&&(this.lookInput.x-=1),this.jumpInput||(this.jumpInput=e.isKeyDown("Space"))}move(e){this.moveInput.add(e)}look(e){this.lookInput.add(e)}jump(){this.jumpInput=!0}onBeforeRender(){this.handleInput(this.moveInput,this.lookInput,this.jumpInput),this.lookInput.set(0,0),this.moveInput.set(0,0),this.jumpInput=!1}handleInput(e,i,n){var o,a,l,c,d,u,f,m,g,_,y;if((o=this.controller)!=null&&o.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((a=this.animator)==null||a.setBool("doubleJump",!1))),this._currentSpeed.z+=e.y*this.movementSpeed*this.context.time.deltaTime,(l=this.animator)==null||l.setBool("running",e.length()>.01),(d=this.animator)==null||d.setBool("jumping",((c=this.controller)==null?void 0:c.isGrounded)===!0&&n),this._temp.copy(this._currentSpeed),this._temp.applyQuaternion(this.gameObject.quaternion),this.controller?this.controller.move(this._temp):this.gameObject.position.add(this._temp),this._currentAngularSpeed.y+=z.toRadians(-i.x*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const b=this.context.mainCameraComponent.forward;b.y=0,b.normalize(),this._currentRotation.setFromUnitVectors(new h.Vector3(0,0,1),b),this.gameObject.quaternion.slerp(this._currentRotation,this.context.time.deltaTime*10)}if(this.gameObject.rotateY(this._currentAngularSpeed.y),this._currentSpeed.multiplyScalar(1-this.context.time.deltaTime*10),this._currentAngularSpeed.y*=1-this.context.time.deltaTime*10,this.controller&&n&&this.jumpForce>0){let b=(u=this.controller)==null?void 0:u.isGrounded;if(this.doubleJumpForce>0&&!((f=this.controller)!=null&&f.isGrounded)&&this._jumpCount===1&&(b=!0,(m=this.animator)==null||m.setBool("doubleJump",!0)),b){this._jumpCount+=1;const v=this.controller.rigidbody,x=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;v.applyImpulse(new h.Vector3(0,1,0).multiplyScalar(x))}}if(this.controller){const b=(g=this.controller)==null?void 0:g.rigidbody.getVelocity().y;if(b<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new h.Ray),this._raycastOptions.ray.origin.copy(K(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const v=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const x=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(v),(x.length&&x[0].distance>2||b<-10)&&((_=this.animator)==null||_.setBool("falling",!0))}else(y=this.animator)==null||y.setBool("falling",!1)}}}Os([p(Tr)],Ms.prototype,"controller",2);Os([p()],Ms.prototype,"movementSpeed",2);Os([p()],Ms.prototype,"rotationSpeed",2);Os([p()],Ms.prototype,"jumpForce",2);Os([p()],Ms.prototype,"doubleJumpForce",2);Os([p(St)],Ms.prototype,"animator",2);var nO=Object.defineProperty,sO=Object.getOwnPropertyDescriptor,Xa=(s,t,e,i)=>{for(var n=i>1?void 0:i?sO(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&nO(t,e,n),n};const xl=S("debugcontactshadows");k0(s=>{const t=s.domElement.getAttribute("contactshadows");t!=null&&t!="0"&&t!="false"&&gn.auto(s)});var Rp;const Vl=(Rp=class extends D{constructor(){super(...arguments);r(this,"autoFit",!1);r(this,"darkness",.5);r(this,"opacity",.5);r(this,"blur",4);r(this,"occludeBelowGround",!1);r(this,"backfaceShadows",!0);r(this,"minSize");r(this,"shadowsRoot",new h.Object3D);r(this,"shadowCamera");r(this,"shadowGroup",new h.Group);r(this,"renderTarget");r(this,"renderTargetBlur");r(this,"plane");r(this,"occluderMesh");r(this,"blurPlane");r(this,"depthMaterial");r(this,"horizontalBlurMaterial");r(this,"verticalBlurMaterial");r(this,"textureSize",512)}static auto(t){if(t||(t=Q.Current),!t)throw new Error("No context provided and no current context set.");let e=this._instances.get(t);if(!e||e.destroyed){const i=new h.Object3D;e=xi(i,Vl,{autoFit:!1,occludeBelowGround:!1}),this._instances.set(t,e)}return t.scene.add(e.gameObject),e.fitShadows(),e}fitShadows(){xl&&console.warn("Fitting shadows to scene"),Bd(this.shadowsRoot,!1);const t=oi(this.context.scene.children,[this.shadowsRoot]),e=Math.max(1,this.blur/32),i=t.max.x-t.min.x,n=t.max.z-t.min.z;t.expandByVector(new h.Vector3(e*i,0,e*n)),xl&&N.DrawWireBox3(t,16776960,60),this.gameObject.parent&&t.applyMatrix4(this.gameObject.parent.matrixWorld.clone().invert());const o=t.min,a=Math.max(1e-5,(t.max.y-o.y)*.002);t.max.y+=a,this.shadowsRoot.position.set((o.x+t.max.x)/2,o.y-a,(o.z+t.max.z)/2),this.shadowsRoot.scale.set(t.max.x-o.x,t.max.y-o.y,t.max.z-o.z),this.applyMinSize(),this.shadowsRoot.matrixWorldNeedsUpdate=!0,xl&&console.log("Fitted shadows to scene",this.shadowsRoot.scale.clone())}awake(){Vl._instances.set(this.context,this),this.shadowsRoot.hideFlags=zu.DontExport,Bd(this.shadowsRoot,!1)}start(){xl&&console.log("Create ContactShadows on "+this.gameObject.name,this),this.gameObject.add(this.shadowsRoot),this.shadowsRoot.add(this.shadowGroup),this.renderTarget=new h.WebGLRenderTarget(this.textureSize,this.textureSize),this.renderTarget.texture.generateMipmaps=!1,this.renderTargetBlur=new h.WebGLRenderTarget(this.textureSize,this.textureSize),this.renderTargetBlur.texture.generateMipmaps=!1;const t=new h.PlaneGeometry(1,1).rotateX(Math.PI/2);this.gameObject instanceof h.Mesh&&(console.warn("ContactShadows can not be added to a Mesh. Please add it to a Group or an empty Object"),ps(this.gameObject,!1));const e=new h.MeshBasicMaterial({map:this.renderTarget.texture,opacity:this.opacity,color:0,transparent:!0,depthWrite:!1,side:h.FrontSide});this.plane=new h.Mesh(t,e),this.plane.scale.y=-1,this.plane.layers.set(2),this.shadowsRoot.add(this.plane),this.plane&&(this.plane.renderOrder=1),this.occluderMesh=new h.Mesh(this.plane.geometry,new h.MeshBasicMaterial({depthWrite:!0,stencilWrite:!0,colorWrite:!1,side:h.BackSide})).translateY(-1e-4),this.occluderMesh.renderOrder=-100,this.occluderMesh.layers.set(2),this.shadowsRoot.add(this.occluderMesh),this.blurPlane=new h.Mesh(t),this.blurPlane.visible=!1,this.shadowGroup.add(this.blurPlane);const i=0,n=1;this.shadowCamera=new h.OrthographicCamera(-1/2,1/2,1/2,-1/2,i,n),this.shadowCamera.layers.enableAll(),this.shadowCamera.rotation.x=Math.PI/2,this.shadowGroup.add(this.shadowCamera),this.depthMaterial=new h.MeshDepthMaterial,this.depthMaterial.userData.darkness={value:this.darkness},this.depthMaterial.blending=h.CustomBlending,this.depthMaterial.blendEquation=h.MaxEquation,this.depthMaterial.onBeforeCompile=o=>{this.depthMaterial&&(o.uniforms.darkness=this.depthMaterial.userData.darkness,o.fragmentShader=`
925
+ Incoming:`,this._incomingCalls),l}else He&&console.error("Failed to make call",e,i,this._peer)}closeAll(){for(const e of this._incomingCalls)e.close();for(const e of this._outgoingCalls)e.close();this.updateCalls()}get peer(){return this._peer}get incomingCalls(){return this._incomingCalls}enable(){this._enabled||(this._enabled=!0,this.context.connection.beginListen(Z.JoinedRoom,this.onConnectRoomFn),this.subscribePeerEvents())}disable(){this._enabled&&(this._enabled=!1,this.context.connection.stopListen(Z.JoinedRoom,this.onConnectRoomFn),this.unsubscribePeerEvents())}onConnectRoom(){this.setupPeer()}setupPeer(){if(this.context.connection.connectionId&&!this._enabledPeer){if(this._enabledPeer=!0,!this._peer){const e=this.getMyPeerId();e?this._peer=_v(e):console.error("Failed to setup peerjs because we dont have a connection id",this.context.connection.connectionId)}this._enabled&&this.subscribePeerEvents()}}subscribePeerEvents(){this._peer&&(this._peer.on("open",this.onPeerConnect),this._peer.on("close",this.onPeerClose),this._peer.on("call",this.onPeerReceivingCall),this._peer.on("disconnected",this.onPeerDisconnected),this._peer.on("error",this.onPeerError))}unsubscribePeerEvents(){this._peer&&(this._peer.off("open",this.onPeerConnect),this._peer.off("close",this.onPeerClose),this._peer.off("call",this.onPeerReceivingCall),this._peer.off("disconnected",this.onPeerDisconnected),this._peer.off("error",this.onPeerError))}registerCall(e,i,n){const o=e.metadata;(!o||!o.userId)&&console.error("Missing call metadata",e);const a=o.userId;i==="incoming"&&He?console.warn("← Receive call from",e.metadata,e.connectionId):He&&console.warn("→ Make call to",e.metadata);const l=i==="incoming"?this._incomingCalls:this._outgoingCalls,c=new LP(a,e,i,n);return l.push(c),e.on("error",d=>{console.error("Call error",d)}),e.on("close",()=>{He&&console.log("Call ended",e.metadata);const d=l.indexOf(c);d!==-1&&l.splice(d,1),c.close(),this.dispatchEvent(new bg(a,i))}),c.addEventListener("call-ended",d=>{this.dispatchEvent(d)}),i==="incoming"&&(c.addEventListener("receive-stream",d=>{this.dispatchEvent(d)}),e.on("stream",()=>{He&&console.log("Received stream for call",e.metadata);let d=0;const u=setInterval(()=>{const f=d===0;!c.isOpen&&f&&(He&&console.warn("Close call because stream is not active",e.metadata),d+=1,clearInterval(u),c.close())},2e3)})),c}};let cr=ba;r(cr,"instances",new Map);class nh extends h.EventDispatcher{constructor(e,i){super();r(this,"context");r(this,"peer");r(this,"_sendingStreams",new Map);r(this,"debug",!1);r(this,"_enabled",!1);r(this,"_tickIntervalId");r(this,"tick",()=>{this.updateSendingCalls()});r(this,"onJoinedRoom",e=>{this._sendingStreams.size>0&&(this.debug&&console.warn(`${e!=null&&e.userId?`User ${e.userId}`:"You"} joined room`,e,this._sendingStreams.size),this.updateSendingCalls())});r(this,"onLeftRoom",e=>{this.debug&&console.warn(`${(e==null?void 0:e.userId)||"You"} left room`,e),this.stopCallsToUsersThatAreNotInTheRoomAnymore(),this.peer.closeAll()});r(this,"onCallStreamReceived",e=>{this.debug&&console.log("Call with "+e.userId+" started"),this.dispatchEvent({type:"receive-stream",target:this,stream:e.stream,userId:e.userId}),this.debug&&this.debugLogCurrentState()});r(this,"onCallEnded",e=>{this.debug&&console.log("Call with "+e.userId+" ended"),this.dispatchEvent(e),this.debug&&this.debugLogCurrentState()});r(this,"onUserConnected",e=>{if(this.peer.id===e.guid){this.debug&&console.log("PEER USER CONNECTED",e.guid,e,this._sendingStreams.size);const i=this._sendingStreams.keys().next().value;this.peer.makeCall(e.peerId,i)}else He&&console.log("Unknown user connected",e.guid,e.peerId)});r(this,"onUserLeft",e=>{this.debug&&console.log("User left room: "+e.userId),this.stopCallsToUsersThatAreNotInTheRoomAnymore()});if(j0(e)){const n=e;e=n.context,i=cr.getOrCreate(n.context,n.guid)}else typeof i=="string"&&(i=cr.getOrCreate(e,i));if(e){if(!(e instanceof Q))throw new Error("Failed to create NetworkedStreams because context is not an instance of Context")}else throw new Error("Failed to create NetworkedStreams because context is undefined");if(!i)throw new Error("Failed to create NetworkedStreams because peer is undefined");this.context=e,this.peer=i,He&&(this.debug=!0)}static create(e,i){const n=cr.getOrCreate(e.context,i||e.context.connection.connectionId||e.guid);return new nh(e.context,n)}startSendingStream(e){this._sendingStreams.has(e)?console.warn("Received start sending stream with stream that is already being sent"):(this._sendingStreams.set(e,[]),this.updateSendingCalls())}stopSendingStream(e){if(e){const i=this._sendingStreams.get(e);if(i){for(const n of i)n.close();i.length=0}this._sendingStreams.delete(e),i&&this.debug&&this.debugLogCurrentState()}this.updateSendingCalls()}get enabled(){return this._enabled}enable(){this._enabled||(this._enabled=!0,this.peer.enable(),this.peer.addEventListener("receive-stream",this.onCallStreamReceived),this.peer.addEventListener("call-ended",this.onCallEnded),this.context.connection.beginListen("peer-user-connected",this.onUserConnected),this.context.connection.beginListen(Z.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(Z.UserJoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(Z.UserLeftRoom,this.onUserLeft),this.context.connection.beginListen(Z.LeftRoom,this.onLeftRoom),this._tickIntervalId=setInterval(this.tick,5e3))}disable(){this._enabled&&(this._enabled=!1,this.peer.disable(),this.peer.removeEventListener("receive-stream",this.onCallStreamReceived),this.peer.removeEventListener("call-ended",this.onCallEnded),this.context.connection.stopListen("peer-user-connected",this.onUserConnected),this.context.connection.stopListen(Z.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(Z.UserJoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(Z.UserLeftRoom,this.onUserLeft),this.context.connection.stopListen(Z.LeftRoom,this.onLeftRoom),this._tickIntervalId!=null&&(clearInterval(this._tickIntervalId),this._tickIntervalId=void 0))}updateSendingCalls(){const e=this.context.connection.connectionId;for(const i of this._sendingStreams.keys()){const n=this._sendingStreams.get(i)||[];for(const o of this.context.connection.usersInRoom()){if(o===e)continue;const a=this.peer.getPeerIdFromUserId(o);if(n.find(c=>{var d;return c.peerId===a&&c.direction==="outgoing"&&!c.isClosed&&((d=c.stream)==null?void 0:d.active)}))He&&console.debug("Already have a call with user "+o+" / peer "+a);else{const c=this.peer.makeCall(a,i);c&&n.push(c)}}this._sendingStreams.set(i,n)}this.stopCallsToUsersThatAreNotInTheRoomAnymore()}stopCallsToUsersThatAreNotInTheRoomAnymore(){for(const e of this._sendingStreams.keys()){const i=this._sendingStreams.get(e);if(i)for(let n=i.length-1;n>=0;n--){const o=i[n];this.context.connection.userIsInRoom(o.userId)?He&&(this.context.connection.connectionId===o.userId?console.warn(`You are still in the room [${n}] ${o.userId}`):console.log(`User is still in room [${n}] ${o.userId}`)):(He&&console.log(`Remove call ${[n]} to user that is not in room anymore ${o.userId}`),o.close(),i.splice(n,1))}}this.peer.updateCalls(),this.debug&&this.debugLogCurrentState()}debugLogCurrentState(){console.warn(`You (${this.context.connection.connectionId}) are currently sending ${this._sendingStreams.size} and receiving ${this.peer.incomingCalls.length} calls (${this.peer.incomingCalls.map(e=>e.userId).join(", ")})`,this.peer.incomingCalls)}}function Ln(s){if(s&&s instanceof MediaStream)for(const t of s.getTracks())t.stop()}var IP=Object.defineProperty,jP=Object.getOwnPropertyDescriptor,vg=(s,t,e,i)=>{for(var n=i>1?void 0:i?jP(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&IP(t,e,n),n};const BP="noVoip",FP=S("debugvoip");class xo extends D{constructor(){super(...arguments);r(this,"autoConnect",!0);r(this,"runInBackground",!0);r(this,"createMenuButton",!0);r(this,"debug",!1);r(this,"_net");r(this,"_menubutton");r(this,"_allowSending",!0);r(this,"_outputStream",null);r(this,"onJoinedRoom",async()=>{this.debug&&console.log("VOIP: Joined room"),await un(300),this.autoConnect&&!this.isSending&&this._allowSending&&this.connect()});r(this,"onLeftRoom",()=>{this.debug&&console.log("VOIP: Left room"),this.disconnect();for(const e of this._incomingStreams.values())Ln(e.srcObject);this._incomingStreams.clear()});r(this,"_incomingStreams",new Map);r(this,"onReceiveStream",e=>{const i=e.target.userId,n=e.stream;let o=this._incomingStreams.get(i);o||(o=new Audio,this._incomingStreams.set(i,o)),o.srcObject=n,o.setAttribute("autoplay","true"),cn.registerWaitForInteraction(()=>{o==null||o.play().catch(a=>{console.error("VOIP: Failed to play audio",a)})})});r(this,"onStreamEnded",e=>{const i=this._incomingStreams.get(e.userId);Ln(i==null?void 0:i.srcObject),this._incomingStreams.delete(e.userId)});r(this,"onEnabledChanged",()=>{for(const e of this._incomingStreams){const i=e[1];i.muted=!this.enabled}});r(this,"onVisibilityChanged",()=>{if(this.runInBackground)return;const i=!(document.visibilityState==="visible");this.setMuted(i);for(const n of this._incomingStreams){const o=n[1];o.muted=i}})}awake(){FP&&(this.debug=!0),this.debug&&(console.log("VOIP debugging: press 'v' to toggle mute or 'c' to toggle connect/disconnect"),window.addEventListener("keydown",async e=>{switch(e.key.toLowerCase()){case"v":console.log("MUTE?",!this.isMuted),this.setMuted(!this.isMuted);break;case"c":this.isSending?this.disconnect():this.connect();break}}),window.addEventListener("blur",()=>{console.log("VOIP: MUTE ON BLUR"),this.setMuted(!0)}),window.addEventListener("focus",()=>{console.log("VOIP: UNMUTE ON FOCUS"),this.setMuted(!1)}))}onEnable(){this._net||(this._net=nh.create(this)),this.debug&&(this._net.debug=!0),this._net.addEventListener(Dn.StreamReceived,this.onReceiveStream),this._net.addEventListener(Dn.StreamEnded,this.onStreamEnded),this._net.enable(),this.autoConnect&&this.context.connection.isConnected&&this.connect(),this.context.connection.beginListen(Z.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(Z.LeftRoom,this.onLeftRoom),this.onEnabledChanged(),this.updateButton(),window.addEventListener("visibilitychange",this.onVisibilityChanged)}onDisable(){var e;this._net&&(this._net.stopSendingStream(this._outputStream),this._net.removeEventListener(Dn.StreamReceived,this.onReceiveStream),this._net.removeEventListener(Dn.StreamEnded,this.onStreamEnded),(e=this._net)==null||e.disable()),this.context.connection.stopListen(Z.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(Z.LeftRoom,this.onLeftRoom),this.onEnabledChanged(),this.updateButton(),window.removeEventListener("visibilitychange",this.onVisibilityChanged)}onDestroy(){var e;(e=this._menubutton)==null||e.remove(),this._menubutton=void 0}get isSending(){return this._outputStream!=null&&this._outputStream.active}async connect(e){var i,n;if(!this._net)return console.error("Cannot connect to voice chat - NetworkedStreams not initialized. Make sure the component is enabled before calling this method."),!1;if(this.context.connection.isConnected){if(!await exports.DeviceUtilities.microphonePermissionsGranted())return console.error("Cannot connect to voice chat - microphone permissions not granted"),this.updateButton(),!1}else return console.error("Cannot connect to voice chat - not connected to server"),this.updateButton(),!1;return this._allowSending=!0,(i=this._net)==null||i.stopSendingStream(this._outputStream),Ln(this._outputStream),this._outputStream=await this.getAudioStream(e),this._outputStream?(this.debug&&console.log("VOIP: Got audio stream"),(n=this._net)==null||n.startSendingStream(this._outputStream),this.updateButton(),!0):(this.updateButton(),await exports.DeviceUtilities.microphonePermissionsGranted()?console.error("VOIP: Could not get audio stream - please make sure to connect an audio device and grant microphone permissions"):Gc("Microphone permissions not granted: Please grant microphone permissions to use voice chat"),(this.debug||B())&&console.log("VOIP: Failed to get audio stream"),!1)}disconnect(e){var i;e!=null&&e.remember&&(this._allowSending=!1),(i=this._net)==null||i.stopSendingStream(this._outputStream),Ln(this._outputStream),this._outputStream=null,this.updateButton()}setMuted(e){var n;const i=(n=this._outputStream)==null?void 0:n.getAudioTracks();if(i)for(const o of i)o.enabled=!e}get isMuted(){var i;if(this._outputStream===null)return!1;const e=(i=this._outputStream)==null?void 0:i.getAudioTracks();if(e){for(const n of e)if(!n.enabled)return!0}return!1}async updateButton(){var e;if(this.createMenuButton){if(this._menubutton||(this._menubutton=document.createElement("button"),this._menubutton.addEventListener("click",()=>{this.isSending?this.disconnect({remember:!0}):this.connect(),exports.DeviceUtilities.microphonePermissionsGranted().then(i=>{i||me("<strong>Microphone permissions not granted</strong>. Please allow your browser to use the microphone to be able to talk. Click on the button on the left side of your browser's address bar to allow microphone permissions.")})})),this._menubutton){this.context.menu.appendChild(this._menubutton),this.activeAndEnabled?this._menubutton.style.display="":this._menubutton.style.display="none",this._menubutton.title=this.isSending?"Click to disable your microphone":"Click to enable your microphone";let i=(this.isSending,""),n=this.isSending?"mic":"mic_off";await exports.DeviceUtilities.microphonePermissionsGranted()||(i="No Permission",n="mic_off",this._menubutton.title="Microphone permissions not granted. Please allow your browser to use the microphone to be able to talk. This can usually be done in the addressbar of the webpage."),this._menubutton.innerText=i,this._menubutton.prepend(bt(n)),this.context.connection.isConnected==!1?this._menubutton.setAttribute("disabled",""):this._menubutton.removeAttribute("disabled")}}else this.activeAndEnabled||(e=this._menubutton)==null||e.remove()}getFrequency(e){return this.unsupported_getfrequency||(this.unsupported_getfrequency=!0,B()&&me("VOIP: getFrequency is currently not supported"),console.warn("VOIP: getFrequency is currently not supported")),null}async getAudioStream(e){if(!navigator.mediaDevices.getUserMedia)return console.error("No getDisplayMedia support"),null;const i=async o=>await navigator.mediaDevices.getUserMedia({audio:o??!0,video:!1}).catch(a=>(console.warn("VOIP failed getting audio stream",a),null)),n=await i(e);if(!n)return null;if(exports.DeviceUtilities.isiOS()&&(e==null?void 0:e.deviceId)===void 0){const a=(await navigator.mediaDevices.enumerateDevices()).find(l=>(l.kind==="audioinput"||l.kind==="audiooutput")&&!l.label.includes("iPhone"));if(a){const l=Object.assign({},e);return l.deviceId=a.deviceId,await i(l)}}return n}}vg([p()],xo.prototype,"autoConnect",2);vg([p()],xo.prototype,"runInBackground",2);vg([p()],xo.prototype,"createMenuButton",2);var UP=Object.defineProperty,zP=Object.getOwnPropertyDescriptor,V0=(s,t,e,i)=>{for(var n=i>1?void 0:i?zP(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&UP(t,e,n),n};const NP=S("debugmouth");class sh extends D{constructor(){super(...arguments);r(this,"idle",[]);r(this,"talking",[]);r(this,"marker",null);r(this,"voip",null);r(this,"lastMouthChangeTime",0);r(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=C.findObjectOfType(xo,this.context),this.marker||(this.marker=C.getComponentInParent(this.gameObject,it))},3e3)}update(){var n;if(!this.voip||this.context.time.frameCount%10!==0)return;let e=((n=this.marker)==null?void 0:n.connectionId)??null;if(!e){NP&&(e=null);return}const i=this.voip.getFrequency(e)??0;this.updateLips(i)}updateLips(e){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&e>30){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.talking.length);this.setMouthShapeActive(this.talking,i)}else if(this.idle.length>0&&this.context.time.time-this.lastMouthChangeTime>.5){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.idle.length);this.setMouthShapeActive(this.idle,i)}}}setMouthShapeActive(e,i){if(e){e!=this.idle?this.idle.map(n=>n.visible=!1):this.talking.map(n=>n.visible=!1);for(let n=0;n<e.length;n++){const o=e[n];o&&(o.visible=n===i)}}}}V0([p(h.Object3D)],sh.prototype,"idle",2);V0([p(h.Object3D)],sh.prototype,"talking",2);class wg extends D{constructor(){super(...arguments);r(this,"voip",null);r(this,"marker",null);r(this,"_startPosition",null)}awake(){this.voip=C.findObjectOfType(xo,this.context),this.marker=C.getComponentInParent(this.gameObject,it)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const e=this.marker.connectionId,i=this.voip.getFrequency(e);if(i==null)return;this._startPosition||(this._startPosition=this.gameObject.position.clone());const n=i/100;this.gameObject.position.y=this._startPosition.y+n*.07}}var VP=Object.defineProperty,$P=Object.getOwnPropertyDescriptor,WP=(s,t,e,i)=>{for(var n=i>1?void 0:i?$P(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&VP(t,e,n),n};const ca=S("debugxrflags"),$0=S("disablexrflags");$0&&console.warn("XRFlags are disabled");var Tn=(s=>(s[s.Never=0]="Never",s[s.Browser=1]="Browser",s[s.AR=2]="AR",s[s.VR=4]="VR",s[s.FirstPerson=8]="FirstPerson",s[s.ThirdPerson=16]="ThirdPerson",s[s.All=4294967295]="All",s))(Tn||{});const C_=class{constructor(){r(this,"Mask",17)}Has(t){return(this.Mask&t)!==0}Set(t){ca&&console.warn("Set XR flag state to",t),this.Mask=t,yi.Apply()}Enable(t){this.Mask|=t,yi.Apply()}Disable(t){this.Mask&=~t,yi.Apply()}Toggle(t){this.Mask^=t,yi.Apply()}EnableAll(){this.Mask=-1,yi.Apply()}DisableAll(){this.Mask=0,yi.Apply()}};let vt=C_;r(vt,"Global",new C_);var Tl;const ss=(Tl=class extends D{constructor(){super(...arguments);r(this,"visibleIn")}static Apply(){for(const t of this.registry)t.UpdateVisible(vt.Global)}awake(){ss.registry.push(this)}onEnable(){ss.firstApply?this.UpdateVisible(vt.Global):(ss.firstApply=!0,ss.Apply())}onDestroy(){const t=ss.registry.indexOf(this);t>=0&&ss.registry.splice(t,1)}get isOn(){return this.gameObject.visible}UpdateVisible(t=null){if($0)return;let e;const i=t;if(i&&typeof i=="number"&&(console.assert(typeof i=="number","XRFlag.UpdateVisible: state must be a number",i),ca&&console.log(i),ss.buffer.Mask=i,t=ss.buffer),t instanceof vt?(ca&&console.warn(this.name,"use passed in mask",t.Mask,this.visibleIn),e=t.Has(this.visibleIn)):(ca&&console.log(this.name,"use global mask"),vt.Global.Has(this.visibleIn)),e!==void 0)if(e)ca&&console.log(this.name,"is visible",this.gameObject.uuid),C.setActive(this.gameObject,!0);else{if(ca&&console.log(this.name,"is not visible",this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}},r(Tl,"registry",[]),r(Tl,"firstApply"),r(Tl,"buffer",new vt),Tl);let yi=ss;WP([p()],yi.prototype,"visibleIn",2);var HP=Object.defineProperty,GP=Object.getOwnPropertyDescriptor,Nu=(s,t,e,i)=>{for(var n=i>1?void 0:i?GP(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&HP(t,e,n),n};class kr extends D{constructor(){super(...arguments);r(this,"eyes",[]);r(this,"lastBlinkTime",0);r(this,"blinkLength",0);r(this,"eyesOpen",!0);r(this,"state",null)}awake(){this.state=C.getComponentInParent(this.gameObject,yi)}update(){if(!this.gameObject||!this.gameObject.visible||!this.eyes||!Array.isArray(this.eyes)||this.eyes.length===0)return;if(this.context.time.time-this.lastBlinkTime>this.blinkLength){if(this.lastBlinkTime=this.context.time.time,this.state&&!this.state.isOn||!this.activeAndEnabled)return;if(this.eyesOpen=!this.eyesOpen,this.blinkLength=Math.random(),this.eyesOpen?(this.blinkLength*=3,this.blinkLength+=.5,Math.random()<.1&&(this.blinkLength=.1+Math.random()*.2)):(this.blinkLength*=Math.random()*.2,this.blinkLength+=.1),Math.random()<.1&&(this.blinkLength*=3),this.blinkLength=Math.max(.2,this.blinkLength),this.blinkLength=Math.min(3,this.blinkLength),this.eyes)for(const i of this.eyes)i&&(i.visible=this.eyesOpen)}}}Nu([p(h.Object3D)],kr.prototype,"eyes",2);Nu([p()],kr.prototype,"lastBlinkTime",2);Nu([p()],kr.prototype,"blinkLength",2);Nu([p()],kr.prototype,"eyesOpen",2);var qP=Object.defineProperty,XP=Object.getOwnPropertyDescriptor,xg=(s,t,e,i)=>{for(var n=i>1?void 0:i?XP(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&qP(t,e,n),n},Mp;const W0=(Mp=class extends D{constructor(){super(...arguments);r(this,"head",null);r(this,"eyes",null);r(this,"target",null);r(this,"brain",null);r(this,"vec",new h.Vector3);r(this,"currentTargetPoint",new h.Vector3)}awake(){this.brain||(this.brain=C.getComponentInParent(this.gameObject,Rc)),this.brain||(this.brain=C.addComponent(this.gameObject,Rc)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const t=this.target;if(t&&this.head){const e=this.eyes;if(e){const i=K(t);this.currentTargetPoint.lerp(i,this.context.time.deltaTime/.1);const n=K(this.head),o=this.vec.copy(this.currentTargetPoint).sub(n).normalize();if(o.length()<.1)return;const a=W0.forward;if(a.set(0,0,1),a.applyQuaternion(ye(this.head)),a.dot(o)>.45)for(let c=0;c<e.length;c++)e[c].lookAt(this.currentTargetPoint)}}}},r(Mp,"forward",new h.Vector3(0,0,1)),Mp);let Wa=W0;xg([p(h.Object3D)],Wa.prototype,"head",2);xg([p(h.Object3D)],Wa.prototype,"eyes",2);xg([p(h.Object3D)],Wa.prototype,"target",2);const wl=S("debugavatar");class Vu{constructor(t,e,i,n){r(this,"root");r(this,"head");r(this,"leftHand");r(this,"rigthHand");var o;this.root=t,this.head=e,this.leftHand=i,this.rigthHand=n,(o=this.root)==null||o.traverse(a=>a.layers.set(2))}get isValid(){return this.head!==null&&this.head!==void 0}}class Sg{constructor(){r(this,"avatarRegistryUrl",null)}async getOrCreateNewAvatarInstance(t,e){if(!e)return console.error("Can not create avatar: failed to provide id or root object"),null;let i=null;if(typeof e=="string"){if(i=await this.loadAvatar(t,e),!i){const o=new pn;i=C.instantiate(Aa(e,t.scene),o)}}else i=e;if(!i)return null;const n=this.findAvatar(i);return n.isValid?(wl&&console.log("[Custom Avatar] valid config",e,wl?n:""),n):(console.warn("[Custom Avatar] config isn't valid",e,wl?n:""),null)}async loadAvatar(t,e){if(console.assert(e!=null&&typeof e=="string","Avatar id must not be null"),e.length<=0||!e)return null;if(wl&&console.log("[Custom Avatar] "+e+", loading..."),e.endsWith(".glb")||(e+=".glb"),this.avatarRegistryUrl===null){const n=await fetch("./"+e);let o=null;if(n.ok){const l=await n.blob();l&&(o=await l.arrayBuffer())}if(!o)return null;const a=await dn().parseSync(t,o,null,0);return(a==null?void 0:a.scene)??null}const i=new Y.GLTFLoader;return Lu(i,t),new Promise((n,o)=>{const a=this.avatarRegistryUrl+"/"+e;i.load(a,async l=>{await dn().createBuiltinComponents(t,a,l,null,void 0),n(l.scene)},l=>{wl&&console.log("[Custom Avatar] "+l.loaded/l.total*100+"% loaded of "+l.total/1024+"kB")},l=>{console.error("[Custom Avatar] Error when loading: "+l),n(null)})})}cacheModel(t,e){}findAvatar(t){const e=t;let i=e;i.children.length==1&&(i=t.children[0]);let n=this.findAvatarPart(i,["head"]);const o=this.findAvatarPart(i,["left","hand"]),a=this.findAvatarPart(i,["right","hand"]);if(!n){n=e;const c=new h.Vector3;new h.Box3().setFromObject(n).getSize(c);const d=Math.max(c.x,c.y,c.z);console.warn("[Custom Avatar] Normalizing head scale, it's too big: "+d+" meters! Should be < 0.3m"),d>.3&&n.scale.multiplyScalar(1/d*.3)}return new Vu(e,n,o,a)}findAvatarPart(t,e){const i=t.name.toLowerCase();let n=!0;for(const o of e){if(!n)break;i.indexOf(o)===-1&&(n=!1)}if(n)return t;if(t.children)for(const o of t.children){const a=this.findAvatarPart(o,e);if(a)return a}return null}handleCustomAvatarErrors(t){if(!t.ok)throw Error(t.statusText);return t}}var QP=Object.defineProperty,YP=Object.getOwnPropertyDescriptor,Cg=(s,t,e,i)=>{for(var n=i>1?void 0:i?YP(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&QP(t,e,n),n};class Ha extends D{constructor(){super(...arguments);r(this,"length",1);r(this,"depthTest",!0);r(this,"isGizmo",!1);r(this,"_axes",null)}onEnable(){if(this.isGizmo&&!Qc)return;this._axes||(this._axes=new h.AxesHelper(this.length)),this._axes.layers.disableAll(),this._axes.layers.set(this.layer),this.gameObject.add(this._axes);const e=this._axes.material;e&&e.depthTest!==void 0&&(e.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}Cg([p()],Ha.prototype,"length",2);Cg([p()],Ha.prototype,"depthTest",2);Cg([p()],Ha.prototype,"isGizmo",2);class Pg extends D{constructor(){super(...arguments);r(this,"from");r(this,"to");r(this,"hint");r(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;const e=K(this.to).clone(),i=K(this.from).clone(),n=e.distanceTo(i),o=e.clone();o.sub(i);const a=i.clone();a.add(e),a.multiplyScalar(.5);const l=K(this.hint).clone();l.sub(a);const c=new h.Vector3;c.crossVectors(l,o),c.crossVectors(o,c),c.normalize();const d=n*.5,u=Math.max(this.desiredDistance,d),f=Math.sqrt(u*u-d*d),m=c.clone();m.multiplyScalar(f),m.add(a),nt(this.gameObject,m);const g=a.clone();g.sub(c),this.gameObject.lookAt(g)}}const KP=S("gizmos"),ZP=S("debugboxhelper"),nn=class extends D{constructor(){super(...arguments);r(this,"box",null);r(this,"_lastMatrixUpdateFrame",-1);r(this,"_helper",null);r(this,"_color",null)}isInBox(e){var n;if(!e)return;if(this.box||(this.box=new h.Box3),oi([e],void 0,void 0,nn.testBox),nn.testBox.isEmpty()){const o=K(e,nn._position);nn.testBox.setFromCenterAndSize(o,nn._emptyObjectSize)}this.updateBox();const i=(n=this.box)==null?void 0:n.intersectsBox(nn.testBox);return i&&ZP&&N.DrawWireBox3(nn.testBox,16711680,5),i}intersects(e){return e?this.updateBox(!1).intersectsBox(e):!1}updateBox(e=!1){if(this.box||(this.box=new h.Box3),e||this.context.time.frameCount!=this._lastMatrixUpdateFrame){const i=this._lastMatrixUpdateFrame<0;this._lastMatrixUpdateFrame=this.context.time.frameCount;const n=i,o=K(this.gameObject,nn._position,n),a=Ne(this.gameObject,nn._size);this.box.setFromCenterAndSize(o,a)}return this.box}awake(){this._helper=null,this._color=null,this.box=null}showHelper(e=null,i=!1){var n;if(!(!KP&&!i)){if(this._helper){e&&((n=this._color)==null||n.set(e)),this.gameObject.add(this._helper);return}this._helper=tg(e),this.gameObject.add(this._helper)}}};let ni=nn;r(ni,"testBox",new h.Box3),r(ni,"_position",new h.Vector3),r(ni,"_size",new h.Vector3(.01,.01,.01)),r(ni,"_emptyObjectSize",new h.Vector3(.01,.01,.01));var JP=Object.defineProperty,eO=Object.getOwnPropertyDescriptor,ri=(s,t,e,i)=>{for(var n=i>1?void 0:i?eO(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&JP(t,e,n),n};class ai extends D{constructor(){super(...arguments);r(this,"attachedRigidbody",null);r(this,"isTrigger",!1);r(this,"sharedMaterial");r(this,"membership",[0]);r(this,"filter");r(this,"updateProperties",()=>{var e;(e=this.context.physics.engine)==null||e.updateProperties(this)})}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ue))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ue))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ue))}onDisable(){var e;(e=this.context.physics.engine)==null||e.removeBody(this)}get body(){var e;return(e=this.context.physics.engine)==null?void 0:e.getBody(this)}updatePhysicsMaterial(){var e;(e=this.context.physics.engine)==null||e.updatePhysicsMaterial(this)}}ri([p(ue)],ai.prototype,"attachedRigidbody",2);ri([p()],ai.prototype,"isTrigger",2);ri([p()],ai.prototype,"sharedMaterial",2);ri([p()],ai.prototype,"membership",2);ri([p()],ai.prototype,"filter",2);class Ga extends ai{constructor(){super(...arguments);r(this,"radius",.5);r(this,"center",new h.Vector3(0,0,0))}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addSphereCollider(this),wu(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),Im(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}ri([Pt(),p()],Ga.prototype,"radius",2);ri([p(h.Vector3)],Ga.prototype,"center",2);const H0=class extends ai{constructor(){super(...arguments);r(this,"size",new h.Vector3(1,1,1));r(this,"center",new h.Vector3(0,0,0))}static add(t,e){const i=xi(t,H0);return i.autoFit(),(e==null?void 0:e.rigidbody)===!0&&xi(t,ue,{isKinematic:!1}),i}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addBoxCollider(this,this.size),wu(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),Im(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}autoFit(t){const e=this.gameObject,i=e.position.clone(),n=e.quaternion.clone(),o=e.scale.clone(),a=e.parent;e.position.set(0,0,0),e.quaternion.set(0,0,0,1),e.scale.set(1,1,1),e.parent=null,e.updateMatrix();const l=oi([e]);e.position.copy(i),e.quaternion.copy(n),e.scale.copy(o),e.parent=a,(t==null?void 0:t.debug)===!0&&N.DrawWireBox3(l,16768256,20),this.size=l.getSize(new h.Vector3)||new h.Vector3(1,1,1),this.center=l.getCenter(new h.Vector3)||new h.Vector3(0,0,0),this.size.length()<=0&&this.size.set(.01,.01,.01)}};let qa=H0;ri([Pt(),p(h.Vector3)],qa.prototype,"size",2);ri([p(h.Vector3)],qa.prototype,"center",2);class So extends ai{constructor(){super(...arguments);r(this,"sharedMesh");r(this,"convex",!1)}onEnable(){var i,n,o;if(super.onEnable(),!this.context.physics.engine)return;(i=this.sharedMesh)!=null&&i.isMesh||(this.gameObject instanceof h.Mesh||this.gameObject instanceof h.Group)&&(this.sharedMesh=this.gameObject);const e=0;if((n=this.sharedMesh)!=null&&n.isMesh)this.context.physics.engine.addMeshCollider(this,this.sharedMesh,this.convex),re.NEEDLE_progressive.assignMeshLOD(this.sharedMesh,e).then(a=>{a&&this.activeAndEnabled&&this.context.physics.engine&&this.sharedMesh&&(this.context.physics.engine.removeBody(this),this.sharedMesh.geometry=a,this.context.physics.engine.addMeshCollider(this,this.sharedMesh,this.convex))});else{const a=this.sharedMesh;if(a!=null&&a.isGroup){console.warn(`MeshCollider mesh is a group "${((o=this.sharedMesh)==null?void 0:o.name)||this.gameObject.name}", adding all children as colliders. This is currently not fully supported (colliders can not be removed from world again)`,this);const l=new Array;for(const c in a.children){const d=a.children[c];d.isMesh&&(this.context.physics.engine.addMeshCollider(this,d,this.convex),l.push(re.NEEDLE_progressive.assignMeshLOD(d,e)))}Promise.all(l).then(c=>{var u,f;if(c.some(m=>m)==!1)return;(u=this.context.physics.engine)==null||u.removeBody(this);const d=new h.Mesh;for(const m of c)m&&this.activeAndEnabled&&(d.geometry=m,(f=this.context.physics.engine)==null||f.addMeshCollider(this,d,this.convex))})}else(B()||S("showcolliders"))&&console.warn(`[MeshCollider] A MeshCollider mesh is assigned to an unknown object on "${this.gameObject.name}", but it's neither a Mesh nor a Group. Please double check that you attached the collider component to the right object and report a bug otherwise!`,this)}}}ri([p(h.Mesh)],So.prototype,"sharedMesh",2);ri([p()],So.prototype,"convex",2);class Ss extends ai{constructor(){super(...arguments);r(this,"center",new h.Vector3(0,0,0));r(this,"radius",.5);r(this,"height",2)}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addCapsuleCollider(this,this.height,this.radius)}}ri([p(h.Vector3)],Ss.prototype,"center",2);ri([p()],Ss.prototype,"radius",2);ri([p()],Ss.prototype,"height",2);var tO=Object.defineProperty,iO=Object.getOwnPropertyDescriptor,Os=(s,t,e,i)=>{for(var n=i>1?void 0:i?iO(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&tO(t,e,n),n};const zy=S("debugcharactercontroller");class Tr extends D{constructor(){super(...arguments);r(this,"center",new h.Vector3(0,0,0));r(this,"radius",.5);r(this,"height",2);r(this,"_rigidbody",null);r(this,"_activeGroundCollisions");r(this,"_contactVelocity",new h.Vector3)}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(ue),this._rigidbody||(this._rigidbody=this.gameObject.addComponent(ue)),this.rigidbody)}awake(){this._activeGroundCollisions=new Set}onEnable(){const e=this.rigidbody;let i=this.gameObject.getComponent(Ss);i||(i=this.gameObject.addComponent(Ss)),i.center.copy(this.center),i.radius=this.radius,i.height=this.height;const n=new h.Vector3(0,0,1),o=new h.Vector3(1,0,0),a=new h.Vector3(0,1,0),l=this.gameObject.getWorldDirection(new h.Vector3);l.y=0;const c=o.dot(l)<0?-1:1,d=n.angleTo(l)*c;this.gameObject.setRotationFromAxisAngle(a,d),e.lockRotationX=!0,e.lockRotationY=!0,e.lockRotationZ=!0}move(e){this.gameObject.position.add(e)}onCollisionEnter(e){(e.contacts.length==0||e.contacts.some(i=>i.normal.y>.2))&&(this._activeGroundCollisions.add(e),zy&&console.log(`Collision(${this._activeGroundCollisions.size}): ${e.contacts.map(i=>i.normal.y.toFixed(2)).join(", ")} - ${this.isGrounded}`))}onCollisionExit(e){this._activeGroundCollisions.delete(e),zy&&console.log(`Collision(${this._activeGroundCollisions.size}) - ${this.isGrounded}`)}get isGrounded(){return this._activeGroundCollisions.size>0}get contactVelocity(){var e;this._contactVelocity.set(0,0,0);for(const i of this._activeGroundCollisions){const n=(e=this.context.physics.engine)==null?void 0:e.getLinearVelocity(i.collider);n&&(this._contactVelocity.x+=n.x,this._contactVelocity.y+=n.y,this._contactVelocity.z+=n.z)}return this._contactVelocity}}Os([p(h.Vector3)],Tr.prototype,"center",2);Os([p()],Tr.prototype,"radius",2);Os([p()],Tr.prototype,"height",2);class Ms extends D{constructor(){super(...arguments);r(this,"controller");r(this,"movementSpeed",2);r(this,"rotationSpeed",2);r(this,"jumpForce",1);r(this,"doubleJumpForce",2);r(this,"animator");r(this,"lookForward",!0);r(this,"lookInput",new h.Vector2(0,0));r(this,"moveInput",new h.Vector2(0,0));r(this,"jumpInput",!1);r(this,"_currentSpeed",new h.Vector3(0,0,0));r(this,"_currentAngularSpeed",new h.Vector3(0,0,0));r(this,"_temp",new h.Vector3(0,0,0));r(this,"_jumpCount",0);r(this,"_currentRotation");r(this,"_raycastOptions",new zn)}awake(){this._currentRotation=new h.Quaternion}update(){const e=this.context.input;e.isKeyPressed("KeyW")?this.moveInput.y+=1:e.isKeyPressed("KeyS")&&(this.moveInput.y-=1),e.isKeyPressed("KeyD")?this.lookInput.x+=1:e.isKeyPressed("KeyA")&&(this.lookInput.x-=1),this.jumpInput||(this.jumpInput=e.isKeyDown("Space"))}move(e){this.moveInput.add(e)}look(e){this.lookInput.add(e)}jump(){this.jumpInput=!0}onBeforeRender(){this.handleInput(this.moveInput,this.lookInput,this.jumpInput),this.lookInput.set(0,0),this.moveInput.set(0,0),this.jumpInput=!1}handleInput(e,i,n){var o,a,l,c,d,u,f,m,g,_,y;if((o=this.controller)!=null&&o.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((a=this.animator)==null||a.setBool("doubleJump",!1))),this._currentSpeed.z+=e.y*this.movementSpeed*this.context.time.deltaTime,(l=this.animator)==null||l.setBool("running",e.length()>.01),(d=this.animator)==null||d.setBool("jumping",((c=this.controller)==null?void 0:c.isGrounded)===!0&&n),this._temp.copy(this._currentSpeed),this._temp.applyQuaternion(this.gameObject.quaternion),this.controller?this.controller.move(this._temp):this.gameObject.position.add(this._temp),this._currentAngularSpeed.y+=z.toRadians(-i.x*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const b=this.context.mainCameraComponent.forward;b.y=0,b.normalize(),this._currentRotation.setFromUnitVectors(new h.Vector3(0,0,1),b),this.gameObject.quaternion.slerp(this._currentRotation,this.context.time.deltaTime*10)}if(this.gameObject.rotateY(this._currentAngularSpeed.y),this._currentSpeed.multiplyScalar(1-this.context.time.deltaTime*10),this._currentAngularSpeed.y*=1-this.context.time.deltaTime*10,this.controller&&n&&this.jumpForce>0){let b=(u=this.controller)==null?void 0:u.isGrounded;if(this.doubleJumpForce>0&&!((f=this.controller)!=null&&f.isGrounded)&&this._jumpCount===1&&(b=!0,(m=this.animator)==null||m.setBool("doubleJump",!0)),b){this._jumpCount+=1;const v=this.controller.rigidbody,x=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;v.applyImpulse(new h.Vector3(0,1,0).multiplyScalar(x))}}if(this.controller){const b=(g=this.controller)==null?void 0:g.rigidbody.getVelocity().y;if(b<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new h.Ray),this._raycastOptions.ray.origin.copy(K(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const v=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const x=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(v),(x.length&&x[0].distance>2||b<-10)&&((_=this.animator)==null||_.setBool("falling",!0))}else(y=this.animator)==null||y.setBool("falling",!1)}}}Os([p(Tr)],Ms.prototype,"controller",2);Os([p()],Ms.prototype,"movementSpeed",2);Os([p()],Ms.prototype,"rotationSpeed",2);Os([p()],Ms.prototype,"jumpForce",2);Os([p()],Ms.prototype,"doubleJumpForce",2);Os([p(St)],Ms.prototype,"animator",2);var nO=Object.defineProperty,sO=Object.getOwnPropertyDescriptor,Xa=(s,t,e,i)=>{for(var n=i>1?void 0:i?sO(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&nO(t,e,n),n};const xl=S("debugcontactshadows");k0(s=>{const t=s.domElement.getAttribute("contactshadows");t!=null&&t!="0"&&t!="false"&&gn.auto(s)});var Rp;const Vl=(Rp=class extends D{constructor(){super(...arguments);r(this,"autoFit",!1);r(this,"darkness",.5);r(this,"opacity",.5);r(this,"blur",4);r(this,"occludeBelowGround",!1);r(this,"backfaceShadows",!0);r(this,"minSize");r(this,"shadowsRoot",new h.Object3D);r(this,"shadowCamera");r(this,"shadowGroup",new h.Group);r(this,"renderTarget");r(this,"renderTargetBlur");r(this,"plane");r(this,"occluderMesh");r(this,"blurPlane");r(this,"depthMaterial");r(this,"horizontalBlurMaterial");r(this,"verticalBlurMaterial");r(this,"textureSize",512)}static auto(t){if(t||(t=Q.Current),!t)throw new Error("No context provided and no current context set.");let e=this._instances.get(t);if(!e||e.destroyed){const i=new h.Object3D;e=xi(i,Vl,{autoFit:!1,occludeBelowGround:!1}),this._instances.set(t,e)}return t.scene.add(e.gameObject),e.fitShadows(),e}fitShadows(){xl&&console.warn("Fitting shadows to scene"),Bd(this.shadowsRoot,!1);const t=oi(this.context.scene.children,[this.shadowsRoot]),e=Math.max(1,this.blur/32),i=t.max.x-t.min.x,n=t.max.z-t.min.z;t.expandByVector(new h.Vector3(e*i,0,e*n)),xl&&N.DrawWireBox3(t,16776960,60),this.gameObject.parent&&t.applyMatrix4(this.gameObject.parent.matrixWorld.clone().invert());const o=t.min,a=Math.max(1e-5,(t.max.y-o.y)*.002);t.max.y+=a,this.shadowsRoot.position.set((o.x+t.max.x)/2,o.y-a,(o.z+t.max.z)/2),this.shadowsRoot.scale.set(t.max.x-o.x,t.max.y-o.y,t.max.z-o.z),this.applyMinSize(),this.shadowsRoot.matrixWorldNeedsUpdate=!0,xl&&console.log("Fitted shadows to scene",this.shadowsRoot.scale.clone())}awake(){Vl._instances.set(this.context,this),this.shadowsRoot.hideFlags=zu.DontExport,Bd(this.shadowsRoot,!1)}start(){xl&&console.log("Create ContactShadows on "+this.gameObject.name,this),this.gameObject.add(this.shadowsRoot),this.shadowsRoot.add(this.shadowGroup),this.renderTarget=new h.WebGLRenderTarget(this.textureSize,this.textureSize),this.renderTarget.texture.generateMipmaps=!1,this.renderTargetBlur=new h.WebGLRenderTarget(this.textureSize,this.textureSize),this.renderTargetBlur.texture.generateMipmaps=!1;const t=new h.PlaneGeometry(1,1).rotateX(Math.PI/2);this.gameObject instanceof h.Mesh&&(console.warn("ContactShadows can not be added to a Mesh. Please add it to a Group or an empty Object"),ps(this.gameObject,!1));const e=new h.MeshBasicMaterial({map:this.renderTarget.texture,opacity:this.opacity,color:0,transparent:!0,depthWrite:!1,side:h.FrontSide});this.plane=new h.Mesh(t,e),this.plane.scale.y=-1,this.plane.layers.set(2),this.shadowsRoot.add(this.plane),this.plane&&(this.plane.renderOrder=1),this.occluderMesh=new h.Mesh(this.plane.geometry,new h.MeshBasicMaterial({depthWrite:!0,stencilWrite:!0,colorWrite:!1,side:h.BackSide})).translateY(-1e-4),this.occluderMesh.renderOrder=-100,this.occluderMesh.layers.set(2),this.shadowsRoot.add(this.occluderMesh),this.blurPlane=new h.Mesh(t),this.blurPlane.visible=!1,this.shadowGroup.add(this.blurPlane);const i=0,n=1;this.shadowCamera=new h.OrthographicCamera(-1/2,1/2,1/2,-1/2,i,n),this.shadowCamera.layers.enableAll(),this.shadowCamera.rotation.x=Math.PI/2,this.shadowGroup.add(this.shadowCamera),this.depthMaterial=new h.MeshDepthMaterial,this.depthMaterial.userData.darkness={value:this.darkness},this.depthMaterial.blending=h.CustomBlending,this.depthMaterial.blendEquation=h.MaxEquation,this.depthMaterial.onBeforeCompile=o=>{this.depthMaterial&&(o.uniforms.darkness=this.depthMaterial.userData.darkness,o.fragmentShader=`
926
926
  uniform float darkness;
927
927
  ${o.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 1.0 ), ( 1.0 - fragCoordZ ) * darkness * opacity * (gl_FrontFacing ? 1.0 : 0.66) );")}
928
928
  `)},this.depthMaterial.depthTest=!1,this.depthMaterial.depthWrite=!1,this.horizontalBlurMaterial=new h.ShaderMaterial(Y.HorizontalBlurShader),this.horizontalBlurMaterial.depthTest=!1,this.verticalBlurMaterial=new h.ShaderMaterial(Y.VerticalBlurShader),this.verticalBlurMaterial.depthTest=!1,this.shadowGroup.visible=!1,this.autoFit?this.fitShadows():this.applyMinSize()}onDestroy(){var e,i,n,o,a,l,c,d;Vl._instances.get(this.context)===this&&Vl._instances.delete(this.context),(e=this.renderTarget)==null||e.dispose(),(i=this.renderTargetBlur)==null||i.dispose(),(n=this.depthMaterial)==null||n.dispose(),(o=this.horizontalBlurMaterial)==null||o.dispose(),(a=this.verticalBlurMaterial)==null||a.dispose(),(l=this.blurPlane)==null||l.geometry.dispose(),(c=this.plane)==null||c.geometry.dispose(),(d=this.occluderMesh)==null||d.geometry.dispose()}onBeforeRender(t){if(!this.renderTarget||!this.renderTargetBlur||!this.depthMaterial||!this.shadowCamera||!this.blurPlane||!this.shadowGroup||!this.plane||!this.horizontalBlurMaterial||!this.verticalBlurMaterial){xl&&console.error("ContactShadows: not initialized yet");return}const e=this.context.scene,i=this.context.renderer,n=i.getRenderTarget();this.shadowGroup.visible=!0,this.occluderMesh&&(this.occluderMesh.visible=!1);const o=this.plane.visible;this.plane.visible=!1,this.gameObject instanceof h.Mesh&&ps(this.gameObject,!1);const a=e.background;e.background=null,e.overrideMaterial=this.depthMaterial,this.backfaceShadows?this.depthMaterial.side=h.DoubleSide:this.depthMaterial.side=h.FrontSide;const l=i.getClearAlpha();i.setClearAlpha(0);const c=i.xr.enabled;i.xr.enabled=!1;const d=this.context.scene.matrixWorldAutoUpdate;this.context.scene.matrixWorldAutoUpdate=!1;const u=i.renderLists.get(e,0),f=u.transparent;Ny.length=0,u.transparent=Ny,Wf.length=0;for(const g of u.opaque){if(!g.object.visible)continue;const _=g.material;let y=g.material.colorWrite==!1||_.wireframe===!0||ev(g.object)===!1;!y&&g.material.isLineMaterial&&(y=!0),!y&&g.material.isPointsMaterial&&(y=!0),y&&(Wf.push(g.object),g.object["needle:visible"]=g.object.visible,g.object.visible=!1)}i.setRenderTarget(this.renderTarget),i.clear(),i.render(e,this.shadowCamera),u.transparent=f;for(const g of Wf)g["needle:visible"]!=null&&(g.visible=g["needle:visible"]);e.overrideMaterial=null;const m=Math.max(this.blur,.05);this.blurShadow(m*2),this.blurShadow(m*.5),this.shadowGroup.visible=!1,this.occluderMesh&&(this.occluderMesh.visible=this.occludeBelowGround),this.plane.visible=o,i.setRenderTarget(n),i.setClearAlpha(l),e.background=a,i.xr.enabled=c,this.context.scene.matrixWorldAutoUpdate=d}blurShadow(t){if(!this.blurPlane||!this.shadowCamera||!this.renderTarget||!this.renderTargetBlur||!this.horizontalBlurMaterial||!this.verticalBlurMaterial)return;this.blurPlane.visible=!0;const e=this.shadowsRoot.worldScale,i=(e.x+e.z)/2,n=e.z/i,o=e.x/i;this.blurPlane.material=this.horizontalBlurMaterial,this.blurPlane.material.uniforms.tDiffuse.value=this.renderTarget.texture,this.horizontalBlurMaterial.uniforms.h.value=t*1/this.textureSize*n;const a=this.context.renderer,l=a.getRenderTarget();a.setRenderTarget(this.renderTargetBlur),a.render(this.blurPlane,this.shadowCamera),this.blurPlane.material=this.verticalBlurMaterial,this.blurPlane.material.uniforms.tDiffuse.value=this.renderTargetBlur.texture,this.verticalBlurMaterial.uniforms.v.value=t*1/this.textureSize*o,a.setRenderTarget(this.renderTarget),a.render(this.blurPlane,this.shadowCamera),this.blurPlane.visible=!1,a.setRenderTarget(l)}applyMinSize(){this.minSize&&this.shadowsRoot.scale.set(Math.max(this.minSize.x||0,this.shadowsRoot.scale.x),Math.max(this.minSize.y||0,this.shadowsRoot.scale.y),Math.max(this.minSize.z||0,this.shadowsRoot.scale.z))}},r(Rp,"_instances",new Map),Rp);let gn=Vl;Xa([p()],gn.prototype,"autoFit",2);Xa([p()],gn.prototype,"darkness",2);Xa([p()],gn.prototype,"opacity",2);Xa([p()],gn.prototype,"blur",2);Xa([p()],gn.prototype,"occludeBelowGround",2);Xa([p()],gn.prototype,"backfaceShadows",2);const Ny=[],Wf=new Array,oO=S("logstats");class Og extends D{onEnable(){console.log(this),oO&&this.startCoroutine(this.run(),ve.OnAfterRender)}*run(){for(;this.enabled;){const t=this.context.renderer.info;console.log(t.memory,t.render,t.programs),yield}}}class oh extends D{constructor(){super(...arguments);r(this,"isUsed",!0);r(this,"usedBy",null)}}class Mg extends D{}const Vy=S("debugdeletable"),gc=class extends ni{onEnable(){gc._instances.push(this)}onDisable(){const t=gc._instances.indexOf(this);t>=0&&gc._instances.splice(t,1)}};let hr=gc;r(hr,"_instances",[]);class Rg extends D{update(){for(const t of hr._instances){const e=this.gameObject;if(t.isInBox(e)===!0){const n=C.getComponentInParent(this.gameObject,oh);if(n)Vy&&console.warn("DeleteBox: Not deleting object with usage marker",this.guid,n);else{if(Vy)try{if(t.box){const o=t.box,a=ni.testBox;N.DrawWireBox3(o,16711680,5),N.DrawWireBox3(a,255,5),console.log("DeleteBox: Destroying",this.gameObject,{deleteBoxArea:o,deletedObjectArea:a})}else console.log("DeleteBox: Destroying",this.gameObject)}catch{}Xc(this.gameObject,this.context.connection)}}}}}var rO=Object.defineProperty,aO=Object.getOwnPropertyDescriptor,lO=(s,t,e,i)=>{for(var n=i>1?void 0:i?aO(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&rO(t,e,n),n};class $u extends D{constructor(){super(...arguments);r(this,"visibleOn")}onEnable(){this.apply()}apply(){this.test()||C.setActive(this.gameObject,!1)}test(){return this.visibleOn<0?!0:exports.DeviceUtilities.isMobileDevice()?(this.visibleOn&2)!==0:(this.visibleOn&1)!==0}}lO([p()],$u.prototype,"visibleOn",2);var cO=Object.defineProperty,hO=Object.getOwnPropertyDescriptor,Er=(s,t,e,i)=>{for(var n=i>1?void 0:i?hO(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&cO(t,e,n),n};const In=S("debugdrag"),Hf=[];var kg=(s=>(s[s.XZPlane=0]="XZPlane",s[s.Attached=1]="Attached",s[s.HitNormal=2]="HitNormal",s[s.DynamicViewAngle=3]="DynamicViewAngle",s[s.SnapToSurfaces=4]="SnapToSurfaces",s[s.None=5]="None",s))(kg||{}),El;const Ii=(El=class extends D{constructor(){super(...arguments);r(this,"dragMode",3);r(this,"snapGridResolution",0);r(this,"keepRotation",!0);r(this,"xrDragMode",1);r(this,"xrKeepRotation",!1);r(this,"xrDistanceDragFactor",1);r(this,"showGizmo",!1);r(this,"_rigidbody",null);r(this,"_targetObject",null);r(this,"_dragHelper",null);r(this,"_draggingRigidbodies",[]);r(this,"_potentialDragStartEvt",null);r(this,"_dragHandlers",new Map);r(this,"_totalMovement",new h.Vector3);r(this,"_marker",null);r(this,"_isDragging",!1);r(this,"_didDrag",!1)}static get HasAnySelected(){return this._active>0}static get CurrentlySelected(){Hf.length=0;for(const t of this._instances)t._isDragging&&Hf.push(t);return Hf}get draggedObject(){return this._targetObject}setTargetObject(t){var i,n;this._targetObject=t;for(const o of this._dragHandlers.values())o.setTargetObject(t);const e="_rigidbody-was-kinematic";((i=this._rigidbody)==null?void 0:i[e])===!1&&(this._rigidbody.isKinematic=!1,this._rigidbody[e]=void 0),this._rigidbody=null,t&&(this._rigidbody=C.getComponentInChildren(t,ue),((n=this._rigidbody)==null?void 0:n.isKinematic)===!1&&(this._rigidbody.isKinematic=!0,this._rigidbody[e]=!1))}awake(){this._potentialDragStartEvt=null,this._dragHandlers=new Map,this._totalMovement=new h.Vector3,this._marker=null,this._isDragging=!1,this._didDrag=!1,this._dragHelper=null,this._draggingRigidbodies=[]}start(){this.gameObject.getComponentInParent(Oi)||this.gameObject.addComponent(Oi)}onEnable(){Ii._instances.push(this)}onDisable(){Ii._instances=Ii._instances.filter(t=>t!==this)}allowEdit(t=null){return this.context.connection.allowEditing}onPointerEnter(t){if(!this.allowEdit(this.gameObject)||t.mode!=="screen"||(t.event.mode==="tracked-pointer"||t.event.mode==="transient-pointer"?this.xrDragMode:this.dragMode)===5)return;const n=C.getComponentInParent(t.object,Ii);!n||n!==this||(Ii.lastHovered=t.object,this.context.domElement.style.cursor="pointer")}onPointerMove(t){(this._isDragging||this._potentialDragStartEvt!==null)&&t.use()}onPointerExit(t){this.allowEdit(this.gameObject)&&t.mode==="screen"&&Ii.lastHovered===t.object&&(this.context.domElement.style.cursor="auto")}onPointerDown(t){if(!(!this.allowEdit(this.gameObject)||t.used||(t.mode==="tracked-pointer"||t.mode==="transient-pointer"?this.xrDragMode:this.dragMode)===5)&&(Ii.lastHovered=t.object,t.button===0)){this._dragHandlers.size===0&&(this._didDrag=!1,this._totalMovement.set(0,0,0),this._potentialDragStartEvt=t),this._targetObject||this.setTargetObject(this.gameObject),Ii._active+=1;const n=new Gf(this,this._targetObject);if(this._dragHandlers.set(t.event.space,n),n.onDragStart(t),this._dragHandlers.size===2){const o=this._dragHandlers.values(),a=o.next().value,l=o.next().value;if(a instanceof Gf&&l instanceof Gf){const c=new dO(this,this._targetObject,a,l);this._dragHandlers.set(this.gameObject,c),c.onDragStart(t)}else console.error("Attempting to construct a MultiTouchDragHandler with invalid DragPointerHandlers. This is likely a bug.",{a,b:l})}t.use()}}onPointerUp(t){if(In&&N.DrawLabel(t.point??this.gameObject.worldPosition,"POINTERUP:"+t.pointerId+", "+t.button,.03,3),!this.allowEdit(this.gameObject)||t.button!==0)return;this._potentialDragStartEvt=null;const e=this._dragHandlers.get(t.event.space),i=this._dragHandlers.get(this.gameObject);i&&(i.handlerA===e||i.handlerB===e)&&(this._dragHandlers.delete(this.gameObject),i.onDragEnd(t)),e&&(Ii._active>0&&(Ii._active-=1),this.setTargetObject(null),e.onDragEnd&&e.onDragEnd(t),this._dragHandlers.delete(t.event.space),this._dragHandlers.size===0&&this.onLastDragEnd(t),t.use())}update(){for(const t of this._dragHandlers.values())t.collectMovementInfo&&t.collectMovementInfo(),t.getTotalMovement&&this._totalMovement.add(t.getTotalMovement());if(this._potentialDragStartEvt){if(!this._didDrag)if(this._totalMovement.length()>3e-4)this._didDrag=!0;else return;const t=this._potentialDragStartEvt;this._potentialDragStartEvt=null,this.onFirstDragStart(t)}for(const t of this._dragHandlers.values())t.onDragUpdate&&t.onDragUpdate(this._dragHandlers.size);this._dragHelper&&this._dragHelper.hasSelected&&this.onAnyDragUpdate()}onFirstDragStart(t){if(!t||!t.object)return;const e=C.getComponentInParent(t.object,Ii);if(!e||e!==this&&e._isDragging)return;const i=this._targetObject||this.gameObject;if(!i)return;this._isDragging=!0;const n=C.getComponentInChildren(i,Nn);In&&console.log("DRAG START",n,i),n&&(n.fastMode=!0,n==null||n.requestOwnership()),this._marker=C.addComponent(i,oh),this._draggingRigidbodies.length=0;const o=C.getComponentsInChildren(i,ue);o&&this._draggingRigidbodies.push(...o)}onAnyDragUpdate(){if(!this._dragHelper)return;this._dragHelper.showGizmo=this.showGizmo,this._dragHelper.onUpdate(this.context);for(const e of this._draggingRigidbodies)e.wakeUp(),e.resetVelocities(),e.resetForcesAndTorques();const t=this._targetObject||this.gameObject;$i.markDirty(t)}onLastDragEnd(t){if(!this||!this._isDragging)return;this._isDragging=!1;for(const i of this._draggingRigidbodies)i.setVelocity(i.smoothedVelocity);if(this._draggingRigidbodies.length=0,this._targetObject=null,t!=null&&t.object){const i=C.getComponentInChildren(t.object,Nn);i&&(i.fastMode=!1)}if(this._marker&&this._marker.destroy(),!this._dragHelper)return;const e=this._dragHelper.selected;In&&console.log("DRAG END",e,e==null?void 0:e.visible),this._dragHelper.setSelected(null,this.context)}},r(El,"_active",0),r(El,"_instances",[]),r(El,"lastHovered"),El);let si=Ii;Er([p()],si.prototype,"dragMode",2);Er([p()],si.prototype,"snapGridResolution",2);Er([p()],si.prototype,"keepRotation",2);Er([p()],si.prototype,"xrDragMode",2);Er([p()],si.prototype,"xrKeepRotation",2);Er([p()],si.prototype,"xrDistanceDragFactor",2);Er([p()],si.prototype,"showGizmo",2);class dO{constructor(t,e,i,n){r(this,"handlerA");r(this,"handlerB");r(this,"context");r(this,"settings");r(this,"gameObject");r(this,"_handlerAAttachmentPoint",new h.Vector3);r(this,"_handlerBAttachmentPoint",new h.Vector3);r(this,"_followObject");r(this,"_manipulatorObject");r(this,"_deviceMode");r(this,"_followObjectStartWorldQuaternion",new h.Quaternion);r(this,"_manipulatorPosOffset",new h.Vector3);r(this,"_manipulatorRotOffset",new h.Quaternion);r(this,"_manipulatorScaleOffset",new h.Vector3);r(this,"_tempVec1",new h.Vector3);r(this,"_tempVec2",new h.Vector3);r(this,"_tempVec3",new h.Vector3);r(this,"tempLookMatrix",new h.Matrix4);r(this,"_initialScale",new h.Vector3);r(this,"_initialDistance",0);var a,l;this.context=t.context,this.settings=t,this.gameObject=e,this.handlerA=i,this.handlerB=n,this._followObject=new h.Object3D,this._manipulatorObject=new h.Object3D,this.context.scene.add(this._manipulatorObject);const o=(l=(a=q.active)==null?void 0:a.rig)==null?void 0:l.gameObject;if(!this.handlerA||!this.handlerB||!this.handlerA.hitPointInLocalSpace||!this.handlerB.hitPointInLocalSpace){console.error("Invalid: MultiTouchDragHandler needs two valid DragPointerHandlers with hitPointInLocalSpace set.");return}if(this._tempVec1.copy(this.handlerA.hitPointInLocalSpace),this._tempVec2.copy(this.handlerB.hitPointInLocalSpace),this.gameObject.localToWorld(this._tempVec1),this.gameObject.localToWorld(this._tempVec2),o&&(o.worldToLocal(this._tempVec1),o.worldToLocal(this._tempVec2)),this._initialDistance=this._tempVec1.distanceTo(this._tempVec2),this._initialDistance<.02?(In&&console.log("Finding alternative drag attachment points since initial distance is too low: "+this._initialDistance.toFixed(2)),this.handlerA.followObject.parent.getWorldPosition(this._tempVec1),this.handlerB.followObject.parent.getWorldPosition(this._tempVec2),this._handlerAAttachmentPoint.copy(this._tempVec1),this._handlerBAttachmentPoint.copy(this._tempVec2),this.gameObject.worldToLocal(this._handlerAAttachmentPoint),this.gameObject.worldToLocal(this._handlerBAttachmentPoint),this._initialDistance=this._tempVec1.distanceTo(this._tempVec2),this._initialDistance<.001&&(console.warn("Not supported right now – controller drag points for multitouch are too close!"),this._initialDistance=1)):(this._handlerAAttachmentPoint.copy(this.handlerA.hitPointInLocalSpace),this._handlerBAttachmentPoint.copy(this.handlerB.hitPointInLocalSpace)),this._tempVec3.lerpVectors(this._tempVec1,this._tempVec2,.5),this._initialScale.copy(e.scale),In){this._followObject.add(new h.AxesHelper(2)),this._manipulatorObject.add(new h.AxesHelper(5));const c=d=>`${d.x.toFixed(2)}, ${d.y.toFixed(2)}, ${d.z.toFixed(2)}`;N.DrawLine(this._tempVec1,this._tempVec2,65535,0,!1),N.DrawLabel(this._tempVec3,"A:B "+this._initialDistance.toFixed(2)+`
@@ -1202,7 +1202,7 @@ dateFormat X
1202
1202
  axisFormat %s
1203
1203
  `;const m=Array.from(o),g=new Set;for(const v of m)if(v.affectedObjects&&typeof v.affectedObjects!="string"){if(Array.isArray(v.affectedObjects))for(const x of v.affectedObjects)g.add(x);else g.add(v.affectedObjects);a&&(f+=`section ${v.animationName} (${v.id})
1204
1204
  `,f+=`${v.id} : ${v.start}, ${v.duration}s
1205
- `)}a&&o.size&&console.log(f);const _=new Set;for(const v of g){v.getPath||console.error("USDZExporter: Animation target object has no getPath method. This is likely a bug",v);let x=v.getPath();x.startsWith("<")&&(x=x.substring(1)),x.endsWith(">")&&(x=x.substring(0,x.length-1)),_.add({path:x,obj:v})}const y=Array.from(_).sort((v,x)=>v.path.length-x.path.length),b=new Array;for(let v=0;v<y.length;v++)for(let x=v+1;x<y.length;x++)if(y[x].path.startsWith(y[v].path)){const O=y[x],k=y[v];b.push({child:O.obj.displayName+" ("+O.path+")",parent:k.obj.displayName+" ("+k.path+")"})}b.length&&console.warn("USDZExporter: There are overlapping PlayAnimation actions. This can lead to undefined runtime behaviour when playing multiple animations. Please restructure the hierarchy so that animations don't overlap.",{overlappingTargets:b,playAnimationActions:o})}for(const f of new Set([...e,...i]))if(Array.isArray(f))for(const m of f)n.add(m.uuid);else n.add(f.uuid);td&&console.log("All Behavior trigger sources and action targets",e,i,n),this.targetUuids=new Set(n)}onAfterHierarchy(t,e){var i;if((i=this.behaviours)!=null&&i.length){e.beginBlock('def Scope "Behaviors"');for(const n of this.behaviours)n.writeTo(this,t.document,e);e.closeBlock()}}async onAfterSerialize(t){td&&console.log("onAfterSerialize behaviours",this.behaviourComponentsCopy);for(const e of this.behaviourComponentsCopy)typeof e.afterSerialize=="function"&&(e.afterSerialize.constructor.name==="AsyncFunction"?await e.afterSerialize(this,t):e.afterSerialize(this,t));for(const{clipUrl:e,filesKey:i}of this.audioClipsCopy){if(t.files[i])return;const a=await(await(await fetch(e)).blob()).arrayBuffer(),l=new Uint8Array(a);t.files[i]=l}this.behaviourComponentsCopy.length=0,this.audioClipsCopy.length=0}}var mM=Object.defineProperty,gM=Object.getOwnPropertyDescriptor,Be=(s,t,e,i)=>{for(var n=i>1?void 0:i?gM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&mM(t,e,n),n};const ib=S("debugusdzbehaviours");function ch(s){s&&(s.getComponentInParent(Fa)||(B()&&console.debug('Raycaster on "'+s.name+'" was automatically added, because no raycaster was found in the parent hierarchy.'),s.addComponent(Oi)))}class Dr extends D{constructor(){super(...arguments);r(this,"object");r(this,"target");r(this,"duration",1);r(this,"relativeMotion",!1);r(this,"coroutine",null);r(this,"targetPos",new h.Vector3);r(this,"targetRot",new h.Quaternion);r(this,"targetScale",new h.Vector3)}start(){ch(this.gameObject)}onPointerClick(e){e.use(),this.coroutine&&this.stopCoroutine(this.coroutine),this.relativeMotion?this.coroutine=this.startCoroutine(this.moveRelative()):this.coroutine=this.startCoroutine(this.moveToTarget())}*moveToTarget(){if(!this.target||!this.object)return;const e=K(this.object).clone(),i=K(this.target).clone(),n=ye(this.object).clone(),o=ye(this.target).clone(),a=Ne(this.object).clone(),l=Ne(this.target).clone(),c=e.distanceTo(i),d=n.angleTo(o),u=a.distanceTo(l);if(c<.01&&d<.01&&u<.01){nt(this.object,i),Wi(this.object,o),Da(this.object,l),this.coroutine=null;return}let f=0,m=0;for(;f<1;)f+=this.context.time.deltaTime/this.duration,f>1&&(f=1),m=f<.5?4*f*f*f:1-Math.pow(-2*f+2,3)/2,this.targetPos.lerpVectors(e,i,m),this.targetRot.slerpQuaternions(n,o,m),this.targetScale.lerpVectors(a,l,m),nt(this.object,this.targetPos),Wi(this.object,this.targetRot),Da(this.object,this.targetScale),yield;this.coroutine=null}*moveRelative(){if(!this.target||!this.object)return;const e=this.object.position.clone(),i=this.object.quaternion.clone(),n=this.object.scale.clone(),o=this.target.position.clone(),a=this.target.quaternion.clone(),l=this.target.scale.clone();o.applyQuaternion(this.object.quaternion),this.targetPos.copy(this.object.position).add(o),this.targetRot.copy(this.object.quaternion).multiply(a),this.targetScale.copy(this.object.scale).multiply(l);let c=0,d=0;for(;c<1;)c+=this.context.time.deltaTime/this.duration,c>1&&(c=1),d=c<.5?4*c*c*c:1-Math.pow(-2*c+2,3)/2,this.object.position.lerpVectors(e,this.targetPos,d),this.object.quaternion.slerpQuaternions(i,this.targetRot,d),this.object.scale.lerpVectors(n,this.targetScale,d),yield;this.coroutine=null}beforeCreateDocument(e){var i;if(this.target&&this.object&&this.gameObject){const n=new st("Move to "+((i=this.target)==null?void 0:i.name),ht.tapTrigger(this.gameObject),he.transformAction(this.object,this.target,this.duration,this.relativeMotion?"relative":"absolute"));e.addBehavior(n)}}}Be([p(h.Object3D)],Dr.prototype,"object",2);Be([p(h.Object3D)],Dr.prototype,"target",2);Be([p()],Dr.prototype,"duration",2);Be([p()],Dr.prototype,"relativeMotion",2);var ia;const Ut=(ia=class extends D{constructor(){super(...arguments);r(this,"materialToSwitch");r(this,"variantMaterial");r(this,"fadeDuration",0);r(this,"_objectsWithThisMaterial",null);r(this,"selfModel");r(this,"targetModels")}start(){var t;this._objectsWithThisMaterial=this.objectsWithThisMaterial,ch(this.gameObject),B()&&this._objectsWithThisMaterial.length<=0&&console.warn('ChangeMaterialOnClick: No objects found with material "'+((t=this.materialToSwitch)==null?void 0:t.name)+'"')}onPointerEnter(t){this.context.input.setCursor("pointer")}onPointerExit(t){this.context.input.unsetCursor("pointer")}onPointerClick(t){if(t.use(),!!this.variantMaterial)for(let e=0;e<this.objectsWithThisMaterial.length;e++){const i=this.objectsWithThisMaterial[e];i.material=this.variantMaterial}}get objectsWithThisMaterial(){return this._objectsWithThisMaterial!=null?this._objectsWithThisMaterial:(this._objectsWithThisMaterial=[],this.variantMaterial&&this.materialToSwitch&&this.context.scene.traverse(t=>{if(t instanceof h.Mesh)if(Array.isArray(t.material)){for(const e of t.material)if(e===this.materialToSwitch){this.objectsWithThisMaterial.push(t);break}}else t.material===this.materialToSwitch?this.objectsWithThisMaterial.push(t):Wv(t.material,this.materialToSwitch)&&this.objectsWithThisMaterial.push(t)}),this._objectsWithThisMaterial)}async beforeCreateDocument(t,e){this.targetModels=[],Ut._materialTriggersPerId={},Ut.variantSwitchIndex=0,this.materialToSwitch&&await re.NEEDLE_progressive.assignTextureLOD(this.materialToSwitch,0),this.variantMaterial&&await re.NEEDLE_progressive.assignTextureLOD(this.variantMaterial,0)}createBehaviours(t,e,i){this.objectsWithThisMaterial.find(o=>o.uuid===e.uuid)&&this.targetModels.push(e),this.gameObject.uuid===e.uuid&&(this.selfModel=e,this.materialToSwitch&&(Ut._materialTriggersPerId[this.materialToSwitch.uuid]||(Ut._materialTriggersPerId[this.materialToSwitch.uuid]=[]),Ut._materialTriggersPerId[this.materialToSwitch.uuid].push(this)))}afterCreateDocument(t,e){if(!this.materialToSwitch)return;const i=Ut._materialTriggersPerId[this.materialToSwitch.uuid];if(i){const n={};for(const o of i){const a=o.createVariants();a&&a.length>0&&(n[o.selfModel.uuid]=a)}for(const o of i){const a=[];for(const l in n)l!==o.selfModel.uuid&&a.push(...n[l]);o.createAndAttachBehaviors(t,n[o.selfModel.uuid],a)}}delete Ut._materialTriggersPerId[this.materialToSwitch.uuid]}createAndAttachBehaviors(t,e,i){const n=[],o=Math.max(0,this.fadeDuration);n.push(he.fadeAction([...this.targetModels,...i],o,!1)),n.push(he.fadeAction(e,o,!0)),t.addBehavior(new st("Select_"+this.selfModel.name,ht.tapTrigger(this.selfModel),he.parallel(...n))),Ut._parallelStartHiddenActions.push(...e),Ut._startHiddenBehaviour||(Ut._startHiddenBehaviour=new st("StartHidden_"+this.selfModel.name,ht.sceneStartTrigger(),he.fadeAction(Ut._parallelStartHiddenActions,o,!1)),t.addBehavior(Ut._startHiddenBehaviour))}static getMaterialName(t){return fn(t.name||"Material")+"_"+t.id}createVariants(){if(!this.variantMaterial)return null;const t=[];for(const e of this.targetModels){const i=e.clone();i.name+="_Variant_"+Ut.variantSwitchIndex+++"_"+Ut.getMaterialName(this.variantMaterial),i.displayName=i.displayName+": Variant with material "+this.variantMaterial.name,i.material=this.variantMaterial,i.geometry=e.geometry,i.transform=e.transform,(!e.parent||!e.parent.isEmpty())&&wt.createEmptyParent(e),e.parent&&e.parent.add(i),t.push(i)}return t}},r(ia,"_materialTriggersPerId",{}),r(ia,"_startHiddenBehaviour",null),r(ia,"_parallelStartHiddenActions",[]),r(ia,"variantSwitchIndex",0),ia);let Ka=Ut;Be([p(h.Material)],Ka.prototype,"materialToSwitch",2);Be([p(h.Material)],Ka.prototype,"variantMaterial",2);Be([p()],Ka.prototype,"fadeDuration",2);var na;const Le=(na=class extends D{constructor(){super(...arguments);r(this,"target");r(this,"toggleOnClick",!1);r(this,"targetState",!0);r(this,"hideSelf",!0);r(this,"selfModel");r(this,"selfModelClone");r(this,"targetModel");r(this,"toggleModel");r(this,"stateBeforeCreatingDocument",!1);r(this,"targetStateBeforeCreatingDocument",!1)}start(){ch(this.gameObject)}onPointerClick(t){t.use(),!this.toggleOnClick&&this.hideSelf&&(this.gameObject.visible=!1),this.target&&(this.target.visible=this.toggleOnClick?!this.target.visible:this.targetState)}createBehaviours(t,e,i){e.uuid===this.gameObject.uuid&&(this.selfModel=e,this.selfModelClone=e.clone())}beforeCreateDocument(){this.target&&(this.gameObject[Le.wasVisible]===void 0&&(this.gameObject[Le.wasVisible]=this.gameObject.activeSelf),this.target[Le.wasVisible]===void 0&&(this.target[Le.wasVisible]=this.target.activeSelf),this.stateBeforeCreatingDocument=this.gameObject[Le.wasVisible],this.targetStateBeforeCreatingDocument=this.target[Le.wasVisible],this.gameObject.visible=!0,this.target.visible=!0)}afterCreateDocument(t,e){if(!this.target)return;this.targetModel=e.document.findById(this.target.uuid);const i=this.selfModel;if(this.selfModel&&this.targetModel){let n=this.selfModel,o=this.targetState;if(this.toggleOnClick)if(o=!this.targetStateBeforeCreatingDocument,!this.selfModelClone.geometry)(!this.selfModel.parent||this.selfModel.parent.isEmpty())&&Bg.createEmptyParent(this.selfModel),this.toggleModel=this.selfModel.deepClone(),this.toggleModel.name+="_toggle",this.selfModel.parent.add(this.toggleModel);else{if(!this.gameObject[Le.toggleClone]){const c=this.selfModelClone.clone();c.setMatrix(new h.Matrix4),c.name+="_toggle"+Le.clonedToggleIndex++,i.add(c),this.gameObject[Le.toggleClone]=c,console.warn("USDZExport: Toggle "+this.gameObject.name+" doesn't have geometry. It will be deep cloned and nested behaviours will likely not work.")}const l=this.gameObject[Le.toggleClone];if(!this.gameObject[Le.reverseToggleClone]){const c=this.selfModelClone.clone();c.setMatrix(new h.Matrix4),c.name+="_toggleReverse"+Le.clonedToggleIndex++,i.add(c),this.gameObject[Le.reverseToggleClone]=c}this.toggleModel=this.gameObject[Le.reverseToggleClone],(!this.toggleModel.geometry||!l.geometry)&&console.error("triggers without childs and without geometry won't work!",this,i.geometry),n=l,i.geometry=null,i.material=null}if(this.toggleModel){if(this.toggleOnClick){const l=[];l.push(he.fadeAction(n,0,!1)),l.push(he.fadeAction(this.toggleModel,0,!0)),l.push(he.fadeAction(this.targetModel,0,o)),t.addBehavior(new st("Toggle_"+n.name+"_ToggleTo"+(o?"On":"Off"),ht.tapTrigger(n),he.parallel(...l)));const c=[];c.push(he.fadeAction(this.toggleModel,0,!1)),c.push(he.fadeAction(n,0,!0)),c.push(he.fadeAction(this.targetModel,0,!o)),t.addBehavior(new st("Toggle_"+n.name+"_ToggleTo"+(o?"Off":"On"),ht.tapTrigger(this.toggleModel),he.parallel(...c)))}}else{const l=[];this.hideSelf&&l.push(he.fadeAction(n,0,!1)),l.push(he.fadeAction(this.targetModel,0,o)),t.addBehavior(new st("Toggle_"+n.name+"_ToggleTo"+(o?"On":"Off"),ht.tapTrigger(n),l.length>1?he.parallel(...l):l[0]))}const a=new Array;this.targetStateBeforeCreatingDocument||a.push(this.targetModel),this.stateBeforeCreatingDocument||a.push(i),this.toggleModel&&a.push(this.toggleModel),Js.add(a,t)}}afterSerialize(t,e){this.gameObject[Le.wasVisible]!==void 0&&(this.gameObject.visible=this.gameObject[Le.wasVisible],delete this.gameObject[Le.wasVisible]),this.target&&this.target[Le.wasVisible]!==void 0&&(this.target.visible=this.target[Le.wasVisible],delete this.target[Le.wasVisible]),delete this.gameObject[Le.toggleClone],delete this.gameObject[Le.reverseToggleClone]}},r(na,"clonedToggleIndex",0),r(na,"wasVisible",Symbol("usdz_SetActiveOnClick_wasVisible")),r(na,"toggleClone",Symbol("clone for toggling")),r(na,"reverseToggleClone",Symbol("clone for reverse toggling")),na);let Lr=Le;Be([p(h.Object3D)],Lr.prototype,"target",2);Be([p()],Lr.prototype,"toggleOnClick",2);Be([p()],Lr.prototype,"targetState",2);Be([p()],Lr.prototype,"hideSelf",2);const hs=class extends D{constructor(){super(...arguments);r(this,"wasVisible",!1)}static add(e,i){const n=Array.isArray(e)?e:[e];for(const o of n)hs._fadeObjects.includes(o)||(console.log("adding hide on start",o),hs._fadeObjects.push(o));hs._fadeBehaviour===void 0&&(hs._fadeBehaviour=new st("HideOnStart",ht.sceneStartTrigger(),he.fadeAction(hs._fadeObjects,0,!1)),i.addBehavior(hs._fadeBehaviour))}start(){C.setActive(this.gameObject,!1)}createBehaviours(e,i,n){i.uuid===this.gameObject.uuid&&(this.wasVisible||hs.add(i,e))}beforeCreateDocument(){this.wasVisible=C.isActiveSelf(this.gameObject)}};let Js=hs;r(Js,"_fadeBehaviour"),r(Js,"_fadeObjects",[]);class Za extends D{constructor(){super(...arguments);r(this,"target");r(this,"duration",.5);r(this,"motionType","bounce")}beforeCreateDocument(){}createBehaviours(e,i,n){if(this.target&&i.uuid===this.gameObject.uuid){const o=new st("emphasize "+this.name,ht.tapTrigger(this.gameObject),he.emphasize(this.target,this.duration,this.motionType,void 0,"basic"));e.addBehavior(o)}}afterCreateDocument(e,i){}}Be([p()],Za.prototype,"target",2);Be([p()],Za.prototype,"duration",2);Be([p()],Za.prototype,"motionType",2);class ho extends D{constructor(){super(...arguments);r(this,"target");r(this,"clip","");r(this,"toggleOnClick",!1);r(this,"trigger","tap")}start(){ch(this.gameObject)}ensureAudioSource(){if(!this.target){const e=this.gameObject.addComponent(je);e&&(this.target=e,e.spatialBlend=1,e.volume=1,e.loop=!1,e.preload=!0)}}onPointerClick(e){var i;e.use(),!(!((i=this.target)!=null&&i.clip)&&!this.clip)&&(this.ensureAudioSource(),this.target&&(this.target.isPlaying&&this.toggleOnClick?this.target.stop():(!this.toggleOnClick&&this.target.isPlaying&&this.target.stop(),this.clip?this.target.play(this.clip):this.target.play())))}createBehaviours(e,i,n){if(!(!this.target&&!this.clip)&&i.uuid===this.gameObject.uuid){const o=this.clip?this.clip:this.target?this.target.clip:void 0;if(!o||typeof o!="string")return;const a=this.target?this.target.gameObject:this.gameObject;Co.getName(o);const l=this.target?this.target.volume:1,c=this.target&&this.target.spatialBlend==0?"nonSpatial":"spatial";let d=!1;this.gameObject.traverse(g=>{g instanceof h.Mesh&&g.visible&&(d=!0)}),d=!0;const u=e.addAudioClip(o);let f=he.playAudioAction(a,u,"play",l,c);this.target&&this.target.loop&&(f=he.sequence(f).makeLooping());const m=this.name?"_"+this.name:"";if(d&&this.trigger==="tap"){this.toggleOnClick&&(f.multiplePerformOperation="stop");const g=new st("playAudio"+m,ht.tapTrigger(i),f);e.addBehavior(g)}if(this.target&&this.target.playOnAwake&&this.target.enabled)if(d&&this.trigger==="tap")console.warn("USDZExport: Audio sources that are played on tap can't also auto-play at scene start due to a QuickLook bug.");else{const g=new st("playAudioOnStart"+m,ht.sceneStartTrigger(),f);e.addBehavior(g)}}}}Be([p(je)],ho.prototype,"target",2);Be([p(URL)],ho.prototype,"clip",2);Be([p()],ho.prototype,"toggleOnClick",2);var ud;const Sn=(ud=class extends D{constructor(){super(...arguments);r(this,"animator");r(this,"stateName");r(this,"trigger","tap");r(this,"animation");r(this,"selfModel");r(this,"stateAnimationModel");r(this,"animationSequence",new Array);r(this,"animationLoopAfterSequence",new Array);r(this,"randomOffsetNormalized",0)}get target(){var t,e;return((t=this.animator)==null?void 0:t.gameObject)||((e=this.animation)==null?void 0:e.gameObject)}start(){ch(this.gameObject)}onPointerClick(t){var e;t.use(),this.target&&this.stateName&&((e=this.animator)==null||e.play(this.stateName,0,0,.1))}createBehaviours(t,e,i){e.uuid===this.gameObject.uuid&&(this.selfModel=e)}afterSerialize(){if(Sn.rootsWithExclusivePlayback.size>1){const t='Multiple root objects targeted by more than one animation. To work around QuickLook bug FB13410767, animations will be set as "exclusive" and activating them will stop other animations being marked as exclusive.';B()&&me(t),console.warn(t,...Sn.rootsWithExclusivePlayback)}Sn.animationActions=[],Sn.rootsWithExclusivePlayback=new Set}afterCreateDocument(t,e){if(this.animationSequence===void 0&&this.animationLoopAfterSequence===void 0||!this.stateAnimationModel||!this.target)return;const i=e.document,n=e.extensions.find(l=>l instanceof lh);if(!n)return;const o=n.getClipCount(this.target)>1;o&&(B()&&console.warn("Setting exclusive playback for "+this.target.name+"@"+this.stateName+" because it has "+n.getClipCount(this.target)+" animations. This works around QuickLook bug FB13410767."),Sn.rootsWithExclusivePlayback.add(this.target));const a=this.name?this.name:"";i.traverse(l=>{var c,d;if(l.uuid===((c=this.target)==null?void 0:c.uuid)){const u=Sn.getActionForSequences(i,l,this.animationSequence,this.animationLoopAfterSequence,this.randomOffsetNormalized),f=new st(this.trigger+"_"+a+"_toPlayAnimation_"+this.stateName+"_on_"+((d=this.target)==null?void 0:d.name),this.trigger=="tap"?ht.tapTrigger(this.selfModel):ht.sceneStartTrigger(),u);o&&f.makeExclusive(!0),t.addBehavior(f)}})}static getActionForSequences(t,e,i,n,o){const a=(c,d)=>{let u=Sn.animationActions.find(f=>f.affectedObjects==c&&f.start==d.start&&f.duration==d.duration&&f.animationSpeed==d.speed);return u||(u=he.startAnimationAction(c,d),Sn.animationActions.push(u)),u},l=he.sequence();if(i&&i.length>0)for(const c of i)l.addAction(a(e,c));if(n&&n.length>0){const c=l.actions.length==0?l:he.sequence();for(const d of n)c.addAction(a(e,d));c.makeLooping(),l!==c&&l.addAction(c)}return o&&o>0&&l.actions.unshift(he.waitAction(o)),l}static getAndRegisterAnimationSequences(t,e,i){var _,y,b,v,x,O,k,M;if(!e)return;const n=e.getComponent(St),o=e.getComponent(Et);if(!n&&!o)return;if(n&&!i)throw new Error("PlayAnimationOnClick: No stateName specified for animator "+n.name+" on "+e.name);let a=[],l=[];if(o){const R=t.registerAnimation(e,o.clip);R&&(o.loop?l.push(R):a.push(R));let A=0;if(o.minMaxOffsetNormalized){const I=o.minMaxOffsetNormalized.x,E=o.minMaxOffsetNormalized.y;A=(((_=o.clip)==null?void 0:_.duration)||1)*(I+Math.random()*(E-I))}return{animationSequence:a,animationLoopAfterSequence:l,randomTimeOffset:A}}const c=n==null?void 0:n.runtimeAnimatorController;let d=c==null?void 0:c.findState(i),u=[],f=[];if(c&&d){const R=new Array;R.push(d);let A=!1;for(;R.length<100;){if(!d||d===null||!d.transitions||d.transitions.length===0){(y=d.motion)!=null&&y.isLooping&&(A=!0);break}const I=d.transitions.find(j=>j.conditions.length===0),E=I?c.getState(I.destinationState,0):null;if(E&&R.includes(E)){d=E,A=!0;break}else if(I){if(d=E,!d)break;R.push(d)}else{A=((b=d.motion)==null?void 0:b.isLooping)??!1;break}}if(A&&d){const I=R.indexOf(d);u=R.slice(0,I),f=R.slice(I),ib&&console.log("found loop from "+i,"states until loop",u,"states looping",f)}else u=R,f=[],ib&&console.log("found no loop from "+i,"states",u);if(!f.length){const I=u[u.length-1],E=(v=I.motion)==null?void 0:v.clip;if(E){let j;if(t.holdClipMap.has(E))j=t.holdClipMap.get(E);else{const F=I.name+"_hold";j=E.clone(),j.duration=1,j.name=F;const G=E.duration;j.tracks=E.tracks.map(T=>{const L=T.clone();L.times=new Float32Array([0,G]);const $=T.values.length,X=T.getValueSize(),J=T.values.slice($-X,$);return L.values=new Float32Array(2*X),L.values.set(J,0),L.values.set(J,X),L}),j.name=F,t.holdClipMap.set(E,j)}if(j){const F={name:j.name,motion:{clip:j,isLooping:!1,name:j.name},speed:1,transitions:[],behaviours:[],hash:I.hash+1};f.push(F)}}}}if(u.length===1&&(!((x=u[0].motion)!=null&&x.clip)||((k=(O=u[0].motion)==null?void 0:O.clip.tracks)==null?void 0:k.length)===0)){a=new Array;const R=t.registerAnimation(e,null);R&&a.push(R);return}if(u=u.filter(R=>{var A,I,E;return((A=R.motion)==null?void 0:A.clip)&&((E=(I=R.motion)==null?void 0:I.clip.tracks)==null?void 0:E.length)>0}),f=f.filter(R=>{var A,I,E;return((A=R.motion)==null?void 0:A.clip)&&((E=(I=R.motion)==null?void 0:I.clip.tracks)==null?void 0:E.length)>0}),u.length===0&&f.length===0){console.warn("No clips found for state "+i+" on "+(n==null?void 0:n.name)+", can't export animation data");return}const m=(R,A)=>{if(!e)return;const I=t.registerAnimation(e,R.motion.clip??null);I?(I.speed=R.speed,A.push(I)):console.warn("Couldn't register animation for state "+R.name+" on "+(n==null?void 0:n.name))};if(u.length>0){a=new Array;for(const R of u)m(R,a)}if(f.length>0){l=new Array;for(const R of f)m(R,l)}let g=0;if(n&&c&&n.minMaxOffsetNormalized){const R=n.minMaxOffsetNormalized.x,A=n.minMaxOffsetNormalized.y,I=u.length?u[0]:f.length?f[0]:null;g=(((M=I==null?void 0:I.motion.clip)==null?void 0:M.duration)||1)*(R+Math.random()*(A-R))}return{animationSequence:a,animationLoopAfterSequence:l,randomTimeOffset:g}}createAnimation(t,e,i){if(!this.target||!this.animator&&!this.animation)return;const n=Sn.getAndRegisterAnimationSequences(t,this.target,this.stateName);n&&(this.animationSequence=n.animationSequence,this.animationLoopAfterSequence=n.animationLoopAfterSequence,this.randomOffsetNormalized=n.randomTimeOffset,this.stateAnimationModel=e)}},r(ud,"animationActions",[]),r(ud,"rootsWithExclusivePlayback",new Set),ud);let wr=Sn;Be([p(St)],wr.prototype,"animator",2);Be([p()],wr.prototype,"stateName",2);class Ja extends D{constructor(){super(...arguments);r(this,"target")}getType(){}getDuration(){}}Be([p(h.Object3D)],Ja.prototype,"target",2);class hh extends D{constructor(){super(...arguments);r(this,"target")}}Be([p(Ja)],hh.prototype,"target",2);class dh extends Ja{constructor(){super(...arguments);r(this,"type",1);r(this,"duration",1)}getType(){switch(this.type){case 1:return"hide";case 0:return"show"}}getDuration(){return this.duration}}Be([p()],dh.prototype,"type",2);Be([p()],dh.prototype,"duration",2);class Ng extends hh{}class Xu{get extensionName(){return"Physics"}onExportObject(t,e,i){const n=C.getComponents(t,ue).filter(c=>c.enabled),o=C.getComponents(t,ai).filter(c=>c.enabled&&!c.isTrigger);let a=n.length>0?n[0]:null;const l=o.length>0?o[0]:null;l&&!a&&(a=new ue,a.isKinematic=!0),a&&e.addEventListener("serialize",(c,d)=>{var u,f,m;if(a){if(c.appendLine(),c.beginBlock('def RealityKitComponent "RigidBody"',"{",!0),a.useGravity||c.appendLine("bool gravityEnabled = 0"),c.appendLine('uniform token info:id = "RealityKit.RigidBody"'),a.isKinematic&&c.appendLine('token motionType = "Kinematic"'),c.beginBlock('def RealityKitStruct "massFrame"',"{",!0),c.appendLine(`float m_mass = ${a.mass}`),c.beginBlock('def RealityKitStruct "m_pose"',"{",!0),c.appendLine(`float3 position = (${a.centerOfMass.x}, ${a.centerOfMass.y}, ${a.centerOfMass.z})`),c.closeBlock("}"),c.closeBlock("}"),o.length>0){const g=o[0];c.beginBlock('def RealityKitStruct "material"',"{",!0);const _=g.sharedMaterial;_&&_.dynamicFriction!==void 0&&c.appendLine(`double dynamicFriction = ${(u=g.sharedMaterial)==null?void 0:u.dynamicFriction}`),_&&_.bounciness!==void 0&&c.appendLine(`double restitution = ${(f=g.sharedMaterial)==null?void 0:f.bounciness}`),_&&_.staticFriction!==void 0&&c.appendLine(`double staticFriction = ${(m=g.sharedMaterial)==null?void 0:m.staticFriction}`),c.closeBlock("}")}c.closeBlock("}")}}),l&&(e.addEventListener("serialize",(c,d)=>{var m;c.beginBlock('def RealityKitComponent "Collider"',"{",!0),c.appendLine("uint group = 1"),c.appendLine('uniform token info:id = "RealityKit.Collider"'),c.appendLine("uint mask = 4294967295");const f=l.isTrigger?"Trigger":"Default";if(c.appendLine(`token type = "${f}"`),c.beginBlock('def RealityKitStruct "Shape"',"{",!0),l instanceof Ga){const g=l;c.appendLine('token shapeType = "Sphere"'),c.appendLine(`float radius = ${g.radius}`)}else if(l instanceof qa){const g=l;c.appendLine('token shapeType = "Box"'),c.appendLine(`float3 extent = (${g.size.x}, ${g.size.y}, ${g.size.z})`)}else if(l instanceof Ss){const g=l;c.appendLine('token shapeType = "Capsule"'),c.appendLine(`float radius = ${g.radius}`),c.appendLine(`float height = ${g.height}`)}else if(l instanceof So&&((m=l.sharedMesh)!=null&&m.geometry)){const g=l.sharedMesh.geometry;g.boundingBox||g.computeBoundingBox();const _=l.sharedMesh.geometry.boundingBox;_&&(c.appendLine('token shapeType = "Box"'),c.appendLine(`float3 extent = (${_.max.x-_.min.x}, ${_.max.y-_.min.y}, ${_.max.z-_.min.z})`),console.log("[USDZ] Only Box, Sphere, and Capsule colliders are supported in visionOS/iOS. MeshCollider will be exported as Box",l))}else console.warn("[USDZ] Only Box, Sphere, and Capsule colliders are supported in visionOS/iOS. Ignoring collider:",l);c.beginBlock('def RealityKitStruct "pose"',"{",!0),c.closeBlock("}"),c.closeBlock("}"),c.closeBlock("}")}),o.length>1&&console.log("WARNING: Multiple colliders detected. visionOS / iOS can only support objects with a single collider, only exporting the first collider: ",l))}}class Vg{get extensionName(){return"DocumentExtension"}onAfterBuildDocument(t){}}var _M=Object.defineProperty,yM=Object.getOwnPropertyDescriptor,uh=(s,t,e,i)=>{for(var n=i>1?void 0:i?yM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&_M(t,e,n),n};const ip=S("debugui"),np=S("debuguilayout");class $g{constructor(){r(this,"width");r(this,"height")}}class Wg{constructor(){r(this,"x");r(this,"y");r(this,"width");r(this,"height")}}const en=new h.Vector3,Sl=new h.Matrix4,id=new h.Quaternion,_w=class extends Hi{constructor(){super(...arguments);r(this,"_anchoredPosition");r(this,"sizeDelta",new h.Vector2(100,100));r(this,"pivot",new h.Vector2(.5,.5));r(this,"anchorMin",new h.Vector2(0,0));r(this,"anchorMax",new h.Vector2(1,1));r(this,"minWidth");r(this,"minHeight");r(this,"lastMatrix");r(this,"rectBlock");r(this,"_transformNeedsUpdate",!1);r(this,"_initialPosition");r(this,"_parentRectTransform");r(this,"_lastUpdateFrame",-1);r(this,"_lastAnchoring");r(this,"_createdBlocks",[]);r(this,"_createdTextBlocks",[])}get parent(){return this._parentRectTransform}get translation(){return this.gameObject.position}get rotation(){return this.gameObject.quaternion}get scale(){return this.gameObject.scale}get anchoredPosition(){return this._anchoredPosition||(this._anchoredPosition=new h.Vector2),this._anchoredPosition}set anchoredPosition(t){this._anchoredPosition=t}get width(){let t=this.sizeDelta.x;if(this.anchorMin.x!==this.anchorMax.x&&this._parentRectTransform){const e=this._parentRectTransform.width,i=this.anchorMax.x-this.anchorMin.x;t=e*i,t+=this.sizeDelta.x}return this.minWidth!==void 0&&t<this.minWidth?this.minWidth:t}get height(){let t=this.sizeDelta.y;if(this.anchorMin.y!==this.anchorMax.y&&this._parentRectTransform){const e=this._parentRectTransform.height,i=this.anchorMax.y-this.anchorMin.y;t=e*i,t+=this.sizeDelta.y}return this.minHeight!==void 0&&t<this.minHeight?this.minHeight:t}awake(){super.awake(),this._anchoredPosition||(this._anchoredPosition=new h.Vector2),this.lastMatrix=new h.Matrix4,this.rectBlock=new h.Object3D,this.rectBlock.name=this.name,this._initialPosition=this.gameObject.position.clone(),this._initialPosition.z=0,la(this,"_anchoredPosition",()=>{this.markDirty()}),la(this,"sizeDelta",()=>{this.markDirty()}),la(this,"pivot",()=>{this.markDirty()}),la(this,"anchorMin",()=>{this.markDirty()}),la(this,"anchorMax",()=>{this.markDirty()})}onEnable(){var t;super.onEnable(),this.rectBlock||(this.rectBlock=new h.Object3D),this.lastMatrix||(this.lastMatrix=new h.Matrix4),this._lastAnchoring||(this._lastAnchoring=new h.Vector2),this._initialPosition||(this._initialPosition=new h.Vector3),this._anchoredPosition||(this._anchoredPosition=new h.Vector2),this.addShadowComponent(this.rectBlock),this._transformNeedsUpdate=!0,(t=this.canvas)==null||t.registerTransform(this)}onDisable(){var t;super.onDisable(),this.removeShadowComponent(),(t=this.canvas)==null||t.unregisterTransform(this)}onParentRectTransformChanged(t){this._transformNeedsUpdate||this.onApplyTransform(np?`${t.name} changed`:void 0)}get isDirty(){return this._transformNeedsUpdate||(this._transformNeedsUpdate=!this.lastMatrix.equals(this.gameObject.matrix)),this._transformNeedsUpdate}markDirty(){this._transformNeedsUpdate||(np&&console.warn("RectTransform markDirty()",this.name),this._transformNeedsUpdate=!0,this._lastUpdateFrame=-1)}updateTransform(){(this._transformNeedsUpdate||!this.lastMatrix.equals(this.gameObject.matrix))&&this.canUpdate()&&this.onApplyTransform(this._transformNeedsUpdate?"Marked dirty":"Matrix changed")}canUpdate(){return this._transformNeedsUpdate&&this.activeAndEnabled&&this._lastUpdateFrame!==this.context.time.frame}onApplyTransform(t){var n;if(this.context.time.frameCount===this._lastUpdateFrame)return;this._lastUpdateFrame=this.context.time.frameCount;const e=this.shadowComponent;if(!e)return;this.gameObject.parent?this._parentRectTransform=C.getComponentInParent(this.gameObject.parent,_w):this._parentRectTransform=void 0,this._transformNeedsUpdate=!1,np&&console.warn("RectTransform → ApplyTransform",this.name+" because "+t),this.isRoot()?this.Root.screenspace||(e.rotation.y=Math.PI):(e.matrix.identity(),e.matrixAutoUpdate=!1,en.set(0,0,0),this.applyPivot(en),e.matrix.setPosition(en.x,en.y,0),(this.gameObject.quaternion.x||this.gameObject.quaternion.y||this.gameObject.quaternion.z)&&(id.copy(this.gameObject.quaternion),id.x*=-1,id.z*=-1,Sl.makeRotationFromQuaternion(id),e.matrix.premultiply(Sl)),en.set(0,0,0),this.applyAnchoring(en),(n=this.canvas)!=null&&n.screenspace?en.z+=.1:en.z+=.01,Sl.identity(),Sl.setPosition(en.x,en.y,en.z),e.matrix.premultiply(Sl),e.matrix.scale(this.gameObject.scale)),this.lastMatrix.copy(this.gameObject.matrix);const i=!0;for(const o of Au(this.gameObject,Hi,i,1)){if(o===this||!o.activeAndEnabled)continue;const a=o;a.onParentRectTransformChanged&&a.onParentRectTransformChanged(this)}}applyAnchoring(t){this._lastAnchoring||(this._lastAnchoring=new h.Vector2);const e=this._lastAnchoring.sub(this._anchoredPosition);this.gameObject.position.x+=e.x,this.gameObject.position.y+=e.y,this._lastAnchoring.copy(this._anchoredPosition),t.x+=this._initialPosition.x-this.gameObject.position.x,t.y+=this._initialPosition.y-this.gameObject.position.y,t.z+=this._initialPosition.z-this.gameObject.position.z;const i=this._parentRectTransform;if(i){let n=0;const o=1-this.anchorMax.y-this.anchorMin.y;n-=i.height*.5*o,t.y+=n;let a=0;const l=1-this.anchorMax.x-this.anchorMin.x;a-=i.width*.5*l,t.x+=a}}applyPivot(t){if(this.pivot&&!this.isRoot()){const e=this.pivot.x-.5;t.x-=e*this.sizeDelta.x*this.gameObject.scale.x;const i=this.pivot.y-.5;t.y-=i*this.sizeDelta.y*this.gameObject.scale.y}}getBasicOptions(){const t={width:this.sizeDelta.x,height:this.sizeDelta.y,offset:0,backgroundOpacity:0,borderWidth:0,borderRadius:0,borderOpacity:0,letterSpacing:-.03};return this.ensureValidSize(t),t}ensureValidSize(t,e=1e-4){return t.width<=0&&(t.width=e),t.height<=0&&(t.height=1e-4),t}createNewBlock(t){t={...this.getBasicOptions(),...t},ip&&console.log(this.name,t);const e=new ie.__webpack_exports__Block(t);return this._createdBlocks.push(e),e}createNewText(t){ip&&console.log(t),t={...this.getBasicOptions(),...t},ip&&console.log(this.name,t);const e=new ie.__webpack_exports__Text(t);return this._createdTextBlocks.push(e),e}};let At=_w;uh([p(h.Vector2)],At.prototype,"anchoredPosition",1);uh([p(h.Vector2)],At.prototype,"sizeDelta",2);uh([p(h.Vector2)],At.prototype,"pivot",2);uh([p(h.Vector2)],At.prototype,"anchorMin",2);uh([p(h.Vector2)],At.prototype,"anchorMax",2);var bM=Object.defineProperty,vM=Object.getOwnPropertyDescriptor,yw=(s,t,e,i)=>{for(var n=i>1?void 0:i?vM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&bM(t,e,n),n};class el extends D{constructor(){super(...arguments);r(this,"effectColor");r(this,"effectDistance")}}yw([p(ge)],el.prototype,"effectColor",2);yw([p(h.Vector2)],el.prototype,"effectDistance",2);var wM=Object.defineProperty,xM=Object.getOwnPropertyDescriptor,bw=(s,t,e,i)=>{for(var n=i>1?void 0:i?xM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&wM(t,e,n),n};const nd={backgroundColor:new h.Color(1,1,1),backgroundOpacity:1,borderColor:new h.Color(1,1,1),borderOpacity:1};var kp;const Hl=(kp=class extends Hi{constructor(){super(...arguments);r(this,"_alphaFactor",1);r(this,"sRGBColor",new h.Color(1,0,1));r(this,"raycastTarget",!0);r(this,"uiObject",null);r(this,"_color",null);r(this,"_rect",null);r(this,"_stateManager",null);r(this,"_currentlyCreatingPanel",!1)}get isGraphic(){return!0}get color(){return this._color||(this._color=new ge(1,1,1,1)),this._color}set color(t){(!this._color||this._color.r!==t.r||this._color.g!==t.g||this._color.b!==t.b||this._color.alpha!==t.alpha)&&(this._color||(this._color=new ge(1,1,1,1)),this._color.copy(t),this.onColorChanged())}setAlphaFactor(t){this._alphaFactor=t,this.onColorChanged()}get alphaFactor(){return this._alphaFactor}onColorChanged(){this.uiObject&&(this.sRGBColor.copy(this._color),this.sRGBColor.convertLinearToSRGB(),nd.backgroundColor=this.sRGBColor,nd.backgroundOpacity=this._color.alpha*this._alphaFactor,this.applyEffects(nd,this._alphaFactor),this.uiObject.set(nd),this.markDirty())}get m_Color(){return this._color}get rectTransform(){if(this._rect||(this._rect=C.getComponent(this.gameObject,At)),!this._rect)throw new Error("Not Supported: Make sure to add a RectTransform component before adding a UI Graphic component.");return this._rect}onParentRectTransformChanged(){var t;(t=this.uiObject)==null||t.set({width:this.rectTransform.width,height:this.rectTransform.height}),this.markDirty()}__internalNewInstanceCreated(t){return super.__internalNewInstanceCreated(t),this._rect=null,this.uiObject=null,this._color&&(this._color=this._color.clone()),this}setState(t){this.makePanel(),this.uiObject&&(this.uiObject.setState(t),this==null||this.markDirty())}setupState(t){this.makePanel(),this.uiObject&&(this._stateManager||(this._stateManager=new ie.SimpleStateBehavior(this.uiObject)),this.uiObject.setupState(t.state,t.attributes))}setOptions(t){this.makePanel(),this.uiObject&&this.uiObject.set(t)}awake(){super.awake(),this.makePanel(),la(this,"_color",()=>vP(this,this.onColorChanged))}onEnable(){var t;super.onEnable(),this.uiObject&&((t=this.rectTransform.shadowComponent)==null||t.add(this.uiObject),this.addShadowComponent(this.uiObject,this.rectTransform))}onDisable(){super.onDisable(),this.uiObject&&this.removeShadowComponent()}makePanel(){if(this.uiObject||this._currentlyCreatingPanel)return;this._currentlyCreatingPanel=!0;const t=.015,e={backgroundColor:this.color,backgroundOpacity:this.color.alpha,offset:t};this.onBeforeCreate(e),this.applyEffects(e),this.onCreate(e),this.controlsChildLayout=!1,this._currentlyCreatingPanel=!1,this.onAfterCreated(),this.onColorChanged()}onBeforeCreate(t){}onCreate(t){this.uiObject=this.rectTransform.createNewBlock(t),this.uiObject.name=this.name}onAfterCreated(){}applyEffects(t,e=1){var n;const i=(n=this.gameObject)==null?void 0:n.getComponent(el);i&&(i.effectDistance&&(t.borderWidth=Math.max(Math.abs(i.effectDistance.x),Math.abs(i.effectDistance.y))),i.effectColor&&(t.borderColor=i.effectColor,t.borderOpacity=i.effectColor.alpha*e))}async setTexture(t){if(this.setOptions({backgroundOpacity:0}),t){if(Hl.textureCache.has(t))t=Hl.textureCache.get(t);else if(!t.isRenderTargetTexture){const e=t.clone();e.colorSpace=h.LinearSRGBColorSpace,Hl.textureCache.set(t,e),t=e}this.setOptions({backgroundImage:t,borderRadius:0,backgroundOpacity:this.color.alpha,backgroundSize:"stretch"}),re.NEEDLE_progressive.assignTextureLOD(t,0).then(e=>{e instanceof h.Texture&&(t&&Hl.textureCache.set(t,e),this.setOptions({backgroundImage:e}),this.markDirty())})}else this.setOptions({backgroundImage:void 0,borderRadius:0,backgroundOpacity:this.color.alpha});this.markDirty()}onAfterAddedToScene(){super.onAfterAddedToScene(),this.shadowComponent&&(this.shadowComponent.offset=this.shadowComponent.position.z)}},r(kp,"textureCache",new Map),kp);let Ir=Hl;bw([p(ge)],Ir.prototype,"color",1);bw([p()],Ir.prototype,"raycastTarget",2);class fh extends Ir{constructor(){super(...arguments);r(this,"_flippedObject",!1)}onAfterCreated(){this.uiObject&&!this._flippedObject&&(this._flippedObject=!0,this.uiObject.scale.y*=-1)}}var SM=Object.defineProperty,CM=Object.getOwnPropertyDescriptor,Ts=(s,t,e,i)=>{for(var n=i>1?void 0:i?CM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&SM(t,e,n),n};const No=S("debugtext");var et=(s=>(s[s.UpperLeft=0]="UpperLeft",s[s.UpperCenter=1]="UpperCenter",s[s.UpperRight=2]="UpperRight",s[s.MiddleLeft=3]="MiddleLeft",s[s.MiddleCenter=4]="MiddleCenter",s[s.MiddleRight=5]="MiddleRight",s[s.LowerLeft=6]="LowerLeft",s[s.LowerCenter=7]="LowerCenter",s[s.LowerRight=8]="LowerRight",s))(et||{}),vw=(s=>(s[s.Normal=0]="Normal",s[s.Bold=1]="Bold",s[s.Italic=2]="Italic",s[s.BoldAndItalic=3]="BoldAndItalic",s))(vw||{});class Dt extends Ir{constructor(){super(...arguments);r(this,"alignment",0);r(this,"verticalOverflow",0);r(this,"horizontalOverflow",0);r(this,"lineSpacing",1);r(this,"supportRichText",!1);r(this,"font");r(this,"fontStyle",0);r(this,"sRGBTextColor",new h.Color(1,0,1));r(this,"_text","");r(this,"_fontSize",12);r(this,"_textMeshUi",null);r(this,"_didHandleTextRenderOnTop",!1)}setAlphaFactor(e){var i;super.setAlphaFactor(e),(i=this.uiObject)==null||i.set({fontOpacity:this.color.alpha*this.alphaFactor}),this.markDirty()}get text(){return this._text}set text(e){e!==this._text&&(this._text=e,this.feedText(this.text,this.supportRichText),this.markDirty())}set_text(e){this.text=e}get fontSize(){return this._fontSize}set fontSize(e){var i;this._fontSize=e,(i=this.uiObject)==null||i.set({fontSize:e})}onColorChanged(){var e;this.sRGBTextColor.copy(this.color),this.sRGBTextColor.convertLinearToSRGB(),(e=this.uiObject)==null||e.set({color:this.sRGBTextColor,fontOpacity:this.color.alpha})}onParentRectTransformChanged(){super.onParentRectTransformChanged(),this.uiObject&&this.updateOverflow()}onBeforeCanvasRender(e){this.updateOverflow()}updateOverflow(){var i;const e=(i=this.uiObject)==null?void 0:i._overflow;e&&(e._needsUpdate=!0)}onCreate(e){No&&console.log(this),this.horizontalOverflow==1&&(e.whiteSpace="pre"),this.verticalOverflow==0&&(this.context.renderer.localClippingEnabled=!0,e.overflow="hidden"),this.horizontalOverflow==1&&this.verticalOverflow==0,e.lineHeight=this.lineSpacing,delete e.backgroundOpacity,delete e.backgroundColor,No&&(e.backgroundColor=16750848,e.backgroundOpacity=.5);const i=this.rectTransform;e={...e,...this.getTextOpts()},this.getAlignment(e),No&&(e.backgroundColor=Math.random()*16777215,e.backgroundOpacity=.1),this.uiObject=i.createNewText(e),this.feedText(this.text,this.supportRichText)}onAfterAddedToScene(){super.onAfterAddedToScene(),this.handleTextRenderOnTop()}getTextOpts(){const e=this.fontSize,i={color:this.color,fontOpacity:this.color.alpha,fontSize:e,fontKerning:"normal"};return this.setFont(i,this.fontStyle),i}onEnable(){var e;super.onEnable(),this._didHandleTextRenderOnTop=!1,this.uiObject&&this.uiObject.addAfterUpdate(()=>{this.setShadowComponentOwner(this.uiObject),this.markDirty()}),setTimeout(()=>this.markDirty(),10),(e=this.canvas)==null||e.registerEventReceiver(this)}onDisable(){var e;super.onDisable(),(e=this.canvas)==null||e.unregisterEventReceiver(this)}getAlignment(e){switch(e.flexDirection="column",this.alignment){case 0:case 3:case 6:e.textAlign="left";break;case 1:case 4:case 7:e.textAlign="center";break;case 2:case 5:case 8:e.textAlign="right";break}switch(this.alignment){default:case 0:case 1:case 2:e.alignItems="start";break;case 3:case 4:case 5:e.alignItems="center";break;case 6:case 7:case 8:e.alignItems="end";break}return e}feedText(e,i){var n,o,a;if(No&&console.log("feedText",this.uiObject,e,i),!!this.uiObject)if(this._textMeshUi||(this._textMeshUi=[]),this.uiObject.children.length=0,!i||e.length===0)this.uiObject.textContent=e;else{let l=this.getNextTag(e);if(l){if(l.startIndex>0){for(let u=this.uiObject.children.length-1;u>=0;u--){const f=this.uiObject.children[u];f.isUI&&(this.uiObject.remove(f),f.clear())}const d=new ie.__webpack_exports__Inline({textContent:e.substring(0,l.startIndex),color:"inherit"});this.uiObject.add(d)}}else{this.uiObject.textContent="",this.setOptions({textContent:e});return}const c=[];for(;l;){const d=this.getNextTag(e,l.endIndex),u={fontFamily:(n=this.uiObject)==null?void 0:n.get("fontFamily"),color:"inherit",textContent:""};if(d){u.textContent=this.getText(e,l,d),this.handleTag(l,u,c);const f=new ie.__webpack_exports__Inline(u);(o=this.uiObject)==null||o.add(f)}else{u.textContent=e.substring(l.endIndex),this.handleTag(l,u,c);const f=new ie.__webpack_exports__Inline(u);(a=this.uiObject)==null||a.add(f)}l=d}}}handleTextRenderOnTop(){this._didHandleTextRenderOnTop||(this._didHandleTextRenderOnTop=!0,this.startCoroutine(this.renderOnTopCoroutine()))}*renderOnTopCoroutine(){if(!this.canvas)return;const e=[],i=this.canvas,n={renderOnTop:i.renderOnTop,depthWrite:i.depthWrite,doubleSided:i.doubleSided};for(;;){let o=!1;if(this._textMeshUi)for(let a=0;a<this._textMeshUi.length;a++){if(e[a]===!0)continue;o=!0;const l=this._textMeshUi[a];l.textContent&&(tu(l,n),e[a]=!0)}if(!o)break;yield}}handleTag(e,i,n){if(!e.isEndTag){if(e.type.includes("color")){const o=new sp(e,{color:i.color});if(n.push(o),e.type.length>6){const a=parseInt("0x"+e.type.substring(7));i.color=a}else i.color=new h.Color(1,1,1)}else if(e.type=="b"){this.setFont(i,1);const o=new sp(e,{fontWeight:700});n.push(o)}else if(e.type=="i"){this.setFont(i,2);const o=new sp(e,{fontStyle:"italic"});n.push(o)}}}getText(e,i,n){return e.substring(i.endIndex,n.startIndex)}getNextTag(e,i=0){const n=e.indexOf("<",i),o=e.indexOf(">",n);if(n>=0&&o>=0){const a=e.substring(n+1,o);return{type:a,startIndex:n,endIndex:o+1,isEndTag:a.startsWith("/")}}return null}setFont(e,i){if(!this.font)return;const n=this.font,o=this.getFamilyNameWithCorrectSuffix(n,i);No&&console.log("Selected font family:"+o);let a=ie.__webpack_exports__FontLibrary.getFontFamily(o);switch(a||(a=ie.__webpack_exports__FontLibrary.addFontFamily(o)),e.fontFamily=a,i){default:case 0:e.fontWeight=400,e.fontStyle="normal";break;case 1:e.fontWeight=700,e.fontStyle="normal";break;case 2:e.fontWeight=400,e.fontStyle="italic";break;case 3:e.fontStyle="italic",e.fontWeight=400}let l=a.getVariant(e.fontWeight,e.fontStyle);if(!l){let c=o;c!=null&&c.endsWith("-msdf.json")||(c+="-msdf.json");let d=o;d!=null&&d.endsWith(".png")||(d+=".png"),l=a.addVariant(e.fontWeight,e.fontStyle,c,d),l==null||l.addEventListener("ready",()=>{this.markDirty()})}}getFamilyNameWithCorrectSuffix(e,i){var u;const n=e.lastIndexOf("-");if(n<0)return e;const o=(u=e.substring(n+1))==null?void 0:u.toLowerCase();if(PM.includes(o))return No&&console.warn("Unsupported font style: "+o),e;const a=e.lastIndexOf("/");let l=e;a>=0&&(l=l.substring(a+1));const c=l[0]===l[0].toUpperCase(),d=e.substring(0,n);switch(No&&console.log("Select font: ",e,vw[i],l,c,d),i){case 0:return c?d+"-Regular":d+"-regular";case 1:return c?d+"-Bold":d+"-bold";case 2:return c?d+"-Italic":d+"-italic";case 3:return c?d+"-BoldItalic":d+"-bolditalic";default:return e}}}Ts([p()],Dt.prototype,"alignment",2);Ts([p()],Dt.prototype,"verticalOverflow",2);Ts([p()],Dt.prototype,"horizontalOverflow",2);Ts([p()],Dt.prototype,"lineSpacing",2);Ts([p()],Dt.prototype,"supportRichText",2);Ts([p(URL)],Dt.prototype,"font",2);Ts([p()],Dt.prototype,"fontStyle",2);Ts([p()],Dt.prototype,"text",1);Ts([p()],Dt.prototype,"fontSize",1);class sp{constructor(t,e){r(this,"tag");r(this,"previousValues");this.tag=t,this.previousValues=e}}const PM=["medium","mediumitalic","black","blackitalic","thin","thinitalic","extrabold","light","lightitalic","semibold"];class eo{constructor(t){r(this,"id");r(this,"content","");r(this,"font",[]);r(this,"pointSize",144);r(this,"width");r(this,"height");r(this,"depth");r(this,"wrapMode");r(this,"horizontalAlignment");r(this,"verticalAlignment");r(this,"material");this.id=t}static getId(){return this.global_id++}setDepth(t){return this.depth=t,this}setPointSize(t){return this.pointSize=t,this}setHorizontalAlignment(t){return this.horizontalAlignment=t,this}setVerticalAlignment(t){return this.verticalAlignment=t,this}writeTo(t,e){var n;e.beginBlock(`def Preliminary_Text "${this.id}"`,"(",!1),e.appendLine('prepend apiSchemas = ["MaterialBindingAPI"]'),e.closeBlock(")"),e.beginBlock(),this.content&&e.appendLine(`string content = "${this.content}"`),(!this.font||this.font.length<=0)&&(this.font||(this.font=[]),(n=this.font)==null||n.push("sans-serif"));const i=this.font.map(o=>`"${o}"`).join(", ");e.appendLine(`string[] font = [ ${i} ]`),e.appendLine(`double pointSize = ${this.pointSize}`),typeof this.width=="number"&&e.appendLine(`double width = ${this.width}`),typeof this.height=="number"&&e.appendLine(`double height = ${this.height}`),typeof this.depth=="number"&&e.appendLine(`double depth = ${this.depth}`),this.wrapMode&&e.appendLine(`token wrapMode = "${this.wrapMode}"`),this.horizontalAlignment&&e.appendLine(`token horizontalAlignment = "${this.horizontalAlignment}"`),this.verticalAlignment&&e.appendLine(`token verticalAlignment = "${this.verticalAlignment}"`),this.material!==void 0&&e.appendLine(`rel material:binding = </StageRoot/Materials/${Fg(this.material)}>`),e.closeBlock()}}r(eo,"global_id",0);class Qu{static singleLine(t,e,i){const n=new eo("text_"+eo.getId());return n.content=t,e&&(n.pointSize=e),i&&(n.depth=i),n}static multiLine(t,e,i,n,o,a){const l=new eo("text_"+eo.getId());return l.content=t,l.width=e,l.height=i,l.horizontalAlignment=n,l.verticalAlignment=o,a!==void 0&&(l.wrapMode=a),l}}const OM=new h.Matrix4().makeRotationY(Math.PI),MM=new h.Matrix4().makeScale(-1,1,-1);class ph{get extensionName(){return"text"}exportText(t,e,i){const n=C.getComponent(t,Dt);if(!n)return;const o=C.getComponent(t,At);let a=100,l=100;o&&(a=o.width,l=o.height);const c=OM.clone();o&&c.premultiply(MM),e.setMatrix(c);const d=n.color.clone();e.material=new h.MeshStandardMaterial({color:d,emissive:d}),e.addEventListener("serialize",(u,f)=>{let m=n.text;m=m.replace(/\r/g,""),m=m.replace(/\n/g,"\\n");const g=Qu.multiLine(m,a,l,"center","bottom","flowing");this.setTextAlignment(g,n.alignment),this.setOverflow(g,n),e.material&&(g.material=e.material),g.pointSize=this.convertToTextSize(n.fontSize),g.depth=.001,g.writeTo(void 0,u)})}convertToTextSize(t){return 1/.0502*144*t}setOverflow(t,e){e.horizontalOverflow?t.wrapMode="singleLine":t.wrapMode="flowing"}setTextAlignment(t,e){switch(e){case et.LowerLeft:case et.MiddleLeft:case et.UpperLeft:t.horizontalAlignment="left";break;case et.LowerCenter:case et.MiddleCenter:case et.UpperCenter:t.horizontalAlignment="center";break;case et.LowerRight:case et.MiddleRight:case et.UpperRight:t.horizontalAlignment="right";break}switch(e){case et.LowerLeft:case et.LowerCenter:case et.LowerRight:t.verticalAlignment="bottom";break;case et.MiddleLeft:case et.MiddleCenter:case et.MiddleRight:t.verticalAlignment="middle";break;case et.UpperLeft:case et.UpperCenter:case et.UpperRight:t.verticalAlignment="top";break}}}var RM=Object.defineProperty,kM=Object.getOwnPropertyDescriptor,Ye=(s,t,e,i)=>{for(var n=i>1?void 0:i?kM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&RM(t,e,n),n};const nb=S("debuguilayout");class Po{constructor(){r(this,"left",0);r(this,"right",0);r(this,"top",0);r(this,"bottom",0)}get vertical(){return this.top+this.bottom}get horizontal(){return this.left+this.right}}Ye([p()],Po.prototype,"left",2);Ye([p()],Po.prototype,"right",2);Ye([p()],Po.prototype,"top",2);Ye([p()],Po.prototype,"bottom",2);class ki extends D{constructor(){super(...arguments);r(this,"_rectTransform",null);r(this,"_needsUpdate",!1);r(this,"childAlignment",0);r(this,"reverseArrangement",!1);r(this,"spacing",0);r(this,"padding");r(this,"minWidth",0);r(this,"minHeight",0);r(this,"flexibleHeight",0);r(this,"flexibleWidth",0);r(this,"preferredHeight",0);r(this,"preferredWidth",0)}get rectTransform(){return this._rectTransform}onParentRectTransformChanged(e){this._needsUpdate=!0}get isDirty(){return this._needsUpdate}get isLayoutGroup(){return!0}updateLayout(){this._rectTransform&&(nb&&console.warn("Layout Update",this.context.time.frame,this.name),this._needsUpdate=!1,this.onCalculateLayout(this._rectTransform))}start(){this._needsUpdate=!0}onEnable(){nb&&console.log(this.name,this),this._rectTransform=this.gameObject.getComponent(At);const e=this.gameObject.getComponentInParent(Ct);e&&e.registerLayoutGroup(this),this._needsUpdate=!0}onDisable(){const e=this.gameObject.getComponentInParent(Ct);e&&e.unregisterLayoutGroup(this)}set m_Spacing(e){e!==this.spacing&&(this._needsUpdate=!0,this.spacing=e)}get m_Spacing(){return this.spacing}}Ye([p()],ki.prototype,"childAlignment",2);Ye([p()],ki.prototype,"reverseArrangement",2);Ye([p()],ki.prototype,"spacing",2);Ye([p(Po)],ki.prototype,"padding",2);Ye([p()],ki.prototype,"minWidth",2);Ye([p()],ki.prototype,"minHeight",2);Ye([p()],ki.prototype,"flexibleHeight",2);Ye([p()],ki.prototype,"flexibleWidth",2);Ye([p()],ki.prototype,"preferredHeight",2);Ye([p()],ki.prototype,"preferredWidth",2);class Oo extends ki{constructor(){super(...arguments);r(this,"childControlHeight",!0);r(this,"childControlWidth",!0);r(this,"childForceExpandHeight",!1);r(this,"childForceExpandWidth",!1);r(this,"childScaleHeight",!1);r(this,"childScaleWidth",!1)}onCalculateLayout(e){var I;const i=this.primaryAxis,n=e.width;let o=n;const a=e.height;let l=a;o-=this.padding.horizontal,l-=this.padding.vertical,i==="x"?this.padding.horizontal:this.padding.vertical;const c=i==="x",d=c?"y":"x",u=c?this.childControlWidth:this.childControlHeight,f=c?this.childControlHeight:this.childControlWidth,m=c?this.childForceExpandWidth:this.childForceExpandHeight,g=c?this.childForceExpandHeight:this.childForceExpandWidth,_=c?l:o,y=c?n:a,b=.5*(c?this.childAlignment%3:Math.floor(this.childAlignment/3));let v=0;c?v+=this.padding.left:v+=this.padding.top;let x=0,O=0;for(let E=0;E<this.gameObject.children.length;E++){const j=this.gameObject.children[E],F=C.getComponent(j,At);F!=null&&F.activeAndEnabled&&(O+=1,c?x+=F.width:x+=F.height)}let k=0;const M=this.spacing*(O-1);if(m||u){let E=0;c?E=o-=M:E=l-=M,O>0&&(k=E/O)}let R=0;R+=this.padding.left,R-=this.padding.right,b!==0&&(v=y-x,v*=b,v-=M*b,c?(v-=this.padding.right*b,v+=this.padding.left*(1-b),v<this.padding.left&&(v=this.padding.left)):(v-=this.padding.bottom*b,v+=this.padding.top*(1-b),v<this.padding.top&&(v=this.padding.top)));let A=1;for(let E=0;E<this.gameObject.children.length;E++){const j=this.gameObject.children[E],F=C.getComponent(j,At);if(F!=null&&F.activeAndEnabled){(I=F.pivot)==null||I.set(.5,.5),F.anchorMin.set(0,1),F.anchorMax.set(0,1);const G=n*.5+R*.5;F.anchoredPosition.x!==G&&(F.anchoredPosition.x=G);const T=a*-.5;F.anchoredPosition.y!==T&&(F.anchoredPosition.y=T),g&&f&&F.sizeDelta[d]!==_&&(F.sizeDelta[d]=_),m&&u&&F.sizeDelta[i]!==k&&(F.sizeDelta[i]=k);const L=c?F.width:F.height,$=L*.5;if(v+=$,m){const J=k*A-k*.5;J>v&&(v=J-k*.5+L+this.padding.left,v-=$)}let X=v;i==="y"&&(X=-X),F.anchoredPosition[i]!==X&&(F.anchoredPosition[i]=X),v+=$,v+=this.spacing,A+=1}}}}Ye([p()],Oo.prototype,"childControlHeight",2);Ye([p()],Oo.prototype,"childControlWidth",2);Ye([p()],Oo.prototype,"childForceExpandHeight",2);Ye([p()],Oo.prototype,"childForceExpandWidth",2);Ye([p()],Oo.prototype,"childScaleHeight",2);Ye([p()],Oo.prototype,"childScaleWidth",2);class Hg extends Oo{get primaryAxis(){return"y"}}class Gg extends Oo{get primaryAxis(){return"x"}}class qg extends ki{onCalculateLayout(){}}var TM=Object.defineProperty,EM=Object.getOwnPropertyDescriptor,Hn=(s,t,e,i)=>{for(var n=i>1?void 0:i?EM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&TM(t,e,n),n},ww=(s=>(s[s.ScreenSpaceOverlay=0]="ScreenSpaceOverlay",s[s.ScreenSpaceCamera=1]="ScreenSpaceCamera",s[s.WorldSpace=2]="WorldSpace",s[s.Undefined=-1]="Undefined",s))(ww||{});const op=S("debuguilayout"),xw=class extends ih{constructor(){super(...arguments);r(this,"_renderOnTop");r(this,"_depthWrite",!1);r(this,"_doubleSided",!0);r(this,"_castShadows",!1);r(this,"_receiveShadows",!1);r(this,"_renderMode",-1);r(this,"_rootCanvas");r(this,"_scaleFactor",1);r(this,"worldCamera");r(this,"planeDistance",-1);r(this,"_boundRenderSettingsChanged",this.onRenderSettingsChanged.bind(this));r(this,"previousParent",null);r(this,"_lastMatrixWorld",null);r(this,"_rectTransforms",[]);r(this,"_layoutGroups",new Map);r(this,"_receivers",[]);r(this,"onBeforeRenderRoutine",()=>{var t,e,i,n;if(this.previousParent=this.gameObject.parent,((t=this.context.xr)!=null&&t.isVR||(e=this.context.xr)!=null&&e.isPassThrough)&&this.screenspace){this.gameObject.visible=!1,this.gameObject.removeFromParent();return}this.renderOnTop||this.screenspace?this.gameObject.removeFromParent():(this.onUpdateRenderMode(),this.handleLayoutUpdates(),(i=this.shadowComponent)==null||i.updateMatrixWorld(!0),(n=this.shadowComponent)==null||n.updateWorldMatrix(!0,!0),this.invokeBeforeRenderEvents(),qt.ensureUpdateMeshUI(ie.ThreeMeshUI,this.context))});r(this,"onAfterRenderRoutine",()=>{var t,e,i,n,o;if(((t=this.context.xr)!=null&&t.isVR||(e=this.context.xr)!=null&&e.isPassThrough)&&this.screenspace){(i=this.previousParent)==null||i.add(this.gameObject);return}if((this.screenspace||this.renderOnTop)&&this.previousParent&&this.context.mainCamera){if(this.screenspace){const c=this.context.mainCamera;c==null||c.add(this.gameObject)}else this.previousParent.add(this.gameObject);const a=this.context.renderer.autoClear,l=this.context.renderer.autoClearColor;this.context.renderer.autoClear=!1,this.context.renderer.autoClearColor=!1,this.context.renderer.clearDepth(),this.onUpdateRenderMode(!0),this.handleLayoutUpdates(),(n=this.shadowComponent)==null||n.updateMatrixWorld(!0),this.invokeBeforeRenderEvents(),qt.ensureUpdateMeshUI(ie.ThreeMeshUI,this.context,!0),this.context.renderer.render(this.gameObject,this.context.mainCamera),this.context.renderer.autoClear=a,this.context.renderer.autoClearColor=l,this.previousParent.add(this.gameObject)}(o=this._lastMatrixWorld)==null||o.copy(this.gameObject.matrixWorld)});r(this,"_updateRenderSettingsRoutine");r(this,"_activeRenderMode",-1);r(this,"_lastWidth",-1);r(this,"_lastHeight",-1)}get isCanvas(){return!0}get screenspace(){return this.renderMode!==2}set renderOnTop(t){t!==this._renderOnTop&&(this._renderOnTop=t,this.onRenderSettingsChanged())}get renderOnTop(){return this._renderOnTop!==void 0?this._renderOnTop:!!(this.screenspace&&this._renderMode===0)}set depthWrite(t){this._depthWrite!==t&&(this._depthWrite=t,this.onRenderSettingsChanged())}get depthWrite(){return this._depthWrite}set doubleSided(t){this._doubleSided!==t&&(this._doubleSided=t,this.onRenderSettingsChanged())}get doubleSided(){return this._doubleSided}set castShadows(t){this._castShadows!==t&&(this._castShadows=t,this.onRenderSettingsChanged())}get castShadows(){return this._castShadows}set receiveShadows(t){this._receiveShadows!==t&&(this._receiveShadows=t,this.onRenderSettingsChanged())}get receiveShadows(){return this._receiveShadows}get renderMode(){return this._renderMode}set renderMode(t){this._renderMode!==t&&(this._renderMode=t,this.onRenderSettingsChanged())}set rootCanvas(t){this._rootCanvas instanceof xw||(this._rootCanvas=t)}get rootCanvas(){return this._rootCanvas}get scaleFactor(){return this._scaleFactor}set scaleFactor(t){this._scaleFactor=t}awake(){var t;this.shadowComponent=this.gameObject,this.previousParent=this.gameObject.parent,op&&console.log("Canvas.Awake()",((t=this.previousParent)==null?void 0:t.name)+"/"+this.gameObject.name),super.awake()}start(){this.onUpdateRenderMode()}onEnable(){super.onEnable(),this._updateRenderSettingsRoutine=void 0,this._lastMatrixWorld=new h.Matrix4,this.onUpdateRenderMode(),document.addEventListener("resize",this._boundRenderSettingsChanged),this.context.pre_render_callbacks.push(this.onBeforeRenderRoutine),this.context.post_render_callbacks.push(this.onAfterRenderRoutine)}onDisable(){super.onDisable(),document.removeEventListener("resize",this._boundRenderSettingsChanged);const t=this.context.pre_render_callbacks.indexOf(this.onBeforeRenderRoutine);t!==-1&&this.context.pre_render_callbacks.splice(t,1);const e=this.context.post_render_callbacks.indexOf(this.onAfterRenderRoutine);e!==-1&&this.context.post_render_callbacks.splice(e,1)}registerTransform(t){this._rectTransforms.push(t)}unregisterTransform(t){const e=this._rectTransforms.indexOf(t);e!==-1&&this._rectTransforms.splice(e,1)}registerLayoutGroup(t){const e=t.gameObject;this._layoutGroups.set(e,t)}unregisterLayoutGroup(t){const e=t.gameObject;this._layoutGroups.delete(e)}registerEventReceiver(t){this._receivers.push(t)}unregisterEventReceiver(t){const e=this._receivers.indexOf(t);e!==-1&&this._receivers.splice(e,1)}async onEnterXR(t){this.screenspace?(t.xr.isVR||t.xr.isPassThrough)&&(this.gameObject.visible=!1):(this.gameObject.visible=!1,await Vc(1).then(()=>{this.gameObject.visible=!0}))}onLeaveXR(t){this.screenspace&&(t.xr.isVR||t.xr.isPassThrough)&&(this.gameObject.visible=!0)}invokeBeforeRenderEvents(){var t;for(const e of this._receivers)(t=e.onBeforeCanvasRender)==null||t.call(e,this)}handleLayoutUpdates(){this._lastMatrixWorld===null&&(this._lastMatrixWorld=new h.Matrix4);const t=!this._lastMatrixWorld.equals(this.gameObject.matrixWorld);op&&t&&console.log("Canvas Layout changed",this.context.time.frameCount,this.name);const e=!1;for(const i of this._rectTransforms){t&&i.markDirty();let n=this._layoutGroups.get(i.gameObject);i.isDirty&&!n&&(n=i.gameObject.getComponentInParent(ki)),(i.isDirty||n!=null&&n.isDirty)&&(op&&!e&&console.log("CANVAS UPDATE ### "+i.name+" ##################################### "+this.context.time.frame),n==null||n.updateLayout(),i.updateTransform())}}applyRenderSettings(){this.onRenderSettingsChanged()}onRenderSettingsChanged(){this._updateRenderSettingsRoutine||(this._updateRenderSettingsRoutine=this.startCoroutine(this._updateRenderSettingsDelayed(),ve.OnBeforeRender))}*_updateRenderSettingsDelayed(){if(yield,this._updateRenderSettingsRoutine=void 0,this.shadowComponent){this.onUpdateRenderMode(),tu(this.shadowComponent,this);for(const t of C.getComponentsInChildren(this.gameObject,Hi))tu(t.shadowComponent,this)}}onUpdateRenderMode(t=!1){if(!t&&this._renderMode===this._activeRenderMode&&this._lastWidth===this.context.domWidth&&this._lastHeight===this.context.domHeight)return;this._activeRenderMode=this._renderMode;let e=this.context.mainCameraComponent,i=10;switch(e&&e.nearClipPlane>0&&e.farClipPlane>0&&(i=z.lerp(e.nearClipPlane,e.farClipPlane,.01)),this._renderMode===1&&(this.worldCamera&&(e=this.worldCamera),this.planeDistance>0&&(i=this.planeDistance)),this._renderMode){case 0:case 1:if(this._lastWidth=this.context.domWidth,this._lastHeight=this.context.domHeight,!e)return;const n=i+.01;this.gameObject.position.x=0,this.gameObject.position.y=0,this.gameObject.position.z=-n,this.gameObject.quaternion.identity();const o=this.gameObject.getComponent(At);let a=!1;o.sizeDelta.x!==this.context.domWidth&&(a=!0),o.sizeDelta.y!==this.context.domHeight&&(a=!0);const l=e.fieldOfView*Math.PI/180,c=2*Math.tan(l/2)*Math.abs(n);this.gameObject.scale.x=c/this.context.domHeight,this.gameObject.scale.y=c/this.context.domHeight,this.gameObject.scale.z=.01,a&&(o.sizeDelta.x=this.context.domWidth,o.sizeDelta.y=this.context.domHeight,o==null||o.markDirty());break;case 2:this._lastWidth=-1,this._lastHeight=-1;break}}};let Ct=xw;Hn([p()],Ct.prototype,"renderOnTop",1);Hn([p()],Ct.prototype,"depthWrite",1);Hn([p()],Ct.prototype,"doubleSided",1);Hn([p()],Ct.prototype,"castShadows",1);Hn([p()],Ct.prototype,"receiveShadows",1);Hn([p()],Ct.prototype,"renderMode",1);Hn([p(Ct)],Ct.prototype,"rootCanvas",1);Hn([p()],Ct.prototype,"scaleFactor",1);Hn([p(be)],Ct.prototype,"worldCamera",2);Hn([p()],Ct.prototype,"planeDistance",2);var AM=Object.defineProperty,DM=Object.getOwnPropertyDescriptor,Xg=(s,t,e,i)=>{for(var n=i>1?void 0:i?DM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&AM(t,e,n),n};class uo extends D{constructor(){super(...arguments);r(this,"_alpha",1);r(this,"interactable",!0);r(this,"blocksRaycasts",!0);r(this,"_isDirty",!1);r(this,"_buffer",[])}get alpha(){return this._alpha}set alpha(e){e!==this._alpha&&(this._alpha=e,this.markDirty())}get isCanvasGroup(){return!0}markDirty(){this._isDirty||(this._isDirty=!0,this.startCoroutine(this.applyChangesDelayed(),ve.OnBeforeRender))}*applyChangesDelayed(){this._isDirty=!1,this.applyChangesNow()}applyChangesNow(){this._buffer.length=0;for(const e of C.getComponentsInChildren(this.gameObject,Hi,this._buffer)){const i=e;i.setAlphaFactor&&i.setAlphaFactor(this._alpha)}}}Xg([p()],uo.prototype,"alpha",1);Xg([p()],uo.prototype,"interactable",2);Xg([p()],uo.prototype,"blocksRaycasts",2);class Yu{get extensionName(){return"tmui"}onExportObject(t,e,i){const n=C.getComponent(t,Ct);if(n&&n.enabled&&n.renderMode===ww.WorldSpace){const o=new ph,a=C.getComponent(t,At),l=C.getComponent(t,uo),c=new Array;if(a){if(!C.isActiveSelf(t)){const f=C.isActiveSelf(t);C.setActive(t,!0),a.onEnable(),a.updateTransform(),c.push(()=>{a.onDisable(),C.setActive(t,f)})}t.traverse(f=>{if(!C.isActiveInHierarchy(f)){const m=C.isActiveSelf(f);C.setActive(f,!0);const g=C.getComponent(f,Hi);g&&(g.onEnable(),c.push(()=>{g.onDisable()}));const _=C.getComponent(f,At);_&&(_.onEnable(),_.updateTransform(),_.onApplyTransform(),c.push(()=>{_.onDisable()}));const y=C.getComponent(f,Dt);y&&(y.onEnable(),c.push(()=>{y.onDisable()})),c.push(()=>{C.setActive(f,m)})}}),a.width,a.height;const d=wt.createEmpty(),u=a.shadowComponent;if(e.add(d),u){const f=u.matrix;d.setMatrix(f);const m=new Map,g=new Map;m.set(u,d),g.set(u,l?l.alpha:1),u.traverse(_=>{if(_===u)return;const y=wt.createEmpty();y.setMatrix(_.matrix);const b=_.parent,v=!!b&&typeof b.textContent=="string"&&b.textContent.length>0;let x=g.get(b)||1;const O=C.getComponent(_,uo);if(O&&(x*=O.alpha),_ instanceof h.Mesh&&v){const M=_[Ni];M?o.exportText(M.gameObject,y,i):console.error("Error when exporting UI: shadow component owner not found. This is likely a bug.",_)}if(_ instanceof h.Mesh&&!v){const M=_.geometry.clone();M.scale(1,1,-1),this.flipWindingOrder(M),y.geometry=M;const R=new h.Color,A=_.material.opacity;R.copy(_.material.color),y.material=new h.MeshBasicMaterial({color:R,opacity:A*x,map:_.material.map,transparent:!0})}m.set(_,y),g.set(_,x);const k=m.get(b);if(!k){console.error("Error when exporting UI: shadow component parent not found!",_,_.parent);return}k.add(y)})}}for(const d of c)d()}}flipWindingOrder(t){const e=t.index.array;for(let i=0,n=e.length/3;i<n;i++){const o=e[i*3];e[i*3]=e[i*3+2],e[i*3+2]=o}t.index.needsUpdate=!0}}const R_=class{constructor(){r(this,"_quicklookButton");r(this,"_arButton");r(this,"_vrButton");r(this,"_sendToQuestButton")}static create(){return new R_}static getOrCreate(){return this._instance||(this._instance=this.create()),this._instance}get isSecureConnection(){return window.location.protocol==="https:"}get quicklookButton(){return this._quicklookButton}get arButton(){return this._arButton}get vrButton(){return this._vrButton}get sendToQuestButton(){return this._sendToQuestButton}get qrButton(){return an.getOrCreate().createQRCode()}createQuicklookButton(){if(this._quicklookButton)return this._quicklookButton;const t=document.createElement("button");this._quicklookButton=t,t.dataset.needle="quicklook-button";const e=exports.DeviceUtilities.supportsQuickLookAR();t.innerText="View in AR",t.prepend(bt("view_in_ar"));let i=!1,n=null;return t.addEventListener("click",()=>{n=ku(Ie),n||(i=!0,n=new Ie),i&&(n.objectToExport=Q.Current.scene),n?(t.classList.add("this-mode-is-requested"),n.exportAndOpen().then(()=>{t.classList.remove("this-mode-is-requested")}).catch(o=>{t.classList.remove("this-mode-is-requested"),console.error(o)})):console.warn("No USDZExporter component found in the scene")}),this.hideElementDuringXRSession(t),t}createARButton(t){var n;if(this._arButton)return this._arButton;const e="immersive-ar",i=document.createElement("button");return this._arButton=i,i.classList.add("webxr-button"),i.dataset.needle="webxr-ar-button",i.innerText="Enter AR",i.prepend(bt("view_in_ar")),i.title="Click to start an AR session",i.addEventListener("click",()=>q.start(e,t)),this.updateSessionSupported(i,e),this.listenToXRSessionState(i,e),this.hideElementDuringXRSession(i),this.isSecureConnection||(i.disabled=!0,i.title="WebXR requires a secure connection (HTTPS)"),exports.DeviceUtilities.isMozillaXR()||(n=navigator.xr)==null||n.addEventListener("devicechange",()=>this.updateSessionSupported(i,e)),i}createVRButton(t){var n;if(this._vrButton)return this._vrButton;const e="immersive-vr",i=document.createElement("button");return this._vrButton=i,i.classList.add("webxr-button"),i.dataset.needle="webxr-vr-button",i.innerText="Enter VR",i.prepend(bt("panorama_photosphere")),i.title="Click to start a VR session",i.addEventListener("click",()=>q.start(e,t)),this.updateSessionSupported(i,e),this.listenToXRSessionState(i,e),this.hideElementDuringXRSession(i),this.isSecureConnection||(i.disabled=!0,i.title="WebXR requires a secure connection (HTTPS)"),exports.DeviceUtilities.isMozillaXR()||(n=navigator.xr)==null||n.addEventListener("devicechange",()=>this.updateSessionSupported(i,e)),i}createSendToQuestButton(){var i;if(this._sendToQuestButton)return this._sendToQuestButton;const t="https://oculus.com/open_url/?url=",e=document.createElement("button");return this._sendToQuestButton=e,e.dataset.needle="webxr-sendtoquest-button",e.innerText="Open on Quest",e.prepend(bt("share_windows")),e.title="Click to send this page to the Oculus Browser on your Quest",e.addEventListener("click",()=>{const n=encodeURIComponent(window.location.href),o=t+n;window.open(o)==null&&Ee("This page doesn't allow popups. Please paste "+o+" into your browser.")}),this.listenToXRSessionState(e),this.hideElementDuringXRSession(e),exports.DeviceUtilities.isMozillaXR()||(i=navigator.xr)==null||i.addEventListener("devicechange",()=>{var n;(n=navigator.xr)!=null&&n.isSessionSupported("immersive-vr")?e.style.display="none":e.style.display=""}),e}createQRCode(){return an.getOrCreate().createQRCode()}updateSessionSupported(t,e){if(!("xr"in navigator)){t.style.display="none";return}q.isSessionSupported(e).then(i=>{t.style.display=i?"":"none",B()&&!i&&console.log('[WebXR] "'+e+'" is not supported on this device – make sure your server runs using HTTPS and you have a device connected that supports '+e)})}hideElementDuringXRSession(t){Pu(e=>{t["previous-display"]=t.style.display,t.style.display="none"}),Xm(e=>{t["previous-display"]!=null&&(t.style.display=t["previous-display"])})}listenToXRSessionState(t,e){e&&(q.onSessionRequestStart(i=>{i.mode===e?t.classList.add("this-mode-is-requested"):(t["was-disabled"]=t.disabled,t.disabled=!0,t.classList.add("other-mode-is-requested"))}),q.onSessionRequestEnd(i=>{t.classList.remove("this-mode-is-requested"),t.classList.remove("other-mode-is-requested"),t.disabled=t["was-disabled"]}))}};let ws=R_;r(ws,"_instance");var LM=Object.defineProperty,IM=Object.getOwnPropertyDescriptor,dt=(s,t,e,i)=>{for(var n=i>1?void 0:i?IM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&LM(t,e,n),n};const ru=S("debugspriterenderer"),jM=S("wireframe"),gu=class{static getOrCreateGeometry(t){if(t.__cached_geometry)return t.__cached_geometry;if(t.guid&&gu.cache[t.guid])return ru&&console.log("Take cached geometry for sprite",t.guid),gu.cache[t.guid];const e=new h.BufferGeometry;t.__cached_geometry=e;const i=new Float32Array(t.triangles.length*3),n=new Float32Array(t.triangles.length*2);for(let o=0;o<t.triangles.length;o+=1){const a=t.triangles[o];i[o*3]=-t.vertices[a].x,i[o*3+1]=t.vertices[a].y,i[o*3+2]=0;const l=t.uv[a];n[o*2]=l.x,n[o*2+1]=1-l.y}return e.setAttribute("position",new h.BufferAttribute(i,3)),e.setAttribute("uv",new h.BufferAttribute(n,2)),t.guid&&(this.cache[t.guid]=e),ru&&console.log("Built sprite geometry",t,e),e}};let ur=gu;r(ur,"cache",{});class BM{constructor(){r(this,"x");r(this,"y")}}function Sw(s){s&&(s.colorSpace!=h.SRGBColorSpace&&(s.colorSpace=h.SRGBColorSpace,s.needsUpdate=!0),s.minFilter==h.NearestFilter&&s.magFilter==h.NearestFilter&&(s.anisotropy=1,s.needsUpdate=!0))}let Gn=class{constructor(t){r(this,"guid");r(this,"texture");r(this,"triangles");r(this,"uv");r(this,"vertices");r(this,"__cached_geometry");r(this,"_mesh");r(this,"_material");t&&(this.texture=t,this.triangles=[0,1,2,0,2,3],this.uv=[{x:0,y:0},{x:1,y:0},{x:1,y:1},{x:0,y:1}],this.vertices=[{x:-.5,y:-.5},{x:.5,y:-.5},{x:.5,y:.5},{x:-.5,y:.5}])}get mesh(){return this._mesh||(this._mesh=new h.Mesh(ur.getOrCreateGeometry(this),this.material)),this._mesh}get material(){return this._material||(this.texture&&Sw(this.texture),this._material=new h.MeshBasicMaterial({map:this.texture,color:16777215,side:h.DoubleSide,transparent:!0})),this._material}getGeometry(){return ur.getOrCreateGeometry(this)}};dt([p()],Gn.prototype,"guid",2);dt([p(h.Texture)],Gn.prototype,"texture",2);dt([Va()],Gn.prototype,"triangles",2);dt([Va()],Gn.prototype,"uv",2);dt([Va()],Gn.prototype,"vertices",2);const rp=Symbol("spriteOwner");class fo{constructor(){r(this,"sprites")}}dt([p(Gn)],fo.prototype,"sprites",2);const Cw=class{constructor(){r(this,"spriteSheet");r(this,"index",0)}static create(){const s=new Cw;return s.spriteSheet=new fo,s}set sprite(s){s&&(this.spriteSheet?((this.index===null||this.index===void 0)&&(this.index=0),this.spriteSheet.sprites[this.index]=s):(this.spriteSheet=new fo,this.spriteSheet.sprites=[s],this.index=0))}get sprite(){if(this.spriteSheet)return this.spriteSheet.sprites[this.index]}update(s){if(!this.spriteSheet)return;const t=this.index;if(t<0||t>=this.spriteSheet.sprites.length)return;const e=this.spriteSheet.sprites[t],i=e==null?void 0:e.texture;if(i&&(Sw(i),!e.__hasLoadedProgressive)){e.__hasLoadedProgressive=!0;const n=i;re.NEEDLE_progressive.assignTextureLOD(i,0).then(o=>{o instanceof h.Texture&&(e.texture=o,(s==null?void 0:s.map)===n&&(s.map=o,s.needsUpdate=!0))})}}};let xs=Cw;dt([p(fo)],xs.prototype,"spriteSheet",2);dt([p()],xs.prototype,"index",2);class li extends D{constructor(){super(...arguments);r(this,"drawMode",0);r(this,"size",{x:1,y:1});r(this,"color");r(this,"sharedMaterial");r(this,"transparent",!0);r(this,"cutoutThreshold",0);r(this,"castShadows",!1);r(this,"renderOrder",0);r(this,"toneMapped",!0);r(this,"_spriteSheet");r(this,"_currentSprite")}set texture(e){var n;if(!this._spriteSheet)return;const i=(n=this._spriteSheet.spriteSheet)==null?void 0:n.sprites[this.spriteIndex];i&&(i.texture=e,this.updateSprite())}addSprite(e,i=!1){var o,a;if(this._spriteSheet||(this._spriteSheet=xs.create()),!this._spriteSheet.spriteSheet)return-1;(o=this._spriteSheet.spriteSheet)==null||o.sprites.push(e);const n=((a=this._spriteSheet.spriteSheet)==null?void 0:a.sprites.length)-1;return i&&(this.spriteIndex=n),n}get sprite(){return this._spriteSheet}set sprite(e){if(e!==this._spriteSheet)if(typeof e=="number"){const i=Math.floor(e);this.spriteIndex=i;return}else e instanceof Gn?(this._spriteSheet||(this._spriteSheet=xs.create()),this._spriteSheet.sprite!=e&&(this._spriteSheet.sprite=e,this.updateSprite())):e!=this._spriteSheet&&(this._spriteSheet=e,this.updateSprite())}set spriteIndex(e){this._spriteSheet&&e!==this.spriteIndex&&(this._spriteSheet.index=e,this.updateSprite())}get spriteIndex(){var e;return((e=this._spriteSheet)==null?void 0:e.index)??0}get spriteFrames(){var e,i;return((i=(e=this._spriteSheet)==null?void 0:e.spriteSheet)==null?void 0:i.sprites.length)??0}awake(){this._currentSprite=void 0,this._spriteSheet||(this._spriteSheet=new xs,this._spriteSheet.spriteSheet=new fo),ru&&console.log("Awake",this.name,this,this.sprite)}start(){this._currentSprite?this.gameObject&&this.gameObject.add(this._currentSprite):this.updateSprite()}updateSprite(e=!1){var o;if(!this.__didAwake&&!e)return!1;const i=this._spriteSheet;if(!((o=i==null?void 0:i.spriteSheet)!=null&&o.sprites))return console.warn("SpriteRenderer has no data or spritesheet assigned..."),!1;const n=i.spriteSheet.sprites[this.spriteIndex];if(!n)return ru&&console.warn("Sprite not found",this.spriteIndex,i.spriteSheet.sprites),!1;if(this._currentSprite)this._currentSprite.geometry=ur.getOrCreateGeometry(n),this._currentSprite.material.map=n.texture;else{const a=new h.MeshBasicMaterial({color:16777215,side:h.DoubleSide});if(jM&&(a.wireframe=!0),this.color&&(a.color||(a.color=new h.Color),a.color.copy(this.color),a.opacity=this.color.alpha),a.transparent=!0,a.toneMapped=this.toneMapped,n.texture&&!a.wireframe){let l=n.texture;l[rp]!==void 0&&l[rp]!==this&&this.spriteFrames>1&&(l=n.texture=l.clone()),l[rp]=this,a.map=l}this.sharedMaterial=a,this._currentSprite=new h.Mesh(ur.getOrCreateGeometry(n),a),this._currentSprite.renderOrder=Math.round(this.renderOrder),re.NEEDLE_progressive.assignTextureLOD(a,0)}return this._currentSprite.parent!==this.gameObject&&(this.drawMode===2&&this._currentSprite.scale.set(this.size.x,this.size.y,1),this.gameObject&&this.gameObject.add(this._currentSprite)),this._currentSprite&&this._currentSprite.layers.set(this.layer),this.sharedMaterial&&(this.sharedMaterial.alphaTest=this.cutoutThreshold,this.sharedMaterial.transparent=this.transparent),this._currentSprite.castShadow=this.castShadows,i==null||i.update(this.sharedMaterial),!0}}dt([p()],li.prototype,"drawMode",2);dt([p(BM)],li.prototype,"size",2);dt([p(ge)],li.prototype,"color",2);dt([p(h.Material)],li.prototype,"sharedMaterial",2);dt([p()],li.prototype,"transparent",2);dt([p()],li.prototype,"cutoutThreshold",2);dt([p()],li.prototype,"castShadows",2);dt([p()],li.prototype,"renderOrder",2);dt([p()],li.prototype,"toneMapped",2);dt([p(xs)],li.prototype,"sprite",1);const sb=S("debugwebxr"),FM=new h.Matrix4().makeRotationY(Math.PI);class Cs extends D{constructor(){super(...arguments);r(this,"_arScale",1);r(this,"invertForward",!1);r(this,"customReticle");r(this,"arTouchTransform",!0);r(this,"autoPlace",!1);r(this,"autoCenter",!1);r(this,"useXRAnchor",!1);r(this,"_isPlacing",!0);r(this,"_startOffset",new h.Matrix4);r(this,"_createdPlacementObject",null);r(this,"_reparentedComponents",[]);r(this,"_placementScene",new h.Scene);r(this,"_reticle",[]);r(this,"_hits",[]);r(this,"_placementStartTime",-1);r(this,"_rigPlacementMatrix");r(this,"_anchor",null);r(this,"userInput");r(this,"onPlaceScene",e=>{var o;if(this._isPlacing==!1||e!=null&&e.used)return;let i=this._reticle[0];if(!i){console.warn("No reticle to place...");return}if(!i.visible&&!this.autoPlace){console.warn("Reticle is not visible (can not place)");return}if((o=q.active)!=null&&o.isTrackingImages){console.warn("Scene Placement is disabled while images are being tracked");return}let n=this._hits[0];if(e&&e.origin instanceof Qm){const a=this._reticle[e.origin.index];a&&(i=a,n=this._hits[e.origin.index])}if(e&&(e.stopImmediatePropagation(),e.stopPropagation(),e.use()),this._isPlacing=!1,this.context.input.removeEventListener("pointerup",this.onPlaceScene),this.onRevertSceneChanges(),i.position.copy(i.lastPos),i.quaternion.copy(i.lastQuat),this.onApplyPose(i),this.useXRAnchor&&this.onCreateAnchor(q.active,n),this.context.xr)for(const a of this.context.xr.controllers)a.cancelHitTestSource()});r(this,"upVec",new h.Vector3(0,1,0));r(this,"lookPoint",new h.Vector3);r(this,"worldUpVec",new h.Vector3(0,1,0))}static onPlaced(e){const i="placed";return this._eventListeners[i]||(this._eventListeners[i]=[]),this._eventListeners[i].push(e),()=>{const n=this._eventListeners[i].indexOf(e);n>=0&&this._eventListeners[i].splice(n,1)}}get arScale(){return this._arScale}set arScale(e){e!==this._arScale&&(this._arScale=e,this.onScaleChanged())}onEnable(){var e;(e=this.customReticle)==null||e.preload()}supportsXR(e){return e==="immersive-ar"}onEnterXR(e){sb&&console.log("ENTER WEBXR: SessionRoot start..."),this._anchor=null,this.gameObject.updateMatrixWorld(),this._startOffset.copy(this.gameObject.matrixWorld);const i=new h.Object3D;this._createdPlacementObject=i,i.name="AR Session Root",this._placementScene.name="AR Placement Scene",this._placementScene.children.length=0;for(let n=this.context.scene.children.length-1;n>=0;n--){const o=this.context.scene.children[n];this._placementScene.add(o)}if(this.context.scene.add(i),this.autoCenter){const n=oi(this._placementScene.children),o=n.getCenter(new h.Vector3),a=n.getSize(new h.Vector3),l=new h.Matrix4;l.makeTranslation(o.x,o.y-a.y*.5,o.z),this._startOffset.multiply(l)}this._reparentedComponents.length=0,this._reparentedComponents.push({comp:this,originalObject:this.gameObject}),C.addComponent(i,this);for(const n of this._reticle)Pi(n);this._reticle.length=0,this._isPlacing=!0,this.context.input.addEventListener("pointerup",this.onPlaceScene,{queue:_i.Early})}onLeaveXR(){this.context.input.removeEventListener("pointerup",this.onPlaceScene,{queue:_i.Early}),this.onRevertSceneChanges(),this._anchor=null,this._rigPlacementMatrix=void 0}onUpdateXR(e){var i,n,o,a;if(e.xr.isTrackingImages){for(const l of this._reticle)l.visible=!1;return}if(this._isPlacing){const l=(i=e.xr.rig)==null?void 0:i.gameObject;l&&l.parent!==this.context.scene&&this.context.scene.add(l);let c=!1;if(e.xr.isPassThrough&&e.xr.controllers.length>0&&!this.autoPlace)for(const d of e.xr.controllers){const u=d.getHitTest();u&&(c=!0,this.updateReticleAndHits(e.xr,d.index,u,e.xr.rigScale))}if(!c){const d=e.xr.getHitTest();d&&this.updateReticleAndHits(e.xr,0,d,e.xr.rigScale)}}else{if(this._anchor&&e.xr.referenceSpace){const l=e.xr.frame.getPose(this._anchor.anchorSpace,e.xr.referenceSpace);if(l&&this.context.time.frame%20===0){const c=e.xr.convertSpace(l.transform),d=this._reticle[0];d&&(d.position.copy(c.position),d.quaternion.copy(c.quaternion),this.onApplyPose(d))}}if(this.arTouchTransform?(this.userInput||(this.userInput=new ua(this.context)),(n=this.userInput)==null||n.enable()):(o=this.userInput)==null||o.disable(),this.arTouchTransform&&((a=this.userInput)!=null&&a.hasChanged)){if(e.xr.rig){const l=e.xr.rig.gameObject;this.userInput.applyMatrixTo(l.matrix,!0),l.matrix.decompose(l.position,l.quaternion,l.scale),this.userInput.factor=l.scale.x}this.userInput.reset()}}}updateReticleAndHits(e,i,n,o){this._hits[i]=n.hit;let a=this._reticle[i];if(!a){if(this.customReticle)if(this.customReticle.asset)a=br(this.customReticle.asset);else{this.customReticle.loadAssetAsync();return}else a=new h.Mesh(new h.RingGeometry(.07,.09,32).rotateX(-Math.PI/2),new h.MeshBasicMaterial({side:h.DoubleSide,depthTest:!1,depthWrite:!1,transparent:!0,opacity:1,color:15658734})),a.name="AR Placement Reticle";if(sb){const l=new h.AxesHelper(1);l.position.y+=.01,a.add(l)}this._reticle[i]=a,a.matrixAutoUpdate=!1,a.visible=!1}if(a.lastPos=a.lastPos||n.position.clone(),a.lastQuat=a.lastQuat||n.quaternion.clone(),a.position.copy(a.lastPos.lerp(n.position,this.context.time.deltaTime/.1)),a.lastPos.copy(a.position),a.quaternion.copy(a.lastQuat.slerp(n.quaternion,this.context.time.deltaTime/.05)),a.lastQuat.copy(a.quaternion),a.scale.set(o,o,o),this.customReticle&&this.applyViewBasedTransform(a),a.updateMatrix(),a.visible=!0,a.parent!==this.context.scene&&this.context.scene.add(a),this._placementStartTime<0&&(this._placementStartTime=this.context.time.realtimeSinceStartup),this.autoPlace)if(this.upVec.set(0,1,0).applyQuaternion(a.quaternion),this.upVec.dot(V(0,1,0))>.9){let c=a["autoplace:timer"]||0;c>=1?(a.visible=!1,this.onPlaceScene(null)):(c+=this.context.time.deltaTime,a["autoplace:timer"]=c)}else a["autoplace:timer"]=0}onScaleChanged(){}onRevertSceneChanges(){var e;for(const i of this._reticle)i&&(i.visible=!1,i==null||i.removeFromParent());this._reticle.length=0;for(let i=this._placementScene.children.length-1;i>=0;i--){const n=this._placementScene.children[i];this.context.scene.add(n)}(e=this._createdPlacementObject)==null||e.removeFromParent();for(const i of this._reparentedComponents)C.addComponent(i.originalObject,i.comp)}async onCreateAnchor(e,i){if(i.createAnchor===void 0){console.warn("Hit does not support creating an anchor",i),B()&&me("Hit does not support creating an anchor");return}else{const n=await i.createAnchor(e.viewerPose.transform);e.running&&n&&(this._anchor=n)}}applyViewBasedTransform(e){const i=this.context.mainCamera,n=e,o=i.worldPosition,a=n.worldPosition;this.upVec.set(0,1,0).applyQuaternion(e.quaternion);const l=i.worldPosition;l&&e.position.clone().sub(l).angleTo(this.upVec)<Math.PI/2&&this.upVec.negate();const c=this.upVec.angleTo(this.worldUpVec)*180/Math.PI,d=30;c>d&&c<180-d||c<-d&&c>-180+d?(this.lookPoint.copy(e.position).add(this.upVec),this.lookPoint.y=e.position.y,e.lookAt(this.lookPoint)):(o.y=a.y,e.lookAt(o))}onApplyPose(e){var o,a,l,c;const i=(a=(o=q.active)==null?void 0:o.rig)==null?void 0:a.gameObject;if(!i){console.warn("No rig object to place");return}(l=q.active)!=null&&l.rigScale;const n=i.parent||this.context.scene;this._rigPlacementMatrix?(c=this._rigPlacementMatrix)==null||c.decompose(i.position,i.quaternion,i.scale):this._rigPlacementMatrix=i.matrix.clone(),this.applyViewBasedTransform(e),e.updateMatrix(),this.context.scene.add(e),e.attach(i),e.removeFromParent(),i.scale.set(this.arScale,this.arScale,this.arScale),i.position.multiplyScalar(this.arScale),i.updateMatrix(),this.invertForward&&i.matrix.premultiply(FM),i.matrix.premultiply(this._startOffset),i.matrix.decompose(i.position,i.quaternion,i.scale),n.add(i)}}r(Cs,"_eventListeners",{});const _u=class{constructor(t){r(this,"oneFingerDrag",!0);r(this,"twoFingerRotate",!0);r(this,"twoFingerScale",!0);r(this,"factor",1);r(this,"context");r(this,"offset");r(this,"plane");r(this,"_scale",1);r(this,"_hasChanged",!1);r(this,"_enabled",!1);r(this,"currentlyUsedPointerIds",new Set);r(this,"currentlyUnusedPointerIds",new Set);r(this,"onPointerDownEarly",t=>{this.isActive&&t.stopPropagation()});r(this,"onPointerDownLate",t=>{t.used?this.currentlyUsedPointerIds.add(t.pointerId):this.currentlyUsedPointerIds.size<=0&&this.currentlyUnusedPointerIds.add(t.pointerId)});r(this,"onPointerUpEarly",t=>{this.currentlyUsedPointerIds.delete(t.pointerId),this.currentlyUnusedPointerIds.delete(t.pointerId)});r(this,"prev",new Map);r(this,"_didMultitouch",!1);r(this,"touchStart",t=>{if(!t.defaultPrevented)for(let e=0;e<t.changedTouches.length;e++){const i=t.changedTouches[e],n=exports.DeviceUtilities.isAndroidDevice()&&i.clientY<window.innerHeight*.1;this.prev.has(i.identifier)||this.prev.set(i.identifier,{ignore:n,x:0,z:0,screenx:0,screeny:0});const o=this.prev.get(i.identifier);if(o){const a=this.getPositionOnPlane(i.clientX,i.clientY);o.x=a.x,o.z=a.z,o.screenx=i.clientX,o.screeny=i.clientY}}});r(this,"touchEnd",t=>{t.touches.length<=0&&(this._didMultitouch=!1);for(let e=0;e<t.changedTouches.length;e++){const i=t.changedTouches[e];this.prev.delete(i.identifier)}});r(this,"touchMove",t=>{if(!t.defaultPrevented&&this.isActive){if(t.touches.length===1){if(this._didMultitouch)return;const e=t.touches[0],i=this.prev.get(e.identifier);if(!i||i.ignore)return;const n=this.getPositionOnPlane(e.clientX,e.clientY),o=n.x-i.x,a=n.z-i.z;if(o===0&&a===0)return;this.oneFingerDrag&&this.addMovement(o,a),i.x=n.x,i.z=n.z,i.screenx=e.clientX,i.screeny=e.clientY;return}else if(t.touches.length===2){this._didMultitouch=!0;const e=t.touches[0],i=t.touches[1],n=this.prev.get(e.identifier),o=this.prev.get(i.identifier);if(!n||!o)return;if(this.twoFingerRotate){const a=Math.atan2(e.clientY-i.clientY,e.clientX-i.clientX),l=Math.atan2(n.screeny-o.screeny,n.screenx-o.screenx),c=a-l;Math.abs(c)>.001&&this.addRotation(c)}if(this.twoFingerScale){const a=e.clientX-i.clientX,l=e.clientY-i.clientY,c=Math.sqrt(a*a+l*l),d=n.screenx-o.screenx,u=n.screeny-o.screeny,f=Math.sqrt(d*d+u*u),m=c-f;Math.abs(m)>2&&this.addScale(m)}n.screenx=e.clientX,n.screeny=e.clientY,o.screenx=i.clientX,o.screeny=i.clientY}}});r(this,"_raycaster",new h.Raycaster);r(this,"_intersection",new h.Vector3);r(this,"_screenPos",new h.Vector3);r(this,"_tempMatrix",new h.Matrix4);this.context=t,this.offset=new h.Matrix4,this.plane=new h.Plane,this.plane.setFromNormalAndCoplanarPoint(_u.up,_u.zero)}reset(){this._scale=1,this.offset.identity()}get hasChanged(){return this._hasChanged}applyMatrixTo(t,e){this._hasChanged=!1,e?(this.offset.invert(),t.premultiply(this.offset)):t.multiply(this.offset)}get isActive(){return this.currentlyUsedPointerIds.size<=0&&this.currentlyUnusedPointerIds.size>0}enable(){this._enabled||(this._enabled=!0,this.context.input.addEventListener("pointerdown",this.onPointerDownEarly,{queue:_i.Early}),this.context.input.addEventListener("pointerdown",this.onPointerDownLate,{queue:_i.Late}),this.context.input.addEventListener("pointerup",this.onPointerUpEarly,{queue:_i.Early}),window.addEventListener("touchstart",this.touchStart,{passive:!1}),window.addEventListener("touchmove",this.touchMove,{passive:!1}),window.addEventListener("touchend",this.touchEnd,{passive:!1}))}disable(){this._enabled&&(this._enabled=!1,this.context.input.removeEventListener("pointerdown",this.onPointerDownEarly,{queue:_i.Early}),this.context.input.removeEventListener("pointerdown",this.onPointerDownLate,{queue:_i.Late}),this.context.input.removeEventListener("pointerup",this.onPointerUpEarly,{queue:_i.Early}),window.removeEventListener("touchstart",this.touchStart),window.removeEventListener("touchmove",this.touchMove),window.removeEventListener("touchend",this.touchEnd))}getPositionOnPlane(t,e){const i=this.context.mainCamera;return this._screenPos.x=t/window.innerWidth*2-1,this._screenPos.y=-(e/window.innerHeight)*2+1,this._screenPos.z=1,this._screenPos.unproject(i),this._raycaster.set(i.position,this._screenPos.sub(i.position)),this._raycaster.ray.intersectPlane(this.plane,this._intersection),this._intersection}addMovement(t,e){t/=this._scale,e/=this._scale,t*=this.factor,e*=this.factor,this.offset.elements[12]+=t,this.offset.elements[14]+=e,(t!==0||e!==0)&&(this._hasChanged=!0)}addScale(t){t/=window.innerWidth,t*=-1,this._scale*=1+t,this._tempMatrix.makeScale(1-t,1-t,1-t),this.offset.premultiply(this._tempMatrix),t!==0&&(this._hasChanged=!0)}addRotation(t){t*=-1,this._tempMatrix.makeRotationY(t),this.offset.premultiply(this._tempMatrix),t!==0&&(this._hasChanged=!0)}};let ua=_u;r(ua,"up",new h.Vector3(0,1,0)),r(ua,"zero",new h.Vector3(0,0,0)),r(ua,"one",new h.Vector3(1,1,1));const Qs=S("debugautosync"),ap=Symbol("syncerId");class UM{constructor(){r(this,"_syncers",{})}getOrCreateSyncer(t){if(!t.guid)return null;if(this._syncers[t.guid])return this._syncers[t.guid];const e=new zM(t);return e[ap]=t.guid,this._syncers[e[ap]]=e,e}removeSyncer(t){delete this._syncers[t[ap]]}}const Qg=new UM;class zM{constructor(t){r(this,"comp");r(this,"hasChanges",!1);r(this,"changedProperties",{});r(this,"_isReceiving",!1);r(this,"_isInit",!1);r(this,"onHandleSending",()=>{if(!this.hasChanges)return;this.hasChanges=!1;const t=this.comp.context.connection;if(!t||!t.isConnected||!t.isInRoom){for(const e in this.changedProperties)delete this.changedProperties[e];return}for(const e in this.changedProperties){const i=this.changedProperties[e];Qs&&console.log("SEND",this.comp.guid,this.networkingKey),t.send(this.networkingKey,{guid:this.comp.guid,property:e,data:i},rn.Queued),delete this.changedProperties[e]}});r(this,"onHandleReceiving",t=>{if(Qs&&console.log("SYNCFIELD RECEIVE",this.comp.name,this.comp.guid,t),!!this._isInit&&this.comp&&t.guid===this.comp.guid)try{this._isReceiving=!0,this.comp[t.property]=t.data}catch(e){console.error(e)}finally{this._isReceiving=!1}});this.comp=t}get networkingKey(){return this.comp.guid}init(t){if(this._isInit)return;this._isInit=!0,this.comp=t,this.comp.context.post_render_callbacks.push(this.onHandleSending),this.comp.context.connection.beginListen(this.networkingKey,this.onHandleReceiving);const e=this.comp.context.connection.tryGetState(this.comp.guid);e&&this.onHandleReceiving(e)}destroy(){this._isInit&&(this.comp.context.post_render_callbacks.splice(this.comp.context.post_render_callbacks.indexOf(this.onHandleSending),1),this.comp.context.connection.stopListen(this.networkingKey,this.onHandleReceiving),this.comp=null,this._isInit=!1)}notifyChanged(t,e){this._isReceiving||(Qs&&console.log("Property changed: "+t,e),this.hasChanges=!0,this.changedProperties[t]=e)}}function NM(s,t){let e=t!==s;return!e&&s&&t&&(Array.isArray(s)&&Array.isArray(t)||typeof s=="object"&&typeof t=="object")&&(e=!0),e}const lc=Symbol("AutoSyncHandler");function VM(s){if(s[lc])return s[lc];const t=Qg.getOrCreateSyncer(s);return t==null||t.init(s),s[lc]=t,t}function $M(s){const t=s[lc];t&&(Qg.removeSyncer(t),t.destroy(),delete s[lc])}const Yg=function(s=null){return function(t,e){var u;let i="";typeof e=="string"?i=e:i=e.name;let n=null,o;typeof s=="string"?o=t[s]:typeof s=="function"&&(o=s),o==null&&(B()||Qs)&&s!=null&&console.warn('syncField: no callback function found for property "'+i+'"','"'+s+'"');const a=t,l=a.__internalAwake;if(typeof l!="function"){(Qs||B())&&console.error('@syncField can currently only used on Needle Engine Components, custom object of type "'+((u=t==null?void 0:t.constructor)==null?void 0:u.name)+'" is not supported',t);return}Qs&&console.log(i);const c=Symbol(i);a.__internalAwake=function(){if(this[c]!==void 0)return;this[c]=this[i],n=Qg.getOrCreateSyncer(this);const f=Object.getOwnPropertyDescriptor(this,i);if((f==null?void 0:f.set)===void 0){let m=!1;Object.defineProperty(this,i,{set:function(g){var y;const _=this[c];if(this[c]=g,m){(B()||Qs)&&console.warn("Recursive call detected",i);return}m=!0;try{const b=NM(g,_);Qs&&console.log("SyncField assignment",i,"changed?",b,g,o),b&&(o==null?void 0:o.call(this,g,_))!==!1&&((y=VM(this))==null||y.notifyChanged(i,g))}finally{m=!1}},get:function(){return this[c]},configurable:!0,enumerable:!0})}n==null||n.init(this),l.call(this)};const d=a.__internalDestroy;a.__internalDestroy=function(){$M(this),d.call(this)}}};var WM=Object.defineProperty,HM=Object.getOwnPropertyDescriptor,Ku=(s,t,e,i)=>{for(var n=i>1?void 0:i?HM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&WM(t,e,n),n};const Nt=S("debugplayersync"),Pw=class extends D{constructor(){super(...arguments);r(this,"autoSync",!0);r(this,"asset");r(this,"onPlayerSpawned");r(this,"_localInstance");r(this,"onJoinedRoom",()=>{Nt&&console.log("PlayerSync.joinedRoom. autoSync is set to "+this.autoSync),this.autoSync&&this.getInstance()});r(this,"destroyInstance",()=>{var t;(t=this._localInstance)==null||t.then(e=>{Nt&&console.log("PlayerSync.destroyInstance",e),Xc(e,this.context.connection,!0,{saveInRoom:!1})}),this._localInstance=void 0})}static async setupFrom(t,e){const i=ee.getOrCreateFromUrl(t);if(!i.asset){const a=await i.loadAssetAsync();a&&C.getOrAddComponent(a,wi)}const n=new Pw;n._internalInit(e),n.asset=i;const o=new h.Object3D;return o.guid=t,C.addComponent(o,n),n}awake(){this.watchTabVisible(),this.onPlayerSpawned||(this.onPlayerSpawned=new fe)}onEnable(){this.context.connection.beginListen(Z.RoomStateSent,this.onJoinedRoom),this.context.connection.beginListen(Z.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(Z.LeftRoom,this.destroyInstance),this.context.connection.isInRoom&&this.onJoinedRoom()}onDisable(){this.context.connection.stopListen(Z.RoomStateSent,this.onJoinedRoom),this.context.connection.stopListen(Z.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(Z.LeftRoom,this.destroyInstance)}async getInstance(){var e,i,n,o,a,l;if(this._localInstance)return this._localInstance;if(Nt&&console.log("PlayerSync.createInstance",(e=this.asset)==null?void 0:e.url),!((i=this.asset)!=null&&i.asset)&&!((n=this.asset)!=null&&n.url))return console.error('PlayerSync: can not create an instance because "asset" is not set and or has no URL!'),null;this.gameObject.guid||console.warn("PlayerSync: gameObject has no guid! This might cause issues with syncing the player state."),this._localInstance=(o=this.asset)==null?void 0:o.instantiateSynced({parent:this.gameObject,deleteOnDisconnect:!0},!0);const t=await this._localInstance;if(t){const c=C.getComponentsInChildren(t,wi);if(Nt&&console.log(`PlayerSync.createInstance: found ${c==null?void 0:c.length} PlayerState components. Owner: ${this.context.connection.connectionId}`),c!=null&&c.length){for(const d of c)d.owner=this.context.connection.connectionId;(a=this.onPlayerSpawned)==null||a.invoke(t)}else this._localInstance=void 0,console.error("<strong>Failed finding PlayerState on "+((l=this.asset)==null?void 0:l.url)+"</strong>: please make sure the asset has a PlayerState component!"),C.destroySynced(t)}else this._localInstance=void 0,console.warn("PlayerSync: failed instantiating asset!");return this._localInstance}watchTabVisible(){window.addEventListener("visibilitychange",t=>{if(document.visibilityState==="visible")for(let e=wi.all.length-1;e>=0;e--){const i=wi.all[e];(!i.owner||!this.context.connection.userIsInRoom(i.owner))&&i.doDestroy()}})}};let tl=Pw;Ku([p()],tl.prototype,"autoSync",2);Ku([p(ee)],tl.prototype,"asset",2);Ku([p(fe)],tl.prototype,"onPlayerSpawned",2);var Ow=(s=>(s.OwnerChanged="ownerChanged",s))(Ow||{}),Al;const gt=(Al=class extends D{constructor(){super(...arguments);r(this,"onOwnerChangeEvent",new fe);r(this,"onFirstOwnerChangeEvent",new fe);r(this,"hasOwner",!1);r(this,"owner");r(this,"dontDestroy",!1);r(this,"onUserLeftRoom",t=>{if(t.userId===this.owner){Nt&&console.log("PLAYERSYNC LEFT",this.owner),this.doDestroy();return}})}static get all(){return gt._all}static get local(){return gt._local}static getFor(t){if(t instanceof h.Object3D)return C.getComponentInParent(t,gt);if(t instanceof D)return C.getComponentInParent(t.gameObject,gt)}static isLocalPlayer(t){const e=gt.getFor(t);return(e==null?void 0:e.isLocalPlayer)??!1}static addEventListener(t,e){return this._callbacks[t]||(this._callbacks[t]=[]),this._callbacks[t].push(e),e}static removeEventListener(t,e){if(!this._callbacks[t])return;const i=this._callbacks[t].indexOf(e);i>=0&&this._callbacks[t].splice(i,1)}static dispatchEvent(t,e){if(this._callbacks[t])for(const i of this._callbacks[t])i(e)}get isLocalPlayer(){return this.owner===this.context.connection.connectionId}onOwnerChange(t,e){var a,l;Nt&&console.log(`PlayerSync.onOwnerChange: ${e} → ${t} (me: ${this.context.connection.connectionId})`);const i=gt._local.indexOf(this);i>=0&&gt._local.splice(i,1);const n={playerState:this,oldValue:e,newValue:t};if(this.hasOwner||(this.hasOwner=!0,(a=this.onFirstOwnerChangeEvent)==null||a.invoke(n)),(l=this.onOwnerChangeEvent)==null||l.invoke(n),this.owner===this.context.connection.connectionId){gt._local.push(this);const c=new CustomEvent("local-owner-changed",{detail:n});this.dispatchEvent(c)}const o=new CustomEvent("owner-changed",{detail:n});this.dispatchEvent(o),gt.dispatchEvent("ownerChanged",o)}awake(){gt.all.push(this),Nt&&console.log("Registered new PlayerState",this.guid,gt.all.length-1,gt.all),this.context.connection.beginListen(Z.UserLeftRoom,this.onUserLeftRoom)}async start(){Nt&&console.log("PLAYERSTATE.START, owner: "+this.owner,this.context.connection.usersInRoom([])),this.owner?(this.context.connection.isInRoom||await un(300),this.context.connection.userIsInRoom(this.owner)==!1&&(Nt&&console.log(`PlayerSync.start → doDestroy "${this.name}" because user "${this.owner}" is not in room anymore...`,"Currently in room:",...this.context.connection.usersInRoom()),this.doDestroy())):this.owner||(Nt&&console.warn("PlayerState.start → owner is undefined!",this.name),setTimeout(()=>{!this.destroyed&&!this.owner?this.dontDestroy?Nt&&console.warn("PlayerState.start → owner is still undefined but dontDestroy is set to true",this.name):(Nt&&console.warn(`PlayerState.start → owner is still undefined: destroying "${this.name}" instance now`),this.doDestroy()):Nt&&console.log("PlayerState.start → owner is assigned",this.owner)},2e3))}doDestroy(){Nt&&console.log("PlayerSync.doDestroy → syncDestroy",this.name),Xc(this.gameObject,this.context.connection,!0,{saveInRoom:!1})}onDestroy(){if(Nt&&console.warn("PlayerState.onDestroy",this.owner),this.context.connection.stopListen(Z.UserLeftRoom,this.onUserLeftRoom),gt.all.splice(gt.all.indexOf(this),1),this.isLocalPlayer){const t=gt._local.indexOf(this);t>=0&&gt._local.splice(t,1)}}},r(Al,"_all",[]),r(Al,"_local",[]),r(Al,"_callbacks",{}),Al);let wi=gt;Ku([Yg(wi.prototype.onOwnerChange)],wi.prototype,"owner",2);var GM=Object.defineProperty,qM=Object.getOwnPropertyDescriptor,il=(s,t,e,i)=>{for(var n=i>1?void 0:i?qM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&GM(t,e,n),n};class qn extends D{constructor(){super(...arguments);r(this,"position","bottom");r(this,"showNeedleLogo",!0);r(this,"showSpatialMenu");r(this,"createFullscreenButton");r(this,"createMuteButton");r(this,"createQRCodeButton")}onEnable(){this.applyOptions()}applyOptions(){this.context.menu.setPosition(this.position),this.context.menu.showNeedleLogo(this.showNeedleLogo),this.createFullscreenButton===!0&&this.context.menu.showFullscreenOption(!0),this.createMuteButton===!0&&this.context.menu.showAudioPlaybackOption(!0),this.showSpatialMenu===!0&&this.context.menu.showSpatialMenu(this.showSpatialMenu),this.createQRCodeButton===!0&&(exports.DeviceUtilities.isMobileDevice()||this.context.menu.showQRCodeButton(!0))}}il([p()],qn.prototype,"position",2);il([p()],qn.prototype,"showNeedleLogo",2);il([p()],qn.prototype,"showSpatialMenu",2);il([p()],qn.prototype,"createFullscreenButton",2);il([p()],qn.prototype,"createMuteButton",2);il([p()],qn.prototype,"createQRCodeButton",2);var XM=Object.defineProperty,QM=Object.getOwnPropertyDescriptor,Kg=(s,t,e,i)=>{for(var n=i>1?void 0:i?QM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&XM(t,e,n),n};const Cl=S("debugwebxr"),ob=new h.Quaternion().setFromAxisAngle(new h.Vector3(0,1,0),Math.PI);class po extends D{constructor(){super(...arguments);r(this,"head");r(this,"leftHand");r(this,"rightHand");r(this,"_leftHandMeshes");r(this,"_rightHandMeshes");r(this,"_syncTransforms")}async onEnterXR(e){if(!this.activeAndEnabled)return;Cl&&console.warn("AVATAR ENTER XR",this.guid,this.sourceId,this,this.activeAndEnabled),this._syncTransforms&&(this._syncTransforms.length=0),await this.prepareAvatar();const i=wi.getFor(this);if(i!=null&&i.owner){const n=this.gameObject.addComponent(it);n.avatar=this.gameObject,n.connectionId=i.owner}else this.context.connection.isConnected?console.error("No player state found for avatar",this):i&&!this.context.connection.isConnected&&(i.dontDestroy=!0)}onLeaveXR(e){const i=this.gameObject.getComponent(it);i&&i.destroy()}onUpdateXR(e){var d,u;if(!this.activeAndEnabled)return;const i=wi.isLocalPlayer(this);if(!i)return;const n=e.xr;if(n.rig&&n.rig.gameObject!==this.gameObject.parent&&(this.gameObject.position.set(0,0,0),this.gameObject.rotation.set(0,0,0),this.gameObject.scale.set(1,1,1),n.rig.gameObject.add(this.gameObject)),this._syncTransforms&&i)for(const f of this._syncTransforms)f.fastMode=!0,f.isOwned()||f.requestOwnership();if(this.head&&this.context.mainCamera){const f=this.head.asset;if(f.position.copy(this.context.mainCamera.position),f.position.x*=-1,f.position.z*=-1,f.quaternion.copy(this.context.mainCamera.quaternion),f.quaternion.x*=-1,this.context.time.frameCount%10===0&&this.head.asset){const m=C.getComponentsInChildren(this.head.asset,yi);for(const g of m)g.enabled=!1,g.gameObject.visible=!1}}const o=e.xr.leftController,a=(d=this.leftHand)==null?void 0:d.asset;o&&a?(a.position.copy(o.gripPosition),a.quaternion.copy(o.gripQuaternion),a.quaternion.multiply(ob),a.visible=o.isTracking,this.updateHandVisibility(o,a,this._leftHandMeshes)):a&&a.visible&&(a.visible=!1);const l=e.xr.rightController,c=(u=this.rightHand)==null?void 0:u.asset;l&&c?(c.position.copy(l.gripPosition),c.quaternion.copy(l.gripQuaternion),c.quaternion.multiply(ob),c.visible=l.isTracking,this.updateHandVisibility(l,c,this._rightHandMeshes)):c&&c.visible&&(c.visible=!1)}onBeforeRender(){this.context.xr&&this.context.time.frame%10===0&&this.updateRemoteAvatarVisibility()}updateHandVisibility(e,i,n){if(n){const o=e.model&&e.model.visible&&e.model!==i;n.forEach(a=>{ps(a,!o)})}}updateRemoteAvatarVisibility(){var e,i,n;if(this.context.connection.isConnected){const o=wi.getFor(this);if(o&&o.isLocalPlayer==!1){const a=q.getXRSync(this.context);if(a&&a.hasState(o.owner)){this.tryFindAvatarObjectsIfMissing();const l=(e=this.leftHand)==null?void 0:e.asset;l&&(l.visible=(a==null?void 0:a.isTracking(o.owner,"left"))??!1);const c=(i=this.rightHand)==null?void 0:i.asset;c&&(c.visible=(a==null?void 0:a.isTracking(o.owner,"right"))??!1)}if((n=this.head)!=null&&n.asset){const l=C.getComponentsInChildren(this.head.asset,yi);for(const c of l)c.enabled=!1,c.gameObject.visible=!0}}}}tryFindAvatarObjectsIfMissing(){if(!this.head||!this.leftHand||!this.rightHand){const e={head:this.head,leftHand:this.leftHand,rightHand:this.rightHand};Cv.tryFindAvatarObjects(this.gameObject,this.sourceId||"",e),e.head&&(this.head=e.head),e.leftHand&&(this.leftHand=e.leftHand),e.rightHand&&(this.rightHand=e.rightHand)}}async prepareAvatar(){var e,i;if(this.tryFindAvatarObjectsIfMissing(),this.head)this.head instanceof h.Object3D&&(this.head=new ee("",this.sourceId,this.head));else{const n=new h.Object3D;n.name="Head";const o=vo.createPrimitive(gr.Cube);n.add(o),this.gameObject.add(n),this.head=new ee("",this.sourceId,n),Cl&&console.log("Create head",n)}if(this.rightHand)this.rightHand instanceof h.Object3D&&(this.rightHand=new ee("",this.sourceId,this.rightHand));else{const n=new h.Object3D;n.name="Right Hand",this.gameObject.add(n),this.rightHand=new ee("",this.sourceId,n),Cl&&console.log("Create right hand",n)}if(this.leftHand)this.leftHand instanceof h.Object3D&&(this.leftHand=new ee("",this.sourceId,this.leftHand));else{const n=new h.Object3D;n.name="Left Hand",this.gameObject.add(n),this.leftHand=new ee("",this.sourceId,n),Cl&&console.log("Create left hand",n)}await this.loadAvatarObjects(this.head,this.leftHand,this.rightHand),this._leftHandMeshes=[],(e=this.leftHand.asset)==null||e.traverse(n=>{n!=null&&n.isMesh&&this._leftHandMeshes.push(n)}),this._rightHandMeshes=[],(i=this.rightHand.asset)==null||i.traverse(n=>{n!=null&&n.isMesh&&this._rightHandMeshes.push(n)}),wi.isLocalPlayer(this.gameObject)&&(this._syncTransforms=C.getComponentsInChildren(this.gameObject,Nn))}async loadAvatarObjects(e,i,n){const o=e.loadAssetAsync(),a=i.loadAssetAsync(),l=n.loadAssetAsync(),c=new Array;o&&c.push(o),a&&c.push(a),l&&c.push(l);const d=await xu(c);Cl&&console.log("Avatar loaded results:",d)}}Kg([p(ee)],po.prototype,"head",2);Kg([p(ee)],po.prototype,"leftHand",2);Kg([p(ee)],po.prototype,"rightHand",2);var YM=Object.defineProperty,KM=Object.getOwnPropertyDescriptor,Zu=(s,t,e,i)=>{for(var n=i>1?void 0:i?KM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&YM(t,e,n),n};const ts=S("debugwebxr"),Fs=new Array;class Vn extends D{constructor(){super(...arguments);r(this,"createControllerModel",!0);r(this,"createHandModel",!0);r(this,"customLeftHand");r(this,"customRightHand");r(this,"_models",new Array)}supportsXR(e){return e==="immersive-vr"||e==="immersive-ar"}async onXRControllerAdded(e){var o;if(!(e.xr.isVR||e.xr.isPassThrough))return;const{controller:n}=e;if(ts&&console.warn("Add Controller Model for",n.side,n.index),this.createControllerModel||this.createHandModel){if(n.hand){if(this.createHandModel){const a=await this.loadHandModel(this,n);if(!a||!n.connected||!n.isHand){a!=null&&a.handObject&&aa(a.handObject,!1),(o=a==null?void 0:a.handObject)==null||o.destroy();return}this._models.push({controller:n,model:a.handObject,handmesh:a.handmesh}),this._models.sort((l,c)=>l.controller.index-c.controller.index),this.scene.add(a.handObject),n.model=a.handObject}}else if(this.createControllerModel){const a=await n.getModelUrl();if(a){const l=await this.loadModel(n,a);if(!l||!n.connected||n.isHand)return;this._models.push({controller:n,model:l}),this._models.sort((c,d)=>c.controller.index-d.controller.index),this.scene.add(l),l.traverse(c=>{c.layers.set(2),c.matrixAutoUpdate=!1,c.updateMatrix()}),n.model=l}else n.targetRayMode!=="transient-pointer"&&console.warn("XRControllerModel: no model found for "+n.side)}}}onXRControllerRemoved(e){console.debug("XR Controller Removed",e.controller.side,e.controller.index);const i=this._models.findIndex(o=>o.controller===e.controller),n=this._models[i];n&&(this._models.splice(i,1),n.model&&(aa(n.model,!1),n.model.destroy(),n.model=void 0))}onBeforeXR(e,i){this.createHandModel&&(this.customLeftHand||this.customRightHand)&&(i.optionalFeatures=i.optionalFeatures||[],i.optionalFeatures.includes("hand-tracking")||i.optionalFeatures.push("hand-tracking"))}onLeaveXR(e){for(const i of this._models)i&&(i.model&&(aa(i.model,!1),i.model.destroy(),i.model=void 0),i.controller.model===i.model&&(i.controller.model=null));this._models.length=0}onBeforeRender(){if(q.active&&(ts&&(Fs[0]=Date.now()),this.updateRendering(q.active),ts)){const e=Date.now()-Fs[0];Fs.push(e),Fs.length>=30&&(Fs[0]=0,Fs.reduce((i,n)=>i+n,0)/Fs.length,Fs.length=0)}}updateRendering(e){var i,n,o,a,l;for(let c=0;c<this._models.length;c++){const d=this._models[c];if(!d)continue;const u=d.controller;if(!u.connected){ts&&console.warn("XRControllerModel.onUpdateXR: controller is not connected anymore",u.side,u.hand);continue}if(d.model&&!d.handmesh)d.model.matrixAutoUpdate=!1,d.model.matrix.copy(u.gripMatrix),d.model.visible=u.isTracking,(i=e.rig)==null||i.gameObject.add(d.model);else if(u.inputSource.hand&&d.handmesh){const f=e.referenceSpace,m=this.context.renderer.xr.getHand(u.index);if(f&&e.frame.getJointPose){for(const g of u.inputSource.hand.values()){const _=m.joints[g.jointName];if(_){const y=u.getHandJointPose(g);if(y){const b=y.transform.position,v=y.transform.orientation;_.position.copy(b),_.quaternion.copy(v),_.matrixAutoUpdate=!1}_.visible=y!=null}}d.model&&(d.model.visible=u.isTracking,d.model.visible&&d.model.parent!==((n=e.rig)==null?void 0:n.gameObject)&&((o=e.rig)==null||o.gameObject.add(d.model))),(a=d.model)!=null&&a.visible&&((l=d.handmesh)==null||l.updateMesh(),d.model.matrixAutoUpdate=!1,d.model.matrix.identity(),d.model.applyMatrix4(xa))}}}}async loadModel(e,i){var a;if(!e.connected)return console.warn("XRControllerModel.onXRControllerAdded: controller is not connected anymore",e.side),null;const o=await ee.getOrCreate("",i).instantiate();return aa(o),(a=q.active)!=null&&a.isPassThrough&&o.traverseVisible(l=>{this.makeOccluder(l)}),o}async loadHandModel(e,i){const n=this.context,o=n.renderer.xr.getHand(i.index);o||(ts?N.DrawLabel(i.rayWorldPosition,"No hand found for index "+i.index,.05,5):console.warn("No hand found for index "+i.index));const a=new Y.GLTFLoader;Lu(a,n),await ou(a,n,this.sourceId??"");const l=Gu(a);let c="";const d=i.side==="left"?this.customLeftHand:this.customRightHand;d?(c=d.url.split(".").slice(0,-1).join("."),a.setPath("")):(c=i.inputSource.handedness==="left"?"left":"right",a.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/"));const u=new h.Object3D;aa(u);const f=new Y.XRHandMeshModel(u,o,a.path,c,a,m=>{var _;const g=l.gltf;((_=g==null?void 0:g.scene.children)==null?void 0:_.length)===0&&(g.scene.children[0]=m),dn().createBuiltinComponents(e.context,e.sourceId||c,l.gltf,null,l),m.traverse(y=>{var b;y.layers.set(2),(b=q.active)!=null&&b.isPassThrough&&!d&&this.makeOccluder(y),y instanceof h.Mesh&&re.NEEDLE_progressive.assignMeshLOD(y,0)}),i.connected||(ts&&N.DrawLabel(i.rayWorldPosition,"Hand is loaded but not connected anymore",.05,5),m.removeFromParent())});if(ts&&u.add(new h.AxesHelper(.5)),i.inputSource.hand){ts&&console.log(i.inputSource.hand);for(const m of i.inputSource.hand.values())if(o.joints[m.jointName]===void 0){const g=new h.Group;g.matrixAutoUpdate=!1,g.visible=!0,o.joints[m.jointName]=g,o.add(g)}}else ts&&N.DrawLabel(i.rayWorldPosition,"No inputSource.hand found for index "+i.index,.05,5);return{handObject:u,handmesh:f}}makeOccluder(e){if(e instanceof h.Mesh){let i=e.material;i instanceof h.Material&&(i=e.material=i.clone(),i.depthWrite=!0,i.depthTest=!0,i.colorWrite=!1,e.receiveShadow=!1,e.renderOrder=-100)}}}r(Vn,"factory",new Y.XRControllerModelFactory);Zu([p()],Vn.prototype,"createControllerModel",2);Zu([p()],Vn.prototype,"createHandModel",2);Zu([p(ee)],Vn.prototype,"customLeftHand",2);Zu([p(ee)],Vn.prototype,"customRightHand",2);class Ju extends D{}var ZM=Object.defineProperty,JM=Object.getOwnPropertyDescriptor,Mo=(s,t,e,i)=>{for(var n=i>1?void 0:i?JM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&ZM(t,e,n),n};const lp=S("debugwebxr");class Mi extends D{constructor(){super(...arguments);r(this,"movementSpeed",1.5);r(this,"rotationStep",30);r(this,"useTeleport",!0);r(this,"usePinchToTeleport",!0);r(this,"useTeleportTarget",!1);r(this,"useTeleportFade",!1);r(this,"showRays",!0);r(this,"showHits",!0);r(this,"isXRMovementHandler",!0);r(this,"xrSessionMode","immersive-vr");r(this,"_didApplyRotation",!1);r(this,"_didTeleport",!1);r(this,"_teleportBuffer",new Array);r(this,"_plane",null);r(this,"_lines",[]);r(this,"_hitDiscs",[]);r(this,"_hitDistances",[]);r(this,"_lastHitDistances",[]);r(this,"hitPointRaycastFilter",e=>e.type==="SkinnedMesh"?"continue in children":!0)}onUpdateXR(e){const i=e.xr.rig;if(!(i!=null&&i.gameObject)||e.xr.isPassThrough)return;const n=e.xr.leftController,o=e.xr.rightController;n&&this.onHandleMovement(n,i.gameObject),o&&(this.onHandleRotation(o,i.gameObject),this.useTeleport&&this.onHandleTeleport(o,i.gameObject))}onLeaveXR(e){for(const i of this._lines)i.removeFromParent();for(const i of this._hitDiscs)i==null||i.removeFromParent()}onBeforeRender(){var e;(e=this.context.xr)!=null&&e.running&&(this.showRays&&this.renderRays(this.context.xr),this.showHits&&this.renderHits(this.context.xr))}onHandleMovement(e,i){const n=e.getStick("xr-standard-thumbstick");if(n.x!=0||n.y!=0){const o=V(n.x,0,n.y);o.multiplyScalar(this.context.time.deltaTimeUnscaled*this.movementSpeed);const a=Ne(i);o.multiplyScalar(a.x),o.applyQuaternion(e.xr.poseOrientation),o.y=0,o.applyQuaternion(i.worldQuaternion),i.position.add(o),i.updateWorldMatrix(!1,!1);for(const l of i.children)l.updateWorldMatrix(!1,!1)}}onHandleRotation(e,i){if(e._isMxInk)return;const o=e.getStick("xr-standard-thumbstick").x;if(this._didApplyRotation)Math.abs(o)<.3&&(this._didApplyRotation=!1);else if(Math.abs(o)>.5){this._didApplyRotation=!0;const a=o>0?1:-1,l=K(this.context.mainCamera).clone();i.rotateY(a*z.toRadians(this.rotationStep));const d=K(this.context.mainCamera).clone().sub(l);d.y=0,i.position.sub(d)}}onHandleTeleport(e,i){var o,a,l,c,d;let n=0;if(e.hand&&this.usePinchToTeleport&&e.isTeleportGesture){const u=e.getPointerId("primary");if(u!=null&&this.context.input.getIsPointerIdInUse(u))return;const f=e.getGesture("pinch");f&&(n=f.value)}else n=(o=e.getStick("xr-standard-thumbstick"))==null?void 0:o.y;if(this._didTeleport)n>=0&&n<.4?this._didTeleport=!1:n<0&&n>-.4&&(this._didTeleport=!1);else if(n>.8){this._didTeleport=!0;const u=this.context.physics.raycastFromRay(e.ray)[0];if(u&&u.object instanceof Y.GroundedSkybox){const m=(a=u.normal)==null?void 0:a.dot(V(0,1,0));if(m!==void 0&&m<.4)return}let f=u==null?void 0:u.point;if(!f&&!this.useTeleportTarget){this._plane||(this._plane=new h.Plane(new h.Vector3(0,1,0),0));const m=i.worldPosition;this._plane.setFromNormalAndCoplanarPoint(new h.Vector3(0,1,0),m);const g=e.ray;f=m.clone(),this._plane.intersectLine(new h.Line3(g.origin,V(g.direction).multiplyScalar(1e4).add(g.origin)),f),f.distanceTo(m)>i.scale.x*10&&(f=null)}if(f){if(this.useTeleportTarget&&!C.getComponentInParent(u.object,Ju))return;const m=f.clone();if(lp&&N.DrawSphere(f,.025,16711680,5),(l=this.context.mainCamera)==null?void 0:l.position){const _=(c=this.context.xr)==null?void 0:c.getUserOffsetInRig();_&&(_.y=0,m.sub(_),lp&&N.DrawWireSphere(_.add(m),.025,65280,5))}this._teleportBuffer.push(i.matrix.clone()),this._teleportBuffer.length>10&&this._teleportBuffer.shift(),this.useTeleportFade?(d=e.xr.fadeTransition())==null||d.then(()=>{i.worldPosition=m}):i.worldPosition=m}}else if(n<-.8&&(this._didTeleport=!0,this._teleportBuffer.length>0)){const u=this._teleportBuffer.pop();u&&u.decompose(i.position,i.quaternion,i.scale)}}renderRays(e){var i;for(let n=0;n<this._lines.length;n++){const o=this._lines[n];o&&(o.visible=!1)}for(let n=0;n<e.controllers.length;n++){const o=e.controllers[n];let a=this._lines[n];if(!o.connected||!o.isTracking||!o.ray||o.targetRayMode==="transient-pointer"||!o.hasSelectEvent){a&&(a.visible=!1);continue}a||(a=this.createRayLineObject(),a.scale.z=.5,this._lines[n]=a),o.updateRayWorldPosition(),o.updateRayWorldQuaternion();const l=o.rayWorldPosition,c=o.rayWorldQuaternion;a.position.copy(l),a.quaternion.copy(c);const d=e.rigScale,u=this.usePinchToTeleport&&o.isTeleportGesture,f=this._lastHitDistances[n],m=this._hitDistances[n]!=null,g=f??d;a.scale.set(d,d,g),a.visible=!0,a.layers.disableAll(),a.layers.enable(2);let _=a.material.opacity;u?_=1:this.showHits&&g<e.rigScale*.5?_=0:(i=o.getButton("primary"))!=null&&i.pressed?_=.5:_=m?.2:.1,a.material.opacity=z.lerp(a.material.opacity,_,this.context.time.deltaTimeUnscaled/.1),a.parent!==this.context.scene&&this.context.scene.add(a)}}renderHits(e){var i;for(const n of this._hitDiscs){if(!n)continue;const o=n.controller;if(!o||!o.connected||!o.isTracking){n.visible=!1;continue}}for(let n=0;n<e.controllers.length;n++){const o=e.controllers[n];if(!o.connected||!o.isTracking||!o.ray||!o.hasSelectEvent)continue;let a=this._hitDiscs[n],l=!0;const c=o.getPointerId("primary");c!=null&&this.context.input.getIsPointerIdInUse(c)&&(a&&(a.visible=!1),this._hitDistances[n]=null,this._lastHitDistances[n]=0,l=!1);const d=this.context.time.smoothedFps>=59?1:10;if((this.context.time.frame+o.index)%d!==0&&(l=!1),!l){const m=this._hitDiscs[n];m&&m.visible&&m.hit&&this.updateHitPointerPosition(o,m,m.hit.distance);continue}const u=this.context.physics.raycastFromRay(o.ray,{testObject:this.hitPointRaycastFilter,precise:!1});let f=u.find(m=>this.usePinchToTeleport&&o.isTeleportGesture?!0:this.isObjectWithInteractiveComponent(m.object));if(f||(f=u[0]),a&&(a.controller=o,a.hit=f),this._hitDistances[n]=(f==null?void 0:f.distance)||null,f){this._lastHitDistances[n]=f.distance;const m=e.rigScale??1;lp&&(N.DrawWireSphere(f.point,.025*m,16711680),N.DrawLabel(V(0,.2,0).add(f.point),f.object.name,.02,0)),a||(a=this.createHitPointObject(),this._hitDiscs[n]=a),a.hit=f,a.visible=f.distance>m*.05;let g=.01*(m+f.distance);const _=(i=o.getButton("primary"))==null?void 0:i.pressed;_&&(g*=1.1),a.scale.set(g,g,g),a.layers.set(2);let y=a.material.opacity;if(_?y=1:y=f.distance<.15*m?.2:.6,a.material.opacity=z.lerp(a.material.opacity,y,this.context.time.deltaTimeUnscaled/.1),a.visible){if(f.normal){this.updateHitPointerPosition(o,a,f.distance);const b=f.normal.applyQuaternion(ye(f.object));a.quaternion.setFromUnitVectors(eR,b)}else this.updateHitPointerPosition(o,a,f.distance);a.parent!==this.context.scene&&this.context.scene.add(a)}}else this._hitDiscs[n]&&(this._hitDiscs[n].visible=!1)}}isObjectWithInteractiveComponent(e,i=0){return Jd(e)||e.isUI===!0?!0:e.isScene?!1:e.parent?this.isObjectWithInteractiveComponent(e.parent,i+1):!1}updateHitPointerPosition(e,i,n){const o=V(e.rayWorldPosition);o.add(V(0,0,n-.01).applyQuaternion(e.rayWorldQuaternion)),i.position.lerp(o,this.context.time.deltaTimeUnscaled/.05)}createHitPointObject(){const e=new h.Mesh(new h.SphereGeometry(.3,6,6),new h.MeshBasicMaterial({color:15658734,opacity:.7,transparent:!0,depthTest:!1,depthWrite:!1,side:h.DoubleSide}));return e.layers.disableAll(),e.layers.enable(2),e}createRayLineObject(){const e=new Y.Line2;e.layers.disableAll(),e.layers.enable(2);const i=new Y.LineGeometry;e.geometry=i;const n=new Float32Array(9);n.set([0,0,.02,0,0,.4,0,0,1]),i.setPositions(n);const o=new Float32Array(9);o.set([1,1,1,.1,.1,.1,0,0,0]),i.setColors(o);const a=new Y.LineMaterial({color:16777215,vertexColors:!0,worldUnits:!0,linewidth:.004,transparent:!0,depthWrite:!1,blending:h.AdditiveBlending,dashed:!1});return e.material=a,e}}Mo([p()],Mi.prototype,"movementSpeed",2);Mo([p()],Mi.prototype,"rotationStep",2);Mo([p()],Mi.prototype,"useTeleport",2);Mo([p()],Mi.prototype,"usePinchToTeleport",2);Mo([p()],Mi.prototype,"useTeleportTarget",2);Mo([p()],Mi.prototype,"useTeleportFade",2);Mo([p()],Mi.prototype,"showRays",2);Mo([p()],Mi.prototype,"showHits",2);const eR=new h.Vector3(0,1,0);var tR=Object.defineProperty,iR=Object.getOwnPropertyDescriptor,ut=(s,t,e,i)=>{for(var n=i>1?void 0:i?iR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&tR(t,e,n),n};const Pl=S("debugwebxr"),nR=S("debugusdz");var Tp;const fa=(Tp=class extends D{constructor(){super(...arguments);r(this,"createVRButton",!0);r(this,"createARButton",!0);r(this,"createSendToQuestButton",!0);r(this,"createQRCode",!0);r(this,"useDefaultControls",!0);r(this,"showControllerModels",!0);r(this,"showHandModels",!0);r(this,"usePlacementReticle",!0);r(this,"customARPlacementReticle");r(this,"usePlacementAdjustment",!0);r(this,"arScale",1);r(this,"useXRAnchor",!1);r(this,"autoPlace",!0);r(this,"autoCenter",!1);r(this,"useQuicklookExport",!1);r(this,"useDepthSensing",!1);r(this,"useSpatialGrab",!0);r(this,"defaultAvatar");r(this,"_playerSync");r(this,"_createdComponentsInSession",[]);r(this,"_usdzExporter");r(this,"_exitXRMenuButton");r(this,"_previousXRState",0);r(this,"_spatialGrabRaycaster");r(this,"onAvatarSpawned",t=>{Pl&&console.log("WebXR.onAvatarSpawned",t),C.getComponentInChildren(t,po)??(e=C.addComponent(t,po))});r(this,"_buttonFactory");r(this,"_buttons",[])}awake(){q.getXRSync(this.context)}onEnable(){var t,e;window.location.protocol!=="https:"&&me('<a href="https://developer.mozilla.org/en-US/docs/Web/API/WebXR_Device_API" target="_blank">WebXR</a> only works on secure connections (https).'),this.useQuicklookExport&&(C.findObjectOfType(Ie)||(Pl&&console.log("WebXR: Adding USDZExporter"),this._usdzExporter=C.addComponent(this.gameObject,Ie),this._usdzExporter.objectToExport=this.context.scene,this._usdzExporter.autoExportAnimations=!0,this._usdzExporter.autoExportAudioSources=!0)),this.handleCreatingHTML(),this.handleOfferSession(),this.defaultAvatar===!0&&(Pl&&console.warn("WebXR: No default avatar set, using static default avatar"),this.defaultAvatar=new ee("https://cdn.needle.tools/static/avatars/DefaultAvatar.glb")),this.defaultAvatar&&(this._playerSync=this.gameObject.getOrAddComponent(tl),this._playerSync.autoSync=!1),this._playerSync&&typeof this.defaultAvatar!="boolean"&&(this._playerSync.asset=this.defaultAvatar,(t=this._playerSync.onPlayerSpawned)==null||t.removeEventListener(this.onAvatarSpawned),(e=this._playerSync.onPlayerSpawned)==null||e.addEventListener(this.onAvatarSpawned))}onDisable(){var t;(t=this._usdzExporter)==null||t.destroy(),this.removeButtons()}async handleOfferSession(){return this.createVRButton&&await q.isVRSupported()&&this.createVRButton?q.offerSession("immersive-vr","default",this.context):this.createARButton&&await q.isARSupported()&&this.createARButton?q.offerSession("immersive-ar","default",this.context):!1}get session(){return q.active??null}get sessionMode(){return q.activeMode??null}async enterVR(t){return q.start("immersive-vr",t,this.context)}async enterAR(t){return q.start("immersive-ar",t,this.context)}exitXR(){q.stop()}get isActiveWebXR(){return!fa.activeWebXRComponent||fa.activeWebXRComponent===this}onBeforeXR(t,e){var i;if(!this.isActiveWebXR){console.warn(`WebXR: another WebXR component is already active (${(i=fa.activeWebXRComponent)==null?void 0:i.name}). This is ignored: ${this.name}`);return}fa.activeWebXRComponent=this,t=="immersive-ar"&&this.useDepthSensing&&(e.optionalFeatures=e.optionalFeatures||[],e.optionalFeatures.push("depth-sensing"))}async onEnterXR(t){if(!this.isActiveWebXR)return;Pl&&console.log("WebXR onEnterXR"),this._previousXRState=vt.Global.Mask;const e=t.xr.isVR;if(vt.Global.Set(e?Tn.VR:Tn.AR),t.xr.isAR){let i=C.findObjectOfType(Cs);if(!i)if(this.usePlacementReticle){const n=new h.Object3D;for(const o of this.context.scene.children)n.add(o);this.context.scene.add(n),i=C.addComponent(n,Cs),this._createdComponentsInSession.push(i)}else(Pl||B())&&console.warn("WebXR: No WebARSessionRoot found in scene and usePlacementReticle is disabled in WebXR component.");i&&(i.customReticle=this.customARPlacementReticle,i.arScale=this.arScale,i.arTouchTransform=this.usePlacementAdjustment,i.autoPlace=this.autoPlace,i.autoCenter=this.autoCenter,i.useXRAnchor=this.useXRAnchor)}this.useDefaultControls&&this.setDefaultMovementEnabled(!0),(this.showControllerModels||this.showHandModels)&&this.setDefaultControllerRenderingEnabled(!0),this.useSpatialGrab&&(this._spatialGrabRaycaster=C.findObjectOfType(ro)??void 0,this._spatialGrabRaycaster||(this._spatialGrabRaycaster=this.gameObject.addComponent(ro))),this.createLocalAvatar(t.xr),t.xr.isScreenBasedAR||(this._exitXRMenuButton=this.context.menu.appendChild({label:"Quit XR",onClick:()=>this.exitXR(),icon:"exit_to_app",priority:2e4}))}onUpdateXR(t){this.isActiveWebXR&&this._spatialGrabRaycaster&&(this._spatialGrabRaycaster.enabled=this.useSpatialGrab)}onLeaveXR(t){var e,i;if((e=this._exitXRMenuButton)==null||e.remove(),!!this.isActiveWebXR){vt.Global.Set(this._previousXRState),(i=this._playerSync)==null||i.destroyInstance();for(const n of this._createdComponentsInSession)n.destroy();this._createdComponentsInSession.length=0,this.handleOfferSession(),Vc(1).then(()=>fa.activeWebXRComponent=null)}}setDefaultMovementEnabled(t){let e=this.gameObject.getComponent(Mi);return!e&&t&&(e=this.gameObject.addComponent(Mi),this._createdComponentsInSession.push(e)),e&&(e.enabled=t),e}setDefaultControllerRenderingEnabled(t){let e=this.gameObject.getComponent(Vn);return!e&&t&&(e=this.gameObject.addComponent(Vn),this._createdComponentsInSession.push(e),e.createControllerModel=this.showControllerModels,e.createHandModel==this.showHandModels),e&&(e.enabled=t),e}async createLocalAvatar(t){this._playerSync&&t.running&&typeof this.defaultAvatar!="boolean"&&(this._playerSync.asset=this.defaultAvatar,await this._playerSync.getInstance())}getButtonsContainer(){return this.getButtonsFactory()}getButtonsFactory(){return this._buttonFactory||(this._buttonFactory=ws.getOrCreate()),this._buttonFactory}handleCreatingHTML(){if(this.createARButton||this.createVRButton||this.useQuicklookExport){if((exports.DeviceUtilities.isiOS()&&exports.DeviceUtilities.isSafari()||nR)&&this.useQuicklookExport){const e=C.findObjectOfType(Ie);if(!e||e&&e.allowCreateQuicklookButton){const i=this.getButtonsFactory().createQuicklookButton();this.addButton(i,50)}}if(this.createARButton){const e=this.getButtonsFactory().createARButton();this.addButton(e,50)}if(this.createVRButton){const e=this.getButtonsFactory().createVRButton();this.addButton(e,50)}}if(this.createSendToQuestButton&&!exports.DeviceUtilities.isQuest()&&q.isVRSupported().then(e=>{if(!e){const i=this.getButtonsFactory().createSendToQuestButton();this.addButton(i,50)}}),this.createQRCode){const e=ku(qn);if(e&&e.createQRCodeButton===!1)B()&&console.warn("WebXR: QRCode button is disabled in the Needle Menu component");else if(!exports.DeviceUtilities.isMobileDevice()){const i=an.getOrCreate().createQRCode();this.addButton(i,50)}}}addButton(t,e){this._buttons.push(t),t.setAttribute("priority",e.toString()),this.context.menu.appendChild(t)}removeButtons(){for(const t of this._buttons)t.remove();this._buttons.length=0}},r(Tp,"activeWebXRComponent",null),Tp);let $e=fa;ut([p()],$e.prototype,"createVRButton",2);ut([p()],$e.prototype,"createARButton",2);ut([p()],$e.prototype,"createSendToQuestButton",2);ut([p()],$e.prototype,"createQRCode",2);ut([p()],$e.prototype,"useDefaultControls",2);ut([p()],$e.prototype,"showControllerModels",2);ut([p()],$e.prototype,"showHandModels",2);ut([p()],$e.prototype,"usePlacementReticle",2);ut([p(ee)],$e.prototype,"customARPlacementReticle",2);ut([p()],$e.prototype,"usePlacementAdjustment",2);ut([p()],$e.prototype,"arScale",2);ut([p()],$e.prototype,"useXRAnchor",2);ut([p()],$e.prototype,"autoPlace",2);ut([p()],$e.prototype,"autoCenter",2);ut([p()],$e.prototype,"useQuicklookExport",2);ut([p()],$e.prototype,"useDepthSensing",2);ut([p()],$e.prototype,"useSpatialGrab",2);ut([p(ee)],$e.prototype,"defaultAvatar",2);const Gl=S("debugusdz");function sR(s,t){var l;const e=[],i=C.getComponentsInChildren(s,St),n=C.getComponentsInChildren(s,Et),o=new Array,a=new Array;if(t.injectImplicitBehaviours)for(const c of i){if(!c||!c.runtimeAnimatorController||!c.enabled)continue;const d=c.runtimeAnimatorController.activeState;if(!d||!d.motion||!d.motion.clip||((l=d.motion.clip.tracks)==null?void 0:l.length)<1||o.includes(c))continue;const u=new wr;u.animator=c,u.stateName=d.name,u.trigger="start",u.name="PlayAnimationOnClick_implicitAtStart_"+u.stateName;const f=new h.Object3D;C.addComponent(f,u),a.push(f),o.push(c),s.add(f)}else for(const c of i){if(!c||!c.runtimeAnimatorController||!c.enabled)continue;Gl&&console.log(c);const d=[];for(const u of c.runtimeAnimatorController.enumerateActions()){Gl&&console.log(u);const f=u.getClip();d.includes(f)||d.push(f)}e.push({root:c.gameObject,clips:d})}if(t.injectImplicitBehaviours)for(const c of n){if(!c||!c.clip||!c.enabled||!c.playAutomatically||o.includes(c))continue;const d=new wr;d.animation=c,d.stateName=c.clip.name,d.trigger="start",d.name="PlayAnimationOnClick_implicitAtStart_"+d.stateName;const u=new h.Object3D;C.addComponent(u,d),a.push(u),o.push(c),s.add(u)}else for(const c of n){Gl&&console.log(c);const d=[];for(const u of c.animations)d.includes(u)||d.push(u);e.push({root:c.gameObject,clips:d})}Gl&&(e==null?void 0:e.length)>0&&console.log("USDZ Animation Clips without behaviours",e);for(const c of e)for(const d of c.clips)t.registerAnimation(c.root,d);return a}function oR(s,t){const e=C.getComponentsInChildren(s,je),i=C.getComponentsInChildren(s,ho),n=new Array,o=new Array;Gl&&console.log({audioSources:e,playAudioOnClicks:i});for(const a of i){if(!a.target)continue;const l=e.indexOf(a.target);l>-1&&e.splice(l,1)}for(const a of e){if(!a||!a.clip||a.volume<=0||n.includes(a))continue;const l=new ho;l.target=a,l.name="PlayAudioOnClick_implicitAtStart_",l.trigger="start";const c=new h.Object3D;C.addComponent(c,l),console.log("implicit PlayAudioOnStart",c,l),o.push(c),n.push(a),s.add(c)}return o}function rR(s){return new st("DisableAtStart",ht.sceneStartTrigger(),he.fadeAction(s,0,!1))}function rb(s,t){const e=s.domElement.shadowRoot.querySelector("link[rel='ar']");if(e)return e;const i=document.createElement("div");i.classList.add("menu"),i.classList.add("quicklook-menu"),i.style.display="none",i.style.visibility="hidden";const n=document.createElement("button");n.id="open-in-ar",t?(n.innerText="View in AR",n.title="View this scene in AR. The scene will be exported to USDZ and opened with Apple's QuickLook."):(n.innerText="View in AR",n.title="Download this scene for AR. Open the downloaded USDZ file to view it in AR using Apple's QuickLook."),i.appendChild(n);const o=document.createElement("a");o.id="needle-usdz-link",o.style.display="none",o.rel="ar",o.href="",o.target="_blank",i.appendChild(o);const a=document.createElement("img");return a.id="button",o.appendChild(a),s.domElement.shadowRoot.appendChild(i),o}var aR=Object.defineProperty,lR=Object.getOwnPropertyDescriptor,Ot=(s,t,e,i)=>{for(var n=i>1?void 0:i?lR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&aR(t,e,n),n};const di=S("debugusdz"),cR=S("debugusdzpruning");class Ro{constructor(){r(this,"callToAction");r(this,"checkoutTitle");r(this,"checkoutSubtitle");r(this,"callToActionURL")}}Ot([p()],Ro.prototype,"callToAction",2);Ot([p()],Ro.prototype,"checkoutTitle",2);Ot([p()],Ro.prototype,"checkoutSubtitle",2);Ot([p()],Ro.prototype,"callToActionURL",2);var fd;const bm=(fd=class extends D{constructor(){super(...arguments);r(this,"objectToExport");r(this,"autoExportAnimations",!0);r(this,"autoExportAudioSources",!0);r(this,"exportFileName");r(this,"customUsdzFile");r(this,"customBranding");r(this,"anchoringType","plane");r(this,"maxTextureSize",2048);r(this,"planeAnchoringAlignment","horizontal");r(this,"interactive",!0);r(this,"physics",!0);r(this,"allowCreateQuicklookButton",!0);r(this,"quickLookCompatible",!0);r(this,"extensions",[]);r(this,"link");r(this,"button");r(this,"onClickedOpenInARElement",t=>{t.preventDefault(),this.exportAndOpen()});r(this,"_currentExportTasks",new Map);r(this,"_previousTimeScale",1);r(this,"lastCallback");r(this,"_rootSessionRootWasAppliedTo",null);r(this,"_rootPositionBeforeExport",new h.Vector3);r(this,"_rootRotationBeforeExport",new h.Quaternion);r(this,"_rootScaleBeforeExport",new h.Vector3)}start(){var t,e,i;di&&(console.log("USDZExporter",this),console.log("Debug USDZ Mode. Press 'T' to export"),window.addEventListener("keydown",n=>{switch(n.key){case"t":this.exportAndOpen();break}})),this.objectToExport||(this.objectToExport=this.gameObject),!((e=(t=this.objectToExport)==null?void 0:t.children)!=null&&e.length)&&!((i=this.objectToExport)!=null&&i.isMesh)&&(this.objectToExport=this.context.scene)}onEnable(){var i;const t=exports.DeviceUtilities.supportsQuickLookAR(),e=exports.DeviceUtilities.isiOS()||exports.DeviceUtilities.isiPad();!this.button&&(di||t||e)&&(this.allowCreateQuicklookButton&&(this.button=this.createQuicklookButton()),this.lastCallback=this.quicklookCallback.bind(this),this.link=rb(this.context,t),this.link.addEventListener("message",this.lastCallback)),di&&Ee("USDZ Exporter enabled: "+this.name),(i=document.getElementById("open-in-ar"))==null||i.addEventListener("click",this.onClickedOpenInARElement),xc.registerExporter(this)}onDisable(){var t,e,i;(t=this.button)==null||t.remove(),(e=this.link)==null||e.removeEventListener("message",this.lastCallback),di&&Ee("USDZ Exporter disabled: "+this.name),(i=document.getElementById("open-in-ar"))==null||i.removeEventListener("click",this.onClickedOpenInARElement),xc.unregisterExporter(this)}async exportAsync(){return this.exportAndOpen()}async exportAndOpen(){var i;let t=this.exportFileName??((i=this.objectToExport)==null?void 0:i.name)??this.name;if(t+="-"+nw(),no()||(t!==""&&(t+="-"),t+="MadeWithNeedle"),this.link||(this.link=rb(this.context,exports.DeviceUtilities.supportsQuickLookAR())),this.customUsdzFile)return di&&console.log("Exporting custom usdz",this.customUsdzFile),this.openInQuickLook(this.customUsdzFile,t),null;if(!this.objectToExport)return console.warn("No object to export",this),null;const e=await this.export(this.objectToExport);return e?(di&&console.log("USDZ generation done. Downloading as "+t),this.openInQuickLook(e,t),e):(console.error("USDZ generation failed. Please report a bug",this),null)}async export(t){if(!t)return console.warn("No object to export"),null;const e=this._currentExportTasks.get(t);if(e)return e;const i=this.internalExport(t);return i instanceof Promise?(this._currentExportTasks.set(t,i),i.then(n=>(this._currentExportTasks.delete(t),n)).catch(n=>(this._currentExportTasks.delete(t),console.error("Error during USDZ export – please report a bug!",n),null))):i}async internalExport(t){se.start("export-usdz",{onProgress:M=>{this.dispatchEvent(new CustomEvent("export-progress",{detail:{progress:M}}))}}),se.report("export-usdz",{message:"Starting export",totalSteps:40,currentStep:0}),se.report("export-usdz",{message:"Load progressive textures",autoStep:5}),se.start("export-usdz-textures","export-usdz");const e=C.getComponentsInChildren(t,li);for(const M of e)M&&M.enabled&&M.updateSprite(!0);const i=C.getComponentsInChildren(t,Ve),n=new Array;let o=0;for(const M of i){for(const R of M.sharedMeshes)if(R){const A=re.NEEDLE_progressive.assignMeshLOD(R,0);A instanceof Promise&&n.push(new Promise((I,E)=>{A.then(()=>{o++,se.report("export-usdz-textures",{message:"Loaded progressive mesh",currentStep:o,totalSteps:n.length}),I()}).catch(j=>E(j))}))}for(const R of M.sharedMaterials)if(R){const A=re.NEEDLE_progressive.assignTextureLOD(R,0);A instanceof Promise&&n.push(new Promise((I,E)=>{A.then(()=>{o++,se.report("export-usdz-textures",{message:"Loaded progressive texture",currentStep:o,totalSteps:n.length}),I()}).catch(j=>E(j))}))}}di&&Ee("Progressive Loading: "+n.length),await Promise.all(n),di&&Ee("Progressive Loading: done"),se.end("export-usdz-textures");const a=vt.Global.Mask;vt.Global.Set(Tn.AR);const l=new lw,c=new lh(this.quickLookCompatible);let d;const u=[];this.interactive&&(u.push(new qu),u.push(new Co),globalThis.false&&C.getComponentsInChildren(t,ue).length>0&&(this.physics?(d=new Xu,u.push(d)):B()&&console.warn("USDZExporter: Physics export is disabled, but there are active Rigidbody components in the scene. They will not be exported.")),u.push(new ph),u.push(new Yu));const f=[c,...u,...this.extensions],m={self:this,exporter:l,extensions:f,object:t};se.report("export-usdz","Invoking before-export"),this.dispatchEvent(new CustomEvent("before-export",{detail:m})),this.applyWebARSessionRoot(),this._previousTimeScale=this.context.time.timeScale,this.context.time.timeScale=0,se.report("export-usdz","auto export animations and audio sources");const g=new Array;this.autoExportAnimations&&g.push(...sR(t,c)),f.find(M=>M.extensionName==="Audio")&&this.autoExportAudioSources&&g.push(...oR(t)),l.debug=di,l.pruneUnusedNodes=!cR;const y=gs.instance.objs.map(M=>M.batchedMesh);l.keepObject=M=>{let R=!0;const A=C.getComponent(M,Ve);return A&&!A.enabled&&(R=!1),R&&y.includes(M)&&(R=!1),R&&C.getComponentInParent(M,gn)&&(R=!1),R&&C.getComponentInParent(M,Wn)&&(R=!1),di&&!R&&console.log("USDZExporter: Discarding object",M),R},l.beforeWritingDocument=()=>{if(B()&&c&&d){const M=c.animatedRoots;for(const R of M){const A=C.getComponentsInChildren(R,ue).filter(E=>E.enabled),I=C.getComponents(R,ai).filter(E=>E.enabled&&!E.isTrigger);(A.length>0||I.length>0)&&console.error("An animated object has physics components in its child hierarchy. This can lead to undefined behaviour due to a bug in Apple's QuickLook (FB15925487). Remove the physics components from child objects or verify that you get the expected results.",R)}}};const b=new Array;this.objectToExport&&this.quickLookCompatible&&this.interactive&&this.objectToExport.traverse(M=>{M.visible||b.push(M)});const v=f.find(M=>M.extensionName==="Behaviour");this.interactive&&v&&b.length>0&&v.addBehavior(rR(b));let x=!0;this.quickLookCompatible&&!this.interactive&&(x=!1),this.anchoringType!=="plane"&&this.anchoringType!=="none"&&this.anchoringType!=="image"&&this.anchoringType!=="face"&&(this.anchoringType="plane"),this.planeAnchoringAlignment!=="horizontal"&&this.planeAnchoringAlignment!=="vertical"&&this.planeAnchoringAlignment!=="any"&&(this.planeAnchoringAlignment="horizontal"),se.report("export-usdz","Invoking exporter.parse");const O=await l.parse(this.objectToExport,{ar:{anchoring:{type:this.anchoringType},planeAnchoring:{alignment:this.planeAnchoringAlignment}},extensions:f,quickLookCompatible:this.quickLookCompatible,maxTextureSize:this.maxTextureSize,exportInvisible:x}),k=new Blob([O],{type:"model/vnd.usdz+zip"});this.revertWebARSessionRoot(),this.context.time.timeScale=this._previousTimeScale,se.report("export-usdz","Invoking after-export"),this.dispatchEvent(new CustomEvent("after-export",{detail:m}));for(const M of g)C.destroy(M);return vt.Global.Set(a),se.end("export-usdz"),k}openInQuickLook(t,e){const i=t instanceof Blob?URL.createObjectURL(t):t,n=this.buildQuicklookOverlay();di&&console.log("QuickLook Overlay",n);const o=n.callToAction?encodeURIComponent(n.callToAction):"",a=n.checkoutTitle?encodeURIComponent(n.checkoutTitle):"",l=n.checkoutSubtitle?encodeURIComponent(n.checkoutSubtitle):"";this.link.href=i+`#callToAction=${o}&checkoutTitle=${a}&checkoutSubtitle=${l}&callToActionURL=${n.callToActionURL}`,this.lastCallback||(this.lastCallback=this.quicklookCallback.bind(this),this.link.addEventListener("message",this.lastCallback)),this.link.download=e+".usdz",this.link.click()}download(t,e){bm.save(t,e)}static save(t,e){const i=document.createElement("a");i.style.display="none",document.body.appendChild(i),typeof t=="string"?i.href=t:i.href=URL.createObjectURL(t),i.download=e,i.click(),i.remove()}quicklookCallback(t){if((t==null?void 0:t.data)=="_apple_ar_quicklook_button_tapped"){di&&me("Quicklook closed via call to action button");var e=new CustomEvent("quicklook-button-tapped",{detail:this});if(this.dispatchEvent(e),!e.defaultPrevented){const i=new URLSearchParams(this.link.href);if(i){const n=i.get("callToActionURL");di&&Ee("Quicklook url: "+n),n&&(no()?globalThis.open(n,"_blank"):console.warn("Quicklook closed: custom redirects require a Needle Engine Pro license: https://needle.tools/pricing",n))}}}}buildQuicklookOverlay(){var i,n,o,a,l,c;const t={};return this.customBranding&&Object.assign(t,this.customBranding),no()||(console.log("Custom Quicklook banner text requires pro license: https://needle.tools/pricing"),t.callToAction="Close",t.checkoutTitle="🌵 Made with Needle",t.checkoutSubtitle="_"),(((i=t.callToAction)==null?void 0:i.length)||((n=t.checkoutTitle)==null?void 0:n.length)||((o=t.checkoutSubtitle)==null?void 0:o.length))&&((a=t.callToAction)!=null&&a.length||(t.callToAction="\0"),(l=t.checkoutTitle)!=null&&l.length||(t.checkoutTitle="\0"),(c=t.checkoutSubtitle)!=null&&c.length||(t.checkoutSubtitle="\0")),this.dispatchEvent(new CustomEvent("quicklook-overlay",{detail:t})),t}getARScaleAndTarget(){if(!this.objectToExport)return{scale:1,_invertForward:!1,target:this.gameObject,sessionRoot:null};const t=C.findObjectOfType($e);let e=C.getComponentInParent(this.objectToExport,Cs);e||(e=C.getComponentInChildren(this.objectToExport,Cs));let i=1,n=!1;const o=this.objectToExport;return t?i=t.arScale:e&&(i=e.arScale,n=e.invertForward),{scale:1/i,_invertForward:n,target:o,sessionRoot:(e==null?void 0:e.gameObject)??null}}applyWebARSessionRoot(){if(!this.objectToExport)return;const{scale:t,_invertForward:e,target:i,sessionRoot:n}=this.getARScaleAndTarget(),o=n==null?void 0:n.matrixWorld.clone().invert();this._rootSessionRootWasAppliedTo=i,this._rootPositionBeforeExport.copy(i.position),this._rootRotationBeforeExport.copy(i.quaternion),this._rootScaleBeforeExport.copy(i.scale),i.scale.multiplyScalar(t),e&&i.quaternion.multiply(bm.invertForwardQuaternion),i.updateMatrix(),i.updateMatrixWorld(!0),n&&o&&i.matrix.premultiply(o)}revertWebARSessionRoot(){if(!this.objectToExport||!this._rootSessionRootWasAppliedTo)return;const t=this._rootSessionRootWasAppliedTo;t.position.copy(this._rootPositionBeforeExport),t.quaternion.copy(this._rootRotationBeforeExport),t.scale.copy(this._rootScaleBeforeExport),t.updateMatrix(),t.updateMatrixWorld(!0),this._rootSessionRootWasAppliedTo=null}createQuicklookButton(){const e=ws.getOrCreate().createQuicklookButton();return e.parentNode||this.context.menu.appendChild(e),e}},r(fd,"invertForwardMatrix",new h.Matrix4().makeRotationY(Math.PI)),r(fd,"invertForwardQuaternion",new h.Quaternion().setFromEuler(new h.Euler(0,Math.PI,0))),fd);let Ie=bm;Ot([p(h.Object3D)],Ie.prototype,"objectToExport",2);Ot([p()],Ie.prototype,"autoExportAnimations",2);Ot([p()],Ie.prototype,"autoExportAudioSources",2);Ot([p()],Ie.prototype,"exportFileName",2);Ot([p(URL)],Ie.prototype,"customUsdzFile",2);Ot([p(Ro)],Ie.prototype,"customBranding",2);Ot([p()],Ie.prototype,"anchoringType",2);Ot([p()],Ie.prototype,"maxTextureSize",2);Ot([p()],Ie.prototype,"planeAnchoringAlignment",2);Ot([p()],Ie.prototype,"interactive",2);Ot([p()],Ie.prototype,"physics",2);Ot([p()],Ie.prototype,"allowCreateQuicklookButton",2);Ot([p()],Ie.prototype,"quickLookCompatible",2);var hR=Object.defineProperty,dR=Object.getOwnPropertyDescriptor,Zg=(s,t,e,i)=>{for(var n=i>1?void 0:i?dR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&hR(t,e,n),n};class nl extends D{constructor(){super(...arguments);r(this,"_fog")}get fog(){return this._fog||(this._fog=new h.Fog(0,0,50)),this._fog}get mode(){return 1}set near(e){this.fog.near=e}get near(){return this.fog.near}set far(e){this.fog.far=e}get far(){return this.fog.far}set color(e){this.fog.color.copy(e)}get color(){return this.fog.color}onEnable(){this.scene.fog=this.fog}onDisable(){this.scene.fog===this._fog&&(this.scene.fog=null)}}Zg([p()],nl.prototype,"near",1);Zg([p()],nl.prototype,"far",1);Zg([p(h.Color)],nl.prototype,"color",1);var uR=Object.defineProperty,fR=Object.getOwnPropertyDescriptor,Jg=(s,t,e,i)=>{for(var n=i>1?void 0:i?fR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&uR(t,e,n),n};class jr extends D{constructor(){super(...arguments);r(this,"objectBounds",!1);r(this,"color");r(this,"isGizmo",!0);r(this,"_gizmoObject",null);r(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!Qc||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new h.BoxHelper(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=tg(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),ve.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){var e;for(;this._boxHelper;)(e=this._boxHelper)==null||e.update(),yield}}Jg([p()],jr.prototype,"objectBounds",2);Jg([p(h.Color)],jr.prototype,"color",2);Jg([p()],jr.prototype,"isGizmo",2);var pR=Object.defineProperty,mR=Object.getOwnPropertyDescriptor,e_=(s,t,e,i)=>{for(var n=i>1?void 0:i?mR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&pR(t,e,n),n};class sl extends D{constructor(){super(...arguments);r(this,"isGizmo",!1);r(this,"color0");r(this,"color1");r(this,"gridHelper");r(this,"size");r(this,"divisions");r(this,"offset")}onEnable(){if(this.isGizmo&&!Qc)return;const e=this.size,i=this.divisions;this.gridHelper||(this.gridHelper=new h.GridHelper(e,i,this.color0??new h.Color(.4,.4,.4),this.color1??new h.Color(.6,.6,.6)),this.offset!==void 0&&(this.gridHelper.position.y+=this.offset)),this.gridHelper&&this.gameObject.add(this.gridHelper)}onDisable(){this.gridHelper&&(this.gameObject.remove(this.gridHelper),this.gridHelper=null)}}e_([p()],sl.prototype,"isGizmo",2);e_([p(h.Color)],sl.prototype,"color0",2);e_([p(h.Color)],sl.prototype,"color1",2);var gR=Object.defineProperty,_R=Object.getOwnPropertyDescriptor,t_=(s,t,e,i)=>{for(var n=i>1?void 0:i?_R(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&gR(t,e,n),n};class i_ extends D{constructor(){super(...arguments);r(this,"connectedBody");r(this,"_rigidBody",null)}get rigidBody(){return this._rigidBody}onEnable(){this._rigidBody||(this._rigidBody=this.gameObject.getComponent(ue)),this.rigidBody&&this.connectedBody&&this.startCoroutine(this.create())}*create(){yield,this.rigidBody&&this.connectedBody&&this.activeAndEnabled&&this.createJoint(this.rigidBody,this.connectedBody)}}t_([p(ue)],i_.prototype,"connectedBody",2);class n_ extends i_{createJoint(t,e){var i;(i=this.context.physics.engine)==null||i.addFixedJoint(t,e)}}class mh extends i_{constructor(){super(...arguments);r(this,"anchor");r(this,"axis")}createJoint(e,i){var n;this.axis&&this.anchor&&((n=this.context.physics.engine)==null||n.addHingeJoint(e,i,this.anchor,this.axis))}}t_([p(h.Vector3)],mh.prototype,"anchor",2);t_([p(h.Vector3)],mh.prototype,"axis",2);var yR=Object.defineProperty,bR=Object.getOwnPropertyDescriptor,Xn=(s,t,e,i)=>{for(var n=i>1?void 0:i?bR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&yR(t,e,n),n};function cp(s){return s*Math.PI/180}const ab=300,Us=S("debuglights");class ci extends D{constructor(){super(...arguments);r(this,"type",0);r(this,"range",1);r(this,"spotAngle",1);r(this,"innerSpotAngle",1);r(this,"_color",new h.Color(16777215));r(this,"_shadowNearPlane",.1);r(this,"_shadowBias",0);r(this,"_shadowNormalBias",0);r(this,"_overrideShadowBiasSettings",!1);r(this,"_shadows",1);r(this,"lightmapBakeType",4);r(this,"_intensity",-1);r(this,"_shadowDistance");r(this,"shadowWidth");r(this,"shadowHeight");r(this,"_shadowResolution");r(this,"light");r(this,"_webXRStartedListener");r(this,"_webXREndedListener");r(this,"_webARRoot")}set color(e){this._color=e,this.light!==void 0&&(this.light.color=e)}get color(){return this.light?this.light.color:this._color}set shadowNearPlane(e){var i,n;if(e!==this._shadowNearPlane&&(this._shadowNearPlane=e,((n=(i=this.light)==null?void 0:i.shadow)==null?void 0:n.camera)!==void 0)){const o=this.light.shadow.camera;o.near=e}}get shadowNearPlane(){return this._shadowNearPlane}set shadowBias(e){var i,n;e!==this._shadowBias&&(this._shadowBias=e,((n=(i=this.light)==null?void 0:i.shadow)==null?void 0:n.bias)!==void 0&&(this.light.shadow.bias=e,this.light.shadow.needsUpdate=!0))}get shadowBias(){return this._shadowBias}set shadowNormalBias(e){var i,n;e!==this._shadowNormalBias&&(this._shadowNormalBias=e,((n=(i=this.light)==null?void 0:i.shadow)==null?void 0:n.normalBias)!==void 0&&(this.light.shadow.normalBias=e,this.light.shadow.needsUpdate=!0))}get shadowNormalBias(){return this._shadowNormalBias}set shadows(e){this._shadows=e,this.light&&(this.light.castShadow=e!==0,this.updateShadowSoftHard())}get shadows(){return this._shadows}set intensity(e){var i;if(this._intensity=e,this.light){let n=1;if(this.context.isInXR&&this._webARRoot){const o=(i=this._webARRoot)==null?void 0:i.arScale;typeof o=="number"&&o>0&&(n/=o)}this.light.intensity=e*n}Us&&console.log("Set light intensity to "+this._intensity,e,this)}get intensity(){return this._intensity}get shadowDistance(){const e=this.light;return e!=null&&e.shadow?e.shadow.camera.far:-1}set shadowDistance(e){this._shadowDistance=e;const i=this.light;if(i!=null&&i.shadow){const n=i.shadow.camera;n.far=e,n.updateProjectionMatrix()}}get shadowResolution(){const e=this.light;return e!=null&&e.shadow?e.shadow.mapSize.x:-1}set shadowResolution(e){if(e===this._shadowResolution)return;this._shadowResolution=e;const i=this.light;i!=null&&i.shadow&&(i.shadow.mapSize.set(e,e),i.shadow.needsUpdate=!0)}get isBaked(){return this.lightmapBakeType===2}get selfIsLight(){if(this.gameObject.isLight===!0)return!0;switch(this.gameObject.type){case"SpotLight":case"PointLight":case"DirectionalLight":return!0}return!1}getWorldPosition(e){return this.light?this.type===1?this.light.getWorldPosition(e).multiplyScalar(1):this.light.getWorldPosition(e):e}awake(){this.color=new h.Color(this.color??16777215),Us&&console.log(this.name,this)}onEnable(){Us&&console.log("ENABLE LIGHT",this.name),this.createLight(),!this.isBaked&&(this.light&&(this.light.visible=!0,this.light.intensity=this._intensity,Us&&console.log("Set light intensity to "+this.light.intensity,this.name),this.selfIsLight||this.light.parent!==this.gameObject&&this.gameObject.add(this.light)),this.type===1&&this.startCoroutine(this.updateMainLightRoutine(),ve.LateUpdate))}onDisable(){Us&&console.log("DISABLE LIGHT",this.name),this.light&&(this.selfIsLight?this.light.intensity=0:this.light.visible=!1)}onEnterXR(e){this._webARRoot=C.getComponentInParent(this.gameObject,Cs)??void 0}onLeaveXR(e){}createLight(){const e=this.selfIsLight;if(e&&!this.light)switch(this.light=this.gameObject,this.light.name=this.name,this._intensity=this.light.intensity,this.type){case 1:this.setDirectionalLight(this.light);break}else if(!this.light)switch(this.type){case 1:const i=new h.DirectionalLight(this.color,this.intensity*Math.PI);if(i.position.set(0,0,-ab*.5).applyQuaternion(this.gameObject.quaternion),this.gameObject.add(i.target),mr(i.target,0,0,0),this.light=i,this.gameObject.position.set(0,0,0),this.gameObject.rotation.set(0,0,0),Us){const l=new h.DirectionalLightHelper(this.light,.2,this.color);this.context.scene.add(l)}break;case 0:const n=new h.SpotLight(this.color,this.intensity*Math.PI,this.range,cp(this.spotAngle/2),1-cp(this.innerSpotAngle/2)/cp(this.spotAngle/2),2);n.position.set(0,0,0),n.rotation.set(0,0,0),this.light=n;const o=n.target;n.add(o),o.position.set(0,0,this.range),o.rotation.set(0,0,0);break;case 2:const a=new h.PointLight(this.color,this.intensity*Math.PI,this.range);this.light=a;break}if(this.light){if(this._intensity>=0?this.light.intensity=this._intensity:this._intensity=this.light.intensity,this.shadows!==0?this.light.castShadow=!0:this.light.castShadow=!1,this.light.shadow){this._shadowResolution!==void 0&&this._shadowResolution>4?(this.light.shadow.mapSize.width=this._shadowResolution,this.light.shadow.mapSize.height=this._shadowResolution):(this.light.shadow.mapSize.width=2048,this.light.shadow.mapSize.height=2048),Us&&console.log("Override shadow bias?",this._overrideShadowBiasSettings,this.shadowBias,this.shadowNormalBias),this.light.shadow.bias=this.shadowBias,this.light.shadow.normalBias=this.shadowNormalBias,this.updateShadowSoftHard();const i=this.light.shadow.camera;if(i.near=this.shadowNearPlane,this._shadowDistance!==void 0&&typeof this._shadowDistance=="number"?i.far=this._shadowDistance:i.far=ab*Math.abs(this.gameObject.scale.z),this.gameObject.scale.set(1,1,1),this.shadowWidth!==void 0)i.left=-this.shadowWidth/2,i.right=this.shadowWidth/2;else{const n=this.gameObject.scale.x;i.left*=n,i.right*=n}if(this.shadowHeight!==void 0)i.top=this.shadowHeight/2,i.bottom=-this.shadowHeight/2;else{const n=this.gameObject.scale.y;i.top*=n,i.bottom*=n}this.light.shadow.needsUpdate=!0,Us&&this.context.scene.add(new h.CameraHelper(i))}this.isBaked?this.light.removeFromParent():e||this.gameObject.add(this.light)}}*updateMainLightRoutine(){for(;;){this.type===1&&((!this.context.mainLight||this.intensity>this.context.mainLight.intensity)&&(this.context.mainLight=this),yield);break}}updateShadowSoftHard(){this.light&&this.light.shadow&&(this.shadows===2||(this.light.shadow.radius=1,this.light.shadow.blurSamples=1))}setDirectionalLight(e){e.add(e.target),e.target.position.set(0,0,-1)}}r(ci,"allowChangingRendererShadowMapType",!0);Xn([p()],ci.prototype,"type",2);Xn([p(h.Color)],ci.prototype,"color",1);Xn([p()],ci.prototype,"shadowNearPlane",1);Xn([p()],ci.prototype,"shadowBias",1);Xn([p()],ci.prototype,"shadowNormalBias",1);Xn([p()],ci.prototype,"shadows",1);Xn([p()],ci.prototype,"lightmapBakeType",2);Xn([p()],ci.prototype,"intensity",1);Xn([p()],ci.prototype,"shadowDistance",1);Xn([p()],ci.prototype,"shadowResolution",1);new h.Vector3(0,0,0);var vR=Object.defineProperty,wR=Object.getOwnPropertyDescriptor,gh=(s,t,e,i)=>{for(var n=i>1?void 0:i?wR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&vR(t,e,n),n};const hp=S("debuglods"),xR=S("nolods");class Br{constructor(){r(this,"screenRelativeTransitionHeight");r(this,"distance");r(this,"renderers")}}gh([p()],Br.prototype,"screenRelativeTransitionHeight",2);gh([p()],Br.prototype,"distance",2);gh([p(Ve)],Br.prototype,"renderers",2);class SR{constructor(t){r(this,"model");this.model=t}get renderers(){return this.model.renderers}}class _h extends D{constructor(){super(...arguments);r(this,"fadeMode",0);r(this,"localReferencePoint");r(this,"lodCount",0);r(this,"size",0);r(this,"animateCrossFading",!1);r(this,"lodModels");r(this,"_lods",[]);r(this,"_settings",[]);r(this,"_lodsHandler");r(this,"_distanceFactor",1)}start(){if(hp&&console.log("LODGROUP",this.name,this.lodModels,this),!xR&&!this._lodsHandler&&this.gameObject&&this.lodModels&&Array.isArray(this.lodModels)){const e=[];for(const n of this.lodModels){const o=new SR(n);this._lods.push(o);for(const a of o.renderers)e.includes(a)||e.push(a)}this._lodsHandler=new Array;for(let n=0;n<e.length;n++){const o=new h.LOD;this._lodsHandler.push(o),this.gameObject.add(o)}const i=new h.Object3D;i.name="Cull "+this.name;for(let n=0;n<e.length;n++){const o=e[n],a=this._lodsHandler[n],l=o.gameObject;hp&&console.log(n,l.name);for(const c of this._lods){const d=c.model.distance;let u=null;if(c.renderers.includes(o)?u=l:u=i,u.type==="Group"){console.warn(`LODGroup ${this.name}: Group or MultiMaterial object's are not supported as LOD object: ${u.name}`);continue}hp&&console.log("LEVEL",u.name,d),a.autoUpdate=!1,this.onAddLodLevel(a,u,c.model.distance)}}}}onAfterRender(){if(!this.gameObject||!this._lodsHandler)return;const e=this.context.mainCamera;if(e)for(const i of this._lodsHandler){i.update(e);const n=i.getCurrentLevel(),o=i.levels[n];i.layers.mask=o.object.layers.mask}}onAddLodLevel(e,i,n){if(i===this.gameObject){console.warn("LODGroup component must be on parent object and not mesh directly at the moment",i.name,i);return}e.addLevel(i,n*this._distanceFactor,.01);const o={lod:e,levelIndex:e.levels.length-1,distance:n};this._settings.push(o)}distanceFactor(e){if(e!==this._distanceFactor){this._distanceFactor=e;for(const i of this._settings){const n=i.lod.levels[i.levelIndex];n.distance=i.distance*e}}}}gh([p(h.Vector3)],_h.prototype,"localReferencePoint",2);gh([p(Br)],_h.prototype,"lodModels",2);var CR=Object.defineProperty,PR=Object.getOwnPropertyDescriptor,OR=(s,t,e,i)=>{for(var n=i>1?void 0:i?PR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&CR(t,e,n),n};const sd=S("debugnestedgltf");class ef extends D{constructor(){super(...arguments);r(this,"filePath");r(this,"loadAssetInParent",!0);r(this,"_isLoadingOrDoneLoading",!1)}listenToProgress(e){var i;(i=this.filePath)==null||i.beginListenDownload(e)}preload(){var e;(e=this.filePath)==null||e.preload()}async start(){var i,n,o,a,l;if(this._isLoadingOrDoneLoading)return;sd&&console.log(this,this.guid);const e=this.gameObject.parent;if(e){this._isLoadingOrDoneLoading=!0;const c=new pn;c.idProvider=new xt(this.hash(this.guid)),c.parent=this.loadAssetInParent!==!1?e:this.gameObject,this.gameObject.updateMatrix();const d=this.gameObject.matrix;sd&&console.log("Load nested:",((i=this.filePath)==null?void 0:i.url)??this.filePath,this.gameObject.position);const u=await((o=(n=this.filePath)==null?void 0:n.instantiate)==null?void 0:o.call(this.filePath,c));sd&&console.log("Nested loaded:",((a=this.filePath)==null?void 0:a.url)??this.filePath,u),u&&this.loadAssetInParent!==!1&&(u.matrixAutoUpdate=!1,u.matrix.identity(),u.applyMatrix4(d),u.matrixAutoUpdate=!0,u.layers.disableAll(),u.layers.set(this.layer),this.dispatchEvent(new CustomEvent("loaded",{detail:{instance:u,assetReference:this.filePath}}))),sd&&console.log("Nested loading done:",((l=this.filePath)==null?void 0:l.url)??this.filePath,u)}}onDestroy(){var e;(e=this.filePath)==null||e.unload()}hash(e){let i=0;for(let n=0;n<e.length;n++)i=e.charCodeAt(n)+((i<<5)-i);return i}}OR([p(ee)],ef.prototype,"filePath",2);var MR=Object.defineProperty,RR=Object.getOwnPropertyDescriptor,s_=(s,t,e,i)=>{for(var n=i>1?void 0:i?RR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&MR(t,e,n),n};const kR=S("debugnet"),vm=class extends D{constructor(){super(...arguments);r(this,"url",null);r(this,"urlParameterName",null);r(this,"localhost",null)}awake(){kR&&console.log(this),this.context.connection.registerProvider(this)}getWebsocketUrl(){let t=this.url?vm.GetUrl(this.url,this.localhost):null;if(this.urlParameterName){const o=S(this.urlParameterName);o&&typeof o=="string"&&(t=o)}if(!t)return null;const i=new RegExp("(((https?)|(?<socket_prefix>wss?))://)?(www.)?(?<url>.+)","gm").exec(t);return i!=null&&i.groups?(i==null?void 0:i.groups.socket_prefix)?t:"wss://"+(i==null?void 0:i.groups.url):null}static GetUrl(t,e){let i=t;const n=vm.IsLocalNetwork()&&e;if(n&&(i=e),t!=null&&t.startsWith("/")){const o=n?i:window.location.origin;o!=null&&o.endsWith("/")&&t.startsWith("/")&&(t=t.substring(1)),i=o+t}return i}static IsLocalNetwork(t=window.location.hostname){return Xt(t)}};let ol=vm;s_([p()],ol.prototype,"url",2);s_([p()],ol.prototype,"urlParameterName",2);s_([p()],ol.prototype,"localhost",2);var TR=Object.defineProperty,ER=Object.getOwnPropertyDescriptor,tf=(s,t,e,i)=>{for(var n=i>1?void 0:i?ER(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&TR(t,e,n),n};class Fr extends D{constructor(){super(...arguments);r(this,"referenceSpace");r(this,"from");r(this,"affectPosition",!1);r(this,"affectRotation",!1);r(this,"alignLookDirection",!1);r(this,"levelLookDirection",!1);r(this,"levelPosition",!1);r(this,"positionOffset",new h.Vector3(0,0,0));r(this,"rotationOffset",new h.Vector3(0,0,0));r(this,"offset",new h.Vector3(0,0,0))}update(){if(!this.from)return;var e=K(this.from),i=ye(this.from);this.offset.copy(this.positionOffset);const n=this.offset.length();if(this.referenceSpace&&this.offset.transformDirection(this.referenceSpace.matrixWorld).multiplyScalar(n),e.add(this.offset),this.levelPosition&&this.referenceSpace){const c=new h.Plane(this.gameObject.up,0),d=K(this.referenceSpace);c.setFromNormalAndCoplanarPoint(this.gameObject.up,d);const u=new h.Vector3(0,0,0);c.projectPoint(e,u),e.copy(u)}this.affectPosition&&nt(this.gameObject,e);const o=new h.Euler(this.rotationOffset.x,this.rotationOffset.y,this.rotationOffset.z),a=new h.Quaternion().setFromEuler(o);this.affectRotation&&Wi(this.gameObject,i.multiply(a));const l=new h.Vector3;this.from.getWorldDirection(l).multiplyScalar(50),this.levelLookDirection&&(l.y=0),this.alignLookDirection&&this.gameObject.lookAt(l)}}tf([p(C)],Fr.prototype,"referenceSpace",2);tf([p(C)],Fr.prototype,"from",2);tf([p(h.Vector3)],Fr.prototype,"positionOffset",2);tf([p(h.Vector3)],Fr.prototype,"rotationOffset",2);var AR=Object.defineProperty,DR=Object.getOwnPropertyDescriptor,P=(s,t,e,i)=>{for(var n=i>1?void 0:i?DR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&AR(t,e,n),n};const od=S("debugparticles");var ds=(s=>(s[s.Billboard=0]="Billboard",s[s.Stretch=1]="Stretch",s[s.HorizontalBillboard=2]="HorizontalBillboard",s[s.VerticalBillboard=3]="VerticalBillboard",s[s.Mesh=4]="Mesh",s))(ds||{});class ko{constructor(){r(this,"alphaKeys",[]);r(this,"colorKeys",[])}get duration(){return 1}evaluate(t,e){let i,n=0,o=null,a=0;for(let l=0;l<this.alphaKeys.length;l++){const c=this.alphaKeys[l];(c.time<t||!i)&&(i=c,n=l)}for(let l=0;l<this.colorKeys.length;l++){const c=this.colorKeys[l];(c.time<t||!o)&&(o=c,a=l)}if(o)if(a+1<this.colorKeys.length){const c=this.colorKeys[a+1],d=z.remap(t,o.time,c.time,0,1);e.r=z.lerp(o.color.r,c.color.r,d),e.g=z.lerp(o.color.g,c.color.g,d),e.b=z.lerp(o.color.b,c.color.b,d)}else e.r=o.color.r,e.g=o.color.g,e.b=o.color.b;if(i)if(n+1<this.alphaKeys.length){const c=this.alphaKeys[n+1],d=z.remap(t,i.time,c.time,0,1);e.alpha=z.lerp(i.alpha,c.alpha,d)}else e.alpha=i.alpha;return e}}P([p()],ko.prototype,"alphaKeys",2);P([p()],ko.prototype,"colorKeys",2);var Tc=(s=>(s[s.Local=0]="Local",s[s.World=1]="World",s[s.Custom=2]="Custom",s))(Tc||{}),au=(s=>(s[s.Sphere=0]="Sphere",s[s.SphereShell=1]="SphereShell",s[s.Hemisphere=2]="Hemisphere",s[s.HemisphereShell=3]="HemisphereShell",s[s.Cone=4]="Cone",s[s.Box=5]="Box",s[s.Mesh=6]="Mesh",s[s.ConeShell=7]="ConeShell",s[s.ConeVolume=8]="ConeVolume",s[s.ConeVolumeShell=9]="ConeVolumeShell",s[s.Circle=10]="Circle",s[s.CircleEdge=11]="CircleEdge",s[s.SingleSidedEdge=12]="SingleSidedEdge",s[s.MeshRenderer=13]="MeshRenderer",s[s.SkinnedMeshRenderer=14]="SkinnedMeshRenderer",s[s.BoxShell=15]="BoxShell",s[s.BoxEdge=16]="BoxEdge",s[s.Donut=17]="Donut",s[s.Rectangle=18]="Rectangle",s[s.Sprite=19]="Sprite",s[s.SpriteRenderer=20]="SpriteRenderer",s))(au||{});const ql=class{constructor(){r(this,"mode","Constant");r(this,"constant");r(this,"constantMin");r(this,"constantMax");r(this,"curve");r(this,"curveMin");r(this,"curveMax");r(this,"curveMultiplier")}static constant(s){const t=new ql;return t.setConstant(s),t}static betweenTwoConstants(s,t){const e=new ql;return e.setMinMaxConstant(s,t),e}static curve(s,t=1){const e=new ql;return e.setCurve(s,t),e}setConstant(s){this.mode=0,this.constant=s}setMinMaxConstant(s,t){this.mode=3,this.constantMin=s,this.constantMax=t}setCurve(s,t=1){this.mode=1,this.curve=s,this.curveMultiplier=t}clone(){var t,e,i;const s=new ql;return s.mode=this.mode,s.constant=this.constant,s.constantMin=this.constantMin,s.constantMax=this.constantMax,s.curve=(t=this.curve)==null?void 0:t.clone(),s.curveMin=(e=this.curveMin)==null?void 0:e.clone(),s.curveMax=(i=this.curveMax)==null?void 0:i.clone(),s.curveMultiplier=this.curveMultiplier,s}evaluate(s,t){const e=t===void 0?Math.random():t;switch(this.mode){case 0:case"Constant":return this.constant;case 1:case"Curve":return s=z.clamp01(s),this.curve.evaluate(s)*this.curveMultiplier;case 2:case"TwoCurves":const i=s*this.curveMin.duration,n=s*this.curveMax.duration;return z.lerp(this.curveMin.evaluate(i),this.curveMax.evaluate(n),e%1)*this.curveMultiplier;case 3:case"TwoConstants":return z.lerp(this.constantMin,this.constantMax,e%1);default:this.curveMax.evaluate(s)*this.curveMultiplier;break}return 0}getMax(){switch(this.mode){case 0:case"Constant":return this.constant;case 1:case"Curve":return this.getMaxFromCurve(this.curve)*this.curveMultiplier;case 2:case"TwoCurves":return Math.max(this.getMaxFromCurve(this.curveMin),this.getMaxFromCurve(this.curveMax))*this.curveMultiplier;case 3:case"TwoConstants":return Math.max(this.constantMin,this.constantMax);default:return 0}}getMaxFromCurve(s){if(!s)return 0;let t=Number.MIN_VALUE;for(let e=0;e<s.keys.length;e++){const i=s.keys[e];i.value>t&&(t=i.value)}return t}};let W=ql;P([p()],W.prototype,"mode",2);P([p()],W.prototype,"constant",2);P([p()],W.prototype,"constantMin",2);P([p()],W.prototype,"constantMax",2);P([p(Mr)],W.prototype,"curve",2);P([p(Mr)],W.prototype,"curveMin",2);P([p(Mr)],W.prototype,"curveMax",2);P([p()],W.prototype,"curveMultiplier",2);var pd;const _t=(pd=class{constructor(){r(this,"mode",0);r(this,"color");r(this,"colorMin");r(this,"colorMax");r(this,"gradient");r(this,"gradientMin");r(this,"gradientMax")}static constant(s){const t=new _t;return t.constant(s),t}static betweenTwoColors(s,t){const e=new _t;return e.betweenTwoColors(s,t),e}constant(s){return this.mode=0,this.color=s,this}betweenTwoColors(s,t){return this.mode=2,this.colorMin=s,this.colorMax=t,this}evaluate(s,t){const e=t===void 0?Math.random():t;switch(this.mode){case 0:case"Color":return this.color;case 1:case"Gradient":return this.gradient.evaluate(s,_t._temp),_t._temp;case 2:case"TwoColors":return _t._temp.lerpColors(this.colorMin,this.colorMax,e);case 3:case"TwoGradients":return this.gradientMin.evaluate(s,_t._temp),this.gradientMax.evaluate(s,_t._temp2),_t._temp.lerp(_t._temp2,e);case 4:case"RandomColor":const n=Math.random();return this.gradientMin.evaluate(s,_t._temp),this.gradientMax.evaluate(s,_t._temp2),_t._temp.lerp(_t._temp2,n)}return _t._temp.set(16777215),_t._temp.alpha=1,_t._temp}},r(pd,"_temp",new ge(0,0,0,1)),r(pd,"_temp2",new ge(0,0,0,1)),pd);let Yt=_t;P([p()],Yt.prototype,"mode",2);P([p(ge)],Yt.prototype,"color",2);P([p(ge)],Yt.prototype,"colorMin",2);P([p(ge)],Yt.prototype,"colorMax",2);P([p(ko)],Yt.prototype,"gradient",2);P([p(ko)],Yt.prototype,"gradientMin",2);P([p(ko)],Yt.prototype,"gradientMax",2);var wm=(s=>(s[s.Hierarchy=0]="Hierarchy",s[s.Local=1]="Local",s[s.Shape=2]="Shape",s))(wm||{});class Mt{constructor(){r(this,"cullingMode");r(this,"duration");r(this,"emitterVelocityMode");r(this,"flipRotation");r(this,"gravityModifier");r(this,"gravityModifierMultiplier");r(this,"loop");r(this,"maxParticles");r(this,"playOnAwake");r(this,"prewarm");r(this,"ringBufferLoopRange");r(this,"ringBufferMode");r(this,"scalingMode");r(this,"simulationSpace");r(this,"simulationSpeed");r(this,"startColor");r(this,"startDelay");r(this,"startDelayMultiplier");r(this,"startLifetime");r(this,"startLifetimeMultiplier");r(this,"startRotation");r(this,"startRotationMultiplier");r(this,"startRotation3D");r(this,"startRotationX");r(this,"startRotationXMultiplier");r(this,"startRotationY");r(this,"startRotationYMultiplier");r(this,"startRotationZ");r(this,"startRotationZMultiplier");r(this,"startSize");r(this,"startSize3D");r(this,"startSizeMultiplier");r(this,"startSizeX");r(this,"startSizeXMultiplier");r(this,"startSizeY");r(this,"startSizeYMultiplier");r(this,"startSizeZ");r(this,"startSizeZMultiplier");r(this,"startSpeed");r(this,"startSpeedMultiplier");r(this,"stopAction");r(this,"useUnscaledTime")}}P([p(W)],Mt.prototype,"gravityModifier",2);P([p(Yt)],Mt.prototype,"startColor",2);P([p(W)],Mt.prototype,"startDelay",2);P([p(W)],Mt.prototype,"startLifetime",2);P([p(W)],Mt.prototype,"startRotation",2);P([p(W)],Mt.prototype,"startRotationX",2);P([p(W)],Mt.prototype,"startRotationY",2);P([p(W)],Mt.prototype,"startRotationZ",2);P([p(W)],Mt.prototype,"startSize",2);P([p(W)],Mt.prototype,"startSizeX",2);P([p(W)],Mt.prototype,"startSizeY",2);P([p(W)],Mt.prototype,"startSizeZ",2);P([p(W)],Mt.prototype,"startSpeed",2);class Ec{constructor(){r(this,"cycleCount");r(this,"maxCount");r(this,"minCount");r(this,"probability");r(this,"repeatInterval");r(this,"time");r(this,"count");r(this,"_performed",0)}reset(){this._performed=0}run(t){if(t<=this.time)return 0;let e=0;if(this.cycleCount===0||this._performed<this.cycleCount){const i=this.time+this.repeatInterval*this._performed;if(t>=i&&(this._performed+=1,Math.random()<this.probability))switch(this.count.mode){case 0:e=this.count.constant;break;case 3:e=z.lerp(this.count.constantMin,this.count.constantMax,Math.random());break;case 1:e=this.count.curve.evaluate(Math.random());break;case 2:const n=Math.random();e=z.lerp(this.count.curveMin.evaluate(n),this.count.curveMax.evaluate(n),Math.random());break}}return e}}class Qn{constructor(){r(this,"enabled");r(this,"bursts");r(this,"rateOverTime");r(this,"rateOverTimeMultiplier");r(this,"rateOverDistance");r(this,"rateOverDistanceMultiplier");r(this,"system")}get burstCount(){var t;return((t=this.bursts)==null?void 0:t.length)??0}reset(){var t;(t=this.bursts)==null||t.forEach(e=>e.reset())}getBurst(){let t=0;if(this.burstCount>0)for(let e=0;e<this.burstCount;e++){const i=this.bursts[e];this.system.main.loop&&i.time>=this.system.time&&i.reset(),t+=Math.round(i.run(this.system.time))}return t}}P([p()],Qn.prototype,"enabled",2);P([p()],Qn.prototype,"bursts",2);P([p(W)],Qn.prototype,"rateOverTime",2);P([p()],Qn.prototype,"rateOverTimeMultiplier",2);P([p(W)],Qn.prototype,"rateOverDistance",2);P([p()],Qn.prototype,"rateOverDistanceMultiplier",2);class yh{constructor(){r(this,"enabled");r(this,"color")}}P([p(Yt)],yh.prototype,"color",2);class To{constructor(){r(this,"enabled");r(this,"separateAxes");r(this,"size");r(this,"sizeMultiplier");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier");r(this,"_time",0);r(this,"_temp",new h.Vector3)}evaluate(t,e,i){if(e||(e=this._temp),!this.enabled)return e.x=e.y=e.z=1,e;if(this.separateAxes)e.x=this.x.evaluate(t,i)*this.xMultiplier,e.y=this.y.evaluate(t,i)*this.yMultiplier,e.z=this.z.evaluate(t,i)*this.zMultiplier;else{const n=this.size.evaluate(t,i)*this.sizeMultiplier;e.x=n}return e}}P([p(W)],To.prototype,"size",2);P([p(W)],To.prototype,"x",2);P([p(W)],To.prototype,"y",2);P([p(W)],To.prototype,"z",2);var md;const Xl=(md=class{constructor(){r(this,"shapeType",5);r(this,"enabled",!0);r(this,"alignToDirection",!1);r(this,"angle",0);r(this,"arc",360);r(this,"arcSpread");r(this,"arcSpeedMultiplier");r(this,"arcMode");r(this,"boxThickness");r(this,"position");r(this,"rotation");r(this,"_rotation",new h.Euler);r(this,"scale");r(this,"radius");r(this,"radiusThickness");r(this,"sphericalDirectionAmount");r(this,"randomDirectionAmount");r(this,"randomPositionAmount");r(this,"meshShapeType");r(this,"meshRenderer");r(this,"_meshObj");r(this,"_meshGeometry");r(this,"system");r(this,"_space");r(this,"_worldSpaceMatrix",new h.Matrix4);r(this,"_worldSpaceMatrixInverse",new h.Matrix4);r(this,"_vector",new h.Vector3(0,0,0));r(this,"_temp",new h.Vector3(0,0,0));r(this,"_triangle",new h.Triangle);r(this,"_dir",new h.Vector3);r(this,"_loopTime",0);r(this,"_loopDirection",1);od&&console.log(this)}get type(){return au[this.shapeType]}initialize(s){this.onInitialize(s),s.position.x=this._vector.x,s.position.y=this._vector.y,s.position.z=this._vector.z}toJSON(){return this}clone(){return new Xl}setMesh(s){this.meshRenderer=s,s?(this._meshObj=s.sharedMeshes[Math.floor(Math.random()*s.sharedMeshes.length)],this._meshGeometry=this._meshObj.geometry):(this._meshObj=void 0,this._meshGeometry=void 0)}update(s,t){}onUpdate(s,t,e,i){this.system=s,this._space=e,e===1&&(this._worldSpaceMatrix.copy(i.matrixWorld),this._worldSpaceMatrix.elements[0]=1,this._worldSpaceMatrix.elements[5]=1,this._worldSpaceMatrix.elements[10]=1,this._worldSpaceMatrixInverse.copy(this._worldSpaceMatrix).invert())}applyRotation(s){const t=this.rotation.x!==0||this.rotation.y!==0||this.rotation.z!==0;return t&&(this._rotation.x=z.toRadians(this.rotation.x),this._rotation.y=z.toRadians(this.rotation.y),this._rotation.z=z.toRadians(this.rotation.z),this._rotation.order="ZYX",s.applyEuler(this._rotation)),t}onInitialize(s){this._vector.set(0,0,0),s.mesh=void 0,s.mesh_geometry=void 0;const t=this._temp.copy(this.position),e=this._space===1;e&&t.applyQuaternion(this.system.worldQuaternion);let i=this.radius;if(e&&(i*=this.system.worldScale.x),this.enabled){switch(this.shapeType){case 5:od&&N.DrawWireBox(this.position,this.scale,14540253,1),this._vector.x=Math.random()*this.scale.x-this.scale.x/2,this._vector.y=Math.random()*this.scale.y-this.scale.y/2,this._vector.z=Math.random()*this.scale.z-this.scale.z/2,this._vector.add(t);break;case 4:this.randomConePoint(this.position,this.angle,i,this.radiusThickness,this.arc,this.arcMode,this._vector);break;case 0:this.randomSpherePoint(this.position,i,this.radiusThickness,this.arc,this._vector);break;case 10:this.randomCirclePoint(this.position,i,this.radiusThickness,this.arc,this._vector);break;case 13:const n=this.meshRenderer;(n==null?void 0:n.destroyed)==!1&&this.setMesh(n);const o=s.mesh=this._meshObj,a=s.mesh_geometry=this._meshGeometry;if(o&&a)switch(this.meshShapeType){case 0:{const l=a.getAttribute("position"),c=Math.floor(Math.random()*l.count);this._vector.fromBufferAttribute(l,c),this._vector.applyMatrix4(o.matrixWorld),s.mesh_normal=c}break;case 1:break;case 2:{const l=a.index;if(l){let c=Math.random(),d=Math.random();c+d>1&&(c=1-c,d=1-d);const u=Math.floor(Math.random()*(l.count/3));let f=u*3,m=u*3+1,g=u*3+2;f=l.getX(f),m=l.getX(m),g=l.getX(g);const _=a.getAttribute("position");this._triangle.a.fromBufferAttribute(_,f),this._triangle.b.fromBufferAttribute(_,m),this._triangle.c.fromBufferAttribute(_,g),this._vector.set(0,0,0).addScaledVector(this._triangle.a,c).addScaledVector(this._triangle.b,d).addScaledVector(this._triangle.c,1-(c+d)),this._vector.applyMatrix4(o.matrixWorld),s.mesh_normal=u}}break}break;default:this._vector.set(0,0,0),B()&&!globalThis.__particlesystem_shapetype_unsupported&&(console.warn("ParticleSystem ShapeType is not supported:",au[this.shapeType]),globalThis.__particlesystem_shapetype_unsupported=!0);break}this.randomizePosition(this._vector,this.randomPositionAmount)}this.applyRotation(this._vector),e&&(this._vector.applyQuaternion(this.system.worldQuaternion),this._vector.add(this.system.worldPos)),od&&N.DrawSphere(this._vector,.03,16711680,.5,!0)}getDirection(s,t){var e;if(!this.enabled)return this._dir.set(0,0,1),this._dir;switch(this.shapeType){case 5:this._dir.set(0,0,1);break;case 4:this._dir.set(0,0,1);break;case 10:case 0:const i=t.x,n=t.y,o=t.z;this._dir.set(i,n,o),(e=this.system)!=null&&e.worldspace?this._dir.sub(this.system.worldPos):this._dir.sub(this.position);break;case 13:const a=s.mesh,l=s.mesh_geometry;if(a&&l)switch(this.meshShapeType){case 0:{const c=l.getAttribute("normal"),d=s.mesh_normal;this._dir.fromBufferAttribute(c,d)}break;case 1:break;case 2:{const c=l.index;if(c){const d=s.mesh_normal,u=c.getX(d*3),f=c.getX(d*3+1),m=c.getX(d*3+2),g=l.getAttribute("position"),_=V(),y=V(),b=V();_.fromBufferAttribute(g,u),y.fromBufferAttribute(g,f),b.fromBufferAttribute(g,m),_.sub(y),b.sub(y),_.cross(b),this._dir.copy(_).multiplyScalar(-1);const v=ye(a);this._dir.applyQuaternion(v)}}break}break;default:this._dir.set(0,0,1);break}return this._space===1&&this._dir.applyQuaternion(this.system.worldQuaternion),this.applyRotation(this._dir),this._dir.normalize(),this.spherizeDirection(this._dir,this.sphericalDirectionAmount),this.randomizeDirection(this._dir,this.randomDirectionAmount),od&&(N.DrawSphere(t,.01,8925952,.5,!0),N.DrawDirection(t,this._dir,8925952,.5,!0)),this._dir}randomizePosition(s,t){if(t<=0)return;const e=Xl._tempVec;e.set(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1),e.x*=t*this.scale.x,e.y*=t*this.scale.y,e.z*=t*this.scale.z,s.add(e)}randomizeDirection(s,t){if(t===0)return;const e=Xl._randomQuat,i=Xl._tempVec;i.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),e.setFromAxisAngle(i,t*Math.random()*Math.PI),s.applyQuaternion(e)}spherizeDirection(s,t){if(t===0)return;const e=Math.random()*Math.PI*2,i=Math.acos(1-Math.random()*2),n=Math.sin(i)*Math.cos(e),o=Math.sin(i)*Math.sin(e),a=Math.cos(i),l=new h.Vector3(n,o,a);s.lerp(l,t)}randomSpherePoint(s,t,e,i,n){const o=Math.random(),a=Math.random(),l=2*Math.PI*o*(i/360),c=Math.acos(2*a-1),d=z.lerp(1,1-Math.pow(1-Math.random(),Math.PI),e)*t,u=s.x+this.scale.x*(-d*Math.sin(c)*Math.cos(l)),f=s.y+this.scale.y*(d*Math.sin(c)*Math.sin(l)),m=s.z+this.scale.z*(d*Math.cos(c));n.x=u,n.y=f,n.z=m}randomCirclePoint(s,t,e,i,n){const o=Math.random(),a=2*Math.PI*o*(i/360),l=z.lerp(1,1-Math.pow(1-Math.random(),Math.PI),e)*t,c=s.x+this.scale.x*l*Math.cos(a),d=s.y+this.scale.y*l*Math.sin(a),u=s.z;n.x=c,n.y=d,n.z=u}randomConePoint(s,t,e,i,n,o,a){let l=0,c=0;switch(o){case 0:l=Math.random(),c=Math.random();break;case 2:this._loopTime>1&&(this._loopDirection=-1),this._loopTime<0&&(this._loopDirection=1);case 1:l=.5,c=Math.random(),this._loopTime+=this.system.deltaTime*this._loopDirection;break}let d=2*Math.PI*l*(n/360);switch(o){case 2:case 1:d+=Math.PI+.5,d+=this._loopTime*Math.PI*2,d%=z.toRadians(n);break}const u=Math.acos(2*c-1),f=z.lerp(1,1-Math.pow(1-Math.random(),Math.PI),i)*e,m=s.x+-f*Math.sin(u)*Math.cos(d),g=s.y+f*Math.sin(u)*Math.sin(d),_=s.z;a.x=m*this.scale.x,a.y=g*this.scale.y,a.z=_*this.scale.z}},r(md,"_randomQuat",new h.Quaternion),r(md,"_tempVec",new h.Vector3),md);let Fe=Xl;P([p()],Fe.prototype,"shapeType",2);P([p()],Fe.prototype,"enabled",2);P([p()],Fe.prototype,"alignToDirection",2);P([p()],Fe.prototype,"angle",2);P([p()],Fe.prototype,"arc",2);P([p()],Fe.prototype,"arcSpread",2);P([p()],Fe.prototype,"arcSpeedMultiplier",2);P([p()],Fe.prototype,"arcMode",2);P([p(h.Vector3)],Fe.prototype,"boxThickness",2);P([p(h.Vector3)],Fe.prototype,"position",2);P([p(h.Vector3)],Fe.prototype,"rotation",2);P([p(h.Vector3)],Fe.prototype,"scale",2);P([p()],Fe.prototype,"radius",2);P([p()],Fe.prototype,"radiusThickness",2);P([p()],Fe.prototype,"sphericalDirectionAmount",2);P([p()],Fe.prototype,"randomDirectionAmount",2);P([p()],Fe.prototype,"randomPositionAmount",2);P([p()],Fe.prototype,"meshShapeType",2);P([p(rh)],Fe.prototype,"meshRenderer",2);class _e{constructor(){r(this,"damping");r(this,"enabled");r(this,"frequency");r(this,"octaveCount");r(this,"octaveMultiplier");r(this,"octaveScale");r(this,"positionAmount");r(this,"quality");r(this,"remap");r(this,"remapEnabled");r(this,"remapMultiplier");r(this,"remapX");r(this,"remapXMultiplier");r(this,"remapY");r(this,"remapYMultiplier");r(this,"remapZ");r(this,"remapZMultiplier");r(this,"scrollSpeedMultiplier");r(this,"separateAxes");r(this,"strengthMultiplier");r(this,"strengthX");r(this,"strengthXMultiplier");r(this,"strengthY");r(this,"strengthYMultiplier");r(this,"strengthZ");r(this,"strengthZMultiplier");r(this,"_noise");r(this,"_time",0);r(this,"_temp",new h.Vector3)}update(t){this._time+=t.time.deltaTime*this.scrollSpeedMultiplier}apply(t,e,i,n,o,a){if(!this.enabled)return;this._noise||(this._noise=oe.createNoise4D(()=>0));const l=this._temp.set(e.x,e.y,e.z).multiplyScalar(this.frequency),c=this._noise(l.x,l.y,l.z,this._time),d=this._noise(l.x,l.y,l.z,this._time+1e3*this.frequency),u=this._noise(l.x,l.y,l.z,this._time+2e3*this.frequency);this._temp.set(c,d,u).normalize();const f=o/a;let m=this.positionAmount.evaluate(f);this.separateAxes?(this._temp.x*=m*this.strengthXMultiplier,this._temp.y*=m*this.strengthYMultiplier,this._temp.z*=m*this.strengthZMultiplier):(this.strengthX&&(m*=this.strengthX.evaluate(f)*1.5),this._temp.multiplyScalar(m)),i.x+=this._temp.x,i.y+=this._temp.y,i.z+=this._temp.z}}P([p()],_e.prototype,"damping",2);P([p()],_e.prototype,"enabled",2);P([p()],_e.prototype,"frequency",2);P([p()],_e.prototype,"octaveCount",2);P([p()],_e.prototype,"octaveMultiplier",2);P([p()],_e.prototype,"octaveScale",2);P([p(W)],_e.prototype,"positionAmount",2);P([p()],_e.prototype,"quality",2);P([p(W)],_e.prototype,"remap",2);P([p()],_e.prototype,"remapEnabled",2);P([p()],_e.prototype,"remapMultiplier",2);P([p(W)],_e.prototype,"remapX",2);P([p()],_e.prototype,"remapXMultiplier",2);P([p(W)],_e.prototype,"remapY",2);P([p()],_e.prototype,"remapYMultiplier",2);P([p(W)],_e.prototype,"remapZ",2);P([p()],_e.prototype,"remapZMultiplier",2);P([p()],_e.prototype,"scrollSpeedMultiplier",2);P([p()],_e.prototype,"separateAxes",2);P([p()],_e.prototype,"strengthMultiplier",2);P([p(W)],_e.prototype,"strengthX",2);P([p()],_e.prototype,"strengthXMultiplier",2);P([p(W)],_e.prototype,"strengthY",2);P([p()],_e.prototype,"strengthYMultiplier",2);P([p(W)],_e.prototype,"strengthZ",2);P([p()],_e.prototype,"strengthZMultiplier",2);class De{constructor(){r(this,"enabled");r(this,"attachRibbonToTransform",!1);r(this,"colorOverLifetime");r(this,"colorOverTrail");r(this,"dieWithParticles",!0);r(this,"inheritParticleColor",!0);r(this,"lifetime");r(this,"lifetimeMultiplier");r(this,"minVertexDistance",.2);r(this,"mode",0);r(this,"ratio",1);r(this,"ribbonCount",1);r(this,"shadowBias",0);r(this,"sizeAffectsLifetime",!1);r(this,"sizeAffectsWidth",!1);r(this,"splitSubEmitterRibbons",!1);r(this,"textureMode",0);r(this,"widthOverTrail");r(this,"widthOverTrailMultiplier");r(this,"worldSpace",!1)}getWidth(t,e,i,n){const o=this.widthOverTrail.evaluate(i,n);return t*=o,t}getColor(t,e,i){const n=this.colorOverTrail.evaluate(i),o=this.colorOverLifetime.evaluate(e);t.x*=n.r*o.r,t.y*=n.g*o.g,t.z*=n.b*o.b,"alpha"in n&&"alpha"in o&&(t.w*=n.alpha*o.alpha)}}P([p()],De.prototype,"enabled",2);P([p()],De.prototype,"attachRibbonToTransform",2);P([p(Yt)],De.prototype,"colorOverLifetime",2);P([p(Yt)],De.prototype,"colorOverTrail",2);P([p()],De.prototype,"dieWithParticles",2);P([p()],De.prototype,"inheritParticleColor",2);P([p(W)],De.prototype,"lifetime",2);P([p()],De.prototype,"lifetimeMultiplier",2);P([p()],De.prototype,"minVertexDistance",2);P([p()],De.prototype,"mode",2);P([p()],De.prototype,"ratio",2);P([p()],De.prototype,"ribbonCount",2);P([p()],De.prototype,"shadowBias",2);P([p()],De.prototype,"sizeAffectsLifetime",2);P([p()],De.prototype,"sizeAffectsWidth",2);P([p()],De.prototype,"splitSubEmitterRibbons",2);P([p()],De.prototype,"textureMode",2);P([p(W)],De.prototype,"widthOverTrail",2);P([p()],De.prototype,"widthOverTrailMultiplier",2);P([p()],De.prototype,"worldSpace",2);class Ue{constructor(){r(this,"enabled");r(this,"space",0);r(this,"orbitalX");r(this,"orbitalY");r(this,"orbitalZ");r(this,"orbitalXMultiplier");r(this,"orbitalYMultiplier");r(this,"orbitalZMultiplier");r(this,"orbitalOffsetX");r(this,"orbitalOffsetY");r(this,"orbitalOffsetZ");r(this,"speedModifier");r(this,"speedModifierMultiplier");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier");r(this,"_system");r(this,"_temp",new h.Vector3);r(this,"_temp2",new h.Vector3);r(this,"_temp3",new h.Vector3);r(this,"_hasOrbital",!1);r(this,"_index",0);r(this,"_orbitalMatrix",new h.Matrix4)}update(t){this._system=t}init(t){this._index==0&&(t.debug=!0),this._index+=1,t.orbitx=this.orbitalX.evaluate(Math.random()),t.orbity=this.orbitalY.evaluate(Math.random()),t.orbitz=this.orbitalZ.evaluate(Math.random()),this._hasOrbital=t.orbitx!=0||t.orbity!=0||t.orbitz!=0}apply(t,e,i,n,o,a,l){var g;if(!this.enabled)return;const c=a/l,d=this.speedModifier.evaluate(c)*this.speedModifierMultiplier,u=this.x.evaluate(c),f=this.y.evaluate(c),m=this.z.evaluate(c);if(this._temp.set(-u,f,m),this._system&&this._system.main.simulationSpace===1&&this._temp.applyQuaternion(this._system.worldQuaternion),this._hasOrbital&&((g=this._system)==null?void 0:g.worldPos)){const y=this._temp2.set(i.x,i.y,i.z),b=this.orbitalXMultiplier,v=this.orbitalYMultiplier,x=this.orbitalZMultiplier,O=d*Math.PI*2*10,k=Math.cos(O*b),M=Math.sin(O*b),R=Math.cos(O*v),A=Math.sin(O*v),I=Math.cos(O*x),E=Math.sin(O*x),j=y.x*(R*I)+y.y*(R*E)+y.z*-A,F=y.x*(M*A*I-k*E)+y.y*(M*A*E+k*I)+y.z*(M*R),G=y.x*(k*A*I+M*E)+y.y*(k*A*E-M*I)+y.z*(k*R),T=this._temp3.set(y.x-j,y.y-F,y.z-G);T.normalize(),T.multiplyScalar(.2/o*Math.max(this.orbitalXMultiplier,this.orbitalYMultiplier,this.orbitalZMultiplier)),n.x+=T.x,n.y+=T.y,n.z+=T.z}n.x+=this._temp.x,n.y+=this._temp.y,n.z+=this._temp.z,n.x*=d,n.y*=d,n.z*=d}}P([p()],Ue.prototype,"enabled",2);P([p()],Ue.prototype,"space",2);P([p(W)],Ue.prototype,"orbitalX",2);P([p(W)],Ue.prototype,"orbitalY",2);P([p(W)],Ue.prototype,"orbitalZ",2);P([p()],Ue.prototype,"orbitalXMultiplier",2);P([p()],Ue.prototype,"orbitalYMultiplier",2);P([p()],Ue.prototype,"orbitalZMultiplier",2);P([p()],Ue.prototype,"orbitalOffsetX",2);P([p()],Ue.prototype,"orbitalOffsetY",2);P([p()],Ue.prototype,"orbitalOffsetZ",2);P([p(W)],Ue.prototype,"speedModifier",2);P([p()],Ue.prototype,"speedModifierMultiplier",2);P([p(W)],Ue.prototype,"x",2);P([p()],Ue.prototype,"xMultiplier",2);P([p(W)],Ue.prototype,"y",2);P([p()],Ue.prototype,"yMultiplier",2);P([p(W)],Ue.prototype,"z",2);P([p()],Ue.prototype,"zMultiplier",2);class Rt{constructor(){r(this,"animation");r(this,"enabled");r(this,"cycleCount");r(this,"frameOverTime");r(this,"frameOverTimeMultiplier");r(this,"numTilesX");r(this,"numTilesY");r(this,"startFrame");r(this,"startFrameMultiplier");r(this,"rowMode");r(this,"rowIndex");r(this,"spriteCount");r(this,"timeMode")}sampleOnceAtStart(){if(this.timeMode===0)switch(this.frameOverTime.mode){case 0:case 3:case 2:case 1:return!0}return!1}getStartIndex(){return this.sampleOnceAtStart()?Math.random()*(this.numTilesX*this.numTilesY):0}evaluate(t){if(!this.sampleOnceAtStart())return this.getIndex(t)}getIndex(t){const e=this.numTilesX*this.numTilesY;t=t*this.cycleCount;let i=this.frameOverTime.evaluate(t%1);return i*=this.frameOverTimeMultiplier,i*=e,i=i%e,i=Math.floor(i),i}}P([p()],Rt.prototype,"animation",2);P([p()],Rt.prototype,"enabled",2);P([p()],Rt.prototype,"cycleCount",2);P([p(W)],Rt.prototype,"frameOverTime",2);P([p()],Rt.prototype,"frameOverTimeMultiplier",2);P([p()],Rt.prototype,"numTilesX",2);P([p()],Rt.prototype,"numTilesY",2);P([p(W)],Rt.prototype,"startFrame",2);P([p()],Rt.prototype,"startFrameMultiplier",2);P([p()],Rt.prototype,"rowMode",2);P([p()],Rt.prototype,"rowIndex",2);P([p()],Rt.prototype,"spriteCount",2);P([p()],Rt.prototype,"timeMode",2);class qi{constructor(){r(this,"enabled");r(this,"separateAxes");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier")}evaluate(t,e){return this.enabled?this.separateAxes?0:this.z.evaluate(t,e)*-1:0}}P([p()],qi.prototype,"enabled",2);P([p()],qi.prototype,"separateAxes",2);P([p(W)],qi.prototype,"x",2);P([p()],qi.prototype,"xMultiplier",2);P([p(W)],qi.prototype,"y",2);P([p()],qi.prototype,"yMultiplier",2);P([p(W)],qi.prototype,"z",2);P([p()],qi.prototype,"zMultiplier",2);class Ti{constructor(){r(this,"enabled");r(this,"range");r(this,"separateAxes");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier")}evaluate(t,e){if(!this.enabled)return 0;if(!this.separateAxes){const i=z.lerp(this.range.x,this.range.y,e);return this.z.evaluate(i)*-1}return 0}}P([p()],Ti.prototype,"enabled",2);P([p()],Ti.prototype,"range",2);P([p()],Ti.prototype,"separateAxes",2);P([p(W)],Ti.prototype,"x",2);P([p()],Ti.prototype,"xMultiplier",2);P([p(W)],Ti.prototype,"y",2);P([p()],Ti.prototype,"yMultiplier",2);P([p(W)],Ti.prototype,"z",2);P([p()],Ti.prototype,"zMultiplier",2);class Ke{constructor(){r(this,"enabled");r(this,"dampen");r(this,"drag");r(this,"dragMultiplier");r(this,"limit");r(this,"limitMultiplier");r(this,"separateAxes");r(this,"limitX");r(this,"limitXMultiplier");r(this,"limitY");r(this,"limitYMultiplier");r(this,"limitZ");r(this,"limitZMultiplier");r(this,"multiplyDragByParticleSize",!1);r(this,"multiplyDragByParticleVelocity",!1);r(this,"space");r(this,"_temp",new h.Vector3);r(this,"_temp2",new h.Vector3)}apply(t,e,i,n,o,a,l){if(this.enabled){const c=this.limit.evaluate(o)*this.limitMultiplier;if(e.length()>c){this._temp.copy(e).normalize().multiplyScalar(c);const u=this.dampen*.5;e.x=z.lerp(e.x,this._temp.x,u),e.y=z.lerp(e.y,this._temp.y,u),e.z=z.lerp(e.z,this._temp.z,u),i.x=z.lerp(i.x,this._temp.x,u),i.y=z.lerp(i.y,this._temp.y,u),i.z=z.lerp(i.z,this._temp.z,u)}}}}P([p()],Ke.prototype,"enabled",2);P([p()],Ke.prototype,"dampen",2);P([p(W)],Ke.prototype,"drag",2);P([p()],Ke.prototype,"dragMultiplier",2);P([p(W)],Ke.prototype,"limit",2);P([p()],Ke.prototype,"limitMultiplier",2);P([p()],Ke.prototype,"separateAxes",2);P([p(W)],Ke.prototype,"limitX",2);P([p()],Ke.prototype,"limitXMultiplier",2);P([p(W)],Ke.prototype,"limitY",2);P([p()],Ke.prototype,"limitYMultiplier",2);P([p(W)],Ke.prototype,"limitZ",2);P([p()],Ke.prototype,"limitZMultiplier",2);P([p()],Ke.prototype,"multiplyDragByParticleSize",2);P([p()],Ke.prototype,"multiplyDragByParticleVelocity",2);P([p()],Ke.prototype,"space",2);const Mw=class{constructor(){r(this,"enabled");r(this,"curve");r(this,"curveMultiplier");r(this,"mode");r(this,"system");r(this,"_temp",new h.Vector3);r(this,"_firstUpdate",!0);r(this,"_frames",0)}clone(){var t;const s=new Mw;return s.enabled=this.enabled,s.curve=(t=this.curve)==null?void 0:t.clone(),s.curveMultiplier=this.curveMultiplier,s.mode=this.mode,s}get _lastWorldPosition(){return this.system._iv_lastWorldPosition||(this.system._iv_lastWorldPosition=new h.Vector3),this.system._iv_lastWorldPosition}get _velocity(){return this.system._iv_velocity||(this.system._iv_velocity=new h.Vector3),this.system._iv_velocity}awake(s){this.system=s,this.reset()}reset(){this._firstUpdate=!0}update(s){this.enabled&&this.system.worldspace!==!1&&(this._firstUpdate?(this._firstUpdate=!1,this._velocity.set(0,0,0),this._lastWorldPosition.copy(this.system.worldPos)):this._lastWorldPosition&&(this._velocity.copy(this.system.worldPos).sub(this._lastWorldPosition).multiplyScalar(1/this.system.deltaTime),this._lastWorldPosition.copy(this.system.worldPos)))}applyInitial(s){if(this.enabled&&this.system.worldspace!==!1&&this.mode===0){const t=this.curve.evaluate(Math.random(),Math.random());this._temp.copy(this._velocity).multiplyScalar(t),s.x+=this._temp.x,s.y+=this._temp.y,s.z+=this._temp.z}}applyCurrent(s,t,e){if(this.enabled&&this.system&&this.system.worldspace!==!1&&this.mode===1){const i=this.curve.evaluate(t,e);this._temp.copy(this._velocity).multiplyScalar(i),s.x+=this._temp.x,s.y+=this._temp.y,s.z+=this._temp.z}}};let Eo=Mw;P([p()],Eo.prototype,"enabled",2);P([p(W)],Eo.prototype,"curve",2);P([p()],Eo.prototype,"curveMultiplier",2);P([p()],Eo.prototype,"mode",2);class Kt{constructor(){r(this,"enabled");r(this,"range");r(this,"separateAxes");r(this,"size");r(this,"sizeMultiplier");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier")}evaluate(t,e,i,n){const o=t.length(),a=z.remap(o,this.range.x,this.range.y,0,1),l=this.size.evaluate(a,i);return n.x*=l,n.y*=l,n.z*=l,n}}P([p()],Kt.prototype,"enabled",2);P([p(h.Vector2)],Kt.prototype,"range",2);P([p()],Kt.prototype,"separateAxes",2);P([p(W)],Kt.prototype,"size",2);P([p()],Kt.prototype,"sizeMultiplier",2);P([p(W)],Kt.prototype,"x",2);P([p()],Kt.prototype,"xMultiplier",2);P([p(W)],Kt.prototype,"y",2);P([p()],Kt.prototype,"yMultiplier",2);P([p(W)],Kt.prototype,"z",2);P([p()],Kt.prototype,"zMultiplier",2);class Ur{constructor(){r(this,"enabled");r(this,"range");r(this,"color")}evaluate(t,e,i){const n=t.length(),o=z.remap(n,this.range.x,this.range.y,0,1),a=this.color.evaluate(o,e);i.x*=a.r,i.y*=a.g,i.z*=a.b,"alpha"in a&&(i.w*=a.alpha)}}P([p()],Ur.prototype,"enabled",2);P([p(h.Vector2)],Ur.prototype,"range",2);P([p(Yt)],Ur.prototype,"color",2);new h.Vector3(1,1,1);new h.Vector3(0,0,1);class nf{constructor(t,e,i,n){r(this,"type","NeedleParticleSubEmitter");r(this,"emitterType");r(this,"emitterProbability");r(this,"q_",new h.Quaternion);r(this,"v_",new h.Vector3);r(this,"v2_",new h.Vector3);r(this,"_emitterMatrix",new oe.Matrix4);r(this,"_circularBuffer");this.system=t,this.particleSystem=e,this.subSystem=i,this.subParticleSystem=n,this.subParticleSystem&&this.subParticleSystem&&(this.subParticleSystem.onlyUsedByOther=!0);const o=1e3;this._circularBuffer=new Ci(()=>new oe.Matrix4,o)}clone(){throw new Error("Method not implemented.")}initialize(t){t.emissionState={burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0},this._emitterMatrix.copy(this.subSystem.matrixWorld).invert().premultiply(this.system.matrixWorld),this._emitterMatrix.setPosition(0,0,0),this.emitterType===xm.Birth&&this.run(t)}update(t,e){this.run(t)}frameUpdate(t){}toJSON(){}reset(){}run(t){if(this.subSystem.currentParticles>=this.subSystem.main.maxParticles||!this.subParticleSystem||!t.emissionState||this.emitterProbability&&Math.random()>this.emitterProbability)return;const e=this.system.deltaTime;if(this.emitterType===xm.Death){let n=t.life;if(t[_a]!==void 0&&(n=t[_a]),!(t.age+e*1.2>=n))return;const a=this.subSystem.main.maxParticles-this.subSystem.currentParticles;t.emissionState.waitEmiting=a}const i=new oe.Matrix4;i.set(1,0,0,t.position.x,0,1,0,t.position.y,0,0,1,t.position.z,0,0,0,1),this.particleSystem.worldSpace||i.multiplyMatrices(this._emitterMatrix,i),this.subParticleSystem.emit(e,t.emissionState,i)}}var LR=Object.defineProperty,IR=Object.getOwnPropertyDescriptor,ze=(s,t,e,i)=>{for(var n=i>1?void 0:i?IR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&LR(t,e,n),n};const qs=S("debugparticles"),jR=S("noprogressive"),BR=S("debugprogressive");var xm=(s=>(s[s.Birth=0]="Birth",s[s.Collision=1]="Collision",s[s.Death=2]="Death",s[s.Trigger=3]="Trigger",s[s.Manual=4]="Manual",s))(xm||{});class Xi extends D{constructor(){super(...arguments);r(this,"renderMode");r(this,"particleMaterial");r(this,"trailMaterial");r(this,"particleMesh");r(this,"maxParticleSize");r(this,"minParticleSize");r(this,"velocityScale");r(this,"cameraVelocityScale");r(this,"lengthScale")}start(){if(this.maxParticleSize!==.5&&this.minParticleSize!==0&&B()){const e=`ParticleSystem "${this.name}" has non-default min/max particle size. This may not render correctly. Please set min size to 0 and the max size to 0.5 and use the "StartSize" setting instead`;console.warn(e)}}get transparent(){var i;return((i=this.particleMaterial)==null?void 0:i.transparent)??!1}getMaterial(e=!1){let i=e===!0&&this.trailMaterial?this.trailMaterial:this.particleMaterial;if(i){if(i.type==="MeshStandardMaterial"){qs&&console.debug("ParticleSystemRenderer.getMaterial: MeshStandardMaterial detected, converting to MeshBasicMaterial. See https://github.com/Alchemist0823/three.quarks/issues/101"),"map"in i&&i.map&&(i.map.colorSpace=h.LinearSRGBColorSpace,i.map.premultiplyAlpha=!1);const n=new h.MeshBasicMaterial;n.copy(i),e?this.trailMaterial=n:this.particleMaterial=n}i.map&&(i.map.colorSpace=h.LinearSRGBColorSpace,i.map.premultiplyAlpha=!1),e&&i.side===h.FrontSide&&(i=i.clone(),i.side=h.BackSide,e?this.trailMaterial=i:this.particleMaterial=i)}return i&&!jR&&i._didRequestTextureLOD===void 0&&(i._didRequestTextureLOD=0,BR&&console.log("Load material LOD",i.name),re.NEEDLE_progressive.assignTextureLOD(i,0)),i}getMesh(e){let i=null;if(!i&&(this.particleMesh instanceof h.Mesh&&(i=this.particleMesh.geometry),i===null)){i=new h.PlaneGeometry(1,1);const o=i.attributes.uv;for(let a=0;a<o.count;a++)o.setX(a,1-o.getX(a))}return new h.Mesh(i,this.getMaterial())}}ze([p()],Xi.prototype,"renderMode",2);ze([p(h.Material)],Xi.prototype,"particleMaterial",2);ze([p(h.Material)],Xi.prototype,"trailMaterial",2);ze([p()],Xi.prototype,"maxParticleSize",2);ze([p()],Xi.prototype,"minParticleSize",2);ze([p()],Xi.prototype,"velocityScale",2);ze([p()],Xi.prototype,"cameraVelocityScale",2);ze([p()],Xi.prototype,"lengthScale",2);class rd{constructor(t,e=1){r(this,"_curve");r(this,"_factor");r(this,"type","function");this._curve=t,this._factor=e}startGen(t){}genValue(t,e){return this._curve.evaluate(e,Math.random())*this._factor}toJSON(){throw new Error("Method not implemented.")}clone(){throw new Error("Method not implemented.")}}class o_{constructor(t){r(this,"type","value");r(this,"system");this.system=t}toJSON(){throw new Error("Method not implemented.")}clone(){throw new Error("Method not implemented.")}startGen(t){}}class FR extends o_{genValue(){return this.system.textureSheetAnimation.getStartIndex()}}class UR extends o_{constructor(){super(...arguments);r(this,"_lastPosition",new h.Vector3);r(this,"_lastDistance",0)}update(){const e=K(this.system.gameObject);this._lastDistance=this._lastPosition.distanceTo(e),this._lastPosition.copy(e)}genValue(){if(!this.system.isPlaying||!this.system.emission.enabled||this.system.currentParticles>=this.system.maxParticles)return 0;let e=this.system.emission.rateOverTime.evaluate(this.system.time/this.system.duration,Math.random());if(this.system.deltaTime>0){const o=this.system.emission.rateOverDistance.evaluate(this.system.time/this.system.duration,Math.random());let l=this._lastDistance/this.system.deltaTime*o;Number.isFinite(l)||(l=0),e+=l}const i=this.system.emission.getBurst();i>0&&(e+=i/this.system.deltaTime);const n=this.system.maxParticles-this.system.currentParticles;return z.clamp(e,0,n/this.system.deltaTime)}}class zR extends o_{genValue(){return this.system.isPlaying,0}}class Ao{constructor(t){r(this,"system");r(this,"type");this.type=Object.getPrototypeOf(this).constructor.name||"ParticleSystemBaseBehaviour",t&&(this.system=t)}get context(){return this.system.context}initialize(t){}update(t,e){}frameUpdate(t){}toJSON(){throw new Error("Method not implemented.")}clone(){throw new Error("Method not implemented.")}reset(){}}class NR extends Ao{constructor(){super(...arguments);r(this,"type","NeedleTextureSheet")}update(e,i){const n=this.system.textureSheetAnimation;if(n.enabled){const o=e.age/e.life,a=n.evaluate(o);a!==void 0&&(e.uvTile=a)}}}const lb=Symbol("particleRotation");class VR extends Ao{constructor(){super(...arguments);r(this,"type","NeedleRotation")}initialize(e){e[lb]=Math.random()}update(e,i){if(e.rotation===void 0)return;const n=e.age/e.life;if(typeof e.rotation=="number"&&(this.system.rotationOverLifetime.enabled?e.rotation+=this.system.rotationOverLifetime.evaluate(n,e[lb])*i:this.system.renderer.renderMode===ds.Billboard&&(e.rotation=Math.PI),this.system.rotationBySpeed.enabled)){const o=e.velocity.length();e.rotation+=this.system.rotationBySpeed.evaluate(n,o)*i}}}const cb=Symbol("sizeLerpFactor"),$R=new h.Vector3;class WR extends Ao{constructor(){super(...arguments);r(this,"type","NeedleSize");r(this,"_minSize",0);r(this,"_maxSize",1)}initialize(e){e[cb]=Math.random(),this._minSize=this.system.renderer.minParticleSize,this._maxSize=this.system.renderer.maxParticleSize}update(e,i){const n=e.age/e.life;let o=1;this.system.sizeOverLifetime.enabled&&(o*=this.system.sizeOverLifetime.evaluate(n,void 0,e[cb]).x);let a=1;this.system.renderer.renderMode!==ds.Mesh&&(a=this.system.worldScale.x/this.system.cameraScale);const l=V(e.startSize).multiplyScalar(o*a);if(e.size.set(l.x,l.y,l.z),this.system.localspace){const c=Rw(this.system,$R);e.size.x*=c.x,e.size.y*=c.y,e.size.z*=c.z}}}const _a=Symbol("particleLife"),dp=Symbol("trailLifetime"),hb=Symbol("trailStartLength"),up=Symbol("trailWidthRandom");class HR extends Ao{constructor(){super(...arguments);r(this,"type","NeedleTrail")}initialize(e){e instanceof oe.TrailParticle&&(e[_a]=e.life,this.system.trails.enabled&&this.system.trails.dieWithParticles===!1&&(e[dp]=this.system.trails.lifetime.evaluate(Math.random(),Math.random()),e.life+=e[dp]),e[hb]=e.length,e[up]=Math.random())}update(e){var i;if((i=this.system.trails)!=null&&i.enabled&&e instanceof oe.TrailParticle){const n=e,o=e.age/e[_a],a=e.previous.values(),l=e.previous.length;for(let c=0;c<l;c++){const u=a.next().value,f=1-c/(l-1),m=e.size;if(m.x<=0&&!this.system.trails.sizeAffectsWidth){const g=20*this.system.trails.widthOverTrail.evaluate(.5,n[up]);m.x=g,m.y=g,m.z=g}u.size=this.system.trails.getWidth(m.x,o,f,n[up]),u.color.copy(e.color),this.system.trails.getColor(u.color,o,f)}if(e.age>e[_a]){e.velocity.set(0,0,0);const c=(e.age-e[_a])/e[dp];n.length=z.lerp(e[hb],0,c)}}}}const ad=Symbol("startVelocity"),db=Symbol("gravityModifier"),fp=Symbol("gravitySpeed"),ld=Symbol("velocity lerp factor"),Sm=new h.Vector3;class GR extends Ao{constructor(){super(...arguments);r(this,"type","NeedleVelocity");r(this,"_gravityDirection",new h.Vector3)}initialize(e){var a,l;const i=this.system.main.simulationSpeed;e.startSpeed=this.system.main.startSpeed.evaluate(Math.random(),Math.random());const n=this.system.shape.getDirection(e,e.position);e.velocity.x=n.x*e.startSpeed,e.velocity.y=n.y*e.startSpeed,e.velocity.z=n.z*e.startSpeed,(a=this.system.inheritVelocity)!=null&&a.enabled&&this.system.inheritVelocity.applyInitial(e.velocity),e[ad]?e[ad].copy(e.velocity):e[ad]=e.velocity.clone();const o=this.system.main.gravityModifier.evaluate(Math.random(),Math.random());e[db]=o*i,e[fp]=o*i*.5,e[ld]=Math.random(),(l=this.system.velocityOverLifetime)==null||l.init(e),this._gravityDirection.set(0,-1,0),this.system.main.simulationSpace===Tc.Local&&this._gravityDirection.applyQuaternion(this.system.worldQuaternionInverted).normalize()}update(e,i){var m;const n=e[ad],o=e[db];if(o!==0){const g=o*e[fp];Sm.copy(this._gravityDirection).multiplyScalar(g),e[fp]+=i*.05,n.add(Sm)}e.velocity.copy(n);const a=e.age/e.life;(m=this.system.inheritVelocity)!=null&&m.enabled&&this.system.inheritVelocity.applyCurrent(e.velocity,a,e[ld]);const l=this.system.noise;l.enabled&&l.apply(0,e.position,e.velocity,i,e.age,e.life);const c=this.system.sizeBySpeed;c!=null&&c.enabled&&(e.size=c.evaluate(e.velocity,a,e[ld],e.size));const d=this.system.colorBySpeed;d!=null&&d.enabled&&d.evaluate(e.velocity,e[ld],e.color);const u=this.system.velocityOverLifetime;u.enabled&&u.apply(e,0,e.position,e.velocity,i,e.age,e.life);const f=this.system.limitVelocityOverLifetime;if(f.enabled&&f.apply(e.position,n,e.velocity,e.size,a,i,1),this.system.worldspace){const g=this.system.worldScale;e.velocity.x*=g.x,e.velocity.y*=g.y,e.velocity.z*=g.z}}}const ub=Symbol("colorLerpFactor"),fb=new ge(1,1,1,1),Vo=new ge(1,1,1,1);class qR extends Ao{constructor(){super(...arguments);r(this,"type","NeedleColor")}initialize(e){}_init(e){const i=this.system.renderer.particleMaterial;Vo.copy(this.system.main.startColor.evaluate(Math.random())),i!=null&&i.color&&(fb.copy(i.color),Vo.multiply(fb)),Vo.convertLinearToSRGB(),e.startColor.set(Vo.r,Vo.g,Vo.b,Vo.alpha),e.color.copy(e.startColor),e[ub]=Math.random()}update(e,i){if(e.age===0&&this._init(e),this.system.colorOverLifetime.enabled){const n=e.age/e.life,o=this.system.colorOverLifetime.color.evaluate(n,e[ub]);e.color.set(o.r,o.g,o.b,"alpha"in o?o.alpha:1).multiply(e.startColor)}else e.color.copy(e.startColor)}}class XR{constructor(t){r(this,"system");r(this,"emission");r(this,"autoDestroy");r(this,"startLength");r(this,"emissionBursts");r(this,"onlyUsedByOther");r(this,"behaviors",[]);r(this,"rendererEmitterSettings",{startLength:new oe.ConstantValue(220),followLocalOrigin:!1});r(this,"flatWhiteTexture");r(this,"clonedTexture",{original:void 0,clone:void 0});this.system=t,this.emission=new UR(this.system)}get anim(){return this.system.textureSheetAnimation}get prewarm(){return!1}get material(){return this.system.renderer.getMaterial(this.system.trails.enabled)}get layers(){return this.system.gameObject.layers}update(){this.emission.update()}get looping(){return this.system.main.loop}get duration(){return this.system.duration}get shape(){return this.system.shape}get startLife(){return new rd(this.system.main.startLifetime)}get startSpeed(){return new rd(this.system.main.startSpeed)}get startRotation(){return new rd(this.system.main.startRotation)}get startSize(){return new rd(this.system.main.startSize)}get startColor(){return new oe.ConstantColor(new oe.Vector4(1,1,1,1))}get emissionOverTime(){return this.emission}get emissionOverDistance(){return new zR(this.system)}get instancingGeometry(){return this.system.renderer.getMesh(this.system.renderer.renderMode).geometry}get renderMode(){if(this.system.trails.enabled===!0)return oe.RenderMode.Trail;switch(this.system.renderer.renderMode){case ds.Billboard:return oe.RenderMode.BillBoard;case ds.Stretch:return oe.RenderMode.StretchedBillBoard;case ds.HorizontalBillboard:return oe.RenderMode.HorizontalBillBoard;case ds.VerticalBillboard:return oe.RenderMode.VerticalBillBoard;case ds.Mesh:return oe.RenderMode.Mesh}return oe.RenderMode.BillBoard}get speedFactor(){var e;let t=this.system.main.simulationSpeed;return((e=this.system.renderer)==null?void 0:e.renderMode)===ds.Stretch&&(t*=this.system.renderer.velocityScale??1),t}get texture(){const t=this.material;if(t&&t.map){const e=t.map;if(this.clonedTexture.original!==e||!this.clonedTexture.clone){const i=e.clone();i.premultiplyAlpha=!1,i.colorSpace=h.LinearSRGBColorSpace,this.clonedTexture.original=e,this.clonedTexture.clone=i}return this.clonedTexture.clone}return this.flatWhiteTexture||(this.flatWhiteTexture=fg(new ge(1,1,1,1),1)),this.flatWhiteTexture}get startTileIndex(){return new FR(this.system)}get uTileCount(){var t;return this.anim.enabled?(t=this.anim)==null?void 0:t.numTilesX:void 0}get vTileCount(){var t;return this.anim.enabled?(t=this.anim)==null?void 0:t.numTilesY:void 0}get renderOrder(){return 1}get blending(){var t;return((t=this.system.renderer.particleMaterial)==null?void 0:t.blending)??h.NormalBlending}get transparent(){return this.system.renderer.transparent}get worldSpace(){return this.system.main.simulationSpace===Tc.World}}class QR{constructor(){r(this,"burstParticleIndex",0);r(this,"burstParticleCount",0);r(this,"isBursting",!1);r(this,"travelDistance",0);r(this,"previousWorldPos");r(this,"burstIndex",0);r(this,"burstWaveIndex",0);r(this,"time",0);r(this,"waitEmiting",0)}}const Ed=class extends D{constructor(){super(...arguments);r(this,"_state");r(this,"colorOverLifetime");r(this,"main");r(this,"emission");r(this,"sizeOverLifetime");r(this,"shape");r(this,"noise");r(this,"trails");r(this,"velocityOverLifetime");r(this,"limitVelocityOverLifetime");r(this,"inheritVelocity");r(this,"colorBySpeed");r(this,"textureSheetAnimation");r(this,"rotationOverLifetime");r(this,"rotationBySpeed");r(this,"sizeBySpeed");r(this,"_cameraScale",1);r(this,"__worldQuaternion",new h.Quaternion);r(this,"_worldQuaternionInverted",new h.Quaternion);r(this,"_worldScale",new h.Vector3);r(this,"_worldPositionFrame",-1);r(this,"_worldPos",new h.Vector3);r(this,"_renderer");r(this,"_batchSystem");r(this,"_particleSystem");r(this,"_interface");r(this,"_container");r(this,"_time",0);r(this,"_isPlaying",!0);r(this,"_isUsedAsSubsystem",!1);r(this,"_didPreWarm",!1);r(this,"_bursts");r(this,"_subEmitterSystems");r(this,"_lastBatchesCount",-1)}play(t=!1){var e;t&&C.foreachComponent(this.gameObject,i=>{i instanceof Ed&&i!==this&&i.play(!1)},!0),this._isPlaying=!0,this._particleSystem&&(this._particleSystem.emissionState.time=0,this._particleSystem.emitEnded=!1),(e=this.emission)==null||e.reset()}pause(t=!0){t&&C.foreachComponent(this.gameObject,e=>{e instanceof Ed&&e!==this&&e.pause(!1)},!0),this._isPlaying=!1}stop(t=!0,e=!1){t&&C.foreachComponent(this.gameObject,i=>{i instanceof Ed&&i!==this&&i.stop(!1,e)},!0),this._isPlaying=!1,this._time=0,e&&this.reset()}reset(){var t;this._time=0,this._particleSystem&&(this._particleSystem.particleNum=0,this._particleSystem.emissionState.time=0,this._particleSystem.emitEnded=!1,(t=this.emission)==null||t.reset())}emit(t){if(this._particleSystem){this.onUpdate(),t=Math.min(t,this.maxParticles-this.currentParticles),this._state||(this._state=new QR),this._state.waitEmiting=t,this._state.time=0;const e=this._particleSystem.emitEnded;this._particleSystem.emitEnded=!1,this._particleSystem.emit(this.deltaTime,this._state,this._particleSystem.emitter.matrixWorld),this._particleSystem.emitEnded=e}}get playOnAwake(){return this.main.playOnAwake}set playOnAwake(t){this.main.playOnAwake=t}get renderer(){return this._renderer}get isPlaying(){return this._isPlaying}get currentParticles(){var t;return((t=this._particleSystem)==null?void 0:t.particleNum)??0}get maxParticles(){return this.main.maxParticles}get time(){return this._time}get duration(){return this.main.duration}get deltaTime(){return this.context.time.deltaTime*this.main.simulationSpeed}get scale(){return this.gameObject.scale.x}get cameraScale(){return this._cameraScale}get container(){return this._container}get worldspace(){return this.main.simulationSpace===Tc.World}get localspace(){return this.main.simulationSpace===Tc.Local}get worldQuaternion(){return this.__worldQuaternion}get worldQuaternionInverted(){return this._worldQuaternionInverted}get worldScale(){return this._worldScale}get worldPos(){return this._worldPositionFrame!==this.context.time.frame&&(this._worldPositionFrame=this.context.time.frame,K(this.gameObject,this._worldPos)),this._worldPos}get matrixWorld(){return this._container.matrixWorld}get isSubsystem(){return this._isUsedAsSubsystem}addBehaviour(t){return this._particleSystem?(t instanceof Ao&&(t.system=this),(B()||qs)&&console.debug("Add custom ParticleSystem Behaviour",t),this._particleSystem.addBehavior(t),!0):!1}removeBehaviour(t){if(!this._particleSystem)return!1;const e=this._particleSystem.behaviors,i=e.indexOf(t);return i!==-1&&((B()||qs)&&console.debug("Remove custom ParticleSystem Behaviour",i,t),e.splice(i,1)),!0}removeAllBehaviours(){return this._particleSystem?(this._particleSystem.behaviors.length=0,!0):!1}get behaviours(){return this._particleSystem?this._particleSystem.behaviors:null}get particleSystem(){return this._particleSystem??null}set bursts(t){for(let e=0;e<t.length;e++){const i=t[e];if(!(i instanceof Ec)){const n=new Ec;ja(n,i),t[e]=n}}this._bursts=t}set subEmitterSystems(t){for(let e=0;e<t.length;e++){const i=t[e];if(!(i instanceof Ac)){const n=new Ac;ja(n,i),t[e]=n}}qs&&t.length>0&&console.log("SubEmitters: ",t,this),this._subEmitterSystems=t}onAfterDeserialize(t){if(this._subEmitterSystems&&Array.isArray(this._subEmitterSystems))for(const e of this._subEmitterSystems)e._deserialize(this.context,this.gameObject)}awake(){if(this._worldPositionFrame=-1,this._renderer=this.gameObject.getComponent(Xi),!this.main)throw new Error("Not Supported: ParticleSystem needs a serialized MainModule. Creating new particle systems at runtime is currently not supported.");this._container=new h.Object3D,this._container.matrixAutoUpdate=!1,this.context.scene.add(this._container),this._batchSystem=new oe.BatchedParticleRenderer,this._batchSystem.name=this.gameObject.name,this._container.add(this._batchSystem),this._interface=new XR(this),this._particleSystem=new oe.ParticleSystem(this._interface),this._particleSystem.addBehavior(new WR(this)),this._particleSystem.addBehavior(new qR(this)),this._particleSystem.addBehavior(new NR(this)),this._particleSystem.addBehavior(new VR(this)),this._particleSystem.addBehavior(new GR(this)),this._particleSystem.addBehavior(new HR(this)),this._batchSystem.addSystem(this._particleSystem);const t=this._particleSystem.emitter;this.context.scene.add(t),this.inheritVelocity.system&&this.inheritVelocity.system!==this&&(this.inheritVelocity=this.inheritVelocity.clone()),this.inheritVelocity.awake(this),qs&&(console.log(this),this.gameObject.add(new h.AxesHelper(1)))}start(){this.addSubParticleSystems(),this.updateLayers(),this.renderer.particleMesh instanceof h.Mesh&&this._interface.renderMode==oe.RenderMode.Mesh&&re.NEEDLE_progressive.assignMeshLOD(this.renderer.particleMesh,0).then(t=>{t&&this.particleSystem&&this._interface.renderMode==oe.RenderMode.Mesh&&(this.particleSystem.instancingGeometry=t)})}onDestroy(){var t,e,i,n;(t=this._container)==null||t.removeFromParent(),(e=this._batchSystem)==null||e.removeFromParent(),(i=this._particleSystem)==null||i.emitter.removeFromParent(),(n=this._particleSystem)==null||n.dispose()}onEnable(){this.main&&(this.inheritVelocity&&(this.inheritVelocity.system=this),this._batchSystem&&(this._batchSystem.visible=!0),this.playOnAwake&&this.play(),this._isPlaying=this.playOnAwake)}onDisable(){this._batchSystem&&(this._batchSystem.visible=!1)}onBeforeRender(){var t;this.main&&(this._didPreWarm===!1&&((t=this.main)==null?void 0:t.prewarm)===!0&&(this._didPreWarm=!0,this.preWarm()),this.onUpdate(),this.onSimulate(this.deltaTime))}preWarm(){var d;if(!((d=this.emission)!=null&&d.enabled)||this.emission.rateOverTime.getMax()<=0)return;const e=1/60,i=this.main.duration,n=this.main.startLifetime.getMax(),o=1e3,a=Math.min(Math.max(i,n)/Math.max(.01,this.main.simulationSpeed),o),l=Math.ceil(a/e),c=Date.now();qs&&console.log(`Particles ${this.name} - Prewarm for ${l} frames (${a} sec). Duration: ${i}, Lifetime: ${n}`);for(let u=0;u<l&&!(this.currentParticles>=this.maxParticles);u++){const f=Date.now()-c;if(f>2e3){console.warn(`Particles ${this.name} - Prewarm took too long. Aborting: ${f}`);break}this.onUpdate(),this.onSimulate(e)}}onSimulate(t){if(this._batchSystem){let e=this.context.time.frameCount%60===0;this._lastBatchesCount!==this._batchSystem.batches.length&&(this._lastBatchesCount=this._batchSystem.batches.length,e=!0),e&&this.updateLayers(),this._batchSystem.update(t)}this._time+=t,this._time>this.duration&&(this._time=0)}updateLayers(){if(this._batchSystem)for(let t=0;t<this._batchSystem.batches.length;t++){const e=this._batchSystem.batches[t];e.layers.disableAll();const i=this.layer;e.layers.mask=1<<i}}onUpdate(){var n,o;if(this._bursts&&(this.emission.bursts=this._bursts,delete this._bursts),!this._isPlaying)return;const t=this.context.mainCamera;if(t){const a=Ne(t);this._cameraScale=a.x}const e=!this.worldspace,i=this.gameObject;if(ye(i,this.__worldQuaternion),this._worldQuaternionInverted.copy(this.__worldQuaternion).invert(),Ne(this.gameObject,this._worldScale),e&&this._container&&((n=this.gameObject)!=null&&n.parent)){const a=Rw(this,Sm);this._container.matrix.makeScale(a.x,a.y,a.z),this._container.matrix.makeRotationFromQuaternion(this.__worldQuaternion),this._container.matrix.setPosition(this.worldPos),this._container.matrix.scale(this.gameObject.scale)}this.emission.system=this,this._interface.update(),this.shape.onUpdate(this,this.context,this.main.simulationSpace,this.gameObject),this.noise.update(this.context),(o=this.inheritVelocity)==null||o.update(this.context),this.velocityOverLifetime.update(this)}addSubParticleSystems(){var t;if(this._subEmitterSystems&&this._particleSystem)for(const e of this._subEmitterSystems){e.particleSystem&&(e.particleSystem.__internalAwake?e.particleSystem.__internalAwake():B()&&console.warn("SubParticleSystem serialization issue(?)",e.particleSystem,e));const i=(t=e.particleSystem)==null?void 0:t._particleSystem;if(i){e.particleSystem._isUsedAsSubsystem=!0;const n=new nf(this,this._particleSystem,e.particleSystem,i);n.emitterType=e.type,n.emitterProbability=e.emitProbability,this._particleSystem.addBehavior(n)}else qs&&console.warn("Could not add SubParticleSystem",e,this)}}};let Qe=Ed;ze([p(yh)],Qe.prototype,"colorOverLifetime",2);ze([p(Mt)],Qe.prototype,"main",2);ze([p(Qn)],Qe.prototype,"emission",2);ze([p(To)],Qe.prototype,"sizeOverLifetime",2);ze([p(Fe)],Qe.prototype,"shape",2);ze([p(_e)],Qe.prototype,"noise",2);ze([p(De)],Qe.prototype,"trails",2);ze([p(Ue)],Qe.prototype,"velocityOverLifetime",2);ze([p(Ke)],Qe.prototype,"limitVelocityOverLifetime",2);ze([p(Eo)],Qe.prototype,"inheritVelocity",2);ze([p(Ur)],Qe.prototype,"colorBySpeed",2);ze([p(Rt)],Qe.prototype,"textureSheetAnimation",2);ze([p(qi)],Qe.prototype,"rotationOverLifetime",2);ze([p(Ti)],Qe.prototype,"rotationBySpeed",2);ze([p(Kt)],Qe.prototype,"sizeBySpeed",2);class Ac{constructor(){r(this,"particleSystem");r(this,"emitProbability",1);r(this,"properties");r(this,"type")}_deserialize(t,e){const i=this.particleSystem;if(i instanceof Qe)return;let n="";i&&typeof i.guid=="string"&&(n=i.guid,this.particleSystem=C.findByGuid(n,e)),qs&&!(this.particleSystem instanceof Qe)&&console.warn("Could not find particle system for sub emitter",n,e,this)}}function Rw(s,t){if(t.set(1,1,1),s.gameObject.parent&&s.localspace)switch(s.main.scalingMode){case wm.Local:t=Ne(s.gameObject.parent,t),t.x=1/t.x,t.y=1/t.y,t.z=1/t.z;break;default:if(!s.unsupported_scaling_mode){s.unsupported_scaling_mode=!0;const e="ParticleSystem scale mode "+wm[s.main.scalingMode]+" is not supported";B()&&me(e),console.warn(e,s.name,s)}t=Ne(s.gameObject,t);break}return t}class Ua extends D{constructor(){super(...arguments);r(this,"_didAssignPlayerColor",!1);r(this,"tryAssignColor",()=>{const e=C.getComponentInParent(this.gameObject,wi);if(e&&e.owner)return this._didAssignPlayerColor=!0,this.assignUserColor(e.owner),!0;const i=C.getComponentInParent(this.gameObject,it);return i!=null&&i.connectionId?(this._didAssignPlayerColor=!0,this.assignUserColor(i.connectionId),!0):!1})}onEnable(){this.context.connection.beginListen(Z.JoinedRoom,this.tryAssignColor),this._didAssignPlayerColor||this.startCoroutine(this.waitForConnection())}onDisable(){this.context.connection.stopListen(Z.JoinedRoom,this.tryAssignColor)}*waitForConnection(){for(;!this.destroyed&&this.activeAndEnabled&&(yield d0(.2),!this.tryAssignColor()););}assignUserColor(e){const i=Ua.hashCode(e),n=Ua.colorFromHashCode(i);if(this.gameObject.type==="Mesh"){const o=this.gameObject;this.assignColor(n,e,o)}else if(this.gameObject.children)for(const o of this.gameObject.children){const a=o;a.material&&a.material.color&&this.assignColor(n,e,a)}}assignColor(e,i,n){let o=n.material;o&&(o._playerMaterial!==i&&(o=o.clone(),o._playerMaterial=i,n.material=o),o.color=e)}static hashCode(e){var i=0,n,o;if(e.length===0)return i;for(n=0;n<e.length;n++)o=e.charCodeAt(n),i=(i<<5)-i+o,i|=0;return i}static colorFromHashCode(e){const i=(e&16711680)>>16,n=(e&65280)>>8,o=e&255;return new h.Color(i/255,n/255,o/255)}}const YR=S("debugpost");let Cm=null;function KR(s){Cm=s}function kw(s){let t=s.gameObject;for(;t;){for(const e of Au(t))if(e.isPostProcessingManager===!0)return e;t=t.parent}return null}function ZR(s){let t=kw(s);if(!t)if(Cm){YR&&console.warn("Adding postprocessing manager to the scene.");const e=s.scene;t=xi(e,Cm)}else B()&&console.warn("No post processing manager found");return t}var JR=Object.defineProperty,ek=Object.getOwnPropertyDescriptor,Tw=(s,t,e,i)=>{for(var n=i>1?void 0:i?ek(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&JR(t,e,n),n};const tk=S("debugpost");class U{constructor(t){r(this,"isVolumeParameter",!0);r(this,"_isInitialized",!1);r(this,"_active",!0);r(this,"_value");r(this,"_valueRaw");r(this,"_defaultValue");r(this,"valueProcessor");r(this,"onValueChanged");t!==void 0&&this.initialize(t)}get isInitialized(){return this._isInitialized}initialize(t){t!==void 0&&(this._value=t,this._defaultValue=t,this._valueRaw=t,this._isInitialized=!0)}get overrideState(){return this._active}set overrideState(t){if(this._active===t)return;this._active=t;const e=t?this._valueRaw:this._defaultValue;this.processValue(e,!0)}get value(){return this._valueRaw}set value(t){this.isInitialized||this.initialize(t),this.processValue(t,!1)}set defaultValue(t){this._defaultValue=t}__init(){this.processValue(this._valueRaw,!0)}processValue(t,e){if(t==null||!e&&this.testIfValueChanged(t)===!1)return;const i=this._value;tk&&typeof i=="number"&&typeof t=="number"&&(i==null||i.toFixed(4),t==null||t.toFixed(4)),!this._active&&this._defaultValue!==void 0?(this._value=this._defaultValue,t=this._defaultValue,this._valueRaw=t):(this._valueRaw=t,this._active&&this.valueProcessor&&(t=this.valueProcessor(t)),this._value=t),this.onValueChanged&&this.onValueChanged(t,i,this)}testIfValueChanged(t){return this._valueRaw!==t}}Tw([p()],U.prototype,"overrideState",1);Tw([p()],U.prototype,"value",1);class ik extends Gi{constructor(){super([U])}onSerialize(t,e){}onDeserialize(t,e){const i=e.target,n=e.path;let o;if(i&&n&&(o=i[n]),(typeof o!="object"||typeof o=="object"&&o.isVolumeParameter!==!0)&&(o=new U),typeof t=="object"&&"value"in t){const a=t.value;o.initialize(a),o.overrideState=t.overrideState}else o.value=t;return o}}new ik;var nk=Object.defineProperty,sk=Object.getOwnPropertyDescriptor,ok=(s,t,e,i)=>{for(var n=i>1?void 0:i?sk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&nk(t,e,n),n};const rk=S("debugpost");class Xe extends D{constructor(e=void 0){super();r(this,"active",!0);r(this,"_manager",null);r(this,"_result");r(this,"_postprocessingContext",null);if(e)for(const i of Object.keys(e)){const n=e[i],o=this[i];o instanceof U?o.initialize(n):o!==void 0&&(this[i]=n)}}get isPostProcessingEffect(){return!0}onEnable(){super.onEnable(),this.onEffectEnabled(),this.__internalDidAwakeAndStart&&(this.active=!0)}onDisable(){var e;super.onDisable(),(e=this._manager)==null||e.removeEffect(this),this.active=!1}onEffectEnabled(e){var i;e&&e.isPostProcessingManager===!0?this._manager=e:this._manager||(this._manager=ZR(this)),(i=this._manager)==null||i.addEffect(this)}init(){}get postprocessingContext(){return this._postprocessingContext}apply(e){var i;return this._postprocessingContext=e,this._result||(this.initParameters(),this._result=(i=this.onCreateEffect)==null?void 0:i.call(this)),this._result&&this.initParameters(),this._result}unapply(){}dispose(){rk&&console.warn("DISPOSE",this),this._result&&(Array.isArray(this._result)?this._result.forEach(e=>e.dispose()):this._result.dispose()),this._result=void 0}initParameters(){const e=Object.keys(this);for(const i of e){const n=this[i];n instanceof U&&n.__init()}}onEditorModification(e){const i=e.propertyName;if(this[i]instanceof U){const n=e.value;return this[i].value=n,!0}}}ok([p()],Xe.prototype,"active",2);var ak=Object.defineProperty,lk=Object.getOwnPropertyDescriptor,ck=(s,t,e,i)=>{for(var n=i>1?void 0:i?lk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&ak(t,e,n),n};const hk=S("debugpost"),Pm={};function Qi(s,t){Pm[s]=t}function dk(s){return s.__type in Pm?Pm[s.__type]:(hk&&s.__type&&console.warn("Unknown postprocessing type",s.__type,s),Xe)}class bh{constructor(){r(this,"components",[])}init(){var t;(t=this.components)==null||t.forEach(e=>e.init())}addEffect(t){this.components.push(t)}removeEffect(t){const e=this.components.indexOf(t);e>=0&&this.components.splice(e,1)}}ck([Va([s=>dk(s),Xe])],bh.prototype,"components",2);var uk=Object.defineProperty,fk=Object.getOwnPropertyDescriptor,pk=(s,t,e,i)=>{for(var n=i>1?void 0:i?fk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&uk(t,e,n),n};class vh extends Xe{constructor(){super(...arguments);r(this,"preset",new U(2))}get typeName(){return"Antialiasing"}onCreateEffect(){const e=new exports.MODULES.POSTPROCESSING.MODULE.SMAAEffect({preset:exports.MODULES.POSTPROCESSING.MODULE.SMAAPreset.HIGH,edgeDetectionMode:exports.MODULES.POSTPROCESSING.MODULE.EdgeDetectionMode.DEPTH});return this.preset.onValueChanged=i=>{e.applyPreset(i)},e}}pk([p(U)],vh.prototype,"preset",2);Qi("Antialiasing",vh);var mk=Object.defineProperty,gk=Object.getOwnPropertyDescriptor,r_=(s,t,e,i)=>{for(var n=i>1?void 0:i?gk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&mk(t,e,n),n},Ep;const Ew=(Ep=class extends Xe{constructor(){super(...arguments);r(this,"threshold",new U(.9));r(this,"intensity",new U(1));r(this,"scatter",new U(.3));r(this,"selectiveBloom")}get typeName(){return"Bloom"}init(){this.threshold.valueProcessor=t=>t,this.intensity.valueProcessor=t=>t,this.scatter.valueProcessor=t=>t}onCreateEffect(){let t;if(this.selectiveBloom==null&&(this.selectiveBloom=Ew.useSelectiveBloom),this.selectiveBloom){const e=t=new exports.MODULES.POSTPROCESSING.MODULE.SelectiveBloomEffect(this.context.scene,this.context.mainCamera,{blendFunction:exports.MODULES.POSTPROCESSING.MODULE.BlendFunction.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,radius:.85,intensity:this.intensity.value});e.inverted=!0}else t=new exports.MODULES.POSTPROCESSING.MODULE.BloomEffect({blendFunction:exports.MODULES.POSTPROCESSING.MODULE.BlendFunction.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,radius:.85,intensity:this.intensity.value});return this.intensity.onValueChanged=e=>{t.intensity=e},this.threshold.onValueChanged=e=>{t.luminanceMaterial.threshold=Math.pow(e,2.2)},this.scatter.onValueChanged=e=>{t.luminancePass.enabled=!0,t.luminanceMaterial.smoothing=e,t.mipmapBlurPass&&(t.mipmapBlurPass.radius=h.MathUtils.lerp(.1,.9,e))},t}},r(Ep,"useSelectiveBloom",!1),Ep);let zr=Ew;r_([p(U)],zr.prototype,"threshold",2);r_([p(U)],zr.prototype,"intensity",2);r_([p(U)],zr.prototype,"scatter",2);Qi("Bloom",zr);var _k=Object.defineProperty,yk=Object.getOwnPropertyDescriptor,bk=(s,t,e,i)=>{for(var n=i>1?void 0:i?yk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&_k(t,e,n),n};class wh extends Xe{constructor(){super(...arguments);r(this,"intensity",new U(0))}get typeName(){return"ChromaticAberration"}onCreateEffect(){const e=new exports.MODULES.POSTPROCESSING.MODULE.ChromaticAberrationEffect;return e.offset=new h.Vector2(0,0),e.radialModulation=!0,e.modulationOffset=.15,this.intensity.valueProcessor=i=>i*.02,this.intensity.onValueChanged=i=>{e.offset.x=-i,e.offset.y=i},e}}bk([p(U)],wh.prototype,"intensity",2);Qi("ChromaticAberration",wh);var vk=Object.defineProperty,wk=Object.getOwnPropertyDescriptor,Aw=(s,t,e,i)=>{for(var n=i>1?void 0:i?wk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&vk(t,e,n),n};const pb=S("debugpost");var Ad=(s=>(s[s.None=0]="None",s[s.Neutral=1]="Neutral",s[s.ACES=2]="ACES",s[s.AgX=3]="AgX",s[s.KhronosNeutral=4]="KhronosNeutral",s))(Ad||{});function pp(s){switch(s){case 0:return h.LinearToneMapping;case 1:return h.ReinhardToneMapping;case 2:return h.ACESFilmicToneMapping;case 3:return h.AgXToneMapping;case 4:return h.NeutralToneMapping;default:return h.NeutralToneMapping}}function xk(s){switch(s){case h.LinearToneMapping:return 0;case h.ACESFilmicToneMapping:return 2;case h.AgXToneMapping:return 3;case h.NeutralToneMapping:return 1;case h.ReinhardToneMapping:return 1;default:return 0}}function mb(s){switch(s){case h.LinearToneMapping:return exports.MODULES.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR;case h.ACESFilmicToneMapping:return exports.MODULES.POSTPROCESSING.MODULE.ToneMappingMode.ACES_FILMIC;case h.AgXToneMapping:return exports.MODULES.POSTPROCESSING.MODULE.ToneMappingMode.AGX;case h.NeutralToneMapping:return exports.MODULES.POSTPROCESSING.MODULE.ToneMappingMode.NEUTRAL;case h.ReinhardToneMapping:return exports.MODULES.POSTPROCESSING.MODULE.ToneMappingMode.REINHARD;default:return exports.MODULES.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR}}const Dw=class extends Xe{constructor(){super(...arguments);r(this,"mode",new U(void 0));r(this,"exposure",new U(1))}get typeName(){return"ToneMapping"}setMode(t){const e=Ad[t];return e===void 0?(console.error("Invalid ToneMapping mode",t),this):(this.mode.value=e,this)}get isToneMapping(){return!0}onEffectEnabled(){const t=kw(this);t&&super.onEffectEnabled(t)}onCreateEffect(){if(this.postprocessingContext)for(const i of this.postprocessingContext.components){if(i===this)break;if(i!=this&&i instanceof Dw){console.warn("Multiple tonemapping effects found in the same postprocessing stack: Please check your scene setup.",{activeEffect:i,ignoredEffect:this});return}}if(this.mode.isInitialized==!1){const i=xk(this.context.renderer.toneMapping);this.mode.initialize(i)}const t=pp(this.mode.value),e=new exports.MODULES.POSTPROCESSING.MODULE.ToneMappingEffect({mode:mb(t)});return this.mode.onValueChanged=i=>{const n=pp(i);e.mode=mb(n),pb&&console.log("ToneMapping mode changed to",Ad[i],n,e.mode)},pb&&console.log("Use ToneMapping",Ad[this.mode.value],t,e.mode,"renderer.tonemapping: "+this.context.renderer.toneMapping),this.exposure.onValueChanged=i=>{this.context.renderer.toneMappingExposure=i},e}onBeforeRender(){this.mode.overrideState&&(this.context.renderer.toneMapping=pp(this.mode.value)),this.exposure.overrideState&&(this.context.renderer.toneMappingExposure=this.exposure.value)}};let mo=Dw;Aw([p(U)],mo.prototype,"mode",2);Aw([p(U)],mo.prototype,"exposure",2);Qi("Tonemapping",mo);var Sk=Object.defineProperty,Ck=Object.getOwnPropertyDescriptor,sf=(s,t,e,i)=>{for(var n=i>1?void 0:i?Ck(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&Sk(t,e,n),n};class Do extends Xe{constructor(){super(...arguments);r(this,"postExposure",new U(0));r(this,"contrast",new U(0));r(this,"hueShift",new U(0));r(this,"saturation",new U(0))}get typeName(){return"ColorAdjustments"}init(){this.postExposure.valueProcessor=e=>(e=Math.pow(2,e),e),this.contrast.valueProcessor=e=>{let i=1;return e>0?i=200:e<0&&(i=100),e/i},this.contrast.defaultValue=0,this.hueShift.valueProcessor=e=>Math.PI*e/180,this.hueShift.defaultValue=0,this.saturation.valueProcessor=e=>e<0?e/100:e/(100*Math.PI),this.saturation.defaultValue=0}onCreateEffect(){var a,l;const e=[];this.context.renderer.toneMapping!==h.NoToneMapping&&this.postExposure.overrideState&&(this.context.renderer.toneMapping=h.NoToneMapping);let i=(a=this.postprocessingContext)==null?void 0:a.components.find(c=>c instanceof mo);i||(i=new mo,(l=this.postprocessingContext)==null||l.components.push(i)),this.postExposure.onValueChanged=c=>{this.postExposure.overrideState&&(i.exposure.value=c)};const n=new exports.MODULES.POSTPROCESSING.MODULE.BrightnessContrastEffect;this.contrast.onValueChanged=c=>n.contrast=c;const o=new exports.MODULES.POSTPROCESSING.MODULE.HueSaturationEffect;return e.push(n),e.push(o),this.hueShift.onValueChanged=c=>o.hue=c,this.saturation.onValueChanged=c=>o.saturation=c,e}}sf([p(U)],Do.prototype,"postExposure",2);sf([p(U)],Do.prototype,"contrast",2);sf([p(U)],Do.prototype,"hueShift",2);sf([p(U)],Do.prototype,"saturation",2);Qi("ColorAdjustments",Do);var Pk=Object.defineProperty,Ok=Object.getOwnPropertyDescriptor,Nr=(s,t,e,i)=>{for(var n=i>1?void 0:i?Ok(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&Pk(t,e,n),n};const Mk=S("debugpost");class _n extends Xe{constructor(){super(...arguments);r(this,"mode");r(this,"focusDistance",new U(1));r(this,"focalLength",new U(.2));r(this,"aperture",new U(20));r(this,"gaussianMaxRadius",new U);r(this,"resolutionScale",new U(1*1/window.devicePixelRatio));r(this,"bokehScale",new U)}get typeName(){return"DepthOfField"}init(){this.focalLength.valueProcessor=i=>{const n=i/300,o=2;return z.lerp(o,.01,n)};const e=20;this.aperture.valueProcessor=i=>{const n=1-i/32;return z.lerp(1,e,n)}}onCreateEffect(){if(this.mode===0){Mk&&console.warn("DepthOfField: Mode is set to Off");return}const e=new exports.MODULES.POSTPROCESSING.MODULE.DepthOfFieldEffect(this.context.mainCamera,{worldFocusRange:.2,focalLength:1,bokehScale:20,resolutionScale:this.resolutionScale.value});return this.focusDistance.onValueChanged=i=>{e.cocMaterial.worldFocusDistance=i},this.focalLength.onValueChanged=i=>e.cocMaterial.worldFocusRange=i,this.aperture.onValueChanged=i=>e.bokehScale=i,this.resolutionScale&&(this.resolutionScale.onValueChanged=i=>e.resolution.scale=i),[e]}unapply(){}}Nr([p()],_n.prototype,"mode",2);Nr([p(U)],_n.prototype,"focusDistance",2);Nr([p(U)],_n.prototype,"focalLength",2);Nr([p(U)],_n.prototype,"aperture",2);Nr([p(U)],_n.prototype,"gaussianMaxRadius",2);Nr([p(U)],_n.prototype,"resolutionScale",2);Nr([p(U)],_n.prototype,"bokehScale",2);Qi("DepthOfField",_n);class Dc extends Xe{constructor(e){super();r(this,"effect");this.effect=e}get typeName(){return this.effect.constructor.name}onCreateEffect(){return this.effect}}var Rk=Object.defineProperty,kk=Object.getOwnPropertyDescriptor,Tk=(s,t,e,i)=>{for(var n=i>1?void 0:i?kk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&Rk(t,e,n),n};class xh extends Xe{constructor(){super(...arguments);r(this,"granularity",new U(10))}get typeName(){return"PixelationEffect"}onCreateEffect(){const e=new exports.MODULES.POSTPROCESSING.MODULE.PixelationEffect;return this.granularity.onValueChanged=i=>{e.granularity=i},e}}Tk([p(U)],xh.prototype,"granularity",2);Qi("PixelationEffect",xh);var Ek=Object.defineProperty,Ak=Object.getOwnPropertyDescriptor,Sh=(s,t,e,i)=>{for(var n=i>1?void 0:i?Ak(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&Ek(t,e,n),n};class Es extends Xe{constructor(){super(...arguments);r(this,"intensity",new U(2));r(this,"falloff",new U(1));r(this,"samples",new U(9));r(this,"color",new U(new h.Color(0,0,0)));r(this,"luminanceInfluence",new U(.7));r(this,"_ssao")}get typeName(){return"ScreenSpaceAmbientOcclusion"}onBeforeRender(){if(this._ssao&&this.context.mainCamera instanceof h.PerspectiveCamera){const e=this.context.mainCamera.far-this.context.mainCamera.near;this._ssao.ssaoMaterial.worldDistanceFalloff=e*.01,this._ssao.ssaoMaterial.worldDistanceThreshold=this.context.mainCamera.far}}onCreateEffect(){const e=this.context.mainCamera,i=new exports.MODULES.POSTPROCESSING.MODULE.NormalPass(this.context.scene,e),n=new exports.MODULES.POSTPROCESSING.MODULE.DepthDownsamplingPass({normalBuffer:i.texture,resolutionScale:.5}),o=this._ssao=new exports.MODULES.POSTPROCESSING.MODULE.SSAOEffect(e,i.texture,{normalDepthBuffer:n.texture,worldDistanceThreshold:1,worldDistanceFalloff:1,worldProximityThreshold:.1,worldProximityFalloff:2,intensity:1,blendFunction:exports.MODULES.POSTPROCESSING.MODULE.BlendFunction.MULTIPLY,luminanceInfluence:.5});this.intensity.onValueChanged=l=>{o.intensity=l},this.falloff.onValueChanged=l=>{o.ssaoMaterial.radius=l*.1},this.samples.onValueChanged=l=>{o.ssaoMaterial.samples=l},this.color.onValueChanged=l=>{o.color||(o.color=new h.Color),o.color.copy(l)},this.luminanceInfluence.onValueChanged=l=>{o.luminanceInfluence=l};const a=new Array;return a.push(i),a.push(n),a.push(o),a}}Sh([p(U)],Es.prototype,"intensity",2);Sh([p(U)],Es.prototype,"falloff",2);Sh([p(U)],Es.prototype,"samples",2);Sh([p(U)],Es.prototype,"color",2);Sh([p(U)],Es.prototype,"luminanceInfluence",2);Qi("ScreenSpaceAmbientOcclusion",Es);var Dk=Object.defineProperty,Lk=Object.getOwnPropertyDescriptor,Vr=(s,t,e,i)=>{for(var n=i>1?void 0:i?Lk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&Dk(t,e,n),n},Om=(s=>(s[s.Performance=0]="Performance",s[s.Low=1]="Low",s[s.Medium=2]="Medium",s[s.High=3]="High",s[s.Ultra=4]="Ultra",s))(Om||{});class yn extends Xe{constructor(){super(...arguments);r(this,"gammaCorrection",!0);r(this,"aoRadius",new U(1));r(this,"falloff",new U(1));r(this,"intensity",new U(1));r(this,"color",new U(new h.Color(0,0,0)));r(this,"screenspaceRadius",!1);r(this,"quality",2);r(this,"_ssao")}get typeName(){return"ScreenSpaceAmbientOcclusionN8"}onValidate(){this._ssao&&(this._ssao.setQualityMode(Om[this.quality]),this._ssao.configuration.gammaCorrection=this.gammaCorrection,this._ssao.configuration.screenSpaceRadius=this.screenspaceRadius)}onCreateEffect(){const e=this.context.mainCamera,i=this._ssao=new exports.MODULES.POSTPROCESSING_AO.MODULE.N8AOPostPass(this.context.scene,e,this.context.domWidth,this.context.domHeight),n=Om[this.quality];i.setQualityMode(n),i.configuration.gammaCorrection=this.gammaCorrection,i.configuration.screenSpaceRadius=this.screenspaceRadius,this.intensity.onValueChanged=a=>{i.configuration.intensity=a},this.falloff.onValueChanged=a=>{i.configuration.distanceFalloff=a},this.aoRadius.onValueChanged=a=>{i.configuration.aoRadius=a},this.color.onValueChanged=a=>{i.color||(i.color=new h.Color),i.configuration.color.copy(a)};const o=new Array;return o.push(i),o}}Vr([Pt(),p()],yn.prototype,"gammaCorrection",2);Vr([p(U)],yn.prototype,"aoRadius",2);Vr([p(U)],yn.prototype,"falloff",2);Vr([p(U)],yn.prototype,"intensity",2);Vr([p(U)],yn.prototype,"color",2);Vr([Pt(),p()],yn.prototype,"screenspaceRadius",2);Vr([Pt(),p()],yn.prototype,"quality",2);Qi("ScreenSpaceAmbientOcclusionN8",yn);var Ik=Object.defineProperty,jk=Object.getOwnPropertyDescriptor,Lw=(s,t,e,i)=>{for(var n=i>1?void 0:i?jk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&Ik(t,e,n),n};class Ch extends Xe{constructor(){super(...arguments);r(this,"_effect");r(this,"_amount",1);r(this,"_radius",1)}get typeName(){return"Sharpening"}onCreateEffect(){return this._effect??(this._effect=new(Bk())),this.effect}get effect(){return this._effect}set amount(e){this._amount=e,this._effect&&(this._effect.uniforms.get("amount").value=e)}get amount(){return this._effect?this._effect.uniforms.get("amount").value:this._amount}set radius(e){this._radius=e,this._effect&&(this._effect.uniforms.get("radius").value=e)}get radius(){return this._effect?this._effect.uniforms.get("radius").value:this._radius}}Lw([p()],Ch.prototype,"amount",1);Lw([p()],Ch.prototype,"radius",1);function Bk(){const s=`
1205
+ `)}a&&o.size&&console.log(f);const _=new Set;for(const v of g){v.getPath||console.error("USDZExporter: Animation target object has no getPath method. This is likely a bug",v);let x=v.getPath();x.startsWith("<")&&(x=x.substring(1)),x.endsWith(">")&&(x=x.substring(0,x.length-1)),_.add({path:x,obj:v})}const y=Array.from(_).sort((v,x)=>v.path.length-x.path.length),b=new Array;for(let v=0;v<y.length;v++)for(let x=v+1;x<y.length;x++)if(y[x].path.startsWith(y[v].path)){const O=y[x],k=y[v];b.push({child:O.obj.displayName+" ("+O.path+")",parent:k.obj.displayName+" ("+k.path+")"})}b.length&&console.warn("USDZExporter: There are overlapping PlayAnimation actions. This can lead to undefined runtime behaviour when playing multiple animations. Please restructure the hierarchy so that animations don't overlap.",{overlappingTargets:b,playAnimationActions:o})}for(const f of new Set([...e,...i]))if(Array.isArray(f))for(const m of f)n.add(m.uuid);else n.add(f.uuid);td&&console.log("All Behavior trigger sources and action targets",e,i,n),this.targetUuids=new Set(n)}onAfterHierarchy(t,e){var i;if((i=this.behaviours)!=null&&i.length){e.beginBlock('def Scope "Behaviors"');for(const n of this.behaviours)n.writeTo(this,t.document,e);e.closeBlock()}}async onAfterSerialize(t){td&&console.log("onAfterSerialize behaviours",this.behaviourComponentsCopy);for(const e of this.behaviourComponentsCopy)typeof e.afterSerialize=="function"&&(e.afterSerialize.constructor.name==="AsyncFunction"?await e.afterSerialize(this,t):e.afterSerialize(this,t));for(const{clipUrl:e,filesKey:i}of this.audioClipsCopy){if(t.files[i])return;const a=await(await(await fetch(e)).blob()).arrayBuffer(),l=new Uint8Array(a);t.files[i]=l}this.behaviourComponentsCopy.length=0,this.audioClipsCopy.length=0}}var mM=Object.defineProperty,gM=Object.getOwnPropertyDescriptor,Be=(s,t,e,i)=>{for(var n=i>1?void 0:i?gM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&mM(t,e,n),n};const ib=S("debugusdzbehaviours");function ch(s){s&&(s.getComponentInParent(Fa)||(B()&&console.debug('Raycaster on "'+s.name+'" was automatically added, because no raycaster was found in the parent hierarchy.'),s.addComponent(Oi)))}class Dr extends D{constructor(){super(...arguments);r(this,"object");r(this,"target");r(this,"duration",1);r(this,"relativeMotion",!1);r(this,"coroutine",null);r(this,"targetPos",new h.Vector3);r(this,"targetRot",new h.Quaternion);r(this,"targetScale",new h.Vector3)}start(){ch(this.gameObject)}onPointerClick(e){e.use(),this.coroutine&&this.stopCoroutine(this.coroutine),this.relativeMotion?this.coroutine=this.startCoroutine(this.moveRelative()):this.coroutine=this.startCoroutine(this.moveToTarget())}*moveToTarget(){if(!this.target||!this.object)return;const e=K(this.object).clone(),i=K(this.target).clone(),n=ye(this.object).clone(),o=ye(this.target).clone(),a=Ne(this.object).clone(),l=Ne(this.target).clone(),c=e.distanceTo(i),d=n.angleTo(o),u=a.distanceTo(l);if(c<.01&&d<.01&&u<.01){nt(this.object,i),Wi(this.object,o),Da(this.object,l),this.coroutine=null;return}let f=0,m=0;for(;f<1;)f+=this.context.time.deltaTime/this.duration,f>1&&(f=1),m=f<.5?4*f*f*f:1-Math.pow(-2*f+2,3)/2,this.targetPos.lerpVectors(e,i,m),this.targetRot.slerpQuaternions(n,o,m),this.targetScale.lerpVectors(a,l,m),nt(this.object,this.targetPos),Wi(this.object,this.targetRot),Da(this.object,this.targetScale),yield;this.coroutine=null}*moveRelative(){if(!this.target||!this.object)return;const e=this.object.position.clone(),i=this.object.quaternion.clone(),n=this.object.scale.clone(),o=this.target.position.clone(),a=this.target.quaternion.clone(),l=this.target.scale.clone();o.applyQuaternion(this.object.quaternion),this.targetPos.copy(this.object.position).add(o),this.targetRot.copy(this.object.quaternion).multiply(a),this.targetScale.copy(this.object.scale).multiply(l);let c=0,d=0;for(;c<1;)c+=this.context.time.deltaTime/this.duration,c>1&&(c=1),d=c<.5?4*c*c*c:1-Math.pow(-2*c+2,3)/2,this.object.position.lerpVectors(e,this.targetPos,d),this.object.quaternion.slerpQuaternions(i,this.targetRot,d),this.object.scale.lerpVectors(n,this.targetScale,d),yield;this.coroutine=null}beforeCreateDocument(e){var i;if(this.target&&this.object&&this.gameObject){const n=new st("Move to "+((i=this.target)==null?void 0:i.name),ht.tapTrigger(this.gameObject),he.transformAction(this.object,this.target,this.duration,this.relativeMotion?"relative":"absolute"));e.addBehavior(n)}}}Be([p(h.Object3D)],Dr.prototype,"object",2);Be([p(h.Object3D)],Dr.prototype,"target",2);Be([p()],Dr.prototype,"duration",2);Be([p()],Dr.prototype,"relativeMotion",2);var ia;const Ut=(ia=class extends D{constructor(){super(...arguments);r(this,"materialToSwitch");r(this,"variantMaterial");r(this,"fadeDuration",0);r(this,"_objectsWithThisMaterial",null);r(this,"selfModel");r(this,"targetModels")}start(){var t;this._objectsWithThisMaterial=this.objectsWithThisMaterial,ch(this.gameObject),B()&&this._objectsWithThisMaterial.length<=0&&console.warn('ChangeMaterialOnClick: No objects found with material "'+((t=this.materialToSwitch)==null?void 0:t.name)+'"')}onPointerEnter(t){this.context.input.setCursor("pointer")}onPointerExit(t){this.context.input.unsetCursor("pointer")}onPointerClick(t){if(t.use(),!!this.variantMaterial)for(let e=0;e<this.objectsWithThisMaterial.length;e++){const i=this.objectsWithThisMaterial[e];i.material=this.variantMaterial}}get objectsWithThisMaterial(){return this._objectsWithThisMaterial!=null?this._objectsWithThisMaterial:(this._objectsWithThisMaterial=[],this.variantMaterial&&this.materialToSwitch&&this.context.scene.traverse(t=>{if(t instanceof h.Mesh)if(Array.isArray(t.material)){for(const e of t.material)if(e===this.materialToSwitch){this.objectsWithThisMaterial.push(t);break}}else t.material===this.materialToSwitch?this.objectsWithThisMaterial.push(t):Wv(t.material,this.materialToSwitch)&&this.objectsWithThisMaterial.push(t)}),this._objectsWithThisMaterial)}async beforeCreateDocument(t,e){this.targetModels=[],Ut._materialTriggersPerId={},Ut.variantSwitchIndex=0,this.materialToSwitch&&await re.NEEDLE_progressive.assignTextureLOD(this.materialToSwitch,0),this.variantMaterial&&await re.NEEDLE_progressive.assignTextureLOD(this.variantMaterial,0)}createBehaviours(t,e,i){this.objectsWithThisMaterial.find(o=>o.uuid===e.uuid)&&this.targetModels.push(e),this.gameObject.uuid===e.uuid&&(this.selfModel=e,this.materialToSwitch&&(Ut._materialTriggersPerId[this.materialToSwitch.uuid]||(Ut._materialTriggersPerId[this.materialToSwitch.uuid]=[]),Ut._materialTriggersPerId[this.materialToSwitch.uuid].push(this)))}afterCreateDocument(t,e){if(!this.materialToSwitch)return;const i=Ut._materialTriggersPerId[this.materialToSwitch.uuid];if(i){const n={};for(const o of i){const a=o.createVariants();a&&a.length>0&&(n[o.selfModel.uuid]=a)}for(const o of i){const a=[];for(const l in n)l!==o.selfModel.uuid&&a.push(...n[l]);o.createAndAttachBehaviors(t,n[o.selfModel.uuid],a)}}delete Ut._materialTriggersPerId[this.materialToSwitch.uuid]}createAndAttachBehaviors(t,e,i){const n=[],o=Math.max(0,this.fadeDuration);n.push(he.fadeAction([...this.targetModels,...i],o,!1)),n.push(he.fadeAction(e,o,!0)),t.addBehavior(new st("Select_"+this.selfModel.name,ht.tapTrigger(this.selfModel),he.parallel(...n))),Ut._parallelStartHiddenActions.push(...e),Ut._startHiddenBehaviour||(Ut._startHiddenBehaviour=new st("StartHidden_"+this.selfModel.name,ht.sceneStartTrigger(),he.fadeAction(Ut._parallelStartHiddenActions,o,!1)),t.addBehavior(Ut._startHiddenBehaviour))}static getMaterialName(t){return fn(t.name||"Material")+"_"+t.id}createVariants(){if(!this.variantMaterial)return null;const t=[];for(const e of this.targetModels){const i=e.clone();i.name+="_Variant_"+Ut.variantSwitchIndex+++"_"+Ut.getMaterialName(this.variantMaterial),i.displayName=i.displayName+": Variant with material "+this.variantMaterial.name,i.material=this.variantMaterial,i.geometry=e.geometry,i.transform=e.transform,(!e.parent||!e.parent.isEmpty())&&wt.createEmptyParent(e),e.parent&&e.parent.add(i),t.push(i)}return t}},r(ia,"_materialTriggersPerId",{}),r(ia,"_startHiddenBehaviour",null),r(ia,"_parallelStartHiddenActions",[]),r(ia,"variantSwitchIndex",0),ia);let Ka=Ut;Be([p(h.Material)],Ka.prototype,"materialToSwitch",2);Be([p(h.Material)],Ka.prototype,"variantMaterial",2);Be([p()],Ka.prototype,"fadeDuration",2);var na;const Le=(na=class extends D{constructor(){super(...arguments);r(this,"target");r(this,"toggleOnClick",!1);r(this,"targetState",!0);r(this,"hideSelf",!0);r(this,"selfModel");r(this,"selfModelClone");r(this,"targetModel");r(this,"toggleModel");r(this,"stateBeforeCreatingDocument",!1);r(this,"targetStateBeforeCreatingDocument",!1)}start(){ch(this.gameObject)}onPointerClick(t){t.use(),!this.toggleOnClick&&this.hideSelf&&(this.gameObject.visible=!1),this.target&&(this.target.visible=this.toggleOnClick?!this.target.visible:this.targetState)}createBehaviours(t,e,i){e.uuid===this.gameObject.uuid&&(this.selfModel=e,this.selfModelClone=e.clone())}beforeCreateDocument(){this.target&&(this.gameObject[Le.wasVisible]===void 0&&(this.gameObject[Le.wasVisible]=this.gameObject.activeSelf),this.target[Le.wasVisible]===void 0&&(this.target[Le.wasVisible]=this.target.activeSelf),this.stateBeforeCreatingDocument=this.gameObject[Le.wasVisible],this.targetStateBeforeCreatingDocument=this.target[Le.wasVisible],this.gameObject.visible=!0,this.target.visible=!0)}afterCreateDocument(t,e){if(!this.target)return;this.targetModel=e.document.findById(this.target.uuid);const i=this.selfModel;if(this.selfModel&&this.targetModel){let n=this.selfModel,o=this.targetState;if(this.toggleOnClick)if(o=!this.targetStateBeforeCreatingDocument,!this.selfModelClone.geometry)(!this.selfModel.parent||this.selfModel.parent.isEmpty())&&Bg.createEmptyParent(this.selfModel),this.toggleModel=this.selfModel.deepClone(),this.toggleModel.name+="_toggle",this.selfModel.parent.add(this.toggleModel);else{if(!this.gameObject[Le.toggleClone]){const c=this.selfModelClone.clone();c.setMatrix(new h.Matrix4),c.name+="_toggle"+Le.clonedToggleIndex++,i.add(c),this.gameObject[Le.toggleClone]=c,console.warn("USDZExport: Toggle "+this.gameObject.name+" doesn't have geometry. It will be deep cloned and nested behaviours will likely not work.")}const l=this.gameObject[Le.toggleClone];if(!this.gameObject[Le.reverseToggleClone]){const c=this.selfModelClone.clone();c.setMatrix(new h.Matrix4),c.name+="_toggleReverse"+Le.clonedToggleIndex++,i.add(c),this.gameObject[Le.reverseToggleClone]=c}this.toggleModel=this.gameObject[Le.reverseToggleClone],(!this.toggleModel.geometry||!l.geometry)&&console.error("triggers without childs and without geometry won't work!",this,i.geometry),n=l,i.geometry=null,i.material=null}if(this.toggleModel){if(this.toggleOnClick){const l=[];l.push(he.fadeAction(n,0,!1)),l.push(he.fadeAction(this.toggleModel,0,!0)),l.push(he.fadeAction(this.targetModel,0,o)),t.addBehavior(new st("Toggle_"+n.name+"_ToggleTo"+(o?"On":"Off"),ht.tapTrigger(n),he.parallel(...l)));const c=[];c.push(he.fadeAction(this.toggleModel,0,!1)),c.push(he.fadeAction(n,0,!0)),c.push(he.fadeAction(this.targetModel,0,!o)),t.addBehavior(new st("Toggle_"+n.name+"_ToggleTo"+(o?"Off":"On"),ht.tapTrigger(this.toggleModel),he.parallel(...c)))}}else{const l=[];this.hideSelf&&l.push(he.fadeAction(n,0,!1)),l.push(he.fadeAction(this.targetModel,0,o)),t.addBehavior(new st("Toggle_"+n.name+"_ToggleTo"+(o?"On":"Off"),ht.tapTrigger(n),l.length>1?he.parallel(...l):l[0]))}const a=new Array;this.targetStateBeforeCreatingDocument||a.push(this.targetModel),this.stateBeforeCreatingDocument||a.push(i),this.toggleModel&&a.push(this.toggleModel),Js.add(a,t)}}afterSerialize(t,e){this.gameObject[Le.wasVisible]!==void 0&&(this.gameObject.visible=this.gameObject[Le.wasVisible],delete this.gameObject[Le.wasVisible]),this.target&&this.target[Le.wasVisible]!==void 0&&(this.target.visible=this.target[Le.wasVisible],delete this.target[Le.wasVisible]),delete this.gameObject[Le.toggleClone],delete this.gameObject[Le.reverseToggleClone]}},r(na,"clonedToggleIndex",0),r(na,"wasVisible",Symbol("usdz_SetActiveOnClick_wasVisible")),r(na,"toggleClone",Symbol("clone for toggling")),r(na,"reverseToggleClone",Symbol("clone for reverse toggling")),na);let Lr=Le;Be([p(h.Object3D)],Lr.prototype,"target",2);Be([p()],Lr.prototype,"toggleOnClick",2);Be([p()],Lr.prototype,"targetState",2);Be([p()],Lr.prototype,"hideSelf",2);const hs=class extends D{constructor(){super(...arguments);r(this,"wasVisible",!1)}static add(e,i){const n=Array.isArray(e)?e:[e];for(const o of n)hs._fadeObjects.includes(o)||(console.log("adding hide on start",o),hs._fadeObjects.push(o));hs._fadeBehaviour===void 0&&(hs._fadeBehaviour=new st("HideOnStart",ht.sceneStartTrigger(),he.fadeAction(hs._fadeObjects,0,!1)),i.addBehavior(hs._fadeBehaviour))}start(){C.setActive(this.gameObject,!1)}createBehaviours(e,i,n){i.uuid===this.gameObject.uuid&&(this.wasVisible||hs.add(i,e))}beforeCreateDocument(){this.wasVisible=C.isActiveSelf(this.gameObject)}};let Js=hs;r(Js,"_fadeBehaviour"),r(Js,"_fadeObjects",[]);class Za extends D{constructor(){super(...arguments);r(this,"target");r(this,"duration",.5);r(this,"motionType","bounce")}beforeCreateDocument(){}createBehaviours(e,i,n){if(this.target&&i.uuid===this.gameObject.uuid){const o=new st("emphasize "+this.name,ht.tapTrigger(this.gameObject),he.emphasize(this.target,this.duration,this.motionType,void 0,"basic"));e.addBehavior(o)}}afterCreateDocument(e,i){}}Be([p()],Za.prototype,"target",2);Be([p()],Za.prototype,"duration",2);Be([p()],Za.prototype,"motionType",2);class ho extends D{constructor(){super(...arguments);r(this,"target");r(this,"clip","");r(this,"toggleOnClick",!1);r(this,"trigger","tap")}start(){ch(this.gameObject)}ensureAudioSource(){if(!this.target){const e=this.gameObject.addComponent(je);e&&(this.target=e,e.spatialBlend=1,e.volume=1,e.loop=!1,e.preload=!0)}}onPointerClick(e){var i;e.use(),!(!((i=this.target)!=null&&i.clip)&&!this.clip)&&(this.ensureAudioSource(),this.target&&(this.target.isPlaying&&this.toggleOnClick?this.target.stop():(!this.toggleOnClick&&this.target.isPlaying&&this.target.stop(),this.clip?this.target.play(this.clip):this.target.play())))}createBehaviours(e,i,n){if(!(!this.target&&!this.clip)&&i.uuid===this.gameObject.uuid){const o=this.clip?this.clip:this.target?this.target.clip:void 0;if(!o||typeof o!="string")return;const a=this.target?this.target.gameObject:this.gameObject;Co.getName(o);const l=this.target?this.target.volume:1,c=this.target&&this.target.spatialBlend==0?"nonSpatial":"spatial";let d=!1;this.gameObject.traverse(g=>{g instanceof h.Mesh&&g.visible&&(d=!0)}),d=!0;const u=e.addAudioClip(o);let f=he.playAudioAction(a,u,"play",l,c);this.target&&this.target.loop&&(f=he.sequence(f).makeLooping());const m=this.name?"_"+this.name:"";if(d&&this.trigger==="tap"){this.toggleOnClick&&(f.multiplePerformOperation="stop");const g=new st("playAudio"+m,ht.tapTrigger(i),f);e.addBehavior(g)}if(this.target&&this.target.playOnAwake&&this.target.enabled)if(d&&this.trigger==="tap")console.warn("USDZExport: Audio sources that are played on tap can't also auto-play at scene start due to a QuickLook bug.");else{const g=new st("playAudioOnStart"+m,ht.sceneStartTrigger(),f);e.addBehavior(g)}}}}Be([p(je)],ho.prototype,"target",2);Be([p(URL)],ho.prototype,"clip",2);Be([p()],ho.prototype,"toggleOnClick",2);var ud;const Sn=(ud=class extends D{constructor(){super(...arguments);r(this,"animator");r(this,"stateName");r(this,"trigger","tap");r(this,"animation");r(this,"selfModel");r(this,"stateAnimationModel");r(this,"animationSequence",new Array);r(this,"animationLoopAfterSequence",new Array);r(this,"randomOffsetNormalized",0)}get target(){var t,e;return((t=this.animator)==null?void 0:t.gameObject)||((e=this.animation)==null?void 0:e.gameObject)}start(){ch(this.gameObject)}onPointerClick(t){var e;t.use(),this.target&&this.stateName&&((e=this.animator)==null||e.play(this.stateName,0,0,.1))}createBehaviours(t,e,i){e.uuid===this.gameObject.uuid&&(this.selfModel=e)}afterSerialize(){if(Sn.rootsWithExclusivePlayback.size>1){const t='Multiple root objects targeted by more than one animation. To work around QuickLook bug FB13410767, animations will be set as "exclusive" and activating them will stop other animations being marked as exclusive.';B()&&me(t),console.warn(t,...Sn.rootsWithExclusivePlayback)}Sn.animationActions=[],Sn.rootsWithExclusivePlayback=new Set}afterCreateDocument(t,e){if(this.animationSequence===void 0&&this.animationLoopAfterSequence===void 0||!this.stateAnimationModel||!this.target)return;const i=e.document,n=e.extensions.find(l=>l instanceof lh);if(!n)return;const o=n.getClipCount(this.target)>1;o&&(B()&&console.warn("Setting exclusive playback for "+this.target.name+"@"+this.stateName+" because it has "+n.getClipCount(this.target)+" animations. This works around QuickLook bug FB13410767."),Sn.rootsWithExclusivePlayback.add(this.target));const a=this.name?this.name:"";i.traverse(l=>{var c,d;if(l.uuid===((c=this.target)==null?void 0:c.uuid)){const u=Sn.getActionForSequences(i,l,this.animationSequence,this.animationLoopAfterSequence,this.randomOffsetNormalized),f=new st(this.trigger+"_"+a+"_toPlayAnimation_"+this.stateName+"_on_"+((d=this.target)==null?void 0:d.name),this.trigger=="tap"?ht.tapTrigger(this.selfModel):ht.sceneStartTrigger(),u);o&&f.makeExclusive(!0),t.addBehavior(f)}})}static getActionForSequences(t,e,i,n,o){const a=(c,d)=>{let u=Sn.animationActions.find(f=>f.affectedObjects==c&&f.start==d.start&&f.duration==d.duration&&f.animationSpeed==d.speed);return u||(u=he.startAnimationAction(c,d),Sn.animationActions.push(u)),u},l=he.sequence();if(i&&i.length>0)for(const c of i)l.addAction(a(e,c));if(n&&n.length>0){const c=l.actions.length==0?l:he.sequence();for(const d of n)c.addAction(a(e,d));c.makeLooping(),l!==c&&l.addAction(c)}return o&&o>0&&l.actions.unshift(he.waitAction(o)),l}static getAndRegisterAnimationSequences(t,e,i){var _,y,b,v,x,O,k,M;if(!e)return;const n=e.getComponent(St),o=e.getComponent(Et);if(!n&&!o)return;if(n&&!i)throw new Error("PlayAnimationOnClick: No stateName specified for animator "+n.name+" on "+e.name);let a=[],l=[];if(o){const R=t.registerAnimation(e,o.clip);R&&(o.loop?l.push(R):a.push(R));let A=0;if(o.minMaxOffsetNormalized){const I=o.minMaxOffsetNormalized.x,E=o.minMaxOffsetNormalized.y;A=(((_=o.clip)==null?void 0:_.duration)||1)*(I+Math.random()*(E-I))}return{animationSequence:a,animationLoopAfterSequence:l,randomTimeOffset:A}}const c=n==null?void 0:n.runtimeAnimatorController;let d=c==null?void 0:c.findState(i),u=[],f=[];if(c&&d){const R=new Array;R.push(d);let A=!1;for(;R.length<100;){if(!d||d===null||!d.transitions||d.transitions.length===0){(y=d.motion)!=null&&y.isLooping&&(A=!0);break}const I=d.transitions.find(j=>j.conditions.length===0),E=I?c.getState(I.destinationState,0):null;if(E&&R.includes(E)){d=E,A=!0;break}else if(I){if(d=E,!d)break;R.push(d)}else{A=((b=d.motion)==null?void 0:b.isLooping)??!1;break}}if(A&&d){const I=R.indexOf(d);u=R.slice(0,I),f=R.slice(I),ib&&console.log("found loop from "+i,"states until loop",u,"states looping",f)}else u=R,f=[],ib&&console.log("found no loop from "+i,"states",u);if(!f.length){const I=u[u.length-1],E=(v=I.motion)==null?void 0:v.clip;if(E){let j;if(t.holdClipMap.has(E))j=t.holdClipMap.get(E);else{const F=I.name+"_hold";j=E.clone(),j.duration=1,j.name=F;const G=E.duration;j.tracks=E.tracks.map(T=>{const L=T.clone();L.times=new Float32Array([0,G]);const $=T.values.length,X=T.getValueSize(),J=T.values.slice($-X,$);return L.values=new Float32Array(2*X),L.values.set(J,0),L.values.set(J,X),L}),j.name=F,t.holdClipMap.set(E,j)}if(j){const F={name:j.name,motion:{clip:j,isLooping:!1,name:j.name},speed:1,transitions:[],behaviours:[],hash:I.hash+1};f.push(F)}}}}if(u.length===1&&(!((x=u[0].motion)!=null&&x.clip)||((k=(O=u[0].motion)==null?void 0:O.clip.tracks)==null?void 0:k.length)===0)){a=new Array;const R=t.registerAnimation(e,null);R&&a.push(R);return}if(u=u.filter(R=>{var A,I,E;return((A=R.motion)==null?void 0:A.clip)&&((E=(I=R.motion)==null?void 0:I.clip.tracks)==null?void 0:E.length)>0}),f=f.filter(R=>{var A,I,E;return((A=R.motion)==null?void 0:A.clip)&&((E=(I=R.motion)==null?void 0:I.clip.tracks)==null?void 0:E.length)>0}),u.length===0&&f.length===0){console.warn("No clips found for state "+i+" on "+(n==null?void 0:n.name)+", can't export animation data");return}const m=(R,A)=>{if(!e)return;const I=t.registerAnimation(e,R.motion.clip??null);I?(I.speed=R.speed,A.push(I)):console.warn("Couldn't register animation for state "+R.name+" on "+(n==null?void 0:n.name))};if(u.length>0){a=new Array;for(const R of u)m(R,a)}if(f.length>0){l=new Array;for(const R of f)m(R,l)}let g=0;if(n&&c&&n.minMaxOffsetNormalized){const R=n.minMaxOffsetNormalized.x,A=n.minMaxOffsetNormalized.y,I=u.length?u[0]:f.length?f[0]:null;g=(((M=I==null?void 0:I.motion.clip)==null?void 0:M.duration)||1)*(R+Math.random()*(A-R))}return{animationSequence:a,animationLoopAfterSequence:l,randomTimeOffset:g}}createAnimation(t,e,i){if(!this.target||!this.animator&&!this.animation)return;const n=Sn.getAndRegisterAnimationSequences(t,this.target,this.stateName);n&&(this.animationSequence=n.animationSequence,this.animationLoopAfterSequence=n.animationLoopAfterSequence,this.randomOffsetNormalized=n.randomTimeOffset,this.stateAnimationModel=e)}},r(ud,"animationActions",[]),r(ud,"rootsWithExclusivePlayback",new Set),ud);let wr=Sn;Be([p(St)],wr.prototype,"animator",2);Be([p()],wr.prototype,"stateName",2);class Ja extends D{constructor(){super(...arguments);r(this,"target")}getType(){}getDuration(){}}Be([p(h.Object3D)],Ja.prototype,"target",2);class hh extends D{constructor(){super(...arguments);r(this,"target")}}Be([p(Ja)],hh.prototype,"target",2);class dh extends Ja{constructor(){super(...arguments);r(this,"type",1);r(this,"duration",1)}getType(){switch(this.type){case 1:return"hide";case 0:return"show"}}getDuration(){return this.duration}}Be([p()],dh.prototype,"type",2);Be([p()],dh.prototype,"duration",2);class Ng extends hh{}class Xu{get extensionName(){return"Physics"}onExportObject(t,e,i){const n=C.getComponents(t,ue).filter(c=>c.enabled),o=C.getComponents(t,ai).filter(c=>c.enabled&&!c.isTrigger);let a=n.length>0?n[0]:null;const l=o.length>0?o[0]:null;l&&!a&&(a=new ue,a.isKinematic=!0),a&&e.addEventListener("serialize",(c,d)=>{var u,f,m;if(a){if(c.appendLine(),c.beginBlock('def RealityKitComponent "RigidBody"',"{",!0),a.useGravity||c.appendLine("bool gravityEnabled = 0"),c.appendLine('uniform token info:id = "RealityKit.RigidBody"'),a.isKinematic&&c.appendLine('token motionType = "Kinematic"'),c.beginBlock('def RealityKitStruct "massFrame"',"{",!0),c.appendLine(`float m_mass = ${a.mass}`),c.beginBlock('def RealityKitStruct "m_pose"',"{",!0),c.appendLine(`float3 position = (${a.centerOfMass.x}, ${a.centerOfMass.y}, ${a.centerOfMass.z})`),c.closeBlock("}"),c.closeBlock("}"),o.length>0){const g=o[0];c.beginBlock('def RealityKitStruct "material"',"{",!0);const _=g.sharedMaterial;_&&_.dynamicFriction!==void 0&&c.appendLine(`double dynamicFriction = ${(u=g.sharedMaterial)==null?void 0:u.dynamicFriction}`),_&&_.bounciness!==void 0&&c.appendLine(`double restitution = ${(f=g.sharedMaterial)==null?void 0:f.bounciness}`),_&&_.staticFriction!==void 0&&c.appendLine(`double staticFriction = ${(m=g.sharedMaterial)==null?void 0:m.staticFriction}`),c.closeBlock("}")}c.closeBlock("}")}}),l&&(e.addEventListener("serialize",(c,d)=>{var m;c.beginBlock('def RealityKitComponent "Collider"',"{",!0),c.appendLine("uint group = 1"),c.appendLine('uniform token info:id = "RealityKit.Collider"'),c.appendLine("uint mask = 4294967295");const f=l.isTrigger?"Trigger":"Default";if(c.appendLine(`token type = "${f}"`),c.beginBlock('def RealityKitStruct "Shape"',"{",!0),l instanceof Ga){const g=l;c.appendLine('token shapeType = "Sphere"'),c.appendLine(`float radius = ${g.radius}`)}else if(l instanceof qa){const g=l;c.appendLine('token shapeType = "Box"'),c.appendLine(`float3 extent = (${g.size.x}, ${g.size.y}, ${g.size.z})`)}else if(l instanceof Ss){const g=l;c.appendLine('token shapeType = "Capsule"'),c.appendLine(`float radius = ${g.radius}`),c.appendLine(`float height = ${g.height}`)}else if(l instanceof So&&((m=l.sharedMesh)!=null&&m.geometry)){const g=l.sharedMesh.geometry;g.boundingBox||g.computeBoundingBox();const _=l.sharedMesh.geometry.boundingBox;_&&(c.appendLine('token shapeType = "Box"'),c.appendLine(`float3 extent = (${_.max.x-_.min.x}, ${_.max.y-_.min.y}, ${_.max.z-_.min.z})`),console.log("[USDZ] Only Box, Sphere, and Capsule colliders are supported in visionOS/iOS. MeshCollider will be exported as Box",l))}else console.warn("[USDZ] Only Box, Sphere, and Capsule colliders are supported in visionOS/iOS. Ignoring collider:",l);c.beginBlock('def RealityKitStruct "pose"',"{",!0),c.closeBlock("}"),c.closeBlock("}"),c.closeBlock("}")}),o.length>1&&console.log("WARNING: Multiple colliders detected. visionOS / iOS can only support objects with a single collider, only exporting the first collider: ",l))}}class Vg{get extensionName(){return"DocumentExtension"}onAfterBuildDocument(t){}}var _M=Object.defineProperty,yM=Object.getOwnPropertyDescriptor,uh=(s,t,e,i)=>{for(var n=i>1?void 0:i?yM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&_M(t,e,n),n};const ip=S("debugui"),np=S("debuguilayout");class $g{constructor(){r(this,"width");r(this,"height")}}class Wg{constructor(){r(this,"x");r(this,"y");r(this,"width");r(this,"height")}}const en=new h.Vector3,Sl=new h.Matrix4,id=new h.Quaternion,_w=class extends Hi{constructor(){super(...arguments);r(this,"_anchoredPosition");r(this,"sizeDelta",new h.Vector2(100,100));r(this,"pivot",new h.Vector2(.5,.5));r(this,"anchorMin",new h.Vector2(0,0));r(this,"anchorMax",new h.Vector2(1,1));r(this,"minWidth");r(this,"minHeight");r(this,"lastMatrix");r(this,"rectBlock");r(this,"_transformNeedsUpdate",!1);r(this,"_initialPosition");r(this,"_parentRectTransform");r(this,"_lastUpdateFrame",-1);r(this,"_lastAnchoring");r(this,"_createdBlocks",[]);r(this,"_createdTextBlocks",[])}get parent(){return this._parentRectTransform}get translation(){return this.gameObject.position}get rotation(){return this.gameObject.quaternion}get scale(){return this.gameObject.scale}get anchoredPosition(){return this._anchoredPosition||(this._anchoredPosition=new h.Vector2),this._anchoredPosition}set anchoredPosition(t){this._anchoredPosition=t}get width(){let t=this.sizeDelta.x;if(this.anchorMin.x!==this.anchorMax.x&&this._parentRectTransform){const e=this._parentRectTransform.width,i=this.anchorMax.x-this.anchorMin.x;t=e*i,t+=this.sizeDelta.x}return this.minWidth!==void 0&&t<this.minWidth?this.minWidth:t}get height(){let t=this.sizeDelta.y;if(this.anchorMin.y!==this.anchorMax.y&&this._parentRectTransform){const e=this._parentRectTransform.height,i=this.anchorMax.y-this.anchorMin.y;t=e*i,t+=this.sizeDelta.y}return this.minHeight!==void 0&&t<this.minHeight?this.minHeight:t}awake(){super.awake(),this._anchoredPosition||(this._anchoredPosition=new h.Vector2),this.lastMatrix=new h.Matrix4,this.rectBlock=new h.Object3D,this.rectBlock.name=this.name,this._initialPosition=this.gameObject.position.clone(),this._initialPosition.z=0,la(this,"_anchoredPosition",()=>{this.markDirty()}),la(this,"sizeDelta",()=>{this.markDirty()}),la(this,"pivot",()=>{this.markDirty()}),la(this,"anchorMin",()=>{this.markDirty()}),la(this,"anchorMax",()=>{this.markDirty()})}onEnable(){var t;super.onEnable(),this.rectBlock||(this.rectBlock=new h.Object3D),this.lastMatrix||(this.lastMatrix=new h.Matrix4),this._lastAnchoring||(this._lastAnchoring=new h.Vector2),this._initialPosition||(this._initialPosition=new h.Vector3),this._anchoredPosition||(this._anchoredPosition=new h.Vector2),this.addShadowComponent(this.rectBlock),this._transformNeedsUpdate=!0,(t=this.canvas)==null||t.registerTransform(this)}onDisable(){var t;super.onDisable(),this.removeShadowComponent(),(t=this.canvas)==null||t.unregisterTransform(this)}onParentRectTransformChanged(t){this._transformNeedsUpdate||this.onApplyTransform(np?`${t.name} changed`:void 0)}get isDirty(){return this._transformNeedsUpdate||(this._transformNeedsUpdate=!this.lastMatrix.equals(this.gameObject.matrix)),this._transformNeedsUpdate}markDirty(){this._transformNeedsUpdate||(np&&console.warn("RectTransform markDirty()",this.name),this._transformNeedsUpdate=!0,this._lastUpdateFrame=-1)}updateTransform(){(this._transformNeedsUpdate||!this.lastMatrix.equals(this.gameObject.matrix))&&this.canUpdate()&&this.onApplyTransform(this._transformNeedsUpdate?"Marked dirty":"Matrix changed")}canUpdate(){return this._transformNeedsUpdate&&this.activeAndEnabled&&this._lastUpdateFrame!==this.context.time.frame}onApplyTransform(t){var n;if(this.context.time.frameCount===this._lastUpdateFrame)return;this._lastUpdateFrame=this.context.time.frameCount;const e=this.shadowComponent;if(!e)return;this.gameObject.parent?this._parentRectTransform=C.getComponentInParent(this.gameObject.parent,_w):this._parentRectTransform=void 0,this._transformNeedsUpdate=!1,np&&console.warn("RectTransform → ApplyTransform",this.name+" because "+t),this.isRoot()?this.Root.screenspace||(e.rotation.y=Math.PI):(e.matrix.identity(),e.matrixAutoUpdate=!1,en.set(0,0,0),this.applyPivot(en),e.matrix.setPosition(en.x,en.y,0),(this.gameObject.quaternion.x||this.gameObject.quaternion.y||this.gameObject.quaternion.z)&&(id.copy(this.gameObject.quaternion),id.x*=-1,id.z*=-1,Sl.makeRotationFromQuaternion(id),e.matrix.premultiply(Sl)),en.set(0,0,0),this.applyAnchoring(en),(n=this.canvas)!=null&&n.screenspace?en.z+=.1:en.z+=.01,Sl.identity(),Sl.setPosition(en.x,en.y,en.z),e.matrix.premultiply(Sl),e.matrix.scale(this.gameObject.scale)),this.lastMatrix.copy(this.gameObject.matrix);const i=!0;for(const o of Au(this.gameObject,Hi,i,1)){if(o===this||!o.activeAndEnabled)continue;const a=o;a.onParentRectTransformChanged&&a.onParentRectTransformChanged(this)}}applyAnchoring(t){this._lastAnchoring||(this._lastAnchoring=new h.Vector2);const e=this._lastAnchoring.sub(this._anchoredPosition);this.gameObject.position.x+=e.x,this.gameObject.position.y+=e.y,this._lastAnchoring.copy(this._anchoredPosition),t.x+=this._initialPosition.x-this.gameObject.position.x,t.y+=this._initialPosition.y-this.gameObject.position.y,t.z+=this._initialPosition.z-this.gameObject.position.z;const i=this._parentRectTransform;if(i){let n=0;const o=1-this.anchorMax.y-this.anchorMin.y;n-=i.height*.5*o,t.y+=n;let a=0;const l=1-this.anchorMax.x-this.anchorMin.x;a-=i.width*.5*l,t.x+=a}}applyPivot(t){if(this.pivot&&!this.isRoot()){const e=this.pivot.x-.5;t.x-=e*this.sizeDelta.x*this.gameObject.scale.x;const i=this.pivot.y-.5;t.y-=i*this.sizeDelta.y*this.gameObject.scale.y}}getBasicOptions(){const t={width:this.sizeDelta.x,height:this.sizeDelta.y,offset:0,backgroundOpacity:0,borderWidth:0,borderRadius:0,borderOpacity:0,letterSpacing:-.03};return this.ensureValidSize(t),t}ensureValidSize(t,e=1e-4){return t.width<=0&&(t.width=e),t.height<=0&&(t.height=1e-4),t}createNewBlock(t){t={...this.getBasicOptions(),...t},ip&&console.log(this.name,t);const e=new ie.__webpack_exports__Block(t);return this._createdBlocks.push(e),e}createNewText(t){ip&&console.log(t),t={...this.getBasicOptions(),...t},ip&&console.log(this.name,t);const e=new ie.__webpack_exports__Text(t);return this._createdTextBlocks.push(e),e}};let At=_w;uh([p(h.Vector2)],At.prototype,"anchoredPosition",1);uh([p(h.Vector2)],At.prototype,"sizeDelta",2);uh([p(h.Vector2)],At.prototype,"pivot",2);uh([p(h.Vector2)],At.prototype,"anchorMin",2);uh([p(h.Vector2)],At.prototype,"anchorMax",2);var bM=Object.defineProperty,vM=Object.getOwnPropertyDescriptor,yw=(s,t,e,i)=>{for(var n=i>1?void 0:i?vM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&bM(t,e,n),n};class el extends D{constructor(){super(...arguments);r(this,"effectColor");r(this,"effectDistance")}}yw([p(ge)],el.prototype,"effectColor",2);yw([p(h.Vector2)],el.prototype,"effectDistance",2);var wM=Object.defineProperty,xM=Object.getOwnPropertyDescriptor,bw=(s,t,e,i)=>{for(var n=i>1?void 0:i?xM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&wM(t,e,n),n};const nd={backgroundColor:new h.Color(1,1,1),backgroundOpacity:1,borderColor:new h.Color(1,1,1),borderOpacity:1};var kp;const Hl=(kp=class extends Hi{constructor(){super(...arguments);r(this,"_alphaFactor",1);r(this,"sRGBColor",new h.Color(1,0,1));r(this,"raycastTarget",!0);r(this,"uiObject",null);r(this,"_color",null);r(this,"_rect",null);r(this,"_stateManager",null);r(this,"_currentlyCreatingPanel",!1)}get isGraphic(){return!0}get color(){return this._color||(this._color=new ge(1,1,1,1)),this._color}set color(t){(!this._color||this._color.r!==t.r||this._color.g!==t.g||this._color.b!==t.b||this._color.alpha!==t.alpha)&&(this._color||(this._color=new ge(1,1,1,1)),this._color.copy(t),this.onColorChanged())}setAlphaFactor(t){this._alphaFactor=t,this.onColorChanged()}get alphaFactor(){return this._alphaFactor}onColorChanged(){this.uiObject&&(this.sRGBColor.copy(this._color),this.sRGBColor.convertLinearToSRGB(),nd.backgroundColor=this.sRGBColor,nd.backgroundOpacity=this._color.alpha*this._alphaFactor,this.applyEffects(nd,this._alphaFactor),this.uiObject.set(nd),this.markDirty())}get m_Color(){return this._color}get rectTransform(){if(this._rect||(this._rect=C.getComponent(this.gameObject,At)),!this._rect)throw new Error("Not Supported: Make sure to add a RectTransform component before adding a UI Graphic component.");return this._rect}onParentRectTransformChanged(){var t;(t=this.uiObject)==null||t.set({width:this.rectTransform.width,height:this.rectTransform.height}),this.markDirty()}__internalNewInstanceCreated(t){return super.__internalNewInstanceCreated(t),this._rect=null,this.uiObject=null,this._color&&(this._color=this._color.clone()),this}setState(t){this.makePanel(),this.uiObject&&(this.uiObject.setState(t),this==null||this.markDirty())}setupState(t){this.makePanel(),this.uiObject&&(this._stateManager||(this._stateManager=new ie.SimpleStateBehavior(this.uiObject)),this.uiObject.setupState(t.state,t.attributes))}setOptions(t){this.makePanel(),this.uiObject&&this.uiObject.set(t)}awake(){super.awake(),this.makePanel(),la(this,"_color",()=>vP(this,this.onColorChanged))}onEnable(){var t;super.onEnable(),this.uiObject&&((t=this.rectTransform.shadowComponent)==null||t.add(this.uiObject),this.addShadowComponent(this.uiObject,this.rectTransform))}onDisable(){super.onDisable(),this.uiObject&&this.removeShadowComponent()}makePanel(){if(this.uiObject||this._currentlyCreatingPanel)return;this._currentlyCreatingPanel=!0;const t=.015,e={backgroundColor:this.color,backgroundOpacity:this.color.alpha,offset:t};this.onBeforeCreate(e),this.applyEffects(e),this.onCreate(e),this.controlsChildLayout=!1,this._currentlyCreatingPanel=!1,this.onAfterCreated(),this.onColorChanged()}onBeforeCreate(t){}onCreate(t){this.uiObject=this.rectTransform.createNewBlock(t),this.uiObject.name=this.name}onAfterCreated(){}applyEffects(t,e=1){var n;const i=(n=this.gameObject)==null?void 0:n.getComponent(el);i&&(i.effectDistance&&(t.borderWidth=Math.max(Math.abs(i.effectDistance.x),Math.abs(i.effectDistance.y))),i.effectColor&&(t.borderColor=i.effectColor,t.borderOpacity=i.effectColor.alpha*e))}async setTexture(t){if(this.setOptions({backgroundOpacity:0}),t){if(Hl.textureCache.has(t))t=Hl.textureCache.get(t);else if(!t.isRenderTargetTexture){const e=t.clone();e.colorSpace=h.LinearSRGBColorSpace,Hl.textureCache.set(t,e),t=e}this.setOptions({backgroundImage:t,borderRadius:0,backgroundOpacity:this.color.alpha,backgroundSize:"stretch"}),re.NEEDLE_progressive.assignTextureLOD(t,0).then(e=>{e instanceof h.Texture&&(t&&Hl.textureCache.set(t,e),this.setOptions({backgroundImage:e}),this.markDirty())})}else this.setOptions({backgroundImage:void 0,borderRadius:0,backgroundOpacity:this.color.alpha});this.markDirty()}onAfterAddedToScene(){super.onAfterAddedToScene(),this.shadowComponent&&(this.shadowComponent.offset=this.shadowComponent.position.z)}},r(kp,"textureCache",new Map),kp);let Ir=Hl;bw([p(ge)],Ir.prototype,"color",1);bw([p()],Ir.prototype,"raycastTarget",2);class fh extends Ir{constructor(){super(...arguments);r(this,"_flippedObject",!1)}onAfterCreated(){this.uiObject&&!this._flippedObject&&(this._flippedObject=!0,this.uiObject.scale.y*=-1)}}var SM=Object.defineProperty,CM=Object.getOwnPropertyDescriptor,Ts=(s,t,e,i)=>{for(var n=i>1?void 0:i?CM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&SM(t,e,n),n};const No=S("debugtext");var et=(s=>(s[s.UpperLeft=0]="UpperLeft",s[s.UpperCenter=1]="UpperCenter",s[s.UpperRight=2]="UpperRight",s[s.MiddleLeft=3]="MiddleLeft",s[s.MiddleCenter=4]="MiddleCenter",s[s.MiddleRight=5]="MiddleRight",s[s.LowerLeft=6]="LowerLeft",s[s.LowerCenter=7]="LowerCenter",s[s.LowerRight=8]="LowerRight",s))(et||{}),vw=(s=>(s[s.Normal=0]="Normal",s[s.Bold=1]="Bold",s[s.Italic=2]="Italic",s[s.BoldAndItalic=3]="BoldAndItalic",s))(vw||{});class Dt extends Ir{constructor(){super(...arguments);r(this,"alignment",0);r(this,"verticalOverflow",0);r(this,"horizontalOverflow",0);r(this,"lineSpacing",1);r(this,"supportRichText",!1);r(this,"font");r(this,"fontStyle",0);r(this,"sRGBTextColor",new h.Color(1,0,1));r(this,"_text","");r(this,"_fontSize",12);r(this,"_textMeshUi",null);r(this,"_didHandleTextRenderOnTop",!1)}setAlphaFactor(e){var i;super.setAlphaFactor(e),(i=this.uiObject)==null||i.set({fontOpacity:this.color.alpha*this.alphaFactor}),this.markDirty()}get text(){return this._text}set text(e){e!==this._text&&(this._text=e,this.feedText(this.text,this.supportRichText),this.markDirty())}set_text(e){this.text=e}get fontSize(){return this._fontSize}set fontSize(e){var i;this._fontSize=e,(i=this.uiObject)==null||i.set({fontSize:e})}onColorChanged(){var e;this.sRGBTextColor.copy(this.color),this.sRGBTextColor.convertLinearToSRGB(),(e=this.uiObject)==null||e.set({color:this.sRGBTextColor,fontOpacity:this.color.alpha})}onParentRectTransformChanged(){super.onParentRectTransformChanged(),this.uiObject&&this.updateOverflow()}onBeforeCanvasRender(e){this.updateOverflow()}updateOverflow(){var i;const e=(i=this.uiObject)==null?void 0:i._overflow;e&&(e._needsUpdate=!0)}onCreate(e){No&&console.log(this),this.horizontalOverflow==1&&(e.whiteSpace="pre"),this.verticalOverflow==0&&(this.context.renderer.localClippingEnabled=!0,e.overflow="hidden"),this.horizontalOverflow==1&&this.verticalOverflow==0,e.lineHeight=this.lineSpacing,delete e.backgroundOpacity,delete e.backgroundColor,No&&(e.backgroundColor=16750848,e.backgroundOpacity=.5);const i=this.rectTransform;e={...e,...this.getTextOpts()},this.getAlignment(e),No&&(e.backgroundColor=Math.random()*16777215,e.backgroundOpacity=.1),this.uiObject=i.createNewText(e),this.feedText(this.text,this.supportRichText)}onAfterAddedToScene(){super.onAfterAddedToScene(),this.handleTextRenderOnTop()}getTextOpts(){const e=this.fontSize,i={color:this.color,fontOpacity:this.color.alpha,fontSize:e,fontKerning:"normal"};return this.setFont(i,this.fontStyle),i}onEnable(){var e;super.onEnable(),this._didHandleTextRenderOnTop=!1,this.uiObject&&this.uiObject.addAfterUpdate(()=>{this.setShadowComponentOwner(this.uiObject),this.markDirty()}),setTimeout(()=>this.markDirty(),10),(e=this.canvas)==null||e.registerEventReceiver(this)}onDisable(){var e;super.onDisable(),(e=this.canvas)==null||e.unregisterEventReceiver(this)}getAlignment(e){switch(e.flexDirection="column",this.alignment){case 0:case 3:case 6:e.textAlign="left";break;case 1:case 4:case 7:e.textAlign="center";break;case 2:case 5:case 8:e.textAlign="right";break}switch(this.alignment){default:case 0:case 1:case 2:e.alignItems="start";break;case 3:case 4:case 5:e.alignItems="center";break;case 6:case 7:case 8:e.alignItems="end";break}return e}feedText(e,i){var n,o,a;if(No&&console.log("feedText",this.uiObject,e,i),!!this.uiObject)if(this._textMeshUi||(this._textMeshUi=[]),this.uiObject.children.length=0,!i||e.length===0)this.uiObject.textContent=e;else{let l=this.getNextTag(e);if(l){if(l.startIndex>0){for(let u=this.uiObject.children.length-1;u>=0;u--){const f=this.uiObject.children[u];f.isUI&&(this.uiObject.remove(f),f.clear())}const d=new ie.__webpack_exports__Inline({textContent:e.substring(0,l.startIndex),color:"inherit"});this.uiObject.add(d)}}else{this.uiObject.textContent="",this.setOptions({textContent:e});return}const c=[];for(;l;){const d=this.getNextTag(e,l.endIndex),u={fontFamily:(n=this.uiObject)==null?void 0:n.get("fontFamily"),color:"inherit",textContent:""};if(d){u.textContent=this.getText(e,l,d),this.handleTag(l,u,c);const f=new ie.__webpack_exports__Inline(u);(o=this.uiObject)==null||o.add(f)}else{u.textContent=e.substring(l.endIndex),this.handleTag(l,u,c);const f=new ie.__webpack_exports__Inline(u);(a=this.uiObject)==null||a.add(f)}l=d}}}handleTextRenderOnTop(){this._didHandleTextRenderOnTop||(this._didHandleTextRenderOnTop=!0,this.startCoroutine(this.renderOnTopCoroutine()))}*renderOnTopCoroutine(){if(!this.canvas)return;const e=[],i=this.canvas,n={renderOnTop:i.renderOnTop,depthWrite:i.depthWrite,doubleSided:i.doubleSided};for(;;){let o=!1;if(this._textMeshUi)for(let a=0;a<this._textMeshUi.length;a++){if(e[a]===!0)continue;o=!0;const l=this._textMeshUi[a];l.textContent&&(tu(l,n),e[a]=!0)}if(!o)break;yield}}handleTag(e,i,n){if(!e.isEndTag){if(e.type.includes("color")){const o=new sp(e,{color:i.color});if(n.push(o),e.type.length>6){const a=parseInt("0x"+e.type.substring(7));i.color=a}else i.color=new h.Color(1,1,1)}else if(e.type=="b"){this.setFont(i,1);const o=new sp(e,{fontWeight:700});n.push(o)}else if(e.type=="i"){this.setFont(i,2);const o=new sp(e,{fontStyle:"italic"});n.push(o)}}}getText(e,i,n){return e.substring(i.endIndex,n.startIndex)}getNextTag(e,i=0){const n=e.indexOf("<",i),o=e.indexOf(">",n);if(n>=0&&o>=0){const a=e.substring(n+1,o);return{type:a,startIndex:n,endIndex:o+1,isEndTag:a.startsWith("/")}}return null}setFont(e,i){if(!this.font)return;const n=this.font,o=this.getFamilyNameWithCorrectSuffix(n,i);No&&console.log("Selected font family:"+o);let a=ie.__webpack_exports__FontLibrary.getFontFamily(o);switch(a||(a=ie.__webpack_exports__FontLibrary.addFontFamily(o)),e.fontFamily=a,i){default:case 0:e.fontWeight=400,e.fontStyle="normal";break;case 1:e.fontWeight=700,e.fontStyle="normal";break;case 2:e.fontWeight=400,e.fontStyle="italic";break;case 3:e.fontStyle="italic",e.fontWeight=400}let l=a.getVariant(e.fontWeight,e.fontStyle);if(!l){let c=o;c!=null&&c.endsWith("-msdf.json")||(c+="-msdf.json");let d=o;d!=null&&d.endsWith(".png")||(d+=".png"),l=a.addVariant(e.fontWeight,e.fontStyle,c,d),l==null||l.addEventListener("ready",()=>{this.markDirty()})}}getFamilyNameWithCorrectSuffix(e,i){var u;const n=e.lastIndexOf("-");if(n<0)return e;const o=(u=e.substring(n+1))==null?void 0:u.toLowerCase();if(PM.includes(o))return No&&console.warn("Unsupported font style: "+o),e;const a=e.lastIndexOf("/");let l=e;a>=0&&(l=l.substring(a+1));const c=l[0]===l[0].toUpperCase(),d=e.substring(0,n);switch(No&&console.log("Select font: ",e,vw[i],l,c,d),i){case 0:return c?d+"-Regular":d+"-regular";case 1:return c?d+"-Bold":d+"-bold";case 2:return c?d+"-Italic":d+"-italic";case 3:return c?d+"-BoldItalic":d+"-bolditalic";default:return e}}}Ts([p()],Dt.prototype,"alignment",2);Ts([p()],Dt.prototype,"verticalOverflow",2);Ts([p()],Dt.prototype,"horizontalOverflow",2);Ts([p()],Dt.prototype,"lineSpacing",2);Ts([p()],Dt.prototype,"supportRichText",2);Ts([p(URL)],Dt.prototype,"font",2);Ts([p()],Dt.prototype,"fontStyle",2);Ts([p()],Dt.prototype,"text",1);Ts([p()],Dt.prototype,"fontSize",1);class sp{constructor(t,e){r(this,"tag");r(this,"previousValues");this.tag=t,this.previousValues=e}}const PM=["medium","mediumitalic","black","blackitalic","thin","thinitalic","extrabold","light","lightitalic","semibold"];class eo{constructor(t){r(this,"id");r(this,"content","");r(this,"font",[]);r(this,"pointSize",144);r(this,"width");r(this,"height");r(this,"depth");r(this,"wrapMode");r(this,"horizontalAlignment");r(this,"verticalAlignment");r(this,"material");this.id=t}static getId(){return this.global_id++}setDepth(t){return this.depth=t,this}setPointSize(t){return this.pointSize=t,this}setHorizontalAlignment(t){return this.horizontalAlignment=t,this}setVerticalAlignment(t){return this.verticalAlignment=t,this}writeTo(t,e){var n;e.beginBlock(`def Preliminary_Text "${this.id}"`,"(",!1),e.appendLine('prepend apiSchemas = ["MaterialBindingAPI"]'),e.closeBlock(")"),e.beginBlock(),this.content&&e.appendLine(`string content = "${this.content}"`),(!this.font||this.font.length<=0)&&(this.font||(this.font=[]),(n=this.font)==null||n.push("sans-serif"));const i=this.font.map(o=>`"${o}"`).join(", ");e.appendLine(`string[] font = [ ${i} ]`),e.appendLine(`double pointSize = ${this.pointSize}`),typeof this.width=="number"&&e.appendLine(`double width = ${this.width}`),typeof this.height=="number"&&e.appendLine(`double height = ${this.height}`),typeof this.depth=="number"&&e.appendLine(`double depth = ${this.depth}`),this.wrapMode&&e.appendLine(`token wrapMode = "${this.wrapMode}"`),this.horizontalAlignment&&e.appendLine(`token horizontalAlignment = "${this.horizontalAlignment}"`),this.verticalAlignment&&e.appendLine(`token verticalAlignment = "${this.verticalAlignment}"`),this.material!==void 0&&e.appendLine(`rel material:binding = </StageRoot/Materials/${Fg(this.material)}>`),e.closeBlock()}}r(eo,"global_id",0);class Qu{static singleLine(t,e,i){const n=new eo("text_"+eo.getId());return n.content=t,e&&(n.pointSize=e),i&&(n.depth=i),n}static multiLine(t,e,i,n,o,a){const l=new eo("text_"+eo.getId());return l.content=t,l.width=e,l.height=i,l.horizontalAlignment=n,l.verticalAlignment=o,a!==void 0&&(l.wrapMode=a),l}}const OM=new h.Matrix4().makeRotationY(Math.PI),MM=new h.Matrix4().makeScale(-1,1,-1);class ph{get extensionName(){return"text"}exportText(t,e,i){const n=C.getComponent(t,Dt);if(!n)return;const o=C.getComponent(t,At);let a=100,l=100;o&&(a=o.width,l=o.height);const c=OM.clone();o&&c.premultiply(MM),e.setMatrix(c);const d=n.color.clone();e.material=new h.MeshStandardMaterial({color:d,emissive:d}),e.addEventListener("serialize",(u,f)=>{let m=n.text;m=m.replace(/\r/g,""),m=m.replace(/\n/g,"\\n");const g=Qu.multiLine(m,a,l,"center","bottom","flowing");this.setTextAlignment(g,n.alignment),this.setOverflow(g,n),e.material&&(g.material=e.material),g.pointSize=this.convertToTextSize(n.fontSize),g.depth=.001,g.writeTo(void 0,u)})}convertToTextSize(t){return 1/.0502*144*t}setOverflow(t,e){e.horizontalOverflow?t.wrapMode="singleLine":t.wrapMode="flowing"}setTextAlignment(t,e){switch(e){case et.LowerLeft:case et.MiddleLeft:case et.UpperLeft:t.horizontalAlignment="left";break;case et.LowerCenter:case et.MiddleCenter:case et.UpperCenter:t.horizontalAlignment="center";break;case et.LowerRight:case et.MiddleRight:case et.UpperRight:t.horizontalAlignment="right";break}switch(e){case et.LowerLeft:case et.LowerCenter:case et.LowerRight:t.verticalAlignment="bottom";break;case et.MiddleLeft:case et.MiddleCenter:case et.MiddleRight:t.verticalAlignment="middle";break;case et.UpperLeft:case et.UpperCenter:case et.UpperRight:t.verticalAlignment="top";break}}}var RM=Object.defineProperty,kM=Object.getOwnPropertyDescriptor,Ye=(s,t,e,i)=>{for(var n=i>1?void 0:i?kM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&RM(t,e,n),n};const nb=S("debuguilayout");class Po{constructor(){r(this,"left",0);r(this,"right",0);r(this,"top",0);r(this,"bottom",0)}get vertical(){return this.top+this.bottom}get horizontal(){return this.left+this.right}}Ye([p()],Po.prototype,"left",2);Ye([p()],Po.prototype,"right",2);Ye([p()],Po.prototype,"top",2);Ye([p()],Po.prototype,"bottom",2);class ki extends D{constructor(){super(...arguments);r(this,"_rectTransform",null);r(this,"_needsUpdate",!1);r(this,"childAlignment",0);r(this,"reverseArrangement",!1);r(this,"spacing",0);r(this,"padding");r(this,"minWidth",0);r(this,"minHeight",0);r(this,"flexibleHeight",0);r(this,"flexibleWidth",0);r(this,"preferredHeight",0);r(this,"preferredWidth",0)}get rectTransform(){return this._rectTransform}onParentRectTransformChanged(e){this._needsUpdate=!0}get isDirty(){return this._needsUpdate}get isLayoutGroup(){return!0}updateLayout(){this._rectTransform&&(nb&&console.warn("Layout Update",this.context.time.frame,this.name),this._needsUpdate=!1,this.onCalculateLayout(this._rectTransform))}start(){this._needsUpdate=!0}onEnable(){nb&&console.log(this.name,this),this._rectTransform=this.gameObject.getComponent(At);const e=this.gameObject.getComponentInParent(Ct);e&&e.registerLayoutGroup(this),this._needsUpdate=!0}onDisable(){const e=this.gameObject.getComponentInParent(Ct);e&&e.unregisterLayoutGroup(this)}set m_Spacing(e){e!==this.spacing&&(this._needsUpdate=!0,this.spacing=e)}get m_Spacing(){return this.spacing}}Ye([p()],ki.prototype,"childAlignment",2);Ye([p()],ki.prototype,"reverseArrangement",2);Ye([p()],ki.prototype,"spacing",2);Ye([p(Po)],ki.prototype,"padding",2);Ye([p()],ki.prototype,"minWidth",2);Ye([p()],ki.prototype,"minHeight",2);Ye([p()],ki.prototype,"flexibleHeight",2);Ye([p()],ki.prototype,"flexibleWidth",2);Ye([p()],ki.prototype,"preferredHeight",2);Ye([p()],ki.prototype,"preferredWidth",2);class Oo extends ki{constructor(){super(...arguments);r(this,"childControlHeight",!0);r(this,"childControlWidth",!0);r(this,"childForceExpandHeight",!1);r(this,"childForceExpandWidth",!1);r(this,"childScaleHeight",!1);r(this,"childScaleWidth",!1)}onCalculateLayout(e){var I;const i=this.primaryAxis,n=e.width;let o=n;const a=e.height;let l=a;o-=this.padding.horizontal,l-=this.padding.vertical,i==="x"?this.padding.horizontal:this.padding.vertical;const c=i==="x",d=c?"y":"x",u=c?this.childControlWidth:this.childControlHeight,f=c?this.childControlHeight:this.childControlWidth,m=c?this.childForceExpandWidth:this.childForceExpandHeight,g=c?this.childForceExpandHeight:this.childForceExpandWidth,_=c?l:o,y=c?n:a,b=.5*(c?this.childAlignment%3:Math.floor(this.childAlignment/3));let v=0;c?v+=this.padding.left:v+=this.padding.top;let x=0,O=0;for(let E=0;E<this.gameObject.children.length;E++){const j=this.gameObject.children[E],F=C.getComponent(j,At);F!=null&&F.activeAndEnabled&&(O+=1,c?x+=F.width:x+=F.height)}let k=0;const M=this.spacing*(O-1);if(m||u){let E=0;c?E=o-=M:E=l-=M,O>0&&(k=E/O)}let R=0;R+=this.padding.left,R-=this.padding.right,b!==0&&(v=y-x,v*=b,v-=M*b,c?(v-=this.padding.right*b,v+=this.padding.left*(1-b),v<this.padding.left&&(v=this.padding.left)):(v-=this.padding.bottom*b,v+=this.padding.top*(1-b),v<this.padding.top&&(v=this.padding.top)));let A=1;for(let E=0;E<this.gameObject.children.length;E++){const j=this.gameObject.children[E],F=C.getComponent(j,At);if(F!=null&&F.activeAndEnabled){(I=F.pivot)==null||I.set(.5,.5),F.anchorMin.set(0,1),F.anchorMax.set(0,1);const G=n*.5+R*.5;F.anchoredPosition.x!==G&&(F.anchoredPosition.x=G);const T=a*-.5;F.anchoredPosition.y!==T&&(F.anchoredPosition.y=T),g&&f&&F.sizeDelta[d]!==_&&(F.sizeDelta[d]=_),m&&u&&F.sizeDelta[i]!==k&&(F.sizeDelta[i]=k);const L=c?F.width:F.height,$=L*.5;if(v+=$,m){const J=k*A-k*.5;J>v&&(v=J-k*.5+L+this.padding.left,v-=$)}let X=v;i==="y"&&(X=-X),F.anchoredPosition[i]!==X&&(F.anchoredPosition[i]=X),v+=$,v+=this.spacing,A+=1}}}}Ye([p()],Oo.prototype,"childControlHeight",2);Ye([p()],Oo.prototype,"childControlWidth",2);Ye([p()],Oo.prototype,"childForceExpandHeight",2);Ye([p()],Oo.prototype,"childForceExpandWidth",2);Ye([p()],Oo.prototype,"childScaleHeight",2);Ye([p()],Oo.prototype,"childScaleWidth",2);class Hg extends Oo{get primaryAxis(){return"y"}}class Gg extends Oo{get primaryAxis(){return"x"}}class qg extends ki{onCalculateLayout(){}}var TM=Object.defineProperty,EM=Object.getOwnPropertyDescriptor,Hn=(s,t,e,i)=>{for(var n=i>1?void 0:i?EM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&TM(t,e,n),n},ww=(s=>(s[s.ScreenSpaceOverlay=0]="ScreenSpaceOverlay",s[s.ScreenSpaceCamera=1]="ScreenSpaceCamera",s[s.WorldSpace=2]="WorldSpace",s[s.Undefined=-1]="Undefined",s))(ww||{});const op=S("debuguilayout"),xw=class extends ih{constructor(){super(...arguments);r(this,"_renderOnTop");r(this,"_depthWrite",!1);r(this,"_doubleSided",!0);r(this,"_castShadows",!1);r(this,"_receiveShadows",!1);r(this,"_renderMode",-1);r(this,"_rootCanvas");r(this,"_scaleFactor",1);r(this,"worldCamera");r(this,"planeDistance",-1);r(this,"_boundRenderSettingsChanged",this.onRenderSettingsChanged.bind(this));r(this,"previousParent",null);r(this,"_lastMatrixWorld",null);r(this,"_rectTransforms",[]);r(this,"_layoutGroups",new Map);r(this,"_receivers",[]);r(this,"onBeforeRenderRoutine",()=>{var t,e,i,n;if(this.previousParent=this.gameObject.parent,((t=this.context.xr)!=null&&t.isVR||(e=this.context.xr)!=null&&e.isPassThrough)&&this.screenspace){this.gameObject.visible=!1,this.gameObject.removeFromParent();return}this.renderOnTop||this.screenspace?this.gameObject.removeFromParent():(this.onUpdateRenderMode(),this.handleLayoutUpdates(),(i=this.shadowComponent)==null||i.updateMatrixWorld(!0),(n=this.shadowComponent)==null||n.updateWorldMatrix(!0,!0),this.invokeBeforeRenderEvents(),qt.ensureUpdateMeshUI(ie.ThreeMeshUI,this.context))});r(this,"onAfterRenderRoutine",()=>{var t,e,i,n,o;if(((t=this.context.xr)!=null&&t.isVR||(e=this.context.xr)!=null&&e.isPassThrough)&&this.screenspace){(i=this.previousParent)==null||i.add(this.gameObject);return}if((this.screenspace||this.renderOnTop)&&this.previousParent&&this.context.mainCamera){if(this.screenspace){const c=this.context.mainCamera;c==null||c.add(this.gameObject)}else this.previousParent.add(this.gameObject);const a=this.context.renderer.autoClear,l=this.context.renderer.autoClearColor;this.context.renderer.autoClear=!1,this.context.renderer.autoClearColor=!1,this.context.renderer.clearDepth(),this.onUpdateRenderMode(!0),this.handleLayoutUpdates(),(n=this.shadowComponent)==null||n.updateMatrixWorld(!0),this.invokeBeforeRenderEvents(),qt.ensureUpdateMeshUI(ie.ThreeMeshUI,this.context,!0),this.context.renderer.render(this.gameObject,this.context.mainCamera),this.context.renderer.autoClear=a,this.context.renderer.autoClearColor=l,this.previousParent.add(this.gameObject)}(o=this._lastMatrixWorld)==null||o.copy(this.gameObject.matrixWorld)});r(this,"_updateRenderSettingsRoutine");r(this,"_activeRenderMode",-1);r(this,"_lastWidth",-1);r(this,"_lastHeight",-1)}get isCanvas(){return!0}get screenspace(){return this.renderMode!==2}set renderOnTop(t){t!==this._renderOnTop&&(this._renderOnTop=t,this.onRenderSettingsChanged())}get renderOnTop(){return this._renderOnTop!==void 0?this._renderOnTop:!!(this.screenspace&&this._renderMode===0)}set depthWrite(t){this._depthWrite!==t&&(this._depthWrite=t,this.onRenderSettingsChanged())}get depthWrite(){return this._depthWrite}set doubleSided(t){this._doubleSided!==t&&(this._doubleSided=t,this.onRenderSettingsChanged())}get doubleSided(){return this._doubleSided}set castShadows(t){this._castShadows!==t&&(this._castShadows=t,this.onRenderSettingsChanged())}get castShadows(){return this._castShadows}set receiveShadows(t){this._receiveShadows!==t&&(this._receiveShadows=t,this.onRenderSettingsChanged())}get receiveShadows(){return this._receiveShadows}get renderMode(){return this._renderMode}set renderMode(t){this._renderMode!==t&&(this._renderMode=t,this.onRenderSettingsChanged())}set rootCanvas(t){this._rootCanvas instanceof xw||(this._rootCanvas=t)}get rootCanvas(){return this._rootCanvas}get scaleFactor(){return this._scaleFactor}set scaleFactor(t){this._scaleFactor=t}awake(){var t;this.shadowComponent=this.gameObject,this.previousParent=this.gameObject.parent,op&&console.log("Canvas.Awake()",((t=this.previousParent)==null?void 0:t.name)+"/"+this.gameObject.name),super.awake()}start(){this.onUpdateRenderMode()}onEnable(){super.onEnable(),this._updateRenderSettingsRoutine=void 0,this._lastMatrixWorld=new h.Matrix4,this.onUpdateRenderMode(),document.addEventListener("resize",this._boundRenderSettingsChanged),this.context.pre_render_callbacks.push(this.onBeforeRenderRoutine),this.context.post_render_callbacks.push(this.onAfterRenderRoutine)}onDisable(){super.onDisable(),document.removeEventListener("resize",this._boundRenderSettingsChanged);const t=this.context.pre_render_callbacks.indexOf(this.onBeforeRenderRoutine);t!==-1&&this.context.pre_render_callbacks.splice(t,1);const e=this.context.post_render_callbacks.indexOf(this.onAfterRenderRoutine);e!==-1&&this.context.post_render_callbacks.splice(e,1)}registerTransform(t){this._rectTransforms.push(t)}unregisterTransform(t){const e=this._rectTransforms.indexOf(t);e!==-1&&this._rectTransforms.splice(e,1)}registerLayoutGroup(t){const e=t.gameObject;this._layoutGroups.set(e,t)}unregisterLayoutGroup(t){const e=t.gameObject;this._layoutGroups.delete(e)}registerEventReceiver(t){this._receivers.push(t)}unregisterEventReceiver(t){const e=this._receivers.indexOf(t);e!==-1&&this._receivers.splice(e,1)}async onEnterXR(t){this.screenspace?(t.xr.isVR||t.xr.isPassThrough)&&(this.gameObject.visible=!1):(this.gameObject.visible=!1,await Vc(1).then(()=>{this.gameObject.visible=!0}))}onLeaveXR(t){this.screenspace&&(t.xr.isVR||t.xr.isPassThrough)&&(this.gameObject.visible=!0)}invokeBeforeRenderEvents(){var t;for(const e of this._receivers)(t=e.onBeforeCanvasRender)==null||t.call(e,this)}handleLayoutUpdates(){this._lastMatrixWorld===null&&(this._lastMatrixWorld=new h.Matrix4);const t=!this._lastMatrixWorld.equals(this.gameObject.matrixWorld);op&&t&&console.log("Canvas Layout changed",this.context.time.frameCount,this.name);const e=!1;for(const i of this._rectTransforms){t&&i.markDirty();let n=this._layoutGroups.get(i.gameObject);i.isDirty&&!n&&(n=i.gameObject.getComponentInParent(ki)),(i.isDirty||n!=null&&n.isDirty)&&(op&&!e&&console.log("CANVAS UPDATE ### "+i.name+" ##################################### "+this.context.time.frame),n==null||n.updateLayout(),i.updateTransform())}}applyRenderSettings(){this.onRenderSettingsChanged()}onRenderSettingsChanged(){this._updateRenderSettingsRoutine||(this._updateRenderSettingsRoutine=this.startCoroutine(this._updateRenderSettingsDelayed(),ve.OnBeforeRender))}*_updateRenderSettingsDelayed(){if(yield,this._updateRenderSettingsRoutine=void 0,this.shadowComponent){this.onUpdateRenderMode(),tu(this.shadowComponent,this);for(const t of C.getComponentsInChildren(this.gameObject,Hi))tu(t.shadowComponent,this)}}onUpdateRenderMode(t=!1){if(!t&&this._renderMode===this._activeRenderMode&&this._lastWidth===this.context.domWidth&&this._lastHeight===this.context.domHeight)return;this._activeRenderMode=this._renderMode;let e=this.context.mainCameraComponent,i=10;switch(e&&e.nearClipPlane>0&&e.farClipPlane>0&&(i=z.lerp(e.nearClipPlane,e.farClipPlane,.01)),this._renderMode===1&&(this.worldCamera&&(e=this.worldCamera),this.planeDistance>0&&(i=this.planeDistance)),this._renderMode){case 0:case 1:if(this._lastWidth=this.context.domWidth,this._lastHeight=this.context.domHeight,!e)return;const n=i+.01;this.gameObject.position.x=0,this.gameObject.position.y=0,this.gameObject.position.z=-n,this.gameObject.quaternion.identity();const o=this.gameObject.getComponent(At);let a=!1;o.sizeDelta.x!==this.context.domWidth&&(a=!0),o.sizeDelta.y!==this.context.domHeight&&(a=!0);const l=e.fieldOfView*Math.PI/180,c=2*Math.tan(l/2)*Math.abs(n);this.gameObject.scale.x=c/this.context.domHeight,this.gameObject.scale.y=c/this.context.domHeight,this.gameObject.scale.z=.01,a&&(o.sizeDelta.x=this.context.domWidth,o.sizeDelta.y=this.context.domHeight,o==null||o.markDirty());break;case 2:this._lastWidth=-1,this._lastHeight=-1;break}}};let Ct=xw;Hn([p()],Ct.prototype,"renderOnTop",1);Hn([p()],Ct.prototype,"depthWrite",1);Hn([p()],Ct.prototype,"doubleSided",1);Hn([p()],Ct.prototype,"castShadows",1);Hn([p()],Ct.prototype,"receiveShadows",1);Hn([p()],Ct.prototype,"renderMode",1);Hn([p(Ct)],Ct.prototype,"rootCanvas",1);Hn([p()],Ct.prototype,"scaleFactor",1);Hn([p(be)],Ct.prototype,"worldCamera",2);Hn([p()],Ct.prototype,"planeDistance",2);var AM=Object.defineProperty,DM=Object.getOwnPropertyDescriptor,Xg=(s,t,e,i)=>{for(var n=i>1?void 0:i?DM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&AM(t,e,n),n};class uo extends D{constructor(){super(...arguments);r(this,"_alpha",1);r(this,"interactable",!0);r(this,"blocksRaycasts",!0);r(this,"_isDirty",!1);r(this,"_buffer",[])}get alpha(){return this._alpha}set alpha(e){e!==this._alpha&&(this._alpha=e,this.markDirty())}get isCanvasGroup(){return!0}markDirty(){this._isDirty||(this._isDirty=!0,this.startCoroutine(this.applyChangesDelayed(),ve.OnBeforeRender))}*applyChangesDelayed(){this._isDirty=!1,this.applyChangesNow()}applyChangesNow(){this._buffer.length=0;for(const e of C.getComponentsInChildren(this.gameObject,Hi,this._buffer)){const i=e;i.setAlphaFactor&&i.setAlphaFactor(this._alpha)}}}Xg([p()],uo.prototype,"alpha",1);Xg([p()],uo.prototype,"interactable",2);Xg([p()],uo.prototype,"blocksRaycasts",2);class Yu{get extensionName(){return"tmui"}onExportObject(t,e,i){const n=C.getComponent(t,Ct);if(n&&n.enabled&&n.renderMode===ww.WorldSpace){const o=new ph,a=C.getComponent(t,At),l=C.getComponent(t,uo),c=new Array;if(a){if(!C.isActiveSelf(t)){const f=C.isActiveSelf(t);C.setActive(t,!0),a.onEnable(),a.updateTransform(),c.push(()=>{a.onDisable(),C.setActive(t,f)})}t.traverse(f=>{if(!C.isActiveInHierarchy(f)){const m=C.isActiveSelf(f);C.setActive(f,!0);const g=C.getComponent(f,Hi);g&&(g.onEnable(),c.push(()=>{g.onDisable()}));const _=C.getComponent(f,At);_&&(_.onEnable(),_.updateTransform(),_.onApplyTransform(),c.push(()=>{_.onDisable()}));const y=C.getComponent(f,Dt);y&&(y.onEnable(),c.push(()=>{y.onDisable()})),c.push(()=>{C.setActive(f,m)})}}),a.width,a.height;const d=wt.createEmpty(),u=a.shadowComponent;if(e.add(d),u){const f=u.matrix;d.setMatrix(f);const m=new Map,g=new Map;m.set(u,d),g.set(u,l?l.alpha:1),u.traverse(_=>{if(_===u)return;const y=wt.createEmpty();y.setMatrix(_.matrix);const b=_.parent,v=!!b&&typeof b.textContent=="string"&&b.textContent.length>0;let x=g.get(b)||1;const O=C.getComponent(_,uo);if(O&&(x*=O.alpha),_ instanceof h.Mesh&&v){const M=_[Ni];M?o.exportText(M.gameObject,y,i):console.error("Error when exporting UI: shadow component owner not found. This is likely a bug.",_)}if(_ instanceof h.Mesh&&!v){const M=_.geometry.clone();M.scale(1,1,-1),this.flipWindingOrder(M),y.geometry=M;const R=new h.Color,A=_.material.opacity;R.copy(_.material.color),y.material=new h.MeshBasicMaterial({color:R,opacity:A*x,map:_.material.map,transparent:!0})}m.set(_,y),g.set(_,x);const k=m.get(b);if(!k){console.error("Error when exporting UI: shadow component parent not found!",_,_.parent);return}k.add(y)})}}for(const d of c)d()}}flipWindingOrder(t){const e=t.index.array;for(let i=0,n=e.length/3;i<n;i++){const o=e[i*3];e[i*3]=e[i*3+2],e[i*3+2]=o}t.index.needsUpdate=!0}}const R_=class{constructor(){r(this,"_quicklookButton");r(this,"_arButton");r(this,"_vrButton");r(this,"_sendToQuestButton")}static create(){return new R_}static getOrCreate(){return this._instance||(this._instance=this.create()),this._instance}get isSecureConnection(){return window.location.protocol==="https:"}get quicklookButton(){return this._quicklookButton}get arButton(){return this._arButton}get vrButton(){return this._vrButton}get sendToQuestButton(){return this._sendToQuestButton}get qrButton(){return an.getOrCreate().createQRCode()}createQuicklookButton(){if(this._quicklookButton)return this._quicklookButton;const t=document.createElement("button");this._quicklookButton=t,t.dataset.needle="quicklook-button";const e=exports.DeviceUtilities.supportsQuickLookAR();t.innerText="View in AR",t.prepend(bt("view_in_ar"));let i=!1,n=null;return t.addEventListener("click",()=>{n=ku(Ie),n||(i=!0,n=new Ie),i&&(n.objectToExport=Q.Current.scene),n?(t.classList.add("this-mode-is-requested"),n.exportAndOpen().then(()=>{t.classList.remove("this-mode-is-requested")}).catch(o=>{t.classList.remove("this-mode-is-requested"),console.error(o)})):console.warn("No USDZExporter component found in the scene")}),this.hideElementDuringXRSession(t),t}createARButton(t){var n;if(this._arButton)return this._arButton;const e="immersive-ar",i=document.createElement("button");return this._arButton=i,i.classList.add("webxr-button"),i.dataset.needle="webxr-ar-button",i.innerText="Enter AR",i.prepend(bt("view_in_ar")),i.title="Click to start an AR session",i.addEventListener("click",()=>q.start(e,t)),this.updateSessionSupported(i,e),this.listenToXRSessionState(i,e),this.hideElementDuringXRSession(i),this.isSecureConnection||(i.disabled=!0,i.title="WebXR requires a secure connection (HTTPS)"),exports.DeviceUtilities.isMozillaXR()||(n=navigator.xr)==null||n.addEventListener("devicechange",()=>this.updateSessionSupported(i,e)),i}createVRButton(t){var n;if(this._vrButton)return this._vrButton;const e="immersive-vr",i=document.createElement("button");return this._vrButton=i,i.classList.add("webxr-button"),i.dataset.needle="webxr-vr-button",i.innerText="Enter VR",i.prepend(bt("panorama_photosphere")),i.title="Click to start a VR session",i.addEventListener("click",()=>q.start(e,t)),this.updateSessionSupported(i,e),this.listenToXRSessionState(i,e),this.hideElementDuringXRSession(i),this.isSecureConnection||(i.disabled=!0,i.title="WebXR requires a secure connection (HTTPS)"),exports.DeviceUtilities.isMozillaXR()||(n=navigator.xr)==null||n.addEventListener("devicechange",()=>this.updateSessionSupported(i,e)),i}createSendToQuestButton(){var i;if(this._sendToQuestButton)return this._sendToQuestButton;const t="https://oculus.com/open_url/?url=",e=document.createElement("button");return this._sendToQuestButton=e,e.dataset.needle="webxr-sendtoquest-button",e.innerText="Open on Quest",e.prepend(bt("share_windows")),e.title="Click to send this page to the Oculus Browser on your Quest",e.addEventListener("click",()=>{const n=encodeURIComponent(window.location.href),o=t+n;window.open(o)==null&&Ee("This page doesn't allow popups. Please paste "+o+" into your browser.")}),this.listenToXRSessionState(e),this.hideElementDuringXRSession(e),exports.DeviceUtilities.isMozillaXR()||(i=navigator.xr)==null||i.addEventListener("devicechange",()=>{var n;(n=navigator.xr)!=null&&n.isSessionSupported("immersive-vr")?e.style.display="none":e.style.display=""}),e}createQRCode(){return an.getOrCreate().createQRCode()}updateSessionSupported(t,e){if(!("xr"in navigator)){t.style.display="none";return}q.isSessionSupported(e).then(i=>{t.style.display=i?"":"none",B()&&!i&&console.log('[WebXR] "'+e+'" is not supported on this device – make sure your server runs using HTTPS and you have a device connected that supports '+e)})}hideElementDuringXRSession(t){Pu(e=>{t["previous-display"]=t.style.display,t.style.display="none"}),Xm(e=>{t["previous-display"]!=null&&(t.style.display=t["previous-display"])})}listenToXRSessionState(t,e){e&&(q.onSessionRequestStart(i=>{i.mode===e?t.classList.add("this-mode-is-requested"):(t["was-disabled"]=t.disabled,t.disabled=!0,t.classList.add("other-mode-is-requested"))}),q.onSessionRequestEnd(i=>{t.classList.remove("this-mode-is-requested"),t.classList.remove("other-mode-is-requested"),t.disabled=t["was-disabled"]}))}};let ws=R_;r(ws,"_instance");var LM=Object.defineProperty,IM=Object.getOwnPropertyDescriptor,dt=(s,t,e,i)=>{for(var n=i>1?void 0:i?IM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&LM(t,e,n),n};const ru=S("debugspriterenderer"),jM=S("wireframe"),gu=class{static getOrCreateGeometry(t){if(t.__cached_geometry)return t.__cached_geometry;if(t.guid&&gu.cache[t.guid])return ru&&console.log("Take cached geometry for sprite",t.guid),gu.cache[t.guid];const e=new h.BufferGeometry;t.__cached_geometry=e;const i=new Float32Array(t.triangles.length*3),n=new Float32Array(t.triangles.length*2);for(let o=0;o<t.triangles.length;o+=1){const a=t.triangles[o];i[o*3]=-t.vertices[a].x,i[o*3+1]=t.vertices[a].y,i[o*3+2]=0;const l=t.uv[a];n[o*2]=l.x,n[o*2+1]=1-l.y}return e.setAttribute("position",new h.BufferAttribute(i,3)),e.setAttribute("uv",new h.BufferAttribute(n,2)),t.guid&&(this.cache[t.guid]=e),ru&&console.log("Built sprite geometry",t,e),e}};let ur=gu;r(ur,"cache",{});class BM{constructor(){r(this,"x");r(this,"y")}}function Sw(s){s&&(s.colorSpace!=h.SRGBColorSpace&&(s.colorSpace=h.SRGBColorSpace,s.needsUpdate=!0),s.minFilter==h.NearestFilter&&s.magFilter==h.NearestFilter&&(s.anisotropy=1,s.needsUpdate=!0))}let Gn=class{constructor(t){r(this,"guid");r(this,"texture");r(this,"triangles");r(this,"uv");r(this,"vertices");r(this,"__cached_geometry");r(this,"_mesh");r(this,"_material");t&&(this.texture=t,this.triangles=[0,1,2,0,2,3],this.uv=[{x:0,y:0},{x:1,y:0},{x:1,y:1},{x:0,y:1}],this.vertices=[{x:-.5,y:-.5},{x:.5,y:-.5},{x:.5,y:.5},{x:-.5,y:.5}])}get mesh(){return this._mesh||(this._mesh=new h.Mesh(ur.getOrCreateGeometry(this),this.material)),this._mesh}get material(){return this._material||(this.texture&&Sw(this.texture),this._material=new h.MeshBasicMaterial({map:this.texture,color:16777215,side:h.DoubleSide,transparent:!0})),this._material}getGeometry(){return ur.getOrCreateGeometry(this)}};dt([p()],Gn.prototype,"guid",2);dt([p(h.Texture)],Gn.prototype,"texture",2);dt([Va()],Gn.prototype,"triangles",2);dt([Va()],Gn.prototype,"uv",2);dt([Va()],Gn.prototype,"vertices",2);const rp=Symbol("spriteOwner");class fo{constructor(){r(this,"sprites")}}dt([p(Gn)],fo.prototype,"sprites",2);const Cw=class{constructor(){r(this,"spriteSheet");r(this,"index",0)}static create(){const s=new Cw;return s.spriteSheet=new fo,s}set sprite(s){s&&(this.spriteSheet?((this.index===null||this.index===void 0)&&(this.index=0),this.spriteSheet.sprites[this.index]=s):(this.spriteSheet=new fo,this.spriteSheet.sprites=[s],this.index=0))}get sprite(){if(this.spriteSheet)return this.spriteSheet.sprites[this.index]}update(s){if(!this.spriteSheet)return;const t=this.index;if(t<0||t>=this.spriteSheet.sprites.length)return;const e=this.spriteSheet.sprites[t],i=e==null?void 0:e.texture;if(i&&(Sw(i),!e.__hasLoadedProgressive)){e.__hasLoadedProgressive=!0;const n=i;re.NEEDLE_progressive.assignTextureLOD(i,0).then(o=>{o instanceof h.Texture&&(e.texture=o,(s==null?void 0:s.map)===n&&(s.map=o,s.needsUpdate=!0))})}}};let xs=Cw;dt([p(fo)],xs.prototype,"spriteSheet",2);dt([p()],xs.prototype,"index",2);class li extends D{constructor(){super(...arguments);r(this,"drawMode",0);r(this,"size",{x:1,y:1});r(this,"color");r(this,"sharedMaterial");r(this,"transparent",!0);r(this,"cutoutThreshold",0);r(this,"castShadows",!1);r(this,"renderOrder",0);r(this,"toneMapped",!0);r(this,"_spriteSheet");r(this,"_currentSprite")}set texture(e){var n;if(!this._spriteSheet)return;const i=(n=this._spriteSheet.spriteSheet)==null?void 0:n.sprites[this.spriteIndex];i&&(i.texture=e,this.updateSprite())}addSprite(e,i=!1){var o,a;if(this._spriteSheet||(this._spriteSheet=xs.create()),!this._spriteSheet.spriteSheet)return-1;(o=this._spriteSheet.spriteSheet)==null||o.sprites.push(e);const n=((a=this._spriteSheet.spriteSheet)==null?void 0:a.sprites.length)-1;return i&&(this.spriteIndex=n),n}get sprite(){return this._spriteSheet}set sprite(e){if(e!==this._spriteSheet)if(typeof e=="number"){const i=Math.floor(e);this.spriteIndex=i;return}else e instanceof Gn?(this._spriteSheet||(this._spriteSheet=xs.create()),this._spriteSheet.sprite!=e&&(this._spriteSheet.sprite=e,this.updateSprite())):e!=this._spriteSheet&&(this._spriteSheet=e,this.updateSprite())}set spriteIndex(e){this._spriteSheet&&e!==this.spriteIndex&&(this._spriteSheet.index=e,this.updateSprite())}get spriteIndex(){var e;return((e=this._spriteSheet)==null?void 0:e.index)??0}get spriteFrames(){var e,i;return((i=(e=this._spriteSheet)==null?void 0:e.spriteSheet)==null?void 0:i.sprites.length)??0}awake(){this._currentSprite=void 0,this._spriteSheet||(this._spriteSheet=new xs,this._spriteSheet.spriteSheet=new fo),ru&&console.log("Awake",this.name,this,this.sprite)}start(){this._currentSprite?this.gameObject&&this.gameObject.add(this._currentSprite):this.updateSprite()}updateSprite(e=!1){var o;if(!this.__didAwake&&!e)return!1;const i=this._spriteSheet;if(!((o=i==null?void 0:i.spriteSheet)!=null&&o.sprites))return console.warn("SpriteRenderer has no data or spritesheet assigned..."),!1;const n=i.spriteSheet.sprites[this.spriteIndex];if(!n)return ru&&console.warn("Sprite not found",this.spriteIndex,i.spriteSheet.sprites),!1;if(this._currentSprite)this._currentSprite.geometry=ur.getOrCreateGeometry(n),this._currentSprite.material.map=n.texture;else{const a=new h.MeshBasicMaterial({color:16777215,side:h.DoubleSide});if(jM&&(a.wireframe=!0),this.color&&(a.color||(a.color=new h.Color),a.color.copy(this.color),a.opacity=this.color.alpha),a.transparent=!0,a.toneMapped=this.toneMapped,n.texture&&!a.wireframe){let l=n.texture;l[rp]!==void 0&&l[rp]!==this&&this.spriteFrames>1&&(l=n.texture=l.clone()),l[rp]=this,a.map=l}this.sharedMaterial=a,this._currentSprite=new h.Mesh(ur.getOrCreateGeometry(n),a),this._currentSprite.renderOrder=Math.round(this.renderOrder),re.NEEDLE_progressive.assignTextureLOD(a,0)}return this._currentSprite.parent!==this.gameObject&&(this.drawMode===2&&this._currentSprite.scale.set(this.size.x,this.size.y,1),this.gameObject&&this.gameObject.add(this._currentSprite)),this._currentSprite&&this._currentSprite.layers.set(this.layer),this.sharedMaterial&&(this.sharedMaterial.alphaTest=this.cutoutThreshold,this.sharedMaterial.transparent=this.transparent),this._currentSprite.castShadow=this.castShadows,i==null||i.update(this.sharedMaterial),!0}}dt([p()],li.prototype,"drawMode",2);dt([p(BM)],li.prototype,"size",2);dt([p(ge)],li.prototype,"color",2);dt([p(h.Material)],li.prototype,"sharedMaterial",2);dt([p()],li.prototype,"transparent",2);dt([p()],li.prototype,"cutoutThreshold",2);dt([p()],li.prototype,"castShadows",2);dt([p()],li.prototype,"renderOrder",2);dt([p()],li.prototype,"toneMapped",2);dt([p(xs)],li.prototype,"sprite",1);const sb=S("debugwebxr"),FM=new h.Matrix4().makeRotationY(Math.PI);class Cs extends D{constructor(){super(...arguments);r(this,"_arScale",1);r(this,"invertForward",!1);r(this,"customReticle");r(this,"arTouchTransform",!0);r(this,"autoPlace",!1);r(this,"autoCenter",!1);r(this,"useXRAnchor",!1);r(this,"_isPlacing",!0);r(this,"_startOffset",new h.Matrix4);r(this,"_createdPlacementObject",null);r(this,"_reparentedComponents",[]);r(this,"_placementScene",new h.Scene);r(this,"_reticle",[]);r(this,"_hits",[]);r(this,"_placementStartTime",-1);r(this,"_rigPlacementMatrix");r(this,"_anchor",null);r(this,"userInput");r(this,"onPlaceScene",e=>{var o;if(this._isPlacing==!1||e!=null&&e.used)return;let i=this._reticle[0];if(!i){console.warn("No reticle to place...");return}if(!i.visible&&!this.autoPlace){console.warn("Reticle is not visible (can not place)");return}if((o=q.active)!=null&&o.isTrackingImages){console.warn("Scene Placement is disabled while images are being tracked");return}let n=this._hits[0];if(e&&e.origin instanceof Qm){const a=this._reticle[e.origin.index];a&&(i=a,n=this._hits[e.origin.index])}if(e&&(e.stopImmediatePropagation(),e.stopPropagation(),e.use()),this._isPlacing=!1,this.context.input.removeEventListener("pointerup",this.onPlaceScene),this.onRevertSceneChanges(),i.position.copy(i.lastPos),i.quaternion.copy(i.lastQuat),this.onApplyPose(i),this.useXRAnchor&&this.onCreateAnchor(q.active,n),this.context.xr)for(const a of this.context.xr.controllers)a.cancelHitTestSource()});r(this,"upVec",new h.Vector3(0,1,0));r(this,"lookPoint",new h.Vector3);r(this,"worldUpVec",new h.Vector3(0,1,0))}static onPlaced(e){const i="placed";return this._eventListeners[i]||(this._eventListeners[i]=[]),this._eventListeners[i].push(e),()=>{const n=this._eventListeners[i].indexOf(e);n>=0&&this._eventListeners[i].splice(n,1)}}get arScale(){return this._arScale}set arScale(e){e!==this._arScale&&(this._arScale=e,this.onScaleChanged())}onEnable(){var e;(e=this.customReticle)==null||e.preload()}supportsXR(e){return e==="immersive-ar"}onEnterXR(e){sb&&console.log("ENTER WEBXR: SessionRoot start..."),this._anchor=null,this.gameObject.updateMatrixWorld(),this._startOffset.copy(this.gameObject.matrixWorld);const i=new h.Object3D;this._createdPlacementObject=i,i.name="AR Session Root",this._placementScene.name="AR Placement Scene",this._placementScene.children.length=0;for(let n=this.context.scene.children.length-1;n>=0;n--){const o=this.context.scene.children[n];this._placementScene.add(o)}if(this.context.scene.add(i),this.autoCenter){const n=oi(this._placementScene.children),o=n.getCenter(new h.Vector3),a=n.getSize(new h.Vector3),l=new h.Matrix4;l.makeTranslation(o.x,o.y-a.y*.5,o.z),this._startOffset.multiply(l)}this._reparentedComponents.length=0,this._reparentedComponents.push({comp:this,originalObject:this.gameObject}),C.addComponent(i,this);for(const n of this._reticle)Pi(n);this._reticle.length=0,this._isPlacing=!0,this.context.input.addEventListener("pointerup",this.onPlaceScene,{queue:_i.Early})}onLeaveXR(){this.context.input.removeEventListener("pointerup",this.onPlaceScene,{queue:_i.Early}),this.onRevertSceneChanges(),this._anchor=null,this._rigPlacementMatrix=void 0}onUpdateXR(e){var i,n,o,a;if(e.xr.isTrackingImages){for(const l of this._reticle)l.visible=!1;return}if(this._isPlacing){const l=(i=e.xr.rig)==null?void 0:i.gameObject;l&&l.parent!==this.context.scene&&this.context.scene.add(l);let c=!1;if(e.xr.isPassThrough&&e.xr.controllers.length>0&&!this.autoPlace)for(const d of e.xr.controllers){const u=d.getHitTest();u&&(c=!0,this.updateReticleAndHits(e.xr,d.index,u,e.xr.rigScale))}if(!c){const d=e.xr.getHitTest();d&&this.updateReticleAndHits(e.xr,0,d,e.xr.rigScale)}}else{if(this._anchor&&e.xr.referenceSpace){const l=e.xr.frame.getPose(this._anchor.anchorSpace,e.xr.referenceSpace);if(l&&this.context.time.frame%20===0){const c=e.xr.convertSpace(l.transform),d=this._reticle[0];d&&(d.position.copy(c.position),d.quaternion.copy(c.quaternion),this.onApplyPose(d))}}if(this.arTouchTransform?(this.userInput||(this.userInput=new ua(this.context)),(n=this.userInput)==null||n.enable()):(o=this.userInput)==null||o.disable(),this.arTouchTransform&&((a=this.userInput)!=null&&a.hasChanged)){if(e.xr.rig){const l=e.xr.rig.gameObject;this.userInput.applyMatrixTo(l.matrix,!0),l.matrix.decompose(l.position,l.quaternion,l.scale),this.userInput.factor=l.scale.x}this.userInput.reset()}}}updateReticleAndHits(e,i,n,o){this._hits[i]=n.hit;let a=this._reticle[i];if(!a){if(this.customReticle)if(this.customReticle.asset)a=br(this.customReticle.asset);else{this.customReticle.loadAssetAsync();return}else a=new h.Mesh(new h.RingGeometry(.07,.09,32).rotateX(-Math.PI/2),new h.MeshBasicMaterial({side:h.DoubleSide,depthTest:!1,depthWrite:!1,transparent:!0,opacity:1,color:15658734})),a.name="AR Placement Reticle";if(sb){const l=new h.AxesHelper(1);l.position.y+=.01,a.add(l)}this._reticle[i]=a,a.matrixAutoUpdate=!1,a.visible=!1}if(a.lastPos=a.lastPos||n.position.clone(),a.lastQuat=a.lastQuat||n.quaternion.clone(),a.position.copy(a.lastPos.lerp(n.position,this.context.time.deltaTime/.1)),a.lastPos.copy(a.position),a.quaternion.copy(a.lastQuat.slerp(n.quaternion,this.context.time.deltaTime/.05)),a.lastQuat.copy(a.quaternion),a.scale.set(o,o,o),this.customReticle&&this.applyViewBasedTransform(a),a.updateMatrix(),a.visible=!0,a.parent!==this.context.scene&&this.context.scene.add(a),this._placementStartTime<0&&(this._placementStartTime=this.context.time.realtimeSinceStartup),this.autoPlace)if(this.upVec.set(0,1,0).applyQuaternion(a.quaternion),this.upVec.dot(V(0,1,0))>.9){let c=a["autoplace:timer"]||0;c>=1?(a.visible=!1,this.onPlaceScene(null)):(c+=this.context.time.deltaTime,a["autoplace:timer"]=c)}else a["autoplace:timer"]=0}onScaleChanged(){}onRevertSceneChanges(){var e;for(const i of this._reticle)i&&(i.visible=!1,i==null||i.removeFromParent());this._reticle.length=0;for(let i=this._placementScene.children.length-1;i>=0;i--){const n=this._placementScene.children[i];this.context.scene.add(n)}(e=this._createdPlacementObject)==null||e.removeFromParent();for(const i of this._reparentedComponents)C.addComponent(i.originalObject,i.comp)}async onCreateAnchor(e,i){if(i.createAnchor===void 0){console.warn("Hit does not support creating an anchor",i),B()&&me("Hit does not support creating an anchor");return}else{const n=await i.createAnchor(e.viewerPose.transform);e.running&&n&&(this._anchor=n)}}applyViewBasedTransform(e){const i=this.context.mainCamera,n=e,o=i.worldPosition,a=n.worldPosition;this.upVec.set(0,1,0).applyQuaternion(e.quaternion);const l=i.worldPosition;l&&e.position.clone().sub(l).angleTo(this.upVec)<Math.PI/2&&this.upVec.negate();const c=this.upVec.angleTo(this.worldUpVec)*180/Math.PI,d=30;c>d&&c<180-d||c<-d&&c>-180+d?(this.lookPoint.copy(e.position).add(this.upVec),this.lookPoint.y=e.position.y,e.lookAt(this.lookPoint)):(o.y=a.y,e.lookAt(o))}onApplyPose(e){var o,a,l,c;const i=(a=(o=q.active)==null?void 0:o.rig)==null?void 0:a.gameObject;if(!i){console.warn("No rig object to place");return}(l=q.active)!=null&&l.rigScale;const n=i.parent||this.context.scene;this._rigPlacementMatrix?(c=this._rigPlacementMatrix)==null||c.decompose(i.position,i.quaternion,i.scale):this._rigPlacementMatrix=i.matrix.clone(),this.applyViewBasedTransform(e),e.updateMatrix(),this.context.scene.add(e),e.attach(i),e.removeFromParent(),i.scale.set(this.arScale,this.arScale,this.arScale),i.position.multiplyScalar(this.arScale),i.updateMatrix(),this.invertForward&&i.matrix.premultiply(FM),i.matrix.premultiply(this._startOffset),i.matrix.decompose(i.position,i.quaternion,i.scale),n.add(i)}}r(Cs,"_eventListeners",{});const _u=class{constructor(t){r(this,"oneFingerDrag",!0);r(this,"twoFingerRotate",!0);r(this,"twoFingerScale",!0);r(this,"factor",1);r(this,"context");r(this,"offset");r(this,"plane");r(this,"_scale",1);r(this,"_hasChanged",!1);r(this,"_enabled",!1);r(this,"currentlyUsedPointerIds",new Set);r(this,"currentlyUnusedPointerIds",new Set);r(this,"onPointerDownEarly",t=>{this.isActive&&t.stopPropagation()});r(this,"onPointerDownLate",t=>{t.used?this.currentlyUsedPointerIds.add(t.pointerId):this.currentlyUsedPointerIds.size<=0&&this.currentlyUnusedPointerIds.add(t.pointerId)});r(this,"onPointerUpEarly",t=>{this.currentlyUsedPointerIds.delete(t.pointerId),this.currentlyUnusedPointerIds.delete(t.pointerId)});r(this,"prev",new Map);r(this,"_didMultitouch",!1);r(this,"touchStart",t=>{if(!t.defaultPrevented)for(let e=0;e<t.changedTouches.length;e++){const i=t.changedTouches[e],n=exports.DeviceUtilities.isAndroidDevice()&&i.clientY<window.innerHeight*.1;this.prev.has(i.identifier)||this.prev.set(i.identifier,{ignore:n,x:0,z:0,screenx:0,screeny:0});const o=this.prev.get(i.identifier);if(o){const a=this.getPositionOnPlane(i.clientX,i.clientY);o.x=a.x,o.z=a.z,o.screenx=i.clientX,o.screeny=i.clientY}}});r(this,"touchEnd",t=>{t.touches.length<=0&&(this._didMultitouch=!1);for(let e=0;e<t.changedTouches.length;e++){const i=t.changedTouches[e];this.prev.delete(i.identifier)}});r(this,"touchMove",t=>{if(!t.defaultPrevented&&this.isActive){if(t.touches.length===1){if(this._didMultitouch)return;const e=t.touches[0],i=this.prev.get(e.identifier);if(!i||i.ignore)return;const n=this.getPositionOnPlane(e.clientX,e.clientY),o=n.x-i.x,a=n.z-i.z;if(o===0&&a===0)return;this.oneFingerDrag&&this.addMovement(o,a),i.x=n.x,i.z=n.z,i.screenx=e.clientX,i.screeny=e.clientY;return}else if(t.touches.length===2){this._didMultitouch=!0;const e=t.touches[0],i=t.touches[1],n=this.prev.get(e.identifier),o=this.prev.get(i.identifier);if(!n||!o)return;if(this.twoFingerRotate){const a=Math.atan2(e.clientY-i.clientY,e.clientX-i.clientX),l=Math.atan2(n.screeny-o.screeny,n.screenx-o.screenx),c=a-l;Math.abs(c)>.001&&this.addRotation(c)}if(this.twoFingerScale){const a=e.clientX-i.clientX,l=e.clientY-i.clientY,c=Math.sqrt(a*a+l*l),d=n.screenx-o.screenx,u=n.screeny-o.screeny,f=Math.sqrt(d*d+u*u),m=c-f;Math.abs(m)>2&&this.addScale(m)}n.screenx=e.clientX,n.screeny=e.clientY,o.screenx=i.clientX,o.screeny=i.clientY}}});r(this,"_raycaster",new h.Raycaster);r(this,"_intersection",new h.Vector3);r(this,"_screenPos",new h.Vector3);r(this,"_tempMatrix",new h.Matrix4);this.context=t,this.offset=new h.Matrix4,this.plane=new h.Plane,this.plane.setFromNormalAndCoplanarPoint(_u.up,_u.zero)}reset(){this._scale=1,this.offset.identity()}get hasChanged(){return this._hasChanged}applyMatrixTo(t,e){this._hasChanged=!1,e?(this.offset.invert(),t.premultiply(this.offset)):t.multiply(this.offset)}get isActive(){return this.currentlyUsedPointerIds.size<=0&&this.currentlyUnusedPointerIds.size>0}enable(){this._enabled||(this._enabled=!0,this.context.input.addEventListener("pointerdown",this.onPointerDownEarly,{queue:_i.Early}),this.context.input.addEventListener("pointerdown",this.onPointerDownLate,{queue:_i.Late}),this.context.input.addEventListener("pointerup",this.onPointerUpEarly,{queue:_i.Early}),window.addEventListener("touchstart",this.touchStart,{passive:!1}),window.addEventListener("touchmove",this.touchMove,{passive:!1}),window.addEventListener("touchend",this.touchEnd,{passive:!1}))}disable(){this._enabled&&(this._enabled=!1,this.context.input.removeEventListener("pointerdown",this.onPointerDownEarly,{queue:_i.Early}),this.context.input.removeEventListener("pointerdown",this.onPointerDownLate,{queue:_i.Late}),this.context.input.removeEventListener("pointerup",this.onPointerUpEarly,{queue:_i.Early}),window.removeEventListener("touchstart",this.touchStart),window.removeEventListener("touchmove",this.touchMove),window.removeEventListener("touchend",this.touchEnd))}getPositionOnPlane(t,e){const i=this.context.mainCamera;return this._screenPos.x=t/window.innerWidth*2-1,this._screenPos.y=-(e/window.innerHeight)*2+1,this._screenPos.z=1,this._screenPos.unproject(i),this._raycaster.set(i.position,this._screenPos.sub(i.position)),this._raycaster.ray.intersectPlane(this.plane,this._intersection),this._intersection}addMovement(t,e){t/=this._scale,e/=this._scale,t*=this.factor,e*=this.factor,this.offset.elements[12]+=t,this.offset.elements[14]+=e,(t!==0||e!==0)&&(this._hasChanged=!0)}addScale(t){t/=window.innerWidth,t*=-1,this._scale*=1+t,this._tempMatrix.makeScale(1-t,1-t,1-t),this.offset.premultiply(this._tempMatrix),t!==0&&(this._hasChanged=!0)}addRotation(t){t*=-1,this._tempMatrix.makeRotationY(t),this.offset.premultiply(this._tempMatrix),t!==0&&(this._hasChanged=!0)}};let ua=_u;r(ua,"up",new h.Vector3(0,1,0)),r(ua,"zero",new h.Vector3(0,0,0)),r(ua,"one",new h.Vector3(1,1,1));const Qs=S("debugautosync"),ap=Symbol("syncerId");class UM{constructor(){r(this,"_syncers",{})}getOrCreateSyncer(t){if(!t.guid)return null;if(this._syncers[t.guid])return this._syncers[t.guid];const e=new zM(t);return e[ap]=t.guid,this._syncers[e[ap]]=e,e}removeSyncer(t){delete this._syncers[t[ap]]}}const Qg=new UM;class zM{constructor(t){r(this,"comp");r(this,"hasChanges",!1);r(this,"changedProperties",{});r(this,"_isReceiving",!1);r(this,"_isInit",!1);r(this,"onHandleSending",()=>{if(!this.hasChanges)return;this.hasChanges=!1;const t=this.comp.context.connection;if(!t||!t.isConnected||!t.isInRoom){for(const e in this.changedProperties)delete this.changedProperties[e];return}for(const e in this.changedProperties){const i=this.changedProperties[e];Qs&&console.log("SEND",this.comp.guid,this.networkingKey),t.send(this.networkingKey,{guid:this.comp.guid,property:e,data:i},rn.Queued),delete this.changedProperties[e]}});r(this,"onHandleReceiving",t=>{if(Qs&&console.log("SYNCFIELD RECEIVE",this.comp.name,this.comp.guid,t),!!this._isInit&&this.comp&&t.guid===this.comp.guid)try{this._isReceiving=!0,this.comp[t.property]=t.data}catch(e){console.error(e)}finally{this._isReceiving=!1}});this.comp=t}get networkingKey(){return this.comp.guid}init(t){if(this._isInit)return;this._isInit=!0,this.comp=t,this.comp.context.post_render_callbacks.push(this.onHandleSending),this.comp.context.connection.beginListen(this.networkingKey,this.onHandleReceiving);const e=this.comp.context.connection.tryGetState(this.comp.guid);e&&this.onHandleReceiving(e)}destroy(){this._isInit&&(this.comp.context.post_render_callbacks.splice(this.comp.context.post_render_callbacks.indexOf(this.onHandleSending),1),this.comp.context.connection.stopListen(this.networkingKey,this.onHandleReceiving),this.comp=null,this._isInit=!1)}notifyChanged(t,e){this._isReceiving||(Qs&&console.log("Property changed: "+t,e),this.hasChanges=!0,this.changedProperties[t]=e)}}function NM(s,t){let e=t!==s;return!e&&s&&t&&(Array.isArray(s)&&Array.isArray(t)||typeof s=="object"&&typeof t=="object")&&(e=!0),e}const lc=Symbol("AutoSyncHandler");function VM(s){if(s[lc])return s[lc];const t=Qg.getOrCreateSyncer(s);return t==null||t.init(s),s[lc]=t,t}function $M(s){const t=s[lc];t&&(Qg.removeSyncer(t),t.destroy(),delete s[lc])}const Yg=function(s=null){return function(t,e){var u;let i="";typeof e=="string"?i=e:i=e.name;let n=null,o;typeof s=="string"?o=t[s]:typeof s=="function"&&(o=s),o==null&&(B()||Qs)&&s!=null&&console.warn('syncField: no callback function found for property "'+i+'"','"'+s+'"');const a=t,l=a.__internalAwake;if(typeof l!="function"){(Qs||B())&&console.error('@syncField can currently only used on Needle Engine Components, custom object of type "'+((u=t==null?void 0:t.constructor)==null?void 0:u.name)+'" is not supported',t);return}Qs&&console.log(i);const c=Symbol(i);a.__internalAwake=function(){if(this[c]!==void 0)return;this[c]=this[i],n=Qg.getOrCreateSyncer(this);const f=Object.getOwnPropertyDescriptor(this,i);if((f==null?void 0:f.set)===void 0){let m=!1;Object.defineProperty(this,i,{set:function(g){var y;const _=this[c];if(this[c]=g,m){(B()||Qs)&&console.warn("Recursive call detected",i);return}m=!0;try{const b=NM(g,_);Qs&&console.log("SyncField assignment",i,"changed?",b,g,o),b&&(o==null?void 0:o.call(this,g,_))!==!1&&((y=VM(this))==null||y.notifyChanged(i,g))}finally{m=!1}},get:function(){return this[c]},configurable:!0,enumerable:!0})}n==null||n.init(this),l.call(this)};const d=a.__internalDestroy;a.__internalDestroy=function(){$M(this),d.call(this)}}};var WM=Object.defineProperty,HM=Object.getOwnPropertyDescriptor,Ku=(s,t,e,i)=>{for(var n=i>1?void 0:i?HM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&WM(t,e,n),n};const Nt=S("debugplayersync"),Pw=class extends D{constructor(){super(...arguments);r(this,"autoSync",!0);r(this,"asset");r(this,"onPlayerSpawned");r(this,"_localInstance");r(this,"onJoinedRoom",()=>{Nt&&console.log("PlayerSync.joinedRoom. autoSync is set to "+this.autoSync),this.autoSync&&this.getInstance()});r(this,"destroyInstance",()=>{var t;(t=this._localInstance)==null||t.then(e=>{Nt&&console.log("PlayerSync.destroyInstance",e),Xc(e,this.context.connection,!0,{saveInRoom:!1})}),this._localInstance=void 0})}static async setupFrom(t,e){const i=ee.getOrCreateFromUrl(t);if(!i.asset){const a=await i.loadAssetAsync();a&&C.getOrAddComponent(a,wi)}const n=new Pw;n._internalInit(e),n.asset=i;const o=new h.Object3D;return o.guid=t,C.addComponent(o,n),n}awake(){this.watchTabVisible(),this.onPlayerSpawned||(this.onPlayerSpawned=new fe)}onEnable(){this.context.connection.beginListen(Z.RoomStateSent,this.onJoinedRoom),this.context.connection.beginListen(Z.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(Z.LeftRoom,this.destroyInstance),this.context.connection.isInRoom&&this.onJoinedRoom()}onDisable(){this.context.connection.stopListen(Z.RoomStateSent,this.onJoinedRoom),this.context.connection.stopListen(Z.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(Z.LeftRoom,this.destroyInstance)}async getInstance(){var e,i,n,o,a,l;if(this._localInstance)return this._localInstance;if(Nt&&console.log("PlayerSync.createInstance",(e=this.asset)==null?void 0:e.url),!((i=this.asset)!=null&&i.asset)&&!((n=this.asset)!=null&&n.url))return console.error('PlayerSync: can not create an instance because "asset" is not set and or has no URL!'),null;this.gameObject.guid||console.warn("PlayerSync: gameObject has no guid! This might cause issues with syncing the player state."),this._localInstance=(o=this.asset)==null?void 0:o.instantiateSynced({parent:this.gameObject,deleteOnDisconnect:!0},!0);const t=await this._localInstance;if(t){const c=C.getComponentsInChildren(t,wi);if(Nt&&console.log(`PlayerSync.createInstance: found ${c==null?void 0:c.length} PlayerState components. Owner: ${this.context.connection.connectionId}`),c!=null&&c.length){for(const d of c)d.owner=this.context.connection.connectionId;(a=this.onPlayerSpawned)==null||a.invoke(t)}else this._localInstance=void 0,console.error("<strong>Failed finding PlayerState on "+((l=this.asset)==null?void 0:l.url)+"</strong>: please make sure the asset has a PlayerState component!"),C.destroySynced(t)}else this._localInstance=void 0,console.warn("PlayerSync: failed instantiating asset!");return this._localInstance}watchTabVisible(){window.addEventListener("visibilitychange",t=>{if(document.visibilityState==="visible")for(let e=wi.all.length-1;e>=0;e--){const i=wi.all[e];(!i.owner||!this.context.connection.userIsInRoom(i.owner))&&i.doDestroy()}})}};let tl=Pw;Ku([p()],tl.prototype,"autoSync",2);Ku([p(ee)],tl.prototype,"asset",2);Ku([p(fe)],tl.prototype,"onPlayerSpawned",2);var Ow=(s=>(s.OwnerChanged="ownerChanged",s))(Ow||{}),Al;const gt=(Al=class extends D{constructor(){super(...arguments);r(this,"onOwnerChangeEvent",new fe);r(this,"onFirstOwnerChangeEvent",new fe);r(this,"hasOwner",!1);r(this,"owner");r(this,"dontDestroy",!1);r(this,"onUserLeftRoom",t=>{if(t.userId===this.owner){Nt&&console.log("PLAYERSYNC LEFT",this.owner),this.doDestroy();return}})}static get all(){return gt._all}static get local(){return gt._local}static getFor(t){if(t instanceof h.Object3D)return C.getComponentInParent(t,gt);if(t instanceof D)return C.getComponentInParent(t.gameObject,gt)}static isLocalPlayer(t){const e=gt.getFor(t);return(e==null?void 0:e.isLocalPlayer)??!1}static addEventListener(t,e){return this._callbacks[t]||(this._callbacks[t]=[]),this._callbacks[t].push(e),e}static removeEventListener(t,e){if(!this._callbacks[t])return;const i=this._callbacks[t].indexOf(e);i>=0&&this._callbacks[t].splice(i,1)}static dispatchEvent(t,e){if(this._callbacks[t])for(const i of this._callbacks[t])i(e)}get isLocalPlayer(){return this.owner===this.context.connection.connectionId}onOwnerChange(t,e){var a,l;Nt&&console.log(`PlayerSync.onOwnerChange: ${e} → ${t} (me: ${this.context.connection.connectionId})`);const i=gt._local.indexOf(this);i>=0&&gt._local.splice(i,1);const n={playerState:this,oldValue:e,newValue:t};if(this.hasOwner||(this.hasOwner=!0,(a=this.onFirstOwnerChangeEvent)==null||a.invoke(n)),(l=this.onOwnerChangeEvent)==null||l.invoke(n),this.owner===this.context.connection.connectionId){gt._local.push(this);const c=new CustomEvent("local-owner-changed",{detail:n});this.dispatchEvent(c)}const o=new CustomEvent("owner-changed",{detail:n});this.dispatchEvent(o),gt.dispatchEvent("ownerChanged",o)}awake(){gt.all.push(this),Nt&&console.log("Registered new PlayerState",this.guid,gt.all.length-1,gt.all),this.context.connection.beginListen(Z.UserLeftRoom,this.onUserLeftRoom)}async start(){Nt&&console.log("PLAYERSTATE.START, owner: "+this.owner,this.context.connection.usersInRoom([])),this.owner?(this.context.connection.isInRoom||await un(300),this.context.connection.userIsInRoom(this.owner)==!1&&(Nt&&console.log(`PlayerSync.start → doDestroy "${this.name}" because user "${this.owner}" is not in room anymore...`,"Currently in room:",...this.context.connection.usersInRoom()),this.doDestroy())):this.owner||(Nt&&console.warn("PlayerState.start → owner is undefined!",this.name),setTimeout(()=>{!this.destroyed&&!this.owner?this.dontDestroy?Nt&&console.warn("PlayerState.start → owner is still undefined but dontDestroy is set to true",this.name):(Nt&&console.warn(`PlayerState.start → owner is still undefined: destroying "${this.name}" instance now`),this.doDestroy()):Nt&&console.log("PlayerState.start → owner is assigned",this.owner)},2e3))}doDestroy(){Nt&&console.log("PlayerSync.doDestroy → syncDestroy",this.name),Xc(this.gameObject,this.context.connection,!0,{saveInRoom:!1})}onDestroy(){if(Nt&&console.warn("PlayerState.onDestroy",this.owner),this.context.connection.stopListen(Z.UserLeftRoom,this.onUserLeftRoom),gt.all.splice(gt.all.indexOf(this),1),this.isLocalPlayer){const t=gt._local.indexOf(this);t>=0&&gt._local.splice(t,1)}}},r(Al,"_all",[]),r(Al,"_local",[]),r(Al,"_callbacks",{}),Al);let wi=gt;Ku([Yg(wi.prototype.onOwnerChange)],wi.prototype,"owner",2);var GM=Object.defineProperty,qM=Object.getOwnPropertyDescriptor,il=(s,t,e,i)=>{for(var n=i>1?void 0:i?qM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&GM(t,e,n),n};class qn extends D{constructor(){super(...arguments);r(this,"position","bottom");r(this,"showNeedleLogo",!0);r(this,"showSpatialMenu");r(this,"createFullscreenButton");r(this,"createMuteButton");r(this,"createQRCodeButton")}onEnable(){this.applyOptions()}applyOptions(){this.context.menu.setPosition(this.position),this.context.menu.showNeedleLogo(this.showNeedleLogo),this.createFullscreenButton===!0&&this.context.menu.showFullscreenOption(!0),this.createMuteButton===!0&&this.context.menu.showAudioPlaybackOption(!0),this.showSpatialMenu===!0&&this.context.menu.showSpatialMenu(this.showSpatialMenu),this.createQRCodeButton===!0&&(exports.DeviceUtilities.isMobileDevice()||this.context.menu.showQRCodeButton(!0))}}il([p()],qn.prototype,"position",2);il([p()],qn.prototype,"showNeedleLogo",2);il([p()],qn.prototype,"showSpatialMenu",2);il([p()],qn.prototype,"createFullscreenButton",2);il([p()],qn.prototype,"createMuteButton",2);il([p()],qn.prototype,"createQRCodeButton",2);var XM=Object.defineProperty,QM=Object.getOwnPropertyDescriptor,Kg=(s,t,e,i)=>{for(var n=i>1?void 0:i?QM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&XM(t,e,n),n};const Cl=S("debugwebxr"),ob=new h.Quaternion().setFromAxisAngle(new h.Vector3(0,1,0),Math.PI);class po extends D{constructor(){super(...arguments);r(this,"head");r(this,"leftHand");r(this,"rightHand");r(this,"_leftHandMeshes");r(this,"_rightHandMeshes");r(this,"_syncTransforms")}async onEnterXR(e){if(!this.activeAndEnabled)return;Cl&&console.warn("AVATAR ENTER XR",this.guid,this.sourceId,this,this.activeAndEnabled),this._syncTransforms&&(this._syncTransforms.length=0),await this.prepareAvatar();const i=wi.getFor(this);if(i!=null&&i.owner){const n=this.gameObject.addComponent(it);n.avatar=this.gameObject,n.connectionId=i.owner}else this.context.connection.isConnected?console.error("No player state found for avatar",this):i&&!this.context.connection.isConnected&&(i.dontDestroy=!0)}onLeaveXR(e){const i=this.gameObject.getComponent(it);i&&i.destroy()}onUpdateXR(e){var d,u;if(!this.activeAndEnabled)return;const i=wi.isLocalPlayer(this);if(!i)return;const n=e.xr;if(n.rig&&n.rig.gameObject!==this.gameObject.parent&&(this.gameObject.position.set(0,0,0),this.gameObject.rotation.set(0,0,0),this.gameObject.scale.set(1,1,1),n.rig.gameObject.add(this.gameObject)),this._syncTransforms&&i)for(const f of this._syncTransforms)f.fastMode=!0,f.isOwned()||f.requestOwnership();if(this.head&&this.context.mainCamera){const f=this.head.asset;if(f.position.copy(this.context.mainCamera.position),f.position.x*=-1,f.position.z*=-1,f.quaternion.copy(this.context.mainCamera.quaternion),f.quaternion.x*=-1,this.context.time.frameCount%10===0&&this.head.asset){const m=C.getComponentsInChildren(this.head.asset,yi);for(const g of m)g.enabled=!1,g.gameObject.visible=!1}}const o=e.xr.leftController,a=(d=this.leftHand)==null?void 0:d.asset;o&&a?(a.position.copy(o.gripPosition),a.quaternion.copy(o.gripQuaternion),a.quaternion.multiply(ob),a.visible=o.isTracking,this.updateHandVisibility(o,a,this._leftHandMeshes)):a&&a.visible&&(a.visible=!1);const l=e.xr.rightController,c=(u=this.rightHand)==null?void 0:u.asset;l&&c?(c.position.copy(l.gripPosition),c.quaternion.copy(l.gripQuaternion),c.quaternion.multiply(ob),c.visible=l.isTracking,this.updateHandVisibility(l,c,this._rightHandMeshes)):c&&c.visible&&(c.visible=!1)}onBeforeRender(){this.context.xr&&this.context.time.frame%10===0&&this.updateRemoteAvatarVisibility()}updateHandVisibility(e,i,n){if(n){const o=e.model&&e.model.visible&&e.model!==i;n.forEach(a=>{ps(a,!o)})}}updateRemoteAvatarVisibility(){var e,i,n;if(this.context.connection.isConnected){const o=wi.getFor(this);if(o&&o.isLocalPlayer==!1){const a=q.getXRSync(this.context);if(a&&a.hasState(o.owner)){this.tryFindAvatarObjectsIfMissing();const l=(e=this.leftHand)==null?void 0:e.asset;l&&(l.visible=(a==null?void 0:a.isTracking(o.owner,"left"))??!1);const c=(i=this.rightHand)==null?void 0:i.asset;c&&(c.visible=(a==null?void 0:a.isTracking(o.owner,"right"))??!1)}if((n=this.head)!=null&&n.asset){const l=C.getComponentsInChildren(this.head.asset,yi);for(const c of l)c.enabled=!1,c.gameObject.visible=!0}}}}tryFindAvatarObjectsIfMissing(){if(!this.head||!this.leftHand||!this.rightHand){const e={head:this.head,leftHand:this.leftHand,rightHand:this.rightHand};Cv.tryFindAvatarObjects(this.gameObject,this.sourceId||"",e),e.head&&(this.head=e.head),e.leftHand&&(this.leftHand=e.leftHand),e.rightHand&&(this.rightHand=e.rightHand)}}async prepareAvatar(){var e,i;if(this.tryFindAvatarObjectsIfMissing(),this.head)this.head instanceof h.Object3D&&(this.head=new ee("",this.sourceId,this.head));else{const n=new h.Object3D;n.name="Head";const o=vo.createPrimitive(gr.Cube);n.add(o),this.gameObject.add(n),this.head=new ee("",this.sourceId,n),Cl&&console.log("Create head",n)}if(this.rightHand)this.rightHand instanceof h.Object3D&&(this.rightHand=new ee("",this.sourceId,this.rightHand));else{const n=new h.Object3D;n.name="Right Hand",this.gameObject.add(n),this.rightHand=new ee("",this.sourceId,n),Cl&&console.log("Create right hand",n)}if(this.leftHand)this.leftHand instanceof h.Object3D&&(this.leftHand=new ee("",this.sourceId,this.leftHand));else{const n=new h.Object3D;n.name="Left Hand",this.gameObject.add(n),this.leftHand=new ee("",this.sourceId,n),Cl&&console.log("Create left hand",n)}await this.loadAvatarObjects(this.head,this.leftHand,this.rightHand),this._leftHandMeshes=[],(e=this.leftHand.asset)==null||e.traverse(n=>{n!=null&&n.isMesh&&this._leftHandMeshes.push(n)}),this._rightHandMeshes=[],(i=this.rightHand.asset)==null||i.traverse(n=>{n!=null&&n.isMesh&&this._rightHandMeshes.push(n)}),wi.isLocalPlayer(this.gameObject)&&(this._syncTransforms=C.getComponentsInChildren(this.gameObject,Nn))}async loadAvatarObjects(e,i,n){const o=e.loadAssetAsync(),a=i.loadAssetAsync(),l=n.loadAssetAsync(),c=new Array;o&&c.push(o),a&&c.push(a),l&&c.push(l);const d=await xu(c);Cl&&console.log("Avatar loaded results:",d)}}Kg([p(ee)],po.prototype,"head",2);Kg([p(ee)],po.prototype,"leftHand",2);Kg([p(ee)],po.prototype,"rightHand",2);var YM=Object.defineProperty,KM=Object.getOwnPropertyDescriptor,Zu=(s,t,e,i)=>{for(var n=i>1?void 0:i?KM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&YM(t,e,n),n};const ts=S("debugwebxr"),Fs=new Array;class Vn extends D{constructor(){super(...arguments);r(this,"createControllerModel",!0);r(this,"createHandModel",!0);r(this,"customLeftHand");r(this,"customRightHand");r(this,"_models",new Array)}supportsXR(e){return e==="immersive-vr"||e==="immersive-ar"}async onXRControllerAdded(e){var o;if(!(e.xr.isVR||e.xr.isPassThrough))return;const{controller:n}=e;if(ts&&console.warn("Add Controller Model for",n.side,n.index),this.createControllerModel||this.createHandModel){if(n.hand){if(this.createHandModel){const a=await this.loadHandModel(this,n);if(!a||!n.connected||!n.isHand){a!=null&&a.handObject&&aa(a.handObject,!1),(o=a==null?void 0:a.handObject)==null||o.destroy();return}this._models.push({controller:n,model:a.handObject,handmesh:a.handmesh}),this._models.sort((l,c)=>l.controller.index-c.controller.index),this.scene.add(a.handObject),n.model=a.handObject}}else if(this.createControllerModel){const a=await n.getModelUrl();if(a){const l=await this.loadModel(n,a);if(!l||!n.connected||n.isHand)return;this._models.push({controller:n,model:l}),this._models.sort((c,d)=>c.controller.index-d.controller.index),this.scene.add(l),l.traverse(c=>{c.layers.set(2),c.matrixAutoUpdate=!1,c.updateMatrix()}),n.model=l}else n.targetRayMode!=="transient-pointer"&&console.warn("XRControllerModel: no model found for "+n.side)}}}onXRControllerRemoved(e){console.debug("XR Controller Removed",e.controller.side,e.controller.index);const i=this._models.findIndex(o=>o.controller===e.controller),n=this._models[i];n&&(this._models.splice(i,1),n.model&&(aa(n.model,!1),n.model.destroy(),n.model=void 0))}onBeforeXR(e,i){this.createHandModel&&(this.customLeftHand||this.customRightHand)&&(i.optionalFeatures=i.optionalFeatures||[],i.optionalFeatures.includes("hand-tracking")||i.optionalFeatures.push("hand-tracking"))}onLeaveXR(e){for(const i of this._models)i&&(i.model&&(aa(i.model,!1),i.model.destroy(),i.model=void 0),i.controller.model===i.model&&(i.controller.model=null));this._models.length=0}onBeforeRender(){if(q.active&&(ts&&(Fs[0]=Date.now()),this.updateRendering(q.active),ts)){const e=Date.now()-Fs[0];Fs.push(e),Fs.length>=30&&(Fs[0]=0,Fs.reduce((i,n)=>i+n,0)/Fs.length,Fs.length=0)}}updateRendering(e){var i,n,o,a,l;for(let c=0;c<this._models.length;c++){const d=this._models[c];if(!d)continue;const u=d.controller;if(!u.connected){ts&&console.warn("XRControllerModel.onUpdateXR: controller is not connected anymore",u.side,u.hand);continue}if(d.model&&!d.handmesh)d.model.matrixAutoUpdate=!1,d.model.matrix.copy(u.gripMatrix),d.model.visible=u.isTracking,(i=e.rig)==null||i.gameObject.add(d.model);else if(u.inputSource.hand&&d.handmesh){const f=e.referenceSpace,m=this.context.renderer.xr.getHand(u.index);if(f&&e.frame.getJointPose){for(const g of u.inputSource.hand.values()){const _=m.joints[g.jointName];if(_){const y=u.getHandJointPose(g);if(y){const b=y.transform.position,v=y.transform.orientation;_.position.copy(b),_.quaternion.copy(v),_.matrixAutoUpdate=!1}_.visible=y!=null}}d.model&&(d.model.visible=u.isTracking,d.model.visible&&d.model.parent!==((n=e.rig)==null?void 0:n.gameObject)&&((o=e.rig)==null||o.gameObject.add(d.model))),(a=d.model)!=null&&a.visible&&((l=d.handmesh)==null||l.updateMesh(),d.model.matrixAutoUpdate=!1,d.model.matrix.identity(),d.model.applyMatrix4(xa))}}}}async loadModel(e,i){var a;if(!e.connected)return console.warn("XRControllerModel.onXRControllerAdded: controller is not connected anymore",e.side),null;const o=await ee.getOrCreate("",i).instantiate();return aa(o),(a=q.active)!=null&&a.isPassThrough&&o.traverseVisible(l=>{this.makeOccluder(l)}),o}async loadHandModel(e,i){const n=this.context,o=n.renderer.xr.getHand(i.index);o||(ts?N.DrawLabel(i.rayWorldPosition,"No hand found for index "+i.index,.05,5):console.warn("No hand found for index "+i.index));const a=new Y.GLTFLoader;Lu(a,n),await ou(a,n,this.sourceId??"");const l=Gu(a);let c="";const d=i.side==="left"?this.customLeftHand:this.customRightHand;d?(c=d.url.split(".").slice(0,-1).join("."),a.setPath("")):(c=i.inputSource.handedness==="left"?"left":"right",a.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/"));const u=new h.Object3D;aa(u);const f=new Y.XRHandMeshModel(u,o,a.path,c,a,m=>{var _;const g=l.gltf;((_=g==null?void 0:g.scene.children)==null?void 0:_.length)===0&&(g.scene.children[0]=m),dn().createBuiltinComponents(e.context,e.sourceId||c,l.gltf,null,l),m.traverse(y=>{var b;y.layers.set(2),(b=q.active)!=null&&b.isPassThrough&&!d&&this.makeOccluder(y),y instanceof h.Mesh&&re.NEEDLE_progressive.assignMeshLOD(y,0)}),i.connected||(ts&&N.DrawLabel(i.rayWorldPosition,"Hand is loaded but not connected anymore",.05,5),m.removeFromParent())});if(ts&&u.add(new h.AxesHelper(.5)),i.inputSource.hand){ts&&console.log(i.inputSource.hand);for(const m of i.inputSource.hand.values())if(o.joints[m.jointName]===void 0){const g=new h.Group;g.matrixAutoUpdate=!1,g.visible=!0,o.joints[m.jointName]=g,o.add(g)}}else ts&&N.DrawLabel(i.rayWorldPosition,"No inputSource.hand found for index "+i.index,.05,5);return{handObject:u,handmesh:f}}makeOccluder(e){if(e instanceof h.Mesh){let i=e.material;i instanceof h.Material&&(i=e.material=i.clone(),i.depthWrite=!0,i.depthTest=!0,i.colorWrite=!1,e.receiveShadow=!1,e.renderOrder=-100)}}}r(Vn,"factory",new Y.XRControllerModelFactory);Zu([p()],Vn.prototype,"createControllerModel",2);Zu([p()],Vn.prototype,"createHandModel",2);Zu([p(ee)],Vn.prototype,"customLeftHand",2);Zu([p(ee)],Vn.prototype,"customRightHand",2);class Ju extends D{}var ZM=Object.defineProperty,JM=Object.getOwnPropertyDescriptor,Mo=(s,t,e,i)=>{for(var n=i>1?void 0:i?JM(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&ZM(t,e,n),n};const lp=S("debugwebxr");class Mi extends D{constructor(){super(...arguments);r(this,"movementSpeed",1.5);r(this,"rotationStep",30);r(this,"useTeleport",!0);r(this,"usePinchToTeleport",!0);r(this,"useTeleportTarget",!1);r(this,"useTeleportFade",!1);r(this,"showRays",!0);r(this,"showHits",!0);r(this,"isXRMovementHandler",!0);r(this,"xrSessionMode","immersive-vr");r(this,"_didApplyRotation",!1);r(this,"_didTeleport",!1);r(this,"_teleportBuffer",new Array);r(this,"_plane",null);r(this,"_lines",[]);r(this,"_hitDiscs",[]);r(this,"_hitDistances",[]);r(this,"_lastHitDistances",[]);r(this,"hitPointRaycastFilter",e=>e.type==="SkinnedMesh"?"continue in children":!0)}onUpdateXR(e){const i=e.xr.rig;if(!(i!=null&&i.gameObject)||e.xr.isPassThrough)return;const n=e.xr.leftController,o=e.xr.rightController;n&&this.onHandleMovement(n,i.gameObject),o&&(this.onHandleRotation(o,i.gameObject),this.useTeleport&&this.onHandleTeleport(o,i.gameObject))}onLeaveXR(e){for(const i of this._lines)i.removeFromParent();for(const i of this._hitDiscs)i==null||i.removeFromParent()}onBeforeRender(){var e;(e=this.context.xr)!=null&&e.running&&(this.showRays&&this.renderRays(this.context.xr),this.showHits&&this.renderHits(this.context.xr))}onHandleMovement(e,i){const n=e.getStick("xr-standard-thumbstick");if(n.x!=0||n.y!=0){const o=V(n.x,0,n.y);o.multiplyScalar(this.context.time.deltaTimeUnscaled*this.movementSpeed);const a=Ne(i);o.multiplyScalar(a.x),o.applyQuaternion(e.xr.poseOrientation),o.y=0,o.applyQuaternion(i.worldQuaternion),i.position.add(o),i.updateWorldMatrix(!1,!1);for(const l of i.children)l.updateWorldMatrix(!1,!1)}}onHandleRotation(e,i){if(e._isMxInk)return;const o=e.getStick("xr-standard-thumbstick").x;if(this._didApplyRotation)Math.abs(o)<.3&&(this._didApplyRotation=!1);else if(Math.abs(o)>.5){this._didApplyRotation=!0;const a=o>0?1:-1,l=K(this.context.mainCamera).clone();i.rotateY(a*z.toRadians(this.rotationStep));const d=K(this.context.mainCamera).clone().sub(l);d.y=0,i.position.sub(d)}}onHandleTeleport(e,i){var o,a,l,c,d;let n=0;if(e.hand&&this.usePinchToTeleport&&e.isTeleportGesture){const u=e.getPointerId("primary");if(u!=null&&this.context.input.getIsPointerIdInUse(u))return;const f=e.getGesture("pinch");f&&(n=f.value)}else n=(o=e.getStick("xr-standard-thumbstick"))==null?void 0:o.y;if(this._didTeleport)n>=0&&n<.4?this._didTeleport=!1:n<0&&n>-.4&&(this._didTeleport=!1);else if(n>.8){this._didTeleport=!0;const u=this.context.physics.raycastFromRay(e.ray)[0];if(u&&u.object instanceof Y.GroundedSkybox){const m=(a=u.normal)==null?void 0:a.dot(V(0,1,0));if(m!==void 0&&m<.4)return}let f=u==null?void 0:u.point;if(!f&&!this.useTeleportTarget){this._plane||(this._plane=new h.Plane(new h.Vector3(0,1,0),0));const m=i.worldPosition;this._plane.setFromNormalAndCoplanarPoint(new h.Vector3(0,1,0),m);const g=e.ray;f=m.clone(),this._plane.intersectLine(new h.Line3(g.origin,V(g.direction).multiplyScalar(1e4).add(g.origin)),f),f.distanceTo(m)>i.scale.x*10&&(f=null)}if(f){if(this.useTeleportTarget&&!C.getComponentInParent(u.object,Ju))return;const m=f.clone();if(lp&&N.DrawSphere(f,.025,16711680,5),(l=this.context.mainCamera)==null?void 0:l.position){const _=(c=this.context.xr)==null?void 0:c.getUserOffsetInRig();_&&(_.y=0,m.sub(_),lp&&N.DrawWireSphere(_.add(m),.025,65280,5))}this._teleportBuffer.push(i.matrix.clone()),this._teleportBuffer.length>10&&this._teleportBuffer.shift(),this.useTeleportFade?(d=e.xr.fadeTransition())==null||d.then(()=>{i.worldPosition=m}):i.worldPosition=m}}else if(n<-.8&&(this._didTeleport=!0,this._teleportBuffer.length>0)){const u=this._teleportBuffer.pop();u&&u.decompose(i.position,i.quaternion,i.scale)}}renderRays(e){var i;for(let n=0;n<this._lines.length;n++){const o=this._lines[n];o&&(o.visible=!1)}for(let n=0;n<e.controllers.length;n++){const o=e.controllers[n];let a=this._lines[n];if(!o.connected||!o.isTracking||!o.ray||o.targetRayMode==="transient-pointer"||!o.hasSelectEvent){a&&(a.visible=!1);continue}a||(a=this.createRayLineObject(),a.scale.z=.5,this._lines[n]=a),o.updateRayWorldPosition(),o.updateRayWorldQuaternion();const l=o.rayWorldPosition,c=o.rayWorldQuaternion;a.position.copy(l),a.quaternion.copy(c);const d=e.rigScale,u=this.usePinchToTeleport&&o.isTeleportGesture,f=this._lastHitDistances[n],m=this._hitDistances[n]!=null,g=f??d;a.scale.set(d,d,g),a.visible=!0,a.layers.disableAll(),a.layers.enable(2);let _=a.material.opacity;u?_=1:this.showHits&&g<e.rigScale*.5?_=0:(i=o.getButton("primary"))!=null&&i.pressed?_=.5:_=m?.2:.1,a.material.opacity=z.lerp(a.material.opacity,_,this.context.time.deltaTimeUnscaled/.1),a.parent!==this.context.scene&&this.context.scene.add(a)}}renderHits(e){var i;for(const n of this._hitDiscs){if(!n)continue;const o=n.controller;if(!o||!o.connected||!o.isTracking){n.visible=!1;continue}}for(let n=0;n<e.controllers.length;n++){const o=e.controllers[n];if(!o.connected||!o.isTracking||!o.ray||!o.hasSelectEvent)continue;let a=this._hitDiscs[n],l=!0;const c=o.getPointerId("primary");c!=null&&this.context.input.getIsPointerIdInUse(c)&&(a&&(a.visible=!1),this._hitDistances[n]=null,this._lastHitDistances[n]=0,l=!1);const d=this.context.time.smoothedFps>=59?1:10;if((this.context.time.frame+o.index)%d!==0&&(l=!1),!l){const m=this._hitDiscs[n];m&&m.visible&&m.hit&&this.updateHitPointerPosition(o,m,m.hit.distance);continue}const u=this.context.physics.raycastFromRay(o.ray,{testObject:this.hitPointRaycastFilter,precise:!1});let f=u.find(m=>this.usePinchToTeleport&&o.isTeleportGesture?!0:this.isObjectWithInteractiveComponent(m.object));if(f||(f=u[0]),a&&(a.controller=o,a.hit=f),this._hitDistances[n]=(f==null?void 0:f.distance)||null,f){this._lastHitDistances[n]=f.distance;const m=e.rigScale??1;lp&&(N.DrawWireSphere(f.point,.025*m,16711680),N.DrawLabel(V(0,.2,0).add(f.point),f.object.name,.02,0)),a||(a=this.createHitPointObject(),this._hitDiscs[n]=a),a.hit=f,a.visible=f.distance>m*.05;let g=.01*(m+f.distance);const _=(i=o.getButton("primary"))==null?void 0:i.pressed;_&&(g*=1.1),a.scale.set(g,g,g),a.layers.set(2);let y=a.material.opacity;if(_?y=1:y=f.distance<.15*m?.2:.6,a.material.opacity=z.lerp(a.material.opacity,y,this.context.time.deltaTimeUnscaled/.1),a.visible){if(f.normal){this.updateHitPointerPosition(o,a,f.distance);const b=f.normal.applyQuaternion(ye(f.object));a.quaternion.setFromUnitVectors(eR,b)}else this.updateHitPointerPosition(o,a,f.distance);a.parent!==this.context.scene&&this.context.scene.add(a)}}else this._hitDiscs[n]&&(this._hitDiscs[n].visible=!1)}}isObjectWithInteractiveComponent(e,i=0){return Jd(e)||e.isUI===!0?!0:e.isScene?!1:e.parent?this.isObjectWithInteractiveComponent(e.parent,i+1):!1}updateHitPointerPosition(e,i,n){const o=V(e.rayWorldPosition);o.add(V(0,0,n-.01).applyQuaternion(e.rayWorldQuaternion)),i.position.lerp(o,this.context.time.deltaTimeUnscaled/.05)}createHitPointObject(){const e=new h.Mesh(new h.SphereGeometry(.3,6,6),new h.MeshBasicMaterial({color:15658734,opacity:.7,transparent:!0,depthTest:!1,depthWrite:!1,side:h.DoubleSide}));return e.layers.disableAll(),e.layers.enable(2),e}createRayLineObject(){const e=new Y.Line2;e.layers.disableAll(),e.layers.enable(2);const i=new Y.LineGeometry;e.geometry=i;const n=new Float32Array(9);n.set([0,0,.02,0,0,.4,0,0,1]),i.setPositions(n);const o=new Float32Array(9);o.set([1,1,1,.1,.1,.1,0,0,0]),i.setColors(o);const a=new Y.LineMaterial({color:16777215,vertexColors:!0,worldUnits:!0,linewidth:.004,transparent:!0,depthWrite:!1,blending:h.AdditiveBlending,dashed:!1});return e.material=a,e}}Mo([p()],Mi.prototype,"movementSpeed",2);Mo([p()],Mi.prototype,"rotationStep",2);Mo([p()],Mi.prototype,"useTeleport",2);Mo([p()],Mi.prototype,"usePinchToTeleport",2);Mo([p()],Mi.prototype,"useTeleportTarget",2);Mo([p()],Mi.prototype,"useTeleportFade",2);Mo([p()],Mi.prototype,"showRays",2);Mo([p()],Mi.prototype,"showHits",2);const eR=new h.Vector3(0,1,0);var tR=Object.defineProperty,iR=Object.getOwnPropertyDescriptor,ut=(s,t,e,i)=>{for(var n=i>1?void 0:i?iR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&tR(t,e,n),n};const Pl=S("debugwebxr"),nR=S("debugusdz");var Tp;const fa=(Tp=class extends D{constructor(){super(...arguments);r(this,"createVRButton",!0);r(this,"createARButton",!0);r(this,"createSendToQuestButton",!0);r(this,"createQRCode",!0);r(this,"useDefaultControls",!0);r(this,"showControllerModels",!0);r(this,"showHandModels",!0);r(this,"usePlacementReticle",!0);r(this,"customARPlacementReticle");r(this,"usePlacementAdjustment",!0);r(this,"arScale",1);r(this,"useXRAnchor",!1);r(this,"autoPlace",!1);r(this,"autoCenter",!1);r(this,"useQuicklookExport",!1);r(this,"useDepthSensing",!1);r(this,"useSpatialGrab",!0);r(this,"defaultAvatar");r(this,"_playerSync");r(this,"_createdComponentsInSession",[]);r(this,"_usdzExporter");r(this,"_exitXRMenuButton");r(this,"_previousXRState",0);r(this,"_spatialGrabRaycaster");r(this,"onAvatarSpawned",t=>{Pl&&console.log("WebXR.onAvatarSpawned",t),C.getComponentInChildren(t,po)??(e=C.addComponent(t,po))});r(this,"_buttonFactory");r(this,"_buttons",[])}awake(){q.getXRSync(this.context)}onEnable(){var t,e;window.location.protocol!=="https:"&&me('<a href="https://developer.mozilla.org/en-US/docs/Web/API/WebXR_Device_API" target="_blank">WebXR</a> only works on secure connections (https).'),this.useQuicklookExport&&(C.findObjectOfType(Ie)||(Pl&&console.log("WebXR: Adding USDZExporter"),this._usdzExporter=C.addComponent(this.gameObject,Ie),this._usdzExporter.objectToExport=this.context.scene,this._usdzExporter.autoExportAnimations=!0,this._usdzExporter.autoExportAudioSources=!0)),this.handleCreatingHTML(),this.handleOfferSession(),this.defaultAvatar===!0&&(Pl&&console.warn("WebXR: No default avatar set, using static default avatar"),this.defaultAvatar=new ee("https://cdn.needle.tools/static/avatars/DefaultAvatar.glb")),this.defaultAvatar&&(this._playerSync=this.gameObject.getOrAddComponent(tl),this._playerSync.autoSync=!1),this._playerSync&&typeof this.defaultAvatar!="boolean"&&(this._playerSync.asset=this.defaultAvatar,(t=this._playerSync.onPlayerSpawned)==null||t.removeEventListener(this.onAvatarSpawned),(e=this._playerSync.onPlayerSpawned)==null||e.addEventListener(this.onAvatarSpawned))}onDisable(){var t;(t=this._usdzExporter)==null||t.destroy(),this.removeButtons()}async handleOfferSession(){return this.createVRButton&&await q.isVRSupported()&&this.createVRButton?q.offerSession("immersive-vr","default",this.context):this.createARButton&&await q.isARSupported()&&this.createARButton?q.offerSession("immersive-ar","default",this.context):!1}get session(){return q.active??null}get sessionMode(){return q.activeMode??null}async enterVR(t){return q.start("immersive-vr",t,this.context)}async enterAR(t){return q.start("immersive-ar",t,this.context)}exitXR(){q.stop()}get isActiveWebXR(){return!fa.activeWebXRComponent||fa.activeWebXRComponent===this}onBeforeXR(t,e){var i;if(!this.isActiveWebXR){console.warn(`WebXR: another WebXR component is already active (${(i=fa.activeWebXRComponent)==null?void 0:i.name}). This is ignored: ${this.name}`);return}fa.activeWebXRComponent=this,t=="immersive-ar"&&this.useDepthSensing&&(e.optionalFeatures=e.optionalFeatures||[],e.optionalFeatures.push("depth-sensing"))}async onEnterXR(t){if(!this.isActiveWebXR)return;Pl&&console.log("WebXR onEnterXR"),this._previousXRState=vt.Global.Mask;const e=t.xr.isVR;if(vt.Global.Set(e?Tn.VR:Tn.AR),t.xr.isAR){let i=C.findObjectOfType(Cs);if(!i)if(this.usePlacementReticle){const n=new h.Object3D;for(const o of this.context.scene.children)n.add(o);this.context.scene.add(n),i=C.addComponent(n,Cs),this._createdComponentsInSession.push(i)}else(Pl||B())&&console.warn("WebXR: No WebARSessionRoot found in scene and usePlacementReticle is disabled in WebXR component.");i&&(i.customReticle=this.customARPlacementReticle,i.arScale=this.arScale,i.arTouchTransform=this.usePlacementAdjustment,i.autoPlace=this.autoPlace,i.autoCenter=this.autoCenter,i.useXRAnchor=this.useXRAnchor)}this.useDefaultControls&&this.setDefaultMovementEnabled(!0),(this.showControllerModels||this.showHandModels)&&this.setDefaultControllerRenderingEnabled(!0),this.useSpatialGrab&&(this._spatialGrabRaycaster=C.findObjectOfType(ro)??void 0,this._spatialGrabRaycaster||(this._spatialGrabRaycaster=this.gameObject.addComponent(ro))),this.createLocalAvatar(t.xr),t.xr.isScreenBasedAR||(this._exitXRMenuButton=this.context.menu.appendChild({label:"Quit XR",onClick:()=>this.exitXR(),icon:"exit_to_app",priority:2e4}))}onUpdateXR(t){this.isActiveWebXR&&this._spatialGrabRaycaster&&(this._spatialGrabRaycaster.enabled=this.useSpatialGrab)}onLeaveXR(t){var e,i;if((e=this._exitXRMenuButton)==null||e.remove(),!!this.isActiveWebXR){vt.Global.Set(this._previousXRState),(i=this._playerSync)==null||i.destroyInstance();for(const n of this._createdComponentsInSession)n.destroy();this._createdComponentsInSession.length=0,this.handleOfferSession(),Vc(1).then(()=>fa.activeWebXRComponent=null)}}setDefaultMovementEnabled(t){let e=this.gameObject.getComponent(Mi);return!e&&t&&(e=this.gameObject.addComponent(Mi),this._createdComponentsInSession.push(e)),e&&(e.enabled=t),e}setDefaultControllerRenderingEnabled(t){let e=this.gameObject.getComponent(Vn);return!e&&t&&(e=this.gameObject.addComponent(Vn),this._createdComponentsInSession.push(e),e.createControllerModel=this.showControllerModels,e.createHandModel==this.showHandModels),e&&(e.enabled=t),e}async createLocalAvatar(t){this._playerSync&&t.running&&typeof this.defaultAvatar!="boolean"&&(this._playerSync.asset=this.defaultAvatar,await this._playerSync.getInstance())}getButtonsContainer(){return this.getButtonsFactory()}getButtonsFactory(){return this._buttonFactory||(this._buttonFactory=ws.getOrCreate()),this._buttonFactory}handleCreatingHTML(){if(this.createARButton||this.createVRButton||this.useQuicklookExport){if((exports.DeviceUtilities.isiOS()&&exports.DeviceUtilities.isSafari()||nR)&&this.useQuicklookExport){const e=C.findObjectOfType(Ie);if(!e||e&&e.allowCreateQuicklookButton){const i=this.getButtonsFactory().createQuicklookButton();this.addButton(i,50)}}if(this.createARButton){const e=this.getButtonsFactory().createARButton();this.addButton(e,50)}if(this.createVRButton){const e=this.getButtonsFactory().createVRButton();this.addButton(e,50)}}if(this.createSendToQuestButton&&!exports.DeviceUtilities.isQuest()&&q.isVRSupported().then(e=>{if(!e){const i=this.getButtonsFactory().createSendToQuestButton();this.addButton(i,50)}}),this.createQRCode){const e=ku(qn);if(e&&e.createQRCodeButton===!1)B()&&console.warn("WebXR: QRCode button is disabled in the Needle Menu component");else if(!exports.DeviceUtilities.isMobileDevice()){const i=an.getOrCreate().createQRCode();this.addButton(i,50)}}}addButton(t,e){this._buttons.push(t),t.setAttribute("priority",e.toString()),this.context.menu.appendChild(t)}removeButtons(){for(const t of this._buttons)t.remove();this._buttons.length=0}},r(Tp,"activeWebXRComponent",null),Tp);let $e=fa;ut([p()],$e.prototype,"createVRButton",2);ut([p()],$e.prototype,"createARButton",2);ut([p()],$e.prototype,"createSendToQuestButton",2);ut([p()],$e.prototype,"createQRCode",2);ut([p()],$e.prototype,"useDefaultControls",2);ut([p()],$e.prototype,"showControllerModels",2);ut([p()],$e.prototype,"showHandModels",2);ut([p()],$e.prototype,"usePlacementReticle",2);ut([p(ee)],$e.prototype,"customARPlacementReticle",2);ut([p()],$e.prototype,"usePlacementAdjustment",2);ut([p()],$e.prototype,"arScale",2);ut([p()],$e.prototype,"useXRAnchor",2);ut([p()],$e.prototype,"autoPlace",2);ut([p()],$e.prototype,"autoCenter",2);ut([p()],$e.prototype,"useQuicklookExport",2);ut([p()],$e.prototype,"useDepthSensing",2);ut([p()],$e.prototype,"useSpatialGrab",2);ut([p(ee)],$e.prototype,"defaultAvatar",2);const Gl=S("debugusdz");function sR(s,t){var l;const e=[],i=C.getComponentsInChildren(s,St),n=C.getComponentsInChildren(s,Et),o=new Array,a=new Array;if(t.injectImplicitBehaviours)for(const c of i){if(!c||!c.runtimeAnimatorController||!c.enabled)continue;const d=c.runtimeAnimatorController.activeState;if(!d||!d.motion||!d.motion.clip||((l=d.motion.clip.tracks)==null?void 0:l.length)<1||o.includes(c))continue;const u=new wr;u.animator=c,u.stateName=d.name,u.trigger="start",u.name="PlayAnimationOnClick_implicitAtStart_"+u.stateName;const f=new h.Object3D;C.addComponent(f,u),a.push(f),o.push(c),s.add(f)}else for(const c of i){if(!c||!c.runtimeAnimatorController||!c.enabled)continue;Gl&&console.log(c);const d=[];for(const u of c.runtimeAnimatorController.enumerateActions()){Gl&&console.log(u);const f=u.getClip();d.includes(f)||d.push(f)}e.push({root:c.gameObject,clips:d})}if(t.injectImplicitBehaviours)for(const c of n){if(!c||!c.clip||!c.enabled||!c.playAutomatically||o.includes(c))continue;const d=new wr;d.animation=c,d.stateName=c.clip.name,d.trigger="start",d.name="PlayAnimationOnClick_implicitAtStart_"+d.stateName;const u=new h.Object3D;C.addComponent(u,d),a.push(u),o.push(c),s.add(u)}else for(const c of n){Gl&&console.log(c);const d=[];for(const u of c.animations)d.includes(u)||d.push(u);e.push({root:c.gameObject,clips:d})}Gl&&(e==null?void 0:e.length)>0&&console.log("USDZ Animation Clips without behaviours",e);for(const c of e)for(const d of c.clips)t.registerAnimation(c.root,d);return a}function oR(s,t){const e=C.getComponentsInChildren(s,je),i=C.getComponentsInChildren(s,ho),n=new Array,o=new Array;Gl&&console.log({audioSources:e,playAudioOnClicks:i});for(const a of i){if(!a.target)continue;const l=e.indexOf(a.target);l>-1&&e.splice(l,1)}for(const a of e){if(!a||!a.clip||a.volume<=0||n.includes(a))continue;const l=new ho;l.target=a,l.name="PlayAudioOnClick_implicitAtStart_",l.trigger="start";const c=new h.Object3D;C.addComponent(c,l),console.log("implicit PlayAudioOnStart",c,l),o.push(c),n.push(a),s.add(c)}return o}function rR(s){return new st("DisableAtStart",ht.sceneStartTrigger(),he.fadeAction(s,0,!1))}function rb(s,t){const e=s.domElement.shadowRoot.querySelector("link[rel='ar']");if(e)return e;const i=document.createElement("div");i.classList.add("menu"),i.classList.add("quicklook-menu"),i.style.display="none",i.style.visibility="hidden";const n=document.createElement("button");n.id="open-in-ar",t?(n.innerText="View in AR",n.title="View this scene in AR. The scene will be exported to USDZ and opened with Apple's QuickLook."):(n.innerText="View in AR",n.title="Download this scene for AR. Open the downloaded USDZ file to view it in AR using Apple's QuickLook."),i.appendChild(n);const o=document.createElement("a");o.id="needle-usdz-link",o.style.display="none",o.rel="ar",o.href="",o.target="_blank",i.appendChild(o);const a=document.createElement("img");return a.id="button",o.appendChild(a),s.domElement.shadowRoot.appendChild(i),o}var aR=Object.defineProperty,lR=Object.getOwnPropertyDescriptor,Ot=(s,t,e,i)=>{for(var n=i>1?void 0:i?lR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&aR(t,e,n),n};const di=S("debugusdz"),cR=S("debugusdzpruning");class Ro{constructor(){r(this,"callToAction");r(this,"checkoutTitle");r(this,"checkoutSubtitle");r(this,"callToActionURL")}}Ot([p()],Ro.prototype,"callToAction",2);Ot([p()],Ro.prototype,"checkoutTitle",2);Ot([p()],Ro.prototype,"checkoutSubtitle",2);Ot([p()],Ro.prototype,"callToActionURL",2);var fd;const bm=(fd=class extends D{constructor(){super(...arguments);r(this,"objectToExport");r(this,"autoExportAnimations",!0);r(this,"autoExportAudioSources",!0);r(this,"exportFileName");r(this,"customUsdzFile");r(this,"customBranding");r(this,"anchoringType","plane");r(this,"maxTextureSize",2048);r(this,"planeAnchoringAlignment","horizontal");r(this,"interactive",!0);r(this,"physics",!0);r(this,"allowCreateQuicklookButton",!0);r(this,"quickLookCompatible",!0);r(this,"extensions",[]);r(this,"link");r(this,"button");r(this,"onClickedOpenInARElement",t=>{t.preventDefault(),this.exportAndOpen()});r(this,"_currentExportTasks",new Map);r(this,"_previousTimeScale",1);r(this,"lastCallback");r(this,"_rootSessionRootWasAppliedTo",null);r(this,"_rootPositionBeforeExport",new h.Vector3);r(this,"_rootRotationBeforeExport",new h.Quaternion);r(this,"_rootScaleBeforeExport",new h.Vector3)}start(){var t,e,i;di&&(console.log("USDZExporter",this),console.log("Debug USDZ Mode. Press 'T' to export"),window.addEventListener("keydown",n=>{switch(n.key){case"t":this.exportAndOpen();break}})),this.objectToExport||(this.objectToExport=this.gameObject),!((e=(t=this.objectToExport)==null?void 0:t.children)!=null&&e.length)&&!((i=this.objectToExport)!=null&&i.isMesh)&&(this.objectToExport=this.context.scene)}onEnable(){var i;const t=exports.DeviceUtilities.supportsQuickLookAR(),e=exports.DeviceUtilities.isiOS()||exports.DeviceUtilities.isiPad();!this.button&&(di||t||e)&&(this.allowCreateQuicklookButton&&(this.button=this.createQuicklookButton()),this.lastCallback=this.quicklookCallback.bind(this),this.link=rb(this.context,t),this.link.addEventListener("message",this.lastCallback)),di&&Ee("USDZ Exporter enabled: "+this.name),(i=document.getElementById("open-in-ar"))==null||i.addEventListener("click",this.onClickedOpenInARElement),xc.registerExporter(this)}onDisable(){var t,e,i;(t=this.button)==null||t.remove(),(e=this.link)==null||e.removeEventListener("message",this.lastCallback),di&&Ee("USDZ Exporter disabled: "+this.name),(i=document.getElementById("open-in-ar"))==null||i.removeEventListener("click",this.onClickedOpenInARElement),xc.unregisterExporter(this)}async exportAsync(){return this.exportAndOpen()}async exportAndOpen(){var i;let t=this.exportFileName??((i=this.objectToExport)==null?void 0:i.name)??this.name;if(t+="-"+nw(),no()||(t!==""&&(t+="-"),t+="MadeWithNeedle"),this.link||(this.link=rb(this.context,exports.DeviceUtilities.supportsQuickLookAR())),this.customUsdzFile)return di&&console.log("Exporting custom usdz",this.customUsdzFile),this.openInQuickLook(this.customUsdzFile,t),null;if(!this.objectToExport)return console.warn("No object to export",this),null;const e=await this.export(this.objectToExport);return e?(di&&console.log("USDZ generation done. Downloading as "+t),this.openInQuickLook(e,t),e):(console.error("USDZ generation failed. Please report a bug",this),null)}async export(t){if(!t)return console.warn("No object to export"),null;const e=this._currentExportTasks.get(t);if(e)return e;const i=this.internalExport(t);return i instanceof Promise?(this._currentExportTasks.set(t,i),i.then(n=>(this._currentExportTasks.delete(t),n)).catch(n=>(this._currentExportTasks.delete(t),console.error("Error during USDZ export – please report a bug!",n),null))):i}async internalExport(t){se.start("export-usdz",{onProgress:M=>{this.dispatchEvent(new CustomEvent("export-progress",{detail:{progress:M}}))}}),se.report("export-usdz",{message:"Starting export",totalSteps:40,currentStep:0}),se.report("export-usdz",{message:"Load progressive textures",autoStep:5}),se.start("export-usdz-textures","export-usdz");const e=C.getComponentsInChildren(t,li);for(const M of e)M&&M.enabled&&M.updateSprite(!0);const i=C.getComponentsInChildren(t,Ve),n=new Array;let o=0;for(const M of i){for(const R of M.sharedMeshes)if(R){const A=re.NEEDLE_progressive.assignMeshLOD(R,0);A instanceof Promise&&n.push(new Promise((I,E)=>{A.then(()=>{o++,se.report("export-usdz-textures",{message:"Loaded progressive mesh",currentStep:o,totalSteps:n.length}),I()}).catch(j=>E(j))}))}for(const R of M.sharedMaterials)if(R){const A=re.NEEDLE_progressive.assignTextureLOD(R,0);A instanceof Promise&&n.push(new Promise((I,E)=>{A.then(()=>{o++,se.report("export-usdz-textures",{message:"Loaded progressive texture",currentStep:o,totalSteps:n.length}),I()}).catch(j=>E(j))}))}}di&&Ee("Progressive Loading: "+n.length),await Promise.all(n),di&&Ee("Progressive Loading: done"),se.end("export-usdz-textures");const a=vt.Global.Mask;vt.Global.Set(Tn.AR);const l=new lw,c=new lh(this.quickLookCompatible);let d;const u=[];this.interactive&&(u.push(new qu),u.push(new Co),globalThis.false&&C.getComponentsInChildren(t,ue).length>0&&(this.physics?(d=new Xu,u.push(d)):B()&&console.warn("USDZExporter: Physics export is disabled, but there are active Rigidbody components in the scene. They will not be exported.")),u.push(new ph),u.push(new Yu));const f=[c,...u,...this.extensions],m={self:this,exporter:l,extensions:f,object:t};se.report("export-usdz","Invoking before-export"),this.dispatchEvent(new CustomEvent("before-export",{detail:m})),this.applyWebARSessionRoot(),this._previousTimeScale=this.context.time.timeScale,this.context.time.timeScale=0,se.report("export-usdz","auto export animations and audio sources");const g=new Array;this.autoExportAnimations&&g.push(...sR(t,c)),f.find(M=>M.extensionName==="Audio")&&this.autoExportAudioSources&&g.push(...oR(t)),l.debug=di,l.pruneUnusedNodes=!cR;const y=gs.instance.objs.map(M=>M.batchedMesh);l.keepObject=M=>{let R=!0;const A=C.getComponent(M,Ve);return A&&!A.enabled&&(R=!1),R&&y.includes(M)&&(R=!1),R&&C.getComponentInParent(M,gn)&&(R=!1),R&&C.getComponentInParent(M,Wn)&&(R=!1),di&&!R&&console.log("USDZExporter: Discarding object",M),R},l.beforeWritingDocument=()=>{if(B()&&c&&d){const M=c.animatedRoots;for(const R of M){const A=C.getComponentsInChildren(R,ue).filter(E=>E.enabled),I=C.getComponents(R,ai).filter(E=>E.enabled&&!E.isTrigger);(A.length>0||I.length>0)&&console.error("An animated object has physics components in its child hierarchy. This can lead to undefined behaviour due to a bug in Apple's QuickLook (FB15925487). Remove the physics components from child objects or verify that you get the expected results.",R)}}};const b=new Array;this.objectToExport&&this.quickLookCompatible&&this.interactive&&this.objectToExport.traverse(M=>{M.visible||b.push(M)});const v=f.find(M=>M.extensionName==="Behaviour");this.interactive&&v&&b.length>0&&v.addBehavior(rR(b));let x=!0;this.quickLookCompatible&&!this.interactive&&(x=!1),this.anchoringType!=="plane"&&this.anchoringType!=="none"&&this.anchoringType!=="image"&&this.anchoringType!=="face"&&(this.anchoringType="plane"),this.planeAnchoringAlignment!=="horizontal"&&this.planeAnchoringAlignment!=="vertical"&&this.planeAnchoringAlignment!=="any"&&(this.planeAnchoringAlignment="horizontal"),se.report("export-usdz","Invoking exporter.parse");const O=await l.parse(this.objectToExport,{ar:{anchoring:{type:this.anchoringType},planeAnchoring:{alignment:this.planeAnchoringAlignment}},extensions:f,quickLookCompatible:this.quickLookCompatible,maxTextureSize:this.maxTextureSize,exportInvisible:x}),k=new Blob([O],{type:"model/vnd.usdz+zip"});this.revertWebARSessionRoot(),this.context.time.timeScale=this._previousTimeScale,se.report("export-usdz","Invoking after-export"),this.dispatchEvent(new CustomEvent("after-export",{detail:m}));for(const M of g)C.destroy(M);return vt.Global.Set(a),se.end("export-usdz"),k}openInQuickLook(t,e){const i=t instanceof Blob?URL.createObjectURL(t):t,n=this.buildQuicklookOverlay();di&&console.log("QuickLook Overlay",n);const o=n.callToAction?encodeURIComponent(n.callToAction):"",a=n.checkoutTitle?encodeURIComponent(n.checkoutTitle):"",l=n.checkoutSubtitle?encodeURIComponent(n.checkoutSubtitle):"";this.link.href=i+`#callToAction=${o}&checkoutTitle=${a}&checkoutSubtitle=${l}&callToActionURL=${n.callToActionURL}`,this.lastCallback||(this.lastCallback=this.quicklookCallback.bind(this),this.link.addEventListener("message",this.lastCallback)),this.link.download=e+".usdz",this.link.click()}download(t,e){bm.save(t,e)}static save(t,e){const i=document.createElement("a");i.style.display="none",document.body.appendChild(i),typeof t=="string"?i.href=t:i.href=URL.createObjectURL(t),i.download=e,i.click(),i.remove()}quicklookCallback(t){if((t==null?void 0:t.data)=="_apple_ar_quicklook_button_tapped"){di&&me("Quicklook closed via call to action button");var e=new CustomEvent("quicklook-button-tapped",{detail:this});if(this.dispatchEvent(e),!e.defaultPrevented){const i=new URLSearchParams(this.link.href);if(i){const n=i.get("callToActionURL");di&&Ee("Quicklook url: "+n),n&&(no()?globalThis.open(n,"_blank"):console.warn("Quicklook closed: custom redirects require a Needle Engine Pro license: https://needle.tools/pricing",n))}}}}buildQuicklookOverlay(){var i,n,o,a,l,c;const t={};return this.customBranding&&Object.assign(t,this.customBranding),no()||(console.log("Custom Quicklook banner text requires pro license: https://needle.tools/pricing"),t.callToAction="Close",t.checkoutTitle="🌵 Made with Needle",t.checkoutSubtitle="_"),(((i=t.callToAction)==null?void 0:i.length)||((n=t.checkoutTitle)==null?void 0:n.length)||((o=t.checkoutSubtitle)==null?void 0:o.length))&&((a=t.callToAction)!=null&&a.length||(t.callToAction="\0"),(l=t.checkoutTitle)!=null&&l.length||(t.checkoutTitle="\0"),(c=t.checkoutSubtitle)!=null&&c.length||(t.checkoutSubtitle="\0")),this.dispatchEvent(new CustomEvent("quicklook-overlay",{detail:t})),t}getARScaleAndTarget(){if(!this.objectToExport)return{scale:1,_invertForward:!1,target:this.gameObject,sessionRoot:null};const t=C.findObjectOfType($e);let e=C.getComponentInParent(this.objectToExport,Cs);e||(e=C.getComponentInChildren(this.objectToExport,Cs));let i=1,n=!1;const o=this.objectToExport;return t?i=t.arScale:e&&(i=e.arScale,n=e.invertForward),{scale:1/i,_invertForward:n,target:o,sessionRoot:(e==null?void 0:e.gameObject)??null}}applyWebARSessionRoot(){if(!this.objectToExport)return;const{scale:t,_invertForward:e,target:i,sessionRoot:n}=this.getARScaleAndTarget(),o=n==null?void 0:n.matrixWorld.clone().invert();this._rootSessionRootWasAppliedTo=i,this._rootPositionBeforeExport.copy(i.position),this._rootRotationBeforeExport.copy(i.quaternion),this._rootScaleBeforeExport.copy(i.scale),i.scale.multiplyScalar(t),e&&i.quaternion.multiply(bm.invertForwardQuaternion),i.updateMatrix(),i.updateMatrixWorld(!0),n&&o&&i.matrix.premultiply(o)}revertWebARSessionRoot(){if(!this.objectToExport||!this._rootSessionRootWasAppliedTo)return;const t=this._rootSessionRootWasAppliedTo;t.position.copy(this._rootPositionBeforeExport),t.quaternion.copy(this._rootRotationBeforeExport),t.scale.copy(this._rootScaleBeforeExport),t.updateMatrix(),t.updateMatrixWorld(!0),this._rootSessionRootWasAppliedTo=null}createQuicklookButton(){const e=ws.getOrCreate().createQuicklookButton();return e.parentNode||this.context.menu.appendChild(e),e}},r(fd,"invertForwardMatrix",new h.Matrix4().makeRotationY(Math.PI)),r(fd,"invertForwardQuaternion",new h.Quaternion().setFromEuler(new h.Euler(0,Math.PI,0))),fd);let Ie=bm;Ot([p(h.Object3D)],Ie.prototype,"objectToExport",2);Ot([p()],Ie.prototype,"autoExportAnimations",2);Ot([p()],Ie.prototype,"autoExportAudioSources",2);Ot([p()],Ie.prototype,"exportFileName",2);Ot([p(URL)],Ie.prototype,"customUsdzFile",2);Ot([p(Ro)],Ie.prototype,"customBranding",2);Ot([p()],Ie.prototype,"anchoringType",2);Ot([p()],Ie.prototype,"maxTextureSize",2);Ot([p()],Ie.prototype,"planeAnchoringAlignment",2);Ot([p()],Ie.prototype,"interactive",2);Ot([p()],Ie.prototype,"physics",2);Ot([p()],Ie.prototype,"allowCreateQuicklookButton",2);Ot([p()],Ie.prototype,"quickLookCompatible",2);var hR=Object.defineProperty,dR=Object.getOwnPropertyDescriptor,Zg=(s,t,e,i)=>{for(var n=i>1?void 0:i?dR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&hR(t,e,n),n};class nl extends D{constructor(){super(...arguments);r(this,"_fog")}get fog(){return this._fog||(this._fog=new h.Fog(0,0,50)),this._fog}get mode(){return 1}set near(e){this.fog.near=e}get near(){return this.fog.near}set far(e){this.fog.far=e}get far(){return this.fog.far}set color(e){this.fog.color.copy(e)}get color(){return this.fog.color}onEnable(){this.scene.fog=this.fog}onDisable(){this.scene.fog===this._fog&&(this.scene.fog=null)}}Zg([p()],nl.prototype,"near",1);Zg([p()],nl.prototype,"far",1);Zg([p(h.Color)],nl.prototype,"color",1);var uR=Object.defineProperty,fR=Object.getOwnPropertyDescriptor,Jg=(s,t,e,i)=>{for(var n=i>1?void 0:i?fR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&uR(t,e,n),n};class jr extends D{constructor(){super(...arguments);r(this,"objectBounds",!1);r(this,"color");r(this,"isGizmo",!0);r(this,"_gizmoObject",null);r(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!Qc||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new h.BoxHelper(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=tg(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),ve.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){var e;for(;this._boxHelper;)(e=this._boxHelper)==null||e.update(),yield}}Jg([p()],jr.prototype,"objectBounds",2);Jg([p(h.Color)],jr.prototype,"color",2);Jg([p()],jr.prototype,"isGizmo",2);var pR=Object.defineProperty,mR=Object.getOwnPropertyDescriptor,e_=(s,t,e,i)=>{for(var n=i>1?void 0:i?mR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&pR(t,e,n),n};class sl extends D{constructor(){super(...arguments);r(this,"isGizmo",!1);r(this,"color0");r(this,"color1");r(this,"gridHelper");r(this,"size");r(this,"divisions");r(this,"offset")}onEnable(){if(this.isGizmo&&!Qc)return;const e=this.size,i=this.divisions;this.gridHelper||(this.gridHelper=new h.GridHelper(e,i,this.color0??new h.Color(.4,.4,.4),this.color1??new h.Color(.6,.6,.6)),this.offset!==void 0&&(this.gridHelper.position.y+=this.offset)),this.gridHelper&&this.gameObject.add(this.gridHelper)}onDisable(){this.gridHelper&&(this.gameObject.remove(this.gridHelper),this.gridHelper=null)}}e_([p()],sl.prototype,"isGizmo",2);e_([p(h.Color)],sl.prototype,"color0",2);e_([p(h.Color)],sl.prototype,"color1",2);var gR=Object.defineProperty,_R=Object.getOwnPropertyDescriptor,t_=(s,t,e,i)=>{for(var n=i>1?void 0:i?_R(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&gR(t,e,n),n};class i_ extends D{constructor(){super(...arguments);r(this,"connectedBody");r(this,"_rigidBody",null)}get rigidBody(){return this._rigidBody}onEnable(){this._rigidBody||(this._rigidBody=this.gameObject.getComponent(ue)),this.rigidBody&&this.connectedBody&&this.startCoroutine(this.create())}*create(){yield,this.rigidBody&&this.connectedBody&&this.activeAndEnabled&&this.createJoint(this.rigidBody,this.connectedBody)}}t_([p(ue)],i_.prototype,"connectedBody",2);class n_ extends i_{createJoint(t,e){var i;(i=this.context.physics.engine)==null||i.addFixedJoint(t,e)}}class mh extends i_{constructor(){super(...arguments);r(this,"anchor");r(this,"axis")}createJoint(e,i){var n;this.axis&&this.anchor&&((n=this.context.physics.engine)==null||n.addHingeJoint(e,i,this.anchor,this.axis))}}t_([p(h.Vector3)],mh.prototype,"anchor",2);t_([p(h.Vector3)],mh.prototype,"axis",2);var yR=Object.defineProperty,bR=Object.getOwnPropertyDescriptor,Xn=(s,t,e,i)=>{for(var n=i>1?void 0:i?bR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&yR(t,e,n),n};function cp(s){return s*Math.PI/180}const ab=300,Us=S("debuglights");class ci extends D{constructor(){super(...arguments);r(this,"type",0);r(this,"range",1);r(this,"spotAngle",1);r(this,"innerSpotAngle",1);r(this,"_color",new h.Color(16777215));r(this,"_shadowNearPlane",.1);r(this,"_shadowBias",0);r(this,"_shadowNormalBias",0);r(this,"_overrideShadowBiasSettings",!1);r(this,"_shadows",1);r(this,"lightmapBakeType",4);r(this,"_intensity",-1);r(this,"_shadowDistance");r(this,"shadowWidth");r(this,"shadowHeight");r(this,"_shadowResolution");r(this,"light");r(this,"_webXRStartedListener");r(this,"_webXREndedListener");r(this,"_webARRoot")}set color(e){this._color=e,this.light!==void 0&&(this.light.color=e)}get color(){return this.light?this.light.color:this._color}set shadowNearPlane(e){var i,n;if(e!==this._shadowNearPlane&&(this._shadowNearPlane=e,((n=(i=this.light)==null?void 0:i.shadow)==null?void 0:n.camera)!==void 0)){const o=this.light.shadow.camera;o.near=e}}get shadowNearPlane(){return this._shadowNearPlane}set shadowBias(e){var i,n;e!==this._shadowBias&&(this._shadowBias=e,((n=(i=this.light)==null?void 0:i.shadow)==null?void 0:n.bias)!==void 0&&(this.light.shadow.bias=e,this.light.shadow.needsUpdate=!0))}get shadowBias(){return this._shadowBias}set shadowNormalBias(e){var i,n;e!==this._shadowNormalBias&&(this._shadowNormalBias=e,((n=(i=this.light)==null?void 0:i.shadow)==null?void 0:n.normalBias)!==void 0&&(this.light.shadow.normalBias=e,this.light.shadow.needsUpdate=!0))}get shadowNormalBias(){return this._shadowNormalBias}set shadows(e){this._shadows=e,this.light&&(this.light.castShadow=e!==0,this.updateShadowSoftHard())}get shadows(){return this._shadows}set intensity(e){var i;if(this._intensity=e,this.light){let n=1;if(this.context.isInXR&&this._webARRoot){const o=(i=this._webARRoot)==null?void 0:i.arScale;typeof o=="number"&&o>0&&(n/=o)}this.light.intensity=e*n}Us&&console.log("Set light intensity to "+this._intensity,e,this)}get intensity(){return this._intensity}get shadowDistance(){const e=this.light;return e!=null&&e.shadow?e.shadow.camera.far:-1}set shadowDistance(e){this._shadowDistance=e;const i=this.light;if(i!=null&&i.shadow){const n=i.shadow.camera;n.far=e,n.updateProjectionMatrix()}}get shadowResolution(){const e=this.light;return e!=null&&e.shadow?e.shadow.mapSize.x:-1}set shadowResolution(e){if(e===this._shadowResolution)return;this._shadowResolution=e;const i=this.light;i!=null&&i.shadow&&(i.shadow.mapSize.set(e,e),i.shadow.needsUpdate=!0)}get isBaked(){return this.lightmapBakeType===2}get selfIsLight(){if(this.gameObject.isLight===!0)return!0;switch(this.gameObject.type){case"SpotLight":case"PointLight":case"DirectionalLight":return!0}return!1}getWorldPosition(e){return this.light?this.type===1?this.light.getWorldPosition(e).multiplyScalar(1):this.light.getWorldPosition(e):e}awake(){this.color=new h.Color(this.color??16777215),Us&&console.log(this.name,this)}onEnable(){Us&&console.log("ENABLE LIGHT",this.name),this.createLight(),!this.isBaked&&(this.light&&(this.light.visible=!0,this.light.intensity=this._intensity,Us&&console.log("Set light intensity to "+this.light.intensity,this.name),this.selfIsLight||this.light.parent!==this.gameObject&&this.gameObject.add(this.light)),this.type===1&&this.startCoroutine(this.updateMainLightRoutine(),ve.LateUpdate))}onDisable(){Us&&console.log("DISABLE LIGHT",this.name),this.light&&(this.selfIsLight?this.light.intensity=0:this.light.visible=!1)}onEnterXR(e){this._webARRoot=C.getComponentInParent(this.gameObject,Cs)??void 0}onLeaveXR(e){}createLight(){const e=this.selfIsLight;if(e&&!this.light)switch(this.light=this.gameObject,this.light.name=this.name,this._intensity=this.light.intensity,this.type){case 1:this.setDirectionalLight(this.light);break}else if(!this.light)switch(this.type){case 1:const i=new h.DirectionalLight(this.color,this.intensity*Math.PI);if(i.position.set(0,0,-ab*.5).applyQuaternion(this.gameObject.quaternion),this.gameObject.add(i.target),mr(i.target,0,0,0),this.light=i,this.gameObject.position.set(0,0,0),this.gameObject.rotation.set(0,0,0),Us){const l=new h.DirectionalLightHelper(this.light,.2,this.color);this.context.scene.add(l)}break;case 0:const n=new h.SpotLight(this.color,this.intensity*Math.PI,this.range,cp(this.spotAngle/2),1-cp(this.innerSpotAngle/2)/cp(this.spotAngle/2),2);n.position.set(0,0,0),n.rotation.set(0,0,0),this.light=n;const o=n.target;n.add(o),o.position.set(0,0,this.range),o.rotation.set(0,0,0);break;case 2:const a=new h.PointLight(this.color,this.intensity*Math.PI,this.range);this.light=a;break}if(this.light){if(this._intensity>=0?this.light.intensity=this._intensity:this._intensity=this.light.intensity,this.shadows!==0?this.light.castShadow=!0:this.light.castShadow=!1,this.light.shadow){this._shadowResolution!==void 0&&this._shadowResolution>4?(this.light.shadow.mapSize.width=this._shadowResolution,this.light.shadow.mapSize.height=this._shadowResolution):(this.light.shadow.mapSize.width=2048,this.light.shadow.mapSize.height=2048),Us&&console.log("Override shadow bias?",this._overrideShadowBiasSettings,this.shadowBias,this.shadowNormalBias),this.light.shadow.bias=this.shadowBias,this.light.shadow.normalBias=this.shadowNormalBias,this.updateShadowSoftHard();const i=this.light.shadow.camera;if(i.near=this.shadowNearPlane,this._shadowDistance!==void 0&&typeof this._shadowDistance=="number"?i.far=this._shadowDistance:i.far=ab*Math.abs(this.gameObject.scale.z),this.gameObject.scale.set(1,1,1),this.shadowWidth!==void 0)i.left=-this.shadowWidth/2,i.right=this.shadowWidth/2;else{const n=this.gameObject.scale.x;i.left*=n,i.right*=n}if(this.shadowHeight!==void 0)i.top=this.shadowHeight/2,i.bottom=-this.shadowHeight/2;else{const n=this.gameObject.scale.y;i.top*=n,i.bottom*=n}this.light.shadow.needsUpdate=!0,Us&&this.context.scene.add(new h.CameraHelper(i))}this.isBaked?this.light.removeFromParent():e||this.gameObject.add(this.light)}}*updateMainLightRoutine(){for(;;){this.type===1&&((!this.context.mainLight||this.intensity>this.context.mainLight.intensity)&&(this.context.mainLight=this),yield);break}}updateShadowSoftHard(){this.light&&this.light.shadow&&(this.shadows===2||(this.light.shadow.radius=1,this.light.shadow.blurSamples=1))}setDirectionalLight(e){e.add(e.target),e.target.position.set(0,0,-1)}}r(ci,"allowChangingRendererShadowMapType",!0);Xn([p()],ci.prototype,"type",2);Xn([p(h.Color)],ci.prototype,"color",1);Xn([p()],ci.prototype,"shadowNearPlane",1);Xn([p()],ci.prototype,"shadowBias",1);Xn([p()],ci.prototype,"shadowNormalBias",1);Xn([p()],ci.prototype,"shadows",1);Xn([p()],ci.prototype,"lightmapBakeType",2);Xn([p()],ci.prototype,"intensity",1);Xn([p()],ci.prototype,"shadowDistance",1);Xn([p()],ci.prototype,"shadowResolution",1);new h.Vector3(0,0,0);var vR=Object.defineProperty,wR=Object.getOwnPropertyDescriptor,gh=(s,t,e,i)=>{for(var n=i>1?void 0:i?wR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&vR(t,e,n),n};const hp=S("debuglods"),xR=S("nolods");class Br{constructor(){r(this,"screenRelativeTransitionHeight");r(this,"distance");r(this,"renderers")}}gh([p()],Br.prototype,"screenRelativeTransitionHeight",2);gh([p()],Br.prototype,"distance",2);gh([p(Ve)],Br.prototype,"renderers",2);class SR{constructor(t){r(this,"model");this.model=t}get renderers(){return this.model.renderers}}class _h extends D{constructor(){super(...arguments);r(this,"fadeMode",0);r(this,"localReferencePoint");r(this,"lodCount",0);r(this,"size",0);r(this,"animateCrossFading",!1);r(this,"lodModels");r(this,"_lods",[]);r(this,"_settings",[]);r(this,"_lodsHandler");r(this,"_distanceFactor",1)}start(){if(hp&&console.log("LODGROUP",this.name,this.lodModels,this),!xR&&!this._lodsHandler&&this.gameObject&&this.lodModels&&Array.isArray(this.lodModels)){const e=[];for(const n of this.lodModels){const o=new SR(n);this._lods.push(o);for(const a of o.renderers)e.includes(a)||e.push(a)}this._lodsHandler=new Array;for(let n=0;n<e.length;n++){const o=new h.LOD;this._lodsHandler.push(o),this.gameObject.add(o)}const i=new h.Object3D;i.name="Cull "+this.name;for(let n=0;n<e.length;n++){const o=e[n],a=this._lodsHandler[n],l=o.gameObject;hp&&console.log(n,l.name);for(const c of this._lods){const d=c.model.distance;let u=null;if(c.renderers.includes(o)?u=l:u=i,u.type==="Group"){console.warn(`LODGroup ${this.name}: Group or MultiMaterial object's are not supported as LOD object: ${u.name}`);continue}hp&&console.log("LEVEL",u.name,d),a.autoUpdate=!1,this.onAddLodLevel(a,u,c.model.distance)}}}}onAfterRender(){if(!this.gameObject||!this._lodsHandler)return;const e=this.context.mainCamera;if(e)for(const i of this._lodsHandler){i.update(e);const n=i.getCurrentLevel(),o=i.levels[n];i.layers.mask=o.object.layers.mask}}onAddLodLevel(e,i,n){if(i===this.gameObject){console.warn("LODGroup component must be on parent object and not mesh directly at the moment",i.name,i);return}e.addLevel(i,n*this._distanceFactor,.01);const o={lod:e,levelIndex:e.levels.length-1,distance:n};this._settings.push(o)}distanceFactor(e){if(e!==this._distanceFactor){this._distanceFactor=e;for(const i of this._settings){const n=i.lod.levels[i.levelIndex];n.distance=i.distance*e}}}}gh([p(h.Vector3)],_h.prototype,"localReferencePoint",2);gh([p(Br)],_h.prototype,"lodModels",2);var CR=Object.defineProperty,PR=Object.getOwnPropertyDescriptor,OR=(s,t,e,i)=>{for(var n=i>1?void 0:i?PR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&CR(t,e,n),n};const sd=S("debugnestedgltf");class ef extends D{constructor(){super(...arguments);r(this,"filePath");r(this,"loadAssetInParent",!0);r(this,"_isLoadingOrDoneLoading",!1)}listenToProgress(e){var i;(i=this.filePath)==null||i.beginListenDownload(e)}preload(){var e;(e=this.filePath)==null||e.preload()}async start(){var i,n,o,a,l;if(this._isLoadingOrDoneLoading)return;sd&&console.log(this,this.guid);const e=this.gameObject.parent;if(e){this._isLoadingOrDoneLoading=!0;const c=new pn;c.idProvider=new xt(this.hash(this.guid)),c.parent=this.loadAssetInParent!==!1?e:this.gameObject,this.gameObject.updateMatrix();const d=this.gameObject.matrix;sd&&console.log("Load nested:",((i=this.filePath)==null?void 0:i.url)??this.filePath,this.gameObject.position);const u=await((o=(n=this.filePath)==null?void 0:n.instantiate)==null?void 0:o.call(this.filePath,c));sd&&console.log("Nested loaded:",((a=this.filePath)==null?void 0:a.url)??this.filePath,u),u&&this.loadAssetInParent!==!1&&(u.matrixAutoUpdate=!1,u.matrix.identity(),u.applyMatrix4(d),u.matrixAutoUpdate=!0,u.layers.disableAll(),u.layers.set(this.layer),this.dispatchEvent(new CustomEvent("loaded",{detail:{instance:u,assetReference:this.filePath}}))),sd&&console.log("Nested loading done:",((l=this.filePath)==null?void 0:l.url)??this.filePath,u)}}onDestroy(){var e;(e=this.filePath)==null||e.unload()}hash(e){let i=0;for(let n=0;n<e.length;n++)i=e.charCodeAt(n)+((i<<5)-i);return i}}OR([p(ee)],ef.prototype,"filePath",2);var MR=Object.defineProperty,RR=Object.getOwnPropertyDescriptor,s_=(s,t,e,i)=>{for(var n=i>1?void 0:i?RR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&MR(t,e,n),n};const kR=S("debugnet"),vm=class extends D{constructor(){super(...arguments);r(this,"url",null);r(this,"urlParameterName",null);r(this,"localhost",null)}awake(){kR&&console.log(this),this.context.connection.registerProvider(this)}getWebsocketUrl(){let t=this.url?vm.GetUrl(this.url,this.localhost):null;if(this.urlParameterName){const o=S(this.urlParameterName);o&&typeof o=="string"&&(t=o)}if(!t)return null;const i=new RegExp("(((https?)|(?<socket_prefix>wss?))://)?(www.)?(?<url>.+)","gm").exec(t);return i!=null&&i.groups?(i==null?void 0:i.groups.socket_prefix)?t:"wss://"+(i==null?void 0:i.groups.url):null}static GetUrl(t,e){let i=t;const n=vm.IsLocalNetwork()&&e;if(n&&(i=e),t!=null&&t.startsWith("/")){const o=n?i:window.location.origin;o!=null&&o.endsWith("/")&&t.startsWith("/")&&(t=t.substring(1)),i=o+t}return i}static IsLocalNetwork(t=window.location.hostname){return Xt(t)}};let ol=vm;s_([p()],ol.prototype,"url",2);s_([p()],ol.prototype,"urlParameterName",2);s_([p()],ol.prototype,"localhost",2);var TR=Object.defineProperty,ER=Object.getOwnPropertyDescriptor,tf=(s,t,e,i)=>{for(var n=i>1?void 0:i?ER(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&TR(t,e,n),n};class Fr extends D{constructor(){super(...arguments);r(this,"referenceSpace");r(this,"from");r(this,"affectPosition",!1);r(this,"affectRotation",!1);r(this,"alignLookDirection",!1);r(this,"levelLookDirection",!1);r(this,"levelPosition",!1);r(this,"positionOffset",new h.Vector3(0,0,0));r(this,"rotationOffset",new h.Vector3(0,0,0));r(this,"offset",new h.Vector3(0,0,0))}update(){if(!this.from)return;var e=K(this.from),i=ye(this.from);this.offset.copy(this.positionOffset);const n=this.offset.length();if(this.referenceSpace&&this.offset.transformDirection(this.referenceSpace.matrixWorld).multiplyScalar(n),e.add(this.offset),this.levelPosition&&this.referenceSpace){const c=new h.Plane(this.gameObject.up,0),d=K(this.referenceSpace);c.setFromNormalAndCoplanarPoint(this.gameObject.up,d);const u=new h.Vector3(0,0,0);c.projectPoint(e,u),e.copy(u)}this.affectPosition&&nt(this.gameObject,e);const o=new h.Euler(this.rotationOffset.x,this.rotationOffset.y,this.rotationOffset.z),a=new h.Quaternion().setFromEuler(o);this.affectRotation&&Wi(this.gameObject,i.multiply(a));const l=new h.Vector3;this.from.getWorldDirection(l).multiplyScalar(50),this.levelLookDirection&&(l.y=0),this.alignLookDirection&&this.gameObject.lookAt(l)}}tf([p(C)],Fr.prototype,"referenceSpace",2);tf([p(C)],Fr.prototype,"from",2);tf([p(h.Vector3)],Fr.prototype,"positionOffset",2);tf([p(h.Vector3)],Fr.prototype,"rotationOffset",2);var AR=Object.defineProperty,DR=Object.getOwnPropertyDescriptor,P=(s,t,e,i)=>{for(var n=i>1?void 0:i?DR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&AR(t,e,n),n};const od=S("debugparticles");var ds=(s=>(s[s.Billboard=0]="Billboard",s[s.Stretch=1]="Stretch",s[s.HorizontalBillboard=2]="HorizontalBillboard",s[s.VerticalBillboard=3]="VerticalBillboard",s[s.Mesh=4]="Mesh",s))(ds||{});class ko{constructor(){r(this,"alphaKeys",[]);r(this,"colorKeys",[])}get duration(){return 1}evaluate(t,e){let i,n=0,o=null,a=0;for(let l=0;l<this.alphaKeys.length;l++){const c=this.alphaKeys[l];(c.time<t||!i)&&(i=c,n=l)}for(let l=0;l<this.colorKeys.length;l++){const c=this.colorKeys[l];(c.time<t||!o)&&(o=c,a=l)}if(o)if(a+1<this.colorKeys.length){const c=this.colorKeys[a+1],d=z.remap(t,o.time,c.time,0,1);e.r=z.lerp(o.color.r,c.color.r,d),e.g=z.lerp(o.color.g,c.color.g,d),e.b=z.lerp(o.color.b,c.color.b,d)}else e.r=o.color.r,e.g=o.color.g,e.b=o.color.b;if(i)if(n+1<this.alphaKeys.length){const c=this.alphaKeys[n+1],d=z.remap(t,i.time,c.time,0,1);e.alpha=z.lerp(i.alpha,c.alpha,d)}else e.alpha=i.alpha;return e}}P([p()],ko.prototype,"alphaKeys",2);P([p()],ko.prototype,"colorKeys",2);var Tc=(s=>(s[s.Local=0]="Local",s[s.World=1]="World",s[s.Custom=2]="Custom",s))(Tc||{}),au=(s=>(s[s.Sphere=0]="Sphere",s[s.SphereShell=1]="SphereShell",s[s.Hemisphere=2]="Hemisphere",s[s.HemisphereShell=3]="HemisphereShell",s[s.Cone=4]="Cone",s[s.Box=5]="Box",s[s.Mesh=6]="Mesh",s[s.ConeShell=7]="ConeShell",s[s.ConeVolume=8]="ConeVolume",s[s.ConeVolumeShell=9]="ConeVolumeShell",s[s.Circle=10]="Circle",s[s.CircleEdge=11]="CircleEdge",s[s.SingleSidedEdge=12]="SingleSidedEdge",s[s.MeshRenderer=13]="MeshRenderer",s[s.SkinnedMeshRenderer=14]="SkinnedMeshRenderer",s[s.BoxShell=15]="BoxShell",s[s.BoxEdge=16]="BoxEdge",s[s.Donut=17]="Donut",s[s.Rectangle=18]="Rectangle",s[s.Sprite=19]="Sprite",s[s.SpriteRenderer=20]="SpriteRenderer",s))(au||{});const ql=class{constructor(){r(this,"mode","Constant");r(this,"constant");r(this,"constantMin");r(this,"constantMax");r(this,"curve");r(this,"curveMin");r(this,"curveMax");r(this,"curveMultiplier")}static constant(s){const t=new ql;return t.setConstant(s),t}static betweenTwoConstants(s,t){const e=new ql;return e.setMinMaxConstant(s,t),e}static curve(s,t=1){const e=new ql;return e.setCurve(s,t),e}setConstant(s){this.mode=0,this.constant=s}setMinMaxConstant(s,t){this.mode=3,this.constantMin=s,this.constantMax=t}setCurve(s,t=1){this.mode=1,this.curve=s,this.curveMultiplier=t}clone(){var t,e,i;const s=new ql;return s.mode=this.mode,s.constant=this.constant,s.constantMin=this.constantMin,s.constantMax=this.constantMax,s.curve=(t=this.curve)==null?void 0:t.clone(),s.curveMin=(e=this.curveMin)==null?void 0:e.clone(),s.curveMax=(i=this.curveMax)==null?void 0:i.clone(),s.curveMultiplier=this.curveMultiplier,s}evaluate(s,t){const e=t===void 0?Math.random():t;switch(this.mode){case 0:case"Constant":return this.constant;case 1:case"Curve":return s=z.clamp01(s),this.curve.evaluate(s)*this.curveMultiplier;case 2:case"TwoCurves":const i=s*this.curveMin.duration,n=s*this.curveMax.duration;return z.lerp(this.curveMin.evaluate(i),this.curveMax.evaluate(n),e%1)*this.curveMultiplier;case 3:case"TwoConstants":return z.lerp(this.constantMin,this.constantMax,e%1);default:this.curveMax.evaluate(s)*this.curveMultiplier;break}return 0}getMax(){switch(this.mode){case 0:case"Constant":return this.constant;case 1:case"Curve":return this.getMaxFromCurve(this.curve)*this.curveMultiplier;case 2:case"TwoCurves":return Math.max(this.getMaxFromCurve(this.curveMin),this.getMaxFromCurve(this.curveMax))*this.curveMultiplier;case 3:case"TwoConstants":return Math.max(this.constantMin,this.constantMax);default:return 0}}getMaxFromCurve(s){if(!s)return 0;let t=Number.MIN_VALUE;for(let e=0;e<s.keys.length;e++){const i=s.keys[e];i.value>t&&(t=i.value)}return t}};let W=ql;P([p()],W.prototype,"mode",2);P([p()],W.prototype,"constant",2);P([p()],W.prototype,"constantMin",2);P([p()],W.prototype,"constantMax",2);P([p(Mr)],W.prototype,"curve",2);P([p(Mr)],W.prototype,"curveMin",2);P([p(Mr)],W.prototype,"curveMax",2);P([p()],W.prototype,"curveMultiplier",2);var pd;const _t=(pd=class{constructor(){r(this,"mode",0);r(this,"color");r(this,"colorMin");r(this,"colorMax");r(this,"gradient");r(this,"gradientMin");r(this,"gradientMax")}static constant(s){const t=new _t;return t.constant(s),t}static betweenTwoColors(s,t){const e=new _t;return e.betweenTwoColors(s,t),e}constant(s){return this.mode=0,this.color=s,this}betweenTwoColors(s,t){return this.mode=2,this.colorMin=s,this.colorMax=t,this}evaluate(s,t){const e=t===void 0?Math.random():t;switch(this.mode){case 0:case"Color":return this.color;case 1:case"Gradient":return this.gradient.evaluate(s,_t._temp),_t._temp;case 2:case"TwoColors":return _t._temp.lerpColors(this.colorMin,this.colorMax,e);case 3:case"TwoGradients":return this.gradientMin.evaluate(s,_t._temp),this.gradientMax.evaluate(s,_t._temp2),_t._temp.lerp(_t._temp2,e);case 4:case"RandomColor":const n=Math.random();return this.gradientMin.evaluate(s,_t._temp),this.gradientMax.evaluate(s,_t._temp2),_t._temp.lerp(_t._temp2,n)}return _t._temp.set(16777215),_t._temp.alpha=1,_t._temp}},r(pd,"_temp",new ge(0,0,0,1)),r(pd,"_temp2",new ge(0,0,0,1)),pd);let Yt=_t;P([p()],Yt.prototype,"mode",2);P([p(ge)],Yt.prototype,"color",2);P([p(ge)],Yt.prototype,"colorMin",2);P([p(ge)],Yt.prototype,"colorMax",2);P([p(ko)],Yt.prototype,"gradient",2);P([p(ko)],Yt.prototype,"gradientMin",2);P([p(ko)],Yt.prototype,"gradientMax",2);var wm=(s=>(s[s.Hierarchy=0]="Hierarchy",s[s.Local=1]="Local",s[s.Shape=2]="Shape",s))(wm||{});class Mt{constructor(){r(this,"cullingMode");r(this,"duration");r(this,"emitterVelocityMode");r(this,"flipRotation");r(this,"gravityModifier");r(this,"gravityModifierMultiplier");r(this,"loop");r(this,"maxParticles");r(this,"playOnAwake");r(this,"prewarm");r(this,"ringBufferLoopRange");r(this,"ringBufferMode");r(this,"scalingMode");r(this,"simulationSpace");r(this,"simulationSpeed");r(this,"startColor");r(this,"startDelay");r(this,"startDelayMultiplier");r(this,"startLifetime");r(this,"startLifetimeMultiplier");r(this,"startRotation");r(this,"startRotationMultiplier");r(this,"startRotation3D");r(this,"startRotationX");r(this,"startRotationXMultiplier");r(this,"startRotationY");r(this,"startRotationYMultiplier");r(this,"startRotationZ");r(this,"startRotationZMultiplier");r(this,"startSize");r(this,"startSize3D");r(this,"startSizeMultiplier");r(this,"startSizeX");r(this,"startSizeXMultiplier");r(this,"startSizeY");r(this,"startSizeYMultiplier");r(this,"startSizeZ");r(this,"startSizeZMultiplier");r(this,"startSpeed");r(this,"startSpeedMultiplier");r(this,"stopAction");r(this,"useUnscaledTime")}}P([p(W)],Mt.prototype,"gravityModifier",2);P([p(Yt)],Mt.prototype,"startColor",2);P([p(W)],Mt.prototype,"startDelay",2);P([p(W)],Mt.prototype,"startLifetime",2);P([p(W)],Mt.prototype,"startRotation",2);P([p(W)],Mt.prototype,"startRotationX",2);P([p(W)],Mt.prototype,"startRotationY",2);P([p(W)],Mt.prototype,"startRotationZ",2);P([p(W)],Mt.prototype,"startSize",2);P([p(W)],Mt.prototype,"startSizeX",2);P([p(W)],Mt.prototype,"startSizeY",2);P([p(W)],Mt.prototype,"startSizeZ",2);P([p(W)],Mt.prototype,"startSpeed",2);class Ec{constructor(){r(this,"cycleCount");r(this,"maxCount");r(this,"minCount");r(this,"probability");r(this,"repeatInterval");r(this,"time");r(this,"count");r(this,"_performed",0)}reset(){this._performed=0}run(t){if(t<=this.time)return 0;let e=0;if(this.cycleCount===0||this._performed<this.cycleCount){const i=this.time+this.repeatInterval*this._performed;if(t>=i&&(this._performed+=1,Math.random()<this.probability))switch(this.count.mode){case 0:e=this.count.constant;break;case 3:e=z.lerp(this.count.constantMin,this.count.constantMax,Math.random());break;case 1:e=this.count.curve.evaluate(Math.random());break;case 2:const n=Math.random();e=z.lerp(this.count.curveMin.evaluate(n),this.count.curveMax.evaluate(n),Math.random());break}}return e}}class Qn{constructor(){r(this,"enabled");r(this,"bursts");r(this,"rateOverTime");r(this,"rateOverTimeMultiplier");r(this,"rateOverDistance");r(this,"rateOverDistanceMultiplier");r(this,"system")}get burstCount(){var t;return((t=this.bursts)==null?void 0:t.length)??0}reset(){var t;(t=this.bursts)==null||t.forEach(e=>e.reset())}getBurst(){let t=0;if(this.burstCount>0)for(let e=0;e<this.burstCount;e++){const i=this.bursts[e];this.system.main.loop&&i.time>=this.system.time&&i.reset(),t+=Math.round(i.run(this.system.time))}return t}}P([p()],Qn.prototype,"enabled",2);P([p()],Qn.prototype,"bursts",2);P([p(W)],Qn.prototype,"rateOverTime",2);P([p()],Qn.prototype,"rateOverTimeMultiplier",2);P([p(W)],Qn.prototype,"rateOverDistance",2);P([p()],Qn.prototype,"rateOverDistanceMultiplier",2);class yh{constructor(){r(this,"enabled");r(this,"color")}}P([p(Yt)],yh.prototype,"color",2);class To{constructor(){r(this,"enabled");r(this,"separateAxes");r(this,"size");r(this,"sizeMultiplier");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier");r(this,"_time",0);r(this,"_temp",new h.Vector3)}evaluate(t,e,i){if(e||(e=this._temp),!this.enabled)return e.x=e.y=e.z=1,e;if(this.separateAxes)e.x=this.x.evaluate(t,i)*this.xMultiplier,e.y=this.y.evaluate(t,i)*this.yMultiplier,e.z=this.z.evaluate(t,i)*this.zMultiplier;else{const n=this.size.evaluate(t,i)*this.sizeMultiplier;e.x=n}return e}}P([p(W)],To.prototype,"size",2);P([p(W)],To.prototype,"x",2);P([p(W)],To.prototype,"y",2);P([p(W)],To.prototype,"z",2);var md;const Xl=(md=class{constructor(){r(this,"shapeType",5);r(this,"enabled",!0);r(this,"alignToDirection",!1);r(this,"angle",0);r(this,"arc",360);r(this,"arcSpread");r(this,"arcSpeedMultiplier");r(this,"arcMode");r(this,"boxThickness");r(this,"position");r(this,"rotation");r(this,"_rotation",new h.Euler);r(this,"scale");r(this,"radius");r(this,"radiusThickness");r(this,"sphericalDirectionAmount");r(this,"randomDirectionAmount");r(this,"randomPositionAmount");r(this,"meshShapeType");r(this,"meshRenderer");r(this,"_meshObj");r(this,"_meshGeometry");r(this,"system");r(this,"_space");r(this,"_worldSpaceMatrix",new h.Matrix4);r(this,"_worldSpaceMatrixInverse",new h.Matrix4);r(this,"_vector",new h.Vector3(0,0,0));r(this,"_temp",new h.Vector3(0,0,0));r(this,"_triangle",new h.Triangle);r(this,"_dir",new h.Vector3);r(this,"_loopTime",0);r(this,"_loopDirection",1);od&&console.log(this)}get type(){return au[this.shapeType]}initialize(s){this.onInitialize(s),s.position.x=this._vector.x,s.position.y=this._vector.y,s.position.z=this._vector.z}toJSON(){return this}clone(){return new Xl}setMesh(s){this.meshRenderer=s,s?(this._meshObj=s.sharedMeshes[Math.floor(Math.random()*s.sharedMeshes.length)],this._meshGeometry=this._meshObj.geometry):(this._meshObj=void 0,this._meshGeometry=void 0)}update(s,t){}onUpdate(s,t,e,i){this.system=s,this._space=e,e===1&&(this._worldSpaceMatrix.copy(i.matrixWorld),this._worldSpaceMatrix.elements[0]=1,this._worldSpaceMatrix.elements[5]=1,this._worldSpaceMatrix.elements[10]=1,this._worldSpaceMatrixInverse.copy(this._worldSpaceMatrix).invert())}applyRotation(s){const t=this.rotation.x!==0||this.rotation.y!==0||this.rotation.z!==0;return t&&(this._rotation.x=z.toRadians(this.rotation.x),this._rotation.y=z.toRadians(this.rotation.y),this._rotation.z=z.toRadians(this.rotation.z),this._rotation.order="ZYX",s.applyEuler(this._rotation)),t}onInitialize(s){this._vector.set(0,0,0),s.mesh=void 0,s.mesh_geometry=void 0;const t=this._temp.copy(this.position),e=this._space===1;e&&t.applyQuaternion(this.system.worldQuaternion);let i=this.radius;if(e&&(i*=this.system.worldScale.x),this.enabled){switch(this.shapeType){case 5:od&&N.DrawWireBox(this.position,this.scale,14540253,1),this._vector.x=Math.random()*this.scale.x-this.scale.x/2,this._vector.y=Math.random()*this.scale.y-this.scale.y/2,this._vector.z=Math.random()*this.scale.z-this.scale.z/2,this._vector.add(t);break;case 4:this.randomConePoint(this.position,this.angle,i,this.radiusThickness,this.arc,this.arcMode,this._vector);break;case 0:this.randomSpherePoint(this.position,i,this.radiusThickness,this.arc,this._vector);break;case 10:this.randomCirclePoint(this.position,i,this.radiusThickness,this.arc,this._vector);break;case 13:const n=this.meshRenderer;(n==null?void 0:n.destroyed)==!1&&this.setMesh(n);const o=s.mesh=this._meshObj,a=s.mesh_geometry=this._meshGeometry;if(o&&a)switch(this.meshShapeType){case 0:{const l=a.getAttribute("position"),c=Math.floor(Math.random()*l.count);this._vector.fromBufferAttribute(l,c),this._vector.applyMatrix4(o.matrixWorld),s.mesh_normal=c}break;case 1:break;case 2:{const l=a.index;if(l){let c=Math.random(),d=Math.random();c+d>1&&(c=1-c,d=1-d);const u=Math.floor(Math.random()*(l.count/3));let f=u*3,m=u*3+1,g=u*3+2;f=l.getX(f),m=l.getX(m),g=l.getX(g);const _=a.getAttribute("position");this._triangle.a.fromBufferAttribute(_,f),this._triangle.b.fromBufferAttribute(_,m),this._triangle.c.fromBufferAttribute(_,g),this._vector.set(0,0,0).addScaledVector(this._triangle.a,c).addScaledVector(this._triangle.b,d).addScaledVector(this._triangle.c,1-(c+d)),this._vector.applyMatrix4(o.matrixWorld),s.mesh_normal=u}}break}break;default:this._vector.set(0,0,0),B()&&!globalThis.__particlesystem_shapetype_unsupported&&(console.warn("ParticleSystem ShapeType is not supported:",au[this.shapeType]),globalThis.__particlesystem_shapetype_unsupported=!0);break}this.randomizePosition(this._vector,this.randomPositionAmount)}this.applyRotation(this._vector),e&&(this._vector.applyQuaternion(this.system.worldQuaternion),this._vector.add(this.system.worldPos)),od&&N.DrawSphere(this._vector,.03,16711680,.5,!0)}getDirection(s,t){var e;if(!this.enabled)return this._dir.set(0,0,1),this._dir;switch(this.shapeType){case 5:this._dir.set(0,0,1);break;case 4:this._dir.set(0,0,1);break;case 10:case 0:const i=t.x,n=t.y,o=t.z;this._dir.set(i,n,o),(e=this.system)!=null&&e.worldspace?this._dir.sub(this.system.worldPos):this._dir.sub(this.position);break;case 13:const a=s.mesh,l=s.mesh_geometry;if(a&&l)switch(this.meshShapeType){case 0:{const c=l.getAttribute("normal"),d=s.mesh_normal;this._dir.fromBufferAttribute(c,d)}break;case 1:break;case 2:{const c=l.index;if(c){const d=s.mesh_normal,u=c.getX(d*3),f=c.getX(d*3+1),m=c.getX(d*3+2),g=l.getAttribute("position"),_=V(),y=V(),b=V();_.fromBufferAttribute(g,u),y.fromBufferAttribute(g,f),b.fromBufferAttribute(g,m),_.sub(y),b.sub(y),_.cross(b),this._dir.copy(_).multiplyScalar(-1);const v=ye(a);this._dir.applyQuaternion(v)}}break}break;default:this._dir.set(0,0,1);break}return this._space===1&&this._dir.applyQuaternion(this.system.worldQuaternion),this.applyRotation(this._dir),this._dir.normalize(),this.spherizeDirection(this._dir,this.sphericalDirectionAmount),this.randomizeDirection(this._dir,this.randomDirectionAmount),od&&(N.DrawSphere(t,.01,8925952,.5,!0),N.DrawDirection(t,this._dir,8925952,.5,!0)),this._dir}randomizePosition(s,t){if(t<=0)return;const e=Xl._tempVec;e.set(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1),e.x*=t*this.scale.x,e.y*=t*this.scale.y,e.z*=t*this.scale.z,s.add(e)}randomizeDirection(s,t){if(t===0)return;const e=Xl._randomQuat,i=Xl._tempVec;i.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),e.setFromAxisAngle(i,t*Math.random()*Math.PI),s.applyQuaternion(e)}spherizeDirection(s,t){if(t===0)return;const e=Math.random()*Math.PI*2,i=Math.acos(1-Math.random()*2),n=Math.sin(i)*Math.cos(e),o=Math.sin(i)*Math.sin(e),a=Math.cos(i),l=new h.Vector3(n,o,a);s.lerp(l,t)}randomSpherePoint(s,t,e,i,n){const o=Math.random(),a=Math.random(),l=2*Math.PI*o*(i/360),c=Math.acos(2*a-1),d=z.lerp(1,1-Math.pow(1-Math.random(),Math.PI),e)*t,u=s.x+this.scale.x*(-d*Math.sin(c)*Math.cos(l)),f=s.y+this.scale.y*(d*Math.sin(c)*Math.sin(l)),m=s.z+this.scale.z*(d*Math.cos(c));n.x=u,n.y=f,n.z=m}randomCirclePoint(s,t,e,i,n){const o=Math.random(),a=2*Math.PI*o*(i/360),l=z.lerp(1,1-Math.pow(1-Math.random(),Math.PI),e)*t,c=s.x+this.scale.x*l*Math.cos(a),d=s.y+this.scale.y*l*Math.sin(a),u=s.z;n.x=c,n.y=d,n.z=u}randomConePoint(s,t,e,i,n,o,a){let l=0,c=0;switch(o){case 0:l=Math.random(),c=Math.random();break;case 2:this._loopTime>1&&(this._loopDirection=-1),this._loopTime<0&&(this._loopDirection=1);case 1:l=.5,c=Math.random(),this._loopTime+=this.system.deltaTime*this._loopDirection;break}let d=2*Math.PI*l*(n/360);switch(o){case 2:case 1:d+=Math.PI+.5,d+=this._loopTime*Math.PI*2,d%=z.toRadians(n);break}const u=Math.acos(2*c-1),f=z.lerp(1,1-Math.pow(1-Math.random(),Math.PI),i)*e,m=s.x+-f*Math.sin(u)*Math.cos(d),g=s.y+f*Math.sin(u)*Math.sin(d),_=s.z;a.x=m*this.scale.x,a.y=g*this.scale.y,a.z=_*this.scale.z}},r(md,"_randomQuat",new h.Quaternion),r(md,"_tempVec",new h.Vector3),md);let Fe=Xl;P([p()],Fe.prototype,"shapeType",2);P([p()],Fe.prototype,"enabled",2);P([p()],Fe.prototype,"alignToDirection",2);P([p()],Fe.prototype,"angle",2);P([p()],Fe.prototype,"arc",2);P([p()],Fe.prototype,"arcSpread",2);P([p()],Fe.prototype,"arcSpeedMultiplier",2);P([p()],Fe.prototype,"arcMode",2);P([p(h.Vector3)],Fe.prototype,"boxThickness",2);P([p(h.Vector3)],Fe.prototype,"position",2);P([p(h.Vector3)],Fe.prototype,"rotation",2);P([p(h.Vector3)],Fe.prototype,"scale",2);P([p()],Fe.prototype,"radius",2);P([p()],Fe.prototype,"radiusThickness",2);P([p()],Fe.prototype,"sphericalDirectionAmount",2);P([p()],Fe.prototype,"randomDirectionAmount",2);P([p()],Fe.prototype,"randomPositionAmount",2);P([p()],Fe.prototype,"meshShapeType",2);P([p(rh)],Fe.prototype,"meshRenderer",2);class _e{constructor(){r(this,"damping");r(this,"enabled");r(this,"frequency");r(this,"octaveCount");r(this,"octaveMultiplier");r(this,"octaveScale");r(this,"positionAmount");r(this,"quality");r(this,"remap");r(this,"remapEnabled");r(this,"remapMultiplier");r(this,"remapX");r(this,"remapXMultiplier");r(this,"remapY");r(this,"remapYMultiplier");r(this,"remapZ");r(this,"remapZMultiplier");r(this,"scrollSpeedMultiplier");r(this,"separateAxes");r(this,"strengthMultiplier");r(this,"strengthX");r(this,"strengthXMultiplier");r(this,"strengthY");r(this,"strengthYMultiplier");r(this,"strengthZ");r(this,"strengthZMultiplier");r(this,"_noise");r(this,"_time",0);r(this,"_temp",new h.Vector3)}update(t){this._time+=t.time.deltaTime*this.scrollSpeedMultiplier}apply(t,e,i,n,o,a){if(!this.enabled)return;this._noise||(this._noise=oe.createNoise4D(()=>0));const l=this._temp.set(e.x,e.y,e.z).multiplyScalar(this.frequency),c=this._noise(l.x,l.y,l.z,this._time),d=this._noise(l.x,l.y,l.z,this._time+1e3*this.frequency),u=this._noise(l.x,l.y,l.z,this._time+2e3*this.frequency);this._temp.set(c,d,u).normalize();const f=o/a;let m=this.positionAmount.evaluate(f);this.separateAxes?(this._temp.x*=m*this.strengthXMultiplier,this._temp.y*=m*this.strengthYMultiplier,this._temp.z*=m*this.strengthZMultiplier):(this.strengthX&&(m*=this.strengthX.evaluate(f)*1.5),this._temp.multiplyScalar(m)),i.x+=this._temp.x,i.y+=this._temp.y,i.z+=this._temp.z}}P([p()],_e.prototype,"damping",2);P([p()],_e.prototype,"enabled",2);P([p()],_e.prototype,"frequency",2);P([p()],_e.prototype,"octaveCount",2);P([p()],_e.prototype,"octaveMultiplier",2);P([p()],_e.prototype,"octaveScale",2);P([p(W)],_e.prototype,"positionAmount",2);P([p()],_e.prototype,"quality",2);P([p(W)],_e.prototype,"remap",2);P([p()],_e.prototype,"remapEnabled",2);P([p()],_e.prototype,"remapMultiplier",2);P([p(W)],_e.prototype,"remapX",2);P([p()],_e.prototype,"remapXMultiplier",2);P([p(W)],_e.prototype,"remapY",2);P([p()],_e.prototype,"remapYMultiplier",2);P([p(W)],_e.prototype,"remapZ",2);P([p()],_e.prototype,"remapZMultiplier",2);P([p()],_e.prototype,"scrollSpeedMultiplier",2);P([p()],_e.prototype,"separateAxes",2);P([p()],_e.prototype,"strengthMultiplier",2);P([p(W)],_e.prototype,"strengthX",2);P([p()],_e.prototype,"strengthXMultiplier",2);P([p(W)],_e.prototype,"strengthY",2);P([p()],_e.prototype,"strengthYMultiplier",2);P([p(W)],_e.prototype,"strengthZ",2);P([p()],_e.prototype,"strengthZMultiplier",2);class De{constructor(){r(this,"enabled");r(this,"attachRibbonToTransform",!1);r(this,"colorOverLifetime");r(this,"colorOverTrail");r(this,"dieWithParticles",!0);r(this,"inheritParticleColor",!0);r(this,"lifetime");r(this,"lifetimeMultiplier");r(this,"minVertexDistance",.2);r(this,"mode",0);r(this,"ratio",1);r(this,"ribbonCount",1);r(this,"shadowBias",0);r(this,"sizeAffectsLifetime",!1);r(this,"sizeAffectsWidth",!1);r(this,"splitSubEmitterRibbons",!1);r(this,"textureMode",0);r(this,"widthOverTrail");r(this,"widthOverTrailMultiplier");r(this,"worldSpace",!1)}getWidth(t,e,i,n){const o=this.widthOverTrail.evaluate(i,n);return t*=o,t}getColor(t,e,i){const n=this.colorOverTrail.evaluate(i),o=this.colorOverLifetime.evaluate(e);t.x*=n.r*o.r,t.y*=n.g*o.g,t.z*=n.b*o.b,"alpha"in n&&"alpha"in o&&(t.w*=n.alpha*o.alpha)}}P([p()],De.prototype,"enabled",2);P([p()],De.prototype,"attachRibbonToTransform",2);P([p(Yt)],De.prototype,"colorOverLifetime",2);P([p(Yt)],De.prototype,"colorOverTrail",2);P([p()],De.prototype,"dieWithParticles",2);P([p()],De.prototype,"inheritParticleColor",2);P([p(W)],De.prototype,"lifetime",2);P([p()],De.prototype,"lifetimeMultiplier",2);P([p()],De.prototype,"minVertexDistance",2);P([p()],De.prototype,"mode",2);P([p()],De.prototype,"ratio",2);P([p()],De.prototype,"ribbonCount",2);P([p()],De.prototype,"shadowBias",2);P([p()],De.prototype,"sizeAffectsLifetime",2);P([p()],De.prototype,"sizeAffectsWidth",2);P([p()],De.prototype,"splitSubEmitterRibbons",2);P([p()],De.prototype,"textureMode",2);P([p(W)],De.prototype,"widthOverTrail",2);P([p()],De.prototype,"widthOverTrailMultiplier",2);P([p()],De.prototype,"worldSpace",2);class Ue{constructor(){r(this,"enabled");r(this,"space",0);r(this,"orbitalX");r(this,"orbitalY");r(this,"orbitalZ");r(this,"orbitalXMultiplier");r(this,"orbitalYMultiplier");r(this,"orbitalZMultiplier");r(this,"orbitalOffsetX");r(this,"orbitalOffsetY");r(this,"orbitalOffsetZ");r(this,"speedModifier");r(this,"speedModifierMultiplier");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier");r(this,"_system");r(this,"_temp",new h.Vector3);r(this,"_temp2",new h.Vector3);r(this,"_temp3",new h.Vector3);r(this,"_hasOrbital",!1);r(this,"_index",0);r(this,"_orbitalMatrix",new h.Matrix4)}update(t){this._system=t}init(t){this._index==0&&(t.debug=!0),this._index+=1,t.orbitx=this.orbitalX.evaluate(Math.random()),t.orbity=this.orbitalY.evaluate(Math.random()),t.orbitz=this.orbitalZ.evaluate(Math.random()),this._hasOrbital=t.orbitx!=0||t.orbity!=0||t.orbitz!=0}apply(t,e,i,n,o,a,l){var g;if(!this.enabled)return;const c=a/l,d=this.speedModifier.evaluate(c)*this.speedModifierMultiplier,u=this.x.evaluate(c),f=this.y.evaluate(c),m=this.z.evaluate(c);if(this._temp.set(-u,f,m),this._system&&this._system.main.simulationSpace===1&&this._temp.applyQuaternion(this._system.worldQuaternion),this._hasOrbital&&((g=this._system)==null?void 0:g.worldPos)){const y=this._temp2.set(i.x,i.y,i.z),b=this.orbitalXMultiplier,v=this.orbitalYMultiplier,x=this.orbitalZMultiplier,O=d*Math.PI*2*10,k=Math.cos(O*b),M=Math.sin(O*b),R=Math.cos(O*v),A=Math.sin(O*v),I=Math.cos(O*x),E=Math.sin(O*x),j=y.x*(R*I)+y.y*(R*E)+y.z*-A,F=y.x*(M*A*I-k*E)+y.y*(M*A*E+k*I)+y.z*(M*R),G=y.x*(k*A*I+M*E)+y.y*(k*A*E-M*I)+y.z*(k*R),T=this._temp3.set(y.x-j,y.y-F,y.z-G);T.normalize(),T.multiplyScalar(.2/o*Math.max(this.orbitalXMultiplier,this.orbitalYMultiplier,this.orbitalZMultiplier)),n.x+=T.x,n.y+=T.y,n.z+=T.z}n.x+=this._temp.x,n.y+=this._temp.y,n.z+=this._temp.z,n.x*=d,n.y*=d,n.z*=d}}P([p()],Ue.prototype,"enabled",2);P([p()],Ue.prototype,"space",2);P([p(W)],Ue.prototype,"orbitalX",2);P([p(W)],Ue.prototype,"orbitalY",2);P([p(W)],Ue.prototype,"orbitalZ",2);P([p()],Ue.prototype,"orbitalXMultiplier",2);P([p()],Ue.prototype,"orbitalYMultiplier",2);P([p()],Ue.prototype,"orbitalZMultiplier",2);P([p()],Ue.prototype,"orbitalOffsetX",2);P([p()],Ue.prototype,"orbitalOffsetY",2);P([p()],Ue.prototype,"orbitalOffsetZ",2);P([p(W)],Ue.prototype,"speedModifier",2);P([p()],Ue.prototype,"speedModifierMultiplier",2);P([p(W)],Ue.prototype,"x",2);P([p()],Ue.prototype,"xMultiplier",2);P([p(W)],Ue.prototype,"y",2);P([p()],Ue.prototype,"yMultiplier",2);P([p(W)],Ue.prototype,"z",2);P([p()],Ue.prototype,"zMultiplier",2);class Rt{constructor(){r(this,"animation");r(this,"enabled");r(this,"cycleCount");r(this,"frameOverTime");r(this,"frameOverTimeMultiplier");r(this,"numTilesX");r(this,"numTilesY");r(this,"startFrame");r(this,"startFrameMultiplier");r(this,"rowMode");r(this,"rowIndex");r(this,"spriteCount");r(this,"timeMode")}sampleOnceAtStart(){if(this.timeMode===0)switch(this.frameOverTime.mode){case 0:case 3:case 2:case 1:return!0}return!1}getStartIndex(){return this.sampleOnceAtStart()?Math.random()*(this.numTilesX*this.numTilesY):0}evaluate(t){if(!this.sampleOnceAtStart())return this.getIndex(t)}getIndex(t){const e=this.numTilesX*this.numTilesY;t=t*this.cycleCount;let i=this.frameOverTime.evaluate(t%1);return i*=this.frameOverTimeMultiplier,i*=e,i=i%e,i=Math.floor(i),i}}P([p()],Rt.prototype,"animation",2);P([p()],Rt.prototype,"enabled",2);P([p()],Rt.prototype,"cycleCount",2);P([p(W)],Rt.prototype,"frameOverTime",2);P([p()],Rt.prototype,"frameOverTimeMultiplier",2);P([p()],Rt.prototype,"numTilesX",2);P([p()],Rt.prototype,"numTilesY",2);P([p(W)],Rt.prototype,"startFrame",2);P([p()],Rt.prototype,"startFrameMultiplier",2);P([p()],Rt.prototype,"rowMode",2);P([p()],Rt.prototype,"rowIndex",2);P([p()],Rt.prototype,"spriteCount",2);P([p()],Rt.prototype,"timeMode",2);class qi{constructor(){r(this,"enabled");r(this,"separateAxes");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier")}evaluate(t,e){return this.enabled?this.separateAxes?0:this.z.evaluate(t,e)*-1:0}}P([p()],qi.prototype,"enabled",2);P([p()],qi.prototype,"separateAxes",2);P([p(W)],qi.prototype,"x",2);P([p()],qi.prototype,"xMultiplier",2);P([p(W)],qi.prototype,"y",2);P([p()],qi.prototype,"yMultiplier",2);P([p(W)],qi.prototype,"z",2);P([p()],qi.prototype,"zMultiplier",2);class Ti{constructor(){r(this,"enabled");r(this,"range");r(this,"separateAxes");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier")}evaluate(t,e){if(!this.enabled)return 0;if(!this.separateAxes){const i=z.lerp(this.range.x,this.range.y,e);return this.z.evaluate(i)*-1}return 0}}P([p()],Ti.prototype,"enabled",2);P([p()],Ti.prototype,"range",2);P([p()],Ti.prototype,"separateAxes",2);P([p(W)],Ti.prototype,"x",2);P([p()],Ti.prototype,"xMultiplier",2);P([p(W)],Ti.prototype,"y",2);P([p()],Ti.prototype,"yMultiplier",2);P([p(W)],Ti.prototype,"z",2);P([p()],Ti.prototype,"zMultiplier",2);class Ke{constructor(){r(this,"enabled");r(this,"dampen");r(this,"drag");r(this,"dragMultiplier");r(this,"limit");r(this,"limitMultiplier");r(this,"separateAxes");r(this,"limitX");r(this,"limitXMultiplier");r(this,"limitY");r(this,"limitYMultiplier");r(this,"limitZ");r(this,"limitZMultiplier");r(this,"multiplyDragByParticleSize",!1);r(this,"multiplyDragByParticleVelocity",!1);r(this,"space");r(this,"_temp",new h.Vector3);r(this,"_temp2",new h.Vector3)}apply(t,e,i,n,o,a,l){if(this.enabled){const c=this.limit.evaluate(o)*this.limitMultiplier;if(e.length()>c){this._temp.copy(e).normalize().multiplyScalar(c);const u=this.dampen*.5;e.x=z.lerp(e.x,this._temp.x,u),e.y=z.lerp(e.y,this._temp.y,u),e.z=z.lerp(e.z,this._temp.z,u),i.x=z.lerp(i.x,this._temp.x,u),i.y=z.lerp(i.y,this._temp.y,u),i.z=z.lerp(i.z,this._temp.z,u)}}}}P([p()],Ke.prototype,"enabled",2);P([p()],Ke.prototype,"dampen",2);P([p(W)],Ke.prototype,"drag",2);P([p()],Ke.prototype,"dragMultiplier",2);P([p(W)],Ke.prototype,"limit",2);P([p()],Ke.prototype,"limitMultiplier",2);P([p()],Ke.prototype,"separateAxes",2);P([p(W)],Ke.prototype,"limitX",2);P([p()],Ke.prototype,"limitXMultiplier",2);P([p(W)],Ke.prototype,"limitY",2);P([p()],Ke.prototype,"limitYMultiplier",2);P([p(W)],Ke.prototype,"limitZ",2);P([p()],Ke.prototype,"limitZMultiplier",2);P([p()],Ke.prototype,"multiplyDragByParticleSize",2);P([p()],Ke.prototype,"multiplyDragByParticleVelocity",2);P([p()],Ke.prototype,"space",2);const Mw=class{constructor(){r(this,"enabled");r(this,"curve");r(this,"curveMultiplier");r(this,"mode");r(this,"system");r(this,"_temp",new h.Vector3);r(this,"_firstUpdate",!0);r(this,"_frames",0)}clone(){var t;const s=new Mw;return s.enabled=this.enabled,s.curve=(t=this.curve)==null?void 0:t.clone(),s.curveMultiplier=this.curveMultiplier,s.mode=this.mode,s}get _lastWorldPosition(){return this.system._iv_lastWorldPosition||(this.system._iv_lastWorldPosition=new h.Vector3),this.system._iv_lastWorldPosition}get _velocity(){return this.system._iv_velocity||(this.system._iv_velocity=new h.Vector3),this.system._iv_velocity}awake(s){this.system=s,this.reset()}reset(){this._firstUpdate=!0}update(s){this.enabled&&this.system.worldspace!==!1&&(this._firstUpdate?(this._firstUpdate=!1,this._velocity.set(0,0,0),this._lastWorldPosition.copy(this.system.worldPos)):this._lastWorldPosition&&(this._velocity.copy(this.system.worldPos).sub(this._lastWorldPosition).multiplyScalar(1/this.system.deltaTime),this._lastWorldPosition.copy(this.system.worldPos)))}applyInitial(s){if(this.enabled&&this.system.worldspace!==!1&&this.mode===0){const t=this.curve.evaluate(Math.random(),Math.random());this._temp.copy(this._velocity).multiplyScalar(t),s.x+=this._temp.x,s.y+=this._temp.y,s.z+=this._temp.z}}applyCurrent(s,t,e){if(this.enabled&&this.system&&this.system.worldspace!==!1&&this.mode===1){const i=this.curve.evaluate(t,e);this._temp.copy(this._velocity).multiplyScalar(i),s.x+=this._temp.x,s.y+=this._temp.y,s.z+=this._temp.z}}};let Eo=Mw;P([p()],Eo.prototype,"enabled",2);P([p(W)],Eo.prototype,"curve",2);P([p()],Eo.prototype,"curveMultiplier",2);P([p()],Eo.prototype,"mode",2);class Kt{constructor(){r(this,"enabled");r(this,"range");r(this,"separateAxes");r(this,"size");r(this,"sizeMultiplier");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier")}evaluate(t,e,i,n){const o=t.length(),a=z.remap(o,this.range.x,this.range.y,0,1),l=this.size.evaluate(a,i);return n.x*=l,n.y*=l,n.z*=l,n}}P([p()],Kt.prototype,"enabled",2);P([p(h.Vector2)],Kt.prototype,"range",2);P([p()],Kt.prototype,"separateAxes",2);P([p(W)],Kt.prototype,"size",2);P([p()],Kt.prototype,"sizeMultiplier",2);P([p(W)],Kt.prototype,"x",2);P([p()],Kt.prototype,"xMultiplier",2);P([p(W)],Kt.prototype,"y",2);P([p()],Kt.prototype,"yMultiplier",2);P([p(W)],Kt.prototype,"z",2);P([p()],Kt.prototype,"zMultiplier",2);class Ur{constructor(){r(this,"enabled");r(this,"range");r(this,"color")}evaluate(t,e,i){const n=t.length(),o=z.remap(n,this.range.x,this.range.y,0,1),a=this.color.evaluate(o,e);i.x*=a.r,i.y*=a.g,i.z*=a.b,"alpha"in a&&(i.w*=a.alpha)}}P([p()],Ur.prototype,"enabled",2);P([p(h.Vector2)],Ur.prototype,"range",2);P([p(Yt)],Ur.prototype,"color",2);new h.Vector3(1,1,1);new h.Vector3(0,0,1);class nf{constructor(t,e,i,n){r(this,"type","NeedleParticleSubEmitter");r(this,"emitterType");r(this,"emitterProbability");r(this,"q_",new h.Quaternion);r(this,"v_",new h.Vector3);r(this,"v2_",new h.Vector3);r(this,"_emitterMatrix",new oe.Matrix4);r(this,"_circularBuffer");this.system=t,this.particleSystem=e,this.subSystem=i,this.subParticleSystem=n,this.subParticleSystem&&this.subParticleSystem&&(this.subParticleSystem.onlyUsedByOther=!0);const o=1e3;this._circularBuffer=new Ci(()=>new oe.Matrix4,o)}clone(){throw new Error("Method not implemented.")}initialize(t){t.emissionState={burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0},this._emitterMatrix.copy(this.subSystem.matrixWorld).invert().premultiply(this.system.matrixWorld),this._emitterMatrix.setPosition(0,0,0),this.emitterType===xm.Birth&&this.run(t)}update(t,e){this.run(t)}frameUpdate(t){}toJSON(){}reset(){}run(t){if(this.subSystem.currentParticles>=this.subSystem.main.maxParticles||!this.subParticleSystem||!t.emissionState||this.emitterProbability&&Math.random()>this.emitterProbability)return;const e=this.system.deltaTime;if(this.emitterType===xm.Death){let n=t.life;if(t[_a]!==void 0&&(n=t[_a]),!(t.age+e*1.2>=n))return;const a=this.subSystem.main.maxParticles-this.subSystem.currentParticles;t.emissionState.waitEmiting=a}const i=new oe.Matrix4;i.set(1,0,0,t.position.x,0,1,0,t.position.y,0,0,1,t.position.z,0,0,0,1),this.particleSystem.worldSpace||i.multiplyMatrices(this._emitterMatrix,i),this.subParticleSystem.emit(e,t.emissionState,i)}}var LR=Object.defineProperty,IR=Object.getOwnPropertyDescriptor,ze=(s,t,e,i)=>{for(var n=i>1?void 0:i?IR(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&LR(t,e,n),n};const qs=S("debugparticles"),jR=S("noprogressive"),BR=S("debugprogressive");var xm=(s=>(s[s.Birth=0]="Birth",s[s.Collision=1]="Collision",s[s.Death=2]="Death",s[s.Trigger=3]="Trigger",s[s.Manual=4]="Manual",s))(xm||{});class Xi extends D{constructor(){super(...arguments);r(this,"renderMode");r(this,"particleMaterial");r(this,"trailMaterial");r(this,"particleMesh");r(this,"maxParticleSize");r(this,"minParticleSize");r(this,"velocityScale");r(this,"cameraVelocityScale");r(this,"lengthScale")}start(){if(this.maxParticleSize!==.5&&this.minParticleSize!==0&&B()){const e=`ParticleSystem "${this.name}" has non-default min/max particle size. This may not render correctly. Please set min size to 0 and the max size to 0.5 and use the "StartSize" setting instead`;console.warn(e)}}get transparent(){var i;return((i=this.particleMaterial)==null?void 0:i.transparent)??!1}getMaterial(e=!1){let i=e===!0&&this.trailMaterial?this.trailMaterial:this.particleMaterial;if(i){if(i.type==="MeshStandardMaterial"){qs&&console.debug("ParticleSystemRenderer.getMaterial: MeshStandardMaterial detected, converting to MeshBasicMaterial. See https://github.com/Alchemist0823/three.quarks/issues/101"),"map"in i&&i.map&&(i.map.colorSpace=h.LinearSRGBColorSpace,i.map.premultiplyAlpha=!1);const n=new h.MeshBasicMaterial;n.copy(i),e?this.trailMaterial=n:this.particleMaterial=n}i.map&&(i.map.colorSpace=h.LinearSRGBColorSpace,i.map.premultiplyAlpha=!1),e&&i.side===h.FrontSide&&(i=i.clone(),i.side=h.BackSide,e?this.trailMaterial=i:this.particleMaterial=i)}return i&&!jR&&i._didRequestTextureLOD===void 0&&(i._didRequestTextureLOD=0,BR&&console.log("Load material LOD",i.name),re.NEEDLE_progressive.assignTextureLOD(i,0)),i}getMesh(e){let i=null;if(!i&&(this.particleMesh instanceof h.Mesh&&(i=this.particleMesh.geometry),i===null)){i=new h.PlaneGeometry(1,1);const o=i.attributes.uv;for(let a=0;a<o.count;a++)o.setX(a,1-o.getX(a))}return new h.Mesh(i,this.getMaterial())}}ze([p()],Xi.prototype,"renderMode",2);ze([p(h.Material)],Xi.prototype,"particleMaterial",2);ze([p(h.Material)],Xi.prototype,"trailMaterial",2);ze([p()],Xi.prototype,"maxParticleSize",2);ze([p()],Xi.prototype,"minParticleSize",2);ze([p()],Xi.prototype,"velocityScale",2);ze([p()],Xi.prototype,"cameraVelocityScale",2);ze([p()],Xi.prototype,"lengthScale",2);class rd{constructor(t,e=1){r(this,"_curve");r(this,"_factor");r(this,"type","function");this._curve=t,this._factor=e}startGen(t){}genValue(t,e){return this._curve.evaluate(e,Math.random())*this._factor}toJSON(){throw new Error("Method not implemented.")}clone(){throw new Error("Method not implemented.")}}class o_{constructor(t){r(this,"type","value");r(this,"system");this.system=t}toJSON(){throw new Error("Method not implemented.")}clone(){throw new Error("Method not implemented.")}startGen(t){}}class FR extends o_{genValue(){return this.system.textureSheetAnimation.getStartIndex()}}class UR extends o_{constructor(){super(...arguments);r(this,"_lastPosition",new h.Vector3);r(this,"_lastDistance",0)}update(){const e=K(this.system.gameObject);this._lastDistance=this._lastPosition.distanceTo(e),this._lastPosition.copy(e)}genValue(){if(!this.system.isPlaying||!this.system.emission.enabled||this.system.currentParticles>=this.system.maxParticles)return 0;let e=this.system.emission.rateOverTime.evaluate(this.system.time/this.system.duration,Math.random());if(this.system.deltaTime>0){const o=this.system.emission.rateOverDistance.evaluate(this.system.time/this.system.duration,Math.random());let l=this._lastDistance/this.system.deltaTime*o;Number.isFinite(l)||(l=0),e+=l}const i=this.system.emission.getBurst();i>0&&(e+=i/this.system.deltaTime);const n=this.system.maxParticles-this.system.currentParticles;return z.clamp(e,0,n/this.system.deltaTime)}}class zR extends o_{genValue(){return this.system.isPlaying,0}}class Ao{constructor(t){r(this,"system");r(this,"type");this.type=Object.getPrototypeOf(this).constructor.name||"ParticleSystemBaseBehaviour",t&&(this.system=t)}get context(){return this.system.context}initialize(t){}update(t,e){}frameUpdate(t){}toJSON(){throw new Error("Method not implemented.")}clone(){throw new Error("Method not implemented.")}reset(){}}class NR extends Ao{constructor(){super(...arguments);r(this,"type","NeedleTextureSheet")}update(e,i){const n=this.system.textureSheetAnimation;if(n.enabled){const o=e.age/e.life,a=n.evaluate(o);a!==void 0&&(e.uvTile=a)}}}const lb=Symbol("particleRotation");class VR extends Ao{constructor(){super(...arguments);r(this,"type","NeedleRotation")}initialize(e){e[lb]=Math.random()}update(e,i){if(e.rotation===void 0)return;const n=e.age/e.life;if(typeof e.rotation=="number"&&(this.system.rotationOverLifetime.enabled?e.rotation+=this.system.rotationOverLifetime.evaluate(n,e[lb])*i:this.system.renderer.renderMode===ds.Billboard&&(e.rotation=Math.PI),this.system.rotationBySpeed.enabled)){const o=e.velocity.length();e.rotation+=this.system.rotationBySpeed.evaluate(n,o)*i}}}const cb=Symbol("sizeLerpFactor"),$R=new h.Vector3;class WR extends Ao{constructor(){super(...arguments);r(this,"type","NeedleSize");r(this,"_minSize",0);r(this,"_maxSize",1)}initialize(e){e[cb]=Math.random(),this._minSize=this.system.renderer.minParticleSize,this._maxSize=this.system.renderer.maxParticleSize}update(e,i){const n=e.age/e.life;let o=1;this.system.sizeOverLifetime.enabled&&(o*=this.system.sizeOverLifetime.evaluate(n,void 0,e[cb]).x);let a=1;this.system.renderer.renderMode!==ds.Mesh&&(a=this.system.worldScale.x/this.system.cameraScale);const l=V(e.startSize).multiplyScalar(o*a);if(e.size.set(l.x,l.y,l.z),this.system.localspace){const c=Rw(this.system,$R);e.size.x*=c.x,e.size.y*=c.y,e.size.z*=c.z}}}const _a=Symbol("particleLife"),dp=Symbol("trailLifetime"),hb=Symbol("trailStartLength"),up=Symbol("trailWidthRandom");class HR extends Ao{constructor(){super(...arguments);r(this,"type","NeedleTrail")}initialize(e){e instanceof oe.TrailParticle&&(e[_a]=e.life,this.system.trails.enabled&&this.system.trails.dieWithParticles===!1&&(e[dp]=this.system.trails.lifetime.evaluate(Math.random(),Math.random()),e.life+=e[dp]),e[hb]=e.length,e[up]=Math.random())}update(e){var i;if((i=this.system.trails)!=null&&i.enabled&&e instanceof oe.TrailParticle){const n=e,o=e.age/e[_a],a=e.previous.values(),l=e.previous.length;for(let c=0;c<l;c++){const u=a.next().value,f=1-c/(l-1),m=e.size;if(m.x<=0&&!this.system.trails.sizeAffectsWidth){const g=20*this.system.trails.widthOverTrail.evaluate(.5,n[up]);m.x=g,m.y=g,m.z=g}u.size=this.system.trails.getWidth(m.x,o,f,n[up]),u.color.copy(e.color),this.system.trails.getColor(u.color,o,f)}if(e.age>e[_a]){e.velocity.set(0,0,0);const c=(e.age-e[_a])/e[dp];n.length=z.lerp(e[hb],0,c)}}}}const ad=Symbol("startVelocity"),db=Symbol("gravityModifier"),fp=Symbol("gravitySpeed"),ld=Symbol("velocity lerp factor"),Sm=new h.Vector3;class GR extends Ao{constructor(){super(...arguments);r(this,"type","NeedleVelocity");r(this,"_gravityDirection",new h.Vector3)}initialize(e){var a,l;const i=this.system.main.simulationSpeed;e.startSpeed=this.system.main.startSpeed.evaluate(Math.random(),Math.random());const n=this.system.shape.getDirection(e,e.position);e.velocity.x=n.x*e.startSpeed,e.velocity.y=n.y*e.startSpeed,e.velocity.z=n.z*e.startSpeed,(a=this.system.inheritVelocity)!=null&&a.enabled&&this.system.inheritVelocity.applyInitial(e.velocity),e[ad]?e[ad].copy(e.velocity):e[ad]=e.velocity.clone();const o=this.system.main.gravityModifier.evaluate(Math.random(),Math.random());e[db]=o*i,e[fp]=o*i*.5,e[ld]=Math.random(),(l=this.system.velocityOverLifetime)==null||l.init(e),this._gravityDirection.set(0,-1,0),this.system.main.simulationSpace===Tc.Local&&this._gravityDirection.applyQuaternion(this.system.worldQuaternionInverted).normalize()}update(e,i){var m;const n=e[ad],o=e[db];if(o!==0){const g=o*e[fp];Sm.copy(this._gravityDirection).multiplyScalar(g),e[fp]+=i*.05,n.add(Sm)}e.velocity.copy(n);const a=e.age/e.life;(m=this.system.inheritVelocity)!=null&&m.enabled&&this.system.inheritVelocity.applyCurrent(e.velocity,a,e[ld]);const l=this.system.noise;l.enabled&&l.apply(0,e.position,e.velocity,i,e.age,e.life);const c=this.system.sizeBySpeed;c!=null&&c.enabled&&(e.size=c.evaluate(e.velocity,a,e[ld],e.size));const d=this.system.colorBySpeed;d!=null&&d.enabled&&d.evaluate(e.velocity,e[ld],e.color);const u=this.system.velocityOverLifetime;u.enabled&&u.apply(e,0,e.position,e.velocity,i,e.age,e.life);const f=this.system.limitVelocityOverLifetime;if(f.enabled&&f.apply(e.position,n,e.velocity,e.size,a,i,1),this.system.worldspace){const g=this.system.worldScale;e.velocity.x*=g.x,e.velocity.y*=g.y,e.velocity.z*=g.z}}}const ub=Symbol("colorLerpFactor"),fb=new ge(1,1,1,1),Vo=new ge(1,1,1,1);class qR extends Ao{constructor(){super(...arguments);r(this,"type","NeedleColor")}initialize(e){}_init(e){const i=this.system.renderer.particleMaterial;Vo.copy(this.system.main.startColor.evaluate(Math.random())),i!=null&&i.color&&(fb.copy(i.color),Vo.multiply(fb)),Vo.convertLinearToSRGB(),e.startColor.set(Vo.r,Vo.g,Vo.b,Vo.alpha),e.color.copy(e.startColor),e[ub]=Math.random()}update(e,i){if(e.age===0&&this._init(e),this.system.colorOverLifetime.enabled){const n=e.age/e.life,o=this.system.colorOverLifetime.color.evaluate(n,e[ub]);e.color.set(o.r,o.g,o.b,"alpha"in o?o.alpha:1).multiply(e.startColor)}else e.color.copy(e.startColor)}}class XR{constructor(t){r(this,"system");r(this,"emission");r(this,"autoDestroy");r(this,"startLength");r(this,"emissionBursts");r(this,"onlyUsedByOther");r(this,"behaviors",[]);r(this,"rendererEmitterSettings",{startLength:new oe.ConstantValue(220),followLocalOrigin:!1});r(this,"flatWhiteTexture");r(this,"clonedTexture",{original:void 0,clone:void 0});this.system=t,this.emission=new UR(this.system)}get anim(){return this.system.textureSheetAnimation}get prewarm(){return!1}get material(){return this.system.renderer.getMaterial(this.system.trails.enabled)}get layers(){return this.system.gameObject.layers}update(){this.emission.update()}get looping(){return this.system.main.loop}get duration(){return this.system.duration}get shape(){return this.system.shape}get startLife(){return new rd(this.system.main.startLifetime)}get startSpeed(){return new rd(this.system.main.startSpeed)}get startRotation(){return new rd(this.system.main.startRotation)}get startSize(){return new rd(this.system.main.startSize)}get startColor(){return new oe.ConstantColor(new oe.Vector4(1,1,1,1))}get emissionOverTime(){return this.emission}get emissionOverDistance(){return new zR(this.system)}get instancingGeometry(){return this.system.renderer.getMesh(this.system.renderer.renderMode).geometry}get renderMode(){if(this.system.trails.enabled===!0)return oe.RenderMode.Trail;switch(this.system.renderer.renderMode){case ds.Billboard:return oe.RenderMode.BillBoard;case ds.Stretch:return oe.RenderMode.StretchedBillBoard;case ds.HorizontalBillboard:return oe.RenderMode.HorizontalBillBoard;case ds.VerticalBillboard:return oe.RenderMode.VerticalBillBoard;case ds.Mesh:return oe.RenderMode.Mesh}return oe.RenderMode.BillBoard}get speedFactor(){var e;let t=this.system.main.simulationSpeed;return((e=this.system.renderer)==null?void 0:e.renderMode)===ds.Stretch&&(t*=this.system.renderer.velocityScale??1),t}get texture(){const t=this.material;if(t&&t.map){const e=t.map;if(this.clonedTexture.original!==e||!this.clonedTexture.clone){const i=e.clone();i.premultiplyAlpha=!1,i.colorSpace=h.LinearSRGBColorSpace,this.clonedTexture.original=e,this.clonedTexture.clone=i}return this.clonedTexture.clone}return this.flatWhiteTexture||(this.flatWhiteTexture=fg(new ge(1,1,1,1),1)),this.flatWhiteTexture}get startTileIndex(){return new FR(this.system)}get uTileCount(){var t;return this.anim.enabled?(t=this.anim)==null?void 0:t.numTilesX:void 0}get vTileCount(){var t;return this.anim.enabled?(t=this.anim)==null?void 0:t.numTilesY:void 0}get renderOrder(){return 1}get blending(){var t;return((t=this.system.renderer.particleMaterial)==null?void 0:t.blending)??h.NormalBlending}get transparent(){return this.system.renderer.transparent}get worldSpace(){return this.system.main.simulationSpace===Tc.World}}class QR{constructor(){r(this,"burstParticleIndex",0);r(this,"burstParticleCount",0);r(this,"isBursting",!1);r(this,"travelDistance",0);r(this,"previousWorldPos");r(this,"burstIndex",0);r(this,"burstWaveIndex",0);r(this,"time",0);r(this,"waitEmiting",0)}}const Ed=class extends D{constructor(){super(...arguments);r(this,"_state");r(this,"colorOverLifetime");r(this,"main");r(this,"emission");r(this,"sizeOverLifetime");r(this,"shape");r(this,"noise");r(this,"trails");r(this,"velocityOverLifetime");r(this,"limitVelocityOverLifetime");r(this,"inheritVelocity");r(this,"colorBySpeed");r(this,"textureSheetAnimation");r(this,"rotationOverLifetime");r(this,"rotationBySpeed");r(this,"sizeBySpeed");r(this,"_cameraScale",1);r(this,"__worldQuaternion",new h.Quaternion);r(this,"_worldQuaternionInverted",new h.Quaternion);r(this,"_worldScale",new h.Vector3);r(this,"_worldPositionFrame",-1);r(this,"_worldPos",new h.Vector3);r(this,"_renderer");r(this,"_batchSystem");r(this,"_particleSystem");r(this,"_interface");r(this,"_container");r(this,"_time",0);r(this,"_isPlaying",!0);r(this,"_isUsedAsSubsystem",!1);r(this,"_didPreWarm",!1);r(this,"_bursts");r(this,"_subEmitterSystems");r(this,"_lastBatchesCount",-1)}play(t=!1){var e;t&&C.foreachComponent(this.gameObject,i=>{i instanceof Ed&&i!==this&&i.play(!1)},!0),this._isPlaying=!0,this._particleSystem&&(this._particleSystem.emissionState.time=0,this._particleSystem.emitEnded=!1),(e=this.emission)==null||e.reset()}pause(t=!0){t&&C.foreachComponent(this.gameObject,e=>{e instanceof Ed&&e!==this&&e.pause(!1)},!0),this._isPlaying=!1}stop(t=!0,e=!1){t&&C.foreachComponent(this.gameObject,i=>{i instanceof Ed&&i!==this&&i.stop(!1,e)},!0),this._isPlaying=!1,this._time=0,e&&this.reset()}reset(){var t;this._time=0,this._particleSystem&&(this._particleSystem.particleNum=0,this._particleSystem.emissionState.time=0,this._particleSystem.emitEnded=!1,(t=this.emission)==null||t.reset())}emit(t){if(this._particleSystem){this.onUpdate(),t=Math.min(t,this.maxParticles-this.currentParticles),this._state||(this._state=new QR),this._state.waitEmiting=t,this._state.time=0;const e=this._particleSystem.emitEnded;this._particleSystem.emitEnded=!1,this._particleSystem.emit(this.deltaTime,this._state,this._particleSystem.emitter.matrixWorld),this._particleSystem.emitEnded=e}}get playOnAwake(){return this.main.playOnAwake}set playOnAwake(t){this.main.playOnAwake=t}get renderer(){return this._renderer}get isPlaying(){return this._isPlaying}get currentParticles(){var t;return((t=this._particleSystem)==null?void 0:t.particleNum)??0}get maxParticles(){return this.main.maxParticles}get time(){return this._time}get duration(){return this.main.duration}get deltaTime(){return this.context.time.deltaTime*this.main.simulationSpeed}get scale(){return this.gameObject.scale.x}get cameraScale(){return this._cameraScale}get container(){return this._container}get worldspace(){return this.main.simulationSpace===Tc.World}get localspace(){return this.main.simulationSpace===Tc.Local}get worldQuaternion(){return this.__worldQuaternion}get worldQuaternionInverted(){return this._worldQuaternionInverted}get worldScale(){return this._worldScale}get worldPos(){return this._worldPositionFrame!==this.context.time.frame&&(this._worldPositionFrame=this.context.time.frame,K(this.gameObject,this._worldPos)),this._worldPos}get matrixWorld(){return this._container.matrixWorld}get isSubsystem(){return this._isUsedAsSubsystem}addBehaviour(t){return this._particleSystem?(t instanceof Ao&&(t.system=this),(B()||qs)&&console.debug("Add custom ParticleSystem Behaviour",t),this._particleSystem.addBehavior(t),!0):!1}removeBehaviour(t){if(!this._particleSystem)return!1;const e=this._particleSystem.behaviors,i=e.indexOf(t);return i!==-1&&((B()||qs)&&console.debug("Remove custom ParticleSystem Behaviour",i,t),e.splice(i,1)),!0}removeAllBehaviours(){return this._particleSystem?(this._particleSystem.behaviors.length=0,!0):!1}get behaviours(){return this._particleSystem?this._particleSystem.behaviors:null}get particleSystem(){return this._particleSystem??null}set bursts(t){for(let e=0;e<t.length;e++){const i=t[e];if(!(i instanceof Ec)){const n=new Ec;ja(n,i),t[e]=n}}this._bursts=t}set subEmitterSystems(t){for(let e=0;e<t.length;e++){const i=t[e];if(!(i instanceof Ac)){const n=new Ac;ja(n,i),t[e]=n}}qs&&t.length>0&&console.log("SubEmitters: ",t,this),this._subEmitterSystems=t}onAfterDeserialize(t){if(this._subEmitterSystems&&Array.isArray(this._subEmitterSystems))for(const e of this._subEmitterSystems)e._deserialize(this.context,this.gameObject)}awake(){if(this._worldPositionFrame=-1,this._renderer=this.gameObject.getComponent(Xi),!this.main)throw new Error("Not Supported: ParticleSystem needs a serialized MainModule. Creating new particle systems at runtime is currently not supported.");this._container=new h.Object3D,this._container.matrixAutoUpdate=!1,this.context.scene.add(this._container),this._batchSystem=new oe.BatchedParticleRenderer,this._batchSystem.name=this.gameObject.name,this._container.add(this._batchSystem),this._interface=new XR(this),this._particleSystem=new oe.ParticleSystem(this._interface),this._particleSystem.addBehavior(new WR(this)),this._particleSystem.addBehavior(new qR(this)),this._particleSystem.addBehavior(new NR(this)),this._particleSystem.addBehavior(new VR(this)),this._particleSystem.addBehavior(new GR(this)),this._particleSystem.addBehavior(new HR(this)),this._batchSystem.addSystem(this._particleSystem);const t=this._particleSystem.emitter;this.context.scene.add(t),this.inheritVelocity.system&&this.inheritVelocity.system!==this&&(this.inheritVelocity=this.inheritVelocity.clone()),this.inheritVelocity.awake(this),qs&&(console.log(this),this.gameObject.add(new h.AxesHelper(1)))}start(){this.addSubParticleSystems(),this.updateLayers(),this.renderer.particleMesh instanceof h.Mesh&&this._interface.renderMode==oe.RenderMode.Mesh&&re.NEEDLE_progressive.assignMeshLOD(this.renderer.particleMesh,0).then(t=>{t&&this.particleSystem&&this._interface.renderMode==oe.RenderMode.Mesh&&(this.particleSystem.instancingGeometry=t)})}onDestroy(){var t,e,i,n;(t=this._container)==null||t.removeFromParent(),(e=this._batchSystem)==null||e.removeFromParent(),(i=this._particleSystem)==null||i.emitter.removeFromParent(),(n=this._particleSystem)==null||n.dispose()}onEnable(){this.main&&(this.inheritVelocity&&(this.inheritVelocity.system=this),this._batchSystem&&(this._batchSystem.visible=!0),this.playOnAwake&&this.play(),this._isPlaying=this.playOnAwake)}onDisable(){this._batchSystem&&(this._batchSystem.visible=!1)}onBeforeRender(){var t;this.main&&(this._didPreWarm===!1&&((t=this.main)==null?void 0:t.prewarm)===!0&&(this._didPreWarm=!0,this.preWarm()),this.onUpdate(),this.onSimulate(this.deltaTime))}preWarm(){var d;if(!((d=this.emission)!=null&&d.enabled)||this.emission.rateOverTime.getMax()<=0)return;const e=1/60,i=this.main.duration,n=this.main.startLifetime.getMax(),o=1e3,a=Math.min(Math.max(i,n)/Math.max(.01,this.main.simulationSpeed),o),l=Math.ceil(a/e),c=Date.now();qs&&console.log(`Particles ${this.name} - Prewarm for ${l} frames (${a} sec). Duration: ${i}, Lifetime: ${n}`);for(let u=0;u<l&&!(this.currentParticles>=this.maxParticles);u++){const f=Date.now()-c;if(f>2e3){console.warn(`Particles ${this.name} - Prewarm took too long. Aborting: ${f}`);break}this.onUpdate(),this.onSimulate(e)}}onSimulate(t){if(this._batchSystem){let e=this.context.time.frameCount%60===0;this._lastBatchesCount!==this._batchSystem.batches.length&&(this._lastBatchesCount=this._batchSystem.batches.length,e=!0),e&&this.updateLayers(),this._batchSystem.update(t)}this._time+=t,this._time>this.duration&&(this._time=0)}updateLayers(){if(this._batchSystem)for(let t=0;t<this._batchSystem.batches.length;t++){const e=this._batchSystem.batches[t];e.layers.disableAll();const i=this.layer;e.layers.mask=1<<i}}onUpdate(){var n,o;if(this._bursts&&(this.emission.bursts=this._bursts,delete this._bursts),!this._isPlaying)return;const t=this.context.mainCamera;if(t){const a=Ne(t);this._cameraScale=a.x}const e=!this.worldspace,i=this.gameObject;if(ye(i,this.__worldQuaternion),this._worldQuaternionInverted.copy(this.__worldQuaternion).invert(),Ne(this.gameObject,this._worldScale),e&&this._container&&((n=this.gameObject)!=null&&n.parent)){const a=Rw(this,Sm);this._container.matrix.makeScale(a.x,a.y,a.z),this._container.matrix.makeRotationFromQuaternion(this.__worldQuaternion),this._container.matrix.setPosition(this.worldPos),this._container.matrix.scale(this.gameObject.scale)}this.emission.system=this,this._interface.update(),this.shape.onUpdate(this,this.context,this.main.simulationSpace,this.gameObject),this.noise.update(this.context),(o=this.inheritVelocity)==null||o.update(this.context),this.velocityOverLifetime.update(this)}addSubParticleSystems(){var t;if(this._subEmitterSystems&&this._particleSystem)for(const e of this._subEmitterSystems){e.particleSystem&&(e.particleSystem.__internalAwake?e.particleSystem.__internalAwake():B()&&console.warn("SubParticleSystem serialization issue(?)",e.particleSystem,e));const i=(t=e.particleSystem)==null?void 0:t._particleSystem;if(i){e.particleSystem._isUsedAsSubsystem=!0;const n=new nf(this,this._particleSystem,e.particleSystem,i);n.emitterType=e.type,n.emitterProbability=e.emitProbability,this._particleSystem.addBehavior(n)}else qs&&console.warn("Could not add SubParticleSystem",e,this)}}};let Qe=Ed;ze([p(yh)],Qe.prototype,"colorOverLifetime",2);ze([p(Mt)],Qe.prototype,"main",2);ze([p(Qn)],Qe.prototype,"emission",2);ze([p(To)],Qe.prototype,"sizeOverLifetime",2);ze([p(Fe)],Qe.prototype,"shape",2);ze([p(_e)],Qe.prototype,"noise",2);ze([p(De)],Qe.prototype,"trails",2);ze([p(Ue)],Qe.prototype,"velocityOverLifetime",2);ze([p(Ke)],Qe.prototype,"limitVelocityOverLifetime",2);ze([p(Eo)],Qe.prototype,"inheritVelocity",2);ze([p(Ur)],Qe.prototype,"colorBySpeed",2);ze([p(Rt)],Qe.prototype,"textureSheetAnimation",2);ze([p(qi)],Qe.prototype,"rotationOverLifetime",2);ze([p(Ti)],Qe.prototype,"rotationBySpeed",2);ze([p(Kt)],Qe.prototype,"sizeBySpeed",2);class Ac{constructor(){r(this,"particleSystem");r(this,"emitProbability",1);r(this,"properties");r(this,"type")}_deserialize(t,e){const i=this.particleSystem;if(i instanceof Qe)return;let n="";i&&typeof i.guid=="string"&&(n=i.guid,this.particleSystem=C.findByGuid(n,e)),qs&&!(this.particleSystem instanceof Qe)&&console.warn("Could not find particle system for sub emitter",n,e,this)}}function Rw(s,t){if(t.set(1,1,1),s.gameObject.parent&&s.localspace)switch(s.main.scalingMode){case wm.Local:t=Ne(s.gameObject.parent,t),t.x=1/t.x,t.y=1/t.y,t.z=1/t.z;break;default:if(!s.unsupported_scaling_mode){s.unsupported_scaling_mode=!0;const e="ParticleSystem scale mode "+wm[s.main.scalingMode]+" is not supported";B()&&me(e),console.warn(e,s.name,s)}t=Ne(s.gameObject,t);break}return t}class Ua extends D{constructor(){super(...arguments);r(this,"_didAssignPlayerColor",!1);r(this,"tryAssignColor",()=>{const e=C.getComponentInParent(this.gameObject,wi);if(e&&e.owner)return this._didAssignPlayerColor=!0,this.assignUserColor(e.owner),!0;const i=C.getComponentInParent(this.gameObject,it);return i!=null&&i.connectionId?(this._didAssignPlayerColor=!0,this.assignUserColor(i.connectionId),!0):!1})}onEnable(){this.context.connection.beginListen(Z.JoinedRoom,this.tryAssignColor),this._didAssignPlayerColor||this.startCoroutine(this.waitForConnection())}onDisable(){this.context.connection.stopListen(Z.JoinedRoom,this.tryAssignColor)}*waitForConnection(){for(;!this.destroyed&&this.activeAndEnabled&&(yield d0(.2),!this.tryAssignColor()););}assignUserColor(e){const i=Ua.hashCode(e),n=Ua.colorFromHashCode(i);if(this.gameObject.type==="Mesh"){const o=this.gameObject;this.assignColor(n,e,o)}else if(this.gameObject.children)for(const o of this.gameObject.children){const a=o;a.material&&a.material.color&&this.assignColor(n,e,a)}}assignColor(e,i,n){let o=n.material;o&&(o._playerMaterial!==i&&(o=o.clone(),o._playerMaterial=i,n.material=o),o.color=e)}static hashCode(e){var i=0,n,o;if(e.length===0)return i;for(n=0;n<e.length;n++)o=e.charCodeAt(n),i=(i<<5)-i+o,i|=0;return i}static colorFromHashCode(e){const i=(e&16711680)>>16,n=(e&65280)>>8,o=e&255;return new h.Color(i/255,n/255,o/255)}}const YR=S("debugpost");let Cm=null;function KR(s){Cm=s}function kw(s){let t=s.gameObject;for(;t;){for(const e of Au(t))if(e.isPostProcessingManager===!0)return e;t=t.parent}return null}function ZR(s){let t=kw(s);if(!t)if(Cm){YR&&console.warn("Adding postprocessing manager to the scene.");const e=s.scene;t=xi(e,Cm)}else B()&&console.warn("No post processing manager found");return t}var JR=Object.defineProperty,ek=Object.getOwnPropertyDescriptor,Tw=(s,t,e,i)=>{for(var n=i>1?void 0:i?ek(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&JR(t,e,n),n};const tk=S("debugpost");class U{constructor(t){r(this,"isVolumeParameter",!0);r(this,"_isInitialized",!1);r(this,"_active",!0);r(this,"_value");r(this,"_valueRaw");r(this,"_defaultValue");r(this,"valueProcessor");r(this,"onValueChanged");t!==void 0&&this.initialize(t)}get isInitialized(){return this._isInitialized}initialize(t){t!==void 0&&(this._value=t,this._defaultValue=t,this._valueRaw=t,this._isInitialized=!0)}get overrideState(){return this._active}set overrideState(t){if(this._active===t)return;this._active=t;const e=t?this._valueRaw:this._defaultValue;this.processValue(e,!0)}get value(){return this._valueRaw}set value(t){this.isInitialized||this.initialize(t),this.processValue(t,!1)}set defaultValue(t){this._defaultValue=t}__init(){this.processValue(this._valueRaw,!0)}processValue(t,e){if(t==null||!e&&this.testIfValueChanged(t)===!1)return;const i=this._value;tk&&typeof i=="number"&&typeof t=="number"&&(i==null||i.toFixed(4),t==null||t.toFixed(4)),!this._active&&this._defaultValue!==void 0?(this._value=this._defaultValue,t=this._defaultValue,this._valueRaw=t):(this._valueRaw=t,this._active&&this.valueProcessor&&(t=this.valueProcessor(t)),this._value=t),this.onValueChanged&&this.onValueChanged(t,i,this)}testIfValueChanged(t){return this._valueRaw!==t}}Tw([p()],U.prototype,"overrideState",1);Tw([p()],U.prototype,"value",1);class ik extends Gi{constructor(){super([U])}onSerialize(t,e){}onDeserialize(t,e){const i=e.target,n=e.path;let o;if(i&&n&&(o=i[n]),(typeof o!="object"||typeof o=="object"&&o.isVolumeParameter!==!0)&&(o=new U),typeof t=="object"&&"value"in t){const a=t.value;o.initialize(a),o.overrideState=t.overrideState}else o.value=t;return o}}new ik;var nk=Object.defineProperty,sk=Object.getOwnPropertyDescriptor,ok=(s,t,e,i)=>{for(var n=i>1?void 0:i?sk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&nk(t,e,n),n};const rk=S("debugpost");class Xe extends D{constructor(e=void 0){super();r(this,"active",!0);r(this,"_manager",null);r(this,"_result");r(this,"_postprocessingContext",null);if(e)for(const i of Object.keys(e)){const n=e[i],o=this[i];o instanceof U?o.initialize(n):o!==void 0&&(this[i]=n)}}get isPostProcessingEffect(){return!0}onEnable(){super.onEnable(),this.onEffectEnabled(),this.__internalDidAwakeAndStart&&(this.active=!0)}onDisable(){var e;super.onDisable(),(e=this._manager)==null||e.removeEffect(this),this.active=!1}onEffectEnabled(e){var i;e&&e.isPostProcessingManager===!0?this._manager=e:this._manager||(this._manager=ZR(this)),(i=this._manager)==null||i.addEffect(this)}init(){}get postprocessingContext(){return this._postprocessingContext}apply(e){var i;return this._postprocessingContext=e,this._result||(this.initParameters(),this._result=(i=this.onCreateEffect)==null?void 0:i.call(this)),this._result&&this.initParameters(),this._result}unapply(){}dispose(){rk&&console.warn("DISPOSE",this),this._result&&(Array.isArray(this._result)?this._result.forEach(e=>e.dispose()):this._result.dispose()),this._result=void 0}initParameters(){const e=Object.keys(this);for(const i of e){const n=this[i];n instanceof U&&n.__init()}}onEditorModification(e){const i=e.propertyName;if(this[i]instanceof U){const n=e.value;return this[i].value=n,!0}}}ok([p()],Xe.prototype,"active",2);var ak=Object.defineProperty,lk=Object.getOwnPropertyDescriptor,ck=(s,t,e,i)=>{for(var n=i>1?void 0:i?lk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&ak(t,e,n),n};const hk=S("debugpost"),Pm={};function Qi(s,t){Pm[s]=t}function dk(s){return s.__type in Pm?Pm[s.__type]:(hk&&s.__type&&console.warn("Unknown postprocessing type",s.__type,s),Xe)}class bh{constructor(){r(this,"components",[])}init(){var t;(t=this.components)==null||t.forEach(e=>e.init())}addEffect(t){this.components.push(t)}removeEffect(t){const e=this.components.indexOf(t);e>=0&&this.components.splice(e,1)}}ck([Va([s=>dk(s),Xe])],bh.prototype,"components",2);var uk=Object.defineProperty,fk=Object.getOwnPropertyDescriptor,pk=(s,t,e,i)=>{for(var n=i>1?void 0:i?fk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&uk(t,e,n),n};class vh extends Xe{constructor(){super(...arguments);r(this,"preset",new U(2))}get typeName(){return"Antialiasing"}onCreateEffect(){const e=new exports.MODULES.POSTPROCESSING.MODULE.SMAAEffect({preset:exports.MODULES.POSTPROCESSING.MODULE.SMAAPreset.HIGH,edgeDetectionMode:exports.MODULES.POSTPROCESSING.MODULE.EdgeDetectionMode.DEPTH});return this.preset.onValueChanged=i=>{e.applyPreset(i)},e}}pk([p(U)],vh.prototype,"preset",2);Qi("Antialiasing",vh);var mk=Object.defineProperty,gk=Object.getOwnPropertyDescriptor,r_=(s,t,e,i)=>{for(var n=i>1?void 0:i?gk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&mk(t,e,n),n},Ep;const Ew=(Ep=class extends Xe{constructor(){super(...arguments);r(this,"threshold",new U(.9));r(this,"intensity",new U(1));r(this,"scatter",new U(.3));r(this,"selectiveBloom")}get typeName(){return"Bloom"}init(){this.threshold.valueProcessor=t=>t,this.intensity.valueProcessor=t=>t,this.scatter.valueProcessor=t=>t}onCreateEffect(){let t;if(this.selectiveBloom==null&&(this.selectiveBloom=Ew.useSelectiveBloom),this.selectiveBloom){const e=t=new exports.MODULES.POSTPROCESSING.MODULE.SelectiveBloomEffect(this.context.scene,this.context.mainCamera,{blendFunction:exports.MODULES.POSTPROCESSING.MODULE.BlendFunction.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,radius:.85,intensity:this.intensity.value});e.inverted=!0}else t=new exports.MODULES.POSTPROCESSING.MODULE.BloomEffect({blendFunction:exports.MODULES.POSTPROCESSING.MODULE.BlendFunction.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,radius:.85,intensity:this.intensity.value});return this.intensity.onValueChanged=e=>{t.intensity=e},this.threshold.onValueChanged=e=>{t.luminanceMaterial.threshold=Math.pow(e,2.2)},this.scatter.onValueChanged=e=>{t.luminancePass.enabled=!0,t.luminanceMaterial.smoothing=e,t.mipmapBlurPass&&(t.mipmapBlurPass.radius=h.MathUtils.lerp(.1,.9,e))},t}},r(Ep,"useSelectiveBloom",!1),Ep);let zr=Ew;r_([p(U)],zr.prototype,"threshold",2);r_([p(U)],zr.prototype,"intensity",2);r_([p(U)],zr.prototype,"scatter",2);Qi("Bloom",zr);var _k=Object.defineProperty,yk=Object.getOwnPropertyDescriptor,bk=(s,t,e,i)=>{for(var n=i>1?void 0:i?yk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&_k(t,e,n),n};class wh extends Xe{constructor(){super(...arguments);r(this,"intensity",new U(0))}get typeName(){return"ChromaticAberration"}onCreateEffect(){const e=new exports.MODULES.POSTPROCESSING.MODULE.ChromaticAberrationEffect;return e.offset=new h.Vector2(0,0),e.radialModulation=!0,e.modulationOffset=.15,this.intensity.valueProcessor=i=>i*.02,this.intensity.onValueChanged=i=>{e.offset.x=-i,e.offset.y=i},e}}bk([p(U)],wh.prototype,"intensity",2);Qi("ChromaticAberration",wh);var vk=Object.defineProperty,wk=Object.getOwnPropertyDescriptor,Aw=(s,t,e,i)=>{for(var n=i>1?void 0:i?wk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&vk(t,e,n),n};const pb=S("debugpost");var Ad=(s=>(s[s.None=0]="None",s[s.Neutral=1]="Neutral",s[s.ACES=2]="ACES",s[s.AgX=3]="AgX",s[s.KhronosNeutral=4]="KhronosNeutral",s))(Ad||{});function pp(s){switch(s){case 0:return h.LinearToneMapping;case 1:return h.ReinhardToneMapping;case 2:return h.ACESFilmicToneMapping;case 3:return h.AgXToneMapping;case 4:return h.NeutralToneMapping;default:return h.NeutralToneMapping}}function xk(s){switch(s){case h.LinearToneMapping:return 0;case h.ACESFilmicToneMapping:return 2;case h.AgXToneMapping:return 3;case h.NeutralToneMapping:return 1;case h.ReinhardToneMapping:return 1;default:return 0}}function mb(s){switch(s){case h.LinearToneMapping:return exports.MODULES.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR;case h.ACESFilmicToneMapping:return exports.MODULES.POSTPROCESSING.MODULE.ToneMappingMode.ACES_FILMIC;case h.AgXToneMapping:return exports.MODULES.POSTPROCESSING.MODULE.ToneMappingMode.AGX;case h.NeutralToneMapping:return exports.MODULES.POSTPROCESSING.MODULE.ToneMappingMode.NEUTRAL;case h.ReinhardToneMapping:return exports.MODULES.POSTPROCESSING.MODULE.ToneMappingMode.REINHARD;default:return exports.MODULES.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR}}const Dw=class extends Xe{constructor(){super(...arguments);r(this,"mode",new U(void 0));r(this,"exposure",new U(1))}get typeName(){return"ToneMapping"}setMode(t){const e=Ad[t];return e===void 0?(console.error("Invalid ToneMapping mode",t),this):(this.mode.value=e,this)}get isToneMapping(){return!0}onEffectEnabled(){const t=kw(this);t&&super.onEffectEnabled(t)}onCreateEffect(){if(this.postprocessingContext)for(const i of this.postprocessingContext.components){if(i===this)break;if(i!=this&&i instanceof Dw){console.warn("Multiple tonemapping effects found in the same postprocessing stack: Please check your scene setup.",{activeEffect:i,ignoredEffect:this});return}}if(this.mode.isInitialized==!1){const i=xk(this.context.renderer.toneMapping);this.mode.initialize(i)}const t=pp(this.mode.value),e=new exports.MODULES.POSTPROCESSING.MODULE.ToneMappingEffect({mode:mb(t)});return this.mode.onValueChanged=i=>{const n=pp(i);e.mode=mb(n),pb&&console.log("ToneMapping mode changed to",Ad[i],n,e.mode)},pb&&console.log("Use ToneMapping",Ad[this.mode.value],t,e.mode,"renderer.tonemapping: "+this.context.renderer.toneMapping),this.exposure.onValueChanged=i=>{this.context.renderer.toneMappingExposure=i},e}onBeforeRender(){this.mode.overrideState&&(this.context.renderer.toneMapping=pp(this.mode.value)),this.exposure.overrideState&&(this.context.renderer.toneMappingExposure=this.exposure.value)}};let mo=Dw;Aw([p(U)],mo.prototype,"mode",2);Aw([p(U)],mo.prototype,"exposure",2);Qi("Tonemapping",mo);var Sk=Object.defineProperty,Ck=Object.getOwnPropertyDescriptor,sf=(s,t,e,i)=>{for(var n=i>1?void 0:i?Ck(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&Sk(t,e,n),n};class Do extends Xe{constructor(){super(...arguments);r(this,"postExposure",new U(0));r(this,"contrast",new U(0));r(this,"hueShift",new U(0));r(this,"saturation",new U(0))}get typeName(){return"ColorAdjustments"}init(){this.postExposure.valueProcessor=e=>(e=Math.pow(2,e),e),this.contrast.valueProcessor=e=>{let i=1;return e>0?i=200:e<0&&(i=100),e/i},this.contrast.defaultValue=0,this.hueShift.valueProcessor=e=>Math.PI*e/180,this.hueShift.defaultValue=0,this.saturation.valueProcessor=e=>e<0?e/100:e/(100*Math.PI),this.saturation.defaultValue=0}onCreateEffect(){var a,l;const e=[];this.context.renderer.toneMapping!==h.NoToneMapping&&this.postExposure.overrideState&&(this.context.renderer.toneMapping=h.NoToneMapping);let i=(a=this.postprocessingContext)==null?void 0:a.components.find(c=>c instanceof mo);i||(i=new mo,(l=this.postprocessingContext)==null||l.components.push(i)),this.postExposure.onValueChanged=c=>{this.postExposure.overrideState&&(i.exposure.value=c)};const n=new exports.MODULES.POSTPROCESSING.MODULE.BrightnessContrastEffect;this.contrast.onValueChanged=c=>n.contrast=c;const o=new exports.MODULES.POSTPROCESSING.MODULE.HueSaturationEffect;return e.push(n),e.push(o),this.hueShift.onValueChanged=c=>o.hue=c,this.saturation.onValueChanged=c=>o.saturation=c,e}}sf([p(U)],Do.prototype,"postExposure",2);sf([p(U)],Do.prototype,"contrast",2);sf([p(U)],Do.prototype,"hueShift",2);sf([p(U)],Do.prototype,"saturation",2);Qi("ColorAdjustments",Do);var Pk=Object.defineProperty,Ok=Object.getOwnPropertyDescriptor,Nr=(s,t,e,i)=>{for(var n=i>1?void 0:i?Ok(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&Pk(t,e,n),n};const Mk=S("debugpost");class _n extends Xe{constructor(){super(...arguments);r(this,"mode");r(this,"focusDistance",new U(1));r(this,"focalLength",new U(.2));r(this,"aperture",new U(20));r(this,"gaussianMaxRadius",new U);r(this,"resolutionScale",new U(1*1/window.devicePixelRatio));r(this,"bokehScale",new U)}get typeName(){return"DepthOfField"}init(){this.focalLength.valueProcessor=i=>{const n=i/300,o=2;return z.lerp(o,.01,n)};const e=20;this.aperture.valueProcessor=i=>{const n=1-i/32;return z.lerp(1,e,n)}}onCreateEffect(){if(this.mode===0){Mk&&console.warn("DepthOfField: Mode is set to Off");return}const e=new exports.MODULES.POSTPROCESSING.MODULE.DepthOfFieldEffect(this.context.mainCamera,{worldFocusRange:.2,focalLength:1,bokehScale:20,resolutionScale:this.resolutionScale.value});return this.focusDistance.onValueChanged=i=>{e.cocMaterial.worldFocusDistance=i},this.focalLength.onValueChanged=i=>e.cocMaterial.worldFocusRange=i,this.aperture.onValueChanged=i=>e.bokehScale=i,this.resolutionScale&&(this.resolutionScale.onValueChanged=i=>e.resolution.scale=i),[e]}unapply(){}}Nr([p()],_n.prototype,"mode",2);Nr([p(U)],_n.prototype,"focusDistance",2);Nr([p(U)],_n.prototype,"focalLength",2);Nr([p(U)],_n.prototype,"aperture",2);Nr([p(U)],_n.prototype,"gaussianMaxRadius",2);Nr([p(U)],_n.prototype,"resolutionScale",2);Nr([p(U)],_n.prototype,"bokehScale",2);Qi("DepthOfField",_n);class Dc extends Xe{constructor(e){super();r(this,"effect");this.effect=e}get typeName(){return this.effect.constructor.name}onCreateEffect(){return this.effect}}var Rk=Object.defineProperty,kk=Object.getOwnPropertyDescriptor,Tk=(s,t,e,i)=>{for(var n=i>1?void 0:i?kk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&Rk(t,e,n),n};class xh extends Xe{constructor(){super(...arguments);r(this,"granularity",new U(10))}get typeName(){return"PixelationEffect"}onCreateEffect(){const e=new exports.MODULES.POSTPROCESSING.MODULE.PixelationEffect;return this.granularity.onValueChanged=i=>{e.granularity=i},e}}Tk([p(U)],xh.prototype,"granularity",2);Qi("PixelationEffect",xh);var Ek=Object.defineProperty,Ak=Object.getOwnPropertyDescriptor,Sh=(s,t,e,i)=>{for(var n=i>1?void 0:i?Ak(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&Ek(t,e,n),n};class Es extends Xe{constructor(){super(...arguments);r(this,"intensity",new U(2));r(this,"falloff",new U(1));r(this,"samples",new U(9));r(this,"color",new U(new h.Color(0,0,0)));r(this,"luminanceInfluence",new U(.7));r(this,"_ssao")}get typeName(){return"ScreenSpaceAmbientOcclusion"}onBeforeRender(){if(this._ssao&&this.context.mainCamera instanceof h.PerspectiveCamera){const e=this.context.mainCamera.far-this.context.mainCamera.near;this._ssao.ssaoMaterial.worldDistanceFalloff=e*.01,this._ssao.ssaoMaterial.worldDistanceThreshold=this.context.mainCamera.far}}onCreateEffect(){const e=this.context.mainCamera,i=new exports.MODULES.POSTPROCESSING.MODULE.NormalPass(this.context.scene,e),n=new exports.MODULES.POSTPROCESSING.MODULE.DepthDownsamplingPass({normalBuffer:i.texture,resolutionScale:.5}),o=this._ssao=new exports.MODULES.POSTPROCESSING.MODULE.SSAOEffect(e,i.texture,{normalDepthBuffer:n.texture,worldDistanceThreshold:1,worldDistanceFalloff:1,worldProximityThreshold:.1,worldProximityFalloff:2,intensity:1,blendFunction:exports.MODULES.POSTPROCESSING.MODULE.BlendFunction.MULTIPLY,luminanceInfluence:.5});this.intensity.onValueChanged=l=>{o.intensity=l},this.falloff.onValueChanged=l=>{o.ssaoMaterial.radius=l*.1},this.samples.onValueChanged=l=>{o.ssaoMaterial.samples=l},this.color.onValueChanged=l=>{o.color||(o.color=new h.Color),o.color.copy(l)},this.luminanceInfluence.onValueChanged=l=>{o.luminanceInfluence=l};const a=new Array;return a.push(i),a.push(n),a.push(o),a}}Sh([p(U)],Es.prototype,"intensity",2);Sh([p(U)],Es.prototype,"falloff",2);Sh([p(U)],Es.prototype,"samples",2);Sh([p(U)],Es.prototype,"color",2);Sh([p(U)],Es.prototype,"luminanceInfluence",2);Qi("ScreenSpaceAmbientOcclusion",Es);var Dk=Object.defineProperty,Lk=Object.getOwnPropertyDescriptor,Vr=(s,t,e,i)=>{for(var n=i>1?void 0:i?Lk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&Dk(t,e,n),n},Om=(s=>(s[s.Performance=0]="Performance",s[s.Low=1]="Low",s[s.Medium=2]="Medium",s[s.High=3]="High",s[s.Ultra=4]="Ultra",s))(Om||{});class yn extends Xe{constructor(){super(...arguments);r(this,"gammaCorrection",!0);r(this,"aoRadius",new U(1));r(this,"falloff",new U(1));r(this,"intensity",new U(1));r(this,"color",new U(new h.Color(0,0,0)));r(this,"screenspaceRadius",!1);r(this,"quality",2);r(this,"_ssao")}get typeName(){return"ScreenSpaceAmbientOcclusionN8"}onValidate(){this._ssao&&(this._ssao.setQualityMode(Om[this.quality]),this._ssao.configuration.gammaCorrection=this.gammaCorrection,this._ssao.configuration.screenSpaceRadius=this.screenspaceRadius)}onCreateEffect(){const e=this.context.mainCamera,i=this._ssao=new exports.MODULES.POSTPROCESSING_AO.MODULE.N8AOPostPass(this.context.scene,e,this.context.domWidth,this.context.domHeight),n=Om[this.quality];i.setQualityMode(n),i.configuration.gammaCorrection=this.gammaCorrection,i.configuration.screenSpaceRadius=this.screenspaceRadius,this.intensity.onValueChanged=a=>{i.configuration.intensity=a},this.falloff.onValueChanged=a=>{i.configuration.distanceFalloff=a},this.aoRadius.onValueChanged=a=>{i.configuration.aoRadius=a},this.color.onValueChanged=a=>{i.color||(i.color=new h.Color),i.configuration.color.copy(a)};const o=new Array;return o.push(i),o}}Vr([Pt(),p()],yn.prototype,"gammaCorrection",2);Vr([p(U)],yn.prototype,"aoRadius",2);Vr([p(U)],yn.prototype,"falloff",2);Vr([p(U)],yn.prototype,"intensity",2);Vr([p(U)],yn.prototype,"color",2);Vr([Pt(),p()],yn.prototype,"screenspaceRadius",2);Vr([Pt(),p()],yn.prototype,"quality",2);Qi("ScreenSpaceAmbientOcclusionN8",yn);var Ik=Object.defineProperty,jk=Object.getOwnPropertyDescriptor,Lw=(s,t,e,i)=>{for(var n=i>1?void 0:i?jk(t,e):t,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(i?a(t,e,n):a(n))||n);return i&&n&&Ik(t,e,n),n};class Ch extends Xe{constructor(){super(...arguments);r(this,"_effect");r(this,"_amount",1);r(this,"_radius",1)}get typeName(){return"Sharpening"}onCreateEffect(){return this._effect??(this._effect=new(Bk())),this.effect}get effect(){return this._effect}set amount(e){this._amount=e,this._effect&&(this._effect.uniforms.get("amount").value=e)}get amount(){return this._effect?this._effect.uniforms.get("amount").value:this._amount}set radius(e){this._radius=e,this._effect&&(this._effect.uniforms.get("radius").value=e)}get radius(){return this._effect?this._effect.uniforms.get("radius").value:this._radius}}Lw([p()],Ch.prototype,"amount",1);Lw([p()],Ch.prototype,"radius",1);function Bk(){const s=`
1206
1206
  void mainSupport() {
1207
1207
  vUv = uv;
1208
1208
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);